summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2016-08-29 18:24:05 +0200
committerCarlos Soriano <csoriano@gnome.org>2016-08-29 18:25:29 +0200
commitbc88db402e424f34fd7a8fa583217c984df7f4b4 (patch)
tree040dc9433d4ad9cc38482fc7f83f560d58fdf803
parente19470ae3c0bd16fde484d0640f0c48a4f6ba4d0 (diff)
downloadnautilus-wip/csoriano/uncrustify.tar.gz
general: run uncrustifywip/csoriano/uncrustify
And make the style of Nautilus the same for all files. Hopefully we can fix all the style issues we can find in the next days, so expect a little of movement on this.
-rw-r--r--eel/check-program.c67
-rw-r--r--eel/eel-accessibility.c266
-rw-r--r--eel/eel-art-extensions.c230
-rw-r--r--eel/eel-canvas.c5116
-rw-r--r--eel/eel-debug.c104
-rw-r--r--eel/eel-gdk-extensions.c114
-rw-r--r--eel/eel-glib-extensions.c201
-rw-r--r--eel/eel-gnome-extensions.c81
-rw-r--r--eel/eel-graphic-effects.c206
-rw-r--r--eel/eel-gtk-extensions.c456
-rw-r--r--eel/eel-lib-self-check-functions.c44
-rw-r--r--eel/eel-self-checks.c237
-rw-r--r--eel/eel-stock-dialogs.c754
-rw-r--r--eel/eel-string.c1653
-rw-r--r--eel/eel-vfs-extensions.c245
-rw-r--r--libnautilus-extension/nautilus-column-provider.c58
-rw-r--r--libnautilus-extension/nautilus-column.c404
-rw-r--r--libnautilus-extension/nautilus-extension-types.c56
-rw-r--r--libnautilus-extension/nautilus-file-info.c268
-rw-r--r--libnautilus-extension/nautilus-info-provider.c138
-rw-r--r--libnautilus-extension/nautilus-location-widget-provider.c63
-rw-r--r--libnautilus-extension/nautilus-menu-item.c505
-rw-r--r--libnautilus-extension/nautilus-menu-provider.c125
-rw-r--r--libnautilus-extension/nautilus-menu.c77
-rw-r--r--libnautilus-extension/nautilus-property-page-provider.c60
-rw-r--r--libnautilus-extension/nautilus-property-page.c340
-rw-r--r--nautilus-desktop/main-desktop.c29
-rw-r--r--nautilus-desktop/nautilus-desktop-application.c212
-rw-r--r--nautilus-desktop/nautilus-desktop-canvas-view-container.c182
-rw-r--r--nautilus-desktop/nautilus-desktop-canvas-view.c1016
-rw-r--r--nautilus-desktop/nautilus-desktop-directory-file.c781
-rw-r--r--nautilus-desktop/nautilus-desktop-directory.c745
-rw-r--r--nautilus-desktop/nautilus-desktop-icon-file.c696
-rw-r--r--nautilus-desktop/nautilus-desktop-link-monitor.c600
-rw-r--r--nautilus-desktop/nautilus-desktop-link.c615
-rw-r--r--nautilus-desktop/nautilus-desktop-metadata.c60
-rw-r--r--nautilus-desktop/nautilus-desktop-window-slot.c36
-rw-r--r--nautilus-desktop/nautilus-desktop-window.c643
-rw-r--r--nautilus-sendto-extension/nautilus-nste.c213
-rw-r--r--nautilus-sendto-extension/nautilus-sendto-module.c19
-rw-r--r--src/gtk/nautilusgtkplacesview.c3159
-rw-r--r--src/gtk/nautilusgtkplacesviewrow.c613
-rw-r--r--src/nautilus-application.c1841
-rw-r--r--src/nautilus-autorun-software.c523
-rw-r--r--src/nautilus-batch-rename-dialog.c5212
-rw-r--r--src/nautilus-batch-rename-utilities.c1728
-rw-r--r--src/nautilus-bookmark-list.c791
-rw-r--r--src/nautilus-bookmark.c1178
-rw-r--r--src/nautilus-canvas-container.c12804
-rw-r--r--src/nautilus-canvas-dnd.c3118
-rw-r--r--src/nautilus-canvas-item.c4186
-rw-r--r--src/nautilus-canvas-view-container.c479
-rw-r--r--src/nautilus-canvas-view.c2578
-rw-r--r--src/nautilus-clipboard-monitor.c412
-rw-r--r--src/nautilus-clipboard.c183
-rw-r--r--src/nautilus-column-chooser.c1112
-rw-r--r--src/nautilus-column-utilities.c587
-rw-r--r--src/nautilus-compress-dialog-controller.c415
-rw-r--r--src/nautilus-dbus-manager.c161
-rw-r--r--src/nautilus-debug.c164
-rw-r--r--src/nautilus-default-file-icon.c1052
-rw-r--r--src/nautilus-desktop-item-properties.c814
-rw-r--r--src/nautilus-directory-async.c7543
-rw-r--r--src/nautilus-directory.c2642
-rw-r--r--src/nautilus-dnd.c1505
-rw-r--r--src/nautilus-empty-view.c243
-rw-r--r--src/nautilus-entry.c395
-rw-r--r--src/nautilus-error-reporting.c633
-rw-r--r--src/nautilus-file-changes-queue.c624
-rw-r--r--src/nautilus-file-conflict-dialog.c663
-rw-r--r--src/nautilus-file-name-widget-controller.c597
-rw-r--r--src/nautilus-file-operations.c14216
-rw-r--r--src/nautilus-file-queue.c146
-rw-r--r--src/nautilus-file-undo-manager.c269
-rw-r--r--src/nautilus-file-undo-operations.c2915
-rw-r--r--src/nautilus-file-utilities.c1745
-rw-r--r--src/nautilus-file.c12789
-rw-r--r--src/nautilus-files-view-dnd.c826
-rw-r--r--src/nautilus-files-view.c11250
-rw-r--r--src/nautilus-floating-bar.c746
-rw-r--r--src/nautilus-freedesktop-dbus.c228
-rw-r--r--src/nautilus-global-preferences.c78
-rw-r--r--src/nautilus-icon-info.c817
-rw-r--r--src/nautilus-image-properties-page.c1165
-rw-r--r--src/nautilus-keyfile-metadata.c467
-rw-r--r--src/nautilus-lib-self-check-functions.c44
-rw-r--r--src/nautilus-link.c994
-rw-r--r--src/nautilus-list-model.c2605
-rw-r--r--src/nautilus-list-view-dnd.c327
-rw-r--r--src/nautilus-list-view.c5147
-rw-r--r--src/nautilus-location-entry.c1125
-rw-r--r--src/nautilus-main.c78
-rw-r--r--src/nautilus-metadata.c84
-rw-r--r--src/nautilus-mime-actions.c3910
-rw-r--r--src/nautilus-mime-application-chooser.c684
-rw-r--r--src/nautilus-module.c367
-rw-r--r--src/nautilus-monitor.c261
-rw-r--r--src/nautilus-new-folder-dialog-controller.c188
-rw-r--r--src/nautilus-notebook.c723
-rw-r--r--src/nautilus-operations-ui-manager.c688
-rw-r--r--src/nautilus-other-locations-window-slot.c44
-rw-r--r--src/nautilus-pathbar.c3097
-rw-r--r--src/nautilus-places-view.c414
-rw-r--r--src/nautilus-preferences-window.c792
-rw-r--r--src/nautilus-previewer.c112
-rw-r--r--src/nautilus-profile.c50
-rw-r--r--src/nautilus-program-choosing.c662
-rw-r--r--src/nautilus-progress-info-manager.c233
-rw-r--r--src/nautilus-progress-info-widget.c254
-rw-r--r--src/nautilus-progress-info.c1056
-rw-r--r--src/nautilus-progress-persistence-handler.c356
-rw-r--r--src/nautilus-properties-window.c8771
-rw-r--r--src/nautilus-query-editor.c975
-rw-r--r--src/nautilus-query.c738
-rw-r--r--src/nautilus-recent.c99
-rw-r--r--src/nautilus-rename-file-popover-controller.c305
-rw-r--r--src/nautilus-search-directory-file.c393
-rw-r--r--src/nautilus-search-directory.c1314
-rw-r--r--src/nautilus-search-engine-model.c377
-rw-r--r--src/nautilus-search-engine-simple.c759
-rw-r--r--src/nautilus-search-engine-tracker.c698
-rw-r--r--src/nautilus-search-engine.c393
-rw-r--r--src/nautilus-search-hit.c514
-rw-r--r--src/nautilus-search-popover.c1075
-rw-r--r--src/nautilus-search-provider.c139
-rw-r--r--src/nautilus-selection-canvas-item.c1179
-rw-r--r--src/nautilus-self-check-functions.c7
-rw-r--r--src/nautilus-shell-search-provider.c999
-rw-r--r--src/nautilus-signaller.c71
-rw-r--r--src/nautilus-special-location-bar.c227
-rw-r--r--src/nautilus-thumbnails.c760
-rw-r--r--src/nautilus-toolbar.c1588
-rw-r--r--src/nautilus-trash-bar.c288
-rw-r--r--src/nautilus-trash-monitor.c232
-rw-r--r--src/nautilus-tree-view-drag-dest.c2060
-rw-r--r--src/nautilus-ui-utilities.c625
-rw-r--r--src/nautilus-vfs-directory.c183
-rw-r--r--src/nautilus-vfs-file.c1192
-rw-r--r--src/nautilus-view.c158
-rw-r--r--src/nautilus-window-slot-dnd.c809
-rw-r--r--src/nautilus-window-slot.c4012
-rw-r--r--src/nautilus-window.c3512
-rw-r--r--src/nautilus-x-content-bar.c477
-rw-r--r--test/test-copy.c142
-rw-r--r--test/test-eel-background.c35
-rw-r--r--test/test-eel-string-get-common-prefix.c192
-rw-r--r--test/test-eel-string-rtrim-punctuation.c123
-rw-r--r--test/test-file-utilities-get-common-filename-prefix.c597
-rw-r--r--test/test-nautilus-directory-async.c116
-rw-r--r--test/test-nautilus-mime-actions-set.c251
-rw-r--r--test/test-nautilus-mime-actions.c198
-rw-r--r--test/test-nautilus-search-engine.c91
-rw-r--r--test/test.c146
-rw-r--r--test/uncrustify-sample.c63
154 files changed, 98109 insertions, 86396 deletions
diff --git a/eel/check-program.c b/eel/check-program.c
index ca109740f..1e0f0a382 100644
--- a/eel/check-program.c
+++ b/eel/check-program.c
@@ -1,24 +1,23 @@
-
/* check-program.c: A simple driver for eel self checks.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Ramiro Estrugo <ramiro@eazel.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
@@ -32,27 +31,29 @@
#include <stdlib.h>
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
#if !defined (EEL_OMIT_SELF_CHECK)
- eel_make_warnings_and_criticals_stop_in_debugger ();
-
+ eel_make_warnings_and_criticals_stop_in_debugger ();
- LIBXML_TEST_VERSION
- gtk_init (&argc, &argv);
- /* Run the checks for eel twice. */
+ LIBXML_TEST_VERSION
+ gtk_init (&argc,
+ &argv);
- eel_run_lib_self_checks ();
- eel_exit_if_self_checks_failed ();
+ /* Run the checks for eel twice. */
- eel_run_lib_self_checks ();
- eel_exit_if_self_checks_failed ();
+ eel_run_lib_self_checks ();
+ eel_exit_if_self_checks_failed ();
- eel_debug_shut_down ();
+ eel_run_lib_self_checks ();
+ eel_exit_if_self_checks_failed ();
+
+ eel_debug_shut_down ();
#endif /* !EEL_OMIT_SELF_CHECK */
-
- return EXIT_SUCCESS;
+
+ return EXIT_SUCCESS;
}
diff --git a/eel/eel-accessibility.c b/eel/eel-accessibility.c
index 83b88accd..3510fc491 100644
--- a/eel/eel-accessibility.c
+++ b/eel/eel-accessibility.c
@@ -1,202 +1,212 @@
/* eel-accessibility.h - Utility functions for accessibility
-
- Copyright (C) 2002 Anders Carlsson, Sun Microsystems, Inc.
-
- The Eel Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Eel Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Eel Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors:
- Anders Carlsson <andersca@gnu.org>
- Michael Meeks <michael@ximian.com>
-*/
+ *
+ * Copyright (C) 2002 Anders Carlsson, Sun Microsystems, Inc.
+ *
+ * The Eel Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Eel Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Eel Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Anders Carlsson <andersca@gnu.org>
+ * Michael Meeks <michael@ximian.com>
+ */
#include <config.h>
#include <gtk/gtk.h>
#include <atk/atkrelationset.h>
#include <eel/eel-accessibility.h>
void
-eel_accessibility_set_up_label_widget_relation (GtkWidget *label, GtkWidget *widget)
+eel_accessibility_set_up_label_widget_relation (GtkWidget *label,
+ GtkWidget *widget)
{
- AtkObject *atk_widget, *atk_label;
+ AtkObject *atk_widget, *atk_label;
- atk_label = gtk_widget_get_accessible (label);
- atk_widget = gtk_widget_get_accessible (widget);
+ atk_label = gtk_widget_get_accessible (label);
+ atk_widget = gtk_widget_get_accessible (widget);
- /* Create the label -> widget relation */
- atk_object_add_relationship (atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
+ /* Create the label -> widget relation */
+ atk_object_add_relationship (atk_label, ATK_RELATION_LABEL_FOR, atk_widget);
- /* Create the widget -> label relation */
- atk_object_add_relationship (atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
+ /* Create the widget -> label relation */
+ atk_object_add_relationship (atk_widget, ATK_RELATION_LABELLED_BY, atk_label);
}
static GQuark
get_quark_gobject (void)
{
- static GQuark quark_accessible_gobject = 0;
+ static GQuark quark_accessible_gobject = 0;
- if (!quark_accessible_gobject) {
- quark_accessible_gobject = g_quark_from_static_string
- ("object-for-accessible");
- }
+ if (!quark_accessible_gobject)
+ {
+ quark_accessible_gobject = g_quark_from_static_string
+ ("object-for-accessible");
+ }
- return quark_accessible_gobject;
+ return quark_accessible_gobject;
}
/**
* eel_accessibility_get_gobject:
* @object: an AtkObject
- *
+ *
* gets the GObject associated with the AtkObject, for which
* @object provides accessibility support.
- *
+ *
* Return value: the accessible's associated GObject
**/
gpointer
eel_accessibility_get_gobject (AtkObject *object)
{
- return g_object_get_qdata (G_OBJECT (object), get_quark_gobject ());
+ return g_object_get_qdata (G_OBJECT (object), get_quark_gobject ());
}
static GailTextUtil *
get_simple_text (gpointer object)
{
- GObject *gobject;
- EelAccessibleTextIface *aif;
-
- if (GTK_IS_ACCESSIBLE (object)) {
- gobject = G_OBJECT (gtk_accessible_get_widget (GTK_ACCESSIBLE (object)));
- } else {
- gobject = eel_accessibility_get_gobject (object);
- }
-
- if (!gobject) {
- return NULL;
- }
-
- aif = EEL_ACCESSIBLE_TEXT_GET_IFACE (gobject);
- if (!aif) {
- g_warning ("No accessible text inferface on '%s'",
- g_type_name_from_instance ((gpointer) gobject));
-
- } else if (aif->get_text) {
- return aif->get_text (gobject);
- }
-
- return NULL;
+ GObject *gobject;
+ EelAccessibleTextIface *aif;
+
+ if (GTK_IS_ACCESSIBLE (object))
+ {
+ gobject = G_OBJECT (gtk_accessible_get_widget (GTK_ACCESSIBLE (object)));
+ }
+ else
+ {
+ gobject = eel_accessibility_get_gobject (object);
+ }
+
+ if (!gobject)
+ {
+ return NULL;
+ }
+
+ aif = EEL_ACCESSIBLE_TEXT_GET_IFACE (gobject);
+ if (!aif)
+ {
+ g_warning ("No accessible text inferface on '%s'",
+ g_type_name_from_instance ((gpointer) gobject));
+ }
+ else if (aif->get_text)
+ {
+ return aif->get_text (gobject);
+ }
+
+ return NULL;
}
char *
eel_accessibility_text_get_text (AtkText *text,
- gint start_pos,
- gint end_pos)
+ gint start_pos,
+ gint end_pos)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_substring (util, start_pos, end_pos);
+ return gail_text_util_get_substring (util, start_pos, end_pos);
}
-gunichar
+gunichar
eel_accessibility_text_get_character_at_offset (AtkText *text,
- gint offset)
+ gint offset)
{
- char *txt, *index;
- gint sucks1 = 0, sucks2 = -1;
- gunichar c;
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, 0);
+ char *txt, *index;
+ gint sucks1 = 0, sucks2 = -1;
+ gunichar c;
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, 0);
- txt = gail_text_util_get_substring (util, sucks1, sucks2);
+ txt = gail_text_util_get_substring (util, sucks1, sucks2);
- index = g_utf8_offset_to_pointer (txt, offset);
- c = g_utf8_get_char (index);
- g_free (txt);
+ index = g_utf8_offset_to_pointer (txt, offset);
+ c = g_utf8_get_char (index);
+ g_free (txt);
- return c;
+ return c;
}
char *
-eel_accessibility_text_get_text_before_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
+eel_accessibility_text_get_text_before_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_text (
- util, NULL, GAIL_BEFORE_OFFSET,
- boundary_type, offset, start_offset, end_offset);
+ return gail_text_util_get_text (
+ util, NULL, GAIL_BEFORE_OFFSET,
+ boundary_type, offset, start_offset, end_offset);
}
char *
-eel_accessibility_text_get_text_at_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
+eel_accessibility_text_get_text_at_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_text (
- util, NULL, GAIL_AT_OFFSET,
- boundary_type, offset, start_offset, end_offset);
+ return gail_text_util_get_text (
+ util, NULL, GAIL_AT_OFFSET,
+ boundary_type, offset, start_offset, end_offset);
}
-gchar*
-eel_accessibility_text_get_text_after_offset (AtkText *text,
- gint offset,
- AtkTextBoundary boundary_type,
- gint *start_offset,
- gint *end_offset)
+gchar *
+eel_accessibility_text_get_text_after_offset (AtkText *text,
+ gint offset,
+ AtkTextBoundary boundary_type,
+ gint *start_offset,
+ gint *end_offset)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, NULL);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, NULL);
- return gail_text_util_get_text (
- util, NULL, GAIL_AFTER_OFFSET,
- boundary_type, offset, start_offset, end_offset);
+ return gail_text_util_get_text (
+ util, NULL, GAIL_AFTER_OFFSET,
+ boundary_type, offset, start_offset, end_offset);
}
gint
eel_accessibility_text_get_character_count (AtkText *text)
{
- GailTextUtil *util = get_simple_text (text);
- g_return_val_if_fail (util != NULL, -1);
+ GailTextUtil *util = get_simple_text (text);
+ g_return_val_if_fail (util != NULL, -1);
- return gtk_text_buffer_get_char_count (util->buffer);
+ return gtk_text_buffer_get_char_count (util->buffer);
}
GType
eel_accessible_text_get_type (void)
{
- static GType type = 0;
-
- if (!type) {
- const GTypeInfo tinfo = {
- sizeof (AtkTextIface),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) NULL,
- (GClassFinalizeFunc) NULL
- };
-
- type = g_type_register_static (
- G_TYPE_INTERFACE, "EelAccessibleText", &tinfo, 0);
- }
-
- return type;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo tinfo =
+ {
+ sizeof (AtkTextIface),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) NULL,
+ (GClassFinalizeFunc) NULL
+ };
+
+ type = g_type_register_static (
+ G_TYPE_INTERFACE, "EelAccessibleText", &tinfo, 0);
+ }
+
+ return type;
}
diff --git a/eel/eel-art-extensions.c b/eel/eel-art-extensions.c
index 38072b562..e8ce5f957 100644
--- a/eel/eel-art-extensions.c
+++ b/eel/eel-art-extensions.c
@@ -1,25 +1,24 @@
-
/* eel-art-extensions.c - implementation of libart extension functions.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
- Ramiro Estrugo <ramiro@eazel.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ * Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
@@ -31,170 +30,185 @@ const EelDRect eel_drect_empty = { 0.0, 0.0, 0.0, 0.0 };
const EelIRect eel_irect_empty = { 0, 0, 0, 0 };
void
-eel_irect_copy (EelIRect *dest, const EelIRect *src)
+eel_irect_copy (EelIRect *dest,
+ const EelIRect *src)
{
- dest->x0 = src->x0;
- dest->y0 = src->y0;
- dest->x1 = src->x1;
- dest->y1 = src->y1;
+ dest->x0 = src->x0;
+ dest->y0 = src->y0;
+ dest->x1 = src->x1;
+ dest->y1 = src->y1;
}
void
-eel_irect_union (EelIRect *dest,
- const EelIRect *src1,
- const EelIRect *src2) {
- if (eel_irect_is_empty (src1)) {
- eel_irect_copy (dest, src2);
- } else if (eel_irect_is_empty (src2)) {
- eel_irect_copy (dest, src1);
- } else {
- dest->x0 = MIN (src1->x0, src2->x0);
- dest->y0 = MIN (src1->y0, src2->y0);
- dest->x1 = MAX (src1->x1, src2->x1);
- dest->y1 = MAX (src1->y1, src2->y1);
- }
+eel_irect_union (EelIRect *dest,
+ const EelIRect *src1,
+ const EelIRect *src2)
+{
+ if (eel_irect_is_empty (src1))
+ {
+ eel_irect_copy (dest, src2);
+ }
+ else if (eel_irect_is_empty (src2))
+ {
+ eel_irect_copy (dest, src1);
+ }
+ else
+ {
+ dest->x0 = MIN (src1->x0, src2->x0);
+ dest->y0 = MIN (src1->y0, src2->y0);
+ dest->x1 = MAX (src1->x1, src2->x1);
+ dest->y1 = MAX (src1->y1, src2->y1);
+ }
}
void
-eel_irect_intersect (EelIRect *dest,
- const EelIRect *src1,
- const EelIRect *src2)
+eel_irect_intersect (EelIRect *dest,
+ const EelIRect *src1,
+ const EelIRect *src2)
{
- dest->x0 = MAX (src1->x0, src2->x0);
- dest->y0 = MAX (src1->y0, src2->y0);
- dest->x1 = MIN (src1->x1, src2->x1);
- dest->y1 = MIN (src1->y1, src2->y1);
+ dest->x0 = MAX (src1->x0, src2->x0);
+ dest->y0 = MAX (src1->y0, src2->y0);
+ dest->x1 = MIN (src1->x1, src2->x1);
+ dest->y1 = MIN (src1->y1, src2->y1);
}
gboolean
eel_irect_is_empty (const EelIRect *src)
{
- return (src->x1 <= src->x0 ||
- src->y1 <= src->y0);
+ return (src->x1 <= src->x0 ||
+ src->y1 <= src->y0);
}
/**
* eel_irect_get_width:
- *
+ *
* @rectangle: An EelIRect.
*
* Returns: The width of the rectangle.
- *
+ *
*/
int
eel_irect_get_width (EelIRect rectangle)
{
- return rectangle.x1 - rectangle.x0;
+ return rectangle.x1 - rectangle.x0;
}
/**
* eel_irect_get_height:
- *
+ *
* @rectangle: An EelIRect.
*
* Returns: The height of the rectangle.
- *
+ *
*/
int
eel_irect_get_height (EelIRect rectangle)
{
- return rectangle.y1 - rectangle.y0;
+ return rectangle.y1 - rectangle.y0;
}
static void
-eel_drect_copy (EelDRect *dest,
- const EelDRect *src)
+eel_drect_copy (EelDRect *dest,
+ const EelDRect *src)
{
- dest->x0 = src->x0;
- dest->y0 = src->y0;
- dest->x1 = src->x1;
- dest->y1 = src->y1;
+ dest->x0 = src->x0;
+ dest->y0 = src->y0;
+ dest->x1 = src->x1;
+ dest->y1 = src->y1;
}
static gboolean
eel_drect_is_empty (const EelDRect *src)
{
- return (src->x1 <= src->x0 || src->y1 <= src->y0);
+ return (src->x1 <= src->x0 || src->y1 <= src->y0);
}
void
-eel_drect_union (EelDRect *dest,
- const EelDRect *src1,
- const EelDRect *src2)
+eel_drect_union (EelDRect *dest,
+ const EelDRect *src1,
+ const EelDRect *src2)
{
- if (eel_drect_is_empty (src1)) {
- eel_drect_copy (dest, src2);
- } else if (eel_drect_is_empty (src2)) {
- eel_drect_copy (dest, src1);
- } else {
- dest->x0 = MIN (src1->x0, src2->x0);
- dest->y0 = MIN (src1->y0, src2->y0);
- dest->x1 = MAX (src1->x1, src2->x1);
- dest->y1 = MAX (src1->y1, src2->y1);
- }
+ if (eel_drect_is_empty (src1))
+ {
+ eel_drect_copy (dest, src2);
+ }
+ else if (eel_drect_is_empty (src2))
+ {
+ eel_drect_copy (dest, src1);
+ }
+ else
+ {
+ dest->x0 = MIN (src1->x0, src2->x0);
+ dest->y0 = MIN (src1->y0, src2->y0);
+ dest->x1 = MAX (src1->x1, src2->x1);
+ dest->y1 = MAX (src1->y1, src2->y1);
+ }
}
/**
* eel_irect_contains_point:
- *
+ *
* @rectangle: An EelIRect.
* @x: X coordinate to test.
* @y: Y coordinate to test.
*
- * Returns: A boolean value indicating whether the rectangle
+ * Returns: A boolean value indicating whether the rectangle
* contains the x,y coordinate.
- *
+ *
*/
gboolean
eel_irect_contains_point (EelIRect rectangle,
- int x,
- int y)
+ int x,
+ int y)
{
- return x >= rectangle.x0
- && x <= rectangle.x1
- && y >= rectangle.y0
- && y <= rectangle.y1;
+ return x >= rectangle.x0
+ && x <= rectangle.x1
+ && y >= rectangle.y0
+ && y <= rectangle.y1;
}
gboolean
eel_irect_hits_irect (EelIRect rectangle_a,
- EelIRect rectangle_b)
+ EelIRect rectangle_b)
{
- EelIRect intersection;
- eel_irect_intersect (&intersection, &rectangle_a, &rectangle_b);
- return !eel_irect_is_empty (&intersection);
+ EelIRect intersection;
+ eel_irect_intersect (&intersection, &rectangle_a, &rectangle_b);
+ return !eel_irect_is_empty (&intersection);
}
gboolean
eel_irect_equal (EelIRect rectangle_a,
- EelIRect rectangle_b)
+ EelIRect rectangle_b)
{
- return rectangle_a.x0 == rectangle_b.x0
- && rectangle_a.y0 == rectangle_b.y0
- && rectangle_a.x1 == rectangle_b.x1
- && rectangle_a.y1 == rectangle_b.y1;
+ return rectangle_a.x0 == rectangle_b.x0
+ && rectangle_a.y0 == rectangle_b.y0
+ && rectangle_a.x1 == rectangle_b.x1
+ && rectangle_a.y1 == rectangle_b.y1;
}
-EelIRect
-eel_irect_offset_by (EelIRect rectangle, int x, int y)
+EelIRect
+eel_irect_offset_by (EelIRect rectangle,
+ int x,
+ int y)
{
- rectangle.x0 += x;
- rectangle.x1 += x;
- rectangle.y0 += y;
- rectangle.y1 += y;
-
- return rectangle;
+ rectangle.x0 += x;
+ rectangle.x1 += x;
+ rectangle.y0 += y;
+ rectangle.y1 += y;
+
+ return rectangle;
}
-EelIRect
-eel_irect_scale_by (EelIRect rectangle, double scale)
+EelIRect
+eel_irect_scale_by (EelIRect rectangle,
+ double scale)
{
- rectangle.x0 *= scale;
- rectangle.x1 *= scale;
- rectangle.y0 *= scale;
- rectangle.y1 *= scale;
-
- return rectangle;
+ rectangle.x0 *= scale;
+ rectangle.x1 *= scale;
+ rectangle.y0 *= scale;
+ rectangle.y1 *= scale;
+
+ return rectangle;
}
diff --git a/eel/eel-canvas.c b/eel/eel-canvas.c
index a0f7bf4dc..044beeb0d 100644
--- a/eel/eel-canvas.c
+++ b/eel/eel-canvas.c
@@ -19,7 +19,7 @@
* see <http://www.gnu.org/licenses/>.
*/
/*
- @NOTATION@
+ * @NOTATION@
*/
/*
* EelCanvas widget - Tk-like canvas widget for Gnome
@@ -70,11 +70,11 @@
#include <cairo-gobject.h>
#include "eel-canvas.h"
-static void eel_canvas_request_update (EelCanvas *canvas);
-static void group_add (EelCanvasGroup *group,
- EelCanvasItem *item);
-static void group_remove (EelCanvasGroup *group,
- EelCanvasItem *item);
+static void eel_canvas_request_update (EelCanvas *canvas);
+static void group_add (EelCanvasGroup *group,
+ EelCanvasItem *item);
+static void group_remove (EelCanvasGroup *group,
+ EelCanvasItem *item);
static void redraw_and_repick_if_mapped (EelCanvasItem *item);
/*** EelCanvasItem ***/
@@ -83,21 +83,24 @@ static void redraw_and_repick_if_mapped (EelCanvasItem *item);
#define GCI_UPDATE_MASK (EEL_CANVAS_UPDATE_REQUESTED | EEL_CANVAS_UPDATE_DEEP)
#define GCI_EPSILON 1e-18
-enum {
- ITEM_PROP_0,
- ITEM_PROP_PARENT,
- ITEM_PROP_VISIBLE
+enum
+{
+ ITEM_PROP_0,
+ ITEM_PROP_PARENT,
+ ITEM_PROP_VISIBLE
};
-enum {
- ITEM_DESTROY,
- ITEM_EVENT,
- ITEM_LAST_SIGNAL
+enum
+{
+ ITEM_DESTROY,
+ ITEM_EVENT,
+ ITEM_LAST_SIGNAL
};
-static void eel_canvas_item_class_init (EelCanvasItemClass *klass);
-static void eel_canvas_item_init (EelCanvasItem *item);
-static int emit_event (EelCanvas *canvas, GdkEvent *event);
+static void eel_canvas_item_class_init (EelCanvasItemClass *klass);
+static void eel_canvas_item_init (EelCanvasItem *item);
+static int emit_event (EelCanvas *canvas,
+ GdkEvent *event);
static guint item_signals[ITEM_LAST_SIGNAL];
@@ -118,35 +121,37 @@ static gpointer accessible_parent_class;
GType
eel_canvas_item_get_type (void)
{
- static GType canvas_item_type = 0;
-
- if (!canvas_item_type) {
- static const GTypeInfo canvas_item_info = {
- sizeof (EelCanvasItemClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) eel_canvas_item_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (EelCanvasItem),
- 0, /* n_preallocs */
- (GInstanceInitFunc) eel_canvas_item_init
- };
+ static GType canvas_item_type = 0;
- canvas_item_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED,
- "EelCanvasItem",
- &canvas_item_info,
- 0);
- }
-
- return canvas_item_type;
+ if (!canvas_item_type)
+ {
+ static const GTypeInfo canvas_item_info =
+ {
+ sizeof (EelCanvasItemClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) eel_canvas_item_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EelCanvasItem),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) eel_canvas_item_init
+ };
+
+ canvas_item_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED,
+ "EelCanvasItem",
+ &canvas_item_info,
+ 0);
+ }
+
+ return canvas_item_type;
}
/* Object initialization function for EelCanvasItem */
static void
eel_canvas_item_init (EelCanvasItem *item)
{
- item->flags |= EEL_CANVAS_ITEM_VISIBLE;
+ item->flags |= EEL_CANVAS_ITEM_VISIBLE;
}
/**
@@ -167,21 +172,24 @@ eel_canvas_item_init (EelCanvasItem *item)
* Return value: The newly-created item.
**/
EelCanvasItem *
-eel_canvas_item_new (EelCanvasGroup *parent, GType type, const gchar *first_arg_name, ...)
+eel_canvas_item_new (EelCanvasGroup *parent,
+ GType type,
+ const gchar *first_arg_name,
+ ...)
{
- EelCanvasItem *item;
- va_list args;
+ EelCanvasItem *item;
+ va_list args;
- g_return_val_if_fail (EEL_IS_CANVAS_GROUP (parent), NULL);
- g_return_val_if_fail (g_type_is_a (type, eel_canvas_item_get_type ()), NULL);
+ g_return_val_if_fail (EEL_IS_CANVAS_GROUP (parent), NULL);
+ g_return_val_if_fail (g_type_is_a (type, eel_canvas_item_get_type ()), NULL);
- item = EEL_CANVAS_ITEM (g_object_new (type, NULL));
+ item = EEL_CANVAS_ITEM (g_object_new (type, NULL));
- va_start (args, first_arg_name);
- eel_canvas_item_construct (item, parent, first_arg_name, args);
- va_end (args);
+ va_start (args, first_arg_name);
+ eel_canvas_item_construct (item, parent, first_arg_name, args);
+ va_end (args);
- return item;
+ return item;
}
@@ -191,65 +199,90 @@ eel_canvas_item_new (EelCanvasGroup *parent, GType type, const gchar *first_arg_
static void
item_post_create_setup (EelCanvasItem *item)
{
- group_add (EEL_CANVAS_GROUP (item->parent), item);
+ group_add (EEL_CANVAS_GROUP (item->parent), item);
- redraw_and_repick_if_mapped (item);
+ redraw_and_repick_if_mapped (item);
}
/* Set_property handler for canvas items */
static void
-eel_canvas_item_set_property (GObject *gobject, guint param_id,
- const GValue *value, GParamSpec *pspec)
-{
- EelCanvasItem *item;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
-
- item = EEL_CANVAS_ITEM (gobject);
-
- switch (param_id) {
- case ITEM_PROP_PARENT:
- if (item->parent != NULL) {
- g_warning ("Cannot set `parent' argument after item has "
- "already been constructed.");
- } else if (g_value_get_object (value)) {
- item->parent = EEL_CANVAS_ITEM (g_value_get_object (value));
- item->canvas = item->parent->canvas;
- item_post_create_setup (item);
- }
- break;
- case ITEM_PROP_VISIBLE:
- if (g_value_get_boolean (value)) {
- eel_canvas_item_show (item);
- } else {
- eel_canvas_item_hide (item);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
+eel_canvas_item_set_property (GObject *gobject,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EelCanvasItem *item;
+
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
+
+ item = EEL_CANVAS_ITEM (gobject);
+
+ switch (param_id)
+ {
+ case ITEM_PROP_PARENT:
+ {
+ if (item->parent != NULL)
+ {
+ g_warning ("Cannot set `parent' argument after item has "
+ "already been constructed.");
+ }
+ else if (g_value_get_object (value))
+ {
+ item->parent = EEL_CANVAS_ITEM (g_value_get_object (value));
+ item->canvas = item->parent->canvas;
+ item_post_create_setup (item);
+ }
+ }
+ break;
+
+ case ITEM_PROP_VISIBLE:
+ {
+ if (g_value_get_boolean (value))
+ {
+ eel_canvas_item_show (item);
+ }
+ else
+ {
+ eel_canvas_item_hide (item);
+ }
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
}
/* Get_property handler for canvas items */
static void
-eel_canvas_item_get_property (GObject *gobject, guint param_id,
- GValue *value, GParamSpec *pspec)
+eel_canvas_item_get_property (GObject *gobject,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EelCanvasItem *item;
+ EelCanvasItem *item;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (gobject));
- item = EEL_CANVAS_ITEM (gobject);
+ item = EEL_CANVAS_ITEM (gobject);
- switch (param_id) {
- case ITEM_PROP_VISIBLE:
- g_value_set_boolean (value, item->flags & EEL_CANVAS_ITEM_VISIBLE);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
+ switch (param_id)
+ {
+ case ITEM_PROP_VISIBLE:
+ {
+ g_value_set_boolean (value, item->flags & EEL_CANVAS_ITEM_VISIBLE);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
}
/**
@@ -262,135 +295,159 @@ eel_canvas_item_get_property (GObject *gobject, guint param_id,
* Constructs a canvas item; meant for use only by item implementations.
**/
void
-eel_canvas_item_construct (EelCanvasItem *item, EelCanvasGroup *parent,
- const gchar *first_arg_name, va_list args)
+eel_canvas_item_construct (EelCanvasItem *item,
+ EelCanvasGroup *parent,
+ const gchar *first_arg_name,
+ va_list args)
{
- g_return_if_fail (EEL_IS_CANVAS_GROUP (parent));
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (parent));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- item->parent = EEL_CANVAS_ITEM (parent);
- item->canvas = item->parent->canvas;
+ item->parent = EEL_CANVAS_ITEM (parent);
+ item->canvas = item->parent->canvas;
- g_object_set_valist (G_OBJECT (item), first_arg_name, args);
+ g_object_set_valist (G_OBJECT (item), first_arg_name, args);
- item_post_create_setup (item);
+ item_post_create_setup (item);
}
static void
redraw_and_repick_if_mapped (EelCanvasItem *item)
{
- if (item->flags & EEL_CANVAS_ITEM_MAPPED) {
- eel_canvas_item_request_redraw (item);
- item->canvas->need_repick = TRUE;
- }
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ eel_canvas_item_request_redraw (item);
+ item->canvas->need_repick = TRUE;
+ }
}
/* Dispose handler for canvas items */
static void
eel_canvas_item_dispose (GObject *object)
{
- EelCanvasItem *item;
+ EelCanvasItem *item;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (object));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (object));
- item = EEL_CANVAS_ITEM (object);
+ item = EEL_CANVAS_ITEM (object);
- if (item->canvas) {
- eel_canvas_item_request_redraw (item);
+ if (item->canvas)
+ {
+ eel_canvas_item_request_redraw (item);
- /* Make the canvas forget about us */
+ /* Make the canvas forget about us */
- if (item == item->canvas->current_item) {
- item->canvas->current_item = NULL;
- item->canvas->need_repick = TRUE;
- }
+ if (item == item->canvas->current_item)
+ {
+ item->canvas->current_item = NULL;
+ item->canvas->need_repick = TRUE;
+ }
- if (item == item->canvas->new_current_item) {
- item->canvas->new_current_item = NULL;
- item->canvas->need_repick = TRUE;
- }
+ if (item == item->canvas->new_current_item)
+ {
+ item->canvas->new_current_item = NULL;
+ item->canvas->need_repick = TRUE;
+ }
- eel_canvas_item_ungrab (item);
+ eel_canvas_item_ungrab (item);
- if (item == item->canvas->focused_item)
- item->canvas->focused_item = NULL;
+ if (item == item->canvas->focused_item)
+ {
+ item->canvas->focused_item = NULL;
+ }
- /* Normal destroy stuff */
+ /* Normal destroy stuff */
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_REALIZED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize) (item);
+ if (item->flags & EEL_CANVAS_ITEM_REALIZED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize)(item);
+ }
- if (item->parent)
- group_remove (EEL_CANVAS_GROUP (item->parent), item);
+ if (item->parent)
+ {
+ group_remove (EEL_CANVAS_GROUP (item->parent), item);
+ }
- item->canvas = NULL;
- }
+ item->canvas = NULL;
+ }
- g_object_set_data (object, "in-destruction", GINT_TO_POINTER (1));
- g_signal_emit (object, item_signals[ITEM_DESTROY], 0);
+ g_object_set_data (object, "in-destruction", GINT_TO_POINTER (1));
+ g_signal_emit (object, item_signals[ITEM_DESTROY], 0);
- g_object_set_data (object, "in-destruction", NULL);
+ g_object_set_data (object, "in-destruction", NULL);
- G_OBJECT_CLASS (item_parent_class)->dispose (object);
+ G_OBJECT_CLASS (item_parent_class)->dispose (object);
}
void
eel_canvas_item_destroy (EelCanvasItem *item)
{
- if (g_object_get_data (G_OBJECT (item), "in-destruction") == NULL) {
- g_object_run_dispose (G_OBJECT (item));
- }
+ if (g_object_get_data (G_OBJECT (item), "in-destruction") == NULL)
+ {
+ g_object_run_dispose (G_OBJECT (item));
+ }
}
/* Realize handler for canvas items */
static void
eel_canvas_item_realize (EelCanvasItem *item)
{
- if (item->parent && !(item->parent->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item->parent)->realize) (item->parent);
-
- if (item->parent == NULL && !gtk_widget_get_realized (GTK_WIDGET (item->canvas)))
- gtk_widget_realize (GTK_WIDGET (item->canvas));
+ if (item->parent && !(item->parent->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item->parent)->realize)(item->parent);
+ }
+
+ if (item->parent == NULL && !gtk_widget_get_realized (GTK_WIDGET (item->canvas)))
+ {
+ gtk_widget_realize (GTK_WIDGET (item->canvas));
+ }
- item->flags |= EEL_CANVAS_ITEM_REALIZED;
+ item->flags |= EEL_CANVAS_ITEM_REALIZED;
- eel_canvas_item_request_update (item);
+ eel_canvas_item_request_update (item);
}
/* Unrealize handler for canvas items */
static void
eel_canvas_item_unrealize (EelCanvasItem *item)
{
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- item->flags &= ~(EEL_CANVAS_ITEM_REALIZED);
+ item->flags &= ~(EEL_CANVAS_ITEM_REALIZED);
}
/* Map handler for canvas items */
static void
eel_canvas_item_map (EelCanvasItem *item)
{
- item->flags |= EEL_CANVAS_ITEM_MAPPED;
+ item->flags |= EEL_CANVAS_ITEM_MAPPED;
}
/* Unmap handler for canvas items */
static void
eel_canvas_item_unmap (EelCanvasItem *item)
{
- item->flags &= ~(EEL_CANVAS_ITEM_MAPPED);
+ item->flags &= ~(EEL_CANVAS_ITEM_MAPPED);
}
/* Update handler for canvas items */
static void
-eel_canvas_item_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, int flags)
+eel_canvas_item_update (EelCanvasItem *item,
+ double i2w_dx,
+ double i2w_dy,
+ int flags)
{
- item->flags &= ~(EEL_CANVAS_ITEM_NEED_UPDATE);
- item->flags &= ~(EEL_CANVAS_ITEM_NEED_DEEP_UPDATE);
+ item->flags &= ~(EEL_CANVAS_ITEM_NEED_UPDATE);
+ item->flags &= ~(EEL_CANVAS_ITEM_NEED_DEEP_UPDATE);
}
/*
@@ -408,31 +465,38 @@ eel_canvas_item_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, int f
static void
eel_canvas_item_invoke_update (EelCanvasItem *item,
- double i2w_dx,
- double i2w_dy,
- int flags)
+ double i2w_dx,
+ double i2w_dy,
+ int flags)
{
- int child_flags;
+ int child_flags;
+
+ child_flags = flags;
- child_flags = flags;
+ /* apply object flags to child flags */
+ child_flags &= ~EEL_CANVAS_UPDATE_REQUESTED;
- /* apply object flags to child flags */
- child_flags &= ~EEL_CANVAS_UPDATE_REQUESTED;
+ if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
+ {
+ child_flags |= EEL_CANVAS_UPDATE_REQUESTED;
+ }
- if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
- child_flags |= EEL_CANVAS_UPDATE_REQUESTED;
+ if (item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)
+ {
+ child_flags |= EEL_CANVAS_UPDATE_DEEP;
+ }
- if (item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)
- child_flags |= EEL_CANVAS_UPDATE_DEEP;
+ if (child_flags & GCI_UPDATE_MASK)
+ {
+ if (EEL_CANVAS_ITEM_GET_CLASS (item)->update)
+ {
+ EEL_CANVAS_ITEM_GET_CLASS (item)->update (item, i2w_dx, i2w_dy, child_flags);
+ }
+ }
- if (child_flags & GCI_UPDATE_MASK) {
- if (EEL_CANVAS_ITEM_GET_CLASS (item)->update)
- EEL_CANVAS_ITEM_GET_CLASS (item)->update (item, i2w_dx, i2w_dy, child_flags);
- }
-
- /* If this fail you probably forgot to chain up to
- * EelCanvasItem::update from a derived class */
- g_return_if_fail (!(item->flags & EEL_CANVAS_ITEM_NEED_UPDATE));
+ /* If this fail you probably forgot to chain up to
+ * EelCanvasItem::update from a derived class */
+ g_return_if_fail (!(item->flags & EEL_CANVAS_ITEM_NEED_UPDATE));
}
/*
@@ -441,14 +505,21 @@ eel_canvas_item_invoke_update (EelCanvasItem *item,
*/
static double
-eel_canvas_item_invoke_point (EelCanvasItem *item, double x, double y, int cx, int cy, EelCanvasItem **actual_item)
+eel_canvas_item_invoke_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item)
{
- /* Calculate x & y in item local coordinates */
+ /* Calculate x & y in item local coordinates */
- if (EEL_CANVAS_ITEM_GET_CLASS (item)->point)
- return EEL_CANVAS_ITEM_GET_CLASS (item)->point (item, x, y, cx, cy, actual_item);
+ if (EEL_CANVAS_ITEM_GET_CLASS (item)->point)
+ {
+ return EEL_CANVAS_ITEM_GET_CLASS (item)->point (item, x, y, cx, cy, actual_item);
+ }
- return 1e18;
+ return 1e18;
}
/**
@@ -461,13 +532,15 @@ eel_canvas_item_invoke_point (EelCanvasItem *item, double x, double y, int cx, i
* values, and the item is repainted as appropriate.
**/
void
-eel_canvas_item_set (EelCanvasItem *item, const gchar *first_arg_name, ...)
+eel_canvas_item_set (EelCanvasItem *item,
+ const gchar *first_arg_name,
+ ...)
{
- va_list args;
+ va_list args;
- va_start (args, first_arg_name);
- eel_canvas_item_set_valist (item, first_arg_name, args);
- va_end (args);
+ va_start (args, first_arg_name);
+ eel_canvas_item_set_valist (item, first_arg_name, args);
+ va_end (args);
}
@@ -481,13 +554,15 @@ eel_canvas_item_set (EelCanvasItem *item, const gchar *first_arg_name, ...)
* values, and the item is repainted as appropriate.
**/
void
-eel_canvas_item_set_valist (EelCanvasItem *item, const gchar *first_arg_name, va_list args)
+eel_canvas_item_set_valist (EelCanvasItem *item,
+ const gchar *first_arg_name,
+ va_list args)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_object_set_valist (G_OBJECT (item), first_arg_name, args);
+ g_object_set_valist (G_OBJECT (item), first_arg_name, args);
- item->canvas->need_repick = TRUE;
+ item->canvas->need_repick = TRUE;
}
@@ -503,92 +578,126 @@ eel_canvas_item_set_valist (EelCanvasItem *item, const gchar *first_arg_name, va
* most probably does not do, what you want.
**/
void
-eel_canvas_item_move (EelCanvasItem *item, double dx, double dy)
+eel_canvas_item_move (EelCanvasItem *item,
+ double dx,
+ double dy)
{
- g_return_if_fail (item != NULL);
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (item != NULL);
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!EEL_CANVAS_ITEM_GET_CLASS (item)->translate) {
- g_warning ("Item type %s does not implement translate method.\n",
- g_type_name (G_OBJECT_TYPE (item)));
- return;
- }
-
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->translate) (item, dx, dy);
+ if (!EEL_CANVAS_ITEM_GET_CLASS (item)->translate)
+ {
+ g_warning ("Item type %s does not implement translate method.\n",
+ g_type_name (G_OBJECT_TYPE (item)));
+ return;
+ }
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- item->canvas->need_repick = TRUE;
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->translate)(item, dx, dy);
- if (!(item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- if (item->parent != NULL)
- eel_canvas_item_request_update (item->parent);
- else
- eel_canvas_request_update (item->canvas);
- }
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ item->canvas->need_repick = TRUE;
+ }
+ if (!(item->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ if (item->parent != NULL)
+ {
+ eel_canvas_item_request_update (item->parent);
+ }
+ else
+ {
+ eel_canvas_request_update (item->canvas);
+ }
+ }
}
static void
eel_canvas_queue_resize (EelCanvas *canvas)
{
- if (gtk_widget_is_drawable (GTK_WIDGET (canvas)))
- gtk_widget_queue_resize (GTK_WIDGET (canvas));
+ if (gtk_widget_is_drawable (GTK_WIDGET (canvas)))
+ {
+ gtk_widget_queue_resize (GTK_WIDGET (canvas));
+ }
}
/* Convenience function to reorder items in a group's child list. This puts the
* specified link after the "before" link. Returns TRUE if the list was changed.
*/
static gboolean
-put_item_after (GList *link, GList *before)
+put_item_after (GList *link,
+ GList *before)
{
- EelCanvasGroup *parent;
+ EelCanvasGroup *parent;
- if (link == before)
- return FALSE;
+ if (link == before)
+ {
+ return FALSE;
+ }
- parent = EEL_CANVAS_GROUP (EEL_CANVAS_ITEM (link->data)->parent);
+ parent = EEL_CANVAS_GROUP (EEL_CANVAS_ITEM (link->data)->parent);
- if (before == NULL) {
- if (link == parent->item_list)
- return FALSE;
+ if (before == NULL)
+ {
+ if (link == parent->item_list)
+ {
+ return FALSE;
+ }
- link->prev->next = link->next;
+ link->prev->next = link->next;
- if (link->next)
- link->next->prev = link->prev;
- else
- parent->item_list_end = link->prev;
+ if (link->next)
+ {
+ link->next->prev = link->prev;
+ }
+ else
+ {
+ parent->item_list_end = link->prev;
+ }
- link->prev = before;
- link->next = parent->item_list;
- link->next->prev = link;
- parent->item_list = link;
- } else {
- if ((link == parent->item_list_end) && (before == parent->item_list_end->prev))
- return FALSE;
+ link->prev = before;
+ link->next = parent->item_list;
+ link->next->prev = link;
+ parent->item_list = link;
+ }
+ else
+ {
+ if ((link == parent->item_list_end) && (before == parent->item_list_end->prev))
+ {
+ return FALSE;
+ }
- if (link->next)
- link->next->prev = link->prev;
+ if (link->next)
+ {
+ link->next->prev = link->prev;
+ }
- if (link->prev)
- link->prev->next = link->next;
- else {
- parent->item_list = link->next;
- parent->item_list->prev = NULL;
- }
+ if (link->prev)
+ {
+ link->prev->next = link->next;
+ }
+ else
+ {
+ parent->item_list = link->next;
+ parent->item_list->prev = NULL;
+ }
- link->prev = before;
- link->next = before->next;
+ link->prev = before;
+ link->next = before->next;
- link->prev->next = link;
+ link->prev->next = link;
- if (link->next)
- link->next->prev = link;
- else
- parent->item_list_end = link;
- }
- return TRUE;
+ if (link->next)
+ {
+ link->next->prev = link;
+ }
+ else
+ {
+ parent->item_list_end = link;
+ }
+ }
+ return TRUE;
}
@@ -602,30 +711,38 @@ put_item_after (GList *link, GList *before)
* stack, then the item is put at the top.
**/
void
-eel_canvas_item_raise (EelCanvasItem *item, int positions)
+eel_canvas_item_raise (EelCanvasItem *item,
+ int positions)
{
- GList *link, *before;
- EelCanvasGroup *parent;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (positions >= 0);
-
- if (!item->parent || positions == 0)
- return;
-
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ GList *link, *before;
+ EelCanvasGroup *parent;
- for (before = link; positions && before; positions--)
- before = before->next;
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (positions >= 0);
- if (!before)
- before = parent->item_list_end;
-
- if (put_item_after (link, before)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (!item->parent || positions == 0)
+ {
+ return;
+ }
+
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
+
+ for (before = link; positions && before; positions--)
+ {
+ before = before->next;
+ }
+
+ if (!before)
+ {
+ before = parent->item_list_end;
+ }
+
+ if (put_item_after (link, before))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
@@ -639,30 +756,40 @@ eel_canvas_item_raise (EelCanvasItem *item, int positions)
* stack, then the item is put at the bottom.
**/
void
-eel_canvas_item_lower (EelCanvasItem *item, int positions)
+eel_canvas_item_lower (EelCanvasItem *item,
+ int positions)
{
- GList *link, *before;
- EelCanvasGroup *parent;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (positions >= 1);
+ GList *link, *before;
+ EelCanvasGroup *parent;
- if (!item->parent || positions == 0)
- return;
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (positions >= 1);
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ if (!item->parent || positions == 0)
+ {
+ return;
+ }
- if (link->prev)
- for (before = link->prev; positions && before; positions--)
- before = before->prev;
- else
- before = NULL;
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
- if (put_item_after (link, before)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (link->prev)
+ {
+ for (before = link->prev; positions && before; positions--)
+ {
+ before = before->prev;
+ }
+ }
+ else
+ {
+ before = NULL;
+ }
+
+ if (put_item_after (link, before))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
@@ -675,21 +802,24 @@ eel_canvas_item_lower (EelCanvasItem *item, int positions)
void
eel_canvas_item_raise_to_top (EelCanvasItem *item)
{
- GList *link;
- EelCanvasGroup *parent;
+ GList *link;
+ EelCanvasGroup *parent;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!item->parent)
- return;
+ if (!item->parent)
+ {
+ return;
+ }
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
- if (put_item_after (link, parent->item_list_end)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (put_item_after (link, parent->item_list_end))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
@@ -702,21 +832,24 @@ eel_canvas_item_raise_to_top (EelCanvasItem *item)
void
eel_canvas_item_lower_to_bottom (EelCanvasItem *item)
{
- GList *link;
- EelCanvasGroup *parent;
+ GList *link;
+ EelCanvasGroup *parent;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!item->parent)
- return;
+ if (!item->parent)
+ {
+ return;
+ }
- parent = EEL_CANVAS_GROUP (item->parent);
- link = g_list_find (parent->item_list, item);
- g_assert (link != NULL);
+ parent = EEL_CANVAS_GROUP (item->parent);
+ link = g_list_find (parent->item_list, item);
+ g_assert (link != NULL);
- if (put_item_after (link, NULL)) {
- redraw_and_repick_if_mapped (item);
- }
+ if (put_item_after (link, NULL))
+ {
+ redraw_and_repick_if_mapped (item);
+ }
}
/**
@@ -730,38 +863,43 @@ eel_canvas_item_lower_to_bottom (EelCanvasItem *item)
**/
void
eel_canvas_item_send_behind (EelCanvasItem *item,
- EelCanvasItem *behind_item)
+ EelCanvasItem *behind_item)
{
- GList *item_list;
- int item_position, behind_position;
-
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ GList *item_list;
+ int item_position, behind_position;
- if (behind_item == NULL) {
- eel_canvas_item_raise_to_top (item);
- return;
- }
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (EEL_IS_CANVAS_ITEM (behind_item));
- g_return_if_fail (item->parent == behind_item->parent);
+ if (behind_item == NULL)
+ {
+ eel_canvas_item_raise_to_top (item);
+ return;
+ }
- item_list = EEL_CANVAS_GROUP (item->parent)->item_list;
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (behind_item));
+ g_return_if_fail (item->parent == behind_item->parent);
- item_position = g_list_index (item_list, item);
- g_assert (item_position != -1);
- behind_position = g_list_index (item_list, behind_item);
- g_assert (behind_position != -1);
- g_assert (item_position != behind_position);
+ item_list = EEL_CANVAS_GROUP (item->parent)->item_list;
- if (item_position == behind_position - 1) {
- return;
- }
+ item_position = g_list_index (item_list, item);
+ g_assert (item_position != -1);
+ behind_position = g_list_index (item_list, behind_item);
+ g_assert (behind_position != -1);
+ g_assert (item_position != behind_position);
- if (item_position < behind_position) {
- eel_canvas_item_raise (item, (behind_position - 1) - item_position);
- } else {
- eel_canvas_item_lower (item, item_position - behind_position);
- }
+ if (item_position == behind_position - 1)
+ {
+ return;
+ }
+
+ if (item_position < behind_position)
+ {
+ eel_canvas_item_raise (item, (behind_position - 1) - item_position);
+ }
+ else
+ {
+ eel_canvas_item_lower (item, item_position - behind_position);
+ }
}
/**
@@ -773,27 +911,37 @@ eel_canvas_item_send_behind (EelCanvasItem *item,
void
eel_canvas_item_show (EelCanvasItem *item)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (!(item->flags & EEL_CANVAS_ITEM_VISIBLE)) {
- item->flags |= EEL_CANVAS_ITEM_VISIBLE;
-
- if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->realize) (item);
+ if (!(item->flags & EEL_CANVAS_ITEM_VISIBLE))
+ {
+ item->flags |= EEL_CANVAS_ITEM_VISIBLE;
- if (item->parent != NULL) {
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
- item->parent->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->map) (item);
- } else {
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
- gtk_widget_get_mapped (GTK_WIDGET (item->canvas)))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->map) (item);
- }
+ if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->realize)(item);
+ }
- redraw_and_repick_if_mapped (item);
- eel_canvas_queue_resize (item->canvas);
- }
+ if (item->parent != NULL)
+ {
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ item->parent->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->map)(item);
+ }
+ }
+ else
+ {
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ gtk_widget_get_mapped (GTK_WIDGET (item->canvas)))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->map)(item);
+ }
+ }
+
+ redraw_and_repick_if_mapped (item);
+ eel_canvas_queue_resize (item->canvas);
+ }
}
@@ -807,20 +955,23 @@ eel_canvas_item_show (EelCanvasItem *item)
void
eel_canvas_item_hide (EelCanvasItem *item)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE) {
- item->flags &= ~EEL_CANVAS_ITEM_VISIBLE;
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ item->flags &= ~EEL_CANVAS_ITEM_VISIBLE;
- redraw_and_repick_if_mapped (item);
+ redraw_and_repick_if_mapped (item);
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- eel_canvas_queue_resize (item->canvas);
+ eel_canvas_queue_resize (item->canvas);
- /* No need to unrealize when we just want to hide */
- }
+ /* No need to unrealize when we just want to hide */
+ }
}
@@ -828,11 +979,11 @@ eel_canvas_item_hide (EelCanvasItem *item)
* Prepare the window for grabbing, i.e. show it.
*/
static void
-seat_grab_prepare_window (GdkSeat *seat,
- GdkWindow *window,
- gpointer user_data)
+seat_grab_prepare_window (GdkSeat *seat,
+ GdkWindow *window,
+ gpointer user_data)
{
- gdk_window_show (window);
+ gdk_window_show (window);
}
/**
@@ -852,45 +1003,51 @@ seat_grab_prepare_window (GdkSeat *seat,
* gdk_seat_grab().
**/
GdkGrabStatus
-eel_canvas_item_grab (EelCanvasItem *item,
- GdkEventMask event_mask,
- GdkCursor *cursor,
- const GdkEvent *event)
+eel_canvas_item_grab (EelCanvasItem *item,
+ GdkEventMask event_mask,
+ GdkCursor *cursor,
+ const GdkEvent *event)
{
- GdkGrabStatus retval;
- GdkDisplay *display;
- GdkSeat *seat;
-
- g_return_val_if_fail (EEL_IS_CANVAS_ITEM (item), GDK_GRAB_NOT_VIEWABLE);
- g_return_val_if_fail (gtk_widget_get_mapped (GTK_WIDGET (item->canvas)),
- GDK_GRAB_NOT_VIEWABLE);
-
- if (item->canvas->grabbed_item)
- return GDK_GRAB_ALREADY_GRABBED;
-
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
- return GDK_GRAB_NOT_VIEWABLE;
-
- display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
- seat = gdk_display_get_default_seat (display);
-
- retval = gdk_seat_grab (seat,
- gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas)),
- GDK_SEAT_CAPABILITY_ALL_POINTING,
- FALSE,
- cursor,
- event,
- seat_grab_prepare_window,
- NULL);
-
- if (retval != GDK_GRAB_SUCCESS)
- return retval;
+ GdkGrabStatus retval;
+ GdkDisplay *display;
+ GdkSeat *seat;
+
+ g_return_val_if_fail (EEL_IS_CANVAS_ITEM (item), GDK_GRAB_NOT_VIEWABLE);
+ g_return_val_if_fail (gtk_widget_get_mapped (GTK_WIDGET (item->canvas)),
+ GDK_GRAB_NOT_VIEWABLE);
+
+ if (item->canvas->grabbed_item)
+ {
+ return GDK_GRAB_ALREADY_GRABBED;
+ }
+
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ return GDK_GRAB_NOT_VIEWABLE;
+ }
+
+ display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
+ seat = gdk_display_get_default_seat (display);
+
+ retval = gdk_seat_grab (seat,
+ gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas)),
+ GDK_SEAT_CAPABILITY_ALL_POINTING,
+ FALSE,
+ cursor,
+ event,
+ seat_grab_prepare_window,
+ NULL);
+
+ if (retval != GDK_GRAB_SUCCESS)
+ {
+ return retval;
+ }
- item->canvas->grabbed_item = item;
- item->canvas->grabbed_event_mask = event_mask;
- item->canvas->current_item = item; /* So that events go to the grabbed item */
+ item->canvas->grabbed_item = item;
+ item->canvas->grabbed_event_mask = event_mask;
+ item->canvas->current_item = item; /* So that events go to the grabbed item */
- return retval;
+ return retval;
}
@@ -904,19 +1061,21 @@ eel_canvas_item_grab (EelCanvasItem *item,
void
eel_canvas_item_ungrab (EelCanvasItem *item)
{
- GdkDisplay *display;
- GdkSeat *seat;
+ GdkDisplay *display;
+ GdkSeat *seat;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- if (item->canvas->grabbed_item != item)
- return;
+ if (item->canvas->grabbed_item != item)
+ {
+ return;
+ }
- display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
- seat = gdk_display_get_default_seat (display);
+ display = gtk_widget_get_display (GTK_WIDGET (item->canvas));
+ seat = gdk_display_get_default_seat (display);
- item->canvas->grabbed_item = NULL;
- gdk_seat_ungrab (seat);
+ item->canvas->grabbed_item = NULL;
+ gdk_seat_ungrab (seat);
}
/**
@@ -929,21 +1088,25 @@ eel_canvas_item_ungrab (EelCanvasItem *item)
* coordinates.
**/
void
-eel_canvas_item_w2i (EelCanvasItem *item, double *x, double *y)
+eel_canvas_item_w2i (EelCanvasItem *item,
+ double *x,
+ double *y)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (x != NULL);
- g_return_if_fail (y != NULL);
-
- item = item->parent;
- while (item) {
- if (EEL_IS_CANVAS_GROUP (item)) {
- *x -= EEL_CANVAS_GROUP (item)->xpos;
- *y -= EEL_CANVAS_GROUP (item)->ypos;
- }
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (x != NULL);
+ g_return_if_fail (y != NULL);
+
+ item = item->parent;
+ while (item)
+ {
+ if (EEL_IS_CANVAS_GROUP (item))
+ {
+ *x -= EEL_CANVAS_GROUP (item)->xpos;
+ *y -= EEL_CANVAS_GROUP (item)->ypos;
+ }
- item = item->parent;
- }
+ item = item->parent;
+ }
}
@@ -957,32 +1120,41 @@ eel_canvas_item_w2i (EelCanvasItem *item, double *x, double *y)
* coordinates.
**/
void
-eel_canvas_item_i2w (EelCanvasItem *item, double *x, double *y)
+eel_canvas_item_i2w (EelCanvasItem *item,
+ double *x,
+ double *y)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (x != NULL);
- g_return_if_fail (y != NULL);
-
- item = item->parent;
- while (item) {
- if (EEL_IS_CANVAS_GROUP (item)) {
- *x += EEL_CANVAS_GROUP (item)->xpos;
- *y += EEL_CANVAS_GROUP (item)->ypos;
- }
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (x != NULL);
+ g_return_if_fail (y != NULL);
+
+ item = item->parent;
+ while (item)
+ {
+ if (EEL_IS_CANVAS_GROUP (item))
+ {
+ *x += EEL_CANVAS_GROUP (item)->xpos;
+ *y += EEL_CANVAS_GROUP (item)->ypos;
+ }
- item = item->parent;
- }
+ item = item->parent;
+ }
}
/* Returns whether the item is an inferior of or is equal to the parent. */
static int
-is_descendant (EelCanvasItem *item, EelCanvasItem *parent)
+is_descendant (EelCanvasItem *item,
+ EelCanvasItem *parent)
{
- for (; item; item = item->parent)
- if (item == parent)
- return TRUE;
+ for (; item; item = item->parent)
+ {
+ if (item == parent)
+ {
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
/**
@@ -995,35 +1167,36 @@ is_descendant (EelCanvasItem *item, EelCanvasItem *parent)
* its absolute position within the canvas.
**/
void
-eel_canvas_item_reparent (EelCanvasItem *item, EelCanvasGroup *new_group)
+eel_canvas_item_reparent (EelCanvasItem *item,
+ EelCanvasGroup *new_group)
{
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (EEL_IS_CANVAS_GROUP (new_group));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (new_group));
- /* Both items need to be in the same canvas */
- g_return_if_fail (item->canvas == EEL_CANVAS_ITEM (new_group)->canvas);
+ /* Both items need to be in the same canvas */
+ g_return_if_fail (item->canvas == EEL_CANVAS_ITEM (new_group)->canvas);
- /* The group cannot be an inferior of the item or be the item itself --
- * this also takes care of the case where the item is the root item of
- * the canvas. */
- g_return_if_fail (!is_descendant (EEL_CANVAS_ITEM (new_group), item));
+ /* The group cannot be an inferior of the item or be the item itself --
+ * this also takes care of the case where the item is the root item of
+ * the canvas. */
+ g_return_if_fail (!is_descendant (EEL_CANVAS_ITEM (new_group), item));
- /* Everything is ok, now actually reparent the item */
+ /* Everything is ok, now actually reparent the item */
- g_object_ref (G_OBJECT (item)); /* protect it from the unref in group_remove */
+ g_object_ref (G_OBJECT (item)); /* protect it from the unref in group_remove */
- eel_canvas_item_request_redraw (item);
+ eel_canvas_item_request_redraw (item);
- group_remove (EEL_CANVAS_GROUP (item->parent), item);
- item->parent = EEL_CANVAS_ITEM (new_group);
- /* item->canvas is unchanged. */
- group_add (new_group, item);
+ group_remove (EEL_CANVAS_GROUP (item->parent), item);
+ item->parent = EEL_CANVAS_ITEM (new_group);
+ /* item->canvas is unchanged. */
+ group_add (new_group, item);
- /* Redraw and repick */
+ /* Redraw and repick */
- redraw_and_repick_if_mapped (item);
+ redraw_and_repick_if_mapped (item);
- g_object_unref (G_OBJECT (item));
+ g_object_unref (G_OBJECT (item));
}
/**
@@ -1037,34 +1210,36 @@ eel_canvas_item_reparent (EelCanvasItem *item, EelCanvasGroup *new_group)
void
eel_canvas_item_grab_focus (EelCanvasItem *item)
{
- EelCanvasItem *focused_item;
- GdkEvent ev;
+ EelCanvasItem *focused_item;
+ GdkEvent ev;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)));
- focused_item = item->canvas->focused_item;
+ focused_item = item->canvas->focused_item;
- if (focused_item) {
- ev.focus_change.type = GDK_FOCUS_CHANGE;
- ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
- ev.focus_change.send_event = FALSE;
- ev.focus_change.in = FALSE;
+ if (focused_item)
+ {
+ ev.focus_change.type = GDK_FOCUS_CHANGE;
+ ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
+ ev.focus_change.send_event = FALSE;
+ ev.focus_change.in = FALSE;
- emit_event (item->canvas, &ev);
- }
+ emit_event (item->canvas, &ev);
+ }
- item->canvas->focused_item = item;
- gtk_widget_grab_focus (GTK_WIDGET (item->canvas));
+ item->canvas->focused_item = item;
+ gtk_widget_grab_focus (GTK_WIDGET (item->canvas));
- if (focused_item) {
- ev.focus_change.type = GDK_FOCUS_CHANGE;
- ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
- ev.focus_change.send_event = FALSE;
- ev.focus_change.in = TRUE;
+ if (focused_item)
+ {
+ ev.focus_change.type = GDK_FOCUS_CHANGE;
+ ev.focus_change.window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas));
+ ev.focus_change.send_event = FALSE;
+ ev.focus_change.in = TRUE;
- emit_event (item->canvas, &ev);
- }
+ emit_event (item->canvas, &ev);
+ }
}
@@ -1080,32 +1255,46 @@ eel_canvas_item_grab_focus (EelCanvasItem *item)
* coordinate system of the item's parent.
**/
void
-eel_canvas_item_get_bounds (EelCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
+eel_canvas_item_get_bounds (EelCanvasItem *item,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- double tx1, ty1, tx2, ty2;
+ double tx1, ty1, tx2, ty2;
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- tx1 = ty1 = tx2 = ty2 = 0.0;
+ tx1 = ty1 = tx2 = ty2 = 0.0;
- /* Get the item's bounds in its coordinate system */
+ /* Get the item's bounds in its coordinate system */
- if (EEL_CANVAS_ITEM_GET_CLASS (item)->bounds)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->bounds) (item, &tx1, &ty1, &tx2, &ty2);
+ if (EEL_CANVAS_ITEM_GET_CLASS (item)->bounds)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->bounds)(item, &tx1, &ty1, &tx2, &ty2);
+ }
- /* Return the values */
+ /* Return the values */
- if (x1)
- *x1 = tx1;
+ if (x1)
+ {
+ *x1 = tx1;
+ }
- if (y1)
- *y1 = ty1;
+ if (y1)
+ {
+ *y1 = ty1;
+ }
- if (x2)
- *x2 = tx2;
+ if (x2)
+ {
+ *x2 = tx2;
+ }
- if (y2)
- *y2 = ty2;
+ if (y2)
+ {
+ *y2 = ty2;
+ }
}
@@ -1119,23 +1308,30 @@ eel_canvas_item_get_bounds (EelCanvasItem *item, double *x1, double *y1, double
void
eel_canvas_item_request_update (EelCanvasItem *item)
{
- if (NULL == item->canvas)
- return;
-
- g_return_if_fail (!item->canvas->doing_update);
-
- if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
- return;
+ if (NULL == item->canvas)
+ {
+ return;
+ }
- item->flags |= EEL_CANVAS_ITEM_NEED_UPDATE;
+ g_return_if_fail (!item->canvas->doing_update);
- if (item->parent != NULL) {
- /* Recurse up the tree */
- eel_canvas_item_request_update (item->parent);
- } else {
- /* Have reached the top of the tree, make sure the update call gets scheduled. */
- eel_canvas_request_update (item->canvas);
- }
+ if (item->flags & EEL_CANVAS_ITEM_NEED_UPDATE)
+ {
+ return;
+ }
+
+ item->flags |= EEL_CANVAS_ITEM_NEED_UPDATE;
+
+ if (item->parent != NULL)
+ {
+ /* Recurse up the tree */
+ eel_canvas_item_request_update (item->parent);
+ }
+ else
+ {
+ /* Have reached the top of the tree, make sure the update call gets scheduled. */
+ eel_canvas_request_update (item->canvas);
+ }
}
/**
@@ -1148,10 +1344,12 @@ eel_canvas_item_request_update (EelCanvasItem *item)
void
eel_canvas_item_request_redraw (EelCanvasItem *item)
{
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- eel_canvas_request_redraw (item->canvas,
- item->x1, item->y1,
- item->x2 + 1, item->y2 + 1);
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ eel_canvas_request_redraw (item->canvas,
+ item->x1, item->y1,
+ item->x2 + 1, item->y2 + 1);
+ }
}
@@ -1159,42 +1357,51 @@ eel_canvas_item_request_redraw (EelCanvasItem *item)
/*** EelCanvasGroup ***/
-enum {
- GROUP_PROP_0,
- GROUP_PROP_X,
- GROUP_PROP_Y
+enum
+{
+ GROUP_PROP_0,
+ GROUP_PROP_X,
+ GROUP_PROP_Y
};
-static void eel_canvas_group_class_init (EelCanvasGroupClass *klass);
-static void eel_canvas_group_init (EelCanvasGroup *group);
-static void eel_canvas_group_set_property(GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static void eel_canvas_group_get_property(GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void eel_canvas_group_destroy (EelCanvasItem *object);
-
-static void eel_canvas_group_update (EelCanvasItem *item,
- double i2w_dx,
- double i2w_dy,
- int flags);
-static void eel_canvas_group_unrealize (EelCanvasItem *item);
-static void eel_canvas_group_map (EelCanvasItem *item);
-static void eel_canvas_group_unmap (EelCanvasItem *item);
-static void eel_canvas_group_draw (EelCanvasItem *item,
- cairo_t *cr,
- cairo_region_t *region);
-static double eel_canvas_group_point (EelCanvasItem *item, double x, double y,
- int cx, int cy,
- EelCanvasItem **actual_item);
-static void eel_canvas_group_translate (EelCanvasItem *item, double dx, double dy);
-static void eel_canvas_group_bounds (EelCanvasItem *item, double *x1, double *y1,
- double *x2, double *y2);
+static void eel_canvas_group_class_init (EelCanvasGroupClass *klass);
+static void eel_canvas_group_init (EelCanvasGroup *group);
+static void eel_canvas_group_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void eel_canvas_group_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+static void eel_canvas_group_destroy (EelCanvasItem *object);
+
+static void eel_canvas_group_update (EelCanvasItem *item,
+ double i2w_dx,
+ double i2w_dy,
+ int flags);
+static void eel_canvas_group_unrealize (EelCanvasItem *item);
+static void eel_canvas_group_map (EelCanvasItem *item);
+static void eel_canvas_group_unmap (EelCanvasItem *item);
+static void eel_canvas_group_draw (EelCanvasItem *item,
+ cairo_t *cr,
+ cairo_region_t *region);
+static double eel_canvas_group_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item);
+static void eel_canvas_group_translate (EelCanvasItem *item,
+ double dx,
+ double dy);
+static void eel_canvas_group_bounds (EelCanvasItem *item,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2);
static EelCanvasItemClass *group_parent_class;
@@ -1211,286 +1418,335 @@ static EelCanvasItemClass *group_parent_class;
GType
eel_canvas_group_get_type (void)
{
- static GType group_type = 0;
-
- if (!group_type) {
- static const GTypeInfo group_info = {
- sizeof (EelCanvasGroupClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) eel_canvas_group_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (EelCanvasGroup),
- 0, /* n_preallocs */
- (GInstanceInitFunc) eel_canvas_group_init
-
-
- };
-
- group_type = g_type_register_static (eel_canvas_item_get_type (),
- "EelCanvasGroup",
- &group_info,
- 0);
- }
+ static GType group_type = 0;
- return group_type;
+ if (!group_type)
+ {
+ static const GTypeInfo group_info =
+ {
+ sizeof (EelCanvasGroupClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) eel_canvas_group_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EelCanvasGroup),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) eel_canvas_group_init
+ };
+
+ group_type = g_type_register_static (eel_canvas_item_get_type (),
+ "EelCanvasGroup",
+ &group_info,
+ 0);
+ }
+
+ return group_type;
}
/* Class initialization function for EelCanvasGroupClass */
static void
eel_canvas_group_class_init (EelCanvasGroupClass *klass)
{
- GObjectClass *gobject_class;
- EelCanvasItemClass *item_class;
-
- gobject_class = (GObjectClass *) klass;
- item_class = (EelCanvasItemClass *) klass;
-
- group_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->set_property = eel_canvas_group_set_property;
- gobject_class->get_property = eel_canvas_group_get_property;
-
- g_object_class_install_property
- (gobject_class, GROUP_PROP_X,
- g_param_spec_double ("x",
- _("X"),
- _("X"),
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
- g_object_class_install_property
- (gobject_class, GROUP_PROP_Y,
- g_param_spec_double ("y",
- _("Y"),
- _("Y"),
- -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- item_class->destroy = eel_canvas_group_destroy;
- item_class->update = eel_canvas_group_update;
- item_class->unrealize = eel_canvas_group_unrealize;
- item_class->map = eel_canvas_group_map;
- item_class->unmap = eel_canvas_group_unmap;
- item_class->draw = eel_canvas_group_draw;
- item_class->point = eel_canvas_group_point;
- item_class->translate = eel_canvas_group_translate;
- item_class->bounds = eel_canvas_group_bounds;
+ GObjectClass *gobject_class;
+ EelCanvasItemClass *item_class;
+
+ gobject_class = (GObjectClass *) klass;
+ item_class = (EelCanvasItemClass *) klass;
+
+ group_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = eel_canvas_group_set_property;
+ gobject_class->get_property = eel_canvas_group_get_property;
+
+ g_object_class_install_property
+ (gobject_class, GROUP_PROP_X,
+ g_param_spec_double ("x",
+ _("X"),
+ _("X"),
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class, GROUP_PROP_Y,
+ g_param_spec_double ("y",
+ _("Y"),
+ _("Y"),
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+
+ item_class->destroy = eel_canvas_group_destroy;
+ item_class->update = eel_canvas_group_update;
+ item_class->unrealize = eel_canvas_group_unrealize;
+ item_class->map = eel_canvas_group_map;
+ item_class->unmap = eel_canvas_group_unmap;
+ item_class->draw = eel_canvas_group_draw;
+ item_class->point = eel_canvas_group_point;
+ item_class->translate = eel_canvas_group_translate;
+ item_class->bounds = eel_canvas_group_bounds;
}
/* Object initialization function for EelCanvasGroup */
static void
eel_canvas_group_init (EelCanvasGroup *group)
{
- group->xpos = 0.0;
- group->ypos = 0.0;
+ group->xpos = 0.0;
+ group->ypos = 0.0;
}
/* Set_property handler for canvas groups */
static void
-eel_canvas_group_set_property (GObject *gobject, guint param_id,
- const GValue *value, GParamSpec *pspec)
-{
- EelCanvasItem *item;
- EelCanvasGroup *group;
- double old;
- gboolean moved;
-
- g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
-
- item = EEL_CANVAS_ITEM (gobject);
- group = EEL_CANVAS_GROUP (gobject);
-
- moved = FALSE;
- switch (param_id) {
- case GROUP_PROP_X:
- old = group->xpos;
- group->xpos = g_value_get_double (value);
- if (old != group->xpos)
- moved = TRUE;
- break;
-
- case GROUP_PROP_Y:
- old = group->ypos;
- group->ypos = g_value_get_double (value);
- if (old != group->ypos)
- moved = TRUE;
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
-
- if (moved) {
- item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- if (item->parent != NULL)
- eel_canvas_item_request_update (item->parent);
- else
- eel_canvas_request_update (item->canvas);
- }
+eel_canvas_group_set_property (GObject *gobject,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EelCanvasItem *item;
+ EelCanvasGroup *group;
+ double old;
+ gboolean moved;
+
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
+
+ item = EEL_CANVAS_ITEM (gobject);
+ group = EEL_CANVAS_GROUP (gobject);
+
+ moved = FALSE;
+ switch (param_id)
+ {
+ case GROUP_PROP_X:
+ {
+ old = group->xpos;
+ group->xpos = g_value_get_double (value);
+ if (old != group->xpos)
+ {
+ moved = TRUE;
+ }
+ }
+ break;
+
+ case GROUP_PROP_Y:
+ {
+ old = group->ypos;
+ group->ypos = g_value_get_double (value);
+ if (old != group->ypos)
+ {
+ moved = TRUE;
+ }
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
+
+ if (moved)
+ {
+ item->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ if (item->parent != NULL)
+ {
+ eel_canvas_item_request_update (item->parent);
+ }
+ else
+ {
+ eel_canvas_request_update (item->canvas);
+ }
+ }
}
/* Get_property handler for canvas groups */
static void
-eel_canvas_group_get_property (GObject *gobject, guint param_id,
- GValue *value, GParamSpec *pspec)
+eel_canvas_group_get_property (GObject *gobject,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EelCanvasGroup *group;
+ EelCanvasGroup *group;
- g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (gobject));
- group = EEL_CANVAS_GROUP (gobject);
+ group = EEL_CANVAS_GROUP (gobject);
- switch (param_id) {
- case GROUP_PROP_X:
- g_value_set_double (value, group->xpos);
- break;
+ switch (param_id)
+ {
+ case GROUP_PROP_X:
+ {
+ g_value_set_double (value, group->xpos);
+ }
+ break;
- case GROUP_PROP_Y:
- g_value_set_double (value, group->ypos);
- break;
+ case GROUP_PROP_Y:
+ {
+ g_value_set_double (value, group->ypos);
+ }
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
- break;
- }
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+ }
+ break;
+ }
}
/* Destroy handler for canvas groups */
static void
eel_canvas_group_destroy (EelCanvasItem *object)
{
- EelCanvasGroup *group;
- EelCanvasItem *child;
- GList *list;
+ EelCanvasGroup *group;
+ EelCanvasItem *child;
+ GList *list;
- g_return_if_fail (EEL_IS_CANVAS_GROUP (object));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (object));
- group = EEL_CANVAS_GROUP (object);
+ group = EEL_CANVAS_GROUP (object);
- list = group->item_list;
- while (list) {
- child = list->data;
- list = list->next;
+ list = group->item_list;
+ while (list)
+ {
+ child = list->data;
+ list = list->next;
- eel_canvas_item_destroy (child);
- }
+ eel_canvas_item_destroy (child);
+ }
- if (EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)
- (* EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy) (object);
+ if (EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)
+ {
+ (*EEL_CANVAS_ITEM_CLASS (group_parent_class)->destroy)(object);
+ }
}
/* Update handler for canvas groups */
static void
-eel_canvas_group_update (EelCanvasItem *item, double i2w_dx, double i2w_dy, int flags)
-{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
- double bbox_x0, bbox_y0, bbox_x1, bbox_y1;
- gboolean first = TRUE;
-
- group = EEL_CANVAS_GROUP (item);
-
- (* group_parent_class->update) (item, i2w_dx, i2w_dy, flags);
-
- bbox_x0 = 0;
- bbox_y0 = 0;
- bbox_x1 = 0;
- bbox_y1 = 0;
-
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
-
- eel_canvas_item_invoke_update (i, i2w_dx + group->xpos, i2w_dy + group->ypos, flags);
-
- if (first) {
- first = FALSE;
- bbox_x0 = i->x1;
- bbox_y0 = i->y1;
- bbox_x1 = i->x2;
- bbox_y1 = i->y2;
- } else {
- bbox_x0 = MIN (bbox_x0, i->x1);
- bbox_y0 = MIN (bbox_y0, i->y1);
- bbox_x1 = MAX (bbox_x1, i->x2);
- bbox_y1 = MAX (bbox_y1, i->y2);
- }
- }
- item->x1 = bbox_x0;
- item->y1 = bbox_y0;
- item->x2 = bbox_x1;
- item->y2 = bbox_y1;
+eel_canvas_group_update (EelCanvasItem *item,
+ double i2w_dx,
+ double i2w_dy,
+ int flags)
+{
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
+ double bbox_x0, bbox_y0, bbox_x1, bbox_y1;
+ gboolean first = TRUE;
+
+ group = EEL_CANVAS_GROUP (item);
+
+ (*group_parent_class->update)(item, i2w_dx, i2w_dy, flags);
+
+ bbox_x0 = 0;
+ bbox_y0 = 0;
+ bbox_x1 = 0;
+ bbox_y1 = 0;
+
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
+
+ eel_canvas_item_invoke_update (i, i2w_dx + group->xpos, i2w_dy + group->ypos, flags);
+
+ if (first)
+ {
+ first = FALSE;
+ bbox_x0 = i->x1;
+ bbox_y0 = i->y1;
+ bbox_x1 = i->x2;
+ bbox_y1 = i->y2;
+ }
+ else
+ {
+ bbox_x0 = MIN (bbox_x0, i->x1);
+ bbox_y0 = MIN (bbox_y0, i->y1);
+ bbox_x1 = MAX (bbox_x1, i->x2);
+ bbox_y1 = MAX (bbox_y1, i->y2);
+ }
+ }
+ item->x1 = bbox_x0;
+ item->y1 = bbox_y0;
+ item->x2 = bbox_x1;
+ item->y2 = bbox_y1;
}
/* Unrealize handler for canvas groups */
static void
eel_canvas_group_unrealize (EelCanvasItem *item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- /* Unmap group before children to avoid flash */
- if (item->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
+ /* Unmap group before children to avoid flash */
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
- if (i->flags & EEL_CANVAS_ITEM_REALIZED)
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->unrealize) (i);
- }
+ if (i->flags & EEL_CANVAS_ITEM_REALIZED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->unrealize)(i);
+ }
+ }
- (* group_parent_class->unrealize) (item);
+ (*group_parent_class->unrealize)(item);
}
/* Map handler for canvas groups */
static void
eel_canvas_group_map (EelCanvasItem *item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
- if (i->flags & EEL_CANVAS_ITEM_VISIBLE &&
- !(i->flags & EEL_CANVAS_ITEM_MAPPED)) {
- if (!(i->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->realize) (i);
-
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->map) (i);
- }
- }
+ if (i->flags & EEL_CANVAS_ITEM_VISIBLE &&
+ !(i->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ if (!(i->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->realize)(i);
+ }
- (* group_parent_class->map) (item);
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->map)(i);
+ }
+ }
+
+ (*group_parent_class->map)(item);
}
/* Unmap handler for canvas groups */
static void
eel_canvas_group_unmap (EelCanvasItem *item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *i;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *i;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- for (list = group->item_list; list; list = list->next) {
- i = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ i = list->data;
- if (i->flags & EEL_CANVAS_ITEM_MAPPED)
- (* EEL_CANVAS_ITEM_GET_CLASS (i)->unmap) (i);
- }
+ if (i->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (i)->unmap)(i);
+ }
+ }
- (* group_parent_class->unmap) (item);
+ (*group_parent_class->unmap)(item);
}
/* Draw handler for canvas groups */
@@ -1499,263 +1755,323 @@ eel_canvas_group_draw (EelCanvasItem *item,
cairo_t *cr,
cairo_region_t *region)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *child = NULL;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *child = NULL;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
- if ((child->flags & EEL_CANVAS_ITEM_MAPPED) &&
- (EEL_CANVAS_ITEM_GET_CLASS (child)->draw)) {
- GdkRectangle child_rect;
+ if ((child->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ (EEL_CANVAS_ITEM_GET_CLASS (child)->draw))
+ {
+ GdkRectangle child_rect;
- child_rect.x = child->x1;
- child_rect.y = child->y1;
- child_rect.width = child->x2 - child->x1 + 1;
- child_rect.height = child->y2 - child->y1 + 1;
+ child_rect.x = child->x1;
+ child_rect.y = child->y1;
+ child_rect.width = child->x2 - child->x1 + 1;
+ child_rect.height = child->y2 - child->y1 + 1;
- if (cairo_region_contains_rectangle (region, &child_rect) != CAIRO_REGION_OVERLAP_OUT)
- EEL_CANVAS_ITEM_GET_CLASS (child)->draw (child, cr, region);
- }
- }
+ if (cairo_region_contains_rectangle (region, &child_rect) != CAIRO_REGION_OVERLAP_OUT)
+ {
+ EEL_CANVAS_ITEM_GET_CLASS (child)->draw (child, cr, region);
+ }
+ }
+ }
}
/* Point handler for canvas groups */
static double
-eel_canvas_group_point (EelCanvasItem *item, double x, double y, int cx, int cy,
- EelCanvasItem **actual_item)
+eel_canvas_group_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item)
{
- EelCanvasGroup *group;
- GList *list;
- EelCanvasItem *child, *point_item;
- int x1, y1, x2, y2;
- double gx, gy;
- double dist, best;
- int has_point;
+ EelCanvasGroup *group;
+ GList *list;
+ EelCanvasItem *child, *point_item;
+ int x1, y1, x2, y2;
+ double gx, gy;
+ double dist, best;
+ int has_point;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- x1 = cx - item->canvas->close_enough;
- y1 = cy - item->canvas->close_enough;
- x2 = cx + item->canvas->close_enough;
- y2 = cy + item->canvas->close_enough;
+ x1 = cx - item->canvas->close_enough;
+ y1 = cy - item->canvas->close_enough;
+ x2 = cx + item->canvas->close_enough;
+ y2 = cy + item->canvas->close_enough;
- best = 0.0;
- *actual_item = NULL;
+ best = 0.0;
+ *actual_item = NULL;
- gx = x - group->xpos;
- gy = y - group->ypos;
+ gx = x - group->xpos;
+ gy = y - group->ypos;
- dist = 0.0; /* keep gcc happy */
+ dist = 0.0; /* keep gcc happy */
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
- if ((child->x1 > x2) || (child->y1 > y2) || (child->x2 < x1) || (child->y2 < y1))
- continue;
+ if ((child->x1 > x2) || (child->y1 > y2) || (child->x2 < x1) || (child->y2 < y1))
+ {
+ continue;
+ }
- point_item = NULL; /* cater for incomplete item implementations */
+ point_item = NULL; /* cater for incomplete item implementations */
- if ((child->flags & EEL_CANVAS_ITEM_MAPPED)
- && EEL_CANVAS_ITEM_GET_CLASS (child)->point) {
- dist = eel_canvas_item_invoke_point (child, gx, gy, cx, cy, &point_item);
- has_point = TRUE;
- } else
- has_point = FALSE;
+ if ((child->flags & EEL_CANVAS_ITEM_MAPPED)
+ && EEL_CANVAS_ITEM_GET_CLASS (child)->point)
+ {
+ dist = eel_canvas_item_invoke_point (child, gx, gy, cx, cy, &point_item);
+ has_point = TRUE;
+ }
+ else
+ {
+ has_point = FALSE;
+ }
- if (has_point
- && point_item
- && ((int) (dist * item->canvas->pixels_per_unit + 0.5)
- <= item->canvas->close_enough)) {
- best = dist;
- *actual_item = point_item;
- }
- }
+ if (has_point
+ && point_item
+ && ((int) (dist * item->canvas->pixels_per_unit + 0.5)
+ <= item->canvas->close_enough))
+ {
+ best = dist;
+ *actual_item = point_item;
+ }
+ }
- return best;
+ return best;
}
void
-eel_canvas_group_translate (EelCanvasItem *item, double dx, double dy)
+eel_canvas_group_translate (EelCanvasItem *item,
+ double dx,
+ double dy)
{
- EelCanvasGroup *group;
+ EelCanvasGroup *group;
- group = EEL_CANVAS_GROUP (item);
+ group = EEL_CANVAS_GROUP (item);
- group->xpos += dx;
- group->ypos += dy;
+ group->xpos += dx;
+ group->ypos += dy;
}
/* Bounds handler for canvas groups */
static void
-eel_canvas_group_bounds (EelCanvasItem *item, double *x1, double *y1, double *x2, double *y2)
+eel_canvas_group_bounds (EelCanvasItem *item,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- EelCanvasGroup *group;
- EelCanvasItem *child;
- GList *list;
- double tx1, ty1, tx2, ty2;
- double minx, miny, maxx, maxy;
- int set;
-
- group = EEL_CANVAS_GROUP (item);
+ EelCanvasGroup *group;
+ EelCanvasItem *child;
+ GList *list;
+ double tx1, ty1, tx2, ty2;
+ double minx, miny, maxx, maxy;
+ int set;
- /* Get the bounds of the first visible item */
+ group = EEL_CANVAS_GROUP (item);
- child = NULL; /* Unnecessary but eliminates a warning. */
+ /* Get the bounds of the first visible item */
- set = FALSE;
+ child = NULL; /* Unnecessary but eliminates a warning. */
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
+ set = FALSE;
- if (child->flags & EEL_CANVAS_ITEM_MAPPED) {
- set = TRUE;
- eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
- break;
- }
- }
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
- /* If there were no visible items, return an empty bounding box */
-
- if (!set) {
- *x1 = *y1 = *x2 = *y2 = 0.0;
- return;
- }
+ if (child->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ set = TRUE;
+ eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
+ break;
+ }
+ }
- /* Now we can grow the bounds using the rest of the items */
+ /* If there were no visible items, return an empty bounding box */
- list = list->next;
+ if (!set)
+ {
+ *x1 = *y1 = *x2 = *y2 = 0.0;
+ return;
+ }
- for (; list; list = list->next) {
- child = list->data;
+ /* Now we can grow the bounds using the rest of the items */
- if (!(child->flags & EEL_CANVAS_ITEM_MAPPED))
- continue;
+ list = list->next;
- eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
+ for (; list; list = list->next)
+ {
+ child = list->data;
- if (tx1 < minx)
- minx = tx1;
+ if (!(child->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ continue;
+ }
- if (ty1 < miny)
- miny = ty1;
+ eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
- if (tx2 > maxx)
- maxx = tx2;
+ if (tx1 < minx)
+ {
+ minx = tx1;
+ }
- if (ty2 > maxy)
- maxy = ty2;
- }
+ if (ty1 < miny)
+ {
+ miny = ty1;
+ }
- /* Make the bounds be relative to our parent's coordinate system */
+ if (tx2 > maxx)
+ {
+ maxx = tx2;
+ }
- if (item->parent) {
- minx += group->xpos;
- miny += group->ypos;
- maxx += group->xpos;
- maxy += group->ypos;
- }
-
- *x1 = minx;
- *y1 = miny;
- *x2 = maxx;
- *y2 = maxy;
+ if (ty2 > maxy)
+ {
+ maxy = ty2;
+ }
+ }
+
+ /* Make the bounds be relative to our parent's coordinate system */
+
+ if (item->parent)
+ {
+ minx += group->xpos;
+ miny += group->ypos;
+ maxx += group->xpos;
+ maxy += group->ypos;
+ }
+
+ *x1 = minx;
+ *y1 = miny;
+ *x2 = maxx;
+ *y2 = maxy;
}
/* Adds an item to a group */
static void
-group_add (EelCanvasGroup *group, EelCanvasItem *item)
+group_add (EelCanvasGroup *group,
+ EelCanvasItem *item)
{
- g_object_ref_sink (item);
-
- if (!group->item_list) {
- group->item_list = g_list_append (group->item_list, item);
- group->item_list_end = group->item_list;
- } else
- group->item_list_end = g_list_append (group->item_list_end, item)->next;
+ g_object_ref_sink (item);
+
+ if (!group->item_list)
+ {
+ group->item_list = g_list_append (group->item_list, item);
+ group->item_list_end = group->item_list;
+ }
+ else
+ {
+ group->item_list_end = g_list_append (group->item_list_end, item)->next;
+ }
+
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE &&
+ group->item.flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->realize)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE &&
- group->item.flags & EEL_CANVAS_ITEM_MAPPED) {
- if (!(item->flags & EEL_CANVAS_ITEM_REALIZED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->realize) (item);
-
- if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->map) (item);
- }
+ if (!(item->flags & EEL_CANVAS_ITEM_MAPPED))
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->map)(item);
+ }
+ }
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
- eel_canvas_queue_resize (EEL_CANVAS_ITEM (group)->canvas);
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ eel_canvas_queue_resize (EEL_CANVAS_ITEM (group)->canvas);
+ }
}
/* Removes an item from a group */
static void
-group_remove (EelCanvasGroup *group, EelCanvasItem *item)
+group_remove (EelCanvasGroup *group,
+ EelCanvasItem *item)
{
- GList *children;
+ GList *children;
- g_return_if_fail (EEL_IS_CANVAS_GROUP (group));
- g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
+ g_return_if_fail (EEL_IS_CANVAS_GROUP (group));
+ g_return_if_fail (EEL_IS_CANVAS_ITEM (item));
- for (children = group->item_list; children; children = children->next)
- if (children->data == item) {
- if (item->flags & EEL_CANVAS_ITEM_MAPPED) {
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unmap) (item);
- }
+ for (children = group->item_list; children; children = children->next)
+ {
+ if (children->data == item)
+ {
+ if (item->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unmap)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_REALIZED)
- (* EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize) (item);
+ if (item->flags & EEL_CANVAS_ITEM_REALIZED)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (item)->unrealize)(item);
+ }
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
- eel_canvas_queue_resize (item->canvas);
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ eel_canvas_queue_resize (item->canvas);
+ }
- /* Unparent the child */
+ /* Unparent the child */
- item->parent = NULL;
- /* item->canvas = NULL; */
- g_object_unref (G_OBJECT (item));
+ item->parent = NULL;
+ /* item->canvas = NULL; */
+ g_object_unref (G_OBJECT (item));
- /* Remove it from the list */
+ /* Remove it from the list */
- if (children == group->item_list_end)
- group->item_list_end = children->prev;
+ if (children == group->item_list_end)
+ {
+ group->item_list_end = children->prev;
+ }
- group->item_list = g_list_remove_link (group->item_list, children);
- g_list_free (children);
- break;
- }
+ group->item_list = g_list_remove_link (group->item_list, children);
+ g_list_free (children);
+ break;
+ }
+ }
}
/*** EelCanvas ***/
-static void eel_canvas_class_init (EelCanvasClass *klass);
-static void eel_canvas_init (EelCanvas *canvas);
-static void eel_canvas_destroy (GtkWidget *object);
-static void eel_canvas_map (GtkWidget *widget);
-static void eel_canvas_unmap (GtkWidget *widget);
-static void eel_canvas_realize (GtkWidget *widget);
-static void eel_canvas_unrealize (GtkWidget *widget);
-static void eel_canvas_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gint eel_canvas_button (GtkWidget *widget,
- GdkEventButton *event);
-static gint eel_canvas_motion (GtkWidget *widget,
- GdkEventMotion *event);
-static gint eel_canvas_draw (GtkWidget *widget,
- cairo_t *cr);
-static gint eel_canvas_key (GtkWidget *widget,
- GdkEventKey *event);
-static gint eel_canvas_crossing (GtkWidget *widget,
- GdkEventCrossing *event);
-static gint eel_canvas_focus_in (GtkWidget *widget,
- GdkEventFocus *event);
-static gint eel_canvas_focus_out (GtkWidget *widget,
- GdkEventFocus *event);
-static void eel_canvas_request_update_real (EelCanvas *canvas);
+static void eel_canvas_class_init (EelCanvasClass *klass);
+static void eel_canvas_init (EelCanvas *canvas);
+static void eel_canvas_destroy (GtkWidget *object);
+static void eel_canvas_map (GtkWidget *widget);
+static void eel_canvas_unmap (GtkWidget *widget);
+static void eel_canvas_realize (GtkWidget *widget);
+static void eel_canvas_unrealize (GtkWidget *widget);
+static void eel_canvas_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gint eel_canvas_button (GtkWidget *widget,
+ GdkEventButton *event);
+static gint eel_canvas_motion (GtkWidget *widget,
+ GdkEventMotion *event);
+static gint eel_canvas_draw (GtkWidget *widget,
+ cairo_t *cr);
+static gint eel_canvas_key (GtkWidget *widget,
+ GdkEventKey *event);
+static gint eel_canvas_crossing (GtkWidget *widget,
+ GdkEventCrossing *event);
+static gint eel_canvas_focus_in (GtkWidget *widget,
+ GdkEventFocus *event);
+static gint eel_canvas_focus_out (GtkWidget *widget,
+ GdkEventFocus *event);
+static void eel_canvas_request_update_real (EelCanvas *canvas);
static GtkLayoutClass *canvas_parent_class;
/**
@@ -1769,162 +2085,173 @@ static GtkLayoutClass *canvas_parent_class;
GType
eel_canvas_get_type (void)
{
- static GType canvas_type = 0;
-
- if (!canvas_type) {
- static const GTypeInfo canvas_info = {
- sizeof (EelCanvasClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) eel_canvas_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (EelCanvas),
- 0, /* n_preallocs */
- (GInstanceInitFunc) eel_canvas_init
- };
-
- canvas_type = g_type_register_static (gtk_layout_get_type (),
- "EelCanvas",
- &canvas_info,
- 0);
- }
+ static GType canvas_type = 0;
- return canvas_type;
+ if (!canvas_type)
+ {
+ static const GTypeInfo canvas_info =
+ {
+ sizeof (EelCanvasClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) eel_canvas_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (EelCanvas),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc) eel_canvas_init
+ };
+
+ canvas_type = g_type_register_static (gtk_layout_get_type (),
+ "EelCanvas",
+ &canvas_info,
+ 0);
+ }
+
+ return canvas_type;
}
static void
-eel_canvas_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+eel_canvas_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
-eel_canvas_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+eel_canvas_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- switch (prop_id) {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ switch (prop_id)
+ {
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
eel_canvas_accessible_adjustment_changed (GtkAdjustment *adjustment,
- gpointer data)
+ gpointer data)
{
- AtkObject *atk_obj;
+ AtkObject *atk_obj;
- /* The scrollbars have changed */
- atk_obj = ATK_OBJECT (data);
+ /* The scrollbars have changed */
+ atk_obj = ATK_OBJECT (data);
- g_signal_emit_by_name (atk_obj, "visible-data-changed");
+ g_signal_emit_by_name (atk_obj, "visible-data-changed");
}
static void
-eel_canvas_accessible_initialize (AtkObject *obj,
- gpointer data)
+eel_canvas_accessible_initialize (AtkObject *obj,
+ gpointer data)
{
- EelCanvas *canvas = data;
-
- if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize != NULL) {
- ATK_OBJECT_CLASS (accessible_parent_class)->initialize (obj, data);
- }
-
- gtk_accessible_set_widget (GTK_ACCESSIBLE (obj), GTK_WIDGET (data));
- g_signal_connect (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)),
- "value-changed",
- G_CALLBACK (eel_canvas_accessible_adjustment_changed),
- obj);
- g_signal_connect (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)),
- "value-changed",
- G_CALLBACK (eel_canvas_accessible_adjustment_changed),
- obj);
-
- obj->role = ATK_ROLE_LAYERED_PANE;
+ EelCanvas *canvas = data;
+
+ if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize != NULL)
+ {
+ ATK_OBJECT_CLASS (accessible_parent_class)->initialize (obj, data);
+ }
+
+ gtk_accessible_set_widget (GTK_ACCESSIBLE (obj), GTK_WIDGET (data));
+ g_signal_connect (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)),
+ "value-changed",
+ G_CALLBACK (eel_canvas_accessible_adjustment_changed),
+ obj);
+ g_signal_connect (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)),
+ "value-changed",
+ G_CALLBACK (eel_canvas_accessible_adjustment_changed),
+ obj);
+
+ obj->role = ATK_ROLE_LAYERED_PANE;
}
static gint
-eel_canvas_accessible_get_n_children (AtkObject* obj)
+eel_canvas_accessible_get_n_children (AtkObject *obj)
{
- GtkAccessible *accessible;
- GtkWidget *widget;
- EelCanvas *canvas;
- EelCanvasGroup *root_group;
+ GtkAccessible *accessible;
+ GtkWidget *widget;
+ EelCanvas *canvas;
+ EelCanvasGroup *root_group;
- accessible = GTK_ACCESSIBLE (obj);
- widget = gtk_accessible_get_widget (accessible);
+ accessible = GTK_ACCESSIBLE (obj);
+ widget = gtk_accessible_get_widget (accessible);
- if (widget == NULL) {
- return 0;
- }
+ if (widget == NULL)
+ {
+ return 0;
+ }
- g_return_val_if_fail (EEL_IS_CANVAS (widget), 0);
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), 0);
- canvas = EEL_CANVAS (widget);
- root_group = eel_canvas_root (canvas);
- g_return_val_if_fail (root_group, 0);
+ canvas = EEL_CANVAS (widget);
+ root_group = eel_canvas_root (canvas);
+ g_return_val_if_fail (root_group, 0);
- return 1;
+ return 1;
}
-static AtkObject*
+static AtkObject *
eel_canvas_accessible_ref_child (AtkObject *obj,
gint i)
{
- GtkAccessible *accessible;
- GtkWidget *widget;
- EelCanvas *canvas;
- EelCanvasGroup *root_group;
- AtkObject *atk_object;
+ GtkAccessible *accessible;
+ GtkWidget *widget;
+ EelCanvas *canvas;
+ EelCanvasGroup *root_group;
+ AtkObject *atk_object;
+
+ /* Canvas only has one child, so return NULL if index is non zero */
+ if (i != 0)
+ {
+ return NULL;
+ }
- /* Canvas only has one child, so return NULL if index is non zero */
- if (i != 0) {
- return NULL;
- }
+ accessible = GTK_ACCESSIBLE (obj);
+ widget = gtk_accessible_get_widget (accessible);
- accessible = GTK_ACCESSIBLE (obj);
- widget = gtk_accessible_get_widget (accessible);
+ if (widget == NULL)
+ {
+ return NULL;
+ }
- if (widget == NULL) {
- return NULL;
- }
+ canvas = EEL_CANVAS (widget);
+ root_group = eel_canvas_root (canvas);
+ g_return_val_if_fail (root_group, NULL);
- canvas = EEL_CANVAS (widget);
- root_group = eel_canvas_root (canvas);
- g_return_val_if_fail (root_group, NULL);
+ atk_object = atk_gobject_accessible_for_object (G_OBJECT (root_group));
- atk_object = atk_gobject_accessible_for_object (G_OBJECT (root_group));
-
- return g_object_ref (atk_object);
+ return g_object_ref (atk_object);
}
static void
eel_canvas_accessible_class_init (EelCanvasAccessibleClass *klass)
{
- AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
+ AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
- accessible_parent_class = g_type_class_peek_parent (klass);
+ accessible_parent_class = g_type_class_peek_parent (klass);
- atk_class->initialize = eel_canvas_accessible_initialize;
- atk_class->get_n_children = eel_canvas_accessible_get_n_children;
- atk_class->ref_child = eel_canvas_accessible_ref_child;
+ atk_class->initialize = eel_canvas_accessible_initialize;
+ atk_class->get_n_children = eel_canvas_accessible_get_n_children;
+ atk_class->ref_child = eel_canvas_accessible_ref_child;
}
static void
eel_canvas_accessible_init (EelCanvasAccessible *accessible)
{
-
}
G_DEFINE_TYPE (EelCanvasAccessible, eel_canvas_accessible, GTK_TYPE_CONTAINER_ACCESSIBLE)
@@ -1933,145 +2260,154 @@ G_DEFINE_TYPE (EelCanvasAccessible, eel_canvas_accessible, GTK_TYPE_CONTAINER_AC
static void
eel_canvas_class_init (EelCanvasClass *klass)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
-
- gobject_class = (GObjectClass *)klass;
- widget_class = (GtkWidgetClass *) klass;
-
- canvas_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->set_property = eel_canvas_set_property;
- gobject_class->get_property = eel_canvas_get_property;
-
- widget_class->destroy = eel_canvas_destroy;
- widget_class->map = eel_canvas_map;
- widget_class->unmap = eel_canvas_unmap;
- widget_class->realize = eel_canvas_realize;
- widget_class->unrealize = eel_canvas_unrealize;
- widget_class->size_allocate = eel_canvas_size_allocate;
- widget_class->button_press_event = eel_canvas_button;
- widget_class->button_release_event = eel_canvas_button;
- widget_class->motion_notify_event = eel_canvas_motion;
- widget_class->draw = eel_canvas_draw;
- widget_class->key_press_event = eel_canvas_key;
- widget_class->key_release_event = eel_canvas_key;
- widget_class->enter_notify_event = eel_canvas_crossing;
- widget_class->leave_notify_event = eel_canvas_crossing;
- widget_class->focus_in_event = eel_canvas_focus_in;
- widget_class->focus_out_event = eel_canvas_focus_out;
-
- klass->request_update = eel_canvas_request_update_real;
-
- gtk_widget_class_set_accessible_type (widget_class, eel_canvas_accessible_get_type ());
+ GObjectClass *gobject_class;
+ GtkWidgetClass *widget_class;
+
+ gobject_class = (GObjectClass *) klass;
+ widget_class = (GtkWidgetClass *) klass;
+
+ canvas_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = eel_canvas_set_property;
+ gobject_class->get_property = eel_canvas_get_property;
+
+ widget_class->destroy = eel_canvas_destroy;
+ widget_class->map = eel_canvas_map;
+ widget_class->unmap = eel_canvas_unmap;
+ widget_class->realize = eel_canvas_realize;
+ widget_class->unrealize = eel_canvas_unrealize;
+ widget_class->size_allocate = eel_canvas_size_allocate;
+ widget_class->button_press_event = eel_canvas_button;
+ widget_class->button_release_event = eel_canvas_button;
+ widget_class->motion_notify_event = eel_canvas_motion;
+ widget_class->draw = eel_canvas_draw;
+ widget_class->key_press_event = eel_canvas_key;
+ widget_class->key_release_event = eel_canvas_key;
+ widget_class->enter_notify_event = eel_canvas_crossing;
+ widget_class->leave_notify_event = eel_canvas_crossing;
+ widget_class->focus_in_event = eel_canvas_focus_in;
+ widget_class->focus_out_event = eel_canvas_focus_out;
+
+ klass->request_update = eel_canvas_request_update_real;
+
+ gtk_widget_class_set_accessible_type (widget_class, eel_canvas_accessible_get_type ());
}
/* Callback used when the root item of a canvas is destroyed. The user should
* never ever do this, so we panic if this happens.
*/
static void
-panic_root_destroyed (GtkWidget *object, gpointer data)
+panic_root_destroyed (GtkWidget *object,
+ gpointer data)
{
- g_error ("Eeeek, root item %p of canvas %p was destroyed!", object, data);
+ g_error ("Eeeek, root item %p of canvas %p was destroyed!", object, data);
}
/* Object initialization function for EelCanvas */
static void
eel_canvas_init (EelCanvas *canvas)
{
- guint width, height;
- gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
+ guint width, height;
+ gtk_widget_set_can_focus (GTK_WIDGET (canvas), TRUE);
- gtk_widget_set_redraw_on_allocate (GTK_WIDGET (canvas), FALSE);
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (canvas), FALSE);
- canvas->scroll_x1 = 0.0;
- canvas->scroll_y1 = 0.0;
- gtk_layout_get_size (GTK_LAYOUT (canvas),
- &width, &height);
- canvas->scroll_x2 = width;
- canvas->scroll_y2 = height;
+ canvas->scroll_x1 = 0.0;
+ canvas->scroll_y1 = 0.0;
+ gtk_layout_get_size (GTK_LAYOUT (canvas),
+ &width, &height);
+ canvas->scroll_x2 = width;
+ canvas->scroll_y2 = height;
- canvas->pixels_per_unit = 1.0;
+ canvas->pixels_per_unit = 1.0;
- canvas->pick_event.type = GDK_LEAVE_NOTIFY;
- canvas->pick_event.crossing.x = 0;
- canvas->pick_event.crossing.y = 0;
+ canvas->pick_event.type = GDK_LEAVE_NOTIFY;
+ canvas->pick_event.crossing.x = 0;
+ canvas->pick_event.crossing.y = 0;
- gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL);
- gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL);
+ gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL);
+ gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL);
- /* Create the root item as a special case */
+ /* Create the root item as a special case */
- canvas->root = EEL_CANVAS_ITEM (g_object_new (eel_canvas_group_get_type (), NULL));
- canvas->root->canvas = canvas;
+ canvas->root = EEL_CANVAS_ITEM (g_object_new (eel_canvas_group_get_type (), NULL));
+ canvas->root->canvas = canvas;
- g_object_ref_sink (canvas->root);
+ g_object_ref_sink (canvas->root);
- canvas->root_destroy_id = g_signal_connect (G_OBJECT (canvas->root),
- "destroy", G_CALLBACK (panic_root_destroyed), canvas);
+ canvas->root_destroy_id = g_signal_connect (G_OBJECT (canvas->root),
+ "destroy", G_CALLBACK (panic_root_destroyed), canvas);
- canvas->need_repick = TRUE;
- canvas->doing_update = FALSE;
+ canvas->need_repick = TRUE;
+ canvas->doing_update = FALSE;
}
/* Convenience function to remove the idle handler of a canvas */
static void
remove_idle (EelCanvas *canvas)
{
- if (canvas->idle_id == 0)
- return;
+ if (canvas->idle_id == 0)
+ {
+ return;
+ }
- g_source_remove (canvas->idle_id);
- canvas->idle_id = 0;
+ g_source_remove (canvas->idle_id);
+ canvas->idle_id = 0;
}
/* Removes the transient state of the canvas (idle handler, grabs). */
static void
shutdown_transients (EelCanvas *canvas)
{
- /* We turn off the need_redraw flag, since if the canvas is mapped again
- * it will request a redraw anyways. We do not turn off the need_update
- * flag, though, because updates are not queued when the canvas remaps
- * itself.
- */
- if (canvas->need_redraw) {
- canvas->need_redraw = FALSE;
- }
-
- if (canvas->grabbed_item) {
- eel_canvas_item_ungrab (canvas->grabbed_item);
- }
-
- remove_idle (canvas);
+ /* We turn off the need_redraw flag, since if the canvas is mapped again
+ * it will request a redraw anyways. We do not turn off the need_update
+ * flag, though, because updates are not queued when the canvas remaps
+ * itself.
+ */
+ if (canvas->need_redraw)
+ {
+ canvas->need_redraw = FALSE;
+ }
+
+ if (canvas->grabbed_item)
+ {
+ eel_canvas_item_ungrab (canvas->grabbed_item);
+ }
+
+ remove_idle (canvas);
}
/* Destroy handler for EelCanvas */
static void
eel_canvas_destroy (GtkWidget *object)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (object));
+ g_return_if_fail (EEL_IS_CANVAS (object));
- /* remember, destroy can be run multiple times! */
+ /* remember, destroy can be run multiple times! */
- canvas = EEL_CANVAS (object);
+ canvas = EEL_CANVAS (object);
- if (canvas->root_destroy_id) {
- g_signal_handler_disconnect (G_OBJECT (canvas->root), canvas->root_destroy_id);
- canvas->root_destroy_id = 0;
- }
- if (canvas->root) {
- EelCanvasItem *root = canvas->root;
- canvas->root = NULL;
- eel_canvas_item_destroy (root);
- g_object_unref (root);
- }
+ if (canvas->root_destroy_id)
+ {
+ g_signal_handler_disconnect (G_OBJECT (canvas->root), canvas->root_destroy_id);
+ canvas->root_destroy_id = 0;
+ }
+ if (canvas->root)
+ {
+ EelCanvasItem *root = canvas->root;
+ canvas->root = NULL;
+ eel_canvas_item_destroy (root);
+ g_object_unref (root);
+ }
- shutdown_transients (canvas);
+ shutdown_transients (canvas);
- if (GTK_WIDGET_CLASS (canvas_parent_class)->destroy)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->destroy) (object);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->destroy)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->destroy)(object);
+ }
}
/**
@@ -2088,237 +2424,285 @@ eel_canvas_destroy (GtkWidget *object)
GtkWidget *
eel_canvas_new (void)
{
- return GTK_WIDGET (g_object_new (eel_canvas_get_type (), NULL));
+ return GTK_WIDGET (g_object_new (eel_canvas_get_type (), NULL));
}
/* Map handler for the canvas */
static void
eel_canvas_map (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- /* Normal widget mapping stuff */
+ /* Normal widget mapping stuff */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->map)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->map) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->map)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->map)(widget);
+ }
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- /* Map items */
+ /* Map items */
- if (canvas->root->flags & EEL_CANVAS_ITEM_VISIBLE &&
- !(canvas->root->flags & EEL_CANVAS_ITEM_MAPPED) &&
- EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map)
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map) (canvas->root);
+ if (canvas->root->flags & EEL_CANVAS_ITEM_VISIBLE &&
+ !(canvas->root->flags & EEL_CANVAS_ITEM_MAPPED) &&
+ EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->map)(canvas->root);
+ }
}
/* Unmap handler for the canvas */
static void
eel_canvas_unmap (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- shutdown_transients (canvas);
+ shutdown_transients (canvas);
- /* Unmap items */
+ /* Unmap items */
- if (EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap)
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap) (canvas->root);
+ if (EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap)
+ {
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unmap)(canvas->root);
+ }
- /* Normal widget unmapping stuff */
+ /* Normal widget unmapping stuff */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->unmap)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->unmap) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->unmap)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->unmap)(widget);
+ }
}
/* Realize handler for the canvas */
static void
eel_canvas_realize (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- /* Normal widget realization stuff */
+ /* Normal widget realization stuff */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->realize)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->realize) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->realize)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->realize)(widget);
+ }
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- gdk_window_set_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
- (gdk_window_get_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- | GDK_EXPOSURE_MASK
- | GDK_BUTTON_PRESS_MASK
- | GDK_BUTTON_RELEASE_MASK
- | GDK_POINTER_MOTION_MASK
- | GDK_KEY_PRESS_MASK
- | GDK_KEY_RELEASE_MASK
- | GDK_ENTER_NOTIFY_MASK
- | GDK_LEAVE_NOTIFY_MASK
- | GDK_FOCUS_CHANGE_MASK));
+ gdk_window_set_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
+ (gdk_window_get_events (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ | GDK_EXPOSURE_MASK
+ | GDK_BUTTON_PRESS_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_POINTER_MOTION_MASK
+ | GDK_KEY_PRESS_MASK
+ | GDK_KEY_RELEASE_MASK
+ | GDK_ENTER_NOTIFY_MASK
+ | GDK_LEAVE_NOTIFY_MASK
+ | GDK_FOCUS_CHANGE_MASK));
- /* Create our own temporary pixmap gc and realize all the items */
+ /* Create our own temporary pixmap gc and realize all the items */
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->realize) (canvas->root);
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->realize)(canvas->root);
}
/* Unrealize handler for the canvas */
static void
eel_canvas_unrealize (GtkWidget *widget)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (EEL_IS_CANVAS (widget));
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- shutdown_transients (canvas);
+ shutdown_transients (canvas);
- /* Unrealize items and parent widget */
+ /* Unrealize items and parent widget */
- (* EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unrealize) (canvas->root);
+ (*EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->unrealize)(canvas->root);
- if (GTK_WIDGET_CLASS (canvas_parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->unrealize) (widget);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->unrealize)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->unrealize)(widget);
+ }
}
/* Handles scrolling of the canvas. Adjusts the scrolling and zooming offset to
* keep as much as possible of the canvas scrolling region in view.
*/
static void
-scroll_to (EelCanvas *canvas, int cx, int cy)
-{
- int scroll_width, scroll_height;
- int right_limit, bottom_limit;
- int old_zoom_xofs, old_zoom_yofs;
- int changed_x = FALSE, changed_y = FALSE;
- int canvas_width, canvas_height;
- GtkAllocation allocation;
- GtkAdjustment *vadjustment, *hadjustment;
- guint width, height;
-
- gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
- canvas_width = allocation.width;
- canvas_height = allocation.height;
-
- scroll_width = floor ((canvas->scroll_x2 - canvas->scroll_x1) * canvas->pixels_per_unit + 0.5);
- scroll_height = floor ((canvas->scroll_y2 - canvas->scroll_y1) * canvas->pixels_per_unit + 0.5);
-
- right_limit = scroll_width - canvas_width;
- bottom_limit = scroll_height - canvas_height;
-
- old_zoom_xofs = canvas->zoom_xofs;
- old_zoom_yofs = canvas->zoom_yofs;
-
- if (right_limit < 0) {
- cx = 0;
- if (canvas->center_scroll_region) {
- canvas->zoom_xofs = (canvas_width - scroll_width) / 2;
- scroll_width = canvas_width;
- } else {
- canvas->zoom_xofs = 0;
- }
- } else if (cx < 0) {
- cx = 0;
- canvas->zoom_xofs = 0;
- } else if (cx > right_limit) {
- cx = right_limit;
- canvas->zoom_xofs = 0;
- } else
- canvas->zoom_xofs = 0;
-
- if (bottom_limit < 0) {
- cy = 0;
- if (canvas->center_scroll_region) {
- canvas->zoom_yofs = (canvas_height - scroll_height) / 2;
- scroll_height = canvas_height;
- } else {
- canvas->zoom_yofs = 0;
- }
- } else if (cy < 0) {
- cy = 0;
- canvas->zoom_yofs = 0;
- } else if (cy > bottom_limit) {
- cy = bottom_limit;
- canvas->zoom_yofs = 0;
- } else
- canvas->zoom_yofs = 0;
-
- if ((canvas->zoom_xofs != old_zoom_xofs) || (canvas->zoom_yofs != old_zoom_yofs)) {
- /* This can only occur, if either canvas size or widget size changes */
- /* So I think we can request full redraw here */
- /* More stuff - we have to mark root as needing fresh affine (Lauris) */
- if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- eel_canvas_request_update (canvas);
- }
- gtk_widget_queue_draw (GTK_WIDGET (canvas));
- }
-
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
-
- if (((int) gtk_adjustment_get_value (hadjustment)) != cx) {
- gtk_adjustment_set_value (hadjustment, cx);
- changed_x = TRUE;
- }
-
- if (((int) gtk_adjustment_get_value (vadjustment)) != cy) {
- gtk_adjustment_set_value (vadjustment, cy);
- changed_y = TRUE;
- }
-
- gtk_layout_get_size (&canvas->layout, &width, &height);
- if ((scroll_width != (int) width )|| (scroll_height != (int) height)) {
- gtk_layout_set_size (GTK_LAYOUT (canvas), scroll_width, scroll_height);
- }
-
- /* Signal GtkLayout that it should do a redraw. */
- if (changed_x)
- g_signal_emit_by_name (hadjustment, "value-changed");
- if (changed_y)
- g_signal_emit_by_name (vadjustment, "value-changed");
+scroll_to (EelCanvas *canvas,
+ int cx,
+ int cy)
+{
+ int scroll_width, scroll_height;
+ int right_limit, bottom_limit;
+ int old_zoom_xofs, old_zoom_yofs;
+ int changed_x = FALSE, changed_y = FALSE;
+ int canvas_width, canvas_height;
+ GtkAllocation allocation;
+ GtkAdjustment *vadjustment, *hadjustment;
+ guint width, height;
+
+ gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
+ canvas_width = allocation.width;
+ canvas_height = allocation.height;
+
+ scroll_width = floor ((canvas->scroll_x2 - canvas->scroll_x1) * canvas->pixels_per_unit + 0.5);
+ scroll_height = floor ((canvas->scroll_y2 - canvas->scroll_y1) * canvas->pixels_per_unit + 0.5);
+
+ right_limit = scroll_width - canvas_width;
+ bottom_limit = scroll_height - canvas_height;
+
+ old_zoom_xofs = canvas->zoom_xofs;
+ old_zoom_yofs = canvas->zoom_yofs;
+
+ if (right_limit < 0)
+ {
+ cx = 0;
+ if (canvas->center_scroll_region)
+ {
+ canvas->zoom_xofs = (canvas_width - scroll_width) / 2;
+ scroll_width = canvas_width;
+ }
+ else
+ {
+ canvas->zoom_xofs = 0;
+ }
+ }
+ else if (cx < 0)
+ {
+ cx = 0;
+ canvas->zoom_xofs = 0;
+ }
+ else if (cx > right_limit)
+ {
+ cx = right_limit;
+ canvas->zoom_xofs = 0;
+ }
+ else
+ {
+ canvas->zoom_xofs = 0;
+ }
+
+ if (bottom_limit < 0)
+ {
+ cy = 0;
+ if (canvas->center_scroll_region)
+ {
+ canvas->zoom_yofs = (canvas_height - scroll_height) / 2;
+ scroll_height = canvas_height;
+ }
+ else
+ {
+ canvas->zoom_yofs = 0;
+ }
+ }
+ else if (cy < 0)
+ {
+ cy = 0;
+ canvas->zoom_yofs = 0;
+ }
+ else if (cy > bottom_limit)
+ {
+ cy = bottom_limit;
+ canvas->zoom_yofs = 0;
+ }
+ else
+ {
+ canvas->zoom_yofs = 0;
+ }
+
+ if ((canvas->zoom_xofs != old_zoom_xofs) || (canvas->zoom_yofs != old_zoom_yofs))
+ {
+ /* This can only occur, if either canvas size or widget size changes */
+ /* So I think we can request full redraw here */
+ /* More stuff - we have to mark root as needing fresh affine (Lauris) */
+ if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ eel_canvas_request_update (canvas);
+ }
+ gtk_widget_queue_draw (GTK_WIDGET (canvas));
+ }
+
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+
+ if (((int) gtk_adjustment_get_value (hadjustment)) != cx)
+ {
+ gtk_adjustment_set_value (hadjustment, cx);
+ changed_x = TRUE;
+ }
+
+ if (((int) gtk_adjustment_get_value (vadjustment)) != cy)
+ {
+ gtk_adjustment_set_value (vadjustment, cy);
+ changed_y = TRUE;
+ }
+
+ gtk_layout_get_size (&canvas->layout, &width, &height);
+ if ((scroll_width != (int) width) || (scroll_height != (int) height))
+ {
+ gtk_layout_set_size (GTK_LAYOUT (canvas), scroll_width, scroll_height);
+ }
+
+ /* Signal GtkLayout that it should do a redraw. */
+ if (changed_x)
+ {
+ g_signal_emit_by_name (hadjustment, "value-changed");
+ }
+ if (changed_y)
+ {
+ g_signal_emit_by_name (vadjustment, "value-changed");
+ }
}
/* Size allocation handler for the canvas */
static void
-eel_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+eel_canvas_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
- EelCanvas *canvas;
- GtkAdjustment *vadjustment, *hadjustment;
+ EelCanvas *canvas;
+ GtkAdjustment *vadjustment, *hadjustment;
- g_return_if_fail (EEL_IS_CANVAS (widget));
- g_return_if_fail (allocation != NULL);
+ g_return_if_fail (EEL_IS_CANVAS (widget));
+ g_return_if_fail (allocation != NULL);
- if (GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate)
- (* GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate) (widget, allocation);
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate)
+ {
+ (*GTK_WIDGET_CLASS (canvas_parent_class)->size_allocate)(widget, allocation);
+ }
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- /* Recenter the view, if appropriate */
+ /* Recenter the view, if appropriate */
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
- gtk_adjustment_set_page_size (hadjustment, allocation->width);
- gtk_adjustment_set_page_increment (hadjustment, allocation->width / 2);
+ gtk_adjustment_set_page_size (hadjustment, allocation->width);
+ gtk_adjustment_set_page_increment (hadjustment, allocation->width / 2);
- gtk_adjustment_set_page_size (vadjustment, allocation->height);
- gtk_adjustment_set_page_increment (vadjustment, allocation->height / 2);
+ gtk_adjustment_set_page_size (vadjustment, allocation->height);
+ gtk_adjustment_set_page_increment (vadjustment, allocation->height / 2);
- scroll_to (canvas,
- gtk_adjustment_get_value (hadjustment),
- gtk_adjustment_get_value (vadjustment));
+ scroll_to (canvas,
+ gtk_adjustment_get_value (hadjustment),
+ gtk_adjustment_get_value (vadjustment));
- g_signal_emit_by_name (hadjustment, "changed");
- g_signal_emit_by_name (vadjustment, "changed");
+ g_signal_emit_by_name (hadjustment, "changed");
+ g_signal_emit_by_name (vadjustment, "changed");
}
/* Emits an event for an item in the canvas, be it the current item, grabbed
@@ -2326,598 +2710,728 @@ eel_canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
*/
static int
-emit_event (EelCanvas *canvas, GdkEvent *event)
-{
- GdkEvent ev;
- gint finished;
- EelCanvasItem *item;
- EelCanvasItem *parent;
- guint mask;
-
- /* Could be an old pick event */
- if (!gtk_widget_get_realized (GTK_WIDGET (canvas))) {
- return FALSE;
- }
-
- /* Perform checks for grabbed items */
-
- if (canvas->grabbed_item &&
- !is_descendant (canvas->current_item, canvas->grabbed_item)) {
- return FALSE;
- }
-
- if (canvas->grabbed_item) {
- switch (event->type) {
- case GDK_ENTER_NOTIFY:
- mask = GDK_ENTER_NOTIFY_MASK;
- break;
+emit_event (EelCanvas *canvas,
+ GdkEvent *event)
+{
+ GdkEvent ev;
+ gint finished;
+ EelCanvasItem *item;
+ EelCanvasItem *parent;
+ guint mask;
+
+ /* Could be an old pick event */
+ if (!gtk_widget_get_realized (GTK_WIDGET (canvas)))
+ {
+ return FALSE;
+ }
+
+ /* Perform checks for grabbed items */
+
+ if (canvas->grabbed_item &&
+ !is_descendant (canvas->current_item, canvas->grabbed_item))
+ {
+ return FALSE;
+ }
+
+ if (canvas->grabbed_item)
+ {
+ switch (event->type)
+ {
+ case GDK_ENTER_NOTIFY:
+ {
+ mask = GDK_ENTER_NOTIFY_MASK;
+ }
+ break;
+
+ case GDK_LEAVE_NOTIFY:
+ {
+ mask = GDK_LEAVE_NOTIFY_MASK;
+ }
+ break;
+
+ case GDK_MOTION_NOTIFY:
+ {
+ mask = GDK_POINTER_MOTION_MASK;
+ }
+ break;
+
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ {
+ mask = GDK_BUTTON_PRESS_MASK;
+ }
+ break;
+
+ case GDK_BUTTON_RELEASE:
+ {
+ mask = GDK_BUTTON_RELEASE_MASK;
+ }
+ break;
+
+ case GDK_KEY_PRESS:
+ {
+ mask = GDK_KEY_PRESS_MASK;
+ }
+ break;
+
+ case GDK_KEY_RELEASE:
+ {
+ mask = GDK_KEY_RELEASE_MASK;
+ }
+ break;
+
+ default:
+ {
+ mask = 0;
+ }
+ break;
+ }
- case GDK_LEAVE_NOTIFY:
- mask = GDK_LEAVE_NOTIFY_MASK;
- break;
+ if (!(mask & canvas->grabbed_event_mask))
+ {
+ return FALSE;
+ }
+ }
+
+ /* Convert to world coordinates -- we have two cases because of diferent
+ * offsets of the fields in the event structures.
+ */
+
+ ev = *event;
+
+ switch (ev.type)
+ {
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ {
+ eel_canvas_window_to_world (canvas,
+ ev.crossing.x, ev.crossing.y,
+ &ev.crossing.x, &ev.crossing.y);
+ }
+ break;
+
+ case GDK_MOTION_NOTIFY:
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ {
+ eel_canvas_window_to_world (canvas,
+ ev.motion.x, ev.motion.y,
+ &ev.motion.x, &ev.motion.y);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ /* Choose where we send the event */
- case GDK_MOTION_NOTIFY:
- mask = GDK_POINTER_MOTION_MASK;
- break;
+ item = canvas->current_item;
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- mask = GDK_BUTTON_PRESS_MASK;
- break;
+ if (canvas->focused_item
+ && ((event->type == GDK_KEY_PRESS) ||
+ (event->type == GDK_KEY_RELEASE) ||
+ (event->type == GDK_FOCUS_CHANGE)))
+ {
+ item = canvas->focused_item;
+ }
- case GDK_BUTTON_RELEASE:
- mask = GDK_BUTTON_RELEASE_MASK;
- break;
+ /* The event is propagated up the hierarchy (for if someone connected to
+ * a group instead of a leaf event), and emission is stopped if a
+ * handler returns TRUE, just like for GtkWidget events.
+ */
- case GDK_KEY_PRESS:
- mask = GDK_KEY_PRESS_MASK;
- break;
+ finished = FALSE;
- case GDK_KEY_RELEASE:
- mask = GDK_KEY_RELEASE_MASK;
- break;
+ while (item && !finished)
+ {
+ g_object_ref (item);
- default:
- mask = 0;
- break;
- }
+ g_signal_emit (
+ G_OBJECT (item), item_signals[ITEM_EVENT], 0,
+ &ev, &finished);
- if (!(mask & canvas->grabbed_event_mask))
- return FALSE;
- }
+ parent = item->parent;
+ g_object_unref (item);
- /* Convert to world coordinates -- we have two cases because of diferent
- * offsets of the fields in the event structures.
- */
+ item = parent;
+ }
- ev = *event;
+ return finished;
+}
- switch (ev.type)
+/* Re-picks the current item in the canvas, based on the event's coordinates.
+ * Also emits enter/leave events for items as appropriate.
+ */
+static int
+pick_current_item (EelCanvas *canvas,
+ GdkEvent *event)
+{
+ int button_down;
+ double x, y;
+ int cx, cy;
+ int retval;
+
+ retval = FALSE;
+
+ /* If a button is down, we'll perform enter and leave events on the
+ * current item, but not enter on any other item. This is more or less
+ * like X pointer grabbing for canvas items.
+ */
+ button_down = canvas->state & (GDK_BUTTON1_MASK
+ | GDK_BUTTON2_MASK
+ | GDK_BUTTON3_MASK
+ | GDK_BUTTON4_MASK
+ | GDK_BUTTON5_MASK);
+ if (!button_down)
+ {
+ canvas->left_grabbed_item = FALSE;
+ }
+
+ /* Save the event in the canvas. This is used to synthesize enter and
+ * leave events in case the current item changes. It is also used to
+ * re-pick the current item if the current one gets deleted. Also,
+ * synthesize an enter event.
+ */
+ if (event != &canvas->pick_event)
+ {
+ if ((event->type == GDK_MOTION_NOTIFY) || (event->type == GDK_BUTTON_RELEASE))
{
- case GDK_ENTER_NOTIFY:
- case GDK_LEAVE_NOTIFY:
- eel_canvas_window_to_world (canvas,
- ev.crossing.x, ev.crossing.y,
- &ev.crossing.x, &ev.crossing.y);
- break;
+ /* these fields have the same offsets in both types of events */
+
+ canvas->pick_event.crossing.type = GDK_ENTER_NOTIFY;
+ canvas->pick_event.crossing.window = event->motion.window;
+ canvas->pick_event.crossing.send_event = event->motion.send_event;
+ canvas->pick_event.crossing.subwindow = NULL;
+ canvas->pick_event.crossing.x = event->motion.x;
+ canvas->pick_event.crossing.y = event->motion.y;
+ canvas->pick_event.crossing.mode = GDK_CROSSING_NORMAL;
+ canvas->pick_event.crossing.detail = GDK_NOTIFY_NONLINEAR;
+ canvas->pick_event.crossing.focus = FALSE;
+ canvas->pick_event.crossing.state = event->motion.state;
+
+ /* these fields don't have the same offsets in both types of events */
+
+ if (event->type == GDK_MOTION_NOTIFY)
+ {
+ canvas->pick_event.crossing.x_root = event->motion.x_root;
+ canvas->pick_event.crossing.y_root = event->motion.y_root;
+ }
+ else
+ {
+ canvas->pick_event.crossing.x_root = event->button.x_root;
+ canvas->pick_event.crossing.y_root = event->button.y_root;
+ }
+ }
+ else
+ {
+ canvas->pick_event = *event;
+ }
+ }
- case GDK_MOTION_NOTIFY:
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- case GDK_BUTTON_RELEASE:
- eel_canvas_window_to_world (canvas,
- ev.motion.x, ev.motion.y,
- &ev.motion.x, &ev.motion.y);
- break;
+ /* Don't do anything else if this is a recursive call */
- default:
- break;
- }
+ if (canvas->in_repick)
+ {
+ return retval;
+ }
- /* Choose where we send the event */
+ /* LeaveNotify means that there is no current item, so we don't look for one */
- item = canvas->current_item;
+ if (canvas->pick_event.type != GDK_LEAVE_NOTIFY)
+ {
+ /* these fields don't have the same offsets in both types of events */
- if (canvas->focused_item
- && ((event->type == GDK_KEY_PRESS) ||
- (event->type == GDK_KEY_RELEASE) ||
- (event->type == GDK_FOCUS_CHANGE)))
- item = canvas->focused_item;
+ if (canvas->pick_event.type == GDK_ENTER_NOTIFY)
+ {
+ x = canvas->pick_event.crossing.x;
+ y = canvas->pick_event.crossing.y;
+ }
+ else
+ {
+ x = canvas->pick_event.motion.x;
+ y = canvas->pick_event.motion.y;
+ }
- /* The event is propagated up the hierarchy (for if someone connected to
- * a group instead of a leaf event), and emission is stopped if a
- * handler returns TRUE, just like for GtkWidget events.
- */
+ /* canvas pixel coords */
- finished = FALSE;
+ cx = (int) (x + 0.5);
+ cy = (int) (y + 0.5);
- while (item && !finished) {
- g_object_ref (item);
+ /* world coords */
+ eel_canvas_c2w (canvas, cx, cy, &x, &y);
- g_signal_emit (
- G_OBJECT (item), item_signals[ITEM_EVENT], 0,
- &ev, &finished);
-
- parent = item->parent;
- g_object_unref (item);
+ /* find the closest item */
+ if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy,
+ &canvas->new_current_item);
+ }
+ else
+ {
+ canvas->new_current_item = NULL;
+ }
+ }
+ else
+ {
+ canvas->new_current_item = NULL;
+ }
+
+ if ((canvas->new_current_item == canvas->current_item) && !canvas->left_grabbed_item)
+ {
+ return retval; /* current item did not change */
+ }
+ /* Synthesize events for old and new current items */
+
+ if ((canvas->new_current_item != canvas->current_item)
+ && (canvas->current_item != NULL)
+ && !canvas->left_grabbed_item)
+ {
+ GdkEvent new_event;
+
+ new_event = canvas->pick_event;
+ new_event.type = GDK_LEAVE_NOTIFY;
+
+ new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
+ new_event.crossing.subwindow = NULL;
+ canvas->in_repick = TRUE;
+ retval = emit_event (canvas, &new_event);
+ canvas->in_repick = FALSE;
+ }
+
+ /* new_current_item may have been set to NULL during the call to emit_event() above */
+
+ if ((canvas->new_current_item != canvas->current_item) && button_down)
+ {
+ canvas->current_item = canvas->new_current_item;
+ canvas->left_grabbed_item = TRUE;
+ return retval;
+ }
- item = parent;
- }
+ /* Handle the rest of cases */
- return finished;
-}
+ canvas->left_grabbed_item = FALSE;
+ canvas->current_item = canvas->new_current_item;
-/* Re-picks the current item in the canvas, based on the event's coordinates.
- * Also emits enter/leave events for items as appropriate.
- */
-static int
-pick_current_item (EelCanvas *canvas, GdkEvent *event)
-{
- int button_down;
- double x, y;
- int cx, cy;
- int retval;
-
- retval = FALSE;
-
- /* If a button is down, we'll perform enter and leave events on the
- * current item, but not enter on any other item. This is more or less
- * like X pointer grabbing for canvas items.
- */
- button_down = canvas->state & (GDK_BUTTON1_MASK
- | GDK_BUTTON2_MASK
- | GDK_BUTTON3_MASK
- | GDK_BUTTON4_MASK
- | GDK_BUTTON5_MASK);
- if (!button_down)
- canvas->left_grabbed_item = FALSE;
-
- /* Save the event in the canvas. This is used to synthesize enter and
- * leave events in case the current item changes. It is also used to
- * re-pick the current item if the current one gets deleted. Also,
- * synthesize an enter event.
- */
- if (event != &canvas->pick_event) {
- if ((event->type == GDK_MOTION_NOTIFY) || (event->type == GDK_BUTTON_RELEASE)) {
- /* these fields have the same offsets in both types of events */
-
- canvas->pick_event.crossing.type = GDK_ENTER_NOTIFY;
- canvas->pick_event.crossing.window = event->motion.window;
- canvas->pick_event.crossing.send_event = event->motion.send_event;
- canvas->pick_event.crossing.subwindow = NULL;
- canvas->pick_event.crossing.x = event->motion.x;
- canvas->pick_event.crossing.y = event->motion.y;
- canvas->pick_event.crossing.mode = GDK_CROSSING_NORMAL;
- canvas->pick_event.crossing.detail = GDK_NOTIFY_NONLINEAR;
- canvas->pick_event.crossing.focus = FALSE;
- canvas->pick_event.crossing.state = event->motion.state;
-
- /* these fields don't have the same offsets in both types of events */
-
- if (event->type == GDK_MOTION_NOTIFY) {
- canvas->pick_event.crossing.x_root = event->motion.x_root;
- canvas->pick_event.crossing.y_root = event->motion.y_root;
- } else {
- canvas->pick_event.crossing.x_root = event->button.x_root;
- canvas->pick_event.crossing.y_root = event->button.y_root;
- }
- } else
- canvas->pick_event = *event;
- }
-
- /* Don't do anything else if this is a recursive call */
-
- if (canvas->in_repick)
- return retval;
-
- /* LeaveNotify means that there is no current item, so we don't look for one */
-
- if (canvas->pick_event.type != GDK_LEAVE_NOTIFY) {
- /* these fields don't have the same offsets in both types of events */
-
- if (canvas->pick_event.type == GDK_ENTER_NOTIFY) {
- x = canvas->pick_event.crossing.x;
- y = canvas->pick_event.crossing.y;
- } else {
- x = canvas->pick_event.motion.x;
- y = canvas->pick_event.motion.y;
- }
-
- /* canvas pixel coords */
-
- cx = (int) (x + 0.5);
- cy = (int) (y + 0.5);
-
- /* world coords */
- eel_canvas_c2w (canvas, cx, cy, &x, &y);
-
- /* find the closest item */
- if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
- eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy,
- &canvas->new_current_item);
- else
- canvas->new_current_item = NULL;
- } else
- canvas->new_current_item = NULL;
-
- if ((canvas->new_current_item == canvas->current_item) && !canvas->left_grabbed_item)
- return retval; /* current item did not change */
-
- /* Synthesize events for old and new current items */
-
- if ((canvas->new_current_item != canvas->current_item)
- && (canvas->current_item != NULL)
- && !canvas->left_grabbed_item) {
- GdkEvent new_event;
-
- new_event = canvas->pick_event;
- new_event.type = GDK_LEAVE_NOTIFY;
-
- new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
- new_event.crossing.subwindow = NULL;
- canvas->in_repick = TRUE;
- retval = emit_event (canvas, &new_event);
- canvas->in_repick = FALSE;
- }
-
- /* new_current_item may have been set to NULL during the call to emit_event() above */
-
- if ((canvas->new_current_item != canvas->current_item) && button_down) {
- canvas->current_item = canvas->new_current_item;
- canvas->left_grabbed_item = TRUE;
- return retval;
- }
-
- /* Handle the rest of cases */
-
- canvas->left_grabbed_item = FALSE;
- canvas->current_item = canvas->new_current_item;
-
- if (canvas->current_item != NULL) {
- GdkEvent new_event;
-
- new_event = canvas->pick_event;
- new_event.type = GDK_ENTER_NOTIFY;
- new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
- new_event.crossing.subwindow = NULL;
- retval = emit_event (canvas, &new_event);
- }
-
- return retval;
+ if (canvas->current_item != NULL)
+ {
+ GdkEvent new_event;
+
+ new_event = canvas->pick_event;
+ new_event.type = GDK_ENTER_NOTIFY;
+ new_event.crossing.detail = GDK_NOTIFY_ANCESTOR;
+ new_event.crossing.subwindow = NULL;
+ retval = emit_event (canvas, &new_event);
+ }
+
+ return retval;
}
/* Button event handler for the canvas */
static gint
-eel_canvas_button (GtkWidget *widget, GdkEventButton *event)
-{
- EelCanvas *canvas;
- int mask;
- int retval;
-
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- retval = FALSE;
-
- canvas = EEL_CANVAS (widget);
-
- /* Don't handle extra mouse button events */
- if (event->button > 5)
- return FALSE;
-
- /*
- * dispatch normally regardless of the event's window if an item has
- * has a pointer grab in effect
- */
- if (!canvas->grabbed_item && event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- return retval;
-
- switch (event->button) {
- case 1:
- mask = GDK_BUTTON1_MASK;
- break;
- case 2:
- mask = GDK_BUTTON2_MASK;
- break;
- case 3:
- mask = GDK_BUTTON3_MASK;
- break;
- case 4:
- mask = GDK_BUTTON4_MASK;
- break;
- case 5:
- mask = GDK_BUTTON5_MASK;
- break;
- default:
- mask = 0;
- }
-
- switch (event->type) {
- case GDK_BUTTON_PRESS:
- case GDK_2BUTTON_PRESS:
- case GDK_3BUTTON_PRESS:
- /* Pick the current item as if the button were not pressed, and
- * then process the event.
- */
- event->state ^= mask;
- canvas->state = event->state;
- pick_current_item (canvas, (GdkEvent *) event);
- event->state ^= mask;
- canvas->state = event->state;
- retval = emit_event (canvas, (GdkEvent *) event);
- break;
-
- case GDK_BUTTON_RELEASE:
- /* Process the event as if the button were pressed, then repick
- * after the button has been released
- */
- canvas->state = event->state;
- retval = emit_event (canvas, (GdkEvent *) event);
- event->state ^= mask;
- canvas->state = event->state;
- pick_current_item (canvas, (GdkEvent *) event);
- event->state ^= mask;
- break;
-
- default:
- g_assert_not_reached ();
- }
-
- return retval;
+eel_canvas_button (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ EelCanvas *canvas;
+ int mask;
+ int retval;
+
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ retval = FALSE;
+
+ canvas = EEL_CANVAS (widget);
+
+ /* Don't handle extra mouse button events */
+ if (event->button > 5)
+ {
+ return FALSE;
+ }
+
+ /*
+ * dispatch normally regardless of the event's window if an item has
+ * has a pointer grab in effect
+ */
+ if (!canvas->grabbed_item && event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ {
+ return retval;
+ }
+
+ switch (event->button)
+ {
+ case 1:
+ {
+ mask = GDK_BUTTON1_MASK;
+ }
+ break;
+
+ case 2:
+ {
+ mask = GDK_BUTTON2_MASK;
+ }
+ break;
+
+ case 3:
+ {
+ mask = GDK_BUTTON3_MASK;
+ }
+ break;
+
+ case 4:
+ {
+ mask = GDK_BUTTON4_MASK;
+ }
+ break;
+
+ case 5:
+ {
+ mask = GDK_BUTTON5_MASK;
+ }
+ break;
+
+ default:
+ mask = 0;
+ }
+
+ switch (event->type)
+ {
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ {
+ /* Pick the current item as if the button were not pressed, and
+ * then process the event.
+ */
+ event->state ^= mask;
+ canvas->state = event->state;
+ pick_current_item (canvas, (GdkEvent *) event);
+ event->state ^= mask;
+ canvas->state = event->state;
+ retval = emit_event (canvas, (GdkEvent *) event);
+ }
+ break;
+
+ case GDK_BUTTON_RELEASE:
+ {
+ /* Process the event as if the button were pressed, then repick
+ * after the button has been released
+ */
+ canvas->state = event->state;
+ retval = emit_event (canvas, (GdkEvent *) event);
+ event->state ^= mask;
+ canvas->state = event->state;
+ pick_current_item (canvas, (GdkEvent *) event);
+ event->state ^= mask;
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ return retval;
}
/* Motion event handler for the canvas */
static gint
-eel_canvas_motion (GtkWidget *widget, GdkEventMotion *event)
+eel_canvas_motion (GtkWidget *widget,
+ GdkEventMotion *event)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- return FALSE;
+ if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ {
+ return FALSE;
+ }
- canvas->state = event->state;
- pick_current_item (canvas, (GdkEvent *) event);
- return emit_event (canvas, (GdkEvent *) event);
+ canvas->state = event->state;
+ pick_current_item (canvas, (GdkEvent *) event);
+ return emit_event (canvas, (GdkEvent *) event);
}
/* Key event handler for the canvas */
static gint
-eel_canvas_key (GtkWidget *widget, GdkEventKey *event)
+eel_canvas_key (GtkWidget *widget,
+ GdkEventKey *event)
{
- EelCanvas *canvas;
-
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- canvas = EEL_CANVAS (widget);
-
- if (emit_event (canvas, (GdkEvent *) event))
- return TRUE;
- if (event->type == GDK_KEY_RELEASE)
- return GTK_WIDGET_CLASS (canvas_parent_class)->key_release_event (widget, event);
- else
- return GTK_WIDGET_CLASS (canvas_parent_class)->key_press_event (widget, event);
+ EelCanvas *canvas;
+
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ canvas = EEL_CANVAS (widget);
+
+ if (emit_event (canvas, (GdkEvent *) event))
+ {
+ return TRUE;
+ }
+ if (event->type == GDK_KEY_RELEASE)
+ {
+ return GTK_WIDGET_CLASS (canvas_parent_class)->key_release_event (widget, event);
+ }
+ else
+ {
+ return GTK_WIDGET_CLASS (canvas_parent_class)->key_press_event (widget, event);
+ }
}
/* Crossing event handler for the canvas */
static gint
-eel_canvas_crossing (GtkWidget *widget, GdkEventCrossing *event)
+eel_canvas_crossing (GtkWidget *widget,
+ GdkEventCrossing *event)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
+ g_return_val_if_fail (EEL_IS_CANVAS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
- canvas = EEL_CANVAS (widget);
+ canvas = EEL_CANVAS (widget);
- if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
- return FALSE;
+ if (event->window != gtk_layout_get_bin_window (GTK_LAYOUT (canvas)))
+ {
+ return FALSE;
+ }
- canvas->state = event->state;
- return pick_current_item (canvas, (GdkEvent *) event);
+ canvas->state = event->state;
+ return pick_current_item (canvas, (GdkEvent *) event);
}
/* Focus in handler for the canvas */
static gint
-eel_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event)
+eel_canvas_focus_in (GtkWidget *widget,
+ GdkEventFocus *event)
{
- EelCanvas *canvas;
-
- canvas = EEL_CANVAS (widget);
-
- if (canvas->focused_item)
- return emit_event (canvas, (GdkEvent *) event);
- else
- return FALSE;
+ EelCanvas *canvas;
+
+ canvas = EEL_CANVAS (widget);
+
+ if (canvas->focused_item)
+ {
+ return emit_event (canvas, (GdkEvent *) event);
+ }
+ else
+ {
+ return FALSE;
+ }
}
/* Focus out handler for the canvas */
static gint
-eel_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
+eel_canvas_focus_out (GtkWidget *widget,
+ GdkEventFocus *event)
{
- EelCanvas *canvas;
-
- canvas = EEL_CANVAS (widget);
-
- if (canvas->focused_item)
- return emit_event (canvas, (GdkEvent *) event);
- else
- return FALSE;
+ EelCanvas *canvas;
+
+ canvas = EEL_CANVAS (widget);
+
+ if (canvas->focused_item)
+ {
+ return emit_event (canvas, (GdkEvent *) event);
+ }
+ else
+ {
+ return FALSE;
+ }
}
static cairo_region_t *
eel_cairo_get_clip_region (cairo_t *cr)
{
- cairo_rectangle_list_t *list;
- cairo_region_t *region;
- int i;
+ cairo_rectangle_list_t *list;
+ cairo_region_t *region;
+ int i;
- list = cairo_copy_clip_rectangle_list (cr);
- if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) {
- cairo_rectangle_int_t clip_rect;
+ list = cairo_copy_clip_rectangle_list (cr);
+ if (list->status == CAIRO_STATUS_CLIP_NOT_REPRESENTABLE)
+ {
+ cairo_rectangle_int_t clip_rect;
- cairo_rectangle_list_destroy (list);
+ cairo_rectangle_list_destroy (list);
- if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
- return NULL;
- return cairo_region_create_rectangle (&clip_rect);
+ if (!gdk_cairo_get_clip_rectangle (cr, &clip_rect))
+ {
+ return NULL;
}
+ return cairo_region_create_rectangle (&clip_rect);
+ }
- region = cairo_region_create ();
- for (i = list->num_rectangles - 1; i >= 0; --i) {
- cairo_rectangle_t *rect = &list->rectangles[i];
- cairo_rectangle_int_t clip_rect;
+ region = cairo_region_create ();
+ for (i = list->num_rectangles - 1; i >= 0; --i)
+ {
+ cairo_rectangle_t *rect = &list->rectangles[i];
+ cairo_rectangle_int_t clip_rect;
- clip_rect.x = floor (rect->x);
- clip_rect.y = floor (rect->y);
- clip_rect.width = ceil (rect->x + rect->width) - clip_rect.x;
- clip_rect.height = ceil (rect->y + rect->height) - clip_rect.y;
+ clip_rect.x = floor (rect->x);
+ clip_rect.y = floor (rect->y);
+ clip_rect.width = ceil (rect->x + rect->width) - clip_rect.x;
+ clip_rect.height = ceil (rect->y + rect->height) - clip_rect.y;
- if (cairo_region_union_rectangle (region, &clip_rect) != CAIRO_STATUS_SUCCESS) {
- cairo_region_destroy (region);
- region = NULL;
- break;
- }
+ if (cairo_region_union_rectangle (region, &clip_rect) != CAIRO_STATUS_SUCCESS)
+ {
+ cairo_region_destroy (region);
+ region = NULL;
+ break;
}
+ }
- cairo_rectangle_list_destroy (list);
- return region;
+ cairo_rectangle_list_destroy (list);
+ return region;
}
/* Expose handler for the canvas */
static gboolean
-eel_canvas_draw (GtkWidget *widget, cairo_t *cr)
+eel_canvas_draw (GtkWidget *widget,
+ cairo_t *cr)
{
- EelCanvas *canvas = EEL_CANVAS (widget);
- GdkWindow *bin_window;
- cairo_region_t *region;
+ EelCanvas *canvas = EEL_CANVAS (widget);
+ GdkWindow *bin_window;
+ cairo_region_t *region;
- if (!gdk_cairo_get_clip_rectangle (cr, NULL))
- return FALSE;
+ if (!gdk_cairo_get_clip_rectangle (cr, NULL))
+ {
+ return FALSE;
+ }
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
- if (!gtk_cairo_should_draw_window (cr, bin_window))
- return FALSE;
+ if (!gtk_cairo_should_draw_window (cr, bin_window))
+ {
+ return FALSE;
+ }
- cairo_save (cr);
+ cairo_save (cr);
- gtk_cairo_transform_to_window (cr, widget, bin_window);
+ gtk_cairo_transform_to_window (cr, widget, bin_window);
- region = eel_cairo_get_clip_region (cr);
- if (region == NULL) {
- cairo_restore (cr);
- return FALSE;
- }
+ region = eel_cairo_get_clip_region (cr);
+ if (region == NULL)
+ {
+ cairo_restore (cr);
+ return FALSE;
+ }
#ifdef VERBOSE
- g_print ("Draw\n");
+ g_print ("Draw\n");
#endif
- /* If there are any outstanding items that need updating, do them now */
- if (canvas->idle_id) {
- g_source_remove (canvas->idle_id);
- canvas->idle_id = 0;
- }
- if (canvas->need_update) {
- g_return_val_if_fail (!canvas->doing_update, FALSE);
+ /* If there are any outstanding items that need updating, do them now */
+ if (canvas->idle_id)
+ {
+ g_source_remove (canvas->idle_id);
+ canvas->idle_id = 0;
+ }
+ if (canvas->need_update)
+ {
+ g_return_val_if_fail (!canvas->doing_update, FALSE);
- canvas->doing_update = TRUE;
- eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
+ canvas->doing_update = TRUE;
+ eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
- g_return_val_if_fail (canvas->doing_update, FALSE);
+ g_return_val_if_fail (canvas->doing_update, FALSE);
- canvas->doing_update = FALSE;
+ canvas->doing_update = FALSE;
- canvas->need_update = FALSE;
- }
+ canvas->need_update = FALSE;
+ }
- if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
- EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->draw (canvas->root, cr, region);
+ if (canvas->root->flags & EEL_CANVAS_ITEM_MAPPED)
+ {
+ EEL_CANVAS_ITEM_GET_CLASS (canvas->root)->draw (canvas->root, cr, region);
+ }
- cairo_restore (cr);
+ cairo_restore (cr);
- /* Chain up to get exposes on child widgets */
- if (GTK_WIDGET_CLASS (canvas_parent_class)->draw)
- GTK_WIDGET_CLASS (canvas_parent_class)->draw (widget, cr);
+ /* Chain up to get exposes on child widgets */
+ if (GTK_WIDGET_CLASS (canvas_parent_class)->draw)
+ {
+ GTK_WIDGET_CLASS (canvas_parent_class)->draw (widget, cr);
+ }
- cairo_region_destroy (region);
- return FALSE;
+ cairo_region_destroy (region);
+ return FALSE;
}
static void
do_update (EelCanvas *canvas)
{
- /* Cause the update if necessary */
+ /* Cause the update if necessary */
update_again:
- if (canvas->need_update) {
- g_return_if_fail (!canvas->doing_update);
+ if (canvas->need_update)
+ {
+ g_return_if_fail (!canvas->doing_update);
- canvas->doing_update = TRUE;
- eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
+ canvas->doing_update = TRUE;
+ eel_canvas_item_invoke_update (canvas->root, 0, 0, 0);
- g_return_if_fail (canvas->doing_update);
+ g_return_if_fail (canvas->doing_update);
- canvas->doing_update = FALSE;
+ canvas->doing_update = FALSE;
- canvas->need_update = FALSE;
- }
+ canvas->need_update = FALSE;
+ }
- /* Pick new current item */
+ /* Pick new current item */
- while (canvas->need_repick) {
- canvas->need_repick = FALSE;
- pick_current_item (canvas, &canvas->pick_event);
- }
+ while (canvas->need_repick)
+ {
+ canvas->need_repick = FALSE;
+ pick_current_item (canvas, &canvas->pick_event);
+ }
- /* it is possible that during picking we emitted an event in which
- the user then called some function which then requested update
- of something. Without this we'd be left in a state where
- need_update would have been left TRUE and the canvas would have
- been left unpainted. */
- if (canvas->need_update) {
- goto update_again;
- }
+ /* it is possible that during picking we emitted an event in which
+ * the user then called some function which then requested update
+ * of something. Without this we'd be left in a state where
+ * need_update would have been left TRUE and the canvas would have
+ * been left unpainted. */
+ if (canvas->need_update)
+ {
+ goto update_again;
+ }
}
/* Idle handler for the canvas. It deals with pending updates and redraws. */
static gint
idle_handler (gpointer data)
{
- EelCanvas *canvas;
+ EelCanvas *canvas;
- canvas = EEL_CANVAS (data);
- do_update (canvas);
+ canvas = EEL_CANVAS (data);
+ do_update (canvas);
- /* Reset idle id */
- canvas->idle_id = 0;
+ /* Reset idle id */
+ canvas->idle_id = 0;
- return FALSE;
+ return FALSE;
}
/* Convenience function to add an idle handler to a canvas */
static void
add_idle (EelCanvas *canvas)
{
- if (!canvas->idle_id) {
- /* We let the update idle handler have higher priority
- * than the redraw idle handler so the canvas state
- * will be updated during the expose event. canvas in
- * expose_event.
- */
- canvas->idle_id = g_idle_add_full (GDK_PRIORITY_REDRAW - 20,
- idle_handler, canvas, NULL);
- }
+ if (!canvas->idle_id)
+ {
+ /* We let the update idle handler have higher priority
+ * than the redraw idle handler so the canvas state
+ * will be updated during the expose event. canvas in
+ * expose_event.
+ */
+ canvas->idle_id = g_idle_add_full (GDK_PRIORITY_REDRAW - 20,
+ idle_handler, canvas, NULL);
+ }
}
/**
@@ -2931,9 +3445,9 @@ add_idle (EelCanvas *canvas)
EelCanvasGroup *
eel_canvas_root (EelCanvas *canvas)
{
- g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
+ g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
- return EEL_CANVAS_GROUP (canvas->root);
+ return EEL_CANVAS_GROUP (canvas->root);
}
@@ -2950,48 +3464,54 @@ eel_canvas_root (EelCanvas *canvas)
* is adjusted as appropriate to display as much of the new region as possible.
**/
void
-eel_canvas_set_scroll_region (EelCanvas *canvas, double x1, double y1, double x2, double y2)
+eel_canvas_set_scroll_region (EelCanvas *canvas,
+ double x1,
+ double y1,
+ double x2,
+ double y2)
{
- double wxofs, wyofs;
- int xofs, yofs;
- GtkAdjustment *vadjustment, *hadjustment;
-
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- if ((canvas->scroll_x1 == x1) && (canvas->scroll_y1 == y1) &&
- (canvas->scroll_x2 == x2) && (canvas->scroll_y2 == y2)) {
- return;
- }
-
- /*
- * Set the new scrolling region. If possible, do not move the visible contents of the
- * canvas.
- */
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
-
- eel_canvas_c2w (canvas,
- gtk_adjustment_get_value (hadjustment) + canvas->zoom_xofs,
- gtk_adjustment_get_value (vadjustment) + canvas->zoom_yofs,
- /*canvas->zoom_xofs,
- canvas->zoom_yofs,*/
- &wxofs, &wyofs);
+ double wxofs, wyofs;
+ int xofs, yofs;
+ GtkAdjustment *vadjustment, *hadjustment;
- canvas->scroll_x1 = x1;
- canvas->scroll_y1 = y1;
- canvas->scroll_x2 = x2;
- canvas->scroll_y2 = y2;
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- eel_canvas_w2c (canvas, wxofs, wyofs, &xofs, &yofs);
-
- scroll_to (canvas, xofs, yofs);
-
- canvas->need_repick = TRUE;
-
- if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- eel_canvas_request_update (canvas);
- }
+ if ((canvas->scroll_x1 == x1) && (canvas->scroll_y1 == y1) &&
+ (canvas->scroll_x2 == x2) && (canvas->scroll_y2 == y2))
+ {
+ return;
+ }
+
+ /*
+ * Set the new scrolling region. If possible, do not move the visible contents of the
+ * canvas.
+ */
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+
+ eel_canvas_c2w (canvas,
+ gtk_adjustment_get_value (hadjustment) + canvas->zoom_xofs,
+ gtk_adjustment_get_value (vadjustment) + canvas->zoom_yofs,
+ /*canvas->zoom_xofs,
+ * canvas->zoom_yofs,*/
+ &wxofs, &wyofs);
+
+ canvas->scroll_x1 = x1;
+ canvas->scroll_y1 = y1;
+ canvas->scroll_x2 = x2;
+ canvas->scroll_y2 = y2;
+
+ eel_canvas_w2c (canvas, wxofs, wyofs, &xofs, &yofs);
+
+ scroll_to (canvas, xofs, yofs);
+
+ canvas->need_repick = TRUE;
+
+ if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ eel_canvas_request_update (canvas);
+ }
}
@@ -3006,39 +3526,51 @@ eel_canvas_set_scroll_region (EelCanvas *canvas, double x1, double y1, double x2
* Queries the scrolling region of a canvas.
**/
void
-eel_canvas_get_scroll_region (EelCanvas *canvas, double *x1, double *y1, double *x2, double *y2)
+eel_canvas_get_scroll_region (EelCanvas *canvas,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- if (x1)
- *x1 = canvas->scroll_x1;
-
- if (y1)
- *y1 = canvas->scroll_y1;
-
- if (x2)
- *x2 = canvas->scroll_x2;
-
- if (y2)
- *y2 = canvas->scroll_y2;
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+
+ if (x1)
+ {
+ *x1 = canvas->scroll_x1;
+ }
+
+ if (y1)
+ {
+ *y1 = canvas->scroll_y1;
+ }
+
+ if (x2)
+ {
+ *x2 = canvas->scroll_x2;
+ }
+
+ if (y2)
+ {
+ *y2 = canvas->scroll_y2;
+ }
}
void
eel_canvas_set_center_scroll_region (EelCanvas *canvas,
- gboolean center_scroll_region)
+ gboolean center_scroll_region)
{
- GtkAdjustment *vadjustment, *hadjustment;
+ GtkAdjustment *vadjustment, *hadjustment;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- canvas->center_scroll_region = center_scroll_region != 0;
+ canvas->center_scroll_region = center_scroll_region != 0;
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (&canvas->layout));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (&canvas->layout));
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (&canvas->layout));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (&canvas->layout));
- scroll_to (canvas,
- gtk_adjustment_get_value (hadjustment),
- gtk_adjustment_get_value (vadjustment));
+ scroll_to (canvas,
+ gtk_adjustment_get_value (hadjustment),
+ gtk_adjustment_get_value (vadjustment));
}
@@ -3051,85 +3583,89 @@ eel_canvas_set_center_scroll_region (EelCanvas *canvas,
* correspond to one canvas unit.
**/
void
-eel_canvas_set_pixels_per_unit (EelCanvas *canvas, double n)
-{
- GtkWidget *widget;
- double cx, cy;
- int x1, y1;
- int center_x, center_y;
- GdkWindow *window;
- GdkWindowAttr attributes;
- gint attributes_mask;
- GtkAllocation allocation;
- GtkAdjustment *vadjustment, *hadjustment;
-
- g_return_if_fail (EEL_IS_CANVAS (canvas));
- g_return_if_fail (n > EEL_CANVAS_EPSILON);
-
- widget = GTK_WIDGET (canvas);
-
- gtk_widget_get_allocation (widget, &allocation);
- center_x = allocation.width / 2;
- center_y = allocation.height / 2;
-
- /* Find the coordinates of the screen center in units. */
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
- cx = (gtk_adjustment_get_value (hadjustment) + center_x) / canvas->pixels_per_unit + canvas->scroll_x1 + canvas->zoom_xofs;
- cy = (gtk_adjustment_get_value (vadjustment) + center_y) / canvas->pixels_per_unit + canvas->scroll_y1 + canvas->zoom_yofs;
-
- /* Now calculate the new offset of the upper left corner. (round not truncate) */
- x1 = ((cx - canvas->scroll_x1) * n) - center_x + .5;
- y1 = ((cy - canvas->scroll_y1) * n) - center_y + .5;
-
- canvas->pixels_per_unit = n;
-
- if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE)) {
- canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
- eel_canvas_request_update (canvas);
- }
-
- /* Map a background None window over the bin_window to avoid
- * scrolling the window scroll causing exposes.
- */
- window = NULL;
- if (gtk_widget_get_mapped (widget)) {
- GtkAllocation allocation;
- attributes.window_type = GDK_WINDOW_CHILD;
- gtk_widget_get_allocation (widget, &allocation);
- attributes.x = allocation.x;
- attributes.y = allocation.y;
- attributes.width = allocation.width;
- attributes.height = allocation.height;
- attributes.wclass = GDK_INPUT_OUTPUT;
- attributes.visual = gtk_widget_get_visual (widget);
- attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
-
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
-
- window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
- gdk_window_set_user_data (window, widget);
-
- gdk_window_show (window);
- }
-
- scroll_to (canvas, x1, y1);
-
- /* If we created a an overlapping background None window, remove it how.
- *
- * TODO: We would like to temporarily set the bin_window background to
- * None to avoid clearing the bin_window to the background, but gdk doesn't
- * expose enought to let us do this, so we get a flash-effect here. At least
- * it looks better than scroll + expose.
- */
- if (window != NULL) {
- gdk_window_hide (window);
- gdk_window_set_user_data (window, NULL);
- gdk_window_destroy (window);
- }
-
- canvas->need_repick = TRUE;
+eel_canvas_set_pixels_per_unit (EelCanvas *canvas,
+ double n)
+{
+ GtkWidget *widget;
+ double cx, cy;
+ int x1, y1;
+ int center_x, center_y;
+ GdkWindow *window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ GtkAllocation allocation;
+ GtkAdjustment *vadjustment, *hadjustment;
+
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (n > EEL_CANVAS_EPSILON);
+
+ widget = GTK_WIDGET (canvas);
+
+ gtk_widget_get_allocation (widget, &allocation);
+ center_x = allocation.width / 2;
+ center_y = allocation.height / 2;
+
+ /* Find the coordinates of the screen center in units. */
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+ cx = (gtk_adjustment_get_value (hadjustment) + center_x) / canvas->pixels_per_unit + canvas->scroll_x1 + canvas->zoom_xofs;
+ cy = (gtk_adjustment_get_value (vadjustment) + center_y) / canvas->pixels_per_unit + canvas->scroll_y1 + canvas->zoom_yofs;
+
+ /* Now calculate the new offset of the upper left corner. (round not truncate) */
+ x1 = ((cx - canvas->scroll_x1) * n) - center_x + .5;
+ y1 = ((cy - canvas->scroll_y1) * n) - center_y + .5;
+
+ canvas->pixels_per_unit = n;
+
+ if (!(canvas->root->flags & EEL_CANVAS_ITEM_NEED_DEEP_UPDATE))
+ {
+ canvas->root->flags |= EEL_CANVAS_ITEM_NEED_DEEP_UPDATE;
+ eel_canvas_request_update (canvas);
+ }
+
+ /* Map a background None window over the bin_window to avoid
+ * scrolling the window scroll causing exposes.
+ */
+ window = NULL;
+ if (gtk_widget_get_mapped (widget))
+ {
+ GtkAllocation allocation;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ gtk_widget_get_allocation (widget, &allocation);
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
+
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
+
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (window, widget);
+
+ gdk_window_show (window);
+ }
+
+ scroll_to (canvas, x1, y1);
+
+ /* If we created a an overlapping background None window, remove it how.
+ *
+ * TODO: We would like to temporarily set the bin_window background to
+ * None to avoid clearing the bin_window to the background, but gdk doesn't
+ * expose enought to let us do this, so we get a flash-effect here. At least
+ * it looks better than scroll + expose.
+ */
+ if (window != NULL)
+ {
+ gdk_window_hide (window);
+ gdk_window_set_user_data (window, NULL);
+ gdk_window_destroy (window);
+ }
+
+ canvas->need_repick = TRUE;
}
/**
@@ -3144,11 +3680,13 @@ eel_canvas_set_pixels_per_unit (EelCanvas *canvas, double n)
* scrollbars to the canvas layout's scrolling adjusments.
**/
void
-eel_canvas_scroll_to (EelCanvas *canvas, int cx, int cy)
+eel_canvas_scroll_to (EelCanvas *canvas,
+ int cx,
+ int cy)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- scroll_to (canvas, cx, cy);
+ scroll_to (canvas, cx, cy);
}
/**
@@ -3161,20 +3699,26 @@ eel_canvas_scroll_to (EelCanvas *canvas, int cx, int cy)
* pixel units.
**/
void
-eel_canvas_get_scroll_offsets (EelCanvas *canvas, int *cx, int *cy)
+eel_canvas_get_scroll_offsets (EelCanvas *canvas,
+ int *cx,
+ int *cy)
{
- GtkAdjustment *vadjustment, *hadjustment;
+ GtkAdjustment *vadjustment, *hadjustment;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+ hadjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
- if (cx)
- *cx = gtk_adjustment_get_value (hadjustment);
+ if (cx)
+ {
+ *cx = gtk_adjustment_get_value (hadjustment);
+ }
- if (cy)
- *cy = gtk_adjustment_get_value (vadjustment);
+ if (cy)
+ {
+ *cy = gtk_adjustment_get_value (vadjustment);
+ }
}
/**
@@ -3189,12 +3733,14 @@ eel_canvas_get_scroll_offsets (EelCanvas *canvas, int *cx, int *cy)
void
eel_canvas_update_now (EelCanvas *canvas)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- if (!(canvas->need_update || canvas->need_redraw))
- return;
- remove_idle (canvas);
- do_update (canvas);
+ if (!(canvas->need_update || canvas->need_redraw))
+ {
+ return;
+ }
+ remove_idle (canvas);
+ do_update (canvas);
}
/**
@@ -3210,35 +3756,41 @@ eel_canvas_update_now (EelCanvas *canvas)
* coordinates.
**/
EelCanvasItem *
-eel_canvas_get_item_at (EelCanvas *canvas, double x, double y)
+eel_canvas_get_item_at (EelCanvas *canvas,
+ double x,
+ double y)
{
- EelCanvasItem *item;
- double dist;
- int cx, cy;
-
- g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
-
- eel_canvas_w2c (canvas, x, y, &cx, &cy);
-
- dist = eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy, &item);
- if ((int) (dist * canvas->pixels_per_unit + 0.5) <= canvas->close_enough)
- return item;
- else
- return NULL;
+ EelCanvasItem *item;
+ double dist;
+ int cx, cy;
+
+ g_return_val_if_fail (EEL_IS_CANVAS (canvas), NULL);
+
+ eel_canvas_w2c (canvas, x, y, &cx, &cy);
+
+ dist = eel_canvas_item_invoke_point (canvas->root, x, y, cx, cy, &item);
+ if ((int) (dist * canvas->pixels_per_unit + 0.5) <= canvas->close_enough)
+ {
+ return item;
+ }
+ else
+ {
+ return NULL;
+ }
}
/* Queues an update of the canvas */
static void
eel_canvas_request_update (EelCanvas *canvas)
{
- EEL_CANVAS_GET_CLASS (canvas)->request_update (canvas);
+ EEL_CANVAS_GET_CLASS (canvas)->request_update (canvas);
}
static void
eel_canvas_request_update_real (EelCanvas *canvas)
{
- canvas->need_update = TRUE;
- add_idle (canvas);
+ canvas->need_update = TRUE;
+ add_idle (canvas);
}
/**
@@ -3254,22 +3806,29 @@ eel_canvas_request_update_real (EelCanvas *canvas)
* To be used only by item implementations.
**/
void
-eel_canvas_request_redraw (EelCanvas *canvas, int x1, int y1, int x2, int y2)
+eel_canvas_request_redraw (EelCanvas *canvas,
+ int x1,
+ int y1,
+ int x2,
+ int y2)
{
- GdkRectangle bbox;
+ GdkRectangle bbox;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- if (!gtk_widget_is_drawable (GTK_WIDGET (canvas))
- || (x1 >= x2) || (y1 >= y2)) return;
+ if (!gtk_widget_is_drawable (GTK_WIDGET (canvas))
+ || (x1 >= x2) || (y1 >= y2))
+ {
+ return;
+ }
- bbox.x = x1;
- bbox.y = y1;
- bbox.width = x2 - x1;
- bbox.height = y2 - y1;
+ bbox.x = x1;
+ bbox.y = y1;
+ bbox.width = x2 - x1;
+ bbox.height = y2 - y1;
- gdk_window_invalidate_rect (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
- &bbox, FALSE);
+ gdk_window_invalidate_rect (gtk_layout_get_bin_window (GTK_LAYOUT (canvas)),
+ &bbox, FALSE);
}
/**
@@ -3283,18 +3842,26 @@ eel_canvas_request_redraw (EelCanvas *canvas, int x1, int y1, int x2, int y2)
* Converts world coordinates into canvas pixel coordinates.
**/
void
-eel_canvas_w2c (EelCanvas *canvas, double wx, double wy, int *cx, int *cy)
+eel_canvas_w2c (EelCanvas *canvas,
+ double wx,
+ double wy,
+ int *cx,
+ int *cy)
{
- double zoom;
+ double zoom;
+
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+
+ zoom = canvas->pixels_per_unit;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- zoom = canvas->pixels_per_unit;
-
- if (cx)
- *cx = floor ((wx - canvas->scroll_x1)*zoom + canvas->zoom_xofs + 0.5);
- if (cy)
- *cy = floor ((wy - canvas->scroll_y1)*zoom + canvas->zoom_yofs + 0.5);
+ if (cx)
+ {
+ *cx = floor ((wx - canvas->scroll_x1) * zoom + canvas->zoom_xofs + 0.5);
+ }
+ if (cy)
+ {
+ *cy = floor ((wy - canvas->scroll_y1) * zoom + canvas->zoom_yofs + 0.5);
+ }
}
/**
@@ -3307,15 +3874,17 @@ eel_canvas_w2c (EelCanvas *canvas, double wx, double wy, int *cx, int *cy)
**/
void
eel_canvas_w2c_rect_d (EelCanvas *canvas,
- double *x1, double *y1,
- double *x2, double *y2)
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- eel_canvas_w2c_d (canvas,
- *x1, *y1,
- x1, y1);
- eel_canvas_w2c_d (canvas,
- *x2, *y2,
- x2, y2);
+ eel_canvas_w2c_d (canvas,
+ *x1, *y1,
+ x1, y1);
+ eel_canvas_w2c_d (canvas,
+ *x2, *y2,
+ x2, y2);
}
@@ -3332,18 +3901,26 @@ eel_canvas_w2c_rect_d (EelCanvas *canvas,
* produces coordinates in floating point coordinates, for greater precision.
**/
void
-eel_canvas_w2c_d (EelCanvas *canvas, double wx, double wy, double *cx, double *cy)
+eel_canvas_w2c_d (EelCanvas *canvas,
+ double wx,
+ double wy,
+ double *cx,
+ double *cy)
{
- double zoom;
+ double zoom;
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- zoom = canvas->pixels_per_unit;
-
- if (cx)
- *cx = (wx - canvas->scroll_x1)*zoom + canvas->zoom_xofs;
- if (cy)
- *cy = (wy - canvas->scroll_y1)*zoom + canvas->zoom_yofs;
+ zoom = canvas->pixels_per_unit;
+
+ if (cx)
+ {
+ *cx = (wx - canvas->scroll_x1) * zoom + canvas->zoom_xofs;
+ }
+ if (cy)
+ {
+ *cy = (wy - canvas->scroll_y1) * zoom + canvas->zoom_yofs;
+ }
}
@@ -3358,18 +3935,26 @@ eel_canvas_w2c_d (EelCanvas *canvas, double wx, double wy, double *cx, double *c
* Converts canvas pixel coordinates to world coordinates.
**/
void
-eel_canvas_c2w (EelCanvas *canvas, int cx, int cy, double *wx, double *wy)
+eel_canvas_c2w (EelCanvas *canvas,
+ int cx,
+ int cy,
+ double *wx,
+ double *wy)
{
- double zoom;
+ double zoom;
+
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ zoom = canvas->pixels_per_unit;
- zoom = canvas->pixels_per_unit;
-
- if (wx)
- *wx = (cx - canvas->zoom_xofs)/zoom + canvas->scroll_x1;
- if (wy)
- *wy = (cy - canvas->zoom_yofs)/zoom + canvas->scroll_y1;
+ if (wx)
+ {
+ *wx = (cx - canvas->zoom_xofs) / zoom + canvas->scroll_x1;
+ }
+ if (wy)
+ {
+ *wy = (cy - canvas->zoom_yofs) / zoom + canvas->scroll_y1;
+ }
}
@@ -3388,18 +3973,25 @@ eel_canvas_c2w (EelCanvas *canvas, int cx, int cy, double *wx, double *wy)
* function is here for backwards compatibility reasons.
**/
void
-eel_canvas_window_to_world (EelCanvas *canvas, double winx, double winy,
- double *worldx, double *worldy)
+eel_canvas_window_to_world (EelCanvas *canvas,
+ double winx,
+ double winy,
+ double *worldx,
+ double *worldy)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
-
- if (worldx)
- *worldx = canvas->scroll_x1 + ((winx - canvas->zoom_xofs)
- / canvas->pixels_per_unit);
-
- if (worldy)
- *worldy = canvas->scroll_y1 + ((winy - canvas->zoom_yofs)
- / canvas->pixels_per_unit);
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
+
+ if (worldx)
+ {
+ *worldx = canvas->scroll_x1 + ((winx - canvas->zoom_xofs)
+ / canvas->pixels_per_unit);
+ }
+
+ if (worldy)
+ {
+ *worldy = canvas->scroll_y1 + ((winy - canvas->zoom_yofs)
+ / canvas->pixels_per_unit);
+ }
}
@@ -3416,361 +4008,391 @@ eel_canvas_window_to_world (EelCanvas *canvas, double winx, double winy,
* function is here for backwards compatibility reasons.
**/
void
-eel_canvas_world_to_window (EelCanvas *canvas, double worldx, double worldy,
- double *winx, double *winy)
+eel_canvas_world_to_window (EelCanvas *canvas,
+ double worldx,
+ double worldy,
+ double *winx,
+ double *winy)
{
- g_return_if_fail (EEL_IS_CANVAS (canvas));
+ g_return_if_fail (EEL_IS_CANVAS (canvas));
- if (winx)
- *winx = (canvas->pixels_per_unit)*(worldx - canvas->scroll_x1) + canvas->zoom_xofs;
+ if (winx)
+ {
+ *winx = (canvas->pixels_per_unit) * (worldx - canvas->scroll_x1) + canvas->zoom_xofs;
+ }
- if (winy)
- *winy = (canvas->pixels_per_unit)*(worldy - canvas->scroll_y1) + canvas->zoom_yofs;
+ if (winy)
+ {
+ *winy = (canvas->pixels_per_unit) * (worldy - canvas->scroll_y1) + canvas->zoom_yofs;
+ }
}
static gboolean
boolean_handled_accumulator (GSignalInvocationHint *ihint,
- GValue *return_accu,
- const GValue *handler_return,
- gpointer dummy)
+ GValue *return_accu,
+ const GValue *handler_return,
+ gpointer dummy)
{
- gboolean continue_emission;
- gboolean signal_handled;
-
- signal_handled = g_value_get_boolean (handler_return);
- g_value_set_boolean (return_accu, signal_handled);
- continue_emission = !signal_handled;
-
- return continue_emission;
+ gboolean continue_emission;
+ gboolean signal_handled;
+
+ signal_handled = g_value_get_boolean (handler_return);
+ g_value_set_boolean (return_accu, signal_handled);
+ continue_emission = !signal_handled;
+
+ return continue_emission;
}
static void
eel_canvas_item_accessible_get_item_extents (EelCanvasItem *item,
GdkRectangle *rect)
{
- double bx1, bx2, by1, by2;
- gint scroll_x, scroll_y;
- gint x1, x2, y1, y2;
-
- eel_canvas_item_get_bounds (item, &bx1, &by1, &bx2, &by2);
- eel_canvas_w2c_rect_d (item->canvas, &bx1, &by1, &bx2, &by2);
- eel_canvas_get_scroll_offsets (item->canvas, &scroll_x, &scroll_y);
- x1 = floor (bx1 + .5);
- y1 = floor (by1 + .5);
- x2 = floor (bx2 + .5);
- y2 = floor (by2 + .5);
- rect->x = x1 - scroll_x;
- rect->y = y1 - scroll_y;
- rect->width = x2 - x1;
- rect->height = y2 - y1;
+ double bx1, bx2, by1, by2;
+ gint scroll_x, scroll_y;
+ gint x1, x2, y1, y2;
+
+ eel_canvas_item_get_bounds (item, &bx1, &by1, &bx2, &by2);
+ eel_canvas_w2c_rect_d (item->canvas, &bx1, &by1, &bx2, &by2);
+ eel_canvas_get_scroll_offsets (item->canvas, &scroll_x, &scroll_y);
+ x1 = floor (bx1 + .5);
+ y1 = floor (by1 + .5);
+ x2 = floor (bx2 + .5);
+ y2 = floor (by2 + .5);
+ rect->x = x1 - scroll_x;
+ rect->y = y1 - scroll_y;
+ rect->width = x2 - x1;
+ rect->height = y2 - y1;
}
static gboolean
eel_canvas_item_accessible_is_item_in_window (EelCanvasItem *item,
GdkRectangle *rect)
{
- GtkWidget *widget;
- gboolean retval;
-
- widget = GTK_WIDGET (item->canvas);
- if (gtk_widget_get_window (widget)) {
- int window_width, window_height;
-
- gdk_window_get_geometry (gtk_widget_get_window (widget), NULL, NULL,
- &window_width, &window_height);
- /*
- * Check whether rectangles intersect
- */
- if (rect->x + rect->width < 0 ||
- rect->y + rect->height < 0 ||
- rect->x > window_width ||
- rect->y > window_height) {
- retval = FALSE;
- } else {
- retval = TRUE;
- }
- } else {
- retval = FALSE;
- }
- return retval;
+ GtkWidget *widget;
+ gboolean retval;
+
+ widget = GTK_WIDGET (item->canvas);
+ if (gtk_widget_get_window (widget))
+ {
+ int window_width, window_height;
+
+ gdk_window_get_geometry (gtk_widget_get_window (widget), NULL, NULL,
+ &window_width, &window_height);
+ /*
+ * Check whether rectangles intersect
+ */
+ if (rect->x + rect->width < 0 ||
+ rect->y + rect->height < 0 ||
+ rect->x > window_width ||
+ rect->y > window_height)
+ {
+ retval = FALSE;
+ }
+ else
+ {
+ retval = TRUE;
+ }
+ }
+ else
+ {
+ retval = FALSE;
+ }
+ return retval;
}
static void
eel_canvas_item_accessible_get_extents (AtkComponent *component,
- gint *x,
- gint *y,
- gint *width,
- gint *height,
- AtkCoordType coord_type)
-{
- AtkGObjectAccessible *atk_gobj;
- GObject *obj;
- EelCanvasItem *item;
- gint window_x, window_y;
- gint toplevel_x, toplevel_y;
- GdkRectangle rect;
- GdkWindow *window;
- GtkWidget *canvas;
-
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
- obj = atk_gobject_accessible_get_object (atk_gobj);
-
- if (obj == NULL) {
- /* item is defunct */
- return;
- }
-
- /* Get the CanvasItem */
- item = EEL_CANVAS_ITEM (obj);
-
- /* If this item has no parent canvas, something's broken */
- g_return_if_fail (GTK_IS_WIDGET (item->canvas));
-
- eel_canvas_item_accessible_get_item_extents (item, &rect);
- *width = rect.width;
- *height = rect.height;
- if (!eel_canvas_item_accessible_is_item_in_window (item, &rect)) {
- *x = G_MININT;
- *y = G_MININT;
- return;
- }
-
- canvas = GTK_WIDGET (item->canvas);
- window = gtk_widget_get_parent_window (canvas);
- gdk_window_get_origin (window, &window_x, &window_y);
- *x = rect.x + window_x;
- *y = rect.y + window_y;
- if (coord_type == ATK_XY_WINDOW) {
- window = gdk_window_get_toplevel (gtk_widget_get_window (canvas));
- gdk_window_get_origin (window, &toplevel_x, &toplevel_y);
- *x -= toplevel_x;
- *y -= toplevel_y;
- }
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height,
+ AtkCoordType coord_type)
+{
+ AtkGObjectAccessible *atk_gobj;
+ GObject *obj;
+ EelCanvasItem *item;
+ gint window_x, window_y;
+ gint toplevel_x, toplevel_y;
+ GdkRectangle rect;
+ GdkWindow *window;
+ GtkWidget *canvas;
+
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+ obj = atk_gobject_accessible_get_object (atk_gobj);
+
+ if (obj == NULL)
+ {
+ /* item is defunct */
+ return;
+ }
+
+ /* Get the CanvasItem */
+ item = EEL_CANVAS_ITEM (obj);
+
+ /* If this item has no parent canvas, something's broken */
+ g_return_if_fail (GTK_IS_WIDGET (item->canvas));
+
+ eel_canvas_item_accessible_get_item_extents (item, &rect);
+ *width = rect.width;
+ *height = rect.height;
+ if (!eel_canvas_item_accessible_is_item_in_window (item, &rect))
+ {
+ *x = G_MININT;
+ *y = G_MININT;
return;
+ }
+
+ canvas = GTK_WIDGET (item->canvas);
+ window = gtk_widget_get_parent_window (canvas);
+ gdk_window_get_origin (window, &window_x, &window_y);
+ *x = rect.x + window_x;
+ *y = rect.y + window_y;
+ if (coord_type == ATK_XY_WINDOW)
+ {
+ window = gdk_window_get_toplevel (gtk_widget_get_window (canvas));
+ gdk_window_get_origin (window, &toplevel_x, &toplevel_y);
+ *x -= toplevel_x;
+ *y -= toplevel_y;
+ }
+ return;
}
static gint
eel_canvas_item_accessible_get_mdi_zorder (AtkComponent *component)
{
- AtkGObjectAccessible *atk_gobj;
- GObject *g_obj;
- EelCanvasItem *item;
-
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
- g_obj = atk_gobject_accessible_get_object (atk_gobj);
- if (g_obj == NULL) {
- /* Object is defunct */
- return -1;
- }
-
- item = EEL_CANVAS_ITEM (g_obj);
- if (item->parent) {
- return g_list_index (EEL_CANVAS_GROUP (item->parent)->item_list, item);
- } else {
- g_return_val_if_fail (item->canvas->root == item, -1);
- return 0;
- }
+ AtkGObjectAccessible *atk_gobj;
+ GObject *g_obj;
+ EelCanvasItem *item;
+
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+ g_obj = atk_gobject_accessible_get_object (atk_gobj);
+ if (g_obj == NULL)
+ {
+ /* Object is defunct */
+ return -1;
+ }
+
+ item = EEL_CANVAS_ITEM (g_obj);
+ if (item->parent)
+ {
+ return g_list_index (EEL_CANVAS_GROUP (item->parent)->item_list, item);
+ }
+ else
+ {
+ g_return_val_if_fail (item->canvas->root == item, -1);
+ return 0;
+ }
}
static gboolean
eel_canvas_item_accessible_grab_focus (AtkComponent *component)
{
- AtkGObjectAccessible *atk_gobj;
- GObject *obj;
- EelCanvasItem *item;
- GtkWidget *toplevel;
-
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
- obj = atk_gobject_accessible_get_object (atk_gobj);
-
- item = EEL_CANVAS_ITEM (obj);
- if (item == NULL) {
- /* item is defunct */
- return FALSE;
- }
-
- eel_canvas_item_grab_focus (item);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->canvas));
- if (gtk_widget_is_toplevel (toplevel)) {
- gtk_window_present (GTK_WINDOW (toplevel));
- }
-
- return TRUE;
+ AtkGObjectAccessible *atk_gobj;
+ GObject *obj;
+ EelCanvasItem *item;
+ GtkWidget *toplevel;
+
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (component);
+ obj = atk_gobject_accessible_get_object (atk_gobj);
+
+ item = EEL_CANVAS_ITEM (obj);
+ if (item == NULL)
+ {
+ /* item is defunct */
+ return FALSE;
+ }
+
+ eel_canvas_item_grab_focus (item);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->canvas));
+ if (gtk_widget_is_toplevel (toplevel))
+ {
+ gtk_window_present (GTK_WINDOW (toplevel));
+ }
+
+ return TRUE;
}
static void
eel_canvas_item_accessible_component_interface_init (AtkComponentIface *iface)
{
- g_return_if_fail (iface != NULL);
+ g_return_if_fail (iface != NULL);
- iface->get_extents = eel_canvas_item_accessible_get_extents;
- iface->get_mdi_zorder = eel_canvas_item_accessible_get_mdi_zorder;
- iface->grab_focus = eel_canvas_item_accessible_grab_focus;
+ iface->get_extents = eel_canvas_item_accessible_get_extents;
+ iface->get_mdi_zorder = eel_canvas_item_accessible_get_mdi_zorder;
+ iface->grab_focus = eel_canvas_item_accessible_grab_focus;
}
static gboolean
eel_canvas_item_accessible_is_item_on_screen (EelCanvasItem *item)
{
- GdkRectangle rect;
+ GdkRectangle rect;
- eel_canvas_item_accessible_get_item_extents (item, &rect);
- return eel_canvas_item_accessible_is_item_in_window (item, &rect);
+ eel_canvas_item_accessible_get_item_extents (item, &rect);
+ return eel_canvas_item_accessible_is_item_in_window (item, &rect);
}
static void
-eel_canvas_item_accessible_initialize (AtkObject *obj, gpointer data)
+eel_canvas_item_accessible_initialize (AtkObject *obj,
+ gpointer data)
{
- if (ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize != NULL)
- ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize (obj, data);
- g_object_set_data (G_OBJECT (obj), "atk-component-layer",
- GINT_TO_POINTER (ATK_LAYER_MDI));
+ if (ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize != NULL)
+ {
+ ATK_OBJECT_CLASS (accessible_item_parent_class)->initialize (obj, data);
+ }
+ g_object_set_data (G_OBJECT (obj), "atk-component-layer",
+ GINT_TO_POINTER (ATK_LAYER_MDI));
}
-static AtkStateSet*
+static AtkStateSet *
eel_canvas_item_accessible_ref_state_set (AtkObject *accessible)
{
- AtkGObjectAccessible *atk_gobj;
- GObject *obj;
- EelCanvasItem *item;
- AtkStateSet *state_set;
-
- state_set = ATK_OBJECT_CLASS (accessible_item_parent_class)->ref_state_set (accessible);
- atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
- obj = atk_gobject_accessible_get_object (atk_gobj);
-
- item = EEL_CANVAS_ITEM (obj);
- if (item == NULL) {
- atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
- } else {
- if (item->flags & EEL_CANVAS_ITEM_VISIBLE) {
- atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
-
- if (eel_canvas_item_accessible_is_item_on_screen (item)) {
- atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
- }
- }
- if (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas))) {
- atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
-
- if (item->canvas->focused_item == item) {
- atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
- }
- }
- }
-
- return state_set;
+ AtkGObjectAccessible *atk_gobj;
+ GObject *obj;
+ EelCanvasItem *item;
+ AtkStateSet *state_set;
+
+ state_set = ATK_OBJECT_CLASS (accessible_item_parent_class)->ref_state_set (accessible);
+ atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
+ obj = atk_gobject_accessible_get_object (atk_gobj);
+
+ item = EEL_CANVAS_ITEM (obj);
+ if (item == NULL)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
+ }
+ else
+ {
+ if (item->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
+
+ if (eel_canvas_item_accessible_is_item_on_screen (item))
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_SHOWING);
+ }
+ }
+ if (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas)))
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_FOCUSABLE);
+
+ if (item->canvas->focused_item == item)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
+ }
+ }
+ }
+
+ return state_set;
}
static void
eel_canvas_item_accessible_class_init (EelCanvasItemAccessibleClass *klass)
{
- AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
+ AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
- accessible_item_parent_class = g_type_class_peek_parent (klass);
+ accessible_item_parent_class = g_type_class_peek_parent (klass);
- atk_class->initialize = eel_canvas_item_accessible_initialize;
- atk_class->ref_state_set = eel_canvas_item_accessible_ref_state_set;
+ atk_class->initialize = eel_canvas_item_accessible_initialize;
+ atk_class->ref_state_set = eel_canvas_item_accessible_ref_state_set;
}
static void
eel_canvas_item_accessible_init (EelCanvasItemAccessible *self)
{
-
}
G_DEFINE_TYPE_WITH_CODE (EelCanvasItemAccessible,
- eel_canvas_item_accessible,
- ATK_TYPE_GOBJECT_ACCESSIBLE,
- G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
- eel_canvas_item_accessible_component_interface_init));
+ eel_canvas_item_accessible,
+ ATK_TYPE_GOBJECT_ACCESSIBLE,
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_COMPONENT,
+ eel_canvas_item_accessible_component_interface_init));
static GType eel_canvas_item_accessible_factory_get_type (void);
-typedef AtkObjectFactory EelCanvasItemAccessibleFactory;
+typedef AtkObjectFactory EelCanvasItemAccessibleFactory;
typedef AtkObjectFactoryClass EelCanvasItemAccessibleFactoryClass;
G_DEFINE_TYPE (EelCanvasItemAccessibleFactory, eel_canvas_item_accessible_factory,
- ATK_TYPE_OBJECT_FACTORY)
+ ATK_TYPE_OBJECT_FACTORY)
static GType
eel_canvas_item_accessible_factory_get_accessible_type (void)
{
- return eel_canvas_item_accessible_get_type ();
+ return eel_canvas_item_accessible_get_type ();
}
-static AtkObject*
+static AtkObject *
eel_canvas_item_accessible_factory_create_accessible (GObject *for_object)
{
- AtkObject *accessible;
+ AtkObject *accessible;
- accessible = g_object_new (eel_canvas_item_accessible_get_type (), NULL);
- atk_object_initialize (accessible, for_object);
- return accessible;
+ accessible = g_object_new (eel_canvas_item_accessible_get_type (), NULL);
+ atk_object_initialize (accessible, for_object);
+ return accessible;
}
static void
eel_canvas_item_accessible_factory_init (EelCanvasItemAccessibleFactory *self)
{
-
}
static void
eel_canvas_item_accessible_factory_class_init (AtkObjectFactoryClass *klass)
{
- klass->create_accessible = eel_canvas_item_accessible_factory_create_accessible;
- klass->get_accessible_type = eel_canvas_item_accessible_factory_get_accessible_type;
+ klass->create_accessible = eel_canvas_item_accessible_factory_create_accessible;
+ klass->get_accessible_type = eel_canvas_item_accessible_factory_get_accessible_type;
}
/* Class initialization function for EelCanvasItemClass */
static void
eel_canvas_item_class_init (EelCanvasItemClass *klass)
{
- GObjectClass *gobject_class = (GObjectClass *) klass;
-
- item_parent_class = g_type_class_peek_parent (klass);
-
- gobject_class->set_property = eel_canvas_item_set_property;
- gobject_class->get_property = eel_canvas_item_get_property;
- gobject_class->dispose = eel_canvas_item_dispose;
-
- g_object_class_install_property
- (gobject_class, ITEM_PROP_PARENT,
- g_param_spec_object ("parent", NULL, NULL,
- EEL_TYPE_CANVAS_ITEM,
- G_PARAM_READWRITE));
-
- g_object_class_install_property
- (gobject_class, ITEM_PROP_VISIBLE,
- g_param_spec_boolean ("visible", NULL, NULL,
- TRUE,
- G_PARAM_READWRITE));
-
- item_signals[ITEM_EVENT] =
- g_signal_new ("event",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (EelCanvasItemClass, event),
- boolean_handled_accumulator, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_BOOLEAN, 1,
- GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-
- item_signals[ITEM_DESTROY] =
- g_signal_new ("destroy",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- G_STRUCT_OFFSET (EelCanvasItemClass, destroy),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- klass->realize = eel_canvas_item_realize;
- klass->unrealize = eel_canvas_item_unrealize;
- klass->map = eel_canvas_item_map;
- klass->unmap = eel_canvas_item_unmap;
- klass->update = eel_canvas_item_update;
-
- atk_registry_set_factory_type (atk_get_default_registry (),
- EEL_TYPE_CANVAS_ITEM,
- eel_canvas_item_accessible_factory_get_type ());
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+
+ item_parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->set_property = eel_canvas_item_set_property;
+ gobject_class->get_property = eel_canvas_item_get_property;
+ gobject_class->dispose = eel_canvas_item_dispose;
+
+ g_object_class_install_property
+ (gobject_class, ITEM_PROP_PARENT,
+ g_param_spec_object ("parent", NULL, NULL,
+ EEL_TYPE_CANVAS_ITEM,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property
+ (gobject_class, ITEM_PROP_VISIBLE,
+ g_param_spec_boolean ("visible", NULL, NULL,
+ TRUE,
+ G_PARAM_READWRITE));
+
+ item_signals[ITEM_EVENT] =
+ g_signal_new ("event",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EelCanvasItemClass, event),
+ boolean_handled_accumulator, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 1,
+ GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+
+ item_signals[ITEM_DESTROY] =
+ g_signal_new ("destroy",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ G_STRUCT_OFFSET (EelCanvasItemClass, destroy),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ klass->realize = eel_canvas_item_realize;
+ klass->unrealize = eel_canvas_item_unrealize;
+ klass->map = eel_canvas_item_map;
+ klass->unmap = eel_canvas_item_unmap;
+ klass->update = eel_canvas_item_update;
+
+ atk_registry_set_factory_type (atk_get_default_registry (),
+ EEL_TYPE_CANVAS_ITEM,
+ eel_canvas_item_accessible_factory_get_type ());
}
diff --git a/eel/eel-debug.c b/eel/eel-debug.c
index df3f51d78..f3d94ec0f 100644
--- a/eel/eel-debug.c
+++ b/eel/eel-debug.c
@@ -1,23 +1,23 @@
/*
- eel-debug.c: Eel debugging aids.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@eazel.com>
-*/
+ * eel-debug.c: Eel debugging aids.
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-debug.h"
@@ -26,9 +26,10 @@
#include <signal.h>
#include <stdio.h>
-typedef struct {
- gpointer data;
- GFreeFunc function;
+typedef struct
+{
+ gpointer data;
+ GFreeFunc function;
} ShutdownFunction;
static GList *shutdown_functions;
@@ -40,11 +41,11 @@ static GList *shutdown_functions;
static void
eel_stop_in_debugger (void)
{
- void (* saved_handler) (int);
+ void (*saved_handler) (int);
- saved_handler = signal (SIGINT, SIG_IGN);
- raise (SIGINT);
- signal (SIGINT, saved_handler);
+ saved_handler = signal (SIGINT, SIG_IGN);
+ raise (SIGINT);
+ signal (SIGINT, saved_handler);
}
/* Stop in the debugger after running the default log handler.
@@ -52,50 +53,53 @@ eel_stop_in_debugger (void)
* without making them fatal (you can continue).
*/
static void
-log_handler (const char *domain,
- GLogLevelFlags level,
- const char *message,
- gpointer data)
+log_handler (const char *domain,
+ GLogLevelFlags level,
+ const char *message,
+ gpointer data)
{
- g_log_default_handler (domain, level, message, data);
- if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0) {
- eel_stop_in_debugger ();
- }
+ g_log_default_handler (domain, level, message, data);
+ if ((level & (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING)) != 0)
+ {
+ eel_stop_in_debugger ();
+ }
}
void
eel_make_warnings_and_criticals_stop_in_debugger (void)
{
- g_log_set_default_handler (log_handler, NULL);
+ g_log_set_default_handler (log_handler, NULL);
}
void
eel_debug_shut_down (void)
{
- ShutdownFunction *f;
+ ShutdownFunction *f;
+
+ while (shutdown_functions != NULL)
+ {
+ f = shutdown_functions->data;
+ shutdown_functions = g_list_remove (shutdown_functions, f);
- while (shutdown_functions != NULL) {
- f = shutdown_functions->data;
- shutdown_functions = g_list_remove (shutdown_functions, f);
-
- f->function (f->data);
- g_free (f);
- }
+ f->function (f->data);
+ g_free (f);
+ }
}
void
eel_debug_call_at_shutdown (EelFunction function)
{
- eel_debug_call_at_shutdown_with_data ((GFreeFunc) function, NULL);
+ eel_debug_call_at_shutdown_with_data ((GFreeFunc) function, NULL);
}
void
-eel_debug_call_at_shutdown_with_data (GFreeFunc function, gpointer data)
+eel_debug_call_at_shutdown_with_data (GFreeFunc function,
+ gpointer data)
{
- ShutdownFunction *f;
+ ShutdownFunction *f;
- f = g_new (ShutdownFunction, 1);
- f->data = data;
- f->function = function;
- shutdown_functions = g_list_prepend (shutdown_functions, f);
+ f = g_new (ShutdownFunction, 1);
+ f->data = data;
+ f->function = function;
+ shutdown_functions = g_list_prepend (shutdown_functions, f);
}
diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c
index dc06f9d4c..6642dda4a 100644
--- a/eel/eel-gdk-extensions.c
+++ b/eel/eel-gdk-extensions.c
@@ -1,26 +1,25 @@
-
/* eel-gdk-extensions.c: Graphics routines to augment what's in gdk.
-
- Copyright (C) 1999, 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>,
- Pavel Cisler <pavel@eazel.com>,
- Ramiro Estrugo <ramiro@eazel.com>
-*/
+ *
+ * Copyright (C) 1999, 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>,
+ * Pavel Cisler <pavel@eazel.com>,
+ * Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
#include "eel-gdk-extensions.h"
@@ -34,40 +33,49 @@
#include <pango/pango.h>
EelGdkGeometryFlags
-eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return,
- guint *width_return, guint *height_return)
+eel_gdk_parse_geometry (const char *string,
+ int *x_return,
+ int *y_return,
+ guint *width_return,
+ guint *height_return)
{
- int x11_flags;
- EelGdkGeometryFlags gdk_flags;
+ int x11_flags;
+ EelGdkGeometryFlags gdk_flags;
- g_return_val_if_fail (string != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (x_return != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (y_return != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (width_return != NULL, EEL_GDK_NO_VALUE);
- g_return_val_if_fail (height_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (string != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (x_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (y_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (width_return != NULL, EEL_GDK_NO_VALUE);
+ g_return_val_if_fail (height_return != NULL, EEL_GDK_NO_VALUE);
- x11_flags = XParseGeometry (string, x_return, y_return,
- width_return, height_return);
+ x11_flags = XParseGeometry (string, x_return, y_return,
+ width_return, height_return);
- gdk_flags = EEL_GDK_NO_VALUE;
- if (x11_flags & XValue) {
- gdk_flags |= EEL_GDK_X_VALUE;
- }
- if (x11_flags & YValue) {
- gdk_flags |= EEL_GDK_Y_VALUE;
- }
- if (x11_flags & WidthValue) {
- gdk_flags |= EEL_GDK_WIDTH_VALUE;
- }
- if (x11_flags & HeightValue) {
- gdk_flags |= EEL_GDK_HEIGHT_VALUE;
- }
- if (x11_flags & XNegative) {
- gdk_flags |= EEL_GDK_X_NEGATIVE;
- }
- if (x11_flags & YNegative) {
- gdk_flags |= EEL_GDK_Y_NEGATIVE;
- }
+ gdk_flags = EEL_GDK_NO_VALUE;
+ if (x11_flags & XValue)
+ {
+ gdk_flags |= EEL_GDK_X_VALUE;
+ }
+ if (x11_flags & YValue)
+ {
+ gdk_flags |= EEL_GDK_Y_VALUE;
+ }
+ if (x11_flags & WidthValue)
+ {
+ gdk_flags |= EEL_GDK_WIDTH_VALUE;
+ }
+ if (x11_flags & HeightValue)
+ {
+ gdk_flags |= EEL_GDK_HEIGHT_VALUE;
+ }
+ if (x11_flags & XNegative)
+ {
+ gdk_flags |= EEL_GDK_X_NEGATIVE;
+ }
+ if (x11_flags & YNegative)
+ {
+ gdk_flags |= EEL_GDK_Y_NEGATIVE;
+ }
- return gdk_flags;
+ return gdk_flags;
}
diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c
index 5564eda08..0a1b22d75 100644
--- a/eel/eel-glib-extensions.c
+++ b/eel/eel-glib-extensions.c
@@ -1,26 +1,25 @@
-
/* eel-glib-extensions.c - implementation of new functions that conceptually
- belong in glib. Perhaps some of these will be
- actually rolled into glib someday.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
-*/
+ * belong in glib. Perhaps some of these will be
+ * actually rolled into glib someday.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
#include "eel-glib-extensions.h"
@@ -33,104 +32,118 @@
#include <stdlib.h>
gboolean
-eel_g_strv_equal (char **a, char **b)
+eel_g_strv_equal (char **a,
+ char **b)
{
- int i;
-
- if (g_strv_length (a) != g_strv_length (b)) {
- return FALSE;
- }
-
- for (i = 0; a[i] != NULL; i++) {
- if (strcmp (a[i], b[i]) != 0) {
- return FALSE;
- }
- }
- return TRUE;
+ int i;
+
+ if (g_strv_length (a) != g_strv_length (b))
+ {
+ return FALSE;
+ }
+
+ for (i = 0; a[i] != NULL; i++)
+ {
+ if (strcmp (a[i], b[i]) != 0)
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
}
static int
-compare_pointers (gconstpointer pointer_1, gconstpointer pointer_2)
+compare_pointers (gconstpointer pointer_1,
+ gconstpointer pointer_2)
{
- if ((const char *) pointer_1 < (const char *) pointer_2) {
- return -1;
- }
- if ((const char *) pointer_1 > (const char *) pointer_2) {
- return +1;
- }
- return 0;
+ if ((const char *) pointer_1 < (const char *) pointer_2)
+ {
+ return -1;
+ }
+ if ((const char *) pointer_1 > (const char *) pointer_2)
+ {
+ return +1;
+ }
+ return 0;
}
gboolean
eel_g_lists_sort_and_check_for_intersection (GList **list_1,
- GList **list_2)
-
+ GList **list_2)
{
- GList *node_1, *node_2;
- int compare_result;
-
- *list_1 = g_list_sort (*list_1, compare_pointers);
- *list_2 = g_list_sort (*list_2, compare_pointers);
-
- node_1 = *list_1;
- node_2 = *list_2;
-
- while (node_1 != NULL && node_2 != NULL) {
- compare_result = compare_pointers (node_1->data, node_2->data);
- if (compare_result == 0) {
- return TRUE;
- }
- if (compare_result <= 0) {
- node_1 = node_1->next;
- }
- if (compare_result >= 0) {
- node_2 = node_2->next;
- }
- }
-
- return FALSE;
+ GList *node_1, *node_2;
+ int compare_result;
+
+ *list_1 = g_list_sort (*list_1, compare_pointers);
+ *list_2 = g_list_sort (*list_2, compare_pointers);
+
+ node_1 = *list_1;
+ node_2 = *list_2;
+
+ while (node_1 != NULL && node_2 != NULL)
+ {
+ compare_result = compare_pointers (node_1->data, node_2->data);
+ if (compare_result == 0)
+ {
+ return TRUE;
+ }
+ if (compare_result <= 0)
+ {
+ node_1 = node_1->next;
+ }
+ if (compare_result >= 0)
+ {
+ node_2 = node_2->next;
+ }
+ }
+
+ return FALSE;
}
-typedef struct {
- GList *keys;
- GList *values;
+typedef struct
+{
+ GList *keys;
+ GList *values;
} FlattenedHashTable;
static void
-flatten_hash_table_element (gpointer key, gpointer value, gpointer callback_data)
+flatten_hash_table_element (gpointer key,
+ gpointer value,
+ gpointer callback_data)
{
- FlattenedHashTable *flattened_table;
+ FlattenedHashTable *flattened_table;
- flattened_table = callback_data;
- flattened_table->keys = g_list_prepend
- (flattened_table->keys, key);
- flattened_table->values = g_list_prepend
- (flattened_table->values, value);
+ flattened_table = callback_data;
+ flattened_table->keys = g_list_prepend
+ (flattened_table->keys, key);
+ flattened_table->values = g_list_prepend
+ (flattened_table->values, value);
}
void
eel_g_hash_table_safe_for_each (GHashTable *hash_table,
- GHFunc callback,
- gpointer callback_data)
+ GHFunc callback,
+ gpointer callback_data)
{
- FlattenedHashTable flattened;
- GList *p, *q;
+ FlattenedHashTable flattened;
+ GList *p, *q;
- flattened.keys = NULL;
- flattened.values = NULL;
+ flattened.keys = NULL;
+ flattened.values = NULL;
- g_hash_table_foreach (hash_table,
- flatten_hash_table_element,
- &flattened);
+ g_hash_table_foreach (hash_table,
+ flatten_hash_table_element,
+ &flattened);
- for (p = flattened.keys, q = flattened.values;
- p != NULL;
- p = p->next, q = q->next) {
- (* callback) (p->data, q->data, callback_data);
- }
+ for (p = flattened.keys, q = flattened.values;
+ p != NULL;
+ p = p->next, q = q->next)
+ {
+ (*callback)(p->data, q->data, callback_data);
+ }
- g_list_free (flattened.keys);
- g_list_free (flattened.values);
+ g_list_free (flattened.keys);
+ g_list_free (flattened.values);
}
#if !defined (EEL_OMIT_SELF_CHECK)
diff --git a/eel/eel-gnome-extensions.c b/eel/eel-gnome-extensions.c
index fe5efef9a..65de96180 100644
--- a/eel/eel-gnome-extensions.c
+++ b/eel/eel-gnome-extensions.c
@@ -1,26 +1,25 @@
-
/* eel-gnome-extensions.c - implementation of new functions that operate on
- gnome classes. Perhaps some of these should be
- rolled into gnome someday.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
-*/
+ * gnome classes. Perhaps some of these should be
+ * rolled into gnome someday.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
@@ -34,29 +33,31 @@
void
eel_gnome_open_terminal_on_screen (const char *command,
- GdkScreen *screen)
+ GdkScreen *screen)
{
- GAppInfo *app;
- GdkAppLaunchContext *ctx;
- GError *error = NULL;
- GdkDisplay *display;
+ GAppInfo *app;
+ GdkAppLaunchContext *ctx;
+ GError *error = NULL;
+ GdkDisplay *display;
- app = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, &error);
+ app = g_app_info_create_from_commandline (command, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, &error);
- if (app != NULL && screen != NULL) {
- display = gdk_screen_get_display (screen);
- ctx = gdk_display_get_app_launch_context (display);
- gdk_app_launch_context_set_screen (ctx, screen);
+ if (app != NULL && screen != NULL)
+ {
+ display = gdk_screen_get_display (screen);
+ ctx = gdk_display_get_app_launch_context (display);
+ gdk_app_launch_context_set_screen (ctx, screen);
- g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+ g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
- g_object_unref (app);
- g_object_unref (ctx);
- }
+ g_object_unref (app);
+ g_object_unref (ctx);
+ }
- if (error != NULL) {
- g_message ("Could not start application on terminal: %s", error->message);
+ if (error != NULL)
+ {
+ g_message ("Could not start application on terminal: %s", error->message);
- g_error_free (error);
- }
+ g_error_free (error);
+ }
}
diff --git a/eel/eel-graphic-effects.c b/eel/eel-graphic-effects.c
index 820435ab7..b3fdc5bdb 100644
--- a/eel/eel-graphic-effects.c
+++ b/eel/eel-graphic-effects.c
@@ -1,4 +1,3 @@
-
/* Eel - pixbuf manipulation routines for graphical effects.
*
* Copyright (C) 2000 Eazel, Inc
@@ -20,7 +19,7 @@
*/
/* This file contains pixbuf manipulation routines used for graphical effects like pre-lighting
- and selection hilighting */
+ * and selection hilighting */
#include <config.h>
@@ -35,17 +34,17 @@
static GdkPixbuf *
create_new_pixbuf (GdkPixbuf *src)
{
- g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB);
- g_assert ((!gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 3)
- || (gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 4));
-
- return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
- gdk_pixbuf_get_has_alpha (src),
- gdk_pixbuf_get_bits_per_sample (src),
- gdk_pixbuf_get_width (src),
- gdk_pixbuf_get_height (src));
+ g_assert (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB);
+ g_assert ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4));
+
+ return gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
+ gdk_pixbuf_get_has_alpha (src),
+ gdk_pixbuf_get_bits_per_sample (src),
+ gdk_pixbuf_get_width (src),
+ gdk_pixbuf_get_height (src));
}
/* utility routine to bump the level of a color component with pinning */
@@ -53,102 +52,109 @@ create_new_pixbuf (GdkPixbuf *src)
static guchar
lighten_component (guchar cur_value)
{
- int new_value = cur_value;
- new_value += 24 + (new_value >> 3);
- if (new_value > 255) {
- new_value = 255;
- }
- return (guchar) new_value;
+ int new_value = cur_value;
+ new_value += 24 + (new_value >> 3);
+ if (new_value > 255)
+ {
+ new_value = 255;
+ }
+ return (guchar) new_value;
}
GdkPixbuf *
-eel_create_spotlight_pixbuf (GdkPixbuf* src)
+eel_create_spotlight_pixbuf (GdkPixbuf *src)
{
- GdkPixbuf *dest;
- int i, j;
- int width, height, has_alpha, src_row_stride, dst_row_stride;
- guchar *target_pixels, *original_pixels;
- guchar *pixsrc, *pixdest;
-
- g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
- g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 3)
- || (gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 4), NULL);
- g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
-
- dest = create_new_pixbuf (src);
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- dst_row_stride = gdk_pixbuf_get_rowstride (dest);
- src_row_stride = gdk_pixbuf_get_rowstride (src);
- target_pixels = gdk_pixbuf_get_pixels (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
-
- for (i = 0; i < height; i++) {
- pixdest = target_pixels + i * dst_row_stride;
- pixsrc = original_pixels + i * src_row_stride;
- for (j = 0; j < width; j++) {
- *pixdest++ = lighten_component (*pixsrc++);
- *pixdest++ = lighten_component (*pixsrc++);
- *pixdest++ = lighten_component (*pixsrc++);
- if (has_alpha) {
- *pixdest++ = *pixsrc++;
- }
- }
- }
- return dest;
+ GdkPixbuf *dest;
+ int i, j;
+ int width, height, has_alpha, src_row_stride, dst_row_stride;
+ guchar *target_pixels, *original_pixels;
+ guchar *pixsrc, *pixdest;
+
+ g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
+ g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4), NULL);
+ g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
+
+ dest = create_new_pixbuf (src);
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ dst_row_stride = gdk_pixbuf_get_rowstride (dest);
+ src_row_stride = gdk_pixbuf_get_rowstride (src);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
+
+ for (i = 0; i < height; i++)
+ {
+ pixdest = target_pixels + i * dst_row_stride;
+ pixsrc = original_pixels + i * src_row_stride;
+ for (j = 0; j < width; j++)
+ {
+ *pixdest++ = lighten_component (*pixsrc++);
+ *pixdest++ = lighten_component (*pixsrc++);
+ *pixdest++ = lighten_component (*pixsrc++);
+ if (has_alpha)
+ {
+ *pixdest++ = *pixsrc++;
+ }
+ }
+ }
+ return dest;
}
/* this routine colorizes the passed-in pixbuf by multiplying each pixel with the passed in color */
GdkPixbuf *
eel_create_colorized_pixbuf (GdkPixbuf *src,
- GdkRGBA *color)
+ GdkRGBA *color)
{
- int i, j;
- int width, height, has_alpha, src_row_stride, dst_row_stride;
- guchar *target_pixels;
- guchar *original_pixels;
- guchar *pixsrc;
- guchar *pixdest;
- GdkPixbuf *dest;
- gint red_value, green_value, blue_value;
-
- g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
- g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 3)
- || (gdk_pixbuf_get_has_alpha (src)
- && gdk_pixbuf_get_n_channels (src) == 4), NULL);
- g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
-
- red_value = (gint) floor (color->red * 255);
- green_value = (gint) floor (color->green * 255);
- blue_value = (gint) floor (color->blue * 255);
-
- dest = create_new_pixbuf (src);
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- src_row_stride = gdk_pixbuf_get_rowstride (src);
- dst_row_stride = gdk_pixbuf_get_rowstride (dest);
- target_pixels = gdk_pixbuf_get_pixels (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
-
- for (i = 0; i < height; i++) {
- pixdest = target_pixels + i*dst_row_stride;
- pixsrc = original_pixels + i*src_row_stride;
- for (j = 0; j < width; j++) {
- *pixdest++ = (*pixsrc++ * red_value) >> 8;
- *pixdest++ = (*pixsrc++ * green_value) >> 8;
- *pixdest++ = (*pixsrc++ * blue_value) >> 8;
- if (has_alpha) {
- *pixdest++ = *pixsrc++;
- }
- }
- }
- return dest;
+ int i, j;
+ int width, height, has_alpha, src_row_stride, dst_row_stride;
+ guchar *target_pixels;
+ guchar *original_pixels;
+ guchar *pixsrc;
+ guchar *pixdest;
+ GdkPixbuf *dest;
+ gint red_value, green_value, blue_value;
+
+ g_return_val_if_fail (gdk_pixbuf_get_colorspace (src) == GDK_COLORSPACE_RGB, NULL);
+ g_return_val_if_fail ((!gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 3)
+ || (gdk_pixbuf_get_has_alpha (src)
+ && gdk_pixbuf_get_n_channels (src) == 4), NULL);
+ g_return_val_if_fail (gdk_pixbuf_get_bits_per_sample (src) == 8, NULL);
+
+ red_value = (gint) floor (color->red * 255);
+ green_value = (gint) floor (color->green * 255);
+ blue_value = (gint) floor (color->blue * 255);
+
+ dest = create_new_pixbuf (src);
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ src_row_stride = gdk_pixbuf_get_rowstride (src);
+ dst_row_stride = gdk_pixbuf_get_rowstride (dest);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
+
+ for (i = 0; i < height; i++)
+ {
+ pixdest = target_pixels + i * dst_row_stride;
+ pixsrc = original_pixels + i * src_row_stride;
+ for (j = 0; j < width; j++)
+ {
+ *pixdest++ = (*pixsrc++ *red_value) >> 8;
+ *pixdest++ = (*pixsrc++ *green_value) >> 8;
+ *pixdest++ = (*pixsrc++ *blue_value) >> 8;
+ if (has_alpha)
+ {
+ *pixdest++ = *pixsrc++;
+ }
+ }
+ }
+ return dest;
}
diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c
index d694ad4f1..8b9a0d909 100644
--- a/eel/eel-gtk-extensions.c
+++ b/eel/eel-gtk-extensions.c
@@ -1,28 +1,27 @@
-
/* eel-gtk-extensions.c - implementation of new functions that operate on
- gtk classes. Perhaps some of these should be
- rolled into gtk someday.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
- Ramiro Estrugo <ramiro@eazel.com>
- Darin Adler <darin@eazel.com>
-*/
+ * gtk classes. Perhaps some of these should be
+ * rolled into gtk someday.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ * Ramiro Estrugo <ramiro@eazel.com>
+ * Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-gtk-extensions.h"
@@ -43,93 +42,95 @@
/* This number is fairly arbitrary. Long enough to show a pretty long
* menu title, but not so long to make a menu grotesquely wide.
*/
-#define MAXIMUM_MENU_TITLE_LENGTH 48
+#define MAXIMUM_MENU_TITLE_LENGTH 48
/* Used for window position & size sanity-checking. The sizes are big enough to prevent
- * at least normal-sized gnome panels from obscuring the window at the screen edges.
+ * at least normal-sized gnome panels from obscuring the window at the screen edges.
*/
-#define MINIMUM_ON_SCREEN_WIDTH 100
-#define MINIMUM_ON_SCREEN_HEIGHT 100
+#define MINIMUM_ON_SCREEN_WIDTH 100
+#define MINIMUM_ON_SCREEN_HEIGHT 100
/**
* eel_gtk_window_get_geometry_string:
* @window: a #GtkWindow
- *
+ *
* Obtains the geometry string for this window, suitable for
* set_geometry_string(); assumes the window has NorthWest gravity
- *
+ *
* Return value: geometry string, must be freed
**/
-char*
+char *
eel_gtk_window_get_geometry_string (GtkWindow *window)
{
- char *str;
- int w, h, x, y;
-
- g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
- g_return_val_if_fail (gtk_window_get_gravity (window) ==
- GDK_GRAVITY_NORTH_WEST, NULL);
-
- gtk_window_get_position (window, &x, &y);
- gtk_window_get_size (window, &w, &h);
-
- str = g_strdup_printf ("%dx%d+%d+%d", w, h, x, y);
-
- return str;
+ char *str;
+ int w, h, x, y;
+
+ g_return_val_if_fail (GTK_IS_WINDOW (window), NULL);
+ g_return_val_if_fail (gtk_window_get_gravity (window) ==
+ GDK_GRAVITY_NORTH_WEST, NULL);
+
+ gtk_window_get_position (window, &x, &y);
+ gtk_window_get_size (window, &w, &h);
+
+ str = g_strdup_printf ("%dx%d+%d+%d", w, h, x, y);
+
+ return str;
}
static void
-sanity_check_window_position (int *left, int *top)
+sanity_check_window_position (int *left,
+ int *top)
{
- g_assert (left != NULL);
- g_assert (top != NULL);
-
- /* Make sure the top of the window is on screen, for
- * draggability (might not be necessary with all window managers,
- * but seems reasonable anyway). Make sure the top of the window
- * isn't off the bottom of the screen, or so close to the bottom
- * that it might be obscured by the panel.
- */
- *top = CLAMP (*top, 0, gdk_screen_height() - MINIMUM_ON_SCREEN_HEIGHT);
-
- /* FIXME bugzilla.eazel.com 669:
- * If window has negative left coordinate, set_uposition sends it
- * somewhere else entirely. Not sure what level contains this bug (XWindows?).
- * Hacked around by pinning the left edge to zero, which just means you
- * can't set a window to be partly off the left of the screen using
- * this routine.
- */
- /* Make sure the left edge of the window isn't off the right edge of
- * the screen, or so close to the right edge that it might be
- * obscured by the panel.
- */
- *left = CLAMP (*left, 0, gdk_screen_width() - MINIMUM_ON_SCREEN_WIDTH);
+ g_assert (left != NULL);
+ g_assert (top != NULL);
+
+ /* Make sure the top of the window is on screen, for
+ * draggability (might not be necessary with all window managers,
+ * but seems reasonable anyway). Make sure the top of the window
+ * isn't off the bottom of the screen, or so close to the bottom
+ * that it might be obscured by the panel.
+ */
+ *top = CLAMP (*top, 0, gdk_screen_height () - MINIMUM_ON_SCREEN_HEIGHT);
+
+ /* FIXME bugzilla.eazel.com 669:
+ * If window has negative left coordinate, set_uposition sends it
+ * somewhere else entirely. Not sure what level contains this bug (XWindows?).
+ * Hacked around by pinning the left edge to zero, which just means you
+ * can't set a window to be partly off the left of the screen using
+ * this routine.
+ */
+ /* Make sure the left edge of the window isn't off the right edge of
+ * the screen, or so close to the right edge that it might be
+ * obscured by the panel.
+ */
+ *left = CLAMP (*left, 0, gdk_screen_width () - MINIMUM_ON_SCREEN_WIDTH);
}
static void
-sanity_check_window_dimensions (guint *width, guint *height)
+sanity_check_window_dimensions (guint *width,
+ guint *height)
{
- g_assert (width != NULL);
- g_assert (height != NULL);
-
- /* Pin the size of the window to the screen, so we don't end up in
- * a state where the window is so big essential parts of it can't
- * be reached (might not be necessary with all window managers,
- * but seems reasonable anyway).
- */
- *width = MIN (*width, gdk_screen_width());
- *height = MIN (*height, gdk_screen_height());
+ g_assert (width != NULL);
+ g_assert (height != NULL);
+
+ /* Pin the size of the window to the screen, so we don't end up in
+ * a state where the window is so big essential parts of it can't
+ * be reached (might not be necessary with all window managers,
+ * but seems reasonable anyway).
+ */
+ *width = MIN (*width, gdk_screen_width ());
+ *height = MIN (*height, gdk_screen_height ());
}
/**
* eel_gtk_window_set_initial_geometry:
- *
+ *
* Sets the position and size of a GtkWindow before the
* GtkWindow is shown. It is an error to call this on a window that
* is already on-screen. Takes into account screen size, and does
* some sanity-checking on the passed-in values.
- *
+ *
* @window: A non-visible GtkWindow
* @geometry_flags: A EelGdkGeometryFlags value defining which of
* the following parameters have defined values
@@ -139,65 +140,69 @@ sanity_check_window_dimensions (guint *width, guint *height)
* @height: height of window in pixels
*/
static void
-eel_gtk_window_set_initial_geometry (GtkWindow *window,
- EelGdkGeometryFlags geometry_flags,
- int left,
- int top,
- guint width,
- guint height)
+eel_gtk_window_set_initial_geometry (GtkWindow *window,
+ EelGdkGeometryFlags geometry_flags,
+ int left,
+ int top,
+ guint width,
+ guint height)
{
- GdkScreen *screen;
- int real_left, real_top;
- int screen_width, screen_height;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
-
- /* Setting the default size doesn't work when the window is already showing.
- * Someday we could make this move an already-showing window, but we don't
- * need that functionality yet.
- */
- g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
-
- if ((geometry_flags & EEL_GDK_X_VALUE) && (geometry_flags & EEL_GDK_Y_VALUE)) {
- real_left = left;
- real_top = top;
-
- screen = gtk_window_get_screen (window);
- screen_width = gdk_screen_get_width (screen);
- screen_height = gdk_screen_get_height (screen);
-
- /* This is sub-optimal. GDK doesn't allow us to set win_gravity
- * to South/East types, which should be done if using negative
- * positions (so that the right or bottom edge of the window
- * appears at the specified position, not the left or top).
- * However it does seem to be consistent with other GNOME apps.
- */
- if (geometry_flags & EEL_GDK_X_NEGATIVE) {
- real_left = screen_width - real_left;
- }
- if (geometry_flags & EEL_GDK_Y_NEGATIVE) {
- real_top = screen_height - real_top;
- }
-
- sanity_check_window_position (&real_left, &real_top);
- gtk_window_move (window, real_left, real_top);
- }
-
- if ((geometry_flags & EEL_GDK_WIDTH_VALUE) && (geometry_flags & EEL_GDK_HEIGHT_VALUE)) {
- sanity_check_window_dimensions (&width, &height);
- gtk_window_set_default_size (GTK_WINDOW (window), (int)width, (int)height);
- }
+ GdkScreen *screen;
+ int real_left, real_top;
+ int screen_width, screen_height;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+
+ /* Setting the default size doesn't work when the window is already showing.
+ * Someday we could make this move an already-showing window, but we don't
+ * need that functionality yet.
+ */
+ g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
+
+ if ((geometry_flags & EEL_GDK_X_VALUE) && (geometry_flags & EEL_GDK_Y_VALUE))
+ {
+ real_left = left;
+ real_top = top;
+
+ screen = gtk_window_get_screen (window);
+ screen_width = gdk_screen_get_width (screen);
+ screen_height = gdk_screen_get_height (screen);
+
+ /* This is sub-optimal. GDK doesn't allow us to set win_gravity
+ * to South/East types, which should be done if using negative
+ * positions (so that the right or bottom edge of the window
+ * appears at the specified position, not the left or top).
+ * However it does seem to be consistent with other GNOME apps.
+ */
+ if (geometry_flags & EEL_GDK_X_NEGATIVE)
+ {
+ real_left = screen_width - real_left;
+ }
+ if (geometry_flags & EEL_GDK_Y_NEGATIVE)
+ {
+ real_top = screen_height - real_top;
+ }
+
+ sanity_check_window_position (&real_left, &real_top);
+ gtk_window_move (window, real_left, real_top);
+ }
+
+ if ((geometry_flags & EEL_GDK_WIDTH_VALUE) && (geometry_flags & EEL_GDK_HEIGHT_VALUE))
+ {
+ sanity_check_window_dimensions (&width, &height);
+ gtk_window_set_default_size (GTK_WINDOW (window), (int) width, (int) height);
+ }
}
/**
* eel_gtk_window_set_initial_geometry_from_string:
- *
+ *
* Sets the position and size of a GtkWindow before the
- * GtkWindow is shown. The geometry is passed in as a string.
+ * GtkWindow is shown. The geometry is passed in as a string.
* It is an error to call this on a window that
* is already on-screen. Takes into account screen size, and does
* some sanity-checking on the passed-in values.
- *
+ *
* @window: A non-visible GtkWindow
* @geometry_string: A string suitable for use with eel_gdk_parse_geometry
* @minimum_width: If the width from the string is smaller than this,
@@ -207,55 +212,58 @@ eel_gtk_window_set_initial_geometry (GtkWindow *window,
* @ignore_position: If true position data from string will be ignored.
*/
void
-eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
- const char *geometry_string,
- guint minimum_width,
- guint minimum_height,
- gboolean ignore_position)
+eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
+ const char *geometry_string,
+ guint minimum_width,
+ guint minimum_height,
+ gboolean ignore_position)
{
- int left, top;
- guint width, height;
- EelGdkGeometryFlags geometry_flags;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (geometry_string != NULL);
-
- /* Setting the default size doesn't work when the window is already showing.
- * Someday we could make this move an already-showing window, but we don't
- * need that functionality yet.
- */
- g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
-
- geometry_flags = eel_gdk_parse_geometry (geometry_string, &left, &top, &width, &height);
-
- /* Make sure the window isn't smaller than makes sense for this window.
- * Other sanity checks are performed in set_initial_geometry.
- */
- if (geometry_flags & EEL_GDK_WIDTH_VALUE) {
- width = MAX (width, minimum_width);
- }
- if (geometry_flags & EEL_GDK_HEIGHT_VALUE) {
- height = MAX (height, minimum_height);
- }
-
- /* Ignore saved window position if requested. */
- if (ignore_position) {
- geometry_flags &= ~(EEL_GDK_X_VALUE | EEL_GDK_Y_VALUE);
- }
-
- eel_gtk_window_set_initial_geometry (window, geometry_flags, left, top, width, height);
+ int left, top;
+ guint width, height;
+ EelGdkGeometryFlags geometry_flags;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ g_return_if_fail (geometry_string != NULL);
+
+ /* Setting the default size doesn't work when the window is already showing.
+ * Someday we could make this move an already-showing window, but we don't
+ * need that functionality yet.
+ */
+ g_return_if_fail (!gtk_widget_get_visible (GTK_WIDGET (window)));
+
+ geometry_flags = eel_gdk_parse_geometry (geometry_string, &left, &top, &width, &height);
+
+ /* Make sure the window isn't smaller than makes sense for this window.
+ * Other sanity checks are performed in set_initial_geometry.
+ */
+ if (geometry_flags & EEL_GDK_WIDTH_VALUE)
+ {
+ width = MAX (width, minimum_width);
+ }
+ if (geometry_flags & EEL_GDK_HEIGHT_VALUE)
+ {
+ height = MAX (height, minimum_height);
+ }
+
+ /* Ignore saved window position if requested. */
+ if (ignore_position)
+ {
+ geometry_flags &= ~(EEL_GDK_X_VALUE | EEL_GDK_Y_VALUE);
+ }
+
+ eel_gtk_window_set_initial_geometry (window, geometry_flags, left, top, width, height);
}
/**
* eel_pop_up_context_menu:
- *
+ *
* Pop up a context menu under the mouse.
- * The menu is sunk after use, so it will be destroyed unless the
+ * The menu is sunk after use, so it will be destroyed unless the
* caller first ref'ed it.
- *
+ *
* This function is more of a helper function than a gtk extension,
* so perhaps it belongs in a different file.
- *
+ *
* @menu: The menu to pop up under the mouse.
* @offset_x: Ignored.
* @offset_y: Ignored.
@@ -263,76 +271,80 @@ eel_gtk_window_set_initial_geometry_from_string (GtkWindow *window,
* is no event available. This is used to get the timestamp for the menu's popup.
* In case no event is provided, gtk_get_current_event_time() will be used automatically.
**/
-void
-eel_pop_up_context_menu (GtkMenu *menu,
- GdkEventButton *event)
+void
+eel_pop_up_context_menu (GtkMenu *menu,
+ GdkEventButton *event)
{
- int button;
-
- g_return_if_fail (GTK_IS_MENU (menu));
-
- /* The event button needs to be 0 if we're popping up this menu from
- * a button release, else a 2nd click outside the menu with any button
- * other than the one that invoked the menu will be ignored (instead
- * of dismissing the menu). This is a subtle fragility of the GTK menu code.
- */
-
- if (event) {
- button = event->type == GDK_BUTTON_RELEASE
- ? 0
- : event->button;
- } else {
- button = 0;
- }
-
- gtk_menu_popup (menu, /* menu */
- NULL, /* parent_menu_shell */
- NULL, /* parent_menu_item */
- NULL, /* popup_position_func */
- NULL, /* popup_position_data */
- button, /* button */
- event ? event->time : gtk_get_current_event_time ()); /* activate_time */
-
- g_object_ref_sink (menu);
- g_object_unref (menu);
+ int button;
+
+ g_return_if_fail (GTK_IS_MENU (menu));
+
+ /* The event button needs to be 0 if we're popping up this menu from
+ * a button release, else a 2nd click outside the menu with any button
+ * other than the one that invoked the menu will be ignored (instead
+ * of dismissing the menu). This is a subtle fragility of the GTK menu code.
+ */
+
+ if (event)
+ {
+ button = event->type == GDK_BUTTON_RELEASE
+ ? 0
+ : event->button;
+ }
+ else
+ {
+ button = 0;
+ }
+
+ gtk_menu_popup (menu, /* menu */
+ NULL, /* parent_menu_shell */
+ NULL, /* parent_menu_item */
+ NULL, /* popup_position_func */
+ NULL, /* popup_position_data */
+ button, /* button */
+ event ? event->time : gtk_get_current_event_time ()); /* activate_time */
+
+ g_object_ref_sink (menu);
+ g_object_unref (menu);
}
GtkMenuItem *
eel_gtk_menu_append_separator (GtkMenu *menu)
{
- return eel_gtk_menu_insert_separator (menu, -1);
+ return eel_gtk_menu_insert_separator (menu, -1);
}
GtkMenuItem *
-eel_gtk_menu_insert_separator (GtkMenu *menu, int index)
+eel_gtk_menu_insert_separator (GtkMenu *menu,
+ int index)
{
- GtkWidget *menu_item;
+ GtkWidget *menu_item;
- menu_item = gtk_separator_menu_item_new ();
- gtk_widget_show (menu_item);
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, index);
+ menu_item = gtk_separator_menu_item_new ();
+ gtk_widget_show (menu_item);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, index);
- return GTK_MENU_ITEM (menu_item);
+ return GTK_MENU_ITEM (menu_item);
}
void
eel_gtk_message_dialog_set_details_label (GtkMessageDialog *dialog,
- const gchar *details_text)
+ const gchar *details_text)
{
- GtkWidget *content_area, *expander, *label;
+ GtkWidget *content_area, *expander, *label;
- content_area = gtk_message_dialog_get_message_area (dialog);
- expander = gtk_expander_new_with_mnemonic (_("Show more _details"));
- gtk_expander_set_spacing (GTK_EXPANDER (expander), 6);
+ content_area = gtk_message_dialog_get_message_area (dialog);
+ expander = gtk_expander_new_with_mnemonic (_("Show more _details"));
+ gtk_expander_set_spacing (GTK_EXPANDER (expander), 6);
- label = gtk_label_new (details_text);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_label_set_selectable (GTK_LABEL (label), TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
+ label = gtk_label_new (details_text);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_container_add (GTK_CONTAINER (expander), label);
- gtk_box_pack_start (GTK_BOX (content_area), expander, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (expander), label);
+ gtk_box_pack_start (GTK_BOX (content_area), expander, FALSE, FALSE, 0);
- gtk_widget_show (label);
- gtk_widget_show (expander);
+ gtk_widget_show (label);
+ gtk_widget_show (expander);
}
diff --git a/eel/eel-lib-self-check-functions.c b/eel/eel-lib-self-check-functions.c
index 2c180e8ae..af1dddfa9 100644
--- a/eel/eel-lib-self-check-functions.c
+++ b/eel/eel-lib-self-check-functions.c
@@ -1,35 +1,35 @@
/*
- eel-lib-self-check-functions.c: Wrapper for all self check functions
- in Eel proper.
-
- Copyright (C) 2000 Eazel, Inc.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@eazel.com>
-*/
+ * eel-lib-self-check-functions.c: Wrapper for all self check functions
+ * in Eel proper.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
-#if ! defined (EEL_OMIT_SELF_CHECK)
+#if !defined (EEL_OMIT_SELF_CHECK)
#include "eel-lib-self-check-functions.h"
void
eel_run_lib_self_checks (void)
{
- EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION (EEL_CALL_SELF_CHECK_FUNCTION)
+ EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION (EEL_CALL_SELF_CHECK_FUNCTION)
}
#endif /* ! EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-self-checks.c b/eel/eel-self-checks.c
index 8de01a421..0ed94f265 100644
--- a/eel/eel-self-checks.c
+++ b/eel/eel-self-checks.c
@@ -1,27 +1,27 @@
/*
- eel-self-checks.c: The self-check framework.
-
- Copyright (C) 1999 Eazel, Inc.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with this program; if not, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@eazel.com>
-*/
+ * eel-self-checks.c: The self-check framework.
+ *
+ * Copyright (C) 1999 Eazel, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
-#if ! defined (EEL_OMIT_SELF_CHECK)
+#if !defined (EEL_OMIT_SELF_CHECK)
#include "eel-self-checks.h"
@@ -38,142 +38,161 @@ static int current_line_number;
void
eel_exit_if_self_checks_failed (void)
{
- if (!failed) {
- return;
- }
+ if (!failed)
+ {
+ return;
+ }
- printf ("\n");
+ printf ("\n");
- exit (EXIT_FAILURE);
+ exit (EXIT_FAILURE);
}
void
-eel_report_check_failure (char *result, char *expected)
+eel_report_check_failure (char *result,
+ char *expected)
{
- if (!failed) {
- fprintf (stderr, "\n");
- }
-
- fprintf (stderr, "FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
- fprintf (stderr, " evaluated: %s\n", current_expression);
- fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected);
- fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result);
-
- failed = TRUE;
-
- g_free (result);
- g_free (expected);
+ if (!failed)
+ {
+ fprintf (stderr, "\n");
+ }
+
+ fprintf (stderr, "FAIL: check failed in %s, line %d\n", current_file_name, current_line_number);
+ fprintf (stderr, " evaluated: %s\n", current_expression);
+ fprintf (stderr, " expected: %s\n", expected == NULL ? "NULL" : expected);
+ fprintf (stderr, " got: %s\n", result == NULL ? "NULL" : result);
+
+ failed = TRUE;
+
+ g_free (result);
+ g_free (expected);
}
static char *
eel_strdup_boolean (gboolean boolean)
{
- if (boolean == FALSE) {
- return g_strdup ("FALSE");
- }
- if (boolean == TRUE) {
- return g_strdup ("TRUE");
- }
- return g_strdup_printf ("gboolean(%d)", boolean);
+ if (boolean == FALSE)
+ {
+ return g_strdup ("FALSE");
+ }
+ if (boolean == TRUE)
+ {
+ return g_strdup ("TRUE");
+ }
+ return g_strdup_printf ("gboolean(%d)", boolean);
}
void
eel_before_check (const char *expression,
- const char *file_name,
- int line_number)
+ const char *file_name,
+ int line_number)
{
- current_expression = expression;
- current_file_name = file_name;
- current_line_number = line_number;
+ current_expression = expression;
+ current_file_name = file_name;
+ current_line_number = line_number;
}
void
eel_after_check (void)
{
- /* It would be good to check here if there was a memory leak. */
+ /* It would be good to check here if there was a memory leak. */
}
void
-eel_check_boolean_result (gboolean result, gboolean expected)
+eel_check_boolean_result (gboolean result,
+ gboolean expected)
{
- if (result != expected) {
- eel_report_check_failure (eel_strdup_boolean (result),
- eel_strdup_boolean (expected));
- }
- eel_after_check ();
+ if (result != expected)
+ {
+ eel_report_check_failure (eel_strdup_boolean (result),
+ eel_strdup_boolean (expected));
+ }
+ eel_after_check ();
}
void
eel_check_rectangle_result (EelIRect result,
- int expected_x0,
- int expected_y0,
- int expected_x1,
- int expected_y1)
+ int expected_x0,
+ int expected_y0,
+ int expected_x1,
+ int expected_y1)
{
- if (result.x0 != expected_x0
- || result.y0 != expected_y0
- || result.x1 != expected_x1
- || result.y1 != expected_y1) {
- eel_report_check_failure (g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
- result.x0,
- result.y0,
- result.x1,
- result.y1),
- g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
- expected_x0,
- expected_y0,
- expected_x1,
- expected_y1));
- }
- eel_after_check ();
+ if (result.x0 != expected_x0
+ || result.y0 != expected_y0
+ || result.x1 != expected_x1
+ || result.y1 != expected_y1)
+ {
+ eel_report_check_failure (g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
+ result.x0,
+ result.y0,
+ result.x1,
+ result.y1),
+ g_strdup_printf ("x0=%d, y0=%d, x1=%d, y1=%d",
+ expected_x0,
+ expected_y0,
+ expected_x1,
+ expected_y1));
+ }
+ eel_after_check ();
}
void
-eel_check_integer_result (long result, long expected)
+eel_check_integer_result (long result,
+ long expected)
{
- if (result != expected) {
- eel_report_check_failure (g_strdup_printf ("%ld", result),
- g_strdup_printf ("%ld", expected));
- }
- eel_after_check ();
+ if (result != expected)
+ {
+ eel_report_check_failure (g_strdup_printf ("%ld", result),
+ g_strdup_printf ("%ld", expected));
+ }
+ eel_after_check ();
}
void
-eel_check_double_result (double result, double expected)
+eel_check_double_result (double result,
+ double expected)
{
- if (result != expected) {
- eel_report_check_failure (g_strdup_printf ("%f", result),
- g_strdup_printf ("%f", expected));
- }
- eel_after_check ();
+ if (result != expected)
+ {
+ eel_report_check_failure (g_strdup_printf ("%f", result),
+ g_strdup_printf ("%f", expected));
+ }
+ eel_after_check ();
}
void
-eel_check_string_result (char *result, const char *expected)
+eel_check_string_result (char *result,
+ const char *expected)
{
- gboolean match;
-
- /* Stricter than eel_strcmp.
- * NULL does not match "" in this test.
- */
- if (expected == NULL) {
- match = result == NULL;
- } else {
- match = result != NULL && strcmp (result, expected) == 0;
- }
-
- if (!match) {
- eel_report_check_failure (result, g_strdup (expected));
- } else {
- g_free (result);
- }
- eel_after_check ();
+ gboolean match;
+
+ /* Stricter than eel_strcmp.
+ * NULL does not match "" in this test.
+ */
+ if (expected == NULL)
+ {
+ match = result == NULL;
+ }
+ else
+ {
+ match = result != NULL && strcmp (result, expected) == 0;
+ }
+
+ if (!match)
+ {
+ eel_report_check_failure (result, g_strdup (expected));
+ }
+ else
+ {
+ g_free (result);
+ }
+ eel_after_check ();
}
void
eel_before_check_function (const char *name)
{
- fprintf (stderr, "running %s\n", name);
+ fprintf (stderr, "running %s\n", name);
}
void
diff --git a/eel/eel-stock-dialogs.c b/eel/eel-stock-dialogs.c
index 2de57672b..499af99d5 100644
--- a/eel/eel-stock-dialogs.c
+++ b/eel/eel-stock-dialogs.c
@@ -1,24 +1,23 @@
-
/* eel-stock-dialogs.c: Various standard dialogs for Eel.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-stock-dialogs.h"
@@ -36,429 +35,452 @@
#define RESPONSE_DETAILS 1000
-typedef struct {
- EelCancelCallback cancel_callback;
- gpointer callback_data;
+typedef struct
+{
+ EelCancelCallback cancel_callback;
+ gpointer callback_data;
- /* Parameters for creation of the window. */
- char *wait_message;
- GtkWindow *parent_window;
+ /* Parameters for creation of the window. */
+ char *wait_message;
+ GtkWindow *parent_window;
- /* Timer to determine when we need to create the window. */
- guint timeout_handler_id;
-
- /* Window, once it's created. */
- GtkDialog *dialog;
-
- /* system time (microseconds) when dialog was created */
- gint64 dialog_creation_time;
+ /* Timer to determine when we need to create the window. */
+ guint timeout_handler_id;
+ /* Window, once it's created. */
+ GtkDialog *dialog;
+
+ /* system time (microseconds) when dialog was created */
+ gint64 dialog_creation_time;
} TimedWait;
static GHashTable *timed_wait_hash_table;
-static void timed_wait_dialog_destroy_callback (GtkWidget *object, gpointer callback_data);
+static void timed_wait_dialog_destroy_callback (GtkWidget *object,
+ gpointer callback_data);
static guint
timed_wait_hash (gconstpointer value)
{
- const TimedWait *wait;
+ const TimedWait *wait;
- wait = value;
+ wait = value;
- return GPOINTER_TO_UINT (wait->cancel_callback)
- ^ GPOINTER_TO_UINT (wait->callback_data);
+ return GPOINTER_TO_UINT (wait->cancel_callback)
+ ^ GPOINTER_TO_UINT (wait->callback_data);
}
static gboolean
-timed_wait_hash_equal (gconstpointer value1, gconstpointer value2)
+timed_wait_hash_equal (gconstpointer value1,
+ gconstpointer value2)
{
- const TimedWait *wait1, *wait2;
+ const TimedWait *wait1, *wait2;
- wait1 = value1;
- wait2 = value2;
+ wait1 = value1;
+ wait2 = value2;
- return wait1->cancel_callback == wait2->cancel_callback
- && wait1->callback_data == wait2->callback_data;
+ return wait1->cancel_callback == wait2->cancel_callback
+ && wait1->callback_data == wait2->callback_data;
}
static void
-timed_wait_delayed_close_destroy_dialog_callback (GtkWidget *object, gpointer callback_data)
+timed_wait_delayed_close_destroy_dialog_callback (GtkWidget *object,
+ gpointer callback_data)
{
- g_source_remove (GPOINTER_TO_UINT (callback_data));
+ g_source_remove (GPOINTER_TO_UINT (callback_data));
}
static gboolean
timed_wait_delayed_close_timeout_callback (gpointer callback_data)
{
- guint handler_id;
-
- handler_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (callback_data),
- "eel-stock-dialogs/delayed_close_handler_timeout_id"));
-
- g_signal_handlers_disconnect_by_func (G_OBJECT (callback_data),
- G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
- GUINT_TO_POINTER (handler_id));
-
- gtk_widget_destroy (GTK_WIDGET (callback_data));
-
- return FALSE;
+ guint handler_id;
+
+ handler_id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (callback_data),
+ "eel-stock-dialogs/delayed_close_handler_timeout_id"));
+
+ g_signal_handlers_disconnect_by_func (G_OBJECT (callback_data),
+ G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
+ GUINT_TO_POINTER (handler_id));
+
+ gtk_widget_destroy (GTK_WIDGET (callback_data));
+
+ return FALSE;
}
static void
timed_wait_free (TimedWait *wait)
{
- guint delayed_close_handler_id;
- guint64 time_up;
-
- g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) != NULL);
-
- g_hash_table_remove (timed_wait_hash_table, wait);
-
- g_free (wait->wait_message);
- if (wait->parent_window != NULL) {
- g_object_unref (wait->parent_window);
- }
- if (wait->timeout_handler_id != 0) {
- g_source_remove (wait->timeout_handler_id);
- }
- if (wait->dialog != NULL) {
- /* Make sure to detach from the "destroy" signal, or we'll
- * double-free.
- */
- g_signal_handlers_disconnect_by_func (G_OBJECT (wait->dialog),
- G_CALLBACK (timed_wait_dialog_destroy_callback),
- wait);
-
- /* compute time up in milliseconds */
- time_up = (g_get_monotonic_time () - wait->dialog_creation_time) / 1000;
-
- if (time_up < TIMED_WAIT_MIN_TIME_UP) {
- delayed_close_handler_id = g_timeout_add (TIMED_WAIT_MIN_TIME_UP - time_up,
- timed_wait_delayed_close_timeout_callback,
- wait->dialog);
- g_object_set_data (G_OBJECT (wait->dialog),
- "eel-stock-dialogs/delayed_close_handler_timeout_id",
- GUINT_TO_POINTER (delayed_close_handler_id));
- g_signal_connect (wait->dialog, "destroy",
- G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
- GUINT_TO_POINTER (delayed_close_handler_id));
- } else {
- gtk_widget_destroy (GTK_WIDGET (wait->dialog));
- }
- }
-
- /* And the wait object itself. */
- g_free (wait);
+ guint delayed_close_handler_id;
+ guint64 time_up;
+
+ g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) != NULL);
+
+ g_hash_table_remove (timed_wait_hash_table, wait);
+
+ g_free (wait->wait_message);
+ if (wait->parent_window != NULL)
+ {
+ g_object_unref (wait->parent_window);
+ }
+ if (wait->timeout_handler_id != 0)
+ {
+ g_source_remove (wait->timeout_handler_id);
+ }
+ if (wait->dialog != NULL)
+ {
+ /* Make sure to detach from the "destroy" signal, or we'll
+ * double-free.
+ */
+ g_signal_handlers_disconnect_by_func (G_OBJECT (wait->dialog),
+ G_CALLBACK (timed_wait_dialog_destroy_callback),
+ wait);
+
+ /* compute time up in milliseconds */
+ time_up = (g_get_monotonic_time () - wait->dialog_creation_time) / 1000;
+
+ if (time_up < TIMED_WAIT_MIN_TIME_UP)
+ {
+ delayed_close_handler_id = g_timeout_add (TIMED_WAIT_MIN_TIME_UP - time_up,
+ timed_wait_delayed_close_timeout_callback,
+ wait->dialog);
+ g_object_set_data (G_OBJECT (wait->dialog),
+ "eel-stock-dialogs/delayed_close_handler_timeout_id",
+ GUINT_TO_POINTER (delayed_close_handler_id));
+ g_signal_connect (wait->dialog, "destroy",
+ G_CALLBACK (timed_wait_delayed_close_destroy_dialog_callback),
+ GUINT_TO_POINTER (delayed_close_handler_id));
+ }
+ else
+ {
+ gtk_widget_destroy (GTK_WIDGET (wait->dialog));
+ }
+ }
+
+ /* And the wait object itself. */
+ g_free (wait);
}
static void
-timed_wait_dialog_destroy_callback (GtkWidget *object, gpointer callback_data)
+timed_wait_dialog_destroy_callback (GtkWidget *object,
+ gpointer callback_data)
{
- TimedWait *wait;
+ TimedWait *wait;
- wait = callback_data;
+ wait = callback_data;
- g_assert (GTK_DIALOG (object) == wait->dialog);
+ g_assert (GTK_DIALOG (object) == wait->dialog);
- wait->dialog = NULL;
-
- /* When there's no cancel_callback, the originator will/must
- * call eel_timed_wait_stop which will call timed_wait_free.
- */
+ wait->dialog = NULL;
- if (wait->cancel_callback != NULL) {
- (* wait->cancel_callback) (wait->callback_data);
- timed_wait_free (wait);
- }
+ /* When there's no cancel_callback, the originator will/must
+ * call eel_timed_wait_stop which will call timed_wait_free.
+ */
+
+ if (wait->cancel_callback != NULL)
+ {
+ (*wait->cancel_callback)(wait->callback_data);
+ timed_wait_free (wait);
+ }
}
static void
trash_dialog_response_callback (GtkDialog *dialog,
- int response_id,
- TimedWait *wait)
+ int response_id,
+ TimedWait *wait)
{
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static gboolean
timed_wait_callback (gpointer callback_data)
{
- TimedWait *wait;
- GtkDialog *dialog;
- const char *button;
-
- wait = callback_data;
-
- /* Put up the timed wait window. */
- button = wait->cancel_callback != NULL ? _("_Cancel") : ("_OK");
- dialog = GTK_DIALOG (gtk_message_dialog_new (wait->parent_window,
- 0,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_NONE,
- NULL));
-
- g_object_set (dialog,
- "text", wait->wait_message,
- "secondary-text", _("You can stop this operation by clicking cancel."),
- NULL);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- /* The contents are often very small, causing tiny little
- * dialogs with their titles clipped if you just let gtk
- * sizing do its thing. This enforces a minimum width to
- * make it more likely that the title won't be clipped.
- */
- gtk_window_set_default_size (GTK_WINDOW (dialog),
- TIMED_WAIT_MINIMUM_DIALOG_WIDTH,
- -1);
- wait->dialog_creation_time = g_get_monotonic_time ();
- gtk_widget_show (GTK_WIDGET (dialog));
-
- /* FIXME bugzilla.eazel.com 2441:
- * Could parent here, but it's complicated because we
- * don't want this window to go away just because the parent
- * would go away first.
- */
-
- /* Make the dialog cancel the timed wait when it goes away.
- * Connect to "destroy" instead of "response" since we want
- * to be called no matter how the dialog goes away.
- */
- g_signal_connect (dialog, "destroy",
- G_CALLBACK (timed_wait_dialog_destroy_callback),
- wait);
- g_signal_connect (dialog, "response",
- G_CALLBACK (trash_dialog_response_callback),
- wait);
-
- wait->timeout_handler_id = 0;
- wait->dialog = dialog;
-
- return FALSE;
+ TimedWait *wait;
+ GtkDialog *dialog;
+ const char *button;
+
+ wait = callback_data;
+
+ /* Put up the timed wait window. */
+ button = wait->cancel_callback != NULL ? _("_Cancel") : ("_OK");
+ dialog = GTK_DIALOG (gtk_message_dialog_new (wait->parent_window,
+ 0,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_NONE,
+ NULL));
+
+ g_object_set (dialog,
+ "text", wait->wait_message,
+ "secondary-text", _("You can stop this operation by clicking cancel."),
+ NULL);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), button, GTK_RESPONSE_OK);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ /* The contents are often very small, causing tiny little
+ * dialogs with their titles clipped if you just let gtk
+ * sizing do its thing. This enforces a minimum width to
+ * make it more likely that the title won't be clipped.
+ */
+ gtk_window_set_default_size (GTK_WINDOW (dialog),
+ TIMED_WAIT_MINIMUM_DIALOG_WIDTH,
+ -1);
+ wait->dialog_creation_time = g_get_monotonic_time ();
+ gtk_widget_show (GTK_WIDGET (dialog));
+
+ /* FIXME bugzilla.eazel.com 2441:
+ * Could parent here, but it's complicated because we
+ * don't want this window to go away just because the parent
+ * would go away first.
+ */
+
+ /* Make the dialog cancel the timed wait when it goes away.
+ * Connect to "destroy" instead of "response" since we want
+ * to be called no matter how the dialog goes away.
+ */
+ g_signal_connect (dialog, "destroy",
+ G_CALLBACK (timed_wait_dialog_destroy_callback),
+ wait);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (trash_dialog_response_callback),
+ wait);
+
+ wait->timeout_handler_id = 0;
+ wait->dialog = dialog;
+
+ return FALSE;
}
void
-eel_timed_wait_start_with_duration (int duration,
- EelCancelCallback cancel_callback,
- gpointer callback_data,
- const char *wait_message,
- GtkWindow *parent_window)
+eel_timed_wait_start_with_duration (int duration,
+ EelCancelCallback cancel_callback,
+ gpointer callback_data,
+ const char *wait_message,
+ GtkWindow *parent_window)
{
- TimedWait *wait;
-
- g_return_if_fail (callback_data != NULL);
- g_return_if_fail (wait_message != NULL);
- g_return_if_fail (parent_window == NULL || GTK_IS_WINDOW (parent_window));
-
- /* Create the timed wait record. */
- wait = g_new0 (TimedWait, 1);
- wait->wait_message = g_strdup (wait_message);
- wait->cancel_callback = cancel_callback;
- wait->callback_data = callback_data;
- wait->parent_window = parent_window;
-
- if (parent_window != NULL) {
- g_object_ref (parent_window);
- }
-
- /* Start the timer. */
- wait->timeout_handler_id = g_timeout_add (duration, timed_wait_callback, wait);
-
- /* Put in the hash table so we can find it later. */
- if (timed_wait_hash_table == NULL) {
- timed_wait_hash_table = g_hash_table_new (timed_wait_hash, timed_wait_hash_equal);
- }
- g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
- g_hash_table_insert (timed_wait_hash_table, wait, wait);
- g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == wait);
+ TimedWait *wait;
+
+ g_return_if_fail (callback_data != NULL);
+ g_return_if_fail (wait_message != NULL);
+ g_return_if_fail (parent_window == NULL || GTK_IS_WINDOW (parent_window));
+
+ /* Create the timed wait record. */
+ wait = g_new0 (TimedWait, 1);
+ wait->wait_message = g_strdup (wait_message);
+ wait->cancel_callback = cancel_callback;
+ wait->callback_data = callback_data;
+ wait->parent_window = parent_window;
+
+ if (parent_window != NULL)
+ {
+ g_object_ref (parent_window);
+ }
+
+ /* Start the timer. */
+ wait->timeout_handler_id = g_timeout_add (duration, timed_wait_callback, wait);
+
+ /* Put in the hash table so we can find it later. */
+ if (timed_wait_hash_table == NULL)
+ {
+ timed_wait_hash_table = g_hash_table_new (timed_wait_hash, timed_wait_hash_equal);
+ }
+ g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
+ g_hash_table_insert (timed_wait_hash_table, wait, wait);
+ g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == wait);
}
void
-eel_timed_wait_start (EelCancelCallback cancel_callback,
- gpointer callback_data,
- const char *wait_message,
- GtkWindow *parent_window)
+eel_timed_wait_start (EelCancelCallback cancel_callback,
+ gpointer callback_data,
+ const char *wait_message,
+ GtkWindow *parent_window)
{
- eel_timed_wait_start_with_duration
- (TIMED_WAIT_STANDARD_DURATION,
- cancel_callback, callback_data,
- wait_message, parent_window);
+ eel_timed_wait_start_with_duration
+ (TIMED_WAIT_STANDARD_DURATION,
+ cancel_callback, callback_data,
+ wait_message, parent_window);
}
void
eel_timed_wait_stop (EelCancelCallback cancel_callback,
- gpointer callback_data)
+ gpointer callback_data)
{
- TimedWait key;
- TimedWait *wait;
+ TimedWait key;
+ TimedWait *wait;
+
+ g_return_if_fail (callback_data != NULL);
- g_return_if_fail (callback_data != NULL);
-
- key.cancel_callback = cancel_callback;
- key.callback_data = callback_data;
- wait = g_hash_table_lookup (timed_wait_hash_table, &key);
+ key.cancel_callback = cancel_callback;
+ key.callback_data = callback_data;
+ wait = g_hash_table_lookup (timed_wait_hash_table, &key);
- g_return_if_fail (wait != NULL);
+ g_return_if_fail (wait != NULL);
- timed_wait_free (wait);
+ timed_wait_free (wait);
}
int
-eel_run_simple_dialog (GtkWidget *parent, gboolean ignore_close_box,
- GtkMessageType message_type, const char *primary_text,
- const char *secondary_text, ...)
+eel_run_simple_dialog (GtkWidget *parent,
+ gboolean ignore_close_box,
+ GtkMessageType message_type,
+ const char *primary_text,
+ const char *secondary_text,
+ ...)
{
- va_list button_title_args;
- const char *button_title;
- GtkWidget *dialog;
- GtkWidget *top_widget, *chosen_parent;
- int result;
- int response_id;
-
- /* Parent it if asked to. */
- chosen_parent = NULL;
- if (parent != NULL) {
- top_widget = gtk_widget_get_toplevel (parent);
- if (GTK_IS_WINDOW (top_widget)) {
- chosen_parent = top_widget;
- }
- }
-
- /* Create the dialog. */
- dialog = gtk_message_dialog_new (GTK_WINDOW (chosen_parent),
- 0,
- message_type,
- GTK_BUTTONS_NONE,
- NULL);
-
- g_object_set (dialog,
- "text", primary_text,
- "secondary-text", secondary_text,
- NULL);
-
- va_start (button_title_args, secondary_text);
- response_id = 0;
- while (1) {
- button_title = va_arg (button_title_args, const char *);
- if (button_title == NULL) {
- break;
- }
- gtk_dialog_add_button (GTK_DIALOG (dialog), button_title, response_id);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
- response_id++;
- }
- va_end (button_title_args);
-
- /* Run it. */
- gtk_widget_show (dialog);
+ va_list button_title_args;
+ const char *button_title;
+ GtkWidget *dialog;
+ GtkWidget *top_widget, *chosen_parent;
+ int result;
+ int response_id;
+
+ /* Parent it if asked to. */
+ chosen_parent = NULL;
+ if (parent != NULL)
+ {
+ top_widget = gtk_widget_get_toplevel (parent);
+ if (GTK_IS_WINDOW (top_widget))
+ {
+ chosen_parent = top_widget;
+ }
+ }
+
+ /* Create the dialog. */
+ dialog = gtk_message_dialog_new (GTK_WINDOW (chosen_parent),
+ 0,
+ message_type,
+ GTK_BUTTONS_NONE,
+ NULL);
+
+ g_object_set (dialog,
+ "text", primary_text,
+ "secondary-text", secondary_text,
+ NULL);
+
+ va_start (button_title_args, secondary_text);
+ response_id = 0;
+ while (1)
+ {
+ button_title = va_arg (button_title_args, const char *);
+ if (button_title == NULL)
+ {
+ break;
+ }
+ gtk_dialog_add_button (GTK_DIALOG (dialog), button_title, response_id);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
+ response_id++;
+ }
+ va_end (button_title_args);
+
+ /* Run it. */
+ gtk_widget_show (dialog);
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && ignore_close_box)
+ {
+ gtk_widget_show (GTK_WIDGET (dialog));
result = gtk_dialog_run (GTK_DIALOG (dialog));
- while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && ignore_close_box) {
- gtk_widget_show (GTK_WIDGET (dialog));
- result = gtk_dialog_run (GTK_DIALOG (dialog));
- }
- gtk_widget_destroy (dialog);
+ }
+ gtk_widget_destroy (dialog);
- return result;
+ return result;
}
static GtkDialog *
-create_message_dialog (const char *primary_text,
- const char *secondary_text,
- GtkMessageType type,
- GtkButtonsType buttons_type,
- GtkWindow *parent)
-{
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (parent,
- 0,
- type,
- buttons_type,
- NULL);
- if (parent)
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- g_object_set (dialog,
- "text", primary_text,
- "secondary-text", secondary_text,
- NULL);
-
- return GTK_DIALOG (dialog);
+create_message_dialog (const char *primary_text,
+ const char *secondary_text,
+ GtkMessageType type,
+ GtkButtonsType buttons_type,
+ GtkWindow *parent)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (parent,
+ 0,
+ type,
+ buttons_type,
+ NULL);
+ if (parent)
+ {
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ }
+
+ g_object_set (dialog,
+ "text", primary_text,
+ "secondary-text", secondary_text,
+ NULL);
+
+ return GTK_DIALOG (dialog);
}
static GtkDialog *
-show_message_dialog (const char *primary_text,
- const char *secondary_text,
- GtkMessageType type,
- GtkButtonsType buttons_type,
- GtkWindow *parent)
+show_message_dialog (const char *primary_text,
+ const char *secondary_text,
+ GtkMessageType type,
+ GtkButtonsType buttons_type,
+ GtkWindow *parent)
{
- GtkDialog *dialog;
+ GtkDialog *dialog;
- dialog = create_message_dialog (primary_text, secondary_text, type,
- buttons_type, parent);
- gtk_widget_show (GTK_WIDGET (dialog));
+ dialog = create_message_dialog (primary_text, secondary_text, type,
+ buttons_type, parent);
+ gtk_widget_show (GTK_WIDGET (dialog));
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy), NULL);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
- return dialog;
+ return dialog;
}
static GtkDialog *
-show_ok_dialog (const char *primary_text,
- const char *secondary_text,
- GtkMessageType type,
- GtkWindow *parent)
-{
- GtkDialog *dialog;
-
- dialog = show_message_dialog (primary_text, secondary_text, type,
- GTK_BUTTONS_OK, parent);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- return dialog;
+show_ok_dialog (const char *primary_text,
+ const char *secondary_text,
+ GtkMessageType type,
+ GtkWindow *parent)
+{
+ GtkDialog *dialog;
+
+ dialog = show_message_dialog (primary_text, secondary_text, type,
+ GTK_BUTTONS_OK, parent);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ return dialog;
}
GtkDialog *
eel_show_info_dialog (const char *primary_text,
- const char *secondary_text,
- GtkWindow *parent)
+ const char *secondary_text,
+ GtkWindow *parent)
{
- return show_ok_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_INFO, parent);
+ return show_ok_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_INFO, parent);
}
GtkDialog *
eel_show_warning_dialog (const char *primary_text,
- const char *secondary_text,
- GtkWindow *parent)
+ const char *secondary_text,
+ GtkWindow *parent)
{
- return show_ok_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_WARNING, parent);
+ return show_ok_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_WARNING, parent);
}
GtkDialog *
eel_show_error_dialog (const char *primary_text,
- const char *secondary_text,
- GtkWindow *parent)
+ const char *secondary_text,
+ GtkWindow *parent)
{
- return show_ok_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_ERROR, parent);
+ return show_ok_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_ERROR, parent);
}
/**
* eel_show_yes_no_dialog:
- *
+ *
* Create and show a dialog asking a question with two choices.
- * The caller needs to set up any necessary callbacks
+ * The caller needs to set up any necessary callbacks
* for the buttons. Use eel_create_question_dialog instead
* if any visual changes need to be made, to avoid flashiness.
* @question: The text of the question.
@@ -467,27 +489,27 @@ eel_show_error_dialog (const char *primary_text,
* @parent: The parent window for this dialog.
*/
GtkDialog *
-eel_show_yes_no_dialog (const char *primary_text,
- const char *secondary_text,
- const char *yes_label,
- const char *no_label,
- GtkWindow *parent)
+eel_show_yes_no_dialog (const char *primary_text,
+ const char *secondary_text,
+ const char *yes_label,
+ const char *no_label,
+ GtkWindow *parent)
{
- GtkDialog *dialog = NULL;
- dialog = eel_create_question_dialog (primary_text,
- secondary_text,
- no_label, GTK_RESPONSE_CANCEL,
- yes_label, GTK_RESPONSE_YES,
- GTK_WINDOW (parent));
- gtk_widget_show (GTK_WIDGET (dialog));
- return dialog;
+ GtkDialog *dialog = NULL;
+ dialog = eel_create_question_dialog (primary_text,
+ secondary_text,
+ no_label, GTK_RESPONSE_CANCEL,
+ yes_label, GTK_RESPONSE_YES,
+ GTK_WINDOW (parent));
+ gtk_widget_show (GTK_WIDGET (dialog));
+ return dialog;
}
/**
* eel_create_question_dialog:
- *
+ *
* Create a dialog asking a question with at least two choices.
- * The caller needs to set up any necessary callbacks
+ * The caller needs to set up any necessary callbacks
* for the buttons. The dialog is not yet shown, so that the
* caller can add additional buttons or make other visual changes
* without causing flashiness.
@@ -498,20 +520,20 @@ eel_show_yes_no_dialog (const char *primary_text,
*/
GtkDialog *
eel_create_question_dialog (const char *primary_text,
- const char *secondary_text,
- const char *answer_1,
- int response_1,
- const char *answer_2,
- int response_2,
- GtkWindow *parent)
+ const char *secondary_text,
+ const char *answer_1,
+ int response_1,
+ const char *answer_2,
+ int response_2,
+ GtkWindow *parent)
{
- GtkDialog *dialog;
-
- dialog = create_message_dialog (primary_text,
- secondary_text,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_NONE,
- parent);
- gtk_dialog_add_buttons (dialog, answer_1, response_1, answer_2, response_2, NULL);
- return dialog;
+ GtkDialog *dialog;
+
+ dialog = create_message_dialog (primary_text,
+ secondary_text,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ parent);
+ gtk_dialog_add_buttons (dialog, answer_1, response_1, answer_2, response_2, NULL);
+ return dialog;
}
diff --git a/eel/eel-string.c b/eel/eel-string.c
index e0f849c7f..9fe79ab98 100644
--- a/eel/eel-string.c
+++ b/eel/eel-string.c
@@ -1,24 +1,24 @@
/*
- eel-string.c: String routines to augment <string.h>.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
-*/
+ * eel-string.c: String routines to augment <string.h>.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ */
#include <config.h>
#include "eel-string.h"
@@ -36,207 +36,228 @@
char *
eel_str_double_underscores (const char *string)
{
- int underscores;
- const char *p;
- char *q;
- char *escaped;
-
- if (string == NULL) {
- return NULL;
- }
-
- underscores = 0;
- for (p = string; *p != '\0'; p++) {
- underscores += (*p == '_');
- }
-
- if (underscores == 0) {
- return g_strdup (string);
- }
-
- escaped = g_new (char, strlen (string) + underscores + 1);
- for (p = string, q = escaped; *p != '\0'; p++, q++) {
- /* Add an extra underscore. */
- if (*p == '_') {
- *q++ = '_';
- }
- *q = *p;
- }
- *q = '\0';
-
- return escaped;
+ int underscores;
+ const char *p;
+ char *q;
+ char *escaped;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ underscores = 0;
+ for (p = string; *p != '\0'; p++)
+ {
+ underscores += (*p == '_');
+ }
+
+ if (underscores == 0)
+ {
+ return g_strdup (string);
+ }
+
+ escaped = g_new (char, strlen (string) + underscores + 1);
+ for (p = string, q = escaped; *p != '\0'; p++, q++)
+ {
+ /* Add an extra underscore. */
+ if (*p == '_')
+ {
+ *q++ = '_';
+ }
+ *q = *p;
+ }
+ *q = '\0';
+
+ return escaped;
}
char *
eel_str_capitalize (const char *string)
{
- char *capitalized;
+ char *capitalized;
- if (string == NULL) {
- return NULL;
- }
+ if (string == NULL)
+ {
+ return NULL;
+ }
- capitalized = g_strdup (string);
+ capitalized = g_strdup (string);
- capitalized[0] = g_ascii_toupper (capitalized[0]);
+ capitalized[0] = g_ascii_toupper (capitalized[0]);
- return capitalized;
+ return capitalized;
}
/* Note: eel_string_ellipsize_* that use a length in pixels
* rather than characters can be found in eel_gdk_extensions.h
- *
- * FIXME bugzilla.eazel.com 5089:
+ *
+ * FIXME bugzilla.eazel.com 5089:
* we should coordinate the names of eel_string_ellipsize_*
* and eel_str_*_truncate so that they match better and reflect
* their different behavior.
*/
char *
eel_str_middle_truncate (const char *string,
- guint truncate_length)
+ guint truncate_length)
{
- char *truncated;
- guint length;
- guint num_left_chars;
- guint num_right_chars;
-
- const char delimter[] = "...";
- const guint delimter_length = strlen (delimter);
- const guint min_truncate_length = delimter_length + 2;
-
- if (string == NULL) {
- return NULL;
- }
-
- /* It doesnt make sense to truncate strings to less than
- * the size of the delimiter plus 2 characters (one on each
- * side)
- */
- if (truncate_length < min_truncate_length) {
- return g_strdup (string);
- }
-
- length = g_utf8_strlen (string, -1);
-
- /* Make sure the string is not already small enough. */
- if (length <= truncate_length) {
- return g_strdup (string);
- }
-
- /* Find the 'middle' where the truncation will occur. */
- num_left_chars = (truncate_length - delimter_length) / 2;
- num_right_chars = truncate_length - num_left_chars - delimter_length;
-
- truncated = g_new (char, strlen (string) + 1);
-
- g_utf8_strncpy (truncated, string, num_left_chars);
- strcat (truncated, delimter);
- strcat (truncated, g_utf8_offset_to_pointer (string, length - num_right_chars));
-
- return truncated;
+ char *truncated;
+ guint length;
+ guint num_left_chars;
+ guint num_right_chars;
+
+ const char delimter[] = "...";
+ const guint delimter_length = strlen (delimter);
+ const guint min_truncate_length = delimter_length + 2;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ /* It doesnt make sense to truncate strings to less than
+ * the size of the delimiter plus 2 characters (one on each
+ * side)
+ */
+ if (truncate_length < min_truncate_length)
+ {
+ return g_strdup (string);
+ }
+
+ length = g_utf8_strlen (string, -1);
+
+ /* Make sure the string is not already small enough. */
+ if (length <= truncate_length)
+ {
+ return g_strdup (string);
+ }
+
+ /* Find the 'middle' where the truncation will occur. */
+ num_left_chars = (truncate_length - delimter_length) / 2;
+ num_right_chars = truncate_length - num_left_chars - delimter_length;
+
+ truncated = g_new (char, strlen (string) + 1);
+
+ g_utf8_strncpy (truncated, string, num_left_chars);
+ strcat (truncated, delimter);
+ strcat (truncated, g_utf8_offset_to_pointer (string, length - num_right_chars));
+
+ return truncated;
}
char *
eel_str_strip_substring_and_after (const char *string,
- const char *substring)
+ const char *substring)
{
- const char *substring_position;
+ const char *substring_position;
- g_return_val_if_fail (substring != NULL, g_strdup (string));
- g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
+ g_return_val_if_fail (substring != NULL, g_strdup (string));
+ g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
- if (string == NULL) {
- return NULL;
- }
+ if (string == NULL)
+ {
+ return NULL;
+ }
- substring_position = strstr (string, substring);
- if (substring_position == NULL) {
- return g_strdup (string);
- }
+ substring_position = strstr (string, substring);
+ if (substring_position == NULL)
+ {
+ return g_strdup (string);
+ }
- return g_strndup (string,
- substring_position - string);
+ return g_strndup (string,
+ substring_position - string);
}
char *
eel_str_replace_substring (const char *string,
- const char *substring,
- const char *replacement)
+ const char *substring,
+ const char *replacement)
{
- int substring_length, replacement_length, result_length, remaining_length;
- const char *p, *substring_position;
- char *result, *result_position;
-
- g_return_val_if_fail (substring != NULL, g_strdup (string));
- g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
-
- if (string == NULL) {
- return NULL;
- }
-
- substring_length = substring ? strlen (substring) : 0;
- replacement_length = replacement ? strlen (replacement) : 0;
-
- result_length = strlen (string);
- for (p = string; ; p = substring_position + substring_length) {
- substring_position = strstr (p, substring);
- if (substring_position == NULL) {
- break;
- }
- result_length += replacement_length - substring_length;
- }
-
- result = g_malloc (result_length + 1);
-
- result_position = result;
- for (p = string; ; p = substring_position + substring_length) {
- substring_position = strstr (p, substring);
- if (substring_position == NULL) {
- remaining_length = strlen (p);
- memcpy (result_position, p, remaining_length);
- result_position += remaining_length;
- break;
- }
- memcpy (result_position, p, substring_position - p);
- result_position += substring_position - p;
- memcpy (result_position, replacement, replacement_length);
- result_position += replacement_length;
- }
- g_assert (result_position - result == result_length);
- result_position[0] = '\0';
-
- return result;
+ int substring_length, replacement_length, result_length, remaining_length;
+ const char *p, *substring_position;
+ char *result, *result_position;
+
+ g_return_val_if_fail (substring != NULL, g_strdup (string));
+ g_return_val_if_fail (substring[0] != '\0', g_strdup (string));
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ substring_length = substring ? strlen (substring) : 0;
+ replacement_length = replacement ? strlen (replacement) : 0;
+
+ result_length = strlen (string);
+ for (p = string;; p = substring_position + substring_length)
+ {
+ substring_position = strstr (p, substring);
+ if (substring_position == NULL)
+ {
+ break;
+ }
+ result_length += replacement_length - substring_length;
+ }
+
+ result = g_malloc (result_length + 1);
+
+ result_position = result;
+ for (p = string;; p = substring_position + substring_length)
+ {
+ substring_position = strstr (p, substring);
+ if (substring_position == NULL)
+ {
+ remaining_length = strlen (p);
+ memcpy (result_position, p, remaining_length);
+ result_position += remaining_length;
+ break;
+ }
+ memcpy (result_position, p, substring_position - p);
+ result_position += substring_position - p;
+ memcpy (result_position, replacement, replacement_length);
+ result_position += replacement_length;
+ }
+ g_assert (result_position - result == result_length);
+ result_position[0] = '\0';
+
+ return result;
}
char *
eel_str_rtrim_punctuation (char *str)
{
- int num_punctuation_chars;
- int str_len;
- int num_chars_left;
- char *current_char_pos;
- gunichar current_char;
+ int num_punctuation_chars;
+ int str_len;
+ int num_chars_left;
+ char *current_char_pos;
+ gunichar current_char;
- num_punctuation_chars = 0;
- str_len = g_utf8_strlen (str, -1);
- current_char_pos = g_utf8_offset_to_pointer (str, str_len);
+ num_punctuation_chars = 0;
+ str_len = g_utf8_strlen (str, -1);
+ current_char_pos = g_utf8_offset_to_pointer (str, str_len);
- while (num_punctuation_chars <= str_len) {
- current_char_pos = g_utf8_prev_char (current_char_pos);
- current_char = g_utf8_get_char (current_char_pos);
+ while (num_punctuation_chars <= str_len)
+ {
+ current_char_pos = g_utf8_prev_char (current_char_pos);
+ current_char = g_utf8_get_char (current_char_pos);
- if (!g_unichar_ispunct (current_char) && !g_unichar_isspace (current_char))
- break;
+ if (!g_unichar_ispunct (current_char) && !g_unichar_isspace (current_char))
+ {
+ break;
+ }
- ++num_punctuation_chars;
- }
+ ++num_punctuation_chars;
+ }
- if (num_punctuation_chars == 0)
- return g_strdup (str);
+ if (num_punctuation_chars == 0)
+ {
+ return g_strdup (str);
+ }
- num_chars_left = str_len - num_punctuation_chars;
+ num_chars_left = str_len - num_punctuation_chars;
- return g_utf8_substring (str, 0, num_chars_left);
+ return g_utf8_substring (str, 0, num_chars_left);
}
/**
@@ -251,460 +272,550 @@ eel_str_rtrim_punctuation (char *str)
*/
static int
get_common_prefix_length (char *str_a,
- char *str_b,
- int min_required_len)
+ char *str_b,
+ int min_required_len)
{
- int a_len;
- int b_len;
- int intersection_len;
- int matching_chars;
- char *a;
- char *b;
-
- a_len = g_utf8_strlen (str_a, -1);
- b_len = g_utf8_strlen (str_b, -1);
-
- intersection_len = MIN (a_len, b_len);
- if (intersection_len < min_required_len)
- return -1;
-
- matching_chars = 0;
- a = str_a;
- b = str_b;
- while (matching_chars < intersection_len) {
- if (g_utf8_get_char (a) != g_utf8_get_char (b))
- break;
-
- ++matching_chars;
-
- a = g_utf8_next_char (a);
- b = g_utf8_next_char (b);
- }
-
- if (matching_chars < min_required_len)
- return -1;
-
- return matching_chars;
+ int a_len;
+ int b_len;
+ int intersection_len;
+ int matching_chars;
+ char *a;
+ char *b;
+
+ a_len = g_utf8_strlen (str_a, -1);
+ b_len = g_utf8_strlen (str_b, -1);
+
+ intersection_len = MIN (a_len, b_len);
+ if (intersection_len < min_required_len)
+ {
+ return -1;
+ }
+
+ matching_chars = 0;
+ a = str_a;
+ b = str_b;
+ while (matching_chars < intersection_len)
+ {
+ if (g_utf8_get_char (a) != g_utf8_get_char (b))
+ {
+ break;
+ }
+
+ ++matching_chars;
+
+ a = g_utf8_next_char (a);
+ b = g_utf8_next_char (b);
+ }
+
+ if (matching_chars < min_required_len)
+ {
+ return -1;
+ }
+
+ return matching_chars;
}
char *
-eel_str_get_common_prefix (GList *strs, int min_required_len)
+eel_str_get_common_prefix (GList *strs,
+ int min_required_len)
{
- GList *l;
- char *common_part;
- char *name;
- char *truncated;
- int matching_chars;
-
- if (strs == NULL)
- return NULL;
-
- common_part = NULL;
- for (l = strs; l != NULL; l = l->next) {
-
- name = l->data;
- if (name == NULL) {
- g_free (common_part);
- return NULL;
- }
-
- if (l->prev == NULL) {
- common_part = g_strdup (name);
- continue;
- }
-
- matching_chars = get_common_prefix_length (common_part, name, min_required_len);
-
- if (matching_chars == -1) {
- g_free (common_part);
- return NULL;
- }
-
- truncated = g_utf8_substring (common_part, 0, matching_chars);
- g_free (common_part);
- common_part = truncated;
- }
-
- matching_chars = g_utf8_strlen (common_part, -1);
- if (matching_chars < min_required_len) {
- g_free (common_part);
- return NULL;
- }
-
- return common_part;
+ GList *l;
+ char *common_part;
+ char *name;
+ char *truncated;
+ int matching_chars;
+
+ if (strs == NULL)
+ {
+ return NULL;
+ }
+
+ common_part = NULL;
+ for (l = strs; l != NULL; l = l->next)
+ {
+ name = l->data;
+ if (name == NULL)
+ {
+ g_free (common_part);
+ return NULL;
+ }
+
+ if (l->prev == NULL)
+ {
+ common_part = g_strdup (name);
+ continue;
+ }
+
+ matching_chars = get_common_prefix_length (common_part, name, min_required_len);
+
+ if (matching_chars == -1)
+ {
+ g_free (common_part);
+ return NULL;
+ }
+
+ truncated = g_utf8_substring (common_part, 0, matching_chars);
+ g_free (common_part);
+ common_part = truncated;
+ }
+
+ matching_chars = g_utf8_strlen (common_part, -1);
+ if (matching_chars < min_required_len)
+ {
+ g_free (common_part);
+ return NULL;
+ }
+
+ return common_part;
}
/**************** Custom printf ***********/
-typedef struct {
- const char *start;
- const char *end;
- GString *format;
- int arg_pos;
- int width_pos;
- int width_format_index;
- int precision_pos;
- int precision_format_index;
+typedef struct
+{
+ const char *start;
+ const char *end;
+ GString *format;
+ int arg_pos;
+ int width_pos;
+ int width_format_index;
+ int precision_pos;
+ int precision_format_index;
} ConversionInfo;
-enum {
- ARG_TYPE_INVALID,
- ARG_TYPE_INT,
- ARG_TYPE_LONG,
- ARG_TYPE_LONG_LONG,
- ARG_TYPE_SIZE,
- ARG_TYPE_LONG_DOUBLE,
- ARG_TYPE_DOUBLE,
- ARG_TYPE_POINTER
+enum
+{
+ ARG_TYPE_INVALID,
+ ARG_TYPE_INT,
+ ARG_TYPE_LONG,
+ ARG_TYPE_LONG_LONG,
+ ARG_TYPE_SIZE,
+ ARG_TYPE_LONG_DOUBLE,
+ ARG_TYPE_DOUBLE,
+ ARG_TYPE_POINTER
};
typedef int ArgType; /* An int, because custom are < 0 */
static const char *
-get_position (const char *format, int *i)
+get_position (const char *format,
+ int *i)
{
- const char *p;
-
- p = format;
-
- if (g_ascii_isdigit (*p)) {
- p++;
-
- while (g_ascii_isdigit (*p)) {
- p++;
- }
-
- if (*p == '$') {
- if (i != NULL) {
- *i = atoi (format) - 1;
- }
- return p + 1;
- }
- }
-
- return format;
+ const char *p;
+
+ p = format;
+
+ if (g_ascii_isdigit (*p))
+ {
+ p++;
+
+ while (g_ascii_isdigit (*p))
+ {
+ p++;
+ }
+
+ if (*p == '$')
+ {
+ if (i != NULL)
+ {
+ *i = atoi (format) - 1;
+ }
+ return p + 1;
+ }
+ }
+
+ return format;
}
static gboolean
is_flag (char c)
{
- return strchr ("#0- +'I", c) != NULL;
+ return strchr ("#0- +'I", c) != NULL;
}
static gboolean
is_length_modifier (char c)
{
- return strchr ("hlLjzt", c) != NULL;
+ return strchr ("hlLjzt", c) != NULL;
}
static ArgType
get_arg_type_from_format (EelPrintfHandler *custom_handlers,
- const char *format,
- int len)
+ const char *format,
+ int len)
{
- int i;
- char c;
-
- c = format[len-1];
-
- if (custom_handlers != NULL) {
- for (i = 0; custom_handlers[i].character != 0; i++) {
- if (custom_handlers[i].character == c) {
- return -(i + 1);
- }
- }
- }
-
- switch (c) {
- case 'd':
- case 'i':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- if (g_str_has_prefix (format, "ll")) {
- return ARG_TYPE_LONG_LONG;
- }
- if (g_str_has_prefix (format, "l")) {
- return ARG_TYPE_LONG;
- }
- if (g_str_has_prefix (format, "l")) {
- return ARG_TYPE_LONG;
- }
- if (g_str_has_prefix (format, "z")) {
- return ARG_TYPE_SIZE;
- }
- return ARG_TYPE_INT;
- case 'e':
- case 'E':
- case 'f':
- case 'F':
- case 'g':
- case 'G':
- case 'a':
- case 'A':
- if (g_str_has_prefix (format, "L")) {
- return ARG_TYPE_LONG_DOUBLE;
- }
- return ARG_TYPE_DOUBLE;
- case 'c':
- return ARG_TYPE_INT;
- case 's':
- case 'p':
- case 'n':
- return ARG_TYPE_POINTER;
- }
- return ARG_TYPE_INVALID;
+ int i;
+ char c;
+
+ c = format[len - 1];
+
+ if (custom_handlers != NULL)
+ {
+ for (i = 0; custom_handlers[i].character != 0; i++)
+ {
+ if (custom_handlers[i].character == c)
+ {
+ return -(i + 1);
+ }
+ }
+ }
+
+ switch (c)
+ {
+ case 'd':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ {
+ if (g_str_has_prefix (format, "ll"))
+ {
+ return ARG_TYPE_LONG_LONG;
+ }
+ if (g_str_has_prefix (format, "l"))
+ {
+ return ARG_TYPE_LONG;
+ }
+ if (g_str_has_prefix (format, "l"))
+ {
+ return ARG_TYPE_LONG;
+ }
+ if (g_str_has_prefix (format, "z"))
+ {
+ return ARG_TYPE_SIZE;
+ }
+ return ARG_TYPE_INT;
+ }
+
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'F':
+ case 'g':
+ case 'G':
+ case 'a':
+ case 'A':
+ {
+ if (g_str_has_prefix (format, "L"))
+ {
+ return ARG_TYPE_LONG_DOUBLE;
+ }
+ return ARG_TYPE_DOUBLE;
+ }
+
+ case 'c':
+ {
+ return ARG_TYPE_INT;
+ }
+
+ case 's':
+ case 'p':
+ case 'n':
+ return ARG_TYPE_POINTER;
+ }
+ return ARG_TYPE_INVALID;
}
static void
-skip_argv (va_list *va,
- ArgType type,
- EelPrintfHandler *custom_handlers)
+skip_argv (va_list *va,
+ ArgType type,
+ EelPrintfHandler *custom_handlers)
{
- if (type < 0) {
- custom_handlers[-type - 1].skip (va);
- return;
- }
-
- switch (type) {
- default:
- case ARG_TYPE_INVALID:
- return;
-
- case ARG_TYPE_INT:
- (void) va_arg (*va, int);
- break;
- case ARG_TYPE_LONG:
- (void) va_arg (*va, long int);
- break;
- case ARG_TYPE_LONG_LONG:
- (void) va_arg (*va, long long int);
- break;
- case ARG_TYPE_SIZE:
- (void) va_arg (*va, gsize);
- break;
- case ARG_TYPE_LONG_DOUBLE:
- (void) va_arg (*va, long double);
- break;
- case ARG_TYPE_DOUBLE:
- (void) va_arg (*va, double);
- break;
- case ARG_TYPE_POINTER:
- (void) va_arg (*va, void *);
- break;
- }
+ if (type < 0)
+ {
+ custom_handlers[-type - 1].skip (va);
+ return;
+ }
+
+ switch (type)
+ {
+ default:
+ case ARG_TYPE_INVALID:
+ {
+ return;
+ }
+
+ case ARG_TYPE_INT:
+ {
+ (void) va_arg (*va, int);
+ }
+ break;
+
+ case ARG_TYPE_LONG:
+ {
+ (void) va_arg (*va, long int);
+ }
+ break;
+
+ case ARG_TYPE_LONG_LONG:
+ {
+ (void) va_arg (*va, long long int);
+ }
+ break;
+
+ case ARG_TYPE_SIZE:
+ {
+ (void) va_arg (*va, gsize);
+ }
+ break;
+
+ case ARG_TYPE_LONG_DOUBLE:
+ {
+ (void) va_arg (*va, long double);
+ }
+ break;
+
+ case ARG_TYPE_DOUBLE:
+ {
+ (void) va_arg (*va, double);
+ }
+ break;
+
+ case ARG_TYPE_POINTER:
+ {
+ (void) va_arg (*va, void *);
+ }
+ break;
+ }
}
static void
-skip_to_arg (va_list *va,
- ArgType *types,
- EelPrintfHandler *custom_handlers,
- int n)
+skip_to_arg (va_list *va,
+ ArgType *types,
+ EelPrintfHandler *custom_handlers,
+ int n)
{
- int i;
- for (i = 0; i < n; i++) {
- skip_argv (va, types[i], custom_handlers);
- }
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ skip_argv (va, types[i], custom_handlers);
+ }
}
char *
eel_strdup_vprintf_with_custom (EelPrintfHandler *custom,
- const char *format,
- va_list va_orig)
+ const char *format,
+ va_list va_orig)
{
- va_list va;
- const char *p;
- int num_args, i, j;
- ArgType *args;
- ArgType type;
- ConversionInfo *conversions;
- GString *f, *str;
- const char *flags, *width, *prec, *mod, *pos;
- char *s;
-
- num_args = 0;
- for (p = format; *p != 0; p++) {
- if (*p == '%') {
- p++;
- if (*p != '%') {
- num_args++;
- }
- }
- }
-
- args = g_new0 (ArgType, num_args * 3 + 1);
- conversions = g_new0 (ConversionInfo, num_args);
-
- /* i indexes conversions, j indexes args */
- i = 0; j = 0;
- p = format;
- while (*p != 0) {
- if (*p != '%') {
- p++;
- continue;
- }
- p++;
- if (*p == '%') {
- p++;
- continue;
- }
-
- /* We got a real conversion: */
- f = g_string_new ("%");
- conversions[i].start = p - 1;
-
- /* First comes the positional arg */
-
- pos = p;
- p = get_position (p, NULL);
-
- /* Then flags */
- flags = p;
- while (is_flag (*p)) {
- p++;
- }
- g_string_append_len (f, flags, p - flags);
-
- /* Field width */
-
- if (*p == '*') {
- p++;
- p = get_position (p, &j);
- args[j] = ARG_TYPE_INT;
- conversions[i].width_pos = j++;
- conversions[i].width_format_index = f->len;
- } else {
- conversions[i].width_pos = -1;
- conversions[i].width_format_index = -1;
- width = p;
- while (g_ascii_isdigit (*p)) {
- p++;
- }
- g_string_append_len (f, width, p - width);
- }
-
- /* Precision */
- conversions[i].precision_pos = -1;
- conversions[i].precision_format_index = -1;
- if (*p == '.') {
- g_string_append_c (f, '.');
- p++;
-
- if (*p == '*') {
- p++;
- p = get_position (p, &j);
- args[j] = ARG_TYPE_INT;
- conversions[i].precision_pos = j++;
- conversions[i].precision_format_index = f->len;
- } else {
- prec = p;
- while (g_ascii_isdigit (*p) || *p == '-') {
- p++;
- }
- g_string_append_len (f, prec, p - prec);
- }
- }
-
- /* length modifier */
-
- mod = p;
-
- while (is_length_modifier (*p)) {
- p++;
- }
-
- /* conversion specifier */
- if (*p != 0)
- p++;
-
- g_string_append_len (f, mod, p - mod);
-
- get_position (pos, &j);
- args[j] = get_arg_type_from_format (custom, mod, p - mod);
- conversions[i].arg_pos = j++;
- conversions[i].format = f;
- conversions[i].end = p;
-
- i++;
- }
-
- g_assert (i == num_args);
-
- str = g_string_new ("");
-
- p = format;
- for (i = 0; i < num_args; i++) {
- g_string_append_len (str, p, conversions[i].start - p);
- p = conversions[i].end;
-
- if (conversions[i].precision_pos != -1) {
- char *val;
-
- G_VA_COPY(va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].precision_pos);
- val = g_strdup_vprintf ("%d", va);
- va_end (va);
-
- g_string_insert (conversions[i].format,
- conversions[i].precision_format_index,
- val);
-
- g_free (val);
- }
-
- if (conversions[i].width_pos != -1) {
- char *val;
-
- G_VA_COPY(va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].width_pos);
- val = g_strdup_vprintf ("%d", va);
- va_end (va);
-
- g_string_insert (conversions[i].format,
- conversions[i].width_format_index,
- val);
-
- g_free (val);
- }
-
- G_VA_COPY(va, va_orig);
- skip_to_arg (&va, args, custom, conversions[i].arg_pos);
- type = args[conversions[i].arg_pos];
- if (type < 0) {
- s = custom[-type - 1].to_string (conversions[i].format->str, va);
- g_string_append (str, s);
- g_free (s);
- } else{
- g_string_append_vprintf (str, conversions[i].format->str, va);
- }
- va_end (va);
-
- g_string_free (conversions[i].format, TRUE);
- }
- g_string_append (str, p);
-
- g_free (args);
- g_free (conversions);
-
- return g_string_free (str, FALSE);
+ va_list va;
+ const char *p;
+ int num_args, i, j;
+ ArgType *args;
+ ArgType type;
+ ConversionInfo *conversions;
+ GString *f, *str;
+ const char *flags, *width, *prec, *mod, *pos;
+ char *s;
+
+ num_args = 0;
+ for (p = format; *p != 0; p++)
+ {
+ if (*p == '%')
+ {
+ p++;
+ if (*p != '%')
+ {
+ num_args++;
+ }
+ }
+ }
+
+ args = g_new0 (ArgType, num_args * 3 + 1);
+ conversions = g_new0 (ConversionInfo, num_args);
+
+ /* i indexes conversions, j indexes args */
+ i = 0;
+ j = 0;
+ p = format;
+ while (*p != 0)
+ {
+ if (*p != '%')
+ {
+ p++;
+ continue;
+ }
+ p++;
+ if (*p == '%')
+ {
+ p++;
+ continue;
+ }
+
+ /* We got a real conversion: */
+ f = g_string_new ("%");
+ conversions[i].start = p - 1;
+
+ /* First comes the positional arg */
+
+ pos = p;
+ p = get_position (p, NULL);
+
+ /* Then flags */
+ flags = p;
+ while (is_flag (*p))
+ {
+ p++;
+ }
+ g_string_append_len (f, flags, p - flags);
+
+ /* Field width */
+
+ if (*p == '*')
+ {
+ p++;
+ p = get_position (p, &j);
+ args[j] = ARG_TYPE_INT;
+ conversions[i].width_pos = j++;
+ conversions[i].width_format_index = f->len;
+ }
+ else
+ {
+ conversions[i].width_pos = -1;
+ conversions[i].width_format_index = -1;
+ width = p;
+ while (g_ascii_isdigit (*p))
+ {
+ p++;
+ }
+ g_string_append_len (f, width, p - width);
+ }
+
+ /* Precision */
+ conversions[i].precision_pos = -1;
+ conversions[i].precision_format_index = -1;
+ if (*p == '.')
+ {
+ g_string_append_c (f, '.');
+ p++;
+
+ if (*p == '*')
+ {
+ p++;
+ p = get_position (p, &j);
+ args[j] = ARG_TYPE_INT;
+ conversions[i].precision_pos = j++;
+ conversions[i].precision_format_index = f->len;
+ }
+ else
+ {
+ prec = p;
+ while (g_ascii_isdigit (*p) || *p == '-')
+ {
+ p++;
+ }
+ g_string_append_len (f, prec, p - prec);
+ }
+ }
+
+ /* length modifier */
+
+ mod = p;
+
+ while (is_length_modifier (*p))
+ {
+ p++;
+ }
+
+ /* conversion specifier */
+ if (*p != 0)
+ {
+ p++;
+ }
+
+ g_string_append_len (f, mod, p - mod);
+
+ get_position (pos, &j);
+ args[j] = get_arg_type_from_format (custom, mod, p - mod);
+ conversions[i].arg_pos = j++;
+ conversions[i].format = f;
+ conversions[i].end = p;
+
+ i++;
+ }
+
+ g_assert (i == num_args);
+
+ str = g_string_new ("");
+
+ p = format;
+ for (i = 0; i < num_args; i++)
+ {
+ g_string_append_len (str, p, conversions[i].start - p);
+ p = conversions[i].end;
+
+ if (conversions[i].precision_pos != -1)
+ {
+ char *val;
+
+ G_VA_COPY (va, va_orig);
+ skip_to_arg (&va, args, custom, conversions[i].precision_pos);
+ val = g_strdup_vprintf ("%d", va);
+ va_end (va);
+
+ g_string_insert (conversions[i].format,
+ conversions[i].precision_format_index,
+ val);
+
+ g_free (val);
+ }
+
+ if (conversions[i].width_pos != -1)
+ {
+ char *val;
+
+ G_VA_COPY (va, va_orig);
+ skip_to_arg (&va, args, custom, conversions[i].width_pos);
+ val = g_strdup_vprintf ("%d", va);
+ va_end (va);
+
+ g_string_insert (conversions[i].format,
+ conversions[i].width_format_index,
+ val);
+
+ g_free (val);
+ }
+
+ G_VA_COPY (va, va_orig);
+ skip_to_arg (&va, args, custom, conversions[i].arg_pos);
+ type = args[conversions[i].arg_pos];
+ if (type < 0)
+ {
+ s = custom[-type - 1].to_string (conversions[i].format->str, va);
+ g_string_append (str, s);
+ g_free (s);
+ }
+ else
+ {
+ g_string_append_vprintf (str, conversions[i].format->str, va);
+ }
+ va_end (va);
+
+ g_string_free (conversions[i].format, TRUE);
+ }
+ g_string_append (str, p);
+
+ g_free (args);
+ g_free (conversions);
+
+ return g_string_free (str, FALSE);
}
char *
eel_strdup_printf_with_custom (EelPrintfHandler *handlers,
- const char *format,
- ...)
+ const char *format,
+ ...)
{
- va_list va;
- char *res;
-
- va_start (va, format);
- res = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
-
- return res;
+ va_list va;
+ char *res;
+
+ va_start (va, format);
+ res = eel_strdup_vprintf_with_custom (handlers, format, va);
+ va_end (va);
+
+ return res;
}
/*********** refcounted strings ****************/
@@ -713,249 +824,269 @@ G_LOCK_DEFINE_STATIC (unique_ref_strs);
static GHashTable *unique_ref_strs = NULL;
static eel_ref_str
-eel_ref_str_new_internal (const char *string, int start_count)
+eel_ref_str_new_internal (const char *string,
+ int start_count)
{
- char *res;
- volatile gint *count;
- gsize len;
-
- len = strlen (string);
- res = g_malloc (sizeof (gint) + len + 1);
- count = (volatile gint *)res;
- *count = start_count;
- res += sizeof(gint);
- memcpy (res, string, len + 1);
- return res;
+ char *res;
+ volatile gint *count;
+ gsize len;
+
+ len = strlen (string);
+ res = g_malloc (sizeof (gint) + len + 1);
+ count = (volatile gint *) res;
+ *count = start_count;
+ res += sizeof (gint);
+ memcpy (res, string, len + 1);
+ return res;
}
eel_ref_str
eel_ref_str_new (const char *string)
{
- if (string == NULL) {
- return NULL;
- }
-
- return eel_ref_str_new_internal (string, 1);
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ return eel_ref_str_new_internal (string, 1);
}
eel_ref_str
eel_ref_str_get_unique (const char *string)
{
- eel_ref_str res;
-
- if (string == NULL) {
- return NULL;
- }
-
- G_LOCK (unique_ref_strs);
- if (unique_ref_strs == NULL) {
- unique_ref_strs =
- g_hash_table_new (g_str_hash, g_str_equal);
- }
-
- res = g_hash_table_lookup (unique_ref_strs, string);
- if (res != NULL) {
- eel_ref_str_ref (res);
- } else {
- res = eel_ref_str_new_internal (string, 0x80000001);
- g_hash_table_insert (unique_ref_strs, res, res);
- }
-
- G_UNLOCK (unique_ref_strs);
-
- return res;
+ eel_ref_str res;
+
+ if (string == NULL)
+ {
+ return NULL;
+ }
+
+ G_LOCK (unique_ref_strs);
+ if (unique_ref_strs == NULL)
+ {
+ unique_ref_strs =
+ g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ res = g_hash_table_lookup (unique_ref_strs, string);
+ if (res != NULL)
+ {
+ eel_ref_str_ref (res);
+ }
+ else
+ {
+ res = eel_ref_str_new_internal (string, 0x80000001);
+ g_hash_table_insert (unique_ref_strs, res, res);
+ }
+
+ G_UNLOCK (unique_ref_strs);
+
+ return res;
}
eel_ref_str
eel_ref_str_ref (eel_ref_str str)
{
- volatile gint *count;
+ volatile gint *count;
- count = (volatile gint *)((char *)str - sizeof (gint));
- g_atomic_int_add (count, 1);
+ count = (volatile gint *) ((char *) str - sizeof (gint));
+ g_atomic_int_add (count, 1);
- return str;
+ return str;
}
void
eel_ref_str_unref (eel_ref_str str)
{
- volatile gint *count;
- gint old_ref;
-
- if (str == NULL)
- return;
-
- count = (volatile gint *)((char *)str - sizeof (gint));
-
- retry_atomic_decrement:
- old_ref = g_atomic_int_get (count);
- if (old_ref == 1) {
- g_free ((char *)count);
- } else if (old_ref == 0x80000001) {
- G_LOCK (unique_ref_strs);
- /* Need to recheck after taking lock to avoid races with _get_unique() */
- if (g_atomic_int_add (count, -1) == 0x80000001) {
- g_hash_table_remove (unique_ref_strs, (char *)str);
- g_free ((char *)count);
- }
- G_UNLOCK (unique_ref_strs);
- } else if (!g_atomic_int_compare_and_exchange (count,
- old_ref, old_ref - 1)) {
- goto retry_atomic_decrement;
- }
+ volatile gint *count;
+ gint old_ref;
+
+ if (str == NULL)
+ {
+ return;
+ }
+
+ count = (volatile gint *) ((char *) str - sizeof (gint));
+
+retry_atomic_decrement:
+ old_ref = g_atomic_int_get (count);
+ if (old_ref == 1)
+ {
+ g_free ((char *) count);
+ }
+ else if (old_ref == 0x80000001)
+ {
+ G_LOCK (unique_ref_strs);
+ /* Need to recheck after taking lock to avoid races with _get_unique() */
+ if (g_atomic_int_add (count, -1) == 0x80000001)
+ {
+ g_hash_table_remove (unique_ref_strs, (char *) str);
+ g_free ((char *) count);
+ }
+ G_UNLOCK (unique_ref_strs);
+ }
+ else if (!g_atomic_int_compare_and_exchange (count,
+ old_ref, old_ref - 1))
+ {
+ goto retry_atomic_decrement;
+ }
}
#if !defined (EEL_OMIT_SELF_CHECK)
static void
-verify_printf (const char *format, ...)
+verify_printf (const char *format,
+ ...)
{
- va_list va;
- char *orig, *new;
-
- va_start (va, format);
- orig = g_strdup_vprintf (format, va);
- va_end (va);
-
- va_start (va, format);
- new = eel_strdup_vprintf_with_custom (NULL, format, va);
- va_end (va);
-
- EEL_CHECK_STRING_RESULT (new, orig);
-
- g_free (orig);
+ va_list va;
+ char *orig, *new;
+
+ va_start (va, format);
+ orig = g_strdup_vprintf (format, va);
+ va_end (va);
+
+ va_start (va, format);
+ new = eel_strdup_vprintf_with_custom (NULL, format, va);
+ va_end (va);
+
+ EEL_CHECK_STRING_RESULT (new, orig);
+
+ g_free (orig);
}
static char *
-custom1_to_string (char *format, va_list va)
+custom1_to_string (char *format,
+ va_list va)
{
- int i;
-
- i = va_arg (va, int);
-
- return g_strdup_printf ("c1-%d-", i);
+ int i;
+
+ i = va_arg (va, int);
+
+ return g_strdup_printf ("c1-%d-", i);
}
static void
custom1_skip (va_list *va)
{
- (void) va_arg (*va, int);
+ (void) va_arg (*va, int);
}
static char *
-custom2_to_string (char *format, va_list va)
+custom2_to_string (char *format,
+ va_list va)
{
- char *s;
-
- s = va_arg (va, char *);
-
- return g_strdup_printf ("c2-%s-", s);
+ char *s;
+
+ s = va_arg (va, char *);
+
+ return g_strdup_printf ("c2-%s-", s);
}
static void
custom2_skip (va_list *va)
{
- (void) va_arg (*va, char *);
+ (void) va_arg (*va, char *);
}
-static EelPrintfHandler handlers[] = {
- { 'N', custom1_to_string, custom1_skip },
- { 'Y', custom2_to_string, custom2_skip },
- { 0 }
+static EelPrintfHandler handlers[] =
+{
+ { 'N', custom1_to_string, custom1_skip },
+ { 'Y', custom2_to_string, custom2_skip },
+ { 0 }
};
static void
-verify_custom (const char *orig, const char *format, ...)
+verify_custom (const char *orig,
+ const char *format,
+ ...)
{
- char *new;
- va_list va;
-
- va_start (va, format);
- new = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
-
- EEL_CHECK_STRING_RESULT (new, orig);
+ char *new;
+ va_list va;
+
+ va_start (va, format);
+ new = eel_strdup_vprintf_with_custom (handlers, format, va);
+ va_end (va);
+
+ EEL_CHECK_STRING_RESULT (new, orig);
}
void
eel_self_check_string (void)
{
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores (NULL), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores (""), "");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_"), "__");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo"), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar"), "foo__bar");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar_2"), "foo__bar__2");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_foo"), "__foo");
- EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_"), "foo__");
-
- EEL_CHECK_STRING_RESULT (eel_str_capitalize (NULL), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_capitalize (""), "");
- EEL_CHECK_STRING_RESULT (eel_str_capitalize ("foo"), "Foo");
- EEL_CHECK_STRING_RESULT (eel_str_capitalize ("Foo"), "Foo");
-
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 0), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 1), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 3), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 4), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 5), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 6), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 7), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 0), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 1), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 2), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 3), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 4), "a_much_longer_foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 5), "a...o");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 6), "a...oo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 7), "a_...oo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 8), "a_...foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 9), "a_m...foo");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 8), "so...ven");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 8), "so...odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 9), "som...ven");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 9), "som...odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 10), "som...even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 10), "som..._odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 11), "some...even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 11), "some..._odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 12), "some..._even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 12), "some...g_odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 13), "somet..._even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 14), "something_even");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("ääääääääää", 5), "ä...ä");
- EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("あぃいぅうぇえぉ", 7), "あぃ...えぉ");
-
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after (NULL, "bar"), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("", "bar"), "");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo", "bar"), "foo");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar", "bar"), "foo ");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar xxx", "bar"), "foo ");
- EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("bar", "bar"), "");
-
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", NULL), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", "bar"), NULL);
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", NULL), "bar");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", ""), "");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", "bar"), "");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", ""), "bar");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("xxx", "x", "foo"), "foofoofoo");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("fff", "f", "foo"), "foofoofoo");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "foo", "f"), "fff");
- EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "f", ""), "oooooo");
-
- verify_printf ("%.*s", 2, "foo");
- verify_printf ("%*.*s", 2, 4, "foo");
- verify_printf ("before %5$*1$.*2$s between %6$*3$.*4$d after",
- 4, 5, 6, 7, "foo", G_PI);
- verify_custom ("c1-42- c2-foo-","%N %Y", 42 ,"foo");
- verify_custom ("c1-42- bar c2-foo-","%N %s %Y", 42, "bar" ,"foo");
- verify_custom ("c1-42- bar c2-foo-","%3$N %2$s %1$Y","foo", "bar", 42);
-
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores (NULL), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores (""), "");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_"), "__");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo"), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar"), "foo__bar");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_bar_2"), "foo__bar__2");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("_foo"), "__foo");
+ EEL_CHECK_STRING_RESULT (eel_str_double_underscores ("foo_"), "foo__");
+
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize (NULL), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize (""), "");
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize ("foo"), "Foo");
+ EEL_CHECK_STRING_RESULT (eel_str_capitalize ("Foo"), "Foo");
+
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 0), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 1), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 3), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 4), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 5), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 6), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("foo", 7), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 0), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 1), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 2), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 3), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 4), "a_much_longer_foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 5), "a...o");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 6), "a...oo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 7), "a_...oo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 8), "a_...foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("a_much_longer_foo", 9), "a_m...foo");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 8), "so...ven");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 8), "so...odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 9), "som...ven");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 9), "som...odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 10), "som...even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 10), "som..._odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 11), "some...even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 11), "some..._odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 12), "some..._even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 12), "some...g_odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 13), "somet..._even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_even", 14), "something_even");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("something_odd", 13), "something_odd");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("ääääääääää", 5), "ä...ä");
+ EEL_CHECK_STRING_RESULT (eel_str_middle_truncate ("あぃいぅうぇえぉ", 7), "あぃ...えぉ");
+
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after (NULL, "bar"), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("", "bar"), "");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo", "bar"), "foo");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar", "bar"), "foo ");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("foo bar xxx", "bar"), "foo ");
+ EEL_CHECK_STRING_RESULT (eel_str_strip_substring_and_after ("bar", "bar"), "");
+
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", NULL), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring (NULL, "foo", "bar"), NULL);
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", NULL), "bar");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", ""), "");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("", "foo", "bar"), "");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("bar", "foo", ""), "bar");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("xxx", "x", "foo"), "foofoofoo");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("fff", "f", "foo"), "foofoofoo");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "foo", "f"), "fff");
+ EEL_CHECK_STRING_RESULT (eel_str_replace_substring ("foofoofoo", "f", ""), "oooooo");
+
+ verify_printf ("%.*s", 2, "foo");
+ verify_printf ("%*.*s", 2, 4, "foo");
+ verify_printf ("before %5$*1$.*2$s between %6$*3$.*4$d after",
+ 4, 5, 6, 7, "foo", G_PI);
+ verify_custom ("c1-42- c2-foo-", "%N %Y", 42, "foo");
+ verify_custom ("c1-42- bar c2-foo-", "%N %s %Y", 42, "bar", "foo");
+ verify_custom ("c1-42- bar c2-foo-", "%3$N %2$s %1$Y", "foo", "bar", 42);
}
#endif /* !EEL_OMIT_SELF_CHECK */
diff --git a/eel/eel-vfs-extensions.c b/eel/eel-vfs-extensions.c
index 5dd6225c4..9b5b24aa4 100644
--- a/eel/eel-vfs-extensions.c
+++ b/eel/eel-vfs-extensions.c
@@ -1,28 +1,27 @@
-
-/* eel-vfs-extensions.c - gnome-vfs extensions. Its likely some of these will
- be part of gnome-vfs in the future.
-
- Copyright (C) 1999, 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@eazel.com>
- Pavel Cisler <pavel@eazel.com>
- Mike Fleming <mfleming@eazel.com>
- John Sullivan <sullivan@eazel.com>
-*/
+/* eel-vfs-extensions.c - gnome-vfs extensions. Its likely some of these will
+ * be part of gnome-vfs in the future.
+ *
+ * Copyright (C) 1999, 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@eazel.com>
+ * Pavel Cisler <pavel@eazel.com>
+ * Mike Fleming <mfleming@eazel.com>
+ * John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
#include "eel-vfs-extensions.h"
@@ -41,138 +40,150 @@
gboolean
eel_uri_is_trash (const char *uri)
{
- return g_str_has_prefix (uri, "trash:");
+ return g_str_has_prefix (uri, "trash:");
}
gboolean
eel_uri_is_recent (const char *uri)
{
- return g_str_has_prefix (uri, "recent:");
+ return g_str_has_prefix (uri, "recent:");
}
gboolean
eel_uri_is_search (const char *uri)
{
- return g_str_has_prefix (uri, EEL_SEARCH_URI);
+ return g_str_has_prefix (uri, EEL_SEARCH_URI);
}
gboolean
eel_uri_is_desktop (const char *uri)
{
- return g_str_has_prefix (uri, EEL_DESKTOP_URI);
+ return g_str_has_prefix (uri, EEL_DESKTOP_URI);
}
char *
eel_make_valid_utf8 (const char *name)
{
- GString *string;
- const char *remainder, *invalid;
- int remaining_bytes, valid_bytes;
-
- string = NULL;
- remainder = name;
- remaining_bytes = strlen (name);
-
- while (remaining_bytes != 0) {
- if (g_utf8_validate (remainder, remaining_bytes, &invalid)) {
- break;
- }
- valid_bytes = invalid - remainder;
-
- if (string == NULL) {
- string = g_string_sized_new (remaining_bytes);
- }
- g_string_append_len (string, remainder, valid_bytes);
- g_string_append_c (string, '?');
-
- remaining_bytes -= valid_bytes + 1;
- remainder = invalid + 1;
- }
-
- if (string == NULL) {
- return g_strdup (name);
- }
-
- g_string_append (string, remainder);
- g_string_append (string, _(" (invalid Unicode)"));
- g_assert (g_utf8_validate (string->str, -1, NULL));
-
- return g_string_free (string, FALSE);
+ GString *string;
+ const char *remainder, *invalid;
+ int remaining_bytes, valid_bytes;
+
+ string = NULL;
+ remainder = name;
+ remaining_bytes = strlen (name);
+
+ while (remaining_bytes != 0)
+ {
+ if (g_utf8_validate (remainder, remaining_bytes, &invalid))
+ {
+ break;
+ }
+ valid_bytes = invalid - remainder;
+
+ if (string == NULL)
+ {
+ string = g_string_sized_new (remaining_bytes);
+ }
+ g_string_append_len (string, remainder, valid_bytes);
+ g_string_append_c (string, '?');
+
+ remaining_bytes -= valid_bytes + 1;
+ remainder = invalid + 1;
+ }
+
+ if (string == NULL)
+ {
+ return g_strdup (name);
+ }
+
+ g_string_append (string, remainder);
+ g_string_append (string, _(" (invalid Unicode)"));
+ g_assert (g_utf8_validate (string->str, -1, NULL));
+
+ return g_string_free (string, FALSE);
}
char *
eel_filename_get_extension_offset (const char *filename)
{
- char *end, *end2;
- const char *start;
-
- if (filename == NULL || filename[0] == '\0') {
- return NULL;
- }
-
- /* basename must have at least one char */
- start = filename + 1;
-
- end = strrchr (start, '.');
- if (end == NULL || end[1] == '\0') {
- return NULL;
- }
-
- if (end != start) {
- if (strcmp (end, ".gz") == 0 ||
- strcmp (end, ".bz2") == 0 ||
- strcmp (end, ".sit") == 0 ||
- strcmp (end, ".Z") == 0) {
- end2 = end - 1;
- while (end2 > start &&
- *end2 != '.') {
- end2--;
- }
- if (end2 != start) {
- end = end2;
- }
- }
- }
-
- return end;
+ char *end, *end2;
+ const char *start;
+
+ if (filename == NULL || filename[0] == '\0')
+ {
+ return NULL;
+ }
+
+ /* basename must have at least one char */
+ start = filename + 1;
+
+ end = strrchr (start, '.');
+ if (end == NULL || end[1] == '\0')
+ {
+ return NULL;
+ }
+
+ if (end != start)
+ {
+ if (strcmp (end, ".gz") == 0 ||
+ strcmp (end, ".bz2") == 0 ||
+ strcmp (end, ".sit") == 0 ||
+ strcmp (end, ".Z") == 0)
+ {
+ end2 = end - 1;
+ while (end2 > start &&
+ *end2 != '.')
+ {
+ end2--;
+ }
+ if (end2 != start)
+ {
+ end = end2;
+ }
+ }
+ }
+
+ return end;
}
char *
-eel_filename_strip_extension (const char * filename_with_extension)
+eel_filename_strip_extension (const char *filename_with_extension)
{
- char *filename, *end;
+ char *filename, *end;
- if (filename_with_extension == NULL) {
- return NULL;
- }
+ if (filename_with_extension == NULL)
+ {
+ return NULL;
+ }
- filename = g_strdup (filename_with_extension);
- end = eel_filename_get_extension_offset (filename);
+ filename = g_strdup (filename_with_extension);
+ end = eel_filename_get_extension_offset (filename);
- if (end && end != filename) {
- *end = '\0';
- }
+ if (end && end != filename)
+ {
+ *end = '\0';
+ }
- return filename;
+ return filename;
}
void
-eel_filename_get_rename_region (const char *filename,
- int *start_offset,
- int *end_offset)
+eel_filename_get_rename_region (const char *filename,
+ int *start_offset,
+ int *end_offset)
{
- char *filename_without_extension;
+ char *filename_without_extension;
- g_return_if_fail (start_offset != NULL);
- g_return_if_fail (end_offset != NULL);
+ g_return_if_fail (start_offset != NULL);
+ g_return_if_fail (end_offset != NULL);
- *start_offset = 0;
- *end_offset = 0;
+ *start_offset = 0;
+ *end_offset = 0;
- g_return_if_fail (filename != NULL);
+ g_return_if_fail (filename != NULL);
- filename_without_extension = eel_filename_strip_extension (filename);
- *end_offset = g_utf8_strlen (filename_without_extension, -1);
+ filename_without_extension = eel_filename_strip_extension (filename);
+ *end_offset = g_utf8_strlen (filename_without_extension, -1);
- g_free (filename_without_extension);
+ g_free (filename_without_extension);
}
diff --git a/libnautilus-extension/nautilus-column-provider.c b/libnautilus-extension/nautilus-column-provider.c
index 7732592da..22519a635 100644
--- a/libnautilus-extension/nautilus-column-provider.c
+++ b/libnautilus-extension/nautilus-column-provider.c
@@ -1,5 +1,5 @@
/*
- * nautilus-column-provider.c - Interface for Nautilus extensions
+ * nautilus-column-provider.c - Interface for Nautilus extensions
* that provide column specifications.
*
* Copyright (C) 2003 Novell, Inc.
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -41,31 +41,33 @@ nautilus_column_provider_base_init (gpointer g_class)
{
}
-GType
+GType
nautilus_column_provider_get_type (void)
{
- static GType type = 0;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusColumnProviderIface),
+ nautilus_column_provider_base_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusColumnProviderIface),
- nautilus_column_provider_base_init,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- type = g_type_register_static (G_TYPE_INTERFACE,
- "NautilusColumnProvider",
- &info, 0);
- g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
- }
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "NautilusColumnProvider",
+ &info, 0);
+ g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+ }
- return type;
+ return type;
}
/**
@@ -77,11 +79,9 @@ nautilus_column_provider_get_type (void)
GList *
nautilus_column_provider_get_columns (NautilusColumnProvider *provider)
{
- g_return_val_if_fail (NAUTILUS_IS_COLUMN_PROVIDER (provider), NULL);
- g_return_val_if_fail (NAUTILUS_COLUMN_PROVIDER_GET_IFACE (provider)->get_columns != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_COLUMN_PROVIDER (provider), NULL);
+ g_return_val_if_fail (NAUTILUS_COLUMN_PROVIDER_GET_IFACE (provider)->get_columns != NULL, NULL);
- return NAUTILUS_COLUMN_PROVIDER_GET_IFACE (provider)->get_columns
- (provider);
+ return NAUTILUS_COLUMN_PROVIDER_GET_IFACE (provider)->get_columns
+ (provider);
}
-
-
diff --git a/libnautilus-extension/nautilus-column.c b/libnautilus-extension/nautilus-column.c
index 29e6149cd..fdf83204c 100644
--- a/libnautilus-extension/nautilus-column.c
+++ b/libnautilus-extension/nautilus-column.c
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -26,25 +26,27 @@
#include <gtk/gtk.h>
#include "nautilus-column.h"
-enum {
- PROP_0,
- PROP_NAME,
- PROP_ATTRIBUTE,
- PROP_ATTRIBUTE_Q,
- PROP_LABEL,
- PROP_DESCRIPTION,
- PROP_XALIGN,
- PROP_DEFAULT_SORT_ORDER,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_NAME,
+ PROP_ATTRIBUTE,
+ PROP_ATTRIBUTE_Q,
+ PROP_LABEL,
+ PROP_DESCRIPTION,
+ PROP_XALIGN,
+ PROP_DEFAULT_SORT_ORDER,
+ LAST_PROP
};
-struct _NautilusColumnDetails {
- char *name;
- GQuark attribute;
- char *label;
- char *description;
- float xalign;
- GtkSortType default_sort_order;
+struct _NautilusColumnDetails
+{
+ char *name;
+ GQuark attribute;
+ char *label;
+ char *description;
+ float xalign;
+ GtkSortType default_sort_order;
};
G_DEFINE_TYPE (NautilusColumn, nautilus_column, G_TYPE_OBJECT);
@@ -75,192 +77,236 @@ G_DEFINE_TYPE (NautilusColumn, nautilus_column, G_TYPE_OBJECT);
*/
NautilusColumn *
nautilus_column_new (const char *name,
- const char *attribute,
- const char *label,
- const char *description)
+ const char *attribute,
+ const char *label,
+ const char *description)
{
- NautilusColumn *column;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (attribute != NULL, NULL);
- g_return_val_if_fail (label != NULL, NULL);
- g_return_val_if_fail (description != NULL, NULL);
-
- column = g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", name,
- "attribute", attribute,
- "label", label,
- "description", description,
- NULL);
-
- return column;
+ NautilusColumn *column;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (attribute != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (description != NULL, NULL);
+
+ column = g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", name,
+ "attribute", attribute,
+ "label", label,
+ "description", description,
+ NULL);
+
+ return column;
}
static void
-nautilus_column_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_column_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusColumn *column;
-
- column = NAUTILUS_COLUMN (object);
-
- switch (param_id) {
- case PROP_NAME :
- g_value_set_string (value, column->details->name);
- break;
- case PROP_ATTRIBUTE :
- g_value_set_string (value, g_quark_to_string (column->details->attribute));
- break;
- case PROP_ATTRIBUTE_Q :
- g_value_set_uint (value, column->details->attribute);
- break;
- case PROP_LABEL :
- g_value_set_string (value, column->details->label);
- break;
- case PROP_DESCRIPTION :
- g_value_set_string (value, column->details->description);
- break;
- case PROP_XALIGN :
- g_value_set_float (value, column->details->xalign);
- break;
- case PROP_DEFAULT_SORT_ORDER :
- g_value_set_enum (value, column->details->default_sort_order);
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusColumn *column;
+
+ column = NAUTILUS_COLUMN (object);
+
+ switch (param_id)
+ {
+ case PROP_NAME:
+ {
+ g_value_set_string (value, column->details->name);
+ }
+ break;
+
+ case PROP_ATTRIBUTE:
+ {
+ g_value_set_string (value, g_quark_to_string (column->details->attribute));
+ }
+ break;
+
+ case PROP_ATTRIBUTE_Q:
+ {
+ g_value_set_uint (value, column->details->attribute);
+ }
+ break;
+
+ case PROP_LABEL:
+ {
+ g_value_set_string (value, column->details->label);
+ }
+ break;
+
+ case PROP_DESCRIPTION:
+ {
+ g_value_set_string (value, column->details->description);
+ }
+ break;
+
+ case PROP_XALIGN:
+ {
+ g_value_set_float (value, column->details->xalign);
+ }
+ break;
+
+ case PROP_DEFAULT_SORT_ORDER:
+ {
+ g_value_set_enum (value, column->details->default_sort_order);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_column_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_column_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusColumn *column;
-
- column = NAUTILUS_COLUMN (object);
-
- switch (param_id) {
- case PROP_NAME :
- g_free (column->details->name);
- column->details->name = g_strdup (g_value_get_string (value));
- g_object_notify (object, "name");
- break;
- case PROP_ATTRIBUTE :
- column->details->attribute = g_quark_from_string (g_value_get_string (value));
- g_object_notify (object, "attribute");
- g_object_notify (object, "attribute_q");
- break;
- case PROP_LABEL :
- g_free (column->details->label);
- column->details->label = g_strdup (g_value_get_string (value));
- g_object_notify (object, "label");
- break;
- case PROP_DESCRIPTION :
- g_free (column->details->description);
- column->details->description = g_strdup (g_value_get_string (value));
- g_object_notify (object, "description");
- break;
- case PROP_XALIGN :
- column->details->xalign = g_value_get_float (value);
- g_object_notify (object, "xalign");
- break;
- case PROP_DEFAULT_SORT_ORDER :
- column->details->default_sort_order = g_value_get_enum (value);
- g_object_notify (object, "default-sort-order");
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusColumn *column;
+
+ column = NAUTILUS_COLUMN (object);
+
+ switch (param_id)
+ {
+ case PROP_NAME:
+ {
+ g_free (column->details->name);
+ column->details->name = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "name");
+ }
+ break;
+
+ case PROP_ATTRIBUTE:
+ {
+ column->details->attribute = g_quark_from_string (g_value_get_string (value));
+ g_object_notify (object, "attribute");
+ g_object_notify (object, "attribute_q");
+ }
+ break;
+
+ case PROP_LABEL:
+ {
+ g_free (column->details->label);
+ column->details->label = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "label");
+ }
+ break;
+
+ case PROP_DESCRIPTION:
+ {
+ g_free (column->details->description);
+ column->details->description = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "description");
+ }
+ break;
+
+ case PROP_XALIGN:
+ {
+ column->details->xalign = g_value_get_float (value);
+ g_object_notify (object, "xalign");
+ }
+ break;
+
+ case PROP_DEFAULT_SORT_ORDER:
+ {
+ column->details->default_sort_order = g_value_get_enum (value);
+ g_object_notify (object, "default-sort-order");
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_column_finalize (GObject *object)
{
- NautilusColumn *column;
-
- column = NAUTILUS_COLUMN (object);
+ NautilusColumn *column;
+
+ column = NAUTILUS_COLUMN (object);
- g_free (column->details->name);
- g_free (column->details->label);
- g_free (column->details->description);
+ g_free (column->details->name);
+ g_free (column->details->label);
+ g_free (column->details->description);
- g_free (column->details);
+ g_free (column->details);
- G_OBJECT_CLASS (nautilus_column_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_column_parent_class)->finalize (object);
}
static void
nautilus_column_init (NautilusColumn *column)
{
- column->details = g_new0 (NautilusColumnDetails, 1);
- column->details->xalign = 0.0;
+ column->details = g_new0 (NautilusColumnDetails, 1);
+ column->details->xalign = 0.0;
}
static void
nautilus_column_class_init (NautilusColumnClass *class)
{
- G_OBJECT_CLASS (class)->finalize = nautilus_column_finalize;
- G_OBJECT_CLASS (class)->get_property = nautilus_column_get_property;
- G_OBJECT_CLASS (class)->set_property = nautilus_column_set_property;
-
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name of the column",
- NULL,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_ATTRIBUTE,
- g_param_spec_string ("attribute",
- "Attribute",
- "The attribute name to display",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_ATTRIBUTE_Q,
- g_param_spec_uint ("attribute_q",
- "Attribute quark",
- "The attribute name to display, in quark form",
- 0, G_MAXUINT, 0,
- G_PARAM_READABLE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_LABEL,
- g_param_spec_string ("label",
- "Label",
- "Label to display in the column",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_DESCRIPTION,
- g_param_spec_string ("description",
- "Description",
- "A user-visible description of the column",
- NULL,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_XALIGN,
- g_param_spec_float ("xalign",
- "xalign",
- "The x-alignment of the column",
- 0.0,
- 1.0,
- 0.0,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_DEFAULT_SORT_ORDER,
- g_param_spec_enum ("default-sort-order",
- "Default sort order",
- "Default sort order",
- GTK_TYPE_SORT_TYPE,
- GTK_SORT_ASCENDING,
- G_PARAM_READWRITE));
-}
+ G_OBJECT_CLASS (class)->finalize = nautilus_column_finalize;
+ G_OBJECT_CLASS (class)->get_property = nautilus_column_get_property;
+ G_OBJECT_CLASS (class)->set_property = nautilus_column_set_property;
+
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "Name of the column",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_ATTRIBUTE,
+ g_param_spec_string ("attribute",
+ "Attribute",
+ "The attribute name to display",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_ATTRIBUTE_Q,
+ g_param_spec_uint ("attribute_q",
+ "Attribute quark",
+ "The attribute name to display, in quark form",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READABLE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_LABEL,
+ g_param_spec_string ("label",
+ "Label",
+ "Label to display in the column",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_DESCRIPTION,
+ g_param_spec_string ("description",
+ "Description",
+ "A user-visible description of the column",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_XALIGN,
+ g_param_spec_float ("xalign",
+ "xalign",
+ "The x-alignment of the column",
+ 0.0,
+ 1.0,
+ 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_DEFAULT_SORT_ORDER,
+ g_param_spec_enum ("default-sort-order",
+ "Default sort order",
+ "Default sort order",
+ GTK_TYPE_SORT_TYPE,
+ GTK_SORT_ASCENDING,
+ G_PARAM_READWRITE));
+}
diff --git a/libnautilus-extension/nautilus-extension-types.c b/libnautilus-extension/nautilus-extension-types.c
index 31f3ec8ea..f61d5db11 100644
--- a/libnautilus-extension/nautilus-extension-types.c
+++ b/libnautilus-extension/nautilus-extension-types.c
@@ -1,6 +1,6 @@
/*
* nautilus-extension-types.c - Type definitions for Nautilus extensions
- *
+ *
* Copyright (C) 2003 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Dave Camp <dave@ximian.com>
- *
+ *
*/
#include <config.h>
@@ -27,30 +27,32 @@
GType
nautilus_operation_result_get_type (void)
{
- static GType type = 0;
- if (type == 0) {
- static const GEnumValue values[] = {
- {
- NAUTILUS_OPERATION_COMPLETE,
- "NAUTILUS_OPERATION_COMPLETE",
- "complete",
- },
- {
- NAUTILUS_OPERATION_FAILED,
- "NAUTILUS_OPERATION_FAILED",
- "failed",
- },
- {
- NAUTILUS_OPERATION_IN_PROGRESS,
- "NAUTILUS_OPERATION_IN_PROGRESS",
- "in_progress",
- },
- { 0, NULL, NULL }
- };
-
- type = g_enum_register_static ("NautilusOperationResult",
- values);
- }
+ static GType type = 0;
+ if (type == 0)
+ {
+ static const GEnumValue values[] =
+ {
+ {
+ NAUTILUS_OPERATION_COMPLETE,
+ "NAUTILUS_OPERATION_COMPLETE",
+ "complete",
+},
+ {
+ NAUTILUS_OPERATION_FAILED,
+ "NAUTILUS_OPERATION_FAILED",
+ "failed",
+},
+ {
+ NAUTILUS_OPERATION_IN_PROGRESS,
+ "NAUTILUS_OPERATION_IN_PROGRESS",
+ "in_progress",
+},
+ { 0, NULL, NULL }
+ };
+
+ type = g_enum_register_static ("NautilusOperationResult",
+ values);
+ }
- return type;
+ return type;
}
diff --git a/libnautilus-extension/nautilus-file-info.c b/libnautilus-extension/nautilus-file-info.c
index 329d5e5cb..2f2a46b93 100644
--- a/libnautilus-extension/nautilus-file-info.c
+++ b/libnautilus-extension/nautilus-file-info.c
@@ -1,5 +1,5 @@
/*
- * nautilus-file-info.c - Information about a file
+ * nautilus-file-info.c - Information about a file
*
* Copyright (C) 2003 Novell, Inc.
*
@@ -22,7 +22,7 @@
#include "nautilus-file-info.h"
#include "nautilus-extension-private.h"
-NautilusFileInfo *(*nautilus_file_info_getter) (GFile *location, gboolean create);
+NautilusFileInfo *(*nautilus_file_info_getter)(GFile * location, gboolean create);
/**
* SECTION:nautilus-file-info
@@ -44,15 +44,16 @@ NautilusFileInfo *(*nautilus_file_info_getter) (GFile *location, gboolean create
GList *
nautilus_file_info_list_copy (GList *files)
{
- GList *ret;
- GList *l;
-
- ret = g_list_copy (files);
- for (l = ret; l != NULL; l = l->next) {
- g_object_ref (G_OBJECT (l->data));
- }
-
- return ret;
+ GList *ret;
+ GList *l;
+
+ ret = g_list_copy (files);
+ for (l = ret; l != NULL; l = l->next)
+ {
+ g_object_ref (G_OBJECT (l->data));
+ }
+
+ return ret;
}
/**
@@ -61,16 +62,17 @@ nautilus_file_info_list_copy (GList *files)
* #nautilus_file_info_list_copy
*
*/
-void
+void
nautilus_file_info_list_free (GList *files)
{
- GList *l;
-
- for (l = files; l != NULL; l = l->next) {
- g_object_unref (G_OBJECT (l->data));
- }
-
- g_list_free (files);
+ GList *l;
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ g_object_unref (G_OBJECT (l->data));
+ }
+
+ g_list_free (files);
}
static void
@@ -78,58 +80,60 @@ nautilus_file_info_base_init (gpointer g_class)
{
}
-GType
+GType
nautilus_file_info_get_type (void)
{
- static GType type = 0;
-
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusFileInfoIface),
- nautilus_file_info_base_init,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- type = g_type_register_static (G_TYPE_INTERFACE,
- "NautilusFileInfo",
- &info, 0);
- g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
- }
-
- return type;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusFileInfoIface),
+ nautilus_file_info_base_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
+
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "NautilusFileInfo",
+ &info, 0);
+ g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+ }
+
+ return type;
}
gboolean
nautilus_file_info_is_gone (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->is_gone != NULL, FALSE);
-
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->is_gone (file);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->is_gone != NULL, FALSE);
+
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->is_gone (file);
}
GFileType
nautilus_file_info_get_file_type (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), G_FILE_TYPE_UNKNOWN);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_file_type != NULL, G_FILE_TYPE_UNKNOWN);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), G_FILE_TYPE_UNKNOWN);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_file_type != NULL, G_FILE_TYPE_UNKNOWN);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_file_type (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_file_type (file);
}
char *
nautilus_file_info_get_name (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_name != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_name != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_name (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_name (file);
}
/**
@@ -141,177 +145,177 @@ nautilus_file_info_get_name (NautilusFileInfo *file)
GFile *
nautilus_file_info_get_location (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_location != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_location != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_location (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_location (file);
}
char *
nautilus_file_info_get_uri (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri (file);
}
char *
nautilus_file_info_get_activation_uri (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_activation_uri != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_activation_uri != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_activation_uri (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_activation_uri (file);
}
/**
* nautilus_file_info_get_parent_location:
* @file: a #NautilusFileInfo
*
- * Returns: (allow-none) (transfer full): a #GFile for the parent location of @file,
+ * Returns: (allow-none) (transfer full): a #GFile for the parent location of @file,
* or %NULL if @file has no parent
*/
GFile *
nautilus_file_info_get_parent_location (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_location != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_location != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_location (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_location (file);
}
char *
nautilus_file_info_get_parent_uri (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_uri != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_uri != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_uri (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_uri (file);
}
/**
* nautilus_file_info_get_parent_info:
* @file: a #NautilusFileInfo
*
- * Returns: (allow-none) (transfer full): a #NautilusFileInfo for the parent of @file,
+ * Returns: (allow-none) (transfer full): a #NautilusFileInfo for the parent of @file,
* or %NULL if @file has no parent
*/
NautilusFileInfo *
nautilus_file_info_get_parent_info (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_info != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_info != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_info (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_parent_info (file);
}
/**
* nautilus_file_info_get_mount:
* @file: a #NautilusFileInfo
*
- * Returns: (allow-none) (transfer full): a #GMount for the mount of @file,
+ * Returns: (allow-none) (transfer full): a #GMount for the mount of @file,
* or %NULL if @file has no mount
*/
GMount *
nautilus_file_info_get_mount (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mount != NULL, NULL);
-
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mount (file);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mount != NULL, NULL);
+
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mount (file);
}
char *
nautilus_file_info_get_uri_scheme (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri_scheme != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri_scheme != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri_scheme (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_uri_scheme (file);
}
char *
nautilus_file_info_get_mime_type (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mime_type != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mime_type != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mime_type (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_mime_type (file);
}
gboolean
nautilus_file_info_is_mime_type (NautilusFileInfo *file,
- const char *mime_type)
+ const char *mime_type)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
- g_return_val_if_fail (mime_type != NULL, FALSE);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->is_mime_type != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
+ g_return_val_if_fail (mime_type != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->is_mime_type != NULL, FALSE);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->is_mime_type (file,
- mime_type);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->is_mime_type (file,
+ mime_type);
}
gboolean
nautilus_file_info_is_directory (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->is_directory != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->is_directory != NULL, FALSE);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->is_directory (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->is_directory (file);
}
gboolean
nautilus_file_info_can_write (NautilusFileInfo *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->can_write != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->can_write != NULL, FALSE);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->can_write (file);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->can_write (file);
}
void
nautilus_file_info_add_emblem (NautilusFileInfo *file,
- const char *emblem_name)
+ const char *emblem_name)
{
- g_return_if_fail (NAUTILUS_IS_FILE_INFO (file));
- g_return_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->add_emblem != NULL);
+ g_return_if_fail (NAUTILUS_IS_FILE_INFO (file));
+ g_return_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->add_emblem != NULL);
- NAUTILUS_FILE_INFO_GET_IFACE (file)->add_emblem (file, emblem_name);
+ NAUTILUS_FILE_INFO_GET_IFACE (file)->add_emblem (file, emblem_name);
}
char *
nautilus_file_info_get_string_attribute (NautilusFileInfo *file,
- const char *attribute_name)
+ const char *attribute_name)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
- g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_string_attribute != NULL, NULL);
- g_return_val_if_fail (attribute_name != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (file), NULL);
+ g_return_val_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->get_string_attribute != NULL, NULL);
+ g_return_val_if_fail (attribute_name != NULL, NULL);
- return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_string_attribute
- (file, attribute_name);
+ return NAUTILUS_FILE_INFO_GET_IFACE (file)->get_string_attribute
+ (file, attribute_name);
}
void
nautilus_file_info_add_string_attribute (NautilusFileInfo *file,
- const char *attribute_name,
- const char *value)
+ const char *attribute_name,
+ const char *value)
{
- g_return_if_fail (NAUTILUS_IS_FILE_INFO (file));
- g_return_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->add_string_attribute != NULL);
- g_return_if_fail (attribute_name != NULL);
- g_return_if_fail (value != NULL);
-
- NAUTILUS_FILE_INFO_GET_IFACE (file)->add_string_attribute
- (file, attribute_name, value);
+ g_return_if_fail (NAUTILUS_IS_FILE_INFO (file));
+ g_return_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->add_string_attribute != NULL);
+ g_return_if_fail (attribute_name != NULL);
+ g_return_if_fail (value != NULL);
+
+ NAUTILUS_FILE_INFO_GET_IFACE (file)->add_string_attribute
+ (file, attribute_name, value);
}
void
nautilus_file_info_invalidate_extension_info (NautilusFileInfo *file)
{
- g_return_if_fail (NAUTILUS_IS_FILE_INFO (file));
- g_return_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->invalidate_extension_info != NULL);
-
- NAUTILUS_FILE_INFO_GET_IFACE (file)->invalidate_extension_info (file);
+ g_return_if_fail (NAUTILUS_IS_FILE_INFO (file));
+ g_return_if_fail (NAUTILUS_FILE_INFO_GET_IFACE (file)->invalidate_extension_info != NULL);
+
+ NAUTILUS_FILE_INFO_GET_IFACE (file)->invalidate_extension_info (file);
}
/**
@@ -323,7 +327,7 @@ nautilus_file_info_invalidate_extension_info (NautilusFileInfo *file)
NautilusFileInfo *
nautilus_file_info_lookup (GFile *location)
{
- return nautilus_file_info_getter (location, FALSE);
+ return nautilus_file_info_getter (location, FALSE);
}
/**
@@ -335,7 +339,7 @@ nautilus_file_info_lookup (GFile *location)
NautilusFileInfo *
nautilus_file_info_create (GFile *location)
{
- return nautilus_file_info_getter (location, TRUE);
+ return nautilus_file_info_getter (location, TRUE);
}
/**
@@ -347,14 +351,14 @@ nautilus_file_info_create (GFile *location)
NautilusFileInfo *
nautilus_file_info_lookup_for_uri (const char *uri)
{
- GFile *location;
- NautilusFile *file;
+ GFile *location;
+ NautilusFile *file;
- location = g_file_new_for_uri (uri);
- file = nautilus_file_info_lookup (location);
- g_object_unref (location);
+ location = g_file_new_for_uri (uri);
+ file = nautilus_file_info_lookup (location);
+ g_object_unref (location);
- return file;
+ return file;
}
/**
@@ -366,12 +370,12 @@ nautilus_file_info_lookup_for_uri (const char *uri)
NautilusFileInfo *
nautilus_file_info_create_for_uri (const char *uri)
{
- GFile *location;
- NautilusFile *file;
+ GFile *location;
+ NautilusFile *file;
- location = g_file_new_for_uri (uri);
- file = nautilus_file_info_create (location);
- g_object_unref (location);
+ location = g_file_new_for_uri (uri);
+ file = nautilus_file_info_create (location);
+ g_object_unref (location);
- return file;
+ return file;
}
diff --git a/libnautilus-extension/nautilus-info-provider.c b/libnautilus-extension/nautilus-info-provider.c
index b2cbbbac0..359bf8e24 100644
--- a/libnautilus-extension/nautilus-info-provider.c
+++ b/libnautilus-extension/nautilus-info-provider.c
@@ -1,5 +1,5 @@
/*
- * nautilus-info-provider.c - Interface for Nautilus extensions that
+ * nautilus-info-provider.c - Interface for Nautilus extensions that
* provide info about files.
*
* Copyright (C) 2003 Novell, Inc.
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -43,89 +43,89 @@ nautilus_info_provider_base_init (gpointer g_class)
{
}
-GType
+GType
nautilus_info_provider_get_type (void)
{
- static GType type = 0;
-
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusInfoProviderIface),
- nautilus_info_provider_base_init,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- type = g_type_register_static (G_TYPE_INTERFACE,
- "NautilusInfoProvider",
- &info, 0);
- g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
- }
-
- return type;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusInfoProviderIface),
+ nautilus_info_provider_base_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
+
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "NautilusInfoProvider",
+ &info, 0);
+ g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+ }
+
+ return type;
}
-NautilusOperationResult
-nautilus_info_provider_update_file_info (NautilusInfoProvider *provider,
- NautilusFileInfo *file,
- GClosure *update_complete,
- NautilusOperationHandle **handle)
+NautilusOperationResult
+nautilus_info_provider_update_file_info (NautilusInfoProvider *provider,
+ NautilusFileInfo *file,
+ GClosure *update_complete,
+ NautilusOperationHandle **handle)
{
- g_return_val_if_fail (NAUTILUS_IS_INFO_PROVIDER (provider),
- NAUTILUS_OPERATION_FAILED);
- g_return_val_if_fail (NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->update_file_info != NULL,
- NAUTILUS_OPERATION_FAILED);
- g_return_val_if_fail (update_complete != NULL,
- NAUTILUS_OPERATION_FAILED);
- g_return_val_if_fail (handle != NULL, NAUTILUS_OPERATION_FAILED);
-
- return NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->update_file_info
- (provider, file, update_complete, handle);
+ g_return_val_if_fail (NAUTILUS_IS_INFO_PROVIDER (provider),
+ NAUTILUS_OPERATION_FAILED);
+ g_return_val_if_fail (NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->update_file_info != NULL,
+ NAUTILUS_OPERATION_FAILED);
+ g_return_val_if_fail (update_complete != NULL,
+ NAUTILUS_OPERATION_FAILED);
+ g_return_val_if_fail (handle != NULL, NAUTILUS_OPERATION_FAILED);
+
+ return NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->update_file_info
+ (provider, file, update_complete, handle);
}
void
-nautilus_info_provider_cancel_update (NautilusInfoProvider *provider,
- NautilusOperationHandle *handle)
+nautilus_info_provider_cancel_update (NautilusInfoProvider *provider,
+ NautilusOperationHandle *handle)
{
- g_return_if_fail (NAUTILUS_IS_INFO_PROVIDER (provider));
- g_return_if_fail (NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->cancel_update != NULL);
- g_return_if_fail (NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->cancel_update != NULL);
- g_return_if_fail (handle != NULL);
+ g_return_if_fail (NAUTILUS_IS_INFO_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->cancel_update != NULL);
+ g_return_if_fail (NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->cancel_update != NULL);
+ g_return_if_fail (handle != NULL);
- NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->cancel_update (provider,
- handle);
+ NAUTILUS_INFO_PROVIDER_GET_IFACE (provider)->cancel_update (provider,
+ handle);
}
void
-nautilus_info_provider_update_complete_invoke (GClosure *update_complete,
- NautilusInfoProvider *provider,
- NautilusOperationHandle *handle,
- NautilusOperationResult result)
+nautilus_info_provider_update_complete_invoke (GClosure *update_complete,
+ NautilusInfoProvider *provider,
+ NautilusOperationHandle *handle,
+ NautilusOperationResult result)
{
- GValue args[3] = { { 0, } };
- GValue return_val = { 0, };
-
- g_return_if_fail (update_complete != NULL);
- g_return_if_fail (NAUTILUS_IS_INFO_PROVIDER (provider));
+ GValue args[3] = { { 0, } };
+ GValue return_val = { 0, };
- g_value_init (&args[0], NAUTILUS_TYPE_INFO_PROVIDER);
- g_value_init (&args[1], G_TYPE_POINTER);
- g_value_init (&args[2], NAUTILUS_TYPE_OPERATION_RESULT);
+ g_return_if_fail (update_complete != NULL);
+ g_return_if_fail (NAUTILUS_IS_INFO_PROVIDER (provider));
- g_value_set_object (&args[0], provider);
- g_value_set_pointer (&args[1], handle);
- g_value_set_enum (&args[2], result);
+ g_value_init (&args[0], NAUTILUS_TYPE_INFO_PROVIDER);
+ g_value_init (&args[1], G_TYPE_POINTER);
+ g_value_init (&args[2], NAUTILUS_TYPE_OPERATION_RESULT);
- g_closure_invoke (update_complete, &return_val, 3, args, NULL);
+ g_value_set_object (&args[0], provider);
+ g_value_set_pointer (&args[1], handle);
+ g_value_set_enum (&args[2], result);
- g_value_unset (&args[0]);
- g_value_unset (&args[1]);
- g_value_unset (&args[2]);
-}
+ g_closure_invoke (update_complete, &return_val, 3, args, NULL);
-
+ g_value_unset (&args[0]);
+ g_value_unset (&args[1]);
+ g_value_unset (&args[2]);
+}
diff --git a/libnautilus-extension/nautilus-location-widget-provider.c b/libnautilus-extension/nautilus-location-widget-provider.c
index 12d28ddeb..a2e2af008 100644
--- a/libnautilus-extension/nautilus-location-widget-provider.c
+++ b/libnautilus-extension/nautilus-location-widget-provider.c
@@ -1,6 +1,6 @@
/*
* nautilus-location-widget-provider.c - Interface for Nautilus
- extensions that provide extra widgets for a location
+ * extensions that provide extra widgets for a location
*
* Copyright (C) 2005 Red Hat, Inc.
*
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Alexander Larsson <alexl@redhat.com>
*
*/
@@ -41,31 +41,33 @@ nautilus_location_widget_provider_base_init (gpointer g_class)
{
}
-GType
+GType
nautilus_location_widget_provider_get_type (void)
{
- static GType type = 0;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusLocationWidgetProviderIface),
+ nautilus_location_widget_provider_base_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusLocationWidgetProviderIface),
- nautilus_location_widget_provider_base_init,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- type = g_type_register_static (G_TYPE_INTERFACE,
- "NautilusLocationWidgetProvider",
- &info, 0);
- g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
- }
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "NautilusLocationWidgetProvider",
+ &info, 0);
+ g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+ }
- return type;
+ return type;
}
/**
@@ -77,13 +79,12 @@ nautilus_location_widget_provider_get_type (void)
* Returns: (transfer none): the location widget for @provider at @uri
*/
GtkWidget *
-nautilus_location_widget_provider_get_widget (NautilusLocationWidgetProvider *provider,
- const char *uri,
- GtkWidget *window)
+nautilus_location_widget_provider_get_widget (NautilusLocationWidgetProvider *provider,
+ const char *uri,
+ GtkWidget *window)
{
- g_return_val_if_fail (NAUTILUS_IS_LOCATION_WIDGET_PROVIDER (provider), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_LOCATION_WIDGET_PROVIDER (provider), NULL);
- return NAUTILUS_LOCATION_WIDGET_PROVIDER_GET_IFACE (provider)->get_widget
- (provider, uri, window);
-
-}
+ return NAUTILUS_LOCATION_WIDGET_PROVIDER_GET_IFACE (provider)->get_widget
+ (provider, uri, window);
+}
diff --git a/libnautilus-extension/nautilus-menu-item.c b/libnautilus-extension/nautilus-menu-item.c
index ee582dcde..068188a6b 100644
--- a/libnautilus-extension/nautilus-menu-item.c
+++ b/libnautilus-extension/nautilus-menu-item.c
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -25,31 +25,34 @@
#include <glib/gi18n-lib.h>
#include "nautilus-menu.h"
-enum {
- ACTIVATE,
- LAST_SIGNAL
+enum
+{
+ ACTIVATE,
+ LAST_SIGNAL
};
-enum {
- PROP_0,
- PROP_NAME,
- PROP_LABEL,
- PROP_TIP,
- PROP_ICON,
- PROP_SENSITIVE,
- PROP_PRIORITY,
- PROP_MENU,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_NAME,
+ PROP_LABEL,
+ PROP_TIP,
+ PROP_ICON,
+ PROP_SENSITIVE,
+ PROP_PRIORITY,
+ PROP_MENU,
+ LAST_PROP
};
-struct _NautilusMenuItemDetails {
- char *name;
- char *label;
- char *tip;
- char *icon;
- NautilusMenu *menu;
- gboolean sensitive;
- gboolean priority;
+struct _NautilusMenuItemDetails
+{
+ char *name;
+ char *label;
+ char *tip;
+ char *icon;
+ NautilusMenu *menu;
+ gboolean sensitive;
+ gboolean priority;
};
static guint signals[LAST_SIGNAL];
@@ -83,24 +86,24 @@ static GObjectClass *parent_class = NULL;
*/
NautilusMenuItem *
nautilus_menu_item_new (const char *name,
- const char *label,
- const char *tip,
- const char *icon)
+ const char *label,
+ const char *tip,
+ const char *icon)
{
- NautilusMenuItem *item;
+ NautilusMenuItem *item;
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (label != NULL, NULL);
- g_return_val_if_fail (tip != NULL, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL, NULL);
+ g_return_val_if_fail (tip != NULL, NULL);
- item = g_object_new (NAUTILUS_TYPE_MENU_ITEM,
- "name", name,
- "label", label,
- "tip", tip,
- "icon", icon,
- NULL);
+ item = g_object_new (NAUTILUS_TYPE_MENU_ITEM,
+ "name", name,
+ "label", label,
+ "tip", tip,
+ "icon", icon,
+ NULL);
- return item;
+ return item;
}
/**
@@ -112,7 +115,7 @@ nautilus_menu_item_new (const char *name,
void
nautilus_menu_item_activate (NautilusMenuItem *item)
{
- g_signal_emit (item, signals[ACTIVATE], 0);
+ g_signal_emit (item, signals[ACTIVATE], 0);
}
/**
@@ -123,224 +126,276 @@ nautilus_menu_item_activate (NautilusMenuItem *item)
* Attachs a menu to the given #NautilusMenuItem.
*/
void
-nautilus_menu_item_set_submenu (NautilusMenuItem *item, NautilusMenu *menu)
+nautilus_menu_item_set_submenu (NautilusMenuItem *item,
+ NautilusMenu *menu)
{
- g_object_set (item, "menu", menu, NULL);
+ g_object_set (item, "menu", menu, NULL);
}
static void
-nautilus_menu_item_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_menu_item_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusMenuItem *item;
-
- item = NAUTILUS_MENU_ITEM (object);
-
- switch (param_id) {
- case PROP_NAME :
- g_value_set_string (value, item->details->name);
- break;
- case PROP_LABEL :
- g_value_set_string (value, item->details->label);
- break;
- case PROP_TIP :
- g_value_set_string (value, item->details->tip);
- break;
- case PROP_ICON :
- g_value_set_string (value, item->details->icon);
- break;
- case PROP_SENSITIVE :
- g_value_set_boolean (value, item->details->sensitive);
- break;
- case PROP_PRIORITY :
- g_value_set_boolean (value, item->details->priority);
- break;
- case PROP_MENU :
- g_value_set_object (value, item->details->menu);
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusMenuItem *item;
+
+ item = NAUTILUS_MENU_ITEM (object);
+
+ switch (param_id)
+ {
+ case PROP_NAME:
+ {
+ g_value_set_string (value, item->details->name);
+ }
+ break;
+
+ case PROP_LABEL:
+ {
+ g_value_set_string (value, item->details->label);
+ }
+ break;
+
+ case PROP_TIP:
+ {
+ g_value_set_string (value, item->details->tip);
+ }
+ break;
+
+ case PROP_ICON:
+ {
+ g_value_set_string (value, item->details->icon);
+ }
+ break;
+
+ case PROP_SENSITIVE:
+ {
+ g_value_set_boolean (value, item->details->sensitive);
+ }
+ break;
+
+ case PROP_PRIORITY:
+ {
+ g_value_set_boolean (value, item->details->priority);
+ }
+ break;
+
+ case PROP_MENU:
+ {
+ g_value_set_object (value, item->details->menu);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_menu_item_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_menu_item_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusMenuItem *item;
-
- item = NAUTILUS_MENU_ITEM (object);
-
- switch (param_id) {
- case PROP_NAME :
- g_free (item->details->name);
- item->details->name = g_strdup (g_value_get_string (value));
- g_object_notify (object, "name");
- break;
- case PROP_LABEL :
- g_free (item->details->label);
- item->details->label = g_strdup (g_value_get_string (value));
- g_object_notify (object, "label");
- break;
- case PROP_TIP :
- g_free (item->details->tip);
- item->details->tip = g_strdup (g_value_get_string (value));
- g_object_notify (object, "tip");
- break;
- case PROP_ICON :
- g_free (item->details->icon);
- item->details->icon = g_strdup (g_value_get_string (value));
- g_object_notify (object, "icon");
- break;
- case PROP_SENSITIVE :
- item->details->sensitive = g_value_get_boolean (value);
- g_object_notify (object, "sensitive");
- break;
- case PROP_PRIORITY :
- item->details->priority = g_value_get_boolean (value);
- g_object_notify (object, "priority");
- break;
- case PROP_MENU :
- if (item->details->menu) {
- g_object_unref (item->details->menu);
- }
- item->details->menu = g_object_ref (g_value_get_object (value));
- g_object_notify (object, "menu");
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusMenuItem *item;
+
+ item = NAUTILUS_MENU_ITEM (object);
+
+ switch (param_id)
+ {
+ case PROP_NAME:
+ {
+ g_free (item->details->name);
+ item->details->name = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "name");
+ }
+ break;
+
+ case PROP_LABEL:
+ {
+ g_free (item->details->label);
+ item->details->label = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "label");
+ }
+ break;
+
+ case PROP_TIP:
+ {
+ g_free (item->details->tip);
+ item->details->tip = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "tip");
+ }
+ break;
+
+ case PROP_ICON:
+ {
+ g_free (item->details->icon);
+ item->details->icon = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "icon");
+ }
+ break;
+
+ case PROP_SENSITIVE:
+ {
+ item->details->sensitive = g_value_get_boolean (value);
+ g_object_notify (object, "sensitive");
+ }
+ break;
+
+ case PROP_PRIORITY:
+ {
+ item->details->priority = g_value_get_boolean (value);
+ g_object_notify (object, "priority");
+ }
+ break;
+
+ case PROP_MENU:
+ {
+ if (item->details->menu)
+ {
+ g_object_unref (item->details->menu);
+ }
+ item->details->menu = g_object_ref (g_value_get_object (value));
+ g_object_notify (object, "menu");
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_menu_item_finalize (GObject *object)
{
- NautilusMenuItem *item;
+ NautilusMenuItem *item;
- item = NAUTILUS_MENU_ITEM (object);
+ item = NAUTILUS_MENU_ITEM (object);
- g_free (item->details->name);
- g_free (item->details->label);
- g_free (item->details->tip);
- g_free (item->details->icon);
- if (item->details->menu) {
- g_object_unref (item->details->menu);
- }
+ g_free (item->details->name);
+ g_free (item->details->label);
+ g_free (item->details->tip);
+ g_free (item->details->icon);
+ if (item->details->menu)
+ {
+ g_object_unref (item->details->menu);
+ }
- g_free (item->details);
+ g_free (item->details);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
nautilus_menu_item_instance_init (NautilusMenuItem *item)
{
- item->details = g_new0 (NautilusMenuItemDetails, 1);
- item->details->sensitive = TRUE;
- item->details->menu = NULL;
+ item->details = g_new0 (NautilusMenuItemDetails, 1);
+ item->details->sensitive = TRUE;
+ item->details->menu = NULL;
}
static void
nautilus_menu_item_class_init (NautilusMenuItemClass *class)
{
- parent_class = g_type_class_peek_parent (class);
-
- G_OBJECT_CLASS (class)->finalize = nautilus_menu_item_finalize;
- G_OBJECT_CLASS (class)->get_property = nautilus_menu_item_get_property;
- G_OBJECT_CLASS (class)->set_property = nautilus_menu_item_set_property;
-
- signals[ACTIVATE] =
- g_signal_new ("activate",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusMenuItemClass,
- activate),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name of the item",
- NULL,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_LABEL,
- g_param_spec_string ("label",
- "Label",
- "Label to display to the user",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_TIP,
- g_param_spec_string ("tip",
- "Tip",
- "Tooltip for the menu item",
- NULL,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_ICON,
- g_param_spec_string ("icon",
- "Icon",
- "Name of the icon to display in the menu item",
- NULL,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_SENSITIVE,
- g_param_spec_boolean ("sensitive",
- "Sensitive",
- "Whether the menu item is sensitive",
- TRUE,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_PRIORITY,
- g_param_spec_boolean ("priority",
- "Priority",
- "Show priority text in toolbars",
- TRUE,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_MENU,
- g_param_spec_object ("menu",
- "Menu",
- "The menu belonging to this item. May be null.",
- NAUTILUS_TYPE_MENU,
- G_PARAM_READWRITE));
+ parent_class = g_type_class_peek_parent (class);
+
+ G_OBJECT_CLASS (class)->finalize = nautilus_menu_item_finalize;
+ G_OBJECT_CLASS (class)->get_property = nautilus_menu_item_get_property;
+ G_OBJECT_CLASS (class)->set_property = nautilus_menu_item_set_property;
+
+ signals[ACTIVATE] =
+ g_signal_new ("activate",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusMenuItemClass,
+ activate),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "Name of the item",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_LABEL,
+ g_param_spec_string ("label",
+ "Label",
+ "Label to display to the user",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_TIP,
+ g_param_spec_string ("tip",
+ "Tip",
+ "Tooltip for the menu item",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_ICON,
+ g_param_spec_string ("icon",
+ "Icon",
+ "Name of the icon to display in the menu item",
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_SENSITIVE,
+ g_param_spec_boolean ("sensitive",
+ "Sensitive",
+ "Whether the menu item is sensitive",
+ TRUE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_PRIORITY,
+ g_param_spec_boolean ("priority",
+ "Priority",
+ "Show priority text in toolbars",
+ TRUE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_MENU,
+ g_param_spec_object ("menu",
+ "Menu",
+ "The menu belonging to this item. May be null.",
+ NAUTILUS_TYPE_MENU,
+ G_PARAM_READWRITE));
}
-GType
+GType
nautilus_menu_item_get_type (void)
{
- static GType type = 0;
-
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusMenuItemClass),
- NULL,
- NULL,
- (GClassInitFunc)nautilus_menu_item_class_init,
- NULL,
- NULL,
- sizeof (NautilusMenuItem),
- 0,
- (GInstanceInitFunc)nautilus_menu_item_instance_init
- };
-
- type = g_type_register_static
- (G_TYPE_OBJECT,
- "NautilusMenuItem",
- &info, 0);
- }
-
- return type;
-}
+ static GType type = 0;
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusMenuItemClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) nautilus_menu_item_class_init,
+ NULL,
+ NULL,
+ sizeof (NautilusMenuItem),
+ 0,
+ (GInstanceInitFunc) nautilus_menu_item_instance_init
+ };
+
+ type = g_type_register_static
+ (G_TYPE_OBJECT,
+ "NautilusMenuItem",
+ &info, 0);
+ }
+
+ return type;
+}
diff --git a/libnautilus-extension/nautilus-menu-provider.c b/libnautilus-extension/nautilus-menu-provider.c
index 0fb709469..05eb28a67 100644
--- a/libnautilus-extension/nautilus-menu-provider.c
+++ b/libnautilus-extension/nautilus-menu-provider.c
@@ -1,5 +1,5 @@
/*
- * nautilus-property-page-provider.c - Interface for Nautilus extensions
+ * nautilus-property-page-provider.c - Interface for Nautilus extensions
* that provide context menu items
* for files.
*
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -40,47 +40,49 @@
static void
nautilus_menu_provider_base_init (gpointer g_class)
{
- static gboolean initialized = FALSE;
+ static gboolean initialized = FALSE;
- if (!initialized)
- {
- /* This signal should be emited each time the extension modify the list of menu items */
- g_signal_new ("items-updated",
- NAUTILUS_TYPE_MENU_PROVIDER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- initialized = TRUE;
- }
+ if (!initialized)
+ {
+ /* This signal should be emited each time the extension modify the list of menu items */
+ g_signal_new ("items-updated",
+ NAUTILUS_TYPE_MENU_PROVIDER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ initialized = TRUE;
+ }
}
-GType
+GType
nautilus_menu_provider_get_type (void)
{
- static GType type = 0;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusMenuProviderIface),
+ nautilus_menu_provider_base_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusMenuProviderIface),
- nautilus_menu_provider_base_init,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- type = g_type_register_static (G_TYPE_INTERFACE,
- "NautilusMenuProvider",
- &info, 0);
- g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
- }
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "NautilusMenuProvider",
+ &info, 0);
+ g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+ }
- return type;
+ return type;
}
/**
@@ -93,17 +95,20 @@ nautilus_menu_provider_get_type (void)
*/
GList *
nautilus_menu_provider_get_file_items (NautilusMenuProvider *provider,
- GtkWidget *window,
- GList *files)
+ GtkWidget *window,
+ GList *files)
{
- g_return_val_if_fail (NAUTILUS_IS_MENU_PROVIDER (provider), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_MENU_PROVIDER (provider), NULL);
- if (NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_file_items) {
- return NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_file_items
- (provider, window, files);
- } else {
- return NULL;
- }
+ if (NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_file_items)
+ {
+ return NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_file_items
+ (provider, window, files);
+ }
+ else
+ {
+ return NULL;
+ }
}
/**
@@ -116,26 +121,28 @@ nautilus_menu_provider_get_file_items (NautilusMenuProvider *provider,
*/
GList *
nautilus_menu_provider_get_background_items (NautilusMenuProvider *provider,
- GtkWidget *window,
- NautilusFileInfo *current_folder)
+ GtkWidget *window,
+ NautilusFileInfo *current_folder)
{
- g_return_val_if_fail (NAUTILUS_IS_MENU_PROVIDER (provider), NULL);
- g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (current_folder), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_MENU_PROVIDER (provider), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE_INFO (current_folder), NULL);
- if (NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_background_items) {
- return NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_background_items
- (provider, window, current_folder);
- } else {
- return NULL;
- }
+ if (NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_background_items)
+ {
+ return NAUTILUS_MENU_PROVIDER_GET_IFACE (provider)->get_background_items
+ (provider, window, current_folder);
+ }
+ else
+ {
+ return NULL;
+ }
}
/* This function emit a signal to inform nautilus that its item list has changed */
void
-nautilus_menu_provider_emit_items_updated_signal (NautilusMenuProvider* provider)
+nautilus_menu_provider_emit_items_updated_signal (NautilusMenuProvider *provider)
{
- g_return_if_fail (NAUTILUS_IS_MENU_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_IS_MENU_PROVIDER (provider));
- g_signal_emit_by_name (provider, "items-updated");
+ g_signal_emit_by_name (provider, "items-updated");
}
-
diff --git a/libnautilus-extension/nautilus-menu.c b/libnautilus-extension/nautilus-menu.c
index ee7b2b2a8..fcc2ecc4c 100644
--- a/libnautilus-extension/nautilus-menu.c
+++ b/libnautilus-extension/nautilus-menu.c
@@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Raffaele Sandrini <rasa@gmx.ch>
*
*/
@@ -40,17 +40,19 @@
#define NAUTILUS_MENU_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_MENU, NautilusMenuPrivate))
G_DEFINE_TYPE (NautilusMenu, nautilus_menu, G_TYPE_OBJECT);
-struct _NautilusMenuPrivate {
- GList *item_list;
+struct _NautilusMenuPrivate
+{
+ GList *item_list;
};
void
-nautilus_menu_append_item (NautilusMenu *menu, NautilusMenuItem *item)
+nautilus_menu_append_item (NautilusMenu *menu,
+ NautilusMenuItem *item)
{
- g_return_if_fail (menu != NULL);
- g_return_if_fail (item != NULL);
-
- menu->priv->item_list = g_list_append (menu->priv->item_list, g_object_ref (item));
+ g_return_if_fail (menu != NULL);
+ g_return_if_fail (item != NULL);
+
+ menu->priv->item_list = g_list_append (menu->priv->item_list, g_object_ref (item));
}
/**
@@ -62,14 +64,14 @@ nautilus_menu_append_item (NautilusMenu *menu, NautilusMenuItem *item)
GList *
nautilus_menu_get_items (NautilusMenu *menu)
{
- GList *item_list;
-
- g_return_val_if_fail (menu != NULL, NULL);
-
- item_list = g_list_copy (menu->priv->item_list);
- g_list_foreach (item_list, (GFunc)g_object_ref, NULL);
-
- return item_list;
+ GList *item_list;
+
+ g_return_val_if_fail (menu != NULL, NULL);
+
+ item_list = g_list_copy (menu->priv->item_list);
+ g_list_foreach (item_list, (GFunc) g_object_ref, NULL);
+
+ return item_list;
}
/**
@@ -80,10 +82,10 @@ nautilus_menu_get_items (NautilusMenu *menu)
void
nautilus_menu_item_list_free (GList *item_list)
{
- g_return_if_fail (item_list != NULL);
-
- g_list_foreach (item_list, (GFunc)g_object_unref, NULL);
- g_list_free (item_list);
+ g_return_if_fail (item_list != NULL);
+
+ g_list_foreach (item_list, (GFunc) g_object_unref, NULL);
+ g_list_free (item_list);
}
/* Type initialization */
@@ -91,31 +93,32 @@ nautilus_menu_item_list_free (GList *item_list)
static void
nautilus_menu_finalize (GObject *object)
{
- NautilusMenu *menu = NAUTILUS_MENU (object);
+ NautilusMenu *menu = NAUTILUS_MENU (object);
- if (menu->priv->item_list) {
- g_list_free (menu->priv->item_list);
- }
+ if (menu->priv->item_list)
+ {
+ g_list_free (menu->priv->item_list);
+ }
- G_OBJECT_CLASS (nautilus_menu_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_menu_parent_class)->finalize (object);
}
static void
nautilus_menu_init (NautilusMenu *menu)
{
- menu->priv = NAUTILUS_MENU_GET_PRIVATE (menu);
+ menu->priv = NAUTILUS_MENU_GET_PRIVATE (menu);
- menu->priv->item_list = NULL;
+ menu->priv->item_list = NULL;
}
static void
nautilus_menu_class_init (NautilusMenuClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- g_type_class_add_private (klass, sizeof (NautilusMenuPrivate));
-
- object_class->finalize = nautilus_menu_finalize;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (NautilusMenuPrivate));
+
+ object_class->finalize = nautilus_menu_finalize;
}
/* public constructors */
@@ -123,9 +126,9 @@ nautilus_menu_class_init (NautilusMenuClass *klass)
NautilusMenu *
nautilus_menu_new (void)
{
- NautilusMenu *obj;
-
- obj = NAUTILUS_MENU (g_object_new (NAUTILUS_TYPE_MENU, NULL));
-
- return obj;
+ NautilusMenu *obj;
+
+ obj = NAUTILUS_MENU (g_object_new (NAUTILUS_TYPE_MENU, NULL));
+
+ return obj;
}
diff --git a/libnautilus-extension/nautilus-property-page-provider.c b/libnautilus-extension/nautilus-property-page-provider.c
index 04a7f1f0f..7a7a13cf0 100644
--- a/libnautilus-extension/nautilus-property-page-provider.c
+++ b/libnautilus-extension/nautilus-property-page-provider.c
@@ -1,6 +1,6 @@
/*
* nautilus-property-page-provider.c - Interface for Nautilus extensions
- * that provide property pages for
+ * that provide property pages for
* files.
*
* Copyright (C) 2003 Novell, Inc.
@@ -17,7 +17,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -42,31 +42,33 @@ nautilus_property_page_provider_base_init (gpointer g_class)
{
}
-GType
+GType
nautilus_property_page_provider_get_type (void)
{
- static GType type = 0;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusPropertyPageProviderIface),
+ nautilus_property_page_provider_base_init,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ 0,
+ NULL
+ };
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusPropertyPageProviderIface),
- nautilus_property_page_provider_base_init,
- NULL,
- NULL,
- NULL,
- NULL,
- 0,
- 0,
- NULL
- };
-
- type = g_type_register_static (G_TYPE_INTERFACE,
- "NautilusPropertyPageProvider",
- &info, 0);
- g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
- }
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "NautilusPropertyPageProvider",
+ &info, 0);
+ g_type_interface_add_prerequisite (type, G_TYPE_OBJECT);
+ }
- return type;
+ return type;
}
/**
@@ -84,13 +86,11 @@ nautilus_property_page_provider_get_type (void)
*/
GList *
nautilus_property_page_provider_get_pages (NautilusPropertyPageProvider *provider,
- GList *files)
+ GList *files)
{
- g_return_val_if_fail (NAUTILUS_IS_PROPERTY_PAGE_PROVIDER (provider), NULL);
- g_return_val_if_fail (NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE (provider)->get_pages != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_PROPERTY_PAGE_PROVIDER (provider), NULL);
+ g_return_val_if_fail (NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE (provider)->get_pages != NULL, NULL);
- return NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE (provider)->get_pages
- (provider, files);
+ return NAUTILUS_PROPERTY_PAGE_PROVIDER_GET_IFACE (provider)->get_pages
+ (provider, files);
}
-
-
diff --git a/libnautilus-extension/nautilus-property-page.c b/libnautilus-extension/nautilus-property-page.c
index 545f2999f..a1c9d3a87 100644
--- a/libnautilus-extension/nautilus-property-page.c
+++ b/libnautilus-extension/nautilus-property-page.c
@@ -1,5 +1,5 @@
/*
- * nautilus-property-page.h - Property pages exported by
+ * nautilus-property-page.h - Property pages exported by
* NautilusPropertyProvider objects.
*
* Copyright (C) 2003 Novell, Inc.
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
*
*/
@@ -26,18 +26,20 @@
#include <glib/gi18n-lib.h>
-enum {
- PROP_0,
- PROP_NAME,
- PROP_LABEL,
- PROP_PAGE,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_NAME,
+ PROP_LABEL,
+ PROP_PAGE,
+ LAST_PROP
};
-struct _NautilusPropertyPageDetails {
- char *name;
- GtkWidget *label;
- GtkWidget *page;
+struct _NautilusPropertyPageDetails
+{
+ char *name;
+ GtkWidget *label;
+ GtkWidget *page;
};
static GObjectClass *parent_class = NULL;
@@ -67,182 +69,212 @@ static GObjectClass *parent_class = NULL;
*/
NautilusPropertyPage *
nautilus_property_page_new (const char *name,
- GtkWidget *label,
- GtkWidget *page_widget)
+ GtkWidget *label,
+ GtkWidget *page_widget)
{
- NautilusPropertyPage *page;
-
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (label != NULL && GTK_IS_WIDGET (label), NULL);
- g_return_val_if_fail (page_widget != NULL && GTK_IS_WIDGET (page_widget),
- NULL);
-
- page = g_object_new (NAUTILUS_TYPE_PROPERTY_PAGE,
- "name", name,
- "label", label,
- "page", page_widget,
- NULL);
-
- return page;
+ NautilusPropertyPage *page;
+
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (label != NULL && GTK_IS_WIDGET (label), NULL);
+ g_return_val_if_fail (page_widget != NULL && GTK_IS_WIDGET (page_widget),
+ NULL);
+
+ page = g_object_new (NAUTILUS_TYPE_PROPERTY_PAGE,
+ "name", name,
+ "label", label,
+ "page", page_widget,
+ NULL);
+
+ return page;
}
static void
-nautilus_property_page_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_property_page_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusPropertyPage *page;
-
- page = NAUTILUS_PROPERTY_PAGE (object);
-
- switch (param_id) {
- case PROP_NAME :
- g_value_set_string (value, page->details->name);
- break;
- case PROP_LABEL :
- g_value_set_object (value, page->details->label);
- break;
- case PROP_PAGE :
- g_value_set_object (value, page->details->page);
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusPropertyPage *page;
+
+ page = NAUTILUS_PROPERTY_PAGE (object);
+
+ switch (param_id)
+ {
+ case PROP_NAME:
+ {
+ g_value_set_string (value, page->details->name);
+ }
+ break;
+
+ case PROP_LABEL:
+ {
+ g_value_set_object (value, page->details->label);
+ }
+ break;
+
+ case PROP_PAGE:
+ {
+ g_value_set_object (value, page->details->page);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_property_page_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_property_page_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusPropertyPage *page;
-
- page = NAUTILUS_PROPERTY_PAGE (object);
-
- switch (param_id) {
- case PROP_NAME :
- g_free (page->details->name);
- page->details->name = g_strdup (g_value_get_string (value));
- g_object_notify (object, "name");
- break;
- case PROP_LABEL :
- if (page->details->label) {
- g_object_unref (page->details->label);
- }
-
- page->details->label = g_object_ref (g_value_get_object (value));
- g_object_notify (object, "label");
- break;
- case PROP_PAGE :
- if (page->details->page) {
- g_object_unref (page->details->page);
- }
-
- page->details->page = g_object_ref (g_value_get_object (value));
- g_object_notify (object, "page");
- break;
- default :
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusPropertyPage *page;
+
+ page = NAUTILUS_PROPERTY_PAGE (object);
+
+ switch (param_id)
+ {
+ case PROP_NAME:
+ {
+ g_free (page->details->name);
+ page->details->name = g_strdup (g_value_get_string (value));
+ g_object_notify (object, "name");
+ }
+ break;
+
+ case PROP_LABEL:
+ {
+ if (page->details->label)
+ {
+ g_object_unref (page->details->label);
+ }
+
+ page->details->label = g_object_ref (g_value_get_object (value));
+ g_object_notify (object, "label");
+ }
+ break;
+
+ case PROP_PAGE:
+ {
+ if (page->details->page)
+ {
+ g_object_unref (page->details->page);
+ }
+
+ page->details->page = g_object_ref (g_value_get_object (value));
+ g_object_notify (object, "page");
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_property_page_dispose (GObject *object)
{
- NautilusPropertyPage *page;
-
- page = NAUTILUS_PROPERTY_PAGE (object);
-
- if (page->details->label) {
- g_object_unref (page->details->label);
- page->details->label = NULL;
- }
- if (page->details->page) {
- g_object_unref (page->details->page);
- page->details->page = NULL;
- }
+ NautilusPropertyPage *page;
+
+ page = NAUTILUS_PROPERTY_PAGE (object);
+
+ if (page->details->label)
+ {
+ g_object_unref (page->details->label);
+ page->details->label = NULL;
+ }
+ if (page->details->page)
+ {
+ g_object_unref (page->details->page);
+ page->details->page = NULL;
+ }
}
static void
nautilus_property_page_finalize (GObject *object)
{
- NautilusPropertyPage *page;
-
- page = NAUTILUS_PROPERTY_PAGE (object);
+ NautilusPropertyPage *page;
- g_free (page->details->name);
+ page = NAUTILUS_PROPERTY_PAGE (object);
- g_free (page->details);
+ g_free (page->details->name);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ g_free (page->details);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
nautilus_property_page_instance_init (NautilusPropertyPage *page)
{
- page->details = g_new0 (NautilusPropertyPageDetails, 1);
+ page->details = g_new0 (NautilusPropertyPageDetails, 1);
}
static void
nautilus_property_page_class_init (NautilusPropertyPageClass *class)
{
- parent_class = g_type_class_peek_parent (class);
-
- G_OBJECT_CLASS (class)->finalize = nautilus_property_page_finalize;
- G_OBJECT_CLASS (class)->dispose = nautilus_property_page_dispose;
- G_OBJECT_CLASS (class)->get_property = nautilus_property_page_get_property;
- G_OBJECT_CLASS (class)->set_property = nautilus_property_page_set_property;
-
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_NAME,
- g_param_spec_string ("name",
- "Name",
- "Name of the page",
- NULL,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_LABEL,
- g_param_spec_object ("label",
- "Label",
- "Label widget to display in the notebook tab",
- GTK_TYPE_WIDGET,
- G_PARAM_READWRITE));
- g_object_class_install_property (G_OBJECT_CLASS (class),
- PROP_PAGE,
- g_param_spec_object ("page",
- "Page",
- "Widget for the property page",
- GTK_TYPE_WIDGET,
- G_PARAM_READWRITE));
+ parent_class = g_type_class_peek_parent (class);
+
+ G_OBJECT_CLASS (class)->finalize = nautilus_property_page_finalize;
+ G_OBJECT_CLASS (class)->dispose = nautilus_property_page_dispose;
+ G_OBJECT_CLASS (class)->get_property = nautilus_property_page_get_property;
+ G_OBJECT_CLASS (class)->set_property = nautilus_property_page_set_property;
+
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Name",
+ "Name of the page",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_LABEL,
+ g_param_spec_object ("label",
+ "Label",
+ "Label widget to display in the notebook tab",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_PAGE,
+ g_param_spec_object ("page",
+ "Page",
+ "Widget for the property page",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE));
}
-GType
+GType
nautilus_property_page_get_type (void)
{
- static GType type = 0;
-
- if (!type) {
- const GTypeInfo info = {
- sizeof (NautilusPropertyPageClass),
- NULL,
- NULL,
- (GClassInitFunc)nautilus_property_page_class_init,
- NULL,
- NULL,
- sizeof (NautilusPropertyPage),
- 0,
- (GInstanceInitFunc)nautilus_property_page_instance_init
- };
-
- type = g_type_register_static
- (G_TYPE_OBJECT,
- "NautilusPropertyPage",
- &info, 0);
- }
-
- return type;
+ static GType type = 0;
+
+ if (!type)
+ {
+ const GTypeInfo info =
+ {
+ sizeof (NautilusPropertyPageClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) nautilus_property_page_class_init,
+ NULL,
+ NULL,
+ sizeof (NautilusPropertyPage),
+ 0,
+ (GInstanceInitFunc) nautilus_property_page_instance_init
+ };
+
+ type = g_type_register_static
+ (G_TYPE_OBJECT,
+ "NautilusPropertyPage",
+ &info, 0);
+ }
+
+ return type;
}
diff --git a/nautilus-desktop/main-desktop.c b/nautilus-desktop/main-desktop.c
index 09851d3a4..aa9c98d86 100644
--- a/nautilus-desktop/main-desktop.c
+++ b/nautilus-desktop/main-desktop.c
@@ -14,25 +14,26 @@
#include <unistd.h>
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- NautilusDesktopApplication *application;
- int retval;
+ NautilusDesktopApplication *application;
+ int retval;
- /* Initialize gettext support */
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
+ /* Initialize gettext support */
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
- g_set_prgname ("nautilus-desktop");
+ g_set_prgname ("nautilus-desktop");
- nautilus_register_resource ();
- application = nautilus_desktop_application_new ();
+ nautilus_register_resource ();
+ application = nautilus_desktop_application_new ();
- retval = g_application_run (G_APPLICATION (application),
- argc, argv);
+ retval = g_application_run (G_APPLICATION (application),
+ argc, argv);
- g_object_unref (application);
+ g_object_unref (application);
- return retval;
+ return retval;
}
diff --git a/nautilus-desktop/nautilus-desktop-application.c b/nautilus-desktop/nautilus-desktop-application.c
index 028add6ff..634526813 100644
--- a/nautilus-desktop/nautilus-desktop-application.c
+++ b/nautilus-desktop/nautilus-desktop-application.c
@@ -35,10 +35,10 @@ static NautilusFreedesktopFileManager1 *freedesktop_proxy = NULL;
struct _NautilusDesktopApplication
{
- NautilusApplication parent_instance;
+ NautilusApplication parent_instance;
- gboolean force;
- GCancellable *freedesktop_cancellable;
+ gboolean force;
+ GCancellable *freedesktop_cancellable;
};
G_DEFINE_TYPE (NautilusDesktopApplication, nautilus_desktop_application, NAUTILUS_TYPE_APPLICATION)
@@ -48,31 +48,31 @@ on_show_folders (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- GError *error = NULL;
+ GError *error = NULL;
- nautilus_freedesktop_file_manager1_call_show_items_finish (freedesktop_proxy,
- res,
- &error);
- if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ nautilus_freedesktop_file_manager1_call_show_items_finish (freedesktop_proxy,
+ res,
+ &error);
+ if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
- g_warning ("Unable to show items with File Manager freedesktop proxy: %s", error->message);
+ g_warning ("Unable to show items with File Manager freedesktop proxy: %s", error->message);
}
- g_clear_error (&error);
+ g_clear_error (&error);
}
static void
open_location_on_dbus (NautilusDesktopApplication *self,
const gchar *uri)
{
- const gchar *uris[] = { uri, NULL };
-
- nautilus_freedesktop_file_manager1_call_show_folders (freedesktop_proxy,
- uris,
- "",
- self->freedesktop_cancellable,
- on_show_folders,
- self);
+ const gchar *uris[] = { uri, NULL };
+
+ nautilus_freedesktop_file_manager1_call_show_folders (freedesktop_proxy,
+ uris,
+ "",
+ self->freedesktop_cancellable,
+ on_show_folders,
+ self);
}
static void
@@ -83,46 +83,46 @@ open_location_full (NautilusApplication *app,
NautilusWindow *target_window,
NautilusWindowSlot *target_slot)
{
- NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
- gchar *uri;
+ NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
+ gchar *uri;
- uri = g_file_get_uri (location);
- if (eel_uri_is_desktop (uri) && target_window &&
- NAUTILUS_IS_DESKTOP_WINDOW (target_window))
+ uri = g_file_get_uri (location);
+ if (eel_uri_is_desktop (uri) && target_window &&
+ NAUTILUS_IS_DESKTOP_WINDOW (target_window))
{
- nautilus_window_open_location_full (target_window, location, flags, selection, NULL);
+ nautilus_window_open_location_full (target_window, location, flags, selection, NULL);
}
- else
+ else
{
- if (freedesktop_proxy)
+ if (freedesktop_proxy)
{
- open_location_on_dbus (self, uri);
+ open_location_on_dbus (self, uri);
}
- else
+ else
{
- g_warning ("cannot open folder on desktop, freedesktop bus not ready\n");
+ g_warning ("cannot open folder on desktop, freedesktop bus not ready\n");
}
}
- g_free (uri);
+ g_free (uri);
}
static void
nautilus_application_set_desktop_visible (NautilusDesktopApplication *self,
gboolean visible)
{
- GtkWidget *desktop_window;
+ GtkWidget *desktop_window;
- if (visible)
+ if (visible)
{
- nautilus_desktop_window_ensure ();
+ nautilus_desktop_window_ensure ();
}
- else
+ else
{
- desktop_window = nautilus_desktop_window_get ();
- if (desktop_window != NULL)
+ desktop_window = nautilus_desktop_window_get ();
+ if (desktop_window != NULL)
{
- gtk_widget_destroy (desktop_window);
+ gtk_widget_destroy (desktop_window);
}
}
}
@@ -130,151 +130,151 @@ nautilus_application_set_desktop_visible (NautilusDesktopApplication *self,
static void
update_desktop_from_gsettings (NautilusDesktopApplication *self)
{
- GdkDisplay *display;
- gboolean visible;
+ GdkDisplay *display;
+ gboolean visible;
#ifdef GDK_WINDOWING_X11
- display = gdk_display_get_default ();
- visible = g_settings_get_boolean (gnome_background_preferences,
- NAUTILUS_PREFERENCES_SHOW_DESKTOP);
- visible = visible || self->force;
+ display = gdk_display_get_default ();
+ visible = g_settings_get_boolean (gnome_background_preferences,
+ NAUTILUS_PREFERENCES_SHOW_DESKTOP);
+ visible = visible || self->force;
- if (!GDK_IS_X11_DISPLAY (display))
+ if (!GDK_IS_X11_DISPLAY (display))
{
- if (visible)
+ if (visible)
{
- g_warning ("Desktop icons only supported on X11. Desktop not created");
+ g_warning ("Desktop icons only supported on X11. Desktop not created");
}
- return;
+ return;
}
- nautilus_application_set_desktop_visible (self, visible);
+ nautilus_application_set_desktop_visible (self, visible);
- return;
+ return;
#endif
- g_warning ("Desktop icons only supported on X11. Desktop not created");
+ g_warning ("Desktop icons only supported on X11. Desktop not created");
}
static void
init_desktop (NautilusDesktopApplication *self)
{
- if (!self->force)
+ if (!self->force)
{
- g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
- G_CALLBACK (update_desktop_from_gsettings),
- self);
+ g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
+ G_CALLBACK (update_desktop_from_gsettings),
+ self);
}
- update_desktop_from_gsettings (self);
+ update_desktop_from_gsettings (self);
}
static void
nautilus_desktop_application_activate (GApplication *app)
{
- /* Do nothing */
+ /* Do nothing */
}
static gint
nautilus_desktop_application_command_line (GApplication *application,
GApplicationCommandLine *command_line)
{
- NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (application);
- GVariantDict *options;
+ NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (application);
+ GVariantDict *options;
- options = g_application_command_line_get_options_dict (command_line);
+ options = g_application_command_line_get_options_dict (command_line);
- if (g_variant_dict_contains (options, "force"))
+ if (g_variant_dict_contains (options, "force"))
{
- self->force = TRUE;
+ self->force = TRUE;
}
- init_desktop (self);
+ init_desktop (self);
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
static void
nautilus_desktop_application_startup (GApplication *app)
{
- NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
- GError *error = NULL;
-
- nautilus_application_startup_common (NAUTILUS_APPLICATION (app));
- self->freedesktop_cancellable = g_cancellable_new ();
- freedesktop_proxy = nautilus_freedesktop_file_manager1_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- "org.freedesktop.FileManager1",
- "/org/freedesktop/FileManager1",
- self->freedesktop_cancellable,
- &error);
-
- if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
+ GError *error = NULL;
+
+ nautilus_application_startup_common (NAUTILUS_APPLICATION (app));
+ self->freedesktop_cancellable = g_cancellable_new ();
+ freedesktop_proxy = nautilus_freedesktop_file_manager1_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ "org.freedesktop.FileManager1",
+ "/org/freedesktop/FileManager1",
+ self->freedesktop_cancellable,
+ &error);
+
+ if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
- g_warning ("Unable to create File Manager freedesktop proxy: %s", error->message);
+ g_warning ("Unable to create File Manager freedesktop proxy: %s", error->message);
}
- g_clear_error (&error);
+ g_clear_error (&error);
}
static void
nautilus_desktop_application_dispose (GObject *object)
{
- NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (object);
+ NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (object);
- g_clear_object (&self->freedesktop_cancellable);
+ g_clear_object (&self->freedesktop_cancellable);
- G_OBJECT_CLASS (nautilus_desktop_application_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_desktop_application_parent_class)->dispose (object);
}
static void
nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
{
- GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- NautilusApplicationClass *parent_class = NAUTILUS_APPLICATION_CLASS (klass);
+ GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ NautilusApplicationClass *parent_class = NAUTILUS_APPLICATION_CLASS (klass);
- parent_class->open_location_full = open_location_full;
+ parent_class->open_location_full = open_location_full;
- application_class->startup = nautilus_desktop_application_startup;
- application_class->activate = nautilus_desktop_application_activate;
- application_class->command_line = nautilus_desktop_application_command_line;
+ application_class->startup = nautilus_desktop_application_startup;
+ application_class->activate = nautilus_desktop_application_activate;
+ application_class->command_line = nautilus_desktop_application_command_line;
- gobject_class->dispose = nautilus_desktop_application_dispose;
+ gobject_class->dispose = nautilus_desktop_application_dispose;
}
static void
nautilus_desktop_ensure_builtins (void)
{
- /* Ensure the type so it can be registered early as a directory extension provider*/
- g_type_ensure (NAUTILUS_TYPE_DESKTOP_DIRECTORY);
+ /* Ensure the type so it can be registered early as a directory extension provider*/
+ g_type_ensure (NAUTILUS_TYPE_DESKTOP_DIRECTORY);
}
-const GOptionEntry desktop_options[] = {
- { "force", '\0', 0, G_OPTION_ARG_NONE, NULL,
- N_("Always manage the desktop (ignore the GSettings preference)."), NULL },
- { NULL }
+const GOptionEntry desktop_options[] =
+{
+ { "force", '\0', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Always manage the desktop (ignore the GSettings preference)."), NULL },
+ { NULL }
};
static void
nautilus_desktop_application_init (NautilusDesktopApplication *self)
{
- self->force = FALSE;
+ self->force = FALSE;
- g_application_add_main_option_entries (G_APPLICATION (self), desktop_options);
- nautilus_ensure_extension_points ();
- nautilus_ensure_extension_builtins ();
- nautilus_desktop_ensure_builtins ();
+ g_application_add_main_option_entries (G_APPLICATION (self), desktop_options);
+ nautilus_ensure_extension_points ();
+ nautilus_ensure_extension_builtins ();
+ nautilus_desktop_ensure_builtins ();
}
NautilusDesktopApplication *
nautilus_desktop_application_new (void)
{
- return g_object_new (NAUTILUS_TYPE_DESKTOP_APPLICATION,
- "application-id", "org.gnome.NautilusDesktop",
- "register-session", TRUE,
- "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_DESKTOP_APPLICATION,
+ "application-id", "org.gnome.NautilusDesktop",
+ "register-session", TRUE,
+ "flags", G_APPLICATION_HANDLES_COMMAND_LINE,
+ NULL);
}
-
diff --git a/nautilus-desktop/nautilus-desktop-canvas-view-container.c b/nautilus-desktop/nautilus-desktop-canvas-view-container.c
index 23db902d2..40012380a 100644
--- a/nautilus-desktop/nautilus-desktop-canvas-view-container.c
+++ b/nautilus-desktop/nautilus-desktop-canvas-view-container.c
@@ -21,7 +21,7 @@
struct _NautilusDesktopCanvasViewContainer
{
- NautilusCanvasViewContainer parent_instance;
+ NautilusCanvasViewContainer parent_instance;
};
G_DEFINE_TYPE (NautilusDesktopCanvasViewContainer, nautilus_desktop_canvas_view_container, NAUTILUS_TYPE_CANVAS_VIEW_CONTAINER)
@@ -33,50 +33,65 @@ G_DEFINE_TYPE (NautilusDesktopCanvasViewContainer, nautilus_desktop_canvas_view_
* 3) other
* 4) trash link
*/
-typedef enum {
- SORT_HOME_LINK,
- SORT_NETWORK_LINK,
- SORT_MOUNT_LINK,
- SORT_OTHER,
- SORT_TRASH_LINK
+typedef enum
+{
+ SORT_HOME_LINK,
+ SORT_NETWORK_LINK,
+ SORT_MOUNT_LINK,
+ SORT_OTHER,
+ SORT_TRASH_LINK
} SortCategory;
static SortCategory
get_sort_category (NautilusFile *file)
{
- NautilusDesktopLink *link;
- SortCategory category;
+ NautilusDesktopLink *link;
+ SortCategory category;
- category = SORT_OTHER;
+ category = SORT_OTHER;
- if (NAUTILUS_IS_DESKTOP_ICON_FILE (file))
+ if (NAUTILUS_IS_DESKTOP_ICON_FILE (file))
{
- link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
- if (link != NULL)
+ link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+ if (link != NULL)
{
- switch (nautilus_desktop_link_get_link_type (link))
+ switch (nautilus_desktop_link_get_link_type (link))
{
- case NAUTILUS_DESKTOP_LINK_HOME:
- category = SORT_HOME_LINK;
+ case NAUTILUS_DESKTOP_LINK_HOME:
+ {
+ category = SORT_HOME_LINK;
+ }
break;
- case NAUTILUS_DESKTOP_LINK_MOUNT:
- category = SORT_MOUNT_LINK;
+
+ case NAUTILUS_DESKTOP_LINK_MOUNT:
+ {
+ category = SORT_MOUNT_LINK;
+ }
break;
- case NAUTILUS_DESKTOP_LINK_TRASH:
- category = SORT_TRASH_LINK;
+
+ case NAUTILUS_DESKTOP_LINK_TRASH:
+ {
+ category = SORT_TRASH_LINK;
+ }
break;
- case NAUTILUS_DESKTOP_LINK_NETWORK:
- category = SORT_NETWORK_LINK;
+
+ case NAUTILUS_DESKTOP_LINK_NETWORK:
+ {
+ category = SORT_NETWORK_LINK;
+ }
break;
- default:
- category = SORT_OTHER;
+
+ default:
+ {
+ category = SORT_OTHER;
+ }
break;
- }
- g_object_unref (link);
- }
+ }
+ g_object_unref (link);
+ }
}
- return category;
+ return category;
}
static int
@@ -84,36 +99,36 @@ real_compare_icons (NautilusCanvasContainer *container,
NautilusCanvasIconData *data_a,
NautilusCanvasIconData *data_b)
{
- NautilusFile *file_a;
- NautilusFile *file_b;
- NautilusFilesView *directory_view;
- SortCategory category_a, category_b;
+ NautilusFile *file_a;
+ NautilusFile *file_b;
+ NautilusFilesView *directory_view;
+ SortCategory category_a, category_b;
- file_a = (NautilusFile *) data_a;
- file_b = (NautilusFile *) data_b;
+ file_a = (NautilusFile *) data_a;
+ file_b = (NautilusFile *) data_b;
- directory_view = NAUTILUS_FILES_VIEW (NAUTILUS_CANVAS_VIEW_CONTAINER (container)->view);
- g_return_val_if_fail (directory_view != NULL, 0);
+ directory_view = NAUTILUS_FILES_VIEW (NAUTILUS_CANVAS_VIEW_CONTAINER (container)->view);
+ g_return_val_if_fail (directory_view != NULL, 0);
- category_a = get_sort_category (file_a);
- category_b = get_sort_category (file_b);
+ category_a = get_sort_category (file_a);
+ category_b = get_sort_category (file_b);
- if (category_a == category_b)
+ if (category_a == category_b)
{
- return nautilus_file_compare_for_sort (file_a,
- file_b,
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- nautilus_files_view_should_sort_directories_first (directory_view),
- FALSE);
+ return nautilus_file_compare_for_sort (file_a,
+ file_b,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ nautilus_files_view_should_sort_directories_first (directory_view),
+ FALSE);
}
- if (category_a < category_b)
+ if (category_a < category_b)
{
- return -1;
+ return -1;
}
- else
+ else
{
- return +1;
+ return +1;
}
}
@@ -124,73 +139,74 @@ real_get_icon_text (NautilusCanvasContainer *container,
char **additional_text,
gboolean include_invisible)
{
- NautilusFile *file;
- gboolean use_additional;
+ NautilusFile *file;
+ gboolean use_additional;
- file = NAUTILUS_FILE (data);
+ file = NAUTILUS_FILE (data);
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (editable_text != NULL);
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (editable_text != NULL);
- use_additional = (additional_text != NULL);
+ use_additional = (additional_text != NULL);
- /* Strip the suffix for nautilus object xml files. */
- *editable_text = nautilus_file_get_display_name (file);
+ /* Strip the suffix for nautilus object xml files. */
+ *editable_text = nautilus_file_get_display_name (file);
- if (!use_additional) {
- return;
- }
+ if (!use_additional)
+ {
+ return;
+ }
- if (NAUTILUS_IS_DESKTOP_ICON_FILE (file) ||
- nautilus_file_is_nautilus_link (file))
+ if (NAUTILUS_IS_DESKTOP_ICON_FILE (file) ||
+ nautilus_file_is_nautilus_link (file))
{
- /* Don't show the normal extra information for desktop icons,
- * or desktop files, it doesn't make sense.
- */
- *additional_text = NULL;
+ /* Don't show the normal extra information for desktop icons,
+ * or desktop files, it doesn't make sense.
+ */
+ *additional_text = NULL;
- return;
+ return;
}
- return NAUTILUS_CANVAS_CONTAINER_CLASS (nautilus_desktop_canvas_view_container_parent_class)->get_icon_text (container,
- data,
- editable_text,
- additional_text,
- include_invisible);
+ return NAUTILUS_CANVAS_CONTAINER_CLASS (nautilus_desktop_canvas_view_container_parent_class)->get_icon_text (container,
+ data,
+ editable_text,
+ additional_text,
+ include_invisible);
}
static char *
real_get_icon_description (NautilusCanvasContainer *container,
NautilusCanvasIconData *data)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = NAUTILUS_FILE (data);
- g_assert (NAUTILUS_IS_FILE (file));
+ file = NAUTILUS_FILE (data);
+ g_assert (NAUTILUS_IS_FILE (file));
- if (NAUTILUS_IS_DESKTOP_ICON_FILE (file))
+ if (NAUTILUS_IS_DESKTOP_ICON_FILE (file))
{
- return NULL;
+ return NULL;
}
- return NAUTILUS_CANVAS_CONTAINER_CLASS (nautilus_desktop_canvas_view_container_parent_class)->get_icon_description (container,
- data);
+ return NAUTILUS_CANVAS_CONTAINER_CLASS (nautilus_desktop_canvas_view_container_parent_class)->get_icon_description (container,
+ data);
}
NautilusDesktopCanvasViewContainer *
nautilus_desktop_canvas_view_container_new (void)
{
- return g_object_new (NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW_CONTAINER, NULL);
+ return g_object_new (NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW_CONTAINER, NULL);
}
static void
nautilus_desktop_canvas_view_container_class_init (NautilusDesktopCanvasViewContainerClass *klass)
{
- NautilusCanvasContainerClass *container_class = NAUTILUS_CANVAS_CONTAINER_CLASS (klass);
+ NautilusCanvasContainerClass *container_class = NAUTILUS_CANVAS_CONTAINER_CLASS (klass);
- container_class->get_icon_description = real_get_icon_description;
- container_class->get_icon_text = real_get_icon_text;
- container_class->compare_icons = real_compare_icons;
+ container_class->get_icon_description = real_get_icon_description;
+ container_class->get_icon_text = real_get_icon_text;
+ container_class->compare_icons = real_compare_icons;
}
static void
diff --git a/nautilus-desktop/nautilus-desktop-canvas-view.c b/nautilus-desktop/nautilus-desktop-canvas-view.c
index 4aa618aed..772c859fa 100644
--- a/nautilus-desktop/nautilus-desktop-canvas-view.c
+++ b/nautilus-desktop/nautilus-desktop-canvas-view.c
@@ -1,26 +1,25 @@
-
/* nautilus-desktop-canvas-view.c - implementation of canvas view for managing the desktop.
-
- Copyright (C) 2000, 2001 Eazel, Inc.mou
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Mike Engber <engber@eazel.com>
- Gene Z. Ragan <gzr@eazel.com>
- Miguel de Icaza <miguel@ximian.com>
-*/
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.mou
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Mike Engber <engber@eazel.com>
+ * Gene Z. Ragan <gzr@eazel.com>
+ * Miguel de Icaza <miguel@ximian.com>
+ */
#include <config.h>
#include <stdlib.h>
@@ -61,685 +60,726 @@
struct NautilusDesktopCanvasViewDetails
{
- GdkWindow *root_window;
+ GdkWindow *root_window;
};
-static void default_zoom_level_changed (gpointer user_data);
-static void real_update_context_menus (NautilusFilesView *view);
-static char* real_get_backing_uri (NautilusFilesView *view);
-static void real_check_empty_states (NautilusFilesView *view);
-static void nautilus_desktop_canvas_view_update_canvas_container_fonts (NautilusDesktopCanvasView *view);
-static void font_changed_callback (gpointer callback_data);
+static void default_zoom_level_changed (gpointer user_data);
+static void real_update_context_menus (NautilusFilesView *view);
+static char *real_get_backing_uri (NautilusFilesView *view);
+static void real_check_empty_states (NautilusFilesView *view);
+static void nautilus_desktop_canvas_view_update_canvas_container_fonts (NautilusDesktopCanvasView *view);
+static void font_changed_callback (gpointer callback_data);
G_DEFINE_TYPE (NautilusDesktopCanvasView, nautilus_desktop_canvas_view, NAUTILUS_TYPE_CANVAS_VIEW)
static char *desktop_directory;
-#define get_canvas_container(w) nautilus_canvas_view_get_canvas_container(NAUTILUS_CANVAS_VIEW (w))
+#define get_canvas_container(w) nautilus_canvas_view_get_canvas_container (NAUTILUS_CANVAS_VIEW (w))
-#define POPUP_PATH_CANVAS_APPEARANCE "/selection/Canvas Appearance Items"
+#define POPUP_PATH_CANVAS_APPEARANCE "/selection/Canvas Appearance Items"
static void
canvas_container_set_workarea (NautilusCanvasContainer *canvas_container,
- GdkScreen *screen,
- long *workareas,
- int n_items)
+ GdkScreen *screen,
+ long *workareas,
+ int n_items)
{
- int left, right, top, bottom;
- int screen_width, screen_height;
- int scale;
- int i;
+ int left, right, top, bottom;
+ int screen_width, screen_height;
+ int scale;
+ int i;
- left = right = top = bottom = 0;
+ left = right = top = bottom = 0;
- screen_width = gdk_screen_get_width (screen);
- screen_height = gdk_screen_get_height (screen);
+ screen_width = gdk_screen_get_width (screen);
+ screen_height = gdk_screen_get_height (screen);
- scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
- scale = scale ? scale : 1;
+ scale = gdk_window_get_scale_factor (gdk_screen_get_root_window (screen));
+ scale = scale ? scale : 1;
- for (i = 0; i < n_items; i += 4) {
- int x = workareas [i] / scale;
- int y = workareas [i + 1] / scale;
- int width = workareas [i + 2] / scale;
- int height = workareas [i + 3] / scale;
+ for (i = 0; i < n_items; i += 4)
+ {
+ int x = workareas [i] / scale;
+ int y = workareas [i + 1] / scale;
+ int width = workareas [i + 2] / scale;
+ int height = workareas [i + 3] / scale;
- if ((x + width) > screen_width || (y + height) > screen_height)
- continue;
+ if ((x + width) > screen_width || (y + height) > screen_height)
+ {
+ continue;
+ }
- left = MAX (left, x);
- right = MAX (right, screen_width - width - x);
- top = MAX (top, y);
- bottom = MAX (bottom, screen_height - height - y);
- }
+ left = MAX (left, x);
+ right = MAX (right, screen_width - width - x);
+ top = MAX (top, y);
+ bottom = MAX (bottom, screen_height - height - y);
+ }
- nautilus_canvas_container_set_margins (canvas_container,
- left, right, top, bottom);
+ nautilus_canvas_container_set_margins (canvas_container,
+ left, right, top, bottom);
}
static void
net_workarea_changed (NautilusDesktopCanvasView *canvas_view,
- GdkWindow *window)
+ GdkWindow *window)
{
- long *nworkareas = NULL;
- long *workareas = NULL;
- GdkAtom type_returned;
- int format_returned;
- int length_returned;
- NautilusCanvasContainer *canvas_container;
- GdkScreen *screen;
-
- g_return_if_fail (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (canvas_view));
-
- canvas_container = get_canvas_container (canvas_view);
-
- /* Find the number of desktops so we know how long the
- * workareas array is going to be (each desktop will have four
- * elements in the workareas array describing
- * x,y,width,height) */
- gdk_error_trap_push ();
- if (!gdk_property_get (window,
- gdk_atom_intern ("_NET_NUMBER_OF_DESKTOPS", FALSE),
- gdk_x11_xatom_to_atom (XA_CARDINAL),
- 0, 4, FALSE,
- &type_returned,
- &format_returned,
- &length_returned,
- (guchar **) &nworkareas)) {
- g_warning("Can not calculate _NET_NUMBER_OF_DESKTOPS");
- }
- if (gdk_error_trap_pop()
- || nworkareas == NULL
- || type_returned != gdk_x11_xatom_to_atom (XA_CARDINAL)
- || format_returned != 32)
- g_warning("Can not calculate _NET_NUMBER_OF_DESKTOPS");
-
- /* Note : gdk_property_get() is broken (API documents admit
- * this). As a length argument, it expects the number of
- * _bytes_ of data you require. Internally, gdk_property_get
- * converts that value to a count of 32 bit (4 byte) elements.
- * However, the length returned is in bytes, but is calculated
- * via the count of returned elements * sizeof(long). This
- * means on a 64 bit system, the number of bytes you have to
- * request does not correspond to the number of bytes you get
- * back, and is the reason for the workaround below.
- */
- gdk_error_trap_push ();
- if (nworkareas == NULL || (*nworkareas < 1)
- || !gdk_property_get (window,
- gdk_atom_intern ("_NET_WORKAREA", FALSE),
- gdk_x11_xatom_to_atom (XA_CARDINAL),
- 0, ((*nworkareas) * 4 * 4), FALSE,
- &type_returned,
- &format_returned,
- &length_returned,
- (guchar **) &workareas)) {
- g_warning("Can not get _NET_WORKAREA");
- workareas = NULL;
- }
-
- if (gdk_error_trap_pop ()
- || workareas == NULL
- || type_returned != gdk_x11_xatom_to_atom (XA_CARDINAL)
- || ((*nworkareas) * 4 * sizeof(long)) != length_returned
- || format_returned != 32) {
- g_warning("Can not determine workarea, guessing at layout");
- nautilus_canvas_container_set_margins (canvas_container,
- 0, 0, 0, 0);
- } else {
- screen = gdk_window_get_screen (window);
-
- canvas_container_set_workarea
- (canvas_container, screen, workareas, length_returned / sizeof (long));
- }
-
- if (nworkareas != NULL)
- g_free (nworkareas);
-
- if (workareas != NULL)
- g_free (workareas);
+ long *nworkareas = NULL;
+ long *workareas = NULL;
+ GdkAtom type_returned;
+ int format_returned;
+ int length_returned;
+ NautilusCanvasContainer *canvas_container;
+ GdkScreen *screen;
+
+ g_return_if_fail (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (canvas_view));
+
+ canvas_container = get_canvas_container (canvas_view);
+
+ /* Find the number of desktops so we know how long the
+ * workareas array is going to be (each desktop will have four
+ * elements in the workareas array describing
+ * x,y,width,height) */
+ gdk_error_trap_push ();
+ if (!gdk_property_get (window,
+ gdk_atom_intern ("_NET_NUMBER_OF_DESKTOPS", FALSE),
+ gdk_x11_xatom_to_atom (XA_CARDINAL),
+ 0, 4, FALSE,
+ &type_returned,
+ &format_returned,
+ &length_returned,
+ (guchar **) &nworkareas))
+ {
+ g_warning ("Can not calculate _NET_NUMBER_OF_DESKTOPS");
+ }
+ if (gdk_error_trap_pop ()
+ || nworkareas == NULL
+ || type_returned != gdk_x11_xatom_to_atom (XA_CARDINAL)
+ || format_returned != 32)
+ {
+ g_warning ("Can not calculate _NET_NUMBER_OF_DESKTOPS");
+ }
+
+ /* Note : gdk_property_get() is broken (API documents admit
+ * this). As a length argument, it expects the number of
+ * _bytes_ of data you require. Internally, gdk_property_get
+ * converts that value to a count of 32 bit (4 byte) elements.
+ * However, the length returned is in bytes, but is calculated
+ * via the count of returned elements * sizeof(long). This
+ * means on a 64 bit system, the number of bytes you have to
+ * request does not correspond to the number of bytes you get
+ * back, and is the reason for the workaround below.
+ */
+ gdk_error_trap_push ();
+ if (nworkareas == NULL || (*nworkareas < 1)
+ || !gdk_property_get (window,
+ gdk_atom_intern ("_NET_WORKAREA", FALSE),
+ gdk_x11_xatom_to_atom (XA_CARDINAL),
+ 0, ((*nworkareas) * 4 * 4), FALSE,
+ &type_returned,
+ &format_returned,
+ &length_returned,
+ (guchar **) &workareas))
+ {
+ g_warning ("Can not get _NET_WORKAREA");
+ workareas = NULL;
+ }
+
+ if (gdk_error_trap_pop ()
+ || workareas == NULL
+ || type_returned != gdk_x11_xatom_to_atom (XA_CARDINAL)
+ || ((*nworkareas) * 4 * sizeof (long)) != length_returned
+ || format_returned != 32)
+ {
+ g_warning ("Can not determine workarea, guessing at layout");
+ nautilus_canvas_container_set_margins (canvas_container,
+ 0, 0, 0, 0);
+ }
+ else
+ {
+ screen = gdk_window_get_screen (window);
+
+ canvas_container_set_workarea
+ (canvas_container, screen, workareas, length_returned / sizeof (long));
+ }
+
+ if (nworkareas != NULL)
+ {
+ g_free (nworkareas);
+ }
+
+ if (workareas != NULL)
+ {
+ g_free (workareas);
+ }
}
static GdkFilterReturn
desktop_canvas_view_property_filter (GdkXEvent *gdk_xevent,
- GdkEvent *event,
- gpointer data)
+ GdkEvent *event,
+ gpointer data)
{
- XEvent *xevent = gdk_xevent;
- NautilusDesktopCanvasView *canvas_view;
-
- canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (data);
-
- switch (xevent->type) {
- case PropertyNotify:
- if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_WORKAREA"))
- net_workarea_changed (canvas_view, event->any.window);
- break;
- default:
- break;
- }
-
- return GDK_FILTER_CONTINUE;
+ XEvent *xevent = gdk_xevent;
+ NautilusDesktopCanvasView *canvas_view;
+
+ canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (data);
+
+ switch (xevent->type)
+ {
+ case PropertyNotify:
+ {
+ if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_WORKAREA"))
+ {
+ net_workarea_changed (canvas_view, event->any.window);
+ }
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ return GDK_FILTER_CONTINUE;
}
static guint
real_get_id (NautilusFilesView *view)
{
- return NAUTILUS_VIEW_DESKTOP_ID;
+ return NAUTILUS_VIEW_DESKTOP_ID;
}
static void
nautilus_desktop_canvas_view_dispose (GObject *object)
{
- NautilusDesktopCanvasView *canvas_view;
+ NautilusDesktopCanvasView *canvas_view;
- canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (object);
+ canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (object);
- g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
- default_zoom_level_changed,
- canvas_view);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- font_changed_callback,
- canvas_view);
- g_signal_handlers_disconnect_by_func (gnome_lockdown_preferences,
- nautilus_files_view_update_context_menus,
- canvas_view);
+ g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
+ default_zoom_level_changed,
+ canvas_view);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ font_changed_callback,
+ canvas_view);
+ g_signal_handlers_disconnect_by_func (gnome_lockdown_preferences,
+ nautilus_files_view_update_context_menus,
+ canvas_view);
- G_OBJECT_CLASS (nautilus_desktop_canvas_view_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_desktop_canvas_view_parent_class)->dispose (object);
}
static void
nautilus_desktop_canvas_view_end_loading (NautilusFilesView *view,
- gboolean all_files_seen)
+ gboolean all_files_seen)
{
- gboolean needs_reorganization;
- gchar *stored_size_icon;
- guint current_zoom;
- guint current_icon_size;
- gchar *current_icon_size_string;
- NautilusFile *file;
-
- NAUTILUS_FILES_VIEW_CLASS (nautilus_desktop_canvas_view_parent_class)->end_loading (view, all_files_seen);
-
- if (!all_files_seen)
- return;
-
- file = nautilus_files_view_get_directory_as_file (view);
- g_return_if_fail (file != NULL);
-
- stored_size_icon = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE, NULL);
- current_zoom = nautilus_canvas_container_get_zoom_level (get_canvas_container (view));
- current_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (current_zoom);
- needs_reorganization = stored_size_icon == NULL || atoi (stored_size_icon) != current_icon_size;
-
- if (needs_reorganization) {
- current_icon_size_string = g_strdup_printf ("%d", current_icon_size);
- nautilus_canvas_view_clean_up_by_name (NAUTILUS_CANVAS_VIEW (view));
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
- NULL, current_icon_size_string);
-
- g_free (current_icon_size_string);
- }
-
- g_free (stored_size_icon);
+ gboolean needs_reorganization;
+ gchar *stored_size_icon;
+ guint current_zoom;
+ guint current_icon_size;
+ gchar *current_icon_size_string;
+ NautilusFile *file;
+
+ NAUTILUS_FILES_VIEW_CLASS (nautilus_desktop_canvas_view_parent_class)->end_loading (view, all_files_seen);
+
+ if (!all_files_seen)
+ {
+ return;
+ }
+
+ file = nautilus_files_view_get_directory_as_file (view);
+ g_return_if_fail (file != NULL);
+
+ stored_size_icon = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE, NULL);
+ current_zoom = nautilus_canvas_container_get_zoom_level (get_canvas_container (view));
+ current_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (current_zoom);
+ needs_reorganization = stored_size_icon == NULL || atoi (stored_size_icon) != current_icon_size;
+
+ if (needs_reorganization)
+ {
+ current_icon_size_string = g_strdup_printf ("%d", current_icon_size);
+ nautilus_canvas_view_clean_up_by_name (NAUTILUS_CANVAS_VIEW (view));
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
+ NULL, current_icon_size_string);
+
+ g_free (current_icon_size_string);
+ }
+
+ g_free (stored_size_icon);
}
static NautilusCanvasContainer *
real_create_canvas_container (NautilusCanvasView *canvas_view)
{
- return NAUTILUS_CANVAS_CONTAINER (nautilus_desktop_canvas_view_container_new ());
+ return NAUTILUS_CANVAS_CONTAINER (nautilus_desktop_canvas_view_container_new ());
}
static void
nautilus_desktop_canvas_view_class_init (NautilusDesktopCanvasViewClass *class)
{
- NautilusFilesViewClass *vclass;
- NautilusCanvasViewClass *canvas_class;
+ NautilusFilesViewClass *vclass;
+ NautilusCanvasViewClass *canvas_class;
- vclass = NAUTILUS_FILES_VIEW_CLASS (class);
- canvas_class = NAUTILUS_CANVAS_VIEW_CLASS (class);
+ vclass = NAUTILUS_FILES_VIEW_CLASS (class);
+ canvas_class = NAUTILUS_CANVAS_VIEW_CLASS (class);
- G_OBJECT_CLASS (class)->dispose = nautilus_desktop_canvas_view_dispose;
+ G_OBJECT_CLASS (class)->dispose = nautilus_desktop_canvas_view_dispose;
- canvas_class->create_canvas_container = real_create_canvas_container;
+ canvas_class->create_canvas_container = real_create_canvas_container;
- vclass->update_context_menus = real_update_context_menus;
- vclass->get_view_id = real_get_id;
- vclass->end_loading = nautilus_desktop_canvas_view_end_loading;
- vclass->get_backing_uri = real_get_backing_uri;
- vclass->check_empty_states = real_check_empty_states;
+ vclass->update_context_menus = real_update_context_menus;
+ vclass->get_view_id = real_get_id;
+ vclass->end_loading = nautilus_desktop_canvas_view_end_loading;
+ vclass->get_backing_uri = real_get_backing_uri;
+ vclass->check_empty_states = real_check_empty_states;
- g_type_class_add_private (class, sizeof (NautilusDesktopCanvasViewDetails));
+ g_type_class_add_private (class, sizeof (NautilusDesktopCanvasViewDetails));
}
static void
-unrealized_callback (GtkWidget *widget, NautilusDesktopCanvasView *desktop_canvas_view)
+unrealized_callback (GtkWidget *widget,
+ NautilusDesktopCanvasView *desktop_canvas_view)
{
- g_return_if_fail (desktop_canvas_view->details->root_window != NULL);
+ g_return_if_fail (desktop_canvas_view->details->root_window != NULL);
- /* Remove the property filter */
- gdk_window_remove_filter (desktop_canvas_view->details->root_window,
- desktop_canvas_view_property_filter,
- desktop_canvas_view);
- desktop_canvas_view->details->root_window = NULL;
+ /* Remove the property filter */
+ gdk_window_remove_filter (desktop_canvas_view->details->root_window,
+ desktop_canvas_view_property_filter,
+ desktop_canvas_view);
+ desktop_canvas_view->details->root_window = NULL;
}
static void
-realized_callback (GtkWidget *widget, NautilusDesktopCanvasView *desktop_canvas_view)
+realized_callback (GtkWidget *widget,
+ NautilusDesktopCanvasView *desktop_canvas_view)
{
- GdkWindow *root_window;
- GdkScreen *screen;
+ GdkWindow *root_window;
+ GdkScreen *screen;
- g_return_if_fail (desktop_canvas_view->details->root_window == NULL);
+ g_return_if_fail (desktop_canvas_view->details->root_window == NULL);
- screen = gtk_widget_get_screen (widget);
- root_window = gdk_screen_get_root_window (screen);
+ screen = gtk_widget_get_screen (widget);
+ root_window = gdk_screen_get_root_window (screen);
- desktop_canvas_view->details->root_window = root_window;
+ desktop_canvas_view->details->root_window = root_window;
- /* Read out the workarea geometry and update the icon container accordingly */
- net_workarea_changed (desktop_canvas_view, root_window);
+ /* Read out the workarea geometry and update the icon container accordingly */
+ net_workarea_changed (desktop_canvas_view, root_window);
- /* Setup the property filter */
- gdk_window_set_events (root_window, GDK_PROPERTY_CHANGE_MASK);
- gdk_window_add_filter (root_window,
- desktop_canvas_view_property_filter,
- desktop_canvas_view);
+ /* Setup the property filter */
+ gdk_window_set_events (root_window, GDK_PROPERTY_CHANGE_MASK);
+ gdk_window_add_filter (root_window,
+ desktop_canvas_view_property_filter,
+ desktop_canvas_view);
}
static void
-desktop_canvas_container_realize (GtkWidget *widget,
- NautilusDesktopCanvasView *desktop_canvas_view)
+desktop_canvas_container_realize (GtkWidget *widget,
+ NautilusDesktopCanvasView *desktop_canvas_view)
{
- GdkWindow *bin_window;
- GdkRGBA transparent = { 0, 0, 0, 0 };
+ GdkWindow *bin_window;
+ GdkRGBA transparent = { 0, 0, 0, 0 };
- bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
- gdk_window_set_background_rgba (bin_window, &transparent);
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (widget));
+ gdk_window_set_background_rgba (bin_window, &transparent);
}
static NautilusCanvasZoomLevel
get_default_zoom_level (void)
{
- NautilusCanvasZoomLevel default_zoom_level;
+ NautilusCanvasZoomLevel default_zoom_level;
- default_zoom_level = g_settings_get_enum (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL);
+ default_zoom_level = g_settings_get_enum (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL);
- return CLAMP (default_zoom_level, NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
+ return CLAMP (default_zoom_level, NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
}
static void
set_up_zoom_level (NautilusDesktopCanvasView *desktop_canvas_view)
{
- NautilusCanvasZoomLevel new_level;
+ NautilusCanvasZoomLevel new_level;
- new_level = get_default_zoom_level ();
- nautilus_canvas_container_set_zoom_level (get_canvas_container (desktop_canvas_view),
- new_level);
+ new_level = get_default_zoom_level ();
+ nautilus_canvas_container_set_zoom_level (get_canvas_container (desktop_canvas_view),
+ new_level);
}
static void
default_zoom_level_changed (gpointer user_data)
{
- NautilusCanvasZoomLevel new_level;
- NautilusDesktopCanvasView *desktop_canvas_view;
- gint new_icon_size;
- NautilusFile *file;
- gchar *new_icon_size_string;
-
- desktop_canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (user_data);
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (user_data));
- new_level = get_default_zoom_level ();
- new_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (new_level);
- new_icon_size_string = g_strdup_printf ("%d", new_icon_size);
-
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
- NULL, new_icon_size_string);
- set_up_zoom_level (desktop_canvas_view);
-
- g_free (new_icon_size_string);
+ NautilusCanvasZoomLevel new_level;
+ NautilusDesktopCanvasView *desktop_canvas_view;
+ gint new_icon_size;
+ NautilusFile *file;
+ gchar *new_icon_size_string;
+
+ desktop_canvas_view = NAUTILUS_DESKTOP_CANVAS_VIEW (user_data);
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (user_data));
+ new_level = get_default_zoom_level ();
+ new_icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (new_level);
+ new_icon_size_string = g_strdup_printf ("%d", new_icon_size);
+
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
+ NULL, new_icon_size_string);
+ set_up_zoom_level (desktop_canvas_view);
+
+ g_free (new_icon_size_string);
}
static void
font_changed_callback (gpointer callback_data)
{
- g_return_if_fail (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (callback_data));
-
- nautilus_desktop_canvas_view_update_canvas_container_fonts (NAUTILUS_DESKTOP_CANVAS_VIEW (callback_data));
+ g_return_if_fail (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (callback_data));
+
+ nautilus_desktop_canvas_view_update_canvas_container_fonts (NAUTILUS_DESKTOP_CANVAS_VIEW (callback_data));
}
static void
nautilus_desktop_canvas_view_update_canvas_container_fonts (NautilusDesktopCanvasView *canvas_view)
{
- NautilusCanvasContainer *canvas_container;
- char *font;
+ NautilusCanvasContainer *canvas_container;
+ char *font;
- canvas_container = get_canvas_container (canvas_view);
- g_assert (canvas_container != NULL);
+ canvas_container = get_canvas_container (canvas_view);
+ g_assert (canvas_container != NULL);
- font = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_FONT);
+ font = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_FONT);
- nautilus_canvas_container_set_font (canvas_container, font);
+ nautilus_canvas_container_set_font (canvas_container, font);
- g_free (font);
+ g_free (font);
}
static const gchar *
-get_control_center_command (const gchar ** params_out)
+get_control_center_command (const gchar **params_out)
{
- gchar *path;
- const gchar *retval;
- const gchar *params;
- const gchar *xdg_current_desktop;
- gchar **desktop_names;
- gboolean is_unity;
- int i;
-
- path = NULL;
- retval = NULL;
- params = NULL;
-
- xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
-
- /* Detect the Unity-based environments */
- is_unity = FALSE;
- if (xdg_current_desktop != NULL) {
- desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
- for (i = 0; desktop_names[i]; ++i) {
- if (!g_strcmp0 (desktop_names[i], "Unity")) {
- is_unity = TRUE;
- break;
- }
- }
- g_strfreev (desktop_names);
- }
-
- /* In Unity look for unity-control-center */
- if (is_unity) {
- path = g_find_program_in_path ("unity-control-center");
- if (path != NULL) {
- retval = "unity-control-center";
- params = "appearance";
- goto out;
- }
- }
-
- /* Otherwise look for gnome-control-center */
- path = g_find_program_in_path ("gnome-control-center");
- if (path != NULL) {
- retval = "gnome-control-center";
- params = "background";
- }
-
- out:
- g_free (path);
- if (params_out != NULL) {
- *params_out = params;
- }
-
- return retval;
+ gchar *path;
+ const gchar *retval;
+ const gchar *params;
+ const gchar *xdg_current_desktop;
+ gchar **desktop_names;
+ gboolean is_unity;
+ int i;
+
+ path = NULL;
+ retval = NULL;
+ params = NULL;
+
+ xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
+
+ /* Detect the Unity-based environments */
+ is_unity = FALSE;
+ if (xdg_current_desktop != NULL)
+ {
+ desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
+ for (i = 0; desktop_names[i]; ++i)
+ {
+ if (!g_strcmp0 (desktop_names[i], "Unity"))
+ {
+ is_unity = TRUE;
+ break;
+ }
+ }
+ g_strfreev (desktop_names);
+ }
+
+ /* In Unity look for unity-control-center */
+ if (is_unity)
+ {
+ path = g_find_program_in_path ("unity-control-center");
+ if (path != NULL)
+ {
+ retval = "unity-control-center";
+ params = "appearance";
+ goto out;
+ }
+ }
+
+ /* Otherwise look for gnome-control-center */
+ path = g_find_program_in_path ("gnome-control-center");
+ if (path != NULL)
+ {
+ retval = "gnome-control-center";
+ params = "background";
+ }
+
+out:
+ g_free (path);
+ if (params_out != NULL)
+ {
+ *params_out = params;
+ }
+
+ return retval;
}
static void
action_change_background (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- const gchar *control_center_cmd, *params;
+ const gchar *control_center_cmd, *params;
- g_assert (NAUTILUS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_FILES_VIEW (user_data));
- control_center_cmd = get_control_center_command (&params);
- if (control_center_cmd == NULL) {
- return;
- }
+ control_center_cmd = get_control_center_command (&params);
+ if (control_center_cmd == NULL)
+ {
+ return;
+ }
- nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (user_data)),
- control_center_cmd,
- FALSE,
- params, NULL);
+ nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (user_data)),
+ control_center_cmd,
+ FALSE,
+ params, NULL);
}
static void
action_empty_trash (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- nautilus_file_operations_empty_trash (GTK_WIDGET (user_data));
+ nautilus_file_operations_empty_trash (GTK_WIDGET (user_data));
}
static void
action_stretch (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- nautilus_canvas_container_show_stretch_handles
- (get_canvas_container (user_data));
+ nautilus_canvas_container_show_stretch_handles
+ (get_canvas_container (user_data));
}
static void
action_unstretch (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- nautilus_canvas_container_unstretch (get_canvas_container (user_data));
+ nautilus_canvas_container_unstretch (get_canvas_container (user_data));
}
static void
action_organize_desktop_by_name (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- nautilus_canvas_view_clean_up_by_name (NAUTILUS_CANVAS_VIEW (user_data));
+ nautilus_canvas_view_clean_up_by_name (NAUTILUS_CANVAS_VIEW (user_data));
}
static gboolean
trash_link_is_selection (NautilusFilesView *view)
{
- GList *selection;
- NautilusDesktopLink *link;
- gboolean result;
-
- result = FALSE;
-
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
-
- if ((g_list_length (selection) == 1) &&
- NAUTILUS_IS_DESKTOP_ICON_FILE (selection->data)) {
- link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (selection->data));
- /* link may be NULL if the link was recently removed (unmounted) */
- if (link != NULL &&
- nautilus_desktop_link_get_link_type (link) == NAUTILUS_DESKTOP_LINK_TRASH) {
- result = TRUE;
- }
- if (link) {
- g_object_unref (link);
- }
- }
-
- nautilus_file_list_free (selection);
-
- return result;
+ GList *selection;
+ NautilusDesktopLink *link;
+ gboolean result;
+
+ result = FALSE;
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+
+ if ((g_list_length (selection) == 1) &&
+ NAUTILUS_IS_DESKTOP_ICON_FILE (selection->data))
+ {
+ link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (selection->data));
+ /* link may be NULL if the link was recently removed (unmounted) */
+ if (link != NULL &&
+ nautilus_desktop_link_get_link_type (link) == NAUTILUS_DESKTOP_LINK_TRASH)
+ {
+ result = TRUE;
+ }
+ if (link)
+ {
+ g_object_unref (link);
+ }
+ }
+
+ nautilus_file_list_free (selection);
+
+ return result;
}
-const GActionEntry desktop_view_entries[] = {
- { "change-background", action_change_background },
- { "organize-desktop-by-name", action_organize_desktop_by_name },
- { "empty-trash", action_empty_trash },
- { "stretch", action_stretch },
- { "unstretch", action_unstretch },
+const GActionEntry desktop_view_entries[] =
+{
+ { "change-background", action_change_background },
+ { "organize-desktop-by-name", action_organize_desktop_by_name },
+ { "empty-trash", action_empty_trash },
+ { "stretch", action_stretch },
+ { "unstretch", action_unstretch },
};
static void
real_check_empty_states (NautilusFilesView *view)
{
- /* Do nothing */
+ /* Do nothing */
}
-static char*
+static char *
real_get_backing_uri (NautilusFilesView *view)
{
- gchar *uri;
- NautilusDirectory *directory;
- NautilusDirectory *model;
+ gchar *uri;
+ NautilusDirectory *directory;
+ NautilusDirectory *model;
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- model = nautilus_files_view_get_model (view);
+ model = nautilus_files_view_get_model (view);
- if (model == NULL) {
- return NULL;
- }
+ if (model == NULL)
+ {
+ return NULL;
+ }
- directory = nautilus_desktop_directory_get_real_directory (NAUTILUS_DESKTOP_DIRECTORY (model));
+ directory = nautilus_desktop_directory_get_real_directory (NAUTILUS_DESKTOP_DIRECTORY (model));
- uri = nautilus_directory_get_uri (directory);
+ uri = nautilus_directory_get_uri (directory);
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
- return uri;
+ return uri;
}
static void
real_update_context_menus (NautilusFilesView *view)
{
- NautilusCanvasContainer *canvas_container;
- NautilusDesktopCanvasView *desktop_view;
- GAction *action;
- GActionGroup *view_action_group;
- GList *selection;
- int selection_count;
+ NautilusCanvasContainer *canvas_container;
+ NautilusDesktopCanvasView *desktop_view;
+ GAction *action;
+ GActionGroup *view_action_group;
+ GList *selection;
+ int selection_count;
- g_assert (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (view));
+ g_assert (NAUTILUS_IS_DESKTOP_CANVAS_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (nautilus_desktop_canvas_view_parent_class)->update_context_menus (view);
+ NAUTILUS_FILES_VIEW_CLASS (nautilus_desktop_canvas_view_parent_class)->update_context_menus (view);
- view_action_group = nautilus_files_view_get_action_group (view);
- desktop_view = NAUTILUS_DESKTOP_CANVAS_VIEW (view);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- selection_count = g_list_length (selection);
+ view_action_group = nautilus_files_view_get_action_group (view);
+ desktop_view = NAUTILUS_DESKTOP_CANVAS_VIEW (view);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection_count = g_list_length (selection);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "empty-trash");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), trash_link_is_selection (view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "empty-trash");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), trash_link_is_selection (view));
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "keep-aligned");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "keep-aligned");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "organize-desktop-by-name");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "organize-desktop-by-name");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "change-background");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "change-background");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "properties");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count > 0);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "properties");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count > 0);
- /* Stretch */
- canvas_container = get_canvas_container (desktop_view);
+ /* Stretch */
+ canvas_container = get_canvas_container (desktop_view);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "stretch");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count == 1 &&
- canvas_container != NULL &&
- !nautilus_canvas_container_has_stretch_handles (canvas_container));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "stretch");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count == 1 &&
+ canvas_container != NULL &&
+ !nautilus_canvas_container_has_stretch_handles (canvas_container));
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
- /* Unstretch */
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "unstretch");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), canvas_container != NULL &&
- nautilus_canvas_container_is_stretched (canvas_container));
+ /* Unstretch */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "unstretch");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), canvas_container != NULL &&
+ nautilus_canvas_container_is_stretched (canvas_container));
}
static void
nautilus_desktop_canvas_view_init (NautilusDesktopCanvasView *desktop_canvas_view)
{
- NautilusCanvasContainer *canvas_container;
- GtkAllocation allocation;
- GActionGroup *view_action_group;
- GtkAdjustment *hadj, *vadj;
+ NautilusCanvasContainer *canvas_container;
+ GtkAllocation allocation;
+ GActionGroup *view_action_group;
+ GtkAdjustment *hadj, *vadj;
- desktop_canvas_view->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_canvas_view,
- NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW,
- NautilusDesktopCanvasViewDetails);
+ desktop_canvas_view->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_canvas_view,
+ NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW,
+ NautilusDesktopCanvasViewDetails);
- if (desktop_directory == NULL) {
- desktop_directory = nautilus_get_desktop_directory ();
- }
+ if (desktop_directory == NULL)
+ {
+ desktop_directory = nautilus_get_desktop_directory ();
+ }
- canvas_container = get_canvas_container (desktop_canvas_view);
+ canvas_container = get_canvas_container (desktop_canvas_view);
- nautilus_canvas_container_set_is_fixed_size (canvas_container, TRUE);
- nautilus_canvas_container_set_is_desktop (canvas_container, TRUE);
- nautilus_canvas_container_set_store_layout_timestamps (canvas_container, TRUE);
+ nautilus_canvas_container_set_is_fixed_size (canvas_container, TRUE);
+ nautilus_canvas_container_set_is_desktop (canvas_container, TRUE);
+ nautilus_canvas_container_set_store_layout_timestamps (canvas_container, TRUE);
- /* Set allocation to be at 0, 0 */
- gtk_widget_get_allocation (GTK_WIDGET (canvas_container), &allocation);
- allocation.x = 0;
- allocation.y = 0;
- gtk_widget_set_allocation (GTK_WIDGET (canvas_container), &allocation);
+ /* Set allocation to be at 0, 0 */
+ gtk_widget_get_allocation (GTK_WIDGET (canvas_container), &allocation);
+ allocation.x = 0;
+ allocation.y = 0;
+ gtk_widget_set_allocation (GTK_WIDGET (canvas_container), &allocation);
- gtk_widget_queue_resize (GTK_WIDGET (canvas_container));
+ gtk_widget_queue_resize (GTK_WIDGET (canvas_container));
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas_container));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas_container));
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas_container));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas_container));
- gtk_adjustment_set_value (hadj, 0);
- gtk_adjustment_set_value (vadj, 0);
+ gtk_adjustment_set_value (hadj, 0);
+ gtk_adjustment_set_value (vadj, 0);
- nautilus_files_view_ignore_hidden_file_preferences
- (NAUTILUS_FILES_VIEW (desktop_canvas_view));
+ nautilus_files_view_ignore_hidden_file_preferences
+ (NAUTILUS_FILES_VIEW (desktop_canvas_view));
- nautilus_files_view_set_show_foreign (NAUTILUS_FILES_VIEW (desktop_canvas_view),
- FALSE);
+ nautilus_files_view_set_show_foreign (NAUTILUS_FILES_VIEW (desktop_canvas_view),
+ FALSE);
- g_signal_connect_object (canvas_container, "realize",
- G_CALLBACK (desktop_canvas_container_realize), desktop_canvas_view, 0);
+ g_signal_connect_object (canvas_container, "realize",
+ G_CALLBACK (desktop_canvas_container_realize), desktop_canvas_view, 0);
- g_signal_connect_object (desktop_canvas_view, "realize",
- G_CALLBACK (realized_callback), desktop_canvas_view, 0);
- g_signal_connect_object (desktop_canvas_view, "unrealize",
- G_CALLBACK (unrealized_callback), desktop_canvas_view, 0);
+ g_signal_connect_object (desktop_canvas_view, "realize",
+ G_CALLBACK (realized_callback), desktop_canvas_view, 0);
+ g_signal_connect_object (desktop_canvas_view, "unrealize",
+ G_CALLBACK (unrealized_callback), desktop_canvas_view, 0);
- g_signal_connect_swapped (nautilus_icon_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
- G_CALLBACK (default_zoom_level_changed),
- desktop_canvas_view);
+ g_signal_connect_swapped (nautilus_icon_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
+ G_CALLBACK (default_zoom_level_changed),
+ desktop_canvas_view);
- g_signal_connect_swapped (nautilus_desktop_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_FONT,
- G_CALLBACK (font_changed_callback),
- desktop_canvas_view);
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_FONT,
+ G_CALLBACK (font_changed_callback),
+ desktop_canvas_view);
- set_up_zoom_level (desktop_canvas_view);
- nautilus_desktop_canvas_view_update_canvas_container_fonts (desktop_canvas_view);
+ set_up_zoom_level (desktop_canvas_view);
+ nautilus_desktop_canvas_view_update_canvas_container_fonts (desktop_canvas_view);
- g_signal_connect_swapped (gnome_lockdown_preferences,
- "changed::" NAUTILUS_PREFERENCES_LOCKDOWN_COMMAND_LINE,
- G_CALLBACK (nautilus_files_view_update_context_menus),
- desktop_canvas_view);
+ g_signal_connect_swapped (gnome_lockdown_preferences,
+ "changed::" NAUTILUS_PREFERENCES_LOCKDOWN_COMMAND_LINE,
+ G_CALLBACK (nautilus_files_view_update_context_menus),
+ desktop_canvas_view);
- view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (desktop_canvas_view));
+ view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (desktop_canvas_view));
- g_action_map_add_action_entries (G_ACTION_MAP (view_action_group),
- desktop_view_entries,
- G_N_ELEMENTS (desktop_view_entries),
- NAUTILUS_FILES_VIEW (desktop_canvas_view));
+ g_action_map_add_action_entries (G_ACTION_MAP (view_action_group),
+ desktop_view_entries,
+ G_N_ELEMENTS (desktop_view_entries),
+ NAUTILUS_FILES_VIEW (desktop_canvas_view));
}
NautilusFilesView *
nautilus_desktop_canvas_view_new (NautilusWindowSlot *slot)
{
- return g_object_new (NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW,
- "window-slot", slot,
- "supports-zooming", FALSE,
- "supports-auto-layout", FALSE,
- "supports-manual-layout", TRUE,
- "supports-scaling", TRUE,
- "supports-keep-aligned", TRUE,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_DESKTOP_CANVAS_VIEW,
+ "window-slot", slot,
+ "supports-zooming", FALSE,
+ "supports-auto-layout", FALSE,
+ "supports-manual-layout", TRUE,
+ "supports-scaling", TRUE,
+ "supports-keep-aligned", TRUE,
+ NULL);
}
diff --git a/nautilus-desktop/nautilus-desktop-directory-file.c b/nautilus-desktop/nautilus-desktop-directory-file.c
index 08c98c7b7..3d451adb0 100644
--- a/nautilus-desktop/nautilus-desktop-directory-file.c
+++ b/nautilus-desktop/nautilus-desktop-directory-file.c
@@ -1,24 +1,24 @@
/*
- nautilus-desktop-directory-file.c: Subclass of NautilusFile to help implement the
- virtual desktop.
-
- Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-desktop-directory-file.c: Subclass of NautilusFile to help implement the
+ * virtual desktop.
+ *
+ * Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include "nautilus-desktop-directory-file.h"
@@ -37,521 +37,532 @@
#include <glib/gi18n.h>
#include <string.h>
-struct NautilusDesktopDirectoryFileDetails {
- NautilusDesktopDirectory *desktop_directory;
+struct NautilusDesktopDirectoryFileDetails
+{
+ NautilusDesktopDirectory *desktop_directory;
- NautilusFile *real_dir_file;
+ NautilusFile *real_dir_file;
- GHashTable *callbacks;
- GHashTable *monitors;
+ GHashTable *callbacks;
+ GHashTable *monitors;
};
-typedef struct {
- NautilusDesktopDirectoryFile *desktop_file;
- NautilusFileCallback callback;
- gpointer callback_data;
+typedef struct
+{
+ NautilusDesktopDirectoryFile *desktop_file;
+ NautilusFileCallback callback;
+ gpointer callback_data;
- NautilusFileAttributes delegated_attributes;
- NautilusFileAttributes non_delegated_attributes;
+ NautilusFileAttributes delegated_attributes;
+ NautilusFileAttributes non_delegated_attributes;
- GList *non_ready_files;
+ GList *non_ready_files;
- gboolean initializing;
+ gboolean initializing;
} DesktopCallback;
-typedef struct {
- NautilusDesktopDirectoryFile *desktop_file;
+typedef struct
+{
+ NautilusDesktopDirectoryFile *desktop_file;
- NautilusFileAttributes delegated_attributes;
- NautilusFileAttributes non_delegated_attributes;
+ NautilusFileAttributes delegated_attributes;
+ NautilusFileAttributes non_delegated_attributes;
} DesktopMonitor;
G_DEFINE_TYPE (NautilusDesktopDirectoryFile, nautilus_desktop_directory_file,
- NAUTILUS_TYPE_FILE);
+ NAUTILUS_TYPE_FILE);
static guint
desktop_callback_hash (gconstpointer desktop_callback_as_pointer)
{
- const DesktopCallback *desktop_callback;
+ const DesktopCallback *desktop_callback;
- desktop_callback = desktop_callback_as_pointer;
- return GPOINTER_TO_UINT (desktop_callback->callback)
- ^ GPOINTER_TO_UINT (desktop_callback->callback_data);
+ desktop_callback = desktop_callback_as_pointer;
+ return GPOINTER_TO_UINT (desktop_callback->callback)
+ ^ GPOINTER_TO_UINT (desktop_callback->callback_data);
}
static gboolean
desktop_callback_equal (gconstpointer desktop_callback_as_pointer,
- gconstpointer desktop_callback_as_pointer_2)
+ gconstpointer desktop_callback_as_pointer_2)
{
- const DesktopCallback *desktop_callback, *desktop_callback_2;
+ const DesktopCallback *desktop_callback, *desktop_callback_2;
- desktop_callback = desktop_callback_as_pointer;
- desktop_callback_2 = desktop_callback_as_pointer_2;
+ desktop_callback = desktop_callback_as_pointer;
+ desktop_callback_2 = desktop_callback_as_pointer_2;
- return desktop_callback->callback == desktop_callback_2->callback
- && desktop_callback->callback_data == desktop_callback_2->callback_data;
+ return desktop_callback->callback == desktop_callback_2->callback
+ && desktop_callback->callback_data == desktop_callback_2->callback_data;
}
-
+
static void
real_file_changed_callback (NautilusFile *real_file,
- gpointer callback_data)
+ gpointer callback_data)
{
- NautilusDesktopDirectoryFile *desktop_file;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (callback_data);
- nautilus_file_changed (NAUTILUS_FILE (desktop_file));
+ NautilusDesktopDirectoryFile *desktop_file;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (callback_data);
+ nautilus_file_changed (NAUTILUS_FILE (desktop_file));
}
-static NautilusFileAttributes
+static NautilusFileAttributes
get_delegated_attributes_mask (void)
{
- return NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES |
- NAUTILUS_FILE_ATTRIBUTE_INFO;
+ return NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES |
+ NAUTILUS_FILE_ATTRIBUTE_INFO;
}
static void
-partition_attributes (NautilusFileAttributes attributes,
- NautilusFileAttributes *delegated_attributes,
- NautilusFileAttributes *non_delegated_attributes)
+partition_attributes (NautilusFileAttributes attributes,
+ NautilusFileAttributes *delegated_attributes,
+ NautilusFileAttributes *non_delegated_attributes)
{
- NautilusFileAttributes mask;
+ NautilusFileAttributes mask;
- mask = get_delegated_attributes_mask ();
+ mask = get_delegated_attributes_mask ();
- *delegated_attributes = attributes & mask;
- *non_delegated_attributes = attributes & ~mask;
+ *delegated_attributes = attributes & mask;
+ *non_delegated_attributes = attributes & ~mask;
}
static void
-desktop_directory_file_monitor_add (NautilusFile *file,
- gconstpointer client,
- NautilusFileAttributes attributes)
+desktop_directory_file_monitor_add (NautilusFile *file,
+ gconstpointer client,
+ NautilusFileAttributes attributes)
{
- NautilusDesktopDirectoryFile *desktop_file;
- DesktopMonitor *monitor;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
-
- /* Map the client to a unique value so this doesn't interfere
- * with direct monitoring of the file by the same client.
- */
- monitor = g_hash_table_lookup (desktop_file->details->monitors, client);
- if (monitor != NULL) {
- g_assert (monitor->desktop_file == desktop_file);
- } else {
- monitor = g_new0 (DesktopMonitor, 1);
- monitor->desktop_file = desktop_file;
- g_hash_table_insert (desktop_file->details->monitors,
- (gpointer) client, monitor);
- }
-
- partition_attributes (attributes,
- &monitor->delegated_attributes,
- &monitor->non_delegated_attributes);
-
- /* Pawn off partioned attributes to real dir file */
- nautilus_file_monitor_add (desktop_file->details->real_dir_file,
- monitor, monitor->delegated_attributes);
-
- /* Do the rest ourself */
- nautilus_directory_monitor_add_internal
- (file->details->directory, file,
- client, TRUE,
- monitor->non_delegated_attributes,
- NULL, NULL);
+ NautilusDesktopDirectoryFile *desktop_file;
+ DesktopMonitor *monitor;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+
+ /* Map the client to a unique value so this doesn't interfere
+ * with direct monitoring of the file by the same client.
+ */
+ monitor = g_hash_table_lookup (desktop_file->details->monitors, client);
+ if (monitor != NULL)
+ {
+ g_assert (monitor->desktop_file == desktop_file);
+ }
+ else
+ {
+ monitor = g_new0 (DesktopMonitor, 1);
+ monitor->desktop_file = desktop_file;
+ g_hash_table_insert (desktop_file->details->monitors,
+ (gpointer) client, monitor);
+ }
+
+ partition_attributes (attributes,
+ &monitor->delegated_attributes,
+ &monitor->non_delegated_attributes);
+
+ /* Pawn off partioned attributes to real dir file */
+ nautilus_file_monitor_add (desktop_file->details->real_dir_file,
+ monitor, monitor->delegated_attributes);
+
+ /* Do the rest ourself */
+ nautilus_directory_monitor_add_internal
+ (file->details->directory, file,
+ client, TRUE,
+ monitor->non_delegated_attributes,
+ NULL, NULL);
}
static void
-desktop_directory_file_monitor_remove (NautilusFile *file,
- gconstpointer client)
+desktop_directory_file_monitor_remove (NautilusFile *file,
+ gconstpointer client)
{
- NautilusDesktopDirectoryFile *desktop_file;
- DesktopMonitor *monitor;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
-
- /* Map the client to the value used by the earlier add call. */
- monitor = g_hash_table_lookup (desktop_file->details->monitors, client);
- if (monitor == NULL) {
- return;
- }
-
- /* Call through to the real file remove calls. */
- g_hash_table_remove (desktop_file->details->monitors, client);
-
- /* Remove the locally handled parts */
- nautilus_directory_monitor_remove_internal
- (file->details->directory, file, client);
+ NautilusDesktopDirectoryFile *desktop_file;
+ DesktopMonitor *monitor;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+
+ /* Map the client to the value used by the earlier add call. */
+ monitor = g_hash_table_lookup (desktop_file->details->monitors, client);
+ if (monitor == NULL)
+ {
+ return;
+ }
+
+ /* Call through to the real file remove calls. */
+ g_hash_table_remove (desktop_file->details->monitors, client);
+
+ /* Remove the locally handled parts */
+ nautilus_directory_monitor_remove_internal
+ (file->details->directory, file, client);
}
static void
desktop_callback_destroy (DesktopCallback *desktop_callback)
{
- g_assert (desktop_callback != NULL);
- g_assert (NAUTILUS_IS_DESKTOP_DIRECTORY_FILE (desktop_callback->desktop_file));
+ g_assert (desktop_callback != NULL);
+ g_assert (NAUTILUS_IS_DESKTOP_DIRECTORY_FILE (desktop_callback->desktop_file));
- nautilus_file_unref (NAUTILUS_FILE (desktop_callback->desktop_file));
- g_list_free (desktop_callback->non_ready_files);
- g_free (desktop_callback);
+ nautilus_file_unref (NAUTILUS_FILE (desktop_callback->desktop_file));
+ g_list_free (desktop_callback->non_ready_files);
+ g_free (desktop_callback);
}
static void
desktop_callback_check_done (DesktopCallback *desktop_callback)
{
- /* Check if we are ready. */
- if (desktop_callback->initializing ||
- desktop_callback->non_ready_files != NULL) {
- return;
- }
-
- /* Ensure our metadata is updated before calling back */
- nautilus_desktop_update_metadata_from_keyfile (NAUTILUS_FILE (desktop_callback->desktop_file), "directory");
-
- /* Remove from the hash table before sending it. */
- g_hash_table_remove (desktop_callback->desktop_file->details->callbacks,
- desktop_callback);
-
- /* We are ready, so do the real callback. */
- (* desktop_callback->callback) (NAUTILUS_FILE (desktop_callback->desktop_file),
- desktop_callback->callback_data);
-
- /* And we are done. */
- desktop_callback_destroy (desktop_callback);
+ /* Check if we are ready. */
+ if (desktop_callback->initializing ||
+ desktop_callback->non_ready_files != NULL)
+ {
+ return;
+ }
+
+ /* Ensure our metadata is updated before calling back */
+ nautilus_desktop_update_metadata_from_keyfile (NAUTILUS_FILE (desktop_callback->desktop_file), "directory");
+
+ /* Remove from the hash table before sending it. */
+ g_hash_table_remove (desktop_callback->desktop_file->details->callbacks,
+ desktop_callback);
+
+ /* We are ready, so do the real callback. */
+ (*desktop_callback->callback)(NAUTILUS_FILE (desktop_callback->desktop_file),
+ desktop_callback->callback_data);
+
+ /* And we are done. */
+ desktop_callback_destroy (desktop_callback);
}
static void
desktop_callback_remove_file (DesktopCallback *desktop_callback,
- NautilusFile *file)
+ NautilusFile *file)
{
- desktop_callback->non_ready_files = g_list_remove
- (desktop_callback->non_ready_files, file);
- desktop_callback_check_done (desktop_callback);
+ desktop_callback->non_ready_files = g_list_remove
+ (desktop_callback->non_ready_files, file);
+ desktop_callback_check_done (desktop_callback);
}
static void
ready_callback (NautilusFile *file,
- gpointer callback_data)
+ gpointer callback_data)
{
- DesktopCallback *desktop_callback;
+ DesktopCallback *desktop_callback;
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (callback_data != NULL);
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (callback_data != NULL);
- desktop_callback = callback_data;
- g_assert (g_list_find (desktop_callback->non_ready_files, file) != NULL);
+ desktop_callback = callback_data;
+ g_assert (g_list_find (desktop_callback->non_ready_files, file) != NULL);
- desktop_callback_remove_file (desktop_callback, file);
+ desktop_callback_remove_file (desktop_callback, file);
}
static void
-desktop_directory_file_call_when_ready (NautilusFile *file,
- NautilusFileAttributes attributes,
- NautilusFileCallback callback,
- gpointer callback_data)
-
+desktop_directory_file_call_when_ready (NautilusFile *file,
+ NautilusFileAttributes attributes,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopDirectoryFile *desktop_file;
- DesktopCallback search_key, *desktop_callback;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
-
- /* Check to be sure we aren't overwriting. */
- search_key.callback = callback;
- search_key.callback_data = callback_data;
- if (g_hash_table_lookup (desktop_file->details->callbacks, &search_key) != NULL) {
- g_warning ("tried to add a new callback while an old one was pending");
- return;
- }
-
- /* Create a desktop_callback record. */
- desktop_callback = g_new0 (DesktopCallback, 1);
- nautilus_file_ref (file);
- desktop_callback->desktop_file = desktop_file;
- desktop_callback->callback = callback;
- desktop_callback->callback_data = callback_data;
- desktop_callback->initializing = TRUE;
-
- partition_attributes (attributes,
- &desktop_callback->delegated_attributes,
- &desktop_callback->non_delegated_attributes);
-
- desktop_callback->non_ready_files = g_list_prepend
- (desktop_callback->non_ready_files, file);
- desktop_callback->non_ready_files = g_list_prepend
- (desktop_callback->non_ready_files, desktop_file->details->real_dir_file);
-
- /* Put it in the hash table. */
- g_hash_table_insert (desktop_file->details->callbacks,
- desktop_callback, desktop_callback);
-
- /* Now connect to each file's call_when_ready. */
- nautilus_directory_call_when_ready_internal
- (file->details->directory, file,
- desktop_callback->non_delegated_attributes,
- FALSE, NULL, ready_callback, desktop_callback);
- nautilus_file_call_when_ready
- (desktop_file->details->real_dir_file,
- desktop_callback->delegated_attributes,
- ready_callback, desktop_callback);
-
- desktop_callback->initializing = FALSE;
-
- /* Check if any files became read while we were connecting up
- * the call_when_ready callbacks (also handles the pathological
- * case where there are no files at all).
- */
- desktop_callback_check_done (desktop_callback);
-
+ NautilusDesktopDirectoryFile *desktop_file;
+ DesktopCallback search_key, *desktop_callback;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+
+ /* Check to be sure we aren't overwriting. */
+ search_key.callback = callback;
+ search_key.callback_data = callback_data;
+ if (g_hash_table_lookup (desktop_file->details->callbacks, &search_key) != NULL)
+ {
+ g_warning ("tried to add a new callback while an old one was pending");
+ return;
+ }
+
+ /* Create a desktop_callback record. */
+ desktop_callback = g_new0 (DesktopCallback, 1);
+ nautilus_file_ref (file);
+ desktop_callback->desktop_file = desktop_file;
+ desktop_callback->callback = callback;
+ desktop_callback->callback_data = callback_data;
+ desktop_callback->initializing = TRUE;
+
+ partition_attributes (attributes,
+ &desktop_callback->delegated_attributes,
+ &desktop_callback->non_delegated_attributes);
+
+ desktop_callback->non_ready_files = g_list_prepend
+ (desktop_callback->non_ready_files, file);
+ desktop_callback->non_ready_files = g_list_prepend
+ (desktop_callback->non_ready_files, desktop_file->details->real_dir_file);
+
+ /* Put it in the hash table. */
+ g_hash_table_insert (desktop_file->details->callbacks,
+ desktop_callback, desktop_callback);
+
+ /* Now connect to each file's call_when_ready. */
+ nautilus_directory_call_when_ready_internal
+ (file->details->directory, file,
+ desktop_callback->non_delegated_attributes,
+ FALSE, NULL, ready_callback, desktop_callback);
+ nautilus_file_call_when_ready
+ (desktop_file->details->real_dir_file,
+ desktop_callback->delegated_attributes,
+ ready_callback, desktop_callback);
+
+ desktop_callback->initializing = FALSE;
+
+ /* Check if any files became read while we were connecting up
+ * the call_when_ready callbacks (also handles the pathological
+ * case where there are no files at all).
+ */
+ desktop_callback_check_done (desktop_callback);
}
static void
-desktop_directory_file_cancel_call_when_ready (NautilusFile *file,
- NautilusFileCallback callback,
- gpointer callback_data)
+desktop_directory_file_cancel_call_when_ready (NautilusFile *file,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopDirectoryFile *desktop_file;
- DesktopCallback search_key, *desktop_callback;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
-
- /* Find the entry in the table. */
- search_key.callback = callback;
- search_key.callback_data = callback_data;
- desktop_callback = g_hash_table_lookup (desktop_file->details->callbacks, &search_key);
- if (desktop_callback == NULL) {
- return;
- }
-
- /* Remove from the hash table before working with it. */
- g_hash_table_remove (desktop_callback->desktop_file->details->callbacks, desktop_callback);
-
- /* Tell the real directory to cancel the call. */
- nautilus_directory_cancel_callback_internal
- (file->details->directory, file,
- NULL, ready_callback, desktop_callback);
-
- nautilus_file_cancel_call_when_ready
- (desktop_file->details->real_dir_file,
- ready_callback, desktop_callback);
-
- desktop_callback_destroy (desktop_callback);
+ NautilusDesktopDirectoryFile *desktop_file;
+ DesktopCallback search_key, *desktop_callback;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+
+ /* Find the entry in the table. */
+ search_key.callback = callback;
+ search_key.callback_data = callback_data;
+ desktop_callback = g_hash_table_lookup (desktop_file->details->callbacks, &search_key);
+ if (desktop_callback == NULL)
+ {
+ return;
+ }
+
+ /* Remove from the hash table before working with it. */
+ g_hash_table_remove (desktop_callback->desktop_file->details->callbacks, desktop_callback);
+
+ /* Tell the real directory to cancel the call. */
+ nautilus_directory_cancel_callback_internal
+ (file->details->directory, file,
+ NULL, ready_callback, desktop_callback);
+
+ nautilus_file_cancel_call_when_ready
+ (desktop_file->details->real_dir_file,
+ ready_callback, desktop_callback);
+
+ desktop_callback_destroy (desktop_callback);
}
static gboolean
-real_check_if_ready (NautilusFile *file,
- NautilusFileAttributes attributes)
+real_check_if_ready (NautilusFile *file,
+ NautilusFileAttributes attributes)
{
- return nautilus_directory_check_if_ready_internal
- (file->details->directory, file,
- attributes);
+ return nautilus_directory_check_if_ready_internal
+ (file->details->directory, file,
+ attributes);
}
static gboolean
-desktop_directory_file_check_if_ready (NautilusFile *file,
- NautilusFileAttributes attributes)
+desktop_directory_file_check_if_ready (NautilusFile *file,
+ NautilusFileAttributes attributes)
{
- NautilusFileAttributes delegated_attributes, non_delegated_attributes;
- NautilusDesktopDirectoryFile *desktop_file;
+ NautilusFileAttributes delegated_attributes, non_delegated_attributes;
+ NautilusDesktopDirectoryFile *desktop_file;
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
- partition_attributes (attributes,
- &delegated_attributes,
- &non_delegated_attributes);
+ partition_attributes (attributes,
+ &delegated_attributes,
+ &non_delegated_attributes);
- return real_check_if_ready (file, non_delegated_attributes) &&
- nautilus_file_check_if_ready (desktop_file->details->real_dir_file,
- delegated_attributes);
+ return real_check_if_ready (file, non_delegated_attributes) &&
+ nautilus_file_check_if_ready (desktop_file->details->real_dir_file,
+ delegated_attributes);
}
static gboolean
-desktop_directory_file_get_item_count (NautilusFile *file,
- guint *count,
- gboolean *count_unreadable)
+desktop_directory_file_get_item_count (NautilusFile *file,
+ guint *count,
+ gboolean *count_unreadable)
{
- NautilusDesktopDirectoryFile *desktop_file;
- gboolean got_count;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
-
- got_count = nautilus_file_get_directory_item_count (desktop_file->details->real_dir_file,
- count,
- count_unreadable);
-
- if (count) {
- *count += g_list_length (file->details->directory->details->file_list);
- }
-
- return got_count;
+ NautilusDesktopDirectoryFile *desktop_file;
+ gboolean got_count;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+
+ got_count = nautilus_file_get_directory_item_count (desktop_file->details->real_dir_file,
+ count,
+ count_unreadable);
+
+ if (count)
+ {
+ *count += g_list_length (file->details->directory->details->file_list);
+ }
+
+ return got_count;
}
static NautilusRequestStatus
desktop_directory_file_get_deep_counts (NautilusFile *file,
- guint *directory_count,
- guint *file_count,
- guint *unreadable_directory_count,
- goffset *total_size)
+ guint *directory_count,
+ guint *file_count,
+ guint *unreadable_directory_count,
+ goffset *total_size)
{
- NautilusDesktopDirectoryFile *desktop_file;
- NautilusRequestStatus status;
-
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
-
- status = nautilus_file_get_deep_counts (desktop_file->details->real_dir_file,
- directory_count,
- file_count,
- unreadable_directory_count,
- total_size,
- TRUE);
-
- if (file_count) {
- *file_count += g_list_length (file->details->directory->details->file_list);
- }
-
- return status;
+ NautilusDesktopDirectoryFile *desktop_file;
+ NautilusRequestStatus status;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+
+ status = nautilus_file_get_deep_counts (desktop_file->details->real_dir_file,
+ directory_count,
+ file_count,
+ unreadable_directory_count,
+ total_size,
+ TRUE);
+
+ if (file_count)
+ {
+ *file_count += g_list_length (file->details->directory->details->file_list);
+ }
+
+ return status;
}
static gboolean
-desktop_directory_file_get_date (NautilusFile *file,
- NautilusDateType date_type,
- time_t *date)
+desktop_directory_file_get_date (NautilusFile *file,
+ NautilusDateType date_type,
+ time_t *date)
{
- NautilusDesktopDirectoryFile *desktop_file;
+ NautilusDesktopDirectoryFile *desktop_file;
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (file);
- return nautilus_file_get_date (desktop_file->details->real_dir_file,
- date_type,
- date);
+ return nautilus_file_get_date (desktop_file->details->real_dir_file,
+ date_type,
+ date);
}
static char *
desktop_directory_file_get_where_string (NautilusFile *file)
{
- return g_strdup (_("on the desktop"));
+ return g_strdup (_("on the desktop"));
}
static void
monitor_destroy (gpointer data)
{
- DesktopMonitor *monitor = data;
-
- nautilus_file_monitor_remove
- (NAUTILUS_FILE (monitor->desktop_file->details->real_dir_file), monitor);
- g_free (monitor);
+ DesktopMonitor *monitor = data;
+
+ nautilus_file_monitor_remove
+ (NAUTILUS_FILE (monitor->desktop_file->details->real_dir_file), monitor);
+ g_free (monitor);
}
static void
-nautilus_desktop_directory_file_set_metadata (NautilusFile *file,
- const char *key,
- const char *value)
+nautilus_desktop_directory_file_set_metadata (NautilusFile *file,
+ const char *key,
+ const char *value)
{
- nautilus_desktop_set_metadata_string (file, "directory", key, value);
+ nautilus_desktop_set_metadata_string (file, "directory", key, value);
}
static void
-nautilus_desktop_directory_file_set_metadata_as_list (NautilusFile *file,
- const char *key,
- char **value)
+nautilus_desktop_directory_file_set_metadata_as_list (NautilusFile *file,
+ const char *key,
+ char **value)
{
- nautilus_desktop_set_metadata_stringv (file, "directory", key, (const gchar **) value);
+ nautilus_desktop_set_metadata_stringv (file, "directory", key, (const gchar **) value);
}
static void
nautilus_desktop_directory_file_init (NautilusDesktopDirectoryFile *desktop_file)
{
- NautilusDesktopDirectory *desktop_directory;
- NautilusDirectory *real_dir;
- NautilusFile *real_dir_file;
-
- desktop_file->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_file,
- NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE,
- NautilusDesktopDirectoryFileDetails);
-
- desktop_directory = NAUTILUS_DESKTOP_DIRECTORY (nautilus_directory_get_by_uri (EEL_DESKTOP_URI));
- desktop_file->details->desktop_directory = desktop_directory;
-
- desktop_file->details->callbacks = g_hash_table_new
- (desktop_callback_hash, desktop_callback_equal);
- desktop_file->details->monitors = g_hash_table_new_full (NULL, NULL,
- NULL, monitor_destroy);
-
- real_dir = nautilus_desktop_directory_get_real_directory (desktop_directory);
- real_dir_file = nautilus_directory_get_corresponding_file (real_dir);
- nautilus_directory_unref (real_dir);
-
- desktop_file->details->real_dir_file = real_dir_file;
- g_signal_connect_object (real_dir_file, "changed",
- G_CALLBACK (real_file_changed_callback), desktop_file, 0);
+ NautilusDesktopDirectory *desktop_directory;
+ NautilusDirectory *real_dir;
+ NautilusFile *real_dir_file;
+
+ desktop_file->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_file,
+ NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE,
+ NautilusDesktopDirectoryFileDetails);
+
+ desktop_directory = NAUTILUS_DESKTOP_DIRECTORY (nautilus_directory_get_by_uri (EEL_DESKTOP_URI));
+ desktop_file->details->desktop_directory = desktop_directory;
+
+ desktop_file->details->callbacks = g_hash_table_new
+ (desktop_callback_hash, desktop_callback_equal);
+ desktop_file->details->monitors = g_hash_table_new_full (NULL, NULL,
+ NULL, monitor_destroy);
+
+ real_dir = nautilus_desktop_directory_get_real_directory (desktop_directory);
+ real_dir_file = nautilus_directory_get_corresponding_file (real_dir);
+ nautilus_directory_unref (real_dir);
+
+ desktop_file->details->real_dir_file = real_dir_file;
+ g_signal_connect_object (real_dir_file, "changed",
+ G_CALLBACK (real_file_changed_callback), desktop_file, 0);
}
static void
desktop_callback_remove_file_cover (gpointer key,
- gpointer value,
- gpointer callback_data)
+ gpointer value,
+ gpointer callback_data)
{
- desktop_callback_remove_file
- (value, NAUTILUS_FILE (callback_data));
+ desktop_callback_remove_file
+ (value, NAUTILUS_FILE (callback_data));
}
static void
desktop_finalize (GObject *object)
{
- NautilusDesktopDirectoryFile *desktop_file;
- NautilusDesktopDirectory *desktop_directory;
+ NautilusDesktopDirectoryFile *desktop_file;
+ NautilusDesktopDirectory *desktop_directory;
+
+ desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (object);
+ desktop_directory = desktop_file->details->desktop_directory;
- desktop_file = NAUTILUS_DESKTOP_DIRECTORY_FILE (object);
- desktop_directory = desktop_file->details->desktop_directory;
+ /* Todo: ghash now safe? */
+ eel_g_hash_table_safe_for_each
+ (desktop_file->details->callbacks,
+ desktop_callback_remove_file_cover,
+ desktop_file->details->real_dir_file);
- /* Todo: ghash now safe? */
- eel_g_hash_table_safe_for_each
- (desktop_file->details->callbacks,
- desktop_callback_remove_file_cover,
- desktop_file->details->real_dir_file);
-
- if (g_hash_table_size (desktop_file->details->callbacks) != 0) {
- g_warning ("call_when_ready still pending when desktop virtual file is destroyed");
- }
+ if (g_hash_table_size (desktop_file->details->callbacks) != 0)
+ {
+ g_warning ("call_when_ready still pending when desktop virtual file is destroyed");
+ }
- g_hash_table_destroy (desktop_file->details->callbacks);
- g_hash_table_destroy (desktop_file->details->monitors);
+ g_hash_table_destroy (desktop_file->details->callbacks);
+ g_hash_table_destroy (desktop_file->details->monitors);
- nautilus_file_unref (desktop_file->details->real_dir_file);
- nautilus_directory_unref (NAUTILUS_DIRECTORY (desktop_directory));
+ nautilus_file_unref (desktop_file->details->real_dir_file);
+ nautilus_directory_unref (NAUTILUS_DIRECTORY (desktop_directory));
- G_OBJECT_CLASS (nautilus_desktop_directory_file_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_desktop_directory_file_parent_class)->finalize (object);
}
static void
nautilus_desktop_directory_file_class_init (NautilusDesktopDirectoryFileClass *klass)
{
- GObjectClass *object_class;
- NautilusFileClass *file_class;
-
- object_class = G_OBJECT_CLASS (klass);
- file_class = NAUTILUS_FILE_CLASS (klass);
-
- object_class->finalize = desktop_finalize;
-
- file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
-
- file_class->monitor_add = desktop_directory_file_monitor_add;
- file_class->monitor_remove = desktop_directory_file_monitor_remove;
- file_class->call_when_ready = desktop_directory_file_call_when_ready;
- file_class->cancel_call_when_ready = desktop_directory_file_cancel_call_when_ready;
- file_class->check_if_ready = desktop_directory_file_check_if_ready;
- file_class->get_item_count = desktop_directory_file_get_item_count;
- file_class->get_deep_counts = desktop_directory_file_get_deep_counts;
- file_class->get_date = desktop_directory_file_get_date;
- file_class->get_where_string = desktop_directory_file_get_where_string;
- file_class->set_metadata = nautilus_desktop_directory_file_set_metadata;
- file_class->set_metadata_as_list = nautilus_desktop_directory_file_set_metadata_as_list;
-
- g_type_class_add_private (klass, sizeof (NautilusDesktopDirectoryFileDetails));
+ GObjectClass *object_class;
+ NautilusFileClass *file_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ file_class = NAUTILUS_FILE_CLASS (klass);
+
+ object_class->finalize = desktop_finalize;
+
+ file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
+
+ file_class->monitor_add = desktop_directory_file_monitor_add;
+ file_class->monitor_remove = desktop_directory_file_monitor_remove;
+ file_class->call_when_ready = desktop_directory_file_call_when_ready;
+ file_class->cancel_call_when_ready = desktop_directory_file_cancel_call_when_ready;
+ file_class->check_if_ready = desktop_directory_file_check_if_ready;
+ file_class->get_item_count = desktop_directory_file_get_item_count;
+ file_class->get_deep_counts = desktop_directory_file_get_deep_counts;
+ file_class->get_date = desktop_directory_file_get_date;
+ file_class->get_where_string = desktop_directory_file_get_where_string;
+ file_class->set_metadata = nautilus_desktop_directory_file_set_metadata;
+ file_class->set_metadata_as_list = nautilus_desktop_directory_file_set_metadata_as_list;
+
+ g_type_class_add_private (klass, sizeof (NautilusDesktopDirectoryFileDetails));
}
diff --git a/nautilus-desktop/nautilus-desktop-directory.c b/nautilus-desktop/nautilus-desktop-directory.c
index 0af76e2fa..cfa125e69 100644
--- a/nautilus-desktop/nautilus-desktop-directory.c
+++ b/nautilus-desktop/nautilus-desktop-directory.c
@@ -1,25 +1,25 @@
/*
- nautilus-desktop-directory.c: Subclass of NautilusDirectory to implement
- a virtual directory consisting of the desktop directory and the desktop
- icons
-
- Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-desktop-directory.c: Subclass of NautilusDirectory to implement
+ * a virtual directory consisting of the desktop directory and the desktop
+ * icons
+ *
+ * Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include "nautilus-desktop-directory.h"
@@ -32,30 +32,33 @@
#include <src/nautilus-global-preferences.h>
#include <gtk/gtk.h>
-struct NautilusDesktopDirectoryDetails {
- NautilusDirectory *real_directory;
- GHashTable *callbacks;
- GHashTable *monitors;
+struct NautilusDesktopDirectoryDetails
+{
+ NautilusDirectory *real_directory;
+ GHashTable *callbacks;
+ GHashTable *monitors;
};
-typedef struct {
- NautilusDesktopDirectory *desktop_dir;
- NautilusDirectoryCallback callback;
- gpointer callback_data;
+typedef struct
+{
+ NautilusDesktopDirectory *desktop_dir;
+ NautilusDirectoryCallback callback;
+ gpointer callback_data;
- NautilusFileAttributes wait_for_attributes;
- gboolean wait_for_file_list;
+ NautilusFileAttributes wait_for_attributes;
+ gboolean wait_for_file_list;
- GList *non_ready_directories;
- GList *merged_file_list;
+ GList *non_ready_directories;
+ GList *merged_file_list;
} MergedCallback;
-typedef struct {
- NautilusDesktopDirectory *desktop_dir;
+typedef struct
+{
+ NautilusDesktopDirectory *desktop_dir;
- gboolean monitor_hidden_files;
- NautilusFileAttributes monitor_attributes;
+ gboolean monitor_hidden_files;
+ NautilusFileAttributes monitor_attributes;
} MergedMonitor;
static void desktop_directory_changed_callback (gpointer data);
@@ -68,424 +71,436 @@ G_DEFINE_TYPE_WITH_CODE (NautilusDesktopDirectory, nautilus_desktop_directory, N
0));
static gboolean
desktop_contains_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- NautilusDesktopDirectory *desktop;
+ NautilusDesktopDirectory *desktop;
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
- if (nautilus_directory_contains_file (desktop->details->real_directory, file)) {
- return TRUE;
- }
+ if (nautilus_directory_contains_file (desktop->details->real_directory, file))
+ {
+ return TRUE;
+ }
- return file->details->directory == directory;
+ return file->details->directory == directory;
}
static guint
merged_callback_hash (gconstpointer merged_callback_as_pointer)
{
- const MergedCallback *merged_callback;
+ const MergedCallback *merged_callback;
- merged_callback = merged_callback_as_pointer;
- return GPOINTER_TO_UINT (merged_callback->callback)
- ^ GPOINTER_TO_UINT (merged_callback->callback_data);
+ merged_callback = merged_callback_as_pointer;
+ return GPOINTER_TO_UINT (merged_callback->callback)
+ ^ GPOINTER_TO_UINT (merged_callback->callback_data);
}
static gboolean
merged_callback_equal (gconstpointer merged_callback_as_pointer,
- gconstpointer merged_callback_as_pointer_2)
+ gconstpointer merged_callback_as_pointer_2)
{
- const MergedCallback *merged_callback, *merged_callback_2;
+ const MergedCallback *merged_callback, *merged_callback_2;
- merged_callback = merged_callback_as_pointer;
- merged_callback_2 = merged_callback_as_pointer_2;
+ merged_callback = merged_callback_as_pointer;
+ merged_callback_2 = merged_callback_as_pointer_2;
- return merged_callback->callback == merged_callback_2->callback
- && merged_callback->callback_data == merged_callback_2->callback_data;
+ return merged_callback->callback == merged_callback_2->callback
+ && merged_callback->callback_data == merged_callback_2->callback_data;
}
static void
merged_callback_destroy (MergedCallback *merged_callback)
{
- g_assert (merged_callback != NULL);
- g_assert (NAUTILUS_IS_DESKTOP_DIRECTORY (merged_callback->desktop_dir));
+ g_assert (merged_callback != NULL);
+ g_assert (NAUTILUS_IS_DESKTOP_DIRECTORY (merged_callback->desktop_dir));
- g_list_free (merged_callback->non_ready_directories);
- nautilus_file_list_free (merged_callback->merged_file_list);
- g_free (merged_callback);
+ g_list_free (merged_callback->non_ready_directories);
+ nautilus_file_list_free (merged_callback->merged_file_list);
+ g_free (merged_callback);
}
static void
merged_callback_check_done (MergedCallback *merged_callback)
{
- /* Check if we are ready. */
- if (merged_callback->non_ready_directories != NULL) {
- return;
- }
-
- /* Remove from the hash table before sending it. */
- g_hash_table_steal (merged_callback->desktop_dir->details->callbacks, merged_callback);
-
- /* We are ready, so do the real callback. */
- (* merged_callback->callback) (NAUTILUS_DIRECTORY (merged_callback->desktop_dir),
- merged_callback->merged_file_list,
- merged_callback->callback_data);
-
- /* And we are done. */
- merged_callback_destroy (merged_callback);
+ /* Check if we are ready. */
+ if (merged_callback->non_ready_directories != NULL)
+ {
+ return;
+ }
+
+ /* Remove from the hash table before sending it. */
+ g_hash_table_steal (merged_callback->desktop_dir->details->callbacks, merged_callback);
+
+ /* We are ready, so do the real callback. */
+ (*merged_callback->callback)(NAUTILUS_DIRECTORY (merged_callback->desktop_dir),
+ merged_callback->merged_file_list,
+ merged_callback->callback_data);
+
+ /* And we are done. */
+ merged_callback_destroy (merged_callback);
}
static void
-merged_callback_remove_directory (MergedCallback *merged_callback,
- NautilusDirectory *directory)
+merged_callback_remove_directory (MergedCallback *merged_callback,
+ NautilusDirectory *directory)
{
- merged_callback->non_ready_directories = g_list_remove
- (merged_callback->non_ready_directories, directory);
- merged_callback_check_done (merged_callback);
+ merged_callback->non_ready_directories = g_list_remove
+ (merged_callback->non_ready_directories, directory);
+ merged_callback_check_done (merged_callback);
}
static void
directory_ready_callback (NautilusDirectory *directory,
- GList *files,
- gpointer callback_data)
+ GList *files,
+ gpointer callback_data)
{
- MergedCallback *merged_callback;
+ MergedCallback *merged_callback;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (callback_data != NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (callback_data != NULL);
- merged_callback = callback_data;
- g_assert (g_list_find (merged_callback->non_ready_directories, directory) != NULL);
+ merged_callback = callback_data;
+ g_assert (g_list_find (merged_callback->non_ready_directories, directory) != NULL);
- /* Update based on this call. */
- merged_callback->merged_file_list = g_list_concat
- (merged_callback->merged_file_list,
- nautilus_file_list_copy (files));
+ /* Update based on this call. */
+ merged_callback->merged_file_list = g_list_concat
+ (merged_callback->merged_file_list,
+ nautilus_file_list_copy (files));
- /* Check if we are ready. */
- merged_callback_remove_directory (merged_callback, directory);
+ /* Check if we are ready. */
+ merged_callback_remove_directory (merged_callback, directory);
}
static void
-desktop_call_when_ready (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes,
- gboolean wait_for_file_list,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+desktop_call_when_ready (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes,
+ gboolean wait_for_file_list,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopDirectory *desktop;
- MergedCallback search_key, *merged_callback;
-
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
-
- /* Check to be sure we aren't overwriting. */
- search_key.callback = callback;
- search_key.callback_data = callback_data;
- if (g_hash_table_lookup (desktop->details->callbacks, &search_key) != NULL) {
- g_warning ("tried to add a new callback while an old one was pending");
- return;
- }
-
- /* Create a merged_callback record. */
- merged_callback = g_new0 (MergedCallback, 1);
- merged_callback->desktop_dir = desktop;
- merged_callback->callback = callback;
- merged_callback->callback_data = callback_data;
- merged_callback->wait_for_attributes = file_attributes;
- merged_callback->wait_for_file_list = wait_for_file_list;
- merged_callback->non_ready_directories = g_list_prepend
- (merged_callback->non_ready_directories, directory);
- merged_callback->non_ready_directories = g_list_prepend
- (merged_callback->non_ready_directories, desktop->details->real_directory);
-
-
- merged_callback->merged_file_list = g_list_concat (NULL,
- nautilus_file_list_copy (directory->details->file_list));
-
- /* Put it in the hash table. */
- g_hash_table_insert (desktop->details->callbacks,
- merged_callback, merged_callback);
-
- /* Now tell all the directories about it. */
- nautilus_directory_call_when_ready
- (desktop->details->real_directory,
- merged_callback->wait_for_attributes,
- merged_callback->wait_for_file_list,
- directory_ready_callback, merged_callback);
- nautilus_directory_call_when_ready_internal
- (directory,
- NULL,
- merged_callback->wait_for_attributes,
- merged_callback->wait_for_file_list,
- directory_ready_callback,
- NULL,
- merged_callback);
-
+ NautilusDesktopDirectory *desktop;
+ MergedCallback search_key, *merged_callback;
+
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+
+ /* Check to be sure we aren't overwriting. */
+ search_key.callback = callback;
+ search_key.callback_data = callback_data;
+ if (g_hash_table_lookup (desktop->details->callbacks, &search_key) != NULL)
+ {
+ g_warning ("tried to add a new callback while an old one was pending");
+ return;
+ }
+
+ /* Create a merged_callback record. */
+ merged_callback = g_new0 (MergedCallback, 1);
+ merged_callback->desktop_dir = desktop;
+ merged_callback->callback = callback;
+ merged_callback->callback_data = callback_data;
+ merged_callback->wait_for_attributes = file_attributes;
+ merged_callback->wait_for_file_list = wait_for_file_list;
+ merged_callback->non_ready_directories = g_list_prepend
+ (merged_callback->non_ready_directories, directory);
+ merged_callback->non_ready_directories = g_list_prepend
+ (merged_callback->non_ready_directories, desktop->details->real_directory);
+
+
+ merged_callback->merged_file_list = g_list_concat (NULL,
+ nautilus_file_list_copy (directory->details->file_list));
+
+ /* Put it in the hash table. */
+ g_hash_table_insert (desktop->details->callbacks,
+ merged_callback, merged_callback);
+
+ /* Now tell all the directories about it. */
+ nautilus_directory_call_when_ready
+ (desktop->details->real_directory,
+ merged_callback->wait_for_attributes,
+ merged_callback->wait_for_file_list,
+ directory_ready_callback, merged_callback);
+ nautilus_directory_call_when_ready_internal
+ (directory,
+ NULL,
+ merged_callback->wait_for_attributes,
+ merged_callback->wait_for_file_list,
+ directory_ready_callback,
+ NULL,
+ merged_callback);
}
static void
-desktop_cancel_callback (NautilusDirectory *directory,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+desktop_cancel_callback (NautilusDirectory *directory,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopDirectory *desktop;
- MergedCallback search_key, *merged_callback;
- GList *node;
-
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
-
- /* Find the entry in the table. */
- search_key.callback = callback;
- search_key.callback_data = callback_data;
- merged_callback = g_hash_table_lookup (desktop->details->callbacks, &search_key);
- if (merged_callback == NULL) {
- return;
- }
-
- /* Remove from the hash table before working with it. */
- g_hash_table_steal (merged_callback->desktop_dir->details->callbacks, merged_callback);
-
- /* Tell all the directories to cancel the call. */
- for (node = merged_callback->non_ready_directories; node != NULL; node = node->next) {
- nautilus_directory_cancel_callback
- (node->data,
- directory_ready_callback, merged_callback);
- }
- merged_callback_destroy (merged_callback);
+ NautilusDesktopDirectory *desktop;
+ MergedCallback search_key, *merged_callback;
+ GList *node;
+
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+
+ /* Find the entry in the table. */
+ search_key.callback = callback;
+ search_key.callback_data = callback_data;
+ merged_callback = g_hash_table_lookup (desktop->details->callbacks, &search_key);
+ if (merged_callback == NULL)
+ {
+ return;
+ }
+
+ /* Remove from the hash table before working with it. */
+ g_hash_table_steal (merged_callback->desktop_dir->details->callbacks, merged_callback);
+
+ /* Tell all the directories to cancel the call. */
+ for (node = merged_callback->non_ready_directories; node != NULL; node = node->next)
+ {
+ nautilus_directory_cancel_callback
+ (node->data,
+ directory_ready_callback, merged_callback);
+ }
+ merged_callback_destroy (merged_callback);
}
static void
merged_monitor_destroy (MergedMonitor *monitor)
{
- NautilusDesktopDirectory *desktop;
+ NautilusDesktopDirectory *desktop;
- desktop = monitor->desktop_dir;
-
- /* Call through to the real directory remove calls. */
- nautilus_directory_file_monitor_remove (desktop->details->real_directory, monitor);
+ desktop = monitor->desktop_dir;
- nautilus_directory_monitor_remove_internal (NAUTILUS_DIRECTORY (desktop), NULL, monitor);
-
- g_free (monitor);
+ /* Call through to the real directory remove calls. */
+ nautilus_directory_file_monitor_remove (desktop->details->real_directory, monitor);
+
+ nautilus_directory_monitor_remove_internal (NAUTILUS_DIRECTORY (desktop), NULL, monitor);
+
+ g_free (monitor);
}
static void
build_merged_callback_list (NautilusDirectory *directory,
- GList *file_list,
- gpointer callback_data)
+ GList *file_list,
+ gpointer callback_data)
{
- GList **merged_list;
+ GList **merged_list;
- merged_list = callback_data;
- *merged_list = g_list_concat (*merged_list,
- nautilus_file_list_copy (file_list));
+ merged_list = callback_data;
+ *merged_list = g_list_concat (*merged_list,
+ nautilus_file_list_copy (file_list));
}
static void
-desktop_monitor_add (NautilusDirectory *directory,
- gconstpointer client,
- gboolean monitor_hidden_files,
- NautilusFileAttributes file_attributes,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+desktop_monitor_add (NautilusDirectory *directory,
+ gconstpointer client,
+ gboolean monitor_hidden_files,
+ NautilusFileAttributes file_attributes,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopDirectory *desktop;
- MergedMonitor *monitor;
- GList *merged_callback_list;
-
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
-
- /* Map the client to a unique value so this doesn't interfere
- * with direct monitoring of the directory by the same client.
- */
- monitor = g_hash_table_lookup (desktop->details->monitors, client);
- if (monitor != NULL) {
- g_assert (monitor->desktop_dir == desktop);
- } else {
- monitor = g_new0 (MergedMonitor, 1);
- monitor->desktop_dir = desktop;
- g_hash_table_insert (desktop->details->monitors,
- (gpointer) client, monitor);
- }
- monitor->monitor_hidden_files = monitor_hidden_files;
- monitor->monitor_attributes = file_attributes;
-
- /* Call through to the real directory add calls. */
- merged_callback_list = NULL;
-
- /* Call up to real dir */
- nautilus_directory_file_monitor_add
- (desktop->details->real_directory, monitor,
- monitor_hidden_files,
- file_attributes,
- build_merged_callback_list, &merged_callback_list);
-
- /* Handle the desktop part */
- merged_callback_list = g_list_concat (merged_callback_list,
- nautilus_file_list_copy (directory->details->file_list));
-
-
- if (callback != NULL) {
- (* callback) (directory, merged_callback_list, callback_data);
- }
- nautilus_file_list_free (merged_callback_list);
+ NautilusDesktopDirectory *desktop;
+ MergedMonitor *monitor;
+ GList *merged_callback_list;
+
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+
+ /* Map the client to a unique value so this doesn't interfere
+ * with direct monitoring of the directory by the same client.
+ */
+ monitor = g_hash_table_lookup (desktop->details->monitors, client);
+ if (monitor != NULL)
+ {
+ g_assert (monitor->desktop_dir == desktop);
+ }
+ else
+ {
+ monitor = g_new0 (MergedMonitor, 1);
+ monitor->desktop_dir = desktop;
+ g_hash_table_insert (desktop->details->monitors,
+ (gpointer) client, monitor);
+ }
+ monitor->monitor_hidden_files = monitor_hidden_files;
+ monitor->monitor_attributes = file_attributes;
+
+ /* Call through to the real directory add calls. */
+ merged_callback_list = NULL;
+
+ /* Call up to real dir */
+ nautilus_directory_file_monitor_add
+ (desktop->details->real_directory, monitor,
+ monitor_hidden_files,
+ file_attributes,
+ build_merged_callback_list, &merged_callback_list);
+
+ /* Handle the desktop part */
+ merged_callback_list = g_list_concat (merged_callback_list,
+ nautilus_file_list_copy (directory->details->file_list));
+
+
+ if (callback != NULL)
+ {
+ (*callback)(directory, merged_callback_list, callback_data);
+ }
+ nautilus_file_list_free (merged_callback_list);
}
static void
desktop_monitor_remove (NautilusDirectory *directory,
- gconstpointer client)
+ gconstpointer client)
{
- NautilusDesktopDirectory *desktop;
- MergedMonitor *monitor;
-
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
-
- monitor = g_hash_table_lookup (desktop->details->monitors, client);
- if (monitor == NULL) {
- return;
- }
-
- g_hash_table_remove (desktop->details->monitors, client);
+ NautilusDesktopDirectory *desktop;
+ MergedMonitor *monitor;
+
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+
+ monitor = g_hash_table_lookup (desktop->details->monitors, client);
+ if (monitor == NULL)
+ {
+ return;
+ }
+
+ g_hash_table_remove (desktop->details->monitors, client);
}
static void
desktop_force_reload (NautilusDirectory *directory)
{
- NautilusDesktopDirectory *desktop;
+ NautilusDesktopDirectory *desktop;
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
- nautilus_directory_force_reload (desktop->details->real_directory);
+ nautilus_directory_force_reload (desktop->details->real_directory);
- /* We don't invalidate the files in desktop, since they are always
- up to date. (And we don't ever want to mark them invalid.) */
+ /* We don't invalidate the files in desktop, since they are always
+ * up to date. (And we don't ever want to mark them invalid.) */
}
static gboolean
desktop_are_all_files_seen (NautilusDirectory *directory)
{
- NautilusDesktopDirectory *desktop;
+ NautilusDesktopDirectory *desktop;
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
- if (!nautilus_directory_are_all_files_seen (desktop->details->real_directory)) {
- return FALSE;
- }
+ if (!nautilus_directory_are_all_files_seen (desktop->details->real_directory))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
desktop_is_not_empty (NautilusDirectory *directory)
{
- NautilusDesktopDirectory *desktop;
+ NautilusDesktopDirectory *desktop;
- desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (directory);
- if (nautilus_directory_is_not_empty (desktop->details->real_directory)) {
- return TRUE;
- }
+ if (nautilus_directory_is_not_empty (desktop->details->real_directory))
+ {
+ return TRUE;
+ }
- return directory->details->file_list != NULL;
+ return directory->details->file_list != NULL;
}
static GList *
desktop_get_file_list (NautilusDirectory *directory)
{
- GList *real_dir_file_list, *desktop_dir_file_list = NULL;
-
- real_dir_file_list = nautilus_directory_get_file_list
- (NAUTILUS_DESKTOP_DIRECTORY (directory)->details->real_directory);
- desktop_dir_file_list = NAUTILUS_DIRECTORY_CLASS (nautilus_desktop_directory_parent_class)->get_file_list (directory);
+ GList *real_dir_file_list, *desktop_dir_file_list = NULL;
+
+ real_dir_file_list = nautilus_directory_get_file_list
+ (NAUTILUS_DESKTOP_DIRECTORY (directory)->details->real_directory);
+ desktop_dir_file_list = NAUTILUS_DIRECTORY_CLASS (nautilus_desktop_directory_parent_class)->get_file_list (directory);
- return g_list_concat (real_dir_file_list, desktop_dir_file_list);
+ return g_list_concat (real_dir_file_list, desktop_dir_file_list);
}
NautilusDirectory *
nautilus_desktop_directory_get_real_directory (NautilusDesktopDirectory *desktop)
{
- nautilus_directory_ref (desktop->details->real_directory);
- return desktop->details->real_directory;
+ nautilus_directory_ref (desktop->details->real_directory);
+ return desktop->details->real_directory;
}
static void
desktop_finalize (GObject *object)
{
- NautilusDesktopDirectory *desktop;
+ NautilusDesktopDirectory *desktop;
- desktop = NAUTILUS_DESKTOP_DIRECTORY (object);
+ desktop = NAUTILUS_DESKTOP_DIRECTORY (object);
- nautilus_directory_unref (desktop->details->real_directory);
+ nautilus_directory_unref (desktop->details->real_directory);
- g_hash_table_destroy (desktop->details->callbacks);
- g_hash_table_destroy (desktop->details->monitors);
- g_free (desktop->details);
+ g_hash_table_destroy (desktop->details->callbacks);
+ g_hash_table_destroy (desktop->details->monitors);
+ g_free (desktop->details);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- desktop_directory_changed_callback,
- desktop);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ desktop_directory_changed_callback,
+ desktop);
- G_OBJECT_CLASS (nautilus_desktop_directory_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_desktop_directory_parent_class)->finalize (object);
}
static void
-done_loading_callback (NautilusDirectory *real_directory,
- NautilusDesktopDirectory *desktop)
+done_loading_callback (NautilusDirectory *real_directory,
+ NautilusDesktopDirectory *desktop)
{
- nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (desktop));
+ nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (desktop));
}
static void
forward_files_added_cover (NautilusDirectory *real_directory,
- GList *files,
- gpointer callback_data)
+ GList *files,
+ gpointer callback_data)
{
- nautilus_directory_emit_files_added (NAUTILUS_DIRECTORY (callback_data), files);
+ nautilus_directory_emit_files_added (NAUTILUS_DIRECTORY (callback_data), files);
}
static void
forward_files_changed_cover (NautilusDirectory *real_directory,
- GList *files,
- gpointer callback_data)
+ GList *files,
+ gpointer callback_data)
{
- nautilus_directory_emit_files_changed (NAUTILUS_DIRECTORY (callback_data), files);
+ nautilus_directory_emit_files_changed (NAUTILUS_DIRECTORY (callback_data), files);
}
static void
update_desktop_directory (NautilusDesktopDirectory *desktop)
{
- char *desktop_path;
- char *desktop_uri;
- NautilusDirectory *real_directory;
-
- real_directory = desktop->details->real_directory;
- if (real_directory != NULL) {
- g_hash_table_foreach_remove (desktop->details->callbacks, (GHRFunc) gtk_true, NULL);
- g_hash_table_foreach_remove (desktop->details->monitors, (GHRFunc) gtk_true, NULL);
-
- g_signal_handlers_disconnect_by_func (real_directory, done_loading_callback, desktop);
- g_signal_handlers_disconnect_by_func (real_directory, forward_files_added_cover, desktop);
- g_signal_handlers_disconnect_by_func (real_directory, forward_files_changed_cover, desktop);
-
- nautilus_directory_unref (real_directory);
- }
-
- desktop_path = nautilus_get_desktop_directory ();
- desktop_uri = g_filename_to_uri (desktop_path, NULL, NULL);
- real_directory = nautilus_directory_get_by_uri (desktop_uri);
- g_free (desktop_uri);
- g_free (desktop_path);
-
- g_signal_connect_object (real_directory, "done-loading",
- G_CALLBACK (done_loading_callback), desktop, 0);
- g_signal_connect_object (real_directory, "files-added",
- G_CALLBACK (forward_files_added_cover), desktop, 0);
- g_signal_connect_object (real_directory, "files-changed",
- G_CALLBACK (forward_files_changed_cover), desktop, 0);
-
- desktop->details->real_directory = real_directory;
+ char *desktop_path;
+ char *desktop_uri;
+ NautilusDirectory *real_directory;
+
+ real_directory = desktop->details->real_directory;
+ if (real_directory != NULL)
+ {
+ g_hash_table_foreach_remove (desktop->details->callbacks, (GHRFunc) gtk_true, NULL);
+ g_hash_table_foreach_remove (desktop->details->monitors, (GHRFunc) gtk_true, NULL);
+
+ g_signal_handlers_disconnect_by_func (real_directory, done_loading_callback, desktop);
+ g_signal_handlers_disconnect_by_func (real_directory, forward_files_added_cover, desktop);
+ g_signal_handlers_disconnect_by_func (real_directory, forward_files_changed_cover, desktop);
+
+ nautilus_directory_unref (real_directory);
+ }
+
+ desktop_path = nautilus_get_desktop_directory ();
+ desktop_uri = g_filename_to_uri (desktop_path, NULL, NULL);
+ real_directory = nautilus_directory_get_by_uri (desktop_uri);
+ g_free (desktop_uri);
+ g_free (desktop_path);
+
+ g_signal_connect_object (real_directory, "done-loading",
+ G_CALLBACK (done_loading_callback), desktop, 0);
+ g_signal_connect_object (real_directory, "files-added",
+ G_CALLBACK (forward_files_added_cover), desktop, 0);
+ g_signal_connect_object (real_directory, "files-changed",
+ G_CALLBACK (forward_files_changed_cover), desktop, 0);
+
+ desktop->details->real_directory = real_directory;
}
static NautilusFile *
@@ -493,79 +508,81 @@ real_new_file_from_filename (NautilusDirectory *directory,
const char *filename,
gboolean self_owned)
{
- NautilusFile *file;
+ NautilusFile *file;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (filename != NULL);
- g_assert (filename[0] != '\0');
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (filename != NULL);
+ g_assert (filename[0] != '\0');
- if (self_owned) {
- file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE, NULL));
- } else {
- g_critical ("Accessing desktop uris directly is not supported.");
+ if (self_owned)
+ {
+ file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_DIRECTORY_FILE, NULL));
+ }
+ else
+ {
+ g_critical ("Accessing desktop uris directly is not supported.");
- return NULL;
- }
+ return NULL;
+ }
- nautilus_file_set_directory (file, directory);
+ nautilus_file_set_directory (file, directory);
- return file;
+ return file;
}
static gboolean
real_handles_location (GFile *location)
{
- g_autofree gchar *uri;
+ g_autofree gchar *uri;
- uri = g_file_get_uri (location);
+ uri = g_file_get_uri (location);
- return eel_uri_is_desktop (uri);
+ return eel_uri_is_desktop (uri);
}
static void
desktop_directory_changed_callback (gpointer data)
{
- update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (data));
- nautilus_directory_force_reload (NAUTILUS_DIRECTORY (data));
+ update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (data));
+ nautilus_directory_force_reload (NAUTILUS_DIRECTORY (data));
}
static void
nautilus_desktop_directory_init (NautilusDesktopDirectory *desktop)
{
- desktop->details = g_new0 (NautilusDesktopDirectoryDetails, 1);
+ desktop->details = g_new0 (NautilusDesktopDirectoryDetails, 1);
- desktop->details->callbacks = g_hash_table_new_full
- (merged_callback_hash, merged_callback_equal,
- NULL, (GDestroyNotify)merged_callback_destroy);
- desktop->details->monitors = g_hash_table_new_full (NULL, NULL,
- NULL, (GDestroyNotify)merged_monitor_destroy);
+ desktop->details->callbacks = g_hash_table_new_full
+ (merged_callback_hash, merged_callback_equal,
+ NULL, (GDestroyNotify) merged_callback_destroy);
+ desktop->details->monitors = g_hash_table_new_full (NULL, NULL,
+ NULL, (GDestroyNotify) merged_monitor_destroy);
- update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (desktop));
+ update_desktop_directory (NAUTILUS_DESKTOP_DIRECTORY (desktop));
}
static void
nautilus_desktop_directory_class_init (NautilusDesktopDirectoryClass *class)
{
- NautilusDirectoryClass *directory_class;
-
- directory_class = NAUTILUS_DIRECTORY_CLASS (class);
-
- G_OBJECT_CLASS (class)->finalize = desktop_finalize;
-
- directory_class->contains_file = desktop_contains_file;
- directory_class->call_when_ready = desktop_call_when_ready;
- directory_class->cancel_callback = desktop_cancel_callback;
- directory_class->file_monitor_add = desktop_monitor_add;
- directory_class->file_monitor_remove = desktop_monitor_remove;
- directory_class->force_reload = desktop_force_reload;
- directory_class->are_all_files_seen = desktop_are_all_files_seen;
- directory_class->is_not_empty = desktop_is_not_empty;
- directory_class->new_file_from_filename = real_new_file_from_filename;
- directory_class->handles_location = real_handles_location;
- /* Override get_file_list so that we can return the list of files
- * in NautilusDesktopDirectory->details->real_directory,
- * in addition to the list of standard desktop icons on the desktop.
- */
- directory_class->get_file_list = desktop_get_file_list;
+ NautilusDirectoryClass *directory_class;
+
+ directory_class = NAUTILUS_DIRECTORY_CLASS (class);
+
+ G_OBJECT_CLASS (class)->finalize = desktop_finalize;
+
+ directory_class->contains_file = desktop_contains_file;
+ directory_class->call_when_ready = desktop_call_when_ready;
+ directory_class->cancel_callback = desktop_cancel_callback;
+ directory_class->file_monitor_add = desktop_monitor_add;
+ directory_class->file_monitor_remove = desktop_monitor_remove;
+ directory_class->force_reload = desktop_force_reload;
+ directory_class->are_all_files_seen = desktop_are_all_files_seen;
+ directory_class->is_not_empty = desktop_is_not_empty;
+ directory_class->new_file_from_filename = real_new_file_from_filename;
+ directory_class->handles_location = real_handles_location;
+ /* Override get_file_list so that we can return the list of files
+ * in NautilusDesktopDirectory->details->real_directory,
+ * in addition to the list of standard desktop icons on the desktop.
+ */
+ directory_class->get_file_list = desktop_get_file_list;
}
-
diff --git a/nautilus-desktop/nautilus-desktop-icon-file.c b/nautilus-desktop/nautilus-desktop-icon-file.c
index 3afdf8e39..a35190f3f 100644
--- a/nautilus-desktop/nautilus-desktop-icon-file.c
+++ b/nautilus-desktop/nautilus-desktop-icon-file.c
@@ -1,24 +1,24 @@
/*
- nautilus-desktop-icon-file.c: Subclass of NautilusFile to help implement the
- virtual desktop icons.
-
- Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-desktop-icon-file.c: Subclass of NautilusFile to help implement the
+ * virtual desktop icons.
+ *
+ * Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include "nautilus-desktop-icon-file.h"
@@ -40,334 +40,354 @@
#include <string.h>
#include <gio/gio.h>
-struct NautilusDesktopIconFileDetails {
- NautilusDesktopLink *link;
+struct NautilusDesktopIconFileDetails
+{
+ NautilusDesktopLink *link;
};
-G_DEFINE_TYPE(NautilusDesktopIconFile, nautilus_desktop_icon_file, NAUTILUS_TYPE_FILE)
+G_DEFINE_TYPE (NautilusDesktopIconFile, nautilus_desktop_icon_file, NAUTILUS_TYPE_FILE)
static void
-desktop_icon_file_monitor_add (NautilusFile *file,
- gconstpointer client,
- NautilusFileAttributes attributes)
+desktop_icon_file_monitor_add (NautilusFile *file,
+ gconstpointer client,
+ NautilusFileAttributes attributes)
{
- nautilus_directory_monitor_add_internal
- (file->details->directory, file,
- client, TRUE, attributes, NULL, NULL);
+ nautilus_directory_monitor_add_internal
+ (file->details->directory, file,
+ client, TRUE, attributes, NULL, NULL);
}
static void
-desktop_icon_file_monitor_remove (NautilusFile *file,
- gconstpointer client)
+desktop_icon_file_monitor_remove (NautilusFile *file,
+ gconstpointer client)
{
- nautilus_directory_monitor_remove_internal
- (file->details->directory, file, client);
+ nautilus_directory_monitor_remove_internal
+ (file->details->directory, file, client);
}
static void
-desktop_icon_file_call_when_ready (NautilusFile *file,
- NautilusFileAttributes attributes,
- NautilusFileCallback callback,
- gpointer callback_data)
+desktop_icon_file_call_when_ready (NautilusFile *file,
+ NautilusFileAttributes attributes,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- nautilus_directory_call_when_ready_internal
- (file->details->directory, file,
- attributes, FALSE, NULL, callback, callback_data);
+ nautilus_directory_call_when_ready_internal
+ (file->details->directory, file,
+ attributes, FALSE, NULL, callback, callback_data);
}
static void
-desktop_icon_file_cancel_call_when_ready (NautilusFile *file,
- NautilusFileCallback callback,
- gpointer callback_data)
+desktop_icon_file_cancel_call_when_ready (NautilusFile *file,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- nautilus_directory_cancel_callback_internal
- (file->details->directory, file,
- NULL, callback, callback_data);
+ nautilus_directory_cancel_callback_internal
+ (file->details->directory, file,
+ NULL, callback, callback_data);
}
static gboolean
-desktop_icon_file_check_if_ready (NautilusFile *file,
- NautilusFileAttributes attributes)
+desktop_icon_file_check_if_ready (NautilusFile *file,
+ NautilusFileAttributes attributes)
{
- return nautilus_directory_check_if_ready_internal
- (file->details->directory, file,
- attributes);
+ return nautilus_directory_check_if_ready_internal
+ (file->details->directory, file,
+ attributes);
}
static gboolean
desktop_icon_file_get_item_count (NautilusFile *file,
- guint *count,
- gboolean *count_unreadable)
+ guint *count,
+ gboolean *count_unreadable)
{
- if (count != NULL) {
- *count = 0;
- }
- if (count_unreadable != NULL) {
- *count_unreadable = FALSE;
- }
- return TRUE;
+ if (count != NULL)
+ {
+ *count = 0;
+ }
+ if (count_unreadable != NULL)
+ {
+ *count_unreadable = FALSE;
+ }
+ return TRUE;
}
static NautilusRequestStatus
desktop_icon_file_get_deep_counts (NautilusFile *file,
- guint *directory_count,
- guint *file_count,
- guint *unreadable_directory_count,
- goffset *total_size)
+ guint *directory_count,
+ guint *file_count,
+ guint *unreadable_directory_count,
+ goffset *total_size)
{
- if (directory_count != NULL) {
- *directory_count = 0;
- }
- if (file_count != NULL) {
- *file_count = 0;
- }
- if (unreadable_directory_count != NULL) {
- *unreadable_directory_count = 0;
- }
- if (total_size != NULL) {
- *total_size = 0;
- }
-
- return NAUTILUS_REQUEST_DONE;
+ if (directory_count != NULL)
+ {
+ *directory_count = 0;
+ }
+ if (file_count != NULL)
+ {
+ *file_count = 0;
+ }
+ if (unreadable_directory_count != NULL)
+ {
+ *unreadable_directory_count = 0;
+ }
+ if (total_size != NULL)
+ {
+ *total_size = 0;
+ }
+
+ return NAUTILUS_REQUEST_DONE;
}
static gboolean
-desktop_icon_file_get_date (NautilusFile *file,
- NautilusDateType date_type,
- time_t *date)
+desktop_icon_file_get_date (NautilusFile *file,
+ NautilusDateType date_type,
+ time_t *date)
{
- NautilusDesktopIconFile *desktop_file;
+ NautilusDesktopIconFile *desktop_file;
- desktop_file = NAUTILUS_DESKTOP_ICON_FILE (file);
+ desktop_file = NAUTILUS_DESKTOP_ICON_FILE (file);
- return nautilus_desktop_link_get_date (desktop_file->details->link,
- date_type, date);
+ return nautilus_desktop_link_get_date (desktop_file->details->link,
+ date_type, date);
}
static char *
desktop_icon_file_get_where_string (NautilusFile *file)
{
- return g_strdup (_("on the desktop"));
+ return g_strdup (_("on the desktop"));
}
static void
nautilus_desktop_icon_file_init (NautilusDesktopIconFile *desktop_file)
{
- desktop_file->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_file,
- NAUTILUS_TYPE_DESKTOP_ICON_FILE,
- NautilusDesktopIconFileDetails);
+ desktop_file->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_file,
+ NAUTILUS_TYPE_DESKTOP_ICON_FILE,
+ NautilusDesktopIconFileDetails);
}
static void
update_info_from_link (NautilusDesktopIconFile *icon_file)
{
- NautilusFile *file;
- NautilusDesktopLink *link;
- char *display_name;
- GMount *mount;
-
- file = NAUTILUS_FILE (icon_file);
-
- link = icon_file->details->link;
-
- if (link == NULL) {
- return;
- }
-
- eel_ref_str_unref (file->details->mime_type);
- file->details->mime_type = eel_ref_str_get_unique ("application/x-nautilus-link");
- file->details->type = G_FILE_TYPE_SHORTCUT;
- file->details->size = 0;
- file->details->has_permissions = FALSE;
- file->details->can_read = TRUE;
- file->details->can_write = TRUE;
-
- file->details->can_mount = FALSE;
- file->details->can_unmount = FALSE;
- file->details->can_eject = FALSE;
- if (file->details->mount) {
- g_object_unref (file->details->mount);
- }
- mount = nautilus_desktop_link_get_mount (link);
- file->details->mount = mount;
- if (mount) {
- file->details->can_unmount = g_mount_can_unmount (mount);
- file->details->can_eject = g_mount_can_eject (mount);
- }
-
- file->details->file_info_is_up_to_date = TRUE;
-
- display_name = nautilus_desktop_link_get_display_name (link);
- nautilus_file_set_display_name (file,
- display_name, NULL, TRUE);
- g_free (display_name);
-
- if (file->details->icon != NULL) {
- g_object_unref (file->details->icon);
- }
- file->details->icon = nautilus_desktop_link_get_icon (link);
- g_free (file->details->activation_uri);
- file->details->activation_uri = nautilus_desktop_link_get_activation_uri (link);
- file->details->got_link_info = TRUE;
- file->details->link_info_is_up_to_date = TRUE;
-
- file->details->directory_count = 0;
- file->details->got_directory_count = TRUE;
- file->details->directory_count_is_up_to_date = TRUE;
+ NautilusFile *file;
+ NautilusDesktopLink *link;
+ char *display_name;
+ GMount *mount;
+
+ file = NAUTILUS_FILE (icon_file);
+
+ link = icon_file->details->link;
+
+ if (link == NULL)
+ {
+ return;
+ }
+
+ eel_ref_str_unref (file->details->mime_type);
+ file->details->mime_type = eel_ref_str_get_unique ("application/x-nautilus-link");
+ file->details->type = G_FILE_TYPE_SHORTCUT;
+ file->details->size = 0;
+ file->details->has_permissions = FALSE;
+ file->details->can_read = TRUE;
+ file->details->can_write = TRUE;
+
+ file->details->can_mount = FALSE;
+ file->details->can_unmount = FALSE;
+ file->details->can_eject = FALSE;
+ if (file->details->mount)
+ {
+ g_object_unref (file->details->mount);
+ }
+ mount = nautilus_desktop_link_get_mount (link);
+ file->details->mount = mount;
+ if (mount)
+ {
+ file->details->can_unmount = g_mount_can_unmount (mount);
+ file->details->can_eject = g_mount_can_eject (mount);
+ }
+
+ file->details->file_info_is_up_to_date = TRUE;
+
+ display_name = nautilus_desktop_link_get_display_name (link);
+ nautilus_file_set_display_name (file,
+ display_name, NULL, TRUE);
+ g_free (display_name);
+
+ if (file->details->icon != NULL)
+ {
+ g_object_unref (file->details->icon);
+ }
+ file->details->icon = nautilus_desktop_link_get_icon (link);
+ g_free (file->details->activation_uri);
+ file->details->activation_uri = nautilus_desktop_link_get_activation_uri (link);
+ file->details->got_link_info = TRUE;
+ file->details->link_info_is_up_to_date = TRUE;
+
+ file->details->directory_count = 0;
+ file->details->got_directory_count = TRUE;
+ file->details->directory_count_is_up_to_date = TRUE;
}
void
nautilus_desktop_icon_file_update (NautilusDesktopIconFile *icon_file)
{
- NautilusFile *file;
+ NautilusFile *file;
- update_info_from_link (icon_file);
- file = NAUTILUS_FILE (icon_file);
- nautilus_file_changed (file);
+ update_info_from_link (icon_file);
+ file = NAUTILUS_FILE (icon_file);
+ nautilus_file_changed (file);
}
void
nautilus_desktop_icon_file_remove (NautilusDesktopIconFile *icon_file)
{
- NautilusFile *file;
- GList list;
+ NautilusFile *file;
+ GList list;
- icon_file->details->link = NULL;
+ icon_file->details->link = NULL;
- file = NAUTILUS_FILE (icon_file);
+ file = NAUTILUS_FILE (icon_file);
- /* ref here because we might be removing the last ref when we
- * mark the file gone below, but we need to keep a ref at
- * least long enough to send the change notification.
- */
- nautilus_file_ref (file);
+ /* ref here because we might be removing the last ref when we
+ * mark the file gone below, but we need to keep a ref at
+ * least long enough to send the change notification.
+ */
+ nautilus_file_ref (file);
- file->details->is_gone = TRUE;
+ file->details->is_gone = TRUE;
- list.data = file;
- list.next = NULL;
- list.prev = NULL;
+ list.data = file;
+ list.next = NULL;
+ list.prev = NULL;
- nautilus_directory_remove_file (file->details->directory, file);
- nautilus_directory_emit_change_signals (file->details->directory, &list);
+ nautilus_directory_remove_file (file->details->directory, file);
+ nautilus_directory_emit_change_signals (file->details->directory, &list);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
NautilusDesktopIconFile *
nautilus_desktop_icon_file_new (NautilusDesktopLink *link)
{
- NautilusFile *file;
- NautilusDirectory *directory;
- NautilusDesktopIconFile *icon_file;
- GList list;
- char *name;
+ NautilusFile *file;
+ NautilusDirectory *directory;
+ NautilusDesktopIconFile *icon_file;
+ GList list;
+ char *name;
- directory = nautilus_directory_get_by_uri (EEL_DESKTOP_URI);
+ directory = nautilus_directory_get_by_uri (EEL_DESKTOP_URI);
- file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_ICON_FILE, NULL));
+ file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_DESKTOP_ICON_FILE, NULL));
#ifdef NAUTILUS_FILE_DEBUG_REF
- printf("%10p ref'd\n", file);
- eazel_dump_stack_trace ("\t", 10);
+ printf ("%10p ref'd\n", file);
+ eazel_dump_stack_trace ("\t", 10);
#endif
- nautilus_file_set_directory (file, directory);
+ nautilus_file_set_directory (file, directory);
- icon_file = NAUTILUS_DESKTOP_ICON_FILE (file);
- icon_file->details->link = link;
+ icon_file = NAUTILUS_DESKTOP_ICON_FILE (file);
+ icon_file->details->link = link;
- name = nautilus_desktop_link_get_file_name (link);
- file->details->name = eel_ref_str_new (name);
- g_free (name);
+ name = nautilus_desktop_link_get_file_name (link);
+ file->details->name = eel_ref_str_new (name);
+ g_free (name);
- update_info_from_link (icon_file);
+ update_info_from_link (icon_file);
- nautilus_desktop_update_metadata_from_keyfile (file, file->details->name);
+ nautilus_desktop_update_metadata_from_keyfile (file, file->details->name);
- nautilus_directory_add_file (directory, file);
+ nautilus_directory_add_file (directory, file);
- list.data = file;
- list.next = NULL;
- list.prev = NULL;
- nautilus_directory_emit_files_added (directory, &list);
+ list.data = file;
+ list.next = NULL;
+ list.prev = NULL;
+ nautilus_directory_emit_files_added (directory, &list);
- return icon_file;
+ return icon_file;
}
/* Note: This can return NULL if the link was recently removed (i.e. unmounted) */
NautilusDesktopLink *
nautilus_desktop_icon_file_get_link (NautilusDesktopIconFile *icon_file)
{
- if (icon_file->details->link)
- return g_object_ref (icon_file->details->link);
- else
- return NULL;
+ if (icon_file->details->link)
+ {
+ return g_object_ref (icon_file->details->link);
+ }
+ else
+ {
+ return NULL;
+ }
}
static void
-nautilus_desktop_icon_file_unmount (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+nautilus_desktop_icon_file_unmount (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopIconFile *desktop_file;
- GMount *mount;
-
- desktop_file = NAUTILUS_DESKTOP_ICON_FILE (file);
- if (desktop_file) {
- mount = nautilus_desktop_link_get_mount (desktop_file->details->link);
- if (mount != NULL) {
- nautilus_file_operations_unmount_mount (NULL, mount, FALSE, TRUE);
- }
- }
-
+ NautilusDesktopIconFile *desktop_file;
+ GMount *mount;
+
+ desktop_file = NAUTILUS_DESKTOP_ICON_FILE (file);
+ if (desktop_file)
+ {
+ mount = nautilus_desktop_link_get_mount (desktop_file->details->link);
+ if (mount != NULL)
+ {
+ nautilus_file_operations_unmount_mount (NULL, mount, FALSE, TRUE);
+ }
+ }
}
static void
-nautilus_desktop_icon_file_eject (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+nautilus_desktop_icon_file_eject (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusDesktopIconFile *desktop_file;
- GMount *mount;
-
- desktop_file = NAUTILUS_DESKTOP_ICON_FILE (file);
- if (desktop_file) {
- mount = nautilus_desktop_link_get_mount (desktop_file->details->link);
- if (mount != NULL) {
- nautilus_file_operations_unmount_mount (NULL, mount, TRUE, TRUE);
- }
- }
+ NautilusDesktopIconFile *desktop_file;
+ GMount *mount;
+
+ desktop_file = NAUTILUS_DESKTOP_ICON_FILE (file);
+ if (desktop_file)
+ {
+ mount = nautilus_desktop_link_get_mount (desktop_file->details->link);
+ if (mount != NULL)
+ {
+ nautilus_file_operations_unmount_mount (NULL, mount, TRUE, TRUE);
+ }
+ }
}
-static char*
+static char *
real_get_target_uri (NautilusFile *file)
{
- char *uri = NULL;
- GFile *location;
- NautilusDesktopLink *link;
+ char *uri = NULL;
+ GFile *location;
+ NautilusDesktopLink *link;
- g_return_val_if_fail (NAUTILUS_IS_DESKTOP_ICON_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DESKTOP_ICON_FILE (file), NULL);
- link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+ link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
- if (link != NULL) {
- location = nautilus_desktop_link_get_activation_location (link);
- g_object_unref (link);
- if (location != NULL) {
- uri = g_file_get_uri (location);
- g_object_unref (location);
+ if (link != NULL)
+ {
+ location = nautilus_desktop_link_get_activation_location (link);
+ g_object_unref (link);
+ if (location != NULL)
+ {
+ uri = g_file_get_uri (location);
+ g_object_unref (location);
- return uri;
- }
- }
+ return uri;
+ }
+ }
- return NAUTILUS_FILE_CLASS (nautilus_desktop_icon_file_parent_class)->get_target_uri (file);
+ return NAUTILUS_FILE_CLASS (nautilus_desktop_icon_file_parent_class)->get_target_uri (file);
}
static void
@@ -376,145 +396,155 @@ real_rename (NautilusFile *file,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- NautilusDesktopLink *link;
- char *old_name;
- gboolean success;
- GError *error;
-
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (new_name != NULL);
- g_return_if_fail (callback != NULL);
-
- /* Can't rename a file that's already gone.
- * We need to check this here because there may be a new
- * file with the same name.
- */
- if (nautilus_file_rename_handle_file_gone (file, callback, callback_data)) {
- return;
- }
-
- link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
- old_name = nautilus_file_get_display_name (file);
-
- if ((old_name != NULL && strcmp (new_name, old_name) == 0)) {
- success = TRUE;
- } else {
- success = (link != NULL && nautilus_desktop_link_rename (link, new_name));
- }
-
- if (success) {
- (* callback) (file, NULL, NULL, callback_data);
- } else {
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Unable to rename desktop icon"));
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- }
-
- g_free (old_name);
- g_object_unref (link);
-
- return;
+ NautilusDesktopLink *link;
+ char *old_name;
+ gboolean success;
+ GError *error;
+
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (new_name != NULL);
+ g_return_if_fail (callback != NULL);
+
+ /* Can't rename a file that's already gone.
+ * We need to check this here because there may be a new
+ * file with the same name.
+ */
+ if (nautilus_file_rename_handle_file_gone (file, callback, callback_data))
+ {
+ return;
+ }
+
+ link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+ old_name = nautilus_file_get_display_name (file);
+
+ if ((old_name != NULL && strcmp (new_name, old_name) == 0))
+ {
+ success = TRUE;
+ }
+ else
+ {
+ success = (link != NULL && nautilus_desktop_link_rename (link, new_name));
+ }
+
+ if (success)
+ {
+ (*callback)(file, NULL, NULL, callback_data);
+ }
+ else
+ {
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Unable to rename desktop icon"));
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+
+ g_free (old_name);
+ g_object_unref (link);
+
+ return;
}
static gboolean
real_can_rename (NautilusFile *file)
{
- NautilusDesktopLink *link;
- gboolean can_rename;
+ NautilusDesktopLink *link;
+ gboolean can_rename;
- can_rename = NAUTILUS_FILE_CLASS (nautilus_desktop_icon_file_parent_class)->can_rename (file);
+ can_rename = NAUTILUS_FILE_CLASS (nautilus_desktop_icon_file_parent_class)->can_rename (file);
- if (!can_rename)
- return FALSE;
+ if (!can_rename)
+ {
+ return FALSE;
+ }
- link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
+ link = nautilus_desktop_icon_file_get_link (NAUTILUS_DESKTOP_ICON_FILE (file));
- /* Certain types of links can't be renamed */
- if (link != NULL) {
- can_rename = nautilus_desktop_link_can_rename (link);
- g_object_unref (link);
- }
+ /* Certain types of links can't be renamed */
+ if (link != NULL)
+ {
+ can_rename = nautilus_desktop_link_can_rename (link);
+ g_object_unref (link);
+ }
- return can_rename;
+ return can_rename;
}
static gboolean
real_drag_can_accept_files (NautilusFile *drop_target_item)
{
- return TRUE;
+ return TRUE;
}
static void
real_invalidate_attributes_internal (NautilusFile *file,
NautilusFileAttributes attributes)
{
- /* Desktop icon files are always up to date.
- * If we invalidate their attributes they
- * will lose data, so we just ignore them.
- */
- return;
+ /* Desktop icon files are always up to date.
+ * If we invalidate their attributes they
+ * will lose data, so we just ignore them.
+ */
+ return;
}
static gboolean
real_opens_in_view (NautilusFile *file)
{
- return TRUE;
+ return TRUE;
}
static gboolean
real_is_special_link (NautilusFile *file)
{
- return TRUE;
+ return TRUE;
}
static void
-nautilus_desktop_icon_file_set_metadata (NautilusFile *file,
- const char *key,
- const char *value)
+nautilus_desktop_icon_file_set_metadata (NautilusFile *file,
+ const char *key,
+ const char *value)
{
- nautilus_desktop_set_metadata_string (file, file->details->name, key, value);
+ nautilus_desktop_set_metadata_string (file, file->details->name, key, value);
}
static void
-nautilus_desktop_icon_file_set_metadata_as_list (NautilusFile *file,
- const char *key,
- char **value)
+nautilus_desktop_icon_file_set_metadata_as_list (NautilusFile *file,
+ const char *key,
+ char **value)
{
- nautilus_desktop_set_metadata_stringv (file, file->details->name, key, (const gchar **) value);
+ nautilus_desktop_set_metadata_stringv (file, file->details->name, key, (const gchar **) value);
}
static void
nautilus_desktop_icon_file_class_init (NautilusDesktopIconFileClass *klass)
{
- GObjectClass *object_class;
- NautilusFileClass *file_class;
-
- object_class = G_OBJECT_CLASS (klass);
- file_class = NAUTILUS_FILE_CLASS (klass);
-
- file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
-
- file_class->monitor_add = desktop_icon_file_monitor_add;
- file_class->monitor_remove = desktop_icon_file_monitor_remove;
- file_class->call_when_ready = desktop_icon_file_call_when_ready;
- file_class->cancel_call_when_ready = desktop_icon_file_cancel_call_when_ready;
- file_class->check_if_ready = desktop_icon_file_check_if_ready;
- file_class->get_item_count = desktop_icon_file_get_item_count;
- file_class->get_deep_counts = desktop_icon_file_get_deep_counts;
- file_class->get_date = desktop_icon_file_get_date;
- file_class->get_where_string = desktop_icon_file_get_where_string;
- file_class->set_metadata = nautilus_desktop_icon_file_set_metadata;
- file_class->set_metadata_as_list = nautilus_desktop_icon_file_set_metadata_as_list;
- file_class->unmount = nautilus_desktop_icon_file_unmount;
- file_class->eject = nautilus_desktop_icon_file_eject;
- file_class->can_rename = real_can_rename;
- file_class->rename = real_rename;
- file_class->get_target_uri = real_get_target_uri;
- file_class->drag_can_accept_files = real_drag_can_accept_files;
- file_class->invalidate_attributes_internal = real_invalidate_attributes_internal;
- file_class->opens_in_view = real_opens_in_view;
- file_class->is_special_link = real_is_special_link;
-
- g_type_class_add_private (object_class, sizeof(NautilusDesktopIconFileDetails));
+ GObjectClass *object_class;
+ NautilusFileClass *file_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ file_class = NAUTILUS_FILE_CLASS (klass);
+
+ file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
+
+ file_class->monitor_add = desktop_icon_file_monitor_add;
+ file_class->monitor_remove = desktop_icon_file_monitor_remove;
+ file_class->call_when_ready = desktop_icon_file_call_when_ready;
+ file_class->cancel_call_when_ready = desktop_icon_file_cancel_call_when_ready;
+ file_class->check_if_ready = desktop_icon_file_check_if_ready;
+ file_class->get_item_count = desktop_icon_file_get_item_count;
+ file_class->get_deep_counts = desktop_icon_file_get_deep_counts;
+ file_class->get_date = desktop_icon_file_get_date;
+ file_class->get_where_string = desktop_icon_file_get_where_string;
+ file_class->set_metadata = nautilus_desktop_icon_file_set_metadata;
+ file_class->set_metadata_as_list = nautilus_desktop_icon_file_set_metadata_as_list;
+ file_class->unmount = nautilus_desktop_icon_file_unmount;
+ file_class->eject = nautilus_desktop_icon_file_eject;
+ file_class->can_rename = real_can_rename;
+ file_class->rename = real_rename;
+ file_class->get_target_uri = real_get_target_uri;
+ file_class->drag_can_accept_files = real_drag_can_accept_files;
+ file_class->invalidate_attributes_internal = real_invalidate_attributes_internal;
+ file_class->opens_in_view = real_opens_in_view;
+ file_class->is_special_link = real_is_special_link;
+
+ g_type_class_add_private (object_class, sizeof (NautilusDesktopIconFileDetails));
}
diff --git a/nautilus-desktop/nautilus-desktop-link-monitor.c b/nautilus-desktop/nautilus-desktop-link-monitor.c
index 346e88b85..955150fa4 100644
--- a/nautilus-desktop/nautilus-desktop-link-monitor.c
+++ b/nautilus-desktop/nautilus-desktop-link-monitor.c
@@ -1,23 +1,23 @@
/*
- nautilus-desktop-link-monitor.c: singleton thatn manages the links
-
- Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-desktop-link-monitor.c: singleton thatn manages the links
+ *
+ * Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include "nautilus-desktop-link-monitor.h"
@@ -38,15 +38,16 @@
#include <string.h>
-struct NautilusDesktopLinkMonitorDetails {
- GVolumeMonitor *volume_monitor;
- NautilusDirectory *desktop_dir;
-
- NautilusDesktopLink *home_link;
- NautilusDesktopLink *trash_link;
- NautilusDesktopLink *network_link;
+struct NautilusDesktopLinkMonitorDetails
+{
+ GVolumeMonitor *volume_monitor;
+ NautilusDirectory *desktop_dir;
+
+ NautilusDesktopLink *home_link;
+ NautilusDesktopLink *trash_link;
+ NautilusDesktopLink *network_link;
- GList *mount_links;
+ GList *mount_links;
};
G_DEFINE_TYPE (NautilusDesktopLinkMonitor, nautilus_desktop_link_monitor, G_TYPE_OBJECT);
@@ -56,377 +57,404 @@ static NautilusDesktopLinkMonitor *the_link_monitor = NULL;
void
nautilus_desktop_link_monitor_shutdown (void)
{
- g_clear_object (&the_link_monitor);
+ g_clear_object (&the_link_monitor);
}
NautilusDesktopLinkMonitor *
nautilus_desktop_link_monitor_get (void)
{
- if (the_link_monitor == NULL) {
- g_object_new (NAUTILUS_TYPE_DESKTOP_LINK_MONITOR, NULL);
- eel_debug_call_at_shutdown (nautilus_desktop_link_monitor_shutdown);
- }
- return the_link_monitor;
+ if (the_link_monitor == NULL)
+ {
+ g_object_new (NAUTILUS_TYPE_DESKTOP_LINK_MONITOR, NULL);
+ eel_debug_call_at_shutdown (nautilus_desktop_link_monitor_shutdown);
+ }
+ return the_link_monitor;
}
static gboolean
volume_file_name_used (NautilusDesktopLinkMonitor *monitor,
- const char *name)
+ const char *name)
{
- GList *l;
- char *other_name;
- gboolean same;
-
- for (l = monitor->details->mount_links; l != NULL; l = l->next) {
- other_name = nautilus_desktop_link_get_file_name (l->data);
- same = strcmp (name, other_name) == 0;
- g_free (other_name);
-
- if (same) {
- return TRUE;
- }
- }
-
- return FALSE;
+ GList *l;
+ char *other_name;
+ gboolean same;
+
+ for (l = monitor->details->mount_links; l != NULL; l = l->next)
+ {
+ other_name = nautilus_desktop_link_get_file_name (l->data);
+ same = strcmp (name, other_name) == 0;
+ g_free (other_name);
+
+ if (same)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
}
char *
nautilus_desktop_link_monitor_make_filename_unique (NautilusDesktopLinkMonitor *monitor,
- const char *filename)
+ const char *filename)
{
- char *unique_name;
- int i;
-
- i = 2;
- unique_name = g_strdup (filename);
- while (volume_file_name_used (monitor, unique_name)) {
- g_free (unique_name);
- unique_name = g_strdup_printf ("%s.%d", filename, i++);
- }
- return unique_name;
+ char *unique_name;
+ int i;
+
+ i = 2;
+ unique_name = g_strdup (filename);
+ while (volume_file_name_used (monitor, unique_name))
+ {
+ g_free (unique_name);
+ unique_name = g_strdup_printf ("%s.%d", filename, i++);
+ }
+ return unique_name;
}
static gboolean
has_mount (NautilusDesktopLinkMonitor *monitor,
- GMount *mount)
+ GMount *mount)
{
- gboolean ret;
- GMount *other_mount;
- GList *l;
-
- ret = FALSE;
-
- for (l = monitor->details->mount_links; l != NULL; l = l->next) {
- other_mount = nautilus_desktop_link_get_mount (l->data);
- if (mount == other_mount) {
- g_object_unref (other_mount);
- ret = TRUE;
- break;
- }
- g_object_unref (other_mount);
- }
-
- return ret;
+ gboolean ret;
+ GMount *other_mount;
+ GList *l;
+
+ ret = FALSE;
+
+ for (l = monitor->details->mount_links; l != NULL; l = l->next)
+ {
+ other_mount = nautilus_desktop_link_get_mount (l->data);
+ if (mount == other_mount)
+ {
+ g_object_unref (other_mount);
+ ret = TRUE;
+ break;
+ }
+ g_object_unref (other_mount);
+ }
+
+ return ret;
}
static void
create_mount_link (NautilusDesktopLinkMonitor *monitor,
- GMount *mount)
+ GMount *mount)
{
- NautilusDesktopLink *link;
-
- if (has_mount (monitor, mount))
- return;
-
- if ((!g_mount_is_shadowed (mount)) &&
- g_settings_get_boolean (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE)) {
- link = nautilus_desktop_link_new_from_mount (mount);
- monitor->details->mount_links = g_list_prepend (monitor->details->mount_links, link);
- }
+ NautilusDesktopLink *link;
+
+ if (has_mount (monitor, mount))
+ {
+ return;
+ }
+
+ if ((!g_mount_is_shadowed (mount)) &&
+ g_settings_get_boolean (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE))
+ {
+ link = nautilus_desktop_link_new_from_mount (mount);
+ monitor->details->mount_links = g_list_prepend (monitor->details->mount_links, link);
+ }
}
static void
remove_mount_link (NautilusDesktopLinkMonitor *monitor,
- GMount *mount)
+ GMount *mount)
{
- GList *l;
- NautilusDesktopLink *link;
- GMount *other_mount;
-
- link = NULL;
- for (l = monitor->details->mount_links; l != NULL; l = l->next) {
- other_mount = nautilus_desktop_link_get_mount (l->data);
- if (mount == other_mount) {
- g_object_unref (other_mount);
- link = l->data;
- break;
- }
- g_object_unref (other_mount);
- }
-
- if (link) {
- monitor->details->mount_links = g_list_remove (monitor->details->mount_links, link);
- g_object_unref (link);
- }
+ GList *l;
+ NautilusDesktopLink *link;
+ GMount *other_mount;
+
+ link = NULL;
+ for (l = monitor->details->mount_links; l != NULL; l = l->next)
+ {
+ other_mount = nautilus_desktop_link_get_mount (l->data);
+ if (mount == other_mount)
+ {
+ g_object_unref (other_mount);
+ link = l->data;
+ break;
+ }
+ g_object_unref (other_mount);
+ }
+
+ if (link)
+ {
+ monitor->details->mount_links = g_list_remove (monitor->details->mount_links, link);
+ g_object_unref (link);
+ }
}
static void
-mount_added_callback (GVolumeMonitor *volume_monitor,
- GMount *mount,
- NautilusDesktopLinkMonitor *monitor)
+mount_added_callback (GVolumeMonitor *volume_monitor,
+ GMount *mount,
+ NautilusDesktopLinkMonitor *monitor)
{
- create_mount_link (monitor, mount);
+ create_mount_link (monitor, mount);
}
static void
-mount_removed_callback (GVolumeMonitor *volume_monitor,
- GMount *mount,
- NautilusDesktopLinkMonitor *monitor)
+mount_removed_callback (GVolumeMonitor *volume_monitor,
+ GMount *mount,
+ NautilusDesktopLinkMonitor *monitor)
{
- remove_mount_link (monitor, mount);
+ remove_mount_link (monitor, mount);
}
static void
-mount_changed_callback (GVolumeMonitor *volume_monitor,
- GMount *mount,
- NautilusDesktopLinkMonitor *monitor)
+mount_changed_callback (GVolumeMonitor *volume_monitor,
+ GMount *mount,
+ NautilusDesktopLinkMonitor *monitor)
{
- /* TODO: update the mount with other details */
+ /* TODO: update the mount with other details */
- /* remove a mount if it goes into the shadows */
- if (g_mount_is_shadowed (mount) && has_mount (monitor, mount)) {
- remove_mount_link (monitor, mount);
- }}
+ /* remove a mount if it goes into the shadows */
+ if (g_mount_is_shadowed (mount) && has_mount (monitor, mount))
+ {
+ remove_mount_link (monitor, mount);
+ }
+}
static void
-update_link_visibility (NautilusDesktopLinkMonitor *monitor,
- NautilusDesktopLink **link_ref,
- NautilusDesktopLinkType link_type,
- const char *preference_key)
+update_link_visibility (NautilusDesktopLinkMonitor *monitor,
+ NautilusDesktopLink **link_ref,
+ NautilusDesktopLinkType link_type,
+ const char *preference_key)
{
- if (g_settings_get_boolean (nautilus_desktop_preferences, preference_key)) {
- if (*link_ref == NULL) {
- *link_ref = nautilus_desktop_link_new (link_type);
- }
- } else {
- if (*link_ref != NULL) {
- g_object_unref (*link_ref);
- *link_ref = NULL;
- }
- }
+ if (g_settings_get_boolean (nautilus_desktop_preferences, preference_key))
+ {
+ if (*link_ref == NULL)
+ {
+ *link_ref = nautilus_desktop_link_new (link_type);
+ }
+ }
+ else
+ {
+ if (*link_ref != NULL)
+ {
+ g_object_unref (*link_ref);
+ *link_ref = NULL;
+ }
+ }
}
static void
desktop_home_visible_changed (gpointer callback_data)
{
- NautilusDesktopLinkMonitor *monitor;
+ NautilusDesktopLinkMonitor *monitor;
- monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
+ monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
- update_link_visibility (NAUTILUS_DESKTOP_LINK_MONITOR (monitor),
- &monitor->details->home_link,
- NAUTILUS_DESKTOP_LINK_HOME,
- NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE);
+ update_link_visibility (NAUTILUS_DESKTOP_LINK_MONITOR (monitor),
+ &monitor->details->home_link,
+ NAUTILUS_DESKTOP_LINK_HOME,
+ NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE);
}
static void
desktop_trash_visible_changed (gpointer callback_data)
{
- NautilusDesktopLinkMonitor *monitor;
+ NautilusDesktopLinkMonitor *monitor;
- monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
+ monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
- update_link_visibility (NAUTILUS_DESKTOP_LINK_MONITOR (callback_data),
- &monitor->details->trash_link,
- NAUTILUS_DESKTOP_LINK_TRASH,
- NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE);
+ update_link_visibility (NAUTILUS_DESKTOP_LINK_MONITOR (callback_data),
+ &monitor->details->trash_link,
+ NAUTILUS_DESKTOP_LINK_TRASH,
+ NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE);
}
static void
desktop_network_visible_changed (gpointer callback_data)
{
- NautilusDesktopLinkMonitor *monitor;
+ NautilusDesktopLinkMonitor *monitor;
- monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
+ monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
- update_link_visibility (NAUTILUS_DESKTOP_LINK_MONITOR (callback_data),
- &monitor->details->network_link,
- NAUTILUS_DESKTOP_LINK_NETWORK,
- NAUTILUS_PREFERENCES_DESKTOP_NETWORK_VISIBLE);
+ update_link_visibility (NAUTILUS_DESKTOP_LINK_MONITOR (callback_data),
+ &monitor->details->network_link,
+ NAUTILUS_DESKTOP_LINK_NETWORK,
+ NAUTILUS_PREFERENCES_DESKTOP_NETWORK_VISIBLE);
}
static void
desktop_volumes_visible_changed (gpointer callback_data)
{
- NautilusDesktopLinkMonitor *monitor;
- GList *l, *mounts;
-
- monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
-
- if (g_settings_get_boolean (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE)) {
- if (monitor->details->mount_links == NULL) {
- mounts = g_volume_monitor_get_mounts (monitor->details->volume_monitor);
- for (l = mounts; l != NULL; l = l->next) {
- create_mount_link (monitor, l->data);
- g_object_unref (l->data);
- }
- g_list_free (mounts);
- }
- } else {
- g_list_foreach (monitor->details->mount_links, (GFunc)g_object_unref, NULL);
- g_list_free (monitor->details->mount_links);
- monitor->details->mount_links = NULL;
- }
+ NautilusDesktopLinkMonitor *monitor;
+ GList *l, *mounts;
+
+ monitor = NAUTILUS_DESKTOP_LINK_MONITOR (callback_data);
+
+ if (g_settings_get_boolean (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE))
+ {
+ if (monitor->details->mount_links == NULL)
+ {
+ mounts = g_volume_monitor_get_mounts (monitor->details->volume_monitor);
+ for (l = mounts; l != NULL; l = l->next)
+ {
+ create_mount_link (monitor, l->data);
+ g_object_unref (l->data);
+ }
+ g_list_free (mounts);
+ }
+ }
+ else
+ {
+ g_list_foreach (monitor->details->mount_links, (GFunc) g_object_unref, NULL);
+ g_list_free (monitor->details->mount_links);
+ monitor->details->mount_links = NULL;
+ }
}
static void
-create_link_and_add_preference (NautilusDesktopLink **link_ref,
- NautilusDesktopLinkType link_type,
- const char *preference_key,
- GCallback callback,
- gpointer callback_data)
+create_link_and_add_preference (NautilusDesktopLink **link_ref,
+ NautilusDesktopLinkType link_type,
+ const char *preference_key,
+ GCallback callback,
+ gpointer callback_data)
{
- char *detailed_signal;
+ char *detailed_signal;
- if (g_settings_get_boolean (nautilus_desktop_preferences, preference_key)) {
- *link_ref = nautilus_desktop_link_new (link_type);
- }
+ if (g_settings_get_boolean (nautilus_desktop_preferences, preference_key))
+ {
+ *link_ref = nautilus_desktop_link_new (link_type);
+ }
- detailed_signal = g_strconcat ("changed::", preference_key, NULL);
- g_signal_connect_swapped (nautilus_desktop_preferences,
- detailed_signal,
- callback, callback_data);
+ detailed_signal = g_strconcat ("changed::", preference_key, NULL);
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ detailed_signal,
+ callback, callback_data);
- g_free (detailed_signal);
+ g_free (detailed_signal);
}
static void
nautilus_desktop_link_monitor_init (NautilusDesktopLinkMonitor *monitor)
{
- GList *l, *mounts;
- GMount *mount;
-
- monitor->details = G_TYPE_INSTANCE_GET_PRIVATE (monitor, NAUTILUS_TYPE_DESKTOP_LINK_MONITOR,
- NautilusDesktopLinkMonitorDetails);
-
- the_link_monitor = monitor;
- monitor->details->volume_monitor = g_volume_monitor_get ();
-
- /* We keep around a ref to the desktop dir */
- monitor->details->desktop_dir = nautilus_directory_get_by_uri (EEL_DESKTOP_URI);
-
- /* Default links */
-
- create_link_and_add_preference (&monitor->details->home_link,
- NAUTILUS_DESKTOP_LINK_HOME,
- NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE,
- G_CALLBACK (desktop_home_visible_changed),
- monitor);
-
- create_link_and_add_preference (&monitor->details->trash_link,
- NAUTILUS_DESKTOP_LINK_TRASH,
- NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE,
- G_CALLBACK (desktop_trash_visible_changed),
- monitor);
-
- create_link_and_add_preference (&monitor->details->network_link,
- NAUTILUS_DESKTOP_LINK_NETWORK,
- NAUTILUS_PREFERENCES_DESKTOP_NETWORK_VISIBLE,
- G_CALLBACK (desktop_network_visible_changed),
- monitor);
-
- /* Mount links */
-
- mounts = g_volume_monitor_get_mounts (monitor->details->volume_monitor);
- for (l = mounts; l != NULL; l = l->next) {
- mount = l->data;
- create_mount_link (monitor, mount);
- g_object_unref (mount);
- }
- g_list_free (mounts);
-
- g_signal_connect_swapped (nautilus_desktop_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE,
- G_CALLBACK (desktop_volumes_visible_changed),
- monitor);
-
- g_signal_connect_object (monitor->details->volume_monitor, "mount-added",
- G_CALLBACK (mount_added_callback), monitor, 0);
- g_signal_connect_object (monitor->details->volume_monitor, "mount-removed",
- G_CALLBACK (mount_removed_callback), monitor, 0);
- g_signal_connect_object (monitor->details->volume_monitor, "mount-changed",
- G_CALLBACK (mount_changed_callback), monitor, 0);
+ GList *l, *mounts;
+ GMount *mount;
+
+ monitor->details = G_TYPE_INSTANCE_GET_PRIVATE (monitor, NAUTILUS_TYPE_DESKTOP_LINK_MONITOR,
+ NautilusDesktopLinkMonitorDetails);
+
+ the_link_monitor = monitor;
+ monitor->details->volume_monitor = g_volume_monitor_get ();
+
+ /* We keep around a ref to the desktop dir */
+ monitor->details->desktop_dir = nautilus_directory_get_by_uri (EEL_DESKTOP_URI);
+
+ /* Default links */
+
+ create_link_and_add_preference (&monitor->details->home_link,
+ NAUTILUS_DESKTOP_LINK_HOME,
+ NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE,
+ G_CALLBACK (desktop_home_visible_changed),
+ monitor);
+
+ create_link_and_add_preference (&monitor->details->trash_link,
+ NAUTILUS_DESKTOP_LINK_TRASH,
+ NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE,
+ G_CALLBACK (desktop_trash_visible_changed),
+ monitor);
+
+ create_link_and_add_preference (&monitor->details->network_link,
+ NAUTILUS_DESKTOP_LINK_NETWORK,
+ NAUTILUS_PREFERENCES_DESKTOP_NETWORK_VISIBLE,
+ G_CALLBACK (desktop_network_visible_changed),
+ monitor);
+
+ /* Mount links */
+
+ mounts = g_volume_monitor_get_mounts (monitor->details->volume_monitor);
+ for (l = mounts; l != NULL; l = l->next)
+ {
+ mount = l->data;
+ create_mount_link (monitor, mount);
+ g_object_unref (mount);
+ }
+ g_list_free (mounts);
+
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_VOLUMES_VISIBLE,
+ G_CALLBACK (desktop_volumes_visible_changed),
+ monitor);
+
+ g_signal_connect_object (monitor->details->volume_monitor, "mount-added",
+ G_CALLBACK (mount_added_callback), monitor, 0);
+ g_signal_connect_object (monitor->details->volume_monitor, "mount-removed",
+ G_CALLBACK (mount_removed_callback), monitor, 0);
+ g_signal_connect_object (monitor->details->volume_monitor, "mount-changed",
+ G_CALLBACK (mount_changed_callback), monitor, 0);
}
static void
-remove_link_and_preference (NautilusDesktopLink **link_ref,
- const char *preference_key,
- GCallback callback,
- gpointer callback_data)
+remove_link_and_preference (NautilusDesktopLink **link_ref,
+ const char *preference_key,
+ GCallback callback,
+ gpointer callback_data)
{
- if (*link_ref != NULL) {
- g_object_unref (*link_ref);
- *link_ref = NULL;
- }
-
- g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
- callback, callback_data);
+ if (*link_ref != NULL)
+ {
+ g_object_unref (*link_ref);
+ *link_ref = NULL;
+ }
+
+ g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
+ callback, callback_data);
}
static void
desktop_link_monitor_finalize (GObject *object)
{
- NautilusDesktopLinkMonitor *monitor;
+ NautilusDesktopLinkMonitor *monitor;
- monitor = NAUTILUS_DESKTOP_LINK_MONITOR (object);
+ monitor = NAUTILUS_DESKTOP_LINK_MONITOR (object);
- /* Default links */
+ /* Default links */
- remove_link_and_preference (&monitor->details->home_link,
- NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE,
- G_CALLBACK (desktop_home_visible_changed),
- monitor);
+ remove_link_and_preference (&monitor->details->home_link,
+ NAUTILUS_PREFERENCES_DESKTOP_HOME_VISIBLE,
+ G_CALLBACK (desktop_home_visible_changed),
+ monitor);
- remove_link_and_preference (&monitor->details->trash_link,
- NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE,
- G_CALLBACK (desktop_trash_visible_changed),
- monitor);
+ remove_link_and_preference (&monitor->details->trash_link,
+ NAUTILUS_PREFERENCES_DESKTOP_TRASH_VISIBLE,
+ G_CALLBACK (desktop_trash_visible_changed),
+ monitor);
- remove_link_and_preference (&monitor->details->network_link,
- NAUTILUS_PREFERENCES_DESKTOP_NETWORK_VISIBLE,
- G_CALLBACK (desktop_network_visible_changed),
- monitor);
+ remove_link_and_preference (&monitor->details->network_link,
+ NAUTILUS_PREFERENCES_DESKTOP_NETWORK_VISIBLE,
+ G_CALLBACK (desktop_network_visible_changed),
+ monitor);
- /* Mounts */
+ /* Mounts */
- g_list_foreach (monitor->details->mount_links, (GFunc)g_object_unref, NULL);
- g_list_free (monitor->details->mount_links);
- monitor->details->mount_links = NULL;
+ g_list_foreach (monitor->details->mount_links, (GFunc) g_object_unref, NULL);
+ g_list_free (monitor->details->mount_links);
+ monitor->details->mount_links = NULL;
- nautilus_directory_unref (monitor->details->desktop_dir);
- monitor->details->desktop_dir = NULL;
+ nautilus_directory_unref (monitor->details->desktop_dir);
+ monitor->details->desktop_dir = NULL;
- g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
- desktop_volumes_visible_changed,
- monitor);
+ g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
+ desktop_volumes_visible_changed,
+ monitor);
- g_object_unref (monitor->details->volume_monitor);
+ g_object_unref (monitor->details->volume_monitor);
- G_OBJECT_CLASS (nautilus_desktop_link_monitor_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_desktop_link_monitor_parent_class)->finalize (object);
}
static void
nautilus_desktop_link_monitor_class_init (NautilusDesktopLinkMonitorClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
- object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = desktop_link_monitor_finalize;
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = desktop_link_monitor_finalize;
- g_type_class_add_private (klass, sizeof (NautilusDesktopLinkMonitorDetails));
+ g_type_class_add_private (klass, sizeof (NautilusDesktopLinkMonitorDetails));
}
diff --git a/nautilus-desktop/nautilus-desktop-link.c b/nautilus-desktop/nautilus-desktop-link.c
index 87ba9081c..603c248d8 100644
--- a/nautilus-desktop/nautilus-desktop-link.c
+++ b/nautilus-desktop/nautilus-desktop-link.c
@@ -1,23 +1,23 @@
/*
- nautilus-desktop-link.c: Class that handles the links on the desktop
-
- Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-desktop-link.c: Class that handles the links on the desktop
+ *
+ * Copyright (C) 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
@@ -37,400 +37,443 @@
#include <string.h>
-struct NautilusDesktopLinkDetails {
- NautilusDesktopLinkType type;
- char *filename;
- char *display_name;
- GFile *activation_location;
- GIcon *icon;
+struct NautilusDesktopLinkDetails
+{
+ NautilusDesktopLinkType type;
+ char *filename;
+ char *display_name;
+ GFile *activation_location;
+ GIcon *icon;
- NautilusDesktopIconFile *icon_file;
+ NautilusDesktopIconFile *icon_file;
- /* Just for mount icons: */
- GMount *mount;
+ /* Just for mount icons: */
+ GMount *mount;
};
-G_DEFINE_TYPE(NautilusDesktopLink, nautilus_desktop_link, G_TYPE_OBJECT)
+G_DEFINE_TYPE (NautilusDesktopLink, nautilus_desktop_link, G_TYPE_OBJECT)
static void
create_icon_file (NautilusDesktopLink *link)
{
- link->details->icon_file = nautilus_desktop_icon_file_new (link);
+ link->details->icon_file = nautilus_desktop_icon_file_new (link);
}
static void
nautilus_desktop_link_changed (NautilusDesktopLink *link)
{
- if (link->details->icon_file != NULL) {
- nautilus_desktop_icon_file_update (link->details->icon_file);
- }
+ if (link->details->icon_file != NULL)
+ {
+ nautilus_desktop_icon_file_update (link->details->icon_file);
+ }
}
static void
-mount_changed_callback (GMount *mount, NautilusDesktopLink *link)
+mount_changed_callback (GMount *mount,
+ NautilusDesktopLink *link)
{
- g_free (link->details->display_name);
- if (link->details->activation_location) {
- g_object_unref (link->details->activation_location);
- }
- if (link->details->icon) {
- g_object_unref (link->details->icon);
- }
-
- link->details->display_name = g_mount_get_name (mount);
- link->details->activation_location = g_mount_get_default_location (mount);
- link->details->icon = g_mount_get_icon (mount);
-
- nautilus_desktop_link_changed (link);
+ g_free (link->details->display_name);
+ if (link->details->activation_location)
+ {
+ g_object_unref (link->details->activation_location);
+ }
+ if (link->details->icon)
+ {
+ g_object_unref (link->details->icon);
+ }
+
+ link->details->display_name = g_mount_get_name (mount);
+ link->details->activation_location = g_mount_get_default_location (mount);
+ link->details->icon = g_mount_get_icon (mount);
+
+ nautilus_desktop_link_changed (link);
}
static GIcon *
get_desktop_trash_icon (void)
{
- const gchar *icon_name;
-
- if (nautilus_trash_monitor_is_empty ()) {
- icon_name = NAUTILUS_DESKTOP_ICON_TRASH;
- } else {
- icon_name = NAUTILUS_DESKTOP_ICON_TRASH_FULL;
- }
-
- return g_themed_icon_new (icon_name);
+ const gchar *icon_name;
+
+ if (nautilus_trash_monitor_is_empty ())
+ {
+ icon_name = NAUTILUS_DESKTOP_ICON_TRASH;
+ }
+ else
+ {
+ icon_name = NAUTILUS_DESKTOP_ICON_TRASH_FULL;
+ }
+
+ return g_themed_icon_new (icon_name);
}
static void
trash_state_changed_callback (NautilusTrashMonitor *trash_monitor,
- gboolean state,
- gpointer callback_data)
+ gboolean state,
+ gpointer callback_data)
{
- NautilusDesktopLink *link;
+ NautilusDesktopLink *link;
- link = NAUTILUS_DESKTOP_LINK (callback_data);
- g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_TRASH);
+ link = NAUTILUS_DESKTOP_LINK (callback_data);
+ g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_TRASH);
- if (link->details->icon) {
- g_object_unref (link->details->icon);
- }
- link->details->icon = get_desktop_trash_icon ();
+ if (link->details->icon)
+ {
+ g_object_unref (link->details->icon);
+ }
+ link->details->icon = get_desktop_trash_icon ();
- nautilus_desktop_link_changed (link);
+ nautilus_desktop_link_changed (link);
}
static void
home_name_changed (gpointer callback_data)
{
- NautilusDesktopLink *link;
+ NautilusDesktopLink *link;
- link = NAUTILUS_DESKTOP_LINK (callback_data);
- g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_HOME);
+ link = NAUTILUS_DESKTOP_LINK (callback_data);
+ g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_HOME);
- g_free (link->details->display_name);
- link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME);
- if (link->details->display_name[0] == 0) {
- g_free (link->details->display_name);
- link->details->display_name = g_strdup (_("Home"));
- }
+ g_free (link->details->display_name);
+ link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME);
+ if (link->details->display_name[0] == 0)
+ {
+ g_free (link->details->display_name);
+ link->details->display_name = g_strdup (_("Home"));
+ }
- nautilus_desktop_link_changed (link);
+ nautilus_desktop_link_changed (link);
}
static void
trash_name_changed (gpointer callback_data)
{
- NautilusDesktopLink *link;
+ NautilusDesktopLink *link;
- link = NAUTILUS_DESKTOP_LINK (callback_data);
- g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_TRASH);
+ link = NAUTILUS_DESKTOP_LINK (callback_data);
+ g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_TRASH);
- g_free (link->details->display_name);
- link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME);
- nautilus_desktop_link_changed (link);
+ g_free (link->details->display_name);
+ link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME);
+ nautilus_desktop_link_changed (link);
}
static void
network_name_changed (gpointer callback_data)
{
- NautilusDesktopLink *link;
+ NautilusDesktopLink *link;
- link = NAUTILUS_DESKTOP_LINK (callback_data);
- g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_NETWORK);
+ link = NAUTILUS_DESKTOP_LINK (callback_data);
+ g_assert (link->details->type == NAUTILUS_DESKTOP_LINK_NETWORK);
- g_free (link->details->display_name);
- link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME);
- nautilus_desktop_link_changed (link);
+ g_free (link->details->display_name);
+ link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME);
+ nautilus_desktop_link_changed (link);
}
NautilusDesktopLink *
nautilus_desktop_link_new (NautilusDesktopLinkType type)
{
- NautilusDesktopLink *link;
-
- link = NAUTILUS_DESKTOP_LINK (g_object_new (NAUTILUS_TYPE_DESKTOP_LINK, NULL));
-
- link->details->type = type;
- switch (type) {
- case NAUTILUS_DESKTOP_LINK_HOME:
- link->details->filename = g_strdup ("home");
- link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME);
- link->details->activation_location = g_file_new_for_path (g_get_home_dir ());
- link->details->icon = g_themed_icon_new (NAUTILUS_DESKTOP_ICON_HOME);
-
- g_signal_connect_swapped (nautilus_desktop_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME,
- G_CALLBACK (home_name_changed),
- link);
- break;
-
- case NAUTILUS_DESKTOP_LINK_TRASH:
- link->details->filename = g_strdup ("trash");
- link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME);
- link->details->activation_location = g_file_new_for_uri (EEL_TRASH_URI);
- link->details->icon = get_desktop_trash_icon ();
-
- g_signal_connect_swapped (nautilus_desktop_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME,
- G_CALLBACK (trash_name_changed),
- link);
- g_signal_connect_object (nautilus_trash_monitor_get (), "trash-state-changed",
- G_CALLBACK (trash_state_changed_callback), link, 0);
- break;
-
- case NAUTILUS_DESKTOP_LINK_NETWORK:
- link->details->filename = g_strdup ("network");
- link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME);
- link->details->activation_location = g_file_new_for_uri ("network:///");
- link->details->icon = g_themed_icon_new (NAUTILUS_DESKTOP_ICON_NETWORK);
-
- g_signal_connect_swapped (nautilus_desktop_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME,
- G_CALLBACK (network_name_changed),
- link);
- break;
-
- default:
- case NAUTILUS_DESKTOP_LINK_MOUNT:
- g_assert_not_reached();
- }
-
- create_icon_file (link);
-
- return link;
+ NautilusDesktopLink *link;
+
+ link = NAUTILUS_DESKTOP_LINK (g_object_new (NAUTILUS_TYPE_DESKTOP_LINK, NULL));
+
+ link->details->type = type;
+ switch (type)
+ {
+ case NAUTILUS_DESKTOP_LINK_HOME:
+ {
+ link->details->filename = g_strdup ("home");
+ link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME);
+ link->details->activation_location = g_file_new_for_path (g_get_home_dir ());
+ link->details->icon = g_themed_icon_new (NAUTILUS_DESKTOP_ICON_HOME);
+
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME,
+ G_CALLBACK (home_name_changed),
+ link);
+ }
+ break;
+
+ case NAUTILUS_DESKTOP_LINK_TRASH:
+ {
+ link->details->filename = g_strdup ("trash");
+ link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME);
+ link->details->activation_location = g_file_new_for_uri (EEL_TRASH_URI);
+ link->details->icon = get_desktop_trash_icon ();
+
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME,
+ G_CALLBACK (trash_name_changed),
+ link);
+ g_signal_connect_object (nautilus_trash_monitor_get (), "trash-state-changed",
+ G_CALLBACK (trash_state_changed_callback), link, 0);
+ }
+ break;
+
+ case NAUTILUS_DESKTOP_LINK_NETWORK:
+ {
+ link->details->filename = g_strdup ("network");
+ link->details->display_name = g_settings_get_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME);
+ link->details->activation_location = g_file_new_for_uri ("network:///");
+ link->details->icon = g_themed_icon_new (NAUTILUS_DESKTOP_ICON_NETWORK);
+
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME,
+ G_CALLBACK (network_name_changed),
+ link);
+ }
+ break;
+
+ default:
+ case NAUTILUS_DESKTOP_LINK_MOUNT:
+ g_assert_not_reached ();
+ }
+
+ create_icon_file (link);
+
+ return link;
}
NautilusDesktopLink *
nautilus_desktop_link_new_from_mount (GMount *mount)
{
- NautilusDesktopLink *link;
- GVolume *volume;
- char *name, *filename;
-
- link = NAUTILUS_DESKTOP_LINK (g_object_new (NAUTILUS_TYPE_DESKTOP_LINK, NULL));
-
- link->details->type = NAUTILUS_DESKTOP_LINK_MOUNT;
-
- link->details->mount = g_object_ref (mount);
-
- /* We try to use the drive name to get somewhat stable filenames
- for metadata */
- volume = g_mount_get_volume (mount);
- if (volume != NULL) {
- name = g_volume_get_name (volume);
- g_object_unref (volume);
- } else {
- name = g_mount_get_name (mount);
- }
-
- /* Replace slashes in name */
- filename = g_strconcat (g_strdelimit (name, "/", '-'), ".volume", NULL);
- link->details->filename =
- nautilus_desktop_link_monitor_make_filename_unique (nautilus_desktop_link_monitor_get (),
- filename);
- g_free (filename);
- g_free (name);
-
- link->details->display_name = g_mount_get_name (mount);
-
- link->details->activation_location = g_mount_get_default_location (mount);
- link->details->icon = g_mount_get_icon (mount);
-
- g_signal_connect_object (mount, "changed",
- G_CALLBACK (mount_changed_callback), link, 0);
-
- create_icon_file (link);
-
- return link;
+ NautilusDesktopLink *link;
+ GVolume *volume;
+ char *name, *filename;
+
+ link = NAUTILUS_DESKTOP_LINK (g_object_new (NAUTILUS_TYPE_DESKTOP_LINK, NULL));
+
+ link->details->type = NAUTILUS_DESKTOP_LINK_MOUNT;
+
+ link->details->mount = g_object_ref (mount);
+
+ /* We try to use the drive name to get somewhat stable filenames
+ * for metadata */
+ volume = g_mount_get_volume (mount);
+ if (volume != NULL)
+ {
+ name = g_volume_get_name (volume);
+ g_object_unref (volume);
+ }
+ else
+ {
+ name = g_mount_get_name (mount);
+ }
+
+ /* Replace slashes in name */
+ filename = g_strconcat (g_strdelimit (name, "/", '-'), ".volume", NULL);
+ link->details->filename =
+ nautilus_desktop_link_monitor_make_filename_unique (nautilus_desktop_link_monitor_get (),
+ filename);
+ g_free (filename);
+ g_free (name);
+
+ link->details->display_name = g_mount_get_name (mount);
+
+ link->details->activation_location = g_mount_get_default_location (mount);
+ link->details->icon = g_mount_get_icon (mount);
+
+ g_signal_connect_object (mount, "changed",
+ G_CALLBACK (mount_changed_callback), link, 0);
+
+ create_icon_file (link);
+
+ return link;
}
GMount *
nautilus_desktop_link_get_mount (NautilusDesktopLink *link)
{
- if (link->details->mount) {
- return g_object_ref (link->details->mount);
- }
- return NULL;
+ if (link->details->mount)
+ {
+ return g_object_ref (link->details->mount);
+ }
+ return NULL;
}
NautilusDesktopLinkType
nautilus_desktop_link_get_link_type (NautilusDesktopLink *link)
{
- return link->details->type;
+ return link->details->type;
}
char *
nautilus_desktop_link_get_file_name (NautilusDesktopLink *link)
{
- return g_strdup (link->details->filename);
+ return g_strdup (link->details->filename);
}
char *
nautilus_desktop_link_get_display_name (NautilusDesktopLink *link)
{
- return g_strdup (link->details->display_name);
+ return g_strdup (link->details->display_name);
}
GIcon *
nautilus_desktop_link_get_icon (NautilusDesktopLink *link)
{
- if (link->details->icon != NULL) {
- return g_object_ref (link->details->icon);
- }
- return NULL;
+ if (link->details->icon != NULL)
+ {
+ return g_object_ref (link->details->icon);
+ }
+ return NULL;
}
GFile *
nautilus_desktop_link_get_activation_location (NautilusDesktopLink *link)
{
- if (link->details->activation_location) {
- return g_object_ref (link->details->activation_location);
- }
- return NULL;
+ if (link->details->activation_location)
+ {
+ return g_object_ref (link->details->activation_location);
+ }
+ return NULL;
}
char *
nautilus_desktop_link_get_activation_uri (NautilusDesktopLink *link)
{
- if (link->details->activation_location) {
- return g_file_get_uri (link->details->activation_location);
- }
- return NULL;
+ if (link->details->activation_location)
+ {
+ return g_file_get_uri (link->details->activation_location);
+ }
+ return NULL;
}
gboolean
nautilus_desktop_link_get_date (NautilusDesktopLink *link,
- NautilusDateType date_type,
- time_t *date)
+ NautilusDateType date_type,
+ time_t *date)
{
- return FALSE;
+ return FALSE;
}
gboolean
-nautilus_desktop_link_can_rename (NautilusDesktopLink *link)
+nautilus_desktop_link_can_rename (NautilusDesktopLink *link)
{
- return (link->details->type == NAUTILUS_DESKTOP_LINK_HOME ||
- link->details->type == NAUTILUS_DESKTOP_LINK_TRASH ||
- link->details->type == NAUTILUS_DESKTOP_LINK_NETWORK);
+ return (link->details->type == NAUTILUS_DESKTOP_LINK_HOME ||
+ link->details->type == NAUTILUS_DESKTOP_LINK_TRASH ||
+ link->details->type == NAUTILUS_DESKTOP_LINK_NETWORK);
}
gboolean
-nautilus_desktop_link_rename (NautilusDesktopLink *link,
- const char *name)
+nautilus_desktop_link_rename (NautilusDesktopLink *link,
+ const char *name)
{
- switch (link->details->type) {
- case NAUTILUS_DESKTOP_LINK_HOME:
- g_settings_set_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME,
- name);
- break;
- case NAUTILUS_DESKTOP_LINK_TRASH:
- g_settings_set_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME,
- name);
- break;
- case NAUTILUS_DESKTOP_LINK_NETWORK:
- g_settings_set_string (nautilus_desktop_preferences,
- NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME,
- name);
- break;
- default:
- g_assert_not_reached ();
- /* FIXME: Do we want volume renaming?
- * We didn't support that before. */
- break;
- }
-
- return TRUE;
+ switch (link->details->type)
+ {
+ case NAUTILUS_DESKTOP_LINK_HOME:
+ {
+ g_settings_set_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_HOME_NAME,
+ name);
+ }
+ break;
+
+ case NAUTILUS_DESKTOP_LINK_TRASH:
+ {
+ g_settings_set_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_TRASH_NAME,
+ name);
+ }
+ break;
+
+ case NAUTILUS_DESKTOP_LINK_NETWORK:
+ {
+ g_settings_set_string (nautilus_desktop_preferences,
+ NAUTILUS_PREFERENCES_DESKTOP_NETWORK_NAME,
+ name);
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ /* FIXME: Do we want volume renaming?
+ * We didn't support that before. */
+ }
+ break;
+ }
+
+ return TRUE;
}
static void
nautilus_desktop_link_init (NautilusDesktopLink *link)
{
- link->details = G_TYPE_INSTANCE_GET_PRIVATE (link,
- NAUTILUS_TYPE_DESKTOP_LINK,
- NautilusDesktopLinkDetails);
+ link->details = G_TYPE_INSTANCE_GET_PRIVATE (link,
+ NAUTILUS_TYPE_DESKTOP_LINK,
+ NautilusDesktopLinkDetails);
}
static void
desktop_link_finalize (GObject *object)
{
- NautilusDesktopLink *link;
-
- link = NAUTILUS_DESKTOP_LINK (object);
-
- if (link->details->icon_file != NULL) {
- nautilus_desktop_icon_file_remove (link->details->icon_file);
- nautilus_file_unref (NAUTILUS_FILE (link->details->icon_file));
- link->details->icon_file = NULL;
- }
-
- if (link->details->type == NAUTILUS_DESKTOP_LINK_HOME) {
- g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
- home_name_changed,
- link);
- }
-
- if (link->details->type == NAUTILUS_DESKTOP_LINK_TRASH) {
- g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
- trash_name_changed,
- link);
- }
-
- if (link->details->type == NAUTILUS_DESKTOP_LINK_NETWORK) {
- g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
- network_name_changed,
- link);
- }
-
- if (link->details->type == NAUTILUS_DESKTOP_LINK_MOUNT) {
- g_object_unref (link->details->mount);
- }
-
- g_free (link->details->filename);
- g_free (link->details->display_name);
- if (link->details->activation_location) {
- g_object_unref (link->details->activation_location);
- }
- if (link->details->icon) {
- g_object_unref (link->details->icon);
- }
-
- G_OBJECT_CLASS (nautilus_desktop_link_parent_class)->finalize (object);
+ NautilusDesktopLink *link;
+
+ link = NAUTILUS_DESKTOP_LINK (object);
+
+ if (link->details->icon_file != NULL)
+ {
+ nautilus_desktop_icon_file_remove (link->details->icon_file);
+ nautilus_file_unref (NAUTILUS_FILE (link->details->icon_file));
+ link->details->icon_file = NULL;
+ }
+
+ if (link->details->type == NAUTILUS_DESKTOP_LINK_HOME)
+ {
+ g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
+ home_name_changed,
+ link);
+ }
+
+ if (link->details->type == NAUTILUS_DESKTOP_LINK_TRASH)
+ {
+ g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
+ trash_name_changed,
+ link);
+ }
+
+ if (link->details->type == NAUTILUS_DESKTOP_LINK_NETWORK)
+ {
+ g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
+ network_name_changed,
+ link);
+ }
+
+ if (link->details->type == NAUTILUS_DESKTOP_LINK_MOUNT)
+ {
+ g_object_unref (link->details->mount);
+ }
+
+ g_free (link->details->filename);
+ g_free (link->details->display_name);
+ if (link->details->activation_location)
+ {
+ g_object_unref (link->details->activation_location);
+ }
+ if (link->details->icon)
+ {
+ g_object_unref (link->details->icon);
+ }
+
+ G_OBJECT_CLASS (nautilus_desktop_link_parent_class)->finalize (object);
}
static void
nautilus_desktop_link_class_init (NautilusDesktopLinkClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
- object_class = G_OBJECT_CLASS (klass);
+ object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = desktop_link_finalize;
+ object_class->finalize = desktop_link_finalize;
- g_type_class_add_private (object_class, sizeof(NautilusDesktopLinkDetails));
+ g_type_class_add_private (object_class, sizeof (NautilusDesktopLinkDetails));
}
diff --git a/nautilus-desktop/nautilus-desktop-metadata.c b/nautilus-desktop/nautilus-desktop-metadata.c
index dd77728de..99d5ffb93 100644
--- a/nautilus-desktop/nautilus-desktop-metadata.c
+++ b/nautilus-desktop/nautilus-desktop-metadata.c
@@ -30,61 +30,61 @@
static gchar *
get_keyfile_path (void)
{
- gchar *xdg_dir, *retval;
+ gchar *xdg_dir, *retval;
- xdg_dir = nautilus_get_user_directory ();
- retval = g_build_filename (xdg_dir, "desktop-metadata", NULL);
+ xdg_dir = nautilus_get_user_directory ();
+ retval = g_build_filename (xdg_dir, "desktop-metadata", NULL);
- g_free (xdg_dir);
+ g_free (xdg_dir);
- return retval;
+ return retval;
}
void
nautilus_desktop_set_metadata_string (NautilusFile *file,
- const gchar *name,
- const gchar *key,
- const gchar *string)
+ const gchar *name,
+ const gchar *key,
+ const gchar *string)
{
- gchar *keyfile_filename;
+ gchar *keyfile_filename;
- keyfile_filename = get_keyfile_path ();
+ keyfile_filename = get_keyfile_path ();
- nautilus_keyfile_metadata_set_string (file, keyfile_filename,
- name, key, string);
+ nautilus_keyfile_metadata_set_string (file, keyfile_filename,
+ name, key, string);
- g_free (keyfile_filename);
+ g_free (keyfile_filename);
}
void
-nautilus_desktop_set_metadata_stringv (NautilusFile *file,
- const char *name,
- const char *key,
+nautilus_desktop_set_metadata_stringv (NautilusFile *file,
+ const char *name,
+ const char *key,
const char * const *stringv)
{
- gchar *keyfile_filename;
+ gchar *keyfile_filename;
- keyfile_filename = get_keyfile_path ();
+ keyfile_filename = get_keyfile_path ();
- nautilus_keyfile_metadata_set_stringv (file, keyfile_filename,
- name, key, stringv);
+ nautilus_keyfile_metadata_set_stringv (file, keyfile_filename,
+ name, key, stringv);
- g_free (keyfile_filename);
+ g_free (keyfile_filename);
}
gboolean
nautilus_desktop_update_metadata_from_keyfile (NautilusFile *file,
- const gchar *name)
+ const gchar *name)
{
- gchar *keyfile_filename;
- gboolean result;
+ gchar *keyfile_filename;
+ gboolean result;
- keyfile_filename = get_keyfile_path ();
+ keyfile_filename = get_keyfile_path ();
- result = nautilus_keyfile_metadata_update_from_keyfile (file,
- keyfile_filename,
- name);
+ result = nautilus_keyfile_metadata_update_from_keyfile (file,
+ keyfile_filename,
+ name);
- g_free (keyfile_filename);
- return result;
+ g_free (keyfile_filename);
+ return result;
}
diff --git a/nautilus-desktop/nautilus-desktop-window-slot.c b/nautilus-desktop/nautilus-desktop-window-slot.c
index be834c287..b7633cec2 100644
--- a/nautilus-desktop/nautilus-desktop-window-slot.c
+++ b/nautilus-desktop/nautilus-desktop-window-slot.c
@@ -21,7 +21,7 @@
struct _NautilusDesktopWindowSlot
{
- NautilusWindowSlot parent_instance;
+ NautilusWindowSlot parent_instance;
};
G_DEFINE_TYPE (NautilusDesktopWindowSlot, nautilus_desktop_window_slot, NAUTILUS_TYPE_WINDOW_SLOT)
@@ -30,40 +30,40 @@ static NautilusView *
real_get_view_for_location (NautilusWindowSlot *self,
GFile *location)
{
- return NAUTILUS_VIEW (nautilus_desktop_canvas_view_new (self));
+ return NAUTILUS_VIEW (nautilus_desktop_canvas_view_new (self));
}
NautilusDesktopWindowSlot *
nautilus_desktop_window_slot_new (NautilusWindow *window)
{
- return g_object_new (NAUTILUS_TYPE_DESKTOP_WINDOW_SLOT,
- "window", window,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_DESKTOP_WINDOW_SLOT,
+ "window", window,
+ NULL);
}
static void
nautilus_desktop_window_slot_class_init (NautilusDesktopWindowSlotClass *klass)
{
- NautilusWindowSlotClass *parent_class = NAUTILUS_WINDOW_SLOT_CLASS (klass);
+ NautilusWindowSlotClass *parent_class = NAUTILUS_WINDOW_SLOT_CLASS (klass);
- parent_class->get_view_for_location = real_get_view_for_location;
+ parent_class->get_view_for_location = real_get_view_for_location;
}
static void
nautilus_desktop_window_slot_init (NautilusDesktopWindowSlot *self)
{
- GAction *action;
- GActionGroup *action_group;
+ GAction *action;
+ GActionGroup *action_group;
- /* Disable search on desktop */
- action_group = gtk_widget_get_action_group (GTK_WIDGET (self), "slot");
+ /* Disable search on desktop */
+ action_group = gtk_widget_get_action_group (GTK_WIDGET (self), "slot");
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "search-visible");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "search-visible");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
- /* Disable the ability to change between types of views */
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode-toggle");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ /* Disable the ability to change between types of views */
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode-toggle");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
}
diff --git a/nautilus-desktop/nautilus-desktop-window.c b/nautilus-desktop/nautilus-desktop-window.c
index b3b4a8ea1..f35c849c6 100644
--- a/nautilus-desktop/nautilus-desktop-window.c
+++ b/nautilus-desktop/nautilus-desktop-window.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -42,30 +41,31 @@
#include <src/nautilus-window.h>
#include <src/nautilus-application.h>
-struct NautilusDesktopWindowDetails {
- gulong size_changed_id;
+struct NautilusDesktopWindowDetails
+{
+ gulong size_changed_id;
- gboolean loaded;
+ gboolean loaded;
- GtkWidget *desktop_selection;
+ GtkWidget *desktop_selection;
- gboolean composited;
- cairo_surface_t *surface;
+ gboolean composited;
+ cairo_surface_t *surface;
};
-G_DEFINE_TYPE (NautilusDesktopWindow, nautilus_desktop_window,
- NAUTILUS_TYPE_WINDOW);
+G_DEFINE_TYPE (NautilusDesktopWindow, nautilus_desktop_window,
+ NAUTILUS_TYPE_WINDOW);
static void
background_changed (NautilusDesktopWindow *window)
{
- GtkWidget *widget = GTK_WIDGET (window);
- GdkScreen *screen = gtk_widget_get_screen (widget);
+ GtkWidget *widget = GTK_WIDGET (window);
+ GdkScreen *screen = gtk_widget_get_screen (widget);
- g_clear_pointer (&window->details->surface, cairo_surface_destroy);
+ g_clear_pointer (&window->details->surface, cairo_surface_destroy);
- window->details->surface = gnome_bg_get_surface_from_root (screen);
- gtk_widget_queue_draw (widget);
+ window->details->surface = gnome_bg_get_surface_from_root (screen);
+ gtk_widget_queue_draw (widget);
}
static GdkFilterReturn
@@ -73,297 +73,309 @@ filter_func (GdkXEvent *xevent,
GdkEvent *event,
NautilusDesktopWindow *window)
{
- XEvent *xev = (XEvent *) xevent;
- GdkAtom gdkatom;
+ XEvent *xev = (XEvent *) xevent;
+ GdkAtom gdkatom;
- if (xev->type != PropertyNotify) {
- return GDK_FILTER_CONTINUE;
- }
+ if (xev->type != PropertyNotify)
+ {
+ return GDK_FILTER_CONTINUE;
+ }
- gdkatom = gdk_atom_intern_static_string ("_XROOTPMAP_ID");
- if (xev->xproperty.atom != gdk_x11_atom_to_xatom (gdkatom)) {
- return GDK_FILTER_CONTINUE;
- }
+ gdkatom = gdk_atom_intern_static_string ("_XROOTPMAP_ID");
+ if (xev->xproperty.atom != gdk_x11_atom_to_xatom (gdkatom))
+ {
+ return GDK_FILTER_CONTINUE;
+ }
- background_changed (window);
+ background_changed (window);
- return GDK_FILTER_CONTINUE;
+ return GDK_FILTER_CONTINUE;
}
static void
nautilus_desktop_window_composited_changed (GtkWidget *widget)
{
- NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (widget);
- GdkScreen *screen = gtk_widget_get_screen (widget);
- gboolean composited = gdk_screen_is_composited (screen);
- GdkWindow *root;
- gint events;
-
- if (window->details->composited == composited) {
- return;
- }
-
- window->details->composited = composited;
- root = gdk_screen_get_root_window (screen);
-
- if (composited) {
- gdk_window_remove_filter (root, (GdkFilterFunc) filter_func, window);
-
- g_clear_pointer (&window->details->surface, cairo_surface_destroy);
- } else {
- events = gdk_window_get_events (root);
-
- gdk_window_set_events (root, events | GDK_PROPERTY_CHANGE_MASK);
- gdk_window_add_filter (root, (GdkFilterFunc) filter_func, window);
- background_changed (window);
- }
+ NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (widget);
+ GdkScreen *screen = gtk_widget_get_screen (widget);
+ gboolean composited = gdk_screen_is_composited (screen);
+ GdkWindow *root;
+ gint events;
+
+ if (window->details->composited == composited)
+ {
+ return;
+ }
+
+ window->details->composited = composited;
+ root = gdk_screen_get_root_window (screen);
+
+ if (composited)
+ {
+ gdk_window_remove_filter (root, (GdkFilterFunc) filter_func, window);
+
+ g_clear_pointer (&window->details->surface, cairo_surface_destroy);
+ }
+ else
+ {
+ events = gdk_window_get_events (root);
+
+ gdk_window_set_events (root, events | GDK_PROPERTY_CHANGE_MASK);
+ gdk_window_add_filter (root, (GdkFilterFunc) filter_func, window);
+ background_changed (window);
+ }
}
static gboolean
nautilus_desktop_window_draw (GtkWidget *widget,
cairo_t *cr)
{
- NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (widget);
+ NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (widget);
- if (window->details->surface) {
- cairo_set_source_surface (cr, window->details->surface, 0, 0);
- cairo_paint (cr);
- }
+ if (window->details->surface)
+ {
+ cairo_set_source_surface (cr, window->details->surface, 0, 0);
+ cairo_paint (cr);
+ }
- return GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->draw (widget, cr);
+ return GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->draw (widget, cr);
}
static void
nautilus_desktop_window_update_directory (NautilusDesktopWindow *window)
{
- GFile *location;
-
- g_assert (NAUTILUS_IS_DESKTOP_WINDOW (window));
-
- window->details->loaded = FALSE;
- location = g_file_new_for_uri (EEL_DESKTOP_URI);
- /* We use NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE so the nautilus-window
- * doesn't call gtk_window_present () which raises the window on the stack
- * and actually hides it from the background */
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location,
- NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
- NULL, NAUTILUS_WINDOW (window), NULL);
- window->details->loaded = TRUE;
-
- g_object_unref (location);
+ GFile *location;
+
+ g_assert (NAUTILUS_IS_DESKTOP_WINDOW (window));
+
+ window->details->loaded = FALSE;
+ location = g_file_new_for_uri (EEL_DESKTOP_URI);
+ /* We use NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE so the nautilus-window
+ * doesn't call gtk_window_present () which raises the window on the stack
+ * and actually hides it from the background */
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location,
+ NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
+ NULL, NAUTILUS_WINDOW (window), NULL);
+ window->details->loaded = TRUE;
+
+ g_object_unref (location);
}
static void
nautilus_desktop_window_finalize (GObject *obj)
{
- NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (obj);
- GdkScreen *screen;
- GdkWindow *root;
+ NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (obj);
+ GdkScreen *screen;
+ GdkWindow *root;
- nautilus_desktop_link_monitor_shutdown ();
+ nautilus_desktop_link_monitor_shutdown ();
- if (window->details->composited == FALSE) {
- screen = gtk_widget_get_screen (GTK_WIDGET (window));
- root = gdk_screen_get_root_window (screen);
+ if (window->details->composited == FALSE)
+ {
+ screen = gtk_widget_get_screen (GTK_WIDGET (window));
+ root = gdk_screen_get_root_window (screen);
- gdk_window_remove_filter (root, (GdkFilterFunc) filter_func, window);
- }
+ gdk_window_remove_filter (root, (GdkFilterFunc) filter_func, window);
+ }
- g_clear_pointer (&window->details->surface, cairo_surface_destroy);
+ g_clear_pointer (&window->details->surface, cairo_surface_destroy);
- G_OBJECT_CLASS (nautilus_desktop_window_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_desktop_window_parent_class)->finalize (obj);
}
static void
nautilus_desktop_window_init_actions (NautilusDesktopWindow *window)
{
- GAction *action;
-
- /* Don't allow close action on desktop */
- action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "close-current-view");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
-
- /* Don't allow new tab on desktop */
- action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "new-tab");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
-
- /* Don't allow switching to home dir on desktop */
- action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "go-home");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ GAction *action;
+
+ /* Don't allow close action on desktop */
+ action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "close-current-view");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+
+ /* Don't allow new tab on desktop */
+ action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "new-tab");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+
+ /* Don't allow switching to home dir on desktop */
+ action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "go-home");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
}
static void
-selection_get_cb (GtkWidget *widget,
- GtkSelectionData *selection_data,
- guint info,
- guint time)
+selection_get_cb (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
{
- /* No extra targets atm */
+ /* No extra targets atm */
}
static gboolean
-selection_clear_event_cb (GtkWidget *widget,
- GdkEventSelection *event,
- NautilusDesktopWindow *window)
+selection_clear_event_cb (GtkWidget *widget,
+ GdkEventSelection *event,
+ NautilusDesktopWindow *window)
{
- gtk_widget_destroy (GTK_WIDGET (window));
+ gtk_widget_destroy (GTK_WIDGET (window));
- return TRUE;
+ return TRUE;
}
static void
nautilus_desktop_window_init_selection (NautilusDesktopWindow *window)
{
- char selection_name[32];
- GdkAtom selection_atom;
- Window selection_owner;
- GdkDisplay *display;
- GtkWidget *selection_widget;
- GdkScreen *screen;
-
- screen = gdk_screen_get_default ();
-
- g_snprintf (selection_name, sizeof (selection_name),
- "_NET_DESKTOP_MANAGER_S%d", gdk_screen_get_number (screen));
- selection_atom = gdk_atom_intern (selection_name, FALSE);
- display = gdk_screen_get_display (screen);
-
- selection_owner = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display),
- gdk_x11_atom_to_xatom_for_display (display,
- selection_atom));
- if (selection_owner != None) {
- g_critical ("Another desktop manager in use; desktop window won't be created");
- return;
- }
-
- selection_widget = gtk_invisible_new_for_screen (screen);
- /* We need this for gdk_x11_get_server_time() */
- gtk_widget_add_events (selection_widget, GDK_PROPERTY_CHANGE_MASK);
-
- if (!gtk_selection_owner_set_for_display (display,
- selection_widget,
- selection_atom,
- gdk_x11_get_server_time (gtk_widget_get_window (selection_widget)))) {
- gtk_widget_destroy (selection_widget);
- g_critical ("Can't set ourselves as selection owner for desktop manager; "
- "desktop window won't be created");
- return;
- }
-
- g_signal_connect (selection_widget, "selection-get",
- G_CALLBACK (selection_get_cb), window);
- g_signal_connect (selection_widget, "selection-clear-event",
- G_CALLBACK (selection_clear_event_cb), window);
-
- window->details->desktop_selection = selection_widget;
+ char selection_name[32];
+ GdkAtom selection_atom;
+ Window selection_owner;
+ GdkDisplay *display;
+ GtkWidget *selection_widget;
+ GdkScreen *screen;
+
+ screen = gdk_screen_get_default ();
+
+ g_snprintf (selection_name, sizeof (selection_name),
+ "_NET_DESKTOP_MANAGER_S%d", gdk_screen_get_number (screen));
+ selection_atom = gdk_atom_intern (selection_name, FALSE);
+ display = gdk_screen_get_display (screen);
+
+ selection_owner = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display),
+ gdk_x11_atom_to_xatom_for_display (display,
+ selection_atom));
+ if (selection_owner != None)
+ {
+ g_critical ("Another desktop manager in use; desktop window won't be created");
+ return;
+ }
+
+ selection_widget = gtk_invisible_new_for_screen (screen);
+ /* We need this for gdk_x11_get_server_time() */
+ gtk_widget_add_events (selection_widget, GDK_PROPERTY_CHANGE_MASK);
+
+ if (!gtk_selection_owner_set_for_display (display,
+ selection_widget,
+ selection_atom,
+ gdk_x11_get_server_time (gtk_widget_get_window (selection_widget))))
+ {
+ gtk_widget_destroy (selection_widget);
+ g_critical ("Can't set ourselves as selection owner for desktop manager; "
+ "desktop window won't be created");
+ return;
+ }
+
+ g_signal_connect (selection_widget, "selection-get",
+ G_CALLBACK (selection_get_cb), window);
+ g_signal_connect (selection_widget, "selection-clear-event",
+ G_CALLBACK (selection_clear_event_cb), window);
+
+ window->details->desktop_selection = selection_widget;
}
static void
nautilus_desktop_window_constructed (GObject *obj)
{
- AtkObject *accessible;
- NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (obj);
-
- G_OBJECT_CLASS (nautilus_desktop_window_parent_class)->constructed (obj);
-
- /* Initialize the desktop link monitor singleton */
- nautilus_desktop_link_monitor_get ();
-
- /* shouldn't really be needed given our semantic type
- * of _NET_WM_TYPE_DESKTOP, but why not
- */
- gtk_window_set_resizable (GTK_WINDOW (window),
- FALSE);
- gtk_window_set_decorated (GTK_WINDOW (window),
- FALSE);
-
- gtk_window_move (GTK_WINDOW (window), 0, 0);
-
- g_object_set_data (G_OBJECT (window), "is_desktop_window",
- GINT_TO_POINTER (1));
-
- nautilus_desktop_window_init_selection (window);
- nautilus_desktop_window_init_actions (window);
-
- if (window->details->desktop_selection != NULL) {
- /* Set the accessible name so that it doesn't inherit the cryptic desktop URI. */
- accessible = gtk_widget_get_accessible (GTK_WIDGET (window));
-
- if (accessible) {
- atk_object_set_name (accessible, _("Desktop"));
- }
-
- /* Special sawmill setting */
- gtk_window_set_wmclass (GTK_WINDOW (window), "desktop_window", "Nautilus");
-
- /* Point window at the desktop folder.
- * Note that nautilus_desktop_window_init is too early to do this.
- */
- nautilus_desktop_window_update_directory (window);
-
- /* We realize it immediately so that the NAUTILUS_DESKTOP_WINDOW_ID
- * property is set so gnome-settings-daemon doesn't try to set
- * background. And we do a gdk_flush() to be sure X gets it.
- */
- gtk_widget_realize (GTK_WIDGET (window));
- gdk_flush ();
- }
+ AtkObject *accessible;
+ NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (obj);
+
+ G_OBJECT_CLASS (nautilus_desktop_window_parent_class)->constructed (obj);
+
+ /* Initialize the desktop link monitor singleton */
+ nautilus_desktop_link_monitor_get ();
+
+ /* shouldn't really be needed given our semantic type
+ * of _NET_WM_TYPE_DESKTOP, but why not
+ */
+ gtk_window_set_resizable (GTK_WINDOW (window),
+ FALSE);
+ gtk_window_set_decorated (GTK_WINDOW (window),
+ FALSE);
+
+ gtk_window_move (GTK_WINDOW (window), 0, 0);
+
+ g_object_set_data (G_OBJECT (window), "is_desktop_window",
+ GINT_TO_POINTER (1));
+
+ nautilus_desktop_window_init_selection (window);
+ nautilus_desktop_window_init_actions (window);
+
+ if (window->details->desktop_selection != NULL)
+ {
+ /* Set the accessible name so that it doesn't inherit the cryptic desktop URI. */
+ accessible = gtk_widget_get_accessible (GTK_WIDGET (window));
+
+ if (accessible)
+ {
+ atk_object_set_name (accessible, _("Desktop"));
+ }
+
+ /* Special sawmill setting */
+ gtk_window_set_wmclass (GTK_WINDOW (window), "desktop_window", "Nautilus");
+
+ /* Point window at the desktop folder.
+ * Note that nautilus_desktop_window_init is too early to do this.
+ */
+ nautilus_desktop_window_update_directory (window);
+
+ /* We realize it immediately so that the NAUTILUS_DESKTOP_WINDOW_ID
+ * property is set so gnome-settings-daemon doesn't try to set
+ * background. And we do a gdk_flush() to be sure X gets it.
+ */
+ gtk_widget_realize (GTK_WIDGET (window));
+ gdk_flush ();
+ }
}
static void
nautilus_desktop_window_init (NautilusDesktopWindow *window)
{
- GtkWidget *widget = GTK_WIDGET (window);
+ GtkWidget *widget = GTK_WIDGET (window);
- window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_DESKTOP_WINDOW,
- NautilusDesktopWindowDetails);
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (window)),
- "nautilus-desktop-window");
+ window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_DESKTOP_WINDOW,
+ NautilusDesktopWindowDetails);
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (window)),
+ "nautilus-desktop-window");
- window->details->composited = TRUE;
- nautilus_desktop_window_composited_changed (widget);
+ window->details->composited = TRUE;
+ nautilus_desktop_window_composited_changed (widget);
}
static void
nautilus_desktop_window_screen_size_changed (GdkScreen *screen,
- NautilusDesktopWindow *window)
+ NautilusDesktopWindow *window)
{
- int width_request, height_request;
-
- width_request = gdk_screen_get_width (screen);
- height_request = gdk_screen_get_height (screen);
-
- g_object_set (window,
- "width_request", width_request,
- "height_request", height_request,
- NULL);
+ int width_request, height_request;
+
+ width_request = gdk_screen_get_width (screen);
+ height_request = gdk_screen_get_height (screen);
+
+ g_object_set (window,
+ "width_request", width_request,
+ "height_request", height_request,
+ NULL);
}
static NautilusDesktopWindow *
nautilus_desktop_window_new (void)
{
- GdkScreen *screen;
- GApplication *application;
- NautilusDesktopWindow *window;
- int width_request, height_request;
-
- application = g_application_get_default ();
- screen = gdk_screen_get_default ();
- width_request = gdk_screen_get_width (screen);
- height_request = gdk_screen_get_height (screen);
-
- window = g_object_new (NAUTILUS_TYPE_DESKTOP_WINDOW,
- "application", application,
- "disable-chrome", TRUE,
- "width_request", width_request,
- "height_request", height_request,
- NULL);
-
- return window;
+ GdkScreen *screen;
+ GApplication *application;
+ NautilusDesktopWindow *window;
+ int width_request, height_request;
+
+ application = g_application_get_default ();
+ screen = gdk_screen_get_default ();
+ width_request = gdk_screen_get_width (screen);
+ height_request = gdk_screen_get_height (screen);
+
+ window = g_object_new (NAUTILUS_TYPE_DESKTOP_WINDOW,
+ "application", application,
+ "disable-chrome", TRUE,
+ "width_request", width_request,
+ "height_request", height_request,
+ NULL);
+
+ return window;
}
static NautilusDesktopWindow *the_desktop_window = NULL;
@@ -371,148 +383,151 @@ static NautilusDesktopWindow *the_desktop_window = NULL;
void
nautilus_desktop_window_ensure (void)
{
- NautilusDesktopWindow *window;
-
- if (!the_desktop_window) {
- window = nautilus_desktop_window_new ();
- g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &the_desktop_window);
- the_desktop_window = window;
- }
+ NautilusDesktopWindow *window;
+
+ if (!the_desktop_window)
+ {
+ window = nautilus_desktop_window_new ();
+ g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &the_desktop_window);
+ the_desktop_window = window;
+ }
}
GtkWidget *
nautilus_desktop_window_get (void)
{
- return GTK_WIDGET (the_desktop_window);
+ return GTK_WIDGET (the_desktop_window);
}
static gboolean
-nautilus_desktop_window_delete_event (GtkWidget *widget,
- GdkEventAny *event)
+nautilus_desktop_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event)
{
- /* Returning true tells GTK+ not to delete the window. */
- return TRUE;
+ /* Returning true tells GTK+ not to delete the window. */
+ return TRUE;
}
static void
map (GtkWidget *widget)
{
- /* Chain up to realize our children */
- GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->map (widget);
- gdk_window_lower (gtk_widget_get_window (widget));
+ /* Chain up to realize our children */
+ GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->map (widget);
+ gdk_window_lower (gtk_widget_get_window (widget));
}
static void
unrealize (GtkWidget *widget)
{
- NautilusDesktopWindow *window;
- NautilusDesktopWindowDetails *details;
+ NautilusDesktopWindow *window;
+ NautilusDesktopWindowDetails *details;
- window = NAUTILUS_DESKTOP_WINDOW (widget);
- details = window->details;
+ window = NAUTILUS_DESKTOP_WINDOW (widget);
+ details = window->details;
- if (details->size_changed_id != 0) {
- g_signal_handler_disconnect (gtk_window_get_screen (GTK_WINDOW (window)),
- details->size_changed_id);
- details->size_changed_id = 0;
- }
+ if (details->size_changed_id != 0)
+ {
+ g_signal_handler_disconnect (gtk_window_get_screen (GTK_WINDOW (window)),
+ details->size_changed_id);
+ details->size_changed_id = 0;
+ }
- gtk_widget_destroy (details->desktop_selection);
+ gtk_widget_destroy (details->desktop_selection);
- GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->unrealize (widget);
+ GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->unrealize (widget);
}
static void
set_wmspec_desktop_hint (GdkWindow *window)
{
- GdkAtom atom;
-
- atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_DESKTOP", FALSE);
-
- gdk_property_change (window,
- gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
- gdk_x11_xatom_to_atom (XA_ATOM), 32,
- GDK_PROP_MODE_REPLACE, (guchar *) &atom, 1);
+ GdkAtom atom;
+
+ atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_DESKTOP", FALSE);
+
+ gdk_property_change (window,
+ gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
+ gdk_x11_xatom_to_atom (XA_ATOM), 32,
+ GDK_PROP_MODE_REPLACE, (guchar *) &atom, 1);
}
static void
realize (GtkWidget *widget)
{
- NautilusDesktopWindow *window;
- NautilusDesktopWindowDetails *details;
- GdkVisual *visual;
-
- window = NAUTILUS_DESKTOP_WINDOW (widget);
- details = window->details;
-
- /* Make sure we get keyboard events */
- gtk_widget_set_events (widget, gtk_widget_get_events (widget)
- | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
-
- visual = gdk_screen_get_rgba_visual (gtk_widget_get_screen (widget));
- if (visual) {
- gtk_widget_set_visual (widget, visual);
- }
-
- /* Do the work of realizing. */
- GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->realize (widget);
-
- /* This is the new way to set up the desktop window */
- set_wmspec_desktop_hint (gtk_widget_get_window (widget));
-
- details->size_changed_id =
- g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size-changed",
- G_CALLBACK (nautilus_desktop_window_screen_size_changed), window);
+ NautilusDesktopWindow *window;
+ NautilusDesktopWindowDetails *details;
+ GdkVisual *visual;
+
+ window = NAUTILUS_DESKTOP_WINDOW (widget);
+ details = window->details;
+
+ /* Make sure we get keyboard events */
+ gtk_widget_set_events (widget, gtk_widget_get_events (widget)
+ | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
+
+ visual = gdk_screen_get_rgba_visual (gtk_widget_get_screen (widget));
+ if (visual)
+ {
+ gtk_widget_set_visual (widget, visual);
+ }
+
+ /* Do the work of realizing. */
+ GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->realize (widget);
+
+ /* This is the new way to set up the desktop window */
+ set_wmspec_desktop_hint (gtk_widget_get_window (widget));
+
+ details->size_changed_id =
+ g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size-changed",
+ G_CALLBACK (nautilus_desktop_window_screen_size_changed), window);
}
static void
-real_sync_title (NautilusWindow *window,
- NautilusWindowSlot *slot)
+real_sync_title (NautilusWindow *window,
+ NautilusWindowSlot *slot)
{
- /* hardcode "Desktop" */
- gtk_window_set_title (GTK_WINDOW (window), _("Desktop"));
+ /* hardcode "Desktop" */
+ gtk_window_set_title (GTK_WINDOW (window), _("Desktop"));
}
static void
real_window_close (NautilusWindow *window)
{
- /* stub, does nothing */
- return;
+ /* stub, does nothing */
+ return;
}
static NautilusWindowSlot *
real_create_slot (NautilusWindow *window,
GFile *location)
{
- return NAUTILUS_WINDOW_SLOT (nautilus_desktop_window_slot_new (window));
+ return NAUTILUS_WINDOW_SLOT (nautilus_desktop_window_slot_new (window));
}
static void
nautilus_desktop_window_class_init (NautilusDesktopWindowClass *klass)
{
- GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
- NautilusWindowClass *nclass = NAUTILUS_WINDOW_CLASS (klass);
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+ NautilusWindowClass *nclass = NAUTILUS_WINDOW_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
- oclass->constructed = nautilus_desktop_window_constructed;
- oclass->finalize = nautilus_desktop_window_finalize;
+ oclass->constructed = nautilus_desktop_window_constructed;
+ oclass->finalize = nautilus_desktop_window_finalize;
- wclass->realize = realize;
- wclass->unrealize = unrealize;
- wclass->map = map;
- wclass->delete_event = nautilus_desktop_window_delete_event;
- wclass->composited_changed = nautilus_desktop_window_composited_changed;
- wclass->draw = nautilus_desktop_window_draw;
+ wclass->realize = realize;
+ wclass->unrealize = unrealize;
+ wclass->map = map;
+ wclass->delete_event = nautilus_desktop_window_delete_event;
+ wclass->composited_changed = nautilus_desktop_window_composited_changed;
+ wclass->draw = nautilus_desktop_window_draw;
- nclass->sync_title = real_sync_title;
- nclass->close = real_window_close;
- nclass->create_slot = real_create_slot;
+ nclass->sync_title = real_sync_title;
+ nclass->close = real_window_close;
+ nclass->create_slot = real_create_slot;
- g_type_class_add_private (klass, sizeof (NautilusDesktopWindowDetails));
+ g_type_class_add_private (klass, sizeof (NautilusDesktopWindowDetails));
}
gboolean
nautilus_desktop_window_loaded (NautilusDesktopWindow *window)
{
- return window->details->loaded;
+ return window->details->loaded;
}
diff --git a/nautilus-sendto-extension/nautilus-nste.c b/nautilus-sendto-extension/nautilus-nste.c
index 29830f597..eb25566a1 100644
--- a/nautilus-sendto-extension/nautilus-nste.c
+++ b/nautilus-sendto-extension/nautilus-nste.c
@@ -33,109 +33,122 @@ static GObjectClass *parent_class;
static void
sendto_callback (NautilusMenuItem *item,
- gpointer user_data)
+ gpointer user_data)
{
- GList *files, *scan;
- gchar *uri;
- GString *cmd;
+ GList *files, *scan;
+ gchar *uri;
+ GString *cmd;
- files = g_object_get_data (G_OBJECT (item), "files");
- cmd = g_string_new ("nautilus-sendto");
+ files = g_object_get_data (G_OBJECT (item), "files");
+ cmd = g_string_new ("nautilus-sendto");
- for (scan = files; scan; scan = scan->next) {
- NautilusFileInfo *file = scan->data;
+ for (scan = files; scan; scan = scan->next)
+ {
+ NautilusFileInfo *file = scan->data;
- uri = nautilus_file_info_get_uri (file);
- g_string_append_printf (cmd, " \"%s\"", uri);
- g_free (uri);
- }
+ uri = nautilus_file_info_get_uri (file);
+ g_string_append_printf (cmd, " \"%s\"", uri);
+ g_free (uri);
+ }
- g_spawn_command_line_async (cmd->str, NULL);
+ g_spawn_command_line_async (cmd->str, NULL);
- g_string_free (cmd, TRUE);
+ g_string_free (cmd, TRUE);
}
static gboolean
check_available_mailer ()
{
- GAppInfo *app_info;
-
- app_info = g_app_info_get_default_for_uri_scheme ("mailto");
- if (app_info) {
- g_clear_object (&app_info);
- return TRUE;
- }
- else
- return FALSE;
+ GAppInfo *app_info;
+
+ app_info = g_app_info_get_default_for_uri_scheme ("mailto");
+ if (app_info)
+ {
+ g_clear_object (&app_info);
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
static GList *
nautilus_nste_get_file_items (NautilusMenuProvider *provider,
- GtkWidget *window,
- GList *files)
+ GtkWidget *window,
+ GList *files)
{
- GList *items = NULL;
- gboolean one_item;
- NautilusMenuItem *item;
- NautilusNste *nste;
-
- nste = NAUTILUS_NSTE (provider);
- if (!nste->nst_present)
- return NULL;
-
- if (files == NULL)
- return NULL;
-
- if (!check_available_mailer ())
- return NULL;
-
- one_item = (files != NULL) && (files->next == NULL);
- if (one_item &&
- !nautilus_file_info_is_directory ((NautilusFileInfo *)files->data)) {
- item = nautilus_menu_item_new ("NautilusNste::sendto",
- _("Send to…"),
- _("Send file by mail…"),
- "document-send");
- } else {
- item = nautilus_menu_item_new ("NautilusNste::sendto",
- _("Send to…"),
- _("Send files by mail…"),
- "document-send");
- }
- g_signal_connect (item,
- "activate",
- G_CALLBACK (sendto_callback),
- provider);
- g_object_set_data_full (G_OBJECT (item),
- "files",
- nautilus_file_info_list_copy (files),
- (GDestroyNotify) nautilus_file_info_list_free);
-
- items = g_list_append (items, item);
-
- return items;
+ GList *items = NULL;
+ gboolean one_item;
+ NautilusMenuItem *item;
+ NautilusNste *nste;
+
+ nste = NAUTILUS_NSTE (provider);
+ if (!nste->nst_present)
+ {
+ return NULL;
+ }
+
+ if (files == NULL)
+ {
+ return NULL;
+ }
+
+ if (!check_available_mailer ())
+ {
+ return NULL;
+ }
+
+ one_item = (files != NULL) && (files->next == NULL);
+ if (one_item &&
+ !nautilus_file_info_is_directory ((NautilusFileInfo *) files->data))
+ {
+ item = nautilus_menu_item_new ("NautilusNste::sendto",
+ _("Send to…"),
+ _("Send file by mail…"),
+ "document-send");
+ }
+ else
+ {
+ item = nautilus_menu_item_new ("NautilusNste::sendto",
+ _("Send to…"),
+ _("Send files by mail…"),
+ "document-send");
+ }
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (sendto_callback),
+ provider);
+ g_object_set_data_full (G_OBJECT (item),
+ "files",
+ nautilus_file_info_list_copy (files),
+ (GDestroyNotify) nautilus_file_info_list_free);
+
+ items = g_list_append (items, item);
+
+ return items;
}
static void
nautilus_nste_menu_provider_iface_init (NautilusMenuProviderIface *iface)
{
- iface->get_file_items = nautilus_nste_get_file_items;
+ iface->get_file_items = nautilus_nste_get_file_items;
}
static void
nautilus_nste_instance_init (NautilusNste *nste)
{
- char *path;
+ char *path;
- path = g_find_program_in_path ("nautilus-sendto");
- nste->nst_present = (path != NULL);
- g_free (path);
+ path = g_find_program_in_path ("nautilus-sendto");
+ nste->nst_present = (path != NULL);
+ g_free (path);
}
static void
nautilus_nste_class_init (NautilusNsteClass *class)
{
- parent_class = g_type_class_peek_parent (class);
+ parent_class = g_type_class_peek_parent (class);
}
static GType nste_type = 0;
@@ -143,37 +156,39 @@ static GType nste_type = 0;
GType
nautilus_nste_get_type (void)
{
- return nste_type;
+ return nste_type;
}
void
nautilus_nste_register_type (GTypeModule *module)
{
- static const GTypeInfo info = {
- sizeof (NautilusNsteClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) nautilus_nste_class_init,
- NULL,
- NULL,
- sizeof (NautilusNste),
- 0,
- (GInstanceInitFunc) nautilus_nste_instance_init,
- };
-
- static const GInterfaceInfo menu_provider_iface_info = {
- (GInterfaceInitFunc) nautilus_nste_menu_provider_iface_init,
- NULL,
- NULL
- };
-
- nste_type = g_type_module_register_type (module,
- G_TYPE_OBJECT,
- "NautilusNste",
- &info, 0);
-
- g_type_module_add_interface (module,
- nste_type,
- NAUTILUS_TYPE_MENU_PROVIDER,
- &menu_provider_iface_info);
+ static const GTypeInfo info =
+ {
+ sizeof (NautilusNsteClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) nautilus_nste_class_init,
+ NULL,
+ NULL,
+ sizeof (NautilusNste),
+ 0,
+ (GInstanceInitFunc) nautilus_nste_instance_init,
+ };
+
+ static const GInterfaceInfo menu_provider_iface_info =
+ {
+ (GInterfaceInitFunc) nautilus_nste_menu_provider_iface_init,
+ NULL,
+ NULL
+ };
+
+ nste_type = g_type_module_register_type (module,
+ G_TYPE_OBJECT,
+ "NautilusNste",
+ &info, 0);
+
+ g_type_module_add_interface (module,
+ nste_type,
+ NAUTILUS_TYPE_MENU_PROVIDER,
+ &menu_provider_iface_info);
}
diff --git a/nautilus-sendto-extension/nautilus-sendto-module.c b/nautilus-sendto-extension/nautilus-sendto-module.c
index 24c53f6b6..8aae9be0e 100644
--- a/nautilus-sendto-extension/nautilus-sendto-module.c
+++ b/nautilus-sendto-extension/nautilus-sendto-module.c
@@ -28,12 +28,12 @@
void
-nautilus_module_initialize (GTypeModule*module)
+nautilus_module_initialize (GTypeModule *module)
{
- nautilus_nste_register_type (module);
+ nautilus_nste_register_type (module);
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
}
void
@@ -43,13 +43,12 @@ nautilus_module_shutdown (void)
void
nautilus_module_list_types (const GType **types,
- int *num_types)
+ int *num_types)
{
- static GType type_list[1];
+ static GType type_list[1];
- type_list[0] = NAUTILUS_TYPE_NSTE;
- *types = type_list;
+ type_list[0] = NAUTILUS_TYPE_NSTE;
+ *types = type_list;
- *num_types = 1;
+ *num_types = 1;
}
-
diff --git a/src/gtk/nautilusgtkplacesview.c b/src/gtk/nautilusgtkplacesview.c
index fd813c7c1..55b0d8077 100644
--- a/src/gtk/nautilusgtkplacesview.c
+++ b/src/gtk/nautilusgtkplacesview.c
@@ -49,338 +49,358 @@
struct _NautilusGtkPlacesViewPrivate
{
- GVolumeMonitor *volume_monitor;
- GtkPlacesOpenFlags open_flags;
- GtkPlacesOpenFlags current_open_flags;
-
- GFile *server_list_file;
- GFileMonitor *server_list_monitor;
-
- GCancellable *cancellable;
-
- gchar *search_query;
-
- GtkWidget *actionbar;
- GtkWidget *address_entry;
- GtkWidget *connect_button;
- GtkWidget *listbox;
- GtkWidget *popup_menu;
- GtkWidget *recent_servers_listbox;
- GtkWidget *recent_servers_popover;
- GtkWidget *recent_servers_stack;
- GtkWidget *stack;
- GtkWidget *server_adresses_popover;
- GtkWidget *network_placeholder;
- GtkWidget *network_placeholder_label;
-
- GtkSizeGroup *path_size_group;
- GtkSizeGroup *space_size_group;
-
- GtkEntryCompletion *address_entry_completion;
- GtkListStore *completion_store;
-
- GCancellable *networks_fetching_cancellable;
-
- guint local_only : 1;
- guint should_open_location : 1;
- guint should_pulse_entry : 1;
- guint entry_pulse_timeout_id;
- guint connecting_to_server : 1;
- guint mounting_volume : 1;
- guint unmounting_mount : 1;
- guint fetching_networks : 1;
- guint loading : 1;
+ GVolumeMonitor *volume_monitor;
+ GtkPlacesOpenFlags open_flags;
+ GtkPlacesOpenFlags current_open_flags;
+
+ GFile *server_list_file;
+ GFileMonitor *server_list_monitor;
+
+ GCancellable *cancellable;
+
+ gchar *search_query;
+
+ GtkWidget *actionbar;
+ GtkWidget *address_entry;
+ GtkWidget *connect_button;
+ GtkWidget *listbox;
+ GtkWidget *popup_menu;
+ GtkWidget *recent_servers_listbox;
+ GtkWidget *recent_servers_popover;
+ GtkWidget *recent_servers_stack;
+ GtkWidget *stack;
+ GtkWidget *server_adresses_popover;
+ GtkWidget *network_placeholder;
+ GtkWidget *network_placeholder_label;
+
+ GtkSizeGroup *path_size_group;
+ GtkSizeGroup *space_size_group;
+
+ GtkEntryCompletion *address_entry_completion;
+ GtkListStore *completion_store;
+
+ GCancellable *networks_fetching_cancellable;
+
+ guint local_only : 1;
+ guint should_open_location : 1;
+ guint should_pulse_entry : 1;
+ guint entry_pulse_timeout_id;
+ guint connecting_to_server : 1;
+ guint mounting_volume : 1;
+ guint unmounting_mount : 1;
+ guint fetching_networks : 1;
+ guint loading : 1;
};
-static void mount_volume (NautilusGtkPlacesView *view,
- GVolume *volume);
+static void mount_volume (NautilusGtkPlacesView *view,
+ GVolume *volume);
-static gboolean on_button_press_event (NautilusGtkPlacesViewRow *row,
- GdkEventButton *event);
+static gboolean on_button_press_event (NautilusGtkPlacesViewRow *row,
+ GdkEventButton *event);
-static void on_eject_button_clicked (GtkWidget *widget,
- NautilusGtkPlacesViewRow *row);
+static void on_eject_button_clicked (GtkWidget *widget,
+ NautilusGtkPlacesViewRow *row);
-static gboolean on_row_popup_menu (NautilusGtkPlacesViewRow *row);
+static gboolean on_row_popup_menu (NautilusGtkPlacesViewRow *row);
-static void populate_servers (NautilusGtkPlacesView *view);
+static void populate_servers (NautilusGtkPlacesView *view);
-static gboolean nautilus_gtk_places_view_get_fetching_networks (NautilusGtkPlacesView *view);
+static gboolean nautilus_gtk_places_view_get_fetching_networks (NautilusGtkPlacesView *view);
-static void nautilus_gtk_places_view_set_fetching_networks (NautilusGtkPlacesView *view,
- gboolean fetching_networks);
+static void nautilus_gtk_places_view_set_fetching_networks (NautilusGtkPlacesView *view,
+ gboolean fetching_networks);
-static void nautilus_gtk_places_view_set_loading (NautilusGtkPlacesView *view,
- gboolean loading);
+static void nautilus_gtk_places_view_set_loading (NautilusGtkPlacesView *view,
+ gboolean loading);
-static void update_loading (NautilusGtkPlacesView *view);
+static void update_loading (NautilusGtkPlacesView *view);
G_DEFINE_TYPE_WITH_PRIVATE (NautilusGtkPlacesView, nautilus_gtk_places_view, GTK_TYPE_BOX)
/* NautilusGtkPlacesView properties & signals */
-enum {
- PROP_0,
- PROP_LOCAL_ONLY,
- PROP_OPEN_FLAGS,
- PROP_FETCHING_NETWORKS,
- PROP_LOADING,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_LOCAL_ONLY,
+ PROP_OPEN_FLAGS,
+ PROP_FETCHING_NETWORKS,
+ PROP_LOADING,
+ LAST_PROP
};
-enum {
- OPEN_LOCATION,
- SHOW_ERROR_MESSAGE,
- LAST_SIGNAL
+enum
+{
+ OPEN_LOCATION,
+ SHOW_ERROR_MESSAGE,
+ LAST_SIGNAL
};
const gchar *unsupported_protocols [] =
{
- "file", "afc", "obex", "http",
- "trash", "burn", "computer",
- "archive", "recent", "localtest",
- NULL
+ "file", "afc", "obex", "http",
+ "trash", "burn", "computer",
+ "archive", "recent", "localtest",
+ NULL
};
static guint places_view_signals [LAST_SIGNAL] = { 0 };
static GParamSpec *properties [LAST_PROP];
static void
-emit_open_location (NautilusGtkPlacesView *view,
- GFile *location,
- GtkPlacesOpenFlags open_flags)
+emit_open_location (NautilusGtkPlacesView *view,
+ GFile *location,
+ GtkPlacesOpenFlags open_flags)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if ((open_flags & priv->open_flags) == 0)
- open_flags = GTK_PLACES_OPEN_NORMAL;
+ if ((open_flags & priv->open_flags) == 0)
+ {
+ open_flags = GTK_PLACES_OPEN_NORMAL;
+ }
- g_signal_emit (view, places_view_signals[OPEN_LOCATION], 0, location, open_flags);
+ g_signal_emit (view, places_view_signals[OPEN_LOCATION], 0, location, open_flags);
}
static void
emit_show_error_message (NautilusGtkPlacesView *view,
- gchar *primary_message,
- gchar *secondary_message)
+ gchar *primary_message,
+ gchar *secondary_message)
{
- g_signal_emit (view, places_view_signals[SHOW_ERROR_MESSAGE],
- 0, primary_message, secondary_message);
+ g_signal_emit (view, places_view_signals[SHOW_ERROR_MESSAGE],
+ 0, primary_message, secondary_message);
}
static void
server_file_changed_cb (NautilusGtkPlacesView *view)
{
- populate_servers (view);
+ populate_servers (view);
}
static GBookmarkFile *
server_list_load (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- GBookmarkFile *bookmarks;
- GError *error = NULL;
- gchar *datadir;
- gchar *filename;
+ NautilusGtkPlacesViewPrivate *priv;
+ GBookmarkFile *bookmarks;
+ GError *error = NULL;
+ gchar *datadir;
+ gchar *filename;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- bookmarks = g_bookmark_file_new ();
- datadir = g_build_filename (g_get_user_config_dir (), "gtk-3.0", NULL);
- filename = g_build_filename (datadir, "servers", NULL);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ bookmarks = g_bookmark_file_new ();
+ datadir = g_build_filename (g_get_user_config_dir (), "gtk-3.0", NULL);
+ filename = g_build_filename (datadir, "servers", NULL);
- g_mkdir_with_parents (datadir, 0700);
- g_bookmark_file_load_from_file (bookmarks, filename, &error);
+ g_mkdir_with_parents (datadir, 0700);
+ g_bookmark_file_load_from_file (bookmarks, filename, &error);
- if (error)
+ if (error)
{
- if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
+ if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
{
- /* only warn if the file exists */
- g_warning ("Unable to open server bookmarks: %s", error->message);
- g_clear_pointer (&bookmarks, g_bookmark_file_free);
+ /* only warn if the file exists */
+ g_warning ("Unable to open server bookmarks: %s", error->message);
+ g_clear_pointer (&bookmarks, g_bookmark_file_free);
}
- g_clear_error (&error);
+ g_clear_error (&error);
}
- /* Monitor the file in case it's modified outside this code */
- if (!priv->server_list_monitor)
+ /* Monitor the file in case it's modified outside this code */
+ if (!priv->server_list_monitor)
{
- priv->server_list_file = g_file_new_for_path (filename);
+ priv->server_list_file = g_file_new_for_path (filename);
- if (priv->server_list_file)
+ if (priv->server_list_file)
{
- priv->server_list_monitor = g_file_monitor_file (priv->server_list_file,
- G_FILE_MONITOR_NONE,
- NULL,
- &error);
+ priv->server_list_monitor = g_file_monitor_file (priv->server_list_file,
+ G_FILE_MONITOR_NONE,
+ NULL,
+ &error);
- if (error)
+ if (error)
{
- g_warning ("Cannot monitor server file: %s", error->message);
- g_clear_error (&error);
+ g_warning ("Cannot monitor server file: %s", error->message);
+ g_clear_error (&error);
}
- else
+ else
{
- g_signal_connect_swapped (priv->server_list_monitor,
- "changed",
- G_CALLBACK (server_file_changed_cb),
- view);
+ g_signal_connect_swapped (priv->server_list_monitor,
+ "changed",
+ G_CALLBACK (server_file_changed_cb),
+ view);
}
}
- g_clear_object (&priv->server_list_file);
+ g_clear_object (&priv->server_list_file);
}
- g_free (datadir);
- g_free (filename);
+ g_free (datadir);
+ g_free (filename);
- return bookmarks;
+ return bookmarks;
}
static void
server_list_save (GBookmarkFile *bookmarks)
{
- gchar *filename;
+ gchar *filename;
- filename = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "servers", NULL);
- g_bookmark_file_to_file (bookmarks, filename, NULL);
- g_free (filename);
+ filename = g_build_filename (g_get_user_config_dir (), "gtk-3.0", "servers", NULL);
+ g_bookmark_file_to_file (bookmarks, filename, NULL);
+ g_free (filename);
}
static void
server_list_add_server (NautilusGtkPlacesView *view,
- GFile *file)
+ GFile *file)
{
- GBookmarkFile *bookmarks;
- GFileInfo *info;
- GError *error;
- gchar *title;
- gchar *uri;
+ GBookmarkFile *bookmarks;
+ GFileInfo *info;
+ GError *error;
+ gchar *title;
+ gchar *uri;
- error = NULL;
- bookmarks = server_list_load (view);
+ error = NULL;
+ bookmarks = server_list_load (view);
- if (!bookmarks)
- return;
+ if (!bookmarks)
+ {
+ return;
+ }
- uri = g_file_get_uri (file);
+ uri = g_file_get_uri (file);
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
- title = g_file_info_get_attribute_as_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
+ title = g_file_info_get_attribute_as_string (info, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
- g_bookmark_file_set_title (bookmarks, uri, title);
- g_bookmark_file_set_visited (bookmarks, uri, -1);
- g_bookmark_file_add_application (bookmarks, uri, NULL, NULL);
+ g_bookmark_file_set_title (bookmarks, uri, title);
+ g_bookmark_file_set_visited (bookmarks, uri, -1);
+ g_bookmark_file_add_application (bookmarks, uri, NULL, NULL);
- server_list_save (bookmarks);
+ server_list_save (bookmarks);
- g_bookmark_file_free (bookmarks);
- g_clear_object (&info);
- g_free (title);
- g_free (uri);
+ g_bookmark_file_free (bookmarks);
+ g_clear_object (&info);
+ g_free (title);
+ g_free (uri);
}
static void
server_list_remove_server (NautilusGtkPlacesView *view,
- const gchar *uri)
+ const gchar *uri)
{
- GBookmarkFile *bookmarks;
+ GBookmarkFile *bookmarks;
- bookmarks = server_list_load (view);
+ bookmarks = server_list_load (view);
- if (!bookmarks)
- return;
+ if (!bookmarks)
+ {
+ return;
+ }
- g_bookmark_file_remove_item (bookmarks, uri, NULL);
- server_list_save (bookmarks);
+ g_bookmark_file_remove_item (bookmarks, uri, NULL);
+ server_list_save (bookmarks);
- g_bookmark_file_free (bookmarks);
+ g_bookmark_file_free (bookmarks);
}
/* Returns a toplevel GtkWindow, or NULL if none */
static GtkWindow *
get_toplevel (GtkWidget *widget)
{
- GtkWidget *toplevel;
+ GtkWidget *toplevel;
- toplevel = gtk_widget_get_toplevel (widget);
- if (!gtk_widget_is_toplevel (toplevel))
- return NULL;
- else
- return GTK_WINDOW (toplevel);
+ toplevel = gtk_widget_get_toplevel (widget);
+ if (!gtk_widget_is_toplevel (toplevel))
+ {
+ return NULL;
+ }
+ else
+ {
+ return GTK_WINDOW (toplevel);
+ }
}
static void
set_busy_cursor (NautilusGtkPlacesView *view,
- gboolean busy)
+ gboolean busy)
{
- GtkWidget *widget;
- GtkWindow *toplevel;
- GdkDisplay *display;
- GdkCursor *cursor;
+ GtkWidget *widget;
+ GtkWindow *toplevel;
+ GdkDisplay *display;
+ GdkCursor *cursor;
- toplevel = get_toplevel (GTK_WIDGET (view));
- widget = GTK_WIDGET (toplevel);
- if (!toplevel || !gtk_widget_get_realized (widget))
- return;
+ toplevel = get_toplevel (GTK_WIDGET (view));
+ widget = GTK_WIDGET (toplevel);
+ if (!toplevel || !gtk_widget_get_realized (widget))
+ {
+ return;
+ }
- display = gtk_widget_get_display (widget);
+ display = gtk_widget_get_display (widget);
- if (busy)
- cursor = gdk_cursor_new_from_name (display, "progress");
- else
- cursor = NULL;
+ if (busy)
+ {
+ cursor = gdk_cursor_new_from_name (display, "progress");
+ }
+ else
+ {
+ cursor = NULL;
+ }
- gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
- gdk_display_flush (display);
+ gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
+ gdk_display_flush (display);
- if (cursor)
- g_object_unref (cursor);
+ if (cursor)
+ {
+ g_object_unref (cursor);
+ }
}
/* Activates the given row, with the given flags as parameter */
static void
-activate_row (NautilusGtkPlacesView *view,
- NautilusGtkPlacesViewRow *row,
- GtkPlacesOpenFlags flags)
+activate_row (NautilusGtkPlacesView *view,
+ NautilusGtkPlacesViewRow *row,
+ GtkPlacesOpenFlags flags)
{
- NautilusGtkPlacesViewPrivate *priv;
- GVolume *volume;
- GMount *mount;
- GFile *file;
+ NautilusGtkPlacesViewPrivate *priv;
+ GVolume *volume;
+ GMount *mount;
+ GFile *file;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- mount = nautilus_gtk_places_view_row_get_mount (row);
- volume = nautilus_gtk_places_view_row_get_volume (row);
- file = nautilus_gtk_places_view_row_get_file (row);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ mount = nautilus_gtk_places_view_row_get_mount (row);
+ volume = nautilus_gtk_places_view_row_get_volume (row);
+ file = nautilus_gtk_places_view_row_get_file (row);
- if (file)
+ if (file)
{
- emit_open_location (view, file, flags);
+ emit_open_location (view, file, flags);
}
- else if (mount)
+ else if (mount)
{
- GFile *location = g_mount_get_default_location (mount);
+ GFile *location = g_mount_get_default_location (mount);
- emit_open_location (view, location, flags);
+ emit_open_location (view, location, flags);
- g_object_unref (location);
+ g_object_unref (location);
}
- else if (volume && g_volume_can_mount (volume))
+ else if (volume && g_volume_can_mount (volume))
{
- /*
- * When the row is activated, the unmounted volume shall
- * be mounted and opened right after.
- */
- priv->should_open_location = TRUE;
-
- nautilus_gtk_places_view_row_set_busy (row, TRUE);
- mount_volume (view, volume);
+ /*
+ * When the row is activated, the unmounted volume shall
+ * be mounted and opened right after.
+ */
+ priv->should_open_location = TRUE;
+
+ nautilus_gtk_places_view_row_set_busy (row, TRUE);
+ mount_volume (view, volume);
}
}
@@ -389,539 +409,563 @@ static void update_places (NautilusGtkPlacesView *view);
static void
nautilus_gtk_places_view_finalize (GObject *object)
{
- NautilusGtkPlacesView *self = (NautilusGtkPlacesView *)object;
- NautilusGtkPlacesViewPrivate *priv = nautilus_gtk_places_view_get_instance_private (self);
+ NautilusGtkPlacesView *self = (NautilusGtkPlacesView *) object;
+ NautilusGtkPlacesViewPrivate *priv = nautilus_gtk_places_view_get_instance_private (self);
- g_signal_handlers_disconnect_by_func (priv->volume_monitor, update_places, object);
+ g_signal_handlers_disconnect_by_func (priv->volume_monitor, update_places, object);
- if (priv->entry_pulse_timeout_id > 0)
- g_source_remove (priv->entry_pulse_timeout_id);
+ if (priv->entry_pulse_timeout_id > 0)
+ {
+ g_source_remove (priv->entry_pulse_timeout_id);
+ }
- g_cancellable_cancel (priv->cancellable);
- g_cancellable_cancel (priv->networks_fetching_cancellable);
+ g_cancellable_cancel (priv->cancellable);
+ g_cancellable_cancel (priv->networks_fetching_cancellable);
- g_clear_pointer (&priv->search_query, g_free);
- g_clear_object (&priv->server_list_file);
- g_clear_object (&priv->server_list_monitor);
- g_clear_object (&priv->volume_monitor);
- g_clear_object (&priv->cancellable);
- g_clear_object (&priv->networks_fetching_cancellable);
- g_clear_object (&priv->path_size_group);
- g_clear_object (&priv->space_size_group);
+ g_clear_pointer (&priv->search_query, g_free);
+ g_clear_object (&priv->server_list_file);
+ g_clear_object (&priv->server_list_monitor);
+ g_clear_object (&priv->volume_monitor);
+ g_clear_object (&priv->cancellable);
+ g_clear_object (&priv->networks_fetching_cancellable);
+ g_clear_object (&priv->path_size_group);
+ g_clear_object (&priv->space_size_group);
- G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->finalize (object);
}
static void
nautilus_gtk_places_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusGtkPlacesView *self = NAUTILUS_GTK_PLACES_VIEW (object);
+ NautilusGtkPlacesView *self = NAUTILUS_GTK_PLACES_VIEW (object);
- switch (prop_id)
+ switch (prop_id)
{
- case PROP_LOCAL_ONLY:
- g_value_set_boolean (value, nautilus_gtk_places_view_get_local_only (self));
- break;
+ case PROP_LOCAL_ONLY:
+ {
+ g_value_set_boolean (value, nautilus_gtk_places_view_get_local_only (self));
+ }
+ break;
- case PROP_LOADING:
- g_value_set_boolean (value, nautilus_gtk_places_view_get_loading (self));
- break;
+ case PROP_LOADING:
+ {
+ g_value_set_boolean (value, nautilus_gtk_places_view_get_loading (self));
+ }
+ break;
- case PROP_FETCHING_NETWORKS:
- g_value_set_boolean (value, nautilus_gtk_places_view_get_fetching_networks (self));
- break;
+ case PROP_FETCHING_NETWORKS:
+ {
+ g_value_set_boolean (value, nautilus_gtk_places_view_get_fetching_networks (self));
+ }
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
nautilus_gtk_places_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusGtkPlacesView *self = NAUTILUS_GTK_PLACES_VIEW (object);
+ NautilusGtkPlacesView *self = NAUTILUS_GTK_PLACES_VIEW (object);
- switch (prop_id)
+ switch (prop_id)
{
- case PROP_LOCAL_ONLY:
- nautilus_gtk_places_view_set_local_only (self, g_value_get_boolean (value));
- break;
+ case PROP_LOCAL_ONLY:
+ {
+ nautilus_gtk_places_view_set_local_only (self, g_value_get_boolean (value));
+ }
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static gboolean
is_external_volume (GVolume *volume)
{
- gboolean is_external;
- GDrive *drive;
- gchar *id;
+ gboolean is_external;
+ GDrive *drive;
+ gchar *id;
- drive = g_volume_get_drive (volume);
- id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
+ drive = g_volume_get_drive (volume);
+ id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
- is_external = g_volume_can_eject (volume);
+ is_external = g_volume_can_eject (volume);
- /* NULL volume identifier only happens on removable devices */
- is_external |= !id;
+ /* NULL volume identifier only happens on removable devices */
+ is_external |= !id;
- if (drive)
- is_external |= g_drive_is_removable (drive);
+ if (drive)
+ {
+ is_external |= g_drive_is_removable (drive);
+ }
- g_clear_object (&drive);
- g_free (id);
+ g_clear_object (&drive);
+ g_free (id);
- return is_external;
+ return is_external;
}
typedef struct
{
- gchar *uri;
- NautilusGtkPlacesView *view;
+ gchar *uri;
+ NautilusGtkPlacesView *view;
} RemoveServerData;
static void
on_remove_server_button_clicked (RemoveServerData *data)
{
- server_list_remove_server (data->view, data->uri);
+ server_list_remove_server (data->view, data->uri);
- populate_servers (data->view);
+ populate_servers (data->view);
}
static void
populate_servers (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- GBookmarkFile *server_list;
- GList *children;
- gchar **uris;
- gsize num_uris;
- gint i;
-
- priv = nautilus_gtk_places_view_get_instance_private (view);
- server_list = server_list_load (view);
+ NautilusGtkPlacesViewPrivate *priv;
+ GBookmarkFile *server_list;
+ GList *children;
+ gchar **uris;
+ gsize num_uris;
+ gint i;
- if (!server_list)
- return;
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ server_list = server_list_load (view);
- uris = g_bookmark_file_get_uris (server_list, &num_uris);
-
- gtk_stack_set_visible_child_name (GTK_STACK (priv->recent_servers_stack),
- num_uris > 0 ? "list" : "empty");
-
- if (!uris)
+ if (!server_list)
{
- g_bookmark_file_free (server_list);
- return;
+ return;
}
- /* clear previous items */
- children = gtk_container_get_children (GTK_CONTAINER (priv->recent_servers_listbox));
- g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy);
+ uris = g_bookmark_file_get_uris (server_list, &num_uris);
- gtk_list_store_clear (priv->completion_store);
+ gtk_stack_set_visible_child_name (GTK_STACK (priv->recent_servers_stack),
+ num_uris > 0 ? "list" : "empty");
- for (i = 0; i < num_uris; i++)
+ if (!uris)
{
- RemoveServerData *data;
- GtkTreeIter iter;
- GtkWidget *row;
- GtkWidget *grid;
- GtkWidget *button;
- GtkWidget *label;
- gchar *name;
- gchar *dup_uri;
-
- name = g_bookmark_file_get_title (server_list, uris[i], NULL);
- dup_uri = g_strdup (uris[i]);
-
- /* add to the completion list */
- gtk_list_store_append (priv->completion_store, &iter);
- gtk_list_store_set (priv->completion_store,
- &iter,
- 0, name,
- 1, uris[i],
- -1);
-
- /* add to the recent servers listbox */
- row = gtk_list_box_row_new ();
-
- grid = g_object_new (GTK_TYPE_GRID,
- "orientation", GTK_ORIENTATION_VERTICAL,
- "border-width", 3,
- NULL);
-
- /* name of the connected uri, if any */
- label = gtk_label_new (name);
- gtk_widget_set_hexpand (label, TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_container_add (GTK_CONTAINER (grid), label);
-
- /* the uri itself */
- label = gtk_label_new (uris[i]);
- gtk_widget_set_hexpand (label, TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
- gtk_container_add (GTK_CONTAINER (grid), label);
-
- /* remove button */
- button = gtk_button_new ();
- gtk_widget_set_halign (button, GTK_ALIGN_END);
- gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
- gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
- gtk_style_context_add_class (gtk_widget_get_style_context (button), "sidebar-button");
- gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 2);
- gtk_container_add (GTK_CONTAINER (button),
- gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_BUTTON));
-
- gtk_container_add (GTK_CONTAINER (row), grid);
- gtk_container_add (GTK_CONTAINER (priv->recent_servers_listbox), row);
-
- /* custom data */
- data = g_new0 (RemoveServerData, 1);
- data->view = view;
- data->uri = dup_uri;
-
- g_object_set_data_full (G_OBJECT (row), "uri", dup_uri, g_free);
- g_object_set_data_full (G_OBJECT (row), "remove-server-data", data, g_free);
+ g_bookmark_file_free (server_list);
+ return;
+ }
- g_signal_connect_swapped (button,
- "clicked",
- G_CALLBACK (on_remove_server_button_clicked),
- data);
+ /* clear previous items */
+ children = gtk_container_get_children (GTK_CONTAINER (priv->recent_servers_listbox));
+ g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy);
- gtk_widget_show_all (row);
+ gtk_list_store_clear (priv->completion_store);
- g_free (name);
+ for (i = 0; i < num_uris; i++)
+ {
+ RemoveServerData *data;
+ GtkTreeIter iter;
+ GtkWidget *row;
+ GtkWidget *grid;
+ GtkWidget *button;
+ GtkWidget *label;
+ gchar *name;
+ gchar *dup_uri;
+
+ name = g_bookmark_file_get_title (server_list, uris[i], NULL);
+ dup_uri = g_strdup (uris[i]);
+
+ /* add to the completion list */
+ gtk_list_store_append (priv->completion_store, &iter);
+ gtk_list_store_set (priv->completion_store,
+ &iter,
+ 0, name,
+ 1, uris[i],
+ -1);
+
+ /* add to the recent servers listbox */
+ row = gtk_list_box_row_new ();
+
+ grid = g_object_new (GTK_TYPE_GRID,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ "border-width", 3,
+ NULL);
+
+ /* name of the connected uri, if any */
+ label = gtk_label_new (name);
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_container_add (GTK_CONTAINER (grid), label);
+
+ /* the uri itself */
+ label = gtk_label_new (uris[i]);
+ gtk_widget_set_hexpand (label, TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
+ gtk_container_add (GTK_CONTAINER (grid), label);
+
+ /* remove button */
+ button = gtk_button_new ();
+ gtk_widget_set_halign (button, GTK_ALIGN_END);
+ gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
+ gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+ gtk_style_context_add_class (gtk_widget_get_style_context (button), "sidebar-button");
+ gtk_grid_attach (GTK_GRID (grid), button, 1, 0, 1, 2);
+ gtk_container_add (GTK_CONTAINER (button),
+ gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_BUTTON));
+
+ gtk_container_add (GTK_CONTAINER (row), grid);
+ gtk_container_add (GTK_CONTAINER (priv->recent_servers_listbox), row);
+
+ /* custom data */
+ data = g_new0 (RemoveServerData, 1);
+ data->view = view;
+ data->uri = dup_uri;
+
+ g_object_set_data_full (G_OBJECT (row), "uri", dup_uri, g_free);
+ g_object_set_data_full (G_OBJECT (row), "remove-server-data", data, g_free);
+
+ g_signal_connect_swapped (button,
+ "clicked",
+ G_CALLBACK (on_remove_server_button_clicked),
+ data);
+
+ gtk_widget_show_all (row);
+
+ g_free (name);
}
- g_strfreev (uris);
- g_bookmark_file_free (server_list);
+ g_strfreev (uris);
+ g_bookmark_file_free (server_list);
}
static void
update_view_mode (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- GList *children;
- GList *l;
- gboolean show_listbox;
+ NautilusGtkPlacesViewPrivate *priv;
+ GList *children;
+ GList *l;
+ gboolean show_listbox;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- show_listbox = FALSE;
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ show_listbox = FALSE;
- /* drives */
- children = gtk_container_get_children (GTK_CONTAINER (priv->listbox));
+ /* drives */
+ children = gtk_container_get_children (GTK_CONTAINER (priv->listbox));
- for (l = children; l; l = l->next)
+ for (l = children; l; l = l->next)
{
- /* GtkListBox filter rows by changing their GtkWidget::child-visible property */
- if (gtk_widget_get_child_visible (l->data))
+ /* GtkListBox filter rows by changing their GtkWidget::child-visible property */
+ if (gtk_widget_get_child_visible (l->data))
{
- show_listbox = TRUE;
- break;
+ show_listbox = TRUE;
+ break;
}
}
- g_list_free (children);
+ g_list_free (children);
- if (!show_listbox &&
- priv->search_query &&
- priv->search_query[0] != '\0')
+ if (!show_listbox &&
+ priv->search_query &&
+ priv->search_query[0] != '\0')
{
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "empty-search");
}
- else
+ else
{
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "browse");
+ gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "browse");
}
}
static void
insert_row (NautilusGtkPlacesView *view,
- GtkWidget *row,
- gboolean is_network)
+ GtkWidget *row,
+ gboolean is_network)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- g_object_set_data (G_OBJECT (row), "is-network", GINT_TO_POINTER (is_network));
+ g_object_set_data (G_OBJECT (row), "is-network", GINT_TO_POINTER (is_network));
- g_signal_connect_swapped (nautilus_gtk_places_view_row_get_event_box (NAUTILUS_GTK_PLACES_VIEW_ROW (row)),
- "button-press-event",
- G_CALLBACK (on_button_press_event),
- row);
+ g_signal_connect_swapped (nautilus_gtk_places_view_row_get_event_box (NAUTILUS_GTK_PLACES_VIEW_ROW (row)),
+ "button-press-event",
+ G_CALLBACK (on_button_press_event),
+ row);
- g_signal_connect (row,
- "popup-menu",
- G_CALLBACK (on_row_popup_menu),
- row);
+ g_signal_connect (row,
+ "popup-menu",
+ G_CALLBACK (on_row_popup_menu),
+ row);
- g_signal_connect (nautilus_gtk_places_view_row_get_eject_button (NAUTILUS_GTK_PLACES_VIEW_ROW (row)),
- "clicked",
- G_CALLBACK (on_eject_button_clicked),
- row);
+ g_signal_connect (nautilus_gtk_places_view_row_get_eject_button (NAUTILUS_GTK_PLACES_VIEW_ROW (row)),
+ "clicked",
+ G_CALLBACK (on_eject_button_clicked),
+ row);
- nautilus_gtk_places_view_row_set_path_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), priv->path_size_group);
- nautilus_gtk_places_view_row_set_space_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), priv->space_size_group);
+ nautilus_gtk_places_view_row_set_path_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), priv->path_size_group);
+ nautilus_gtk_places_view_row_set_space_size_group (NAUTILUS_GTK_PLACES_VIEW_ROW (row), priv->space_size_group);
- gtk_container_add (GTK_CONTAINER (priv->listbox), row);
+ gtk_container_add (GTK_CONTAINER (priv->listbox), row);
}
static void
add_volume (NautilusGtkPlacesView *view,
- GVolume *volume)
-{
- gboolean is_network;
- GMount *mount;
- GFile *root;
- GIcon *icon;
- gchar *identifier;
- gchar *name;
- gchar *path;
-
- if (is_external_volume (volume))
- return;
-
- identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
- is_network = g_strcmp0 (identifier, "network") == 0;
-
- mount = g_volume_get_mount (volume);
- root = mount ? g_mount_get_default_location (mount) : NULL;
- icon = g_volume_get_icon (volume);
- name = g_volume_get_name (volume);
- path = !is_network ? g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) : NULL;
-
- if (!mount || !g_mount_is_shadowed (mount))
- {
- GtkWidget *row;
-
- row = g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
- "icon", icon,
- "name", name,
- "path", path ? path : "",
- "volume", volume,
- "mount", mount,
- "file", NULL,
- "is-network", is_network,
- NULL);
+ GVolume *volume)
+{
+ gboolean is_network;
+ GMount *mount;
+ GFile *root;
+ GIcon *icon;
+ gchar *identifier;
+ gchar *name;
+ gchar *path;
+
+ if (is_external_volume (volume))
+ {
+ return;
+ }
+
+ identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
+ is_network = g_strcmp0 (identifier, "network") == 0;
+
+ mount = g_volume_get_mount (volume);
+ root = mount ? g_mount_get_default_location (mount) : NULL;
+ icon = g_volume_get_icon (volume);
+ name = g_volume_get_name (volume);
+ path = !is_network ? g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE) : NULL;
+
+ if (!mount || !g_mount_is_shadowed (mount))
+ {
+ GtkWidget *row;
+
+ row = g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
+ "icon", icon,
+ "name", name,
+ "path", path ? path : "",
+ "volume", volume,
+ "mount", mount,
+ "file", NULL,
+ "is-network", is_network,
+ NULL);
- insert_row (view, row, is_network);
+ insert_row (view, row, is_network);
}
- g_clear_object (&root);
- g_clear_object (&icon);
- g_clear_object (&mount);
- g_free (identifier);
- g_free (name);
- g_free (path);
+ g_clear_object (&root);
+ g_clear_object (&icon);
+ g_clear_object (&mount);
+ g_free (identifier);
+ g_free (name);
+ g_free (path);
}
static void
add_mount (NautilusGtkPlacesView *view,
- GMount *mount)
-{
- gboolean is_network;
- GFile *root;
- GIcon *icon;
- gchar *name;
- gchar *path;
- gchar *uri;
- gchar *schema;
-
- icon = g_mount_get_icon (mount);
- name = g_mount_get_name (mount);
- root = g_mount_get_default_location (mount);
- path = root ? g_file_get_parse_name (root) : NULL;
- uri = g_file_get_uri (root);
- schema = g_uri_parse_scheme (uri);
- is_network = g_strcmp0 (schema, "file") != 0;
-
- if (is_network)
- g_clear_pointer (&path, g_free);
-
- if (!g_mount_is_shadowed (mount))
- {
- GtkWidget *row;
-
- row = g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
- "icon", icon,
- "name", name,
- "path", path ? path : "",
- "volume", NULL,
- "mount", mount,
- "file", NULL,
- "is-network", is_network,
- NULL);
+ GMount *mount)
+{
+ gboolean is_network;
+ GFile *root;
+ GIcon *icon;
+ gchar *name;
+ gchar *path;
+ gchar *uri;
+ gchar *schema;
+
+ icon = g_mount_get_icon (mount);
+ name = g_mount_get_name (mount);
+ root = g_mount_get_default_location (mount);
+ path = root ? g_file_get_parse_name (root) : NULL;
+ uri = g_file_get_uri (root);
+ schema = g_uri_parse_scheme (uri);
+ is_network = g_strcmp0 (schema, "file") != 0;
+
+ if (is_network)
+ {
+ g_clear_pointer (&path, g_free);
+ }
+
+ if (!g_mount_is_shadowed (mount))
+ {
+ GtkWidget *row;
+
+ row = g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
+ "icon", icon,
+ "name", name,
+ "path", path ? path : "",
+ "volume", NULL,
+ "mount", mount,
+ "file", NULL,
+ "is-network", is_network,
+ NULL);
- insert_row (view, row, is_network);
+ insert_row (view, row, is_network);
}
- g_clear_object (&root);
- g_clear_object (&icon);
- g_free (name);
- g_free (path);
- g_free (uri);
- g_free (schema);
+ g_clear_object (&root);
+ g_clear_object (&icon);
+ g_free (name);
+ g_free (path);
+ g_free (uri);
+ g_free (schema);
}
static void
add_drive (NautilusGtkPlacesView *view,
- GDrive *drive)
+ GDrive *drive)
{
- GList *volumes;
- GList *l;
+ GList *volumes;
+ GList *l;
- volumes = g_drive_get_volumes (drive);
+ volumes = g_drive_get_volumes (drive);
- for (l = volumes; l != NULL; l = l->next)
- add_volume (view, l->data);
+ for (l = volumes; l != NULL; l = l->next)
+ {
+ add_volume (view, l->data);
+ }
- g_list_free_full (volumes, g_object_unref);
+ g_list_free_full (volumes, g_object_unref);
}
static void
add_file (NautilusGtkPlacesView *view,
- GFile *file,
- GIcon *icon,
- const gchar *display_name,
- const gchar *path,
- gboolean is_network)
-{
- GtkWidget *row;
- row = g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
- "icon", icon,
- "name", display_name,
- "path", path,
- "volume", NULL,
- "mount", NULL,
- "file", file,
- "is_network", is_network,
- NULL);
-
- insert_row (view, row, is_network);
+ GFile *file,
+ GIcon *icon,
+ const gchar *display_name,
+ const gchar *path,
+ gboolean is_network)
+{
+ GtkWidget *row;
+ row = g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
+ "icon", icon,
+ "name", display_name,
+ "path", path,
+ "volume", NULL,
+ "mount", NULL,
+ "file", file,
+ "is_network", is_network,
+ NULL);
+
+ insert_row (view, row, is_network);
}
static gboolean
has_networks (NautilusGtkPlacesView *view)
{
- GList *l;
- NautilusGtkPlacesViewPrivate *priv;
- GList *children;
- gboolean has_network = FALSE;
+ GList *l;
+ NautilusGtkPlacesViewPrivate *priv;
+ GList *children;
+ gboolean has_network = FALSE;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- children = gtk_container_get_children (GTK_CONTAINER (priv->listbox));
- for (l = children; l != NULL; l = l->next)
+ children = gtk_container_get_children (GTK_CONTAINER (priv->listbox));
+ for (l = children; l != NULL; l = l->next)
{
- if (GPOINTER_TO_INT (g_object_get_data (l->data, "is-network")) == TRUE &&
- g_object_get_data (l->data, "is-placeholder") == NULL)
- {
- has_network = TRUE;
- break;
- }
+ if (GPOINTER_TO_INT (g_object_get_data (l->data, "is-network")) == TRUE &&
+ g_object_get_data (l->data, "is-placeholder") == NULL)
+ {
+ has_network = TRUE;
+ break;
+ }
}
- g_list_free (children);
+ g_list_free (children);
- return has_network;
+ return has_network;
}
static void
update_network_state (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (priv->network_placeholder == NULL)
+ if (priv->network_placeholder == NULL)
{
- priv->network_placeholder = gtk_list_box_row_new ();
- priv->network_placeholder_label = gtk_label_new ("");
- gtk_label_set_xalign (GTK_LABEL (priv->network_placeholder_label), 0.0);
- gtk_widget_set_margin_start (priv->network_placeholder_label, 12);
- gtk_widget_set_margin_end (priv->network_placeholder_label, 12);
- gtk_widget_set_margin_top (priv->network_placeholder_label, 6);
- gtk_widget_set_margin_bottom (priv->network_placeholder_label, 6);
- gtk_widget_set_hexpand (priv->network_placeholder_label, TRUE);
- gtk_widget_set_sensitive (priv->network_placeholder, FALSE);
- gtk_container_add (GTK_CONTAINER (priv->network_placeholder),
- priv->network_placeholder_label);
- g_object_set_data (G_OBJECT (priv->network_placeholder),
- "is-network", GINT_TO_POINTER (TRUE));
- /* mark the row as placeholder, so it always goes first */
- g_object_set_data (G_OBJECT (priv->network_placeholder),
- "is-placeholder", GINT_TO_POINTER (TRUE));
- gtk_container_add (GTK_CONTAINER (priv->listbox), priv->network_placeholder);
+ priv->network_placeholder = gtk_list_box_row_new ();
+ priv->network_placeholder_label = gtk_label_new ("");
+ gtk_label_set_xalign (GTK_LABEL (priv->network_placeholder_label), 0.0);
+ gtk_widget_set_margin_start (priv->network_placeholder_label, 12);
+ gtk_widget_set_margin_end (priv->network_placeholder_label, 12);
+ gtk_widget_set_margin_top (priv->network_placeholder_label, 6);
+ gtk_widget_set_margin_bottom (priv->network_placeholder_label, 6);
+ gtk_widget_set_hexpand (priv->network_placeholder_label, TRUE);
+ gtk_widget_set_sensitive (priv->network_placeholder, FALSE);
+ gtk_container_add (GTK_CONTAINER (priv->network_placeholder),
+ priv->network_placeholder_label);
+ g_object_set_data (G_OBJECT (priv->network_placeholder),
+ "is-network", GINT_TO_POINTER (TRUE));
+ /* mark the row as placeholder, so it always goes first */
+ g_object_set_data (G_OBJECT (priv->network_placeholder),
+ "is-placeholder", GINT_TO_POINTER (TRUE));
+ gtk_container_add (GTK_CONTAINER (priv->listbox), priv->network_placeholder);
}
- if (nautilus_gtk_places_view_get_fetching_networks (view))
+ if (nautilus_gtk_places_view_get_fetching_networks (view))
{
- /* only show a placeholder with a message if the list is empty.
- * otherwise just show the spinner in the header */
- if (!has_networks (view))
+ /* only show a placeholder with a message if the list is empty.
+ * otherwise just show the spinner in the header */
+ if (!has_networks (view))
{
- gtk_widget_show_all (priv->network_placeholder);
- gtk_label_set_text (GTK_LABEL (priv->network_placeholder_label),
- _("Searching for network locations"));
+ gtk_widget_show_all (priv->network_placeholder);
+ gtk_label_set_text (GTK_LABEL (priv->network_placeholder_label),
+ _("Searching for network locations"));
}
}
- else if (!has_networks (view))
+ else if (!has_networks (view))
{
- gtk_widget_show_all (priv->network_placeholder);
- gtk_label_set_text (GTK_LABEL (priv->network_placeholder_label),
- _("No network locations found"));
+ gtk_widget_show_all (priv->network_placeholder);
+ gtk_label_set_text (GTK_LABEL (priv->network_placeholder_label),
+ _("No network locations found"));
}
- else
+ else
{
- gtk_widget_hide (priv->network_placeholder);
+ gtk_widget_hide (priv->network_placeholder);
}
}
static void
-populate_networks (NautilusGtkPlacesView *view,
- GFileEnumerator *enumerator,
- GList *detected_networks)
-{
- GList *l;
- GFile *file;
- GFile *activatable_file;
- gchar *uri;
- GFileType type;
- GIcon *icon;
- gchar *display_name;
-
- for (l = detected_networks; l != NULL; l = l->next)
+populate_networks (NautilusGtkPlacesView *view,
+ GFileEnumerator *enumerator,
+ GList *detected_networks)
+{
+ GList *l;
+ GFile *file;
+ GFile *activatable_file;
+ gchar *uri;
+ GFileType type;
+ GIcon *icon;
+ gchar *display_name;
+
+ for (l = detected_networks; l != NULL; l = l->next)
{
- file = g_file_enumerator_get_child (enumerator, l->data);
- type = g_file_info_get_file_type (l->data);
- if (type == G_FILE_TYPE_SHORTCUT || type == G_FILE_TYPE_MOUNTABLE)
- uri = g_file_info_get_attribute_as_string (l->data, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
- else
- uri = g_file_get_uri (file);
- activatable_file = g_file_new_for_uri (uri);
- display_name = g_file_info_get_attribute_as_string (l->data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
- icon = g_file_info_get_icon (l->data);
+ file = g_file_enumerator_get_child (enumerator, l->data);
+ type = g_file_info_get_file_type (l->data);
+ if (type == G_FILE_TYPE_SHORTCUT || type == G_FILE_TYPE_MOUNTABLE)
+ {
+ uri = g_file_info_get_attribute_as_string (l->data, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
+ }
+ else
+ {
+ uri = g_file_get_uri (file);
+ }
+ activatable_file = g_file_new_for_uri (uri);
+ display_name = g_file_info_get_attribute_as_string (l->data, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
+ icon = g_file_info_get_icon (l->data);
- add_file (view, activatable_file, icon, display_name, NULL, TRUE);
+ add_file (view, activatable_file, icon, display_name, NULL, TRUE);
- g_free (uri);
- g_free (display_name);
- g_clear_object (&file);
- g_clear_object (&activatable_file);
+ g_free (uri);
+ g_free (display_name);
+ g_clear_object (&file);
+ g_clear_object (&activatable_file);
}
}
@@ -930,38 +974,40 @@ network_enumeration_next_files_finished (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- NautilusGtkPlacesViewPrivate *priv;
- NautilusGtkPlacesView *view;
- GList *detected_networks;
- GError *error;
+ NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesView *view;
+ GList *detected_networks;
+ GError *error;
- view = NAUTILUS_GTK_PLACES_VIEW (user_data);
- priv = nautilus_gtk_places_view_get_instance_private (view);
- error = NULL;
+ view = NAUTILUS_GTK_PLACES_VIEW (user_data);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ error = NULL;
- detected_networks = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source_object),
- res, &error);
+ detected_networks = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source_object),
+ res, &error);
- if (error)
+ if (error)
{
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Failed to fetch network locations: %s", error->message);
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ g_warning ("Failed to fetch network locations: %s", error->message);
+ }
- g_clear_error (&error);
+ g_clear_error (&error);
}
- else
+ else
{
- nautilus_gtk_places_view_set_fetching_networks (view, FALSE);
- populate_networks (view, G_FILE_ENUMERATOR (source_object), detected_networks);
+ nautilus_gtk_places_view_set_fetching_networks (view, FALSE);
+ populate_networks (view, G_FILE_ENUMERATOR (source_object), detected_networks);
- g_list_free_full (detected_networks, g_object_unref);
+ g_list_free_full (detected_networks, g_object_unref);
}
- /* avoid to update widgets if the operation was cancelled in finalize */
- if (priv->listbox != NULL)
+ /* avoid to update widgets if the operation was cancelled in finalize */
+ if (priv->listbox != NULL)
{
- update_network_state (view);
- update_loading (view);
+ update_network_state (view);
+ update_loading (view);
}
}
@@ -970,169 +1016,181 @@ network_enumeration_finished (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- NautilusGtkPlacesViewPrivate *priv;
- GFileEnumerator *enumerator;
- GError *error;
+ NautilusGtkPlacesViewPrivate *priv;
+ GFileEnumerator *enumerator;
+ GError *error;
- error = NULL;
- enumerator = g_file_enumerate_children_finish (G_FILE (source_object), res, &error);
+ error = NULL;
+ enumerator = g_file_enumerate_children_finish (G_FILE (source_object), res, &error);
- if (error)
+ if (error)
{
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
- !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
- g_warning ("Failed to fetch network locations: %s", error->message);
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
+ !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
+ {
+ g_warning ("Failed to fetch network locations: %s", error->message);
+ }
- g_clear_error (&error);
+ g_clear_error (&error);
}
- else
+ else
{
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data));
- g_file_enumerator_next_files_async (enumerator,
- G_MAXINT32,
- G_PRIORITY_DEFAULT,
- priv->networks_fetching_cancellable,
- network_enumeration_next_files_finished,
- user_data);
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data));
+ g_file_enumerator_next_files_async (enumerator,
+ G_MAXINT32,
+ G_PRIORITY_DEFAULT,
+ priv->networks_fetching_cancellable,
+ network_enumeration_next_files_finished,
+ user_data);
}
}
static void
fetch_networks (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- GFile *network_file;
- const gchar * const *supported_uris;
- gboolean found;
+ NautilusGtkPlacesViewPrivate *priv;
+ GFile *network_file;
+ const gchar * const *supported_uris;
+ gboolean found;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- supported_uris = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ supported_uris = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
- for (found = FALSE; !found && supported_uris && supported_uris[0]; supported_uris++)
- if (g_strcmp0 (supported_uris[0], "network") == 0)
- found = TRUE;
+ for (found = FALSE; !found && supported_uris && supported_uris[0]; supported_uris++)
+ {
+ if (g_strcmp0 (supported_uris[0], "network") == 0)
+ {
+ found = TRUE;
+ }
+ }
- if (!found)
- return;
+ if (!found)
+ {
+ return;
+ }
- network_file = g_file_new_for_uri ("network:///");
+ network_file = g_file_new_for_uri ("network:///");
- g_cancellable_cancel (priv->networks_fetching_cancellable);
- g_clear_object (&priv->networks_fetching_cancellable);
- priv->networks_fetching_cancellable = g_cancellable_new ();
- nautilus_gtk_places_view_set_fetching_networks (view, TRUE);
- update_network_state (view);
+ g_cancellable_cancel (priv->networks_fetching_cancellable);
+ g_clear_object (&priv->networks_fetching_cancellable);
+ priv->networks_fetching_cancellable = g_cancellable_new ();
+ nautilus_gtk_places_view_set_fetching_networks (view, TRUE);
+ update_network_state (view);
- g_file_enumerate_children_async (network_file,
- "standard::type,standard::target-uri,standard::name,standard::display-name,standard::icon",
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT,
- priv->networks_fetching_cancellable,
- network_enumeration_finished,
- view);
+ g_file_enumerate_children_async (network_file,
+ "standard::type,standard::target-uri,standard::name,standard::display-name,standard::icon",
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ priv->networks_fetching_cancellable,
+ network_enumeration_finished,
+ view);
- g_clear_object (&network_file);
+ g_clear_object (&network_file);
}
static void
update_places (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- GList *children;
- GList *mounts;
- GList *volumes;
- GList *drives;
- GList *l;
- GIcon *icon;
- GFile *file;
+ NautilusGtkPlacesViewPrivate *priv;
+ GList *children;
+ GList *mounts;
+ GList *volumes;
+ GList *drives;
+ GList *l;
+ GIcon *icon;
+ GFile *file;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- /* Clear all previously added items */
- children = gtk_container_get_children (GTK_CONTAINER (priv->listbox));
- g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy);
- priv->network_placeholder = NULL;
- /* Inform clients that we started loading */
- nautilus_gtk_places_view_set_loading (view, TRUE);
+ /* Clear all previously added items */
+ children = gtk_container_get_children (GTK_CONTAINER (priv->listbox));
+ g_list_free_full (children, (GDestroyNotify) gtk_widget_destroy);
+ priv->network_placeholder = NULL;
+ /* Inform clients that we started loading */
+ nautilus_gtk_places_view_set_loading (view, TRUE);
- /* Add "Computer" row */
- file = g_file_new_for_path ("/");
- icon = g_themed_icon_new_with_default_fallbacks ("drive-harddisk");
+ /* Add "Computer" row */
+ file = g_file_new_for_path ("/");
+ icon = g_themed_icon_new_with_default_fallbacks ("drive-harddisk");
- add_file (view, file, icon, _("Computer"), "/", FALSE);
+ add_file (view, file, icon, _("Computer"), "/", FALSE);
- g_clear_object (&file);
- g_clear_object (&icon);
+ g_clear_object (&file);
+ g_clear_object (&icon);
- /* Add currently connected drives */
- drives = g_volume_monitor_get_connected_drives (priv->volume_monitor);
+ /* Add currently connected drives */
+ drives = g_volume_monitor_get_connected_drives (priv->volume_monitor);
- for (l = drives; l != NULL; l = l->next)
- add_drive (view, l->data);
+ for (l = drives; l != NULL; l = l->next)
+ {
+ add_drive (view, l->data);
+ }
- g_list_free_full (drives, g_object_unref);
+ g_list_free_full (drives, g_object_unref);
- /*
- * Since all volumes with an associated GDrive were already added with
- * add_drive before, add all volumes that aren't associated with a
- * drive.
- */
- volumes = g_volume_monitor_get_volumes (priv->volume_monitor);
+ /*
+ * Since all volumes with an associated GDrive were already added with
+ * add_drive before, add all volumes that aren't associated with a
+ * drive.
+ */
+ volumes = g_volume_monitor_get_volumes (priv->volume_monitor);
- for (l = volumes; l != NULL; l = l->next)
+ for (l = volumes; l != NULL; l = l->next)
{
- GVolume *volume;
- GDrive *drive;
+ GVolume *volume;
+ GDrive *drive;
- volume = l->data;
- drive = g_volume_get_drive (volume);
+ volume = l->data;
+ drive = g_volume_get_drive (volume);
- if (drive)
+ if (drive)
{
- g_object_unref (drive);
- continue;
+ g_object_unref (drive);
+ continue;
}
- add_volume (view, volume);
+ add_volume (view, volume);
}
- g_list_free_full (volumes, g_object_unref);
+ g_list_free_full (volumes, g_object_unref);
- /*
- * Now that all necessary drives and volumes were already added, add mounts
- * that have no volume, such as /etc/mtab mounts, ftp, sftp, etc.
- */
- mounts = g_volume_monitor_get_mounts (priv->volume_monitor);
+ /*
+ * Now that all necessary drives and volumes were already added, add mounts
+ * that have no volume, such as /etc/mtab mounts, ftp, sftp, etc.
+ */
+ mounts = g_volume_monitor_get_mounts (priv->volume_monitor);
- for (l = mounts; l != NULL; l = l->next)
+ for (l = mounts; l != NULL; l = l->next)
{
- GMount *mount;
- GVolume *volume;
+ GMount *mount;
+ GVolume *volume;
- mount = l->data;
- volume = g_mount_get_volume (mount);
+ mount = l->data;
+ volume = g_mount_get_volume (mount);
- if (volume)
+ if (volume)
{
- g_object_unref (volume);
- continue;
+ g_object_unref (volume);
+ continue;
}
- add_mount (view, mount);
+ add_mount (view, mount);
}
- g_list_free_full (mounts, g_object_unref);
+ g_list_free_full (mounts, g_object_unref);
- /* load saved servers */
- populate_servers (view);
+ /* load saved servers */
+ populate_servers (view);
- /* fetch networks and add them asynchronously */
- if (!nautilus_gtk_places_view_get_local_only (view))
- fetch_networks (view);
+ /* fetch networks and add them asynchronously */
+ if (!nautilus_gtk_places_view_get_local_only (view))
+ {
+ fetch_networks (view);
+ }
- update_view_mode (view);
- /* Check whether we still are in a loading state */
- update_loading (view);
+ update_view_mode (view);
+ /* Check whether we still are in a loading state */
+ update_loading (view);
}
static void
@@ -1140,72 +1198,74 @@ server_mount_ready_cb (GObject *source_file,
GAsyncResult *res,
gpointer user_data)
{
- NautilusGtkPlacesViewPrivate *priv;
- NautilusGtkPlacesView *view;
- gboolean should_show;
- GError *error;
- GFile *location;
+ NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesView *view;
+ gboolean should_show;
+ GError *error;
+ GFile *location;
- location = G_FILE (source_file);
- should_show = TRUE;
- error = NULL;
+ location = G_FILE (source_file);
+ should_show = TRUE;
+ error = NULL;
- g_file_mount_enclosing_volume_finish (location, res, &error);
- if (error)
+ g_file_mount_enclosing_volume_finish (location, res, &error);
+ if (error)
{
- should_show = FALSE;
+ should_show = FALSE;
- if (error->code == G_IO_ERROR_ALREADY_MOUNTED)
+ if (error->code == G_IO_ERROR_ALREADY_MOUNTED)
{
- /*
- * Already mounted volume is not a critical error
- * and we can still continue with the operation.
- */
- should_show = TRUE;
+ /*
+ * Already mounted volume is not a critical error
+ * and we can still continue with the operation.
+ */
+ should_show = TRUE;
}
- else if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED))
+ else if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED))
{
- view = NAUTILUS_GTK_PLACES_VIEW (user_data);
- /* if it wasn't cancelled show a dialog */
- emit_show_error_message (view, _("Unable to access location"), error->message);
- should_show = FALSE;
+ view = NAUTILUS_GTK_PLACES_VIEW (user_data);
+ /* if it wasn't cancelled show a dialog */
+ emit_show_error_message (view, _("Unable to access location"), error->message);
+ should_show = FALSE;
}
- else
+ else
{
- /* it was cancelled, so probably it was called during finalize, bail out. */
- g_clear_error (&error);
- return;
+ /* it was cancelled, so probably it was called during finalize, bail out. */
+ g_clear_error (&error);
+ return;
}
- g_clear_error (&error);
+ g_clear_error (&error);
}
- view = NAUTILUS_GTK_PLACES_VIEW (user_data);
- priv = nautilus_gtk_places_view_get_instance_private (view);
- priv->should_pulse_entry = FALSE;
+ view = NAUTILUS_GTK_PLACES_VIEW (user_data);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv->should_pulse_entry = FALSE;
- /* Restore from Cancel to Connect */
- gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
- gtk_widget_set_sensitive (priv->address_entry, TRUE);
- priv->connecting_to_server = FALSE;
+ /* Restore from Cancel to Connect */
+ gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Con_nect"));
+ gtk_widget_set_sensitive (priv->address_entry, TRUE);
+ priv->connecting_to_server = FALSE;
- if (should_show)
+ if (should_show)
{
- server_list_add_server (view, location);
+ server_list_add_server (view, location);
- /*
- * Only clear the entry if it successfully connects to the server.
- * Otherwise, the user would lost the typed address even if it fails
- * to connect.
- */
- gtk_entry_set_text (GTK_ENTRY (priv->address_entry), "");
+ /*
+ * Only clear the entry if it successfully connects to the server.
+ * Otherwise, the user would lost the typed address even if it fails
+ * to connect.
+ */
+ gtk_entry_set_text (GTK_ENTRY (priv->address_entry), "");
- if (priv->should_open_location)
- emit_open_location (view, location, priv->open_flags);
+ if (priv->should_open_location)
+ {
+ emit_open_location (view, location, priv->open_flags);
+ }
}
- update_places (view);
+ update_places (view);
}
static void
@@ -1213,69 +1273,71 @@ volume_mount_ready_cb (GObject *source_volume,
GAsyncResult *res,
gpointer user_data)
{
- NautilusGtkPlacesViewPrivate *priv;
- NautilusGtkPlacesView *view;
- gboolean should_show;
- GVolume *volume;
- GError *error;
+ NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesView *view;
+ gboolean should_show;
+ GVolume *volume;
+ GError *error;
- volume = G_VOLUME (source_volume);
- should_show = TRUE;
- error = NULL;
+ volume = G_VOLUME (source_volume);
+ should_show = TRUE;
+ error = NULL;
- g_volume_mount_finish (volume, res, &error);
+ g_volume_mount_finish (volume, res, &error);
- if (error)
+ if (error)
{
- should_show = FALSE;
+ should_show = FALSE;
- if (error->code == G_IO_ERROR_ALREADY_MOUNTED)
+ if (error->code == G_IO_ERROR_ALREADY_MOUNTED)
{
- /*
- * If the volume was already mounted, it's not a hard error
- * and we can still continue with the operation.
- */
- should_show = TRUE;
+ /*
+ * If the volume was already mounted, it's not a hard error
+ * and we can still continue with the operation.
+ */
+ should_show = TRUE;
}
- else if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED))
+ else if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED))
{
- /* if it wasn't cancelled show a dialog */
- emit_show_error_message (NAUTILUS_GTK_PLACES_VIEW (user_data), _("Unable to access location"), error->message);
- should_show = FALSE;
+ /* if it wasn't cancelled show a dialog */
+ emit_show_error_message (NAUTILUS_GTK_PLACES_VIEW (user_data), _("Unable to access location"), error->message);
+ should_show = FALSE;
}
- else
+ else
{
- /* it was cancelled, so probably it was called during finalize, bail out. */
- g_clear_error (&error);
- return;
+ /* it was cancelled, so probably it was called during finalize, bail out. */
+ g_clear_error (&error);
+ return;
}
- g_clear_error (&error);
+ g_clear_error (&error);
}
- view = NAUTILUS_GTK_PLACES_VIEW (user_data);
- priv = nautilus_gtk_places_view_get_instance_private (view);
- priv->mounting_volume = FALSE;
- update_loading (view);
+ view = NAUTILUS_GTK_PLACES_VIEW (user_data);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv->mounting_volume = FALSE;
+ update_loading (view);
- if (should_show)
+ if (should_show)
{
- GMount *mount;
- GFile *root;
+ GMount *mount;
+ GFile *root;
- mount = g_volume_get_mount (volume);
- root = g_mount_get_default_location (mount);
+ mount = g_volume_get_mount (volume);
+ root = g_mount_get_default_location (mount);
- if (priv->should_open_location)
- emit_open_location (NAUTILUS_GTK_PLACES_VIEW (user_data), root, priv->open_flags);
+ if (priv->should_open_location)
+ {
+ emit_open_location (NAUTILUS_GTK_PLACES_VIEW (user_data), root, priv->open_flags);
+ }
- g_object_unref (mount);
- g_object_unref (root);
+ g_object_unref (mount);
+ g_object_unref (root);
}
- update_places (view);
+ update_places (view);
}
static void
@@ -1283,161 +1345,165 @@ unmount_ready_cb (GObject *source_mount,
GAsyncResult *res,
gpointer user_data)
{
- NautilusGtkPlacesView *view;
- NautilusGtkPlacesViewPrivate *priv;
- GMount *mount;
- GError *error;
+ NautilusGtkPlacesView *view;
+ NautilusGtkPlacesViewPrivate *priv;
+ GMount *mount;
+ GError *error;
- view = NAUTILUS_GTK_PLACES_VIEW (user_data);
- mount = G_MOUNT (source_mount);
- error = NULL;
+ view = NAUTILUS_GTK_PLACES_VIEW (user_data);
+ mount = G_MOUNT (source_mount);
+ error = NULL;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- priv->unmounting_mount = FALSE;
- update_loading (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv->unmounting_mount = FALSE;
+ update_loading (view);
- g_mount_unmount_with_operation_finish (mount, res, &error);
+ g_mount_unmount_with_operation_finish (mount, res, &error);
- if (error)
+ if (error)
{
- if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED))
+ if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED))
{
- /* if it wasn't cancelled show a dialog */
- emit_show_error_message (view, _("Unable to unmount volume"), error->message);
+ /* if it wasn't cancelled show a dialog */
+ emit_show_error_message (view, _("Unable to unmount volume"), error->message);
}
- g_clear_error (&error);
+ g_clear_error (&error);
}
}
static gboolean
pulse_entry_cb (gpointer user_data)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data));
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data));
- if (priv->should_pulse_entry)
+ if (priv->should_pulse_entry)
{
- gtk_entry_progress_pulse (GTK_ENTRY (priv->address_entry));
+ gtk_entry_progress_pulse (GTK_ENTRY (priv->address_entry));
- return G_SOURCE_CONTINUE;
+ return G_SOURCE_CONTINUE;
}
- else
+ else
{
- gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.0);
- gtk_entry_set_progress_fraction (GTK_ENTRY (priv->address_entry), 0.0);
- priv->entry_pulse_timeout_id = 0;
+ gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.0);
+ gtk_entry_set_progress_fraction (GTK_ENTRY (priv->address_entry), 0.0);
+ priv->entry_pulse_timeout_id = 0;
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
}
}
static void
unmount_mount (NautilusGtkPlacesView *view,
- GMount *mount)
+ GMount *mount)
{
- NautilusGtkPlacesViewPrivate *priv;
- GMountOperation *operation;
- GtkWidget *toplevel;
+ NautilusGtkPlacesViewPrivate *priv;
+ GMountOperation *operation;
+ GtkWidget *toplevel;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
- operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
- g_cancellable_cancel (priv->cancellable);
- g_clear_object (&priv->cancellable);
- priv->cancellable = g_cancellable_new ();
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+ priv->cancellable = g_cancellable_new ();
- priv->unmounting_mount = TRUE;
- update_loading (view);
+ priv->unmounting_mount = TRUE;
+ update_loading (view);
- operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
- g_mount_unmount_with_operation (mount,
- 0,
- operation,
- priv->cancellable,
- unmount_ready_cb,
- view);
- g_object_unref (operation);
+ operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
+ g_mount_unmount_with_operation (mount,
+ 0,
+ operation,
+ priv->cancellable,
+ unmount_ready_cb,
+ view);
+ g_object_unref (operation);
}
static void
mount_server (NautilusGtkPlacesView *view,
- GFile *location)
+ GFile *location)
{
- NautilusGtkPlacesViewPrivate *priv;
- GMountOperation *operation;
- GtkWidget *toplevel;
+ NautilusGtkPlacesViewPrivate *priv;
+ GMountOperation *operation;
+ GtkWidget *toplevel;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- g_cancellable_cancel (priv->cancellable);
- g_clear_object (&priv->cancellable);
- /* User cliked when the operation was ongoing, so wanted to cancel it */
- if (priv->connecting_to_server)
- return;
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+ /* User cliked when the operation was ongoing, so wanted to cancel it */
+ if (priv->connecting_to_server)
+ {
+ return;
+ }
- priv->cancellable = g_cancellable_new ();
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
- operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
+ priv->cancellable = g_cancellable_new ();
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
- priv->should_pulse_entry = TRUE;
- gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.1);
- /* Allow to cancel the operation */
- gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Cance_l"));
- gtk_widget_set_sensitive (priv->address_entry, FALSE);
- priv->connecting_to_server = TRUE;
- update_loading (view);
+ priv->should_pulse_entry = TRUE;
+ gtk_entry_set_progress_pulse_step (GTK_ENTRY (priv->address_entry), 0.1);
+ /* Allow to cancel the operation */
+ gtk_button_set_label (GTK_BUTTON (priv->connect_button), _("Cance_l"));
+ gtk_widget_set_sensitive (priv->address_entry, FALSE);
+ priv->connecting_to_server = TRUE;
+ update_loading (view);
- if (priv->entry_pulse_timeout_id == 0)
- priv->entry_pulse_timeout_id = g_timeout_add (100, (GSourceFunc) pulse_entry_cb, view);
+ if (priv->entry_pulse_timeout_id == 0)
+ {
+ priv->entry_pulse_timeout_id = g_timeout_add (100, (GSourceFunc) pulse_entry_cb, view);
+ }
- g_mount_operation_set_password_save (operation, G_PASSWORD_SAVE_FOR_SESSION);
+ g_mount_operation_set_password_save (operation, G_PASSWORD_SAVE_FOR_SESSION);
- g_file_mount_enclosing_volume (location,
- 0,
- operation,
- priv->cancellable,
- server_mount_ready_cb,
- view);
+ g_file_mount_enclosing_volume (location,
+ 0,
+ operation,
+ priv->cancellable,
+ server_mount_ready_cb,
+ view);
- /* unref operation here - g_file_mount_enclosing_volume() does ref for itself */
- g_object_unref (operation);
+ /* unref operation here - g_file_mount_enclosing_volume() does ref for itself */
+ g_object_unref (operation);
}
static void
mount_volume (NautilusGtkPlacesView *view,
- GVolume *volume)
+ GVolume *volume)
{
- NautilusGtkPlacesViewPrivate *priv;
- GMountOperation *operation;
- GtkWidget *toplevel;
+ NautilusGtkPlacesViewPrivate *priv;
+ GMountOperation *operation;
+ GtkWidget *toplevel;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
- operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ operation = gtk_mount_operation_new (GTK_WINDOW (toplevel));
- g_cancellable_cancel (priv->cancellable);
- g_clear_object (&priv->cancellable);
- priv->cancellable = g_cancellable_new ();
+ g_cancellable_cancel (priv->cancellable);
+ g_clear_object (&priv->cancellable);
+ priv->cancellable = g_cancellable_new ();
- priv->mounting_volume = TRUE;
- update_loading (view);
+ priv->mounting_volume = TRUE;
+ update_loading (view);
- g_mount_operation_set_password_save (operation, G_PASSWORD_SAVE_FOR_SESSION);
+ g_mount_operation_set_password_save (operation, G_PASSWORD_SAVE_FOR_SESSION);
- g_volume_mount (volume,
- 0,
- operation,
- priv->cancellable,
- volume_mount_ready_cb,
- view);
+ g_volume_mount (volume,
+ 0,
+ operation,
+ priv->cancellable,
+ volume_mount_ready_cb,
+ view);
- /* unref operation here - g_file_mount_enclosing_volume() does ref for itself */
- g_object_unref (operation);
+ /* unref operation here - g_file_mount_enclosing_volume() does ref for itself */
+ g_object_unref (operation);
}
/* Callback used when the file list's popup menu is detached */
@@ -1445,127 +1511,136 @@ static void
popup_menu_detach_cb (GtkWidget *attach_widget,
GtkMenu *menu)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (attach_widget));
- priv->popup_menu = NULL;
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (attach_widget));
+ priv->popup_menu = NULL;
}
static void
get_view_and_file (NautilusGtkPlacesViewRow *row,
- GtkWidget **view,
- GFile **file)
+ GtkWidget **view,
+ GFile **file)
{
- if (view)
- *view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
+ if (view)
+ {
+ *view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
+ }
- if (file)
+ if (file)
{
- GVolume *volume;
- GMount *mount;
+ GVolume *volume;
+ GMount *mount;
- volume = nautilus_gtk_places_view_row_get_volume (row);
- mount = nautilus_gtk_places_view_row_get_mount (row);
+ volume = nautilus_gtk_places_view_row_get_volume (row);
+ mount = nautilus_gtk_places_view_row_get_mount (row);
- if (mount)
+ if (mount)
{
- *file = g_mount_get_default_location (mount);
+ *file = g_mount_get_default_location (mount);
}
- else if (volume)
+ else if (volume)
{
- *file = g_volume_get_activation_root (volume);
+ *file = g_volume_get_activation_root (volume);
}
- else
+ else
{
- *file = nautilus_gtk_places_view_row_get_file (row);
- if (*file) {
- g_object_ref (*file);
- }
+ *file = nautilus_gtk_places_view_row_get_file (row);
+ if (*file)
+ {
+ g_object_ref (*file);
+ }
}
}
}
static void
-open_cb (GtkMenuItem *item,
+open_cb (GtkMenuItem *item,
NautilusGtkPlacesViewRow *row)
{
- GtkWidget *view;
- GFile *file;
+ GtkWidget *view;
+ GFile *file;
- get_view_and_file (row, &view, &file);
+ get_view_and_file (row, &view, &file);
- if (file)
- emit_open_location (NAUTILUS_GTK_PLACES_VIEW (view), file, GTK_PLACES_OPEN_NORMAL);
+ if (file)
+ {
+ emit_open_location (NAUTILUS_GTK_PLACES_VIEW (view), file, GTK_PLACES_OPEN_NORMAL);
+ }
- g_clear_object (&file);
+ g_clear_object (&file);
}
static void
-open_in_new_tab_cb (GtkMenuItem *item,
+open_in_new_tab_cb (GtkMenuItem *item,
NautilusGtkPlacesViewRow *row)
{
- GtkWidget *view;
- GFile *file;
+ GtkWidget *view;
+ GFile *file;
- get_view_and_file (row, &view, &file);
+ get_view_and_file (row, &view, &file);
- if (file)
- emit_open_location (NAUTILUS_GTK_PLACES_VIEW (view), file, GTK_PLACES_OPEN_NEW_TAB);
+ if (file)
+ {
+ emit_open_location (NAUTILUS_GTK_PLACES_VIEW (view), file, GTK_PLACES_OPEN_NEW_TAB);
+ }
- g_clear_object (&file);
+ g_clear_object (&file);
}
static void
-open_in_new_window_cb (GtkMenuItem *item,
+open_in_new_window_cb (GtkMenuItem *item,
NautilusGtkPlacesViewRow *row)
{
- GtkWidget *view;
- GFile *file;
+ GtkWidget *view;
+ GFile *file;
- get_view_and_file (row, &view, &file);
+ get_view_and_file (row, &view, &file);
- if (file)
- emit_open_location (NAUTILUS_GTK_PLACES_VIEW (view), file, GTK_PLACES_OPEN_NEW_WINDOW);
+ if (file)
+ {
+ emit_open_location (NAUTILUS_GTK_PLACES_VIEW (view), file, GTK_PLACES_OPEN_NEW_WINDOW);
+ }
- g_clear_object (&file);
+ g_clear_object (&file);
}
static void
-mount_cb (GtkMenuItem *item,
+mount_cb (GtkMenuItem *item,
NautilusGtkPlacesViewRow *row)
{
- NautilusGtkPlacesViewPrivate *priv;
- GtkWidget *view;
- GVolume *volume;
+ NautilusGtkPlacesViewPrivate *priv;
+ GtkWidget *view;
+ GVolume *volume;
- view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (view));
- volume = nautilus_gtk_places_view_row_get_volume (row);
+ view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (view));
+ volume = nautilus_gtk_places_view_row_get_volume (row);
- /*
- * When the mount item is activated, it's expected that
- * the volume only gets mounted, without opening it after
- * the operation is complete.
- */
- priv->should_open_location = FALSE;
+ /*
+ * When the mount item is activated, it's expected that
+ * the volume only gets mounted, without opening it after
+ * the operation is complete.
+ */
+ priv->should_open_location = FALSE;
- nautilus_gtk_places_view_row_set_busy (row, TRUE);
- mount_volume (NAUTILUS_GTK_PLACES_VIEW (view), volume);
+ nautilus_gtk_places_view_row_set_busy (row, TRUE);
+ mount_volume (NAUTILUS_GTK_PLACES_VIEW (view), volume);
}
static void
-unmount_cb (GtkMenuItem *item,
+unmount_cb (GtkMenuItem *item,
NautilusGtkPlacesViewRow *row)
{
- GtkWidget *view;
- GMount *mount;
+ GtkWidget *view;
+ GMount *mount;
- view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
- mount = nautilus_gtk_places_view_row_get_mount (row);
+ view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
+ mount = nautilus_gtk_places_view_row_get_mount (row);
- nautilus_gtk_places_view_row_set_busy (row, TRUE);
+ nautilus_gtk_places_view_row_set_busy (row, TRUE);
- unmount_mount (NAUTILUS_GTK_PLACES_VIEW (view), mount);
+ unmount_mount (NAUTILUS_GTK_PLACES_VIEW (view), mount);
}
/* Constructs the popup menu if needed */
@@ -1573,370 +1648,402 @@ static void
build_popup_menu (NautilusGtkPlacesView *view,
NautilusGtkPlacesViewRow *row)
{
- NautilusGtkPlacesViewPrivate *priv;
- GtkWidget *item;
- GMount *mount;
- GFile *file;
- gboolean is_network;
-
- priv = nautilus_gtk_places_view_get_instance_private (view);
- mount = nautilus_gtk_places_view_row_get_mount (row);
- file = nautilus_gtk_places_view_row_get_file (row);
- is_network = nautilus_gtk_places_view_row_get_is_network (row);
-
- priv->popup_menu = gtk_menu_new ();
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu),
- GTK_STYLE_CLASS_CONTEXT_MENU);
-
- gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
- GTK_WIDGET (view),
- popup_menu_detach_cb);
-
- /* Open item is always present */
- item = gtk_menu_item_new_with_mnemonic (_("_Open"));
- g_signal_connect (item,
- "activate",
- G_CALLBACK (open_cb),
- row);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
-
- if (priv->open_flags & GTK_PLACES_OPEN_NEW_TAB)
- {
- item = gtk_menu_item_new_with_mnemonic (_("Open in New _Tab"));
- g_signal_connect (item,
- "activate",
- G_CALLBACK (open_in_new_tab_cb),
- row);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- }
-
- if (priv->open_flags & GTK_PLACES_OPEN_NEW_WINDOW)
- {
- item = gtk_menu_item_new_with_mnemonic (_("Open in New _Window"));
- g_signal_connect (item,
- "activate",
- G_CALLBACK (open_in_new_window_cb),
- row);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- }
-
- /*
- * The only item that contains a file up to now is the Computer
- * item, which cannot be mounted or unmounted.
- */
- if (file)
- return;
-
- /* Separator */
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_insert (GTK_MENU_SHELL (priv->popup_menu), item, -1);
-
- /* Mount/Unmount items */
- if (mount)
- {
- item = gtk_menu_item_new_with_mnemonic (is_network ? _("_Disconnect") : _("_Unmount"));
- g_signal_connect (item,
- "activate",
- G_CALLBACK (unmount_cb),
- row);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
- }
- else
- {
- item = gtk_menu_item_new_with_mnemonic (is_network ? _("_Connect") : _("_Mount"));
- g_signal_connect (item,
- "activate",
- G_CALLBACK (mount_cb),
- row);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
+ NautilusGtkPlacesViewPrivate *priv;
+ GtkWidget *item;
+ GMount *mount;
+ GFile *file;
+ gboolean is_network;
+
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ mount = nautilus_gtk_places_view_row_get_mount (row);
+ file = nautilus_gtk_places_view_row_get_file (row);
+ is_network = nautilus_gtk_places_view_row_get_is_network (row);
+
+ priv->popup_menu = gtk_menu_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu),
+ GTK_STYLE_CLASS_CONTEXT_MENU);
+
+ gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
+ GTK_WIDGET (view),
+ popup_menu_detach_cb);
+
+ /* Open item is always present */
+ item = gtk_menu_item_new_with_mnemonic (_("_Open"));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (open_cb),
+ row);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
+
+ if (priv->open_flags & GTK_PLACES_OPEN_NEW_TAB)
+ {
+ item = gtk_menu_item_new_with_mnemonic (_("Open in New _Tab"));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (open_in_new_tab_cb),
+ row);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
+ }
+
+ if (priv->open_flags & GTK_PLACES_OPEN_NEW_WINDOW)
+ {
+ item = gtk_menu_item_new_with_mnemonic (_("Open in New _Window"));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (open_in_new_window_cb),
+ row);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
+ }
+
+ /*
+ * The only item that contains a file up to now is the Computer
+ * item, which cannot be mounted or unmounted.
+ */
+ if (file)
+ {
+ return;
+ }
+
+ /* Separator */
+ item = gtk_separator_menu_item_new ();
+ gtk_widget_show (item);
+ gtk_menu_shell_insert (GTK_MENU_SHELL (priv->popup_menu), item, -1);
+
+ /* Mount/Unmount items */
+ if (mount)
+ {
+ item = gtk_menu_item_new_with_mnemonic (is_network ? _("_Disconnect") : _("_Unmount"));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (unmount_cb),
+ row);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
+ }
+ else
+ {
+ item = gtk_menu_item_new_with_mnemonic (is_network ? _("_Connect") : _("_Mount"));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (mount_cb),
+ row);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), item);
}
}
static void
popup_menu (NautilusGtkPlacesViewRow *row,
- GdkEventButton *event)
+ GdkEventButton *event)
{
- NautilusGtkPlacesViewPrivate *priv;
- GtkWidget *view;
- gint button;
+ NautilusGtkPlacesViewPrivate *priv;
+ GtkWidget *view;
+ gint button;
- view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (view));
+ view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (view));
- g_clear_pointer (&priv->popup_menu, gtk_widget_destroy);
+ g_clear_pointer (&priv->popup_menu, gtk_widget_destroy);
- build_popup_menu (NAUTILUS_GTK_PLACES_VIEW (view), row);
+ build_popup_menu (NAUTILUS_GTK_PLACES_VIEW (view), row);
- /* The event button needs to be 0 if we're popping up this menu from
- * a button release, else a 2nd click outside the menu with any button
- * other than the one that invoked the menu will be ignored (instead
- * of dismissing the menu). This is a subtle fragility of the GTK menu code.
- */
- if (event)
+ /* The event button needs to be 0 if we're popping up this menu from
+ * a button release, else a 2nd click outside the menu with any button
+ * other than the one that invoked the menu will be ignored (instead
+ * of dismissing the menu). This is a subtle fragility of the GTK menu code.
+ */
+ if (event)
{
- if (event->type == GDK_BUTTON_PRESS)
- button = 0;
- else
- button = event->button;
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ button = 0;
+ }
+ else
+ {
+ button = event->button;
+ }
}
- else
+ else
{
- button = 0;
+ button = 0;
}
- gtk_menu_popup (GTK_MENU (priv->popup_menu),
- NULL,
- NULL,
- NULL,
- NULL,
- button,
- event ? event->time : gtk_get_current_event_time ());
+ gtk_menu_popup (GTK_MENU (priv->popup_menu),
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ button,
+ event ? event->time : gtk_get_current_event_time ());
}
static gboolean
on_row_popup_menu (NautilusGtkPlacesViewRow *row)
{
- popup_menu (row, NULL);
- return TRUE;
+ popup_menu (row, NULL);
+ return TRUE;
}
static gboolean
on_button_press_event (NautilusGtkPlacesViewRow *row,
- GdkEventButton *event)
+ GdkEventButton *event)
{
- if (row &&
- gdk_event_triggers_context_menu ((GdkEvent*) event) &&
- event->type == GDK_BUTTON_PRESS)
+ if (row &&
+ gdk_event_triggers_context_menu ((GdkEvent *) event) &&
+ event->type == GDK_BUTTON_PRESS)
{
- popup_menu (row, event);
+ popup_menu (row, event);
- return TRUE;
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
static gboolean
-on_key_press_event (GtkWidget *widget,
- GdkEventKey *event,
+on_key_press_event (GtkWidget *widget,
+ GdkEventKey *event,
NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (event)
+ if (event)
{
- guint modifiers;
+ guint modifiers;
- modifiers = gtk_accelerator_get_default_mod_mask ();
+ modifiers = gtk_accelerator_get_default_mod_mask ();
- if (event->keyval == GDK_KEY_Return ||
- event->keyval == GDK_KEY_KP_Enter ||
- event->keyval == GDK_KEY_ISO_Enter ||
- event->keyval == GDK_KEY_space)
+ if (event->keyval == GDK_KEY_Return ||
+ event->keyval == GDK_KEY_KP_Enter ||
+ event->keyval == GDK_KEY_ISO_Enter ||
+ event->keyval == GDK_KEY_space)
{
- GtkWidget *focus_widget;
- GtkWindow *toplevel;
+ GtkWidget *focus_widget;
+ GtkWindow *toplevel;
- priv->current_open_flags = GTK_PLACES_OPEN_NORMAL;
- toplevel = get_toplevel (GTK_WIDGET (view));
+ priv->current_open_flags = GTK_PLACES_OPEN_NORMAL;
+ toplevel = get_toplevel (GTK_WIDGET (view));
- if (!toplevel)
- return FALSE;
+ if (!toplevel)
+ {
+ return FALSE;
+ }
- focus_widget = gtk_window_get_focus (toplevel);
+ focus_widget = gtk_window_get_focus (toplevel);
- if (!NAUTILUS_IS_GTK_PLACES_VIEW_ROW (focus_widget))
- return FALSE;
+ if (!NAUTILUS_IS_GTK_PLACES_VIEW_ROW (focus_widget))
+ {
+ return FALSE;
+ }
- if ((event->state & modifiers) == GDK_SHIFT_MASK)
- priv->current_open_flags = GTK_PLACES_OPEN_NEW_TAB;
- else if ((event->state & modifiers) == GDK_CONTROL_MASK)
- priv->current_open_flags = GTK_PLACES_OPEN_NEW_WINDOW;
+ if ((event->state & modifiers) == GDK_SHIFT_MASK)
+ {
+ priv->current_open_flags = GTK_PLACES_OPEN_NEW_TAB;
+ }
+ else if ((event->state & modifiers) == GDK_CONTROL_MASK)
+ {
+ priv->current_open_flags = GTK_PLACES_OPEN_NEW_WINDOW;
+ }
- activate_row (view, NAUTILUS_GTK_PLACES_VIEW_ROW (focus_widget), priv->current_open_flags);
+ activate_row (view, NAUTILUS_GTK_PLACES_VIEW_ROW (focus_widget), priv->current_open_flags);
- return TRUE;
+ return TRUE;
}
}
- return FALSE;
+ return FALSE;
}
static void
-on_eject_button_clicked (GtkWidget *widget,
+on_eject_button_clicked (GtkWidget *widget,
NautilusGtkPlacesViewRow *row)
{
- if (row)
+ if (row)
{
- GtkWidget *view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
+ GtkWidget *view = gtk_widget_get_ancestor (GTK_WIDGET (row), NAUTILUS_TYPE_GTK_PLACES_VIEW);
- unmount_mount (NAUTILUS_GTK_PLACES_VIEW (view), nautilus_gtk_places_view_row_get_mount (row));
+ unmount_mount (NAUTILUS_GTK_PLACES_VIEW (view), nautilus_gtk_places_view_row_get_mount (row));
}
}
static void
on_connect_button_clicked (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- const gchar *uri;
- GFile *file;
+ NautilusGtkPlacesViewPrivate *priv;
+ const gchar *uri;
+ GFile *file;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- file = NULL;
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ file = NULL;
- /*
- * Since the 'Connect' button is updated whenever the typed
- * address changes, it is sufficient to check if it's sensitive
- * or not, in order to determine if the given address is valid.
- */
- if (!gtk_widget_get_sensitive (priv->connect_button))
- return;
+ /*
+ * Since the 'Connect' button is updated whenever the typed
+ * address changes, it is sufficient to check if it's sensitive
+ * or not, in order to determine if the given address is valid.
+ */
+ if (!gtk_widget_get_sensitive (priv->connect_button))
+ {
+ return;
+ }
- uri = gtk_entry_get_text (GTK_ENTRY (priv->address_entry));
+ uri = gtk_entry_get_text (GTK_ENTRY (priv->address_entry));
- if (uri != NULL && uri[0] != '\0')
- file = g_file_new_for_commandline_arg (uri);
+ if (uri != NULL && uri[0] != '\0')
+ {
+ file = g_file_new_for_commandline_arg (uri);
+ }
- if (file)
+ if (file)
{
- priv->should_open_location = TRUE;
+ priv->should_open_location = TRUE;
- mount_server (view, file);
+ mount_server (view, file);
}
- else
+ else
{
- emit_show_error_message (view, _("Unable to get remote server location"), NULL);
+ emit_show_error_message (view, _("Unable to get remote server location"), NULL);
}
}
static void
on_address_entry_text_changed (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- const gchar* const *supported_protocols;
- gchar *address, *scheme;
- gboolean supported;
+ NautilusGtkPlacesViewPrivate *priv;
+ const gchar * const *supported_protocols;
+ gchar *address, *scheme;
+ gboolean supported;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- supported = FALSE;
- supported_protocols = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
- address = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->address_entry)));
- scheme = g_uri_parse_scheme (address);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ supported = FALSE;
+ supported_protocols = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
+ address = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->address_entry)));
+ scheme = g_uri_parse_scheme (address);
- if (!supported_protocols)
- goto out;
+ if (!supported_protocols)
+ {
+ goto out;
+ }
- if (!scheme)
- goto out;
+ if (!scheme)
+ {
+ goto out;
+ }
- supported = g_strv_contains (supported_protocols, scheme) &&
- !g_strv_contains (unsupported_protocols, scheme);
+ supported = g_strv_contains (supported_protocols, scheme) &&
+ !g_strv_contains (unsupported_protocols, scheme);
out:
- gtk_widget_set_sensitive (priv->connect_button, supported);
- g_free (address);
- g_free (scheme);
+ gtk_widget_set_sensitive (priv->connect_button, supported);
+ g_free (address);
+ g_free (scheme);
}
static void
-on_address_entry_show_help_pressed (NautilusGtkPlacesView *view,
- GtkEntryIconPosition icon_pos,
- GdkEvent *event,
- GtkEntry *entry)
+on_address_entry_show_help_pressed (NautilusGtkPlacesView *view,
+ GtkEntryIconPosition icon_pos,
+ GdkEvent *event,
+ GtkEntry *entry)
{
- NautilusGtkPlacesViewPrivate *priv;
- GdkRectangle rect;
+ NautilusGtkPlacesViewPrivate *priv;
+ GdkRectangle rect;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- /* Setup the auxiliary popover's rectangle */
- gtk_entry_get_icon_area (GTK_ENTRY (priv->address_entry),
- GTK_ENTRY_ICON_SECONDARY,
- &rect);
+ /* Setup the auxiliary popover's rectangle */
+ gtk_entry_get_icon_area (GTK_ENTRY (priv->address_entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ &rect);
- gtk_popover_set_pointing_to (GTK_POPOVER (priv->server_adresses_popover), &rect);
- gtk_widget_set_visible (priv->server_adresses_popover, TRUE);
+ gtk_popover_set_pointing_to (GTK_POPOVER (priv->server_adresses_popover), &rect);
+ gtk_widget_set_visible (priv->server_adresses_popover, TRUE);
}
static void
on_recent_servers_listbox_row_activated (NautilusGtkPlacesView *view,
NautilusGtkPlacesViewRow *row,
- GtkWidget *listbox)
+ GtkWidget *listbox)
{
- NautilusGtkPlacesViewPrivate *priv;
- gchar *uri;
+ NautilusGtkPlacesViewPrivate *priv;
+ gchar *uri;
- priv = nautilus_gtk_places_view_get_instance_private (view);
- uri = g_object_get_data (G_OBJECT (row), "uri");
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ uri = g_object_get_data (G_OBJECT (row), "uri");
- gtk_entry_set_text (GTK_ENTRY (priv->address_entry), uri);
+ gtk_entry_set_text (GTK_ENTRY (priv->address_entry), uri);
- gtk_widget_hide (priv->recent_servers_popover);
+ gtk_widget_hide (priv->recent_servers_popover);
}
static void
on_listbox_row_activated (NautilusGtkPlacesView *view,
NautilusGtkPlacesViewRow *row,
- GtkWidget *listbox)
+ GtkWidget *listbox)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- activate_row (view, row, priv->current_open_flags);
+ activate_row (view, row, priv->current_open_flags);
}
static gboolean
listbox_filter_func (GtkListBoxRow *row,
gpointer user_data)
{
- NautilusGtkPlacesViewPrivate *priv;
- gboolean is_network;
- gboolean is_placeholder;
- gboolean retval;
- gboolean searching;
- gchar *name;
- gchar *path;
+ NautilusGtkPlacesViewPrivate *priv;
+ gboolean is_network;
+ gboolean is_placeholder;
+ gboolean retval;
+ gboolean searching;
+ gchar *name;
+ gchar *path;
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data));
- retval = FALSE;
- searching = priv->search_query && priv->search_query[0] != '\0';
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (user_data));
+ retval = FALSE;
+ searching = priv->search_query && priv->search_query[0] != '\0';
- is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-network"));
- is_placeholder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-placeholder"));
+ is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-network"));
+ is_placeholder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-placeholder"));
- if (is_network && priv->local_only)
- return FALSE;
+ if (is_network && priv->local_only)
+ {
+ return FALSE;
+ }
- if (is_placeholder && searching)
- return FALSE;
+ if (is_placeholder && searching)
+ {
+ return FALSE;
+ }
- if (!searching)
- return TRUE;
+ if (!searching)
+ {
+ return TRUE;
+ }
- g_object_get (row,
- "name", &name,
- "path", &path,
- NULL);
+ g_object_get (row,
+ "name", &name,
+ "path", &path,
+ NULL);
- if (name)
- retval |= strstr (name, priv->search_query) != NULL;
+ if (name)
+ {
+ retval |= strstr (name, priv->search_query) != NULL;
+ }
- if (path)
- retval |= strstr (path, priv->search_query) != NULL;
+ if (path)
+ {
+ retval |= strstr (path, priv->search_query) != NULL;
+ }
- g_free (name);
- g_free (path);
+ g_free (name);
+ g_free (path);
- return retval;
+ return retval;
}
static void
@@ -1944,86 +2051,88 @@ listbox_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
gpointer user_data)
{
- gboolean row_is_network;
- gchar *text;
+ gboolean row_is_network;
+ gchar *text;
- text = NULL;
- row_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-network"));
+ text = NULL;
+ row_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "is-network"));
- if (!before)
+ if (!before)
{
- text = g_strdup_printf ("<b>%s</b>", row_is_network ? _("Networks") : _("On This Computer"));
+ text = g_strdup_printf ("<b>%s</b>", row_is_network ? _("Networks") : _("On This Computer"));
}
- else
+ else
{
- gboolean before_is_network;
+ gboolean before_is_network;
- before_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (before), "is-network"));
+ before_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (before), "is-network"));
- if (before_is_network != row_is_network)
- text = g_strdup_printf ("<b>%s</b>", row_is_network ? _("Networks") : _("On This Computer"));
+ if (before_is_network != row_is_network)
+ {
+ text = g_strdup_printf ("<b>%s</b>", row_is_network ? _("Networks") : _("On This Computer"));
+ }
}
- if (text)
+ if (text)
{
- GtkWidget *header;
- GtkWidget *label;
- GtkWidget *separator;
+ GtkWidget *header;
+ GtkWidget *label;
+ GtkWidget *separator;
- header = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_widget_set_margin_top (header, 6);
+ header = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_widget_set_margin_top (header, 6);
- separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- label = g_object_new (GTK_TYPE_LABEL,
- "use_markup", TRUE,
- "margin-start", 12,
- "label", text,
- "xalign", 0.0f,
- NULL);
- if (row_is_network)
+ label = g_object_new (GTK_TYPE_LABEL,
+ "use_markup", TRUE,
+ "margin-start", 12,
+ "label", text,
+ "xalign", 0.0f,
+ NULL);
+ if (row_is_network)
{
- GtkWidget *header_name;
- GtkWidget *network_header_spinner;
+ GtkWidget *header_name;
+ GtkWidget *network_header_spinner;
- g_object_set (label,
- "margin-end", 6,
- NULL);
+ g_object_set (label,
+ "margin-end", 6,
+ NULL);
- header_name = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- network_header_spinner = gtk_spinner_new ();
- g_object_set (network_header_spinner,
- "margin-end", 12,
- NULL);
- g_object_bind_property (NAUTILUS_GTK_PLACES_VIEW (user_data),
- "fetching-networks",
- network_header_spinner,
- "active",
- G_BINDING_SYNC_CREATE);
-
- gtk_container_add (GTK_CONTAINER (header_name), label);
- gtk_container_add (GTK_CONTAINER (header_name), network_header_spinner);
- gtk_container_add (GTK_CONTAINER (header), header_name);
+ header_name = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ network_header_spinner = gtk_spinner_new ();
+ g_object_set (network_header_spinner,
+ "margin-end", 12,
+ NULL);
+ g_object_bind_property (NAUTILUS_GTK_PLACES_VIEW (user_data),
+ "fetching-networks",
+ network_header_spinner,
+ "active",
+ G_BINDING_SYNC_CREATE);
+
+ gtk_container_add (GTK_CONTAINER (header_name), label);
+ gtk_container_add (GTK_CONTAINER (header_name), network_header_spinner);
+ gtk_container_add (GTK_CONTAINER (header), header_name);
}
- else
+ else
{
- g_object_set (label,
- "hexpand", TRUE,
- "margin-end", 12,
- NULL);
- gtk_container_add (GTK_CONTAINER (header), label);
+ g_object_set (label,
+ "hexpand", TRUE,
+ "margin-end", 12,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (header), label);
}
- gtk_container_add (GTK_CONTAINER (header), separator);
- gtk_widget_show_all (header);
+ gtk_container_add (GTK_CONTAINER (header), separator);
+ gtk_widget_show_all (header);
- gtk_list_box_row_set_header (row, header);
+ gtk_list_box_row_set_header (row, header);
- g_free (text);
+ g_free (text);
}
- else
+ else
{
- gtk_list_box_row_set_header (row, NULL);
+ gtk_list_box_row_set_header (row, NULL);
}
}
@@ -2032,237 +2141,243 @@ listbox_sort_func (GtkListBoxRow *row1,
GtkListBoxRow *row2,
gpointer user_data)
{
- gboolean row1_is_network;
- gboolean row2_is_network;
- gchar *path1;
- gchar *path2;
- gboolean *is_placeholder1;
- gboolean *is_placeholder2;
- gint retval;
+ gboolean row1_is_network;
+ gboolean row2_is_network;
+ gchar *path1;
+ gchar *path2;
+ gboolean *is_placeholder1;
+ gboolean *is_placeholder2;
+ gint retval;
- row1_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row1), "is-network"));
- row2_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row2), "is-network"));
+ row1_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row1), "is-network"));
+ row2_is_network = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row2), "is-network"));
- retval = row1_is_network - row2_is_network;
+ retval = row1_is_network - row2_is_network;
- if (retval != 0)
- return retval;
+ if (retval != 0)
+ {
+ return retval;
+ }
- is_placeholder1 = g_object_get_data (G_OBJECT (row1), "is-placeholder");
- is_placeholder2 = g_object_get_data (G_OBJECT (row2), "is-placeholder");
+ is_placeholder1 = g_object_get_data (G_OBJECT (row1), "is-placeholder");
+ is_placeholder2 = g_object_get_data (G_OBJECT (row2), "is-placeholder");
- /* we can't have two placeholders for the same section */
- g_assert (!(is_placeholder1 != NULL && is_placeholder2 != NULL));
+ /* we can't have two placeholders for the same section */
+ g_assert (!(is_placeholder1 != NULL && is_placeholder2 != NULL));
- if (is_placeholder1)
- return -1;
- if (is_placeholder2)
- return 1;
+ if (is_placeholder1)
+ {
+ return -1;
+ }
+ if (is_placeholder2)
+ {
+ return 1;
+ }
- g_object_get (row1, "path", &path1, NULL);
- g_object_get (row2, "path", &path2, NULL);
+ g_object_get (row1, "path", &path1, NULL);
+ g_object_get (row2, "path", &path2, NULL);
- retval = g_utf8_collate (path1, path2);
+ retval = g_utf8_collate (path1, path2);
- g_free (path1);
- g_free (path2);
+ g_free (path1);
+ g_free (path2);
- return retval;
+ return retval;
}
static void
nautilus_gtk_places_view_constructed (GObject *object)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (object));
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (object));
- G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->constructed (object);
+ G_OBJECT_CLASS (nautilus_gtk_places_view_parent_class)->constructed (object);
- gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->listbox),
- listbox_sort_func,
- object,
- NULL);
- gtk_list_box_set_filter_func (GTK_LIST_BOX (priv->listbox),
- listbox_filter_func,
- object,
- NULL);
- gtk_list_box_set_header_func (GTK_LIST_BOX (priv->listbox),
- listbox_header_func,
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->listbox),
+ listbox_sort_func,
object,
NULL);
-
- /* load drives */
- update_places (NAUTILUS_GTK_PLACES_VIEW (object));
-
- g_signal_connect_swapped (priv->volume_monitor,
- "mount-added",
- G_CALLBACK (update_places),
- object);
- g_signal_connect_swapped (priv->volume_monitor,
- "mount-changed",
- G_CALLBACK (update_places),
- object);
- g_signal_connect_swapped (priv->volume_monitor,
- "mount-removed",
- G_CALLBACK (update_places),
- object);
- g_signal_connect_swapped (priv->volume_monitor,
- "volume-added",
- G_CALLBACK (update_places),
- object);
- g_signal_connect_swapped (priv->volume_monitor,
- "volume-changed",
- G_CALLBACK (update_places),
- object);
- g_signal_connect_swapped (priv->volume_monitor,
- "volume-removed",
- G_CALLBACK (update_places),
- object);
+ gtk_list_box_set_filter_func (GTK_LIST_BOX (priv->listbox),
+ listbox_filter_func,
+ object,
+ NULL);
+ gtk_list_box_set_header_func (GTK_LIST_BOX (priv->listbox),
+ listbox_header_func,
+ object,
+ NULL);
+
+ /* load drives */
+ update_places (NAUTILUS_GTK_PLACES_VIEW (object));
+
+ g_signal_connect_swapped (priv->volume_monitor,
+ "mount-added",
+ G_CALLBACK (update_places),
+ object);
+ g_signal_connect_swapped (priv->volume_monitor,
+ "mount-changed",
+ G_CALLBACK (update_places),
+ object);
+ g_signal_connect_swapped (priv->volume_monitor,
+ "mount-removed",
+ G_CALLBACK (update_places),
+ object);
+ g_signal_connect_swapped (priv->volume_monitor,
+ "volume-added",
+ G_CALLBACK (update_places),
+ object);
+ g_signal_connect_swapped (priv->volume_monitor,
+ "volume-changed",
+ G_CALLBACK (update_places),
+ object);
+ g_signal_connect_swapped (priv->volume_monitor,
+ "volume-removed",
+ G_CALLBACK (update_places),
+ object);
}
static void
nautilus_gtk_places_view_map (GtkWidget *widget)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (widget));
+ priv = nautilus_gtk_places_view_get_instance_private (NAUTILUS_GTK_PLACES_VIEW (widget));
- gtk_entry_set_text (GTK_ENTRY (priv->address_entry), "");
+ gtk_entry_set_text (GTK_ENTRY (priv->address_entry), "");
- GTK_WIDGET_CLASS (nautilus_gtk_places_view_parent_class)->map (widget);
+ GTK_WIDGET_CLASS (nautilus_gtk_places_view_parent_class)->map (widget);
}
static void
nautilus_gtk_places_view_class_init (NautilusGtkPlacesViewClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- object_class->finalize = nautilus_gtk_places_view_finalize;
- object_class->constructed = nautilus_gtk_places_view_constructed;
- object_class->get_property = nautilus_gtk_places_view_get_property;
- object_class->set_property = nautilus_gtk_places_view_set_property;
-
- widget_class->map = nautilus_gtk_places_view_map;
-
- /**
- * NautilusGtkPlacesView::open-location:
- * @view: the object which received the signal.
- * @location: (type Gio.File): #GFile to which the caller should switch.
- * @open_flags: a single value from #GtkPlacesOpenFlags specifying how the @location
- * should be opened.
- *
- * The places view emits this signal when the user selects a location
- * in it. The calling application should display the contents of that
- * location; for example, a file manager should show a list of files in
- * the specified location.
- *
- * Since: 3.18
- */
- places_view_signals [OPEN_LOCATION] =
- g_signal_new ("open-location",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NautilusGtkPlacesViewClass, open_location),
- NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- G_TYPE_OBJECT,
- GTK_TYPE_PLACES_OPEN_FLAGS);
-
- /**
- * NautilusGtkPlacesView::show-error-message:
- * @view: the object which received the signal.
- * @primary: primary message with a summary of the error to show.
- * @secondary: secondary message with details of the error to show.
- *
- * The places view emits this signal when it needs the calling
- * application to present an error message. Most of these messages
- * refer to mounting or unmounting media, for example, when a drive
- * cannot be started for some reason.
- *
- * Since: 3.18
- */
- places_view_signals [SHOW_ERROR_MESSAGE] =
- g_signal_new ("show-error-message",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NautilusGtkPlacesViewClass, show_error_message),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 2,
- G_TYPE_STRING,
- G_TYPE_STRING);
-
- properties[PROP_LOCAL_ONLY] =
- g_param_spec_boolean ("local-only",
- "Local Only",
- "Whether the sidebar only includes local files",
- FALSE,
- G_PARAM_READWRITE);
-
- properties[PROP_LOADING] =
- g_param_spec_boolean ("loading",
- "Loading",
- "Whether the view is loading locations",
- FALSE,
- G_PARAM_READABLE);
-
- properties[PROP_FETCHING_NETWORKS] =
- g_param_spec_boolean ("fetching-networks",
- "Fetching networks",
- "Whether the view is fetching networks",
- FALSE,
- G_PARAM_READABLE);
-
- properties[PROP_OPEN_FLAGS] =
- g_param_spec_flags ("open-flags",
- "Open Flags",
- "Modes in which the calling application can open locations selected in the sidebar",
- GTK_TYPE_PLACES_OPEN_FLAGS,
- GTK_PLACES_OPEN_NORMAL,
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = nautilus_gtk_places_view_finalize;
+ object_class->constructed = nautilus_gtk_places_view_constructed;
+ object_class->get_property = nautilus_gtk_places_view_get_property;
+ object_class->set_property = nautilus_gtk_places_view_set_property;
+
+ widget_class->map = nautilus_gtk_places_view_map;
+
+ /**
+ * NautilusGtkPlacesView::open-location:
+ * @view: the object which received the signal.
+ * @location: (type Gio.File): #GFile to which the caller should switch.
+ * @open_flags: a single value from #GtkPlacesOpenFlags specifying how the @location
+ * should be opened.
+ *
+ * The places view emits this signal when the user selects a location
+ * in it. The calling application should display the contents of that
+ * location; for example, a file manager should show a list of files in
+ * the specified location.
+ *
+ * Since: 3.18
+ */
+ places_view_signals [OPEN_LOCATION] =
+ g_signal_new ("open-location",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NautilusGtkPlacesViewClass, open_location),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 2,
+ G_TYPE_OBJECT,
+ GTK_TYPE_PLACES_OPEN_FLAGS);
+
+ /**
+ * NautilusGtkPlacesView::show-error-message:
+ * @view: the object which received the signal.
+ * @primary: primary message with a summary of the error to show.
+ * @secondary: secondary message with details of the error to show.
+ *
+ * The places view emits this signal when it needs the calling
+ * application to present an error message. Most of these messages
+ * refer to mounting or unmounting media, for example, when a drive
+ * cannot be started for some reason.
+ *
+ * Since: 3.18
+ */
+ places_view_signals [SHOW_ERROR_MESSAGE] =
+ g_signal_new ("show-error-message",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NautilusGtkPlacesViewClass, show_error_message),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+
+ properties[PROP_LOCAL_ONLY] =
+ g_param_spec_boolean ("local-only",
+ "Local Only",
+ "Whether the sidebar only includes local files",
+ FALSE,
G_PARAM_READWRITE);
- g_object_class_install_properties (object_class, LAST_PROP, properties);
-
- /* Bind class to template */
- gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/gtk/ui/nautilusgtkplacesview.ui");
-
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, actionbar);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, address_entry);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, address_entry_completion);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, completion_store);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, connect_button);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, listbox);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_listbox);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_popover);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_stack);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, stack);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, server_adresses_popover);
-
- gtk_widget_class_bind_template_callback (widget_class, on_address_entry_text_changed);
- gtk_widget_class_bind_template_callback (widget_class, on_address_entry_show_help_pressed);
- gtk_widget_class_bind_template_callback (widget_class, on_connect_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
- gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
- gtk_widget_class_bind_template_callback (widget_class, on_recent_servers_listbox_row_activated);
-
- gtk_widget_class_set_css_name (widget_class, "placesview");
+ properties[PROP_LOADING] =
+ g_param_spec_boolean ("loading",
+ "Loading",
+ "Whether the view is loading locations",
+ FALSE,
+ G_PARAM_READABLE);
+
+ properties[PROP_FETCHING_NETWORKS] =
+ g_param_spec_boolean ("fetching-networks",
+ "Fetching networks",
+ "Whether the view is fetching networks",
+ FALSE,
+ G_PARAM_READABLE);
+
+ properties[PROP_OPEN_FLAGS] =
+ g_param_spec_flags ("open-flags",
+ "Open Flags",
+ "Modes in which the calling application can open locations selected in the sidebar",
+ GTK_TYPE_PLACES_OPEN_FLAGS,
+ GTK_PLACES_OPEN_NORMAL,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ /* Bind class to template */
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/gtk/ui/nautilusgtkplacesview.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, actionbar);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, address_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, address_entry_completion);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, completion_store);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, connect_button);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, listbox);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_listbox);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_popover);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, recent_servers_stack);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, stack);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusGtkPlacesView, server_adresses_popover);
+
+ gtk_widget_class_bind_template_callback (widget_class, on_address_entry_text_changed);
+ gtk_widget_class_bind_template_callback (widget_class, on_address_entry_show_help_pressed);
+ gtk_widget_class_bind_template_callback (widget_class, on_connect_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
+ gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, on_recent_servers_listbox_row_activated);
+
+ gtk_widget_class_set_css_name (widget_class, "placesview");
}
static void
nautilus_gtk_places_view_init (NautilusGtkPlacesView *self)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- priv = nautilus_gtk_places_view_get_instance_private (self);
+ priv = nautilus_gtk_places_view_get_instance_private (self);
- priv->volume_monitor = g_volume_monitor_get ();
- priv->open_flags = GTK_PLACES_OPEN_NORMAL;
- priv->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- priv->space_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ priv->volume_monitor = g_volume_monitor_get ();
+ priv->open_flags = GTK_PLACES_OPEN_NORMAL;
+ priv->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ priv->space_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- gtk_widget_init_template (GTK_WIDGET (self));
+ gtk_widget_init_template (GTK_WIDGET (self));
}
/**
@@ -2281,7 +2396,7 @@ nautilus_gtk_places_view_init (NautilusGtkPlacesView *self)
GtkWidget *
nautilus_gtk_places_view_new (void)
{
- return g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW, NULL);
+ return g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW, NULL);
}
/**
@@ -2308,19 +2423,19 @@ nautilus_gtk_places_view_new (void)
* Since: 3.18
*/
void
-nautilus_gtk_places_view_set_open_flags (NautilusGtkPlacesView *view,
- GtkPlacesOpenFlags flags)
+nautilus_gtk_places_view_set_open_flags (NautilusGtkPlacesView *view,
+ GtkPlacesOpenFlags flags)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (priv->open_flags != flags)
+ if (priv->open_flags != flags)
{
- priv->open_flags = flags;
- g_object_notify_by_pspec (G_OBJECT (view), properties[PROP_OPEN_FLAGS]);
+ priv->open_flags = flags;
+ g_object_notify_by_pspec (G_OBJECT (view), properties[PROP_OPEN_FLAGS]);
}
}
@@ -2337,13 +2452,13 @@ nautilus_gtk_places_view_set_open_flags (NautilusGtkPlacesView *view,
GtkPlacesOpenFlags
nautilus_gtk_places_view_get_open_flags (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), 0);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), 0);
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- return priv->open_flags;
+ return priv->open_flags;
}
/**
@@ -2354,16 +2469,16 @@ nautilus_gtk_places_view_get_open_flags (NautilusGtkPlacesView *view)
*
* Returns: (transfer none): the current search query.
*/
-const gchar*
+const gchar *
nautilus_gtk_places_view_get_search_query (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), NULL);
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- return priv->search_query;
+ return priv->search_query;
}
/**
@@ -2376,23 +2491,23 @@ nautilus_gtk_places_view_get_search_query (NautilusGtkPlacesView *view)
*/
void
nautilus_gtk_places_view_set_search_query (NautilusGtkPlacesView *view,
- const gchar *query_text)
+ const gchar *query_text)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (g_strcmp0 (priv->search_query, query_text) != 0)
+ if (g_strcmp0 (priv->search_query, query_text) != 0)
{
- g_clear_pointer (&priv->search_query, g_free);
- priv->search_query = g_strdup (query_text);
+ g_clear_pointer (&priv->search_query, g_free);
+ priv->search_query = g_strdup (query_text);
- gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->listbox));
- gtk_list_box_invalidate_headers (GTK_LIST_BOX (priv->listbox));
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (priv->listbox));
+ gtk_list_box_invalidate_headers (GTK_LIST_BOX (priv->listbox));
- update_view_mode (view);
+ update_view_mode (view);
}
}
@@ -2407,74 +2522,74 @@ nautilus_gtk_places_view_set_search_query (NautilusGtkPlacesView *view,
gboolean
nautilus_gtk_places_view_get_loading (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE);
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- return priv->loading;
+ return priv->loading;
}
static void
update_loading (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
- gboolean loading;
+ NautilusGtkPlacesViewPrivate *priv;
+ gboolean loading;
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
- priv = nautilus_gtk_places_view_get_instance_private (view);
- loading = priv->fetching_networks || priv->connecting_to_server ||
- priv->mounting_volume || priv->unmounting_mount;
+ priv = nautilus_gtk_places_view_get_instance_private (view);
+ loading = priv->fetching_networks || priv->connecting_to_server ||
+ priv->mounting_volume || priv->unmounting_mount;
- set_busy_cursor (view, loading);
- nautilus_gtk_places_view_set_loading (view, loading);
+ set_busy_cursor (view, loading);
+ nautilus_gtk_places_view_set_loading (view, loading);
}
static void
nautilus_gtk_places_view_set_loading (NautilusGtkPlacesView *view,
- gboolean loading)
+ gboolean loading)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (priv->loading != loading)
+ if (priv->loading != loading)
{
- priv->loading = loading;
- g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_LOADING]);
+ priv->loading = loading;
+ g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_LOADING]);
}
}
static gboolean
nautilus_gtk_places_view_get_fetching_networks (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE);
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- return priv->fetching_networks;
+ return priv->fetching_networks;
}
static void
nautilus_gtk_places_view_set_fetching_networks (NautilusGtkPlacesView *view,
- gboolean fetching_networks)
+ gboolean fetching_networks)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (priv->fetching_networks != fetching_networks)
+ if (priv->fetching_networks != fetching_networks)
{
- priv->fetching_networks = fetching_networks;
- g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_FETCHING_NETWORKS]);
+ priv->fetching_networks = fetching_networks;
+ g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_FETCHING_NETWORKS]);
}
}
@@ -2492,13 +2607,13 @@ nautilus_gtk_places_view_set_fetching_networks (NautilusGtkPlacesView *view,
gboolean
nautilus_gtk_places_view_get_local_only (NautilusGtkPlacesView *view)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view), FALSE);
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- return priv->local_only;
+ return priv->local_only;
}
/**
@@ -2512,23 +2627,23 @@ nautilus_gtk_places_view_get_local_only (NautilusGtkPlacesView *view)
*/
void
nautilus_gtk_places_view_set_local_only (NautilusGtkPlacesView *view,
- gboolean local_only)
+ gboolean local_only)
{
- NautilusGtkPlacesViewPrivate *priv;
+ NautilusGtkPlacesViewPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW (view));
- priv = nautilus_gtk_places_view_get_instance_private (view);
+ priv = nautilus_gtk_places_view_get_instance_private (view);
- if (priv->local_only != local_only)
+ if (priv->local_only != local_only)
{
- priv->local_only = local_only;
+ priv->local_only = local_only;
- gtk_widget_set_visible (priv->actionbar, !local_only);
- update_places (view);
+ gtk_widget_set_visible (priv->actionbar, !local_only);
+ update_places (view);
- update_view_mode (view);
+ update_view_mode (view);
- g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_LOCAL_ONLY]);
+ g_object_notify_by_pspec (G_OBJECT (view), properties [PROP_LOCAL_ONLY]);
}
}
diff --git a/src/gtk/nautilusgtkplacesviewrow.c b/src/gtk/nautilusgtkplacesviewrow.c
index 5c820cf3d..d19c3268f 100644
--- a/src/gtk/nautilusgtkplacesviewrow.c
+++ b/src/gtk/nautilusgtkplacesviewrow.c
@@ -42,38 +42,39 @@
struct _NautilusGtkPlacesViewRow
{
- GtkListBoxRow parent_instance;
+ GtkListBoxRow parent_instance;
- GtkLabel *available_space_label;
- GtkSpinner *busy_spinner;
- GtkButton *eject_button;
- GtkImage *eject_icon;
- GtkEventBox *event_box;
- GtkImage *icon_image;
- GtkLabel *name_label;
- GtkLabel *path_label;
+ GtkLabel *available_space_label;
+ GtkSpinner *busy_spinner;
+ GtkButton *eject_button;
+ GtkImage *eject_icon;
+ GtkEventBox *event_box;
+ GtkImage *icon_image;
+ GtkLabel *name_label;
+ GtkLabel *path_label;
- GVolume *volume;
- GMount *mount;
- GFile *file;
+ GVolume *volume;
+ GMount *mount;
+ GFile *file;
- GCancellable *cancellable;
+ GCancellable *cancellable;
- gint is_network : 1;
+ gint is_network : 1;
};
G_DEFINE_TYPE (NautilusGtkPlacesViewRow, nautilus_gtk_places_view_row, GTK_TYPE_LIST_BOX_ROW)
-enum {
- PROP_0,
- PROP_ICON,
- PROP_NAME,
- PROP_PATH,
- PROP_VOLUME,
- PROP_MOUNT,
- PROP_FILE,
- PROP_IS_NETWORK,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_ICON,
+ PROP_NAME,
+ PROP_PATH,
+ PROP_VOLUME,
+ PROP_MOUNT,
+ PROP_FILE,
+ PROP_IS_NETWORK,
+ LAST_PROP
};
static GParamSpec *properties [LAST_PROP];
@@ -83,113 +84,115 @@ measure_available_space_finished (GObject *object,
GAsyncResult *res,
gpointer user_data)
{
- NautilusGtkPlacesViewRow *row = user_data;
- GFileInfo *info;
- GError *error;
- guint64 free_space;
- guint64 total_space;
- gchar *formatted_free_size;
- gchar *formatted_total_size;
- gchar *label;
- guint plural_form;
-
- error = NULL;
-
- info = g_file_query_filesystem_info_finish (G_FILE (object),
- res,
- &error);
-
- if (error)
+ NautilusGtkPlacesViewRow *row = user_data;
+ GFileInfo *info;
+ GError *error;
+ guint64 free_space;
+ guint64 total_space;
+ gchar *formatted_free_size;
+ gchar *formatted_total_size;
+ gchar *label;
+ guint plural_form;
+
+ error = NULL;
+
+ info = g_file_query_filesystem_info_finish (G_FILE (object),
+ res,
+ &error);
+
+ if (error)
{
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
- !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED))
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) &&
+ !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED))
{
- g_warning ("Failed to measure available space: %s", error->message);
+ g_warning ("Failed to measure available space: %s", error->message);
}
- g_clear_error (&error);
- goto out;
+ g_clear_error (&error);
+ goto out;
}
- if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE) ||
- !g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE))
+ if (!g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE) ||
+ !g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE))
{
- g_object_unref (info);
- goto out;
+ g_object_unref (info);
+ goto out;
}
- free_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
- total_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
+ free_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+ total_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
- formatted_free_size = g_format_size (free_space);
- formatted_total_size = g_format_size (total_space);
+ formatted_free_size = g_format_size (free_space);
+ formatted_total_size = g_format_size (total_space);
- /* read g_format_size code in glib for further understanding */
- plural_form = free_space < 1000 ? free_space : free_space % 1000 + 1000;
+ /* read g_format_size code in glib for further understanding */
+ plural_form = free_space < 1000 ? free_space : free_space % 1000 + 1000;
- /* Translators: respectively, free and total space of the drive. The plural form
- * should be based on the free space available.
- * i.e. 1 GB / 24 GB available.
- */
- label = g_strdup_printf (dngettext (GETTEXT_PACKAGE, "%s / %s available", "%s / %s available", plural_form),
- formatted_free_size, formatted_total_size);
+ /* Translators: respectively, free and total space of the drive. The plural form
+ * should be based on the free space available.
+ * i.e. 1 GB / 24 GB available.
+ */
+ label = g_strdup_printf (dngettext (GETTEXT_PACKAGE, "%s / %s available", "%s / %s available", plural_form),
+ formatted_free_size, formatted_total_size);
- gtk_label_set_label (row->available_space_label, label);
+ gtk_label_set_label (row->available_space_label, label);
- g_object_unref (info);
- g_free (formatted_total_size);
- g_free (formatted_free_size);
- g_free (label);
+ g_object_unref (info);
+ g_free (formatted_total_size);
+ g_free (formatted_free_size);
+ g_free (label);
out:
- g_object_unref (object);
+ g_object_unref (object);
}
static void
measure_available_space (NautilusGtkPlacesViewRow *row)
{
- gboolean should_measure;
+ gboolean should_measure;
- should_measure = (!row->is_network && (row->volume || row->mount || row->file));
+ should_measure = (!row->is_network && (row->volume || row->mount || row->file));
- gtk_label_set_label (row->available_space_label, "");
- gtk_widget_set_visible (GTK_WIDGET (row->available_space_label), should_measure);
+ gtk_label_set_label (row->available_space_label, "");
+ gtk_widget_set_visible (GTK_WIDGET (row->available_space_label), should_measure);
- if (should_measure)
+ if (should_measure)
{
- GFile *file = NULL;
+ GFile *file = NULL;
- if (row->file)
+ if (row->file)
{
- file = g_object_ref (row->file);
+ file = g_object_ref (row->file);
}
- else if (row->mount)
+ else if (row->mount)
{
- file = g_mount_get_root (row->mount);
+ file = g_mount_get_root (row->mount);
}
- else if (row->volume)
+ else if (row->volume)
{
- GMount *mount;
+ GMount *mount;
- mount = g_volume_get_mount (row->volume);
+ mount = g_volume_get_mount (row->volume);
- if (mount)
- file = g_mount_get_root (row->mount);
+ if (mount)
+ {
+ file = g_mount_get_root (row->mount);
+ }
- g_clear_object (&mount);
+ g_clear_object (&mount);
}
- if (file)
+ if (file)
{
- g_cancellable_cancel (row->cancellable);
- g_clear_object (&row->cancellable);
- row->cancellable = g_cancellable_new ();
-
- g_file_query_filesystem_info_async (file,
- G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,
- G_PRIORITY_DEFAULT,
- row->cancellable,
- measure_available_space_finished,
- row);
+ g_cancellable_cancel (row->cancellable);
+ g_clear_object (&row->cancellable);
+ row->cancellable = g_cancellable_new ();
+
+ g_file_query_filesystem_info_async (file,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE "," G_FILE_ATTRIBUTE_FILESYSTEM_SIZE,
+ G_PRIORITY_DEFAULT,
+ row->cancellable,
+ measure_available_space_finished,
+ row);
}
}
}
@@ -197,294 +200,326 @@ measure_available_space (NautilusGtkPlacesViewRow *row)
static void
nautilus_gtk_places_view_row_finalize (GObject *object)
{
- NautilusGtkPlacesViewRow *self = NAUTILUS_GTK_PLACES_VIEW_ROW (object);
+ NautilusGtkPlacesViewRow *self = NAUTILUS_GTK_PLACES_VIEW_ROW (object);
- g_cancellable_cancel (self->cancellable);
+ g_cancellable_cancel (self->cancellable);
- g_clear_object (&self->volume);
- g_clear_object (&self->mount);
- g_clear_object (&self->file);
- g_clear_object (&self->cancellable);
+ g_clear_object (&self->volume);
+ g_clear_object (&self->mount);
+ g_clear_object (&self->file);
+ g_clear_object (&self->cancellable);
- G_OBJECT_CLASS (nautilus_gtk_places_view_row_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_gtk_places_view_row_parent_class)->finalize (object);
}
static void
nautilus_gtk_places_view_row_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusGtkPlacesViewRow *self;
- GIcon *icon;
+ NautilusGtkPlacesViewRow *self;
+ GIcon *icon;
- self = NAUTILUS_GTK_PLACES_VIEW_ROW (object);
- icon = NULL;
+ self = NAUTILUS_GTK_PLACES_VIEW_ROW (object);
+ icon = NULL;
- switch (prop_id)
+ switch (prop_id)
{
- case PROP_ICON:
- gtk_image_get_gicon (self->icon_image, &icon, NULL);
- g_value_set_object (value, icon);
- break;
+ case PROP_ICON:
+ {
+ gtk_image_get_gicon (self->icon_image, &icon, NULL);
+ g_value_set_object (value, icon);
+ }
+ break;
- case PROP_NAME:
- g_value_set_string (value, gtk_label_get_label (self->name_label));
- break;
+ case PROP_NAME:
+ {
+ g_value_set_string (value, gtk_label_get_label (self->name_label));
+ }
+ break;
- case PROP_PATH:
- g_value_set_string (value, gtk_label_get_label (self->path_label));
- break;
+ case PROP_PATH:
+ {
+ g_value_set_string (value, gtk_label_get_label (self->path_label));
+ }
+ break;
- case PROP_VOLUME:
- g_value_set_object (value, self->volume);
- break;
+ case PROP_VOLUME:
+ {
+ g_value_set_object (value, self->volume);
+ }
+ break;
- case PROP_MOUNT:
- g_value_set_object (value, self->mount);
- break;
+ case PROP_MOUNT:
+ {
+ g_value_set_object (value, self->mount);
+ }
+ break;
- case PROP_FILE:
- g_value_set_object (value, self->file);
- break;
+ case PROP_FILE:
+ {
+ g_value_set_object (value, self->file);
+ }
+ break;
- case PROP_IS_NETWORK:
- g_value_set_boolean (value, self->is_network);
- break;
+ case PROP_IS_NETWORK:
+ {
+ g_value_set_boolean (value, self->is_network);
+ }
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
nautilus_gtk_places_view_row_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusGtkPlacesViewRow *self = NAUTILUS_GTK_PLACES_VIEW_ROW (object);
+ NautilusGtkPlacesViewRow *self = NAUTILUS_GTK_PLACES_VIEW_ROW (object);
- switch (prop_id)
+ switch (prop_id)
{
- case PROP_ICON:
- gtk_image_set_from_gicon (self->icon_image,
- g_value_get_object (value),
- GTK_ICON_SIZE_LARGE_TOOLBAR);
- break;
-
- case PROP_NAME:
- gtk_label_set_label (self->name_label, g_value_get_string (value));
- break;
-
- case PROP_PATH:
- gtk_label_set_label (self->path_label, g_value_get_string (value));
- break;
-
- case PROP_VOLUME:
- g_set_object (&self->volume, g_value_get_object (value));
- break;
-
- case PROP_MOUNT:
- g_set_object (&self->mount, g_value_get_object (value));
-
- /*
- * When we hide the eject button, no size is allocated for it. Since
- * we want to have alignment between rows, it needs an empty space
- * when the eject button is not available. So, call then
- * gtk_widget_set_child_visible(), which makes the button allocate the
- * size but it stays hidden when needed.
- */
- gtk_widget_set_child_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
- measure_available_space (self);
- break;
-
- case PROP_FILE:
- g_set_object (&self->file, g_value_get_object (value));
- measure_available_space (self);
- break;
-
- case PROP_IS_NETWORK:
- nautilus_gtk_places_view_row_set_is_network (self, g_value_get_boolean (value));
- measure_available_space (self);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ case PROP_ICON:
+ {
+ gtk_image_set_from_gicon (self->icon_image,
+ g_value_get_object (value),
+ GTK_ICON_SIZE_LARGE_TOOLBAR);
+ }
+ break;
+
+ case PROP_NAME:
+ {
+ gtk_label_set_label (self->name_label, g_value_get_string (value));
+ }
+ break;
+
+ case PROP_PATH:
+ {
+ gtk_label_set_label (self->path_label, g_value_get_string (value));
+ }
+ break;
+
+ case PROP_VOLUME:
+ {
+ g_set_object (&self->volume, g_value_get_object (value));
+ }
+ break;
+
+ case PROP_MOUNT:
+ {
+ g_set_object (&self->mount, g_value_get_object (value));
+
+ /*
+ * When we hide the eject button, no size is allocated for it. Since
+ * we want to have alignment between rows, it needs an empty space
+ * when the eject button is not available. So, call then
+ * gtk_widget_set_child_visible(), which makes the button allocate the
+ * size but it stays hidden when needed.
+ */
+ gtk_widget_set_child_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
+ measure_available_space (self);
+ }
+ break;
+
+ case PROP_FILE:
+ {
+ g_set_object (&self->file, g_value_get_object (value));
+ measure_available_space (self);
+ }
+ break;
+
+ case PROP_IS_NETWORK:
+ {
+ nautilus_gtk_places_view_row_set_is_network (self, g_value_get_boolean (value));
+ measure_available_space (self);
+ }
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
nautilus_gtk_places_view_row_class_init (NautilusGtkPlacesViewRowClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- object_class->finalize = nautilus_gtk_places_view_row_finalize;
- object_class->get_property = nautilus_gtk_places_view_row_get_property;
- object_class->set_property = nautilus_gtk_places_view_row_set_property;
-
- properties[PROP_ICON] =
- g_param_spec_object ("icon",
- "Icon of the row",
- "The icon representing the volume",
- G_TYPE_ICON,
- G_PARAM_READWRITE);
-
- properties[PROP_NAME] =
- g_param_spec_string ("name",
- "Name of the volume",
- "The name of the volume",
- "",
- G_PARAM_READWRITE);
-
- properties[PROP_PATH] =
- g_param_spec_string ("path",
- "Path of the volume",
- "The path of the volume",
- "",
- G_PARAM_READWRITE);
-
- properties[PROP_VOLUME] =
- g_param_spec_object ("volume",
- "Volume represented by the row",
- "The volume represented by the row",
- G_TYPE_VOLUME,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
- properties[PROP_MOUNT] =
- g_param_spec_object ("mount",
- "Mount represented by the row",
- "The mount point represented by the row, if any",
- G_TYPE_MOUNT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
- properties[PROP_FILE] =
- g_param_spec_object ("file",
- "File represented by the row",
- "The file represented by the row, if any",
- G_TYPE_FILE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
- properties[PROP_IS_NETWORK] =
- g_param_spec_boolean ("is-network",
- "Whether the row represents a network location",
- "Whether the row represents a network location",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (object_class, LAST_PROP, properties);
-
- gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/gtk/ui/nautilusgtkplacesviewrow.ui");
-
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, available_space_label);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, busy_spinner);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, eject_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, eject_icon);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, event_box);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, icon_image);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, name_label);
- gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, path_label);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->finalize = nautilus_gtk_places_view_row_finalize;
+ object_class->get_property = nautilus_gtk_places_view_row_get_property;
+ object_class->set_property = nautilus_gtk_places_view_row_set_property;
+
+ properties[PROP_ICON] =
+ g_param_spec_object ("icon",
+ "Icon of the row",
+ "The icon representing the volume",
+ G_TYPE_ICON,
+ G_PARAM_READWRITE);
+
+ properties[PROP_NAME] =
+ g_param_spec_string ("name",
+ "Name of the volume",
+ "The name of the volume",
+ "",
+ G_PARAM_READWRITE);
+
+ properties[PROP_PATH] =
+ g_param_spec_string ("path",
+ "Path of the volume",
+ "The path of the volume",
+ "",
+ G_PARAM_READWRITE);
+
+ properties[PROP_VOLUME] =
+ g_param_spec_object ("volume",
+ "Volume represented by the row",
+ "The volume represented by the row",
+ G_TYPE_VOLUME,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ properties[PROP_MOUNT] =
+ g_param_spec_object ("mount",
+ "Mount represented by the row",
+ "The mount point represented by the row, if any",
+ G_TYPE_MOUNT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ properties[PROP_FILE] =
+ g_param_spec_object ("file",
+ "File represented by the row",
+ "The file represented by the row, if any",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ properties[PROP_IS_NETWORK] =
+ g_param_spec_boolean ("is-network",
+ "Whether the row represents a network location",
+ "Whether the row represents a network location",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (object_class, LAST_PROP, properties);
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/gtk/ui/nautilusgtkplacesviewrow.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, available_space_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, busy_spinner);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, eject_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, eject_icon);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, event_box);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, icon_image);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, name_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusGtkPlacesViewRow, path_label);
}
static void
nautilus_gtk_places_view_row_init (NautilusGtkPlacesViewRow *self)
{
- gtk_widget_init_template (GTK_WIDGET (self));
+ gtk_widget_init_template (GTK_WIDGET (self));
}
-GtkWidget*
+GtkWidget *
nautilus_gtk_places_view_row_new (GVolume *volume,
- GMount *mount)
+ GMount *mount)
{
- return g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
- "volume", volume,
- "mount", mount,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_GTK_PLACES_VIEW_ROW,
+ "volume", volume,
+ "mount", mount,
+ NULL);
}
-GMount*
+GMount *
nautilus_gtk_places_view_row_get_mount (NautilusGtkPlacesViewRow *row)
{
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
- return row->mount;
+ return row->mount;
}
-GVolume*
+GVolume *
nautilus_gtk_places_view_row_get_volume (NautilusGtkPlacesViewRow *row)
{
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
- return row->volume;
+ return row->volume;
}
-GFile*
+GFile *
nautilus_gtk_places_view_row_get_file (NautilusGtkPlacesViewRow *row)
{
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
- return row->file;
+ return row->file;
}
-GtkWidget*
+GtkWidget *
nautilus_gtk_places_view_row_get_eject_button (NautilusGtkPlacesViewRow *row)
{
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
- return GTK_WIDGET (row->eject_button);
+ return GTK_WIDGET (row->eject_button);
}
-GtkWidget*
+GtkWidget *
nautilus_gtk_places_view_row_get_event_box (NautilusGtkPlacesViewRow *row)
{
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), NULL);
- return GTK_WIDGET (row->event_box);
+ return GTK_WIDGET (row->event_box);
}
void
nautilus_gtk_places_view_row_set_busy (NautilusGtkPlacesViewRow *row,
- gboolean is_busy)
+ gboolean is_busy)
{
- g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row));
+ g_return_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row));
- gtk_widget_set_visible (GTK_WIDGET (row->busy_spinner), is_busy);
+ gtk_widget_set_visible (GTK_WIDGET (row->busy_spinner), is_busy);
}
gboolean
nautilus_gtk_places_view_row_get_is_network (NautilusGtkPlacesViewRow *row)
{
- g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_GTK_PLACES_VIEW_ROW (row), FALSE);
- return row->is_network;
+ return row->is_network;
}
void
nautilus_gtk_places_view_row_set_is_network (NautilusGtkPlacesViewRow *row,
- gboolean is_network)
+ gboolean is_network)
{
- if (row->is_network != is_network)
+ if (row->is_network != is_network)
{
- row->is_network = is_network;
+ row->is_network = is_network;
- gtk_image_set_from_icon_name (row->eject_icon, "media-eject-symbolic", GTK_ICON_SIZE_BUTTON);
- gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? _("Disconnect") : _("Unmount"));
+ gtk_image_set_from_icon_name (row->eject_icon, "media-eject-symbolic", GTK_ICON_SIZE_BUTTON);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? _("Disconnect") : _("Unmount"));
}
}
void
nautilus_gtk_places_view_row_set_path_size_group (NautilusGtkPlacesViewRow *row,
- GtkSizeGroup *group)
+ GtkSizeGroup *group)
{
- if (group)
- gtk_size_group_add_widget (group, GTK_WIDGET (row->path_label));
+ if (group)
+ {
+ gtk_size_group_add_widget (group, GTK_WIDGET (row->path_label));
+ }
}
void
nautilus_gtk_places_view_row_set_space_size_group (NautilusGtkPlacesViewRow *row,
- GtkSizeGroup *group)
+ GtkSizeGroup *group)
{
- if (group)
- gtk_size_group_add_widget (group, GTK_WIDGET (row->available_space_label));
+ if (group)
+ {
+ gtk_size_group_add_widget (group, GTK_WIDGET (row->available_space_label));
+ }
}
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 675cfd3d7..be928462e 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -65,267 +65,289 @@
#include <gdk/gdkx.h>
#include <gtk/gtk.h>
-typedef struct {
- NautilusProgressPersistenceHandler *progress_handler;
- NautilusDBusManager *dbus_manager;
- NautilusFreedesktopDBus *fdb_manager;
+typedef struct
+{
+ NautilusProgressPersistenceHandler *progress_handler;
+ NautilusDBusManager *dbus_manager;
+ NautilusFreedesktopDBus *fdb_manager;
- NautilusBookmarkList *bookmark_list;
+ NautilusBookmarkList *bookmark_list;
- NautilusShellSearchProvider *search_provider;
+ NautilusShellSearchProvider *search_provider;
- GList *windows;
+ GList *windows;
- GHashTable *notifications;
+ GHashTable *notifications;
- NautilusFileUndoManager *undo_manager;
+ NautilusFileUndoManager *undo_manager;
} NautilusApplicationPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (NautilusApplication, nautilus_application, GTK_TYPE_APPLICATION);
void
nautilus_application_set_accelerator (GApplication *app,
- const gchar *action_name,
- const gchar *accel)
+ const gchar *action_name,
+ const gchar *accel)
{
- const gchar *vaccels[] = {
- accel,
- NULL
- };
+ const gchar *vaccels[] =
+ {
+ accel,
+ NULL
+ };
- gtk_application_set_accels_for_action (GTK_APPLICATION (app), action_name, vaccels);
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app), action_name, vaccels);
}
void
-nautilus_application_set_accelerators (GApplication *app,
- const gchar *action_name,
- const gchar **accels)
+nautilus_application_set_accelerators (GApplication *app,
+ const gchar *action_name,
+ const gchar **accels)
{
- gtk_application_set_accels_for_action (GTK_APPLICATION (app), action_name, accels);
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app), action_name, accels);
}
GList *
nautilus_application_get_windows (NautilusApplication *self)
{
- NautilusApplicationPrivate *priv;
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
+ priv = nautilus_application_get_instance_private (self);
- return priv->windows;
+ return priv->windows;
}
NautilusBookmarkList *
nautilus_application_get_bookmarks (NautilusApplication *self)
{
- NautilusApplicationPrivate *priv;
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
+ priv = nautilus_application_get_instance_private (self);
- if (!priv->bookmark_list) {
- priv->bookmark_list = nautilus_bookmark_list_new ();
- }
+ if (!priv->bookmark_list)
+ {
+ priv->bookmark_list = nautilus_bookmark_list_new ();
+ }
- return priv->bookmark_list;
+ return priv->bookmark_list;
}
static gboolean
check_required_directories (NautilusApplication *self)
{
- char *user_directory;
- GSList *directories;
- gboolean ret;
+ char *user_directory;
+ GSList *directories;
+ gboolean ret;
- g_assert (NAUTILUS_IS_APPLICATION (self));
+ g_assert (NAUTILUS_IS_APPLICATION (self));
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- ret = TRUE;
+ ret = TRUE;
- user_directory = nautilus_get_user_directory ();
+ user_directory = nautilus_get_user_directory ();
- directories = NULL;
+ directories = NULL;
- if (!g_file_test (user_directory, G_FILE_TEST_IS_DIR)) {
- directories = g_slist_prepend (directories, user_directory);
- }
+ if (!g_file_test (user_directory, G_FILE_TEST_IS_DIR))
+ {
+ directories = g_slist_prepend (directories, user_directory);
+ }
- if (directories != NULL) {
- int failed_count;
- GString *directories_as_string;
- GSList *l;
- char *error_string;
- const char *detail_string;
- GtkDialog *dialog;
+ if (directories != NULL)
+ {
+ int failed_count;
+ GString *directories_as_string;
+ GSList *l;
+ char *error_string;
+ const char *detail_string;
+ GtkDialog *dialog;
- ret = FALSE;
+ ret = FALSE;
- failed_count = g_slist_length (directories);
+ failed_count = g_slist_length (directories);
- directories_as_string = g_string_new ((const char *)directories->data);
- for (l = directories->next; l != NULL; l = l->next) {
- g_string_append_printf (directories_as_string, ", %s", (const char *)l->data);
- }
+ directories_as_string = g_string_new ((const char *) directories->data);
+ for (l = directories->next; l != NULL; l = l->next)
+ {
+ g_string_append_printf (directories_as_string, ", %s", (const char *) l->data);
+ }
- error_string = _("Oops! Something went wrong.");
- if (failed_count == 1) {
- detail_string = g_strdup_printf (_("Unable to create a required folder. "
- "Please create the following folder, or "
- "set permissions such that it can be created:\n%s"),
- directories_as_string->str);
- } else {
- detail_string = g_strdup_printf (_("Unable to create required folders. "
- "Please create the following folders, or "
- "set permissions such that they can be created:\n%s"),
- directories_as_string->str);
- }
+ error_string = _("Oops! Something went wrong.");
+ if (failed_count == 1)
+ {
+ detail_string = g_strdup_printf (_("Unable to create a required folder. "
+ "Please create the following folder, or "
+ "set permissions such that it can be created:\n%s"),
+ directories_as_string->str);
+ }
+ else
+ {
+ detail_string = g_strdup_printf (_("Unable to create required folders. "
+ "Please create the following folders, or "
+ "set permissions such that they can be created:\n%s"),
+ directories_as_string->str);
+ }
- dialog = eel_show_error_dialog (error_string, detail_string, NULL);
- /* We need the main event loop so the user has a chance to see the dialog. */
- gtk_application_add_window (GTK_APPLICATION (self),
- GTK_WINDOW (dialog));
+ dialog = eel_show_error_dialog (error_string, detail_string, NULL);
+ /* We need the main event loop so the user has a chance to see the dialog. */
+ gtk_application_add_window (GTK_APPLICATION (self),
+ GTK_WINDOW (dialog));
- g_string_free (directories_as_string, TRUE);
- }
+ g_string_free (directories_as_string, TRUE);
+ }
- g_slist_free (directories);
- g_free (user_directory);
- nautilus_profile_end (NULL);
+ g_slist_free (directories);
+ g_free (user_directory);
+ nautilus_profile_end (NULL);
- return ret;
+ return ret;
}
static void
-menu_provider_items_updated_handler (NautilusMenuProvider *provider, GtkWidget* parent_window, gpointer data)
+menu_provider_items_updated_handler (NautilusMenuProvider *provider,
+ GtkWidget *parent_window,
+ gpointer data)
{
-
- g_signal_emit_by_name (nautilus_signaller_get_current (),
- "popup-menu-changed");
+ g_signal_emit_by_name (nautilus_signaller_get_current (),
+ "popup-menu-changed");
}
static void
menu_provider_init_callback (void)
{
- GList *providers;
- GList *l;
+ GList *providers;
+ GList *l;
- providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
+ providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
- for (l = providers; l != NULL; l = l->next) {
- NautilusMenuProvider *provider = NAUTILUS_MENU_PROVIDER (l->data);
+ for (l = providers; l != NULL; l = l->next)
+ {
+ NautilusMenuProvider *provider = NAUTILUS_MENU_PROVIDER (l->data);
- g_signal_connect_after (G_OBJECT (provider), "items-updated",
- (GCallback)menu_provider_items_updated_handler,
- NULL);
- }
+ g_signal_connect_after (G_OBJECT (provider), "items-updated",
+ (GCallback) menu_provider_items_updated_handler,
+ NULL);
+ }
- nautilus_module_extension_list_free (providers);
+ nautilus_module_extension_list_free (providers);
}
NautilusWindow *
nautilus_application_create_window (NautilusApplication *self,
- GdkScreen *screen)
+ GdkScreen *screen)
{
- NautilusApplicationPrivate *priv;
- NautilusWindow *window;
- char *geometry_string;
- gboolean maximized;
- gint n_windows;
-
- g_return_val_if_fail (NAUTILUS_IS_APPLICATION (self), NULL);
- nautilus_profile_start (NULL);
-
- priv = nautilus_application_get_instance_private (self);
- n_windows = g_list_length (priv->windows);
- window = nautilus_window_new (screen);
-
- maximized = g_settings_get_boolean
- (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED);
- if (maximized) {
- gtk_window_maximize (GTK_WINDOW (window));
- } else {
- gtk_window_unmaximize (GTK_WINDOW (window));
- }
-
- geometry_string = g_settings_get_string
- (nautilus_window_state, NAUTILUS_WINDOW_STATE_GEOMETRY);
- if (geometry_string != NULL &&
- geometry_string[0] != 0) {
- /* Ignore saved window position if another window is already showing.
- * That way the two windows wont appear at the exact same
- * location on the screen.
- */
- eel_gtk_window_set_initial_geometry_from_string
- (GTK_WINDOW (window),
- geometry_string,
- NAUTILUS_WINDOW_MIN_WIDTH,
- NAUTILUS_WINDOW_MIN_HEIGHT,
- n_windows > 0);
- }
- g_free (geometry_string);
-
- DEBUG ("Creating a new navigation window");
- nautilus_profile_end (NULL);
-
- return window;
+ NautilusApplicationPrivate *priv;
+ NautilusWindow *window;
+ char *geometry_string;
+ gboolean maximized;
+ gint n_windows;
+
+ g_return_val_if_fail (NAUTILUS_IS_APPLICATION (self), NULL);
+ nautilus_profile_start (NULL);
+
+ priv = nautilus_application_get_instance_private (self);
+ n_windows = g_list_length (priv->windows);
+ window = nautilus_window_new (screen);
+
+ maximized = g_settings_get_boolean
+ (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED);
+ if (maximized)
+ {
+ gtk_window_maximize (GTK_WINDOW (window));
+ }
+ else
+ {
+ gtk_window_unmaximize (GTK_WINDOW (window));
+ }
+
+ geometry_string = g_settings_get_string
+ (nautilus_window_state, NAUTILUS_WINDOW_STATE_GEOMETRY);
+ if (geometry_string != NULL &&
+ geometry_string[0] != 0)
+ {
+ /* Ignore saved window position if another window is already showing.
+ * That way the two windows wont appear at the exact same
+ * location on the screen.
+ */
+ eel_gtk_window_set_initial_geometry_from_string
+ (GTK_WINDOW (window),
+ geometry_string,
+ NAUTILUS_WINDOW_MIN_WIDTH,
+ NAUTILUS_WINDOW_MIN_HEIGHT,
+ n_windows > 0);
+ }
+ g_free (geometry_string);
+
+ DEBUG ("Creating a new navigation window");
+ nautilus_profile_end (NULL);
+
+ return window;
}
static NautilusWindowSlot *
get_window_slot_for_location (NautilusApplication *self,
GFile *location)
{
- NautilusApplicationPrivate *priv;
- NautilusWindowSlot *slot;
- NautilusWindow *window;
- NautilusFile *file;
- GList *l, *sl;
-
- priv = nautilus_application_get_instance_private (self);
- slot = NULL;
- file = nautilus_file_get (location);
-
- if (!nautilus_file_is_directory (file) && !nautilus_file_is_other_locations (file) &&
- g_file_has_parent (location, NULL)) {
- location = g_file_get_parent (location);
- } else {
- g_object_ref (location);
- }
-
- for (l = priv->windows; l != NULL; l = l->next) {
- window = l->data;
-
- for (sl = nautilus_window_get_slots (window); sl; sl = sl->next) {
- NautilusWindowSlot *current = sl->data;
- GFile *slot_location = nautilus_window_slot_get_location (current);
-
- if (slot_location && g_file_equal (slot_location, location)) {
- slot = current;
- break;
- }
- }
-
- if (slot) {
- break;
- }
- }
-
- nautilus_file_unref (file);
- g_object_unref (location);
-
- return slot;
+ NautilusApplicationPrivate *priv;
+ NautilusWindowSlot *slot;
+ NautilusWindow *window;
+ NautilusFile *file;
+ GList *l, *sl;
+
+ priv = nautilus_application_get_instance_private (self);
+ slot = NULL;
+ file = nautilus_file_get (location);
+
+ if (!nautilus_file_is_directory (file) && !nautilus_file_is_other_locations (file) &&
+ g_file_has_parent (location, NULL))
+ {
+ location = g_file_get_parent (location);
+ }
+ else
+ {
+ g_object_ref (location);
+ }
+
+ for (l = priv->windows; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ for (sl = nautilus_window_get_slots (window); sl; sl = sl->next)
+ {
+ NautilusWindowSlot *current = sl->data;
+ GFile *slot_location = nautilus_window_slot_get_location (current);
+
+ if (slot_location && g_file_equal (slot_location, location))
+ {
+ slot = current;
+ break;
+ }
+ }
+
+ if (slot)
+ {
+ break;
+ }
+ }
+
+ nautilus_file_unref (file);
+ g_object_unref (location);
+
+ return slot;
}
static void
new_window_show_callback (GtkWidget *widget,
gpointer user_data)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = NAUTILUS_WINDOW (user_data);
- nautilus_window_close (window);
+ window = NAUTILUS_WINDOW (user_data);
+ nautilus_window_close (window);
- g_signal_handlers_disconnect_by_func (widget,
- G_CALLBACK (new_window_show_callback),
- user_data);
+ g_signal_handlers_disconnect_by_func (widget,
+ G_CALLBACK (new_window_show_callback),
+ user_data);
}
void
@@ -336,12 +358,12 @@ nautilus_application_open_location_full (NautilusApplication *self,
NautilusWindow *target_window,
NautilusWindowSlot *target_slot)
{
- NAUTILUS_APPLICATION_CLASS (G_OBJECT_GET_CLASS (self))->open_location_full (self,
- location,
- flags,
- selection,
- target_window,
- target_slot);
+ NAUTILUS_APPLICATION_CLASS (G_OBJECT_GET_CLASS (self))->open_location_full (self,
+ location,
+ flags,
+ selection,
+ target_window,
+ target_slot);
}
static void
@@ -352,116 +374,138 @@ real_open_location_full (NautilusApplication *self,
NautilusWindow *target_window,
NautilusWindowSlot *target_slot)
{
- NautilusWindowSlot *active_slot = NULL;
- NautilusWindow *active_window;
- GFile *old_location = NULL;
- char *old_uri, *new_uri;
- gboolean use_same;
-
- use_same = TRUE;
- /* FIXME: We are having problems on getting the current focused window with
- * gtk_application_get_active_window, see https://bugzilla.gnome.org/show_bug.cgi?id=756499
- * so what we do is never rely on this on the callers, but would be cool to
- * make it work withouth explicitly setting the active window on the callers. */
- active_window = NAUTILUS_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (self)));
- /* There is no active window if the application is run with
- * --gapplication-service
- */
- if (active_window) {
- active_slot = nautilus_window_get_active_slot (active_window);
- /* Just for debug.*/
- old_location = nautilus_window_slot_get_location (active_slot);
- }
+ NautilusWindowSlot *active_slot = NULL;
+ NautilusWindow *active_window;
+ GFile *old_location = NULL;
+ char *old_uri, *new_uri;
+ gboolean use_same;
+
+ use_same = TRUE;
+ /* FIXME: We are having problems on getting the current focused window with
+ * gtk_application_get_active_window, see https://bugzilla.gnome.org/show_bug.cgi?id=756499
+ * so what we do is never rely on this on the callers, but would be cool to
+ * make it work withouth explicitly setting the active window on the callers. */
+ active_window = NAUTILUS_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (self)));
+ /* There is no active window if the application is run with
+ * --gapplication-service
+ */
+ if (active_window)
+ {
+ active_slot = nautilus_window_get_active_slot (active_window);
+ /* Just for debug.*/
+ old_location = nautilus_window_slot_get_location (active_slot);
+ }
- /* this happens at startup */
- if (old_location == NULL)
- old_uri = g_strdup ("(none)");
- else
- old_uri = g_file_get_uri (old_location);
+ /* this happens at startup */
+ if (old_location == NULL)
+ {
+ old_uri = g_strdup ("(none)");
+ }
+ else
+ {
+ old_uri = g_file_get_uri (old_location);
+ }
+
+ new_uri = g_file_get_uri (location);
+
+ DEBUG ("Application opening location, old: %s, new: %s", old_uri, new_uri);
+ nautilus_profile_start ("Application opening location, old: %s, new: %s", old_uri, new_uri);
+
+ g_free (old_uri);
+ g_free (new_uri);
+ /* end debug */
- new_uri = g_file_get_uri (location);
+ /* In case a target slot is provided, we can use it's associated window.
+ * In case a target window were given as well, we give preference to the
+ * slot we target at */
+ if (target_slot != NULL)
+ {
+ target_window = nautilus_window_slot_get_window (target_slot);
+ }
- DEBUG ("Application opening location, old: %s, new: %s", old_uri, new_uri);
- nautilus_profile_start ("Application opening location, old: %s, new: %s", old_uri, new_uri);
+ g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 &&
+ (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
- g_free (old_uri);
- g_free (new_uri);
- /* end debug */
+ /* and if the flags specify so, this is overridden */
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0)
+ {
+ use_same = FALSE;
+ }
- /* In case a target slot is provided, we can use it's associated window.
- * In case a target window were given as well, we give preference to the
- * slot we target at */
- if (target_slot != NULL)
+ /* now get/create the window */
+ if (use_same)
+ {
+ if (!target_window)
+ {
+ if (!target_slot)
+ {
+ target_window = active_window;
+ }
+ else
+ {
target_window = nautilus_window_slot_get_window (target_slot);
+ }
+ }
+ }
+ else
+ {
+ target_window = nautilus_application_create_window (self,
+ gtk_window_get_screen (GTK_WINDOW (active_window)));
+ /* Whatever the caller says, the slot won't be the same */
+ target_slot = NULL;
+ }
- g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 &&
- (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
-
- /* and if the flags specify so, this is overridden */
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0) {
- use_same = FALSE;
- }
-
- /* now get/create the window */
- if (use_same) {
- if (!target_window) {
- if (!target_slot) {
- target_window = active_window;
- } else {
- target_window = nautilus_window_slot_get_window (target_slot);
- }
- }
- } else {
- target_window = nautilus_application_create_window (self,
- gtk_window_get_screen (GTK_WINDOW (active_window)));
- /* Whatever the caller says, the slot won't be the same */
- target_slot = NULL;
- }
-
- g_assert (target_window != NULL);
-
- /* close the current window if the flags say so */
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
- if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
- nautilus_window_close (active_window);
- } else {
- g_signal_connect_object (target_window,
- "show",
- G_CALLBACK (new_window_show_callback),
- active_window,
- G_CONNECT_AFTER);
- }
- }
-
- /* Application is the one that manages windows, so this flag shouldn't use
- * it anymore by any client */
- flags &= ~NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- nautilus_window_open_location_full (target_window, location, flags, selection, target_slot);
+ g_assert (target_window != NULL);
+
+ /* close the current window if the flags say so */
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0)
+ {
+ if (gtk_widget_get_visible (GTK_WIDGET (target_window)))
+ {
+ nautilus_window_close (active_window);
+ }
+ else
+ {
+ g_signal_connect_object (target_window,
+ "show",
+ G_CALLBACK (new_window_show_callback),
+ active_window,
+ G_CONNECT_AFTER);
+ }
+ }
+
+ /* Application is the one that manages windows, so this flag shouldn't use
+ * it anymore by any client */
+ flags &= ~NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ nautilus_window_open_location_full (target_window, location, flags, selection, target_slot);
}
-static NautilusWindow*
+static NautilusWindow *
open_window (NautilusApplication *self,
GFile *location)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- nautilus_profile_start (NULL);
- window = nautilus_application_create_window (self, gdk_screen_get_default ());
+ nautilus_profile_start (NULL);
+ window = nautilus_application_create_window (self, gdk_screen_get_default ());
- if (location != NULL) {
- nautilus_application_open_location_full (self, location, 0, NULL, window, NULL);
- } else {
- GFile *home;
- home = g_file_new_for_path (g_get_home_dir ());
- nautilus_application_open_location_full (self, home, 0, NULL, window, NULL);
+ if (location != NULL)
+ {
+ nautilus_application_open_location_full (self, location, 0, NULL, window, NULL);
+ }
+ else
+ {
+ GFile *home;
+ home = g_file_new_for_path (g_get_home_dir ());
+ nautilus_application_open_location_full (self, home, 0, NULL, window, NULL);
- g_object_unref (home);
- }
+ g_object_unref (home);
+ }
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
- return window;
+ return window;
}
void
@@ -470,31 +514,36 @@ nautilus_application_open_location (NautilusApplication *self,
GFile *selection,
const char *startup_id)
{
- NautilusWindow *window;
- NautilusWindowSlot *slot;
- GList *sel_list = NULL;
+ NautilusWindow *window;
+ NautilusWindowSlot *slot;
+ GList *sel_list = NULL;
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- if (selection != NULL) {
- sel_list = g_list_prepend (sel_list, nautilus_file_get (selection));
- }
+ if (selection != NULL)
+ {
+ sel_list = g_list_prepend (sel_list, nautilus_file_get (selection));
+ }
- slot = get_window_slot_for_location (self, location);
+ slot = get_window_slot_for_location (self, location);
- if (!slot) {
- window = nautilus_application_create_window (self, gdk_screen_get_default ());
- } else {
- window = nautilus_window_slot_get_window (slot);
- }
+ if (!slot)
+ {
+ window = nautilus_application_create_window (self, gdk_screen_get_default ());
+ }
+ else
+ {
+ window = nautilus_window_slot_get_window (slot);
+ }
- nautilus_application_open_location_full (self, location, 0, sel_list, window, slot);
+ nautilus_application_open_location_full (self, location, 0, sel_list, window, slot);
- if (sel_list != NULL) {
- nautilus_file_list_free (sel_list);
- }
+ if (sel_list != NULL)
+ {
+ nautilus_file_list_free (sel_list);
+ }
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
/* Note: when launched from command line we do not reach this method
@@ -504,139 +553,147 @@ nautilus_application_open_location (NautilusApplication *self,
* instance when gtk_uri_open () is called from outside.
*/
static void
-nautilus_application_open (GApplication *app,
- GFile **files,
- gint n_files,
- const gchar *hint)
+nautilus_application_open (GApplication *app,
+ GFile **files,
+ gint n_files,
+ const gchar *hint)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (app);
- gboolean force_new = (g_strcmp0 (hint, "new-window") == 0);
- NautilusWindowSlot *slot = NULL;
- GFile *file;
- gint idx;
-
- DEBUG ("Open called on the GApplication instance; %d files", n_files);
-
- /* Open windows at each requested location. */
- for (idx = 0; idx < n_files; idx++) {
- file = files[idx];
-
- if (!force_new) {
- slot = get_window_slot_for_location (self, file);
- }
-
- if (!slot) {
- open_window (self, file);
- } else {
- /* We open the location again to update any possible selection */
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (app), file, 0, NULL, NULL, slot);
- }
- }
+ NautilusApplication *self = NAUTILUS_APPLICATION (app);
+ gboolean force_new = (g_strcmp0 (hint, "new-window") == 0);
+ NautilusWindowSlot *slot = NULL;
+ GFile *file;
+ gint idx;
+
+ DEBUG ("Open called on the GApplication instance; %d files", n_files);
+
+ /* Open windows at each requested location. */
+ for (idx = 0; idx < n_files; idx++)
+ {
+ file = files[idx];
+
+ if (!force_new)
+ {
+ slot = get_window_slot_for_location (self, file);
+ }
+
+ if (!slot)
+ {
+ open_window (self, file);
+ }
+ else
+ {
+ /* We open the location again to update any possible selection */
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (app), file, 0, NULL, NULL, slot);
+ }
+ }
}
static void
nautilus_application_finalize (GObject *object)
{
- NautilusApplication *self;
- NautilusApplicationPrivate *priv;
+ NautilusApplication *self;
+ NautilusApplicationPrivate *priv;
- self = NAUTILUS_APPLICATION (object);
- priv = nautilus_application_get_instance_private (self);
+ self = NAUTILUS_APPLICATION (object);
+ priv = nautilus_application_get_instance_private (self);
- g_clear_object (&priv->progress_handler);
- g_clear_object (&priv->bookmark_list);
+ g_clear_object (&priv->progress_handler);
+ g_clear_object (&priv->bookmark_list);
- g_clear_object (&priv->dbus_manager);
- g_clear_object (&priv->fdb_manager);
- g_clear_object (&priv->search_provider);
+ g_clear_object (&priv->dbus_manager);
+ g_clear_object (&priv->fdb_manager);
+ g_clear_object (&priv->search_provider);
- g_list_free (priv->windows);
+ g_list_free (priv->windows);
- g_hash_table_destroy (priv->notifications);
+ g_hash_table_destroy (priv->notifications);
- g_clear_object (&priv->undo_manager);
+ g_clear_object (&priv->undo_manager);
- G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
}
static gboolean
do_cmdline_sanity_checks (NautilusApplication *self,
- GVariantDict *options)
+ GVariantDict *options)
{
- gboolean retval = FALSE;
-
- if (g_variant_dict_contains (options, "check") &&
- (g_variant_dict_contains (options, G_OPTION_REMAINING) ||
- g_variant_dict_contains (options, "quit"))) {
- g_printerr ("%s\n",
- _("--check cannot be used with other options."));
- goto out;
- }
-
- if (g_variant_dict_contains (options, "quit") &&
- g_variant_dict_contains (options, G_OPTION_REMAINING)) {
- g_printerr ("%s\n",
- _("--quit cannot be used with URIs."));
- goto out;
- }
-
-
- if (g_variant_dict_contains (options, "select") &&
- !g_variant_dict_contains (options, G_OPTION_REMAINING)) {
- g_printerr ("%s\n",
- _("--select must be used with at least an URI."));
- goto out;
- }
-
- retval = TRUE;
-
- out:
- return retval;
+ gboolean retval = FALSE;
+
+ if (g_variant_dict_contains (options, "check") &&
+ (g_variant_dict_contains (options, G_OPTION_REMAINING) ||
+ g_variant_dict_contains (options, "quit")))
+ {
+ g_printerr ("%s\n",
+ _("--check cannot be used with other options."));
+ goto out;
+ }
+
+ if (g_variant_dict_contains (options, "quit") &&
+ g_variant_dict_contains (options, G_OPTION_REMAINING))
+ {
+ g_printerr ("%s\n",
+ _("--quit cannot be used with URIs."));
+ goto out;
+ }
+
+
+ if (g_variant_dict_contains (options, "select") &&
+ !g_variant_dict_contains (options, G_OPTION_REMAINING))
+ {
+ g_printerr ("%s\n",
+ _("--select must be used with at least an URI."));
+ goto out;
+ }
+
+ retval = TRUE;
+
+out:
+ return retval;
}
static int
do_perform_self_checks (void)
{
#ifndef NAUTILUS_OMIT_SELF_CHECK
- gtk_init (NULL, NULL);
+ gtk_init (NULL, NULL);
- nautilus_profile_start (NULL);
- /* Run the checks (each twice) for nautilus and libnautilus-private. */
+ nautilus_profile_start (NULL);
+ /* Run the checks (each twice) for nautilus and libnautilus-private. */
- nautilus_run_self_checks ();
- nautilus_run_lib_self_checks ();
- eel_exit_if_self_checks_failed ();
+ nautilus_run_self_checks ();
+ nautilus_run_lib_self_checks ();
+ eel_exit_if_self_checks_failed ();
- nautilus_run_self_checks ();
- nautilus_run_lib_self_checks ();
- eel_exit_if_self_checks_failed ();
- nautilus_profile_end (NULL);
+ nautilus_run_self_checks ();
+ nautilus_run_lib_self_checks ();
+ eel_exit_if_self_checks_failed ();
+ nautilus_profile_end (NULL);
#endif
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
static void
-nautilus_application_select (NautilusApplication *self,
- GFile **files,
- gint len)
+nautilus_application_select (NautilusApplication *self,
+ GFile **files,
+ gint len)
{
- int i;
- GFile *file;
- GFile *parent;
+ int i;
+ GFile *file;
+ GFile *parent;
- for (i = 0; i < len; i++)
+ for (i = 0; i < len; i++)
{
- file = files[i];
- parent = g_file_get_parent (file);
- if (parent != NULL)
+ file = files[i];
+ parent = g_file_get_parent (file);
+ if (parent != NULL)
{
- nautilus_application_open_location (self, parent, file, NULL);
- g_object_unref (parent);
+ nautilus_application_open_location (self, parent, file, NULL);
+ g_object_unref (parent);
}
- else
+ else
{
- nautilus_application_open_location (self, file, NULL, NULL);
+ nautilus_application_open_location (self, file, NULL, NULL);
}
}
}
@@ -646,14 +703,14 @@ action_new_window (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- GtkApplication *application = user_data;
- GFile *home;
+ GtkApplication *application = user_data;
+ GFile *home;
- home = g_file_new_for_path (g_get_home_dir ());
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (application), home,
- NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW, NULL, NULL, NULL);
+ home = g_file_new_for_path (g_get_home_dir ());
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (application), home,
+ NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW, NULL, NULL, NULL);
- g_object_unref (home);
+ g_object_unref (home);
}
static void
@@ -661,8 +718,8 @@ action_preferences (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- GtkApplication *application = user_data;
- nautilus_preferences_window_show (gtk_application_get_active_window (application));
+ GtkApplication *application = user_data;
+ nautilus_preferences_window_show (gtk_application_get_active_window (application));
}
static void
@@ -670,9 +727,9 @@ action_about (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- GtkApplication *application = user_data;
+ GtkApplication *application = user_data;
- nautilus_window_show_about_dialog (NAUTILUS_WINDOW (gtk_application_get_active_window (application)));
+ nautilus_window_show_about_dialog (NAUTILUS_WINDOW (gtk_application_get_active_window (application)));
}
static void
@@ -680,33 +737,34 @@ action_help (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- GtkWindow *window;
- GtkWidget *dialog;
- GtkApplication *application = user_data;
- GError *error = NULL;
-
- window = gtk_application_get_active_window (application);
- gtk_show_uri (window ?
- gtk_window_get_screen (GTK_WINDOW (window)) :
- gdk_screen_get_default (),
- "help:gnome-help/files",
- gtk_get_current_event_time (), &error);
-
- if (error) {
- dialog = gtk_message_dialog_new (window ? GTK_WINDOW (window) : NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("There was an error displaying help: \n%s"),
- error->message);
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
-
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
- gtk_widget_show (dialog);
- g_error_free (error);
- }
+ GtkWindow *window;
+ GtkWidget *dialog;
+ GtkApplication *application = user_data;
+ GError *error = NULL;
+
+ window = gtk_application_get_active_window (application);
+ gtk_show_uri (window ?
+ gtk_window_get_screen (GTK_WINDOW (window)) :
+ gdk_screen_get_default (),
+ "help:gnome-help/files",
+ gtk_get_current_event_time (), &error);
+
+ if (error)
+ {
+ dialog = gtk_message_dialog_new (window ? GTK_WINDOW (window) : NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("There was an error displaying help: \n%s"),
+ error->message);
+ g_signal_connect (G_OBJECT (dialog), "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_widget_show (dialog);
+ g_error_free (error);
+ }
}
static void
@@ -714,10 +772,10 @@ action_kill (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- GtkApplication *application = user_data;
+ GtkApplication *application = user_data;
- /* we have been asked to force quit */
- g_application_quit (G_APPLICATION (application));
+ /* we have been asked to force quit */
+ g_application_quit (G_APPLICATION (application));
}
static void
@@ -725,18 +783,19 @@ action_quit (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (user_data);
- GList *windows, *l;
-
- windows = nautilus_application_get_windows (self);
- /* make a copy, since the original list will be modified when destroying
- * a window, making this list invalid */
- windows = g_list_copy (windows);
- for (l = windows; l != NULL; l = l->next) {
- nautilus_window_close (l->data);
- }
+ NautilusApplication *self = NAUTILUS_APPLICATION (user_data);
+ GList *windows, *l;
+
+ windows = nautilus_application_get_windows (self);
+ /* make a copy, since the original list will be modified when destroying
+ * a window, making this list invalid */
+ windows = g_list_copy (windows);
+ for (l = windows; l != NULL; l = l->next)
+ {
+ nautilus_window_close (l->data);
+ }
- g_list_free (windows);
+ g_list_free (windows);
}
static void
@@ -744,305 +803,329 @@ action_show_hide_sidebar (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- GList *window, *windows;
+ GList *window, *windows;
- windows = gtk_application_get_windows (GTK_APPLICATION (user_data));
+ windows = gtk_application_get_windows (GTK_APPLICATION (user_data));
- for (window = windows; window != NULL; window = window->next) {
- if (g_variant_get_boolean (state)) {
- nautilus_window_show_sidebar (window->data);
- } else {
- nautilus_window_hide_sidebar (window->data);
- }
+ for (window = windows; window != NULL; window = window->next)
+ {
+ if (g_variant_get_boolean (state))
+ {
+ nautilus_window_show_sidebar (window->data);
}
+ else
+ {
+ nautilus_window_hide_sidebar (window->data);
+ }
+ }
- g_simple_action_set_state (action, state);
+ g_simple_action_set_state (action, state);
}
static void
action_show_help_overlay (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- GtkApplication *application = user_data;
- GtkWindow *window = gtk_application_get_active_window (application);
+ GtkApplication *application = user_data;
+ GtkWindow *window = gtk_application_get_active_window (application);
- g_action_group_activate_action (G_ACTION_GROUP (window), "show-help-overlay", NULL);
+ g_action_group_activate_action (G_ACTION_GROUP (window), "show-help-overlay", NULL);
}
-static GActionEntry app_entries[] = {
- { "new-window", action_new_window, NULL, NULL, NULL },
- { "preferences", action_preferences, NULL, NULL, NULL },
- { "show-hide-sidebar", NULL, NULL, "true", action_show_hide_sidebar },
- { "about", action_about, NULL, NULL, NULL },
- { "help", action_help, NULL, NULL, NULL },
- { "quit", action_quit, NULL, NULL, NULL },
- { "kill", action_kill, NULL, NULL, NULL },
- { "show-help-overlay", action_show_help_overlay, NULL, NULL, NULL },
+static GActionEntry app_entries[] =
+{
+ { "new-window", action_new_window, NULL, NULL, NULL },
+ { "preferences", action_preferences, NULL, NULL, NULL },
+ { "show-hide-sidebar", NULL, NULL, "true", action_show_hide_sidebar },
+ { "about", action_about, NULL, NULL, NULL },
+ { "help", action_help, NULL, NULL, NULL },
+ { "quit", action_quit, NULL, NULL, NULL },
+ { "kill", action_kill, NULL, NULL, NULL },
+ { "show-help-overlay", action_show_help_overlay, NULL, NULL, NULL },
};
static void
nautilus_init_application_actions (NautilusApplication *app)
{
- gboolean show_sidebar;
- const gchar *debug_no_app_menu;
-
- g_action_map_add_action_entries (G_ACTION_MAP (app),
- app_entries, G_N_ELEMENTS (app_entries),
- app);
-
- debug_no_app_menu = g_getenv ("NAUTILUS_DEBUG_NO_APP_MENU");
- if (debug_no_app_menu) {
- DEBUG ("Disabling app menu GtkSetting as requested...");
- g_object_set (gtk_settings_get_default (),
- "gtk-shell-shows-app-menu", FALSE,
- NULL);
- }
+ gboolean show_sidebar;
+ const gchar *debug_no_app_menu;
+
+ g_action_map_add_action_entries (G_ACTION_MAP (app),
+ app_entries, G_N_ELEMENTS (app_entries),
+ app);
+
+ debug_no_app_menu = g_getenv ("NAUTILUS_DEBUG_NO_APP_MENU");
+ if (debug_no_app_menu)
+ {
+ DEBUG ("Disabling app menu GtkSetting as requested...");
+ g_object_set (gtk_settings_get_default (),
+ "gtk-shell-shows-app-menu", FALSE,
+ NULL);
+ }
- show_sidebar = g_settings_get_boolean (nautilus_window_state,
- NAUTILUS_WINDOW_STATE_START_WITH_SIDEBAR);
+ show_sidebar = g_settings_get_boolean (nautilus_window_state,
+ NAUTILUS_WINDOW_STATE_START_WITH_SIDEBAR);
- g_action_group_change_action_state (G_ACTION_GROUP (app),
- "show-hide-sidebar",
- g_variant_new_boolean (show_sidebar));
+ g_action_group_change_action_state (G_ACTION_GROUP (app),
+ "show-hide-sidebar",
+ g_variant_new_boolean (show_sidebar));
- nautilus_application_set_accelerator (G_APPLICATION (app), "app.show-hide-sidebar", "F9");
+ nautilus_application_set_accelerator (G_APPLICATION (app), "app.show-hide-sidebar", "F9");
}
-const GOptionEntry options[] = {
+const GOptionEntry options[] =
+{
#ifndef NAUTILUS_OMIT_SELF_CHECK
- { "check", 'c', 0, G_OPTION_ARG_NONE, NULL,
- N_("Perform a quick set of self-check tests."), NULL },
+ { "check", 'c', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Perform a quick set of self-check tests."), NULL },
#endif
- /* dummy, only for compatibility reasons */
- { "browser", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, NULL,
- NULL, NULL },
- /* ditto */
- { "geometry", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, NULL,
- N_("Create the initial window with the given geometry."), N_("GEOMETRY") },
- { "version", '\0', 0, G_OPTION_ARG_NONE, NULL,
- N_("Show the version of the program."), NULL },
- { "new-window", 'w', 0, G_OPTION_ARG_NONE, NULL,
- N_("Always open a new window for browsing specified URIs"), NULL },
- { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL,
- N_("Only create windows for explicitly specified URIs."), NULL },
- { "quit", 'q', 0, G_OPTION_ARG_NONE, NULL,
- N_("Quit Nautilus."), NULL },
- { "select", 's', 0, G_OPTION_ARG_NONE, NULL,
- N_("Select specified URI in parent folder."), NULL },
- { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, N_("[URI...]") },
-
- { NULL }
+ /* dummy, only for compatibility reasons */
+ { "browser", '\0', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, NULL,
+ NULL, NULL },
+ /* ditto */
+ { "geometry", 'g', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, NULL,
+ N_("Create the initial window with the given geometry."), N_("GEOMETRY") },
+ { "version", '\0', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Show the version of the program."), NULL },
+ { "new-window", 'w', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Always open a new window for browsing specified URIs"), NULL },
+ { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Only create windows for explicitly specified URIs."), NULL },
+ { "quit", 'q', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Quit Nautilus."), NULL },
+ { "select", 's', 0, G_OPTION_ARG_NONE, NULL,
+ N_("Select specified URI in parent folder."), NULL },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, NULL, NULL, N_("[URI...]") },
+
+ { NULL }
};
static void
nautilus_application_activate (GApplication *app)
{
- GFile **files;
+ GFile **files;
- DEBUG ("Calling activate");
+ DEBUG ("Calling activate");
- files = g_malloc0 (2 * sizeof (GFile *));
- files[0] = g_file_new_for_path (g_get_home_dir ());
- nautilus_application_open (app, files, 1, NULL);
+ files = g_malloc0 (2 * sizeof (GFile *));
+ files[0] = g_file_new_for_path (g_get_home_dir ());
+ nautilus_application_open (app, files, 1, NULL);
- g_object_unref (files[0]);
- g_free (files);
+ g_object_unref (files[0]);
+ g_free (files);
}
static gint
nautilus_application_handle_file_args (NautilusApplication *self,
- GVariantDict *options)
+ GVariantDict *options)
{
- GFile **files;
- GFile *file;
- gint idx, len;
- const gchar * const *remaining = NULL;
- GPtrArray *file_array;
-
- g_variant_dict_lookup (options, G_OPTION_REMAINING, "^a&s", &remaining);
-
- /* Convert args to GFiles */
- file_array = g_ptr_array_new_full (0, g_object_unref);
-
- if (remaining) {
- for (idx = 0; remaining[idx] != NULL; idx++) {
- gchar *cwd;
-
- g_variant_dict_lookup (options, "cwd", "s", &cwd);
- if (cwd == NULL) {
- file = g_file_new_for_commandline_arg (remaining[idx]);
- } else {
- file = g_file_new_for_commandline_arg_and_cwd (remaining[idx], cwd);
- g_free (cwd);
- }
- g_ptr_array_add (file_array, file);
- }
- } else if (g_variant_dict_contains (options, "new-window")) {
- file = g_file_new_for_path (g_get_home_dir ());
- g_ptr_array_add (file_array, file);
- } else {
- g_ptr_array_unref (file_array);
+ GFile **files;
+ GFile *file;
+ gint idx, len;
+ const gchar * const *remaining = NULL;
+ GPtrArray *file_array;
- /* No command line options or files, just activate the application */
- nautilus_application_activate (G_APPLICATION (self));
- return EXIT_SUCCESS;
- }
+ g_variant_dict_lookup (options, G_OPTION_REMAINING, "^a&s", &remaining);
- len = file_array->len;
- files = (GFile **) file_array->pdata;
+ /* Convert args to GFiles */
+ file_array = g_ptr_array_new_full (0, g_object_unref);
- if (g_variant_dict_contains (options, "select")) {
- nautilus_application_select (self, files, len);
- } else {
- /* Create new windows */
- nautilus_application_open (G_APPLICATION (self), files, len,
- g_variant_dict_contains (options, "new-window") ? "new-window" : "");
- }
+ if (remaining)
+ {
+ for (idx = 0; remaining[idx] != NULL; idx++)
+ {
+ gchar *cwd;
+ g_variant_dict_lookup (options, "cwd", "s", &cwd);
+ if (cwd == NULL)
+ {
+ file = g_file_new_for_commandline_arg (remaining[idx]);
+ }
+ else
+ {
+ file = g_file_new_for_commandline_arg_and_cwd (remaining[idx], cwd);
+ g_free (cwd);
+ }
+ g_ptr_array_add (file_array, file);
+ }
+ }
+ else if (g_variant_dict_contains (options, "new-window"))
+ {
+ file = g_file_new_for_path (g_get_home_dir ());
+ g_ptr_array_add (file_array, file);
+ }
+ else
+ {
g_ptr_array_unref (file_array);
+ /* No command line options or files, just activate the application */
+ nautilus_application_activate (G_APPLICATION (self));
return EXIT_SUCCESS;
+ }
+
+ len = file_array->len;
+ files = (GFile **) file_array->pdata;
+
+ if (g_variant_dict_contains (options, "select"))
+ {
+ nautilus_application_select (self, files, len);
+ }
+ else
+ {
+ /* Create new windows */
+ nautilus_application_open (G_APPLICATION (self), files, len,
+ g_variant_dict_contains (options, "new-window") ? "new-window" : "");
+ }
+
+ g_ptr_array_unref (file_array);
+
+ return EXIT_SUCCESS;
}
static gint
nautilus_application_command_line (GApplication *application,
GApplicationCommandLine *command_line)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (application);
- gint retval = -1;
- GVariantDict *options;
+ NautilusApplication *self = NAUTILUS_APPLICATION (application);
+ gint retval = -1;
+ GVariantDict *options;
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- options = g_application_command_line_get_options_dict (command_line);
+ options = g_application_command_line_get_options_dict (command_line);
- if (g_variant_dict_contains (options, "version")) {
- g_application_command_line_print (command_line,
- "GNOME nautilus " PACKAGE_VERSION "\n");
- retval = EXIT_SUCCESS;
- goto out;
- }
+ if (g_variant_dict_contains (options, "version"))
+ {
+ g_application_command_line_print (command_line,
+ "GNOME nautilus " PACKAGE_VERSION "\n");
+ retval = EXIT_SUCCESS;
+ goto out;
+ }
- if (!do_cmdline_sanity_checks (self, options)) {
- retval = EXIT_FAILURE;
- goto out;
- }
+ if (!do_cmdline_sanity_checks (self, options))
+ {
+ retval = EXIT_FAILURE;
+ goto out;
+ }
- if (g_variant_dict_contains (options, "check")) {
- retval = do_perform_self_checks ();
- goto out;
- }
+ if (g_variant_dict_contains (options, "check"))
+ {
+ retval = do_perform_self_checks ();
+ goto out;
+ }
- if (g_variant_dict_contains (options, "quit")) {
- DEBUG ("Killing application, as requested");
- g_action_group_activate_action (G_ACTION_GROUP (application),
- "kill", NULL);
- goto out;
- }
+ if (g_variant_dict_contains (options, "quit"))
+ {
+ DEBUG ("Killing application, as requested");
+ g_action_group_activate_action (G_ACTION_GROUP (application),
+ "kill", NULL);
+ goto out;
+ }
- retval = nautilus_application_handle_file_args (self, options);
+ retval = nautilus_application_handle_file_args (self, options);
- out:
- nautilus_profile_end (NULL);
+out:
+ nautilus_profile_end (NULL);
- return retval;
+ return retval;
}
static void
nautilus_application_init (NautilusApplication *self)
{
- NautilusApplicationPrivate *priv;
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
+ priv = nautilus_application_get_instance_private (self);
- priv->notifications = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- NULL);
+ priv->notifications = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ NULL);
- priv->undo_manager = nautilus_file_undo_manager_new ();
+ priv->undo_manager = nautilus_file_undo_manager_new ();
- g_application_add_main_option_entries (G_APPLICATION (self), options);
+ g_application_add_main_option_entries (G_APPLICATION (self), options);
- nautilus_ensure_extension_points ();
- nautilus_ensure_extension_builtins ();
+ nautilus_ensure_extension_points ();
+ nautilus_ensure_extension_builtins ();
}
static void
theme_changed (GtkSettings *settings)
{
- static GtkCssProvider *provider = NULL;
- static GtkCssProvider *permanent_provider = NULL;
- gchar *theme;
- GdkScreen *screen;
- GFile *file;
-
- g_object_get (settings, "gtk-theme-name", &theme, NULL);
- screen = gdk_screen_get_default ();
-
- /* CSS that themes can override */
- if (g_str_equal (theme, "Adwaita"))
- {
- if (provider == NULL)
- {
- provider = gtk_css_provider_new ();
- file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/Adwaita.css");
- gtk_css_provider_load_from_file (provider, file, NULL);
- g_object_unref (file);
- }
-
- gtk_style_context_add_provider_for_screen (screen,
- GTK_STYLE_PROVIDER (provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
- else if (provider != NULL)
- {
- gtk_style_context_remove_provider_for_screen (screen,
- GTK_STYLE_PROVIDER (provider));
- g_clear_object (&provider);
- }
-
- /* CSS we want to always load for any theme */
- if (permanent_provider == NULL) {
- permanent_provider = gtk_css_provider_new ();
- file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/nautilus.css");
- gtk_css_provider_load_from_file (permanent_provider, file, NULL);
- /* The behavior of two style providers with the same priority is
- * undefined and gtk happens to prefer the provider that got added last.
- * Use a higher priority here to avoid this problem.
- */
- gtk_style_context_add_provider_for_screen (screen,
- GTK_STYLE_PROVIDER (permanent_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
- g_object_unref (file);
- }
-
- g_free (theme);
+ static GtkCssProvider *provider = NULL;
+ static GtkCssProvider *permanent_provider = NULL;
+ gchar *theme;
+ GdkScreen *screen;
+ GFile *file;
+
+ g_object_get (settings, "gtk-theme-name", &theme, NULL);
+ screen = gdk_screen_get_default ();
+
+ /* CSS that themes can override */
+ if (g_str_equal (theme, "Adwaita"))
+ {
+ if (provider == NULL)
+ {
+ provider = gtk_css_provider_new ();
+ file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/Adwaita.css");
+ gtk_css_provider_load_from_file (provider, file, NULL);
+ g_object_unref (file);
+ }
+
+ gtk_style_context_add_provider_for_screen (screen,
+ GTK_STYLE_PROVIDER (provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
+ else if (provider != NULL)
+ {
+ gtk_style_context_remove_provider_for_screen (screen,
+ GTK_STYLE_PROVIDER (provider));
+ g_clear_object (&provider);
+ }
+
+ /* CSS we want to always load for any theme */
+ if (permanent_provider == NULL)
+ {
+ permanent_provider = gtk_css_provider_new ();
+ file = g_file_new_for_uri ("resource:///org/gnome/nautilus/css/nautilus.css");
+ gtk_css_provider_load_from_file (permanent_provider, file, NULL);
+ /* The behavior of two style providers with the same priority is
+ * undefined and gtk happens to prefer the provider that got added last.
+ * Use a higher priority here to avoid this problem.
+ */
+ gtk_style_context_add_provider_for_screen (screen,
+ GTK_STYLE_PROVIDER (permanent_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
+ g_object_unref (file);
+ }
+
+ g_free (theme);
}
static void
setup_theme_extensions (void)
{
- GtkSettings *settings;
-
- /* Set up a handler to load our custom css for Adwaita.
- * See https://bugzilla.gnome.org/show_bug.cgi?id=732959
- * for a more automatic solution that is still under discussion.
- */
- settings = gtk_settings_get_default ();
- g_signal_connect (settings, "notify::gtk-theme-name", G_CALLBACK (theme_changed), NULL);
- theme_changed (settings);
+ GtkSettings *settings;
+
+ /* Set up a handler to load our custom css for Adwaita.
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=732959
+ * for a more automatic solution that is still under discussion.
+ */
+ settings = gtk_settings_get_default ();
+ g_signal_connect (settings, "notify::gtk-theme-name", G_CALLBACK (theme_changed), NULL);
+ theme_changed (settings);
}
NautilusApplication *
nautilus_application_get_default (void)
{
- NautilusApplication *self;
+ NautilusApplication *self;
- self = NAUTILUS_APPLICATION (g_application_get_default ());
+ self = NAUTILUS_APPLICATION (g_application_get_default ());
- return self;
+ return self;
}
void
@@ -1050,214 +1133,228 @@ nautilus_application_send_notification (NautilusApplication *self,
const gchar *notification_id,
GNotification *notification)
{
- NautilusApplicationPrivate *priv;
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
+ priv = nautilus_application_get_instance_private (self);
- g_hash_table_add (priv->notifications, g_strdup (notification_id));
- g_application_send_notification (G_APPLICATION (self), notification_id, notification);
+ g_hash_table_add (priv->notifications, g_strdup (notification_id));
+ g_application_send_notification (G_APPLICATION (self), notification_id, notification);
}
void
nautilus_application_withdraw_notification (NautilusApplication *self,
const gchar *notification_id)
{
- NautilusApplicationPrivate *priv;
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
- if (!g_hash_table_contains (priv->notifications, notification_id)) {
- return;
- }
+ priv = nautilus_application_get_instance_private (self);
+ if (!g_hash_table_contains (priv->notifications, notification_id))
+ {
+ return;
+ }
- g_hash_table_remove (priv->notifications, notification_id);
- g_application_withdraw_notification (G_APPLICATION (self), notification_id);
+ g_hash_table_remove (priv->notifications, notification_id);
+ g_application_withdraw_notification (G_APPLICATION (self), notification_id);
}
static void
on_application_shutdown (GApplication *application,
gpointer user_data)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (application);
- NautilusApplicationPrivate *priv;
- GList *notification_ids;
- GList *l;
- gchar *notification_id;
-
- priv = nautilus_application_get_instance_private (self);
- notification_ids = g_hash_table_get_keys (priv->notifications);
- for (l = notification_ids; l != NULL; l = l->next) {
- notification_id = l->data;
-
- g_application_withdraw_notification (application, notification_id);
- }
+ NautilusApplication *self = NAUTILUS_APPLICATION (application);
+ NautilusApplicationPrivate *priv;
+ GList *notification_ids;
+ GList *l;
+ gchar *notification_id;
+
+ priv = nautilus_application_get_instance_private (self);
+ notification_ids = g_hash_table_get_keys (priv->notifications);
+ for (l = notification_ids; l != NULL; l = l->next)
+ {
+ notification_id = l->data;
- g_list_free (notification_ids);
+ g_application_withdraw_notification (application, notification_id);
+ }
+
+ g_list_free (notification_ids);
- nautilus_icon_info_clear_caches ();
+ nautilus_icon_info_clear_caches ();
}
void
nautilus_application_startup_common (NautilusApplication *self)
{
- NautilusApplicationPrivate *priv;
+ NautilusApplicationPrivate *priv;
- nautilus_profile_start (NULL);
- priv = nautilus_application_get_instance_private (self);
+ nautilus_profile_start (NULL);
+ priv = nautilus_application_get_instance_private (self);
- g_application_set_resource_base_path (G_APPLICATION (self), "/org/gnome/nautilus");
+ g_application_set_resource_base_path (G_APPLICATION (self), "/org/gnome/nautilus");
- /* chain up to the GTK+ implementation early, so gtk_init()
- * is called for us.
- */
- G_APPLICATION_CLASS (nautilus_application_parent_class)->startup (G_APPLICATION (self));
+ /* chain up to the GTK+ implementation early, so gtk_init()
+ * is called for us.
+ */
+ G_APPLICATION_CLASS (nautilus_application_parent_class)->startup (G_APPLICATION (self));
- gtk_window_set_default_icon_name ("system-file-manager");
+ gtk_window_set_default_icon_name ("system-file-manager");
- setup_theme_extensions ();
+ setup_theme_extensions ();
- /* initialize preferences and create the global GSettings objects */
- nautilus_global_preferences_init ();
+ /* initialize preferences and create the global GSettings objects */
+ nautilus_global_preferences_init ();
- /* register property pages */
- nautilus_image_properties_page_register ();
+ /* register property pages */
+ nautilus_image_properties_page_register ();
- /* initialize nautilus modules */
- nautilus_profile_start ("Modules");
- nautilus_module_setup ();
- nautilus_profile_end ("Modules");
+ /* initialize nautilus modules */
+ nautilus_profile_start ("Modules");
+ nautilus_module_setup ();
+ nautilus_profile_end ("Modules");
- /* attach menu-provider module callback */
- menu_provider_init_callback ();
-
- /* Initialize the UI handler singleton for file operations */
- priv->progress_handler = nautilus_progress_persistence_handler_new (G_OBJECT (self));
+ /* attach menu-provider module callback */
+ menu_provider_init_callback ();
- /* Check the user's .nautilus directories and post warnings
- * if there are problems.
- */
- check_required_directories (self);
+ /* Initialize the UI handler singleton for file operations */
+ priv->progress_handler = nautilus_progress_persistence_handler_new (G_OBJECT (self));
- nautilus_init_application_actions (self);
+ /* Check the user's .nautilus directories and post warnings
+ * if there are problems.
+ */
+ check_required_directories (self);
- nautilus_profile_end (NULL);
+ nautilus_init_application_actions (self);
- g_signal_connect (self, "shutdown", G_CALLBACK (on_application_shutdown), NULL);
+ nautilus_profile_end (NULL);
+ g_signal_connect (self, "shutdown", G_CALLBACK (on_application_shutdown), NULL);
}
static void
nautilus_application_startup (GApplication *app)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (app);
- NautilusApplicationPrivate *priv;
+ NautilusApplication *self = NAUTILUS_APPLICATION (app);
+ NautilusApplicationPrivate *priv;
- nautilus_profile_start (NULL);
- priv = nautilus_application_get_instance_private (self);
+ nautilus_profile_start (NULL);
+ priv = nautilus_application_get_instance_private (self);
- /* create DBus manager */
- priv->fdb_manager = nautilus_freedesktop_dbus_new ();
- nautilus_application_startup_common (self);
+ /* create DBus manager */
+ priv->fdb_manager = nautilus_freedesktop_dbus_new ();
+ nautilus_application_startup_common (self);
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static gboolean
-nautilus_application_dbus_register (GApplication *app,
- GDBusConnection *connection,
- const gchar *object_path,
- GError **error)
+nautilus_application_dbus_register (GApplication *app,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (app);
- NautilusApplicationPrivate *priv;
+ NautilusApplication *self = NAUTILUS_APPLICATION (app);
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
- priv->dbus_manager = nautilus_dbus_manager_new ();
- if (!nautilus_dbus_manager_register (priv->dbus_manager, connection, error)) {
- return FALSE;
- }
+ priv = nautilus_application_get_instance_private (self);
+ priv->dbus_manager = nautilus_dbus_manager_new ();
+ if (!nautilus_dbus_manager_register (priv->dbus_manager, connection, error))
+ {
+ return FALSE;
+ }
- priv->search_provider = nautilus_shell_search_provider_new ();
- if (!nautilus_shell_search_provider_register (priv->search_provider, connection, error)) {
- return FALSE;
- }
+ priv->search_provider = nautilus_shell_search_provider_new ();
+ if (!nautilus_shell_search_provider_register (priv->search_provider, connection, error))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static void
-nautilus_application_dbus_unregister (GApplication *app,
- GDBusConnection *connection,
- const gchar *object_path)
+nautilus_application_dbus_unregister (GApplication *app,
+ GDBusConnection *connection,
+ const gchar *object_path)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (app);
- NautilusApplicationPrivate *priv;
+ NautilusApplication *self = NAUTILUS_APPLICATION (app);
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
- if (priv->dbus_manager) {
- nautilus_dbus_manager_unregister (priv->dbus_manager);
- }
+ priv = nautilus_application_get_instance_private (self);
+ if (priv->dbus_manager)
+ {
+ nautilus_dbus_manager_unregister (priv->dbus_manager);
+ }
- if (priv->search_provider) {
- nautilus_shell_search_provider_unregister (priv->search_provider);
- }
+ if (priv->search_provider)
+ {
+ nautilus_shell_search_provider_unregister (priv->search_provider);
+ }
}
static void
update_dbus_opened_locations (NautilusApplication *self)
{
- NautilusApplicationPrivate *priv;
- gint i;
- GList *l, *sl;
- GList *locations = NULL;
- gsize locations_size = 0;
- gchar **locations_array;
- NautilusWindow *window;
- GFile *location;
-
- g_return_if_fail (NAUTILUS_IS_APPLICATION (self));
-
- priv = nautilus_application_get_instance_private (self);
-
- /* Children of nautilus application could not handle the dbus, so don't
- * do anything in that case */
- if (!priv->fdb_manager)
- return;
-
- for (l = priv->windows; l != NULL; l = l->next) {
- window = l->data;
-
- for (sl = nautilus_window_get_slots (window); sl; sl = sl->next) {
- NautilusWindowSlot *slot = sl->data;
- location = nautilus_window_slot_get_location (slot);
-
- if (location != NULL) {
- gchar *uri = g_file_get_uri (location);
- GList *found = g_list_find_custom (locations, uri, (GCompareFunc) g_strcmp0);
-
- if (!found) {
- locations = g_list_prepend (locations, uri);
- ++locations_size;
- } else {
- g_free (uri);
- }
- }
- }
- }
-
- locations_array = g_new (gchar*, locations_size + 1);
-
- for (i = 0, l = locations; l; l = l->next, ++i) {
- /* We reuse the locations string locations saved on list */
- locations_array[i] = l->data;
- }
-
- locations_array[locations_size] = NULL;
-
- nautilus_freedesktop_dbus_set_open_locations (priv->fdb_manager,
- (const gchar**) locations_array);
-
- g_free (locations_array);
- g_list_free_full (locations, g_free);
+ NautilusApplicationPrivate *priv;
+ gint i;
+ GList *l, *sl;
+ GList *locations = NULL;
+ gsize locations_size = 0;
+ gchar **locations_array;
+ NautilusWindow *window;
+ GFile *location;
+
+ g_return_if_fail (NAUTILUS_IS_APPLICATION (self));
+
+ priv = nautilus_application_get_instance_private (self);
+
+ /* Children of nautilus application could not handle the dbus, so don't
+ * do anything in that case */
+ if (!priv->fdb_manager)
+ {
+ return;
+ }
+
+ for (l = priv->windows; l != NULL; l = l->next)
+ {
+ window = l->data;
+
+ for (sl = nautilus_window_get_slots (window); sl; sl = sl->next)
+ {
+ NautilusWindowSlot *slot = sl->data;
+ location = nautilus_window_slot_get_location (slot);
+
+ if (location != NULL)
+ {
+ gchar *uri = g_file_get_uri (location);
+ GList *found = g_list_find_custom (locations, uri, (GCompareFunc) g_strcmp0);
+
+ if (!found)
+ {
+ locations = g_list_prepend (locations, uri);
+ ++locations_size;
+ }
+ else
+ {
+ g_free (uri);
+ }
+ }
+ }
+ }
+
+ locations_array = g_new (gchar *, locations_size + 1);
+
+ for (i = 0, l = locations; l; l = l->next, ++i)
+ {
+ /* We reuse the locations string locations saved on list */
+ locations_array[i] = l->data;
+ }
+
+ locations_array[locations_size] = NULL;
+
+ nautilus_freedesktop_dbus_set_open_locations (priv->fdb_manager,
+ (const gchar **) locations_array);
+
+ g_free (locations_array);
+ g_list_free_full (locations, g_free);
}
static void
@@ -1265,70 +1362,74 @@ on_slot_location_changed (NautilusWindowSlot *slot,
GParamSpec *pspec,
NautilusApplication *self)
{
- update_dbus_opened_locations (self);
+ update_dbus_opened_locations (self);
}
static void
on_slot_added (NautilusWindow *window,
- NautilusWindowSlot *slot,
- NautilusApplication *self)
+ NautilusWindowSlot *slot,
+ NautilusApplication *self)
{
- if (nautilus_window_slot_get_location (slot)) {
- update_dbus_opened_locations (self);
- }
+ if (nautilus_window_slot_get_location (slot))
+ {
+ update_dbus_opened_locations (self);
+ }
- g_signal_connect (slot, "notify::location", G_CALLBACK (on_slot_location_changed), self);
+ g_signal_connect (slot, "notify::location", G_CALLBACK (on_slot_location_changed), self);
}
static void
on_slot_removed (NautilusWindow *window,
- NautilusWindowSlot *slot,
- NautilusApplication *self)
+ NautilusWindowSlot *slot,
+ NautilusApplication *self)
{
- update_dbus_opened_locations (self);
+ update_dbus_opened_locations (self);
- g_signal_handlers_disconnect_by_func (slot, on_slot_location_changed, self);
+ g_signal_handlers_disconnect_by_func (slot, on_slot_location_changed, self);
}
static void
nautilus_application_window_added (GtkApplication *app,
- GtkWindow *window)
+ GtkWindow *window)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (app);
- NautilusApplicationPrivate *priv;
+ NautilusApplication *self = NAUTILUS_APPLICATION (app);
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
- GTK_APPLICATION_CLASS (nautilus_application_parent_class)->window_added (app, window);
+ priv = nautilus_application_get_instance_private (self);
+ GTK_APPLICATION_CLASS (nautilus_application_parent_class)->window_added (app, window);
- if (NAUTILUS_IS_WINDOW (window)) {
- priv->windows = g_list_prepend (priv->windows, window);
- g_signal_connect (window, "slot-added", G_CALLBACK (on_slot_added), app);
- g_signal_connect (window, "slot-removed", G_CALLBACK (on_slot_removed), app);
- }
+ if (NAUTILUS_IS_WINDOW (window))
+ {
+ priv->windows = g_list_prepend (priv->windows, window);
+ g_signal_connect (window, "slot-added", G_CALLBACK (on_slot_added), app);
+ g_signal_connect (window, "slot-removed", G_CALLBACK (on_slot_removed), app);
+ }
}
static void
nautilus_application_window_removed (GtkApplication *app,
- GtkWindow *window)
+ GtkWindow *window)
{
- NautilusApplication *self = NAUTILUS_APPLICATION (app);
- NautilusApplicationPrivate *priv;
+ NautilusApplication *self = NAUTILUS_APPLICATION (app);
+ NautilusApplicationPrivate *priv;
- priv = nautilus_application_get_instance_private (self);
+ priv = nautilus_application_get_instance_private (self);
- GTK_APPLICATION_CLASS (nautilus_application_parent_class)->window_removed (app, window);
+ GTK_APPLICATION_CLASS (nautilus_application_parent_class)->window_removed (app, window);
- if (NAUTILUS_IS_WINDOW (window)) {
- priv->windows = g_list_remove_all (priv->windows, window);
- g_signal_handlers_disconnect_by_func (window, on_slot_added, app);
- g_signal_handlers_disconnect_by_func (window, on_slot_removed, app);
- }
+ if (NAUTILUS_IS_WINDOW (window))
+ {
+ priv->windows = g_list_remove_all (priv->windows, window);
+ g_signal_handlers_disconnect_by_func (window, on_slot_added, app);
+ g_signal_handlers_disconnect_by_func (window, on_slot_removed, app);
+ }
- /* if this was the last window, close the previewer */
- if (g_list_length (priv->windows) == 0) {
- nautilus_previewer_call_close ();
- nautilus_progress_persistence_handler_make_persistent (priv->progress_handler);
- }
+ /* if this was the last window, close the previewer */
+ if (g_list_length (priv->windows) == 0)
+ {
+ nautilus_previewer_call_close ();
+ nautilus_progress_persistence_handler_make_persistent (priv->progress_handler);
+ }
}
/* Manage the local instance command line options. This is only necessary to
@@ -1339,49 +1440,49 @@ static gint
nautilus_application_handle_local_options (GApplication *app,
GVariantDict *options)
{
- gchar *cwd;
+ gchar *cwd;
- cwd = g_get_current_dir ();
- g_variant_dict_insert (options, "cwd", "s", cwd);
- g_free (cwd);
+ cwd = g_get_current_dir ();
+ g_variant_dict_insert (options, "cwd", "s", cwd);
+ g_free (cwd);
- return -1;
+ return -1;
}
static void
nautilus_application_class_init (NautilusApplicationClass *class)
{
- GObjectClass *object_class;
- GApplicationClass *application_class;
- GtkApplicationClass *gtkapp_class;
-
- object_class = G_OBJECT_CLASS (class);
- object_class->finalize = nautilus_application_finalize;
-
- application_class = G_APPLICATION_CLASS (class);
- application_class->startup = nautilus_application_startup;
- application_class->activate = nautilus_application_activate;
- application_class->dbus_register = nautilus_application_dbus_register;
- application_class->dbus_unregister = nautilus_application_dbus_unregister;
- application_class->open = nautilus_application_open;
- application_class->command_line = nautilus_application_command_line;
- application_class->handle_local_options = nautilus_application_handle_local_options;
-
- class->open_location_full = real_open_location_full;
-
- gtkapp_class = GTK_APPLICATION_CLASS (class);
- gtkapp_class->window_added = nautilus_application_window_added;
- gtkapp_class->window_removed = nautilus_application_window_removed;
+ GObjectClass *object_class;
+ GApplicationClass *application_class;
+ GtkApplicationClass *gtkapp_class;
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->finalize = nautilus_application_finalize;
+
+ application_class = G_APPLICATION_CLASS (class);
+ application_class->startup = nautilus_application_startup;
+ application_class->activate = nautilus_application_activate;
+ application_class->dbus_register = nautilus_application_dbus_register;
+ application_class->dbus_unregister = nautilus_application_dbus_unregister;
+ application_class->open = nautilus_application_open;
+ application_class->command_line = nautilus_application_command_line;
+ application_class->handle_local_options = nautilus_application_handle_local_options;
+
+ class->open_location_full = real_open_location_full;
+
+ gtkapp_class = GTK_APPLICATION_CLASS (class);
+ gtkapp_class->window_added = nautilus_application_window_added;
+ gtkapp_class->window_removed = nautilus_application_window_removed;
}
NautilusApplication *
nautilus_application_new (void)
{
- return g_object_new (NAUTILUS_TYPE_APPLICATION,
- "application-id", "org.gnome.Nautilus",
- "flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN,
- "inactivity-timeout", 12000,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_APPLICATION,
+ "application-id", "org.gnome.Nautilus",
+ "flags", G_APPLICATION_HANDLES_COMMAND_LINE | G_APPLICATION_HANDLES_OPEN,
+ "inactivity-timeout", 12000,
+ NULL);
}
void
@@ -1389,12 +1490,12 @@ nautilus_application_search (NautilusApplication *self,
const gchar *uri,
const gchar *text)
{
- NautilusWindow *window;
- GFile *location;
+ NautilusWindow *window;
+ GFile *location;
- location = g_file_new_for_uri (uri);
- window = open_window (self, location);
- nautilus_window_search (window, text);
+ location = g_file_new_for_uri (uri);
+ window = open_window (self, location);
+ nautilus_window_search (window, text);
- g_object_unref (location);
+ g_object_unref (location);
}
diff --git a/src/nautilus-autorun-software.c b/src/nautilus-autorun-software.c
index cfe528eea..6195a3e74 100644
--- a/src/nautilus-autorun-software.c
+++ b/src/nautilus-autorun-software.c
@@ -1,24 +1,23 @@
-
/* Nautilus
-
- Copyright (C) 2008 Red Hat, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Author: David Zeuthen <davidz@redhat.com>
-*/
+ *
+ * Copyright (C) 2008 Red Hat, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Author: David Zeuthen <davidz@redhat.com>
+ */
#include <config.h>
@@ -37,263 +36,291 @@
typedef struct
{
- GtkWidget *dialog;
- GMount *mount;
+ GtkWidget *dialog;
+ GMount *mount;
} AutorunSoftwareDialogData;
-static void autorun_software_dialog_mount_unmounted (GMount *mount, AutorunSoftwareDialogData *data);
+static void autorun_software_dialog_mount_unmounted (GMount *mount,
+ AutorunSoftwareDialogData *data);
static void
autorun_software_dialog_destroy (AutorunSoftwareDialogData *data)
{
- g_signal_handlers_disconnect_by_func (G_OBJECT (data->mount),
- G_CALLBACK (autorun_software_dialog_mount_unmounted),
- data);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (data->mount),
+ G_CALLBACK (autorun_software_dialog_mount_unmounted),
+ data);
- gtk_widget_destroy (GTK_WIDGET (data->dialog));
- g_object_unref (data->mount);
- g_free (data);
+ gtk_widget_destroy (GTK_WIDGET (data->dialog));
+ g_object_unref (data->mount);
+ g_free (data);
}
-static void
-autorun_software_dialog_mount_unmounted (GMount *mount, AutorunSoftwareDialogData *data)
+static void
+autorun_software_dialog_mount_unmounted (GMount *mount,
+ AutorunSoftwareDialogData *data)
{
- autorun_software_dialog_destroy (data);
+ autorun_software_dialog_destroy (data);
}
static gboolean
-_check_file (GFile *mount_root, const char *file_path, gboolean must_be_executable)
+_check_file (GFile *mount_root,
+ const char *file_path,
+ gboolean must_be_executable)
{
- GFile *file;
- GFileInfo *file_info;
- gboolean ret;
-
- ret = FALSE;
-
- file = g_file_get_child (mount_root, file_path);
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- NULL);
- if (file_info != NULL) {
- if (must_be_executable) {
- if (g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) {
- ret = TRUE;
- }
- } else {
- ret = TRUE;
- }
- g_object_unref (file_info);
- }
- g_object_unref (file);
-
- return ret;
+ GFile *file;
+ GFileInfo *file_info;
+ gboolean ret;
+
+ ret = FALSE;
+
+ file = g_file_get_child (mount_root, file_path);
+ file_info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ if (file_info != NULL)
+ {
+ if (must_be_executable)
+ {
+ if (g_file_info_get_attribute_boolean (file_info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
+ {
+ ret = TRUE;
+ }
+ }
+ else
+ {
+ ret = TRUE;
+ }
+ g_object_unref (file_info);
+ }
+ g_object_unref (file);
+
+ return ret;
}
static void
autorun (GMount *mount)
{
- char *error_string;
- GFile *root;
- GFile *program_to_spawn;
- GFile *program_parameter_file;
- char *path_to_spawn;
- char *cwd_for_program;
- char *program_parameter;
-
- root = g_mount_get_root (mount);
-
- /* Careful here, according to
- *
- * http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
- *
- * the ordering does matter.
- */
-
- program_to_spawn = NULL;
- path_to_spawn = NULL;
- program_parameter_file = NULL;
- program_parameter = NULL;
-
- if (_check_file (root, ".autorun", TRUE)) {
- program_to_spawn = g_file_get_child (root, ".autorun");
- } else if (_check_file (root, "autorun", TRUE)) {
- program_to_spawn = g_file_get_child (root, "autorun");
- } else if (_check_file (root, "autorun.sh", TRUE)) {
- program_to_spawn = g_file_new_for_path ("/bin/sh");
- program_parameter_file = g_file_get_child (root, "autorun.sh");
+ char *error_string;
+ GFile *root;
+ GFile *program_to_spawn;
+ GFile *program_parameter_file;
+ char *path_to_spawn;
+ char *cwd_for_program;
+ char *program_parameter;
+
+ root = g_mount_get_root (mount);
+
+ /* Careful here, according to
+ *
+ * http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
+ *
+ * the ordering does matter.
+ */
+
+ program_to_spawn = NULL;
+ path_to_spawn = NULL;
+ program_parameter_file = NULL;
+ program_parameter = NULL;
+
+ if (_check_file (root, ".autorun", TRUE))
+ {
+ program_to_spawn = g_file_get_child (root, ".autorun");
+ }
+ else if (_check_file (root, "autorun", TRUE))
+ {
+ program_to_spawn = g_file_get_child (root, "autorun");
+ }
+ else if (_check_file (root, "autorun.sh", TRUE))
+ {
+ program_to_spawn = g_file_new_for_path ("/bin/sh");
+ program_parameter_file = g_file_get_child (root, "autorun.sh");
+ }
+
+ if (program_to_spawn != NULL)
+ {
+ path_to_spawn = g_file_get_path (program_to_spawn);
+ }
+ if (program_parameter_file != NULL)
+ {
+ program_parameter = g_file_get_path (program_parameter_file);
+ }
+
+ cwd_for_program = g_file_get_path (root);
+
+ error_string = NULL;
+ if (path_to_spawn != NULL && cwd_for_program != NULL)
+ {
+ if (chdir (cwd_for_program) == 0)
+ {
+ execl (path_to_spawn, path_to_spawn, program_parameter, NULL);
+ error_string = g_strdup_printf (_("Unable to start the program:\n%s"), strerror (errno));
+ goto out;
}
-
- if (program_to_spawn != NULL) {
- path_to_spawn = g_file_get_path (program_to_spawn);
- }
- if (program_parameter_file != NULL) {
- program_parameter = g_file_get_path (program_parameter_file);
- }
-
- cwd_for_program = g_file_get_path (root);
-
- error_string = NULL;
- if (path_to_spawn != NULL && cwd_for_program != NULL) {
- if (chdir (cwd_for_program) == 0) {
- execl (path_to_spawn, path_to_spawn, program_parameter, NULL);
- error_string = g_strdup_printf (_("Unable to start the program:\n%s"), strerror (errno));
- goto out;
- }
- error_string = g_strdup_printf (_("Unable to start the program:\n%s"), strerror (errno));
- goto out;
- }
- error_string = g_strdup_printf (_("Unable to locate the program"));
+ error_string = g_strdup_printf (_("Unable to start the program:\n%s"), strerror (errno));
+ goto out;
+ }
+ error_string = g_strdup_printf (_("Unable to locate the program"));
out:
- if (program_to_spawn != NULL) {
- g_object_unref (program_to_spawn);
- }
- if (program_parameter_file != NULL) {
- g_object_unref (program_parameter_file);
- }
- if (root != NULL) {
- g_object_unref (root);
- }
- g_free (path_to_spawn);
- g_free (cwd_for_program);
- g_free (program_parameter);
-
- if (error_string != NULL) {
- GtkWidget *dialog;
- dialog = gtk_message_dialog_new_with_markup (NULL, /* TODO: parent window? */
- 0,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Oops! There was a problem running this software."));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error_string);
- /* This is required because we don't show dialogs in the
- window picker and if the window pops under another window
- there is no way to get it back. */
- gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
-
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- g_free (error_string);
- }
+ if (program_to_spawn != NULL)
+ {
+ g_object_unref (program_to_spawn);
+ }
+ if (program_parameter_file != NULL)
+ {
+ g_object_unref (program_parameter_file);
+ }
+ if (root != NULL)
+ {
+ g_object_unref (root);
+ }
+ g_free (path_to_spawn);
+ g_free (cwd_for_program);
+ g_free (program_parameter);
+
+ if (error_string != NULL)
+ {
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new_with_markup (NULL, /* TODO: parent window? */
+ 0,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Oops! There was a problem running this software."));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error_string);
+ /* This is required because we don't show dialogs in the
+ * window picker and if the window pops under another window
+ * there is no way to get it back. */
+ gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ g_free (error_string);
+ }
}
static void
present_autorun_for_software_dialog (GMount *mount)
{
- GIcon *icon;
- int icon_size;
- NautilusIconInfo *icon_info;
- GdkPixbuf *pixbuf;
- char *mount_name;
- GtkWidget *dialog;
- AutorunSoftwareDialogData *data;
-
- mount_name = g_mount_get_name (mount);
-
- dialog = gtk_message_dialog_new (NULL, /* TODO: parent window? */
- 0,
- GTK_MESSAGE_OTHER,
- GTK_BUTTONS_CANCEL,
- _("“%s” contains software intended to be automatically started. Would you like to run it?"),
- mount_name);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s",
- _("If you don't trust this location or aren't sure, press Cancel."));
-
- /* This is required because we don't show dialogs in the
- window picker and if the window pops under another window
- there is no way to get it back. */
- gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
-
- /* TODO: in a star trek future add support for verifying
- * software on media (e.g. if it has a certificate, check it
- * etc.)
- */
-
-
- icon = g_mount_get_icon (mount);
- icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
- icon_info = nautilus_icon_info_lookup (icon, icon_size,
- gtk_widget_get_scale_factor (GTK_WIDGET (dialog)));
- pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);
-
- gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);
-
- data = g_new0 (AutorunSoftwareDialogData, 1);
- data->dialog = dialog;
- data->mount = g_object_ref (mount);
-
- g_signal_connect (G_OBJECT (mount),
- "unmounted",
- G_CALLBACK (autorun_software_dialog_mount_unmounted),
- data);
-
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- _("_Run"),
- GTK_RESPONSE_OK);
-
- gtk_widget_show_all (dialog);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
- gtk_widget_destroy (dialog);
- autorun (mount);
- }
-
- g_object_unref (icon_info);
- g_object_unref (pixbuf);
- g_free (mount_name);
+ GIcon *icon;
+ int icon_size;
+ NautilusIconInfo *icon_info;
+ GdkPixbuf *pixbuf;
+ char *mount_name;
+ GtkWidget *dialog;
+ AutorunSoftwareDialogData *data;
+
+ mount_name = g_mount_get_name (mount);
+
+ dialog = gtk_message_dialog_new (NULL, /* TODO: parent window? */
+ 0,
+ GTK_MESSAGE_OTHER,
+ GTK_BUTTONS_CANCEL,
+ _("“%s” contains software intended to be automatically started. Would you like to run it?"),
+ mount_name);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s",
+ _("If you don't trust this location or aren't sure, press Cancel."));
+
+ /* This is required because we don't show dialogs in the
+ * window picker and if the window pops under another window
+ * there is no way to get it back. */
+ gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+
+ /* TODO: in a star trek future add support for verifying
+ * software on media (e.g. if it has a certificate, check it
+ * etc.)
+ */
+
+
+ icon = g_mount_get_icon (mount);
+ icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_DIALOG);
+ icon_info = nautilus_icon_info_lookup (icon, icon_size,
+ gtk_widget_get_scale_factor (GTK_WIDGET (dialog)));
+ pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);
+
+ gtk_window_set_icon (GTK_WINDOW (dialog), pixbuf);
+
+ data = g_new0 (AutorunSoftwareDialogData, 1);
+ data->dialog = dialog;
+ data->mount = g_object_ref (mount);
+
+ g_signal_connect (G_OBJECT (mount),
+ "unmounted",
+ G_CALLBACK (autorun_software_dialog_mount_unmounted),
+ data);
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("_Run"),
+ GTK_RESPONSE_OK);
+
+ gtk_widget_show_all (dialog);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+ {
+ gtk_widget_destroy (dialog);
+ autorun (mount);
+ }
+
+ g_object_unref (icon_info);
+ g_object_unref (pixbuf);
+ g_free (mount_name);
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- GVolumeMonitor *monitor;
- GFile *file;
- GMount *mount;
- GError *error;
-
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
-
- gtk_init (&argc, &argv);
-
- if (argc != 2) {
- g_print ("Usage: %s mount-uri\n", argv[0]);
- goto out;
- }
-
- /* instantiate monitor so we get the "unmounted" signal properly */
- monitor = g_volume_monitor_get ();
- if (monitor == NULL) {
- g_warning ("Unable to connect to the volume monitor");
- goto out;
- }
-
- file = g_file_new_for_commandline_arg (argv[1]);
- if (file == NULL) {
- g_object_unref (monitor);
- g_warning ("Unable to parse mount URI");
- goto out;
- }
-
- error = NULL;
- mount = g_file_find_enclosing_mount (file, NULL, &error);
- if (mount == NULL) {
- g_warning ("Unable to find device for URI: %s", error->message);
- g_clear_error (&error);
- g_object_unref (file);
- g_object_unref (monitor);
- goto out;
- }
-
- present_autorun_for_software_dialog (mount);
- g_object_unref (file);
- g_object_unref (monitor);
- g_object_unref (mount);
-
-out:
- return 0;
+ GVolumeMonitor *monitor;
+ GFile *file;
+ GMount *mount;
+ GError *error;
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ gtk_init (&argc, &argv);
+
+ if (argc != 2)
+ {
+ g_print ("Usage: %s mount-uri\n", argv[0]);
+ goto out;
+ }
+
+ /* instantiate monitor so we get the "unmounted" signal properly */
+ monitor = g_volume_monitor_get ();
+ if (monitor == NULL)
+ {
+ g_warning ("Unable to connect to the volume monitor");
+ goto out;
+ }
+
+ file = g_file_new_for_commandline_arg (argv[1]);
+ if (file == NULL)
+ {
+ g_object_unref (monitor);
+ g_warning ("Unable to parse mount URI");
+ goto out;
+ }
+
+ error = NULL;
+ mount = g_file_find_enclosing_mount (file, NULL, &error);
+ if (mount == NULL)
+ {
+ g_warning ("Unable to find device for URI: %s", error->message);
+ g_clear_error (&error);
+ g_object_unref (file);
+ g_object_unref (monitor);
+ goto out;
+ }
+
+ present_autorun_for_software_dialog (mount);
+ g_object_unref (file);
+ g_object_unref (monitor);
+ g_object_unref (mount);
+
+out:
+ return 0;
}
diff --git a/src/nautilus-batch-rename-dialog.c b/src/nautilus-batch-rename-dialog.c
index 31432a068..20ea4111d 100644
--- a/src/nautilus-batch-rename-dialog.c
+++ b/src/nautilus-batch-rename-dialog.c
@@ -30,433 +30,450 @@
struct _NautilusBatchRenameDialog
{
- GtkDialog parent;
-
- GtkWidget *grid;
- NautilusWindow *window;
-
- GtkWidget *cancel_button;
- GtkWidget *original_name_listbox;
- GtkWidget *arrow_listbox;
- GtkWidget *result_listbox;
- GtkWidget *name_entry;
- GtkWidget *rename_button;
- GtkWidget *find_entry;
- GtkWidget *mode_stack;
- GtkWidget *replace_entry;
- GtkWidget *format_mode_button;
- GtkWidget *replace_mode_button;
- GtkWidget *add_button;
- GtkWidget *add_popover;
- GtkWidget *numbering_order_label;
- GtkWidget *numbering_label;
- GtkWidget *scrolled_window;
- GtkWidget *numbering_order_popover;
- GtkWidget *numbering_order_button;
- GtkWidget *conflict_box;
- GtkWidget *conflict_label;
- GtkWidget *conflict_down;
- GtkWidget *conflict_up;
-
- GList *original_name_listbox_rows;
- GList *arrow_listbox_rows;
- GList *result_listbox_rows;
- GList *listbox_labels_new;
- GList *listbox_labels_old;
- GList *listbox_icons;
- GtkSizeGroup *size_group;
-
- GList *selection;
- GList *new_names;
- NautilusBatchRenameDialogMode mode;
- NautilusDirectory *directory;
-
- GActionGroup *action_group;
-
- GMenu *numbering_order_menu;
- GMenu *add_tag_menu;
-
- GHashTable *create_date;
- GList *selection_metadata;
-
- /* check if all files in selection have the same parent */
- gboolean same_parent;
- /* the index of the currently selected conflict */
- gint selected_conflict;
- /* total conflicts number */
- gint conflicts_number;
-
- gint checked_parents;
- GList *duplicates;
- GList *distinct_parents;
- GTask *conflicts_task;
- GCancellable *conflict_cancellable;
- gboolean checking_conflicts;
-
- /* this hash table has information about the status
- * of all tags: availability, if it's currently used
- * and position */
- GHashTable *tag_info_table;
-
- GtkWidget *preselected_row1;
- GtkWidget *preselected_row2;
-
- gint row_height;
- gboolean rename_clicked;
-
- /* the numbers of characters from the name entry */
- gint name_entry_characters;
- gboolean tags_deleted;
- gint cursor_position;
- gboolean use_manual_cursor_position;
+ GtkDialog parent;
+
+ GtkWidget *grid;
+ NautilusWindow *window;
+
+ GtkWidget *cancel_button;
+ GtkWidget *original_name_listbox;
+ GtkWidget *arrow_listbox;
+ GtkWidget *result_listbox;
+ GtkWidget *name_entry;
+ GtkWidget *rename_button;
+ GtkWidget *find_entry;
+ GtkWidget *mode_stack;
+ GtkWidget *replace_entry;
+ GtkWidget *format_mode_button;
+ GtkWidget *replace_mode_button;
+ GtkWidget *add_button;
+ GtkWidget *add_popover;
+ GtkWidget *numbering_order_label;
+ GtkWidget *numbering_label;
+ GtkWidget *scrolled_window;
+ GtkWidget *numbering_order_popover;
+ GtkWidget *numbering_order_button;
+ GtkWidget *conflict_box;
+ GtkWidget *conflict_label;
+ GtkWidget *conflict_down;
+ GtkWidget *conflict_up;
+
+ GList *original_name_listbox_rows;
+ GList *arrow_listbox_rows;
+ GList *result_listbox_rows;
+ GList *listbox_labels_new;
+ GList *listbox_labels_old;
+ GList *listbox_icons;
+ GtkSizeGroup *size_group;
+
+ GList *selection;
+ GList *new_names;
+ NautilusBatchRenameDialogMode mode;
+ NautilusDirectory *directory;
+
+ GActionGroup *action_group;
+
+ GMenu *numbering_order_menu;
+ GMenu *add_tag_menu;
+
+ GHashTable *create_date;
+ GList *selection_metadata;
+
+ /* check if all files in selection have the same parent */
+ gboolean same_parent;
+ /* the index of the currently selected conflict */
+ gint selected_conflict;
+ /* total conflicts number */
+ gint conflicts_number;
+
+ gint checked_parents;
+ GList *duplicates;
+ GList *distinct_parents;
+ GTask *conflicts_task;
+ GCancellable *conflict_cancellable;
+ gboolean checking_conflicts;
+
+ /* this hash table has information about the status
+ * of all tags: availability, if it's currently used
+ * and position */
+ GHashTable *tag_info_table;
+
+ GtkWidget *preselected_row1;
+ GtkWidget *preselected_row2;
+
+ gint row_height;
+ gboolean rename_clicked;
+
+ /* the numbers of characters from the name entry */
+ gint name_entry_characters;
+ gboolean tags_deleted;
+ gint cursor_position;
+ gboolean use_manual_cursor_position;
};
typedef struct
{
- gboolean available;
- gboolean set;
- gint position;
- gint original_position;
- gint new_position;
- /* if the tag was just added, then we shouldn't update it's position */
- gboolean just_added;
+ gboolean available;
+ gboolean set;
+ gint position;
+ gint original_position;
+ gint new_position;
+ /* if the tag was just added, then we shouldn't update it's position */
+ gboolean just_added;
} TagData;
-static void update_display_text (NautilusBatchRenameDialog *dialog);
+static void update_display_text (NautilusBatchRenameDialog *dialog);
G_DEFINE_TYPE (NautilusBatchRenameDialog, nautilus_batch_rename_dialog, GTK_TYPE_DIALOG);
static void
-add_numbering_order (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+add_numbering_order (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
- const gchar *target_name;
+ NautilusBatchRenameDialog *dialog;
+ const gchar *target_name;
+
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+
+ target_name = g_variant_get_string (value, NULL);
+
+ if (g_strcmp0 (target_name, "name-ascending") == 0)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ _("Original name (Ascending)"));
+ dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
+ ORIGINAL_ASCENDING,
+ NULL);
+ }
+
+ if (g_strcmp0 (target_name, "name-descending") == 0)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ _("Original name (Descending)"));
+ dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
+ ORIGINAL_DESCENDING,
+ NULL);
+ }
+
+ if (g_strcmp0 (target_name, "first-modified") == 0)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ _("First Modified"));
+ dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
+ FIRST_MODIFIED,
+ NULL);
+ }
+
+ if (g_strcmp0 (target_name, "last-modified") == 0)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ _("Last Modified"));
+ dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
+ LAST_MODIFIED,
+ NULL);
+ }
+
+ if (g_strcmp0 (target_name, "first-created") == 0)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ _("First Created"));
+ dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
+ FIRST_CREATED,
+ dialog->create_date);
+ }
+
+ if (g_strcmp0 (target_name, "last-created") == 0)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
+ _("Last Created"));
+ dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
+ LAST_CREATED,
+ dialog->create_date);
+ }
+
+ g_simple_action_set_state (action, value);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
+
+ update_display_text (dialog);
+}
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+static void
+add_original_file_name_tag (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
+{
+ NautilusBatchRenameDialog *dialog;
+ gint cursor_position;
+ TagData *tag_data;
- target_name = g_variant_get_string (value, NULL);
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
- if (g_strcmp0 (target_name, "name-ascending") == 0) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- _("Original name (Ascending)"));
- dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
- ORIGINAL_ASCENDING,
- NULL);
- }
+ g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
- if (g_strcmp0 (target_name, "name-descending") == 0) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- _("Original name (Descending)"));
- dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
- ORIGINAL_DESCENDING,
- NULL);
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
- if (g_strcmp0 (target_name, "first-modified") == 0) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- _("First Modified"));
- dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
- FIRST_MODIFIED,
- NULL);
- }
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ ORIGINAL_FILE_NAME,
+ g_utf8_strlen (ORIGINAL_FILE_NAME, -1),
+ &cursor_position);
- if (g_strcmp0 (target_name, "last-modified") == 0) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- _("Last Modified"));
- dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
- LAST_MODIFIED,
- NULL);
- }
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- if (g_strcmp0 (target_name, "first-created") == 0) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- _("First Created"));
- dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
- FIRST_CREATED,
- dialog->create_date);
- }
+ gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
- if (g_strcmp0 (target_name, "last-created") == 0) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_order_label),
- _("Last Created"));
- dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
- LAST_CREATED,
- dialog->create_date);
- }
-
- g_simple_action_set_state (action, value);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+}
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
+static void
+disable_action (NautilusBatchRenameDialog *dialog,
+ gchar *action_name)
+{
+ GAction *action;
- update_display_text (dialog);
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ action_name);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
}
static void
-add_original_file_name_tag (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+add_metadata_tag (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
- gint cursor_position;
- TagData *tag_data;
+ NautilusBatchRenameDialog *dialog;
+ const gchar *action_name;
+ gint cursor_position;
+ TagData *tag_data;
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
+ action_name = g_action_get_name (G_ACTION (action));
+ g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
+ if (g_strrstr (action_name, "creation-date"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
+ tag_data->available = TRUE;
tag_data->set = TRUE;
tag_data->just_added = TRUE;
tag_data->position = cursor_position;
gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- ORIGINAL_FILE_NAME,
- g_utf8_strlen (ORIGINAL_FILE_NAME, -1),
+ CREATION_DATE,
+ g_utf8_strlen (CREATION_DATE, -1),
&cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-creation-date-tag");
+ }
+ if (g_strrstr (action_name, "equipment"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ CAMERA_MODEL,
+ g_utf8_strlen (CAMERA_MODEL, -1),
+ &cursor_position);
gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-equipment-tag");
+ }
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
+ if (g_strrstr (action_name, "season"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
-}
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ SEASON_NUMBER,
+ g_utf8_strlen (SEASON_NUMBER, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-season-tag");
+ }
-static void
-disable_action (NautilusBatchRenameDialog *dialog,
- gchar *action_name)
-{
- GAction *action;
+ if (g_strrstr (action_name, "episode"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- action_name);
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
-}
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ EPISODE_NUMBER,
+ g_utf8_strlen (EPISODE_NUMBER, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-episode-tag");
+ }
-static void
-add_metadata_tag (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
-{
- NautilusBatchRenameDialog *dialog;
- const gchar *action_name;
- gint cursor_position;
- TagData *tag_data;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
- action_name = g_action_get_name (G_ACTION (action));
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
- if (g_strrstr (action_name, "creation-date")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- CREATION_DATE,
- g_utf8_strlen (CREATION_DATE, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-creation-date-tag");
- }
-
- if (g_strrstr (action_name, "equipment")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- CAMERA_MODEL,
- g_utf8_strlen (CAMERA_MODEL, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-equipment-tag");
- }
-
- if (g_strrstr (action_name, "season")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- SEASON_NUMBER,
- g_utf8_strlen (SEASON_NUMBER, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-season-tag");
- }
-
- if (g_strrstr (action_name, "episode")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- EPISODE_NUMBER,
- g_utf8_strlen (EPISODE_NUMBER, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-episode-tag");
- }
-
- if (g_strrstr (action_name, "track")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- TRACK_NUMBER,
- g_utf8_strlen (TRACK_NUMBER, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-track-number-tag");
- }
-
- if (g_strrstr (action_name, "artist")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- ARTIST_NAME,
- g_utf8_strlen (ARTIST_NAME, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-artist-name-tag");
- }
-
- if (g_strrstr (action_name, "title")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- TITLE,
- g_utf8_strlen (TITLE, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-title-tag");
- }
-
- if (g_strrstr (action_name, "album")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- ALBUM_NAME,
- g_utf8_strlen (ALBUM_NAME, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-album-name-tag");
- }
+ if (g_strrstr (action_name, "track"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ TRACK_NUMBER,
+ g_utf8_strlen (TRACK_NUMBER, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-track-number-tag");
+ }
+
+ if (g_strrstr (action_name, "artist"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ ARTIST_NAME,
+ g_utf8_strlen (ARTIST_NAME, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-artist-name-tag");
+ }
+
+ if (g_strrstr (action_name, "title"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ TITLE,
+ g_utf8_strlen (TITLE, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-title-tag");
+ }
+
+ if (g_strrstr (action_name, "album"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ ALBUM_NAME,
+ g_utf8_strlen (ALBUM_NAME, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ disable_action (dialog, "add-album-name-tag");
+ }
+
+ gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
}
static void
-add_numbering_tag (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+add_numbering_tag (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
- const gchar *action_name;
- gint cursor_position;
- GAction *add_numbering_action;
- TagData *tag_data;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
- action_name = g_action_get_name (G_ACTION (action));
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
- if (g_strrstr (action_name, "zero")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- NUMBERING,
- g_utf8_strlen (NUMBERING, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- }
-
- if (g_strrstr (action_name, "one")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- NUMBERING0,
- g_utf8_strlen (NUMBERING0, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- }
-
- if (g_strrstr (action_name, "two")) {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- NUMBERING00,
- g_utf8_strlen (NUMBERING00, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- }
-
- add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-zero");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
- add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-one");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
-
- add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-two");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
+ NautilusBatchRenameDialog *dialog;
+ const gchar *action_name;
+ gint cursor_position;
+ GAction *add_numbering_action;
+ TagData *tag_data;
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
-}
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+
+ action_name = g_action_get_name (G_ACTION (action));
+ g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
+
+ if (g_strrstr (action_name, "zero"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ NUMBERING,
+ g_utf8_strlen (NUMBERING, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ }
+
+ if (g_strrstr (action_name, "one"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ NUMBERING0,
+ g_utf8_strlen (NUMBERING0, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ }
+
+ if (g_strrstr (action_name, "two"))
+ {
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
+
+ gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
+ NUMBERING00,
+ g_utf8_strlen (NUMBERING00, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ }
+
+ add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-zero");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
+ add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-one");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
+
+ add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-two");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
-const GActionEntry dialog_entries[] = {
- { "numbering-order-changed", NULL, "s", "'name-ascending'", add_numbering_order },
- { "add-original-file-name-tag", add_original_file_name_tag },
- { "add-numbering-tag-zero", add_numbering_tag },
- { "add-numbering-tag-one", add_numbering_tag },
- { "add-numbering-tag-two", add_numbering_tag },
- { "add-creation-date-tag", add_metadata_tag },
- { "add-equipment-tag", add_metadata_tag },
- { "add-season-tag", add_metadata_tag },
- { "add-episode-tag", add_metadata_tag },
- { "add-video-album-tag", add_metadata_tag },
- { "add-track-number-tag", add_metadata_tag },
- { "add-artist-name-tag", add_metadata_tag },
- { "add-title-tag", add_metadata_tag },
- { "add-album-name-tag", add_metadata_tag },
+ gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
+}
+const GActionEntry dialog_entries[] =
+{
+ { "numbering-order-changed", NULL, "s", "'name-ascending'", add_numbering_order },
+ { "add-original-file-name-tag", add_original_file_name_tag },
+ { "add-numbering-tag-zero", add_numbering_tag },
+ { "add-numbering-tag-one", add_numbering_tag },
+ { "add-numbering-tag-two", add_numbering_tag },
+ { "add-creation-date-tag", add_metadata_tag },
+ { "add-equipment-tag", add_metadata_tag },
+ { "add-season-tag", add_metadata_tag },
+ { "add-episode-tag", add_metadata_tag },
+ { "add-video-album-tag", add_metadata_tag },
+ { "add-track-number-tag", add_metadata_tag },
+ { "add-artist-name-tag", add_metadata_tag },
+ { "add-title-tag", add_metadata_tag },
+ { "add-album-name-tag", add_metadata_tag },
};
static void
@@ -464,366 +481,410 @@ row_selected (GtkListBox *box,
GtkListBoxRow *listbox_row,
gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
- GtkListBoxRow *row;
- gint index;
+ NautilusBatchRenameDialog *dialog;
+ GtkListBoxRow *row;
+ gint index;
- if (!GTK_IS_LIST_BOX_ROW (listbox_row))
- return;
+ if (!GTK_IS_LIST_BOX_ROW (listbox_row))
+ {
+ return;
+ }
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
- index = gtk_list_box_row_get_index (listbox_row);
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+ index = gtk_list_box_row_get_index (listbox_row);
- if (GTK_WIDGET (box) == dialog->original_name_listbox) {
- row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->arrow_listbox), index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->arrow_listbox),
- row);
- row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->result_listbox), index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->result_listbox),
- row);
- }
+ if (GTK_WIDGET (box) == dialog->original_name_listbox)
+ {
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->arrow_listbox), index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->arrow_listbox),
+ row);
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->result_listbox), index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->result_listbox),
+ row);
+ }
- if (GTK_WIDGET (box) == dialog->arrow_listbox) {
- row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->original_name_listbox), index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->original_name_listbox),
- row);
- row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->result_listbox), index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->result_listbox),
- row);
- }
+ if (GTK_WIDGET (box) == dialog->arrow_listbox)
+ {
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->original_name_listbox), index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->original_name_listbox),
+ row);
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->result_listbox), index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->result_listbox),
+ row);
+ }
- if (GTK_WIDGET (box) == dialog->result_listbox) {
- row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->arrow_listbox), index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->arrow_listbox),
- row);
- row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->original_name_listbox), index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->original_name_listbox),
- row);
- }
+ if (GTK_WIDGET (box) == dialog->result_listbox)
+ {
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->arrow_listbox), index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->arrow_listbox),
+ row);
+ row = gtk_list_box_get_row_at_index (GTK_LIST_BOX (dialog->original_name_listbox), index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->original_name_listbox),
+ row);
+ }
}
static gint
compare_tag_position (gconstpointer a,
gconstpointer b)
{
- int *number1 = (int*) a;
- int *number2 = (int*) b;
+ int *number1 = (int *) a;
+ int *number2 = (int *) b;
- return *number1 - *number2;
+ return *number1 - *number2;
}
/* This function splits the entry text into a list of regular text and tags.
* For instance, "[1, 2, 3]Paris[Creation date]" would result in:
* "[1, 2, 3]", "Paris", "[Creation date]" */
-static GList*
+static GList *
split_entry_text (NautilusBatchRenameDialog *dialog,
gchar *entry_text)
{
- GString *normal_text;
- GString *tag;
- GArray *tag_positions;
- gint tags;
- gint i;
- gchar *substring;
- gint tag_end_position;
- GList *result = NULL;
- TagData *tag_data;
-
- tags = 0;
- tag_end_position = 0;
- tag_positions = g_array_new (FALSE, FALSE, sizeof (gint));
+ GString *normal_text;
+ GString *tag;
+ GArray *tag_positions;
+ gint tags;
+ gint i;
+ gchar *substring;
+ gint tag_end_position;
+ GList *result = NULL;
+ TagData *tag_data;
+
+ tags = 0;
+ tag_end_position = 0;
+ tag_positions = g_array_new (FALSE, FALSE, sizeof (gint));
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
+
+ g_array_sort (tag_positions, compare_tag_position);
+
+ for (i = 0; i < tags; i++)
+ {
+ tag = g_string_new ("");
+
+ substring = g_utf8_substring (entry_text, tag_end_position,
+ g_array_index (tag_positions, gint, i));
+ normal_text = g_string_new (substring);
+ g_free (substring);
+
+ if (g_strcmp0 (normal_text->str, ""))
+ {
+ result = g_list_prepend (result, normal_text);
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (ORIGINAL_FILE_NAME, -1);
+ tag = g_string_append (tag, ORIGINAL_FILE_NAME);
+ }
tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (NUMBERING, -1);
+ tag = g_string_append (tag, NUMBERING);
}
tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (NUMBERING0, -1);
+ tag = g_string_append (tag, NUMBERING0);
}
tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (NUMBERING00, -1);
+ tag = g_string_append (tag, NUMBERING00);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (CREATION_DATE, -1);
+ tag = g_string_append (tag, CREATION_DATE);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (CAMERA_MODEL, -1);
+ tag = g_string_append (tag, CAMERA_MODEL);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (SEASON_NUMBER, -1);
+ tag = g_string_append (tag, SEASON_NUMBER);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (EPISODE_NUMBER, -1);
+ tag = g_string_append (tag, EPISODE_NUMBER);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (TRACK_NUMBER, -1);
+ tag = g_string_append (tag, TRACK_NUMBER);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (ARTIST_NAME, -1);
+ tag = g_string_append (tag, ARTIST_NAME);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (TITLE, -1);
+ tag = g_string_append (tag, TITLE);
}
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->set) {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (ALBUM_NAME, -1);
+ tag = g_string_append (tag, ALBUM_NAME);
}
- g_array_sort (tag_positions, compare_tag_position);
-
- for (i = 0; i < tags; i++) {
- tag = g_string_new ("");
-
- substring = g_utf8_substring (entry_text, tag_end_position,
- g_array_index (tag_positions, gint, i));
- normal_text = g_string_new (substring);
- g_free (substring);
+ result = g_list_prepend (result, tag);
+ }
+ normal_text = g_string_new (g_utf8_offset_to_pointer (entry_text, tag_end_position));
- if (g_strcmp0 (normal_text->str, ""))
- result = g_list_prepend (result, normal_text);
+ if (g_strcmp0 (normal_text->str, "") != 0)
+ {
+ result = g_list_prepend (result, normal_text);
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (ORIGINAL_FILE_NAME, -1);
- tag = g_string_append (tag, ORIGINAL_FILE_NAME);
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (NUMBERING, -1);
- tag = g_string_append (tag, NUMBERING);
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (NUMBERING0, -1);
- tag = g_string_append (tag, NUMBERING0);
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (NUMBERING00, -1);
- tag = g_string_append (tag, NUMBERING00);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (CREATION_DATE, -1);
- tag = g_string_append (tag, CREATION_DATE);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (CAMERA_MODEL, -1);
- tag = g_string_append (tag, CAMERA_MODEL);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (SEASON_NUMBER, -1);
- tag = g_string_append (tag, SEASON_NUMBER);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (EPISODE_NUMBER, -1);
- tag = g_string_append (tag, EPISODE_NUMBER);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (TRACK_NUMBER, -1);
- tag = g_string_append (tag, TRACK_NUMBER);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (ARTIST_NAME, -1);
- tag = g_string_append (tag, ARTIST_NAME);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (TITLE, -1);
- tag = g_string_append (tag, TITLE);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position) {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (ALBUM_NAME, -1);
- tag = g_string_append (tag, ALBUM_NAME);
- }
-
- result = g_list_prepend (result, tag);
- }
- normal_text = g_string_new (g_utf8_offset_to_pointer (entry_text, tag_end_position));
+ result = g_list_reverse (result);
- if (g_strcmp0 (normal_text->str, "") != 0)
- result = g_list_prepend (result, normal_text);
-
- result = g_list_reverse (result);
-
- g_array_free (tag_positions, TRUE);
- return result;
+ g_array_free (tag_positions, TRUE);
+ return result;
}
-static GList*
+static GList *
batch_rename_dialog_get_new_names (NautilusBatchRenameDialog *dialog)
{
- GList *result = NULL;
- GList *selection;
- GList *text_chunks;
- g_autofree gchar *entry_text;
- g_autofree gchar *replace_text;
-
- selection = dialog->selection;
- text_chunks = NULL;
-
- if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE)
- entry_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
- else
- entry_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
-
- replace_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->replace_entry)));
-
- if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE) {
- result = batch_rename_dialog_get_new_names_list (dialog->mode,
- selection,
- NULL,
- NULL,
- entry_text,
- replace_text);
- } else {
- text_chunks = split_entry_text (dialog, entry_text);
-
- result = batch_rename_dialog_get_new_names_list (dialog->mode,
- selection,
- text_chunks,
- dialog->selection_metadata,
- entry_text,
- replace_text);
- g_list_free_full (text_chunks, string_free);
- }
-
- result = g_list_reverse (result);
-
- return result;
+ GList *result = NULL;
+ GList *selection;
+ GList *text_chunks;
+ g_autofree gchar *entry_text;
+ g_autofree gchar *replace_text;
+
+ selection = dialog->selection;
+ text_chunks = NULL;
+
+ if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE)
+ {
+ entry_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
+ }
+ else
+ {
+ entry_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
+ }
+
+ replace_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->replace_entry)));
+
+ if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE)
+ {
+ result = batch_rename_dialog_get_new_names_list (dialog->mode,
+ selection,
+ NULL,
+ NULL,
+ entry_text,
+ replace_text);
+ }
+ else
+ {
+ text_chunks = split_entry_text (dialog, entry_text);
+
+ result = batch_rename_dialog_get_new_names_list (dialog->mode,
+ selection,
+ text_chunks,
+ dialog->selection_metadata,
+ entry_text,
+ replace_text);
+ g_list_free_full (text_chunks, string_free);
+ }
+
+ result = g_list_reverse (result);
+
+ return result;
}
static void
begin_batch_rename (NautilusBatchRenameDialog *dialog,
GList *new_names)
{
- GList *new_names_list;
- GList *files;
- GList *files2;
- GList *new_names_list2;
- gchar *file_name;
- gchar *old_file_name;
- GString *new_file_name;
- GString *new_name;
- NautilusFile *file;
-
- /* in the following case:
- * file1 -> file2
- * file2 -> file3
- * file2 must be renamed first, so because of that, the list has to be reordered */
- for (new_names_list = new_names, files = dialog->selection;
- new_names_list != NULL && files != NULL;
- new_names_list = new_names_list->next, files = files->next) {
- old_file_name = nautilus_file_get_name (NAUTILUS_FILE (files->data));
- new_file_name = new_names_list->data;
-
- for (files2 = dialog->selection, new_names_list2 = new_names;
- files2 != NULL && new_names_list2 != NULL;
- files2 = files2->next, new_names_list2 = new_names_list2->next) {
- file_name = nautilus_file_get_name (NAUTILUS_FILE (files2->data));
- if (files2 != files && g_strcmp0 (file_name, new_file_name->str) == 0) {
- file = NAUTILUS_FILE (files2->data);
- new_name = new_names_list2->data;
-
- dialog->selection = g_list_remove_link (dialog->selection, files2);
- new_names = g_list_remove_link (new_names, new_names_list2);
-
- dialog->selection = g_list_prepend (dialog->selection, file);
- new_names = g_list_prepend (new_names, new_name);
-
- g_free (file_name);
-
- break;
- }
-
- g_free (file_name);
- }
+ GList *new_names_list;
+ GList *files;
+ GList *files2;
+ GList *new_names_list2;
+ gchar *file_name;
+ gchar *old_file_name;
+ GString *new_file_name;
+ GString *new_name;
+ NautilusFile *file;
+
+ /* in the following case:
+ * file1 -> file2
+ * file2 -> file3
+ * file2 must be renamed first, so because of that, the list has to be reordered */
+ for (new_names_list = new_names, files = dialog->selection;
+ new_names_list != NULL && files != NULL;
+ new_names_list = new_names_list->next, files = files->next)
+ {
+ old_file_name = nautilus_file_get_name (NAUTILUS_FILE (files->data));
+ new_file_name = new_names_list->data;
+
+ for (files2 = dialog->selection, new_names_list2 = new_names;
+ files2 != NULL && new_names_list2 != NULL;
+ files2 = files2->next, new_names_list2 = new_names_list2->next)
+ {
+ file_name = nautilus_file_get_name (NAUTILUS_FILE (files2->data));
+ if (files2 != files && g_strcmp0 (file_name, new_file_name->str) == 0)
+ {
+ file = NAUTILUS_FILE (files2->data);
+ new_name = new_names_list2->data;
+
+ dialog->selection = g_list_remove_link (dialog->selection, files2);
+ new_names = g_list_remove_link (new_names, new_names_list2);
+
+ dialog->selection = g_list_prepend (dialog->selection, file);
+ new_names = g_list_prepend (new_names, new_name);
+
+ g_free (file_name);
- g_free (old_file_name);
+ break;
+ }
+
+ g_free (file_name);
}
- /* do the actual rename here */
- nautilus_file_batch_rename (dialog->selection, new_names, NULL, NULL);
+ g_free (old_file_name);
+ }
+
+ /* do the actual rename here */
+ nautilus_file_batch_rename (dialog->selection, new_names, NULL, NULL);
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (dialog->window)), NULL);
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (dialog->window)), NULL);
}
static void
-listbox_header_func (GtkListBoxRow *row,
- GtkListBoxRow *before,
- NautilusBatchRenameDialog *dialog)
+listbox_header_func (GtkListBoxRow *row,
+ GtkListBoxRow *before,
+ NautilusBatchRenameDialog *dialog)
{
- gboolean show_separator;
+ gboolean show_separator;
- show_separator = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row),
- "show-separator"));
+ show_separator = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row),
+ "show-separator"));
- if (show_separator)
- {
- GtkWidget *separator;
+ if (show_separator)
+ {
+ GtkWidget *separator;
- separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_widget_show (separator);
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_show (separator);
- gtk_list_box_row_set_header (row, separator);
- }
+ gtk_list_box_row_set_header (row, separator);
+ }
}
/* This is manually done instead of using GtkSizeGroup because of the computational
@@ -831,173 +892,188 @@ listbox_header_func (GtkListBoxRow *row,
static void
update_rows_height (NautilusBatchRenameDialog *dialog)
{
- GList *l;
- gint current_row_natural_height;
- gint maximum_height;
+ GList *l;
+ gint current_row_natural_height;
+ gint maximum_height;
- maximum_height = -1;
+ maximum_height = -1;
- /* check if maximum height has changed */
- for (l = dialog->listbox_labels_new; l != NULL; l = l->next) {
- gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
- NULL,
- &current_row_natural_height);
+ /* check if maximum height has changed */
+ for (l = dialog->listbox_labels_new; l != NULL; l = l->next)
+ {
+ gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
+ NULL,
+ &current_row_natural_height);
- if (current_row_natural_height > maximum_height) {
- maximum_height = current_row_natural_height;
- }
+ if (current_row_natural_height > maximum_height)
+ {
+ maximum_height = current_row_natural_height;
}
+ }
- for (l = dialog->listbox_labels_old; l != NULL; l = l->next) {
- gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
- NULL,
- &current_row_natural_height);
+ for (l = dialog->listbox_labels_old; l != NULL; l = l->next)
+ {
+ gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
+ NULL,
+ &current_row_natural_height);
- if (current_row_natural_height > maximum_height) {
- maximum_height = current_row_natural_height;
- }
+ if (current_row_natural_height > maximum_height)
+ {
+ maximum_height = current_row_natural_height;
}
+ }
- for (l = dialog->listbox_icons; l != NULL; l = l->next) {
- gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
- NULL,
- &current_row_natural_height);
+ for (l = dialog->listbox_icons; l != NULL; l = l->next)
+ {
+ gtk_widget_get_preferred_height (GTK_WIDGET (l->data),
+ NULL,
+ &current_row_natural_height);
- if (current_row_natural_height > maximum_height) {
- maximum_height = current_row_natural_height;
- }
+ if (current_row_natural_height > maximum_height)
+ {
+ maximum_height = current_row_natural_height;
}
+ }
- if (maximum_height != dialog->row_height) {
- dialog->row_height = maximum_height;
+ if (maximum_height != dialog->row_height)
+ {
+ dialog->row_height = maximum_height;
- for (l = dialog->listbox_icons; l != NULL; l = l->next) {
- g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
- }
+ for (l = dialog->listbox_icons; l != NULL; l = l->next)
+ {
+ g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
+ }
- for (l = dialog->listbox_labels_new; l != NULL; l = l->next) {
- g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
- }
+ for (l = dialog->listbox_labels_new; l != NULL; l = l->next)
+ {
+ g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
+ }
- for (l = dialog->listbox_labels_old; l != NULL; l = l->next) {
- g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
- }
+ for (l = dialog->listbox_labels_old; l != NULL; l = l->next)
+ {
+ g_object_set (G_OBJECT (l->data), "height-request", dialog->row_height, NULL);
}
+ }
}
-static GtkWidget*
+static GtkWidget *
create_original_name_row_for_label (NautilusBatchRenameDialog *dialog,
const gchar *old_text,
gboolean show_separator)
{
- GtkWidget *row;
- GtkWidget *label_old;
+ GtkWidget *row;
+ GtkWidget *label_old;
- row = gtk_list_box_row_new ();
+ row = gtk_list_box_row_new ();
- g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
+ g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
- label_old = gtk_label_new (old_text);
- gtk_label_set_xalign (GTK_LABEL (label_old), 0.0);
- gtk_widget_set_hexpand (label_old, TRUE);
- gtk_widget_set_margin_start (label_old, 6);
+ label_old = gtk_label_new (old_text);
+ gtk_label_set_xalign (GTK_LABEL (label_old), 0.0);
+ gtk_widget_set_hexpand (label_old, TRUE);
+ gtk_widget_set_margin_start (label_old, 6);
- gtk_label_set_ellipsize (GTK_LABEL (label_old), PANGO_ELLIPSIZE_END);
+ gtk_label_set_ellipsize (GTK_LABEL (label_old), PANGO_ELLIPSIZE_END);
- dialog->listbox_labels_old = g_list_prepend (dialog->listbox_labels_old, label_old);
+ dialog->listbox_labels_old = g_list_prepend (dialog->listbox_labels_old, label_old);
- gtk_container_add (GTK_CONTAINER (row), label_old);
- gtk_widget_show_all (row);
+ gtk_container_add (GTK_CONTAINER (row), label_old);
+ gtk_widget_show_all (row);
- return row;
+ return row;
}
-static GtkWidget*
+static GtkWidget *
create_result_row_for_label (NautilusBatchRenameDialog *dialog,
const gchar *new_text,
gboolean show_separator)
{
- GtkWidget *row;
- GtkWidget *label_new;
+ GtkWidget *row;
+ GtkWidget *label_new;
- row = gtk_list_box_row_new ();
+ row = gtk_list_box_row_new ();
- g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
+ g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
- label_new = gtk_label_new (new_text);
- gtk_label_set_xalign (GTK_LABEL (label_new), 0.0);
- gtk_widget_set_hexpand (label_new, TRUE);
- gtk_widget_set_margin_start (label_new, 6);
+ label_new = gtk_label_new (new_text);
+ gtk_label_set_xalign (GTK_LABEL (label_new), 0.0);
+ gtk_widget_set_hexpand (label_new, TRUE);
+ gtk_widget_set_margin_start (label_new, 6);
- gtk_label_set_ellipsize (GTK_LABEL (label_new), PANGO_ELLIPSIZE_END);
+ gtk_label_set_ellipsize (GTK_LABEL (label_new), PANGO_ELLIPSIZE_END);
- dialog->listbox_labels_new = g_list_prepend (dialog->listbox_labels_new, label_new);
+ dialog->listbox_labels_new = g_list_prepend (dialog->listbox_labels_new, label_new);
- gtk_container_add (GTK_CONTAINER (row), label_new);
- gtk_widget_show_all (row);
+ gtk_container_add (GTK_CONTAINER (row), label_new);
+ gtk_widget_show_all (row);
- return row;
+ return row;
}
-static GtkWidget*
+static GtkWidget *
create_arrow_row_for_label (NautilusBatchRenameDialog *dialog,
gboolean show_separator)
{
- GtkWidget *row;
- GtkWidget *icon;
+ GtkWidget *row;
+ GtkWidget *icon;
- row = gtk_list_box_row_new ();
+ row = gtk_list_box_row_new ();
- g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
+ g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
- icon = gtk_label_new ("→");
- gtk_label_set_xalign (GTK_LABEL (icon), 1.0);
- gtk_widget_set_hexpand (icon, FALSE);
- gtk_widget_set_margin_start (icon, 6);
+ icon = gtk_label_new ("→");
+ gtk_label_set_xalign (GTK_LABEL (icon), 1.0);
+ gtk_widget_set_hexpand (icon, FALSE);
+ gtk_widget_set_margin_start (icon, 6);
- dialog->listbox_icons = g_list_prepend (dialog->listbox_icons, icon);
+ dialog->listbox_icons = g_list_prepend (dialog->listbox_icons, icon);
- gtk_container_add (GTK_CONTAINER (row), icon);
- gtk_widget_show_all (row);
+ gtk_container_add (GTK_CONTAINER (row), icon);
+ gtk_widget_show_all (row);
- return row;
+ return row;
}
static void
prepare_batch_rename (NautilusBatchRenameDialog *dialog)
{
- GdkCursor *cursor;
- GdkDisplay *display;
-
- /* wait for checking conflicts to finish, to be sure that
- * the rename can actually take place */
- if (dialog->checking_conflicts) {
- dialog->rename_clicked = TRUE;
- return;
- }
-
- if (!gtk_widget_is_sensitive (dialog->rename_button))
- return;
-
- display = gtk_widget_get_display (GTK_WIDGET (dialog->window));
- cursor = gdk_cursor_new_from_name (display, "progress");
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (dialog->window)),
- cursor);
- g_object_unref (cursor);
-
- display = gtk_widget_get_display (GTK_WIDGET (dialog));
- cursor = gdk_cursor_new_from_name (display, "progress");
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (dialog)),
- cursor);
- g_object_unref (cursor);
-
- gtk_widget_hide (GTK_WIDGET (dialog));
- begin_batch_rename (dialog, dialog->new_names);
-
- if (dialog->conflict_cancellable)
- g_cancellable_cancel (dialog->conflict_cancellable);
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ GdkCursor *cursor;
+ GdkDisplay *display;
+
+ /* wait for checking conflicts to finish, to be sure that
+ * the rename can actually take place */
+ if (dialog->checking_conflicts)
+ {
+ dialog->rename_clicked = TRUE;
+ return;
+ }
+
+ if (!gtk_widget_is_sensitive (dialog->rename_button))
+ {
+ return;
+ }
+
+ display = gtk_widget_get_display (GTK_WIDGET (dialog->window));
+ cursor = gdk_cursor_new_from_name (display, "progress");
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (dialog->window)),
+ cursor);
+ g_object_unref (cursor);
+
+ display = gtk_widget_get_display (GTK_WIDGET (dialog));
+ cursor = gdk_cursor_new_from_name (display, "progress");
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (dialog)),
+ cursor);
+ g_object_unref (cursor);
+
+ gtk_widget_hide (GTK_WIDGET (dialog));
+ begin_batch_rename (dialog, dialog->new_names);
+
+ if (dialog->conflict_cancellable)
+ {
+ g_cancellable_cancel (dialog->conflict_cancellable);
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
@@ -1005,281 +1081,320 @@ batch_rename_dialog_on_response (NautilusBatchRenameDialog *dialog,
gint response_id,
gpointer user_data)
{
- if (response_id == GTK_RESPONSE_OK) {
- prepare_batch_rename (dialog);
- } else {
- if (dialog->conflict_cancellable)
- g_cancellable_cancel (dialog->conflict_cancellable);
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ prepare_batch_rename (dialog);
+ }
+ else
+ {
+ if (dialog->conflict_cancellable)
+ {
+ g_cancellable_cancel (dialog->conflict_cancellable);
}
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ }
}
static void
fill_display_listbox (NautilusBatchRenameDialog *dialog)
{
- GtkWidget *row;
- GList *l1;
- GList *l2;
- NautilusFile *file;
- GString *new_name;
- gchar *name;
-
- dialog->original_name_listbox_rows = NULL;
- dialog->arrow_listbox_rows = NULL;
- dialog->result_listbox_rows = NULL;
-
- gtk_size_group_add_widget (dialog->size_group, dialog->result_listbox);
- gtk_size_group_add_widget (dialog->size_group, dialog->original_name_listbox);
-
- for (l1 = dialog->new_names, l2 = dialog->selection; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- file = NAUTILUS_FILE (l2->data);
- new_name = l1->data;
-
- name = nautilus_file_get_name (file);
- row = create_original_name_row_for_label (dialog, name, TRUE);
- gtk_container_add (GTK_CONTAINER (dialog->original_name_listbox), row);
- dialog->original_name_listbox_rows = g_list_prepend (dialog->original_name_listbox_rows,
- row);
-
- row = create_arrow_row_for_label (dialog, TRUE);
- gtk_container_add (GTK_CONTAINER (dialog->arrow_listbox), row);
- dialog->arrow_listbox_rows = g_list_prepend (dialog->arrow_listbox_rows,
+ GtkWidget *row;
+ GList *l1;
+ GList *l2;
+ NautilusFile *file;
+ GString *new_name;
+ gchar *name;
+
+ dialog->original_name_listbox_rows = NULL;
+ dialog->arrow_listbox_rows = NULL;
+ dialog->result_listbox_rows = NULL;
+
+ gtk_size_group_add_widget (dialog->size_group, dialog->result_listbox);
+ gtk_size_group_add_widget (dialog->size_group, dialog->original_name_listbox);
+
+ for (l1 = dialog->new_names, l2 = dialog->selection; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ file = NAUTILUS_FILE (l2->data);
+ new_name = l1->data;
+
+ name = nautilus_file_get_name (file);
+ row = create_original_name_row_for_label (dialog, name, TRUE);
+ gtk_container_add (GTK_CONTAINER (dialog->original_name_listbox), row);
+ dialog->original_name_listbox_rows = g_list_prepend (dialog->original_name_listbox_rows,
row);
- row = create_result_row_for_label (dialog, new_name->str, TRUE);
- gtk_container_add (GTK_CONTAINER (dialog->result_listbox), row);
- dialog->result_listbox_rows = g_list_prepend (dialog->result_listbox_rows,
- row);
-
- g_free (name);
- }
-
- dialog->original_name_listbox_rows = g_list_reverse (dialog->original_name_listbox_rows);
- dialog->arrow_listbox_rows = g_list_reverse (dialog->arrow_listbox_rows);
- dialog->result_listbox_rows = g_list_reverse (dialog->result_listbox_rows);
- dialog->listbox_labels_old = g_list_reverse (dialog->listbox_labels_old);
- dialog->listbox_labels_new = g_list_reverse (dialog->listbox_labels_new);
- dialog->listbox_icons = g_list_reverse (dialog->listbox_icons);
+ row = create_arrow_row_for_label (dialog, TRUE);
+ gtk_container_add (GTK_CONTAINER (dialog->arrow_listbox), row);
+ dialog->arrow_listbox_rows = g_list_prepend (dialog->arrow_listbox_rows,
+ row);
+
+ row = create_result_row_for_label (dialog, new_name->str, TRUE);
+ gtk_container_add (GTK_CONTAINER (dialog->result_listbox), row);
+ dialog->result_listbox_rows = g_list_prepend (dialog->result_listbox_rows,
+ row);
+
+ g_free (name);
+ }
+
+ dialog->original_name_listbox_rows = g_list_reverse (dialog->original_name_listbox_rows);
+ dialog->arrow_listbox_rows = g_list_reverse (dialog->arrow_listbox_rows);
+ dialog->result_listbox_rows = g_list_reverse (dialog->result_listbox_rows);
+ dialog->listbox_labels_old = g_list_reverse (dialog->listbox_labels_old);
+ dialog->listbox_labels_new = g_list_reverse (dialog->listbox_labels_new);
+ dialog->listbox_icons = g_list_reverse (dialog->listbox_icons);
}
static void
select_nth_conflict (NautilusBatchRenameDialog *dialog)
{
- GList *l;
- GString *conflict_file_name;
- GString *display_text;
- GString *new_name;
- gint nth_conflict_index;
- gint nth_conflict;
- gint name_occurences;
- GtkAdjustment *adjustment;
- GtkAllocation allocation;
- ConflictData *conflict_data;
-
- nth_conflict = dialog->selected_conflict;
- l = g_list_nth (dialog->duplicates, nth_conflict);
- conflict_data = l->data;
-
- /* the conflict that has to be selected */
- conflict_file_name = g_string_new (conflict_data->name);
- display_text = g_string_new ("");
-
- nth_conflict_index = conflict_data->index;
-
- l = g_list_nth (dialog->original_name_listbox_rows, nth_conflict_index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->original_name_listbox),
- l->data);
-
- l = g_list_nth (dialog->arrow_listbox_rows, nth_conflict_index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->arrow_listbox),
- l->data);
-
- l = g_list_nth (dialog->result_listbox_rows, nth_conflict_index);
- gtk_list_box_select_row (GTK_LIST_BOX (dialog->result_listbox),
- l->data);
-
- /* scroll to the selected row */
- adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (dialog->scrolled_window));
- gtk_widget_get_allocation (GTK_WIDGET (l->data), &allocation);
- gtk_adjustment_set_value (adjustment, (allocation.height + 1) * nth_conflict_index);
-
- name_occurences = 0;
- for (l = dialog->new_names; l != NULL; l = l->next) {
- new_name = l->data;
- if (g_string_equal (new_name, conflict_file_name))
- name_occurences++;
- }
- if (name_occurences > 1)
- g_string_append_printf (display_text,
- _("\"%s\" would not be a unique new name"),
- conflict_file_name->str);
- else
- g_string_append_printf (display_text,
- _("\"%s\" would conflict with an existing file."),
- conflict_file_name->str);
-
- gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
- display_text->str);
-
- g_string_free (conflict_file_name, TRUE);
+ GList *l;
+ GString *conflict_file_name;
+ GString *display_text;
+ GString *new_name;
+ gint nth_conflict_index;
+ gint nth_conflict;
+ gint name_occurences;
+ GtkAdjustment *adjustment;
+ GtkAllocation allocation;
+ ConflictData *conflict_data;
+
+ nth_conflict = dialog->selected_conflict;
+ l = g_list_nth (dialog->duplicates, nth_conflict);
+ conflict_data = l->data;
+
+ /* the conflict that has to be selected */
+ conflict_file_name = g_string_new (conflict_data->name);
+ display_text = g_string_new ("");
+
+ nth_conflict_index = conflict_data->index;
+
+ l = g_list_nth (dialog->original_name_listbox_rows, nth_conflict_index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->original_name_listbox),
+ l->data);
+
+ l = g_list_nth (dialog->arrow_listbox_rows, nth_conflict_index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->arrow_listbox),
+ l->data);
+
+ l = g_list_nth (dialog->result_listbox_rows, nth_conflict_index);
+ gtk_list_box_select_row (GTK_LIST_BOX (dialog->result_listbox),
+ l->data);
+
+ /* scroll to the selected row */
+ adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (dialog->scrolled_window));
+ gtk_widget_get_allocation (GTK_WIDGET (l->data), &allocation);
+ gtk_adjustment_set_value (adjustment, (allocation.height + 1) * nth_conflict_index);
+
+ name_occurences = 0;
+ for (l = dialog->new_names; l != NULL; l = l->next)
+ {
+ new_name = l->data;
+ if (g_string_equal (new_name, conflict_file_name))
+ {
+ name_occurences++;
+ }
+ }
+ if (name_occurences > 1)
+ {
+ g_string_append_printf (display_text,
+ _("\"%s\" would not be a unique new name"),
+ conflict_file_name->str);
+ }
+ else
+ {
+ g_string_append_printf (display_text,
+ _("\"%s\" would conflict with an existing file."),
+ conflict_file_name->str);
+ }
+
+ gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
+ display_text->str);
+
+ g_string_free (conflict_file_name, TRUE);
}
static void
select_next_conflict_down (NautilusBatchRenameDialog *dialog)
{
- dialog->selected_conflict++;
+ dialog->selected_conflict++;
- if (dialog->selected_conflict == 1)
- gtk_widget_set_sensitive (dialog->conflict_up, TRUE);
+ if (dialog->selected_conflict == 1)
+ {
+ gtk_widget_set_sensitive (dialog->conflict_up, TRUE);
+ }
- if (dialog->selected_conflict == dialog->conflicts_number - 1)
- gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
+ if (dialog->selected_conflict == dialog->conflicts_number - 1)
+ {
+ gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
+ }
- select_nth_conflict (dialog);
+ select_nth_conflict (dialog);
}
static void
select_next_conflict_up (NautilusBatchRenameDialog *dialog)
{
- dialog->selected_conflict--;
+ dialog->selected_conflict--;
- if (dialog->selected_conflict == 0)
- gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
+ if (dialog->selected_conflict == 0)
+ {
+ gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
+ }
- if (dialog->selected_conflict == dialog->conflicts_number - 2)
- gtk_widget_set_sensitive (dialog->conflict_down, TRUE);
+ if (dialog->selected_conflict == dialog->conflicts_number - 2)
+ {
+ gtk_widget_set_sensitive (dialog->conflict_down, TRUE);
+ }
- select_nth_conflict (dialog);
+ select_nth_conflict (dialog);
}
static void
update_conflict_row_background (NautilusBatchRenameDialog *dialog)
{
- GList *l1;
- GList *l2;
- GList *l3;
- GList *duplicates;
- gint index;
- GtkStyleContext *context;
- ConflictData *conflict_data;
-
- index = 0;
-
- duplicates = dialog->duplicates;
-
- for (l1 = dialog->original_name_listbox_rows,
- l2 = dialog->arrow_listbox_rows,
- l3 = dialog->result_listbox_rows;
- l1 != NULL && l2 != NULL && l3 != NULL;
- l1 = l1->next, l2 = l2->next, l3 = l3->next) {
- context = gtk_widget_get_style_context (GTK_WIDGET (l1->data));
-
- if (gtk_style_context_has_class (context, "conflict-row")) {
- gtk_style_context_remove_class (context, "conflict-row");
-
- context = gtk_widget_get_style_context (GTK_WIDGET (l2->data));
- gtk_style_context_remove_class (context, "conflict-row");
+ GList *l1;
+ GList *l2;
+ GList *l3;
+ GList *duplicates;
+ gint index;
+ GtkStyleContext *context;
+ ConflictData *conflict_data;
+
+ index = 0;
+
+ duplicates = dialog->duplicates;
+
+ for (l1 = dialog->original_name_listbox_rows,
+ l2 = dialog->arrow_listbox_rows,
+ l3 = dialog->result_listbox_rows;
+ l1 != NULL && l2 != NULL && l3 != NULL;
+ l1 = l1->next, l2 = l2->next, l3 = l3->next)
+ {
+ context = gtk_widget_get_style_context (GTK_WIDGET (l1->data));
+
+ if (gtk_style_context_has_class (context, "conflict-row"))
+ {
+ gtk_style_context_remove_class (context, "conflict-row");
- context = gtk_widget_get_style_context (GTK_WIDGET (l3->data));
- gtk_style_context_remove_class (context, "conflict-row");
+ context = gtk_widget_get_style_context (GTK_WIDGET (l2->data));
+ gtk_style_context_remove_class (context, "conflict-row");
- }
+ context = gtk_widget_get_style_context (GTK_WIDGET (l3->data));
+ gtk_style_context_remove_class (context, "conflict-row");
+ }
- if (duplicates != NULL) {
- conflict_data = duplicates->data;
- if (conflict_data->index == index) {
- context = gtk_widget_get_style_context (GTK_WIDGET (l1->data));
- gtk_style_context_add_class (context, "conflict-row");
+ if (duplicates != NULL)
+ {
+ conflict_data = duplicates->data;
+ if (conflict_data->index == index)
+ {
+ context = gtk_widget_get_style_context (GTK_WIDGET (l1->data));
+ gtk_style_context_add_class (context, "conflict-row");
- context = gtk_widget_get_style_context (GTK_WIDGET (l2->data));
- gtk_style_context_add_class (context, "conflict-row");
+ context = gtk_widget_get_style_context (GTK_WIDGET (l2->data));
+ gtk_style_context_add_class (context, "conflict-row");
- context = gtk_widget_get_style_context (GTK_WIDGET (l3->data));
- gtk_style_context_add_class (context, "conflict-row");
+ context = gtk_widget_get_style_context (GTK_WIDGET (l3->data));
+ gtk_style_context_add_class (context, "conflict-row");
- duplicates = duplicates->next;
- }
- }
- index++;
+ duplicates = duplicates->next;
+ }
}
+ index++;
+ }
}
static void
update_listbox (NautilusBatchRenameDialog *dialog)
{
- GList *l1;
- GList *l2;
- NautilusFile *file;
- gchar *old_name;
- GtkLabel *label;
- GString *new_name;
+ GList *l1;
+ GList *l2;
+ NautilusFile *file;
+ gchar *old_name;
+ GtkLabel *label;
+ GString *new_name;
- for (l1 = dialog->new_names, l2 = dialog->listbox_labels_new; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- label = GTK_LABEL (l2->data);
- new_name = l1->data;
+ for (l1 = dialog->new_names, l2 = dialog->listbox_labels_new; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ label = GTK_LABEL (l2->data);
+ new_name = l1->data;
- gtk_label_set_label (label, new_name->str);
- }
+ gtk_label_set_label (label, new_name->str);
+ }
- for (l1 = dialog->selection, l2 = dialog->listbox_labels_old; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- label = GTK_LABEL (l2->data);
- file = NAUTILUS_FILE (l1->data);
+ for (l1 = dialog->selection, l2 = dialog->listbox_labels_old; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ label = GTK_LABEL (l2->data);
+ file = NAUTILUS_FILE (l1->data);
- old_name = nautilus_file_get_name (file);
+ old_name = nautilus_file_get_name (file);
- if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT) {
- gtk_label_set_label (label, old_name);
- } else {
- new_name = batch_rename_replace_label_text (old_name,
- gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
- gtk_label_set_markup (GTK_LABEL (label), new_name->str);
-
- g_string_free (new_name, TRUE);
- }
+ if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT)
+ {
+ gtk_label_set_label (label, old_name);
+ }
+ else
+ {
+ new_name = batch_rename_replace_label_text (old_name,
+ gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
+ gtk_label_set_markup (GTK_LABEL (label), new_name->str);
- g_free (old_name);
+ g_string_free (new_name, TRUE);
}
- update_rows_height (dialog);
+ g_free (old_name);
+ }
- /* check if there are name conflicts and display them if they exist */
- if (dialog->duplicates != NULL) {
- update_conflict_row_background (dialog);
+ update_rows_height (dialog);
- gtk_widget_set_sensitive (dialog->rename_button, FALSE);
+ /* check if there are name conflicts and display them if they exist */
+ if (dialog->duplicates != NULL)
+ {
+ update_conflict_row_background (dialog);
- gtk_widget_show (dialog->conflict_box);
+ gtk_widget_set_sensitive (dialog->rename_button, FALSE);
- dialog->selected_conflict = 0;
- dialog->conflicts_number = g_list_length (dialog->duplicates);
+ gtk_widget_show (dialog->conflict_box);
- select_nth_conflict (dialog);
+ dialog->selected_conflict = 0;
+ dialog->conflicts_number = g_list_length (dialog->duplicates);
- gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
+ select_nth_conflict (dialog);
- if (g_list_length (dialog->duplicates) == 1)
- gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
- else
- gtk_widget_set_sensitive (dialog->conflict_down, TRUE);
- } else {
- gtk_widget_hide (dialog->conflict_box);
+ gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
- /* re-enable the rename button if there are no more name conflicts */
- if (dialog->duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button)) {
- update_conflict_row_background (dialog);
- gtk_widget_set_sensitive (dialog->rename_button, TRUE);
- }
+ if (g_list_length (dialog->duplicates) == 1)
+ {
+ gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
}
-
- /* if the rename button was clicked and there's no conflict, then start renaming */
- if (dialog->rename_clicked && dialog->duplicates == NULL) {
- prepare_batch_rename (dialog);
+ else
+ {
+ gtk_widget_set_sensitive (dialog->conflict_down, TRUE);
}
+ }
+ else
+ {
+ gtk_widget_hide (dialog->conflict_box);
- if (dialog->rename_clicked && dialog->duplicates != NULL) {
- dialog->rename_clicked = FALSE;
+ /* re-enable the rename button if there are no more name conflicts */
+ if (dialog->duplicates == NULL && !gtk_widget_is_sensitive (dialog->rename_button))
+ {
+ update_conflict_row_background (dialog);
+ gtk_widget_set_sensitive (dialog->rename_button, TRUE);
}
+ }
+
+ /* if the rename button was clicked and there's no conflict, then start renaming */
+ if (dialog->rename_clicked && dialog->duplicates == NULL)
+ {
+ prepare_batch_rename (dialog);
+ }
+
+ if (dialog->rename_clicked && dialog->duplicates != NULL)
+ {
+ dialog->rename_clicked = FALSE;
+ }
}
@@ -1288,152 +1403,168 @@ check_conflict_for_files (NautilusBatchRenameDialog *dialog,
NautilusDirectory *directory,
GList *files)
{
- gchar *current_directory;
- gchar *parent_uri;
- gchar *name;
- NautilusFile *file;
- GString *new_name;
- GString *file_name;
- GList *l1, *l2;
- GHashTable *directory_files_table;
- GHashTable *new_names_table;
- GHashTable *names_conflicts_table;
- gboolean exists;
- gboolean have_conflict;
- gboolean tag_present;
- gboolean same_parent_directory;
- ConflictData *conflict_data;
-
- current_directory = nautilus_directory_get_uri (directory);
-
- directory_files_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
- new_names_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
- names_conflicts_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
-
- /* names_conflicts_table is used for knowing which names from the list are not unique,
- * so that they can easily be reached when needed */
- for (l1 = dialog->new_names, l2 = dialog->selection;
- l1 != NULL && l2 != NULL;
- l1 = l1->next, l2 = l2->next) {
- new_name = l1->data;
- file = NAUTILUS_FILE (l2->data);
- parent_uri = nautilus_file_get_parent_uri (file);
-
- tag_present = g_hash_table_lookup (new_names_table, new_name->str) != NULL;
- same_parent_directory = g_strcmp0 (parent_uri, current_directory) == 0;
-
- if (same_parent_directory) {
- if (!tag_present) {
- g_hash_table_insert (new_names_table,
- g_strdup (new_name->str),
- nautilus_file_get_parent_uri (file));
- } else {
- g_hash_table_insert (names_conflicts_table,
- g_strdup (new_name->str),
- nautilus_file_get_parent_uri (file));
- }
- }
+ gchar *current_directory;
+ gchar *parent_uri;
+ gchar *name;
+ NautilusFile *file;
+ GString *new_name;
+ GString *file_name;
+ GList *l1, *l2;
+ GHashTable *directory_files_table;
+ GHashTable *new_names_table;
+ GHashTable *names_conflicts_table;
+ gboolean exists;
+ gboolean have_conflict;
+ gboolean tag_present;
+ gboolean same_parent_directory;
+ ConflictData *conflict_data;
+
+ current_directory = nautilus_directory_get_uri (directory);
+
+ directory_files_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+ new_names_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+ names_conflicts_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+
+ /* names_conflicts_table is used for knowing which names from the list are not unique,
+ * so that they can easily be reached when needed */
+ for (l1 = dialog->new_names, l2 = dialog->selection;
+ l1 != NULL && l2 != NULL;
+ l1 = l1->next, l2 = l2->next)
+ {
+ new_name = l1->data;
+ file = NAUTILUS_FILE (l2->data);
+ parent_uri = nautilus_file_get_parent_uri (file);
+
+ tag_present = g_hash_table_lookup (new_names_table, new_name->str) != NULL;
+ same_parent_directory = g_strcmp0 (parent_uri, current_directory) == 0;
+
+ if (same_parent_directory)
+ {
+ if (!tag_present)
+ {
+ g_hash_table_insert (new_names_table,
+ g_strdup (new_name->str),
+ nautilus_file_get_parent_uri (file));
+ }
+ else
+ {
+ g_hash_table_insert (names_conflicts_table,
+ g_strdup (new_name->str),
+ nautilus_file_get_parent_uri (file));
+ }
+ }
+
+ g_free (parent_uri);
+ }
+
+ for (l1 = files; l1 != NULL; l1 = l1->next)
+ {
+ file = NAUTILUS_FILE (l1->data);
+ g_hash_table_insert (directory_files_table,
+ nautilus_file_get_name (file),
+ GINT_TO_POINTER (TRUE));
+ }
+
+ for (l1 = dialog->selection, l2 = dialog->new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ file = NAUTILUS_FILE (l1->data);
+
+ name = nautilus_file_get_name (file);
+ file_name = g_string_new (name);
+ g_free (name);
+
+ parent_uri = nautilus_file_get_parent_uri (file);
+
+ new_name = l2->data;
+
+ have_conflict = FALSE;
+
+ /* check for duplicate only if the parent of the current file is
+ * the current directory and the name of the file has changed */
+ if (g_strcmp0 (parent_uri, current_directory) == 0 &&
+ !g_string_equal (new_name, file_name))
+ {
+ exists = GPOINTER_TO_INT (g_hash_table_lookup (directory_files_table, new_name->str));
- g_free (parent_uri);
- }
+ if (exists == TRUE &&
+ !file_name_conflicts_with_results (dialog->selection, dialog->new_names, new_name, parent_uri))
+ {
+ conflict_data = g_new (ConflictData, 1);
+ conflict_data->name = g_strdup (new_name->str);
+ conflict_data->index = g_list_index (dialog->selection, l1->data);
+ dialog->duplicates = g_list_prepend (dialog->duplicates,
+ conflict_data);
- for (l1 = files; l1 != NULL; l1 = l1->next) {
- file = NAUTILUS_FILE (l1->data);
- g_hash_table_insert (directory_files_table,
- nautilus_file_get_name (file),
- GINT_TO_POINTER (TRUE));
+ have_conflict = TRUE;
+ }
}
+ if (!have_conflict)
+ {
+ tag_present = g_hash_table_lookup (names_conflicts_table, new_name->str) != NULL;
+ same_parent_directory = g_strcmp0 (nautilus_file_get_parent_uri (file), current_directory) == 0;
- for (l1 = dialog->selection, l2 = dialog->new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- file = NAUTILUS_FILE (l1->data);
-
- name = nautilus_file_get_name (file);
- file_name = g_string_new (name);
- g_free (name);
-
- parent_uri = nautilus_file_get_parent_uri (file);
-
- new_name = l2->data;
-
- have_conflict = FALSE;
-
- /* check for duplicate only if the parent of the current file is
- * the current directory and the name of the file has changed */
- if (g_strcmp0 (parent_uri, current_directory) == 0 &&
- !g_string_equal (new_name, file_name)) {
- exists = GPOINTER_TO_INT (g_hash_table_lookup (directory_files_table, new_name->str));
-
- if (exists == TRUE &&
- !file_name_conflicts_with_results (dialog->selection, dialog->new_names, new_name, parent_uri)) {
- conflict_data = g_new (ConflictData, 1);
- conflict_data->name = g_strdup (new_name->str);
- conflict_data->index = g_list_index (dialog->selection, l1->data);
- dialog->duplicates = g_list_prepend (dialog->duplicates,
- conflict_data);
-
- have_conflict = TRUE;
- }
- }
- if (!have_conflict) {
- tag_present = g_hash_table_lookup (names_conflicts_table, new_name->str) != NULL;
- same_parent_directory = g_strcmp0 (nautilus_file_get_parent_uri (file), current_directory) == 0;
-
- if (tag_present && same_parent_directory) {
- conflict_data = g_new (ConflictData, 1);
- conflict_data->name = g_strdup (new_name->str);
- conflict_data->index = g_list_index (dialog->selection, l1->data);
- dialog->duplicates = g_list_prepend (dialog->duplicates,
- conflict_data);
-
- have_conflict = TRUE;
- }
- }
+ if (tag_present && same_parent_directory)
+ {
+ conflict_data = g_new (ConflictData, 1);
+ conflict_data->name = g_strdup (new_name->str);
+ conflict_data->index = g_list_index (dialog->selection, l1->data);
+ dialog->duplicates = g_list_prepend (dialog->duplicates,
+ conflict_data);
- g_string_free (file_name, TRUE);
- g_free (parent_uri);
+ have_conflict = TRUE;
+ }
}
- /* check if this is the last call of the callback. Update
- * the listbox with the conflicts if it is. */
- if (dialog->checked_parents == g_list_length (dialog->distinct_parents) - 1) {
- dialog->duplicates = g_list_reverse (dialog->duplicates);
+ g_string_free (file_name, TRUE);
+ g_free (parent_uri);
+ }
- dialog->checking_conflicts = FALSE;
+ /* check if this is the last call of the callback. Update
+ * the listbox with the conflicts if it is. */
+ if (dialog->checked_parents == g_list_length (dialog->distinct_parents) - 1)
+ {
+ dialog->duplicates = g_list_reverse (dialog->duplicates);
- update_listbox (dialog);
- }
+ dialog->checking_conflicts = FALSE;
- dialog->checked_parents++;
+ update_listbox (dialog);
+ }
- g_free (current_directory);
- g_hash_table_destroy (directory_files_table);
- g_hash_table_destroy (new_names_table);
- g_hash_table_destroy (names_conflicts_table);
+ dialog->checked_parents++;
+
+ g_free (current_directory);
+ g_hash_table_destroy (directory_files_table);
+ g_hash_table_destroy (new_names_table);
+ g_hash_table_destroy (names_conflicts_table);
}
static void
-file_names_list_has_duplicates_callback (GObject *object,
- GAsyncResult *res,
- gpointer user_data)
+file_names_list_has_duplicates_callback (GObject *object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
+ NautilusBatchRenameDialog *dialog;
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
- if (g_cancellable_is_cancelled (dialog->conflict_cancellable))
- return;
+ if (g_cancellable_is_cancelled (dialog->conflict_cancellable))
+ {
+ return;
+ }
- if (dialog->same_parent)
- update_listbox (dialog);
+ if (dialog->same_parent)
+ {
+ update_listbox (dialog);
+ }
}
static void
@@ -1441,9 +1572,9 @@ on_call_when_ready (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
- check_conflict_for_files (NAUTILUS_BATCH_RENAME_DIALOG (callback_data),
- directory,
- files);
+ check_conflict_for_files (NAUTILUS_BATCH_RENAME_DIALOG (callback_data),
+ directory,
+ files);
}
static void
@@ -1452,151 +1583,165 @@ file_names_list_has_duplicates_async_thread (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- NautilusBatchRenameDialog *dialog;
- GList *new_names;
- GList *directory_files;
- GList *l1;
- GList *l2;
- NautilusFile *file;
- GString *file_name;
- GString *new_name;
- NautilusDirectory *parent;
- gboolean have_conflict;
- gboolean hash_table_insertion;
- gchar *name;
- GHashTable *directory_names_table;
- GHashTable *new_names_table;
- GHashTable *names_conflicts_table;
- gint exists;
- ConflictData *conflict_data;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
-
- dialog->duplicates = NULL;
-
- if (g_cancellable_is_cancelled (cancellable))
+ NautilusBatchRenameDialog *dialog;
+ GList *new_names;
+ GList *directory_files;
+ GList *l1;
+ GList *l2;
+ NautilusFile *file;
+ GString *file_name;
+ GString *new_name;
+ NautilusDirectory *parent;
+ gboolean have_conflict;
+ gboolean hash_table_insertion;
+ gchar *name;
+ GHashTable *directory_names_table;
+ GHashTable *new_names_table;
+ GHashTable *names_conflicts_table;
+ gint exists;
+ ConflictData *conflict_data;
+
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
+
+ dialog->duplicates = NULL;
+
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ return;
+ }
+
+ g_return_if_fail (g_list_length (dialog->new_names) == g_list_length (dialog->selection));
+
+ /* If the batch rename is launched in a search, then for each file we have to check for
+ * conflicts with each file in the file's parent directory */
+ if (dialog->distinct_parents != NULL)
+ {
+ for (l1 = dialog->distinct_parents; l1 != NULL; l1 = l1->next)
+ {
+ if (g_cancellable_is_cancelled (cancellable))
+ {
return;
+ }
- g_return_if_fail (g_list_length (dialog->new_names) == g_list_length (dialog->selection));
+ parent = nautilus_directory_get_by_uri (l1->data);
- /* If the batch rename is launched in a search, then for each file we have to check for
- * conflicts with each file in the file's parent directory */
- if (dialog->distinct_parents != NULL) {
- for (l1 = dialog->distinct_parents; l1 != NULL; l1 = l1->next) {
- if (g_cancellable_is_cancelled (cancellable))
- return;
-
- parent = nautilus_directory_get_by_uri (l1->data);
-
- nautilus_directory_call_when_ready (parent,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- TRUE,
- on_call_when_ready,
- dialog);
- }
-
- g_task_return_pointer (task, object, NULL);
- return;
+ nautilus_directory_call_when_ready (parent,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ TRUE,
+ on_call_when_ready,
+ dialog);
}
- new_names = batch_rename_dialog_get_new_names (dialog);
-
- directory_names_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
- new_names_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
- names_conflicts_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
-
- directory_files = nautilus_directory_get_file_list (dialog->directory);
-
- for (l1 = new_names; l1 != NULL; l1 = l1->next) {
- new_name = l1->data;
- hash_table_insertion = g_hash_table_insert (new_names_table,
- g_strdup (new_name->str),
- GINT_TO_POINTER (TRUE));
-
- if (!hash_table_insertion) {
- g_hash_table_insert (names_conflicts_table,
- g_strdup (new_name->str),
- GINT_TO_POINTER (TRUE));
- }
+ g_task_return_pointer (task, object, NULL);
+ return;
+ }
+
+ new_names = batch_rename_dialog_get_new_names (dialog);
+
+ directory_names_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+ new_names_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+ names_conflicts_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+
+ directory_files = nautilus_directory_get_file_list (dialog->directory);
+
+ for (l1 = new_names; l1 != NULL; l1 = l1->next)
+ {
+ new_name = l1->data;
+ hash_table_insertion = g_hash_table_insert (new_names_table,
+ g_strdup (new_name->str),
+ GINT_TO_POINTER (TRUE));
+
+ if (!hash_table_insertion)
+ {
+ g_hash_table_insert (names_conflicts_table,
+ g_strdup (new_name->str),
+ GINT_TO_POINTER (TRUE));
+ }
+ }
+
+ for (l1 = directory_files; l1 != NULL; l1 = l1->next)
+ {
+ file = NAUTILUS_FILE (l1->data);
+ g_hash_table_insert (directory_names_table,
+ nautilus_file_get_name (file),
+ GINT_TO_POINTER (TRUE));
+ }
+
+ for (l1 = new_names, l2 = dialog->selection; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ g_list_free_full (dialog->duplicates, conflict_data_free);
+ break;
}
- for (l1 = directory_files; l1 != NULL; l1 = l1->next) {
- file = NAUTILUS_FILE (l1->data);
- g_hash_table_insert (directory_names_table,
- nautilus_file_get_name (file),
- GINT_TO_POINTER (TRUE));
- }
+ file = NAUTILUS_FILE (l2->data);
+ new_name = l1->data;
- for (l1 = new_names, l2 = dialog->selection; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- if (g_cancellable_is_cancelled (cancellable)) {
- g_list_free_full (dialog->duplicates, conflict_data_free);
- break;
- }
+ have_conflict = FALSE;
- file = NAUTILUS_FILE (l2->data);
- new_name = l1->data;
-
- have_conflict = FALSE;
-
- name = nautilus_file_get_name (file);
- file_name = g_string_new (name);
-
- g_free (name);
-
- /* check for duplicate only if the name has changed */
- if (!g_string_equal (new_name, file_name)) {
- /* check with already existing files */
- exists = GPOINTER_TO_INT (g_hash_table_lookup (directory_names_table, new_name->str));
-
- if (exists == TRUE &&
- !file_name_conflicts_with_results (dialog->selection, new_names, new_name, NULL)) {
- conflict_data = g_new (ConflictData, 1);
- conflict_data->name = g_strdup (new_name->str);
- conflict_data->index = g_list_index (dialog->selection, l2->data);
- dialog->duplicates = g_list_prepend (dialog->duplicates,
- conflict_data);
- have_conflict = TRUE;
- }
-
- /* check with files that will result from the batch rename, unless
- * this file already has a conflict */
- if (!have_conflict) {
- exists = GPOINTER_TO_INT (g_hash_table_lookup (names_conflicts_table, new_name->str));
-
- if (exists == TRUE) {
- conflict_data = g_new (ConflictData, 1);
- conflict_data->name = g_strdup (new_name->str);
- conflict_data->index = g_list_index (dialog->selection, l2->data);
- dialog->duplicates = g_list_prepend (dialog->duplicates,
- conflict_data);
- }
- }
- }
+ name = nautilus_file_get_name (file);
+ file_name = g_string_new (name);
+
+ g_free (name);
- g_string_free (file_name, TRUE);
+ /* check for duplicate only if the name has changed */
+ if (!g_string_equal (new_name, file_name))
+ {
+ /* check with already existing files */
+ exists = GPOINTER_TO_INT (g_hash_table_lookup (directory_names_table, new_name->str));
+
+ if (exists == TRUE &&
+ !file_name_conflicts_with_results (dialog->selection, new_names, new_name, NULL))
+ {
+ conflict_data = g_new (ConflictData, 1);
+ conflict_data->name = g_strdup (new_name->str);
+ conflict_data->index = g_list_index (dialog->selection, l2->data);
+ dialog->duplicates = g_list_prepend (dialog->duplicates,
+ conflict_data);
+ have_conflict = TRUE;
+ }
+
+ /* check with files that will result from the batch rename, unless
+ * this file already has a conflict */
+ if (!have_conflict)
+ {
+ exists = GPOINTER_TO_INT (g_hash_table_lookup (names_conflicts_table, new_name->str));
+
+ if (exists == TRUE)
+ {
+ conflict_data = g_new (ConflictData, 1);
+ conflict_data->name = g_strdup (new_name->str);
+ conflict_data->index = g_list_index (dialog->selection, l2->data);
+ dialog->duplicates = g_list_prepend (dialog->duplicates,
+ conflict_data);
+ }
+ }
}
- g_hash_table_destroy (directory_names_table);
- g_hash_table_destroy (new_names_table);
- g_hash_table_destroy (names_conflicts_table);
- nautilus_file_list_free (directory_files);
- g_list_free_full (new_names, string_free);
+ g_string_free (file_name, TRUE);
+ }
- dialog->duplicates = g_list_reverse (dialog->duplicates);
+ g_hash_table_destroy (directory_names_table);
+ g_hash_table_destroy (new_names_table);
+ g_hash_table_destroy (names_conflicts_table);
+ nautilus_file_list_free (directory_files);
+ g_list_free_full (new_names, string_free);
- dialog->checking_conflicts = FALSE;
+ dialog->duplicates = g_list_reverse (dialog->duplicates);
- g_task_return_pointer (task, object, NULL);
+ dialog->checking_conflicts = FALSE;
+ g_task_return_pointer (task, object, NULL);
}
static void
@@ -1604,318 +1749,403 @@ file_names_list_has_duplicates_async (NautilusBatchRenameDialog *dialog,
GAsyncReadyCallback callback,
gpointer user_data)
{
- if (dialog->checking_conflicts == TRUE)
- g_cancellable_cancel (dialog->conflict_cancellable);
+ if (dialog->checking_conflicts == TRUE)
+ {
+ g_cancellable_cancel (dialog->conflict_cancellable);
+ }
- dialog->conflict_cancellable = g_cancellable_new ();
+ dialog->conflict_cancellable = g_cancellable_new ();
- dialog->checking_conflicts = TRUE;
- dialog->conflicts_task = g_task_new (dialog, dialog->conflict_cancellable, callback, user_data);
+ dialog->checking_conflicts = TRUE;
+ dialog->conflicts_task = g_task_new (dialog, dialog->conflict_cancellable, callback, user_data);
- g_task_run_in_thread (dialog->conflicts_task, file_names_list_has_duplicates_async_thread);
+ g_task_run_in_thread (dialog->conflicts_task, file_names_list_has_duplicates_async_thread);
- g_object_unref (dialog->conflicts_task);
+ g_object_unref (dialog->conflicts_task);
}
static void
update_tags (NautilusBatchRenameDialog *dialog)
{
- TagData *tag_data;
- const gchar *entry_text;
- gint character_difference;
- gint cursor_position;
-
- entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
-
- if (dialog->use_manual_cursor_position) {
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry),
- dialog->cursor_position);
- }
-
- if (dialog->tags_deleted) {
- dialog->tags_deleted = FALSE;
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry),
- g_utf8_strlen (entry_text, -1));
- }
-
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
- character_difference = g_utf8_strlen (entry_text, -1) - dialog->name_entry_characters;
- dialog->name_entry_characters = g_utf8_strlen (entry_text, -1);
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->just_added) {
- tag_data->just_added = FALSE;
- } else {
- if (tag_data->set && cursor_position <= tag_data->position) {
- tag_data->position += character_difference;
- }
+ TagData *tag_data;
+ const gchar *entry_text;
+ gint character_difference;
+ gint cursor_position;
+
+ entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
+
+ if (dialog->use_manual_cursor_position)
+ {
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry),
+ dialog->cursor_position);
+ }
+
+ if (dialog->tags_deleted)
+ {
+ dialog->tags_deleted = FALSE;
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry),
+ g_utf8_strlen (entry_text, -1));
+ }
+
+ g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
+
+ character_difference = g_utf8_strlen (entry_text, -1) - dialog->name_entry_characters;
+ dialog->name_entry_characters = g_utf8_strlen (entry_text, -1);
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
+ if (tag_data->just_added)
+ {
+ tag_data->just_added = FALSE;
+ }
+ else
+ {
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
}
+ }
}
static gboolean
have_unallowed_character (NautilusBatchRenameDialog *dialog)
{
- const gchar *entry_text;
- gboolean have_unallowed_character_slash;
- gboolean have_unallowed_character_dot;
- gboolean have_unallowed_character_dotdot;
+ const gchar *entry_text;
+ gboolean have_unallowed_character_slash;
+ gboolean have_unallowed_character_dot;
+ gboolean have_unallowed_character_dotdot;
- have_unallowed_character_slash = FALSE;
- have_unallowed_character_dot = FALSE;
- have_unallowed_character_dotdot = FALSE;
+ have_unallowed_character_slash = FALSE;
+ have_unallowed_character_dot = FALSE;
+ have_unallowed_character_dotdot = FALSE;
- if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT) {
- entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
-
- } else {
- entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->replace_entry));
- }
-
- if (strstr (entry_text, "/") != NULL) {
- have_unallowed_character_slash = TRUE;
- }
-
- if (g_strcmp0 (entry_text, ".") == 0) {
- have_unallowed_character_dot = TRUE;
- }
-
- if (g_strcmp0 (entry_text, "..") == 0) {
- have_unallowed_character_dotdot = TRUE;
- }
-
- if (have_unallowed_character_slash) {
- gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
- "\"/\" is an unallowed character");
- }
+ if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT)
+ {
+ entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
+ }
+ else
+ {
+ entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->replace_entry));
+ }
+
+ if (strstr (entry_text, "/") != NULL)
+ {
+ have_unallowed_character_slash = TRUE;
+ }
+
+ if (g_strcmp0 (entry_text, ".") == 0)
+ {
+ have_unallowed_character_dot = TRUE;
+ }
+
+ if (g_strcmp0 (entry_text, "..") == 0)
+ {
+ have_unallowed_character_dotdot = TRUE;
+ }
+
+ if (have_unallowed_character_slash)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
+ "\"/\" is an unallowed character");
+ }
- if (have_unallowed_character_dot) {
- gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
- "\".\" is an unallowed file name");
- }
+ if (have_unallowed_character_dot)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
+ "\".\" is an unallowed file name");
+ }
- if (have_unallowed_character_dotdot) {
- gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
- "\"..\" is an unallowed file name");
- }
+ if (have_unallowed_character_dotdot)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->conflict_label),
+ "\"..\" is an unallowed file name");
+ }
- if (have_unallowed_character_slash || have_unallowed_character_dot || have_unallowed_character_dotdot) {
- gtk_widget_set_sensitive (dialog->rename_button, FALSE);
- gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
- gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
+ if (have_unallowed_character_slash || have_unallowed_character_dot || have_unallowed_character_dotdot)
+ {
+ gtk_widget_set_sensitive (dialog->rename_button, FALSE);
+ gtk_widget_set_sensitive (dialog->conflict_down, FALSE);
+ gtk_widget_set_sensitive (dialog->conflict_up, FALSE);
- gtk_widget_show (dialog->conflict_box);
+ gtk_widget_show (dialog->conflict_box);
- return TRUE;
- } else {
- gtk_widget_hide (dialog->conflict_box);
+ return TRUE;
+ }
+ else
+ {
+ gtk_widget_hide (dialog->conflict_box);
- return FALSE;
- }
+ return FALSE;
+ }
}
static void
update_display_text (NautilusBatchRenameDialog *dialog)
{
- TagData *tag_data;
- TagData *tag_data0;
- TagData *tag_data00;
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- tag_data0 = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- tag_data00 = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
-
- if (dialog->conflict_cancellable != NULL)
- g_cancellable_cancel (dialog->conflict_cancellable);
-
- if(dialog->selection == NULL)
- return;
-
- if (dialog->duplicates != NULL) {
- g_list_free_full (dialog->duplicates, conflict_data_free);
- dialog->duplicates = NULL;
- }
-
- if (have_unallowed_character (dialog))
- return;
-
- update_tags (dialog);
-
- if (dialog->new_names != NULL)
- g_list_free_full (dialog->new_names, string_free);
+ TagData *tag_data;
+ TagData *tag_data0;
+ TagData *tag_data00;
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
+ tag_data0 = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
+ tag_data00 = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
+
+ if (dialog->conflict_cancellable != NULL)
+ {
+ g_cancellable_cancel (dialog->conflict_cancellable);
+ }
+
+ if(dialog->selection == NULL)
+ {
+ return;
+ }
+
+ if (dialog->duplicates != NULL)
+ {
+ g_list_free_full (dialog->duplicates, conflict_data_free);
+ dialog->duplicates = NULL;
+ }
- if (!tag_data->set && !tag_data0->set && !tag_data00->set) {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_label), "");
- gtk_widget_hide (dialog->numbering_order_button);
- } else {
- gtk_label_set_label (GTK_LABEL (dialog->numbering_label), _("Automatic Numbering Order"));
- gtk_widget_show (dialog->numbering_order_button);
- }
+ if (have_unallowed_character (dialog))
+ {
+ return;
+ }
- dialog->new_names = batch_rename_dialog_get_new_names (dialog);
- dialog->checked_parents = 0;
+ update_tags (dialog);
- file_names_list_has_duplicates_async (dialog,
- file_names_list_has_duplicates_callback,
- NULL);
+ if (dialog->new_names != NULL)
+ {
+ g_list_free_full (dialog->new_names, string_free);
+ }
+
+ if (!tag_data->set && !tag_data0->set && !tag_data00->set)
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_label), "");
+ gtk_widget_hide (dialog->numbering_order_button);
+ }
+ else
+ {
+ gtk_label_set_label (GTK_LABEL (dialog->numbering_label), _("Automatic Numbering Order"));
+ gtk_widget_show (dialog->numbering_order_button);
+ }
+
+ dialog->new_names = batch_rename_dialog_get_new_names (dialog);
+ dialog->checked_parents = 0;
+
+ file_names_list_has_duplicates_async (dialog,
+ file_names_list_has_duplicates_callback,
+ NULL);
}
static void
file_names_widget_entry_on_changed (NautilusBatchRenameDialog *dialog)
{
- update_display_text (dialog);
+ update_display_text (dialog);
}
static void
batch_rename_dialog_mode_changed (NautilusBatchRenameDialog *dialog)
{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->format_mode_button))) {
- gtk_stack_set_visible_child_name (GTK_STACK (dialog->mode_stack), "format");
-
- dialog->mode = NAUTILUS_BATCH_RENAME_DIALOG_FORMAT;
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->format_mode_button)))
+ {
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->mode_stack), "format");
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
+ dialog->mode = NAUTILUS_BATCH_RENAME_DIALOG_FORMAT;
- } else {
- gtk_stack_set_visible_child_name (GTK_STACK (dialog->mode_stack), "replace");
+ gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
+ }
+ else
+ {
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->mode_stack), "replace");
- dialog->mode = NAUTILUS_BATCH_RENAME_DIALOG_REPLACE;
+ dialog->mode = NAUTILUS_BATCH_RENAME_DIALOG_REPLACE;
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->find_entry));
- }
+ gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->find_entry));
+ }
- update_display_text (dialog);
+ update_display_text (dialog);
}
static void
add_button_clicked (NautilusBatchRenameDialog *dialog)
{
- if (gtk_widget_is_visible (dialog->add_popover))
- gtk_widget_set_visible (dialog->add_popover, FALSE);
- else
- gtk_widget_set_visible (dialog->add_popover, TRUE);
+ if (gtk_widget_is_visible (dialog->add_popover))
+ {
+ gtk_widget_set_visible (dialog->add_popover, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_visible (dialog->add_popover, TRUE);
+ }
}
static void
add_popover_closed (NautilusBatchRenameDialog *dialog)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->add_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->add_button), FALSE);
}
static void
numbering_order_button_clicked (NautilusBatchRenameDialog *dialog)
{
- if (gtk_widget_is_visible (dialog->numbering_order_popover))
- gtk_widget_set_visible (dialog->numbering_order_popover, FALSE);
- else
- gtk_widget_set_visible (dialog->numbering_order_popover, TRUE);
+ if (gtk_widget_is_visible (dialog->numbering_order_popover))
+ {
+ gtk_widget_set_visible (dialog->numbering_order_popover, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_visible (dialog->numbering_order_popover, TRUE);
+ }
}
static void
numbering_order_popover_closed (NautilusBatchRenameDialog *dialog)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
}
void
@@ -1923,142 +2153,176 @@ nautilus_batch_rename_dialog_query_finished (NautilusBatchRenameDialog *dialog,
GHashTable *hash_table,
GList *selection_metadata)
{
- GMenuItem *first_created;
- GMenuItem *last_created;
- FileMetadata *metadata;
- TagData *tag_data;
-
- /* for files with no metadata */
- if (hash_table != NULL && g_hash_table_size (hash_table) == 0) {
- g_hash_table_destroy (hash_table);
-
- hash_table = NULL;
- }
-
- if (hash_table == NULL)
- dialog->create_date = NULL;
- else
- dialog->create_date = hash_table;
-
- if (dialog->create_date != NULL) {
- first_created = g_menu_item_new ("First Created",
- "dialog.numbering-order-changed('first-created')");
-
- g_menu_append_item (dialog->numbering_order_menu, first_created);
-
- last_created = g_menu_item_new ("Last Created",
- "dialog.numbering-order-changed('last-created')");
-
- g_menu_append_item (dialog->numbering_order_menu, last_created);
-
- }
-
- dialog->selection_metadata = selection_metadata;
- metadata = selection_metadata->data;
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (metadata->creation_date == NULL || g_strcmp0 (metadata->creation_date->str, "") == 0) {
- disable_action (dialog, "add-creation-date-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ GMenuItem *first_created;
+ GMenuItem *last_created;
+ FileMetadata *metadata;
+ TagData *tag_data;
+
+ /* for files with no metadata */
+ if (hash_table != NULL && g_hash_table_size (hash_table) == 0)
+ {
+ g_hash_table_destroy (hash_table);
+
+ hash_table = NULL;
+ }
+
+ if (hash_table == NULL)
+ {
+ dialog->create_date = NULL;
+ }
+ else
+ {
+ dialog->create_date = hash_table;
+ }
+
+ if (dialog->create_date != NULL)
+ {
+ first_created = g_menu_item_new ("First Created",
+ "dialog.numbering-order-changed('first-created')");
+
+ g_menu_append_item (dialog->numbering_order_menu, first_created);
+
+ last_created = g_menu_item_new ("Last Created",
+ "dialog.numbering-order-changed('last-created')");
+
+ g_menu_append_item (dialog->numbering_order_menu, last_created);
+ }
+
+ dialog->selection_metadata = selection_metadata;
+ metadata = selection_metadata->data;
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
+ if (metadata->creation_date == NULL || g_strcmp0 (metadata->creation_date->str, "") == 0)
+ {
+ disable_action (dialog, "add-creation-date-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (metadata->equipment == NULL || g_strcmp0 (metadata->equipment->str, "") == 0) {
- disable_action (dialog, "add-equipment-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
+ if (metadata->equipment == NULL || g_strcmp0 (metadata->equipment->str, "") == 0)
+ {
+ disable_action (dialog, "add-equipment-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (metadata->season == NULL || g_strcmp0 (metadata->season->str, "") == 0) {
- disable_action (dialog, "add-season-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
+ if (metadata->season == NULL || g_strcmp0 (metadata->season->str, "") == 0)
+ {
+ disable_action (dialog, "add-season-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (metadata->episode_number == NULL || g_strcmp0 (metadata->episode_number->str, "") == 0) {
- disable_action (dialog, "add-episode-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
+ if (metadata->episode_number == NULL || g_strcmp0 (metadata->episode_number->str, "") == 0)
+ {
+ disable_action (dialog, "add-episode-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (metadata->track_number == NULL || g_strcmp0 (metadata->track_number->str, "") == 0) {
- disable_action (dialog, "add-track-number-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
+ if (metadata->track_number == NULL || g_strcmp0 (metadata->track_number->str, "") == 0)
+ {
+ disable_action (dialog, "add-track-number-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (metadata->artist_name == NULL || g_strcmp0 (metadata->artist_name->str, "") == 0) {
- disable_action (dialog, "add-artist-name-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
+ if (metadata->artist_name == NULL || g_strcmp0 (metadata->artist_name->str, "") == 0)
+ {
+ disable_action (dialog, "add-artist-name-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (metadata->title == NULL || g_strcmp0 (metadata->title->str, "") == 0) {
- disable_action (dialog, "add-title-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
+ if (metadata->title == NULL || g_strcmp0 (metadata->title->str, "") == 0)
+ {
+ disable_action (dialog, "add-title-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (metadata->album_name == NULL || g_strcmp0 (metadata->album_name->str, "") == 0) {
- disable_action (dialog, "add-album-name-tag");
- tag_data->available = FALSE;
- } else {
- tag_data->set = FALSE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
+ if (metadata->album_name == NULL || g_strcmp0 (metadata->album_name->str, "") == 0)
+ {
+ disable_action (dialog, "add-album-name-tag");
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
}
static void
update_row_shadowing (GtkWidget *row,
gboolean shown)
{
- GtkStyleContext *context;
- GtkStateFlags flags;
-
- if (!GTK_IS_LIST_BOX_ROW (row))
- return;
-
- context = gtk_widget_get_style_context (row);
- flags = gtk_style_context_get_state (context);
-
- if (shown)
- flags |= GTK_STATE_PRELIGHT;
- else
- flags &= ~GTK_STATE_PRELIGHT;
-
- gtk_style_context_set_state (context, flags);
-
+ GtkStyleContext *context;
+ GtkStateFlags flags;
+
+ if (!GTK_IS_LIST_BOX_ROW (row))
+ {
+ return;
+ }
+
+ context = gtk_widget_get_style_context (row);
+ flags = gtk_style_context_get_state (context);
+
+ if (shown)
+ {
+ flags |= GTK_STATE_PRELIGHT;
+ }
+ else
+ {
+ flags &= ~GTK_STATE_PRELIGHT;
+ }
+
+ gtk_style_context_set_state (context, flags);
}
static gboolean
on_leave_event (GtkWidget *widget,
- GdkEventMotion *event,
- gpointer user_data)
+ GdkEventMotion *event,
+ gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
+ NautilusBatchRenameDialog *dialog;
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
- update_row_shadowing (dialog->preselected_row1, FALSE);
- update_row_shadowing (dialog->preselected_row2, FALSE);
+ update_row_shadowing (dialog->preselected_row1, FALSE);
+ update_row_shadowing (dialog->preselected_row2, FALSE);
- dialog->preselected_row1 = NULL;
- dialog->preselected_row2 = NULL;
+ dialog->preselected_row1 = NULL;
+ dialog->preselected_row2 = NULL;
- return FALSE;
+ return FALSE;
}
static gboolean
@@ -2066,76 +2330,79 @@ on_motion (GtkWidget *widget,
GdkEventMotion *event,
gpointer user_data)
{
- GtkListBoxRow *row;
- NautilusBatchRenameDialog *dialog;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
- if (dialog->preselected_row1 && dialog->preselected_row2) {
- update_row_shadowing (dialog->preselected_row1, FALSE);
- update_row_shadowing (dialog->preselected_row2, FALSE);
- }
-
- if (widget == dialog->result_listbox) {
- row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->original_name_listbox), event->y);
- update_row_shadowing (GTK_WIDGET (row), TRUE);
- dialog->preselected_row1 = GTK_WIDGET (row);
-
- row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->arrow_listbox), event->y);
- update_row_shadowing (GTK_WIDGET (row), TRUE);
- dialog->preselected_row2 = GTK_WIDGET (row);
+ GtkListBoxRow *row;
+ NautilusBatchRenameDialog *dialog;
- }
-
- if (widget == dialog->arrow_listbox) {
- row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->original_name_listbox), event->y);
- update_row_shadowing (GTK_WIDGET (row), TRUE);
- dialog->preselected_row1 = GTK_WIDGET (row);
-
- row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->result_listbox), event->y);
- update_row_shadowing (GTK_WIDGET (row), TRUE);
- dialog->preselected_row2 = GTK_WIDGET (row);
- }
-
- if (widget == dialog->original_name_listbox) {
- row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->result_listbox), event->y);
- update_row_shadowing (GTK_WIDGET (row), TRUE);
- dialog->preselected_row1 = GTK_WIDGET (row);
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
- row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->arrow_listbox), event->y);
- update_row_shadowing (GTK_WIDGET (row), TRUE);
- dialog->preselected_row2 = GTK_WIDGET (row);
- }
-
- return FALSE;
+ if (dialog->preselected_row1 && dialog->preselected_row2)
+ {
+ update_row_shadowing (dialog->preselected_row1, FALSE);
+ update_row_shadowing (dialog->preselected_row2, FALSE);
+ }
+
+ if (widget == dialog->result_listbox)
+ {
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->original_name_listbox), event->y);
+ update_row_shadowing (GTK_WIDGET (row), TRUE);
+ dialog->preselected_row1 = GTK_WIDGET (row);
+
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->arrow_listbox), event->y);
+ update_row_shadowing (GTK_WIDGET (row), TRUE);
+ dialog->preselected_row2 = GTK_WIDGET (row);
+ }
+
+ if (widget == dialog->arrow_listbox)
+ {
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->original_name_listbox), event->y);
+ update_row_shadowing (GTK_WIDGET (row), TRUE);
+ dialog->preselected_row1 = GTK_WIDGET (row);
+
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->result_listbox), event->y);
+ update_row_shadowing (GTK_WIDGET (row), TRUE);
+ dialog->preselected_row2 = GTK_WIDGET (row);
+ }
+
+ if (widget == dialog->original_name_listbox)
+ {
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->result_listbox), event->y);
+ update_row_shadowing (GTK_WIDGET (row), TRUE);
+ dialog->preselected_row1 = GTK_WIDGET (row);
+
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (dialog->arrow_listbox), event->y);
+ update_row_shadowing (GTK_WIDGET (row), TRUE);
+ dialog->preselected_row2 = GTK_WIDGET (row);
+ }
+
+ return FALSE;
}
static void
nautilus_batch_rename_dialog_initialize_actions (NautilusBatchRenameDialog *dialog)
{
- GAction *action;
+ GAction *action;
- dialog->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
+ dialog->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
- g_action_map_add_action_entries (G_ACTION_MAP (dialog->action_group),
- dialog_entries,
- G_N_ELEMENTS (dialog_entries),
- dialog);
- gtk_widget_insert_action_group (GTK_WIDGET (dialog),
- "dialog",
- G_ACTION_GROUP (dialog->action_group));
+ g_action_map_add_action_entries (G_ACTION_MAP (dialog->action_group),
+ dialog_entries,
+ G_N_ELEMENTS (dialog_entries),
+ dialog);
+ gtk_widget_insert_action_group (GTK_WIDGET (dialog),
+ "dialog",
+ G_ACTION_GROUP (dialog->action_group));
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-original-file-name-tag");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-original-file-name-tag");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
- check_metadata_for_selection (dialog, dialog->selection);
+ check_metadata_for_selection (dialog, dialog->selection);
}
static void
file_names_widget_on_activate (NautilusBatchRenameDialog *dialog)
{
- prepare_batch_rename (dialog);
+ prepare_batch_rename (dialog);
}
static gboolean
@@ -2145,83 +2412,92 @@ remove_tag (NautilusBatchRenameDialog *dialog,
gint keyval,
gboolean is_modifier)
{
- TagData *tag_data;
- gint cursor_position;
- GString *new_entry_text;
- GString *entry_text;
- gboolean delete_tag;
- GAction *action;
-
- delete_tag = FALSE;
+ TagData *tag_data;
+ gint cursor_position;
+ GString *new_entry_text;
+ GString *entry_text;
+ gboolean delete_tag;
+ GAction *action;
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
+ delete_tag = FALSE;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
+ g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
- entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
- if (!tag_data->set)
- return FALSE;
+ entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
- if (keyval == GDK_KEY_BackSpace) {
- if (cursor_position > tag_data->position &&
- cursor_position <= tag_data->position + g_utf8_strlen (tag_name, -1)) {
- delete_tag = TRUE;
- }
- }
+ if (!tag_data->set)
+ {
+ return FALSE;
+ }
- if (keyval == GDK_KEY_Delete) {
- if (cursor_position >= tag_data->position &&
- cursor_position < tag_data->position + g_utf8_strlen (tag_name, -1)) {
- delete_tag = TRUE;
- }
+ if (keyval == GDK_KEY_BackSpace)
+ {
+ if (cursor_position > tag_data->position &&
+ cursor_position <= tag_data->position + g_utf8_strlen (tag_name, -1))
+ {
+ delete_tag = TRUE;
}
+ }
- if (!is_modifier &&
- keyval != GDK_KEY_Left &&
- keyval != GDK_KEY_Right &&
- keyval != GDK_KEY_Delete &&
- keyval != GDK_KEY_Return &&
- keyval != GDK_KEY_Escape &&
- keyval != GDK_KEY_Tab &&
- keyval != GDK_KEY_End &&
- keyval != GDK_KEY_Home) {
- if (cursor_position > tag_data->position &&
- cursor_position < tag_data->position + g_utf8_strlen (tag_name, -1)) {
- delete_tag = TRUE;
- }
+ if (keyval == GDK_KEY_Delete)
+ {
+ if (cursor_position >= tag_data->position &&
+ cursor_position < tag_data->position + g_utf8_strlen (tag_name, -1))
+ {
+ delete_tag = TRUE;
+ }
+ }
+
+ if (!is_modifier &&
+ keyval != GDK_KEY_Left &&
+ keyval != GDK_KEY_Right &&
+ keyval != GDK_KEY_Delete &&
+ keyval != GDK_KEY_Return &&
+ keyval != GDK_KEY_Escape &&
+ keyval != GDK_KEY_Tab &&
+ keyval != GDK_KEY_End &&
+ keyval != GDK_KEY_Home)
+ {
+ if (cursor_position > tag_data->position &&
+ cursor_position < tag_data->position + g_utf8_strlen (tag_name, -1))
+ {
+ delete_tag = TRUE;
}
+ }
- if (delete_tag) {
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- action_name);
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ if (delete_tag)
+ {
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ action_name);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- new_entry_text = g_string_new ("");
- new_entry_text = g_string_append_len (new_entry_text,
- entry_text->str,
- tag_data->position);
- new_entry_text = g_string_append (new_entry_text,
- g_utf8_offset_to_pointer (entry_text->str,
- tag_data->position + g_utf8_strlen (tag_name, -1)));
+ new_entry_text = g_string_new ("");
+ new_entry_text = g_string_append_len (new_entry_text,
+ entry_text->str,
+ tag_data->position);
+ new_entry_text = g_string_append (new_entry_text,
+ g_utf8_offset_to_pointer (entry_text->str,
+ tag_data->position + g_utf8_strlen (tag_name, -1)));
- tag_data->set = FALSE;
- dialog->cursor_position = tag_data->position;
- dialog->use_manual_cursor_position = TRUE;
- gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), new_entry_text->str);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), tag_data->position);
- dialog->use_manual_cursor_position = FALSE;
+ tag_data->set = FALSE;
+ dialog->cursor_position = tag_data->position;
+ dialog->use_manual_cursor_position = TRUE;
+ gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), new_entry_text->str);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), tag_data->position);
+ dialog->use_manual_cursor_position = FALSE;
- g_string_free (new_entry_text, TRUE);
- g_string_free (entry_text, TRUE);
+ g_string_free (new_entry_text, TRUE);
+ g_string_free (entry_text, TRUE);
- return TRUE;
- }
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
-static GString*
+static GString *
remove_tag_selection (NautilusBatchRenameDialog *dialog,
GString *old_entry_text,
gchar *action_name,
@@ -2229,34 +2505,37 @@ remove_tag_selection (NautilusBatchRenameDialog *dialog,
gint start,
gint end)
{
- TagData *tag_data;
- GAction *action;
- GString *new_entry_text;
-
- new_entry_text = NULL;
+ TagData *tag_data;
+ GAction *action;
+ GString *new_entry_text;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
+ new_entry_text = NULL;
- if (tag_data->set && tag_data->original_position < end &&
- tag_data->original_position + g_utf8_strlen (tag_name, -1) > start) {
- new_entry_text = g_string_new ("");
- new_entry_text = g_string_append_len (new_entry_text,
- old_entry_text->str,
- tag_data->new_position);
- new_entry_text = g_string_append (new_entry_text,
- g_utf8_offset_to_pointer (old_entry_text->str,
- tag_data->new_position + g_utf8_strlen (tag_name, -1)));
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
- tag_data->set = FALSE;
+ if (tag_data->set && tag_data->original_position < end &&
+ tag_data->original_position + g_utf8_strlen (tag_name, -1) > start)
+ {
+ new_entry_text = g_string_new ("");
+ new_entry_text = g_string_append_len (new_entry_text,
+ old_entry_text->str,
+ tag_data->new_position);
+ new_entry_text = g_string_append (new_entry_text,
+ g_utf8_offset_to_pointer (old_entry_text->str,
+ tag_data->new_position + g_utf8_strlen (tag_name, -1)));
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- action_name);
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- }
+ tag_data->set = FALSE;
- if (new_entry_text == NULL)
- return g_string_new (old_entry_text->str);
- return new_entry_text;
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ action_name);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ }
+
+ if (new_entry_text == NULL)
+ {
+ return g_string_new (old_entry_text->str);
+ }
+ return new_entry_text;
}
static void
@@ -2264,756 +2543,859 @@ update_tag_position (NautilusBatchRenameDialog *dialog,
gchar *tag_name,
GString *new_entry_text)
{
- TagData *tag_data;
+ TagData *tag_data;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
- if (tag_data->set) {
- tag_data->original_position = tag_data->position;
- tag_data->new_position = g_utf8_pointer_to_offset(new_entry_text->str,
- g_strrstr (new_entry_text->str, tag_name));
- }
+ if (tag_data->set)
+ {
+ tag_data->original_position = tag_data->position;
+ tag_data->new_position = g_utf8_pointer_to_offset (new_entry_text->str,
+ g_strrstr (new_entry_text->str, tag_name));
+ }
}
static gboolean
-on_key_press_event (GtkWidget *widget,
- GdkEventKey *event,
- gpointer user_data)
+on_key_press_event (GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
- gint keyval;
- GdkEvent *gdk_event;
- GString *old_entry_text;
- GString *new_entry_text;
- gboolean entry_has_selection;
- gint start;
- gint end;
- gboolean tag_removed = FALSE;
- TagData *tag_data;
- gint minimum_tag_position;
- GAction *action;
-
- gdk_event = (GdkEvent *) event;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
- keyval = event->keyval;
-
- entry_has_selection = (gtk_editable_get_selection_bounds (GTK_EDITABLE (dialog->name_entry),
- &start,
- &end));
-
- if (event->state & GDK_CONTROL_MASK)
- return GDK_EVENT_PROPAGATE;
-
- if (entry_has_selection &&
- ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) ||
- (!gdk_event->key.is_modifier &&
- keyval != GDK_KEY_Left &&
- keyval != GDK_KEY_Right &&
- keyval != GDK_KEY_Return &&
- keyval != GDK_KEY_Escape &&
- keyval != GDK_KEY_Tab &&
- keyval != GDK_KEY_End &&
- keyval != GDK_KEY_Home))) {
- old_entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
-
- minimum_tag_position = G_MAXINT;
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->set) {
- update_tag_position (dialog, ORIGINAL_FILE_NAME, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-original-file-name-tag",
- ORIGINAL_FILE_NAME,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ NautilusBatchRenameDialog *dialog;
+ gint keyval;
+ GdkEvent *gdk_event;
+ GString *old_entry_text;
+ GString *new_entry_text;
+ gboolean entry_has_selection;
+ gint start;
+ gint end;
+ gboolean tag_removed = FALSE;
+ TagData *tag_data;
+ gint minimum_tag_position;
+ GAction *action;
+
+ gdk_event = (GdkEvent *) event;
+
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+
+ keyval = event->keyval;
+
+ entry_has_selection = (gtk_editable_get_selection_bounds (GTK_EDITABLE (dialog->name_entry),
+ &start,
+ &end));
+
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ return GDK_EVENT_PROPAGATE;
+ }
+
+ if (entry_has_selection &&
+ ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) ||
+ (!gdk_event->key.is_modifier &&
+ keyval != GDK_KEY_Left &&
+ keyval != GDK_KEY_Right &&
+ keyval != GDK_KEY_Return &&
+ keyval != GDK_KEY_Escape &&
+ keyval != GDK_KEY_Tab &&
+ keyval != GDK_KEY_End &&
+ keyval != GDK_KEY_Home)))
+ {
+ old_entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
+
+ minimum_tag_position = G_MAXINT;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->set) {
- update_tag_position (dialog, CREATION_DATE, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-creation-date-tag",
- CREATION_DATE,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
-
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, ORIGINAL_FILE_NAME, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-original-file-name-tag",
+ ORIGINAL_FILE_NAME,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->set) {
- update_tag_position (dialog, NUMBERING, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-numbering-tag-zero",
- NUMBERING,
- start,
- end);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-one");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-two");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->set) {
- update_tag_position (dialog, NUMBERING0, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-numbering-tag-one",
- NUMBERING0,
- start,
- end);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-zero");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-two");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, CREATION_DATE, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-creation-date-tag",
+ CREATION_DATE,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->set) {
- update_tag_position (dialog, NUMBERING00, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-numbering-tag-two",
- NUMBERING0,
- start,
- end);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-one");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-zero");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ tag_removed = TRUE;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->set) {
- update_tag_position (dialog, CAMERA_MODEL, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-equipment-tag",
- CAMERA_MODEL,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->set) {
- update_tag_position (dialog, TRACK_NUMBER, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-track-number-tag",
- TRACK_NUMBER,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, NUMBERING, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-numbering-tag-zero",
+ NUMBERING,
+ start,
+ end);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-one");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-two");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->set) {
- update_tag_position (dialog, SEASON_NUMBER, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-season-tag",
- SEASON_NUMBER,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->set) {
- update_tag_position (dialog, EPISODE_NUMBER, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-episode-tag",
- EPISODE_NUMBER,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, NUMBERING0, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-numbering-tag-one",
+ NUMBERING0,
+ start,
+ end);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-zero");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-two");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->set) {
- update_tag_position (dialog, ARTIST_NAME, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-artist-name-tag",
- ARTIST_NAME,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->set) {
- update_tag_position (dialog, TITLE, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-title-tag",
- TITLE,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, NUMBERING00, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-numbering-tag-two",
+ NUMBERING0,
+ start,
+ end);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-one");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-zero");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->set) {
- update_tag_position (dialog, ALBUM_NAME, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-album-name-tag",
- ALBUM_NAME,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text)) {
- if (tag_data->position < minimum_tag_position)
- minimum_tag_position = tag_data->position;
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, CAMERA_MODEL, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-equipment-tag",
+ CAMERA_MODEL,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- if (minimum_tag_position != G_MAXINT) {
- dialog->use_manual_cursor_position = TRUE;
- dialog->cursor_position = minimum_tag_position;
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
- gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), new_entry_text->str);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), minimum_tag_position);
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, TRACK_NUMBER, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-track-number-tag",
+ TRACK_NUMBER,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
+ }
- dialog->use_manual_cursor_position = FALSE;
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
- g_string_free (new_entry_text, TRUE);
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, SEASON_NUMBER, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-season-tag",
+ SEASON_NUMBER,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- if ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) &&
- tag_removed)
- return GDK_EVENT_STOP;
- } else {
- if (remove_tag (dialog,
- ORIGINAL_FILE_NAME,
- "add-original-file-name-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- CREATION_DATE,
- "add-creation-date-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- NUMBERING,
- "add-numbering-tag-zero",
- keyval,
- gdk_event->key.is_modifier)) {
- tag_removed = TRUE;
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-one");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-two");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, EPISODE_NUMBER, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-episode-tag",
+ EPISODE_NUMBER,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- if (!tag_removed && remove_tag (dialog,
- NUMBERING0,
- "add-numbering-tag-one",
- keyval,
- gdk_event->key.is_modifier)) {
- tag_removed = TRUE;
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-zero");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-two");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, ARTIST_NAME, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-artist-name-tag",
+ ARTIST_NAME,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- if (!tag_removed && remove_tag (dialog,
- NUMBERING00,
- "add-numbering-tag-two",
- keyval,
- gdk_event->key.is_modifier)) {
- tag_removed = TRUE;
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-one");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-zero");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, TITLE, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-title-tag",
+ TITLE,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
- if (!tag_removed && remove_tag (dialog,
- CAMERA_MODEL,
- "add-equipment-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- SEASON_NUMBER,
- "add-season-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- EPISODE_NUMBER,
- "add-episode-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- TRACK_NUMBER,
- "add-track-number-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- ARTIST_NAME,
- "add-artist-name-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- TITLE,
- "add-title-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (!tag_removed && remove_tag (dialog,
- ALBUM_NAME,
- "add-album-name-tag",
- keyval,
- gdk_event->key.is_modifier))
- tag_removed = TRUE;
-
- if (tag_removed && (keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace)) {
- return GDK_EVENT_STOP;
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
+ }
+
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
+ if (tag_data->set)
+ {
+ update_tag_position (dialog, ALBUM_NAME, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ "add-album-name-tag",
+ ALBUM_NAME,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
+ {
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
}
+
+ tag_removed = TRUE;
+ }
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
}
- return GDK_EVENT_PROPAGATE;
-}
+ if (minimum_tag_position != G_MAXINT)
+ {
+ dialog->use_manual_cursor_position = TRUE;
+ dialog->cursor_position = minimum_tag_position;
-static void
-nautilus_batch_rename_dialog_finalize (GObject *object)
-{
- NautilusBatchRenameDialog *dialog;
- GList *l;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
-
- if (dialog->checking_conflicts) {
- g_cancellable_cancel (dialog->conflict_cancellable);
- g_object_unref (dialog->conflict_cancellable);
- }
-
- g_list_free (dialog->original_name_listbox_rows);
- g_list_free (dialog->arrow_listbox_rows);
- g_list_free (dialog->result_listbox_rows);
- g_list_free (dialog->listbox_labels_new);
- g_list_free (dialog->listbox_labels_old);
- g_list_free (dialog->listbox_icons);
-
- for (l = dialog->selection_metadata; l != NULL; l = l->next) {
- FileMetadata *metadata;
-
- metadata = l->data;
-
- if (metadata->file_name != NULL)
- g_string_free (metadata->file_name, TRUE);
- if (metadata->creation_date != NULL)
- g_string_free (metadata->creation_date, TRUE);
- if (metadata->equipment != NULL)
- g_string_free (metadata->equipment, TRUE);
- if (metadata->season != NULL)
- g_string_free (metadata->season, TRUE);
- if (metadata->episode_number != NULL)
- g_string_free (metadata->episode_number, TRUE);
- if (metadata->track_number != NULL)
- g_string_free (metadata->track_number, TRUE);
- if (metadata->artist_name != NULL)
- g_string_free (metadata->artist_name, TRUE);
- if (metadata->album_name != NULL)
- g_string_free (metadata->album_name, TRUE);
- }
-
- if (dialog->create_date != NULL)
- g_hash_table_destroy (dialog->create_date);
-
- g_list_free_full (dialog->distinct_parents, g_free);
- g_list_free_full (dialog->new_names, string_free);
- g_list_free_full (dialog->duplicates, conflict_data_free);
+ gtk_entry_set_text (GTK_ENTRY (dialog->name_entry), new_entry_text->str);
+ gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), minimum_tag_position);
- G_OBJECT_CLASS (nautilus_batch_rename_dialog_parent_class)->finalize (object);
-}
+ dialog->use_manual_cursor_position = FALSE;
-static void
-nautilus_batch_rename_dialog_class_init (NautilusBatchRenameDialogClass *klass)
-{
- GtkWidgetClass *widget_class;
- GObjectClass *oclass;
-
- widget_class = GTK_WIDGET_CLASS (klass);
- oclass = G_OBJECT_CLASS (klass);
-
- oclass->finalize = nautilus_batch_rename_dialog_finalize;
-
- gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/ui/nautilus-batch-rename-dialog.ui");
-
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, grid);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, cancel_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, original_name_listbox);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, arrow_listbox);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, result_listbox);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, name_entry);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, rename_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, find_entry);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, replace_entry);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, mode_stack);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, replace_mode_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, format_mode_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, add_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, add_popover);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_label);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, scrolled_window);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_popover);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_menu);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_box);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_label);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_up);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_down);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, add_tag_menu);
- gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_label);
-
- gtk_widget_class_bind_template_callback (widget_class, file_names_widget_entry_on_changed);
- gtk_widget_class_bind_template_callback (widget_class, file_names_widget_on_activate);
- gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_mode_changed);
- gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, add_popover_closed);
- gtk_widget_class_bind_template_callback (widget_class, numbering_order_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, numbering_order_popover_closed);
- gtk_widget_class_bind_template_callback (widget_class, select_next_conflict_up);
- gtk_widget_class_bind_template_callback (widget_class, select_next_conflict_down);
- gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_on_response);
- gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
-}
+ g_string_free (new_entry_text, TRUE);
+ }
-GtkWidget*
-nautilus_batch_rename_dialog_new (GList *selection,
- NautilusDirectory *directory,
- NautilusWindow *window)
-{
- NautilusBatchRenameDialog *dialog;
- GString *dialog_title;
+ if ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) &&
+ tag_removed)
+ {
+ return GDK_EVENT_STOP;
+ }
+ }
+ else
+ {
+ if (remove_tag (dialog,
+ ORIGINAL_FILE_NAME,
+ "add-original-file-name-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
+
+ if (!tag_removed && remove_tag (dialog,
+ CREATION_DATE,
+ "add-creation-date-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
- dialog = g_object_new (NAUTILUS_TYPE_BATCH_RENAME_DIALOG, "use-header-bar", TRUE, NULL);
+ if (!tag_removed && remove_tag (dialog,
+ NUMBERING,
+ "add-numbering-tag-zero",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-one");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- dialog->selection = selection;
- dialog->directory = directory;
- dialog->window = window;
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-two");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ }
- gtk_window_set_transient_for (GTK_WINDOW (dialog),
- GTK_WINDOW (window));
+ if (!tag_removed && remove_tag (dialog,
+ NUMBERING0,
+ "add-numbering-tag-one",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-zero");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- dialog_title = g_string_new ("");
- g_string_append_printf (dialog_title, "Rename %d Files", g_list_length (selection));
- gtk_window_set_title (GTK_WINDOW (dialog), dialog_title->str);
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-two");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ }
- nautilus_batch_rename_dialog_initialize_actions (dialog);
+ if (!tag_removed && remove_tag (dialog,
+ NUMBERING00,
+ "add-numbering-tag-two",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-one");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
- dialog->same_parent = !NAUTILUS_IS_SEARCH_DIRECTORY (directory);
+ action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+ "add-numbering-tag-zero");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+ }
- if (!dialog->same_parent)
- dialog->distinct_parents = batch_rename_files_get_distinct_parents (dialog->selection);
- else
- dialog->distinct_parents = NULL;
+ if (!tag_removed && remove_tag (dialog,
+ CAMERA_MODEL,
+ "add-equipment-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
- update_display_text (dialog);
+ if (!tag_removed && remove_tag (dialog,
+ SEASON_NUMBER,
+ "add-season-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
- fill_display_listbox (dialog);
+ if (!tag_removed && remove_tag (dialog,
+ EPISODE_NUMBER,
+ "add-episode-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
+
+ if (!tag_removed && remove_tag (dialog,
+ TRACK_NUMBER,
+ "add-track-number-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
+
+ if (!tag_removed && remove_tag (dialog,
+ ARTIST_NAME,
+ "add-artist-name-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
+
+ if (!tag_removed && remove_tag (dialog,
+ TITLE,
+ "add-title-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
+ if (!tag_removed && remove_tag (dialog,
+ ALBUM_NAME,
+ "add-album-name-tag",
+ keyval,
+ gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
+ }
- g_string_free (dialog_title, TRUE);
+ if (tag_removed && (keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace))
+ {
+ return GDK_EVENT_STOP;
+ }
+ }
- return GTK_WIDGET (dialog);
+ return GDK_EVENT_PROPAGATE;
}
static void
-nautilus_batch_rename_dialog_init (NautilusBatchRenameDialog *self)
+nautilus_batch_rename_dialog_finalize (GObject *object)
{
- TagData *tag_data;
-
- gtk_widget_init_template (GTK_WIDGET (self));
-
- gtk_list_box_set_header_func (GTK_LIST_BOX (self->original_name_listbox),
- (GtkListBoxUpdateHeaderFunc) listbox_header_func,
- self,
- NULL);
- gtk_list_box_set_header_func (GTK_LIST_BOX (self->arrow_listbox),
- (GtkListBoxUpdateHeaderFunc) listbox_header_func,
- self,
- NULL);
- gtk_list_box_set_header_func (GTK_LIST_BOX (self->result_listbox),
- (GtkListBoxUpdateHeaderFunc) listbox_header_func,
- self,
- NULL);
+ NautilusBatchRenameDialog *dialog;
+ GList *l;
+
+ dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
+
+ if (dialog->checking_conflicts)
+ {
+ g_cancellable_cancel (dialog->conflict_cancellable);
+ g_object_unref (dialog->conflict_cancellable);
+ }
+
+ g_list_free (dialog->original_name_listbox_rows);
+ g_list_free (dialog->arrow_listbox_rows);
+ g_list_free (dialog->result_listbox_rows);
+ g_list_free (dialog->listbox_labels_new);
+ g_list_free (dialog->listbox_labels_old);
+ g_list_free (dialog->listbox_icons);
+
+ for (l = dialog->selection_metadata; l != NULL; l = l->next)
+ {
+ FileMetadata *metadata;
+ metadata = l->data;
- self->mode = NAUTILUS_BATCH_RENAME_DIALOG_FORMAT;
+ if (metadata->file_name != NULL)
+ {
+ g_string_free (metadata->file_name, TRUE);
+ }
+ if (metadata->creation_date != NULL)
+ {
+ g_string_free (metadata->creation_date, TRUE);
+ }
+ if (metadata->equipment != NULL)
+ {
+ g_string_free (metadata->equipment, TRUE);
+ }
+ if (metadata->season != NULL)
+ {
+ g_string_free (metadata->season, TRUE);
+ }
+ if (metadata->episode_number != NULL)
+ {
+ g_string_free (metadata->episode_number, TRUE);
+ }
+ if (metadata->track_number != NULL)
+ {
+ g_string_free (metadata->track_number, TRUE);
+ }
+ if (metadata->artist_name != NULL)
+ {
+ g_string_free (metadata->artist_name, TRUE);
+ }
+ if (metadata->album_name != NULL)
+ {
+ g_string_free (metadata->album_name, TRUE);
+ }
+ }
- gtk_popover_bind_model (GTK_POPOVER (self->numbering_order_popover),
- G_MENU_MODEL (self->numbering_order_menu),
- NULL);
- gtk_popover_bind_model (GTK_POPOVER (self->add_popover),
- G_MENU_MODEL (self->add_tag_menu),
- NULL);
+ if (dialog->create_date != NULL)
+ {
+ g_hash_table_destroy (dialog->create_date);
+ }
- gtk_label_set_ellipsize (GTK_LABEL (self->conflict_label), PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (GTK_LABEL (self->conflict_label), 1);
+ g_list_free_full (dialog->distinct_parents, g_free);
+ g_list_free_full (dialog->new_names, string_free);
+ g_list_free_full (dialog->duplicates, conflict_data_free);
- self->duplicates = NULL;
- self->new_names = NULL;
+ G_OBJECT_CLASS (nautilus_batch_rename_dialog_parent_class)->finalize (object);
+}
- self->checking_conflicts = FALSE;
+static void
+nautilus_batch_rename_dialog_class_init (NautilusBatchRenameDialogClass *klass)
+{
+ GtkWidgetClass *widget_class;
+ GObjectClass *oclass;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
+
+ oclass->finalize = nautilus_batch_rename_dialog_finalize;
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/ui/nautilus-batch-rename-dialog.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, grid);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, cancel_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, original_name_listbox);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, arrow_listbox);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, result_listbox);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, name_entry);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, rename_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, find_entry);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, replace_entry);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, mode_stack);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, replace_mode_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, format_mode_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, add_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, add_popover);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, scrolled_window);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_popover);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_order_menu);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_box);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_up);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, conflict_down);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, add_tag_menu);
+ gtk_widget_class_bind_template_child (widget_class, NautilusBatchRenameDialog, numbering_label);
+
+ gtk_widget_class_bind_template_callback (widget_class, file_names_widget_entry_on_changed);
+ gtk_widget_class_bind_template_callback (widget_class, file_names_widget_on_activate);
+ gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_mode_changed);
+ gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, add_popover_closed);
+ gtk_widget_class_bind_template_callback (widget_class, numbering_order_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, numbering_order_popover_closed);
+ gtk_widget_class_bind_template_callback (widget_class, select_next_conflict_up);
+ gtk_widget_class_bind_template_callback (widget_class, select_next_conflict_down);
+ gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_on_response);
+ gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
+}
- self->rename_clicked = FALSE;
+GtkWidget *
+nautilus_batch_rename_dialog_new (GList *selection,
+ NautilusDirectory *directory,
+ NautilusWindow *window)
+{
+ NautilusBatchRenameDialog *dialog;
+ GString *dialog_title;
+ dialog = g_object_new (NAUTILUS_TYPE_BATCH_RENAME_DIALOG, "use-header-bar", TRUE, NULL);
- self->tag_info_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (ORIGINAL_FILE_NAME), tag_data);
+ dialog->selection = selection;
+ dialog->directory = directory;
+ dialog->window = window;
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING), tag_data);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog),
+ GTK_WINDOW (window));
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING0), tag_data);
+ dialog_title = g_string_new ("");
+ g_string_append_printf (dialog_title, "Rename %d Files", g_list_length (selection));
+ gtk_window_set_title (GTK_WINDOW (dialog), dialog_title->str);
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING00), tag_data);
+ nautilus_batch_rename_dialog_initialize_actions (dialog);
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (CREATION_DATE), tag_data);
+ dialog->same_parent = !NAUTILUS_IS_SEARCH_DIRECTORY (directory);
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (CAMERA_MODEL), tag_data);
+ if (!dialog->same_parent)
+ {
+ dialog->distinct_parents = batch_rename_files_get_distinct_parents (dialog->selection);
+ }
+ else
+ {
+ dialog->distinct_parents = NULL;
+ }
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (SEASON_NUMBER), tag_data);
+ update_display_text (dialog);
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (EPISODE_NUMBER), tag_data);
+ fill_display_listbox (dialog);
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (TRACK_NUMBER), tag_data);
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (ARTIST_NAME), tag_data);
+ g_string_free (dialog_title, TRUE);
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (TITLE), tag_data);
+ return GTK_WIDGET (dialog);
+}
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (ALBUM_NAME), tag_data);
-
- gtk_entry_set_text (GTK_ENTRY (self->name_entry),ORIGINAL_FILE_NAME);
- self->name_entry_characters = g_utf8_strlen (ORIGINAL_FILE_NAME, -1);
-
- self->row_height = -1;
-
- g_signal_connect (self->original_name_listbox, "row-selected", G_CALLBACK (row_selected), self);
- g_signal_connect (self->arrow_listbox, "row-selected", G_CALLBACK (row_selected), self);
- g_signal_connect (self->result_listbox, "row-selected", G_CALLBACK (row_selected), self);
-
- self->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
-
- g_signal_connect (self->original_name_listbox,
- "motion-notify-event",
- G_CALLBACK (on_motion),
- self);
- g_signal_connect (self->result_listbox,
- "motion-notify-event",
- G_CALLBACK (on_motion),
- self);
- g_signal_connect (self->arrow_listbox,
- "motion-notify-event",
- G_CALLBACK (on_motion),
- self);
-
- g_signal_connect (self->original_name_listbox,
- "leave-notify-event",
- G_CALLBACK (on_leave_event),
- self);
- g_signal_connect (self->result_listbox,
- "leave-notify-event",
- G_CALLBACK (on_leave_event),
- self);
- g_signal_connect (self->arrow_listbox,
- "leave-notify-event",
- G_CALLBACK (on_leave_event),
- self);
+static void
+nautilus_batch_rename_dialog_init (NautilusBatchRenameDialog *self)
+{
+ TagData *tag_data;
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ gtk_list_box_set_header_func (GTK_LIST_BOX (self->original_name_listbox),
+ (GtkListBoxUpdateHeaderFunc) listbox_header_func,
+ self,
+ NULL);
+ gtk_list_box_set_header_func (GTK_LIST_BOX (self->arrow_listbox),
+ (GtkListBoxUpdateHeaderFunc) listbox_header_func,
+ self,
+ NULL);
+ gtk_list_box_set_header_func (GTK_LIST_BOX (self->result_listbox),
+ (GtkListBoxUpdateHeaderFunc) listbox_header_func,
+ self,
+ NULL);
+
+
+ self->mode = NAUTILUS_BATCH_RENAME_DIALOG_FORMAT;
+
+ gtk_popover_bind_model (GTK_POPOVER (self->numbering_order_popover),
+ G_MENU_MODEL (self->numbering_order_menu),
+ NULL);
+ gtk_popover_bind_model (GTK_POPOVER (self->add_popover),
+ G_MENU_MODEL (self->add_tag_menu),
+ NULL);
+
+ gtk_label_set_ellipsize (GTK_LABEL (self->conflict_label), PANGO_ELLIPSIZE_END);
+ gtk_label_set_max_width_chars (GTK_LABEL (self->conflict_label), 1);
+
+ self->duplicates = NULL;
+ self->new_names = NULL;
+
+ self->checking_conflicts = FALSE;
+
+ self->rename_clicked = FALSE;
+
+
+ self->tag_info_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+ tag_data = g_new (TagData, 1);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (ORIGINAL_FILE_NAME), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = TRUE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = TRUE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING0), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = TRUE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING00), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (CREATION_DATE), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (CAMERA_MODEL), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (SEASON_NUMBER), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (EPISODE_NUMBER), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (TRACK_NUMBER), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (ARTIST_NAME), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (TITLE), tag_data);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = FALSE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (ALBUM_NAME), tag_data);
+
+ gtk_entry_set_text (GTK_ENTRY (self->name_entry), ORIGINAL_FILE_NAME);
+ self->name_entry_characters = g_utf8_strlen (ORIGINAL_FILE_NAME, -1);
+
+ self->row_height = -1;
+
+ g_signal_connect (self->original_name_listbox, "row-selected", G_CALLBACK (row_selected), self);
+ g_signal_connect (self->arrow_listbox, "row-selected", G_CALLBACK (row_selected), self);
+ g_signal_connect (self->result_listbox, "row-selected", G_CALLBACK (row_selected), self);
+
+ self->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+
+ g_signal_connect (self->original_name_listbox,
+ "motion-notify-event",
+ G_CALLBACK (on_motion),
+ self);
+ g_signal_connect (self->result_listbox,
+ "motion-notify-event",
+ G_CALLBACK (on_motion),
+ self);
+ g_signal_connect (self->arrow_listbox,
+ "motion-notify-event",
+ G_CALLBACK (on_motion),
+ self);
+
+ g_signal_connect (self->original_name_listbox,
+ "leave-notify-event",
+ G_CALLBACK (on_leave_event),
+ self);
+ g_signal_connect (self->result_listbox,
+ "leave-notify-event",
+ G_CALLBACK (on_leave_event),
+ self);
+ g_signal_connect (self->arrow_listbox,
+ "leave-notify-event",
+ G_CALLBACK (on_leave_event),
+ self);
}
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index 7fb9383b4..07ba1c459 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -26,44 +26,46 @@
#include <stdarg.h>
#include <eel/eel-vfs-extensions.h>
-typedef struct {
- NautilusFile *file;
- gint position;
+typedef struct
+{
+ NautilusFile *file;
+ gint position;
} CreateDateElem;
-typedef struct {
- NautilusBatchRenameDialog *dialog;
- GHashTable *hash_table;
-
- GList *selection_metadata;
-
- gboolean have_creation_date;
- gboolean have_equipment;
- gboolean have_season;
- gboolean have_episode_number;
- gboolean have_track_number;
- gboolean have_artist_name;
- gboolean have_title;
- gboolean have_album_name;
+typedef struct
+{
+ NautilusBatchRenameDialog *dialog;
+ GHashTable *hash_table;
+
+ GList *selection_metadata;
+
+ gboolean have_creation_date;
+ gboolean have_equipment;
+ gboolean have_season;
+ gboolean have_episode_number;
+ gboolean have_track_number;
+ gboolean have_artist_name;
+ gboolean have_title;
+ gboolean have_album_name;
} QueryData;
-enum {
- FILE_NAME_INDEX,
- CREATION_DATE_INDEX,
- YEAR_INDEX,
- MONTH_INDEX,
- DAY_INDEX,
- HOURS_INDEX,
- MINUTES_INDEX,
- SECONDS_INDEX,
- CAMERA_MODEL_INDEX,
- SEASON_INDEX,
- EPISODE_NUMBER_INDEX,
- TRACK_NUMBER_INDEX,
- ARTIST_NAME_INDEX,
- TITLE_INDEX,
- ALBUM_NAME_INDEX,
-
+enum
+{
+ FILE_NAME_INDEX,
+ CREATION_DATE_INDEX,
+ YEAR_INDEX,
+ MONTH_INDEX,
+ DAY_INDEX,
+ HOURS_INDEX,
+ MINUTES_INDEX,
+ SECONDS_INDEX,
+ CAMERA_MODEL_INDEX,
+ SEASON_INDEX,
+ EPISODE_NUMBER_INDEX,
+ TRACK_NUMBER_INDEX,
+ ARTIST_NAME_INDEX,
+ TITLE_INDEX,
+ ALBUM_NAME_INDEX,
} QueryMetadata;
static void on_cursor_callback (GObject *object,
@@ -73,556 +75,633 @@ static void on_cursor_callback (GObject *object,
void
string_free (gpointer mem)
{
- if (mem != NULL)
- g_string_free (mem, TRUE);
+ if (mem != NULL)
+ {
+ g_string_free (mem, TRUE);
+ }
}
void
conflict_data_free (gpointer mem)
{
- ConflictData *conflict_data = mem;
+ ConflictData *conflict_data = mem;
- g_free (conflict_data->name);
- g_free (conflict_data);
+ g_free (conflict_data->name);
+ g_free (conflict_data);
}
-static GString*
+static GString *
batch_rename_replace (gchar *string,
gchar *substring,
gchar *replacement)
{
- GString *new_string;
- gchar **splitted_string;
- gint i, n_splits;
+ GString *new_string;
+ gchar **splitted_string;
+ gint i, n_splits;
- new_string = g_string_new ("");
+ new_string = g_string_new ("");
- if (substring == NULL || replacement == NULL) {
- g_string_append (new_string, string);
+ if (substring == NULL || replacement == NULL)
+ {
+ g_string_append (new_string, string);
- return new_string;
- }
+ return new_string;
+ }
- if (g_utf8_strlen (substring, -1) == 0) {
- g_string_append (new_string, string);
+ if (g_utf8_strlen (substring, -1) == 0)
+ {
+ g_string_append (new_string, string);
- return new_string;
- }
+ return new_string;
+ }
- splitted_string = g_strsplit (string, substring, -1);
- if (splitted_string == NULL) {
- g_string_append (new_string, string);
+ splitted_string = g_strsplit (string, substring, -1);
+ if (splitted_string == NULL)
+ {
+ g_string_append (new_string, string);
- return new_string;
- }
+ return new_string;
+ }
- n_splits = g_strv_length (splitted_string);
+ n_splits = g_strv_length (splitted_string);
- for (i = 0; i < n_splits; i++) {
- g_string_append (new_string, splitted_string[i]);
+ for (i = 0; i < n_splits; i++)
+ {
+ g_string_append (new_string, splitted_string[i]);
- if (i != n_splits - 1)
- g_string_append (new_string, replacement);
+ if (i != n_splits - 1)
+ {
+ g_string_append (new_string, replacement);
}
+ }
- g_strfreev (splitted_string);
+ g_strfreev (splitted_string);
- return new_string;
+ return new_string;
}
/* This function changes the background color of the replaced part of the name */
-GString*
+GString *
batch_rename_replace_label_text (gchar *label,
const gchar *substring)
{
- GString *new_label;
- gchar **splitted_string;
- gchar *token;
- gint i, n_splits;
+ GString *new_label;
+ gchar **splitted_string;
+ gchar *token;
+ gint i, n_splits;
- new_label = g_string_new ("");
+ new_label = g_string_new ("");
- if (substring == NULL || g_strcmp0 (substring, "") == 0) {
- token = g_markup_escape_text (label, g_utf8_strlen (label, -1));
- new_label = g_string_append (new_label, token);
- g_free (token);
+ if (substring == NULL || g_strcmp0 (substring, "") == 0)
+ {
+ token = g_markup_escape_text (label, g_utf8_strlen (label, -1));
+ new_label = g_string_append (new_label, token);
+ g_free (token);
- return new_label;
- }
+ return new_label;
+ }
- splitted_string = g_strsplit (label, substring, -1);
- if (splitted_string == NULL) {
- token = g_markup_escape_text (label, g_utf8_strlen (label, -1));
- new_label = g_string_append (new_label, token);
- g_free (token);
+ splitted_string = g_strsplit (label, substring, -1);
+ if (splitted_string == NULL)
+ {
+ token = g_markup_escape_text (label, g_utf8_strlen (label, -1));
+ new_label = g_string_append (new_label, token);
+ g_free (token);
- return new_label;
- }
+ return new_label;
+ }
- n_splits = g_strv_length (splitted_string);
+ n_splits = g_strv_length (splitted_string);
- for (i = 0; i < n_splits; i++) {
- token = g_markup_escape_text (splitted_string[i], strlen (splitted_string[i]));
- new_label = g_string_append (new_label, token);
+ for (i = 0; i < n_splits; i++)
+ {
+ token = g_markup_escape_text (splitted_string[i], strlen (splitted_string[i]));
+ new_label = g_string_append (new_label, token);
- g_free (token);
+ g_free (token);
- if (i != n_splits - 1) {
- token = g_markup_escape_text (substring, g_utf8_strlen (substring, -1));
- g_string_append_printf (new_label,
- "<span background=\'#f57900\' color='white'>%s</span>",
- token);
+ if (i != n_splits - 1)
+ {
+ token = g_markup_escape_text (substring, g_utf8_strlen (substring, -1));
+ g_string_append_printf (new_label,
+ "<span background=\'#f57900\' color='white'>%s</span>",
+ token);
- g_free (token);
- }
+ g_free (token);
}
+ }
- g_strfreev (splitted_string);
+ g_strfreev (splitted_string);
- return new_label;
+ return new_label;
}
-static gchar*
+static gchar *
get_metadata (GList *selection_metadata,
gchar *file_name,
gchar *metadata)
{
- GList *l;
- FileMetadata *file_metadata;
-
- for (l = selection_metadata; l != NULL; l = l->next) {
- file_metadata = l->data;
- if (g_strcmp0 (file_name, file_metadata->file_name->str) == 0) {
- if (g_strcmp0 (metadata, "creation_date") == 0 &&
- file_metadata->creation_date != NULL &&
- file_metadata->creation_date->len != 0)
- return file_metadata->creation_date->str;
-
- if (g_strcmp0 (metadata, "equipment") == 0 &&
- file_metadata->equipment != NULL &&
- file_metadata->equipment->len != 0)
- return file_metadata->equipment->str;
-
- if (g_strcmp0 (metadata, "season") == 0 &&
- file_metadata->season != NULL &&
- file_metadata->season->len != 0)
- return file_metadata->season->str;
-
- if (g_strcmp0 (metadata, "episode_number") == 0 &&
- file_metadata->episode_number != NULL &&
- file_metadata->episode_number->len != 0)
- return file_metadata->episode_number->str;
-
- if (g_strcmp0 (metadata, "track_number") == 0 &&
- file_metadata->track_number != NULL &&
- file_metadata->track_number->len != 0)
- return file_metadata->track_number->str;
-
- if (g_strcmp0 (metadata, "artist_name") == 0 &&
- file_metadata->artist_name != NULL &&
- file_metadata->artist_name->len != 0)
- return file_metadata->artist_name->str;
-
- if (g_strcmp0 (metadata, "title") == 0 &&
- file_metadata->title != NULL &&
- file_metadata->title->len != 0)
- return file_metadata->title->str;
-
- if (g_strcmp0 (metadata, "album_name") == 0 &&
- file_metadata->album_name != NULL &&
- file_metadata->album_name->len != 0)
- return file_metadata->album_name->str;
- }
+ GList *l;
+ FileMetadata *file_metadata;
+
+ for (l = selection_metadata; l != NULL; l = l->next)
+ {
+ file_metadata = l->data;
+ if (g_strcmp0 (file_name, file_metadata->file_name->str) == 0)
+ {
+ if (g_strcmp0 (metadata, "creation_date") == 0 &&
+ file_metadata->creation_date != NULL &&
+ file_metadata->creation_date->len != 0)
+ {
+ return file_metadata->creation_date->str;
+ }
+
+ if (g_strcmp0 (metadata, "equipment") == 0 &&
+ file_metadata->equipment != NULL &&
+ file_metadata->equipment->len != 0)
+ {
+ return file_metadata->equipment->str;
+ }
+
+ if (g_strcmp0 (metadata, "season") == 0 &&
+ file_metadata->season != NULL &&
+ file_metadata->season->len != 0)
+ {
+ return file_metadata->season->str;
+ }
+
+ if (g_strcmp0 (metadata, "episode_number") == 0 &&
+ file_metadata->episode_number != NULL &&
+ file_metadata->episode_number->len != 0)
+ {
+ return file_metadata->episode_number->str;
+ }
+
+ if (g_strcmp0 (metadata, "track_number") == 0 &&
+ file_metadata->track_number != NULL &&
+ file_metadata->track_number->len != 0)
+ {
+ return file_metadata->track_number->str;
+ }
+
+ if (g_strcmp0 (metadata, "artist_name") == 0 &&
+ file_metadata->artist_name != NULL &&
+ file_metadata->artist_name->len != 0)
+ {
+ return file_metadata->artist_name->str;
+ }
+
+ if (g_strcmp0 (metadata, "title") == 0 &&
+ file_metadata->title != NULL &&
+ file_metadata->title->len != 0)
+ {
+ return file_metadata->title->str;
+ }
+
+ if (g_strcmp0 (metadata, "album_name") == 0 &&
+ file_metadata->album_name != NULL &&
+ file_metadata->album_name->len != 0)
+ {
+ return file_metadata->album_name->str;
+ }
}
+ }
- return NULL;
+ return NULL;
}
-static GString*
+static GString *
batch_rename_format (NautilusFile *file,
GList *text_chunks,
GList *selection_metadata,
gint count)
{
- GList *l;
- GString *tag;
- GString *new_name;
- gboolean added_tag;
- g_autofree gchar *file_name;
- g_autofree gchar *extension;
- gchar *metadata;
- gchar *base_name;
-
- file_name = nautilus_file_get_display_name (file);
- extension = nautilus_file_get_extension (file);
+ GList *l;
+ GString *tag;
+ GString *new_name;
+ gboolean added_tag;
+ g_autofree gchar *file_name;
+ g_autofree gchar *extension;
+ gchar *metadata;
+ gchar *base_name;
- new_name = g_string_new ("");
+ file_name = nautilus_file_get_display_name (file);
+ extension = nautilus_file_get_extension (file);
- for (l = text_chunks; l != NULL; l = l->next) {
- tag = l->data;
- added_tag = FALSE;
+ new_name = g_string_new ("");
- if (!added_tag && g_strcmp0 (tag->str, ORIGINAL_FILE_NAME) == 0) {
- base_name = eel_filename_strip_extension (file_name);
+ for (l = text_chunks; l != NULL; l = l->next)
+ {
+ tag = l->data;
+ added_tag = FALSE;
- new_name = g_string_append (new_name, base_name);
+ if (!added_tag && g_strcmp0 (tag->str, ORIGINAL_FILE_NAME) == 0)
+ {
+ base_name = eel_filename_strip_extension (file_name);
- added_tag = TRUE;
- g_free (base_name);
- }
+ new_name = g_string_append (new_name, base_name);
- if (!added_tag && g_strcmp0 (tag->str, NUMBERING) == 0) {
- g_string_append_printf (new_name, "%d", count);
- added_tag = TRUE;
- }
+ added_tag = TRUE;
+ g_free (base_name);
+ }
- if (!added_tag && g_strcmp0 (tag->str, NUMBERING0) == 0) {
- g_string_append_printf (new_name, "%02d", count);
+ if (!added_tag && g_strcmp0 (tag->str, NUMBERING) == 0)
+ {
+ g_string_append_printf (new_name, "%d", count);
+ added_tag = TRUE;
+ }
- added_tag = TRUE;
- }
+ if (!added_tag && g_strcmp0 (tag->str, NUMBERING0) == 0)
+ {
+ g_string_append_printf (new_name, "%02d", count);
- if (!added_tag && g_strcmp0 (tag->str, NUMBERING00) == 0) {
- g_string_append_printf (new_name, "%03d", count);
+ added_tag = TRUE;
+ }
- added_tag = TRUE;
- }
+ if (!added_tag && g_strcmp0 (tag->str, NUMBERING00) == 0)
+ {
+ g_string_append_printf (new_name, "%03d", count);
- if (!added_tag && g_strcmp0 (tag->str, CAMERA_MODEL) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "equipment");
+ added_tag = TRUE;
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, CAMERA_MODEL) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "equipment");
- if (!added_tag && g_strcmp0 (tag->str, CREATION_DATE) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "creation_date");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, CREATION_DATE) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "creation_date");
- if (!added_tag && g_strcmp0 (tag->str, SEASON_NUMBER) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "season");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, SEASON_NUMBER) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "season");
- if (!added_tag && g_strcmp0 (tag->str, EPISODE_NUMBER) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "episode_number");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, EPISODE_NUMBER) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "episode_number");
- if (!added_tag && g_strcmp0 (tag->str, TRACK_NUMBER) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "track_number");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, TRACK_NUMBER) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "track_number");
- if (!added_tag && g_strcmp0 (tag->str, ARTIST_NAME) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "artist_name");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, ARTIST_NAME) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "artist_name");
- if (!added_tag && g_strcmp0 (tag->str, TITLE) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "title");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, TITLE) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "title");
- if (!added_tag && g_strcmp0 (tag->str, ALBUM_NAME) == 0) {
- metadata = get_metadata (selection_metadata, file_name, "album_name");
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
+ }
- if (metadata != NULL) {
- new_name = g_string_append (new_name, metadata);
- added_tag = TRUE;
- }
- }
+ if (!added_tag && g_strcmp0 (tag->str, ALBUM_NAME) == 0)
+ {
+ metadata = get_metadata (selection_metadata, file_name, "album_name");
- if (!added_tag)
- new_name = g_string_append (new_name, tag->str);
+ if (metadata != NULL)
+ {
+ new_name = g_string_append (new_name, metadata);
+ added_tag = TRUE;
+ }
}
- if (g_strcmp0 (new_name->str, "") == 0) {
- new_name = g_string_append (new_name, file_name);
- } else {
- if (extension != NULL)
- new_name = g_string_append (new_name, extension);
+ if (!added_tag)
+ {
+ new_name = g_string_append (new_name, tag->str);
}
+ }
+
+ if (g_strcmp0 (new_name->str, "") == 0)
+ {
+ new_name = g_string_append (new_name, file_name);
+ }
+ else
+ {
+ if (extension != NULL)
+ {
+ new_name = g_string_append (new_name, extension);
+ }
+ }
- return new_name;
+ return new_name;
}
-GList*
-batch_rename_dialog_get_new_names_list (NautilusBatchRenameDialogMode mode,
- GList *selection,
- GList *text_chunks,
- GList *selection_metadata,
- gchar *entry_text,
- gchar *replace_text)
+GList *
+batch_rename_dialog_get_new_names_list (NautilusBatchRenameDialogMode mode,
+ GList *selection,
+ GList *text_chunks,
+ GList *selection_metadata,
+ gchar *entry_text,
+ gchar *replace_text)
{
- GList *l;
- GList *result;
- GString *file_name;
- GString *new_name;
- NautilusFile *file;
- gchar *name;
- gint count;
-
- result = NULL;
- count = 1;
- file_name = g_string_new ("");
+ GList *l;
+ GList *result;
+ GString *file_name;
+ GString *new_name;
+ NautilusFile *file;
+ gchar *name;
+ gint count;
+
+ result = NULL;
+ count = 1;
+ file_name = g_string_new ("");
+
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- file_name = g_string_new ("");
- name = nautilus_file_get_name (file);
- g_string_append (file_name, name);
-
- /* get the new name here and add it to the list*/
- if (mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT) {
- new_name = batch_rename_format (file,
- text_chunks,
- selection_metadata,
- count++);
- result = g_list_prepend (result, new_name);
- }
-
- if (mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE) {
- new_name = batch_rename_replace (file_name->str,
- entry_text,
- replace_text);
- result = g_list_prepend (result, new_name);
- }
+ file_name = g_string_new ("");
+ name = nautilus_file_get_name (file);
+ g_string_append (file_name, name);
+
+ /* get the new name here and add it to the list*/
+ if (mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT)
+ {
+ new_name = batch_rename_format (file,
+ text_chunks,
+ selection_metadata,
+ count++);
+ result = g_list_prepend (result, new_name);
+ }
- g_string_free (file_name, TRUE);
- g_free (name);
+ if (mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE)
+ {
+ new_name = batch_rename_replace (file_name->str,
+ entry_text,
+ replace_text);
+ result = g_list_prepend (result, new_name);
}
- return result;
+ g_string_free (file_name, TRUE);
+ g_free (name);
+ }
+
+ return result;
}
/* There is a case that a new name for a file conflicts with an existing file name
* in the directory but it's not a problem because the file in the directory that
* conflicts is part of the batch renaming selection and it's going to change the name anyway. */
gboolean
-file_name_conflicts_with_results (GList *selection,
- GList *new_names,
- GString *old_name,
- gchar *parent_uri)
+file_name_conflicts_with_results (GList *selection,
+ GList *new_names,
+ GString *old_name,
+ gchar *parent_uri)
{
- GList *l1;
- GList *l2;
- NautilusFile *selection_file;
- gchar *name1;
- GString *new_name;
- gchar *selection_parent_uri;
-
- for (l1 = selection, l2 = new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- selection_file = NAUTILUS_FILE (l1->data);
- name1 = nautilus_file_get_name (selection_file);
-
- selection_parent_uri = nautilus_file_get_parent_uri (selection_file);
-
- if (g_strcmp0 (name1, old_name->str) == 0) {
- new_name = l2->data;
-
- /* if the name didn't change, then there's a conflict */
- if (g_string_equal (old_name, new_name) &&
- (parent_uri == NULL || g_strcmp0 (parent_uri, selection_parent_uri) == 0))
- return FALSE;
-
-
- /* if this file exists and it changed it's name, then there's no
- * conflict */
- return TRUE;
- }
-
- g_free (selection_parent_uri);
+ GList *l1;
+ GList *l2;
+ NautilusFile *selection_file;
+ gchar *name1;
+ GString *new_name;
+ gchar *selection_parent_uri;
+
+ for (l1 = selection, l2 = new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ selection_file = NAUTILUS_FILE (l1->data);
+ name1 = nautilus_file_get_name (selection_file);
+
+ selection_parent_uri = nautilus_file_get_parent_uri (selection_file);
+
+ if (g_strcmp0 (name1, old_name->str) == 0)
+ {
+ new_name = l2->data;
+
+ /* if the name didn't change, then there's a conflict */
+ if (g_string_equal (old_name, new_name) &&
+ (parent_uri == NULL || g_strcmp0 (parent_uri, selection_parent_uri) == 0))
+ {
+ return FALSE;
+ }
+
+
+ /* if this file exists and it changed it's name, then there's no
+ * conflict */
+ return TRUE;
}
- /* the case this function searched for doesn't exist, so the file
- * has a conlfict */
- return FALSE;
+ g_free (selection_parent_uri);
+ }
+
+ /* the case this function searched for doesn't exist, so the file
+ * has a conlfict */
+ return FALSE;
}
static gint
compare_files_by_name_ascending (gconstpointer a,
gconstpointer b)
{
- NautilusFile *file1;
- NautilusFile *file2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- file1 = NAUTILUS_FILE (a);
- file2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (file1,file2,
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- FALSE, FALSE);
+ return nautilus_file_compare_for_sort (file1, file2,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ FALSE, FALSE);
}
static gint
compare_files_by_name_descending (gconstpointer a,
gconstpointer b)
{
- NautilusFile *file1;
- NautilusFile *file2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- file1 = NAUTILUS_FILE (a);
- file2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (file1,file2,
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- FALSE, TRUE);
+ return nautilus_file_compare_for_sort (file1, file2,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ FALSE, TRUE);
}
static gint
compare_files_by_first_modified (gconstpointer a,
gconstpointer b)
{
- NautilusFile *file1;
- NautilusFile *file2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- file1 = NAUTILUS_FILE (a);
- file2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (file1,file2,
- NAUTILUS_FILE_SORT_BY_MTIME,
- FALSE, FALSE);
+ return nautilus_file_compare_for_sort (file1, file2,
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ FALSE, FALSE);
}
static gint
compare_files_by_last_modified (gconstpointer a,
gconstpointer b)
{
- NautilusFile *file1;
- NautilusFile *file2;
+ NautilusFile *file1;
+ NautilusFile *file2;
- file1 = NAUTILUS_FILE (a);
- file2 = NAUTILUS_FILE (b);
+ file1 = NAUTILUS_FILE (a);
+ file2 = NAUTILUS_FILE (b);
- return nautilus_file_compare_for_sort (file1,file2,
- NAUTILUS_FILE_SORT_BY_MTIME,
- FALSE, TRUE);
+ return nautilus_file_compare_for_sort (file1, file2,
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ FALSE, TRUE);
}
static gint
compare_files_by_first_created (gconstpointer a,
gconstpointer b)
{
- CreateDateElem *elem1;
- CreateDateElem *elem2;
+ CreateDateElem *elem1;
+ CreateDateElem *elem2;
- elem1 = (CreateDateElem*) a;
- elem2 = (CreateDateElem*) b;
+ elem1 = (CreateDateElem *) a;
+ elem2 = (CreateDateElem *) b;
- return elem1->position - elem2->position;
+ return elem1->position - elem2->position;
}
static gint
compare_files_by_last_created (gconstpointer a,
gconstpointer b)
{
- CreateDateElem *elem1;
- CreateDateElem *elem2;
+ CreateDateElem *elem1;
+ CreateDateElem *elem2;
- elem1 = (CreateDateElem*) a;
- elem2 = (CreateDateElem*) b;
+ elem1 = (CreateDateElem *) a;
+ elem2 = (CreateDateElem *) b;
- return elem2->position - elem1->position;
+ return elem2->position - elem1->position;
}
-GList*
+GList *
nautilus_batch_rename_dialog_sort (GList *selection,
SortingMode mode,
GHashTable *creation_date_table)
{
- GList *l,*l2;
- NautilusFile *file;
- GList *create_date_list;
- GList *create_date_list_sorted;
- gchar *name;
-
- if (mode == ORIGINAL_ASCENDING)
- return g_list_sort (selection, compare_files_by_name_ascending);
-
- if (mode == ORIGINAL_DESCENDING) {
- return g_list_sort (selection, compare_files_by_name_descending);
+ GList *l, *l2;
+ NautilusFile *file;
+ GList *create_date_list;
+ GList *create_date_list_sorted;
+ gchar *name;
+
+ if (mode == ORIGINAL_ASCENDING)
+ {
+ return g_list_sort (selection, compare_files_by_name_ascending);
+ }
+
+ if (mode == ORIGINAL_DESCENDING)
+ {
+ return g_list_sort (selection, compare_files_by_name_descending);
+ }
+
+ if (mode == FIRST_MODIFIED)
+ {
+ return g_list_sort (selection, compare_files_by_first_modified);
+ }
+
+ if (mode == LAST_MODIFIED)
+ {
+ return g_list_sort (selection, compare_files_by_last_modified);
+ }
+
+ if (mode == FIRST_CREATED || mode == LAST_CREATED)
+ {
+ create_date_list = NULL;
+
+ for (l = selection; l != NULL; l = l->next)
+ {
+ CreateDateElem *elem;
+ elem = g_new (CreateDateElem, 1);
+
+ file = NAUTILUS_FILE (l->data);
+
+ name = nautilus_file_get_name (file);
+ elem->file = file;
+ elem->position = GPOINTER_TO_INT (g_hash_table_lookup (creation_date_table, name));
+ g_free (name);
+
+ create_date_list = g_list_prepend (create_date_list, elem);
}
- if (mode == FIRST_MODIFIED) {
- return g_list_sort (selection, compare_files_by_first_modified);
+ if (mode == FIRST_CREATED)
+ {
+ create_date_list_sorted = g_list_sort (create_date_list,
+ compare_files_by_first_created);
}
-
- if (mode == LAST_MODIFIED) {
- return g_list_sort (selection, compare_files_by_last_modified);
+ else
+ {
+ create_date_list_sorted = g_list_sort (create_date_list,
+ compare_files_by_last_created);
}
- if (mode == FIRST_CREATED || mode == LAST_CREATED) {
- create_date_list = NULL;
-
- for (l = selection; l != NULL; l = l->next) {
- CreateDateElem *elem;
- elem = g_new (CreateDateElem, 1);
-
- file = NAUTILUS_FILE (l->data);
-
- name = nautilus_file_get_name (file);
- elem->file = file;
- elem->position = GPOINTER_TO_INT (g_hash_table_lookup (creation_date_table, name));
- g_free (name);
-
- create_date_list = g_list_prepend (create_date_list, elem);
- }
-
- if (mode == FIRST_CREATED)
- create_date_list_sorted = g_list_sort (create_date_list,
- compare_files_by_first_created);
- else
- create_date_list_sorted = g_list_sort (create_date_list,
- compare_files_by_last_created);
-
- for (l = selection, l2 = create_date_list_sorted; l2 != NULL; l = l->next, l2 = l2->next) {
- CreateDateElem *elem = l2->data;
- l->data = elem->file;
- }
-
- g_list_free_full (create_date_list, g_free);
+ for (l = selection, l2 = create_date_list_sorted; l2 != NULL; l = l->next, l2 = l2->next)
+ {
+ CreateDateElem *elem = l2->data;
+ l->data = elem->file;
}
- return selection;
+ g_list_free_full (create_date_list, g_free);
+ }
+
+ return selection;
}
static void
cursor_next (QueryData *query_data,
TrackerSparqlCursor *cursor)
{
- tracker_sparql_cursor_next_async (cursor,
- NULL,
- on_cursor_callback,
- query_data);
+ tracker_sparql_cursor_next_async (cursor,
+ NULL,
+ on_cursor_callback,
+ query_data);
}
static void
@@ -630,250 +709,311 @@ on_cursor_callback (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- GHashTable *hash_table;
- TrackerSparqlCursor *cursor;
- gboolean success;
- QueryData *query_data;
- GError *error;
- GList *l;
- FileMetadata *metadata;
- FileMetadata *metadata_clear;
- GDateTime *datetime;
- gchar *date;
- const gchar *file_name;
- const gchar *creation_date;
- const gchar *year;
- const gchar *month;
- const gchar *day;
- const gchar *hours;
- const gchar *minutes;
- const gchar *seconds;
- const gchar *equipment;
- const gchar *season_number;
- const gchar *episode_number;
- const gchar *track_number;
- const gchar *artist_name;
- const gchar *title;
- const gchar *album_name;
-
- error = NULL;
- metadata = NULL;
-
- cursor = TRACKER_SPARQL_CURSOR (object);
- query_data = user_data;
- hash_table = query_data->hash_table;
-
- success = tracker_sparql_cursor_next_finish (cursor, result, &error);
- if (!success) {
- g_clear_error (&error);
- g_clear_object (&cursor);
-
- nautilus_batch_rename_dialog_query_finished (query_data->dialog,
- query_data->hash_table,
- query_data->selection_metadata);
-
- return;
+ GHashTable *hash_table;
+ TrackerSparqlCursor *cursor;
+ gboolean success;
+ QueryData *query_data;
+ GError *error;
+ GList *l;
+ FileMetadata *metadata;
+ FileMetadata *metadata_clear;
+ GDateTime *datetime;
+ gchar *date;
+ const gchar *file_name;
+ const gchar *creation_date;
+ const gchar *year;
+ const gchar *month;
+ const gchar *day;
+ const gchar *hours;
+ const gchar *minutes;
+ const gchar *seconds;
+ const gchar *equipment;
+ const gchar *season_number;
+ const gchar *episode_number;
+ const gchar *track_number;
+ const gchar *artist_name;
+ const gchar *title;
+ const gchar *album_name;
+
+ error = NULL;
+ metadata = NULL;
+
+ cursor = TRACKER_SPARQL_CURSOR (object);
+ query_data = user_data;
+ hash_table = query_data->hash_table;
+
+ success = tracker_sparql_cursor_next_finish (cursor, result, &error);
+ if (!success)
+ {
+ g_clear_error (&error);
+ g_clear_object (&cursor);
+
+ nautilus_batch_rename_dialog_query_finished (query_data->dialog,
+ query_data->hash_table,
+ query_data->selection_metadata);
+
+ return;
+ }
+
+ creation_date = tracker_sparql_cursor_get_string (cursor, CREATION_DATE_INDEX, NULL);
+
+ year = tracker_sparql_cursor_get_string (cursor, YEAR_INDEX, NULL);
+ month = tracker_sparql_cursor_get_string (cursor, MONTH_INDEX, NULL);
+ day = tracker_sparql_cursor_get_string (cursor, DAY_INDEX, NULL);
+ hours = tracker_sparql_cursor_get_string (cursor, HOURS_INDEX, NULL);
+ minutes = tracker_sparql_cursor_get_string (cursor, MINUTES_INDEX, NULL);
+ seconds = tracker_sparql_cursor_get_string (cursor, SECONDS_INDEX, NULL);
+ equipment = tracker_sparql_cursor_get_string (cursor, CAMERA_MODEL_INDEX, NULL);
+ season_number = tracker_sparql_cursor_get_string (cursor, SEASON_INDEX, NULL);
+ episode_number = tracker_sparql_cursor_get_string (cursor, EPISODE_NUMBER_INDEX, NULL);
+ track_number = tracker_sparql_cursor_get_string (cursor, TRACK_NUMBER_INDEX, NULL);
+ artist_name = tracker_sparql_cursor_get_string (cursor, ARTIST_NAME_INDEX, NULL);
+ title = tracker_sparql_cursor_get_string (cursor, TITLE_INDEX, NULL);
+ album_name = tracker_sparql_cursor_get_string (cursor, ALBUM_NAME_INDEX, NULL);
+
+ /* creation date used for sorting criteria */
+ if (creation_date == NULL)
+ {
+ if (hash_table != NULL)
+ {
+ g_hash_table_destroy (hash_table);
}
- creation_date = tracker_sparql_cursor_get_string (cursor, CREATION_DATE_INDEX, NULL);
-
- year = tracker_sparql_cursor_get_string (cursor, YEAR_INDEX, NULL);
- month = tracker_sparql_cursor_get_string (cursor, MONTH_INDEX, NULL);
- day = tracker_sparql_cursor_get_string (cursor, DAY_INDEX, NULL);
- hours = tracker_sparql_cursor_get_string (cursor, HOURS_INDEX, NULL);
- minutes = tracker_sparql_cursor_get_string (cursor, MINUTES_INDEX, NULL);
- seconds = tracker_sparql_cursor_get_string (cursor, SECONDS_INDEX, NULL);
- equipment = tracker_sparql_cursor_get_string (cursor, CAMERA_MODEL_INDEX, NULL);
- season_number = tracker_sparql_cursor_get_string (cursor, SEASON_INDEX, NULL);
- episode_number = tracker_sparql_cursor_get_string (cursor, EPISODE_NUMBER_INDEX, NULL);
- track_number = tracker_sparql_cursor_get_string (cursor, TRACK_NUMBER_INDEX, NULL);
- artist_name = tracker_sparql_cursor_get_string (cursor, ARTIST_NAME_INDEX, NULL);
- title = tracker_sparql_cursor_get_string (cursor, TITLE_INDEX, NULL);
- album_name = tracker_sparql_cursor_get_string (cursor, ALBUM_NAME_INDEX, NULL);
-
- /* creation date used for sorting criteria */
- if (creation_date == NULL) {
- if (hash_table != NULL)
- g_hash_table_destroy (hash_table);
-
- query_data->hash_table = NULL;
- query_data->have_creation_date = FALSE;
- } else {
- if (query_data->have_creation_date){
- g_hash_table_insert (hash_table,
- g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL)),
- GINT_TO_POINTER (g_hash_table_size (hash_table)));
- }
+ query_data->hash_table = NULL;
+ query_data->have_creation_date = FALSE;
+ }
+ else
+ {
+ if (query_data->have_creation_date)
+ {
+ g_hash_table_insert (hash_table,
+ g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL)),
+ GINT_TO_POINTER (g_hash_table_size (hash_table)));
}
- file_name = tracker_sparql_cursor_get_string (cursor, FILE_NAME_INDEX, NULL);
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata = l->data;
-
- if (g_strcmp0 (file_name, metadata->file_name->str) == 0)
- break;
+ }
+ file_name = tracker_sparql_cursor_get_string (cursor, FILE_NAME_INDEX, NULL);
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata = l->data;
+
+ if (g_strcmp0 (file_name, metadata->file_name->str) == 0)
+ {
+ break;
}
-
- /* Metadata to be used in file name
- * creation date */
- if (query_data->have_creation_date) {
- if (!creation_date) {
- query_data->have_creation_date = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->creation_date != NULL) {
- g_string_free (metadata_clear->creation_date, TRUE);
- metadata_clear->creation_date = NULL;
- }
- }
- } else {
- datetime = g_date_time_new_local (atoi (year),
- atoi (month),
- atoi (day),
- atoi (hours),
- atoi (minutes),
- atoi (seconds));
-
- date = g_date_time_format (datetime, "%x");
-
- if (strstr (date, "/") != NULL) {
- metadata->creation_date = batch_rename_replace (date, "/", "-");
- } else {
- metadata->creation_date = g_string_new (date);
- }
-
- g_free (date);
+ }
+
+ /* Metadata to be used in file name
+ * creation date */
+ if (query_data->have_creation_date)
+ {
+ if (!creation_date)
+ {
+ query_data->have_creation_date = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->creation_date != NULL)
+ {
+ g_string_free (metadata_clear->creation_date, TRUE);
+ metadata_clear->creation_date = NULL;
}
+ }
}
-
- /* equipment */
- if (query_data->have_equipment) {
- if (equipment == NULL) {
- query_data->have_equipment = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->equipment != NULL) {
- g_string_free (metadata_clear->equipment, TRUE);
- metadata_clear->equipment = NULL;
- }
- }
- } else {
- metadata->equipment = g_string_new (equipment);
+ else
+ {
+ datetime = g_date_time_new_local (atoi (year),
+ atoi (month),
+ atoi (day),
+ atoi (hours),
+ atoi (minutes),
+ atoi (seconds));
+
+ date = g_date_time_format (datetime, "%x");
+
+ if (strstr (date, "/") != NULL)
+ {
+ metadata->creation_date = batch_rename_replace (date, "/", "-");
+ }
+ else
+ {
+ metadata->creation_date = g_string_new (date);
+ }
+
+ g_free (date);
+ }
+ }
+
+ /* equipment */
+ if (query_data->have_equipment)
+ {
+ if (equipment == NULL)
+ {
+ query_data->have_equipment = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->equipment != NULL)
+ {
+ g_string_free (metadata_clear->equipment, TRUE);
+ metadata_clear->equipment = NULL;
}
+ }
}
-
- /* season number */
- if (query_data->have_season) {
- if (season_number == NULL) {
- query_data->have_season = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->season != NULL) {
- g_string_free (metadata_clear->season, TRUE);
- metadata_clear->season = NULL;
- }
- }
- } else {
- metadata->season = g_string_new (season_number);
+ else
+ {
+ metadata->equipment = g_string_new (equipment);
+ }
+ }
+
+ /* season number */
+ if (query_data->have_season)
+ {
+ if (season_number == NULL)
+ {
+ query_data->have_season = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->season != NULL)
+ {
+ g_string_free (metadata_clear->season, TRUE);
+ metadata_clear->season = NULL;
}
+ }
}
-
- /* episode number */
- if (query_data->have_episode_number) {
- if (episode_number == NULL) {
- query_data->have_episode_number = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->episode_number != NULL) {
- g_string_free (metadata_clear->episode_number, TRUE);
- metadata_clear->episode_number = NULL;
- }
- }
- } else {
- metadata->episode_number = g_string_new (episode_number);
+ else
+ {
+ metadata->season = g_string_new (season_number);
+ }
+ }
+
+ /* episode number */
+ if (query_data->have_episode_number)
+ {
+ if (episode_number == NULL)
+ {
+ query_data->have_episode_number = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->episode_number != NULL)
+ {
+ g_string_free (metadata_clear->episode_number, TRUE);
+ metadata_clear->episode_number = NULL;
}
+ }
}
-
- /* track number */
- if (query_data->have_track_number) {
- if (track_number == NULL) {
- query_data->have_track_number = FALSE;
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->track_number != NULL) {
- g_string_free (metadata_clear->track_number, TRUE);
- metadata_clear->track_number = NULL;
- }
- }
- } else {
- metadata->track_number = g_string_new (track_number);
+ else
+ {
+ metadata->episode_number = g_string_new (episode_number);
+ }
+ }
+
+ /* track number */
+ if (query_data->have_track_number)
+ {
+ if (track_number == NULL)
+ {
+ query_data->have_track_number = FALSE;
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->track_number != NULL)
+ {
+ g_string_free (metadata_clear->track_number, TRUE);
+ metadata_clear->track_number = NULL;
}
+ }
}
-
- /* artist name */
- if (query_data->have_artist_name) {
- if (artist_name == NULL) {
- query_data->have_artist_name = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->artist_name != NULL) {
- g_string_free (metadata_clear->artist_name, TRUE);
- metadata_clear->artist_name = NULL;
- }
- }
- } else {
- metadata->artist_name = g_string_new (artist_name);
+ else
+ {
+ metadata->track_number = g_string_new (track_number);
+ }
+ }
+
+ /* artist name */
+ if (query_data->have_artist_name)
+ {
+ if (artist_name == NULL)
+ {
+ query_data->have_artist_name = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->artist_name != NULL)
+ {
+ g_string_free (metadata_clear->artist_name, TRUE);
+ metadata_clear->artist_name = NULL;
}
+ }
}
-
- /* title */
- if (query_data->have_title) {
- if (title == NULL) {
- query_data->have_title = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->title != NULL) {
- g_string_free (metadata_clear->title, TRUE);
- metadata_clear->title = NULL;
- }
- }
- } else {
- metadata->title = g_string_new (title);
+ else
+ {
+ metadata->artist_name = g_string_new (artist_name);
+ }
+ }
+
+ /* title */
+ if (query_data->have_title)
+ {
+ if (title == NULL)
+ {
+ query_data->have_title = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->title != NULL)
+ {
+ g_string_free (metadata_clear->title, TRUE);
+ metadata_clear->title = NULL;
}
+ }
}
-
- /* album name */
- if (query_data->have_album_name) {
- if (album_name == NULL) {
- query_data->have_album_name = FALSE;
-
- for (l = query_data->selection_metadata; l != NULL; l = l->next) {
- metadata_clear = l->data;
-
- if (metadata_clear->album_name != NULL) {
- g_string_free (metadata_clear->album_name, TRUE);
- metadata_clear->album_name = NULL;
- }
- }
- } else {
- metadata->album_name = g_string_new (album_name);
+ else
+ {
+ metadata->title = g_string_new (title);
+ }
+ }
+
+ /* album name */
+ if (query_data->have_album_name)
+ {
+ if (album_name == NULL)
+ {
+ query_data->have_album_name = FALSE;
+
+ for (l = query_data->selection_metadata; l != NULL; l = l->next)
+ {
+ metadata_clear = l->data;
+
+ if (metadata_clear->album_name != NULL)
+ {
+ g_string_free (metadata_clear->album_name, TRUE);
+ metadata_clear->album_name = NULL;
}
+ }
+ }
+ else
+ {
+ metadata->album_name = g_string_new (album_name);
}
+ }
- /* Get next */
- cursor_next (query_data, cursor);
+ /* Get next */
+ cursor_next (query_data, cursor);
}
static void
@@ -881,170 +1021,186 @@ batch_rename_dialog_query_callback (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- TrackerSparqlConnection *connection;
- TrackerSparqlCursor *cursor;
- QueryData *query_data;
- GError *error;
-
- error = NULL;
-
- connection = TRACKER_SPARQL_CONNECTION (object);
- query_data = user_data;
-
- cursor = tracker_sparql_connection_query_finish (connection,
- result,
- &error);
-
- if (error != NULL) {
- g_warning ("Error on batch rename query for metadata: %s", error->message);
- g_error_free (error);
-
- nautilus_batch_rename_dialog_query_finished (query_data->dialog,
- query_data->hash_table,
- query_data->selection_metadata);
- } else {
- cursor_next (query_data, cursor);
- }
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
+ QueryData *query_data;
+ GError *error;
+
+ error = NULL;
+
+ connection = TRACKER_SPARQL_CONNECTION (object);
+ query_data = user_data;
+
+ cursor = tracker_sparql_connection_query_finish (connection,
+ result,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error on batch rename query for metadata: %s", error->message);
+ g_error_free (error);
+
+ nautilus_batch_rename_dialog_query_finished (query_data->dialog,
+ query_data->hash_table,
+ query_data->selection_metadata);
+ }
+ else
+ {
+ cursor_next (query_data, cursor);
+ }
}
void
check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
GList *selection)
{
- TrackerSparqlConnection *connection;
- GString *query;
- GHashTable *hash_table;
- GList *l;
- NautilusFile *file;
- GError *error;
- QueryData *query_data;
- gchar *file_name;
- FileMetadata *metadata;
- GList *selection_metadata;
-
- error = NULL;
- selection_metadata = NULL;
-
- query = g_string_new ("SELECT "
- "nfo:fileName(?file) "
- "nie:contentCreated(?file) "
- "year(nie:contentCreated(?file)) "
- "month(nie:contentCreated(?file)) "
- "day(nie:contentCreated(?file)) "
- "hours(nie:contentCreated(?file)) "
- "minutes(nie:contentCreated(?file)) "
- "seconds(nie:contentCreated(?file)) "
- "nfo:model(nfo:equipment(?file)) "
- "nmm:season(?file) "
- "nmm:episodeNumber(?file) "
- "nmm:trackNumber(?file) "
- "nmm:artistName(nmm:performer(?file)) "
- "nie:title(?file) "
- "nmm:albumTitle(nmm:musicAlbum(?file)) "
- "WHERE { ?file a nfo:FileDataObject. ");
-
- g_string_append_printf (query,
- "FILTER(tracker:uri-is-parent('%s', nie:url(?file))) ",
- nautilus_file_get_parent_uri (NAUTILUS_FILE (selection->data)));
-
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- file_name = nautilus_file_get_name (file);
-
- if (l == selection)
- g_string_append_printf (query,
- "FILTER (nfo:fileName(?file) = '%s' ",
- file_name);
- else
- g_string_append_printf (query,
- "|| nfo:fileName(?file) = '%s' ",
- file_name);
-
- metadata = g_new (FileMetadata, 1);
- metadata->file_name = g_string_new (file_name);
- metadata->creation_date = NULL;
- metadata->equipment = NULL;
- metadata->season = NULL;
- metadata->episode_number = NULL;
- metadata->track_number = NULL;
- metadata->artist_name = NULL;
- metadata->title = NULL;
- metadata->album_name = NULL;
-
- selection_metadata = g_list_append (selection_metadata, metadata);
-
- g_free (file_name);
+ TrackerSparqlConnection *connection;
+ GString *query;
+ GHashTable *hash_table;
+ GList *l;
+ NautilusFile *file;
+ GError *error;
+ QueryData *query_data;
+ gchar *file_name;
+ FileMetadata *metadata;
+ GList *selection_metadata;
+
+ error = NULL;
+ selection_metadata = NULL;
+
+ query = g_string_new ("SELECT "
+ "nfo:fileName(?file) "
+ "nie:contentCreated(?file) "
+ "year(nie:contentCreated(?file)) "
+ "month(nie:contentCreated(?file)) "
+ "day(nie:contentCreated(?file)) "
+ "hours(nie:contentCreated(?file)) "
+ "minutes(nie:contentCreated(?file)) "
+ "seconds(nie:contentCreated(?file)) "
+ "nfo:model(nfo:equipment(?file)) "
+ "nmm:season(?file) "
+ "nmm:episodeNumber(?file) "
+ "nmm:trackNumber(?file) "
+ "nmm:artistName(nmm:performer(?file)) "
+ "nie:title(?file) "
+ "nmm:albumTitle(nmm:musicAlbum(?file)) "
+ "WHERE { ?file a nfo:FileDataObject. ");
+
+ g_string_append_printf (query,
+ "FILTER(tracker:uri-is-parent('%s', nie:url(?file))) ",
+ nautilus_file_get_parent_uri (NAUTILUS_FILE (selection->data)));
+
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ file_name = nautilus_file_get_name (file);
+
+ if (l == selection)
+ {
+ g_string_append_printf (query,
+ "FILTER (nfo:fileName(?file) = '%s' ",
+ file_name);
}
-
- g_string_append (query, ")} ORDER BY ASC(nie:contentCreated(?file))");
-
- connection = tracker_sparql_connection_get (NULL, &error);
- if (!connection) {
- g_error_free (error);
-
- return;
+ else
+ {
+ g_string_append_printf (query,
+ "|| nfo:fileName(?file) = '%s' ",
+ file_name);
}
- hash_table = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
-
- query_data = g_new (QueryData, 1);
- query_data->hash_table = hash_table;
- query_data->dialog = dialog;
- query_data->selection_metadata = selection_metadata;
-
- query_data->have_season = TRUE;
- query_data->have_creation_date = TRUE;
- query_data->have_artist_name = TRUE;
- query_data->have_track_number = TRUE;
- query_data->have_equipment = TRUE;
- query_data->have_episode_number = TRUE;
- query_data->have_title = TRUE;
- query_data->have_album_name = TRUE;
-
- /* Make an asynchronous query to the store */
- tracker_sparql_connection_query_async (connection,
- query->str,
- NULL,
- batch_rename_dialog_query_callback,
- query_data);
-
- g_object_unref (connection);
- g_string_free (query, TRUE);
+ metadata = g_new (FileMetadata, 1);
+ metadata->file_name = g_string_new (file_name);
+ metadata->creation_date = NULL;
+ metadata->equipment = NULL;
+ metadata->season = NULL;
+ metadata->episode_number = NULL;
+ metadata->track_number = NULL;
+ metadata->artist_name = NULL;
+ metadata->title = NULL;
+ metadata->album_name = NULL;
+
+ selection_metadata = g_list_append (selection_metadata, metadata);
+
+ g_free (file_name);
+ }
+
+ g_string_append (query, ")} ORDER BY ASC(nie:contentCreated(?file))");
+
+ connection = tracker_sparql_connection_get (NULL, &error);
+ if (!connection)
+ {
+ g_error_free (error);
+
+ return;
+ }
+
+ hash_table = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+
+ query_data = g_new (QueryData, 1);
+ query_data->hash_table = hash_table;
+ query_data->dialog = dialog;
+ query_data->selection_metadata = selection_metadata;
+
+ query_data->have_season = TRUE;
+ query_data->have_creation_date = TRUE;
+ query_data->have_artist_name = TRUE;
+ query_data->have_track_number = TRUE;
+ query_data->have_equipment = TRUE;
+ query_data->have_episode_number = TRUE;
+ query_data->have_title = TRUE;
+ query_data->have_album_name = TRUE;
+
+ /* Make an asynchronous query to the store */
+ tracker_sparql_connection_query_async (connection,
+ query->str,
+ NULL,
+ batch_rename_dialog_query_callback,
+ query_data);
+
+ g_object_unref (connection);
+ g_string_free (query, TRUE);
}
-GList*
+GList *
batch_rename_files_get_distinct_parents (GList *selection)
{
- GList *result;
- GList *l1;
- GList *l2;
- NautilusFile *file;
- gboolean exists;
- gchar *parent_uri;
-
- result = NULL;
-
- for (l1 = selection; l1 != NULL; l1 = l1->next) {
- exists = FALSE;
-
- file = NAUTILUS_FILE (l1->data);
- parent_uri = nautilus_file_get_parent_uri (file);
-
- for (l2 = result; l2 != NULL; l2 = l2->next)
- if (g_strcmp0 (parent_uri, l2->data) == 0) {
- exists = TRUE;
- break;
- }
-
- if (!exists) {
- result = g_list_prepend (result, parent_uri);
- } else {
- g_free (parent_uri);
- }
+ GList *result;
+ GList *l1;
+ GList *l2;
+ NautilusFile *file;
+ gboolean exists;
+ gchar *parent_uri;
+
+ result = NULL;
+
+ for (l1 = selection; l1 != NULL; l1 = l1->next)
+ {
+ exists = FALSE;
+
+ file = NAUTILUS_FILE (l1->data);
+ parent_uri = nautilus_file_get_parent_uri (file);
+
+ for (l2 = result; l2 != NULL; l2 = l2->next)
+ {
+ if (g_strcmp0 (parent_uri, l2->data) == 0)
+ {
+ exists = TRUE;
+ break;
+ }
+ }
+
+ if (!exists)
+ {
+ result = g_list_prepend (result, parent_uri);
+ }
+ else
+ {
+ g_free (parent_uri);
}
+ }
- return result;
-} \ No newline at end of file
+ return result;
+}
diff --git a/src/nautilus-bookmark-list.c b/src/nautilus-bookmark-list.c
index c849c0106..839b6a539 100644
--- a/src/nautilus-bookmark-list.c
+++ b/src/nautilus-bookmark-list.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -37,202 +36,208 @@
#define LOAD_JOB 1
#define SAVE_JOB 2
-enum {
- CHANGED,
- LAST_SIGNAL
+enum
+{
+ CHANGED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
/* forward declarations */
-static void nautilus_bookmark_list_load_file (NautilusBookmarkList *bookmarks);
-static void nautilus_bookmark_list_save_file (NautilusBookmarkList *bookmarks);
+static void nautilus_bookmark_list_load_file (NautilusBookmarkList *bookmarks);
+static void nautilus_bookmark_list_save_file (NautilusBookmarkList *bookmarks);
-G_DEFINE_TYPE(NautilusBookmarkList, nautilus_bookmark_list, G_TYPE_OBJECT)
+G_DEFINE_TYPE (NautilusBookmarkList, nautilus_bookmark_list, G_TYPE_OBJECT)
static NautilusBookmark *
new_bookmark_from_uri (const char *uri, const char *label)
{
- NautilusBookmark *new_bookmark;
- GFile *location;
-
- location = NULL;
- if (uri) {
- location = g_file_new_for_uri (uri);
- }
-
- new_bookmark = NULL;
-
- if (location) {
- new_bookmark = nautilus_bookmark_new (location, label);
- g_object_unref (location);
- }
-
- return new_bookmark;
+ NautilusBookmark *new_bookmark;
+ GFile *location;
+
+ location = NULL;
+ if (uri)
+ {
+ location = g_file_new_for_uri (uri);
+ }
+
+ new_bookmark = NULL;
+
+ if (location)
+ {
+ new_bookmark = nautilus_bookmark_new (location, label);
+ g_object_unref (location);
+ }
+
+ return new_bookmark;
}
static GFile *
nautilus_bookmark_list_get_legacy_file (void)
{
- char *filename;
- GFile *file;
+ char *filename;
+ GFile *file;
- filename = g_build_filename (g_get_home_dir (),
- ".gtk-bookmarks",
- NULL);
- file = g_file_new_for_path (filename);
+ filename = g_build_filename (g_get_home_dir (),
+ ".gtk-bookmarks",
+ NULL);
+ file = g_file_new_for_path (filename);
- g_free (filename);
+ g_free (filename);
- return file;
+ return file;
}
static GFile *
nautilus_bookmark_list_get_file (void)
{
- char *filename;
- GFile *file;
+ char *filename;
+ GFile *file;
- filename = g_build_filename (g_get_user_config_dir (),
- "gtk-3.0",
- "bookmarks",
- NULL);
- file = g_file_new_for_path (filename);
+ filename = g_build_filename (g_get_user_config_dir (),
+ "gtk-3.0",
+ "bookmarks",
+ NULL);
+ file = g_file_new_for_path (filename);
- g_free (filename);
+ g_free (filename);
- return file;
+ return file;
}
/* Initialization. */
static void
bookmark_in_list_changed_callback (NautilusBookmark *bookmark,
- NautilusBookmarkList *bookmarks)
+ NautilusBookmarkList *bookmarks)
{
- g_assert (NAUTILUS_IS_BOOKMARK (bookmark));
- g_assert (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
+ g_assert (NAUTILUS_IS_BOOKMARK (bookmark));
+ g_assert (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
- /* save changes to the list */
- nautilus_bookmark_list_save_file (bookmarks);
+ /* save changes to the list */
+ nautilus_bookmark_list_save_file (bookmarks);
}
static void
-bookmark_in_list_notify (GObject *object,
- GParamSpec *pspec,
- NautilusBookmarkList *bookmarks)
+bookmark_in_list_notify (GObject *object,
+ GParamSpec *pspec,
+ NautilusBookmarkList *bookmarks)
{
- /* emit the changed signal without saving, as only appearance properties changed */
- g_signal_emit (bookmarks, signals[CHANGED], 0);
+ /* emit the changed signal without saving, as only appearance properties changed */
+ g_signal_emit (bookmarks, signals[CHANGED], 0);
}
static void
stop_monitoring_bookmark (NautilusBookmarkList *bookmarks,
- NautilusBookmark *bookmark)
+ NautilusBookmark *bookmark)
{
- g_signal_handlers_disconnect_by_func (bookmark,
- bookmark_in_list_changed_callback,
- bookmarks);
+ g_signal_handlers_disconnect_by_func (bookmark,
+ bookmark_in_list_changed_callback,
+ bookmarks);
}
static void
-stop_monitoring_one (gpointer data, gpointer user_data)
+stop_monitoring_one (gpointer data,
+ gpointer user_data)
{
- g_assert (NAUTILUS_IS_BOOKMARK (data));
- g_assert (NAUTILUS_IS_BOOKMARK_LIST (user_data));
+ g_assert (NAUTILUS_IS_BOOKMARK (data));
+ g_assert (NAUTILUS_IS_BOOKMARK_LIST (user_data));
- stop_monitoring_bookmark (NAUTILUS_BOOKMARK_LIST (user_data),
- NAUTILUS_BOOKMARK (data));
+ stop_monitoring_bookmark (NAUTILUS_BOOKMARK_LIST (user_data),
+ NAUTILUS_BOOKMARK (data));
}
static void
clear (NautilusBookmarkList *bookmarks)
{
- g_list_foreach (bookmarks->list, stop_monitoring_one, bookmarks);
- g_list_free_full (bookmarks->list, g_object_unref);
- bookmarks->list = NULL;
+ g_list_foreach (bookmarks->list, stop_monitoring_one, bookmarks);
+ g_list_free_full (bookmarks->list, g_object_unref);
+ bookmarks->list = NULL;
}
static void
do_finalize (GObject *object)
{
- if (NAUTILUS_BOOKMARK_LIST (object)->monitor != NULL) {
- g_file_monitor_cancel (NAUTILUS_BOOKMARK_LIST (object)->monitor);
- NAUTILUS_BOOKMARK_LIST (object)->monitor = NULL;
- }
+ if (NAUTILUS_BOOKMARK_LIST (object)->monitor != NULL)
+ {
+ g_file_monitor_cancel (NAUTILUS_BOOKMARK_LIST (object)->monitor);
+ NAUTILUS_BOOKMARK_LIST (object)->monitor = NULL;
+ }
- g_queue_free (NAUTILUS_BOOKMARK_LIST (object)->pending_ops);
+ g_queue_free (NAUTILUS_BOOKMARK_LIST (object)->pending_ops);
- clear (NAUTILUS_BOOKMARK_LIST (object));
+ clear (NAUTILUS_BOOKMARK_LIST (object));
- G_OBJECT_CLASS (nautilus_bookmark_list_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_bookmark_list_parent_class)->finalize (object);
}
static void
nautilus_bookmark_list_class_init (NautilusBookmarkListClass *class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->finalize = do_finalize;
-
- signals[CHANGED] =
- g_signal_new ("changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusBookmarkListClass,
- changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = do_finalize;
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusBookmarkListClass,
+ changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static void
bookmark_monitor_changed_cb (GFileMonitor *monitor,
- GFile *child,
- GFile *other_file,
- GFileMonitorEvent eflags,
- gpointer user_data)
+ GFile *child,
+ GFile *other_file,
+ GFileMonitorEvent eflags,
+ gpointer user_data)
{
- if (eflags == G_FILE_MONITOR_EVENT_CHANGED ||
- eflags == G_FILE_MONITOR_EVENT_CREATED) {
- g_return_if_fail (NAUTILUS_IS_BOOKMARK_LIST (NAUTILUS_BOOKMARK_LIST (user_data)));
- nautilus_bookmark_list_load_file (NAUTILUS_BOOKMARK_LIST (user_data));
- }
+ if (eflags == G_FILE_MONITOR_EVENT_CHANGED ||
+ eflags == G_FILE_MONITOR_EVENT_CREATED)
+ {
+ g_return_if_fail (NAUTILUS_IS_BOOKMARK_LIST (NAUTILUS_BOOKMARK_LIST (user_data)));
+ nautilus_bookmark_list_load_file (NAUTILUS_BOOKMARK_LIST (user_data));
+ }
}
static void
nautilus_bookmark_list_init (NautilusBookmarkList *bookmarks)
{
- GFile *file;
+ GFile *file;
- bookmarks->pending_ops = g_queue_new ();
+ bookmarks->pending_ops = g_queue_new ();
- nautilus_bookmark_list_load_file (bookmarks);
+ nautilus_bookmark_list_load_file (bookmarks);
- file = nautilus_bookmark_list_get_file ();
- bookmarks->monitor = g_file_monitor_file (file, 0, NULL, NULL);
- g_file_monitor_set_rate_limit (bookmarks->monitor, 1000);
+ file = nautilus_bookmark_list_get_file ();
+ bookmarks->monitor = g_file_monitor_file (file, 0, NULL, NULL);
+ g_file_monitor_set_rate_limit (bookmarks->monitor, 1000);
- g_signal_connect (bookmarks->monitor, "changed",
- G_CALLBACK (bookmark_monitor_changed_cb), bookmarks);
+ g_signal_connect (bookmarks->monitor, "changed",
+ G_CALLBACK (bookmark_monitor_changed_cb), bookmarks);
- g_object_unref (file);
+ g_object_unref (file);
}
static void
insert_bookmark_internal (NautilusBookmarkList *bookmarks,
- NautilusBookmark *bookmark,
- int index)
+ NautilusBookmark *bookmark,
+ int index)
{
- bookmarks->list = g_list_insert (bookmarks->list, bookmark, index);
-
- g_signal_connect_object (bookmark, "contents-changed",
- G_CALLBACK (bookmark_in_list_changed_callback), bookmarks, 0);
- g_signal_connect_object (bookmark, "notify::icon",
- G_CALLBACK (bookmark_in_list_notify), bookmarks, 0);
- g_signal_connect_object (bookmark, "notify::name",
- G_CALLBACK (bookmark_in_list_notify), bookmarks, 0);
+ bookmarks->list = g_list_insert (bookmarks->list, bookmark, index);
+
+ g_signal_connect_object (bookmark, "contents-changed",
+ G_CALLBACK (bookmark_in_list_changed_callback), bookmarks, 0);
+ g_signal_connect_object (bookmark, "notify::icon",
+ G_CALLBACK (bookmark_in_list_notify), bookmarks, 0);
+ g_signal_connect_object (bookmark, "notify::name",
+ G_CALLBACK (bookmark_in_list_notify), bookmarks, 0);
}
/**
@@ -247,41 +252,45 @@ insert_bookmark_internal (NautilusBookmarkList *bookmarks,
**/
NautilusBookmark *
nautilus_bookmark_list_item_with_location (NautilusBookmarkList *bookmarks,
- GFile *location,
- guint *index)
+ GFile *location,
+ guint *index)
{
- GList *node;
- GFile *bookmark_location;
- NautilusBookmark *bookmark;
- gboolean found = FALSE;
- guint idx;
-
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks), NULL);
- g_return_val_if_fail (G_IS_FILE (location), NULL);
-
- idx = 0;
-
- for (node = bookmarks->list; node != NULL; node = node->next) {
- bookmark = node->data;
- bookmark_location = nautilus_bookmark_get_location (bookmark);
-
- if (g_file_equal (location, bookmark_location)) {
- found = TRUE;
- }
-
- g_object_unref (bookmark_location);
-
- if (found) {
- if (index) {
- *index = idx;
- }
- return bookmark;
- }
-
- idx++;
- }
-
- return NULL;
+ GList *node;
+ GFile *bookmark_location;
+ NautilusBookmark *bookmark;
+ gboolean found = FALSE;
+ guint idx;
+
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks), NULL);
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
+
+ idx = 0;
+
+ for (node = bookmarks->list; node != NULL; node = node->next)
+ {
+ bookmark = node->data;
+ bookmark_location = nautilus_bookmark_get_location (bookmark);
+
+ if (g_file_equal (location, bookmark_location))
+ {
+ found = TRUE;
+ }
+
+ g_object_unref (bookmark_location);
+
+ if (found)
+ {
+ if (index)
+ {
+ *index = idx;
+ }
+ return bookmark;
+ }
+
+ idx++;
+ }
+
+ return NULL;
}
/**
@@ -293,18 +302,19 @@ nautilus_bookmark_list_item_with_location (NautilusBookmarkList *bookmarks,
**/
void
nautilus_bookmark_list_append (NautilusBookmarkList *bookmarks,
- NautilusBookmark *bookmark)
+ NautilusBookmark *bookmark)
{
- g_return_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
- g_return_if_fail (NAUTILUS_IS_BOOKMARK (bookmark));
+ g_return_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks));
+ g_return_if_fail (NAUTILUS_IS_BOOKMARK (bookmark));
- if (g_list_find_custom (bookmarks->list, bookmark,
- nautilus_bookmark_compare_with) != NULL) {
- return;
- }
+ if (g_list_find_custom (bookmarks->list, bookmark,
+ nautilus_bookmark_compare_with) != NULL)
+ {
+ return;
+ }
- insert_bookmark_internal (bookmarks, g_object_ref (bookmark), -1);
- nautilus_bookmark_list_save_file (bookmarks);
+ insert_bookmark_internal (bookmarks, g_object_ref (bookmark), -1);
+ nautilus_bookmark_list_save_file (bookmarks);
}
static void
@@ -313,307 +323,334 @@ process_next_op (NautilusBookmarkList *bookmarks);
static void
op_processed_cb (NautilusBookmarkList *self)
{
- g_queue_pop_tail (self->pending_ops);
+ g_queue_pop_tail (self->pending_ops);
- if (!g_queue_is_empty (self->pending_ops)) {
- process_next_op (self);
- }
+ if (!g_queue_is_empty (self->pending_ops))
+ {
+ process_next_op (self);
+ }
}
static void
-load_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+load_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusBookmarkList *self = NAUTILUS_BOOKMARK_LIST (source_object);
- GError *error = NULL;
- gchar *contents;
- char **lines;
- int i;
-
- contents = g_task_propagate_pointer (G_TASK (res), &error);
-
- if (error != NULL) {
- g_warning ("Unable to get contents of the bookmarks file: %s",
- error->message);
- g_error_free (error);
- op_processed_cb (self);
- return;
- }
-
- lines = g_strsplit (contents, "\n", -1);
- for (i = 0; lines[i]; i++) {
- /* Ignore empty or invalid lines that cannot be parsed properly */
- if (lines[i][0] != '\0' && lines[i][0] != ' ') {
- /* gtk 2.7/2.8 might have labels appended to bookmarks which are separated by a space */
- /* we must seperate the bookmark uri and the potential label */
- char *space, *label;
-
- label = NULL;
- space = strchr (lines[i], ' ');
- if (space) {
- *space = '\0';
- label = g_strdup (space + 1);
- }
-
- insert_bookmark_internal (self, new_bookmark_from_uri (lines[i], label), -1);
- g_free (label);
- }
- }
-
- g_signal_emit (self, signals[CHANGED], 0);
- op_processed_cb (self);
-
- g_strfreev (lines);
+ NautilusBookmarkList *self = NAUTILUS_BOOKMARK_LIST (source_object);
+ GError *error = NULL;
+ gchar *contents;
+ char **lines;
+ int i;
+
+ contents = g_task_propagate_pointer (G_TASK (res), &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Unable to get contents of the bookmarks file: %s",
+ error->message);
+ g_error_free (error);
+ op_processed_cb (self);
+ return;
+ }
+
+ lines = g_strsplit (contents, "\n", -1);
+ for (i = 0; lines[i]; i++)
+ {
+ /* Ignore empty or invalid lines that cannot be parsed properly */
+ if (lines[i][0] != '\0' && lines[i][0] != ' ')
+ {
+ /* gtk 2.7/2.8 might have labels appended to bookmarks which are separated by a space */
+ /* we must seperate the bookmark uri and the potential label */
+ char *space, *label;
+
+ label = NULL;
+ space = strchr (lines[i], ' ');
+ if (space)
+ {
+ *space = '\0';
+ label = g_strdup (space + 1);
+ }
+
+ insert_bookmark_internal (self, new_bookmark_from_uri (lines[i], label), -1);
+ g_free (label);
+ }
+ }
+
+ g_signal_emit (self, signals[CHANGED], 0);
+ op_processed_cb (self);
+
+ g_strfreev (lines);
}
static void
-load_io_thread (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
+load_io_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
- GFile *file;
- gchar *contents;
- GError *error = NULL;
-
- file = nautilus_bookmark_list_get_file ();
- if (!g_file_query_exists (file, NULL)) {
- g_object_unref (file);
- file = nautilus_bookmark_list_get_legacy_file ();
- }
-
- g_file_load_contents (file, NULL, &contents, NULL, NULL, &error);
- g_object_unref (file);
-
- if (error != NULL) {
- g_task_return_error (task, error);
- } else {
- g_task_return_pointer (task, contents, g_free);
- }
+ GFile *file;
+ gchar *contents;
+ GError *error = NULL;
+
+ file = nautilus_bookmark_list_get_file ();
+ if (!g_file_query_exists (file, NULL))
+ {
+ g_object_unref (file);
+ file = nautilus_bookmark_list_get_legacy_file ();
+ }
+
+ g_file_load_contents (file, NULL, &contents, NULL, NULL, &error);
+ g_object_unref (file);
+
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ }
+ else
+ {
+ g_task_return_pointer (task, contents, g_free);
+ }
}
static void
load_file_async (NautilusBookmarkList *self)
{
- GTask *task;
+ GTask *task;
- /* Wipe out old list. */
- clear (self);
+ /* Wipe out old list. */
+ clear (self);
- task = g_task_new (G_OBJECT (self),
- NULL,
- load_callback, NULL);
- g_task_run_in_thread (task, load_io_thread);
- g_object_unref (task);
+ task = g_task_new (G_OBJECT (self),
+ NULL,
+ load_callback, NULL);
+ g_task_run_in_thread (task, load_io_thread);
+ g_object_unref (task);
}
static void
-save_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+save_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusBookmarkList *self = NAUTILUS_BOOKMARK_LIST (source_object);
- GError *error = NULL;
- gboolean success;
- GFile *file;
-
- success = g_task_propagate_boolean (G_TASK (res), &error);
-
- if (error != NULL) {
- g_warning ("Unable to replace contents of the bookmarks file: %s",
- error->message);
- g_error_free (error);
- }
-
- /* g_file_replace_contents() returned FALSE, but did not set an error. */
- if (!success) {
- g_warning ("Unable to replace contents of the bookmarks file.");
- }
-
- /* re-enable bookmark file monitoring */
- file = nautilus_bookmark_list_get_file ();
- self->monitor = g_file_monitor_file (file, 0, NULL, NULL);
- g_object_unref (file);
-
- g_file_monitor_set_rate_limit (self->monitor, 1000);
- g_signal_connect (self->monitor, "changed",
- G_CALLBACK (bookmark_monitor_changed_cb), self);
-
- op_processed_cb (self);
+ NautilusBookmarkList *self = NAUTILUS_BOOKMARK_LIST (source_object);
+ GError *error = NULL;
+ gboolean success;
+ GFile *file;
+
+ success = g_task_propagate_boolean (G_TASK (res), &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Unable to replace contents of the bookmarks file: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ /* g_file_replace_contents() returned FALSE, but did not set an error. */
+ if (!success)
+ {
+ g_warning ("Unable to replace contents of the bookmarks file.");
+ }
+
+ /* re-enable bookmark file monitoring */
+ file = nautilus_bookmark_list_get_file ();
+ self->monitor = g_file_monitor_file (file, 0, NULL, NULL);
+ g_object_unref (file);
+
+ g_file_monitor_set_rate_limit (self->monitor, 1000);
+ g_signal_connect (self->monitor, "changed",
+ G_CALLBACK (bookmark_monitor_changed_cb), self);
+
+ op_processed_cb (self);
}
static void
-save_io_thread (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
+save_io_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
{
- gchar *contents, *path;
- GFile *parent, *file;
- gboolean success;
- GError *error = NULL;
-
- file = nautilus_bookmark_list_get_file ();
- parent = g_file_get_parent (file);
- path = g_file_get_path (parent);
- g_mkdir_with_parents (path, 0700);
- g_free (path);
- g_object_unref (parent);
-
- contents = (gchar *)g_task_get_task_data (task);
-
- success = g_file_replace_contents (file,
- contents, strlen (contents),
- NULL, FALSE, 0, NULL,
- NULL, &error);
-
- if (error != NULL) {
- g_task_return_error (task, error);
- } else {
- g_task_return_boolean (task, success);
- }
-
- g_object_unref (file);
+ gchar *contents, *path;
+ GFile *parent, *file;
+ gboolean success;
+ GError *error = NULL;
+
+ file = nautilus_bookmark_list_get_file ();
+ parent = g_file_get_parent (file);
+ path = g_file_get_path (parent);
+ g_mkdir_with_parents (path, 0700);
+ g_free (path);
+ g_object_unref (parent);
+
+ contents = (gchar *) g_task_get_task_data (task);
+
+ success = g_file_replace_contents (file,
+ contents, strlen (contents),
+ NULL, FALSE, 0, NULL,
+ NULL, &error);
+
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ }
+ else
+ {
+ g_task_return_boolean (task, success);
+ }
+
+ g_object_unref (file);
}
static void
save_file_async (NautilusBookmarkList *self)
{
- GTask *task;
- GString *bookmark_string;
- gchar *contents;
- GList *l;
-
- bookmark_string = g_string_new (NULL);
-
- /* temporarily disable bookmark file monitoring when writing file */
- if (self->monitor != NULL) {
- g_file_monitor_cancel (self->monitor);
- self->monitor = NULL;
- }
-
- for (l = self->list; l; l = l->next) {
- NautilusBookmark *bookmark;
-
- bookmark = NAUTILUS_BOOKMARK (l->data);
-
- /* make sure we save label if it has one for compatibility with GTK 2.7 and 2.8 */
- if (nautilus_bookmark_get_has_custom_name (bookmark)) {
- const char *label;
- char *uri;
- label = nautilus_bookmark_get_name (bookmark);
- uri = nautilus_bookmark_get_uri (bookmark);
- g_string_append_printf (bookmark_string,
- "%s %s\n", uri, label);
- g_free (uri);
- } else {
- char *uri;
- uri = nautilus_bookmark_get_uri (bookmark);
- g_string_append_printf (bookmark_string, "%s\n", uri);
- g_free (uri);
- }
- }
-
- task = g_task_new (G_OBJECT (self),
- NULL,
- save_callback, NULL);
- contents = g_string_free (bookmark_string, FALSE);
- g_task_set_task_data (task, contents, g_free);
-
- g_task_run_in_thread (task, save_io_thread);
- g_object_unref (task);
+ GTask *task;
+ GString *bookmark_string;
+ gchar *contents;
+ GList *l;
+
+ bookmark_string = g_string_new (NULL);
+
+ /* temporarily disable bookmark file monitoring when writing file */
+ if (self->monitor != NULL)
+ {
+ g_file_monitor_cancel (self->monitor);
+ self->monitor = NULL;
+ }
+
+ for (l = self->list; l; l = l->next)
+ {
+ NautilusBookmark *bookmark;
+
+ bookmark = NAUTILUS_BOOKMARK (l->data);
+
+ /* make sure we save label if it has one for compatibility with GTK 2.7 and 2.8 */
+ if (nautilus_bookmark_get_has_custom_name (bookmark))
+ {
+ const char *label;
+ char *uri;
+ label = nautilus_bookmark_get_name (bookmark);
+ uri = nautilus_bookmark_get_uri (bookmark);
+ g_string_append_printf (bookmark_string,
+ "%s %s\n", uri, label);
+ g_free (uri);
+ }
+ else
+ {
+ char *uri;
+ uri = nautilus_bookmark_get_uri (bookmark);
+ g_string_append_printf (bookmark_string, "%s\n", uri);
+ g_free (uri);
+ }
+ }
+
+ task = g_task_new (G_OBJECT (self),
+ NULL,
+ save_callback, NULL);
+ contents = g_string_free (bookmark_string, FALSE);
+ g_task_set_task_data (task, contents, g_free);
+
+ g_task_run_in_thread (task, save_io_thread);
+ g_object_unref (task);
}
static void
process_next_op (NautilusBookmarkList *bookmarks)
{
- gint op;
-
- op = GPOINTER_TO_INT (g_queue_peek_tail (bookmarks->pending_ops));
-
- if (op == LOAD_JOB) {
- load_file_async (bookmarks);
- } else {
- save_file_async (bookmarks);
- }
+ gint op;
+
+ op = GPOINTER_TO_INT (g_queue_peek_tail (bookmarks->pending_ops));
+
+ if (op == LOAD_JOB)
+ {
+ load_file_async (bookmarks);
+ }
+ else
+ {
+ save_file_async (bookmarks);
+ }
}
/**
* nautilus_bookmark_list_load_file:
- *
+ *
* Reads bookmarks from file, clobbering contents in memory.
* @bookmarks: the list of bookmarks to fill with file contents.
**/
static void
nautilus_bookmark_list_load_file (NautilusBookmarkList *bookmarks)
{
- g_queue_push_head (bookmarks->pending_ops, GINT_TO_POINTER (LOAD_JOB));
+ g_queue_push_head (bookmarks->pending_ops, GINT_TO_POINTER (LOAD_JOB));
- if (g_queue_get_length (bookmarks->pending_ops) == 1) {
- process_next_op (bookmarks);
- }
+ if (g_queue_get_length (bookmarks->pending_ops) == 1)
+ {
+ process_next_op (bookmarks);
+ }
}
/**
* nautilus_bookmark_list_save_file:
- *
+ *
* Save bookmarks to disk.
* @bookmarks: the list of bookmarks to save.
**/
static void
nautilus_bookmark_list_save_file (NautilusBookmarkList *bookmarks)
{
- g_signal_emit (bookmarks, signals[CHANGED], 0);
+ g_signal_emit (bookmarks, signals[CHANGED], 0);
- g_queue_push_head (bookmarks->pending_ops, GINT_TO_POINTER (SAVE_JOB));
+ g_queue_push_head (bookmarks->pending_ops, GINT_TO_POINTER (SAVE_JOB));
- if (g_queue_get_length (bookmarks->pending_ops) == 1) {
- process_next_op (bookmarks);
- }
+ if (g_queue_get_length (bookmarks->pending_ops) == 1)
+ {
+ process_next_op (bookmarks);
+ }
}
gboolean
nautilus_bookmark_list_can_bookmark_location (NautilusBookmarkList *list,
- GFile *location)
+ GFile *location)
{
- NautilusBookmark *bookmark;
- gboolean is_builtin;
+ NautilusBookmark *bookmark;
+ gboolean is_builtin;
- if (nautilus_bookmark_list_item_with_location (list, location, NULL)) {
- return FALSE;
- }
+ if (nautilus_bookmark_list_item_with_location (list, location, NULL))
+ {
+ return FALSE;
+ }
- if (nautilus_is_home_directory (location)) {
- return FALSE;
- }
+ if (nautilus_is_home_directory (location))
+ {
+ return FALSE;
+ }
- if (nautilus_is_search_directory (location)) {
- return FALSE;
- }
+ if (nautilus_is_search_directory (location))
+ {
+ return FALSE;
+ }
- bookmark = nautilus_bookmark_new (location, NULL);
- is_builtin = nautilus_bookmark_get_is_builtin (bookmark);
- g_object_unref (bookmark);
+ bookmark = nautilus_bookmark_new (location, NULL);
+ is_builtin = nautilus_bookmark_get_is_builtin (bookmark);
+ g_object_unref (bookmark);
- return !is_builtin;
+ return !is_builtin;
}
/**
* nautilus_bookmark_list_new:
- *
+ *
* Create a new bookmark_list, with contents read from disk.
- *
+ *
* Return value: A pointer to the new widget.
**/
NautilusBookmarkList *
nautilus_bookmark_list_new (void)
{
- NautilusBookmarkList *list;
+ NautilusBookmarkList *list;
- list = NAUTILUS_BOOKMARK_LIST (g_object_new (NAUTILUS_TYPE_BOOKMARK_LIST, NULL));
+ list = NAUTILUS_BOOKMARK_LIST (g_object_new (NAUTILUS_TYPE_BOOKMARK_LIST, NULL));
- return list;
+ return list;
}
/**
@@ -625,7 +662,7 @@ nautilus_bookmark_list_new (void)
GList *
nautilus_bookmark_list_get_all (NautilusBookmarkList *bookmarks)
{
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK_LIST (bookmarks), NULL);
- return bookmarks->list;
+ return bookmarks->list;
}
diff --git a/src/nautilus-bookmark.c b/src/nautilus-bookmark.c
index 29a36f9d1..6a7e93c3c 100644
--- a/src/nautilus-bookmark.c
+++ b/src/nautilus-bookmark.c
@@ -1,4 +1,3 @@
-
/* nautilus-bookmark.c - implementation of individual bookmarks.
*
* Copyright (C) 1999, 2000 Eazel, Inc.
@@ -39,600 +38,688 @@
#define DEBUG_FLAG NAUTILUS_DEBUG_BOOKMARKS
#include "nautilus-debug.h"
-enum {
- CONTENTS_CHANGED,
- LAST_SIGNAL
+enum
+{
+ CONTENTS_CHANGED,
+ LAST_SIGNAL
};
-enum {
- PROP_NAME = 1,
- PROP_CUSTOM_NAME,
- PROP_LOCATION,
- PROP_ICON,
- PROP_SYMBOLIC_ICON,
- NUM_PROPERTIES
+enum
+{
+ PROP_NAME = 1,
+ PROP_CUSTOM_NAME,
+ PROP_LOCATION,
+ PROP_ICON,
+ PROP_SYMBOLIC_ICON,
+ NUM_PROPERTIES
};
#define ELLIPSISED_MENU_ITEM_MIN_CHARS 32
-static GParamSpec* properties[NUM_PROPERTIES] = { NULL };
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL };
static guint signals[LAST_SIGNAL];
struct NautilusBookmarkDetails
{
- char *name;
- gboolean has_custom_name;
- GFile *location;
- GIcon *icon;
- GIcon *symbolic_icon;
- NautilusFile *file;
-
- char *scroll_file;
-
- gboolean exists;
- guint exists_id;
- GCancellable *cancellable;
+ char *name;
+ gboolean has_custom_name;
+ GFile *location;
+ GIcon *icon;
+ GIcon *symbolic_icon;
+ NautilusFile *file;
+
+ char *scroll_file;
+
+ gboolean exists;
+ guint exists_id;
+ GCancellable *cancellable;
};
-static void nautilus_bookmark_disconnect_file (NautilusBookmark *file);
+static void nautilus_bookmark_disconnect_file (NautilusBookmark *file);
G_DEFINE_TYPE (NautilusBookmark, nautilus_bookmark, G_TYPE_OBJECT);
static void
nautilus_bookmark_set_name_internal (NautilusBookmark *bookmark,
- const char *new_name)
+ const char *new_name)
{
- if (g_strcmp0 (bookmark->details->name, new_name) != 0) {
- g_free (bookmark->details->name);
- bookmark->details->name = g_strdup (new_name);
+ if (g_strcmp0 (bookmark->details->name, new_name) != 0)
+ {
+ g_free (bookmark->details->name);
+ bookmark->details->name = g_strdup (new_name);
- g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_NAME]);
- }
+ g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_NAME]);
+ }
}
static void
bookmark_set_name_from_ready_file (NautilusBookmark *self,
- NautilusFile *file)
-{
- gchar *display_name;
-
- if (self->details->has_custom_name) {
- return;
- }
-
- display_name = nautilus_file_get_display_name (self->details->file);
-
- if (nautilus_file_is_other_locations (self->details->file)) {
- nautilus_bookmark_set_name_internal (self, _("Other Locations"));
- } else if (nautilus_file_is_home (self->details->file)) {
- nautilus_bookmark_set_name_internal (self, _("Home"));
- } else if (g_strcmp0 (self->details->name, display_name) != 0) {
- nautilus_bookmark_set_name_internal (self, display_name);
- DEBUG ("%s: name changed to %s", nautilus_bookmark_get_name (self), display_name);
- }
-
- g_free (display_name);
+ NautilusFile *file)
+{
+ gchar *display_name;
+
+ if (self->details->has_custom_name)
+ {
+ return;
+ }
+
+ display_name = nautilus_file_get_display_name (self->details->file);
+
+ if (nautilus_file_is_other_locations (self->details->file))
+ {
+ nautilus_bookmark_set_name_internal (self, _("Other Locations"));
+ }
+ else if (nautilus_file_is_home (self->details->file))
+ {
+ nautilus_bookmark_set_name_internal (self, _("Home"));
+ }
+ else if (g_strcmp0 (self->details->name, display_name) != 0)
+ {
+ nautilus_bookmark_set_name_internal (self, display_name);
+ DEBUG ("%s: name changed to %s", nautilus_bookmark_get_name (self), display_name);
+ }
+
+ g_free (display_name);
}
static void
-bookmark_file_changed_callback (NautilusFile *file,
- NautilusBookmark *bookmark)
-{
- GFile *location;
-
- g_assert (file == bookmark->details->file);
-
- DEBUG ("%s: file changed", nautilus_bookmark_get_name (bookmark));
-
- location = nautilus_file_get_location (file);
-
- if (!g_file_equal (bookmark->details->location, location) &&
- !nautilus_file_is_in_trash (file)) {
- DEBUG ("%s: file got moved", nautilus_bookmark_get_name (bookmark));
-
- g_object_unref (bookmark->details->location);
- bookmark->details->location = g_object_ref (location);
-
- g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_LOCATION]);
- g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
- }
-
- g_object_unref (location);
-
- if (nautilus_file_is_gone (file) ||
- nautilus_file_is_in_trash (file)) {
- /* The file we were monitoring has been trashed, deleted,
- * or moved in a way that we didn't notice. We should make
- * a spanking new NautilusFile object for this
- * location so if a new file appears in this place
- * we will notice. However, we can't immediately do so
- * because creating a new NautilusFile directly as a result
- * of noticing a file goes away may trigger i/o on that file
- * again, noticeing it is gone, leading to a loop.
- * So, the new NautilusFile is created when the bookmark
- * is used again. However, this is not really a problem, as
- * we don't want to change the icon or anything about the
- * bookmark just because its not there anymore.
- */
- DEBUG ("%s: trashed", nautilus_bookmark_get_name (bookmark));
- nautilus_bookmark_disconnect_file (bookmark);
- } else {
- bookmark_set_name_from_ready_file (bookmark, file);
- }
+bookmark_file_changed_callback (NautilusFile *file,
+ NautilusBookmark *bookmark)
+{
+ GFile *location;
+
+ g_assert (file == bookmark->details->file);
+
+ DEBUG ("%s: file changed", nautilus_bookmark_get_name (bookmark));
+
+ location = nautilus_file_get_location (file);
+
+ if (!g_file_equal (bookmark->details->location, location) &&
+ !nautilus_file_is_in_trash (file))
+ {
+ DEBUG ("%s: file got moved", nautilus_bookmark_get_name (bookmark));
+
+ g_object_unref (bookmark->details->location);
+ bookmark->details->location = g_object_ref (location);
+
+ g_object_notify_by_pspec (G_OBJECT (bookmark), properties[PROP_LOCATION]);
+ g_signal_emit (bookmark, signals[CONTENTS_CHANGED], 0);
+ }
+
+ g_object_unref (location);
+
+ if (nautilus_file_is_gone (file) ||
+ nautilus_file_is_in_trash (file))
+ {
+ /* The file we were monitoring has been trashed, deleted,
+ * or moved in a way that we didn't notice. We should make
+ * a spanking new NautilusFile object for this
+ * location so if a new file appears in this place
+ * we will notice. However, we can't immediately do so
+ * because creating a new NautilusFile directly as a result
+ * of noticing a file goes away may trigger i/o on that file
+ * again, noticeing it is gone, leading to a loop.
+ * So, the new NautilusFile is created when the bookmark
+ * is used again. However, this is not really a problem, as
+ * we don't want to change the icon or anything about the
+ * bookmark just because its not there anymore.
+ */
+ DEBUG ("%s: trashed", nautilus_bookmark_get_name (bookmark));
+ nautilus_bookmark_disconnect_file (bookmark);
+ }
+ else
+ {
+ bookmark_set_name_from_ready_file (bookmark, file);
+ }
}
static void
-apply_warning_emblem (GIcon **base,
- gboolean symbolic)
+apply_warning_emblem (GIcon **base,
+ gboolean symbolic)
{
- GIcon *warning, *emblemed_icon;
- GEmblem *emblem;
+ GIcon *warning, *emblemed_icon;
+ GEmblem *emblem;
- if (symbolic) {
- warning = g_themed_icon_new ("dialog-warning-symbolic");
- } else {
- warning = g_themed_icon_new ("dialog-warning");
- }
+ if (symbolic)
+ {
+ warning = g_themed_icon_new ("dialog-warning-symbolic");
+ }
+ else
+ {
+ warning = g_themed_icon_new ("dialog-warning");
+ }
- emblem = g_emblem_new (warning);
- emblemed_icon = g_emblemed_icon_new (*base, emblem);
+ emblem = g_emblem_new (warning);
+ emblemed_icon = g_emblemed_icon_new (*base, emblem);
- g_object_unref (emblem);
- g_object_unref (warning);
- g_object_unref (*base);
+ g_object_unref (emblem);
+ g_object_unref (warning);
+ g_object_unref (*base);
- *base = emblemed_icon;
+ *base = emblemed_icon;
}
gboolean
nautilus_bookmark_get_is_builtin (NautilusBookmark *bookmark)
{
- GUserDirectory xdg_type;
+ GUserDirectory xdg_type;
- /* if this is not an XDG dir, it's never builtin */
- if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type)) {
- return FALSE;
- }
+ /* if this is not an XDG dir, it's never builtin */
+ if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type))
+ {
+ return FALSE;
+ }
- /* exclude XDG locations which are not in our builtin list */
- if (xdg_type == G_USER_DIRECTORY_DESKTOP &&
- !g_settings_get_boolean (gnome_background_preferences, NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
- return FALSE;
- }
+ /* exclude XDG locations which are not in our builtin list */
+ if (xdg_type == G_USER_DIRECTORY_DESKTOP &&
+ !g_settings_get_boolean (gnome_background_preferences, NAUTILUS_PREFERENCES_SHOW_DESKTOP))
+ {
+ return FALSE;
+ }
- return (xdg_type != G_USER_DIRECTORY_TEMPLATES) && (xdg_type != G_USER_DIRECTORY_PUBLIC_SHARE);
+ return (xdg_type != G_USER_DIRECTORY_TEMPLATES) && (xdg_type != G_USER_DIRECTORY_PUBLIC_SHARE);
}
gboolean
nautilus_bookmark_get_xdg_type (NautilusBookmark *bookmark,
- GUserDirectory *directory)
-{
- gboolean match;
- GFile *location;
- const gchar *path;
- GUserDirectory dir;
-
- match = FALSE;
-
- for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++) {
- path = g_get_user_special_dir (dir);
- if (!path) {
- continue;
- }
-
- location = g_file_new_for_path (path);
- match = g_file_equal (location, bookmark->details->location);
- g_object_unref (location);
-
- if (match) {
- break;
- }
- }
-
- if (match && directory != NULL) {
- *directory = dir;
- }
-
- return match;
+ GUserDirectory *directory)
+{
+ gboolean match;
+ GFile *location;
+ const gchar *path;
+ GUserDirectory dir;
+
+ match = FALSE;
+
+ for (dir = 0; dir < G_USER_N_DIRECTORIES; dir++)
+ {
+ path = g_get_user_special_dir (dir);
+ if (!path)
+ {
+ continue;
+ }
+
+ location = g_file_new_for_path (path);
+ match = g_file_equal (location, bookmark->details->location);
+ g_object_unref (location);
+
+ if (match)
+ {
+ break;
+ }
+ }
+
+ if (match && directory != NULL)
+ {
+ *directory = dir;
+ }
+
+ return match;
}
static GIcon *
get_native_icon (NautilusBookmark *bookmark,
- gboolean symbolic)
-{
- GUserDirectory xdg_type;
- GIcon *icon = NULL;
-
- if (bookmark->details->file == NULL) {
- goto out;
- }
-
- if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type)) {
- goto out;
- }
-
- if (xdg_type < G_USER_N_DIRECTORIES) {
- if (symbolic) {
- icon = nautilus_special_directory_get_symbolic_icon (xdg_type);
- } else {
- icon = nautilus_special_directory_get_icon (xdg_type);
- }
- }
-
- out:
- if (icon == NULL) {
- if (symbolic) {
- icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER);
- } else {
- icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER);
- }
- }
-
- return icon;
+ gboolean symbolic)
+{
+ GUserDirectory xdg_type;
+ GIcon *icon = NULL;
+
+ if (bookmark->details->file == NULL)
+ {
+ goto out;
+ }
+
+ if (!nautilus_bookmark_get_xdg_type (bookmark, &xdg_type))
+ {
+ goto out;
+ }
+
+ if (xdg_type < G_USER_N_DIRECTORIES)
+ {
+ if (symbolic)
+ {
+ icon = nautilus_special_directory_get_symbolic_icon (xdg_type);
+ }
+ else
+ {
+ icon = nautilus_special_directory_get_icon (xdg_type);
+ }
+ }
+
+out:
+ if (icon == NULL)
+ {
+ if (symbolic)
+ {
+ icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER);
+ }
+ else
+ {
+ icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER);
+ }
+ }
+
+ return icon;
}
static void
nautilus_bookmark_set_icon_to_default (NautilusBookmark *bookmark)
{
- GIcon *icon, *symbolic_icon;
- char *uri;
-
- if (g_file_is_native (bookmark->details->location)) {
- symbolic_icon = get_native_icon (bookmark, TRUE);
- icon = get_native_icon (bookmark, FALSE);
- } else {
- uri = nautilus_bookmark_get_uri (bookmark);
- if (g_str_has_prefix (uri, EEL_SEARCH_URI)) {
- symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_SAVED_SEARCH);
- icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_SAVED_SEARCH);
- } else {
- symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE);
- icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_REMOTE);
- }
- g_free (uri);
- }
-
- if (!bookmark->details->exists) {
- DEBUG ("%s: file does not exist, add emblem", nautilus_bookmark_get_name (bookmark));
-
- apply_warning_emblem (&icon, FALSE);
- apply_warning_emblem (&symbolic_icon, TRUE);
- }
-
- DEBUG ("%s: setting icon to default", nautilus_bookmark_get_name (bookmark));
-
- g_object_set (bookmark,
- "icon", icon,
- "symbolic-icon", symbolic_icon,
- NULL);
-
- g_object_unref (icon);
- g_object_unref (symbolic_icon);
+ GIcon *icon, *symbolic_icon;
+ char *uri;
+
+ if (g_file_is_native (bookmark->details->location))
+ {
+ symbolic_icon = get_native_icon (bookmark, TRUE);
+ icon = get_native_icon (bookmark, FALSE);
+ }
+ else
+ {
+ uri = nautilus_bookmark_get_uri (bookmark);
+ if (g_str_has_prefix (uri, EEL_SEARCH_URI))
+ {
+ symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_SAVED_SEARCH);
+ icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_SAVED_SEARCH);
+ }
+ else
+ {
+ symbolic_icon = g_themed_icon_new (NAUTILUS_ICON_FOLDER_REMOTE);
+ icon = g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_REMOTE);
+ }
+ g_free (uri);
+ }
+
+ if (!bookmark->details->exists)
+ {
+ DEBUG ("%s: file does not exist, add emblem", nautilus_bookmark_get_name (bookmark));
+
+ apply_warning_emblem (&icon, FALSE);
+ apply_warning_emblem (&symbolic_icon, TRUE);
+ }
+
+ DEBUG ("%s: setting icon to default", nautilus_bookmark_get_name (bookmark));
+
+ g_object_set (bookmark,
+ "icon", icon,
+ "symbolic-icon", symbolic_icon,
+ NULL);
+
+ g_object_unref (icon);
+ g_object_unref (symbolic_icon);
}
static void
nautilus_bookmark_disconnect_file (NautilusBookmark *bookmark)
{
- if (bookmark->details->file != NULL) {
- DEBUG ("%s: disconnecting file",
- nautilus_bookmark_get_name (bookmark));
-
- g_signal_handlers_disconnect_by_func (bookmark->details->file,
- G_CALLBACK (bookmark_file_changed_callback),
- bookmark);
- g_clear_object (&bookmark->details->file);
- }
-
- if (bookmark->details->cancellable != NULL) {
- g_cancellable_cancel (bookmark->details->cancellable);
- g_clear_object (&bookmark->details->cancellable);
- }
-
- if (bookmark->details->exists_id != 0) {
- g_source_remove (bookmark->details->exists_id);
- bookmark->details->exists_id = 0;
- }
+ if (bookmark->details->file != NULL)
+ {
+ DEBUG ("%s: disconnecting file",
+ nautilus_bookmark_get_name (bookmark));
+
+ g_signal_handlers_disconnect_by_func (bookmark->details->file,
+ G_CALLBACK (bookmark_file_changed_callback),
+ bookmark);
+ g_clear_object (&bookmark->details->file);
+ }
+
+ if (bookmark->details->cancellable != NULL)
+ {
+ g_cancellable_cancel (bookmark->details->cancellable);
+ g_clear_object (&bookmark->details->cancellable);
+ }
+
+ if (bookmark->details->exists_id != 0)
+ {
+ g_source_remove (bookmark->details->exists_id);
+ bookmark->details->exists_id = 0;
+ }
}
static void
nautilus_bookmark_connect_file (NautilusBookmark *bookmark)
{
- if (bookmark->details->file != NULL) {
- DEBUG ("%s: file already connected, returning",
- nautilus_bookmark_get_name (bookmark));
- return;
- }
-
- if (bookmark->details->exists) {
- DEBUG ("%s: creating file", nautilus_bookmark_get_name (bookmark));
-
- bookmark->details->file = nautilus_file_get (bookmark->details->location);
- g_assert (!nautilus_file_is_gone (bookmark->details->file));
-
- g_signal_connect_object (bookmark->details->file, "changed",
- G_CALLBACK (bookmark_file_changed_callback), bookmark, 0);
- }
-
- if (bookmark->details->icon == NULL ||
- bookmark->details->symbolic_icon == NULL) {
- nautilus_bookmark_set_icon_to_default (bookmark);
- }
-
- if (bookmark->details->file != NULL &&
- nautilus_file_check_if_ready (bookmark->details->file, NAUTILUS_FILE_ATTRIBUTE_INFO)) {
- bookmark_set_name_from_ready_file (bookmark, bookmark->details->file);
- }
-
- if (bookmark->details->name == NULL) {
- bookmark->details->name = nautilus_compute_title_for_location (bookmark->details->location);
- }
+ if (bookmark->details->file != NULL)
+ {
+ DEBUG ("%s: file already connected, returning",
+ nautilus_bookmark_get_name (bookmark));
+ return;
+ }
+
+ if (bookmark->details->exists)
+ {
+ DEBUG ("%s: creating file", nautilus_bookmark_get_name (bookmark));
+
+ bookmark->details->file = nautilus_file_get (bookmark->details->location);
+ g_assert (!nautilus_file_is_gone (bookmark->details->file));
+
+ g_signal_connect_object (bookmark->details->file, "changed",
+ G_CALLBACK (bookmark_file_changed_callback), bookmark, 0);
+ }
+
+ if (bookmark->details->icon == NULL ||
+ bookmark->details->symbolic_icon == NULL)
+ {
+ nautilus_bookmark_set_icon_to_default (bookmark);
+ }
+
+ if (bookmark->details->file != NULL &&
+ nautilus_file_check_if_ready (bookmark->details->file, NAUTILUS_FILE_ATTRIBUTE_INFO))
+ {
+ bookmark_set_name_from_ready_file (bookmark, bookmark->details->file);
+ }
+
+ if (bookmark->details->name == NULL)
+ {
+ bookmark->details->name = nautilus_compute_title_for_location (bookmark->details->location);
+ }
}
static void
nautilus_bookmark_set_exists (NautilusBookmark *bookmark,
- gboolean exists)
+ gboolean exists)
{
- if (bookmark->details->exists == exists) {
- return;
- }
+ if (bookmark->details->exists == exists)
+ {
+ return;
+ }
- bookmark->details->exists = exists;
- DEBUG ("%s: setting bookmark to exist: %d\n",
- nautilus_bookmark_get_name (bookmark), exists);
+ bookmark->details->exists = exists;
+ DEBUG ("%s: setting bookmark to exist: %d\n",
+ nautilus_bookmark_get_name (bookmark), exists);
- /* refresh icon */
- nautilus_bookmark_set_icon_to_default (bookmark);
+ /* refresh icon */
+ nautilus_bookmark_set_icon_to_default (bookmark);
}
static gboolean
exists_non_native_idle_cb (gpointer user_data)
{
- NautilusBookmark *bookmark = user_data;
- bookmark->details->exists_id = 0;
- nautilus_bookmark_set_exists (bookmark, FALSE);
+ NautilusBookmark *bookmark = user_data;
+ bookmark->details->exists_id = 0;
+ nautilus_bookmark_set_exists (bookmark, FALSE);
- return FALSE;
+ return FALSE;
}
static void
-exists_query_info_ready_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- GFileInfo *info;
- NautilusBookmark *bookmark;
- GError *error = NULL;
- gboolean exists = FALSE;
-
- info = g_file_query_info_finish (G_FILE (source), res, &error);
- if (!info && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- g_clear_error (&error);
- return;
- }
-
- g_clear_error (&error);
- bookmark = user_data;
-
- if (info) {
- exists = TRUE;
-
- g_object_unref (info);
- g_clear_object (&bookmark->details->cancellable);
- }
-
- nautilus_bookmark_set_exists (bookmark, exists);
+exists_query_info_ready_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GFileInfo *info;
+ NautilusBookmark *bookmark;
+ GError *error = NULL;
+ gboolean exists = FALSE;
+
+ info = g_file_query_info_finish (G_FILE (source), res, &error);
+ if (!info && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ g_clear_error (&error);
+ return;
+ }
+
+ g_clear_error (&error);
+ bookmark = user_data;
+
+ if (info)
+ {
+ exists = TRUE;
+
+ g_object_unref (info);
+ g_clear_object (&bookmark->details->cancellable);
+ }
+
+ nautilus_bookmark_set_exists (bookmark, exists);
}
static void
nautilus_bookmark_update_exists (NautilusBookmark *bookmark)
{
- /* Convert to a path, returning FALSE if not local. */
- if (!g_file_is_native (bookmark->details->location) &&
- bookmark->details->exists_id == 0) {
- bookmark->details->exists_id =
- g_idle_add (exists_non_native_idle_cb, bookmark);
- return;
- }
-
- if (bookmark->details->cancellable != NULL) {
- return;
- }
-
- bookmark->details->cancellable = g_cancellable_new ();
- g_file_query_info_async (bookmark->details->location,
- G_FILE_ATTRIBUTE_STANDARD_TYPE,
- 0, G_PRIORITY_DEFAULT,
- bookmark->details->cancellable,
- exists_query_info_ready_cb, bookmark);
+ /* Convert to a path, returning FALSE if not local. */
+ if (!g_file_is_native (bookmark->details->location) &&
+ bookmark->details->exists_id == 0)
+ {
+ bookmark->details->exists_id =
+ g_idle_add (exists_non_native_idle_cb, bookmark);
+ return;
+ }
+
+ if (bookmark->details->cancellable != NULL)
+ {
+ return;
+ }
+
+ bookmark->details->cancellable = g_cancellable_new ();
+ g_file_query_info_async (bookmark->details->location,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ 0, G_PRIORITY_DEFAULT,
+ bookmark->details->cancellable,
+ exists_query_info_ready_cb, bookmark);
}
/* GObject methods */
static void
-nautilus_bookmark_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NautilusBookmark *self = NAUTILUS_BOOKMARK (object);
- GIcon *new_icon;
-
- switch (property_id) {
- case PROP_ICON:
- new_icon = g_value_get_object (value);
-
- if (new_icon != NULL && !g_icon_equal (self->details->icon, new_icon)) {
- g_clear_object (&self->details->icon);
- self->details->icon = g_object_ref (new_icon);
- }
-
- break;
- case PROP_SYMBOLIC_ICON:
- new_icon = g_value_get_object (value);
-
- if (new_icon != NULL && !g_icon_equal (self->details->symbolic_icon, new_icon)) {
- g_clear_object (&self->details->symbolic_icon);
- self->details->symbolic_icon = g_object_ref (new_icon);
- }
-
- break;
- case PROP_LOCATION:
- self->details->location = g_value_dup_object (value);
- break;
- case PROP_CUSTOM_NAME:
- self->details->has_custom_name = g_value_get_boolean (value);
- break;
- case PROP_NAME:
- nautilus_bookmark_set_name_internal (self, g_value_get_string (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+nautilus_bookmark_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusBookmark *self = NAUTILUS_BOOKMARK (object);
+ GIcon *new_icon;
+
+ switch (property_id)
+ {
+ case PROP_ICON:
+ {
+ new_icon = g_value_get_object (value);
+
+ if (new_icon != NULL && !g_icon_equal (self->details->icon, new_icon))
+ {
+ g_clear_object (&self->details->icon);
+ self->details->icon = g_object_ref (new_icon);
+ }
+ }
+ break;
+
+ case PROP_SYMBOLIC_ICON:
+ {
+ new_icon = g_value_get_object (value);
+
+ if (new_icon != NULL && !g_icon_equal (self->details->symbolic_icon, new_icon))
+ {
+ g_clear_object (&self->details->symbolic_icon);
+ self->details->symbolic_icon = g_object_ref (new_icon);
+ }
+ }
+ break;
+
+ case PROP_LOCATION:
+ {
+ self->details->location = g_value_dup_object (value);
+ }
+ break;
+
+ case PROP_CUSTOM_NAME:
+ {
+ self->details->has_custom_name = g_value_get_boolean (value);
+ }
+ break;
+
+ case PROP_NAME:
+ {
+ nautilus_bookmark_set_name_internal (self, g_value_get_string (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_bookmark_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NautilusBookmark *self = NAUTILUS_BOOKMARK (object);
-
- switch (property_id) {
- case PROP_NAME:
- g_value_set_string (value, self->details->name);
- break;
- case PROP_ICON:
- g_value_set_object (value, self->details->icon);
- break;
- case PROP_SYMBOLIC_ICON:
- g_value_set_object (value, self->details->symbolic_icon);
- break;
- case PROP_LOCATION:
- g_value_set_object (value, self->details->location);
- break;
- case PROP_CUSTOM_NAME:
- g_value_set_boolean (value, self->details->has_custom_name);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+nautilus_bookmark_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusBookmark *self = NAUTILUS_BOOKMARK (object);
+
+ switch (property_id)
+ {
+ case PROP_NAME:
+ {
+ g_value_set_string (value, self->details->name);
+ }
+ break;
+
+ case PROP_ICON:
+ {
+ g_value_set_object (value, self->details->icon);
+ }
+ break;
+
+ case PROP_SYMBOLIC_ICON:
+ {
+ g_value_set_object (value, self->details->symbolic_icon);
+ }
+ break;
+
+ case PROP_LOCATION:
+ {
+ g_value_set_object (value, self->details->location);
+ }
+ break;
+
+ case PROP_CUSTOM_NAME:
+ {
+ g_value_set_boolean (value, self->details->has_custom_name);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_bookmark_finalize (GObject *object)
{
- NautilusBookmark *bookmark;
+ NautilusBookmark *bookmark;
- g_assert (NAUTILUS_IS_BOOKMARK (object));
+ g_assert (NAUTILUS_IS_BOOKMARK (object));
- bookmark = NAUTILUS_BOOKMARK (object);
+ bookmark = NAUTILUS_BOOKMARK (object);
- nautilus_bookmark_disconnect_file (bookmark);
+ nautilus_bookmark_disconnect_file (bookmark);
- g_object_unref (bookmark->details->location);
- g_clear_object (&bookmark->details->icon);
- g_clear_object (&bookmark->details->symbolic_icon);
+ g_object_unref (bookmark->details->location);
+ g_clear_object (&bookmark->details->icon);
+ g_clear_object (&bookmark->details->symbolic_icon);
- g_free (bookmark->details->name);
- g_free (bookmark->details->scroll_file);
+ g_free (bookmark->details->name);
+ g_free (bookmark->details->scroll_file);
- G_OBJECT_CLASS (nautilus_bookmark_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_bookmark_parent_class)->finalize (object);
}
static void
nautilus_bookmark_constructed (GObject *obj)
{
- NautilusBookmark *self = NAUTILUS_BOOKMARK (obj);
+ NautilusBookmark *self = NAUTILUS_BOOKMARK (obj);
- nautilus_bookmark_connect_file (self);
- nautilus_bookmark_update_exists (self);
+ nautilus_bookmark_connect_file (self);
+ nautilus_bookmark_update_exists (self);
}
static void
nautilus_bookmark_class_init (NautilusBookmarkClass *class)
{
- GObjectClass *oclass = G_OBJECT_CLASS (class);
-
- oclass->finalize = nautilus_bookmark_finalize;
- oclass->get_property = nautilus_bookmark_get_property;
- oclass->set_property = nautilus_bookmark_set_property;
- oclass->constructed = nautilus_bookmark_constructed;
-
- signals[CONTENTS_CHANGED] =
- g_signal_new ("contents-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusBookmarkClass, contents_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- properties[PROP_NAME] =
- g_param_spec_string ("name",
- "Bookmark's name",
- "The name of this bookmark",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT);
-
- properties[PROP_CUSTOM_NAME] =
- g_param_spec_boolean ("custom-name",
- "Whether the bookmark has a custom name",
- "Whether the bookmark has a custom name",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT);
-
- properties[PROP_LOCATION] =
- g_param_spec_object ("location",
- "Bookmark's location",
- "The location of this bookmark",
- G_TYPE_FILE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
-
- properties[PROP_ICON] =
- g_param_spec_object ("icon",
- "Bookmark's icon",
- "The icon of this bookmark",
- G_TYPE_ICON,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- properties[PROP_SYMBOLIC_ICON] =
- g_param_spec_object ("symbolic-icon",
- "Bookmark's symbolic icon",
- "The symbolic icon of this bookmark",
- G_TYPE_ICON,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
-
- g_type_class_add_private (class, sizeof (NautilusBookmarkDetails));
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+
+ oclass->finalize = nautilus_bookmark_finalize;
+ oclass->get_property = nautilus_bookmark_get_property;
+ oclass->set_property = nautilus_bookmark_set_property;
+ oclass->constructed = nautilus_bookmark_constructed;
+
+ signals[CONTENTS_CHANGED] =
+ g_signal_new ("contents-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusBookmarkClass, contents_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ properties[PROP_NAME] =
+ g_param_spec_string ("name",
+ "Bookmark's name",
+ "The name of this bookmark",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT);
+
+ properties[PROP_CUSTOM_NAME] =
+ g_param_spec_boolean ("custom-name",
+ "Whether the bookmark has a custom name",
+ "Whether the bookmark has a custom name",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT);
+
+ properties[PROP_LOCATION] =
+ g_param_spec_object ("location",
+ "Bookmark's location",
+ "The location of this bookmark",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+
+ properties[PROP_ICON] =
+ g_param_spec_object ("icon",
+ "Bookmark's icon",
+ "The icon of this bookmark",
+ G_TYPE_ICON,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ properties[PROP_SYMBOLIC_ICON] =
+ g_param_spec_object ("symbolic-icon",
+ "Bookmark's symbolic icon",
+ "The symbolic icon of this bookmark",
+ G_TYPE_ICON,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+
+ g_type_class_add_private (class, sizeof (NautilusBookmarkDetails));
}
static void
nautilus_bookmark_init (NautilusBookmark *bookmark)
{
- bookmark->details = G_TYPE_INSTANCE_GET_PRIVATE (bookmark, NAUTILUS_TYPE_BOOKMARK,
- NautilusBookmarkDetails);
+ bookmark->details = G_TYPE_INSTANCE_GET_PRIVATE (bookmark, NAUTILUS_TYPE_BOOKMARK,
+ NautilusBookmarkDetails);
- bookmark->details->exists = TRUE;
+ bookmark->details->exists = TRUE;
}
const gchar *
nautilus_bookmark_get_name (NautilusBookmark *bookmark)
{
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
- return bookmark->details->name;
+ return bookmark->details->name;
}
gboolean
nautilus_bookmark_get_has_custom_name (NautilusBookmark *bookmark)
{
- g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), FALSE);
- return (bookmark->details->has_custom_name);
+ return (bookmark->details->has_custom_name);
}
/**
@@ -641,140 +728,145 @@ nautilus_bookmark_get_has_custom_name (NautilusBookmark *bookmark)
* Check whether two bookmarks are considered identical.
* @a: first NautilusBookmark*.
* @b: second NautilusBookmark*.
- *
- * Return value: 0 if @a and @b have same name and uri, 1 otherwise
+ *
+ * Return value: 0 if @a and @b have same name and uri, 1 otherwise
* (GCompareFunc style)
**/
-int
-nautilus_bookmark_compare_with (gconstpointer a, gconstpointer b)
-{
- NautilusBookmark *bookmark_a;
- NautilusBookmark *bookmark_b;
-
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (a), 1);
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (b), 1);
-
- bookmark_a = NAUTILUS_BOOKMARK (a);
- bookmark_b = NAUTILUS_BOOKMARK (b);
-
- if (!g_file_equal (bookmark_a->details->location,
- bookmark_b->details->location)) {
- return 1;
- }
-
- if (g_strcmp0 (bookmark_a->details->name,
- bookmark_b->details->name) != 0) {
- return 1;
- }
-
- return 0;
+int
+nautilus_bookmark_compare_with (gconstpointer a,
+ gconstpointer b)
+{
+ NautilusBookmark *bookmark_a;
+ NautilusBookmark *bookmark_b;
+
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (a), 1);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (b), 1);
+
+ bookmark_a = NAUTILUS_BOOKMARK (a);
+ bookmark_b = NAUTILUS_BOOKMARK (b);
+
+ if (!g_file_equal (bookmark_a->details->location,
+ bookmark_b->details->location))
+ {
+ return 1;
+ }
+
+ if (g_strcmp0 (bookmark_a->details->name,
+ bookmark_b->details->name) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
}
GIcon *
nautilus_bookmark_get_symbolic_icon (NautilusBookmark *bookmark)
{
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
- /* Try to connect a file in case file exists now but didn't earlier. */
- nautilus_bookmark_connect_file (bookmark);
+ /* Try to connect a file in case file exists now but didn't earlier. */
+ nautilus_bookmark_connect_file (bookmark);
- if (bookmark->details->symbolic_icon) {
- return g_object_ref (bookmark->details->symbolic_icon);
- }
- return NULL;
+ if (bookmark->details->symbolic_icon)
+ {
+ return g_object_ref (bookmark->details->symbolic_icon);
+ }
+ return NULL;
}
GIcon *
nautilus_bookmark_get_icon (NautilusBookmark *bookmark)
{
- g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
- /* Try to connect a file in case file exists now but didn't earlier. */
- nautilus_bookmark_connect_file (bookmark);
+ /* Try to connect a file in case file exists now but didn't earlier. */
+ nautilus_bookmark_connect_file (bookmark);
- if (bookmark->details->icon) {
- return g_object_ref (bookmark->details->icon);
- }
- return NULL;
+ if (bookmark->details->icon)
+ {
+ return g_object_ref (bookmark->details->icon);
+ }
+ return NULL;
}
GFile *
nautilus_bookmark_get_location (NautilusBookmark *bookmark)
{
- g_return_val_if_fail(NAUTILUS_IS_BOOKMARK (bookmark), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_BOOKMARK (bookmark), NULL);
- /* Try to connect a file in case file exists now but didn't earlier.
- * This allows a bookmark to update its image properly in the case
- * where a new file appears with the same URI as a previously-deleted
- * file. Calling connect_file here means that attempts to activate the
- * bookmark will update its image if possible.
- */
- nautilus_bookmark_connect_file (bookmark);
+ /* Try to connect a file in case file exists now but didn't earlier.
+ * This allows a bookmark to update its image properly in the case
+ * where a new file appears with the same URI as a previously-deleted
+ * file. Calling connect_file here means that attempts to activate the
+ * bookmark will update its image if possible.
+ */
+ nautilus_bookmark_connect_file (bookmark);
- return g_object_ref (bookmark->details->location);
+ return g_object_ref (bookmark->details->location);
}
char *
nautilus_bookmark_get_uri (NautilusBookmark *bookmark)
{
- GFile *file;
- char *uri;
+ GFile *file;
+ char *uri;
- file = nautilus_bookmark_get_location (bookmark);
- uri = g_file_get_uri (file);
- g_object_unref (file);
- return uri;
+ file = nautilus_bookmark_get_location (bookmark);
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+ return uri;
}
NautilusBookmark *
-nautilus_bookmark_new (GFile *location,
- const gchar *custom_name)
+nautilus_bookmark_new (GFile *location,
+ const gchar *custom_name)
{
- NautilusBookmark *new_bookmark;
+ NautilusBookmark *new_bookmark;
- new_bookmark = NAUTILUS_BOOKMARK (g_object_new (NAUTILUS_TYPE_BOOKMARK,
- "location", location,
- "name", custom_name,
- "custom-name", custom_name != NULL,
- NULL));
+ new_bookmark = NAUTILUS_BOOKMARK (g_object_new (NAUTILUS_TYPE_BOOKMARK,
+ "location", location,
+ "name", custom_name,
+ "custom-name", custom_name != NULL,
+ NULL));
- return new_bookmark;
-}
+ return new_bookmark;
+}
/**
* nautilus_bookmark_menu_item_new:
- *
+ *
* Return a menu item representing a bookmark.
* @bookmark: The bookmark the menu item represents.
* Return value: A newly-created bookmark, not yet shown.
- **/
+ **/
GtkWidget *
nautilus_bookmark_menu_item_new (NautilusBookmark *bookmark)
{
- GtkWidget *menu_item;
- GtkLabel *label;
- const char *name;
+ GtkWidget *menu_item;
+ GtkLabel *label;
+ const char *name;
- name = nautilus_bookmark_get_name (bookmark);
- menu_item = gtk_menu_item_new_with_label (name);
- label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (menu_item)));
- gtk_label_set_use_underline (label, FALSE);
- gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (label, ELLIPSISED_MENU_ITEM_MIN_CHARS);
+ name = nautilus_bookmark_get_name (bookmark);
+ menu_item = gtk_menu_item_new_with_label (name);
+ label = GTK_LABEL (gtk_bin_get_child (GTK_BIN (menu_item)));
+ gtk_label_set_use_underline (label, FALSE);
+ gtk_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
+ gtk_label_set_max_width_chars (label, ELLIPSISED_MENU_ITEM_MIN_CHARS);
- return menu_item;
+ return menu_item;
}
void
-nautilus_bookmark_set_scroll_pos (NautilusBookmark *bookmark,
- const char *uri)
+nautilus_bookmark_set_scroll_pos (NautilusBookmark *bookmark,
+ const char *uri)
{
- g_free (bookmark->details->scroll_file);
- bookmark->details->scroll_file = g_strdup (uri);
+ g_free (bookmark->details->scroll_file);
+ bookmark->details->scroll_file = g_strdup (uri);
}
char *
-nautilus_bookmark_get_scroll_pos (NautilusBookmark *bookmark)
+nautilus_bookmark_get_scroll_pos (NautilusBookmark *bookmark)
{
- return g_strdup (bookmark->details->scroll_file);
+ return g_strdup (bookmark->details->scroll_file);
}
diff --git a/src/nautilus-canvas-container.c b/src/nautilus-canvas-container.c
index 3da17a0c6..610225efa 100644
--- a/src/nautilus-canvas-container.c
+++ b/src/nautilus-canvas-container.c
@@ -1,27 +1,26 @@
-
/* nautilus-canvas-container.c - Canvas container widget.
-
- Copyright (C) 1999, 2000 Free Software Foundation
- Copyright (C) 2000, 2001 Eazel, Inc.
- Copyright (C) 2002, 2003 Red Hat, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Ettore Perazzoli <ettore@gnu.org>,
- Darin Adler <darin@bentspoon.com>
-*/
+ *
+ * Copyright (C) 1999, 2000 Free Software Foundation
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ * Copyright (C) 2002, 2003 Red Hat, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Ettore Perazzoli <ettore@gnu.org>,
+ * Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
#include <X11/Xlib.h>
@@ -104,13 +103,13 @@
#define LARGER_ICON_GRID_WIDTH 128
/* Desktop layout mode defines */
-#define DESKTOP_PAD_HORIZONTAL 10
-#define DESKTOP_PAD_VERTICAL 10
-#define SNAP_SIZE_X 78
-#define SNAP_SIZE_Y 20
+#define DESKTOP_PAD_HORIZONTAL 10
+#define DESKTOP_PAD_VERTICAL 10
+#define SNAP_SIZE_X 78
+#define SNAP_SIZE_Y 20
-#define SNAP_HORIZONTAL(func,x) ((func ((double)((x) - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X) * SNAP_SIZE_X) + DESKTOP_PAD_HORIZONTAL)
-#define SNAP_VERTICAL(func, y) ((func ((double)((y) - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y) * SNAP_SIZE_Y) + DESKTOP_PAD_VERTICAL)
+#define SNAP_HORIZONTAL(func, x) ((func ((double) ((x) - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X) * SNAP_SIZE_X) + DESKTOP_PAD_HORIZONTAL)
+#define SNAP_VERTICAL(func, y) ((func ((double) ((y) - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y) * SNAP_SIZE_Y) + DESKTOP_PAD_VERTICAL)
#define SNAP_NEAREST_HORIZONTAL(x) SNAP_HORIZONTAL (floor, x + SNAP_SIZE_X / 2)
#define SNAP_NEAREST_VERTICAL(y) SNAP_VERTICAL (floor, y + SNAP_SIZE_Y / 2)
@@ -124,123 +123,129 @@
/* Copied from NautilusFile */
#define UNDEFINED_TIME ((time_t) (-1))
-enum {
- ACTION_ACTIVATE,
- ACTION_MENU,
- LAST_ACTION
+enum
+{
+ ACTION_ACTIVATE,
+ ACTION_MENU,
+ LAST_ACTION
};
-typedef struct {
- GList *selection;
- char *action_descriptions[LAST_ACTION];
+typedef struct
+{
+ GList *selection;
+ char *action_descriptions[LAST_ACTION];
} NautilusCanvasContainerAccessiblePrivate;
-static GType nautilus_canvas_container_accessible_get_type (void);
-static void preview_selected_items (NautilusCanvasContainer *container);
-static void activate_selected_items (NautilusCanvasContainer *container);
-static void activate_selected_items_alternate (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon);
-static void compute_stretch (StretchState *start,
- StretchState *current);
-static NautilusCanvasIcon *get_first_selected_icon (NautilusCanvasContainer *container);
-static NautilusCanvasIcon *get_nth_selected_icon (NautilusCanvasContainer *container,
- int index);
-static gboolean has_multiple_selection (NautilusCanvasContainer *container);
-static gboolean all_selected (NautilusCanvasContainer *container);
-static gboolean has_selection (NautilusCanvasContainer *container);
-static void icon_destroy (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon);
-static gboolean finish_adding_new_icons (NautilusCanvasContainer *container);
-static inline void icon_get_bounding_box (NautilusCanvasIcon *icon,
- int *x1_return,
- int *y1_return,
- int *x2_return,
- int *y2_return,
- NautilusCanvasItemBoundsUsage usage);
-static void handle_hadjustment_changed (GtkAdjustment *adjustment,
- NautilusCanvasContainer *container);
-static void handle_vadjustment_changed (GtkAdjustment *adjustment,
- NautilusCanvasContainer *container);
-static GList * nautilus_canvas_container_get_selected_icons (NautilusCanvasContainer *container);
-static void nautilus_canvas_container_update_visible_icons (NautilusCanvasContainer *container);
-static void reveal_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon);
-
-static void nautilus_canvas_container_set_rtl_positions (NautilusCanvasContainer *container);
-static double get_mirror_x_position (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- double x);
-static void text_ellipsis_limit_changed_container_callback (gpointer callback_data);
+static GType nautilus_canvas_container_accessible_get_type (void);
+static void preview_selected_items (NautilusCanvasContainer *container);
+static void activate_selected_items (NautilusCanvasContainer *container);
+static void activate_selected_items_alternate (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon);
+static void compute_stretch (StretchState *start,
+ StretchState *current);
+static NautilusCanvasIcon *get_first_selected_icon (NautilusCanvasContainer *container);
+static NautilusCanvasIcon *get_nth_selected_icon (NautilusCanvasContainer *container,
+ int index);
+static gboolean has_multiple_selection (NautilusCanvasContainer *container);
+static gboolean all_selected (NautilusCanvasContainer *container);
+static gboolean has_selection (NautilusCanvasContainer *container);
+static void icon_destroy (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon);
+static gboolean finish_adding_new_icons (NautilusCanvasContainer *container);
+static inline void icon_get_bounding_box (NautilusCanvasIcon *icon,
+ int *x1_return,
+ int *y1_return,
+ int *x2_return,
+ int *y2_return,
+ NautilusCanvasItemBoundsUsage usage);
+static void handle_hadjustment_changed (GtkAdjustment *adjustment,
+ NautilusCanvasContainer *container);
+static void handle_vadjustment_changed (GtkAdjustment *adjustment,
+ NautilusCanvasContainer *container);
+static GList *nautilus_canvas_container_get_selected_icons (NautilusCanvasContainer *container);
+static void nautilus_canvas_container_update_visible_icons (NautilusCanvasContainer *container);
+static void reveal_icon (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon);
+
+static void nautilus_canvas_container_set_rtl_positions (NautilusCanvasContainer *container);
+static double get_mirror_x_position (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon,
+ double x);
+static void text_ellipsis_limit_changed_container_callback (gpointer callback_data);
static int compare_icons_horizontal (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b);
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b);
static int compare_icons_vertical (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b);
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b);
static void store_layout_timestamps_now (NautilusCanvasContainer *container);
static void schedule_redo_layout (NautilusCanvasContainer *container);
-static const char *nautilus_canvas_container_accessible_action_names[] = {
- "activate",
- "menu",
- NULL
+static const char *nautilus_canvas_container_accessible_action_names[] =
+{
+ "activate",
+ "menu",
+ NULL
};
-static const char *nautilus_canvas_container_accessible_action_descriptions[] = {
- "Activate selected items",
- "Popup context menu",
- NULL
+static const char *nautilus_canvas_container_accessible_action_descriptions[] =
+{
+ "Activate selected items",
+ "Popup context menu",
+ NULL
};
G_DEFINE_TYPE (NautilusCanvasContainer, nautilus_canvas_container, EEL_TYPE_CANVAS);
/* The NautilusCanvasContainer signals. */
-enum {
- ACTIVATE,
- ACTIVATE_ALTERNATE,
- ACTIVATE_PREVIEWER,
- BAND_SELECT_STARTED,
- BAND_SELECT_ENDED,
- BUTTON_PRESS,
- CAN_ACCEPT_ITEM,
- CONTEXT_CLICK_BACKGROUND,
- CONTEXT_CLICK_SELECTION,
- MIDDLE_CLICK,
- GET_CONTAINER_URI,
- GET_ICON_URI,
- GET_ICON_ACTIVATION_URI,
- GET_ICON_DROP_TARGET_URI,
- GET_STORED_ICON_POSITION,
- ICON_POSITION_CHANGED,
- GET_STORED_LAYOUT_TIMESTAMP,
- STORE_LAYOUT_TIMESTAMP,
- ICON_RENAME_STARTED,
- ICON_RENAME_ENDED,
- ICON_STRETCH_STARTED,
- ICON_STRETCH_ENDED,
- LAYOUT_CHANGED,
- MOVE_COPY_ITEMS,
- HANDLE_NETSCAPE_URL,
- HANDLE_URI_LIST,
- HANDLE_TEXT,
- HANDLE_RAW,
- HANDLE_HOVER,
- SELECTION_CHANGED,
- ICON_ADDED,
- ICON_REMOVED,
- CLEARED,
- LAST_SIGNAL
+enum
+{
+ ACTIVATE,
+ ACTIVATE_ALTERNATE,
+ ACTIVATE_PREVIEWER,
+ BAND_SELECT_STARTED,
+ BAND_SELECT_ENDED,
+ BUTTON_PRESS,
+ CAN_ACCEPT_ITEM,
+ CONTEXT_CLICK_BACKGROUND,
+ CONTEXT_CLICK_SELECTION,
+ MIDDLE_CLICK,
+ GET_CONTAINER_URI,
+ GET_ICON_URI,
+ GET_ICON_ACTIVATION_URI,
+ GET_ICON_DROP_TARGET_URI,
+ GET_STORED_ICON_POSITION,
+ ICON_POSITION_CHANGED,
+ GET_STORED_LAYOUT_TIMESTAMP,
+ STORE_LAYOUT_TIMESTAMP,
+ ICON_RENAME_STARTED,
+ ICON_RENAME_ENDED,
+ ICON_STRETCH_STARTED,
+ ICON_STRETCH_ENDED,
+ LAYOUT_CHANGED,
+ MOVE_COPY_ITEMS,
+ HANDLE_NETSCAPE_URL,
+ HANDLE_URI_LIST,
+ HANDLE_TEXT,
+ HANDLE_RAW,
+ HANDLE_HOVER,
+ SELECTION_CHANGED,
+ ICON_ADDED,
+ ICON_REMOVED,
+ CLEARED,
+ LAST_SIGNAL
};
-typedef struct {
- int **icon_grid;
- int *grid_memory;
- int num_rows;
- int num_columns;
- gboolean tight;
+typedef struct
+{
+ int **icon_grid;
+ int *grid_memory;
+ int num_rows;
+ int num_columns;
+ gboolean tight;
} PlacementGrid;
static guint signals[LAST_SIGNAL];
@@ -250,144 +255,170 @@ static guint signals[LAST_SIGNAL];
static void
icon_free (NautilusCanvasIcon *icon)
{
- /* Destroy this icon item; the parent will unref it. */
- eel_canvas_item_destroy (EEL_CANVAS_ITEM (icon->item));
- g_free (icon);
+ /* Destroy this icon item; the parent will unref it. */
+ eel_canvas_item_destroy (EEL_CANVAS_ITEM (icon->item));
+ g_free (icon);
}
static gboolean
icon_is_positioned (const NautilusCanvasIcon *icon)
{
- return icon->x != ICON_UNPOSITIONED_VALUE && icon->y != ICON_UNPOSITIONED_VALUE;
+ return icon->x != ICON_UNPOSITIONED_VALUE && icon->y != ICON_UNPOSITIONED_VALUE;
}
/* x, y are the top-left coordinates of the icon. */
static void
icon_set_position (NautilusCanvasIcon *icon,
- double x, double y)
-{
- NautilusCanvasContainer *container;
- double pixels_per_unit;
- int container_left, container_top, container_right, container_bottom;
- int x1, x2, y1, y2;
- int container_x, container_y, container_width, container_height;
- EelDRect icon_bounds;
- int item_width, item_height;
- int height_above, width_left;
- int min_x, max_x, min_y, max_y;
-
- if (icon->x == x && icon->y == y) {
- return;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (icon->item)->canvas);
-
- if (nautilus_canvas_container_get_is_fixed_size (container)) {
- /* FIXME: This should be:
-
- container_x = GTK_WIDGET (container)->allocation.x;
- container_y = GTK_WIDGET (container)->allocation.y;
- container_width = GTK_WIDGET (container)->allocation.width;
- container_height = GTK_WIDGET (container)->allocation.height;
-
- But for some reason the widget allocation is sometimes not done
- at startup, and the allocation is then only 45x60. which is
- really bad.
-
- For now, we have a cheesy workaround:
- */
- container_x = 0;
- container_y = 0;
- container_width = gdk_screen_width () - container_x
- - container->details->left_margin
- - container->details->right_margin;
- container_height = gdk_screen_height () - container_y
- - container->details->top_margin
- - container->details->bottom_margin;
- pixels_per_unit = EEL_CANVAS (container)->pixels_per_unit;
- /* Clip the position of the icon within our desktop bounds */
- container_left = container_x / pixels_per_unit;
- container_top = container_y / pixels_per_unit;
- container_right = container_left + container_width / pixels_per_unit;
- container_bottom = container_top + container_height / pixels_per_unit;
-
- icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
- BOUNDS_USAGE_FOR_ENTIRE_ITEM);
- item_width = x2 - x1;
- item_height = y2 - y1;
-
- icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
-
- /* determine icon rectangle relative to item rectangle */
- height_above = icon_bounds.y0 - y1;
- width_left = icon_bounds.x0 - x1;
-
- min_x = container_left + DESKTOP_PAD_HORIZONTAL + width_left;
- max_x = container_right - DESKTOP_PAD_HORIZONTAL - item_width + width_left;
- x = CLAMP (x, min_x, max_x);
-
- min_y = container_top + height_above + DESKTOP_PAD_VERTICAL;
- max_y = container_bottom - DESKTOP_PAD_VERTICAL - item_height + height_above;
- y = CLAMP (y, min_y, max_y);
- }
-
- if (icon->x == ICON_UNPOSITIONED_VALUE) {
- icon->x = 0;
- }
- if (icon->y == ICON_UNPOSITIONED_VALUE) {
- icon->y = 0;
- }
-
- eel_canvas_item_move (EEL_CANVAS_ITEM (icon->item),
- x - icon->x,
- y - icon->y);
-
- icon->x = x;
- icon->y = y;
+ double x,
+ double y)
+{
+ NautilusCanvasContainer *container;
+ double pixels_per_unit;
+ int container_left, container_top, container_right, container_bottom;
+ int x1, x2, y1, y2;
+ int container_x, container_y, container_width, container_height;
+ EelDRect icon_bounds;
+ int item_width, item_height;
+ int height_above, width_left;
+ int min_x, max_x, min_y, max_y;
+
+ if (icon->x == x && icon->y == y)
+ {
+ return;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (icon->item)->canvas);
+
+ if (nautilus_canvas_container_get_is_fixed_size (container))
+ {
+ /* FIXME: This should be:
+ *
+ * container_x = GTK_WIDGET (container)->allocation.x;
+ * container_y = GTK_WIDGET (container)->allocation.y;
+ * container_width = GTK_WIDGET (container)->allocation.width;
+ * container_height = GTK_WIDGET (container)->allocation.height;
+ *
+ * But for some reason the widget allocation is sometimes not done
+ * at startup, and the allocation is then only 45x60. which is
+ * really bad.
+ *
+ * For now, we have a cheesy workaround:
+ */
+ container_x = 0;
+ container_y = 0;
+ container_width = gdk_screen_width () - container_x
+ - container->details->left_margin
+ - container->details->right_margin;
+ container_height = gdk_screen_height () - container_y
+ - container->details->top_margin
+ - container->details->bottom_margin;
+ pixels_per_unit = EEL_CANVAS (container)->pixels_per_unit;
+ /* Clip the position of the icon within our desktop bounds */
+ container_left = container_x / pixels_per_unit;
+ container_top = container_y / pixels_per_unit;
+ container_right = container_left + container_width / pixels_per_unit;
+ container_bottom = container_top + container_height / pixels_per_unit;
+
+ icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
+ BOUNDS_USAGE_FOR_ENTIRE_ITEM);
+ item_width = x2 - x1;
+ item_height = y2 - y1;
+
+ icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
+
+ /* determine icon rectangle relative to item rectangle */
+ height_above = icon_bounds.y0 - y1;
+ width_left = icon_bounds.x0 - x1;
+
+ min_x = container_left + DESKTOP_PAD_HORIZONTAL + width_left;
+ max_x = container_right - DESKTOP_PAD_HORIZONTAL - item_width + width_left;
+ x = CLAMP (x, min_x, max_x);
+
+ min_y = container_top + height_above + DESKTOP_PAD_VERTICAL;
+ max_y = container_bottom - DESKTOP_PAD_VERTICAL - item_height + height_above;
+ y = CLAMP (y, min_y, max_y);
+ }
+
+ if (icon->x == ICON_UNPOSITIONED_VALUE)
+ {
+ icon->x = 0;
+ }
+ if (icon->y == ICON_UNPOSITIONED_VALUE)
+ {
+ icon->y = 0;
+ }
+
+ eel_canvas_item_move (EEL_CANVAS_ITEM (icon->item),
+ x - icon->x,
+ y - icon->y);
+
+ icon->x = x;
+ icon->y = y;
}
static guint
nautilus_canvas_container_get_grid_size_for_zoom_level (NautilusCanvasZoomLevel zoom_level)
{
- switch (zoom_level) {
- case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
- return SMALL_ICON_GRID_WIDTH;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
- return STANDARD_ICON_GRID_WIDTH;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
- return LARGE_ICON_GRID_WIDTH;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
- return LARGER_ICON_GRID_WIDTH;
- }
- g_return_val_if_reached (STANDARD_ICON_GRID_WIDTH);
+ switch (zoom_level)
+ {
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
+ {
+ return SMALL_ICON_GRID_WIDTH;
+ }
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
+ {
+ return STANDARD_ICON_GRID_WIDTH;
+ }
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
+ {
+ return LARGE_ICON_GRID_WIDTH;
+ }
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
+ return LARGER_ICON_GRID_WIDTH;
+ }
+ g_return_val_if_reached (STANDARD_ICON_GRID_WIDTH);
}
guint
nautilus_canvas_container_get_icon_size_for_zoom_level (NautilusCanvasZoomLevel zoom_level)
{
- switch (zoom_level) {
- case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
- return NAUTILUS_CANVAS_ICON_SIZE_SMALL;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
- return NAUTILUS_CANVAS_ICON_SIZE_STANDARD;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
- return NAUTILUS_CANVAS_ICON_SIZE_LARGE;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
- return NAUTILUS_CANVAS_ICON_SIZE_LARGER;
- }
- g_return_val_if_reached (NAUTILUS_CANVAS_ICON_SIZE_STANDARD);
+ switch (zoom_level)
+ {
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
+ {
+ return NAUTILUS_CANVAS_ICON_SIZE_SMALL;
+ }
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
+ {
+ return NAUTILUS_CANVAS_ICON_SIZE_STANDARD;
+ }
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
+ {
+ return NAUTILUS_CANVAS_ICON_SIZE_LARGE;
+ }
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
+ return NAUTILUS_CANVAS_ICON_SIZE_LARGER;
+ }
+ g_return_val_if_reached (NAUTILUS_CANVAS_ICON_SIZE_STANDARD);
}
static void
icon_get_size (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- guint *size)
+ NautilusCanvasIcon *icon,
+ guint *size)
{
- if (size != NULL) {
- *size = MAX (nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level)
- * icon->scale, NAUTILUS_CANVAS_ICON_SIZE_SMALL);
- }
+ if (size != NULL)
+ {
+ *size = MAX (nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level)
+ * icon->scale, NAUTILUS_CANVAS_ICON_SIZE_SMALL);
+ }
}
/* The icon_set_size function is used by the stretching user
@@ -397,462 +428,513 @@ icon_get_size (NautilusCanvasContainer *container,
*/
static void
icon_set_size (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- guint icon_size,
- gboolean snap,
- gboolean update_position)
+ NautilusCanvasIcon *icon,
+ guint icon_size,
+ gboolean snap,
+ gboolean update_position)
{
- guint old_size;
- double scale;
+ guint old_size;
+ double scale;
- icon_get_size (container, icon, &old_size);
- if (icon_size == old_size) {
- return;
- }
+ icon_get_size (container, icon, &old_size);
+ if (icon_size == old_size)
+ {
+ return;
+ }
- scale = (double) icon_size /
- nautilus_canvas_container_get_icon_size_for_zoom_level
- (container->details->zoom_level);
- nautilus_canvas_container_move_icon (container, icon,
- icon->x, icon->y,
- scale, FALSE,
- snap, update_position);
+ scale = (double) icon_size /
+ nautilus_canvas_container_get_icon_size_for_zoom_level
+ (container->details->zoom_level);
+ nautilus_canvas_container_move_icon (container, icon,
+ icon->x, icon->y,
+ scale, FALSE,
+ snap, update_position);
}
static void
icon_raise (NautilusCanvasIcon *icon)
{
- EelCanvasItem *item, *band;
-
- item = EEL_CANVAS_ITEM (icon->item);
- band = NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle;
-
- eel_canvas_item_send_behind (item, band);
+ EelCanvasItem *item, *band;
+
+ item = EEL_CANVAS_ITEM (icon->item);
+ band = NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle;
+
+ eel_canvas_item_send_behind (item, band);
}
static void
-emit_stretch_started (NautilusCanvasContainer *container, NautilusCanvasIcon *icon)
+emit_stretch_started (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon)
{
- g_signal_emit (container,
- signals[ICON_STRETCH_STARTED], 0,
- icon->data);
+ g_signal_emit (container,
+ signals[ICON_STRETCH_STARTED], 0,
+ icon->data);
}
static void
-emit_stretch_ended (NautilusCanvasContainer *container, NautilusCanvasIcon *icon)
+emit_stretch_ended (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon)
{
- g_signal_emit (container,
- signals[ICON_STRETCH_ENDED], 0,
- icon->data);
+ g_signal_emit (container,
+ signals[ICON_STRETCH_ENDED], 0,
+ icon->data);
}
static void
icon_toggle_selected (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
-{
- icon->is_selected = !icon->is_selected;
- if (icon->is_selected) {
- container->details->selection = g_list_prepend (container->details->selection, icon->data);
- container->details->selection_needs_resort = TRUE;
- } else {
- container->details->selection = g_list_remove (container->details->selection, icon->data);
- }
-
- eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
- "highlighted_for_selection", (gboolean) icon->is_selected,
- NULL);
-
- /* If the icon is deselected, then get rid of the stretch handles.
- * No harm in doing the same if the item is newly selected.
- */
- if (icon == container->details->stretch_icon) {
- container->details->stretch_icon = NULL;
- nautilus_canvas_item_set_show_stretch_handles (icon->item, FALSE);
- /* snap the icon if necessary */
- if (container->details->keep_aligned) {
- nautilus_canvas_container_move_icon (container,
- icon,
- icon->x, icon->y,
- icon->scale,
- FALSE, TRUE, TRUE);
- }
-
- emit_stretch_ended (container, icon);
- }
-
- /* Raise each newly-selected icon to the front as it is selected. */
- if (icon->is_selected) {
- icon_raise (icon);
- }
+ NautilusCanvasIcon *icon)
+{
+ icon->is_selected = !icon->is_selected;
+ if (icon->is_selected)
+ {
+ container->details->selection = g_list_prepend (container->details->selection, icon->data);
+ container->details->selection_needs_resort = TRUE;
+ }
+ else
+ {
+ container->details->selection = g_list_remove (container->details->selection, icon->data);
+ }
+
+ eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
+ "highlighted_for_selection", (gboolean) icon->is_selected,
+ NULL);
+
+ /* If the icon is deselected, then get rid of the stretch handles.
+ * No harm in doing the same if the item is newly selected.
+ */
+ if (icon == container->details->stretch_icon)
+ {
+ container->details->stretch_icon = NULL;
+ nautilus_canvas_item_set_show_stretch_handles (icon->item, FALSE);
+ /* snap the icon if necessary */
+ if (container->details->keep_aligned)
+ {
+ nautilus_canvas_container_move_icon (container,
+ icon,
+ icon->x, icon->y,
+ icon->scale,
+ FALSE, TRUE, TRUE);
+ }
+
+ emit_stretch_ended (container, icon);
+ }
+
+ /* Raise each newly-selected icon to the front as it is selected. */
+ if (icon->is_selected)
+ {
+ icon_raise (icon);
+ }
}
/* Select an icon. Return TRUE if selection has changed. */
static gboolean
icon_set_selected (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- gboolean select)
+ NautilusCanvasIcon *icon,
+ gboolean select)
{
- g_assert (select == FALSE || select == TRUE);
- g_assert (icon->is_selected == FALSE || icon->is_selected == TRUE);
+ g_assert (select == FALSE || select == TRUE);
+ g_assert (icon->is_selected == FALSE || icon->is_selected == TRUE);
- if (select == icon->is_selected) {
- return FALSE;
- }
+ if (select == icon->is_selected)
+ {
+ return FALSE;
+ }
- icon_toggle_selected (container, icon);
- g_assert (select == icon->is_selected);
- return TRUE;
+ icon_toggle_selected (container, icon);
+ g_assert (select == icon->is_selected);
+ return TRUE;
}
static inline void
-icon_get_bounding_box (NautilusCanvasIcon *icon,
- int *x1_return, int *y1_return,
- int *x2_return, int *y2_return,
- NautilusCanvasItemBoundsUsage usage)
-{
- double x1, y1, x2, y2;
-
- if (usage == BOUNDS_USAGE_FOR_DISPLAY) {
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
- &x1, &y1, &x2, &y2);
- } else if (usage == BOUNDS_USAGE_FOR_LAYOUT) {
- nautilus_canvas_item_get_bounds_for_layout (icon->item,
- &x1, &y1, &x2, &y2);
- } else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM) {
- nautilus_canvas_item_get_bounds_for_entire_item (icon->item,
- &x1, &y1, &x2, &y2);
- } else {
- g_assert_not_reached ();
- }
-
- if (x1_return != NULL) {
- *x1_return = x1;
- }
-
- if (y1_return != NULL) {
- *y1_return = y1;
- }
-
- if (x2_return != NULL) {
- *x2_return = x2;
- }
-
- if (y2_return != NULL) {
- *y2_return = y2;
- }
+icon_get_bounding_box (NautilusCanvasIcon *icon,
+ int *x1_return,
+ int *y1_return,
+ int *x2_return,
+ int *y2_return,
+ NautilusCanvasItemBoundsUsage usage)
+{
+ double x1, y1, x2, y2;
+
+ if (usage == BOUNDS_USAGE_FOR_DISPLAY)
+ {
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
+ &x1, &y1, &x2, &y2);
+ }
+ else if (usage == BOUNDS_USAGE_FOR_LAYOUT)
+ {
+ nautilus_canvas_item_get_bounds_for_layout (icon->item,
+ &x1, &y1, &x2, &y2);
+ }
+ else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
+ {
+ nautilus_canvas_item_get_bounds_for_entire_item (icon->item,
+ &x1, &y1, &x2, &y2);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ if (x1_return != NULL)
+ {
+ *x1_return = x1;
+ }
+
+ if (y1_return != NULL)
+ {
+ *y1_return = y1;
+ }
+
+ if (x2_return != NULL)
+ {
+ *x2_return = x2;
+ }
+
+ if (y2_return != NULL)
+ {
+ *y2_return = y2;
+ }
}
/* Utility functions for NautilusCanvasContainer. */
gboolean
nautilus_canvas_container_scroll (NautilusCanvasContainer *container,
- int delta_x, int delta_y)
+ int delta_x,
+ int delta_y)
{
- GtkAdjustment *hadj, *vadj;
- int old_h_value, old_v_value;
+ GtkAdjustment *hadj, *vadj;
+ int old_h_value, old_v_value;
+
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
+ /* Store the old ajustment values so we can tell if we
+ * ended up actually scrolling. We may not have in a case
+ * where the resulting value got pinned to the adjustment
+ * min or max.
+ */
+ old_h_value = gtk_adjustment_get_value (hadj);
+ old_v_value = gtk_adjustment_get_value (vadj);
- /* Store the old ajustment values so we can tell if we
- * ended up actually scrolling. We may not have in a case
- * where the resulting value got pinned to the adjustment
- * min or max.
- */
- old_h_value = gtk_adjustment_get_value (hadj);
- old_v_value = gtk_adjustment_get_value (vadj);
-
- gtk_adjustment_set_value (hadj, gtk_adjustment_get_value (hadj) + delta_x);
- gtk_adjustment_set_value (vadj, gtk_adjustment_get_value (vadj) + delta_y);
+ gtk_adjustment_set_value (hadj, gtk_adjustment_get_value (hadj) + delta_x);
+ gtk_adjustment_set_value (vadj, gtk_adjustment_get_value (vadj) + delta_y);
- /* return TRUE if we did scroll */
- return gtk_adjustment_get_value (hadj) != old_h_value || gtk_adjustment_get_value (vadj) != old_v_value;
+ /* return TRUE if we did scroll */
+ return gtk_adjustment_get_value (hadj) != old_h_value || gtk_adjustment_get_value (vadj) != old_v_value;
}
static void
-pending_icon_to_reveal_destroy_callback (NautilusCanvasItem *item,
- NautilusCanvasContainer *container)
+pending_icon_to_reveal_destroy_callback (NautilusCanvasItem *item,
+ NautilusCanvasContainer *container)
{
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (container->details->pending_icon_to_reveal != NULL);
- g_assert (container->details->pending_icon_to_reveal->item == item);
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (container->details->pending_icon_to_reveal != NULL);
+ g_assert (container->details->pending_icon_to_reveal->item == item);
- container->details->pending_icon_to_reveal = NULL;
+ container->details->pending_icon_to_reveal = NULL;
}
static NautilusCanvasIcon *
get_pending_icon_to_reveal (NautilusCanvasContainer *container)
{
- return container->details->pending_icon_to_reveal;
+ return container->details->pending_icon_to_reveal;
}
static void
-set_pending_icon_to_reveal (NautilusCanvasContainer *container, NautilusCanvasIcon *icon)
-{
- NautilusCanvasIcon *old_icon;
-
- old_icon = container->details->pending_icon_to_reveal;
-
- if (icon == old_icon) {
- return;
- }
-
- if (old_icon != NULL) {
- g_signal_handlers_disconnect_by_func
- (old_icon->item,
- G_CALLBACK (pending_icon_to_reveal_destroy_callback),
- container);
- }
-
- if (icon != NULL) {
- g_signal_connect (icon->item, "destroy",
- G_CALLBACK (pending_icon_to_reveal_destroy_callback),
- container);
- }
-
- container->details->pending_icon_to_reveal = icon;
+set_pending_icon_to_reveal (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon)
+{
+ NautilusCanvasIcon *old_icon;
+
+ old_icon = container->details->pending_icon_to_reveal;
+
+ if (icon == old_icon)
+ {
+ return;
+ }
+
+ if (old_icon != NULL)
+ {
+ g_signal_handlers_disconnect_by_func
+ (old_icon->item,
+ G_CALLBACK (pending_icon_to_reveal_destroy_callback),
+ container);
+ }
+
+ if (icon != NULL)
+ {
+ g_signal_connect (icon->item, "destroy",
+ G_CALLBACK (pending_icon_to_reveal_destroy_callback),
+ container);
+ }
+
+ container->details->pending_icon_to_reveal = icon;
}
static void
item_get_canvas_bounds (EelCanvasItem *item,
- EelIRect *bounds)
-{
- EelDRect world_rect;
-
- eel_canvas_item_get_bounds (item,
- &world_rect.x0,
- &world_rect.y0,
- &world_rect.x1,
- &world_rect.y1);
- eel_canvas_item_i2w (item->parent,
- &world_rect.x0,
- &world_rect.y0);
- eel_canvas_item_i2w (item->parent,
- &world_rect.x1,
- &world_rect.y1);
-
- world_rect.x0 -= ICON_PAD_LEFT + ICON_PAD_RIGHT;
- world_rect.x1 += ICON_PAD_LEFT + ICON_PAD_RIGHT;
-
- world_rect.y0 -= ICON_PAD_TOP + ICON_PAD_BOTTOM;
- world_rect.y1 += ICON_PAD_TOP + ICON_PAD_BOTTOM;
-
- eel_canvas_w2c (item->canvas,
- world_rect.x0,
- world_rect.y0,
- &bounds->x0,
- &bounds->y0);
- eel_canvas_w2c (item->canvas,
- world_rect.x1,
- world_rect.y1,
- &bounds->x1,
- &bounds->y1);
+ EelIRect *bounds)
+{
+ EelDRect world_rect;
+
+ eel_canvas_item_get_bounds (item,
+ &world_rect.x0,
+ &world_rect.y0,
+ &world_rect.x1,
+ &world_rect.y1);
+ eel_canvas_item_i2w (item->parent,
+ &world_rect.x0,
+ &world_rect.y0);
+ eel_canvas_item_i2w (item->parent,
+ &world_rect.x1,
+ &world_rect.y1);
+
+ world_rect.x0 -= ICON_PAD_LEFT + ICON_PAD_RIGHT;
+ world_rect.x1 += ICON_PAD_LEFT + ICON_PAD_RIGHT;
+
+ world_rect.y0 -= ICON_PAD_TOP + ICON_PAD_BOTTOM;
+ world_rect.y1 += ICON_PAD_TOP + ICON_PAD_BOTTOM;
+
+ eel_canvas_w2c (item->canvas,
+ world_rect.x0,
+ world_rect.y0,
+ &bounds->x0,
+ &bounds->y0);
+ eel_canvas_w2c (item->canvas,
+ world_rect.x1,
+ world_rect.y1,
+ &bounds->x1,
+ &bounds->y1);
}
static void
icon_get_row_and_column_bounds (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- EelIRect *bounds)
+ NautilusCanvasIcon *icon,
+ EelIRect *bounds)
{
- GList *p;
- NautilusCanvasIcon *one_icon;
- EelIRect one_bounds;
-
- item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), bounds);
+ GList *p;
+ NautilusCanvasIcon *one_icon;
+ EelIRect one_bounds;
- for (p = container->details->icons; p != NULL; p = p->next) {
- one_icon = p->data;
+ item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), bounds);
- if (icon == one_icon) {
- continue;
- }
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ one_icon = p->data;
- if (compare_icons_horizontal (container, icon, one_icon) == 0) {
- item_get_canvas_bounds (EEL_CANVAS_ITEM (one_icon->item), &one_bounds);
- bounds->x0 = MIN (bounds->x0, one_bounds.x0);
- bounds->x1 = MAX (bounds->x1, one_bounds.x1);
- }
-
- if (compare_icons_vertical (container, icon, one_icon) == 0) {
- item_get_canvas_bounds (EEL_CANVAS_ITEM (one_icon->item), &one_bounds);
- bounds->y0 = MIN (bounds->y0, one_bounds.y0);
- bounds->y1 = MAX (bounds->y1, one_bounds.y1);
- }
- }
+ if (icon == one_icon)
+ {
+ continue;
+ }
+ if (compare_icons_horizontal (container, icon, one_icon) == 0)
+ {
+ item_get_canvas_bounds (EEL_CANVAS_ITEM (one_icon->item), &one_bounds);
+ bounds->x0 = MIN (bounds->x0, one_bounds.x0);
+ bounds->x1 = MAX (bounds->x1, one_bounds.x1);
+ }
+ if (compare_icons_vertical (container, icon, one_icon) == 0)
+ {
+ item_get_canvas_bounds (EEL_CANVAS_ITEM (one_icon->item), &one_bounds);
+ bounds->y0 = MIN (bounds->y0, one_bounds.y0);
+ bounds->y1 = MAX (bounds->y1, one_bounds.y1);
+ }
+ }
}
static void
reveal_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
-{
- GtkAllocation allocation;
- GtkAdjustment *hadj, *vadj;
- EelIRect bounds;
-
- if (!icon_is_positioned (icon)) {
- set_pending_icon_to_reveal (container, icon);
- return;
- }
-
- set_pending_icon_to_reveal (container, NULL);
-
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
-
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
-
- if (nautilus_canvas_container_is_auto_layout (container)) {
- /* ensure that we reveal the entire row/column */
- icon_get_row_and_column_bounds (container, icon, &bounds);
- } else {
- item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), &bounds);
- }
- if (bounds.y0 < gtk_adjustment_get_value (vadj)) {
- gtk_adjustment_set_value (vadj, bounds.y0);
- } else if (bounds.y1 > gtk_adjustment_get_value (vadj) + allocation.height) {
- gtk_adjustment_set_value
- (vadj, bounds.y1 - allocation.height);
- }
-
- if (bounds.x0 < gtk_adjustment_get_value (hadj)) {
- gtk_adjustment_set_value (hadj, bounds.x0);
- } else if (bounds.x1 > gtk_adjustment_get_value (hadj) + allocation.width) {
- gtk_adjustment_set_value
- (hadj, bounds.x1 - allocation.width);
- }
+ NautilusCanvasIcon *icon)
+{
+ GtkAllocation allocation;
+ GtkAdjustment *hadj, *vadj;
+ EelIRect bounds;
+
+ if (!icon_is_positioned (icon))
+ {
+ set_pending_icon_to_reveal (container, icon);
+ return;
+ }
+
+ set_pending_icon_to_reveal (container, NULL);
+
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
+
+ if (nautilus_canvas_container_is_auto_layout (container))
+ {
+ /* ensure that we reveal the entire row/column */
+ icon_get_row_and_column_bounds (container, icon, &bounds);
+ }
+ else
+ {
+ item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), &bounds);
+ }
+ if (bounds.y0 < gtk_adjustment_get_value (vadj))
+ {
+ gtk_adjustment_set_value (vadj, bounds.y0);
+ }
+ else if (bounds.y1 > gtk_adjustment_get_value (vadj) + allocation.height)
+ {
+ gtk_adjustment_set_value
+ (vadj, bounds.y1 - allocation.height);
+ }
+
+ if (bounds.x0 < gtk_adjustment_get_value (hadj))
+ {
+ gtk_adjustment_set_value (hadj, bounds.x0);
+ }
+ else if (bounds.x1 > gtk_adjustment_get_value (hadj) + allocation.width)
+ {
+ gtk_adjustment_set_value
+ (hadj, bounds.x1 - allocation.width);
+ }
}
static void
process_pending_icon_to_reveal (NautilusCanvasContainer *container)
{
- NautilusCanvasIcon *pending_icon_to_reveal;
-
- pending_icon_to_reveal = get_pending_icon_to_reveal (container);
-
- if (pending_icon_to_reveal != NULL) {
- reveal_icon (container, pending_icon_to_reveal);
- }
+ NautilusCanvasIcon *pending_icon_to_reveal;
+
+ pending_icon_to_reveal = get_pending_icon_to_reveal (container);
+
+ if (pending_icon_to_reveal != NULL)
+ {
+ reveal_icon (container, pending_icon_to_reveal);
+ }
}
static gboolean
keyboard_icon_reveal_timeout_callback (gpointer data)
{
- NautilusCanvasContainer *container;
- NautilusCanvasIcon *icon;
+ NautilusCanvasContainer *container;
+ NautilusCanvasIcon *icon;
- container = NAUTILUS_CANVAS_CONTAINER (data);
- icon = container->details->keyboard_icon_to_reveal;
+ container = NAUTILUS_CANVAS_CONTAINER (data);
+ icon = container->details->keyboard_icon_to_reveal;
- g_assert (icon != NULL);
+ g_assert (icon != NULL);
- /* Only reveal the icon if it's still the keyboard focus or if
- * it's still selected. Someone originally thought we should
- * cancel this reveal if the user manages to sneak a direct
- * scroll in before the timeout fires, but we later realized
- * this wouldn't actually be an improvement
- * (see bugzilla.gnome.org 40612).
- */
- if (icon == container->details->focus
- || icon->is_selected) {
- reveal_icon (container, icon);
- }
- container->details->keyboard_icon_reveal_timer_id = 0;
+ /* Only reveal the icon if it's still the keyboard focus or if
+ * it's still selected. Someone originally thought we should
+ * cancel this reveal if the user manages to sneak a direct
+ * scroll in before the timeout fires, but we later realized
+ * this wouldn't actually be an improvement
+ * (see bugzilla.gnome.org 40612).
+ */
+ if (icon == container->details->focus
+ || icon->is_selected)
+ {
+ reveal_icon (container, icon);
+ }
+ container->details->keyboard_icon_reveal_timer_id = 0;
- return FALSE;
+ return FALSE;
}
static void
unschedule_keyboard_icon_reveal (NautilusCanvasContainer *container)
{
- NautilusCanvasContainerDetails *details;
+ NautilusCanvasContainerDetails *details;
- details = container->details;
+ details = container->details;
- if (details->keyboard_icon_reveal_timer_id != 0) {
- g_source_remove (details->keyboard_icon_reveal_timer_id);
- }
+ if (details->keyboard_icon_reveal_timer_id != 0)
+ {
+ g_source_remove (details->keyboard_icon_reveal_timer_id);
+ }
}
static void
schedule_keyboard_icon_reveal (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- NautilusCanvasContainerDetails *details;
+ NautilusCanvasContainerDetails *details;
- details = container->details;
+ details = container->details;
- unschedule_keyboard_icon_reveal (container);
+ unschedule_keyboard_icon_reveal (container);
- details->keyboard_icon_to_reveal = icon;
- details->keyboard_icon_reveal_timer_id
- = g_timeout_add (KEYBOARD_ICON_REVEAL_TIMEOUT,
- keyboard_icon_reveal_timeout_callback,
- container);
+ details->keyboard_icon_to_reveal = icon;
+ details->keyboard_icon_reveal_timer_id
+ = g_timeout_add (KEYBOARD_ICON_REVEAL_TIMEOUT,
+ keyboard_icon_reveal_timeout_callback,
+ container);
}
static void inline
emit_atk_object_notify_focused (NautilusCanvasIcon *icon,
- gboolean focused)
+ gboolean focused)
{
- AtkObject *atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
- atk_object_notify_state_change (atk_object, ATK_STATE_FOCUSED, focused);
+ AtkObject *atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
+ atk_object_notify_state_change (atk_object, ATK_STATE_FOCUSED, focused);
}
static void
clear_focus (NautilusCanvasContainer *container)
{
- if (container->details->focus != NULL) {
- if (container->details->keyboard_focus) {
- eel_canvas_item_set (EEL_CANVAS_ITEM (container->details->focus->item),
- "highlighted_as_keyboard_focus", 0,
- NULL);
- } else {
- emit_atk_object_notify_focused (container->details->focus, FALSE);
- }
- }
+ if (container->details->focus != NULL)
+ {
+ if (container->details->keyboard_focus)
+ {
+ eel_canvas_item_set (EEL_CANVAS_ITEM (container->details->focus->item),
+ "highlighted_as_keyboard_focus", 0,
+ NULL);
+ }
+ else
+ {
+ emit_atk_object_notify_focused (container->details->focus, FALSE);
+ }
+ }
- container->details->focus = NULL;
+ container->details->focus = NULL;
}
/* Set @icon as the icon currently focused for accessibility. */
static void
set_focus (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- gboolean keyboard_focus)
+ NautilusCanvasIcon *icon,
+ gboolean keyboard_focus)
{
- g_assert (icon != NULL);
+ g_assert (icon != NULL);
- if (icon == container->details->focus) {
- return;
- }
+ if (icon == container->details->focus)
+ {
+ return;
+ }
- clear_focus (container);
+ clear_focus (container);
- container->details->focus = icon;
- container->details->keyboard_focus = keyboard_focus;
+ container->details->focus = icon;
+ container->details->keyboard_focus = keyboard_focus;
- if (keyboard_focus) {
- eel_canvas_item_set (EEL_CANVAS_ITEM (container->details->focus->item),
- "highlighted_as_keyboard_focus", 1,
- NULL);
- } else {
- emit_atk_object_notify_focused (container->details->focus, TRUE);
- }
+ if (keyboard_focus)
+ {
+ eel_canvas_item_set (EEL_CANVAS_ITEM (container->details->focus->item),
+ "highlighted_as_keyboard_focus", 1,
+ NULL);
+ }
+ else
+ {
+ emit_atk_object_notify_focused (container->details->focus, TRUE);
+ }
}
static void
set_keyboard_rubberband_start (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- container->details->keyboard_rubberband_start = icon;
+ container->details->keyboard_rubberband_start = icon;
}
static void
clear_keyboard_rubberband_start (NautilusCanvasContainer *container)
{
- container->details->keyboard_rubberband_start = NULL;
+ container->details->keyboard_rubberband_start = NULL;
}
/* carbon-copy of eel_canvas_group_bounds(), but
@@ -860,132 +942,171 @@ clear_keyboard_rubberband_start (NautilusCanvasContainer *container)
* bounds for the “entire item”.
*/
static void
-get_icon_bounds_for_canvas_bounds (EelCanvasGroup *group,
- double *x1, double *y1,
- double *x2, double *y2,
- NautilusCanvasItemBoundsUsage usage)
-{
- EelCanvasItem *child;
- GList *list;
- double tx1, ty1, tx2, ty2;
- double minx, miny, maxx, maxy;
- int set;
-
- /* Get the bounds of the first visible item */
-
- child = NULL; /* Unnecessary but eliminates a warning. */
-
- set = FALSE;
-
- for (list = group->item_list; list; list = list->next) {
- child = list->data;
-
- if (!NAUTILUS_IS_CANVAS_ITEM (child)) {
- continue;
- }
-
- if (child->flags & EEL_CANVAS_ITEM_VISIBLE) {
- set = TRUE;
- if (!NAUTILUS_IS_CANVAS_ITEM (child) ||
- usage == BOUNDS_USAGE_FOR_DISPLAY) {
- eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
- } else if (usage == BOUNDS_USAGE_FOR_LAYOUT) {
- nautilus_canvas_item_get_bounds_for_layout (NAUTILUS_CANVAS_ITEM (child),
- &minx, &miny, &maxx, &maxy);
- } else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM) {
- nautilus_canvas_item_get_bounds_for_entire_item (NAUTILUS_CANVAS_ITEM (child),
- &minx, &miny, &maxx, &maxy);
- } else {
- g_assert_not_reached ();
- }
- break;
- }
- }
-
- /* If there were no visible items, return an empty bounding box */
-
- if (!set) {
- *x1 = *y1 = *x2 = *y2 = 0.0;
- return;
- }
-
- /* Now we can grow the bounds using the rest of the items */
-
- list = list->next;
-
- for (; list; list = list->next) {
- child = list->data;
-
- if (!NAUTILUS_IS_CANVAS_ITEM (child)) {
- continue;
- }
-
- if (!(child->flags & EEL_CANVAS_ITEM_VISIBLE))
- continue;
-
- if (!NAUTILUS_IS_CANVAS_ITEM (child) ||
- usage == BOUNDS_USAGE_FOR_DISPLAY) {
- eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
- } else if (usage == BOUNDS_USAGE_FOR_LAYOUT) {
- nautilus_canvas_item_get_bounds_for_layout (NAUTILUS_CANVAS_ITEM (child),
- &tx1, &ty1, &tx2, &ty2);
- } else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM) {
- nautilus_canvas_item_get_bounds_for_entire_item (NAUTILUS_CANVAS_ITEM (child),
- &tx1, &ty1, &tx2, &ty2);
- } else {
- g_assert_not_reached ();
- }
-
- if (tx1 < minx)
- minx = tx1;
-
- if (ty1 < miny)
- miny = ty1;
-
- if (tx2 > maxx)
- maxx = tx2;
-
- if (ty2 > maxy)
- maxy = ty2;
- }
-
- /* Make the bounds be relative to our parent's coordinate system */
-
- if (EEL_CANVAS_ITEM (group)->parent) {
- minx += group->xpos;
- miny += group->ypos;
- maxx += group->xpos;
- maxy += group->ypos;
- }
-
- if (x1 != NULL) {
- *x1 = minx;
- }
-
- if (y1 != NULL) {
- *y1 = miny;
- }
-
- if (x2 != NULL) {
- *x2 = maxx;
- }
-
- if (y2 != NULL) {
- *y2 = maxy;
- }
+get_icon_bounds_for_canvas_bounds (EelCanvasGroup *group,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2,
+ NautilusCanvasItemBoundsUsage usage)
+{
+ EelCanvasItem *child;
+ GList *list;
+ double tx1, ty1, tx2, ty2;
+ double minx, miny, maxx, maxy;
+ int set;
+
+ /* Get the bounds of the first visible item */
+
+ child = NULL; /* Unnecessary but eliminates a warning. */
+
+ set = FALSE;
+
+ for (list = group->item_list; list; list = list->next)
+ {
+ child = list->data;
+
+ if (!NAUTILUS_IS_CANVAS_ITEM (child))
+ {
+ continue;
+ }
+
+ if (child->flags & EEL_CANVAS_ITEM_VISIBLE)
+ {
+ set = TRUE;
+ if (!NAUTILUS_IS_CANVAS_ITEM (child) ||
+ usage == BOUNDS_USAGE_FOR_DISPLAY)
+ {
+ eel_canvas_item_get_bounds (child, &minx, &miny, &maxx, &maxy);
+ }
+ else if (usage == BOUNDS_USAGE_FOR_LAYOUT)
+ {
+ nautilus_canvas_item_get_bounds_for_layout (NAUTILUS_CANVAS_ITEM (child),
+ &minx, &miny, &maxx, &maxy);
+ }
+ else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
+ {
+ nautilus_canvas_item_get_bounds_for_entire_item (NAUTILUS_CANVAS_ITEM (child),
+ &minx, &miny, &maxx, &maxy);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
+ }
+
+ /* If there were no visible items, return an empty bounding box */
+
+ if (!set)
+ {
+ *x1 = *y1 = *x2 = *y2 = 0.0;
+ return;
+ }
+
+ /* Now we can grow the bounds using the rest of the items */
+
+ list = list->next;
+
+ for (; list; list = list->next)
+ {
+ child = list->data;
+
+ if (!NAUTILUS_IS_CANVAS_ITEM (child))
+ {
+ continue;
+ }
+
+ if (!(child->flags & EEL_CANVAS_ITEM_VISIBLE))
+ {
+ continue;
+ }
+
+ if (!NAUTILUS_IS_CANVAS_ITEM (child) ||
+ usage == BOUNDS_USAGE_FOR_DISPLAY)
+ {
+ eel_canvas_item_get_bounds (child, &tx1, &ty1, &tx2, &ty2);
+ }
+ else if (usage == BOUNDS_USAGE_FOR_LAYOUT)
+ {
+ nautilus_canvas_item_get_bounds_for_layout (NAUTILUS_CANVAS_ITEM (child),
+ &tx1, &ty1, &tx2, &ty2);
+ }
+ else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
+ {
+ nautilus_canvas_item_get_bounds_for_entire_item (NAUTILUS_CANVAS_ITEM (child),
+ &tx1, &ty1, &tx2, &ty2);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ if (tx1 < minx)
+ {
+ minx = tx1;
+ }
+
+ if (ty1 < miny)
+ {
+ miny = ty1;
+ }
+
+ if (tx2 > maxx)
+ {
+ maxx = tx2;
+ }
+
+ if (ty2 > maxy)
+ {
+ maxy = ty2;
+ }
+ }
+
+ /* Make the bounds be relative to our parent's coordinate system */
+
+ if (EEL_CANVAS_ITEM (group)->parent)
+ {
+ minx += group->xpos;
+ miny += group->ypos;
+ maxx += group->xpos;
+ maxy += group->ypos;
+ }
+
+ if (x1 != NULL)
+ {
+ *x1 = minx;
+ }
+
+ if (y1 != NULL)
+ {
+ *y1 = miny;
+ }
+
+ if (x2 != NULL)
+ {
+ *x2 = maxx;
+ }
+
+ if (y2 != NULL)
+ {
+ *y2 = maxy;
+ }
}
static void
-get_all_icon_bounds (NautilusCanvasContainer *container,
- double *x1, double *y1,
- double *x2, double *y2,
- NautilusCanvasItemBoundsUsage usage)
+get_all_icon_bounds (NautilusCanvasContainer *container,
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2,
+ NautilusCanvasItemBoundsUsage usage)
{
- /* FIXME bugzilla.gnome.org 42477: Do we have to do something about the rubberband
- * here? Any other non-icon items?
- */
- get_icon_bounds_for_canvas_bounds (EEL_CANVAS_GROUP (EEL_CANVAS (container)->root),
- x1, y1, x2, y2, usage);
+ /* FIXME bugzilla.gnome.org 42477: Do we have to do something about the rubberband
+ * here? Any other non-icon items?
+ */
+ get_icon_bounds_for_canvas_bounds (EEL_CANVAS_GROUP (EEL_CANVAS (container)->root),
+ x1, y1, x2, y2, usage);
}
/* Don't preserve visible white space the next time the scroll region
@@ -993,1052 +1114,1160 @@ get_all_icon_bounds (NautilusCanvasContainer *container,
void
nautilus_canvas_container_reset_scroll_region (NautilusCanvasContainer *container)
{
- container->details->reset_scroll_region_trigger = TRUE;
+ container->details->reset_scroll_region_trigger = TRUE;
}
/* Set a new scroll region without eliminating any of the currently-visible area. */
static void
canvas_set_scroll_region_include_visible_area (EelCanvas *canvas,
- double x1, double y1,
- double x2, double y2)
+ double x1,
+ double y1,
+ double x2,
+ double y2)
{
- double old_x1, old_y1, old_x2, old_y2;
- double old_scroll_x, old_scroll_y;
- double height, width;
- GtkAllocation allocation;
-
- eel_canvas_get_scroll_region (canvas, &old_x1, &old_y1, &old_x2, &old_y2);
- gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
+ double old_x1, old_y1, old_x2, old_y2;
+ double old_scroll_x, old_scroll_y;
+ double height, width;
+ GtkAllocation allocation;
+
+ eel_canvas_get_scroll_region (canvas, &old_x1, &old_y1, &old_x2, &old_y2);
+ gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation);
- width = (allocation.width) / canvas->pixels_per_unit;
- height = (allocation.height) / canvas->pixels_per_unit;
+ width = (allocation.width) / canvas->pixels_per_unit;
+ height = (allocation.height) / canvas->pixels_per_unit;
- old_scroll_x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)));
- old_scroll_y = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)));
+ old_scroll_x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)));
+ old_scroll_y = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)));
- x1 = MIN (x1, old_x1 + old_scroll_x);
- y1 = MIN (y1, old_y1 + old_scroll_y);
- x2 = MAX (x2, old_x1 + old_scroll_x + width);
- y2 = MAX (y2, old_y1 + old_scroll_y + height);
+ x1 = MIN (x1, old_x1 + old_scroll_x);
+ y1 = MIN (y1, old_y1 + old_scroll_y);
+ x2 = MAX (x2, old_x1 + old_scroll_x + width);
+ y2 = MAX (y2, old_y1 + old_scroll_y + height);
- eel_canvas_set_scroll_region
- (canvas, x1, y1, x2, y2);
+ eel_canvas_set_scroll_region
+ (canvas, x1, y1, x2, y2);
}
void
nautilus_canvas_container_update_scroll_region (NautilusCanvasContainer *container)
{
- double x1, y1, x2, y2;
- double pixels_per_unit;
- GtkAdjustment *hadj, *vadj;
- float step_increment;
- gboolean reset_scroll_region;
- GtkAllocation allocation;
-
- pixels_per_unit = EEL_CANVAS (container)->pixels_per_unit;
-
- if (nautilus_canvas_container_get_is_fixed_size (container)) {
- /* Set the scroll region to the size of the container allocation */
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- eel_canvas_set_scroll_region
- (EEL_CANVAS (container),
- (double) - container->details->left_margin / pixels_per_unit,
- (double) - container->details->top_margin / pixels_per_unit,
- ((double) (allocation.width - 1)
- - container->details->left_margin
- - container->details->right_margin)
- / pixels_per_unit,
- ((double) (allocation.height - 1)
- - container->details->top_margin
- - container->details->bottom_margin)
- / pixels_per_unit);
- return;
- }
-
- reset_scroll_region = container->details->reset_scroll_region_trigger
- || nautilus_canvas_container_is_empty (container)
- || nautilus_canvas_container_is_auto_layout (container);
-
- /* The trigger is only cleared when container is non-empty, so
- * callers can reliably reset the scroll region when an item
- * is added even if extraneous relayouts are called when the
- * window is still empty.
- */
- if (!nautilus_canvas_container_is_empty (container)) {
- container->details->reset_scroll_region_trigger = FALSE;
- }
-
- get_all_icon_bounds (container, &x1, &y1, &x2, &y2, BOUNDS_USAGE_FOR_ENTIRE_ITEM);
-
- /* Add border at the "end"of the layout (i.e. after the icons), to
- * ensure we get some space when scrolled to the end.
- * For horizontal layouts, we add a bottom border.
- * Vertical layout is used by the compact view so the end
- * depends on the RTL setting.
- */
- if (nautilus_canvas_container_is_layout_vertical (container)) {
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- x1 -= ICON_PAD_LEFT + CONTAINER_PAD_LEFT;
- } else {
- x2 += ICON_PAD_RIGHT + CONTAINER_PAD_RIGHT;
- }
- } else {
- y2 += ICON_PAD_BOTTOM + CONTAINER_PAD_BOTTOM;
- }
-
- /* Auto-layout assumes a 0, 0 scroll origin and at least allocation->width.
- * Then we lay out to the right or to the left, so
- * x can be < 0 and > allocation */
- if (nautilus_canvas_container_is_auto_layout (container)) {
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- x1 = MIN (x1, 0);
- x2 = MAX (x2, allocation.width / pixels_per_unit);
- y1 = 0;
- } else {
- /* Otherwise we add the padding that is at the start of the
- layout */
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- x2 += ICON_PAD_RIGHT + CONTAINER_PAD_RIGHT;
- } else {
- x1 -= ICON_PAD_LEFT + CONTAINER_PAD_LEFT;
- }
- y1 -= ICON_PAD_TOP + CONTAINER_PAD_TOP;
- }
-
- x2 -= 1;
- x2 = MAX(x1, x2);
-
- y2 -= 1;
- y2 = MAX(y1, y2);
-
- if (reset_scroll_region) {
- eel_canvas_set_scroll_region
- (EEL_CANVAS (container),
- x1, y1, x2, y2);
- } else {
- canvas_set_scroll_region_include_visible_area
- (EEL_CANVAS (container),
- x1, y1, x2, y2);
- }
-
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
-
- /* Scroll by 1/4 icon each time you click. */
- step_increment = nautilus_canvas_container_get_icon_size_for_zoom_level
- (container->details->zoom_level) / 4;
- if (gtk_adjustment_get_step_increment (hadj) != step_increment) {
- gtk_adjustment_set_step_increment (hadj, step_increment);
- }
- if (gtk_adjustment_get_step_increment (vadj) != step_increment) {
- gtk_adjustment_set_step_increment (vadj, step_increment);
- }
+ double x1, y1, x2, y2;
+ double pixels_per_unit;
+ GtkAdjustment *hadj, *vadj;
+ float step_increment;
+ gboolean reset_scroll_region;
+ GtkAllocation allocation;
+
+ pixels_per_unit = EEL_CANVAS (container)->pixels_per_unit;
+
+ if (nautilus_canvas_container_get_is_fixed_size (container))
+ {
+ /* Set the scroll region to the size of the container allocation */
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ eel_canvas_set_scroll_region
+ (EEL_CANVAS (container),
+ (double) -container->details->left_margin / pixels_per_unit,
+ (double) -container->details->top_margin / pixels_per_unit,
+ ((double) (allocation.width - 1)
+ - container->details->left_margin
+ - container->details->right_margin)
+ / pixels_per_unit,
+ ((double) (allocation.height - 1)
+ - container->details->top_margin
+ - container->details->bottom_margin)
+ / pixels_per_unit);
+ return;
+ }
+
+ reset_scroll_region = container->details->reset_scroll_region_trigger
+ || nautilus_canvas_container_is_empty (container)
+ || nautilus_canvas_container_is_auto_layout (container);
+
+ /* The trigger is only cleared when container is non-empty, so
+ * callers can reliably reset the scroll region when an item
+ * is added even if extraneous relayouts are called when the
+ * window is still empty.
+ */
+ if (!nautilus_canvas_container_is_empty (container))
+ {
+ container->details->reset_scroll_region_trigger = FALSE;
+ }
+
+ get_all_icon_bounds (container, &x1, &y1, &x2, &y2, BOUNDS_USAGE_FOR_ENTIRE_ITEM);
+
+ /* Add border at the "end"of the layout (i.e. after the icons), to
+ * ensure we get some space when scrolled to the end.
+ * For horizontal layouts, we add a bottom border.
+ * Vertical layout is used by the compact view so the end
+ * depends on the RTL setting.
+ */
+ if (nautilus_canvas_container_is_layout_vertical (container))
+ {
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ x1 -= ICON_PAD_LEFT + CONTAINER_PAD_LEFT;
+ }
+ else
+ {
+ x2 += ICON_PAD_RIGHT + CONTAINER_PAD_RIGHT;
+ }
+ }
+ else
+ {
+ y2 += ICON_PAD_BOTTOM + CONTAINER_PAD_BOTTOM;
+ }
+
+ /* Auto-layout assumes a 0, 0 scroll origin and at least allocation->width.
+ * Then we lay out to the right or to the left, so
+ * x can be < 0 and > allocation */
+ if (nautilus_canvas_container_is_auto_layout (container))
+ {
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ x1 = MIN (x1, 0);
+ x2 = MAX (x2, allocation.width / pixels_per_unit);
+ y1 = 0;
+ }
+ else
+ {
+ /* Otherwise we add the padding that is at the start of the
+ * layout */
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ x2 += ICON_PAD_RIGHT + CONTAINER_PAD_RIGHT;
+ }
+ else
+ {
+ x1 -= ICON_PAD_LEFT + CONTAINER_PAD_LEFT;
+ }
+ y1 -= ICON_PAD_TOP + CONTAINER_PAD_TOP;
+ }
+
+ x2 -= 1;
+ x2 = MAX (x1, x2);
+
+ y2 -= 1;
+ y2 = MAX (y1, y2);
+
+ if (reset_scroll_region)
+ {
+ eel_canvas_set_scroll_region
+ (EEL_CANVAS (container),
+ x1, y1, x2, y2);
+ }
+ else
+ {
+ canvas_set_scroll_region_include_visible_area
+ (EEL_CANVAS (container),
+ x1, y1, x2, y2);
+ }
+
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
+
+ /* Scroll by 1/4 icon each time you click. */
+ step_increment = nautilus_canvas_container_get_icon_size_for_zoom_level
+ (container->details->zoom_level) / 4;
+ if (gtk_adjustment_get_step_increment (hadj) != step_increment)
+ {
+ gtk_adjustment_set_step_increment (hadj, step_increment);
+ }
+ if (gtk_adjustment_get_step_increment (vadj) != step_increment)
+ {
+ gtk_adjustment_set_step_increment (vadj, step_increment);
+ }
}
static void
cache_icon_positions (NautilusCanvasContainer *container)
{
- GList *l;
- gint idx;
- NautilusCanvasIcon *icon;
+ GList *l;
+ gint idx;
+ NautilusCanvasIcon *icon;
- for (l = container->details->icons, idx = 0; l != NULL; l = l ->next) {
- icon = l->data;
- icon->position = idx++;
- }
+ for (l = container->details->icons, idx = 0; l != NULL; l = l->next)
+ {
+ icon = l->data;
+ icon->position = idx++;
+ }
}
static int
-compare_icons_data (gconstpointer a, gconstpointer b, gpointer canvas_container)
+compare_icons_data (gconstpointer a,
+ gconstpointer b,
+ gpointer canvas_container)
{
- NautilusCanvasContainerClass *klass;
- NautilusCanvasIconData *data_a, *data_b;
+ NautilusCanvasContainerClass *klass;
+ NautilusCanvasIconData *data_a, *data_b;
- data_a = (NautilusCanvasIconData *) a;
- data_b = (NautilusCanvasIconData *) b;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (canvas_container);
+ data_a = (NautilusCanvasIconData *) a;
+ data_b = (NautilusCanvasIconData *) b;
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (canvas_container);
- return klass->compare_icons (canvas_container, data_a, data_b);
+ return klass->compare_icons (canvas_container, data_a, data_b);
}
static int
-compare_icons (gconstpointer a, gconstpointer b, gpointer canvas_container)
+compare_icons (gconstpointer a,
+ gconstpointer b,
+ gpointer canvas_container)
{
- NautilusCanvasContainerClass *klass;
- const NautilusCanvasIcon *icon_a, *icon_b;
+ NautilusCanvasContainerClass *klass;
+ const NautilusCanvasIcon *icon_a, *icon_b;
- icon_a = a;
- icon_b = b;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (canvas_container);
+ icon_a = a;
+ icon_b = b;
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (canvas_container);
- return klass->compare_icons (canvas_container, icon_a->data, icon_b->data);
+ return klass->compare_icons (canvas_container, icon_a->data, icon_b->data);
}
static void
sort_selection (NautilusCanvasContainer *container)
{
- container->details->selection = g_list_sort_with_data (container->details->selection,
- compare_icons_data,
- container);
- container->details->selection_needs_resort = FALSE;
+ container->details->selection = g_list_sort_with_data (container->details->selection,
+ compare_icons_data,
+ container);
+ container->details->selection_needs_resort = FALSE;
}
static void
-sort_icons (NautilusCanvasContainer *container,
- GList **icons)
+sort_icons (NautilusCanvasContainer *container,
+ GList **icons)
{
- NautilusCanvasContainerClass *klass;
+ NautilusCanvasContainerClass *klass;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
- g_assert (klass->compare_icons != NULL);
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
+ g_assert (klass->compare_icons != NULL);
- *icons = g_list_sort_with_data (*icons, compare_icons, container);
+ *icons = g_list_sort_with_data (*icons, compare_icons, container);
}
static void
resort (NautilusCanvasContainer *container)
{
- sort_icons (container, &container->details->icons);
- sort_selection (container);
- cache_icon_positions (container);
+ sort_icons (container, &container->details->icons);
+ sort_selection (container);
+ cache_icon_positions (container);
}
-typedef struct {
- double width;
- double height;
- double x_offset;
- double y_offset;
+typedef struct
+{
+ double width;
+ double height;
+ double x_offset;
+ double y_offset;
} IconPositions;
static void
lay_down_one_line (NautilusCanvasContainer *container,
- GList *line_start,
- GList *line_end,
- double y,
- double max_height,
- GArray *positions,
- gboolean whole_text)
+ GList *line_start,
+ GList *line_end,
+ double y,
+ double max_height,
+ GArray *positions,
+ gboolean whole_text)
{
- GList *p;
- NautilusCanvasIcon *icon;
- double x, y_offset;
- IconPositions *position;
- int i;
- gboolean is_rtl;
+ GList *p;
+ NautilusCanvasIcon *icon;
+ double x, y_offset;
+ IconPositions *position;
+ int i;
+ gboolean is_rtl;
- is_rtl = nautilus_canvas_container_is_layout_rtl (container);
+ is_rtl = nautilus_canvas_container_is_layout_rtl (container);
- /* Lay out the icons along the baseline. */
- x = ICON_PAD_LEFT;
- i = 0;
- for (p = line_start; p != line_end; p = p->next) {
- icon = p->data;
+ /* Lay out the icons along the baseline. */
+ x = ICON_PAD_LEFT;
+ i = 0;
+ for (p = line_start; p != line_end; p = p->next)
+ {
+ icon = p->data;
- position = &g_array_index (positions, IconPositions, i++);
- y_offset = position->y_offset;
+ position = &g_array_index (positions, IconPositions, i++);
+ y_offset = position->y_offset;
- icon_set_position
- (icon,
- is_rtl ? get_mirror_x_position (container, icon, x + position->x_offset) : x + position->x_offset,
- y + y_offset);
- nautilus_canvas_item_set_entire_text (icon->item, whole_text);
+ icon_set_position
+ (icon,
+ is_rtl ? get_mirror_x_position (container, icon, x + position->x_offset) : x + position->x_offset,
+ y + y_offset);
+ nautilus_canvas_item_set_entire_text (icon->item, whole_text);
- icon->saved_ltr_x = is_rtl ? get_mirror_x_position (container, icon, icon->x) : icon->x;
+ icon->saved_ltr_x = is_rtl ? get_mirror_x_position (container, icon, icon->x) : icon->x;
- x += position->width;
- }
+ x += position->width;
+ }
}
static void
lay_down_icons_horizontal (NautilusCanvasContainer *container,
- GList *icons,
- double start_y)
-{
- GList *p, *line_start;
- NautilusCanvasIcon *icon;
- double canvas_width, y;
- GArray *positions;
- IconPositions *position;
- EelDRect bounds;
- EelDRect icon_bounds;
- double max_height_above, max_height_below;
- double height_above, height_below;
- double line_width;
- double grid_width;
- int icon_width, icon_size;
- int i;
- GtkAllocation allocation;
-
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
-
- if (icons == NULL) {
- return;
- }
-
- positions = g_array_new (FALSE, FALSE, sizeof (IconPositions));
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
-
- /* Lay out icons a line at a time. */
- canvas_width = CANVAS_WIDTH(container, allocation);
-
- grid_width = nautilus_canvas_container_get_grid_size_for_zoom_level (container->details->zoom_level);
- icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level);
-
- line_width = 0;
- line_start = icons;
- y = start_y + CONTAINER_PAD_TOP;
- i = 0;
-
- max_height_above = 0;
- max_height_below = 0;
- for (p = icons; p != NULL; p = p->next) {
- icon = p->data;
-
- /* Assume it's only one level hierarchy to avoid costly affine calculations */
- nautilus_canvas_item_get_bounds_for_layout (icon->item,
- &bounds.x0, &bounds.y0,
- &bounds.x1, &bounds.y1);
-
- /* Normalize the icon width to the grid unit.
- * Use the icon size for this zoom level too in the calculation, since
- * the actual bounds might be smaller - e.g. because we have a very
- * narrow thumbnail.
- */
- icon_width = ceil (MAX ((bounds.x1 - bounds.x0), icon_size) / grid_width) * grid_width;
-
- /* Calculate size above/below baseline */
- icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
- height_above = icon_bounds.y1 - bounds.y0;
- height_below = bounds.y1 - icon_bounds.y1;
-
- /* If this icon doesn't fit, it's time to lay out the line that's queued up. */
- if (line_start != p && line_width + icon_width >= canvas_width ) {
- /* Advance to the baseline. */
- y += ICON_PAD_TOP + max_height_above;
-
- lay_down_one_line (container, line_start, p, y, max_height_above, positions, FALSE);
-
- /* Advance to next line. */
- y += max_height_below + ICON_PAD_BOTTOM;
-
- line_width = 0;
- line_start = p;
- i = 0;
-
- max_height_above = height_above;
- max_height_below = height_below;
- } else {
- if (height_above > max_height_above) {
- max_height_above = height_above;
- }
- if (height_below > max_height_below) {
- max_height_below = height_below;
- }
- }
-
- g_array_set_size (positions, i + 1);
- position = &g_array_index (positions, IconPositions, i++);
- position->width = icon_width;
- position->height = icon_bounds.y1 - icon_bounds.y0;
-
- position->x_offset = (icon_width - (icon_bounds.x1 - icon_bounds.x0)) / 2;
- position->y_offset = icon_bounds.y0 - icon_bounds.y1;
-
- /* Add this icon. */
- line_width += icon_width;
- }
-
- /* Lay down that last line of icons. */
- if (line_start != NULL) {
- /* Advance to the baseline. */
- y += ICON_PAD_TOP + max_height_above;
-
- lay_down_one_line (container, line_start, NULL, y, max_height_above, positions, TRUE);
- }
-
- g_array_free (positions, TRUE);
+ GList *icons,
+ double start_y)
+{
+ GList *p, *line_start;
+ NautilusCanvasIcon *icon;
+ double canvas_width, y;
+ GArray *positions;
+ IconPositions *position;
+ EelDRect bounds;
+ EelDRect icon_bounds;
+ double max_height_above, max_height_below;
+ double height_above, height_below;
+ double line_width;
+ double grid_width;
+ int icon_width, icon_size;
+ int i;
+ GtkAllocation allocation;
+
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+
+ if (icons == NULL)
+ {
+ return;
+ }
+
+ positions = g_array_new (FALSE, FALSE, sizeof (IconPositions));
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+
+ /* Lay out icons a line at a time. */
+ canvas_width = CANVAS_WIDTH (container, allocation);
+
+ grid_width = nautilus_canvas_container_get_grid_size_for_zoom_level (container->details->zoom_level);
+ icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level);
+
+ line_width = 0;
+ line_start = icons;
+ y = start_y + CONTAINER_PAD_TOP;
+ i = 0;
+
+ max_height_above = 0;
+ max_height_below = 0;
+ for (p = icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ /* Assume it's only one level hierarchy to avoid costly affine calculations */
+ nautilus_canvas_item_get_bounds_for_layout (icon->item,
+ &bounds.x0, &bounds.y0,
+ &bounds.x1, &bounds.y1);
+
+ /* Normalize the icon width to the grid unit.
+ * Use the icon size for this zoom level too in the calculation, since
+ * the actual bounds might be smaller - e.g. because we have a very
+ * narrow thumbnail.
+ */
+ icon_width = ceil (MAX ((bounds.x1 - bounds.x0), icon_size) / grid_width) * grid_width;
+
+ /* Calculate size above/below baseline */
+ icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
+ height_above = icon_bounds.y1 - bounds.y0;
+ height_below = bounds.y1 - icon_bounds.y1;
+
+ /* If this icon doesn't fit, it's time to lay out the line that's queued up. */
+ if (line_start != p && line_width + icon_width >= canvas_width)
+ {
+ /* Advance to the baseline. */
+ y += ICON_PAD_TOP + max_height_above;
+
+ lay_down_one_line (container, line_start, p, y, max_height_above, positions, FALSE);
+
+ /* Advance to next line. */
+ y += max_height_below + ICON_PAD_BOTTOM;
+
+ line_width = 0;
+ line_start = p;
+ i = 0;
+
+ max_height_above = height_above;
+ max_height_below = height_below;
+ }
+ else
+ {
+ if (height_above > max_height_above)
+ {
+ max_height_above = height_above;
+ }
+ if (height_below > max_height_below)
+ {
+ max_height_below = height_below;
+ }
+ }
+
+ g_array_set_size (positions, i + 1);
+ position = &g_array_index (positions, IconPositions, i++);
+ position->width = icon_width;
+ position->height = icon_bounds.y1 - icon_bounds.y0;
+
+ position->x_offset = (icon_width - (icon_bounds.x1 - icon_bounds.x0)) / 2;
+ position->y_offset = icon_bounds.y0 - icon_bounds.y1;
+
+ /* Add this icon. */
+ line_width += icon_width;
+ }
+
+ /* Lay down that last line of icons. */
+ if (line_start != NULL)
+ {
+ /* Advance to the baseline. */
+ y += ICON_PAD_TOP + max_height_above;
+
+ lay_down_one_line (container, line_start, NULL, y, max_height_above, positions, TRUE);
+ }
+
+ g_array_free (positions, TRUE);
}
static void
snap_position (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- int *x, int *y)
-{
- int center_x;
- int baseline_y;
- int icon_width;
- int icon_height;
- int total_width;
- int total_height;
- EelDRect canvas_position;
- GtkAllocation allocation;
-
- canvas_position = nautilus_canvas_item_get_icon_rectangle (icon->item);
- icon_width = canvas_position.x1 - canvas_position.x0;
- icon_height = canvas_position.y1 - canvas_position.y0;
-
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- total_width = CANVAS_WIDTH (container, allocation);
- total_height = CANVAS_HEIGHT (container, allocation);
-
- if (nautilus_canvas_container_is_layout_rtl (container))
- *x = get_mirror_x_position (container, icon, *x);
-
- if (*x + icon_width / 2 < DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X) {
- *x = DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X - icon_width / 2;
- }
-
- if (*x + icon_width / 2 > total_width - (DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X)) {
- *x = total_width - (DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X + (icon_width / 2));
- }
-
- if (*y + icon_height < DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y) {
- *y = DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y - icon_height;
- }
-
- if (*y + icon_height > total_height - (DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y)) {
- *y = total_height - (DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y + (icon_height / 2));
- }
-
- center_x = *x + icon_width / 2;
- *x = SNAP_NEAREST_HORIZONTAL (center_x) - (icon_width / 2);
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- *x = get_mirror_x_position (container, icon, *x);
- }
-
-
- /* Find the grid position vertically and place on the proper baseline */
- baseline_y = *y + icon_height;
- baseline_y = SNAP_NEAREST_VERTICAL (baseline_y);
- *y = baseline_y - icon_height;
+ NautilusCanvasIcon *icon,
+ int *x,
+ int *y)
+{
+ int center_x;
+ int baseline_y;
+ int icon_width;
+ int icon_height;
+ int total_width;
+ int total_height;
+ EelDRect canvas_position;
+ GtkAllocation allocation;
+
+ canvas_position = nautilus_canvas_item_get_icon_rectangle (icon->item);
+ icon_width = canvas_position.x1 - canvas_position.x0;
+ icon_height = canvas_position.y1 - canvas_position.y0;
+
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ total_width = CANVAS_WIDTH (container, allocation);
+ total_height = CANVAS_HEIGHT (container, allocation);
+
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ *x = get_mirror_x_position (container, icon, *x);
+ }
+
+ if (*x + icon_width / 2 < DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X)
+ {
+ *x = DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X - icon_width / 2;
+ }
+
+ if (*x + icon_width / 2 > total_width - (DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X))
+ {
+ *x = total_width - (DESKTOP_PAD_HORIZONTAL + SNAP_SIZE_X + (icon_width / 2));
+ }
+
+ if (*y + icon_height < DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y)
+ {
+ *y = DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y - icon_height;
+ }
+
+ if (*y + icon_height > total_height - (DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y))
+ {
+ *y = total_height - (DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y + (icon_height / 2));
+ }
+
+ center_x = *x + icon_width / 2;
+ *x = SNAP_NEAREST_HORIZONTAL (center_x) - (icon_width / 2);
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ *x = get_mirror_x_position (container, icon, *x);
+ }
+
+
+ /* Find the grid position vertically and place on the proper baseline */
+ baseline_y = *y + icon_height;
+ baseline_y = SNAP_NEAREST_VERTICAL (baseline_y);
+ *y = baseline_y - icon_height;
}
static int
-compare_icons_by_position (gconstpointer a, gconstpointer b)
+compare_icons_by_position (gconstpointer a,
+ gconstpointer b)
{
- NautilusCanvasIcon *icon_a, *icon_b;
- int x1, y1, x2, y2;
- int center_a;
- int center_b;
+ NautilusCanvasIcon *icon_a, *icon_b;
+ int x1, y1, x2, y2;
+ int center_a;
+ int center_b;
- icon_a = (NautilusCanvasIcon *)a;
- icon_b = (NautilusCanvasIcon *)b;
+ icon_a = (NautilusCanvasIcon *) a;
+ icon_b = (NautilusCanvasIcon *) b;
- icon_get_bounding_box (icon_a, &x1, &y1, &x2, &y2,
- BOUNDS_USAGE_FOR_DISPLAY);
- center_a = x1 + (x2 - x1) / 2;
- icon_get_bounding_box (icon_b, &x1, &y1, &x2, &y2,
- BOUNDS_USAGE_FOR_DISPLAY);
- center_b = x1 + (x2 - x1) / 2;
+ icon_get_bounding_box (icon_a, &x1, &y1, &x2, &y2,
+ BOUNDS_USAGE_FOR_DISPLAY);
+ center_a = x1 + (x2 - x1) / 2;
+ icon_get_bounding_box (icon_b, &x1, &y1, &x2, &y2,
+ BOUNDS_USAGE_FOR_DISPLAY);
+ center_b = x1 + (x2 - x1) / 2;
- return center_a == center_b ?
- icon_a->y - icon_b->y :
- center_a - center_b;
+ return center_a == center_b ?
+ icon_a->y - icon_b->y :
+ center_a - center_b;
}
static PlacementGrid *
-placement_grid_new (NautilusCanvasContainer *container, gboolean tight)
-{
- PlacementGrid *grid;
- int width, height;
- int num_columns;
- int num_rows;
- int i;
- GtkAllocation allocation;
-
- /* Get container dimensions */
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- width = CANVAS_WIDTH(container, allocation);
- height = CANVAS_HEIGHT(container, allocation);
-
- num_columns = width / SNAP_SIZE_X;
- num_rows = height / SNAP_SIZE_Y;
-
- if (num_columns == 0 || num_rows == 0) {
- return NULL;
- }
-
- grid = g_new0 (PlacementGrid, 1);
- grid->tight = tight;
- grid->num_columns = num_columns;
- grid->num_rows = num_rows;
-
- grid->grid_memory = g_new0 (int, (num_rows * num_columns));
- grid->icon_grid = g_new0 (int *, num_columns);
-
- for (i = 0; i < num_columns; i++) {
- grid->icon_grid[i] = grid->grid_memory + (i * num_rows);
- }
-
- return grid;
+placement_grid_new (NautilusCanvasContainer *container,
+ gboolean tight)
+{
+ PlacementGrid *grid;
+ int width, height;
+ int num_columns;
+ int num_rows;
+ int i;
+ GtkAllocation allocation;
+
+ /* Get container dimensions */
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ width = CANVAS_WIDTH (container, allocation);
+ height = CANVAS_HEIGHT (container, allocation);
+
+ num_columns = width / SNAP_SIZE_X;
+ num_rows = height / SNAP_SIZE_Y;
+
+ if (num_columns == 0 || num_rows == 0)
+ {
+ return NULL;
+ }
+
+ grid = g_new0 (PlacementGrid, 1);
+ grid->tight = tight;
+ grid->num_columns = num_columns;
+ grid->num_rows = num_rows;
+
+ grid->grid_memory = g_new0 (int, (num_rows * num_columns));
+ grid->icon_grid = g_new0 (int *, num_columns);
+
+ for (i = 0; i < num_columns; i++)
+ {
+ grid->icon_grid[i] = grid->grid_memory + (i * num_rows);
+ }
+
+ return grid;
}
static void
placement_grid_free (PlacementGrid *grid)
{
- g_free (grid->icon_grid);
- g_free (grid->grid_memory);
- g_free (grid);
+ g_free (grid->icon_grid);
+ g_free (grid->grid_memory);
+ g_free (grid);
}
static gboolean
-placement_grid_position_is_free (PlacementGrid *grid, EelIRect pos)
-{
- int x, y;
-
- g_assert (pos.x0 >= 0 && pos.x0 < grid->num_columns);
- g_assert (pos.y0 >= 0 && pos.y0 < grid->num_rows);
- g_assert (pos.x1 >= 0 && pos.x1 < grid->num_columns);
- g_assert (pos.y1 >= 0 && pos.y1 < grid->num_rows);
-
- for (x = pos.x0; x <= pos.x1; x++) {
- for (y = pos.y0; y <= pos.y1; y++) {
- if (grid->icon_grid[x][y] != 0) {
- return FALSE;
- }
- }
- }
+placement_grid_position_is_free (PlacementGrid *grid,
+ EelIRect pos)
+{
+ int x, y;
+
+ g_assert (pos.x0 >= 0 && pos.x0 < grid->num_columns);
+ g_assert (pos.y0 >= 0 && pos.y0 < grid->num_rows);
+ g_assert (pos.x1 >= 0 && pos.x1 < grid->num_columns);
+ g_assert (pos.y1 >= 0 && pos.y1 < grid->num_rows);
+
+ for (x = pos.x0; x <= pos.x1; x++)
+ {
+ for (y = pos.y0; y <= pos.y1; y++)
+ {
+ if (grid->icon_grid[x][y] != 0)
+ {
+ return FALSE;
+ }
+ }
+ }
- return TRUE;
+ return TRUE;
}
static void
-placement_grid_mark (PlacementGrid *grid, EelIRect pos)
+placement_grid_mark (PlacementGrid *grid,
+ EelIRect pos)
{
- int x, y;
-
- g_assert (pos.x0 >= 0 && pos.x0 < grid->num_columns);
- g_assert (pos.y0 >= 0 && pos.y0 < grid->num_rows);
- g_assert (pos.x1 >= 0 && pos.x1 < grid->num_columns);
- g_assert (pos.y1 >= 0 && pos.y1 < grid->num_rows);
+ int x, y;
+
+ g_assert (pos.x0 >= 0 && pos.x0 < grid->num_columns);
+ g_assert (pos.y0 >= 0 && pos.y0 < grid->num_rows);
+ g_assert (pos.x1 >= 0 && pos.x1 < grid->num_columns);
+ g_assert (pos.y1 >= 0 && pos.y1 < grid->num_rows);
- for (x = pos.x0; x <= pos.x1; x++) {
- for (y = pos.y0; y <= pos.y1; y++) {
- grid->icon_grid[x][y] = 1;
- }
- }
+ for (x = pos.x0; x <= pos.x1; x++)
+ {
+ for (y = pos.y0; y <= pos.y1; y++)
+ {
+ grid->icon_grid[x][y] = 1;
+ }
+ }
}
static void
canvas_position_to_grid_position (PlacementGrid *grid,
- EelIRect canvas_position,
- EelIRect *grid_position)
-{
- /* The first causes minimal moving around during a snap, but
- * can end up with partially overlapping icons. The second one won't
- * allow any overlapping, but can cause more movement to happen
- * during a snap. */
- if (grid->tight) {
- grid_position->x0 = ceil ((double)(canvas_position.x0 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
- grid_position->y0 = ceil ((double)(canvas_position.y0 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
- grid_position->x1 = floor ((double)(canvas_position.x1 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
- grid_position->y1 = floor ((double)(canvas_position.y1 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
- } else {
- grid_position->x0 = floor ((double)(canvas_position.x0 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
- grid_position->y0 = floor ((double)(canvas_position.y0 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
- grid_position->x1 = floor ((double)(canvas_position.x1 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
- grid_position->y1 = floor ((double)(canvas_position.y1 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
- }
-
- grid_position->x0 = CLAMP (grid_position->x0, 0, grid->num_columns - 1);
- grid_position->y0 = CLAMP (grid_position->y0, 0, grid->num_rows - 1);
- grid_position->x1 = CLAMP (grid_position->x1, grid_position->x0, grid->num_columns - 1);
- grid_position->y1 = CLAMP (grid_position->y1, grid_position->y0, grid->num_rows - 1);
+ EelIRect canvas_position,
+ EelIRect *grid_position)
+{
+ /* The first causes minimal moving around during a snap, but
+ * can end up with partially overlapping icons. The second one won't
+ * allow any overlapping, but can cause more movement to happen
+ * during a snap. */
+ if (grid->tight)
+ {
+ grid_position->x0 = ceil ((double) (canvas_position.x0 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
+ grid_position->y0 = ceil ((double) (canvas_position.y0 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
+ grid_position->x1 = floor ((double) (canvas_position.x1 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
+ grid_position->y1 = floor ((double) (canvas_position.y1 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
+ }
+ else
+ {
+ grid_position->x0 = floor ((double) (canvas_position.x0 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
+ grid_position->y0 = floor ((double) (canvas_position.y0 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
+ grid_position->x1 = floor ((double) (canvas_position.x1 - DESKTOP_PAD_HORIZONTAL) / SNAP_SIZE_X);
+ grid_position->y1 = floor ((double) (canvas_position.y1 - DESKTOP_PAD_VERTICAL) / SNAP_SIZE_Y);
+ }
+
+ grid_position->x0 = CLAMP (grid_position->x0, 0, grid->num_columns - 1);
+ grid_position->y0 = CLAMP (grid_position->y0, 0, grid->num_rows - 1);
+ grid_position->x1 = CLAMP (grid_position->x1, grid_position->x0, grid->num_columns - 1);
+ grid_position->y1 = CLAMP (grid_position->y1, grid_position->y0, grid->num_rows - 1);
}
static void
-placement_grid_mark_icon (PlacementGrid *grid, NautilusCanvasIcon *icon)
+placement_grid_mark_icon (PlacementGrid *grid,
+ NautilusCanvasIcon *icon)
{
- EelIRect canvas_pos;
- EelIRect grid_pos;
-
- icon_get_bounding_box (icon,
- &canvas_pos.x0, &canvas_pos.y0,
- &canvas_pos.x1, &canvas_pos.y1,
- BOUNDS_USAGE_FOR_LAYOUT);
- canvas_position_to_grid_position (grid,
- canvas_pos,
- &grid_pos);
- placement_grid_mark (grid, grid_pos);
+ EelIRect canvas_pos;
+ EelIRect grid_pos;
+
+ icon_get_bounding_box (icon,
+ &canvas_pos.x0, &canvas_pos.y0,
+ &canvas_pos.x1, &canvas_pos.y1,
+ BOUNDS_USAGE_FOR_LAYOUT);
+ canvas_position_to_grid_position (grid,
+ canvas_pos,
+ &grid_pos);
+ placement_grid_mark (grid, grid_pos);
}
static void
find_empty_location (NautilusCanvasContainer *container,
- PlacementGrid *grid,
- NautilusCanvasIcon *icon,
- int start_x,
- int start_y,
- int *x,
- int *y)
-{
- double icon_width, icon_height;
- int canvas_width;
- int canvas_height;
- int height_for_bound_check;
- EelIRect icon_position;
- EelDRect pixbuf_rect;
- gboolean collision;
- GtkAllocation allocation;
-
- /* Get container dimensions */
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- canvas_width = CANVAS_WIDTH(container, allocation);
- canvas_height = CANVAS_HEIGHT(container, allocation);
-
- icon_get_bounding_box (icon,
- &icon_position.x0, &icon_position.y0,
- &icon_position.x1, &icon_position.y1,
- BOUNDS_USAGE_FOR_LAYOUT);
- icon_width = icon_position.x1 - icon_position.x0;
- icon_height = icon_position.y1 - icon_position.y0;
-
- icon_get_bounding_box (icon,
- NULL, &icon_position.y0,
- NULL, &icon_position.y1,
- BOUNDS_USAGE_FOR_ENTIRE_ITEM);
- height_for_bound_check = icon_position.y1 - icon_position.y0;
-
- pixbuf_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
-
- /* Start the icon on a grid location */
- snap_position (container, icon, &start_x, &start_y);
-
- icon_position.x0 = start_x;
- icon_position.y0 = start_y;
- icon_position.x1 = icon_position.x0 + icon_width;
- icon_position.y1 = icon_position.y0 + icon_height;
-
- do {
- EelIRect grid_position;
- gboolean need_new_column;
-
- collision = FALSE;
-
- canvas_position_to_grid_position (grid,
- icon_position,
- &grid_position);
-
- need_new_column = icon_position.y0 + height_for_bound_check + DESKTOP_PAD_VERTICAL > canvas_height;
-
- if (need_new_column ||
- !placement_grid_position_is_free (grid, grid_position)) {
- icon_position.y0 += SNAP_SIZE_Y;
- icon_position.y1 = icon_position.y0 + icon_height;
-
- if (need_new_column) {
- /* Move to the next column */
- icon_position.y0 = DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y - (pixbuf_rect.y1 - pixbuf_rect.y0);
- while (icon_position.y0 < DESKTOP_PAD_VERTICAL) {
- icon_position.y0 += SNAP_SIZE_Y;
- }
- icon_position.y1 = icon_position.y0 + icon_height;
-
- icon_position.x0 += SNAP_SIZE_X;
- icon_position.x1 = icon_position.x0 + icon_width;
- }
-
- collision = TRUE;
- }
- } while (collision && (icon_position.x1 < canvas_width));
-
- *x = icon_position.x0;
- *y = icon_position.y0;
+ PlacementGrid *grid,
+ NautilusCanvasIcon *icon,
+ int start_x,
+ int start_y,
+ int *x,
+ int *y)
+{
+ double icon_width, icon_height;
+ int canvas_width;
+ int canvas_height;
+ int height_for_bound_check;
+ EelIRect icon_position;
+ EelDRect pixbuf_rect;
+ gboolean collision;
+ GtkAllocation allocation;
+
+ /* Get container dimensions */
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ canvas_width = CANVAS_WIDTH (container, allocation);
+ canvas_height = CANVAS_HEIGHT (container, allocation);
+
+ icon_get_bounding_box (icon,
+ &icon_position.x0, &icon_position.y0,
+ &icon_position.x1, &icon_position.y1,
+ BOUNDS_USAGE_FOR_LAYOUT);
+ icon_width = icon_position.x1 - icon_position.x0;
+ icon_height = icon_position.y1 - icon_position.y0;
+
+ icon_get_bounding_box (icon,
+ NULL, &icon_position.y0,
+ NULL, &icon_position.y1,
+ BOUNDS_USAGE_FOR_ENTIRE_ITEM);
+ height_for_bound_check = icon_position.y1 - icon_position.y0;
+
+ pixbuf_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
+
+ /* Start the icon on a grid location */
+ snap_position (container, icon, &start_x, &start_y);
+
+ icon_position.x0 = start_x;
+ icon_position.y0 = start_y;
+ icon_position.x1 = icon_position.x0 + icon_width;
+ icon_position.y1 = icon_position.y0 + icon_height;
+
+ do
+ {
+ EelIRect grid_position;
+ gboolean need_new_column;
+
+ collision = FALSE;
+
+ canvas_position_to_grid_position (grid,
+ icon_position,
+ &grid_position);
+
+ need_new_column = icon_position.y0 + height_for_bound_check + DESKTOP_PAD_VERTICAL > canvas_height;
+
+ if (need_new_column ||
+ !placement_grid_position_is_free (grid, grid_position))
+ {
+ icon_position.y0 += SNAP_SIZE_Y;
+ icon_position.y1 = icon_position.y0 + icon_height;
+
+ if (need_new_column)
+ {
+ /* Move to the next column */
+ icon_position.y0 = DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y - (pixbuf_rect.y1 - pixbuf_rect.y0);
+ while (icon_position.y0 < DESKTOP_PAD_VERTICAL)
+ {
+ icon_position.y0 += SNAP_SIZE_Y;
+ }
+ icon_position.y1 = icon_position.y0 + icon_height;
+
+ icon_position.x0 += SNAP_SIZE_X;
+ icon_position.x1 = icon_position.x0 + icon_width;
+ }
+
+ collision = TRUE;
+ }
+ }
+ while (collision && (icon_position.x1 < canvas_width));
+
+ *x = icon_position.x0;
+ *y = icon_position.y0;
}
static void
align_icons (NautilusCanvasContainer *container)
{
- GList *unplaced_icons;
- GList *l;
- PlacementGrid *grid;
+ GList *unplaced_icons;
+ GList *l;
+ PlacementGrid *grid;
- unplaced_icons = g_list_copy (container->details->icons);
-
- unplaced_icons = g_list_sort (unplaced_icons,
- compare_icons_by_position);
+ unplaced_icons = g_list_copy (container->details->icons);
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- unplaced_icons = g_list_reverse (unplaced_icons);
- }
+ unplaced_icons = g_list_sort (unplaced_icons,
+ compare_icons_by_position);
- grid = placement_grid_new (container, TRUE);
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ unplaced_icons = g_list_reverse (unplaced_icons);
+ }
- if (!grid) {
- return;
- }
+ grid = placement_grid_new (container, TRUE);
- for (l = unplaced_icons; l != NULL; l = l->next) {
- NautilusCanvasIcon *icon;
- int x, y;
+ if (!grid)
+ {
+ return;
+ }
+
+ for (l = unplaced_icons; l != NULL; l = l->next)
+ {
+ NautilusCanvasIcon *icon;
+ int x, y;
- icon = l->data;
- x = icon->saved_ltr_x;
- y = icon->y;
- find_empty_location (container, grid,
- icon, x, y, &x, &y);
+ icon = l->data;
+ x = icon->saved_ltr_x;
+ y = icon->y;
+ find_empty_location (container, grid,
+ icon, x, y, &x, &y);
- icon_set_position (icon, x, y);
- icon->saved_ltr_x = icon->x;
- placement_grid_mark_icon (grid, icon);
- }
+ icon_set_position (icon, x, y);
+ icon->saved_ltr_x = icon->x;
+ placement_grid_mark_icon (grid, icon);
+ }
- g_list_free (unplaced_icons);
+ g_list_free (unplaced_icons);
- placement_grid_free (grid);
+ placement_grid_free (grid);
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- nautilus_canvas_container_set_rtl_positions (container);
- }
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ nautilus_canvas_container_set_rtl_positions (container);
+ }
}
static double
-get_mirror_x_position (NautilusCanvasContainer *container, NautilusCanvasIcon *icon, double x)
+get_mirror_x_position (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *icon,
+ double x)
{
- EelDRect icon_bounds;
- GtkAllocation allocation;
+ EelDRect icon_bounds;
+ GtkAllocation allocation;
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ icon_bounds = nautilus_canvas_item_get_icon_rectangle (icon->item);
- return CANVAS_WIDTH(container, allocation) - x - (icon_bounds.x1 - icon_bounds.x0);
+ return CANVAS_WIDTH (container, allocation) - x - (icon_bounds.x1 - icon_bounds.x0);
}
static void
nautilus_canvas_container_set_rtl_positions (NautilusCanvasContainer *container)
{
- GList *l;
- NautilusCanvasIcon *icon;
- double x;
+ GList *l;
+ NautilusCanvasIcon *icon;
+ double x;
- if (!container->details->icons) {
- return;
- }
+ if (!container->details->icons)
+ {
+ return;
+ }
- for (l = container->details->icons; l != NULL; l = l->next) {
- icon = l->data;
- x = get_mirror_x_position (container, icon, icon->saved_ltr_x);
- icon_set_position (icon, x, icon->y);
- }
+ for (l = container->details->icons; l != NULL; l = l->next)
+ {
+ icon = l->data;
+ x = get_mirror_x_position (container, icon, icon->saved_ltr_x);
+ icon_set_position (icon, x, icon->y);
+ }
}
static void
-lay_down_icons_vertical_desktop (NautilusCanvasContainer *container, GList *icons)
-{
- GList *p, *placed_icons, *unplaced_icons;
- int total, new_length, placed;
- NautilusCanvasIcon *icon;
- int height, max_width, column_width, icon_width, icon_height;
- int x, y, x1, x2, y1, y2;
- EelDRect icon_rect;
- GtkAllocation allocation;
-
- /* Get container dimensions */
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- height = CANVAS_HEIGHT(container, allocation);
-
- /* Determine which icons have and have not been placed */
- placed_icons = NULL;
- unplaced_icons = NULL;
-
- total = g_list_length (container->details->icons);
- new_length = g_list_length (icons);
- placed = total - new_length;
- if (placed > 0) {
- PlacementGrid *grid;
- /* Add only placed icons in list */
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
- if (icon_is_positioned (icon)) {
- icon_set_position(icon, icon->saved_ltr_x, icon->y);
- placed_icons = g_list_prepend (placed_icons, icon);
- } else {
- icon->x = 0;
- icon->y = 0;
- unplaced_icons = g_list_prepend (unplaced_icons, icon);
- }
- }
- placed_icons = g_list_reverse (placed_icons);
- unplaced_icons = g_list_reverse (unplaced_icons);
-
- grid = placement_grid_new (container, FALSE);
-
- if (grid) {
- for (p = placed_icons; p != NULL; p = p->next) {
- placement_grid_mark_icon
- (grid, (NautilusCanvasIcon *)p->data);
- }
-
- /* Place unplaced icons in the best locations */
- for (p = unplaced_icons; p != NULL; p = p->next) {
- icon = p->data;
-
- icon_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
-
- /* Start the icon in the first column */
- x = DESKTOP_PAD_HORIZONTAL + (SNAP_SIZE_X / 2) - ((icon_rect.x1 - icon_rect.x0) / 2);
- y = DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y - (icon_rect.y1 - icon_rect.y0);
-
- find_empty_location (container,
- grid,
- icon,
- x, y,
- &x, &y);
-
- icon_set_position (icon, x, y);
- icon->saved_ltr_x = x;
- placement_grid_mark_icon (grid, icon);
- }
-
- placement_grid_free (grid);
- }
-
- g_list_free (placed_icons);
- g_list_free (unplaced_icons);
- } else {
- /* There are no placed icons. Just lay them down using our rules */
- x = DESKTOP_PAD_HORIZONTAL;
-
- while (icons != NULL) {
- int center_x;
- int baseline;
- int icon_height_for_bound_check;
- gboolean should_snap;
-
- should_snap = container->details->keep_aligned;
-
- y = DESKTOP_PAD_VERTICAL;
-
- max_width = 0;
-
- /* Calculate max width for column */
- for (p = icons; p != NULL; p = p->next) {
- icon = p->data;
-
- icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
- BOUNDS_USAGE_FOR_LAYOUT);
- icon_width = x2 - x1;
- icon_height = y2 - y1;
-
- icon_get_bounding_box (icon, NULL, &y1, NULL, &y2,
- BOUNDS_USAGE_FOR_ENTIRE_ITEM);
- icon_height_for_bound_check = y2 - y1;
-
- if (should_snap) {
- /* Snap the baseline to a grid position */
- icon_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
- baseline = y + (icon_rect.y1 - icon_rect.y0);
- baseline = SNAP_CEIL_VERTICAL (baseline);
- y = baseline - (icon_rect.y1 - icon_rect.y0);
- }
-
- /* Check and see if we need to move to a new column */
- if (y != DESKTOP_PAD_VERTICAL && y + icon_height_for_bound_check > height) {
- break;
- }
-
- if (max_width < icon_width) {
- max_width = icon_width;
- }
-
- y += icon_height + DESKTOP_PAD_VERTICAL;
- }
-
- y = DESKTOP_PAD_VERTICAL;
-
- center_x = x + max_width / 2;
- column_width = max_width;
- if (should_snap) {
- /* Find the grid column to center on */
- center_x = SNAP_CEIL_HORIZONTAL (center_x);
- column_width = (center_x - x) + (max_width / 2);
- }
-
- /* Lay out column */
- for (p = icons; p != NULL; p = p->next) {
- icon = p->data;
- icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
- BOUNDS_USAGE_FOR_LAYOUT);
- icon_height = y2 - y1;
-
- icon_get_bounding_box (icon, NULL, &y1, NULL, &y2,
- BOUNDS_USAGE_FOR_ENTIRE_ITEM);
- icon_height_for_bound_check = y2 - y1;
-
- icon_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
-
- if (should_snap) {
- baseline = y + (icon_rect.y1 - icon_rect.y0);
- baseline = SNAP_CEIL_VERTICAL (baseline);
- y = baseline - (icon_rect.y1 - icon_rect.y0);
- }
-
- /* Check and see if we need to move to a new column */
- if (y != DESKTOP_PAD_VERTICAL && y > height - icon_height_for_bound_check &&
- /* Make sure we lay out at least one icon per column, to make progress */
- p != icons) {
- x += column_width + DESKTOP_PAD_HORIZONTAL;
- break;
- }
-
- icon_set_position (icon,
- center_x - (icon_rect.x1 - icon_rect.x0) / 2,
- y);
-
- icon->saved_ltr_x = icon->x;
- y += icon_height + DESKTOP_PAD_VERTICAL;
- }
- icons = p;
- }
- }
-
- /* These modes are special. We freeze all of our positions
- * after we do the layout.
- */
- /* FIXME bugzilla.gnome.org 42478:
- * This should not be tied to the direction of layout.
- * It should be a separate switch.
- */
- nautilus_canvas_container_freeze_icon_positions (container);
+lay_down_icons_vertical_desktop (NautilusCanvasContainer *container,
+ GList *icons)
+{
+ GList *p, *placed_icons, *unplaced_icons;
+ int total, new_length, placed;
+ NautilusCanvasIcon *icon;
+ int height, max_width, column_width, icon_width, icon_height;
+ int x, y, x1, x2, y1, y2;
+ EelDRect icon_rect;
+ GtkAllocation allocation;
+
+ /* Get container dimensions */
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ height = CANVAS_HEIGHT (container, allocation);
+
+ /* Determine which icons have and have not been placed */
+ placed_icons = NULL;
+ unplaced_icons = NULL;
+
+ total = g_list_length (container->details->icons);
+ new_length = g_list_length (icons);
+ placed = total - new_length;
+ if (placed > 0)
+ {
+ PlacementGrid *grid;
+ /* Add only placed icons in list */
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (icon_is_positioned (icon))
+ {
+ icon_set_position (icon, icon->saved_ltr_x, icon->y);
+ placed_icons = g_list_prepend (placed_icons, icon);
+ }
+ else
+ {
+ icon->x = 0;
+ icon->y = 0;
+ unplaced_icons = g_list_prepend (unplaced_icons, icon);
+ }
+ }
+ placed_icons = g_list_reverse (placed_icons);
+ unplaced_icons = g_list_reverse (unplaced_icons);
+
+ grid = placement_grid_new (container, FALSE);
+
+ if (grid)
+ {
+ for (p = placed_icons; p != NULL; p = p->next)
+ {
+ placement_grid_mark_icon
+ (grid, (NautilusCanvasIcon *) p->data);
+ }
+
+ /* Place unplaced icons in the best locations */
+ for (p = unplaced_icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ icon_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
+
+ /* Start the icon in the first column */
+ x = DESKTOP_PAD_HORIZONTAL + (SNAP_SIZE_X / 2) - ((icon_rect.x1 - icon_rect.x0) / 2);
+ y = DESKTOP_PAD_VERTICAL + SNAP_SIZE_Y - (icon_rect.y1 - icon_rect.y0);
+
+ find_empty_location (container,
+ grid,
+ icon,
+ x, y,
+ &x, &y);
+
+ icon_set_position (icon, x, y);
+ icon->saved_ltr_x = x;
+ placement_grid_mark_icon (grid, icon);
+ }
+
+ placement_grid_free (grid);
+ }
+
+ g_list_free (placed_icons);
+ g_list_free (unplaced_icons);
+ }
+ else
+ {
+ /* There are no placed icons. Just lay them down using our rules */
+ x = DESKTOP_PAD_HORIZONTAL;
+
+ while (icons != NULL)
+ {
+ int center_x;
+ int baseline;
+ int icon_height_for_bound_check;
+ gboolean should_snap;
+
+ should_snap = container->details->keep_aligned;
+
+ y = DESKTOP_PAD_VERTICAL;
+
+ max_width = 0;
+
+ /* Calculate max width for column */
+ for (p = icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
+ BOUNDS_USAGE_FOR_LAYOUT);
+ icon_width = x2 - x1;
+ icon_height = y2 - y1;
+
+ icon_get_bounding_box (icon, NULL, &y1, NULL, &y2,
+ BOUNDS_USAGE_FOR_ENTIRE_ITEM);
+ icon_height_for_bound_check = y2 - y1;
+
+ if (should_snap)
+ {
+ /* Snap the baseline to a grid position */
+ icon_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
+ baseline = y + (icon_rect.y1 - icon_rect.y0);
+ baseline = SNAP_CEIL_VERTICAL (baseline);
+ y = baseline - (icon_rect.y1 - icon_rect.y0);
+ }
+
+ /* Check and see if we need to move to a new column */
+ if (y != DESKTOP_PAD_VERTICAL && y + icon_height_for_bound_check > height)
+ {
+ break;
+ }
+
+ if (max_width < icon_width)
+ {
+ max_width = icon_width;
+ }
+
+ y += icon_height + DESKTOP_PAD_VERTICAL;
+ }
+
+ y = DESKTOP_PAD_VERTICAL;
+
+ center_x = x + max_width / 2;
+ column_width = max_width;
+ if (should_snap)
+ {
+ /* Find the grid column to center on */
+ center_x = SNAP_CEIL_HORIZONTAL (center_x);
+ column_width = (center_x - x) + (max_width / 2);
+ }
+
+ /* Lay out column */
+ for (p = icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ icon_get_bounding_box (icon, &x1, &y1, &x2, &y2,
+ BOUNDS_USAGE_FOR_LAYOUT);
+ icon_height = y2 - y1;
+
+ icon_get_bounding_box (icon, NULL, &y1, NULL, &y2,
+ BOUNDS_USAGE_FOR_ENTIRE_ITEM);
+ icon_height_for_bound_check = y2 - y1;
+
+ icon_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
+
+ if (should_snap)
+ {
+ baseline = y + (icon_rect.y1 - icon_rect.y0);
+ baseline = SNAP_CEIL_VERTICAL (baseline);
+ y = baseline - (icon_rect.y1 - icon_rect.y0);
+ }
+
+ /* Check and see if we need to move to a new column */
+ if (y != DESKTOP_PAD_VERTICAL && y > height - icon_height_for_bound_check &&
+ /* Make sure we lay out at least one icon per column, to make progress */
+ p != icons)
+ {
+ x += column_width + DESKTOP_PAD_HORIZONTAL;
+ break;
+ }
+
+ icon_set_position (icon,
+ center_x - (icon_rect.x1 - icon_rect.x0) / 2,
+ y);
+
+ icon->saved_ltr_x = icon->x;
+ y += icon_height + DESKTOP_PAD_VERTICAL;
+ }
+ icons = p;
+ }
+ }
+
+ /* These modes are special. We freeze all of our positions
+ * after we do the layout.
+ */
+ /* FIXME bugzilla.gnome.org 42478:
+ * This should not be tied to the direction of layout.
+ * It should be a separate switch.
+ */
+ nautilus_canvas_container_freeze_icon_positions (container);
}
static void
-lay_down_icons (NautilusCanvasContainer *container, GList *icons, double start_y)
+lay_down_icons (NautilusCanvasContainer *container,
+ GList *icons,
+ double start_y)
{
- if (container->details->is_desktop) {
- lay_down_icons_vertical_desktop (container, icons);
- } else {
- lay_down_icons_horizontal (container, icons, start_y);
- }
+ if (container->details->is_desktop)
+ {
+ lay_down_icons_vertical_desktop (container, icons);
+ }
+ else
+ {
+ lay_down_icons_horizontal (container, icons, start_y);
+ }
}
static void
redo_layout_internal (NautilusCanvasContainer *container)
{
- gboolean layout_possible;
-
- layout_possible = finish_adding_new_icons (container);
- if (!layout_possible) {
- schedule_redo_layout (container);
- return;
+ gboolean layout_possible;
+
+ layout_possible = finish_adding_new_icons (container);
+ if (!layout_possible)
+ {
+ schedule_redo_layout (container);
+ return;
+ }
+
+ /* Don't do any re-laying-out during stretching. Later we
+ * might add smart logic that does this and leaves room for
+ * the stretched icon, but if we do it we want it to be fast
+ * and only re-lay-out when it's really needed.
+ */
+ if (container->details->auto_layout
+ && container->details->drag_state != DRAG_STATE_STRETCH)
+ {
+ if (container->details->needs_resort)
+ {
+ resort (container);
+ container->details->needs_resort = FALSE;
}
+ lay_down_icons (container, container->details->icons, 0);
+ }
- /* Don't do any re-laying-out during stretching. Later we
- * might add smart logic that does this and leaves room for
- * the stretched icon, but if we do it we want it to be fast
- * and only re-lay-out when it's really needed.
- */
- if (container->details->auto_layout
- && container->details->drag_state != DRAG_STATE_STRETCH) {
- if (container->details->needs_resort) {
- resort (container);
- container->details->needs_resort = FALSE;
- }
- lay_down_icons (container, container->details->icons, 0);
- }
-
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- nautilus_canvas_container_set_rtl_positions (container);
- }
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ nautilus_canvas_container_set_rtl_positions (container);
+ }
- nautilus_canvas_container_update_scroll_region (container);
+ nautilus_canvas_container_update_scroll_region (container);
- process_pending_icon_to_reveal (container);
- nautilus_canvas_container_update_visible_icons (container);
+ process_pending_icon_to_reveal (container);
+ nautilus_canvas_container_update_visible_icons (container);
}
static gboolean
redo_layout_callback (gpointer callback_data)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (callback_data);
- redo_layout_internal (container);
- container->details->idle_id = 0;
+ container = NAUTILUS_CANVAS_CONTAINER (callback_data);
+ redo_layout_internal (container);
+ container->details->idle_id = 0;
- return FALSE;
+ return FALSE;
}
static void
unschedule_redo_layout (NautilusCanvasContainer *container)
{
- if (container->details->idle_id != 0) {
- g_source_remove (container->details->idle_id);
- container->details->idle_id = 0;
- }
+ if (container->details->idle_id != 0)
+ {
+ g_source_remove (container->details->idle_id);
+ container->details->idle_id = 0;
+ }
}
static void
schedule_redo_layout (NautilusCanvasContainer *container)
{
- if (container->details->idle_id == 0
- && container->details->has_been_allocated) {
- container->details->idle_id = g_idle_add
- (redo_layout_callback, container);
- }
+ if (container->details->idle_id == 0
+ && container->details->has_been_allocated)
+ {
+ container->details->idle_id = g_idle_add
+ (redo_layout_callback, container);
+ }
}
static void
redo_layout (NautilusCanvasContainer *container)
{
- unschedule_redo_layout (container);
- redo_layout_internal (container);
+ unschedule_redo_layout (container);
+ redo_layout_internal (container);
}
static void
reload_icon_positions (NautilusCanvasContainer *container)
{
- GList *p, *no_position_icons;
- NautilusCanvasIcon *icon;
- gboolean have_stored_position;
- NautilusCanvasPosition position;
- EelDRect bounds;
- double bottom;
- EelCanvasItem *item;
-
- g_assert (!container->details->auto_layout);
-
- resort (container);
-
- no_position_icons = NULL;
-
- /* Place all the icons with positions. */
- bottom = 0;
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- have_stored_position = FALSE;
- g_signal_emit (container,
- signals[GET_STORED_ICON_POSITION], 0,
- icon->data,
- &position,
- &have_stored_position);
- if (have_stored_position) {
- icon_set_position (icon, position.x, position.y);
- item = EEL_CANVAS_ITEM (icon->item);
- nautilus_canvas_item_get_bounds_for_layout (icon->item,
- &bounds.x0,
- &bounds.y0,
- &bounds.x1,
- &bounds.y1);
- eel_canvas_item_i2w (item->parent,
- &bounds.x0,
- &bounds.y0);
- eel_canvas_item_i2w (item->parent,
- &bounds.x1,
- &bounds.y1);
- if (bounds.y1 > bottom) {
- bottom = bounds.y1;
- }
- } else {
- no_position_icons = g_list_prepend (no_position_icons, icon);
- }
- }
- no_position_icons = g_list_reverse (no_position_icons);
-
- /* Place all the other icons. */
- lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
- g_list_free (no_position_icons);
+ GList *p, *no_position_icons;
+ NautilusCanvasIcon *icon;
+ gboolean have_stored_position;
+ NautilusCanvasPosition position;
+ EelDRect bounds;
+ double bottom;
+ EelCanvasItem *item;
+
+ g_assert (!container->details->auto_layout);
+
+ resort (container);
+
+ no_position_icons = NULL;
+
+ /* Place all the icons with positions. */
+ bottom = 0;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ have_stored_position = FALSE;
+ g_signal_emit (container,
+ signals[GET_STORED_ICON_POSITION], 0,
+ icon->data,
+ &position,
+ &have_stored_position);
+ if (have_stored_position)
+ {
+ icon_set_position (icon, position.x, position.y);
+ item = EEL_CANVAS_ITEM (icon->item);
+ nautilus_canvas_item_get_bounds_for_layout (icon->item,
+ &bounds.x0,
+ &bounds.y0,
+ &bounds.x1,
+ &bounds.y1);
+ eel_canvas_item_i2w (item->parent,
+ &bounds.x0,
+ &bounds.y0);
+ eel_canvas_item_i2w (item->parent,
+ &bounds.x1,
+ &bounds.y1);
+ if (bounds.y1 > bottom)
+ {
+ bottom = bounds.y1;
+ }
+ }
+ else
+ {
+ no_position_icons = g_list_prepend (no_position_icons, icon);
+ }
+ }
+ no_position_icons = g_list_reverse (no_position_icons);
+
+ /* Place all the other icons. */
+ lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
+ g_list_free (no_position_icons);
}
/* Container-level icon handling functions. */
@@ -2046,1731 +2275,1932 @@ reload_icon_positions (NautilusCanvasContainer *container)
static gboolean
button_event_modifies_selection (GdkEventButton *event)
{
- return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
+ return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
}
/* invalidate the cached label sizes for all the icons */
static void
invalidate_label_sizes (NautilusCanvasContainer *container)
{
- GList *p;
- NautilusCanvasIcon *icon;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
+ GList *p;
+ NautilusCanvasIcon *icon;
+
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
- nautilus_canvas_item_invalidate_label_size (icon->item);
- }
+ nautilus_canvas_item_invalidate_label_size (icon->item);
+ }
}
static gboolean
select_range (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon1,
- NautilusCanvasIcon *icon2,
- gboolean unselect_outside_range)
-{
- gboolean selection_changed;
- GList *p;
- NautilusCanvasIcon *icon;
- NautilusCanvasIcon *unmatched_icon;
- gboolean select;
-
- selection_changed = FALSE;
-
- unmatched_icon = NULL;
- select = FALSE;
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- if (unmatched_icon == NULL) {
- if (icon == icon1) {
- unmatched_icon = icon2;
- select = TRUE;
- } else if (icon == icon2) {
- unmatched_icon = icon1;
- select = TRUE;
- }
- }
-
- if (select || unselect_outside_range) {
- selection_changed |= icon_set_selected
- (container, icon, select);
- }
-
- if (unmatched_icon != NULL && icon == unmatched_icon) {
- select = FALSE;
- }
-
- }
- return selection_changed;
+ NautilusCanvasIcon *icon1,
+ NautilusCanvasIcon *icon2,
+ gboolean unselect_outside_range)
+{
+ gboolean selection_changed;
+ GList *p;
+ NautilusCanvasIcon *icon;
+ NautilusCanvasIcon *unmatched_icon;
+ gboolean select;
+
+ selection_changed = FALSE;
+
+ unmatched_icon = NULL;
+ select = FALSE;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ if (unmatched_icon == NULL)
+ {
+ if (icon == icon1)
+ {
+ unmatched_icon = icon2;
+ select = TRUE;
+ }
+ else if (icon == icon2)
+ {
+ unmatched_icon = icon1;
+ select = TRUE;
+ }
+ }
+
+ if (select || unselect_outside_range)
+ {
+ selection_changed |= icon_set_selected
+ (container, icon, select);
+ }
+
+ if (unmatched_icon != NULL && icon == unmatched_icon)
+ {
+ select = FALSE;
+ }
+ }
+ return selection_changed;
}
static gboolean
select_one_unselect_others (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_to_select)
+ NautilusCanvasIcon *icon_to_select)
{
- gboolean selection_changed;
- GList *p;
- NautilusCanvasIcon *icon;
+ gboolean selection_changed;
+ GList *p;
+ NautilusCanvasIcon *icon;
+
+ selection_changed = FALSE;
- selection_changed = FALSE;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
- selection_changed |= icon_set_selected
- (container, icon, icon == icon_to_select);
- }
-
- if (selection_changed && icon_to_select != NULL) {
- reveal_icon (container, icon_to_select);
- }
- return selection_changed;
+ selection_changed |= icon_set_selected
+ (container, icon, icon == icon_to_select);
+ }
+
+ if (selection_changed && icon_to_select != NULL)
+ {
+ reveal_icon (container, icon_to_select);
+ }
+ return selection_changed;
}
static gboolean
unselect_all (NautilusCanvasContainer *container)
{
- return select_one_unselect_others (container, NULL);
+ return select_one_unselect_others (container, NULL);
}
void
nautilus_canvas_container_move_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- int x, int y,
- double scale,
- gboolean raise,
- gboolean snap,
- gboolean update_position)
-{
- NautilusCanvasContainerDetails *details;
- gboolean emit_signal;
- NautilusCanvasPosition position;
-
- details = container->details;
-
- emit_signal = FALSE;
-
- if (scale != icon->scale) {
- icon->scale = scale;
- nautilus_canvas_container_update_icon (container, icon);
- if (update_position) {
- redo_layout (container);
- emit_signal = TRUE;
- }
- }
-
- if (!details->auto_layout) {
- if (details->keep_aligned && snap) {
- snap_position (container, icon, &x, &y);
- }
-
- if (x != icon->x || y != icon->y) {
- icon_set_position (icon, x, y);
- emit_signal = update_position;
- }
-
- icon->saved_ltr_x = nautilus_canvas_container_is_layout_rtl (container) ? get_mirror_x_position (container, icon, icon->x) : icon->x;
- }
-
- if (emit_signal) {
- position.x = icon->saved_ltr_x;
- position.y = icon->y;
- position.scale = scale;
- g_signal_emit (container,
- signals[ICON_POSITION_CHANGED], 0,
- icon->data, &position);
- }
-
- if (raise) {
- icon_raise (icon);
- }
-
- /* FIXME bugzilla.gnome.org 42474:
- * Handling of the scroll region is inconsistent here. In
- * the scale-changing case, redo_layout is called, which updates the
- * scroll region appropriately. In other cases, it's up to the
- * caller to make sure the scroll region is updated. This could
- * lead to hard-to-track-down bugs.
- */
+ NautilusCanvasIcon *icon,
+ int x,
+ int y,
+ double scale,
+ gboolean raise,
+ gboolean snap,
+ gboolean update_position)
+{
+ NautilusCanvasContainerDetails *details;
+ gboolean emit_signal;
+ NautilusCanvasPosition position;
+
+ details = container->details;
+
+ emit_signal = FALSE;
+
+ if (scale != icon->scale)
+ {
+ icon->scale = scale;
+ nautilus_canvas_container_update_icon (container, icon);
+ if (update_position)
+ {
+ redo_layout (container);
+ emit_signal = TRUE;
+ }
+ }
+
+ if (!details->auto_layout)
+ {
+ if (details->keep_aligned && snap)
+ {
+ snap_position (container, icon, &x, &y);
+ }
+
+ if (x != icon->x || y != icon->y)
+ {
+ icon_set_position (icon, x, y);
+ emit_signal = update_position;
+ }
+
+ icon->saved_ltr_x = nautilus_canvas_container_is_layout_rtl (container) ? get_mirror_x_position (container, icon, icon->x) : icon->x;
+ }
+
+ if (emit_signal)
+ {
+ position.x = icon->saved_ltr_x;
+ position.y = icon->y;
+ position.scale = scale;
+ g_signal_emit (container,
+ signals[ICON_POSITION_CHANGED], 0,
+ icon->data, &position);
+ }
+
+ if (raise)
+ {
+ icon_raise (icon);
+ }
+
+ /* FIXME bugzilla.gnome.org 42474:
+ * Handling of the scroll region is inconsistent here. In
+ * the scale-changing case, redo_layout is called, which updates the
+ * scroll region appropriately. In other cases, it's up to the
+ * caller to make sure the scroll region is updated. This could
+ * lead to hard-to-track-down bugs.
+ */
}
/* Implementation of rubberband selection. */
static void
rubberband_select (NautilusCanvasContainer *container,
- const EelDRect *current_rect)
-{
- GList *p;
- gboolean selection_changed, is_in, canvas_rect_calculated;
- NautilusCanvasIcon *icon;
- EelIRect canvas_rect;
- EelCanvas *canvas;
-
- selection_changed = FALSE;
- canvas_rect_calculated = FALSE;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- if (!canvas_rect_calculated) {
- /* Only do this calculation once, since all the canvas items
- * we are interating are in the same coordinate space
- */
- canvas = EEL_CANVAS_ITEM (icon->item)->canvas;
- eel_canvas_w2c (canvas,
- current_rect->x0,
- current_rect->y0,
- &canvas_rect.x0,
- &canvas_rect.y0);
- eel_canvas_w2c (canvas,
- current_rect->x1,
- current_rect->y1,
- &canvas_rect.x1,
- &canvas_rect.y1);
- canvas_rect_calculated = TRUE;
- }
-
- is_in = nautilus_canvas_item_hit_test_rectangle (icon->item, canvas_rect);
-
- selection_changed |= icon_set_selected
- (container, icon,
- is_in ^ icon->was_selected_before_rubberband);
- }
-
- if (selection_changed) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
+ const EelDRect *current_rect)
+{
+ GList *p;
+ gboolean selection_changed, is_in, canvas_rect_calculated;
+ NautilusCanvasIcon *icon;
+ EelIRect canvas_rect;
+ EelCanvas *canvas;
+
+ selection_changed = FALSE;
+ canvas_rect_calculated = FALSE;
+
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ if (!canvas_rect_calculated)
+ {
+ /* Only do this calculation once, since all the canvas items
+ * we are interating are in the same coordinate space
+ */
+ canvas = EEL_CANVAS_ITEM (icon->item)->canvas;
+ eel_canvas_w2c (canvas,
+ current_rect->x0,
+ current_rect->y0,
+ &canvas_rect.x0,
+ &canvas_rect.y0);
+ eel_canvas_w2c (canvas,
+ current_rect->x1,
+ current_rect->y1,
+ &canvas_rect.x1,
+ &canvas_rect.y1);
+ canvas_rect_calculated = TRUE;
+ }
+
+ is_in = nautilus_canvas_item_hit_test_rectangle (icon->item, canvas_rect);
+
+ selection_changed |= icon_set_selected
+ (container, icon,
+ is_in ^ icon->was_selected_before_rubberband);
+ }
+
+ if (selection_changed)
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
}
static int
rubberband_timeout_callback (gpointer data)
{
- NautilusCanvasContainer *container;
- GtkWidget *widget;
- NautilusCanvasRubberbandInfo *band_info;
- int x, y;
- double x1, y1, x2, y2;
- double world_x, world_y;
- int x_scroll, y_scroll;
- int adj_x, adj_y;
- GdkDisplay *display;
- GdkSeat *seat;
- gboolean adj_changed;
- GtkAllocation allocation;
-
- EelDRect selection_rect;
-
- widget = GTK_WIDGET (data);
- container = NAUTILUS_CANVAS_CONTAINER (data);
- band_info = &container->details->rubberband_info;
-
- g_assert (band_info->timer_id != 0);
-
- adj_changed = FALSE;
- gtk_widget_get_allocation (widget, &allocation);
-
- adj_x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
- if (adj_x != band_info->last_adj_x) {
- band_info->last_adj_x = adj_x;
- adj_changed = TRUE;
- }
-
- adj_y = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
- if (adj_y != band_info->last_adj_y) {
- band_info->last_adj_y = adj_y;
- adj_changed = TRUE;
- }
-
- display = gtk_widget_get_display (widget);
- seat = gdk_display_get_default_seat (display);
-
- gdk_window_get_device_position (gtk_widget_get_window (widget),
- gdk_seat_get_pointer (seat),
- &x, &y, NULL);
-
- if (x < RUBBERBAND_SCROLL_THRESHOLD) {
- x_scroll = x - RUBBERBAND_SCROLL_THRESHOLD;
- x = 0;
- } else if (x >= allocation.width - RUBBERBAND_SCROLL_THRESHOLD) {
- x_scroll = x - allocation.width + RUBBERBAND_SCROLL_THRESHOLD + 1;
- x = allocation.width - 1;
- } else {
- x_scroll = 0;
- }
-
- if (y < RUBBERBAND_SCROLL_THRESHOLD) {
- y_scroll = y - RUBBERBAND_SCROLL_THRESHOLD;
- y = 0;
- } else if (y >= allocation.height - RUBBERBAND_SCROLL_THRESHOLD) {
- y_scroll = y - allocation.height + RUBBERBAND_SCROLL_THRESHOLD + 1;
- y = allocation.height - 1;
- } else {
- y_scroll = 0;
- }
-
- if (y_scroll == 0 && x_scroll == 0
- && (int) band_info->prev_x == x && (int) band_info->prev_y == y && !adj_changed) {
- return TRUE;
- }
-
- nautilus_canvas_container_scroll (container, x_scroll, y_scroll);
-
- /* Remember to convert from widget to scrolled window coords */
- eel_canvas_window_to_world (EEL_CANVAS (container),
- x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))),
- y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))),
- &world_x, &world_y);
-
- if (world_x < band_info->start_x) {
- x1 = world_x;
- x2 = band_info->start_x;
- } else {
- x1 = band_info->start_x;
- x2 = world_x;
- }
-
- if (world_y < band_info->start_y) {
- y1 = world_y;
- y2 = band_info->start_y;
- } else {
- y1 = band_info->start_y;
- y2 = world_y;
- }
-
- /* Don't let the area of the selection rectangle be empty.
- * Aside from the fact that it would be funny when the rectangle disappears,
- * this also works around a crash in libart that happens sometimes when a
- * zero height rectangle is passed.
- */
- x2 = MAX (x1 + 1, x2);
- y2 = MAX (y1 + 1, y2);
-
- eel_canvas_item_set
- (band_info->selection_rectangle,
- "x1", x1, "y1", y1,
- "x2", x2, "y2", y2,
- NULL);
-
- selection_rect.x0 = x1;
- selection_rect.y0 = y1;
- selection_rect.x1 = x2;
- selection_rect.y1 = y2;
-
- rubberband_select (container,
- &selection_rect);
-
- band_info->prev_x = x;
- band_info->prev_y = y;
-
- return TRUE;
+ NautilusCanvasContainer *container;
+ GtkWidget *widget;
+ NautilusCanvasRubberbandInfo *band_info;
+ int x, y;
+ double x1, y1, x2, y2;
+ double world_x, world_y;
+ int x_scroll, y_scroll;
+ int adj_x, adj_y;
+ GdkDisplay *display;
+ GdkSeat *seat;
+ gboolean adj_changed;
+ GtkAllocation allocation;
+
+ EelDRect selection_rect;
+
+ widget = GTK_WIDGET (data);
+ container = NAUTILUS_CANVAS_CONTAINER (data);
+ band_info = &container->details->rubberband_info;
+
+ g_assert (band_info->timer_id != 0);
+
+ adj_changed = FALSE;
+ gtk_widget_get_allocation (widget, &allocation);
+
+ adj_x = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
+ if (adj_x != band_info->last_adj_x)
+ {
+ band_info->last_adj_x = adj_x;
+ adj_changed = TRUE;
+ }
+
+ adj_y = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
+ if (adj_y != band_info->last_adj_y)
+ {
+ band_info->last_adj_y = adj_y;
+ adj_changed = TRUE;
+ }
+
+ display = gtk_widget_get_display (widget);
+ seat = gdk_display_get_default_seat (display);
+
+ gdk_window_get_device_position (gtk_widget_get_window (widget),
+ gdk_seat_get_pointer (seat),
+ &x, &y, NULL);
+
+ if (x < RUBBERBAND_SCROLL_THRESHOLD)
+ {
+ x_scroll = x - RUBBERBAND_SCROLL_THRESHOLD;
+ x = 0;
+ }
+ else if (x >= allocation.width - RUBBERBAND_SCROLL_THRESHOLD)
+ {
+ x_scroll = x - allocation.width + RUBBERBAND_SCROLL_THRESHOLD + 1;
+ x = allocation.width - 1;
+ }
+ else
+ {
+ x_scroll = 0;
+ }
+
+ if (y < RUBBERBAND_SCROLL_THRESHOLD)
+ {
+ y_scroll = y - RUBBERBAND_SCROLL_THRESHOLD;
+ y = 0;
+ }
+ else if (y >= allocation.height - RUBBERBAND_SCROLL_THRESHOLD)
+ {
+ y_scroll = y - allocation.height + RUBBERBAND_SCROLL_THRESHOLD + 1;
+ y = allocation.height - 1;
+ }
+ else
+ {
+ y_scroll = 0;
+ }
+
+ if (y_scroll == 0 && x_scroll == 0
+ && (int) band_info->prev_x == x && (int) band_info->prev_y == y && !adj_changed)
+ {
+ return TRUE;
+ }
+
+ nautilus_canvas_container_scroll (container, x_scroll, y_scroll);
+
+ /* Remember to convert from widget to scrolled window coords */
+ eel_canvas_window_to_world (EEL_CANVAS (container),
+ x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))),
+ y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))),
+ &world_x, &world_y);
+
+ if (world_x < band_info->start_x)
+ {
+ x1 = world_x;
+ x2 = band_info->start_x;
+ }
+ else
+ {
+ x1 = band_info->start_x;
+ x2 = world_x;
+ }
+
+ if (world_y < band_info->start_y)
+ {
+ y1 = world_y;
+ y2 = band_info->start_y;
+ }
+ else
+ {
+ y1 = band_info->start_y;
+ y2 = world_y;
+ }
+
+ /* Don't let the area of the selection rectangle be empty.
+ * Aside from the fact that it would be funny when the rectangle disappears,
+ * this also works around a crash in libart that happens sometimes when a
+ * zero height rectangle is passed.
+ */
+ x2 = MAX (x1 + 1, x2);
+ y2 = MAX (y1 + 1, y2);
+
+ eel_canvas_item_set
+ (band_info->selection_rectangle,
+ "x1", x1, "y1", y1,
+ "x2", x2, "y2", y2,
+ NULL);
+
+ selection_rect.x0 = x1;
+ selection_rect.y0 = y1;
+ selection_rect.x1 = x2;
+ selection_rect.y1 = y2;
+
+ rubberband_select (container,
+ &selection_rect);
+
+ band_info->prev_x = x;
+ band_info->prev_y = y;
+
+ return TRUE;
}
static void
get_rubber_color (NautilusCanvasContainer *container,
- GdkRGBA *bgcolor,
- GdkRGBA *bordercolor)
-{
- Atom real_type;
- gint result = -1;
- gint real_format;
- gulong items_read = 0;
- gulong items_left = 0;
- gchar *colors;
- Atom representative_colors_atom;
- Display *display;
-
- if (nautilus_canvas_container_get_is_desktop (container)) {
- representative_colors_atom = gdk_x11_get_xatom_by_name ("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS");
- display = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
-
- gdk_error_trap_push ();
- result = XGetWindowProperty (display,
- GDK_ROOT_WINDOW (),
- representative_colors_atom,
- 0L,
- G_MAXLONG,
- False,
- XA_STRING,
- &real_type,
- &real_format,
- &items_read,
- &items_left,
- (guchar **) &colors);
- gdk_error_trap_pop_ignored ();
- }
-
- if (result == Success && items_read) {
- /* by treating the result as a nul-terminated string, we
- * select the first colour in the list.
- */
- GdkRGBA read;
- gdouble shade;
-
- gdk_rgba_parse (&read, colors);
- XFree (colors);
-
- /* Border
- *
- * We shade darker colours to be slightly lighter and
- * lighter ones to be slightly darker.
- */
- shade = read.green < 0.5 ? 1.1 : 0.9;
- bordercolor->red = read.red * shade;
- bordercolor->green = read.green * shade;
- bordercolor->blue = read.blue * shade;
- bordercolor->alpha = 1.0;
-
- /* Background */
- *bgcolor = read;
- bgcolor->alpha = 0.6;
- } else {
- /* Fallback to the style context if we can't get the Atom */
- GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (GTK_WIDGET (container));
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
-
- gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, bgcolor);
- gtk_style_context_get_border_color (context, GTK_STATE_FLAG_NORMAL, bordercolor);
-
- gtk_style_context_restore (context);
- }
+ GdkRGBA *bgcolor,
+ GdkRGBA *bordercolor)
+{
+ Atom real_type;
+ gint result = -1;
+ gint real_format;
+ gulong items_read = 0;
+ gulong items_left = 0;
+ gchar *colors;
+ Atom representative_colors_atom;
+ Display *display;
+
+ if (nautilus_canvas_container_get_is_desktop (container))
+ {
+ representative_colors_atom = gdk_x11_get_xatom_by_name ("_GNOME_BACKGROUND_REPRESENTATIVE_COLORS");
+ display = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
+
+ gdk_error_trap_push ();
+ result = XGetWindowProperty (display,
+ GDK_ROOT_WINDOW (),
+ representative_colors_atom,
+ 0L,
+ G_MAXLONG,
+ False,
+ XA_STRING,
+ &real_type,
+ &real_format,
+ &items_read,
+ &items_left,
+ (guchar **) &colors);
+ gdk_error_trap_pop_ignored ();
+ }
+
+ if (result == Success && items_read)
+ {
+ /* by treating the result as a nul-terminated string, we
+ * select the first colour in the list.
+ */
+ GdkRGBA read;
+ gdouble shade;
+
+ gdk_rgba_parse (&read, colors);
+ XFree (colors);
+
+ /* Border
+ *
+ * We shade darker colours to be slightly lighter and
+ * lighter ones to be slightly darker.
+ */
+ shade = read.green < 0.5 ? 1.1 : 0.9;
+ bordercolor->red = read.red * shade;
+ bordercolor->green = read.green * shade;
+ bordercolor->blue = read.blue * shade;
+ bordercolor->alpha = 1.0;
+
+ /* Background */
+ *bgcolor = read;
+ bgcolor->alpha = 0.6;
+ }
+ else
+ {
+ /* Fallback to the style context if we can't get the Atom */
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (container));
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_RUBBERBAND);
+
+ gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, bgcolor);
+ gtk_style_context_get_border_color (context, GTK_STATE_FLAG_NORMAL, bordercolor);
+
+ gtk_style_context_restore (context);
+ }
}
static void
start_rubberbanding (NautilusCanvasContainer *container,
- GdkEventButton *event)
-{
- AtkObject *accessible;
- NautilusCanvasContainerDetails *details;
- NautilusCanvasRubberbandInfo *band_info;
- GdkRGBA bg_color, border_color;
- GList *p;
- NautilusCanvasIcon *icon;
-
- details = container->details;
- band_info = &details->rubberband_info;
-
- g_signal_emit (container,
- signals[BAND_SELECT_STARTED], 0);
-
- for (p = details->icons; p != NULL; p = p->next) {
- icon = p->data;
- icon->was_selected_before_rubberband = icon->is_selected;
- }
-
- eel_canvas_window_to_world
- (EEL_CANVAS (container), event->x, event->y,
- &band_info->start_x, &band_info->start_y);
-
- get_rubber_color (container, &bg_color, &border_color);
-
- band_info->selection_rectangle = eel_canvas_item_new
- (eel_canvas_root
- (EEL_CANVAS (container)),
- NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
- "x1", band_info->start_x,
- "y1", band_info->start_y,
- "x2", band_info->start_x,
- "y2", band_info->start_y,
- "fill_color_rgba", &bg_color,
- "outline_color_rgba", &border_color,
- "width_pixels", 1,
- NULL);
-
- accessible = atk_gobject_accessible_for_object
- (G_OBJECT (band_info->selection_rectangle));
- atk_object_set_name (accessible, "selection");
- atk_object_set_description (accessible, _("The selection rectangle"));
-
- band_info->prev_x = event->x - gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
- band_info->prev_y = event->y - gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
-
- band_info->active = TRUE;
-
- if (band_info->timer_id == 0) {
- band_info->timer_id = g_timeout_add
- (RUBBERBAND_TIMEOUT_INTERVAL,
- rubberband_timeout_callback,
- container);
- }
-
- eel_canvas_item_grab (band_info->selection_rectangle,
- (GDK_POINTER_MOTION_MASK
- | GDK_BUTTON_RELEASE_MASK
- | GDK_SCROLL_MASK),
- NULL,
- (GdkEvent *)event);
+ GdkEventButton *event)
+{
+ AtkObject *accessible;
+ NautilusCanvasContainerDetails *details;
+ NautilusCanvasRubberbandInfo *band_info;
+ GdkRGBA bg_color, border_color;
+ GList *p;
+ NautilusCanvasIcon *icon;
+
+ details = container->details;
+ band_info = &details->rubberband_info;
+
+ g_signal_emit (container,
+ signals[BAND_SELECT_STARTED], 0);
+
+ for (p = details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ icon->was_selected_before_rubberband = icon->is_selected;
+ }
+
+ eel_canvas_window_to_world
+ (EEL_CANVAS (container), event->x, event->y,
+ &band_info->start_x, &band_info->start_y);
+
+ get_rubber_color (container, &bg_color, &border_color);
+
+ band_info->selection_rectangle = eel_canvas_item_new
+ (eel_canvas_root
+ (EEL_CANVAS (container)),
+ NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
+ "x1", band_info->start_x,
+ "y1", band_info->start_y,
+ "x2", band_info->start_x,
+ "y2", band_info->start_y,
+ "fill_color_rgba", &bg_color,
+ "outline_color_rgba", &border_color,
+ "width_pixels", 1,
+ NULL);
+
+ accessible = atk_gobject_accessible_for_object
+ (G_OBJECT (band_info->selection_rectangle));
+ atk_object_set_name (accessible, "selection");
+ atk_object_set_description (accessible, _("The selection rectangle"));
+
+ band_info->prev_x = event->x - gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
+ band_info->prev_y = event->y - gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
+
+ band_info->active = TRUE;
+
+ if (band_info->timer_id == 0)
+ {
+ band_info->timer_id = g_timeout_add
+ (RUBBERBAND_TIMEOUT_INTERVAL,
+ rubberband_timeout_callback,
+ container);
+ }
+
+ eel_canvas_item_grab (band_info->selection_rectangle,
+ (GDK_POINTER_MOTION_MASK
+ | GDK_BUTTON_RELEASE_MASK
+ | GDK_SCROLL_MASK),
+ NULL,
+ (GdkEvent *) event);
}
static void
stop_rubberbanding (NautilusCanvasContainer *container)
{
- NautilusCanvasRubberbandInfo *band_info;
- GList *icons;
- gboolean enable_animation;
+ NautilusCanvasRubberbandInfo *band_info;
+ GList *icons;
+ gboolean enable_animation;
- band_info = &container->details->rubberband_info;
+ band_info = &container->details->rubberband_info;
- g_assert (band_info->timer_id != 0);
- g_source_remove (band_info->timer_id);
- band_info->timer_id = 0;
+ g_assert (band_info->timer_id != 0);
+ g_source_remove (band_info->timer_id);
+ band_info->timer_id = 0;
- band_info->active = FALSE;
+ band_info->active = FALSE;
- g_object_get (gtk_settings_get_default (), "gtk-enable-animations", &enable_animation, NULL);
+ g_object_get (gtk_settings_get_default (), "gtk-enable-animations", &enable_animation, NULL);
- /* Destroy this canvas item; the parent will unref it. */
- eel_canvas_item_ungrab (band_info->selection_rectangle);
- eel_canvas_item_lower_to_bottom (band_info->selection_rectangle);
- if (enable_animation) {
- nautilus_selection_canvas_item_fade_out (NAUTILUS_SELECTION_CANVAS_ITEM (band_info->selection_rectangle), 150);
- } else {
- eel_canvas_item_destroy (band_info->selection_rectangle);
- }
- band_info->selection_rectangle = NULL;
+ /* Destroy this canvas item; the parent will unref it. */
+ eel_canvas_item_ungrab (band_info->selection_rectangle);
+ eel_canvas_item_lower_to_bottom (band_info->selection_rectangle);
+ if (enable_animation)
+ {
+ nautilus_selection_canvas_item_fade_out (NAUTILUS_SELECTION_CANVAS_ITEM (band_info->selection_rectangle), 150);
+ }
+ else
+ {
+ eel_canvas_item_destroy (band_info->selection_rectangle);
+ }
+ band_info->selection_rectangle = NULL;
- /* if only one item has been selected, use it as range
- * selection base (cf. handle_icon_button_press) */
- icons = nautilus_canvas_container_get_selected_icons (container);
- if (g_list_length (icons) == 1) {
- container->details->range_selection_base_icon = icons->data;
- }
- g_list_free (icons);
+ /* if only one item has been selected, use it as range
+ * selection base (cf. handle_icon_button_press) */
+ icons = nautilus_canvas_container_get_selected_icons (container);
+ if (g_list_length (icons) == 1)
+ {
+ container->details->range_selection_base_icon = icons->data;
+ }
+ g_list_free (icons);
- g_signal_emit (container,
- signals[BAND_SELECT_ENDED], 0);
+ g_signal_emit (container,
+ signals[BAND_SELECT_ENDED], 0);
}
/* Keyboard navigation. */
-typedef gboolean (* IsBetterCanvasFunction) (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data);
+typedef gboolean (*IsBetterCanvasFunction) (NautilusCanvasContainer *container,
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data);
static NautilusCanvasIcon *
find_best_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- IsBetterCanvasFunction function,
- void *data)
-{
- GList *p;
- NautilusCanvasIcon *best, *candidate;
-
- best = NULL;
- for (p = container->details->icons; p != NULL; p = p->next) {
- candidate = p->data;
-
- if (candidate != start_icon) {
- if ((* function) (container, start_icon, best, candidate, data)) {
- best = candidate;
- }
- }
- }
- return best;
+ NautilusCanvasIcon *start_icon,
+ IsBetterCanvasFunction function,
+ void *data)
+{
+ GList *p;
+ NautilusCanvasIcon *best, *candidate;
+
+ best = NULL;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ candidate = p->data;
+
+ if (candidate != start_icon)
+ {
+ if ((*function)(container, start_icon, best, candidate, data))
+ {
+ best = candidate;
+ }
+ }
+ }
+ return best;
}
static NautilusCanvasIcon *
find_best_selected_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- IsBetterCanvasFunction function,
- void *data)
-{
- GList *p;
- NautilusCanvasIcon *best, *candidate;
-
- best = NULL;
- for (p = container->details->icons; p != NULL; p = p->next) {
- candidate = p->data;
-
- if (candidate != start_icon && candidate->is_selected) {
- if ((* function) (container, start_icon, best, candidate, data)) {
- best = candidate;
- }
- }
- }
- return best;
+ NautilusCanvasIcon *start_icon,
+ IsBetterCanvasFunction function,
+ void *data)
+{
+ GList *p;
+ NautilusCanvasIcon *best, *candidate;
+
+ best = NULL;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ candidate = p->data;
+
+ if (candidate != start_icon && candidate->is_selected)
+ {
+ if ((*function)(container, start_icon, best, candidate, data))
+ {
+ best = candidate;
+ }
+ }
+ }
+ return best;
}
static int
compare_icons_by_uri (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b)
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b)
{
- char *uri_a, *uri_b;
- int result;
+ char *uri_a, *uri_b;
+ int result;
+
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (icon_a != NULL);
+ g_assert (icon_b != NULL);
+ g_assert (icon_a != icon_b);
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (icon_a != NULL);
- g_assert (icon_b != NULL);
- g_assert (icon_a != icon_b);
+ uri_a = nautilus_canvas_container_get_icon_uri (container, icon_a);
+ uri_b = nautilus_canvas_container_get_icon_uri (container, icon_b);
+ result = strcmp (uri_a, uri_b);
+ g_assert (result != 0);
+ g_free (uri_a);
+ g_free (uri_b);
- uri_a = nautilus_canvas_container_get_icon_uri (container, icon_a);
- uri_b = nautilus_canvas_container_get_icon_uri (container, icon_b);
- result = strcmp (uri_a, uri_b);
- g_assert (result != 0);
- g_free (uri_a);
- g_free (uri_b);
-
- return result;
+ return result;
}
static int
get_cmp_point_x (NautilusCanvasContainer *container,
- EelDRect icon_rect)
+ EelDRect icon_rect)
{
- return (icon_rect.x0 + icon_rect.x1) / 2;
+ return (icon_rect.x0 + icon_rect.x1) / 2;
}
static int
get_cmp_point_y (NautilusCanvasContainer *container,
- EelDRect icon_rect)
+ EelDRect icon_rect)
{
- return icon_rect.y1;
+ return icon_rect.y1;
}
static int
compare_icons_horizontal (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b)
-{
- EelDRect world_rect;
- int ax, bx;
-
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &ax,
- NULL);
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &bx,
- NULL);
-
- if (ax < bx) {
- return -1;
- }
- if (ax > bx) {
- return +1;
- }
- return 0;
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b)
+{
+ EelDRect world_rect;
+ int ax, bx;
+
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &ax,
+ NULL);
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &bx,
+ NULL);
+
+ if (ax < bx)
+ {
+ return -1;
+ }
+ if (ax > bx)
+ {
+ return +1;
+ }
+ return 0;
}
static int
compare_icons_vertical (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b)
-{
- EelDRect world_rect;
- int ay, by;
-
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- NULL,
- &ay);
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- NULL,
- &by);
-
- if (ay < by) {
- return -1;
- }
- if (ay > by) {
- return +1;
- }
- return 0;
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b)
+{
+ EelDRect world_rect;
+ int ay, by;
+
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ NULL,
+ &ay);
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ NULL,
+ &by);
+
+ if (ay < by)
+ {
+ return -1;
+ }
+ if (ay > by)
+ {
+ return +1;
+ }
+ return 0;
}
static int
compare_icons_horizontal_first (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b)
-{
- EelDRect world_rect;
- int ax, ay, bx, by;
-
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &ax,
- &ay);
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &bx,
- &by);
-
- if (ax < bx) {
- return -1;
- }
- if (ax > bx) {
- return +1;
- }
- if (ay < by) {
- return -1;
- }
- if (ay > by) {
- return +1;
- }
- return compare_icons_by_uri (container, icon_a, icon_b);
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b)
+{
+ EelDRect world_rect;
+ int ax, ay, bx, by;
+
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &ax,
+ &ay);
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &bx,
+ &by);
+
+ if (ax < bx)
+ {
+ return -1;
+ }
+ if (ax > bx)
+ {
+ return +1;
+ }
+ if (ay < by)
+ {
+ return -1;
+ }
+ if (ay > by)
+ {
+ return +1;
+ }
+ return compare_icons_by_uri (container, icon_a, icon_b);
}
static int
compare_icons_vertical_first (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon_a,
- NautilusCanvasIcon *icon_b)
-{
- EelDRect world_rect;
- int ax, ay, bx, by;
-
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &ax,
- &ay);
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &bx,
- &by);
-
- if (ay < by) {
- return -1;
- }
- if (ay > by) {
- return +1;
- }
- if (ax < bx) {
- return -1;
- }
- if (ax > bx) {
- return +1;
- }
- return compare_icons_by_uri (container, icon_a, icon_b);
+ NautilusCanvasIcon *icon_a,
+ NautilusCanvasIcon *icon_b)
+{
+ EelDRect world_rect;
+ int ax, ay, bx, by;
+
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_a->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &ax,
+ &ay);
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon_b->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &bx,
+ &by);
+
+ if (ay < by)
+ {
+ return -1;
+ }
+ if (ay > by)
+ {
+ return +1;
+ }
+ if (ax < bx)
+ {
+ return -1;
+ }
+ if (ax > bx)
+ {
+ return +1;
+ }
+ return compare_icons_by_uri (container, icon_a, icon_b);
}
static gboolean
leftmost_in_top_row (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
{
- if (best_so_far == NULL) {
- return TRUE;
- }
- return compare_icons_vertical_first (container, best_so_far, candidate) > 0;
+ if (best_so_far == NULL)
+ {
+ return TRUE;
+ }
+ return compare_icons_vertical_first (container, best_so_far, candidate) > 0;
}
static gboolean
rightmost_in_top_row (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
{
- if (best_so_far == NULL) {
- return TRUE;
- }
- return compare_icons_vertical (container, best_so_far, candidate) > 0;
- return compare_icons_horizontal (container, best_so_far, candidate) < 0;
+ if (best_so_far == NULL)
+ {
+ return TRUE;
+ }
+ return compare_icons_vertical (container, best_so_far, candidate) > 0;
+ return compare_icons_horizontal (container, best_so_far, candidate) < 0;
}
static gboolean
rightmost_in_bottom_row (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
{
- if (best_so_far == NULL) {
- return TRUE;
- }
- return compare_icons_vertical_first (container, best_so_far, candidate) < 0;
+ if (best_so_far == NULL)
+ {
+ return TRUE;
+ }
+ return compare_icons_vertical_first (container, best_so_far, candidate) < 0;
}
static int
compare_with_start_row (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- EelCanvasItem *item;
+ EelCanvasItem *item;
- item = EEL_CANVAS_ITEM (icon->item);
-
- if (container->details->arrow_key_start_y < item->y1) {
- return -1;
- }
- if (container->details->arrow_key_start_y > item->y2) {
- return +1;
- }
- return 0;
+ item = EEL_CANVAS_ITEM (icon->item);
+
+ if (container->details->arrow_key_start_y < item->y1)
+ {
+ return -1;
+ }
+ if (container->details->arrow_key_start_y > item->y2)
+ {
+ return +1;
+ }
+ return 0;
}
static int
compare_with_start_column (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- EelCanvasItem *item;
+ EelCanvasItem *item;
+
+ item = EEL_CANVAS_ITEM (icon->item);
- item = EEL_CANVAS_ITEM (icon->item);
-
- if (container->details->arrow_key_start_x < item->x1) {
- return -1;
- }
- if (container->details->arrow_key_start_x > item->x2) {
- return +1;
- }
- return 0;
+ if (container->details->arrow_key_start_x < item->x1)
+ {
+ return -1;
+ }
+ if (container->details->arrow_key_start_x > item->x2)
+ {
+ return +1;
+ }
+ return 0;
}
static gboolean
same_row_right_side_leftmost (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* Candidates not on the start row do not qualify. */
- if (compare_with_start_row (container, candidate) != 0) {
- return FALSE;
- }
-
- /* Candidates that are farther right lose out. */
- if (best_so_far != NULL) {
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) < 0) {
- return FALSE;
- }
- }
-
- /* Candidate to the left of the start do not qualify. */
- if (compare_icons_horizontal_first (container,
- candidate,
- start_icon) <= 0) {
- return FALSE;
- }
-
- return TRUE;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* Candidates not on the start row do not qualify. */
+ if (compare_with_start_row (container, candidate) != 0)
+ {
+ return FALSE;
+ }
+
+ /* Candidates that are farther right lose out. */
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ return FALSE;
+ }
+ }
+
+ /* Candidate to the left of the start do not qualify. */
+ if (compare_icons_horizontal_first (container,
+ candidate,
+ start_icon) <= 0)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
same_row_left_side_rightmost (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* Candidates not on the start row do not qualify. */
- if (compare_with_start_row (container, candidate) != 0) {
- return FALSE;
- }
-
- /* Candidates that are farther left lose out. */
- if (best_so_far != NULL) {
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) > 0) {
- return FALSE;
- }
- }
-
- /* Candidate to the right of the start do not qualify. */
- if (compare_icons_horizontal_first (container,
- candidate,
- start_icon) >= 0) {
- return FALSE;
- }
-
- return TRUE;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* Candidates not on the start row do not qualify. */
+ if (compare_with_start_row (container, candidate) != 0)
+ {
+ return FALSE;
+ }
+
+ /* Candidates that are farther left lose out. */
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ return FALSE;
+ }
+ }
+
+ /* Candidate to the right of the start do not qualify. */
+ if (compare_icons_horizontal_first (container,
+ candidate,
+ start_icon) >= 0)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
next_row_leftmost (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not below the current row */
- if (compare_with_start_row (container, candidate) >= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) > 0) {
- /* candidate is above best choice, but below the current row */
- return TRUE;
- }
-
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) > 0) {
- return TRUE;
- }
- }
-
- return best_so_far == NULL;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not below the current row */
+ if (compare_with_start_row (container, candidate) >= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ /* candidate is above best choice, but below the current row */
+ return TRUE;
+ }
+
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return best_so_far == NULL;
}
static gboolean
next_row_rightmost (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not below the current row */
- if (compare_with_start_row (container, candidate) >= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) > 0) {
- /* candidate is above best choice, but below the current row */
- return TRUE;
- }
-
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) < 0) {
- return TRUE;
- }
- }
-
- return best_so_far == NULL;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not below the current row */
+ if (compare_with_start_row (container, candidate) >= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ /* candidate is above best choice, but below the current row */
+ return TRUE;
+ }
+
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return best_so_far == NULL;
}
static gboolean
next_column_bottommost (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not on the right of the current column */
- if (compare_with_start_column (container, candidate) >= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) > 0) {
- /* candidate is above best choice, but below the current row */
- return TRUE;
- }
-
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) < 0) {
- return TRUE;
- }
- }
-
- return best_so_far == NULL;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not on the right of the current column */
+ if (compare_with_start_column (container, candidate) >= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ /* candidate is above best choice, but below the current row */
+ return TRUE;
+ }
+
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return best_so_far == NULL;
}
static gboolean
previous_row_rightmost (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not above the current row */
- if (compare_with_start_row (container, candidate) <= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) < 0) {
- /* candidate is below the best choice, but above the current row */
- return TRUE;
- }
-
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) < 0) {
- return TRUE;
- }
- }
-
- return best_so_far == NULL;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not above the current row */
+ if (compare_with_start_row (container, candidate) <= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ /* candidate is below the best choice, but above the current row */
+ return TRUE;
+ }
+
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return best_so_far == NULL;
}
static gboolean
same_column_above_lowest (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* Candidates not on the start column do not qualify. */
- if (compare_with_start_column (container, candidate) != 0) {
- return FALSE;
- }
-
- /* Candidates that are higher lose out. */
- if (best_so_far != NULL) {
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) > 0) {
- return FALSE;
- }
- }
-
- /* Candidates below the start do not qualify. */
- if (compare_icons_vertical_first (container,
- candidate,
- start_icon) >= 0) {
- return FALSE;
- }
-
- return TRUE;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* Candidates not on the start column do not qualify. */
+ if (compare_with_start_column (container, candidate) != 0)
+ {
+ return FALSE;
+ }
+
+ /* Candidates that are higher lose out. */
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ return FALSE;
+ }
+ }
+
+ /* Candidates below the start do not qualify. */
+ if (compare_icons_vertical_first (container,
+ candidate,
+ start_icon) >= 0)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
same_column_below_highest (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* Candidates not on the start column do not qualify. */
- if (compare_with_start_column (container, candidate) != 0) {
- return FALSE;
- }
-
- /* Candidates that are lower lose out. */
- if (best_so_far != NULL) {
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) < 0) {
- return FALSE;
- }
- }
-
- /* Candidates above the start do not qualify. */
- if (compare_icons_vertical_first (container,
- candidate,
- start_icon) <= 0) {
- return FALSE;
- }
-
- return TRUE;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* Candidates not on the start column do not qualify. */
+ if (compare_with_start_column (container, candidate) != 0)
+ {
+ return FALSE;
+ }
+
+ /* Candidates that are lower lose out. */
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ return FALSE;
+ }
+ }
+
+ /* Candidates above the start do not qualify. */
+ if (compare_icons_vertical_first (container,
+ candidate,
+ start_icon) <= 0)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
previous_column_highest (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not before the current column */
- if (compare_with_start_column (container, candidate) <= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_horizontal (container,
- best_so_far,
- candidate) < 0) {
- /* candidate is right of the best choice, but left of the current column */
- return TRUE;
- }
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not before the current column */
+ if (compare_with_start_column (container, candidate) <= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_horizontal (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ /* candidate is right of the best choice, but left of the current column */
+ return TRUE;
+ }
- if (compare_icons_vertical (container,
- best_so_far,
- candidate) > 0) {
- return TRUE;
- }
- }
+ if (compare_icons_vertical (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ return TRUE;
+ }
+ }
- return best_so_far == NULL;
+ return best_so_far == NULL;
}
static gboolean
next_column_highest (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not after the current column */
- if (compare_with_start_column (container, candidate) >= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) > 0) {
- /* candidate is left of the best choice, but right of the current column */
- return TRUE;
- }
-
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) > 0) {
- return TRUE;
- }
- }
-
- return best_so_far == NULL;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not after the current column */
+ if (compare_with_start_column (container, candidate) >= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ /* candidate is left of the best choice, but right of the current column */
+ return TRUE;
+ }
+
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) > 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return best_so_far == NULL;
}
static gboolean
previous_column_lowest (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- /* sort out icons that are not before the current column */
- if (compare_with_start_column (container, candidate) <= 0) {
- return FALSE;
- }
-
- if (best_so_far != NULL) {
- if (compare_icons_horizontal_first (container,
- best_so_far,
- candidate) < 0) {
- /* candidate is right of the best choice, but left of the current column */
- return TRUE;
- }
-
- if (compare_icons_vertical_first (container,
- best_so_far,
- candidate) < 0) {
- return TRUE;
- }
- }
-
- return best_so_far == NULL;
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ /* sort out icons that are not before the current column */
+ if (compare_with_start_column (container, candidate) <= 0)
+ {
+ return FALSE;
+ }
+
+ if (best_so_far != NULL)
+ {
+ if (compare_icons_horizontal_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ /* candidate is right of the best choice, but left of the current column */
+ return TRUE;
+ }
+
+ if (compare_icons_vertical_first (container,
+ best_so_far,
+ candidate) < 0)
+ {
+ return TRUE;
+ }
+ }
+
+ return best_so_far == NULL;
}
static gboolean
last_column_lowest (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
{
- if (best_so_far == NULL) {
- return TRUE;
- }
- return compare_icons_horizontal_first (container, best_so_far, candidate) < 0;
+ if (best_so_far == NULL)
+ {
+ return TRUE;
+ }
+ return compare_icons_horizontal_first (container, best_so_far, candidate) < 0;
}
static gboolean
closest_in_90_degrees (NautilusCanvasContainer *container,
- NautilusCanvasIcon *start_icon,
- NautilusCanvasIcon *best_so_far,
- NautilusCanvasIcon *candidate,
- void *data)
-{
- EelDRect world_rect;
- int x, y;
- int dx, dy;
- int dist;
- int *best_dist;
-
-
- world_rect = nautilus_canvas_item_get_icon_rectangle (candidate->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &x,
- &y);
-
- dx = x - container->details->arrow_key_start_x;
- dy = y - container->details->arrow_key_start_y;
-
- switch (container->details->arrow_key_direction) {
- case GTK_DIR_UP:
- if (dy > 0 ||
- ABS(dx) > ABS(dy)) {
- return FALSE;
- }
- break;
- case GTK_DIR_DOWN:
- if (dy < 0 ||
- ABS(dx) > ABS(dy)) {
- return FALSE;
- }
- break;
- case GTK_DIR_LEFT:
- if (dx > 0 ||
- ABS(dy) > ABS(dx)) {
- return FALSE;
- }
- break;
- case GTK_DIR_RIGHT:
- if (dx < 0 ||
- ABS(dy) > ABS(dx)) {
- return FALSE;
- }
- break;
- default:
- g_assert_not_reached();
- }
-
- dist = dx*dx + dy*dy;
- best_dist = data;
-
- if (best_so_far == NULL) {
- *best_dist = dist;
- return TRUE;
- }
-
- if (dist < *best_dist) {
- *best_dist = dist;
- return TRUE;
- }
-
- return FALSE;
-}
-
-static EelDRect
+ NautilusCanvasIcon *start_icon,
+ NautilusCanvasIcon *best_so_far,
+ NautilusCanvasIcon *candidate,
+ void *data)
+{
+ EelDRect world_rect;
+ int x, y;
+ int dx, dy;
+ int dist;
+ int *best_dist;
+
+
+ world_rect = nautilus_canvas_item_get_icon_rectangle (candidate->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &x,
+ &y);
+
+ dx = x - container->details->arrow_key_start_x;
+ dy = y - container->details->arrow_key_start_y;
+
+ switch (container->details->arrow_key_direction)
+ {
+ case GTK_DIR_UP:
+ {
+ if (dy > 0 ||
+ ABS (dx) > ABS (dy))
+ {
+ return FALSE;
+ }
+ }
+ break;
+
+ case GTK_DIR_DOWN:
+ {
+ if (dy < 0 ||
+ ABS (dx) > ABS (dy))
+ {
+ return FALSE;
+ }
+ }
+ break;
+
+ case GTK_DIR_LEFT:
+ {
+ if (dx > 0 ||
+ ABS (dy) > ABS (dx))
+ {
+ return FALSE;
+ }
+ }
+ break;
+
+ case GTK_DIR_RIGHT:
+ {
+ if (dx < 0 ||
+ ABS (dy) > ABS (dx))
+ {
+ return FALSE;
+ }
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ dist = dx * dx + dy * dy;
+ best_dist = data;
+
+ if (best_so_far == NULL)
+ {
+ *best_dist = dist;
+ return TRUE;
+ }
+
+ if (dist < *best_dist)
+ {
+ *best_dist = dist;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static EelDRect
get_rubberband (NautilusCanvasIcon *icon1,
- NautilusCanvasIcon *icon2)
+ NautilusCanvasIcon *icon2)
{
- EelDRect rect1;
- EelDRect rect2;
- EelDRect ret;
+ EelDRect rect1;
+ EelDRect rect2;
+ EelDRect ret;
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon1->item),
- &rect1.x0, &rect1.y0,
- &rect1.x1, &rect1.y1);
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon2->item),
- &rect2.x0, &rect2.y0,
- &rect2.x1, &rect2.y1);
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon1->item),
+ &rect1.x0, &rect1.y0,
+ &rect1.x1, &rect1.y1);
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon2->item),
+ &rect2.x0, &rect2.y0,
+ &rect2.x1, &rect2.y1);
- eel_drect_union (&ret, &rect1, &rect2);
+ eel_drect_union (&ret, &rect1, &rect2);
- return ret;
+ return ret;
}
static void
keyboard_move_to (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- NautilusCanvasIcon *from,
- GdkEventKey *event)
-{
- if (icon == NULL) {
- return;
- }
-
- set_focus (container, icon, TRUE);
-
- if (event != NULL &&
- (event->state & GDK_CONTROL_MASK) != 0 &&
- (event->state & GDK_SHIFT_MASK) == 0) {
- clear_keyboard_rubberband_start (container);
- } else if (event != NULL &&
- ((event->state & GDK_CONTROL_MASK) != 0 ||
- !container->details->auto_layout) &&
- (event->state & GDK_SHIFT_MASK) != 0) {
- /* Do rubberband selection */
- EelDRect rect;
-
- if (from && !container->details->keyboard_rubberband_start) {
- set_keyboard_rubberband_start (container, from);
- }
-
- if (icon && container->details->keyboard_rubberband_start) {
- rect = get_rubberband (container->details->keyboard_rubberband_start,
- icon);
- rubberband_select (container, &rect);
- }
- } else if (event != NULL &&
- (event->state & GDK_CONTROL_MASK) == 0 &&
- (event->state & GDK_SHIFT_MASK) != 0) {
- /* Select range */
- NautilusCanvasIcon *start_icon;
-
- start_icon = container->details->range_selection_base_icon;
- if (start_icon == NULL || !start_icon->is_selected) {
- start_icon = icon;
- container->details->range_selection_base_icon = icon;
- }
-
- if (select_range (container, start_icon, icon, TRUE)) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
- } else {
- /* Select icon. */
- clear_keyboard_rubberband_start (container);
-
- container->details->range_selection_base_icon = icon;
- if (select_one_unselect_others (container, icon)) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
- }
- schedule_keyboard_icon_reveal (container, icon);
+ NautilusCanvasIcon *icon,
+ NautilusCanvasIcon *from,
+ GdkEventKey *event)
+{
+ if (icon == NULL)
+ {
+ return;
+ }
+
+ set_focus (container, icon, TRUE);
+
+ if (event != NULL &&
+ (event->state & GDK_CONTROL_MASK) != 0 &&
+ (event->state & GDK_SHIFT_MASK) == 0)
+ {
+ clear_keyboard_rubberband_start (container);
+ }
+ else if (event != NULL &&
+ ((event->state & GDK_CONTROL_MASK) != 0 ||
+ !container->details->auto_layout) &&
+ (event->state & GDK_SHIFT_MASK) != 0)
+ {
+ /* Do rubberband selection */
+ EelDRect rect;
+
+ if (from && !container->details->keyboard_rubberband_start)
+ {
+ set_keyboard_rubberband_start (container, from);
+ }
+
+ if (icon && container->details->keyboard_rubberband_start)
+ {
+ rect = get_rubberband (container->details->keyboard_rubberband_start,
+ icon);
+ rubberband_select (container, &rect);
+ }
+ }
+ else if (event != NULL &&
+ (event->state & GDK_CONTROL_MASK) == 0 &&
+ (event->state & GDK_SHIFT_MASK) != 0)
+ {
+ /* Select range */
+ NautilusCanvasIcon *start_icon;
+
+ start_icon = container->details->range_selection_base_icon;
+ if (start_icon == NULL || !start_icon->is_selected)
+ {
+ start_icon = icon;
+ container->details->range_selection_base_icon = icon;
+ }
+
+ if (select_range (container, start_icon, icon, TRUE))
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ }
+ else
+ {
+ /* Select icon. */
+ clear_keyboard_rubberband_start (container);
+
+ container->details->range_selection_base_icon = icon;
+ if (select_one_unselect_others (container, icon))
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ }
+ schedule_keyboard_icon_reveal (container, icon);
}
static void
keyboard_home (NautilusCanvasContainer *container,
- GdkEventKey *event)
+ GdkEventKey *event)
{
- NautilusCanvasIcon *from;
- NautilusCanvasIcon *to;
-
- /* Home selects the first canvas.
- * Control-Home sets the keyboard focus to the first canvas.
- */
+ NautilusCanvasIcon *from;
+ NautilusCanvasIcon *to;
- from = find_best_selected_icon (container, NULL,
- rightmost_in_bottom_row,
- NULL);
- to = find_best_icon (container, NULL, leftmost_in_top_row, NULL);
+ /* Home selects the first canvas.
+ * Control-Home sets the keyboard focus to the first canvas.
+ */
- keyboard_move_to (container, to, from, event);
+ from = find_best_selected_icon (container, NULL,
+ rightmost_in_bottom_row,
+ NULL);
+ to = find_best_icon (container, NULL, leftmost_in_top_row, NULL);
+
+ keyboard_move_to (container, to, from, event);
}
static void
keyboard_end (NautilusCanvasContainer *container,
- GdkEventKey *event)
+ GdkEventKey *event)
{
- NautilusCanvasIcon *to;
- NautilusCanvasIcon *from;
+ NautilusCanvasIcon *to;
+ NautilusCanvasIcon *from;
- /* End selects the last canvas.
- * Control-End sets the keyboard focus to the last canvas.
- */
- from = find_best_selected_icon (container, NULL,
- leftmost_in_top_row,
- NULL);
- to = find_best_icon (container, NULL,
- nautilus_canvas_container_is_layout_vertical (container) ?
- last_column_lowest :
- rightmost_in_bottom_row,
- NULL);
+ /* End selects the last canvas.
+ * Control-End sets the keyboard focus to the last canvas.
+ */
+ from = find_best_selected_icon (container, NULL,
+ leftmost_in_top_row,
+ NULL);
+ to = find_best_icon (container, NULL,
+ nautilus_canvas_container_is_layout_vertical (container) ?
+ last_column_lowest :
+ rightmost_in_bottom_row,
+ NULL);
- keyboard_move_to (container, to, from, event);
+ keyboard_move_to (container, to, from, event);
}
static void
record_arrow_key_start (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- GtkDirectionType direction)
+ NautilusCanvasIcon *icon,
+ GtkDirectionType direction)
{
- EelDRect world_rect;
+ EelDRect world_rect;
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
- eel_canvas_w2c
- (EEL_CANVAS (container),
- get_cmp_point_x (container, world_rect),
- get_cmp_point_y (container, world_rect),
- &container->details->arrow_key_start_x,
- &container->details->arrow_key_start_y);
- container->details->arrow_key_direction = direction;
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
+ eel_canvas_w2c
+ (EEL_CANVAS (container),
+ get_cmp_point_x (container, world_rect),
+ get_cmp_point_y (container, world_rect),
+ &container->details->arrow_key_start_x,
+ &container->details->arrow_key_start_y);
+ container->details->arrow_key_direction = direction;
}
static void
keyboard_arrow_key (NautilusCanvasContainer *container,
- GdkEventKey *event,
- GtkDirectionType direction,
- IsBetterCanvasFunction better_start,
- IsBetterCanvasFunction empty_start,
- IsBetterCanvasFunction better_destination,
- IsBetterCanvasFunction better_destination_fallback,
- IsBetterCanvasFunction better_destination_fallback_fallback,
- IsBetterCanvasFunction better_destination_manual)
-{
- NautilusCanvasIcon *from;
- NautilusCanvasIcon *to;
- int data;
-
- /* Chose the icon to start with.
- * If we have a keyboard focus, start with it.
- * Otherwise, use the single selected icon.
- * If there's multiple selection, use the icon farthest toward the end.
- */
-
- from = container->details->focus;
-
- if (from == NULL) {
- if (has_multiple_selection (container)) {
- if (all_selected (container)) {
- from = find_best_selected_icon
- (container, NULL,
- empty_start, NULL);
- } else {
- from = find_best_selected_icon
- (container, NULL,
- better_start, NULL);
- }
- } else {
- from = get_first_selected_icon (container);
- }
- }
-
- /* If there's no icon, select the icon farthest toward the end.
- * If there is an icon, select the next icon based on the arrow direction.
- */
- if (from == NULL) {
- to = from = find_best_icon
- (container, NULL,
- empty_start, NULL);
- } else {
- record_arrow_key_start (container, from, direction);
-
- to = find_best_icon
- (container, from,
- container->details->auto_layout ? better_destination : better_destination_manual,
- &data);
-
- /* Wrap around to next/previous row/column */
- if (to == NULL &&
- better_destination_fallback != NULL) {
- to = find_best_icon
- (container, from,
- better_destination_fallback,
- &data);
- }
-
- /* With a layout like
- * 1 2 3
- * 4
- * (horizontal layout)
- *
- * or
- *
- * 1 4
- * 2
- * 3
- * (vertical layout)
- *
- * * pressing down for any of 1,2,3 (horizontal layout)
- * * pressing right for any of 1,2,3 (vertical layout)
- *
- * Should select 4.
- */
- if (to == NULL &&
- container->details->auto_layout &&
- better_destination_fallback_fallback != NULL) {
- to = find_best_icon
- (container, from,
- better_destination_fallback_fallback,
- &data);
- }
-
- if (to == NULL) {
- to = from;
- }
-
- }
-
- keyboard_move_to (container, to, from, event);
+ GdkEventKey *event,
+ GtkDirectionType direction,
+ IsBetterCanvasFunction better_start,
+ IsBetterCanvasFunction empty_start,
+ IsBetterCanvasFunction better_destination,
+ IsBetterCanvasFunction better_destination_fallback,
+ IsBetterCanvasFunction better_destination_fallback_fallback,
+ IsBetterCanvasFunction better_destination_manual)
+{
+ NautilusCanvasIcon *from;
+ NautilusCanvasIcon *to;
+ int data;
+
+ /* Chose the icon to start with.
+ * If we have a keyboard focus, start with it.
+ * Otherwise, use the single selected icon.
+ * If there's multiple selection, use the icon farthest toward the end.
+ */
+
+ from = container->details->focus;
+
+ if (from == NULL)
+ {
+ if (has_multiple_selection (container))
+ {
+ if (all_selected (container))
+ {
+ from = find_best_selected_icon
+ (container, NULL,
+ empty_start, NULL);
+ }
+ else
+ {
+ from = find_best_selected_icon
+ (container, NULL,
+ better_start, NULL);
+ }
+ }
+ else
+ {
+ from = get_first_selected_icon (container);
+ }
+ }
+
+ /* If there's no icon, select the icon farthest toward the end.
+ * If there is an icon, select the next icon based on the arrow direction.
+ */
+ if (from == NULL)
+ {
+ to = from = find_best_icon
+ (container, NULL,
+ empty_start, NULL);
+ }
+ else
+ {
+ record_arrow_key_start (container, from, direction);
+
+ to = find_best_icon
+ (container, from,
+ container->details->auto_layout ? better_destination : better_destination_manual,
+ &data);
+
+ /* Wrap around to next/previous row/column */
+ if (to == NULL &&
+ better_destination_fallback != NULL)
+ {
+ to = find_best_icon
+ (container, from,
+ better_destination_fallback,
+ &data);
+ }
+
+ /* With a layout like
+ * 1 2 3
+ * 4
+ * (horizontal layout)
+ *
+ * or
+ *
+ * 1 4
+ * 2
+ * 3
+ * (vertical layout)
+ *
+ * * pressing down for any of 1,2,3 (horizontal layout)
+ * * pressing right for any of 1,2,3 (vertical layout)
+ *
+ * Should select 4.
+ */
+ if (to == NULL &&
+ container->details->auto_layout &&
+ better_destination_fallback_fallback != NULL)
+ {
+ to = find_best_icon
+ (container, from,
+ better_destination_fallback_fallback,
+ &data);
+ }
+
+ if (to == NULL)
+ {
+ to = from;
+ }
+ }
+
+ keyboard_move_to (container, to, from, event);
}
static gboolean
is_rectangle_selection_event (GdkEventKey *event)
{
- return (event->state & GDK_CONTROL_MASK) != 0 &&
- (event->state & GDK_SHIFT_MASK) != 0;
+ return (event->state & GDK_CONTROL_MASK) != 0 &&
+ (event->state & GDK_SHIFT_MASK) != 0;
}
static void
keyboard_right (NautilusCanvasContainer *container,
- GdkEventKey *event)
-{
- IsBetterCanvasFunction fallback;
- IsBetterCanvasFunction next_column_fallback;
-
- fallback = NULL;
- if (container->details->auto_layout &&
- !nautilus_canvas_container_is_layout_vertical (container) &&
- !is_rectangle_selection_event (event)) {
- fallback = next_row_leftmost;
- }
-
- next_column_fallback = NULL;
- if (nautilus_canvas_container_is_layout_vertical (container) &&
- gtk_widget_get_direction (GTK_WIDGET (container)) != GTK_TEXT_DIR_RTL) {
- next_column_fallback = next_column_bottommost;
- }
-
- /* Right selects the next icon in the same row.
- * Control-Right sets the keyboard focus to the next icon in the same row.
- */
- keyboard_arrow_key (container,
- event,
- GTK_DIR_RIGHT,
- rightmost_in_bottom_row,
- nautilus_canvas_container_is_layout_rtl (container) ?
- rightmost_in_top_row : leftmost_in_top_row,
- same_row_right_side_leftmost,
- fallback,
- next_column_fallback,
- closest_in_90_degrees);
+ GdkEventKey *event)
+{
+ IsBetterCanvasFunction fallback;
+ IsBetterCanvasFunction next_column_fallback;
+
+ fallback = NULL;
+ if (container->details->auto_layout &&
+ !nautilus_canvas_container_is_layout_vertical (container) &&
+ !is_rectangle_selection_event (event))
+ {
+ fallback = next_row_leftmost;
+ }
+
+ next_column_fallback = NULL;
+ if (nautilus_canvas_container_is_layout_vertical (container) &&
+ gtk_widget_get_direction (GTK_WIDGET (container)) != GTK_TEXT_DIR_RTL)
+ {
+ next_column_fallback = next_column_bottommost;
+ }
+
+ /* Right selects the next icon in the same row.
+ * Control-Right sets the keyboard focus to the next icon in the same row.
+ */
+ keyboard_arrow_key (container,
+ event,
+ GTK_DIR_RIGHT,
+ rightmost_in_bottom_row,
+ nautilus_canvas_container_is_layout_rtl (container) ?
+ rightmost_in_top_row : leftmost_in_top_row,
+ same_row_right_side_leftmost,
+ fallback,
+ next_column_fallback,
+ closest_in_90_degrees);
}
static void
keyboard_left (NautilusCanvasContainer *container,
- GdkEventKey *event)
-{
- IsBetterCanvasFunction fallback;
- IsBetterCanvasFunction previous_column_fallback;
-
- fallback = NULL;
- if (container->details->auto_layout &&
- !nautilus_canvas_container_is_layout_vertical (container) &&
- !is_rectangle_selection_event (event)) {
- fallback = previous_row_rightmost;
- }
-
- previous_column_fallback = NULL;
- if (nautilus_canvas_container_is_layout_vertical (container) &&
- gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
- previous_column_fallback = previous_column_lowest;
- }
-
- /* Left selects the next icon in the same row.
- * Control-Left sets the keyboard focus to the next icon in the same row.
- */
- keyboard_arrow_key (container,
- event,
- GTK_DIR_LEFT,
- rightmost_in_bottom_row,
- nautilus_canvas_container_is_layout_rtl (container) ?
- rightmost_in_top_row : leftmost_in_top_row,
- same_row_left_side_rightmost,
- fallback,
- previous_column_fallback,
- closest_in_90_degrees);
+ GdkEventKey *event)
+{
+ IsBetterCanvasFunction fallback;
+ IsBetterCanvasFunction previous_column_fallback;
+
+ fallback = NULL;
+ if (container->details->auto_layout &&
+ !nautilus_canvas_container_is_layout_vertical (container) &&
+ !is_rectangle_selection_event (event))
+ {
+ fallback = previous_row_rightmost;
+ }
+
+ previous_column_fallback = NULL;
+ if (nautilus_canvas_container_is_layout_vertical (container) &&
+ gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
+ {
+ previous_column_fallback = previous_column_lowest;
+ }
+
+ /* Left selects the next icon in the same row.
+ * Control-Left sets the keyboard focus to the next icon in the same row.
+ */
+ keyboard_arrow_key (container,
+ event,
+ GTK_DIR_LEFT,
+ rightmost_in_bottom_row,
+ nautilus_canvas_container_is_layout_rtl (container) ?
+ rightmost_in_top_row : leftmost_in_top_row,
+ same_row_left_side_rightmost,
+ fallback,
+ previous_column_fallback,
+ closest_in_90_degrees);
}
static void
keyboard_down (NautilusCanvasContainer *container,
- GdkEventKey *event)
-{
- IsBetterCanvasFunction fallback;
- IsBetterCanvasFunction next_row_fallback;
-
- fallback = NULL;
- if (container->details->auto_layout &&
- nautilus_canvas_container_is_layout_vertical (container) &&
- !is_rectangle_selection_event (event)) {
- if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
- fallback = previous_column_highest;
- } else {
- fallback = next_column_highest;
- }
- }
-
- next_row_fallback = NULL;
- if (!nautilus_canvas_container_is_layout_vertical (container)) {
- if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
- next_row_fallback = next_row_leftmost;
- } else {
- next_row_fallback = next_row_rightmost;
- }
- }
-
- /* Down selects the next icon in the same column.
- * Control-Down sets the keyboard focus to the next icon in the same column.
- */
- keyboard_arrow_key (container,
- event,
- GTK_DIR_DOWN,
- rightmost_in_bottom_row,
- nautilus_canvas_container_is_layout_rtl (container) ?
- rightmost_in_top_row : leftmost_in_top_row,
- same_column_below_highest,
- fallback,
- next_row_fallback,
- closest_in_90_degrees);
+ GdkEventKey *event)
+{
+ IsBetterCanvasFunction fallback;
+ IsBetterCanvasFunction next_row_fallback;
+
+ fallback = NULL;
+ if (container->details->auto_layout &&
+ nautilus_canvas_container_is_layout_vertical (container) &&
+ !is_rectangle_selection_event (event))
+ {
+ if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
+ {
+ fallback = previous_column_highest;
+ }
+ else
+ {
+ fallback = next_column_highest;
+ }
+ }
+
+ next_row_fallback = NULL;
+ if (!nautilus_canvas_container_is_layout_vertical (container))
+ {
+ if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
+ {
+ next_row_fallback = next_row_leftmost;
+ }
+ else
+ {
+ next_row_fallback = next_row_rightmost;
+ }
+ }
+
+ /* Down selects the next icon in the same column.
+ * Control-Down sets the keyboard focus to the next icon in the same column.
+ */
+ keyboard_arrow_key (container,
+ event,
+ GTK_DIR_DOWN,
+ rightmost_in_bottom_row,
+ nautilus_canvas_container_is_layout_rtl (container) ?
+ rightmost_in_top_row : leftmost_in_top_row,
+ same_column_below_highest,
+ fallback,
+ next_row_fallback,
+ closest_in_90_degrees);
}
static void
keyboard_up (NautilusCanvasContainer *container,
- GdkEventKey *event)
-{
- IsBetterCanvasFunction fallback;
-
- fallback = NULL;
- if (container->details->auto_layout &&
- nautilus_canvas_container_is_layout_vertical (container) &&
- !is_rectangle_selection_event (event)) {
- if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
- fallback = next_column_bottommost;
- } else {
- fallback = previous_column_lowest;
- }
- }
-
- /* Up selects the next icon in the same column.
- * Control-Up sets the keyboard focus to the next icon in the same column.
- */
- keyboard_arrow_key (container,
- event,
- GTK_DIR_UP,
- rightmost_in_bottom_row,
- nautilus_canvas_container_is_layout_rtl (container) ?
- rightmost_in_top_row : leftmost_in_top_row,
- same_column_above_lowest,
- fallback,
- NULL,
- closest_in_90_degrees);
+ GdkEventKey *event)
+{
+ IsBetterCanvasFunction fallback;
+
+ fallback = NULL;
+ if (container->details->auto_layout &&
+ nautilus_canvas_container_is_layout_vertical (container) &&
+ !is_rectangle_selection_event (event))
+ {
+ if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL)
+ {
+ fallback = next_column_bottommost;
+ }
+ else
+ {
+ fallback = previous_column_lowest;
+ }
+ }
+
+ /* Up selects the next icon in the same column.
+ * Control-Up sets the keyboard focus to the next icon in the same column.
+ */
+ keyboard_arrow_key (container,
+ event,
+ GTK_DIR_UP,
+ rightmost_in_bottom_row,
+ nautilus_canvas_container_is_layout_rtl (container) ?
+ rightmost_in_top_row : leftmost_in_top_row,
+ same_column_above_lowest,
+ fallback,
+ NULL,
+ closest_in_90_degrees);
}
static void
keyboard_space (NautilusCanvasContainer *container,
- GdkEventKey *event)
-{
- NautilusCanvasIcon *icon;
-
- if (!has_selection (container) &&
- container->details->focus != NULL) {
- keyboard_move_to (container,
- container->details->focus,
- NULL, NULL);
- } else if ((event->state & GDK_CONTROL_MASK) != 0 &&
- (event->state & GDK_SHIFT_MASK) == 0) {
- /* Control-space toggles the selection state of the current icon. */
- if (container->details->focus != NULL) {
- icon_toggle_selected (container, container->details->focus);
- g_signal_emit (container, signals[SELECTION_CHANGED], 0);
- if (container->details->focus->is_selected) {
- container->details->range_selection_base_icon = container->details->focus;
- }
- } else {
- icon = find_best_selected_icon (container,
- NULL,
- leftmost_in_top_row,
- NULL);
- if (icon == NULL) {
- icon = find_best_icon (container,
- NULL,
- leftmost_in_top_row,
- NULL);
- }
- if (icon != NULL) {
- set_focus (container, icon, TRUE);
- }
- }
- } else if ((event->state & GDK_SHIFT_MASK) != 0) {
- activate_selected_items_alternate (container, NULL);
- } else {
- preview_selected_items (container);
- }
+ GdkEventKey *event)
+{
+ NautilusCanvasIcon *icon;
+
+ if (!has_selection (container) &&
+ container->details->focus != NULL)
+ {
+ keyboard_move_to (container,
+ container->details->focus,
+ NULL, NULL);
+ }
+ else if ((event->state & GDK_CONTROL_MASK) != 0 &&
+ (event->state & GDK_SHIFT_MASK) == 0)
+ {
+ /* Control-space toggles the selection state of the current icon. */
+ if (container->details->focus != NULL)
+ {
+ icon_toggle_selected (container, container->details->focus);
+ g_signal_emit (container, signals[SELECTION_CHANGED], 0);
+ if (container->details->focus->is_selected)
+ {
+ container->details->range_selection_base_icon = container->details->focus;
+ }
+ }
+ else
+ {
+ icon = find_best_selected_icon (container,
+ NULL,
+ leftmost_in_top_row,
+ NULL);
+ if (icon == NULL)
+ {
+ icon = find_best_icon (container,
+ NULL,
+ leftmost_in_top_row,
+ NULL);
+ }
+ if (icon != NULL)
+ {
+ set_focus (container, icon, TRUE);
+ }
+ }
+ }
+ else if ((event->state & GDK_SHIFT_MASK) != 0)
+ {
+ activate_selected_items_alternate (container, NULL);
+ }
+ else
+ {
+ preview_selected_items (container);
+ }
}
static void
destroy (GtkWidget *object)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (object);
+ container = NAUTILUS_CANVAS_CONTAINER (object);
- nautilus_canvas_container_clear (container);
+ nautilus_canvas_container_clear (container);
- if (container->details->rubberband_info.timer_id != 0) {
- g_source_remove (container->details->rubberband_info.timer_id);
- container->details->rubberband_info.timer_id = 0;
- }
+ if (container->details->rubberband_info.timer_id != 0)
+ {
+ g_source_remove (container->details->rubberband_info.timer_id);
+ container->details->rubberband_info.timer_id = 0;
+ }
- if (container->details->idle_id != 0) {
- g_source_remove (container->details->idle_id);
- container->details->idle_id = 0;
- }
+ if (container->details->idle_id != 0)
+ {
+ g_source_remove (container->details->idle_id);
+ container->details->idle_id = 0;
+ }
- if (container->details->stretch_idle_id != 0) {
- g_source_remove (container->details->stretch_idle_id);
- container->details->stretch_idle_id = 0;
- }
+ if (container->details->stretch_idle_id != 0)
+ {
+ g_source_remove (container->details->stretch_idle_id);
+ container->details->stretch_idle_id = 0;
+ }
- if (container->details->align_idle_id != 0) {
- g_source_remove (container->details->align_idle_id);
- container->details->align_idle_id = 0;
- }
+ if (container->details->align_idle_id != 0)
+ {
+ g_source_remove (container->details->align_idle_id);
+ container->details->align_idle_id = 0;
+ }
- if (container->details->selection_changed_id != 0) {
- g_source_remove (container->details->selection_changed_id);
- container->details->selection_changed_id = 0;
- }
+ if (container->details->selection_changed_id != 0)
+ {
+ g_source_remove (container->details->selection_changed_id);
+ container->details->selection_changed_id = 0;
+ }
- if (container->details->size_allocation_count_id != 0) {
- g_source_remove (container->details->size_allocation_count_id);
- container->details->size_allocation_count_id = 0;
- }
+ if (container->details->size_allocation_count_id != 0)
+ {
+ g_source_remove (container->details->size_allocation_count_id);
+ container->details->size_allocation_count_id = 0;
+ }
- GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->destroy (object);
}
static void
finalize (GObject *object)
{
- NautilusCanvasContainerDetails *details;
+ NautilusCanvasContainerDetails *details;
- details = NAUTILUS_CANVAS_CONTAINER (object)->details;
+ details = NAUTILUS_CANVAS_CONTAINER (object)->details;
- g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
- text_ellipsis_limit_changed_container_callback,
- object);
- g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
- text_ellipsis_limit_changed_container_callback,
- object);
+ g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
+ text_ellipsis_limit_changed_container_callback,
+ object);
+ g_signal_handlers_disconnect_by_func (nautilus_desktop_preferences,
+ text_ellipsis_limit_changed_container_callback,
+ object);
- g_hash_table_destroy (details->icon_set);
- details->icon_set = NULL;
+ g_hash_table_destroy (details->icon_set);
+ details->icon_set = NULL;
- g_free (details->font);
+ g_free (details->font);
- if (details->a11y_item_action_queue != NULL) {
- while (!g_queue_is_empty (details->a11y_item_action_queue)) {
- g_free (g_queue_pop_head (details->a11y_item_action_queue));
- }
- g_queue_free (details->a11y_item_action_queue);
- }
- if (details->a11y_item_action_idle_handler != 0) {
- g_source_remove (details->a11y_item_action_idle_handler);
- }
+ if (details->a11y_item_action_queue != NULL)
+ {
+ while (!g_queue_is_empty (details->a11y_item_action_queue))
+ {
+ g_free (g_queue_pop_head (details->a11y_item_action_queue));
+ }
+ g_queue_free (details->a11y_item_action_queue);
+ }
+ if (details->a11y_item_action_idle_handler != 0)
+ {
+ g_source_remove (details->a11y_item_action_idle_handler);
+ }
- g_free (details);
+ g_free (details);
- G_OBJECT_CLASS (nautilus_canvas_container_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_canvas_container_parent_class)->finalize (object);
}
/* GtkWidget methods. */
@@ -3778,951 +4208,1113 @@ finalize (GObject *object)
static gboolean
clear_size_allocation_count (gpointer data)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (data);
+ container = NAUTILUS_CANVAS_CONTAINER (data);
- container->details->size_allocation_count_id = 0;
- container->details->size_allocation_count = 0;
+ container->details->size_allocation_count_id = 0;
+ container->details->size_allocation_count = 0;
- return FALSE;
+ return FALSE;
}
static void
-size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- NautilusCanvasContainer *container;
- gboolean need_layout_redone;
- GtkAllocation wid_allocation;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
-
- need_layout_redone = !container->details->has_been_allocated;
- gtk_widget_get_allocation (widget, &wid_allocation);
-
- if (allocation->width != wid_allocation.width) {
- need_layout_redone = TRUE;
- }
-
- if (allocation->height != wid_allocation.height) {
- need_layout_redone = TRUE;
- }
-
- /* Under some conditions we can end up in a loop when size allocating.
- * This happens when the icons don't fit without a scrollbar, but fits
- * when a scrollbar is added (bug #129963 for details).
- * We keep track of this looping by increasing a counter in size_allocate
- * and clearing it in a high-prio idle (the only way to detect the loop is
- * done).
- * When we've done at more than two iterations (with/without scrollbar)
- * we terminate this looping by not redoing the layout when the width
- * is wider than the current one (i.e when removing the scrollbar).
- */
- if (container->details->size_allocation_count_id == 0) {
- container->details->size_allocation_count_id =
- g_idle_add_full (G_PRIORITY_HIGH,
- clear_size_allocation_count,
- container, NULL);
- }
- container->details->size_allocation_count++;
- if (container->details->size_allocation_count > 2 &&
- allocation->width >= wid_allocation.width) {
- need_layout_redone = FALSE;
- }
-
- GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->size_allocate (widget, allocation);
-
- container->details->has_been_allocated = TRUE;
-
- if (need_layout_redone) {
- redo_layout (container);
- }
+size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ NautilusCanvasContainer *container;
+ gboolean need_layout_redone;
+ GtkAllocation wid_allocation;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+
+ need_layout_redone = !container->details->has_been_allocated;
+ gtk_widget_get_allocation (widget, &wid_allocation);
+
+ if (allocation->width != wid_allocation.width)
+ {
+ need_layout_redone = TRUE;
+ }
+
+ if (allocation->height != wid_allocation.height)
+ {
+ need_layout_redone = TRUE;
+ }
+
+ /* Under some conditions we can end up in a loop when size allocating.
+ * This happens when the icons don't fit without a scrollbar, but fits
+ * when a scrollbar is added (bug #129963 for details).
+ * We keep track of this looping by increasing a counter in size_allocate
+ * and clearing it in a high-prio idle (the only way to detect the loop is
+ * done).
+ * When we've done at more than two iterations (with/without scrollbar)
+ * we terminate this looping by not redoing the layout when the width
+ * is wider than the current one (i.e when removing the scrollbar).
+ */
+ if (container->details->size_allocation_count_id == 0)
+ {
+ container->details->size_allocation_count_id =
+ g_idle_add_full (G_PRIORITY_HIGH,
+ clear_size_allocation_count,
+ container, NULL);
+ }
+ container->details->size_allocation_count++;
+ if (container->details->size_allocation_count > 2 &&
+ allocation->width >= wid_allocation.width)
+ {
+ need_layout_redone = FALSE;
+ }
+
+ GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->size_allocate (widget, allocation);
+
+ container->details->has_been_allocated = TRUE;
+
+ if (need_layout_redone)
+ {
+ redo_layout (container);
+ }
}
static GtkSizeRequestMode
get_request_mode (GtkWidget *widget)
{
- /* Don't trade size at all, since we get whatever we get anyway. */
- return GTK_SIZE_REQUEST_CONSTANT_SIZE;
+ /* Don't trade size at all, since we get whatever we get anyway. */
+ return GTK_SIZE_REQUEST_CONSTANT_SIZE;
}
/* We need to implement these since the GtkScrolledWindow uses them
- to guess whether to show scrollbars or not, and if we don't report
- anything it'll tend to get it wrong causing double calls
- to size_allocate (at different sizes) during its size allocation. */
+ * to guess whether to show scrollbars or not, and if we don't report
+ * anything it'll tend to get it wrong causing double calls
+ * to size_allocate (at different sizes) during its size allocation. */
static void
get_prefered_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- EelCanvasGroup *root;
- double x1, x2;
- int cx1, cx2;
- int width;
-
- root = eel_canvas_root (EEL_CANVAS (widget));
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
- &x1, NULL, &x2, NULL);
- eel_canvas_w2c (EEL_CANVAS (widget), x1, 0, &cx1, NULL);
- eel_canvas_w2c (EEL_CANVAS (widget), x2, 0, &cx2, NULL);
-
- width = cx2 - cx1;
- if (natural_size) {
- *natural_size = width;
- }
- if (minimum_size) {
- *minimum_size = width;
- }
+ gint *minimum_size,
+ gint *natural_size)
+{
+ EelCanvasGroup *root;
+ double x1, x2;
+ int cx1, cx2;
+ int width;
+
+ root = eel_canvas_root (EEL_CANVAS (widget));
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
+ &x1, NULL, &x2, NULL);
+ eel_canvas_w2c (EEL_CANVAS (widget), x1, 0, &cx1, NULL);
+ eel_canvas_w2c (EEL_CANVAS (widget), x2, 0, &cx2, NULL);
+
+ width = cx2 - cx1;
+ if (natural_size)
+ {
+ *natural_size = width;
+ }
+ if (minimum_size)
+ {
+ *minimum_size = width;
+ }
}
static void
get_prefered_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- EelCanvasGroup *root;
- double y1, y2;
- int cy1, cy2;
- int height;
-
- root = eel_canvas_root (EEL_CANVAS (widget));
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
- NULL, &y1, NULL, &y2);
- eel_canvas_w2c (EEL_CANVAS (widget), 0, y1, NULL, &cy1);
- eel_canvas_w2c (EEL_CANVAS (widget), 0, y2, NULL, &cy2);
-
- height = cy2 - cy1;
- if (natural_size) {
- *natural_size = height;
- }
- if (minimum_size) {
- *minimum_size = height;
- }
+ gint *minimum_size,
+ gint *natural_size)
+{
+ EelCanvasGroup *root;
+ double y1, y2;
+ int cy1, cy2;
+ int height;
+
+ root = eel_canvas_root (EEL_CANVAS (widget));
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (root),
+ NULL, &y1, NULL, &y2);
+ eel_canvas_w2c (EEL_CANVAS (widget), 0, y1, NULL, &cy1);
+ eel_canvas_w2c (EEL_CANVAS (widget), 0, y2, NULL, &cy2);
+
+ height = cy2 - cy1;
+ if (natural_size)
+ {
+ *natural_size = height;
+ }
+ if (minimum_size)
+ {
+ *minimum_size = height;
+ }
}
static void
realize (GtkWidget *widget)
{
- GtkAdjustment *vadj, *hadj;
- NautilusCanvasContainer *container;
+ GtkAdjustment *vadj, *hadj;
+ NautilusCanvasContainer *container;
- GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->realize (widget);
+ GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->realize (widget);
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- /* Set up DnD. */
- nautilus_canvas_dnd_init (container);
+ /* Set up DnD. */
+ nautilus_canvas_dnd_init (container);
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget));
- g_signal_connect (hadj, "value-changed",
- G_CALLBACK (handle_hadjustment_changed), widget);
-
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget));
- g_signal_connect (vadj, "value-changed",
- G_CALLBACK (handle_vadjustment_changed), widget);
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget));
+ g_signal_connect (hadj, "value-changed",
+ G_CALLBACK (handle_hadjustment_changed), widget);
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget));
+ g_signal_connect (vadj, "value-changed",
+ G_CALLBACK (handle_vadjustment_changed), widget);
}
static void
unrealize (GtkWidget *widget)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- nautilus_canvas_dnd_fini (container);
+ nautilus_canvas_dnd_fini (container);
- GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->unrealize (widget);
+ GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->unrealize (widget);
}
static void
nautilus_canvas_container_request_update_all_internal (NautilusCanvasContainer *container,
- gboolean invalidate_labels)
+ gboolean invalidate_labels)
{
- GList *node;
- NautilusCanvasIcon *icon;
+ GList *node;
+ NautilusCanvasIcon *icon;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- for (node = container->details->icons; node != NULL; node = node->next) {
- icon = node->data;
+ for (node = container->details->icons; node != NULL; node = node->next)
+ {
+ icon = node->data;
- if (invalidate_labels) {
- nautilus_canvas_item_invalidate_label (icon->item);
- }
+ if (invalidate_labels)
+ {
+ nautilus_canvas_item_invalidate_label (icon->item);
+ }
- nautilus_canvas_container_update_icon (container, icon);
- }
+ nautilus_canvas_container_update_icon (container, icon);
+ }
- container->details->needs_resort = TRUE;
- redo_layout (container);
+ container->details->needs_resort = TRUE;
+ redo_layout (container);
}
static void
style_updated (GtkWidget *widget)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- /* Don't chain up to parent, if this is a desktop container,
- * because that resets the background of the window.
- */
- if (!nautilus_canvas_container_get_is_desktop (container)) {
- GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->style_updated (widget);
- }
+ /* Don't chain up to parent, if this is a desktop container,
+ * because that resets the background of the window.
+ */
+ if (!nautilus_canvas_container_get_is_desktop (container))
+ {
+ GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->style_updated (widget);
+ }
- if (gtk_widget_get_realized (widget)) {
- nautilus_canvas_container_request_update_all_internal (container, TRUE);
- }
+ if (gtk_widget_get_realized (widget))
+ {
+ nautilus_canvas_container_request_update_all_internal (container, TRUE);
+ }
}
static gboolean
-button_press_event (GtkWidget *widget,
- GdkEventButton *event)
-{
- NautilusCanvasContainer *container;
- gboolean selection_changed;
- gboolean return_value;
- gboolean clicked_on_icon;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- container->details->button_down_time = event->time;
-
- /* Forget about the old keyboard selection now that we've started mousing. */
- clear_keyboard_rubberband_start (container);
-
- if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
- /* We use our own double-click detection. */
- return TRUE;
- }
-
- /* Invoke the canvas event handler and see if an item picks up the event. */
- clicked_on_icon = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->button_press_event (widget, event);
-
- if (!gtk_widget_has_focus (widget)) {
- gtk_widget_grab_focus (widget);
- }
-
- if (clicked_on_icon) {
- return TRUE;
- }
-
- clear_focus (container);
-
- if (event->button == DRAG_BUTTON &&
- event->type == GDK_BUTTON_PRESS) {
- /* Clear the last click icon for double click */
- container->details->double_click_icon[1] = container->details->double_click_icon[0];
- container->details->double_click_icon[0] = NULL;
- }
-
- /* Button 1 does rubber banding. */
- if (event->button == RUBBERBAND_BUTTON) {
- if (! button_event_modifies_selection (event)) {
- selection_changed = unselect_all (container);
- if (selection_changed) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
- }
-
- start_rubberbanding (container, event);
- return TRUE;
- }
-
- /* Prevent multi-button weirdness such as bug 6181 */
- if (container->details->rubberband_info.active) {
- return TRUE;
- }
-
- /* Button 2 may be passed to the window manager. */
- if (event->button == MIDDLE_BUTTON) {
- selection_changed = unselect_all (container);
- if (selection_changed) {
- g_signal_emit (container, signals[SELECTION_CHANGED], 0);
- }
- g_signal_emit (widget, signals[MIDDLE_CLICK], 0, event);
- return TRUE;
- }
-
- /* Button 3 does a contextual menu. */
- if (event->button == CONTEXTUAL_MENU_BUTTON) {
- selection_changed = unselect_all (container);
- if (selection_changed) {
- g_signal_emit (container, signals[SELECTION_CHANGED], 0);
- }
- g_signal_emit (widget, signals[CONTEXT_CLICK_BACKGROUND], 0, event);
- return TRUE;
- }
-
- /* Otherwise, we emit a button_press message. */
- g_signal_emit (widget,
- signals[BUTTON_PRESS], 0, event,
- &return_value);
- return return_value;
+button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ NautilusCanvasContainer *container;
+ gboolean selection_changed;
+ gboolean return_value;
+ gboolean clicked_on_icon;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container->details->button_down_time = event->time;
+
+ /* Forget about the old keyboard selection now that we've started mousing. */
+ clear_keyboard_rubberband_start (container);
+
+ if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
+ {
+ /* We use our own double-click detection. */
+ return TRUE;
+ }
+
+ /* Invoke the canvas event handler and see if an item picks up the event. */
+ clicked_on_icon = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->button_press_event (widget, event);
+
+ if (!gtk_widget_has_focus (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ }
+
+ if (clicked_on_icon)
+ {
+ return TRUE;
+ }
+
+ clear_focus (container);
+
+ if (event->button == DRAG_BUTTON &&
+ event->type == GDK_BUTTON_PRESS)
+ {
+ /* Clear the last click icon for double click */
+ container->details->double_click_icon[1] = container->details->double_click_icon[0];
+ container->details->double_click_icon[0] = NULL;
+ }
+
+ /* Button 1 does rubber banding. */
+ if (event->button == RUBBERBAND_BUTTON)
+ {
+ if (!button_event_modifies_selection (event))
+ {
+ selection_changed = unselect_all (container);
+ if (selection_changed)
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ }
+
+ start_rubberbanding (container, event);
+ return TRUE;
+ }
+
+ /* Prevent multi-button weirdness such as bug 6181 */
+ if (container->details->rubberband_info.active)
+ {
+ return TRUE;
+ }
+
+ /* Button 2 may be passed to the window manager. */
+ if (event->button == MIDDLE_BUTTON)
+ {
+ selection_changed = unselect_all (container);
+ if (selection_changed)
+ {
+ g_signal_emit (container, signals[SELECTION_CHANGED], 0);
+ }
+ g_signal_emit (widget, signals[MIDDLE_CLICK], 0, event);
+ return TRUE;
+ }
+
+ /* Button 3 does a contextual menu. */
+ if (event->button == CONTEXTUAL_MENU_BUTTON)
+ {
+ selection_changed = unselect_all (container);
+ if (selection_changed)
+ {
+ g_signal_emit (container, signals[SELECTION_CHANGED], 0);
+ }
+ g_signal_emit (widget, signals[CONTEXT_CLICK_BACKGROUND], 0, event);
+ return TRUE;
+ }
+
+ /* Otherwise, we emit a button_press message. */
+ g_signal_emit (widget,
+ signals[BUTTON_PRESS], 0, event,
+ &return_value);
+ return return_value;
}
static void
nautilus_canvas_container_did_not_drag (NautilusCanvasContainer *container,
- GdkEventButton *event)
-{
- NautilusCanvasContainerDetails *details;
- gboolean selection_changed;
- static gint64 last_click_time = 0;
- static gint click_count = 0;
- gint double_click_time;
- gint64 current_time;
-
- details = container->details;
-
- if (details->icon_selected_on_button_down &&
- ((event->state & GDK_CONTROL_MASK) != 0 ||
- (event->state & GDK_SHIFT_MASK) == 0)) {
- if (button_event_modifies_selection (event)) {
- details->range_selection_base_icon = NULL;
- icon_toggle_selected (container, details->drag_icon);
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- } else {
- details->range_selection_base_icon = details->drag_icon;
- selection_changed = select_one_unselect_others
- (container, details->drag_icon);
-
- if (selection_changed) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
- }
- }
-
- if (details->drag_icon != NULL &&
- (details->single_click_mode ||
- event->button == MIDDLE_BUTTON)) {
- /* Determine click count */
- g_object_get (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (container))),
- "gtk-double-click-time", &double_click_time,
- NULL);
- current_time = g_get_monotonic_time ();
- if (current_time - last_click_time < double_click_time * 1000) {
- click_count++;
- } else {
- click_count = 0;
- }
-
- /* Stash time for next compare */
- last_click_time = current_time;
-
- /* If single-click mode, activate the selected icons, unless modifying
- * the selection or pressing for a very long time, or double clicking.
- */
-
-
- if (click_count == 0 &&
- event->time - details->button_down_time < MAX_CLICK_TIME &&
- ! button_event_modifies_selection (event)) {
-
- /* It's a tricky UI issue whether this should activate
- * just the clicked item (as if it were a link), or all
- * the selected items (as if you were issuing an "activate
- * selection" command). For now, we're trying the activate
- * entire selection version to see how it feels. Note that
- * NautilusList goes the other way because its "links" seem
- * much more link-like.
- */
- if (event->button == MIDDLE_BUTTON) {
- activate_selected_items_alternate (container, NULL);
- } else {
- activate_selected_items (container);
- }
- }
- }
+ GdkEventButton *event)
+{
+ NautilusCanvasContainerDetails *details;
+ gboolean selection_changed;
+ static gint64 last_click_time = 0;
+ static gint click_count = 0;
+ gint double_click_time;
+ gint64 current_time;
+
+ details = container->details;
+
+ if (details->icon_selected_on_button_down &&
+ ((event->state & GDK_CONTROL_MASK) != 0 ||
+ (event->state & GDK_SHIFT_MASK) == 0))
+ {
+ if (button_event_modifies_selection (event))
+ {
+ details->range_selection_base_icon = NULL;
+ icon_toggle_selected (container, details->drag_icon);
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ else
+ {
+ details->range_selection_base_icon = details->drag_icon;
+ selection_changed = select_one_unselect_others
+ (container, details->drag_icon);
+
+ if (selection_changed)
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ }
+ }
+
+ if (details->drag_icon != NULL &&
+ (details->single_click_mode ||
+ event->button == MIDDLE_BUTTON))
+ {
+ /* Determine click count */
+ g_object_get (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (container))),
+ "gtk-double-click-time", &double_click_time,
+ NULL);
+ current_time = g_get_monotonic_time ();
+ if (current_time - last_click_time < double_click_time * 1000)
+ {
+ click_count++;
+ }
+ else
+ {
+ click_count = 0;
+ }
+
+ /* Stash time for next compare */
+ last_click_time = current_time;
+
+ /* If single-click mode, activate the selected icons, unless modifying
+ * the selection or pressing for a very long time, or double clicking.
+ */
+
+
+ if (click_count == 0 &&
+ event->time - details->button_down_time < MAX_CLICK_TIME &&
+ !button_event_modifies_selection (event))
+ {
+ /* It's a tricky UI issue whether this should activate
+ * just the clicked item (as if it were a link), or all
+ * the selected items (as if you were issuing an "activate
+ * selection" command). For now, we're trying the activate
+ * entire selection version to see how it feels. Note that
+ * NautilusList goes the other way because its "links" seem
+ * much more link-like.
+ */
+ if (event->button == MIDDLE_BUTTON)
+ {
+ activate_selected_items_alternate (container, NULL);
+ }
+ else
+ {
+ activate_selected_items (container);
+ }
+ }
+ }
}
static gboolean
clicked_within_double_click_interval (NautilusCanvasContainer *container)
{
- static gint64 last_click_time = 0;
- static gint click_count = 0;
- gint double_click_time;
- gint64 current_time;
-
- /* Determine click count */
- g_object_get (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (container))),
- "gtk-double-click-time", &double_click_time,
- NULL);
- current_time = g_get_monotonic_time ();
- if (current_time - last_click_time < double_click_time * 1000) {
- click_count++;
- } else {
- click_count = 0;
- }
-
- /* Stash time for next compare */
- last_click_time = current_time;
-
- /* Only allow double click */
- if (click_count == 1) {
- click_count = 0;
- return TRUE;
- } else {
- return FALSE;
- }
+ static gint64 last_click_time = 0;
+ static gint click_count = 0;
+ gint double_click_time;
+ gint64 current_time;
+
+ /* Determine click count */
+ g_object_get (G_OBJECT (gtk_widget_get_settings (GTK_WIDGET (container))),
+ "gtk-double-click-time", &double_click_time,
+ NULL);
+ current_time = g_get_monotonic_time ();
+ if (current_time - last_click_time < double_click_time * 1000)
+ {
+ click_count++;
+ }
+ else
+ {
+ click_count = 0;
+ }
+
+ /* Stash time for next compare */
+ last_click_time = current_time;
+
+ /* Only allow double click */
+ if (click_count == 1)
+ {
+ click_count = 0;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
static void
clear_drag_state (NautilusCanvasContainer *container)
{
- container->details->drag_icon = NULL;
- container->details->drag_state = DRAG_STATE_INITIAL;
+ container->details->drag_icon = NULL;
+ container->details->drag_state = DRAG_STATE_INITIAL;
}
static gboolean
start_stretching (NautilusCanvasContainer *container,
- GdkEvent *event)
-{
- NautilusCanvasContainerDetails *details;
- NautilusCanvasIcon *icon;
- GtkWidget *toplevel;
- GdkDisplay *display;
- GtkCornerType corner;
- GdkCursor *cursor;
-
- details = container->details;
- icon = details->stretch_icon;
- display = gtk_widget_get_display (GTK_WIDGET (container));
-
- /* Check if we hit the stretch handles. */
- if (!nautilus_canvas_item_hit_test_stretch_handles (icon->item,
- details->drag_x, details->drag_y,
- &corner)) {
- return FALSE;
- }
-
- switch (corner) {
- case GTK_CORNER_TOP_LEFT:
- cursor = gdk_cursor_new_for_display (display, GDK_TOP_LEFT_CORNER);
- break;
- case GTK_CORNER_BOTTOM_LEFT:
- cursor = gdk_cursor_new_for_display (display,GDK_BOTTOM_LEFT_CORNER);
- break;
- case GTK_CORNER_TOP_RIGHT:
- cursor = gdk_cursor_new_for_display (display,GDK_TOP_RIGHT_CORNER);
- break;
- case GTK_CORNER_BOTTOM_RIGHT:
- cursor = gdk_cursor_new_for_display (display,GDK_BOTTOM_RIGHT_CORNER);
- break;
- default:
- cursor = NULL;
- break;
- }
- /* Set up the dragging. */
- details->drag_state = DRAG_STATE_STRETCH;
- eel_canvas_w2c (EEL_CANVAS (container),
- details->drag_x,
- details->drag_y,
- &details->stretch_start.pointer_x,
- &details->stretch_start.pointer_y);
- eel_canvas_w2c (EEL_CANVAS (container),
- icon->x, icon->y,
- &details->stretch_start.icon_x,
- &details->stretch_start.icon_y);
- icon_get_size (container, icon,
- &details->stretch_start.icon_size);
-
- eel_canvas_item_grab (EEL_CANVAS_ITEM (icon->item),
- (GDK_POINTER_MOTION_MASK
- | GDK_BUTTON_RELEASE_MASK),
- cursor,
- event);
- if (cursor)
- g_object_unref (cursor);
-
- /* Ensure the window itself is focused.. */
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
- if (toplevel != NULL && gtk_widget_get_realized (toplevel)) {
- gdk_window_focus (gtk_widget_get_window (toplevel), GDK_CURRENT_TIME);
- }
-
- return TRUE;
+ GdkEvent *event)
+{
+ NautilusCanvasContainerDetails *details;
+ NautilusCanvasIcon *icon;
+ GtkWidget *toplevel;
+ GdkDisplay *display;
+ GtkCornerType corner;
+ GdkCursor *cursor;
+
+ details = container->details;
+ icon = details->stretch_icon;
+ display = gtk_widget_get_display (GTK_WIDGET (container));
+
+ /* Check if we hit the stretch handles. */
+ if (!nautilus_canvas_item_hit_test_stretch_handles (icon->item,
+ details->drag_x, details->drag_y,
+ &corner))
+ {
+ return FALSE;
+ }
+
+ switch (corner)
+ {
+ case GTK_CORNER_TOP_LEFT:
+ {
+ cursor = gdk_cursor_new_for_display (display, GDK_TOP_LEFT_CORNER);
+ }
+ break;
+
+ case GTK_CORNER_BOTTOM_LEFT:
+ {
+ cursor = gdk_cursor_new_for_display (display, GDK_BOTTOM_LEFT_CORNER);
+ }
+ break;
+
+ case GTK_CORNER_TOP_RIGHT:
+ {
+ cursor = gdk_cursor_new_for_display (display, GDK_TOP_RIGHT_CORNER);
+ }
+ break;
+
+ case GTK_CORNER_BOTTOM_RIGHT:
+ {
+ cursor = gdk_cursor_new_for_display (display, GDK_BOTTOM_RIGHT_CORNER);
+ }
+ break;
+
+ default:
+ {
+ cursor = NULL;
+ }
+ break;
+ }
+ /* Set up the dragging. */
+ details->drag_state = DRAG_STATE_STRETCH;
+ eel_canvas_w2c (EEL_CANVAS (container),
+ details->drag_x,
+ details->drag_y,
+ &details->stretch_start.pointer_x,
+ &details->stretch_start.pointer_y);
+ eel_canvas_w2c (EEL_CANVAS (container),
+ icon->x, icon->y,
+ &details->stretch_start.icon_x,
+ &details->stretch_start.icon_y);
+ icon_get_size (container, icon,
+ &details->stretch_start.icon_size);
+
+ eel_canvas_item_grab (EEL_CANVAS_ITEM (icon->item),
+ (GDK_POINTER_MOTION_MASK
+ | GDK_BUTTON_RELEASE_MASK),
+ cursor,
+ event);
+ if (cursor)
+ {
+ g_object_unref (cursor);
+ }
+
+ /* Ensure the window itself is focused.. */
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (container));
+ if (toplevel != NULL && gtk_widget_get_realized (toplevel))
+ {
+ gdk_window_focus (gtk_widget_get_window (toplevel), GDK_CURRENT_TIME);
+ }
+
+ return TRUE;
}
static gboolean
update_stretch_at_idle (NautilusCanvasContainer *container)
{
- NautilusCanvasContainerDetails *details;
- NautilusCanvasIcon *icon;
- double world_x, world_y;
- StretchState stretch_state;
+ NautilusCanvasContainerDetails *details;
+ NautilusCanvasIcon *icon;
+ double world_x, world_y;
+ StretchState stretch_state;
- details = container->details;
- icon = details->stretch_icon;
+ details = container->details;
+ icon = details->stretch_icon;
- if (icon == NULL) {
- container->details->stretch_idle_id = 0;
- return FALSE;
- }
+ if (icon == NULL)
+ {
+ container->details->stretch_idle_id = 0;
+ return FALSE;
+ }
- eel_canvas_w2c (EEL_CANVAS (container),
- details->world_x, details->world_y,
- &stretch_state.pointer_x, &stretch_state.pointer_y);
+ eel_canvas_w2c (EEL_CANVAS (container),
+ details->world_x, details->world_y,
+ &stretch_state.pointer_x, &stretch_state.pointer_y);
- compute_stretch (&details->stretch_start,
- &stretch_state);
+ compute_stretch (&details->stretch_start,
+ &stretch_state);
- eel_canvas_c2w (EEL_CANVAS (container),
- stretch_state.icon_x, stretch_state.icon_y,
- &world_x, &world_y);
+ eel_canvas_c2w (EEL_CANVAS (container),
+ stretch_state.icon_x, stretch_state.icon_y,
+ &world_x, &world_y);
- icon_set_position (icon, world_x, world_y);
- icon_set_size (container, icon, stretch_state.icon_size, FALSE, FALSE);
+ icon_set_position (icon, world_x, world_y);
+ icon_set_size (container, icon, stretch_state.icon_size, FALSE, FALSE);
- container->details->stretch_idle_id = 0;
+ container->details->stretch_idle_id = 0;
- return FALSE;
-}
+ return FALSE;
+}
static void
continue_stretching (NautilusCanvasContainer *container,
- double world_x, double world_y)
+ double world_x,
+ double world_y)
{
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
-
- container->details->world_x = world_x;
- container->details->world_y = world_y;
+ container->details->world_x = world_x;
+ container->details->world_y = world_y;
- if (container->details->stretch_idle_id == 0) {
- container->details->stretch_idle_id = g_idle_add ((GSourceFunc) update_stretch_at_idle, container);
- }
+ if (container->details->stretch_idle_id == 0)
+ {
+ container->details->stretch_idle_id = g_idle_add ((GSourceFunc) update_stretch_at_idle, container);
+ }
}
static gboolean
keyboard_stretching (NautilusCanvasContainer *container,
- GdkEventKey *event)
-{
- NautilusCanvasIcon *icon;
- guint size;
-
- icon = container->details->stretch_icon;
-
- if (icon == NULL || !icon->is_selected) {
- return FALSE;
- }
-
- icon_get_size (container, icon, &size);
-
- switch (event->keyval) {
- case GDK_KEY_equal:
- case GDK_KEY_plus:
- case GDK_KEY_KP_Add:
- icon_set_size (container, icon, size + 5, FALSE, FALSE);
- break;
- case GDK_KEY_minus:
- case GDK_KEY_KP_Subtract:
- icon_set_size (container, icon, size - 5, FALSE, FALSE);
- break;
- case GDK_KEY_0:
- case GDK_KEY_KP_0:
- nautilus_canvas_container_move_icon (container, icon,
- icon->x, icon->y,
- 1.0,
- FALSE, TRUE, TRUE);
- break;
- }
-
- return TRUE;
+ GdkEventKey *event)
+{
+ NautilusCanvasIcon *icon;
+ guint size;
+
+ icon = container->details->stretch_icon;
+
+ if (icon == NULL || !icon->is_selected)
+ {
+ return FALSE;
+ }
+
+ icon_get_size (container, icon, &size);
+
+ switch (event->keyval)
+ {
+ case GDK_KEY_equal:
+ case GDK_KEY_plus:
+ case GDK_KEY_KP_Add:
+ {
+ icon_set_size (container, icon, size + 5, FALSE, FALSE);
+ }
+ break;
+
+ case GDK_KEY_minus:
+ case GDK_KEY_KP_Subtract:
+ {
+ icon_set_size (container, icon, size - 5, FALSE, FALSE);
+ }
+ break;
+
+ case GDK_KEY_0:
+ case GDK_KEY_KP_0:
+ {
+ nautilus_canvas_container_move_icon (container, icon,
+ icon->x, icon->y,
+ 1.0,
+ FALSE, TRUE, TRUE);
+ }
+ break;
+ }
+
+ return TRUE;
}
static void
ungrab_stretch_icon (NautilusCanvasContainer *container)
{
- eel_canvas_item_ungrab (EEL_CANVAS_ITEM (container->details->stretch_icon->item));
+ eel_canvas_item_ungrab (EEL_CANVAS_ITEM (container->details->stretch_icon->item));
}
static void
end_stretching (NautilusCanvasContainer *container,
- double world_x, double world_y)
-{
- NautilusCanvasPosition position;
- NautilusCanvasIcon *icon;
-
- continue_stretching (container, world_x, world_y);
- ungrab_stretch_icon (container);
-
- /* now that we're done stretching, update the icon's position */
-
- icon = container->details->drag_icon;
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- position.x = icon->saved_ltr_x = get_mirror_x_position (container, icon, icon->x);
- } else {
- position.x = icon->x;
- }
- position.y = icon->y;
- position.scale = icon->scale;
- g_signal_emit (container,
- signals[ICON_POSITION_CHANGED], 0,
- icon->data, &position);
-
- clear_drag_state (container);
- redo_layout (container);
+ double world_x,
+ double world_y)
+{
+ NautilusCanvasPosition position;
+ NautilusCanvasIcon *icon;
+
+ continue_stretching (container, world_x, world_y);
+ ungrab_stretch_icon (container);
+
+ /* now that we're done stretching, update the icon's position */
+
+ icon = container->details->drag_icon;
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ position.x = icon->saved_ltr_x = get_mirror_x_position (container, icon, icon->x);
+ }
+ else
+ {
+ position.x = icon->x;
+ }
+ position.y = icon->y;
+ position.scale = icon->scale;
+ g_signal_emit (container,
+ signals[ICON_POSITION_CHANGED], 0,
+ icon->data, &position);
+
+ clear_drag_state (container);
+ redo_layout (container);
}
static gboolean
undo_stretching (NautilusCanvasContainer *container)
{
- NautilusCanvasIcon *stretched_icon;
-
- stretched_icon = container->details->stretch_icon;
-
- if (stretched_icon == NULL) {
- return FALSE;
- }
-
- if (container->details->drag_state == DRAG_STATE_STRETCH) {
- ungrab_stretch_icon (container);
- clear_drag_state (container);
- }
- nautilus_canvas_item_set_show_stretch_handles
- (stretched_icon->item, FALSE);
-
- icon_set_position (stretched_icon,
- container->details->stretch_initial_x,
- container->details->stretch_initial_y);
- icon_set_size (container,
- stretched_icon,
- container->details->stretch_initial_size,
- TRUE,
- TRUE);
-
- container->details->stretch_icon = NULL;
- emit_stretch_ended (container, stretched_icon);
- redo_layout (container);
-
- return TRUE;
+ NautilusCanvasIcon *stretched_icon;
+
+ stretched_icon = container->details->stretch_icon;
+
+ if (stretched_icon == NULL)
+ {
+ return FALSE;
+ }
+
+ if (container->details->drag_state == DRAG_STATE_STRETCH)
+ {
+ ungrab_stretch_icon (container);
+ clear_drag_state (container);
+ }
+ nautilus_canvas_item_set_show_stretch_handles
+ (stretched_icon->item, FALSE);
+
+ icon_set_position (stretched_icon,
+ container->details->stretch_initial_x,
+ container->details->stretch_initial_y);
+ icon_set_size (container,
+ stretched_icon,
+ container->details->stretch_initial_size,
+ TRUE,
+ TRUE);
+
+ container->details->stretch_icon = NULL;
+ emit_stretch_ended (container, stretched_icon);
+ redo_layout (container);
+
+ return TRUE;
}
static gboolean
-button_release_event (GtkWidget *widget,
- GdkEventButton *event)
-{
- NautilusCanvasContainer *container;
- NautilusCanvasContainerDetails *details;
- double world_x, world_y;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- details = container->details;
-
- if (event->button == RUBBERBAND_BUTTON && details->rubberband_info.active) {
- stop_rubberbanding (container);
- return TRUE;
- }
-
- if (event->button == details->drag_button) {
- details->drag_button = 0;
-
- switch (details->drag_state) {
- case DRAG_STATE_MOVE_OR_COPY:
- if (!details->drag_started) {
- nautilus_canvas_container_did_not_drag (container, event);
- } else {
- nautilus_canvas_dnd_end_drag (container);
- DEBUG ("Ending drag from canvas container");
- }
- break;
- case DRAG_STATE_STRETCH:
- eel_canvas_window_to_world
- (EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
- end_stretching (container, world_x, world_y);
- break;
- default:
- break;
- }
-
- clear_drag_state (container);
- return TRUE;
- }
-
- return GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->button_release_event (widget, event);
+button_release_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ NautilusCanvasContainer *container;
+ NautilusCanvasContainerDetails *details;
+ double world_x, world_y;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ details = container->details;
+
+ if (event->button == RUBBERBAND_BUTTON && details->rubberband_info.active)
+ {
+ stop_rubberbanding (container);
+ return TRUE;
+ }
+
+ if (event->button == details->drag_button)
+ {
+ details->drag_button = 0;
+
+ switch (details->drag_state)
+ {
+ case DRAG_STATE_MOVE_OR_COPY:
+ {
+ if (!details->drag_started)
+ {
+ nautilus_canvas_container_did_not_drag (container, event);
+ }
+ else
+ {
+ nautilus_canvas_dnd_end_drag (container);
+ DEBUG ("Ending drag from canvas container");
+ }
+ }
+ break;
+
+ case DRAG_STATE_STRETCH:
+ {
+ eel_canvas_window_to_world
+ (EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
+ end_stretching (container, world_x, world_y);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ clear_drag_state (container);
+ return TRUE;
+ }
+
+ return GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->button_release_event (widget, event);
}
static int
-motion_notify_event (GtkWidget *widget,
- GdkEventMotion *event)
-{
- NautilusCanvasContainer *container;
- NautilusCanvasContainerDetails *details;
- double world_x, world_y;
- int canvas_x, canvas_y;
- GdkDragAction actions;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- details = container->details;
-
- if (details->drag_button != 0) {
- switch (details->drag_state) {
- case DRAG_STATE_MOVE_OR_COPY:
- if (details->drag_started) {
- break;
- }
-
- eel_canvas_window_to_world
- (EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
-
- if (gtk_drag_check_threshold (widget,
- details->drag_x,
- details->drag_y,
- world_x,
- world_y)) {
- details->drag_started = TRUE;
- details->drag_state = DRAG_STATE_MOVE_OR_COPY;
-
- eel_canvas_w2c (EEL_CANVAS (container),
- details->drag_x,
- details->drag_y,
- &canvas_x,
- &canvas_y);
-
- actions = GDK_ACTION_COPY
- | GDK_ACTION_MOVE
- | GDK_ACTION_LINK
- | GDK_ACTION_ASK;
-
- nautilus_canvas_dnd_begin_drag (container,
- actions,
- details->drag_button,
- event,
- canvas_x,
- canvas_y);
- DEBUG ("Beginning drag from canvas container");
- }
- break;
- case DRAG_STATE_STRETCH:
- eel_canvas_window_to_world
- (EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
- continue_stretching (container, world_x, world_y);
- break;
- default:
- break;
- }
- }
-
- return GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->motion_notify_event (widget, event);
+motion_notify_event (GtkWidget *widget,
+ GdkEventMotion *event)
+{
+ NautilusCanvasContainer *container;
+ NautilusCanvasContainerDetails *details;
+ double world_x, world_y;
+ int canvas_x, canvas_y;
+ GdkDragAction actions;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ details = container->details;
+
+ if (details->drag_button != 0)
+ {
+ switch (details->drag_state)
+ {
+ case DRAG_STATE_MOVE_OR_COPY:
+ {
+ if (details->drag_started)
+ {
+ break;
+ }
+
+ eel_canvas_window_to_world
+ (EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
+
+ if (gtk_drag_check_threshold (widget,
+ details->drag_x,
+ details->drag_y,
+ world_x,
+ world_y))
+ {
+ details->drag_started = TRUE;
+ details->drag_state = DRAG_STATE_MOVE_OR_COPY;
+
+ eel_canvas_w2c (EEL_CANVAS (container),
+ details->drag_x,
+ details->drag_y,
+ &canvas_x,
+ &canvas_y);
+
+ actions = GDK_ACTION_COPY
+ | GDK_ACTION_MOVE
+ | GDK_ACTION_LINK
+ | GDK_ACTION_ASK;
+
+ nautilus_canvas_dnd_begin_drag (container,
+ actions,
+ details->drag_button,
+ event,
+ canvas_x,
+ canvas_y);
+ DEBUG ("Beginning drag from canvas container");
+ }
+ }
+ break;
+
+ case DRAG_STATE_STRETCH:
+ {
+ eel_canvas_window_to_world
+ (EEL_CANVAS (container), event->x, event->y, &world_x, &world_y);
+ continue_stretching (container, world_x, world_y);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+ }
+
+ return GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->motion_notify_event (widget, event);
}
static void
-nautilus_canvas_container_get_icon_text (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data,
- char **editable_text,
- char **additional_text,
- gboolean include_invisible)
+nautilus_canvas_container_get_icon_text (NautilusCanvasContainer *container,
+ NautilusCanvasIconData *data,
+ char **editable_text,
+ char **additional_text,
+ gboolean include_invisible)
{
- NautilusCanvasContainerClass *klass;
+ NautilusCanvasContainerClass *klass;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
- g_assert (klass->get_icon_text != NULL);
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
+ g_assert (klass->get_icon_text != NULL);
- klass->get_icon_text (container, data, editable_text, additional_text, include_invisible);
+ klass->get_icon_text (container, data, editable_text, additional_text, include_invisible);
}
static gboolean
handle_popups (NautilusCanvasContainer *container,
- GdkEventKey *event,
- const char *signal)
+ GdkEventKey *event,
+ const char *signal)
{
- GdkEventButton button_event = { 0 };
+ GdkEventButton button_event = { 0 };
- /* ensure we clear the drag state before showing the menu */
- clear_drag_state (container);
+ /* ensure we clear the drag state before showing the menu */
+ clear_drag_state (container);
- g_signal_emit_by_name (container, signal, &button_event);
+ g_signal_emit_by_name (container, signal, &button_event);
- return TRUE;
+ return TRUE;
}
static int
-key_press_event (GtkWidget *widget,
- GdkEventKey *event)
-{
- NautilusCanvasContainer *container;
- gboolean handled;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- handled = FALSE;
-
- switch (event->keyval) {
- case GDK_KEY_Home:
- case GDK_KEY_KP_Home:
- keyboard_home (container, event);
- handled = TRUE;
- break;
- case GDK_KEY_End:
- case GDK_KEY_KP_End:
- keyboard_end (container, event);
- handled = TRUE;
- break;
- case GDK_KEY_Left:
- case GDK_KEY_KP_Left:
- /* Don't eat Alt-Left, as that is used for history browsing */
- if ((event->state & GDK_MOD1_MASK) == 0) {
- keyboard_left (container, event);
- handled = TRUE;
- }
- break;
- case GDK_KEY_Up:
- case GDK_KEY_KP_Up:
- /* Don't eat Alt-Up, as that is used for alt-shift-Up */
- if ((event->state & GDK_MOD1_MASK) == 0) {
- keyboard_up (container, event);
- handled = TRUE;
- }
- break;
- case GDK_KEY_Right:
- case GDK_KEY_KP_Right:
- /* Don't eat Alt-Right, as that is used for history browsing */
- if ((event->state & GDK_MOD1_MASK) == 0) {
- keyboard_right (container, event);
- handled = TRUE;
- }
- break;
- case GDK_KEY_Down:
- case GDK_KEY_KP_Down:
- /* Don't eat Alt-Down, as that is used for Open */
- if ((event->state & GDK_MOD1_MASK) == 0) {
- keyboard_down (container, event);
- handled = TRUE;
- }
- break;
- case GDK_KEY_space:
- keyboard_space (container, event);
- handled = TRUE;
- break;
- case GDK_KEY_Return:
- case GDK_KEY_KP_Enter:
- if ((event->state & GDK_SHIFT_MASK) != 0) {
- activate_selected_items_alternate (container, NULL);
- } else {
- activate_selected_items (container);
- }
-
- handled = TRUE;
- break;
- case GDK_KEY_Escape:
- handled = undo_stretching (container);
- break;
- case GDK_KEY_plus:
- case GDK_KEY_minus:
- case GDK_KEY_equal:
- case GDK_KEY_KP_Add:
- case GDK_KEY_KP_Subtract:
- case GDK_KEY_0:
- case GDK_KEY_KP_0:
- if (event->state & GDK_CONTROL_MASK) {
- handled = keyboard_stretching (container, event);
- }
- break;
- case GDK_KEY_F10:
- /* handle Ctrl+F10 because we want to display the
- * background popup even if something is selected.
- * The other cases are handled by popup_menu().
- */
- if (event->state & GDK_CONTROL_MASK) {
- handled = handle_popups (container, event,
- "context_click_background");
- }
- break;
- case GDK_KEY_v:
- /* Eat Control + v to not enable type ahead */
- if ((event->state & GDK_CONTROL_MASK) != 0) {
- handled = TRUE;
- }
- break;
- default:
- break;
- }
-
- if (!handled) {
- handled = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->key_press_event (widget, event);
- }
-
- return handled;
+key_press_event (GtkWidget *widget,
+ GdkEventKey *event)
+{
+ NautilusCanvasContainer *container;
+ gboolean handled;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ handled = FALSE;
+
+ switch (event->keyval)
+ {
+ case GDK_KEY_Home:
+ case GDK_KEY_KP_Home:
+ {
+ keyboard_home (container, event);
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_End:
+ case GDK_KEY_KP_End:
+ {
+ keyboard_end (container, event);
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_Left:
+ case GDK_KEY_KP_Left:
+ {
+ /* Don't eat Alt-Left, as that is used for history browsing */
+ if ((event->state & GDK_MOD1_MASK) == 0)
+ {
+ keyboard_left (container, event);
+ handled = TRUE;
+ }
+ }
+ break;
+
+ case GDK_KEY_Up:
+ case GDK_KEY_KP_Up:
+ {
+ /* Don't eat Alt-Up, as that is used for alt-shift-Up */
+ if ((event->state & GDK_MOD1_MASK) == 0)
+ {
+ keyboard_up (container, event);
+ handled = TRUE;
+ }
+ }
+ break;
+
+ case GDK_KEY_Right:
+ case GDK_KEY_KP_Right:
+ {
+ /* Don't eat Alt-Right, as that is used for history browsing */
+ if ((event->state & GDK_MOD1_MASK) == 0)
+ {
+ keyboard_right (container, event);
+ handled = TRUE;
+ }
+ }
+ break;
+
+ case GDK_KEY_Down:
+ case GDK_KEY_KP_Down:
+ {
+ /* Don't eat Alt-Down, as that is used for Open */
+ if ((event->state & GDK_MOD1_MASK) == 0)
+ {
+ keyboard_down (container, event);
+ handled = TRUE;
+ }
+ }
+ break;
+
+ case GDK_KEY_space:
+ {
+ keyboard_space (container, event);
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ {
+ if ((event->state & GDK_SHIFT_MASK) != 0)
+ {
+ activate_selected_items_alternate (container, NULL);
+ }
+ else
+ {
+ activate_selected_items (container);
+ }
+
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_Escape:
+ {
+ handled = undo_stretching (container);
+ }
+ break;
+
+ case GDK_KEY_plus:
+ case GDK_KEY_minus:
+ case GDK_KEY_equal:
+ case GDK_KEY_KP_Add:
+ case GDK_KEY_KP_Subtract:
+ case GDK_KEY_0:
+ case GDK_KEY_KP_0:
+ {
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ handled = keyboard_stretching (container, event);
+ }
+ }
+ break;
+
+ case GDK_KEY_F10:
+ {
+ /* handle Ctrl+F10 because we want to display the
+ * background popup even if something is selected.
+ * The other cases are handled by popup_menu().
+ */
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ handled = handle_popups (container, event,
+ "context_click_background");
+ }
+ }
+ break;
+
+ case GDK_KEY_v:
+ {
+ /* Eat Control + v to not enable type ahead */
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ handled = TRUE;
+ }
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ if (!handled)
+ {
+ handled = GTK_WIDGET_CLASS (nautilus_canvas_container_parent_class)->key_press_event (widget, event);
+ }
+
+ return handled;
}
static gboolean
popup_menu (GtkWidget *widget)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- if (has_selection (container)) {
- handle_popups (container, NULL,
- "context_click_selection");
- } else {
- handle_popups (container, NULL,
- "context_click_background");
- }
+ if (has_selection (container))
+ {
+ handle_popups (container, NULL,
+ "context_click_selection");
+ }
+ else
+ {
+ handle_popups (container, NULL,
+ "context_click_background");
+ }
- return TRUE;
+ return TRUE;
}
static void
-grab_notify_cb (GtkWidget *widget,
- gboolean was_grabbed)
+grab_notify_cb (GtkWidget *widget,
+ gboolean was_grabbed)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- if (container->details->rubberband_info.active &&
- !was_grabbed) {
- /* we got a (un)grab-notify during rubberband.
- * This happens when a new modal dialog shows
- * up (e.g. authentication or an error). Stop
- * the rubberbanding so that we can handle the
- * dialog. */
- stop_rubberbanding (container);
- }
+ if (container->details->rubberband_info.active &&
+ !was_grabbed)
+ {
+ /* we got a (un)grab-notify during rubberband.
+ * This happens when a new modal dialog shows
+ * up (e.g. authentication or an error). Stop
+ * the rubberbanding so that we can handle the
+ * dialog. */
+ stop_rubberbanding (container);
+ }
}
static void
text_ellipsis_limit_changed_container_callback (gpointer callback_data)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (callback_data);
- invalidate_label_sizes (container);
- schedule_redo_layout (container);
+ container = NAUTILUS_CANVAS_CONTAINER (callback_data);
+ invalidate_label_sizes (container);
+ schedule_redo_layout (container);
}
-static GObject*
+static GObject *
nautilus_canvas_container_constructor (GType type,
- guint n_construct_params,
- GObjectConstructParam *construct_params)
-{
- NautilusCanvasContainer *container;
- GObject *object;
-
- object = G_OBJECT_CLASS (nautilus_canvas_container_parent_class)->constructor
- (type,
- n_construct_params,
- construct_params);
-
- container = NAUTILUS_CANVAS_CONTAINER (object);
- if (nautilus_canvas_container_get_is_desktop (container)) {
- g_signal_connect_swapped (nautilus_desktop_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
- G_CALLBACK (text_ellipsis_limit_changed_container_callback),
- container);
- } else {
- g_signal_connect_swapped (nautilus_icon_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
- G_CALLBACK (text_ellipsis_limit_changed_container_callback),
- container);
- }
-
- return object;
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ NautilusCanvasContainer *container;
+ GObject *object;
+
+ object = G_OBJECT_CLASS (nautilus_canvas_container_parent_class)->constructor
+ (type,
+ n_construct_params,
+ construct_params);
+
+ container = NAUTILUS_CANVAS_CONTAINER (object);
+ if (nautilus_canvas_container_get_is_desktop (container))
+ {
+ g_signal_connect_swapped (nautilus_desktop_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
+ G_CALLBACK (text_ellipsis_limit_changed_container_callback),
+ container);
+ }
+ else
+ {
+ g_signal_connect_swapped (nautilus_icon_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
+ G_CALLBACK (text_ellipsis_limit_changed_container_callback),
+ container);
+ }
+
+ return object;
}
/* Initialization. */
@@ -4730,401 +5322,407 @@ nautilus_canvas_container_constructor (GType type,
static void
nautilus_canvas_container_class_init (NautilusCanvasContainerClass *class)
{
- GtkWidgetClass *widget_class;
-
- G_OBJECT_CLASS (class)->constructor = nautilus_canvas_container_constructor;
- G_OBJECT_CLASS (class)->finalize = finalize;
-
- /* Signals. */
-
- signals[SELECTION_CHANGED]
- = g_signal_new ("selection-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- selection_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[BUTTON_PRESS]
- = g_signal_new ("button-press",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- button_press),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_BOOLEAN, 1,
- GDK_TYPE_EVENT);
- signals[ACTIVATE]
- = g_signal_new ("activate",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- activate),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[ACTIVATE_ALTERNATE]
- = g_signal_new ("activate-alternate",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- activate_alternate),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[ACTIVATE_PREVIEWER]
- = g_signal_new ("activate-previewer",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- activate_previewer),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 2,
- G_TYPE_POINTER, G_TYPE_POINTER);
- signals[CONTEXT_CLICK_SELECTION]
- = g_signal_new ("context-click-selection",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- context_click_selection),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[CONTEXT_CLICK_BACKGROUND]
- = g_signal_new ("context-click-background",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- context_click_background),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[MIDDLE_CLICK]
- = g_signal_new ("middle-click",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- middle_click),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[ICON_POSITION_CHANGED]
- = g_signal_new ("icon-position-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- icon_position_changed),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 2,
- G_TYPE_POINTER,
- G_TYPE_POINTER);
- signals[ICON_STRETCH_STARTED]
- = g_signal_new ("icon-stretch-started",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- icon_stretch_started),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[ICON_STRETCH_ENDED]
- = g_signal_new ("icon-stretch-ended",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- icon_stretch_ended),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
- signals[GET_ICON_URI]
- = g_signal_new ("get-icon-uri",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- get_icon_uri),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_STRING, 1,
- G_TYPE_POINTER);
- signals[GET_ICON_ACTIVATION_URI]
- = g_signal_new ("get-icon-activation-uri",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- get_icon_activation_uri),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_STRING, 1,
- G_TYPE_POINTER);
- signals[GET_ICON_DROP_TARGET_URI]
- = g_signal_new ("get-icon-drop-target-uri",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- get_icon_drop_target_uri),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_STRING, 1,
- G_TYPE_POINTER);
- signals[MOVE_COPY_ITEMS]
- = g_signal_new ("move-copy-items",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- move_copy_items),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 6,
- G_TYPE_POINTER,
- G_TYPE_POINTER,
- G_TYPE_POINTER,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_NETSCAPE_URL]
- = g_signal_new ("handle-netscape-url",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- handle_netscape_url),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_URI_LIST]
- = g_signal_new ("handle-uri-list",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- handle_uri_list),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_TEXT]
- = g_signal_new ("handle-text",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- handle_text),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_RAW]
- = g_signal_new ("handle-raw",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- handle_raw),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 7,
- G_TYPE_POINTER,
- G_TYPE_INT,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_HOVER] =
- g_signal_new ("handle-hover",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- handle_hover),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 1,
- G_TYPE_STRING);
- signals[GET_CONTAINER_URI]
- = g_signal_new ("get-container-uri",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- get_container_uri),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_STRING, 0);
- signals[CAN_ACCEPT_ITEM]
- = g_signal_new ("can-accept-item",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- can_accept_item),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_INT, 2,
- G_TYPE_POINTER,
- G_TYPE_STRING);
- signals[GET_STORED_ICON_POSITION]
- = g_signal_new ("get-stored-icon-position",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- get_stored_icon_position),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_BOOLEAN, 2,
- G_TYPE_POINTER,
- G_TYPE_POINTER);
- signals[GET_STORED_LAYOUT_TIMESTAMP]
- = g_signal_new ("get-stored-layout-timestamp",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- get_stored_layout_timestamp),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_BOOLEAN, 2,
- G_TYPE_POINTER,
- G_TYPE_POINTER);
- signals[STORE_LAYOUT_TIMESTAMP]
- = g_signal_new ("store-layout-timestamp",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- store_layout_timestamp),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_BOOLEAN, 2,
- G_TYPE_POINTER,
- G_TYPE_POINTER);
- signals[LAYOUT_CHANGED]
- = g_signal_new ("layout-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- layout_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[BAND_SELECT_STARTED]
- = g_signal_new ("band-select-started",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- band_select_started),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[BAND_SELECT_ENDED]
- = g_signal_new ("band-select-ended",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- band_select_ended),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[ICON_ADDED]
- = g_signal_new ("icon-added",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- icon_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals[ICON_REMOVED]
- = g_signal_new ("icon-removed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- icon_removed),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- signals[CLEARED]
- = g_signal_new ("cleared",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusCanvasContainerClass,
- cleared),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- /* GtkWidget class. */
-
- widget_class = GTK_WIDGET_CLASS (class);
- widget_class->destroy = destroy;
- widget_class->size_allocate = size_allocate;
- widget_class->get_request_mode = get_request_mode;
- widget_class->get_preferred_width = get_prefered_width;
- widget_class->get_preferred_height = get_prefered_height;
- widget_class->realize = realize;
- widget_class->unrealize = unrealize;
- widget_class->button_press_event = button_press_event;
- widget_class->button_release_event = button_release_event;
- widget_class->motion_notify_event = motion_notify_event;
- widget_class->key_press_event = key_press_event;
- widget_class->popup_menu = popup_menu;
- widget_class->style_updated = style_updated;
- widget_class->grab_notify = grab_notify_cb;
-
- gtk_widget_class_set_accessible_type (widget_class, nautilus_canvas_container_accessible_get_type ());
-
- gtk_widget_class_install_style_property (widget_class,
- g_param_spec_boolean ("activate_prelight_icon_label",
- "Activate Prelight Icon Label",
- "Whether icon labels should make use of its prelight color in prelight state",
- FALSE,
- G_PARAM_READABLE));
+ GtkWidgetClass *widget_class;
+
+ G_OBJECT_CLASS (class)->constructor = nautilus_canvas_container_constructor;
+ G_OBJECT_CLASS (class)->finalize = finalize;
+
+ /* Signals. */
+
+ signals[SELECTION_CHANGED]
+ = g_signal_new ("selection-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ selection_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[BUTTON_PRESS]
+ = g_signal_new ("button-press",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ button_press),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 1,
+ GDK_TYPE_EVENT);
+ signals[ACTIVATE]
+ = g_signal_new ("activate",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ activate),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[ACTIVATE_ALTERNATE]
+ = g_signal_new ("activate-alternate",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ activate_alternate),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[ACTIVATE_PREVIEWER]
+ = g_signal_new ("activate-previewer",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ activate_previewer),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2,
+ G_TYPE_POINTER, G_TYPE_POINTER);
+ signals[CONTEXT_CLICK_SELECTION]
+ = g_signal_new ("context-click-selection",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ context_click_selection),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[CONTEXT_CLICK_BACKGROUND]
+ = g_signal_new ("context-click-background",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ context_click_background),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[MIDDLE_CLICK]
+ = g_signal_new ("middle-click",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ middle_click),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[ICON_POSITION_CHANGED]
+ = g_signal_new ("icon-position-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ icon_position_changed),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER);
+ signals[ICON_STRETCH_STARTED]
+ = g_signal_new ("icon-stretch-started",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ icon_stretch_started),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[ICON_STRETCH_ENDED]
+ = g_signal_new ("icon-stretch-ended",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ icon_stretch_ended),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+ signals[GET_ICON_URI]
+ = g_signal_new ("get-icon-uri",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ get_icon_uri),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_STRING, 1,
+ G_TYPE_POINTER);
+ signals[GET_ICON_ACTIVATION_URI]
+ = g_signal_new ("get-icon-activation-uri",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ get_icon_activation_uri),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_STRING, 1,
+ G_TYPE_POINTER);
+ signals[GET_ICON_DROP_TARGET_URI]
+ = g_signal_new ("get-icon-drop-target-uri",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ get_icon_drop_target_uri),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_STRING, 1,
+ G_TYPE_POINTER);
+ signals[MOVE_COPY_ITEMS]
+ = g_signal_new ("move-copy-items",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ move_copy_items),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 6,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_NETSCAPE_URL]
+ = g_signal_new ("handle-netscape-url",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ handle_netscape_url),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_URI_LIST]
+ = g_signal_new ("handle-uri-list",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ handle_uri_list),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_TEXT]
+ = g_signal_new ("handle-text",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ handle_text),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_RAW]
+ = g_signal_new ("handle-raw",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ handle_raw),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 7,
+ G_TYPE_POINTER,
+ G_TYPE_INT,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_HOVER] =
+ g_signal_new ("handle-hover",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ handle_hover),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
+ signals[GET_CONTAINER_URI]
+ = g_signal_new ("get-container-uri",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ get_container_uri),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_STRING, 0);
+ signals[CAN_ACCEPT_ITEM]
+ = g_signal_new ("can-accept-item",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ can_accept_item),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_INT, 2,
+ G_TYPE_POINTER,
+ G_TYPE_STRING);
+ signals[GET_STORED_ICON_POSITION]
+ = g_signal_new ("get-stored-icon-position",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ get_stored_icon_position),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 2,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER);
+ signals[GET_STORED_LAYOUT_TIMESTAMP]
+ = g_signal_new ("get-stored-layout-timestamp",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ get_stored_layout_timestamp),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 2,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER);
+ signals[STORE_LAYOUT_TIMESTAMP]
+ = g_signal_new ("store-layout-timestamp",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ store_layout_timestamp),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_BOOLEAN, 2,
+ G_TYPE_POINTER,
+ G_TYPE_POINTER);
+ signals[LAYOUT_CHANGED]
+ = g_signal_new ("layout-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ layout_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[BAND_SELECT_STARTED]
+ = g_signal_new ("band-select-started",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ band_select_started),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[BAND_SELECT_ENDED]
+ = g_signal_new ("band-select-ended",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ band_select_ended),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[ICON_ADDED]
+ = g_signal_new ("icon-added",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ icon_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+ signals[ICON_REMOVED]
+ = g_signal_new ("icon-removed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ icon_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ signals[CLEARED]
+ = g_signal_new ("cleared",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusCanvasContainerClass,
+ cleared),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /* GtkWidget class. */
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->destroy = destroy;
+ widget_class->size_allocate = size_allocate;
+ widget_class->get_request_mode = get_request_mode;
+ widget_class->get_preferred_width = get_prefered_width;
+ widget_class->get_preferred_height = get_prefered_height;
+ widget_class->realize = realize;
+ widget_class->unrealize = unrealize;
+ widget_class->button_press_event = button_press_event;
+ widget_class->button_release_event = button_release_event;
+ widget_class->motion_notify_event = motion_notify_event;
+ widget_class->key_press_event = key_press_event;
+ widget_class->popup_menu = popup_menu;
+ widget_class->style_updated = style_updated;
+ widget_class->grab_notify = grab_notify_cb;
+
+ gtk_widget_class_set_accessible_type (widget_class, nautilus_canvas_container_accessible_get_type ());
+
+ gtk_widget_class_install_style_property (widget_class,
+ g_param_spec_boolean ("activate_prelight_icon_label",
+ "Activate Prelight Icon Label",
+ "Whether icon labels should make use of its prelight color in prelight state",
+ FALSE,
+ G_PARAM_READABLE));
}
static void
update_selected (NautilusCanvasContainer *container)
{
- GList *node;
- NautilusCanvasIcon *icon;
-
- for (node = container->details->icons; node != NULL; node = node->next) {
- icon = node->data;
- if (icon->is_selected) {
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (icon->item));
- }
- }
+ GList *node;
+ NautilusCanvasIcon *icon;
+
+ for (node = container->details->icons; node != NULL; node = node->next)
+ {
+ icon = node->data;
+ if (icon->is_selected)
+ {
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (icon->item));
+ }
+ }
}
static gboolean
-handle_focus_in_event (GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
+handle_focus_in_event (GtkWidget *widget,
+ GdkEventFocus *event,
+ gpointer user_data)
{
- update_selected (NAUTILUS_CANVAS_CONTAINER (widget));
+ update_selected (NAUTILUS_CANVAS_CONTAINER (widget));
- return FALSE;
+ return FALSE;
}
static gboolean
-handle_focus_out_event (GtkWidget *widget, GdkEventFocus *event, gpointer user_data)
+handle_focus_out_event (GtkWidget *widget,
+ GdkEventFocus *event,
+ gpointer user_data)
{
- update_selected (NAUTILUS_CANVAS_CONTAINER (widget));
+ update_selected (NAUTILUS_CANVAS_CONTAINER (widget));
- return FALSE;
+ return FALSE;
}
@@ -5132,147 +5730,161 @@ static int text_ellipsis_limits[NAUTILUS_CANVAS_ZOOM_LEVEL_N_ENTRIES];
static int desktop_text_ellipsis_limit;
static gboolean
-get_text_ellipsis_limit_for_zoom (char **strs,
- const char *zoom_level,
- int *limit)
-{
- char **p;
- char *str;
- gboolean success;
-
- success = FALSE;
-
- /* default */
- *limit = 3;
-
- if (zoom_level != NULL) {
- str = g_strdup_printf ("%s:%%d", zoom_level);
- } else {
- str = g_strdup ("%d");
- }
-
- if (strs != NULL) {
+get_text_ellipsis_limit_for_zoom (char **strs,
+ const char *zoom_level,
+ int *limit)
+{
+ char **p;
+ char *str;
+ gboolean success;
+
+ success = FALSE;
+
+ /* default */
+ *limit = 3;
+
+ if (zoom_level != NULL)
+ {
+ str = g_strdup_printf ("%s:%%d", zoom_level);
+ }
+ else
+ {
+ str = g_strdup ("%d");
+ }
+
+ if (strs != NULL)
+ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
- for (p = strs; *p != NULL; p++) {
- if (sscanf (*p, str, limit)) {
- success = TRUE;
- }
- }
+ for (p = strs; *p != NULL; p++)
+ {
+ if (sscanf (*p, str, limit))
+ {
+ success = TRUE;
+ }
+ }
#pragma GCC diagnostic pop
- }
+ }
- g_free (str);
+ g_free (str);
- return success;
+ return success;
}
-static const char * zoom_level_names[] = {
- "small",
- "standard",
- "large",
+static const char *zoom_level_names[] =
+{
+ "small",
+ "standard",
+ "large",
};
static void
text_ellipsis_limit_changed_callback (gpointer callback_data)
{
- char **pref;
- unsigned int i;
- int one_limit;
-
- pref = g_settings_get_strv (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT);
-
- /* set default */
- get_text_ellipsis_limit_for_zoom (pref, NULL, &one_limit);
- for (i = 0; i < NAUTILUS_CANVAS_ZOOM_LEVEL_N_ENTRIES; i++) {
- text_ellipsis_limits[i] = one_limit;
- }
-
- /* override for each zoom level */
- for (i = 0; i < G_N_ELEMENTS(zoom_level_names); i++) {
- if (get_text_ellipsis_limit_for_zoom (pref,
- zoom_level_names[i],
- &one_limit)) {
- text_ellipsis_limits[i] = one_limit;
- }
- }
+ char **pref;
+ unsigned int i;
+ int one_limit;
+
+ pref = g_settings_get_strv (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT);
+
+ /* set default */
+ get_text_ellipsis_limit_for_zoom (pref, NULL, &one_limit);
+ for (i = 0; i < NAUTILUS_CANVAS_ZOOM_LEVEL_N_ENTRIES; i++)
+ {
+ text_ellipsis_limits[i] = one_limit;
+ }
+
+ /* override for each zoom level */
+ for (i = 0; i < G_N_ELEMENTS (zoom_level_names); i++)
+ {
+ if (get_text_ellipsis_limit_for_zoom (pref,
+ zoom_level_names[i],
+ &one_limit))
+ {
+ text_ellipsis_limits[i] = one_limit;
+ }
+ }
- g_strfreev (pref);
+ g_strfreev (pref);
}
static void
desktop_text_ellipsis_limit_changed_callback (gpointer callback_data)
{
- int pref;
+ int pref;
- pref = g_settings_get_int (nautilus_desktop_preferences, NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT);
- desktop_text_ellipsis_limit = pref;
+ pref = g_settings_get_int (nautilus_desktop_preferences, NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT);
+ desktop_text_ellipsis_limit = pref;
}
static void
nautilus_canvas_container_init (NautilusCanvasContainer *container)
{
- NautilusCanvasContainerDetails *details;
- static gboolean setup_prefs = FALSE;
+ NautilusCanvasContainerDetails *details;
+ static gboolean setup_prefs = FALSE;
- details = g_new0 (NautilusCanvasContainerDetails, 1);
+ details = g_new0 (NautilusCanvasContainerDetails, 1);
- details->icon_set = g_hash_table_new (g_direct_hash, g_direct_equal);
- details->layout_timestamp = UNDEFINED_TIME;
- details->zoom_level = NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD;
+ details->icon_set = g_hash_table_new (g_direct_hash, g_direct_equal);
+ details->layout_timestamp = UNDEFINED_TIME;
+ details->zoom_level = NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD;
- container->details = details;
+ container->details = details;
- g_signal_connect (container, "focus-in-event",
- G_CALLBACK (handle_focus_in_event), NULL);
- g_signal_connect (container, "focus-out-event",
- G_CALLBACK (handle_focus_out_event), NULL);
+ g_signal_connect (container, "focus-in-event",
+ G_CALLBACK (handle_focus_in_event), NULL);
+ g_signal_connect (container, "focus-out-event",
+ G_CALLBACK (handle_focus_out_event), NULL);
- if (!setup_prefs) {
- g_signal_connect_swapped (nautilus_icon_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
- G_CALLBACK (text_ellipsis_limit_changed_callback),
- NULL);
- text_ellipsis_limit_changed_callback (NULL);
+ if (!setup_prefs)
+ {
+ g_signal_connect_swapped (nautilus_icon_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
+ G_CALLBACK (text_ellipsis_limit_changed_callback),
+ NULL);
+ text_ellipsis_limit_changed_callback (NULL);
- g_signal_connect_swapped (nautilus_icon_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
- G_CALLBACK (desktop_text_ellipsis_limit_changed_callback),
- NULL);
- desktop_text_ellipsis_limit_changed_callback (NULL);
+ g_signal_connect_swapped (nautilus_icon_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
+ G_CALLBACK (desktop_text_ellipsis_limit_changed_callback),
+ NULL);
+ desktop_text_ellipsis_limit_changed_callback (NULL);
- setup_prefs = TRUE;
- }
+ setup_prefs = TRUE;
+ }
}
-typedef struct {
- NautilusCanvasContainer *container;
- GdkEventButton *event;
+typedef struct
+{
+ NautilusCanvasContainer *container;
+ GdkEventButton *event;
} ContextMenuParameters;
static gboolean
handle_canvas_double_click (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- GdkEventButton *event)
+ NautilusCanvasIcon *icon,
+ GdkEventButton *event)
{
- NautilusCanvasContainerDetails *details;
+ NautilusCanvasContainerDetails *details;
- if (event->button != DRAG_BUTTON) {
- return FALSE;
- }
+ if (event->button != DRAG_BUTTON)
+ {
+ return FALSE;
+ }
- details = container->details;
+ details = container->details;
- if (!details->single_click_mode &&
- clicked_within_double_click_interval (container) &&
- details->double_click_icon[0] == details->double_click_icon[1] &&
- details->double_click_button[0] == details->double_click_button[1]) {
- details->double_clicked = TRUE;
- return TRUE;
- }
+ if (!details->single_click_mode &&
+ clicked_within_double_click_interval (container) &&
+ details->double_click_icon[0] == details->double_click_icon[1] &&
+ details->double_click_button[0] == details->double_click_button[1])
+ {
+ details->double_clicked = TRUE;
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
/* NautilusCanvasIcon event handling. */
@@ -5288,969 +5900,1087 @@ handle_canvas_double_click (NautilusCanvasContainer *container,
static gboolean
handle_canvas_button_press (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon,
- GdkEventButton *event)
-{
- NautilusCanvasContainerDetails *details;
-
- details = container->details;
-
- if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS) {
- return TRUE;
- }
-
- if (event->button != DRAG_BUTTON
- && event->button != CONTEXTUAL_MENU_BUTTON
- && event->button != DRAG_MENU_BUTTON) {
- return TRUE;
- }
-
- if ((event->button == DRAG_BUTTON) &&
- event->type == GDK_BUTTON_PRESS) {
- /* The next double click has to be on this icon */
- details->double_click_icon[1] = details->double_click_icon[0];
- details->double_click_icon[0] = icon;
-
- details->double_click_button[1] = details->double_click_button[0];
- details->double_click_button[0] = event->button;
- }
-
- if (handle_canvas_double_click (container, icon, event)) {
- /* Double clicking does not trigger a D&D action. */
- details->drag_button = 0;
- details->drag_icon = NULL;
- return TRUE;
- }
-
- if (event->button == DRAG_BUTTON
- || event->button == DRAG_MENU_BUTTON) {
- details->drag_button = event->button;
- details->drag_icon = icon;
- details->drag_x = event->x;
- details->drag_y = event->y;
- details->drag_state = DRAG_STATE_MOVE_OR_COPY;
- details->drag_started = FALSE;
-
- /* Check to see if this is a click on the stretch handles.
- * If so, it won't modify the selection.
- */
- if (icon == container->details->stretch_icon) {
- if (start_stretching (container, (GdkEvent *)event)) {
- return TRUE;
- }
- }
- }
-
- /* Modify the selection as appropriate. Selection is modified
- * the same way for contextual menu as it would be without.
- */
- details->icon_selected_on_button_down = icon->is_selected;
-
- if ((event->button == DRAG_BUTTON || event->button == MIDDLE_BUTTON) &&
- (event->state & GDK_SHIFT_MASK) != 0) {
- NautilusCanvasIcon *start_icon;
-
- set_focus (container, icon, FALSE);
-
- start_icon = details->range_selection_base_icon;
- if (start_icon == NULL || !start_icon->is_selected) {
- start_icon = icon;
- details->range_selection_base_icon = icon;
- }
- if (select_range (container, start_icon, icon,
- (event->state & GDK_CONTROL_MASK) == 0)) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
- } else if (!details->icon_selected_on_button_down) {
- set_focus (container, icon, FALSE);
-
- details->range_selection_base_icon = icon;
- if (button_event_modifies_selection (event)) {
- icon_toggle_selected (container, icon);
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- } else {
- select_one_unselect_others (container, icon);
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
- }
-
- if (event->button == CONTEXTUAL_MENU_BUTTON) {
- clear_drag_state (container);
-
- g_signal_emit (container,
- signals[CONTEXT_CLICK_SELECTION], 0,
- event);
- }
-
-
- return TRUE;
+ NautilusCanvasIcon *icon,
+ GdkEventButton *event)
+{
+ NautilusCanvasContainerDetails *details;
+
+ details = container->details;
+
+ if (event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
+ {
+ return TRUE;
+ }
+
+ if (event->button != DRAG_BUTTON
+ && event->button != CONTEXTUAL_MENU_BUTTON
+ && event->button != DRAG_MENU_BUTTON)
+ {
+ return TRUE;
+ }
+
+ if ((event->button == DRAG_BUTTON) &&
+ event->type == GDK_BUTTON_PRESS)
+ {
+ /* The next double click has to be on this icon */
+ details->double_click_icon[1] = details->double_click_icon[0];
+ details->double_click_icon[0] = icon;
+
+ details->double_click_button[1] = details->double_click_button[0];
+ details->double_click_button[0] = event->button;
+ }
+
+ if (handle_canvas_double_click (container, icon, event))
+ {
+ /* Double clicking does not trigger a D&D action. */
+ details->drag_button = 0;
+ details->drag_icon = NULL;
+ return TRUE;
+ }
+
+ if (event->button == DRAG_BUTTON
+ || event->button == DRAG_MENU_BUTTON)
+ {
+ details->drag_button = event->button;
+ details->drag_icon = icon;
+ details->drag_x = event->x;
+ details->drag_y = event->y;
+ details->drag_state = DRAG_STATE_MOVE_OR_COPY;
+ details->drag_started = FALSE;
+
+ /* Check to see if this is a click on the stretch handles.
+ * If so, it won't modify the selection.
+ */
+ if (icon == container->details->stretch_icon)
+ {
+ if (start_stretching (container, (GdkEvent *) event))
+ {
+ return TRUE;
+ }
+ }
+ }
+
+ /* Modify the selection as appropriate. Selection is modified
+ * the same way for contextual menu as it would be without.
+ */
+ details->icon_selected_on_button_down = icon->is_selected;
+
+ if ((event->button == DRAG_BUTTON || event->button == MIDDLE_BUTTON) &&
+ (event->state & GDK_SHIFT_MASK) != 0)
+ {
+ NautilusCanvasIcon *start_icon;
+
+ set_focus (container, icon, FALSE);
+
+ start_icon = details->range_selection_base_icon;
+ if (start_icon == NULL || !start_icon->is_selected)
+ {
+ start_icon = icon;
+ details->range_selection_base_icon = icon;
+ }
+ if (select_range (container, start_icon, icon,
+ (event->state & GDK_CONTROL_MASK) == 0))
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ }
+ else if (!details->icon_selected_on_button_down)
+ {
+ set_focus (container, icon, FALSE);
+
+ details->range_selection_base_icon = icon;
+ if (button_event_modifies_selection (event))
+ {
+ icon_toggle_selected (container, icon);
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ else
+ {
+ select_one_unselect_others (container, icon);
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
+ }
+
+ if (event->button == CONTEXTUAL_MENU_BUTTON)
+ {
+ clear_drag_state (container);
+
+ g_signal_emit (container,
+ signals[CONTEXT_CLICK_SELECTION], 0,
+ event);
+ }
+
+
+ return TRUE;
}
static int
item_event_callback (EelCanvasItem *item,
- GdkEvent *event,
- gpointer data)
-{
- NautilusCanvasContainer *container;
- NautilusCanvasIcon *icon;
- GdkEventButton *event_button;
-
- container = NAUTILUS_CANVAS_CONTAINER (data);
-
- icon = NAUTILUS_CANVAS_ITEM (item)->user_data;
- g_assert (icon != NULL);
-
- event_button = &event->button;
-
- switch (event->type) {
- case GDK_MOTION_NOTIFY:
- return FALSE;
- case GDK_BUTTON_PRESS:
- container->details->double_clicked = FALSE;
- if (handle_canvas_button_press (container, icon, event_button)) {
- /* Stop the event from being passed along further. Returning
- * TRUE ain't enough.
- */
- return TRUE;
- }
- return FALSE;
- case GDK_BUTTON_RELEASE:
- if (event_button->button == DRAG_BUTTON
- && container->details->double_clicked) {
- if (!button_event_modifies_selection (event_button)) {
- activate_selected_items (container);
- } else if ((event_button->state & GDK_CONTROL_MASK) == 0 &&
- (event_button->state & GDK_SHIFT_MASK) != 0) {
- activate_selected_items_alternate (container, icon);
- }
- }
- /* fall through */
- default:
- container->details->double_clicked = FALSE;
- return FALSE;
- }
+ GdkEvent *event,
+ gpointer data)
+{
+ NautilusCanvasContainer *container;
+ NautilusCanvasIcon *icon;
+ GdkEventButton *event_button;
+
+ container = NAUTILUS_CANVAS_CONTAINER (data);
+
+ icon = NAUTILUS_CANVAS_ITEM (item)->user_data;
+ g_assert (icon != NULL);
+
+ event_button = &event->button;
+
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ {
+ return FALSE;
+ }
+
+ case GDK_BUTTON_PRESS:
+ {
+ container->details->double_clicked = FALSE;
+ if (handle_canvas_button_press (container, icon, event_button))
+ {
+ /* Stop the event from being passed along further. Returning
+ * TRUE ain't enough.
+ */
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ case GDK_BUTTON_RELEASE:
+ {
+ if (event_button->button == DRAG_BUTTON
+ && container->details->double_clicked)
+ {
+ if (!button_event_modifies_selection (event_button))
+ {
+ activate_selected_items (container);
+ }
+ else if ((event_button->state & GDK_CONTROL_MASK) == 0 &&
+ (event_button->state & GDK_SHIFT_MASK) != 0)
+ {
+ activate_selected_items_alternate (container, icon);
+ }
+ }
+ /* fall through */
+ }
+
+ default:
+ container->details->double_clicked = FALSE;
+ return FALSE;
+ }
}
GtkWidget *
nautilus_canvas_container_new (void)
{
- return gtk_widget_new (NAUTILUS_TYPE_CANVAS_CONTAINER, NULL);
+ return gtk_widget_new (NAUTILUS_TYPE_CANVAS_CONTAINER, NULL);
}
/* Clear all of the icons in the container. */
void
nautilus_canvas_container_clear (NautilusCanvasContainer *container)
{
- NautilusCanvasContainerDetails *details;
- GList *p;
+ NautilusCanvasContainerDetails *details;
+ GList *p;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- details = container->details;
- details->layout_timestamp = UNDEFINED_TIME;
- details->store_layout_timestamps_when_finishing_new_icons = FALSE;
+ details = container->details;
+ details->layout_timestamp = UNDEFINED_TIME;
+ details->store_layout_timestamps_when_finishing_new_icons = FALSE;
- if (details->icons == NULL) {
- return;
- }
+ if (details->icons == NULL)
+ {
+ return;
+ }
- clear_focus (container);
- clear_keyboard_rubberband_start (container);
- unschedule_keyboard_icon_reveal (container);
- set_pending_icon_to_reveal (container, NULL);
- details->stretch_icon = NULL;
- details->drop_target = NULL;
+ clear_focus (container);
+ clear_keyboard_rubberband_start (container);
+ unschedule_keyboard_icon_reveal (container);
+ set_pending_icon_to_reveal (container, NULL);
+ details->stretch_icon = NULL;
+ details->drop_target = NULL;
- for (p = details->icons; p != NULL; p = p->next) {
- icon_free (p->data);
- }
- g_list_free (details->icons);
- details->icons = NULL;
- g_list_free (details->new_icons);
- details->new_icons = NULL;
- g_list_free (details->selection);
- details->selection = NULL;
+ for (p = details->icons; p != NULL; p = p->next)
+ {
+ icon_free (p->data);
+ }
+ g_list_free (details->icons);
+ details->icons = NULL;
+ g_list_free (details->new_icons);
+ details->new_icons = NULL;
+ g_list_free (details->selection);
+ details->selection = NULL;
- g_hash_table_destroy (details->icon_set);
- details->icon_set = g_hash_table_new (g_direct_hash, g_direct_equal);
-
- nautilus_canvas_container_update_scroll_region (container);
+ g_hash_table_destroy (details->icon_set);
+ details->icon_set = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+ nautilus_canvas_container_update_scroll_region (container);
}
gboolean
nautilus_canvas_container_is_empty (NautilusCanvasContainer *container)
{
- return container->details->icons == NULL;
+ return container->details->icons == NULL;
}
NautilusCanvasIconData *
nautilus_canvas_container_get_first_visible_icon (NautilusCanvasContainer *container)
{
- GList *l;
- NautilusCanvasIcon *icon, *best_icon;
- double x, y;
- double x1, y1, x2, y2;
- double *pos, best_pos;
- double hadj_v, vadj_v, h_page_size;
- gboolean better_icon;
- gboolean compare_lt;
-
- hadj_v = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
- vadj_v = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
- h_page_size = gtk_adjustment_get_page_size (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
-
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- x = hadj_v + h_page_size - ICON_PAD_LEFT - 1;
- y = vadj_v;
- } else {
- x = hadj_v;
- y = vadj_v;
- }
-
- eel_canvas_c2w (EEL_CANVAS (container),
- x, y,
- &x, &y);
-
- l = container->details->icons;
- best_icon = NULL;
- best_pos = 0;
- while (l != NULL) {
- icon = l->data;
-
- if (icon_is_positioned (icon)) {
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
- &x1, &y1, &x2, &y2);
-
- compare_lt = FALSE;
- if (nautilus_canvas_container_is_layout_vertical (container)) {
- pos = &x1;
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- compare_lt = TRUE;
- better_icon = x1 < x + ICON_PAD_LEFT;
- } else {
- better_icon = x2 > x + ICON_PAD_LEFT;
- }
- } else {
- pos = &y1;
- better_icon = y2 > y + ICON_PAD_TOP;
- }
- if (better_icon) {
- if (best_icon == NULL) {
- better_icon = TRUE;
- } else if (compare_lt) {
- better_icon = best_pos < *pos;
- } else {
- better_icon = best_pos > *pos;
- }
-
- if (better_icon) {
- best_icon = icon;
- best_pos = *pos;
- }
- }
- }
-
- l = l->next;
- }
-
- return best_icon ? best_icon->data : NULL;
+ GList *l;
+ NautilusCanvasIcon *icon, *best_icon;
+ double x, y;
+ double x1, y1, x2, y2;
+ double *pos, best_pos;
+ double hadj_v, vadj_v, h_page_size;
+ gboolean better_icon;
+ gboolean compare_lt;
+
+ hadj_v = gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
+ vadj_v = gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
+ h_page_size = gtk_adjustment_get_page_size (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
+
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ x = hadj_v + h_page_size - ICON_PAD_LEFT - 1;
+ y = vadj_v;
+ }
+ else
+ {
+ x = hadj_v;
+ y = vadj_v;
+ }
+
+ eel_canvas_c2w (EEL_CANVAS (container),
+ x, y,
+ &x, &y);
+
+ l = container->details->icons;
+ best_icon = NULL;
+ best_pos = 0;
+ while (l != NULL)
+ {
+ icon = l->data;
+
+ if (icon_is_positioned (icon))
+ {
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
+ &x1, &y1, &x2, &y2);
+
+ compare_lt = FALSE;
+ if (nautilus_canvas_container_is_layout_vertical (container))
+ {
+ pos = &x1;
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ compare_lt = TRUE;
+ better_icon = x1 < x + ICON_PAD_LEFT;
+ }
+ else
+ {
+ better_icon = x2 > x + ICON_PAD_LEFT;
+ }
+ }
+ else
+ {
+ pos = &y1;
+ better_icon = y2 > y + ICON_PAD_TOP;
+ }
+ if (better_icon)
+ {
+ if (best_icon == NULL)
+ {
+ better_icon = TRUE;
+ }
+ else if (compare_lt)
+ {
+ better_icon = best_pos < *pos;
+ }
+ else
+ {
+ better_icon = best_pos > *pos;
+ }
+
+ if (better_icon)
+ {
+ best_icon = icon;
+ best_pos = *pos;
+ }
+ }
+ }
+
+ l = l->next;
+ }
+
+ return best_icon ? best_icon->data : NULL;
}
/* puts the icon at the top of the screen */
void
-nautilus_canvas_container_scroll_to_canvas (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
-{
- GList *l;
- NautilusCanvasIcon *icon;
- GtkAdjustment *hadj, *vadj;
- EelIRect bounds;
- GtkAllocation allocation;
-
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
-
- /* We need to force a relayout now if there are updates queued
- * since we need the final positions */
- nautilus_canvas_container_layout_now (container);
-
- l = container->details->icons;
- while (l != NULL) {
- icon = l->data;
-
- if (icon->data == data &&
- icon_is_positioned (icon)) {
-
- if (nautilus_canvas_container_is_auto_layout (container)) {
- /* ensure that we reveal the entire row/column */
- icon_get_row_and_column_bounds (container, icon, &bounds);
- } else {
- item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), &bounds);
- }
-
- if (nautilus_canvas_container_is_layout_vertical (container)) {
- if (nautilus_canvas_container_is_layout_rtl (container)) {
- gtk_adjustment_set_value (hadj, bounds.x1 - allocation.width);
- } else {
- gtk_adjustment_set_value (hadj, bounds.x0);
- }
- } else {
- gtk_adjustment_set_value (vadj, bounds.y0);
- }
- }
-
- l = l->next;
- }
+nautilus_canvas_container_scroll_to_canvas (NautilusCanvasContainer *container,
+ NautilusCanvasIconData *data)
+{
+ GList *l;
+ NautilusCanvasIcon *icon;
+ GtkAdjustment *hadj, *vadj;
+ EelIRect bounds;
+ GtkAllocation allocation;
+
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+
+ /* We need to force a relayout now if there are updates queued
+ * since we need the final positions */
+ nautilus_canvas_container_layout_now (container);
+
+ l = container->details->icons;
+ while (l != NULL)
+ {
+ icon = l->data;
+
+ if (icon->data == data &&
+ icon_is_positioned (icon))
+ {
+ if (nautilus_canvas_container_is_auto_layout (container))
+ {
+ /* ensure that we reveal the entire row/column */
+ icon_get_row_and_column_bounds (container, icon, &bounds);
+ }
+ else
+ {
+ item_get_canvas_bounds (EEL_CANVAS_ITEM (icon->item), &bounds);
+ }
+
+ if (nautilus_canvas_container_is_layout_vertical (container))
+ {
+ if (nautilus_canvas_container_is_layout_rtl (container))
+ {
+ gtk_adjustment_set_value (hadj, bounds.x1 - allocation.width);
+ }
+ else
+ {
+ gtk_adjustment_set_value (hadj, bounds.x0);
+ }
+ }
+ else
+ {
+ gtk_adjustment_set_value (vadj, bounds.y0);
+ }
+ }
+
+ l = l->next;
+ }
}
/* Call a function for all the icons. */
-typedef struct {
- NautilusCanvasCallback callback;
- gpointer callback_data;
+typedef struct
+{
+ NautilusCanvasCallback callback;
+ gpointer callback_data;
} CallbackAndData;
static void
-call_canvas_callback (gpointer data, gpointer callback_data)
+call_canvas_callback (gpointer data,
+ gpointer callback_data)
{
- NautilusCanvasIcon *icon;
- CallbackAndData *callback_and_data;
+ NautilusCanvasIcon *icon;
+ CallbackAndData *callback_and_data;
- icon = data;
- callback_and_data = callback_data;
- (* callback_and_data->callback) (icon->data, callback_and_data->callback_data);
+ icon = data;
+ callback_and_data = callback_data;
+ (*callback_and_data->callback)(icon->data, callback_and_data->callback_data);
}
void
nautilus_canvas_container_for_each (NautilusCanvasContainer *container,
- NautilusCanvasCallback callback,
- gpointer callback_data)
+ NautilusCanvasCallback callback,
+ gpointer callback_data)
{
- CallbackAndData callback_and_data;
+ CallbackAndData callback_and_data;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- callback_and_data.callback = callback;
- callback_and_data.callback_data = callback_data;
+ callback_and_data.callback = callback;
+ callback_and_data.callback_data = callback_data;
- g_list_foreach (container->details->icons,
- call_canvas_callback, &callback_and_data);
+ g_list_foreach (container->details->icons,
+ call_canvas_callback, &callback_and_data);
}
static int
selection_changed_at_idle_callback (gpointer data)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
+
+ container = NAUTILUS_CANVAS_CONTAINER (data);
- container = NAUTILUS_CANVAS_CONTAINER (data);
-
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
- container->details->selection_changed_id = 0;
- return FALSE;
+ container->details->selection_changed_id = 0;
+ return FALSE;
}
/* utility routine to remove a single icon from the container */
static void
icon_destroy (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
-{
- NautilusCanvasContainerDetails *details;
- gboolean was_selected;
- NautilusCanvasIcon *icon_to_focus;
- GList *item;
-
- details = container->details;
-
- item = g_list_find (details->icons, icon);
- item = item->next ? item->next : item->prev;
- icon_to_focus = (item != NULL) ? item->data : NULL;
-
- details->icons = g_list_remove (details->icons, icon);
- details->new_icons = g_list_remove (details->new_icons, icon);
- details->selection = g_list_remove (details->selection, icon->data);
- g_hash_table_remove (details->icon_set, icon->data);
-
- was_selected = icon->is_selected;
-
- if (details->focus == icon ||
- details->focus == NULL) {
- if (icon_to_focus != NULL) {
- set_focus (container, icon_to_focus, TRUE);
- } else {
- clear_focus (container);
- }
- }
-
- if (details->keyboard_rubberband_start == icon) {
- clear_keyboard_rubberband_start (container);
- }
-
- if (details->keyboard_icon_to_reveal == icon) {
- unschedule_keyboard_icon_reveal (container);
- }
- if (details->drag_icon == icon) {
- clear_drag_state (container);
- }
- if (details->drop_target == icon) {
- details->drop_target = NULL;
- }
- if (details->range_selection_base_icon == icon) {
- details->range_selection_base_icon = NULL;
- }
- if (details->pending_icon_to_reveal == icon) {
- set_pending_icon_to_reveal (container, NULL);
- }
- if (details->stretch_icon == icon) {
- details->stretch_icon = NULL;
- }
-
- icon_free (icon);
-
- if (was_selected) {
- /* Coalesce multiple removals causing multiple selection_changed events */
- details->selection_changed_id = g_idle_add (selection_changed_at_idle_callback, container);
- }
+ NautilusCanvasIcon *icon)
+{
+ NautilusCanvasContainerDetails *details;
+ gboolean was_selected;
+ NautilusCanvasIcon *icon_to_focus;
+ GList *item;
+
+ details = container->details;
+
+ item = g_list_find (details->icons, icon);
+ item = item->next ? item->next : item->prev;
+ icon_to_focus = (item != NULL) ? item->data : NULL;
+
+ details->icons = g_list_remove (details->icons, icon);
+ details->new_icons = g_list_remove (details->new_icons, icon);
+ details->selection = g_list_remove (details->selection, icon->data);
+ g_hash_table_remove (details->icon_set, icon->data);
+
+ was_selected = icon->is_selected;
+
+ if (details->focus == icon ||
+ details->focus == NULL)
+ {
+ if (icon_to_focus != NULL)
+ {
+ set_focus (container, icon_to_focus, TRUE);
+ }
+ else
+ {
+ clear_focus (container);
+ }
+ }
+
+ if (details->keyboard_rubberband_start == icon)
+ {
+ clear_keyboard_rubberband_start (container);
+ }
+
+ if (details->keyboard_icon_to_reveal == icon)
+ {
+ unschedule_keyboard_icon_reveal (container);
+ }
+ if (details->drag_icon == icon)
+ {
+ clear_drag_state (container);
+ }
+ if (details->drop_target == icon)
+ {
+ details->drop_target = NULL;
+ }
+ if (details->range_selection_base_icon == icon)
+ {
+ details->range_selection_base_icon = NULL;
+ }
+ if (details->pending_icon_to_reveal == icon)
+ {
+ set_pending_icon_to_reveal (container, NULL);
+ }
+ if (details->stretch_icon == icon)
+ {
+ details->stretch_icon = NULL;
+ }
+
+ icon_free (icon);
+
+ if (was_selected)
+ {
+ /* Coalesce multiple removals causing multiple selection_changed events */
+ details->selection_changed_id = g_idle_add (selection_changed_at_idle_callback, container);
+ }
}
/* activate any selected items in the container */
static void
activate_selected_items (NautilusCanvasContainer *container)
{
- GList *selection;
+ GList *selection;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- selection = nautilus_canvas_container_get_selection (container);
- if (selection != NULL) {
- g_signal_emit (container,
- signals[ACTIVATE], 0,
- selection);
- }
- g_list_free (selection);
+ selection = nautilus_canvas_container_get_selection (container);
+ if (selection != NULL)
+ {
+ g_signal_emit (container,
+ signals[ACTIVATE], 0,
+ selection);
+ }
+ g_list_free (selection);
}
static void
preview_selected_items (NautilusCanvasContainer *container)
{
- GList *selection;
- GArray *locations;
- gint idx;
+ GList *selection;
+ GArray *locations;
+ gint idx;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- selection = nautilus_canvas_container_get_selection (container);
- locations = nautilus_canvas_container_get_selected_icon_locations (container);
+ selection = nautilus_canvas_container_get_selection (container);
+ locations = nautilus_canvas_container_get_selected_icon_locations (container);
- for (idx = 0; idx < locations->len; idx++) {
- GdkPoint *point = &(g_array_index (locations, GdkPoint, idx));
- gint scroll_x, scroll_y;
+ for (idx = 0; idx < locations->len; idx++)
+ {
+ GdkPoint *point = &(g_array_index (locations, GdkPoint, idx));
+ gint scroll_x, scroll_y;
- eel_canvas_get_scroll_offsets (EEL_CANVAS (container),
- &scroll_x, &scroll_y);
+ eel_canvas_get_scroll_offsets (EEL_CANVAS (container),
+ &scroll_x, &scroll_y);
- point->x -= scroll_x;
- point->y -= scroll_y;
- }
+ point->x -= scroll_x;
+ point->y -= scroll_y;
+ }
- if (selection != NULL) {
- g_signal_emit (container,
- signals[ACTIVATE_PREVIEWER], 0,
- selection, locations);
- }
- g_list_free (selection);
- g_array_unref (locations);
+ if (selection != NULL)
+ {
+ g_signal_emit (container,
+ signals[ACTIVATE_PREVIEWER], 0,
+ selection, locations);
+ }
+ g_list_free (selection);
+ g_array_unref (locations);
}
static void
activate_selected_items_alternate (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- GList *selection;
+ GList *selection;
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- if (icon != NULL) {
- selection = g_list_prepend (NULL, icon->data);
- } else {
- selection = nautilus_canvas_container_get_selection (container);
- }
- if (selection != NULL) {
- g_signal_emit (container,
- signals[ACTIVATE_ALTERNATE], 0,
- selection);
- }
- g_list_free (selection);
+ if (icon != NULL)
+ {
+ selection = g_list_prepend (NULL, icon->data);
+ }
+ else
+ {
+ selection = nautilus_canvas_container_get_selection (container);
+ }
+ if (selection != NULL)
+ {
+ g_signal_emit (container,
+ signals[ACTIVATE_ALTERNATE], 0,
+ selection);
+ }
+ g_list_free (selection);
}
static NautilusIconInfo *
nautilus_canvas_container_get_icon_images (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data,
- int size,
- gboolean for_drag_accept)
+ NautilusCanvasIconData *data,
+ int size,
+ gboolean for_drag_accept)
{
- NautilusCanvasContainerClass *klass;
+ NautilusCanvasContainerClass *klass;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
- g_assert (klass->get_icon_images != NULL);
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
+ g_assert (klass->get_icon_images != NULL);
- return klass->get_icon_images (container, data, size, for_drag_accept);
+ return klass->get_icon_images (container, data, size, for_drag_accept);
}
static void
nautilus_canvas_container_prioritize_thumbnailing (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- NautilusCanvasContainerClass *klass;
+ NautilusCanvasContainerClass *klass;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
- g_assert (klass->prioritize_thumbnailing != NULL);
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
+ g_assert (klass->prioritize_thumbnailing != NULL);
- klass->prioritize_thumbnailing (container, icon->data);
+ klass->prioritize_thumbnailing (container, icon->data);
}
static void
nautilus_canvas_container_update_visible_icons (NautilusCanvasContainer *container)
{
- GtkAdjustment *vadj, *hadj;
- double min_y, max_y;
- double min_x, max_x;
- double x0, y0, x1, y1;
- GList *node;
- NautilusCanvasIcon *icon;
- gboolean visible;
- GtkAllocation allocation;
-
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
-
- min_x = gtk_adjustment_get_value (hadj);
- max_x = min_x + allocation.width;
-
- min_y = gtk_adjustment_get_value (vadj);
- max_y = min_y + allocation.height;
-
- eel_canvas_c2w (EEL_CANVAS (container),
- min_x, min_y, &min_x, &min_y);
- eel_canvas_c2w (EEL_CANVAS (container),
- max_x, max_y, &max_x, &max_y);
-
- /* Do the iteration in reverse to get the render-order from top to
- * bottom for the prioritized thumbnails.
- */
- for (node = g_list_last (container->details->icons); node != NULL; node = node->prev) {
- icon = node->data;
-
- if (icon_is_positioned (icon)) {
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
- &x0,
- &y0,
- &x1,
- &y1);
- eel_canvas_item_i2w (EEL_CANVAS_ITEM (icon->item)->parent,
- &x0,
- &y0);
- eel_canvas_item_i2w (EEL_CANVAS_ITEM (icon->item)->parent,
- &x1,
- &y1);
-
- if (nautilus_canvas_container_is_layout_vertical (container)) {
- visible = x1 >= min_x && x0 <= max_x;
- } else {
- visible = y1 >= min_y && y0 <= max_y;
- }
-
- if (visible) {
- nautilus_canvas_item_set_is_visible (icon->item, TRUE);
- nautilus_canvas_container_prioritize_thumbnailing (container,
- icon);
- } else {
- nautilus_canvas_item_set_is_visible (icon->item, FALSE);
- }
- }
- }
+ GtkAdjustment *vadj, *hadj;
+ double min_y, max_y;
+ double min_x, max_x;
+ double x0, y0, x1, y1;
+ GList *node;
+ NautilusCanvasIcon *icon;
+ gboolean visible;
+ GtkAllocation allocation;
+
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container));
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+
+ min_x = gtk_adjustment_get_value (hadj);
+ max_x = min_x + allocation.width;
+
+ min_y = gtk_adjustment_get_value (vadj);
+ max_y = min_y + allocation.height;
+
+ eel_canvas_c2w (EEL_CANVAS (container),
+ min_x, min_y, &min_x, &min_y);
+ eel_canvas_c2w (EEL_CANVAS (container),
+ max_x, max_y, &max_x, &max_y);
+
+ /* Do the iteration in reverse to get the render-order from top to
+ * bottom for the prioritized thumbnails.
+ */
+ for (node = g_list_last (container->details->icons); node != NULL; node = node->prev)
+ {
+ icon = node->data;
+
+ if (icon_is_positioned (icon))
+ {
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (icon->item),
+ &x0,
+ &y0,
+ &x1,
+ &y1);
+ eel_canvas_item_i2w (EEL_CANVAS_ITEM (icon->item)->parent,
+ &x0,
+ &y0);
+ eel_canvas_item_i2w (EEL_CANVAS_ITEM (icon->item)->parent,
+ &x1,
+ &y1);
+
+ if (nautilus_canvas_container_is_layout_vertical (container))
+ {
+ visible = x1 >= min_x && x0 <= max_x;
+ }
+ else
+ {
+ visible = y1 >= min_y && y0 <= max_y;
+ }
+
+ if (visible)
+ {
+ nautilus_canvas_item_set_is_visible (icon->item, TRUE);
+ nautilus_canvas_container_prioritize_thumbnailing (container,
+ icon);
+ }
+ else
+ {
+ nautilus_canvas_item_set_is_visible (icon->item, FALSE);
+ }
+ }
+ }
}
static void
-handle_vadjustment_changed (GtkAdjustment *adjustment,
- NautilusCanvasContainer *container)
+handle_vadjustment_changed (GtkAdjustment *adjustment,
+ NautilusCanvasContainer *container)
{
- if (!nautilus_canvas_container_is_layout_vertical (container)) {
- nautilus_canvas_container_update_visible_icons (container);
- }
+ if (!nautilus_canvas_container_is_layout_vertical (container))
+ {
+ nautilus_canvas_container_update_visible_icons (container);
+ }
}
static void
-handle_hadjustment_changed (GtkAdjustment *adjustment,
- NautilusCanvasContainer *container)
+handle_hadjustment_changed (GtkAdjustment *adjustment,
+ NautilusCanvasContainer *container)
{
- if (nautilus_canvas_container_is_layout_vertical (container)) {
- nautilus_canvas_container_update_visible_icons (container);
- }
+ if (nautilus_canvas_container_is_layout_vertical (container))
+ {
+ nautilus_canvas_container_update_visible_icons (container);
+ }
}
-void
+void
nautilus_canvas_container_update_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- NautilusCanvasContainerDetails *details;
- guint icon_size;
- guint min_image_size, max_image_size;
- NautilusIconInfo *icon_info;
- GdkPixbuf *pixbuf;
- char *editable_text, *additional_text;
-
- if (icon == NULL) {
- return;
- }
+ NautilusCanvasContainerDetails *details;
+ guint icon_size;
+ guint min_image_size, max_image_size;
+ NautilusIconInfo *icon_info;
+ GdkPixbuf *pixbuf;
+ char *editable_text, *additional_text;
+
+ if (icon == NULL)
+ {
+ return;
+ }
- details = container->details;
+ details = container->details;
- /* compute the maximum size based on the scale factor */
- min_image_size = MINIMUM_IMAGE_SIZE * EEL_CANVAS (container)->pixels_per_unit;
- max_image_size = MAX (MAXIMUM_IMAGE_SIZE * EEL_CANVAS (container)->pixels_per_unit, NAUTILUS_ICON_MAXIMUM_SIZE);
+ /* compute the maximum size based on the scale factor */
+ min_image_size = MINIMUM_IMAGE_SIZE * EEL_CANVAS (container)->pixels_per_unit;
+ max_image_size = MAX (MAXIMUM_IMAGE_SIZE * EEL_CANVAS (container)->pixels_per_unit, NAUTILUS_ICON_MAXIMUM_SIZE);
- /* Get the appropriate images for the file. */
- icon_get_size (container, icon, &icon_size);
+ /* Get the appropriate images for the file. */
+ icon_get_size (container, icon, &icon_size);
- icon_size = MAX (icon_size, min_image_size);
- icon_size = MIN (icon_size, max_image_size);
+ icon_size = MAX (icon_size, min_image_size);
+ icon_size = MIN (icon_size, max_image_size);
- DEBUG ("Icon size, getting for size %d", icon_size);
+ DEBUG ("Icon size, getting for size %d", icon_size);
- /* Get the icons. */
- icon_info = nautilus_canvas_container_get_icon_images (container, icon->data, icon_size,
- icon == details->drop_target);
+ /* Get the icons. */
+ icon_info = nautilus_canvas_container_get_icon_images (container, icon->data, icon_size,
+ icon == details->drop_target);
- pixbuf = nautilus_icon_info_get_pixbuf (icon_info);
- g_object_unref (icon_info);
-
- nautilus_canvas_container_get_icon_text (container,
- icon->data,
- &editable_text,
- &additional_text,
- FALSE);
+ pixbuf = nautilus_icon_info_get_pixbuf (icon_info);
+ g_object_unref (icon_info);
- eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
- "editable_text", editable_text,
- "additional_text", additional_text,
- "highlighted_for_drop", icon == details->drop_target,
- NULL);
+ nautilus_canvas_container_get_icon_text (container,
+ icon->data,
+ &editable_text,
+ &additional_text,
+ FALSE);
- nautilus_canvas_item_set_image (icon->item, pixbuf);
+ eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
+ "editable_text", editable_text,
+ "additional_text", additional_text,
+ "highlighted_for_drop", icon == details->drop_target,
+ NULL);
- /* Let the pixbufs go. */
- g_object_unref (pixbuf);
+ nautilus_canvas_item_set_image (icon->item, pixbuf);
- g_free (editable_text);
- g_free (additional_text);
+ /* Let the pixbufs go. */
+ g_object_unref (pixbuf);
+
+ g_free (editable_text);
+ g_free (additional_text);
}
static gboolean
assign_icon_position (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
-{
- gboolean have_stored_position;
- NautilusCanvasPosition position;
-
- /* Get the stored position. */
- have_stored_position = FALSE;
- position.scale = 1.0;
- g_signal_emit (container,
- signals[GET_STORED_ICON_POSITION], 0,
- icon->data,
- &position,
- &have_stored_position);
- icon->scale = position.scale;
- if (!container->details->auto_layout) {
- if (have_stored_position) {
- icon_set_position (icon, position.x, position.y);
- icon->saved_ltr_x = icon->x;
- } else {
- return FALSE;
- }
- }
- return TRUE;
+ NautilusCanvasIcon *icon)
+{
+ gboolean have_stored_position;
+ NautilusCanvasPosition position;
+
+ /* Get the stored position. */
+ have_stored_position = FALSE;
+ position.scale = 1.0;
+ g_signal_emit (container,
+ signals[GET_STORED_ICON_POSITION], 0,
+ icon->data,
+ &position,
+ &have_stored_position);
+ icon->scale = position.scale;
+ if (!container->details->auto_layout)
+ {
+ if (have_stored_position)
+ {
+ icon_set_position (icon, position.x, position.y);
+ icon->saved_ltr_x = icon->x;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
}
static void
finish_adding_icon (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- nautilus_canvas_container_update_icon (container, icon);
- eel_canvas_item_show (EEL_CANVAS_ITEM (icon->item));
+ nautilus_canvas_container_update_icon (container, icon);
+ eel_canvas_item_show (EEL_CANVAS_ITEM (icon->item));
- g_signal_connect_object (icon->item, "event",
- G_CALLBACK (item_event_callback), container, 0);
+ g_signal_connect_object (icon->item, "event",
+ G_CALLBACK (item_event_callback), container, 0);
- g_signal_emit (container, signals[ICON_ADDED], 0, icon->data);
+ g_signal_emit (container, signals[ICON_ADDED], 0, icon->data);
}
static gboolean
finish_adding_new_icons (NautilusCanvasContainer *container)
{
- GList *p, *new_icons, *no_position_icons, *semi_position_icons;
- NautilusCanvasIcon *icon;
- double bottom;
-
- new_icons = container->details->new_icons;
- container->details->new_icons = NULL;
-
- /* Position most icons (not unpositioned manual-layout icons). */
- new_icons = g_list_reverse (new_icons);
- no_position_icons = semi_position_icons = NULL;
- for (p = new_icons; p != NULL; p = p->next) {
- icon = p->data;
- if (icon->has_lazy_position) {
- assign_icon_position (container, icon);
- semi_position_icons = g_list_prepend (semi_position_icons, icon);
- } else if (!assign_icon_position (container, icon)) {
- no_position_icons = g_list_prepend (no_position_icons, icon);
- }
-
- finish_adding_icon (container, icon);
- }
- g_list_free (new_icons);
-
- if (semi_position_icons != NULL) {
- PlacementGrid *grid;
- time_t now;
- gboolean dummy;
-
- g_assert (!container->details->auto_layout);
-
- semi_position_icons = g_list_reverse (semi_position_icons);
-
- /* This is currently only used on the desktop.
- * Thus, we pass FALSE for tight, like lay_down_icons_tblr */
- grid = placement_grid_new (container, FALSE);
-
- /* we can do nothing, just return */
- if (grid == NULL)
- return FALSE;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- if (icon_is_positioned (icon) && !icon->has_lazy_position) {
- placement_grid_mark_icon (grid, icon);
- }
- }
-
- now = time (NULL);
-
- for (p = semi_position_icons; p != NULL; p = p->next) {
- NautilusCanvasIcon *icon;
- NautilusCanvasPosition position;
- int x, y;
-
- icon = p->data;
- x = icon->x;
- y = icon->y;
-
- find_empty_location (container, grid,
- icon, x, y, &x, &y);
-
- icon_set_position (icon, x, y);
-
- position.x = icon->x;
- position.y = icon->y;
- position.scale = icon->scale;
- placement_grid_mark_icon (grid, icon);
- g_signal_emit (container, signals[ICON_POSITION_CHANGED], 0,
- icon->data, &position);
- g_signal_emit (container, signals[STORE_LAYOUT_TIMESTAMP], 0,
- icon->data, &now, &dummy);
-
- /* ensure that next time we run this code, the formerly semi-positioned
- * icons are treated as being positioned. */
- icon->has_lazy_position = FALSE;
- }
-
- placement_grid_free (grid);
-
- g_list_free (semi_position_icons);
- }
-
- /* Position the unpositioned manual layout icons. */
- if (no_position_icons != NULL) {
- g_assert (!container->details->auto_layout);
-
- sort_icons (container, &no_position_icons);
- if (nautilus_canvas_container_get_is_desktop (container)) {
- lay_down_icons (container, no_position_icons, CONTAINER_PAD_TOP);
- } else {
- get_all_icon_bounds (container, NULL, NULL, NULL, &bottom, BOUNDS_USAGE_FOR_LAYOUT);
- lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
- }
- g_list_free (no_position_icons);
- }
-
- if (container->details->store_layout_timestamps_when_finishing_new_icons) {
- store_layout_timestamps_now (container);
- container->details->store_layout_timestamps_when_finishing_new_icons = FALSE;
- }
+ GList *p, *new_icons, *no_position_icons, *semi_position_icons;
+ NautilusCanvasIcon *icon;
+ double bottom;
+
+ new_icons = container->details->new_icons;
+ container->details->new_icons = NULL;
+
+ /* Position most icons (not unpositioned manual-layout icons). */
+ new_icons = g_list_reverse (new_icons);
+ no_position_icons = semi_position_icons = NULL;
+ for (p = new_icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (icon->has_lazy_position)
+ {
+ assign_icon_position (container, icon);
+ semi_position_icons = g_list_prepend (semi_position_icons, icon);
+ }
+ else if (!assign_icon_position (container, icon))
+ {
+ no_position_icons = g_list_prepend (no_position_icons, icon);
+ }
- return TRUE;
+ finish_adding_icon (container, icon);
+ }
+ g_list_free (new_icons);
+
+ if (semi_position_icons != NULL)
+ {
+ PlacementGrid *grid;
+ time_t now;
+ gboolean dummy;
+
+ g_assert (!container->details->auto_layout);
+
+ semi_position_icons = g_list_reverse (semi_position_icons);
+
+ /* This is currently only used on the desktop.
+ * Thus, we pass FALSE for tight, like lay_down_icons_tblr */
+ grid = placement_grid_new (container, FALSE);
+
+ /* we can do nothing, just return */
+ if (grid == NULL)
+ {
+ return FALSE;
+ }
+
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ if (icon_is_positioned (icon) && !icon->has_lazy_position)
+ {
+ placement_grid_mark_icon (grid, icon);
+ }
+ }
+
+ now = time (NULL);
+
+ for (p = semi_position_icons; p != NULL; p = p->next)
+ {
+ NautilusCanvasIcon *icon;
+ NautilusCanvasPosition position;
+ int x, y;
+
+ icon = p->data;
+ x = icon->x;
+ y = icon->y;
+
+ find_empty_location (container, grid,
+ icon, x, y, &x, &y);
+
+ icon_set_position (icon, x, y);
+
+ position.x = icon->x;
+ position.y = icon->y;
+ position.scale = icon->scale;
+ placement_grid_mark_icon (grid, icon);
+ g_signal_emit (container, signals[ICON_POSITION_CHANGED], 0,
+ icon->data, &position);
+ g_signal_emit (container, signals[STORE_LAYOUT_TIMESTAMP], 0,
+ icon->data, &now, &dummy);
+
+ /* ensure that next time we run this code, the formerly semi-positioned
+ * icons are treated as being positioned. */
+ icon->has_lazy_position = FALSE;
+ }
+
+ placement_grid_free (grid);
+
+ g_list_free (semi_position_icons);
+ }
+
+ /* Position the unpositioned manual layout icons. */
+ if (no_position_icons != NULL)
+ {
+ g_assert (!container->details->auto_layout);
+
+ sort_icons (container, &no_position_icons);
+ if (nautilus_canvas_container_get_is_desktop (container))
+ {
+ lay_down_icons (container, no_position_icons, CONTAINER_PAD_TOP);
+ }
+ else
+ {
+ get_all_icon_bounds (container, NULL, NULL, NULL, &bottom, BOUNDS_USAGE_FOR_LAYOUT);
+ lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
+ }
+ g_list_free (no_position_icons);
+ }
+
+ if (container->details->store_layout_timestamps_when_finishing_new_icons)
+ {
+ store_layout_timestamps_now (container);
+ container->details->store_layout_timestamps_when_finishing_new_icons = FALSE;
+ }
+
+ return TRUE;
}
static gboolean
is_old_or_unknown_icon_data (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
+ NautilusCanvasIconData *data)
{
- time_t timestamp;
- gboolean success;
+ time_t timestamp;
+ gboolean success;
- if (container->details->layout_timestamp == UNDEFINED_TIME) {
- /* don't know */
- return FALSE;
- }
+ if (container->details->layout_timestamp == UNDEFINED_TIME)
+ {
+ /* don't know */
+ return FALSE;
+ }
- g_signal_emit (container,
- signals[GET_STORED_LAYOUT_TIMESTAMP], 0,
- data, &timestamp, &success);
- return (!success || timestamp < container->details->layout_timestamp);
+ g_signal_emit (container,
+ signals[GET_STORED_LAYOUT_TIMESTAMP], 0,
+ data, &timestamp, &success);
+ return (!success || timestamp < container->details->layout_timestamp);
}
/**
* nautilus_canvas_container_add:
* @container: A NautilusCanvasContainer
* @data: Icon data.
- *
+ *
* Add icon to represent @data to container.
* Returns FALSE if there was already such an icon.
**/
gboolean
nautilus_canvas_container_add (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
-{
- NautilusCanvasContainerDetails *details;
- NautilusCanvasIcon *icon;
- EelCanvasItem *band, *item;
-
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
-
- details = container->details;
-
- if (g_hash_table_lookup (details->icon_set, data) != NULL) {
- return FALSE;
- }
-
- /* Create the new icon, including the canvas item. */
- icon = g_new0 (NautilusCanvasIcon, 1);
- icon->data = data;
- icon->x = ICON_UNPOSITIONED_VALUE;
- icon->y = ICON_UNPOSITIONED_VALUE;
-
- /* Whether the saved icon position should only be used
- * if the previous icon position is free. If the position
- * is occupied, another position near the last one will
- */
- icon->has_lazy_position = is_old_or_unknown_icon_data (container, data);
- icon->scale = 1.0;
- icon->item = NAUTILUS_CANVAS_ITEM
- (eel_canvas_item_new (EEL_CANVAS_GROUP (EEL_CANVAS (container)->root),
- nautilus_canvas_item_get_type (),
- "visible", FALSE,
- NULL));
- icon->item->user_data = icon;
-
- /* Make sure the icon is under the selection_rectangle */
- item = EEL_CANVAS_ITEM (icon->item);
- band = NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle;
- if (band) {
- eel_canvas_item_send_behind (item, band);
- }
-
- /* Put it on both lists. */
- details->icons = g_list_prepend (details->icons, icon);
- details->new_icons = g_list_prepend (details->new_icons, icon);
-
- g_hash_table_insert (details->icon_set, data, icon);
-
- details->needs_resort = TRUE;
-
- /* Run an idle function to add the icons. */
- schedule_redo_layout (container);
-
- return TRUE;
+ NautilusCanvasIconData *data)
+{
+ NautilusCanvasContainerDetails *details;
+ NautilusCanvasIcon *icon;
+ EelCanvasItem *band, *item;
+
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ details = container->details;
+
+ if (g_hash_table_lookup (details->icon_set, data) != NULL)
+ {
+ return FALSE;
+ }
+
+ /* Create the new icon, including the canvas item. */
+ icon = g_new0 (NautilusCanvasIcon, 1);
+ icon->data = data;
+ icon->x = ICON_UNPOSITIONED_VALUE;
+ icon->y = ICON_UNPOSITIONED_VALUE;
+
+ /* Whether the saved icon position should only be used
+ * if the previous icon position is free. If the position
+ * is occupied, another position near the last one will
+ */
+ icon->has_lazy_position = is_old_or_unknown_icon_data (container, data);
+ icon->scale = 1.0;
+ icon->item = NAUTILUS_CANVAS_ITEM
+ (eel_canvas_item_new (EEL_CANVAS_GROUP (EEL_CANVAS (container)->root),
+ nautilus_canvas_item_get_type (),
+ "visible", FALSE,
+ NULL));
+ icon->item->user_data = icon;
+
+ /* Make sure the icon is under the selection_rectangle */
+ item = EEL_CANVAS_ITEM (icon->item);
+ band = NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle;
+ if (band)
+ {
+ eel_canvas_item_send_behind (item, band);
+ }
+
+ /* Put it on both lists. */
+ details->icons = g_list_prepend (details->icons, icon);
+ details->new_icons = g_list_prepend (details->new_icons, icon);
+
+ g_hash_table_insert (details->icon_set, data, icon);
+
+ details->needs_resort = TRUE;
+
+ /* Run an idle function to add the icons. */
+ schedule_redo_layout (container);
+
+ return TRUE;
}
void
nautilus_canvas_container_layout_now (NautilusCanvasContainer *container)
{
- if (container->details->idle_id != 0) {
- unschedule_redo_layout (container);
- redo_layout_internal (container);
- }
+ if (container->details->idle_id != 0)
+ {
+ unschedule_redo_layout (container);
+ redo_layout_internal (container);
+ }
- /* Also need to make sure we're properly resized, for instance
- * newly added files may trigger a change in the size allocation and
- * thus toggle scrollbars on */
- gtk_container_check_resize (GTK_CONTAINER (gtk_widget_get_parent (GTK_WIDGET (container))));
+ /* Also need to make sure we're properly resized, for instance
+ * newly added files may trigger a change in the size allocation and
+ * thus toggle scrollbars on */
+ gtk_container_check_resize (GTK_CONTAINER (gtk_widget_get_parent (GTK_WIDGET (container))));
}
/**
* nautilus_canvas_container_remove:
* @container: A NautilusCanvasContainer.
* @data: Icon data.
- *
+ *
* Remove the icon with this data.
**/
gboolean
nautilus_canvas_container_remove (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
+ NautilusCanvasIconData *data)
{
- NautilusCanvasIcon *icon;
+ NautilusCanvasIcon *icon;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
- icon = g_hash_table_lookup (container->details->icon_set, data);
+ icon = g_hash_table_lookup (container->details->icon_set, data);
- if (icon == NULL) {
- return FALSE;
- }
+ if (icon == NULL)
+ {
+ return FALSE;
+ }
- icon_destroy (container, icon);
- schedule_redo_layout (container);
+ icon_destroy (container, icon);
+ schedule_redo_layout (container);
- g_signal_emit (container, signals[ICON_REMOVED], 0, icon);
+ g_signal_emit (container, signals[ICON_REMOVED], 0, icon);
- return TRUE;
+ return TRUE;
}
/**
* nautilus_canvas_container_request_update:
* @container: A NautilusCanvasContainer.
* @data: Icon data.
- *
+ *
* Update the icon with this data.
**/
void
nautilus_canvas_container_request_update (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
+ NautilusCanvasIconData *data)
{
- NautilusCanvasIcon *icon;
+ NautilusCanvasIcon *icon;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_return_if_fail (data != NULL);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (data != NULL);
- icon = g_hash_table_lookup (container->details->icon_set, data);
+ icon = g_hash_table_lookup (container->details->icon_set, data);
- if (icon != NULL) {
- nautilus_canvas_container_update_icon (container, icon);
- container->details->needs_resort = TRUE;
- schedule_redo_layout (container);
- }
+ if (icon != NULL)
+ {
+ nautilus_canvas_container_update_icon (container, icon);
+ container->details->needs_resort = TRUE;
+ schedule_redo_layout (container);
+ }
}
/* zooming */
@@ -6258,49 +6988,54 @@ nautilus_canvas_container_request_update (NautilusCanvasContainer *container,
NautilusCanvasZoomLevel
nautilus_canvas_container_get_zoom_level (NautilusCanvasContainer *container)
{
- return container->details->zoom_level;
+ return container->details->zoom_level;
}
void
-nautilus_canvas_container_set_zoom_level (NautilusCanvasContainer *container, int new_level)
-{
- NautilusCanvasContainerDetails *details;
- int pinned_level;
- double pixels_per_unit;
-
- details = container->details;
-
- pinned_level = new_level;
- if (pinned_level < NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL) {
- pinned_level = NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL;
- } else if (pinned_level > NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER) {
- pinned_level = NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER;
- }
-
- if (pinned_level == details->zoom_level) {
- return;
- }
-
- details->zoom_level = pinned_level;
-
- pixels_per_unit = (double) nautilus_canvas_container_get_icon_size_for_zoom_level (pinned_level)
- / NAUTILUS_CANVAS_ICON_SIZE_STANDARD;
- eel_canvas_set_pixels_per_unit (EEL_CANVAS (container), pixels_per_unit);
-
- nautilus_canvas_container_request_update_all_internal (container, TRUE);
+nautilus_canvas_container_set_zoom_level (NautilusCanvasContainer *container,
+ int new_level)
+{
+ NautilusCanvasContainerDetails *details;
+ int pinned_level;
+ double pixels_per_unit;
+
+ details = container->details;
+
+ pinned_level = new_level;
+ if (pinned_level < NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL)
+ {
+ pinned_level = NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL;
+ }
+ else if (pinned_level > NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER)
+ {
+ pinned_level = NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER;
+ }
+
+ if (pinned_level == details->zoom_level)
+ {
+ return;
+ }
+
+ details->zoom_level = pinned_level;
+
+ pixels_per_unit = (double) nautilus_canvas_container_get_icon_size_for_zoom_level (pinned_level)
+ / NAUTILUS_CANVAS_ICON_SIZE_STANDARD;
+ eel_canvas_set_pixels_per_unit (EEL_CANVAS (container), pixels_per_unit);
+
+ nautilus_canvas_container_request_update_all_internal (container, TRUE);
}
/**
* nautilus_canvas_container_request_update_all:
* For each icon, synchronizes the displayed information (image, text) with the
* information from the model.
- *
+ *
* @container: An canvas container.
**/
void
nautilus_canvas_container_request_update_all (NautilusCanvasContainer *container)
{
- nautilus_canvas_container_request_update_all_internal (container, FALSE);
+ nautilus_canvas_container_request_update_all_internal (container, FALSE);
}
/**
@@ -6308,26 +7043,28 @@ nautilus_canvas_container_request_update_all (NautilusCanvasContainer *container
* Change scroll position as necessary to reveal the specified item.
*/
void
-nautilus_canvas_container_reveal (NautilusCanvasContainer *container, NautilusCanvasIconData *data)
+nautilus_canvas_container_reveal (NautilusCanvasContainer *container,
+ NautilusCanvasIconData *data)
{
- NautilusCanvasIcon *icon;
+ NautilusCanvasIcon *icon;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_return_if_fail (data != NULL);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (data != NULL);
- icon = g_hash_table_lookup (container->details->icon_set, data);
+ icon = g_hash_table_lookup (container->details->icon_set, data);
- if (icon != NULL) {
- reveal_icon (container, icon);
- }
+ if (icon != NULL)
+ {
+ reveal_icon (container, icon);
+ }
}
/**
* nautilus_canvas_container_get_selection:
* @container: An canvas container.
- *
+ *
* Get a list of the icons currently selected in @container.
- *
+ *
* Return value: A GList of the programmer-specified data associated to each
* selected icon, or NULL if no canvas is selected. The caller is expected to
* free the list when it is not needed anymore.
@@ -6335,80 +7072,85 @@ nautilus_canvas_container_reveal (NautilusCanvasContainer *container, NautilusCa
GList *
nautilus_canvas_container_get_selection (NautilusCanvasContainer *container)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
- if (container->details->selection_needs_resort) {
- sort_selection (container);
- }
+ if (container->details->selection_needs_resort)
+ {
+ sort_selection (container);
+ }
- return g_list_copy (container->details->selection);
+ return g_list_copy (container->details->selection);
}
static GList *
nautilus_canvas_container_get_selected_icons (NautilusCanvasContainer *container)
{
- GList *list, *p;
+ GList *list, *p;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
- list = NULL;
- for (p = container->details->icons; p != NULL; p = p->next) {
- NautilusCanvasIcon *icon;
+ list = NULL;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ NautilusCanvasIcon *icon;
- icon = p->data;
- if (icon->is_selected) {
- list = g_list_prepend (list, icon);
- }
- }
+ icon = p->data;
+ if (icon->is_selected)
+ {
+ list = g_list_prepend (list, icon);
+ }
+ }
- return g_list_reverse (list);
+ return g_list_reverse (list);
}
/**
* nautilus_canvas_container_invert_selection:
* @container: An canvas container.
- *
+ *
* Inverts the selection in @container.
- *
+ *
**/
void
nautilus_canvas_container_invert_selection (NautilusCanvasContainer *container)
{
- GList *p;
+ GList *p;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- for (p = container->details->icons; p != NULL; p = p->next) {
- NautilusCanvasIcon *icon;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ NautilusCanvasIcon *icon;
- icon = p->data;
- icon_toggle_selected (container, icon);
- }
+ icon = p->data;
+ icon_toggle_selected (container, icon);
+ }
- g_signal_emit (container, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (container, signals[SELECTION_CHANGED], 0);
}
/* Returns an array of GdkPoints of locations of the icons. */
static GArray *
nautilus_canvas_container_get_icon_locations (NautilusCanvasContainer *container,
- GList *icons)
+ GList *icons)
{
- GArray *result;
- GList *node;
- int index;
-
- result = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
- result = g_array_set_size (result, g_list_length (icons));
-
- for (index = 0, node = icons; node != NULL; index++, node = node->next) {
- g_array_index (result, GdkPoint, index).x =
- ((NautilusCanvasIcon *)node->data)->x;
- g_array_index (result, GdkPoint, index).y =
- ((NautilusCanvasIcon *)node->data)->y;
- }
+ GArray *result;
+ GList *node;
+ int index;
+
+ result = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
+ result = g_array_set_size (result, g_list_length (icons));
- return result;
+ for (index = 0, node = icons; node != NULL; index++, node = node->next)
+ {
+ g_array_index (result, GdkPoint, index).x =
+ ((NautilusCanvasIcon *) node->data)->x;
+ g_array_index (result, GdkPoint, index).y =
+ ((NautilusCanvasIcon *) node->data)->y;
+ }
+
+ return result;
}
/* Returns an array of GdkRectangles of the icons. The bounding box is adjusted
@@ -6417,515 +7159,550 @@ static GArray *
nautilus_canvas_container_get_icons_bounding_box (NautilusCanvasContainer *container,
GList *icons)
{
- GArray *result;
- GList *node;
- int index;
- int x1, x2, y1, y2;
+ GArray *result;
+ GList *node;
+ int index;
+ int x1, x2, y1, y2;
- result = g_array_new (FALSE, TRUE, sizeof (GdkRectangle));
- result = g_array_set_size (result, g_list_length (icons));
+ result = g_array_new (FALSE, TRUE, sizeof (GdkRectangle));
+ result = g_array_set_size (result, g_list_length (icons));
- for (index = 0, node = icons; node != NULL; index++, node = node->next) {
- icon_get_bounding_box ((NautilusCanvasIcon *)node->data,
- &x1, &y1, &x2, &y2,
- BOUNDS_USAGE_FOR_DISPLAY);
- g_array_index (result, GdkRectangle, index).x = x1 * EEL_CANVAS (container)->pixels_per_unit +
- container->details->left_margin;
- g_array_index (result, GdkRectangle, index).width = (x2 - x1) * EEL_CANVAS (container)->pixels_per_unit;
- g_array_index (result, GdkRectangle, index).y = y1 * EEL_CANVAS (container)->pixels_per_unit +
- container->details->top_margin;
- g_array_index (result, GdkRectangle, index).height = (y2 - y1) * EEL_CANVAS (container)->pixels_per_unit;
- }
+ for (index = 0, node = icons; node != NULL; index++, node = node->next)
+ {
+ icon_get_bounding_box ((NautilusCanvasIcon *) node->data,
+ &x1, &y1, &x2, &y2,
+ BOUNDS_USAGE_FOR_DISPLAY);
+ g_array_index (result, GdkRectangle, index).x = x1 * EEL_CANVAS (container)->pixels_per_unit +
+ container->details->left_margin;
+ g_array_index (result, GdkRectangle, index).width = (x2 - x1) * EEL_CANVAS (container)->pixels_per_unit;
+ g_array_index (result, GdkRectangle, index).y = y1 * EEL_CANVAS (container)->pixels_per_unit +
+ container->details->top_margin;
+ g_array_index (result, GdkRectangle, index).height = (y2 - y1) * EEL_CANVAS (container)->pixels_per_unit;
+ }
- return result;
+ return result;
}
GArray *
nautilus_canvas_container_get_selected_icons_bounding_box (NautilusCanvasContainer *container)
{
- GArray *result;
- GList *icons;
+ GArray *result;
+ GList *icons;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
- icons = nautilus_canvas_container_get_selected_icons (container);
- result = nautilus_canvas_container_get_icons_bounding_box (container, icons);
- g_list_free (icons);
+ icons = nautilus_canvas_container_get_selected_icons (container);
+ result = nautilus_canvas_container_get_icons_bounding_box (container, icons);
+ g_list_free (icons);
- return result;
+ return result;
}
/**
* nautilus_canvas_container_get_selected_icon_locations:
* @container: An canvas container widget.
- *
+ *
* Returns an array of GdkPoints of locations of the selected icons.
**/
GArray *
nautilus_canvas_container_get_selected_icon_locations (NautilusCanvasContainer *container)
{
- GArray *result;
- GList *icons;
+ GArray *result;
+ GList *icons;
+
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
+ icons = nautilus_canvas_container_get_selected_icons (container);
+ result = nautilus_canvas_container_get_icon_locations (container, icons);
+ g_list_free (icons);
- icons = nautilus_canvas_container_get_selected_icons (container);
- result = nautilus_canvas_container_get_icon_locations (container, icons);
- g_list_free (icons);
-
- return result;
+ return result;
}
/**
* nautilus_canvas_container_select_all:
* @container: An canvas container widget.
- *
+ *
* Select all the icons in @container at once.
**/
void
nautilus_canvas_container_select_all (NautilusCanvasContainer *container)
{
- gboolean selection_changed;
- GList *p;
- NautilusCanvasIcon *icon;
+ gboolean selection_changed;
+ GList *p;
+ NautilusCanvasIcon *icon;
+
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ selection_changed = FALSE;
- selection_changed = FALSE;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- selection_changed |= icon_set_selected (container, icon, TRUE);
- }
+ selection_changed |= icon_set_selected (container, icon, TRUE);
+ }
- if (selection_changed) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
+ if (selection_changed)
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
}
/**
* nautilus_canvas_container_select_first:
* @container: An canvas container widget.
- *
+ *
* Select the first icon in @container.
**/
void
nautilus_canvas_container_select_first (NautilusCanvasContainer *container)
{
- gboolean selection_changed;
- NautilusCanvasIcon *icon;
+ gboolean selection_changed;
+ NautilusCanvasIcon *icon;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- selection_changed = FALSE;
+ selection_changed = FALSE;
- if (container->details->needs_resort) {
- resort (container);
- container->details->needs_resort = FALSE;
- }
+ if (container->details->needs_resort)
+ {
+ resort (container);
+ container->details->needs_resort = FALSE;
+ }
- icon = g_list_nth_data (container->details->icons, 0);
- if (icon) {
- selection_changed |= icon_set_selected (container, icon, TRUE);
- }
+ icon = g_list_nth_data (container->details->icons, 0);
+ if (icon)
+ {
+ selection_changed |= icon_set_selected (container, icon, TRUE);
+ }
- if (selection_changed) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
+ if (selection_changed)
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
}
/**
* nautilus_canvas_container_set_selection:
* @container: An canvas container widget.
* @selection: A list of NautilusCanvasIconData *.
- *
+ *
* Set the selection to exactly the icons in @container which have
* programmer data matching one of the items in @selection.
**/
void
nautilus_canvas_container_set_selection (NautilusCanvasContainer *container,
- GList *selection)
-{
- gboolean selection_changed;
- GHashTable *hash;
- GList *p;
- gboolean res;
- NautilusCanvasIcon *icon, *selected_icon;
-
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
-
- selection_changed = FALSE;
- selected_icon = NULL;
-
- hash = g_hash_table_new (NULL, NULL);
- for (p = selection; p != NULL; p = p->next) {
- g_hash_table_insert (hash, p->data, p->data);
- }
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- res = icon_set_selected
- (container, icon,
- g_hash_table_lookup (hash, icon->data) != NULL);
- selection_changed |= res;
-
- if (res) {
- selected_icon = icon;
- }
- }
- g_hash_table_destroy (hash);
-
- if (selection_changed) {
- /* if only one item has been selected, use it as range
- * selection base (cf. handle_canvas_button_press) */
- if (g_list_length (selection) == 1) {
- container->details->range_selection_base_icon = selected_icon;
- }
-
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
+ GList *selection)
+{
+ gboolean selection_changed;
+ GHashTable *hash;
+ GList *p;
+ gboolean res;
+ NautilusCanvasIcon *icon, *selected_icon;
+
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+
+ selection_changed = FALSE;
+ selected_icon = NULL;
+
+ hash = g_hash_table_new (NULL, NULL);
+ for (p = selection; p != NULL; p = p->next)
+ {
+ g_hash_table_insert (hash, p->data, p->data);
+ }
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+
+ res = icon_set_selected
+ (container, icon,
+ g_hash_table_lookup (hash, icon->data) != NULL);
+ selection_changed |= res;
+
+ if (res)
+ {
+ selected_icon = icon;
+ }
+ }
+ g_hash_table_destroy (hash);
+
+ if (selection_changed)
+ {
+ /* if only one item has been selected, use it as range
+ * selection base (cf. handle_canvas_button_press) */
+ if (g_list_length (selection) == 1)
+ {
+ container->details->range_selection_base_icon = selected_icon;
+ }
+
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
}
/**
* nautilus_canvas_container_select_list_unselect_others.
* @container: An canvas container widget.
* @selection: A list of NautilusCanvasIcon *.
- *
+ *
* Set the selection to exactly the icons in @selection.
**/
void
nautilus_canvas_container_select_list_unselect_others (NautilusCanvasContainer *container,
- GList *selection)
+ GList *selection)
{
- gboolean selection_changed;
- GHashTable *hash;
- GList *p;
- NautilusCanvasIcon *icon;
+ gboolean selection_changed;
+ GHashTable *hash;
+ GList *p;
+ NautilusCanvasIcon *icon;
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- selection_changed = FALSE;
+ selection_changed = FALSE;
- hash = g_hash_table_new (NULL, NULL);
- for (p = selection; p != NULL; p = p->next) {
- g_hash_table_insert (hash, p->data, p->data);
- }
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
-
- selection_changed |= icon_set_selected
- (container, icon,
- g_hash_table_lookup (hash, icon) != NULL);
- }
- g_hash_table_destroy (hash);
+ hash = g_hash_table_new (NULL, NULL);
+ for (p = selection; p != NULL; p = p->next)
+ {
+ g_hash_table_insert (hash, p->data, p->data);
+ }
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
- if (selection_changed) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
+ selection_changed |= icon_set_selected
+ (container, icon,
+ g_hash_table_lookup (hash, icon) != NULL);
+ }
+ g_hash_table_destroy (hash);
+
+ if (selection_changed)
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
}
/**
* nautilus_canvas_container_unselect_all:
* @container: An canvas container widget.
- *
+ *
* Deselect all the icons in @container.
**/
void
nautilus_canvas_container_unselect_all (NautilusCanvasContainer *container)
{
- if (unselect_all (container)) {
- g_signal_emit (container,
- signals[SELECTION_CHANGED], 0);
- }
+ if (unselect_all (container))
+ {
+ g_signal_emit (container,
+ signals[SELECTION_CHANGED], 0);
+ }
}
/**
* nautilus_canvas_container_get_icon_by_uri:
* @container: An canvas container widget.
* @uri: The uri of an canvas to find.
- *
+ *
* Locate an icon, given the URI. The URI must match exactly.
* Later we may have to have some way of figuring out if the
* URI specifies the same object that does not require an exact match.
**/
NautilusCanvasIcon *
nautilus_canvas_container_get_icon_by_uri (NautilusCanvasContainer *container,
- const char *uri)
+ const char *uri)
{
- NautilusCanvasContainerDetails *details;
- GList *p;
+ NautilusCanvasContainerDetails *details;
+ GList *p;
- /* Eventually, we must avoid searching the entire canvas list,
- but it's OK for now.
- A hash table mapping uri to canvas is one possibility.
- */
+ /* Eventually, we must avoid searching the entire canvas list,
+ * but it's OK for now.
+ * A hash table mapping uri to canvas is one possibility.
+ */
- details = container->details;
+ details = container->details;
- for (p = details->icons; p != NULL; p = p->next) {
- NautilusCanvasIcon *icon;
- char *icon_uri;
- gboolean is_match;
+ for (p = details->icons; p != NULL; p = p->next)
+ {
+ NautilusCanvasIcon *icon;
+ char *icon_uri;
+ gboolean is_match;
- icon = p->data;
+ icon = p->data;
- icon_uri = nautilus_canvas_container_get_icon_uri
- (container, icon);
- is_match = strcmp (uri, icon_uri) == 0;
- g_free (icon_uri);
+ icon_uri = nautilus_canvas_container_get_icon_uri
+ (container, icon);
+ is_match = strcmp (uri, icon_uri) == 0;
+ g_free (icon_uri);
- if (is_match) {
- return icon;
- }
- }
+ if (is_match)
+ {
+ return icon;
+ }
+ }
- return NULL;
+ return NULL;
}
static NautilusCanvasIcon *
-get_nth_selected_icon (NautilusCanvasContainer *container, int index)
-{
- GList *p;
- NautilusCanvasIcon *icon;
- int selection_count;
-
- g_assert (index > 0);
-
- /* Find the nth selected icon. */
- selection_count = 0;
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
- if (icon->is_selected) {
- if (++selection_count == index) {
- return icon;
- }
- }
- }
- return NULL;
+get_nth_selected_icon (NautilusCanvasContainer *container,
+ int index)
+{
+ GList *p;
+ NautilusCanvasIcon *icon;
+ int selection_count;
+
+ g_assert (index > 0);
+
+ /* Find the nth selected icon. */
+ selection_count = 0;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (icon->is_selected)
+ {
+ if (++selection_count == index)
+ {
+ return icon;
+ }
+ }
+ }
+ return NULL;
}
static NautilusCanvasIcon *
get_first_selected_icon (NautilusCanvasContainer *container)
{
- return get_nth_selected_icon (container, 1);
+ return get_nth_selected_icon (container, 1);
}
static gboolean
has_multiple_selection (NautilusCanvasContainer *container)
{
- return get_nth_selected_icon (container, 2) != NULL;
+ return get_nth_selected_icon (container, 2) != NULL;
}
static gboolean
all_selected (NautilusCanvasContainer *container)
{
- GList *p;
- NautilusCanvasIcon *icon;
+ GList *p;
+ NautilusCanvasIcon *icon;
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
- if (!icon->is_selected) {
- return FALSE;
- }
- }
- return TRUE;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (!icon->is_selected)
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
}
static gboolean
has_selection (NautilusCanvasContainer *container)
{
- return get_nth_selected_icon (container, 1) != NULL;
+ return get_nth_selected_icon (container, 1) != NULL;
}
/**
* nautilus_canvas_container_show_stretch_handles:
* @container: An canvas container widget.
- *
+ *
* Makes stretch handles visible on the first selected icon.
**/
void
nautilus_canvas_container_show_stretch_handles (NautilusCanvasContainer *container)
{
- NautilusCanvasContainerDetails *details;
- NautilusCanvasIcon *icon;
- guint initial_size;
-
- icon = get_first_selected_icon (container);
- if (icon == NULL) {
- return;
- }
-
- /* Check if it already has stretch handles. */
- details = container->details;
- if (details->stretch_icon == icon) {
- return;
- }
-
- /* Get rid of the existing stretch handles and put them on the new canvas. */
- if (details->stretch_icon != NULL) {
- nautilus_canvas_item_set_show_stretch_handles
- (details->stretch_icon->item, FALSE);
- ungrab_stretch_icon (container);
- emit_stretch_ended (container, details->stretch_icon);
- }
- nautilus_canvas_item_set_show_stretch_handles (icon->item, TRUE);
- details->stretch_icon = icon;
-
- icon_get_size (container, icon, &initial_size);
-
- /* only need to keep size in one dimension, since they are constrained to be the same */
- container->details->stretch_initial_x = icon->x;
- container->details->stretch_initial_y = icon->y;
- container->details->stretch_initial_size = initial_size;
-
- emit_stretch_started (container, icon);
+ NautilusCanvasContainerDetails *details;
+ NautilusCanvasIcon *icon;
+ guint initial_size;
+
+ icon = get_first_selected_icon (container);
+ if (icon == NULL)
+ {
+ return;
+ }
+
+ /* Check if it already has stretch handles. */
+ details = container->details;
+ if (details->stretch_icon == icon)
+ {
+ return;
+ }
+
+ /* Get rid of the existing stretch handles and put them on the new canvas. */
+ if (details->stretch_icon != NULL)
+ {
+ nautilus_canvas_item_set_show_stretch_handles
+ (details->stretch_icon->item, FALSE);
+ ungrab_stretch_icon (container);
+ emit_stretch_ended (container, details->stretch_icon);
+ }
+ nautilus_canvas_item_set_show_stretch_handles (icon->item, TRUE);
+ details->stretch_icon = icon;
+
+ icon_get_size (container, icon, &initial_size);
+
+ /* only need to keep size in one dimension, since they are constrained to be the same */
+ container->details->stretch_initial_x = icon->x;
+ container->details->stretch_initial_y = icon->y;
+ container->details->stretch_initial_size = initial_size;
+
+ emit_stretch_started (container, icon);
}
/**
* nautilus_canvas_container_has_stretch_handles
* @container: An canvas container widget.
- *
+ *
* Returns true if the first selected item has stretch handles.
**/
gboolean
nautilus_canvas_container_has_stretch_handles (NautilusCanvasContainer *container)
{
- NautilusCanvasIcon *icon;
+ NautilusCanvasIcon *icon;
- icon = get_first_selected_icon (container);
- if (icon == NULL) {
- return FALSE;
- }
+ icon = get_first_selected_icon (container);
+ if (icon == NULL)
+ {
+ return FALSE;
+ }
- return icon == container->details->stretch_icon;
+ return icon == container->details->stretch_icon;
}
/**
* nautilus_canvas_container_is_stretched
* @container: An canvas container widget.
- *
+ *
* Returns true if the any selected item is stretched to a size other than 1.0.
**/
gboolean
nautilus_canvas_container_is_stretched (NautilusCanvasContainer *container)
{
- GList *p;
- NautilusCanvasIcon *icon;
+ GList *p;
+ NautilusCanvasIcon *icon;
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
- if (icon->is_selected && icon->scale != 1.0) {
- return TRUE;
- }
- }
- return FALSE;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (icon->is_selected && icon->scale != 1.0)
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
}
/**
* nautilus_canvas_container_unstretch
* @container: An canvas container widget.
- *
+ *
* Gets rid of any canvas stretching.
**/
void
nautilus_canvas_container_unstretch (NautilusCanvasContainer *container)
{
- GList *p;
- NautilusCanvasIcon *icon;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
- if (icon->is_selected) {
- nautilus_canvas_container_move_icon (container, icon,
- icon->x, icon->y,
- 1.0,
- FALSE, TRUE, TRUE);
- }
- }
+ GList *p;
+ NautilusCanvasIcon *icon;
+
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (icon->is_selected)
+ {
+ nautilus_canvas_container_move_icon (container, icon,
+ icon->x, icon->y,
+ 1.0,
+ FALSE, TRUE, TRUE);
+ }
+ }
}
static void
compute_stretch (StretchState *start,
- StretchState *current)
-{
- gboolean right, bottom;
- int x_stretch, y_stretch;
-
- /* FIXME bugzilla.gnome.org 45390: This doesn't correspond to
- * the way the handles are drawn.
- */
- /* Figure out which handle we are dragging. */
- right = start->pointer_x > start->icon_x + (int) start->icon_size / 2;
- bottom = start->pointer_y > start->icon_y + (int) start->icon_size / 2;
-
- /* Figure out how big we should stretch. */
- x_stretch = start->pointer_x - current->pointer_x;
- y_stretch = start->pointer_y - current->pointer_y;
- if (right) {
- x_stretch = - x_stretch;
- }
- if (bottom) {
- y_stretch = - y_stretch;
- }
- current->icon_size = MAX ((int) start->icon_size + MIN (x_stretch, y_stretch),
- (int) NAUTILUS_CANVAS_ICON_SIZE_SMALL);
-
- /* Figure out where the corner of the icon should be. */
- current->icon_x = start->icon_x;
- if (!right) {
- current->icon_x += start->icon_size - current->icon_size;
- }
- current->icon_y = start->icon_y;
- if (!bottom) {
- current->icon_y += start->icon_size - current->icon_size;
- }
+ StretchState *current)
+{
+ gboolean right, bottom;
+ int x_stretch, y_stretch;
+
+ /* FIXME bugzilla.gnome.org 45390: This doesn't correspond to
+ * the way the handles are drawn.
+ */
+ /* Figure out which handle we are dragging. */
+ right = start->pointer_x > start->icon_x + (int) start->icon_size / 2;
+ bottom = start->pointer_y > start->icon_y + (int) start->icon_size / 2;
+
+ /* Figure out how big we should stretch. */
+ x_stretch = start->pointer_x - current->pointer_x;
+ y_stretch = start->pointer_y - current->pointer_y;
+ if (right)
+ {
+ x_stretch = -x_stretch;
+ }
+ if (bottom)
+ {
+ y_stretch = -y_stretch;
+ }
+ current->icon_size = MAX ((int) start->icon_size + MIN (x_stretch, y_stretch),
+ (int) NAUTILUS_CANVAS_ICON_SIZE_SMALL);
+
+ /* Figure out where the corner of the icon should be. */
+ current->icon_x = start->icon_x;
+ if (!right)
+ {
+ current->icon_x += start->icon_size - current->icon_size;
+ }
+ current->icon_y = start->icon_y;
+ if (!bottom)
+ {
+ current->icon_y += start->icon_size - current->icon_size;
+ }
}
char *
nautilus_canvas_container_get_icon_uri (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- char *uri;
+ char *uri;
- uri = NULL;
- g_signal_emit (container,
- signals[GET_ICON_URI], 0,
- icon->data,
- &uri);
- return uri;
+ uri = NULL;
+ g_signal_emit (container,
+ signals[GET_ICON_URI], 0,
+ icon->data,
+ &uri);
+ return uri;
}
char *
nautilus_canvas_container_get_icon_activation_uri (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- char *uri;
+ char *uri;
- uri = NULL;
- g_signal_emit (container,
- signals[GET_ICON_ACTIVATION_URI], 0,
- icon->data,
- &uri);
- return uri;
+ uri = NULL;
+ g_signal_emit (container,
+ signals[GET_ICON_ACTIVATION_URI], 0,
+ icon->data,
+ &uri);
+ return uri;
}
char *
nautilus_canvas_container_get_icon_drop_target_uri (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- char *uri;
+ char *uri;
- uri = NULL;
- g_signal_emit (container,
- signals[GET_ICON_DROP_TARGET_URI], 0,
- icon->data,
- &uri);
- return uri;
+ uri = NULL;
+ g_signal_emit (container,
+ signals[GET_ICON_DROP_TARGET_URI], 0,
+ icon->data,
+ &uri);
+ return uri;
}
/* Call to reset the scroll region only if the container is not empty,
@@ -6934,9 +7711,10 @@ nautilus_canvas_container_get_icon_drop_target_uri (NautilusCanvasContainer *con
static void
reset_scroll_region_if_not_empty (NautilusCanvasContainer *container)
{
- if (!nautilus_canvas_container_is_empty (container)) {
- nautilus_canvas_container_reset_scroll_region (container);
- }
+ if (!nautilus_canvas_container_is_empty (container))
+ {
+ nautilus_canvas_container_reset_scroll_region (container);
+ }
}
/* Switch from automatic layout to manual or vice versa.
@@ -6945,79 +7723,87 @@ reset_scroll_region_if_not_empty (NautilusCanvasContainer *container)
*/
void
nautilus_canvas_container_set_auto_layout (NautilusCanvasContainer *container,
- gboolean auto_layout)
+ gboolean auto_layout)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_return_if_fail (auto_layout == FALSE || auto_layout == TRUE);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (auto_layout == FALSE || auto_layout == TRUE);
- if (container->details->auto_layout == auto_layout) {
- return;
- }
+ if (container->details->auto_layout == auto_layout)
+ {
+ return;
+ }
- reset_scroll_region_if_not_empty (container);
- container->details->auto_layout = auto_layout;
+ reset_scroll_region_if_not_empty (container);
+ container->details->auto_layout = auto_layout;
- if (!auto_layout) {
- reload_icon_positions (container);
- nautilus_canvas_container_freeze_icon_positions (container);
- }
+ if (!auto_layout)
+ {
+ reload_icon_positions (container);
+ nautilus_canvas_container_freeze_icon_positions (container);
+ }
- container->details->needs_resort = TRUE;
- redo_layout (container);
+ container->details->needs_resort = TRUE;
+ redo_layout (container);
- g_signal_emit (container, signals[LAYOUT_CHANGED], 0);
+ g_signal_emit (container, signals[LAYOUT_CHANGED], 0);
}
gboolean
nautilus_canvas_container_is_keep_aligned (NautilusCanvasContainer *container)
{
- return container->details->keep_aligned;
+ return container->details->keep_aligned;
}
static gboolean
align_icons_callback (gpointer callback_data)
{
- NautilusCanvasContainer *container;
+ NautilusCanvasContainer *container;
- container = NAUTILUS_CANVAS_CONTAINER (callback_data);
- align_icons (container);
- container->details->align_idle_id = 0;
+ container = NAUTILUS_CANVAS_CONTAINER (callback_data);
+ align_icons (container);
+ container->details->align_idle_id = 0;
- return FALSE;
+ return FALSE;
}
static void
unschedule_align_icons (NautilusCanvasContainer *container)
{
- if (container->details->align_idle_id != 0) {
- g_source_remove (container->details->align_idle_id);
- container->details->align_idle_id = 0;
- }
+ if (container->details->align_idle_id != 0)
+ {
+ g_source_remove (container->details->align_idle_id);
+ container->details->align_idle_id = 0;
+ }
}
static void
schedule_align_icons (NautilusCanvasContainer *container)
{
- if (container->details->align_idle_id == 0
- && container->details->has_been_allocated) {
- container->details->align_idle_id = g_idle_add
- (align_icons_callback, container);
- }
+ if (container->details->align_idle_id == 0
+ && container->details->has_been_allocated)
+ {
+ container->details->align_idle_id = g_idle_add
+ (align_icons_callback, container);
+ }
}
void
nautilus_canvas_container_set_keep_aligned (NautilusCanvasContainer *container,
- gboolean keep_aligned)
+ gboolean keep_aligned)
{
- if (container->details->keep_aligned != keep_aligned) {
- container->details->keep_aligned = keep_aligned;
-
- if (keep_aligned && !container->details->auto_layout) {
- schedule_align_icons (container);
- } else {
- unschedule_align_icons (container);
- }
- }
+ if (container->details->keep_aligned != keep_aligned)
+ {
+ container->details->keep_aligned = keep_aligned;
+
+ if (keep_aligned && !container->details->auto_layout)
+ {
+ schedule_align_icons (container);
+ }
+ else
+ {
+ unschedule_align_icons (container);
+ }
+ }
}
/* Switch from automatic to manual layout, freezing all the icons in their
@@ -7027,142 +7813,147 @@ nautilus_canvas_container_set_keep_aligned (NautilusCanvasContainer *container,
void
nautilus_canvas_container_freeze_icon_positions (NautilusCanvasContainer *container)
{
- gboolean changed;
- GList *p;
- NautilusCanvasIcon *icon;
- NautilusCanvasPosition position;
+ gboolean changed;
+ GList *p;
+ NautilusCanvasIcon *icon;
+ NautilusCanvasPosition position;
- changed = container->details->auto_layout;
- container->details->auto_layout = FALSE;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
+ changed = container->details->auto_layout;
+ container->details->auto_layout = FALSE;
- position.x = icon->saved_ltr_x;
- position.y = icon->y;
- position.scale = icon->scale;
- g_signal_emit (container, signals[ICON_POSITION_CHANGED], 0,
- icon->data, &position);
- }
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
- if (changed) {
- g_signal_emit (container, signals[LAYOUT_CHANGED], 0);
- }
+ position.x = icon->saved_ltr_x;
+ position.y = icon->y;
+ position.scale = icon->scale;
+ g_signal_emit (container, signals[ICON_POSITION_CHANGED], 0,
+ icon->data, &position);
+ }
+
+ if (changed)
+ {
+ g_signal_emit (container, signals[LAYOUT_CHANGED], 0);
+ }
}
/* Re-sort, switching to automatic layout if it was in manual layout. */
void
nautilus_canvas_container_sort (NautilusCanvasContainer *container)
{
- gboolean changed;
+ gboolean changed;
- changed = !container->details->auto_layout;
- container->details->auto_layout = TRUE;
+ changed = !container->details->auto_layout;
+ container->details->auto_layout = TRUE;
- reset_scroll_region_if_not_empty (container);
- container->details->needs_resort = TRUE;
- redo_layout (container);
+ reset_scroll_region_if_not_empty (container);
+ container->details->needs_resort = TRUE;
+ redo_layout (container);
- if (changed) {
- g_signal_emit (container, signals[LAYOUT_CHANGED], 0);
- }
+ if (changed)
+ {
+ g_signal_emit (container, signals[LAYOUT_CHANGED], 0);
+ }
}
gboolean
nautilus_canvas_container_is_auto_layout (NautilusCanvasContainer *container)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
- return container->details->auto_layout;
+ return container->details->auto_layout;
}
void
nautilus_canvas_container_set_single_click_mode (NautilusCanvasContainer *container,
- gboolean single_click_mode)
+ gboolean single_click_mode)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- container->details->single_click_mode = single_click_mode;
+ container->details->single_click_mode = single_click_mode;
}
/* Return if the canvas container is a fixed size */
gboolean
nautilus_canvas_container_get_is_fixed_size (NautilusCanvasContainer *container)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
- return container->details->is_fixed_size;
+ return container->details->is_fixed_size;
}
/* Set the canvas container to be a fixed size */
void
nautilus_canvas_container_set_is_fixed_size (NautilusCanvasContainer *container,
- gboolean is_fixed_size)
+ gboolean is_fixed_size)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- container->details->is_fixed_size = is_fixed_size;
+ container->details->is_fixed_size = is_fixed_size;
}
gboolean
nautilus_canvas_container_get_is_desktop (NautilusCanvasContainer *container)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
- return container->details->is_desktop;
+ return container->details->is_desktop;
}
void
nautilus_canvas_container_set_is_desktop (NautilusCanvasContainer *container,
- gboolean is_desktop)
+ gboolean is_desktop)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- container->details->is_desktop = is_desktop;
+ container->details->is_desktop = is_desktop;
- if (is_desktop) {
- GtkStyleContext *context;
+ if (is_desktop)
+ {
+ GtkStyleContext *context;
- context = gtk_widget_get_style_context (GTK_WIDGET (container));
- gtk_style_context_add_class (context, "nautilus-desktop");
- }
+ context = gtk_widget_get_style_context (GTK_WIDGET (container));
+ gtk_style_context_add_class (context, "nautilus-desktop");
+ }
}
void
nautilus_canvas_container_set_margins (NautilusCanvasContainer *container,
- int left_margin,
- int right_margin,
- int top_margin,
- int bottom_margin)
+ int left_margin,
+ int right_margin,
+ int top_margin,
+ int bottom_margin)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- container->details->left_margin = left_margin;
- container->details->right_margin = right_margin;
- container->details->top_margin = top_margin;
- container->details->bottom_margin = bottom_margin;
+ container->details->left_margin = left_margin;
+ container->details->right_margin = right_margin;
+ container->details->top_margin = top_margin;
+ container->details->bottom_margin = bottom_margin;
- /* redo layout of icons as the margins have changed */
- schedule_redo_layout (container);
+ /* redo layout of icons as the margins have changed */
+ schedule_redo_layout (container);
}
/* handle theme changes */
void
nautilus_canvas_container_set_font (NautilusCanvasContainer *container,
- const char *font)
+ const char *font)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- if (g_strcmp0 (container->details->font, font) == 0) {
- return;
- }
+ if (g_strcmp0 (container->details->font, font) == 0)
+ {
+ return;
+ }
- g_free (container->details->font);
- container->details->font = g_strdup (font);
+ g_free (container->details->font);
+ container->details->font = g_strdup (font);
- nautilus_canvas_container_request_update_all_internal (container, TRUE);
- gtk_widget_queue_draw (GTK_WIDGET (container));
+ nautilus_canvas_container_request_update_all_internal (container, TRUE);
+ gtk_widget_queue_draw (GTK_WIDGET (container));
}
/**
@@ -7172,19 +7963,22 @@ nautilus_canvas_container_set_font (NautilusCanvasContainer *container,
*
* Gets the description for the icon. This function may return NULL.
**/
-char*
+char *
nautilus_canvas_container_get_icon_description (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
+ NautilusCanvasIconData *data)
{
- NautilusCanvasContainerClass *klass;
+ NautilusCanvasContainerClass *klass;
- klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
+ klass = NAUTILUS_CANVAS_CONTAINER_GET_CLASS (container);
- if (klass->get_icon_description) {
- return klass->get_icon_description (container, data);
- } else {
- return NULL;
- }
+ if (klass->get_icon_description)
+ {
+ return klass->get_icon_description (container, data);
+ }
+ else
+ {
+ return NULL;
+ }
}
/**
@@ -7195,29 +7989,30 @@ nautilus_canvas_container_get_icon_description (NautilusCanvasContainer *contain
**/
void
nautilus_canvas_container_set_highlighted_for_clipboard (NautilusCanvasContainer *container,
- GList *clipboard_canvas_data)
+ GList *clipboard_canvas_data)
{
- GList *l;
- NautilusCanvasIcon *icon;
- gboolean highlighted_for_clipboard;
-
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ GList *l;
+ NautilusCanvasIcon *icon;
+ gboolean highlighted_for_clipboard;
- for (l = container->details->icons; l != NULL; l = l->next) {
- icon = l->data;
- highlighted_for_clipboard = (g_list_find (clipboard_canvas_data, icon->data) != NULL);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
- "highlighted-for-clipboard", highlighted_for_clipboard,
- NULL);
- }
+ for (l = container->details->icons; l != NULL; l = l->next)
+ {
+ icon = l->data;
+ highlighted_for_clipboard = (g_list_find (clipboard_canvas_data, icon->data) != NULL);
+ eel_canvas_item_set (EEL_CANVAS_ITEM (icon->item),
+ "highlighted-for-clipboard", highlighted_for_clipboard,
+ NULL);
+ }
}
/* NautilusCanvasContainerAccessible */
-typedef struct {
- EelCanvasAccessible parent;
- NautilusCanvasContainerAccessiblePrivate *priv;
+typedef struct
+{
+ EelCanvasAccessible parent;
+ NautilusCanvasContainerAccessiblePrivate *priv;
} NautilusCanvasContainerAccessible;
typedef EelCanvasAccessibleClass NautilusCanvasContainerAccessibleClass;
@@ -7226,107 +8021,122 @@ typedef EelCanvasAccessibleClass NautilusCanvasContainerAccessibleClass;
/* AtkAction interface */
static gboolean
-nautilus_canvas_container_accessible_do_action (AtkAction *accessible, int i)
-{
- GtkWidget *widget;
- NautilusCanvasContainer *container;
- GList *selection;
-
- g_return_val_if_fail (i < LAST_ACTION, FALSE);
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- switch (i) {
- case ACTION_ACTIVATE :
- selection = nautilus_canvas_container_get_selection (container);
-
- if (selection) {
- g_signal_emit_by_name (container, "activate", selection);
- g_list_free (selection);
- }
- break;
- case ACTION_MENU :
- handle_popups (container, NULL,"context_click_background");
- break;
- default :
- g_warning ("Invalid action passed to NautilusCanvasContainerAccessible::do_action");
- return FALSE;
- }
- return TRUE;
+nautilus_canvas_container_accessible_do_action (AtkAction *accessible,
+ int i)
+{
+ GtkWidget *widget;
+ NautilusCanvasContainer *container;
+ GList *selection;
+
+ g_return_val_if_fail (i < LAST_ACTION, FALSE);
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ switch (i)
+ {
+ case ACTION_ACTIVATE:
+ {
+ selection = nautilus_canvas_container_get_selection (container);
+
+ if (selection)
+ {
+ g_signal_emit_by_name (container, "activate", selection);
+ g_list_free (selection);
+ }
+ }
+ break;
+
+ case ACTION_MENU:
+ {
+ handle_popups (container, NULL, "context_click_background");
+ }
+ break;
+
+ default:
+ g_warning ("Invalid action passed to NautilusCanvasContainerAccessible::do_action");
+ return FALSE;
+ }
+ return TRUE;
}
static int
nautilus_canvas_container_accessible_get_n_actions (AtkAction *accessible)
{
- return LAST_ACTION;
+ return LAST_ACTION;
}
static const char *
nautilus_canvas_container_accessible_action_get_description (AtkAction *accessible,
- int i)
+ int i)
{
- NautilusCanvasContainerAccessiblePrivate *priv;
+ NautilusCanvasContainerAccessiblePrivate *priv;
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- priv = GET_ACCESSIBLE_PRIV (accessible);
+ priv = GET_ACCESSIBLE_PRIV (accessible);
- if (priv->action_descriptions[i]) {
- return priv->action_descriptions[i];
- } else {
- return nautilus_canvas_container_accessible_action_descriptions[i];
- }
+ if (priv->action_descriptions[i])
+ {
+ return priv->action_descriptions[i];
+ }
+ else
+ {
+ return nautilus_canvas_container_accessible_action_descriptions[i];
+ }
}
static const char *
-nautilus_canvas_container_accessible_action_get_name (AtkAction *accessible, int i)
+nautilus_canvas_container_accessible_action_get_name (AtkAction *accessible,
+ int i)
{
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- return nautilus_canvas_container_accessible_action_names[i];
+ return nautilus_canvas_container_accessible_action_names[i];
}
static const char *
-nautilus_canvas_container_accessible_action_get_keybinding (AtkAction *accessible,
- int i)
+nautilus_canvas_container_accessible_action_get_keybinding (AtkAction *accessible,
+ int i)
{
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- return NULL;
+ return NULL;
}
static gboolean
-nautilus_canvas_container_accessible_action_set_description (AtkAction *accessible,
- int i,
- const char *description)
+nautilus_canvas_container_accessible_action_set_description (AtkAction *accessible,
+ int i,
+ const char *description)
{
- NautilusCanvasContainerAccessiblePrivate *priv;
+ NautilusCanvasContainerAccessiblePrivate *priv;
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- priv = GET_ACCESSIBLE_PRIV (accessible);
+ priv = GET_ACCESSIBLE_PRIV (accessible);
- if (priv->action_descriptions[i]) {
- g_free (priv->action_descriptions[i]);
- }
- priv->action_descriptions[i] = g_strdup (description);
+ if (priv->action_descriptions[i])
+ {
+ g_free (priv->action_descriptions[i]);
+ }
+ priv->action_descriptions[i] = g_strdup (description);
- return FALSE;
+ return FALSE;
}
static void
nautilus_canvas_container_accessible_action_interface_init (AtkActionIface *iface)
{
- iface->do_action = nautilus_canvas_container_accessible_do_action;
- iface->get_n_actions = nautilus_canvas_container_accessible_get_n_actions;
- iface->get_description = nautilus_canvas_container_accessible_action_get_description;
- iface->get_name = nautilus_canvas_container_accessible_action_get_name;
- iface->get_keybinding = nautilus_canvas_container_accessible_action_get_keybinding;
- iface->set_description = nautilus_canvas_container_accessible_action_set_description;
+ iface->do_action = nautilus_canvas_container_accessible_do_action;
+ iface->get_n_actions = nautilus_canvas_container_accessible_get_n_actions;
+ iface->get_description = nautilus_canvas_container_accessible_action_get_description;
+ iface->get_name = nautilus_canvas_container_accessible_action_get_name;
+ iface->get_keybinding = nautilus_canvas_container_accessible_action_get_keybinding;
+ iface->set_description = nautilus_canvas_container_accessible_action_set_description;
}
/* AtkSelection interface */
@@ -7334,551 +8144,593 @@ nautilus_canvas_container_accessible_action_interface_init (AtkActionIface *ifac
static void
nautilus_canvas_container_accessible_update_selection (AtkObject *accessible)
{
- NautilusCanvasContainer *container;
- NautilusCanvasContainerAccessiblePrivate *priv;
+ NautilusCanvasContainer *container;
+ NautilusCanvasContainerAccessiblePrivate *priv;
- container = NAUTILUS_CANVAS_CONTAINER (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
- priv = GET_ACCESSIBLE_PRIV (accessible);
+ container = NAUTILUS_CANVAS_CONTAINER (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
+ priv = GET_ACCESSIBLE_PRIV (accessible);
- if (priv->selection) {
- g_list_free (priv->selection);
- priv->selection = NULL;
- }
+ if (priv->selection)
+ {
+ g_list_free (priv->selection);
+ priv->selection = NULL;
+ }
- priv->selection = nautilus_canvas_container_get_selected_icons (container);
+ priv->selection = nautilus_canvas_container_get_selected_icons (container);
}
static void
nautilus_canvas_container_accessible_selection_changed_cb (NautilusCanvasContainer *container,
- gpointer data)
+ gpointer data)
{
- g_signal_emit_by_name (data, "selection-changed");
+ g_signal_emit_by_name (data, "selection-changed");
}
static void
nautilus_canvas_container_accessible_icon_added_cb (NautilusCanvasContainer *container,
- NautilusCanvasIconData *icon_data,
- gpointer data)
+ NautilusCanvasIconData *icon_data,
+ gpointer data)
{
- NautilusCanvasIcon *icon;
- AtkObject *atk_parent;
- AtkObject *atk_child;
+ NautilusCanvasIcon *icon;
+ AtkObject *atk_parent;
+ AtkObject *atk_child;
+
+ icon = g_hash_table_lookup (container->details->icon_set, icon_data);
+ if (icon)
+ {
+ atk_parent = ATK_OBJECT (data);
+ atk_child = atk_gobject_accessible_for_object
+ (G_OBJECT (icon->item));
- icon = g_hash_table_lookup (container->details->icon_set, icon_data);
- if (icon) {
- atk_parent = ATK_OBJECT (data);
- atk_child = atk_gobject_accessible_for_object
- (G_OBJECT (icon->item));
-
- g_signal_emit_by_name (atk_parent, "children-changed::add",
- icon->position, atk_child, NULL);
- }
+ g_signal_emit_by_name (atk_parent, "children-changed::add",
+ icon->position, atk_child, NULL);
+ }
}
static void
nautilus_canvas_container_accessible_icon_removed_cb (NautilusCanvasContainer *container,
- NautilusCanvasIconData *icon_data,
- gpointer data)
-{
- NautilusCanvasIcon *icon;
- AtkObject *atk_parent;
- AtkObject *atk_child;
-
- icon = g_hash_table_lookup (container->details->icon_set, icon_data);
- if (icon) {
- atk_parent = ATK_OBJECT (data);
- atk_child = atk_gobject_accessible_for_object
- (G_OBJECT (icon->item));
-
- g_signal_emit_by_name (atk_parent, "children-changed::remove",
- icon->position, atk_child, NULL);
- }
+ NautilusCanvasIconData *icon_data,
+ gpointer data)
+{
+ NautilusCanvasIcon *icon;
+ AtkObject *atk_parent;
+ AtkObject *atk_child;
+
+ icon = g_hash_table_lookup (container->details->icon_set, icon_data);
+ if (icon)
+ {
+ atk_parent = ATK_OBJECT (data);
+ atk_child = atk_gobject_accessible_for_object
+ (G_OBJECT (icon->item));
+
+ g_signal_emit_by_name (atk_parent, "children-changed::remove",
+ icon->position, atk_child, NULL);
+ }
}
static void
-nautilus_canvas_container_accessible_cleared_cb (NautilusCanvasContainer *container,
- gpointer data)
+nautilus_canvas_container_accessible_cleared_cb (NautilusCanvasContainer *container,
+ gpointer data)
{
- g_signal_emit_by_name (data, "children-changed", 0, NULL, NULL);
+ g_signal_emit_by_name (data, "children-changed", 0, NULL, NULL);
}
-static gboolean
-nautilus_canvas_container_accessible_add_selection (AtkSelection *accessible,
- int i)
-{
- GtkWidget *widget;
- NautilusCanvasContainer *container;
- GList *l;
- GList *selection;
- NautilusCanvasIcon *icon;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
-
- l = g_list_nth (container->details->icons, i);
- if (l) {
- icon = l->data;
-
- selection = nautilus_canvas_container_get_selection (container);
- selection = g_list_prepend (selection,
- icon->data);
- nautilus_canvas_container_set_selection (container, selection);
-
- g_list_free (selection);
- return TRUE;
- }
+static gboolean
+nautilus_canvas_container_accessible_add_selection (AtkSelection *accessible,
+ int i)
+{
+ GtkWidget *widget;
+ NautilusCanvasContainer *container;
+ GList *l;
+ GList *selection;
+ NautilusCanvasIcon *icon;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+
+ l = g_list_nth (container->details->icons, i);
+ if (l)
+ {
+ icon = l->data;
+
+ selection = nautilus_canvas_container_get_selection (container);
+ selection = g_list_prepend (selection,
+ icon->data);
+ nautilus_canvas_container_set_selection (container, selection);
+
+ g_list_free (selection);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
nautilus_canvas_container_accessible_clear_selection (AtkSelection *accessible)
{
- GtkWidget *widget;
- NautilusCanvasContainer *container;
+ GtkWidget *widget;
+ NautilusCanvasContainer *container;
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- nautilus_canvas_container_unselect_all (container);
+ nautilus_canvas_container_unselect_all (container);
- return TRUE;
+ return TRUE;
}
static AtkObject *
-nautilus_canvas_container_accessible_ref_selection (AtkSelection *accessible,
- int i)
-{
- NautilusCanvasContainerAccessiblePrivate *priv;
- AtkObject *atk_object;
- GList *item;
- NautilusCanvasIcon *icon;
-
- nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
- priv = GET_ACCESSIBLE_PRIV (accessible);
-
- item = (g_list_nth (priv->selection, i));
-
- if (item) {
- icon = item->data;
- atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
- if (atk_object) {
- g_object_ref (atk_object);
- }
+nautilus_canvas_container_accessible_ref_selection (AtkSelection *accessible,
+ int i)
+{
+ NautilusCanvasContainerAccessiblePrivate *priv;
+ AtkObject *atk_object;
+ GList *item;
+ NautilusCanvasIcon *icon;
+
+ nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
+ priv = GET_ACCESSIBLE_PRIV (accessible);
+
+ item = (g_list_nth (priv->selection, i));
+
+ if (item)
+ {
+ icon = item->data;
+ atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
+ if (atk_object)
+ {
+ g_object_ref (atk_object);
+ }
- return atk_object;
- } else {
- return NULL;
- }
+ return atk_object;
+ }
+ else
+ {
+ return NULL;
+ }
}
static int
nautilus_canvas_container_accessible_get_selection_count (AtkSelection *accessible)
{
- NautilusCanvasContainerAccessiblePrivate *priv;
- int count;
+ NautilusCanvasContainerAccessiblePrivate *priv;
+ int count;
- priv = GET_ACCESSIBLE_PRIV (accessible);
- nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
- count = g_list_length (priv->selection);
+ priv = GET_ACCESSIBLE_PRIV (accessible);
+ nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
+ count = g_list_length (priv->selection);
- return count;
+ return count;
}
static gboolean
nautilus_canvas_container_accessible_is_child_selected (AtkSelection *accessible,
- int i)
+ int i)
{
- NautilusCanvasContainer *container;
- GList *l;
- NautilusCanvasIcon *icon;
- GtkWidget *widget;
+ NautilusCanvasContainer *container;
+ GList *l;
+ NautilusCanvasIcon *icon;
+ GtkWidget *widget;
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- l = g_list_nth (container->details->icons, i);
- if (l) {
- icon = l->data;
- return icon->is_selected;
- }
- return FALSE;
+ l = g_list_nth (container->details->icons, i);
+ if (l)
+ {
+ icon = l->data;
+ return icon->is_selected;
+ }
+ return FALSE;
}
static gboolean
nautilus_canvas_container_accessible_remove_selection (AtkSelection *accessible,
- int i)
-{
- NautilusCanvasContainerAccessiblePrivate *priv;
- NautilusCanvasContainer *container;
- GList *l;
- GList *selection;
- NautilusCanvasIcon *icon;
- GtkWidget *widget;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
-
- priv = GET_ACCESSIBLE_PRIV (accessible);
- l = g_list_nth (priv->selection, i);
- if (l) {
- icon = l->data;
-
- selection = nautilus_canvas_container_get_selection (container);
- selection = g_list_remove (selection, icon->data);
- nautilus_canvas_container_set_selection (container, selection);
-
- g_list_free (selection);
- return TRUE;
- }
-
- return FALSE;
+ int i)
+{
+ NautilusCanvasContainerAccessiblePrivate *priv;
+ NautilusCanvasContainer *container;
+ GList *l;
+ GList *selection;
+ NautilusCanvasIcon *icon;
+ GtkWidget *widget;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ nautilus_canvas_container_accessible_update_selection (ATK_OBJECT (accessible));
+
+ priv = GET_ACCESSIBLE_PRIV (accessible);
+ l = g_list_nth (priv->selection, i);
+ if (l)
+ {
+ icon = l->data;
+
+ selection = nautilus_canvas_container_get_selection (container);
+ selection = g_list_remove (selection, icon->data);
+ nautilus_canvas_container_set_selection (container, selection);
+
+ g_list_free (selection);
+ return TRUE;
+ }
+
+ return FALSE;
}
static gboolean
nautilus_canvas_container_accessible_select_all_selection (AtkSelection *accessible)
{
- NautilusCanvasContainer *container;
- GtkWidget *widget;
+ NautilusCanvasContainer *container;
+ GtkWidget *widget;
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- nautilus_canvas_container_select_all (container);
+ nautilus_canvas_container_select_all (container);
- return TRUE;
+ return TRUE;
}
void
nautilus_canvas_container_widget_to_file_operation_position (NautilusCanvasContainer *container,
- GdkPoint *position)
+ GdkPoint *position)
{
- double x, y;
+ double x, y;
- g_return_if_fail (position != NULL);
+ g_return_if_fail (position != NULL);
- x = position->x;
- y = position->y;
+ x = position->x;
+ y = position->y;
- eel_canvas_window_to_world (EEL_CANVAS (container), x, y, &x, &y);
+ eel_canvas_window_to_world (EEL_CANVAS (container), x, y, &x, &y);
- position->x = (int) x;
- position->y = (int) y;
+ position->x = (int) x;
+ position->y = (int) y;
- /* ensure that we end up in the middle of the icon */
- position->x -= nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level) / 2;
- position->y -= nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level) / 2;
+ /* ensure that we end up in the middle of the icon */
+ position->x -= nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level) / 2;
+ position->y -= nautilus_canvas_container_get_icon_size_for_zoom_level (container->details->zoom_level) / 2;
}
-static void
+static void
nautilus_canvas_container_accessible_selection_interface_init (AtkSelectionIface *iface)
{
- iface->add_selection = nautilus_canvas_container_accessible_add_selection;
- iface->clear_selection = nautilus_canvas_container_accessible_clear_selection;
- iface->ref_selection = nautilus_canvas_container_accessible_ref_selection;
- iface->get_selection_count = nautilus_canvas_container_accessible_get_selection_count;
- iface->is_child_selected = nautilus_canvas_container_accessible_is_child_selected;
- iface->remove_selection = nautilus_canvas_container_accessible_remove_selection;
- iface->select_all_selection = nautilus_canvas_container_accessible_select_all_selection;
+ iface->add_selection = nautilus_canvas_container_accessible_add_selection;
+ iface->clear_selection = nautilus_canvas_container_accessible_clear_selection;
+ iface->ref_selection = nautilus_canvas_container_accessible_ref_selection;
+ iface->get_selection_count = nautilus_canvas_container_accessible_get_selection_count;
+ iface->is_child_selected = nautilus_canvas_container_accessible_is_child_selected;
+ iface->remove_selection = nautilus_canvas_container_accessible_remove_selection;
+ iface->select_all_selection = nautilus_canvas_container_accessible_select_all_selection;
}
-static gint
+static gint
nautilus_canvas_container_accessible_get_n_children (AtkObject *accessible)
{
- NautilusCanvasContainer *container;
- GtkWidget *widget;
- gint i;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return FALSE;
- }
+ NautilusCanvasContainer *container;
+ GtkWidget *widget;
+ gint i;
- container = NAUTILUS_CANVAS_CONTAINER (widget);
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
+ return FALSE;
+ }
- i = g_hash_table_size (container->details->icon_set);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
- return i;
+ i = g_hash_table_size (container->details->icon_set);
+
+ return i;
}
-static AtkObject*
-nautilus_canvas_container_accessible_ref_child (AtkObject *accessible, int i)
-{
- AtkObject *atk_object;
- NautilusCanvasContainer *container;
- GList *item;
- NautilusCanvasIcon *icon;
- GtkWidget *widget;
-
- widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
- if (!widget) {
- return NULL;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
-
- item = (g_list_nth (container->details->icons, i));
-
- if (item) {
- icon = item->data;
-
- atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
- g_object_ref (atk_object);
-
- return atk_object;
- }
+static AtkObject *
+nautilus_canvas_container_accessible_ref_child (AtkObject *accessible,
+ int i)
+{
+ AtkObject *atk_object;
+ NautilusCanvasContainer *container;
+ GList *item;
+ NautilusCanvasIcon *icon;
+ GtkWidget *widget;
+
+ widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
+ if (!widget)
+ {
return NULL;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+
+ item = (g_list_nth (container->details->icons, i));
+
+ if (item)
+ {
+ icon = item->data;
+
+ atk_object = atk_gobject_accessible_for_object (G_OBJECT (icon->item));
+ g_object_ref (atk_object);
+
+ return atk_object;
+ }
+ return NULL;
}
G_DEFINE_TYPE_WITH_CODE (NautilusCanvasContainerAccessible, nautilus_canvas_container_accessible,
- eel_canvas_accessible_get_type (),
- G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, nautilus_canvas_container_accessible_action_interface_init)
- G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, nautilus_canvas_container_accessible_selection_interface_init))
+ eel_canvas_accessible_get_type (),
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, nautilus_canvas_container_accessible_action_interface_init)
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_SELECTION, nautilus_canvas_container_accessible_selection_interface_init))
static void
nautilus_canvas_container_accessible_initialize (AtkObject *accessible,
- gpointer data)
-{
- NautilusCanvasContainer *container;
-
- if (ATK_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->initialize) {
- ATK_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->initialize (accessible, data);
- }
-
- if (GTK_IS_ACCESSIBLE (accessible)) {
- nautilus_canvas_container_accessible_update_selection
- (ATK_OBJECT (accessible));
-
- container = NAUTILUS_CANVAS_CONTAINER (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
- g_signal_connect (container, "selection-changed",
- G_CALLBACK (nautilus_canvas_container_accessible_selection_changed_cb),
- accessible);
- g_signal_connect (container, "icon-added",
- G_CALLBACK (nautilus_canvas_container_accessible_icon_added_cb),
- accessible);
- g_signal_connect (container, "icon-removed",
- G_CALLBACK (nautilus_canvas_container_accessible_icon_removed_cb),
- accessible);
- g_signal_connect (container, "cleared",
- G_CALLBACK (nautilus_canvas_container_accessible_cleared_cb),
- accessible);
- }
+ gpointer data)
+{
+ NautilusCanvasContainer *container;
+
+ if (ATK_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->initialize)
+ {
+ ATK_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->initialize (accessible, data);
+ }
+
+ if (GTK_IS_ACCESSIBLE (accessible))
+ {
+ nautilus_canvas_container_accessible_update_selection
+ (ATK_OBJECT (accessible));
+
+ container = NAUTILUS_CANVAS_CONTAINER (gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)));
+ g_signal_connect (container, "selection-changed",
+ G_CALLBACK (nautilus_canvas_container_accessible_selection_changed_cb),
+ accessible);
+ g_signal_connect (container, "icon-added",
+ G_CALLBACK (nautilus_canvas_container_accessible_icon_added_cb),
+ accessible);
+ g_signal_connect (container, "icon-removed",
+ G_CALLBACK (nautilus_canvas_container_accessible_icon_removed_cb),
+ accessible);
+ g_signal_connect (container, "cleared",
+ G_CALLBACK (nautilus_canvas_container_accessible_cleared_cb),
+ accessible);
+ }
}
static void
nautilus_canvas_container_accessible_finalize (GObject *object)
{
- NautilusCanvasContainerAccessiblePrivate *priv;
- int i;
+ NautilusCanvasContainerAccessiblePrivate *priv;
+ int i;
- priv = GET_ACCESSIBLE_PRIV (object);
+ priv = GET_ACCESSIBLE_PRIV (object);
- if (priv->selection) {
- g_list_free (priv->selection);
- }
+ if (priv->selection)
+ {
+ g_list_free (priv->selection);
+ }
- for (i = 0; i < LAST_ACTION; i++) {
- if (priv->action_descriptions[i]) {
- g_free (priv->action_descriptions[i]);
- }
- }
+ for (i = 0; i < LAST_ACTION; i++)
+ {
+ if (priv->action_descriptions[i])
+ {
+ g_free (priv->action_descriptions[i]);
+ }
+ }
- G_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_canvas_container_accessible_parent_class)->finalize (object);
}
static void
nautilus_canvas_container_accessible_init (NautilusCanvasContainerAccessible *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_canvas_container_accessible_get_type (),
- NautilusCanvasContainerAccessiblePrivate);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_canvas_container_accessible_get_type (),
+ NautilusCanvasContainerAccessiblePrivate);
}
static void
nautilus_canvas_container_accessible_class_init (NautilusCanvasContainerAccessibleClass *klass)
{
- AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->finalize = nautilus_canvas_container_accessible_finalize;
+ gobject_class->finalize = nautilus_canvas_container_accessible_finalize;
- atk_class->get_n_children = nautilus_canvas_container_accessible_get_n_children;
- atk_class->ref_child = nautilus_canvas_container_accessible_ref_child;
- atk_class->initialize = nautilus_canvas_container_accessible_initialize;
+ atk_class->get_n_children = nautilus_canvas_container_accessible_get_n_children;
+ atk_class->ref_child = nautilus_canvas_container_accessible_ref_child;
+ atk_class->initialize = nautilus_canvas_container_accessible_initialize;
- g_type_class_add_private (klass, sizeof (NautilusCanvasContainerAccessiblePrivate));
+ g_type_class_add_private (klass, sizeof (NautilusCanvasContainerAccessiblePrivate));
}
gboolean
nautilus_canvas_container_is_layout_rtl (NautilusCanvasContainer *container)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), 0);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), 0);
- return (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL);
+ return (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL);
}
gboolean
nautilus_canvas_container_is_layout_vertical (NautilusCanvasContainer *container)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), FALSE);
- /* we only do vertical layout in the desktop nowadays */
- return container->details->is_desktop;
+ /* we only do vertical layout in the desktop nowadays */
+ return container->details->is_desktop;
}
int
-nautilus_canvas_container_get_max_layout_lines_for_pango (NautilusCanvasContainer *container)
+nautilus_canvas_container_get_max_layout_lines_for_pango (NautilusCanvasContainer *container)
{
- int limit;
+ int limit;
- if (nautilus_canvas_container_get_is_desktop (container)) {
- limit = desktop_text_ellipsis_limit;
- } else {
- limit = text_ellipsis_limits[container->details->zoom_level];
- }
+ if (nautilus_canvas_container_get_is_desktop (container))
+ {
+ limit = desktop_text_ellipsis_limit;
+ }
+ else
+ {
+ limit = text_ellipsis_limits[container->details->zoom_level];
+ }
- if (limit <= 0) {
- return G_MININT;
- }
+ if (limit <= 0)
+ {
+ return G_MININT;
+ }
- return -limit;
+ return -limit;
}
int
-nautilus_canvas_container_get_max_layout_lines (NautilusCanvasContainer *container)
+nautilus_canvas_container_get_max_layout_lines (NautilusCanvasContainer *container)
{
- int limit;
+ int limit;
- if (nautilus_canvas_container_get_is_desktop (container)) {
- limit = desktop_text_ellipsis_limit;
- } else {
- limit = text_ellipsis_limits[container->details->zoom_level];
- }
+ if (nautilus_canvas_container_get_is_desktop (container))
+ {
+ limit = desktop_text_ellipsis_limit;
+ }
+ else
+ {
+ limit = text_ellipsis_limits[container->details->zoom_level];
+ }
- if (limit <= 0) {
- return G_MAXINT;
- }
+ if (limit <= 0)
+ {
+ return G_MAXINT;
+ }
- return limit;
+ return limit;
}
void
nautilus_canvas_container_begin_loading (NautilusCanvasContainer *container)
{
- gboolean dummy;
+ gboolean dummy;
- if (nautilus_canvas_container_get_store_layout_timestamps (container)) {
- container->details->layout_timestamp = UNDEFINED_TIME;
- g_signal_emit (container,
- signals[GET_STORED_LAYOUT_TIMESTAMP], 0,
- NULL, &container->details->layout_timestamp, &dummy);
- }
+ if (nautilus_canvas_container_get_store_layout_timestamps (container))
+ {
+ container->details->layout_timestamp = UNDEFINED_TIME;
+ g_signal_emit (container,
+ signals[GET_STORED_LAYOUT_TIMESTAMP], 0,
+ NULL, &container->details->layout_timestamp, &dummy);
+ }
}
static void
store_layout_timestamps_now (NautilusCanvasContainer *container)
{
- NautilusCanvasIcon *icon;
- GList *p;
- gboolean dummy;
+ NautilusCanvasIcon *icon;
+ GList *p;
+ gboolean dummy;
- container->details->layout_timestamp = time (NULL);
- g_signal_emit (container,
- signals[STORE_LAYOUT_TIMESTAMP], 0,
- NULL, &container->details->layout_timestamp, &dummy);
+ container->details->layout_timestamp = time (NULL);
+ g_signal_emit (container,
+ signals[STORE_LAYOUT_TIMESTAMP], 0,
+ NULL, &container->details->layout_timestamp, &dummy);
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
- g_signal_emit (container,
- signals[STORE_LAYOUT_TIMESTAMP], 0,
- icon->data, &container->details->layout_timestamp, &dummy);
- }
+ g_signal_emit (container,
+ signals[STORE_LAYOUT_TIMESTAMP], 0,
+ icon->data, &container->details->layout_timestamp, &dummy);
+ }
}
void
nautilus_canvas_container_end_loading (NautilusCanvasContainer *container,
- gboolean all_icons_added)
-{
- if (all_icons_added &&
- nautilus_canvas_container_get_store_layout_timestamps (container)) {
- if (container->details->new_icons == NULL) {
- store_layout_timestamps_now (container);
- } else {
- container->details->store_layout_timestamps_when_finishing_new_icons = TRUE;
- }
- }
+ gboolean all_icons_added)
+{
+ if (all_icons_added &&
+ nautilus_canvas_container_get_store_layout_timestamps (container))
+ {
+ if (container->details->new_icons == NULL)
+ {
+ store_layout_timestamps_now (container);
+ }
+ else
+ {
+ container->details->store_layout_timestamps_when_finishing_new_icons = TRUE;
+ }
+ }
}
gboolean
nautilus_canvas_container_get_store_layout_timestamps (NautilusCanvasContainer *container)
{
- return container->details->store_layout_timestamps;
+ return container->details->store_layout_timestamps;
}
void
nautilus_canvas_container_set_store_layout_timestamps (NautilusCanvasContainer *container,
- gboolean store_layout_timestamps)
+ gboolean store_layout_timestamps)
{
- container->details->store_layout_timestamps = store_layout_timestamps;
+ container->details->store_layout_timestamps = store_layout_timestamps;
}
-#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
static char *
-check_compute_stretch (int icon_x, int icon_y, int icon_size,
- int start_pointer_x, int start_pointer_y,
- int end_pointer_x, int end_pointer_y)
+check_compute_stretch (int icon_x,
+ int icon_y,
+ int icon_size,
+ int start_pointer_x,
+ int start_pointer_y,
+ int end_pointer_x,
+ int end_pointer_y)
{
- StretchState start, current;
+ StretchState start, current;
- start.icon_x = icon_x;
- start.icon_y = icon_y;
- start.icon_size = icon_size;
- start.pointer_x = start_pointer_x;
- start.pointer_y = start_pointer_y;
- current.pointer_x = end_pointer_x;
- current.pointer_y = end_pointer_y;
+ start.icon_x = icon_x;
+ start.icon_y = icon_y;
+ start.icon_size = icon_size;
+ start.pointer_x = start_pointer_x;
+ start.pointer_y = start_pointer_y;
+ current.pointer_x = end_pointer_x;
+ current.pointer_y = end_pointer_y;
- compute_stretch (&start, &current);
+ compute_stretch (&start, &current);
- return g_strdup_printf ("%d,%d:%d",
- current.icon_x,
- current.icon_y,
- current.icon_size);
+ return g_strdup_printf ("%d,%d:%d",
+ current.icon_x,
+ current.icon_y,
+ current.icon_size);
}
void
nautilus_self_check_canvas_container (void)
{
- EEL_CHECK_STRING_RESULT (check_compute_stretch (0, 0, 64, 0, 0, 0, 0), "0,0:64");
- EEL_CHECK_STRING_RESULT (check_compute_stretch (0, 0, 64, 64, 64, 65, 65), "0,0:65");
- EEL_CHECK_STRING_RESULT (check_compute_stretch (0, 0, 64, 64, 64, 65, 64), "0,0:64");
- EEL_CHECK_STRING_RESULT (check_compute_stretch (100, 100, 64, 105, 105, 40, 40), "35,35:129");
+ EEL_CHECK_STRING_RESULT (check_compute_stretch (0, 0, 64, 0, 0, 0, 0), "0,0:64");
+ EEL_CHECK_STRING_RESULT (check_compute_stretch (0, 0, 64, 64, 64, 65, 65), "0,0:65");
+ EEL_CHECK_STRING_RESULT (check_compute_stretch (0, 0, 64, 64, 64, 65, 64), "0,0:64");
+ EEL_CHECK_STRING_RESULT (check_compute_stretch (100, 100, 64, 105, 105, 40, 40), "35,35:129");
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/nautilus-canvas-dnd.c b/src/nautilus-canvas-dnd.c
index 39b68af93..ae8a2e282 100644
--- a/src/nautilus-canvas-dnd.c
+++ b/src/nautilus-canvas-dnd.c
@@ -1,32 +1,31 @@
-
/* nautilus-canvas-dnd.c - Drag & drop handling for the canvas container widget.
-
- Copyright (C) 1999, 2000 Free Software Foundation
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Ettore Perazzoli <ettore@gnu.org>,
- Darin Adler <darin@bentspoon.com>,
- Andy Hertzfeld <andy@eazel.com>
- Pavel Cisler <pavel@eazel.com>
-
-
- XDS support: Benedikt Meurer <benny@xfce.org> (adapted by Amos Brocco <amos.brocco@unifr.ch>)
-
-*/
+ *
+ * Copyright (C) 1999, 2000 Free Software Foundation
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Ettore Perazzoli <ettore@gnu.org>,
+ * Darin Adler <darin@bentspoon.com>,
+ * Andy Hertzfeld <andy@eazel.com>
+ * Pavel Cisler <pavel@eazel.com>
+ *
+ *
+ * XDS support: Benedikt Meurer <benny@xfce.org> (adapted by Amos Brocco <amos.brocco@unifr.ch>)
+ *
+ */
#include <config.h>
@@ -60,104 +59,114 @@
#define DEBUG_FLAG NAUTILUS_DEBUG_CANVAS_CONTAINER
#include "nautilus-debug.h"
-static const GtkTargetEntry drag_types [] = {
- { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
- { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
+static const GtkTargetEntry drag_types [] =
+{
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
+ { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
};
-static const GtkTargetEntry drop_types [] = {
- { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
- /* prefer "_NETSCAPE_URL" over "text/uri-list" to satisfy web browsers. */
- { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL },
- /* prefer XDS over "text/uri-list" */
- { NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, 0, NAUTILUS_ICON_DND_XDNDDIRECTSAVE }, /* XDS Protocol Type */
- { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
- { NAUTILUS_ICON_DND_RAW_TYPE, 0, NAUTILUS_ICON_DND_RAW },
- /* Must be last: */
- { NAUTILUS_ICON_DND_ROOTWINDOW_DROP_TYPE, 0, NAUTILUS_ICON_DND_ROOTWINDOW_DROP }
+static const GtkTargetEntry drop_types [] =
+{
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
+ /* prefer "_NETSCAPE_URL" over "text/uri-list" to satisfy web browsers. */
+ { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL },
+ /* prefer XDS over "text/uri-list" */
+ { NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, 0, NAUTILUS_ICON_DND_XDNDDIRECTSAVE }, /* XDS Protocol Type */
+ { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
+ { NAUTILUS_ICON_DND_RAW_TYPE, 0, NAUTILUS_ICON_DND_RAW },
+ /* Must be last: */
+ { NAUTILUS_ICON_DND_ROOTWINDOW_DROP_TYPE, 0, NAUTILUS_ICON_DND_ROOTWINDOW_DROP }
};
-static void stop_dnd_highlight (GtkWidget *widget);
-static void dnd_highlight_queue_redraw (GtkWidget *widget);
+static void stop_dnd_highlight (GtkWidget *widget);
+static void dnd_highlight_queue_redraw (GtkWidget *widget);
static GtkTargetList *drop_types_list = NULL;
static GtkTargetList *drop_types_list_root = NULL;
-static char * nautilus_canvas_container_find_drop_target (NautilusCanvasContainer *container,
- GdkDragContext *context,
- int x, int y, gboolean *icon_hit,
- gboolean rewrite_desktop);
+static char *nautilus_canvas_container_find_drop_target (NautilusCanvasContainer *container,
+ GdkDragContext *context,
+ int x,
+ int y,
+ gboolean *icon_hit,
+ gboolean rewrite_desktop);
static EelCanvasItem *
create_selection_shadow (NautilusCanvasContainer *container,
- GList *list)
+ GList *list)
{
- EelCanvasGroup *group;
- EelCanvas *canvas;
- int max_x, max_y;
- int min_x, min_y;
- GList *p;
- GtkAllocation allocation;
-
- if (list == NULL) {
- return NULL;
- }
-
- /* if we're only dragging a single item, don't worry about the shadow */
- if (list->next == NULL) {
- return NULL;
- }
-
- canvas = EEL_CANVAS (container);
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
-
- /* Creating a big set of rectangles in the canvas can be expensive, so
- we try to be smart and only create the maximum number of rectangles
- that we will need, in the vertical/horizontal directions. */
-
- max_x = allocation.width;
- min_x = -max_x;
-
- max_y = allocation.height;
- min_y = -max_y;
-
- /* Create a group, so that it's easier to move all the items around at
- once. */
- group = EEL_CANVAS_GROUP
- (eel_canvas_item_new (EEL_CANVAS_GROUP (canvas->root),
- eel_canvas_group_get_type (),
- NULL));
-
- for (p = list; p != NULL; p = p->next) {
- NautilusDragSelectionItem *item;
- int x1, y1, x2, y2;
- GdkRGBA black = { 0, 0, 0, 1 };
-
- item = p->data;
-
- if (!item->got_icon_position) {
- continue;
- }
-
- x1 = item->icon_x;
- y1 = item->icon_y;
- x2 = x1 + item->icon_width;
- y2 = y1 + item->icon_height;
-
- if (x2 >= min_x && x1 <= max_x && y2 >= min_y && y1 <= max_y)
- eel_canvas_item_new
- (group,
- NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
- "x1", (double) x1,
- "y1", (double) y1,
- "x2", (double) x2,
- "y2", (double) y2,
- "outline-color-rgba", &black,
- "outline-stippling", TRUE,
- "width_pixels", 1,
- NULL);
- }
-
- return EEL_CANVAS_ITEM (group);
+ EelCanvasGroup *group;
+ EelCanvas *canvas;
+ int max_x, max_y;
+ int min_x, min_y;
+ GList *p;
+ GtkAllocation allocation;
+
+ if (list == NULL)
+ {
+ return NULL;
+ }
+
+ /* if we're only dragging a single item, don't worry about the shadow */
+ if (list->next == NULL)
+ {
+ return NULL;
+ }
+
+ canvas = EEL_CANVAS (container);
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+
+ /* Creating a big set of rectangles in the canvas can be expensive, so
+ * we try to be smart and only create the maximum number of rectangles
+ * that we will need, in the vertical/horizontal directions. */
+
+ max_x = allocation.width;
+ min_x = -max_x;
+
+ max_y = allocation.height;
+ min_y = -max_y;
+
+ /* Create a group, so that it's easier to move all the items around at
+ * once. */
+ group = EEL_CANVAS_GROUP
+ (eel_canvas_item_new (EEL_CANVAS_GROUP (canvas->root),
+ eel_canvas_group_get_type (),
+ NULL));
+
+ for (p = list; p != NULL; p = p->next)
+ {
+ NautilusDragSelectionItem *item;
+ int x1, y1, x2, y2;
+ GdkRGBA black = { 0, 0, 0, 1 };
+
+ item = p->data;
+
+ if (!item->got_icon_position)
+ {
+ continue;
+ }
+
+ x1 = item->icon_x;
+ y1 = item->icon_y;
+ x2 = x1 + item->icon_width;
+ y2 = y1 + item->icon_height;
+
+ if (x2 >= min_x && x1 <= max_x && y2 >= min_y && y1 <= max_y)
+ {
+ eel_canvas_item_new
+ (group,
+ NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
+ "x1", (double) x1,
+ "y1", (double) y1,
+ "x2", (double) x2,
+ "y2", (double) y2,
+ "outline-color-rgba", &black,
+ "outline-stippling", TRUE,
+ "width_pixels", 1,
+ NULL);
+ }
+ }
+
+ return EEL_CANVAS_ITEM (group);
}
/* Set the affine instead of the x and y position.
@@ -165,109 +174,116 @@ create_selection_shadow (NautilusCanvasContainer *container,
*/
static void
set_shadow_position (EelCanvasItem *shadow,
- double x, double y)
+ double x,
+ double y)
{
- eel_canvas_item_set (shadow,
- "x", x, "y", y,
- NULL);
+ eel_canvas_item_set (shadow,
+ "x", x, "y", y,
+ NULL);
}
/* Source-side handling of the drag. */
/* iteration glue struct */
-typedef struct {
- gpointer iterator_context;
- NautilusDragEachSelectedItemDataGet iteratee;
- gpointer iteratee_data;
+typedef struct
+{
+ gpointer iterator_context;
+ NautilusDragEachSelectedItemDataGet iteratee;
+ gpointer iteratee_data;
} CanvasGetDataBinderContext;
static void
canvas_rect_world_to_widget (EelCanvas *canvas,
- EelDRect *world_rect,
- EelIRect *widget_rect)
+ EelDRect *world_rect,
+ EelIRect *widget_rect)
{
- EelDRect window_rect;
- GtkAdjustment *hadj, *vadj;
-
- hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
- vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
-
- eel_canvas_world_to_window (canvas,
- world_rect->x0, world_rect->y0,
- &window_rect.x0, &window_rect.y0);
- eel_canvas_world_to_window (canvas,
- world_rect->x1, world_rect->y1,
- &window_rect.x1, &window_rect.y1);
- widget_rect->x0 = (int) window_rect.x0 - gtk_adjustment_get_value (hadj);
- widget_rect->y0 = (int) window_rect.y0 - gtk_adjustment_get_value (vadj);
- widget_rect->x1 = (int) window_rect.x1 - gtk_adjustment_get_value (hadj);
- widget_rect->y1 = (int) window_rect.y1 - gtk_adjustment_get_value (vadj);
+ EelDRect window_rect;
+ GtkAdjustment *hadj, *vadj;
+
+ hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas));
+ vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas));
+
+ eel_canvas_world_to_window (canvas,
+ world_rect->x0, world_rect->y0,
+ &window_rect.x0, &window_rect.y0);
+ eel_canvas_world_to_window (canvas,
+ world_rect->x1, world_rect->y1,
+ &window_rect.x1, &window_rect.y1);
+ widget_rect->x0 = (int) window_rect.x0 - gtk_adjustment_get_value (hadj);
+ widget_rect->y0 = (int) window_rect.y0 - gtk_adjustment_get_value (vadj);
+ widget_rect->x1 = (int) window_rect.x1 - gtk_adjustment_get_value (hadj);
+ widget_rect->y1 = (int) window_rect.y1 - gtk_adjustment_get_value (vadj);
}
static void
canvas_widget_to_world (EelCanvas *canvas,
- double widget_x, double widget_y,
- double *world_x, double *world_y)
+ double widget_x,
+ double widget_y,
+ double *world_x,
+ double *world_y)
{
- eel_canvas_window_to_world (canvas,
- widget_x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas))),
- widget_y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas))),
- world_x, world_y);
+ eel_canvas_window_to_world (canvas,
+ widget_x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas))),
+ widget_y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas))),
+ world_x, world_y);
}
static gboolean
-icon_get_data_binder (NautilusCanvasIcon *icon, gpointer data)
+icon_get_data_binder (NautilusCanvasIcon *icon,
+ gpointer data)
{
- CanvasGetDataBinderContext *context;
- EelDRect world_rect;
- EelIRect widget_rect;
- char *uri;
- NautilusCanvasContainer *container;
- NautilusFile *file;
-
- context = (CanvasGetDataBinderContext *)data;
-
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (context->iterator_context));
-
- container = NAUTILUS_CANVAS_CONTAINER (context->iterator_context);
-
- world_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
-
- canvas_rect_world_to_widget (EEL_CANVAS (container), &world_rect, &widget_rect);
-
- uri = nautilus_canvas_container_get_icon_uri (container, icon);
- file = nautilus_file_get_by_uri (uri);
- if (!eel_uri_is_desktop (uri) && !nautilus_file_is_nautilus_link (file)) {
- g_free (uri);
- uri = nautilus_canvas_container_get_icon_activation_uri (container, icon);
- }
-
- if (uri == NULL) {
- g_warning ("no URI for one of the iterated icons");
- nautilus_file_unref (file);
- return TRUE;
- }
-
- widget_rect = eel_irect_offset_by (widget_rect,
- - container->details->dnd_info->drag_info.start_x,
- - container->details->dnd_info->drag_info.start_y);
-
- widget_rect = eel_irect_scale_by (widget_rect,
- 1 / EEL_CANVAS (container)->pixels_per_unit);
-
- /* pass the uri, mouse-relative x/y and icon width/height */
- context->iteratee (uri,
- (int) widget_rect.x0,
- (int) widget_rect.y0,
- widget_rect.x1 - widget_rect.x0,
- widget_rect.y1 - widget_rect.y0,
- context->iteratee_data);
-
- g_free (uri);
- nautilus_file_unref (file);
-
- return TRUE;
+ CanvasGetDataBinderContext *context;
+ EelDRect world_rect;
+ EelIRect widget_rect;
+ char *uri;
+ NautilusCanvasContainer *container;
+ NautilusFile *file;
+
+ context = (CanvasGetDataBinderContext *) data;
+
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (context->iterator_context));
+
+ container = NAUTILUS_CANVAS_CONTAINER (context->iterator_context);
+
+ world_rect = nautilus_canvas_item_get_icon_rectangle (icon->item);
+
+ canvas_rect_world_to_widget (EEL_CANVAS (container), &world_rect, &widget_rect);
+
+ uri = nautilus_canvas_container_get_icon_uri (container, icon);
+ file = nautilus_file_get_by_uri (uri);
+ if (!eel_uri_is_desktop (uri) && !nautilus_file_is_nautilus_link (file))
+ {
+ g_free (uri);
+ uri = nautilus_canvas_container_get_icon_activation_uri (container, icon);
+ }
+
+ if (uri == NULL)
+ {
+ g_warning ("no URI for one of the iterated icons");
+ nautilus_file_unref (file);
+ return TRUE;
+ }
+
+ widget_rect = eel_irect_offset_by (widget_rect,
+ -container->details->dnd_info->drag_info.start_x,
+ -container->details->dnd_info->drag_info.start_y);
+
+ widget_rect = eel_irect_scale_by (widget_rect,
+ 1 / EEL_CANVAS (container)->pixels_per_unit);
+
+ /* pass the uri, mouse-relative x/y and icon width/height */
+ context->iteratee (uri,
+ (int) widget_rect.x0,
+ (int) widget_rect.y0,
+ widget_rect.x1 - widget_rect.x0,
+ widget_rect.y1 - widget_rect.y0,
+ context->iteratee_data);
+
+ g_free (uri);
+ nautilus_file_unref (file);
+
+ return TRUE;
}
/* Iterate over each selected icon in a NautilusCanvasContainer,
@@ -275,20 +291,24 @@ icon_get_data_binder (NautilusCanvasIcon *icon, gpointer data)
*/
static void
nautilus_canvas_container_each_selected_icon (NautilusCanvasContainer *container,
- gboolean (*each_function) (NautilusCanvasIcon *, gpointer), gpointer data)
+ gboolean (*each_function)(NautilusCanvasIcon *, gpointer),
+ gpointer data)
{
- GList *p;
- NautilusCanvasIcon *icon;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- icon = p->data;
- if (!icon->is_selected) {
- continue;
- }
- if (!each_function (icon, data)) {
- return;
- }
- }
+ GList *p;
+ NautilusCanvasIcon *icon;
+
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ icon = p->data;
+ if (!icon->is_selected)
+ {
+ continue;
+ }
+ if (!each_function (icon, data))
+ {
+ return;
+ }
+ }
}
/* Adaptor function used with nautilus_canvas_container_each_selected_icon
@@ -296,42 +316,43 @@ nautilus_canvas_container_each_selected_icon (NautilusCanvasContainer *container
* values to the iteratee
*/
static void
-each_icon_get_data_binder (NautilusDragEachSelectedItemDataGet iteratee,
- gpointer iterator_context, gpointer data)
+each_icon_get_data_binder (NautilusDragEachSelectedItemDataGet iteratee,
+ gpointer iterator_context,
+ gpointer data)
{
- CanvasGetDataBinderContext context;
- NautilusCanvasContainer *container;
+ CanvasGetDataBinderContext context;
+ NautilusCanvasContainer *container;
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (iterator_context));
- container = NAUTILUS_CANVAS_CONTAINER (iterator_context);
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (iterator_context));
+ container = NAUTILUS_CANVAS_CONTAINER (iterator_context);
- context.iterator_context = iterator_context;
- context.iteratee = iteratee;
- context.iteratee_data = data;
- nautilus_canvas_container_each_selected_icon (container, icon_get_data_binder, &context);
+ context.iterator_context = iterator_context;
+ context.iteratee = iteratee;
+ context.iteratee_data = data;
+ nautilus_canvas_container_each_selected_icon (container, icon_get_data_binder, &context);
}
/* Called when the data for drag&drop is needed */
static void
-drag_data_get_callback (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint32 time,
- gpointer data)
+drag_data_get_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint32 time,
+ gpointer data)
{
- NautilusDragInfo *drag_info;
-
- g_assert (widget != NULL);
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (widget));
- g_return_if_fail (context != NULL);
-
- /* Call common function from nautilus-drag that set's up
- * the selection data in the right format. Pass it means to
- * iterate all the selected icons.
- */
- drag_info = &(NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info->drag_info);
- nautilus_drag_drag_data_get_from_cache (drag_info->selection_cache, context, selection_data, info, time);
+ NautilusDragInfo *drag_info;
+
+ g_assert (widget != NULL);
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (widget));
+ g_return_if_fail (context != NULL);
+
+ /* Call common function from nautilus-drag that set's up
+ * the selection data in the right format. Pass it means to
+ * iterate all the selected icons.
+ */
+ drag_info = &(NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info->drag_info);
+ nautilus_drag_drag_data_get_from_cache (drag_info->selection_cache, context, selection_data, info, time);
}
@@ -339,1042 +360,1173 @@ drag_data_get_callback (GtkWidget *widget,
static void
nautilus_canvas_container_position_shadow (NautilusCanvasContainer *container,
- int x, int y)
+ int x,
+ int y)
{
- EelCanvasItem *shadow;
- double world_x, world_y;
+ EelCanvasItem *shadow;
+ double world_x, world_y;
- shadow = container->details->dnd_info->shadow;
- if (shadow == NULL) {
- return;
- }
+ shadow = container->details->dnd_info->shadow;
+ if (shadow == NULL)
+ {
+ return;
+ }
- canvas_widget_to_world (EEL_CANVAS (container), x, y,
- &world_x, &world_y);
+ canvas_widget_to_world (EEL_CANVAS (container), x, y,
+ &world_x, &world_y);
- set_shadow_position (shadow, world_x, world_y);
- eel_canvas_item_show (shadow);
+ set_shadow_position (shadow, world_x, world_y);
+ eel_canvas_item_show (shadow);
}
static void
stop_cache_selection_list (NautilusDragInfo *drag_info)
{
- if (drag_info->file_list_info_handler) {
- nautilus_file_list_cancel_call_when_ready (drag_info->file_list_info_handler);
- drag_info->file_list_info_handler = NULL;
- }
+ if (drag_info->file_list_info_handler)
+ {
+ nautilus_file_list_cancel_call_when_ready (drag_info->file_list_info_handler);
+ drag_info->file_list_info_handler = NULL;
+ }
}
static void
cache_selection_list (NautilusDragInfo *drag_info)
{
- GList *files;
+ GList *files;
- files = nautilus_drag_file_list_from_selection_list (drag_info->selection_list);
- nautilus_file_list_call_when_ready (files,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- drag_info->file_list_info_handler,
- NULL, NULL);
+ files = nautilus_drag_file_list_from_selection_list (drag_info->selection_list);
+ nautilus_file_list_call_when_ready (files,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ drag_info->file_list_info_handler,
+ NULL, NULL);
- g_list_free_full (files, g_object_unref);
+ g_list_free_full (files, g_object_unref);
}
static void
-nautilus_canvas_container_dropped_canvas_feedback (GtkWidget *widget,
- GtkSelectionData *data,
- int x, int y)
+nautilus_canvas_container_dropped_canvas_feedback (GtkWidget *widget,
+ GtkSelectionData *data,
+ int x,
+ int y)
{
- NautilusCanvasContainer *container;
- NautilusCanvasDndInfo *dnd_info;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- dnd_info = container->details->dnd_info;
-
- /* Delete old selection list. */
- stop_cache_selection_list (&dnd_info->drag_info);
- nautilus_drag_destroy_selection_list (dnd_info->drag_info.selection_list);
- dnd_info->drag_info.selection_list = NULL;
-
- /* Delete old shadow if any. */
- if (dnd_info->shadow != NULL) {
- /* FIXME bugzilla.gnome.org 42484:
- * Is a destroy really sufficient here? Who does the unref? */
- eel_canvas_item_destroy (dnd_info->shadow);
- }
-
- /* Build the selection list and the shadow. */
- dnd_info->drag_info.selection_list = nautilus_drag_build_selection_list (data);
- cache_selection_list (&dnd_info->drag_info);
- dnd_info->shadow = create_selection_shadow (container, dnd_info->drag_info.selection_list);
- nautilus_canvas_container_position_shadow (container, x, y);
+ NautilusCanvasContainer *container;
+ NautilusCanvasDndInfo *dnd_info;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ dnd_info = container->details->dnd_info;
+
+ /* Delete old selection list. */
+ stop_cache_selection_list (&dnd_info->drag_info);
+ nautilus_drag_destroy_selection_list (dnd_info->drag_info.selection_list);
+ dnd_info->drag_info.selection_list = NULL;
+
+ /* Delete old shadow if any. */
+ if (dnd_info->shadow != NULL)
+ {
+ /* FIXME bugzilla.gnome.org 42484:
+ * Is a destroy really sufficient here? Who does the unref? */
+ eel_canvas_item_destroy (dnd_info->shadow);
+ }
+
+ /* Build the selection list and the shadow. */
+ dnd_info->drag_info.selection_list = nautilus_drag_build_selection_list (data);
+ cache_selection_list (&dnd_info->drag_info);
+ dnd_info->shadow = create_selection_shadow (container, dnd_info->drag_info.selection_list);
+ nautilus_canvas_container_position_shadow (container, x, y);
}
static char *
get_direct_save_filename (GdkDragContext *context)
{
- guchar *prop_text;
- gint prop_len;
-
- if (!gdk_property_get (gdk_drag_context_get_source_window (context), gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
- gdk_atom_intern ("text/plain", FALSE), 0, 1024, FALSE, NULL, NULL,
- &prop_len, &prop_text)) {
- return NULL;
- }
-
- /* Zero-terminate the string */
- prop_text = g_realloc (prop_text, prop_len + 1);
- prop_text[prop_len] = '\0';
-
- /* Verify that the file name provided by the source is valid */
- if (*prop_text == '\0' ||
- strchr ((const gchar *) prop_text, G_DIR_SEPARATOR) != NULL) {
- DEBUG ("Invalid filename provided by XDS drag site");
- g_free (prop_text);
- return NULL;
- }
-
- return (gchar *) prop_text;
+ guchar *prop_text;
+ gint prop_len;
+
+ if (!gdk_property_get (gdk_drag_context_get_source_window (context), gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
+ gdk_atom_intern ("text/plain", FALSE), 0, 1024, FALSE, NULL, NULL,
+ &prop_len, &prop_text))
+ {
+ return NULL;
+ }
+
+ /* Zero-terminate the string */
+ prop_text = g_realloc (prop_text, prop_len + 1);
+ prop_text[prop_len] = '\0';
+
+ /* Verify that the file name provided by the source is valid */
+ if (*prop_text == '\0' ||
+ strchr ((const gchar *) prop_text, G_DIR_SEPARATOR) != NULL)
+ {
+ DEBUG ("Invalid filename provided by XDS drag site");
+ g_free (prop_text);
+ return NULL;
+ }
+
+ return (gchar *) prop_text;
}
static void
-set_direct_save_uri (GtkWidget *widget, GdkDragContext *context, NautilusDragInfo *drag_info, int x, int y)
+set_direct_save_uri (GtkWidget *widget,
+ GdkDragContext *context,
+ NautilusDragInfo *drag_info,
+ int x,
+ int y)
{
- GFile *base, *child;
- char *filename, *drop_target;
- gchar *uri;
-
- drag_info->got_drop_data_type = TRUE;
- drag_info->data_type = NAUTILUS_ICON_DND_XDNDDIRECTSAVE;
-
- uri = NULL;
-
- filename = get_direct_save_filename (context);
- drop_target = nautilus_canvas_container_find_drop_target (NAUTILUS_CANVAS_CONTAINER (widget),
- context, x, y, NULL, TRUE);
-
- if (drop_target && eel_uri_is_trash (drop_target)) {
- g_free (drop_target);
- drop_target = NULL; /* Cannot save to trash ...*/
- }
-
- if (filename != NULL && drop_target != NULL) {
- /* Resolve relative path */
- base = g_file_new_for_uri (drop_target);
- child = g_file_get_child (base, filename);
- uri = g_file_get_uri (child);
- g_object_unref (base);
- g_object_unref (child);
-
- /* Change the uri property */
- gdk_property_change (gdk_drag_context_get_source_window (context),
- gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
- gdk_atom_intern ("text/plain", FALSE), 8,
- GDK_PROP_MODE_REPLACE, (const guchar *) uri,
- strlen (uri));
-
- drag_info->direct_save_uri = uri;
- }
-
- g_free (filename);
- g_free (drop_target);
+ GFile *base, *child;
+ char *filename, *drop_target;
+ gchar *uri;
+
+ drag_info->got_drop_data_type = TRUE;
+ drag_info->data_type = NAUTILUS_ICON_DND_XDNDDIRECTSAVE;
+
+ uri = NULL;
+
+ filename = get_direct_save_filename (context);
+ drop_target = nautilus_canvas_container_find_drop_target (NAUTILUS_CANVAS_CONTAINER (widget),
+ context, x, y, NULL, TRUE);
+
+ if (drop_target && eel_uri_is_trash (drop_target))
+ {
+ g_free (drop_target);
+ drop_target = NULL; /* Cannot save to trash ...*/
+ }
+
+ if (filename != NULL && drop_target != NULL)
+ {
+ /* Resolve relative path */
+ base = g_file_new_for_uri (drop_target);
+ child = g_file_get_child (base, filename);
+ uri = g_file_get_uri (child);
+ g_object_unref (base);
+ g_object_unref (child);
+
+ /* Change the uri property */
+ gdk_property_change (gdk_drag_context_get_source_window (context),
+ gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
+ gdk_atom_intern ("text/plain", FALSE), 8,
+ GDK_PROP_MODE_REPLACE, (const guchar *) uri,
+ strlen (uri));
+
+ drag_info->direct_save_uri = uri;
+ }
+
+ g_free (filename);
+ g_free (drop_target);
}
/* FIXME bugzilla.gnome.org 47445: Needs to become a shared function */
static void
-get_data_on_first_target_we_support (GtkWidget *widget, GdkDragContext *context, guint32 time, int x, int y)
+get_data_on_first_target_we_support (GtkWidget *widget,
+ GdkDragContext *context,
+ guint32 time,
+ int x,
+ int y)
{
- GtkTargetList *list;
- GdkAtom target;
-
- if (drop_types_list == NULL) {
- drop_types_list = gtk_target_list_new (drop_types,
- G_N_ELEMENTS (drop_types) - 1);
- gtk_target_list_add_text_targets (drop_types_list, NAUTILUS_ICON_DND_TEXT);
- }
- if (drop_types_list_root == NULL) {
- drop_types_list_root = gtk_target_list_new (drop_types,
- G_N_ELEMENTS (drop_types));
- gtk_target_list_add_text_targets (drop_types_list_root, NAUTILUS_ICON_DND_TEXT);
- }
-
- if (nautilus_canvas_container_get_is_desktop (NAUTILUS_CANVAS_CONTAINER (widget))) {
- list = drop_types_list_root;
- } else {
- list = drop_types_list;
- }
-
- target = gtk_drag_dest_find_target (widget, context, list);
- if (target != GDK_NONE) {
- guint info;
- NautilusDragInfo *drag_info;
- gboolean found;
-
- drag_info = &(NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info->drag_info);
-
- found = gtk_target_list_find (list, target, &info);
- g_assert (found);
-
- /* Don't get_data for destructive ops */
- if ((info == NAUTILUS_ICON_DND_ROOTWINDOW_DROP ||
- info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE) &&
- !drag_info->drop_occured) {
- /* We can't call get_data here, because that would
- make the source execute the rootwin action or the direct save */
- drag_info->got_drop_data_type = TRUE;
- drag_info->data_type = info;
- } else {
- if (info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE) {
- set_direct_save_uri (widget, context, drag_info, x, y);
- }
- gtk_drag_get_data (GTK_WIDGET (widget), context,
- target, time);
- }
- }
+ GtkTargetList *list;
+ GdkAtom target;
+
+ if (drop_types_list == NULL)
+ {
+ drop_types_list = gtk_target_list_new (drop_types,
+ G_N_ELEMENTS (drop_types) - 1);
+ gtk_target_list_add_text_targets (drop_types_list, NAUTILUS_ICON_DND_TEXT);
+ }
+ if (drop_types_list_root == NULL)
+ {
+ drop_types_list_root = gtk_target_list_new (drop_types,
+ G_N_ELEMENTS (drop_types));
+ gtk_target_list_add_text_targets (drop_types_list_root, NAUTILUS_ICON_DND_TEXT);
+ }
+
+ if (nautilus_canvas_container_get_is_desktop (NAUTILUS_CANVAS_CONTAINER (widget)))
+ {
+ list = drop_types_list_root;
+ }
+ else
+ {
+ list = drop_types_list;
+ }
+
+ target = gtk_drag_dest_find_target (widget, context, list);
+ if (target != GDK_NONE)
+ {
+ guint info;
+ NautilusDragInfo *drag_info;
+ gboolean found;
+
+ drag_info = &(NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info->drag_info);
+
+ found = gtk_target_list_find (list, target, &info);
+ g_assert (found);
+
+ /* Don't get_data for destructive ops */
+ if ((info == NAUTILUS_ICON_DND_ROOTWINDOW_DROP ||
+ info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE) &&
+ !drag_info->drop_occured)
+ {
+ /* We can't call get_data here, because that would
+ * make the source execute the rootwin action or the direct save */
+ drag_info->got_drop_data_type = TRUE;
+ drag_info->data_type = info;
+ }
+ else
+ {
+ if (info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE)
+ {
+ set_direct_save_uri (widget, context, drag_info, x, y);
+ }
+ gtk_drag_get_data (GTK_WIDGET (widget), context,
+ target, time);
+ }
+ }
}
static void
nautilus_canvas_container_ensure_drag_data (NautilusCanvasContainer *container,
- GdkDragContext *context,
- guint32 time)
+ GdkDragContext *context,
+ guint32 time)
{
- NautilusCanvasDndInfo *dnd_info;
+ NautilusCanvasDndInfo *dnd_info;
- dnd_info = container->details->dnd_info;
+ dnd_info = container->details->dnd_info;
- if (!dnd_info->drag_info.got_drop_data_type) {
- get_data_on_first_target_we_support (GTK_WIDGET (container), context, time, 0, 0);
- }
+ if (!dnd_info->drag_info.got_drop_data_type)
+ {
+ get_data_on_first_target_we_support (GTK_WIDGET (container), context, time, 0, 0);
+ }
}
static void
-drag_end_callback (GtkWidget *widget,
- GdkDragContext *context,
- gpointer data)
+drag_end_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ gpointer data)
{
- NautilusCanvasContainer *container;
- NautilusCanvasDndInfo *dnd_info;
- NautilusWindow *window;
+ NautilusCanvasContainer *container;
+ NautilusCanvasDndInfo *dnd_info;
+ NautilusWindow *window;
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container)));
- dnd_info = container->details->dnd_info;
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container)));
+ dnd_info = container->details->dnd_info;
- stop_cache_selection_list (&dnd_info->drag_info);
- nautilus_drag_destroy_selection_list (dnd_info->drag_info.selection_list);
- nautilus_drag_destroy_selection_list (container->details->dnd_source_info->selection_cache);
- dnd_info->drag_info.selection_list = NULL;
- container->details->dnd_source_info->selection_cache = NULL;
+ stop_cache_selection_list (&dnd_info->drag_info);
+ nautilus_drag_destroy_selection_list (dnd_info->drag_info.selection_list);
+ nautilus_drag_destroy_selection_list (container->details->dnd_source_info->selection_cache);
+ dnd_info->drag_info.selection_list = NULL;
+ container->details->dnd_source_info->selection_cache = NULL;
- nautilus_window_end_dnd (window, context);
+ nautilus_window_end_dnd (window, context);
}
static NautilusCanvasIcon *
nautilus_canvas_container_item_at (NautilusCanvasContainer *container,
- int x, int y)
+ int x,
+ int y)
{
- GList *p;
- int size;
- EelDRect point;
- EelIRect canvas_point;
-
- /* build the hit-test rectangle. Base the size on the scale factor to ensure that it is
- * non-empty even at the smallest scale factor
- */
-
- size = MAX (1, 1 + (1 / EEL_CANVAS (container)->pixels_per_unit));
- point.x0 = x;
- point.y0 = y;
- point.x1 = x + size;
- point.y1 = y + size;
-
- for (p = container->details->icons; p != NULL; p = p->next) {
- NautilusCanvasIcon *icon;
- icon = p->data;
-
- eel_canvas_w2c (EEL_CANVAS (container),
- point.x0,
- point.y0,
- &canvas_point.x0,
- &canvas_point.y0);
- eel_canvas_w2c (EEL_CANVAS (container),
- point.x1,
- point.y1,
- &canvas_point.x1,
- &canvas_point.y1);
- if (nautilus_canvas_item_hit_test_rectangle (icon->item, canvas_point)) {
- return icon;
- }
- }
-
- return NULL;
+ GList *p;
+ int size;
+ EelDRect point;
+ EelIRect canvas_point;
+
+ /* build the hit-test rectangle. Base the size on the scale factor to ensure that it is
+ * non-empty even at the smallest scale factor
+ */
+
+ size = MAX (1, 1 + (1 / EEL_CANVAS (container)->pixels_per_unit));
+ point.x0 = x;
+ point.y0 = y;
+ point.x1 = x + size;
+ point.y1 = y + size;
+
+ for (p = container->details->icons; p != NULL; p = p->next)
+ {
+ NautilusCanvasIcon *icon;
+ icon = p->data;
+
+ eel_canvas_w2c (EEL_CANVAS (container),
+ point.x0,
+ point.y0,
+ &canvas_point.x0,
+ &canvas_point.y0);
+ eel_canvas_w2c (EEL_CANVAS (container),
+ point.x1,
+ point.y1,
+ &canvas_point.x1,
+ &canvas_point.y1);
+ if (nautilus_canvas_item_hit_test_rectangle (icon->item, canvas_point))
+ {
+ return icon;
+ }
+ }
+
+ return NULL;
}
static char *
get_container_uri (NautilusCanvasContainer *container)
{
- char *uri;
+ char *uri;
- /* get the URI associated with the container */
- uri = NULL;
- g_signal_emit_by_name (container, "get-container-uri", &uri);
- return uri;
+ /* get the URI associated with the container */
+ uri = NULL;
+ g_signal_emit_by_name (container, "get-container-uri", &uri);
+ return uri;
}
static gboolean
nautilus_canvas_container_selection_items_local (NautilusCanvasContainer *container,
- GList *items)
+ GList *items)
{
- char *container_uri_string;
- gboolean result;
-
- /* must have at least one item */
- g_assert (items);
-
- /* get the URI associated with the container */
- container_uri_string = get_container_uri (container);
-
- if (eel_uri_is_desktop (container_uri_string)) {
- result = nautilus_drag_items_on_desktop (items);
- } else {
- result = nautilus_drag_items_local (container_uri_string, items);
- }
- g_free (container_uri_string);
-
- return result;
+ char *container_uri_string;
+ gboolean result;
+
+ /* must have at least one item */
+ g_assert (items);
+
+ /* get the URI associated with the container */
+ container_uri_string = get_container_uri (container);
+
+ if (eel_uri_is_desktop (container_uri_string))
+ {
+ result = nautilus_drag_items_on_desktop (items);
+ }
+ else
+ {
+ result = nautilus_drag_items_local (container_uri_string, items);
+ }
+ g_free (container_uri_string);
+
+ return result;
}
/* handle dropped url */
static void
-receive_dropped_netscape_url (NautilusCanvasContainer *container, const char *encoded_url, GdkDragContext *context, int x, int y)
+receive_dropped_netscape_url (NautilusCanvasContainer *container,
+ const char *encoded_url,
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
+ char *drop_target;
- if (encoded_url == NULL) {
- return;
- }
+ if (encoded_url == NULL)
+ {
+ return;
+ }
- drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
+ drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
- g_signal_emit_by_name (container, "handle-netscape-url",
- encoded_url,
- drop_target,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ g_signal_emit_by_name (container, "handle-netscape-url",
+ encoded_url,
+ drop_target,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (drop_target);
+ g_free (drop_target);
}
/* handle dropped uri list */
static void
-receive_dropped_uri_list (NautilusCanvasContainer *container, const char *uri_list, GdkDragContext *context, int x, int y)
-{
- char *drop_target;
+receive_dropped_uri_list (NautilusCanvasContainer *container,
+ const char *uri_list,
+ GdkDragContext *context,
+ int x,
+ int y)
+{
+ char *drop_target;
- if (uri_list == NULL) {
- return;
- }
+ if (uri_list == NULL)
+ {
+ return;
+ }
- drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
+ drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
- g_signal_emit_by_name (container, "handle-uri-list",
- uri_list,
- drop_target,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ g_signal_emit_by_name (container, "handle-uri-list",
+ uri_list,
+ drop_target,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (drop_target);
+ g_free (drop_target);
}
/* handle dropped text */
static void
-receive_dropped_text (NautilusCanvasContainer *container, const char *text, GdkDragContext *context, int x, int y)
-{
- char *drop_target;
-
- if (text == NULL) {
- return;
- }
-
- drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
-
- g_signal_emit_by_name (container, "handle-text",
- text,
- drop_target,
- gdk_drag_context_get_selected_action (context),
- x, y);
-
- g_free (drop_target);
+receive_dropped_text (NautilusCanvasContainer *container,
+ const char *text,
+ GdkDragContext *context,
+ int x,
+ int y)
+{
+ char *drop_target;
+
+ if (text == NULL)
+ {
+ return;
+ }
+
+ drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
+
+ g_signal_emit_by_name (container, "handle-text",
+ text,
+ drop_target,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
+
+ g_free (drop_target);
}
/* handle dropped raw data */
static void
-receive_dropped_raw (NautilusCanvasContainer *container, const char *raw_data, int length, const char *direct_save_uri, GdkDragContext *context, int x, int y)
+receive_dropped_raw (NautilusCanvasContainer *container,
+ const char *raw_data,
+ int length,
+ const char *direct_save_uri,
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
+ char *drop_target;
- if (raw_data == NULL) {
- return;
- }
+ if (raw_data == NULL)
+ {
+ return;
+ }
- drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
+ drop_target = nautilus_canvas_container_find_drop_target (container, context, x, y, NULL, TRUE);
- g_signal_emit_by_name (container, "handle-raw",
- raw_data,
- length,
- drop_target,
- direct_save_uri,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ g_signal_emit_by_name (container, "handle-raw",
+ raw_data,
+ length,
+ drop_target,
+ direct_save_uri,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (drop_target);
+ g_free (drop_target);
}
static int
auto_scroll_timeout_callback (gpointer data)
{
- NautilusCanvasContainer *container;
- GtkWidget *widget;
- float x_scroll_delta, y_scroll_delta;
- GdkRectangle exposed_area;
- GtkAllocation allocation;
-
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (data));
- widget = GTK_WIDGET (data);
- container = NAUTILUS_CANVAS_CONTAINER (widget);
-
- if (container->details->dnd_info->drag_info.waiting_to_autoscroll
- && container->details->dnd_info->drag_info.start_auto_scroll_in > g_get_monotonic_time ()) {
- /* not yet */
- return TRUE;
- }
-
- container->details->dnd_info->drag_info.waiting_to_autoscroll = FALSE;
-
- nautilus_drag_autoscroll_calculate_delta (widget, &x_scroll_delta, &y_scroll_delta);
- if (x_scroll_delta == 0 && y_scroll_delta == 0) {
- /* no work */
- return TRUE;
- }
-
- /* Clear the old dnd highlight frame */
- dnd_highlight_queue_redraw (widget);
-
- if (!nautilus_canvas_container_scroll (container, (int)x_scroll_delta, (int)y_scroll_delta)) {
- /* the scroll value got pinned to a min or max adjustment value,
- * we ended up not scrolling
- */
- return TRUE;
- }
-
- /* Make sure the dnd highlight frame is redrawn */
- dnd_highlight_queue_redraw (widget);
-
- /* update cached drag start offsets */
- container->details->dnd_info->drag_info.start_x -= x_scroll_delta;
- container->details->dnd_info->drag_info.start_y -= y_scroll_delta;
-
- /* Due to a glitch in GtkLayout, whe need to do an explicit draw of the exposed
- * area.
- * Calculate the size of the area we need to draw
- */
- gtk_widget_get_allocation (widget, &allocation);
- exposed_area.x = allocation.x;
- exposed_area.y = allocation.y;
- exposed_area.width = allocation.width;
- exposed_area.height = allocation.height;
-
- if (x_scroll_delta > 0) {
- exposed_area.x = exposed_area.width - x_scroll_delta;
- } else if (x_scroll_delta < 0) {
- exposed_area.width = -x_scroll_delta;
- }
-
- if (y_scroll_delta > 0) {
- exposed_area.y = exposed_area.height - y_scroll_delta;
- } else if (y_scroll_delta < 0) {
- exposed_area.height = -y_scroll_delta;
- }
-
- /* offset it to 0, 0 */
- exposed_area.x -= allocation.x;
- exposed_area.y -= allocation.y;
-
- gtk_widget_queue_draw_area (widget,
- exposed_area.x,
- exposed_area.y,
- exposed_area.width,
- exposed_area.height);
-
- return TRUE;
+ NautilusCanvasContainer *container;
+ GtkWidget *widget;
+ float x_scroll_delta, y_scroll_delta;
+ GdkRectangle exposed_area;
+ GtkAllocation allocation;
+
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (data));
+ widget = GTK_WIDGET (data);
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+
+ if (container->details->dnd_info->drag_info.waiting_to_autoscroll
+ && container->details->dnd_info->drag_info.start_auto_scroll_in > g_get_monotonic_time ())
+ {
+ /* not yet */
+ return TRUE;
+ }
+
+ container->details->dnd_info->drag_info.waiting_to_autoscroll = FALSE;
+
+ nautilus_drag_autoscroll_calculate_delta (widget, &x_scroll_delta, &y_scroll_delta);
+ if (x_scroll_delta == 0 && y_scroll_delta == 0)
+ {
+ /* no work */
+ return TRUE;
+ }
+
+ /* Clear the old dnd highlight frame */
+ dnd_highlight_queue_redraw (widget);
+
+ if (!nautilus_canvas_container_scroll (container, (int) x_scroll_delta, (int) y_scroll_delta))
+ {
+ /* the scroll value got pinned to a min or max adjustment value,
+ * we ended up not scrolling
+ */
+ return TRUE;
+ }
+
+ /* Make sure the dnd highlight frame is redrawn */
+ dnd_highlight_queue_redraw (widget);
+
+ /* update cached drag start offsets */
+ container->details->dnd_info->drag_info.start_x -= x_scroll_delta;
+ container->details->dnd_info->drag_info.start_y -= y_scroll_delta;
+
+ /* Due to a glitch in GtkLayout, whe need to do an explicit draw of the exposed
+ * area.
+ * Calculate the size of the area we need to draw
+ */
+ gtk_widget_get_allocation (widget, &allocation);
+ exposed_area.x = allocation.x;
+ exposed_area.y = allocation.y;
+ exposed_area.width = allocation.width;
+ exposed_area.height = allocation.height;
+
+ if (x_scroll_delta > 0)
+ {
+ exposed_area.x = exposed_area.width - x_scroll_delta;
+ }
+ else if (x_scroll_delta < 0)
+ {
+ exposed_area.width = -x_scroll_delta;
+ }
+
+ if (y_scroll_delta > 0)
+ {
+ exposed_area.y = exposed_area.height - y_scroll_delta;
+ }
+ else if (y_scroll_delta < 0)
+ {
+ exposed_area.height = -y_scroll_delta;
+ }
+
+ /* offset it to 0, 0 */
+ exposed_area.x -= allocation.x;
+ exposed_area.y -= allocation.y;
+
+ gtk_widget_queue_draw_area (widget,
+ exposed_area.x,
+ exposed_area.y,
+ exposed_area.width,
+ exposed_area.height);
+
+ return TRUE;
}
static void
set_up_auto_scroll_if_needed (NautilusCanvasContainer *container)
{
- nautilus_drag_autoscroll_start (&container->details->dnd_info->drag_info,
- GTK_WIDGET (container),
- auto_scroll_timeout_callback,
- container);
+ nautilus_drag_autoscroll_start (&container->details->dnd_info->drag_info,
+ GTK_WIDGET (container),
+ auto_scroll_timeout_callback,
+ container);
}
static void
stop_auto_scroll (NautilusCanvasContainer *container)
{
- nautilus_drag_autoscroll_stop (&container->details->dnd_info->drag_info);
+ nautilus_drag_autoscroll_stop (&container->details->dnd_info->drag_info);
}
static void
handle_local_move (NautilusCanvasContainer *container,
- double world_x, double world_y)
+ double world_x,
+ double world_y)
{
- GList *moved_icons, *p;
- NautilusDragSelectionItem *item;
- NautilusCanvasIcon *icon;
- NautilusFile *file;
- char screen_string[32];
- GdkScreen *screen;
- time_t now;
-
- if (container->details->auto_layout) {
- return;
- }
-
- time (&now);
-
- /* Move and select the icons. */
- moved_icons = NULL;
- for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next) {
- item = p->data;
-
- icon = nautilus_canvas_container_get_icon_by_uri
- (container, item->uri);
-
- if (icon == NULL) {
- /* probably dragged from another screen. Add it to
- * this screen
- */
-
- file = nautilus_file_get_by_uri (item->uri);
-
- screen = gtk_widget_get_screen (GTK_WIDGET (container));
- g_snprintf (screen_string, sizeof (screen_string), "%d",
- gdk_screen_get_number (screen));
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_SCREEN,
- NULL, screen_string);
- nautilus_file_set_time_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP, now);
-
- nautilus_canvas_container_add (container, NAUTILUS_CANVAS_ICON_DATA (file));
-
- icon = nautilus_canvas_container_get_icon_by_uri
- (container, item->uri);
- }
-
- if (item->got_icon_position) {
- nautilus_canvas_container_move_icon
- (container, icon,
- world_x + item->icon_x, world_y + item->icon_y,
- icon->scale,
- TRUE, TRUE, TRUE);
- }
- moved_icons = g_list_prepend (moved_icons, icon);
- }
- nautilus_canvas_container_select_list_unselect_others
- (container, moved_icons);
- /* Might have been moved in a way that requires adjusting scroll region. */
- nautilus_canvas_container_update_scroll_region (container);
- g_list_free (moved_icons);
+ GList *moved_icons, *p;
+ NautilusDragSelectionItem *item;
+ NautilusCanvasIcon *icon;
+ NautilusFile *file;
+ char screen_string[32];
+ GdkScreen *screen;
+ time_t now;
+
+ if (container->details->auto_layout)
+ {
+ return;
+ }
+
+ time (&now);
+
+ /* Move and select the icons. */
+ moved_icons = NULL;
+ for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next)
+ {
+ item = p->data;
+
+ icon = nautilus_canvas_container_get_icon_by_uri
+ (container, item->uri);
+
+ if (icon == NULL)
+ {
+ /* probably dragged from another screen. Add it to
+ * this screen
+ */
+
+ file = nautilus_file_get_by_uri (item->uri);
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (container));
+ g_snprintf (screen_string, sizeof (screen_string), "%d",
+ gdk_screen_get_number (screen));
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_SCREEN,
+ NULL, screen_string);
+ nautilus_file_set_time_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP, now);
+
+ nautilus_canvas_container_add (container, NAUTILUS_CANVAS_ICON_DATA (file));
+
+ icon = nautilus_canvas_container_get_icon_by_uri
+ (container, item->uri);
+ }
+
+ if (item->got_icon_position)
+ {
+ nautilus_canvas_container_move_icon
+ (container, icon,
+ world_x + item->icon_x, world_y + item->icon_y,
+ icon->scale,
+ TRUE, TRUE, TRUE);
+ }
+ moved_icons = g_list_prepend (moved_icons, icon);
+ }
+ nautilus_canvas_container_select_list_unselect_others
+ (container, moved_icons);
+ /* Might have been moved in a way that requires adjusting scroll region. */
+ nautilus_canvas_container_update_scroll_region (container);
+ g_list_free (moved_icons);
}
static void
handle_nonlocal_move (NautilusCanvasContainer *container,
- GdkDragAction action,
- int x, int y,
- const char *target_uri,
- gboolean icon_hit)
+ GdkDragAction action,
+ int x,
+ int y,
+ const char *target_uri,
+ gboolean icon_hit)
{
- GList *source_uris, *p;
- GArray *source_item_locations;
- gboolean free_target_uri, is_rtl;
- int index, item_x;
- GtkAllocation allocation;
-
- if (container->details->dnd_info->drag_info.selection_list == NULL) {
- return;
- }
-
- source_uris = NULL;
- for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next) {
- /* do a shallow copy of all the uri strings of the copied files */
- source_uris = g_list_prepend (source_uris, ((NautilusDragSelectionItem *)p->data)->uri);
- }
- source_uris = g_list_reverse (source_uris);
-
- is_rtl = nautilus_canvas_container_is_layout_rtl (container);
-
- source_item_locations = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
- if (!icon_hit) {
- /* Drop onto a container. Pass along the item points to allow placing
- * the items in their same relative positions in the new container.
- */
- source_item_locations = g_array_set_size (source_item_locations,
- g_list_length (container->details->dnd_info->drag_info.selection_list));
-
- for (index = 0, p = container->details->dnd_info->drag_info.selection_list;
- p != NULL; index++, p = p->next) {
- item_x = ((NautilusDragSelectionItem *)p->data)->icon_x;
- if (is_rtl)
- item_x = -item_x - ((NautilusDragSelectionItem *)p->data)->icon_width;
- g_array_index (source_item_locations, GdkPoint, index).x = item_x;
- g_array_index (source_item_locations, GdkPoint, index).y =
- ((NautilusDragSelectionItem *)p->data)->icon_y;
- }
- }
-
- free_target_uri = FALSE;
- /* Rewrite internal desktop URIs to the normal target uri */
- if (eel_uri_is_desktop (target_uri)) {
- target_uri = nautilus_get_desktop_directory_uri ();
- free_target_uri = TRUE;
- }
-
- if (is_rtl) {
- gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
- x = CANVAS_WIDTH (container, allocation) - x;
- }
-
- /* start the copy */
- g_signal_emit_by_name (container, "move-copy-items",
- source_uris,
- source_item_locations,
- target_uri,
- action,
- x, y);
-
- if (free_target_uri) {
- g_free ((char *)target_uri);
- }
-
- g_list_free (source_uris);
- g_array_free (source_item_locations, TRUE);
+ GList *source_uris, *p;
+ GArray *source_item_locations;
+ gboolean free_target_uri, is_rtl;
+ int index, item_x;
+ GtkAllocation allocation;
+
+ if (container->details->dnd_info->drag_info.selection_list == NULL)
+ {
+ return;
+ }
+
+ source_uris = NULL;
+ for (p = container->details->dnd_info->drag_info.selection_list; p != NULL; p = p->next)
+ {
+ /* do a shallow copy of all the uri strings of the copied files */
+ source_uris = g_list_prepend (source_uris, ((NautilusDragSelectionItem *) p->data)->uri);
+ }
+ source_uris = g_list_reverse (source_uris);
+
+ is_rtl = nautilus_canvas_container_is_layout_rtl (container);
+
+ source_item_locations = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
+ if (!icon_hit)
+ {
+ /* Drop onto a container. Pass along the item points to allow placing
+ * the items in their same relative positions in the new container.
+ */
+ source_item_locations = g_array_set_size (source_item_locations,
+ g_list_length (container->details->dnd_info->drag_info.selection_list));
+
+ for (index = 0, p = container->details->dnd_info->drag_info.selection_list;
+ p != NULL; index++, p = p->next)
+ {
+ item_x = ((NautilusDragSelectionItem *) p->data)->icon_x;
+ if (is_rtl)
+ {
+ item_x = -item_x - ((NautilusDragSelectionItem *) p->data)->icon_width;
+ }
+ g_array_index (source_item_locations, GdkPoint, index).x = item_x;
+ g_array_index (source_item_locations, GdkPoint, index).y =
+ ((NautilusDragSelectionItem *) p->data)->icon_y;
+ }
+ }
+
+ free_target_uri = FALSE;
+ /* Rewrite internal desktop URIs to the normal target uri */
+ if (eel_uri_is_desktop (target_uri))
+ {
+ target_uri = nautilus_get_desktop_directory_uri ();
+ free_target_uri = TRUE;
+ }
+
+ if (is_rtl)
+ {
+ gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+ x = CANVAS_WIDTH (container, allocation) - x;
+ }
+
+ /* start the copy */
+ g_signal_emit_by_name (container, "move-copy-items",
+ source_uris,
+ source_item_locations,
+ target_uri,
+ action,
+ x, y);
+
+ if (free_target_uri)
+ {
+ g_free ((char *) target_uri);
+ }
+
+ g_list_free (source_uris);
+ g_array_free (source_item_locations, TRUE);
}
static char *
nautilus_canvas_container_find_drop_target (NautilusCanvasContainer *container,
- GdkDragContext *context,
- int x, int y,
- gboolean *icon_hit,
- gboolean rewrite_desktop)
+ GdkDragContext *context,
+ int x,
+ int y,
+ gboolean *icon_hit,
+ gboolean rewrite_desktop)
{
- NautilusCanvasIcon *drop_target_icon;
- double world_x, world_y;
- NautilusFile *file;
- char *icon_uri;
- char *container_uri;
-
- if (icon_hit) {
- *icon_hit = FALSE;
- }
-
- if (!container->details->dnd_info->drag_info.got_drop_data_type) {
- return NULL;
- }
-
- canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y);
-
- /* FIXME bugzilla.gnome.org 42485:
- * These "can_accept_items" tests need to be done by
- * the canvas view, not here. This file is not supposed to know
- * that the target is a file.
- */
-
- /* Find the item we hit with our drop, if any */
- drop_target_icon = nautilus_canvas_container_item_at (container, world_x, world_y);
- if (drop_target_icon != NULL) {
- icon_uri = nautilus_canvas_container_get_icon_uri (container, drop_target_icon);
- if (icon_uri != NULL) {
- file = nautilus_file_get_by_uri (icon_uri);
-
- if (!nautilus_drag_can_accept_info (file,
- container->details->dnd_info->drag_info.data_type,
- container->details->dnd_info->drag_info.selection_list)) {
- /* the item we dropped our selection on cannot accept the items,
- * do the same thing as if we just dropped the items on the canvas
- */
- drop_target_icon = NULL;
- }
-
- g_free (icon_uri);
- nautilus_file_unref (file);
- }
- }
-
- if (drop_target_icon == NULL) {
- if (icon_hit) {
- *icon_hit = FALSE;
- }
-
- container_uri = get_container_uri (container);
-
- if (container_uri != NULL) {
- if (rewrite_desktop && eel_uri_is_desktop (container_uri)) {
- g_free (container_uri);
- container_uri = nautilus_get_desktop_directory_uri ();
- } else {
- gboolean can;
- file = nautilus_file_get_by_uri (container_uri);
- can = nautilus_drag_can_accept_info (file,
- container->details->dnd_info->drag_info.data_type,
- container->details->dnd_info->drag_info.selection_list);
- g_object_unref (file);
- if (!can) {
- g_free (container_uri);
- container_uri = NULL;
- }
- }
- }
-
- return container_uri;
- }
-
- if (icon_hit) {
- *icon_hit = TRUE;
- }
- return nautilus_canvas_container_get_icon_drop_target_uri (container, drop_target_icon);
+ NautilusCanvasIcon *drop_target_icon;
+ double world_x, world_y;
+ NautilusFile *file;
+ char *icon_uri;
+ char *container_uri;
+
+ if (icon_hit)
+ {
+ *icon_hit = FALSE;
+ }
+
+ if (!container->details->dnd_info->drag_info.got_drop_data_type)
+ {
+ return NULL;
+ }
+
+ canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y);
+
+ /* FIXME bugzilla.gnome.org 42485:
+ * These "can_accept_items" tests need to be done by
+ * the canvas view, not here. This file is not supposed to know
+ * that the target is a file.
+ */
+
+ /* Find the item we hit with our drop, if any */
+ drop_target_icon = nautilus_canvas_container_item_at (container, world_x, world_y);
+ if (drop_target_icon != NULL)
+ {
+ icon_uri = nautilus_canvas_container_get_icon_uri (container, drop_target_icon);
+ if (icon_uri != NULL)
+ {
+ file = nautilus_file_get_by_uri (icon_uri);
+
+ if (!nautilus_drag_can_accept_info (file,
+ container->details->dnd_info->drag_info.data_type,
+ container->details->dnd_info->drag_info.selection_list))
+ {
+ /* the item we dropped our selection on cannot accept the items,
+ * do the same thing as if we just dropped the items on the canvas
+ */
+ drop_target_icon = NULL;
+ }
+
+ g_free (icon_uri);
+ nautilus_file_unref (file);
+ }
+ }
+
+ if (drop_target_icon == NULL)
+ {
+ if (icon_hit)
+ {
+ *icon_hit = FALSE;
+ }
+
+ container_uri = get_container_uri (container);
+
+ if (container_uri != NULL)
+ {
+ if (rewrite_desktop && eel_uri_is_desktop (container_uri))
+ {
+ g_free (container_uri);
+ container_uri = nautilus_get_desktop_directory_uri ();
+ }
+ else
+ {
+ gboolean can;
+ file = nautilus_file_get_by_uri (container_uri);
+ can = nautilus_drag_can_accept_info (file,
+ container->details->dnd_info->drag_info.data_type,
+ container->details->dnd_info->drag_info.selection_list);
+ g_object_unref (file);
+ if (!can)
+ {
+ g_free (container_uri);
+ container_uri = NULL;
+ }
+ }
+ }
+
+ return container_uri;
+ }
+
+ if (icon_hit)
+ {
+ *icon_hit = TRUE;
+ }
+ return nautilus_canvas_container_get_icon_drop_target_uri (container, drop_target_icon);
}
static void
nautilus_canvas_container_receive_dropped_icons (NautilusCanvasContainer *container,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
- gboolean local_move_only;
- double world_x, world_y;
- gboolean icon_hit;
- GdkDragAction action, real_action;
-
- drop_target = NULL;
-
- if (container->details->dnd_info->drag_info.selection_list == NULL) {
- return;
- }
-
- real_action = gdk_drag_context_get_selected_action (context);
-
- if (real_action == GDK_ACTION_ASK) {
- /* FIXME bugzilla.gnome.org 42485: This belongs in FMDirectoryView, not here. */
- /* Check for special case items in selection list */
- if (nautilus_drag_selection_includes_special_link (container->details->dnd_info->drag_info.selection_list)) {
- /* We only want to move the trash */
- action = GDK_ACTION_MOVE;
- } else {
- action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
- }
- real_action = nautilus_drag_drop_action_ask
- (GTK_WIDGET (container), action);
- }
-
- if (real_action > 0) {
- eel_canvas_window_to_world (EEL_CANVAS (container),
- x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))),
- y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))),
- &world_x, &world_y);
-
- drop_target = nautilus_canvas_container_find_drop_target (container,
- context, x, y, &icon_hit, FALSE);
-
- local_move_only = FALSE;
- if (!icon_hit && real_action == GDK_ACTION_MOVE) {
- /* we can just move the canvas positions if the move ended up in
- * the item's parent container
- */
- local_move_only = nautilus_canvas_container_selection_items_local
- (container, container->details->dnd_info->drag_info.selection_list);
- }
-
- if (local_move_only) {
- handle_local_move (container, world_x, world_y);
- } else {
- handle_nonlocal_move (container, real_action, world_x, world_y, drop_target, icon_hit);
- }
- }
-
- g_free (drop_target);
- stop_cache_selection_list (&container->details->dnd_info->drag_info);
- nautilus_drag_destroy_selection_list (container->details->dnd_info->drag_info.selection_list);
- container->details->dnd_info->drag_info.selection_list = NULL;
+ char *drop_target;
+ gboolean local_move_only;
+ double world_x, world_y;
+ gboolean icon_hit;
+ GdkDragAction action, real_action;
+
+ drop_target = NULL;
+
+ if (container->details->dnd_info->drag_info.selection_list == NULL)
+ {
+ return;
+ }
+
+ real_action = gdk_drag_context_get_selected_action (context);
+
+ if (real_action == GDK_ACTION_ASK)
+ {
+ /* FIXME bugzilla.gnome.org 42485: This belongs in FMDirectoryView, not here. */
+ /* Check for special case items in selection list */
+ if (nautilus_drag_selection_includes_special_link (container->details->dnd_info->drag_info.selection_list))
+ {
+ /* We only want to move the trash */
+ action = GDK_ACTION_MOVE;
+ }
+ else
+ {
+ action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
+ }
+ real_action = nautilus_drag_drop_action_ask
+ (GTK_WIDGET (container), action);
+ }
+
+ if (real_action > 0)
+ {
+ eel_canvas_window_to_world (EEL_CANVAS (container),
+ x + gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container))),
+ y + gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container))),
+ &world_x, &world_y);
+
+ drop_target = nautilus_canvas_container_find_drop_target (container,
+ context, x, y, &icon_hit, FALSE);
+
+ local_move_only = FALSE;
+ if (!icon_hit && real_action == GDK_ACTION_MOVE)
+ {
+ /* we can just move the canvas positions if the move ended up in
+ * the item's parent container
+ */
+ local_move_only = nautilus_canvas_container_selection_items_local
+ (container, container->details->dnd_info->drag_info.selection_list);
+ }
+
+ if (local_move_only)
+ {
+ handle_local_move (container, world_x, world_y);
+ }
+ else
+ {
+ handle_nonlocal_move (container, real_action, world_x, world_y, drop_target, icon_hit);
+ }
+ }
+
+ g_free (drop_target);
+ stop_cache_selection_list (&container->details->dnd_info->drag_info);
+ nautilus_drag_destroy_selection_list (container->details->dnd_info->drag_info.selection_list);
+ container->details->dnd_info->drag_info.selection_list = NULL;
}
NautilusDragInfo *
nautilus_canvas_dnd_get_drag_source_data (NautilusCanvasContainer *container,
GdkDragContext *context)
{
- return container->details->dnd_source_info;
+ return container->details->dnd_source_info;
}
static void
nautilus_canvas_container_get_drop_action (NautilusCanvasContainer *container,
- GdkDragContext *context,
- int x, int y,
- int *action)
+ GdkDragContext *context,
+ int x,
+ int y,
+ int *action)
{
- char *drop_target;
- gboolean icon_hit;
- double world_x, world_y;
-
- icon_hit = FALSE;
- if (!container->details->dnd_info->drag_info.got_drop_data_type) {
- /* drag_data_received_callback didn't get called yet */
- return;
- }
-
- /* find out if we're over an canvas */
- canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y);
- *action = 0;
-
- drop_target = nautilus_canvas_container_find_drop_target (container,
- context, x, y, &icon_hit, FALSE);
- if (drop_target == NULL) {
- return;
- }
-
- /* case out on the type of object being dragged */
- switch (container->details->dnd_info->drag_info.data_type) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
- if (container->details->dnd_info->drag_info.selection_list != NULL) {
- nautilus_drag_default_drop_action_for_icons (context, drop_target,
- container->details->dnd_info->drag_info.selection_list,
- 0,
- action);
- }
- break;
- case NAUTILUS_ICON_DND_URI_LIST:
- *action = nautilus_drag_default_drop_action_for_uri_list (context, drop_target);
- break;
-
- case NAUTILUS_ICON_DND_NETSCAPE_URL:
- *action = nautilus_drag_default_drop_action_for_netscape_url (context);
- break;
-
- case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
- *action = gdk_drag_context_get_suggested_action (context);
- break;
-
- case NAUTILUS_ICON_DND_TEXT:
- case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
- case NAUTILUS_ICON_DND_RAW:
- *action = GDK_ACTION_COPY;
- break;
- }
-
- g_free (drop_target);
+ char *drop_target;
+ gboolean icon_hit;
+ double world_x, world_y;
+
+ icon_hit = FALSE;
+ if (!container->details->dnd_info->drag_info.got_drop_data_type)
+ {
+ /* drag_data_received_callback didn't get called yet */
+ return;
+ }
+
+ /* find out if we're over an canvas */
+ canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y);
+ *action = 0;
+
+ drop_target = nautilus_canvas_container_find_drop_target (container,
+ context, x, y, &icon_hit, FALSE);
+ if (drop_target == NULL)
+ {
+ return;
+ }
+
+ /* case out on the type of object being dragged */
+ switch (container->details->dnd_info->drag_info.data_type)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ if (container->details->dnd_info->drag_info.selection_list != NULL)
+ {
+ nautilus_drag_default_drop_action_for_icons (context, drop_target,
+ container->details->dnd_info->drag_info.selection_list,
+ 0,
+ action);
+ }
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ {
+ *action = nautilus_drag_default_drop_action_for_uri_list (context, drop_target);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_NETSCAPE_URL:
+ {
+ *action = nautilus_drag_default_drop_action_for_netscape_url (context);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
+ {
+ *action = gdk_drag_context_get_suggested_action (context);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_TEXT:
+ case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+ case NAUTILUS_ICON_DND_RAW:
+ {
+ *action = GDK_ACTION_COPY;
+ }
+ break;
+ }
+
+ g_free (drop_target);
}
static void
set_drop_target (NautilusCanvasContainer *container,
- NautilusCanvasIcon *icon)
+ NautilusCanvasIcon *icon)
{
- NautilusCanvasIcon *old_icon;
-
- /* Check if current drop target changed, update icon drop
- * higlight if needed.
- */
- old_icon = container->details->drop_target;
- if (icon == old_icon) {
- return;
- }
-
- /* Remember the new drop target for the next round. */
- container->details->drop_target = icon;
- nautilus_canvas_container_update_icon (container, old_icon);
- nautilus_canvas_container_update_icon (container, icon);
+ NautilusCanvasIcon *old_icon;
+
+ /* Check if current drop target changed, update icon drop
+ * higlight if needed.
+ */
+ old_icon = container->details->drop_target;
+ if (icon == old_icon)
+ {
+ return;
+ }
+
+ /* Remember the new drop target for the next round. */
+ container->details->drop_target = icon;
+ nautilus_canvas_container_update_icon (container, old_icon);
+ nautilus_canvas_container_update_icon (container, icon);
}
static void
nautilus_canvas_dnd_update_drop_target (NautilusCanvasContainer *container,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- NautilusCanvasIcon *icon;
- NautilusFile *file;
- double world_x, world_y;
- char *uri;
-
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
-
- canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y);
-
- /* Find the item we hit with our drop, if any. */
- icon = nautilus_canvas_container_item_at (container, world_x, world_y);
-
- /* FIXME bugzilla.gnome.org 42485:
- * These "can_accept_items" tests need to be done by
- * the canvas view, not here. This file is not supposed to know
- * that the target is a file.
- */
-
- /* Find if target canvas accepts our drop. */
- if (icon != NULL) {
- uri = nautilus_canvas_container_get_icon_uri (container, icon);
- file = nautilus_file_get_by_uri (uri);
- g_free (uri);
-
- if (!nautilus_drag_can_accept_info (file,
- container->details->dnd_info->drag_info.data_type,
- container->details->dnd_info->drag_info.selection_list)) {
- icon = NULL;
- }
-
- nautilus_file_unref (file);
- }
-
- set_drop_target (container, icon);
+ NautilusCanvasIcon *icon;
+ NautilusFile *file;
+ double world_x, world_y;
+ char *uri;
+
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+
+ canvas_widget_to_world (EEL_CANVAS (container), x, y, &world_x, &world_y);
+
+ /* Find the item we hit with our drop, if any. */
+ icon = nautilus_canvas_container_item_at (container, world_x, world_y);
+
+ /* FIXME bugzilla.gnome.org 42485:
+ * These "can_accept_items" tests need to be done by
+ * the canvas view, not here. This file is not supposed to know
+ * that the target is a file.
+ */
+
+ /* Find if target canvas accepts our drop. */
+ if (icon != NULL)
+ {
+ uri = nautilus_canvas_container_get_icon_uri (container, icon);
+ file = nautilus_file_get_by_uri (uri);
+ g_free (uri);
+
+ if (!nautilus_drag_can_accept_info (file,
+ container->details->dnd_info->drag_info.data_type,
+ container->details->dnd_info->drag_info.selection_list))
+ {
+ icon = NULL;
+ }
+
+ nautilus_file_unref (file);
+ }
+
+ set_drop_target (container, icon);
}
static void
remove_hover_timer (NautilusCanvasDndInfo *dnd_info)
{
- if (dnd_info->hover_id != 0) {
- g_source_remove (dnd_info->hover_id);
- dnd_info->hover_id = 0;
- }
+ if (dnd_info->hover_id != 0)
+ {
+ g_source_remove (dnd_info->hover_id);
+ dnd_info->hover_id = 0;
+ }
}
static void
nautilus_canvas_container_free_drag_data (NautilusCanvasContainer *container)
{
- NautilusCanvasDndInfo *dnd_info;
+ NautilusCanvasDndInfo *dnd_info;
- dnd_info = container->details->dnd_info;
-
- dnd_info->drag_info.got_drop_data_type = FALSE;
+ dnd_info = container->details->dnd_info;
- if (dnd_info->shadow != NULL) {
- eel_canvas_item_destroy (dnd_info->shadow);
- dnd_info->shadow = NULL;
- }
+ dnd_info->drag_info.got_drop_data_type = FALSE;
- if (dnd_info->drag_info.selection_data != NULL) {
- gtk_selection_data_free (dnd_info->drag_info.selection_data);
- dnd_info->drag_info.selection_data = NULL;
- }
+ if (dnd_info->shadow != NULL)
+ {
+ eel_canvas_item_destroy (dnd_info->shadow);
+ dnd_info->shadow = NULL;
+ }
- if (dnd_info->drag_info.direct_save_uri != NULL) {
- g_free (dnd_info->drag_info.direct_save_uri);
- dnd_info->drag_info.direct_save_uri = NULL;
- }
+ if (dnd_info->drag_info.selection_data != NULL)
+ {
+ gtk_selection_data_free (dnd_info->drag_info.selection_data);
+ dnd_info->drag_info.selection_data = NULL;
+ }
- g_free (dnd_info->target_uri);
- dnd_info->target_uri = NULL;
+ if (dnd_info->drag_info.direct_save_uri != NULL)
+ {
+ g_free (dnd_info->drag_info.direct_save_uri);
+ dnd_info->drag_info.direct_save_uri = NULL;
+ }
- remove_hover_timer (dnd_info);
+ g_free (dnd_info->target_uri);
+ dnd_info->target_uri = NULL;
+
+ remove_hover_timer (dnd_info);
}
static void
-drag_leave_callback (GtkWidget *widget,
- GdkDragContext *context,
- guint32 time,
- gpointer data)
+drag_leave_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ guint32 time,
+ gpointer data)
{
- NautilusCanvasDndInfo *dnd_info;
-
- dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
-
- if (dnd_info->shadow != NULL)
- eel_canvas_item_hide (dnd_info->shadow);
-
- stop_dnd_highlight (widget);
-
- set_drop_target (NAUTILUS_CANVAS_CONTAINER (widget), NULL);
- stop_auto_scroll (NAUTILUS_CANVAS_CONTAINER (widget));
- nautilus_canvas_container_free_drag_data(NAUTILUS_CANVAS_CONTAINER (widget));
+ NautilusCanvasDndInfo *dnd_info;
+
+ dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
+
+ if (dnd_info->shadow != NULL)
+ {
+ eel_canvas_item_hide (dnd_info->shadow);
+ }
+
+ stop_dnd_highlight (widget);
+
+ set_drop_target (NAUTILUS_CANVAS_CONTAINER (widget), NULL);
+ stop_auto_scroll (NAUTILUS_CANVAS_CONTAINER (widget));
+ nautilus_canvas_container_free_drag_data (NAUTILUS_CANVAS_CONTAINER (widget));
}
static void
drag_begin_callback (GtkWidget *widget,
- GdkDragContext *context,
- gpointer data)
+ GdkDragContext *context,
+ gpointer data)
{
- NautilusCanvasContainer *container;
- NautilusDragInfo *drag_info;
- NautilusWindow *window;
- cairo_surface_t *surface;
- double x1, y1, x2, y2, winx, winy;
- int x_offset, y_offset;
- int start_x, start_y;
-
- container = NAUTILUS_CANVAS_CONTAINER (widget);
- window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container)));
-
- start_x = container->details->dnd_info->drag_info.start_x +
- gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
- start_y = container->details->dnd_info->drag_info.start_y +
- gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
-
- /* create a pixmap and mask to drag with */
- surface = nautilus_canvas_item_get_drag_surface (container->details->drag_icon->item);
-
- /* compute the image's offset */
- eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (container->details->drag_icon->item),
- &x1, &y1, &x2, &y2);
- eel_canvas_world_to_window (EEL_CANVAS (container),
- x1, y1, &winx, &winy);
- x_offset = start_x - winx;
- y_offset = start_y - winy;
-
- cairo_surface_set_device_offset (surface, -x_offset, -y_offset);
- gtk_drag_set_icon_surface (context, surface);
- cairo_surface_destroy (surface);
-
- /* cache the data at the beginning since the view may change */
- drag_info = &(container->details->dnd_info->drag_info);
- drag_info->selection_cache = nautilus_drag_create_selection_cache (widget,
- each_icon_get_data_binder);
-
- container->details->dnd_source_info->selection_cache = nautilus_drag_create_selection_cache (widget,
- each_icon_get_data_binder);
-
- nautilus_window_start_dnd (window, context);
+ NautilusCanvasContainer *container;
+ NautilusDragInfo *drag_info;
+ NautilusWindow *window;
+ cairo_surface_t *surface;
+ double x1, y1, x2, y2, winx, winy;
+ int x_offset, y_offset;
+ int start_x, start_y;
+
+ container = NAUTILUS_CANVAS_CONTAINER (widget);
+ window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (container)));
+
+ start_x = container->details->dnd_info->drag_info.start_x +
+ gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
+ start_y = container->details->dnd_info->drag_info.start_y +
+ gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
+
+ /* create a pixmap and mask to drag with */
+ surface = nautilus_canvas_item_get_drag_surface (container->details->drag_icon->item);
+
+ /* compute the image's offset */
+ eel_canvas_item_get_bounds (EEL_CANVAS_ITEM (container->details->drag_icon->item),
+ &x1, &y1, &x2, &y2);
+ eel_canvas_world_to_window (EEL_CANVAS (container),
+ x1, y1, &winx, &winy);
+ x_offset = start_x - winx;
+ y_offset = start_y - winy;
+
+ cairo_surface_set_device_offset (surface, -x_offset, -y_offset);
+ gtk_drag_set_icon_surface (context, surface);
+ cairo_surface_destroy (surface);
+
+ /* cache the data at the beginning since the view may change */
+ drag_info = &(container->details->dnd_info->drag_info);
+ drag_info->selection_cache = nautilus_drag_create_selection_cache (widget,
+ each_icon_get_data_binder);
+
+ container->details->dnd_source_info->selection_cache = nautilus_drag_create_selection_cache (widget,
+ each_icon_get_data_binder);
+
+ nautilus_window_start_dnd (window, context);
}
void
nautilus_canvas_dnd_begin_drag (NautilusCanvasContainer *container,
- GdkDragAction actions,
- int button,
- GdkEventMotion *event,
- int start_x,
- int start_y)
+ GdkDragAction actions,
+ int button,
+ GdkEventMotion *event,
+ int start_x,
+ int start_y)
{
- NautilusCanvasDndInfo *dnd_info;
- NautilusDragInfo *dnd_source_info;
-
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_return_if_fail (event != NULL);
-
- dnd_info = container->details->dnd_info;
- container->details->dnd_source_info = g_new0 (NautilusDragInfo, 1);
- dnd_source_info = container->details->dnd_source_info;
- g_return_if_fail (dnd_info != NULL);
-
- /* Notice that the event is in bin_window coordinates, because of
- the way the canvas handles events.
- */
- dnd_info->drag_info.start_x = start_x -
- gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
- dnd_info->drag_info.start_y = start_y -
- gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
-
- dnd_source_info->source_actions = actions;
- /* start the drag */
- gtk_drag_begin_with_coordinates (GTK_WIDGET (container),
- dnd_info->drag_info.target_list,
- actions,
- button,
- (GdkEvent *) event,
- dnd_info->drag_info.start_x,
- dnd_info->drag_info.start_y);
+ NautilusCanvasDndInfo *dnd_info;
+ NautilusDragInfo *dnd_source_info;
+
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (event != NULL);
+
+ dnd_info = container->details->dnd_info;
+ container->details->dnd_source_info = g_new0 (NautilusDragInfo, 1);
+ dnd_source_info = container->details->dnd_source_info;
+ g_return_if_fail (dnd_info != NULL);
+
+ /* Notice that the event is in bin_window coordinates, because of
+ * the way the canvas handles events.
+ */
+ dnd_info->drag_info.start_x = start_x -
+ gtk_adjustment_get_value (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (container)));
+ dnd_info->drag_info.start_y = start_y -
+ gtk_adjustment_get_value (gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (container)));
+
+ dnd_source_info->source_actions = actions;
+ /* start the drag */
+ gtk_drag_begin_with_coordinates (GTK_WIDGET (container),
+ dnd_info->drag_info.target_list,
+ actions,
+ button,
+ (GdkEvent *) event,
+ dnd_info->drag_info.start_x,
+ dnd_info->drag_info.start_y);
}
static gboolean
@@ -1382,439 +1534,487 @@ drag_highlight_draw (GtkWidget *widget,
cairo_t *cr,
gpointer user_data)
{
- gint width, height;
- GdkWindow *window;
- GtkStyleContext *style;
-
- window = gtk_widget_get_window (widget);
- width = gdk_window_get_width (window);
- height = gdk_window_get_height (window);
+ gint width, height;
+ GdkWindow *window;
+ GtkStyleContext *style;
- style = gtk_widget_get_style_context (widget);
+ window = gtk_widget_get_window (widget);
+ width = gdk_window_get_width (window);
+ height = gdk_window_get_height (window);
- gtk_style_context_save (style);
- gtk_style_context_add_class (style, GTK_STYLE_CLASS_DND);
- gtk_style_context_set_state (style, GTK_STATE_FLAG_FOCUSED);
+ style = gtk_widget_get_style_context (widget);
- gtk_render_frame (style,
- cr,
- 0, 0, width, height);
+ gtk_style_context_save (style);
+ gtk_style_context_add_class (style, GTK_STYLE_CLASS_DND);
+ gtk_style_context_set_state (style, GTK_STATE_FLAG_FOCUSED);
- gtk_style_context_restore (style);
+ gtk_render_frame (style,
+ cr,
+ 0, 0, width, height);
- return FALSE;
+ gtk_style_context_restore (style);
+
+ return FALSE;
}
/* Queue a redraw of the dnd highlight rect */
static void
dnd_highlight_queue_redraw (GtkWidget *widget)
{
- NautilusCanvasDndInfo *dnd_info;
- int width, height;
- GtkAllocation allocation;
-
- dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
-
- if (!dnd_info->highlighted) {
- return;
- }
-
- gtk_widget_get_allocation (widget, &allocation);
- width = allocation.width;
- height = allocation.height;
-
- /* we don't know how wide the shadow is exactly,
- * so we expose a 10-pixel wide border
- */
- gtk_widget_queue_draw_area (widget,
- 0, 0,
- width, 10);
- gtk_widget_queue_draw_area (widget,
- 0, 0,
- 10, height);
- gtk_widget_queue_draw_area (widget,
- 0, height - 10,
- width, 10);
- gtk_widget_queue_draw_area (widget,
- width - 10, 0,
- 10, height);
+ NautilusCanvasDndInfo *dnd_info;
+ int width, height;
+ GtkAllocation allocation;
+
+ dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
+
+ if (!dnd_info->highlighted)
+ {
+ return;
+ }
+
+ gtk_widget_get_allocation (widget, &allocation);
+ width = allocation.width;
+ height = allocation.height;
+
+ /* we don't know how wide the shadow is exactly,
+ * so we expose a 10-pixel wide border
+ */
+ gtk_widget_queue_draw_area (widget,
+ 0, 0,
+ width, 10);
+ gtk_widget_queue_draw_area (widget,
+ 0, 0,
+ 10, height);
+ gtk_widget_queue_draw_area (widget,
+ 0, height - 10,
+ width, 10);
+ gtk_widget_queue_draw_area (widget,
+ width - 10, 0,
+ 10, height);
}
static void
start_dnd_highlight (GtkWidget *widget)
{
- NautilusCanvasDndInfo *dnd_info;
- GtkWidget *toplevel;
-
- dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
-
- toplevel = gtk_widget_get_toplevel (widget);
- if (toplevel != NULL &&
- g_object_get_data (G_OBJECT (toplevel), "is_desktop_window")) {
- return;
- }
-
- if (!dnd_info->highlighted) {
- dnd_info->highlighted = TRUE;
- g_signal_connect_after (widget, "draw",
- G_CALLBACK (drag_highlight_draw),
- NULL);
- dnd_highlight_queue_redraw (widget);
- }
+ NautilusCanvasDndInfo *dnd_info;
+ GtkWidget *toplevel;
+
+ dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
+
+ toplevel = gtk_widget_get_toplevel (widget);
+ if (toplevel != NULL &&
+ g_object_get_data (G_OBJECT (toplevel), "is_desktop_window"))
+ {
+ return;
+ }
+
+ if (!dnd_info->highlighted)
+ {
+ dnd_info->highlighted = TRUE;
+ g_signal_connect_after (widget, "draw",
+ G_CALLBACK (drag_highlight_draw),
+ NULL);
+ dnd_highlight_queue_redraw (widget);
+ }
}
static void
stop_dnd_highlight (GtkWidget *widget)
{
- NautilusCanvasDndInfo *dnd_info;
-
- dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
-
- if (dnd_info->highlighted) {
- g_signal_handlers_disconnect_by_func (widget,
- drag_highlight_draw,
- NULL);
- dnd_highlight_queue_redraw (widget);
- dnd_info->highlighted = FALSE;
- }
+ NautilusCanvasDndInfo *dnd_info;
+
+ dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
+
+ if (dnd_info->highlighted)
+ {
+ g_signal_handlers_disconnect_by_func (widget,
+ drag_highlight_draw,
+ NULL);
+ dnd_highlight_queue_redraw (widget);
+ dnd_info->highlighted = FALSE;
+ }
}
static gboolean
hover_timer (gpointer user_data)
{
- NautilusCanvasContainer *container = user_data;
- NautilusCanvasDndInfo *dnd_info;
+ NautilusCanvasContainer *container = user_data;
+ NautilusCanvasDndInfo *dnd_info;
- dnd_info = container->details->dnd_info;
+ dnd_info = container->details->dnd_info;
- dnd_info->hover_id = 0;
+ dnd_info->hover_id = 0;
- g_signal_emit_by_name (container, "handle-hover", dnd_info->target_uri);
+ g_signal_emit_by_name (container, "handle-hover", dnd_info->target_uri);
- return FALSE;
+ return FALSE;
}
static void
check_hover_timer (NautilusCanvasContainer *container,
- const char *uri)
+ const char *uri)
{
- NautilusCanvasDndInfo *dnd_info;
- GtkSettings *settings;
- guint timeout;
-
- dnd_info = container->details->dnd_info;
-
- if (g_strcmp0 (uri, dnd_info->target_uri) == 0) {
- return;
- }
-
- if (nautilus_canvas_container_get_is_desktop (container)) {
- return;
- }
-
- remove_hover_timer (dnd_info);
-
- settings = gtk_widget_get_settings (GTK_WIDGET (container));
- g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
-
- g_free (dnd_info->target_uri);
- dnd_info->target_uri = NULL;
-
- if (uri != NULL) {
- dnd_info->target_uri = g_strdup (uri);
- dnd_info->hover_id =
- gdk_threads_add_timeout (timeout,
- hover_timer,
- container);
- }
+ NautilusCanvasDndInfo *dnd_info;
+ GtkSettings *settings;
+ guint timeout;
+
+ dnd_info = container->details->dnd_info;
+
+ if (g_strcmp0 (uri, dnd_info->target_uri) == 0)
+ {
+ return;
+ }
+
+ if (nautilus_canvas_container_get_is_desktop (container))
+ {
+ return;
+ }
+
+ remove_hover_timer (dnd_info);
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (container));
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+
+ g_free (dnd_info->target_uri);
+ dnd_info->target_uri = NULL;
+
+ if (uri != NULL)
+ {
+ dnd_info->target_uri = g_strdup (uri);
+ dnd_info->hover_id =
+ gdk_threads_add_timeout (timeout,
+ hover_timer,
+ container);
+ }
}
static gboolean
-drag_motion_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x, int y,
- guint32 time)
+drag_motion_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ guint32 time)
{
- int action;
-
- nautilus_canvas_container_ensure_drag_data (NAUTILUS_CANVAS_CONTAINER (widget), context, time);
- nautilus_canvas_container_position_shadow (NAUTILUS_CANVAS_CONTAINER (widget), x, y);
- nautilus_canvas_dnd_update_drop_target (NAUTILUS_CANVAS_CONTAINER (widget), context, x, y);
- set_up_auto_scroll_if_needed (NAUTILUS_CANVAS_CONTAINER (widget));
- /* Find out what the drop actions are based on our drag selection and
- * the drop target.
- */
- action = 0;
- nautilus_canvas_container_get_drop_action (NAUTILUS_CANVAS_CONTAINER (widget), context, x, y,
- &action);
- if (action != 0) {
- char *uri;
- uri = nautilus_canvas_container_find_drop_target (NAUTILUS_CANVAS_CONTAINER (widget),
- context, x, y, NULL, TRUE);
- check_hover_timer (NAUTILUS_CANVAS_CONTAINER (widget), uri);
- g_free (uri);
- start_dnd_highlight (widget);
- } else {
- remove_hover_timer (NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info);
- }
-
- gdk_drag_status (context, action, time);
-
- return TRUE;
+ int action;
+
+ nautilus_canvas_container_ensure_drag_data (NAUTILUS_CANVAS_CONTAINER (widget), context, time);
+ nautilus_canvas_container_position_shadow (NAUTILUS_CANVAS_CONTAINER (widget), x, y);
+ nautilus_canvas_dnd_update_drop_target (NAUTILUS_CANVAS_CONTAINER (widget), context, x, y);
+ set_up_auto_scroll_if_needed (NAUTILUS_CANVAS_CONTAINER (widget));
+ /* Find out what the drop actions are based on our drag selection and
+ * the drop target.
+ */
+ action = 0;
+ nautilus_canvas_container_get_drop_action (NAUTILUS_CANVAS_CONTAINER (widget), context, x, y,
+ &action);
+ if (action != 0)
+ {
+ char *uri;
+ uri = nautilus_canvas_container_find_drop_target (NAUTILUS_CANVAS_CONTAINER (widget),
+ context, x, y, NULL, TRUE);
+ check_hover_timer (NAUTILUS_CANVAS_CONTAINER (widget), uri);
+ g_free (uri);
+ start_dnd_highlight (widget);
+ }
+ else
+ {
+ remove_hover_timer (NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info);
+ }
+
+ gdk_drag_status (context, action, time);
+
+ return TRUE;
}
static gboolean
-drag_drop_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- guint32 time,
- gpointer data)
+drag_drop_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ guint32 time,
+ gpointer data)
{
- NautilusCanvasDndInfo *dnd_info;
+ NautilusCanvasDndInfo *dnd_info;
- dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
+ dnd_info = NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info;
- /* tell the drag_data_received callback that
- the drop occured and that it can actually
- process the actions.
- make sure it is going to be called at least once.
- */
- dnd_info->drag_info.drop_occured = TRUE;
+ /* tell the drag_data_received callback that
+ * the drop occured and that it can actually
+ * process the actions.
+ * make sure it is going to be called at least once.
+ */
+ dnd_info->drag_info.drop_occured = TRUE;
- get_data_on_first_target_we_support (widget, context, time, x, y);
-
- return TRUE;
+ get_data_on_first_target_we_support (widget, context, time, x, y);
+
+ return TRUE;
}
void
nautilus_canvas_dnd_end_drag (NautilusCanvasContainer *container)
{
- NautilusCanvasDndInfo *dnd_info;
-
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
-
- dnd_info = container->details->dnd_info;
- g_return_if_fail (dnd_info != NULL);
- stop_auto_scroll (container);
- /* Do nothing.
- * Can that possibly be right?
- */
+ NautilusCanvasDndInfo *dnd_info;
+
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+
+ dnd_info = container->details->dnd_info;
+ g_return_if_fail (dnd_info != NULL);
+ stop_auto_scroll (container);
+ /* Do nothing.
+ * Can that possibly be right?
+ */
}
/** this callback is called in 2 cases.
- It is called upon drag_motion events to get the actual data
- In that case, it just makes sure it gets the data.
- It is called upon drop_drop events to execute the actual
- actions on the received action. In that case, it actually first makes sure
- that we have got the data then processes it.
-*/
+ * It is called upon drag_motion events to get the actual data
+ * In that case, it just makes sure it gets the data.
+ * It is called upon drop_drop events to execute the actual
+ * actions on the received action. In that case, it actually first makes sure
+ * that we have got the data then processes it.
+ */
static void
-drag_data_received_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- GtkSelectionData *data,
- guint info,
- guint32 time,
- gpointer user_data)
+drag_data_received_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ GtkSelectionData *data,
+ guint info,
+ guint32 time,
+ gpointer user_data)
{
- NautilusDragInfo *drag_info;
- guchar *tmp;
- const guchar *tmp_raw;
- int length;
- gboolean success;
-
- drag_info = &(NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info->drag_info);
-
- drag_info->got_drop_data_type = TRUE;
- drag_info->data_type = info;
-
- switch (info) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
- nautilus_canvas_container_dropped_canvas_feedback (widget, data, x, y);
- break;
- case NAUTILUS_ICON_DND_URI_LIST:
- case NAUTILUS_ICON_DND_TEXT:
- case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
- case NAUTILUS_ICON_DND_RAW:
- /* Save the data so we can do the actual work on drop. */
- if (drag_info->selection_data != NULL) {
- gtk_selection_data_free (drag_info->selection_data);
- }
- drag_info->selection_data = gtk_selection_data_copy (data);
- break;
-
- /* Netscape keeps sending us the data, even though we accept the first drag */
- case NAUTILUS_ICON_DND_NETSCAPE_URL:
- if (drag_info->selection_data != NULL) {
- gtk_selection_data_free (drag_info->selection_data);
- drag_info->selection_data = gtk_selection_data_copy (data);
- }
- break;
- case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
- /* Do nothing, this won't even happen, since we don't want to call get_data twice */
- break;
- }
-
- /* this is the second use case of this callback.
- * we have to do the actual work for the drop.
- */
- if (drag_info->drop_occured) {
-
- success = FALSE;
- switch (info) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
- nautilus_canvas_container_receive_dropped_icons
- (NAUTILUS_CANVAS_CONTAINER (widget),
- context, x, y);
- break;
- case NAUTILUS_ICON_DND_NETSCAPE_URL:
- receive_dropped_netscape_url
- (NAUTILUS_CANVAS_CONTAINER (widget),
- (char *) gtk_selection_data_get_data (data), context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_URI_LIST:
- receive_dropped_uri_list
- (NAUTILUS_CANVAS_CONTAINER (widget),
- (char *) gtk_selection_data_get_data (data), context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_TEXT:
- tmp = gtk_selection_data_get_text (data);
- receive_dropped_text
- (NAUTILUS_CANVAS_CONTAINER (widget),
- (char *) tmp, context, x, y);
- success = TRUE;
- g_free (tmp);
- break;
- case NAUTILUS_ICON_DND_RAW:
- length = gtk_selection_data_get_length (data);
- tmp_raw = gtk_selection_data_get_data (data);
- receive_dropped_raw
- (NAUTILUS_CANVAS_CONTAINER (widget),
- (const gchar *) tmp_raw, length, drag_info->direct_save_uri,
- context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
- /* Do nothing, everything is done by the sender */
- break;
- case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
- {
- const guchar *selection_data;
- gint selection_length;
- gint selection_format;
-
- selection_data = gtk_selection_data_get_data (drag_info->selection_data);
- selection_length = gtk_selection_data_get_length (drag_info->selection_data);
- selection_format = gtk_selection_data_get_format (drag_info->selection_data);
-
- if (selection_format == 8 &&
- selection_length == 1 &&
- selection_data[0] == 'F') {
- gtk_drag_get_data (widget, context,
- gdk_atom_intern (NAUTILUS_ICON_DND_RAW_TYPE,
- FALSE),
- time);
- return;
- } else if (selection_format == 8 &&
- selection_length == 1 &&
- selection_data[0] == 'F' &&
- drag_info->direct_save_uri != NULL) {
- GdkPoint p;
- GFile *location;
-
- location = g_file_new_for_uri (drag_info->direct_save_uri);
-
- nautilus_file_changes_queue_file_added (location);
- p.x = x; p.y = y;
- nautilus_file_changes_queue_schedule_position_set (
- location,
- p,
- gdk_screen_get_number (
- gtk_widget_get_screen (widget)));
- g_object_unref (location);
- nautilus_file_changes_consume_changes (TRUE);
- success = TRUE;
- }
- break;
- } /* NAUTILUS_ICON_DND_XDNDDIRECTSAVE */
- }
- gtk_drag_finish (context, success, FALSE, time);
-
- nautilus_canvas_container_free_drag_data (NAUTILUS_CANVAS_CONTAINER (widget));
-
- set_drop_target (NAUTILUS_CANVAS_CONTAINER (widget), NULL);
-
- /* reinitialise it for the next dnd */
- drag_info->drop_occured = FALSE;
- }
+ NautilusDragInfo *drag_info;
+ guchar *tmp;
+ const guchar *tmp_raw;
+ int length;
+ gboolean success;
+
+ drag_info = &(NAUTILUS_CANVAS_CONTAINER (widget)->details->dnd_info->drag_info);
+
+ drag_info->got_drop_data_type = TRUE;
+ drag_info->data_type = info;
+
+ switch (info)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ nautilus_canvas_container_dropped_canvas_feedback (widget, data, x, y);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ case NAUTILUS_ICON_DND_TEXT:
+ case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+ case NAUTILUS_ICON_DND_RAW:
+ {
+ /* Save the data so we can do the actual work on drop. */
+ if (drag_info->selection_data != NULL)
+ {
+ gtk_selection_data_free (drag_info->selection_data);
+ }
+ drag_info->selection_data = gtk_selection_data_copy (data);
+ }
+ break;
+
+ /* Netscape keeps sending us the data, even though we accept the first drag */
+ case NAUTILUS_ICON_DND_NETSCAPE_URL:
+ {
+ if (drag_info->selection_data != NULL)
+ {
+ gtk_selection_data_free (drag_info->selection_data);
+ drag_info->selection_data = gtk_selection_data_copy (data);
+ }
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
+ {
+ /* Do nothing, this won't even happen, since we don't want to call get_data twice */
+ }
+ break;
+ }
+
+ /* this is the second use case of this callback.
+ * we have to do the actual work for the drop.
+ */
+ if (drag_info->drop_occured)
+ {
+ success = FALSE;
+ switch (info)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ nautilus_canvas_container_receive_dropped_icons
+ (NAUTILUS_CANVAS_CONTAINER (widget),
+ context, x, y);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_NETSCAPE_URL:
+ {
+ receive_dropped_netscape_url
+ (NAUTILUS_CANVAS_CONTAINER (widget),
+ (char *) gtk_selection_data_get_data (data), context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ {
+ receive_dropped_uri_list
+ (NAUTILUS_CANVAS_CONTAINER (widget),
+ (char *) gtk_selection_data_get_data (data), context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_TEXT:
+ {
+ tmp = gtk_selection_data_get_text (data);
+ receive_dropped_text
+ (NAUTILUS_CANVAS_CONTAINER (widget),
+ (char *) tmp, context, x, y);
+ success = TRUE;
+ g_free (tmp);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_RAW:
+ {
+ length = gtk_selection_data_get_length (data);
+ tmp_raw = gtk_selection_data_get_data (data);
+ receive_dropped_raw
+ (NAUTILUS_CANVAS_CONTAINER (widget),
+ (const gchar *) tmp_raw, length, drag_info->direct_save_uri,
+ context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
+ {
+ /* Do nothing, everything is done by the sender */
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+ {
+ const guchar *selection_data;
+ gint selection_length;
+ gint selection_format;
+
+ selection_data = gtk_selection_data_get_data (drag_info->selection_data);
+ selection_length = gtk_selection_data_get_length (drag_info->selection_data);
+ selection_format = gtk_selection_data_get_format (drag_info->selection_data);
+
+ if (selection_format == 8 &&
+ selection_length == 1 &&
+ selection_data[0] == 'F')
+ {
+ gtk_drag_get_data (widget, context,
+ gdk_atom_intern (NAUTILUS_ICON_DND_RAW_TYPE,
+ FALSE),
+ time);
+ return;
+ }
+ else if (selection_format == 8 &&
+ selection_length == 1 &&
+ selection_data[0] == 'F' &&
+ drag_info->direct_save_uri != NULL)
+ {
+ GdkPoint p;
+ GFile *location;
+
+ location = g_file_new_for_uri (drag_info->direct_save_uri);
+
+ nautilus_file_changes_queue_file_added (location);
+ p.x = x;
+ p.y = y;
+ nautilus_file_changes_queue_schedule_position_set (
+ location,
+ p,
+ gdk_screen_get_number (
+ gtk_widget_get_screen (widget)));
+ g_object_unref (location);
+ nautilus_file_changes_consume_changes (TRUE);
+ success = TRUE;
+ }
+ break;
+ } /* NAUTILUS_ICON_DND_XDNDDIRECTSAVE */
+ }
+ gtk_drag_finish (context, success, FALSE, time);
+
+ nautilus_canvas_container_free_drag_data (NAUTILUS_CANVAS_CONTAINER (widget));
+
+ set_drop_target (NAUTILUS_CANVAS_CONTAINER (widget), NULL);
+ /* reinitialise it for the next dnd */
+ drag_info->drop_occured = FALSE;
+ }
}
void
nautilus_canvas_dnd_init (NautilusCanvasContainer *container)
{
- GtkTargetList *targets;
- int n_elements;
-
- g_return_if_fail (container != NULL);
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
-
-
- container->details->dnd_info = g_new0 (NautilusCanvasDndInfo, 1);
- nautilus_drag_init (&container->details->dnd_info->drag_info,
- drag_types, G_N_ELEMENTS (drag_types), TRUE);
-
- /* Set up the widget as a drag destination.
- * (But not a source, as drags starting from this widget will be
- * implemented by dealing with events manually.)
- */
- n_elements = G_N_ELEMENTS (drop_types);
- if (!nautilus_canvas_container_get_is_desktop (container)) {
- /* Don't set up rootwindow drop */
- n_elements -= 1;
- }
- gtk_drag_dest_set (GTK_WIDGET (container),
- 0,
- drop_types, n_elements,
- GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
-
- targets = gtk_drag_dest_get_target_list (GTK_WIDGET (container));
- gtk_target_list_add_text_targets (targets, NAUTILUS_ICON_DND_TEXT);
-
-
- /* Messages for outgoing drag. */
- g_signal_connect (container, "drag-begin",
- G_CALLBACK (drag_begin_callback), NULL);
- g_signal_connect (container, "drag-data-get",
- G_CALLBACK (drag_data_get_callback), NULL);
- g_signal_connect (container, "drag-end",
- G_CALLBACK (drag_end_callback), NULL);
-
- /* Messages for incoming drag. */
- g_signal_connect (container, "drag-data-received",
- G_CALLBACK (drag_data_received_callback), NULL);
- g_signal_connect (container, "drag-motion",
- G_CALLBACK (drag_motion_callback), NULL);
- g_signal_connect (container, "drag-drop",
- G_CALLBACK (drag_drop_callback), NULL);
- g_signal_connect (container, "drag-leave",
- G_CALLBACK (drag_leave_callback), NULL);
+ GtkTargetList *targets;
+ int n_elements;
+
+ g_return_if_fail (container != NULL);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+
+
+ container->details->dnd_info = g_new0 (NautilusCanvasDndInfo, 1);
+ nautilus_drag_init (&container->details->dnd_info->drag_info,
+ drag_types, G_N_ELEMENTS (drag_types), TRUE);
+
+ /* Set up the widget as a drag destination.
+ * (But not a source, as drags starting from this widget will be
+ * implemented by dealing with events manually.)
+ */
+ n_elements = G_N_ELEMENTS (drop_types);
+ if (!nautilus_canvas_container_get_is_desktop (container))
+ {
+ /* Don't set up rootwindow drop */
+ n_elements -= 1;
+ }
+ gtk_drag_dest_set (GTK_WIDGET (container),
+ 0,
+ drop_types, n_elements,
+ GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK);
+
+ targets = gtk_drag_dest_get_target_list (GTK_WIDGET (container));
+ gtk_target_list_add_text_targets (targets, NAUTILUS_ICON_DND_TEXT);
+
+
+ /* Messages for outgoing drag. */
+ g_signal_connect (container, "drag-begin",
+ G_CALLBACK (drag_begin_callback), NULL);
+ g_signal_connect (container, "drag-data-get",
+ G_CALLBACK (drag_data_get_callback), NULL);
+ g_signal_connect (container, "drag-end",
+ G_CALLBACK (drag_end_callback), NULL);
+
+ /* Messages for incoming drag. */
+ g_signal_connect (container, "drag-data-received",
+ G_CALLBACK (drag_data_received_callback), NULL);
+ g_signal_connect (container, "drag-motion",
+ G_CALLBACK (drag_motion_callback), NULL);
+ g_signal_connect (container, "drag-drop",
+ G_CALLBACK (drag_drop_callback), NULL);
+ g_signal_connect (container, "drag-leave",
+ G_CALLBACK (drag_leave_callback), NULL);
}
void
nautilus_canvas_dnd_fini (NautilusCanvasContainer *container)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container));
- if (container->details->dnd_info != NULL) {
- stop_auto_scroll (container);
+ if (container->details->dnd_info != NULL)
+ {
+ stop_auto_scroll (container);
- nautilus_drag_finalize (&container->details->dnd_info->drag_info);
- container->details->dnd_info = NULL;
- }
+ nautilus_drag_finalize (&container->details->dnd_info->drag_info);
+ container->details->dnd_info = NULL;
+ }
}
diff --git a/src/nautilus-canvas-item.c b/src/nautilus-canvas-item.c
index 9205af4d5..a103d34a4 100644
--- a/src/nautilus-canvas-item.c
+++ b/src/nautilus-canvas-item.c
@@ -1,4 +1,3 @@
-
/* Nautilus - Canvas item class for canvas container.
*
* Copyright (C) 2000 Eazel, Inc
@@ -62,7 +61,7 @@
* each item has three text height variables:
* + text_height: actual height of the displayed (i.e. on-screen) PangoLayout.
* + text_height_for_layout: height used in canvas grid layout algorithms.
- * “sane amount” of text.
+ * “sane amount” of text.
* “sane amount“ as of
* + hard-coded to three lines in text-below-icon mode.
*
@@ -75,106 +74,109 @@
*/
/* Private part of the NautilusCanvasItem structure. */
-struct NautilusCanvasItemDetails {
- /* The image, text, font. */
- double x, y;
- GdkPixbuf *pixbuf;
- cairo_surface_t *rendered_surface;
- char *editable_text; /* Text that can be modified by a renaming function */
- char *additional_text; /* Text that cannot be modifed, such as file size, etc. */
-
- /* Size of the text at current font. */
- int text_dx;
- int text_width;
-
- /* actual size required for rendering the text to display */
- int text_height;
- /* actual size that would be required for rendering the entire text if it wasn't ellipsized */
- int text_height_for_entire_text;
- /* actual size needed for rendering a “sane amount” of text */
- int text_height_for_layout;
-
- int editable_text_height;
-
- /* whether the entire text must always be visible. In that case,
- * text_height_for_layout will always be equal to text_height.
- * Used for the last line of a line-wise icon layout. */
- guint entire_text : 1;
-
- /* Highlight state. */
- guint is_highlighted_for_selection : 1;
- guint is_highlighted_as_keyboard_focus: 1;
- guint is_highlighted_for_drop : 1;
- guint is_highlighted_for_clipboard : 1;
- guint show_stretch_handles : 1;
- guint is_prelit : 1;
-
- guint rendered_is_highlighted_for_selection : 1;
- guint rendered_is_highlighted_for_drop : 1;
- guint rendered_is_highlighted_for_clipboard : 1;
- guint rendered_is_prelit : 1;
- guint rendered_is_focused : 1;
-
- guint bounds_cached : 1;
-
- guint is_visible : 1;
-
- /* Cached PangoLayouts. Only used if the icon is visible */
- PangoLayout *editable_text_layout;
- PangoLayout *additional_text_layout;
-
- /* Cached rectangle in canvas coordinates */
- EelIRect icon_rect;
- EelIRect text_rect;
-
- EelIRect bounds_cache;
- EelIRect bounds_cache_for_layout;
- EelIRect bounds_cache_for_entire_item;
-
- GdkWindow *cursor_window;
-
- /* Accessibility bits */
- GailTextUtil *text_util;
+struct NautilusCanvasItemDetails
+{
+ /* The image, text, font. */
+ double x, y;
+ GdkPixbuf *pixbuf;
+ cairo_surface_t *rendered_surface;
+ char *editable_text; /* Text that can be modified by a renaming function */
+ char *additional_text; /* Text that cannot be modifed, such as file size, etc. */
+
+ /* Size of the text at current font. */
+ int text_dx;
+ int text_width;
+
+ /* actual size required for rendering the text to display */
+ int text_height;
+ /* actual size that would be required for rendering the entire text if it wasn't ellipsized */
+ int text_height_for_entire_text;
+ /* actual size needed for rendering a “sane amount” of text */
+ int text_height_for_layout;
+
+ int editable_text_height;
+
+ /* whether the entire text must always be visible. In that case,
+ * text_height_for_layout will always be equal to text_height.
+ * Used for the last line of a line-wise icon layout. */
+ guint entire_text : 1;
+
+ /* Highlight state. */
+ guint is_highlighted_for_selection : 1;
+ guint is_highlighted_as_keyboard_focus : 1;
+ guint is_highlighted_for_drop : 1;
+ guint is_highlighted_for_clipboard : 1;
+ guint show_stretch_handles : 1;
+ guint is_prelit : 1;
+
+ guint rendered_is_highlighted_for_selection : 1;
+ guint rendered_is_highlighted_for_drop : 1;
+ guint rendered_is_highlighted_for_clipboard : 1;
+ guint rendered_is_prelit : 1;
+ guint rendered_is_focused : 1;
+
+ guint bounds_cached : 1;
+
+ guint is_visible : 1;
+
+ /* Cached PangoLayouts. Only used if the icon is visible */
+ PangoLayout *editable_text_layout;
+ PangoLayout *additional_text_layout;
+
+ /* Cached rectangle in canvas coordinates */
+ EelIRect icon_rect;
+ EelIRect text_rect;
+
+ EelIRect bounds_cache;
+ EelIRect bounds_cache_for_layout;
+ EelIRect bounds_cache_for_entire_item;
+
+ GdkWindow *cursor_window;
+
+ /* Accessibility bits */
+ GailTextUtil *text_util;
};
/* Object argument IDs. */
-enum {
- PROP_0,
- PROP_EDITABLE_TEXT,
- PROP_ADDITIONAL_TEXT,
- PROP_HIGHLIGHTED_FOR_SELECTION,
- PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
- PROP_HIGHLIGHTED_FOR_DROP,
- PROP_HIGHLIGHTED_FOR_CLIPBOARD
+enum
+{
+ PROP_0,
+ PROP_EDITABLE_TEXT,
+ PROP_ADDITIONAL_TEXT,
+ PROP_HIGHLIGHTED_FOR_SELECTION,
+ PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
+ PROP_HIGHLIGHTED_FOR_DROP,
+ PROP_HIGHLIGHTED_FOR_CLIPBOARD
};
-typedef enum {
- RIGHT_SIDE,
- BOTTOM_SIDE,
- LEFT_SIDE,
- TOP_SIDE
+typedef enum
+{
+ RIGHT_SIDE,
+ BOTTOM_SIDE,
+ LEFT_SIDE,
+ TOP_SIDE
} RectangleSide;
static void nautilus_canvas_item_text_interface_init (EelAccessibleTextIface *iface);
static GType nautilus_canvas_item_accessible_factory_get_type (void);
G_DEFINE_TYPE_WITH_CODE (NautilusCanvasItem, nautilus_canvas_item, EEL_TYPE_CANVAS_ITEM,
- G_IMPLEMENT_INTERFACE (EEL_TYPE_ACCESSIBLE_TEXT,
- nautilus_canvas_item_text_interface_init));
+ G_IMPLEMENT_INTERFACE (EEL_TYPE_ACCESSIBLE_TEXT,
+ nautilus_canvas_item_text_interface_init));
/* private */
-static void get_icon_rectangle (NautilusCanvasItem *item,
- EelIRect *rect);
-static void draw_pixbuf (GdkPixbuf *pixbuf,
- cairo_t *cr,
- int x,
- int y);
-static PangoLayout *get_label_layout (PangoLayout **layout,
- NautilusCanvasItem *item,
- const char *text);
-static gboolean hit_test_stretch_handle (NautilusCanvasItem *item,
- EelIRect icon_rect,
- GtkCornerType *corner);
+static void get_icon_rectangle (NautilusCanvasItem *item,
+ EelIRect *rect);
+static void draw_pixbuf (GdkPixbuf *pixbuf,
+ cairo_t *cr,
+ int x,
+ int y);
+static PangoLayout *get_label_layout (PangoLayout **layout,
+ NautilusCanvasItem *item,
+ const char *text);
+static gboolean hit_test_stretch_handle (NautilusCanvasItem *item,
+ EelIRect icon_rect,
+ GtkCornerType *corner);
;
static void nautilus_canvas_item_ensure_bounds_up_to_date (NautilusCanvasItem *canvas_item);
@@ -183,50 +185,56 @@ static void nautilus_canvas_item_ensure_bounds_up_to_date (NautilusCanvasI
static void
nautilus_canvas_item_init (NautilusCanvasItem *canvas_item)
{
- canvas_item->details = G_TYPE_INSTANCE_GET_PRIVATE ((canvas_item), NAUTILUS_TYPE_CANVAS_ITEM, NautilusCanvasItemDetails);
- nautilus_canvas_item_invalidate_label_size (canvas_item);
+ canvas_item->details = G_TYPE_INSTANCE_GET_PRIVATE ((canvas_item), NAUTILUS_TYPE_CANVAS_ITEM, NautilusCanvasItemDetails);
+ nautilus_canvas_item_invalidate_label_size (canvas_item);
}
static void
nautilus_canvas_item_finalize (GObject *object)
{
- NautilusCanvasItemDetails *details;
+ NautilusCanvasItemDetails *details;
+
+ g_assert (NAUTILUS_IS_CANVAS_ITEM (object));
- g_assert (NAUTILUS_IS_CANVAS_ITEM (object));
+ details = NAUTILUS_CANVAS_ITEM (object)->details;
- details = NAUTILUS_CANVAS_ITEM (object)->details;
+ if (details->cursor_window != NULL)
+ {
+ gdk_window_set_cursor (details->cursor_window, NULL);
+ g_object_unref (details->cursor_window);
+ }
- if (details->cursor_window != NULL) {
- gdk_window_set_cursor (details->cursor_window, NULL);
- g_object_unref (details->cursor_window);
- }
+ if (details->pixbuf != NULL)
+ {
+ g_object_unref (details->pixbuf);
+ }
- if (details->pixbuf != NULL) {
- g_object_unref (details->pixbuf);
- }
-
- if (details->text_util != NULL) {
- g_object_unref (details->text_util);
- }
+ if (details->text_util != NULL)
+ {
+ g_object_unref (details->text_util);
+ }
- g_free (details->editable_text);
- g_free (details->additional_text);
+ g_free (details->editable_text);
+ g_free (details->additional_text);
- if (details->rendered_surface != NULL) {
- cairo_surface_destroy (details->rendered_surface);
- }
+ if (details->rendered_surface != NULL)
+ {
+ cairo_surface_destroy (details->rendered_surface);
+ }
- if (details->editable_text_layout != NULL) {
- g_object_unref (details->editable_text_layout);
- }
+ if (details->editable_text_layout != NULL)
+ {
+ g_object_unref (details->editable_text_layout);
+ }
- if (details->additional_text_layout != NULL) {
- g_object_unref (details->additional_text_layout);
- }
+ if (details->additional_text_layout != NULL)
+ {
+ g_object_unref (details->additional_text_layout);
+ }
- G_OBJECT_CLASS (nautilus_canvas_item_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_canvas_item_parent_class)->finalize (object);
}
-
+
/* Currently we require pixbufs in this format (for hit testing).
* Perhaps gdk-pixbuf will be changed so it can do the hit testing
* and we won't have this requirement any more.
@@ -234,229 +242,274 @@ nautilus_canvas_item_finalize (GObject *object)
static gboolean
pixbuf_is_acceptable (GdkPixbuf *pixbuf)
{
- return gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB
- && ((!gdk_pixbuf_get_has_alpha (pixbuf)
- && gdk_pixbuf_get_n_channels (pixbuf) == 3)
- || (gdk_pixbuf_get_has_alpha (pixbuf)
- && gdk_pixbuf_get_n_channels (pixbuf) == 4))
- && gdk_pixbuf_get_bits_per_sample (pixbuf) == 8;
+ return gdk_pixbuf_get_colorspace (pixbuf) == GDK_COLORSPACE_RGB
+ && ((!gdk_pixbuf_get_has_alpha (pixbuf)
+ && gdk_pixbuf_get_n_channels (pixbuf) == 3)
+ || (gdk_pixbuf_get_has_alpha (pixbuf)
+ && gdk_pixbuf_get_n_channels (pixbuf) == 4))
+ && gdk_pixbuf_get_bits_per_sample (pixbuf) == 8;
}
static void
nautilus_canvas_item_invalidate_bounds_cache (NautilusCanvasItem *item)
{
- item->details->bounds_cached = FALSE;
+ item->details->bounds_cached = FALSE;
}
/* invalidate the text width and height cached in the item details. */
void
nautilus_canvas_item_invalidate_label_size (NautilusCanvasItem *item)
{
- if (item->details->editable_text_layout != NULL) {
- pango_layout_context_changed (item->details->editable_text_layout);
- }
- if (item->details->additional_text_layout != NULL) {
- pango_layout_context_changed (item->details->additional_text_layout);
- }
- nautilus_canvas_item_invalidate_bounds_cache (item);
- item->details->text_width = -1;
- item->details->text_height = -1;
- item->details->text_height_for_layout = -1;
- item->details->text_height_for_entire_text = -1;
- item->details->editable_text_height = -1;
+ if (item->details->editable_text_layout != NULL)
+ {
+ pango_layout_context_changed (item->details->editable_text_layout);
+ }
+ if (item->details->additional_text_layout != NULL)
+ {
+ pango_layout_context_changed (item->details->additional_text_layout);
+ }
+ nautilus_canvas_item_invalidate_bounds_cache (item);
+ item->details->text_width = -1;
+ item->details->text_height = -1;
+ item->details->text_height_for_layout = -1;
+ item->details->text_height_for_entire_text = -1;
+ item->details->editable_text_height = -1;
}
/* Set property handler for the canvas item. */
static void
-nautilus_canvas_item_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NautilusCanvasItem *item;
- NautilusCanvasItemDetails *details;
- AtkObject *accessible;
-
- item = NAUTILUS_CANVAS_ITEM (object);
- accessible = atk_gobject_accessible_for_object (G_OBJECT (item));
- details = item->details;
-
- switch (property_id) {
-
- case PROP_EDITABLE_TEXT:
- if (g_strcmp0 (details->editable_text,
- g_value_get_string (value)) == 0) {
- return;
- }
-
- g_free (details->editable_text);
- details->editable_text = g_strdup (g_value_get_string (value));
- if (details->text_util) {
- gail_text_util_text_setup (details->text_util,
- details->editable_text);
- g_object_notify (G_OBJECT(accessible), "accessible-name");
- }
-
- nautilus_canvas_item_invalidate_label_size (item);
- if (details->editable_text_layout) {
- g_object_unref (details->editable_text_layout);
- details->editable_text_layout = NULL;
- }
- break;
-
- case PROP_ADDITIONAL_TEXT:
- if (g_strcmp0 (details->additional_text,
- g_value_get_string (value)) == 0) {
- return;
- }
-
- g_free (details->additional_text);
- details->additional_text = g_strdup (g_value_get_string (value));
-
- nautilus_canvas_item_invalidate_label_size (item);
- if (details->additional_text_layout) {
- g_object_unref (details->additional_text_layout);
- details->additional_text_layout = NULL;
- }
- break;
-
- case PROP_HIGHLIGHTED_FOR_SELECTION:
- if (!details->is_highlighted_for_selection == !g_value_get_boolean (value)) {
- return;
- }
- details->is_highlighted_for_selection = g_value_get_boolean (value);
- nautilus_canvas_item_invalidate_label_size (item);
-
- atk_object_notify_state_change (accessible, ATK_STATE_SELECTED,
- details->is_highlighted_for_selection);
-
- break;
-
+nautilus_canvas_item_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusCanvasItem *item;
+ NautilusCanvasItemDetails *details;
+ AtkObject *accessible;
+
+ item = NAUTILUS_CANVAS_ITEM (object);
+ accessible = atk_gobject_accessible_for_object (G_OBJECT (item));
+ details = item->details;
+
+ switch (property_id)
+ {
+ case PROP_EDITABLE_TEXT:
+ {
+ if (g_strcmp0 (details->editable_text,
+ g_value_get_string (value)) == 0)
+ {
+ return;
+ }
+
+ g_free (details->editable_text);
+ details->editable_text = g_strdup (g_value_get_string (value));
+ if (details->text_util)
+ {
+ gail_text_util_text_setup (details->text_util,
+ details->editable_text);
+ g_object_notify (G_OBJECT (accessible), "accessible-name");
+ }
+
+ nautilus_canvas_item_invalidate_label_size (item);
+ if (details->editable_text_layout)
+ {
+ g_object_unref (details->editable_text_layout);
+ details->editable_text_layout = NULL;
+ }
+ }
+ break;
+
+ case PROP_ADDITIONAL_TEXT:
+ {
+ if (g_strcmp0 (details->additional_text,
+ g_value_get_string (value)) == 0)
+ {
+ return;
+ }
+
+ g_free (details->additional_text);
+ details->additional_text = g_strdup (g_value_get_string (value));
+
+ nautilus_canvas_item_invalidate_label_size (item);
+ if (details->additional_text_layout)
+ {
+ g_object_unref (details->additional_text_layout);
+ details->additional_text_layout = NULL;
+ }
+ }
+ break;
+
+ case PROP_HIGHLIGHTED_FOR_SELECTION:
+ {
+ if (!details->is_highlighted_for_selection == !g_value_get_boolean (value))
+ {
+ return;
+ }
+ details->is_highlighted_for_selection = g_value_get_boolean (value);
+ nautilus_canvas_item_invalidate_label_size (item);
+
+ atk_object_notify_state_change (accessible, ATK_STATE_SELECTED,
+ details->is_highlighted_for_selection);
+ }
+ break;
+
case PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS:
- if (!details->is_highlighted_as_keyboard_focus == !g_value_get_boolean (value)) {
- return;
- }
- details->is_highlighted_as_keyboard_focus = g_value_get_boolean (value);
-
- atk_object_notify_state_change (accessible, ATK_STATE_FOCUSED,
- details->is_highlighted_as_keyboard_focus);
- break;
-
+ {
+ if (!details->is_highlighted_as_keyboard_focus == !g_value_get_boolean (value))
+ {
+ return;
+ }
+ details->is_highlighted_as_keyboard_focus = g_value_get_boolean (value);
+
+ atk_object_notify_state_change (accessible, ATK_STATE_FOCUSED,
+ details->is_highlighted_as_keyboard_focus);
+ }
+ break;
+
case PROP_HIGHLIGHTED_FOR_DROP:
- if (!details->is_highlighted_for_drop == !g_value_get_boolean (value)) {
- return;
- }
- details->is_highlighted_for_drop = g_value_get_boolean (value);
- break;
-
- case PROP_HIGHLIGHTED_FOR_CLIPBOARD:
- if (!details->is_highlighted_for_clipboard == !g_value_get_boolean (value)) {
- return;
- }
- details->is_highlighted_for_clipboard = g_value_get_boolean (value);
- break;
-
- default:
- g_warning ("nautilus_canvas_item_set_property on unknown argument");
- return;
- }
-
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (object));
+ {
+ if (!details->is_highlighted_for_drop == !g_value_get_boolean (value))
+ {
+ return;
+ }
+ details->is_highlighted_for_drop = g_value_get_boolean (value);
+ }
+ break;
+
+ case PROP_HIGHLIGHTED_FOR_CLIPBOARD:
+ {
+ if (!details->is_highlighted_for_clipboard == !g_value_get_boolean (value))
+ {
+ return;
+ }
+ details->is_highlighted_for_clipboard = g_value_get_boolean (value);
+ }
+ break;
+
+ default:
+ g_warning ("nautilus_canvas_item_set_property on unknown argument");
+ return;
+ }
+
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (object));
}
/* Get property handler for the canvas item */
static void
-nautilus_canvas_item_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NautilusCanvasItemDetails *details;
-
- details = NAUTILUS_CANVAS_ITEM (object)->details;
-
- switch (property_id) {
-
- case PROP_EDITABLE_TEXT:
- g_value_set_string (value, details->editable_text);
- break;
-
- case PROP_ADDITIONAL_TEXT:
- g_value_set_string (value, details->additional_text);
- break;
-
+nautilus_canvas_item_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusCanvasItemDetails *details;
+
+ details = NAUTILUS_CANVAS_ITEM (object)->details;
+
+ switch (property_id)
+ {
+ case PROP_EDITABLE_TEXT:
+ {
+ g_value_set_string (value, details->editable_text);
+ }
+ break;
+
+ case PROP_ADDITIONAL_TEXT:
+ {
+ g_value_set_string (value, details->additional_text);
+ }
+ break;
+
case PROP_HIGHLIGHTED_FOR_SELECTION:
- g_value_set_boolean (value, details->is_highlighted_for_selection);
- break;
-
+ {
+ g_value_set_boolean (value, details->is_highlighted_for_selection);
+ }
+ break;
+
case PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS:
- g_value_set_boolean (value, details->is_highlighted_as_keyboard_focus);
- break;
-
+ {
+ g_value_set_boolean (value, details->is_highlighted_as_keyboard_focus);
+ }
+ break;
+
case PROP_HIGHLIGHTED_FOR_DROP:
- g_value_set_boolean (value, details->is_highlighted_for_drop);
- break;
+ {
+ g_value_set_boolean (value, details->is_highlighted_for_drop);
+ }
+ break;
- case PROP_HIGHLIGHTED_FOR_CLIPBOARD:
- g_value_set_boolean (value, details->is_highlighted_for_clipboard);
- break;
+ case PROP_HIGHLIGHTED_FOR_CLIPBOARD:
+ {
+ g_value_set_boolean (value, details->is_highlighted_for_clipboard);
+ }
+ break;
default:
- g_warning ("invalid property %d", property_id);
- break;
- }
+ {
+ g_warning ("invalid property %d", property_id);
+ }
+ break;
+ }
}
static void
get_scaled_icon_size (NautilusCanvasItem *item,
- gint *width,
- gint *height)
-{
- EelCanvas *canvas;
- GdkPixbuf *pixbuf = NULL;
- gint scale;
-
- if (item != NULL) {
- canvas = EEL_CANVAS_ITEM (item)->canvas;
- scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas));
- pixbuf = item->details->pixbuf;
- }
-
- if (width)
- *width = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_width (pixbuf) / scale);
- if (height)
- *height = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_height (pixbuf) / scale);
+ gint *width,
+ gint *height)
+{
+ EelCanvas *canvas;
+ GdkPixbuf *pixbuf = NULL;
+ gint scale;
+
+ if (item != NULL)
+ {
+ canvas = EEL_CANVAS_ITEM (item)->canvas;
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas));
+ pixbuf = item->details->pixbuf;
+ }
+
+ if (width)
+ {
+ *width = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_width (pixbuf) / scale);
+ }
+ if (height)
+ {
+ *height = (pixbuf == NULL) ? 0 : (gdk_pixbuf_get_height (pixbuf) / scale);
+ }
}
void
nautilus_canvas_item_set_image (NautilusCanvasItem *item,
- GdkPixbuf *image)
-{
- NautilusCanvasItemDetails *details;
-
- g_return_if_fail (NAUTILUS_IS_CANVAS_ITEM (item));
- g_return_if_fail (image == NULL || pixbuf_is_acceptable (image));
-
- details = item->details;
- if (details->pixbuf == image) {
- return;
- }
-
- if (image != NULL) {
- g_object_ref (image);
- }
- if (details->pixbuf != NULL) {
- g_object_unref (details->pixbuf);
- }
- if (details->rendered_surface != NULL) {
- cairo_surface_destroy (details->rendered_surface);
- details->rendered_surface = NULL;
- }
-
- details->pixbuf = image;
-
- nautilus_canvas_item_invalidate_bounds_cache (item);
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (item));
+ GdkPixbuf *image)
+{
+ NautilusCanvasItemDetails *details;
+
+ g_return_if_fail (NAUTILUS_IS_CANVAS_ITEM (item));
+ g_return_if_fail (image == NULL || pixbuf_is_acceptable (image));
+
+ details = item->details;
+ if (details->pixbuf == image)
+ {
+ return;
+ }
+
+ if (image != NULL)
+ {
+ g_object_ref (image);
+ }
+ if (details->pixbuf != NULL)
+ {
+ g_object_unref (details->pixbuf);
+ }
+ if (details->rendered_surface != NULL)
+ {
+ cairo_surface_destroy (details->rendered_surface);
+ details->rendered_surface = NULL;
+ }
+
+ details->pixbuf = image;
+
+ nautilus_canvas_item_invalidate_bounds_cache (item);
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (item));
}
/* Recomputes the bounding box of a canvas item.
@@ -465,152 +518,166 @@ nautilus_canvas_item_set_image (NautilusCanvasItem *item,
*/
static void
recompute_bounding_box (NautilusCanvasItem *canvas_item,
- double i2w_dx, double i2w_dy)
+ double i2w_dx,
+ double i2w_dy)
{
- /* The bounds stored in the item is the same as what get_bounds
- * returns, except it's in canvas coordinates instead of the item's
- * parent's coordinates.
- */
+ /* The bounds stored in the item is the same as what get_bounds
+ * returns, except it's in canvas coordinates instead of the item's
+ * parent's coordinates.
+ */
- EelCanvasItem *item;
- EelDRect bounds_rect;
+ EelCanvasItem *item;
+ EelDRect bounds_rect;
- item = EEL_CANVAS_ITEM (canvas_item);
+ item = EEL_CANVAS_ITEM (canvas_item);
- eel_canvas_item_get_bounds (item,
- &bounds_rect.x0, &bounds_rect.y0,
- &bounds_rect.x1, &bounds_rect.y1);
+ eel_canvas_item_get_bounds (item,
+ &bounds_rect.x0, &bounds_rect.y0,
+ &bounds_rect.x1, &bounds_rect.y1);
- bounds_rect.x0 += i2w_dx;
- bounds_rect.y0 += i2w_dy;
- bounds_rect.x1 += i2w_dx;
- bounds_rect.y1 += i2w_dy;
- eel_canvas_w2c_d (item->canvas,
- bounds_rect.x0, bounds_rect.y0,
- &item->x1, &item->y1);
- eel_canvas_w2c_d (item->canvas,
- bounds_rect.x1, bounds_rect.y1,
- &item->x2, &item->y2);
+ bounds_rect.x0 += i2w_dx;
+ bounds_rect.y0 += i2w_dy;
+ bounds_rect.x1 += i2w_dx;
+ bounds_rect.y1 += i2w_dy;
+ eel_canvas_w2c_d (item->canvas,
+ bounds_rect.x0, bounds_rect.y0,
+ &item->x1, &item->y1);
+ eel_canvas_w2c_d (item->canvas,
+ bounds_rect.x1, bounds_rect.y1,
+ &item->x2, &item->y2);
}
static EelIRect
-compute_text_rectangle (const NautilusCanvasItem *item,
- EelIRect icon_rectangle,
- gboolean canvas_coords,
- NautilusCanvasItemBoundsUsage usage)
-{
- EelIRect text_rectangle;
- double pixels_per_unit;
- double text_width, text_height, text_height_for_layout, text_height_for_entire_text, real_text_height;
-
- pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
- if (canvas_coords) {
- text_width = item->details->text_width;
- text_height = item->details->text_height;
- text_height_for_layout = item->details->text_height_for_layout;
- text_height_for_entire_text = item->details->text_height_for_entire_text;
- } else {
- text_width = item->details->text_width / pixels_per_unit;
- text_height = item->details->text_height / pixels_per_unit;
- text_height_for_layout = item->details->text_height_for_layout / pixels_per_unit;
- text_height_for_entire_text = item->details->text_height_for_entire_text / pixels_per_unit;
- }
-
- text_rectangle.x0 = (icon_rectangle.x0 + icon_rectangle.x1) / 2 - (int) text_width / 2;
- text_rectangle.y0 = icon_rectangle.y1;
- text_rectangle.x1 = text_rectangle.x0 + text_width;
-
- if (usage == BOUNDS_USAGE_FOR_LAYOUT) {
- real_text_height = text_height_for_layout;
- } else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM) {
- real_text_height = text_height_for_entire_text;
- } else if (usage == BOUNDS_USAGE_FOR_DISPLAY) {
- real_text_height = text_height;
- } else {
- g_assert_not_reached ();
- }
-
- text_rectangle.y1 = text_rectangle.y0 + real_text_height + LABEL_OFFSET / pixels_per_unit;
-
- return text_rectangle;
+compute_text_rectangle (const NautilusCanvasItem *item,
+ EelIRect icon_rectangle,
+ gboolean canvas_coords,
+ NautilusCanvasItemBoundsUsage usage)
+{
+ EelIRect text_rectangle;
+ double pixels_per_unit;
+ double text_width, text_height, text_height_for_layout, text_height_for_entire_text, real_text_height;
+
+ pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
+ if (canvas_coords)
+ {
+ text_width = item->details->text_width;
+ text_height = item->details->text_height;
+ text_height_for_layout = item->details->text_height_for_layout;
+ text_height_for_entire_text = item->details->text_height_for_entire_text;
+ }
+ else
+ {
+ text_width = item->details->text_width / pixels_per_unit;
+ text_height = item->details->text_height / pixels_per_unit;
+ text_height_for_layout = item->details->text_height_for_layout / pixels_per_unit;
+ text_height_for_entire_text = item->details->text_height_for_entire_text / pixels_per_unit;
+ }
+
+ text_rectangle.x0 = (icon_rectangle.x0 + icon_rectangle.x1) / 2 - (int) text_width / 2;
+ text_rectangle.y0 = icon_rectangle.y1;
+ text_rectangle.x1 = text_rectangle.x0 + text_width;
+
+ if (usage == BOUNDS_USAGE_FOR_LAYOUT)
+ {
+ real_text_height = text_height_for_layout;
+ }
+ else if (usage == BOUNDS_USAGE_FOR_ENTIRE_ITEM)
+ {
+ real_text_height = text_height_for_entire_text;
+ }
+ else if (usage == BOUNDS_USAGE_FOR_DISPLAY)
+ {
+ real_text_height = text_height;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ text_rectangle.y1 = text_rectangle.y0 + real_text_height + LABEL_OFFSET / pixels_per_unit;
+
+ return text_rectangle;
}
static EelIRect
get_current_canvas_bounds (EelCanvasItem *item)
{
- EelIRect bounds;
+ EelIRect bounds;
- g_assert (EEL_IS_CANVAS_ITEM (item));
+ g_assert (EEL_IS_CANVAS_ITEM (item));
- bounds.x0 = item->x1;
- bounds.y0 = item->y1;
- bounds.x1 = item->x2;
- bounds.y1 = item->y2;
+ bounds.x0 = item->x1;
+ bounds.y0 = item->y1;
+ bounds.x1 = item->x2;
+ bounds.y1 = item->y2;
- return bounds;
+ return bounds;
}
void
nautilus_canvas_item_update_bounds (NautilusCanvasItem *item,
- double i2w_dx, double i2w_dy)
-{
- EelIRect before, after;
- EelCanvasItem *canvas_item;
-
- canvas_item = EEL_CANVAS_ITEM (item);
-
- /* Compute new bounds. */
- before = get_current_canvas_bounds (canvas_item);
- recompute_bounding_box (item, i2w_dx, i2w_dy);
- after = get_current_canvas_bounds (canvas_item);
-
- /* If the bounds didn't change, we are done. */
- if (eel_irect_equal (before, after)) {
- return;
- }
-
- /* Update canvas and text rect cache */
- get_icon_rectangle (item, &item->details->icon_rect);
- item->details->text_rect = compute_text_rectangle (item, item->details->icon_rect,
- TRUE, BOUNDS_USAGE_FOR_DISPLAY);
-
- /* queue a redraw. */
- eel_canvas_request_redraw (canvas_item->canvas,
- before.x0, before.y0,
- before.x1 + 1, before.y1 + 1);
+ double i2w_dx,
+ double i2w_dy)
+{
+ EelIRect before, after;
+ EelCanvasItem *canvas_item;
+
+ canvas_item = EEL_CANVAS_ITEM (item);
+
+ /* Compute new bounds. */
+ before = get_current_canvas_bounds (canvas_item);
+ recompute_bounding_box (item, i2w_dx, i2w_dy);
+ after = get_current_canvas_bounds (canvas_item);
+
+ /* If the bounds didn't change, we are done. */
+ if (eel_irect_equal (before, after))
+ {
+ return;
+ }
+
+ /* Update canvas and text rect cache */
+ get_icon_rectangle (item, &item->details->icon_rect);
+ item->details->text_rect = compute_text_rectangle (item, item->details->icon_rect,
+ TRUE, BOUNDS_USAGE_FOR_DISPLAY);
+
+ /* queue a redraw. */
+ eel_canvas_request_redraw (canvas_item->canvas,
+ before.x0, before.y0,
+ before.x1 + 1, before.y1 + 1);
}
/* Update handler for the canvas canvas item. */
static void
nautilus_canvas_item_update (EelCanvasItem *item,
- double i2w_dx, double i2w_dy,
- gint flags)
+ double i2w_dx,
+ double i2w_dy,
+ gint flags)
{
- nautilus_canvas_item_update_bounds (NAUTILUS_CANVAS_ITEM (item), i2w_dx, i2w_dy);
+ nautilus_canvas_item_update_bounds (NAUTILUS_CANVAS_ITEM (item), i2w_dx, i2w_dy);
- eel_canvas_item_request_redraw (EEL_CANVAS_ITEM (item));
+ eel_canvas_item_request_redraw (EEL_CANVAS_ITEM (item));
- EEL_CANVAS_ITEM_CLASS (nautilus_canvas_item_parent_class)->update (item, i2w_dx, i2w_dy, flags);
+ EEL_CANVAS_ITEM_CLASS (nautilus_canvas_item_parent_class)->update (item, i2w_dx, i2w_dy, flags);
}
/* Rendering */
static gboolean
in_single_click_mode (void)
{
- int click_policy;
+ int click_policy;
- click_policy = g_settings_get_enum (nautilus_preferences,
- NAUTILUS_PREFERENCES_CLICK_POLICY);
+ click_policy = g_settings_get_enum (nautilus_preferences,
+ NAUTILUS_PREFERENCES_CLICK_POLICY);
- return click_policy == NAUTILUS_CLICK_POLICY_SINGLE;
+ return click_policy == NAUTILUS_CLICK_POLICY_SINGLE;
}
/* Keep these for a bit while we work on performance of draw_or_measure_label_text. */
/*
- #define PERFORMANCE_TEST_DRAW_DISABLE
- #define PERFORMANCE_TEST_MEASURE_DISABLE
-*/
+ #define PERFORMANCE_TEST_DRAW_DISABLE
+ #define PERFORMANCE_TEST_MEASURE_DISABLE
+ */
/* This gets the size of the layout from the position of the layout.
* This means that if the layout is right aligned we get the full width
@@ -618,1183 +685,1315 @@ in_single_click_mode (void)
*/
static void
layout_get_full_size (PangoLayout *layout,
- int *width,
- int *height,
- int *dx)
+ int *width,
+ int *height,
+ int *dx)
{
- PangoRectangle logical_rect;
- int the_width, total_width;
-
- pango_layout_get_extents (layout, NULL, &logical_rect);
- the_width = (logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE;
- total_width = (logical_rect.x + logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE;
+ PangoRectangle logical_rect;
+ int the_width, total_width;
+
+ pango_layout_get_extents (layout, NULL, &logical_rect);
+ the_width = (logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE;
+ total_width = (logical_rect.x + logical_rect.width + PANGO_SCALE / 2) / PANGO_SCALE;
- if (width != NULL) {
- *width = the_width;
- }
+ if (width != NULL)
+ {
+ *width = the_width;
+ }
- if (height != NULL) {
- *height = (logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE;
- }
+ if (height != NULL)
+ {
+ *height = (logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE;
+ }
- if (dx != NULL) {
- *dx = total_width - the_width;
- }
+ if (dx != NULL)
+ {
+ *dx = total_width - the_width;
+ }
}
static void
layout_get_size_for_layout (PangoLayout *layout,
- int max_layout_line_count,
- int height_for_entire_text,
- int *height_for_layout)
-{
- PangoLayoutIter *iter;
- PangoRectangle logical_rect;
- int i;
-
- /* only use the first max_layout_line_count lines for the gridded auto layout */
- if (pango_layout_get_line_count (layout) <= max_layout_line_count) {
- *height_for_layout = height_for_entire_text;
- } else {
- *height_for_layout = 0;
- iter = pango_layout_get_iter (layout);
- for (i = 0; i < max_layout_line_count; i++) {
- pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
- *height_for_layout += (logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE;
-
- if (!pango_layout_iter_next_line (iter)) {
- break;
- }
-
- *height_for_layout += pango_layout_get_spacing (layout);
- }
- pango_layout_iter_free (iter);
- }
+ int max_layout_line_count,
+ int height_for_entire_text,
+ int *height_for_layout)
+{
+ PangoLayoutIter *iter;
+ PangoRectangle logical_rect;
+ int i;
+
+ /* only use the first max_layout_line_count lines for the gridded auto layout */
+ if (pango_layout_get_line_count (layout) <= max_layout_line_count)
+ {
+ *height_for_layout = height_for_entire_text;
+ }
+ else
+ {
+ *height_for_layout = 0;
+ iter = pango_layout_get_iter (layout);
+ for (i = 0; i < max_layout_line_count; i++)
+ {
+ pango_layout_iter_get_line_extents (iter, NULL, &logical_rect);
+ *height_for_layout += (logical_rect.height + PANGO_SCALE / 2) / PANGO_SCALE;
+
+ if (!pango_layout_iter_next_line (iter))
+ {
+ break;
+ }
+
+ *height_for_layout += pango_layout_get_spacing (layout);
+ }
+ pango_layout_iter_free (iter);
+ }
}
static double
nautilus_canvas_item_get_max_text_width (NautilusCanvasItem *item)
{
- EelCanvasItem *canvas_item;
- NautilusCanvasContainer *container;
- guint max_text_width;
+ EelCanvasItem *canvas_item;
+ NautilusCanvasContainer *container;
+ guint max_text_width;
+
+
+ canvas_item = EEL_CANVAS_ITEM (item);
+ container = NAUTILUS_CANVAS_CONTAINER (canvas_item->canvas);
+
+ switch (nautilus_canvas_container_get_zoom_level (container))
+ {
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
+ {
+ max_text_width = MAX_TEXT_WIDTH_SMALL;
+ }
+ break;
+
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
+ {
+ max_text_width = MAX_TEXT_WIDTH_STANDARD;
+ }
+ break;
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
+ {
+ max_text_width = MAX_TEXT_WIDTH_LARGE;
+ }
+ break;
- canvas_item = EEL_CANVAS_ITEM (item);
- container = NAUTILUS_CANVAS_CONTAINER (canvas_item->canvas);
+ case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
+ {
+ max_text_width = MAX_TEXT_WIDTH_LARGER;
+ }
+ break;
- switch (nautilus_canvas_container_get_zoom_level (container)) {
- case NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL:
- max_text_width = MAX_TEXT_WIDTH_SMALL;
- break;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD:
- max_text_width = MAX_TEXT_WIDTH_STANDARD;
- break;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE:
- max_text_width = MAX_TEXT_WIDTH_LARGE;
- break;
- case NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER:
- max_text_width = MAX_TEXT_WIDTH_LARGER;
- break;
- default:
- g_warning ("Zoom level not valid. This may incur in missaligned grid");
- max_text_width = MAX_TEXT_WIDTH_STANDARD;
- }
+ default:
+ g_warning ("Zoom level not valid. This may incur in missaligned grid");
+ max_text_width = MAX_TEXT_WIDTH_STANDARD;
+ }
- return max_text_width * canvas_item->canvas->pixels_per_unit - 2 * TEXT_BACK_PADDING_X;
+ return max_text_width * canvas_item->canvas->pixels_per_unit - 2 * TEXT_BACK_PADDING_X;
}
static void
prepare_pango_layout_width (NautilusCanvasItem *item,
- PangoLayout *layout)
+ PangoLayout *layout)
{
- pango_layout_set_width (layout, floor (nautilus_canvas_item_get_max_text_width (item)) * PANGO_SCALE);
- pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
+ pango_layout_set_width (layout, floor (nautilus_canvas_item_get_max_text_width (item)) * PANGO_SCALE);
+ pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
}
static void
prepare_pango_layout_for_measure_entire_text (NautilusCanvasItem *item,
- PangoLayout *layout)
+ PangoLayout *layout)
{
- prepare_pango_layout_width (item, layout);
- pango_layout_set_height (layout, G_MININT);
+ prepare_pango_layout_width (item, layout);
+ pango_layout_set_height (layout, G_MININT);
}
static void
prepare_pango_layout_for_draw (NautilusCanvasItem *item,
- PangoLayout *layout)
+ PangoLayout *layout)
{
- NautilusCanvasItemDetails *details;
- NautilusCanvasContainer *container;
- gboolean needs_highlight;
+ NautilusCanvasItemDetails *details;
+ NautilusCanvasContainer *container;
+ gboolean needs_highlight;
- prepare_pango_layout_width (item, layout);
+ prepare_pango_layout_width (item, layout);
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
- details = item->details;
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+ details = item->details;
- needs_highlight = details->is_highlighted_for_selection || details->is_highlighted_for_drop;
+ needs_highlight = details->is_highlighted_for_selection || details->is_highlighted_for_drop;
- if (needs_highlight ||
- details->is_highlighted_as_keyboard_focus ||
- details->entire_text) {
- /* VOODOO-TODO, cf. compute_text_rectangle() */
- pango_layout_set_height (layout, G_MININT);
- } else {
- /* TODO? we might save some resources, when the re-layout is not neccessary in case
- * the layout height already fits into max. layout lines. But pango should figure this
- * out itself (which it doesn't ATM).
- */
- pango_layout_set_height (layout,
- nautilus_canvas_container_get_max_layout_lines_for_pango (container));
- }
+ if (needs_highlight ||
+ details->is_highlighted_as_keyboard_focus ||
+ details->entire_text)
+ {
+ /* VOODOO-TODO, cf. compute_text_rectangle() */
+ pango_layout_set_height (layout, G_MININT);
+ }
+ else
+ {
+ /* TODO? we might save some resources, when the re-layout is not neccessary in case
+ * the layout height already fits into max. layout lines. But pango should figure this
+ * out itself (which it doesn't ATM).
+ */
+ pango_layout_set_height (layout,
+ nautilus_canvas_container_get_max_layout_lines_for_pango (container));
+ }
}
static void
measure_label_text (NautilusCanvasItem *item)
{
- NautilusCanvasItemDetails *details;
- NautilusCanvasContainer *container;
- gint editable_height, editable_height_for_layout, editable_height_for_entire_text, editable_width, editable_dx;
- gint additional_height, additional_width, additional_dx;
- PangoLayout *editable_layout;
- PangoLayout *additional_layout;
- gboolean have_editable, have_additional;
-
- /* check to see if the cached values are still valid; if so, there's
- * no work necessary
- */
-
- if (item->details->text_width >= 0 && item->details->text_height >= 0) {
- return;
- }
-
- details = item->details;
-
- have_editable = details->editable_text != NULL && details->editable_text[0] != '\0';
- have_additional = details->additional_text != NULL && details->additional_text[0] != '\0';
-
- /* No font or no text, then do no work. */
- if (!have_editable && !have_additional) {
- details->text_height = 0;
- details->text_height_for_layout = 0;
- details->text_height_for_entire_text = 0;
- details->text_width = 0;
- return;
- }
+ NautilusCanvasItemDetails *details;
+ NautilusCanvasContainer *container;
+ gint editable_height, editable_height_for_layout, editable_height_for_entire_text, editable_width, editable_dx;
+ gint additional_height, additional_width, additional_dx;
+ PangoLayout *editable_layout;
+ PangoLayout *additional_layout;
+ gboolean have_editable, have_additional;
+
+ /* check to see if the cached values are still valid; if so, there's
+ * no work necessary
+ */
+
+ if (item->details->text_width >= 0 && item->details->text_height >= 0)
+ {
+ return;
+ }
+
+ details = item->details;
+
+ have_editable = details->editable_text != NULL && details->editable_text[0] != '\0';
+ have_additional = details->additional_text != NULL && details->additional_text[0] != '\0';
+
+ /* No font or no text, then do no work. */
+ if (!have_editable && !have_additional)
+ {
+ details->text_height = 0;
+ details->text_height_for_layout = 0;
+ details->text_height_for_entire_text = 0;
+ details->text_width = 0;
+ return;
+ }
#ifdef PERFORMANCE_TEST_MEASURE_DISABLE
- /* fake out the width */
- details->text_width = 80;
- details->text_height = 20;
- details->text_height_for_layout = 20;
- details->text_height_for_entire_text = 20;
- return;
+ /* fake out the width */
+ details->text_width = 80;
+ details->text_height = 20;
+ details->text_height_for_layout = 20;
+ details->text_height_for_entire_text = 20;
+ return;
#endif
- editable_width = 0;
- editable_height = 0;
- editable_height_for_layout = 0;
- editable_height_for_entire_text = 0;
- editable_dx = 0;
- additional_width = 0;
- additional_height = 0;
- additional_dx = 0;
-
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
- editable_layout = NULL;
- additional_layout = NULL;
-
- if (have_editable) {
- /* first, measure required text height: editable_height_for_entire_text
- * then, measure text height applicable for layout: editable_height_for_layout
- * next, measure actually displayed height: editable_height
- */
- editable_layout = get_label_layout (&details->editable_text_layout, item, details->editable_text);
-
- prepare_pango_layout_for_measure_entire_text (item, editable_layout);
- layout_get_full_size (editable_layout,
- NULL,
- &editable_height_for_entire_text,
- NULL);
- layout_get_size_for_layout (editable_layout,
- nautilus_canvas_container_get_max_layout_lines (container),
- editable_height_for_entire_text,
- &editable_height_for_layout);
-
- prepare_pango_layout_for_draw (item, editable_layout);
- layout_get_full_size (editable_layout,
- &editable_width,
- &editable_height,
- &editable_dx);
- }
-
- if (have_additional) {
- additional_layout = get_label_layout (&details->additional_text_layout, item, details->additional_text);
- prepare_pango_layout_for_draw (item, additional_layout);
- layout_get_full_size (additional_layout,
- &additional_width, &additional_height, &additional_dx);
- }
-
- details->editable_text_height = editable_height;
-
- if (editable_width > additional_width) {
- details->text_width = editable_width;
- details->text_dx = editable_dx;
- } else {
- details->text_width = additional_width;
- details->text_dx = additional_dx;
- }
-
- if (have_additional) {
- details->text_height = editable_height + LABEL_LINE_SPACING + additional_height;
- details->text_height_for_layout = editable_height_for_layout + LABEL_LINE_SPACING + additional_height;
- details->text_height_for_entire_text = editable_height_for_entire_text + LABEL_LINE_SPACING + additional_height;
- } else {
- details->text_height = editable_height;
- details->text_height_for_layout = editable_height_for_layout;
- details->text_height_for_entire_text = editable_height_for_entire_text;
- }
-
- /* add some extra space for highlighting even when we don't highlight so things won't move */
-
- /* extra slop for nicer highlighting */
- details->text_height += TEXT_BACK_PADDING_Y*2;
- details->text_height_for_layout += TEXT_BACK_PADDING_Y*2;
- details->text_height_for_entire_text += TEXT_BACK_PADDING_Y*2;
- details->editable_text_height += TEXT_BACK_PADDING_Y*2;
-
- /* extra to make it look nicer */
- details->text_width += TEXT_BACK_PADDING_X*2;
-
- if (editable_layout) {
- g_object_unref (editable_layout);
- }
-
- if (additional_layout) {
- g_object_unref (additional_layout);
- }
+ editable_width = 0;
+ editable_height = 0;
+ editable_height_for_layout = 0;
+ editable_height_for_entire_text = 0;
+ editable_dx = 0;
+ additional_width = 0;
+ additional_height = 0;
+ additional_dx = 0;
+
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+ editable_layout = NULL;
+ additional_layout = NULL;
+
+ if (have_editable)
+ {
+ /* first, measure required text height: editable_height_for_entire_text
+ * then, measure text height applicable for layout: editable_height_for_layout
+ * next, measure actually displayed height: editable_height
+ */
+ editable_layout = get_label_layout (&details->editable_text_layout, item, details->editable_text);
+
+ prepare_pango_layout_for_measure_entire_text (item, editable_layout);
+ layout_get_full_size (editable_layout,
+ NULL,
+ &editable_height_for_entire_text,
+ NULL);
+ layout_get_size_for_layout (editable_layout,
+ nautilus_canvas_container_get_max_layout_lines (container),
+ editable_height_for_entire_text,
+ &editable_height_for_layout);
+
+ prepare_pango_layout_for_draw (item, editable_layout);
+ layout_get_full_size (editable_layout,
+ &editable_width,
+ &editable_height,
+ &editable_dx);
+ }
+
+ if (have_additional)
+ {
+ additional_layout = get_label_layout (&details->additional_text_layout, item, details->additional_text);
+ prepare_pango_layout_for_draw (item, additional_layout);
+ layout_get_full_size (additional_layout,
+ &additional_width, &additional_height, &additional_dx);
+ }
+
+ details->editable_text_height = editable_height;
+
+ if (editable_width > additional_width)
+ {
+ details->text_width = editable_width;
+ details->text_dx = editable_dx;
+ }
+ else
+ {
+ details->text_width = additional_width;
+ details->text_dx = additional_dx;
+ }
+
+ if (have_additional)
+ {
+ details->text_height = editable_height + LABEL_LINE_SPACING + additional_height;
+ details->text_height_for_layout = editable_height_for_layout + LABEL_LINE_SPACING + additional_height;
+ details->text_height_for_entire_text = editable_height_for_entire_text + LABEL_LINE_SPACING + additional_height;
+ }
+ else
+ {
+ details->text_height = editable_height;
+ details->text_height_for_layout = editable_height_for_layout;
+ details->text_height_for_entire_text = editable_height_for_entire_text;
+ }
+
+ /* add some extra space for highlighting even when we don't highlight so things won't move */
+
+ /* extra slop for nicer highlighting */
+ details->text_height += TEXT_BACK_PADDING_Y * 2;
+ details->text_height_for_layout += TEXT_BACK_PADDING_Y * 2;
+ details->text_height_for_entire_text += TEXT_BACK_PADDING_Y * 2;
+ details->editable_text_height += TEXT_BACK_PADDING_Y * 2;
+
+ /* extra to make it look nicer */
+ details->text_width += TEXT_BACK_PADDING_X * 2;
+
+ if (editable_layout)
+ {
+ g_object_unref (editable_layout);
+ }
+
+ if (additional_layout)
+ {
+ g_object_unref (additional_layout);
+ }
}
static void
draw_label_text (NautilusCanvasItem *item,
- cairo_t *cr,
- EelIRect icon_rect)
-{
- NautilusCanvasItemDetails *details;
- NautilusCanvasContainer *container;
- PangoLayout *editable_layout;
- PangoLayout *additional_layout;
- GtkStyleContext *context;
- GtkStateFlags state, base_state;
- gboolean have_editable, have_additional;
- gboolean needs_highlight, prelight_label;
- EelIRect text_rect;
- int x;
- int max_text_width;
- gdouble frame_w, frame_h, frame_x, frame_y;
- gboolean draw_frame = TRUE;
+ cairo_t *cr,
+ EelIRect icon_rect)
+{
+ NautilusCanvasItemDetails *details;
+ NautilusCanvasContainer *container;
+ PangoLayout *editable_layout;
+ PangoLayout *additional_layout;
+ GtkStyleContext *context;
+ GtkStateFlags state, base_state;
+ gboolean have_editable, have_additional;
+ gboolean needs_highlight, prelight_label;
+ EelIRect text_rect;
+ int x;
+ int max_text_width;
+ gdouble frame_w, frame_h, frame_x, frame_y;
+ gboolean draw_frame = TRUE;
#ifdef PERFORMANCE_TEST_DRAW_DISABLE
- return;
+ return;
#endif
- details = item->details;
-
- measure_label_text (item);
- if (details->text_height == 0 ||
- details->text_width == 0) {
- return;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
- context = gtk_widget_get_style_context (GTK_WIDGET (container));
-
- text_rect = compute_text_rectangle (item, icon_rect, TRUE, BOUNDS_USAGE_FOR_DISPLAY);
-
- needs_highlight = details->is_highlighted_for_selection || details->is_highlighted_for_drop;
-
- editable_layout = NULL;
- additional_layout = NULL;
-
- have_editable = details->editable_text != NULL && details->editable_text[0] != '\0';
- have_additional = details->additional_text != NULL && details->additional_text[0] != '\0';
- g_assert (have_editable || have_additional);
-
- max_text_width = floor (nautilus_canvas_item_get_max_text_width (item));
-
- base_state = gtk_widget_get_state_flags (GTK_WIDGET (container));
- base_state &= ~(GTK_STATE_FLAG_SELECTED |
- GTK_STATE_FLAG_PRELIGHT);
- state = base_state;
-
- gtk_widget_style_get (GTK_WIDGET (container),
- "activate_prelight_icon_label", &prelight_label,
- NULL);
-
- /* if the canvas is highlighted, do some set-up */
- if (needs_highlight) {
- state |= GTK_STATE_FLAG_SELECTED;
-
- frame_x = text_rect.x0;
- frame_y = text_rect.y0;
- frame_w = text_rect.x1 - text_rect.x0;
- frame_h = text_rect.y1 - text_rect.y0;
- } else if (!needs_highlight && have_editable &&
- details->text_width > 0 && details->text_height > 0 &&
- prelight_label && item->details->is_prelit) {
- state |= GTK_STATE_FLAG_PRELIGHT;
-
- frame_x = text_rect.x0;
- frame_y = text_rect.y0;
- frame_w = text_rect.x1 - text_rect.x0;
- frame_h = text_rect.y1 - text_rect.y0;
- } else {
- draw_frame = FALSE;
- }
+ details = item->details;
+
+ measure_label_text (item);
+ if (details->text_height == 0 ||
+ details->text_width == 0)
+ {
+ return;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+ context = gtk_widget_get_style_context (GTK_WIDGET (container));
+
+ text_rect = compute_text_rectangle (item, icon_rect, TRUE, BOUNDS_USAGE_FOR_DISPLAY);
+
+ needs_highlight = details->is_highlighted_for_selection || details->is_highlighted_for_drop;
+
+ editable_layout = NULL;
+ additional_layout = NULL;
+
+ have_editable = details->editable_text != NULL && details->editable_text[0] != '\0';
+ have_additional = details->additional_text != NULL && details->additional_text[0] != '\0';
+ g_assert (have_editable || have_additional);
+
+ max_text_width = floor (nautilus_canvas_item_get_max_text_width (item));
+
+ base_state = gtk_widget_get_state_flags (GTK_WIDGET (container));
+ base_state &= ~(GTK_STATE_FLAG_SELECTED |
+ GTK_STATE_FLAG_PRELIGHT);
+ state = base_state;
+
+ gtk_widget_style_get (GTK_WIDGET (container),
+ "activate_prelight_icon_label", &prelight_label,
+ NULL);
+
+ /* if the canvas is highlighted, do some set-up */
+ if (needs_highlight)
+ {
+ state |= GTK_STATE_FLAG_SELECTED;
+
+ frame_x = text_rect.x0;
+ frame_y = text_rect.y0;
+ frame_w = text_rect.x1 - text_rect.x0;
+ frame_h = text_rect.y1 - text_rect.y0;
+ }
+ else if (!needs_highlight && have_editable &&
+ details->text_width > 0 && details->text_height > 0 &&
+ prelight_label && item->details->is_prelit)
+ {
+ state |= GTK_STATE_FLAG_PRELIGHT;
+
+ frame_x = text_rect.x0;
+ frame_y = text_rect.y0;
+ frame_w = text_rect.x1 - text_rect.x0;
+ frame_h = text_rect.y1 - text_rect.y0;
+ }
+ else
+ {
+ draw_frame = FALSE;
+ }
+
+ if (draw_frame)
+ {
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
+
+ gtk_render_frame (context, cr,
+ frame_x, frame_y,
+ frame_w, frame_h);
+ gtk_render_background (context, cr,
+ frame_x, frame_y,
+ frame_w, frame_h);
+
+ gtk_style_context_restore (context);
+ }
+
+ x = text_rect.x0 + ((text_rect.x1 - text_rect.x0) - max_text_width) / 2;
+
+ if (have_editable)
+ {
+ state = base_state;
+
+ if (prelight_label && item->details->is_prelit)
+ {
+ state |= GTK_STATE_FLAG_PRELIGHT;
+ }
- if (draw_frame) {
- gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
+ if (needs_highlight)
+ {
+ state |= GTK_STATE_FLAG_SELECTED;
+ }
- gtk_render_frame (context, cr,
- frame_x, frame_y,
- frame_w, frame_h);
- gtk_render_background (context, cr,
- frame_x, frame_y,
- frame_w, frame_h);
+ editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text);
+ prepare_pango_layout_for_draw (item, editable_layout);
- gtk_style_context_restore (context);
- }
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
- x = text_rect.x0 + ((text_rect.x1 - text_rect.x0) - max_text_width) / 2;
+ gtk_render_layout (context, cr,
+ x, text_rect.y0 + TEXT_BACK_PADDING_Y,
+ editable_layout);
- if (have_editable) {
- state = base_state;
+ gtk_style_context_restore (context);
+ }
- if (prelight_label && item->details->is_prelit) {
- state |= GTK_STATE_FLAG_PRELIGHT;
- }
+ if (have_additional)
+ {
+ state = base_state;
- if (needs_highlight) {
- state |= GTK_STATE_FLAG_SELECTED;
- }
+ if (needs_highlight)
+ {
+ state |= GTK_STATE_FLAG_SELECTED;
+ }
- editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text);
- prepare_pango_layout_for_draw (item, editable_layout);
+ additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
+ prepare_pango_layout_for_draw (item, additional_layout);
- gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
+ gtk_style_context_add_class (context, "dim-label");
- gtk_render_layout (context, cr,
- x, text_rect.y0 + TEXT_BACK_PADDING_Y,
- editable_layout);
+ gtk_render_layout (context, cr,
+ x, text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y,
+ additional_layout);
- gtk_style_context_restore (context);
- }
+ gtk_style_context_restore (context);
+ }
- if (have_additional) {
- state = base_state;
+ if (item->details->is_highlighted_as_keyboard_focus)
+ {
+ if (needs_highlight)
+ {
+ state = GTK_STATE_FLAG_SELECTED;
+ }
- if (needs_highlight) {
- state |= GTK_STATE_FLAG_SELECTED;
- }
+ gtk_style_context_save (context);
+ gtk_style_context_set_state (context, state);
- additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
- prepare_pango_layout_for_draw (item, additional_layout);
+ gtk_render_focus (context,
+ cr,
+ text_rect.x0,
+ text_rect.y0,
+ text_rect.x1 - text_rect.x0,
+ text_rect.y1 - text_rect.y0);
- gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
- gtk_style_context_add_class (context, "dim-label");
+ gtk_style_context_restore (context);
+ }
- gtk_render_layout (context, cr,
- x, text_rect.y0 + details->editable_text_height + LABEL_LINE_SPACING + TEXT_BACK_PADDING_Y,
- additional_layout);
+ if (editable_layout != NULL)
+ {
+ g_object_unref (editable_layout);
+ }
- gtk_style_context_restore (context);
- }
-
- if (item->details->is_highlighted_as_keyboard_focus) {
- if (needs_highlight) {
- state = GTK_STATE_FLAG_SELECTED;
- }
-
- gtk_style_context_save (context);
- gtk_style_context_set_state (context, state);
-
- gtk_render_focus (context,
- cr,
- text_rect.x0,
- text_rect.y0,
- text_rect.x1 - text_rect.x0,
- text_rect.y1 - text_rect.y0);
-
- gtk_style_context_restore (context);
- }
-
- if (editable_layout != NULL) {
- g_object_unref (editable_layout);
- }
-
- if (additional_layout != NULL) {
- g_object_unref (additional_layout);
- }
+ if (additional_layout != NULL)
+ {
+ g_object_unref (additional_layout);
+ }
}
void
-nautilus_canvas_item_set_is_visible (NautilusCanvasItem *item,
- gboolean visible)
+nautilus_canvas_item_set_is_visible (NautilusCanvasItem *item,
+ gboolean visible)
{
- if (item->details->is_visible == visible)
- return;
-
- item->details->is_visible = visible;
+ if (item->details->is_visible == visible)
+ {
+ return;
+ }
- if (!visible) {
- nautilus_canvas_item_invalidate_label (item);
- }
+ item->details->is_visible = visible;
+
+ if (!visible)
+ {
+ nautilus_canvas_item_invalidate_label (item);
+ }
}
void
-nautilus_canvas_item_invalidate_label (NautilusCanvasItem *item)
+nautilus_canvas_item_invalidate_label (NautilusCanvasItem *item)
{
- nautilus_canvas_item_invalidate_label_size (item);
+ nautilus_canvas_item_invalidate_label_size (item);
- if (item->details->editable_text_layout) {
- g_object_unref (item->details->editable_text_layout);
- item->details->editable_text_layout = NULL;
- }
+ if (item->details->editable_text_layout)
+ {
+ g_object_unref (item->details->editable_text_layout);
+ item->details->editable_text_layout = NULL;
+ }
- if (item->details->additional_text_layout) {
- g_object_unref (item->details->additional_text_layout);
- item->details->additional_text_layout = NULL;
- }
+ if (item->details->additional_text_layout)
+ {
+ g_object_unref (item->details->additional_text_layout);
+ item->details->additional_text_layout = NULL;
+ }
}
static GdkPixbuf *
get_knob_pixbuf (void)
{
- GdkPixbuf *knob_pixbuf = NULL;
- GInputStream *stream = g_resources_open_stream ("/org/gnome/nautilus/icons/knob.png", 0, NULL);
+ GdkPixbuf *knob_pixbuf = NULL;
+ GInputStream *stream = g_resources_open_stream ("/org/gnome/nautilus/icons/knob.png", 0, NULL);
- if (stream != NULL) {
- knob_pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
- g_object_unref (stream);
- }
+ if (stream != NULL)
+ {
+ knob_pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+ g_object_unref (stream);
+ }
- return knob_pixbuf;
+ return knob_pixbuf;
}
static void
draw_stretch_handles (NautilusCanvasItem *item,
- cairo_t *cr,
- const EelIRect *rect)
-{
- GtkWidget *widget;
- GdkPixbuf *knob_pixbuf;
- int knob_width, knob_height;
- double dash = { 2.0 };
- GtkStyleContext *style;
- GdkRGBA color;
-
- if (!item->details->show_stretch_handles) {
- return;
- }
-
- widget = GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas);
- style = gtk_widget_get_style_context (widget);
-
- cairo_save (cr);
- knob_pixbuf = get_knob_pixbuf ();
- knob_width = gdk_pixbuf_get_width (knob_pixbuf);
- knob_height = gdk_pixbuf_get_height (knob_pixbuf);
-
- /* first draw the box */
- gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color);
- gdk_cairo_set_source_rgba (cr, &color);
- cairo_set_dash (cr, &dash, 1, 0);
- cairo_set_line_width (cr, 1.0);
- cairo_rectangle (cr,
- rect->x0 + 0.5,
- rect->y0 + 0.5,
- rect->x1 - rect->x0 - 1,
- rect->y1 - rect->y0 - 1);
- cairo_stroke (cr);
-
- cairo_restore (cr);
-
- /* draw the stretch handles themselves */
- draw_pixbuf (knob_pixbuf, cr, rect->x0, rect->y0);
- draw_pixbuf (knob_pixbuf, cr, rect->x0, rect->y1 - knob_height);
- draw_pixbuf (knob_pixbuf, cr, rect->x1 - knob_width, rect->y0);
- draw_pixbuf (knob_pixbuf, cr, rect->x1 - knob_width, rect->y1 - knob_height);
-
- g_object_unref (knob_pixbuf);
+ cairo_t *cr,
+ const EelIRect *rect)
+{
+ GtkWidget *widget;
+ GdkPixbuf *knob_pixbuf;
+ int knob_width, knob_height;
+ double dash = { 2.0 };
+ GtkStyleContext *style;
+ GdkRGBA color;
+
+ if (!item->details->show_stretch_handles)
+ {
+ return;
+ }
+
+ widget = GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas);
+ style = gtk_widget_get_style_context (widget);
+
+ cairo_save (cr);
+ knob_pixbuf = get_knob_pixbuf ();
+ knob_width = gdk_pixbuf_get_width (knob_pixbuf);
+ knob_height = gdk_pixbuf_get_height (knob_pixbuf);
+
+ /* first draw the box */
+ gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color);
+ gdk_cairo_set_source_rgba (cr, &color);
+ cairo_set_dash (cr, &dash, 1, 0);
+ cairo_set_line_width (cr, 1.0);
+ cairo_rectangle (cr,
+ rect->x0 + 0.5,
+ rect->y0 + 0.5,
+ rect->x1 - rect->x0 - 1,
+ rect->y1 - rect->y0 - 1);
+ cairo_stroke (cr);
+
+ cairo_restore (cr);
+
+ /* draw the stretch handles themselves */
+ draw_pixbuf (knob_pixbuf, cr, rect->x0, rect->y0);
+ draw_pixbuf (knob_pixbuf, cr, rect->x0, rect->y1 - knob_height);
+ draw_pixbuf (knob_pixbuf, cr, rect->x1 - knob_width, rect->y0);
+ draw_pixbuf (knob_pixbuf, cr, rect->x1 - knob_width, rect->y1 - knob_height);
+
+ g_object_unref (knob_pixbuf);
}
static void
draw_pixbuf (GdkPixbuf *pixbuf,
- cairo_t *cr,
- int x, int y)
+ cairo_t *cr,
+ int x,
+ int y)
{
- cairo_save (cr);
- gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
- cairo_paint (cr);
- cairo_restore (cr);
+ cairo_save (cr);
+ gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y);
+ cairo_paint (cr);
+ cairo_restore (cr);
}
/* shared code to highlight or dim the passed-in pixbuf */
static cairo_surface_t *
real_map_surface (NautilusCanvasItem *canvas_item)
{
- EelCanvas *canvas;
- GdkPixbuf *temp_pixbuf, *old_pixbuf;
- GtkStyleContext *style;
- GdkRGBA color;
- cairo_surface_t *surface;
-
- temp_pixbuf = canvas_item->details->pixbuf;
- canvas = EEL_CANVAS_ITEM(canvas_item)->canvas;
+ EelCanvas *canvas;
+ GdkPixbuf *temp_pixbuf, *old_pixbuf;
+ GtkStyleContext *style;
+ GdkRGBA color;
+ cairo_surface_t *surface;
- g_object_ref (temp_pixbuf);
+ temp_pixbuf = canvas_item->details->pixbuf;
+ canvas = EEL_CANVAS_ITEM (canvas_item)->canvas;
- if (canvas_item->details->is_prelit ||
- canvas_item->details->is_highlighted_for_clipboard) {
- old_pixbuf = temp_pixbuf;
+ g_object_ref (temp_pixbuf);
- temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
- g_object_unref (old_pixbuf);
- }
+ if (canvas_item->details->is_prelit ||
+ canvas_item->details->is_highlighted_for_clipboard)
+ {
+ old_pixbuf = temp_pixbuf;
- if (canvas_item->details->is_highlighted_for_selection
- || canvas_item->details->is_highlighted_for_drop) {
- style = gtk_widget_get_style_context (GTK_WIDGET (canvas));
+ temp_pixbuf = eel_create_spotlight_pixbuf (temp_pixbuf);
+ g_object_unref (old_pixbuf);
+ }
- if (gtk_widget_has_focus (GTK_WIDGET (canvas))) {
- gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color);
- } else {
- gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color);
- }
+ if (canvas_item->details->is_highlighted_for_selection
+ || canvas_item->details->is_highlighted_for_drop)
+ {
+ style = gtk_widget_get_style_context (GTK_WIDGET (canvas));
- old_pixbuf = temp_pixbuf;
- temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, &color);
+ if (gtk_widget_has_focus (GTK_WIDGET (canvas)))
+ {
+ gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color);
+ }
+ else
+ {
+ gtk_style_context_get_background_color (style, GTK_STATE_FLAG_ACTIVE, &color);
+ }
- g_object_unref (old_pixbuf);
- }
+ old_pixbuf = temp_pixbuf;
+ temp_pixbuf = eel_create_colorized_pixbuf (temp_pixbuf, &color);
- surface = gdk_cairo_surface_create_from_pixbuf (temp_pixbuf,
- gtk_widget_get_scale_factor (GTK_WIDGET (canvas)),
- gtk_widget_get_window (GTK_WIDGET (canvas)));
- g_object_unref (temp_pixbuf);
+ g_object_unref (old_pixbuf);
+ }
- return surface;
+ surface = gdk_cairo_surface_create_from_pixbuf (temp_pixbuf,
+ gtk_widget_get_scale_factor (GTK_WIDGET (canvas)),
+ gtk_widget_get_window (GTK_WIDGET (canvas)));
+ g_object_unref (temp_pixbuf);
+
+ return surface;
}
static cairo_surface_t *
map_surface (NautilusCanvasItem *canvas_item)
{
- if (!(canvas_item->details->rendered_surface != NULL
- && canvas_item->details->rendered_is_prelit == canvas_item->details->is_prelit
- && canvas_item->details->rendered_is_highlighted_for_selection == canvas_item->details->is_highlighted_for_selection
- && canvas_item->details->rendered_is_highlighted_for_drop == canvas_item->details->is_highlighted_for_drop
- && canvas_item->details->rendered_is_highlighted_for_clipboard == canvas_item->details->is_highlighted_for_clipboard
- && (canvas_item->details->is_highlighted_for_selection && canvas_item->details->rendered_is_focused == gtk_widget_has_focus (GTK_WIDGET (EEL_CANVAS_ITEM (canvas_item)->canvas))))) {
- if (canvas_item->details->rendered_surface != NULL) {
- cairo_surface_destroy (canvas_item->details->rendered_surface);
- }
- canvas_item->details->rendered_surface = real_map_surface (canvas_item);
- canvas_item->details->rendered_is_prelit = canvas_item->details->is_prelit;
- canvas_item->details->rendered_is_highlighted_for_selection = canvas_item->details->is_highlighted_for_selection;
- canvas_item->details->rendered_is_highlighted_for_drop = canvas_item->details->is_highlighted_for_drop;
- canvas_item->details->rendered_is_highlighted_for_clipboard = canvas_item->details->is_highlighted_for_clipboard;
- canvas_item->details->rendered_is_focused = gtk_widget_has_focus (GTK_WIDGET (EEL_CANVAS_ITEM (canvas_item)->canvas));
- }
+ if (!(canvas_item->details->rendered_surface != NULL
+ && canvas_item->details->rendered_is_prelit == canvas_item->details->is_prelit
+ && canvas_item->details->rendered_is_highlighted_for_selection == canvas_item->details->is_highlighted_for_selection
+ && canvas_item->details->rendered_is_highlighted_for_drop == canvas_item->details->is_highlighted_for_drop
+ && canvas_item->details->rendered_is_highlighted_for_clipboard == canvas_item->details->is_highlighted_for_clipboard
+ && (canvas_item->details->is_highlighted_for_selection && canvas_item->details->rendered_is_focused == gtk_widget_has_focus (GTK_WIDGET (EEL_CANVAS_ITEM (canvas_item)->canvas)))))
+ {
+ if (canvas_item->details->rendered_surface != NULL)
+ {
+ cairo_surface_destroy (canvas_item->details->rendered_surface);
+ }
+ canvas_item->details->rendered_surface = real_map_surface (canvas_item);
+ canvas_item->details->rendered_is_prelit = canvas_item->details->is_prelit;
+ canvas_item->details->rendered_is_highlighted_for_selection = canvas_item->details->is_highlighted_for_selection;
+ canvas_item->details->rendered_is_highlighted_for_drop = canvas_item->details->is_highlighted_for_drop;
+ canvas_item->details->rendered_is_highlighted_for_clipboard = canvas_item->details->is_highlighted_for_clipboard;
+ canvas_item->details->rendered_is_focused = gtk_widget_has_focus (GTK_WIDGET (EEL_CANVAS_ITEM (canvas_item)->canvas));
+ }
- cairo_surface_reference (canvas_item->details->rendered_surface);
+ cairo_surface_reference (canvas_item->details->rendered_surface);
- return canvas_item->details->rendered_surface;
+ return canvas_item->details->rendered_surface;
}
cairo_surface_t *
nautilus_canvas_item_get_drag_surface (NautilusCanvasItem *item)
{
- cairo_surface_t *surface;
- EelCanvas *canvas;
- int width, height;
- int pix_width, pix_height;
- int item_offset_x, item_offset_y;
- EelIRect icon_rect;
- double item_x, item_y;
- cairo_t *cr;
- GtkStyleContext *context;
- cairo_surface_t *drag_surface;
+ cairo_surface_t *surface;
+ EelCanvas *canvas;
+ int width, height;
+ int pix_width, pix_height;
+ int item_offset_x, item_offset_y;
+ EelIRect icon_rect;
+ double item_x, item_y;
+ cairo_t *cr;
+ GtkStyleContext *context;
+ cairo_surface_t *drag_surface;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), NULL);
- canvas = EEL_CANVAS_ITEM (item)->canvas;
- context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
+ canvas = EEL_CANVAS_ITEM (item)->canvas;
+ context = gtk_widget_get_style_context (GTK_WIDGET (canvas));
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, "nautilus-canvas-item");
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "nautilus-canvas-item");
- /* Assume we're updated so canvas item data is right */
+ /* Assume we're updated so canvas item data is right */
- /* Calculate the offset from the top-left corner of the
- new image to the item position (where the pixmap is placed) */
- eel_canvas_world_to_window (canvas,
- item->details->x, item->details->y,
- &item_x, &item_y);
+ /* Calculate the offset from the top-left corner of the
+ * new image to the item position (where the pixmap is placed) */
+ eel_canvas_world_to_window (canvas,
+ item->details->x, item->details->y,
+ &item_x, &item_y);
- item_offset_x = item_x - EEL_CANVAS_ITEM (item)->x1;
- item_offset_y = item_y - EEL_CANVAS_ITEM (item)->y1;
+ item_offset_x = item_x - EEL_CANVAS_ITEM (item)->x1;
+ item_offset_y = item_y - EEL_CANVAS_ITEM (item)->y1;
- /* Calculate the width of the item */
- width = EEL_CANVAS_ITEM (item)->x2 - EEL_CANVAS_ITEM (item)->x1;
- height = EEL_CANVAS_ITEM (item)->y2 - EEL_CANVAS_ITEM (item)->y1;
+ /* Calculate the width of the item */
+ width = EEL_CANVAS_ITEM (item)->x2 - EEL_CANVAS_ITEM (item)->x1;
+ height = EEL_CANVAS_ITEM (item)->y2 - EEL_CANVAS_ITEM (item)->y1;
- surface = gdk_window_create_similar_surface (gtk_widget_get_window (GTK_WIDGET (canvas)),
- CAIRO_CONTENT_COLOR_ALPHA,
- width, height);
- cr = cairo_create (surface);
+ surface = gdk_window_create_similar_surface (gtk_widget_get_window (GTK_WIDGET (canvas)),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ width, height);
+ cr = cairo_create (surface);
- drag_surface = map_surface (item);
- gtk_render_icon_surface (context, cr, drag_surface,
- item_offset_x, item_offset_y);
- cairo_surface_destroy (drag_surface);
+ drag_surface = map_surface (item);
+ gtk_render_icon_surface (context, cr, drag_surface,
+ item_offset_x, item_offset_y);
+ cairo_surface_destroy (drag_surface);
- get_scaled_icon_size (item, &pix_width, &pix_height);
+ get_scaled_icon_size (item, &pix_width, &pix_height);
- icon_rect.x0 = item_offset_x;
- icon_rect.y0 = item_offset_y;
- icon_rect.x1 = item_offset_x + pix_width;
- icon_rect.y1 = item_offset_y + pix_height;
+ icon_rect.x0 = item_offset_x;
+ icon_rect.y0 = item_offset_y;
+ icon_rect.x1 = item_offset_x + pix_width;
+ icon_rect.y1 = item_offset_y + pix_height;
- draw_label_text (item, cr, icon_rect);
- cairo_destroy (cr);
+ draw_label_text (item, cr, icon_rect);
+ cairo_destroy (cr);
- gtk_style_context_restore (context);
+ gtk_style_context_restore (context);
- return surface;
+ return surface;
}
/* Draw the canvas item for non-anti-aliased mode. */
static void
-nautilus_canvas_item_draw (EelCanvasItem *item,
- cairo_t *cr,
- cairo_region_t *region)
+nautilus_canvas_item_draw (EelCanvasItem *item,
+ cairo_t *cr,
+ cairo_region_t *region)
{
- NautilusCanvasContainer *container;
- NautilusCanvasItem *canvas_item;
- NautilusCanvasItemDetails *details;
- EelIRect icon_rect;
- cairo_surface_t *temp_surface;
- GtkStyleContext *context;
+ NautilusCanvasContainer *container;
+ NautilusCanvasItem *canvas_item;
+ NautilusCanvasItemDetails *details;
+ EelIRect icon_rect;
+ cairo_surface_t *temp_surface;
+ GtkStyleContext *context;
- container = NAUTILUS_CANVAS_CONTAINER (item->canvas);
- canvas_item = NAUTILUS_CANVAS_ITEM (item);
- details = canvas_item->details;
+ container = NAUTILUS_CANVAS_CONTAINER (item->canvas);
+ canvas_item = NAUTILUS_CANVAS_ITEM (item);
+ details = canvas_item->details;
- /* Draw the pixbuf. */
- if (details->pixbuf == NULL) {
- return;
- }
+ /* Draw the pixbuf. */
+ if (details->pixbuf == NULL)
+ {
+ return;
+ }
- context = gtk_widget_get_style_context (GTK_WIDGET (container));
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, "nautilus-canvas-item");
+ context = gtk_widget_get_style_context (GTK_WIDGET (container));
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "nautilus-canvas-item");
- icon_rect = canvas_item->details->icon_rect;
- temp_surface = map_surface (canvas_item);
+ icon_rect = canvas_item->details->icon_rect;
+ temp_surface = map_surface (canvas_item);
- gtk_render_icon_surface (context, cr,
- temp_surface,
- icon_rect.x0, icon_rect.y0);
- cairo_surface_destroy (temp_surface);
+ gtk_render_icon_surface (context, cr,
+ temp_surface,
+ icon_rect.x0, icon_rect.y0);
+ cairo_surface_destroy (temp_surface);
- /* Draw stretching handles (if necessary). */
- draw_stretch_handles (canvas_item, cr, &icon_rect);
-
- /* Draw the label text. */
- draw_label_text (canvas_item, cr, icon_rect);
+ /* Draw stretching handles (if necessary). */
+ draw_stretch_handles (canvas_item, cr, &icon_rect);
- gtk_style_context_restore (context);
+ /* Draw the label text. */
+ draw_label_text (canvas_item, cr, icon_rect);
+
+ gtk_style_context_restore (context);
}
#define ZERO_WIDTH_SPACE "\xE2\x80\x8B"
-#define ZERO_OR_THREE_DIGITS(p) \
- (!g_ascii_isdigit (*(p)) || \
- (g_ascii_isdigit (*(p+1)) && \
- g_ascii_isdigit (*(p+2))))
+#define ZERO_OR_THREE_DIGITS(p) \
+ (!g_ascii_isdigit (*(p)) || \
+ (g_ascii_isdigit (*(p + 1)) && \
+ g_ascii_isdigit (*(p + 2))))
static PangoLayout *
create_label_layout (NautilusCanvasItem *item,
- const char *text)
-{
- PangoLayout *layout;
- PangoContext *context;
- PangoFontDescription *desc;
- NautilusCanvasContainer *container;
- EelCanvasItem *canvas_item;
- GString *str;
- char *zeroified_text;
- const char *p;
-
- canvas_item = EEL_CANVAS_ITEM (item);
-
- container = NAUTILUS_CANVAS_CONTAINER (canvas_item->canvas);
- context = gtk_widget_get_pango_context (GTK_WIDGET (canvas_item->canvas));
- layout = pango_layout_new (context);
-
- zeroified_text = NULL;
-
- if (text != NULL) {
- str = g_string_new (NULL);
-
- for (p = text; *p != '\0'; p++) {
- str = g_string_append_c (str, *p);
-
- if (*p == '_' || *p == '-' || (*p == '.' && ZERO_OR_THREE_DIGITS (p+1))) {
- /* Ensure that we allow to break after '_' or '.' characters,
- * if they are not likely to be part of a version information, to
- * not break wrapping of foobar-0.0.1.
- * Wrap before IPs and long numbers, though. */
- str = g_string_append (str, ZERO_WIDTH_SPACE);
- }
- }
-
- zeroified_text = g_string_free (str, FALSE);
- }
-
- pango_layout_set_text (layout, zeroified_text, -1);
- pango_layout_set_auto_dir (layout, FALSE);
- pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
-
- pango_layout_set_spacing (layout, LABEL_LINE_SPACING);
- pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
-
- /* Create a font description */
- if (container->details->font) {
- desc = pango_font_description_from_string (container->details->font);
- } else {
- desc = pango_font_description_copy (pango_context_get_font_description (context));
- }
- pango_layout_set_font_description (layout, desc);
- pango_font_description_free (desc);
- g_free (zeroified_text);
-
- return layout;
+ const char *text)
+{
+ PangoLayout *layout;
+ PangoContext *context;
+ PangoFontDescription *desc;
+ NautilusCanvasContainer *container;
+ EelCanvasItem *canvas_item;
+ GString *str;
+ char *zeroified_text;
+ const char *p;
+
+ canvas_item = EEL_CANVAS_ITEM (item);
+
+ container = NAUTILUS_CANVAS_CONTAINER (canvas_item->canvas);
+ context = gtk_widget_get_pango_context (GTK_WIDGET (canvas_item->canvas));
+ layout = pango_layout_new (context);
+
+ zeroified_text = NULL;
+
+ if (text != NULL)
+ {
+ str = g_string_new (NULL);
+
+ for (p = text; *p != '\0'; p++)
+ {
+ str = g_string_append_c (str, *p);
+
+ if (*p == '_' || *p == '-' || (*p == '.' && ZERO_OR_THREE_DIGITS (p + 1)))
+ {
+ /* Ensure that we allow to break after '_' or '.' characters,
+ * if they are not likely to be part of a version information, to
+ * not break wrapping of foobar-0.0.1.
+ * Wrap before IPs and long numbers, though. */
+ str = g_string_append (str, ZERO_WIDTH_SPACE);
+ }
+ }
+
+ zeroified_text = g_string_free (str, FALSE);
+ }
+
+ pango_layout_set_text (layout, zeroified_text, -1);
+ pango_layout_set_auto_dir (layout, FALSE);
+ pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+
+ pango_layout_set_spacing (layout, LABEL_LINE_SPACING);
+ pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
+
+ /* Create a font description */
+ if (container->details->font)
+ {
+ desc = pango_font_description_from_string (container->details->font);
+ }
+ else
+ {
+ desc = pango_font_description_copy (pango_context_get_font_description (context));
+ }
+ pango_layout_set_font_description (layout, desc);
+ pango_font_description_free (desc);
+ g_free (zeroified_text);
+
+ return layout;
}
static PangoLayout *
-get_label_layout (PangoLayout **layout_cache,
- NautilusCanvasItem *item,
- const char *text)
+get_label_layout (PangoLayout **layout_cache,
+ NautilusCanvasItem *item,
+ const char *text)
{
- PangoLayout *layout;
+ PangoLayout *layout;
+
+ if (*layout_cache != NULL)
+ {
+ return g_object_ref (*layout_cache);
+ }
- if (*layout_cache != NULL) {
- return g_object_ref (*layout_cache);
- }
+ layout = create_label_layout (item, text);
- layout = create_label_layout (item, text);
+ if (item->details->is_visible)
+ {
+ *layout_cache = g_object_ref (layout);
+ }
- if (item->details->is_visible) {
- *layout_cache = g_object_ref (layout);
- }
-
- return layout;
+ return layout;
}
/* handle events */
static int
-nautilus_canvas_item_event (EelCanvasItem *item, GdkEvent *event)
-{
- NautilusCanvasItem *canvas_item;
- GdkCursor *cursor;
- GdkWindow *cursor_window;
-
- canvas_item = NAUTILUS_CANVAS_ITEM (item);
- cursor_window = ((GdkEventAny *)event)->window;
-
- switch (event->type) {
- case GDK_ENTER_NOTIFY:
- if (!canvas_item->details->is_prelit) {
- canvas_item->details->is_prelit = TRUE;
- nautilus_canvas_item_invalidate_label_size (canvas_item);
- eel_canvas_item_request_update (item);
- eel_canvas_item_send_behind (item,
- NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle);
-
- /* show a hand cursor */
- if (in_single_click_mode ()) {
- cursor = gdk_cursor_new_for_display (gdk_display_get_default(),
- GDK_HAND2);
- gdk_window_set_cursor (cursor_window, cursor);
- g_object_unref (cursor);
-
- canvas_item->details->cursor_window = g_object_ref (cursor_window);
- }
- }
- return TRUE;
-
- case GDK_LEAVE_NOTIFY:
- if (canvas_item->details->is_prelit
- || canvas_item->details->is_highlighted_for_drop) {
- /* When leaving, turn of the prelight state and the
- * higlighted for drop. The latter gets turned on
- * by the drag&drop motion callback.
- */
- canvas_item->details->is_prelit = FALSE;
- canvas_item->details->is_highlighted_for_drop = FALSE;
- nautilus_canvas_item_invalidate_label_size (canvas_item);
- eel_canvas_item_request_update (item);
-
- /* show default cursor */
- gdk_window_set_cursor (cursor_window, NULL);
- g_clear_object (&canvas_item->details->cursor_window);
- }
- return TRUE;
-
- default:
- /* Don't eat up other events; canvas container might use them. */
- return FALSE;
- }
+nautilus_canvas_item_event (EelCanvasItem *item,
+ GdkEvent *event)
+{
+ NautilusCanvasItem *canvas_item;
+ GdkCursor *cursor;
+ GdkWindow *cursor_window;
+
+ canvas_item = NAUTILUS_CANVAS_ITEM (item);
+ cursor_window = ((GdkEventAny *) event)->window;
+
+ switch (event->type)
+ {
+ case GDK_ENTER_NOTIFY:
+ {
+ if (!canvas_item->details->is_prelit)
+ {
+ canvas_item->details->is_prelit = TRUE;
+ nautilus_canvas_item_invalidate_label_size (canvas_item);
+ eel_canvas_item_request_update (item);
+ eel_canvas_item_send_behind (item,
+ NAUTILUS_CANVAS_CONTAINER (item->canvas)->details->rubberband_info.selection_rectangle);
+
+ /* show a hand cursor */
+ if (in_single_click_mode ())
+ {
+ cursor = gdk_cursor_new_for_display (gdk_display_get_default (),
+ GDK_HAND2);
+ gdk_window_set_cursor (cursor_window, cursor);
+ g_object_unref (cursor);
+
+ canvas_item->details->cursor_window = g_object_ref (cursor_window);
+ }
+ }
+ return TRUE;
+ }
+
+ case GDK_LEAVE_NOTIFY:
+ {
+ if (canvas_item->details->is_prelit
+ || canvas_item->details->is_highlighted_for_drop)
+ {
+ /* When leaving, turn of the prelight state and the
+ * higlighted for drop. The latter gets turned on
+ * by the drag&drop motion callback.
+ */
+ canvas_item->details->is_prelit = FALSE;
+ canvas_item->details->is_highlighted_for_drop = FALSE;
+ nautilus_canvas_item_invalidate_label_size (canvas_item);
+ eel_canvas_item_request_update (item);
+
+ /* show default cursor */
+ gdk_window_set_cursor (cursor_window, NULL);
+ g_clear_object (&canvas_item->details->cursor_window);
+ }
+ return TRUE;
+ }
+
+ default:
+ /* Don't eat up other events; canvas container might use them. */
+ return FALSE;
+ }
}
static gboolean
-hit_test (NautilusCanvasItem *canvas_item, EelIRect icon_rect)
-{
- NautilusCanvasItemDetails *details;
-
- details = canvas_item->details;
-
- /* Quick check to see if the rect hits the canvas or text at all. */
- if (!eel_irect_hits_irect (canvas_item->details->icon_rect, icon_rect)
- && (!eel_irect_hits_irect (details->text_rect, icon_rect))) {
- return FALSE;
- }
-
- /* Check for hits in the stretch handles. */
- if (hit_test_stretch_handle (canvas_item, icon_rect, NULL)) {
- return TRUE;
- }
-
- /* Check for hit in the canvas. */
- if (eel_irect_hits_irect (canvas_item->details->icon_rect, icon_rect)) {
- return TRUE;
- }
-
- /* Check for hit in the text. */
- if (eel_irect_hits_irect (details->text_rect, icon_rect)) {
- return TRUE;
- }
-
- return FALSE;
+hit_test (NautilusCanvasItem *canvas_item,
+ EelIRect icon_rect)
+{
+ NautilusCanvasItemDetails *details;
+
+ details = canvas_item->details;
+
+ /* Quick check to see if the rect hits the canvas or text at all. */
+ if (!eel_irect_hits_irect (canvas_item->details->icon_rect, icon_rect)
+ && (!eel_irect_hits_irect (details->text_rect, icon_rect)))
+ {
+ return FALSE;
+ }
+
+ /* Check for hits in the stretch handles. */
+ if (hit_test_stretch_handle (canvas_item, icon_rect, NULL))
+ {
+ return TRUE;
+ }
+
+ /* Check for hit in the canvas. */
+ if (eel_irect_hits_irect (canvas_item->details->icon_rect, icon_rect))
+ {
+ return TRUE;
+ }
+
+ /* Check for hit in the text. */
+ if (eel_irect_hits_irect (details->text_rect, icon_rect))
+ {
+ return TRUE;
+ }
+
+ return FALSE;
}
/* Point handler for the canvas canvas item. */
static double
-nautilus_canvas_item_point (EelCanvasItem *item, double x, double y, int cx, int cy,
- EelCanvasItem **actual_item)
-{
- EelIRect icon_rect;
-
- *actual_item = item;
- icon_rect.x0 = cx;
- icon_rect.y0 = cy;
- icon_rect.x1 = cx + 1;
- icon_rect.y1 = cy + 1;
- if (hit_test (NAUTILUS_CANVAS_ITEM (item), icon_rect)) {
- return 0.0;
- } else {
- /* This value means not hit.
- * It's kind of arbitrary. Can we do better?
- */
- return item->canvas->pixels_per_unit * 2 + 10;
- }
+nautilus_canvas_item_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item)
+{
+ EelIRect icon_rect;
+
+ *actual_item = item;
+ icon_rect.x0 = cx;
+ icon_rect.y0 = cy;
+ icon_rect.x1 = cx + 1;
+ icon_rect.y1 = cy + 1;
+ if (hit_test (NAUTILUS_CANVAS_ITEM (item), icon_rect))
+ {
+ return 0.0;
+ }
+ else
+ {
+ /* This value means not hit.
+ * It's kind of arbitrary. Can we do better?
+ */
+ return item->canvas->pixels_per_unit * 2 + 10;
+ }
}
static void
-nautilus_canvas_item_translate (EelCanvasItem *item, double dx, double dy)
+nautilus_canvas_item_translate (EelCanvasItem *item,
+ double dx,
+ double dy)
{
- NautilusCanvasItem *canvas_item;
- NautilusCanvasItemDetails *details;
-
- canvas_item = NAUTILUS_CANVAS_ITEM (item);
- details = canvas_item->details;
+ NautilusCanvasItem *canvas_item;
+ NautilusCanvasItemDetails *details;
- details->x += dx;
- details->y += dy;
+ canvas_item = NAUTILUS_CANVAS_ITEM (item);
+ details = canvas_item->details;
+
+ details->x += dx;
+ details->y += dy;
}
void
nautilus_canvas_item_get_bounds_for_layout (NautilusCanvasItem *canvas_item,
- double *x1, double *y1, double *x2, double *y2)
-{
- NautilusCanvasItemDetails *details;
- EelIRect *total_rect;
-
- details = canvas_item->details;
-
- nautilus_canvas_item_ensure_bounds_up_to_date (canvas_item);
- g_assert (details->bounds_cached);
-
- total_rect = &details->bounds_cache_for_layout;
-
- /* Return the result. */
- if (x1 != NULL) {
- *x1 = (int)details->x + total_rect->x0;
- }
- if (y1 != NULL) {
- *y1 = (int)details->y + total_rect->y0;
- }
- if (x2 != NULL) {
- *x2 = (int)details->x + total_rect->x1 + 1;
- }
- if (y2 != NULL) {
- *y2 = (int)details->y + total_rect->y1 + 1;
- }
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
+{
+ NautilusCanvasItemDetails *details;
+ EelIRect *total_rect;
+
+ details = canvas_item->details;
+
+ nautilus_canvas_item_ensure_bounds_up_to_date (canvas_item);
+ g_assert (details->bounds_cached);
+
+ total_rect = &details->bounds_cache_for_layout;
+
+ /* Return the result. */
+ if (x1 != NULL)
+ {
+ *x1 = (int) details->x + total_rect->x0;
+ }
+ if (y1 != NULL)
+ {
+ *y1 = (int) details->y + total_rect->y0;
+ }
+ if (x2 != NULL)
+ {
+ *x2 = (int) details->x + total_rect->x1 + 1;
+ }
+ if (y2 != NULL)
+ {
+ *y2 = (int) details->y + total_rect->y1 + 1;
+ }
}
void
nautilus_canvas_item_get_bounds_for_entire_item (NautilusCanvasItem *canvas_item,
- double *x1, double *y1, double *x2, double *y2)
-{
- NautilusCanvasItemDetails *details;
- EelIRect *total_rect;
-
- details = canvas_item->details;
-
- nautilus_canvas_item_ensure_bounds_up_to_date (canvas_item);
- g_assert (details->bounds_cached);
-
- total_rect = &details->bounds_cache_for_entire_item;
-
- /* Return the result. */
- if (x1 != NULL) {
- *x1 = (int)details->x + total_rect->x0;
- }
- if (y1 != NULL) {
- *y1 = (int)details->y + total_rect->y0;
- }
- if (x2 != NULL) {
- *x2 = (int)details->x + total_rect->x1 + 1;
- }
- if (y2 != NULL) {
- *y2 = (int)details->y + total_rect->y1 + 1;
- }
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
+{
+ NautilusCanvasItemDetails *details;
+ EelIRect *total_rect;
+
+ details = canvas_item->details;
+
+ nautilus_canvas_item_ensure_bounds_up_to_date (canvas_item);
+ g_assert (details->bounds_cached);
+
+ total_rect = &details->bounds_cache_for_entire_item;
+
+ /* Return the result. */
+ if (x1 != NULL)
+ {
+ *x1 = (int) details->x + total_rect->x0;
+ }
+ if (y1 != NULL)
+ {
+ *y1 = (int) details->y + total_rect->y0;
+ }
+ if (x2 != NULL)
+ {
+ *x2 = (int) details->x + total_rect->x1 + 1;
+ }
+ if (y2 != NULL)
+ {
+ *y2 = (int) details->y + total_rect->y1 + 1;
+ }
}
-
+
/* Bounds handler for the canvas canvas item. */
static void
nautilus_canvas_item_bounds (EelCanvasItem *item,
- double *x1, double *y1, double *x2, double *y2)
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- NautilusCanvasItem *canvas_item;
- NautilusCanvasItemDetails *details;
- EelIRect *total_rect;
+ NautilusCanvasItem *canvas_item;
+ NautilusCanvasItemDetails *details;
+ EelIRect *total_rect;
- canvas_item = NAUTILUS_CANVAS_ITEM (item);
- details = canvas_item->details;
+ canvas_item = NAUTILUS_CANVAS_ITEM (item);
+ details = canvas_item->details;
- g_assert (x1 != NULL);
- g_assert (y1 != NULL);
- g_assert (x2 != NULL);
- g_assert (y2 != NULL);
+ g_assert (x1 != NULL);
+ g_assert (y1 != NULL);
+ g_assert (x2 != NULL);
+ g_assert (y2 != NULL);
- nautilus_canvas_item_ensure_bounds_up_to_date (canvas_item);
- g_assert (details->bounds_cached);
+ nautilus_canvas_item_ensure_bounds_up_to_date (canvas_item);
+ g_assert (details->bounds_cached);
- total_rect = &details->bounds_cache;
+ total_rect = &details->bounds_cache;
- /* Return the result. */
- *x1 = (int)details->x + total_rect->x0;
- *y1 = (int)details->y + total_rect->y0;
- *x2 = (int)details->x + total_rect->x1 + 1;
- *y2 = (int)details->y + total_rect->y1 + 1;
+ /* Return the result. */
+ *x1 = (int) details->x + total_rect->x0;
+ *y1 = (int) details->y + total_rect->y0;
+ *x2 = (int) details->x + total_rect->x1 + 1;
+ *y2 = (int) details->y + total_rect->y1 + 1;
}
static void
nautilus_canvas_item_ensure_bounds_up_to_date (NautilusCanvasItem *canvas_item)
{
- NautilusCanvasItemDetails *details;
- EelIRect icon_rect;
- EelIRect text_rect, text_rect_for_layout, text_rect_for_entire_text;
- EelIRect total_rect, total_rect_for_layout, total_rect_for_entire_text;
- EelCanvasItem *item;
- double pixels_per_unit;
- gint width, height;
-
- details = canvas_item->details;
- item = EEL_CANVAS_ITEM (canvas_item);
+ NautilusCanvasItemDetails *details;
+ EelIRect icon_rect;
+ EelIRect text_rect, text_rect_for_layout, text_rect_for_entire_text;
+ EelIRect total_rect, total_rect_for_layout, total_rect_for_entire_text;
+ EelCanvasItem *item;
+ double pixels_per_unit;
+ gint width, height;
+
+ details = canvas_item->details;
+ item = EEL_CANVAS_ITEM (canvas_item);
- if (!details->bounds_cached) {
- measure_label_text (canvas_item);
+ if (!details->bounds_cached)
+ {
+ measure_label_text (canvas_item);
- pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
+ pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
- /* Compute scaled canvas rectangle. */
- icon_rect.x0 = 0;
- icon_rect.y0 = 0;
+ /* Compute scaled canvas rectangle. */
+ icon_rect.x0 = 0;
+ icon_rect.y0 = 0;
- get_scaled_icon_size (canvas_item, &width, &height);
+ get_scaled_icon_size (canvas_item, &width, &height);
- icon_rect.x1 = width / pixels_per_unit;
- icon_rect.y1 = height / pixels_per_unit;
+ icon_rect.x1 = width / pixels_per_unit;
+ icon_rect.y1 = height / pixels_per_unit;
- /* Compute text rectangle. */
- text_rect = compute_text_rectangle (canvas_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_DISPLAY);
- text_rect_for_layout = compute_text_rectangle (canvas_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_LAYOUT);
- text_rect_for_entire_text = compute_text_rectangle (canvas_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_ENTIRE_ITEM);
+ /* Compute text rectangle. */
+ text_rect = compute_text_rectangle (canvas_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_DISPLAY);
+ text_rect_for_layout = compute_text_rectangle (canvas_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_LAYOUT);
+ text_rect_for_entire_text = compute_text_rectangle (canvas_item, icon_rect, FALSE, BOUNDS_USAGE_FOR_ENTIRE_ITEM);
- /* Compute total rectangle */
- eel_irect_union (&total_rect, &icon_rect, &text_rect);
- eel_irect_union (&total_rect_for_layout, &icon_rect, &text_rect_for_layout);
- eel_irect_union (&total_rect_for_entire_text, &icon_rect, &text_rect_for_entire_text);
+ /* Compute total rectangle */
+ eel_irect_union (&total_rect, &icon_rect, &text_rect);
+ eel_irect_union (&total_rect_for_layout, &icon_rect, &text_rect_for_layout);
+ eel_irect_union (&total_rect_for_entire_text, &icon_rect, &text_rect_for_entire_text);
- details->bounds_cache = total_rect;
- details->bounds_cache_for_layout = total_rect_for_layout;
- details->bounds_cache_for_entire_item = total_rect_for_entire_text;
- details->bounds_cached = TRUE;
- }
+ details->bounds_cache = total_rect;
+ details->bounds_cache_for_layout = total_rect_for_layout;
+ details->bounds_cache_for_entire_item = total_rect_for_entire_text;
+ details->bounds_cached = TRUE;
+ }
}
/* Get the rectangle of the canvas only, in world coordinates. */
EelDRect
nautilus_canvas_item_get_icon_rectangle (const NautilusCanvasItem *item)
{
- EelDRect rectangle;
- double pixels_per_unit;
- gint width, height;
-
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), eel_drect_empty);
+ EelDRect rectangle;
+ double pixels_per_unit;
+ gint width, height;
+
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), eel_drect_empty);
+
+ rectangle.x0 = item->details->x;
+ rectangle.y0 = item->details->y;
- rectangle.x0 = item->details->x;
- rectangle.y0 = item->details->y;
-
- pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
- get_scaled_icon_size (NAUTILUS_CANVAS_ITEM (item), &width, &height);
- rectangle.x1 = rectangle.x0 + width / pixels_per_unit;
- rectangle.y1 = rectangle.y0 + height / pixels_per_unit;
+ pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
+ get_scaled_icon_size (NAUTILUS_CANVAS_ITEM (item), &width, &height);
+ rectangle.x1 = rectangle.x0 + width / pixels_per_unit;
+ rectangle.y1 = rectangle.y0 + height / pixels_per_unit;
- eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
- &rectangle.x0,
- &rectangle.y0);
- eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
- &rectangle.x1,
- &rectangle.y1);
+ eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
+ &rectangle.x0,
+ &rectangle.y0);
+ eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
+ &rectangle.x1,
+ &rectangle.y1);
- return rectangle;
+ return rectangle;
}
/* Get the rectangle of the icon only, in canvas coordinates. */
static void
get_icon_rectangle (NautilusCanvasItem *item,
- EelIRect *rect)
+ EelIRect *rect)
{
- gint width, height;
+ gint width, height;
- g_assert (NAUTILUS_IS_CANVAS_ITEM (item));
- g_assert (rect != NULL);
+ g_assert (NAUTILUS_IS_CANVAS_ITEM (item));
+ g_assert (rect != NULL);
- eel_canvas_w2c (EEL_CANVAS_ITEM (item)->canvas,
- item->details->x,
- item->details->y,
- &rect->x0,
- &rect->y0);
-
- get_scaled_icon_size (item, &width, &height);
-
- rect->x1 = rect->x0 + width;
- rect->y1 = rect->y0 + height;
+ eel_canvas_w2c (EEL_CANVAS_ITEM (item)->canvas,
+ item->details->x,
+ item->details->y,
+ &rect->x0,
+ &rect->y0);
+
+ get_scaled_icon_size (item, &width, &height);
+
+ rect->x1 = rect->x0 + width;
+ rect->y1 = rect->y0 + height;
}
void
nautilus_canvas_item_set_show_stretch_handles (NautilusCanvasItem *item,
- gboolean show_stretch_handles)
+ gboolean show_stretch_handles)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_ITEM (item));
- g_return_if_fail (show_stretch_handles == FALSE || show_stretch_handles == TRUE);
-
- if (!item->details->show_stretch_handles == !show_stretch_handles) {
- return;
- }
+ g_return_if_fail (NAUTILUS_IS_CANVAS_ITEM (item));
+ g_return_if_fail (show_stretch_handles == FALSE || show_stretch_handles == TRUE);
+
+ if (!item->details->show_stretch_handles == !show_stretch_handles)
+ {
+ return;
+ }
- item->details->show_stretch_handles = show_stretch_handles;
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (item));
+ item->details->show_stretch_handles = show_stretch_handles;
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (item));
}
/* Check if one of the stretch handles was hit. */
static gboolean
hit_test_stretch_handle (NautilusCanvasItem *item,
- EelIRect probe_icon_rect,
- GtkCornerType *corner)
-{
- EelIRect icon_rect;
- GdkPixbuf *knob_pixbuf;
- int knob_width, knob_height;
- int hit_corner;
-
- g_assert (NAUTILUS_IS_CANVAS_ITEM (item));
-
- /* Make sure there are handles to hit. */
- if (!item->details->show_stretch_handles) {
- return FALSE;
- }
-
- /* Quick check to see if the rect hits the canvas at all. */
- icon_rect = item->details->icon_rect;
- if (!eel_irect_hits_irect (probe_icon_rect, icon_rect)) {
- return FALSE;
- }
-
- knob_pixbuf = get_knob_pixbuf ();
- knob_width = gdk_pixbuf_get_width (knob_pixbuf);
- knob_height = gdk_pixbuf_get_height (knob_pixbuf);
- g_object_unref (knob_pixbuf);
-
- /* Check for hits in the stretch handles. */
- hit_corner = -1;
- if (probe_icon_rect.x0 < icon_rect.x0 + knob_width) {
- if (probe_icon_rect.y0 < icon_rect.y0 + knob_height)
- hit_corner = GTK_CORNER_TOP_LEFT;
- else if (probe_icon_rect.y1 >= icon_rect.y1 - knob_height)
- hit_corner = GTK_CORNER_BOTTOM_LEFT;
- }
- else if (probe_icon_rect.x1 >= icon_rect.x1 - knob_width) {
- if (probe_icon_rect.y0 < icon_rect.y0 + knob_height)
- hit_corner = GTK_CORNER_TOP_RIGHT;
- else if (probe_icon_rect.y1 >= icon_rect.y1 - knob_height)
- hit_corner = GTK_CORNER_BOTTOM_RIGHT;
- }
- if (corner)
- *corner = hit_corner;
-
- return hit_corner != -1;
+ EelIRect probe_icon_rect,
+ GtkCornerType *corner)
+{
+ EelIRect icon_rect;
+ GdkPixbuf *knob_pixbuf;
+ int knob_width, knob_height;
+ int hit_corner;
+
+ g_assert (NAUTILUS_IS_CANVAS_ITEM (item));
+
+ /* Make sure there are handles to hit. */
+ if (!item->details->show_stretch_handles)
+ {
+ return FALSE;
+ }
+
+ /* Quick check to see if the rect hits the canvas at all. */
+ icon_rect = item->details->icon_rect;
+ if (!eel_irect_hits_irect (probe_icon_rect, icon_rect))
+ {
+ return FALSE;
+ }
+
+ knob_pixbuf = get_knob_pixbuf ();
+ knob_width = gdk_pixbuf_get_width (knob_pixbuf);
+ knob_height = gdk_pixbuf_get_height (knob_pixbuf);
+ g_object_unref (knob_pixbuf);
+
+ /* Check for hits in the stretch handles. */
+ hit_corner = -1;
+ if (probe_icon_rect.x0 < icon_rect.x0 + knob_width)
+ {
+ if (probe_icon_rect.y0 < icon_rect.y0 + knob_height)
+ {
+ hit_corner = GTK_CORNER_TOP_LEFT;
+ }
+ else if (probe_icon_rect.y1 >= icon_rect.y1 - knob_height)
+ {
+ hit_corner = GTK_CORNER_BOTTOM_LEFT;
+ }
+ }
+ else if (probe_icon_rect.x1 >= icon_rect.x1 - knob_width)
+ {
+ if (probe_icon_rect.y0 < icon_rect.y0 + knob_height)
+ {
+ hit_corner = GTK_CORNER_TOP_RIGHT;
+ }
+ else if (probe_icon_rect.y1 >= icon_rect.y1 - knob_height)
+ {
+ hit_corner = GTK_CORNER_BOTTOM_RIGHT;
+ }
+ }
+ if (corner)
+ {
+ *corner = hit_corner;
+ }
+
+ return hit_corner != -1;
}
gboolean
nautilus_canvas_item_hit_test_stretch_handles (NautilusCanvasItem *item,
- gdouble world_x,
- gdouble world_y,
- GtkCornerType *corner)
+ gdouble world_x,
+ gdouble world_y,
+ GtkCornerType *corner)
{
- EelIRect icon_rect;
+ EelIRect icon_rect;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), FALSE);
-
- eel_canvas_w2c (EEL_CANVAS_ITEM (item)->canvas,
- world_x,
- world_y,
- &icon_rect.x0,
- &icon_rect.y0);
- icon_rect.x1 = icon_rect.x0 + 1;
- icon_rect.y1 = icon_rect.y0 + 1;
- return hit_test_stretch_handle (item, icon_rect, corner);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), FALSE);
+
+ eel_canvas_w2c (EEL_CANVAS_ITEM (item)->canvas,
+ world_x,
+ world_y,
+ &icon_rect.x0,
+ &icon_rect.y0);
+ icon_rect.x1 = icon_rect.x0 + 1;
+ icon_rect.y1 = icon_rect.y0 + 1;
+ return hit_test_stretch_handle (item, icon_rect, corner);
}
/* nautilus_canvas_item_hit_test_rectangle
@@ -1803,152 +2002,161 @@ nautilus_canvas_item_hit_test_stretch_handles (NautilusCanvasItem *item,
* canvas rect.
*/
gboolean
-nautilus_canvas_item_hit_test_rectangle (NautilusCanvasItem *item, EelIRect icon_rect)
+nautilus_canvas_item_hit_test_rectangle (NautilusCanvasItem *item,
+ EelIRect icon_rect)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_ITEM (item), FALSE);
- return hit_test (item, icon_rect);
+ return hit_test (item, icon_rect);
}
void
-nautilus_canvas_item_set_entire_text (NautilusCanvasItem *item,
- gboolean entire_text)
+nautilus_canvas_item_set_entire_text (NautilusCanvasItem *item,
+ gboolean entire_text)
{
- if (item->details->entire_text != entire_text) {
- item->details->entire_text = entire_text;
+ if (item->details->entire_text != entire_text)
+ {
+ item->details->entire_text = entire_text;
- nautilus_canvas_item_invalidate_label_size (item);
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (item));
- }
+ nautilus_canvas_item_invalidate_label_size (item);
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (item));
+ }
}
/* Class initialization function for the canvas canvas item. */
static void
nautilus_canvas_item_class_init (NautilusCanvasItemClass *class)
{
- GObjectClass *object_class;
- EelCanvasItemClass *item_class;
-
- object_class = G_OBJECT_CLASS (class);
- item_class = EEL_CANVAS_ITEM_CLASS (class);
-
- object_class->finalize = nautilus_canvas_item_finalize;
- object_class->set_property = nautilus_canvas_item_set_property;
- object_class->get_property = nautilus_canvas_item_get_property;
-
- g_object_class_install_property (
- object_class,
- PROP_EDITABLE_TEXT,
- g_param_spec_string ("editable_text",
- "editable text",
- "the editable label",
- "", G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_ADDITIONAL_TEXT,
- g_param_spec_string ("additional_text",
- "additional text",
- "some more text",
- "", G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_HIGHLIGHTED_FOR_SELECTION,
- g_param_spec_boolean ("highlighted_for_selection",
- "highlighted for selection",
- "whether we are highlighted for a selection",
- FALSE, G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
- g_param_spec_boolean ("highlighted_as_keyboard_focus",
- "highlighted as keyboard focus",
- "whether we are highlighted to render keyboard focus",
- FALSE, G_PARAM_READWRITE));
-
-
- g_object_class_install_property (
- object_class,
- PROP_HIGHLIGHTED_FOR_DROP,
- g_param_spec_boolean ("highlighted_for_drop",
- "highlighted for drop",
- "whether we are highlighted for a D&D drop",
- FALSE, G_PARAM_READWRITE));
-
- g_object_class_install_property (
- object_class,
- PROP_HIGHLIGHTED_FOR_CLIPBOARD,
- g_param_spec_boolean ("highlighted_for_clipboard",
- "highlighted for clipboard",
- "whether we are highlighted for a clipboard paste (after we have been cut)",
- FALSE, G_PARAM_READWRITE));
-
- item_class->update = nautilus_canvas_item_update;
- item_class->draw = nautilus_canvas_item_draw;
- item_class->point = nautilus_canvas_item_point;
- item_class->translate = nautilus_canvas_item_translate;
- item_class->bounds = nautilus_canvas_item_bounds;
- item_class->event = nautilus_canvas_item_event;
-
- atk_registry_set_factory_type (atk_get_default_registry (),
- NAUTILUS_TYPE_CANVAS_ITEM,
- nautilus_canvas_item_accessible_factory_get_type ());
-
- g_type_class_add_private (class, sizeof (NautilusCanvasItemDetails));
+ GObjectClass *object_class;
+ EelCanvasItemClass *item_class;
+
+ object_class = G_OBJECT_CLASS (class);
+ item_class = EEL_CANVAS_ITEM_CLASS (class);
+
+ object_class->finalize = nautilus_canvas_item_finalize;
+ object_class->set_property = nautilus_canvas_item_set_property;
+ object_class->get_property = nautilus_canvas_item_get_property;
+
+ g_object_class_install_property (
+ object_class,
+ PROP_EDITABLE_TEXT,
+ g_param_spec_string ("editable_text",
+ "editable text",
+ "the editable label",
+ "", G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_ADDITIONAL_TEXT,
+ g_param_spec_string ("additional_text",
+ "additional text",
+ "some more text",
+ "", G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_HIGHLIGHTED_FOR_SELECTION,
+ g_param_spec_boolean ("highlighted_for_selection",
+ "highlighted for selection",
+ "whether we are highlighted for a selection",
+ FALSE, G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_HIGHLIGHTED_AS_KEYBOARD_FOCUS,
+ g_param_spec_boolean ("highlighted_as_keyboard_focus",
+ "highlighted as keyboard focus",
+ "whether we are highlighted to render keyboard focus",
+ FALSE, G_PARAM_READWRITE));
+
+
+ g_object_class_install_property (
+ object_class,
+ PROP_HIGHLIGHTED_FOR_DROP,
+ g_param_spec_boolean ("highlighted_for_drop",
+ "highlighted for drop",
+ "whether we are highlighted for a D&D drop",
+ FALSE, G_PARAM_READWRITE));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_HIGHLIGHTED_FOR_CLIPBOARD,
+ g_param_spec_boolean ("highlighted_for_clipboard",
+ "highlighted for clipboard",
+ "whether we are highlighted for a clipboard paste (after we have been cut)",
+ FALSE, G_PARAM_READWRITE));
+
+ item_class->update = nautilus_canvas_item_update;
+ item_class->draw = nautilus_canvas_item_draw;
+ item_class->point = nautilus_canvas_item_point;
+ item_class->translate = nautilus_canvas_item_translate;
+ item_class->bounds = nautilus_canvas_item_bounds;
+ item_class->event = nautilus_canvas_item_event;
+
+ atk_registry_set_factory_type (atk_get_default_registry (),
+ NAUTILUS_TYPE_CANVAS_ITEM,
+ nautilus_canvas_item_accessible_factory_get_type ());
+
+ g_type_class_add_private (class, sizeof (NautilusCanvasItemDetails));
}
static GailTextUtil *
nautilus_canvas_item_get_text (GObject *text)
{
- return NAUTILUS_CANVAS_ITEM (text)->details->text_util;
+ return NAUTILUS_CANVAS_ITEM (text)->details->text_util;
}
static void
nautilus_canvas_item_text_interface_init (EelAccessibleTextIface *iface)
{
- iface->get_text = nautilus_canvas_item_get_text;
+ iface->get_text = nautilus_canvas_item_get_text;
}
/* ============================= a11y interfaces =========================== */
-static const char *nautilus_canvas_item_accessible_action_names[] = {
- "open",
- "menu",
- NULL
+static const char *nautilus_canvas_item_accessible_action_names[] =
+{
+ "open",
+ "menu",
+ NULL
};
-static const char *nautilus_canvas_item_accessible_action_descriptions[] = {
- "Open item",
- "Popup context menu",
- NULL
+static const char *nautilus_canvas_item_accessible_action_descriptions[] =
+{
+ "Open item",
+ "Popup context menu",
+ NULL
};
-enum {
- ACTION_OPEN,
- ACTION_MENU,
- LAST_ACTION
+enum
+{
+ ACTION_OPEN,
+ ACTION_MENU,
+ LAST_ACTION
};
-typedef struct {
- char *action_descriptions[LAST_ACTION];
- char *image_description;
- char *description;
+typedef struct
+{
+ char *action_descriptions[LAST_ACTION];
+ char *image_description;
+ char *description;
} NautilusCanvasItemAccessiblePrivate;
-typedef struct {
- NautilusCanvasItem *item;
- gint action_number;
+typedef struct
+{
+ NautilusCanvasItem *item;
+ gint action_number;
} NautilusCanvasItemAccessibleActionContext;
-typedef struct {
- EelCanvasItemAccessible parent;
- NautilusCanvasItemAccessiblePrivate *priv;
+typedef struct
+{
+ EelCanvasItemAccessible parent;
+ NautilusCanvasItemAccessiblePrivate *priv;
} NautilusCanvasItemAccessible;
-typedef struct {
- EelCanvasItemAccessibleClass parent_class;
+typedef struct
+{
+ EelCanvasItemAccessibleClass parent_class;
} NautilusCanvasItemAccessibleClass;
#define GET_ACCESSIBLE_PRIV(o) ((NautilusCanvasItemAccessible *) o)->priv;
@@ -1957,668 +2165,748 @@ typedef struct {
static gboolean
nautilus_canvas_item_accessible_idle_do_action (gpointer data)
{
- NautilusCanvasItem *item;
- NautilusCanvasItemAccessibleActionContext *ctx;
- NautilusCanvasIcon *icon;
- NautilusCanvasContainer *container;
- GList* selection;
- GList file_list;
- GdkEventButton button_event = { 0 };
- gint action_number;
-
- container = NAUTILUS_CANVAS_CONTAINER (data);
- container->details->a11y_item_action_idle_handler = 0;
- while (!g_queue_is_empty (container->details->a11y_item_action_queue)) {
- ctx = g_queue_pop_head (container->details->a11y_item_action_queue);
- action_number = ctx->action_number;
- item = ctx->item;
- g_free (ctx);
- icon = item->user_data;
-
- switch (action_number) {
- case ACTION_OPEN:
- file_list.data = icon->data;
- file_list.next = NULL;
- file_list.prev = NULL;
- g_signal_emit_by_name (container, "activate", &file_list);
- break;
- case ACTION_MENU:
- selection = nautilus_canvas_container_get_selection (container);
- if (selection == NULL ||
- g_list_length (selection) != 1 ||
- selection->data != icon->data) {
- g_list_free (selection);
- return FALSE;
- }
- g_list_free (selection);
- g_signal_emit_by_name (container, "context-click-selection", &button_event);
- break;
- default :
- g_assert_not_reached ();
- break;
- }
- }
- return FALSE;
+ NautilusCanvasItem *item;
+ NautilusCanvasItemAccessibleActionContext *ctx;
+ NautilusCanvasIcon *icon;
+ NautilusCanvasContainer *container;
+ GList *selection;
+ GList file_list;
+ GdkEventButton button_event = { 0 };
+ gint action_number;
+
+ container = NAUTILUS_CANVAS_CONTAINER (data);
+ container->details->a11y_item_action_idle_handler = 0;
+ while (!g_queue_is_empty (container->details->a11y_item_action_queue))
+ {
+ ctx = g_queue_pop_head (container->details->a11y_item_action_queue);
+ action_number = ctx->action_number;
+ item = ctx->item;
+ g_free (ctx);
+ icon = item->user_data;
+
+ switch (action_number)
+ {
+ case ACTION_OPEN:
+ {
+ file_list.data = icon->data;
+ file_list.next = NULL;
+ file_list.prev = NULL;
+ g_signal_emit_by_name (container, "activate", &file_list);
+ }
+ break;
+
+ case ACTION_MENU:
+ {
+ selection = nautilus_canvas_container_get_selection (container);
+ if (selection == NULL ||
+ g_list_length (selection) != 1 ||
+ selection->data != icon->data)
+ {
+ g_list_free (selection);
+ return FALSE;
+ }
+ g_list_free (selection);
+ g_signal_emit_by_name (container, "context-click-selection", &button_event);
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
+ }
+ return FALSE;
}
static gboolean
nautilus_canvas_item_accessible_do_action (AtkAction *accessible,
- int i)
-{
- NautilusCanvasItem *item;
- NautilusCanvasItemAccessibleActionContext *ctx;
- NautilusCanvasContainer *container;
-
- g_assert (i < LAST_ACTION);
-
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
- if (!item) {
- return FALSE;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
- switch (i) {
- case ACTION_OPEN:
- case ACTION_MENU:
- if (container->details->a11y_item_action_queue == NULL) {
- container->details->a11y_item_action_queue = g_queue_new ();
- }
- ctx = g_new (NautilusCanvasItemAccessibleActionContext, 1);
- ctx->action_number = i;
- ctx->item = item;
- g_queue_push_head (container->details->a11y_item_action_queue, ctx);
- if (container->details->a11y_item_action_idle_handler == 0) {
- container->details->a11y_item_action_idle_handler = g_idle_add (nautilus_canvas_item_accessible_idle_do_action, container);
- }
- break;
- default :
- g_warning ("Invalid action passed to NautilusCanvasItemAccessible::do_action");
- return FALSE;
+ int i)
+{
+ NautilusCanvasItem *item;
+ NautilusCanvasItemAccessibleActionContext *ctx;
+ NautilusCanvasContainer *container;
+
+ g_assert (i < LAST_ACTION);
+
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+ if (!item)
+ {
+ return FALSE;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+ switch (i)
+ {
+ case ACTION_OPEN:
+ case ACTION_MENU:
+ {
+ if (container->details->a11y_item_action_queue == NULL)
+ {
+ container->details->a11y_item_action_queue = g_queue_new ();
+ }
+ ctx = g_new (NautilusCanvasItemAccessibleActionContext, 1);
+ ctx->action_number = i;
+ ctx->item = item;
+ g_queue_push_head (container->details->a11y_item_action_queue, ctx);
+ if (container->details->a11y_item_action_idle_handler == 0)
+ {
+ container->details->a11y_item_action_idle_handler = g_idle_add (nautilus_canvas_item_accessible_idle_do_action, container);
+ }
}
+ break;
- return TRUE;
+ default:
+ g_warning ("Invalid action passed to NautilusCanvasItemAccessible::do_action");
+ return FALSE;
+ }
+
+ return TRUE;
}
static int
nautilus_canvas_item_accessible_get_n_actions (AtkAction *accessible)
{
- return LAST_ACTION;
+ return LAST_ACTION;
}
static const char *
nautilus_canvas_item_accessible_action_get_description (AtkAction *accessible,
- int i)
+ int i)
{
- NautilusCanvasItemAccessiblePrivate *priv;
+ NautilusCanvasItemAccessiblePrivate *priv;
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- priv = GET_ACCESSIBLE_PRIV (accessible);
+ priv = GET_ACCESSIBLE_PRIV (accessible);
- if (priv->action_descriptions[i]) {
- return priv->action_descriptions[i];
- } else {
- return nautilus_canvas_item_accessible_action_descriptions[i];
- }
+ if (priv->action_descriptions[i])
+ {
+ return priv->action_descriptions[i];
+ }
+ else
+ {
+ return nautilus_canvas_item_accessible_action_descriptions[i];
+ }
}
static const char *
-nautilus_canvas_item_accessible_action_get_name (AtkAction *accessible, int i)
+nautilus_canvas_item_accessible_action_get_name (AtkAction *accessible,
+ int i)
{
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- return nautilus_canvas_item_accessible_action_names[i];
+ return nautilus_canvas_item_accessible_action_names[i];
}
static const char *
nautilus_canvas_item_accessible_action_get_keybinding (AtkAction *accessible,
- int i)
+ int i)
{
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- return NULL;
+ return NULL;
}
static gboolean
-nautilus_canvas_item_accessible_action_set_description (AtkAction *accessible,
- int i,
- const char *description)
+nautilus_canvas_item_accessible_action_set_description (AtkAction *accessible,
+ int i,
+ const char *description)
{
- NautilusCanvasItemAccessiblePrivate *priv;
+ NautilusCanvasItemAccessiblePrivate *priv;
- g_assert (i < LAST_ACTION);
+ g_assert (i < LAST_ACTION);
- priv = GET_ACCESSIBLE_PRIV (accessible);
+ priv = GET_ACCESSIBLE_PRIV (accessible);
- if (priv->action_descriptions[i]) {
- g_free (priv->action_descriptions[i]);
- }
- priv->action_descriptions[i] = g_strdup (description);
+ if (priv->action_descriptions[i])
+ {
+ g_free (priv->action_descriptions[i]);
+ }
+ priv->action_descriptions[i] = g_strdup (description);
- return TRUE;
+ return TRUE;
}
static void
nautilus_canvas_item_accessible_action_interface_init (AtkActionIface *iface)
{
- iface->do_action = nautilus_canvas_item_accessible_do_action;
- iface->get_n_actions = nautilus_canvas_item_accessible_get_n_actions;
- iface->get_description = nautilus_canvas_item_accessible_action_get_description;
- iface->get_keybinding = nautilus_canvas_item_accessible_action_get_keybinding;
- iface->get_name = nautilus_canvas_item_accessible_action_get_name;
- iface->set_description = nautilus_canvas_item_accessible_action_set_description;
+ iface->do_action = nautilus_canvas_item_accessible_do_action;
+ iface->get_n_actions = nautilus_canvas_item_accessible_get_n_actions;
+ iface->get_description = nautilus_canvas_item_accessible_action_get_description;
+ iface->get_keybinding = nautilus_canvas_item_accessible_action_get_keybinding;
+ iface->get_name = nautilus_canvas_item_accessible_action_get_name;
+ iface->set_description = nautilus_canvas_item_accessible_action_set_description;
}
static const gchar *
nautilus_canvas_item_accessible_get_name (AtkObject *accessible)
{
- NautilusCanvasItem *item;
+ NautilusCanvasItem *item;
- if (accessible->name) {
- return accessible->name;
- }
+ if (accessible->name)
+ {
+ return accessible->name;
+ }
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
- if (!item) {
- return NULL;
- }
- return item->details->editable_text;
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+ if (!item)
+ {
+ return NULL;
+ }
+ return item->details->editable_text;
}
-static const gchar*
+static const gchar *
nautilus_canvas_item_accessible_get_description (AtkObject *accessible)
{
- NautilusCanvasItem *item;
+ NautilusCanvasItem *item;
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
- if (!item) {
- return NULL;
- }
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+ if (!item)
+ {
+ return NULL;
+ }
- return item->details->additional_text;
+ return item->details->additional_text;
}
static AtkObject *
nautilus_canvas_item_accessible_get_parent (AtkObject *accessible)
{
- NautilusCanvasItem *item;
-
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
- if (!item) {
- return NULL;
- }
+ NautilusCanvasItem *item;
- return gtk_widget_get_accessible (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas));
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+ if (!item)
+ {
+ return NULL;
+ }
+
+ return gtk_widget_get_accessible (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas));
}
static int
nautilus_canvas_item_accessible_get_index_in_parent (AtkObject *accessible)
{
- NautilusCanvasItem *item;
- NautilusCanvasContainer *container;
- GList *l;
- NautilusCanvasIcon *icon;
- int i;
-
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
- if (!item) {
- return -1;
- }
-
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
-
- l = container->details->icons;
- i = 0;
- while (l) {
- icon = l->data;
-
- if (icon->item == item) {
- return i;
- }
-
- i++;
- l = l->next;
- }
-
- return -1;
+ NautilusCanvasItem *item;
+ NautilusCanvasContainer *container;
+ GList *l;
+ NautilusCanvasIcon *icon;
+ int i;
+
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+ if (!item)
+ {
+ return -1;
+ }
+
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+
+ l = container->details->icons;
+ i = 0;
+ while (l)
+ {
+ icon = l->data;
+
+ if (icon->item == item)
+ {
+ return i;
+ }
+
+ i++;
+ l = l->next;
+ }
+
+ return -1;
}
static const gchar *
nautilus_canvas_item_accessible_get_image_description (AtkImage *image)
{
- NautilusCanvasItemAccessiblePrivate *priv;
- NautilusCanvasItem *item;
- NautilusCanvasIcon *icon;
- NautilusCanvasContainer *container;
- char *description;
-
- priv = GET_ACCESSIBLE_PRIV (image);
-
- if (priv->image_description) {
- return priv->image_description;
- } else {
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
- if (item == NULL) {
- return NULL;
- }
- icon = item->user_data;
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
- description = nautilus_canvas_container_get_icon_description (container, icon->data);
- g_free (priv->description);
- priv->description = description;
- return priv->description;
- }
+ NautilusCanvasItemAccessiblePrivate *priv;
+ NautilusCanvasItem *item;
+ NautilusCanvasIcon *icon;
+ NautilusCanvasContainer *container;
+ char *description;
+
+ priv = GET_ACCESSIBLE_PRIV (image);
+
+ if (priv->image_description)
+ {
+ return priv->image_description;
+ }
+ else
+ {
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
+ if (item == NULL)
+ {
+ return NULL;
+ }
+ icon = item->user_data;
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+ description = nautilus_canvas_container_get_icon_description (container, icon->data);
+ g_free (priv->description);
+ priv->description = description;
+ return priv->description;
+ }
}
static void
-nautilus_canvas_item_accessible_get_image_size
-(AtkImage *image,
- gint *width,
- gint *height)
+nautilus_canvas_item_accessible_get_image_size (AtkImage *image,
+ gint *width,
+ gint *height)
{
- NautilusCanvasItem *item;
+ NautilusCanvasItem *item;
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
- get_scaled_icon_size (item, width, height);
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
+ get_scaled_icon_size (item, width, height);
}
static void
-nautilus_canvas_item_accessible_get_image_position
-(AtkImage *image,
- gint *x,
- gint *y,
- AtkCoordType coord_type)
-{
- NautilusCanvasItem *item;
- gint x_offset, y_offset, itmp;
-
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
- if (!item) {
- return;
- }
- if (!item->details->icon_rect.x0 && !item->details->icon_rect.x1) {
- return;
- } else {
- x_offset = 0;
- y_offset = 0;
- if (item->details->text_width) {
- itmp = item->details->icon_rect.x0 -
- item->details->text_rect.x0;
- if (itmp > x_offset) {
- x_offset = itmp;
- }
- itmp = item->details->icon_rect.y0 -
- item->details->text_rect.y0;
- if (itmp > y_offset) {
- y_offset = itmp;
- }
- }
- }
- atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, coord_type);
- *x += x_offset;
- *y += y_offset;
+nautilus_canvas_item_accessible_get_image_position (AtkImage *image,
+ gint *x,
+ gint *y,
+ AtkCoordType coord_type)
+{
+ NautilusCanvasItem *item;
+ gint x_offset, y_offset, itmp;
+
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (image)));
+ if (!item)
+ {
+ return;
+ }
+ if (!item->details->icon_rect.x0 && !item->details->icon_rect.x1)
+ {
+ return;
+ }
+ else
+ {
+ x_offset = 0;
+ y_offset = 0;
+ if (item->details->text_width)
+ {
+ itmp = item->details->icon_rect.x0 -
+ item->details->text_rect.x0;
+ if (itmp > x_offset)
+ {
+ x_offset = itmp;
+ }
+ itmp = item->details->icon_rect.y0 -
+ item->details->text_rect.y0;
+ if (itmp > y_offset)
+ {
+ y_offset = itmp;
+ }
+ }
+ }
+ atk_component_get_extents (ATK_COMPONENT (image), x, y, NULL, NULL, coord_type);
+ *x += x_offset;
+ *y += y_offset;
}
static gboolean
nautilus_canvas_item_accessible_set_image_description (AtkImage *image,
- const gchar *description)
+ const gchar *description)
{
- NautilusCanvasItemAccessiblePrivate *priv;
+ NautilusCanvasItemAccessiblePrivate *priv;
- priv = GET_ACCESSIBLE_PRIV (image);
+ priv = GET_ACCESSIBLE_PRIV (image);
- g_free (priv->image_description);
- priv->image_description = g_strdup (description);
+ g_free (priv->image_description);
+ priv->image_description = g_strdup (description);
- return TRUE;
+ return TRUE;
}
static void
nautilus_canvas_item_accessible_image_interface_init (AtkImageIface *iface)
{
- iface->get_image_description = nautilus_canvas_item_accessible_get_image_description;
- iface->set_image_description = nautilus_canvas_item_accessible_set_image_description;
- iface->get_image_size = nautilus_canvas_item_accessible_get_image_size;
- iface->get_image_position = nautilus_canvas_item_accessible_get_image_position;
+ iface->get_image_description = nautilus_canvas_item_accessible_get_image_description;
+ iface->set_image_description = nautilus_canvas_item_accessible_set_image_description;
+ iface->get_image_size = nautilus_canvas_item_accessible_get_image_size;
+ iface->get_image_position = nautilus_canvas_item_accessible_get_image_position;
}
/* accessible text interface */
static gint
-nautilus_canvas_item_accessible_get_offset_at_point (AtkText *text,
- gint x,
- gint y,
- AtkCoordType coords)
-{
- gint real_x, real_y, real_width, real_height;
- NautilusCanvasItem *item;
- gint editable_height;
- gint offset = 0;
- gint index;
- PangoLayout *layout, *editable_layout, *additional_layout;
- PangoRectangle rect0;
- char *canvas_text;
- gboolean have_editable;
- gboolean have_additional;
- gint text_offset, height;
-
- atk_component_get_extents (ATK_COMPONENT (text), &real_x, &real_y,
- &real_width, &real_height, coords);
-
- x -= real_x;
- y -= real_y;
-
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)));
-
- if (item->details->pixbuf) {
- get_scaled_icon_size (item, NULL, &height);
- y -= height;
- }
- have_editable = item->details->editable_text != NULL &&
- item->details->editable_text[0] != '\0';
- have_additional = item->details->additional_text != NULL &&item->details->additional_text[0] != '\0';
-
- editable_layout = NULL;
- additional_layout = NULL;
- if (have_editable) {
- editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text);
- prepare_pango_layout_for_draw (item, editable_layout);
- pango_layout_get_pixel_size (editable_layout, NULL, &editable_height);
- if (y >= editable_height &&
- have_additional) {
- prepare_pango_layout_for_draw (item, editable_layout);
- additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
- layout = additional_layout;
- canvas_text = item->details->additional_text;
- y -= editable_height + LABEL_LINE_SPACING;
- } else {
- layout = editable_layout;
- canvas_text = item->details->editable_text;
- }
- } else if (have_additional) {
- additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
- prepare_pango_layout_for_draw (item, additional_layout);
- layout = additional_layout;
- canvas_text = item->details->additional_text;
- } else {
- return 0;
- }
-
- text_offset = 0;
- if (have_editable) {
- pango_layout_index_to_pos (editable_layout, 0, &rect0);
- text_offset = PANGO_PIXELS (rect0.x);
- }
- if (have_additional) {
- gint itmp;
-
- pango_layout_index_to_pos (additional_layout, 0, &rect0);
- itmp = PANGO_PIXELS (rect0.x);
- if (itmp < text_offset) {
- text_offset = itmp;
- }
- }
- pango_layout_index_to_pos (layout, 0, &rect0);
- x += text_offset;
- if (!pango_layout_xy_to_index (layout,
- x * PANGO_SCALE,
- y * PANGO_SCALE,
- &index, NULL)) {
- if (x < 0 || y < 0) {
- index = 0;
- } else {
- index = -1;
- }
- }
- if (index == -1) {
- offset = g_utf8_strlen (canvas_text, -1);
- } else {
- offset = g_utf8_pointer_to_offset (canvas_text, canvas_text + index);
- }
- if (layout == additional_layout) {
- offset += g_utf8_strlen (item->details->editable_text, -1);
- }
-
- if (editable_layout != NULL) {
- g_object_unref (editable_layout);
- }
-
- if (additional_layout != NULL) {
- g_object_unref (additional_layout);
- }
-
- return offset;
+nautilus_canvas_item_accessible_get_offset_at_point (AtkText *text,
+ gint x,
+ gint y,
+ AtkCoordType coords)
+{
+ gint real_x, real_y, real_width, real_height;
+ NautilusCanvasItem *item;
+ gint editable_height;
+ gint offset = 0;
+ gint index;
+ PangoLayout *layout, *editable_layout, *additional_layout;
+ PangoRectangle rect0;
+ char *canvas_text;
+ gboolean have_editable;
+ gboolean have_additional;
+ gint text_offset, height;
+
+ atk_component_get_extents (ATK_COMPONENT (text), &real_x, &real_y,
+ &real_width, &real_height, coords);
+
+ x -= real_x;
+ y -= real_y;
+
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)));
+
+ if (item->details->pixbuf)
+ {
+ get_scaled_icon_size (item, NULL, &height);
+ y -= height;
+ }
+ have_editable = item->details->editable_text != NULL &&
+ item->details->editable_text[0] != '\0';
+ have_additional = item->details->additional_text != NULL && item->details->additional_text[0] != '\0';
+
+ editable_layout = NULL;
+ additional_layout = NULL;
+ if (have_editable)
+ {
+ editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text);
+ prepare_pango_layout_for_draw (item, editable_layout);
+ pango_layout_get_pixel_size (editable_layout, NULL, &editable_height);
+ if (y >= editable_height &&
+ have_additional)
+ {
+ prepare_pango_layout_for_draw (item, editable_layout);
+ additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
+ layout = additional_layout;
+ canvas_text = item->details->additional_text;
+ y -= editable_height + LABEL_LINE_SPACING;
+ }
+ else
+ {
+ layout = editable_layout;
+ canvas_text = item->details->editable_text;
+ }
+ }
+ else if (have_additional)
+ {
+ additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
+ prepare_pango_layout_for_draw (item, additional_layout);
+ layout = additional_layout;
+ canvas_text = item->details->additional_text;
+ }
+ else
+ {
+ return 0;
+ }
+
+ text_offset = 0;
+ if (have_editable)
+ {
+ pango_layout_index_to_pos (editable_layout, 0, &rect0);
+ text_offset = PANGO_PIXELS (rect0.x);
+ }
+ if (have_additional)
+ {
+ gint itmp;
+
+ pango_layout_index_to_pos (additional_layout, 0, &rect0);
+ itmp = PANGO_PIXELS (rect0.x);
+ if (itmp < text_offset)
+ {
+ text_offset = itmp;
+ }
+ }
+ pango_layout_index_to_pos (layout, 0, &rect0);
+ x += text_offset;
+ if (!pango_layout_xy_to_index (layout,
+ x * PANGO_SCALE,
+ y * PANGO_SCALE,
+ &index, NULL))
+ {
+ if (x < 0 || y < 0)
+ {
+ index = 0;
+ }
+ else
+ {
+ index = -1;
+ }
+ }
+ if (index == -1)
+ {
+ offset = g_utf8_strlen (canvas_text, -1);
+ }
+ else
+ {
+ offset = g_utf8_pointer_to_offset (canvas_text, canvas_text + index);
+ }
+ if (layout == additional_layout)
+ {
+ offset += g_utf8_strlen (item->details->editable_text, -1);
+ }
+
+ if (editable_layout != NULL)
+ {
+ g_object_unref (editable_layout);
+ }
+
+ if (additional_layout != NULL)
+ {
+ g_object_unref (additional_layout);
+ }
+
+ return offset;
}
static void
-nautilus_canvas_item_accessible_get_character_extents (AtkText *text,
- gint offset,
- gint *x,
- gint *y,
- gint *width,
- gint *height,
- AtkCoordType coords)
-{
- gint pos_x, pos_y;
- gint len, byte_offset;
- gint editable_height;
- gchar *canvas_text;
- NautilusCanvasItem *item;
- PangoLayout *layout, *editable_layout, *additional_layout;
- PangoRectangle rect;
- PangoRectangle rect0;
- gboolean have_editable;
- gint text_offset, pix_height;
-
- atk_component_get_extents (ATK_COMPONENT (text), &pos_x, &pos_y, NULL, NULL, coords);
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)));
-
- if (item->details->pixbuf) {
- get_scaled_icon_size (item, NULL, &pix_height);
- pos_y += pix_height;
- }
-
- have_editable = item->details->editable_text != NULL &&
- item->details->editable_text[0] != '\0';
- if (have_editable) {
- len = g_utf8_strlen (item->details->editable_text, -1);
- } else {
- len = 0;
- }
-
- editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text);
- additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
-
- if (offset < len) {
- canvas_text = item->details->editable_text;
- layout = editable_layout;
- } else {
- offset -= len;
- canvas_text = item->details->additional_text;
- layout = additional_layout;
- pos_y += LABEL_LINE_SPACING;
- if (have_editable) {
- pango_layout_get_pixel_size (editable_layout, NULL, &editable_height);
- pos_y += editable_height;
- }
- }
- byte_offset = g_utf8_offset_to_pointer (canvas_text, offset) - canvas_text;
- pango_layout_index_to_pos (layout, byte_offset, &rect);
- text_offset = 0;
- if (have_editable) {
- pango_layout_index_to_pos (editable_layout, 0, &rect0);
- text_offset = PANGO_PIXELS (rect0.x);
- }
- if (item->details->additional_text != NULL &&
- item->details->additional_text[0] != '\0') {
- gint itmp;
-
- pango_layout_index_to_pos (additional_layout, 0, &rect0);
- itmp = PANGO_PIXELS (rect0.x);
- if (itmp < text_offset) {
- text_offset = itmp;
- }
- }
-
- g_object_unref (editable_layout);
- g_object_unref (additional_layout);
-
- *x = pos_x + PANGO_PIXELS (rect.x) - text_offset;
- *y = pos_y + PANGO_PIXELS (rect.y);
- *width = PANGO_PIXELS (rect.width);
- *height = PANGO_PIXELS (rect.height);
+nautilus_canvas_item_accessible_get_character_extents (AtkText *text,
+ gint offset,
+ gint *x,
+ gint *y,
+ gint *width,
+ gint *height,
+ AtkCoordType coords)
+{
+ gint pos_x, pos_y;
+ gint len, byte_offset;
+ gint editable_height;
+ gchar *canvas_text;
+ NautilusCanvasItem *item;
+ PangoLayout *layout, *editable_layout, *additional_layout;
+ PangoRectangle rect;
+ PangoRectangle rect0;
+ gboolean have_editable;
+ gint text_offset, pix_height;
+
+ atk_component_get_extents (ATK_COMPONENT (text), &pos_x, &pos_y, NULL, NULL, coords);
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)));
+
+ if (item->details->pixbuf)
+ {
+ get_scaled_icon_size (item, NULL, &pix_height);
+ pos_y += pix_height;
+ }
+
+ have_editable = item->details->editable_text != NULL &&
+ item->details->editable_text[0] != '\0';
+ if (have_editable)
+ {
+ len = g_utf8_strlen (item->details->editable_text, -1);
+ }
+ else
+ {
+ len = 0;
+ }
+
+ editable_layout = get_label_layout (&item->details->editable_text_layout, item, item->details->editable_text);
+ additional_layout = get_label_layout (&item->details->additional_text_layout, item, item->details->additional_text);
+
+ if (offset < len)
+ {
+ canvas_text = item->details->editable_text;
+ layout = editable_layout;
+ }
+ else
+ {
+ offset -= len;
+ canvas_text = item->details->additional_text;
+ layout = additional_layout;
+ pos_y += LABEL_LINE_SPACING;
+ if (have_editable)
+ {
+ pango_layout_get_pixel_size (editable_layout, NULL, &editable_height);
+ pos_y += editable_height;
+ }
+ }
+ byte_offset = g_utf8_offset_to_pointer (canvas_text, offset) - canvas_text;
+ pango_layout_index_to_pos (layout, byte_offset, &rect);
+ text_offset = 0;
+ if (have_editable)
+ {
+ pango_layout_index_to_pos (editable_layout, 0, &rect0);
+ text_offset = PANGO_PIXELS (rect0.x);
+ }
+ if (item->details->additional_text != NULL &&
+ item->details->additional_text[0] != '\0')
+ {
+ gint itmp;
+
+ pango_layout_index_to_pos (additional_layout, 0, &rect0);
+ itmp = PANGO_PIXELS (rect0.x);
+ if (itmp < text_offset)
+ {
+ text_offset = itmp;
+ }
+ }
+
+ g_object_unref (editable_layout);
+ g_object_unref (additional_layout);
+
+ *x = pos_x + PANGO_PIXELS (rect.x) - text_offset;
+ *y = pos_y + PANGO_PIXELS (rect.y);
+ *width = PANGO_PIXELS (rect.width);
+ *height = PANGO_PIXELS (rect.height);
}
static void
nautilus_canvas_item_accessible_text_interface_init (AtkTextIface *iface)
{
- iface->get_text = eel_accessibility_text_get_text;
- iface->get_character_at_offset = eel_accessibility_text_get_character_at_offset;
- iface->get_text_before_offset = eel_accessibility_text_get_text_before_offset;
- iface->get_text_at_offset = eel_accessibility_text_get_text_at_offset;
- iface->get_text_after_offset = eel_accessibility_text_get_text_after_offset;
- iface->get_character_count = eel_accessibility_text_get_character_count;
- iface->get_character_extents = nautilus_canvas_item_accessible_get_character_extents;
- iface->get_offset_at_point = nautilus_canvas_item_accessible_get_offset_at_point;
+ iface->get_text = eel_accessibility_text_get_text;
+ iface->get_character_at_offset = eel_accessibility_text_get_character_at_offset;
+ iface->get_text_before_offset = eel_accessibility_text_get_text_before_offset;
+ iface->get_text_at_offset = eel_accessibility_text_get_text_at_offset;
+ iface->get_text_after_offset = eel_accessibility_text_get_text_after_offset;
+ iface->get_character_count = eel_accessibility_text_get_character_count;
+ iface->get_character_extents = nautilus_canvas_item_accessible_get_character_extents;
+ iface->get_offset_at_point = nautilus_canvas_item_accessible_get_offset_at_point;
}
static GType nautilus_canvas_item_accessible_get_type (void);
G_DEFINE_TYPE_WITH_CODE (NautilusCanvasItemAccessible,
- nautilus_canvas_item_accessible,
- eel_canvas_item_accessible_get_type (),
- G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE,
- nautilus_canvas_item_accessible_image_interface_init)
- G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT,
- nautilus_canvas_item_accessible_text_interface_init)
- G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION,
- nautilus_canvas_item_accessible_action_interface_init));
-
-static AtkStateSet*
+ nautilus_canvas_item_accessible,
+ eel_canvas_item_accessible_get_type (),
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_IMAGE,
+ nautilus_canvas_item_accessible_image_interface_init)
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_TEXT,
+ nautilus_canvas_item_accessible_text_interface_init)
+ G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION,
+ nautilus_canvas_item_accessible_action_interface_init));
+
+static AtkStateSet *
nautilus_canvas_item_accessible_ref_state_set (AtkObject *accessible)
{
- AtkStateSet *state_set;
- NautilusCanvasItem *item;
- NautilusCanvasContainer *container;
- GList *selection;
- gboolean one_item_selected;
-
- state_set = ATK_OBJECT_CLASS (nautilus_canvas_item_accessible_parent_class)->ref_state_set (accessible);
-
- item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
- if (!item) {
- atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
- return state_set;
- }
- container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
- if (item->details->is_highlighted_as_keyboard_focus) {
- atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
- } else if (!container->details->keyboard_focus) {
- selection = nautilus_canvas_container_get_selection (container);
- one_item_selected = (g_list_length (selection) == 1) &&
- item->details->is_highlighted_for_selection;
-
- if (one_item_selected) {
- atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
- }
+ AtkStateSet *state_set;
+ NautilusCanvasItem *item;
+ NautilusCanvasContainer *container;
+ GList *selection;
+ gboolean one_item_selected;
+
+ state_set = ATK_OBJECT_CLASS (nautilus_canvas_item_accessible_parent_class)->ref_state_set (accessible);
+
+ item = NAUTILUS_CANVAS_ITEM (atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)));
+ if (!item)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_DEFUNCT);
+ return state_set;
+ }
+ container = NAUTILUS_CANVAS_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+ if (item->details->is_highlighted_as_keyboard_focus)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
+ }
+ else if (!container->details->keyboard_focus)
+ {
+ selection = nautilus_canvas_container_get_selection (container);
+ one_item_selected = (g_list_length (selection) == 1) &&
+ item->details->is_highlighted_for_selection;
+
+ if (one_item_selected)
+ {
+ atk_state_set_add_state (state_set, ATK_STATE_FOCUSED);
+ }
- g_list_free (selection);
- }
+ g_list_free (selection);
+ }
- return state_set;
+ return state_set;
}
static void
nautilus_canvas_item_accessible_finalize (GObject *object)
{
- NautilusCanvasItemAccessiblePrivate *priv;
- int i;
+ NautilusCanvasItemAccessiblePrivate *priv;
+ int i;
- priv = GET_ACCESSIBLE_PRIV (object);
+ priv = GET_ACCESSIBLE_PRIV (object);
- for (i = 0; i < LAST_ACTION; i++) {
- g_free (priv->action_descriptions[i]);
- }
- g_free (priv->image_description);
- g_free (priv->description);
+ for (i = 0; i < LAST_ACTION; i++)
+ {
+ g_free (priv->action_descriptions[i]);
+ }
+ g_free (priv->image_description);
+ g_free (priv->description);
- G_OBJECT_CLASS (nautilus_canvas_item_accessible_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_canvas_item_accessible_parent_class)->finalize (object);
}
static void
nautilus_canvas_item_accessible_initialize (AtkObject *accessible,
- gpointer widget)
+ gpointer widget)
{
- ATK_OBJECT_CLASS (nautilus_canvas_item_accessible_parent_class)->initialize (accessible, widget);
+ ATK_OBJECT_CLASS (nautilus_canvas_item_accessible_parent_class)->initialize (accessible, widget);
- atk_object_set_role (accessible, ATK_ROLE_CANVAS);
+ atk_object_set_role (accessible, ATK_ROLE_CANVAS);
}
static void
nautilus_canvas_item_accessible_class_init (NautilusCanvasItemAccessibleClass *klass)
{
- AtkObjectClass *aclass = ATK_OBJECT_CLASS (klass);
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ AtkObjectClass *aclass = ATK_OBJECT_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
- oclass->finalize = nautilus_canvas_item_accessible_finalize;
+ oclass->finalize = nautilus_canvas_item_accessible_finalize;
- aclass->initialize = nautilus_canvas_item_accessible_initialize;
+ aclass->initialize = nautilus_canvas_item_accessible_initialize;
- aclass->get_name = nautilus_canvas_item_accessible_get_name;
- aclass->get_description = nautilus_canvas_item_accessible_get_description;
- aclass->get_parent = nautilus_canvas_item_accessible_get_parent;
- aclass->get_index_in_parent = nautilus_canvas_item_accessible_get_index_in_parent;
- aclass->ref_state_set = nautilus_canvas_item_accessible_ref_state_set;
+ aclass->get_name = nautilus_canvas_item_accessible_get_name;
+ aclass->get_description = nautilus_canvas_item_accessible_get_description;
+ aclass->get_parent = nautilus_canvas_item_accessible_get_parent;
+ aclass->get_index_in_parent = nautilus_canvas_item_accessible_get_index_in_parent;
+ aclass->ref_state_set = nautilus_canvas_item_accessible_ref_state_set;
- g_type_class_add_private (klass, sizeof (NautilusCanvasItemAccessiblePrivate));
+ g_type_class_add_private (klass, sizeof (NautilusCanvasItemAccessiblePrivate));
}
static void
nautilus_canvas_item_accessible_init (NautilusCanvasItemAccessible *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_canvas_item_accessible_get_type (),
- NautilusCanvasItemAccessiblePrivate);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_canvas_item_accessible_get_type (),
+ NautilusCanvasItemAccessiblePrivate);
}
/* dummy typedef */
-typedef AtkObjectFactory NautilusCanvasItemAccessibleFactory;
+typedef AtkObjectFactory NautilusCanvasItemAccessibleFactory;
typedef AtkObjectFactoryClass NautilusCanvasItemAccessibleFactoryClass;
G_DEFINE_TYPE (NautilusCanvasItemAccessibleFactory, nautilus_canvas_item_accessible_factory,
- ATK_TYPE_OBJECT_FACTORY);
+ ATK_TYPE_OBJECT_FACTORY);
static AtkObject *
nautilus_canvas_item_accessible_factory_create_accessible (GObject *for_object)
{
- AtkObject *accessible;
- NautilusCanvasItem *item;
- GString *item_text;
+ AtkObject *accessible;
+ NautilusCanvasItem *item;
+ GString *item_text;
- item = NAUTILUS_CANVAS_ITEM (for_object);
- g_assert (item != NULL);
+ item = NAUTILUS_CANVAS_ITEM (for_object);
+ g_assert (item != NULL);
- item_text = g_string_new (NULL);
- if (item->details->editable_text) {
- g_string_append (item_text, item->details->editable_text);
- }
- if (item->details->additional_text) {
- g_string_append (item_text, item->details->additional_text);
- }
+ item_text = g_string_new (NULL);
+ if (item->details->editable_text)
+ {
+ g_string_append (item_text, item->details->editable_text);
+ }
+ if (item->details->additional_text)
+ {
+ g_string_append (item_text, item->details->additional_text);
+ }
- item->details->text_util = gail_text_util_new ();
- gail_text_util_text_setup (item->details->text_util,
- item_text->str);
- g_string_free (item_text, TRUE);
+ item->details->text_util = gail_text_util_new ();
+ gail_text_util_text_setup (item->details->text_util,
+ item_text->str);
+ g_string_free (item_text, TRUE);
- accessible = g_object_new (nautilus_canvas_item_accessible_get_type (), NULL);
- atk_object_initialize (accessible, for_object);
+ accessible = g_object_new (nautilus_canvas_item_accessible_get_type (), NULL);
+ atk_object_initialize (accessible, for_object);
- return accessible;
+ return accessible;
}
static GType
nautilus_canvas_item_accessible_factory_get_accessible_type (void)
{
- return nautilus_canvas_item_accessible_get_type ();
+ return nautilus_canvas_item_accessible_get_type ();
}
static void
@@ -2629,6 +2917,6 @@ nautilus_canvas_item_accessible_factory_init (NautilusCanvasItemAccessibleFactor
static void
nautilus_canvas_item_accessible_factory_class_init (NautilusCanvasItemAccessibleFactoryClass *klass)
{
- klass->create_accessible = nautilus_canvas_item_accessible_factory_create_accessible;
- klass->get_accessible_type = nautilus_canvas_item_accessible_factory_get_accessible_type;
+ klass->create_accessible = nautilus_canvas_item_accessible_factory_create_accessible;
+ klass->get_accessible_type = nautilus_canvas_item_accessible_factory_get_accessible_type;
}
diff --git a/src/nautilus-canvas-view-container.c b/src/nautilus-canvas-view-container.c
index 53f29d8ea..4fb0abfcd 100644
--- a/src/nautilus-canvas-view-container.c
+++ b/src/nautilus-canvas-view-container.c
@@ -1,24 +1,23 @@
-
/* fm-icon-container.h - the container widget for file manager icons
-
- Copyright (C) 2002 Sun Microsystems, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Author: Michael Meeks <michael@ximian.com>
-*/
+ *
+ * Copyright (C) 2002 Sun Microsystems, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Michael Meeks <michael@ximian.com>
+ */
#include <config.h>
#include "nautilus-canvas-view-container.h"
@@ -38,88 +37,91 @@ static GQuark attribute_none_q;
static NautilusCanvasView *
get_canvas_view (NautilusCanvasContainer *container)
{
- /* Type unsafe comparison for performance */
- return ((NautilusCanvasViewContainer *)container)->view;
+ /* Type unsafe comparison for performance */
+ return ((NautilusCanvasViewContainer *) container)->view;
}
static NautilusIconInfo *
nautilus_canvas_view_container_get_icon_images (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data,
- int size,
- gboolean for_drag_accept)
+ NautilusCanvasIconData *data,
+ int size,
+ gboolean for_drag_accept)
{
- NautilusCanvasView *canvas_view;
- NautilusFile *file;
- NautilusFileIconFlags flags;
- NautilusIconInfo *icon_info;
- gint scale;
+ NautilusCanvasView *canvas_view;
+ NautilusFile *file;
+ NautilusFileIconFlags flags;
+ NautilusIconInfo *icon_info;
+ gint scale;
- file = (NautilusFile *) data;
+ file = (NautilusFile *) data;
- g_assert (NAUTILUS_IS_FILE (file));
- canvas_view = get_canvas_view (container);
- g_return_val_if_fail (canvas_view != NULL, NULL);
-
- flags = NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS |
- NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS;
+ g_assert (NAUTILUS_IS_FILE (file));
+ canvas_view = get_canvas_view (container);
+ g_return_val_if_fail (canvas_view != NULL, NULL);
- if (for_drag_accept) {
- flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
- }
+ flags = NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS |
+ NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS;
- scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas_view));
- icon_info = nautilus_file_get_icon (file, size, scale, flags);
+ if (for_drag_accept)
+ {
+ flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
+ }
- return icon_info;
+ scale = gtk_widget_get_scale_factor (GTK_WIDGET (canvas_view));
+ icon_info = nautilus_file_get_icon (file, size, scale, flags);
+
+ return icon_info;
}
static char *
nautilus_canvas_view_container_get_icon_description (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
+ NautilusCanvasIconData *data)
{
- NautilusFile *file;
- char *mime_type;
- const char *description;
+ NautilusFile *file;
+ char *mime_type;
+ const char *description;
- file = NAUTILUS_FILE (data);
- g_assert (NAUTILUS_IS_FILE (file));
+ file = NAUTILUS_FILE (data);
+ g_assert (NAUTILUS_IS_FILE (file));
- mime_type = nautilus_file_get_mime_type (file);
- description = g_content_type_get_description (mime_type);
- g_free (mime_type);
- return g_strdup (description);
+ mime_type = nautilus_file_get_mime_type (file);
+ description = g_content_type_get_description (mime_type);
+ g_free (mime_type);
+ return g_strdup (description);
}
static void
nautilus_canvas_view_container_prioritize_thumbnailing (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data)
+ NautilusCanvasIconData *data)
{
- NautilusFile *file;
- char *uri;
+ NautilusFile *file;
+ char *uri;
- file = (NautilusFile *) data;
+ file = (NautilusFile *) data;
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- if (nautilus_file_is_thumbnailing (file)) {
- uri = nautilus_file_get_uri (file);
- nautilus_thumbnail_prioritize (uri);
- g_free (uri);
- }
+ if (nautilus_file_is_thumbnailing (file))
+ {
+ uri = nautilus_file_get_uri (file);
+ nautilus_thumbnail_prioritize (uri);
+ g_free (uri);
+ }
}
static GQuark *
-get_quark_from_strv (gchar ** value)
+get_quark_from_strv (gchar **value)
{
- GQuark *quark;
- int i;
+ GQuark *quark;
+ int i;
- quark = g_new0 (GQuark, g_strv_length (value) + 1);
- for (i = 0; value[i] != NULL; ++i) {
- quark[i] = g_quark_from_string (value[i]);
- }
+ quark = g_new0 (GQuark, g_strv_length (value) + 1);
+ for (i = 0; value[i] != NULL; ++i)
+ {
+ quark[i] = g_quark_from_string (value[i]);
+ }
- return quark;
+ return quark;
}
/*
@@ -129,52 +131,53 @@ get_quark_from_strv (gchar ** value)
static GQuark *
nautilus_canvas_view_container_get_icon_text_attributes_from_preferences (void)
{
- GQuark *attributes;
- gchar **value;
-
- value = g_settings_get_strv (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
- attributes = get_quark_from_strv (value);
- g_strfreev (value);
-
- /* We don't need to sanity check the attributes list even though it came
- * from preferences.
- *
- * There are 2 ways that the values in the list could be bad.
- *
- * 1) The user picks "bad" values. "bad" values are those that result in
- * there being duplicate attributes in the list.
- *
- * 2) Value stored in GConf are tampered with. Its possible physically do
- * this by pulling the rug underneath GConf and manually editing its
- * config files. Its also possible to use a third party GConf key
- * editor and store garbage for the keys in question.
- *
- * Thankfully, the Nautilus preferences machinery deals with both of
- * these cases.
- *
- * In the first case, the preferences dialog widgetry prevents
- * duplicate attributes by making "bad" choices insensitive.
- *
- * In the second case, the preferences getter (and also the auto storage) for
- * string_array values are always valid members of the enumeration associated
- * with the preference.
- *
- * So, no more error checking on attributes is needed here and we can return
- * a the auto stored value.
- */
- return attributes;
+ GQuark *attributes;
+ gchar **value;
+
+ value = g_settings_get_strv (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
+ attributes = get_quark_from_strv (value);
+ g_strfreev (value);
+
+ /* We don't need to sanity check the attributes list even though it came
+ * from preferences.
+ *
+ * There are 2 ways that the values in the list could be bad.
+ *
+ * 1) The user picks "bad" values. "bad" values are those that result in
+ * there being duplicate attributes in the list.
+ *
+ * 2) Value stored in GConf are tampered with. Its possible physically do
+ * this by pulling the rug underneath GConf and manually editing its
+ * config files. Its also possible to use a third party GConf key
+ * editor and store garbage for the keys in question.
+ *
+ * Thankfully, the Nautilus preferences machinery deals with both of
+ * these cases.
+ *
+ * In the first case, the preferences dialog widgetry prevents
+ * duplicate attributes by making "bad" choices insensitive.
+ *
+ * In the second case, the preferences getter (and also the auto storage) for
+ * string_array values are always valid members of the enumeration associated
+ * with the preference.
+ *
+ * So, no more error checking on attributes is needed here and we can return
+ * a the auto stored value.
+ */
+ return attributes;
}
static int
quarkv_length (GQuark *attributes)
{
- int i;
- i = 0;
- while (attributes[i] != 0) {
- i++;
- }
- return i;
+ int i;
+ i = 0;
+ while (attributes[i] != 0)
+ {
+ i++;
+ }
+ return i;
}
/**
@@ -184,177 +187,189 @@ quarkv_length (GQuark *attributes)
* beneath an icon. The result is dependent on zoom level and possibly
* user configuration. Don't free the result.
* @view: NautilusCanvasView to query.
- *
+ *
**/
static GQuark *
nautilus_canvas_view_container_get_icon_text_attribute_names (NautilusCanvasContainer *container,
- int *len)
+ int *len)
{
- GQuark *attributes;
- int piece_count;
+ GQuark *attributes;
+ int piece_count;
- const int pieces_by_level[] = {
- 1, /* NAUTILUS_ZOOM_LEVEL_SMALL */
- 2, /* NAUTILUS_ZOOM_LEVEL_STANDARD */
- 3, /* NAUTILUS_ZOOM_LEVEL_LARGE */
- 3, /* NAUTILUS_ZOOM_LEVEL_LARGER */
- };
+ const int pieces_by_level[] =
+ {
+ 1, /* NAUTILUS_ZOOM_LEVEL_SMALL */
+ 2, /* NAUTILUS_ZOOM_LEVEL_STANDARD */
+ 3, /* NAUTILUS_ZOOM_LEVEL_LARGE */
+ 3, /* NAUTILUS_ZOOM_LEVEL_LARGER */
+ };
- piece_count = pieces_by_level[nautilus_canvas_container_get_zoom_level (container)];
+ piece_count = pieces_by_level[nautilus_canvas_container_get_zoom_level (container)];
- attributes = nautilus_canvas_view_container_get_icon_text_attributes_from_preferences ();
+ attributes = nautilus_canvas_view_container_get_icon_text_attributes_from_preferences ();
- *len = MIN (piece_count, quarkv_length (attributes));
+ *len = MIN (piece_count, quarkv_length (attributes));
- return attributes;
+ return attributes;
}
/* This callback returns the text, both the editable part, and the
* part below that is not editable.
*/
static void
-nautilus_canvas_view_container_get_icon_text (NautilusCanvasContainer *container,
- NautilusCanvasIconData *data,
- char **editable_text,
- char **additional_text,
- gboolean include_invisible)
+nautilus_canvas_view_container_get_icon_text (NautilusCanvasContainer *container,
+ NautilusCanvasIconData *data,
+ char **editable_text,
+ char **additional_text,
+ gboolean include_invisible)
{
- GQuark *attributes;
- char *text_array[4];
- int i, j, num_attributes;
- NautilusCanvasView *canvas_view;
- NautilusFile *file;
- gboolean use_additional;
-
- file = NAUTILUS_FILE (data);
-
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (editable_text != NULL);
- canvas_view = get_canvas_view (container);
- g_return_if_fail (canvas_view != NULL);
-
- use_additional = (additional_text != NULL);
-
- /* Strip the suffix for nautilus object xml files. */
- *editable_text = nautilus_file_get_display_name (file);
-
- if (!use_additional) {
- return;
- }
-
- if (nautilus_file_is_nautilus_link (file)) {
- /* Don't show the normal extra information for desktop files,
- * it doesn't make sense. */
- *additional_text = NULL;
- return;
- }
-
- /* Find out what attributes go below each icon. */
- attributes = nautilus_canvas_view_container_get_icon_text_attribute_names (container,
- &num_attributes);
-
- /* Get the attributes. */
- j = 0;
- for (i = 0; i < num_attributes; ++i) {
- char *text;
- if (attributes[i] == attribute_none_q) {
- continue;
- }
- text = nautilus_file_get_string_attribute_q (file, attributes[i]);
- if (text == NULL) {
- continue;
- }
- text_array[j++] = text;
- }
- text_array[j] = NULL;
-
- /* Return them. */
- if (j == 0) {
- *additional_text = NULL;
- } else if (j == 1) {
- /* Only one item, avoid the strdup + free */
- *additional_text = text_array[0];
- } else {
- *additional_text = g_strjoinv ("\n", text_array);
-
- for (i = 0; i < j; i++) {
- g_free (text_array[i]);
- }
- }
+ GQuark *attributes;
+ char *text_array[4];
+ int i, j, num_attributes;
+ NautilusCanvasView *canvas_view;
+ NautilusFile *file;
+ gboolean use_additional;
+
+ file = NAUTILUS_FILE (data);
+
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (editable_text != NULL);
+ canvas_view = get_canvas_view (container);
+ g_return_if_fail (canvas_view != NULL);
+
+ use_additional = (additional_text != NULL);
+
+ /* Strip the suffix for nautilus object xml files. */
+ *editable_text = nautilus_file_get_display_name (file);
+
+ if (!use_additional)
+ {
+ return;
+ }
+
+ if (nautilus_file_is_nautilus_link (file))
+ {
+ /* Don't show the normal extra information for desktop files,
+ * it doesn't make sense. */
+ *additional_text = NULL;
+ return;
+ }
+
+ /* Find out what attributes go below each icon. */
+ attributes = nautilus_canvas_view_container_get_icon_text_attribute_names (container,
+ &num_attributes);
+
+ /* Get the attributes. */
+ j = 0;
+ for (i = 0; i < num_attributes; ++i)
+ {
+ char *text;
+ if (attributes[i] == attribute_none_q)
+ {
+ continue;
+ }
+ text = nautilus_file_get_string_attribute_q (file, attributes[i]);
+ if (text == NULL)
+ {
+ continue;
+ }
+ text_array[j++] = text;
+ }
+ text_array[j] = NULL;
+
+ /* Return them. */
+ if (j == 0)
+ {
+ *additional_text = NULL;
+ }
+ else if (j == 1)
+ {
+ /* Only one item, avoid the strdup + free */
+ *additional_text = text_array[0];
+ }
+ else
+ {
+ *additional_text = g_strjoinv ("\n", text_array);
+
+ for (i = 0; i < j; i++)
+ {
+ g_free (text_array[i]);
+ }
+ }
}
static int
nautilus_canvas_view_container_compare_icons (NautilusCanvasContainer *container,
- NautilusCanvasIconData *icon_a,
- NautilusCanvasIconData *icon_b)
+ NautilusCanvasIconData *icon_a,
+ NautilusCanvasIconData *icon_b)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
- canvas_view = get_canvas_view (container);
- g_return_val_if_fail (canvas_view != NULL, 0);
+ canvas_view = get_canvas_view (container);
+ g_return_val_if_fail (canvas_view != NULL, 0);
- /* Type unsafe comparisons for performance */
- return nautilus_canvas_view_compare_files (canvas_view,
- (NautilusFile *)icon_a,
- (NautilusFile *)icon_b);
+ /* Type unsafe comparisons for performance */
+ return nautilus_canvas_view_compare_files (canvas_view,
+ (NautilusFile *) icon_a,
+ (NautilusFile *) icon_b);
}
static int
nautilus_canvas_view_container_compare_icons_by_name (NautilusCanvasContainer *container,
- NautilusCanvasIconData *icon_a,
- NautilusCanvasIconData *icon_b)
+ NautilusCanvasIconData *icon_a,
+ NautilusCanvasIconData *icon_b)
{
- return nautilus_file_compare_for_sort
- (NAUTILUS_FILE (icon_a),
- NAUTILUS_FILE (icon_b),
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- FALSE, FALSE);
+ return nautilus_file_compare_for_sort
+ (NAUTILUS_FILE (icon_a),
+ NAUTILUS_FILE (icon_b),
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ FALSE, FALSE);
}
static void
nautilus_canvas_view_container_class_init (NautilusCanvasViewContainerClass *klass)
{
- NautilusCanvasContainerClass *ic_class;
+ NautilusCanvasContainerClass *ic_class;
- ic_class = &klass->parent_class;
+ ic_class = &klass->parent_class;
- attribute_none_q = g_quark_from_static_string ("none");
-
- ic_class->get_icon_text = nautilus_canvas_view_container_get_icon_text;
- ic_class->get_icon_images = nautilus_canvas_view_container_get_icon_images;
- ic_class->get_icon_description = nautilus_canvas_view_container_get_icon_description;
- ic_class->prioritize_thumbnailing = nautilus_canvas_view_container_prioritize_thumbnailing;
+ attribute_none_q = g_quark_from_static_string ("none");
- ic_class->compare_icons = nautilus_canvas_view_container_compare_icons;
- ic_class->compare_icons_by_name = nautilus_canvas_view_container_compare_icons_by_name;
+ ic_class->get_icon_text = nautilus_canvas_view_container_get_icon_text;
+ ic_class->get_icon_images = nautilus_canvas_view_container_get_icon_images;
+ ic_class->get_icon_description = nautilus_canvas_view_container_get_icon_description;
+ ic_class->prioritize_thumbnailing = nautilus_canvas_view_container_prioritize_thumbnailing;
+
+ ic_class->compare_icons = nautilus_canvas_view_container_compare_icons;
+ ic_class->compare_icons_by_name = nautilus_canvas_view_container_compare_icons_by_name;
}
static void
nautilus_canvas_view_container_init (NautilusCanvasViewContainer *canvas_container)
{
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (canvas_container)),
- GTK_STYLE_CLASS_VIEW);
-
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (canvas_container)),
+ GTK_STYLE_CLASS_VIEW);
}
NautilusCanvasContainer *
-nautilus_canvas_view_container_construct (NautilusCanvasViewContainer *canvas_container, NautilusCanvasView *view)
+nautilus_canvas_view_container_construct (NautilusCanvasViewContainer *canvas_container,
+ NautilusCanvasView *view)
{
- AtkObject *atk_obj;
+ AtkObject *atk_obj;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
- canvas_container->view = view;
- atk_obj = gtk_widget_get_accessible (GTK_WIDGET (canvas_container));
- atk_object_set_name (atk_obj, _("Icon View"));
+ canvas_container->view = view;
+ atk_obj = gtk_widget_get_accessible (GTK_WIDGET (canvas_container));
+ atk_object_set_name (atk_obj, _("Icon View"));
- return NAUTILUS_CANVAS_CONTAINER (canvas_container);
+ return NAUTILUS_CANVAS_CONTAINER (canvas_container);
}
NautilusCanvasContainer *
nautilus_canvas_view_container_new (NautilusCanvasView *view)
{
- return nautilus_canvas_view_container_construct
- (g_object_new (NAUTILUS_TYPE_CANVAS_VIEW_CONTAINER, NULL),
- view);
+ return nautilus_canvas_view_container_construct
+ (g_object_new (NAUTILUS_TYPE_CANVAS_VIEW_CONTAINER, NULL),
+ view);
}
diff --git a/src/nautilus-canvas-view.c b/src/nautilus-canvas-view.c
index 2867358a4..28233d58f 100644
--- a/src/nautilus-canvas-view.c
+++ b/src/nautilus-canvas-view.c
@@ -1,24 +1,23 @@
-
/* fm-canvas-view.c - implementation of canvas view of directory.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
-*/
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
@@ -57,232 +56,243 @@
#include <sys/wait.h>
#include <unistd.h>
-enum
+enum
{
- PROP_SUPPORTS_AUTO_LAYOUT = 1,
- PROP_SUPPORTS_SCALING,
- PROP_SUPPORTS_KEEP_ALIGNED,
- PROP_SUPPORTS_MANUAL_LAYOUT,
- NUM_PROPERTIES
+ PROP_SUPPORTS_AUTO_LAYOUT = 1,
+ PROP_SUPPORTS_SCALING,
+ PROP_SUPPORTS_KEEP_ALIGNED,
+ PROP_SUPPORTS_MANUAL_LAYOUT,
+ NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
-typedef gboolean (* SortCriterionMatchFunc) (NautilusFile *file);
+typedef gboolean (*SortCriterionMatchFunc) (NautilusFile *file);
-typedef struct {
- const NautilusFileSortType sort_type;
- const char *metadata_text;
- const char *action_target_name;
- const gboolean reverse_order;
- SortCriterionMatchFunc match_func;
+typedef struct
+{
+ const NautilusFileSortType sort_type;
+ const char *metadata_text;
+ const char *action_target_name;
+ const gboolean reverse_order;
+ SortCriterionMatchFunc match_func;
} SortCriterion;
-typedef enum {
- MENU_ITEM_TYPE_STANDARD,
- MENU_ITEM_TYPE_CHECK,
- MENU_ITEM_TYPE_RADIO,
- MENU_ITEM_TYPE_TREE
+typedef enum
+{
+ MENU_ITEM_TYPE_STANDARD,
+ MENU_ITEM_TYPE_CHECK,
+ MENU_ITEM_TYPE_RADIO,
+ MENU_ITEM_TYPE_TREE
} MenuItemType;
struct NautilusCanvasViewDetails
{
- GList *icons_not_positioned;
+ GList *icons_not_positioned;
- guint react_to_canvas_change_idle_id;
+ guint react_to_canvas_change_idle_id;
- const SortCriterion *sort;
+ const SortCriterion *sort;
- gulong clipboard_handler_id;
+ gulong clipboard_handler_id;
- GtkWidget *canvas_container;
+ GtkWidget *canvas_container;
- gboolean supports_auto_layout;
- gboolean supports_manual_layout;
- gboolean supports_scaling;
- gboolean supports_keep_aligned;
+ gboolean supports_auto_layout;
+ gboolean supports_manual_layout;
+ gboolean supports_scaling;
+ gboolean supports_keep_aligned;
- GIcon *icon;
+ GIcon *icon;
};
/* Note that the first item in this list is the default sort,
* and that the items show up in the menu in the order they
* appear in this list.
*/
-static const SortCriterion sort_criteria[] = {
- {
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- "name",
- "name",
- FALSE
- },
- {
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- "name",
- "name-desc",
- TRUE
- },
- {
- NAUTILUS_FILE_SORT_BY_SIZE,
- "size",
- "size",
- TRUE
- },
- {
- NAUTILUS_FILE_SORT_BY_TYPE,
- "type",
- "type",
- FALSE
- },
- {
- NAUTILUS_FILE_SORT_BY_MTIME,
- "modification date",
- "modification-date",
- FALSE
- },
- {
- NAUTILUS_FILE_SORT_BY_MTIME,
- "modification date",
- "modification-date-desc",
- TRUE
- },
- {
- NAUTILUS_FILE_SORT_BY_ATIME,
- "access date",
- "access-date",
- FALSE
- },
- {
- NAUTILUS_FILE_SORT_BY_ATIME,
- "access date",
- "access-date-desc",
- TRUE
- },
- {
- NAUTILUS_FILE_SORT_BY_TRASHED_TIME,
- "trashed",
- "trash-time",
- TRUE,
- nautilus_file_is_in_trash
- },
- {
- NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE,
- NULL,
- "search-relevance",
- TRUE,
- nautilus_file_is_in_search
- }
+static const SortCriterion sort_criteria[] =
+{
+ {
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ "name",
+ "name",
+ FALSE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ "name",
+ "name-desc",
+ TRUE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_SIZE,
+ "size",
+ "size",
+ TRUE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_TYPE,
+ "type",
+ "type",
+ FALSE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ "modification date",
+ "modification-date",
+ FALSE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ "modification date",
+ "modification-date-desc",
+ TRUE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_ATIME,
+ "access date",
+ "access-date",
+ FALSE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_ATIME,
+ "access date",
+ "access-date-desc",
+ TRUE
+},
+ {
+ NAUTILUS_FILE_SORT_BY_TRASHED_TIME,
+ "trashed",
+ "trash-time",
+ TRUE,
+ nautilus_file_is_in_trash
+},
+ {
+ NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE,
+ NULL,
+ "search-relevance",
+ TRUE,
+ nautilus_file_is_in_search
+}
};
-static void nautilus_canvas_view_set_directory_sort_by (NautilusCanvasView *canvas_view,
- NautilusFile *file,
- const SortCriterion *sort);
-static void nautilus_canvas_view_update_click_mode (NautilusCanvasView *canvas_view);
-static gboolean nautilus_canvas_view_supports_scaling (NautilusCanvasView *canvas_view);
-static void nautilus_canvas_view_reveal_selection (NautilusFilesView *view);
-static const SortCriterion *get_sort_criterion_by_metadata_text (const char *metadata_text,
- gboolean reversed);
-static const SortCriterion *get_sort_criterion_by_sort_type (NautilusFileSortType sort_type,
- gboolean reversed);
-static void switch_to_manual_layout (NautilusCanvasView *view);
-static const SortCriterion *get_default_sort_order (NautilusFile *file);
-static void nautilus_canvas_view_clear (NautilusFilesView *view);
+static void nautilus_canvas_view_set_directory_sort_by (NautilusCanvasView *canvas_view,
+ NautilusFile *file,
+ const SortCriterion *sort);
+static void nautilus_canvas_view_update_click_mode (NautilusCanvasView *canvas_view);
+static gboolean nautilus_canvas_view_supports_scaling (NautilusCanvasView *canvas_view);
+static void nautilus_canvas_view_reveal_selection (NautilusFilesView *view);
+static const SortCriterion *get_sort_criterion_by_metadata_text (const char *metadata_text,
+ gboolean reversed);
+static const SortCriterion *get_sort_criterion_by_sort_type (NautilusFileSortType sort_type,
+ gboolean reversed);
+static void switch_to_manual_layout (NautilusCanvasView *view);
+static const SortCriterion *get_default_sort_order (NautilusFile *file);
+static void nautilus_canvas_view_clear (NautilusFilesView *view);
G_DEFINE_TYPE (NautilusCanvasView, nautilus_canvas_view, NAUTILUS_TYPE_FILES_VIEW);
static void
nautilus_canvas_view_destroy (GtkWidget *object)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
- canvas_view = NAUTILUS_CANVAS_VIEW (object);
+ canvas_view = NAUTILUS_CANVAS_VIEW (object);
- nautilus_canvas_view_clear (NAUTILUS_FILES_VIEW (object));
+ nautilus_canvas_view_clear (NAUTILUS_FILES_VIEW (object));
- if (canvas_view->details->react_to_canvas_change_idle_id != 0) {
- g_source_remove (canvas_view->details->react_to_canvas_change_idle_id);
- canvas_view->details->react_to_canvas_change_idle_id = 0;
- }
+ if (canvas_view->details->react_to_canvas_change_idle_id != 0)
+ {
+ g_source_remove (canvas_view->details->react_to_canvas_change_idle_id);
+ canvas_view->details->react_to_canvas_change_idle_id = 0;
+ }
- if (canvas_view->details->clipboard_handler_id != 0) {
- g_signal_handler_disconnect (nautilus_clipboard_monitor_get (),
- canvas_view->details->clipboard_handler_id);
- canvas_view->details->clipboard_handler_id = 0;
- }
+ if (canvas_view->details->clipboard_handler_id != 0)
+ {
+ g_signal_handler_disconnect (nautilus_clipboard_monitor_get (),
+ canvas_view->details->clipboard_handler_id);
+ canvas_view->details->clipboard_handler_id = 0;
+ }
- if (canvas_view->details->icons_not_positioned) {
- nautilus_file_list_free (canvas_view->details->icons_not_positioned);
- canvas_view->details->icons_not_positioned = NULL;
- }
+ if (canvas_view->details->icons_not_positioned)
+ {
+ nautilus_file_list_free (canvas_view->details->icons_not_positioned);
+ canvas_view->details->icons_not_positioned = NULL;
+ }
- GTK_WIDGET_CLASS (nautilus_canvas_view_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (nautilus_canvas_view_parent_class)->destroy (object);
}
static NautilusCanvasContainer *
get_canvas_container (NautilusCanvasView *canvas_view)
{
- return NAUTILUS_CANVAS_CONTAINER (canvas_view->details->canvas_container);
+ return NAUTILUS_CANVAS_CONTAINER (canvas_view->details->canvas_container);
}
NautilusCanvasContainer *
nautilus_canvas_view_get_canvas_container (NautilusCanvasView *canvas_view)
{
- return get_canvas_container (canvas_view);
+ return get_canvas_container (canvas_view);
}
static gboolean
nautilus_canvas_view_supports_manual_layout (NautilusCanvasView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return view->details->supports_manual_layout;
+ return view->details->supports_manual_layout;
}
static gboolean
get_stored_icon_position_callback (NautilusCanvasContainer *container,
- NautilusFile *file,
- NautilusCanvasPosition *position,
- NautilusCanvasView *canvas_view)
-{
- char *position_string, *scale_string;
- gboolean position_good;
- char c;
-
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (position != NULL);
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
-
- if (!nautilus_canvas_view_supports_manual_layout (canvas_view)) {
- return FALSE;
- }
-
- /* Get the current position of this canvas from the metadata. */
- position_string = nautilus_file_get_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_POSITION, "");
- position_good = sscanf
- (position_string, " %d , %d %c",
- &position->x, &position->y, &c) == 2;
- g_free (position_string);
-
- /* If it is the desktop directory, maybe the gnome-libs metadata has information about it */
-
- /* Disable scaling if not on the desktop */
- if (nautilus_canvas_view_supports_scaling (canvas_view)) {
- /* Get the scale of the canvas from the metadata. */
- scale_string = nautilus_file_get_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_SCALE, "1");
- position->scale = g_ascii_strtod (scale_string, NULL);
- if (errno != 0) {
- position->scale = 1.0;
- }
-
- g_free (scale_string);
- } else {
- position->scale = 1.0;
- }
-
- return position_good;
+ NautilusFile *file,
+ NautilusCanvasPosition *position,
+ NautilusCanvasView *canvas_view)
+{
+ char *position_string, *scale_string;
+ gboolean position_good;
+ char c;
+
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (position != NULL);
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+
+ if (!nautilus_canvas_view_supports_manual_layout (canvas_view))
+ {
+ return FALSE;
+ }
+
+ /* Get the current position of this canvas from the metadata. */
+ position_string = nautilus_file_get_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_POSITION, "");
+ position_good = sscanf
+ (position_string, " %d , %d %c",
+ &position->x, &position->y, &c) == 2;
+ g_free (position_string);
+
+ /* If it is the desktop directory, maybe the gnome-libs metadata has information about it */
+
+ /* Disable scaling if not on the desktop */
+ if (nautilus_canvas_view_supports_scaling (canvas_view))
+ {
+ /* Get the scale of the canvas from the metadata. */
+ scale_string = nautilus_file_get_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_SCALE, "1");
+ position->scale = g_ascii_strtod (scale_string, NULL);
+ if (errno != 0)
+ {
+ position->scale = 1.0;
+ }
+
+ g_free (scale_string);
+ }
+ else
+ {
+ position->scale = 1.0;
+ }
+
+ return position_good;
}
static void
@@ -290,910 +300,969 @@ update_sort_criterion (NautilusCanvasView *canvas_view,
const SortCriterion *sort,
gboolean set_metadata)
{
- NautilusFile *file;
- const SortCriterion *overrided_sort_criterion;
-
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
-
- /* Make sure we use the default one and not one that the user used previously
- * of the change to not allow sorting on search and recent, or the
- * case that the user or some app modified directly the metadata */
- if (nautilus_file_is_in_search (file) || nautilus_file_is_in_recent (file)) {
- overrided_sort_criterion = get_default_sort_order (file);
- } else if (sort != NULL && canvas_view->details->sort != sort) {
- overrided_sort_criterion = sort;
- if (set_metadata) {
- /* Store the new sort setting. */
- nautilus_canvas_view_set_directory_sort_by (canvas_view,
- file,
- sort);
- }
- } else {
- return;
+ NautilusFile *file;
+ const SortCriterion *overrided_sort_criterion;
+
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
+
+ /* Make sure we use the default one and not one that the user used previously
+ * of the change to not allow sorting on search and recent, or the
+ * case that the user or some app modified directly the metadata */
+ if (nautilus_file_is_in_search (file) || nautilus_file_is_in_recent (file))
+ {
+ overrided_sort_criterion = get_default_sort_order (file);
+ }
+ else if (sort != NULL && canvas_view->details->sort != sort)
+ {
+ overrided_sort_criterion = sort;
+ if (set_metadata)
+ {
+ /* Store the new sort setting. */
+ nautilus_canvas_view_set_directory_sort_by (canvas_view,
+ file,
+ sort);
}
+ }
+ else
+ {
+ return;
+ }
- canvas_view->details->sort = overrided_sort_criterion;
+ canvas_view->details->sort = overrided_sort_criterion;
}
void
nautilus_canvas_view_clean_up_by_name (NautilusCanvasView *canvas_view)
{
- NautilusCanvasContainer *canvas_container;
+ NautilusCanvasContainer *canvas_container;
- canvas_container = get_canvas_container (canvas_view);
+ canvas_container = get_canvas_container (canvas_view);
- update_sort_criterion (canvas_view, &sort_criteria[0], FALSE);
+ update_sort_criterion (canvas_view, &sort_criteria[0], FALSE);
- nautilus_canvas_container_sort (canvas_container);
- nautilus_canvas_container_freeze_icon_positions (canvas_container);
+ nautilus_canvas_container_sort (canvas_container);
+ nautilus_canvas_container_freeze_icon_positions (canvas_container);
}
static gboolean
nautilus_canvas_view_using_auto_layout (NautilusCanvasView *canvas_view)
{
- return nautilus_canvas_container_is_auto_layout
- (get_canvas_container (canvas_view));
+ return nautilus_canvas_container_is_auto_layout
+ (get_canvas_container (canvas_view));
}
static void
-list_covers (NautilusCanvasIconData *data, gpointer callback_data)
+list_covers (NautilusCanvasIconData *data,
+ gpointer callback_data)
{
- GSList **file_list;
+ GSList **file_list;
- file_list = callback_data;
+ file_list = callback_data;
- *file_list = g_slist_prepend (*file_list, data);
+ *file_list = g_slist_prepend (*file_list, data);
}
static void
-unref_cover (NautilusCanvasIconData *data, gpointer callback_data)
+unref_cover (NautilusCanvasIconData *data,
+ gpointer callback_data)
{
- nautilus_file_unref (NAUTILUS_FILE (data));
+ nautilus_file_unref (NAUTILUS_FILE (data));
}
static void
nautilus_canvas_view_clear (NautilusFilesView *view)
{
- NautilusCanvasContainer *canvas_container;
- GSList *file_list;
-
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ NautilusCanvasContainer *canvas_container;
+ GSList *file_list;
+
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
- if (!canvas_container)
- return;
+ canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
+ if (!canvas_container)
+ {
+ return;
+ }
- /* Clear away the existing icons. */
- file_list = NULL;
- nautilus_canvas_container_for_each (canvas_container, list_covers, &file_list);
- nautilus_canvas_container_clear (canvas_container);
- g_slist_foreach (file_list, (GFunc)unref_cover, NULL);
- g_slist_free (file_list);
+ /* Clear away the existing icons. */
+ file_list = NULL;
+ nautilus_canvas_container_for_each (canvas_container, list_covers, &file_list);
+ nautilus_canvas_container_clear (canvas_container);
+ g_slist_foreach (file_list, (GFunc) unref_cover, NULL);
+ g_slist_free (file_list);
}
static void
-nautilus_canvas_view_remove_file (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
-{
- NautilusCanvasView *canvas_view;
-
- /* This used to assert that 'directory == nautilus_files_view_get_model (view)', but that
- * resulted in a lot of crash reports (bug #352592). I don't see how that trace happens.
- * It seems that somehow we get a files_changed event sent to the view from a directory
- * that isn't the model, but the code disables the monitor and signal callback handlers when
- * changing directories. Maybe we can get some more information when this happens.
- * Further discussion in bug #368178.
- */
- if (directory != nautilus_files_view_get_model (view)) {
- char *file_uri, *dir_uri, *model_uri;
- file_uri = nautilus_file_get_uri (file);
- dir_uri = nautilus_directory_get_uri (directory);
- model_uri = nautilus_directory_get_uri (nautilus_files_view_get_model (view));
- g_warning ("nautilus_canvas_view_remove_file() - directory not canvas view model, shouldn't happen.\n"
- "file: %p:%s, dir: %p:%s, model: %p:%s, view loading: %d\n"
- "If you see this, please add this info to http://bugzilla.gnome.org/show_bug.cgi?id=368178",
- file, file_uri, directory, dir_uri, nautilus_files_view_get_model (view), model_uri, nautilus_files_view_get_loading (view));
- g_free (file_uri);
- g_free (dir_uri);
- g_free (model_uri);
- }
-
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
-
- if (nautilus_canvas_container_remove (get_canvas_container (canvas_view),
- NAUTILUS_CANVAS_ICON_DATA (file))) {
- nautilus_file_unref (file);
- }
+nautilus_canvas_view_remove_file (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
+{
+ NautilusCanvasView *canvas_view;
+
+ /* This used to assert that 'directory == nautilus_files_view_get_model (view)', but that
+ * resulted in a lot of crash reports (bug #352592). I don't see how that trace happens.
+ * It seems that somehow we get a files_changed event sent to the view from a directory
+ * that isn't the model, but the code disables the monitor and signal callback handlers when
+ * changing directories. Maybe we can get some more information when this happens.
+ * Further discussion in bug #368178.
+ */
+ if (directory != nautilus_files_view_get_model (view))
+ {
+ char *file_uri, *dir_uri, *model_uri;
+ file_uri = nautilus_file_get_uri (file);
+ dir_uri = nautilus_directory_get_uri (directory);
+ model_uri = nautilus_directory_get_uri (nautilus_files_view_get_model (view));
+ g_warning ("nautilus_canvas_view_remove_file() - directory not canvas view model, shouldn't happen.\n"
+ "file: %p:%s, dir: %p:%s, model: %p:%s, view loading: %d\n"
+ "If you see this, please add this info to http://bugzilla.gnome.org/show_bug.cgi?id=368178",
+ file, file_uri, directory, dir_uri, nautilus_files_view_get_model (view), model_uri, nautilus_files_view_get_loading (view));
+ g_free (file_uri);
+ g_free (dir_uri);
+ g_free (model_uri);
+ }
+
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
+
+ if (nautilus_canvas_container_remove (get_canvas_container (canvas_view),
+ NAUTILUS_CANVAS_ICON_DATA (file)))
+ {
+ nautilus_file_unref (file);
+ }
}
static void
-nautilus_canvas_view_add_file (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
+nautilus_canvas_view_add_file (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
- NautilusCanvasView *canvas_view;
- NautilusCanvasContainer *canvas_container;
+ NautilusCanvasView *canvas_view;
+ NautilusCanvasContainer *canvas_container;
- g_assert (directory == nautilus_files_view_get_model (view));
-
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
- canvas_container = get_canvas_container (canvas_view);
+ g_assert (directory == nautilus_files_view_get_model (view));
- /* Reset scroll region for the first canvas added when loading a directory. */
- if (nautilus_files_view_get_loading (view) && nautilus_canvas_container_is_empty (canvas_container)) {
- nautilus_canvas_container_reset_scroll_region (canvas_container);
- }
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
+ canvas_container = get_canvas_container (canvas_view);
- if (nautilus_canvas_container_add (canvas_container,
- NAUTILUS_CANVAS_ICON_DATA (file))) {
- nautilus_file_ref (file);
- }
+ /* Reset scroll region for the first canvas added when loading a directory. */
+ if (nautilus_files_view_get_loading (view) && nautilus_canvas_container_is_empty (canvas_container))
+ {
+ nautilus_canvas_container_reset_scroll_region (canvas_container);
+ }
+
+ if (nautilus_canvas_container_add (canvas_container,
+ NAUTILUS_CANVAS_ICON_DATA (file)))
+ {
+ nautilus_file_ref (file);
+ }
}
static void
-nautilus_canvas_view_file_changed (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
+nautilus_canvas_view_file_changed (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
+
+ g_assert (directory == nautilus_files_view_get_model (view));
- g_assert (directory == nautilus_files_view_get_model (view));
-
- g_return_if_fail (view != NULL);
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
+ g_return_if_fail (view != NULL);
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
- nautilus_canvas_container_request_update
- (get_canvas_container (canvas_view),
- NAUTILUS_CANVAS_ICON_DATA (file));
+ nautilus_canvas_container_request_update
+ (get_canvas_container (canvas_view),
+ NAUTILUS_CANVAS_ICON_DATA (file));
}
static gboolean
nautilus_canvas_view_supports_auto_layout (NautilusCanvasView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return view->details->supports_auto_layout;
+ return view->details->supports_auto_layout;
}
static gboolean
nautilus_canvas_view_supports_scaling (NautilusCanvasView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return view->details->supports_scaling;
+ return view->details->supports_scaling;
}
static gboolean
nautilus_canvas_view_supports_keep_aligned (NautilusCanvasView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return view->details->supports_keep_aligned;
+ return view->details->supports_keep_aligned;
}
static const SortCriterion *
nautilus_canvas_view_get_directory_sort_by (NautilusCanvasView *canvas_view,
- NautilusFile *file)
+ NautilusFile *file)
{
- const SortCriterion *default_sort;
- g_autofree char *sort_by = NULL;
- gboolean reversed;
+ const SortCriterion *default_sort;
+ g_autofree char *sort_by = NULL;
+ gboolean reversed;
- if (!nautilus_canvas_view_supports_auto_layout (canvas_view)) {
- return get_sort_criterion_by_metadata_text ("name", FALSE);
- }
+ if (!nautilus_canvas_view_supports_auto_layout (canvas_view))
+ {
+ return get_sort_criterion_by_metadata_text ("name", FALSE);
+ }
- default_sort = get_default_sort_order (file);
- g_return_val_if_fail (default_sort != NULL, NULL);
+ default_sort = get_default_sort_order (file);
+ g_return_val_if_fail (default_sort != NULL, NULL);
- sort_by = nautilus_file_get_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY,
- default_sort->metadata_text);
+ sort_by = nautilus_file_get_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY,
+ default_sort->metadata_text);
- reversed = nautilus_file_get_boolean_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
- default_sort->reverse_order);
+ reversed = nautilus_file_get_boolean_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
+ default_sort->reverse_order);
- return get_sort_criterion_by_metadata_text (sort_by, reversed);
+ return get_sort_criterion_by_metadata_text (sort_by, reversed);
}
static const SortCriterion *
get_default_sort_order (NautilusFile *file)
{
- NautilusFileSortType sort_type, default_sort_order;
- gboolean reversed;
+ NautilusFileSortType sort_type, default_sort_order;
+ gboolean reversed;
- default_sort_order = g_settings_get_enum (nautilus_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
- reversed = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
+ default_sort_order = g_settings_get_enum (nautilus_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
+ reversed = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
- /* If this is a special folder (e.g. search or recent), override the sort
- * order and reversed flag with values appropriate for the folder */
- sort_type = nautilus_file_get_default_sort_type (file, &reversed);
+ /* If this is a special folder (e.g. search or recent), override the sort
+ * order and reversed flag with values appropriate for the folder */
+ sort_type = nautilus_file_get_default_sort_type (file, &reversed);
- if (sort_type == NAUTILUS_FILE_SORT_NONE) {
- sort_type = CLAMP (default_sort_order,
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- NAUTILUS_FILE_SORT_BY_ATIME);
- }
+ if (sort_type == NAUTILUS_FILE_SORT_NONE)
+ {
+ sort_type = CLAMP (default_sort_order,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ NAUTILUS_FILE_SORT_BY_ATIME);
+ }
- return get_sort_criterion_by_sort_type (sort_type, reversed);
+ return get_sort_criterion_by_sort_type (sort_type, reversed);
}
static void
-nautilus_canvas_view_set_directory_sort_by (NautilusCanvasView *canvas_view,
- NautilusFile *file,
+nautilus_canvas_view_set_directory_sort_by (NautilusCanvasView *canvas_view,
+ NautilusFile *file,
const SortCriterion *sort)
{
- const SortCriterion *default_sort_criterion;
+ const SortCriterion *default_sort_criterion;
- if (!nautilus_canvas_view_supports_auto_layout (canvas_view)) {
- return;
- }
+ if (!nautilus_canvas_view_supports_auto_layout (canvas_view))
+ {
+ return;
+ }
- default_sort_criterion = get_default_sort_order (file);
- g_return_if_fail (default_sort_criterion != NULL);
+ default_sort_criterion = get_default_sort_order (file);
+ g_return_if_fail (default_sort_criterion != NULL);
- nautilus_file_set_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY,
- default_sort_criterion->metadata_text,
- sort->metadata_text);
- nautilus_file_set_boolean_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
- default_sort_criterion->reverse_order,
- sort->reverse_order);
+ nautilus_file_set_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY,
+ default_sort_criterion->metadata_text,
+ sort->metadata_text);
+ nautilus_file_set_boolean_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
+ default_sort_criterion->reverse_order,
+ sort->reverse_order);
}
static gboolean
get_default_directory_keep_aligned (void)
{
- return TRUE;
+ return TRUE;
}
static gboolean
nautilus_canvas_view_get_directory_keep_aligned (NautilusCanvasView *canvas_view,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (!nautilus_canvas_view_supports_keep_aligned (canvas_view)) {
- return FALSE;
- }
-
- return nautilus_file_get_boolean_metadata
- (file,
- NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
- get_default_directory_keep_aligned ());
+ if (!nautilus_canvas_view_supports_keep_aligned (canvas_view))
+ {
+ return FALSE;
+ }
+
+ return nautilus_file_get_boolean_metadata
+ (file,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
+ get_default_directory_keep_aligned ());
}
static void
nautilus_canvas_view_set_directory_keep_aligned (NautilusCanvasView *canvas_view,
- NautilusFile *file,
- gboolean keep_aligned)
+ NautilusFile *file,
+ gboolean keep_aligned)
{
- if (!nautilus_canvas_view_supports_keep_aligned (canvas_view)) {
- return;
- }
+ if (!nautilus_canvas_view_supports_keep_aligned (canvas_view))
+ {
+ return;
+ }
- nautilus_file_set_boolean_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
- get_default_directory_keep_aligned (),
- keep_aligned);
+ nautilus_file_set_boolean_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
+ get_default_directory_keep_aligned (),
+ keep_aligned);
}
static gboolean
nautilus_canvas_view_get_directory_auto_layout (NautilusCanvasView *canvas_view,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (!nautilus_canvas_view_supports_auto_layout (canvas_view)) {
- return FALSE;
- }
+ if (!nautilus_canvas_view_supports_auto_layout (canvas_view))
+ {
+ return FALSE;
+ }
- if (!nautilus_canvas_view_supports_manual_layout (canvas_view)) {
- return TRUE;
- }
+ if (!nautilus_canvas_view_supports_manual_layout (canvas_view))
+ {
+ return TRUE;
+ }
- return nautilus_file_get_boolean_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT, TRUE);
+ return nautilus_file_get_boolean_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT, TRUE);
}
static void
nautilus_canvas_view_set_directory_auto_layout (NautilusCanvasView *canvas_view,
- NautilusFile *file,
- gboolean auto_layout)
+ NautilusFile *file,
+ gboolean auto_layout)
{
- if (!nautilus_canvas_view_supports_auto_layout (canvas_view) ||
- !nautilus_canvas_view_supports_manual_layout (canvas_view)) {
- return;
- }
+ if (!nautilus_canvas_view_supports_auto_layout (canvas_view) ||
+ !nautilus_canvas_view_supports_manual_layout (canvas_view))
+ {
+ return;
+ }
- nautilus_file_set_boolean_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT,
- TRUE,
- auto_layout);
+ nautilus_file_set_boolean_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT,
+ TRUE,
+ auto_layout);
}
static const SortCriterion *
-get_sort_criterion_by_metadata_text (const char *metadata_text, gboolean reversed)
+get_sort_criterion_by_metadata_text (const char *metadata_text,
+ gboolean reversed)
{
- guint i;
+ guint i;
- /* Figure out what the new sort setting should be. */
- for (i = 0; i < G_N_ELEMENTS (sort_criteria); i++) {
- if (g_strcmp0 (sort_criteria[i].metadata_text, metadata_text) == 0
- && reversed == sort_criteria[i].reverse_order) {
- return &sort_criteria[i];
- }
- }
- return &sort_criteria[0];
+ /* Figure out what the new sort setting should be. */
+ for (i = 0; i < G_N_ELEMENTS (sort_criteria); i++)
+ {
+ if (g_strcmp0 (sort_criteria[i].metadata_text, metadata_text) == 0
+ && reversed == sort_criteria[i].reverse_order)
+ {
+ return &sort_criteria[i];
+ }
+ }
+ return &sort_criteria[0];
}
static const SortCriterion *
get_sort_criterion_by_action_target_name (const char *action_target_name)
{
- guint i;
- /* Figure out what the new sort setting should be. */
- for (i = 0; i < G_N_ELEMENTS (sort_criteria); i++) {
- if (g_strcmp0 (sort_criteria[i].action_target_name, action_target_name) == 0) {
- return &sort_criteria[i];
- }
- }
- return NULL;
+ guint i;
+ /* Figure out what the new sort setting should be. */
+ for (i = 0; i < G_N_ELEMENTS (sort_criteria); i++)
+ {
+ if (g_strcmp0 (sort_criteria[i].action_target_name, action_target_name) == 0)
+ {
+ return &sort_criteria[i];
+ }
+ }
+ return NULL;
}
static const SortCriterion *
-get_sort_criterion_by_sort_type (NautilusFileSortType sort_type, gboolean reversed)
+get_sort_criterion_by_sort_type (NautilusFileSortType sort_type,
+ gboolean reversed)
{
- guint i;
+ guint i;
- /* Figure out what the new sort setting should be. */
- for (i = 0; i < G_N_ELEMENTS (sort_criteria); i++) {
- if (sort_type == sort_criteria[i].sort_type
- && reversed == sort_criteria[i].reverse_order) {
- return &sort_criteria[i];
- }
- }
+ /* Figure out what the new sort setting should be. */
+ for (i = 0; i < G_N_ELEMENTS (sort_criteria); i++)
+ {
+ if (sort_type == sort_criteria[i].sort_type
+ && reversed == sort_criteria[i].reverse_order)
+ {
+ return &sort_criteria[i];
+ }
+ }
- return &sort_criteria[0];
+ return &sort_criteria[0];
}
static NautilusCanvasZoomLevel
get_default_zoom_level (NautilusCanvasView *canvas_view)
{
- NautilusCanvasZoomLevel default_zoom_level;
+ NautilusCanvasZoomLevel default_zoom_level;
- default_zoom_level = g_settings_get_enum (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL);
+ default_zoom_level = g_settings_get_enum (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL);
- return CLAMP (default_zoom_level, NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER);
+ return CLAMP (default_zoom_level, NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER);
}
static void
nautilus_canvas_view_begin_loading (NautilusFilesView *view)
{
- NautilusCanvasView *canvas_view;
- GtkWidget *canvas_container;
- NautilusFile *file;
- char *uri;
- const SortCriterion *sort;
+ NautilusCanvasView *canvas_view;
+ GtkWidget *canvas_container;
+ NautilusFile *file;
+ char *uri;
+ const SortCriterion *sort;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
- file = nautilus_files_view_get_directory_as_file (view);
- uri = nautilus_file_get_uri (file);
- canvas_container = GTK_WIDGET (get_canvas_container (canvas_view));
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
+ file = nautilus_files_view_get_directory_as_file (view);
+ uri = nautilus_file_get_uri (file);
+ canvas_container = GTK_WIDGET (get_canvas_container (canvas_view));
- nautilus_canvas_container_begin_loading (NAUTILUS_CANVAS_CONTAINER (canvas_container));
+ nautilus_canvas_container_begin_loading (NAUTILUS_CANVAS_CONTAINER (canvas_container));
- g_free (uri);
+ g_free (uri);
- /* Set the sort mode.
- * It's OK not to resort the icons because the
- * container doesn't have any icons at this point.
- */
- sort = nautilus_canvas_view_get_directory_sort_by (canvas_view, file);
- update_sort_criterion (canvas_view, sort, FALSE);
+ /* Set the sort mode.
+ * It's OK not to resort the icons because the
+ * container doesn't have any icons at this point.
+ */
+ sort = nautilus_canvas_view_get_directory_sort_by (canvas_view, file);
+ update_sort_criterion (canvas_view, sort, FALSE);
- nautilus_canvas_container_set_keep_aligned
- (get_canvas_container (canvas_view),
- nautilus_canvas_view_get_directory_keep_aligned (canvas_view, file));
+ nautilus_canvas_container_set_keep_aligned
+ (get_canvas_container (canvas_view),
+ nautilus_canvas_view_get_directory_keep_aligned (canvas_view, file));
- /* We must set auto-layout last, because it invokes the layout_changed
- * callback, which works incorrectly if the other layout criteria are
- * not already set up properly (see bug 6500, e.g.)
- */
- nautilus_canvas_container_set_auto_layout
- (get_canvas_container (canvas_view),
- nautilus_canvas_view_get_directory_auto_layout (canvas_view, file));
+ /* We must set auto-layout last, because it invokes the layout_changed
+ * callback, which works incorrectly if the other layout criteria are
+ * not already set up properly (see bug 6500, e.g.)
+ */
+ nautilus_canvas_container_set_auto_layout
+ (get_canvas_container (canvas_view),
+ nautilus_canvas_view_get_directory_auto_layout (canvas_view, file));
- /* We could have changed to the trash directory or to searching, and then
- * we need to update the menus */
- nautilus_files_view_update_context_menus(view);
- nautilus_files_view_update_toolbar_menus(view);
+ /* We could have changed to the trash directory or to searching, and then
+ * we need to update the menus */
+ nautilus_files_view_update_context_menus (view);
+ nautilus_files_view_update_toolbar_menus (view);
}
static void
canvas_view_notify_clipboard_info (NautilusClipboardMonitor *monitor,
- NautilusClipboardInfo *info,
- NautilusCanvasView *canvas_view)
+ NautilusClipboardInfo *info,
+ NautilusCanvasView *canvas_view)
{
- GList *icon_data;
+ GList *icon_data;
- icon_data = NULL;
- if (info && info->cut) {
- icon_data = info->files;
- }
+ icon_data = NULL;
+ if (info && info->cut)
+ {
+ icon_data = info->files;
+ }
- nautilus_canvas_container_set_highlighted_for_clipboard (
- get_canvas_container (canvas_view), icon_data);
+ nautilus_canvas_container_set_highlighted_for_clipboard (
+ get_canvas_container (canvas_view), icon_data);
}
static void
nautilus_canvas_view_end_loading (NautilusFilesView *view,
- gboolean all_files_seen)
+ gboolean all_files_seen)
{
- NautilusCanvasView *canvas_view;
- GtkWidget *canvas_container;
- NautilusClipboardMonitor *monitor;
- NautilusClipboardInfo *info;
+ NautilusCanvasView *canvas_view;
+ GtkWidget *canvas_container;
+ NautilusClipboardMonitor *monitor;
+ NautilusClipboardInfo *info;
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
- canvas_container = GTK_WIDGET (get_canvas_container (canvas_view));
- nautilus_canvas_container_end_loading (NAUTILUS_CANVAS_CONTAINER (canvas_container), all_files_seen);
+ canvas_container = GTK_WIDGET (get_canvas_container (canvas_view));
+ nautilus_canvas_container_end_loading (NAUTILUS_CANVAS_CONTAINER (canvas_container), all_files_seen);
- monitor = nautilus_clipboard_monitor_get ();
- info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
+ monitor = nautilus_clipboard_monitor_get ();
+ info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
- canvas_view_notify_clipboard_info (monitor, info, canvas_view);
+ canvas_view_notify_clipboard_info (monitor, info, canvas_view);
}
static NautilusCanvasZoomLevel
nautilus_canvas_view_get_zoom_level (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD);
-
- return nautilus_canvas_container_get_zoom_level (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD);
+
+ return nautilus_canvas_container_get_zoom_level (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
}
static void
nautilus_canvas_view_zoom_to_level (NautilusFilesView *view,
- gint new_level)
+ gint new_level)
{
- NautilusCanvasView *canvas_view;
- NautilusCanvasContainer *canvas_container;
+ NautilusCanvasView *canvas_view;
+ NautilusCanvasContainer *canvas_container;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- g_return_if_fail (new_level >= NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL &&
- new_level <= NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (new_level >= NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL &&
+ new_level <= NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER);
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
- canvas_container = get_canvas_container (canvas_view);
- if (nautilus_canvas_container_get_zoom_level (canvas_container) == new_level)
- return;
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
+ canvas_container = get_canvas_container (canvas_view);
+ if (nautilus_canvas_container_get_zoom_level (canvas_container) == new_level)
+ {
+ return;
+ }
- nautilus_canvas_container_set_zoom_level (canvas_container, new_level);
- g_action_group_change_action_state (nautilus_files_view_get_action_group (view),
- "zoom-to-level", g_variant_new_int32 (new_level));
+ nautilus_canvas_container_set_zoom_level (canvas_container, new_level);
+ g_action_group_change_action_state (nautilus_files_view_get_action_group (view),
+ "zoom-to-level", g_variant_new_int32 (new_level));
- nautilus_files_view_update_toolbar_menus (view);
+ nautilus_files_view_update_toolbar_menus (view);
}
static void
-nautilus_canvas_view_bump_zoom_level (NautilusFilesView *view, int zoom_increment)
+nautilus_canvas_view_bump_zoom_level (NautilusFilesView *view,
+ int zoom_increment)
{
- NautilusCanvasZoomLevel new_level;
+ NautilusCanvasZoomLevel new_level;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- if (!nautilus_files_view_supports_zooming (view)) {
- return;
- }
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ if (!nautilus_files_view_supports_zooming (view))
+ {
+ return;
+ }
- new_level = nautilus_canvas_view_get_zoom_level (view) + zoom_increment;
+ new_level = nautilus_canvas_view_get_zoom_level (view) + zoom_increment;
- if (new_level >= NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL &&
- new_level <= NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER) {
- nautilus_canvas_view_zoom_to_level (view, new_level);
- }
+ if (new_level >= NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL &&
+ new_level <= NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER)
+ {
+ nautilus_canvas_view_zoom_to_level (view, new_level);
+ }
}
static void
nautilus_canvas_view_restore_standard_zoom_level (NautilusFilesView *view)
{
- nautilus_canvas_view_zoom_to_level (view, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
+ nautilus_canvas_view_zoom_to_level (view, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
}
-static gboolean
+static gboolean
nautilus_canvas_view_can_zoom_in (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return nautilus_canvas_view_get_zoom_level (view)
- < NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER;
+ return nautilus_canvas_view_get_zoom_level (view)
+ < NAUTILUS_CANVAS_ZOOM_LEVEL_LARGER;
}
-static gboolean
+static gboolean
nautilus_canvas_view_can_zoom_out (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return nautilus_canvas_view_get_zoom_level (view)
- > NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL;
+ return nautilus_canvas_view_get_zoom_level (view)
+ > NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL;
}
static gfloat
nautilus_canvas_view_get_zoom_level_percentage (NautilusFilesView *view)
{
- guint icon_size;
- NautilusCanvasZoomLevel zoom_level;
+ guint icon_size;
+ NautilusCanvasZoomLevel zoom_level;
- zoom_level = nautilus_canvas_view_get_zoom_level (view);
- icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (zoom_level);
+ zoom_level = nautilus_canvas_view_get_zoom_level (view);
+ icon_size = nautilus_canvas_container_get_icon_size_for_zoom_level (zoom_level);
- return (gfloat) icon_size / NAUTILUS_CANVAS_ICON_SIZE_LARGE;
+ return (gfloat) icon_size / NAUTILUS_CANVAS_ICON_SIZE_LARGE;
}
static gboolean
nautilus_canvas_view_is_empty (NautilusFilesView *view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (view));
- return nautilus_canvas_container_is_empty
- (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
+ return nautilus_canvas_container_is_empty
+ (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
}
static GList *
nautilus_canvas_view_get_selection (NautilusFilesView *view)
{
- GList *list;
+ GList *list;
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
- list = nautilus_canvas_container_get_selection
- (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
- nautilus_file_list_ref (list);
- return list;
+ list = nautilus_canvas_container_get_selection
+ (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
+ nautilus_file_list_ref (list);
+ return list;
}
static void
action_keep_aligned (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusFile *file;
- NautilusCanvasView *canvas_view;
- gboolean keep_aligned;
+ NautilusFile *file;
+ NautilusCanvasView *canvas_view;
+ gboolean keep_aligned;
- canvas_view = NAUTILUS_CANVAS_VIEW (user_data);
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
- keep_aligned = g_variant_get_boolean (state);
+ canvas_view = NAUTILUS_CANVAS_VIEW (user_data);
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
+ keep_aligned = g_variant_get_boolean (state);
- nautilus_canvas_view_set_directory_keep_aligned (canvas_view,
- file,
- keep_aligned);
- nautilus_canvas_container_set_keep_aligned (get_canvas_container (canvas_view),
- keep_aligned);
+ nautilus_canvas_view_set_directory_keep_aligned (canvas_view,
+ file,
+ keep_aligned);
+ nautilus_canvas_container_set_keep_aligned (get_canvas_container (canvas_view),
+ keep_aligned);
- g_simple_action_set_state (action, state);
+ g_simple_action_set_state (action, state);
}
static void
action_sort_order_changed (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+ GVariant *value,
+ gpointer user_data)
{
- const gchar *target_name;
- const SortCriterion *sort_criterion;
+ const gchar *target_name;
+ const SortCriterion *sort_criterion;
- g_assert (NAUTILUS_IS_CANVAS_VIEW (user_data));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (user_data));
- target_name = g_variant_get_string (value, NULL);
- sort_criterion = get_sort_criterion_by_action_target_name (target_name);
+ target_name = g_variant_get_string (value, NULL);
+ sort_criterion = get_sort_criterion_by_action_target_name (target_name);
- g_assert (sort_criterion != NULL);
- /* Note that id might be a toggle item.
- * Ignore non-sort ids so that they don't cause sorting.
- */
- if (sort_criterion->sort_type == NAUTILUS_FILE_SORT_NONE) {
- switch_to_manual_layout (user_data);
- } else {
- update_sort_criterion (user_data, sort_criterion, TRUE);
+ g_assert (sort_criterion != NULL);
+ /* Note that id might be a toggle item.
+ * Ignore non-sort ids so that they don't cause sorting.
+ */
+ if (sort_criterion->sort_type == NAUTILUS_FILE_SORT_NONE)
+ {
+ switch_to_manual_layout (user_data);
+ }
+ else
+ {
+ update_sort_criterion (user_data, sort_criterion, TRUE);
- nautilus_canvas_container_sort (get_canvas_container (user_data));
- nautilus_canvas_view_reveal_selection (NAUTILUS_FILES_VIEW (user_data));
- }
+ nautilus_canvas_container_sort (get_canvas_container (user_data));
+ nautilus_canvas_view_reveal_selection (NAUTILUS_FILES_VIEW (user_data));
+ }
- g_simple_action_set_state (action, value);
+ g_simple_action_set_state (action, value);
}
static void
action_zoom_to_level (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusFilesView *view;
- NautilusCanvasZoomLevel zoom_level;
+ NautilusFilesView *view;
+ NautilusCanvasZoomLevel zoom_level;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
- zoom_level = g_variant_get_int32 (state);
- nautilus_canvas_view_zoom_to_level (view, zoom_level);
+ view = NAUTILUS_FILES_VIEW (user_data);
+ zoom_level = g_variant_get_int32 (state);
+ nautilus_canvas_view_zoom_to_level (view, zoom_level);
- g_simple_action_set_state (G_SIMPLE_ACTION (action), state);
- if (g_settings_get_enum (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL) != zoom_level) {
- g_settings_set_enum (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
- zoom_level);
- }
+ g_simple_action_set_state (G_SIMPLE_ACTION (action), state);
+ if (g_settings_get_enum (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL) != zoom_level)
+ {
+ g_settings_set_enum (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
+ zoom_level);
+ }
}
static void
switch_to_manual_layout (NautilusCanvasView *canvas_view)
{
- if (!nautilus_canvas_view_using_auto_layout (canvas_view) ||
- !nautilus_files_view_is_editable (NAUTILUS_FILES_VIEW (canvas_view))) {
- return;
- }
+ if (!nautilus_canvas_view_using_auto_layout (canvas_view) ||
+ !nautilus_files_view_is_editable (NAUTILUS_FILES_VIEW (canvas_view)))
+ {
+ return;
+ }
+
+ canvas_view->details->sort = &sort_criteria[0];
- canvas_view->details->sort = &sort_criteria[0];
-
- nautilus_canvas_container_set_auto_layout
- (get_canvas_container (canvas_view), FALSE);
+ nautilus_canvas_container_set_auto_layout
+ (get_canvas_container (canvas_view), FALSE);
}
static void
layout_changed_callback (NautilusCanvasContainer *container,
- NautilusCanvasView *canvas_view)
+ NautilusCanvasView *canvas_view)
{
- NautilusFile *file;
+ NautilusFile *file;
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
- if (file != NULL) {
- nautilus_canvas_view_set_directory_auto_layout
- (canvas_view,
- file,
- nautilus_canvas_view_using_auto_layout (canvas_view));
- }
+ if (file != NULL)
+ {
+ nautilus_canvas_view_set_directory_auto_layout
+ (canvas_view,
+ file,
+ nautilus_canvas_view_using_auto_layout (canvas_view));
+ }
}
-const GActionEntry canvas_view_entries[] = {
- { "keep-aligned", NULL, NULL, "true", action_keep_aligned },
- { "sort", NULL, "s", "'name'", action_sort_order_changed },
- { "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
+const GActionEntry canvas_view_entries[] =
+{
+ { "keep-aligned", NULL, NULL, "true", action_keep_aligned },
+ { "sort", NULL, "s", "'name'", action_sort_order_changed },
+ { "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
};
static void
update_sort_action_state_hint (NautilusCanvasView *canvas_view)
{
- NautilusFile *file;
- GVariantBuilder builder;
- GActionGroup *action_group;
- GAction *action;
- GVariant *state_hint;
- gint idx;
+ NautilusFile *file;
+ GVariantBuilder builder;
+ GActionGroup *action_group;
+ GAction *action;
+ GVariant *state_hint;
+ gint idx;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
- for (idx = 0; idx < G_N_ELEMENTS (sort_criteria); idx++) {
- if (sort_criteria[idx].match_func == NULL ||
- (file != NULL && sort_criteria[idx].match_func (file)))
- g_variant_builder_add (&builder, "s", sort_criteria[idx].action_target_name);
- }
+ for (idx = 0; idx < G_N_ELEMENTS (sort_criteria); idx++)
+ {
+ if (sort_criteria[idx].match_func == NULL ||
+ (file != NULL && sort_criteria[idx].match_func (file)))
+ {
+ g_variant_builder_add (&builder, "s", sort_criteria[idx].action_target_name);
+ }
+ }
- state_hint = g_variant_builder_end (&builder);
+ state_hint = g_variant_builder_end (&builder);
- action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (canvas_view));
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "sort");
- g_simple_action_set_state_hint (G_SIMPLE_ACTION (action), state_hint);
+ action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (canvas_view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "sort");
+ g_simple_action_set_state_hint (G_SIMPLE_ACTION (action), state_hint);
- g_variant_unref (state_hint);
+ g_variant_unref (state_hint);
}
static gboolean
showing_recent_directory (NautilusFilesView *view)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL) {
- return nautilus_file_is_in_recent (file);
- }
- return FALSE;
+ file = nautilus_files_view_get_directory_as_file (view);
+ if (file != NULL)
+ {
+ return nautilus_file_is_in_recent (file);
+ }
+ return FALSE;
}
static gboolean
showing_search_directory (NautilusFilesView *view)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL) {
- return nautilus_file_is_in_search (file);
- }
- return FALSE;
+ file = nautilus_files_view_get_directory_as_file (view);
+ if (file != NULL)
+ {
+ return nautilus_file_is_in_search (file);
+ }
+ return FALSE;
}
static void
nautilus_canvas_view_update_actions_state (NautilusFilesView *view)
{
- GActionGroup *view_action_group;
- GAction *action;
- gboolean keep_aligned;
- NautilusCanvasView *canvas_view;
-
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
-
- NAUTILUS_FILES_VIEW_CLASS (nautilus_canvas_view_parent_class)->update_actions_state (view);
-
- view_action_group = nautilus_files_view_get_action_group (view);
- if (nautilus_canvas_view_supports_auto_layout (canvas_view)) {
- GVariant *sort_state;
-
- /* When we change the sort action state, even using the same value, it triggers
- * the sort action changed handler, which reveals the selection, since we expect
- * the selection to be visible when the user changes the sort order. But we may
- * need to update the actions state for others reason than an actual sort change,
- * so we need to prevent to trigger the sort action changed handler for those cases.
- * To achieve this, check if the action state value actually changed before setting
- * it
- */
- sort_state = g_action_group_get_action_state (view_action_group, "sort");
-
- if (g_strcmp0 (g_variant_get_string (sort_state, NULL),
- NAUTILUS_CANVAS_VIEW (view)->details->sort->action_target_name) != 0) {
- g_action_group_change_action_state (view_action_group,
- "sort",
- g_variant_new_string (NAUTILUS_CANVAS_VIEW (view)->details->sort->action_target_name));
- }
-
- g_variant_unref (sort_state);
- }
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "sort");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !showing_recent_directory (view) &&
- !showing_search_directory (view));
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "keep-aligned");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- canvas_view->details->supports_keep_aligned);
- if (canvas_view->details->supports_keep_aligned) {
- keep_aligned = nautilus_canvas_container_is_keep_aligned (get_canvas_container (canvas_view));
- g_action_change_state (action, g_variant_new_boolean (keep_aligned));
- }
-
- update_sort_action_state_hint (canvas_view);
+ GActionGroup *view_action_group;
+ GAction *action;
+ gboolean keep_aligned;
+ NautilusCanvasView *canvas_view;
+
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
+
+ NAUTILUS_FILES_VIEW_CLASS (nautilus_canvas_view_parent_class)->update_actions_state (view);
+
+ view_action_group = nautilus_files_view_get_action_group (view);
+ if (nautilus_canvas_view_supports_auto_layout (canvas_view))
+ {
+ GVariant *sort_state;
+
+ /* When we change the sort action state, even using the same value, it triggers
+ * the sort action changed handler, which reveals the selection, since we expect
+ * the selection to be visible when the user changes the sort order. But we may
+ * need to update the actions state for others reason than an actual sort change,
+ * so we need to prevent to trigger the sort action changed handler for those cases.
+ * To achieve this, check if the action state value actually changed before setting
+ * it
+ */
+ sort_state = g_action_group_get_action_state (view_action_group, "sort");
+
+ if (g_strcmp0 (g_variant_get_string (sort_state, NULL),
+ NAUTILUS_CANVAS_VIEW (view)->details->sort->action_target_name) != 0)
+ {
+ g_action_group_change_action_state (view_action_group,
+ "sort",
+ g_variant_new_string (NAUTILUS_CANVAS_VIEW (view)->details->sort->action_target_name));
+ }
+
+ g_variant_unref (sort_state);
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "sort");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !showing_recent_directory (view) &&
+ !showing_search_directory (view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group), "keep-aligned");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ canvas_view->details->supports_keep_aligned);
+ if (canvas_view->details->supports_keep_aligned)
+ {
+ keep_aligned = nautilus_canvas_container_is_keep_aligned (get_canvas_container (canvas_view));
+ g_action_change_state (action, g_variant_new_boolean (keep_aligned));
+ }
+
+ update_sort_action_state_hint (canvas_view);
}
static void
nautilus_canvas_view_select_all (NautilusFilesView *view)
{
- NautilusCanvasContainer *canvas_container;
+ NautilusCanvasContainer *canvas_container;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
- nautilus_canvas_container_select_all (canvas_container);
+ canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
+ nautilus_canvas_container_select_all (canvas_container);
}
static void
nautilus_canvas_view_select_first (NautilusFilesView *view)
{
- NautilusCanvasContainer *canvas_container;
+ NautilusCanvasContainer *canvas_container;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
- nautilus_canvas_container_select_first (canvas_container);
+ canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
+ nautilus_canvas_container_select_first (canvas_container);
}
static void
nautilus_canvas_view_reveal_selection (NautilusFilesView *view)
{
- GList *selection;
+ GList *selection;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- /* Make sure at least one of the selected items is scrolled into view */
- if (selection != NULL) {
- /* Update the icon ordering to reveal the rigth selection */
- nautilus_canvas_container_layout_now (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
- nautilus_canvas_container_reveal
- (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)),
- selection->data);
- }
+ /* Make sure at least one of the selected items is scrolled into view */
+ if (selection != NULL)
+ {
+ /* Update the icon ordering to reveal the rigth selection */
+ nautilus_canvas_container_layout_now (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
+ nautilus_canvas_container_reveal
+ (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)),
+ selection->data);
+ }
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
-static GdkRectangle*
+static GdkRectangle *
nautilus_canvas_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
{
- GArray *bounding_boxes;
- GdkRectangle *bounding_box;
- NautilusCanvasContainer *canvas_container;
- GtkAdjustment *vadjustment, *hadjustment;
- GtkWidget *parent_container;
+ GArray *bounding_boxes;
+ GdkRectangle *bounding_box;
+ NautilusCanvasContainer *canvas_container;
+ GtkAdjustment *vadjustment, *hadjustment;
+ GtkWidget *parent_container;
- canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
- bounding_boxes = nautilus_canvas_container_get_selected_icons_bounding_box (canvas_container);
- /* We only allow renaming one item at once */
- bounding_box = &g_array_index (bounding_boxes, GdkRectangle, 0);
- parent_container = nautilus_files_view_get_content_widget (view);
- vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (parent_container));
- hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (parent_container));
+ canvas_container = get_canvas_container (NAUTILUS_CANVAS_VIEW (view));
+ bounding_boxes = nautilus_canvas_container_get_selected_icons_bounding_box (canvas_container);
+ /* We only allow renaming one item at once */
+ bounding_box = &g_array_index (bounding_boxes, GdkRectangle, 0);
+ parent_container = nautilus_files_view_get_content_widget (view);
+ vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (parent_container));
+ hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (parent_container));
- bounding_box->x -= gtk_adjustment_get_value (hadjustment);
- bounding_box->y -= gtk_adjustment_get_value (vadjustment);
+ bounding_box->x -= gtk_adjustment_get_value (hadjustment);
+ bounding_box->y -= gtk_adjustment_get_value (vadjustment);
- g_array_free (bounding_boxes, FALSE);
+ g_array_free (bounding_boxes, FALSE);
- return bounding_box;
+ return bounding_box;
}
static void
-nautilus_canvas_view_set_selection (NautilusFilesView *view, GList *selection)
+nautilus_canvas_view_set_selection (NautilusFilesView *view,
+ GList *selection)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- nautilus_canvas_container_set_selection
- (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)), selection);
+ nautilus_canvas_container_set_selection
+ (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)), selection);
}
static void
nautilus_canvas_view_invert_selection (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
- nautilus_canvas_container_invert_selection
- (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
+ nautilus_canvas_container_invert_selection
+ (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)));
}
static gboolean
nautilus_canvas_view_using_manual_layout (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), FALSE);
- return !nautilus_canvas_view_using_auto_layout (NAUTILUS_CANVAS_VIEW (view));
+ return !nautilus_canvas_view_using_auto_layout (NAUTILUS_CANVAS_VIEW (view));
}
static void
nautilus_canvas_view_widget_to_file_operation_position (NautilusFilesView *view,
- GdkPoint *position)
+ GdkPoint *position)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (view));
- nautilus_canvas_container_widget_to_file_operation_position
- (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)), position);
+ nautilus_canvas_container_widget_to_file_operation_position
+ (get_canvas_container (NAUTILUS_CANVAS_VIEW (view)), position);
}
static void
canvas_container_activate_callback (NautilusCanvasContainer *container,
- GList *file_list,
- NautilusCanvasView *canvas_view)
+ GList *file_list,
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
- nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (canvas_view),
- file_list,
- 0, TRUE);
+ nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (canvas_view),
+ file_list,
+ 0, TRUE);
}
static void
canvas_container_activate_previewer_callback (NautilusCanvasContainer *container,
- GList *file_list,
- GArray *locations,
- NautilusCanvasView *canvas_view)
+ GList *file_list,
+ GArray *locations,
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
- nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (canvas_view),
- file_list, locations);
+ nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (canvas_view),
+ file_list, locations);
}
/* this is called in one of these cases:
@@ -1211,737 +1280,790 @@ canvas_container_activate_previewer_callback (NautilusCanvasContainer *container
*/
static void
canvas_container_activate_alternate_callback (NautilusCanvasContainer *container,
- GList *file_list,
- NautilusCanvasView *canvas_view)
-{
- GdkEvent *event;
- GdkEventButton *button_event;
- GdkEventKey *key_event;
- gboolean open_in_tab, open_in_window, close_behind;
- NautilusWindowOpenFlags flags;
-
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
-
- flags = 0;
- event = gtk_get_current_event ();
- open_in_tab = FALSE;
- open_in_window = FALSE;
- close_behind = FALSE;
-
- if (event->type == GDK_BUTTON_PRESS ||
- event->type == GDK_BUTTON_RELEASE ||
- event->type == GDK_2BUTTON_PRESS ||
- event->type == GDK_3BUTTON_PRESS) {
- button_event = (GdkEventButton *) event;
- open_in_window = ((button_event->state & GDK_SHIFT_MASK) != 0);
- open_in_tab = !open_in_window;
- } else if (event->type == GDK_KEY_PRESS ||
- event->type == GDK_KEY_RELEASE) {
- key_event = (GdkEventKey *) event;
- open_in_tab = ((key_event->state & GDK_SHIFT_MASK) != 0);
- }
-
- if (open_in_tab) {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
- }
-
- if (open_in_window) {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- }
-
- if (close_behind) {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
- }
-
- DEBUG ("Activate alternate, open in tab %d, close behind %d, new window %d\n",
- open_in_tab, close_behind, open_in_window);
-
- nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (canvas_view),
- file_list,
- flags,
- TRUE);
+ GList *file_list,
+ NautilusCanvasView *canvas_view)
+{
+ GdkEvent *event;
+ GdkEventButton *button_event;
+ GdkEventKey *key_event;
+ gboolean open_in_tab, open_in_window, close_behind;
+ NautilusWindowOpenFlags flags;
+
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
+
+ flags = 0;
+ event = gtk_get_current_event ();
+ open_in_tab = FALSE;
+ open_in_window = FALSE;
+ close_behind = FALSE;
+
+ if (event->type == GDK_BUTTON_PRESS ||
+ event->type == GDK_BUTTON_RELEASE ||
+ event->type == GDK_2BUTTON_PRESS ||
+ event->type == GDK_3BUTTON_PRESS)
+ {
+ button_event = (GdkEventButton *) event;
+ open_in_window = ((button_event->state & GDK_SHIFT_MASK) != 0);
+ open_in_tab = !open_in_window;
+ }
+ else if (event->type == GDK_KEY_PRESS ||
+ event->type == GDK_KEY_RELEASE)
+ {
+ key_event = (GdkEventKey *) event;
+ open_in_tab = ((key_event->state & GDK_SHIFT_MASK) != 0);
+ }
+
+ if (open_in_tab)
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
+ }
+
+ if (open_in_window)
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ }
+
+ if (close_behind)
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND;
+ }
+
+ DEBUG ("Activate alternate, open in tab %d, close behind %d, new window %d\n",
+ open_in_tab, close_behind, open_in_window);
+
+ nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (canvas_view),
+ file_list,
+ flags,
+ TRUE);
}
static void
band_select_started_callback (NautilusCanvasContainer *container,
- NautilusCanvasView *canvas_view)
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
- nautilus_files_view_start_batching_selection_changes (NAUTILUS_FILES_VIEW (canvas_view));
+ nautilus_files_view_start_batching_selection_changes (NAUTILUS_FILES_VIEW (canvas_view));
}
static void
band_select_ended_callback (NautilusCanvasContainer *container,
- NautilusCanvasView *canvas_view)
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
- nautilus_files_view_stop_batching_selection_changes (NAUTILUS_FILES_VIEW (canvas_view));
+ nautilus_files_view_stop_batching_selection_changes (NAUTILUS_FILES_VIEW (canvas_view));
}
int
-nautilus_canvas_view_compare_files (NautilusCanvasView *canvas_view,
- NautilusFile *a,
- NautilusFile *b)
+nautilus_canvas_view_compare_files (NautilusCanvasView *canvas_view,
+ NautilusFile *a,
+ NautilusFile *b)
{
- return nautilus_file_compare_for_sort
- (a, b, canvas_view->details->sort->sort_type,
- /* Use type-unsafe cast for performance */
- nautilus_files_view_should_sort_directories_first ((NautilusFilesView *)canvas_view),
- canvas_view->details->sort->reverse_order);
+ return nautilus_file_compare_for_sort
+ (a, b, canvas_view->details->sort->sort_type,
+ /* Use type-unsafe cast for performance */
+ nautilus_files_view_should_sort_directories_first ((NautilusFilesView *) canvas_view),
+ canvas_view->details->sort->reverse_order);
}
static int
-compare_files (NautilusFilesView *canvas_view,
- NautilusFile *a,
- NautilusFile *b)
+compare_files (NautilusFilesView *canvas_view,
+ NautilusFile *a,
+ NautilusFile *b)
{
- return nautilus_canvas_view_compare_files ((NautilusCanvasView *)canvas_view, a, b);
+ return nautilus_canvas_view_compare_files ((NautilusCanvasView *) canvas_view, a, b);
}
static void
selection_changed_callback (NautilusCanvasContainer *container,
- NautilusCanvasView *canvas_view)
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
- nautilus_files_view_notify_selection_changed (NAUTILUS_FILES_VIEW (canvas_view));
+ nautilus_files_view_notify_selection_changed (NAUTILUS_FILES_VIEW (canvas_view));
}
static void
canvas_container_context_click_selection_callback (NautilusCanvasContainer *container,
- GdkEventButton *event,
- NautilusCanvasView *canvas_view)
+ GdkEventButton *event,
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
}
static void
canvas_container_context_click_background_callback (NautilusCanvasContainer *container,
- GdkEventButton *event,
- NautilusCanvasView *canvas_view)
+ GdkEventButton *event,
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (canvas_view), event);
}
static void
-icon_position_changed_callback (NautilusCanvasContainer *container,
- NautilusFile *file,
- const NautilusCanvasPosition *position,
- NautilusCanvasView *canvas_view)
+icon_position_changed_callback (NautilusCanvasContainer *container,
+ NautilusFile *file,
+ const NautilusCanvasPosition *position,
+ NautilusCanvasView *canvas_view)
{
- char *position_string;
- char scale_string[G_ASCII_DTOSTR_BUF_SIZE];
+ char *position_string;
+ char scale_string[G_ASCII_DTOSTR_BUF_SIZE];
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- g_assert (container == get_canvas_container (canvas_view));
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (container == get_canvas_container (canvas_view));
+ g_assert (NAUTILUS_IS_FILE (file));
- /* Store the new position of the canvas in the metadata. */
- if (!nautilus_canvas_view_using_auto_layout (canvas_view)) {
- position_string = g_strdup_printf
- ("%d,%d", position->x, position->y);
- nautilus_file_set_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_POSITION,
- NULL, position_string);
- g_free (position_string);
- }
+ /* Store the new position of the canvas in the metadata. */
+ if (!nautilus_canvas_view_using_auto_layout (canvas_view))
+ {
+ position_string = g_strdup_printf
+ ("%d,%d", position->x, position->y);
+ nautilus_file_set_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_POSITION,
+ NULL, position_string);
+ g_free (position_string);
+ }
- g_ascii_dtostr (scale_string, sizeof (scale_string), position->scale);
- nautilus_file_set_metadata
- (file, NAUTILUS_METADATA_KEY_ICON_SCALE,
- "1.0", scale_string);
+ g_ascii_dtostr (scale_string, sizeof (scale_string), position->scale);
+ nautilus_file_set_metadata
+ (file, NAUTILUS_METADATA_KEY_ICON_SCALE,
+ "1.0", scale_string);
}
static char *
get_icon_uri_callback (NautilusCanvasContainer *container,
- NautilusFile *file,
- NautilusCanvasView *canvas_view)
+ NautilusFile *file,
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- return nautilus_file_get_uri (file);
+ return nautilus_file_get_uri (file);
}
static char *
get_icon_activation_uri_callback (NautilusCanvasContainer *container,
- NautilusFile *file,
- NautilusCanvasView *canvas_view)
+ NautilusFile *file,
+ NautilusCanvasView *canvas_view)
{
- g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
+ g_assert (NAUTILUS_IS_CANVAS_CONTAINER (container));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (canvas_view));
- return nautilus_file_get_activation_uri (file);
+ return nautilus_file_get_activation_uri (file);
}
static char *
get_icon_drop_target_uri_callback (NautilusCanvasContainer *container,
- NautilusFile *file,
- NautilusCanvasView *canvas_view)
+ NautilusFile *file,
+ NautilusCanvasView *canvas_view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (canvas_view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (container), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (canvas_view), NULL);
- return nautilus_file_get_target_uri (file);
+ return nautilus_file_get_target_uri (file);
}
/* Preferences changed callbacks */
static void
nautilus_canvas_view_click_policy_changed (NautilusFilesView *directory_view)
{
- g_assert (NAUTILUS_IS_CANVAS_VIEW (directory_view));
+ g_assert (NAUTILUS_IS_CANVAS_VIEW (directory_view));
- nautilus_canvas_view_update_click_mode (NAUTILUS_CANVAS_VIEW (directory_view));
+ nautilus_canvas_view_update_click_mode (NAUTILUS_CANVAS_VIEW (directory_view));
}
static void
image_display_policy_changed_callback (gpointer callback_data)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
- canvas_view = NAUTILUS_CANVAS_VIEW (callback_data);
+ canvas_view = NAUTILUS_CANVAS_VIEW (callback_data);
- nautilus_canvas_container_request_update_all (get_canvas_container (canvas_view));
+ nautilus_canvas_container_request_update_all (get_canvas_container (canvas_view));
}
static void
text_attribute_names_changed_callback (gpointer callback_data)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
- canvas_view = NAUTILUS_CANVAS_VIEW (callback_data);
+ canvas_view = NAUTILUS_CANVAS_VIEW (callback_data);
- nautilus_canvas_container_request_update_all (get_canvas_container (canvas_view));
+ nautilus_canvas_container_request_update_all (get_canvas_container (canvas_view));
}
static void
default_sort_order_changed_callback (gpointer callback_data)
{
- NautilusCanvasView *canvas_view;
- NautilusFile *file;
- const SortCriterion *sort;
- NautilusCanvasContainer *canvas_container;
+ NautilusCanvasView *canvas_view;
+ NautilusFile *file;
+ const SortCriterion *sort;
+ NautilusCanvasContainer *canvas_container;
- g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (callback_data));
+ g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (callback_data));
- canvas_view = NAUTILUS_CANVAS_VIEW (callback_data);
+ canvas_view = NAUTILUS_CANVAS_VIEW (callback_data);
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
- sort = nautilus_canvas_view_get_directory_sort_by (canvas_view, file);
- update_sort_criterion (canvas_view, sort, FALSE);
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (canvas_view));
+ sort = nautilus_canvas_view_get_directory_sort_by (canvas_view, file);
+ update_sort_criterion (canvas_view, sort, FALSE);
- canvas_container = get_canvas_container (canvas_view);
- g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (canvas_container));
+ canvas_container = get_canvas_container (canvas_view);
+ g_return_if_fail (NAUTILUS_IS_CANVAS_CONTAINER (canvas_container));
- nautilus_canvas_container_request_update_all (canvas_container);
+ nautilus_canvas_container_request_update_all (canvas_container);
}
static void
nautilus_canvas_view_sort_directories_first_changed (NautilusFilesView *directory_view)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
- canvas_view = NAUTILUS_CANVAS_VIEW (directory_view);
+ canvas_view = NAUTILUS_CANVAS_VIEW (directory_view);
- if (nautilus_canvas_view_using_auto_layout (canvas_view)) {
- nautilus_canvas_container_sort
- (get_canvas_container (canvas_view));
- }
+ if (nautilus_canvas_view_using_auto_layout (canvas_view))
+ {
+ nautilus_canvas_container_sort
+ (get_canvas_container (canvas_view));
+ }
}
static gboolean
canvas_view_can_accept_item (NautilusCanvasContainer *container,
- NautilusFile *target_item,
- const char *item_uri,
- NautilusFilesView *view)
+ NautilusFile *target_item,
+ const char *item_uri,
+ NautilusFilesView *view)
{
- return nautilus_drag_can_accept_item (target_item, item_uri);
+ return nautilus_drag_can_accept_item (target_item, item_uri);
}
static char *
canvas_view_get_container_uri (NautilusCanvasContainer *container,
- NautilusFilesView *view)
+ NautilusFilesView *view)
{
- return nautilus_files_view_get_uri (view);
+ return nautilus_files_view_get_uri (view);
}
static void
canvas_view_move_copy_items (NautilusCanvasContainer *container,
- const GList *item_uris,
- GArray *relative_item_points,
- const char *target_dir,
- int copy_action,
- int x, int y,
- NautilusFilesView *view)
+ const GList *item_uris,
+ GArray *relative_item_points,
+ const char *target_dir,
+ int copy_action,
+ int x,
+ int y,
+ NautilusFilesView *view)
{
- nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
- item_uris,
- nautilus_files_view_get_copied_files_atom (view));
- nautilus_files_view_move_copy_items (view, item_uris, relative_item_points, target_dir,
- copy_action, x, y);
+ nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
+ item_uris,
+ nautilus_files_view_get_copied_files_atom (view));
+ nautilus_files_view_move_copy_items (view, item_uris, relative_item_points, target_dir,
+ copy_action, x, y);
}
static void
nautilus_canvas_view_update_click_mode (NautilusCanvasView *canvas_view)
{
- NautilusCanvasContainer *canvas_container;
- int click_mode;
+ NautilusCanvasContainer *canvas_container;
+ int click_mode;
- canvas_container = get_canvas_container (canvas_view);
- g_assert (canvas_container != NULL);
+ canvas_container = get_canvas_container (canvas_view);
+ g_assert (canvas_container != NULL);
- click_mode = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_CLICK_POLICY);
+ click_mode = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_CLICK_POLICY);
- nautilus_canvas_container_set_single_click_mode (canvas_container,
- click_mode == NAUTILUS_CLICK_POLICY_SINGLE);
+ nautilus_canvas_container_set_single_click_mode (canvas_container,
+ click_mode == NAUTILUS_CLICK_POLICY_SINGLE);
}
static gboolean
get_stored_layout_timestamp (NautilusCanvasContainer *container,
- NautilusCanvasIconData *icon_data,
- time_t *timestamp,
- NautilusCanvasView *view)
+ NautilusCanvasIconData *icon_data,
+ time_t *timestamp,
+ NautilusCanvasView *view)
{
- NautilusFile *file;
- NautilusDirectory *directory;
+ NautilusFile *file;
+ NautilusDirectory *directory;
- if (icon_data == NULL) {
- directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
- if (directory == NULL) {
- return FALSE;
- }
+ if (icon_data == NULL)
+ {
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
+ if (directory == NULL)
+ {
+ return FALSE;
+ }
- file = nautilus_directory_get_corresponding_file (directory);
- *timestamp = nautilus_file_get_time_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP);
- nautilus_file_unref (file);
- } else {
- *timestamp = nautilus_file_get_time_metadata (NAUTILUS_FILE (icon_data),
- NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP);
- }
+ file = nautilus_directory_get_corresponding_file (directory);
+ *timestamp = nautilus_file_get_time_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP);
+ nautilus_file_unref (file);
+ }
+ else
+ {
+ *timestamp = nautilus_file_get_time_metadata (NAUTILUS_FILE (icon_data),
+ NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP);
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
store_layout_timestamp (NautilusCanvasContainer *container,
- NautilusCanvasIconData *icon_data,
- const time_t *timestamp,
- NautilusCanvasView *view)
+ NautilusCanvasIconData *icon_data,
+ const time_t *timestamp,
+ NautilusCanvasView *view)
{
- NautilusFile *file;
- NautilusDirectory *directory;
+ NautilusFile *file;
+ NautilusDirectory *directory;
- if (icon_data == NULL) {
- directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
- if (directory == NULL) {
- return FALSE;
- }
+ if (icon_data == NULL)
+ {
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
+ if (directory == NULL)
+ {
+ return FALSE;
+ }
- file = nautilus_directory_get_corresponding_file (directory);
- nautilus_file_set_time_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP,
- (time_t) *timestamp);
- nautilus_file_unref (file);
- } else {
- nautilus_file_set_time_metadata (NAUTILUS_FILE (icon_data),
- NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
- (time_t) *timestamp);
- }
+ file = nautilus_directory_get_corresponding_file (directory);
+ nautilus_file_set_time_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP,
+ (time_t) *timestamp);
+ nautilus_file_unref (file);
+ }
+ else
+ {
+ nautilus_file_set_time_metadata (NAUTILUS_FILE (icon_data),
+ NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
+ (time_t) *timestamp);
+ }
- return TRUE;
+ return TRUE;
}
static NautilusCanvasContainer *
create_canvas_container (NautilusCanvasView *canvas_view)
{
- return NAUTILUS_CANVAS_VIEW_CLASS (G_OBJECT_GET_CLASS (canvas_view))->create_canvas_container (canvas_view);
+ return NAUTILUS_CANVAS_VIEW_CLASS (G_OBJECT_GET_CLASS (canvas_view))->create_canvas_container (canvas_view);
}
static NautilusCanvasContainer *
real_create_canvas_container (NautilusCanvasView *canvas_view)
{
- return nautilus_canvas_view_container_new (canvas_view);
+ return nautilus_canvas_view_container_new (canvas_view);
}
static void
initialize_canvas_container (NautilusCanvasView *canvas_view,
NautilusCanvasContainer *canvas_container)
{
- GtkWidget *content_widget;
-
- content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (canvas_view));
- canvas_view->details->canvas_container = GTK_WIDGET (canvas_container);
- g_object_add_weak_pointer (G_OBJECT (canvas_container),
- (gpointer *) &canvas_view->details->canvas_container);
-
- gtk_widget_set_can_focus (GTK_WIDGET (canvas_container), TRUE);
-
- g_signal_connect_object (canvas_container, "activate",
- G_CALLBACK (canvas_container_activate_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "activate-alternate",
- G_CALLBACK (canvas_container_activate_alternate_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "activate-previewer",
- G_CALLBACK (canvas_container_activate_previewer_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "band-select-started",
- G_CALLBACK (band_select_started_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "band-select-ended",
- G_CALLBACK (band_select_ended_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "context-click-selection",
- G_CALLBACK (canvas_container_context_click_selection_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "context-click-background",
- G_CALLBACK (canvas_container_context_click_background_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "icon-position-changed",
- G_CALLBACK (icon_position_changed_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "selection-changed",
- G_CALLBACK (selection_changed_callback), canvas_view, 0);
- /* FIXME: many of these should move into fm-canvas-container as virtual methods */
- g_signal_connect_object (canvas_container, "get-icon-uri",
- G_CALLBACK (get_icon_uri_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "get-icon-activation-uri",
- G_CALLBACK (get_icon_activation_uri_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "get-icon-drop-target-uri",
- G_CALLBACK (get_icon_drop_target_uri_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "move-copy-items",
- G_CALLBACK (canvas_view_move_copy_items), canvas_view, 0);
- g_signal_connect_object (canvas_container, "get-container-uri",
- G_CALLBACK (canvas_view_get_container_uri), canvas_view, 0);
- g_signal_connect_object (canvas_container, "can-accept-item",
- G_CALLBACK (canvas_view_can_accept_item), canvas_view, 0);
- g_signal_connect_object (canvas_container, "get-stored-icon-position",
- G_CALLBACK (get_stored_icon_position_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "layout-changed",
- G_CALLBACK (layout_changed_callback), canvas_view, 0);
- g_signal_connect_object (canvas_container, "icon-stretch-started",
- G_CALLBACK (nautilus_files_view_update_context_menus), canvas_view,
- G_CONNECT_SWAPPED);
- g_signal_connect_object (canvas_container, "icon-stretch-ended",
- G_CALLBACK (nautilus_files_view_update_context_menus), canvas_view,
- G_CONNECT_SWAPPED);
-
- g_signal_connect_object (canvas_container, "get-stored-layout-timestamp",
- G_CALLBACK (get_stored_layout_timestamp), canvas_view, 0);
- g_signal_connect_object (canvas_container, "store-layout-timestamp",
- G_CALLBACK (store_layout_timestamp), canvas_view, 0);
-
- gtk_container_add (GTK_CONTAINER (content_widget),
- GTK_WIDGET (canvas_container));
-
- nautilus_canvas_view_update_click_mode (canvas_view);
- nautilus_canvas_container_set_zoom_level (canvas_container,
- get_default_zoom_level (canvas_view));
-
- gtk_widget_show (GTK_WIDGET (canvas_container));
+ GtkWidget *content_widget;
+
+ content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (canvas_view));
+ canvas_view->details->canvas_container = GTK_WIDGET (canvas_container);
+ g_object_add_weak_pointer (G_OBJECT (canvas_container),
+ (gpointer *) &canvas_view->details->canvas_container);
+
+ gtk_widget_set_can_focus (GTK_WIDGET (canvas_container), TRUE);
+
+ g_signal_connect_object (canvas_container, "activate",
+ G_CALLBACK (canvas_container_activate_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "activate-alternate",
+ G_CALLBACK (canvas_container_activate_alternate_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "activate-previewer",
+ G_CALLBACK (canvas_container_activate_previewer_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "band-select-started",
+ G_CALLBACK (band_select_started_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "band-select-ended",
+ G_CALLBACK (band_select_ended_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "context-click-selection",
+ G_CALLBACK (canvas_container_context_click_selection_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "context-click-background",
+ G_CALLBACK (canvas_container_context_click_background_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "icon-position-changed",
+ G_CALLBACK (icon_position_changed_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "selection-changed",
+ G_CALLBACK (selection_changed_callback), canvas_view, 0);
+ /* FIXME: many of these should move into fm-canvas-container as virtual methods */
+ g_signal_connect_object (canvas_container, "get-icon-uri",
+ G_CALLBACK (get_icon_uri_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "get-icon-activation-uri",
+ G_CALLBACK (get_icon_activation_uri_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "get-icon-drop-target-uri",
+ G_CALLBACK (get_icon_drop_target_uri_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "move-copy-items",
+ G_CALLBACK (canvas_view_move_copy_items), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "get-container-uri",
+ G_CALLBACK (canvas_view_get_container_uri), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "can-accept-item",
+ G_CALLBACK (canvas_view_can_accept_item), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "get-stored-icon-position",
+ G_CALLBACK (get_stored_icon_position_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "layout-changed",
+ G_CALLBACK (layout_changed_callback), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "icon-stretch-started",
+ G_CALLBACK (nautilus_files_view_update_context_menus), canvas_view,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (canvas_container, "icon-stretch-ended",
+ G_CALLBACK (nautilus_files_view_update_context_menus), canvas_view,
+ G_CONNECT_SWAPPED);
+
+ g_signal_connect_object (canvas_container, "get-stored-layout-timestamp",
+ G_CALLBACK (get_stored_layout_timestamp), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "store-layout-timestamp",
+ G_CALLBACK (store_layout_timestamp), canvas_view, 0);
+
+ gtk_container_add (GTK_CONTAINER (content_widget),
+ GTK_WIDGET (canvas_container));
+
+ nautilus_canvas_view_update_click_mode (canvas_view);
+ nautilus_canvas_container_set_zoom_level (canvas_container,
+ get_default_zoom_level (canvas_view));
+
+ gtk_widget_show (GTK_WIDGET (canvas_container));
}
/* Handles an URL received from Mozilla */
static void
-canvas_view_handle_netscape_url (NautilusCanvasContainer *container, const char *encoded_url,
- const char *target_uri,
- GdkDragAction action, int x, int y, NautilusCanvasView *view)
+canvas_view_handle_netscape_url (NautilusCanvasContainer *container,
+ const char *encoded_url,
+ const char *target_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusCanvasView *view)
{
- nautilus_files_view_handle_netscape_url_drop (NAUTILUS_FILES_VIEW (view),
- encoded_url, target_uri, action, x, y);
+ nautilus_files_view_handle_netscape_url_drop (NAUTILUS_FILES_VIEW (view),
+ encoded_url, target_uri, action, x, y);
}
static void
-canvas_view_handle_uri_list (NautilusCanvasContainer *container, const char *item_uris,
- const char *target_uri,
- GdkDragAction action, int x, int y, NautilusCanvasView *view)
+canvas_view_handle_uri_list (NautilusCanvasContainer *container,
+ const char *item_uris,
+ const char *target_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusCanvasView *view)
{
- nautilus_files_view_handle_uri_list_drop (NAUTILUS_FILES_VIEW (view),
- item_uris, target_uri, action, x, y);
+ nautilus_files_view_handle_uri_list_drop (NAUTILUS_FILES_VIEW (view),
+ item_uris, target_uri, action, x, y);
}
static void
-canvas_view_handle_text (NautilusCanvasContainer *container, const char *text,
- const char *target_uri,
- GdkDragAction action, int x, int y, NautilusCanvasView *view)
+canvas_view_handle_text (NautilusCanvasContainer *container,
+ const char *text,
+ const char *target_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusCanvasView *view)
{
- nautilus_files_view_handle_text_drop (NAUTILUS_FILES_VIEW (view),
- text, target_uri, action, x, y);
+ nautilus_files_view_handle_text_drop (NAUTILUS_FILES_VIEW (view),
+ text, target_uri, action, x, y);
}
static void
-canvas_view_handle_raw (NautilusCanvasContainer *container, const char *raw_data,
- int length, const char *target_uri, const char *direct_save_uri,
- GdkDragAction action, int x, int y, NautilusCanvasView *view)
+canvas_view_handle_raw (NautilusCanvasContainer *container,
+ const char *raw_data,
+ int length,
+ const char *target_uri,
+ const char *direct_save_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusCanvasView *view)
{
- nautilus_files_view_handle_raw_drop (NAUTILUS_FILES_VIEW (view),
- raw_data, length, target_uri, direct_save_uri, action, x, y);
+ nautilus_files_view_handle_raw_drop (NAUTILUS_FILES_VIEW (view),
+ raw_data, length, target_uri, direct_save_uri, action, x, y);
}
static void
canvas_view_handle_hover (NautilusCanvasContainer *container,
- const char *target_uri,
- NautilusCanvasView *view)
+ const char *target_uri,
+ NautilusCanvasView *view)
{
- nautilus_files_view_handle_hover (NAUTILUS_FILES_VIEW (view), target_uri);
+ nautilus_files_view_handle_hover (NAUTILUS_FILES_VIEW (view), target_uri);
}
static char *
canvas_view_get_first_visible_file (NautilusFilesView *view)
{
- NautilusFile *file;
- NautilusCanvasView *canvas_view;
+ NautilusFile *file;
+ NautilusCanvasView *canvas_view;
+
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
+ file = NAUTILUS_FILE (nautilus_canvas_container_get_first_visible_icon (get_canvas_container (canvas_view)));
- file = NAUTILUS_FILE (nautilus_canvas_container_get_first_visible_icon (get_canvas_container (canvas_view)));
+ if (file)
+ {
+ return nautilus_file_get_uri (file);
+ }
- if (file) {
- return nautilus_file_get_uri (file);
- }
-
- return NULL;
+ return NULL;
}
static void
canvas_view_scroll_to_file (NautilusFilesView *view,
- const char *uri)
+ const char *uri)
{
- NautilusFile *file;
- NautilusCanvasView *canvas_view;
+ NautilusFile *file;
+ NautilusCanvasView *canvas_view;
- canvas_view = NAUTILUS_CANVAS_VIEW (view);
-
- if (uri != NULL) {
- /* Only if existing, since we don't want to add the file to
- the directory if it has been removed since then */
- file = nautilus_file_get_existing_by_uri (uri);
- if (file != NULL) {
- nautilus_canvas_container_scroll_to_canvas (get_canvas_container (canvas_view),
- NAUTILUS_CANVAS_ICON_DATA (file));
- nautilus_file_unref (file);
- }
- }
+ canvas_view = NAUTILUS_CANVAS_VIEW (view);
+
+ if (uri != NULL)
+ {
+ /* Only if existing, since we don't want to add the file to
+ * the directory if it has been removed since then */
+ file = nautilus_file_get_existing_by_uri (uri);
+ if (file != NULL)
+ {
+ nautilus_canvas_container_scroll_to_canvas (get_canvas_container (canvas_view),
+ NAUTILUS_CANVAS_ICON_DATA (file));
+ nautilus_file_unref (file);
+ }
+ }
}
static guint
nautilus_canvas_view_get_id (NautilusFilesView *view)
{
- return NAUTILUS_VIEW_GRID_ID;
+ return NAUTILUS_VIEW_GRID_ID;
}
static void
-nautilus_canvas_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NautilusCanvasView *canvas_view;
-
- canvas_view = NAUTILUS_CANVAS_VIEW (object);
-
- switch (prop_id) {
- case PROP_SUPPORTS_AUTO_LAYOUT:
- canvas_view->details->supports_auto_layout = g_value_get_boolean (value);
- break;
- case PROP_SUPPORTS_MANUAL_LAYOUT:
- canvas_view->details->supports_manual_layout = g_value_get_boolean (value);
- break;
- case PROP_SUPPORTS_SCALING:
- canvas_view->details->supports_scaling = g_value_get_boolean (value);
- break;
- case PROP_SUPPORTS_KEEP_ALIGNED:
- canvas_view->details->supports_keep_aligned = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+nautilus_canvas_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusCanvasView *canvas_view;
+
+ canvas_view = NAUTILUS_CANVAS_VIEW (object);
+
+ switch (prop_id)
+ {
+ case PROP_SUPPORTS_AUTO_LAYOUT:
+ {
+ canvas_view->details->supports_auto_layout = g_value_get_boolean (value);
+ }
+ break;
+
+ case PROP_SUPPORTS_MANUAL_LAYOUT:
+ {
+ canvas_view->details->supports_manual_layout = g_value_get_boolean (value);
+ }
+ break;
+
+ case PROP_SUPPORTS_SCALING:
+ {
+ canvas_view->details->supports_scaling = g_value_get_boolean (value);
+ }
+ break;
+
+ case PROP_SUPPORTS_KEEP_ALIGNED:
+ {
+ canvas_view->details->supports_keep_aligned = g_value_get_boolean (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_canvas_view_finalize (GObject *object)
{
- NautilusCanvasView *canvas_view;
+ NautilusCanvasView *canvas_view;
- canvas_view = NAUTILUS_CANVAS_VIEW (object);
+ canvas_view = NAUTILUS_CANVAS_VIEW (object);
- g_clear_object (&canvas_view->details->icon);
+ g_clear_object (&canvas_view->details->icon);
- g_free (canvas_view->details);
+ g_free (canvas_view->details);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- default_sort_order_changed_callback,
- canvas_view);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- image_display_policy_changed_callback,
- canvas_view);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ default_sort_order_changed_callback,
+ canvas_view);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ image_display_policy_changed_callback,
+ canvas_view);
- g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
- text_attribute_names_changed_callback,
- canvas_view);
+ g_signal_handlers_disconnect_by_func (nautilus_icon_view_preferences,
+ text_attribute_names_changed_callback,
+ canvas_view);
- G_OBJECT_CLASS (nautilus_canvas_view_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_canvas_view_parent_class)->finalize (object);
}
-static GIcon*
+static GIcon *
nautilus_canvas_view_get_icon (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_CANVAS_VIEW (view), NULL);
- return NAUTILUS_CANVAS_VIEW (view)->details->icon;
+ return NAUTILUS_CANVAS_VIEW (view)->details->icon;
}
static void
nautilus_canvas_view_class_init (NautilusCanvasViewClass *klass)
{
- NautilusFilesViewClass *nautilus_files_view_class;
- GObjectClass *oclass;
-
- nautilus_files_view_class = NAUTILUS_FILES_VIEW_CLASS (klass);
- oclass = G_OBJECT_CLASS (klass);
-
- oclass->set_property = nautilus_canvas_view_set_property;
- oclass->finalize = nautilus_canvas_view_finalize;
-
- GTK_WIDGET_CLASS (klass)->destroy = nautilus_canvas_view_destroy;
-
- klass->create_canvas_container = real_create_canvas_container;
-
- nautilus_files_view_class->add_file = nautilus_canvas_view_add_file;
- nautilus_files_view_class->begin_loading = nautilus_canvas_view_begin_loading;
- nautilus_files_view_class->bump_zoom_level = nautilus_canvas_view_bump_zoom_level;
- nautilus_files_view_class->can_zoom_in = nautilus_canvas_view_can_zoom_in;
- nautilus_files_view_class->can_zoom_out = nautilus_canvas_view_can_zoom_out;
- nautilus_files_view_class->get_zoom_level_percentage = nautilus_canvas_view_get_zoom_level_percentage;
- nautilus_files_view_class->clear = nautilus_canvas_view_clear;
- nautilus_files_view_class->end_loading = nautilus_canvas_view_end_loading;
- nautilus_files_view_class->file_changed = nautilus_canvas_view_file_changed;
- nautilus_files_view_class->compute_rename_popover_pointing_to = nautilus_canvas_view_compute_rename_popover_pointing_to;
- nautilus_files_view_class->get_selection = nautilus_canvas_view_get_selection;
- nautilus_files_view_class->get_selection_for_file_transfer = nautilus_canvas_view_get_selection;
- nautilus_files_view_class->is_empty = nautilus_canvas_view_is_empty;
- nautilus_files_view_class->remove_file = nautilus_canvas_view_remove_file;
- nautilus_files_view_class->restore_standard_zoom_level = nautilus_canvas_view_restore_standard_zoom_level;
- nautilus_files_view_class->reveal_selection = nautilus_canvas_view_reveal_selection;
- nautilus_files_view_class->select_all = nautilus_canvas_view_select_all;
- nautilus_files_view_class->select_first = nautilus_canvas_view_select_first;
- nautilus_files_view_class->set_selection = nautilus_canvas_view_set_selection;
- nautilus_files_view_class->invert_selection = nautilus_canvas_view_invert_selection;
- nautilus_files_view_class->compare_files = compare_files;
- nautilus_files_view_class->click_policy_changed = nautilus_canvas_view_click_policy_changed;
- nautilus_files_view_class->update_actions_state = nautilus_canvas_view_update_actions_state;
- nautilus_files_view_class->sort_directories_first_changed = nautilus_canvas_view_sort_directories_first_changed;
- nautilus_files_view_class->using_manual_layout = nautilus_canvas_view_using_manual_layout;
- nautilus_files_view_class->widget_to_file_operation_position = nautilus_canvas_view_widget_to_file_operation_position;
- nautilus_files_view_class->get_view_id = nautilus_canvas_view_get_id;
- nautilus_files_view_class->get_first_visible_file = canvas_view_get_first_visible_file;
- nautilus_files_view_class->scroll_to_file = canvas_view_scroll_to_file;
- nautilus_files_view_class->get_icon = nautilus_canvas_view_get_icon;
-
- properties[PROP_SUPPORTS_AUTO_LAYOUT] =
- g_param_spec_boolean ("supports-auto-layout",
- "Supports auto layout",
- "Whether this view supports auto layout",
- TRUE,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY);
- properties[PROP_SUPPORTS_MANUAL_LAYOUT] =
- g_param_spec_boolean ("supports-manual-layout",
- "Supports manual layout",
- "Whether this view supports manual layout",
- FALSE,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY);
- properties[PROP_SUPPORTS_SCALING] =
- g_param_spec_boolean ("supports-scaling",
- "Supports scaling",
- "Whether this view supports scaling",
- FALSE,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY);
- properties[PROP_SUPPORTS_KEEP_ALIGNED] =
- g_param_spec_boolean ("supports-keep-aligned",
- "Supports keep aligned",
- "Whether this view supports keep aligned",
- FALSE,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+ NautilusFilesViewClass *nautilus_files_view_class;
+ GObjectClass *oclass;
+
+ nautilus_files_view_class = NAUTILUS_FILES_VIEW_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
+
+ oclass->set_property = nautilus_canvas_view_set_property;
+ oclass->finalize = nautilus_canvas_view_finalize;
+
+ GTK_WIDGET_CLASS (klass)->destroy = nautilus_canvas_view_destroy;
+
+ klass->create_canvas_container = real_create_canvas_container;
+
+ nautilus_files_view_class->add_file = nautilus_canvas_view_add_file;
+ nautilus_files_view_class->begin_loading = nautilus_canvas_view_begin_loading;
+ nautilus_files_view_class->bump_zoom_level = nautilus_canvas_view_bump_zoom_level;
+ nautilus_files_view_class->can_zoom_in = nautilus_canvas_view_can_zoom_in;
+ nautilus_files_view_class->can_zoom_out = nautilus_canvas_view_can_zoom_out;
+ nautilus_files_view_class->get_zoom_level_percentage = nautilus_canvas_view_get_zoom_level_percentage;
+ nautilus_files_view_class->clear = nautilus_canvas_view_clear;
+ nautilus_files_view_class->end_loading = nautilus_canvas_view_end_loading;
+ nautilus_files_view_class->file_changed = nautilus_canvas_view_file_changed;
+ nautilus_files_view_class->compute_rename_popover_pointing_to = nautilus_canvas_view_compute_rename_popover_pointing_to;
+ nautilus_files_view_class->get_selection = nautilus_canvas_view_get_selection;
+ nautilus_files_view_class->get_selection_for_file_transfer = nautilus_canvas_view_get_selection;
+ nautilus_files_view_class->is_empty = nautilus_canvas_view_is_empty;
+ nautilus_files_view_class->remove_file = nautilus_canvas_view_remove_file;
+ nautilus_files_view_class->restore_standard_zoom_level = nautilus_canvas_view_restore_standard_zoom_level;
+ nautilus_files_view_class->reveal_selection = nautilus_canvas_view_reveal_selection;
+ nautilus_files_view_class->select_all = nautilus_canvas_view_select_all;
+ nautilus_files_view_class->select_first = nautilus_canvas_view_select_first;
+ nautilus_files_view_class->set_selection = nautilus_canvas_view_set_selection;
+ nautilus_files_view_class->invert_selection = nautilus_canvas_view_invert_selection;
+ nautilus_files_view_class->compare_files = compare_files;
+ nautilus_files_view_class->click_policy_changed = nautilus_canvas_view_click_policy_changed;
+ nautilus_files_view_class->update_actions_state = nautilus_canvas_view_update_actions_state;
+ nautilus_files_view_class->sort_directories_first_changed = nautilus_canvas_view_sort_directories_first_changed;
+ nautilus_files_view_class->using_manual_layout = nautilus_canvas_view_using_manual_layout;
+ nautilus_files_view_class->widget_to_file_operation_position = nautilus_canvas_view_widget_to_file_operation_position;
+ nautilus_files_view_class->get_view_id = nautilus_canvas_view_get_id;
+ nautilus_files_view_class->get_first_visible_file = canvas_view_get_first_visible_file;
+ nautilus_files_view_class->scroll_to_file = canvas_view_scroll_to_file;
+ nautilus_files_view_class->get_icon = nautilus_canvas_view_get_icon;
+
+ properties[PROP_SUPPORTS_AUTO_LAYOUT] =
+ g_param_spec_boolean ("supports-auto-layout",
+ "Supports auto layout",
+ "Whether this view supports auto layout",
+ TRUE,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_SUPPORTS_MANUAL_LAYOUT] =
+ g_param_spec_boolean ("supports-manual-layout",
+ "Supports manual layout",
+ "Whether this view supports manual layout",
+ FALSE,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_SUPPORTS_SCALING] =
+ g_param_spec_boolean ("supports-scaling",
+ "Supports scaling",
+ "Whether this view supports scaling",
+ FALSE,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_SUPPORTS_KEEP_ALIGNED] =
+ g_param_spec_boolean ("supports-keep-aligned",
+ "Supports keep aligned",
+ "Whether this view supports keep aligned",
+ FALSE,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
static void
nautilus_canvas_view_init (NautilusCanvasView *canvas_view)
{
- NautilusCanvasContainer *canvas_container;
- GActionGroup *view_action_group;
-
- canvas_view->details = g_new0 (NautilusCanvasViewDetails, 1);
- canvas_view->details->sort = &sort_criteria[0];
- canvas_view->details->icon = g_themed_icon_new ("view-grid-symbolic");
-
- canvas_container = create_canvas_container (canvas_view);
- initialize_canvas_container (canvas_view, canvas_container);
-
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER,
- G_CALLBACK (default_sort_order_changed_callback),
- canvas_view);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER,
- G_CALLBACK (default_sort_order_changed_callback),
- canvas_view);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS,
- G_CALLBACK (image_display_policy_changed_callback),
- canvas_view);
-
- g_signal_connect_swapped (nautilus_icon_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
- G_CALLBACK (text_attribute_names_changed_callback),
- canvas_view);
-
- g_signal_connect_object (canvas_container, "handle-netscape-url",
- G_CALLBACK (canvas_view_handle_netscape_url), canvas_view, 0);
- g_signal_connect_object (canvas_container, "handle-uri-list",
- G_CALLBACK (canvas_view_handle_uri_list), canvas_view, 0);
- g_signal_connect_object (canvas_container, "handle-text",
- G_CALLBACK (canvas_view_handle_text), canvas_view, 0);
- g_signal_connect_object (canvas_container, "handle-raw",
- G_CALLBACK (canvas_view_handle_raw), canvas_view, 0);
- g_signal_connect_object (canvas_container, "handle-hover",
- G_CALLBACK (canvas_view_handle_hover), canvas_view, 0);
-
- canvas_view->details->clipboard_handler_id =
- g_signal_connect (nautilus_clipboard_monitor_get (),
- "clipboard-info",
- G_CALLBACK (canvas_view_notify_clipboard_info), canvas_view);
-
- view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (canvas_view));
- g_action_map_add_action_entries (G_ACTION_MAP (view_action_group),
- canvas_view_entries,
- G_N_ELEMENTS (canvas_view_entries),
- canvas_view);
- /* Keep the action synced with the actual value, so the toolbar can poll it */
- g_action_group_change_action_state (nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (canvas_view)),
- "zoom-to-level", g_variant_new_int32 (get_default_zoom_level (canvas_view)));
+ NautilusCanvasContainer *canvas_container;
+ GActionGroup *view_action_group;
+
+ canvas_view->details = g_new0 (NautilusCanvasViewDetails, 1);
+ canvas_view->details->sort = &sort_criteria[0];
+ canvas_view->details->icon = g_themed_icon_new ("view-grid-symbolic");
+
+ canvas_container = create_canvas_container (canvas_view);
+ initialize_canvas_container (canvas_view, canvas_container);
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER,
+ G_CALLBACK (default_sort_order_changed_callback),
+ canvas_view);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER,
+ G_CALLBACK (default_sort_order_changed_callback),
+ canvas_view);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS,
+ G_CALLBACK (image_display_policy_changed_callback),
+ canvas_view);
+
+ g_signal_connect_swapped (nautilus_icon_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
+ G_CALLBACK (text_attribute_names_changed_callback),
+ canvas_view);
+
+ g_signal_connect_object (canvas_container, "handle-netscape-url",
+ G_CALLBACK (canvas_view_handle_netscape_url), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "handle-uri-list",
+ G_CALLBACK (canvas_view_handle_uri_list), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "handle-text",
+ G_CALLBACK (canvas_view_handle_text), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "handle-raw",
+ G_CALLBACK (canvas_view_handle_raw), canvas_view, 0);
+ g_signal_connect_object (canvas_container, "handle-hover",
+ G_CALLBACK (canvas_view_handle_hover), canvas_view, 0);
+
+ canvas_view->details->clipboard_handler_id =
+ g_signal_connect (nautilus_clipboard_monitor_get (),
+ "clipboard-info",
+ G_CALLBACK (canvas_view_notify_clipboard_info), canvas_view);
+
+ view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (canvas_view));
+ g_action_map_add_action_entries (G_ACTION_MAP (view_action_group),
+ canvas_view_entries,
+ G_N_ELEMENTS (canvas_view_entries),
+ canvas_view);
+ /* Keep the action synced with the actual value, so the toolbar can poll it */
+ g_action_group_change_action_state (nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (canvas_view)),
+ "zoom-to-level", g_variant_new_int32 (get_default_zoom_level (canvas_view)));
}
NautilusFilesView *
nautilus_canvas_view_new (NautilusWindowSlot *slot)
{
- return g_object_new (NAUTILUS_TYPE_CANVAS_VIEW,
- "window-slot", slot,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_CANVAS_VIEW,
+ "window-slot", slot,
+ NULL);
}
diff --git a/src/nautilus-clipboard-monitor.c b/src/nautilus-clipboard-monitor.c
index 4d164723c..ed1318a86 100644
--- a/src/nautilus-clipboard-monitor.c
+++ b/src/nautilus-clipboard-monitor.c
@@ -1,23 +1,23 @@
/*
- nautilus-clipboard-monitor.c: catch clipboard changes.
-
- Copyright (C) 2004 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-clipboard-monitor.c: catch clipboard changes.
+ *
+ * Copyright (C) 2004 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include "nautilus-clipboard-monitor.h"
@@ -41,14 +41,16 @@
* XFIXES.
*/
-enum {
- CLIPBOARD_CHANGED,
- CLIPBOARD_INFO,
- LAST_SIGNAL
+enum
+{
+ CLIPBOARD_CHANGED,
+ CLIPBOARD_INFO,
+ LAST_SIGNAL
};
-struct NautilusClipboardMonitorDetails {
- NautilusClipboardInfo *info;
+struct NautilusClipboardMonitorDetails
+{
+ NautilusClipboardInfo *info;
};
static guint signals[LAST_SIGNAL];
@@ -61,213 +63,229 @@ static NautilusClipboardMonitor *clipboard_monitor = NULL;
static void
destroy_clipboard_monitor (void)
{
- if (clipboard_monitor != NULL) {
- g_object_unref (clipboard_monitor);
- }
+ if (clipboard_monitor != NULL)
+ {
+ g_object_unref (clipboard_monitor);
+ }
}
NautilusClipboardMonitor *
nautilus_clipboard_monitor_get (void)
{
- GtkClipboard *clipboard;
-
- if (clipboard_monitor == NULL) {
- clipboard_monitor = NAUTILUS_CLIPBOARD_MONITOR (g_object_new (NAUTILUS_TYPE_CLIPBOARD_MONITOR, NULL));
- eel_debug_call_at_shutdown (destroy_clipboard_monitor);
-
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- g_signal_connect (clipboard, "owner-change",
- G_CALLBACK (nautilus_clipboard_monitor_emit_changed), NULL);
- }
- return clipboard_monitor;
+ GtkClipboard *clipboard;
+
+ if (clipboard_monitor == NULL)
+ {
+ clipboard_monitor = NAUTILUS_CLIPBOARD_MONITOR (g_object_new (NAUTILUS_TYPE_CLIPBOARD_MONITOR, NULL));
+ eel_debug_call_at_shutdown (destroy_clipboard_monitor);
+
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ g_signal_connect (clipboard, "owner-change",
+ G_CALLBACK (nautilus_clipboard_monitor_emit_changed), NULL);
+ }
+ return clipboard_monitor;
}
void
nautilus_clipboard_monitor_emit_changed (void)
{
- NautilusClipboardMonitor *monitor;
-
- monitor = nautilus_clipboard_monitor_get ();
-
- g_signal_emit (monitor, signals[CLIPBOARD_CHANGED], 0);
+ NautilusClipboardMonitor *monitor;
+
+ monitor = nautilus_clipboard_monitor_get ();
+
+ g_signal_emit (monitor, signals[CLIPBOARD_CHANGED], 0);
}
static NautilusClipboardInfo *
-nautilus_clipboard_info_new (GList *files,
- gboolean cut)
+nautilus_clipboard_info_new (GList *files,
+ gboolean cut)
{
- NautilusClipboardInfo *info;
+ NautilusClipboardInfo *info;
- info = g_slice_new0 (NautilusClipboardInfo);
- info->files = nautilus_file_list_copy (files);
- info->cut = cut;
+ info = g_slice_new0 (NautilusClipboardInfo);
+ info->files = nautilus_file_list_copy (files);
+ info->cut = cut;
- return info;
+ return info;
}
static NautilusClipboardInfo *
nautilus_clipboard_info_copy (NautilusClipboardInfo *info)
{
- NautilusClipboardInfo *new_info;
+ NautilusClipboardInfo *new_info;
- new_info = NULL;
+ new_info = NULL;
- if (info != NULL) {
- new_info = nautilus_clipboard_info_new (info->files,
- info->cut);
- }
+ if (info != NULL)
+ {
+ new_info = nautilus_clipboard_info_new (info->files,
+ info->cut);
+ }
- return new_info;
+ return new_info;
}
static void
nautilus_clipboard_info_free (NautilusClipboardInfo *info)
{
- nautilus_file_list_free (info->files);
+ nautilus_file_list_free (info->files);
- g_slice_free (NautilusClipboardInfo, info);
+ g_slice_free (NautilusClipboardInfo, info);
}
static void
nautilus_clipboard_monitor_init (NautilusClipboardMonitor *monitor)
{
- monitor->details =
- G_TYPE_INSTANCE_GET_PRIVATE (monitor, NAUTILUS_TYPE_CLIPBOARD_MONITOR,
- NautilusClipboardMonitorDetails);
-}
+ monitor->details =
+ G_TYPE_INSTANCE_GET_PRIVATE (monitor, NAUTILUS_TYPE_CLIPBOARD_MONITOR,
+ NautilusClipboardMonitorDetails);
+}
static void
clipboard_monitor_finalize (GObject *object)
{
- NautilusClipboardMonitor *monitor;
+ NautilusClipboardMonitor *monitor;
- monitor = NAUTILUS_CLIPBOARD_MONITOR (object);
+ monitor = NAUTILUS_CLIPBOARD_MONITOR (object);
- if (monitor->details->info != NULL) {
- nautilus_clipboard_info_free (monitor->details->info);
- monitor->details->info = NULL;
- }
+ if (monitor->details->info != NULL)
+ {
+ nautilus_clipboard_info_free (monitor->details->info);
+ monitor->details->info = NULL;
+ }
- G_OBJECT_CLASS (nautilus_clipboard_monitor_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_clipboard_monitor_parent_class)->finalize (object);
}
static void
nautilus_clipboard_monitor_class_init (NautilusClipboardMonitorClass *klass)
{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = clipboard_monitor_finalize;
-
- copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
-
- signals[CLIPBOARD_CHANGED] =
- g_signal_new ("clipboard-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusClipboardMonitorClass, clipboard_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[CLIPBOARD_INFO] =
- g_signal_new ("clipboard-info",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusClipboardMonitorClass, clipboard_info),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1, G_TYPE_POINTER);
-
- g_type_class_add_private (klass, sizeof (NautilusClipboardMonitorDetails));
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = clipboard_monitor_finalize;
+
+ copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
+
+ signals[CLIPBOARD_CHANGED] =
+ g_signal_new ("clipboard-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusClipboardMonitorClass, clipboard_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[CLIPBOARD_INFO] =
+ g_signal_new ("clipboard-info",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusClipboardMonitorClass, clipboard_info),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1, G_TYPE_POINTER);
+
+ g_type_class_add_private (klass, sizeof (NautilusClipboardMonitorDetails));
}
void
nautilus_clipboard_monitor_set_clipboard_info (NautilusClipboardMonitor *monitor,
- NautilusClipboardInfo *info)
+ NautilusClipboardInfo *info)
{
- if (monitor->details->info != NULL) {
- nautilus_clipboard_info_free (monitor->details->info);
- monitor->details->info = NULL;
- }
+ if (monitor->details->info != NULL)
+ {
+ nautilus_clipboard_info_free (monitor->details->info);
+ monitor->details->info = NULL;
+ }
+
+ monitor->details->info = nautilus_clipboard_info_copy (info);
- monitor->details->info = nautilus_clipboard_info_copy (info);
+ g_signal_emit (monitor, signals[CLIPBOARD_INFO], 0, monitor->details->info);
- g_signal_emit (monitor, signals[CLIPBOARD_INFO], 0, monitor->details->info);
-
- nautilus_clipboard_monitor_emit_changed ();
+ nautilus_clipboard_monitor_emit_changed ();
}
NautilusClipboardInfo *
nautilus_clipboard_monitor_get_clipboard_info (NautilusClipboardMonitor *monitor)
{
- return monitor->details->info;
+ return monitor->details->info;
}
gboolean
nautilus_clipboard_monitor_is_cut (NautilusClipboardMonitor *monitor)
{
- NautilusClipboardInfo *info;
+ NautilusClipboardInfo *info;
- info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
+ info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
- return info != NULL ? info->cut : FALSE;
+ return info != NULL ? info->cut : FALSE;
}
void
nautilus_clear_clipboard_callback (GtkClipboard *clipboard,
gpointer user_data)
{
- nautilus_clipboard_monitor_set_clipboard_info
- (nautilus_clipboard_monitor_get (), NULL);
+ nautilus_clipboard_monitor_set_clipboard_info
+ (nautilus_clipboard_monitor_get (), NULL);
}
static char *
convert_file_list_to_string (NautilusClipboardInfo *info,
- gboolean format_for_text,
- gsize *len)
+ gboolean format_for_text,
+ gsize *len)
{
- GString *uris;
- char *uri, *tmp;
- GFile *f;
- guint i;
- GList *l;
-
- if (format_for_text) {
- uris = g_string_new (NULL);
- } else {
- uris = g_string_new (info->cut ? "cut" : "copy");
- }
-
- for (i = 0, l = info->files; l != NULL; l = l->next, i++) {
- uri = nautilus_file_get_uri (l->data);
-
- if (format_for_text) {
- f = g_file_new_for_uri (uri);
- tmp = g_file_get_parse_name (f);
- g_object_unref (f);
-
- if (tmp != NULL) {
- g_string_append (uris, tmp);
- g_free (tmp);
- } else {
- g_string_append (uris, uri);
- }
-
- /* skip newline for last element */
- if (i + 1 < g_list_length (info->files)) {
- g_string_append_c (uris, '\n');
- }
- } else {
- g_string_append_c (uris, '\n');
- g_string_append (uris, uri);
- }
-
- g_free (uri);
- }
-
- *len = uris->len;
- return g_string_free (uris, FALSE);
+ GString *uris;
+ char *uri, *tmp;
+ GFile *f;
+ guint i;
+ GList *l;
+
+ if (format_for_text)
+ {
+ uris = g_string_new (NULL);
+ }
+ else
+ {
+ uris = g_string_new (info->cut ? "cut" : "copy");
+ }
+
+ for (i = 0, l = info->files; l != NULL; l = l->next, i++)
+ {
+ uri = nautilus_file_get_uri (l->data);
+
+ if (format_for_text)
+ {
+ f = g_file_new_for_uri (uri);
+ tmp = g_file_get_parse_name (f);
+ g_object_unref (f);
+
+ if (tmp != NULL)
+ {
+ g_string_append (uris, tmp);
+ g_free (tmp);
+ }
+ else
+ {
+ g_string_append (uris, uri);
+ }
+
+ /* skip newline for last element */
+ if (i + 1 < g_list_length (info->files))
+ {
+ g_string_append_c (uris, '\n');
+ }
+ }
+ else
+ {
+ g_string_append_c (uris, '\n');
+ g_string_append (uris, uri);
+ }
+
+ g_free (uri);
+ }
+
+ *len = uris->len;
+ return g_string_free (uris, FALSE);
}
void
@@ -276,44 +294,50 @@ nautilus_get_clipboard_callback (GtkClipboard *clipboard,
guint info,
gpointer user_data)
{
- char **uris;
- GList *l;
- int i;
- NautilusClipboardInfo *clipboard_info;
- GdkAtom target;
-
- clipboard_info =
- nautilus_clipboard_monitor_get_clipboard_info (nautilus_clipboard_monitor_get ());
-
- target = gtk_selection_data_get_target (selection_data);
-
- if (gtk_targets_include_uri (&target, 1)) {
- uris = g_malloc ((g_list_length (clipboard_info->files) + 1) * sizeof (char *));
- i = 0;
-
- for (l = clipboard_info->files; l != NULL; l = l->next) {
- uris[i] = nautilus_file_get_uri (l->data);
- i++;
- }
-
- uris[i] = NULL;
-
- gtk_selection_data_set_uris (selection_data, uris);
-
- g_strfreev (uris);
- } else if (gtk_targets_include_text (&target, 1)) {
- char *str;
- gsize len;
-
- str = convert_file_list_to_string (clipboard_info, TRUE, &len);
- gtk_selection_data_set_text (selection_data, str, len);
- g_free (str);
- } else if (target == copied_files_atom) {
- char *str;
- gsize len;
-
- str = convert_file_list_to_string (clipboard_info, FALSE, &len);
- gtk_selection_data_set (selection_data, copied_files_atom, 8, (guchar *) str, len);
- g_free (str);
+ char **uris;
+ GList *l;
+ int i;
+ NautilusClipboardInfo *clipboard_info;
+ GdkAtom target;
+
+ clipboard_info =
+ nautilus_clipboard_monitor_get_clipboard_info (nautilus_clipboard_monitor_get ());
+
+ target = gtk_selection_data_get_target (selection_data);
+
+ if (gtk_targets_include_uri (&target, 1))
+ {
+ uris = g_malloc ((g_list_length (clipboard_info->files) + 1) * sizeof (char *));
+ i = 0;
+
+ for (l = clipboard_info->files; l != NULL; l = l->next)
+ {
+ uris[i] = nautilus_file_get_uri (l->data);
+ i++;
}
+
+ uris[i] = NULL;
+
+ gtk_selection_data_set_uris (selection_data, uris);
+
+ g_strfreev (uris);
+ }
+ else if (gtk_targets_include_text (&target, 1))
+ {
+ char *str;
+ gsize len;
+
+ str = convert_file_list_to_string (clipboard_info, TRUE, &len);
+ gtk_selection_data_set_text (selection_data, str, len);
+ g_free (str);
+ }
+ else if (target == copied_files_atom)
+ {
+ char *str;
+ gsize len;
+
+ str = convert_file_list_to_string (clipboard_info, FALSE, &len);
+ gtk_selection_data_set (selection_data, copied_files_atom, 8, (guchar *) str, len);
+ g_free (str);
+ }
}
diff --git a/src/nautilus-clipboard.c b/src/nautilus-clipboard.c
index 36e68002d..1409e26f6 100644
--- a/src/nautilus-clipboard.c
+++ b/src/nautilus-clipboard.c
@@ -1,4 +1,3 @@
-
/* nautilus-clipboard.c
*
* Nautilus Clipboard support. For now, routines to support component cut
@@ -33,101 +32,117 @@
#include <string.h>
static GList *
-convert_lines_to_str_list (char **lines, gboolean *cut)
+convert_lines_to_str_list (char **lines,
+ gboolean *cut)
{
- int i;
- GList *result;
-
- if (cut) {
- *cut = FALSE;
- }
-
- if (lines[0] == NULL) {
- return NULL;
- }
-
- if (strcmp (lines[0], "cut") == 0) {
- if (cut) {
- *cut = TRUE;
- }
- } else if (strcmp (lines[0], "copy") != 0) {
- return NULL;
- }
-
- result = NULL;
- for (i = 1; lines[i] != NULL; i++) {
- result = g_list_prepend (result, g_strdup (lines[i]));
- }
- return g_list_reverse (result);
+ int i;
+ GList *result;
+
+ if (cut)
+ {
+ *cut = FALSE;
+ }
+
+ if (lines[0] == NULL)
+ {
+ return NULL;
+ }
+
+ if (strcmp (lines[0], "cut") == 0)
+ {
+ if (cut)
+ {
+ *cut = TRUE;
+ }
+ }
+ else if (strcmp (lines[0], "copy") != 0)
+ {
+ return NULL;
+ }
+
+ result = NULL;
+ for (i = 1; lines[i] != NULL; i++)
+ {
+ result = g_list_prepend (result, g_strdup (lines[i]));
+ }
+ return g_list_reverse (result);
}
-GList*
+GList *
nautilus_clipboard_get_uri_list_from_selection_data (GtkSelectionData *selection_data,
- gboolean *cut,
- GdkAtom copied_files_atom)
+ gboolean *cut,
+ GdkAtom copied_files_atom)
{
- GList *items;
- char **lines;
-
- if (gtk_selection_data_get_data_type (selection_data) != copied_files_atom
- || gtk_selection_data_get_length (selection_data) <= 0) {
- items = NULL;
- } else {
- gchar *data;
- /* Not sure why it's legal to assume there's an extra byte
- * past the end of the selection data that it's safe to write
- * to. But gtk_editable_selection_received does this, so I
- * think it is OK.
- */
- data = (gchar *) gtk_selection_data_get_data (selection_data);
- data[gtk_selection_data_get_length (selection_data)] = '\0';
- lines = g_strsplit (data, "\n", 0);
- items = convert_lines_to_str_list (lines, cut);
- g_strfreev (lines);
- }
-
- return items;
+ GList *items;
+ char **lines;
+
+ if (gtk_selection_data_get_data_type (selection_data) != copied_files_atom
+ || gtk_selection_data_get_length (selection_data) <= 0)
+ {
+ items = NULL;
+ }
+ else
+ {
+ gchar *data;
+ /* Not sure why it's legal to assume there's an extra byte
+ * past the end of the selection data that it's safe to write
+ * to. But gtk_editable_selection_received does this, so I
+ * think it is OK.
+ */
+ data = (gchar *) gtk_selection_data_get_data (selection_data);
+ data[gtk_selection_data_get_length (selection_data)] = '\0';
+ lines = g_strsplit (data, "\n", 0);
+ items = convert_lines_to_str_list (lines, cut);
+ g_strfreev (lines);
+ }
+
+ return items;
}
GtkClipboard *
nautilus_clipboard_get (GtkWidget *widget)
{
- return gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (widget)),
- GDK_SELECTION_CLIPBOARD);
+ return gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (widget)),
+ GDK_SELECTION_CLIPBOARD);
}
void
-nautilus_clipboard_clear_if_colliding_uris (GtkWidget *widget,
- const GList *item_uris,
- GdkAtom copied_files_atom)
+nautilus_clipboard_clear_if_colliding_uris (GtkWidget *widget,
+ const GList *item_uris,
+ GdkAtom copied_files_atom)
{
- GtkSelectionData *data;
- GList *clipboard_item_uris, *l;
- gboolean collision;
-
- collision = FALSE;
- data = gtk_clipboard_wait_for_contents (nautilus_clipboard_get (widget),
- copied_files_atom);
- if (data == NULL) {
- return;
- }
-
- clipboard_item_uris = nautilus_clipboard_get_uri_list_from_selection_data (data, NULL,
- copied_files_atom);
-
- for (l = (GList *) item_uris; l; l = l->next) {
- if (g_list_find_custom ((GList *) item_uris, l->data,
- (GCompareFunc) g_strcmp0)) {
- collision = TRUE;
- break;
- }
- }
-
- if (collision) {
- gtk_clipboard_clear (nautilus_clipboard_get (widget));
- }
-
- if (clipboard_item_uris) {
- g_list_free_full (clipboard_item_uris, g_free);
- }
+ GtkSelectionData *data;
+ GList *clipboard_item_uris, *l;
+ gboolean collision;
+
+ collision = FALSE;
+ data = gtk_clipboard_wait_for_contents (nautilus_clipboard_get (widget),
+ copied_files_atom);
+ if (data == NULL)
+ {
+ return;
+ }
+
+ clipboard_item_uris = nautilus_clipboard_get_uri_list_from_selection_data (data, NULL,
+ copied_files_atom);
+
+ for (l = (GList *) item_uris; l; l = l->next)
+ {
+ if (g_list_find_custom ((GList *) item_uris, l->data,
+ (GCompareFunc) g_strcmp0))
+ {
+ collision = TRUE;
+ break;
+ }
+ }
+
+ if (collision)
+ {
+ gtk_clipboard_clear (nautilus_clipboard_get (widget));
+ }
+
+ if (clipboard_item_uris)
+ {
+ g_list_free_full (clipboard_item_uris, g_free);
+ }
}
diff --git a/src/nautilus-column-chooser.c b/src/nautilus-column-chooser.c
index f6e3d65d6..bb3bb8bf6 100644
--- a/src/nautilus-column-chooser.c
+++ b/src/nautilus-column-chooser.c
@@ -1,24 +1,23 @@
-
/* nautilus-column-chooser.h - A column chooser widget
-
- Copyright (C) 2004 Novell, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the column COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Dave Camp <dave@ximian.com>
-*/
+ *
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the column COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Dave Camp <dave@ximian.com>
+ */
#include <config.h>
#include "nautilus-column-chooser.h"
@@ -31,652 +30,691 @@
struct _NautilusColumnChooserDetails
{
- GtkTreeView *view;
- GtkListStore *store;
+ GtkTreeView *view;
+ GtkListStore *store;
- GtkWidget *main_box;
- GtkWidget *move_up_button;
- GtkWidget *move_down_button;
- GtkWidget *use_default_button;
+ GtkWidget *main_box;
+ GtkWidget *move_up_button;
+ GtkWidget *move_down_button;
+ GtkWidget *use_default_button;
- NautilusFile *file;
+ NautilusFile *file;
};
-enum {
- COLUMN_VISIBLE,
- COLUMN_LABEL,
- COLUMN_NAME,
- COLUMN_SENSITIVE,
- NUM_COLUMNS
+enum
+{
+ COLUMN_VISIBLE,
+ COLUMN_LABEL,
+ COLUMN_NAME,
+ COLUMN_SENSITIVE,
+ NUM_COLUMNS
};
-enum {
- PROP_FILE = 1,
- NUM_PROPERTIES
+enum
+{
+ PROP_FILE = 1,
+ NUM_PROPERTIES
};
-enum {
- CHANGED,
- USE_DEFAULT,
- LAST_SIGNAL
+enum
+{
+ CHANGED,
+ USE_DEFAULT,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
-G_DEFINE_TYPE(NautilusColumnChooser, nautilus_column_chooser, GTK_TYPE_BOX);
+G_DEFINE_TYPE (NautilusColumnChooser, nautilus_column_chooser, GTK_TYPE_BOX);
static void nautilus_column_chooser_constructed (GObject *object);
static void
-nautilus_column_chooser_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_column_chooser_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusColumnChooser *chooser;
-
- chooser = NAUTILUS_COLUMN_CHOOSER (object);
-
- switch (param_id) {
- case PROP_FILE:
- chooser->details->file = g_value_get_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusColumnChooser *chooser;
+
+ chooser = NAUTILUS_COLUMN_CHOOSER (object);
+
+ switch (param_id)
+ {
+ case PROP_FILE:
+ {
+ chooser->details->file = g_value_get_object (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_column_chooser_class_init (NautilusColumnChooserClass *chooser_class)
{
- GObjectClass *oclass;
-
- oclass = G_OBJECT_CLASS (chooser_class);
-
- oclass->set_property = nautilus_column_chooser_set_property;
- oclass->constructed = nautilus_column_chooser_constructed;
-
- signals[CHANGED] = g_signal_new
- ("changed",
- G_TYPE_FROM_CLASS (chooser_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusColumnChooserClass,
- changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[USE_DEFAULT] = g_signal_new
- ("use-default",
- G_TYPE_FROM_CLASS (chooser_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusColumnChooserClass,
- use_default),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_object_class_install_property (oclass,
- PROP_FILE,
- g_param_spec_object ("file",
- "File",
- "The file this column chooser is for",
- NAUTILUS_TYPE_FILE,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_WRITABLE));
-
- g_type_class_add_private (chooser_class, sizeof (NautilusColumnChooserDetails));
+ GObjectClass *oclass;
+
+ oclass = G_OBJECT_CLASS (chooser_class);
+
+ oclass->set_property = nautilus_column_chooser_set_property;
+ oclass->constructed = nautilus_column_chooser_constructed;
+
+ signals[CHANGED] = g_signal_new
+ ("changed",
+ G_TYPE_FROM_CLASS (chooser_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusColumnChooserClass,
+ changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[USE_DEFAULT] = g_signal_new
+ ("use-default",
+ G_TYPE_FROM_CLASS (chooser_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusColumnChooserClass,
+ use_default),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_object_class_install_property (oclass,
+ PROP_FILE,
+ g_param_spec_object ("file",
+ "File",
+ "The file this column chooser is for",
+ NAUTILUS_TYPE_FILE,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_WRITABLE));
+
+ g_type_class_add_private (chooser_class, sizeof (NautilusColumnChooserDetails));
}
-static void
+static void
update_buttons (NautilusColumnChooser *chooser)
{
- GtkTreeSelection *selection;
- GtkTreeIter iter;
-
- selection = gtk_tree_view_get_selection (chooser->details->view);
-
- if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
- gboolean visible;
- gboolean top;
- gboolean bottom;
- GtkTreePath *first;
- GtkTreePath *path;
-
- gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
- &iter,
- COLUMN_VISIBLE, &visible,
- -1);
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (chooser->details->store),
- &iter);
- first = gtk_tree_path_new_first ();
-
- top = (gtk_tree_path_compare (path, first) == 0);
-
- gtk_tree_path_free (path);
- gtk_tree_path_free (first);
-
- bottom = !gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store),
- &iter);
-
- gtk_widget_set_sensitive (chooser->details->move_up_button,
- !top);
- gtk_widget_set_sensitive (chooser->details->move_down_button,
- !bottom);
- } else {
- gtk_widget_set_sensitive (chooser->details->move_up_button,
- FALSE);
- gtk_widget_set_sensitive (chooser->details->move_down_button,
- FALSE);
- }
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+
+ selection = gtk_tree_view_get_selection (chooser->details->view);
+
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ gboolean visible;
+ gboolean top;
+ gboolean bottom;
+ GtkTreePath *first;
+ GtkTreePath *path;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
+ &iter,
+ COLUMN_VISIBLE, &visible,
+ -1);
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (chooser->details->store),
+ &iter);
+ first = gtk_tree_path_new_first ();
+
+ top = (gtk_tree_path_compare (path, first) == 0);
+
+ gtk_tree_path_free (path);
+ gtk_tree_path_free (first);
+
+ bottom = !gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store),
+ &iter);
+
+ gtk_widget_set_sensitive (chooser->details->move_up_button,
+ !top);
+ gtk_widget_set_sensitive (chooser->details->move_down_button,
+ !bottom);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (chooser->details->move_up_button,
+ FALSE);
+ gtk_widget_set_sensitive (chooser->details->move_down_button,
+ FALSE);
+ }
}
static void
-list_changed (NautilusColumnChooser *chooser)
+list_changed (NautilusColumnChooser *chooser)
{
- update_buttons (chooser);
- g_signal_emit (chooser, signals[CHANGED], 0);
+ update_buttons (chooser);
+ g_signal_emit (chooser, signals[CHANGED], 0);
}
static void
toggle_path (NautilusColumnChooser *chooser,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- GtkTreeIter iter;
- gboolean visible;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (chooser->details->store),
- &iter, path);
- gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
- &iter, COLUMN_VISIBLE, &visible, -1);
- gtk_list_store_set (chooser->details->store,
- &iter, COLUMN_VISIBLE, !visible, -1);
- list_changed (chooser);
+ GtkTreeIter iter;
+ gboolean visible;
+
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (chooser->details->store),
+ &iter, path);
+ gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
+ &iter, COLUMN_VISIBLE, &visible, -1);
+ gtk_list_store_set (chooser->details->store,
+ &iter, COLUMN_VISIBLE, !visible, -1);
+ list_changed (chooser);
}
static void
visible_toggled_callback (GtkCellRendererToggle *cell,
- char *path_string,
- gpointer user_data)
+ char *path_string,
+ gpointer user_data)
{
- GtkTreePath *path;
-
- path = gtk_tree_path_new_from_string (path_string);
- toggle_path (NAUTILUS_COLUMN_CHOOSER (user_data), path);
- gtk_tree_path_free (path);
+ GtkTreePath *path;
+
+ path = gtk_tree_path_new_from_string (path_string);
+ toggle_path (NAUTILUS_COLUMN_CHOOSER (user_data), path);
+ gtk_tree_path_free (path);
}
static void
-view_row_activated_callback (GtkTreeView *tree_view,
- GtkTreePath *path,
+view_row_activated_callback (GtkTreeView *tree_view,
+ GtkTreePath *path,
GtkTreeViewColumn *column,
- gpointer user_data)
+ gpointer user_data)
{
- toggle_path (NAUTILUS_COLUMN_CHOOSER (user_data), path);
+ toggle_path (NAUTILUS_COLUMN_CHOOSER (user_data), path);
}
static void
-selection_changed_callback (GtkTreeSelection *selection, gpointer user_data)
+selection_changed_callback (GtkTreeSelection *selection,
+ gpointer user_data)
{
- update_buttons (NAUTILUS_COLUMN_CHOOSER (user_data));
+ update_buttons (NAUTILUS_COLUMN_CHOOSER (user_data));
}
static void
-row_deleted_callback (GtkTreeModel *model,
- GtkTreePath *path,
- gpointer user_data)
+row_deleted_callback (GtkTreeModel *model,
+ GtkTreePath *path,
+ gpointer user_data)
{
- list_changed (NAUTILUS_COLUMN_CHOOSER (user_data));
+ list_changed (NAUTILUS_COLUMN_CHOOSER (user_data));
}
-static void move_up_clicked_callback (GtkWidget *button, gpointer user_data);
-static void move_down_clicked_callback (GtkWidget *button, gpointer user_data);
+static void move_up_clicked_callback (GtkWidget *button,
+ gpointer user_data);
+static void move_down_clicked_callback (GtkWidget *button,
+ gpointer user_data);
static void
add_tree_view (NautilusColumnChooser *chooser)
{
- GtkWidget *scrolled;
- GtkWidget *view;
- GtkListStore *store;
- GtkCellRenderer *cell;
- GtkTreeSelection *selection;
-
- view = gtk_tree_view_new ();
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
-
- store = gtk_list_store_new (NUM_COLUMNS,
- G_TYPE_BOOLEAN,
- G_TYPE_STRING,
- G_TYPE_STRING,
- G_TYPE_BOOLEAN);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (view),
- GTK_TREE_MODEL (store));
- g_object_unref (store);
-
- gtk_tree_view_set_reorderable (GTK_TREE_VIEW (view), TRUE);
-
- g_signal_connect (view, "row-activated",
- G_CALLBACK (view_row_activated_callback), chooser);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
- g_signal_connect (selection, "changed",
- G_CALLBACK (selection_changed_callback), chooser);
-
- cell = gtk_cell_renderer_toggle_new ();
-
- g_signal_connect (G_OBJECT (cell), "toggled",
- G_CALLBACK (visible_toggled_callback), chooser);
-
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1, NULL,
- cell,
- "active", COLUMN_VISIBLE,
- "sensitive", COLUMN_SENSITIVE,
- NULL);
-
- cell = gtk_cell_renderer_text_new ();
-
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
- -1, NULL,
- cell,
- "text", COLUMN_LABEL,
- "sensitive", COLUMN_SENSITIVE,
- NULL);
-
- chooser->details->view = GTK_TREE_VIEW (view);
- chooser->details->store = store;
-
- gtk_widget_show (view);
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
- GTK_SHADOW_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_widget_show (GTK_WIDGET (scrolled));
-
- gtk_container_add (GTK_CONTAINER (scrolled), view);
- gtk_box_pack_start (GTK_BOX (chooser->details->main_box), scrolled, TRUE, TRUE, 0);
+ GtkWidget *scrolled;
+ GtkWidget *view;
+ GtkListStore *store;
+ GtkCellRenderer *cell;
+ GtkTreeSelection *selection;
+
+ view = gtk_tree_view_new ();
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (view), FALSE);
+
+ store = gtk_list_store_new (NUM_COLUMNS,
+ G_TYPE_BOOLEAN,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ G_TYPE_BOOLEAN);
+
+ gtk_tree_view_set_model (GTK_TREE_VIEW (view),
+ GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ gtk_tree_view_set_reorderable (GTK_TREE_VIEW (view), TRUE);
+
+ g_signal_connect (view, "row-activated",
+ G_CALLBACK (view_row_activated_callback), chooser);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ g_signal_connect (selection, "changed",
+ G_CALLBACK (selection_changed_callback), chooser);
+
+ cell = gtk_cell_renderer_toggle_new ();
+
+ g_signal_connect (G_OBJECT (cell), "toggled",
+ G_CALLBACK (visible_toggled_callback), chooser);
+
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
+ -1, NULL,
+ cell,
+ "active", COLUMN_VISIBLE,
+ "sensitive", COLUMN_SENSITIVE,
+ NULL);
+
+ cell = gtk_cell_renderer_text_new ();
+
+ gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
+ -1, NULL,
+ cell,
+ "text", COLUMN_LABEL,
+ "sensitive", COLUMN_SENSITIVE,
+ NULL);
+
+ chooser->details->view = GTK_TREE_VIEW (view);
+ chooser->details->store = store;
+
+ gtk_widget_show (view);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_widget_show (GTK_WIDGET (scrolled));
+
+ gtk_container_add (GTK_CONTAINER (scrolled), view);
+ gtk_box_pack_start (GTK_BOX (chooser->details->main_box), scrolled, TRUE, TRUE, 0);
}
static void
-move_up_clicked_callback (GtkWidget *button, gpointer user_data)
+move_up_clicked_callback (GtkWidget *button,
+ gpointer user_data)
{
- NautilusColumnChooser *chooser;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
-
- chooser = NAUTILUS_COLUMN_CHOOSER (user_data);
-
- selection = gtk_tree_view_get_selection (chooser->details->view);
-
- if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
- GtkTreePath *path;
- GtkTreeIter prev;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (chooser->details->store), &iter);
- gtk_tree_path_prev (path);
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (chooser->details->store), &prev, path)) {
- gtk_list_store_move_before (chooser->details->store,
- &iter,
- &prev);
- }
- gtk_tree_path_free (path);
- }
-
- list_changed (chooser);
+ NautilusColumnChooser *chooser;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+
+ chooser = NAUTILUS_COLUMN_CHOOSER (user_data);
+
+ selection = gtk_tree_view_get_selection (chooser->details->view);
+
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ GtkTreePath *path;
+ GtkTreeIter prev;
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (chooser->details->store), &iter);
+ gtk_tree_path_prev (path);
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (chooser->details->store), &prev, path))
+ {
+ gtk_list_store_move_before (chooser->details->store,
+ &iter,
+ &prev);
+ }
+ gtk_tree_path_free (path);
+ }
+
+ list_changed (chooser);
}
static void
-move_down_clicked_callback (GtkWidget *button, gpointer user_data)
+move_down_clicked_callback (GtkWidget *button,
+ gpointer user_data)
{
- NautilusColumnChooser *chooser;
- GtkTreeIter iter;
- GtkTreeSelection *selection;
+ NautilusColumnChooser *chooser;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
- chooser = NAUTILUS_COLUMN_CHOOSER (user_data);
+ chooser = NAUTILUS_COLUMN_CHOOSER (user_data);
- selection = gtk_tree_view_get_selection (chooser->details->view);
+ selection = gtk_tree_view_get_selection (chooser->details->view);
- if (gtk_tree_selection_get_selected (selection, NULL, &iter)) {
- GtkTreeIter next;
+ if (gtk_tree_selection_get_selected (selection, NULL, &iter))
+ {
+ GtkTreeIter next;
- next = iter;
+ next = iter;
- if (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), &next)) {
- gtk_list_store_move_after (chooser->details->store,
- &iter,
- &next);
- }
- }
+ if (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), &next))
+ {
+ gtk_list_store_move_after (chooser->details->store,
+ &iter,
+ &next);
+ }
+ }
- list_changed (chooser);
+ list_changed (chooser);
}
static void
-use_default_clicked_callback (GtkWidget *button, gpointer user_data)
+use_default_clicked_callback (GtkWidget *button,
+ gpointer user_data)
{
- g_signal_emit (NAUTILUS_COLUMN_CHOOSER (user_data),
- signals[USE_DEFAULT], 0);
+ g_signal_emit (NAUTILUS_COLUMN_CHOOSER (user_data),
+ signals[USE_DEFAULT], 0);
}
static void
add_buttons (NautilusColumnChooser *chooser)
{
- GtkWidget *inline_toolbar;
- GtkStyleContext *style_context;
- GtkToolItem *tool_item;
- GtkWidget *box;
-
- inline_toolbar = gtk_toolbar_new ();
- gtk_widget_show (GTK_WIDGET (inline_toolbar));
-
- style_context = gtk_widget_get_style_context (GTK_WIDGET (inline_toolbar));
- gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
- gtk_box_pack_start (GTK_BOX (chooser->details->main_box), inline_toolbar,
- FALSE, FALSE, 0);
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- tool_item = gtk_tool_item_new ();
- gtk_container_add (GTK_CONTAINER (tool_item), box);
- gtk_container_add (GTK_CONTAINER (inline_toolbar), GTK_WIDGET (tool_item));
-
- chooser->details->move_up_button = gtk_button_new_from_icon_name ("go-up-symbolic",
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- g_signal_connect (chooser->details->move_up_button,
- "clicked", G_CALLBACK (move_up_clicked_callback),
- chooser);
- gtk_widget_set_sensitive (chooser->details->move_up_button, FALSE);
- gtk_container_add (GTK_CONTAINER (box), chooser->details->move_up_button);
-
- chooser->details->move_down_button = gtk_button_new_from_icon_name ("go-down-symbolic",
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- g_signal_connect (chooser->details->move_down_button,
- "clicked", G_CALLBACK (move_down_clicked_callback),
- chooser);
- gtk_widget_set_sensitive (chooser->details->move_down_button, FALSE);
- gtk_container_add (GTK_CONTAINER (box), chooser->details->move_down_button);
-
- tool_item = gtk_separator_tool_item_new ();
- gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item), FALSE);
- gtk_tool_item_set_expand (tool_item, TRUE);
- gtk_container_add (GTK_CONTAINER (inline_toolbar), GTK_WIDGET (tool_item));
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- tool_item = gtk_tool_item_new ();
- gtk_container_add (GTK_CONTAINER (tool_item), box);
- gtk_container_add (GTK_CONTAINER (inline_toolbar), GTK_WIDGET (tool_item));
-
- chooser->details->use_default_button = gtk_button_new_with_mnemonic (_("Reset to De_fault"));
- gtk_widget_set_tooltip_text (chooser->details->use_default_button,
- _("Replace the current List Columns settings with the default settings"));
- g_signal_connect (chooser->details->use_default_button,
- "clicked", G_CALLBACK (use_default_clicked_callback),
- chooser);
- gtk_container_add (GTK_CONTAINER (box), chooser->details->use_default_button);
-
- gtk_widget_show_all (inline_toolbar);
+ GtkWidget *inline_toolbar;
+ GtkStyleContext *style_context;
+ GtkToolItem *tool_item;
+ GtkWidget *box;
+
+ inline_toolbar = gtk_toolbar_new ();
+ gtk_widget_show (GTK_WIDGET (inline_toolbar));
+
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (inline_toolbar));
+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_INLINE_TOOLBAR);
+ gtk_box_pack_start (GTK_BOX (chooser->details->main_box), inline_toolbar,
+ FALSE, FALSE, 0);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ tool_item = gtk_tool_item_new ();
+ gtk_container_add (GTK_CONTAINER (tool_item), box);
+ gtk_container_add (GTK_CONTAINER (inline_toolbar), GTK_WIDGET (tool_item));
+
+ chooser->details->move_up_button = gtk_button_new_from_icon_name ("go-up-symbolic",
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+ g_signal_connect (chooser->details->move_up_button,
+ "clicked", G_CALLBACK (move_up_clicked_callback),
+ chooser);
+ gtk_widget_set_sensitive (chooser->details->move_up_button, FALSE);
+ gtk_container_add (GTK_CONTAINER (box), chooser->details->move_up_button);
+
+ chooser->details->move_down_button = gtk_button_new_from_icon_name ("go-down-symbolic",
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+ g_signal_connect (chooser->details->move_down_button,
+ "clicked", G_CALLBACK (move_down_clicked_callback),
+ chooser);
+ gtk_widget_set_sensitive (chooser->details->move_down_button, FALSE);
+ gtk_container_add (GTK_CONTAINER (box), chooser->details->move_down_button);
+
+ tool_item = gtk_separator_tool_item_new ();
+ gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (tool_item), FALSE);
+ gtk_tool_item_set_expand (tool_item, TRUE);
+ gtk_container_add (GTK_CONTAINER (inline_toolbar), GTK_WIDGET (tool_item));
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ tool_item = gtk_tool_item_new ();
+ gtk_container_add (GTK_CONTAINER (tool_item), box);
+ gtk_container_add (GTK_CONTAINER (inline_toolbar), GTK_WIDGET (tool_item));
+
+ chooser->details->use_default_button = gtk_button_new_with_mnemonic (_("Reset to De_fault"));
+ gtk_widget_set_tooltip_text (chooser->details->use_default_button,
+ _("Replace the current List Columns settings with the default settings"));
+ g_signal_connect (chooser->details->use_default_button,
+ "clicked", G_CALLBACK (use_default_clicked_callback),
+ chooser);
+ gtk_container_add (GTK_CONTAINER (box), chooser->details->use_default_button);
+
+ gtk_widget_show_all (inline_toolbar);
}
static void
populate_tree (NautilusColumnChooser *chooser)
{
- GList *columns;
- GList *l;
-
- columns = nautilus_get_columns_for_file (chooser->details->file);
-
- for (l = columns; l != NULL; l = l->next) {
- GtkTreeIter iter;
- NautilusColumn *column;
- char *name;
- char *label;
- gboolean visible = FALSE;
- gboolean sensitive = TRUE;
-
- column = NAUTILUS_COLUMN (l->data);
-
- g_object_get (G_OBJECT (column),
- "name", &name, "label", &label,
- NULL);
-
- if (strcmp (name, "name") == 0) {
- visible = TRUE;
- sensitive = FALSE;
- }
-
- gtk_list_store_append (chooser->details->store, &iter);
- gtk_list_store_set (chooser->details->store, &iter,
- COLUMN_VISIBLE, visible,
- COLUMN_LABEL, label,
- COLUMN_NAME, name,
- COLUMN_SENSITIVE, sensitive,
- -1);
-
- g_free (name);
- g_free (label);
- }
-
- nautilus_column_list_free (columns);
+ GList *columns;
+ GList *l;
+
+ columns = nautilus_get_columns_for_file (chooser->details->file);
+
+ for (l = columns; l != NULL; l = l->next)
+ {
+ GtkTreeIter iter;
+ NautilusColumn *column;
+ char *name;
+ char *label;
+ gboolean visible = FALSE;
+ gboolean sensitive = TRUE;
+
+ column = NAUTILUS_COLUMN (l->data);
+
+ g_object_get (G_OBJECT (column),
+ "name", &name, "label", &label,
+ NULL);
+
+ if (strcmp (name, "name") == 0)
+ {
+ visible = TRUE;
+ sensitive = FALSE;
+ }
+
+ gtk_list_store_append (chooser->details->store, &iter);
+ gtk_list_store_set (chooser->details->store, &iter,
+ COLUMN_VISIBLE, visible,
+ COLUMN_LABEL, label,
+ COLUMN_NAME, name,
+ COLUMN_SENSITIVE, sensitive,
+ -1);
+
+ g_free (name);
+ g_free (label);
+ }
+
+ nautilus_column_list_free (columns);
}
static void
nautilus_column_chooser_constructed (GObject *object)
{
- NautilusColumnChooser *chooser;
+ NautilusColumnChooser *chooser;
- chooser = NAUTILUS_COLUMN_CHOOSER (object);
+ chooser = NAUTILUS_COLUMN_CHOOSER (object);
- populate_tree (chooser);
+ populate_tree (chooser);
- g_signal_connect (chooser->details->store, "row-deleted",
- G_CALLBACK (row_deleted_callback), chooser);
+ g_signal_connect (chooser->details->store, "row-deleted",
+ G_CALLBACK (row_deleted_callback), chooser);
}
static void
nautilus_column_chooser_init (NautilusColumnChooser *chooser)
-{
- chooser->details = G_TYPE_INSTANCE_GET_PRIVATE ((chooser), NAUTILUS_TYPE_COLUMN_CHOOSER, NautilusColumnChooserDetails);
-
- g_object_set (G_OBJECT (chooser),
- "homogeneous", FALSE,
- "spacing", 8,
- "orientation", GTK_ORIENTATION_HORIZONTAL,
- NULL);
-
- chooser->details->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_set_hexpand (chooser->details->main_box, TRUE);
- gtk_widget_show (chooser->details->main_box);
- gtk_container_add (GTK_CONTAINER (chooser), chooser->details->main_box);
-
- add_tree_view (chooser);
- add_buttons (chooser);
+{
+ chooser->details = G_TYPE_INSTANCE_GET_PRIVATE ((chooser), NAUTILUS_TYPE_COLUMN_CHOOSER, NautilusColumnChooserDetails);
+
+ g_object_set (G_OBJECT (chooser),
+ "homogeneous", FALSE,
+ "spacing", 8,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ NULL);
+
+ chooser->details->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_hexpand (chooser->details->main_box, TRUE);
+ gtk_widget_show (chooser->details->main_box);
+ gtk_container_add (GTK_CONTAINER (chooser), chooser->details->main_box);
+
+ add_tree_view (chooser);
+ add_buttons (chooser);
}
-static void
-set_visible_columns (NautilusColumnChooser *chooser,
- char **visible_columns)
+static void
+set_visible_columns (NautilusColumnChooser *chooser,
+ char **visible_columns)
{
- GHashTable *visible_columns_hash;
- GtkTreeIter iter;
- int i;
-
- visible_columns_hash = g_hash_table_new (g_str_hash, g_str_equal);
- /* always show the name column */
- g_hash_table_insert (visible_columns_hash, "name", "name");
- for (i = 0; visible_columns[i] != NULL; ++i) {
- g_hash_table_insert (visible_columns_hash,
- visible_columns[i],
- visible_columns[i]);
- }
-
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser->details->store),
- &iter)) {
- do {
- char *name;
- gboolean visible;
-
- gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
- &iter,
- COLUMN_NAME, &name,
- -1);
-
- visible = (g_hash_table_lookup (visible_columns_hash, name) != NULL);
-
- gtk_list_store_set (chooser->details->store,
- &iter,
- COLUMN_VISIBLE, visible,
- -1);
- g_free (name);
-
- } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), &iter));
- }
-
- g_hash_table_destroy (visible_columns_hash);
+ GHashTable *visible_columns_hash;
+ GtkTreeIter iter;
+ int i;
+
+ visible_columns_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ /* always show the name column */
+ g_hash_table_insert (visible_columns_hash, "name", "name");
+ for (i = 0; visible_columns[i] != NULL; ++i)
+ {
+ g_hash_table_insert (visible_columns_hash,
+ visible_columns[i],
+ visible_columns[i]);
+ }
+
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser->details->store),
+ &iter))
+ {
+ do
+ {
+ char *name;
+ gboolean visible;
+
+ gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
+ &iter,
+ COLUMN_NAME, &name,
+ -1);
+
+ visible = (g_hash_table_lookup (visible_columns_hash, name) != NULL);
+
+ gtk_list_store_set (chooser->details->store,
+ &iter,
+ COLUMN_VISIBLE, visible,
+ -1);
+ g_free (name);
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), &iter));
+ }
+
+ g_hash_table_destroy (visible_columns_hash);
}
static char **
-get_column_names (NautilusColumnChooser *chooser, gboolean only_visible)
+get_column_names (NautilusColumnChooser *chooser,
+ gboolean only_visible)
{
- GPtrArray *ret;
- GtkTreeIter iter;
-
- ret = g_ptr_array_new ();
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser->details->store),
- &iter)) {
- do {
- char *name;
- gboolean visible;
- gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
- &iter,
- COLUMN_VISIBLE, &visible,
- COLUMN_NAME, &name,
- -1);
- if (!only_visible || visible) {
- /* give ownership to the array */
- g_ptr_array_add (ret, name);
- } else {
- g_free (name);
- }
-
- } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), &iter));
- }
- g_ptr_array_add (ret, NULL);
-
- return (char **) g_ptr_array_free (ret, FALSE);
+ GPtrArray *ret;
+ GtkTreeIter iter;
+
+ ret = g_ptr_array_new ();
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser->details->store),
+ &iter))
+ {
+ do
+ {
+ char *name;
+ gboolean visible;
+ gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
+ &iter,
+ COLUMN_VISIBLE, &visible,
+ COLUMN_NAME, &name,
+ -1);
+ if (!only_visible || visible)
+ {
+ /* give ownership to the array */
+ g_ptr_array_add (ret, name);
+ }
+ else
+ {
+ g_free (name);
+ }
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), &iter));
+ }
+ g_ptr_array_add (ret, NULL);
+
+ return (char **) g_ptr_array_free (ret, FALSE);
}
static gboolean
-get_column_iter (NautilusColumnChooser *chooser,
- NautilusColumn *column,
- GtkTreeIter *iter)
+get_column_iter (NautilusColumnChooser *chooser,
+ NautilusColumn *column,
+ GtkTreeIter *iter)
{
- char *column_name;
-
- g_object_get (NAUTILUS_COLUMN (column), "name", &column_name, NULL);
-
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser->details->store),
- iter)) {
- do {
- char *name;
-
-
- gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
- iter,
- COLUMN_NAME, &name,
- -1);
- if (!strcmp (name, column_name)) {
- g_free (column_name);
- g_free (name);
- return TRUE;
- }
-
- g_free (name);
- } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), iter));
- }
- g_free (column_name);
- return FALSE;
+ char *column_name;
+
+ g_object_get (NAUTILUS_COLUMN (column), "name", &column_name, NULL);
+
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (chooser->details->store),
+ iter))
+ {
+ do
+ {
+ char *name;
+
+
+ gtk_tree_model_get (GTK_TREE_MODEL (chooser->details->store),
+ iter,
+ COLUMN_NAME, &name,
+ -1);
+ if (!strcmp (name, column_name))
+ {
+ g_free (column_name);
+ g_free (name);
+ return TRUE;
+ }
+
+ g_free (name);
+ }
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (chooser->details->store), iter));
+ }
+ g_free (column_name);
+ return FALSE;
}
static void
-set_column_order (NautilusColumnChooser *chooser,
- char **column_order)
-
+set_column_order (NautilusColumnChooser *chooser,
+ char **column_order)
{
- GList *columns;
- GList *l;
- GtkTreePath *path;
-
- columns = nautilus_get_columns_for_file (chooser->details->file);
- columns = nautilus_sort_columns (columns, column_order);
-
- g_signal_handlers_block_by_func (chooser->details->store,
- G_CALLBACK (row_deleted_callback),
- chooser);
-
- path = gtk_tree_path_new_first ();
- for (l = columns; l != NULL; l = l->next) {
- GtkTreeIter iter;
-
- if (get_column_iter (chooser, NAUTILUS_COLUMN (l->data), &iter)) {
- GtkTreeIter before;
- if (path) {
- gtk_tree_model_get_iter (GTK_TREE_MODEL (chooser->details->store),
- &before, path);
- gtk_list_store_move_after (chooser->details->store,
- &iter, &before);
- gtk_tree_path_next (path);
-
- } else {
- gtk_list_store_move_after (chooser->details->store,
- &iter, NULL);
- }
- }
- }
- gtk_tree_path_free (path);
- g_signal_handlers_unblock_by_func (chooser->details->store,
- G_CALLBACK (row_deleted_callback),
- chooser);
-
- nautilus_column_list_free (columns);
+ GList *columns;
+ GList *l;
+ GtkTreePath *path;
+
+ columns = nautilus_get_columns_for_file (chooser->details->file);
+ columns = nautilus_sort_columns (columns, column_order);
+
+ g_signal_handlers_block_by_func (chooser->details->store,
+ G_CALLBACK (row_deleted_callback),
+ chooser);
+
+ path = gtk_tree_path_new_first ();
+ for (l = columns; l != NULL; l = l->next)
+ {
+ GtkTreeIter iter;
+
+ if (get_column_iter (chooser, NAUTILUS_COLUMN (l->data), &iter))
+ {
+ GtkTreeIter before;
+ if (path)
+ {
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (chooser->details->store),
+ &before, path);
+ gtk_list_store_move_after (chooser->details->store,
+ &iter, &before);
+ gtk_tree_path_next (path);
+ }
+ else
+ {
+ gtk_list_store_move_after (chooser->details->store,
+ &iter, NULL);
+ }
+ }
+ }
+ gtk_tree_path_free (path);
+ g_signal_handlers_unblock_by_func (chooser->details->store,
+ G_CALLBACK (row_deleted_callback),
+ chooser);
+
+ nautilus_column_list_free (columns);
}
void
-nautilus_column_chooser_set_settings (NautilusColumnChooser *chooser,
- char **visible_columns,
- char **column_order)
+nautilus_column_chooser_set_settings (NautilusColumnChooser *chooser,
+ char **visible_columns,
+ char **column_order)
{
- g_return_if_fail (NAUTILUS_IS_COLUMN_CHOOSER (chooser));
- g_return_if_fail (visible_columns != NULL);
- g_return_if_fail (column_order != NULL);
+ g_return_if_fail (NAUTILUS_IS_COLUMN_CHOOSER (chooser));
+ g_return_if_fail (visible_columns != NULL);
+ g_return_if_fail (column_order != NULL);
- set_visible_columns (chooser, visible_columns);
- set_column_order (chooser, column_order);
+ set_visible_columns (chooser, visible_columns);
+ set_column_order (chooser, column_order);
- list_changed (chooser);
+ list_changed (chooser);
}
void
-nautilus_column_chooser_get_settings (NautilusColumnChooser *chooser,
- char ***visible_columns,
- char ***column_order)
+nautilus_column_chooser_get_settings (NautilusColumnChooser *chooser,
+ char ***visible_columns,
+ char ***column_order)
{
- g_return_if_fail (NAUTILUS_IS_COLUMN_CHOOSER (chooser));
- g_return_if_fail (visible_columns != NULL);
- g_return_if_fail (column_order != NULL);
+ g_return_if_fail (NAUTILUS_IS_COLUMN_CHOOSER (chooser));
+ g_return_if_fail (visible_columns != NULL);
+ g_return_if_fail (column_order != NULL);
- *visible_columns = get_column_names (chooser, TRUE);
- *column_order = get_column_names (chooser, FALSE);
+ *visible_columns = get_column_names (chooser, TRUE);
+ *column_order = get_column_names (chooser, FALSE);
}
GtkWidget *
nautilus_column_chooser_new (NautilusFile *file)
{
- return g_object_new (NAUTILUS_TYPE_COLUMN_CHOOSER, "file", file, NULL);
+ return g_object_new (NAUTILUS_TYPE_COLUMN_CHOOSER, "file", file, NULL);
}
-
diff --git a/src/nautilus-column-utilities.c b/src/nautilus-column-utilities.c
index 0a10229ca..75deca6b5 100644
--- a/src/nautilus-column-utilities.c
+++ b/src/nautilus-column-utilities.c
@@ -1,24 +1,23 @@
-
/* nautilus-column-utilities.h - Utilities related to column specifications
-
- Copyright (C) 2004 Novell, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the column COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Dave Camp <dave@ximian.com>
-*/
+ *
+ * Copyright (C) 2004 Novell, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the column COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Dave Camp <dave@ximian.com>
+ */
#include <config.h>
#include "nautilus-column-utilities.h"
@@ -29,329 +28,357 @@
#include <libnautilus-extension/nautilus-column-provider.h>
#include "nautilus-module.h"
-static const char *default_column_order[] = {
- "name",
- "size",
- "type",
- "owner",
- "group",
- "permissions",
- "mime_type",
- "where",
- "date_modified_with_time",
- "date_modified",
- "date_accessed",
- NULL
+static const char *default_column_order[] =
+{
+ "name",
+ "size",
+ "type",
+ "owner",
+ "group",
+ "permissions",
+ "mime_type",
+ "where",
+ "date_modified_with_time",
+ "date_modified",
+ "date_accessed",
+ NULL
};
static GList *
get_builtin_columns (void)
{
- GList *columns;
-
- columns = g_list_append (NULL,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "name",
- "attribute", "name",
- "label", _("Name"),
- "description", _("The name and icon of the file."),
- NULL));
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "size",
- "attribute", "size",
- "label", _("Size"),
- "description", _("The size of the file."),
- NULL));
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "type",
- "attribute", "type",
- "label", _("Type"),
- "description", _("The type of the file."),
- NULL));
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "date_modified",
- "attribute", "date_modified",
- "label", _("Modified"),
- "description", _("The date the file was modified."),
- "default-sort-order", GTK_SORT_DESCENDING,
- "xalign", 1.0,
- NULL));
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "date_accessed",
- "attribute", "date_accessed",
- "label", _("Accessed"),
- "description", _("The date the file was accessed."),
- "default-sort-order", GTK_SORT_DESCENDING,
- "xalign", 1.0,
- NULL));
-
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "owner",
- "attribute", "owner",
- "label", _("Owner"),
- "description", _("The owner of the file."),
- NULL));
-
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "group",
- "attribute", "group",
- "label", _("Group"),
- "description", _("The group of the file."),
- NULL));
-
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "permissions",
- "attribute", "permissions",
- "label", _("Permissions"),
- "description", _("The permissions of the file."),
- NULL));
-
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "mime_type",
- "attribute", "mime_type",
- "label", _("MIME Type"),
- "description", _("The MIME type of the file."),
- NULL));
-
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "where",
- "attribute", "where",
- "label", _("Location"),
- "description", _("The location of the file."),
- NULL));
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "date_modified_with_time",
- "attribute", "date_modified_with_time",
- "label", _("Modified - Time"),
- "description", _("The date the file was modified."),
- "xalign", 1.0,
- NULL));
-
- return columns;
+ GList *columns;
+
+ columns = g_list_append (NULL,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "name",
+ "attribute", "name",
+ "label", _("Name"),
+ "description", _("The name and icon of the file."),
+ NULL));
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "size",
+ "attribute", "size",
+ "label", _("Size"),
+ "description", _("The size of the file."),
+ NULL));
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "type",
+ "attribute", "type",
+ "label", _("Type"),
+ "description", _("The type of the file."),
+ NULL));
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "date_modified",
+ "attribute", "date_modified",
+ "label", _("Modified"),
+ "description", _("The date the file was modified."),
+ "default-sort-order", GTK_SORT_DESCENDING,
+ "xalign", 1.0,
+ NULL));
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "date_accessed",
+ "attribute", "date_accessed",
+ "label", _("Accessed"),
+ "description", _("The date the file was accessed."),
+ "default-sort-order", GTK_SORT_DESCENDING,
+ "xalign", 1.0,
+ NULL));
+
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "owner",
+ "attribute", "owner",
+ "label", _("Owner"),
+ "description", _("The owner of the file."),
+ NULL));
+
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "group",
+ "attribute", "group",
+ "label", _("Group"),
+ "description", _("The group of the file."),
+ NULL));
+
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "permissions",
+ "attribute", "permissions",
+ "label", _("Permissions"),
+ "description", _("The permissions of the file."),
+ NULL));
+
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "mime_type",
+ "attribute", "mime_type",
+ "label", _("MIME Type"),
+ "description", _("The MIME type of the file."),
+ NULL));
+
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "where",
+ "attribute", "where",
+ "label", _("Location"),
+ "description", _("The location of the file."),
+ NULL));
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "date_modified_with_time",
+ "attribute", "date_modified_with_time",
+ "label", _("Modified - Time"),
+ "description", _("The date the file was modified."),
+ "xalign", 1.0,
+ NULL));
+
+ return columns;
}
static GList *
get_extension_columns (void)
{
- GList *columns;
- GList *providers;
- GList *l;
-
- providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_COLUMN_PROVIDER);
-
- columns = NULL;
-
- for (l = providers; l != NULL; l = l->next) {
- NautilusColumnProvider *provider;
- GList *provider_columns;
-
- provider = NAUTILUS_COLUMN_PROVIDER (l->data);
- provider_columns = nautilus_column_provider_get_columns (provider);
- columns = g_list_concat (columns, provider_columns);
- }
-
- nautilus_module_extension_list_free (providers);
-
- return columns;
+ GList *columns;
+ GList *providers;
+ GList *l;
+
+ providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_COLUMN_PROVIDER);
+
+ columns = NULL;
+
+ for (l = providers; l != NULL; l = l->next)
+ {
+ NautilusColumnProvider *provider;
+ GList *provider_columns;
+
+ provider = NAUTILUS_COLUMN_PROVIDER (l->data);
+ provider_columns = nautilus_column_provider_get_columns (provider);
+ columns = g_list_concat (columns, provider_columns);
+ }
+
+ nautilus_module_extension_list_free (providers);
+
+ return columns;
}
static GList *
get_trash_columns (void)
{
- static GList *columns = NULL;
-
- if (columns == NULL) {
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "trashed_on",
- "attribute", "trashed_on",
- "label", _("Trashed On"),
- "description", _("Date when file was moved to the Trash"),
- "xalign", 1.0,
- NULL));
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "trash_orig_path",
- "attribute", "trash_orig_path",
- "label", _("Original Location"),
- "description", _("Original location of file before moved to the Trash"),
- NULL));
- }
-
- return nautilus_column_list_copy (columns);
+ static GList *columns = NULL;
+
+ if (columns == NULL)
+ {
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "trashed_on",
+ "attribute", "trashed_on",
+ "label", _("Trashed On"),
+ "description", _("Date when file was moved to the Trash"),
+ "xalign", 1.0,
+ NULL));
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "trash_orig_path",
+ "attribute", "trash_orig_path",
+ "label", _("Original Location"),
+ "description", _("Original location of file before moved to the Trash"),
+ NULL));
+ }
+
+ return nautilus_column_list_copy (columns);
}
static GList *
get_search_columns (void)
{
- static GList *columns = NULL;
-
- if (columns == NULL) {
- columns = g_list_append (columns,
- g_object_new (NAUTILUS_TYPE_COLUMN,
- "name", "search_relevance",
- "attribute", "search_relevance",
- "label", _("Relevance"),
- "description", _("Relevance rank for search"),
- NULL));
- }
-
- return nautilus_column_list_copy (columns);
+ static GList *columns = NULL;
+
+ if (columns == NULL)
+ {
+ columns = g_list_append (columns,
+ g_object_new (NAUTILUS_TYPE_COLUMN,
+ "name", "search_relevance",
+ "attribute", "search_relevance",
+ "label", _("Relevance"),
+ "description", _("Relevance rank for search"),
+ NULL));
+ }
+
+ return nautilus_column_list_copy (columns);
}
GList *
nautilus_get_common_columns (void)
{
- static GList *columns = NULL;
+ static GList *columns = NULL;
- if (!columns) {
- columns = g_list_concat (get_builtin_columns (),
- get_extension_columns ());
- }
+ if (!columns)
+ {
+ columns = g_list_concat (get_builtin_columns (),
+ get_extension_columns ());
+ }
- return nautilus_column_list_copy (columns);
+ return nautilus_column_list_copy (columns);
}
GList *
nautilus_get_all_columns (void)
{
- GList *columns = NULL;
+ GList *columns = NULL;
- columns = g_list_concat (nautilus_get_common_columns (),
- get_trash_columns ());
- columns = g_list_concat (columns,
- get_search_columns ());
+ columns = g_list_concat (nautilus_get_common_columns (),
+ get_trash_columns ());
+ columns = g_list_concat (columns,
+ get_search_columns ());
- return columns;
+ return columns;
}
GList *
nautilus_get_columns_for_file (NautilusFile *file)
{
- GList *columns;
+ GList *columns;
- columns = nautilus_get_common_columns ();
+ columns = nautilus_get_common_columns ();
- if (file != NULL && nautilus_file_is_in_trash (file)) {
- columns = g_list_concat (columns,
- get_trash_columns ());
- }
+ if (file != NULL && nautilus_file_is_in_trash (file))
+ {
+ columns = g_list_concat (columns,
+ get_trash_columns ());
+ }
- return columns;
+ return columns;
}
GList *
-nautilus_column_list_copy (GList *columns)
+nautilus_column_list_copy (GList *columns)
{
- GList *ret;
- GList *l;
-
- ret = g_list_copy (columns);
-
- for (l = ret; l != NULL; l = l->next) {
- g_object_ref (l->data);
- }
-
- return ret;
+ GList *ret;
+ GList *l;
+
+ ret = g_list_copy (columns);
+
+ for (l = ret; l != NULL; l = l->next)
+ {
+ g_object_ref (l->data);
+ }
+
+ return ret;
}
void
nautilus_column_list_free (GList *columns)
{
- GList *l;
-
- for (l = columns; l != NULL; l = l->next) {
- g_object_unref (l->data);
- }
-
- g_list_free (columns);
+ GList *l;
+
+ for (l = columns; l != NULL; l = l->next)
+ {
+ g_object_unref (l->data);
+ }
+
+ g_list_free (columns);
}
static int
-strv_index (char **strv, const char *str)
+strv_index (char **strv,
+ const char *str)
{
- int i;
+ int i;
- for (i = 0; strv[i] != NULL; ++i) {
- if (strcmp (strv[i], str) == 0)
- return i;
- }
+ for (i = 0; strv[i] != NULL; ++i)
+ {
+ if (strcmp (strv[i], str) == 0)
+ {
+ return i;
+ }
+ }
- return -1;
+ return -1;
}
static int
-column_compare (NautilusColumn *a, NautilusColumn *b, char **column_order)
+column_compare (NautilusColumn *a,
+ NautilusColumn *b,
+ char **column_order)
{
- int index_a;
- int index_b;
- char *name_a;
- char *name_b;
- int ret;
-
- g_object_get (G_OBJECT (a), "name", &name_a, NULL);
- index_a = strv_index (column_order, name_a);
-
- g_object_get (G_OBJECT (b), "name", &name_b, NULL);
- index_b = strv_index (column_order, name_b);
-
- if (index_a == index_b) {
- int pos_a;
- int pos_b;
-
- pos_a = strv_index ((char **)default_column_order, name_a);
- pos_b = strv_index ((char **)default_column_order, name_b);
-
- if (pos_a == pos_b) {
- char *label_a;
- char *label_b;
-
- g_object_get (G_OBJECT (a), "label", &label_a, NULL);
- g_object_get (G_OBJECT (b), "label", &label_b, NULL);
- ret = strcmp (label_a, label_b);
- g_free (label_a);
- g_free (label_b);
- } else if (pos_a == -1) {
- ret = 1;
- } else if (pos_b == -1) {
- ret = -1;
- } else {
- ret = index_a - index_b;
- }
- } else if (index_a == -1) {
- ret = 1;
- } else if (index_b == -1) {
- ret = -1;
- } else {
- ret = index_a - index_b;
- }
-
- g_free (name_a);
- g_free (name_b);
-
- return ret;
+ int index_a;
+ int index_b;
+ char *name_a;
+ char *name_b;
+ int ret;
+
+ g_object_get (G_OBJECT (a), "name", &name_a, NULL);
+ index_a = strv_index (column_order, name_a);
+
+ g_object_get (G_OBJECT (b), "name", &name_b, NULL);
+ index_b = strv_index (column_order, name_b);
+
+ if (index_a == index_b)
+ {
+ int pos_a;
+ int pos_b;
+
+ pos_a = strv_index ((char **) default_column_order, name_a);
+ pos_b = strv_index ((char **) default_column_order, name_b);
+
+ if (pos_a == pos_b)
+ {
+ char *label_a;
+ char *label_b;
+
+ g_object_get (G_OBJECT (a), "label", &label_a, NULL);
+ g_object_get (G_OBJECT (b), "label", &label_b, NULL);
+ ret = strcmp (label_a, label_b);
+ g_free (label_a);
+ g_free (label_b);
+ }
+ else if (pos_a == -1)
+ {
+ ret = 1;
+ }
+ else if (pos_b == -1)
+ {
+ ret = -1;
+ }
+ else
+ {
+ ret = index_a - index_b;
+ }
+ }
+ else if (index_a == -1)
+ {
+ ret = 1;
+ }
+ else if (index_b == -1)
+ {
+ ret = -1;
+ }
+ else
+ {
+ ret = index_a - index_b;
+ }
+
+ g_free (name_a);
+ g_free (name_b);
+
+ return ret;
}
GList *
-nautilus_sort_columns (GList *columns,
- char **column_order)
+nautilus_sort_columns (GList *columns,
+ char **column_order)
{
- if (column_order == NULL) {
- return columns;
- }
-
- return g_list_sort_with_data (columns,
- (GCompareDataFunc)column_compare,
- column_order);
+ if (column_order == NULL)
+ {
+ return columns;
+ }
+
+ return g_list_sort_with_data (columns,
+ (GCompareDataFunc) column_compare,
+ column_order);
}
-
diff --git a/src/nautilus-compress-dialog-controller.c b/src/nautilus-compress-dialog-controller.c
index ea4a78a37..284b05a21 100644
--- a/src/nautilus-compress-dialog-controller.c
+++ b/src/nautilus-compress-dialog-controller.c
@@ -11,19 +11,20 @@
#define TAR_XZ_DESCRIPTION _("Smaller archives but Linux and Mac only.")
#define SEVEN_ZIP_DESCRIPTION _("Smaller archives but must be installed on Windows and Mac.")
-struct _NautilusCompressDialogController {
- NautilusFileNameWidgetController parent_instance;
+struct _NautilusCompressDialogController
+{
+ NautilusFileNameWidgetController parent_instance;
- GtkWidget *compress_dialog;
- GtkWidget *description_label;
- GtkWidget *name_entry;
- GtkWidget *zip_radio_button;
- GtkWidget *tar_xz_radio_button;
- GtkWidget *seven_zip_radio_button;
+ GtkWidget *compress_dialog;
+ GtkWidget *description_label;
+ GtkWidget *name_entry;
+ GtkWidget *zip_radio_button;
+ GtkWidget *tar_xz_radio_button;
+ GtkWidget *seven_zip_radio_button;
- const char *extension;
+ const char *extension;
- gint response_handler_id;
+ gint response_handler_id;
};
G_DEFINE_TYPE (NautilusCompressDialogController, nautilus_compress_dialog_controller, NAUTILUS_TYPE_FILE_NAME_WIDGET_CONTROLLER);
@@ -33,46 +34,54 @@ nautilus_compress_dialog_controller_name_is_valid (NautilusFileNameWidgetControl
gchar *name,
gchar **error_message)
{
- if (strlen (name) == 0) {
- return FALSE;
- }
-
- if (strstr (name, "/") != NULL) {
- *error_message = _("Archive names cannot contain “/”.");
- } else if (strcmp (name, ".") == 0){
- *error_message = _("An archive cannot be called “.”.");
- } else if (strcmp (name, "..") == 0){
- *error_message = _("An archive cannot be called “..”.");
- }
-
- return *error_message == NULL;
+ if (strlen (name) == 0)
+ {
+ return FALSE;
+ }
+
+ if (strstr (name, "/") != NULL)
+ {
+ *error_message = _("Archive names cannot contain “/”.");
+ }
+ else if (strcmp (name, ".") == 0)
+ {
+ *error_message = _("An archive cannot be called “.”.");
+ }
+ else if (strcmp (name, "..") == 0)
+ {
+ *error_message = _("An archive cannot be called “..”.");
+ }
+
+ return *error_message == NULL;
}
static gchar *
nautilus_compress_dialog_controller_get_new_name (NautilusFileNameWidgetController *controller)
{
- NautilusCompressDialogController *self;
- g_autofree gchar *basename;
- gchar *error_message = NULL;
- gboolean valid_name;
-
- self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (controller);
-
- basename = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (nautilus_compress_dialog_controller_parent_class)->get_new_name (controller);
- /* Do not check or add the extension if the name is invalid */
- valid_name = nautilus_compress_dialog_controller_name_is_valid (controller,
- basename,
- &error_message);
-
- if (!valid_name) {
- return g_strdup (basename);
- }
-
- if (g_str_has_suffix (basename, self->extension)) {
- return g_strdup (basename);
- }
-
- return g_strconcat (basename, self->extension, NULL);
+ NautilusCompressDialogController *self;
+ g_autofree gchar *basename;
+ gchar *error_message = NULL;
+ gboolean valid_name;
+
+ self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (controller);
+
+ basename = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (nautilus_compress_dialog_controller_parent_class)->get_new_name (controller);
+ /* Do not check or add the extension if the name is invalid */
+ valid_name = nautilus_compress_dialog_controller_name_is_valid (controller,
+ basename,
+ &error_message);
+
+ if (!valid_name)
+ {
+ return g_strdup (basename);
+ }
+
+ if (g_str_has_suffix (basename, self->extension))
+ {
+ return g_strdup (basename);
+ }
+
+ return g_strconcat (basename, self->extension, NULL);
}
static void
@@ -80,107 +89,115 @@ compress_dialog_controller_on_response (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- NautilusCompressDialogController *controller;
+ NautilusCompressDialogController *controller;
- controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
+ controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
- if (response_id != GTK_RESPONSE_OK) {
- g_signal_emit_by_name (controller, "cancelled");
- }
+ if (response_id != GTK_RESPONSE_OK)
+ {
+ g_signal_emit_by_name (controller, "cancelled");
+ }
}
static void
update_selected_format (NautilusCompressDialogController *self,
NautilusCompressionFormat format)
{
- const char *extension;
- const char *description;
- GtkWidget *active_button;
-
- switch (format) {
- case NAUTILUS_COMPRESSION_ZIP:
- extension = ".zip";
- description = ZIP_DESCRIPTION;
- active_button = self->zip_radio_button;
- break;
- case NAUTILUS_COMPRESSION_TAR_XZ:
- extension = ".tar.xz";
- description = TAR_XZ_DESCRIPTION;
- active_button = self->tar_xz_radio_button;
- break;
- case NAUTILUS_COMPRESSION_7ZIP:
- extension = ".7z";
- description = SEVEN_ZIP_DESCRIPTION;
- active_button = self->seven_zip_radio_button;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- self->extension = extension;
-
- gtk_label_set_text (GTK_LABEL (self->description_label),
- description);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_button),
- TRUE);
-
- g_settings_set_enum (nautilus_compression_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT,
- format);
- /* Since the extension changes when the button is toggled, force a
- * verification of the new file name by simulating an entry change
- */
- g_signal_emit_by_name (self->name_entry, "changed");
+ const char *extension;
+ const char *description;
+ GtkWidget *active_button;
+
+ switch (format)
+ {
+ case NAUTILUS_COMPRESSION_ZIP:
+ extension = ".zip";
+ description = ZIP_DESCRIPTION;
+ active_button = self->zip_radio_button;
+ break;
+
+ case NAUTILUS_COMPRESSION_TAR_XZ:
+ extension = ".tar.xz";
+ description = TAR_XZ_DESCRIPTION;
+ active_button = self->tar_xz_radio_button;
+ break;
+
+ case NAUTILUS_COMPRESSION_7ZIP:
+ extension = ".7z";
+ description = SEVEN_ZIP_DESCRIPTION;
+ active_button = self->seven_zip_radio_button;
+ break;
+
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ self->extension = extension;
+
+ gtk_label_set_text (GTK_LABEL (self->description_label),
+ description);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (active_button),
+ TRUE);
+
+ g_settings_set_enum (nautilus_compression_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT,
+ format);
+ /* Since the extension changes when the button is toggled, force a
+ * verification of the new file name by simulating an entry change
+ */
+ g_signal_emit_by_name (self->name_entry, "changed");
}
static void
zip_radio_button_on_toggled (GtkToggleButton *toggle_button,
gpointer user_data)
{
- NautilusCompressDialogController *controller;
+ NautilusCompressDialogController *controller;
- controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
+ controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
- if (!gtk_toggle_button_get_active (toggle_button)) {
- return;
- }
+ if (!gtk_toggle_button_get_active (toggle_button))
+ {
+ return;
+ }
- update_selected_format (controller,
- NAUTILUS_COMPRESSION_ZIP);
+ update_selected_format (controller,
+ NAUTILUS_COMPRESSION_ZIP);
}
static void
tar_xz_radio_button_on_toggled (GtkToggleButton *toggle_button,
gpointer user_data)
{
- NautilusCompressDialogController *controller;
+ NautilusCompressDialogController *controller;
- controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
+ controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
- if (!gtk_toggle_button_get_active (toggle_button)) {
- return;
- }
+ if (!gtk_toggle_button_get_active (toggle_button))
+ {
+ return;
+ }
- update_selected_format (controller,
- NAUTILUS_COMPRESSION_TAR_XZ);
+ update_selected_format (controller,
+ NAUTILUS_COMPRESSION_TAR_XZ);
}
static void
seven_zip_radio_button_on_toggled (GtkToggleButton *toggle_button,
gpointer user_data)
{
- NautilusCompressDialogController *controller;
+ NautilusCompressDialogController *controller;
- controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
+ controller = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (user_data);
- if (!gtk_toggle_button_get_active (toggle_button)) {
- return;
- }
+ if (!gtk_toggle_button_get_active (toggle_button))
+ {
+ return;
+ }
- update_selected_format (controller,
- NAUTILUS_COMPRESSION_7ZIP);
+ update_selected_format (controller,
+ NAUTILUS_COMPRESSION_7ZIP);
}
NautilusCompressDialogController *
@@ -188,110 +205,112 @@ nautilus_compress_dialog_controller_new (GtkWindow *parent_window,
NautilusDirectory *destination_directory,
gchar *initial_name)
{
- NautilusCompressDialogController *self;
- g_autoptr (GtkBuilder) builder;
- GtkWidget *compress_dialog;
- GtkWidget *error_revealer;
- GtkWidget *error_label;
- GtkWidget *name_entry;
- GtkWidget *activate_button;
- GtkWidget *description_label;
- GtkWidget *zip_radio_button;
- GtkWidget *tar_xz_radio_button;
- GtkWidget *seven_zip_radio_button;
- NautilusCompressionFormat format;
-
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-compress-dialog.ui");
- compress_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "compress_dialog"));
- error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
- error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
- name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
- activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "activate_button"));
- zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "zip_radio_button"));
- tar_xz_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "tar_xz_radio_button"));
- seven_zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "seven_zip_radio_button"));
- description_label = GTK_WIDGET (gtk_builder_get_object (builder, "description_label"));
-
- gtk_window_set_transient_for (GTK_WINDOW (compress_dialog),
- parent_window);
-
- self = g_object_new (NAUTILUS_TYPE_COMPRESS_DIALOG_CONTROLLER,
- "error-revealer", error_revealer,
- "error-label", error_label,
- "name-entry", name_entry,
- "activate-button", activate_button,
- "containing-directory", destination_directory, NULL);
-
- self->compress_dialog = compress_dialog;
- self->zip_radio_button = zip_radio_button;
- self->tar_xz_radio_button = tar_xz_radio_button;
- self->seven_zip_radio_button = seven_zip_radio_button;
- self->description_label = description_label;
- self->name_entry = name_entry;
-
- self->response_handler_id = g_signal_connect (compress_dialog,
- "response",
- (GCallback)compress_dialog_controller_on_response,
- self);
-
- gtk_builder_add_callback_symbols (builder,
- "zip_radio_button_on_toggled",
- G_CALLBACK (zip_radio_button_on_toggled),
- "tar_xz_radio_button_on_toggled",
- G_CALLBACK (tar_xz_radio_button_on_toggled),
- "seven_zip_radio_button_on_toggled",
- G_CALLBACK (seven_zip_radio_button_on_toggled),
- NULL);
- gtk_builder_connect_signals (builder, self);
-
- format = g_settings_get_enum (nautilus_compression_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT);
-
- update_selected_format (self, format);
-
- if (initial_name != NULL) {
- gtk_entry_set_text (GTK_ENTRY (name_entry), initial_name);
- }
-
- gtk_widget_show_all (compress_dialog);
-
- return self;
+ NautilusCompressDialogController *self;
+ g_autoptr (GtkBuilder) builder;
+ GtkWidget *compress_dialog;
+ GtkWidget *error_revealer;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
+ GtkWidget *description_label;
+ GtkWidget *zip_radio_button;
+ GtkWidget *tar_xz_radio_button;
+ GtkWidget *seven_zip_radio_button;
+ NautilusCompressionFormat format;
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-compress-dialog.ui");
+ compress_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "compress_dialog"));
+ error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
+ error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
+ name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "activate_button"));
+ zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "zip_radio_button"));
+ tar_xz_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "tar_xz_radio_button"));
+ seven_zip_radio_button = GTK_WIDGET (gtk_builder_get_object (builder, "seven_zip_radio_button"));
+ description_label = GTK_WIDGET (gtk_builder_get_object (builder, "description_label"));
+
+ gtk_window_set_transient_for (GTK_WINDOW (compress_dialog),
+ parent_window);
+
+ self = g_object_new (NAUTILUS_TYPE_COMPRESS_DIALOG_CONTROLLER,
+ "error-revealer", error_revealer,
+ "error-label", error_label,
+ "name-entry", name_entry,
+ "activate-button", activate_button,
+ "containing-directory", destination_directory, NULL);
+
+ self->compress_dialog = compress_dialog;
+ self->zip_radio_button = zip_radio_button;
+ self->tar_xz_radio_button = tar_xz_radio_button;
+ self->seven_zip_radio_button = seven_zip_radio_button;
+ self->description_label = description_label;
+ self->name_entry = name_entry;
+
+ self->response_handler_id = g_signal_connect (compress_dialog,
+ "response",
+ (GCallback) compress_dialog_controller_on_response,
+ self);
+
+ gtk_builder_add_callback_symbols (builder,
+ "zip_radio_button_on_toggled",
+ G_CALLBACK (zip_radio_button_on_toggled),
+ "tar_xz_radio_button_on_toggled",
+ G_CALLBACK (tar_xz_radio_button_on_toggled),
+ "seven_zip_radio_button_on_toggled",
+ G_CALLBACK (seven_zip_radio_button_on_toggled),
+ NULL);
+ gtk_builder_connect_signals (builder, self);
+
+ format = g_settings_get_enum (nautilus_compression_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT);
+
+ update_selected_format (self, format);
+
+ if (initial_name != NULL)
+ {
+ gtk_entry_set_text (GTK_ENTRY (name_entry), initial_name);
+ }
+
+ gtk_widget_show_all (compress_dialog);
+
+ return self;
}
static void
nautilus_compress_dialog_controller_init (NautilusCompressDialogController *self)
{
-
}
static void
nautilus_compress_dialog_controller_finalize (GObject *object)
{
- NautilusCompressDialogController *self;
-
- self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (object);
-
- if (self->compress_dialog != NULL) {
- if (self->response_handler_id > 0) {
- g_signal_handler_disconnect (self->compress_dialog,
- self->response_handler_id);
- self->response_handler_id = 0;
- }
- gtk_widget_destroy (self->compress_dialog);
- self->compress_dialog = NULL;
+ NautilusCompressDialogController *self;
+
+ self = NAUTILUS_COMPRESS_DIALOG_CONTROLLER (object);
+
+ if (self->compress_dialog != NULL)
+ {
+ if (self->response_handler_id > 0)
+ {
+ g_signal_handler_disconnect (self->compress_dialog,
+ self->response_handler_id);
+ self->response_handler_id = 0;
}
+ gtk_widget_destroy (self->compress_dialog);
+ self->compress_dialog = NULL;
+ }
- G_OBJECT_CLASS (nautilus_compress_dialog_controller_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_compress_dialog_controller_parent_class)->finalize (object);
}
static void
nautilus_compress_dialog_controller_class_init (NautilusCompressDialogControllerClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass);
- object_class->finalize = nautilus_compress_dialog_controller_finalize;
+ object_class->finalize = nautilus_compress_dialog_controller_finalize;
- parent_class->get_new_name = nautilus_compress_dialog_controller_get_new_name;
- parent_class->name_is_valid = nautilus_compress_dialog_controller_name_is_valid;
+ parent_class->get_new_name = nautilus_compress_dialog_controller_get_new_name;
+ parent_class->name_is_valid = nautilus_compress_dialog_controller_name_is_valid;
}
diff --git a/src/nautilus-dbus-manager.c b/src/nautilus-dbus-manager.c
index 847afb577..77d00d615 100644
--- a/src/nautilus-dbus-manager.c
+++ b/src/nautilus-dbus-manager.c
@@ -32,14 +32,16 @@
#include <gio/gio.h>
-struct _NautilusDBusManager {
- GObject parent;
+struct _NautilusDBusManager
+{
+ GObject parent;
- NautilusDBusFileOperations *file_operations;
+ NautilusDBusFileOperations *file_operations;
};
-struct _NautilusDBusManagerClass {
- GObjectClass parent_class;
+struct _NautilusDBusManagerClass
+{
+ GObjectClass parent_class;
};
G_DEFINE_TYPE (NautilusDBusManager, nautilus_dbus_manager, G_TYPE_OBJECT);
@@ -47,128 +49,135 @@ G_DEFINE_TYPE (NautilusDBusManager, nautilus_dbus_manager, G_TYPE_OBJECT);
static void
nautilus_dbus_manager_dispose (GObject *object)
{
- NautilusDBusManager *self = (NautilusDBusManager *) object;
+ NautilusDBusManager *self = (NautilusDBusManager *) object;
- if (self->file_operations) {
- g_object_unref (self->file_operations);
- self->file_operations = NULL;
- }
+ if (self->file_operations)
+ {
+ g_object_unref (self->file_operations);
+ self->file_operations = NULL;
+ }
- G_OBJECT_CLASS (nautilus_dbus_manager_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_dbus_manager_parent_class)->dispose (object);
}
static gboolean
handle_copy_file (NautilusDBusFileOperations *object,
- GDBusMethodInvocation *invocation,
- const gchar *source_uri,
- const gchar *source_display_name,
- const gchar *dest_dir_uri,
- const gchar *dest_name)
+ GDBusMethodInvocation *invocation,
+ const gchar *source_uri,
+ const gchar *source_display_name,
+ const gchar *dest_dir_uri,
+ const gchar *dest_name)
{
- GFile *source_file, *target_dir;
- const gchar *target_name = NULL, *source_name = NULL;
+ GFile *source_file, *target_dir;
+ const gchar *target_name = NULL, *source_name = NULL;
- source_file = g_file_new_for_uri (source_uri);
- target_dir = g_file_new_for_uri (dest_dir_uri);
+ source_file = g_file_new_for_uri (source_uri);
+ target_dir = g_file_new_for_uri (dest_dir_uri);
- if (dest_name != NULL && dest_name[0] != '\0')
- target_name = dest_name;
+ if (dest_name != NULL && dest_name[0] != '\0')
+ {
+ target_name = dest_name;
+ }
- if (source_display_name != NULL && source_display_name[0] != '\0')
- source_name = source_display_name;
+ if (source_display_name != NULL && source_display_name[0] != '\0')
+ {
+ source_name = source_display_name;
+ }
- nautilus_file_operations_copy_file (source_file, target_dir, source_name, target_name,
- NULL, NULL, NULL);
+ nautilus_file_operations_copy_file (source_file, target_dir, source_name, target_name,
+ NULL, NULL, NULL);
- g_object_unref (source_file);
- g_object_unref (target_dir);
+ g_object_unref (source_file);
+ g_object_unref (target_dir);
- nautilus_dbus_file_operations_complete_copy_file (object, invocation);
- return TRUE; /* invocation was handled */
+ nautilus_dbus_file_operations_complete_copy_file (object, invocation);
+ return TRUE; /* invocation was handled */
}
static gboolean
-handle_copy_uris (NautilusDBusFileOperations *object,
- GDBusMethodInvocation *invocation,
- const gchar **sources,
- const gchar *destination)
+handle_copy_uris (NautilusDBusFileOperations *object,
+ GDBusMethodInvocation *invocation,
+ const gchar **sources,
+ const gchar *destination)
{
- GList *source_files = NULL;
- GFile *dest_dir;
- gint idx;
+ GList *source_files = NULL;
+ GFile *dest_dir;
+ gint idx;
- dest_dir = g_file_new_for_uri (destination);
+ dest_dir = g_file_new_for_uri (destination);
- for (idx = 0; sources[idx] != NULL; idx++)
- source_files = g_list_prepend (source_files,
- g_file_new_for_uri (sources[idx]));
+ for (idx = 0; sources[idx] != NULL; idx++)
+ {
+ source_files = g_list_prepend (source_files,
+ g_file_new_for_uri (sources[idx]));
+ }
- nautilus_file_operations_copy (source_files, NULL,
- dest_dir,
- NULL, NULL, NULL);
+ nautilus_file_operations_copy (source_files, NULL,
+ dest_dir,
+ NULL, NULL, NULL);
- g_list_free_full (source_files, g_object_unref);
- g_object_unref (dest_dir);
+ g_list_free_full (source_files, g_object_unref);
+ g_object_unref (dest_dir);
- nautilus_dbus_file_operations_complete_copy_uris (object, invocation);
- return TRUE; /* invocation was handled */
+ nautilus_dbus_file_operations_complete_copy_uris (object, invocation);
+ return TRUE; /* invocation was handled */
}
static gboolean
handle_empty_trash (NautilusDBusFileOperations *object,
- GDBusMethodInvocation *invocation)
+ GDBusMethodInvocation *invocation)
{
- nautilus_file_operations_empty_trash (NULL);
+ nautilus_file_operations_empty_trash (NULL);
- nautilus_dbus_file_operations_complete_empty_trash (object, invocation);
- return TRUE; /* invocation was handled */
+ nautilus_dbus_file_operations_complete_empty_trash (object, invocation);
+ return TRUE; /* invocation was handled */
}
static void
nautilus_dbus_manager_init (NautilusDBusManager *self)
{
- self->file_operations = nautilus_dbus_file_operations_skeleton_new ();
-
- g_signal_connect (self->file_operations,
- "handle-copy-uris",
- G_CALLBACK (handle_copy_uris),
- self);
- g_signal_connect (self->file_operations,
- "handle-copy-file",
- G_CALLBACK (handle_copy_file),
- self);
- g_signal_connect (self->file_operations,
- "handle-empty-trash",
- G_CALLBACK (handle_empty_trash),
- self);
+ self->file_operations = nautilus_dbus_file_operations_skeleton_new ();
+
+ g_signal_connect (self->file_operations,
+ "handle-copy-uris",
+ G_CALLBACK (handle_copy_uris),
+ self);
+ g_signal_connect (self->file_operations,
+ "handle-copy-file",
+ G_CALLBACK (handle_copy_file),
+ self);
+ g_signal_connect (self->file_operations,
+ "handle-empty-trash",
+ G_CALLBACK (handle_empty_trash),
+ self);
}
static void
nautilus_dbus_manager_class_init (NautilusDBusManagerClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
- oclass->dispose = nautilus_dbus_manager_dispose;
+ oclass->dispose = nautilus_dbus_manager_dispose;
}
NautilusDBusManager *
nautilus_dbus_manager_new (void)
{
- return g_object_new (nautilus_dbus_manager_get_type (),
- NULL);
+ return g_object_new (nautilus_dbus_manager_get_type (),
+ NULL);
}
gboolean
-nautilus_dbus_manager_register (NautilusDBusManager *self,
- GDBusConnection *connection,
- GError **error)
+nautilus_dbus_manager_register (NautilusDBusManager *self,
+ GDBusConnection *connection,
+ GError **error)
{
- return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->file_operations),
- connection, "/org/gnome/Nautilus", error);
+ return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->file_operations),
+ connection, "/org/gnome/Nautilus", error);
}
void
nautilus_dbus_manager_unregister (NautilusDBusManager *self)
{
- g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->file_operations));
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->file_operations));
}
diff --git a/src/nautilus-debug.c b/src/nautilus-debug.c
index 55f59913b..972166fe8 100644
--- a/src/nautilus-debug.c
+++ b/src/nautilus-debug.c
@@ -33,131 +33,145 @@
static DebugFlags flags = 0;
static gboolean initialized = FALSE;
-static GDebugKey keys[] = {
- { "Application", NAUTILUS_DEBUG_APPLICATION },
- { "Bookmarks", NAUTILUS_DEBUG_BOOKMARKS },
- { "DBus", NAUTILUS_DEBUG_DBUS },
- { "DirectoryView", NAUTILUS_DEBUG_DIRECTORY_VIEW },
- { "File", NAUTILUS_DEBUG_FILE },
- { "CanvasContainer", NAUTILUS_DEBUG_CANVAS_CONTAINER },
- { "IconView", NAUTILUS_DEBUG_CANVAS_VIEW },
- { "ListView", NAUTILUS_DEBUG_LIST_VIEW },
- { "Mime", NAUTILUS_DEBUG_MIME },
- { "Places", NAUTILUS_DEBUG_PLACES },
- { "Previewer", NAUTILUS_DEBUG_PREVIEWER },
- { "Search", NAUTILUS_DEBUG_SEARCH },
- { "SearchHit", NAUTILUS_DEBUG_SEARCH_HIT },
- { "Smclient", NAUTILUS_DEBUG_SMCLIENT },
- { "Window", NAUTILUS_DEBUG_WINDOW },
- { "Undo", NAUTILUS_DEBUG_UNDO },
- { 0, }
+static GDebugKey keys[] =
+{
+ { "Application", NAUTILUS_DEBUG_APPLICATION },
+ { "Bookmarks", NAUTILUS_DEBUG_BOOKMARKS },
+ { "DBus", NAUTILUS_DEBUG_DBUS },
+ { "DirectoryView", NAUTILUS_DEBUG_DIRECTORY_VIEW },
+ { "File", NAUTILUS_DEBUG_FILE },
+ { "CanvasContainer", NAUTILUS_DEBUG_CANVAS_CONTAINER },
+ { "IconView", NAUTILUS_DEBUG_CANVAS_VIEW },
+ { "ListView", NAUTILUS_DEBUG_LIST_VIEW },
+ { "Mime", NAUTILUS_DEBUG_MIME },
+ { "Places", NAUTILUS_DEBUG_PLACES },
+ { "Previewer", NAUTILUS_DEBUG_PREVIEWER },
+ { "Search", NAUTILUS_DEBUG_SEARCH },
+ { "SearchHit", NAUTILUS_DEBUG_SEARCH_HIT },
+ { "Smclient", NAUTILUS_DEBUG_SMCLIENT },
+ { "Window", NAUTILUS_DEBUG_WINDOW },
+ { "Undo", NAUTILUS_DEBUG_UNDO },
+ { 0, }
};
static void
nautilus_debug_set_flags_from_env ()
{
- guint nkeys;
- const gchar *flags_string;
+ guint nkeys;
+ const gchar *flags_string;
- for (nkeys = 0; keys[nkeys].value; nkeys++);
+ for (nkeys = 0; keys[nkeys].value; nkeys++)
+ {
+ ;
+ }
- flags_string = g_getenv ("NAUTILUS_DEBUG");
+ flags_string = g_getenv ("NAUTILUS_DEBUG");
- if (flags_string)
- nautilus_debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
+ if (flags_string)
+ {
+ nautilus_debug_set_flags (g_parse_debug_string (flags_string, keys, nkeys));
+ }
- initialized = TRUE;
+ initialized = TRUE;
}
void
nautilus_debug_set_flags (DebugFlags new_flags)
{
- flags |= new_flags;
- initialized = TRUE;
+ flags |= new_flags;
+ initialized = TRUE;
}
gboolean
nautilus_debug_flag_is_set (DebugFlags flag)
{
- return flag & flags;
+ return flag & flags;
}
void
-nautilus_debug (DebugFlags flag,
+nautilus_debug (DebugFlags flag,
const gchar *format,
...)
{
- va_list args;
- va_start (args, format);
- nautilus_debug_valist (flag, format, args);
- va_end (args);
+ va_list args;
+ va_start (args, format);
+ nautilus_debug_valist (flag, format, args);
+ va_end (args);
}
void
-nautilus_debug_valist (DebugFlags flag,
+nautilus_debug_valist (DebugFlags flag,
const gchar *format,
- va_list args)
+ va_list args)
{
- if (G_UNLIKELY(!initialized))
- nautilus_debug_set_flags_from_env ();
+ if (G_UNLIKELY (!initialized))
+ {
+ nautilus_debug_set_flags_from_env ();
+ }
- if (flag & flags)
- g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
+ if (flag & flags)
+ {
+ g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
+ }
}
static void
-nautilus_debug_files_valist (DebugFlags flag,
- GList *files,
+nautilus_debug_files_valist (DebugFlags flag,
+ GList *files,
const gchar *format,
- va_list args)
+ va_list args)
{
- NautilusFile *file;
- GList *l;
- gchar *uri, *msg;
+ NautilusFile *file;
+ GList *l;
+ gchar *uri, *msg;
- if (G_UNLIKELY (!initialized))
- nautilus_debug_set_flags_from_env ();
+ if (G_UNLIKELY (!initialized))
+ {
+ nautilus_debug_set_flags_from_env ();
+ }
- if (!(flag & flags))
- return;
+ if (!(flag & flags))
+ {
+ return;
+ }
- msg = g_strdup_vprintf (format, args);
+ msg = g_strdup_vprintf (format, args);
- g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:", msg);
+ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "%s:", msg);
- for (l = files; l != NULL; l = l->next)
+ for (l = files; l != NULL; l = l->next)
{
- file = l->data;
- uri = nautilus_file_get_uri (file);
-
- if (nautilus_file_is_gone (file)) {
- gchar *new_uri;
-
- /* Hack: this will create an invalid URI, but it's for
- * display purposes only.
- */
- new_uri = g_strconcat (uri ? uri : "", " (gone)", NULL);
+ file = l->data;
+ uri = nautilus_file_get_uri (file);
+
+ if (nautilus_file_is_gone (file))
+ {
+ gchar *new_uri;
+
+ /* Hack: this will create an invalid URI, but it's for
+ * display purposes only.
+ */
+ new_uri = g_strconcat (uri ? uri : "", " (gone)", NULL);
+ g_free (uri);
+ uri = new_uri;
+ }
+
+ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, " %s", uri);
g_free (uri);
- uri = new_uri;
- }
-
- g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, " %s", uri);
- g_free (uri);
}
- g_free (msg);
+ g_free (msg);
}
void
-nautilus_debug_files (DebugFlags flag,
- GList *files,
+nautilus_debug_files (DebugFlags flag,
+ GList *files,
const gchar *format,
...)
{
- va_list args;
+ va_list args;
- va_start (args, format);
- nautilus_debug_files_valist (flag, files, format, args);
- va_end (args);
+ va_start (args, format);
+ nautilus_debug_files_valist (flag, files, format, args);
+ va_end (args);
}
-
diff --git a/src/nautilus-default-file-icon.c b/src/nautilus-default-file-icon.c
index cceaf0deb..cfe955ecf 100644
--- a/src/nautilus-default-file-icon.c
+++ b/src/nautilus-default-file-icon.c
@@ -1,23 +1,23 @@
/*
- Default file icon used by the icon factory.
-
- Copyright (C) 2000 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * Default file icon used by the icon factory.
+ *
+ * Copyright (C) 2000 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
#include "nautilus-default-file-icon.h"
@@ -25,510 +25,510 @@
const int nautilus_default_file_icon_width = 48;
const int nautilus_default_file_icon_height = 48;
const unsigned char nautilus_default_file_icon[] =
- /* This is from text-x-preview.svg in the gnome icon theme */
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\243\255\243\31\252\254\245\307\246\251\243\374\246\251\243\377\246"
- "\251\243\377\246\251\242\377\246\250\242\377\246\250\242\377\246\250"
- "\242\377\245\250\242\377\245\250\242\377\245\250\242\377\245\250\241"
- "\377\245\247\241\377\245\247\241\377\245\247\241\377\244\247\241\377"
- "\244\247\241\377\244\247\241\377\244\247\240\377\244\246\240\377\244"
- "\246\240\377\244\246\240\377\243\246\240\377\243\246\240\377\243\246"
- "\237\377\244\247\240\371\245\251\242\333\245\247\242\216\246\246\233"
- "\27\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\252\254\246\277\347\351"
- "\346\376\377\377\376\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\374\374\374\377\362\363\361\377\353\355\352\377"
- "\344\345\342\377\276\300\272\371\244\245\240\366\244\247\237h\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\246\251\244\373\376\376\376\377\354\355\352\377"
- "\352\354\350\377\351\353\347\377\351\353\347\377\350\352\346\377\350"
- "\351\345\377\347\351\344\377\346\350\344\377\345\350\343\377\344\347"
- "\342\377\344\346\341\377\343\346\340\377\342\345\340\377\341\344\337"
- "\377\341\343\336\377\340\342\335\377\337\342\334\377\337\341\333\377"
- "\336\340\332\377\335\337\332\377\334\337\331\377\333\336\330\377\332"
- "\335\327\377\331\334\326\377\331\334\325\377\333\334\327\377\362\363"
- "\361\377\333\335\331\377\250\253\245\364\245\246\240\236\200\200\200"
- "\2\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\245\247\241\377\377\377\377\377\352\354\350\377\351\353\347\377\351"
- "\353\347\377\350\352\346\377\350\352\346\377\347\351\345\377\347\350"
- "\344\377\346\351\344\377\345\350\343\377\344\347\342\377\344\346\342"
- "\377\343\346\341\377\342\345\340\377\341\344\337\377\341\344\336\377"
- "\340\343\335\377\340\342\335\377\337\341\334\377\336\341\333\377\335"
- "\340\332\377\334\337\331\377\334\336\330\377\333\336\327\377\332\335"
- "\326\377\331\334\325\377\326\331\322\377\326\330\324\377\372\372\371"
- "\377\333\336\331\377\253\257\251\364\241\246\240\251\377\377\377\1\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\244\247\240\377"
- "\377\377\377\377\351\353\347\377\351\353\347\377\350\353\347\377\350"
- "\352\346\377\347\352\345\377\347\351\345\377\347\350\344\377\346\350"
- "\343\377\345\347\343\377\344\347\343\377\344\346\342\377\343\346\341"
- "\377\342\345\340\377\342\344\337\377\341\344\336\377\341\343\336\377"
- "\340\342\335\377\337\342\334\377\337\341\333\377\336\340\332\377\335"
- "\340\332\377\334\337\331\377\333\336\330\377\333\335\327\377\332\335"
- "\326\377\330\333\324\377\312\314\307\377\374\375\374\377\363\364\362"
- "\377\325\330\322\377\253\255\250\365\242\244\235\222\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\243\246\240\377\377\377\377\377"
- "\351\352\346\377\350\352\346\377\350\352\346\377\347\352\346\377\347"
- "\351\345\377\347\351\344\377\346\350\344\377\346\350\343\377\345\347"
- "\342\377\344\346\342\377\344\346\342\377\343\346\341\377\342\345\340"
- "\377\342\345\337\377\342\344\337\377\341\343\336\377\340\343\335\377"
- "\340\342\334\377\337\341\333\377\336\341\333\377\335\340\332\377\335"
- "\337\331\377\334\337\330\377\333\336\327\377\332\335\326\377\332\335"
- "\326\377\314\317\310\377\372\372\372\377\370\370\370\377\346\351\345"
- "\377\324\330\321\377\245\247\241\364\241\244\235Q\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\243\245\237\377\377\377\377\377\350\352\346\377"
- "\350\351\345\377\347\351\345\377\347\351\345\377\347\351\344\377\346"
- "\350\344\377\346\350\343\377\345\347\343\377\345\347\342\377\344\346"
- "\342\377\344\346\341\377\343\345\341\377\342\345\340\377\342\345\337"
- "\377\341\344\337\377\340\344\336\377\341\343\335\377\340\342\334\377"
- "\337\342\334\377\336\341\333\377\336\340\332\377\335\340\331\377\334"
- "\337\331\377\334\336\330\377\333\336\327\377\332\335\326\377\320\323"
- "\314\377\305\307\301\377\271\274\266\377\262\265\257\377\300\303\276"
- "\377\314\317\311\377\240\244\234\355\222\222\222\7\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\242\245\237\377\377\377\377\377\347\351\345\377\347\351\344"
- "\377\347\350\345\377\346\350\344\377\346\350\344\377\346\350\343\377"
- "\346\350\343\377\345\347\342\377\345\347\342\377\344\346\342\377\344"
- "\346\341\377\343\345\341\377\342\345\340\377\342\345\337\377\341\344"
- "\337\377\341\344\336\377\341\343\335\377\340\343\334\377\337\342\334"
- "\377\337\341\333\377\336\341\332\377\335\340\332\377\335\340\331\377"
- "\334\337\330\377\333\336\327\377\333\336\327\377\322\325\317\377\307"
- "\312\304\377\274\300\271\377\261\264\257\377\246\250\244\377\302\304"
- "\300\377\260\263\255\363\237\242\235h\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\241"
- "\244\236\377\377\377\377\377\347\351\344\377\346\350\344\377\346\350"
- "\344\377\346\350\344\377\345\350\343\377\346\350\343\377\345\347\342"
- "\377\345\347\343\377\344\347\342\377\344\346\342\377\343\346\341\377"
- "\343\345\341\377\342\345\340\377\342\344\337\377\342\344\337\377\341"
- "\343\336\377\341\343\335\377\340\343\335\377\340\342\334\377\337\342"
- "\333\377\336\341\333\377\336\341\332\377\335\340\331\377\335\340\331"
- "\377\334\337\330\377\334\337\330\377\334\337\330\377\333\335\327\377"
- "\331\333\325\377\322\324\317\377\306\310\303\377\273\276\271\377\322"
- "\325\320\377\242\244\236\312\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\241\243\235"
- "\377\377\377\377\377\346\350\343\377\346\350\344\377\346\350\343\377"
- "\345\347\343\377\345\347\343\377\345\347\342\377\345\347\342\377\345"
- "\347\342\377\344\347\342\377\344\346\341\377\343\346\341\377\343\345"
- "\340\377\342\345\340\377\342\344\337\377\341\344\337\377\341\343\336"
- "\377\341\343\335\377\340\342\335\377\340\342\334\377\337\341\334\377"
- "\337\341\334\377\336\341\333\377\336\340\333\377\335\340\332\377\335"
- "\337\331\377\335\337\331\377\335\337\331\377\334\337\331\377\334\337"
- "\331\377\334\337\331\377\334\337\331\377\336\341\333\377\350\352\347"
- "\377\236\240\232\370\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\240\242\234\377\377"
- "\377\377\377\346\347\343\377\345\350\343\377\345\347\343\377\345\347"
- "\343\377\345\347\342\377\344\347\342\377\345\346\342\377\344\347\342"
- "\377\344\346\342\377\344\346\341\377\343\346\341\377\343\345\340\377"
- "\342\345\340\377\342\344\337\377\341\344\337\377\342\343\337\377\341"
- "\343\336\377\341\342\336\377\340\342\335\377\340\341\335\377\337\341"
- "\334\377\336\340\333\377\336\340\333\377\336\340\333\377\336\340\333"
- "\377\336\340\333\377\336\340\333\377\336\340\333\377\335\340\332\377"
- "\335\340\332\377\335\340\332\377\337\342\334\377\363\364\362\377\233"
- "\235\230\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\237\242\234\377\377\377"
- "\377\377\345\347\342\377\345\347\342\377\345\347\343\377\345\347\342"
- "\377\344\347\342\377\344\346\342\377\345\346\342\377\344\346\342\377"
- "\344\346\341\377\344\346\341\377\343\346\341\377\343\345\340\377\342"
- "\345\340\377\342\344\337\377\341\344\337\377\342\344\337\377\341\343"
- "\336\377\341\343\336\377\340\342\335\377\340\342\335\377\337\341\334"
- "\377\337\341\334\377\337\341\334\377\337\341\334\377\337\341\334\377"
- "\337\341\334\377\337\341\334\377\337\341\334\377\337\341\334\377\336"
- "\341\333\377\336\341\333\377\340\343\335\377\373\373\372\377\232\235"
- "\227\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\237\241\233\377\377\377\377\377"
- "\344\347\342\377\345\346\342\377\345\347\342\377\344\347\342\377\344"
- "\347\342\377\344\346\341\377\344\346\342\377\344\346\342\377\344\345"
- "\341\377\343\346\341\377\343\346\341\377\343\345\340\377\342\345\340"
- "\377\342\345\337\377\341\344\340\377\341\344\337\377\341\343\337\377"
- "\341\343\336\377\340\342\336\377\340\342\335\377\340\342\335\377\340"
- "\342\335\377\340\342\335\377\340\342\335\377\340\342\335\377\340\342"
- "\335\377\340\342\335\377\337\342\335\377\337\342\335\377\337\342\334"
- "\377\337\342\334\377\341\344\336\377\375\375\375\377\232\234\226\377"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\236\240\233\377\377\377\377\377\344\346"
- "\341\377\345\346\342\377\344\346\342\377\344\347\342\377\344\346\341"
- "\377\344\346\341\377\343\346\342\377\344\346\341\377\344\346\341\377"
- "\343\345\341\377\343\345\340\377\343\345\340\377\342\345\340\377\342"
- "\345\337\377\341\344\340\377\341\344\337\377\342\344\337\377\341\343"
- "\336\377\341\343\336\377\341\343\336\377\341\343\336\377\341\343\336"
- "\377\341\343\336\377\341\343\336\377\341\343\336\377\341\343\336\377"
- "\341\343\336\377\341\343\336\377\340\343\336\377\340\343\336\377\340"
- "\343\335\377\342\345\337\377\375\375\375\377\231\233\226\377\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\235\240\232\377\377\377\377\377\344\346\341\377"
- "\343\346\341\377\344\346\342\377\344\346\341\377\344\346\341\377\344"
- "\346\341\377\343\346\341\377\344\346\341\377\344\345\341\377\343\345"
- "\341\377\343\345\340\377\343\345\340\377\342\345\341\377\342\345\340"
- "\377\342\345\340\377\342\344\337\377\342\344\337\377\342\344\337\377"
- "\342\344\337\377\342\344\337\377\342\344\337\377\342\344\337\377\342"
- "\344\337\377\342\344\337\377\342\344\337\377\342\344\337\377\342\344"
- "\337\377\342\344\337\377\341\344\337\377\341\344\337\377\341\344\337"
- "\377\341\343\336\377\375\375\375\377\230\233\225\377\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\235\237\231\377\377\377\377\377\343\345\341\377\343\346\341"
- "\377\344\346\341\377\344\346\341\377\344\346\341\377\343\345\341\377"
- "\343\346\341\377\344\346\341\377\344\346\341\377\343\345\341\377\343"
- "\345\340\377\343\345\340\377\343\345\341\377\342\345\340\377\342\345"
- "\340\377\342\345\340\377\342\345\340\377\343\345\340\377\343\345\340"
- "\377\343\345\340\377\343\345\340\377\343\345\340\377\343\345\340\377"
- "\343\345\340\377\343\345\340\377\343\345\340\377\343\345\340\377\342"
- "\345\340\377\342\345\340\377\342\345\340\377\342\344\340\377\342\344"
- "\337\377\377\377\377\377\230\232\224\377\377\377\377\0\377\377\377\0"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\234\236\231\377\377\377\377\377\343\345\341\377\343\345\340\377\343"
- "\346\341\377\344\346\341\377\344\345\341\377\343\345\341\377\343\345"
- "\341\377\343\346\341\377\344\346\341\377\344\346\341\377\343\345\340"
- "\377\343\345\340\377\343\345\341\377\343\345\341\377\343\346\341\377"
- "\343\346\341\377\344\346\341\377\344\346\341\377\344\346\341\377\344"
- "\346\341\377\344\346\341\377\344\346\341\377\344\346\341\377\344\346"
- "\341\377\344\346\341\377\344\346\341\377\344\346\341\377\343\346\341"
- "\377\343\346\341\377\343\345\341\377\343\345\341\377\343\345\341\377"
- "\377\377\377\377\227\231\224\377\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\233\236"
- "\230\377\377\377\377\377\343\345\340\377\343\345\340\377\343\346\341"
- "\377\343\346\341\377\344\346\341\377\344\346\341\377\343\345\341\377"
- "\343\345\341\377\344\346\341\377\344\346\341\377\344\346\341\377\344"
- "\346\342\377\344\346\342\377\344\346\342\377\344\346\342\377\344\346"
- "\342\377\345\346\342\377\345\346\342\377\345\347\342\377\345\347\342"
- "\377\345\347\342\377\345\347\342\377\345\347\342\377\345\347\342\377"
- "\345\347\342\377\345\347\342\377\345\346\342\377\345\346\342\377\344"
- "\346\342\377\344\346\342\377\344\346\342\377\344\346\342\377\377\377"
- "\377\377\226\231\223\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\233\235\227\377"
- "\377\377\377\377\343\345\340\377\343\345\340\377\343\345\341\377\343"
- "\346\341\377\344\346\341\377\344\346\341\377\344\346\342\377\344\346"
- "\342\377\345\346\342\377\345\347\342\377\345\347\342\377\345\347\343"
- "\377\345\347\343\377\345\347\343\377\345\347\343\377\346\347\343\377"
- "\346\347\343\377\346\347\343\377\346\347\343\377\346\347\343\377\346"
- "\350\343\377\346\350\343\377\346\350\343\377\346\350\343\377\346\347"
- "\343\377\346\347\343\377\346\347\343\377\346\347\343\377\345\347\343"
- "\377\345\347\343\377\345\347\343\377\345\347\343\377\377\377\377\377"
- "\226\230\222\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\232\234\227\377\377\377"
- "\377\377\343\346\341\377\344\346\341\377\344\346\342\377\344\346\342"
- "\377\345\346\342\377\345\347\342\377\345\347\343\377\345\347\343\377"
- "\345\347\343\377\346\347\343\377\346\350\343\377\346\350\344\377\346"
- "\350\344\377\346\350\344\377\346\350\344\377\346\350\344\377\347\350"
- "\344\377\347\350\344\377\347\350\344\377\347\350\344\377\347\350\344"
- "\377\347\350\344\377\347\350\344\377\347\350\344\377\347\350\344\377"
- "\347\350\344\377\347\350\344\377\346\350\344\377\346\350\344\377\346"
- "\350\344\377\346\350\344\377\346\350\344\377\377\377\377\377\225\227"
- "\222\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\231\234\226\377\377\377\377\377"
- "\344\346\342\377\345\346\342\377\345\347\342\377\345\347\343\377\345"
- "\347\343\377\346\347\343\377\346\350\344\377\346\350\344\377\346\350"
- "\344\377\346\350\344\377\347\350\344\377\347\351\345\377\347\351\345"
- "\377\347\351\345\377\347\351\345\377\347\351\345\377\350\351\345\377"
- "\350\351\345\377\350\351\346\377\350\351\346\377\350\351\346\377\350"
- "\351\346\377\350\351\346\377\350\351\346\377\350\351\346\377\350\351"
- "\346\377\350\351\345\377\347\351\345\377\347\351\345\377\347\351\345"
- "\377\347\351\345\377\347\351\345\377\377\377\377\377\224\227\221\377"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\231\233\225\377\377\377\377\377\345\347"
- "\343\377\345\347\343\377\346\347\343\377\346\350\344\377\346\350\344"
- "\377\346\350\344\377\347\350\344\377\347\351\345\377\347\351\345\377"
- "\347\351\345\377\350\351\346\377\350\351\346\377\350\352\346\377\350"
- "\352\346\377\350\352\346\377\350\352\346\377\351\352\346\377\351\352"
- "\347\377\351\352\347\377\351\352\347\377\351\352\347\377\351\352\347"
- "\377\351\352\347\377\351\352\347\377\351\352\347\377\351\352\347\377"
- "\351\352\346\377\351\352\346\377\350\352\346\377\350\352\346\377\350"
- "\352\346\377\350\352\346\377\377\377\377\377\224\226\220\377\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\230\232\225\377\377\377\377\377\346\350\344\377"
- "\346\350\344\377\346\350\344\377\347\350\344\377\347\351\345\377\347"
- "\351\345\377\350\351\346\377\350\351\346\377\350\352\346\377\350\352"
- "\346\377\351\352\346\377\351\352\347\377\351\352\347\377\351\352\347"
- "\377\351\353\347\377\351\353\347\377\351\353\347\377\352\353\350\377"
- "\352\353\350\377\352\353\350\377\352\353\350\377\352\353\350\377\352"
- "\353\350\377\352\353\350\377\352\353\350\377\352\353\350\377\352\353"
- "\350\377\351\353\347\377\351\353\347\377\351\353\347\377\351\352\347"
- "\377\351\352\347\377\377\377\377\377\223\225\220\377\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\227\232\224\377\377\377\377\377\347\350\344\377\347\351\345"
- "\377\347\351\345\377\350\351\345\377\350\351\346\377\350\352\346\377"
- "\351\352\346\377\351\352\347\377\351\352\347\377\351\353\347\377\351"
- "\353\347\377\352\353\350\377\352\353\350\377\352\353\350\377\352\353"
- "\350\377\352\354\350\377\352\354\350\377\353\354\351\377\353\354\351"
- "\377\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377"
- "\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377\352"
- "\354\350\377\352\354\350\377\352\353\350\377\352\353\350\377\352\353"
- "\350\377\377\377\377\377\222\224\217\377\377\377\377\0\377\377\377\0"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\227\231\223\377\377\377\377\377\347\351\345\377\350\351\346\377\350"
- "\352\346\377\350\352\346\377\351\352\347\377\351\352\347\377\351\353"
- "\347\377\352\353\350\377\352\353\350\377\352\353\350\377\352\354\350"
- "\377\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377"
- "\353\354\351\377\353\355\352\377\354\355\352\377\354\355\352\377\354"
- "\355\352\377\354\355\352\377\354\355\352\377\354\355\352\377\354\355"
- "\352\377\354\355\352\377\354\355\352\377\354\355\352\377\353\355\352"
- "\377\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377"
- "\377\377\377\377\222\224\216\377\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\226\230"
- "\223\377\377\377\377\377\350\352\346\377\350\352\346\377\351\352\347"
- "\377\351\352\347\377\351\353\347\377\352\353\350\377\352\353\350\377"
- "\352\354\350\377\353\354\351\377\353\354\351\377\353\354\351\377\354"
- "\355\352\377\354\355\352\377\354\355\352\377\354\355\352\377\354\355"
- "\352\377\354\356\353\377\354\356\353\377\355\356\353\377\355\356\353"
- "\377\355\356\353\377\355\356\353\377\355\356\353\377\355\356\353\377"
- "\355\356\353\377\355\356\353\377\354\356\353\377\354\355\353\377\354"
- "\355\352\377\354\355\352\377\354\355\352\377\354\355\352\377\377\377"
- "\377\377\221\223\216\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\225\230\222\377"
- "\377\377\377\377\351\352\347\377\351\352\347\377\351\353\347\377\352"
- "\353\350\377\352\353\350\377\352\354\350\377\353\354\351\377\353\354"
- "\351\377\354\355\352\377\354\355\352\377\354\355\352\377\354\355\353"
- "\377\355\356\353\377\355\356\353\377\355\356\353\377\355\356\353\377"
- "\355\356\354\377\356\356\354\377\356\356\354\377\356\357\354\377\356"
- "\357\354\377\356\357\354\377\356\357\354\377\356\357\354\377\356\357"
- "\354\377\356\356\354\377\355\356\354\377\355\356\354\377\355\356\353"
- "\377\355\356\353\377\355\356\353\377\354\356\353\377\377\377\377\377"
- "\220\222\215\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\225\227\221\377\377\377"
- "\377\377\351\353\347\377\352\353\350\377\352\353\350\377\352\354\350"
- "\377\353\354\351\377\353\354\351\377\354\355\352\377\354\355\352\377"
- "\354\355\352\377\354\356\353\377\355\356\353\377\355\356\353\377\355"
- "\356\354\377\356\357\354\377\356\357\354\377\356\357\354\377\356\357"
- "\355\377\357\357\355\377\357\357\355\377\357\357\355\377\357\360\355"
- "\377\357\360\355\377\357\360\355\377\357\360\355\377\357\357\355\377"
- "\357\357\355\377\356\357\355\377\356\357\355\377\356\357\354\377\356"
- "\357\354\377\356\356\354\377\355\356\354\377\377\377\377\377\220\222"
- "\215\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\224\226\221\377\377\377\377\377"
- "\352\353\350\377\352\353\350\377\353\354\351\377\353\354\351\377\353"
- "\355\352\377\354\355\352\377\354\355\352\377\355\356\353\377\355\356"
- "\353\377\355\356\354\377\356\356\354\377\356\357\354\377\356\357\355"
- "\377\357\357\355\377\357\360\355\377\357\360\356\377\357\360\356\377"
- "\357\360\356\377\360\360\356\377\360\360\356\377\360\360\356\377\360"
- "\360\356\377\360\360\356\377\360\360\356\377\360\360\356\377\357\360"
- "\356\377\357\360\356\377\357\360\356\377\357\360\355\377\357\357\355"
- "\377\356\357\355\377\356\357\354\377\377\377\377\377\217\221\214\377"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\223\225\220\377\377\377\377\377\352\353"
- "\350\377\353\354\351\377\353\354\351\377\354\355\352\377\354\355\352"
- "\377\354\355\353\377\355\356\353\377\355\356\353\377\356\356\354\377"
- "\356\357\354\377\356\357\355\377\357\357\355\377\357\360\356\377\357"
- "\360\356\377\360\360\356\377\360\361\356\377\360\361\357\377\360\361"
- "\357\377\361\361\357\377\361\361\357\377\361\361\357\377\361\361\357"
- "\377\361\361\357\377\361\361\357\377\361\361\357\377\360\361\357\377"
- "\360\361\357\377\360\361\357\377\360\360\356\377\357\360\356\377\357"
- "\360\356\377\357\360\355\377\377\377\377\377\216\220\213\377\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\223\225\217\377\377\377\377\377\353\354\351\377"
- "\353\354\351\377\354\355\352\377\354\355\352\377\354\355\353\377\355"
- "\356\353\377\355\356\354\377\356\357\354\377\356\357\354\377\357\357"
- "\355\377\357\360\355\377\357\360\356\377\360\360\356\377\360\361\357"
- "\377\360\361\357\377\361\361\357\377\361\362\360\377\361\362\360\377"
- "\362\362\360\377\362\362\360\377\362\362\360\377\362\362\360\377\362"
- "\362\360\377\362\362\360\377\362\362\360\377\361\362\360\377\361\362"
- "\360\377\361\361\357\377\361\361\357\377\360\361\357\377\360\361\356"
- "\377\357\360\356\377\377\377\377\377\216\220\213\377\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\222\224\217\377\377\377\377\377\353\354\351\377\353\355\352"
- "\377\354\355\352\377\354\355\352\377\355\356\353\377\355\356\353\377"
- "\356\357\354\377\356\357\354\377\357\357\355\377\357\360\355\377\357"
- "\360\356\377\360\361\356\377\360\361\357\377\361\361\357\377\361\362"
- "\360\377\361\362\360\377\362\362\360\377\362\362\361\377\362\363\361"
- "\377\363\363\361\377\363\363\362\377\363\363\362\377\363\363\362\377"
- "\363\363\361\377\362\363\361\377\362\363\361\377\362\362\361\377\362"
- "\362\360\377\361\362\360\377\361\361\357\377\360\361\357\377\360\361"
- "\357\377\377\377\377\377\215\217\212\377\377\377\377\0\377\377\377\0"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\221\223\216\377\377\377\377\377\353\354\351\377\354\355\352\377\354"
- "\355\352\377\354\356\353\377\355\356\353\377\355\356\354\377\356\357"
- "\354\377\356\357\355\377\357\360\355\377\357\360\356\377\360\360\356"
- "\377\360\361\357\377\361\361\357\377\361\362\360\377\362\362\360\377"
- "\362\362\361\377\362\363\361\377\363\363\362\377\363\363\362\377\363"
- "\364\362\377\364\364\363\377\364\364\363\377\364\364\363\377\364\364"
- "\362\377\363\364\362\377\363\363\362\377\363\363\361\377\362\363\361"
- "\377\362\362\360\377\361\362\360\377\361\362\360\377\360\361\357\377"
- "\377\377\377\377\214\216\211\377\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\221\223"
- "\215\377\377\377\377\377\353\354\351\377\354\355\352\377\354\355\352"
- "\377\355\356\353\377\355\356\353\377\356\356\354\377\356\357\354\377"
- "\357\357\355\377\357\360\356\377\360\360\356\377\360\361\357\377\361"
- "\361\357\377\361\362\360\377\362\362\360\377\362\362\361\377\362\363"
- "\361\377\363\363\362\377\363\364\362\377\364\364\363\377\364\364\363"
- "\377\365\365\363\377\365\365\364\377\365\365\364\377\364\365\363\377"
- "\364\364\363\377\364\364\362\377\363\363\362\377\363\363\361\377\362"
- "\363\361\377\362\362\360\377\361\362\360\377\361\361\357\377\377\377"
- "\377\377\214\216\211\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\220\222\215\377"
- "\377\377\377\377\353\354\351\377\354\355\352\377\354\355\352\377\355"
- "\356\353\377\355\356\353\377\356\357\354\377\356\357\354\377\357\357"
- "\355\377\357\360\356\377\360\360\356\377\360\361\357\377\361\361\357"
- "\377\361\362\360\377\362\362\360\377\362\362\361\377\362\363\361\377"
- "\363\363\362\377\363\364\362\377\364\364\363\377\364\365\363\377\365"
- "\365\364\377\365\365\364\377\365\365\364\377\365\365\364\377\364\364"
- "\363\377\364\364\363\377\363\363\362\377\363\363\362\377\362\363\361"
- "\377\362\362\360\377\361\362\360\377\361\361\357\377\377\377\377\377"
- "\213\215\210\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\217\221\214\377\377\377"
- "\377\377\353\354\351\377\354\355\352\377\354\355\352\377\355\356\353"
- "\377\355\356\353\377\356\356\354\377\356\357\354\377\357\357\355\377"
- "\357\360\355\377\357\360\356\377\360\361\356\377\360\361\357\377\361"
- "\361\357\377\361\362\360\377\362\362\360\377\362\363\361\377\363\363"
- "\362\377\363\363\362\377\364\364\362\377\364\364\363\377\364\364\363"
- "\377\364\364\363\377\364\364\363\377\364\364\363\377\364\364\363\377"
- "\363\364\362\377\363\363\362\377\362\363\361\377\362\362\361\377\362"
- "\362\360\377\361\362\360\377\361\361\357\377\377\377\377\377\212\214"
- "\207\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\217\221\213\377\377\377\377\377"
- "\353\354\351\377\354\355\352\377\354\355\352\377\354\355\353\377\355"
- "\356\353\377\355\356\354\377\356\357\354\377\356\357\355\377\357\360"
- "\355\377\357\360\356\377\360\360\356\377\360\361\357\377\361\361\357"
- "\377\361\362\360\377\361\362\360\377\362\362\360\377\362\363\361\377"
- "\362\363\361\377\363\363\362\377\363\363\362\377\363\363\362\377\363"
- "\364\362\377\363\364\362\377\363\363\362\377\363\363\362\377\363\363"
- "\361\377\362\363\361\377\362\362\361\377\362\362\360\377\361\362\360"
- "\377\361\361\357\377\360\361\357\377\377\377\377\377\212\214\207\377"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\0\0\0\5\216\220\213\377\377\377\377\377\353\354\351"
- "\377\353\354\351\377\354\355\352\377\354\355\352\377\355\356\353\377"
- "\355\356\353\377\355\356\354\377\356\357\354\377\356\357\355\377\357"
- "\360\355\377\357\360\356\377\360\360\356\377\360\361\357\377\360\361"
- "\357\377\361\361\357\377\361\362\360\377\361\362\360\377\362\362\360"
- "\377\362\362\361\377\362\362\361\377\362\363\361\377\362\363\361\377"
- "\362\363\361\377\362\363\361\377\362\362\361\377\362\362\360\377\362"
- "\362\360\377\361\362\360\377\361\362\360\377\361\361\357\377\360\361"
- "\357\377\360\360\356\377\377\377\377\377\211\213\206\377\0\0\0\4\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\10\0\0\0\21"
- "\215\217\212\377\377\377\377\377\352\354\350\377\353\354\351\377\353"
- "\354\351\377\354\355\352\377\354\355\352\377\355\356\353\377\355\356"
- "\353\377\355\356\354\377\356\357\354\377\356\357\355\377\357\357\355"
- "\377\357\360\355\377\357\360\356\377\360\360\356\377\360\361\357\377"
- "\360\361\357\377\361\361\357\377\361\361\357\377\361\362\360\377\361"
- "\362\360\377\361\362\360\377\361\362\360\377\361\362\360\377\361\362"
- "\360\377\361\362\360\377\361\362\360\377\361\361\357\377\360\361\357"
- "\377\360\361\357\377\360\361\356\377\357\360\356\377\357\360\356\377"
- "\377\377\377\377\210\212\205\377\0\0\0\20\0\0\0\7\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\0\0\0\4\0\0\0\17\0\0\0\37\216\220\212\374\376\376\376\377\353"
- "\354\351\377\352\354\350\377\353\354\351\377\353\354\351\377\354\355"
- "\352\377\354\355\352\377\354\356\353\377\355\356\353\377\355\356\354"
- "\377\356\356\354\377\356\357\354\377\356\357\355\377\357\357\355\377"
- "\357\360\355\377\357\360\356\377\357\360\356\377\360\360\356\377\360"
- "\361\356\377\360\361\357\377\360\361\357\377\360\361\357\377\360\361"
- "\357\377\360\361\357\377\360\361\357\377\360\361\357\377\360\361\357"
- "\377\360\360\356\377\360\360\356\377\357\360\356\377\357\360\356\377"
- "\357\360\355\377\360\360\356\377\376\376\376\377\212\214\207\374\0\0"
- "\0\33\0\0\0\16\0\0\0\2\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\0\0\0\6\0\0\0\22\0\0\0*\206\207"
- "\203\320\335\335\334\376\376\376\376\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
- "\377\377\377\377\377\377\377\377\377\377\377\376\376\376\377\334\335"
- "\332\376\203\205\200\315\0\0\0&\0\0\0\20\0\0\0\4\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0"
- "\4\0\0\0\17\0\0\0\37//,L\205\206\202\327\213\215\210\375\213\215\210"
- "\377\213\215\210\377\213\215\210\377\212\214\207\377\212\214\207\377"
- "\212\214\207\377\212\214\207\377\212\214\207\377\212\214\207\377\212"
- "\214\207\377\211\213\206\377\211\213\206\377\211\213\206\377\211\213"
- "\206\377\211\213\206\377\211\213\206\377\211\213\206\377\210\212\205"
- "\377\210\212\205\377\210\212\205\377\210\212\205\377\210\212\205\377"
- "\210\212\205\377\210\212\205\377\210\212\205\377\210\212\205\377\210"
- "\212\205\377\210\212\205\377\210\212\205\377\210\212\205\377\210\212"
- "\205\375\204\205\200\325-1-I\0\0\0\33\0\0\0\16\0\0\0\2\377\377\377\0"
- "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
- "\0\377\377\377\0\0\0\0\10\0\0\0\21\0\0\0\32\0\0\0%\0\0\0+\0\0\0""2\0"
- "\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2"
- "\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0"
- "2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0"
- "\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0""2\0\0\0*\0\0\0$\0\0"
- "\0\30\0\0\0\20\0\0\0\7\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
- "\377\377\0\0\0\0\5\0\0\0\13\0\0\0\17\0\0\0\20\0\0\0\21\0\0\0\21\0\0\0"
- "\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0"
- "\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21"
- "\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0"
- "\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\20\0\0\0\16\0\0\0\12\0"
- "\0\0\4\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
- "\377\0\377\377\377\0\377\377\377\0\377\377\377\0";
+ /* This is from text-x-preview.svg in the gnome icon theme */
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\243\255\243\31\252\254\245\307\246\251\243\374\246\251\243\377\246"
+ "\251\243\377\246\251\242\377\246\250\242\377\246\250\242\377\246\250"
+ "\242\377\245\250\242\377\245\250\242\377\245\250\242\377\245\250\241"
+ "\377\245\247\241\377\245\247\241\377\245\247\241\377\244\247\241\377"
+ "\244\247\241\377\244\247\241\377\244\247\240\377\244\246\240\377\244"
+ "\246\240\377\244\246\240\377\243\246\240\377\243\246\240\377\243\246"
+ "\237\377\244\247\240\371\245\251\242\333\245\247\242\216\246\246\233"
+ "\27\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\252\254\246\277\347\351"
+ "\346\376\377\377\376\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\374\374\374\377\362\363\361\377\353\355\352\377"
+ "\344\345\342\377\276\300\272\371\244\245\240\366\244\247\237h\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\246\251\244\373\376\376\376\377\354\355\352\377"
+ "\352\354\350\377\351\353\347\377\351\353\347\377\350\352\346\377\350"
+ "\351\345\377\347\351\344\377\346\350\344\377\345\350\343\377\344\347"
+ "\342\377\344\346\341\377\343\346\340\377\342\345\340\377\341\344\337"
+ "\377\341\343\336\377\340\342\335\377\337\342\334\377\337\341\333\377"
+ "\336\340\332\377\335\337\332\377\334\337\331\377\333\336\330\377\332"
+ "\335\327\377\331\334\326\377\331\334\325\377\333\334\327\377\362\363"
+ "\361\377\333\335\331\377\250\253\245\364\245\246\240\236\200\200\200"
+ "\2\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\245\247\241\377\377\377\377\377\352\354\350\377\351\353\347\377\351"
+ "\353\347\377\350\352\346\377\350\352\346\377\347\351\345\377\347\350"
+ "\344\377\346\351\344\377\345\350\343\377\344\347\342\377\344\346\342"
+ "\377\343\346\341\377\342\345\340\377\341\344\337\377\341\344\336\377"
+ "\340\343\335\377\340\342\335\377\337\341\334\377\336\341\333\377\335"
+ "\340\332\377\334\337\331\377\334\336\330\377\333\336\327\377\332\335"
+ "\326\377\331\334\325\377\326\331\322\377\326\330\324\377\372\372\371"
+ "\377\333\336\331\377\253\257\251\364\241\246\240\251\377\377\377\1\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\244\247\240\377"
+ "\377\377\377\377\351\353\347\377\351\353\347\377\350\353\347\377\350"
+ "\352\346\377\347\352\345\377\347\351\345\377\347\350\344\377\346\350"
+ "\343\377\345\347\343\377\344\347\343\377\344\346\342\377\343\346\341"
+ "\377\342\345\340\377\342\344\337\377\341\344\336\377\341\343\336\377"
+ "\340\342\335\377\337\342\334\377\337\341\333\377\336\340\332\377\335"
+ "\340\332\377\334\337\331\377\333\336\330\377\333\335\327\377\332\335"
+ "\326\377\330\333\324\377\312\314\307\377\374\375\374\377\363\364\362"
+ "\377\325\330\322\377\253\255\250\365\242\244\235\222\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\243\246\240\377\377\377\377\377"
+ "\351\352\346\377\350\352\346\377\350\352\346\377\347\352\346\377\347"
+ "\351\345\377\347\351\344\377\346\350\344\377\346\350\343\377\345\347"
+ "\342\377\344\346\342\377\344\346\342\377\343\346\341\377\342\345\340"
+ "\377\342\345\337\377\342\344\337\377\341\343\336\377\340\343\335\377"
+ "\340\342\334\377\337\341\333\377\336\341\333\377\335\340\332\377\335"
+ "\337\331\377\334\337\330\377\333\336\327\377\332\335\326\377\332\335"
+ "\326\377\314\317\310\377\372\372\372\377\370\370\370\377\346\351\345"
+ "\377\324\330\321\377\245\247\241\364\241\244\235Q\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\243\245\237\377\377\377\377\377\350\352\346\377"
+ "\350\351\345\377\347\351\345\377\347\351\345\377\347\351\344\377\346"
+ "\350\344\377\346\350\343\377\345\347\343\377\345\347\342\377\344\346"
+ "\342\377\344\346\341\377\343\345\341\377\342\345\340\377\342\345\337"
+ "\377\341\344\337\377\340\344\336\377\341\343\335\377\340\342\334\377"
+ "\337\342\334\377\336\341\333\377\336\340\332\377\335\340\331\377\334"
+ "\337\331\377\334\336\330\377\333\336\327\377\332\335\326\377\320\323"
+ "\314\377\305\307\301\377\271\274\266\377\262\265\257\377\300\303\276"
+ "\377\314\317\311\377\240\244\234\355\222\222\222\7\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\242\245\237\377\377\377\377\377\347\351\345\377\347\351\344"
+ "\377\347\350\345\377\346\350\344\377\346\350\344\377\346\350\343\377"
+ "\346\350\343\377\345\347\342\377\345\347\342\377\344\346\342\377\344"
+ "\346\341\377\343\345\341\377\342\345\340\377\342\345\337\377\341\344"
+ "\337\377\341\344\336\377\341\343\335\377\340\343\334\377\337\342\334"
+ "\377\337\341\333\377\336\341\332\377\335\340\332\377\335\340\331\377"
+ "\334\337\330\377\333\336\327\377\333\336\327\377\322\325\317\377\307"
+ "\312\304\377\274\300\271\377\261\264\257\377\246\250\244\377\302\304"
+ "\300\377\260\263\255\363\237\242\235h\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\241"
+ "\244\236\377\377\377\377\377\347\351\344\377\346\350\344\377\346\350"
+ "\344\377\346\350\344\377\345\350\343\377\346\350\343\377\345\347\342"
+ "\377\345\347\343\377\344\347\342\377\344\346\342\377\343\346\341\377"
+ "\343\345\341\377\342\345\340\377\342\344\337\377\342\344\337\377\341"
+ "\343\336\377\341\343\335\377\340\343\335\377\340\342\334\377\337\342"
+ "\333\377\336\341\333\377\336\341\332\377\335\340\331\377\335\340\331"
+ "\377\334\337\330\377\334\337\330\377\334\337\330\377\333\335\327\377"
+ "\331\333\325\377\322\324\317\377\306\310\303\377\273\276\271\377\322"
+ "\325\320\377\242\244\236\312\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\241\243\235"
+ "\377\377\377\377\377\346\350\343\377\346\350\344\377\346\350\343\377"
+ "\345\347\343\377\345\347\343\377\345\347\342\377\345\347\342\377\345"
+ "\347\342\377\344\347\342\377\344\346\341\377\343\346\341\377\343\345"
+ "\340\377\342\345\340\377\342\344\337\377\341\344\337\377\341\343\336"
+ "\377\341\343\335\377\340\342\335\377\340\342\334\377\337\341\334\377"
+ "\337\341\334\377\336\341\333\377\336\340\333\377\335\340\332\377\335"
+ "\337\331\377\335\337\331\377\335\337\331\377\334\337\331\377\334\337"
+ "\331\377\334\337\331\377\334\337\331\377\336\341\333\377\350\352\347"
+ "\377\236\240\232\370\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\240\242\234\377\377"
+ "\377\377\377\346\347\343\377\345\350\343\377\345\347\343\377\345\347"
+ "\343\377\345\347\342\377\344\347\342\377\345\346\342\377\344\347\342"
+ "\377\344\346\342\377\344\346\341\377\343\346\341\377\343\345\340\377"
+ "\342\345\340\377\342\344\337\377\341\344\337\377\342\343\337\377\341"
+ "\343\336\377\341\342\336\377\340\342\335\377\340\341\335\377\337\341"
+ "\334\377\336\340\333\377\336\340\333\377\336\340\333\377\336\340\333"
+ "\377\336\340\333\377\336\340\333\377\336\340\333\377\335\340\332\377"
+ "\335\340\332\377\335\340\332\377\337\342\334\377\363\364\362\377\233"
+ "\235\230\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\237\242\234\377\377\377"
+ "\377\377\345\347\342\377\345\347\342\377\345\347\343\377\345\347\342"
+ "\377\344\347\342\377\344\346\342\377\345\346\342\377\344\346\342\377"
+ "\344\346\341\377\344\346\341\377\343\346\341\377\343\345\340\377\342"
+ "\345\340\377\342\344\337\377\341\344\337\377\342\344\337\377\341\343"
+ "\336\377\341\343\336\377\340\342\335\377\340\342\335\377\337\341\334"
+ "\377\337\341\334\377\337\341\334\377\337\341\334\377\337\341\334\377"
+ "\337\341\334\377\337\341\334\377\337\341\334\377\337\341\334\377\336"
+ "\341\333\377\336\341\333\377\340\343\335\377\373\373\372\377\232\235"
+ "\227\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\237\241\233\377\377\377\377\377"
+ "\344\347\342\377\345\346\342\377\345\347\342\377\344\347\342\377\344"
+ "\347\342\377\344\346\341\377\344\346\342\377\344\346\342\377\344\345"
+ "\341\377\343\346\341\377\343\346\341\377\343\345\340\377\342\345\340"
+ "\377\342\345\337\377\341\344\340\377\341\344\337\377\341\343\337\377"
+ "\341\343\336\377\340\342\336\377\340\342\335\377\340\342\335\377\340"
+ "\342\335\377\340\342\335\377\340\342\335\377\340\342\335\377\340\342"
+ "\335\377\340\342\335\377\337\342\335\377\337\342\335\377\337\342\334"
+ "\377\337\342\334\377\341\344\336\377\375\375\375\377\232\234\226\377"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\236\240\233\377\377\377\377\377\344\346"
+ "\341\377\345\346\342\377\344\346\342\377\344\347\342\377\344\346\341"
+ "\377\344\346\341\377\343\346\342\377\344\346\341\377\344\346\341\377"
+ "\343\345\341\377\343\345\340\377\343\345\340\377\342\345\340\377\342"
+ "\345\337\377\341\344\340\377\341\344\337\377\342\344\337\377\341\343"
+ "\336\377\341\343\336\377\341\343\336\377\341\343\336\377\341\343\336"
+ "\377\341\343\336\377\341\343\336\377\341\343\336\377\341\343\336\377"
+ "\341\343\336\377\341\343\336\377\340\343\336\377\340\343\336\377\340"
+ "\343\335\377\342\345\337\377\375\375\375\377\231\233\226\377\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\235\240\232\377\377\377\377\377\344\346\341\377"
+ "\343\346\341\377\344\346\342\377\344\346\341\377\344\346\341\377\344"
+ "\346\341\377\343\346\341\377\344\346\341\377\344\345\341\377\343\345"
+ "\341\377\343\345\340\377\343\345\340\377\342\345\341\377\342\345\340"
+ "\377\342\345\340\377\342\344\337\377\342\344\337\377\342\344\337\377"
+ "\342\344\337\377\342\344\337\377\342\344\337\377\342\344\337\377\342"
+ "\344\337\377\342\344\337\377\342\344\337\377\342\344\337\377\342\344"
+ "\337\377\342\344\337\377\341\344\337\377\341\344\337\377\341\344\337"
+ "\377\341\343\336\377\375\375\375\377\230\233\225\377\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\235\237\231\377\377\377\377\377\343\345\341\377\343\346\341"
+ "\377\344\346\341\377\344\346\341\377\344\346\341\377\343\345\341\377"
+ "\343\346\341\377\344\346\341\377\344\346\341\377\343\345\341\377\343"
+ "\345\340\377\343\345\340\377\343\345\341\377\342\345\340\377\342\345"
+ "\340\377\342\345\340\377\342\345\340\377\343\345\340\377\343\345\340"
+ "\377\343\345\340\377\343\345\340\377\343\345\340\377\343\345\340\377"
+ "\343\345\340\377\343\345\340\377\343\345\340\377\343\345\340\377\342"
+ "\345\340\377\342\345\340\377\342\345\340\377\342\344\340\377\342\344"
+ "\337\377\377\377\377\377\230\232\224\377\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\234\236\231\377\377\377\377\377\343\345\341\377\343\345\340\377\343"
+ "\346\341\377\344\346\341\377\344\345\341\377\343\345\341\377\343\345"
+ "\341\377\343\346\341\377\344\346\341\377\344\346\341\377\343\345\340"
+ "\377\343\345\340\377\343\345\341\377\343\345\341\377\343\346\341\377"
+ "\343\346\341\377\344\346\341\377\344\346\341\377\344\346\341\377\344"
+ "\346\341\377\344\346\341\377\344\346\341\377\344\346\341\377\344\346"
+ "\341\377\344\346\341\377\344\346\341\377\344\346\341\377\343\346\341"
+ "\377\343\346\341\377\343\345\341\377\343\345\341\377\343\345\341\377"
+ "\377\377\377\377\227\231\224\377\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\233\236"
+ "\230\377\377\377\377\377\343\345\340\377\343\345\340\377\343\346\341"
+ "\377\343\346\341\377\344\346\341\377\344\346\341\377\343\345\341\377"
+ "\343\345\341\377\344\346\341\377\344\346\341\377\344\346\341\377\344"
+ "\346\342\377\344\346\342\377\344\346\342\377\344\346\342\377\344\346"
+ "\342\377\345\346\342\377\345\346\342\377\345\347\342\377\345\347\342"
+ "\377\345\347\342\377\345\347\342\377\345\347\342\377\345\347\342\377"
+ "\345\347\342\377\345\347\342\377\345\346\342\377\345\346\342\377\344"
+ "\346\342\377\344\346\342\377\344\346\342\377\344\346\342\377\377\377"
+ "\377\377\226\231\223\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\233\235\227\377"
+ "\377\377\377\377\343\345\340\377\343\345\340\377\343\345\341\377\343"
+ "\346\341\377\344\346\341\377\344\346\341\377\344\346\342\377\344\346"
+ "\342\377\345\346\342\377\345\347\342\377\345\347\342\377\345\347\343"
+ "\377\345\347\343\377\345\347\343\377\345\347\343\377\346\347\343\377"
+ "\346\347\343\377\346\347\343\377\346\347\343\377\346\347\343\377\346"
+ "\350\343\377\346\350\343\377\346\350\343\377\346\350\343\377\346\347"
+ "\343\377\346\347\343\377\346\347\343\377\346\347\343\377\345\347\343"
+ "\377\345\347\343\377\345\347\343\377\345\347\343\377\377\377\377\377"
+ "\226\230\222\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\232\234\227\377\377\377"
+ "\377\377\343\346\341\377\344\346\341\377\344\346\342\377\344\346\342"
+ "\377\345\346\342\377\345\347\342\377\345\347\343\377\345\347\343\377"
+ "\345\347\343\377\346\347\343\377\346\350\343\377\346\350\344\377\346"
+ "\350\344\377\346\350\344\377\346\350\344\377\346\350\344\377\347\350"
+ "\344\377\347\350\344\377\347\350\344\377\347\350\344\377\347\350\344"
+ "\377\347\350\344\377\347\350\344\377\347\350\344\377\347\350\344\377"
+ "\347\350\344\377\347\350\344\377\346\350\344\377\346\350\344\377\346"
+ "\350\344\377\346\350\344\377\346\350\344\377\377\377\377\377\225\227"
+ "\222\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\231\234\226\377\377\377\377\377"
+ "\344\346\342\377\345\346\342\377\345\347\342\377\345\347\343\377\345"
+ "\347\343\377\346\347\343\377\346\350\344\377\346\350\344\377\346\350"
+ "\344\377\346\350\344\377\347\350\344\377\347\351\345\377\347\351\345"
+ "\377\347\351\345\377\347\351\345\377\347\351\345\377\350\351\345\377"
+ "\350\351\345\377\350\351\346\377\350\351\346\377\350\351\346\377\350"
+ "\351\346\377\350\351\346\377\350\351\346\377\350\351\346\377\350\351"
+ "\346\377\350\351\345\377\347\351\345\377\347\351\345\377\347\351\345"
+ "\377\347\351\345\377\347\351\345\377\377\377\377\377\224\227\221\377"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\231\233\225\377\377\377\377\377\345\347"
+ "\343\377\345\347\343\377\346\347\343\377\346\350\344\377\346\350\344"
+ "\377\346\350\344\377\347\350\344\377\347\351\345\377\347\351\345\377"
+ "\347\351\345\377\350\351\346\377\350\351\346\377\350\352\346\377\350"
+ "\352\346\377\350\352\346\377\350\352\346\377\351\352\346\377\351\352"
+ "\347\377\351\352\347\377\351\352\347\377\351\352\347\377\351\352\347"
+ "\377\351\352\347\377\351\352\347\377\351\352\347\377\351\352\347\377"
+ "\351\352\346\377\351\352\346\377\350\352\346\377\350\352\346\377\350"
+ "\352\346\377\350\352\346\377\377\377\377\377\224\226\220\377\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\230\232\225\377\377\377\377\377\346\350\344\377"
+ "\346\350\344\377\346\350\344\377\347\350\344\377\347\351\345\377\347"
+ "\351\345\377\350\351\346\377\350\351\346\377\350\352\346\377\350\352"
+ "\346\377\351\352\346\377\351\352\347\377\351\352\347\377\351\352\347"
+ "\377\351\353\347\377\351\353\347\377\351\353\347\377\352\353\350\377"
+ "\352\353\350\377\352\353\350\377\352\353\350\377\352\353\350\377\352"
+ "\353\350\377\352\353\350\377\352\353\350\377\352\353\350\377\352\353"
+ "\350\377\351\353\347\377\351\353\347\377\351\353\347\377\351\352\347"
+ "\377\351\352\347\377\377\377\377\377\223\225\220\377\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\227\232\224\377\377\377\377\377\347\350\344\377\347\351\345"
+ "\377\347\351\345\377\350\351\345\377\350\351\346\377\350\352\346\377"
+ "\351\352\346\377\351\352\347\377\351\352\347\377\351\353\347\377\351"
+ "\353\347\377\352\353\350\377\352\353\350\377\352\353\350\377\352\353"
+ "\350\377\352\354\350\377\352\354\350\377\353\354\351\377\353\354\351"
+ "\377\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377"
+ "\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377\352"
+ "\354\350\377\352\354\350\377\352\353\350\377\352\353\350\377\352\353"
+ "\350\377\377\377\377\377\222\224\217\377\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\227\231\223\377\377\377\377\377\347\351\345\377\350\351\346\377\350"
+ "\352\346\377\350\352\346\377\351\352\347\377\351\352\347\377\351\353"
+ "\347\377\352\353\350\377\352\353\350\377\352\353\350\377\352\354\350"
+ "\377\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377"
+ "\353\354\351\377\353\355\352\377\354\355\352\377\354\355\352\377\354"
+ "\355\352\377\354\355\352\377\354\355\352\377\354\355\352\377\354\355"
+ "\352\377\354\355\352\377\354\355\352\377\354\355\352\377\353\355\352"
+ "\377\353\354\351\377\353\354\351\377\353\354\351\377\353\354\351\377"
+ "\377\377\377\377\222\224\216\377\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\226\230"
+ "\223\377\377\377\377\377\350\352\346\377\350\352\346\377\351\352\347"
+ "\377\351\352\347\377\351\353\347\377\352\353\350\377\352\353\350\377"
+ "\352\354\350\377\353\354\351\377\353\354\351\377\353\354\351\377\354"
+ "\355\352\377\354\355\352\377\354\355\352\377\354\355\352\377\354\355"
+ "\352\377\354\356\353\377\354\356\353\377\355\356\353\377\355\356\353"
+ "\377\355\356\353\377\355\356\353\377\355\356\353\377\355\356\353\377"
+ "\355\356\353\377\355\356\353\377\354\356\353\377\354\355\353\377\354"
+ "\355\352\377\354\355\352\377\354\355\352\377\354\355\352\377\377\377"
+ "\377\377\221\223\216\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\225\230\222\377"
+ "\377\377\377\377\351\352\347\377\351\352\347\377\351\353\347\377\352"
+ "\353\350\377\352\353\350\377\352\354\350\377\353\354\351\377\353\354"
+ "\351\377\354\355\352\377\354\355\352\377\354\355\352\377\354\355\353"
+ "\377\355\356\353\377\355\356\353\377\355\356\353\377\355\356\353\377"
+ "\355\356\354\377\356\356\354\377\356\356\354\377\356\357\354\377\356"
+ "\357\354\377\356\357\354\377\356\357\354\377\356\357\354\377\356\357"
+ "\354\377\356\356\354\377\355\356\354\377\355\356\354\377\355\356\353"
+ "\377\355\356\353\377\355\356\353\377\354\356\353\377\377\377\377\377"
+ "\220\222\215\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\225\227\221\377\377\377"
+ "\377\377\351\353\347\377\352\353\350\377\352\353\350\377\352\354\350"
+ "\377\353\354\351\377\353\354\351\377\354\355\352\377\354\355\352\377"
+ "\354\355\352\377\354\356\353\377\355\356\353\377\355\356\353\377\355"
+ "\356\354\377\356\357\354\377\356\357\354\377\356\357\354\377\356\357"
+ "\355\377\357\357\355\377\357\357\355\377\357\357\355\377\357\360\355"
+ "\377\357\360\355\377\357\360\355\377\357\360\355\377\357\357\355\377"
+ "\357\357\355\377\356\357\355\377\356\357\355\377\356\357\354\377\356"
+ "\357\354\377\356\356\354\377\355\356\354\377\377\377\377\377\220\222"
+ "\215\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\224\226\221\377\377\377\377\377"
+ "\352\353\350\377\352\353\350\377\353\354\351\377\353\354\351\377\353"
+ "\355\352\377\354\355\352\377\354\355\352\377\355\356\353\377\355\356"
+ "\353\377\355\356\354\377\356\356\354\377\356\357\354\377\356\357\355"
+ "\377\357\357\355\377\357\360\355\377\357\360\356\377\357\360\356\377"
+ "\357\360\356\377\360\360\356\377\360\360\356\377\360\360\356\377\360"
+ "\360\356\377\360\360\356\377\360\360\356\377\360\360\356\377\357\360"
+ "\356\377\357\360\356\377\357\360\356\377\357\360\355\377\357\357\355"
+ "\377\356\357\355\377\356\357\354\377\377\377\377\377\217\221\214\377"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\223\225\220\377\377\377\377\377\352\353"
+ "\350\377\353\354\351\377\353\354\351\377\354\355\352\377\354\355\352"
+ "\377\354\355\353\377\355\356\353\377\355\356\353\377\356\356\354\377"
+ "\356\357\354\377\356\357\355\377\357\357\355\377\357\360\356\377\357"
+ "\360\356\377\360\360\356\377\360\361\356\377\360\361\357\377\360\361"
+ "\357\377\361\361\357\377\361\361\357\377\361\361\357\377\361\361\357"
+ "\377\361\361\357\377\361\361\357\377\361\361\357\377\360\361\357\377"
+ "\360\361\357\377\360\361\357\377\360\360\356\377\357\360\356\377\357"
+ "\360\356\377\357\360\355\377\377\377\377\377\216\220\213\377\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\223\225\217\377\377\377\377\377\353\354\351\377"
+ "\353\354\351\377\354\355\352\377\354\355\352\377\354\355\353\377\355"
+ "\356\353\377\355\356\354\377\356\357\354\377\356\357\354\377\357\357"
+ "\355\377\357\360\355\377\357\360\356\377\360\360\356\377\360\361\357"
+ "\377\360\361\357\377\361\361\357\377\361\362\360\377\361\362\360\377"
+ "\362\362\360\377\362\362\360\377\362\362\360\377\362\362\360\377\362"
+ "\362\360\377\362\362\360\377\362\362\360\377\361\362\360\377\361\362"
+ "\360\377\361\361\357\377\361\361\357\377\360\361\357\377\360\361\356"
+ "\377\357\360\356\377\377\377\377\377\216\220\213\377\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\222\224\217\377\377\377\377\377\353\354\351\377\353\355\352"
+ "\377\354\355\352\377\354\355\352\377\355\356\353\377\355\356\353\377"
+ "\356\357\354\377\356\357\354\377\357\357\355\377\357\360\355\377\357"
+ "\360\356\377\360\361\356\377\360\361\357\377\361\361\357\377\361\362"
+ "\360\377\361\362\360\377\362\362\360\377\362\362\361\377\362\363\361"
+ "\377\363\363\361\377\363\363\362\377\363\363\362\377\363\363\362\377"
+ "\363\363\361\377\362\363\361\377\362\363\361\377\362\362\361\377\362"
+ "\362\360\377\361\362\360\377\361\361\357\377\360\361\357\377\360\361"
+ "\357\377\377\377\377\377\215\217\212\377\377\377\377\0\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\221\223\216\377\377\377\377\377\353\354\351\377\354\355\352\377\354"
+ "\355\352\377\354\356\353\377\355\356\353\377\355\356\354\377\356\357"
+ "\354\377\356\357\355\377\357\360\355\377\357\360\356\377\360\360\356"
+ "\377\360\361\357\377\361\361\357\377\361\362\360\377\362\362\360\377"
+ "\362\362\361\377\362\363\361\377\363\363\362\377\363\363\362\377\363"
+ "\364\362\377\364\364\363\377\364\364\363\377\364\364\363\377\364\364"
+ "\362\377\363\364\362\377\363\363\362\377\363\363\361\377\362\363\361"
+ "\377\362\362\360\377\361\362\360\377\361\362\360\377\360\361\357\377"
+ "\377\377\377\377\214\216\211\377\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\221\223"
+ "\215\377\377\377\377\377\353\354\351\377\354\355\352\377\354\355\352"
+ "\377\355\356\353\377\355\356\353\377\356\356\354\377\356\357\354\377"
+ "\357\357\355\377\357\360\356\377\360\360\356\377\360\361\357\377\361"
+ "\361\357\377\361\362\360\377\362\362\360\377\362\362\361\377\362\363"
+ "\361\377\363\363\362\377\363\364\362\377\364\364\363\377\364\364\363"
+ "\377\365\365\363\377\365\365\364\377\365\365\364\377\364\365\363\377"
+ "\364\364\363\377\364\364\362\377\363\363\362\377\363\363\361\377\362"
+ "\363\361\377\362\362\360\377\361\362\360\377\361\361\357\377\377\377"
+ "\377\377\214\216\211\377\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\220\222\215\377"
+ "\377\377\377\377\353\354\351\377\354\355\352\377\354\355\352\377\355"
+ "\356\353\377\355\356\353\377\356\357\354\377\356\357\354\377\357\357"
+ "\355\377\357\360\356\377\360\360\356\377\360\361\357\377\361\361\357"
+ "\377\361\362\360\377\362\362\360\377\362\362\361\377\362\363\361\377"
+ "\363\363\362\377\363\364\362\377\364\364\363\377\364\365\363\377\365"
+ "\365\364\377\365\365\364\377\365\365\364\377\365\365\364\377\364\364"
+ "\363\377\364\364\363\377\363\363\362\377\363\363\362\377\362\363\361"
+ "\377\362\362\360\377\361\362\360\377\361\361\357\377\377\377\377\377"
+ "\213\215\210\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\217\221\214\377\377\377"
+ "\377\377\353\354\351\377\354\355\352\377\354\355\352\377\355\356\353"
+ "\377\355\356\353\377\356\356\354\377\356\357\354\377\357\357\355\377"
+ "\357\360\355\377\357\360\356\377\360\361\356\377\360\361\357\377\361"
+ "\361\357\377\361\362\360\377\362\362\360\377\362\363\361\377\363\363"
+ "\362\377\363\363\362\377\364\364\362\377\364\364\363\377\364\364\363"
+ "\377\364\364\363\377\364\364\363\377\364\364\363\377\364\364\363\377"
+ "\363\364\362\377\363\363\362\377\362\363\361\377\362\362\361\377\362"
+ "\362\360\377\361\362\360\377\361\361\357\377\377\377\377\377\212\214"
+ "\207\377\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\217\221\213\377\377\377\377\377"
+ "\353\354\351\377\354\355\352\377\354\355\352\377\354\355\353\377\355"
+ "\356\353\377\355\356\354\377\356\357\354\377\356\357\355\377\357\360"
+ "\355\377\357\360\356\377\360\360\356\377\360\361\357\377\361\361\357"
+ "\377\361\362\360\377\361\362\360\377\362\362\360\377\362\363\361\377"
+ "\362\363\361\377\363\363\362\377\363\363\362\377\363\363\362\377\363"
+ "\364\362\377\363\364\362\377\363\363\362\377\363\363\362\377\363\363"
+ "\361\377\362\363\361\377\362\362\361\377\362\362\360\377\361\362\360"
+ "\377\361\361\357\377\360\361\357\377\377\377\377\377\212\214\207\377"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\0\0\0\5\216\220\213\377\377\377\377\377\353\354\351"
+ "\377\353\354\351\377\354\355\352\377\354\355\352\377\355\356\353\377"
+ "\355\356\353\377\355\356\354\377\356\357\354\377\356\357\355\377\357"
+ "\360\355\377\357\360\356\377\360\360\356\377\360\361\357\377\360\361"
+ "\357\377\361\361\357\377\361\362\360\377\361\362\360\377\362\362\360"
+ "\377\362\362\361\377\362\362\361\377\362\363\361\377\362\363\361\377"
+ "\362\363\361\377\362\363\361\377\362\362\361\377\362\362\360\377\362"
+ "\362\360\377\361\362\360\377\361\362\360\377\361\361\357\377\360\361"
+ "\357\377\360\360\356\377\377\377\377\377\211\213\206\377\0\0\0\4\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0\10\0\0\0\21"
+ "\215\217\212\377\377\377\377\377\352\354\350\377\353\354\351\377\353"
+ "\354\351\377\354\355\352\377\354\355\352\377\355\356\353\377\355\356"
+ "\353\377\355\356\354\377\356\357\354\377\356\357\355\377\357\357\355"
+ "\377\357\360\355\377\357\360\356\377\360\360\356\377\360\361\357\377"
+ "\360\361\357\377\361\361\357\377\361\361\357\377\361\362\360\377\361"
+ "\362\360\377\361\362\360\377\361\362\360\377\361\362\360\377\361\362"
+ "\360\377\361\362\360\377\361\362\360\377\361\361\357\377\360\361\357"
+ "\377\360\361\357\377\360\361\356\377\357\360\356\377\357\360\356\377"
+ "\377\377\377\377\210\212\205\377\0\0\0\20\0\0\0\7\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\0\0\0\4\0\0\0\17\0\0\0\37\216\220\212\374\376\376\376\377\353"
+ "\354\351\377\352\354\350\377\353\354\351\377\353\354\351\377\354\355"
+ "\352\377\354\355\352\377\354\356\353\377\355\356\353\377\355\356\354"
+ "\377\356\356\354\377\356\357\354\377\356\357\355\377\357\357\355\377"
+ "\357\360\355\377\357\360\356\377\357\360\356\377\360\360\356\377\360"
+ "\361\356\377\360\361\357\377\360\361\357\377\360\361\357\377\360\361"
+ "\357\377\360\361\357\377\360\361\357\377\360\361\357\377\360\361\357"
+ "\377\360\360\356\377\360\360\356\377\357\360\356\377\357\360\356\377"
+ "\357\360\355\377\360\360\356\377\376\376\376\377\212\214\207\374\0\0"
+ "\0\33\0\0\0\16\0\0\0\2\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\0\0\0\6\0\0\0\22\0\0\0*\206\207"
+ "\203\320\335\335\334\376\376\376\376\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
+ "\377\377\377\377\377\377\377\377\377\377\377\376\376\376\377\334\335"
+ "\332\376\203\205\200\315\0\0\0&\0\0\0\20\0\0\0\4\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\0\0\0"
+ "\4\0\0\0\17\0\0\0\37//,L\205\206\202\327\213\215\210\375\213\215\210"
+ "\377\213\215\210\377\213\215\210\377\212\214\207\377\212\214\207\377"
+ "\212\214\207\377\212\214\207\377\212\214\207\377\212\214\207\377\212"
+ "\214\207\377\211\213\206\377\211\213\206\377\211\213\206\377\211\213"
+ "\206\377\211\213\206\377\211\213\206\377\211\213\206\377\210\212\205"
+ "\377\210\212\205\377\210\212\205\377\210\212\205\377\210\212\205\377"
+ "\210\212\205\377\210\212\205\377\210\212\205\377\210\212\205\377\210"
+ "\212\205\377\210\212\205\377\210\212\205\377\210\212\205\377\210\212"
+ "\205\375\204\205\200\325-1-I\0\0\0\33\0\0\0\16\0\0\0\2\377\377\377\0"
+ "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377"
+ "\0\377\377\377\0\0\0\0\10\0\0\0\21\0\0\0\32\0\0\0%\0\0\0+\0\0\0" "2\0"
+ "\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2"
+ "\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0"
+ "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0"
+ "\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0" "2\0\0\0*\0\0\0$\0\0"
+ "\0\30\0\0\0\20\0\0\0\7\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377"
+ "\377\377\0\0\0\0\5\0\0\0\13\0\0\0\17\0\0\0\20\0\0\0\21\0\0\0\21\0\0\0"
+ "\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0"
+ "\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21"
+ "\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0"
+ "\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\21\0\0\0\20\0\0\0\16\0\0\0\12\0"
+ "\0\0\4\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377"
+ "\377\0\377\377\377\0\377\377\377\0\377\377\377\0";
diff --git a/src/nautilus-desktop-item-properties.c b/src/nautilus-desktop-item-properties.c
index 1094d7337..558cfbfc9 100644
--- a/src/nautilus-desktop-item-properties.c
+++ b/src/nautilus-desktop-item-properties.c
@@ -1,6 +1,6 @@
/*
* fm-ditem-page.c: Desktop item editing support
- *
+ *
* Copyright (C) 2004 James Willcox
*
* This library is free software; you can redistribute it and/or
@@ -36,484 +36,528 @@
#define MAIN_GROUP "Desktop Entry"
-typedef struct ItemEntry {
- const char *field;
- const char *description;
- char *current_value;
- gboolean localized;
- gboolean filename;
+typedef struct ItemEntry
+{
+ const char *field;
+ const char *description;
+ char *current_value;
+ gboolean localized;
+ gboolean filename;
} ItemEntry;
-enum {
- TARGET_URI_LIST
+enum
+{
+ TARGET_URI_LIST
};
-static const GtkTargetEntry target_table[] = {
- { "text/uri-list", 0, TARGET_URI_LIST }
+static const GtkTargetEntry target_table[] =
+{
+ { "text/uri-list", 0, TARGET_URI_LIST }
};
static gboolean
-_g_key_file_load_from_gfile (GKeyFile *key_file,
- GFile *file,
- GKeyFileFlags flags,
- GError **error)
+_g_key_file_load_from_gfile (GKeyFile *key_file,
+ GFile *file,
+ GKeyFileFlags flags,
+ GError **error)
{
- char *data;
- gsize len;
- gboolean res;
-
- if (!g_file_load_contents (file, NULL, &data, &len, NULL, error)) {
- return FALSE;
- }
-
- res = g_key_file_load_from_data (key_file, data, len, flags, error);
-
- g_free (data);
-
- return res;
+ char *data;
+ gsize len;
+ gboolean res;
+
+ if (!g_file_load_contents (file, NULL, &data, &len, NULL, error))
+ {
+ return FALSE;
+ }
+
+ res = g_key_file_load_from_data (key_file, data, len, flags, error);
+
+ g_free (data);
+
+ return res;
}
static gboolean
-_g_key_file_save_to_uri (GKeyFile *key_file,
- const char *uri,
- GError **error)
+_g_key_file_save_to_uri (GKeyFile *key_file,
+ const char *uri,
+ GError **error)
{
- GFile *file;
- char *data;
- gsize len;
-
- data = g_key_file_to_data (key_file, &len, error);
- if (data == NULL) {
- return FALSE;
- }
- file = g_file_new_for_uri (uri);
- if (!g_file_replace_contents (file,
- data, len,
- NULL, FALSE,
- G_FILE_CREATE_NONE,
- NULL, NULL, error)) {
- g_object_unref (file);
- g_free (data);
- return FALSE;
- }
- g_object_unref (file);
- g_free (data);
- return TRUE;
+ GFile *file;
+ char *data;
+ gsize len;
+
+ data = g_key_file_to_data (key_file, &len, error);
+ if (data == NULL)
+ {
+ return FALSE;
+ }
+ file = g_file_new_for_uri (uri);
+ if (!g_file_replace_contents (file,
+ data, len,
+ NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL, NULL, error))
+ {
+ g_object_unref (file);
+ g_free (data);
+ return FALSE;
+ }
+ g_object_unref (file);
+ g_free (data);
+ return TRUE;
}
static GKeyFile *
-_g_key_file_new_from_file (GFile *file,
- GKeyFileFlags flags,
- GError **error)
+_g_key_file_new_from_file (GFile *file,
+ GKeyFileFlags flags,
+ GError **error)
{
- GKeyFile *key_file;
-
- key_file = g_key_file_new ();
- if (!_g_key_file_load_from_gfile (key_file, file, flags, error)) {
- g_key_file_free (key_file);
- key_file = NULL;
- }
- return key_file;
+ GKeyFile *key_file;
+
+ key_file = g_key_file_new ();
+ if (!_g_key_file_load_from_gfile (key_file, file, flags, error))
+ {
+ g_key_file_free (key_file);
+ key_file = NULL;
+ }
+ return key_file;
}
static GKeyFile *
-_g_key_file_new_from_uri (const char *uri,
- GKeyFileFlags flags,
- GError **error)
+_g_key_file_new_from_uri (const char *uri,
+ GKeyFileFlags flags,
+ GError **error)
{
- GKeyFile *key_file;
- GFile *file;
-
- file = g_file_new_for_uri (uri);
- key_file = _g_key_file_new_from_file (file, flags, error);
- g_object_unref (file);
- return key_file;
+ GKeyFile *key_file;
+ GFile *file;
+
+ file = g_file_new_for_uri (uri);
+ key_file = _g_key_file_new_from_file (file, flags, error);
+ g_object_unref (file);
+ return key_file;
}
static ItemEntry *
item_entry_new (const char *field,
- const char *description,
- gboolean localized,
- gboolean filename)
+ const char *description,
+ gboolean localized,
+ gboolean filename)
{
- ItemEntry *entry;
-
- entry = g_new0 (ItemEntry, 1);
- entry->field = field;
- entry->description = description;
- entry->localized = localized;
- entry->filename = filename;
-
- return entry;
+ ItemEntry *entry;
+
+ entry = g_new0 (ItemEntry, 1);
+ entry->field = field;
+ entry->description = description;
+ entry->localized = localized;
+ entry->filename = filename;
+
+ return entry;
}
static void
item_entry_free (ItemEntry *entry)
{
- g_free (entry->current_value);
- g_free (entry);
+ g_free (entry->current_value);
+ g_free (entry);
}
static void
-nautilus_desktop_item_properties_url_drag_data_received (GtkWidget *widget, GdkDragContext *context,
- int x, int y,
+nautilus_desktop_item_properties_url_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
GtkSelectionData *selection_data,
- guint info, guint time,
- GtkEntry *entry)
+ guint info,
+ guint time,
+ GtkEntry *entry)
{
- char **uris;
- gboolean exactly_one;
- char *path;
-
- uris = g_strsplit ((gchar *) gtk_selection_data_get_data (selection_data), "\r\n", 0);
- exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
-
- if (!exactly_one) {
- g_strfreev (uris);
- return;
- }
-
- path = g_filename_from_uri (uris[0], NULL, NULL);
- if (path != NULL) {
- gtk_entry_set_text (entry, path);
- g_free (path);
- } else {
- gtk_entry_set_text (entry, uris[0]);
- }
-
- g_strfreev (uris);
+ char **uris;
+ gboolean exactly_one;
+ char *path;
+
+ uris = g_strsplit ((gchar *) gtk_selection_data_get_data (selection_data), "\r\n", 0);
+ exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
+
+ if (!exactly_one)
+ {
+ g_strfreev (uris);
+ return;
+ }
+
+ path = g_filename_from_uri (uris[0], NULL, NULL);
+ if (path != NULL)
+ {
+ gtk_entry_set_text (entry, path);
+ g_free (path);
+ }
+ else
+ {
+ gtk_entry_set_text (entry, uris[0]);
+ }
+
+ g_strfreev (uris);
}
static void
-nautilus_desktop_item_properties_exec_drag_data_received (GtkWidget *widget, GdkDragContext *context,
- int x, int y,
+nautilus_desktop_item_properties_exec_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
GtkSelectionData *selection_data,
- guint info, guint time,
- GtkEntry *entry)
+ guint info,
+ guint time,
+ GtkEntry *entry)
{
- char **uris;
- gboolean exactly_one;
- NautilusFile *file;
- GKeyFile *key_file;
- char *uri, *type, *exec;
-
- uris = g_strsplit ((gchar *) gtk_selection_data_get_data (selection_data), "\r\n", 0);
- exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
-
- if (!exactly_one) {
- g_strfreev (uris);
- return;
- }
-
- file = nautilus_file_get_by_uri (uris[0]);
-
- g_return_if_fail (file != NULL);
-
- uri = nautilus_file_get_uri (file);
- if (nautilus_file_is_mime_type (file, "application/x-desktop")) {
- key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
- if (key_file != NULL) {
- type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
- if (type != NULL && strcmp (type, "Application") == 0) {
- exec = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL);
- if (exec != NULL) {
- g_free (uri);
- uri = exec;
- }
- }
- g_free (type);
- g_key_file_free (key_file);
- }
- }
- gtk_entry_set_text (entry,
- uri?uri:"");
- gtk_widget_grab_focus (GTK_WIDGET (entry));
-
- g_free (uri);
-
- nautilus_file_unref (file);
-
- g_strfreev (uris);
+ char **uris;
+ gboolean exactly_one;
+ NautilusFile *file;
+ GKeyFile *key_file;
+ char *uri, *type, *exec;
+
+ uris = g_strsplit ((gchar *) gtk_selection_data_get_data (selection_data), "\r\n", 0);
+ exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
+
+ if (!exactly_one)
+ {
+ g_strfreev (uris);
+ return;
+ }
+
+ file = nautilus_file_get_by_uri (uris[0]);
+
+ g_return_if_fail (file != NULL);
+
+ uri = nautilus_file_get_uri (file);
+ if (nautilus_file_is_mime_type (file, "application/x-desktop"))
+ {
+ key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
+ if (key_file != NULL)
+ {
+ type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
+ if (type != NULL && strcmp (type, "Application") == 0)
+ {
+ exec = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL);
+ if (exec != NULL)
+ {
+ g_free (uri);
+ uri = exec;
+ }
+ }
+ g_free (type);
+ g_key_file_free (key_file);
+ }
+ }
+ gtk_entry_set_text (entry,
+ uri ? uri : "");
+ gtk_widget_grab_focus (GTK_WIDGET (entry));
+
+ g_free (uri);
+
+ nautilus_file_unref (file);
+
+ g_strfreev (uris);
}
static void
-save_entry (GtkEntry *entry, GKeyFile *key_file, const char *uri)
+save_entry (GtkEntry *entry,
+ GKeyFile *key_file,
+ const char *uri)
{
- GError *error;
- ItemEntry *item_entry;
- const char *val;
- gchar **languages;
-
- item_entry = g_object_get_data (G_OBJECT (entry), "item_entry");
- val = gtk_entry_get_text (entry);
-
- if (strcmp (val, item_entry->current_value) == 0) {
- return; /* No actual change, don't update file */
- }
-
- g_free (item_entry->current_value);
- item_entry->current_value = g_strdup (val);
-
- if (item_entry->localized) {
- languages = (gchar **) g_get_language_names ();
- g_key_file_set_locale_string (key_file, MAIN_GROUP, item_entry->field, languages[0], val);
- } else {
- g_key_file_set_string (key_file, MAIN_GROUP, item_entry->field, val);
- }
-
- error = NULL;
-
- if (!_g_key_file_save_to_uri (key_file, uri, &error)) {
- g_warning ("%s", error->message);
- g_error_free (error);
- }
+ GError *error;
+ ItemEntry *item_entry;
+ const char *val;
+ gchar **languages;
+
+ item_entry = g_object_get_data (G_OBJECT (entry), "item_entry");
+ val = gtk_entry_get_text (entry);
+
+ if (strcmp (val, item_entry->current_value) == 0)
+ {
+ return; /* No actual change, don't update file */
+ }
+
+ g_free (item_entry->current_value);
+ item_entry->current_value = g_strdup (val);
+
+ if (item_entry->localized)
+ {
+ languages = (gchar **) g_get_language_names ();
+ g_key_file_set_locale_string (key_file, MAIN_GROUP, item_entry->field, languages[0], val);
+ }
+ else
+ {
+ g_key_file_set_string (key_file, MAIN_GROUP, item_entry->field, val);
+ }
+
+ error = NULL;
+
+ if (!_g_key_file_save_to_uri (key_file, uri, &error))
+ {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
}
static void
entry_activate_cb (GtkWidget *entry,
- GtkWidget *container)
+ GtkWidget *container)
{
- const char *uri;
- GKeyFile *key_file;
-
- uri = g_object_get_data (G_OBJECT (container), "uri");
- key_file = g_object_get_data (G_OBJECT (container), "keyfile");
- save_entry (GTK_ENTRY (entry), key_file, uri);
+ const char *uri;
+ GKeyFile *key_file;
+
+ uri = g_object_get_data (G_OBJECT (container), "uri");
+ key_file = g_object_get_data (G_OBJECT (container), "keyfile");
+ save_entry (GTK_ENTRY (entry), key_file, uri);
}
static gboolean
-entry_focus_out_cb (GtkWidget *entry,
- GdkEventFocus *event,
- GtkWidget *container)
+entry_focus_out_cb (GtkWidget *entry,
+ GdkEventFocus *event,
+ GtkWidget *container)
{
- const char *uri;
- GKeyFile *key_file;
-
- uri = g_object_get_data (G_OBJECT (container), "uri");
- key_file = g_object_get_data (G_OBJECT (container), "keyfile");
- save_entry (GTK_ENTRY (entry), key_file, uri);
- return FALSE;
+ const char *uri;
+ GKeyFile *key_file;
+
+ uri = g_object_get_data (G_OBJECT (container), "uri");
+ key_file = g_object_get_data (G_OBJECT (container), "keyfile");
+ save_entry (GTK_ENTRY (entry), key_file, uri);
+ return FALSE;
}
static GtkWidget *
-build_grid (GtkWidget *container,
- GKeyFile *key_file,
+build_grid (GtkWidget *container,
+ GKeyFile *key_file,
GtkSizeGroup *label_size_group,
- GList *entries)
+ GList *entries)
{
- GtkWidget *grid;
- GtkWidget *label;
- GtkWidget *entry;
- GList *l;
- char *val;
-
- grid = gtk_grid_new ();
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
- gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
- gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
-
- for (l = entries; l; l = l->next) {
- ItemEntry *item_entry = (ItemEntry *)l->data;
- char *label_text;
-
- label_text = g_strdup_printf ("%s:", item_entry->description);
- label = gtk_label_new (label_text);
- gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
- g_free (label_text);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_size_group_add_widget (label_size_group, label);
-
- entry = gtk_entry_new ();
- gtk_widget_set_hexpand (entry, TRUE);
-
- if (item_entry->localized) {
- val = g_key_file_get_locale_string (key_file,
- MAIN_GROUP,
- item_entry->field,
- NULL, NULL);
- } else {
- val = g_key_file_get_string (key_file,
- MAIN_GROUP,
- item_entry->field,
- NULL);
- }
-
- item_entry->current_value = g_strdup (val?val:"");
- gtk_entry_set_text (GTK_ENTRY (entry), item_entry->current_value);
- g_free (val);
-
- gtk_container_add (GTK_CONTAINER (grid), label);
- gtk_grid_attach_next_to (GTK_GRID (grid), entry, label,
- GTK_POS_RIGHT, 1, 1);
-
- g_signal_connect (entry, "activate",
- G_CALLBACK (entry_activate_cb),
- container);
- g_signal_connect (entry, "focus-out-event",
- G_CALLBACK (entry_focus_out_cb),
- container);
-
- g_object_set_data_full (G_OBJECT (entry), "item_entry", item_entry,
- (GDestroyNotify)item_entry_free);
-
- if (item_entry->filename) {
- gtk_drag_dest_set (GTK_WIDGET (entry),
- GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
- target_table, G_N_ELEMENTS (target_table),
- GDK_ACTION_COPY | GDK_ACTION_MOVE);
-
- g_signal_connect (entry, "drag-data-received",
- G_CALLBACK (nautilus_desktop_item_properties_url_drag_data_received),
- entry);
- } else if (strcmp (item_entry->field, "Exec") == 0) {
- gtk_drag_dest_set (GTK_WIDGET (entry),
- GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
- target_table, G_N_ELEMENTS (target_table),
- GDK_ACTION_COPY | GDK_ACTION_MOVE);
-
- g_signal_connect (entry, "drag-data-received",
- G_CALLBACK (nautilus_desktop_item_properties_exec_drag_data_received),
- entry);
- }
- }
-
- /* append dummy row */
- label = gtk_label_new ("");
- gtk_container_add (GTK_CONTAINER (grid), label);
- gtk_size_group_add_widget (label_size_group, label);
+ GtkWidget *grid;
+ GtkWidget *label;
+ GtkWidget *entry;
+ GList *l;
+ char *val;
+
+ grid = gtk_grid_new ();
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
+
+ for (l = entries; l; l = l->next)
+ {
+ ItemEntry *item_entry = (ItemEntry *) l->data;
+ char *label_text;
+
+ label_text = g_strdup_printf ("%s:", item_entry->description);
+ label = gtk_label_new (label_text);
+ gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+ g_free (label_text);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_size_group_add_widget (label_size_group, label);
+
+ entry = gtk_entry_new ();
+ gtk_widget_set_hexpand (entry, TRUE);
+
+ if (item_entry->localized)
+ {
+ val = g_key_file_get_locale_string (key_file,
+ MAIN_GROUP,
+ item_entry->field,
+ NULL, NULL);
+ }
+ else
+ {
+ val = g_key_file_get_string (key_file,
+ MAIN_GROUP,
+ item_entry->field,
+ NULL);
+ }
+
+ item_entry->current_value = g_strdup (val ? val : "");
+ gtk_entry_set_text (GTK_ENTRY (entry), item_entry->current_value);
+ g_free (val);
- gtk_widget_show_all (grid);
- return grid;
+ gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_grid_attach_next_to (GTK_GRID (grid), entry, label,
+ GTK_POS_RIGHT, 1, 1);
+
+ g_signal_connect (entry, "activate",
+ G_CALLBACK (entry_activate_cb),
+ container);
+ g_signal_connect (entry, "focus-out-event",
+ G_CALLBACK (entry_focus_out_cb),
+ container);
+
+ g_object_set_data_full (G_OBJECT (entry), "item_entry", item_entry,
+ (GDestroyNotify) item_entry_free);
+
+ if (item_entry->filename)
+ {
+ gtk_drag_dest_set (GTK_WIDGET (entry),
+ GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
+ target_table, G_N_ELEMENTS (target_table),
+ GDK_ACTION_COPY | GDK_ACTION_MOVE);
+
+ g_signal_connect (entry, "drag-data-received",
+ G_CALLBACK (nautilus_desktop_item_properties_url_drag_data_received),
+ entry);
+ }
+ else if (strcmp (item_entry->field, "Exec") == 0)
+ {
+ gtk_drag_dest_set (GTK_WIDGET (entry),
+ GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
+ target_table, G_N_ELEMENTS (target_table),
+ GDK_ACTION_COPY | GDK_ACTION_MOVE);
+
+ g_signal_connect (entry, "drag-data-received",
+ G_CALLBACK (nautilus_desktop_item_properties_exec_drag_data_received),
+ entry);
+ }
+ }
+
+ /* append dummy row */
+ label = gtk_label_new ("");
+ gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_size_group_add_widget (label_size_group, label);
+
+ gtk_widget_show_all (grid);
+ return grid;
}
static void
-create_page (GKeyFile *key_file, GtkWidget *box)
+create_page (GKeyFile *key_file,
+ GtkWidget *box)
{
- GtkWidget *grid;
- GList *entries;
- GtkSizeGroup *label_size_group;
- char *type;
-
- entries = NULL;
-
- type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
-
- if (g_strcmp0 (type, "Link") == 0) {
- entries = g_list_prepend (entries,
- item_entry_new ("Comment",
- _("Comment"), TRUE, FALSE));
- entries = g_list_prepend (entries,
- item_entry_new ("URL",
- _("URL"), FALSE, TRUE));
- entries = g_list_prepend (entries,
- item_entry_new ("GenericName",
- _("Description"), TRUE, FALSE));
- } else if (g_strcmp0 (type, "Application") == 0) {
- entries = g_list_prepend (entries,
- item_entry_new ("Comment",
- _("Comment"), TRUE, FALSE));
- entries = g_list_prepend (entries,
- item_entry_new ("Exec",
- _("Command"), FALSE, FALSE));
- entries = g_list_prepend (entries,
- item_entry_new ("GenericName",
- _("Description"), TRUE, FALSE));
- } else {
- /* we only handle launchers and links */
-
- /* ensure that we build an empty table with a dummy row at the end */
- goto build_table;
- }
- g_free (type);
+ GtkWidget *grid;
+ GList *entries;
+ GtkSizeGroup *label_size_group;
+ char *type;
+
+ entries = NULL;
+
+ type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
+
+ if (g_strcmp0 (type, "Link") == 0)
+ {
+ entries = g_list_prepend (entries,
+ item_entry_new ("Comment",
+ _("Comment"), TRUE, FALSE));
+ entries = g_list_prepend (entries,
+ item_entry_new ("URL",
+ _("URL"), FALSE, TRUE));
+ entries = g_list_prepend (entries,
+ item_entry_new ("GenericName",
+ _("Description"), TRUE, FALSE));
+ }
+ else if (g_strcmp0 (type, "Application") == 0)
+ {
+ entries = g_list_prepend (entries,
+ item_entry_new ("Comment",
+ _("Comment"), TRUE, FALSE));
+ entries = g_list_prepend (entries,
+ item_entry_new ("Exec",
+ _("Command"), FALSE, FALSE));
+ entries = g_list_prepend (entries,
+ item_entry_new ("GenericName",
+ _("Description"), TRUE, FALSE));
+ }
+ else
+ {
+ /* we only handle launchers and links */
+
+ /* ensure that we build an empty table with a dummy row at the end */
+ goto build_table;
+ }
+ g_free (type);
build_table:
- label_size_group = g_object_get_data (G_OBJECT (box), "label-size-group");
+ label_size_group = g_object_get_data (G_OBJECT (box), "label-size-group");
- grid = build_grid (box, key_file, label_size_group, entries);
- g_list_free (entries);
-
- gtk_box_pack_start (GTK_BOX (box), grid, FALSE, TRUE, 0);
- gtk_widget_show_all (GTK_WIDGET (box));
+ grid = build_grid (box, key_file, label_size_group, entries);
+ g_list_free (entries);
+
+ gtk_box_pack_start (GTK_BOX (box), grid, FALSE, TRUE, 0);
+ gtk_widget_show_all (GTK_WIDGET (box));
}
static void
-ditem_read_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+ditem_read_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GKeyFile *key_file;
- GtkWidget *box;
- gsize file_size;
- char *file_contents;
-
- box = GTK_WIDGET (user_data);
-
- if (g_file_load_contents_finish (G_FILE (source_object),
- res,
- &file_contents, &file_size,
- NULL, NULL)) {
- key_file = g_key_file_new ();
- g_object_set_data_full (G_OBJECT (box), "keyfile", key_file, (GDestroyNotify)g_key_file_free);
- if (g_key_file_load_from_data (key_file, file_contents, file_size, 0, NULL)) {
- create_page (key_file, box);
- }
- g_free (file_contents);
-
- }
- g_object_unref (box);
+ GKeyFile *key_file;
+ GtkWidget *box;
+ gsize file_size;
+ char *file_contents;
+
+ box = GTK_WIDGET (user_data);
+
+ if (g_file_load_contents_finish (G_FILE (source_object),
+ res,
+ &file_contents, &file_size,
+ NULL, NULL))
+ {
+ key_file = g_key_file_new ();
+ g_object_set_data_full (G_OBJECT (box), "keyfile", key_file, (GDestroyNotify) g_key_file_free);
+ if (g_key_file_load_from_data (key_file, file_contents, file_size, 0, NULL))
+ {
+ create_page (key_file, box);
+ }
+ g_free (file_contents);
+ }
+ g_object_unref (box);
}
static void
nautilus_desktop_item_properties_create_begin (const char *uri,
- GtkWidget *box)
+ GtkWidget *box)
{
- GFile *location;
+ GFile *location;
- location = g_file_new_for_uri (uri);
- g_object_set_data_full (G_OBJECT (box), "uri", g_strdup (uri), g_free);
- g_file_load_contents_async (location, NULL, ditem_read_cb, g_object_ref (box));
- g_object_unref (location);
+ location = g_file_new_for_uri (uri);
+ g_object_set_data_full (G_OBJECT (box), "uri", g_strdup (uri), g_free);
+ g_file_load_contents_async (location, NULL, ditem_read_cb, g_object_ref (box));
+ g_object_unref (location);
}
GtkWidget *
nautilus_desktop_item_properties_make_box (GtkSizeGroup *label_size_group,
- GList *files)
+ GList *files)
{
- NautilusFileInfo *info;
- char *uri;
- GtkWidget *box;
+ NautilusFileInfo *info;
+ char *uri;
+ GtkWidget *box;
- g_assert (nautilus_desktop_item_properties_should_show (files));
+ g_assert (nautilus_desktop_item_properties_should_show (files));
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- g_object_set_data_full (G_OBJECT (box), "label-size-group",
- label_size_group, (GDestroyNotify) g_object_unref);
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ g_object_set_data_full (G_OBJECT (box), "label-size-group",
+ label_size_group, (GDestroyNotify) g_object_unref);
- info = NAUTILUS_FILE_INFO (files->data);
+ info = NAUTILUS_FILE_INFO (files->data);
- uri = nautilus_file_info_get_uri (info);
- nautilus_desktop_item_properties_create_begin (uri, box);
- g_free (uri);
+ uri = nautilus_file_info_get_uri (info);
+ nautilus_desktop_item_properties_create_begin (uri, box);
+ g_free (uri);
- return box;
+ return box;
}
gboolean
nautilus_desktop_item_properties_should_show (GList *files)
{
- NautilusFileInfo *info;
+ NautilusFileInfo *info;
- if (!files || files->next) {
- return FALSE;
- }
+ if (!files || files->next)
+ {
+ return FALSE;
+ }
- info = NAUTILUS_FILE_INFO (files->data);
+ info = NAUTILUS_FILE_INFO (files->data);
- if (!nautilus_file_info_is_mime_type (info, "application/x-desktop")) {
- return FALSE;
- }
+ if (!nautilus_file_info_is_mime_type (info, "application/x-desktop"))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
-
diff --git a/src/nautilus-directory-async.c b/src/nautilus-directory-async.c
index ea97da61f..e8a10cd3b 100644
--- a/src/nautilus-directory-async.c
+++ b/src/nautilus-directory-async.c
@@ -1,23 +1,23 @@
/*
- nautilus-directory-async.c: Nautilus directory model state machine.
-
- Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * nautilus-directory-async.c: Nautilus directory model state machine.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
@@ -56,118 +56,133 @@
/* Keep async. jobs down to this number for all directories. */
#define MAX_ASYNC_JOBS 10
-struct TopLeftTextReadState {
- NautilusDirectory *directory;
- NautilusFile *file;
- gboolean large;
- GCancellable *cancellable;
+struct TopLeftTextReadState
+{
+ NautilusDirectory *directory;
+ NautilusFile *file;
+ gboolean large;
+ GCancellable *cancellable;
};
-struct LinkInfoReadState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- NautilusFile *file;
+struct LinkInfoReadState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ NautilusFile *file;
};
-struct ThumbnailState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- NautilusFile *file;
- gboolean trying_original;
- gboolean tried_original;
+struct ThumbnailState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ NautilusFile *file;
+ gboolean trying_original;
+ gboolean tried_original;
};
-struct MountState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- NautilusFile *file;
+struct MountState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ NautilusFile *file;
};
-struct FilesystemInfoState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- NautilusFile *file;
+struct FilesystemInfoState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ NautilusFile *file;
};
-struct DirectoryLoadState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- GFileEnumerator *enumerator;
- GHashTable *load_mime_list_hash;
- NautilusFile *load_directory_file;
- int load_file_count;
+struct DirectoryLoadState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ GFileEnumerator *enumerator;
+ GHashTable *load_mime_list_hash;
+ NautilusFile *load_directory_file;
+ int load_file_count;
};
-struct MimeListState {
- NautilusDirectory *directory;
- NautilusFile *mime_list_file;
- GCancellable *cancellable;
- GFileEnumerator *enumerator;
- GHashTable *mime_list_hash;
+struct MimeListState
+{
+ NautilusDirectory *directory;
+ NautilusFile *mime_list_file;
+ GCancellable *cancellable;
+ GFileEnumerator *enumerator;
+ GHashTable *mime_list_hash;
};
-struct GetInfoState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
+struct GetInfoState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
};
-struct NewFilesState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- int count;
+struct NewFilesState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ int count;
};
-struct DirectoryCountState {
- NautilusDirectory *directory;
- NautilusFile *count_file;
- GCancellable *cancellable;
- GFileEnumerator *enumerator;
- int file_count;
+struct DirectoryCountState
+{
+ NautilusDirectory *directory;
+ NautilusFile *count_file;
+ GCancellable *cancellable;
+ GFileEnumerator *enumerator;
+ int file_count;
};
-struct DeepCountState {
- NautilusDirectory *directory;
- GCancellable *cancellable;
- GFileEnumerator *enumerator;
- GFile *deep_count_location;
- GList *deep_count_subdirectories;
- GArray *seen_deep_count_inodes;
- char *fs_id;
+struct DeepCountState
+{
+ NautilusDirectory *directory;
+ GCancellable *cancellable;
+ GFileEnumerator *enumerator;
+ GFile *deep_count_location;
+ GList *deep_count_subdirectories;
+ GArray *seen_deep_count_inodes;
+ char *fs_id;
};
-typedef struct {
- NautilusFile *file; /* Which file, NULL means all. */
- union {
- NautilusDirectoryCallback directory;
- NautilusFileCallback file;
- } callback;
- gpointer callback_data;
- Request request;
- gboolean active; /* Set to FALSE when the callback is triggered and
- * scheduled to be called at idle, its still kept
- * in the list so we can kill it when the file
- * goes away.
- */
+typedef struct
+{
+ NautilusFile *file; /* Which file, NULL means all. */
+ union
+ {
+ NautilusDirectoryCallback directory;
+ NautilusFileCallback file;
+ } callback;
+ gpointer callback_data;
+ Request request;
+ gboolean active; /* Set to FALSE when the callback is triggered and
+ * scheduled to be called at idle, its still kept
+ * in the list so we can kill it when the file
+ * goes away.
+ */
} ReadyCallback;
-typedef struct {
- NautilusFile *file; /* Which file, NULL means all. */
- gboolean monitor_hidden_files; /* defines whether "all" includes hidden files */
- gconstpointer client;
- Request request;
+typedef struct
+{
+ NautilusFile *file; /* Which file, NULL means all. */
+ gboolean monitor_hidden_files; /* defines whether "all" includes hidden files */
+ gconstpointer client;
+ Request request;
} Monitor;
-typedef struct {
- NautilusDirectory *directory;
- NautilusInfoProvider *provider;
- NautilusOperationHandle *handle;
- NautilusOperationResult result;
+typedef struct
+{
+ NautilusDirectory *directory;
+ NautilusInfoProvider *provider;
+ NautilusOperationHandle *handle;
+ NautilusOperationResult result;
} InfoProviderResponse;
-typedef gboolean (* RequestCheck) (Request);
-typedef gboolean (* FileCheck) (NautilusFile *);
+typedef gboolean (*RequestCheck) (Request);
+typedef gboolean (*FileCheck) (NautilusFile *);
/* Current number of async. jobs. */
static int async_job_count;
@@ -177,157 +192,174 @@ static GHashTable *async_jobs;
#endif
/* Forward declarations for functions that need them. */
-static void deep_count_load (DeepCountState *state,
- GFile *location);
-static gboolean request_is_satisfied (NautilusDirectory *directory,
- NautilusFile *file,
- Request request);
-static void cancel_loading_attributes (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes);
-static void add_all_files_to_work_queue (NautilusDirectory *directory);
-static void link_info_done (NautilusDirectory *directory,
- NautilusFile *file,
- const char *uri,
- const char *name,
- GIcon *icon,
- gboolean is_launcher,
- gboolean is_foreign);
-static void move_file_to_low_priority_queue (NautilusDirectory *directory,
- NautilusFile *file);
-static void move_file_to_extension_queue (NautilusDirectory *directory,
- NautilusFile *file);
-static void nautilus_directory_invalidate_file_attributes (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes);
+static void deep_count_load (DeepCountState *state,
+ GFile *location);
+static gboolean request_is_satisfied (NautilusDirectory *directory,
+ NautilusFile *file,
+ Request request);
+static void cancel_loading_attributes (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes);
+static void add_all_files_to_work_queue (NautilusDirectory *directory);
+static void link_info_done (NautilusDirectory *directory,
+ NautilusFile *file,
+ const char *uri,
+ const char *name,
+ GIcon *icon,
+ gboolean is_launcher,
+ gboolean is_foreign);
+static void move_file_to_low_priority_queue (NautilusDirectory *directory,
+ NautilusFile *file);
+static void move_file_to_extension_queue (NautilusDirectory *directory,
+ NautilusFile *file);
+static void nautilus_directory_invalidate_file_attributes (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes);
/* Some helpers for case-insensitive strings.
* Move to nautilus-glib-extensions?
*/
static gboolean
-istr_equal (gconstpointer v, gconstpointer v2)
+istr_equal (gconstpointer v,
+ gconstpointer v2)
{
- return g_ascii_strcasecmp (v, v2) == 0;
+ return g_ascii_strcasecmp (v, v2) == 0;
}
static guint
istr_hash (gconstpointer key)
{
- const char *p;
- guint h;
+ const char *p;
+ guint h;
- h = 0;
- for (p = key; *p != '\0'; p++) {
- h = (h << 5) - h + g_ascii_tolower (*p);
- }
-
- return h;
+ h = 0;
+ for (p = key; *p != '\0'; p++)
+ {
+ h = (h << 5) - h + g_ascii_tolower (*p);
+ }
+
+ return h;
}
static GHashTable *
istr_set_new (void)
{
- return g_hash_table_new_full (istr_hash, istr_equal, g_free, NULL);
+ return g_hash_table_new_full (istr_hash, istr_equal, g_free, NULL);
}
static void
-istr_set_insert (GHashTable *table, const char *istr)
+istr_set_insert (GHashTable *table,
+ const char *istr)
{
- char *key;
+ char *key;
- key = g_strdup (istr);
- g_hash_table_replace (table, key, key);
+ key = g_strdup (istr);
+ g_hash_table_replace (table, key, key);
}
static void
-add_istr_to_list (gpointer key, gpointer value, gpointer callback_data)
+add_istr_to_list (gpointer key,
+ gpointer value,
+ gpointer callback_data)
{
- GList **list;
+ GList **list;
- list = callback_data;
- *list = g_list_prepend (*list, g_strdup (key));
+ list = callback_data;
+ *list = g_list_prepend (*list, g_strdup (key));
}
static GList *
istr_set_get_as_list (GHashTable *table)
{
- GList *list;
+ GList *list;
- list = NULL;
- g_hash_table_foreach (table, add_istr_to_list, &list);
- return list;
+ list = NULL;
+ g_hash_table_foreach (table, add_istr_to_list, &list);
+ return list;
}
static void
istr_set_destroy (GHashTable *table)
{
- g_hash_table_destroy (table);
+ g_hash_table_destroy (table);
}
static void
request_counter_add_request (RequestCounter counter,
- Request request)
+ Request request)
{
- guint i;
+ guint i;
- for (i = 0; i < REQUEST_TYPE_LAST; i++) {
- if (REQUEST_WANTS_TYPE (request, i)) {
- counter[i]++;
- }
- }
+ for (i = 0; i < REQUEST_TYPE_LAST; i++)
+ {
+ if (REQUEST_WANTS_TYPE (request, i))
+ {
+ counter[i]++;
+ }
+ }
}
static void
request_counter_remove_request (RequestCounter counter,
- Request request)
+ Request request)
{
- guint i;
+ guint i;
- for (i = 0; i < REQUEST_TYPE_LAST; i++) {
- if (REQUEST_WANTS_TYPE (request, i)) {
- counter[i]--;
- }
- }
+ for (i = 0; i < REQUEST_TYPE_LAST; i++)
+ {
+ if (REQUEST_WANTS_TYPE (request, i))
+ {
+ counter[i]--;
+ }
+ }
}
#if 0
static void
nautilus_directory_verify_request_counts (NautilusDirectory *directory)
{
- GList *l;
- RequestCounter counters;
- int i;
- gboolean fail;
-
- fail = FALSE;
- for (i = 0; i < REQUEST_TYPE_LAST; i ++) {
- counters[i] = 0;
- }
- for (l = directory->details->monitor_list; l != NULL; l = l->next) {
- Monitor *monitor = l->data;
- request_counter_add_request (counters, monitor->request);
- }
- for (i = 0; i < REQUEST_TYPE_LAST; i ++) {
- if (counters[i] != directory->details->monitor_counters[i]) {
- g_warning ("monitor counter for %i is wrong, expecting %d but found %d",
- i, counters[i], directory->details->monitor_counters[i]);
- fail = TRUE;
- }
- }
- for (i = 0; i < REQUEST_TYPE_LAST; i ++) {
- counters[i] = 0;
- }
- for (l = directory->details->call_when_ready_list; l != NULL; l = l->next) {
- ReadyCallback *callback = l->data;
- request_counter_add_request (counters, callback->request);
- }
- for (i = 0; i < REQUEST_TYPE_LAST; i ++) {
- if (counters[i] != directory->details->call_when_ready_counters[i]) {
- g_warning ("call when ready counter for %i is wrong, expecting %d but found %d",
- i, counters[i], directory->details->call_when_ready_counters[i]);
- fail = TRUE;
- }
- }
- g_assert (!fail);
+ GList *l;
+ RequestCounter counters;
+ int i;
+ gboolean fail;
+
+ fail = FALSE;
+ for (i = 0; i < REQUEST_TYPE_LAST; i++)
+ {
+ counters[i] = 0;
+ }
+ for (l = directory->details->monitor_list; l != NULL; l = l->next)
+ {
+ Monitor *monitor = l->data;
+ request_counter_add_request (counters, monitor->request);
+ }
+ for (i = 0; i < REQUEST_TYPE_LAST; i++)
+ {
+ if (counters[i] != directory->details->monitor_counters[i])
+ {
+ g_warning ("monitor counter for %i is wrong, expecting %d but found %d",
+ i, counters[i], directory->details->monitor_counters[i]);
+ fail = TRUE;
+ }
+ }
+ for (i = 0; i < REQUEST_TYPE_LAST; i++)
+ {
+ counters[i] = 0;
+ }
+ for (l = directory->details->call_when_ready_list; l != NULL; l = l->next)
+ {
+ ReadyCallback *callback = l->data;
+ request_counter_add_request (counters, callback->request);
+ }
+ for (i = 0; i < REQUEST_TYPE_LAST; i++)
+ {
+ if (counters[i] != directory->details->call_when_ready_counters[i])
+ {
+ g_warning ("call when ready counter for %i is wrong, expecting %d but found %d",
+ i, counters[i], directory->details->call_when_ready_counters[i]);
+ fail = TRUE;
+ }
+ }
+ g_assert (!fail);
}
#endif
@@ -337,110 +369,120 @@ nautilus_directory_verify_request_counts (NautilusDirectory *directory)
*/
static gboolean
async_job_start (NautilusDirectory *directory,
- const char *job)
+ const char *job)
{
#ifdef DEBUG_ASYNC_JOBS
- char *key;
+ char *key;
#endif
#ifdef DEBUG_START_STOP
- g_message ("starting %s in %p", job, directory->details->location);
+ g_message ("starting %s in %p", job, directory->details->location);
#endif
- g_assert (async_job_count >= 0);
- g_assert (async_job_count <= MAX_ASYNC_JOBS);
+ g_assert (async_job_count >= 0);
+ g_assert (async_job_count <= MAX_ASYNC_JOBS);
+
+ if (async_job_count >= MAX_ASYNC_JOBS)
+ {
+ if (waiting_directories == NULL)
+ {
+ waiting_directories = g_hash_table_new (NULL, NULL);
+ }
- if (async_job_count >= MAX_ASYNC_JOBS) {
- if (waiting_directories == NULL) {
- waiting_directories = g_hash_table_new (NULL, NULL);
- }
+ g_hash_table_insert (waiting_directories,
+ directory,
+ directory);
- g_hash_table_insert (waiting_directories,
- directory,
- directory);
-
- return FALSE;
- }
+ return FALSE;
+ }
#ifdef DEBUG_ASYNC_JOBS
- {
- char *uri;
- if (async_jobs == NULL) {
- async_jobs = g_hash_table_new (g_str_hash, g_str_equal);
- }
- uri = nautilus_directory_get_uri (directory);
- key = g_strconcat (uri, ": ", job, NULL);
- if (g_hash_table_lookup (async_jobs, key) != NULL) {
- g_warning ("same job twice: %s in %s",
- job, uri);
- }
- g_free (uri);
- g_hash_table_insert (async_jobs, key, directory);
- }
-#endif
-
- async_job_count += 1;
- return TRUE;
+ {
+ char *uri;
+ if (async_jobs == NULL)
+ {
+ async_jobs = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+ uri = nautilus_directory_get_uri (directory);
+ key = g_strconcat (uri, ": ", job, NULL);
+ if (g_hash_table_lookup (async_jobs, key) != NULL)
+ {
+ g_warning ("same job twice: %s in %s",
+ job, uri);
+ }
+ g_free (uri);
+ g_hash_table_insert (async_jobs, key, directory);
+ }
+#endif
+
+ async_job_count += 1;
+ return TRUE;
}
/* End a job. */
static void
async_job_end (NautilusDirectory *directory,
- const char *job)
+ const char *job)
{
#ifdef DEBUG_ASYNC_JOBS
- char *key;
- gpointer table_key, value;
+ char *key;
+ gpointer table_key, value;
#endif
#ifdef DEBUG_START_STOP
- g_message ("stopping %s in %p", job, directory->details->location);
+ g_message ("stopping %s in %p", job, directory->details->location);
#endif
- g_assert (async_job_count > 0);
+ g_assert (async_job_count > 0);
#ifdef DEBUG_ASYNC_JOBS
- {
- char *uri;
- uri = nautilus_directory_get_uri (directory);
- g_assert (async_jobs != NULL);
- key = g_strconcat (uri, ": ", job, NULL);
- if (!g_hash_table_lookup_extended (async_jobs, key, &table_key, &value)) {
- g_warning ("ending job we didn't start: %s in %s",
- job, uri);
- } else {
- g_hash_table_remove (async_jobs, key);
- g_free (table_key);
- }
- g_free (uri);
- g_free (key);
- }
+ {
+ char *uri;
+ uri = nautilus_directory_get_uri (directory);
+ g_assert (async_jobs != NULL);
+ key = g_strconcat (uri, ": ", job, NULL);
+ if (!g_hash_table_lookup_extended (async_jobs, key, &table_key, &value))
+ {
+ g_warning ("ending job we didn't start: %s in %s",
+ job, uri);
+ }
+ else
+ {
+ g_hash_table_remove (async_jobs, key);
+ g_free (table_key);
+ }
+ g_free (uri);
+ g_free (key);
+ }
#endif
- async_job_count -= 1;
+ async_job_count -= 1;
}
/* Helper to get one value from a hash table. */
static void
-get_one_value_callback (gpointer key, gpointer value, gpointer callback_data)
+get_one_value_callback (gpointer key,
+ gpointer value,
+ gpointer callback_data)
{
- gpointer *returned_value;
+ gpointer *returned_value;
- returned_value = callback_data;
- *returned_value = value;
+ returned_value = callback_data;
+ *returned_value = value;
}
/* return a single value from a hash table. */
static gpointer
get_one_value (GHashTable *table)
{
- gpointer value;
+ gpointer value;
- value = NULL;
- if (table != NULL) {
- g_hash_table_foreach (table, get_one_value_callback, &value);
- }
- return value;
+ value = NULL;
+ if (table != NULL)
+ {
+ g_hash_table_foreach (table, get_one_value_callback, &value);
+ }
+ return value;
}
/* Wake up directories that are "blocked" as long as there are job
@@ -449,354 +491,397 @@ get_one_value (GHashTable *table)
static void
async_job_wake_up (void)
{
- static gboolean already_waking_up = FALSE;
- gpointer value;
-
- g_assert (async_job_count >= 0);
- g_assert (async_job_count <= MAX_ASYNC_JOBS);
-
- if (already_waking_up) {
- return;
- }
-
- already_waking_up = TRUE;
- while (async_job_count < MAX_ASYNC_JOBS) {
- value = get_one_value (waiting_directories);
- if (value == NULL) {
- break;
- }
- g_hash_table_remove (waiting_directories, value);
- nautilus_directory_async_state_changed
- (NAUTILUS_DIRECTORY (value));
- }
- already_waking_up = FALSE;
+ static gboolean already_waking_up = FALSE;
+ gpointer value;
+
+ g_assert (async_job_count >= 0);
+ g_assert (async_job_count <= MAX_ASYNC_JOBS);
+
+ if (already_waking_up)
+ {
+ return;
+ }
+
+ already_waking_up = TRUE;
+ while (async_job_count < MAX_ASYNC_JOBS)
+ {
+ value = get_one_value (waiting_directories);
+ if (value == NULL)
+ {
+ break;
+ }
+ g_hash_table_remove (waiting_directories, value);
+ nautilus_directory_async_state_changed
+ (NAUTILUS_DIRECTORY (value));
+ }
+ already_waking_up = FALSE;
}
static void
directory_count_cancel (NautilusDirectory *directory)
{
- if (directory->details->count_in_progress != NULL) {
- g_cancellable_cancel (directory->details->count_in_progress->cancellable);
- directory->details->count_in_progress = NULL;
- }
+ if (directory->details->count_in_progress != NULL)
+ {
+ g_cancellable_cancel (directory->details->count_in_progress->cancellable);
+ directory->details->count_in_progress = NULL;
+ }
}
static void
deep_count_cancel (NautilusDirectory *directory)
{
- if (directory->details->deep_count_in_progress != NULL) {
- g_assert (NAUTILUS_IS_FILE (directory->details->deep_count_file));
-
- g_cancellable_cancel (directory->details->deep_count_in_progress->cancellable);
+ if (directory->details->deep_count_in_progress != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (directory->details->deep_count_file));
+
+ g_cancellable_cancel (directory->details->deep_count_in_progress->cancellable);
- directory->details->deep_count_file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
+ directory->details->deep_count_file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
- directory->details->deep_count_in_progress->directory = NULL;
- directory->details->deep_count_in_progress = NULL;
- directory->details->deep_count_file = NULL;
+ directory->details->deep_count_in_progress->directory = NULL;
+ directory->details->deep_count_in_progress = NULL;
+ directory->details->deep_count_file = NULL;
- async_job_end (directory, "deep count");
- }
+ async_job_end (directory, "deep count");
+ }
}
static void
mime_list_cancel (NautilusDirectory *directory)
{
- if (directory->details->mime_list_in_progress != NULL) {
- g_cancellable_cancel (directory->details->mime_list_in_progress->cancellable);
- }
+ if (directory->details->mime_list_in_progress != NULL)
+ {
+ g_cancellable_cancel (directory->details->mime_list_in_progress->cancellable);
+ }
}
static void
link_info_cancel (NautilusDirectory *directory)
{
- if (directory->details->link_info_read_state != NULL) {
- g_cancellable_cancel (directory->details->link_info_read_state->cancellable);
- directory->details->link_info_read_state->directory = NULL;
- directory->details->link_info_read_state = NULL;
- async_job_end (directory, "link info");
- }
+ if (directory->details->link_info_read_state != NULL)
+ {
+ g_cancellable_cancel (directory->details->link_info_read_state->cancellable);
+ directory->details->link_info_read_state->directory = NULL;
+ directory->details->link_info_read_state = NULL;
+ async_job_end (directory, "link info");
+ }
}
static void
thumbnail_cancel (NautilusDirectory *directory)
{
- if (directory->details->thumbnail_state != NULL) {
- g_cancellable_cancel (directory->details->thumbnail_state->cancellable);
- directory->details->thumbnail_state->directory = NULL;
- directory->details->thumbnail_state = NULL;
- async_job_end (directory, "thumbnail");
- }
+ if (directory->details->thumbnail_state != NULL)
+ {
+ g_cancellable_cancel (directory->details->thumbnail_state->cancellable);
+ directory->details->thumbnail_state->directory = NULL;
+ directory->details->thumbnail_state = NULL;
+ async_job_end (directory, "thumbnail");
+ }
}
static void
mount_cancel (NautilusDirectory *directory)
{
- if (directory->details->mount_state != NULL) {
- g_cancellable_cancel (directory->details->mount_state->cancellable);
- directory->details->mount_state->directory = NULL;
- directory->details->mount_state = NULL;
- async_job_end (directory, "mount");
- }
+ if (directory->details->mount_state != NULL)
+ {
+ g_cancellable_cancel (directory->details->mount_state->cancellable);
+ directory->details->mount_state->directory = NULL;
+ directory->details->mount_state = NULL;
+ async_job_end (directory, "mount");
+ }
}
static void
file_info_cancel (NautilusDirectory *directory)
{
- if (directory->details->get_info_in_progress != NULL) {
- g_cancellable_cancel (directory->details->get_info_in_progress->cancellable);
- directory->details->get_info_in_progress->directory = NULL;
- directory->details->get_info_in_progress = NULL;
- directory->details->get_info_file = NULL;
+ if (directory->details->get_info_in_progress != NULL)
+ {
+ g_cancellable_cancel (directory->details->get_info_in_progress->cancellable);
+ directory->details->get_info_in_progress->directory = NULL;
+ directory->details->get_info_in_progress = NULL;
+ directory->details->get_info_file = NULL;
- async_job_end (directory, "file info");
- }
+ async_job_end (directory, "file info");
+ }
}
static void
new_files_cancel (NautilusDirectory *directory)
{
- GList *l;
- NewFilesState *state;
-
- if (directory->details->new_files_in_progress != NULL) {
- for (l = directory->details->new_files_in_progress; l != NULL; l = l->next) {
- state = l->data;
- g_cancellable_cancel (state->cancellable);
- state->directory = NULL;
- }
- g_list_free (directory->details->new_files_in_progress);
- directory->details->new_files_in_progress = NULL;
- }
+ GList *l;
+ NewFilesState *state;
+
+ if (directory->details->new_files_in_progress != NULL)
+ {
+ for (l = directory->details->new_files_in_progress; l != NULL; l = l->next)
+ {
+ state = l->data;
+ g_cancellable_cancel (state->cancellable);
+ state->directory = NULL;
+ }
+ g_list_free (directory->details->new_files_in_progress);
+ directory->details->new_files_in_progress = NULL;
+ }
}
static int
monitor_key_compare (gconstpointer a,
- gconstpointer data)
-{
- const Monitor *monitor;
- const Monitor *compare_monitor;
-
- monitor = a;
- compare_monitor = data;
-
- if (monitor->client < compare_monitor->client) {
- return -1;
- }
- if (monitor->client > compare_monitor->client) {
- return +1;
- }
-
- if (monitor->file < compare_monitor->file) {
- return -1;
- }
- if (monitor->file > compare_monitor->file) {
- return +1;
- }
-
- return 0;
+ gconstpointer data)
+{
+ const Monitor *monitor;
+ const Monitor *compare_monitor;
+
+ monitor = a;
+ compare_monitor = data;
+
+ if (monitor->client < compare_monitor->client)
+ {
+ return -1;
+ }
+ if (monitor->client > compare_monitor->client)
+ {
+ return +1;
+ }
+
+ if (monitor->file < compare_monitor->file)
+ {
+ return -1;
+ }
+ if (monitor->file > compare_monitor->file)
+ {
+ return +1;
+ }
+
+ return 0;
}
static GList *
find_monitor (NautilusDirectory *directory,
- NautilusFile *file,
- gconstpointer client)
+ NautilusFile *file,
+ gconstpointer client)
{
- Monitor monitor;
+ Monitor monitor;
- monitor.client = client;
- monitor.file = file;
+ monitor.client = client;
+ monitor.file = file;
- return g_list_find_custom (directory->details->monitor_list,
- &monitor,
- monitor_key_compare);
+ return g_list_find_custom (directory->details->monitor_list,
+ &monitor,
+ monitor_key_compare);
}
static void
remove_monitor_link (NautilusDirectory *directory,
- GList *link)
+ GList *link)
{
- Monitor *monitor;
+ Monitor *monitor;
- if (link != NULL) {
- monitor = link->data;
- request_counter_remove_request (directory->details->monitor_counters,
- monitor->request);
- directory->details->monitor_list =
- g_list_remove_link (directory->details->monitor_list, link);
- g_free (monitor);
- g_list_free_1 (link);
- }
+ if (link != NULL)
+ {
+ monitor = link->data;
+ request_counter_remove_request (directory->details->monitor_counters,
+ monitor->request);
+ directory->details->monitor_list =
+ g_list_remove_link (directory->details->monitor_list, link);
+ g_free (monitor);
+ g_list_free_1 (link);
+ }
}
static void
remove_monitor (NautilusDirectory *directory,
- NautilusFile *file,
- gconstpointer client)
+ NautilusFile *file,
+ gconstpointer client)
{
- remove_monitor_link (directory, find_monitor (directory, file, client));
+ remove_monitor_link (directory, find_monitor (directory, file, client));
}
Request
nautilus_directory_set_up_request (NautilusFileAttributes file_attributes)
{
- Request request;
-
- request = 0;
-
- if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT) != 0) {
- REQUEST_SET_TYPE (request, REQUEST_DIRECTORY_COUNT);
- }
-
- if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS) != 0) {
- REQUEST_SET_TYPE (request, REQUEST_DEEP_COUNT);
- }
-
- if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES) != 0) {
- REQUEST_SET_TYPE (request, REQUEST_MIME_LIST);
- }
- if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_INFO) != 0) {
- REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
- }
-
- if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_LINK_INFO) {
- REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
- REQUEST_SET_TYPE (request, REQUEST_LINK_INFO);
- }
-
- if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO) != 0) {
- REQUEST_SET_TYPE (request, REQUEST_EXTENSION_INFO);
- }
-
- if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL) {
- REQUEST_SET_TYPE (request, REQUEST_THUMBNAIL);
- REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
- }
-
- if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_MOUNT) {
- REQUEST_SET_TYPE (request, REQUEST_MOUNT);
- REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
- }
-
- if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO) {
- REQUEST_SET_TYPE (request, REQUEST_FILESYSTEM_INFO);
- }
-
- return request;
+ Request request;
+
+ request = 0;
+
+ if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT) != 0)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_DIRECTORY_COUNT);
+ }
+
+ if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS) != 0)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_DEEP_COUNT);
+ }
+
+ if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES) != 0)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_MIME_LIST);
+ }
+ if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_INFO) != 0)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
+ }
+
+ if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_LINK_INFO)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
+ REQUEST_SET_TYPE (request, REQUEST_LINK_INFO);
+ }
+
+ if ((file_attributes & NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO) != 0)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_EXTENSION_INFO);
+ }
+
+ if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_THUMBNAIL);
+ REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
+ }
+
+ if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_MOUNT)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_MOUNT);
+ REQUEST_SET_TYPE (request, REQUEST_FILE_INFO);
+ }
+
+ if (file_attributes & NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO)
+ {
+ REQUEST_SET_TYPE (request, REQUEST_FILESYSTEM_INFO);
+ }
+
+ return request;
}
static void
-mime_db_changed_callback (GObject *ignore, NautilusDirectory *dir)
+mime_db_changed_callback (GObject *ignore,
+ NautilusDirectory *dir)
{
- NautilusFileAttributes attrs;
+ NautilusFileAttributes attrs;
- g_assert (dir != NULL);
- g_assert (dir->details != NULL);
+ g_assert (dir != NULL);
+ g_assert (dir->details != NULL);
- attrs = NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES;
+ attrs = NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES;
- nautilus_directory_force_reload_internal (dir, attrs);
+ nautilus_directory_force_reload_internal (dir, attrs);
}
void
-nautilus_directory_monitor_add_internal (NautilusDirectory *directory,
- NautilusFile *file,
- gconstpointer client,
- gboolean monitor_hidden_files,
- NautilusFileAttributes file_attributes,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
-{
- Monitor *monitor;
- GList *file_list;
- char *file_uri = NULL;
- char *dir_uri = NULL;
-
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
-
- if (file != NULL)
- file_uri = nautilus_file_get_uri (file);
- if (directory != NULL)
- dir_uri = nautilus_directory_get_uri (directory);
- nautilus_profile_start ("uri %s file-uri %s client %p", dir_uri, file_uri, client);
- g_free (dir_uri);
- g_free (file_uri);
-
- /* Replace any current monitor for this client/file pair. */
- remove_monitor (directory, file, client);
-
- /* Add the new monitor. */
- monitor = g_new (Monitor, 1);
- monitor->file = file;
- monitor->monitor_hidden_files = monitor_hidden_files;
- monitor->client = client;
- monitor->request = nautilus_directory_set_up_request (file_attributes);
-
- if (file == NULL) {
- REQUEST_SET_TYPE (monitor->request, REQUEST_FILE_LIST);
- }
- directory->details->monitor_list =
- g_list_prepend (directory->details->monitor_list, monitor);
- request_counter_add_request (directory->details->monitor_counters,
- monitor->request);
-
- if (callback != NULL) {
- file_list = nautilus_directory_get_file_list (directory);
- (* callback) (directory, file_list, callback_data);
- nautilus_file_list_free (file_list);
- }
-
- /* Start the "real" monitoring (FAM or whatever). */
- /* We always monitor the whole directory since in practice
- * nautilus almost always shows the whole directory anyway, and
- * it allows us to avoid one file monitor per file in a directory.
- */
- if (directory->details->monitor == NULL) {
- directory->details->monitor = nautilus_monitor_directory (directory->details->location);
- }
-
-
- if (REQUEST_WANTS_TYPE (monitor->request, REQUEST_FILE_INFO) &&
- directory->details->mime_db_monitor == 0) {
- directory->details->mime_db_monitor =
- g_signal_connect_object (nautilus_signaller_get_current (),
- "mime-data-changed",
- G_CALLBACK (mime_db_changed_callback), directory, 0);
- }
-
- /* Put the monitor file or all the files on the work queue. */
- if (file != NULL) {
- nautilus_directory_add_file_to_work_queue (directory, file);
- } else {
- add_all_files_to_work_queue (directory);
- }
-
- /* Kick off I/O. */
- nautilus_directory_async_state_changed (directory);
- nautilus_profile_end (NULL);
+nautilus_directory_monitor_add_internal (NautilusDirectory *directory,
+ NautilusFile *file,
+ gconstpointer client,
+ gboolean monitor_hidden_files,
+ NautilusFileAttributes file_attributes,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
+{
+ Monitor *monitor;
+ GList *file_list;
+ char *file_uri = NULL;
+ char *dir_uri = NULL;
+
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+
+ if (file != NULL)
+ {
+ file_uri = nautilus_file_get_uri (file);
+ }
+ if (directory != NULL)
+ {
+ dir_uri = nautilus_directory_get_uri (directory);
+ }
+ nautilus_profile_start ("uri %s file-uri %s client %p", dir_uri, file_uri, client);
+ g_free (dir_uri);
+ g_free (file_uri);
+
+ /* Replace any current monitor for this client/file pair. */
+ remove_monitor (directory, file, client);
+
+ /* Add the new monitor. */
+ monitor = g_new (Monitor, 1);
+ monitor->file = file;
+ monitor->monitor_hidden_files = monitor_hidden_files;
+ monitor->client = client;
+ monitor->request = nautilus_directory_set_up_request (file_attributes);
+
+ if (file == NULL)
+ {
+ REQUEST_SET_TYPE (monitor->request, REQUEST_FILE_LIST);
+ }
+ directory->details->monitor_list =
+ g_list_prepend (directory->details->monitor_list, monitor);
+ request_counter_add_request (directory->details->monitor_counters,
+ monitor->request);
+
+ if (callback != NULL)
+ {
+ file_list = nautilus_directory_get_file_list (directory);
+ (*callback)(directory, file_list, callback_data);
+ nautilus_file_list_free (file_list);
+ }
+
+ /* Start the "real" monitoring (FAM or whatever). */
+ /* We always monitor the whole directory since in practice
+ * nautilus almost always shows the whole directory anyway, and
+ * it allows us to avoid one file monitor per file in a directory.
+ */
+ if (directory->details->monitor == NULL)
+ {
+ directory->details->monitor = nautilus_monitor_directory (directory->details->location);
+ }
+
+
+ if (REQUEST_WANTS_TYPE (monitor->request, REQUEST_FILE_INFO) &&
+ directory->details->mime_db_monitor == 0)
+ {
+ directory->details->mime_db_monitor =
+ g_signal_connect_object (nautilus_signaller_get_current (),
+ "mime-data-changed",
+ G_CALLBACK (mime_db_changed_callback), directory, 0);
+ }
+
+ /* Put the monitor file or all the files on the work queue. */
+ if (file != NULL)
+ {
+ nautilus_directory_add_file_to_work_queue (directory, file);
+ }
+ else
+ {
+ add_all_files_to_work_queue (directory);
+ }
+
+ /* Kick off I/O. */
+ nautilus_directory_async_state_changed (directory);
+ nautilus_profile_end (NULL);
}
static void
-set_file_unconfirmed (NautilusFile *file, gboolean unconfirmed)
+set_file_unconfirmed (NautilusFile *file,
+ gboolean unconfirmed)
{
- NautilusDirectory *directory;
+ NautilusDirectory *directory;
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (unconfirmed == FALSE || unconfirmed == TRUE);
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (unconfirmed == FALSE || unconfirmed == TRUE);
- if (file->details->unconfirmed == unconfirmed) {
- return;
- }
- file->details->unconfirmed = unconfirmed;
+ if (file->details->unconfirmed == unconfirmed)
+ {
+ return;
+ }
+ file->details->unconfirmed = unconfirmed;
- directory = file->details->directory;
- if (unconfirmed) {
- directory->details->confirmed_file_count--;
- } else {
- directory->details->confirmed_file_count++;
- }
+ directory = file->details->directory;
+ if (unconfirmed)
+ {
+ directory->details->confirmed_file_count--;
+ }
+ else
+ {
+ directory->details->confirmed_file_count++;
+ }
}
static gboolean show_hidden_files = TRUE;
@@ -804,1017 +889,1142 @@ static gboolean show_hidden_files = TRUE;
static void
show_hidden_files_changed_callback (gpointer callback_data)
{
- show_hidden_files = g_settings_get_boolean (gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
+ show_hidden_files = g_settings_get_boolean (gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
}
static gboolean
-should_skip_file (NautilusDirectory *directory, GFileInfo *info)
+should_skip_file (NautilusDirectory *directory,
+ GFileInfo *info)
{
- static gboolean show_hidden_files_changed_callback_installed = FALSE;
+ static gboolean show_hidden_files_changed_callback_installed = FALSE;
- /* Add the callback once for the life of our process */
- if (!show_hidden_files_changed_callback_installed) {
- g_signal_connect_swapped (gtk_filechooser_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
- G_CALLBACK(show_hidden_files_changed_callback),
- NULL);
+ /* Add the callback once for the life of our process */
+ if (!show_hidden_files_changed_callback_installed)
+ {
+ g_signal_connect_swapped (gtk_filechooser_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
+ G_CALLBACK (show_hidden_files_changed_callback),
+ NULL);
- show_hidden_files_changed_callback_installed = TRUE;
+ show_hidden_files_changed_callback_installed = TRUE;
- /* Peek for the first time */
- show_hidden_files_changed_callback (NULL);
- }
+ /* Peek for the first time */
+ show_hidden_files_changed_callback (NULL);
+ }
- if (!show_hidden_files &&
- (g_file_info_get_is_hidden (info) ||
- g_file_info_get_is_backup (info))) {
- return TRUE;
- }
+ if (!show_hidden_files &&
+ (g_file_info_get_is_hidden (info) ||
+ g_file_info_get_is_backup (info)))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
dequeue_pending_idle_callback (gpointer callback_data)
{
- NautilusDirectory *directory;
- GList *pending_file_info;
- GList *node, *next;
- NautilusFile *file;
- GList *changed_files, *added_files;
- GFileInfo *file_info;
- const char *mimetype, *name;
- DirectoryLoadState *dir_load_state;
-
- directory = NAUTILUS_DIRECTORY (callback_data);
-
- nautilus_directory_ref (directory);
-
- nautilus_profile_start ("nitems %d", g_list_length (directory->details->pending_file_info));
-
- directory->details->dequeue_pending_idle_id = 0;
-
- /* Handle the files in the order we saw them. */
- pending_file_info = g_list_reverse (directory->details->pending_file_info);
- directory->details->pending_file_info = NULL;
-
- /* If we are no longer monitoring, then throw away these. */
- if (!nautilus_directory_is_file_list_monitored (directory)) {
- nautilus_directory_async_state_changed (directory);
- goto drain;
- }
-
- added_files = NULL;
- changed_files = NULL;
-
- dir_load_state = directory->details->directory_load_in_progress;
-
- /* Build a list of NautilusFile objects. */
- for (node = pending_file_info; node != NULL; node = node->next) {
- file_info = node->data;
-
- name = g_file_info_get_name (file_info);
-
- /* Update the file count. */
- /* FIXME bugzilla.gnome.org 45063: This could count a
- * file twice if we get it from both load_directory
- * and from new_files_callback. Not too hard to fix by
- * moving this into the actual callback instead of
- * waiting for the idle function.
- */
- if (dir_load_state &&
- !should_skip_file (directory, file_info)) {
- dir_load_state->load_file_count += 1;
-
- /* Add the MIME type to the set. */
- mimetype = g_file_info_get_content_type (file_info);
- if (mimetype != NULL) {
- istr_set_insert (dir_load_state->load_mime_list_hash,
- mimetype);
- }
- }
-
- /* check if the file already exists */
- file = nautilus_directory_find_file_by_name (directory, name);
- if (file != NULL) {
- /* file already exists in dir, check if we still need to
- * emit file_added or if it changed */
- set_file_unconfirmed (file, FALSE);
- if (!file->details->is_added) {
- /* We consider this newly added even if its in the list.
- * This can happen if someone called nautilus_file_get_by_uri()
- * on a file in the folder before the add signal was
- * emitted */
- nautilus_file_ref (file);
- file->details->is_added = TRUE;
- added_files = g_list_prepend (added_files, file);
- } else if (nautilus_file_update_info (file, file_info)) {
- /* File changed, notify about the change. */
- nautilus_file_ref (file);
- changed_files = g_list_prepend (changed_files, file);
- }
- } else {
- /* new file, create a nautilus file object and add it to the list */
- file = nautilus_file_new_from_info (directory, file_info);
- nautilus_directory_add_file (directory, file);
- file->details->is_added = TRUE;
- added_files = g_list_prepend (added_files, file);
- }
- }
-
- /* If we are done loading, then we assume that any unconfirmed
- * files are gone.
- */
- if (directory->details->directory_loaded) {
- for (node = directory->details->file_list;
- node != NULL; node = next) {
- file = NAUTILUS_FILE (node->data);
- next = node->next;
-
- if (file->details->unconfirmed) {
- nautilus_file_ref (file);
- changed_files = g_list_prepend (changed_files, file);
-
- nautilus_file_mark_gone (file);
- }
- }
- }
-
- /* Send the changed and added signals. */
- nautilus_directory_emit_change_signals (directory, changed_files);
- nautilus_file_list_free (changed_files);
- nautilus_directory_emit_files_added (directory, added_files);
- nautilus_file_list_free (added_files);
-
- if (directory->details->directory_loaded &&
- !directory->details->directory_loaded_sent_notification) {
- /* Send the done_loading signal. */
- nautilus_directory_emit_done_loading (directory);
-
- if (dir_load_state) {
- file = dir_load_state->load_directory_file;
-
- file->details->directory_count = dir_load_state->load_file_count;
- file->details->directory_count_is_up_to_date = TRUE;
- file->details->got_directory_count = TRUE;
-
- file->details->got_mime_list = TRUE;
- file->details->mime_list_is_up_to_date = TRUE;
- g_list_free_full (file->details->mime_list, g_free);
- file->details->mime_list = istr_set_get_as_list
- (dir_load_state->load_mime_list_hash);
-
- nautilus_file_changed (file);
- }
-
- nautilus_directory_async_state_changed (directory);
-
- directory->details->directory_loaded_sent_notification = TRUE;
- }
-
- drain:
- g_list_free_full (pending_file_info, g_object_unref);
-
- /* Get the state machine running again. */
- nautilus_directory_async_state_changed (directory);
-
- nautilus_profile_end (NULL);
-
- nautilus_directory_unref (directory);
- return FALSE;
+ NautilusDirectory *directory;
+ GList *pending_file_info;
+ GList *node, *next;
+ NautilusFile *file;
+ GList *changed_files, *added_files;
+ GFileInfo *file_info;
+ const char *mimetype, *name;
+ DirectoryLoadState *dir_load_state;
+
+ directory = NAUTILUS_DIRECTORY (callback_data);
+
+ nautilus_directory_ref (directory);
+
+ nautilus_profile_start ("nitems %d", g_list_length (directory->details->pending_file_info));
+
+ directory->details->dequeue_pending_idle_id = 0;
+
+ /* Handle the files in the order we saw them. */
+ pending_file_info = g_list_reverse (directory->details->pending_file_info);
+ directory->details->pending_file_info = NULL;
+
+ /* If we are no longer monitoring, then throw away these. */
+ if (!nautilus_directory_is_file_list_monitored (directory))
+ {
+ nautilus_directory_async_state_changed (directory);
+ goto drain;
+ }
+
+ added_files = NULL;
+ changed_files = NULL;
+
+ dir_load_state = directory->details->directory_load_in_progress;
+
+ /* Build a list of NautilusFile objects. */
+ for (node = pending_file_info; node != NULL; node = node->next)
+ {
+ file_info = node->data;
+
+ name = g_file_info_get_name (file_info);
+
+ /* Update the file count. */
+ /* FIXME bugzilla.gnome.org 45063: This could count a
+ * file twice if we get it from both load_directory
+ * and from new_files_callback. Not too hard to fix by
+ * moving this into the actual callback instead of
+ * waiting for the idle function.
+ */
+ if (dir_load_state &&
+ !should_skip_file (directory, file_info))
+ {
+ dir_load_state->load_file_count += 1;
+
+ /* Add the MIME type to the set. */
+ mimetype = g_file_info_get_content_type (file_info);
+ if (mimetype != NULL)
+ {
+ istr_set_insert (dir_load_state->load_mime_list_hash,
+ mimetype);
+ }
+ }
+
+ /* check if the file already exists */
+ file = nautilus_directory_find_file_by_name (directory, name);
+ if (file != NULL)
+ {
+ /* file already exists in dir, check if we still need to
+ * emit file_added or if it changed */
+ set_file_unconfirmed (file, FALSE);
+ if (!file->details->is_added)
+ {
+ /* We consider this newly added even if its in the list.
+ * This can happen if someone called nautilus_file_get_by_uri()
+ * on a file in the folder before the add signal was
+ * emitted */
+ nautilus_file_ref (file);
+ file->details->is_added = TRUE;
+ added_files = g_list_prepend (added_files, file);
+ }
+ else if (nautilus_file_update_info (file, file_info))
+ {
+ /* File changed, notify about the change. */
+ nautilus_file_ref (file);
+ changed_files = g_list_prepend (changed_files, file);
+ }
+ }
+ else
+ {
+ /* new file, create a nautilus file object and add it to the list */
+ file = nautilus_file_new_from_info (directory, file_info);
+ nautilus_directory_add_file (directory, file);
+ file->details->is_added = TRUE;
+ added_files = g_list_prepend (added_files, file);
+ }
+ }
+
+ /* If we are done loading, then we assume that any unconfirmed
+ * files are gone.
+ */
+ if (directory->details->directory_loaded)
+ {
+ for (node = directory->details->file_list;
+ node != NULL; node = next)
+ {
+ file = NAUTILUS_FILE (node->data);
+ next = node->next;
+
+ if (file->details->unconfirmed)
+ {
+ nautilus_file_ref (file);
+ changed_files = g_list_prepend (changed_files, file);
+
+ nautilus_file_mark_gone (file);
+ }
+ }
+ }
+
+ /* Send the changed and added signals. */
+ nautilus_directory_emit_change_signals (directory, changed_files);
+ nautilus_file_list_free (changed_files);
+ nautilus_directory_emit_files_added (directory, added_files);
+ nautilus_file_list_free (added_files);
+
+ if (directory->details->directory_loaded &&
+ !directory->details->directory_loaded_sent_notification)
+ {
+ /* Send the done_loading signal. */
+ nautilus_directory_emit_done_loading (directory);
+
+ if (dir_load_state)
+ {
+ file = dir_load_state->load_directory_file;
+
+ file->details->directory_count = dir_load_state->load_file_count;
+ file->details->directory_count_is_up_to_date = TRUE;
+ file->details->got_directory_count = TRUE;
+
+ file->details->got_mime_list = TRUE;
+ file->details->mime_list_is_up_to_date = TRUE;
+ g_list_free_full (file->details->mime_list, g_free);
+ file->details->mime_list = istr_set_get_as_list
+ (dir_load_state->load_mime_list_hash);
+
+ nautilus_file_changed (file);
+ }
+
+ nautilus_directory_async_state_changed (directory);
+
+ directory->details->directory_loaded_sent_notification = TRUE;
+ }
+
+drain:
+ g_list_free_full (pending_file_info, g_object_unref);
+
+ /* Get the state machine running again. */
+ nautilus_directory_async_state_changed (directory);
+
+ nautilus_profile_end (NULL);
+
+ nautilus_directory_unref (directory);
+ return FALSE;
}
void
nautilus_directory_schedule_dequeue_pending (NautilusDirectory *directory)
{
- if (directory->details->dequeue_pending_idle_id == 0) {
- directory->details->dequeue_pending_idle_id
- = g_idle_add (dequeue_pending_idle_callback, directory);
- }
+ if (directory->details->dequeue_pending_idle_id == 0)
+ {
+ directory->details->dequeue_pending_idle_id
+ = g_idle_add (dequeue_pending_idle_callback, directory);
+ }
}
static void
directory_load_one (NautilusDirectory *directory,
- GFileInfo *info)
+ GFileInfo *info)
{
- if (info == NULL) {
- return;
- }
+ if (info == NULL)
+ {
+ return;
+ }
- if (g_file_info_get_name (info) == NULL) {
- char *uri;
+ if (g_file_info_get_name (info) == NULL)
+ {
+ char *uri;
- uri = nautilus_directory_get_uri (directory);
- g_warning ("Got GFileInfo with NULL name in %s, ignoring. This shouldn't happen unless the gvfs backend is broken.\n", uri);
- g_free (uri);
-
- return;
- }
-
- /* Arrange for the "loading" part of the work. */
- g_object_ref (info);
- directory->details->pending_file_info
- = g_list_prepend (directory->details->pending_file_info, info);
- nautilus_directory_schedule_dequeue_pending (directory);
+ uri = nautilus_directory_get_uri (directory);
+ g_warning ("Got GFileInfo with NULL name in %s, ignoring. This shouldn't happen unless the gvfs backend is broken.\n", uri);
+ g_free (uri);
+
+ return;
+ }
+
+ /* Arrange for the "loading" part of the work. */
+ g_object_ref (info);
+ directory->details->pending_file_info
+ = g_list_prepend (directory->details->pending_file_info, info);
+ nautilus_directory_schedule_dequeue_pending (directory);
}
static void
directory_load_cancel (NautilusDirectory *directory)
{
- NautilusFile *file;
- DirectoryLoadState *state;
+ NautilusFile *file;
+ DirectoryLoadState *state;
+
+ state = directory->details->directory_load_in_progress;
+ if (state != NULL)
+ {
+ file = state->load_directory_file;
+ file->details->loading_directory = FALSE;
+ if (file->details->directory != directory)
+ {
+ nautilus_directory_async_state_changed (file->details->directory);
+ }
- state = directory->details->directory_load_in_progress;
- if (state != NULL) {
- file = state->load_directory_file;
- file->details->loading_directory = FALSE;
- if (file->details->directory != directory) {
- nautilus_directory_async_state_changed (file->details->directory);
- }
-
- g_cancellable_cancel (state->cancellable);
- state->directory = NULL;
- directory->details->directory_load_in_progress = NULL;
- async_job_end (directory, "file list");
- }
+ g_cancellable_cancel (state->cancellable);
+ state->directory = NULL;
+ directory->details->directory_load_in_progress = NULL;
+ async_job_end (directory, "file list");
+ }
}
static void
file_list_cancel (NautilusDirectory *directory)
{
- directory_load_cancel (directory);
-
- if (directory->details->dequeue_pending_idle_id != 0) {
- g_source_remove (directory->details->dequeue_pending_idle_id);
- directory->details->dequeue_pending_idle_id = 0;
- }
+ directory_load_cancel (directory);
- if (directory->details->pending_file_info != NULL) {
- g_list_free_full (directory->details->pending_file_info, g_object_unref);
- directory->details->pending_file_info = NULL;
- }
+ if (directory->details->dequeue_pending_idle_id != 0)
+ {
+ g_source_remove (directory->details->dequeue_pending_idle_id);
+ directory->details->dequeue_pending_idle_id = 0;
+ }
+
+ if (directory->details->pending_file_info != NULL)
+ {
+ g_list_free_full (directory->details->pending_file_info, g_object_unref);
+ directory->details->pending_file_info = NULL;
+ }
}
static void
directory_load_done (NautilusDirectory *directory,
- GError *error)
+ GError *error)
{
- GList *node;
+ GList *node;
- nautilus_profile_start (NULL);
- g_object_ref (directory);
+ nautilus_profile_start (NULL);
+ g_object_ref (directory);
- directory->details->directory_loaded = TRUE;
- directory->details->directory_loaded_sent_notification = FALSE;
+ directory->details->directory_loaded = TRUE;
+ directory->details->directory_loaded_sent_notification = FALSE;
- if (error != NULL) {
- /* The load did not complete successfully. This means
- * we don't know the status of the files in this directory.
- * We clear the unconfirmed bit on each file here so that
- * they won't be marked "gone" later -- we don't know enough
- * about them to know whether they are really gone.
- */
- for (node = directory->details->file_list;
- node != NULL; node = node->next) {
- set_file_unconfirmed (NAUTILUS_FILE (node->data), FALSE);
- }
+ if (error != NULL)
+ {
+ /* The load did not complete successfully. This means
+ * we don't know the status of the files in this directory.
+ * We clear the unconfirmed bit on each file here so that
+ * they won't be marked "gone" later -- we don't know enough
+ * about them to know whether they are really gone.
+ */
+ for (node = directory->details->file_list;
+ node != NULL; node = node->next)
+ {
+ set_file_unconfirmed (NAUTILUS_FILE (node->data), FALSE);
+ }
- nautilus_directory_emit_load_error (directory, error);
- }
+ nautilus_directory_emit_load_error (directory, error);
+ }
- /* Call the idle function right away. */
- if (directory->details->dequeue_pending_idle_id != 0) {
- g_source_remove (directory->details->dequeue_pending_idle_id);
- }
- dequeue_pending_idle_callback (directory);
+ /* Call the idle function right away. */
+ if (directory->details->dequeue_pending_idle_id != 0)
+ {
+ g_source_remove (directory->details->dequeue_pending_idle_id);
+ }
+ dequeue_pending_idle_callback (directory);
- directory_load_cancel (directory);
+ directory_load_cancel (directory);
- g_object_unref (directory);
- nautilus_profile_end (NULL);
+ g_object_unref (directory);
+ nautilus_profile_end (NULL);
}
void
nautilus_directory_monitor_remove_internal (NautilusDirectory *directory,
- NautilusFile *file,
- gconstpointer client)
+ NautilusFile *file,
+ gconstpointer client)
{
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (file == NULL || NAUTILUS_IS_FILE (file));
- g_assert (client != NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (file == NULL || NAUTILUS_IS_FILE (file));
+ g_assert (client != NULL);
- remove_monitor (directory, file, client);
+ remove_monitor (directory, file, client);
- if (directory->details->monitor != NULL
- && directory->details->monitor_list == NULL) {
- nautilus_monitor_cancel (directory->details->monitor);
- directory->details->monitor = NULL;
- }
+ if (directory->details->monitor != NULL
+ && directory->details->monitor_list == NULL)
+ {
+ nautilus_monitor_cancel (directory->details->monitor);
+ directory->details->monitor = NULL;
+ }
- /* XXX - do we need to remove anything from the work queue? */
+ /* XXX - do we need to remove anything from the work queue? */
- nautilus_directory_async_state_changed (directory);
+ nautilus_directory_async_state_changed (directory);
}
FileMonitors *
nautilus_directory_remove_file_monitors (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- GList *result, **list, *node, *next;
- Monitor *monitor;
+ GList *result, **list, *node, *next;
+ Monitor *monitor;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
- result = NULL;
+ result = NULL;
- list = &directory->details->monitor_list;
- for (node = directory->details->monitor_list; node != NULL; node = next) {
- next = node->next;
- monitor = node->data;
+ list = &directory->details->monitor_list;
+ for (node = directory->details->monitor_list; node != NULL; node = next)
+ {
+ next = node->next;
+ monitor = node->data;
- if (monitor->file == file) {
- *list = g_list_remove_link (*list, node);
- result = g_list_concat (node, result);
- request_counter_remove_request (directory->details->monitor_counters,
- monitor->request);
- }
- }
+ if (monitor->file == file)
+ {
+ *list = g_list_remove_link (*list, node);
+ result = g_list_concat (node, result);
+ request_counter_remove_request (directory->details->monitor_counters,
+ monitor->request);
+ }
+ }
- /* XXX - do we need to remove anything from the work queue? */
+ /* XXX - do we need to remove anything from the work queue? */
- nautilus_directory_async_state_changed (directory);
+ nautilus_directory_async_state_changed (directory);
- return (FileMonitors *) result;
+ return (FileMonitors *) result;
}
void
nautilus_directory_add_file_monitors (NautilusDirectory *directory,
- NautilusFile *file,
- FileMonitors *monitors)
+ NautilusFile *file,
+ FileMonitors *monitors)
{
- GList **list;
- GList *l;
- Monitor *monitor;
+ GList **list;
+ GList *l;
+ Monitor *monitor;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
- if (monitors == NULL) {
- return;
- }
+ if (monitors == NULL)
+ {
+ return;
+ }
- for (l = (GList *)monitors; l != NULL; l = l->next) {
- monitor = l->data;
- request_counter_add_request (directory->details->monitor_counters,
- monitor->request);
- }
+ for (l = (GList *) monitors; l != NULL; l = l->next)
+ {
+ monitor = l->data;
+ request_counter_add_request (directory->details->monitor_counters,
+ monitor->request);
+ }
- list = &directory->details->monitor_list;
- *list = g_list_concat (*list, (GList *) monitors);
+ list = &directory->details->monitor_list;
+ *list = g_list_concat (*list, (GList *) monitors);
- nautilus_directory_add_file_to_work_queue (directory, file);
+ nautilus_directory_add_file_to_work_queue (directory, file);
- nautilus_directory_async_state_changed (directory);
+ nautilus_directory_async_state_changed (directory);
}
static int
-ready_callback_key_compare (gconstpointer a, gconstpointer b)
-{
- const ReadyCallback *callback_a, *callback_b;
-
- callback_a = a;
- callback_b = b;
-
- if (callback_a->file < callback_b->file) {
- return -1;
- }
- if (callback_a->file > callback_b->file) {
- return 1;
- }
- if (callback_a->file == NULL) {
- /* ANSI C doesn't allow ordered compares of function pointers, so we cast them to
- * normal pointers to make some overly pedantic compilers (*cough* HP-UX *cough*)
- * compile this. Of course, on any compiler where ordered function pointers actually
- * break this probably won't work, but at least it will compile on platforms where it
- * works, but stupid compilers won't let you use it.
- */
- if ((void *)callback_a->callback.directory < (void *)callback_b->callback.directory) {
- return -1;
- }
- if ((void *)callback_a->callback.directory > (void *)callback_b->callback.directory) {
- return 1;
- }
- } else {
- if ((void *)callback_a->callback.file < (void *)callback_b->callback.file) {
- return -1;
- }
- if ((void *)callback_a->callback.file > (void *)callback_b->callback.file) {
- return 1;
- }
- }
- if (callback_a->callback_data < callback_b->callback_data) {
- return -1;
- }
- if (callback_a->callback_data > callback_b->callback_data) {
- return 1;
- }
- return 0;
+ready_callback_key_compare (gconstpointer a,
+ gconstpointer b)
+{
+ const ReadyCallback *callback_a, *callback_b;
+
+ callback_a = a;
+ callback_b = b;
+
+ if (callback_a->file < callback_b->file)
+ {
+ return -1;
+ }
+ if (callback_a->file > callback_b->file)
+ {
+ return 1;
+ }
+ if (callback_a->file == NULL)
+ {
+ /* ANSI C doesn't allow ordered compares of function pointers, so we cast them to
+ * normal pointers to make some overly pedantic compilers (*cough* HP-UX *cough*)
+ * compile this. Of course, on any compiler where ordered function pointers actually
+ * break this probably won't work, but at least it will compile on platforms where it
+ * works, but stupid compilers won't let you use it.
+ */
+ if ((void *) callback_a->callback.directory < (void *) callback_b->callback.directory)
+ {
+ return -1;
+ }
+ if ((void *) callback_a->callback.directory > (void *) callback_b->callback.directory)
+ {
+ return 1;
+ }
+ }
+ else
+ {
+ if ((void *) callback_a->callback.file < (void *) callback_b->callback.file)
+ {
+ return -1;
+ }
+ if ((void *) callback_a->callback.file > (void *) callback_b->callback.file)
+ {
+ return 1;
+ }
+ }
+ if (callback_a->callback_data < callback_b->callback_data)
+ {
+ return -1;
+ }
+ if (callback_a->callback_data > callback_b->callback_data)
+ {
+ return 1;
+ }
+ return 0;
}
static int
-ready_callback_key_compare_only_active (gconstpointer a, gconstpointer b)
+ready_callback_key_compare_only_active (gconstpointer a,
+ gconstpointer b)
{
- const ReadyCallback *callback_a;
+ const ReadyCallback *callback_a;
- callback_a = a;
+ callback_a = a;
- /* Non active callbacks never match */
- if (!callback_a->active) {
- return -1;
- }
+ /* Non active callbacks never match */
+ if (!callback_a->active)
+ {
+ return -1;
+ }
- return ready_callback_key_compare (a, b);
+ return ready_callback_key_compare (a, b);
}
static void
-ready_callback_call (NautilusDirectory *directory,
- const ReadyCallback *callback)
-{
- GList *file_list;
-
- /* Call the callback. */
- if (callback->file != NULL) {
- if (callback->callback.file) {
- (* callback->callback.file) (callback->file,
- callback->callback_data);
- }
- } else if (callback->callback.directory != NULL) {
- if (directory == NULL ||
- !REQUEST_WANTS_TYPE (callback->request, REQUEST_FILE_LIST)) {
- file_list = NULL;
- } else {
- file_list = nautilus_directory_get_file_list (directory);
- }
-
- /* Pass back the file list if the user was waiting for it. */
- (* callback->callback.directory) (directory,
- file_list,
- callback->callback_data);
-
- nautilus_file_list_free (file_list);
- }
+ready_callback_call (NautilusDirectory *directory,
+ const ReadyCallback *callback)
+{
+ GList *file_list;
+
+ /* Call the callback. */
+ if (callback->file != NULL)
+ {
+ if (callback->callback.file)
+ {
+ (*callback->callback.file)(callback->file,
+ callback->callback_data);
+ }
+ }
+ else if (callback->callback.directory != NULL)
+ {
+ if (directory == NULL ||
+ !REQUEST_WANTS_TYPE (callback->request, REQUEST_FILE_LIST))
+ {
+ file_list = NULL;
+ }
+ else
+ {
+ file_list = nautilus_directory_get_file_list (directory);
+ }
+
+ /* Pass back the file list if the user was waiting for it. */
+ (*callback->callback.directory)(directory,
+ file_list,
+ callback->callback_data);
+
+ nautilus_file_list_free (file_list);
+ }
}
void
-nautilus_directory_call_when_ready_internal (NautilusDirectory *directory,
- NautilusFile *file,
- NautilusFileAttributes file_attributes,
- gboolean wait_for_file_list,
- NautilusDirectoryCallback directory_callback,
- NautilusFileCallback file_callback,
- gpointer callback_data)
-{
- ReadyCallback callback;
-
- g_assert (directory == NULL || NAUTILUS_IS_DIRECTORY (directory));
- g_assert (file == NULL || NAUTILUS_IS_FILE (file));
- g_assert (file != NULL || directory_callback != NULL);
-
- /* Construct a callback object. */
- callback.active = TRUE;
- callback.file = file;
- if (file == NULL) {
- callback.callback.directory = directory_callback;
- } else {
- callback.callback.file = file_callback;
- }
- callback.callback_data = callback_data;
- callback.request = nautilus_directory_set_up_request (file_attributes);
- if (wait_for_file_list) {
- REQUEST_SET_TYPE (callback.request, REQUEST_FILE_LIST);
- }
-
- /* Handle the NULL case. */
- if (directory == NULL) {
- ready_callback_call (NULL, &callback);
- return;
- }
-
- /* Check if the callback is already there. */
- if (g_list_find_custom (directory->details->call_when_ready_list,
- &callback,
- ready_callback_key_compare_only_active) != NULL) {
- if (file_callback != NULL && directory_callback != NULL) {
- g_warning ("tried to add a new callback while an old one was pending");
- }
- /* NULL callback means, just read it. Conflicts are ok. */
- return;
- }
-
- /* Add the new callback to the list. */
- directory->details->call_when_ready_list = g_list_prepend
- (directory->details->call_when_ready_list,
- g_memdup (&callback, sizeof (callback)));
- request_counter_add_request (directory->details->call_when_ready_counters,
- callback.request);
-
- /* Put the callback file or all the files on the work queue. */
- if (file != NULL) {
- nautilus_directory_add_file_to_work_queue (directory, file);
- } else {
- add_all_files_to_work_queue (directory);
- }
-
- nautilus_directory_async_state_changed (directory);
-}
-
-gboolean
-nautilus_directory_check_if_ready_internal (NautilusDirectory *directory,
- NautilusFile *file,
- NautilusFileAttributes file_attributes)
-{
- Request request;
-
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
-
- request = nautilus_directory_set_up_request (file_attributes);
- return request_is_satisfied (directory, file, request);
+nautilus_directory_call_when_ready_internal (NautilusDirectory *directory,
+ NautilusFile *file,
+ NautilusFileAttributes file_attributes,
+ gboolean wait_for_file_list,
+ NautilusDirectoryCallback directory_callback,
+ NautilusFileCallback file_callback,
+ gpointer callback_data)
+{
+ ReadyCallback callback;
+
+ g_assert (directory == NULL || NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (file == NULL || NAUTILUS_IS_FILE (file));
+ g_assert (file != NULL || directory_callback != NULL);
+
+ /* Construct a callback object. */
+ callback.active = TRUE;
+ callback.file = file;
+ if (file == NULL)
+ {
+ callback.callback.directory = directory_callback;
+ }
+ else
+ {
+ callback.callback.file = file_callback;
+ }
+ callback.callback_data = callback_data;
+ callback.request = nautilus_directory_set_up_request (file_attributes);
+ if (wait_for_file_list)
+ {
+ REQUEST_SET_TYPE (callback.request, REQUEST_FILE_LIST);
+ }
+
+ /* Handle the NULL case. */
+ if (directory == NULL)
+ {
+ ready_callback_call (NULL, &callback);
+ return;
+ }
+
+ /* Check if the callback is already there. */
+ if (g_list_find_custom (directory->details->call_when_ready_list,
+ &callback,
+ ready_callback_key_compare_only_active) != NULL)
+ {
+ if (file_callback != NULL && directory_callback != NULL)
+ {
+ g_warning ("tried to add a new callback while an old one was pending");
+ }
+ /* NULL callback means, just read it. Conflicts are ok. */
+ return;
+ }
+
+ /* Add the new callback to the list. */
+ directory->details->call_when_ready_list = g_list_prepend
+ (directory->details->call_when_ready_list,
+ g_memdup (&callback, sizeof (callback)));
+ request_counter_add_request (directory->details->call_when_ready_counters,
+ callback.request);
+
+ /* Put the callback file or all the files on the work queue. */
+ if (file != NULL)
+ {
+ nautilus_directory_add_file_to_work_queue (directory, file);
+ }
+ else
+ {
+ add_all_files_to_work_queue (directory);
+ }
+
+ nautilus_directory_async_state_changed (directory);
+}
+
+gboolean
+nautilus_directory_check_if_ready_internal (NautilusDirectory *directory,
+ NautilusFile *file,
+ NautilusFileAttributes file_attributes)
+{
+ Request request;
+
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+
+ request = nautilus_directory_set_up_request (file_attributes);
+ return request_is_satisfied (directory, file, request);
}
static void
remove_callback_link_keep_data (NautilusDirectory *directory,
- GList *link)
+ GList *link)
{
- ReadyCallback *callback;
+ ReadyCallback *callback;
+
+ callback = link->data;
+
+ directory->details->call_when_ready_list = g_list_remove_link
+ (directory->details->call_when_ready_list, link);
- callback = link->data;
-
- directory->details->call_when_ready_list = g_list_remove_link
- (directory->details->call_when_ready_list, link);
-
- request_counter_remove_request (directory->details->call_when_ready_counters,
- callback->request);
- g_list_free_1 (link);
+ request_counter_remove_request (directory->details->call_when_ready_counters,
+ callback->request);
+ g_list_free_1 (link);
}
static void
remove_callback_link (NautilusDirectory *directory,
- GList *link)
+ GList *link)
{
- ReadyCallback *callback;
-
- callback = link->data;
- remove_callback_link_keep_data (directory, link);
- g_free (callback);
+ ReadyCallback *callback;
+
+ callback = link->data;
+ remove_callback_link_keep_data (directory, link);
+ g_free (callback);
}
void
-nautilus_directory_cancel_callback_internal (NautilusDirectory *directory,
- NautilusFile *file,
- NautilusDirectoryCallback directory_callback,
- NautilusFileCallback file_callback,
- gpointer callback_data)
-{
- ReadyCallback callback;
- GList *node;
-
- if (directory == NULL) {
- return;
- }
-
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (file == NULL || NAUTILUS_IS_FILE (file));
- g_assert (file != NULL || directory_callback != NULL);
- g_assert (file == NULL || file_callback != NULL);
-
- /* Construct a callback object. */
- callback.file = file;
- if (file == NULL) {
- callback.callback.directory = directory_callback;
- } else {
- callback.callback.file = file_callback;
- }
- callback.callback_data = callback_data;
-
- /* Remove all queued callback from the list (including non-active). */
- do {
- node = g_list_find_custom (directory->details->call_when_ready_list,
- &callback,
- ready_callback_key_compare);
- if (node != NULL) {
- remove_callback_link (directory, node);
-
- nautilus_directory_async_state_changed (directory);
- }
- } while (node != NULL);
+nautilus_directory_cancel_callback_internal (NautilusDirectory *directory,
+ NautilusFile *file,
+ NautilusDirectoryCallback directory_callback,
+ NautilusFileCallback file_callback,
+ gpointer callback_data)
+{
+ ReadyCallback callback;
+ GList *node;
+
+ if (directory == NULL)
+ {
+ return;
+ }
+
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (file == NULL || NAUTILUS_IS_FILE (file));
+ g_assert (file != NULL || directory_callback != NULL);
+ g_assert (file == NULL || file_callback != NULL);
+
+ /* Construct a callback object. */
+ callback.file = file;
+ if (file == NULL)
+ {
+ callback.callback.directory = directory_callback;
+ }
+ else
+ {
+ callback.callback.file = file_callback;
+ }
+ callback.callback_data = callback_data;
+
+ /* Remove all queued callback from the list (including non-active). */
+ do
+ {
+ node = g_list_find_custom (directory->details->call_when_ready_list,
+ &callback,
+ ready_callback_key_compare);
+ if (node != NULL)
+ {
+ remove_callback_link (directory, node);
+
+ nautilus_directory_async_state_changed (directory);
+ }
+ }
+ while (node != NULL);
}
static void
new_files_state_unref (NewFilesState *state)
{
- state->count--;
+ state->count--;
+
+ if (state->count == 0)
+ {
+ if (state->directory)
+ {
+ state->directory->details->new_files_in_progress =
+ g_list_remove (state->directory->details->new_files_in_progress,
+ state);
+ }
- if (state->count == 0) {
- if (state->directory) {
- state->directory->details->new_files_in_progress =
- g_list_remove (state->directory->details->new_files_in_progress,
- state);
- }
-
- g_object_unref (state->cancellable);
- g_free (state);
- }
+ g_object_unref (state->cancellable);
+ g_free (state);
+ }
}
static void
-new_files_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+new_files_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusDirectory *directory;
- GFileInfo *info;
- NewFilesState *state;
+ NautilusDirectory *directory;
+ GFileInfo *info;
+ NewFilesState *state;
+
+ state = user_data;
- state = user_data;
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ new_files_state_unref (state);
+ return;
+ }
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- new_files_state_unref (state);
- return;
- }
-
- directory = nautilus_directory_ref (state->directory);
-
- /* Queue up the new file. */
- info = g_file_query_info_finish (G_FILE (source_object), res, NULL);
- if (info != NULL) {
- directory_load_one (directory, info);
- g_object_unref (info);
- }
+ directory = nautilus_directory_ref (state->directory);
- new_files_state_unref (state);
+ /* Queue up the new file. */
+ info = g_file_query_info_finish (G_FILE (source_object), res, NULL);
+ if (info != NULL)
+ {
+ directory_load_one (directory, info);
+ g_object_unref (info);
+ }
- nautilus_directory_unref (directory);
+ new_files_state_unref (state);
+
+ nautilus_directory_unref (directory);
}
void
nautilus_directory_get_info_for_new_files (NautilusDirectory *directory,
- GList *location_list)
-{
- NewFilesState *state;
- GFile *location;
- GList *l;
-
- if (location_list == NULL) {
- return;
- }
-
- state = g_new (NewFilesState, 1);
- state->directory = directory;
- state->cancellable = g_cancellable_new ();
- state->count = 0;
-
- for (l = location_list; l != NULL; l = l->next) {
- location = l->data;
-
- state->count++;
-
- g_file_query_info_async (location,
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- new_files_callback, state);
- }
-
- directory->details->new_files_in_progress
- = g_list_prepend (directory->details->new_files_in_progress,
- state);
+ GList *location_list)
+{
+ NewFilesState *state;
+ GFile *location;
+ GList *l;
+
+ if (location_list == NULL)
+ {
+ return;
+ }
+
+ state = g_new (NewFilesState, 1);
+ state->directory = directory;
+ state->cancellable = g_cancellable_new ();
+ state->count = 0;
+
+ for (l = location_list; l != NULL; l = l->next)
+ {
+ location = l->data;
+
+ state->count++;
+
+ g_file_query_info_async (location,
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ new_files_callback, state);
+ }
+
+ directory->details->new_files_in_progress
+ = g_list_prepend (directory->details->new_files_in_progress,
+ state);
}
void
nautilus_async_destroying_file (NautilusFile *file)
{
- NautilusDirectory *directory;
- gboolean changed;
- GList *node, *next;
- ReadyCallback *callback;
- Monitor *monitor;
-
- directory = file->details->directory;
- changed = FALSE;
-
- /* Check for callbacks. */
- for (node = directory->details->call_when_ready_list; node != NULL; node = next) {
- next = node->next;
- callback = node->data;
-
- if (callback->file == file) {
- /* Client should have cancelled callback. */
- if (callback->active) {
- g_warning ("destroyed file has call_when_ready pending");
- }
- remove_callback_link (directory, node);
- changed = TRUE;
- }
- }
-
- /* Check for monitors. */
- for (node = directory->details->monitor_list; node != NULL; node = next) {
- next = node->next;
- monitor = node->data;
-
- if (monitor->file == file) {
- /* Client should have removed monitor earlier. */
- g_warning ("destroyed file still being monitored");
- remove_monitor_link (directory, node);
- changed = TRUE;
- }
- }
-
- /* Check if it's a file that's currently being worked on.
- * If so, make that NULL so it gets canceled right away.
- */
- if (directory->details->count_in_progress != NULL &&
- directory->details->count_in_progress->count_file == file) {
- directory->details->count_in_progress->count_file = NULL;
- changed = TRUE;
- }
- if (directory->details->deep_count_file == file) {
- directory->details->deep_count_file = NULL;
- changed = TRUE;
- }
- if (directory->details->mime_list_in_progress != NULL &&
- directory->details->mime_list_in_progress->mime_list_file == file) {
- directory->details->mime_list_in_progress->mime_list_file = NULL;
- changed = TRUE;
- }
- if (directory->details->get_info_file == file) {
- directory->details->get_info_file = NULL;
- changed = TRUE;
- }
- if (directory->details->link_info_read_state != NULL &&
- directory->details->link_info_read_state->file == file) {
- directory->details->link_info_read_state->file = NULL;
- changed = TRUE;
- }
- if (directory->details->extension_info_file == file) {
- directory->details->extension_info_file = NULL;
- changed = TRUE;
- }
-
- if (directory->details->thumbnail_state != NULL &&
- directory->details->thumbnail_state->file == file) {
- directory->details->thumbnail_state->file = NULL;
- changed = TRUE;
- }
-
- if (directory->details->mount_state != NULL &&
- directory->details->mount_state->file == file) {
- directory->details->mount_state->file = NULL;
- changed = TRUE;
- }
-
- if (directory->details->filesystem_info_state != NULL &&
- directory->details->filesystem_info_state->file == file) {
- directory->details->filesystem_info_state->file = NULL;
- changed = TRUE;
- }
-
- /* Let the directory take care of the rest. */
- if (changed) {
- nautilus_directory_async_state_changed (directory);
- }
+ NautilusDirectory *directory;
+ gboolean changed;
+ GList *node, *next;
+ ReadyCallback *callback;
+ Monitor *monitor;
+
+ directory = file->details->directory;
+ changed = FALSE;
+
+ /* Check for callbacks. */
+ for (node = directory->details->call_when_ready_list; node != NULL; node = next)
+ {
+ next = node->next;
+ callback = node->data;
+
+ if (callback->file == file)
+ {
+ /* Client should have cancelled callback. */
+ if (callback->active)
+ {
+ g_warning ("destroyed file has call_when_ready pending");
+ }
+ remove_callback_link (directory, node);
+ changed = TRUE;
+ }
+ }
+
+ /* Check for monitors. */
+ for (node = directory->details->monitor_list; node != NULL; node = next)
+ {
+ next = node->next;
+ monitor = node->data;
+
+ if (monitor->file == file)
+ {
+ /* Client should have removed monitor earlier. */
+ g_warning ("destroyed file still being monitored");
+ remove_monitor_link (directory, node);
+ changed = TRUE;
+ }
+ }
+
+ /* Check if it's a file that's currently being worked on.
+ * If so, make that NULL so it gets canceled right away.
+ */
+ if (directory->details->count_in_progress != NULL &&
+ directory->details->count_in_progress->count_file == file)
+ {
+ directory->details->count_in_progress->count_file = NULL;
+ changed = TRUE;
+ }
+ if (directory->details->deep_count_file == file)
+ {
+ directory->details->deep_count_file = NULL;
+ changed = TRUE;
+ }
+ if (directory->details->mime_list_in_progress != NULL &&
+ directory->details->mime_list_in_progress->mime_list_file == file)
+ {
+ directory->details->mime_list_in_progress->mime_list_file = NULL;
+ changed = TRUE;
+ }
+ if (directory->details->get_info_file == file)
+ {
+ directory->details->get_info_file = NULL;
+ changed = TRUE;
+ }
+ if (directory->details->link_info_read_state != NULL &&
+ directory->details->link_info_read_state->file == file)
+ {
+ directory->details->link_info_read_state->file = NULL;
+ changed = TRUE;
+ }
+ if (directory->details->extension_info_file == file)
+ {
+ directory->details->extension_info_file = NULL;
+ changed = TRUE;
+ }
+
+ if (directory->details->thumbnail_state != NULL &&
+ directory->details->thumbnail_state->file == file)
+ {
+ directory->details->thumbnail_state->file = NULL;
+ changed = TRUE;
+ }
+
+ if (directory->details->mount_state != NULL &&
+ directory->details->mount_state->file == file)
+ {
+ directory->details->mount_state->file = NULL;
+ changed = TRUE;
+ }
+
+ if (directory->details->filesystem_info_state != NULL &&
+ directory->details->filesystem_info_state->file == file)
+ {
+ directory->details->filesystem_info_state->file = NULL;
+ changed = TRUE;
+ }
+
+ /* Let the directory take care of the rest. */
+ if (changed)
+ {
+ nautilus_directory_async_state_changed (directory);
+ }
}
static gboolean
lacks_directory_count (NautilusFile *file)
{
- return !file->details->directory_count_is_up_to_date
- && nautilus_file_should_show_directory_item_count (file);
+ return !file->details->directory_count_is_up_to_date
+ && nautilus_file_should_show_directory_item_count (file);
}
static gboolean
should_get_directory_count_now (NautilusFile *file)
{
- return lacks_directory_count (file)
- && !file->details->loading_directory;
+ return lacks_directory_count (file)
+ && !file->details->loading_directory;
}
static gboolean
lacks_info (NautilusFile *file)
{
- return !file->details->file_info_is_up_to_date
- && !file->details->is_gone;
+ return !file->details->file_info_is_up_to_date
+ && !file->details->is_gone;
}
static gboolean
lacks_filesystem_info (NautilusFile *file)
{
- return !file->details->filesystem_info_is_up_to_date;
+ return !file->details->filesystem_info_is_up_to_date;
}
static gboolean
lacks_deep_count (NautilusFile *file)
{
- return file->details->deep_counts_status != NAUTILUS_REQUEST_DONE;
+ return file->details->deep_counts_status != NAUTILUS_REQUEST_DONE;
}
static gboolean
lacks_mime_list (NautilusFile *file)
{
- return !file->details->mime_list_is_up_to_date;
+ return !file->details->mime_list_is_up_to_date;
}
static gboolean
should_get_mime_list (NautilusFile *file)
{
- return lacks_mime_list (file)
- && !file->details->loading_directory;
+ return lacks_mime_list (file)
+ && !file->details->loading_directory;
}
static gboolean
lacks_link_info (NautilusFile *file)
{
- if (file->details->file_info_is_up_to_date &&
- !file->details->link_info_is_up_to_date) {
- if (nautilus_file_is_nautilus_link (file)) {
- return TRUE;
- } else {
- link_info_done (file->details->directory, file, NULL, NULL, NULL, FALSE, FALSE);
- return FALSE;
- }
- } else {
- return FALSE;
- }
+ if (file->details->file_info_is_up_to_date &&
+ !file->details->link_info_is_up_to_date)
+ {
+ if (nautilus_file_is_nautilus_link (file))
+ {
+ return TRUE;
+ }
+ else
+ {
+ link_info_done (file->details->directory, file, NULL, NULL, NULL, FALSE, FALSE);
+ return FALSE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
}
static gboolean
lacks_extension_info (NautilusFile *file)
{
- return file->details->pending_info_providers != NULL;
+ return file->details->pending_info_providers != NULL;
}
static gboolean
lacks_thumbnail (NautilusFile *file)
{
- return nautilus_file_should_show_thumbnail (file) &&
- file->details->thumbnail_path != NULL &&
- !file->details->thumbnail_is_up_to_date;
+ return nautilus_file_should_show_thumbnail (file) &&
+ file->details->thumbnail_path != NULL &&
+ !file->details->thumbnail_is_up_to_date;
}
static gboolean
lacks_mount (NautilusFile *file)
{
- return (!file->details->mount_is_up_to_date &&
- (
- /* Unix mountpoint, could be a GMount */
- file->details->is_mountpoint ||
-
- /* The toplevel directory of something */
- (file->details->type == G_FILE_TYPE_DIRECTORY &&
- nautilus_file_is_self_owned (file)) ||
-
- /* Mountable, could be a mountpoint */
- (file->details->type == G_FILE_TYPE_MOUNTABLE)
+ return (!file->details->mount_is_up_to_date &&
+ (
+ /* Unix mountpoint, could be a GMount */
+ file->details->is_mountpoint ||
+
+ /* The toplevel directory of something */
+ (file->details->type == G_FILE_TYPE_DIRECTORY &&
+ nautilus_file_is_self_owned (file)) ||
- )
- );
+ /* Mountable, could be a mountpoint */
+ (file->details->type == G_FILE_TYPE_MOUNTABLE)
+
+ )
+ );
}
static gboolean
-has_problem (NautilusDirectory *directory, NautilusFile *file, FileCheck problem)
+has_problem (NautilusDirectory *directory,
+ NautilusFile *file,
+ FileCheck problem)
{
- GList *node;
+ GList *node;
- if (file != NULL) {
- return (* problem) (file);
- }
+ if (file != NULL)
+ {
+ return (*problem)(file);
+ }
- for (node = directory->details->file_list; node != NULL; node = node->next) {
- if ((* problem) (node->data)) {
- return TRUE;
- }
- }
+ for (node = directory->details->file_list; node != NULL; node = node->next)
+ {
+ if ((*problem)(node->data))
+ {
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
request_is_satisfied (NautilusDirectory *directory,
- NautilusFile *file,
- Request request)
-{
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_LIST) &&
- !(directory->details->directory_loaded &&
- directory->details->directory_loaded_sent_notification)) {
- return FALSE;
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT)) {
- if (has_problem (directory, file, lacks_directory_count)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
- if (has_problem (directory, file, lacks_info)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO)) {
- if (has_problem (directory, file, lacks_filesystem_info)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT)) {
- if (has_problem (directory, file, lacks_deep_count)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL)) {
- if (has_problem (directory, file, lacks_thumbnail)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT)) {
- if (has_problem (directory, file, lacks_mount)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
- if (has_problem (directory, file, lacks_mime_list)) {
- return FALSE;
- }
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO)) {
- if (has_problem (directory, file, lacks_link_info)) {
- return FALSE;
- }
- }
-
- return TRUE;
+ NautilusFile *file,
+ Request request)
+{
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_LIST) &&
+ !(directory->details->directory_loaded &&
+ directory->details->directory_loaded_sent_notification))
+ {
+ return FALSE;
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT))
+ {
+ if (has_problem (directory, file, lacks_directory_count))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO))
+ {
+ if (has_problem (directory, file, lacks_info))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO))
+ {
+ if (has_problem (directory, file, lacks_filesystem_info))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT))
+ {
+ if (has_problem (directory, file, lacks_deep_count))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL))
+ {
+ if (has_problem (directory, file, lacks_thumbnail))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT))
+ {
+ if (has_problem (directory, file, lacks_mount))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST))
+ {
+ if (has_problem (directory, file, lacks_mime_list))
+ {
+ return FALSE;
+ }
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO))
+ {
+ if (has_problem (directory, file, lacks_link_info))
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
}
static gboolean
call_ready_callbacks_at_idle (gpointer callback_data)
{
- NautilusDirectory *directory;
- GList *node, *next;
- ReadyCallback *callback;
-
- directory = NAUTILUS_DIRECTORY (callback_data);
- directory->details->call_ready_idle_id = 0;
-
- nautilus_directory_ref (directory);
-
- callback = NULL;
- while (1) {
- /* Check if any callbacks are non-active and call them if they are. */
- for (node = directory->details->call_when_ready_list;
- node != NULL; node = next) {
- next = node->next;
- callback = node->data;
- if (!callback->active) {
- /* Non-active, remove and call */
- break;
- }
- }
- if (node == NULL) {
- break;
- }
-
- /* Callbacks are one-shots, so remove it now. */
- remove_callback_link_keep_data (directory, node);
-
- /* Call the callback. */
- ready_callback_call (directory, callback);
- g_free (callback);
- }
-
- nautilus_directory_async_state_changed (directory);
-
- nautilus_directory_unref (directory);
-
- return FALSE;
+ NautilusDirectory *directory;
+ GList *node, *next;
+ ReadyCallback *callback;
+
+ directory = NAUTILUS_DIRECTORY (callback_data);
+ directory->details->call_ready_idle_id = 0;
+
+ nautilus_directory_ref (directory);
+
+ callback = NULL;
+ while (1)
+ {
+ /* Check if any callbacks are non-active and call them if they are. */
+ for (node = directory->details->call_when_ready_list;
+ node != NULL; node = next)
+ {
+ next = node->next;
+ callback = node->data;
+ if (!callback->active)
+ {
+ /* Non-active, remove and call */
+ break;
+ }
+ }
+ if (node == NULL)
+ {
+ break;
+ }
+
+ /* Callbacks are one-shots, so remove it now. */
+ remove_callback_link_keep_data (directory, node);
+
+ /* Call the callback. */
+ ready_callback_call (directory, callback);
+ g_free (callback);
+ }
+
+ nautilus_directory_async_state_changed (directory);
+
+ nautilus_directory_unref (directory);
+
+ return FALSE;
}
static void
schedule_call_ready_callbacks (NautilusDirectory *directory)
{
- if (directory->details->call_ready_idle_id == 0) {
- directory->details->call_ready_idle_id
- = g_idle_add (call_ready_callbacks_at_idle, directory);
- }
+ if (directory->details->call_ready_idle_id == 0)
+ {
+ directory->details->call_ready_idle_id
+ = g_idle_add (call_ready_callbacks_at_idle, directory);
+ }
}
/* Marks all callbacks that are ready as non-active and
@@ -1823,58 +2033,65 @@ schedule_call_ready_callbacks (NautilusDirectory *directory)
static gboolean
call_ready_callbacks (NautilusDirectory *directory)
{
- gboolean found_any;
- GList *node, *next;
- ReadyCallback *callback;
-
- found_any = FALSE;
-
- /* Check if any callbacks are satisifed and mark them for call them if they are. */
- for (node = directory->details->call_when_ready_list;
- node != NULL; node = next) {
- next = node->next;
- callback = node->data;
- if (callback->active &&
- request_is_satisfied (directory, callback->file, callback->request)) {
- callback->active = FALSE;
- found_any = TRUE;
- }
- }
-
- if (found_any) {
- schedule_call_ready_callbacks (directory);
- }
-
- return found_any;
-}
+ gboolean found_any;
+ GList *node, *next;
+ ReadyCallback *callback;
-gboolean
-nautilus_directory_has_active_request_for_file (NautilusDirectory *directory,
- NautilusFile *file)
-{
- GList *node;
- ReadyCallback *callback;
- Monitor *monitor;
+ found_any = FALSE;
+
+ /* Check if any callbacks are satisifed and mark them for call them if they are. */
+ for (node = directory->details->call_when_ready_list;
+ node != NULL; node = next)
+ {
+ next = node->next;
+ callback = node->data;
+ if (callback->active &&
+ request_is_satisfied (directory, callback->file, callback->request))
+ {
+ callback->active = FALSE;
+ found_any = TRUE;
+ }
+ }
- for (node = directory->details->call_when_ready_list;
- node != NULL; node = node->next) {
- callback = node->data;
- if (callback->file == file ||
- callback->file == NULL) {
- return TRUE;
- }
- }
+ if (found_any)
+ {
+ schedule_call_ready_callbacks (directory);
+ }
- for (node = directory->details->monitor_list;
- node != NULL; node = node->next) {
- monitor = node->data;
- if (monitor->file == file ||
- monitor->file == NULL) {
- return TRUE;
- }
- }
+ return found_any;
+}
- return FALSE;
+gboolean
+nautilus_directory_has_active_request_for_file (NautilusDirectory *directory,
+ NautilusFile *file)
+{
+ GList *node;
+ ReadyCallback *callback;
+ Monitor *monitor;
+
+ for (node = directory->details->call_when_ready_list;
+ node != NULL; node = node->next)
+ {
+ callback = node->data;
+ if (callback->file == file ||
+ callback->file == NULL)
+ {
+ return TRUE;
+ }
+ }
+
+ for (node = directory->details->monitor_list;
+ node != NULL; node = node->next)
+ {
+ monitor = node->data;
+ if (monitor->file == file ||
+ monitor->file == NULL)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
}
@@ -1882,145 +2099,161 @@ nautilus_directory_has_active_request_for_file (NautilusDirectory *directory,
gboolean
nautilus_directory_is_anyone_monitoring_file_list (NautilusDirectory *directory)
{
- if (directory->details->call_when_ready_counters[REQUEST_FILE_LIST] > 0) {
- return TRUE;
- }
+ if (directory->details->call_when_ready_counters[REQUEST_FILE_LIST] > 0)
+ {
+ return TRUE;
+ }
- if (directory->details->monitor_counters[REQUEST_FILE_LIST] > 0) {
- return TRUE;
- }
+ if (directory->details->monitor_counters[REQUEST_FILE_LIST] > 0)
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
/* This checks if the file list being monitored. */
gboolean
-nautilus_directory_is_file_list_monitored (NautilusDirectory *directory)
+nautilus_directory_is_file_list_monitored (NautilusDirectory *directory)
{
- return directory->details->file_list_monitored;
+ return directory->details->file_list_monitored;
}
static void
mark_all_files_unconfirmed (NautilusDirectory *directory)
{
- GList *node;
- NautilusFile *file;
+ GList *node;
+ NautilusFile *file;
- for (node = directory->details->file_list; node != NULL; node = node->next) {
- file = node->data;
- set_file_unconfirmed (file, TRUE);
- }
+ for (node = directory->details->file_list; node != NULL; node = node->next)
+ {
+ file = node->data;
+ set_file_unconfirmed (file, TRUE);
+ }
}
static void
directory_load_state_free (DirectoryLoadState *state)
{
- if (state->enumerator) {
- if (!g_file_enumerator_is_closed (state->enumerator)) {
- g_file_enumerator_close_async (state->enumerator,
- 0, NULL, NULL, NULL);
- }
- g_object_unref (state->enumerator);
- }
-
- if (state->load_mime_list_hash != NULL) {
- istr_set_destroy (state->load_mime_list_hash);
- }
- nautilus_file_unref (state->load_directory_file);
- g_object_unref (state->cancellable);
- g_free (state);
+ if (state->enumerator)
+ {
+ if (!g_file_enumerator_is_closed (state->enumerator))
+ {
+ g_file_enumerator_close_async (state->enumerator,
+ 0, NULL, NULL, NULL);
+ }
+ g_object_unref (state->enumerator);
+ }
+
+ if (state->load_mime_list_hash != NULL)
+ {
+ istr_set_destroy (state->load_mime_list_hash);
+ }
+ nautilus_file_unref (state->load_directory_file);
+ g_object_unref (state->cancellable);
+ g_free (state);
}
static void
-more_files_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- DirectoryLoadState *state;
- NautilusDirectory *directory;
- GError *error;
- GList *files, *l;
- GFileInfo *info;
-
- state = user_data;
-
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- directory_load_state_free (state);
- return;
- }
-
- directory = nautilus_directory_ref (state->directory);
-
- g_assert (directory->details->directory_load_in_progress != NULL);
- g_assert (directory->details->directory_load_in_progress == state);
-
- error = NULL;
- files = g_file_enumerator_next_files_finish (state->enumerator,
- res, &error);
-
- for (l = files; l != NULL; l = l->next) {
- info = l->data;
- directory_load_one (directory, info);
- g_object_unref (info);
- }
-
- if (files == NULL) {
- directory_load_done (directory, error);
- directory_load_state_free (state);
- } else {
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- more_files_callback,
- state);
- }
-
- nautilus_directory_unref (directory);
-
- if (error) {
- g_error_free (error);
- }
-
- g_list_free (files);
+more_files_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DirectoryLoadState *state;
+ NautilusDirectory *directory;
+ GError *error;
+ GList *files, *l;
+ GFileInfo *info;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ directory_load_state_free (state);
+ return;
+ }
+
+ directory = nautilus_directory_ref (state->directory);
+
+ g_assert (directory->details->directory_load_in_progress != NULL);
+ g_assert (directory->details->directory_load_in_progress == state);
+
+ error = NULL;
+ files = g_file_enumerator_next_files_finish (state->enumerator,
+ res, &error);
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ info = l->data;
+ directory_load_one (directory, info);
+ g_object_unref (info);
+ }
+
+ if (files == NULL)
+ {
+ directory_load_done (directory, error);
+ directory_load_state_free (state);
+ }
+ else
+ {
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ more_files_callback,
+ state);
+ }
+
+ nautilus_directory_unref (directory);
+
+ if (error)
+ {
+ g_error_free (error);
+ }
+
+ g_list_free (files);
}
static void
-enumerate_children_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- DirectoryLoadState *state;
- GFileEnumerator *enumerator;
- GError *error;
-
- state = user_data;
-
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- directory_load_state_free (state);
- return;
- }
-
- error = NULL;
- enumerator = g_file_enumerate_children_finish (G_FILE (source_object),
- res, &error);
-
- if (enumerator == NULL) {
- directory_load_done (state->directory, error);
- g_error_free (error);
- directory_load_state_free (state);
- return;
- } else {
- state->enumerator = enumerator;
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- more_files_callback,
- state);
- }
+enumerate_children_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DirectoryLoadState *state;
+ GFileEnumerator *enumerator;
+ GError *error;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ directory_load_state_free (state);
+ return;
+ }
+
+ error = NULL;
+ enumerator = g_file_enumerate_children_finish (G_FILE (source_object),
+ res, &error);
+
+ if (enumerator == NULL)
+ {
+ directory_load_done (state->directory, error);
+ g_error_free (error);
+ directory_load_state_free (state);
+ return;
+ }
+ else
+ {
+ state->enumerator = enumerator;
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ more_files_callback,
+ state);
+ }
}
@@ -2028,86 +2261,93 @@ enumerate_children_callback (GObject *source_object,
static void
start_monitoring_file_list (NautilusDirectory *directory)
{
- DirectoryLoadState *state;
-
- if (!directory->details->file_list_monitored) {
- g_assert (!directory->details->directory_load_in_progress);
- directory->details->file_list_monitored = TRUE;
- nautilus_file_list_ref (directory->details->file_list);
- }
-
- if (directory->details->directory_loaded ||
- directory->details->directory_load_in_progress != NULL) {
- return;
- }
-
- if (!async_job_start (directory, "file list")) {
- return;
- }
-
- mark_all_files_unconfirmed (directory);
-
- state = g_new0 (DirectoryLoadState, 1);
- state->directory = directory;
- state->cancellable = g_cancellable_new ();
- state->load_mime_list_hash = istr_set_new ();
- state->load_file_count = 0;
-
- g_assert (directory->details->location != NULL);
- state->load_directory_file =
- nautilus_directory_get_corresponding_file (directory);
- state->load_directory_file->details->loading_directory = TRUE;
+ DirectoryLoadState *state;
+
+ if (!directory->details->file_list_monitored)
+ {
+ g_assert (!directory->details->directory_load_in_progress);
+ directory->details->file_list_monitored = TRUE;
+ nautilus_file_list_ref (directory->details->file_list);
+ }
+
+ if (directory->details->directory_loaded ||
+ directory->details->directory_load_in_progress != NULL)
+ {
+ return;
+ }
+
+ if (!async_job_start (directory, "file list"))
+ {
+ return;
+ }
+
+ mark_all_files_unconfirmed (directory);
+
+ state = g_new0 (DirectoryLoadState, 1);
+ state->directory = directory;
+ state->cancellable = g_cancellable_new ();
+ state->load_mime_list_hash = istr_set_new ();
+ state->load_file_count = 0;
+
+ g_assert (directory->details->location != NULL);
+ state->load_directory_file =
+ nautilus_directory_get_corresponding_file (directory);
+ state->load_directory_file->details->loading_directory = TRUE;
#ifdef DEBUG_LOAD_DIRECTORY
- g_message ("load_directory called to monitor file list of %p", directory->details->location);
+ g_message ("load_directory called to monitor file list of %p", directory->details->location);
#endif
-
- directory->details->directory_load_in_progress = state;
-
- g_file_enumerate_children_async (directory->details->location,
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0, /* flags */
- G_PRIORITY_DEFAULT, /* prio */
- state->cancellable,
- enumerate_children_callback,
- state);
+
+ directory->details->directory_load_in_progress = state;
+
+ g_file_enumerate_children_async (directory->details->location,
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0, /* flags */
+ G_PRIORITY_DEFAULT, /* prio */
+ state->cancellable,
+ enumerate_children_callback,
+ state);
}
/* Stop monitoring the file list if it is being monitored. */
void
nautilus_directory_stop_monitoring_file_list (NautilusDirectory *directory)
{
- if (!directory->details->file_list_monitored) {
- g_assert (directory->details->directory_load_in_progress == NULL);
- return;
- }
+ if (!directory->details->file_list_monitored)
+ {
+ g_assert (directory->details->directory_load_in_progress == NULL);
+ return;
+ }
- directory->details->file_list_monitored = FALSE;
- file_list_cancel (directory);
- nautilus_file_list_unref (directory->details->file_list);
- directory->details->directory_loaded = FALSE;
+ directory->details->file_list_monitored = FALSE;
+ file_list_cancel (directory);
+ nautilus_file_list_unref (directory->details->file_list);
+ directory->details->directory_loaded = FALSE;
}
static void
file_list_start_or_stop (NautilusDirectory *directory)
{
- if (nautilus_directory_is_anyone_monitoring_file_list (directory)) {
- start_monitoring_file_list (directory);
- } else {
- nautilus_directory_stop_monitoring_file_list (directory);
- }
+ if (nautilus_directory_is_anyone_monitoring_file_list (directory))
+ {
+ start_monitoring_file_list (directory);
+ }
+ else
+ {
+ nautilus_directory_stop_monitoring_file_list (directory);
+ }
}
void
nautilus_file_invalidate_count_and_mime_list (NautilusFile *file)
{
- NautilusFileAttributes attributes;
-
- attributes = NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES;
-
- nautilus_file_invalidate_attributes (file, attributes);
+ NautilusFileAttributes attributes;
+
+ attributes = NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES;
+
+ nautilus_file_invalidate_attributes (file, attributes);
}
@@ -2120,1429 +2360,1578 @@ nautilus_file_invalidate_count_and_mime_list (NautilusFile *file)
void
nautilus_directory_invalidate_count_and_mime_list (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_directory_get_existing_corresponding_file (directory);
- if (file != NULL) {
- nautilus_file_invalidate_count_and_mime_list (file);
- }
-
- nautilus_file_unref (file);
+ file = nautilus_directory_get_existing_corresponding_file (directory);
+ if (file != NULL)
+ {
+ nautilus_file_invalidate_count_and_mime_list (file);
+ }
+
+ nautilus_file_unref (file);
}
static void
nautilus_directory_invalidate_file_attributes (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes)
+ NautilusFileAttributes file_attributes)
{
- GList *node;
+ GList *node;
- cancel_loading_attributes (directory, file_attributes);
+ cancel_loading_attributes (directory, file_attributes);
- for (node = directory->details->file_list; node != NULL; node = node->next) {
- nautilus_file_invalidate_attributes_internal (NAUTILUS_FILE (node->data),
- file_attributes);
- }
+ for (node = directory->details->file_list; node != NULL; node = node->next)
+ {
+ nautilus_file_invalidate_attributes_internal (NAUTILUS_FILE (node->data),
+ file_attributes);
+ }
- if (directory->details->as_file != NULL) {
- nautilus_file_invalidate_attributes_internal (directory->details->as_file,
- file_attributes);
- }
+ if (directory->details->as_file != NULL)
+ {
+ nautilus_file_invalidate_attributes_internal (directory->details->as_file,
+ file_attributes);
+ }
}
void
-nautilus_directory_force_reload_internal (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes)
+nautilus_directory_force_reload_internal (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes)
{
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- /* invalidate attributes that are getting reloaded for all files */
- nautilus_directory_invalidate_file_attributes (directory, file_attributes);
+ /* invalidate attributes that are getting reloaded for all files */
+ nautilus_directory_invalidate_file_attributes (directory, file_attributes);
- /* Start a new directory load. */
- file_list_cancel (directory);
- directory->details->directory_loaded = FALSE;
+ /* Start a new directory load. */
+ file_list_cancel (directory);
+ directory->details->directory_loaded = FALSE;
- /* Start a new directory count. */
- nautilus_directory_invalidate_count_and_mime_list (directory);
+ /* Start a new directory count. */
+ nautilus_directory_invalidate_count_and_mime_list (directory);
- add_all_files_to_work_queue (directory);
- nautilus_directory_async_state_changed (directory);
+ add_all_files_to_work_queue (directory);
+ nautilus_directory_async_state_changed (directory);
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static gboolean
monitor_includes_file (const Monitor *monitor,
- NautilusFile *file)
-{
- if (monitor->file == file) {
- return TRUE;
- }
- if (monitor->file != NULL) {
- return FALSE;
- }
- if (file == file->details->directory->details->as_file) {
- return FALSE;
- }
- return nautilus_file_should_show (file,
- monitor->monitor_hidden_files,
- TRUE);
+ NautilusFile *file)
+{
+ if (monitor->file == file)
+ {
+ return TRUE;
+ }
+ if (monitor->file != NULL)
+ {
+ return FALSE;
+ }
+ if (file == file->details->directory->details->as_file)
+ {
+ return FALSE;
+ }
+ return nautilus_file_should_show (file,
+ monitor->monitor_hidden_files,
+ TRUE);
}
static gboolean
is_needy (NautilusFile *file,
- FileCheck check_missing,
- RequestType request_type_wanted)
-{
- NautilusDirectory *directory;
- GList *node;
- ReadyCallback *callback;
- Monitor *monitor;
-
- if (!(* check_missing) (file)) {
- return FALSE;
- }
-
- directory = file->details->directory;
- if (directory->details->call_when_ready_counters[request_type_wanted] > 0) {
- for (node = directory->details->call_when_ready_list;
- node != NULL; node = node->next) {
- callback = node->data;
- if (callback->active &&
- REQUEST_WANTS_TYPE (callback->request, request_type_wanted)) {
- if (callback->file == file) {
- return TRUE;
- }
- if (callback->file == NULL
- && file != directory->details->as_file) {
- return TRUE;
- }
- }
- }
- }
-
- if (directory->details->monitor_counters[request_type_wanted] > 0) {
- for (node = directory->details->monitor_list;
- node != NULL; node = node->next) {
- monitor = node->data;
- if (REQUEST_WANTS_TYPE (monitor->request, request_type_wanted)) {
- if (monitor_includes_file (monitor, file)) {
- return TRUE;
- }
- }
- }
- }
- return FALSE;
+ FileCheck check_missing,
+ RequestType request_type_wanted)
+{
+ NautilusDirectory *directory;
+ GList *node;
+ ReadyCallback *callback;
+ Monitor *monitor;
+
+ if (!(*check_missing)(file))
+ {
+ return FALSE;
+ }
+
+ directory = file->details->directory;
+ if (directory->details->call_when_ready_counters[request_type_wanted] > 0)
+ {
+ for (node = directory->details->call_when_ready_list;
+ node != NULL; node = node->next)
+ {
+ callback = node->data;
+ if (callback->active &&
+ REQUEST_WANTS_TYPE (callback->request, request_type_wanted))
+ {
+ if (callback->file == file)
+ {
+ return TRUE;
+ }
+ if (callback->file == NULL
+ && file != directory->details->as_file)
+ {
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ if (directory->details->monitor_counters[request_type_wanted] > 0)
+ {
+ for (node = directory->details->monitor_list;
+ node != NULL; node = node->next)
+ {
+ monitor = node->data;
+ if (REQUEST_WANTS_TYPE (monitor->request, request_type_wanted))
+ {
+ if (monitor_includes_file (monitor, file))
+ {
+ return TRUE;
+ }
+ }
+ }
+ }
+ return FALSE;
}
static void
directory_count_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->count_in_progress != NULL) {
- file = directory->details->count_in_progress->count_file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- should_get_directory_count_now,
- REQUEST_DIRECTORY_COUNT)) {
- return;
- }
- }
+ if (directory->details->count_in_progress != NULL)
+ {
+ file = directory->details->count_in_progress->count_file;
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ should_get_directory_count_now,
+ REQUEST_DIRECTORY_COUNT))
+ {
+ return;
+ }
+ }
- /* The count is not wanted, so stop it. */
- directory_count_cancel (directory);
- }
+ /* The count is not wanted, so stop it. */
+ directory_count_cancel (directory);
+ }
}
static guint
count_non_skipped_files (GList *list)
{
- guint count;
- GList *node;
- GFileInfo *info;
+ guint count;
+ GList *node;
+ GFileInfo *info;
- count = 0;
- for (node = list; node != NULL; node = node->next) {
- info = node->data;
- if (!should_skip_file (NULL, info)) {
- count += 1;
- }
- }
- return count;
+ count = 0;
+ for (node = list; node != NULL; node = node->next)
+ {
+ info = node->data;
+ if (!should_skip_file (NULL, info))
+ {
+ count += 1;
+ }
+ }
+ return count;
}
static void
count_children_done (NautilusDirectory *directory,
- NautilusFile *count_file,
- gboolean succeeded,
- int count)
-{
- g_assert (NAUTILUS_IS_FILE (count_file));
-
- count_file->details->directory_count_is_up_to_date = TRUE;
-
- /* Record either a failure or success. */
- if (!succeeded) {
- count_file->details->directory_count_failed = TRUE;
- count_file->details->got_directory_count = FALSE;
- count_file->details->directory_count = 0;
- } else {
- count_file->details->directory_count_failed = FALSE;
- count_file->details->got_directory_count = TRUE;
- count_file->details->directory_count = count;
- }
- directory->details->count_in_progress = NULL;
-
- /* Send file-changed even if count failed, so interested parties can
- * distinguish between unknowable and not-yet-known cases.
- */
- nautilus_file_changed (count_file);
-
- /* Start up the next one. */
- async_job_end (directory, "directory count");
- nautilus_directory_async_state_changed (directory);
+ NautilusFile *count_file,
+ gboolean succeeded,
+ int count)
+{
+ g_assert (NAUTILUS_IS_FILE (count_file));
+
+ count_file->details->directory_count_is_up_to_date = TRUE;
+
+ /* Record either a failure or success. */
+ if (!succeeded)
+ {
+ count_file->details->directory_count_failed = TRUE;
+ count_file->details->got_directory_count = FALSE;
+ count_file->details->directory_count = 0;
+ }
+ else
+ {
+ count_file->details->directory_count_failed = FALSE;
+ count_file->details->got_directory_count = TRUE;
+ count_file->details->directory_count = count;
+ }
+ directory->details->count_in_progress = NULL;
+
+ /* Send file-changed even if count failed, so interested parties can
+ * distinguish between unknowable and not-yet-known cases.
+ */
+ nautilus_file_changed (count_file);
+
+ /* Start up the next one. */
+ async_job_end (directory, "directory count");
+ nautilus_directory_async_state_changed (directory);
}
static void
directory_count_state_free (DirectoryCountState *state)
{
- if (state->enumerator) {
- if (!g_file_enumerator_is_closed (state->enumerator)) {
- g_file_enumerator_close_async (state->enumerator,
- 0, NULL, NULL, NULL);
- }
- g_object_unref (state->enumerator);
- }
- g_object_unref (state->cancellable);
- nautilus_directory_unref (state->directory);
- g_free (state);
+ if (state->enumerator)
+ {
+ if (!g_file_enumerator_is_closed (state->enumerator))
+ {
+ g_file_enumerator_close_async (state->enumerator,
+ 0, NULL, NULL, NULL);
+ }
+ g_object_unref (state->enumerator);
+ }
+ g_object_unref (state->cancellable);
+ nautilus_directory_unref (state->directory);
+ g_free (state);
}
static void
-count_more_files_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- DirectoryCountState *state;
- NautilusDirectory *directory;
- GError *error;
- GList *files;
-
- state = user_data;
- directory = state->directory;
-
- if (g_cancellable_is_cancelled (state->cancellable)) {
- /* Operation was cancelled. Bail out */
-
- async_job_end (directory, "directory count");
- nautilus_directory_async_state_changed (directory);
-
- directory_count_state_free (state);
-
- return;
- }
-
- g_assert (directory->details->count_in_progress != NULL);
- g_assert (directory->details->count_in_progress == state);
-
- error = NULL;
- files = g_file_enumerator_next_files_finish (state->enumerator,
- res, &error);
-
- state->file_count += count_non_skipped_files (files);
-
- if (files == NULL) {
- count_children_done (directory, state->count_file,
- TRUE, state->file_count);
- directory_count_state_free (state);
- } else {
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- count_more_files_callback,
- state);
- }
-
- g_list_free_full (files, g_object_unref);
-
- if (error) {
- g_error_free (error);
- }
+count_more_files_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DirectoryCountState *state;
+ NautilusDirectory *directory;
+ GError *error;
+ GList *files;
+
+ state = user_data;
+ directory = state->directory;
+
+ if (g_cancellable_is_cancelled (state->cancellable))
+ {
+ /* Operation was cancelled. Bail out */
+
+ async_job_end (directory, "directory count");
+ nautilus_directory_async_state_changed (directory);
+
+ directory_count_state_free (state);
+
+ return;
+ }
+
+ g_assert (directory->details->count_in_progress != NULL);
+ g_assert (directory->details->count_in_progress == state);
+
+ error = NULL;
+ files = g_file_enumerator_next_files_finish (state->enumerator,
+ res, &error);
+
+ state->file_count += count_non_skipped_files (files);
+
+ if (files == NULL)
+ {
+ count_children_done (directory, state->count_file,
+ TRUE, state->file_count);
+ directory_count_state_free (state);
+ }
+ else
+ {
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ count_more_files_callback,
+ state);
+ }
+
+ g_list_free_full (files, g_object_unref);
+
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-count_children_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- DirectoryCountState *state;
- GFileEnumerator *enumerator;
- NautilusDirectory *directory;
- GError *error;
-
- state = user_data;
-
- if (g_cancellable_is_cancelled (state->cancellable)) {
- /* Operation was cancelled. Bail out */
- directory = state->directory;
-
- async_job_end (directory, "directory count");
- nautilus_directory_async_state_changed (directory);
-
- directory_count_state_free (state);
-
- return;
- }
-
- error = NULL;
- enumerator = g_file_enumerate_children_finish (G_FILE (source_object),
- res, &error);
-
- if (enumerator == NULL) {
- count_children_done (state->directory,
- state->count_file,
- FALSE, 0);
- g_error_free (error);
- directory_count_state_free (state);
- return;
- } else {
- state->enumerator = enumerator;
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- count_more_files_callback,
- state);
- }
+count_children_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DirectoryCountState *state;
+ GFileEnumerator *enumerator;
+ NautilusDirectory *directory;
+ GError *error;
+
+ state = user_data;
+
+ if (g_cancellable_is_cancelled (state->cancellable))
+ {
+ /* Operation was cancelled. Bail out */
+ directory = state->directory;
+
+ async_job_end (directory, "directory count");
+ nautilus_directory_async_state_changed (directory);
+
+ directory_count_state_free (state);
+
+ return;
+ }
+
+ error = NULL;
+ enumerator = g_file_enumerate_children_finish (G_FILE (source_object),
+ res, &error);
+
+ if (enumerator == NULL)
+ {
+ count_children_done (state->directory,
+ state->count_file,
+ FALSE, 0);
+ g_error_free (error);
+ directory_count_state_free (state);
+ return;
+ }
+ else
+ {
+ state->enumerator = enumerator;
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ count_more_files_callback,
+ state);
+ }
}
static void
directory_count_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- DirectoryCountState *state;
- GFile *location;
-
- if (directory->details->count_in_progress != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file,
- should_get_directory_count_now,
- REQUEST_DIRECTORY_COUNT)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!nautilus_file_is_directory (file)) {
- file->details->directory_count_is_up_to_date = TRUE;
- file->details->directory_count_failed = FALSE;
- file->details->got_directory_count = FALSE;
-
- nautilus_directory_async_state_changed (directory);
- return;
- }
-
- if (!async_job_start (directory, "directory count")) {
- return;
- }
-
- /* Start counting. */
- state = g_new0 (DirectoryCountState, 1);
- state->count_file = file;
- state->directory = nautilus_directory_ref (directory);
- state->cancellable = g_cancellable_new ();
-
- directory->details->count_in_progress = state;
-
- location = nautilus_file_get_location (file);
-#ifdef DEBUG_LOAD_DIRECTORY
- {
- char *uri;
- uri = g_file_get_uri (location);
- g_message ("load_directory called to get shallow file count for %s", uri);
- g_free (uri);
- }
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ DirectoryCountState *state;
+ GFile *location;
+
+ if (directory->details->count_in_progress != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file,
+ should_get_directory_count_now,
+ REQUEST_DIRECTORY_COUNT))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!nautilus_file_is_directory (file))
+ {
+ file->details->directory_count_is_up_to_date = TRUE;
+ file->details->directory_count_failed = FALSE;
+ file->details->got_directory_count = FALSE;
+
+ nautilus_directory_async_state_changed (directory);
+ return;
+ }
+
+ if (!async_job_start (directory, "directory count"))
+ {
+ return;
+ }
+
+ /* Start counting. */
+ state = g_new0 (DirectoryCountState, 1);
+ state->count_file = file;
+ state->directory = nautilus_directory_ref (directory);
+ state->cancellable = g_cancellable_new ();
+
+ directory->details->count_in_progress = state;
+
+ location = nautilus_file_get_location (file);
+#ifdef DEBUG_LOAD_DIRECTORY
+ {
+ char *uri;
+ uri = g_file_get_uri (location);
+ g_message ("load_directory called to get shallow file count for %s", uri);
+ g_free (uri);
+ }
#endif
- g_file_enumerate_children_async (location,
- G_FILE_ATTRIBUTE_STANDARD_NAME ","
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
- G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, /* flags */
- G_PRIORITY_DEFAULT, /* prio */
- state->cancellable,
- count_children_callback,
- state);
- g_object_unref (location);
+ g_file_enumerate_children_async (location,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, /* flags */
+ G_PRIORITY_DEFAULT, /* prio */
+ state->cancellable,
+ count_children_callback,
+ state);
+ g_object_unref (location);
}
static inline gboolean
seen_inode (DeepCountState *state,
- GFileInfo *info)
+ GFileInfo *info)
{
- guint64 inode, inode2;
- guint i;
+ guint64 inode, inode2;
+ guint i;
- inode = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_INODE);
+ inode = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_INODE);
- if (inode != 0) {
- for (i = 0; i < state->seen_deep_count_inodes->len; i++) {
- inode2 = g_array_index (state->seen_deep_count_inodes, guint64, i);
- if (inode == inode2) {
- return TRUE;
- }
- }
- }
+ if (inode != 0)
+ {
+ for (i = 0; i < state->seen_deep_count_inodes->len; i++)
+ {
+ inode2 = g_array_index (state->seen_deep_count_inodes, guint64, i);
+ if (inode == inode2)
+ {
+ return TRUE;
+ }
+ }
+ }
- return FALSE;
+ return FALSE;
}
static inline void
mark_inode_as_seen (DeepCountState *state,
- GFileInfo *info)
+ GFileInfo *info)
{
- guint64 inode;
+ guint64 inode;
- inode = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_INODE);
- if (inode != 0) {
- g_array_append_val (state->seen_deep_count_inodes, inode);
- }
+ inode = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_UNIX_INODE);
+ if (inode != 0)
+ {
+ g_array_append_val (state->seen_deep_count_inodes, inode);
+ }
}
static void
deep_count_one (DeepCountState *state,
- GFileInfo *info)
-{
- NautilusFile *file;
- GFile *subdir;
- gboolean is_seen_inode;
- const char *fs_id;
-
- if (should_skip_file (NULL, info)) {
- return;
- }
-
- is_seen_inode = seen_inode (state, info);
- if (!is_seen_inode) {
- mark_inode_as_seen (state, info);
- }
-
- file = state->directory->details->deep_count_file;
-
- if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
- /* Count the directory. */
- file->details->deep_directory_count += 1;
-
- /* Record the fact that we have to descend into this directory. */
- fs_id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
- if (g_strcmp0 (fs_id, state->fs_id) == 0) {
- /* only if it is on the same filesystem */
- subdir = g_file_get_child (state->deep_count_location, g_file_info_get_name (info));
- state->deep_count_subdirectories = g_list_prepend
- (state->deep_count_subdirectories, subdir);
- }
- } else {
- /* Even non-regular files count as files. */
- file->details->deep_file_count += 1;
- }
-
- /* Count the size. */
- if (!is_seen_inode && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) {
- file->details->deep_size += g_file_info_get_size (info);
- }
+ GFileInfo *info)
+{
+ NautilusFile *file;
+ GFile *subdir;
+ gboolean is_seen_inode;
+ const char *fs_id;
+
+ if (should_skip_file (NULL, info))
+ {
+ return;
+ }
+
+ is_seen_inode = seen_inode (state, info);
+ if (!is_seen_inode)
+ {
+ mark_inode_as_seen (state, info);
+ }
+
+ file = state->directory->details->deep_count_file;
+
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ /* Count the directory. */
+ file->details->deep_directory_count += 1;
+
+ /* Record the fact that we have to descend into this directory. */
+ fs_id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
+ if (g_strcmp0 (fs_id, state->fs_id) == 0)
+ {
+ /* only if it is on the same filesystem */
+ subdir = g_file_get_child (state->deep_count_location, g_file_info_get_name (info));
+ state->deep_count_subdirectories = g_list_prepend
+ (state->deep_count_subdirectories, subdir);
+ }
+ }
+ else
+ {
+ /* Even non-regular files count as files. */
+ file->details->deep_file_count += 1;
+ }
+
+ /* Count the size. */
+ if (!is_seen_inode && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
+ {
+ file->details->deep_size += g_file_info_get_size (info);
+ }
}
static void
deep_count_state_free (DeepCountState *state)
{
- if (state->enumerator) {
- if (!g_file_enumerator_is_closed (state->enumerator)) {
- g_file_enumerator_close_async (state->enumerator,
- 0, NULL, NULL, NULL);
- }
- g_object_unref (state->enumerator);
- }
- g_object_unref (state->cancellable);
- if (state->deep_count_location) {
- g_object_unref (state->deep_count_location);
- }
- g_list_free_full (state->deep_count_subdirectories, g_object_unref);
- g_array_free (state->seen_deep_count_inodes, TRUE);
- g_free (state->fs_id);
- g_free (state);
+ if (state->enumerator)
+ {
+ if (!g_file_enumerator_is_closed (state->enumerator))
+ {
+ g_file_enumerator_close_async (state->enumerator,
+ 0, NULL, NULL, NULL);
+ }
+ g_object_unref (state->enumerator);
+ }
+ g_object_unref (state->cancellable);
+ if (state->deep_count_location)
+ {
+ g_object_unref (state->deep_count_location);
+ }
+ g_list_free_full (state->deep_count_subdirectories, g_object_unref);
+ g_array_free (state->seen_deep_count_inodes, TRUE);
+ g_free (state->fs_id);
+ g_free (state);
}
static void
deep_count_next_dir (DeepCountState *state)
{
- GFile *location;
- NautilusFile *file;
- NautilusDirectory *directory;
- gboolean done;
-
- directory = state->directory;
-
- g_object_unref (state->deep_count_location);
- state->deep_count_location = NULL;
-
- done = FALSE;
- file = directory->details->deep_count_file;
-
- if (state->deep_count_subdirectories != NULL) {
- /* Work on a new directory. */
- location = state->deep_count_subdirectories->data;
- state->deep_count_subdirectories = g_list_remove
- (state->deep_count_subdirectories, location);
- deep_count_load (state, location);
- g_object_unref (location);
- } else {
- file->details->deep_counts_status = NAUTILUS_REQUEST_DONE;
- directory->details->deep_count_file = NULL;
- directory->details->deep_count_in_progress = NULL;
- deep_count_state_free (state);
- done = TRUE;
- }
-
- nautilus_file_updated_deep_count_in_progress (file);
-
- if (done) {
- nautilus_file_changed (file);
- async_job_end (directory, "deep count");
- nautilus_directory_async_state_changed (directory);
- }
+ GFile *location;
+ NautilusFile *file;
+ NautilusDirectory *directory;
+ gboolean done;
+
+ directory = state->directory;
+
+ g_object_unref (state->deep_count_location);
+ state->deep_count_location = NULL;
+
+ done = FALSE;
+ file = directory->details->deep_count_file;
+
+ if (state->deep_count_subdirectories != NULL)
+ {
+ /* Work on a new directory. */
+ location = state->deep_count_subdirectories->data;
+ state->deep_count_subdirectories = g_list_remove
+ (state->deep_count_subdirectories, location);
+ deep_count_load (state, location);
+ g_object_unref (location);
+ }
+ else
+ {
+ file->details->deep_counts_status = NAUTILUS_REQUEST_DONE;
+ directory->details->deep_count_file = NULL;
+ directory->details->deep_count_in_progress = NULL;
+ deep_count_state_free (state);
+ done = TRUE;
+ }
+
+ nautilus_file_updated_deep_count_in_progress (file);
+
+ if (done)
+ {
+ nautilus_file_changed (file);
+ async_job_end (directory, "deep count");
+ nautilus_directory_async_state_changed (directory);
+ }
}
static void
-deep_count_more_files_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- DeepCountState *state;
- NautilusDirectory *directory;
- GList *files, *l;
- GFileInfo *info;
-
- state = user_data;
-
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- deep_count_state_free (state);
- return;
- }
-
- directory = nautilus_directory_ref (state->directory);
-
- g_assert (directory->details->deep_count_in_progress != NULL);
- g_assert (directory->details->deep_count_in_progress == state);
-
- files = g_file_enumerator_next_files_finish (state->enumerator,
- res, NULL);
-
- for (l = files; l != NULL; l = l->next) {
- info = l->data;
- deep_count_one (state, info);
- g_object_unref (info);
- }
-
- if (files == NULL) {
- g_file_enumerator_close_async (state->enumerator, 0, NULL, NULL, NULL);
- g_object_unref (state->enumerator);
- state->enumerator = NULL;
-
- deep_count_next_dir (state);
- } else {
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_LOW,
- state->cancellable,
- deep_count_more_files_callback,
- state);
- }
-
- g_list_free (files);
-
- nautilus_directory_unref (directory);
+deep_count_more_files_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DeepCountState *state;
+ NautilusDirectory *directory;
+ GList *files, *l;
+ GFileInfo *info;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ deep_count_state_free (state);
+ return;
+ }
+
+ directory = nautilus_directory_ref (state->directory);
+
+ g_assert (directory->details->deep_count_in_progress != NULL);
+ g_assert (directory->details->deep_count_in_progress == state);
+
+ files = g_file_enumerator_next_files_finish (state->enumerator,
+ res, NULL);
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ info = l->data;
+ deep_count_one (state, info);
+ g_object_unref (info);
+ }
+
+ if (files == NULL)
+ {
+ g_file_enumerator_close_async (state->enumerator, 0, NULL, NULL, NULL);
+ g_object_unref (state->enumerator);
+ state->enumerator = NULL;
+
+ deep_count_next_dir (state);
+ }
+ else
+ {
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_LOW,
+ state->cancellable,
+ deep_count_more_files_callback,
+ state);
+ }
+
+ g_list_free (files);
+
+ nautilus_directory_unref (directory);
}
static void
-deep_count_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- DeepCountState *state;
- GFileEnumerator *enumerator;
- NautilusFile *file;
-
- state = user_data;
-
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- deep_count_state_free (state);
- return;
- }
-
- file = state->directory->details->deep_count_file;
-
- enumerator = g_file_enumerate_children_finish (G_FILE (source_object), res, NULL);
-
- if (enumerator == NULL) {
- file->details->deep_unreadable_count += 1;
-
- deep_count_next_dir (state);
- } else {
- state->enumerator = enumerator;
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_LOW,
- state->cancellable,
- deep_count_more_files_callback,
- state);
- }
+deep_count_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ DeepCountState *state;
+ GFileEnumerator *enumerator;
+ NautilusFile *file;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ deep_count_state_free (state);
+ return;
+ }
+
+ file = state->directory->details->deep_count_file;
+
+ enumerator = g_file_enumerate_children_finish (G_FILE (source_object), res, NULL);
+
+ if (enumerator == NULL)
+ {
+ file->details->deep_unreadable_count += 1;
+
+ deep_count_next_dir (state);
+ }
+ else
+ {
+ state->enumerator = enumerator;
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_LOW,
+ state->cancellable,
+ deep_count_more_files_callback,
+ state);
+ }
}
static void
-deep_count_load (DeepCountState *state, GFile *location)
-{
- state->deep_count_location = g_object_ref (location);
-
-#ifdef DEBUG_LOAD_DIRECTORY
- g_message ("load_directory called to get deep file count for %p", location);
-#endif
- g_file_enumerate_children_async (state->deep_count_location,
- G_FILE_ATTRIBUTE_STANDARD_NAME ","
- G_FILE_ATTRIBUTE_STANDARD_TYPE ","
- G_FILE_ATTRIBUTE_STANDARD_SIZE ","
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
- G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP ","
- G_FILE_ATTRIBUTE_ID_FILESYSTEM ","
- G_FILE_ATTRIBUTE_UNIX_INODE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, /* flags */
- G_PRIORITY_LOW, /* prio */
- state->cancellable,
- deep_count_callback,
- state);
+deep_count_load (DeepCountState *state,
+ GFile *location)
+{
+ state->deep_count_location = g_object_ref (location);
+
+#ifdef DEBUG_LOAD_DIRECTORY
+ g_message ("load_directory called to get deep file count for %p", location);
+#endif
+ g_file_enumerate_children_async (state->deep_count_location,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_SIZE ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP ","
+ G_FILE_ATTRIBUTE_ID_FILESYSTEM ","
+ G_FILE_ATTRIBUTE_UNIX_INODE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, /* flags */
+ G_PRIORITY_LOW, /* prio */
+ state->cancellable,
+ deep_count_callback,
+ state);
}
static void
deep_count_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->deep_count_in_progress != NULL) {
- file = directory->details->deep_count_file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- lacks_deep_count,
- REQUEST_DEEP_COUNT)) {
- return;
- }
- }
+ if (directory->details->deep_count_in_progress != NULL)
+ {
+ file = directory->details->deep_count_file;
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ lacks_deep_count,
+ REQUEST_DEEP_COUNT))
+ {
+ return;
+ }
+ }
- /* The count is not wanted, so stop it. */
- deep_count_cancel (directory);
- }
+ /* The count is not wanted, so stop it. */
+ deep_count_cancel (directory);
+ }
}
static void
-deep_count_got_info (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+deep_count_got_info (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GFileInfo *info;
- const char *id;
- GFile *file = (GFile *)source_object;
- DeepCountState *state = (DeepCountState *)user_data;
+ GFileInfo *info;
+ const char *id;
+ GFile *file = (GFile *) source_object;
+ DeepCountState *state = (DeepCountState *) user_data;
- info = g_file_query_info_finish (file, res, NULL);
- if (info != NULL) {
- id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
- state->fs_id = g_strdup (id);
- g_object_unref (info);
- }
- deep_count_load (state, file);
+ info = g_file_query_info_finish (file, res, NULL);
+ if (info != NULL)
+ {
+ id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
+ state->fs_id = g_strdup (id);
+ g_object_unref (info);
+ }
+ deep_count_load (state, file);
}
static void
deep_count_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- GFile *location;
- DeepCountState *state;
-
- if (directory->details->deep_count_in_progress != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file,
- lacks_deep_count,
- REQUEST_DEEP_COUNT)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!nautilus_file_is_directory (file)) {
- file->details->deep_counts_status = NAUTILUS_REQUEST_DONE;
-
- nautilus_directory_async_state_changed (directory);
- return;
- }
-
- if (!async_job_start (directory, "deep count")) {
- return;
- }
-
- /* Start counting. */
- file->details->deep_counts_status = NAUTILUS_REQUEST_IN_PROGRESS;
- file->details->deep_directory_count = 0;
- file->details->deep_file_count = 0;
- file->details->deep_unreadable_count = 0;
- file->details->deep_size = 0;
- directory->details->deep_count_file = file;
-
- state = g_new0 (DeepCountState, 1);
- state->directory = directory;
- state->cancellable = g_cancellable_new ();
- state->seen_deep_count_inodes = g_array_new (FALSE, TRUE, sizeof (guint64));
- state->fs_id = NULL;
-
- directory->details->deep_count_in_progress = state;
-
- location = nautilus_file_get_location (file);
- g_file_query_info_async (location,
- G_FILE_ATTRIBUTE_ID_FILESYSTEM,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- G_PRIORITY_DEFAULT,
- NULL,
- deep_count_got_info,
- state);
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ GFile *location;
+ DeepCountState *state;
+
+ if (directory->details->deep_count_in_progress != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file,
+ lacks_deep_count,
+ REQUEST_DEEP_COUNT))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!nautilus_file_is_directory (file))
+ {
+ file->details->deep_counts_status = NAUTILUS_REQUEST_DONE;
+
+ nautilus_directory_async_state_changed (directory);
+ return;
+ }
+
+ if (!async_job_start (directory, "deep count"))
+ {
+ return;
+ }
+
+ /* Start counting. */
+ file->details->deep_counts_status = NAUTILUS_REQUEST_IN_PROGRESS;
+ file->details->deep_directory_count = 0;
+ file->details->deep_file_count = 0;
+ file->details->deep_unreadable_count = 0;
+ file->details->deep_size = 0;
+ directory->details->deep_count_file = file;
+
+ state = g_new0 (DeepCountState, 1);
+ state->directory = directory;
+ state->cancellable = g_cancellable_new ();
+ state->seen_deep_count_inodes = g_array_new (FALSE, TRUE, sizeof (guint64));
+ state->fs_id = NULL;
+
+ directory->details->deep_count_in_progress = state;
+
+ location = nautilus_file_get_location (file);
+ g_file_query_info_async (location,
+ G_FILE_ATTRIBUTE_ID_FILESYSTEM,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ deep_count_got_info,
+ state);
+ g_object_unref (location);
}
static void
mime_list_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
-
- if (directory->details->mime_list_in_progress != NULL) {
- file = directory->details->mime_list_in_progress->mime_list_file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- should_get_mime_list,
- REQUEST_MIME_LIST)) {
- return;
- }
- }
-
- /* The count is not wanted, so stop it. */
- mime_list_cancel (directory);
- }
+ NautilusFile *file;
+
+ if (directory->details->mime_list_in_progress != NULL)
+ {
+ file = directory->details->mime_list_in_progress->mime_list_file;
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ should_get_mime_list,
+ REQUEST_MIME_LIST))
+ {
+ return;
+ }
+ }
+
+ /* The count is not wanted, so stop it. */
+ mime_list_cancel (directory);
+ }
}
static void
mime_list_state_free (MimeListState *state)
{
- if (state->enumerator) {
- if (!g_file_enumerator_is_closed (state->enumerator)) {
- g_file_enumerator_close_async (state->enumerator,
- 0, NULL, NULL, NULL);
- }
- g_object_unref (state->enumerator);
- }
- g_object_unref (state->cancellable);
- istr_set_destroy (state->mime_list_hash);
- nautilus_directory_unref (state->directory);
- g_free (state);
+ if (state->enumerator)
+ {
+ if (!g_file_enumerator_is_closed (state->enumerator))
+ {
+ g_file_enumerator_close_async (state->enumerator,
+ 0, NULL, NULL, NULL);
+ }
+ g_object_unref (state->enumerator);
+ }
+ g_object_unref (state->cancellable);
+ istr_set_destroy (state->mime_list_hash);
+ nautilus_directory_unref (state->directory);
+ g_free (state);
}
static void
-mime_list_done (MimeListState *state, gboolean success)
-{
- NautilusFile *file;
- NautilusDirectory *directory;
-
- directory = state->directory;
- g_assert (directory != NULL);
-
- file = state->mime_list_file;
-
- file->details->mime_list_is_up_to_date = TRUE;
- g_list_free_full (file->details->mime_list, g_free);
- if (success) {
- file->details->mime_list_failed = TRUE;
- file->details->mime_list = NULL;
- } else {
- file->details->got_mime_list = TRUE;
- file->details->mime_list = istr_set_get_as_list (state->mime_list_hash);
- }
- directory->details->mime_list_in_progress = NULL;
-
- /* Send file-changed even if getting the item type list
- * failed, so interested parties can distinguish between
- * unknowable and not-yet-known cases.
- */
- nautilus_file_changed (file);
-
- /* Start up the next one. */
- async_job_end (directory, "MIME list");
- nautilus_directory_async_state_changed (directory);
+mime_list_done (MimeListState *state,
+ gboolean success)
+{
+ NautilusFile *file;
+ NautilusDirectory *directory;
+
+ directory = state->directory;
+ g_assert (directory != NULL);
+
+ file = state->mime_list_file;
+
+ file->details->mime_list_is_up_to_date = TRUE;
+ g_list_free_full (file->details->mime_list, g_free);
+ if (success)
+ {
+ file->details->mime_list_failed = TRUE;
+ file->details->mime_list = NULL;
+ }
+ else
+ {
+ file->details->got_mime_list = TRUE;
+ file->details->mime_list = istr_set_get_as_list (state->mime_list_hash);
+ }
+ directory->details->mime_list_in_progress = NULL;
+
+ /* Send file-changed even if getting the item type list
+ * failed, so interested parties can distinguish between
+ * unknowable and not-yet-known cases.
+ */
+ nautilus_file_changed (file);
+
+ /* Start up the next one. */
+ async_job_end (directory, "MIME list");
+ nautilus_directory_async_state_changed (directory);
}
static void
mime_list_one (MimeListState *state,
- GFileInfo *info)
+ GFileInfo *info)
{
- const char *mime_type;
-
- if (should_skip_file (NULL, info)) {
- g_object_unref (info);
- return;
- }
+ const char *mime_type;
+
+ if (should_skip_file (NULL, info))
+ {
+ g_object_unref (info);
+ return;
+ }
- mime_type = g_file_info_get_content_type (info);
- if (mime_type != NULL) {
- istr_set_insert (state->mime_list_hash, mime_type);
- }
+ mime_type = g_file_info_get_content_type (info);
+ if (mime_type != NULL)
+ {
+ istr_set_insert (state->mime_list_hash, mime_type);
+ }
}
static void
-mime_list_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- MimeListState *state;
- NautilusDirectory *directory;
- GError *error;
- GList *files, *l;
- GFileInfo *info;
-
- state = user_data;
- directory = state->directory;
-
- if (g_cancellable_is_cancelled (state->cancellable)) {
- /* Operation was cancelled. Bail out */
- directory->details->mime_list_in_progress = NULL;
-
- async_job_end (directory, "MIME list");
- nautilus_directory_async_state_changed (directory);
-
- mime_list_state_free (state);
-
- return;
- }
-
- g_assert (directory->details->mime_list_in_progress != NULL);
- g_assert (directory->details->mime_list_in_progress == state);
-
- error = NULL;
- files = g_file_enumerator_next_files_finish (state->enumerator,
- res, &error);
-
- for (l = files; l != NULL; l = l->next) {
- info = l->data;
- mime_list_one (state, info);
- g_object_unref (info);
- }
-
- if (files == NULL) {
- mime_list_done (state, error != NULL);
- mime_list_state_free (state);
- } else {
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- mime_list_callback,
- state);
- }
-
- g_list_free (files);
-
- if (error) {
- g_error_free (error);
- }
+mime_list_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ MimeListState *state;
+ NautilusDirectory *directory;
+ GError *error;
+ GList *files, *l;
+ GFileInfo *info;
+
+ state = user_data;
+ directory = state->directory;
+
+ if (g_cancellable_is_cancelled (state->cancellable))
+ {
+ /* Operation was cancelled. Bail out */
+ directory->details->mime_list_in_progress = NULL;
+
+ async_job_end (directory, "MIME list");
+ nautilus_directory_async_state_changed (directory);
+
+ mime_list_state_free (state);
+
+ return;
+ }
+
+ g_assert (directory->details->mime_list_in_progress != NULL);
+ g_assert (directory->details->mime_list_in_progress == state);
+
+ error = NULL;
+ files = g_file_enumerator_next_files_finish (state->enumerator,
+ res, &error);
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ info = l->data;
+ mime_list_one (state, info);
+ g_object_unref (info);
+ }
+
+ if (files == NULL)
+ {
+ mime_list_done (state, error != NULL);
+ mime_list_state_free (state);
+ }
+ else
+ {
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ mime_list_callback,
+ state);
+ }
+
+ g_list_free (files);
+
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-list_mime_enum_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- MimeListState *state;
- GFileEnumerator *enumerator;
- NautilusDirectory *directory;
- GError *error;
-
- state = user_data;
-
- if (g_cancellable_is_cancelled (state->cancellable)) {
- /* Operation was cancelled. Bail out */
- directory = state->directory;
- directory->details->mime_list_in_progress = NULL;
-
- async_job_end (directory, "MIME list");
- nautilus_directory_async_state_changed (directory);
-
- mime_list_state_free (state);
-
- return;
- }
-
- error = NULL;
- enumerator = g_file_enumerate_children_finish (G_FILE (source_object),
- res, &error);
-
- if (enumerator == NULL) {
- mime_list_done (state, FALSE);
- g_error_free (error);
- mime_list_state_free (state);
- return;
- } else {
- state->enumerator = enumerator;
- g_file_enumerator_next_files_async (state->enumerator,
- DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- mime_list_callback,
- state);
- }
+list_mime_enum_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ MimeListState *state;
+ GFileEnumerator *enumerator;
+ NautilusDirectory *directory;
+ GError *error;
+
+ state = user_data;
+
+ if (g_cancellable_is_cancelled (state->cancellable))
+ {
+ /* Operation was cancelled. Bail out */
+ directory = state->directory;
+ directory->details->mime_list_in_progress = NULL;
+
+ async_job_end (directory, "MIME list");
+ nautilus_directory_async_state_changed (directory);
+
+ mime_list_state_free (state);
+
+ return;
+ }
+
+ error = NULL;
+ enumerator = g_file_enumerate_children_finish (G_FILE (source_object),
+ res, &error);
+
+ if (enumerator == NULL)
+ {
+ mime_list_done (state, FALSE);
+ g_error_free (error);
+ mime_list_state_free (state);
+ return;
+ }
+ else
+ {
+ state->enumerator = enumerator;
+ g_file_enumerator_next_files_async (state->enumerator,
+ DIRECTORY_LOAD_ITEMS_PER_CALLBACK,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ mime_list_callback,
+ state);
+ }
}
static void
mime_list_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- MimeListState *state;
- GFile *location;
-
- mime_list_stop (directory);
-
- if (directory->details->mime_list_in_progress != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- /* Figure out which file to get a mime list for. */
- if (!is_needy (file,
- should_get_mime_list,
- REQUEST_MIME_LIST)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!nautilus_file_is_directory (file)) {
- g_list_free (file->details->mime_list);
- file->details->mime_list_failed = FALSE;
- file->details->got_mime_list = FALSE;
- file->details->mime_list_is_up_to_date = TRUE;
-
- nautilus_directory_async_state_changed (directory);
- return;
- }
-
- if (!async_job_start (directory, "MIME list")) {
- return;
- }
-
-
- state = g_new0 (MimeListState, 1);
- state->mime_list_file = file;
- state->directory = nautilus_directory_ref (directory);
- state->cancellable = g_cancellable_new ();
- state->mime_list_hash = istr_set_new ();
-
- directory->details->mime_list_in_progress = state;
-
- location = nautilus_file_get_location (file);
-#ifdef DEBUG_LOAD_DIRECTORY
- {
- char *uri;
- uri = g_file_get_uri (location);
- g_message ("load_directory called to get MIME list of %s", uri);
- g_free (uri);
- }
-#endif
-
- g_file_enumerate_children_async (location,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- 0, /* flags */
- G_PRIORITY_LOW, /* prio */
- state->cancellable,
- list_mime_enum_callback,
- state);
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ MimeListState *state;
+ GFile *location;
+
+ mime_list_stop (directory);
+
+ if (directory->details->mime_list_in_progress != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ /* Figure out which file to get a mime list for. */
+ if (!is_needy (file,
+ should_get_mime_list,
+ REQUEST_MIME_LIST))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!nautilus_file_is_directory (file))
+ {
+ g_list_free (file->details->mime_list);
+ file->details->mime_list_failed = FALSE;
+ file->details->got_mime_list = FALSE;
+ file->details->mime_list_is_up_to_date = TRUE;
+
+ nautilus_directory_async_state_changed (directory);
+ return;
+ }
+
+ if (!async_job_start (directory, "MIME list"))
+ {
+ return;
+ }
+
+
+ state = g_new0 (MimeListState, 1);
+ state->mime_list_file = file;
+ state->directory = nautilus_directory_ref (directory);
+ state->cancellable = g_cancellable_new ();
+ state->mime_list_hash = istr_set_new ();
+
+ directory->details->mime_list_in_progress = state;
+
+ location = nautilus_file_get_location (file);
+#ifdef DEBUG_LOAD_DIRECTORY
+ {
+ char *uri;
+ uri = g_file_get_uri (location);
+ g_message ("load_directory called to get MIME list of %s", uri);
+ g_free (uri);
+ }
+#endif
+
+ g_file_enumerate_children_async (location,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, /* flags */
+ G_PRIORITY_LOW, /* prio */
+ state->cancellable,
+ list_mime_enum_callback,
+ state);
+ g_object_unref (location);
}
static void
get_info_state_free (GetInfoState *state)
{
- g_object_unref (state->cancellable);
- g_free (state);
+ g_object_unref (state->cancellable);
+ g_free (state);
}
static void
-query_info_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NautilusDirectory *directory;
- NautilusFile *get_info_file;
- GFileInfo *info;
- GetInfoState *state;
- GError *error;
-
- state = user_data;
-
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- get_info_state_free (state);
- return;
- }
-
- directory = nautilus_directory_ref (state->directory);
-
- get_info_file = directory->details->get_info_file;
- g_assert (NAUTILUS_IS_FILE (get_info_file));
-
- directory->details->get_info_file = NULL;
- directory->details->get_info_in_progress = NULL;
-
- /* ref here because we might be removing the last ref when we
- * mark the file gone below, but we need to keep a ref at
- * least long enough to send the change notification.
- */
- nautilus_file_ref (get_info_file);
-
- error = NULL;
- info = g_file_query_info_finish (G_FILE (source_object), res, &error);
-
- if (info == NULL) {
- if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND) {
- /* mark file as gone */
- nautilus_file_mark_gone (get_info_file);
- }
- get_info_file->details->file_info_is_up_to_date = TRUE;
- nautilus_file_clear_info (get_info_file);
- get_info_file->details->get_info_failed = TRUE;
- get_info_file->details->get_info_error = error;
- } else {
- nautilus_file_update_info (get_info_file, info);
- g_object_unref (info);
- }
-
- nautilus_file_changed (get_info_file);
- nautilus_file_unref (get_info_file);
-
- async_job_end (directory, "file info");
- nautilus_directory_async_state_changed (directory);
-
- nautilus_directory_unref (directory);
-
- get_info_state_free (state);
+query_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NautilusDirectory *directory;
+ NautilusFile *get_info_file;
+ GFileInfo *info;
+ GetInfoState *state;
+ GError *error;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ get_info_state_free (state);
+ return;
+ }
+
+ directory = nautilus_directory_ref (state->directory);
+
+ get_info_file = directory->details->get_info_file;
+ g_assert (NAUTILUS_IS_FILE (get_info_file));
+
+ directory->details->get_info_file = NULL;
+ directory->details->get_info_in_progress = NULL;
+
+ /* ref here because we might be removing the last ref when we
+ * mark the file gone below, but we need to keep a ref at
+ * least long enough to send the change notification.
+ */
+ nautilus_file_ref (get_info_file);
+
+ error = NULL;
+ info = g_file_query_info_finish (G_FILE (source_object), res, &error);
+
+ if (info == NULL)
+ {
+ if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_FOUND)
+ {
+ /* mark file as gone */
+ nautilus_file_mark_gone (get_info_file);
+ }
+ get_info_file->details->file_info_is_up_to_date = TRUE;
+ nautilus_file_clear_info (get_info_file);
+ get_info_file->details->get_info_failed = TRUE;
+ get_info_file->details->get_info_error = error;
+ }
+ else
+ {
+ nautilus_file_update_info (get_info_file, info);
+ g_object_unref (info);
+ }
+
+ nautilus_file_changed (get_info_file);
+ nautilus_file_unref (get_info_file);
+
+ async_job_end (directory, "file info");
+ nautilus_directory_async_state_changed (directory);
+
+ nautilus_directory_unref (directory);
+
+ get_info_state_free (state);
}
static void
file_info_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->get_info_in_progress != NULL) {
- file = directory->details->get_info_file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file, lacks_info, REQUEST_FILE_INFO)) {
- return;
- }
- }
+ if (directory->details->get_info_in_progress != NULL)
+ {
+ file = directory->details->get_info_file;
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file, lacks_info, REQUEST_FILE_INFO))
+ {
+ return;
+ }
+ }
- /* The info is not wanted, so stop it. */
- file_info_cancel (directory);
- }
+ /* The info is not wanted, so stop it. */
+ file_info_cancel (directory);
+ }
}
static void
file_info_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- GFile *location;
- GetInfoState *state;
-
- file_info_stop (directory);
-
- if (directory->details->get_info_in_progress != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file, lacks_info, REQUEST_FILE_INFO)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!async_job_start (directory, "file info")) {
- return;
- }
-
- directory->details->get_info_file = file;
- file->details->get_info_failed = FALSE;
- if (file->details->get_info_error) {
- g_error_free (file->details->get_info_error);
- file->details->get_info_error = NULL;
- }
-
- state = g_new (GetInfoState, 1);
- state->directory = directory;
- state->cancellable = g_cancellable_new ();
-
- directory->details->get_info_in_progress = state;
-
- location = nautilus_file_get_location (file);
- g_file_query_info_async (location,
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0,
- G_PRIORITY_DEFAULT,
- state->cancellable, query_info_callback, state);
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ GFile *location;
+ GetInfoState *state;
+
+ file_info_stop (directory);
+
+ if (directory->details->get_info_in_progress != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file, lacks_info, REQUEST_FILE_INFO))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!async_job_start (directory, "file info"))
+ {
+ return;
+ }
+
+ directory->details->get_info_file = file;
+ file->details->get_info_failed = FALSE;
+ if (file->details->get_info_error)
+ {
+ g_error_free (file->details->get_info_error);
+ file->details->get_info_error = NULL;
+ }
+
+ state = g_new (GetInfoState, 1);
+ state->directory = directory;
+ state->cancellable = g_cancellable_new ();
+
+ directory->details->get_info_in_progress = state;
+
+ location = nautilus_file_get_location (file);
+ g_file_query_info_async (location,
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0,
+ G_PRIORITY_DEFAULT,
+ state->cancellable, query_info_callback, state);
+ g_object_unref (location);
}
static gboolean
is_link_trusted (NautilusFile *file,
- gboolean is_launcher)
-{
- GFile *location;
- gboolean res;
-
- if (!is_launcher) {
- return TRUE;
- }
-
- if (nautilus_file_can_execute (file)) {
- return TRUE;
- }
-
- res = FALSE;
-
- if (nautilus_file_is_local (file)) {
- location = nautilus_file_get_location (file);
- res = nautilus_is_in_system_dir (location);
- g_object_unref (location);
- }
-
- return res;
+ gboolean is_launcher)
+{
+ GFile *location;
+ gboolean res;
+
+ if (!is_launcher)
+ {
+ return TRUE;
+ }
+
+ if (nautilus_file_can_execute (file))
+ {
+ return TRUE;
+ }
+
+ res = FALSE;
+
+ if (nautilus_file_is_local (file))
+ {
+ location = nautilus_file_get_location (file);
+ res = nautilus_is_in_system_dir (location);
+ g_object_unref (location);
+ }
+
+ return res;
}
static void
link_info_done (NautilusDirectory *directory,
- NautilusFile *file,
- const char *uri,
- const char *name,
- GIcon *icon,
- gboolean is_launcher,
- gboolean is_foreign)
-{
- gboolean is_trusted;
-
- file->details->link_info_is_up_to_date = TRUE;
-
- is_trusted = is_link_trusted (file, is_launcher);
-
- if (is_trusted) {
- nautilus_file_set_display_name (file, name, name, TRUE);
- } else {
- nautilus_file_set_display_name (file, NULL, NULL, TRUE);
- }
-
- file->details->got_link_info = TRUE;
- g_clear_object (&file->details->custom_icon);
-
- if (uri) {
- g_free (file->details->activation_uri);
- file->details->activation_uri = NULL;
- file->details->got_custom_activation_uri = TRUE;
- file->details->activation_uri = g_strdup (uri);
- }
- if (is_trusted && (icon != NULL)) {
- file->details->custom_icon = g_object_ref (icon);
- }
- file->details->is_launcher = is_launcher;
- file->details->is_foreign_link = is_foreign;
- file->details->is_trusted_link = is_trusted;
-
- nautilus_directory_async_state_changed (directory);
+ NautilusFile *file,
+ const char *uri,
+ const char *name,
+ GIcon *icon,
+ gboolean is_launcher,
+ gboolean is_foreign)
+{
+ gboolean is_trusted;
+
+ file->details->link_info_is_up_to_date = TRUE;
+
+ is_trusted = is_link_trusted (file, is_launcher);
+
+ if (is_trusted)
+ {
+ nautilus_file_set_display_name (file, name, name, TRUE);
+ }
+ else
+ {
+ nautilus_file_set_display_name (file, NULL, NULL, TRUE);
+ }
+
+ file->details->got_link_info = TRUE;
+ g_clear_object (&file->details->custom_icon);
+
+ if (uri)
+ {
+ g_free (file->details->activation_uri);
+ file->details->activation_uri = NULL;
+ file->details->got_custom_activation_uri = TRUE;
+ file->details->activation_uri = g_strdup (uri);
+ }
+ if (is_trusted && (icon != NULL))
+ {
+ file->details->custom_icon = g_object_ref (icon);
+ }
+ file->details->is_launcher = is_launcher;
+ file->details->is_foreign_link = is_foreign;
+ file->details->is_trusted_link = is_trusted;
+
+ nautilus_directory_async_state_changed (directory);
}
static void
link_info_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->link_info_read_state != NULL) {
- file = directory->details->link_info_read_state->file;
+ if (directory->details->link_info_read_state != NULL)
+ {
+ file = directory->details->link_info_read_state->file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- lacks_link_info,
- REQUEST_LINK_INFO)) {
- return;
- }
- }
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ lacks_link_info,
+ REQUEST_LINK_INFO))
+ {
+ return;
+ }
+ }
- /* The link info is not wanted, so stop it. */
- link_info_cancel (directory);
- }
+ /* The link info is not wanted, so stop it. */
+ link_info_cancel (directory);
+ }
}
static void
link_info_got_data (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean result,
- goffset bytes_read,
- char *file_contents)
-{
- char *link_uri, *uri, *name;
- GIcon *icon;
- gboolean is_launcher;
- gboolean is_foreign;
-
- nautilus_directory_ref (directory);
-
- uri = NULL;
- name = NULL;
- icon = NULL;
- is_launcher = FALSE;
- is_foreign = FALSE;
-
- /* Handle the case where we read the Nautilus link. */
- if (result) {
- link_uri = nautilus_file_get_uri (file);
- nautilus_link_get_link_info_given_file_contents (file_contents, bytes_read, link_uri,
- &uri, &name, &icon, &is_launcher, &is_foreign);
- g_free (link_uri);
- } else {
- /* FIXME bugzilla.gnome.org 42433: We should report this error to the user. */
- }
-
- nautilus_file_ref (file);
- link_info_done (directory, file, uri, name, icon, is_launcher, is_foreign);
- nautilus_file_changed (file);
- nautilus_file_unref (file);
-
- g_free (uri);
- g_free (name);
-
- if (icon != NULL) {
- g_object_unref (icon);
- }
-
- nautilus_directory_unref (directory);
+ NautilusFile *file,
+ gboolean result,
+ goffset bytes_read,
+ char *file_contents)
+{
+ char *link_uri, *uri, *name;
+ GIcon *icon;
+ gboolean is_launcher;
+ gboolean is_foreign;
+
+ nautilus_directory_ref (directory);
+
+ uri = NULL;
+ name = NULL;
+ icon = NULL;
+ is_launcher = FALSE;
+ is_foreign = FALSE;
+
+ /* Handle the case where we read the Nautilus link. */
+ if (result)
+ {
+ link_uri = nautilus_file_get_uri (file);
+ nautilus_link_get_link_info_given_file_contents (file_contents, bytes_read, link_uri,
+ &uri, &name, &icon, &is_launcher, &is_foreign);
+ g_free (link_uri);
+ }
+ else
+ {
+ /* FIXME bugzilla.gnome.org 42433: We should report this error to the user. */
+ }
+
+ nautilus_file_ref (file);
+ link_info_done (directory, file, uri, name, icon, is_launcher, is_foreign);
+ nautilus_file_changed (file);
+ nautilus_file_unref (file);
+
+ g_free (uri);
+ g_free (name);
+
+ if (icon != NULL)
+ {
+ g_object_unref (icon);
+ }
+
+ nautilus_directory_unref (directory);
}
static void
link_info_read_state_free (LinkInfoReadState *state)
{
- g_object_unref (state->cancellable);
- g_free (state);
+ g_object_unref (state->cancellable);
+ g_free (state);
}
static void
-link_info_nautilus_link_read_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+link_info_nautilus_link_read_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- LinkInfoReadState *state;
- gsize file_size;
- char *file_contents;
- gboolean result;
- NautilusDirectory *directory;
+ LinkInfoReadState *state;
+ gsize file_size;
+ char *file_contents;
+ gboolean result;
+ NautilusDirectory *directory;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ link_info_read_state_free (state);
+ return;
+ }
+
+ directory = nautilus_directory_ref (state->directory);
- state = user_data;
+ result = g_file_load_contents_finish (G_FILE (source_object),
+ res,
+ &file_contents, &file_size,
+ NULL, NULL);
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- link_info_read_state_free (state);
- return;
- }
+ state->directory->details->link_info_read_state = NULL;
+ async_job_end (state->directory, "link info");
- directory = nautilus_directory_ref (state->directory);
+ link_info_got_data (state->directory, state->file, result, file_size, file_contents);
- result = g_file_load_contents_finish (G_FILE (source_object),
- res,
- &file_contents, &file_size,
- NULL, NULL);
+ if (result)
+ {
+ g_free (file_contents);
+ }
- state->directory->details->link_info_read_state = NULL;
- async_job_end (state->directory, "link info");
-
- link_info_got_data (state->directory, state->file, result, file_size, file_contents);
+ link_info_read_state_free (state);
- if (result) {
- g_free (file_contents);
- }
-
- link_info_read_state_free (state);
-
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
}
static void
link_info_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- GFile *location;
- gboolean nautilus_style_link;
- LinkInfoReadState *state;
-
- if (directory->details->link_info_read_state != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file,
- lacks_link_info,
- REQUEST_LINK_INFO)) {
- return;
- }
- *doing_io = TRUE;
-
- /* Figure out if it is a link. */
- nautilus_style_link = nautilus_file_is_nautilus_link (file);
- location = nautilus_file_get_location (file);
-
- /* If it's not a link we are done. If it is, we need to read it. */
- if (!nautilus_style_link) {
- link_info_done (directory, file, NULL, NULL, NULL, FALSE, FALSE);
- } else {
- if (!async_job_start (directory, "link info")) {
- g_object_unref (location);
- return;
- }
-
- state = g_new0 (LinkInfoReadState, 1);
- state->directory = directory;
- state->file = file;
- state->cancellable = g_cancellable_new ();
-
- directory->details->link_info_read_state = state;
-
- g_file_load_contents_async (location,
- state->cancellable,
- link_info_nautilus_link_read_callback,
- state);
- }
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ GFile *location;
+ gboolean nautilus_style_link;
+ LinkInfoReadState *state;
+
+ if (directory->details->link_info_read_state != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file,
+ lacks_link_info,
+ REQUEST_LINK_INFO))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ /* Figure out if it is a link. */
+ nautilus_style_link = nautilus_file_is_nautilus_link (file);
+ location = nautilus_file_get_location (file);
+
+ /* If it's not a link we are done. If it is, we need to read it. */
+ if (!nautilus_style_link)
+ {
+ link_info_done (directory, file, NULL, NULL, NULL, FALSE, FALSE);
+ }
+ else
+ {
+ if (!async_job_start (directory, "link info"))
+ {
+ g_object_unref (location);
+ return;
+ }
+
+ state = g_new0 (LinkInfoReadState, 1);
+ state->directory = directory;
+ state->file = file;
+ state->cancellable = g_cancellable_new ();
+
+ directory->details->link_info_read_state = state;
+
+ g_file_load_contents_async (location,
+ state->cancellable,
+ link_info_nautilus_link_read_callback,
+ state);
+ }
+ g_object_unref (location);
}
static void
thumbnail_done (NautilusDirectory *directory,
- NautilusFile *file,
- GdkPixbuf *pixbuf,
- gboolean tried_original)
-{
- const char *thumb_mtime_str;
- time_t thumb_mtime = 0;
-
- file->details->thumbnail_is_up_to_date = TRUE;
- file->details->thumbnail_tried_original = tried_original;
- if (file->details->thumbnail) {
- g_object_unref (file->details->thumbnail);
- file->details->thumbnail = NULL;
- }
- if (file->details->scaled_thumbnail) {
- g_object_unref (file->details->scaled_thumbnail);
- file->details->scaled_thumbnail = NULL;
- }
-
- if (pixbuf) {
- if (tried_original) {
- thumb_mtime = file->details->mtime;
- } else {
- thumb_mtime_str = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime");
- if (thumb_mtime_str) {
- thumb_mtime = atol (thumb_mtime_str);
- }
- }
-
- if (thumb_mtime == 0 ||
- thumb_mtime == file->details->mtime) {
- file->details->thumbnail = g_object_ref (pixbuf);
- file->details->thumbnail_mtime = thumb_mtime;
- } else {
- g_free (file->details->thumbnail_path);
- file->details->thumbnail_path = NULL;
- }
- }
-
- nautilus_directory_async_state_changed (directory);
+ NautilusFile *file,
+ GdkPixbuf *pixbuf,
+ gboolean tried_original)
+{
+ const char *thumb_mtime_str;
+ time_t thumb_mtime = 0;
+
+ file->details->thumbnail_is_up_to_date = TRUE;
+ file->details->thumbnail_tried_original = tried_original;
+ if (file->details->thumbnail)
+ {
+ g_object_unref (file->details->thumbnail);
+ file->details->thumbnail = NULL;
+ }
+ if (file->details->scaled_thumbnail)
+ {
+ g_object_unref (file->details->scaled_thumbnail);
+ file->details->scaled_thumbnail = NULL;
+ }
+
+ if (pixbuf)
+ {
+ if (tried_original)
+ {
+ thumb_mtime = file->details->mtime;
+ }
+ else
+ {
+ thumb_mtime_str = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime");
+ if (thumb_mtime_str)
+ {
+ thumb_mtime = atol (thumb_mtime_str);
+ }
+ }
+
+ if (thumb_mtime == 0 ||
+ thumb_mtime == file->details->mtime)
+ {
+ file->details->thumbnail = g_object_ref (pixbuf);
+ file->details->thumbnail_mtime = thumb_mtime;
+ }
+ else
+ {
+ g_free (file->details->thumbnail_path);
+ file->details->thumbnail_path = NULL;
+ }
+ }
+
+ nautilus_directory_async_state_changed (directory);
}
static void
thumbnail_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->thumbnail_state != NULL) {
- file = directory->details->thumbnail_state->file;
+ if (directory->details->thumbnail_state != NULL)
+ {
+ file = directory->details->thumbnail_state->file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- lacks_thumbnail,
- REQUEST_THUMBNAIL)) {
- return;
- }
- }
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ lacks_thumbnail,
+ REQUEST_THUMBNAIL))
+ {
+ return;
+ }
+ }
- /* The link info is not wanted, so stop it. */
- thumbnail_cancel (directory);
- }
+ /* The link info is not wanted, so stop it. */
+ thumbnail_cancel (directory);
+ }
}
static void
thumbnail_got_pixbuf (NautilusDirectory *directory,
- NautilusFile *file,
- GdkPixbuf *pixbuf,
- gboolean tried_original)
+ NautilusFile *file,
+ GdkPixbuf *pixbuf,
+ gboolean tried_original)
{
- nautilus_directory_ref (directory);
+ nautilus_directory_ref (directory);
- nautilus_file_ref (file);
- thumbnail_done (directory, file, pixbuf, tried_original);
- nautilus_file_changed (file);
- nautilus_file_unref (file);
-
- if (pixbuf) {
- g_object_unref (pixbuf);
- }
+ nautilus_file_ref (file);
+ thumbnail_done (directory, file, pixbuf, tried_original);
+ nautilus_file_changed (file);
+ nautilus_file_unref (file);
- nautilus_directory_unref (directory);
+ if (pixbuf)
+ {
+ g_object_unref (pixbuf);
+ }
+
+ nautilus_directory_unref (directory);
}
static void
thumbnail_state_free (ThumbnailState *state)
{
- g_object_unref (state->cancellable);
- g_free (state);
+ g_object_unref (state->cancellable);
+ g_free (state);
}
extern int cached_thumbnail_size;
@@ -3550,733 +3939,806 @@ extern int cached_thumbnail_size;
/* scale very large images down to the max. size we need */
static void
thumbnail_loader_size_prepared (GdkPixbufLoader *loader,
- int width,
- int height,
- gpointer user_data)
-{
- int max_thumbnail_size;
- double aspect_ratio;
-
- aspect_ratio = ((double) width) / height;
-
- /* cf. nautilus_file_get_icon() */
- max_thumbnail_size = NAUTILUS_CANVAS_ICON_SIZE_LARGER * cached_thumbnail_size / NAUTILUS_CANVAS_ICON_SIZE_SMALL;
- if (MAX (width, height) > max_thumbnail_size) {
- if (width > height) {
- width = max_thumbnail_size;
- height = width / aspect_ratio;
- } else {
- height = max_thumbnail_size;
- width = height * aspect_ratio;
- }
-
- gdk_pixbuf_loader_set_size (loader, width, height);
- }
+ int width,
+ int height,
+ gpointer user_data)
+{
+ int max_thumbnail_size;
+ double aspect_ratio;
+
+ aspect_ratio = ((double) width) / height;
+
+ /* cf. nautilus_file_get_icon() */
+ max_thumbnail_size = NAUTILUS_CANVAS_ICON_SIZE_LARGER * cached_thumbnail_size / NAUTILUS_CANVAS_ICON_SIZE_SMALL;
+ if (MAX (width, height) > max_thumbnail_size)
+ {
+ if (width > height)
+ {
+ width = max_thumbnail_size;
+ height = width / aspect_ratio;
+ }
+ else
+ {
+ height = max_thumbnail_size;
+ width = height * aspect_ratio;
+ }
+
+ gdk_pixbuf_loader_set_size (loader, width, height);
+ }
}
static GdkPixbuf *
-get_pixbuf_for_content (goffset file_len,
- char *file_contents)
-{
- gboolean res;
- GdkPixbuf *pixbuf, *pixbuf2;
- GdkPixbufLoader *loader;
- gsize chunk_len;
- pixbuf = NULL;
-
- loader = gdk_pixbuf_loader_new ();
- g_signal_connect (loader, "size-prepared",
- G_CALLBACK (thumbnail_loader_size_prepared),
- NULL);
-
- /* For some reason we have to write in chunks, or gdk-pixbuf fails */
- res = TRUE;
- while (res && file_len > 0) {
- chunk_len = file_len;
- res = gdk_pixbuf_loader_write (loader, (guchar *) file_contents, chunk_len, NULL);
- file_contents += chunk_len;
- file_len -= chunk_len;
- }
- if (res) {
- res = gdk_pixbuf_loader_close (loader, NULL);
- }
- if (res) {
- pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader));
- }
- g_object_unref (G_OBJECT (loader));
-
- if (pixbuf) {
- pixbuf2 = gdk_pixbuf_apply_embedded_orientation (pixbuf);
- g_object_unref (pixbuf);
- pixbuf = pixbuf2;
- }
- return pixbuf;
+get_pixbuf_for_content (goffset file_len,
+ char *file_contents)
+{
+ gboolean res;
+ GdkPixbuf *pixbuf, *pixbuf2;
+ GdkPixbufLoader *loader;
+ gsize chunk_len;
+ pixbuf = NULL;
+
+ loader = gdk_pixbuf_loader_new ();
+ g_signal_connect (loader, "size-prepared",
+ G_CALLBACK (thumbnail_loader_size_prepared),
+ NULL);
+
+ /* For some reason we have to write in chunks, or gdk-pixbuf fails */
+ res = TRUE;
+ while (res && file_len > 0)
+ {
+ chunk_len = file_len;
+ res = gdk_pixbuf_loader_write (loader, (guchar *) file_contents, chunk_len, NULL);
+ file_contents += chunk_len;
+ file_len -= chunk_len;
+ }
+ if (res)
+ {
+ res = gdk_pixbuf_loader_close (loader, NULL);
+ }
+ if (res)
+ {
+ pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader));
+ }
+ g_object_unref (G_OBJECT (loader));
+
+ if (pixbuf)
+ {
+ pixbuf2 = gdk_pixbuf_apply_embedded_orientation (pixbuf);
+ g_object_unref (pixbuf);
+ pixbuf = pixbuf2;
+ }
+ return pixbuf;
}
static void
-thumbnail_read_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- ThumbnailState *state;
- gsize file_size;
- char *file_contents;
- gboolean result;
- NautilusDirectory *directory;
- GdkPixbuf *pixbuf;
- GFile *location;
-
- state = user_data;
-
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- thumbnail_state_free (state);
- return;
- }
-
- directory = nautilus_directory_ref (state->directory);
-
- result = g_file_load_contents_finish (G_FILE (source_object),
- res,
- &file_contents, &file_size,
- NULL, NULL);
-
- pixbuf = NULL;
- if (result) {
- pixbuf = get_pixbuf_for_content (file_size, file_contents);
- g_free (file_contents);
- }
-
- if (pixbuf == NULL && state->trying_original) {
- state->trying_original = FALSE;
-
- location = g_file_new_for_path (state->file->details->thumbnail_path);
- g_file_load_contents_async (location,
- state->cancellable,
- thumbnail_read_callback,
- state);
- g_object_unref (location);
- } else {
- state->directory->details->thumbnail_state = NULL;
- async_job_end (state->directory, "thumbnail");
-
- thumbnail_got_pixbuf (state->directory, state->file, pixbuf, state->tried_original);
-
- thumbnail_state_free (state);
- }
-
- nautilus_directory_unref (directory);
+thumbnail_read_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ThumbnailState *state;
+ gsize file_size;
+ char *file_contents;
+ gboolean result;
+ NautilusDirectory *directory;
+ GdkPixbuf *pixbuf;
+ GFile *location;
+
+ state = user_data;
+
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ thumbnail_state_free (state);
+ return;
+ }
+
+ directory = nautilus_directory_ref (state->directory);
+
+ result = g_file_load_contents_finish (G_FILE (source_object),
+ res,
+ &file_contents, &file_size,
+ NULL, NULL);
+
+ pixbuf = NULL;
+ if (result)
+ {
+ pixbuf = get_pixbuf_for_content (file_size, file_contents);
+ g_free (file_contents);
+ }
+
+ if (pixbuf == NULL && state->trying_original)
+ {
+ state->trying_original = FALSE;
+
+ location = g_file_new_for_path (state->file->details->thumbnail_path);
+ g_file_load_contents_async (location,
+ state->cancellable,
+ thumbnail_read_callback,
+ state);
+ g_object_unref (location);
+ }
+ else
+ {
+ state->directory->details->thumbnail_state = NULL;
+ async_job_end (state->directory, "thumbnail");
+
+ thumbnail_got_pixbuf (state->directory, state->file, pixbuf, state->tried_original);
+
+ thumbnail_state_free (state);
+ }
+
+ nautilus_directory_unref (directory);
}
static void
thumbnail_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- GFile *location;
- ThumbnailState *state;
-
- if (directory->details->thumbnail_state != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file,
- lacks_thumbnail,
- REQUEST_THUMBNAIL)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!async_job_start (directory, "thumbnail")) {
- return;
- }
-
- state = g_new0 (ThumbnailState, 1);
- state->directory = directory;
- state->file = file;
- state->cancellable = g_cancellable_new ();
-
- if (file->details->thumbnail_wants_original) {
- state->tried_original = TRUE;
- state->trying_original = TRUE;
- location = nautilus_file_get_location (file);
- } else {
- location = g_file_new_for_path (file->details->thumbnail_path);
- }
-
- directory->details->thumbnail_state = state;
-
- g_file_load_contents_async (location,
- state->cancellable,
- thumbnail_read_callback,
- state);
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ GFile *location;
+ ThumbnailState *state;
+
+ if (directory->details->thumbnail_state != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file,
+ lacks_thumbnail,
+ REQUEST_THUMBNAIL))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!async_job_start (directory, "thumbnail"))
+ {
+ return;
+ }
+
+ state = g_new0 (ThumbnailState, 1);
+ state->directory = directory;
+ state->file = file;
+ state->cancellable = g_cancellable_new ();
+
+ if (file->details->thumbnail_wants_original)
+ {
+ state->tried_original = TRUE;
+ state->trying_original = TRUE;
+ location = nautilus_file_get_location (file);
+ }
+ else
+ {
+ location = g_file_new_for_path (file->details->thumbnail_path);
+ }
+
+ directory->details->thumbnail_state = state;
+
+ g_file_load_contents_async (location,
+ state->cancellable,
+ thumbnail_read_callback,
+ state);
+ g_object_unref (location);
}
static void
mount_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->mount_state != NULL) {
- file = directory->details->mount_state->file;
+ if (directory->details->mount_state != NULL)
+ {
+ file = directory->details->mount_state->file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- lacks_mount,
- REQUEST_MOUNT)) {
- return;
- }
- }
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ lacks_mount,
+ REQUEST_MOUNT))
+ {
+ return;
+ }
+ }
- /* The link info is not wanted, so stop it. */
- mount_cancel (directory);
- }
+ /* The link info is not wanted, so stop it. */
+ mount_cancel (directory);
+ }
}
static void
mount_state_free (MountState *state)
{
- g_object_unref (state->cancellable);
- g_free (state);
+ g_object_unref (state->cancellable);
+ g_free (state);
}
static void
-got_mount (MountState *state, GMount *mount)
+got_mount (MountState *state,
+ GMount *mount)
{
- NautilusDirectory *directory;
- NautilusFile *file;
-
- directory = nautilus_directory_ref (state->directory);
+ NautilusDirectory *directory;
+ NautilusFile *file;
+
+ directory = nautilus_directory_ref (state->directory);
- state->directory->details->mount_state = NULL;
- async_job_end (state->directory, "mount");
-
- file = nautilus_file_ref (state->file);
+ state->directory->details->mount_state = NULL;
+ async_job_end (state->directory, "mount");
- file->details->mount_is_up_to_date = TRUE;
- nautilus_file_set_mount (file, mount);
+ file = nautilus_file_ref (state->file);
- nautilus_directory_async_state_changed (directory);
- nautilus_file_changed (file);
-
- nautilus_file_unref (file);
-
- nautilus_directory_unref (directory);
-
- mount_state_free (state);
+ file->details->mount_is_up_to_date = TRUE;
+ nautilus_file_set_mount (file, mount);
+ nautilus_directory_async_state_changed (directory);
+ nautilus_file_changed (file);
+
+ nautilus_file_unref (file);
+
+ nautilus_directory_unref (directory);
+
+ mount_state_free (state);
}
static void
-find_enclosing_mount_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- GMount *mount;
- MountState *state;
- GFile *location, *root;
-
- state = user_data;
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- mount_state_free (state);
- return;
- }
-
- mount = g_file_find_enclosing_mount_finish (G_FILE (source_object),
- res, NULL);
-
- if (mount) {
- root = g_mount_get_root (mount);
- location = nautilus_file_get_location (state->file);
- if (!g_file_equal (location, root)) {
- g_object_unref (mount);
- mount = NULL;
- }
- g_object_unref (root);
- g_object_unref (location);
- }
-
- got_mount (state, mount);
-
- if (mount) {
- g_object_unref (mount);
- }
+find_enclosing_mount_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GMount *mount;
+ MountState *state;
+ GFile *location, *root;
+
+ state = user_data;
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ mount_state_free (state);
+ return;
+ }
+
+ mount = g_file_find_enclosing_mount_finish (G_FILE (source_object),
+ res, NULL);
+
+ if (mount)
+ {
+ root = g_mount_get_root (mount);
+ location = nautilus_file_get_location (state->file);
+ if (!g_file_equal (location, root))
+ {
+ g_object_unref (mount);
+ mount = NULL;
+ }
+ g_object_unref (root);
+ g_object_unref (location);
+ }
+
+ got_mount (state, mount);
+
+ if (mount)
+ {
+ g_object_unref (mount);
+ }
}
static GMount *
get_mount_at (GFile *target)
{
- GVolumeMonitor *monitor;
- GFile *root;
- GList *mounts, *l;
- GMount *found;
-
- monitor = g_volume_monitor_get ();
- mounts = g_volume_monitor_get_mounts (monitor);
+ GVolumeMonitor *monitor;
+ GFile *root;
+ GList *mounts, *l;
+ GMount *found;
+
+ monitor = g_volume_monitor_get ();
+ mounts = g_volume_monitor_get_mounts (monitor);
+
+ found = NULL;
+ for (l = mounts; l != NULL; l = l->next)
+ {
+ GMount *mount = G_MOUNT (l->data);
+
+ if (g_mount_is_shadowed (mount))
+ {
+ continue;
+ }
- found = NULL;
- for (l = mounts; l != NULL; l = l->next) {
- GMount *mount = G_MOUNT (l->data);
+ root = g_mount_get_root (mount);
- if (g_mount_is_shadowed (mount))
- continue;
+ if (g_file_equal (target, root))
+ {
+ found = g_object_ref (mount);
+ break;
+ }
- root = g_mount_get_root (mount);
+ g_object_unref (root);
+ }
- if (g_file_equal (target, root)) {
- found = g_object_ref (mount);
- break;
- }
-
- g_object_unref (root);
- }
+ g_list_free_full (mounts, g_object_unref);
- g_list_free_full (mounts, g_object_unref);
-
- g_object_unref (monitor);
+ g_object_unref (monitor);
- return found;
+ return found;
}
static void
mount_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- GFile *location;
- MountState *state;
-
- if (directory->details->mount_state != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file,
- lacks_mount,
- REQUEST_MOUNT)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!async_job_start (directory, "mount")) {
- return;
- }
-
- state = g_new0 (MountState, 1);
- state->directory = directory;
- state->file = file;
- state->cancellable = g_cancellable_new ();
-
- location = nautilus_file_get_location (file);
-
- directory->details->mount_state = state;
-
- if (file->details->type == G_FILE_TYPE_MOUNTABLE) {
- GFile *target;
- GMount *mount;
-
- mount = NULL;
- target = nautilus_file_get_activation_location (file);
- if (target != NULL) {
- mount = get_mount_at (target);
- g_object_unref (target);
- }
-
- got_mount (state, mount);
-
- if (mount) {
- g_object_unref (mount);
- }
- } else {
- g_file_find_enclosing_mount_async (location,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- find_enclosing_mount_callback,
- state);
- }
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ GFile *location;
+ MountState *state;
+
+ if (directory->details->mount_state != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file,
+ lacks_mount,
+ REQUEST_MOUNT))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!async_job_start (directory, "mount"))
+ {
+ return;
+ }
+
+ state = g_new0 (MountState, 1);
+ state->directory = directory;
+ state->file = file;
+ state->cancellable = g_cancellable_new ();
+
+ location = nautilus_file_get_location (file);
+
+ directory->details->mount_state = state;
+
+ if (file->details->type == G_FILE_TYPE_MOUNTABLE)
+ {
+ GFile *target;
+ GMount *mount;
+
+ mount = NULL;
+ target = nautilus_file_get_activation_location (file);
+ if (target != NULL)
+ {
+ mount = get_mount_at (target);
+ g_object_unref (target);
+ }
+
+ got_mount (state, mount);
+
+ if (mount)
+ {
+ g_object_unref (mount);
+ }
+ }
+ else
+ {
+ g_file_find_enclosing_mount_async (location,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ find_enclosing_mount_callback,
+ state);
+ }
+ g_object_unref (location);
}
static void
filesystem_info_cancel (NautilusDirectory *directory)
{
- if (directory->details->filesystem_info_state != NULL) {
- g_cancellable_cancel (directory->details->filesystem_info_state->cancellable);
- directory->details->filesystem_info_state->directory = NULL;
- directory->details->filesystem_info_state = NULL;
- async_job_end (directory, "filesystem info");
- }
+ if (directory->details->filesystem_info_state != NULL)
+ {
+ g_cancellable_cancel (directory->details->filesystem_info_state->cancellable);
+ directory->details->filesystem_info_state->directory = NULL;
+ directory->details->filesystem_info_state = NULL;
+ async_job_end (directory, "filesystem info");
+ }
}
static void
filesystem_info_stop (NautilusDirectory *directory)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (directory->details->filesystem_info_state != NULL) {
- file = directory->details->filesystem_info_state->file;
+ if (directory->details->filesystem_info_state != NULL)
+ {
+ file = directory->details->filesystem_info_state->file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file,
- lacks_filesystem_info,
- REQUEST_FILESYSTEM_INFO)) {
- return;
- }
- }
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file,
+ lacks_filesystem_info,
+ REQUEST_FILESYSTEM_INFO))
+ {
+ return;
+ }
+ }
- /* The filesystem info is not wanted, so stop it. */
- filesystem_info_cancel (directory);
- }
+ /* The filesystem info is not wanted, so stop it. */
+ filesystem_info_cancel (directory);
+ }
}
static void
filesystem_info_state_free (FilesystemInfoState *state)
{
- g_object_unref (state->cancellable);
- g_free (state);
+ g_object_unref (state->cancellable);
+ g_free (state);
}
static void
-got_filesystem_info (FilesystemInfoState *state, GFileInfo *info)
-{
- NautilusDirectory *directory;
- NautilusFile *file;
- const char *filesystem_type;
-
- /* careful here, info may be NULL */
-
- directory = nautilus_directory_ref (state->directory);
-
- state->directory->details->filesystem_info_state = NULL;
- async_job_end (state->directory, "filesystem info");
-
- file = nautilus_file_ref (state->file);
-
- file->details->filesystem_info_is_up_to_date = TRUE;
- if (info != NULL) {
- file->details->filesystem_use_preview =
- g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW);
- file->details->filesystem_readonly =
- g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
- filesystem_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
- if (g_strcmp0 (eel_ref_str_peek (file->details->filesystem_type), filesystem_type) != 0) {
- eel_ref_str_unref (file->details->filesystem_type);
- file->details->filesystem_type = eel_ref_str_get_unique (filesystem_type);
- }
- }
-
- nautilus_directory_async_state_changed (directory);
- nautilus_file_changed (file);
-
- nautilus_file_unref (file);
-
- nautilus_directory_unref (directory);
-
- filesystem_info_state_free (state);
+got_filesystem_info (FilesystemInfoState *state,
+ GFileInfo *info)
+{
+ NautilusDirectory *directory;
+ NautilusFile *file;
+ const char *filesystem_type;
+
+ /* careful here, info may be NULL */
+
+ directory = nautilus_directory_ref (state->directory);
+
+ state->directory->details->filesystem_info_state = NULL;
+ async_job_end (state->directory, "filesystem info");
+
+ file = nautilus_file_ref (state->file);
+
+ file->details->filesystem_info_is_up_to_date = TRUE;
+ if (info != NULL)
+ {
+ file->details->filesystem_use_preview =
+ g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW);
+ file->details->filesystem_readonly =
+ g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_FILESYSTEM_READONLY);
+ filesystem_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
+ if (g_strcmp0 (eel_ref_str_peek (file->details->filesystem_type), filesystem_type) != 0)
+ {
+ eel_ref_str_unref (file->details->filesystem_type);
+ file->details->filesystem_type = eel_ref_str_get_unique (filesystem_type);
+ }
+ }
+
+ nautilus_directory_async_state_changed (directory);
+ nautilus_file_changed (file);
+
+ nautilus_file_unref (file);
+
+ nautilus_directory_unref (directory);
+
+ filesystem_info_state_free (state);
}
static void
-query_filesystem_info_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+query_filesystem_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GFileInfo *info;
- FilesystemInfoState *state;
+ GFileInfo *info;
+ FilesystemInfoState *state;
- state = user_data;
- if (state->directory == NULL) {
- /* Operation was cancelled. Bail out */
- filesystem_info_state_free (state);
- return;
- }
+ state = user_data;
+ if (state->directory == NULL)
+ {
+ /* Operation was cancelled. Bail out */
+ filesystem_info_state_free (state);
+ return;
+ }
- info = g_file_query_filesystem_info_finish (G_FILE (source_object), res, NULL);
+ info = g_file_query_filesystem_info_finish (G_FILE (source_object), res, NULL);
- got_filesystem_info (state, info);
+ got_filesystem_info (state, info);
- if (info != NULL) {
- g_object_unref (info);
- }
+ if (info != NULL)
+ {
+ g_object_unref (info);
+ }
}
static void
filesystem_info_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- GFile *location;
- FilesystemInfoState *state;
-
- if (directory->details->filesystem_info_state != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file,
- lacks_filesystem_info,
- REQUEST_FILESYSTEM_INFO)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!async_job_start (directory, "filesystem info")) {
- return;
- }
-
- state = g_new0 (FilesystemInfoState, 1);
- state->directory = directory;
- state->file = file;
- state->cancellable = g_cancellable_new ();
-
- location = nautilus_file_get_location (file);
-
- directory->details->filesystem_info_state = state;
-
- g_file_query_filesystem_info_async (location,
- G_FILE_ATTRIBUTE_FILESYSTEM_READONLY ","
- G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW ","
- G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
- G_PRIORITY_DEFAULT,
- state->cancellable,
- query_filesystem_info_callback,
- state);
- g_object_unref (location);
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ GFile *location;
+ FilesystemInfoState *state;
+
+ if (directory->details->filesystem_info_state != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file,
+ lacks_filesystem_info,
+ REQUEST_FILESYSTEM_INFO))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!async_job_start (directory, "filesystem info"))
+ {
+ return;
+ }
+
+ state = g_new0 (FilesystemInfoState, 1);
+ state->directory = directory;
+ state->file = file;
+ state->cancellable = g_cancellable_new ();
+
+ location = nautilus_file_get_location (file);
+
+ directory->details->filesystem_info_state = state;
+
+ g_file_query_filesystem_info_async (location,
+ G_FILE_ATTRIBUTE_FILESYSTEM_READONLY ","
+ G_FILE_ATTRIBUTE_FILESYSTEM_USE_PREVIEW ","
+ G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
+ G_PRIORITY_DEFAULT,
+ state->cancellable,
+ query_filesystem_info_callback,
+ state);
+ g_object_unref (location);
}
static void
extension_info_cancel (NautilusDirectory *directory)
{
- if (directory->details->extension_info_in_progress != NULL) {
- if (directory->details->extension_info_idle) {
- g_source_remove (directory->details->extension_info_idle);
- } else {
- nautilus_info_provider_cancel_update
- (directory->details->extension_info_provider,
- directory->details->extension_info_in_progress);
- }
+ if (directory->details->extension_info_in_progress != NULL)
+ {
+ if (directory->details->extension_info_idle)
+ {
+ g_source_remove (directory->details->extension_info_idle);
+ }
+ else
+ {
+ nautilus_info_provider_cancel_update
+ (directory->details->extension_info_provider,
+ directory->details->extension_info_in_progress);
+ }
- directory->details->extension_info_in_progress = NULL;
- directory->details->extension_info_file = NULL;
- directory->details->extension_info_provider = NULL;
- directory->details->extension_info_idle = 0;
+ directory->details->extension_info_in_progress = NULL;
+ directory->details->extension_info_file = NULL;
+ directory->details->extension_info_provider = NULL;
+ directory->details->extension_info_idle = 0;
- async_job_end (directory, "extension info");
- }
+ async_job_end (directory, "extension info");
+ }
}
-
+
static void
extension_info_stop (NautilusDirectory *directory)
{
- if (directory->details->extension_info_in_progress != NULL) {
- NautilusFile *file;
+ if (directory->details->extension_info_in_progress != NULL)
+ {
+ NautilusFile *file;
- file = directory->details->extension_info_file;
- if (file != NULL) {
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->directory == directory);
- if (is_needy (file, lacks_extension_info, REQUEST_EXTENSION_INFO)) {
- return;
- }
- }
+ file = directory->details->extension_info_file;
+ if (file != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->directory == directory);
+ if (is_needy (file, lacks_extension_info, REQUEST_EXTENSION_INFO))
+ {
+ return;
+ }
+ }
- /* The info is not wanted, so stop it. */
- extension_info_cancel (directory);
- }
+ /* The info is not wanted, so stop it. */
+ extension_info_cancel (directory);
+ }
}
static void
-finish_info_provider (NautilusDirectory *directory,
- NautilusFile *file,
- NautilusInfoProvider *provider)
+finish_info_provider (NautilusDirectory *directory,
+ NautilusFile *file,
+ NautilusInfoProvider *provider)
{
- file->details->pending_info_providers =
- g_list_remove (file->details->pending_info_providers,
- provider);
- g_object_unref (provider);
+ file->details->pending_info_providers =
+ g_list_remove (file->details->pending_info_providers,
+ provider);
+ g_object_unref (provider);
- nautilus_directory_async_state_changed (directory);
+ nautilus_directory_async_state_changed (directory);
- if (file->details->pending_info_providers == NULL) {
- nautilus_file_info_providers_done (file);
- }
+ if (file->details->pending_info_providers == NULL)
+ {
+ nautilus_file_info_providers_done (file);
+ }
}
static gboolean
info_provider_idle_callback (gpointer user_data)
{
- InfoProviderResponse *response;
- NautilusDirectory *directory;
+ InfoProviderResponse *response;
+ NautilusDirectory *directory;
- response = user_data;
- directory = response->directory;
+ response = user_data;
+ directory = response->directory;
- if (response->handle != directory->details->extension_info_in_progress
- || response->provider != directory->details->extension_info_provider) {
- g_warning ("Unexpected plugin response. This probably indicates a bug in a Nautilus extension: handle=%p", response->handle);
- } else {
- NautilusFile *file;
- async_job_end (directory, "extension info");
+ if (response->handle != directory->details->extension_info_in_progress
+ || response->provider != directory->details->extension_info_provider)
+ {
+ g_warning ("Unexpected plugin response. This probably indicates a bug in a Nautilus extension: handle=%p", response->handle);
+ }
+ else
+ {
+ NautilusFile *file;
+ async_job_end (directory, "extension info");
- file = directory->details->extension_info_file;
+ file = directory->details->extension_info_file;
- directory->details->extension_info_file = NULL;
- directory->details->extension_info_provider = NULL;
- directory->details->extension_info_in_progress = NULL;
- directory->details->extension_info_idle = 0;
-
- finish_info_provider (directory, file, response->provider);
- }
+ directory->details->extension_info_file = NULL;
+ directory->details->extension_info_provider = NULL;
+ directory->details->extension_info_in_progress = NULL;
+ directory->details->extension_info_idle = 0;
- return FALSE;
+ finish_info_provider (directory, file, response->provider);
+ }
+
+ return FALSE;
}
static void
-info_provider_callback (NautilusInfoProvider *provider,
- NautilusOperationHandle *handle,
- NautilusOperationResult result,
- gpointer user_data)
+info_provider_callback (NautilusInfoProvider *provider,
+ NautilusOperationHandle *handle,
+ NautilusOperationResult result,
+ gpointer user_data)
{
- InfoProviderResponse *response;
-
- response = g_new0 (InfoProviderResponse, 1);
- response->provider = provider;
- response->handle = handle;
- response->result = result;
- response->directory = NAUTILUS_DIRECTORY (user_data);
+ InfoProviderResponse *response;
+
+ response = g_new0 (InfoProviderResponse, 1);
+ response->provider = provider;
+ response->handle = handle;
+ response->result = result;
+ response->directory = NAUTILUS_DIRECTORY (user_data);
- response->directory->details->extension_info_idle =
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
- info_provider_idle_callback, response,
- g_free);
+ response->directory->details->extension_info_idle =
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ info_provider_idle_callback, response,
+ g_free);
}
static void
extension_info_start (NautilusDirectory *directory,
- NautilusFile *file,
- gboolean *doing_io)
-{
- NautilusInfoProvider *provider;
- NautilusOperationResult result;
- NautilusOperationHandle *handle;
- GClosure *update_complete;
-
- if (directory->details->extension_info_in_progress != NULL) {
- *doing_io = TRUE;
- return;
- }
-
- if (!is_needy (file, lacks_extension_info, REQUEST_EXTENSION_INFO)) {
- return;
- }
- *doing_io = TRUE;
-
- if (!async_job_start (directory, "extension info")) {
- return;
- }
-
- provider = file->details->pending_info_providers->data;
-
- update_complete = g_cclosure_new (G_CALLBACK (info_provider_callback),
- directory,
- NULL);
- g_closure_set_marshal (update_complete,
- g_cclosure_marshal_generic);
-
- result = nautilus_info_provider_update_file_info
- (provider,
- NAUTILUS_FILE_INFO (file),
- update_complete,
- &handle);
-
- g_closure_unref (update_complete);
-
- if (result == NAUTILUS_OPERATION_COMPLETE ||
- result == NAUTILUS_OPERATION_FAILED) {
- finish_info_provider (directory, file, provider);
- async_job_end (directory, "extension info");
- } else {
- directory->details->extension_info_in_progress = handle;
- directory->details->extension_info_provider = provider;
- directory->details->extension_info_file = file;
- }
+ NautilusFile *file,
+ gboolean *doing_io)
+{
+ NautilusInfoProvider *provider;
+ NautilusOperationResult result;
+ NautilusOperationHandle *handle;
+ GClosure *update_complete;
+
+ if (directory->details->extension_info_in_progress != NULL)
+ {
+ *doing_io = TRUE;
+ return;
+ }
+
+ if (!is_needy (file, lacks_extension_info, REQUEST_EXTENSION_INFO))
+ {
+ return;
+ }
+ *doing_io = TRUE;
+
+ if (!async_job_start (directory, "extension info"))
+ {
+ return;
+ }
+
+ provider = file->details->pending_info_providers->data;
+
+ update_complete = g_cclosure_new (G_CALLBACK (info_provider_callback),
+ directory,
+ NULL);
+ g_closure_set_marshal (update_complete,
+ g_cclosure_marshal_generic);
+
+ result = nautilus_info_provider_update_file_info
+ (provider,
+ NAUTILUS_FILE_INFO (file),
+ update_complete,
+ &handle);
+
+ g_closure_unref (update_complete);
+
+ if (result == NAUTILUS_OPERATION_COMPLETE ||
+ result == NAUTILUS_OPERATION_FAILED)
+ {
+ finish_info_provider (directory, file, provider);
+ async_job_end (directory, "extension info");
+ }
+ else
+ {
+ directory->details->extension_info_in_progress = handle;
+ directory->details->extension_info_provider = provider;
+ directory->details->extension_info_file = file;
+ }
}
static void
start_or_stop_io (NautilusDirectory *directory)
{
- NautilusFile *file;
- gboolean doing_io;
-
- /* Start or stop reading files. */
- file_list_start_or_stop (directory);
-
- /* Stop any no longer wanted attribute fetches. */
- file_info_stop (directory);
- directory_count_stop (directory);
- deep_count_stop (directory);
- mime_list_stop (directory);
- link_info_stop (directory);
- extension_info_stop (directory);
- mount_stop (directory);
- thumbnail_stop (directory);
- filesystem_info_stop (directory);
-
- doing_io = FALSE;
- /* Take files that are all done off the queue. */
- while (!nautilus_file_queue_is_empty (directory->details->high_priority_queue)) {
- file = nautilus_file_queue_head (directory->details->high_priority_queue);
-
- /* Start getting attributes if possible */
- file_info_start (directory, file, &doing_io);
- link_info_start (directory, file, &doing_io);
-
- if (doing_io) {
- return;
- }
-
- move_file_to_low_priority_queue (directory, file);
- }
-
- /* High priority queue must be empty */
- while (!nautilus_file_queue_is_empty (directory->details->low_priority_queue)) {
- file = nautilus_file_queue_head (directory->details->low_priority_queue);
-
- /* Start getting attributes if possible */
- mount_start (directory, file, &doing_io);
- directory_count_start (directory, file, &doing_io);
- deep_count_start (directory, file, &doing_io);
- mime_list_start (directory, file, &doing_io);
- thumbnail_start (directory, file, &doing_io);
- filesystem_info_start (directory, file, &doing_io);
-
- if (doing_io) {
- return;
- }
-
- move_file_to_extension_queue (directory, file);
- }
-
- /* Low priority queue must be empty */
- while (!nautilus_file_queue_is_empty (directory->details->extension_queue)) {
- file = nautilus_file_queue_head (directory->details->extension_queue);
-
- /* Start getting attributes if possible */
- extension_info_start (directory, file, &doing_io);
- if (doing_io) {
- return;
- }
-
- nautilus_directory_remove_file_from_work_queue (directory, file);
- }
+ NautilusFile *file;
+ gboolean doing_io;
+
+ /* Start or stop reading files. */
+ file_list_start_or_stop (directory);
+
+ /* Stop any no longer wanted attribute fetches. */
+ file_info_stop (directory);
+ directory_count_stop (directory);
+ deep_count_stop (directory);
+ mime_list_stop (directory);
+ link_info_stop (directory);
+ extension_info_stop (directory);
+ mount_stop (directory);
+ thumbnail_stop (directory);
+ filesystem_info_stop (directory);
+
+ doing_io = FALSE;
+ /* Take files that are all done off the queue. */
+ while (!nautilus_file_queue_is_empty (directory->details->high_priority_queue))
+ {
+ file = nautilus_file_queue_head (directory->details->high_priority_queue);
+
+ /* Start getting attributes if possible */
+ file_info_start (directory, file, &doing_io);
+ link_info_start (directory, file, &doing_io);
+
+ if (doing_io)
+ {
+ return;
+ }
+
+ move_file_to_low_priority_queue (directory, file);
+ }
+
+ /* High priority queue must be empty */
+ while (!nautilus_file_queue_is_empty (directory->details->low_priority_queue))
+ {
+ file = nautilus_file_queue_head (directory->details->low_priority_queue);
+
+ /* Start getting attributes if possible */
+ mount_start (directory, file, &doing_io);
+ directory_count_start (directory, file, &doing_io);
+ deep_count_start (directory, file, &doing_io);
+ mime_list_start (directory, file, &doing_io);
+ thumbnail_start (directory, file, &doing_io);
+ filesystem_info_start (directory, file, &doing_io);
+
+ if (doing_io)
+ {
+ return;
+ }
+
+ move_file_to_extension_queue (directory, file);
+ }
+
+ /* Low priority queue must be empty */
+ while (!nautilus_file_queue_is_empty (directory->details->extension_queue))
+ {
+ file = nautilus_file_queue_head (directory->details->extension_queue);
+
+ /* Start getting attributes if possible */
+ extension_info_start (directory, file, &doing_io);
+ if (doing_io)
+ {
+ return;
+ }
+
+ nautilus_directory_remove_file_from_work_queue (directory, file);
+ }
}
/* Call this when the monitor or call when ready list changes,
@@ -4285,274 +4747,305 @@ start_or_stop_io (NautilusDirectory *directory)
void
nautilus_directory_async_state_changed (NautilusDirectory *directory)
{
- /* Check if any callbacks are satisfied and call them if they
- * are. Do this last so that any changes done in start or stop
- * I/O functions immediately (not in callbacks) are taken into
- * consideration. If any callbacks are called, consider the
- * I/O state again so that we can release or cancel I/O that
- * is not longer needed once the callbacks are satisfied.
- */
-
- if (directory->details->in_async_service_loop) {
- directory->details->state_changed = TRUE;
- return;
- }
- directory->details->in_async_service_loop = TRUE;
- nautilus_directory_ref (directory);
- do {
- directory->details->state_changed = FALSE;
- start_or_stop_io (directory);
- if (call_ready_callbacks (directory)) {
- directory->details->state_changed = TRUE;
- }
- } while (directory->details->state_changed);
- directory->details->in_async_service_loop = FALSE;
- nautilus_directory_unref (directory);
-
- /* Check if any directories should wake up. */
- async_job_wake_up ();
+ /* Check if any callbacks are satisfied and call them if they
+ * are. Do this last so that any changes done in start or stop
+ * I/O functions immediately (not in callbacks) are taken into
+ * consideration. If any callbacks are called, consider the
+ * I/O state again so that we can release or cancel I/O that
+ * is not longer needed once the callbacks are satisfied.
+ */
+
+ if (directory->details->in_async_service_loop)
+ {
+ directory->details->state_changed = TRUE;
+ return;
+ }
+ directory->details->in_async_service_loop = TRUE;
+ nautilus_directory_ref (directory);
+ do
+ {
+ directory->details->state_changed = FALSE;
+ start_or_stop_io (directory);
+ if (call_ready_callbacks (directory))
+ {
+ directory->details->state_changed = TRUE;
+ }
+ }
+ while (directory->details->state_changed);
+ directory->details->in_async_service_loop = FALSE;
+ nautilus_directory_unref (directory);
+
+ /* Check if any directories should wake up. */
+ async_job_wake_up ();
}
void
nautilus_directory_cancel (NautilusDirectory *directory)
{
- /* Arbitrary order (kept alphabetical). */
- deep_count_cancel (directory);
- directory_count_cancel (directory);
- file_info_cancel (directory);
- file_list_cancel (directory);
- link_info_cancel (directory);
- mime_list_cancel (directory);
- new_files_cancel (directory);
- extension_info_cancel (directory);
- thumbnail_cancel (directory);
- mount_cancel (directory);
- filesystem_info_cancel (directory);
-
- /* We aren't waiting for anything any more. */
- if (waiting_directories != NULL) {
- g_hash_table_remove (waiting_directories, directory);
- }
-
- /* Check if any directories should wake up. */
- async_job_wake_up ();
+ /* Arbitrary order (kept alphabetical). */
+ deep_count_cancel (directory);
+ directory_count_cancel (directory);
+ file_info_cancel (directory);
+ file_list_cancel (directory);
+ link_info_cancel (directory);
+ mime_list_cancel (directory);
+ new_files_cancel (directory);
+ extension_info_cancel (directory);
+ thumbnail_cancel (directory);
+ mount_cancel (directory);
+ filesystem_info_cancel (directory);
+
+ /* We aren't waiting for anything any more. */
+ if (waiting_directories != NULL)
+ {
+ g_hash_table_remove (waiting_directories, directory);
+ }
+
+ /* Check if any directories should wake up. */
+ async_job_wake_up ();
}
static void
cancel_directory_count_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->count_in_progress != NULL &&
- directory->details->count_in_progress->count_file == file) {
- directory_count_cancel (directory);
- }
+ if (directory->details->count_in_progress != NULL &&
+ directory->details->count_in_progress->count_file == file)
+ {
+ directory_count_cancel (directory);
+ }
}
static void
cancel_deep_counts_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->deep_count_file == file) {
- deep_count_cancel (directory);
- }
+ if (directory->details->deep_count_file == file)
+ {
+ deep_count_cancel (directory);
+ }
}
static void
cancel_mime_list_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->mime_list_in_progress != NULL &&
- directory->details->mime_list_in_progress->mime_list_file == file) {
- mime_list_cancel (directory);
- }
+ if (directory->details->mime_list_in_progress != NULL &&
+ directory->details->mime_list_in_progress->mime_list_file == file)
+ {
+ mime_list_cancel (directory);
+ }
}
static void
cancel_file_info_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->get_info_file == file) {
- file_info_cancel (directory);
- }
+ if (directory->details->get_info_file == file)
+ {
+ file_info_cancel (directory);
+ }
}
static void
cancel_thumbnail_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->thumbnail_state != NULL &&
- directory->details->thumbnail_state->file == file) {
- thumbnail_cancel (directory);
- }
+ if (directory->details->thumbnail_state != NULL &&
+ directory->details->thumbnail_state->file == file)
+ {
+ thumbnail_cancel (directory);
+ }
}
static void
cancel_mount_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->mount_state != NULL &&
- directory->details->mount_state->file == file) {
- mount_cancel (directory);
- }
+ if (directory->details->mount_state != NULL &&
+ directory->details->mount_state->file == file)
+ {
+ mount_cancel (directory);
+ }
}
static void
cancel_filesystem_info_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->filesystem_info_state != NULL &&
- directory->details->filesystem_info_state->file == file) {
- filesystem_info_cancel (directory);
- }
+ if (directory->details->filesystem_info_state != NULL &&
+ directory->details->filesystem_info_state->file == file)
+ {
+ filesystem_info_cancel (directory);
+ }
}
static void
cancel_link_info_for_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (directory->details->link_info_read_state != NULL &&
- directory->details->link_info_read_state->file == file) {
- link_info_cancel (directory);
- }
+ if (directory->details->link_info_read_state != NULL &&
+ directory->details->link_info_read_state->file == file)
+ {
+ link_info_cancel (directory);
+ }
}
static void
-cancel_loading_attributes (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes)
-{
- Request request;
-
- request = nautilus_directory_set_up_request (file_attributes);
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT)) {
- directory_count_cancel (directory);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT)) {
- deep_count_cancel (directory);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
- mime_list_cancel (directory);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
- file_info_cancel (directory);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO)) {
- filesystem_info_cancel (directory);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO)) {
- link_info_cancel (directory);
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_EXTENSION_INFO)) {
- extension_info_cancel (directory);
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL)) {
- thumbnail_cancel (directory);
- }
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT)) {
- mount_cancel (directory);
- }
-
- nautilus_directory_async_state_changed (directory);
+cancel_loading_attributes (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes)
+{
+ Request request;
+
+ request = nautilus_directory_set_up_request (file_attributes);
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT))
+ {
+ directory_count_cancel (directory);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT))
+ {
+ deep_count_cancel (directory);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST))
+ {
+ mime_list_cancel (directory);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO))
+ {
+ file_info_cancel (directory);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO))
+ {
+ filesystem_info_cancel (directory);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO))
+ {
+ link_info_cancel (directory);
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_EXTENSION_INFO))
+ {
+ extension_info_cancel (directory);
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL))
+ {
+ thumbnail_cancel (directory);
+ }
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT))
+ {
+ mount_cancel (directory);
+ }
+
+ nautilus_directory_async_state_changed (directory);
}
void
nautilus_directory_cancel_loading_file_attributes (NautilusDirectory *directory,
- NautilusFile *file,
- NautilusFileAttributes file_attributes)
-{
- Request request;
-
- nautilus_directory_remove_file_from_work_queue (directory, file);
-
- request = nautilus_directory_set_up_request (file_attributes);
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT)) {
- cancel_directory_count_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT)) {
- cancel_deep_counts_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
- cancel_mime_list_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
- cancel_file_info_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO)) {
- cancel_filesystem_info_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO)) {
- cancel_link_info_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL)) {
- cancel_thumbnail_for_file (directory, file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT)) {
- cancel_mount_for_file (directory, file);
- }
-
- nautilus_directory_async_state_changed (directory);
+ NautilusFile *file,
+ NautilusFileAttributes file_attributes)
+{
+ Request request;
+
+ nautilus_directory_remove_file_from_work_queue (directory, file);
+
+ request = nautilus_directory_set_up_request (file_attributes);
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT))
+ {
+ cancel_directory_count_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT))
+ {
+ cancel_deep_counts_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST))
+ {
+ cancel_mime_list_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO))
+ {
+ cancel_file_info_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILESYSTEM_INFO))
+ {
+ cancel_filesystem_info_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO))
+ {
+ cancel_link_info_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL))
+ {
+ cancel_thumbnail_for_file (directory, file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT))
+ {
+ cancel_mount_for_file (directory, file);
+ }
+
+ nautilus_directory_async_state_changed (directory);
}
void
nautilus_directory_add_file_to_work_queue (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- g_return_if_fail (file->details->directory == directory);
+ g_return_if_fail (file->details->directory == directory);
- nautilus_file_queue_enqueue (directory->details->high_priority_queue,
- file);
+ nautilus_file_queue_enqueue (directory->details->high_priority_queue,
+ file);
}
static void
add_all_files_to_work_queue (NautilusDirectory *directory)
{
- GList *node;
- NautilusFile *file;
-
- for (node = directory->details->file_list; node != NULL; node = node->next) {
- file = NAUTILUS_FILE (node->data);
+ GList *node;
+ NautilusFile *file;
+
+ for (node = directory->details->file_list; node != NULL; node = node->next)
+ {
+ file = NAUTILUS_FILE (node->data);
- nautilus_directory_add_file_to_work_queue (directory, file);
- }
+ nautilus_directory_add_file_to_work_queue (directory, file);
+ }
}
void
nautilus_directory_remove_file_from_work_queue (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- nautilus_file_queue_remove (directory->details->high_priority_queue,
- file);
- nautilus_file_queue_remove (directory->details->low_priority_queue,
- file);
- nautilus_file_queue_remove (directory->details->extension_queue,
- file);
+ nautilus_file_queue_remove (directory->details->high_priority_queue,
+ file);
+ nautilus_file_queue_remove (directory->details->low_priority_queue,
+ file);
+ nautilus_file_queue_remove (directory->details->extension_queue,
+ file);
}
static void
move_file_to_low_priority_queue (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- /* Must add before removing to avoid ref underflow */
- nautilus_file_queue_enqueue (directory->details->low_priority_queue,
- file);
- nautilus_file_queue_remove (directory->details->high_priority_queue,
- file);
+ /* Must add before removing to avoid ref underflow */
+ nautilus_file_queue_enqueue (directory->details->low_priority_queue,
+ file);
+ nautilus_file_queue_remove (directory->details->high_priority_queue,
+ file);
}
static void
move_file_to_extension_queue (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- /* Must add before removing to avoid ref underflow */
- nautilus_file_queue_enqueue (directory->details->extension_queue,
- file);
- nautilus_file_queue_remove (directory->details->low_priority_queue,
- file);
+ /* Must add before removing to avoid ref underflow */
+ nautilus_file_queue_enqueue (directory->details->extension_queue,
+ file);
+ nautilus_file_queue_remove (directory->details->low_priority_queue,
+ file);
}
diff --git a/src/nautilus-directory.c b/src/nautilus-directory.c
index 5be514450..8e66ff099 100644
--- a/src/nautilus-directory.c
+++ b/src/nautilus-directory.c
@@ -1,23 +1,23 @@
/*
- nautilus-directory.c: Nautilus directory model.
-
- Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * nautilus-directory.c: Nautilus directory model.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
#include "nautilus-directory-private.h"
@@ -39,17 +39,19 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-enum {
- FILES_ADDED,
- FILES_CHANGED,
- DONE_LOADING,
- LOAD_ERROR,
- LAST_SIGNAL
+enum
+{
+ FILES_ADDED,
+ FILES_CHANGED,
+ DONE_LOADING,
+ LOAD_ERROR,
+ LAST_SIGNAL
};
-enum {
- PROP_LOCATION = 1,
- NUM_PROPERTIES
+enum
+{
+ PROP_LOCATION = 1,
+ NUM_PROPERTIES
};
static guint signals[LAST_SIGNAL];
@@ -57,308 +59,334 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
static GHashTable *directories;
-static void nautilus_directory_finalize (GObject *object);
-static NautilusDirectory *nautilus_directory_new (GFile *location);
-static GList * real_get_file_list (NautilusDirectory *directory);
-static gboolean real_is_editable (NautilusDirectory *directory);
-static void set_directory_location (NautilusDirectory *directory,
- GFile *location);
-static NautilusFile * real_new_file_from_filename (NautilusDirectory *directory,
- const char *filename,
- gboolean self_owned);
-static gboolean real_handles_location (GFile *location);
+static void nautilus_directory_finalize (GObject *object);
+static NautilusDirectory *nautilus_directory_new (GFile *location);
+static GList *real_get_file_list (NautilusDirectory *directory);
+static gboolean real_is_editable (NautilusDirectory *directory);
+static void set_directory_location (NautilusDirectory *directory,
+ GFile *location);
+static NautilusFile *real_new_file_from_filename (NautilusDirectory *directory,
+ const char *filename,
+ gboolean self_owned);
+static gboolean real_handles_location (GFile *location);
G_DEFINE_TYPE (NautilusDirectory, nautilus_directory, G_TYPE_OBJECT);
static void
-nautilus_directory_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- NautilusDirectory *directory = NAUTILUS_DIRECTORY (object);
+nautilus_directory_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusDirectory *directory = NAUTILUS_DIRECTORY (object);
+
+ switch (property_id)
+ {
+ case PROP_LOCATION:
+ {
+ set_directory_location (directory, g_value_get_object (value));
+ }
+ break;
- switch (property_id) {
- case PROP_LOCATION:
- set_directory_location (directory, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_directory_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- NautilusDirectory *directory = NAUTILUS_DIRECTORY (object);
+nautilus_directory_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NautilusDirectory *directory = NAUTILUS_DIRECTORY (object);
+
+ switch (property_id)
+ {
+ case PROP_LOCATION:
+ {
+ g_value_set_object (value, directory->details->location);
+ }
+ break;
- switch (property_id) {
- case PROP_LOCATION:
- g_value_set_object (value, directory->details->location);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_directory_class_init (NautilusDirectoryClass *klass)
{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
-
- klass->new_file_from_filename = real_new_file_from_filename;
-
- object_class->finalize = nautilus_directory_finalize;
- object_class->set_property = nautilus_directory_set_property;
- object_class->get_property = nautilus_directory_get_property;
-
- signals[FILES_ADDED] =
- g_signal_new ("files-added",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusDirectoryClass, files_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals[FILES_CHANGED] =
- g_signal_new ("files-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusDirectoryClass, files_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals[DONE_LOADING] =
- g_signal_new ("done-loading",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusDirectoryClass, done_loading),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[LOAD_ERROR] =
- g_signal_new ("load-error",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusDirectoryClass, load_error),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-
- properties[PROP_LOCATION] =
- g_param_spec_object ("location",
- "The location",
- "The location of this directory",
- G_TYPE_FILE,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
-
- klass->get_file_list = real_get_file_list;
- klass->is_editable = real_is_editable;
- klass->handles_location = real_handles_location;
-
- g_type_class_add_private (klass, sizeof (NautilusDirectoryDetails));
- g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ klass->new_file_from_filename = real_new_file_from_filename;
+
+ object_class->finalize = nautilus_directory_finalize;
+ object_class->set_property = nautilus_directory_set_property;
+ object_class->get_property = nautilus_directory_get_property;
+
+ signals[FILES_ADDED] =
+ g_signal_new ("files-added",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusDirectoryClass, files_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+ signals[FILES_CHANGED] =
+ g_signal_new ("files-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusDirectoryClass, files_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+ signals[DONE_LOADING] =
+ g_signal_new ("done-loading",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusDirectoryClass, done_loading),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[LOAD_ERROR] =
+ g_signal_new ("load-error",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusDirectoryClass, load_error),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+
+ properties[PROP_LOCATION] =
+ g_param_spec_object ("location",
+ "The location",
+ "The location of this directory",
+ G_TYPE_FILE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+
+ klass->get_file_list = real_get_file_list;
+ klass->is_editable = real_is_editable;
+ klass->handles_location = real_handles_location;
+
+ g_type_class_add_private (klass, sizeof (NautilusDirectoryDetails));
+ g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
}
static void
nautilus_directory_init (NautilusDirectory *directory)
{
- directory->details = G_TYPE_INSTANCE_GET_PRIVATE ((directory), NAUTILUS_TYPE_DIRECTORY, NautilusDirectoryDetails);
- directory->details->file_hash = g_hash_table_new (g_str_hash, g_str_equal);
- directory->details->high_priority_queue = nautilus_file_queue_new ();
- directory->details->low_priority_queue = nautilus_file_queue_new ();
- directory->details->extension_queue = nautilus_file_queue_new ();
+ directory->details = G_TYPE_INSTANCE_GET_PRIVATE ((directory), NAUTILUS_TYPE_DIRECTORY, NautilusDirectoryDetails);
+ directory->details->file_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ directory->details->high_priority_queue = nautilus_file_queue_new ();
+ directory->details->low_priority_queue = nautilus_file_queue_new ();
+ directory->details->extension_queue = nautilus_file_queue_new ();
}
NautilusDirectory *
nautilus_directory_ref (NautilusDirectory *directory)
{
- if (directory == NULL) {
- return directory;
- }
+ if (directory == NULL)
+ {
+ return directory;
+ }
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
- g_object_ref (directory);
- return directory;
+ g_object_ref (directory);
+ return directory;
}
void
nautilus_directory_unref (NautilusDirectory *directory)
{
- if (directory == NULL) {
- return;
- }
+ if (directory == NULL)
+ {
+ return;
+ }
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
- g_object_unref (directory);
+ g_object_unref (directory);
}
static void
nautilus_directory_finalize (GObject *object)
{
- NautilusDirectory *directory;
+ NautilusDirectory *directory;
- directory = NAUTILUS_DIRECTORY (object);
+ directory = NAUTILUS_DIRECTORY (object);
- g_hash_table_remove (directories, directory->details->location);
+ g_hash_table_remove (directories, directory->details->location);
- nautilus_directory_cancel (directory);
- g_assert (directory->details->count_in_progress == NULL);
+ nautilus_directory_cancel (directory);
+ g_assert (directory->details->count_in_progress == NULL);
- if (directory->details->monitor_list != NULL) {
- g_warning ("destroying a NautilusDirectory while it's being monitored");
- g_list_free_full (directory->details->monitor_list, g_free);
- }
+ if (directory->details->monitor_list != NULL)
+ {
+ g_warning ("destroying a NautilusDirectory while it's being monitored");
+ g_list_free_full (directory->details->monitor_list, g_free);
+ }
- if (directory->details->monitor != NULL) {
- nautilus_monitor_cancel (directory->details->monitor);
- }
+ if (directory->details->monitor != NULL)
+ {
+ nautilus_monitor_cancel (directory->details->monitor);
+ }
- if (directory->details->dequeue_pending_idle_id != 0) {
- g_source_remove (directory->details->dequeue_pending_idle_id);
- }
+ if (directory->details->dequeue_pending_idle_id != 0)
+ {
+ g_source_remove (directory->details->dequeue_pending_idle_id);
+ }
- if (directory->details->call_ready_idle_id != 0) {
- g_source_remove (directory->details->call_ready_idle_id);
- }
+ if (directory->details->call_ready_idle_id != 0)
+ {
+ g_source_remove (directory->details->call_ready_idle_id);
+ }
- if (directory->details->location) {
- g_object_unref (directory->details->location);
- }
+ if (directory->details->location)
+ {
+ g_object_unref (directory->details->location);
+ }
- g_assert (directory->details->file_list == NULL);
- g_hash_table_destroy (directory->details->file_hash);
+ g_assert (directory->details->file_list == NULL);
+ g_hash_table_destroy (directory->details->file_hash);
- nautilus_file_queue_destroy (directory->details->high_priority_queue);
- nautilus_file_queue_destroy (directory->details->low_priority_queue);
- nautilus_file_queue_destroy (directory->details->extension_queue);
- g_assert (directory->details->directory_load_in_progress == NULL);
- g_assert (directory->details->count_in_progress == NULL);
- g_assert (directory->details->dequeue_pending_idle_id == 0);
- g_list_free_full (directory->details->pending_file_info, g_object_unref);
+ nautilus_file_queue_destroy (directory->details->high_priority_queue);
+ nautilus_file_queue_destroy (directory->details->low_priority_queue);
+ nautilus_file_queue_destroy (directory->details->extension_queue);
+ g_assert (directory->details->directory_load_in_progress == NULL);
+ g_assert (directory->details->count_in_progress == NULL);
+ g_assert (directory->details->dequeue_pending_idle_id == 0);
+ g_list_free_full (directory->details->pending_file_info, g_object_unref);
- G_OBJECT_CLASS (nautilus_directory_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_directory_parent_class)->finalize (object);
}
static void
-collect_all_directories (gpointer key, gpointer value, gpointer callback_data)
+collect_all_directories (gpointer key,
+ gpointer value,
+ gpointer callback_data)
{
- NautilusDirectory *directory;
- GList **dirs;
+ NautilusDirectory *directory;
+ GList **dirs;
- directory = NAUTILUS_DIRECTORY (value);
- dirs = callback_data;
+ directory = NAUTILUS_DIRECTORY (value);
+ dirs = callback_data;
- *dirs = g_list_prepend (*dirs, nautilus_directory_ref (directory));
+ *dirs = g_list_prepend (*dirs, nautilus_directory_ref (directory));
}
static void
filtering_changed_callback (gpointer callback_data)
{
- GList *dirs, *l;
- NautilusDirectory *directory;
+ GList *dirs, *l;
+ NautilusDirectory *directory;
- g_assert (callback_data == NULL);
+ g_assert (callback_data == NULL);
- dirs = NULL;
- g_hash_table_foreach (directories, collect_all_directories, &dirs);
+ dirs = NULL;
+ g_hash_table_foreach (directories, collect_all_directories, &dirs);
- /* Preference about which items to show has changed, so we
- * can't trust any of our precomputed directory counts.
- */
- for (l = dirs; l != NULL; l = l->next) {
- directory = NAUTILUS_DIRECTORY (l->data);
- nautilus_directory_invalidate_count_and_mime_list (directory);
- }
+ /* Preference about which items to show has changed, so we
+ * can't trust any of our precomputed directory counts.
+ */
+ for (l = dirs; l != NULL; l = l->next)
+ {
+ directory = NAUTILUS_DIRECTORY (l->data);
+ nautilus_directory_invalidate_count_and_mime_list (directory);
+ }
- nautilus_directory_list_unref (dirs);
+ nautilus_directory_list_unref (dirs);
}
void
emit_change_signals_for_all_files (NautilusDirectory *directory)
{
- GList *files;
+ GList *files;
- files = g_list_copy (directory->details->file_list);
- if (directory->details->as_file != NULL) {
- files = g_list_prepend (files, directory->details->as_file);
- }
+ files = g_list_copy (directory->details->file_list);
+ if (directory->details->as_file != NULL)
+ {
+ files = g_list_prepend (files, directory->details->as_file);
+ }
- nautilus_file_list_ref (files);
- nautilus_directory_emit_change_signals (directory, files);
+ nautilus_file_list_ref (files);
+ nautilus_directory_emit_change_signals (directory, files);
- nautilus_file_list_free (files);
+ nautilus_file_list_free (files);
}
void
emit_change_signals_for_all_files_in_all_directories (void)
{
- GList *dirs, *l;
- NautilusDirectory *directory;
+ GList *dirs, *l;
+ NautilusDirectory *directory;
- dirs = NULL;
- g_hash_table_foreach (directories,
- collect_all_directories,
- &dirs);
+ dirs = NULL;
+ g_hash_table_foreach (directories,
+ collect_all_directories,
+ &dirs);
- for (l = dirs; l != NULL; l = l->next) {
- directory = NAUTILUS_DIRECTORY (l->data);
- emit_change_signals_for_all_files (directory);
- nautilus_directory_unref (directory);
- }
+ for (l = dirs; l != NULL; l = l->next)
+ {
+ directory = NAUTILUS_DIRECTORY (l->data);
+ emit_change_signals_for_all_files (directory);
+ nautilus_directory_unref (directory);
+ }
- g_list_free (dirs);
+ g_list_free (dirs);
}
static void
-async_state_changed_one (gpointer key, gpointer value, gpointer user_data)
+async_state_changed_one (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- NautilusDirectory *directory;
+ NautilusDirectory *directory;
- g_assert (key != NULL);
- g_assert (NAUTILUS_IS_DIRECTORY (value));
- g_assert (user_data == NULL);
+ g_assert (key != NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (value));
+ g_assert (user_data == NULL);
- directory = NAUTILUS_DIRECTORY (value);
-
- nautilus_directory_async_state_changed (directory);
- emit_change_signals_for_all_files (directory);
+ directory = NAUTILUS_DIRECTORY (value);
+
+ nautilus_directory_async_state_changed (directory);
+ emit_change_signals_for_all_files (directory);
}
static void
async_data_preference_changed_callback (gpointer callback_data)
{
- g_assert (callback_data == NULL);
+ g_assert (callback_data == NULL);
- /* Preference involving fetched async data has changed, so
- * we have to kick off refetching all async data, and tell
- * each file that it (might have) changed.
- */
- g_hash_table_foreach (directories, async_state_changed_one, NULL);
+ /* Preference involving fetched async data has changed, so
+ * we have to kick off refetching all async data, and tell
+ * each file that it (might have) changed.
+ */
+ g_hash_table_foreach (directories, async_state_changed_one, NULL);
}
static void
add_preferences_callbacks (void)
{
- nautilus_global_preferences_init ();
+ nautilus_global_preferences_init ();
- g_signal_connect_swapped (gtk_filechooser_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
- G_CALLBACK(filtering_changed_callback),
- NULL);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
- G_CALLBACK (async_data_preference_changed_callback),
- NULL);
+ g_signal_connect_swapped (gtk_filechooser_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
+ G_CALLBACK (filtering_changed_callback),
+ NULL);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
+ G_CALLBACK (async_data_preference_changed_callback),
+ NULL);
}
/**
@@ -371,88 +399,97 @@ add_preferences_callbacks (void)
* If two windows are viewing the same uri, the directory object is shared.
*/
NautilusDirectory *
-nautilus_directory_get_internal (GFile *location, gboolean create)
-{
- NautilusDirectory *directory;
-
- /* Create the hash table first time through. */
- if (directories == NULL) {
- directories = g_hash_table_new (g_file_hash, (GCompareFunc) g_file_equal);
- add_preferences_callbacks ();
- }
-
- /* If the object is already in the hash table, look it up. */
-
- directory = g_hash_table_lookup (directories,
- location);
- if (directory != NULL) {
- nautilus_directory_ref (directory);
- } else if (create) {
- /* Create a new directory object instead. */
- directory = nautilus_directory_new (location);
- if (directory == NULL) {
- return NULL;
- }
-
- /* Put it in the hash table. */
- g_hash_table_insert (directories,
- directory->details->location,
- directory);
- }
-
- return directory;
+nautilus_directory_get_internal (GFile *location,
+ gboolean create)
+{
+ NautilusDirectory *directory;
+
+ /* Create the hash table first time through. */
+ if (directories == NULL)
+ {
+ directories = g_hash_table_new (g_file_hash, (GCompareFunc) g_file_equal);
+ add_preferences_callbacks ();
+ }
+
+ /* If the object is already in the hash table, look it up. */
+
+ directory = g_hash_table_lookup (directories,
+ location);
+ if (directory != NULL)
+ {
+ nautilus_directory_ref (directory);
+ }
+ else if (create)
+ {
+ /* Create a new directory object instead. */
+ directory = nautilus_directory_new (location);
+ if (directory == NULL)
+ {
+ return NULL;
+ }
+
+ /* Put it in the hash table. */
+ g_hash_table_insert (directories,
+ directory->details->location,
+ directory);
+ }
+
+ return directory;
}
NautilusDirectory *
nautilus_directory_get (GFile *location)
{
- if (location == NULL) {
- return NULL;
- }
+ if (location == NULL)
+ {
+ return NULL;
+ }
- return nautilus_directory_get_internal (location, TRUE);
+ return nautilus_directory_get_internal (location, TRUE);
}
NautilusDirectory *
nautilus_directory_get_existing (GFile *location)
{
- if (location == NULL) {
- return NULL;
- }
+ if (location == NULL)
+ {
+ return NULL;
+ }
- return nautilus_directory_get_internal (location, FALSE);
+ return nautilus_directory_get_internal (location, FALSE);
}
NautilusDirectory *
nautilus_directory_get_by_uri (const char *uri)
{
- NautilusDirectory *directory;
- GFile *location;
+ NautilusDirectory *directory;
+ GFile *location;
- if (uri == NULL) {
- return NULL;
- }
+ if (uri == NULL)
+ {
+ return NULL;
+ }
- location = g_file_new_for_uri (uri);
+ location = g_file_new_for_uri (uri);
- directory = nautilus_directory_get_internal (location, TRUE);
- g_object_unref (location);
- return directory;
+ directory = nautilus_directory_get_internal (location, TRUE);
+ g_object_unref (location);
+ return directory;
}
NautilusDirectory *
nautilus_directory_get_for_file (NautilusFile *file)
{
- char *uri;
- NautilusDirectory *directory;
+ char *uri;
+ NautilusDirectory *directory;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- uri = nautilus_file_get_uri (file);
- directory = nautilus_directory_get_by_uri (uri);
- g_free (uri);
- return directory;
+ uri = nautilus_file_get_uri (file);
+ directory = nautilus_directory_get_by_uri (uri);
+ g_free (uri);
+ return directory;
}
/* Returns a reffed NautilusFile object for this directory.
@@ -460,17 +497,18 @@ nautilus_directory_get_for_file (NautilusFile *file)
NautilusFile *
nautilus_directory_get_corresponding_file (NautilusDirectory *directory)
{
- NautilusFile *file;
- char *uri;
+ NautilusFile *file;
+ char *uri;
- file = nautilus_directory_get_existing_corresponding_file (directory);
- if (file == NULL) {
- uri = nautilus_directory_get_uri (directory);
- file = nautilus_file_get_by_uri (uri);
- g_free (uri);
- }
+ file = nautilus_directory_get_existing_corresponding_file (directory);
+ if (file == NULL)
+ {
+ uri = nautilus_directory_get_uri (directory);
+ file = nautilus_file_get_by_uri (uri);
+ g_free (uri);
+ }
- return file;
+ return file;
}
/* Returns a reffed NautilusFile object for this directory, but only if the
@@ -479,23 +517,24 @@ nautilus_directory_get_corresponding_file (NautilusDirectory *directory)
NautilusFile *
nautilus_directory_get_existing_corresponding_file (NautilusDirectory *directory)
{
- NautilusFile *file;
- char *uri;
-
- file = directory->details->as_file;
- if (file != NULL) {
- nautilus_file_ref (file);
- return file;
- }
+ NautilusFile *file;
+ char *uri;
- uri = nautilus_directory_get_uri (directory);
- file = nautilus_file_get_existing_by_uri (uri);
- g_free (uri);
- return file;
+ file = directory->details->as_file;
+ if (file != NULL)
+ {
+ nautilus_file_ref (file);
+ return file;
+ }
+
+ uri = nautilus_directory_get_uri (directory);
+ file = nautilus_file_get_existing_by_uri (uri);
+ g_free (uri);
+ return file;
}
/* nautilus_directory_get_name_for_self_as_new_file:
- *
+ *
* Get a name to display for the file representing this
* directory. This is called only when there's no VFS
* directory for this NautilusDirectory.
@@ -503,55 +542,60 @@ nautilus_directory_get_existing_corresponding_file (NautilusDirectory *directory
char *
nautilus_directory_get_name_for_self_as_new_file (NautilusDirectory *directory)
{
- GFile *file;
- char *directory_uri;
- char *scheme;
- char *name;
- char *hostname = NULL;
-
- directory_uri = nautilus_directory_get_uri (directory);
- file = g_file_new_for_uri (directory_uri);
- scheme = g_file_get_uri_scheme (file);
- g_object_unref (file);
-
- nautilus_uri_parse (directory_uri, &hostname, NULL, NULL);
- if (hostname == NULL || (strlen (hostname) == 0)) {
- name = g_strdup (directory_uri);
- } else if (scheme == NULL) {
- name = g_strdup (hostname);
- } else {
- /* Translators: this is of the format "hostname (uri-scheme)" */
- name = g_strdup_printf (_("%s (%s)"), hostname, scheme);
- }
-
- g_free (directory_uri);
- g_free (scheme);
- g_free (hostname);
-
- return name;
+ GFile *file;
+ char *directory_uri;
+ char *scheme;
+ char *name;
+ char *hostname = NULL;
+
+ directory_uri = nautilus_directory_get_uri (directory);
+ file = g_file_new_for_uri (directory_uri);
+ scheme = g_file_get_uri_scheme (file);
+ g_object_unref (file);
+
+ nautilus_uri_parse (directory_uri, &hostname, NULL, NULL);
+ if (hostname == NULL || (strlen (hostname) == 0))
+ {
+ name = g_strdup (directory_uri);
+ }
+ else if (scheme == NULL)
+ {
+ name = g_strdup (hostname);
+ }
+ else
+ {
+ /* Translators: this is of the format "hostname (uri-scheme)" */
+ name = g_strdup_printf (_("%s (%s)"), hostname, scheme);
+ }
+
+ g_free (directory_uri);
+ g_free (scheme);
+ g_free (hostname);
+
+ return name;
}
char *
nautilus_directory_get_uri (NautilusDirectory *directory)
{
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
- return g_file_get_uri (directory->details->location);
+ return g_file_get_uri (directory->details->location);
}
GFile *
-nautilus_directory_get_location (NautilusDirectory *directory)
+nautilus_directory_get_location (NautilusDirectory *directory)
{
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
- return g_object_ref (directory->details->location);
+ return g_object_ref (directory->details->location);
}
static gboolean
real_handles_location (GFile *location)
{
- /* This class is the fallback on handling any location */
- return TRUE;
+ /* This class is the fallback on handling any location */
+ return TRUE;
}
NautilusFile *
@@ -559,9 +603,9 @@ nautilus_directory_new_file_from_filename (NautilusDirectory *directory,
const char *filename,
gboolean self_owned)
{
- return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->new_file_from_filename (directory,
- filename,
- self_owned);
+ return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->new_file_from_filename (directory,
+ filename,
+ self_owned);
}
static NautilusFile *
@@ -569,360 +613,390 @@ real_new_file_from_filename (NautilusDirectory *directory,
const char *filename,
gboolean self_owned)
{
- NautilusFile *file;
+ NautilusFile *file;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (filename != NULL);
- g_assert (filename[0] != '\0');
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (filename != NULL);
+ g_assert (filename[0] != '\0');
- if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
- if (self_owned) {
- file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE, NULL));
- } else {
- /* This doesn't normally happen, unless the user somehow types in a uri
- * that references a file like this. (See #349840) */
- file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
- }
- } else {
- file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
- }
- nautilus_file_set_directory (file, directory);
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ if (self_owned)
+ {
+ file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE, NULL));
+ }
+ else
+ {
+ /* This doesn't normally happen, unless the user somehow types in a uri
+ * that references a file like this. (See #349840) */
+ file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
+ }
+ }
+ else
+ {
+ file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
+ }
+ nautilus_file_set_directory (file, directory);
- return file;
+ return file;
}
-static GList*
+static GList *
nautilus_directory_provider_get_all (void)
{
- GIOExtensionPoint *extension_point;
- GList *extensions;
+ GIOExtensionPoint *extension_point;
+ GList *extensions;
- extension_point = g_io_extension_point_lookup (NAUTILUS_DIRECTORY_PROVIDER_EXTENSION_POINT_NAME);
- extensions = g_io_extension_point_get_extensions (extension_point);
+ extension_point = g_io_extension_point_lookup (NAUTILUS_DIRECTORY_PROVIDER_EXTENSION_POINT_NAME);
+ extensions = g_io_extension_point_get_extensions (extension_point);
- return extensions;
+ return extensions;
}
static NautilusDirectory *
nautilus_directory_new (GFile *location)
{
- GList *extensions;
- GList *l;
- GIOExtension *gio_extension;
- GType handling_provider_type;
- gboolean handled = FALSE;
- NautilusDirectoryClass *current_provider_class;
- NautilusDirectory *handling_instance;
-
- extensions = nautilus_directory_provider_get_all ();
-
- for (l = extensions; l != NULL; l = l->next) {
- gio_extension = l->data;
- current_provider_class = NAUTILUS_DIRECTORY_CLASS (g_io_extension_ref_class (gio_extension));
- if (current_provider_class->handles_location (location)) {
- handling_provider_type = g_io_extension_get_type (gio_extension);
- handled = TRUE;
- break;
- }
+ GList *extensions;
+ GList *l;
+ GIOExtension *gio_extension;
+ GType handling_provider_type;
+ gboolean handled = FALSE;
+ NautilusDirectoryClass *current_provider_class;
+ NautilusDirectory *handling_instance;
+
+ extensions = nautilus_directory_provider_get_all ();
+
+ for (l = extensions; l != NULL; l = l->next)
+ {
+ gio_extension = l->data;
+ current_provider_class = NAUTILUS_DIRECTORY_CLASS (g_io_extension_ref_class (gio_extension));
+ if (current_provider_class->handles_location (location))
+ {
+ handling_provider_type = g_io_extension_get_type (gio_extension);
+ handled = TRUE;
+ break;
}
+ }
- if (!handled) {
- /* This class is the fallback for any location */
- handling_provider_type = NAUTILUS_TYPE_VFS_DIRECTORY;
- }
+ if (!handled)
+ {
+ /* This class is the fallback for any location */
+ handling_provider_type = NAUTILUS_TYPE_VFS_DIRECTORY;
+ }
- handling_instance = g_object_new (handling_provider_type,
- "location", location,
- NULL);
+ handling_instance = g_object_new (handling_provider_type,
+ "location", location,
+ NULL);
- return handling_instance;
+ return handling_instance;
}
gboolean
nautilus_directory_is_local (NautilusDirectory *directory)
{
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
- if (directory->details->location == NULL) {
- return TRUE;
- }
+ if (directory->details->location == NULL)
+ {
+ return TRUE;
+ }
- return nautilus_directory_is_in_trash (directory) ||
- nautilus_directory_is_in_recent (directory) ||
- g_file_is_native (directory->details->location);
+ return nautilus_directory_is_in_trash (directory) ||
+ nautilus_directory_is_in_recent (directory) ||
+ g_file_is_native (directory->details->location);
}
gboolean
nautilus_directory_is_local_or_fuse (NautilusDirectory *directory)
{
- g_autofree char* path = NULL;
+ g_autofree char *path = NULL;
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
-
- if (directory->details->location == NULL) {
- return TRUE;
- }
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
- /* If the glib reports a path, then it can use FUSE to convert the uri
- * to a local path
- */
- path = g_file_get_path (directory->details->location);
+ if (directory->details->location == NULL)
+ {
+ return TRUE;
+ }
+
+ /* If the glib reports a path, then it can use FUSE to convert the uri
+ * to a local path
+ */
+ path = g_file_get_path (directory->details->location);
- return nautilus_directory_is_in_trash (directory) ||
- nautilus_directory_is_in_recent (directory) ||
- g_file_is_native (directory->details->location) ||
- path != NULL;
+ return nautilus_directory_is_in_trash (directory) ||
+ nautilus_directory_is_in_recent (directory) ||
+ g_file_is_native (directory->details->location) ||
+ path != NULL;
}
gboolean
nautilus_directory_is_in_trash (NautilusDirectory *directory)
{
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
-
- if (directory->details->location == NULL) {
- return FALSE;
- }
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
- return g_file_has_uri_scheme (directory->details->location, "trash");
+ if (directory->details->location == NULL)
+ {
+ return FALSE;
+ }
+
+ return g_file_has_uri_scheme (directory->details->location, "trash");
}
gboolean
nautilus_directory_is_in_recent (NautilusDirectory *directory)
{
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
- if (directory->details->location == NULL) {
- return FALSE;
- }
+ if (directory->details->location == NULL)
+ {
+ return FALSE;
+ }
- return g_file_has_uri_scheme (directory->details->location, "recent");
+ return g_file_has_uri_scheme (directory->details->location, "recent");
}
gboolean
nautilus_directory_is_remote (NautilusDirectory *directory)
{
- NautilusFile *file;
- gboolean is_remote;
+ NautilusFile *file;
+ gboolean is_remote;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
- file = nautilus_directory_get_corresponding_file (directory);
- is_remote = nautilus_file_is_remote (file);
- nautilus_file_unref (file);
+ file = nautilus_directory_get_corresponding_file (directory);
+ is_remote = nautilus_file_is_remote (file);
+ nautilus_file_unref (file);
- return is_remote;
+ return is_remote;
}
gboolean
nautilus_directory_are_all_files_seen (NautilusDirectory *directory)
{
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
- return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->are_all_files_seen (directory);
+ return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->are_all_files_seen (directory);
}
static void
-add_to_hash_table (NautilusDirectory *directory, NautilusFile *file, GList *node)
+add_to_hash_table (NautilusDirectory *directory,
+ NautilusFile *file,
+ GList *node)
{
- const char *name;
+ const char *name;
- name = eel_ref_str_peek (file->details->name);
+ name = eel_ref_str_peek (file->details->name);
- g_assert (node != NULL);
- g_assert (g_hash_table_lookup (directory->details->file_hash,
- name) == NULL);
- g_hash_table_insert (directory->details->file_hash, (char *) name, node);
+ g_assert (node != NULL);
+ g_assert (g_hash_table_lookup (directory->details->file_hash,
+ name) == NULL);
+ g_hash_table_insert (directory->details->file_hash, (char *) name, node);
}
static GList *
-extract_from_hash_table (NautilusDirectory *directory, NautilusFile *file)
+extract_from_hash_table (NautilusDirectory *directory,
+ NautilusFile *file)
{
- const char *name;
- GList *node;
+ const char *name;
+ GList *node;
- name = eel_ref_str_peek (file->details->name);
- if (name == NULL) {
- return NULL;
- }
+ name = eel_ref_str_peek (file->details->name);
+ if (name == NULL)
+ {
+ return NULL;
+ }
- /* Find the list node in the hash table. */
- node = g_hash_table_lookup (directory->details->file_hash, name);
- g_hash_table_remove (directory->details->file_hash, name);
+ /* Find the list node in the hash table. */
+ node = g_hash_table_lookup (directory->details->file_hash, name);
+ g_hash_table_remove (directory->details->file_hash, name);
- return node;
+ return node;
}
void
-nautilus_directory_add_file (NautilusDirectory *directory, NautilusFile *file)
-{
- GList *node;
- gboolean add_to_work_queue;
-
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->name != NULL);
-
- /* Add to list. */
- node = g_list_prepend (directory->details->file_list, file);
- directory->details->file_list = node;
-
- /* Add to hash table. */
- add_to_hash_table (directory, file, node);
-
- directory->details->confirmed_file_count++;
-
- add_to_work_queue = FALSE;
- if (nautilus_directory_is_file_list_monitored (directory)) {
- /* Ref if we are monitoring, since monitoring owns the file list. */
- nautilus_file_ref (file);
- add_to_work_queue = TRUE;
- } else if (nautilus_directory_has_active_request_for_file (directory, file)) {
- /* We're waiting for the file in a call_when_ready. Make sure
- we add the file to the work queue so that said waiter won't
- wait forever for e.g. all files in the directory to be done */
- add_to_work_queue = TRUE;
- }
-
- if (add_to_work_queue) {
- nautilus_directory_add_file_to_work_queue (directory, file);
- }
+nautilus_directory_add_file (NautilusDirectory *directory,
+ NautilusFile *file)
+{
+ GList *node;
+ gboolean add_to_work_queue;
+
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->name != NULL);
+
+ /* Add to list. */
+ node = g_list_prepend (directory->details->file_list, file);
+ directory->details->file_list = node;
+
+ /* Add to hash table. */
+ add_to_hash_table (directory, file, node);
+
+ directory->details->confirmed_file_count++;
+
+ add_to_work_queue = FALSE;
+ if (nautilus_directory_is_file_list_monitored (directory))
+ {
+ /* Ref if we are monitoring, since monitoring owns the file list. */
+ nautilus_file_ref (file);
+ add_to_work_queue = TRUE;
+ }
+ else if (nautilus_directory_has_active_request_for_file (directory, file))
+ {
+ /* We're waiting for the file in a call_when_ready. Make sure
+ * we add the file to the work queue so that said waiter won't
+ * wait forever for e.g. all files in the directory to be done */
+ add_to_work_queue = TRUE;
+ }
+
+ if (add_to_work_queue)
+ {
+ nautilus_directory_add_file_to_work_queue (directory, file);
+ }
}
void
-nautilus_directory_remove_file (NautilusDirectory *directory, NautilusFile *file)
+nautilus_directory_remove_file (NautilusDirectory *directory,
+ NautilusFile *file)
{
- GList *node;
+ GList *node;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (file->details->name != NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (file->details->name != NULL);
- /* Find the list node in the hash table. */
- node = extract_from_hash_table (directory, file);
- g_assert (node != NULL);
- g_assert (node->data == file);
+ /* Find the list node in the hash table. */
+ node = extract_from_hash_table (directory, file);
+ g_assert (node != NULL);
+ g_assert (node->data == file);
- /* Remove the item from the list. */
- directory->details->file_list = g_list_remove_link
- (directory->details->file_list, node);
- g_list_free_1 (node);
+ /* Remove the item from the list. */
+ directory->details->file_list = g_list_remove_link
+ (directory->details->file_list, node);
+ g_list_free_1 (node);
- nautilus_directory_remove_file_from_work_queue (directory, file);
+ nautilus_directory_remove_file_from_work_queue (directory, file);
- if (!file->details->unconfirmed) {
- directory->details->confirmed_file_count--;
- }
+ if (!file->details->unconfirmed)
+ {
+ directory->details->confirmed_file_count--;
+ }
- /* Unref if we are monitoring. */
- if (nautilus_directory_is_file_list_monitored (directory)) {
- nautilus_file_unref (file);
- }
+ /* Unref if we are monitoring. */
+ if (nautilus_directory_is_file_list_monitored (directory))
+ {
+ nautilus_file_unref (file);
+ }
}
GList *
nautilus_directory_begin_file_name_change (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- /* Find the list node in the hash table. */
- return extract_from_hash_table (directory, file);
+ /* Find the list node in the hash table. */
+ return extract_from_hash_table (directory, file);
}
void
nautilus_directory_end_file_name_change (NautilusDirectory *directory,
- NautilusFile *file,
- GList *node)
+ NautilusFile *file,
+ GList *node)
{
- /* Add the list node to the hash table. */
- if (node != NULL) {
- add_to_hash_table (directory, file, node);
- }
+ /* Add the list node to the hash table. */
+ if (node != NULL)
+ {
+ add_to_hash_table (directory, file, node);
+ }
}
NautilusFile *
nautilus_directory_find_file_by_name (NautilusDirectory *directory,
- const char *name)
+ const char *name)
{
- GList *node;
+ GList *node;
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
- g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ g_return_val_if_fail (name != NULL, NULL);
- node = g_hash_table_lookup (directory->details->file_hash,
- name);
- return node == NULL ? NULL : NAUTILUS_FILE (node->data);
+ node = g_hash_table_lookup (directory->details->file_hash,
+ name);
+ return node == NULL ? NULL : NAUTILUS_FILE (node->data);
}
void
nautilus_directory_emit_files_added (NautilusDirectory *directory,
- GList *added_files)
+ GList *added_files)
{
- nautilus_profile_start (NULL);
- if (added_files != NULL) {
- g_signal_emit (directory,
- signals[FILES_ADDED], 0,
- added_files);
- }
- nautilus_profile_end (NULL);
+ nautilus_profile_start (NULL);
+ if (added_files != NULL)
+ {
+ g_signal_emit (directory,
+ signals[FILES_ADDED], 0,
+ added_files);
+ }
+ nautilus_profile_end (NULL);
}
void
nautilus_directory_emit_files_changed (NautilusDirectory *directory,
- GList *changed_files)
+ GList *changed_files)
{
- nautilus_profile_start (NULL);
- if (changed_files != NULL) {
- g_signal_emit (directory,
- signals[FILES_CHANGED], 0,
- changed_files);
- }
- nautilus_profile_end (NULL);
+ nautilus_profile_start (NULL);
+ if (changed_files != NULL)
+ {
+ g_signal_emit (directory,
+ signals[FILES_CHANGED], 0,
+ changed_files);
+ }
+ nautilus_profile_end (NULL);
}
void
nautilus_directory_emit_change_signals (NautilusDirectory *directory,
- GList *changed_files)
+ GList *changed_files)
{
- GList *p;
+ GList *p;
- nautilus_profile_start (NULL);
- for (p = changed_files; p != NULL; p = p->next) {
- nautilus_file_emit_changed (p->data);
- }
- nautilus_directory_emit_files_changed (directory, changed_files);
- nautilus_profile_end (NULL);
+ nautilus_profile_start (NULL);
+ for (p = changed_files; p != NULL; p = p->next)
+ {
+ nautilus_file_emit_changed (p->data);
+ }
+ nautilus_directory_emit_files_changed (directory, changed_files);
+ nautilus_profile_end (NULL);
}
void
nautilus_directory_emit_done_loading (NautilusDirectory *directory)
{
- g_signal_emit (directory,
- signals[DONE_LOADING], 0);
+ g_signal_emit (directory,
+ signals[DONE_LOADING], 0);
}
void
nautilus_directory_emit_load_error (NautilusDirectory *directory,
- GError *error)
+ GError *error)
{
- g_signal_emit (directory,
- signals[LOAD_ERROR], 0,
- error);
+ g_signal_emit (directory,
+ signals[LOAD_ERROR], 0,
+ error);
}
/* Return a directory object for this one's parent. */
static NautilusDirectory *
get_parent_directory (GFile *location)
{
- NautilusDirectory *directory;
- GFile *parent;
+ NautilusDirectory *directory;
+ GFile *parent;
- parent = g_file_get_parent (location);
- if (parent) {
- directory = nautilus_directory_get_internal (parent, TRUE);
- g_object_unref (parent);
- return directory;
- }
- return NULL;
+ parent = g_file_get_parent (location);
+ if (parent)
+ {
+ directory = nautilus_directory_get_internal (parent, TRUE);
+ g_object_unref (parent);
+ return directory;
+ }
+ return NULL;
}
/* If a directory object exists for this one's parent, then
@@ -931,788 +1005,854 @@ get_parent_directory (GFile *location)
static NautilusDirectory *
get_parent_directory_if_exists (GFile *location)
{
- NautilusDirectory *directory;
- GFile *parent;
+ NautilusDirectory *directory;
+ GFile *parent;
- parent = g_file_get_parent (location);
- if (parent) {
- directory = nautilus_directory_get_internal (parent, FALSE);
- g_object_unref (parent);
- return directory;
- }
- return NULL;
+ parent = g_file_get_parent (location);
+ if (parent)
+ {
+ directory = nautilus_directory_get_internal (parent, FALSE);
+ g_object_unref (parent);
+ return directory;
+ }
+ return NULL;
}
static void
-hash_table_list_prepend (GHashTable *table, gconstpointer key, gpointer data)
+hash_table_list_prepend (GHashTable *table,
+ gconstpointer key,
+ gpointer data)
{
- GList *list;
+ GList *list;
- list = g_hash_table_lookup (table, key);
- list = g_list_prepend (list, data);
- g_hash_table_insert (table, (gpointer) key, list);
+ list = g_hash_table_lookup (table, key);
+ list = g_list_prepend (list, data);
+ g_hash_table_insert (table, (gpointer) key, list);
}
static void
-call_files_added_free_list (gpointer key, gpointer value, gpointer user_data)
+call_files_added_free_list (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- g_assert (NAUTILUS_IS_DIRECTORY (key));
- g_assert (value != NULL);
- g_assert (user_data == NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (key));
+ g_assert (value != NULL);
+ g_assert (user_data == NULL);
- g_signal_emit (key,
- signals[FILES_ADDED], 0,
- value);
- g_list_free (value);
+ g_signal_emit (key,
+ signals[FILES_ADDED], 0,
+ value);
+ g_list_free (value);
}
static void
-call_files_changed_common (NautilusDirectory *directory, GList *file_list)
-{
- GList *node;
- NautilusFile *file;
-
- for (node = file_list; node != NULL; node = node->next) {
- file = node->data;
- if (file->details->directory == directory) {
- nautilus_directory_add_file_to_work_queue (directory,
- file);
- }
- }
- nautilus_directory_async_state_changed (directory);
- nautilus_directory_emit_change_signals (directory, file_list);
+call_files_changed_common (NautilusDirectory *directory,
+ GList *file_list)
+{
+ GList *node;
+ NautilusFile *file;
+
+ for (node = file_list; node != NULL; node = node->next)
+ {
+ file = node->data;
+ if (file->details->directory == directory)
+ {
+ nautilus_directory_add_file_to_work_queue (directory,
+ file);
+ }
+ }
+ nautilus_directory_async_state_changed (directory);
+ nautilus_directory_emit_change_signals (directory, file_list);
}
static void
-call_files_changed_free_list (gpointer key, gpointer value, gpointer user_data)
+call_files_changed_free_list (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- g_assert (value != NULL);
- g_assert (user_data == NULL);
+ g_assert (value != NULL);
+ g_assert (user_data == NULL);
- call_files_changed_common (NAUTILUS_DIRECTORY (key), value);
- g_list_free (value);
+ call_files_changed_common (NAUTILUS_DIRECTORY (key), value);
+ g_list_free (value);
}
static void
-call_files_changed_unref_free_list (gpointer key, gpointer value, gpointer user_data)
+call_files_changed_unref_free_list (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- g_assert (value != NULL);
- g_assert (user_data == NULL);
+ g_assert (value != NULL);
+ g_assert (user_data == NULL);
- call_files_changed_common (NAUTILUS_DIRECTORY (key), value);
- nautilus_file_list_free (value);
+ call_files_changed_common (NAUTILUS_DIRECTORY (key), value);
+ nautilus_file_list_free (value);
}
static void
-call_get_file_info_free_list (gpointer key, gpointer value, gpointer user_data)
+call_get_file_info_free_list (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- NautilusDirectory *directory;
- GList *files;
-
- g_assert (NAUTILUS_IS_DIRECTORY (key));
- g_assert (value != NULL);
- g_assert (user_data == NULL);
+ NautilusDirectory *directory;
+ GList *files;
- directory = key;
- files = value;
-
- nautilus_directory_get_info_for_new_files (directory, files);
- g_list_foreach (files, (GFunc) g_object_unref, NULL);
- g_list_free (files);
+ g_assert (NAUTILUS_IS_DIRECTORY (key));
+ g_assert (value != NULL);
+ g_assert (user_data == NULL);
+
+ directory = key;
+ files = value;
+
+ nautilus_directory_get_info_for_new_files (directory, files);
+ g_list_foreach (files, (GFunc) g_object_unref, NULL);
+ g_list_free (files);
}
static void
-invalidate_count_and_unref (gpointer key, gpointer value, gpointer user_data)
+invalidate_count_and_unref (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- g_assert (NAUTILUS_IS_DIRECTORY (key));
- g_assert (value == key);
- g_assert (user_data == NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (key));
+ g_assert (value == key);
+ g_assert (user_data == NULL);
- nautilus_directory_invalidate_count_and_mime_list (key);
- nautilus_directory_unref (key);
+ nautilus_directory_invalidate_count_and_mime_list (key);
+ nautilus_directory_unref (key);
}
static void
-collect_parent_directories (GHashTable *hash_table, NautilusDirectory *directory)
+collect_parent_directories (GHashTable *hash_table,
+ NautilusDirectory *directory)
{
- g_assert (hash_table != NULL);
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (hash_table != NULL);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
- if (g_hash_table_lookup (hash_table, directory) == NULL) {
- nautilus_directory_ref (directory);
- g_hash_table_insert (hash_table, directory, directory);
- }
+ if (g_hash_table_lookup (hash_table, directory) == NULL)
+ {
+ nautilus_directory_ref (directory);
+ g_hash_table_insert (hash_table, directory, directory);
+ }
}
void
nautilus_directory_notify_files_added (GList *files)
{
- GHashTable *added_lists;
- GList *p;
- NautilusDirectory *directory;
- GHashTable *parent_directories;
- NautilusFile *file;
- GFile *location, *parent;
-
- nautilus_profile_start (NULL);
-
- /* Make a list of added files in each directory. */
- added_lists = g_hash_table_new (NULL, NULL);
-
- /* Make a list of parent directories that will need their counts updated. */
- parent_directories = g_hash_table_new (NULL, NULL);
-
- for (p = files; p != NULL; p = p->next) {
- location = p->data;
-
- /* See if the directory is already known. */
- directory = get_parent_directory_if_exists (location);
- if (directory == NULL) {
- /* In case the directory is not being
- * monitored, but the corresponding file is,
- * we must invalidate it's item count.
- */
-
-
- file = NULL;
- parent = g_file_get_parent (location);
- if (parent) {
- file = nautilus_file_get_existing (parent);
- g_object_unref (parent);
- }
-
- if (file != NULL) {
- nautilus_file_invalidate_count_and_mime_list (file);
- nautilus_file_unref (file);
- }
-
- continue;
- }
-
- collect_parent_directories (parent_directories, directory);
-
- /* If no one is monitoring files in the directory, nothing to do. */
- if (!nautilus_directory_is_file_list_monitored (directory)) {
- nautilus_directory_unref (directory);
- continue;
- }
-
- file = nautilus_file_get_existing (location);
- /* We check is_added here, because the file could have been added
- * to the directory by a nautilus_file_get() but not gotten
- * files_added emitted
- */
- if (file && file->details->is_added) {
- /* A file already exists, it was probably renamed.
- * If it was renamed this could be ignored, but
- * queue a change just in case */
- nautilus_file_changed (file);
- nautilus_file_unref (file);
- } else {
- hash_table_list_prepend (added_lists,
- directory,
- g_object_ref (location));
- }
- nautilus_directory_unref (directory);
- }
-
- /* Now get file info for the new files. This creates NautilusFile
- * objects for the new files, and sends out a files_added signal.
- */
- g_hash_table_foreach (added_lists, call_get_file_info_free_list, NULL);
- g_hash_table_destroy (added_lists);
-
- /* Invalidate count for each parent directory. */
- g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
- g_hash_table_destroy (parent_directories);
-
- nautilus_profile_end (NULL);
-}
+ GHashTable *added_lists;
+ GList *p;
+ NautilusDirectory *directory;
+ GHashTable *parent_directories;
+ NautilusFile *file;
+ GFile *location, *parent;
+
+ nautilus_profile_start (NULL);
+
+ /* Make a list of added files in each directory. */
+ added_lists = g_hash_table_new (NULL, NULL);
+
+ /* Make a list of parent directories that will need their counts updated. */
+ parent_directories = g_hash_table_new (NULL, NULL);
+
+ for (p = files; p != NULL; p = p->next)
+ {
+ location = p->data;
+
+ /* See if the directory is already known. */
+ directory = get_parent_directory_if_exists (location);
+ if (directory == NULL)
+ {
+ /* In case the directory is not being
+ * monitored, but the corresponding file is,
+ * we must invalidate it's item count.
+ */
+
+
+ file = NULL;
+ parent = g_file_get_parent (location);
+ if (parent)
+ {
+ file = nautilus_file_get_existing (parent);
+ g_object_unref (parent);
+ }
+
+ if (file != NULL)
+ {
+ nautilus_file_invalidate_count_and_mime_list (file);
+ nautilus_file_unref (file);
+ }
+
+ continue;
+ }
-void
-nautilus_directory_notify_files_changed (GList *files)
-{
- GHashTable *changed_lists;
- GList *node;
- GFile *location;
- NautilusFile *file;
+ collect_parent_directories (parent_directories, directory);
- /* Make a list of changed files in each directory. */
- changed_lists = g_hash_table_new (NULL, NULL);
+ /* If no one is monitoring files in the directory, nothing to do. */
+ if (!nautilus_directory_is_file_list_monitored (directory))
+ {
+ nautilus_directory_unref (directory);
+ continue;
+ }
- /* Go through all the notifications. */
- for (node = files; node != NULL; node = node->next) {
- location = node->data;
+ file = nautilus_file_get_existing (location);
+ /* We check is_added here, because the file could have been added
+ * to the directory by a nautilus_file_get() but not gotten
+ * files_added emitted
+ */
+ if (file && file->details->is_added)
+ {
+ /* A file already exists, it was probably renamed.
+ * If it was renamed this could be ignored, but
+ * queue a change just in case */
+ nautilus_file_changed (file);
+ nautilus_file_unref (file);
+ }
+ else
+ {
+ hash_table_list_prepend (added_lists,
+ directory,
+ g_object_ref (location));
+ }
+ nautilus_directory_unref (directory);
+ }
- /* Find the file. */
- file = nautilus_file_get_existing (location);
- if (file != NULL) {
- /* Tell it to re-get info now, and later emit
- * a changed signal.
- */
- file->details->file_info_is_up_to_date = FALSE;
- file->details->link_info_is_up_to_date = FALSE;
- nautilus_file_invalidate_extension_info_internal (file);
+ /* Now get file info for the new files. This creates NautilusFile
+ * objects for the new files, and sends out a files_added signal.
+ */
+ g_hash_table_foreach (added_lists, call_get_file_info_free_list, NULL);
+ g_hash_table_destroy (added_lists);
- hash_table_list_prepend (changed_lists,
- file->details->directory,
- file);
- }
- }
+ /* Invalidate count for each parent directory. */
+ g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
+ g_hash_table_destroy (parent_directories);
- /* Now send out the changed signals. */
- g_hash_table_foreach (changed_lists, call_files_changed_unref_free_list, NULL);
- g_hash_table_destroy (changed_lists);
+ nautilus_profile_end (NULL);
+}
+
+void
+nautilus_directory_notify_files_changed (GList *files)
+{
+ GHashTable *changed_lists;
+ GList *node;
+ GFile *location;
+ NautilusFile *file;
+
+ /* Make a list of changed files in each directory. */
+ changed_lists = g_hash_table_new (NULL, NULL);
+
+ /* Go through all the notifications. */
+ for (node = files; node != NULL; node = node->next)
+ {
+ location = node->data;
+
+ /* Find the file. */
+ file = nautilus_file_get_existing (location);
+ if (file != NULL)
+ {
+ /* Tell it to re-get info now, and later emit
+ * a changed signal.
+ */
+ file->details->file_info_is_up_to_date = FALSE;
+ file->details->link_info_is_up_to_date = FALSE;
+ nautilus_file_invalidate_extension_info_internal (file);
+
+ hash_table_list_prepend (changed_lists,
+ file->details->directory,
+ file);
+ }
+ }
+
+ /* Now send out the changed signals. */
+ g_hash_table_foreach (changed_lists, call_files_changed_unref_free_list, NULL);
+ g_hash_table_destroy (changed_lists);
}
void
nautilus_directory_notify_files_removed (GList *files)
{
- GHashTable *changed_lists;
- GList *p;
- NautilusDirectory *directory;
- GHashTable *parent_directories;
- NautilusFile *file;
- GFile *location;
-
- /* Make a list of changed files in each directory. */
- changed_lists = g_hash_table_new (NULL, NULL);
-
- /* Make a list of parent directories that will need their counts updated. */
- parent_directories = g_hash_table_new (NULL, NULL);
-
- /* Go through all the notifications. */
- for (p = files; p != NULL; p = p->next) {
- location = p->data;
-
- /* Update file count for parent directory if anyone might care. */
- directory = get_parent_directory_if_exists (location);
- if (directory != NULL) {
- collect_parent_directories (parent_directories, directory);
- nautilus_directory_unref (directory);
- }
-
- /* Find the file. */
- file = nautilus_file_get_existing (location);
- if (file != NULL && !nautilus_file_rename_in_progress (file)) {
- /* Mark it gone and prepare to send the changed signal. */
- nautilus_file_mark_gone (file);
- hash_table_list_prepend (changed_lists,
- file->details->directory,
- nautilus_file_ref (file));
- }
- nautilus_file_unref (file);
- }
-
- /* Now send out the changed signals. */
- g_hash_table_foreach (changed_lists, call_files_changed_unref_free_list, NULL);
- g_hash_table_destroy (changed_lists);
-
- /* Invalidate count for each parent directory. */
- g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
- g_hash_table_destroy (parent_directories);
+ GHashTable *changed_lists;
+ GList *p;
+ NautilusDirectory *directory;
+ GHashTable *parent_directories;
+ NautilusFile *file;
+ GFile *location;
+
+ /* Make a list of changed files in each directory. */
+ changed_lists = g_hash_table_new (NULL, NULL);
+
+ /* Make a list of parent directories that will need their counts updated. */
+ parent_directories = g_hash_table_new (NULL, NULL);
+
+ /* Go through all the notifications. */
+ for (p = files; p != NULL; p = p->next)
+ {
+ location = p->data;
+
+ /* Update file count for parent directory if anyone might care. */
+ directory = get_parent_directory_if_exists (location);
+ if (directory != NULL)
+ {
+ collect_parent_directories (parent_directories, directory);
+ nautilus_directory_unref (directory);
+ }
+
+ /* Find the file. */
+ file = nautilus_file_get_existing (location);
+ if (file != NULL && !nautilus_file_rename_in_progress (file))
+ {
+ /* Mark it gone and prepare to send the changed signal. */
+ nautilus_file_mark_gone (file);
+ hash_table_list_prepend (changed_lists,
+ file->details->directory,
+ nautilus_file_ref (file));
+ }
+ nautilus_file_unref (file);
+ }
+
+ /* Now send out the changed signals. */
+ g_hash_table_foreach (changed_lists, call_files_changed_unref_free_list, NULL);
+ g_hash_table_destroy (changed_lists);
+
+ /* Invalidate count for each parent directory. */
+ g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
+ g_hash_table_destroy (parent_directories);
}
static void
set_directory_location (NautilusDirectory *directory,
- GFile *location)
+ GFile *location)
{
- if (directory->details->location) {
- g_object_unref (directory->details->location);
- }
- directory->details->location = g_object_ref (location);
+ if (directory->details->location)
+ {
+ g_object_unref (directory->details->location);
+ }
+ directory->details->location = g_object_ref (location);
- g_object_notify_by_pspec (G_OBJECT (directory), properties[PROP_LOCATION]);
+ g_object_notify_by_pspec (G_OBJECT (directory), properties[PROP_LOCATION]);
}
static void
change_directory_location (NautilusDirectory *directory,
- GFile *new_location)
+ GFile *new_location)
{
- /* I believe it's impossible for a self-owned file/directory
- * to be moved. But if that did somehow happen, this function
- * wouldn't do enough to handle it.
- */
- g_assert (directory->details->as_file == NULL);
+ /* I believe it's impossible for a self-owned file/directory
+ * to be moved. But if that did somehow happen, this function
+ * wouldn't do enough to handle it.
+ */
+ g_assert (directory->details->as_file == NULL);
- g_hash_table_remove (directories,
- directory->details->location);
+ g_hash_table_remove (directories,
+ directory->details->location);
- set_directory_location (directory, new_location);
+ set_directory_location (directory, new_location);
- g_hash_table_insert (directories,
- directory->details->location,
- directory);
+ g_hash_table_insert (directories,
+ directory->details->location,
+ directory);
}
-typedef struct {
- GFile *container;
- GList *directories;
+typedef struct
+{
+ GFile *container;
+ GList *directories;
} CollectData;
static void
-collect_directories_by_container (gpointer key, gpointer value, gpointer callback_data)
+collect_directories_by_container (gpointer key,
+ gpointer value,
+ gpointer callback_data)
{
- NautilusDirectory *directory;
- CollectData *collect_data;
- GFile *location;
+ NautilusDirectory *directory;
+ CollectData *collect_data;
+ GFile *location;
- location = (GFile *) key;
- directory = NAUTILUS_DIRECTORY (value);
- collect_data = (CollectData *) callback_data;
+ location = (GFile *) key;
+ directory = NAUTILUS_DIRECTORY (value);
+ collect_data = (CollectData *) callback_data;
- if (g_file_has_prefix (location, collect_data->container) ||
- g_file_equal (collect_data->container, location)) {
- nautilus_directory_ref (directory);
- collect_data->directories =
- g_list_prepend (collect_data->directories,
- directory);
- }
+ if (g_file_has_prefix (location, collect_data->container) ||
+ g_file_equal (collect_data->container, location))
+ {
+ nautilus_directory_ref (directory);
+ collect_data->directories =
+ g_list_prepend (collect_data->directories,
+ directory);
+ }
}
static GList *
nautilus_directory_moved_internal (GFile *old_location,
- GFile *new_location)
-{
- CollectData collection;
- NautilusDirectory *directory;
- GList *node, *affected_files;
- GFile *new_directory_location;
- char *relative_path;
-
- collection.container = old_location;
- collection.directories = NULL;
-
- g_hash_table_foreach (directories,
- collect_directories_by_container,
- &collection);
-
- affected_files = NULL;
-
- for (node = collection.directories; node != NULL; node = node->next) {
- directory = NAUTILUS_DIRECTORY (node->data);
- new_directory_location = NULL;
-
- if (g_file_equal (directory->details->location, old_location)) {
- new_directory_location = g_object_ref (new_location);
- } else {
- relative_path = g_file_get_relative_path (old_location,
- directory->details->location);
- if (relative_path != NULL) {
- new_directory_location = g_file_resolve_relative_path (new_location, relative_path);
- g_free (relative_path);
-
- }
- }
-
- if (new_directory_location) {
- change_directory_location (directory, new_directory_location);
- g_object_unref (new_directory_location);
-
- /* Collect affected files. */
- if (directory->details->as_file != NULL) {
- affected_files = g_list_prepend
- (affected_files,
- nautilus_file_ref (directory->details->as_file));
- }
- affected_files = g_list_concat
- (affected_files,
- nautilus_file_list_copy (directory->details->file_list));
- }
-
- nautilus_directory_unref (directory);
- }
-
- g_list_free (collection.directories);
-
- return affected_files;
+ GFile *new_location)
+{
+ CollectData collection;
+ NautilusDirectory *directory;
+ GList *node, *affected_files;
+ GFile *new_directory_location;
+ char *relative_path;
+
+ collection.container = old_location;
+ collection.directories = NULL;
+
+ g_hash_table_foreach (directories,
+ collect_directories_by_container,
+ &collection);
+
+ affected_files = NULL;
+
+ for (node = collection.directories; node != NULL; node = node->next)
+ {
+ directory = NAUTILUS_DIRECTORY (node->data);
+ new_directory_location = NULL;
+
+ if (g_file_equal (directory->details->location, old_location))
+ {
+ new_directory_location = g_object_ref (new_location);
+ }
+ else
+ {
+ relative_path = g_file_get_relative_path (old_location,
+ directory->details->location);
+ if (relative_path != NULL)
+ {
+ new_directory_location = g_file_resolve_relative_path (new_location, relative_path);
+ g_free (relative_path);
+ }
+ }
+
+ if (new_directory_location)
+ {
+ change_directory_location (directory, new_directory_location);
+ g_object_unref (new_directory_location);
+
+ /* Collect affected files. */
+ if (directory->details->as_file != NULL)
+ {
+ affected_files = g_list_prepend
+ (affected_files,
+ nautilus_file_ref (directory->details->as_file));
+ }
+ affected_files = g_list_concat
+ (affected_files,
+ nautilus_file_list_copy (directory->details->file_list));
+ }
+
+ nautilus_directory_unref (directory);
+ }
+
+ g_list_free (collection.directories);
+
+ return affected_files;
}
void
nautilus_directory_moved (const char *old_uri,
- const char *new_uri)
-{
- GList *list, *node;
- GHashTable *hash;
- NautilusFile *file;
- GFile *old_location;
- GFile *new_location;
-
- hash = g_hash_table_new (NULL, NULL);
-
- old_location = g_file_new_for_uri (old_uri);
- new_location = g_file_new_for_uri (new_uri);
-
- list = nautilus_directory_moved_internal (old_location, new_location);
- for (node = list; node != NULL; node = node->next) {
- file = NAUTILUS_FILE (node->data);
- hash_table_list_prepend (hash,
- file->details->directory,
- nautilus_file_ref (file));
- }
- nautilus_file_list_free (list);
-
- g_object_unref (old_location);
- g_object_unref (new_location);
-
- g_hash_table_foreach (hash, call_files_changed_unref_free_list, NULL);
- g_hash_table_destroy (hash);
+ const char *new_uri)
+{
+ GList *list, *node;
+ GHashTable *hash;
+ NautilusFile *file;
+ GFile *old_location;
+ GFile *new_location;
+
+ hash = g_hash_table_new (NULL, NULL);
+
+ old_location = g_file_new_for_uri (old_uri);
+ new_location = g_file_new_for_uri (new_uri);
+
+ list = nautilus_directory_moved_internal (old_location, new_location);
+ for (node = list; node != NULL; node = node->next)
+ {
+ file = NAUTILUS_FILE (node->data);
+ hash_table_list_prepend (hash,
+ file->details->directory,
+ nautilus_file_ref (file));
+ }
+ nautilus_file_list_free (list);
+
+ g_object_unref (old_location);
+ g_object_unref (new_location);
+
+ g_hash_table_foreach (hash, call_files_changed_unref_free_list, NULL);
+ g_hash_table_destroy (hash);
}
void
nautilus_directory_notify_files_moved (GList *file_pairs)
{
- GList *p, *affected_files, *node;
- GFilePair *pair;
- NautilusFile *file;
- NautilusDirectory *old_directory, *new_directory;
- GHashTable *parent_directories;
- GList *new_files_list, *unref_list;
- GHashTable *added_lists, *changed_lists;
- char *name;
- NautilusFileAttributes cancel_attributes;
- GFile *to_location, *from_location;
-
- /* Make a list of added and changed files in each directory. */
- new_files_list = NULL;
- added_lists = g_hash_table_new (NULL, NULL);
- changed_lists = g_hash_table_new (NULL, NULL);
- unref_list = NULL;
-
- /* Make a list of parent directories that will need their counts updated. */
- parent_directories = g_hash_table_new (NULL, NULL);
-
- cancel_attributes = nautilus_file_get_all_attributes ();
-
- for (p = file_pairs; p != NULL; p = p->next) {
- pair = p->data;
- from_location = pair->from;
- to_location = pair->to;
-
- /* Handle overwriting a file. */
- file = nautilus_file_get_existing (to_location);
- if (file != NULL) {
- /* Mark it gone and prepare to send the changed signal. */
- nautilus_file_mark_gone (file);
- new_directory = file->details->directory;
- hash_table_list_prepend (changed_lists,
- new_directory,
- file);
- collect_parent_directories (parent_directories,
- new_directory);
- }
-
- /* Update any directory objects that are affected. */
- affected_files = nautilus_directory_moved_internal (from_location,
- to_location);
- for (node = affected_files; node != NULL; node = node->next) {
- file = NAUTILUS_FILE (node->data);
- hash_table_list_prepend (changed_lists,
- file->details->directory,
- file);
- }
- unref_list = g_list_concat (unref_list, affected_files);
-
- /* Move an existing file. */
- file = nautilus_file_get_existing (from_location);
- if (file == NULL) {
- /* Handle this as if it was a new file. */
- new_files_list = g_list_prepend (new_files_list,
- to_location);
- } else {
- /* Handle notification in the old directory. */
- old_directory = file->details->directory;
- collect_parent_directories (parent_directories, old_directory);
-
- /* Cancel loading of attributes in the old directory */
- nautilus_directory_cancel_loading_file_attributes
- (old_directory, file, cancel_attributes);
-
- /* Locate the new directory. */
- new_directory = get_parent_directory (to_location);
- collect_parent_directories (parent_directories, new_directory);
- /* We can unref now -- new_directory is in the
- * parent directories list so it will be
- * around until the end of this function
- * anyway.
- */
- nautilus_directory_unref (new_directory);
-
- /* Update the file's name and directory. */
- name = g_file_get_basename (to_location);
- nautilus_file_update_name_and_directory
- (file, name, new_directory);
- g_free (name);
-
- /* Update file attributes */
- nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_INFO);
-
- hash_table_list_prepend (changed_lists,
- old_directory,
- file);
- if (old_directory != new_directory) {
- hash_table_list_prepend (added_lists,
- new_directory,
- file);
- }
-
- /* Unref each file once to balance out nautilus_file_get_by_uri. */
- unref_list = g_list_prepend (unref_list, file);
- }
- }
-
- /* Now send out the changed and added signals for existing file objects. */
- g_hash_table_foreach (changed_lists, call_files_changed_free_list, NULL);
- g_hash_table_destroy (changed_lists);
- g_hash_table_foreach (added_lists, call_files_added_free_list, NULL);
- g_hash_table_destroy (added_lists);
-
- /* Let the file objects go. */
- nautilus_file_list_free (unref_list);
-
- /* Invalidate count for each parent directory. */
- g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
- g_hash_table_destroy (parent_directories);
-
- /* Separate handling for brand new file objects. */
- nautilus_directory_notify_files_added (new_files_list);
- g_list_free (new_files_list);
+ GList *p, *affected_files, *node;
+ GFilePair *pair;
+ NautilusFile *file;
+ NautilusDirectory *old_directory, *new_directory;
+ GHashTable *parent_directories;
+ GList *new_files_list, *unref_list;
+ GHashTable *added_lists, *changed_lists;
+ char *name;
+ NautilusFileAttributes cancel_attributes;
+ GFile *to_location, *from_location;
+
+ /* Make a list of added and changed files in each directory. */
+ new_files_list = NULL;
+ added_lists = g_hash_table_new (NULL, NULL);
+ changed_lists = g_hash_table_new (NULL, NULL);
+ unref_list = NULL;
+
+ /* Make a list of parent directories that will need their counts updated. */
+ parent_directories = g_hash_table_new (NULL, NULL);
+
+ cancel_attributes = nautilus_file_get_all_attributes ();
+
+ for (p = file_pairs; p != NULL; p = p->next)
+ {
+ pair = p->data;
+ from_location = pair->from;
+ to_location = pair->to;
+
+ /* Handle overwriting a file. */
+ file = nautilus_file_get_existing (to_location);
+ if (file != NULL)
+ {
+ /* Mark it gone and prepare to send the changed signal. */
+ nautilus_file_mark_gone (file);
+ new_directory = file->details->directory;
+ hash_table_list_prepend (changed_lists,
+ new_directory,
+ file);
+ collect_parent_directories (parent_directories,
+ new_directory);
+ }
+
+ /* Update any directory objects that are affected. */
+ affected_files = nautilus_directory_moved_internal (from_location,
+ to_location);
+ for (node = affected_files; node != NULL; node = node->next)
+ {
+ file = NAUTILUS_FILE (node->data);
+ hash_table_list_prepend (changed_lists,
+ file->details->directory,
+ file);
+ }
+ unref_list = g_list_concat (unref_list, affected_files);
+
+ /* Move an existing file. */
+ file = nautilus_file_get_existing (from_location);
+ if (file == NULL)
+ {
+ /* Handle this as if it was a new file. */
+ new_files_list = g_list_prepend (new_files_list,
+ to_location);
+ }
+ else
+ {
+ /* Handle notification in the old directory. */
+ old_directory = file->details->directory;
+ collect_parent_directories (parent_directories, old_directory);
+
+ /* Cancel loading of attributes in the old directory */
+ nautilus_directory_cancel_loading_file_attributes
+ (old_directory, file, cancel_attributes);
+
+ /* Locate the new directory. */
+ new_directory = get_parent_directory (to_location);
+ collect_parent_directories (parent_directories, new_directory);
+ /* We can unref now -- new_directory is in the
+ * parent directories list so it will be
+ * around until the end of this function
+ * anyway.
+ */
+ nautilus_directory_unref (new_directory);
+
+ /* Update the file's name and directory. */
+ name = g_file_get_basename (to_location);
+ nautilus_file_update_name_and_directory
+ (file, name, new_directory);
+ g_free (name);
+
+ /* Update file attributes */
+ nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_INFO);
+
+ hash_table_list_prepend (changed_lists,
+ old_directory,
+ file);
+ if (old_directory != new_directory)
+ {
+ hash_table_list_prepend (added_lists,
+ new_directory,
+ file);
+ }
+
+ /* Unref each file once to balance out nautilus_file_get_by_uri. */
+ unref_list = g_list_prepend (unref_list, file);
+ }
+ }
+
+ /* Now send out the changed and added signals for existing file objects. */
+ g_hash_table_foreach (changed_lists, call_files_changed_free_list, NULL);
+ g_hash_table_destroy (changed_lists);
+ g_hash_table_foreach (added_lists, call_files_added_free_list, NULL);
+ g_hash_table_destroy (added_lists);
+
+ /* Let the file objects go. */
+ nautilus_file_list_free (unref_list);
+
+ /* Invalidate count for each parent directory. */
+ g_hash_table_foreach (parent_directories, invalidate_count_and_unref, NULL);
+ g_hash_table_destroy (parent_directories);
+
+ /* Separate handling for brand new file objects. */
+ nautilus_directory_notify_files_added (new_files_list);
+ g_list_free (new_files_list);
}
void
nautilus_directory_schedule_position_set (GList *position_setting_list)
{
- GList *p;
- const NautilusFileChangesQueuePosition *item;
- NautilusFile *file;
- char str[64];
- time_t now;
-
- time (&now);
-
- for (p = position_setting_list; p != NULL; p = p->next) {
- item = (NautilusFileChangesQueuePosition *) p->data;
-
- file = nautilus_file_get (item->location);
-
- if (item->set) {
- g_snprintf (str, sizeof (str), "%d,%d", item->point.x, item->point.y);
- } else {
- str[0] = 0;
- }
- nautilus_file_set_metadata
- (file,
- NAUTILUS_METADATA_KEY_ICON_POSITION,
- NULL,
- str);
-
- if (item->set) {
- nautilus_file_set_time_metadata
- (file,
- NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
- now);
- } else {
- nautilus_file_set_time_metadata
- (file,
- NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
- UNDEFINED_TIME);
- }
-
- if (item->set) {
- g_snprintf (str, sizeof (str), "%d", item->screen);
- } else {
- str[0] = 0;
- }
- nautilus_file_set_metadata
- (file,
- NAUTILUS_METADATA_KEY_SCREEN,
- NULL,
- str);
-
- nautilus_file_unref (file);
- }
+ GList *p;
+ const NautilusFileChangesQueuePosition *item;
+ NautilusFile *file;
+ char str[64];
+ time_t now;
+
+ time (&now);
+
+ for (p = position_setting_list; p != NULL; p = p->next)
+ {
+ item = (NautilusFileChangesQueuePosition *) p->data;
+
+ file = nautilus_file_get (item->location);
+
+ if (item->set)
+ {
+ g_snprintf (str, sizeof (str), "%d,%d", item->point.x, item->point.y);
+ }
+ else
+ {
+ str[0] = 0;
+ }
+ nautilus_file_set_metadata
+ (file,
+ NAUTILUS_METADATA_KEY_ICON_POSITION,
+ NULL,
+ str);
+
+ if (item->set)
+ {
+ nautilus_file_set_time_metadata
+ (file,
+ NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
+ now);
+ }
+ else
+ {
+ nautilus_file_set_time_metadata
+ (file,
+ NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
+ UNDEFINED_TIME);
+ }
+
+ if (item->set)
+ {
+ g_snprintf (str, sizeof (str), "%d", item->screen);
+ }
+ else
+ {
+ str[0] = 0;
+ }
+ nautilus_file_set_metadata
+ (file,
+ NAUTILUS_METADATA_KEY_SCREEN,
+ NULL,
+ str);
+
+ nautilus_file_unref (file);
+ }
}
gboolean
nautilus_directory_contains_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- if (nautilus_file_is_gone (file)) {
- return FALSE;
- }
+ if (nautilus_file_is_gone (file))
+ {
+ return FALSE;
+ }
- return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->contains_file (directory, file);
+ return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->contains_file (directory, file);
}
-NautilusFile*
+NautilusFile *
nautilus_directory_get_file_by_name (NautilusDirectory *directory,
const gchar *name)
{
- GList *files;
- GList *l;
- NautilusFile *result = NULL;
+ GList *files;
+ GList *l;
+ NautilusFile *result = NULL;
- files = nautilus_directory_get_file_list (directory);
+ files = nautilus_directory_get_file_list (directory);
- for (l = files; l != NULL; l = l->next) {
- if (nautilus_file_compare_display_name (l->data, name) == 0) {
- result = nautilus_file_ref (l->data);
- break;
- }
+ for (l = files; l != NULL; l = l->next)
+ {
+ if (nautilus_file_compare_display_name (l->data, name) == 0)
+ {
+ result = nautilus_file_ref (l->data);
+ break;
}
+ }
- nautilus_file_list_free (files);
+ nautilus_file_list_free (files);
- return result;
+ return result;
}
void
-nautilus_directory_call_when_ready (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes,
- gboolean wait_for_all_files,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+nautilus_directory_call_when_ready (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes,
+ gboolean wait_for_all_files,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
- g_return_if_fail (callback != NULL);
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ g_return_if_fail (callback != NULL);
- NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->call_when_ready
- (directory, file_attributes, wait_for_all_files,
- callback, callback_data);
+ NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->call_when_ready
+ (directory, file_attributes, wait_for_all_files,
+ callback, callback_data);
}
void
-nautilus_directory_cancel_callback (NautilusDirectory *directory,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+nautilus_directory_cancel_callback (NautilusDirectory *directory,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
- g_return_if_fail (callback != NULL);
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ g_return_if_fail (callback != NULL);
- NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->cancel_callback
- (directory, callback, callback_data);
+ NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->cancel_callback
+ (directory, callback, callback_data);
}
void
-nautilus_directory_file_monitor_add (NautilusDirectory *directory,
- gconstpointer client,
- gboolean monitor_hidden_files,
- NautilusFileAttributes file_attributes,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+nautilus_directory_file_monitor_add (NautilusDirectory *directory,
+ gconstpointer client,
+ gboolean monitor_hidden_files,
+ NautilusFileAttributes file_attributes,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
- g_return_if_fail (client != NULL);
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ g_return_if_fail (client != NULL);
- NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->file_monitor_add
- (directory, client,
- monitor_hidden_files,
- file_attributes,
- callback, callback_data);
+ NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->file_monitor_add
+ (directory, client,
+ monitor_hidden_files,
+ file_attributes,
+ callback, callback_data);
}
void
nautilus_directory_file_monitor_remove (NautilusDirectory *directory,
- gconstpointer client)
+ gconstpointer client)
{
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
- g_return_if_fail (client != NULL);
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ g_return_if_fail (client != NULL);
- NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->file_monitor_remove
- (directory, client);
+ NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->file_monitor_remove
+ (directory, client);
}
void
nautilus_directory_force_reload (NautilusDirectory *directory)
{
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
- NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->force_reload (directory);
+ NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->force_reload (directory);
}
gboolean
nautilus_directory_is_not_empty (NautilusDirectory *directory)
{
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), FALSE);
- return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->is_not_empty (directory);
+ return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->is_not_empty (directory);
}
static gboolean
is_tentative (NautilusFile *file,
gpointer callback_data)
{
- g_assert (callback_data == NULL);
+ g_assert (callback_data == NULL);
- /* Avoid returning files with !is_added, because these
- * will later be sent with the files_added signal, and a
- * user doing get_file_list + files_added monitoring will
- * then see the file twice */
- return !file->details->got_file_info || !file->details->is_added;
+ /* Avoid returning files with !is_added, because these
+ * will later be sent with the files_added signal, and a
+ * user doing get_file_list + files_added monitoring will
+ * then see the file twice */
+ return !file->details->got_file_info || !file->details->is_added;
}
GList *
nautilus_directory_get_file_list (NautilusDirectory *directory)
{
- return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->get_file_list (directory);
+ return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->get_file_list (directory);
}
static GList *
real_get_file_list (NautilusDirectory *directory)
{
- GList *tentative_files, *non_tentative_files;
+ GList *tentative_files, *non_tentative_files;
- tentative_files = nautilus_file_list_filter (directory->details->file_list,
- &non_tentative_files, is_tentative, NULL);
- nautilus_file_list_free (tentative_files);
+ tentative_files = nautilus_file_list_filter (directory->details->file_list,
+ &non_tentative_files, is_tentative, NULL);
+ nautilus_file_list_free (tentative_files);
- return non_tentative_files;
+ return non_tentative_files;
}
static gboolean
real_is_editable (NautilusDirectory *directory)
{
- return TRUE;
+ return TRUE;
}
gboolean
nautilus_directory_is_editable (NautilusDirectory *directory)
{
- return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->is_editable (directory);
+ return NAUTILUS_DIRECTORY_CLASS (G_OBJECT_GET_CLASS (directory))->is_editable (directory);
}
GList *
-nautilus_directory_match_pattern (NautilusDirectory *directory, const char *pattern)
+nautilus_directory_match_pattern (NautilusDirectory *directory,
+ const char *pattern)
{
- GList *files, *l, *ret;
- GPatternSpec *spec;
+ GList *files, *l, *ret;
+ GPatternSpec *spec;
- ret = NULL;
- spec = g_pattern_spec_new (pattern);
-
- files = nautilus_directory_get_file_list (directory);
- for (l = files; l; l = l->next) {
- NautilusFile *file;
- char *name;
-
- file = NAUTILUS_FILE (l->data);
- name = nautilus_file_get_display_name (file);
+ ret = NULL;
+ spec = g_pattern_spec_new (pattern);
- if (g_pattern_match_string (spec, name)) {
- ret = g_list_prepend(ret, nautilus_file_ref (file));
- }
+ files = nautilus_directory_get_file_list (directory);
+ for (l = files; l; l = l->next)
+ {
+ NautilusFile *file;
+ char *name;
- g_free (name);
- }
+ file = NAUTILUS_FILE (l->data);
+ name = nautilus_file_get_display_name (file);
- g_pattern_spec_free (spec);
- nautilus_file_list_free (files);
+ if (g_pattern_match_string (spec, name))
+ {
+ ret = g_list_prepend (ret, nautilus_file_ref (file));
+ }
+
+ g_free (name);
+ }
- return ret;
+ g_pattern_spec_free (spec);
+ nautilus_file_list_free (files);
+
+ return ret;
}
/**
@@ -1724,8 +1864,8 @@ nautilus_directory_match_pattern (NautilusDirectory *directory, const char *patt
GList *
nautilus_directory_list_ref (GList *list)
{
- g_list_foreach (list, (GFunc) nautilus_directory_ref, NULL);
- return list;
+ g_list_foreach (list, (GFunc) nautilus_directory_ref, NULL);
+ return list;
}
/**
@@ -1737,7 +1877,7 @@ nautilus_directory_list_ref (GList *list)
void
nautilus_directory_list_unref (GList *list)
{
- g_list_foreach (list, (GFunc) nautilus_directory_unref, NULL);
+ g_list_foreach (list, (GFunc) nautilus_directory_unref, NULL);
}
/**
@@ -1749,8 +1889,8 @@ nautilus_directory_list_unref (GList *list)
void
nautilus_directory_list_free (GList *list)
{
- nautilus_directory_list_unref (list);
- g_list_free (list);
+ nautilus_directory_list_unref (list);
+ g_list_free (list);
}
/**
@@ -1762,42 +1902,44 @@ nautilus_directory_list_free (GList *list)
GList *
nautilus_directory_list_copy (GList *list)
{
- return g_list_copy (nautilus_directory_list_ref (list));
+ return g_list_copy (nautilus_directory_list_ref (list));
}
static int
-compare_by_uri (NautilusDirectory *a, NautilusDirectory *b)
+compare_by_uri (NautilusDirectory *a,
+ NautilusDirectory *b)
{
- char *uri_a, *uri_b;
- int res;
+ char *uri_a, *uri_b;
+ int res;
+
+ uri_a = g_file_get_uri (a->details->location);
+ uri_b = g_file_get_uri (b->details->location);
- uri_a = g_file_get_uri (a->details->location);
- uri_b = g_file_get_uri (b->details->location);
-
- res = strcmp (uri_a, uri_b);
+ res = strcmp (uri_a, uri_b);
- g_free (uri_a);
- g_free (uri_b);
-
- return res;
+ g_free (uri_a);
+ g_free (uri_b);
+
+ return res;
}
static int
-compare_by_uri_cover (gconstpointer a, gconstpointer b)
+compare_by_uri_cover (gconstpointer a,
+ gconstpointer b)
{
- return compare_by_uri (NAUTILUS_DIRECTORY (a), NAUTILUS_DIRECTORY (b));
+ return compare_by_uri (NAUTILUS_DIRECTORY (a), NAUTILUS_DIRECTORY (b));
}
/**
* nautilus_directory_list_sort_by_uri
- *
+ *
* Sort the list of directories by directory uri.
* @list: GList of directories.
**/
GList *
nautilus_directory_list_sort_by_uri (GList *list)
{
- return g_list_sort (list, compare_by_uri_cover);
+ return g_list_sort (list, compare_by_uri_cover);
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
@@ -1809,116 +1951,120 @@ static int data_dummy;
static gboolean got_files_flag;
static void
-got_files_callback (NautilusDirectory *directory, GList *files, gpointer callback_data)
+got_files_callback (NautilusDirectory *directory,
+ GList *files,
+ gpointer callback_data)
{
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (g_list_length (files) > 10);
- g_assert (callback_data == &data_dummy);
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (g_list_length (files) > 10);
+ g_assert (callback_data == &data_dummy);
- got_files_flag = TRUE;
+ got_files_flag = TRUE;
}
/* Return the number of extant NautilusDirectories */
int
nautilus_directory_number_outstanding (void)
{
- return directories ? g_hash_table_size (directories) : 0;
+ return directories ? g_hash_table_size (directories) : 0;
}
void
nautilus_directory_dump (NautilusDirectory *directory)
{
- g_autofree gchar *uri;
+ g_autofree gchar *uri;
- uri = g_file_get_uri (directory->details->location);
- g_print ("uri: %s\n", uri);
- g_print ("ref count: %d\n", G_OBJECT (directory)->ref_count);
+ uri = g_file_get_uri (directory->details->location);
+ g_print ("uri: %s\n", uri);
+ g_print ("ref count: %d\n", G_OBJECT (directory)->ref_count);
}
void
nautilus_self_check_directory (void)
{
- NautilusDirectory *directory;
- NautilusFile *file;
-
- directory = nautilus_directory_get_by_uri ("file:///etc");
- file = nautilus_file_get_by_uri ("file:///etc/passwd");
+ NautilusDirectory *directory;
+ NautilusFile *file;
- EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);
+ directory = nautilus_directory_get_by_uri ("file:///etc");
+ file = nautilus_file_get_by_uri ("file:///etc/passwd");
- nautilus_directory_file_monitor_add
- (directory, &data_dummy,
- TRUE, 0, NULL, NULL);
+ EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);
- /* FIXME: these need to be updated to the new metadata infrastructure
- * as make check doesn't pass.
- nautilus_file_set_metadata (file, "test", "default", "value");
- EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value");
+ nautilus_directory_file_monitor_add
+ (directory, &data_dummy,
+ TRUE, 0, NULL, NULL);
- nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), TRUE);
- nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, FALSE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), FALSE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "test_boolean", TRUE), TRUE);
+ /* FIXME: these need to be updated to the new metadata infrastructure
+ * as make check doesn't pass.
+ * nautilus_file_set_metadata (file, "test", "default", "value");
+ * EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value");
+ *
+ * nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, TRUE);
+ * EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), TRUE);
+ * nautilus_file_set_boolean_metadata (file, "test_boolean", TRUE, FALSE);
+ * EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (file, "test_boolean", TRUE), FALSE);
+ * EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_boolean_metadata (NULL, "test_boolean", TRUE), TRUE);
+ *
+ * nautilus_file_set_integer_metadata (file, "test_integer", 0, 17);
+ * EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), 17);
+ * nautilus_file_set_integer_metadata (file, "test_integer", 0, -1);
+ * EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), -1);
+ * nautilus_file_set_integer_metadata (file, "test_integer", 42, 42);
+ * EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 42), 42);
+ * EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (NULL, "test_integer", 42), 42);
+ * EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "nonexistent_key", 42), 42);
+ */
- nautilus_file_set_integer_metadata (file, "test_integer", 0, 17);
- EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), 17);
- nautilus_file_set_integer_metadata (file, "test_integer", 0, -1);
- EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 0), -1);
- nautilus_file_set_integer_metadata (file, "test_integer", 42, 42);
- EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "test_integer", 42), 42);
- EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (NULL, "test_integer", 42), 42);
- EEL_CHECK_INTEGER_RESULT (nautilus_file_get_integer_metadata (file, "nonexistent_key", 42), 42);
- */
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc") == directory, TRUE);
+ nautilus_directory_unref (directory);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc") == directory, TRUE);
- nautilus_directory_unref (directory);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc/") == directory, TRUE);
+ nautilus_directory_unref (directory);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc/") == directory, TRUE);
- nautilus_directory_unref (directory);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc////") == directory, TRUE);
+ nautilus_directory_unref (directory);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_directory_get_by_uri ("file:///etc////") == directory, TRUE);
- nautilus_directory_unref (directory);
+ nautilus_file_unref (file);
- nautilus_file_unref (file);
+ nautilus_directory_file_monitor_remove (directory, &data_dummy);
- nautilus_directory_file_monitor_remove (directory, &data_dummy);
+ nautilus_directory_unref (directory);
- nautilus_directory_unref (directory);
+ while (g_hash_table_size (directories) != 0)
+ {
+ gtk_main_iteration ();
+ }
- while (g_hash_table_size (directories) != 0) {
- gtk_main_iteration ();
- }
+ EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0);
- EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0);
+ directory = nautilus_directory_get_by_uri ("file:///etc");
- directory = nautilus_directory_get_by_uri ("file:///etc");
+ got_files_flag = FALSE;
- got_files_flag = FALSE;
+ nautilus_directory_call_when_ready (directory,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS,
+ TRUE,
+ got_files_callback, &data_dummy);
- nautilus_directory_call_when_ready (directory,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS,
- TRUE,
- got_files_callback, &data_dummy);
+ while (!got_files_flag)
+ {
+ gtk_main_iteration ();
+ }
- while (!got_files_flag) {
- gtk_main_iteration ();
- }
+ EEL_CHECK_BOOLEAN_RESULT (directory->details->file_list == NULL, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (directory->details->file_list == NULL, TRUE);
+ EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);
- EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 1);
+ file = nautilus_file_get_by_uri ("file:///etc/passwd");
- file = nautilus_file_get_by_uri ("file:///etc/passwd");
+ /* EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value"); */
- /* EEL_CHECK_STRING_RESULT (nautilus_file_get_metadata (file, "test", "default"), "value"); */
-
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
- EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0);
+ EEL_CHECK_INTEGER_RESULT (g_hash_table_size (directories), 0);
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/nautilus-dnd.c b/src/nautilus-dnd.c
index 1731b473b..fb5ebeca1 100644
--- a/src/nautilus-dnd.c
+++ b/src/nautilus-dnd.c
@@ -1,26 +1,25 @@
-
/* nautilus-dnd.c - Common Drag & drop handling code shared by the icon container
- and the list view.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Pavel Cisler <pavel@eazel.com>,
- Ettore Perazzoli <ettore@gnu.org>
-*/
+ * and the list view.
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Pavel Cisler <pavel@eazel.com>,
+ * Ettore Perazzoli <ettore@gnu.org>
+ */
#include <config.h>
#include "nautilus-dnd.h"
@@ -52,7 +51,7 @@
* margin
*/
#define MIN_AUTOSCROLL_DELTA 5
-
+
/* the largest amount of auto scroll used when we are right over the view
* edge
*/
@@ -60,30 +59,31 @@
void
nautilus_drag_init (NautilusDragInfo *drag_info,
- const GtkTargetEntry *drag_types,
- int drag_type_count,
- gboolean add_text_targets)
+ const GtkTargetEntry *drag_types,
+ int drag_type_count,
+ gboolean add_text_targets)
{
- drag_info->target_list = gtk_target_list_new (drag_types,
- drag_type_count);
+ drag_info->target_list = gtk_target_list_new (drag_types,
+ drag_type_count);
- if (add_text_targets) {
- gtk_target_list_add_text_targets (drag_info->target_list,
- NAUTILUS_ICON_DND_TEXT);
- }
+ if (add_text_targets)
+ {
+ gtk_target_list_add_text_targets (drag_info->target_list,
+ NAUTILUS_ICON_DND_TEXT);
+ }
- drag_info->drop_occured = FALSE;
- drag_info->need_to_destroy = FALSE;
+ drag_info->drop_occured = FALSE;
+ drag_info->need_to_destroy = FALSE;
}
void
nautilus_drag_finalize (NautilusDragInfo *drag_info)
{
- gtk_target_list_unref (drag_info->target_list);
- nautilus_drag_destroy_selection_list (drag_info->selection_list);
- nautilus_drag_destroy_selection_list (drag_info->selection_cache);
+ gtk_target_list_unref (drag_info->target_list);
+ nautilus_drag_destroy_selection_list (drag_info->selection_list);
+ nautilus_drag_destroy_selection_list (drag_info->selection_cache);
- g_free (drag_info);
+ g_free (drag_info);
}
@@ -92,47 +92,53 @@ nautilus_drag_finalize (NautilusDragInfo *drag_info)
NautilusDragSelectionItem *
nautilus_drag_selection_item_new (void)
{
- return g_new0 (NautilusDragSelectionItem, 1);
+ return g_new0 (NautilusDragSelectionItem, 1);
}
static void
drag_selection_item_destroy (NautilusDragSelectionItem *item)
{
- g_clear_object (&item->file);
- g_free (item->uri);
- g_free (item);
+ g_clear_object (&item->file);
+ g_free (item->uri);
+ g_free (item);
}
void
nautilus_drag_destroy_selection_list (GList *list)
{
- GList *p;
+ GList *p;
- if (list == NULL)
- return;
+ if (list == NULL)
+ {
+ return;
+ }
- for (p = list; p != NULL; p = p->next)
- drag_selection_item_destroy (p->data);
+ for (p = list; p != NULL; p = p->next)
+ {
+ drag_selection_item_destroy (p->data);
+ }
- g_list_free (list);
+ g_list_free (list);
}
GList *
nautilus_drag_uri_list_from_selection_list (const GList *selection_list)
{
- NautilusDragSelectionItem *selection_item;
- GList *uri_list;
- const GList *l;
-
- uri_list = NULL;
- for (l = selection_list; l != NULL; l = l->next) {
- selection_item = (NautilusDragSelectionItem *) l->data;
- if (selection_item->uri != NULL) {
- uri_list = g_list_prepend (uri_list, g_strdup (selection_item->uri));
- }
- }
+ NautilusDragSelectionItem *selection_item;
+ GList *uri_list;
+ const GList *l;
+
+ uri_list = NULL;
+ for (l = selection_list; l != NULL; l = l->next)
+ {
+ selection_item = (NautilusDragSelectionItem *) l->data;
+ if (selection_item->uri != NULL)
+ {
+ uri_list = g_list_prepend (uri_list, g_strdup (selection_item->uri));
+ }
+ }
- return g_list_reverse (uri_list);
+ return g_list_reverse (uri_list);
}
/*
@@ -141,303 +147,336 @@ nautilus_drag_uri_list_from_selection_list (const GList *selection_list)
GList *
nautilus_drag_file_list_from_selection_list (const GList *selection_list)
{
- NautilusDragSelectionItem *selection_item;
- GList *file_list;
- const GList *l;
-
- file_list = NULL;
- for (l = selection_list; l != NULL; l = l->next) {
- selection_item = (NautilusDragSelectionItem *) l->data;
- if (selection_item->file != NULL) {
- file_list = g_list_prepend (file_list, g_object_ref (selection_item->file));
- }
- }
+ NautilusDragSelectionItem *selection_item;
+ GList *file_list;
+ const GList *l;
+
+ file_list = NULL;
+ for (l = selection_list; l != NULL; l = l->next)
+ {
+ selection_item = (NautilusDragSelectionItem *) l->data;
+ if (selection_item->file != NULL)
+ {
+ file_list = g_list_prepend (file_list, g_object_ref (selection_item->file));
+ }
+ }
- return g_list_reverse (file_list);
+ return g_list_reverse (file_list);
}
GList *
nautilus_drag_uri_list_from_array (const char **uris)
{
- GList *uri_list;
- int i;
+ GList *uri_list;
+ int i;
- if (uris == NULL) {
- return NULL;
- }
+ if (uris == NULL)
+ {
+ return NULL;
+ }
- uri_list = NULL;
+ uri_list = NULL;
- for (i = 0; uris[i] != NULL; i++) {
- uri_list = g_list_prepend (uri_list, g_strdup (uris[i]));
- }
+ for (i = 0; uris[i] != NULL; i++)
+ {
+ uri_list = g_list_prepend (uri_list, g_strdup (uris[i]));
+ }
- return g_list_reverse (uri_list);
+ return g_list_reverse (uri_list);
}
GList *
nautilus_drag_build_selection_list (GtkSelectionData *data)
{
- GList *result;
- const guchar *p, *oldp;
- int size;
-
- result = NULL;
- oldp = gtk_selection_data_get_data (data);
- size = gtk_selection_data_get_length (data);
-
- while (size > 0) {
- NautilusDragSelectionItem *item;
- guint len;
-
- /* The list is in the form:
-
- name\rx:y:width:height\r\n
+ GList *result;
+ const guchar *p, *oldp;
+ int size;
+
+ result = NULL;
+ oldp = gtk_selection_data_get_data (data);
+ size = gtk_selection_data_get_length (data);
+
+ while (size > 0)
+ {
+ NautilusDragSelectionItem *item;
+ guint len;
+
+ /* The list is in the form:
+ *
+ * name\rx:y:width:height\r\n
+ *
+ * The geometry information after the first \r is optional. */
+
+ /* 1: Decode name. */
+
+ p = memchr (oldp, '\r', size);
+ if (p == NULL)
+ {
+ break;
+ }
- The geometry information after the first \r is optional. */
+ item = nautilus_drag_selection_item_new ();
+
+ len = p - oldp;
+
+ item->uri = g_malloc (len + 1);
+ memcpy (item->uri, oldp, len);
+ item->uri[len] = 0;
+ item->file = nautilus_file_get_by_uri (item->uri);
+
+ p++;
+ if (*p == '\n' || *p == '\0')
+ {
+ result = g_list_prepend (result, item);
+ if (p == 0)
+ {
+ g_warning ("Invalid x-special/gnome-icon-list data received: "
+ "missing newline character.");
+ break;
+ }
+ else
+ {
+ oldp = p + 1;
+ continue;
+ }
+ }
- /* 1: Decode name. */
+ size -= p - oldp;
+ oldp = p;
- p = memchr (oldp, '\r', size);
- if (p == NULL) {
- break;
- }
+ /* 2: Decode geometry information. */
- item = nautilus_drag_selection_item_new ();
+ item->got_icon_position = sscanf ((const gchar *) p, "%d:%d:%d:%d%*s",
+ &item->icon_x, &item->icon_y,
+ &item->icon_width, &item->icon_height) == 4;
+ if (!item->got_icon_position)
+ {
+ g_warning ("Invalid x-special/gnome-icon-list data received: "
+ "invalid icon position specification.");
+ }
- len = p - oldp;
+ result = g_list_prepend (result, item);
+
+ p = memchr (p, '\r', size);
+ if (p == NULL || p[1] != '\n')
+ {
+ g_warning ("Invalid x-special/gnome-icon-list data received: "
+ "missing newline character.");
+ if (p == NULL)
+ {
+ break;
+ }
+ }
+ else
+ {
+ p += 2;
+ }
- item->uri = g_malloc (len + 1);
- memcpy (item->uri, oldp, len);
- item->uri[len] = 0;
- item->file = nautilus_file_get_by_uri (item->uri);
+ size -= p - oldp;
+ oldp = p;
+ }
- p++;
- if (*p == '\n' || *p == '\0') {
- result = g_list_prepend (result, item);
- if (p == 0) {
- g_warning ("Invalid x-special/gnome-icon-list data received: "
- "missing newline character.");
- break;
- } else {
- oldp = p + 1;
- continue;
- }
- }
+ return g_list_reverse (result);
+}
- size -= p - oldp;
- oldp = p;
+static gboolean
+nautilus_drag_file_local_internal (const char *target_uri_string,
+ const char *first_source_uri)
+{
+ /* check if the first item on the list has target_uri_string as a parent
+ * FIXME:
+ * we should really test each item but that would be slow for large selections
+ * and currently dropped items can only be from the same container
+ */
+ GFile *target, *item, *parent;
+ gboolean result;
- /* 2: Decode geometry information. */
+ result = FALSE;
- item->got_icon_position = sscanf ((const gchar *) p, "%d:%d:%d:%d%*s",
- &item->icon_x, &item->icon_y,
- &item->icon_width, &item->icon_height) == 4;
- if (!item->got_icon_position) {
- g_warning ("Invalid x-special/gnome-icon-list data received: "
- "invalid icon position specification.");
- }
+ target = g_file_new_for_uri (target_uri_string);
- result = g_list_prepend (result, item);
+ /* get the parent URI of the first item in the selection */
+ item = g_file_new_for_uri (first_source_uri);
+ parent = g_file_get_parent (item);
+ g_object_unref (item);
- p = memchr (p, '\r', size);
- if (p == NULL || p[1] != '\n') {
- g_warning ("Invalid x-special/gnome-icon-list data received: "
- "missing newline character.");
- if (p == NULL) {
- break;
- }
- } else {
- p += 2;
- }
+ if (parent != NULL)
+ {
+ result = g_file_equal (parent, target);
+ g_object_unref (parent);
+ }
- size -= p - oldp;
- oldp = p;
- }
+ g_object_unref (target);
- return g_list_reverse (result);
+ return result;
}
-static gboolean
-nautilus_drag_file_local_internal (const char *target_uri_string,
- const char *first_source_uri)
-{
- /* check if the first item on the list has target_uri_string as a parent
- * FIXME:
- * we should really test each item but that would be slow for large selections
- * and currently dropped items can only be from the same container
- */
- GFile *target, *item, *parent;
- gboolean result;
-
- result = FALSE;
-
- target = g_file_new_for_uri (target_uri_string);
-
- /* get the parent URI of the first item in the selection */
- item = g_file_new_for_uri (first_source_uri);
- parent = g_file_get_parent (item);
- g_object_unref (item);
-
- if (parent != NULL) {
- result = g_file_equal (parent, target);
- g_object_unref (parent);
- }
-
- g_object_unref (target);
-
- return result;
-}
-
gboolean
-nautilus_drag_uris_local (const char *target_uri,
- const GList *source_uri_list)
+nautilus_drag_uris_local (const char *target_uri,
+ const GList *source_uri_list)
{
- /* must have at least one item */
- g_assert (source_uri_list);
-
- return nautilus_drag_file_local_internal (target_uri, source_uri_list->data);
+ /* must have at least one item */
+ g_assert (source_uri_list);
+
+ return nautilus_drag_file_local_internal (target_uri, source_uri_list->data);
}
gboolean
-nautilus_drag_items_local (const char *target_uri_string,
- const GList *selection_list)
+nautilus_drag_items_local (const char *target_uri_string,
+ const GList *selection_list)
{
- /* must have at least one item */
- g_assert (selection_list);
+ /* must have at least one item */
+ g_assert (selection_list);
- return nautilus_drag_file_local_internal (target_uri_string,
- ((NautilusDragSelectionItem *)selection_list->data)->uri);
+ return nautilus_drag_file_local_internal (target_uri_string,
+ ((NautilusDragSelectionItem *) selection_list->data)->uri);
}
gboolean
nautilus_drag_items_on_desktop (const GList *selection_list)
{
- char *uri;
- GFile *desktop, *item, *parent;
- gboolean result;
-
- /* check if the first item on the list is in trash.
- * FIXME:
- * we should really test each item but that would be slow for large selections
- * and currently dropped items can only be from the same container
- */
- uri = ((NautilusDragSelectionItem *)selection_list->data)->uri;
- if (eel_uri_is_desktop (uri)) {
- return TRUE;
- }
-
- desktop = nautilus_get_desktop_location ();
-
- item = g_file_new_for_uri (uri);
- parent = g_file_get_parent (item);
- g_object_unref (item);
-
- result = FALSE;
-
- if (parent) {
- result = g_file_equal (desktop, parent);
- g_object_unref (parent);
- }
- g_object_unref (desktop);
-
- return result;
-
+ char *uri;
+ GFile *desktop, *item, *parent;
+ gboolean result;
+
+ /* check if the first item on the list is in trash.
+ * FIXME:
+ * we should really test each item but that would be slow for large selections
+ * and currently dropped items can only be from the same container
+ */
+ uri = ((NautilusDragSelectionItem *) selection_list->data)->uri;
+ if (eel_uri_is_desktop (uri))
+ {
+ return TRUE;
+ }
+
+ desktop = nautilus_get_desktop_location ();
+
+ item = g_file_new_for_uri (uri);
+ parent = g_file_get_parent (item);
+ g_object_unref (item);
+
+ result = FALSE;
+
+ if (parent)
+ {
+ result = g_file_equal (desktop, parent);
+ g_object_unref (parent);
+ }
+ g_object_unref (desktop);
+
+ return result;
}
GdkDragAction
nautilus_drag_default_drop_action_for_netscape_url (GdkDragContext *context)
{
- /* Mozilla defaults to copy, but unless thats the
- only allowed thing (enforced by ctrl) we want to LINK */
- if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_COPY &&
- gdk_drag_context_get_actions (context) != GDK_ACTION_COPY) {
- return GDK_ACTION_LINK;
- } else if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE) {
- /* Don't support move */
- return GDK_ACTION_COPY;
- }
-
- return gdk_drag_context_get_suggested_action (context);
+ /* Mozilla defaults to copy, but unless thats the
+ * only allowed thing (enforced by ctrl) we want to LINK */
+ if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_COPY &&
+ gdk_drag_context_get_actions (context) != GDK_ACTION_COPY)
+ {
+ return GDK_ACTION_LINK;
+ }
+ else if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_MOVE)
+ {
+ /* Don't support move */
+ return GDK_ACTION_COPY;
+ }
+
+ return gdk_drag_context_get_suggested_action (context);
}
static gboolean
check_same_fs (NautilusFile *file1,
- NautilusFile *file2)
+ NautilusFile *file2)
{
- char *id1, *id2;
- gboolean result;
+ char *id1, *id2;
+ gboolean result;
- result = FALSE;
+ result = FALSE;
- if (file1 != NULL && file2 != NULL) {
- id1 = nautilus_file_get_filesystem_id (file1);
- id2 = nautilus_file_get_filesystem_id (file2);
+ if (file1 != NULL && file2 != NULL)
+ {
+ id1 = nautilus_file_get_filesystem_id (file1);
+ id2 = nautilus_file_get_filesystem_id (file2);
- if (id1 != NULL && id2 != NULL) {
- result = (strcmp (id1, id2) == 0);
- }
+ if (id1 != NULL && id2 != NULL)
+ {
+ result = (strcmp (id1, id2) == 0);
+ }
- g_free (id1);
- g_free (id2);
- }
+ g_free (id1);
+ g_free (id2);
+ }
- return result;
+ return result;
}
static gboolean
source_is_deletable (GFile *file)
{
- NautilusFile *naut_file;
- gboolean ret;
+ NautilusFile *naut_file;
+ gboolean ret;
- /* if there's no a cached NautilusFile, it returns NULL */
- naut_file = nautilus_file_get (file);
- if (naut_file == NULL) {
- return FALSE;
- }
-
- ret = nautilus_file_can_delete (naut_file);
- nautilus_file_unref (naut_file);
+ /* if there's no a cached NautilusFile, it returns NULL */
+ naut_file = nautilus_file_get (file);
+ if (naut_file == NULL)
+ {
+ return FALSE;
+ }
- return ret;
+ ret = nautilus_file_can_delete (naut_file);
+ nautilus_file_unref (naut_file);
+
+ return ret;
}
NautilusDragInfo *
nautilus_drag_get_source_data (GdkDragContext *context)
{
- GtkWidget *source_widget;
- NautilusDragInfo *source_data;
-
- source_widget = gtk_drag_get_source_widget (context);
- if (source_widget == NULL)
- return NULL;
-
- if (NAUTILUS_IS_CANVAS_CONTAINER (source_widget)) {
- source_data = nautilus_canvas_dnd_get_drag_source_data (NAUTILUS_CANVAS_CONTAINER (source_widget),
+ GtkWidget *source_widget;
+ NautilusDragInfo *source_data;
+
+ source_widget = gtk_drag_get_source_widget (context);
+ if (source_widget == NULL)
+ {
+ return NULL;
+ }
+
+ if (NAUTILUS_IS_CANVAS_CONTAINER (source_widget))
+ {
+ source_data = nautilus_canvas_dnd_get_drag_source_data (NAUTILUS_CANVAS_CONTAINER (source_widget),
+ context);
+ }
+ else if (GTK_IS_TREE_VIEW (source_widget))
+ {
+ NautilusWindow *window;
+ NautilusWindowSlot *active_slot;
+ NautilusView *view;
+
+ window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (source_widget));
+ active_slot = nautilus_window_get_active_slot (window);
+ view = nautilus_window_slot_get_current_view (active_slot);
+ if (NAUTILUS_IS_LIST_VIEW (view))
+ {
+ source_data = nautilus_list_view_dnd_get_drag_source_data (NAUTILUS_LIST_VIEW (view),
context);
- } else if (GTK_IS_TREE_VIEW (source_widget)) {
- NautilusWindow *window;
- NautilusWindowSlot *active_slot;
- NautilusView *view;
-
- window = NAUTILUS_WINDOW (gtk_widget_get_toplevel (source_widget));
- active_slot = nautilus_window_get_active_slot (window);
- view = nautilus_window_slot_get_current_view (active_slot);
- if (NAUTILUS_IS_LIST_VIEW (view)) {
- source_data = nautilus_list_view_dnd_get_drag_source_data (NAUTILUS_LIST_VIEW (view),
- context);
- } else {
- g_warning ("Got a drag context with a tree view source widget, but current view is not list view");
- source_data = NULL;
- }
- } else {
- /* it's a slot or something else */
- g_warning ("Requested drag source data from a widget that doesn't support it");
- source_data = NULL;
}
-
- return source_data;
+ else
+ {
+ g_warning ("Got a drag context with a tree view source widget, but current view is not list view");
+ source_data = NULL;
+ }
+ }
+ else
+ {
+ /* it's a slot or something else */
+ g_warning ("Requested drag source data from a widget that doesn't support it");
+ source_data = NULL;
+ }
+
+ return source_data;
}
void
@@ -447,506 +486,580 @@ nautilus_drag_default_drop_action_for_icons (GdkDragContext *context,
guint32 source_actions,
int *action)
{
- gboolean same_fs;
- gboolean target_is_source_parent;
- gboolean source_deletable;
- const char *dropped_uri;
- GFile *target, *dropped, *dropped_directory;
- GdkDragAction actions;
- NautilusFile *dropped_file, *target_file;
-
- if (target_uri_string == NULL) {
- *action = 0;
- return;
- }
-
- /* this is needed because of how dnd works. The actions at the time drag-begin
- * is done are not set, because they are first set on drag-motion. However,
- * for our use case, which is validation with the sidebar for dnd feedback
- * when the dnd doesn't have as a destination the sidebar itself, we need
- * a way to know the actions at drag-begin time. Either canvas view or
- * list view know them when starting the drag, but asking for them here
- * would be breaking the current model too much. So instead we rely on the
- * caller, which will ask if appropiate to those objects about the actions
- * available, instead of relying solely on the context here. */
- if (source_actions)
- actions = source_actions & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ gboolean same_fs;
+ gboolean target_is_source_parent;
+ gboolean source_deletable;
+ const char *dropped_uri;
+ GFile *target, *dropped, *dropped_directory;
+ GdkDragAction actions;
+ NautilusFile *dropped_file, *target_file;
+
+ if (target_uri_string == NULL)
+ {
+ *action = 0;
+ return;
+ }
+
+ /* this is needed because of how dnd works. The actions at the time drag-begin
+ * is done are not set, because they are first set on drag-motion. However,
+ * for our use case, which is validation with the sidebar for dnd feedback
+ * when the dnd doesn't have as a destination the sidebar itself, we need
+ * a way to know the actions at drag-begin time. Either canvas view or
+ * list view know them when starting the drag, but asking for them here
+ * would be breaking the current model too much. So instead we rely on the
+ * caller, which will ask if appropiate to those objects about the actions
+ * available, instead of relying solely on the context here. */
+ if (source_actions)
+ {
+ actions = source_actions & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ }
+ else
+ {
+ actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
+ }
+ if (actions == 0)
+ {
+ /* We can't use copy or move, just go with the suggested action. */
+ *action = gdk_drag_context_get_suggested_action (context);
+ return;
+ }
+
+ if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK)
+ {
+ /* Don't override ask */
+ *action = gdk_drag_context_get_suggested_action (context);
+ return;
+ }
+
+ dropped_uri = ((NautilusDragSelectionItem *) items->data)->uri;
+ dropped_file = ((NautilusDragSelectionItem *) items->data)->file;
+ target_file = nautilus_file_get_by_uri (target_uri_string);
+
+ if (eel_uri_is_desktop (dropped_uri) &&
+ !eel_uri_is_desktop (target_uri_string))
+ {
+ /* Desktop items only move on the desktop */
+ *action = 0;
+ return;
+ }
+
+ /*
+ * Check for trash URI. We do a find_directory for any Trash directory.
+ * Passing 0 permissions as gnome-vfs would override the permissions
+ * passed with 700 while creating .Trash directory
+ */
+ if (eel_uri_is_trash (target_uri_string))
+ {
+ /* Only move to Trash */
+ if (actions & GDK_ACTION_MOVE)
+ {
+ *action = GDK_ACTION_MOVE;
+ }
+ nautilus_file_unref (target_file);
+ return;
+ }
+ else if (dropped_file != NULL && nautilus_file_is_launcher (dropped_file))
+ {
+ if (actions & GDK_ACTION_MOVE)
+ {
+ *action = GDK_ACTION_MOVE;
+ }
+ nautilus_file_unref (target_file);
+ return;
+ }
+ else if (eel_uri_is_desktop (target_uri_string))
+ {
+ target = nautilus_get_desktop_location ();
+
+ nautilus_file_unref (target_file);
+ target_file = nautilus_file_get (target);
+
+ if (eel_uri_is_desktop (dropped_uri))
+ {
+ /* Only move to Desktop icons */
+ if (actions & GDK_ACTION_MOVE)
+ {
+ *action = GDK_ACTION_MOVE;
+ }
+
+ g_object_unref (target);
+ nautilus_file_unref (target_file);
+ return;
+ }
+ }
+ else if (target_file != NULL && nautilus_file_is_archive (target_file))
+ {
+ *action = GDK_ACTION_COPY;
+
+ nautilus_file_unref (target_file);
+ return;
+ }
+ else
+ {
+ target = g_file_new_for_uri (target_uri_string);
+ }
+
+ same_fs = check_same_fs (target_file, dropped_file);
+
+ nautilus_file_unref (target_file);
+
+ /* Compare the first dropped uri with the target uri for same fs match. */
+ dropped = g_file_new_for_uri (dropped_uri);
+ dropped_directory = g_file_get_parent (dropped);
+ target_is_source_parent = FALSE;
+ if (dropped_directory != NULL)
+ {
+ /* If the dropped file is already in the same directory but
+ * is in another filesystem we still want to move, not copy
+ * as this is then just a move of a mountpoint to another
+ * position in the dir */
+ target_is_source_parent = g_file_equal (dropped_directory, target);
+ g_object_unref (dropped_directory);
+ }
+ source_deletable = source_is_deletable (dropped);
+
+ if ((same_fs && source_deletable) || target_is_source_parent ||
+ g_file_has_uri_scheme (dropped, "trash"))
+ {
+ if (actions & GDK_ACTION_MOVE)
+ {
+ *action = GDK_ACTION_MOVE;
+ }
+ else
+ {
+ *action = gdk_drag_context_get_suggested_action (context);
+ }
+ }
+ else
+ {
+ if (actions & GDK_ACTION_COPY)
+ {
+ *action = GDK_ACTION_COPY;
+ }
else
- actions = gdk_drag_context_get_actions (context) & (GDK_ACTION_MOVE | GDK_ACTION_COPY);
- if (actions == 0) {
- /* We can't use copy or move, just go with the suggested action. */
- *action = gdk_drag_context_get_suggested_action (context);
- return;
- }
-
- if (gdk_drag_context_get_suggested_action (context) == GDK_ACTION_ASK) {
- /* Don't override ask */
- *action = gdk_drag_context_get_suggested_action (context);
- return;
- }
-
- dropped_uri = ((NautilusDragSelectionItem *)items->data)->uri;
- dropped_file = ((NautilusDragSelectionItem *)items->data)->file;
- target_file = nautilus_file_get_by_uri (target_uri_string);
-
- if (eel_uri_is_desktop (dropped_uri) &&
- !eel_uri_is_desktop (target_uri_string)) {
- /* Desktop items only move on the desktop */
- *action = 0;
- return;
- }
-
- /*
- * Check for trash URI. We do a find_directory for any Trash directory.
- * Passing 0 permissions as gnome-vfs would override the permissions
- * passed with 700 while creating .Trash directory
- */
- if (eel_uri_is_trash (target_uri_string)) {
- /* Only move to Trash */
- if (actions & GDK_ACTION_MOVE) {
- *action = GDK_ACTION_MOVE;
- }
- nautilus_file_unref (target_file);
- return;
-
- } else if (dropped_file != NULL && nautilus_file_is_launcher (dropped_file)) {
- if (actions & GDK_ACTION_MOVE) {
- *action = GDK_ACTION_MOVE;
- }
- nautilus_file_unref (target_file);
- return;
- } else if (eel_uri_is_desktop (target_uri_string)) {
- target = nautilus_get_desktop_location ();
-
- nautilus_file_unref (target_file);
- target_file = nautilus_file_get (target);
-
- if (eel_uri_is_desktop (dropped_uri)) {
- /* Only move to Desktop icons */
- if (actions & GDK_ACTION_MOVE) {
- *action = GDK_ACTION_MOVE;
- }
-
- g_object_unref (target);
- nautilus_file_unref (target_file);
- return;
- }
- } else if (target_file != NULL && nautilus_file_is_archive (target_file)) {
- *action = GDK_ACTION_COPY;
-
- nautilus_file_unref (target_file);
- return;
- } else {
- target = g_file_new_for_uri (target_uri_string);
- }
-
- same_fs = check_same_fs (target_file, dropped_file);
-
- nautilus_file_unref (target_file);
-
- /* Compare the first dropped uri with the target uri for same fs match. */
- dropped = g_file_new_for_uri (dropped_uri);
- dropped_directory = g_file_get_parent (dropped);
- target_is_source_parent = FALSE;
- if (dropped_directory != NULL) {
- /* If the dropped file is already in the same directory but
- is in another filesystem we still want to move, not copy
- as this is then just a move of a mountpoint to another
- position in the dir */
- target_is_source_parent = g_file_equal (dropped_directory, target);
- g_object_unref (dropped_directory);
- }
- source_deletable = source_is_deletable (dropped);
-
- if ((same_fs && source_deletable) || target_is_source_parent ||
- g_file_has_uri_scheme (dropped, "trash")) {
- if (actions & GDK_ACTION_MOVE) {
- *action = GDK_ACTION_MOVE;
- } else {
- *action = gdk_drag_context_get_suggested_action (context);
- }
- } else {
- if (actions & GDK_ACTION_COPY) {
- *action = GDK_ACTION_COPY;
- } else {
- *action = gdk_drag_context_get_suggested_action (context);
- }
- }
-
- g_object_unref (target);
- g_object_unref (dropped);
-
+ {
+ *action = gdk_drag_context_get_suggested_action (context);
+ }
+ }
+
+ g_object_unref (target);
+ g_object_unref (dropped);
}
GdkDragAction
nautilus_drag_default_drop_action_for_uri_list (GdkDragContext *context,
- const char *target_uri_string)
+ const char *target_uri_string)
{
- if (eel_uri_is_trash (target_uri_string) && (gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE)) {
- /* Only move to Trash */
- return GDK_ACTION_MOVE;
- } else {
- return gdk_drag_context_get_suggested_action (context);
- }
+ if (eel_uri_is_trash (target_uri_string) && (gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE))
+ {
+ /* Only move to Trash */
+ return GDK_ACTION_MOVE;
+ }
+ else
+ {
+ return gdk_drag_context_get_suggested_action (context);
+ }
}
/* Encode a "x-special/gnome-icon-list" selection.
- Along with the URIs of the dragged files, this encodes
- the location and size of each icon relative to the cursor.
-*/
+ * Along with the URIs of the dragged files, this encodes
+ * the location and size of each icon relative to the cursor.
+ */
static void
-add_one_gnome_icon (const char *uri, int x, int y, int w, int h,
- gpointer data)
+add_one_gnome_icon (const char *uri,
+ int x,
+ int y,
+ int w,
+ int h,
+ gpointer data)
{
- GString *result;
+ GString *result;
- result = (GString *) data;
+ result = (GString *) data;
- g_string_append_printf (result, "%s\r%d:%d:%hu:%hu\r\n",
- uri, x, y, w, h);
+ g_string_append_printf (result, "%s\r%d:%d:%hu:%hu\r\n",
+ uri, x, y, w, h);
}
static void
-add_one_uri (const char *uri, int x, int y, int w, int h, gpointer data)
+add_one_uri (const char *uri,
+ int x,
+ int y,
+ int w,
+ int h,
+ gpointer data)
{
- GString *result;
-
- result = (GString *) data;
+ GString *result;
+
+ result = (GString *) data;
- g_string_append (result, uri);
- g_string_append (result, "\r\n");
+ g_string_append (result, uri);
+ g_string_append (result, "\r\n");
}
static void
cache_one_item (const char *uri,
- int x, int y,
- int w, int h,
- gpointer data)
+ int x,
+ int y,
+ int w,
+ int h,
+ gpointer data)
{
- GList **cache = data;
- NautilusDragSelectionItem *item;
-
- item = nautilus_drag_selection_item_new ();
- item->uri = g_strdup (uri);
- item->file = nautilus_file_get_by_uri (uri);
- item->icon_x = x;
- item->icon_y = y;
- item->icon_width = w;
- item->icon_height = h;
- *cache = g_list_prepend (*cache, item);
+ GList **cache = data;
+ NautilusDragSelectionItem *item;
+
+ item = nautilus_drag_selection_item_new ();
+ item->uri = g_strdup (uri);
+ item->file = nautilus_file_get_by_uri (uri);
+ item->icon_x = x;
+ item->icon_y = y;
+ item->icon_width = w;
+ item->icon_height = h;
+ *cache = g_list_prepend (*cache, item);
}
GList *
-nautilus_drag_create_selection_cache (gpointer container_context,
- NautilusDragEachSelectedItemIterator each_selected_item_iterator)
+nautilus_drag_create_selection_cache (gpointer container_context,
+ NautilusDragEachSelectedItemIterator each_selected_item_iterator)
{
- GList *cache = NULL;
+ GList *cache = NULL;
- (* each_selected_item_iterator) (cache_one_item, container_context, &cache);
- cache = g_list_reverse (cache);
+ (*each_selected_item_iterator)(cache_one_item, container_context, &cache);
+ cache = g_list_reverse (cache);
- return cache;
+ return cache;
}
/* Common function for drag_data_get_callback calls.
* Returns FALSE if it doesn't handle drag data */
gboolean
-nautilus_drag_drag_data_get_from_cache (GList *cache,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint32 time)
-{
- GList *l;
- GString *result;
- NautilusDragEachSelectedItemDataGet func;
-
- if (cache == NULL) {
- return FALSE;
- }
-
- switch (info) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
- func = add_one_gnome_icon;
- break;
- case NAUTILUS_ICON_DND_URI_LIST:
- case NAUTILUS_ICON_DND_TEXT:
- func = add_one_uri;
- break;
- default:
- return FALSE;
- }
-
- result = g_string_new (NULL);
-
- for (l = cache; l != NULL; l = l->next) {
- NautilusDragSelectionItem *item = l->data;
- (*func) (item->uri, item->icon_x, item->icon_y, item->icon_width, item->icon_height, result);
- }
-
- gtk_selection_data_set (selection_data,
- gtk_selection_data_get_target (selection_data),
- 8, (guchar *) result->str, result->len);
- g_string_free (result, TRUE);
-
- return TRUE;
+nautilus_drag_drag_data_get_from_cache (GList *cache,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint32 time)
+{
+ GList *l;
+ GString *result;
+ NautilusDragEachSelectedItemDataGet func;
+
+ if (cache == NULL)
+ {
+ return FALSE;
+ }
+
+ switch (info)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ func = add_one_gnome_icon;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ case NAUTILUS_ICON_DND_TEXT:
+ {
+ func = add_one_uri;
+ }
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ result = g_string_new (NULL);
+
+ for (l = cache; l != NULL; l = l->next)
+ {
+ NautilusDragSelectionItem *item = l->data;
+ (*func)(item->uri, item->icon_x, item->icon_y, item->icon_width, item->icon_height, result);
+ }
+
+ gtk_selection_data_set (selection_data,
+ gtk_selection_data_get_target (selection_data),
+ 8, (guchar *) result->str, result->len);
+ g_string_free (result, TRUE);
+
+ return TRUE;
}
typedef struct
{
- GMainLoop *loop;
- GdkDragAction chosen;
+ GMainLoop *loop;
+ GdkDragAction chosen;
} DropActionMenuData;
static void
menu_deactivate_callback (GtkWidget *menu,
- gpointer data)
+ gpointer data)
{
- DropActionMenuData *damd;
-
- damd = data;
+ DropActionMenuData *damd;
+
+ damd = data;
- if (g_main_loop_is_running (damd->loop))
- g_main_loop_quit (damd->loop);
+ if (g_main_loop_is_running (damd->loop))
+ {
+ g_main_loop_quit (damd->loop);
+ }
}
static void
-drop_action_activated_callback (GtkWidget *menu_item,
- gpointer data)
+drop_action_activated_callback (GtkWidget *menu_item,
+ gpointer data)
{
- DropActionMenuData *damd;
-
- damd = data;
+ DropActionMenuData *damd;
+
+ damd = data;
- damd->chosen = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item),
- "action"));
+ damd->chosen = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item),
+ "action"));
- if (g_main_loop_is_running (damd->loop))
- g_main_loop_quit (damd->loop);
+ if (g_main_loop_is_running (damd->loop))
+ {
+ g_main_loop_quit (damd->loop);
+ }
}
static void
append_drop_action_menu_item (GtkWidget *menu,
- const char *text,
- GdkDragAction action,
- gboolean sensitive,
- DropActionMenuData *damd)
+ const char *text,
+ GdkDragAction action,
+ gboolean sensitive,
+ DropActionMenuData *damd)
{
- GtkWidget *menu_item;
+ GtkWidget *menu_item;
- menu_item = gtk_menu_item_new_with_mnemonic (text);
- gtk_widget_set_sensitive (menu_item, sensitive);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ menu_item = gtk_menu_item_new_with_mnemonic (text);
+ gtk_widget_set_sensitive (menu_item, sensitive);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
- g_object_set_data (G_OBJECT (menu_item),
- "action",
- GINT_TO_POINTER (action));
-
- g_signal_connect (menu_item, "activate",
- G_CALLBACK (drop_action_activated_callback),
- damd);
+ g_object_set_data (G_OBJECT (menu_item),
+ "action",
+ GINT_TO_POINTER (action));
- gtk_widget_show (menu_item);
+ g_signal_connect (menu_item, "activate",
+ G_CALLBACK (drop_action_activated_callback),
+ damd);
+
+ gtk_widget_show (menu_item);
}
/* Pops up a menu of actions to perform on dropped files */
GdkDragAction
-nautilus_drag_drop_action_ask (GtkWidget *widget,
- 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 ();
- gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
-
- append_drop_action_menu_item (menu, _("_Move Here"),
- GDK_ACTION_MOVE,
- (actions & GDK_ACTION_MOVE) != 0,
- &damd);
-
- append_drop_action_menu_item (menu, _("_Copy Here"),
- GDK_ACTION_COPY,
- (actions & GDK_ACTION_COPY) != 0,
- &damd);
-
- append_drop_action_menu_item (menu, _("_Link Here"),
- GDK_ACTION_LINK,
- (actions & GDK_ACTION_LINK) != 0,
- &damd);
-
- eel_gtk_menu_append_separator (GTK_MENU (menu));
-
- 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);
-
- g_object_ref_sink (menu);
- g_object_unref (menu);
-
- return damd.chosen;
+nautilus_drag_drop_action_ask (GtkWidget *widget,
+ 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 ();
+ gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
+
+ append_drop_action_menu_item (menu, _("_Move Here"),
+ GDK_ACTION_MOVE,
+ (actions & GDK_ACTION_MOVE) != 0,
+ &damd);
+
+ append_drop_action_menu_item (menu, _("_Copy Here"),
+ GDK_ACTION_COPY,
+ (actions & GDK_ACTION_COPY) != 0,
+ &damd);
+
+ append_drop_action_menu_item (menu, _("_Link Here"),
+ GDK_ACTION_LINK,
+ (actions & GDK_ACTION_LINK) != 0,
+ &damd);
+
+ eel_gtk_menu_append_separator (GTK_MENU (menu));
+
+ 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);
+
+ g_object_ref_sink (menu);
+ g_object_unref (menu);
+
+ return damd.chosen;
}
gboolean
nautilus_drag_autoscroll_in_scroll_region (GtkWidget *widget)
{
- float x_scroll_delta, y_scroll_delta;
+ float x_scroll_delta, y_scroll_delta;
- nautilus_drag_autoscroll_calculate_delta (widget, &x_scroll_delta, &y_scroll_delta);
+ nautilus_drag_autoscroll_calculate_delta (widget, &x_scroll_delta, &y_scroll_delta);
- return x_scroll_delta != 0 || y_scroll_delta != 0;
+ return x_scroll_delta != 0 || y_scroll_delta != 0;
}
void
-nautilus_drag_autoscroll_calculate_delta (GtkWidget *widget, float *x_scroll_delta, float *y_scroll_delta)
-{
- GtkAllocation allocation;
- GdkDisplay *display;
- GdkSeat *seat;
- GdkDevice *pointer;
- int x, y;
-
- g_assert (GTK_IS_WIDGET (widget));
-
- display = gtk_widget_get_display (widget);
- seat = gdk_display_get_default_seat (display);
- pointer = gdk_seat_get_pointer (seat);
- gdk_window_get_device_position (gtk_widget_get_window (widget), pointer,
- &x, &y, NULL);
-
- /* Find out if we are anywhere close to the tree view edges
- * to see if we need to autoscroll.
- */
- *x_scroll_delta = 0;
- *y_scroll_delta = 0;
-
- if (x < AUTO_SCROLL_MARGIN) {
- *x_scroll_delta = (float)(x - AUTO_SCROLL_MARGIN);
- }
-
- gtk_widget_get_allocation (widget, &allocation);
- if (x > allocation.width - AUTO_SCROLL_MARGIN) {
- if (*x_scroll_delta != 0) {
- /* Already trying to scroll because of being too close to
- * the top edge -- must be the window is really short,
- * don't autoscroll.
- */
- return;
- }
- *x_scroll_delta = (float)(x - (allocation.width - AUTO_SCROLL_MARGIN));
- }
-
- if (y < AUTO_SCROLL_MARGIN) {
- *y_scroll_delta = (float)(y - AUTO_SCROLL_MARGIN);
- }
-
- if (y > allocation.height - AUTO_SCROLL_MARGIN) {
- if (*y_scroll_delta != 0) {
- /* Already trying to scroll because of being too close to
- * the top edge -- must be the window is really narrow,
- * don't autoscroll.
- */
- return;
- }
- *y_scroll_delta = (float)(y - (allocation.height - AUTO_SCROLL_MARGIN));
- }
-
- if (*x_scroll_delta == 0 && *y_scroll_delta == 0) {
- /* no work */
- return;
- }
-
- /* Adjust the scroll delta to the proper acceleration values depending on how far
- * into the sroll margins we are.
- * FIXME bugzilla.eazel.com 2486:
- * we could use an exponential acceleration factor here for better feel
- */
- if (*x_scroll_delta != 0) {
- *x_scroll_delta /= AUTO_SCROLL_MARGIN;
- *x_scroll_delta *= (MAX_AUTOSCROLL_DELTA - MIN_AUTOSCROLL_DELTA);
- *x_scroll_delta += MIN_AUTOSCROLL_DELTA;
- }
-
- if (*y_scroll_delta != 0) {
- *y_scroll_delta /= AUTO_SCROLL_MARGIN;
- *y_scroll_delta *= (MAX_AUTOSCROLL_DELTA - MIN_AUTOSCROLL_DELTA);
- *y_scroll_delta += MIN_AUTOSCROLL_DELTA;
- }
-
+nautilus_drag_autoscroll_calculate_delta (GtkWidget *widget,
+ float *x_scroll_delta,
+ float *y_scroll_delta)
+{
+ GtkAllocation allocation;
+ GdkDisplay *display;
+ GdkSeat *seat;
+ GdkDevice *pointer;
+ int x, y;
+
+ g_assert (GTK_IS_WIDGET (widget));
+
+ display = gtk_widget_get_display (widget);
+ seat = gdk_display_get_default_seat (display);
+ pointer = gdk_seat_get_pointer (seat);
+ gdk_window_get_device_position (gtk_widget_get_window (widget), pointer,
+ &x, &y, NULL);
+
+ /* Find out if we are anywhere close to the tree view edges
+ * to see if we need to autoscroll.
+ */
+ *x_scroll_delta = 0;
+ *y_scroll_delta = 0;
+
+ if (x < AUTO_SCROLL_MARGIN)
+ {
+ *x_scroll_delta = (float) (x - AUTO_SCROLL_MARGIN);
+ }
+
+ gtk_widget_get_allocation (widget, &allocation);
+ if (x > allocation.width - AUTO_SCROLL_MARGIN)
+ {
+ if (*x_scroll_delta != 0)
+ {
+ /* Already trying to scroll because of being too close to
+ * the top edge -- must be the window is really short,
+ * don't autoscroll.
+ */
+ return;
+ }
+ *x_scroll_delta = (float) (x - (allocation.width - AUTO_SCROLL_MARGIN));
+ }
+
+ if (y < AUTO_SCROLL_MARGIN)
+ {
+ *y_scroll_delta = (float) (y - AUTO_SCROLL_MARGIN);
+ }
+
+ if (y > allocation.height - AUTO_SCROLL_MARGIN)
+ {
+ if (*y_scroll_delta != 0)
+ {
+ /* Already trying to scroll because of being too close to
+ * the top edge -- must be the window is really narrow,
+ * don't autoscroll.
+ */
+ return;
+ }
+ *y_scroll_delta = (float) (y - (allocation.height - AUTO_SCROLL_MARGIN));
+ }
+
+ if (*x_scroll_delta == 0 && *y_scroll_delta == 0)
+ {
+ /* no work */
+ return;
+ }
+
+ /* Adjust the scroll delta to the proper acceleration values depending on how far
+ * into the sroll margins we are.
+ * FIXME bugzilla.eazel.com 2486:
+ * we could use an exponential acceleration factor here for better feel
+ */
+ if (*x_scroll_delta != 0)
+ {
+ *x_scroll_delta /= AUTO_SCROLL_MARGIN;
+ *x_scroll_delta *= (MAX_AUTOSCROLL_DELTA - MIN_AUTOSCROLL_DELTA);
+ *x_scroll_delta += MIN_AUTOSCROLL_DELTA;
+ }
+
+ if (*y_scroll_delta != 0)
+ {
+ *y_scroll_delta /= AUTO_SCROLL_MARGIN;
+ *y_scroll_delta *= (MAX_AUTOSCROLL_DELTA - MIN_AUTOSCROLL_DELTA);
+ *y_scroll_delta += MIN_AUTOSCROLL_DELTA;
+ }
}
void
nautilus_drag_autoscroll_start (NautilusDragInfo *drag_info,
- GtkWidget *widget,
- GSourceFunc callback,
- gpointer user_data)
-{
- if (nautilus_drag_autoscroll_in_scroll_region (widget)) {
- if (drag_info->auto_scroll_timeout_id == 0) {
- drag_info->waiting_to_autoscroll = TRUE;
- drag_info->start_auto_scroll_in = g_get_monotonic_time ()
- + AUTOSCROLL_INITIAL_DELAY;
-
- drag_info->auto_scroll_timeout_id = g_timeout_add
- (AUTOSCROLL_TIMEOUT_INTERVAL,
- callback,
- user_data);
- }
- } else {
- if (drag_info->auto_scroll_timeout_id != 0) {
- g_source_remove (drag_info->auto_scroll_timeout_id);
- drag_info->auto_scroll_timeout_id = 0;
- }
- }
+ GtkWidget *widget,
+ GSourceFunc callback,
+ gpointer user_data)
+{
+ if (nautilus_drag_autoscroll_in_scroll_region (widget))
+ {
+ if (drag_info->auto_scroll_timeout_id == 0)
+ {
+ drag_info->waiting_to_autoscroll = TRUE;
+ drag_info->start_auto_scroll_in = g_get_monotonic_time ()
+ + AUTOSCROLL_INITIAL_DELAY;
+
+ drag_info->auto_scroll_timeout_id = g_timeout_add
+ (AUTOSCROLL_TIMEOUT_INTERVAL,
+ callback,
+ user_data);
+ }
+ }
+ else
+ {
+ if (drag_info->auto_scroll_timeout_id != 0)
+ {
+ g_source_remove (drag_info->auto_scroll_timeout_id);
+ drag_info->auto_scroll_timeout_id = 0;
+ }
+ }
}
void
nautilus_drag_autoscroll_stop (NautilusDragInfo *drag_info)
{
- if (drag_info->auto_scroll_timeout_id != 0) {
- g_source_remove (drag_info->auto_scroll_timeout_id);
- drag_info->auto_scroll_timeout_id = 0;
- }
+ if (drag_info->auto_scroll_timeout_id != 0)
+ {
+ g_source_remove (drag_info->auto_scroll_timeout_id);
+ drag_info->auto_scroll_timeout_id = 0;
+ }
}
gboolean
nautilus_drag_selection_includes_special_link (GList *selection_list)
{
- GList *node;
- char *uri;
+ GList *node;
+ char *uri;
- for (node = selection_list; node != NULL; node = node->next) {
- uri = ((NautilusDragSelectionItem *) node->data)->uri;
+ for (node = selection_list; node != NULL; node = node->next)
+ {
+ uri = ((NautilusDragSelectionItem *) node->data)->uri;
+
+ if (eel_uri_is_desktop (uri))
+ {
+ return TRUE;
+ }
+ }
- if (eel_uri_is_desktop (uri)) {
- return TRUE;
- }
- }
-
- return FALSE;
+ return FALSE;
}
diff --git a/src/nautilus-empty-view.c b/src/nautilus-empty-view.c
index 5e7c6a73d..e4a4198be 100644
--- a/src/nautilus-empty-view.c
+++ b/src/nautilus-empty-view.c
@@ -1,24 +1,23 @@
-
/* fm-empty-view.c - implementation of empty view of directory.
-
- Copyright (C) 2006 Free Software Foundation, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Christian Neumair <chris@gnome-de.org>
-*/
+ *
+ * Copyright (C) 2006 Free Software Foundation, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Christian Neumair <chris@gnome-de.org>
+ */
#include <config.h>
@@ -30,37 +29,43 @@
#include "nautilus-file-utilities.h"
#include <eel/eel-vfs-extensions.h>
-struct NautilusEmptyViewDetails {
- int number_of_files;
+struct NautilusEmptyViewDetails
+{
+ int number_of_files;
};
-static GList *nautilus_empty_view_get_selection (NautilusFilesView *view);
-static GList *nautilus_empty_view_get_selection_for_file_transfer (NautilusFilesView *view);
-static void nautilus_empty_view_scroll_to_file (NautilusFilesView *view,
- const char *uri);
+static GList *nautilus_empty_view_get_selection (NautilusFilesView *view);
+static GList *nautilus_empty_view_get_selection_for_file_transfer (NautilusFilesView *view);
+static void nautilus_empty_view_scroll_to_file (NautilusFilesView *view,
+ const char *uri);
G_DEFINE_TYPE (NautilusEmptyView, nautilus_empty_view, NAUTILUS_TYPE_FILES_VIEW)
static void
-nautilus_empty_view_add_file (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
+nautilus_empty_view_add_file (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
- static GTimer *timer = NULL;
- static gdouble cumu = 0, elaps;
- NAUTILUS_EMPTY_VIEW (view)->details->number_of_files++;
- GdkPixbuf *icon;
+ static GTimer *timer = NULL;
+ static gdouble cumu = 0, elaps;
+ NAUTILUS_EMPTY_VIEW (view)->details->number_of_files++;
+ GdkPixbuf *icon;
+
+ if (!timer)
+ {
+ timer = g_timer_new ();
+ }
- if (!timer) timer = g_timer_new ();
+ g_timer_start (timer);
+ icon = nautilus_file_get_icon_pixbuf (file, nautilus_get_icon_size_for_zoom_level (NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD), TRUE, 0);
- g_timer_start (timer);
- icon = nautilus_file_get_icon_pixbuf (file, nautilus_get_icon_size_for_zoom_level (NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD), TRUE, 0);
+ elaps = g_timer_elapsed (timer, NULL);
+ g_timer_stop (timer);
- elaps = g_timer_elapsed (timer, NULL);
- g_timer_stop (timer);
+ g_object_unref (icon);
- g_object_unref (icon);
-
- cumu += elaps;
- g_message ("entire loading: %.3f, cumulative %.3f", elaps, cumu);
+ cumu += elaps;
+ g_message ("entire loading: %.3f, cumulative %.3f", elaps, cumu);
}
@@ -76,27 +81,29 @@ nautilus_empty_view_clear (NautilusFilesView *view)
static void
-nautilus_empty_view_file_changed (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
+nautilus_empty_view_file_changed (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
}
static GList *
nautilus_empty_view_get_selection (NautilusFilesView *view)
{
- return NULL;
+ return NULL;
}
static GList *
nautilus_empty_view_get_selection_for_file_transfer (NautilusFilesView *view)
{
- return NULL;
+ return NULL;
}
static gboolean
nautilus_empty_view_is_empty (NautilusFilesView *view)
{
- return NAUTILUS_EMPTY_VIEW (view)->details->number_of_files == 0;
+ return NAUTILUS_EMPTY_VIEW (view)->details->number_of_files == 0;
}
static void
@@ -105,16 +112,19 @@ nautilus_empty_view_end_file_changes (NautilusFilesView *view)
}
static void
-nautilus_empty_view_remove_file (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
+nautilus_empty_view_remove_file (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
- NAUTILUS_EMPTY_VIEW (view)->details->number_of_files--;
- g_assert (NAUTILUS_EMPTY_VIEW (view)->details->number_of_files >= 0);
+ NAUTILUS_EMPTY_VIEW (view)->details->number_of_files--;
+ g_assert (NAUTILUS_EMPTY_VIEW (view)->details->number_of_files >= 0);
}
static void
-nautilus_empty_view_set_selection (NautilusFilesView *view, GList *selection)
+nautilus_empty_view_set_selection (NautilusFilesView *view,
+ GList *selection)
{
- nautilus_files_view_notify_selection_changed (view);
+ nautilus_files_view_notify_selection_changed (view);
}
static void
@@ -130,23 +140,24 @@ nautilus_empty_view_reveal_selection (NautilusFilesView *view)
static void
nautilus_empty_view_update_menus (NautilusFilesView *view)
{
- NAUTILUS_FILES_VIEW_CLASS (nautilus_empty_view_parent_class)->update_menus (view);
+ NAUTILUS_FILES_VIEW_CLASS (nautilus_empty_view_parent_class)->update_menus (view);
}
static void
-nautilus_empty_view_bump_zoom_level (NautilusFilesView *view, int zoom_increment)
+nautilus_empty_view_bump_zoom_level (NautilusFilesView *view,
+ int zoom_increment)
{
}
static NautilusCanvasZoomLevel
nautilus_empty_view_get_zoom_level (NautilusFilesView *view)
{
- return NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD;
+ return NAUTILUS_CANVAS_ZOOM_LEVEL_STANDARD;
}
static void
-nautilus_empty_view_zoom_to_level (NautilusFilesView *view,
- NautilusCanvasZoomLevel zoom_level)
+nautilus_empty_view_zoom_to_level (NautilusFilesView *view,
+ NautilusCanvasZoomLevel zoom_level)
{
}
@@ -155,22 +166,22 @@ nautilus_empty_view_restore_standard_zoom_level (NautilusFilesView *view)
{
}
-static gboolean
+static gboolean
nautilus_empty_view_can_zoom_in (NautilusFilesView *view)
{
- return FALSE;
+ return FALSE;
}
-static gboolean
+static gboolean
nautilus_empty_view_can_zoom_out (NautilusFilesView *view)
{
- return FALSE;
+ return FALSE;
}
static gfloat
nautilus_empty_view_get_zoom_level_percentage (NautilusFilesView *view)
{
- return 1.0;
+ return 1.0;
}
static void
@@ -180,40 +191,44 @@ nautilus_empty_view_click_policy_changed (NautilusFilesView *directory_view)
static int
-nautilus_empty_view_compare_files (NautilusFilesView *view, NautilusFile *file1, NautilusFile *file2)
+nautilus_empty_view_compare_files (NautilusFilesView *view,
+ NautilusFile *file1,
+ NautilusFile *file2)
{
- if (file1 < file2) {
- return -1;
- }
+ if (file1 < file2)
+ {
+ return -1;
+ }
- if (file1 > file2) {
- return +1;
- }
+ if (file1 > file2)
+ {
+ return +1;
+ }
- return 0;
+ return 0;
}
static gboolean
nautilus_empty_view_using_manual_layout (NautilusFilesView *view)
{
- return FALSE;
+ return FALSE;
}
static void
nautilus_empty_view_end_loading (NautilusFilesView *view,
- gboolean all_files_seen)
+ gboolean all_files_seen)
{
}
static char *
nautilus_empty_view_get_first_visible_file (NautilusFilesView *view)
{
- return NULL;
+ return NULL;
}
static void
nautilus_empty_view_scroll_to_file (NautilusFilesView *view,
- const char *uri)
+ const char *uri)
{
}
@@ -225,66 +240,66 @@ nautilus_empty_view_sort_directories_first_changed (NautilusFilesView *view)
static guint
nautilus_empty_view_get_id (NautilusFilesView *view)
{
- return NAUTILUS_VIEW_EMPTY_ID;
+ return NAUTILUS_VIEW_EMPTY_ID;
}
-static GIcon*
+static GIcon *
nautilus_empty_view_get_icon (NautilusFilesView *view)
{
- return NULL;
+ return NULL;
}
static void
nautilus_empty_view_class_init (NautilusEmptyViewClass *class)
{
- NautilusFilesViewClass *nautilus_files_view_class;
-
- g_type_class_add_private (class, sizeof (NautilusEmptyViewDetails));
-
- nautilus_files_view_class = NAUTILUS_FILES_VIEW_CLASS (class);
-
- nautilus_files_view_class->add_file = nautilus_empty_view_add_file;
- nautilus_files_view_class->begin_loading = nautilus_empty_view_begin_loading;
- nautilus_files_view_class->bump_zoom_level = nautilus_empty_view_bump_zoom_level;
- nautilus_files_view_class->can_zoom_in = nautilus_empty_view_can_zoom_in;
- nautilus_files_view_class->can_zoom_out = nautilus_empty_view_can_zoom_out;
- nautilus_files_view_class->get_zoom_level_percentage = nautilus_empty_view_get_zoom_level_percentage;
- nautilus_files_view_class->click_policy_changed = nautilus_empty_view_click_policy_changed;
- nautilus_files_view_class->clear = nautilus_empty_view_clear;
- nautilus_files_view_class->file_changed = nautilus_empty_view_file_changed;
- nautilus_files_view_class->get_selection = nautilus_empty_view_get_selection;
- nautilus_files_view_class->get_selection_for_file_transfer = nautilus_empty_view_get_selection_for_file_transfer;
- nautilus_files_view_class->is_empty = nautilus_empty_view_is_empty;
- nautilus_files_view_class->remove_file = nautilus_empty_view_remove_file;
- nautilus_files_view_class->update_menus = nautilus_empty_view_update_menus;
- nautilus_files_view_class->restore_standard_zoom_level = nautilus_empty_view_restore_standard_zoom_level;
- nautilus_files_view_class->reveal_selection = nautilus_empty_view_reveal_selection;
- nautilus_files_view_class->select_all = nautilus_empty_view_select_all;
- nautilus_files_view_class->set_selection = nautilus_empty_view_set_selection;
- nautilus_files_view_class->compare_files = nautilus_empty_view_compare_files;
- nautilus_files_view_class->sort_directories_first_changed = nautilus_empty_view_sort_directories_first_changed;
- nautilus_files_view_class->get_zoom_level = nautilus_empty_view_get_zoom_level;
- nautilus_files_view_class->zoom_to_level = nautilus_empty_view_zoom_to_level;
- nautilus_files_view_class->end_file_changes = nautilus_empty_view_end_file_changes;
- nautilus_files_view_class->using_manual_layout = nautilus_empty_view_using_manual_layout;
- nautilus_files_view_class->end_loading = nautilus_empty_view_end_loading;
- nautilus_files_view_class->get_view_id = nautilus_empty_view_get_id;
- nautilus_files_view_class->get_first_visible_file = nautilus_empty_view_get_first_visible_file;
- nautilus_files_view_class->scroll_to_file = nautilus_empty_view_scroll_to_file;
- nautilus_files_view_class->get_icon = nautilus_empty_view_get_icon;
+ NautilusFilesViewClass *nautilus_files_view_class;
+
+ g_type_class_add_private (class, sizeof (NautilusEmptyViewDetails));
+
+ nautilus_files_view_class = NAUTILUS_FILES_VIEW_CLASS (class);
+
+ nautilus_files_view_class->add_file = nautilus_empty_view_add_file;
+ nautilus_files_view_class->begin_loading = nautilus_empty_view_begin_loading;
+ nautilus_files_view_class->bump_zoom_level = nautilus_empty_view_bump_zoom_level;
+ nautilus_files_view_class->can_zoom_in = nautilus_empty_view_can_zoom_in;
+ nautilus_files_view_class->can_zoom_out = nautilus_empty_view_can_zoom_out;
+ nautilus_files_view_class->get_zoom_level_percentage = nautilus_empty_view_get_zoom_level_percentage;
+ nautilus_files_view_class->click_policy_changed = nautilus_empty_view_click_policy_changed;
+ nautilus_files_view_class->clear = nautilus_empty_view_clear;
+ nautilus_files_view_class->file_changed = nautilus_empty_view_file_changed;
+ nautilus_files_view_class->get_selection = nautilus_empty_view_get_selection;
+ nautilus_files_view_class->get_selection_for_file_transfer = nautilus_empty_view_get_selection_for_file_transfer;
+ nautilus_files_view_class->is_empty = nautilus_empty_view_is_empty;
+ nautilus_files_view_class->remove_file = nautilus_empty_view_remove_file;
+ nautilus_files_view_class->update_menus = nautilus_empty_view_update_menus;
+ nautilus_files_view_class->restore_standard_zoom_level = nautilus_empty_view_restore_standard_zoom_level;
+ nautilus_files_view_class->reveal_selection = nautilus_empty_view_reveal_selection;
+ nautilus_files_view_class->select_all = nautilus_empty_view_select_all;
+ nautilus_files_view_class->set_selection = nautilus_empty_view_set_selection;
+ nautilus_files_view_class->compare_files = nautilus_empty_view_compare_files;
+ nautilus_files_view_class->sort_directories_first_changed = nautilus_empty_view_sort_directories_first_changed;
+ nautilus_files_view_class->get_zoom_level = nautilus_empty_view_get_zoom_level;
+ nautilus_files_view_class->zoom_to_level = nautilus_empty_view_zoom_to_level;
+ nautilus_files_view_class->end_file_changes = nautilus_empty_view_end_file_changes;
+ nautilus_files_view_class->using_manual_layout = nautilus_empty_view_using_manual_layout;
+ nautilus_files_view_class->end_loading = nautilus_empty_view_end_loading;
+ nautilus_files_view_class->get_view_id = nautilus_empty_view_get_id;
+ nautilus_files_view_class->get_first_visible_file = nautilus_empty_view_get_first_visible_file;
+ nautilus_files_view_class->scroll_to_file = nautilus_empty_view_scroll_to_file;
+ nautilus_files_view_class->get_icon = nautilus_empty_view_get_icon;
}
static void
nautilus_empty_view_init (NautilusEmptyView *empty_view)
{
- empty_view->details = G_TYPE_INSTANCE_GET_PRIVATE (empty_view, NAUTILUS_TYPE_EMPTY_VIEW,
- NautilusEmptyViewDetails);
+ empty_view->details = G_TYPE_INSTANCE_GET_PRIVATE (empty_view, NAUTILUS_TYPE_EMPTY_VIEW,
+ NautilusEmptyViewDetails);
}
NautilusFilesView *
nautilus_empty_view_new (NautilusWindowSlot *slot)
{
- return g_object_new (NAUTILUS_TYPE_EMPTY_VIEW,
- "window-slot", slot,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_EMPTY_VIEW,
+ "window-slot", slot,
+ NULL);
}
diff --git a/src/nautilus-entry.c b/src/nautilus-entry.c
index 1b790a2ab..e8110ab87 100644
--- a/src/nautilus-entry.c
+++ b/src/nautilus-entry.c
@@ -1,4 +1,3 @@
-
/* NautilusEntry: one-line text editing widget. This consists of bug fixes
* and other improvements to GtkEntry, and all the changes could be rolled
* into GtkEntry some day.
@@ -30,160 +29,175 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-struct NautilusEntryDetails {
- gboolean special_tab_handling;
+struct NautilusEntryDetails
+{
+ gboolean special_tab_handling;
- guint select_idle_id;
+ guint select_idle_id;
};
-enum {
- SELECTION_CHANGED,
- LAST_SIGNAL
+enum
+{
+ SELECTION_CHANGED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static void nautilus_entry_editable_init (GtkEditableInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NautilusEntry, nautilus_entry, GTK_TYPE_ENTRY,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
- nautilus_entry_editable_init));
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_EDITABLE,
+ nautilus_entry_editable_init));
static GtkEditableInterface *parent_editable_interface = NULL;
static void
nautilus_entry_init (NautilusEntry *entry)
{
- entry->details = g_new0 (NautilusEntryDetails, 1);
+ entry->details = g_new0 (NautilusEntryDetails, 1);
}
GtkWidget *
nautilus_entry_new (void)
{
- return gtk_widget_new (NAUTILUS_TYPE_ENTRY, NULL);
+ return gtk_widget_new (NAUTILUS_TYPE_ENTRY, NULL);
}
static void
nautilus_entry_finalize (GObject *object)
{
- NautilusEntry *entry;
+ NautilusEntry *entry;
- entry = NAUTILUS_ENTRY (object);
+ entry = NAUTILUS_ENTRY (object);
- if (entry->details->select_idle_id != 0) {
- g_source_remove (entry->details->select_idle_id);
- }
-
- g_free (entry->details);
+ if (entry->details->select_idle_id != 0)
+ {
+ g_source_remove (entry->details->select_idle_id);
+ }
- G_OBJECT_CLASS (nautilus_entry_parent_class)->finalize (object);
+ g_free (entry->details);
+
+ G_OBJECT_CLASS (nautilus_entry_parent_class)->finalize (object);
}
static gboolean
-nautilus_entry_key_press (GtkWidget *widget, GdkEventKey *event)
+nautilus_entry_key_press (GtkWidget *widget,
+ GdkEventKey *event)
{
- NautilusEntry *entry;
- GtkEditable *editable;
- int position;
- gboolean old_has, new_has;
- gboolean result;
-
- entry = NAUTILUS_ENTRY (widget);
- editable = GTK_EDITABLE (widget);
-
- if (!gtk_editable_get_editable (editable)) {
- return FALSE;
- }
-
- switch (event->keyval) {
- case GDK_KEY_Tab:
- /* The location bar entry wants TAB to work kind of
- * like it does in the shell for command completion,
- * so if we get a tab and there's a selection, we
- * should position the insertion point at the end of
- * the selection.
- */
- if (entry->details->special_tab_handling && gtk_editable_get_selection_bounds (editable, NULL, NULL)) {
- position = strlen (gtk_entry_get_text (GTK_ENTRY (editable)));
- gtk_editable_select_region (editable, position, position);
- return TRUE;
- }
- break;
-
- default:
- break;
- }
-
- old_has = gtk_editable_get_selection_bounds (editable, NULL, NULL);
-
- result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->key_press_event (widget, event);
-
- /* Pressing a key usually changes the selection if there is a selection.
- * If there is not selection, we can save work by not emitting a signal.
- */
- if (result) {
- new_has = gtk_editable_get_selection_bounds (editable, NULL, NULL);
- if (old_has || new_has) {
- g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
- }
- }
-
- return result;
-
+ NautilusEntry *entry;
+ GtkEditable *editable;
+ int position;
+ gboolean old_has, new_has;
+ gboolean result;
+
+ entry = NAUTILUS_ENTRY (widget);
+ editable = GTK_EDITABLE (widget);
+
+ if (!gtk_editable_get_editable (editable))
+ {
+ return FALSE;
+ }
+
+ switch (event->keyval)
+ {
+ case GDK_KEY_Tab:
+ {
+ /* The location bar entry wants TAB to work kind of
+ * like it does in the shell for command completion,
+ * so if we get a tab and there's a selection, we
+ * should position the insertion point at the end of
+ * the selection.
+ */
+ if (entry->details->special_tab_handling && gtk_editable_get_selection_bounds (editable, NULL, NULL))
+ {
+ position = strlen (gtk_entry_get_text (GTK_ENTRY (editable)));
+ gtk_editable_select_region (editable, position, position);
+ return TRUE;
+ }
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ old_has = gtk_editable_get_selection_bounds (editable, NULL, NULL);
+
+ result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->key_press_event (widget, event);
+
+ /* Pressing a key usually changes the selection if there is a selection.
+ * If there is not selection, we can save work by not emitting a signal.
+ */
+ if (result)
+ {
+ new_has = gtk_editable_get_selection_bounds (editable, NULL, NULL);
+ if (old_has || new_has)
+ {
+ g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
+ }
+ }
+
+ return result;
}
static gboolean
-nautilus_entry_motion_notify (GtkWidget *widget, GdkEventMotion *event)
+nautilus_entry_motion_notify (GtkWidget *widget,
+ GdkEventMotion *event)
{
- int result;
- gboolean old_had, new_had;
- int old_start, old_end, new_start, new_end;
- GtkEditable *editable;
-
- editable = GTK_EDITABLE (widget);
-
- old_had = gtk_editable_get_selection_bounds (editable, &old_start, &old_end);
-
- result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->motion_notify_event (widget, event);
-
- /* Send a signal if dragging the mouse caused the selection to change. */
- if (result) {
- new_had = gtk_editable_get_selection_bounds (editable, &new_start, &new_end);
- if (old_had != new_had || (old_had && (old_start != new_start || old_end != new_end))) {
- g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
- }
- }
-
- return result;
+ int result;
+ gboolean old_had, new_had;
+ int old_start, old_end, new_start, new_end;
+ GtkEditable *editable;
+
+ editable = GTK_EDITABLE (widget);
+
+ old_had = gtk_editable_get_selection_bounds (editable, &old_start, &old_end);
+
+ result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->motion_notify_event (widget, event);
+
+ /* Send a signal if dragging the mouse caused the selection to change. */
+ if (result)
+ {
+ new_had = gtk_editable_get_selection_bounds (editable, &new_start, &new_end);
+ if (old_had != new_had || (old_had && (old_start != new_start || old_end != new_end)))
+ {
+ g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
+ }
+ }
+
+ return result;
}
/**
* nautilus_entry_select_all
*
* Select all text, leaving the text cursor position at the end.
- *
+ *
* @entry: A NautilusEntry
**/
void
nautilus_entry_select_all (NautilusEntry *entry)
{
- g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
+ g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
- gtk_editable_set_position (GTK_EDITABLE (entry), -1);
- gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
+ gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+ gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
}
static gboolean
select_all_at_idle (gpointer callback_data)
{
- NautilusEntry *entry;
+ NautilusEntry *entry;
- entry = NAUTILUS_ENTRY (callback_data);
+ entry = NAUTILUS_ENTRY (callback_data);
- nautilus_entry_select_all (entry);
+ nautilus_entry_select_all (entry);
- entry->details->select_idle_id = 0;
-
- return FALSE;
+ entry->details->select_idle_id = 0;
+
+ return FALSE;
}
/**
@@ -193,22 +207,23 @@ select_all_at_idle (gpointer callback_data)
* This is useful when reacting to a key press, because
* changing the selection and the text cursor position doesn't
* work in a key_press signal handler.
- *
+ *
* @entry: A NautilusEntry
**/
void
nautilus_entry_select_all_at_idle (NautilusEntry *entry)
{
- g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
+ g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
- /* If the text cursor position changes in this routine
- * then gtk_entry_key_press will unselect (and we want
- * to move the text cursor position to the end).
- */
+ /* If the text cursor position changes in this routine
+ * then gtk_entry_key_press will unselect (and we want
+ * to move the text cursor position to the end).
+ */
- if (entry->details->select_idle_id == 0) {
- entry->details->select_idle_id = g_idle_add (select_all_at_idle, entry);
- }
+ if (entry->details->select_idle_id == 0)
+ {
+ entry->details->select_idle_id = g_idle_add (select_all_at_idle, entry);
+ }
}
/**
@@ -218,75 +233,82 @@ nautilus_entry_select_all_at_idle (NautilusEntry *entry)
* to TRUE and preserves the old value for a later restore. This is
* done so the programmatic changes to the entry do not register
* with the undo manager.
- *
+ *
* @entry: A NautilusEntry
* @test: The text to set
**/
void
-nautilus_entry_set_text (NautilusEntry *entry, const gchar *text)
+nautilus_entry_set_text (NautilusEntry *entry,
+ const gchar *text)
{
- g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
+ g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
- gtk_entry_set_text (GTK_ENTRY (entry), text);
- g_signal_emit (entry, signals[SELECTION_CHANGED], 0);
+ gtk_entry_set_text (GTK_ENTRY (entry), text);
+ g_signal_emit (entry, signals[SELECTION_CHANGED], 0);
}
static void
nautilus_entry_set_selection_bounds (GtkEditable *editable,
- int start_pos,
- int end_pos)
+ int start_pos,
+ int end_pos)
{
- parent_editable_interface->set_selection_bounds (editable, start_pos, end_pos);
+ parent_editable_interface->set_selection_bounds (editable, start_pos, end_pos);
- g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
}
static gboolean
-nautilus_entry_button_press (GtkWidget *widget,
- GdkEventButton *event)
+nautilus_entry_button_press (GtkWidget *widget,
+ GdkEventButton *event)
{
- gboolean result;
+ gboolean result;
- result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_press_event (widget, event);
+ result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_press_event (widget, event);
- if (result) {
- g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
- }
+ if (result)
+ {
+ g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
+ }
- return result;
+ return result;
}
static gboolean
-nautilus_entry_button_release (GtkWidget *widget,
- GdkEventButton *event)
+nautilus_entry_button_release (GtkWidget *widget,
+ GdkEventButton *event)
{
- gboolean result;
+ gboolean result;
- result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_release_event (widget, event);
+ result = GTK_WIDGET_CLASS (nautilus_entry_parent_class)->button_release_event (widget, event);
- if (result) {
- g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
- }
+ if (result)
+ {
+ g_signal_emit (widget, signals[SELECTION_CHANGED], 0);
+ }
- return result;
+ return result;
}
static void
-nautilus_entry_insert_text (GtkEditable *editable, const gchar *text,
- int length, int *position)
+nautilus_entry_insert_text (GtkEditable *editable,
+ const gchar *text,
+ int length,
+ int *position)
{
- parent_editable_interface->insert_text (editable, text, length, position);
+ parent_editable_interface->insert_text (editable, text, length, position);
- g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
}
-
-static void
-nautilus_entry_delete_text (GtkEditable *editable, int start_pos, int end_pos)
+
+static void
+nautilus_entry_delete_text (GtkEditable *editable,
+ int start_pos,
+ int end_pos)
{
- parent_editable_interface->delete_text (editable, start_pos, end_pos);
+ parent_editable_interface->delete_text (editable, start_pos, end_pos);
- g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (editable, signals[SELECTION_CHANGED], 0);
}
/* Overridden to work around GTK bug. The selection_clear_event is queued
@@ -298,68 +320,67 @@ nautilus_entry_delete_text (GtkEditable *editable, int start_pos, int end_pos)
* gtk+/gtkselection.c, gtk_selection_clear.
*/
static gboolean
-nautilus_entry_selection_clear (GtkWidget *widget,
- GdkEventSelection *event)
+nautilus_entry_selection_clear (GtkWidget *widget,
+ GdkEventSelection *event)
{
- g_assert (NAUTILUS_IS_ENTRY (widget));
-
- if (gdk_selection_owner_get (event->selection) == gtk_widget_get_window (widget)) {
- return FALSE;
- }
-
- return GTK_WIDGET_CLASS (nautilus_entry_parent_class)->selection_clear_event (widget, event);
+ g_assert (NAUTILUS_IS_ENTRY (widget));
+
+ if (gdk_selection_owner_get (event->selection) == gtk_widget_get_window (widget))
+ {
+ return FALSE;
+ }
+
+ return GTK_WIDGET_CLASS (nautilus_entry_parent_class)->selection_clear_event (widget, event);
}
static void
nautilus_entry_editable_init (GtkEditableInterface *iface)
{
- parent_editable_interface = g_type_interface_peek_parent (iface);
+ parent_editable_interface = g_type_interface_peek_parent (iface);
- iface->insert_text = nautilus_entry_insert_text;
- iface->delete_text = nautilus_entry_delete_text;
- iface->set_selection_bounds = nautilus_entry_set_selection_bounds;
+ iface->insert_text = nautilus_entry_insert_text;
+ iface->delete_text = nautilus_entry_delete_text;
+ iface->set_selection_bounds = nautilus_entry_set_selection_bounds;
- /* Otherwise we might need some memcpy loving */
- g_assert (iface->do_insert_text != NULL);
- g_assert (iface->get_position != NULL);
- g_assert (iface->get_chars != NULL);
+ /* Otherwise we might need some memcpy loving */
+ g_assert (iface->do_insert_text != NULL);
+ g_assert (iface->get_position != NULL);
+ g_assert (iface->get_chars != NULL);
}
static void
nautilus_entry_class_init (NautilusEntryClass *class)
{
- GtkWidgetClass *widget_class;
- GObjectClass *gobject_class;
-
- widget_class = GTK_WIDGET_CLASS (class);
- gobject_class = G_OBJECT_CLASS (class);
-
- widget_class->button_press_event = nautilus_entry_button_press;
- widget_class->button_release_event = nautilus_entry_button_release;
- widget_class->key_press_event = nautilus_entry_key_press;
- widget_class->motion_notify_event = nautilus_entry_motion_notify;
- widget_class->selection_clear_event = nautilus_entry_selection_clear;
-
- gobject_class->finalize = nautilus_entry_finalize;
-
- /* Set up signals */
- signals[SELECTION_CHANGED] = g_signal_new
- ("selection-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusEntryClass, selection_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GtkWidgetClass *widget_class;
+ GObjectClass *gobject_class;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ gobject_class = G_OBJECT_CLASS (class);
+
+ widget_class->button_press_event = nautilus_entry_button_press;
+ widget_class->button_release_event = nautilus_entry_button_release;
+ widget_class->key_press_event = nautilus_entry_key_press;
+ widget_class->motion_notify_event = nautilus_entry_motion_notify;
+ widget_class->selection_clear_event = nautilus_entry_selection_clear;
+
+ gobject_class->finalize = nautilus_entry_finalize;
+
+ /* Set up signals */
+ signals[SELECTION_CHANGED] = g_signal_new
+ ("selection-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusEntryClass, selection_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
void
nautilus_entry_set_special_tab_handling (NautilusEntry *entry,
- gboolean special_tab_handling)
+ gboolean special_tab_handling)
{
- g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
+ g_return_if_fail (NAUTILUS_IS_ENTRY (entry));
- entry->details->special_tab_handling = special_tab_handling;
+ entry->details->special_tab_handling = special_tab_handling;
}
-
-
diff --git a/src/nautilus-error-reporting.c b/src/nautilus-error-reporting.c
index be08b3ee2..e2e4cfe8b 100644
--- a/src/nautilus-error-reporting.c
+++ b/src/nautilus-error-reporting.c
@@ -1,25 +1,24 @@
-
/* nautilus-error-reporting.h - implementation of file manager functions that report
- errors to the user.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
-*/
+ * errors to the user.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
@@ -35,327 +34,387 @@
#include "nautilus-debug.h"
#define NEW_NAME_TAG "Nautilus: new name"
-#define MAXIMUM_DISPLAYED_FILE_NAME_LENGTH 50
+#define MAXIMUM_DISPLAYED_FILE_NAME_LENGTH 50
-static void finish_rename (NautilusFile *file, gboolean stop_timer, GError *error);
+static void finish_rename (NautilusFile *file,
+ gboolean stop_timer,
+ GError *error);
void
nautilus_report_error_loading_directory (NautilusFile *file,
- GError *error,
- GtkWindow *parent_window)
+ GError *error,
+ GtkWindow *parent_window)
{
- char *file_name;
- char *message;
-
- if (error == NULL ||
- error->message == NULL) {
- return;
- }
-
- if (error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_NOT_MOUNTED) {
- /* This case is retried automatically */
- return;
- }
-
- file_name = nautilus_file_get_display_name (file);
-
- if (error->domain == G_IO_ERROR) {
- switch (error->code) {
- case G_IO_ERROR_PERMISSION_DENIED:
- message = g_strdup_printf (_("You do not have the permissions necessary to view the contents of “%s”."),
- file_name);
- break;
- case G_IO_ERROR_NOT_FOUND:
- message = g_strdup_printf (_("“%s” could not be found. Perhaps it has recently been deleted."),
- file_name);
- break;
- default:
- message = g_strdup_printf (_("Sorry, could not display all the contents of “%s”: %s"), file_name,
- error->message);
- }
- } else {
- message = g_strdup (error->message);
- }
-
- eel_show_error_dialog (_("This location could not be displayed."), message, parent_window);
-
- g_free (file_name);
- g_free (message);
+ char *file_name;
+ char *message;
+
+ if (error == NULL ||
+ error->message == NULL)
+ {
+ return;
+ }
+
+ if (error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_NOT_MOUNTED)
+ {
+ /* This case is retried automatically */
+ return;
+ }
+
+ file_name = nautilus_file_get_display_name (file);
+
+ if (error->domain == G_IO_ERROR)
+ {
+ switch (error->code)
+ {
+ case G_IO_ERROR_PERMISSION_DENIED:
+ {
+ message = g_strdup_printf (_("You do not have the permissions necessary to view the contents of “%s”."),
+ file_name);
+ }
+ break;
+
+ case G_IO_ERROR_NOT_FOUND:
+ {
+ message = g_strdup_printf (_("“%s” could not be found. Perhaps it has recently been deleted."),
+ file_name);
+ }
+ break;
+
+ default:
+ message = g_strdup_printf (_("Sorry, could not display all the contents of “%s”: %s"), file_name,
+ error->message);
+ }
+ }
+ else
+ {
+ message = g_strdup (error->message);
+ }
+
+ eel_show_error_dialog (_("This location could not be displayed."), message, parent_window);
+
+ g_free (file_name);
+ g_free (message);
}
void
nautilus_report_error_setting_group (NautilusFile *file,
- GError *error,
- GtkWindow *parent_window)
+ GError *error,
+ GtkWindow *parent_window)
{
- char *file_name;
- char *message;
-
- if (error == NULL) {
- return;
- }
-
- file_name = nautilus_file_get_display_name (file);
-
- message = NULL;
- if (error->domain == G_IO_ERROR) {
- switch (error->code) {
- case G_IO_ERROR_PERMISSION_DENIED:
- message = g_strdup_printf (_("You do not have the permissions necessary to change the group of “%s”."),
- file_name);
- break;
- default:
- break;
- }
- }
-
- if (message == NULL) {
- /* We should invent decent error messages for every case we actually experience. */
- g_warning ("Hit unhandled case %s:%d in nautilus_report_error_setting_group",
- g_quark_to_string (error->domain), error->code);
- /* fall through */
- message = g_strdup_printf (_("Sorry, could not change the group of “%s”: %s"), file_name,
- error->message);
- }
-
-
- eel_show_error_dialog (_("The group could not be changed."), message, parent_window);
-
- g_free (file_name);
- g_free (message);
+ char *file_name;
+ char *message;
+
+ if (error == NULL)
+ {
+ return;
+ }
+
+ file_name = nautilus_file_get_display_name (file);
+
+ message = NULL;
+ if (error->domain == G_IO_ERROR)
+ {
+ switch (error->code)
+ {
+ case G_IO_ERROR_PERMISSION_DENIED:
+ {
+ message = g_strdup_printf (_("You do not have the permissions necessary to change the group of “%s”."),
+ file_name);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+ }
+
+ if (message == NULL)
+ {
+ /* We should invent decent error messages for every case we actually experience. */
+ g_warning ("Hit unhandled case %s:%d in nautilus_report_error_setting_group",
+ g_quark_to_string (error->domain), error->code);
+ /* fall through */
+ message = g_strdup_printf (_("Sorry, could not change the group of “%s”: %s"), file_name,
+ error->message);
+ }
+
+
+ eel_show_error_dialog (_("The group could not be changed."), message, parent_window);
+
+ g_free (file_name);
+ g_free (message);
}
void
nautilus_report_error_setting_owner (NautilusFile *file,
- GError *error,
- GtkWindow *parent_window)
+ GError *error,
+ GtkWindow *parent_window)
{
- char *file_name;
- char *message;
+ char *file_name;
+ char *message;
- if (error == NULL) {
- return;
- }
+ if (error == NULL)
+ {
+ return;
+ }
- file_name = nautilus_file_get_display_name (file);
+ file_name = nautilus_file_get_display_name (file);
- message = g_strdup_printf (_("Sorry, could not change the owner of “%s”: %s"), file_name, error->message);
+ message = g_strdup_printf (_("Sorry, could not change the owner of “%s”: %s"), file_name, error->message);
- eel_show_error_dialog (_("The owner could not be changed."), message, parent_window);
+ eel_show_error_dialog (_("The owner could not be changed."), message, parent_window);
- g_free (file_name);
- g_free (message);
-}
+ g_free (file_name);
+ g_free (message);
+}
void
nautilus_report_error_setting_permissions (NautilusFile *file,
- GError *error,
- GtkWindow *parent_window)
+ GError *error,
+ GtkWindow *parent_window)
{
- char *file_name;
- char *message;
+ char *file_name;
+ char *message;
- if (error == NULL) {
- return;
- }
+ if (error == NULL)
+ {
+ return;
+ }
- file_name = nautilus_file_get_display_name (file);
+ file_name = nautilus_file_get_display_name (file);
- message = g_strdup_printf (_("Sorry, could not change the permissions of “%s”: %s"), file_name, error->message);
+ message = g_strdup_printf (_("Sorry, could not change the permissions of “%s”: %s"), file_name, error->message);
- eel_show_error_dialog (_("The permissions could not be changed."), message, parent_window);
+ eel_show_error_dialog (_("The permissions could not be changed."), message, parent_window);
- g_free (file_name);
- g_free (message);
-}
+ g_free (file_name);
+ g_free (message);
+}
-typedef struct _NautilusRenameData {
- char *name;
- NautilusFileOperationCallback callback;
- gpointer callback_data;
+typedef struct _NautilusRenameData
+{
+ char *name;
+ NautilusFileOperationCallback callback;
+ gpointer callback_data;
} NautilusRenameData;
void
nautilus_report_error_renaming_file (NautilusFile *file,
- const char *new_name,
- GError *error,
- GtkWindow *parent_window)
+ const char *new_name,
+ GError *error,
+ GtkWindow *parent_window)
{
- char *original_name, *original_name_truncated;
- char *new_name_truncated;
- char *message;
-
- /* Truncate names for display since very long file names with no spaces
- * in them won't get wrapped, and can create insanely wide dialog boxes.
- */
- original_name = nautilus_file_get_display_name (file);
- original_name_truncated = eel_str_middle_truncate (original_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH);
- g_free (original_name);
-
- new_name_truncated = eel_str_middle_truncate (new_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH);
-
- message = NULL;
- if (error->domain == G_IO_ERROR) {
- switch (error->code) {
- case G_IO_ERROR_EXISTS:
- message = g_strdup_printf (_("The name “%s” is already used in this location. "
- "Please use a different name."),
- new_name_truncated);
- break;
- case G_IO_ERROR_NOT_FOUND:
- message = g_strdup_printf (_("There is no “%s” in this location. "
- "Perhaps it was just moved or deleted?"),
- original_name_truncated);
- break;
- case G_IO_ERROR_PERMISSION_DENIED:
- message = g_strdup_printf (_("You do not have the permissions necessary to rename “%s”."),
- original_name_truncated);
- break;
- case G_IO_ERROR_INVALID_FILENAME:
- if (strchr (new_name, '/') != NULL) {
- message = g_strdup_printf (_("The name “%s” is not valid because it contains the character “/”. "
- "Please use a different name."),
- new_name_truncated);
- } else {
- message = g_strdup_printf (_("The name “%s” is not valid. "
- "Please use a different name."),
- new_name_truncated);
- }
- break;
- case G_IO_ERROR_FILENAME_TOO_LONG:
- message = g_strdup_printf (_("The name “%s” is too long. "
- "Please use a different name."),
- new_name_truncated);
- break;
- default:
- break;
- }
- }
-
- if (message == NULL) {
- /* We should invent decent error messages for every case we actually experience. */
- g_warning ("Hit unhandled case %s:%d in nautilus_report_error_renaming_file",
- g_quark_to_string (error->domain), error->code);
- /* fall through */
- message = g_strdup_printf (_("Sorry, could not rename “%s” to “%s”: %s"),
- original_name_truncated, new_name_truncated,
- error->message);
- }
-
- g_free (original_name_truncated);
- g_free (new_name_truncated);
-
- eel_show_error_dialog (_("The item could not be renamed."), message, parent_window);
- g_free (message);
+ char *original_name, *original_name_truncated;
+ char *new_name_truncated;
+ char *message;
+
+ /* Truncate names for display since very long file names with no spaces
+ * in them won't get wrapped, and can create insanely wide dialog boxes.
+ */
+ original_name = nautilus_file_get_display_name (file);
+ original_name_truncated = eel_str_middle_truncate (original_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH);
+ g_free (original_name);
+
+ new_name_truncated = eel_str_middle_truncate (new_name, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH);
+
+ message = NULL;
+ if (error->domain == G_IO_ERROR)
+ {
+ switch (error->code)
+ {
+ case G_IO_ERROR_EXISTS:
+ {
+ message = g_strdup_printf (_("The name “%s” is already used in this location. "
+ "Please use a different name."),
+ new_name_truncated);
+ }
+ break;
+
+ case G_IO_ERROR_NOT_FOUND:
+ {
+ message = g_strdup_printf (_("There is no “%s” in this location. "
+ "Perhaps it was just moved or deleted?"),
+ original_name_truncated);
+ }
+ break;
+
+ case G_IO_ERROR_PERMISSION_DENIED:
+ {
+ message = g_strdup_printf (_("You do not have the permissions necessary to rename “%s”."),
+ original_name_truncated);
+ }
+ break;
+
+ case G_IO_ERROR_INVALID_FILENAME:
+ {
+ if (strchr (new_name, '/') != NULL)
+ {
+ message = g_strdup_printf (_("The name “%s” is not valid because it contains the character “/”. "
+ "Please use a different name."),
+ new_name_truncated);
+ }
+ else
+ {
+ message = g_strdup_printf (_("The name “%s” is not valid. "
+ "Please use a different name."),
+ new_name_truncated);
+ }
+ }
+ break;
+
+ case G_IO_ERROR_FILENAME_TOO_LONG:
+ {
+ message = g_strdup_printf (_("The name “%s” is too long. "
+ "Please use a different name."),
+ new_name_truncated);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+ }
+
+ if (message == NULL)
+ {
+ /* We should invent decent error messages for every case we actually experience. */
+ g_warning ("Hit unhandled case %s:%d in nautilus_report_error_renaming_file",
+ g_quark_to_string (error->domain), error->code);
+ /* fall through */
+ message = g_strdup_printf (_("Sorry, could not rename “%s” to “%s”: %s"),
+ original_name_truncated, new_name_truncated,
+ error->message);
+ }
+
+ g_free (original_name_truncated);
+ g_free (new_name_truncated);
+
+ eel_show_error_dialog (_("The item could not be renamed."), message, parent_window);
+ g_free (message);
}
static void
nautilus_rename_data_free (NautilusRenameData *data)
{
- g_free (data->name);
- g_free (data);
+ g_free (data->name);
+ g_free (data);
}
static void
-rename_callback (NautilusFile *file, GFile *result_location,
- GError *error, gpointer callback_data)
+rename_callback (NautilusFile *file,
+ GFile *result_location,
+ GError *error,
+ gpointer callback_data)
{
- NautilusRenameData *data;
- gboolean cancelled = FALSE;
-
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (callback_data == NULL);
-
- data = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
- g_assert (data != NULL);
-
- if (error) {
- if (!(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)) {
- /* If rename failed, notify the user. */
- nautilus_report_error_renaming_file (file, data->name, error, NULL);
- } else {
- cancelled = TRUE;
- }
- }
-
- finish_rename (file, ! cancelled, error);
+ NautilusRenameData *data;
+ gboolean cancelled = FALSE;
+
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (callback_data == NULL);
+
+ data = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
+ g_assert (data != NULL);
+
+ if (error)
+ {
+ if (!(error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED))
+ {
+ /* If rename failed, notify the user. */
+ nautilus_report_error_renaming_file (file, data->name, error, NULL);
+ }
+ else
+ {
+ cancelled = TRUE;
+ }
+ }
+
+ finish_rename (file, !cancelled, error);
}
static void
cancel_rename_callback (gpointer callback_data)
{
- nautilus_file_cancel (NAUTILUS_FILE (callback_data), rename_callback, NULL);
+ nautilus_file_cancel (NAUTILUS_FILE (callback_data), rename_callback, NULL);
}
static void
-finish_rename (NautilusFile *file, gboolean stop_timer, GError *error)
+finish_rename (NautilusFile *file,
+ gboolean stop_timer,
+ GError *error)
{
- NautilusRenameData *data;
-
- data = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
- if (data == NULL) {
- return;
- }
-
- /* Cancel both the rename and the timed wait. */
- nautilus_file_cancel (file, rename_callback, NULL);
- if (stop_timer) {
- eel_timed_wait_stop (cancel_rename_callback, file);
- }
-
- if (data->callback != NULL) {
- data->callback (file, NULL, error, data->callback_data);
- }
-
- /* Let go of file name. */
- g_object_set_data (G_OBJECT (file), NEW_NAME_TAG, NULL);
+ NautilusRenameData *data;
+
+ data = g_object_get_data (G_OBJECT (file), NEW_NAME_TAG);
+ if (data == NULL)
+ {
+ return;
+ }
+
+ /* Cancel both the rename and the timed wait. */
+ nautilus_file_cancel (file, rename_callback, NULL);
+ if (stop_timer)
+ {
+ eel_timed_wait_stop (cancel_rename_callback, file);
+ }
+
+ if (data->callback != NULL)
+ {
+ data->callback (file, NULL, error, data->callback_data);
+ }
+
+ /* Let go of file name. */
+ g_object_set_data (G_OBJECT (file), NEW_NAME_TAG, NULL);
}
void
-nautilus_rename_file (NautilusFile *file,
- const char *new_name,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+nautilus_rename_file (NautilusFile *file,
+ const char *new_name,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- char *old_name, *wait_message;
- NautilusRenameData *data;
- char *uri;
- GError *error;
-
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (new_name != NULL);
-
- /* Stop any earlier rename that's already in progress. */
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled");
- finish_rename (file, TRUE, error);
- g_error_free (error);
-
- data = g_new0 (NautilusRenameData, 1);
- data->name = g_strdup (new_name);
- data->callback = callback;
- data->callback_data = callback_data;
-
- /* Attach the new name to the file. */
- g_object_set_data_full (G_OBJECT (file),
- NEW_NAME_TAG,
- data, (GDestroyNotify)nautilus_rename_data_free);
-
- /* Start the timed wait to cancel the rename. */
- old_name = nautilus_file_get_display_name (file);
- wait_message = g_strdup_printf (_("Renaming “%s” to “%s”."),
- old_name,
- new_name);
- g_free (old_name);
- eel_timed_wait_start (cancel_rename_callback, file, wait_message,
- NULL); /* FIXME bugzilla.gnome.org 42395: Parent this? */
- g_free (wait_message);
-
- uri = nautilus_file_get_uri (file);
- DEBUG ("Renaming file %s to %s", uri, new_name);
- g_free (uri);
-
- /* Start the rename. */
- nautilus_file_rename (file, new_name,
- rename_callback, NULL);
+ char *old_name, *wait_message;
+ NautilusRenameData *data;
+ char *uri;
+ GError *error;
+
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (new_name != NULL);
+
+ /* Stop any earlier rename that's already in progress. */
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_CANCELLED, "Cancelled");
+ finish_rename (file, TRUE, error);
+ g_error_free (error);
+
+ data = g_new0 (NautilusRenameData, 1);
+ data->name = g_strdup (new_name);
+ data->callback = callback;
+ data->callback_data = callback_data;
+
+ /* Attach the new name to the file. */
+ g_object_set_data_full (G_OBJECT (file),
+ NEW_NAME_TAG,
+ data, (GDestroyNotify) nautilus_rename_data_free);
+
+ /* Start the timed wait to cancel the rename. */
+ old_name = nautilus_file_get_display_name (file);
+ wait_message = g_strdup_printf (_("Renaming “%s” to “%s”."),
+ old_name,
+ new_name);
+ g_free (old_name);
+ eel_timed_wait_start (cancel_rename_callback, file, wait_message,
+ NULL); /* FIXME bugzilla.gnome.org 42395: Parent this? */
+ g_free (wait_message);
+
+ uri = nautilus_file_get_uri (file);
+ DEBUG ("Renaming file %s to %s", uri, new_name);
+ g_free (uri);
+
+ /* Start the rename. */
+ nautilus_file_rename (file, new_name,
+ rename_callback, NULL);
}
diff --git a/src/nautilus-file-changes-queue.c b/src/nautilus-file-changes-queue.c
index b637c61e2..44c2d55c3 100644
--- a/src/nautilus-file-changes-queue.c
+++ b/src/nautilus-file-changes-queue.c
@@ -1,393 +1,431 @@
/*
- Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Pavel Cisler <pavel@eazel.com>
-*/
+ * Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Pavel Cisler <pavel@eazel.com>
+ */
#include <config.h>
#include "nautilus-file-changes-queue.h"
#include "nautilus-directory-notify.h"
-typedef enum {
- CHANGE_FILE_INITIAL,
- CHANGE_FILE_ADDED,
- CHANGE_FILE_CHANGED,
- CHANGE_FILE_REMOVED,
- CHANGE_FILE_MOVED,
- CHANGE_POSITION_SET,
- CHANGE_POSITION_REMOVE
+typedef enum
+{
+ CHANGE_FILE_INITIAL,
+ CHANGE_FILE_ADDED,
+ CHANGE_FILE_CHANGED,
+ CHANGE_FILE_REMOVED,
+ CHANGE_FILE_MOVED,
+ CHANGE_POSITION_SET,
+ CHANGE_POSITION_REMOVE
} NautilusFileChangeKind;
-typedef struct {
- NautilusFileChangeKind kind;
- GFile *from;
- GFile *to;
- GdkPoint point;
- int screen;
+typedef struct
+{
+ NautilusFileChangeKind kind;
+ GFile *from;
+ GFile *to;
+ GdkPoint point;
+ int screen;
} NautilusFileChange;
-typedef struct {
- GList *head;
- GList *tail;
- GMutex mutex;
+typedef struct
+{
+ GList *head;
+ GList *tail;
+ GMutex mutex;
} NautilusFileChangesQueue;
static NautilusFileChangesQueue *
nautilus_file_changes_queue_new (void)
{
- NautilusFileChangesQueue *result;
+ NautilusFileChangesQueue *result;
- result = g_new0 (NautilusFileChangesQueue, 1);
- g_mutex_init (&result->mutex);
+ result = g_new0 (NautilusFileChangesQueue, 1);
+ g_mutex_init (&result->mutex);
- return result;
+ return result;
}
static NautilusFileChangesQueue *
nautilus_file_changes_queue_get (void)
{
- static NautilusFileChangesQueue *file_changes_queue;
+ static NautilusFileChangesQueue *file_changes_queue;
- if (file_changes_queue == NULL) {
- file_changes_queue = nautilus_file_changes_queue_new ();
- }
+ if (file_changes_queue == NULL)
+ {
+ file_changes_queue = nautilus_file_changes_queue_new ();
+ }
- return file_changes_queue;
+ return file_changes_queue;
}
static void
-nautilus_file_changes_queue_add_common (NautilusFileChangesQueue *queue,
- NautilusFileChange *new_item)
+nautilus_file_changes_queue_add_common (NautilusFileChangesQueue *queue,
+ NautilusFileChange *new_item)
{
- /* enqueue the new queue item while locking down the list */
- g_mutex_lock (&queue->mutex);
+ /* enqueue the new queue item while locking down the list */
+ g_mutex_lock (&queue->mutex);
- queue->head = g_list_prepend (queue->head, new_item);
- if (queue->tail == NULL)
- queue->tail = queue->head;
+ queue->head = g_list_prepend (queue->head, new_item);
+ if (queue->tail == NULL)
+ {
+ queue->tail = queue->head;
+ }
- g_mutex_unlock (&queue->mutex);
+ g_mutex_unlock (&queue->mutex);
}
void
nautilus_file_changes_queue_file_added (GFile *location)
{
- NautilusFileChange *new_item;
- NautilusFileChangesQueue *queue;
+ NautilusFileChange *new_item;
+ NautilusFileChangesQueue *queue;
- queue = nautilus_file_changes_queue_get();
+ queue = nautilus_file_changes_queue_get ();
- new_item = g_new0 (NautilusFileChange, 1);
- new_item->kind = CHANGE_FILE_ADDED;
- new_item->from = g_object_ref (location);
- nautilus_file_changes_queue_add_common (queue, new_item);
+ new_item = g_new0 (NautilusFileChange, 1);
+ new_item->kind = CHANGE_FILE_ADDED;
+ new_item->from = g_object_ref (location);
+ nautilus_file_changes_queue_add_common (queue, new_item);
}
void
nautilus_file_changes_queue_file_changed (GFile *location)
{
- NautilusFileChange *new_item;
- NautilusFileChangesQueue *queue;
+ NautilusFileChange *new_item;
+ NautilusFileChangesQueue *queue;
- queue = nautilus_file_changes_queue_get();
+ queue = nautilus_file_changes_queue_get ();
- new_item = g_new0 (NautilusFileChange, 1);
- new_item->kind = CHANGE_FILE_CHANGED;
- new_item->from = g_object_ref (location);
- nautilus_file_changes_queue_add_common (queue, new_item);
+ new_item = g_new0 (NautilusFileChange, 1);
+ new_item->kind = CHANGE_FILE_CHANGED;
+ new_item->from = g_object_ref (location);
+ nautilus_file_changes_queue_add_common (queue, new_item);
}
void
nautilus_file_changes_queue_file_removed (GFile *location)
{
- NautilusFileChange *new_item;
- NautilusFileChangesQueue *queue;
+ NautilusFileChange *new_item;
+ NautilusFileChangesQueue *queue;
- queue = nautilus_file_changes_queue_get();
+ queue = nautilus_file_changes_queue_get ();
- new_item = g_new0 (NautilusFileChange, 1);
- new_item->kind = CHANGE_FILE_REMOVED;
- new_item->from = g_object_ref (location);
- nautilus_file_changes_queue_add_common (queue, new_item);
+ new_item = g_new0 (NautilusFileChange, 1);
+ new_item->kind = CHANGE_FILE_REMOVED;
+ new_item->from = g_object_ref (location);
+ nautilus_file_changes_queue_add_common (queue, new_item);
}
void
nautilus_file_changes_queue_file_moved (GFile *from,
- GFile *to)
+ GFile *to)
{
- NautilusFileChange *new_item;
- NautilusFileChangesQueue *queue;
+ NautilusFileChange *new_item;
+ NautilusFileChangesQueue *queue;
- queue = nautilus_file_changes_queue_get ();
+ queue = nautilus_file_changes_queue_get ();
- new_item = g_new (NautilusFileChange, 1);
- new_item->kind = CHANGE_FILE_MOVED;
- new_item->from = g_object_ref (from);
- new_item->to = g_object_ref (to);
- nautilus_file_changes_queue_add_common (queue, new_item);
+ new_item = g_new (NautilusFileChange, 1);
+ new_item->kind = CHANGE_FILE_MOVED;
+ new_item->from = g_object_ref (from);
+ new_item->to = g_object_ref (to);
+ nautilus_file_changes_queue_add_common (queue, new_item);
}
void
-nautilus_file_changes_queue_schedule_position_set (GFile *location,
- GdkPoint point,
- int screen)
+nautilus_file_changes_queue_schedule_position_set (GFile *location,
+ GdkPoint point,
+ int screen)
{
- NautilusFileChange *new_item;
- NautilusFileChangesQueue *queue;
+ NautilusFileChange *new_item;
+ NautilusFileChangesQueue *queue;
- queue = nautilus_file_changes_queue_get ();
+ queue = nautilus_file_changes_queue_get ();
- new_item = g_new (NautilusFileChange, 1);
- new_item->kind = CHANGE_POSITION_SET;
- new_item->from = g_object_ref (location);
- new_item->point = point;
- new_item->screen = screen;
- nautilus_file_changes_queue_add_common (queue, new_item);
+ new_item = g_new (NautilusFileChange, 1);
+ new_item->kind = CHANGE_POSITION_SET;
+ new_item->from = g_object_ref (location);
+ new_item->point = point;
+ new_item->screen = screen;
+ nautilus_file_changes_queue_add_common (queue, new_item);
}
void
nautilus_file_changes_queue_schedule_position_remove (GFile *location)
{
- NautilusFileChange *new_item;
- NautilusFileChangesQueue *queue;
+ NautilusFileChange *new_item;
+ NautilusFileChangesQueue *queue;
- queue = nautilus_file_changes_queue_get ();
+ queue = nautilus_file_changes_queue_get ();
- new_item = g_new (NautilusFileChange, 1);
- new_item->kind = CHANGE_POSITION_REMOVE;
- new_item->from = g_object_ref (location);
- nautilus_file_changes_queue_add_common (queue, new_item);
+ new_item = g_new (NautilusFileChange, 1);
+ new_item->kind = CHANGE_POSITION_REMOVE;
+ new_item->from = g_object_ref (location);
+ nautilus_file_changes_queue_add_common (queue, new_item);
}
static NautilusFileChange *
nautilus_file_changes_queue_get_change (NautilusFileChangesQueue *queue)
{
- GList *new_tail;
- NautilusFileChange *result;
-
- g_assert (queue != NULL);
-
- /* dequeue the tail item while locking down the list */
- g_mutex_lock (&queue->mutex);
-
- if (queue->tail == NULL) {
- result = NULL;
- } else {
- new_tail = queue->tail->prev;
- result = queue->tail->data;
- queue->head = g_list_remove_link (queue->head,
- queue->tail);
- g_list_free_1 (queue->tail);
- queue->tail = new_tail;
- }
-
- g_mutex_unlock (&queue->mutex);
-
- return result;
+ GList *new_tail;
+ NautilusFileChange *result;
+
+ g_assert (queue != NULL);
+
+ /* dequeue the tail item while locking down the list */
+ g_mutex_lock (&queue->mutex);
+
+ if (queue->tail == NULL)
+ {
+ result = NULL;
+ }
+ else
+ {
+ new_tail = queue->tail->prev;
+ result = queue->tail->data;
+ queue->head = g_list_remove_link (queue->head,
+ queue->tail);
+ g_list_free_1 (queue->tail);
+ queue->tail = new_tail;
+ }
+
+ g_mutex_unlock (&queue->mutex);
+
+ return result;
}
-enum {
- CONSUME_CHANGES_MAX_CHUNK = 20
+enum
+{
+ CONSUME_CHANGES_MAX_CHUNK = 20
};
static void
pairs_list_free (GList *pairs)
{
- GList *p;
- GFilePair *pair;
+ GList *p;
+ GFilePair *pair;
- /* deep delete the list of pairs */
+ /* deep delete the list of pairs */
- for (p = pairs; p != NULL; p = p->next) {
- /* delete the strings in each pair */
- pair = p->data;
- g_object_unref (pair->from);
- g_object_unref (pair->to);
- }
+ for (p = pairs; p != NULL; p = p->next)
+ {
+ /* delete the strings in each pair */
+ pair = p->data;
+ g_object_unref (pair->from);
+ g_object_unref (pair->to);
+ }
- /* delete the list and the now empty pair structs */
- g_list_free_full (pairs, g_free);
+ /* delete the list and the now empty pair structs */
+ g_list_free_full (pairs, g_free);
}
static void
position_set_list_free (GList *list)
{
- GList *p;
- NautilusFileChangesQueuePosition *item;
-
- for (p = list; p != NULL; p = p->next) {
- item = p->data;
- g_object_unref (item->location);
- }
- /* delete the list and the now empty structs */
- g_list_free_full (list, g_free);
+ GList *p;
+ NautilusFileChangesQueuePosition *item;
+
+ for (p = list; p != NULL; p = p->next)
+ {
+ item = p->data;
+ g_object_unref (item->location);
+ }
+ /* delete the list and the now empty structs */
+ g_list_free_full (list, g_free);
}
/* go through changes in the change queue, send ones with the same kind
* in a list to the different nautilus_directory_notify calls
- */
+ */
void
nautilus_file_changes_consume_changes (gboolean consume_all)
{
- NautilusFileChange *change;
- GList *additions, *changes, *deletions, *moves;
- GList *position_set_requests;
- GFilePair *pair;
- NautilusFileChangesQueuePosition *position_set;
- guint chunk_count;
- NautilusFileChangesQueue *queue;
- gboolean flush_needed;
-
-
- additions = NULL;
- changes = NULL;
- deletions = NULL;
- moves = NULL;
- position_set_requests = NULL;
-
- queue = nautilus_file_changes_queue_get();
-
- /* Consume changes from the queue, stuffing them into one of three lists,
- * keep doing it while the changes are of the same kind, then send them off.
- * This is to ensure that the changes get sent off in the same order that they
- * arrived.
- */
- for (chunk_count = 0; ; chunk_count++) {
- change = nautilus_file_changes_queue_get_change (queue);
-
- /* figure out if we need to flush the pending changes that we collected sofar */
-
- if (change == NULL) {
- flush_needed = TRUE;
- /* no changes left, flush everything */
- } else {
- flush_needed = additions != NULL
- && change->kind != CHANGE_FILE_ADDED
- && change->kind != CHANGE_POSITION_SET
- && change->kind != CHANGE_POSITION_REMOVE;
-
- flush_needed |= changes != NULL
- && change->kind != CHANGE_FILE_CHANGED;
-
- flush_needed |= moves != NULL
- && change->kind != CHANGE_FILE_MOVED
- && change->kind != CHANGE_POSITION_SET
- && change->kind != CHANGE_POSITION_REMOVE;
-
- flush_needed |= deletions != NULL
- && change->kind != CHANGE_FILE_REMOVED;
-
- flush_needed |= position_set_requests != NULL
- && change->kind != CHANGE_POSITION_SET
- && change->kind != CHANGE_POSITION_REMOVE
- && change->kind != CHANGE_FILE_ADDED
- && change->kind != CHANGE_FILE_MOVED;
-
- flush_needed |= !consume_all && chunk_count >= CONSUME_CHANGES_MAX_CHUNK;
- /* we have reached the chunk maximum */
- }
-
- if (flush_needed) {
- /* Send changes we collected off.
- * At one time we may only have one of the lists
- * contain changes.
- */
-
- if (deletions != NULL) {
- deletions = g_list_reverse (deletions);
- nautilus_directory_notify_files_removed (deletions);
- g_list_free_full (deletions, g_object_unref);
- deletions = NULL;
- }
- if (moves != NULL) {
- moves = g_list_reverse (moves);
- nautilus_directory_notify_files_moved (moves);
- pairs_list_free (moves);
- moves = NULL;
- }
- if (additions != NULL) {
- additions = g_list_reverse (additions);
- nautilus_directory_notify_files_added (additions);
- g_list_free_full (additions, g_object_unref);
- additions = NULL;
- }
- if (changes != NULL) {
- changes = g_list_reverse (changes);
- nautilus_directory_notify_files_changed (changes);
- g_list_free_full (changes, g_object_unref);
- changes = NULL;
- }
- if (position_set_requests != NULL) {
- position_set_requests = g_list_reverse (position_set_requests);
- nautilus_directory_schedule_position_set (position_set_requests);
- position_set_list_free (position_set_requests);
- position_set_requests = NULL;
- }
- }
-
- if (change == NULL) {
- /* we are done */
- return;
- }
-
- /* add the new change to the list */
- switch (change->kind) {
- case CHANGE_FILE_ADDED:
- additions = g_list_prepend (additions, change->from);
- break;
-
- case CHANGE_FILE_CHANGED:
- changes = g_list_prepend (changes, change->from);
- break;
-
- case CHANGE_FILE_REMOVED:
- deletions = g_list_prepend (deletions, change->from);
- break;
-
- case CHANGE_FILE_MOVED:
- pair = g_new (GFilePair, 1);
- pair->from = change->from;
- pair->to = change->to;
- moves = g_list_prepend (moves, pair);
- break;
-
- case CHANGE_POSITION_SET:
- position_set = g_new (NautilusFileChangesQueuePosition, 1);
- position_set->location = change->from;
- position_set->set = TRUE;
- position_set->point = change->point;
- position_set->screen = change->screen;
- position_set_requests = g_list_prepend (position_set_requests,
- position_set);
- break;
-
- case CHANGE_POSITION_REMOVE:
- position_set = g_new (NautilusFileChangesQueuePosition, 1);
- position_set->location = change->from;
- position_set->set = FALSE;
- position_set_requests = g_list_prepend (position_set_requests,
- position_set);
- break;
-
- default:
- g_assert_not_reached ();
- break;
- }
-
- g_free (change);
- }
+ NautilusFileChange *change;
+ GList *additions, *changes, *deletions, *moves;
+ GList *position_set_requests;
+ GFilePair *pair;
+ NautilusFileChangesQueuePosition *position_set;
+ guint chunk_count;
+ NautilusFileChangesQueue *queue;
+ gboolean flush_needed;
+
+
+ additions = NULL;
+ changes = NULL;
+ deletions = NULL;
+ moves = NULL;
+ position_set_requests = NULL;
+
+ queue = nautilus_file_changes_queue_get ();
+
+ /* Consume changes from the queue, stuffing them into one of three lists,
+ * keep doing it while the changes are of the same kind, then send them off.
+ * This is to ensure that the changes get sent off in the same order that they
+ * arrived.
+ */
+ for (chunk_count = 0;; chunk_count++)
+ {
+ change = nautilus_file_changes_queue_get_change (queue);
+
+ /* figure out if we need to flush the pending changes that we collected sofar */
+
+ if (change == NULL)
+ {
+ flush_needed = TRUE;
+ /* no changes left, flush everything */
+ }
+ else
+ {
+ flush_needed = additions != NULL
+ && change->kind != CHANGE_FILE_ADDED
+ && change->kind != CHANGE_POSITION_SET
+ && change->kind != CHANGE_POSITION_REMOVE;
+
+ flush_needed |= changes != NULL
+ && change->kind != CHANGE_FILE_CHANGED;
+
+ flush_needed |= moves != NULL
+ && change->kind != CHANGE_FILE_MOVED
+ && change->kind != CHANGE_POSITION_SET
+ && change->kind != CHANGE_POSITION_REMOVE;
+
+ flush_needed |= deletions != NULL
+ && change->kind != CHANGE_FILE_REMOVED;
+
+ flush_needed |= position_set_requests != NULL
+ && change->kind != CHANGE_POSITION_SET
+ && change->kind != CHANGE_POSITION_REMOVE
+ && change->kind != CHANGE_FILE_ADDED
+ && change->kind != CHANGE_FILE_MOVED;
+
+ flush_needed |= !consume_all && chunk_count >= CONSUME_CHANGES_MAX_CHUNK;
+ /* we have reached the chunk maximum */
+ }
+
+ if (flush_needed)
+ {
+ /* Send changes we collected off.
+ * At one time we may only have one of the lists
+ * contain changes.
+ */
+
+ if (deletions != NULL)
+ {
+ deletions = g_list_reverse (deletions);
+ nautilus_directory_notify_files_removed (deletions);
+ g_list_free_full (deletions, g_object_unref);
+ deletions = NULL;
+ }
+ if (moves != NULL)
+ {
+ moves = g_list_reverse (moves);
+ nautilus_directory_notify_files_moved (moves);
+ pairs_list_free (moves);
+ moves = NULL;
+ }
+ if (additions != NULL)
+ {
+ additions = g_list_reverse (additions);
+ nautilus_directory_notify_files_added (additions);
+ g_list_free_full (additions, g_object_unref);
+ additions = NULL;
+ }
+ if (changes != NULL)
+ {
+ changes = g_list_reverse (changes);
+ nautilus_directory_notify_files_changed (changes);
+ g_list_free_full (changes, g_object_unref);
+ changes = NULL;
+ }
+ if (position_set_requests != NULL)
+ {
+ position_set_requests = g_list_reverse (position_set_requests);
+ nautilus_directory_schedule_position_set (position_set_requests);
+ position_set_list_free (position_set_requests);
+ position_set_requests = NULL;
+ }
+ }
+
+ if (change == NULL)
+ {
+ /* we are done */
+ return;
+ }
+
+ /* add the new change to the list */
+ switch (change->kind)
+ {
+ case CHANGE_FILE_ADDED:
+ {
+ additions = g_list_prepend (additions, change->from);
+ }
+ break;
+
+ case CHANGE_FILE_CHANGED:
+ {
+ changes = g_list_prepend (changes, change->from);
+ }
+ break;
+
+ case CHANGE_FILE_REMOVED:
+ {
+ deletions = g_list_prepend (deletions, change->from);
+ }
+ break;
+
+ case CHANGE_FILE_MOVED:
+ {
+ pair = g_new (GFilePair, 1);
+ pair->from = change->from;
+ pair->to = change->to;
+ moves = g_list_prepend (moves, pair);
+ }
+ break;
+
+ case CHANGE_POSITION_SET:
+ {
+ position_set = g_new (NautilusFileChangesQueuePosition, 1);
+ position_set->location = change->from;
+ position_set->set = TRUE;
+ position_set->point = change->point;
+ position_set->screen = change->screen;
+ position_set_requests = g_list_prepend (position_set_requests,
+ position_set);
+ }
+ break;
+
+ case CHANGE_POSITION_REMOVE:
+ {
+ position_set = g_new (NautilusFileChangesQueuePosition, 1);
+ position_set->location = change->from;
+ position_set->set = FALSE;
+ position_set_requests = g_list_prepend (position_set_requests,
+ position_set);
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
+
+ g_free (change);
+ }
}
diff --git a/src/nautilus-file-conflict-dialog.c b/src/nautilus-file-conflict-dialog.c
index 0ba63a117..a11eb689d 100644
--- a/src/nautilus-file-conflict-dialog.c
+++ b/src/nautilus-file-conflict-dialog.c
@@ -1,24 +1,23 @@
-
/* nautilus-file-conflict-dialog: dialog that handles file conflicts
- during transfer operations.
-
- Copyright (C) 2008-2010 Cosimo Cecchi
-
- 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, see <http://www.gnu.org/licenses/>.
-
- Authors: Cosimo Cecchi <cosimoc@gnome.org>
-*/
+ * during transfer operations.
+ *
+ * Copyright (C) 2008-2010 Cosimo Cecchi
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Cosimo Cecchi <cosimoc@gnome.org>
+ */
#include <config.h>
#include "nautilus-file-conflict-dialog.h"
@@ -36,408 +35,420 @@
struct _NautilusFileConflictDialogDetails
{
- gchar *conflict_name;
-
- /* UI objects */
- GtkWidget *titles_vbox;
- GtkWidget *first_hbox;
- GtkWidget *second_hbox;
- GtkWidget *expander;
- GtkWidget *entry;
- GtkWidget *checkbox;
- GtkWidget *skip_button;
- GtkWidget *rename_button;
- GtkWidget *replace_button;
- GtkWidget *dest_image;
- GtkWidget *src_image;
+ gchar *conflict_name;
+
+ /* UI objects */
+ GtkWidget *titles_vbox;
+ GtkWidget *first_hbox;
+ GtkWidget *second_hbox;
+ GtkWidget *expander;
+ GtkWidget *entry;
+ GtkWidget *checkbox;
+ GtkWidget *skip_button;
+ GtkWidget *rename_button;
+ GtkWidget *replace_button;
+ GtkWidget *dest_image;
+ GtkWidget *src_image;
};
G_DEFINE_TYPE (NautilusFileConflictDialog,
- nautilus_file_conflict_dialog,
- GTK_TYPE_DIALOG);
+ nautilus_file_conflict_dialog,
+ GTK_TYPE_DIALOG);
-#define NAUTILUS_FILE_CONFLICT_DIALOG_GET_PRIVATE(object) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((object), NAUTILUS_TYPE_FILE_CONFLICT_DIALOG, \
- NautilusFileConflictDialogDetails))
+#define NAUTILUS_FILE_CONFLICT_DIALOG_GET_PRIVATE(object) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((object), NAUTILUS_TYPE_FILE_CONFLICT_DIALOG, \
+ NautilusFileConflictDialogDetails))
void
nautilus_file_conflict_dialog_set_text (NautilusFileConflictDialog *fcd,
- gchar *primary_text,
- gchar *secondary_text)
+ gchar *primary_text,
+ gchar *secondary_text)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
- GtkWidget *label;
- PangoAttrList *attr_list;
-
- label = gtk_label_new (primary_text);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- gtk_box_pack_start (GTK_BOX (details->titles_vbox),
- label, FALSE, FALSE, 0);
- gtk_widget_show (label);
-
- attr_list = pango_attr_list_new ();
- pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
- pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE));
- g_object_set (label,
- "attributes", attr_list,
- NULL);
-
- pango_attr_list_unref (attr_list);
-
- label = gtk_label_new (secondary_text);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- gtk_box_pack_start (GTK_BOX (details->titles_vbox),
- label, FALSE, FALSE, 0);
- gtk_widget_show (label);
+ NautilusFileConflictDialogDetails *details = fcd->details;
+ GtkWidget *label;
+ PangoAttrList *attr_list;
+
+ label = gtk_label_new (primary_text);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_line_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD_CHAR);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_box_pack_start (GTK_BOX (details->titles_vbox),
+ label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+
+ attr_list = pango_attr_list_new ();
+ pango_attr_list_insert (attr_list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+ pango_attr_list_insert (attr_list, pango_attr_scale_new (PANGO_SCALE_LARGE));
+ g_object_set (label,
+ "attributes", attr_list,
+ NULL);
+
+ pango_attr_list_unref (attr_list);
+
+ label = gtk_label_new (secondary_text);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.0);
+ gtk_box_pack_start (GTK_BOX (details->titles_vbox),
+ label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
}
void
nautilus_file_conflict_dialog_set_images (NautilusFileConflictDialog *fcd,
- GdkPixbuf *destination_pixbuf,
- GdkPixbuf *source_pixbuf)
+ GdkPixbuf *destination_pixbuf,
+ GdkPixbuf *source_pixbuf)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
-
- if (details->dest_image == NULL) {
- details->dest_image = gtk_image_new_from_pixbuf (destination_pixbuf);
- gtk_box_pack_start (GTK_BOX (details->first_hbox),
- details->dest_image, FALSE, FALSE, 0);
- gtk_widget_show (details->dest_image);
- } else {
- gtk_image_set_from_pixbuf (GTK_IMAGE (details->dest_image),
- destination_pixbuf);
- }
+ NautilusFileConflictDialogDetails *details = fcd->details;
- if (details->src_image == NULL) {
- details->src_image = gtk_image_new_from_pixbuf (source_pixbuf);
- gtk_box_pack_start (GTK_BOX (details->second_hbox),
- details->src_image, FALSE, FALSE, 0);
- gtk_widget_show (details->src_image);
- } else {
- gtk_image_set_from_pixbuf (GTK_IMAGE (details->src_image),
- source_pixbuf);
- }
+ if (details->dest_image == NULL)
+ {
+ details->dest_image = gtk_image_new_from_pixbuf (destination_pixbuf);
+ gtk_box_pack_start (GTK_BOX (details->first_hbox),
+ details->dest_image, FALSE, FALSE, 0);
+ gtk_widget_show (details->dest_image);
+ }
+ else
+ {
+ gtk_image_set_from_pixbuf (GTK_IMAGE (details->dest_image),
+ destination_pixbuf);
+ }
+
+ if (details->src_image == NULL)
+ {
+ details->src_image = gtk_image_new_from_pixbuf (source_pixbuf);
+ gtk_box_pack_start (GTK_BOX (details->second_hbox),
+ details->src_image, FALSE, FALSE, 0);
+ gtk_widget_show (details->src_image);
+ }
+ else
+ {
+ gtk_image_set_from_pixbuf (GTK_IMAGE (details->src_image),
+ source_pixbuf);
+ }
}
void
nautilus_file_conflict_dialog_set_file_labels (NautilusFileConflictDialog *fcd,
- gchar *destination_label,
- gchar *source_label)
+ gchar *destination_label,
+ gchar *source_label)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
- GtkWidget *label;
-
- label = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label),
- destination_label);
- gtk_box_pack_start (GTK_BOX (details->first_hbox),
- label, FALSE, FALSE, 0);
- gtk_widget_show (label);
-
- label = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label),
- source_label);
- gtk_box_pack_start (GTK_BOX (details->second_hbox),
- label, FALSE, FALSE, 0);
- gtk_widget_show (label);
+ NautilusFileConflictDialogDetails *details = fcd->details;
+ GtkWidget *label;
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label),
+ destination_label);
+ gtk_box_pack_start (GTK_BOX (details->first_hbox),
+ label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label),
+ source_label);
+ gtk_box_pack_start (GTK_BOX (details->second_hbox),
+ label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
}
void
nautilus_file_conflict_dialog_set_conflict_name (NautilusFileConflictDialog *fcd,
- gchar *conflict_name)
+ gchar *conflict_name)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
-
- details->conflict_name = g_strdup (conflict_name);
+ NautilusFileConflictDialogDetails *details = fcd->details;
- gtk_entry_set_text (GTK_ENTRY (details->entry), details->conflict_name);
+ details->conflict_name = g_strdup (conflict_name);
+ gtk_entry_set_text (GTK_ENTRY (details->entry), details->conflict_name);
}
void
nautilus_file_conflict_dialog_set_replace_button_label (NautilusFileConflictDialog *fcd,
- gchar *label)
+ gchar *label)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
+ NautilusFileConflictDialogDetails *details = fcd->details;
- gtk_button_set_label (GTK_BUTTON (details->replace_button),
- label);
+ gtk_button_set_label (GTK_BUTTON (details->replace_button),
+ label);
}
void
nautilus_file_conflict_dialog_disable_skip (NautilusFileConflictDialog *fcd)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
+ NautilusFileConflictDialogDetails *details = fcd->details;
- gtk_widget_hide (details->skip_button);
+ gtk_widget_hide (details->skip_button);
}
void
nautilus_file_conflict_dialog_disable_apply_to_all (NautilusFileConflictDialog *fcd)
{
- NautilusFileConflictDialogDetails *details = fcd->details;
+ NautilusFileConflictDialogDetails *details = fcd->details;
- gtk_widget_hide (details->checkbox);
+ gtk_widget_hide (details->checkbox);
}
static void
-entry_text_changed_cb (GtkEditable *entry,
- NautilusFileConflictDialog *dialog)
+entry_text_changed_cb (GtkEditable *entry,
+ NautilusFileConflictDialog *dialog)
{
- NautilusFileConflictDialogDetails *details;
-
- details = dialog->details;
-
- /* The rename button is visible only if there's text
- * in the entry.
- */
- if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (entry)), "") != 0 &&
- g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (entry)), details->conflict_name) != 0) {
- gtk_widget_hide (details->replace_button);
- gtk_widget_show (details->rename_button);
-
- gtk_widget_set_sensitive (details->checkbox, FALSE);
-
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- CONFLICT_RESPONSE_RENAME);
- } else {
- gtk_widget_hide (details->rename_button);
- gtk_widget_show (details->replace_button);
-
- gtk_widget_set_sensitive (details->checkbox, TRUE);
-
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- CONFLICT_RESPONSE_REPLACE);
- }
+ NautilusFileConflictDialogDetails *details;
+
+ details = dialog->details;
+
+ /* The rename button is visible only if there's text
+ * in the entry.
+ */
+ if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (entry)), "") != 0 &&
+ g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (entry)), details->conflict_name) != 0)
+ {
+ gtk_widget_hide (details->replace_button);
+ gtk_widget_show (details->rename_button);
+
+ gtk_widget_set_sensitive (details->checkbox, FALSE);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ CONFLICT_RESPONSE_RENAME);
+ }
+ else
+ {
+ gtk_widget_hide (details->rename_button);
+ gtk_widget_show (details->replace_button);
+
+ gtk_widget_set_sensitive (details->checkbox, TRUE);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ CONFLICT_RESPONSE_REPLACE);
+ }
}
static void
-expander_activated_cb (GtkExpander *w,
- NautilusFileConflictDialog *dialog)
+expander_activated_cb (GtkExpander *w,
+ NautilusFileConflictDialog *dialog)
{
- NautilusFileConflictDialogDetails *details;
- int start_pos, end_pos;
-
- details = dialog->details;
-
- if (!gtk_expander_get_expanded (w)) {
- if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (details->entry)),
- details->conflict_name) == 0) {
- gtk_widget_grab_focus (details->entry);
-
- eel_filename_get_rename_region (details->conflict_name,
- &start_pos, &end_pos);
- gtk_editable_select_region (GTK_EDITABLE (details->entry),
- start_pos, end_pos);
- }
- }
+ NautilusFileConflictDialogDetails *details;
+ int start_pos, end_pos;
+
+ details = dialog->details;
+
+ if (!gtk_expander_get_expanded (w))
+ {
+ if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (details->entry)),
+ details->conflict_name) == 0)
+ {
+ gtk_widget_grab_focus (details->entry);
+
+ eel_filename_get_rename_region (details->conflict_name,
+ &start_pos, &end_pos);
+ gtk_editable_select_region (GTK_EDITABLE (details->entry),
+ start_pos, end_pos);
+ }
+ }
}
static void
-checkbox_toggled_cb (GtkToggleButton *t,
- NautilusFileConflictDialog *dialog)
+checkbox_toggled_cb (GtkToggleButton *t,
+ NautilusFileConflictDialog *dialog)
{
- NautilusFileConflictDialogDetails *details;
-
- details = dialog->details;
-
- gtk_widget_set_sensitive (details->expander,
- !gtk_toggle_button_get_active (t));
- gtk_widget_set_sensitive (details->rename_button,
- !gtk_toggle_button_get_active (t));
-
- if (!gtk_toggle_button_get_active (t) &&
- g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (details->entry)),
- "") != 0 &&
- g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (details->entry)),
- details->conflict_name) != 0) {
- gtk_widget_hide (details->replace_button);
- gtk_widget_show (details->rename_button);
- } else {
- gtk_widget_hide (details->rename_button);
- gtk_widget_show (details->replace_button);
- }
+ NautilusFileConflictDialogDetails *details;
+
+ details = dialog->details;
+
+ gtk_widget_set_sensitive (details->expander,
+ !gtk_toggle_button_get_active (t));
+ gtk_widget_set_sensitive (details->rename_button,
+ !gtk_toggle_button_get_active (t));
+
+ if (!gtk_toggle_button_get_active (t) &&
+ g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (details->entry)),
+ "") != 0 &&
+ g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (details->entry)),
+ details->conflict_name) != 0)
+ {
+ gtk_widget_hide (details->replace_button);
+ gtk_widget_show (details->rename_button);
+ }
+ else
+ {
+ gtk_widget_hide (details->rename_button);
+ gtk_widget_show (details->replace_button);
+ }
}
static void
-reset_button_clicked_cb (GtkButton *w,
- NautilusFileConflictDialog *dialog)
+reset_button_clicked_cb (GtkButton *w,
+ NautilusFileConflictDialog *dialog)
{
- NautilusFileConflictDialogDetails *details;
- int start_pos, end_pos;
-
- details = dialog->details;
-
- gtk_entry_set_text (GTK_ENTRY (details->entry),
- details->conflict_name);
- gtk_widget_grab_focus (details->entry);
- eel_filename_get_rename_region (details->conflict_name,
- &start_pos, &end_pos);
- gtk_editable_select_region (GTK_EDITABLE (details->entry),
- start_pos, end_pos);
-
+ NautilusFileConflictDialogDetails *details;
+ int start_pos, end_pos;
+
+ details = dialog->details;
+
+ gtk_entry_set_text (GTK_ENTRY (details->entry),
+ details->conflict_name);
+ gtk_widget_grab_focus (details->entry);
+ eel_filename_get_rename_region (details->conflict_name,
+ &start_pos, &end_pos);
+ gtk_editable_select_region (GTK_EDITABLE (details->entry),
+ start_pos, end_pos);
}
static void
nautilus_file_conflict_dialog_init (NautilusFileConflictDialog *fcd)
{
- GtkWidget *hbox, *vbox, *vbox2;
- GtkWidget *widget, *dialog_area;
- NautilusFileConflictDialogDetails *details;
- GtkDialog *dialog;
-
- details = fcd->details = NAUTILUS_FILE_CONFLICT_DIALOG_GET_PRIVATE (fcd);
- dialog = GTK_DIALOG (fcd);
-
- /* Setup the main hbox */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- dialog_area = gtk_dialog_get_content_area (dialog);
- gtk_box_pack_start (GTK_BOX (dialog_area), hbox, FALSE, FALSE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
-
- /* Setup the dialog image */
- widget = gtk_image_new_from_icon_name ("dialog-warning",
- GTK_ICON_SIZE_DIALOG);
- gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
- gtk_widget_set_valign (widget, GTK_ALIGN_START);
-
- /* Setup the vbox containing the dialog body */
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
-
- /* Setup the vbox for the dialog labels */
- widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
- details->titles_vbox = widget;
-
- /* Setup the hboxes to pack file infos into */
- vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_widget_set_halign (vbox2, GTK_ALIGN_START);
- gtk_widget_set_margin_start (vbox2, 12);
- gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
- details->first_hbox = hbox;
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
- gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
- details->second_hbox = hbox;
-
- /* Setup the expander for the rename action */
- details->expander = gtk_expander_new_with_mnemonic (_("_Select a new name for the destination"));
- gtk_box_pack_start (GTK_BOX (vbox2), details->expander, FALSE, FALSE, 0);
- g_signal_connect (details->expander, "activate",
- G_CALLBACK (expander_activated_cb), dialog);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_container_add (GTK_CONTAINER (details->expander), hbox);
-
- widget = gtk_entry_new ();
- gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 6);
- details->entry = widget;
- g_signal_connect (widget, "changed",
- G_CALLBACK (entry_text_changed_cb), dialog);
-
- widget = gtk_button_new_with_label (_("Reset"));
- gtk_button_set_image (GTK_BUTTON (widget),
- gtk_image_new_from_icon_name ("edit-undo",
- GTK_ICON_SIZE_MENU));
- gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 6);
- g_signal_connect (widget, "clicked",
- G_CALLBACK (reset_button_clicked_cb), dialog);
-
- gtk_widget_show_all (vbox2);
-
-
- /* Setup the checkbox to apply the action to all files */
- widget = gtk_check_button_new_with_mnemonic (_("Apply this action to all files and folders"));
-
- gtk_box_pack_start (GTK_BOX (vbox),
- widget, FALSE, FALSE, 0);
- details->checkbox = widget;
- g_signal_connect (widget, "toggled",
- G_CALLBACK (checkbox_toggled_cb), dialog);
-
- /* Add buttons */
+ GtkWidget *hbox, *vbox, *vbox2;
+ GtkWidget *widget, *dialog_area;
+ NautilusFileConflictDialogDetails *details;
+ GtkDialog *dialog;
+
+ details = fcd->details = NAUTILUS_FILE_CONFLICT_DIALOG_GET_PRIVATE (fcd);
+ dialog = GTK_DIALOG (fcd);
+
+ /* Setup the main hbox */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ dialog_area = gtk_dialog_get_content_area (dialog);
+ gtk_box_pack_start (GTK_BOX (dialog_area), hbox, FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
+
+ /* Setup the dialog image */
+ widget = gtk_image_new_from_icon_name ("dialog-warning",
+ GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
+ gtk_widget_set_valign (widget, GTK_ALIGN_START);
+
+ /* Setup the vbox containing the dialog body */
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
+
+ /* Setup the vbox for the dialog labels */
+ widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
+ details->titles_vbox = widget;
+
+ /* Setup the hboxes to pack file infos into */
+ vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_widget_set_halign (vbox2, GTK_ALIGN_START);
+ gtk_widget_set_margin_start (vbox2, 12);
+ gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
+ details->first_hbox = hbox;
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
+ details->second_hbox = hbox;
+
+ /* Setup the expander for the rename action */
+ details->expander = gtk_expander_new_with_mnemonic (_("_Select a new name for the destination"));
+ gtk_box_pack_start (GTK_BOX (vbox2), details->expander, FALSE, FALSE, 0);
+ g_signal_connect (details->expander, "activate",
+ G_CALLBACK (expander_activated_cb), dialog);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_container_add (GTK_CONTAINER (details->expander), hbox);
+
+ widget = gtk_entry_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 6);
+ details->entry = widget;
+ g_signal_connect (widget, "changed",
+ G_CALLBACK (entry_text_changed_cb), dialog);
+
+ widget = gtk_button_new_with_label (_("Reset"));
+ gtk_button_set_image (GTK_BUTTON (widget),
+ gtk_image_new_from_icon_name ("edit-undo",
+ GTK_ICON_SIZE_MENU));
+ gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 6);
+ g_signal_connect (widget, "clicked",
+ G_CALLBACK (reset_button_clicked_cb), dialog);
+
+ gtk_widget_show_all (vbox2);
+
+
+ /* Setup the checkbox to apply the action to all files */
+ widget = gtk_check_button_new_with_mnemonic (_("Apply this action to all files and folders"));
+
+ gtk_box_pack_start (GTK_BOX (vbox),
+ widget, FALSE, FALSE, 0);
+ details->checkbox = widget;
+ g_signal_connect (widget, "toggled",
+ G_CALLBACK (checkbox_toggled_cb), dialog);
+
+ /* Add buttons */
+ gtk_dialog_add_button (dialog,
+ _("_Cancel"),
+ GTK_RESPONSE_CANCEL);
+
+ details->skip_button =
gtk_dialog_add_button (dialog,
- _("_Cancel"),
- GTK_RESPONSE_CANCEL);
-
- details->skip_button =
- gtk_dialog_add_button (dialog,
- _("_Skip"),
- CONFLICT_RESPONSE_SKIP);
-
- details->rename_button =
- gtk_dialog_add_button (dialog,
- _("Re_name"),
- CONFLICT_RESPONSE_RENAME);
- gtk_widget_hide (details->rename_button);
-
- details->replace_button =
- gtk_dialog_add_button (dialog,
- _("Replace"),
- CONFLICT_RESPONSE_REPLACE);
- gtk_widget_grab_focus (details->replace_button);
-
- /* Setup HIG properties */
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (dialog)), 14);
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
- gtk_widget_show_all (dialog_area);
+ _("_Skip"),
+ CONFLICT_RESPONSE_SKIP);
+
+ details->rename_button =
+ gtk_dialog_add_button (dialog,
+ _("Re_name"),
+ CONFLICT_RESPONSE_RENAME);
+ gtk_widget_hide (details->rename_button);
+
+ details->replace_button =
+ gtk_dialog_add_button (dialog,
+ _("Replace"),
+ CONFLICT_RESPONSE_REPLACE);
+ gtk_widget_grab_focus (details->replace_button);
+
+ /* Setup HIG properties */
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (dialog)), 14);
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+ gtk_widget_show_all (dialog_area);
}
static void
do_finalize (GObject *self)
{
- NautilusFileConflictDialogDetails *details =
- NAUTILUS_FILE_CONFLICT_DIALOG (self)->details;
+ NautilusFileConflictDialogDetails *details =
+ NAUTILUS_FILE_CONFLICT_DIALOG (self)->details;
- g_free (details->conflict_name);
+ g_free (details->conflict_name);
- G_OBJECT_CLASS (nautilus_file_conflict_dialog_parent_class)->finalize (self);
+ G_OBJECT_CLASS (nautilus_file_conflict_dialog_parent_class)->finalize (self);
}
static void
nautilus_file_conflict_dialog_class_init (NautilusFileConflictDialogClass *klass)
{
- G_OBJECT_CLASS (klass)->finalize = do_finalize;
+ G_OBJECT_CLASS (klass)->finalize = do_finalize;
- g_type_class_add_private (klass, sizeof (NautilusFileConflictDialogDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileConflictDialogDetails));
}
char *
nautilus_file_conflict_dialog_get_new_name (NautilusFileConflictDialog *dialog)
{
- return g_strdup (gtk_entry_get_text
- (GTK_ENTRY (dialog->details->entry)));
+ return g_strdup (gtk_entry_get_text
+ (GTK_ENTRY (dialog->details->entry)));
}
gboolean
nautilus_file_conflict_dialog_get_apply_to_all (NautilusFileConflictDialog *dialog)
{
- return gtk_toggle_button_get_active
- (GTK_TOGGLE_BUTTON (dialog->details->checkbox));
+ return gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (dialog->details->checkbox));
}
NautilusFileConflictDialog *
nautilus_file_conflict_dialog_new (GtkWindow *parent)
{
- NautilusFileConflictDialog *dialog;
+ NautilusFileConflictDialog *dialog;
- dialog = NAUTILUS_FILE_CONFLICT_DIALOG (g_object_new (NAUTILUS_TYPE_FILE_CONFLICT_DIALOG,
- "use-header-bar", TRUE,
- "modal", TRUE,
- NULL));
+ dialog = NAUTILUS_FILE_CONFLICT_DIALOG (g_object_new (NAUTILUS_TYPE_FILE_CONFLICT_DIALOG,
+ "use-header-bar", TRUE,
+ "modal", TRUE,
+ NULL));
- gtk_window_set_transient_for (GTK_WINDOW (dialog),
- parent);
+ gtk_window_set_transient_for (GTK_WINDOW (dialog),
+ parent);
- return dialog;
+ return dialog;
}
diff --git a/src/nautilus-file-name-widget-controller.c b/src/nautilus-file-name-widget-controller.c
index 0eb474528..7b2f21d3f 100644
--- a/src/nautilus-file-name-widget-controller.c
+++ b/src/nautilus-file-name-widget-controller.c
@@ -5,30 +5,33 @@
#define FILE_NAME_DUPLICATED_LABEL_TIMEOUT 500
-typedef struct {
- GtkWidget *error_revealer;
- GtkWidget *error_label;
- GtkWidget *name_entry;
- GtkWidget *activate_button;
- NautilusDirectory *containing_directory;
-
- gboolean duplicated_is_folder;
- gint duplicated_label_timeout_id;
+typedef struct
+{
+ GtkWidget *error_revealer;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
+ NautilusDirectory *containing_directory;
+
+ gboolean duplicated_is_folder;
+ gint duplicated_label_timeout_id;
} NautilusFileNameWidgetControllerPrivate;
-enum {
- NAME_ACCEPTED,
- CANCELLED,
- LAST_SIGNAL
+enum
+{
+ NAME_ACCEPTED,
+ CANCELLED,
+ LAST_SIGNAL
};
-enum {
- PROP_ERROR_REVEALER = 1,
- PROP_ERROR_LABEL,
- PROP_NAME_ENTRY,
- PROP_ACTION_BUTTON,
- PROP_CONTAINING_DIRECTORY,
- NUM_PROPERTIES
+enum
+{
+ PROP_ERROR_REVEALER = 1,
+ PROP_ERROR_LABEL,
+ PROP_NAME_ENTRY,
+ PROP_ACTION_BUTTON,
+ PROP_CONTAINING_DIRECTORY,
+ NUM_PROPERTIES
};
static guint signals[LAST_SIGNAL];
@@ -38,7 +41,7 @@ G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (NautilusFileNameWidgetController, nautilus_
gchar *
nautilus_file_name_widget_controller_get_new_name (NautilusFileNameWidgetController *self)
{
- return NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_GET_CLASS (self)->get_new_name (self);
+ return NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_GET_CLASS (self)->get_new_name (self);
}
static gboolean
@@ -46,27 +49,27 @@ nautilus_file_name_widget_controller_name_is_valid (NautilusFileNameWidgetContro
gchar *name,
gchar **error_message)
{
- return NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_GET_CLASS (self)->name_is_valid (self,
- name,
- error_message);
+ return NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_GET_CLASS (self)->name_is_valid (self,
+ name,
+ error_message);
}
static gboolean
nautilus_file_name_widget_controller_ignore_existing_file (NautilusFileNameWidgetController *self,
NautilusFile *existing_file)
{
- return NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_GET_CLASS (self)->ignore_existing_file (self,
- existing_file);
+ return NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_GET_CLASS (self)->ignore_existing_file (self,
+ existing_file);
}
static gchar *
real_get_new_name (NautilusFileNameWidgetController *self)
{
- NautilusFileNameWidgetControllerPrivate *priv;
+ NautilusFileNameWidgetControllerPrivate *priv;
- priv = nautilus_file_name_widget_controller_get_instance_private (self);
+ priv = nautilus_file_name_widget_controller_get_instance_private (self);
- return g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->name_entry))));
+ return g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->name_entry))));
}
static gboolean
@@ -74,48 +77,57 @@ real_name_is_valid (NautilusFileNameWidgetController *self,
gchar *name,
gchar **error_message)
{
- if (strlen (name) == 0) {
- return FALSE;
- }
-
- if (strstr (name, "/") != NULL) {
- *error_message = _("File names cannot contain “/”.");
- } else if (strcmp (name, ".") == 0){
- *error_message = _("A file cannot be called “.”.");
- } else if (strcmp (name, "..") == 0){
- *error_message = _("A file cannot be called “..”.");
- }
-
- return *error_message == NULL;
+ if (strlen (name) == 0)
+ {
+ return FALSE;
+ }
+
+ if (strstr (name, "/") != NULL)
+ {
+ *error_message = _("File names cannot contain “/”.");
+ }
+ else if (strcmp (name, ".") == 0)
+ {
+ *error_message = _("A file cannot be called “.”.");
+ }
+ else if (strcmp (name, "..") == 0)
+ {
+ *error_message = _("A file cannot be called “..”.");
+ }
+
+ return *error_message == NULL;
}
static gboolean
real_ignore_existing_file (NautilusFileNameWidgetController *self,
NautilusFile *existing_file)
{
- return FALSE;
+ return FALSE;
}
static gboolean
duplicated_file_label_show (NautilusFileNameWidgetController *self)
{
- NautilusFileNameWidgetControllerPrivate *priv;
-
- priv = nautilus_file_name_widget_controller_get_instance_private (self);
- if (priv->duplicated_is_folder) {
- gtk_label_set_label (GTK_LABEL (priv->error_label),
- _("A folder with that name already exists."));
- } else {
- gtk_label_set_label (GTK_LABEL (priv->error_label),
- _("A file with that name already exists."));
- }
-
- gtk_revealer_set_reveal_child (GTK_REVEALER (priv->error_revealer),
- TRUE);
-
- priv->duplicated_label_timeout_id = 0;
-
- return G_SOURCE_REMOVE;
+ NautilusFileNameWidgetControllerPrivate *priv;
+
+ priv = nautilus_file_name_widget_controller_get_instance_private (self);
+ if (priv->duplicated_is_folder)
+ {
+ gtk_label_set_label (GTK_LABEL (priv->error_label),
+ _("A folder with that name already exists."));
+ }
+ else
+ {
+ gtk_label_set_label (GTK_LABEL (priv->error_label),
+ _("A file with that name already exists."));
+ }
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->error_revealer),
+ TRUE);
+
+ priv->duplicated_label_timeout_id = 0;
+
+ return G_SOURCE_REMOVE;
}
static void
@@ -123,40 +135,43 @@ file_name_widget_controller_process_new_name (NautilusFileNameWidgetController *
gboolean *duplicated_name,
gboolean *valid_name)
{
- NautilusFileNameWidgetControllerPrivate *priv;
- g_autofree gchar *name;
- gchar *error_message = NULL;
- NautilusFile *existing_file;
- priv = nautilus_file_name_widget_controller_get_instance_private (controller);
-
- name = nautilus_file_name_widget_controller_get_new_name (controller);
- *valid_name = nautilus_file_name_widget_controller_name_is_valid (controller,
- name,
- &error_message);
-
- gtk_label_set_label (GTK_LABEL (priv->error_label), error_message);
- gtk_revealer_set_reveal_child (GTK_REVEALER (priv->error_revealer),
- error_message != NULL);
-
- existing_file = nautilus_directory_get_file_by_name (priv->containing_directory, name);
- *duplicated_name = existing_file != NULL &&
- !nautilus_file_name_widget_controller_ignore_existing_file (controller,
- existing_file);
-
- gtk_widget_set_sensitive (priv->activate_button, *valid_name && !*duplicated_name);
-
- if (priv->duplicated_label_timeout_id != 0) {
- g_source_remove (priv->duplicated_label_timeout_id);
- priv->duplicated_label_timeout_id = 0;
- }
+ NautilusFileNameWidgetControllerPrivate *priv;
+ g_autofree gchar *name;
+ gchar *error_message = NULL;
+ NautilusFile *existing_file;
+ priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+
+ name = nautilus_file_name_widget_controller_get_new_name (controller);
+ *valid_name = nautilus_file_name_widget_controller_name_is_valid (controller,
+ name,
+ &error_message);
+
+ gtk_label_set_label (GTK_LABEL (priv->error_label), error_message);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (priv->error_revealer),
+ error_message != NULL);
+
+ existing_file = nautilus_directory_get_file_by_name (priv->containing_directory, name);
+ *duplicated_name = existing_file != NULL &&
+ !nautilus_file_name_widget_controller_ignore_existing_file (controller,
+ existing_file);
+
+ gtk_widget_set_sensitive (priv->activate_button, *valid_name && !*duplicated_name);
+
+ if (priv->duplicated_label_timeout_id != 0)
+ {
+ g_source_remove (priv->duplicated_label_timeout_id);
+ priv->duplicated_label_timeout_id = 0;
+ }
- if (*duplicated_name) {
- priv->duplicated_is_folder = nautilus_file_is_directory (existing_file);
- }
+ if (*duplicated_name)
+ {
+ priv->duplicated_is_folder = nautilus_file_is_directory (existing_file);
+ }
- if (existing_file != NULL) {
- nautilus_file_unref (existing_file);
- }
+ if (existing_file != NULL)
+ {
+ nautilus_file_unref (existing_file);
+ }
}
static void
@@ -164,43 +179,44 @@ file_name_widget_controller_on_changed_directory_info_ready (NautilusDirectory *
GList *files,
gpointer user_data)
{
- NautilusFileNameWidgetController *controller;
- NautilusFileNameWidgetControllerPrivate *priv;
- gboolean duplicated_name;
- gboolean valid_name;
-
- controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
- priv = nautilus_file_name_widget_controller_get_instance_private (controller);
-
- file_name_widget_controller_process_new_name (controller,
- &duplicated_name,
- &valid_name);
-
- /* Report duplicated file only if not other message shown (for instance,
- * folders like "." or ".." will always exists, but we consider it as an
- * error, not as a duplicated file or if the name is the same as the file
- * we are renaming also don't report as a duplicated */
- if (duplicated_name && valid_name) {
- priv->duplicated_label_timeout_id = g_timeout_add (FILE_NAME_DUPLICATED_LABEL_TIMEOUT,
- (GSourceFunc)duplicated_file_label_show,
- controller);
- }
+ NautilusFileNameWidgetController *controller;
+ NautilusFileNameWidgetControllerPrivate *priv;
+ gboolean duplicated_name;
+ gboolean valid_name;
+
+ controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
+ priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+
+ file_name_widget_controller_process_new_name (controller,
+ &duplicated_name,
+ &valid_name);
+
+ /* Report duplicated file only if not other message shown (for instance,
+ * folders like "." or ".." will always exists, but we consider it as an
+ * error, not as a duplicated file or if the name is the same as the file
+ * we are renaming also don't report as a duplicated */
+ if (duplicated_name && valid_name)
+ {
+ priv->duplicated_label_timeout_id = g_timeout_add (FILE_NAME_DUPLICATED_LABEL_TIMEOUT,
+ (GSourceFunc) duplicated_file_label_show,
+ controller);
+ }
}
static void
file_name_widget_controller_on_changed (gpointer user_data)
{
- NautilusFileNameWidgetController *controller;
- NautilusFileNameWidgetControllerPrivate *priv;
+ NautilusFileNameWidgetController *controller;
+ NautilusFileNameWidgetControllerPrivate *priv;
- controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
- priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+ controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
+ priv = nautilus_file_name_widget_controller_get_instance_private (controller);
- nautilus_directory_call_when_ready (priv->containing_directory,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- TRUE,
- file_name_widget_controller_on_changed_directory_info_ready,
- controller);
+ nautilus_directory_call_when_ready (priv->containing_directory,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ TRUE,
+ file_name_widget_controller_on_changed_directory_info_ready,
+ controller);
}
static void
@@ -208,49 +224,52 @@ file_name_widget_controller_on_activate_directory_info_ready (NautilusDirectory
GList *files,
gpointer user_data)
{
- NautilusFileNameWidgetController *controller;
- gboolean duplicated_name;
- gboolean valid_name;
-
- controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
-
- file_name_widget_controller_process_new_name (controller,
- &duplicated_name,
- &valid_name);
-
- if (valid_name && !duplicated_name) {
- g_signal_emit (controller, signals[NAME_ACCEPTED], 0);
- } else {
- /* Report duplicated file only if not other message shown (for instance,
- * folders like "." or ".." will always exists, but we consider it as an
- * error, not as a duplicated file) */
- if (duplicated_name && valid_name) {
- /* Show it inmediatily since the user tried to trigger the action */
- duplicated_file_label_show (controller);
- }
+ NautilusFileNameWidgetController *controller;
+ gboolean duplicated_name;
+ gboolean valid_name;
+
+ controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
+
+ file_name_widget_controller_process_new_name (controller,
+ &duplicated_name,
+ &valid_name);
+
+ if (valid_name && !duplicated_name)
+ {
+ g_signal_emit (controller, signals[NAME_ACCEPTED], 0);
+ }
+ else
+ {
+ /* Report duplicated file only if not other message shown (for instance,
+ * folders like "." or ".." will always exists, but we consider it as an
+ * error, not as a duplicated file) */
+ if (duplicated_name && valid_name)
+ {
+ /* Show it inmediatily since the user tried to trigger the action */
+ duplicated_file_label_show (controller);
}
+ }
}
static void
file_name_widget_controller_on_activate (gpointer user_data)
{
- NautilusFileNameWidgetController *controller;
- NautilusFileNameWidgetControllerPrivate *priv;
+ NautilusFileNameWidgetController *controller;
+ NautilusFileNameWidgetControllerPrivate *priv;
- controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
- priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+ controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (user_data);
+ priv = nautilus_file_name_widget_controller_get_instance_private (controller);
- nautilus_directory_call_when_ready (priv->containing_directory,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- TRUE,
- file_name_widget_controller_on_activate_directory_info_ready,
- controller);
+ nautilus_directory_call_when_ready (priv->containing_directory,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ TRUE,
+ file_name_widget_controller_on_activate_directory_info_ready,
+ controller);
}
static void
nautilus_file_name_widget_controller_init (NautilusFileNameWidgetController *self)
{
-
}
static void
@@ -259,149 +278,157 @@ nautilus_file_name_widget_controller_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- NautilusFileNameWidgetController *controller;
- NautilusFileNameWidgetControllerPrivate *priv;
-
- controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (object);
- priv = nautilus_file_name_widget_controller_get_instance_private (controller);
-
- switch (prop_id) {
- case PROP_ERROR_REVEALER:
- priv->error_revealer = GTK_WIDGET (g_value_get_object (value));
- break;
- case PROP_ERROR_LABEL:
- priv->error_label = GTK_WIDGET (g_value_get_object (value));
- break;
- case PROP_NAME_ENTRY:
- priv->name_entry = GTK_WIDGET (g_value_get_object (value));
-
- g_signal_connect_swapped (G_OBJECT (priv->name_entry),
- "activate",
- (GCallback)file_name_widget_controller_on_activate,
- controller);
- g_signal_connect_swapped (G_OBJECT (priv->name_entry),
- "changed",
- (GCallback)file_name_widget_controller_on_changed,
- controller);
- break;
- case PROP_ACTION_BUTTON:
- priv->activate_button = GTK_WIDGET (g_value_get_object (value));
-
- g_signal_connect_swapped (G_OBJECT (priv->activate_button),
- "clicked",
- (GCallback)file_name_widget_controller_on_activate,
- controller);
- break;
- case PROP_CONTAINING_DIRECTORY:
- priv->containing_directory = NAUTILUS_DIRECTORY (g_value_get_object (value));
- nautilus_directory_ref (priv->containing_directory);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ NautilusFileNameWidgetController *controller;
+ NautilusFileNameWidgetControllerPrivate *priv;
+
+ controller = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (object);
+ priv = nautilus_file_name_widget_controller_get_instance_private (controller);
+
+ switch (prop_id)
+ {
+ case PROP_ERROR_REVEALER:
+ priv->error_revealer = GTK_WIDGET (g_value_get_object (value));
+ break;
+
+ case PROP_ERROR_LABEL:
+ priv->error_label = GTK_WIDGET (g_value_get_object (value));
+ break;
+
+ case PROP_NAME_ENTRY:
+ priv->name_entry = GTK_WIDGET (g_value_get_object (value));
+
+ g_signal_connect_swapped (G_OBJECT (priv->name_entry),
+ "activate",
+ (GCallback) file_name_widget_controller_on_activate,
+ controller);
+ g_signal_connect_swapped (G_OBJECT (priv->name_entry),
+ "changed",
+ (GCallback) file_name_widget_controller_on_changed,
+ controller);
+ break;
+
+ case PROP_ACTION_BUTTON:
+ priv->activate_button = GTK_WIDGET (g_value_get_object (value));
+
+ g_signal_connect_swapped (G_OBJECT (priv->activate_button),
+ "clicked",
+ (GCallback) file_name_widget_controller_on_activate,
+ controller);
+ break;
+
+ case PROP_CONTAINING_DIRECTORY:
+ priv->containing_directory = NAUTILUS_DIRECTORY (g_value_get_object (value));
+ nautilus_directory_ref (priv->containing_directory);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
static void
nautilus_file_name_widget_controller_finalize (GObject *object)
{
- NautilusFileNameWidgetController *self;
- NautilusFileNameWidgetControllerPrivate *priv;
-
- self = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (object);
- priv = nautilus_file_name_widget_controller_get_instance_private (self);
-
- if (priv->containing_directory != NULL) {
- nautilus_directory_cancel_callback (priv->containing_directory,
- file_name_widget_controller_on_changed_directory_info_ready,
- self);
- nautilus_directory_cancel_callback (priv->containing_directory,
- file_name_widget_controller_on_activate_directory_info_ready,
- self);
- g_clear_object (&priv->containing_directory);
- }
+ NautilusFileNameWidgetController *self;
+ NautilusFileNameWidgetControllerPrivate *priv;
- if (priv->duplicated_label_timeout_id > 0) {
- g_source_remove (priv->duplicated_label_timeout_id);
- priv->duplicated_label_timeout_id = 0;
- }
+ self = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER (object);
+ priv = nautilus_file_name_widget_controller_get_instance_private (self);
+
+ if (priv->containing_directory != NULL)
+ {
+ nautilus_directory_cancel_callback (priv->containing_directory,
+ file_name_widget_controller_on_changed_directory_info_ready,
+ self);
+ nautilus_directory_cancel_callback (priv->containing_directory,
+ file_name_widget_controller_on_activate_directory_info_ready,
+ self);
+ g_clear_object (&priv->containing_directory);
+ }
- G_OBJECT_CLASS (nautilus_file_name_widget_controller_parent_class)->finalize (object);
+ if (priv->duplicated_label_timeout_id > 0)
+ {
+ g_source_remove (priv->duplicated_label_timeout_id);
+ priv->duplicated_label_timeout_id = 0;
+ }
+
+ G_OBJECT_CLASS (nautilus_file_name_widget_controller_parent_class)->finalize (object);
}
static void
nautilus_file_name_widget_controller_class_init (NautilusFileNameWidgetControllerClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->set_property = nautilus_file_name_widget_controller_set_property;
- object_class->finalize = nautilus_file_name_widget_controller_finalize;
-
- klass->get_new_name = real_get_new_name;
- klass->name_is_valid = real_name_is_valid;
- klass->ignore_existing_file = real_ignore_existing_file;
-
- signals[NAME_ACCEPTED] =
- g_signal_new ("name-accepted",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NautilusFileNameWidgetControllerClass, name_accepted),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 0);
- signals[CANCELLED] =
- g_signal_new ("cancelled",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 0);
-
- g_object_class_install_property (
- object_class,
- PROP_ERROR_REVEALER,
- g_param_spec_object ("error-revealer",
- "Error Revealer",
- "The error label revealer",
- GTK_TYPE_WIDGET,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (
- object_class,
- PROP_ERROR_LABEL,
- g_param_spec_object ("error-label",
- "Error Label",
- "The label used for displaying errors",
- GTK_TYPE_WIDGET,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class,
- PROP_NAME_ENTRY,
- g_param_spec_object ("name-entry",
- "Name Entry",
- "The entry for the file name",
- GTK_TYPE_WIDGET,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class,
- PROP_ACTION_BUTTON,
- g_param_spec_object ("activate-button",
- "Activate Button",
- "The activate button of the widget",
- GTK_TYPE_WIDGET,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- object_class,
- PROP_CONTAINING_DIRECTORY,
- g_param_spec_object ("containing-directory",
- "Containing Directory",
- "The directory used to check for duplicate names",
- NAUTILUS_TYPE_DIRECTORY,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->set_property = nautilus_file_name_widget_controller_set_property;
+ object_class->finalize = nautilus_file_name_widget_controller_finalize;
+
+ klass->get_new_name = real_get_new_name;
+ klass->name_is_valid = real_name_is_valid;
+ klass->ignore_existing_file = real_ignore_existing_file;
+
+ signals[NAME_ACCEPTED] =
+ g_signal_new ("name-accepted",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NautilusFileNameWidgetControllerClass, name_accepted),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 0);
+ signals[CANCELLED] =
+ g_signal_new ("cancelled",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 0);
+
+ g_object_class_install_property (
+ object_class,
+ PROP_ERROR_REVEALER,
+ g_param_spec_object ("error-revealer",
+ "Error Revealer",
+ "The error label revealer",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (
+ object_class,
+ PROP_ERROR_LABEL,
+ g_param_spec_object ("error-label",
+ "Error Label",
+ "The label used for displaying errors",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (
+ object_class,
+ PROP_NAME_ENTRY,
+ g_param_spec_object ("name-entry",
+ "Name Entry",
+ "The entry for the file name",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (
+ object_class,
+ PROP_ACTION_BUTTON,
+ g_param_spec_object ("activate-button",
+ "Activate Button",
+ "The activate button of the widget",
+ GTK_TYPE_WIDGET,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (
+ object_class,
+ PROP_CONTAINING_DIRECTORY,
+ g_param_spec_object ("containing-directory",
+ "Containing Directory",
+ "The directory used to check for duplicate names",
+ NAUTILUS_TYPE_DIRECTORY,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
}
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index 24124daff..48847a5ee 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -1,26 +1,25 @@
-
/* nautilus-file-operations.c - Nautilus file operations.
-
- Copyright (C) 1999, 2000 Free Software Foundation
- Copyright (C) 2000, 2001 Eazel, Inc.
- Copyright (C) 2007 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Authors: Alexander Larsson <alexl@redhat.com>
- Ettore Perazzoli <ettore@gnu.org>
- Pavel Cisler <pavel@eazel.com>
+ *
+ * Copyright (C) 1999, 2000 Free Software Foundation
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ * Copyright (C) 2007 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Alexander Larsson <alexl@redhat.com>
+ * Ettore Perazzoli <ettore@gnu.org>
+ * Pavel Cisler <pavel@eazel.com>
*/
#include <config.h>
@@ -64,143 +63,155 @@
/* TODO: TESTING!!! */
-typedef struct {
- GTimer *time;
- GtkWindow *parent_window;
- int screen_num;
- guint inhibit_cookie;
- NautilusProgressInfo *progress;
- GCancellable *cancellable;
- GHashTable *skip_files;
- GHashTable *skip_readdir_error;
- NautilusFileUndoInfo *undo_info;
- gboolean skip_all_error;
- gboolean skip_all_conflict;
- gboolean merge_all;
- gboolean replace_all;
- gboolean delete_all;
+typedef struct
+{
+ GTimer *time;
+ GtkWindow *parent_window;
+ int screen_num;
+ guint inhibit_cookie;
+ NautilusProgressInfo *progress;
+ GCancellable *cancellable;
+ GHashTable *skip_files;
+ GHashTable *skip_readdir_error;
+ NautilusFileUndoInfo *undo_info;
+ gboolean skip_all_error;
+ gboolean skip_all_conflict;
+ gboolean merge_all;
+ gboolean replace_all;
+ gboolean delete_all;
} CommonJob;
-typedef struct {
- CommonJob common;
- gboolean is_move;
- GList *files;
- GFile *destination;
- GFile *desktop_location;
- GFile *fake_display_source;
- GdkPoint *icon_positions;
- int n_icon_positions;
- GHashTable *debuting_files;
- gchar *target_name;
- NautilusCopyCallback done_callback;
- gpointer done_callback_data;
+typedef struct
+{
+ CommonJob common;
+ gboolean is_move;
+ GList *files;
+ GFile *destination;
+ GFile *desktop_location;
+ GFile *fake_display_source;
+ GdkPoint *icon_positions;
+ int n_icon_positions;
+ GHashTable *debuting_files;
+ gchar *target_name;
+ NautilusCopyCallback done_callback;
+ gpointer done_callback_data;
} CopyMoveJob;
-typedef struct {
- CommonJob common;
- GList *files;
- gboolean try_trash;
- gboolean user_cancel;
- NautilusDeleteCallback done_callback;
- gpointer done_callback_data;
+typedef struct
+{
+ CommonJob common;
+ GList *files;
+ gboolean try_trash;
+ gboolean user_cancel;
+ NautilusDeleteCallback done_callback;
+ gpointer done_callback_data;
} DeleteJob;
-typedef struct {
- CommonJob common;
- GFile *dest_dir;
- char *filename;
- gboolean make_dir;
- GFile *src;
- char *src_data;
- int length;
- GdkPoint position;
- gboolean has_position;
- GFile *created_file;
- NautilusCreateCallback done_callback;
- gpointer done_callback_data;
+typedef struct
+{
+ CommonJob common;
+ GFile *dest_dir;
+ char *filename;
+ gboolean make_dir;
+ GFile *src;
+ char *src_data;
+ int length;
+ GdkPoint position;
+ gboolean has_position;
+ GFile *created_file;
+ NautilusCreateCallback done_callback;
+ gpointer done_callback_data;
} CreateJob;
-typedef struct {
- CommonJob common;
- GList *trash_dirs;
- gboolean should_confirm;
- NautilusOpCallback done_callback;
- gpointer done_callback_data;
+typedef struct
+{
+ CommonJob common;
+ GList *trash_dirs;
+ gboolean should_confirm;
+ NautilusOpCallback done_callback;
+ gpointer done_callback_data;
} EmptyTrashJob;
-typedef struct {
- CommonJob common;
- GFile *file;
- gboolean interactive;
- NautilusOpCallback done_callback;
- gpointer done_callback_data;
+typedef struct
+{
+ CommonJob common;
+ GFile *file;
+ gboolean interactive;
+ NautilusOpCallback done_callback;
+ gpointer done_callback_data;
} MarkTrustedJob;
-typedef struct {
- CommonJob common;
- GFile *file;
- NautilusOpCallback done_callback;
- gpointer done_callback_data;
- guint32 file_permissions;
- guint32 file_mask;
- guint32 dir_permissions;
- guint32 dir_mask;
+typedef struct
+{
+ CommonJob common;
+ GFile *file;
+ NautilusOpCallback done_callback;
+ gpointer done_callback_data;
+ guint32 file_permissions;
+ guint32 file_mask;
+ guint32 dir_permissions;
+ guint32 dir_mask;
} SetPermissionsJob;
-typedef enum {
- OP_KIND_COPY,
- OP_KIND_MOVE,
- OP_KIND_DELETE,
- OP_KIND_TRASH,
- OP_KIND_COMPRESS
+typedef enum
+{
+ OP_KIND_COPY,
+ OP_KIND_MOVE,
+ OP_KIND_DELETE,
+ OP_KIND_TRASH,
+ OP_KIND_COMPRESS
} OpKind;
-typedef struct {
- int num_files;
- goffset num_bytes;
- int num_files_since_progress;
- OpKind op;
+typedef struct
+{
+ int num_files;
+ goffset num_bytes;
+ int num_files_since_progress;
+ OpKind op;
} SourceInfo;
-typedef struct {
- int num_files;
- goffset num_bytes;
- OpKind op;
- guint64 last_report_time;
- int last_reported_files_left;
+typedef struct
+{
+ int num_files;
+ goffset num_bytes;
+ OpKind op;
+ guint64 last_report_time;
+ int last_reported_files_left;
} TransferInfo;
-typedef struct {
- CommonJob common;
- GList *source_files;
- GFile *destination_directory;
- GList *output_files;
+typedef struct
+{
+ CommonJob common;
+ GList *source_files;
+ GFile *destination_directory;
+ GList *output_files;
- gdouble base_progress;
+ gdouble base_progress;
- guint64 archive_compressed_size;
- guint64 total_compressed_size;
+ guint64 archive_compressed_size;
+ guint64 total_compressed_size;
- NautilusExtractCallback done_callback;
- gpointer done_callback_data;
+ NautilusExtractCallback done_callback;
+ gpointer done_callback_data;
} ExtractJob;
-typedef struct {
- CommonJob common;
- GList *source_files;
- GFile *output_file;
+typedef struct
+{
+ CommonJob common;
+ GList *source_files;
+ GFile *output_file;
- AutoarFormat format;
- AutoarFilter filter;
+ AutoarFormat format;
+ AutoarFilter filter;
- guint64 total_size;
- guint total_files;
+ guint64 total_size;
+ guint total_files;
- gboolean success;
+ gboolean success;
- NautilusCreateCallback done_callback;
- gpointer done_callback_data;
+ NautilusCreateCallback done_callback;
+ gpointer done_callback_data;
} CompressJob;
#define SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE 8
@@ -224,39 +235,39 @@ typedef struct {
#define COPY_FORCE _("Copy _Anyway")
static void
-mark_desktop_file_trusted (CommonJob *common,
- GCancellable *cancellable,
- GFile *file,
- gboolean interactive);
+mark_desktop_file_trusted (CommonJob *common,
+ GCancellable *cancellable,
+ GFile *file,
+ gboolean interactive);
static gboolean
is_all_button_text (const char *button_text)
{
- g_assert (button_text != NULL);
+ g_assert (button_text != NULL);
- return !strcmp (button_text, SKIP_ALL) ||
- !strcmp (button_text, REPLACE_ALL) ||
- !strcmp (button_text, DELETE_ALL) ||
- !strcmp (button_text, MERGE_ALL);
+ return !strcmp (button_text, SKIP_ALL) ||
+ !strcmp (button_text, REPLACE_ALL) ||
+ !strcmp (button_text, DELETE_ALL) ||
+ !strcmp (button_text, MERGE_ALL);
}
-static void scan_sources (GList *files,
- SourceInfo *source_info,
- CommonJob *job,
- OpKind kind);
+static void scan_sources (GList *files,
+ SourceInfo *source_info,
+ CommonJob *job,
+ OpKind kind);
-static void empty_trash_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+static void empty_trash_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable);
-static void empty_trash_task_done (GObject *source_object,
+static void empty_trash_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data);
+ gpointer user_data);
-static char * query_fs_type (GFile *file,
- GCancellable *cancellable);
+static char *query_fs_type (GFile *file,
+ GCancellable *cancellable);
/* keep in time with format_time()
*
@@ -268,113 +279,128 @@ static char * query_fs_type (GFile *file,
static int
seconds_count_format_time_units (int seconds)
{
- int minutes;
- int hours;
+ int minutes;
+ int hours;
- if (seconds < 0) {
- /* Just to make sure... */
- seconds = 0;
- }
+ if (seconds < 0)
+ {
+ /* Just to make sure... */
+ seconds = 0;
+ }
- if (seconds < 60) {
- /* seconds */
- return seconds;
- }
+ if (seconds < 60)
+ {
+ /* seconds */
+ return seconds;
+ }
- if (seconds < 60*60) {
- /* minutes */
- minutes = seconds / 60;
- return minutes;
- }
+ if (seconds < 60 * 60)
+ {
+ /* minutes */
+ minutes = seconds / 60;
+ return minutes;
+ }
- hours = seconds / (60*60);
+ hours = seconds / (60 * 60);
- if (seconds < 60*60*4) {
- /* minutes + hours */
- minutes = (seconds - hours * 60 * 60) / 60;
- return minutes + hours;
- }
+ if (seconds < 60 * 60 * 4)
+ {
+ /* minutes + hours */
+ minutes = (seconds - hours * 60 * 60) / 60;
+ return minutes + hours;
+ }
- return hours;
+ return hours;
}
static char *
format_time (int seconds)
{
- int minutes;
- int hours;
- char *res;
-
- if (seconds < 0) {
- /* Just to make sure... */
- seconds = 0;
- }
-
- if (seconds < 60) {
- return g_strdup_printf (ngettext ("%'d second","%'d seconds", (int) seconds), (int) seconds);
- }
-
- if (seconds < 60*60) {
- minutes = seconds / 60;
- return g_strdup_printf (ngettext ("%'d minute", "%'d minutes", minutes), minutes);
- }
-
- hours = seconds / (60*60);
-
- if (seconds < 60*60*4) {
- char *h, *m;
-
- minutes = (seconds - hours * 60 * 60) / 60;
-
- h = g_strdup_printf (ngettext ("%'d hour", "%'d hours", hours), hours);
- m = g_strdup_printf (ngettext ("%'d minute", "%'d minutes", minutes), minutes);
- res = g_strconcat (h, ", ", m, NULL);
- g_free (h);
- g_free (m);
- return res;
- }
-
- return g_strdup_printf (ngettext ("approximately %'d hour",
- "approximately %'d hours",
- hours), hours);
+ int minutes;
+ int hours;
+ char *res;
+
+ if (seconds < 0)
+ {
+ /* Just to make sure... */
+ seconds = 0;
+ }
+
+ if (seconds < 60)
+ {
+ return g_strdup_printf (ngettext ("%'d second", "%'d seconds", (int) seconds), (int) seconds);
+ }
+
+ if (seconds < 60 * 60)
+ {
+ minutes = seconds / 60;
+ return g_strdup_printf (ngettext ("%'d minute", "%'d minutes", minutes), minutes);
+ }
+
+ hours = seconds / (60 * 60);
+
+ if (seconds < 60 * 60 * 4)
+ {
+ char *h, *m;
+
+ minutes = (seconds - hours * 60 * 60) / 60;
+
+ h = g_strdup_printf (ngettext ("%'d hour", "%'d hours", hours), hours);
+ m = g_strdup_printf (ngettext ("%'d minute", "%'d minutes", minutes), minutes);
+ res = g_strconcat (h, ", ", m, NULL);
+ g_free (h);
+ g_free (m);
+ return res;
+ }
+
+ return g_strdup_printf (ngettext ("approximately %'d hour",
+ "approximately %'d hours",
+ hours), hours);
}
static char *
-shorten_utf8_string (const char *base, int reduce_by_num_bytes)
-{
- int len;
- char *ret;
- const char *p;
-
- len = strlen (base);
- len -= reduce_by_num_bytes;
-
- if (len <= 0) {
- return NULL;
- }
-
- ret = g_new (char, len + 1);
-
- p = base;
- while (len) {
- char *next;
- next = g_utf8_next_char (p);
- if (next - p > len || *next == '\0') {
- break;
- }
-
- len -= next - p;
- p = next;
- }
-
- if (p - base == 0) {
- g_free (ret);
- return NULL;
- } else {
- memcpy (ret, base, p - base);
- ret[p - base] = '\0';
- return ret;
- }
+shorten_utf8_string (const char *base,
+ int reduce_by_num_bytes)
+{
+ int len;
+ char *ret;
+ const char *p;
+
+ len = strlen (base);
+ len -= reduce_by_num_bytes;
+
+ if (len <= 0)
+ {
+ return NULL;
+ }
+
+ ret = g_new (char, len + 1);
+
+ p = base;
+ while (len)
+ {
+ char *next;
+ next = g_utf8_next_char (p);
+ if (next - p > len || *next == '\0')
+ {
+ break;
+ }
+
+ len -= next - p;
+ p = next;
+ }
+
+ if (p - base == 0)
+ {
+ g_free (ret);
+ return NULL;
+ }
+ else
+ {
+ memcpy (ret, base, p - base);
+ ret[p - base] = '\0';
+ return ret;
+ }
}
/* Note that we have these two separate functions with separate format
@@ -382,102 +408,142 @@ shorten_utf8_string (const char *base, int reduce_by_num_bytes)
*/
static char *
-get_link_name (const char *name, int count, int max_length)
-{
- const char *format;
- char *result;
- int unshortened_length;
- gboolean use_count;
-
- g_assert (name != NULL);
-
- if (count < 0) {
- g_warning ("bad count in get_link_name");
- count = 0;
- }
-
- if (count <= 2) {
- /* Handle special cases for low numbers.
- * Perhaps for some locales we will need to add more.
- */
- switch (count) {
- default:
- g_assert_not_reached ();
- /* fall through */
- case 0:
- /* duplicate original file name */
- format = "%s";
- break;
- case 1:
- /* appended to new link file */
- format = _("Link to %s");
- break;
- case 2:
- /* appended to new link file */
- format = _("Another link to %s");
- break;
- }
-
- use_count = FALSE;
- } else {
- /* Handle special cases for the first few numbers of each ten.
- * For locales where getting this exactly right is difficult,
- * these can just be made all the same as the general case below.
- */
- switch (count % 10) {
- case 1:
- /* Localizers: Feel free to leave out the "st" suffix
- * if there's no way to do that nicely for a
- * particular language.
- */
- format = _("%'dst link to %s");
- break;
- case 2:
- /* appended to new link file */
- format = _("%'dnd link to %s");
- break;
- case 3:
- /* appended to new link file */
- format = _("%'drd link to %s");
- break;
- default:
- /* appended to new link file */
- format = _("%'dth link to %s");
- break;
- }
-
- use_count = TRUE;
- }
+get_link_name (const char *name,
+ int count,
+ int max_length)
+{
+ const char *format;
+ char *result;
+ int unshortened_length;
+ gboolean use_count;
+
+ g_assert (name != NULL);
+
+ if (count < 0)
+ {
+ g_warning ("bad count in get_link_name");
+ count = 0;
+ }
+
+ if (count <= 2)
+ {
+ /* Handle special cases for low numbers.
+ * Perhaps for some locales we will need to add more.
+ */
+ switch (count)
+ {
+ default:
+ {
+ g_assert_not_reached ();
+ /* fall through */
+ }
+
+ case 0:
+ {
+ /* duplicate original file name */
+ format = "%s";
+ }
+ break;
+
+ case 1:
+ {
+ /* appended to new link file */
+ format = _("Link to %s");
+ }
+ break;
+
+ case 2:
+ {
+ /* appended to new link file */
+ format = _("Another link to %s");
+ }
+ break;
+ }
+
+ use_count = FALSE;
+ }
+ else
+ {
+ /* Handle special cases for the first few numbers of each ten.
+ * For locales where getting this exactly right is difficult,
+ * these can just be made all the same as the general case below.
+ */
+ switch (count % 10)
+ {
+ case 1:
+ {
+ /* Localizers: Feel free to leave out the "st" suffix
+ * if there's no way to do that nicely for a
+ * particular language.
+ */
+ format = _("%'dst link to %s");
+ }
+ break;
+
+ case 2:
+ {
+ /* appended to new link file */
+ format = _("%'dnd link to %s");
+ }
+ break;
+
+ case 3:
+ {
+ /* appended to new link file */
+ format = _("%'drd link to %s");
+ }
+ break;
+
+ default:
+ {
+ /* appended to new link file */
+ format = _("%'dth link to %s");
+ }
+ break;
+ }
+
+ use_count = TRUE;
+ }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
- if (use_count)
- result = g_strdup_printf (format, count, name);
- else
- result = g_strdup_printf (format, name);
-
- if (max_length > 0 && (unshortened_length = strlen (result)) > max_length) {
- char *new_name;
-
- new_name = shorten_utf8_string (name, unshortened_length - max_length);
- if (new_name) {
- g_free (result);
-
- if (use_count)
- result = g_strdup_printf (format, count, new_name);
- else
- result = g_strdup_printf (format, new_name);
-
- g_assert (strlen (result) <= max_length);
- g_free (new_name);
- }
- }
+ if (use_count)
+ {
+ result = g_strdup_printf (format, count, name);
+ }
+ else
+ {
+ result = g_strdup_printf (format, name);
+ }
+
+ if (max_length > 0 && (unshortened_length = strlen (result)) > max_length)
+ {
+ char *new_name;
+
+ new_name = shorten_utf8_string (name, unshortened_length - max_length);
+ if (new_name)
+ {
+ g_free (result);
+
+ if (use_count)
+ {
+ result = g_strdup_printf (format, count, new_name);
+ }
+ else
+ {
+ result = g_strdup_printf (format, new_name);
+ }
+
+ g_assert (strlen (result) <= max_length);
+ g_free (new_name);
+ }
+ }
#pragma GCC diagnostic pop
- return result;
+ return result;
}
-/* Localizers:
+/* Localizers:
* Feel free to leave out the st, nd, rd and th suffix or
* make some or all of them match.
*/
@@ -553,18 +619,19 @@ static const char untranslated_th_copy_duplicate_format[] = N_("%s (%'dth copy)%
#define TH_COPY_DUPLICATE_FORMAT _(untranslated_th_copy_duplicate_format)
static char *
-extract_string_until (const char *original, const char *until_substring)
+extract_string_until (const char *original,
+ const char *until_substring)
{
- char *result;
-
- g_assert ((int) strlen (original) >= until_substring - original);
- g_assert (until_substring - original >= 0);
+ char *result;
- result = g_malloc (until_substring - original + 1);
- strncpy (result, original, until_substring - original);
- result[until_substring - original] = '\0';
-
- return result;
+ g_assert ((int) strlen (original) >= until_substring - original);
+ g_assert (until_substring - original >= 0);
+
+ result = g_malloc (until_substring - original + 1);
+ strncpy (result, original, until_substring - original);
+ result[until_substring - original] = '\0';
+
+ return result;
}
/* Dismantle a file name, separating the base name, the file suffix and removing any
@@ -572,1076 +639,1222 @@ extract_string_until (const char *original, const char *until_substring)
* (xxxcopy) substring.
*/
static void
-parse_previous_duplicate_name (const char *name,
- char **name_base,
- const char **suffix,
- int *count)
-{
- const char *tag;
-
- g_assert (name[0] != '\0');
-
- *suffix = eel_filename_get_extension_offset (name);
-
- if (*suffix == NULL || (*suffix)[1] == '\0') {
- /* no suffix */
- *suffix = "";
- }
-
- tag = strstr (name, COPY_DUPLICATE_TAG);
- if (tag != NULL) {
- if (tag > *suffix) {
- /* handle case "foo. (copy)" */
- *suffix = "";
- }
- *name_base = extract_string_until (name, tag);
- *count = 1;
- return;
- }
-
-
- tag = strstr (name, ANOTHER_COPY_DUPLICATE_TAG);
- if (tag != NULL) {
- if (tag > *suffix) {
- /* handle case "foo. (another copy)" */
- *suffix = "";
- }
- *name_base = extract_string_until (name, tag);
- *count = 2;
- return;
- }
-
-
- /* Check to see if we got one of st, nd, rd, th. */
- tag = strstr (name, X11TH_COPY_DUPLICATE_TAG);
-
- if (tag == NULL) {
- tag = strstr (name, X12TH_COPY_DUPLICATE_TAG);
- }
- if (tag == NULL) {
- tag = strstr (name, X13TH_COPY_DUPLICATE_TAG);
- }
-
- if (tag == NULL) {
- tag = strstr (name, ST_COPY_DUPLICATE_TAG);
- }
- if (tag == NULL) {
- tag = strstr (name, ND_COPY_DUPLICATE_TAG);
- }
- if (tag == NULL) {
- tag = strstr (name, RD_COPY_DUPLICATE_TAG);
- }
- if (tag == NULL) {
- tag = strstr (name, TH_COPY_DUPLICATE_TAG);
- }
-
- /* If we got one of st, nd, rd, th, fish out the duplicate number. */
- if (tag != NULL) {
- /* localizers: opening parentheses to match the "th copy)" string */
- tag = strstr (name, _(" ("));
- if (tag != NULL) {
- if (tag > *suffix) {
- /* handle case "foo. (22nd copy)" */
- *suffix = "";
- }
- *name_base = extract_string_until (name, tag);
- /* localizers: opening parentheses of the "th copy)" string */
- if (sscanf (tag, _(" (%'d"), count) == 1) {
- if (*count < 1 || *count > 1000000) {
- /* keep the count within a reasonable range */
- *count = 0;
- }
- return;
- }
- *count = 0;
- return;
- }
- }
-
-
- *count = 0;
- if (**suffix != '\0') {
- *name_base = extract_string_until (name, *suffix);
- } else {
- *name_base = g_strdup (name);
- }
+parse_previous_duplicate_name (const char *name,
+ char **name_base,
+ const char **suffix,
+ int *count)
+{
+ const char *tag;
+
+ g_assert (name[0] != '\0');
+
+ *suffix = eel_filename_get_extension_offset (name);
+
+ if (*suffix == NULL || (*suffix)[1] == '\0')
+ {
+ /* no suffix */
+ *suffix = "";
+ }
+
+ tag = strstr (name, COPY_DUPLICATE_TAG);
+ if (tag != NULL)
+ {
+ if (tag > *suffix)
+ {
+ /* handle case "foo. (copy)" */
+ *suffix = "";
+ }
+ *name_base = extract_string_until (name, tag);
+ *count = 1;
+ return;
+ }
+
+
+ tag = strstr (name, ANOTHER_COPY_DUPLICATE_TAG);
+ if (tag != NULL)
+ {
+ if (tag > *suffix)
+ {
+ /* handle case "foo. (another copy)" */
+ *suffix = "";
+ }
+ *name_base = extract_string_until (name, tag);
+ *count = 2;
+ return;
+ }
+
+
+ /* Check to see if we got one of st, nd, rd, th. */
+ tag = strstr (name, X11TH_COPY_DUPLICATE_TAG);
+
+ if (tag == NULL)
+ {
+ tag = strstr (name, X12TH_COPY_DUPLICATE_TAG);
+ }
+ if (tag == NULL)
+ {
+ tag = strstr (name, X13TH_COPY_DUPLICATE_TAG);
+ }
+
+ if (tag == NULL)
+ {
+ tag = strstr (name, ST_COPY_DUPLICATE_TAG);
+ }
+ if (tag == NULL)
+ {
+ tag = strstr (name, ND_COPY_DUPLICATE_TAG);
+ }
+ if (tag == NULL)
+ {
+ tag = strstr (name, RD_COPY_DUPLICATE_TAG);
+ }
+ if (tag == NULL)
+ {
+ tag = strstr (name, TH_COPY_DUPLICATE_TAG);
+ }
+
+ /* If we got one of st, nd, rd, th, fish out the duplicate number. */
+ if (tag != NULL)
+ {
+ /* localizers: opening parentheses to match the "th copy)" string */
+ tag = strstr (name, _(" ("));
+ if (tag != NULL)
+ {
+ if (tag > *suffix)
+ {
+ /* handle case "foo. (22nd copy)" */
+ *suffix = "";
+ }
+ *name_base = extract_string_until (name, tag);
+ /* localizers: opening parentheses of the "th copy)" string */
+ if (sscanf (tag, _(" (%'d"), count) == 1)
+ {
+ if (*count < 1 || *count > 1000000)
+ {
+ /* keep the count within a reasonable range */
+ *count = 0;
+ }
+ return;
+ }
+ *count = 0;
+ return;
+ }
+ }
+
+
+ *count = 0;
+ if (**suffix != '\0')
+ {
+ *name_base = extract_string_until (name, *suffix);
+ }
+ else
+ {
+ *name_base = g_strdup (name);
+ }
}
static char *
-make_next_duplicate_name (const char *base, const char *suffix, int count, int max_length)
-{
- const char *format;
- char *result;
- int unshortened_length;
- gboolean use_count;
-
- if (count < 1) {
- g_warning ("bad count %d in get_duplicate_name", count);
- count = 1;
- }
-
- if (count <= 2) {
-
- /* Handle special cases for low numbers.
- * Perhaps for some locales we will need to add more.
- */
- switch (count) {
- default:
- g_assert_not_reached ();
- /* fall through */
- case 1:
- format = FIRST_COPY_DUPLICATE_FORMAT;
- break;
- case 2:
- format = SECOND_COPY_DUPLICATE_FORMAT;
- break;
-
- }
-
- use_count = FALSE;
- } else {
-
- /* Handle special cases for the first few numbers of each ten.
- * For locales where getting this exactly right is difficult,
- * these can just be made all the same as the general case below.
- */
-
- /* Handle special cases for x11th - x20th.
- */
- switch (count % 100) {
- case 11:
- format = X11TH_COPY_DUPLICATE_FORMAT;
- break;
- case 12:
- format = X12TH_COPY_DUPLICATE_FORMAT;
- break;
- case 13:
- format = X13TH_COPY_DUPLICATE_FORMAT;
- break;
- default:
- format = NULL;
- break;
- }
-
- if (format == NULL) {
- switch (count % 10) {
- case 1:
- format = ST_COPY_DUPLICATE_FORMAT;
- break;
- case 2:
- format = ND_COPY_DUPLICATE_FORMAT;
- break;
- case 3:
- format = RD_COPY_DUPLICATE_FORMAT;
- break;
- default:
- /* The general case. */
- format = TH_COPY_DUPLICATE_FORMAT;
- break;
- }
- }
-
- use_count = TRUE;
-
- }
+make_next_duplicate_name (const char *base,
+ const char *suffix,
+ int count,
+ int max_length)
+{
+ const char *format;
+ char *result;
+ int unshortened_length;
+ gboolean use_count;
+
+ if (count < 1)
+ {
+ g_warning ("bad count %d in get_duplicate_name", count);
+ count = 1;
+ }
+
+ if (count <= 2)
+ {
+ /* Handle special cases for low numbers.
+ * Perhaps for some locales we will need to add more.
+ */
+ switch (count)
+ {
+ default:
+ {
+ g_assert_not_reached ();
+ /* fall through */
+ }
+
+ case 1:
+ {
+ format = FIRST_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ case 2:
+ {
+ format = SECOND_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+ }
+
+ use_count = FALSE;
+ }
+ else
+ {
+ /* Handle special cases for the first few numbers of each ten.
+ * For locales where getting this exactly right is difficult,
+ * these can just be made all the same as the general case below.
+ */
+
+ /* Handle special cases for x11th - x20th.
+ */
+ switch (count % 100)
+ {
+ case 11:
+ {
+ format = X11TH_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ case 12:
+ {
+ format = X12TH_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ case 13:
+ {
+ format = X13TH_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ default:
+ {
+ format = NULL;
+ }
+ break;
+ }
+
+ if (format == NULL)
+ {
+ switch (count % 10)
+ {
+ case 1:
+ {
+ format = ST_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ case 2:
+ {
+ format = ND_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ case 3:
+ {
+ format = RD_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+
+ default:
+ {
+ /* The general case. */
+ format = TH_COPY_DUPLICATE_FORMAT;
+ }
+ break;
+ }
+ }
+
+ use_count = TRUE;
+ }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
- if (use_count)
- result = g_strdup_printf (format, base, count, suffix);
- else
- result = g_strdup_printf (format, base, suffix);
-
- if (max_length > 0 && (unshortened_length = strlen (result)) > max_length) {
- char *new_base;
-
- new_base = shorten_utf8_string (base, unshortened_length - max_length);
- if (new_base) {
- g_free (result);
-
- if (use_count)
- result = g_strdup_printf (format, new_base, count, suffix);
- else
- result = g_strdup_printf (format, new_base, suffix);
-
- g_assert (strlen (result) <= max_length);
- g_free (new_base);
- }
- }
+ if (use_count)
+ {
+ result = g_strdup_printf (format, base, count, suffix);
+ }
+ else
+ {
+ result = g_strdup_printf (format, base, suffix);
+ }
+
+ if (max_length > 0 && (unshortened_length = strlen (result)) > max_length)
+ {
+ char *new_base;
+
+ new_base = shorten_utf8_string (base, unshortened_length - max_length);
+ if (new_base)
+ {
+ g_free (result);
+
+ if (use_count)
+ {
+ result = g_strdup_printf (format, new_base, count, suffix);
+ }
+ else
+ {
+ result = g_strdup_printf (format, new_base, suffix);
+ }
+
+ g_assert (strlen (result) <= max_length);
+ g_free (new_base);
+ }
+ }
#pragma GCC diagnostic pop
- return result;
+ return result;
}
static char *
-get_duplicate_name (const char *name, int count_increment, int max_length)
+get_duplicate_name (const char *name,
+ int count_increment,
+ int max_length)
{
- char *result;
- char *name_base;
- const char *suffix;
- int count;
+ char *result;
+ char *name_base;
+ const char *suffix;
+ int count;
- parse_previous_duplicate_name (name, &name_base, &suffix, &count);
- result = make_next_duplicate_name (name_base, suffix, count + count_increment, max_length);
+ parse_previous_duplicate_name (name, &name_base, &suffix, &count);
+ result = make_next_duplicate_name (name_base, suffix, count + count_increment, max_length);
- g_free (name_base);
+ g_free (name_base);
- return result;
+ return result;
}
static gboolean
has_invalid_xml_char (char *str)
{
- gunichar c;
-
- while (*str != 0) {
- c = g_utf8_get_char (str);
- /* characters XML permits */
- if (!(c == 0x9 ||
- c == 0xA ||
- c == 0xD ||
- (c >= 0x20 && c <= 0xD7FF) ||
- (c >= 0xE000 && c <= 0xFFFD) ||
- (c >= 0x10000 && c <= 0x10FFFF))) {
- return TRUE;
- }
- str = g_utf8_next_char (str);
- }
- return FALSE;
+ gunichar c;
+
+ while (*str != 0)
+ {
+ c = g_utf8_get_char (str);
+ /* characters XML permits */
+ if (!(c == 0x9 ||
+ c == 0xA ||
+ c == 0xD ||
+ (c >= 0x20 && c <= 0xD7FF) ||
+ (c >= 0xE000 && c <= 0xFFFD) ||
+ (c >= 0x10000 && c <= 0x10FFFF)))
+ {
+ return TRUE;
+ }
+ str = g_utf8_next_char (str);
+ }
+ return FALSE;
}
static char *
-custom_full_name_to_string (char *format, va_list va)
+custom_full_name_to_string (char *format,
+ va_list va)
{
- GFile *file;
-
- file = va_arg (va, GFile *);
-
- return g_file_get_parse_name (file);
+ GFile *file;
+
+ file = va_arg (va, GFile *);
+
+ return g_file_get_parse_name (file);
}
static void
custom_full_name_skip (va_list *va)
{
- (void) va_arg (*va, GFile *);
+ (void) va_arg (*va, GFile *);
}
static char *
-custom_basename_to_string (char *format, va_list va)
-{
- GFile *file;
- GFileInfo *info;
- char *name, *basename, *tmp;
- GMount *mount;
-
- file = va_arg (va, GFile *);
-
- if ((mount = nautilus_get_mounted_mount_for_root (file)) != NULL) {
- name = g_mount_get_name (mount);
- g_object_unref (mount);
- } else {
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- 0,
- g_cancellable_get_current (),
- NULL);
- name = NULL;
- if (info) {
- name = g_strdup (g_file_info_get_display_name (info));
- g_object_unref (info);
- }
- }
-
- if (name == NULL) {
- basename = g_file_get_basename (file);
- if (g_utf8_validate (basename, -1, NULL)) {
- name = basename;
- } else {
- name = g_uri_escape_string (basename, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
- g_free (basename);
- }
- }
-
- /* Some chars can't be put in the markup we use for the dialogs... */
- if (has_invalid_xml_char (name)) {
- tmp = name;
- name = g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
- g_free (tmp);
- }
-
- /* Finally, if the string is too long, truncate it. */
- if (name != NULL) {
- tmp = name;
- name = eel_str_middle_truncate (tmp, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH);
- g_free (tmp);
- }
-
-
- return name;
+custom_basename_to_string (char *format,
+ va_list va)
+{
+ GFile *file;
+ GFileInfo *info;
+ char *name, *basename, *tmp;
+ GMount *mount;
+
+ file = va_arg (va, GFile *);
+
+ if ((mount = nautilus_get_mounted_mount_for_root (file)) != NULL)
+ {
+ name = g_mount_get_name (mount);
+ g_object_unref (mount);
+ }
+ else
+ {
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
+ 0,
+ g_cancellable_get_current (),
+ NULL);
+ name = NULL;
+ if (info)
+ {
+ name = g_strdup (g_file_info_get_display_name (info));
+ g_object_unref (info);
+ }
+ }
+
+ if (name == NULL)
+ {
+ basename = g_file_get_basename (file);
+ if (g_utf8_validate (basename, -1, NULL))
+ {
+ name = basename;
+ }
+ else
+ {
+ name = g_uri_escape_string (basename, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
+ g_free (basename);
+ }
+ }
+
+ /* Some chars can't be put in the markup we use for the dialogs... */
+ if (has_invalid_xml_char (name))
+ {
+ tmp = name;
+ name = g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
+ g_free (tmp);
+ }
+
+ /* Finally, if the string is too long, truncate it. */
+ if (name != NULL)
+ {
+ tmp = name;
+ name = eel_str_middle_truncate (tmp, MAXIMUM_DISPLAYED_FILE_NAME_LENGTH);
+ g_free (tmp);
+ }
+
+
+ return name;
}
static void
custom_basename_skip (va_list *va)
{
- (void) va_arg (*va, GFile *);
+ (void) va_arg (*va, GFile *);
}
static char *
-custom_size_to_string (char *format, va_list va)
+custom_size_to_string (char *format,
+ va_list va)
{
- goffset size;
+ goffset size;
- size = va_arg (va, goffset);
- return g_format_size (size);
+ size = va_arg (va, goffset);
+ return g_format_size (size);
}
static void
custom_size_skip (va_list *va)
{
- (void) va_arg (*va, goffset);
+ (void) va_arg (*va, goffset);
}
static char *
-custom_time_to_string (char *format, va_list va)
+custom_time_to_string (char *format,
+ va_list va)
{
- int secs;
+ int secs;
- secs = va_arg (va, int);
- return format_time (secs);
+ secs = va_arg (va, int);
+ return format_time (secs);
}
static void
custom_time_skip (va_list *va)
{
- (void) va_arg (*va, int);
+ (void) va_arg (*va, int);
}
static char *
-custom_mount_to_string (char *format, va_list va)
+custom_mount_to_string (char *format,
+ va_list va)
{
- GMount *mount;
+ GMount *mount;
- mount = va_arg (va, GMount *);
- return g_mount_get_name (mount);
+ mount = va_arg (va, GMount *);
+ return g_mount_get_name (mount);
}
static void
custom_mount_skip (va_list *va)
{
- (void) va_arg (*va, GMount *);
+ (void) va_arg (*va, GMount *);
}
-static EelPrintfHandler handlers[] = {
- { 'F', custom_full_name_to_string, custom_full_name_skip },
- { 'B', custom_basename_to_string, custom_basename_skip },
- { 'S', custom_size_to_string, custom_size_skip },
- { 'T', custom_time_to_string, custom_time_skip },
- { 'V', custom_mount_to_string, custom_mount_skip },
- { 0 }
+static EelPrintfHandler handlers[] =
+{
+ { 'F', custom_full_name_to_string, custom_full_name_skip },
+ { 'B', custom_basename_to_string, custom_basename_skip },
+ { 'S', custom_size_to_string, custom_size_skip },
+ { 'T', custom_time_to_string, custom_time_skip },
+ { 'V', custom_mount_to_string, custom_mount_skip },
+ { 0 }
};
static char *
-f (const char *format, ...) {
- va_list va;
- char *res;
-
- va_start (va, format);
- res = eel_strdup_vprintf_with_custom (handlers, format, va);
- va_end (va);
+f (const char *format,
+ ...)
+{
+ va_list va;
+ char *res;
- return res;
+ va_start (va, format);
+ res = eel_strdup_vprintf_with_custom (handlers, format, va);
+ va_end (va);
+
+ return res;
}
-#define op_job_new(__type, parent_window) ((__type *)(init_common (sizeof(__type), parent_window)))
+#define op_job_new(__type, parent_window) ((__type *) (init_common (sizeof (__type), parent_window)))
static gpointer
-init_common (gsize job_size,
- GtkWindow *parent_window)
+init_common (gsize job_size,
+ GtkWindow *parent_window)
{
- CommonJob *common;
- GdkScreen *screen;
+ CommonJob *common;
+ GdkScreen *screen;
- common = g_malloc0 (job_size);
+ common = g_malloc0 (job_size);
- if (parent_window) {
- common->parent_window = parent_window;
- g_object_add_weak_pointer (G_OBJECT (common->parent_window),
- (gpointer *) &common->parent_window);
+ if (parent_window)
+ {
+ common->parent_window = parent_window;
+ g_object_add_weak_pointer (G_OBJECT (common->parent_window),
+ (gpointer *) &common->parent_window);
+ }
+ common->progress = nautilus_progress_info_new ();
+ common->cancellable = nautilus_progress_info_get_cancellable (common->progress);
+ common->time = g_timer_new ();
+ common->inhibit_cookie = 0;
+ common->screen_num = 0;
+ if (parent_window)
+ {
+ screen = gtk_widget_get_screen (GTK_WIDGET (parent_window));
+ common->screen_num = gdk_screen_get_number (screen);
+ }
- }
- common->progress = nautilus_progress_info_new ();
- common->cancellable = nautilus_progress_info_get_cancellable (common->progress);
- common->time = g_timer_new ();
- common->inhibit_cookie = 0;
- common->screen_num = 0;
- if (parent_window) {
- screen = gtk_widget_get_screen (GTK_WIDGET (parent_window));
- common->screen_num = gdk_screen_get_number (screen);
- }
-
- return common;
+ return common;
}
static void
finalize_common (CommonJob *common)
{
- nautilus_progress_info_finish (common->progress);
+ nautilus_progress_info_finish (common->progress);
- if (common->inhibit_cookie != 0) {
- gtk_application_uninhibit (GTK_APPLICATION (g_application_get_default ()),
- common->inhibit_cookie);
- }
+ if (common->inhibit_cookie != 0)
+ {
+ gtk_application_uninhibit (GTK_APPLICATION (g_application_get_default ()),
+ common->inhibit_cookie);
+ }
- common->inhibit_cookie = 0;
- g_timer_destroy (common->time);
+ common->inhibit_cookie = 0;
+ g_timer_destroy (common->time);
- if (common->parent_window) {
- g_object_remove_weak_pointer (G_OBJECT (common->parent_window),
- (gpointer *) &common->parent_window);
- }
+ if (common->parent_window)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (common->parent_window),
+ (gpointer *) &common->parent_window);
+ }
- if (common->skip_files) {
- g_hash_table_destroy (common->skip_files);
- }
- if (common->skip_readdir_error) {
- g_hash_table_destroy (common->skip_readdir_error);
- }
+ if (common->skip_files)
+ {
+ g_hash_table_destroy (common->skip_files);
+ }
+ if (common->skip_readdir_error)
+ {
+ g_hash_table_destroy (common->skip_readdir_error);
+ }
- if (common->undo_info != NULL) {
- nautilus_file_undo_manager_set_action (common->undo_info);
- g_object_unref (common->undo_info);
- }
+ if (common->undo_info != NULL)
+ {
+ nautilus_file_undo_manager_set_action (common->undo_info);
+ g_object_unref (common->undo_info);
+ }
- g_object_unref (common->progress);
- g_object_unref (common->cancellable);
- g_free (common);
+ g_object_unref (common->progress);
+ g_object_unref (common->cancellable);
+ g_free (common);
}
static void
skip_file (CommonJob *common,
- GFile *file)
+ GFile *file)
{
- if (common->skip_files == NULL) {
- common->skip_files =
- g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
- }
+ if (common->skip_files == NULL)
+ {
+ common->skip_files =
+ g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+ }
- g_hash_table_insert (common->skip_files, g_object_ref (file), file);
+ g_hash_table_insert (common->skip_files, g_object_ref (file), file);
}
static void
skip_readdir_error (CommonJob *common,
- GFile *dir)
+ GFile *dir)
{
- if (common->skip_readdir_error == NULL) {
- common->skip_readdir_error =
- g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
- }
+ if (common->skip_readdir_error == NULL)
+ {
+ common->skip_readdir_error =
+ g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+ }
- g_hash_table_insert (common->skip_readdir_error, g_object_ref (dir), dir);
+ g_hash_table_insert (common->skip_readdir_error, g_object_ref (dir), dir);
}
static gboolean
should_skip_file (CommonJob *common,
- GFile *file)
+ GFile *file)
{
- if (common->skip_files != NULL) {
- return g_hash_table_lookup (common->skip_files, file) != NULL;
- }
- return FALSE;
+ if (common->skip_files != NULL)
+ {
+ return g_hash_table_lookup (common->skip_files, file) != NULL;
+ }
+ return FALSE;
}
static gboolean
should_skip_readdir_error (CommonJob *common,
- GFile *dir)
+ GFile *dir)
{
- if (common->skip_readdir_error != NULL) {
- return g_hash_table_lookup (common->skip_readdir_error, dir) != NULL;
- }
- return FALSE;
+ if (common->skip_readdir_error != NULL)
+ {
+ return g_hash_table_lookup (common->skip_readdir_error, dir) != NULL;
+ }
+ return FALSE;
}
static gboolean
can_delete_without_confirm (GFile *file)
{
- if (g_file_has_uri_scheme (file, "burn") ||
- g_file_has_uri_scheme (file, "recent") ||
- g_file_has_uri_scheme (file, "x-nautilus-desktop")) {
- return TRUE;
- }
+ if (g_file_has_uri_scheme (file, "burn") ||
+ g_file_has_uri_scheme (file, "recent") ||
+ g_file_has_uri_scheme (file, "x-nautilus-desktop"))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
can_delete_files_without_confirm (GList *files)
{
- g_assert (files != NULL);
-
- while (files != NULL) {
- if (!can_delete_without_confirm (files->data)) {
- return FALSE;
- }
-
- files = files->next;
- }
-
- return TRUE;
-}
-
-typedef struct {
- GtkWindow **parent_window;
- gboolean ignore_close_box;
- GtkMessageType message_type;
- const char *primary_text;
- const char *secondary_text;
- const char *details_text;
- const char **button_titles;
- gboolean show_all;
- int result;
- /* Dialogs are ran from operation threads, which need to be blocked until
- * the user gives a valid response
- */
- gboolean completed;
- GMutex mutex;
- GCond cond;
+ g_assert (files != NULL);
+
+ while (files != NULL)
+ {
+ if (!can_delete_without_confirm (files->data))
+ {
+ return FALSE;
+ }
+
+ files = files->next;
+ }
+
+ return TRUE;
+}
+
+typedef struct
+{
+ GtkWindow **parent_window;
+ gboolean ignore_close_box;
+ GtkMessageType message_type;
+ const char *primary_text;
+ const char *secondary_text;
+ const char *details_text;
+ const char **button_titles;
+ gboolean show_all;
+ int result;
+ /* Dialogs are ran from operation threads, which need to be blocked until
+ * the user gives a valid response
+ */
+ gboolean completed;
+ GMutex mutex;
+ GCond cond;
} RunSimpleDialogData;
static gboolean
do_run_simple_dialog (gpointer _data)
{
- RunSimpleDialogData *data = _data;
- const char *button_title;
- GtkWidget *dialog;
- int result;
- int response_id;
-
- g_mutex_lock (&data->mutex);
-
- /* Create the dialog. */
- dialog = gtk_message_dialog_new (*data->parent_window,
- 0,
- data->message_type,
- GTK_BUTTONS_NONE,
- NULL);
-
- g_object_set (dialog,
- "text", data->primary_text,
- "secondary-text", data->secondary_text,
- NULL);
-
- for (response_id = 0;
- data->button_titles[response_id] != NULL;
- response_id++) {
- button_title = data->button_titles[response_id];
- if (!data->show_all && is_all_button_text (button_title)) {
- continue;
- }
-
- gtk_dialog_add_button (GTK_DIALOG (dialog), button_title, response_id);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
- }
-
- if (data->details_text) {
- eel_gtk_message_dialog_set_details_label (GTK_MESSAGE_DIALOG (dialog),
- data->details_text);
- }
-
- /* Run it. */
+ RunSimpleDialogData *data = _data;
+ const char *button_title;
+ GtkWidget *dialog;
+ int result;
+ int response_id;
+
+ g_mutex_lock (&data->mutex);
+
+ /* Create the dialog. */
+ dialog = gtk_message_dialog_new (*data->parent_window,
+ 0,
+ data->message_type,
+ GTK_BUTTONS_NONE,
+ NULL);
+
+ g_object_set (dialog,
+ "text", data->primary_text,
+ "secondary-text", data->secondary_text,
+ NULL);
+
+ for (response_id = 0;
+ data->button_titles[response_id] != NULL;
+ response_id++)
+ {
+ button_title = data->button_titles[response_id];
+ if (!data->show_all && is_all_button_text (button_title))
+ {
+ continue;
+ }
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog), button_title, response_id);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), response_id);
+ }
+
+ if (data->details_text)
+ {
+ eel_gtk_message_dialog_set_details_label (GTK_MESSAGE_DIALOG (dialog),
+ data->details_text);
+ }
+
+ /* Run it. */
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+
+ while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && data->ignore_close_box)
+ {
result = gtk_dialog_run (GTK_DIALOG (dialog));
-
- while ((result == GTK_RESPONSE_NONE || result == GTK_RESPONSE_DELETE_EVENT) && data->ignore_close_box) {
- result = gtk_dialog_run (GTK_DIALOG (dialog));
- }
-
- gtk_widget_destroy (dialog);
+ }
- data->result = result;
- data->completed = TRUE;
+ gtk_widget_destroy (dialog);
- g_cond_signal (&data->cond);
- g_mutex_unlock (&data->mutex);
-
- return FALSE;
+ data->result = result;
+ data->completed = TRUE;
+
+ g_cond_signal (&data->cond);
+ g_mutex_unlock (&data->mutex);
+
+ return FALSE;
}
/* NOTE: This frees the primary / secondary strings, in order to
- avoid doing that everywhere. So, make sure they are strduped */
+ * avoid doing that everywhere. So, make sure they are strduped */
static int
-run_simple_dialog_va (CommonJob *job,
- gboolean ignore_close_box,
- GtkMessageType message_type,
- char *primary_text,
- char *secondary_text,
- const char *details_text,
- gboolean show_all,
- va_list varargs)
-{
- RunSimpleDialogData *data;
- int res;
- const char *button_title;
- GPtrArray *ptr_array;
-
- g_timer_stop (job->time);
-
- data = g_new0 (RunSimpleDialogData, 1);
- data->parent_window = &job->parent_window;
- data->ignore_close_box = ignore_close_box;
- data->message_type = message_type;
- data->primary_text = primary_text;
- data->secondary_text = secondary_text;
- data->details_text = details_text;
- data->show_all = show_all;
- data->completed = FALSE;
- g_mutex_init (&data->mutex);
- g_cond_init (&data->cond);
-
- ptr_array = g_ptr_array_new ();
- while ((button_title = va_arg (varargs, const char *)) != NULL) {
- g_ptr_array_add (ptr_array, (char *)button_title);
- }
- g_ptr_array_add (ptr_array, NULL);
- data->button_titles = (const char **)g_ptr_array_free (ptr_array, FALSE);
-
- nautilus_progress_info_pause (job->progress);
-
- g_mutex_lock (&data->mutex);
-
- g_main_context_invoke (NULL,
- do_run_simple_dialog,
- data);
-
- while (!data->completed) {
- g_cond_wait (&data->cond, &data->mutex);
- }
-
- nautilus_progress_info_resume (job->progress);
- res = data->result;
-
- g_mutex_unlock (&data->mutex);
- g_mutex_clear (&data->mutex);
- g_cond_clear (&data->cond);
-
- g_free (data->button_titles);
- g_free (data);
-
- g_timer_continue (job->time);
-
- g_free (primary_text);
- g_free (secondary_text);
-
- return res;
+run_simple_dialog_va (CommonJob *job,
+ gboolean ignore_close_box,
+ GtkMessageType message_type,
+ char *primary_text,
+ char *secondary_text,
+ const char *details_text,
+ gboolean show_all,
+ va_list varargs)
+{
+ RunSimpleDialogData *data;
+ int res;
+ const char *button_title;
+ GPtrArray *ptr_array;
+
+ g_timer_stop (job->time);
+
+ data = g_new0 (RunSimpleDialogData, 1);
+ data->parent_window = &job->parent_window;
+ data->ignore_close_box = ignore_close_box;
+ data->message_type = message_type;
+ data->primary_text = primary_text;
+ data->secondary_text = secondary_text;
+ data->details_text = details_text;
+ data->show_all = show_all;
+ data->completed = FALSE;
+ g_mutex_init (&data->mutex);
+ g_cond_init (&data->cond);
+
+ ptr_array = g_ptr_array_new ();
+ while ((button_title = va_arg (varargs, const char *)) != NULL)
+ {
+ g_ptr_array_add (ptr_array, (char *) button_title);
+ }
+ g_ptr_array_add (ptr_array, NULL);
+ data->button_titles = (const char **) g_ptr_array_free (ptr_array, FALSE);
+
+ nautilus_progress_info_pause (job->progress);
+
+ g_mutex_lock (&data->mutex);
+
+ g_main_context_invoke (NULL,
+ do_run_simple_dialog,
+ data);
+
+ while (!data->completed)
+ {
+ g_cond_wait (&data->cond, &data->mutex);
+ }
+
+ nautilus_progress_info_resume (job->progress);
+ res = data->result;
+
+ g_mutex_unlock (&data->mutex);
+ g_mutex_clear (&data->mutex);
+ g_cond_clear (&data->cond);
+
+ g_free (data->button_titles);
+ g_free (data);
+
+ g_timer_continue (job->time);
+
+ g_free (primary_text);
+ g_free (secondary_text);
+
+ return res;
}
#if 0 /* Not used at the moment */
static int
-run_simple_dialog (CommonJob *job,
- gboolean ignore_close_box,
- GtkMessageType message_type,
- char *primary_text,
- char *secondary_text,
- const char *details_text,
- ...)
-{
- va_list varargs;
- int res;
-
- va_start (varargs, details_text);
- res = run_simple_dialog_va (job,
- ignore_close_box,
- message_type,
- primary_text,
- secondary_text,
- details_text,
- varargs);
- va_end (varargs);
- return res;
+run_simple_dialog (CommonJob *job,
+ gboolean ignore_close_box,
+ GtkMessageType message_type,
+ char *primary_text,
+ char *secondary_text,
+ const char *details_text,
+ ...)
+{
+ va_list varargs;
+ int res;
+
+ va_start (varargs, details_text);
+ res = run_simple_dialog_va (job,
+ ignore_close_box,
+ message_type,
+ primary_text,
+ secondary_text,
+ details_text,
+ varargs);
+ va_end (varargs);
+ return res;
}
#endif
static int
-run_error (CommonJob *job,
- char *primary_text,
- char *secondary_text,
- const char *details_text,
- gboolean show_all,
- ...)
-{
- va_list varargs;
- int res;
-
- va_start (varargs, show_all);
- res = run_simple_dialog_va (job,
- FALSE,
- GTK_MESSAGE_ERROR,
- primary_text,
- secondary_text,
- details_text,
- show_all,
- varargs);
- va_end (varargs);
- return res;
+run_error (CommonJob *job,
+ char *primary_text,
+ char *secondary_text,
+ const char *details_text,
+ gboolean show_all,
+ ...)
+{
+ va_list varargs;
+ int res;
+
+ va_start (varargs, show_all);
+ res = run_simple_dialog_va (job,
+ FALSE,
+ GTK_MESSAGE_ERROR,
+ primary_text,
+ secondary_text,
+ details_text,
+ show_all,
+ varargs);
+ va_end (varargs);
+ return res;
}
static int
-run_warning (CommonJob *job,
- char *primary_text,
- char *secondary_text,
- const char *details_text,
- gboolean show_all,
- ...)
-{
- va_list varargs;
- int res;
-
- va_start (varargs, show_all);
- res = run_simple_dialog_va (job,
- FALSE,
- GTK_MESSAGE_WARNING,
- primary_text,
- secondary_text,
- details_text,
- show_all,
- varargs);
- va_end (varargs);
- return res;
+run_warning (CommonJob *job,
+ char *primary_text,
+ char *secondary_text,
+ const char *details_text,
+ gboolean show_all,
+ ...)
+{
+ va_list varargs;
+ int res;
+
+ va_start (varargs, show_all);
+ res = run_simple_dialog_va (job,
+ FALSE,
+ GTK_MESSAGE_WARNING,
+ primary_text,
+ secondary_text,
+ details_text,
+ show_all,
+ varargs);
+ va_end (varargs);
+ return res;
}
static int
-run_question (CommonJob *job,
- char *primary_text,
- char *secondary_text,
- const char *details_text,
- gboolean show_all,
- ...)
-{
- va_list varargs;
- int res;
-
- va_start (varargs, show_all);
- res = run_simple_dialog_va (job,
- FALSE,
- GTK_MESSAGE_QUESTION,
- primary_text,
- secondary_text,
- details_text,
- show_all,
- varargs);
- va_end (varargs);
- return res;
+run_question (CommonJob *job,
+ char *primary_text,
+ char *secondary_text,
+ const char *details_text,
+ gboolean show_all,
+ ...)
+{
+ va_list varargs;
+ int res;
+
+ va_start (varargs, show_all);
+ res = run_simple_dialog_va (job,
+ FALSE,
+ GTK_MESSAGE_QUESTION,
+ primary_text,
+ secondary_text,
+ details_text,
+ show_all,
+ varargs);
+ va_end (varargs);
+ return res;
}
static int
-run_cancel_or_skip_warning (CommonJob *job,
- char *primary_text,
- char *secondary_text,
- const char *details_text,
- int total_operations,
- int operations_remaining)
-{
- int response;
-
- if (total_operations == 1) {
- response = run_warning (job,
- primary_text,
- secondary_text,
- details_text,
- FALSE,
- CANCEL,
- NULL);
- } else {
- response = run_warning (job,
- primary_text,
- secondary_text,
- details_text,
- operations_remaining > 1,
- CANCEL, SKIP_ALL, SKIP,
- NULL);
- }
-
- return response;
+run_cancel_or_skip_warning (CommonJob *job,
+ char *primary_text,
+ char *secondary_text,
+ const char *details_text,
+ int total_operations,
+ int operations_remaining)
+{
+ int response;
+
+ if (total_operations == 1)
+ {
+ response = run_warning (job,
+ primary_text,
+ secondary_text,
+ details_text,
+ FALSE,
+ CANCEL,
+ NULL);
+ }
+ else
+ {
+ response = run_warning (job,
+ primary_text,
+ secondary_text,
+ details_text,
+ operations_remaining > 1,
+ CANCEL, SKIP_ALL, SKIP,
+ NULL);
+ }
+
+ return response;
}
static void
-inhibit_power_manager (CommonJob *job, const char *message)
+inhibit_power_manager (CommonJob *job,
+ const char *message)
{
- job->inhibit_cookie = gtk_application_inhibit (GTK_APPLICATION (g_application_get_default ()),
- GTK_WINDOW (job->parent_window),
- GTK_APPLICATION_INHIBIT_LOGOUT |
- GTK_APPLICATION_INHIBIT_SUSPEND,
- message);
+ job->inhibit_cookie = gtk_application_inhibit (GTK_APPLICATION (g_application_get_default ()),
+ GTK_WINDOW (job->parent_window),
+ GTK_APPLICATION_INHIBIT_LOGOUT |
+ GTK_APPLICATION_INHIBIT_SUSPEND,
+ message);
}
static void
abort_job (CommonJob *job)
{
- /* destroy the undo action data too */
- g_clear_object (&job->undo_info);
+ /* destroy the undo action data too */
+ g_clear_object (&job->undo_info);
- g_cancellable_cancel (job->cancellable);
+ g_cancellable_cancel (job->cancellable);
}
static gboolean
job_aborted (CommonJob *job)
{
- return g_cancellable_is_cancelled (job->cancellable);
+ return g_cancellable_is_cancelled (job->cancellable);
}
/* Since this happens on a thread we can't use the global prefs object */
static gboolean
should_confirm_trash (void)
{
- GSettings *prefs;
- gboolean confirm_trash;
+ GSettings *prefs;
+ gboolean confirm_trash;
- prefs = g_settings_new ("org.gnome.nautilus.preferences");
- confirm_trash = g_settings_get_boolean (prefs, NAUTILUS_PREFERENCES_CONFIRM_TRASH);
- g_object_unref (prefs);
- return confirm_trash;
+ prefs = g_settings_new ("org.gnome.nautilus.preferences");
+ confirm_trash = g_settings_get_boolean (prefs, NAUTILUS_PREFERENCES_CONFIRM_TRASH);
+ g_object_unref (prefs);
+ return confirm_trash;
}
static gboolean
confirm_delete_from_trash (CommonJob *job,
- GList *files)
-{
- char *prompt;
- int file_count;
- int response;
-
- /* Just Say Yes if the preference says not to confirm. */
- if (!should_confirm_trash ()) {
- return TRUE;
- }
-
- file_count = g_list_length (files);
- g_assert (file_count > 0);
-
- if (file_count == 1) {
- prompt = f (_("Are you sure you want to permanently delete “%B” "
- "from the trash?"), files->data);
- } else {
- prompt = f (ngettext("Are you sure you want to permanently delete "
- "the %'d selected item from the trash?",
- "Are you sure you want to permanently delete "
- "the %'d selected items from the trash?",
- file_count),
- file_count);
- }
-
- response = run_warning (job,
- prompt,
- f (_("If you delete an item, it will be permanently lost.")),
- NULL,
- FALSE,
- CANCEL, DELETE,
- NULL);
-
- return (response == 1);
+ GList *files)
+{
+ char *prompt;
+ int file_count;
+ int response;
+
+ /* Just Say Yes if the preference says not to confirm. */
+ if (!should_confirm_trash ())
+ {
+ return TRUE;
+ }
+
+ file_count = g_list_length (files);
+ g_assert (file_count > 0);
+
+ if (file_count == 1)
+ {
+ prompt = f (_("Are you sure you want to permanently delete “%B” "
+ "from the trash?"), files->data);
+ }
+ else
+ {
+ prompt = f (ngettext ("Are you sure you want to permanently delete "
+ "the %'d selected item from the trash?",
+ "Are you sure you want to permanently delete "
+ "the %'d selected items from the trash?",
+ file_count),
+ file_count);
+ }
+
+ response = run_warning (job,
+ prompt,
+ f (_("If you delete an item, it will be permanently lost.")),
+ NULL,
+ FALSE,
+ CANCEL, DELETE,
+ NULL);
+
+ return (response == 1);
}
static gboolean
confirm_empty_trash (CommonJob *job)
{
- char *prompt;
- int response;
+ char *prompt;
+ int response;
- /* Just Say Yes if the preference says not to confirm. */
- if (!should_confirm_trash ()) {
- return TRUE;
- }
+ /* Just Say Yes if the preference says not to confirm. */
+ if (!should_confirm_trash ())
+ {
+ return TRUE;
+ }
- prompt = f (_("Empty all items from Trash?"));
+ prompt = f (_("Empty all items from Trash?"));
- response = run_warning (job,
- prompt,
- f(_("All items in the Trash will be permanently deleted.")),
- NULL,
- FALSE,
- CANCEL, _("Empty _Trash"),
- NULL);
+ response = run_warning (job,
+ prompt,
+ f (_("All items in the Trash will be permanently deleted.")),
+ NULL,
+ FALSE,
+ CANCEL, _("Empty _Trash"),
+ NULL);
- return (response == 1);
+ return (response == 1);
}
static gboolean
confirm_delete_directly (CommonJob *job,
- GList *files)
-{
- char *prompt;
- int file_count;
- int response;
-
- /* Just Say Yes if the preference says not to confirm. */
- if (!should_confirm_trash ()) {
- return TRUE;
- }
-
- file_count = g_list_length (files);
- g_assert (file_count > 0);
-
- if (can_delete_files_without_confirm (files)) {
- return TRUE;
- }
-
- if (file_count == 1) {
- prompt = f (_("Are you sure you want to permanently delete “%B”?"),
- files->data);
- } else {
- prompt = f (ngettext("Are you sure you want to permanently delete "
- "the %'d selected item?",
- "Are you sure you want to permanently delete "
- "the %'d selected items?", file_count),
- file_count);
- }
-
- response = run_warning (job,
- prompt,
- f (_("If you delete an item, it will be permanently lost.")),
- NULL,
- FALSE,
- CANCEL, DELETE,
- NULL);
-
- return response == 1;
+ GList *files)
+{
+ char *prompt;
+ int file_count;
+ int response;
+
+ /* Just Say Yes if the preference says not to confirm. */
+ if (!should_confirm_trash ())
+ {
+ return TRUE;
+ }
+
+ file_count = g_list_length (files);
+ g_assert (file_count > 0);
+
+ if (can_delete_files_without_confirm (files))
+ {
+ return TRUE;
+ }
+
+ if (file_count == 1)
+ {
+ prompt = f (_("Are you sure you want to permanently delete “%B”?"),
+ files->data);
+ }
+ else
+ {
+ prompt = f (ngettext ("Are you sure you want to permanently delete "
+ "the %'d selected item?",
+ "Are you sure you want to permanently delete "
+ "the %'d selected items?", file_count),
+ file_count);
+ }
+
+ response = run_warning (job,
+ prompt,
+ f (_("If you delete an item, it will be permanently lost.")),
+ NULL,
+ FALSE,
+ CANCEL, DELETE,
+ NULL);
+
+ return response == 1;
}
static void
-report_delete_progress (CommonJob *job,
- SourceInfo *source_info,
- TransferInfo *transfer_info)
-{
- int files_left;
- double elapsed, transfer_rate;
- int remaining_time;
- gint64 now;
- char *details;
- char *status;
- DeleteJob *delete_job;
-
- delete_job = (DeleteJob *) job;
- now = g_get_monotonic_time ();
- files_left = source_info->num_files - transfer_info->num_files;
-
- /* Races and whatnot could cause this to be negative... */
- if (files_left < 0) {
- files_left = 0;
- }
-
- /* If the number of files left is 0, we want to update the status without
- * considering this time, since we want to change the status to completed
- * and probably we won't get more calls to this function */
- if (transfer_info->last_report_time != 0 &&
- ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC &&
- files_left > 0) {
- return;
- }
-
- transfer_info->last_report_time = now;
-
- if (source_info->num_files == 1) {
- if (files_left == 0) {
- status = _("Deleted “%B”");
- } else {
- status = _("Deleting “%B”");
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- (GFile*) delete_job->files->data));
-
- } else {
- if (files_left == 0) {
- status = ngettext ("Deleted %'d file",
- "Deleted %'d files",
- source_info->num_files);
- } else {
- status = ngettext ("Deleting %'d file",
- "Deleting %'d files",
- source_info->num_files);
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- source_info->num_files));
- }
-
- elapsed = g_timer_elapsed (job->time, NULL);
- transfer_rate = 0;
- remaining_time = INT_MAX;
- if (elapsed > 0) {
- transfer_rate = transfer_info->num_files / elapsed;
- if (transfer_rate > 0)
- remaining_time = (source_info->num_files - transfer_info->num_files) / transfer_rate;
- }
-
- if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE) {
- if (files_left > 0) {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files + 1,
- source_info->num_files);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files,
- source_info->num_files);
- }
- } else {
- if (files_left > 0) {
- gchar *time_left_message;
- gchar *files_per_second_message;
- gchar *concat_detail;
-
- /* To translators: %T will expand to a time duration like "2 minutes".
- * So the whole thing will be something like "1 / 5 -- 2 hours left (4 files/sec)"
- *
- * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
- */
- time_left_message = ngettext ("%'d / %'d \xE2\x80\x94 %T left",
- "%'d / %'d \xE2\x80\x94 %T left",
- seconds_count_format_time_units (remaining_time));
- transfer_rate += 0.5;
- files_per_second_message = ngettext ("(%d file/sec)",
- "(%d files/sec)",
- (int) transfer_rate);
- concat_detail = g_strconcat (time_left_message, " ", files_per_second_message, NULL);
-
- details = f (concat_detail,
- transfer_info->num_files + 1, source_info->num_files,
- remaining_time,
- (int) transfer_rate);
-
- g_free (concat_detail);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files,
- source_info->num_files);
- }
- }
- nautilus_progress_info_set_details (job->progress, details);
+report_delete_progress (CommonJob *job,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info)
+{
+ int files_left;
+ double elapsed, transfer_rate;
+ int remaining_time;
+ gint64 now;
+ char *details;
+ char *status;
+ DeleteJob *delete_job;
+
+ delete_job = (DeleteJob *) job;
+ now = g_get_monotonic_time ();
+ files_left = source_info->num_files - transfer_info->num_files;
+
+ /* Races and whatnot could cause this to be negative... */
+ if (files_left < 0)
+ {
+ files_left = 0;
+ }
- if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE) {
- nautilus_progress_info_set_remaining_time (job->progress,
- remaining_time);
- nautilus_progress_info_set_elapsed_time (job->progress,
- elapsed);
+ /* If the number of files left is 0, we want to update the status without
+ * considering this time, since we want to change the status to completed
+ * and probably we won't get more calls to this function */
+ if (transfer_info->last_report_time != 0 &&
+ ABS ((gint64) (transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC &&
+ files_left > 0)
+ {
+ return;
+ }
+
+ transfer_info->last_report_time = now;
+
+ if (source_info->num_files == 1)
+ {
+ if (files_left == 0)
+ {
+ status = _("Deleted “%B”");
}
+ else
+ {
+ status = _("Deleting “%B”");
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ (GFile *) delete_job->files->data));
+ }
+ else
+ {
+ if (files_left == 0)
+ {
+ status = ngettext ("Deleted %'d file",
+ "Deleted %'d files",
+ source_info->num_files);
+ }
+ else
+ {
+ status = ngettext ("Deleting %'d file",
+ "Deleting %'d files",
+ source_info->num_files);
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ source_info->num_files));
+ }
+
+ elapsed = g_timer_elapsed (job->time, NULL);
+ transfer_rate = 0;
+ remaining_time = INT_MAX;
+ if (elapsed > 0)
+ {
+ transfer_rate = transfer_info->num_files / elapsed;
+ if (transfer_rate > 0)
+ {
+ remaining_time = (source_info->num_files - transfer_info->num_files) / transfer_rate;
+ }
+ }
- if (source_info->num_files != 0) {
- nautilus_progress_info_set_progress (job->progress, transfer_info->num_files, source_info->num_files);
- }
+ if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE)
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files + 1,
+ source_info->num_files);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files,
+ source_info->num_files);
+ }
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ gchar *time_left_message;
+ gchar *files_per_second_message;
+ gchar *concat_detail;
+
+ /* To translators: %T will expand to a time duration like "2 minutes".
+ * So the whole thing will be something like "1 / 5 -- 2 hours left (4 files/sec)"
+ *
+ * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
+ */
+ time_left_message = ngettext ("%'d / %'d \xE2\x80\x94 %T left",
+ "%'d / %'d \xE2\x80\x94 %T left",
+ seconds_count_format_time_units (remaining_time));
+ transfer_rate += 0.5;
+ files_per_second_message = ngettext ("(%d file/sec)",
+ "(%d files/sec)",
+ (int) transfer_rate);
+ concat_detail = g_strconcat (time_left_message, " ", files_per_second_message, NULL);
+
+ details = f (concat_detail,
+ transfer_info->num_files + 1, source_info->num_files,
+ remaining_time,
+ (int) transfer_rate);
+
+ g_free (concat_detail);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files,
+ source_info->num_files);
+ }
+ }
+ nautilus_progress_info_set_details (job->progress, details);
+
+ if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE)
+ {
+ nautilus_progress_info_set_remaining_time (job->progress,
+ remaining_time);
+ nautilus_progress_info_set_elapsed_time (job->progress,
+ elapsed);
+ }
+
+ if (source_info->num_files != 0)
+ {
+ nautilus_progress_info_set_progress (job->progress, transfer_info->num_files, source_info->num_files);
+ }
}
-typedef void (*DeleteCallback) (GFile *file,
- GError *error,
- gpointer callback_data);
+typedef void (*DeleteCallback) (GFile *file,
+ GError *error,
+ gpointer callback_data);
static gboolean
delete_file_recursively (GFile *file,
@@ -1649,68 +1862,76 @@ delete_file_recursively (GFile *file,
DeleteCallback callback,
gpointer callback_data)
{
- gboolean success;
- g_autoptr (GError) error = NULL;
+ gboolean success;
+ g_autoptr (GError) error = NULL;
- do {
- g_autoptr (GFileEnumerator) enumerator = NULL;
+ do
+ {
+ g_autoptr (GFileEnumerator) enumerator = NULL;
- success = g_file_delete (file, cancellable, &error);
- if (success ||
- !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_EMPTY)) {
- break;
- }
-
- g_clear_error (&error);
+ success = g_file_delete (file, cancellable, &error);
+ if (success ||
+ !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_EMPTY))
+ {
+ break;
+ }
- enumerator = g_file_enumerate_children (file,
- G_FILE_ATTRIBUTE_STANDARD_NAME,
- G_FILE_QUERY_INFO_NONE,
- cancellable, &error);
+ g_clear_error (&error);
- if (enumerator) {
- GFileInfo *info;
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable, &error);
- success = TRUE;
+ if (enumerator)
+ {
+ GFileInfo *info;
- info = g_file_enumerator_next_file (enumerator,
- cancellable,
- &error);
+ success = TRUE;
- while (info != NULL) {
- g_autoptr (GFile) child;
+ info = g_file_enumerator_next_file (enumerator,
+ cancellable,
+ &error);
- child = g_file_enumerator_get_child (enumerator, info);
+ while (info != NULL)
+ {
+ g_autoptr (GFile) child;
- success = success && delete_file_recursively (child,
- cancellable,
- callback,
- callback_data);
+ child = g_file_enumerator_get_child (enumerator, info);
- g_object_unref (info);
+ success = success && delete_file_recursively (child,
+ cancellable,
+ callback,
+ callback_data);
- info = g_file_enumerator_next_file (enumerator,
- cancellable,
- &error);
- }
- }
+ g_object_unref (info);
- if (error != NULL) {
- success = FALSE;
- }
- } while (success);
+ info = g_file_enumerator_next_file (enumerator,
+ cancellable,
+ &error);
+ }
+ }
- if (callback) {
- callback (file, error, callback_data);
+ if (error != NULL)
+ {
+ success = FALSE;
}
+ }
+ while (success);
- return success;
+ if (callback)
+ {
+ callback (file, error, callback_data);
+ }
+
+ return success;
}
-typedef struct {
- CommonJob *job;
- SourceInfo *source_info;
- TransferInfo *transfer_info;
+typedef struct
+{
+ CommonJob *job;
+ SourceInfo *source_info;
+ TransferInfo *transfer_info;
} DeleteData;
static void
@@ -1718,123 +1939,138 @@ file_deleted_callback (GFile *file,
GError *error,
gpointer callback_data)
{
- DeleteData *data = callback_data;
- CommonJob *job;
- SourceInfo *source_info;
- TransferInfo *transfer_info;
- GFileType file_type;
- char *primary;
- char *secondary;
- char *details = NULL;
- int response;
+ DeleteData *data = callback_data;
+ CommonJob *job;
+ SourceInfo *source_info;
+ TransferInfo *transfer_info;
+ GFileType file_type;
+ char *primary;
+ char *secondary;
+ char *details = NULL;
+ int response;
- job = data->job;
- source_info = data->source_info;
- transfer_info = data->transfer_info;
+ job = data->job;
+ source_info = data->source_info;
+ transfer_info = data->transfer_info;
- data->transfer_info->num_files++;
+ data->transfer_info->num_files++;
- if (error == NULL) {
- nautilus_file_changes_queue_file_removed (file);
- report_delete_progress (data->job, data->source_info, data->transfer_info);
+ if (error == NULL)
+ {
+ nautilus_file_changes_queue_file_removed (file);
+ report_delete_progress (data->job, data->source_info, data->transfer_info);
- return;
- }
+ return;
+ }
- if (job_aborted (job) ||
- job->skip_all_error ||
- should_skip_file (job, file) ||
- should_skip_readdir_error (job, file)) {
- return;
- }
+ if (job_aborted (job) ||
+ job->skip_all_error ||
+ should_skip_file (job, file) ||
+ should_skip_readdir_error (job, file))
+ {
+ return;
+ }
- primary = f (_("Error while deleting."));
+ primary = f (_("Error while deleting."));
- file_type = g_file_query_file_type (file,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable);
-
- if (file_type == G_FILE_TYPE_DIRECTORY) {
- secondary = IS_IO_ERROR (error, PERMISSION_DENIED) ?
- f (_("There was an error deleting the folder “%B”."),
- file) :
- f (_("You do not have sufficient permissions to delete the folder “%B”."),
- file);
- } else {
- secondary = IS_IO_ERROR (error, PERMISSION_DENIED) ?
- f (_("There was an error deleting the file “%B”."),
- file) :
- f (_("You do not have sufficient permissions to delete the file “%B”."),
- file);
- }
+ file_type = g_file_query_file_type (file,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ job->cancellable);
- details = error->message;
+ if (file_type == G_FILE_TYPE_DIRECTORY)
+ {
+ secondary = IS_IO_ERROR (error, PERMISSION_DENIED) ?
+ f (_("There was an error deleting the folder “%B”."),
+ file) :
+ f (_("You do not have sufficient permissions to delete the folder “%B”."),
+ file);
+ }
+ else
+ {
+ secondary = IS_IO_ERROR (error, PERMISSION_DENIED) ?
+ f (_("There was an error deleting the file “%B”."),
+ file) :
+ f (_("You do not have sufficient permissions to delete the file “%B”."),
+ file);
+ }
- response = run_cancel_or_skip_warning (job,
- primary,
- secondary,
- details,
- source_info->num_files,
- source_info->num_files - transfer_info->num_files);
+ details = error->message;
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) {
- /* skip all */
- job->skip_all_error = TRUE;
- }
+ response = run_cancel_or_skip_warning (job,
+ primary,
+ secondary,
+ details,
+ source_info->num_files,
+ source_info->num_files - transfer_info->num_files);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ /* skip all */
+ job->skip_all_error = TRUE;
+ }
}
static void
-delete_files (CommonJob *job, GList *files, int *files_skipped)
-{
- GList *l;
- GFile *file;
- SourceInfo source_info;
- TransferInfo transfer_info;
- DeleteData data;
-
- if (job_aborted (job)) {
- return;
- }
-
- scan_sources (files,
- &source_info,
- job,
- OP_KIND_DELETE);
- if (job_aborted (job)) {
- return;
- }
-
- g_timer_start (job->time);
-
- memset (&transfer_info, 0, sizeof (transfer_info));
- report_delete_progress (job, &source_info, &transfer_info);
+delete_files (CommonJob *job,
+ GList *files,
+ int *files_skipped)
+{
+ GList *l;
+ GFile *file;
+ SourceInfo source_info;
+ TransferInfo transfer_info;
+ DeleteData data;
+
+ if (job_aborted (job))
+ {
+ return;
+ }
- data.job = job;
- data.source_info = &source_info;
- data.transfer_info = &transfer_info;
-
- for (l = files;
- l != NULL && !job_aborted (job);
- l = l->next) {
- gboolean success;
-
- file = l->data;
-
- if (should_skip_file (job, file)) {
- (*files_skipped)++;
- continue;
- }
+ scan_sources (files,
+ &source_info,
+ job,
+ OP_KIND_DELETE);
+ if (job_aborted (job))
+ {
+ return;
+ }
- success = delete_file_recursively (file, job->cancellable,
- file_deleted_callback,
- &data);
+ g_timer_start (job->time);
- if (!success) {
- (*files_skipped)++;
- }
- }
+ memset (&transfer_info, 0, sizeof (transfer_info));
+ report_delete_progress (job, &source_info, &transfer_info);
+
+ data.job = job;
+ data.source_info = &source_info;
+ data.transfer_info = &transfer_info;
+
+ for (l = files;
+ l != NULL && !job_aborted (job);
+ l = l->next)
+ {
+ gboolean success;
+
+ file = l->data;
+
+ if (should_skip_file (job, file))
+ {
+ (*files_skipped)++;
+ continue;
+ }
+
+ success = delete_file_recursively (file, job->cancellable,
+ file_deleted_callback,
+ &data);
+
+ if (!success)
+ {
+ (*files_skipped)++;
+ }
+ }
}
static void
@@ -1842,208 +2078,249 @@ report_trash_progress (CommonJob *job,
SourceInfo *source_info,
TransferInfo *transfer_info)
{
- int files_left;
- double elapsed, transfer_rate;
- int remaining_time;
- gint64 now;
- char *details;
- char *status;
- DeleteJob *delete_job;
-
- delete_job = (DeleteJob *) job;
- now = g_get_monotonic_time ();
- files_left = source_info->num_files - transfer_info->num_files;
-
- /* Races and whatnot could cause this to be negative... */
- if (files_left < 0) {
- files_left = 0;
- }
-
- /* If the number of files left is 0, we want to update the status without
- * considering this time, since we want to change the status to completed
- * and probably we won't get more calls to this function */
- if (transfer_info->last_report_time != 0 &&
- ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC &&
- files_left > 0) {
- return;
- }
-
- transfer_info->last_report_time = now;
-
- if (source_info->num_files == 1) {
- if (files_left > 0) {
- status = _("Trashing “%B”");
- } else {
- status = _("Trashed “%B”");
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- (GFile*) delete_job->files->data));
-
- } else {
- if (files_left > 0) {
- status = ngettext ("Trashing %'d file",
- "Trashing %'d files",
- source_info->num_files);
- } else {
- status = ngettext ("Trashed %'d file",
- "Trashed %'d files",
- source_info->num_files);
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- source_info->num_files));
- }
-
-
- elapsed = g_timer_elapsed (job->time, NULL);
- transfer_rate = 0;
- remaining_time = INT_MAX;
- if (elapsed > 0) {
- transfer_rate = transfer_info->num_files / elapsed;
- if (transfer_rate > 0)
- remaining_time = (source_info->num_files - transfer_info->num_files) / transfer_rate;
- }
-
- if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE) {
- if (files_left > 0) {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files + 1,
- source_info->num_files);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files,
- source_info->num_files);
- }
- } else {
- if (files_left > 0) {
- gchar *time_left_message;
- gchar *files_per_second_message;
- gchar *concat_detail;
-
- /* To translators: %T will expand to a time duration like "2 minutes".
- * So the whole thing will be something like "1 / 5 -- 2 hours left (4 files/sec)"
- *
- * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
- */
- time_left_message = ngettext ("%'d / %'d \xE2\x80\x94 %T left",
- "%'d / %'d \xE2\x80\x94 %T left",
- seconds_count_format_time_units (remaining_time));
- files_per_second_message = ngettext ("(%d file/sec)",
- "(%d files/sec)",
- (int)(transfer_rate + 0.5));
- concat_detail = g_strconcat (time_left_message, " ", files_per_second_message, NULL);
-
- details = f (concat_detail,
- transfer_info->num_files + 1, source_info->num_files,
- remaining_time,
- (int) transfer_rate + 0.5);
-
- g_free (concat_detail);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files,
- source_info->num_files);
- }
- }
- nautilus_progress_info_set_details (job->progress, details);
+ int files_left;
+ double elapsed, transfer_rate;
+ int remaining_time;
+ gint64 now;
+ char *details;
+ char *status;
+ DeleteJob *delete_job;
+
+ delete_job = (DeleteJob *) job;
+ now = g_get_monotonic_time ();
+ files_left = source_info->num_files - transfer_info->num_files;
+
+ /* Races and whatnot could cause this to be negative... */
+ if (files_left < 0)
+ {
+ files_left = 0;
+ }
+
+ /* If the number of files left is 0, we want to update the status without
+ * considering this time, since we want to change the status to completed
+ * and probably we won't get more calls to this function */
+ if (transfer_info->last_report_time != 0 &&
+ ABS ((gint64) (transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC &&
+ files_left > 0)
+ {
+ return;
+ }
+
+ transfer_info->last_report_time = now;
- if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE) {
- nautilus_progress_info_set_remaining_time (job->progress,
- remaining_time);
- nautilus_progress_info_set_elapsed_time (job->progress,
- elapsed);
+ if (source_info->num_files == 1)
+ {
+ if (files_left > 0)
+ {
+ status = _("Trashing “%B”");
+ }
+ else
+ {
+ status = _("Trashed “%B”");
}
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ (GFile *) delete_job->files->data));
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ status = ngettext ("Trashing %'d file",
+ "Trashing %'d files",
+ source_info->num_files);
+ }
+ else
+ {
+ status = ngettext ("Trashed %'d file",
+ "Trashed %'d files",
+ source_info->num_files);
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ source_info->num_files));
+ }
+
- if (source_info->num_files != 0) {
- nautilus_progress_info_set_progress (job->progress, transfer_info->num_files, source_info->num_files);
- }
+ elapsed = g_timer_elapsed (job->time, NULL);
+ transfer_rate = 0;
+ remaining_time = INT_MAX;
+ if (elapsed > 0)
+ {
+ transfer_rate = transfer_info->num_files / elapsed;
+ if (transfer_rate > 0)
+ {
+ remaining_time = (source_info->num_files - transfer_info->num_files) / transfer_rate;
+ }
+ }
+
+ if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE)
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files + 1,
+ source_info->num_files);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files,
+ source_info->num_files);
+ }
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ gchar *time_left_message;
+ gchar *files_per_second_message;
+ gchar *concat_detail;
+
+ /* To translators: %T will expand to a time duration like "2 minutes".
+ * So the whole thing will be something like "1 / 5 -- 2 hours left (4 files/sec)"
+ *
+ * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
+ */
+ time_left_message = ngettext ("%'d / %'d \xE2\x80\x94 %T left",
+ "%'d / %'d \xE2\x80\x94 %T left",
+ seconds_count_format_time_units (remaining_time));
+ files_per_second_message = ngettext ("(%d file/sec)",
+ "(%d files/sec)",
+ (int) (transfer_rate + 0.5));
+ concat_detail = g_strconcat (time_left_message, " ", files_per_second_message, NULL);
+
+ details = f (concat_detail,
+ transfer_info->num_files + 1, source_info->num_files,
+ remaining_time,
+ (int) transfer_rate + 0.5);
+
+ g_free (concat_detail);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files,
+ source_info->num_files);
+ }
+ }
+ nautilus_progress_info_set_details (job->progress, details);
+
+ if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE)
+ {
+ nautilus_progress_info_set_remaining_time (job->progress,
+ remaining_time);
+ nautilus_progress_info_set_elapsed_time (job->progress,
+ elapsed);
+ }
+
+ if (source_info->num_files != 0)
+ {
+ nautilus_progress_info_set_progress (job->progress, transfer_info->num_files, source_info->num_files);
+ }
}
static void
-trash_file (CommonJob *job,
- GFile *file,
- gboolean *skipped_file,
- SourceInfo *source_info,
- TransferInfo *transfer_info,
- gboolean toplevel,
- GList **to_delete)
-{
- GError *error;
- char *primary, *secondary, *details;
- int response;
+trash_file (CommonJob *job,
+ GFile *file,
+ gboolean *skipped_file,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info,
+ gboolean toplevel,
+ GList **to_delete)
+{
+ GError *error;
+ char *primary, *secondary, *details;
+ int response;
+
+ if (should_skip_file (job, file))
+ {
+ *skipped_file = TRUE;
+ return;
+ }
- if (should_skip_file (job, file)) {
- *skipped_file = TRUE;
- return;
- }
+ error = NULL;
- error = NULL;
+ if (g_file_trash (file, job->cancellable, &error))
+ {
+ transfer_info->num_files++;
+ nautilus_file_changes_queue_file_removed (file);
- if (g_file_trash (file, job->cancellable, &error)) {
- transfer_info->num_files ++;
- nautilus_file_changes_queue_file_removed (file);
+ if (job->undo_info != NULL)
+ {
+ nautilus_file_undo_info_trash_add_file (NAUTILUS_FILE_UNDO_INFO_TRASH (job->undo_info), file);
+ }
- if (job->undo_info != NULL) {
- nautilus_file_undo_info_trash_add_file (NAUTILUS_FILE_UNDO_INFO_TRASH (job->undo_info), file);
- }
+ report_trash_progress (job, source_info, transfer_info);
+ return;
+ }
- report_trash_progress (job, source_info, transfer_info);
- return;
- }
-
- if (job->skip_all_error) {
- *skipped_file = TRUE;
- goto skip;
- }
-
- if (job->delete_all) {
- *to_delete = g_list_prepend (*to_delete, file);
- goto skip;
- }
-
- /* Translators: %B is a file name */
- primary = f (_("“%B” can't be put in the trash. Do you want to delete it immediately?"), file);
- details = NULL;
- secondary = NULL;
- if (!IS_IO_ERROR (error, NOT_SUPPORTED)) {
- details = error->message;
- } else if (!g_file_is_native (file)) {
- secondary = f (_("This remote location does not support sending items to the trash."));
- }
-
- response = run_question (job,
- primary,
- secondary,
- details,
- (source_info->num_files - transfer_info->num_files) > 1,
- CANCEL, SKIP_ALL, SKIP, DELETE_ALL, DELETE,
- NULL);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- ((DeleteJob *) job)->user_cancel = TRUE;
- abort_job (job);
- } else if (response == 1) { /* skip all */
- *skipped_file = TRUE;
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- *skipped_file = TRUE;
- job->skip_all_error = TRUE;
- } else if (response == 3) { /* delete all */
- *to_delete = g_list_prepend (*to_delete, file);
- job->delete_all = TRUE;
- } else if (response == 4) { /* delete */
- *to_delete = g_list_prepend (*to_delete, file);
- }
+ if (job->skip_all_error)
+ {
+ *skipped_file = TRUE;
+ goto skip;
+ }
+
+ if (job->delete_all)
+ {
+ *to_delete = g_list_prepend (*to_delete, file);
+ goto skip;
+ }
+
+ /* Translators: %B is a file name */
+ primary = f (_("“%B” can't be put in the trash. Do you want to delete it immediately?"), file);
+ details = NULL;
+ secondary = NULL;
+ if (!IS_IO_ERROR (error, NOT_SUPPORTED))
+ {
+ details = error->message;
+ }
+ else if (!g_file_is_native (file))
+ {
+ secondary = f (_("This remote location does not support sending items to the trash."));
+ }
+
+ response = run_question (job,
+ primary,
+ secondary,
+ details,
+ (source_info->num_files - transfer_info->num_files) > 1,
+ CANCEL, SKIP_ALL, SKIP, DELETE_ALL, DELETE,
+ NULL);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ ((DeleteJob *) job)->user_cancel = TRUE;
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ *skipped_file = TRUE;
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ {
+ *skipped_file = TRUE;
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 3) /* delete all */
+ {
+ *to_delete = g_list_prepend (*to_delete, file);
+ job->delete_all = TRUE;
+ }
+ else if (response == 4) /* delete */
+ {
+ *to_delete = g_list_prepend (*to_delete, file);
+ }
skip:
- g_error_free (error);
+ g_error_free (error);
}
static void
@@ -2053,7 +2330,8 @@ transfer_add_file_to_count (GFile *file,
{
g_autoptr (GFileInfo) file_info = NULL;
- if (g_cancellable_is_cancelled (job->cancellable)) {
+ if (g_cancellable_is_cancelled (job->cancellable))
+ {
return;
}
@@ -2064,7 +2342,8 @@ transfer_add_file_to_count (GFile *file,
NULL);
transfer_info->num_files++;
- if (file_info != NULL) {
+ if (file_info != NULL)
+ {
transfer_info->num_bytes += g_file_info_get_size (file_info);
}
}
@@ -2074,1847 +2353,2154 @@ trash_files (CommonJob *job,
GList *files,
int *files_skipped)
{
- GList *l;
- GFile *file;
- GList *to_delete;
- SourceInfo source_info;
- TransferInfo transfer_info;
- gboolean skipped_file;
-
- if (job_aborted (job)) {
- return;
- }
-
- scan_sources (files,
- &source_info,
- job,
- OP_KIND_TRASH);
- if (job_aborted (job)) {
- return;
- }
-
- g_timer_start (job->time);
-
- memset (&transfer_info, 0, sizeof (transfer_info));
- report_trash_progress (job, &source_info, &transfer_info);
-
- to_delete = NULL;
- for (l = files;
- l != NULL && !job_aborted (job);
- l = l->next) {
- file = l->data;
-
- skipped_file = FALSE;
- trash_file (job, file,
- &skipped_file,
- &source_info, &transfer_info,
- TRUE, &to_delete);
- if (skipped_file) {
- (*files_skipped)++;
- transfer_add_file_to_count (file, job, &transfer_info);
- report_trash_progress (job, &source_info, &transfer_info);
-
- }
- }
-
- if (to_delete) {
- to_delete = g_list_reverse (to_delete);
- delete_files (job, to_delete, files_skipped);
- g_list_free (to_delete);
- }
+ GList *l;
+ GFile *file;
+ GList *to_delete;
+ SourceInfo source_info;
+ TransferInfo transfer_info;
+ gboolean skipped_file;
+
+ if (job_aborted (job))
+ {
+ return;
+ }
+
+ scan_sources (files,
+ &source_info,
+ job,
+ OP_KIND_TRASH);
+ if (job_aborted (job))
+ {
+ return;
+ }
+
+ g_timer_start (job->time);
+
+ memset (&transfer_info, 0, sizeof (transfer_info));
+ report_trash_progress (job, &source_info, &transfer_info);
+
+ to_delete = NULL;
+ for (l = files;
+ l != NULL && !job_aborted (job);
+ l = l->next)
+ {
+ file = l->data;
+
+ skipped_file = FALSE;
+ trash_file (job, file,
+ &skipped_file,
+ &source_info, &transfer_info,
+ TRUE, &to_delete);
+ if (skipped_file)
+ {
+ (*files_skipped)++;
+ transfer_add_file_to_count (file, job, &transfer_info);
+ report_trash_progress (job, &source_info, &transfer_info);
+ }
+ }
+
+ if (to_delete)
+ {
+ to_delete = g_list_reverse (to_delete);
+ delete_files (job, to_delete, files_skipped);
+ g_list_free (to_delete);
+ }
}
static void
-delete_task_done (GObject *source_object,
+delete_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- DeleteJob *job;
- GHashTable *debuting_uris;
+ DeleteJob *job;
+ GHashTable *debuting_uris;
- job = user_data;
+ job = user_data;
- g_list_free_full (job->files, g_object_unref);
+ g_list_free_full (job->files, g_object_unref);
- if (job->done_callback) {
- debuting_uris = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
- job->done_callback (debuting_uris, job->user_cancel, job->done_callback_data);
- g_hash_table_unref (debuting_uris);
- }
-
- finalize_common ((CommonJob *)job);
+ if (job->done_callback)
+ {
+ debuting_uris = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+ job->done_callback (debuting_uris, job->user_cancel, job->done_callback_data);
+ g_hash_table_unref (debuting_uris);
+ }
+
+ finalize_common ((CommonJob *) job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
static void
-delete_task_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+delete_task_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- DeleteJob *job = task_data;
- GList *to_trash_files;
- GList *to_delete_files;
- GList *l;
- GFile *file;
- gboolean confirmed;
- CommonJob *common;
- gboolean must_confirm_delete_in_trash;
- gboolean must_confirm_delete;
- int files_skipped;
-
- common = (CommonJob *)job;
-
- nautilus_progress_info_start (job->common.progress);
-
- to_trash_files = NULL;
- to_delete_files = NULL;
-
- must_confirm_delete_in_trash = FALSE;
- must_confirm_delete = FALSE;
- files_skipped = 0;
-
- for (l = job->files; l != NULL; l = l->next) {
- file = l->data;
-
- if (job->try_trash &&
- g_file_has_uri_scheme (file, "trash")) {
- must_confirm_delete_in_trash = TRUE;
- to_delete_files = g_list_prepend (to_delete_files, file);
- } else if (can_delete_without_confirm (file)) {
- to_delete_files = g_list_prepend (to_delete_files, file);
- } else {
- if (job->try_trash) {
- to_trash_files = g_list_prepend (to_trash_files, file);
- } else {
- must_confirm_delete = TRUE;
- to_delete_files = g_list_prepend (to_delete_files, file);
- }
- }
- }
-
- if (to_delete_files != NULL) {
- to_delete_files = g_list_reverse (to_delete_files);
- confirmed = TRUE;
- if (must_confirm_delete_in_trash) {
- confirmed = confirm_delete_from_trash (common, to_delete_files);
- } else if (must_confirm_delete) {
- confirmed = confirm_delete_directly (common, to_delete_files);
- }
- if (confirmed) {
- delete_files (common, to_delete_files, &files_skipped);
- } else {
- job->user_cancel = TRUE;
- }
- }
-
- if (to_trash_files != NULL) {
- to_trash_files = g_list_reverse (to_trash_files);
-
- trash_files (common, to_trash_files, &files_skipped);
- }
-
- g_list_free (to_trash_files);
- g_list_free (to_delete_files);
-
- if (files_skipped == g_list_length (job->files)) {
- /* User has skipped all files, report user cancel */
- job->user_cancel = TRUE;
- }
+ DeleteJob *job = task_data;
+ GList *to_trash_files;
+ GList *to_delete_files;
+ GList *l;
+ GFile *file;
+ gboolean confirmed;
+ CommonJob *common;
+ gboolean must_confirm_delete_in_trash;
+ gboolean must_confirm_delete;
+ int files_skipped;
+
+ common = (CommonJob *) job;
+
+ nautilus_progress_info_start (job->common.progress);
+
+ to_trash_files = NULL;
+ to_delete_files = NULL;
+
+ must_confirm_delete_in_trash = FALSE;
+ must_confirm_delete = FALSE;
+ files_skipped = 0;
+
+ for (l = job->files; l != NULL; l = l->next)
+ {
+ file = l->data;
+
+ if (job->try_trash &&
+ g_file_has_uri_scheme (file, "trash"))
+ {
+ must_confirm_delete_in_trash = TRUE;
+ to_delete_files = g_list_prepend (to_delete_files, file);
+ }
+ else if (can_delete_without_confirm (file))
+ {
+ to_delete_files = g_list_prepend (to_delete_files, file);
+ }
+ else
+ {
+ if (job->try_trash)
+ {
+ to_trash_files = g_list_prepend (to_trash_files, file);
+ }
+ else
+ {
+ must_confirm_delete = TRUE;
+ to_delete_files = g_list_prepend (to_delete_files, file);
+ }
+ }
+ }
+
+ if (to_delete_files != NULL)
+ {
+ to_delete_files = g_list_reverse (to_delete_files);
+ confirmed = TRUE;
+ if (must_confirm_delete_in_trash)
+ {
+ confirmed = confirm_delete_from_trash (common, to_delete_files);
+ }
+ else if (must_confirm_delete)
+ {
+ confirmed = confirm_delete_directly (common, to_delete_files);
+ }
+ if (confirmed)
+ {
+ delete_files (common, to_delete_files, &files_skipped);
+ }
+ else
+ {
+ job->user_cancel = TRUE;
+ }
+ }
+
+ if (to_trash_files != NULL)
+ {
+ to_trash_files = g_list_reverse (to_trash_files);
+
+ trash_files (common, to_trash_files, &files_skipped);
+ }
+
+ g_list_free (to_trash_files);
+ g_list_free (to_delete_files);
+
+ if (files_skipped == g_list_length (job->files))
+ {
+ /* User has skipped all files, report user cancel */
+ job->user_cancel = TRUE;
+ }
}
static void
trash_or_delete_internal (GList *files,
- GtkWindow *parent_window,
- gboolean try_trash,
- NautilusDeleteCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- DeleteJob *job;
-
- /* TODO: special case desktop icon link files ... */
-
- job = op_job_new (DeleteJob, parent_window);
- job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
- job->try_trash = try_trash;
- job->user_cancel = FALSE;
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
-
- if (try_trash) {
- inhibit_power_manager ((CommonJob *)job, _("Trashing Files"));
- } else {
- inhibit_power_manager ((CommonJob *)job, _("Deleting Files"));
- }
-
- if (!nautilus_file_undo_manager_is_operating () && try_trash) {
- job->common.undo_info = nautilus_file_undo_info_trash_new (g_list_length (files));
- }
-
- task = g_task_new (NULL, NULL, delete_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, delete_task_thread_func);
- g_object_unref (task);
+ GtkWindow *parent_window,
+ gboolean try_trash,
+ NautilusDeleteCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ DeleteJob *job;
+
+ /* TODO: special case desktop icon link files ... */
+
+ job = op_job_new (DeleteJob, parent_window);
+ job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
+ job->try_trash = try_trash;
+ job->user_cancel = FALSE;
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+
+ if (try_trash)
+ {
+ inhibit_power_manager ((CommonJob *) job, _("Trashing Files"));
+ }
+ else
+ {
+ inhibit_power_manager ((CommonJob *) job, _("Deleting Files"));
+ }
+
+ if (!nautilus_file_undo_manager_is_operating () && try_trash)
+ {
+ job->common.undo_info = nautilus_file_undo_info_trash_new (g_list_length (files));
+ }
+
+ task = g_task_new (NULL, NULL, delete_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, delete_task_thread_func);
+ g_object_unref (task);
}
void
nautilus_file_operations_trash_or_delete (GList *files,
- GtkWindow *parent_window,
- NautilusDeleteCallback done_callback,
- gpointer done_callback_data)
+ GtkWindow *parent_window,
+ NautilusDeleteCallback done_callback,
+ gpointer done_callback_data)
{
- trash_or_delete_internal (files, parent_window,
- TRUE,
- done_callback, done_callback_data);
+ trash_or_delete_internal (files, parent_window,
+ TRUE,
+ done_callback, done_callback_data);
}
void
-nautilus_file_operations_delete (GList *files,
- GtkWindow *parent_window,
- NautilusDeleteCallback done_callback,
- gpointer done_callback_data)
+nautilus_file_operations_delete (GList *files,
+ GtkWindow *parent_window,
+ NautilusDeleteCallback done_callback,
+ gpointer done_callback_data)
{
- trash_or_delete_internal (files, parent_window,
- FALSE,
- done_callback, done_callback_data);
+ trash_or_delete_internal (files, parent_window,
+ FALSE,
+ done_callback, done_callback_data);
}
-typedef struct {
- gboolean eject;
- GMount *mount;
- GMountOperation *mount_operation;
- GtkWindow *parent_window;
- NautilusUnmountCallback callback;
- gpointer callback_data;
+typedef struct
+{
+ gboolean eject;
+ GMount *mount;
+ GMountOperation *mount_operation;
+ GtkWindow *parent_window;
+ NautilusUnmountCallback callback;
+ gpointer callback_data;
} UnmountData;
static void
unmount_data_free (UnmountData *data)
{
- if (data->parent_window) {
- g_object_remove_weak_pointer (G_OBJECT (data->parent_window),
- (gpointer *) &data->parent_window);
- }
+ if (data->parent_window)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (data->parent_window),
+ (gpointer *) &data->parent_window);
+ }
- g_clear_object (&data->mount_operation);
- g_object_unref (data->mount);
- g_free (data);
+ g_clear_object (&data->mount_operation);
+ g_object_unref (data->mount);
+ g_free (data);
}
static void
-unmount_mount_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- UnmountData *data = user_data;
- GError *error;
- char *primary;
- gboolean unmounted;
-
- error = NULL;
- if (data->eject) {
- unmounted = g_mount_eject_with_operation_finish (G_MOUNT (source_object),
- res, &error);
- } else {
- unmounted = g_mount_unmount_with_operation_finish (G_MOUNT (source_object),
- res, &error);
- }
-
- if (! unmounted) {
- if (error->code != G_IO_ERROR_FAILED_HANDLED) {
- if (data->eject) {
- primary = f (_("Unable to eject %V"), source_object);
- } else {
- primary = f (_("Unable to unmount %V"), source_object);
- }
- eel_show_error_dialog (primary,
- error->message,
- data->parent_window);
- g_free (primary);
- }
- }
-
- if (data->callback) {
- data->callback (data->callback_data);
- }
-
- if (error != NULL) {
- g_error_free (error);
- }
-
- unmount_data_free (data);
+unmount_mount_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ UnmountData *data = user_data;
+ GError *error;
+ char *primary;
+ gboolean unmounted;
+
+ error = NULL;
+ if (data->eject)
+ {
+ unmounted = g_mount_eject_with_operation_finish (G_MOUNT (source_object),
+ res, &error);
+ }
+ else
+ {
+ unmounted = g_mount_unmount_with_operation_finish (G_MOUNT (source_object),
+ res, &error);
+ }
+
+ if (!unmounted)
+ {
+ if (error->code != G_IO_ERROR_FAILED_HANDLED)
+ {
+ if (data->eject)
+ {
+ primary = f (_("Unable to eject %V"), source_object);
+ }
+ else
+ {
+ primary = f (_("Unable to unmount %V"), source_object);
+ }
+ eel_show_error_dialog (primary,
+ error->message,
+ data->parent_window);
+ g_free (primary);
+ }
+ }
+
+ if (data->callback)
+ {
+ data->callback (data->callback_data);
+ }
+
+ if (error != NULL)
+ {
+ g_error_free (error);
+ }
+
+ unmount_data_free (data);
}
static void
do_unmount (UnmountData *data)
{
- GMountOperation *mount_op;
-
- if (data->mount_operation) {
- mount_op = g_object_ref (data->mount_operation);
- } else {
- mount_op = gtk_mount_operation_new (data->parent_window);
- }
- if (data->eject) {
- g_mount_eject_with_operation (data->mount,
- 0,
- mount_op,
- NULL,
- unmount_mount_callback,
- data);
- } else {
- g_mount_unmount_with_operation (data->mount,
- 0,
- mount_op,
- NULL,
- unmount_mount_callback,
- data);
- }
- g_object_unref (mount_op);
+ GMountOperation *mount_op;
+
+ if (data->mount_operation)
+ {
+ mount_op = g_object_ref (data->mount_operation);
+ }
+ else
+ {
+ mount_op = gtk_mount_operation_new (data->parent_window);
+ }
+ if (data->eject)
+ {
+ g_mount_eject_with_operation (data->mount,
+ 0,
+ mount_op,
+ NULL,
+ unmount_mount_callback,
+ data);
+ }
+ else
+ {
+ g_mount_unmount_with_operation (data->mount,
+ 0,
+ mount_op,
+ NULL,
+ unmount_mount_callback,
+ data);
+ }
+ g_object_unref (mount_op);
}
static gboolean
dir_has_files (GFile *dir)
{
- GFileEnumerator *enumerator;
- gboolean res;
- GFileInfo *file_info;
-
- res = FALSE;
-
- enumerator = g_file_enumerate_children (dir,
- G_FILE_ATTRIBUTE_STANDARD_NAME,
- 0,
- NULL, NULL);
- if (enumerator) {
- file_info = g_file_enumerator_next_file (enumerator, NULL, NULL);
- if (file_info != NULL) {
- res = TRUE;
- g_object_unref (file_info);
- }
-
- g_file_enumerator_close (enumerator, NULL, NULL);
- g_object_unref (enumerator);
- }
-
-
- return res;
+ GFileEnumerator *enumerator;
+ gboolean res;
+ GFileInfo *file_info;
+
+ res = FALSE;
+
+ enumerator = g_file_enumerate_children (dir,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ 0,
+ NULL, NULL);
+ if (enumerator)
+ {
+ file_info = g_file_enumerator_next_file (enumerator, NULL, NULL);
+ if (file_info != NULL)
+ {
+ res = TRUE;
+ g_object_unref (file_info);
+ }
+
+ g_file_enumerator_close (enumerator, NULL, NULL);
+ g_object_unref (enumerator);
+ }
+
+
+ return res;
}
static GList *
get_trash_dirs_for_mount (GMount *mount)
{
- GFile *root;
- GFile *trash;
- char *relpath;
- GList *list;
-
- root = g_mount_get_root (mount);
- if (root == NULL) {
- return NULL;
- }
-
- list = NULL;
-
- if (g_file_is_native (root)) {
- relpath = g_strdup_printf (".Trash/%d", getuid ());
- trash = g_file_resolve_relative_path (root, relpath);
- g_free (relpath);
-
- list = g_list_prepend (list, g_file_get_child (trash, "files"));
- list = g_list_prepend (list, g_file_get_child (trash, "info"));
-
- g_object_unref (trash);
-
- relpath = g_strdup_printf (".Trash-%d", getuid ());
- trash = g_file_get_child (root, relpath);
- g_free (relpath);
-
- list = g_list_prepend (list, g_file_get_child (trash, "files"));
- list = g_list_prepend (list, g_file_get_child (trash, "info"));
-
- g_object_unref (trash);
- }
-
- g_object_unref (root);
-
- return list;
+ GFile *root;
+ GFile *trash;
+ char *relpath;
+ GList *list;
+
+ root = g_mount_get_root (mount);
+ if (root == NULL)
+ {
+ return NULL;
+ }
+
+ list = NULL;
+
+ if (g_file_is_native (root))
+ {
+ relpath = g_strdup_printf (".Trash/%d", getuid ());
+ trash = g_file_resolve_relative_path (root, relpath);
+ g_free (relpath);
+
+ list = g_list_prepend (list, g_file_get_child (trash, "files"));
+ list = g_list_prepend (list, g_file_get_child (trash, "info"));
+
+ g_object_unref (trash);
+
+ relpath = g_strdup_printf (".Trash-%d", getuid ());
+ trash = g_file_get_child (root, relpath);
+ g_free (relpath);
+
+ list = g_list_prepend (list, g_file_get_child (trash, "files"));
+ list = g_list_prepend (list, g_file_get_child (trash, "info"));
+
+ g_object_unref (trash);
+ }
+
+ g_object_unref (root);
+
+ return list;
}
static gboolean
has_trash_files (GMount *mount)
{
- GList *dirs, *l;
- GFile *dir;
- gboolean res;
+ GList *dirs, *l;
+ GFile *dir;
+ gboolean res;
- dirs = get_trash_dirs_for_mount (mount);
+ dirs = get_trash_dirs_for_mount (mount);
- res = FALSE;
+ res = FALSE;
- for (l = dirs; l != NULL; l = l->next) {
- dir = l->data;
+ for (l = dirs; l != NULL; l = l->next)
+ {
+ dir = l->data;
+
+ if (dir_has_files (dir))
+ {
+ res = TRUE;
+ break;
+ }
+ }
- if (dir_has_files (dir)) {
- res = TRUE;
- break;
- }
- }
+ g_list_free_full (dirs, g_object_unref);
- g_list_free_full (dirs, g_object_unref);
-
- return res;
+ return res;
}
static gint
prompt_empty_trash (GtkWindow *parent_window)
{
- gint result;
- GtkWidget *dialog;
- GdkScreen *screen;
-
- screen = NULL;
- if (parent_window != NULL) {
- screen = gtk_widget_get_screen (GTK_WIDGET (parent_window));
- }
-
- /* Do we need to be modal ? */
- dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
- GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
- _("Do you want to empty the trash before you unmount?"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("In order to regain the "
- "free space on this volume "
- "the trash must be emptied. "
- "All trashed items on the volume "
- "will be permanently lost."));
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- _("Do _not Empty Trash"), GTK_RESPONSE_REJECT,
- CANCEL, GTK_RESPONSE_CANCEL,
- _("Empty _Trash"), GTK_RESPONSE_ACCEPT, NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
- gtk_window_set_title (GTK_WINDOW (dialog), ""); /* as per HIG */
- gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
- if (screen) {
- gtk_window_set_screen (GTK_WINDOW (dialog), screen);
- }
- atk_object_set_role (gtk_widget_get_accessible (dialog), ATK_ROLE_ALERT);
- gtk_window_set_wmclass (GTK_WINDOW (dialog), "empty_trash",
- "Nautilus");
-
- /* Make transient for the window group */
- gtk_widget_realize (dialog);
- if (screen != NULL) {
- gdk_window_set_transient_for (gtk_widget_get_window (GTK_WIDGET (dialog)),
- gdk_screen_get_root_window (screen));
- }
-
- result = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- return result;
+ gint result;
+ GtkWidget *dialog;
+ GdkScreen *screen;
+
+ screen = NULL;
+ if (parent_window != NULL)
+ {
+ screen = gtk_widget_get_screen (GTK_WIDGET (parent_window));
+ }
+
+ /* Do we need to be modal ? */
+ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
+ _("Do you want to empty the trash before you unmount?"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("In order to regain the "
+ "free space on this volume "
+ "the trash must be emptied. "
+ "All trashed items on the volume "
+ "will be permanently lost."));
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ _("Do _not Empty Trash"), GTK_RESPONSE_REJECT,
+ CANCEL, GTK_RESPONSE_CANCEL,
+ _("Empty _Trash"), GTK_RESPONSE_ACCEPT, NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+ gtk_window_set_title (GTK_WINDOW (dialog), ""); /* as per HIG */
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
+ if (screen)
+ {
+ gtk_window_set_screen (GTK_WINDOW (dialog), screen);
+ }
+ atk_object_set_role (gtk_widget_get_accessible (dialog), ATK_ROLE_ALERT);
+ gtk_window_set_wmclass (GTK_WINDOW (dialog), "empty_trash",
+ "Nautilus");
+
+ /* Make transient for the window group */
+ gtk_widget_realize (dialog);
+ if (screen != NULL)
+ {
+ gdk_window_set_transient_for (gtk_widget_get_window (GTK_WIDGET (dialog)),
+ gdk_screen_get_root_window (screen));
+ }
+
+ result = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return result;
}
static void
empty_trash_for_unmount_done (gboolean success,
- gpointer user_data)
+ gpointer user_data)
{
- UnmountData *data = user_data;
- do_unmount (data);
+ UnmountData *data = user_data;
+ do_unmount (data);
}
void
-nautilus_file_operations_unmount_mount_full (GtkWindow *parent_window,
- GMount *mount,
- GMountOperation *mount_operation,
- gboolean eject,
- gboolean check_trash,
- NautilusUnmountCallback callback,
- gpointer callback_data)
-{
- UnmountData *data;
- int response;
-
- data = g_new0 (UnmountData, 1);
- data->callback = callback;
- data->callback_data = callback_data;
- if (parent_window) {
- data->parent_window = parent_window;
- g_object_add_weak_pointer (G_OBJECT (data->parent_window),
- (gpointer *) &data->parent_window);
-
- }
- if (mount_operation) {
- data->mount_operation = g_object_ref (mount_operation);
- }
- data->eject = eject;
- data->mount = g_object_ref (mount);
-
- if (check_trash && has_trash_files (mount)) {
- response = prompt_empty_trash (parent_window);
-
- if (response == GTK_RESPONSE_ACCEPT) {
- GTask *task;
- EmptyTrashJob *job;
-
- job = op_job_new (EmptyTrashJob, parent_window);
- job->should_confirm = FALSE;
- job->trash_dirs = get_trash_dirs_for_mount (mount);
- job->done_callback = empty_trash_for_unmount_done;
- job->done_callback_data = data;
-
- task = g_task_new (NULL, NULL, empty_trash_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, empty_trash_thread_func);
- g_object_unref (task);
- return;
- } else if (response == GTK_RESPONSE_CANCEL) {
- if (callback) {
- callback (callback_data);
- }
-
- unmount_data_free (data);
- return;
- }
- }
-
- do_unmount (data);
+nautilus_file_operations_unmount_mount_full (GtkWindow *parent_window,
+ GMount *mount,
+ GMountOperation *mount_operation,
+ gboolean eject,
+ gboolean check_trash,
+ NautilusUnmountCallback callback,
+ gpointer callback_data)
+{
+ UnmountData *data;
+ int response;
+
+ data = g_new0 (UnmountData, 1);
+ data->callback = callback;
+ data->callback_data = callback_data;
+ if (parent_window)
+ {
+ data->parent_window = parent_window;
+ g_object_add_weak_pointer (G_OBJECT (data->parent_window),
+ (gpointer *) &data->parent_window);
+ }
+ if (mount_operation)
+ {
+ data->mount_operation = g_object_ref (mount_operation);
+ }
+ data->eject = eject;
+ data->mount = g_object_ref (mount);
+
+ if (check_trash && has_trash_files (mount))
+ {
+ response = prompt_empty_trash (parent_window);
+
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ GTask *task;
+ EmptyTrashJob *job;
+
+ job = op_job_new (EmptyTrashJob, parent_window);
+ job->should_confirm = FALSE;
+ job->trash_dirs = get_trash_dirs_for_mount (mount);
+ job->done_callback = empty_trash_for_unmount_done;
+ job->done_callback_data = data;
+
+ task = g_task_new (NULL, NULL, empty_trash_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, empty_trash_thread_func);
+ g_object_unref (task);
+ return;
+ }
+ else if (response == GTK_RESPONSE_CANCEL)
+ {
+ if (callback)
+ {
+ callback (callback_data);
+ }
+
+ unmount_data_free (data);
+ return;
+ }
+ }
+
+ do_unmount (data);
}
void
-nautilus_file_operations_unmount_mount (GtkWindow *parent_window,
- GMount *mount,
- gboolean eject,
- gboolean check_trash)
+nautilus_file_operations_unmount_mount (GtkWindow *parent_window,
+ GMount *mount,
+ gboolean eject,
+ gboolean check_trash)
{
- nautilus_file_operations_unmount_mount_full (parent_window, mount, NULL, eject,
- check_trash, NULL, NULL);
+ nautilus_file_operations_unmount_mount_full (parent_window, mount, NULL, eject,
+ check_trash, NULL, NULL);
}
static void
-mount_callback_data_notify (gpointer data,
- GObject *object)
+mount_callback_data_notify (gpointer data,
+ GObject *object)
{
- GMountOperation *mount_op;
+ GMountOperation *mount_op;
- mount_op = G_MOUNT_OPERATION (data);
- g_object_set_data (G_OBJECT (mount_op), "mount-callback", NULL);
- g_object_set_data (G_OBJECT (mount_op), "mount-callback-data", NULL);
+ mount_op = G_MOUNT_OPERATION (data);
+ g_object_set_data (G_OBJECT (mount_op), "mount-callback", NULL);
+ g_object_set_data (G_OBJECT (mount_op), "mount-callback-data", NULL);
}
static void
-volume_mount_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NautilusMountCallback mount_callback;
- GObject *mount_callback_data_object;
- GMountOperation *mount_op = user_data;
- GError *error;
- char *primary;
- char *name;
- gboolean success;
-
- success = TRUE;
- error = NULL;
- if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error)) {
- if (error->code != G_IO_ERROR_FAILED_HANDLED &&
- error->code != G_IO_ERROR_ALREADY_MOUNTED) {
- GtkWindow *parent;
-
- parent = gtk_mount_operation_get_parent (GTK_MOUNT_OPERATION (mount_op));
- name = g_volume_get_name (G_VOLUME (source_object));
- primary = g_strdup_printf (_("Unable to access “%s”"), name);
- g_free (name);
- success = FALSE;
- eel_show_error_dialog (primary,
- error->message,
- parent);
- g_free (primary);
- }
- g_error_free (error);
- }
-
- mount_callback = (NautilusMountCallback)
- g_object_get_data (G_OBJECT (mount_op), "mount-callback");
- mount_callback_data_object =
- g_object_get_data (G_OBJECT (mount_op), "mount-callback-data");
-
- if (mount_callback != NULL) {
- (* mount_callback) (G_VOLUME (source_object),
- success,
- mount_callback_data_object);
-
- if (mount_callback_data_object != NULL) {
- g_object_weak_unref (mount_callback_data_object,
- mount_callback_data_notify,
- mount_op);
- }
- }
-
- g_object_unref (mount_op);
+volume_mount_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NautilusMountCallback mount_callback;
+ GObject *mount_callback_data_object;
+ GMountOperation *mount_op = user_data;
+ GError *error;
+ char *primary;
+ char *name;
+ gboolean success;
+
+ success = TRUE;
+ error = NULL;
+ if (!g_volume_mount_finish (G_VOLUME (source_object), res, &error))
+ {
+ if (error->code != G_IO_ERROR_FAILED_HANDLED &&
+ error->code != G_IO_ERROR_ALREADY_MOUNTED)
+ {
+ GtkWindow *parent;
+
+ parent = gtk_mount_operation_get_parent (GTK_MOUNT_OPERATION (mount_op));
+ name = g_volume_get_name (G_VOLUME (source_object));
+ primary = g_strdup_printf (_("Unable to access “%s”"), name);
+ g_free (name);
+ success = FALSE;
+ eel_show_error_dialog (primary,
+ error->message,
+ parent);
+ g_free (primary);
+ }
+ g_error_free (error);
+ }
+
+ mount_callback = (NautilusMountCallback)
+ g_object_get_data (G_OBJECT (mount_op), "mount-callback");
+ mount_callback_data_object =
+ g_object_get_data (G_OBJECT (mount_op), "mount-callback-data");
+
+ if (mount_callback != NULL)
+ {
+ (*mount_callback)(G_VOLUME (source_object),
+ success,
+ mount_callback_data_object);
+
+ if (mount_callback_data_object != NULL)
+ {
+ g_object_weak_unref (mount_callback_data_object,
+ mount_callback_data_notify,
+ mount_op);
+ }
+ }
+
+ g_object_unref (mount_op);
}
void
nautilus_file_operations_mount_volume (GtkWindow *parent_window,
- GVolume *volume)
+ GVolume *volume)
{
- nautilus_file_operations_mount_volume_full (parent_window, volume,
- NULL, NULL);
+ nautilus_file_operations_mount_volume_full (parent_window, volume,
+ NULL, NULL);
}
void
-nautilus_file_operations_mount_volume_full (GtkWindow *parent_window,
- GVolume *volume,
- NautilusMountCallback mount_callback,
- GObject *mount_callback_data_object)
-{
- GMountOperation *mount_op;
-
- mount_op = gtk_mount_operation_new (parent_window);
- g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
- g_object_set_data (G_OBJECT (mount_op),
- "mount-callback",
- mount_callback);
-
- if (mount_callback != NULL &&
- mount_callback_data_object != NULL) {
- g_object_weak_ref (mount_callback_data_object,
- mount_callback_data_notify,
- mount_op);
- }
- g_object_set_data (G_OBJECT (mount_op),
- "mount-callback-data",
- mount_callback_data_object);
+nautilus_file_operations_mount_volume_full (GtkWindow *parent_window,
+ GVolume *volume,
+ NautilusMountCallback mount_callback,
+ GObject *mount_callback_data_object)
+{
+ GMountOperation *mount_op;
+
+ mount_op = gtk_mount_operation_new (parent_window);
+ g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
+ g_object_set_data (G_OBJECT (mount_op),
+ "mount-callback",
+ mount_callback);
+
+ if (mount_callback != NULL &&
+ mount_callback_data_object != NULL)
+ {
+ g_object_weak_ref (mount_callback_data_object,
+ mount_callback_data_notify,
+ mount_op);
+ }
+ g_object_set_data (G_OBJECT (mount_op),
+ "mount-callback-data",
+ mount_callback_data_object);
- g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, mount_op);
+ g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, mount_op);
}
static void
-report_preparing_count_progress (CommonJob *job,
+report_preparing_count_progress (CommonJob *job,
SourceInfo *source_info)
{
- char *s;
-
- switch (source_info->op) {
- default:
- case OP_KIND_COPY:
- s = f (ngettext("Preparing to copy %'d file (%S)",
- "Preparing to copy %'d files (%S)",
- source_info->num_files),
- source_info->num_files, source_info->num_bytes);
- break;
- case OP_KIND_MOVE:
- s = f (ngettext("Preparing to move %'d file (%S)",
- "Preparing to move %'d files (%S)",
- source_info->num_files),
- source_info->num_files, source_info->num_bytes);
- break;
- case OP_KIND_DELETE:
- s = f (ngettext("Preparing to delete %'d file (%S)",
- "Preparing to delete %'d files (%S)",
- source_info->num_files),
- source_info->num_files, source_info->num_bytes);
- break;
- case OP_KIND_TRASH:
- s = f (ngettext("Preparing to trash %'d file",
- "Preparing to trash %'d files",
- source_info->num_files),
- source_info->num_files);
- break;
- case OP_KIND_COMPRESS:
- s = f (ngettext("Preparing to compress %'d file",
- "Preparing to compress %'d files",
- source_info->num_files),
+ char *s;
+
+ switch (source_info->op)
+ {
+ default:
+ case OP_KIND_COPY:
+ {
+ s = f (ngettext ("Preparing to copy %'d file (%S)",
+ "Preparing to copy %'d files (%S)",
+ source_info->num_files),
+ source_info->num_files, source_info->num_bytes);
+ }
+ break;
+
+ case OP_KIND_MOVE:
+ {
+ s = f (ngettext ("Preparing to move %'d file (%S)",
+ "Preparing to move %'d files (%S)",
+ source_info->num_files),
+ source_info->num_files, source_info->num_bytes);
+ }
+ break;
+
+ case OP_KIND_DELETE:
+ {
+ s = f (ngettext ("Preparing to delete %'d file (%S)",
+ "Preparing to delete %'d files (%S)",
+ source_info->num_files),
+ source_info->num_files, source_info->num_bytes);
+ }
+ break;
+
+ case OP_KIND_TRASH:
+ {
+ s = f (ngettext ("Preparing to trash %'d file",
+ "Preparing to trash %'d files",
+ source_info->num_files),
source_info->num_files);
- }
+ }
+ break;
+
+ case OP_KIND_COMPRESS:
+ s = f (ngettext ("Preparing to compress %'d file",
+ "Preparing to compress %'d files",
+ source_info->num_files),
+ source_info->num_files);
+ }
- nautilus_progress_info_take_details (job->progress, s);
- nautilus_progress_info_pulse_progress (job->progress);
+ nautilus_progress_info_take_details (job->progress, s);
+ nautilus_progress_info_pulse_progress (job->progress);
}
static void
-count_file (GFileInfo *info,
- CommonJob *job,
- SourceInfo *source_info)
+count_file (GFileInfo *info,
+ CommonJob *job,
+ SourceInfo *source_info)
{
- source_info->num_files += 1;
- source_info->num_bytes += g_file_info_get_size (info);
+ source_info->num_files += 1;
+ source_info->num_bytes += g_file_info_get_size (info);
- if (source_info->num_files_since_progress++ > 100) {
- report_preparing_count_progress (job, source_info);
- source_info->num_files_since_progress = 0;
- }
+ if (source_info->num_files_since_progress++ > 100)
+ {
+ report_preparing_count_progress (job, source_info);
+ source_info->num_files_since_progress = 0;
+ }
}
static char *
get_scan_primary (OpKind kind)
{
- switch (kind) {
- default:
- case OP_KIND_COPY:
- return f (_("Error while copying."));
- case OP_KIND_MOVE:
- return f (_("Error while moving."));
- case OP_KIND_DELETE:
- return f (_("Error while deleting."));
- case OP_KIND_TRASH:
- return f (_("Error while moving files to trash."));
+ switch (kind)
+ {
+ default:
+ case OP_KIND_COPY:
+ {
+ return f (_("Error while copying."));
+ }
+
+ case OP_KIND_MOVE:
+ {
+ return f (_("Error while moving."));
+ }
+
+ case OP_KIND_DELETE:
+ {
+ return f (_("Error while deleting."));
+ }
+
+ case OP_KIND_TRASH:
+ {
+ return f (_("Error while moving files to trash."));
+ }
+
case OP_KIND_COMPRESS:
- return f (_("Error while compressing files."));
- }
+ return f (_("Error while compressing files."));
+ }
}
static void
-scan_dir (GFile *dir,
- SourceInfo *source_info,
- CommonJob *job,
- GQueue *dirs)
-{
- GFileInfo *info;
- GError *error;
- GFile *subdir;
- GFileEnumerator *enumerator;
- char *primary, *secondary, *details;
- int response;
- SourceInfo saved_info;
-
- saved_info = *source_info;
-
- retry:
- error = NULL;
- enumerator = g_file_enumerate_children (dir,
- G_FILE_ATTRIBUTE_STANDARD_NAME","
- G_FILE_ATTRIBUTE_STANDARD_TYPE","
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable,
- &error);
- if (enumerator) {
- error = NULL;
- while ((info = g_file_enumerator_next_file (enumerator, job->cancellable, &error)) != NULL) {
- count_file (info, job, source_info);
-
- if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
- subdir = g_file_get_child (dir,
- g_file_info_get_name (info));
-
- /* Push to head, since we want depth-first */
- g_queue_push_head (dirs, subdir);
- }
-
- g_object_unref (info);
- }
- g_file_enumerator_close (enumerator, job->cancellable, NULL);
- g_object_unref (enumerator);
-
- if (error && IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- } else if (error) {
- primary = get_scan_primary (source_info->op);
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("Files in the folder “%B” cannot be handled because you do "
- "not have permissions to see them."), dir);
- } else {
- secondary = f (_("There was an error getting information about the files in the folder “%B”."), dir);
- details = error->message;
- }
-
- response = run_warning (job,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL, RETRY, SKIP,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) {
- *source_info = saved_info;
- goto retry;
- } else if (response == 2) {
- skip_readdir_error (job, dir);
- } else {
- g_assert_not_reached ();
- }
- }
-
- } else if (job->skip_all_error) {
- g_error_free (error);
- skip_file (job, dir);
- } else if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- } else {
- primary = get_scan_primary (source_info->op);
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("The folder “%B” cannot be handled because you do not have "
- "permissions to read it."), dir);
- } else {
- secondary = f (_("There was an error reading the folder “%B”."), dir);
- details = error->message;
- }
- /* set show_all to TRUE here, as we don't know how many
- * files we'll end up processing yet.
- */
- response = run_warning (job,
- primary,
- secondary,
- details,
- TRUE,
- CANCEL, SKIP_ALL, SKIP, RETRY,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1 || response == 2) {
- if (response == 1) {
- job->skip_all_error = TRUE;
- }
- skip_file (job, dir);
- } else if (response == 3) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
- }
-}
+scan_dir (GFile *dir,
+ SourceInfo *source_info,
+ CommonJob *job,
+ GQueue *dirs)
+{
+ GFileInfo *info;
+ GError *error;
+ GFile *subdir;
+ GFileEnumerator *enumerator;
+ char *primary, *secondary, *details;
+ int response;
+ SourceInfo saved_info;
+
+ saved_info = *source_info;
+
+retry:
+ error = NULL;
+ enumerator = g_file_enumerate_children (dir,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ job->cancellable,
+ &error);
+ if (enumerator)
+ {
+ error = NULL;
+ while ((info = g_file_enumerator_next_file (enumerator, job->cancellable, &error)) != NULL)
+ {
+ count_file (info, job, source_info);
+
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ subdir = g_file_get_child (dir,
+ g_file_info_get_name (info));
+
+ /* Push to head, since we want depth-first */
+ g_queue_push_head (dirs, subdir);
+ }
+
+ g_object_unref (info);
+ }
+ g_file_enumerator_close (enumerator, job->cancellable, NULL);
+ g_object_unref (enumerator);
+
+ if (error && IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ else if (error)
+ {
+ primary = get_scan_primary (source_info->op);
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("Files in the folder “%B” cannot be handled because you do "
+ "not have permissions to see them."), dir);
+ }
+ else
+ {
+ secondary = f (_("There was an error getting information about the files in the folder “%B”."), dir);
+ details = error->message;
+ }
+
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ FALSE,
+ CANCEL, RETRY, SKIP,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ *source_info = saved_info;
+ goto retry;
+ }
+ else if (response == 2)
+ {
+ skip_readdir_error (job, dir);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ }
+ else if (job->skip_all_error)
+ {
+ g_error_free (error);
+ skip_file (job, dir);
+ }
+ else if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ else
+ {
+ primary = get_scan_primary (source_info->op);
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("The folder “%B” cannot be handled because you do not have "
+ "permissions to read it."), dir);
+ }
+ else
+ {
+ secondary = f (_("There was an error reading the folder “%B”."), dir);
+ details = error->message;
+ }
+ /* set show_all to TRUE here, as we don't know how many
+ * files we'll end up processing yet.
+ */
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ TRUE,
+ CANCEL, SKIP_ALL, SKIP, RETRY,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1 || response == 2)
+ {
+ if (response == 1)
+ {
+ job->skip_all_error = TRUE;
+ }
+ skip_file (job, dir);
+ }
+ else if (response == 3)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+}
static void
-scan_file (GFile *file,
- SourceInfo *source_info,
- CommonJob *job)
-{
- GFileInfo *info;
- GError *error;
- GQueue *dirs;
- GFile *dir;
- char *primary;
- char *secondary;
- char *details;
- int response;
-
- dirs = g_queue_new ();
-
- retry:
- error = NULL;
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE","
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable,
- &error);
-
- if (info) {
- count_file (info, job, source_info);
-
- if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
- g_queue_push_head (dirs, g_object_ref (file));
- }
-
- g_object_unref (info);
- } else if (job->skip_all_error) {
- g_error_free (error);
- skip_file (job, file);
- } else if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- } else {
- primary = get_scan_primary (source_info->op);
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("The file “%B” cannot be handled because you do not have "
- "permissions to read it."), file);
- } else {
- secondary = f (_("There was an error getting information about “%B”."), file);
- details = error->message;
- }
- /* set show_all to TRUE here, as we don't know how many
- * files we'll end up processing yet.
- */
- response = run_warning (job,
- primary,
- secondary,
- details,
- TRUE,
- CANCEL, SKIP_ALL, SKIP, RETRY,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1 || response == 2) {
- if (response == 1) {
- job->skip_all_error = TRUE;
- }
- skip_file (job, file);
- } else if (response == 3) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
- }
-
- while (!job_aborted (job) &&
- (dir = g_queue_pop_head (dirs)) != NULL) {
- scan_dir (dir, source_info, job, dirs);
- g_object_unref (dir);
- }
-
- /* Free all from queue if we exited early */
- g_queue_foreach (dirs, (GFunc)g_object_unref, NULL);
- g_queue_free (dirs);
+scan_file (GFile *file,
+ SourceInfo *source_info,
+ CommonJob *job)
+{
+ GFileInfo *info;
+ GError *error;
+ GQueue *dirs;
+ GFile *dir;
+ char *primary;
+ char *secondary;
+ char *details;
+ int response;
+
+ dirs = g_queue_new ();
+
+retry:
+ error = NULL;
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ job->cancellable,
+ &error);
+
+ if (info)
+ {
+ count_file (info, job, source_info);
+
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ g_queue_push_head (dirs, g_object_ref (file));
+ }
+
+ g_object_unref (info);
+ }
+ else if (job->skip_all_error)
+ {
+ g_error_free (error);
+ skip_file (job, file);
+ }
+ else if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ else
+ {
+ primary = get_scan_primary (source_info->op);
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("The file “%B” cannot be handled because you do not have "
+ "permissions to read it."), file);
+ }
+ else
+ {
+ secondary = f (_("There was an error getting information about “%B”."), file);
+ details = error->message;
+ }
+ /* set show_all to TRUE here, as we don't know how many
+ * files we'll end up processing yet.
+ */
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ TRUE,
+ CANCEL, SKIP_ALL, SKIP, RETRY,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1 || response == 2)
+ {
+ if (response == 1)
+ {
+ job->skip_all_error = TRUE;
+ }
+ skip_file (job, file);
+ }
+ else if (response == 3)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+
+ while (!job_aborted (job) &&
+ (dir = g_queue_pop_head (dirs)) != NULL)
+ {
+ scan_dir (dir, source_info, job, dirs);
+ g_object_unref (dir);
+ }
+
+ /* Free all from queue if we exited early */
+ g_queue_foreach (dirs, (GFunc) g_object_unref, NULL);
+ g_queue_free (dirs);
}
static void
-scan_sources (GList *files,
- SourceInfo *source_info,
- CommonJob *job,
- OpKind kind)
+scan_sources (GList *files,
+ SourceInfo *source_info,
+ CommonJob *job,
+ OpKind kind)
{
- GList *l;
- GFile *file;
+ GList *l;
+ GFile *file;
- memset (source_info, 0, sizeof (SourceInfo));
- source_info->op = kind;
+ memset (source_info, 0, sizeof (SourceInfo));
+ source_info->op = kind;
- report_preparing_count_progress (job, source_info);
-
- for (l = files; l != NULL && !job_aborted (job); l = l->next) {
- file = l->data;
+ report_preparing_count_progress (job, source_info);
- scan_file (file,
- source_info,
- job);
- }
+ for (l = files; l != NULL && !job_aborted (job); l = l->next)
+ {
+ file = l->data;
- /* Make sure we report the final count */
- report_preparing_count_progress (job, source_info);
+ scan_file (file,
+ source_info,
+ job);
+ }
+
+ /* Make sure we report the final count */
+ report_preparing_count_progress (job, source_info);
}
static void
-verify_destination (CommonJob *job,
- GFile *dest,
- char **dest_fs_id,
- goffset required_size)
-{
- GFileInfo *info, *fsinfo;
- GError *error;
- guint64 free_size;
- guint64 size_difference;
- char *primary, *secondary, *details;
- int response;
- GFileType file_type;
- gboolean dest_is_symlink = FALSE;
-
- if (dest_fs_id) {
- *dest_fs_id = NULL;
- }
-
- retry:
-
- error = NULL;
- info = g_file_query_info (dest,
- G_FILE_ATTRIBUTE_STANDARD_TYPE","
- G_FILE_ATTRIBUTE_ID_FILESYSTEM,
- dest_is_symlink ? G_FILE_QUERY_INFO_NONE : G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable,
- &error);
-
- if (info == NULL) {
- if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- return;
- }
-
- primary = f (_("Error while copying to “%B”."), dest);
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("You do not have permissions to access the destination folder."));
- } else {
- secondary = f (_("There was an error getting information about the destination."));
- details = error->message;
- }
-
- response = run_error (job,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL, RETRY,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
-
- return;
- }
-
- file_type = g_file_info_get_file_type (info);
- if (!dest_is_symlink && file_type == G_FILE_TYPE_SYMBOLIC_LINK) {
- /* Record that destination is a symlink and do real stat() once again */
- dest_is_symlink = TRUE;
- g_object_unref (info);
- goto retry;
- }
-
- if (dest_fs_id) {
- *dest_fs_id =
- g_strdup (g_file_info_get_attribute_string (info,
- G_FILE_ATTRIBUTE_ID_FILESYSTEM));
- }
-
- g_object_unref (info);
-
- if (file_type != G_FILE_TYPE_DIRECTORY) {
- primary = f (_("Error while copying to “%B”."), dest);
- secondary = f (_("The destination is not a folder."));
-
- run_error (job,
- primary,
- secondary,
- NULL,
- FALSE,
- CANCEL,
- NULL);
-
- abort_job (job);
- return;
- }
-
- if (dest_is_symlink) {
- /* We can't reliably statfs() destination if it's a symlink, thus not doing any further checks. */
- return;
- }
-
- fsinfo = g_file_query_filesystem_info (dest,
- G_FILE_ATTRIBUTE_FILESYSTEM_FREE","
- G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
- job->cancellable,
- NULL);
- if (fsinfo == NULL) {
- /* All sorts of things can go wrong getting the fs info (like not supported)
- * only check these things if the fs returns them
- */
- return;
- }
-
- if (required_size > 0 &&
- g_file_info_has_attribute (fsinfo, G_FILE_ATTRIBUTE_FILESYSTEM_FREE)) {
- free_size = g_file_info_get_attribute_uint64 (fsinfo,
- G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
-
- if (free_size < required_size) {
- size_difference = required_size - free_size;
- primary = f (_("Error while copying to “%B”."), dest);
- secondary = f (_("There is not enough space on the destination. Try to remove files to make space."));
-
- details = f (_("%S more space is required to copy to the destination."), size_difference);
-
- response = run_warning (job,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL,
- COPY_FORCE,
- RETRY,
- NULL);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 2) {
- goto retry;
- } else if (response == 1) {
- /* We are forced to copy - just fall through ... */
- } else {
- g_assert_not_reached ();
- }
- }
- }
-
- if (!job_aborted (job) &&
- g_file_info_get_attribute_boolean (fsinfo,
- G_FILE_ATTRIBUTE_FILESYSTEM_READONLY)) {
- primary = f (_("Error while copying to “%B”."), dest);
- secondary = f (_("The destination is read-only."));
-
- run_error (job,
- primary,
- secondary,
- NULL,
- FALSE,
- CANCEL,
- NULL);
-
- g_error_free (error);
-
- abort_job (job);
- }
-
- g_object_unref (fsinfo);
+verify_destination (CommonJob *job,
+ GFile *dest,
+ char **dest_fs_id,
+ goffset required_size)
+{
+ GFileInfo *info, *fsinfo;
+ GError *error;
+ guint64 free_size;
+ guint64 size_difference;
+ char *primary, *secondary, *details;
+ int response;
+ GFileType file_type;
+ gboolean dest_is_symlink = FALSE;
+
+ if (dest_fs_id)
+ {
+ *dest_fs_id = NULL;
+ }
+
+retry:
+
+ error = NULL;
+ info = g_file_query_info (dest,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_ID_FILESYSTEM,
+ dest_is_symlink ? G_FILE_QUERY_INFO_NONE : G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ job->cancellable,
+ &error);
+
+ if (info == NULL)
+ {
+ if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ return;
+ }
+
+ primary = f (_("Error while copying to “%B”."), dest);
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("You do not have permissions to access the destination folder."));
+ }
+ else
+ {
+ secondary = f (_("There was an error getting information about the destination."));
+ details = error->message;
+ }
+
+ response = run_error (job,
+ primary,
+ secondary,
+ details,
+ FALSE,
+ CANCEL, RETRY,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ return;
+ }
+
+ file_type = g_file_info_get_file_type (info);
+ if (!dest_is_symlink && file_type == G_FILE_TYPE_SYMBOLIC_LINK)
+ {
+ /* Record that destination is a symlink and do real stat() once again */
+ dest_is_symlink = TRUE;
+ g_object_unref (info);
+ goto retry;
+ }
+
+ if (dest_fs_id)
+ {
+ *dest_fs_id =
+ g_strdup (g_file_info_get_attribute_string (info,
+ G_FILE_ATTRIBUTE_ID_FILESYSTEM));
+ }
+
+ g_object_unref (info);
+
+ if (file_type != G_FILE_TYPE_DIRECTORY)
+ {
+ primary = f (_("Error while copying to “%B”."), dest);
+ secondary = f (_("The destination is not a folder."));
+
+ run_error (job,
+ primary,
+ secondary,
+ NULL,
+ FALSE,
+ CANCEL,
+ NULL);
+
+ abort_job (job);
+ return;
+ }
+
+ if (dest_is_symlink)
+ {
+ /* We can't reliably statfs() destination if it's a symlink, thus not doing any further checks. */
+ return;
+ }
+
+ fsinfo = g_file_query_filesystem_info (dest,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE ","
+ G_FILE_ATTRIBUTE_FILESYSTEM_READONLY,
+ job->cancellable,
+ NULL);
+ if (fsinfo == NULL)
+ {
+ /* All sorts of things can go wrong getting the fs info (like not supported)
+ * only check these things if the fs returns them
+ */
+ return;
+ }
+
+ if (required_size > 0 &&
+ g_file_info_has_attribute (fsinfo, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
+ {
+ free_size = g_file_info_get_attribute_uint64 (fsinfo,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+
+ if (free_size < required_size)
+ {
+ size_difference = required_size - free_size;
+ primary = f (_("Error while copying to “%B”."), dest);
+ secondary = f (_("There is not enough space on the destination. Try to remove files to make space."));
+
+ details = f (_("%S more space is required to copy to the destination."), size_difference);
+
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ FALSE,
+ CANCEL,
+ COPY_FORCE,
+ RETRY,
+ NULL);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 2)
+ {
+ goto retry;
+ }
+ else if (response == 1)
+ {
+ /* We are forced to copy - just fall through ... */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ }
+
+ if (!job_aborted (job) &&
+ g_file_info_get_attribute_boolean (fsinfo,
+ G_FILE_ATTRIBUTE_FILESYSTEM_READONLY))
+ {
+ primary = f (_("Error while copying to “%B”."), dest);
+ secondary = f (_("The destination is read-only."));
+
+ run_error (job,
+ primary,
+ secondary,
+ NULL,
+ FALSE,
+ CANCEL,
+ NULL);
+
+ g_error_free (error);
+
+ abort_job (job);
+ }
+
+ g_object_unref (fsinfo);
}
static void
-report_copy_progress (CopyMoveJob *copy_job,
- SourceInfo *source_info,
- TransferInfo *transfer_info)
-{
- int files_left;
- goffset total_size;
- double elapsed, transfer_rate;
- int remaining_time;
- guint64 now;
- CommonJob *job;
- gboolean is_move;
- gchar *status;
- char *details;
-
- job = (CommonJob *)copy_job;
-
- is_move = copy_job->is_move;
-
- now = g_get_monotonic_time ();
-
- files_left = source_info->num_files - transfer_info->num_files;
-
- /* Races and whatnot could cause this to be negative... */
- if (files_left < 0) {
- files_left = 0;
- }
-
- /* If the number of files left is 0, we want to update the status without
- * considering this time, since we want to change the status to completed
- * and probably we won't get more calls to this function */
- if (transfer_info->last_report_time != 0 &&
- ABS ((gint64)(transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC &&
- files_left > 0) {
- return;
- }
- transfer_info->last_report_time = now;
-
- if (files_left != transfer_info->last_reported_files_left ||
- transfer_info->last_reported_files_left == 0) {
- /* Avoid changing this unless files_left changed since last time */
- transfer_info->last_reported_files_left = files_left;
-
- if (source_info->num_files == 1) {
- if (copy_job->destination != NULL) {
- if (is_move) {
- if (files_left > 0) {
- status = _("Moving “%B” to “%B”");
- } else {
- status = _("Moved “%B” to “%B”");
- }
- } else {
- if (files_left > 0) {
- status = _("Copying “%B” to “%B”");
- } else {
- status = _("Copied “%B” to “%B”");
- }
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- copy_job->fake_display_source != NULL ?
- copy_job->fake_display_source :
- (GFile *)copy_job->files->data,
- copy_job->destination));
- } else {
- if (files_left > 0) {
- status = _("Duplicating “%B”");
- } else {
- status = _("Duplicated “%B”");
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- (GFile *)copy_job->files->data));
- }
- } else if (copy_job->files != NULL) {
- if (copy_job->destination != NULL) {
- if (files_left > 0) {
- if (is_move) {
- status = ngettext ("Moving %'d file to “%B”",
- "Moving %'d files to “%B”",
- source_info->num_files);
- } else {
- status = ngettext ("Copying %'d file to “%B”",
- "Copying %'d files to “%B”",
- source_info->num_files);
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- source_info->num_files,
- (GFile *)copy_job->destination));
- } else {
- if (is_move) {
- status = ngettext ("Moved %'d file to “%B”",
- "Moved %'d files to “%B”",
- source_info->num_files);
- } else {
- status = ngettext ("Copied %'d file to “%B”",
- "Copied %'d files to “%B”",
- source_info->num_files);
- }
- nautilus_progress_info_take_status (job->progress,
- f (status,
- source_info->num_files,
- (GFile *)copy_job->destination));
- }
- } else {
- GFile *parent;
-
- parent = g_file_get_parent (copy_job->files->data);
- if (files_left > 0) {
- status = ngettext ("Duplicating %'d file in “%B”",
- "Duplicating %'d files in “%B”",
- source_info->num_files);
- nautilus_progress_info_take_status (job->progress,
- f (status,
- source_info->num_files,
- parent));
- } else {
- status = ngettext ("Duplicated %'d file in “%B”",
- "Duplicated %'d files in “%B”",
- source_info->num_files);
- nautilus_progress_info_take_status (job->progress,
- f (status,
- source_info->num_files,
- parent));
- }
- g_object_unref (parent);
- }
- }
- }
-
- total_size = MAX (source_info->num_bytes, transfer_info->num_bytes);
-
- elapsed = g_timer_elapsed (job->time, NULL);
- transfer_rate = 0;
- remaining_time = INT_MAX;
- if (elapsed > 0) {
- transfer_rate = transfer_info->num_bytes / elapsed;
- if (transfer_rate > 0)
- remaining_time = (total_size - transfer_info->num_bytes) / transfer_rate;
- }
-
- if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE &&
- transfer_rate > 0) {
- if (source_info->num_files == 1) {
- /* To translators: %S will expand to a size like "2 bytes" or "3 MB", so something like "4 kb / 4 MB" */
- details = f (_("%S / %S"), transfer_info->num_bytes, total_size);
- } else {
- if (files_left > 0) {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files + 1,
- source_info->num_files);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files,
- source_info->num_files);
- }
+report_copy_progress (CopyMoveJob *copy_job,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info)
+{
+ int files_left;
+ goffset total_size;
+ double elapsed, transfer_rate;
+ int remaining_time;
+ guint64 now;
+ CommonJob *job;
+ gboolean is_move;
+ gchar *status;
+ char *details;
+
+ job = (CommonJob *) copy_job;
+
+ is_move = copy_job->is_move;
+
+ now = g_get_monotonic_time ();
+
+ files_left = source_info->num_files - transfer_info->num_files;
+
+ /* Races and whatnot could cause this to be negative... */
+ if (files_left < 0)
+ {
+ files_left = 0;
+ }
+
+ /* If the number of files left is 0, we want to update the status without
+ * considering this time, since we want to change the status to completed
+ * and probably we won't get more calls to this function */
+ if (transfer_info->last_report_time != 0 &&
+ ABS ((gint64) (transfer_info->last_report_time - now)) < 100 * NSEC_PER_MICROSEC &&
+ files_left > 0)
+ {
+ return;
+ }
+ transfer_info->last_report_time = now;
+
+ if (files_left != transfer_info->last_reported_files_left ||
+ transfer_info->last_reported_files_left == 0)
+ {
+ /* Avoid changing this unless files_left changed since last time */
+ transfer_info->last_reported_files_left = files_left;
+
+ if (source_info->num_files == 1)
+ {
+ if (copy_job->destination != NULL)
+ {
+ if (is_move)
+ {
+ if (files_left > 0)
+ {
+ status = _("Moving “%B” to “%B”");
+ }
+ else
+ {
+ status = _("Moved “%B” to “%B”");
+ }
}
- } else {
- if (source_info->num_files == 1) {
- if (files_left > 0) {
- /* To translators: %S will expand to a size like "2 bytes" or "3 MB", %T to a time duration like
- * "2 minutes". So the whole thing will be something like "2 kb / 4 MB -- 2 hours left (4kb/sec)"
- *
- * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
- */
- details = f (ngettext ("%S / %S \xE2\x80\x94 %T left (%S/sec)",
- "%S / %S \xE2\x80\x94 %T left (%S/sec)",
- seconds_count_format_time_units (remaining_time)),
- transfer_info->num_bytes, total_size,
- remaining_time,
- (goffset)transfer_rate);
- } else {
- /* To translators: %S will expand to a size like "2 bytes" or "3 MB". */
- details = f (_("%S / %S"),
- transfer_info->num_bytes,
- total_size);
- }
- } else {
- if (files_left > 0) {
- /* To translators: %T will expand to a time duration like "2 minutes".
- * So the whole thing will be something like "1 / 5 -- 2 hours left (4kb/sec)"
- *
- * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
- */
- details = f (ngettext ("%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
- "%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
- seconds_count_format_time_units (remaining_time)),
- transfer_info->num_files + 1, source_info->num_files,
- remaining_time,
- (goffset)transfer_rate);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- transfer_info->num_files,
- source_info->num_files);
- }
+ else
+ {
+ if (files_left > 0)
+ {
+ status = _("Copying “%B” to “%B”");
+ }
+ else
+ {
+ status = _("Copied “%B” to “%B”");
+ }
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ copy_job->fake_display_source != NULL ?
+ copy_job->fake_display_source :
+ (GFile *) copy_job->files->data,
+ copy_job->destination));
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ status = _("Duplicating “%B”");
}
- }
- nautilus_progress_info_take_details (job->progress, details);
+ else
+ {
+ status = _("Duplicated “%B”");
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ (GFile *) copy_job->files->data));
+ }
+ }
+ else if (copy_job->files != NULL)
+ {
+ if (copy_job->destination != NULL)
+ {
+ if (files_left > 0)
+ {
+ if (is_move)
+ {
+ status = ngettext ("Moving %'d file to “%B”",
+ "Moving %'d files to “%B”",
+ source_info->num_files);
+ }
+ else
+ {
+ status = ngettext ("Copying %'d file to “%B”",
+ "Copying %'d files to “%B”",
+ source_info->num_files);
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ source_info->num_files,
+ (GFile *) copy_job->destination));
+ }
+ else
+ {
+ if (is_move)
+ {
+ status = ngettext ("Moved %'d file to “%B”",
+ "Moved %'d files to “%B”",
+ source_info->num_files);
+ }
+ else
+ {
+ status = ngettext ("Copied %'d file to “%B”",
+ "Copied %'d files to “%B”",
+ source_info->num_files);
+ }
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ source_info->num_files,
+ (GFile *) copy_job->destination));
+ }
+ }
+ else
+ {
+ GFile *parent;
+
+ parent = g_file_get_parent (copy_job->files->data);
+ if (files_left > 0)
+ {
+ status = ngettext ("Duplicating %'d file in “%B”",
+ "Duplicating %'d files in “%B”",
+ source_info->num_files);
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ source_info->num_files,
+ parent));
+ }
+ else
+ {
+ status = ngettext ("Duplicated %'d file in “%B”",
+ "Duplicated %'d files in “%B”",
+ source_info->num_files);
+ nautilus_progress_info_take_status (job->progress,
+ f (status,
+ source_info->num_files,
+ parent));
+ }
+ g_object_unref (parent);
+ }
+ }
+ }
- if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE) {
- nautilus_progress_info_set_remaining_time (job->progress,
- remaining_time);
- nautilus_progress_info_set_elapsed_time (job->progress,
- elapsed);
+ total_size = MAX (source_info->num_bytes, transfer_info->num_bytes);
+
+ elapsed = g_timer_elapsed (job->time, NULL);
+ transfer_rate = 0;
+ remaining_time = INT_MAX;
+ if (elapsed > 0)
+ {
+ transfer_rate = transfer_info->num_bytes / elapsed;
+ if (transfer_rate > 0)
+ {
+ remaining_time = (total_size - transfer_info->num_bytes) / transfer_rate;
}
+ }
- nautilus_progress_info_set_progress (job->progress, transfer_info->num_bytes, total_size);
+ if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE &&
+ transfer_rate > 0)
+ {
+ if (source_info->num_files == 1)
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or "3 MB", so something like "4 kb / 4 MB" */
+ details = f (_("%S / %S"), transfer_info->num_bytes, total_size);
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files + 1,
+ source_info->num_files);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files,
+ source_info->num_files);
+ }
+ }
+ }
+ else
+ {
+ if (source_info->num_files == 1)
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or "3 MB", %T to a time duration like
+ * "2 minutes". So the whole thing will be something like "2 kb / 4 MB -- 2 hours left (4kb/sec)"
+ *
+ * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
+ */
+ details = f (ngettext ("%S / %S \xE2\x80\x94 %T left (%S/sec)",
+ "%S / %S \xE2\x80\x94 %T left (%S/sec)",
+ seconds_count_format_time_units (remaining_time)),
+ transfer_info->num_bytes, total_size,
+ remaining_time,
+ (goffset) transfer_rate);
+ }
+ else
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or "3 MB". */
+ details = f (_("%S / %S"),
+ transfer_info->num_bytes,
+ total_size);
+ }
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %T will expand to a time duration like "2 minutes".
+ * So the whole thing will be something like "1 / 5 -- 2 hours left (4kb/sec)"
+ *
+ * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
+ */
+ details = f (ngettext ("%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
+ "%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
+ seconds_count_format_time_units (remaining_time)),
+ transfer_info->num_files + 1, source_info->num_files,
+ remaining_time,
+ (goffset) transfer_rate);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ transfer_info->num_files,
+ source_info->num_files);
+ }
+ }
+ }
+ nautilus_progress_info_take_details (job->progress, details);
+
+ if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE)
+ {
+ nautilus_progress_info_set_remaining_time (job->progress,
+ remaining_time);
+ nautilus_progress_info_set_elapsed_time (job->progress,
+ elapsed);
+ }
+
+ nautilus_progress_info_set_progress (job->progress, transfer_info->num_bytes, total_size);
}
static int
get_max_name_length (GFile *file_dir)
{
- int max_length;
- char *dir;
- long max_path;
- long max_name;
+ int max_length;
+ char *dir;
+ long max_path;
+ long max_name;
- max_length = -1;
+ max_length = -1;
- if (!g_file_has_uri_scheme (file_dir, "file"))
- return max_length;
+ if (!g_file_has_uri_scheme (file_dir, "file"))
+ {
+ return max_length;
+ }
- dir = g_file_get_path (file_dir);
- if (!dir)
- return max_length;
+ dir = g_file_get_path (file_dir);
+ if (!dir)
+ {
+ return max_length;
+ }
- max_path = pathconf (dir, _PC_PATH_MAX);
- max_name = pathconf (dir, _PC_NAME_MAX);
+ max_path = pathconf (dir, _PC_PATH_MAX);
+ max_name = pathconf (dir, _PC_NAME_MAX);
- if (max_name == -1 && max_path == -1) {
- max_length = -1;
- } else if (max_name == -1 && max_path != -1) {
- max_length = max_path - (strlen (dir) + 1);
- } else if (max_name != -1 && max_path == -1) {
- max_length = max_name;
- } else {
- int leftover;
+ if (max_name == -1 && max_path == -1)
+ {
+ max_length = -1;
+ }
+ else if (max_name == -1 && max_path != -1)
+ {
+ max_length = max_path - (strlen (dir) + 1);
+ }
+ else if (max_name != -1 && max_path == -1)
+ {
+ max_length = max_name;
+ }
+ else
+ {
+ int leftover;
- leftover = max_path - (strlen (dir) + 1);
+ leftover = max_path - (strlen (dir) + 1);
- max_length = MIN (leftover, max_name);
- }
+ max_length = MIN (leftover, max_name);
+ }
- g_free (dir);
+ g_free (dir);
- return max_length;
+ return max_length;
}
#define FAT_FORBIDDEN_CHARACTERS "/:;*?\"<>"
static gboolean
fat_str_replace (char *str,
- char replacement)
-{
- gboolean success;
- int i;
-
- success = FALSE;
- for (i = 0; str[i] != '\0'; i++) {
- if (strchr (FAT_FORBIDDEN_CHARACTERS, str[i]) ||
- str[i] < 32) {
- success = TRUE;
- str[i] = replacement;
- }
- }
+ char replacement)
+{
+ gboolean success;
+ int i;
+
+ success = FALSE;
+ for (i = 0; str[i] != '\0'; i++)
+ {
+ if (strchr (FAT_FORBIDDEN_CHARACTERS, str[i]) ||
+ str[i] < 32)
+ {
+ success = TRUE;
+ str[i] = replacement;
+ }
+ }
- return success;
+ return success;
}
static gboolean
-make_file_name_valid_for_dest_fs (char *filename,
- const char *dest_fs_type)
-{
- if (dest_fs_type != NULL && filename != NULL) {
- if (!strcmp (dest_fs_type, "fat") ||
- !strcmp (dest_fs_type, "vfat") ||
- !strcmp (dest_fs_type, "msdos") ||
- !strcmp (dest_fs_type, "msdosfs")) {
- gboolean ret;
- int i, old_len;
-
- ret = fat_str_replace (filename, '_');
-
- old_len = strlen (filename);
- for (i = 0; i < old_len; i++) {
- if (filename[i] != ' ') {
- g_strchomp (filename);
- ret |= (old_len != strlen (filename));
- break;
- }
- }
+make_file_name_valid_for_dest_fs (char *filename,
+ const char *dest_fs_type)
+{
+ if (dest_fs_type != NULL && filename != NULL)
+ {
+ if (!strcmp (dest_fs_type, "fat") ||
+ !strcmp (dest_fs_type, "vfat") ||
+ !strcmp (dest_fs_type, "msdos") ||
+ !strcmp (dest_fs_type, "msdosfs"))
+ {
+ gboolean ret;
+ int i, old_len;
+
+ ret = fat_str_replace (filename, '_');
+
+ old_len = strlen (filename);
+ for (i = 0; i < old_len; i++)
+ {
+ if (filename[i] != ' ')
+ {
+ g_strchomp (filename);
+ ret |= (old_len != strlen (filename));
+ break;
+ }
+ }
- return ret;
- }
- }
+ return ret;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static GFile *
-get_unique_target_file (GFile *src,
- GFile *dest_dir,
- gboolean same_fs,
- const char *dest_fs_type,
- int count)
-{
- const char *editname, *end;
- char *basename, *new_name;
- GFileInfo *info;
- GFile *dest;
- int max_length;
-
- max_length = get_max_name_length (dest_dir);
-
- dest = NULL;
- info = g_file_query_info (src,
- G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME,
- 0, NULL, NULL);
- if (info != NULL) {
- editname = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
-
- if (editname != NULL) {
- new_name = get_duplicate_name (editname, count, max_length);
- make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
- dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
- g_free (new_name);
- }
-
- g_object_unref (info);
- }
-
- if (dest == NULL) {
- basename = g_file_get_basename (src);
-
- if (g_utf8_validate (basename, -1, NULL)) {
- new_name = get_duplicate_name (basename, count, max_length);
- make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
- dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
- g_free (new_name);
- }
-
- if (dest == NULL) {
- end = strrchr (basename, '.');
- if (end != NULL) {
- count += atoi (end + 1);
- }
- new_name = g_strdup_printf ("%s.%d", basename, count);
- make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
- dest = g_file_get_child (dest_dir, new_name);
- g_free (new_name);
- }
-
- g_free (basename);
- }
-
- return dest;
+get_unique_target_file (GFile *src,
+ GFile *dest_dir,
+ gboolean same_fs,
+ const char *dest_fs_type,
+ int count)
+{
+ const char *editname, *end;
+ char *basename, *new_name;
+ GFileInfo *info;
+ GFile *dest;
+ int max_length;
+
+ max_length = get_max_name_length (dest_dir);
+
+ dest = NULL;
+ info = g_file_query_info (src,
+ G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME,
+ 0, NULL, NULL);
+ if (info != NULL)
+ {
+ editname = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
+
+ if (editname != NULL)
+ {
+ new_name = get_duplicate_name (editname, count, max_length);
+ make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
+ dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
+ g_free (new_name);
+ }
+
+ g_object_unref (info);
+ }
+
+ if (dest == NULL)
+ {
+ basename = g_file_get_basename (src);
+
+ if (g_utf8_validate (basename, -1, NULL))
+ {
+ new_name = get_duplicate_name (basename, count, max_length);
+ make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
+ dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
+ g_free (new_name);
+ }
+
+ if (dest == NULL)
+ {
+ end = strrchr (basename, '.');
+ if (end != NULL)
+ {
+ count += atoi (end + 1);
+ }
+ new_name = g_strdup_printf ("%s.%d", basename, count);
+ make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
+ dest = g_file_get_child (dest_dir, new_name);
+ g_free (new_name);
+ }
+
+ g_free (basename);
+ }
+
+ return dest;
}
static GFile *
-get_target_file_for_link (GFile *src,
- GFile *dest_dir,
- const char *dest_fs_type,
- int count)
-{
- const char *editname;
- char *basename, *new_name;
- GFileInfo *info;
- GFile *dest;
- int max_length;
-
- max_length = get_max_name_length (dest_dir);
-
- dest = NULL;
- info = g_file_query_info (src,
- G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME,
- 0, NULL, NULL);
- if (info != NULL) {
- editname = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
-
- if (editname != NULL) {
- new_name = get_link_name (editname, count, max_length);
- make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
- dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
- g_free (new_name);
- }
-
- g_object_unref (info);
- }
-
- if (dest == NULL) {
- basename = g_file_get_basename (src);
- make_file_name_valid_for_dest_fs (basename, dest_fs_type);
-
- if (g_utf8_validate (basename, -1, NULL)) {
- new_name = get_link_name (basename, count, max_length);
- make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
- dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
- g_free (new_name);
- }
-
- if (dest == NULL) {
- if (count == 1) {
- new_name = g_strdup_printf ("%s.lnk", basename);
- } else {
- new_name = g_strdup_printf ("%s.lnk%d", basename, count);
- }
- make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
- dest = g_file_get_child (dest_dir, new_name);
- g_free (new_name);
- }
-
- g_free (basename);
- }
-
- return dest;
+get_target_file_for_link (GFile *src,
+ GFile *dest_dir,
+ const char *dest_fs_type,
+ int count)
+{
+ const char *editname;
+ char *basename, *new_name;
+ GFileInfo *info;
+ GFile *dest;
+ int max_length;
+
+ max_length = get_max_name_length (dest_dir);
+
+ dest = NULL;
+ info = g_file_query_info (src,
+ G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME,
+ 0, NULL, NULL);
+ if (info != NULL)
+ {
+ editname = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
+
+ if (editname != NULL)
+ {
+ new_name = get_link_name (editname, count, max_length);
+ make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
+ dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
+ g_free (new_name);
+ }
+
+ g_object_unref (info);
+ }
+
+ if (dest == NULL)
+ {
+ basename = g_file_get_basename (src);
+ make_file_name_valid_for_dest_fs (basename, dest_fs_type);
+
+ if (g_utf8_validate (basename, -1, NULL))
+ {
+ new_name = get_link_name (basename, count, max_length);
+ make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
+ dest = g_file_get_child_for_display_name (dest_dir, new_name, NULL);
+ g_free (new_name);
+ }
+
+ if (dest == NULL)
+ {
+ if (count == 1)
+ {
+ new_name = g_strdup_printf ("%s.lnk", basename);
+ }
+ else
+ {
+ new_name = g_strdup_printf ("%s.lnk%d", basename, count);
+ }
+ make_file_name_valid_for_dest_fs (new_name, dest_fs_type);
+ dest = g_file_get_child (dest_dir, new_name);
+ g_free (new_name);
+ }
+
+ g_free (basename);
+ }
+
+ return dest;
}
static GFile *
-get_target_file_with_custom_name (GFile *src,
- GFile *dest_dir,
- const char *dest_fs_type,
- gboolean same_fs,
- const gchar *custom_name)
-{
- char *basename;
- GFile *dest;
- GFileInfo *info;
- char *copyname;
-
- dest = NULL;
-
- if (custom_name != NULL) {
- copyname = g_strdup (custom_name);
- make_file_name_valid_for_dest_fs (copyname, dest_fs_type);
- dest = g_file_get_child_for_display_name (dest_dir, copyname, NULL);
-
- g_free (copyname);
- }
-
- if (dest == NULL && !same_fs) {
- info = g_file_query_info (src,
- G_FILE_ATTRIBUTE_STANDARD_COPY_NAME ","
- G_FILE_ATTRIBUTE_TRASH_ORIG_PATH,
- 0, NULL, NULL);
-
- if (info) {
- copyname = NULL;
-
- /* if file is being restored from trash make sure it uses its original name */
- if (g_file_has_uri_scheme (src, "trash")) {
- copyname = g_path_get_basename (g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH));
- }
-
- if (copyname == NULL) {
- copyname = g_strdup (g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME));
- }
-
- if (copyname) {
- make_file_name_valid_for_dest_fs (copyname, dest_fs_type);
- dest = g_file_get_child_for_display_name (dest_dir, copyname, NULL);
- g_free (copyname);
- }
-
- g_object_unref (info);
- }
- }
-
- if (dest == NULL) {
- basename = g_file_get_basename (src);
- make_file_name_valid_for_dest_fs (basename, dest_fs_type);
- dest = g_file_get_child (dest_dir, basename);
- g_free (basename);
- }
-
- return dest;
+get_target_file_with_custom_name (GFile *src,
+ GFile *dest_dir,
+ const char *dest_fs_type,
+ gboolean same_fs,
+ const gchar *custom_name)
+{
+ char *basename;
+ GFile *dest;
+ GFileInfo *info;
+ char *copyname;
+
+ dest = NULL;
+
+ if (custom_name != NULL)
+ {
+ copyname = g_strdup (custom_name);
+ make_file_name_valid_for_dest_fs (copyname, dest_fs_type);
+ dest = g_file_get_child_for_display_name (dest_dir, copyname, NULL);
+
+ g_free (copyname);
+ }
+
+ if (dest == NULL && !same_fs)
+ {
+ info = g_file_query_info (src,
+ G_FILE_ATTRIBUTE_STANDARD_COPY_NAME ","
+ G_FILE_ATTRIBUTE_TRASH_ORIG_PATH,
+ 0, NULL, NULL);
+
+ if (info)
+ {
+ copyname = NULL;
+
+ /* if file is being restored from trash make sure it uses its original name */
+ if (g_file_has_uri_scheme (src, "trash"))
+ {
+ copyname = g_path_get_basename (g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH));
+ }
+
+ if (copyname == NULL)
+ {
+ copyname = g_strdup (g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_COPY_NAME));
+ }
+
+ if (copyname)
+ {
+ make_file_name_valid_for_dest_fs (copyname, dest_fs_type);
+ dest = g_file_get_child_for_display_name (dest_dir, copyname, NULL);
+ g_free (copyname);
+ }
+
+ g_object_unref (info);
+ }
+ }
+
+ if (dest == NULL)
+ {
+ basename = g_file_get_basename (src);
+ make_file_name_valid_for_dest_fs (basename, dest_fs_type);
+ dest = g_file_get_child (dest_dir, basename);
+ g_free (basename);
+ }
+
+ return dest;
}
static GFile *
-get_target_file (GFile *src,
- GFile *dest_dir,
- const char *dest_fs_type,
- gboolean same_fs)
+get_target_file (GFile *src,
+ GFile *dest_dir,
+ const char *dest_fs_type,
+ gboolean same_fs)
{
- return get_target_file_with_custom_name (src, dest_dir, dest_fs_type, same_fs, NULL);
+ return get_target_file_with_custom_name (src, dest_dir, dest_fs_type, same_fs, NULL);
}
static gboolean
-has_fs_id (GFile *file, const char *fs_id)
-{
- const char *id;
- GFileInfo *info;
- gboolean res;
-
- res = FALSE;
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_ID_FILESYSTEM,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
-
- if (info) {
- id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
-
- if (id && strcmp (id, fs_id) == 0) {
- res = TRUE;
- }
-
- g_object_unref (info);
- }
-
- return res;
+has_fs_id (GFile *file,
+ const char *fs_id)
+{
+ const char *id;
+ GFileInfo *info;
+ gboolean res;
+
+ res = FALSE;
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_ID_FILESYSTEM,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+
+ if (info)
+ {
+ id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
+
+ if (id && strcmp (id, fs_id) == 0)
+ {
+ res = TRUE;
+ }
+
+ g_object_unref (info);
+ }
+
+ return res;
}
static gboolean
is_dir (GFile *file)
{
- GFileInfo *info;
- gboolean res;
-
- res = FALSE;
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
- if (info) {
- res = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
- g_object_unref (info);
- }
-
- return res;
-}
-
-static GFile*
-map_possibly_volatile_file_to_real (GFile *volatile_file,
- GCancellable *cancellable,
- GError **error)
-{
- GFile *real_file = NULL;
- GFileInfo *info = NULL;
-
- info = g_file_query_info (volatile_file,
- G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","
- G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE","
- G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- cancellable,
- error);
- if (info == NULL) {
- return NULL;
- } else {
- gboolean is_volatile;
-
- is_volatile = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE);
- if (is_volatile) {
- const gchar *target;
-
- target = g_file_info_get_symlink_target (info);
- real_file = g_file_resolve_relative_path (volatile_file, target);
- }
- }
-
- g_object_unref (info);
-
- if (real_file == NULL)
- real_file = g_object_ref (volatile_file);
-
- return real_file;
-}
-
-static GFile*
-map_possibly_volatile_file_to_real_on_write (GFile *volatile_file,
- GFileOutputStream *stream,
- GCancellable *cancellable,
- GError **error)
-{
- GFile *real_file = NULL;
- GFileInfo *info = NULL;
-
- info = g_file_output_stream_query_info (stream,
- G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK","
- G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE","
- G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
- cancellable,
- error);
- if (info == NULL) {
- return NULL;
- } else {
- gboolean is_volatile;
-
- is_volatile = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE);
- if (is_volatile) {
- const gchar *target;
-
- target = g_file_info_get_symlink_target (info);
- real_file = g_file_resolve_relative_path (volatile_file, target);
- }
- }
-
- g_object_unref (info);
-
- if (real_file == NULL)
- real_file = g_object_ref (volatile_file);
-
- return real_file;
-}
-
-static void copy_move_file (CopyMoveJob *job,
- GFile *src,
- GFile *dest_dir,
- gboolean same_fs,
- gboolean unique_names,
- char **dest_fs_type,
- SourceInfo *source_info,
- TransferInfo *transfer_info,
- GHashTable *debuting_files,
- GdkPoint *point,
- gboolean overwrite,
- gboolean *skipped_file,
- gboolean readonly_source_fs);
-
-typedef enum {
- CREATE_DEST_DIR_RETRY,
- CREATE_DEST_DIR_FAILED,
- CREATE_DEST_DIR_SUCCESS
+ GFileInfo *info;
+ gboolean res;
+
+ res = FALSE;
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, NULL);
+ if (info)
+ {
+ res = g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY;
+ g_object_unref (info);
+ }
+
+ return res;
+}
+
+static GFile *
+map_possibly_volatile_file_to_real (GFile *volatile_file,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GFile *real_file = NULL;
+ GFileInfo *info = NULL;
+
+ info = g_file_query_info (volatile_file,
+ G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE ","
+ G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ cancellable,
+ error);
+ if (info == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ gboolean is_volatile;
+
+ is_volatile = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE);
+ if (is_volatile)
+ {
+ const gchar *target;
+
+ target = g_file_info_get_symlink_target (info);
+ real_file = g_file_resolve_relative_path (volatile_file, target);
+ }
+ }
+
+ g_object_unref (info);
+
+ if (real_file == NULL)
+ {
+ real_file = g_object_ref (volatile_file);
+ }
+
+ return real_file;
+}
+
+static GFile *
+map_possibly_volatile_file_to_real_on_write (GFile *volatile_file,
+ GFileOutputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GFile *real_file = NULL;
+ GFileInfo *info = NULL;
+
+ info = g_file_output_stream_query_info (stream,
+ G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
+ G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE ","
+ G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+ cancellable,
+ error);
+ if (info == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ gboolean is_volatile;
+
+ is_volatile = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_STANDARD_IS_VOLATILE);
+ if (is_volatile)
+ {
+ const gchar *target;
+
+ target = g_file_info_get_symlink_target (info);
+ real_file = g_file_resolve_relative_path (volatile_file, target);
+ }
+ }
+
+ g_object_unref (info);
+
+ if (real_file == NULL)
+ {
+ real_file = g_object_ref (volatile_file);
+ }
+
+ return real_file;
+}
+
+static void copy_move_file (CopyMoveJob *job,
+ GFile *src,
+ GFile *dest_dir,
+ gboolean same_fs,
+ gboolean unique_names,
+ char **dest_fs_type,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info,
+ GHashTable *debuting_files,
+ GdkPoint *point,
+ gboolean overwrite,
+ gboolean *skipped_file,
+ gboolean readonly_source_fs);
+
+typedef enum
+{
+ CREATE_DEST_DIR_RETRY,
+ CREATE_DEST_DIR_FAILED,
+ CREATE_DEST_DIR_SUCCESS
} CreateDestDirResult;
static CreateDestDirResult
-create_dest_dir (CommonJob *job,
- GFile *src,
- GFile **dest,
- gboolean same_fs,
- char **dest_fs_type)
-{
- GError *error;
- GFile *new_dest, *dest_dir;
- char *primary, *secondary, *details;
- int response;
- gboolean handled_invalid_filename;
- gboolean res;
-
- handled_invalid_filename = *dest_fs_type != NULL;
-
- retry:
- /* First create the directory, then copy stuff to it before
- copying the attributes, because we need to be sure we can write to it */
-
- error = NULL;
- res = g_file_make_directory (*dest, job->cancellable, &error);
-
- if (res) {
- GFile *real;
-
- real = map_possibly_volatile_file_to_real (*dest, job->cancellable, &error);
- if (real == NULL) {
- res = FALSE;
- } else {
- g_object_unref (*dest);
- *dest = real;
- }
- }
-
- if (!res) {
- if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- return CREATE_DEST_DIR_FAILED;
- } else if (IS_IO_ERROR (error, INVALID_FILENAME) &&
- !handled_invalid_filename) {
- handled_invalid_filename = TRUE;
-
- g_assert (*dest_fs_type == NULL);
-
- dest_dir = g_file_get_parent (*dest);
-
- if (dest_dir != NULL) {
- *dest_fs_type = query_fs_type (dest_dir, job->cancellable);
-
- new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
- g_object_unref (dest_dir);
-
- if (!g_file_equal (*dest, new_dest)) {
- g_object_unref (*dest);
- *dest = new_dest;
- g_error_free (error);
- return CREATE_DEST_DIR_RETRY;
- } else {
- g_object_unref (new_dest);
- }
- }
- }
-
- primary = f (_("Error while copying."));
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("The folder “%B” cannot be copied because you do not have "
- "permissions to create it in the destination."), src);
- } else {
- secondary = f (_("There was an error creating the folder “%B”."), src);
- details = error->message;
- }
-
- response = run_warning (job,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL, SKIP, RETRY,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) {
- /* Skip: Do Nothing */
- } else if (response == 2) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
- return CREATE_DEST_DIR_FAILED;
- }
- nautilus_file_changes_queue_file_added (*dest);
-
- if (job->undo_info != NULL) {
- nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (job->undo_info),
- src, *dest);
- }
-
- return CREATE_DEST_DIR_SUCCESS;
+create_dest_dir (CommonJob *job,
+ GFile *src,
+ GFile **dest,
+ gboolean same_fs,
+ char **dest_fs_type)
+{
+ GError *error;
+ GFile *new_dest, *dest_dir;
+ char *primary, *secondary, *details;
+ int response;
+ gboolean handled_invalid_filename;
+ gboolean res;
+
+ handled_invalid_filename = *dest_fs_type != NULL;
+
+retry:
+ /* First create the directory, then copy stuff to it before
+ * copying the attributes, because we need to be sure we can write to it */
+
+ error = NULL;
+ res = g_file_make_directory (*dest, job->cancellable, &error);
+
+ if (res)
+ {
+ GFile *real;
+
+ real = map_possibly_volatile_file_to_real (*dest, job->cancellable, &error);
+ if (real == NULL)
+ {
+ res = FALSE;
+ }
+ else
+ {
+ g_object_unref (*dest);
+ *dest = real;
+ }
+ }
+
+ if (!res)
+ {
+ if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ return CREATE_DEST_DIR_FAILED;
+ }
+ else if (IS_IO_ERROR (error, INVALID_FILENAME) &&
+ !handled_invalid_filename)
+ {
+ handled_invalid_filename = TRUE;
+
+ g_assert (*dest_fs_type == NULL);
+
+ dest_dir = g_file_get_parent (*dest);
+
+ if (dest_dir != NULL)
+ {
+ *dest_fs_type = query_fs_type (dest_dir, job->cancellable);
+
+ new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+ g_object_unref (dest_dir);
+
+ if (!g_file_equal (*dest, new_dest))
+ {
+ g_object_unref (*dest);
+ *dest = new_dest;
+ g_error_free (error);
+ return CREATE_DEST_DIR_RETRY;
+ }
+ else
+ {
+ g_object_unref (new_dest);
+ }
+ }
+ }
+
+ primary = f (_("Error while copying."));
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("The folder “%B” cannot be copied because you do not have "
+ "permissions to create it in the destination."), src);
+ }
+ else
+ {
+ secondary = f (_("There was an error creating the folder “%B”."), src);
+ details = error->message;
+ }
+
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ FALSE,
+ CANCEL, SKIP, RETRY,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ /* Skip: Do Nothing */
+ }
+ else if (response == 2)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ return CREATE_DEST_DIR_FAILED;
+ }
+ nautilus_file_changes_queue_file_added (*dest);
+
+ if (job->undo_info != NULL)
+ {
+ nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (job->undo_info),
+ src, *dest);
+ }
+
+ return CREATE_DEST_DIR_SUCCESS;
}
/* a return value of FALSE means retry, i.e.
@@ -3924,414 +4510,490 @@ create_dest_dir (CommonJob *job,
* the new destination.
*/
static gboolean
-copy_move_directory (CopyMoveJob *copy_job,
- GFile *src,
- GFile **dest,
- gboolean same_fs,
- gboolean create_dest,
- char **parent_dest_fs_type,
- SourceInfo *source_info,
- TransferInfo *transfer_info,
- GHashTable *debuting_files,
- gboolean *skipped_file,
- gboolean readonly_source_fs)
-{
- GFileInfo *info;
- GError *error;
- GFile *src_file;
- GFileEnumerator *enumerator;
- char *primary, *secondary, *details;
- char *dest_fs_type;
- int response;
- gboolean skip_error;
- gboolean local_skipped_file;
- CommonJob *job;
- GFileCopyFlags flags;
-
- job = (CommonJob *)copy_job;
-
- if (create_dest) {
- switch (create_dest_dir (job, src, dest, same_fs, parent_dest_fs_type)) {
- case CREATE_DEST_DIR_RETRY:
- /* next time copy_move_directory() is called,
- * create_dest will be FALSE if a directory already
- * exists under the new name (i.e. WOULD_RECURSE)
- */
- return FALSE;
-
- case CREATE_DEST_DIR_FAILED:
- *skipped_file = TRUE;
- return TRUE;
-
- case CREATE_DEST_DIR_SUCCESS:
- default:
- break;
- }
-
- if (debuting_files) {
- g_hash_table_replace (debuting_files, g_object_ref (*dest), GINT_TO_POINTER (TRUE));
- }
-
- }
-
- local_skipped_file = FALSE;
- dest_fs_type = NULL;
-
- skip_error = should_skip_readdir_error (job, src);
- retry:
- error = NULL;
- enumerator = g_file_enumerate_children (src,
- G_FILE_ATTRIBUTE_STANDARD_NAME,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable,
- &error);
- if (enumerator) {
- error = NULL;
-
- while (!job_aborted (job) &&
- (info = g_file_enumerator_next_file (enumerator, job->cancellable, skip_error?NULL:&error)) != NULL) {
- src_file = g_file_get_child (src,
- g_file_info_get_name (info));
- copy_move_file (copy_job, src_file, *dest, same_fs, FALSE, &dest_fs_type,
- source_info, transfer_info, NULL, NULL, FALSE, &local_skipped_file,
- readonly_source_fs);
-
- if (local_skipped_file) {
- transfer_add_file_to_count (src_file, job, transfer_info);
- report_copy_progress (copy_job, source_info, transfer_info);
- }
-
- g_object_unref (src_file);
- g_object_unref (info);
- }
- g_file_enumerator_close (enumerator, job->cancellable, NULL);
- g_object_unref (enumerator);
-
- if (error && IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- } else if (error) {
- if (copy_job->is_move) {
- primary = f (_("Error while moving."));
- } else {
- primary = f (_("Error while copying."));
- }
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("Files in the folder “%B” cannot be copied because you do "
- "not have permissions to see them."), src);
- } else {
- secondary = f (_("There was an error getting information about the files in the folder “%B”."), src);
- details = error->message;
- }
-
- response = run_warning (job,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL, _("_Skip files"),
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) {
- /* Skip: Do Nothing */
- local_skipped_file = TRUE;
- } else {
- g_assert_not_reached ();
- }
- }
-
- /* Count the copied directory as a file */
- transfer_info->num_files ++;
- report_copy_progress (copy_job, source_info, transfer_info);
-
- if (debuting_files) {
- g_hash_table_replace (debuting_files, g_object_ref (*dest), GINT_TO_POINTER (create_dest));
- }
- } else if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- } else {
- if (copy_job->is_move) {
- primary = f (_("Error while moving."));
- } else {
- primary = f (_("Error while copying."));
- }
- details = NULL;
-
- if (IS_IO_ERROR (error, PERMISSION_DENIED)) {
- secondary = f (_("The folder “%B” cannot be copied because you do not have "
- "permissions to read it."), src);
- } else {
- secondary = f (_("There was an error reading the folder “%B”."), src);
- details = error->message;
- }
-
- response = run_warning (job,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL, SKIP, RETRY,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) {
- /* Skip: Do Nothing */
- local_skipped_file = TRUE;
- } else if (response == 2) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
- }
-
- if (create_dest) {
- flags = (readonly_source_fs) ? G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_TARGET_DEFAULT_PERMS
- : G_FILE_COPY_NOFOLLOW_SYMLINKS;
- /* Ignore errors here. Failure to copy metadata is not a hard error */
- g_file_copy_attributes (src, *dest,
- flags,
- job->cancellable, NULL);
- }
-
- if (!job_aborted (job) && copy_job->is_move &&
- /* Don't delete source if there was a skipped file */
- !local_skipped_file) {
- if (!g_file_delete (src, job->cancellable, &error)) {
- if (job->skip_all_error) {
- goto skip;
- }
- primary = f (_("Error while moving “%B”."), src);
- secondary = f (_("Could not remove the source folder."));
- details = error->message;
-
- response = run_cancel_or_skip_warning (job,
- primary,
- secondary,
- details,
- source_info->num_files,
- source_info->num_files - transfer_info->num_files);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- local_skipped_file = TRUE;
- } else if (response == 2) { /* skip */
- local_skipped_file = TRUE;
- } else {
- g_assert_not_reached ();
- }
-
- skip:
- g_error_free (error);
- }
- }
-
- if (local_skipped_file) {
- *skipped_file = TRUE;
- }
-
- g_free (dest_fs_type);
- return TRUE;
-}
-
-
-typedef struct {
- CommonJob *job;
- GFile *source;
-} DeleteExistingFileData;
-
-static void
-existing_file_removed_callback (GFile *file,
- GError *error,
- gpointer callback_data)
-{
- DeleteExistingFileData *data = callback_data;
- CommonJob *job;
- GFile *source;
- GFileType file_type;
- char *primary;
- char *secondary;
- char *details = NULL;
- int response;
-
- job = data->job;
- source = data->source;
+copy_move_directory (CopyMoveJob *copy_job,
+ GFile *src,
+ GFile **dest,
+ gboolean same_fs,
+ gboolean create_dest,
+ char **parent_dest_fs_type,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info,
+ GHashTable *debuting_files,
+ gboolean *skipped_file,
+ gboolean readonly_source_fs)
+{
+ GFileInfo *info;
+ GError *error;
+ GFile *src_file;
+ GFileEnumerator *enumerator;
+ char *primary, *secondary, *details;
+ char *dest_fs_type;
+ int response;
+ gboolean skip_error;
+ gboolean local_skipped_file;
+ CommonJob *job;
+ GFileCopyFlags flags;
+
+ job = (CommonJob *) copy_job;
+
+ if (create_dest)
+ {
+ switch (create_dest_dir (job, src, dest, same_fs, parent_dest_fs_type))
+ {
+ case CREATE_DEST_DIR_RETRY:
+ {
+ /* next time copy_move_directory() is called,
+ * create_dest will be FALSE if a directory already
+ * exists under the new name (i.e. WOULD_RECURSE)
+ */
+ return FALSE;
+ }
- if (error == NULL) {
- nautilus_file_changes_queue_file_removed (file);
+ case CREATE_DEST_DIR_FAILED:
+ {
+ *skipped_file = TRUE;
+ return TRUE;
+ }
- return;
+ case CREATE_DEST_DIR_SUCCESS:
+ default:
+ {
+ }
+ break;
}
- if (job_aborted (job) || job->skip_all_error) {
- return;
+ if (debuting_files)
+ {
+ g_hash_table_replace (debuting_files, g_object_ref (*dest), GINT_TO_POINTER (TRUE));
}
+ }
- primary = f (_("Error while copying “%B”."), source);
+ local_skipped_file = FALSE;
+ dest_fs_type = NULL;
- file_type = g_file_query_file_type (file,
+ skip_error = should_skip_readdir_error (job, src);
+retry:
+ error = NULL;
+ enumerator = g_file_enumerate_children (src,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable);
+ job->cancellable,
+ &error);
+ if (enumerator)
+ {
+ error = NULL;
+
+ while (!job_aborted (job) &&
+ (info = g_file_enumerator_next_file (enumerator, job->cancellable, skip_error ? NULL : &error)) != NULL)
+ {
+ src_file = g_file_get_child (src,
+ g_file_info_get_name (info));
+ copy_move_file (copy_job, src_file, *dest, same_fs, FALSE, &dest_fs_type,
+ source_info, transfer_info, NULL, NULL, FALSE, &local_skipped_file,
+ readonly_source_fs);
+
+ if (local_skipped_file)
+ {
+ transfer_add_file_to_count (src_file, job, transfer_info);
+ report_copy_progress (copy_job, source_info, transfer_info);
+ }
+
+ g_object_unref (src_file);
+ g_object_unref (info);
+ }
+ g_file_enumerator_close (enumerator, job->cancellable, NULL);
+ g_object_unref (enumerator);
- if (file_type == G_FILE_TYPE_DIRECTORY) {
- secondary = f (_("Could not remove the already existing folder %F."),
- file);
- } else {
- secondary = f (_("Could not remove the already existing file %F."),
- file);
+ if (error && IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ else if (error)
+ {
+ if (copy_job->is_move)
+ {
+ primary = f (_("Error while moving."));
+ }
+ else
+ {
+ primary = f (_("Error while copying."));
+ }
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("Files in the folder “%B” cannot be copied because you do "
+ "not have permissions to see them."), src);
+ }
+ else
+ {
+ secondary = f (_("There was an error getting information about the files in the folder “%B”."), src);
+ details = error->message;
+ }
+
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ FALSE,
+ CANCEL, _("_Skip files"),
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ /* Skip: Do Nothing */
+ local_skipped_file = TRUE;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
}
- details = error->message;
+ /* Count the copied directory as a file */
+ transfer_info->num_files++;
+ report_copy_progress (copy_job, source_info, transfer_info);
+
+ if (debuting_files)
+ {
+ g_hash_table_replace (debuting_files, g_object_ref (*dest), GINT_TO_POINTER (create_dest));
+ }
+ }
+ else if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ else
+ {
+ if (copy_job->is_move)
+ {
+ primary = f (_("Error while moving."));
+ }
+ else
+ {
+ primary = f (_("Error while copying."));
+ }
+ details = NULL;
+
+ if (IS_IO_ERROR (error, PERMISSION_DENIED))
+ {
+ secondary = f (_("The folder “%B” cannot be copied because you do not have "
+ "permissions to read it."), src);
+ }
+ else
+ {
+ secondary = f (_("There was an error reading the folder “%B”."), src);
+ details = error->message;
+ }
- /* set show_all to TRUE here, as we don't know how many
- * files we'll end up processing yet.
- */
response = run_warning (job,
primary,
secondary,
details,
- TRUE,
- CANCEL, SKIP_ALL, SKIP,
+ FALSE,
+ CANCEL, SKIP, RETRY,
NULL);
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ /* Skip: Do Nothing */
+ local_skipped_file = TRUE;
+ }
+ else if (response == 2)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+
+ if (create_dest)
+ {
+ flags = (readonly_source_fs) ? G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_TARGET_DEFAULT_PERMS
+ : G_FILE_COPY_NOFOLLOW_SYMLINKS;
+ /* Ignore errors here. Failure to copy metadata is not a hard error */
+ g_file_copy_attributes (src, *dest,
+ flags,
+ job->cancellable, NULL);
+ }
+
+ if (!job_aborted (job) && copy_job->is_move &&
+ /* Don't delete source if there was a skipped file */
+ !local_skipped_file)
+ {
+ if (!g_file_delete (src, job->cancellable, &error))
+ {
+ if (job->skip_all_error)
+ {
+ goto skip;
+ }
+ primary = f (_("Error while moving “%B”."), src);
+ secondary = f (_("Could not remove the source folder."));
+ details = error->message;
+
+ response = run_cancel_or_skip_warning (job,
+ primary,
+ secondary,
+ details,
+ source_info->num_files,
+ source_info->num_files - transfer_info->num_files);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
abort_job (job);
- } else if (response == 1) {
- /* skip all */
+ }
+ else if (response == 1) /* skip all */
+ {
job->skip_all_error = TRUE;
+ local_skipped_file = TRUE;
+ }
+ else if (response == 2) /* skip */
+ {
+ local_skipped_file = TRUE;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+skip:
+ g_error_free (error);
}
+ }
+
+ if (local_skipped_file)
+ {
+ *skipped_file = TRUE;
+ }
+
+ g_free (dest_fs_type);
+ return TRUE;
+}
+
+
+typedef struct
+{
+ CommonJob *job;
+ GFile *source;
+} DeleteExistingFileData;
+
+static void
+existing_file_removed_callback (GFile *file,
+ GError *error,
+ gpointer callback_data)
+{
+ DeleteExistingFileData *data = callback_data;
+ CommonJob *job;
+ GFile *source;
+ GFileType file_type;
+ char *primary;
+ char *secondary;
+ char *details = NULL;
+ int response;
+
+ job = data->job;
+ source = data->source;
+
+ if (error == NULL)
+ {
+ nautilus_file_changes_queue_file_removed (file);
+
+ return;
+ }
+
+ if (job_aborted (job) || job->skip_all_error)
+ {
+ return;
+ }
+
+ primary = f (_("Error while copying “%B”."), source);
+
+ file_type = g_file_query_file_type (file,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ job->cancellable);
+
+ if (file_type == G_FILE_TYPE_DIRECTORY)
+ {
+ secondary = f (_("Could not remove the already existing folder %F."),
+ file);
+ }
+ else
+ {
+ secondary = f (_("Could not remove the already existing file %F."),
+ file);
+ }
+
+ details = error->message;
+
+ /* set show_all to TRUE here, as we don't know how many
+ * files we'll end up processing yet.
+ */
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ TRUE,
+ CANCEL, SKIP_ALL, SKIP,
+ NULL);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1)
+ {
+ /* skip all */
+ job->skip_all_error = TRUE;
+ }
}
-typedef struct {
- CopyMoveJob *job;
- goffset last_size;
- SourceInfo *source_info;
- TransferInfo *transfer_info;
+typedef struct
+{
+ CopyMoveJob *job;
+ goffset last_size;
+ SourceInfo *source_info;
+ TransferInfo *transfer_info;
} ProgressData;
static void
-copy_file_progress_callback (goffset current_num_bytes,
- goffset total_num_bytes,
- gpointer user_data)
+copy_file_progress_callback (goffset current_num_bytes,
+ goffset total_num_bytes,
+ gpointer user_data)
{
- ProgressData *pdata;
- goffset new_size;
+ ProgressData *pdata;
+ goffset new_size;
+
+ pdata = user_data;
- pdata = user_data;
-
- new_size = current_num_bytes - pdata->last_size;
+ new_size = current_num_bytes - pdata->last_size;
- if (new_size > 0) {
- pdata->transfer_info->num_bytes += new_size;
- pdata->last_size = current_num_bytes;
- report_copy_progress (pdata->job,
- pdata->source_info,
- pdata->transfer_info);
- }
+ if (new_size > 0)
+ {
+ pdata->transfer_info->num_bytes += new_size;
+ pdata->last_size = current_num_bytes;
+ report_copy_progress (pdata->job,
+ pdata->source_info,
+ pdata->transfer_info);
+ }
}
static gboolean
-test_dir_is_parent (GFile *child, GFile *root)
-{
- GFile *f, *tmp;
-
- f = g_file_dup (child);
- while (f) {
- if (g_file_equal (f, root)) {
- g_object_unref (f);
- return TRUE;
- }
- tmp = f;
- f = g_file_get_parent (f);
- g_object_unref (tmp);
- }
- if (f) {
- g_object_unref (f);
- }
- return FALSE;
+test_dir_is_parent (GFile *child,
+ GFile *root)
+{
+ GFile *f, *tmp;
+
+ f = g_file_dup (child);
+ while (f)
+ {
+ if (g_file_equal (f, root))
+ {
+ g_object_unref (f);
+ return TRUE;
+ }
+ tmp = f;
+ f = g_file_get_parent (f);
+ g_object_unref (tmp);
+ }
+ if (f)
+ {
+ g_object_unref (f);
+ }
+ return FALSE;
}
static char *
-query_fs_type (GFile *file,
- GCancellable *cancellable)
+query_fs_type (GFile *file,
+ GCancellable *cancellable)
+{
+ GFileInfo *fsinfo;
+ char *ret;
+
+ ret = NULL;
+
+ fsinfo = g_file_query_filesystem_info (file,
+ G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
+ cancellable,
+ NULL);
+ if (fsinfo != NULL)
+ {
+ ret = g_strdup (g_file_info_get_attribute_string (fsinfo, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE));
+ g_object_unref (fsinfo);
+ }
+
+ if (ret == NULL)
+ {
+ /* ensure that we don't attempt to query
+ * the FS type for each file in a given
+ * directory, if it can't be queried. */
+ ret = g_strdup ("");
+ }
+
+ return ret;
+}
+
+static gboolean
+is_trusted_desktop_file (GFile *file,
+ GCancellable *cancellable)
{
- GFileInfo *fsinfo;
- char *ret;
+ char *basename;
+ gboolean res;
+ GFileInfo *info;
- ret = NULL;
+ /* Don't trust non-local files */
+ if (!g_file_is_native (file))
+ {
+ return FALSE;
+ }
- fsinfo = g_file_query_filesystem_info (file,
- G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
- cancellable,
- NULL);
- if (fsinfo != NULL) {
- ret = g_strdup (g_file_info_get_attribute_string (fsinfo, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE));
- g_object_unref (fsinfo);
- }
+ basename = g_file_get_basename (file);
+ if (!g_str_has_suffix (basename, ".desktop"))
+ {
+ g_free (basename);
+ return FALSE;
+ }
+ g_free (basename);
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ cancellable,
+ NULL);
+
+ if (info == NULL)
+ {
+ return FALSE;
+ }
- if (ret == NULL) {
- /* ensure that we don't attempt to query
- * the FS type for each file in a given
- * directory, if it can't be queried. */
- ret = g_strdup ("");
- }
+ res = FALSE;
- return ret;
-}
+ /* Weird file => not trusted,
+ * Already executable => no need to mark trusted */
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR &&
+ !g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) &&
+ nautilus_is_in_system_dir (file))
+ {
+ res = TRUE;
+ }
+ g_object_unref (info);
-static gboolean
-is_trusted_desktop_file (GFile *file,
- GCancellable *cancellable)
-{
- char *basename;
- gboolean res;
- GFileInfo *info;
-
- /* Don't trust non-local files */
- if (!g_file_is_native (file)) {
- return FALSE;
- }
-
- basename = g_file_get_basename (file);
- if (!g_str_has_suffix (basename, ".desktop")) {
- g_free (basename);
- return FALSE;
- }
- g_free (basename);
-
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE ","
- G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- cancellable,
- NULL);
-
- if (info == NULL) {
- return FALSE;
- }
-
- res = FALSE;
-
- /* Weird file => not trusted,
- Already executable => no need to mark trusted */
- if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR &&
- !g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE) &&
- nautilus_is_in_system_dir (file)) {
- res = TRUE;
- }
- g_object_unref (info);
-
- return res;
+ return res;
}
static FileConflictResponse *
@@ -4340,2731 +5002,3107 @@ handle_copy_move_conflict (CommonJob *job,
GFile *dest,
GFile *dest_dir)
{
- FileConflictResponse *response;
+ FileConflictResponse *response;
- g_timer_stop (job->time);
- nautilus_progress_info_pause (job->progress);
+ g_timer_stop (job->time);
+ nautilus_progress_info_pause (job->progress);
- response = copy_move_conflict_ask_user_action (job->parent_window,
- src,
- dest,
- dest_dir);
+ response = copy_move_conflict_ask_user_action (job->parent_window,
+ src,
+ dest,
+ dest_dir);
- nautilus_progress_info_resume (job->progress);
- g_timer_continue (job->time);
+ nautilus_progress_info_resume (job->progress);
+ g_timer_continue (job->time);
- return response;
+ return response;
}
static GFile *
-get_target_file_for_display_name (GFile *dir,
- const gchar *name)
+get_target_file_for_display_name (GFile *dir,
+ const gchar *name)
{
- GFile *dest;
+ GFile *dest;
- dest = NULL;
- dest = g_file_get_child_for_display_name (dir, name, NULL);
+ dest = NULL;
+ dest = g_file_get_child_for_display_name (dir, name, NULL);
+
+ if (dest == NULL)
+ {
+ dest = g_file_get_child (dir, name);
+ }
- if (dest == NULL) {
- dest = g_file_get_child (dir, name);
- }
-
- return dest;
+ return dest;
}
/* Debuting files is non-NULL only for toplevel items */
static void
-copy_move_file (CopyMoveJob *copy_job,
- GFile *src,
- GFile *dest_dir,
- gboolean same_fs,
- gboolean unique_names,
- char **dest_fs_type,
- SourceInfo *source_info,
- TransferInfo *transfer_info,
- GHashTable *debuting_files,
- GdkPoint *position,
- gboolean overwrite,
- gboolean *skipped_file,
- gboolean readonly_source_fs)
-{
- GFile *dest, *new_dest;
- GError *error;
- GFileCopyFlags flags;
- char *primary, *secondary, *details;
- int response;
- ProgressData pdata;
- gboolean would_recurse, is_merge;
- CommonJob *job;
- gboolean res;
- int unique_name_nr;
- gboolean handled_invalid_filename;
-
- job = (CommonJob *)copy_job;
-
- if (should_skip_file (job, src)) {
- *skipped_file = TRUE;
- return;
- }
-
- unique_name_nr = 1;
-
- /* another file in the same directory might have handled the invalid
- * filename condition for us
- */
- handled_invalid_filename = *dest_fs_type != NULL;
-
- if (unique_names) {
- dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
- } else if (copy_job->target_name != NULL) {
- dest = get_target_file_with_custom_name (src, dest_dir, *dest_fs_type, same_fs,
- copy_job->target_name);
- } else {
- dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
- }
-
- /* Don't allow recursive move/copy into itself.
- * (We would get a file system error if we proceeded but it is nicer to
- * detect and report it at this level) */
- if (test_dir_is_parent (dest_dir, src)) {
- if (job->skip_all_error) {
- goto out;
- }
-
- /* the run_warning() frees all strings passed in automatically */
- primary = copy_job->is_move ? g_strdup (_("You cannot move a folder into itself."))
- : g_strdup (_("You cannot copy a folder into itself."));
- secondary = g_strdup (_("The destination folder is inside the source folder."));
-
- response = run_cancel_or_skip_warning (job,
- primary,
- secondary,
- NULL,
- source_info->num_files,
- source_info->num_files - transfer_info->num_files);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
-
- /* Don't allow copying over the source or one of the parents of the source.
- */
- if (test_dir_is_parent (src, dest)) {
- if (job->skip_all_error) {
- goto out;
- }
-
- /* the run_warning() frees all strings passed in automatically */
- primary = copy_job->is_move ? g_strdup (_("You cannot move a file over itself."))
- : g_strdup (_("You cannot copy a file over itself."));
- secondary = g_strdup (_("The source file would be overwritten by the destination."));
-
- response = run_cancel_or_skip_warning (job,
- primary,
- secondary,
- NULL,
- source_info->num_files,
- source_info->num_files - transfer_info->num_files);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
-
-
- retry:
-
- error = NULL;
- flags = G_FILE_COPY_NOFOLLOW_SYMLINKS;
- if (overwrite) {
- flags |= G_FILE_COPY_OVERWRITE;
- }
- if (readonly_source_fs) {
- flags |= G_FILE_COPY_TARGET_DEFAULT_PERMS;
- }
-
- pdata.job = copy_job;
- pdata.last_size = 0;
- pdata.source_info = source_info;
- pdata.transfer_info = transfer_info;
-
- if (copy_job->is_move) {
- res = g_file_move (src, dest,
- flags,
- job->cancellable,
- copy_file_progress_callback,
- &pdata,
- &error);
- } else {
- res = g_file_copy (src, dest,
- flags,
- job->cancellable,
- copy_file_progress_callback,
- &pdata,
- &error);
- }
-
- if (res) {
- GFile *real;
-
- real = map_possibly_volatile_file_to_real (dest, job->cancellable, &error);
- if (real == NULL) {
- res = FALSE;
- } else {
- g_object_unref (dest);
- dest = real;
- }
- }
-
- if (res) {
- transfer_info->num_files ++;
- report_copy_progress (copy_job, source_info, transfer_info);
-
- if (debuting_files) {
- if (position) {
- nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
- } else {
- nautilus_file_changes_queue_schedule_position_remove (dest);
- }
-
- g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
- }
- if (copy_job->is_move) {
- nautilus_file_changes_queue_file_moved (src, dest);
- } else {
- nautilus_file_changes_queue_file_added (dest);
- }
-
- /* If copying a trusted desktop file to the desktop,
- mark it as trusted. */
- if (copy_job->desktop_location != NULL &&
- g_file_equal (copy_job->desktop_location, dest_dir) &&
- is_trusted_desktop_file (src, job->cancellable)) {
- mark_desktop_file_trusted (job,
- job->cancellable,
- dest,
- FALSE);
- }
-
- if (job->undo_info != NULL) {
- nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (job->undo_info),
- src, dest);
- }
-
- g_object_unref (dest);
- return;
- }
-
- if (!handled_invalid_filename &&
- IS_IO_ERROR (error, INVALID_FILENAME)) {
- handled_invalid_filename = TRUE;
-
- g_assert (*dest_fs_type == NULL);
- *dest_fs_type = query_fs_type (dest_dir, job->cancellable);
-
- if (unique_names) {
- new_dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr);
- } else {
- new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
- }
-
- if (!g_file_equal (dest, new_dest)) {
- g_object_unref (dest);
- dest = new_dest;
-
- g_error_free (error);
- goto retry;
- } else {
- g_object_unref (new_dest);
- }
- }
-
- /* Conflict */
- if (!overwrite &&
- IS_IO_ERROR (error, EXISTS)) {
- gboolean is_merge;
- FileConflictResponse *response;
-
- g_error_free (error);
-
- if (unique_names) {
- g_object_unref (dest);
- dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
- goto retry;
- }
-
- is_merge = FALSE;
-
- if (is_dir (dest) && is_dir (src)) {
- is_merge = TRUE;
- }
-
- if ((is_merge && job->merge_all) ||
- (!is_merge && job->replace_all)) {
- overwrite = TRUE;
- goto retry;
- }
-
- if (job->skip_all_conflict) {
- goto out;
- }
-
- response = handle_copy_move_conflict (job, src, dest, dest_dir);
-
- if (response->id == GTK_RESPONSE_CANCEL ||
- response->id == GTK_RESPONSE_DELETE_EVENT) {
- file_conflict_response_free (response);
- abort_job (job);
- } else if (response->id == CONFLICT_RESPONSE_SKIP) {
- if (response->apply_to_all) {
- job->skip_all_conflict = TRUE;
- }
- file_conflict_response_free (response);
- } else if (response->id == CONFLICT_RESPONSE_REPLACE) { /* merge/replace */
- if (response->apply_to_all) {
- if (is_merge) {
- job->merge_all = TRUE;
- } else {
- job->replace_all = TRUE;
- }
- }
- overwrite = TRUE;
- file_conflict_response_free (response);
- goto retry;
- } else if (response->id == CONFLICT_RESPONSE_RENAME) {
- g_object_unref (dest);
- dest = get_target_file_for_display_name (dest_dir,
- response->new_name);
- file_conflict_response_free (response);
- goto retry;
- } else {
- g_assert_not_reached ();
- }
- }
-
- else if (overwrite &&
- IS_IO_ERROR (error, IS_DIRECTORY)) {
- gboolean existing_file_deleted;
- DeleteExistingFileData data;
-
- g_error_free (error);
-
- data.job = job;
- data.source = src;
-
- existing_file_deleted =
- delete_file_recursively (dest,
- job->cancellable,
- existing_file_removed_callback,
- &data);
-
- if (existing_file_deleted) {
- goto retry;
+copy_move_file (CopyMoveJob *copy_job,
+ GFile *src,
+ GFile *dest_dir,
+ gboolean same_fs,
+ gboolean unique_names,
+ char **dest_fs_type,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info,
+ GHashTable *debuting_files,
+ GdkPoint *position,
+ gboolean overwrite,
+ gboolean *skipped_file,
+ gboolean readonly_source_fs)
+{
+ GFile *dest, *new_dest;
+ GError *error;
+ GFileCopyFlags flags;
+ char *primary, *secondary, *details;
+ int response;
+ ProgressData pdata;
+ gboolean would_recurse, is_merge;
+ CommonJob *job;
+ gboolean res;
+ int unique_name_nr;
+ gboolean handled_invalid_filename;
+
+ job = (CommonJob *) copy_job;
+
+ if (should_skip_file (job, src))
+ {
+ *skipped_file = TRUE;
+ return;
+ }
+
+ unique_name_nr = 1;
+
+ /* another file in the same directory might have handled the invalid
+ * filename condition for us
+ */
+ handled_invalid_filename = *dest_fs_type != NULL;
+
+ if (unique_names)
+ {
+ dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
+ }
+ else if (copy_job->target_name != NULL)
+ {
+ dest = get_target_file_with_custom_name (src, dest_dir, *dest_fs_type, same_fs,
+ copy_job->target_name);
+ }
+ else
+ {
+ dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+ }
+
+ /* Don't allow recursive move/copy into itself.
+ * (We would get a file system error if we proceeded but it is nicer to
+ * detect and report it at this level) */
+ if (test_dir_is_parent (dest_dir, src))
+ {
+ if (job->skip_all_error)
+ {
+ goto out;
+ }
+
+ /* the run_warning() frees all strings passed in automatically */
+ primary = copy_job->is_move ? g_strdup (_("You cannot move a folder into itself."))
+ : g_strdup (_("You cannot copy a folder into itself."));
+ secondary = g_strdup (_("The destination folder is inside the source folder."));
+
+ response = run_cancel_or_skip_warning (job,
+ primary,
+ secondary,
+ NULL,
+ source_info->num_files,
+ source_info->num_files - transfer_info->num_files);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+
+ /* Don't allow copying over the source or one of the parents of the source.
+ */
+ if (test_dir_is_parent (src, dest))
+ {
+ if (job->skip_all_error)
+ {
+ goto out;
+ }
+
+ /* the run_warning() frees all strings passed in automatically */
+ primary = copy_job->is_move ? g_strdup (_("You cannot move a file over itself."))
+ : g_strdup (_("You cannot copy a file over itself."));
+ secondary = g_strdup (_("The source file would be overwritten by the destination."));
+
+ response = run_cancel_or_skip_warning (job,
+ primary,
+ secondary,
+ NULL,
+ source_info->num_files,
+ source_info->num_files - transfer_info->num_files);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+
+
+retry:
+
+ error = NULL;
+ flags = G_FILE_COPY_NOFOLLOW_SYMLINKS;
+ if (overwrite)
+ {
+ flags |= G_FILE_COPY_OVERWRITE;
+ }
+ if (readonly_source_fs)
+ {
+ flags |= G_FILE_COPY_TARGET_DEFAULT_PERMS;
+ }
+
+ pdata.job = copy_job;
+ pdata.last_size = 0;
+ pdata.source_info = source_info;
+ pdata.transfer_info = transfer_info;
+
+ if (copy_job->is_move)
+ {
+ res = g_file_move (src, dest,
+ flags,
+ job->cancellable,
+ copy_file_progress_callback,
+ &pdata,
+ &error);
+ }
+ else
+ {
+ res = g_file_copy (src, dest,
+ flags,
+ job->cancellable,
+ copy_file_progress_callback,
+ &pdata,
+ &error);
+ }
+
+ if (res)
+ {
+ GFile *real;
+
+ real = map_possibly_volatile_file_to_real (dest, job->cancellable, &error);
+ if (real == NULL)
+ {
+ res = FALSE;
+ }
+ else
+ {
+ g_object_unref (dest);
+ dest = real;
+ }
+ }
+
+ if (res)
+ {
+ transfer_info->num_files++;
+ report_copy_progress (copy_job, source_info, transfer_info);
+
+ if (debuting_files)
+ {
+ if (position)
+ {
+ nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
+ }
+ else
+ {
+ nautilus_file_changes_queue_schedule_position_remove (dest);
+ }
+
+ g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
+ }
+ if (copy_job->is_move)
+ {
+ nautilus_file_changes_queue_file_moved (src, dest);
+ }
+ else
+ {
+ nautilus_file_changes_queue_file_added (dest);
+ }
+
+ /* If copying a trusted desktop file to the desktop,
+ * mark it as trusted. */
+ if (copy_job->desktop_location != NULL &&
+ g_file_equal (copy_job->desktop_location, dest_dir) &&
+ is_trusted_desktop_file (src, job->cancellable))
+ {
+ mark_desktop_file_trusted (job,
+ job->cancellable,
+ dest,
+ FALSE);
+ }
+
+ if (job->undo_info != NULL)
+ {
+ nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (job->undo_info),
+ src, dest);
+ }
+
+ g_object_unref (dest);
+ return;
+ }
+
+ if (!handled_invalid_filename &&
+ IS_IO_ERROR (error, INVALID_FILENAME))
+ {
+ handled_invalid_filename = TRUE;
+
+ g_assert (*dest_fs_type == NULL);
+ *dest_fs_type = query_fs_type (dest_dir, job->cancellable);
+
+ if (unique_names)
+ {
+ new_dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr);
+ }
+ else
+ {
+ new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+ }
+
+ if (!g_file_equal (dest, new_dest))
+ {
+ g_object_unref (dest);
+ dest = new_dest;
+
+ g_error_free (error);
+ goto retry;
+ }
+ else
+ {
+ g_object_unref (new_dest);
+ }
+ }
+
+ /* Conflict */
+ if (!overwrite &&
+ IS_IO_ERROR (error, EXISTS))
+ {
+ gboolean is_merge;
+ FileConflictResponse *response;
+
+ g_error_free (error);
+
+ if (unique_names)
+ {
+ g_object_unref (dest);
+ dest = get_unique_target_file (src, dest_dir, same_fs, *dest_fs_type, unique_name_nr++);
+ goto retry;
+ }
+
+ is_merge = FALSE;
+
+ if (is_dir (dest) && is_dir (src))
+ {
+ is_merge = TRUE;
+ }
+
+ if ((is_merge && job->merge_all) ||
+ (!is_merge && job->replace_all))
+ {
+ overwrite = TRUE;
+ goto retry;
+ }
+
+ if (job->skip_all_conflict)
+ {
+ goto out;
+ }
+
+ response = handle_copy_move_conflict (job, src, dest, dest_dir);
+
+ if (response->id == GTK_RESPONSE_CANCEL ||
+ response->id == GTK_RESPONSE_DELETE_EVENT)
+ {
+ file_conflict_response_free (response);
+ abort_job (job);
+ }
+ else if (response->id == CONFLICT_RESPONSE_SKIP)
+ {
+ if (response->apply_to_all)
+ {
+ job->skip_all_conflict = TRUE;
+ }
+ file_conflict_response_free (response);
+ }
+ else if (response->id == CONFLICT_RESPONSE_REPLACE) /* merge/replace */
+ {
+ if (response->apply_to_all)
+ {
+ if (is_merge)
+ {
+ job->merge_all = TRUE;
+ }
+ else
+ {
+ job->replace_all = TRUE;
+ }
+ }
+ overwrite = TRUE;
+ file_conflict_response_free (response);
+ goto retry;
+ }
+ else if (response->id == CONFLICT_RESPONSE_RENAME)
+ {
+ g_object_unref (dest);
+ dest = get_target_file_for_display_name (dest_dir,
+ response->new_name);
+ file_conflict_response_free (response);
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ else if (overwrite &&
+ IS_IO_ERROR (error, IS_DIRECTORY))
+ {
+ gboolean existing_file_deleted;
+ DeleteExistingFileData data;
+
+ g_error_free (error);
+
+ data.job = job;
+ data.source = src;
+
+ existing_file_deleted =
+ delete_file_recursively (dest,
+ job->cancellable,
+ existing_file_removed_callback,
+ &data);
+
+ if (existing_file_deleted)
+ {
+ goto retry;
+ }
+ }
+ /* Needs to recurse */
+ else if (IS_IO_ERROR (error, WOULD_RECURSE) ||
+ IS_IO_ERROR (error, WOULD_MERGE))
+ {
+ is_merge = error->code == G_IO_ERROR_WOULD_MERGE;
+ would_recurse = error->code == G_IO_ERROR_WOULD_RECURSE;
+ g_error_free (error);
+
+ if (overwrite && would_recurse)
+ {
+ error = NULL;
+
+ /* Copying a dir onto file, first remove the file */
+ if (!g_file_delete (dest, job->cancellable, &error) &&
+ !IS_IO_ERROR (error, NOT_FOUND))
+ {
+ if (job->skip_all_error)
+ {
+ g_error_free (error);
+ goto out;
+ }
+ if (copy_job->is_move)
+ {
+ primary = f (_("Error while moving “%B”."), src);
+ }
+ else
+ {
+ primary = f (_("Error while copying “%B”."), src);
}
- }
-
- /* Needs to recurse */
- else if (IS_IO_ERROR (error, WOULD_RECURSE) ||
- IS_IO_ERROR (error, WOULD_MERGE)) {
- is_merge = error->code == G_IO_ERROR_WOULD_MERGE;
- would_recurse = error->code == G_IO_ERROR_WOULD_RECURSE;
- g_error_free (error);
-
- if (overwrite && would_recurse) {
- error = NULL;
-
- /* Copying a dir onto file, first remove the file */
- if (!g_file_delete (dest, job->cancellable, &error) &&
- !IS_IO_ERROR (error, NOT_FOUND)) {
- if (job->skip_all_error) {
- g_error_free (error);
- goto out;
- }
- if (copy_job->is_move) {
- primary = f (_("Error while moving “%B”."), src);
- } else {
- primary = f (_("Error while copying “%B”."), src);
- }
- secondary = f (_("Could not remove the already existing file with the same name in %F."), dest_dir);
- details = error->message;
-
- /* setting TRUE on show_all here, as we could have
- * another error on the same file later.
- */
- response = run_warning (job,
- primary,
- secondary,
- details,
- TRUE,
- CANCEL, SKIP_ALL, SKIP,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
- goto out;
-
- }
- if (error) {
- g_error_free (error);
- error = NULL;
- }
- nautilus_file_changes_queue_file_removed (dest);
- }
-
- if (is_merge) {
- /* On merge we now write in the target directory, which may not
- be in the same directory as the source, even if the parent is
- (if the merged directory is a mountpoint). This could cause
- problems as we then don't transcode filenames.
- We just set same_fs to FALSE which is safe but a bit slower. */
- same_fs = FALSE;
- }
-
- if (!copy_move_directory (copy_job, src, &dest, same_fs,
- would_recurse, dest_fs_type,
- source_info, transfer_info,
- debuting_files, skipped_file,
- readonly_source_fs)) {
- /* destination changed, since it was an invalid file name */
- g_assert (*dest_fs_type != NULL);
- handled_invalid_filename = TRUE;
- goto retry;
- }
-
- g_object_unref (dest);
- return;
- }
-
- else if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- }
-
- /* Other error */
- else {
- if (job->skip_all_error) {
- g_error_free (error);
- goto out;
- }
- primary = f (_("Error while copying “%B”."), src);
- secondary = f (_("There was an error copying the file into %F."), dest_dir);
- details = error->message;
-
- response = run_cancel_or_skip_warning (job,
- primary,
- secondary,
- details,
- source_info->num_files,
- source_info->num_files - transfer_info->num_files);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
- }
- out:
- *skipped_file = TRUE; /* Or aborted, but same-same */
- g_object_unref (dest);
+ secondary = f (_("Could not remove the already existing file with the same name in %F."), dest_dir);
+ details = error->message;
+
+ /* setting TRUE on show_all here, as we could have
+ * another error on the same file later.
+ */
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ TRUE,
+ CANCEL, SKIP_ALL, SKIP,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ goto out;
+ }
+ if (error)
+ {
+ g_error_free (error);
+ error = NULL;
+ }
+ nautilus_file_changes_queue_file_removed (dest);
+ }
+
+ if (is_merge)
+ {
+ /* On merge we now write in the target directory, which may not
+ * be in the same directory as the source, even if the parent is
+ * (if the merged directory is a mountpoint). This could cause
+ * problems as we then don't transcode filenames.
+ * We just set same_fs to FALSE which is safe but a bit slower. */
+ same_fs = FALSE;
+ }
+
+ if (!copy_move_directory (copy_job, src, &dest, same_fs,
+ would_recurse, dest_fs_type,
+ source_info, transfer_info,
+ debuting_files, skipped_file,
+ readonly_source_fs))
+ {
+ /* destination changed, since it was an invalid file name */
+ g_assert (*dest_fs_type != NULL);
+ handled_invalid_filename = TRUE;
+ goto retry;
+ }
+
+ g_object_unref (dest);
+ return;
+ }
+ else if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ /* Other error */
+ else
+ {
+ if (job->skip_all_error)
+ {
+ g_error_free (error);
+ goto out;
+ }
+ primary = f (_("Error while copying “%B”."), src);
+ secondary = f (_("There was an error copying the file into %F."), dest_dir);
+ details = error->message;
+
+ response = run_cancel_or_skip_warning (job,
+ primary,
+ secondary,
+ details,
+ source_info->num_files,
+ source_info->num_files - transfer_info->num_files);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+out:
+ *skipped_file = TRUE; /* Or aborted, but same-same */
+ g_object_unref (dest);
}
static void
-copy_files (CopyMoveJob *job,
- const char *dest_fs_id,
- SourceInfo *source_info,
- TransferInfo *transfer_info)
-{
- CommonJob *common;
- GList *l;
- GFile *src;
- gboolean same_fs;
- int i;
- GdkPoint *point;
- gboolean skipped_file;
- gboolean unique_names;
- GFile *dest;
- GFile *source_dir;
- char *dest_fs_type;
- GFileInfo *inf;
- gboolean readonly_source_fs;
-
- dest_fs_type = NULL;
- readonly_source_fs = FALSE;
-
- common = &job->common;
-
- report_copy_progress (job, source_info, transfer_info);
-
- /* Query the source dir, not the file because if it's a symlink we'll follow it */
- source_dir = g_file_get_parent ((GFile *) job->files->data);
- if (source_dir) {
- inf = g_file_query_filesystem_info (source_dir, "filesystem::readonly", NULL, NULL);
- if (inf != NULL) {
- readonly_source_fs = g_file_info_get_attribute_boolean (inf, "filesystem::readonly");
- g_object_unref (inf);
- }
- g_object_unref (source_dir);
- }
-
- unique_names = (job->destination == NULL);
- i = 0;
- for (l = job->files;
- l != NULL && !job_aborted (common);
- l = l->next) {
- src = l->data;
-
- if (i < job->n_icon_positions) {
- point = &job->icon_positions[i];
- } else {
- point = NULL;
- }
-
-
- same_fs = FALSE;
- if (dest_fs_id) {
- same_fs = has_fs_id (src, dest_fs_id);
- }
-
- if (job->destination) {
- dest = g_object_ref (job->destination);
- } else {
- dest = g_file_get_parent (src);
-
- }
- if (dest) {
- skipped_file = FALSE;
- copy_move_file (job, src, dest,
- same_fs, unique_names,
- &dest_fs_type,
- source_info, transfer_info,
- job->debuting_files,
- point, FALSE, &skipped_file,
- readonly_source_fs);
- g_object_unref (dest);
-
- if (skipped_file) {
- transfer_add_file_to_count (src, common, transfer_info);
- report_copy_progress (job, source_info, transfer_info);
- }
- }
- i++;
- }
-
- g_free (dest_fs_type);
+copy_files (CopyMoveJob *job,
+ const char *dest_fs_id,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info)
+{
+ CommonJob *common;
+ GList *l;
+ GFile *src;
+ gboolean same_fs;
+ int i;
+ GdkPoint *point;
+ gboolean skipped_file;
+ gboolean unique_names;
+ GFile *dest;
+ GFile *source_dir;
+ char *dest_fs_type;
+ GFileInfo *inf;
+ gboolean readonly_source_fs;
+
+ dest_fs_type = NULL;
+ readonly_source_fs = FALSE;
+
+ common = &job->common;
+
+ report_copy_progress (job, source_info, transfer_info);
+
+ /* Query the source dir, not the file because if it's a symlink we'll follow it */
+ source_dir = g_file_get_parent ((GFile *) job->files->data);
+ if (source_dir)
+ {
+ inf = g_file_query_filesystem_info (source_dir, "filesystem::readonly", NULL, NULL);
+ if (inf != NULL)
+ {
+ readonly_source_fs = g_file_info_get_attribute_boolean (inf, "filesystem::readonly");
+ g_object_unref (inf);
+ }
+ g_object_unref (source_dir);
+ }
+
+ unique_names = (job->destination == NULL);
+ i = 0;
+ for (l = job->files;
+ l != NULL && !job_aborted (common);
+ l = l->next)
+ {
+ src = l->data;
+
+ if (i < job->n_icon_positions)
+ {
+ point = &job->icon_positions[i];
+ }
+ else
+ {
+ point = NULL;
+ }
+
+
+ same_fs = FALSE;
+ if (dest_fs_id)
+ {
+ same_fs = has_fs_id (src, dest_fs_id);
+ }
+
+ if (job->destination)
+ {
+ dest = g_object_ref (job->destination);
+ }
+ else
+ {
+ dest = g_file_get_parent (src);
+ }
+ if (dest)
+ {
+ skipped_file = FALSE;
+ copy_move_file (job, src, dest,
+ same_fs, unique_names,
+ &dest_fs_type,
+ source_info, transfer_info,
+ job->debuting_files,
+ point, FALSE, &skipped_file,
+ readonly_source_fs);
+ g_object_unref (dest);
+
+ if (skipped_file)
+ {
+ transfer_add_file_to_count (src, common, transfer_info);
+ report_copy_progress (job, source_info, transfer_info);
+ }
+ }
+ i++;
+ }
+
+ g_free (dest_fs_type);
}
static void
-copy_task_done (GObject *source_object,
+copy_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- CopyMoveJob *job;
+ CopyMoveJob *job;
- job = user_data;
- if (job->done_callback) {
- job->done_callback (job->debuting_files,
- !job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
+ job = user_data;
+ if (job->done_callback)
+ {
+ job->done_callback (job->debuting_files,
+ !job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
- g_list_free_full (job->files, g_object_unref);
- if (job->destination) {
- g_object_unref (job->destination);
- }
- if (job->desktop_location) {
- g_object_unref (job->desktop_location);
- }
- g_hash_table_unref (job->debuting_files);
- g_free (job->icon_positions);
- g_free (job->target_name);
+ g_list_free_full (job->files, g_object_unref);
+ if (job->destination)
+ {
+ g_object_unref (job->destination);
+ }
+ if (job->desktop_location)
+ {
+ g_object_unref (job->desktop_location);
+ }
+ g_hash_table_unref (job->debuting_files);
+ g_free (job->icon_positions);
+ g_free (job->target_name);
+
+ g_clear_object (&job->fake_display_source);
- g_clear_object (&job->fake_display_source);
-
- finalize_common ((CommonJob *)job);
+ finalize_common ((CommonJob *) job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
static void
-copy_task_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+copy_task_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- CopyMoveJob *job;
- CommonJob *common;
- SourceInfo source_info;
- TransferInfo transfer_info;
- char *dest_fs_id;
- GFile *dest;
-
- job = task_data;
- common = &job->common;
-
- dest_fs_id = NULL;
-
- nautilus_progress_info_start (job->common.progress);
-
- scan_sources (job->files,
- &source_info,
- common,
- OP_KIND_COPY);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- if (job->destination) {
- dest = g_object_ref (job->destination);
- } else {
- /* Duplication, no dest,
- * use source for free size, etc
- */
- dest = g_file_get_parent (job->files->data);
- }
-
- verify_destination (&job->common,
- dest,
- &dest_fs_id,
- source_info.num_bytes);
- g_object_unref (dest);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- g_timer_start (job->common.time);
-
- memset (&transfer_info, 0, sizeof (transfer_info));
- copy_files (job,
- dest_fs_id,
- &source_info, &transfer_info);
-
- aborted:
-
- g_free (dest_fs_id);
-}
+ CopyMoveJob *job;
+ CommonJob *common;
+ SourceInfo source_info;
+ TransferInfo transfer_info;
+ char *dest_fs_id;
+ GFile *dest;
-void
-nautilus_file_operations_copy_file (GFile *source_file,
- GFile *target_dir,
- const gchar *source_display_name,
- const gchar *new_name,
- GtkWindow *parent_window,
- NautilusCopyCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CopyMoveJob *job;
+ job = task_data;
+ common = &job->common;
- job = op_job_new (CopyMoveJob, parent_window);
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->files = g_list_append (NULL, g_object_ref (source_file));
- job->destination = g_object_ref (target_dir);
- /* Need to indicate the destination for the operation notification open
- * button. */
- nautilus_progress_info_set_destination (((CommonJob *)job)->progress, target_dir);
- job->target_name = g_strdup (new_name);
- job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
+ dest_fs_id = NULL;
- if (source_display_name != NULL) {
- gchar *path;
+ nautilus_progress_info_start (job->common.progress);
- path = g_build_filename ("/", source_display_name, NULL);
- job->fake_display_source = g_file_new_for_path (path);
+ scan_sources (job->files,
+ &source_info,
+ common,
+ OP_KIND_COPY);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
- g_free (path);
- }
+ if (job->destination)
+ {
+ dest = g_object_ref (job->destination);
+ }
+ else
+ {
+ /* Duplication, no dest,
+ * use source for free size, etc
+ */
+ dest = g_file_get_parent (job->files->data);
+ }
- inhibit_power_manager ((CommonJob *)job, _("Copying Files"));
+ verify_destination (&job->common,
+ dest,
+ &dest_fs_id,
+ source_info.num_bytes);
+ g_object_unref (dest);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
- task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, copy_task_thread_func);
- g_object_unref (task);
+ g_timer_start (job->common.time);
+
+ memset (&transfer_info, 0, sizeof (transfer_info));
+ copy_files (job,
+ dest_fs_id,
+ &source_info, &transfer_info);
+
+aborted:
+
+ g_free (dest_fs_id);
}
void
-nautilus_file_operations_copy (GList *files,
- GArray *relative_item_points,
- GFile *target_dir,
- GtkWindow *parent_window,
- NautilusCopyCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CopyMoveJob *job;
-
- job = op_job_new (CopyMoveJob, parent_window);
- job->desktop_location = nautilus_get_desktop_location ();
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
- job->destination = g_object_ref (target_dir);
- /* Need to indicate the destination for the operation notification open
- * button. */
- nautilus_progress_info_set_destination (((CommonJob *)job)->progress, target_dir);
- if (relative_item_points != NULL &&
- relative_item_points->len > 0) {
- job->icon_positions =
- g_memdup (relative_item_points->data,
- sizeof (GdkPoint) * relative_item_points->len);
- job->n_icon_positions = relative_item_points->len;
- }
- job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
-
- inhibit_power_manager ((CommonJob *)job, _("Copying Files"));
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- GFile* src_dir;
-
- src_dir = g_file_get_parent (files->data);
- job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_COPY,
- g_list_length (files),
- src_dir, target_dir);
-
- g_object_unref (src_dir);
- }
-
- task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, copy_task_thread_func);
- g_object_unref (task);
+nautilus_file_operations_copy_file (GFile *source_file,
+ GFile *target_dir,
+ const gchar *source_display_name,
+ const gchar *new_name,
+ GtkWindow *parent_window,
+ NautilusCopyCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CopyMoveJob *job;
+
+ job = op_job_new (CopyMoveJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->files = g_list_append (NULL, g_object_ref (source_file));
+ job->destination = g_object_ref (target_dir);
+ /* Need to indicate the destination for the operation notification open
+ * button. */
+ nautilus_progress_info_set_destination (((CommonJob *) job)->progress, target_dir);
+ job->target_name = g_strdup (new_name);
+ job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+
+ if (source_display_name != NULL)
+ {
+ gchar *path;
+
+ path = g_build_filename ("/", source_display_name, NULL);
+ job->fake_display_source = g_file_new_for_path (path);
+
+ g_free (path);
+ }
+
+ inhibit_power_manager ((CommonJob *) job, _("Copying Files"));
+
+ task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, copy_task_thread_func);
+ g_object_unref (task);
+}
+
+void
+nautilus_file_operations_copy (GList *files,
+ GArray *relative_item_points,
+ GFile *target_dir,
+ GtkWindow *parent_window,
+ NautilusCopyCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CopyMoveJob *job;
+
+ job = op_job_new (CopyMoveJob, parent_window);
+ job->desktop_location = nautilus_get_desktop_location ();
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
+ job->destination = g_object_ref (target_dir);
+ /* Need to indicate the destination for the operation notification open
+ * button. */
+ nautilus_progress_info_set_destination (((CommonJob *) job)->progress, target_dir);
+ if (relative_item_points != NULL &&
+ relative_item_points->len > 0)
+ {
+ job->icon_positions =
+ g_memdup (relative_item_points->data,
+ sizeof (GdkPoint) * relative_item_points->len);
+ job->n_icon_positions = relative_item_points->len;
+ }
+ job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+
+ inhibit_power_manager ((CommonJob *) job, _("Copying Files"));
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ GFile *src_dir;
+
+ src_dir = g_file_get_parent (files->data);
+ job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_COPY,
+ g_list_length (files),
+ src_dir, target_dir);
+
+ g_object_unref (src_dir);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, copy_task_thread_func);
+ g_object_unref (task);
}
static void
-report_preparing_move_progress (CopyMoveJob *move_job, int total, int left)
+report_preparing_move_progress (CopyMoveJob *move_job,
+ int total,
+ int left)
{
- CommonJob *job;
+ CommonJob *job;
+
+ job = (CommonJob *) move_job;
- job = (CommonJob *)move_job;
-
- nautilus_progress_info_take_status (job->progress,
- f (_("Preparing to move to “%B”"),
- move_job->destination));
+ nautilus_progress_info_take_status (job->progress,
+ f (_("Preparing to move to “%B”"),
+ move_job->destination));
- nautilus_progress_info_take_details (job->progress,
- f (ngettext ("Preparing to move %'d file",
- "Preparing to move %'d files",
- left), left));
+ nautilus_progress_info_take_details (job->progress,
+ f (ngettext ("Preparing to move %'d file",
+ "Preparing to move %'d files",
+ left), left));
- nautilus_progress_info_pulse_progress (job->progress);
+ nautilus_progress_info_pulse_progress (job->progress);
}
-typedef struct {
- GFile *file;
- gboolean overwrite;
- gboolean has_position;
- GdkPoint position;
+typedef struct
+{
+ GFile *file;
+ gboolean overwrite;
+ gboolean has_position;
+ GdkPoint position;
} MoveFileCopyFallback;
static MoveFileCopyFallback *
-move_copy_file_callback_new (GFile *file,
- gboolean overwrite,
- GdkPoint *position)
-{
- MoveFileCopyFallback *fallback;
-
- fallback = g_new (MoveFileCopyFallback, 1);
- fallback->file = file;
- fallback->overwrite = overwrite;
- if (position) {
- fallback->has_position = TRUE;
- fallback->position = *position;
- } else {
- fallback->has_position = FALSE;
- }
+move_copy_file_callback_new (GFile *file,
+ gboolean overwrite,
+ GdkPoint *position)
+{
+ MoveFileCopyFallback *fallback;
+
+ fallback = g_new (MoveFileCopyFallback, 1);
+ fallback->file = file;
+ fallback->overwrite = overwrite;
+ if (position)
+ {
+ fallback->has_position = TRUE;
+ fallback->position = *position;
+ }
+ else
+ {
+ fallback->has_position = FALSE;
+ }
- return fallback;
+ return fallback;
}
static GList *
get_files_from_fallbacks (GList *fallbacks)
{
- MoveFileCopyFallback *fallback;
- GList *res, *l;
+ MoveFileCopyFallback *fallback;
+ GList *res, *l;
- res = NULL;
- for (l = fallbacks; l != NULL; l = l->next) {
- fallback = l->data;
- res = g_list_prepend (res, fallback->file);
- }
- return g_list_reverse (res);
+ res = NULL;
+ for (l = fallbacks; l != NULL; l = l->next)
+ {
+ fallback = l->data;
+ res = g_list_prepend (res, fallback->file);
+ }
+ return g_list_reverse (res);
}
static void
-move_file_prepare (CopyMoveJob *move_job,
- GFile *src,
- GFile *dest_dir,
- gboolean same_fs,
- char **dest_fs_type,
- GHashTable *debuting_files,
- GdkPoint *position,
- GList **fallback_files,
- int files_left)
-{
- GFile *dest, *new_dest;
- GError *error;
- CommonJob *job;
- gboolean overwrite;
- char *primary, *secondary, *details;
- int response;
- GFileCopyFlags flags;
- MoveFileCopyFallback *fallback;
- gboolean handled_invalid_filename;
-
- overwrite = FALSE;
- handled_invalid_filename = *dest_fs_type != NULL;
-
- job = (CommonJob *)move_job;
-
- dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
-
-
- /* Don't allow recursive move/copy into itself.
- * (We would get a file system error if we proceeded but it is nicer to
- * detect and report it at this level) */
- if (test_dir_is_parent (dest_dir, src)) {
- if (job->skip_all_error) {
- goto out;
- }
-
- /* the run_warning() frees all strings passed in automatically */
- primary = move_job->is_move ? g_strdup (_("You cannot move a folder into itself."))
- : g_strdup (_("You cannot copy a folder into itself."));
- secondary = g_strdup (_("The destination folder is inside the source folder."));
-
- response = run_warning (job,
- primary,
- secondary,
- NULL,
- files_left > 1,
- CANCEL, SKIP_ALL, SKIP,
- NULL);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
-
- retry:
-
- flags = G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_NO_FALLBACK_FOR_MOVE;
- if (overwrite) {
- flags |= G_FILE_COPY_OVERWRITE;
- }
-
- error = NULL;
- if (g_file_move (src, dest,
- flags,
- job->cancellable,
- NULL,
- NULL,
- &error)) {
-
- if (debuting_files) {
- g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
- }
-
- nautilus_file_changes_queue_file_moved (src, dest);
-
- if (position) {
- nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
- } else {
- nautilus_file_changes_queue_schedule_position_remove (dest);
- }
-
- if (job->undo_info != NULL) {
- nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (job->undo_info),
- src, dest);
- }
-
- return;
- }
-
- if (IS_IO_ERROR (error, INVALID_FILENAME) &&
- !handled_invalid_filename) {
- g_error_free (error);
-
- handled_invalid_filename = TRUE;
-
- g_assert (*dest_fs_type == NULL);
- *dest_fs_type = query_fs_type (dest_dir, job->cancellable);
-
- new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
- if (!g_file_equal (dest, new_dest)) {
- g_object_unref (dest);
- dest = new_dest;
- goto retry;
- } else {
- g_object_unref (new_dest);
- }
- }
-
- /* Conflict */
- else if (!overwrite &&
- IS_IO_ERROR (error, EXISTS)) {
- gboolean is_merge;
- FileConflictResponse *response;
-
- g_error_free (error);
-
- is_merge = FALSE;
- if (is_dir (dest) && is_dir (src)) {
- is_merge = TRUE;
- }
-
- if ((is_merge && job->merge_all) ||
- (!is_merge && job->replace_all)) {
- overwrite = TRUE;
- goto retry;
- }
-
- if (job->skip_all_conflict) {
- goto out;
- }
-
- response = handle_copy_move_conflict (job, src, dest, dest_dir);
-
- if (response->id == GTK_RESPONSE_CANCEL ||
- response->id == GTK_RESPONSE_DELETE_EVENT) {
- file_conflict_response_free (response);
- abort_job (job);
- } else if (response->id == CONFLICT_RESPONSE_SKIP) {
- if (response->apply_to_all) {
- job->skip_all_conflict = TRUE;
- }
- file_conflict_response_free (response);
- } else if (response->id == CONFLICT_RESPONSE_REPLACE) { /* merge/replace */
- if (response->apply_to_all) {
- if (is_merge) {
- job->merge_all = TRUE;
- } else {
- job->replace_all = TRUE;
- }
- }
- overwrite = TRUE;
- file_conflict_response_free (response);
- goto retry;
- } else if (response->id == CONFLICT_RESPONSE_RENAME) {
- g_object_unref (dest);
- dest = get_target_file_for_display_name (dest_dir,
- response->new_name);
- file_conflict_response_free (response);
- goto retry;
- } else {
- g_assert_not_reached ();
- }
- }
-
- else if (IS_IO_ERROR (error, WOULD_RECURSE) ||
- IS_IO_ERROR (error, WOULD_MERGE) ||
- IS_IO_ERROR (error, NOT_SUPPORTED) ||
- (overwrite && IS_IO_ERROR (error, IS_DIRECTORY))) {
- g_error_free (error);
-
- fallback = move_copy_file_callback_new (src,
- overwrite,
- position);
- *fallback_files = g_list_prepend (*fallback_files, fallback);
- }
-
- else if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- }
-
- /* Other error */
- else {
- if (job->skip_all_error) {
- g_error_free (error);
- goto out;
- }
- primary = f (_("Error while moving “%B”."), src);
- secondary = f (_("There was an error moving the file into %F."), dest_dir);
- details = error->message;
-
- response = run_warning (job,
- primary,
- secondary,
- details,
- files_left > 1,
- CANCEL, SKIP_ALL, SKIP,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (job);
- } else if (response == 1) { /* skip all */
- job->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
- }
-
- out:
- g_object_unref (dest);
+move_file_prepare (CopyMoveJob *move_job,
+ GFile *src,
+ GFile *dest_dir,
+ gboolean same_fs,
+ char **dest_fs_type,
+ GHashTable *debuting_files,
+ GdkPoint *position,
+ GList **fallback_files,
+ int files_left)
+{
+ GFile *dest, *new_dest;
+ GError *error;
+ CommonJob *job;
+ gboolean overwrite;
+ char *primary, *secondary, *details;
+ int response;
+ GFileCopyFlags flags;
+ MoveFileCopyFallback *fallback;
+ gboolean handled_invalid_filename;
+
+ overwrite = FALSE;
+ handled_invalid_filename = *dest_fs_type != NULL;
+
+ job = (CommonJob *) move_job;
+
+ dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+
+
+ /* Don't allow recursive move/copy into itself.
+ * (We would get a file system error if we proceeded but it is nicer to
+ * detect and report it at this level) */
+ if (test_dir_is_parent (dest_dir, src))
+ {
+ if (job->skip_all_error)
+ {
+ goto out;
+ }
+
+ /* the run_warning() frees all strings passed in automatically */
+ primary = move_job->is_move ? g_strdup (_("You cannot move a folder into itself."))
+ : g_strdup (_("You cannot copy a folder into itself."));
+ secondary = g_strdup (_("The destination folder is inside the source folder."));
+
+ response = run_warning (job,
+ primary,
+ secondary,
+ NULL,
+ files_left > 1,
+ CANCEL, SKIP_ALL, SKIP,
+ NULL);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+
+retry:
+
+ flags = G_FILE_COPY_NOFOLLOW_SYMLINKS | G_FILE_COPY_NO_FALLBACK_FOR_MOVE;
+ if (overwrite)
+ {
+ flags |= G_FILE_COPY_OVERWRITE;
+ }
+
+ error = NULL;
+ if (g_file_move (src, dest,
+ flags,
+ job->cancellable,
+ NULL,
+ NULL,
+ &error))
+ {
+ if (debuting_files)
+ {
+ g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
+ }
+
+ nautilus_file_changes_queue_file_moved (src, dest);
+
+ if (position)
+ {
+ nautilus_file_changes_queue_schedule_position_set (dest, *position, job->screen_num);
+ }
+ else
+ {
+ nautilus_file_changes_queue_schedule_position_remove (dest);
+ }
+
+ if (job->undo_info != NULL)
+ {
+ nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (job->undo_info),
+ src, dest);
+ }
+
+ return;
+ }
+
+ if (IS_IO_ERROR (error, INVALID_FILENAME) &&
+ !handled_invalid_filename)
+ {
+ g_error_free (error);
+
+ handled_invalid_filename = TRUE;
+
+ g_assert (*dest_fs_type == NULL);
+ *dest_fs_type = query_fs_type (dest_dir, job->cancellable);
+
+ new_dest = get_target_file (src, dest_dir, *dest_fs_type, same_fs);
+ if (!g_file_equal (dest, new_dest))
+ {
+ g_object_unref (dest);
+ dest = new_dest;
+ goto retry;
+ }
+ else
+ {
+ g_object_unref (new_dest);
+ }
+ }
+ /* Conflict */
+ else if (!overwrite &&
+ IS_IO_ERROR (error, EXISTS))
+ {
+ gboolean is_merge;
+ FileConflictResponse *response;
+
+ g_error_free (error);
+
+ is_merge = FALSE;
+ if (is_dir (dest) && is_dir (src))
+ {
+ is_merge = TRUE;
+ }
+
+ if ((is_merge && job->merge_all) ||
+ (!is_merge && job->replace_all))
+ {
+ overwrite = TRUE;
+ goto retry;
+ }
+
+ if (job->skip_all_conflict)
+ {
+ goto out;
+ }
+
+ response = handle_copy_move_conflict (job, src, dest, dest_dir);
+
+ if (response->id == GTK_RESPONSE_CANCEL ||
+ response->id == GTK_RESPONSE_DELETE_EVENT)
+ {
+ file_conflict_response_free (response);
+ abort_job (job);
+ }
+ else if (response->id == CONFLICT_RESPONSE_SKIP)
+ {
+ if (response->apply_to_all)
+ {
+ job->skip_all_conflict = TRUE;
+ }
+ file_conflict_response_free (response);
+ }
+ else if (response->id == CONFLICT_RESPONSE_REPLACE) /* merge/replace */
+ {
+ if (response->apply_to_all)
+ {
+ if (is_merge)
+ {
+ job->merge_all = TRUE;
+ }
+ else
+ {
+ job->replace_all = TRUE;
+ }
+ }
+ overwrite = TRUE;
+ file_conflict_response_free (response);
+ goto retry;
+ }
+ else if (response->id == CONFLICT_RESPONSE_RENAME)
+ {
+ g_object_unref (dest);
+ dest = get_target_file_for_display_name (dest_dir,
+ response->new_name);
+ file_conflict_response_free (response);
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ else if (IS_IO_ERROR (error, WOULD_RECURSE) ||
+ IS_IO_ERROR (error, WOULD_MERGE) ||
+ IS_IO_ERROR (error, NOT_SUPPORTED) ||
+ (overwrite && IS_IO_ERROR (error, IS_DIRECTORY)))
+ {
+ g_error_free (error);
+
+ fallback = move_copy_file_callback_new (src,
+ overwrite,
+ position);
+ *fallback_files = g_list_prepend (*fallback_files, fallback);
+ }
+ else if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ /* Other error */
+ else
+ {
+ if (job->skip_all_error)
+ {
+ g_error_free (error);
+ goto out;
+ }
+ primary = f (_("Error while moving “%B”."), src);
+ secondary = f (_("There was an error moving the file into %F."), dest_dir);
+ details = error->message;
+
+ response = run_warning (job,
+ primary,
+ secondary,
+ details,
+ files_left > 1,
+ CANCEL, SKIP_ALL, SKIP,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (job);
+ }
+ else if (response == 1) /* skip all */
+ {
+ job->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+
+out:
+ g_object_unref (dest);
}
static void
-move_files_prepare (CopyMoveJob *job,
- const char *dest_fs_id,
- char **dest_fs_type,
- GList **fallbacks)
-{
- CommonJob *common;
- GList *l;
- GFile *src;
- gboolean same_fs;
- int i;
- GdkPoint *point;
- int total, left;
-
- common = &job->common;
-
- total = left = g_list_length (job->files);
-
- report_preparing_move_progress (job, total, left);
-
- i = 0;
- for (l = job->files;
- l != NULL && !job_aborted (common);
- l = l->next) {
- src = l->data;
-
- if (i < job->n_icon_positions) {
- point = &job->icon_positions[i];
- } else {
- point = NULL;
- }
-
-
- same_fs = FALSE;
- if (dest_fs_id) {
- same_fs = has_fs_id (src, dest_fs_id);
- }
-
- move_file_prepare (job, src, job->destination,
- same_fs, dest_fs_type,
- job->debuting_files,
- point,
- fallbacks,
- left);
- report_preparing_move_progress (job, total, --left);
- i++;
- }
-
- *fallbacks = g_list_reverse (*fallbacks);
-
-
+move_files_prepare (CopyMoveJob *job,
+ const char *dest_fs_id,
+ char **dest_fs_type,
+ GList **fallbacks)
+{
+ CommonJob *common;
+ GList *l;
+ GFile *src;
+ gboolean same_fs;
+ int i;
+ GdkPoint *point;
+ int total, left;
+
+ common = &job->common;
+
+ total = left = g_list_length (job->files);
+
+ report_preparing_move_progress (job, total, left);
+
+ i = 0;
+ for (l = job->files;
+ l != NULL && !job_aborted (common);
+ l = l->next)
+ {
+ src = l->data;
+
+ if (i < job->n_icon_positions)
+ {
+ point = &job->icon_positions[i];
+ }
+ else
+ {
+ point = NULL;
+ }
+
+
+ same_fs = FALSE;
+ if (dest_fs_id)
+ {
+ same_fs = has_fs_id (src, dest_fs_id);
+ }
+
+ move_file_prepare (job, src, job->destination,
+ same_fs, dest_fs_type,
+ job->debuting_files,
+ point,
+ fallbacks,
+ left);
+ report_preparing_move_progress (job, total, --left);
+ i++;
+ }
+
+ *fallbacks = g_list_reverse (*fallbacks);
}
static void
-move_files (CopyMoveJob *job,
- GList *fallbacks,
- const char *dest_fs_id,
- char **dest_fs_type,
- SourceInfo *source_info,
- TransferInfo *transfer_info)
-{
- CommonJob *common;
- GList *l;
- GFile *src;
- gboolean same_fs;
- int i;
- GdkPoint *point;
- gboolean skipped_file;
- MoveFileCopyFallback *fallback;
-common = &job->common;
-
- report_copy_progress (job, source_info, transfer_info);
-
- i = 0;
- for (l = fallbacks;
- l != NULL && !job_aborted (common);
- l = l->next) {
- fallback = l->data;
- src = fallback->file;
-
- if (fallback->has_position) {
- point = &fallback->position;
- } else {
- point = NULL;
- }
-
- same_fs = FALSE;
- if (dest_fs_id) {
- same_fs = has_fs_id (src, dest_fs_id);
- }
-
- /* Set overwrite to true, as the user has
- selected overwrite on all toplevel items */
- skipped_file = FALSE;
- copy_move_file (job, src, job->destination,
- same_fs, FALSE, dest_fs_type,
- source_info, transfer_info,
- job->debuting_files,
- point, fallback->overwrite, &skipped_file, FALSE);
- i++;
-
- if (skipped_file) {
- transfer_add_file_to_count (src, common, transfer_info);
- report_copy_progress (job, source_info, transfer_info);
- }
- }
+move_files (CopyMoveJob *job,
+ GList *fallbacks,
+ const char *dest_fs_id,
+ char **dest_fs_type,
+ SourceInfo *source_info,
+ TransferInfo *transfer_info)
+{
+ CommonJob *common;
+ GList *l;
+ GFile *src;
+ gboolean same_fs;
+ int i;
+ GdkPoint *point;
+ gboolean skipped_file;
+ MoveFileCopyFallback *fallback;
+ common = &job->common;
+
+ report_copy_progress (job, source_info, transfer_info);
+
+ i = 0;
+ for (l = fallbacks;
+ l != NULL && !job_aborted (common);
+ l = l->next)
+ {
+ fallback = l->data;
+ src = fallback->file;
+
+ if (fallback->has_position)
+ {
+ point = &fallback->position;
+ }
+ else
+ {
+ point = NULL;
+ }
+
+ same_fs = FALSE;
+ if (dest_fs_id)
+ {
+ same_fs = has_fs_id (src, dest_fs_id);
+ }
+
+ /* Set overwrite to true, as the user has
+ * selected overwrite on all toplevel items */
+ skipped_file = FALSE;
+ copy_move_file (job, src, job->destination,
+ same_fs, FALSE, dest_fs_type,
+ source_info, transfer_info,
+ job->debuting_files,
+ point, fallback->overwrite, &skipped_file, FALSE);
+ i++;
+
+ if (skipped_file)
+ {
+ transfer_add_file_to_count (src, common, transfer_info);
+ report_copy_progress (job, source_info, transfer_info);
+ }
+ }
}
static void
-move_task_done (GObject *source_object,
+move_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- CopyMoveJob *job;
+ CopyMoveJob *job;
- job = user_data;
- if (job->done_callback) {
- job->done_callback (job->debuting_files,
- !job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
+ job = user_data;
+ if (job->done_callback)
+ {
+ job->done_callback (job->debuting_files,
+ !job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
+
+ g_list_free_full (job->files, g_object_unref);
+ g_object_unref (job->destination);
+ g_hash_table_unref (job->debuting_files);
+ g_free (job->icon_positions);
- g_list_free_full (job->files, g_object_unref);
- g_object_unref (job->destination);
- g_hash_table_unref (job->debuting_files);
- g_free (job->icon_positions);
-
- finalize_common ((CommonJob *)job);
+ finalize_common ((CommonJob *) job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
static void
-move_task_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+move_task_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- CopyMoveJob *job;
- CommonJob *common;
- GList *fallbacks;
- SourceInfo source_info;
- TransferInfo transfer_info;
- char *dest_fs_id;
- char *dest_fs_type;
- GList *fallback_files;
-
- job = task_data;
- common = &job->common;
-
- dest_fs_id = NULL;
- dest_fs_type = NULL;
-
- fallbacks = NULL;
-
- nautilus_progress_info_start (job->common.progress);
-
- verify_destination (&job->common,
- job->destination,
- &dest_fs_id,
- -1);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- /* This moves all files that we can do without copy + delete */
- move_files_prepare (job, dest_fs_id, &dest_fs_type, &fallbacks);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- /* The rest we need to do deep copy + delete behind on,
- so scan for size */
-
- fallback_files = get_files_from_fallbacks (fallbacks);
- scan_sources (fallback_files,
- &source_info,
- common,
- OP_KIND_MOVE);
-
- g_list_free (fallback_files);
-
- if (job_aborted (common)) {
- goto aborted;
- }
-
- verify_destination (&job->common,
- job->destination,
- NULL,
- source_info.num_bytes);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- memset (&transfer_info, 0, sizeof (transfer_info));
- move_files (job,
- fallbacks,
- dest_fs_id, &dest_fs_type,
- &source_info, &transfer_info);
-
- aborted:
- g_list_free_full (fallbacks, g_free);
-
- g_free (dest_fs_id);
- g_free (dest_fs_type);
+ CopyMoveJob *job;
+ CommonJob *common;
+ GList *fallbacks;
+ SourceInfo source_info;
+ TransferInfo transfer_info;
+ char *dest_fs_id;
+ char *dest_fs_type;
+ GList *fallback_files;
+
+ job = task_data;
+ common = &job->common;
+
+ dest_fs_id = NULL;
+ dest_fs_type = NULL;
+
+ fallbacks = NULL;
+
+ nautilus_progress_info_start (job->common.progress);
+
+ verify_destination (&job->common,
+ job->destination,
+ &dest_fs_id,
+ -1);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
+
+ /* This moves all files that we can do without copy + delete */
+ move_files_prepare (job, dest_fs_id, &dest_fs_type, &fallbacks);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
+
+ /* The rest we need to do deep copy + delete behind on,
+ * so scan for size */
+
+ fallback_files = get_files_from_fallbacks (fallbacks);
+ scan_sources (fallback_files,
+ &source_info,
+ common,
+ OP_KIND_MOVE);
+
+ g_list_free (fallback_files);
+
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
+
+ verify_destination (&job->common,
+ job->destination,
+ NULL,
+ source_info.num_bytes);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
+
+ memset (&transfer_info, 0, sizeof (transfer_info));
+ move_files (job,
+ fallbacks,
+ dest_fs_id, &dest_fs_type,
+ &source_info, &transfer_info);
+
+aborted:
+ g_list_free_full (fallbacks, g_free);
+
+ g_free (dest_fs_id);
+ g_free (dest_fs_type);
}
void
-nautilus_file_operations_move (GList *files,
- GArray *relative_item_points,
- GFile *target_dir,
- GtkWindow *parent_window,
- NautilusCopyCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CopyMoveJob *job;
-
- job = op_job_new (CopyMoveJob, parent_window);
- job->is_move = TRUE;
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
- job->destination = g_object_ref (target_dir);
- /* Need to indicate the destination for the operation notification open
- * button. */
- nautilus_progress_info_set_destination (((CommonJob *)job)->progress, target_dir);
- if (relative_item_points != NULL &&
- relative_item_points->len > 0) {
- job->icon_positions =
- g_memdup (relative_item_points->data,
- sizeof (GdkPoint) * relative_item_points->len);
- job->n_icon_positions = relative_item_points->len;
- }
- job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
-
- inhibit_power_manager ((CommonJob *)job, _("Moving Files"));
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- GFile* src_dir;
-
- src_dir = g_file_get_parent (files->data);
-
- if (g_file_has_uri_scheme (g_list_first (files)->data, "trash")) {
- job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH,
- g_list_length (files),
- src_dir, target_dir);
- } else {
- job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_MOVE,
- g_list_length (files),
- src_dir, target_dir);
- }
-
- g_object_unref (src_dir);
- }
-
- task = g_task_new (NULL, job->common.cancellable, move_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, move_task_thread_func);
- g_object_unref (task);
+nautilus_file_operations_move (GList *files,
+ GArray *relative_item_points,
+ GFile *target_dir,
+ GtkWindow *parent_window,
+ NautilusCopyCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CopyMoveJob *job;
+
+ job = op_job_new (CopyMoveJob, parent_window);
+ job->is_move = TRUE;
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
+ job->destination = g_object_ref (target_dir);
+ /* Need to indicate the destination for the operation notification open
+ * button. */
+ nautilus_progress_info_set_destination (((CommonJob *) job)->progress, target_dir);
+ if (relative_item_points != NULL &&
+ relative_item_points->len > 0)
+ {
+ job->icon_positions =
+ g_memdup (relative_item_points->data,
+ sizeof (GdkPoint) * relative_item_points->len);
+ job->n_icon_positions = relative_item_points->len;
+ }
+ job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+
+ inhibit_power_manager ((CommonJob *) job, _("Moving Files"));
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ GFile *src_dir;
+
+ src_dir = g_file_get_parent (files->data);
+
+ if (g_file_has_uri_scheme (g_list_first (files)->data, "trash"))
+ {
+ job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH,
+ g_list_length (files),
+ src_dir, target_dir);
+ }
+ else
+ {
+ job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_MOVE,
+ g_list_length (files),
+ src_dir, target_dir);
+ }
+
+ g_object_unref (src_dir);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, move_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, move_task_thread_func);
+ g_object_unref (task);
}
static void
-report_preparing_link_progress (CopyMoveJob *link_job, int total, int left)
+report_preparing_link_progress (CopyMoveJob *link_job,
+ int total,
+ int left)
{
- CommonJob *job;
+ CommonJob *job;
+
+ job = (CommonJob *) link_job;
- job = (CommonJob *)link_job;
-
- nautilus_progress_info_take_status (job->progress,
- f (_("Creating links in “%B”"),
- link_job->destination));
+ nautilus_progress_info_take_status (job->progress,
+ f (_("Creating links in “%B”"),
+ link_job->destination));
- nautilus_progress_info_take_details (job->progress,
- f (ngettext ("Making link to %'d file",
- "Making links to %'d files",
- left), left));
+ nautilus_progress_info_take_details (job->progress,
+ f (ngettext ("Making link to %'d file",
+ "Making links to %'d files",
+ left), left));
- nautilus_progress_info_set_progress (job->progress, left, total);
+ nautilus_progress_info_set_progress (job->progress, left, total);
}
static char *
-get_abs_path_for_symlink (GFile *file, GFile *destination)
+get_abs_path_for_symlink (GFile *file,
+ GFile *destination)
{
- GFile *root, *parent;
- char *relative, *abs;
-
- if (g_file_is_native (file) || g_file_is_native (destination)) {
- return g_file_get_path (file);
- }
+ GFile *root, *parent;
+ char *relative, *abs;
+
+ if (g_file_is_native (file) || g_file_is_native (destination))
+ {
+ return g_file_get_path (file);
+ }
+
+ root = g_object_ref (file);
+ while ((parent = g_file_get_parent (root)) != NULL)
+ {
+ g_object_unref (root);
+ root = parent;
+ }
- root = g_object_ref (file);
- while ((parent = g_file_get_parent (root)) != NULL) {
- g_object_unref (root);
- root = parent;
- }
-
- relative = g_file_get_relative_path (root, file);
- g_object_unref (root);
- abs = g_strconcat ("/", relative, NULL);
- g_free (relative);
- return abs;
+ relative = g_file_get_relative_path (root, file);
+ g_object_unref (root);
+ abs = g_strconcat ("/", relative, NULL);
+ g_free (relative);
+ return abs;
}
static void
-link_file (CopyMoveJob *job,
- GFile *src, GFile *dest_dir,
- char **dest_fs_type,
- GHashTable *debuting_files,
- GdkPoint *position,
- int files_left)
-{
- GFile *src_dir, *dest, *new_dest;
- int count;
- char *path;
- gboolean not_local;
- GError *error;
- CommonJob *common;
- char *primary, *secondary, *details;
- int response;
- gboolean handled_invalid_filename;
-
- common = (CommonJob *)job;
-
- count = 0;
-
- src_dir = g_file_get_parent (src);
- if (g_file_equal (src_dir, dest_dir)) {
- count = 1;
- }
- g_object_unref (src_dir);
-
- handled_invalid_filename = *dest_fs_type != NULL;
-
- dest = get_target_file_for_link (src, dest_dir, *dest_fs_type, count);
-
- retry:
- error = NULL;
- not_local = FALSE;
-
- path = get_abs_path_for_symlink (src, dest);
- if (path == NULL) {
- not_local = TRUE;
- } else if (g_file_make_symbolic_link (dest,
- path,
- common->cancellable,
- &error)) {
-
- if (common->undo_info != NULL) {
- nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (common->undo_info),
- src, dest);
- }
-
- g_free (path);
- if (debuting_files) {
- g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
- }
-
- nautilus_file_changes_queue_file_added (dest);
- if (position) {
- nautilus_file_changes_queue_schedule_position_set (dest, *position, common->screen_num);
- } else {
- nautilus_file_changes_queue_schedule_position_remove (dest);
- }
-
- g_object_unref (dest);
-
- return;
- }
- g_free (path);
-
- if (error != NULL &&
- IS_IO_ERROR (error, INVALID_FILENAME) &&
- !handled_invalid_filename) {
- handled_invalid_filename = TRUE;
-
- g_assert (*dest_fs_type == NULL);
- *dest_fs_type = query_fs_type (dest_dir, common->cancellable);
-
- new_dest = get_target_file_for_link (src, dest_dir, *dest_fs_type, count);
-
- if (!g_file_equal (dest, new_dest)) {
- g_object_unref (dest);
- dest = new_dest;
- g_error_free (error);
-
- goto retry;
- } else {
- g_object_unref (new_dest);
- }
- }
- /* Conflict */
- if (error != NULL && IS_IO_ERROR (error, EXISTS)) {
- g_object_unref (dest);
- dest = get_target_file_for_link (src, dest_dir, *dest_fs_type, count++);
- g_error_free (error);
- goto retry;
- }
-
- else if (error != NULL && IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- }
-
- /* Other error */
- else if (error != NULL) {
- if (common->skip_all_error) {
- goto out;
- }
- primary = f (_("Error while creating link to %B."), src);
- if (not_local) {
- secondary = f (_("Symbolic links only supported for local files"));
- details = NULL;
- } else if (IS_IO_ERROR (error, NOT_SUPPORTED)) {
- secondary = f (_("The target doesn't support symbolic links."));
- details = NULL;
- } else {
- secondary = f (_("There was an error creating the symlink in %F."), dest_dir);
- details = error->message;
- }
-
- response = run_warning (common,
- primary,
- secondary,
- details,
- files_left > 1,
- CANCEL, SKIP_ALL, SKIP,
- NULL);
-
- if (error) {
- g_error_free (error);
- }
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (common);
- } else if (response == 1) { /* skip all */
- common->skip_all_error = TRUE;
- } else if (response == 2) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
- }
-
- out:
- g_object_unref (dest);
+link_file (CopyMoveJob *job,
+ GFile *src,
+ GFile *dest_dir,
+ char **dest_fs_type,
+ GHashTable *debuting_files,
+ GdkPoint *position,
+ int files_left)
+{
+ GFile *src_dir, *dest, *new_dest;
+ int count;
+ char *path;
+ gboolean not_local;
+ GError *error;
+ CommonJob *common;
+ char *primary, *secondary, *details;
+ int response;
+ gboolean handled_invalid_filename;
+
+ common = (CommonJob *) job;
+
+ count = 0;
+
+ src_dir = g_file_get_parent (src);
+ if (g_file_equal (src_dir, dest_dir))
+ {
+ count = 1;
+ }
+ g_object_unref (src_dir);
+
+ handled_invalid_filename = *dest_fs_type != NULL;
+
+ dest = get_target_file_for_link (src, dest_dir, *dest_fs_type, count);
+
+retry:
+ error = NULL;
+ not_local = FALSE;
+
+ path = get_abs_path_for_symlink (src, dest);
+ if (path == NULL)
+ {
+ not_local = TRUE;
+ }
+ else if (g_file_make_symbolic_link (dest,
+ path,
+ common->cancellable,
+ &error))
+ {
+ if (common->undo_info != NULL)
+ {
+ nautilus_file_undo_info_ext_add_origin_target_pair (NAUTILUS_FILE_UNDO_INFO_EXT (common->undo_info),
+ src, dest);
+ }
+
+ g_free (path);
+ if (debuting_files)
+ {
+ g_hash_table_replace (debuting_files, g_object_ref (dest), GINT_TO_POINTER (TRUE));
+ }
+
+ nautilus_file_changes_queue_file_added (dest);
+ if (position)
+ {
+ nautilus_file_changes_queue_schedule_position_set (dest, *position, common->screen_num);
+ }
+ else
+ {
+ nautilus_file_changes_queue_schedule_position_remove (dest);
+ }
+
+ g_object_unref (dest);
+
+ return;
+ }
+ g_free (path);
+
+ if (error != NULL &&
+ IS_IO_ERROR (error, INVALID_FILENAME) &&
+ !handled_invalid_filename)
+ {
+ handled_invalid_filename = TRUE;
+
+ g_assert (*dest_fs_type == NULL);
+ *dest_fs_type = query_fs_type (dest_dir, common->cancellable);
+
+ new_dest = get_target_file_for_link (src, dest_dir, *dest_fs_type, count);
+
+ if (!g_file_equal (dest, new_dest))
+ {
+ g_object_unref (dest);
+ dest = new_dest;
+ g_error_free (error);
+
+ goto retry;
+ }
+ else
+ {
+ g_object_unref (new_dest);
+ }
+ }
+ /* Conflict */
+ if (error != NULL && IS_IO_ERROR (error, EXISTS))
+ {
+ g_object_unref (dest);
+ dest = get_target_file_for_link (src, dest_dir, *dest_fs_type, count++);
+ g_error_free (error);
+ goto retry;
+ }
+ else if (error != NULL && IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ /* Other error */
+ else if (error != NULL)
+ {
+ if (common->skip_all_error)
+ {
+ goto out;
+ }
+ primary = f (_("Error while creating link to %B."), src);
+ if (not_local)
+ {
+ secondary = f (_("Symbolic links only supported for local files"));
+ details = NULL;
+ }
+ else if (IS_IO_ERROR (error, NOT_SUPPORTED))
+ {
+ secondary = f (_("The target doesn't support symbolic links."));
+ details = NULL;
+ }
+ else
+ {
+ secondary = f (_("There was an error creating the symlink in %F."), dest_dir);
+ details = error->message;
+ }
+
+ response = run_warning (common,
+ primary,
+ secondary,
+ details,
+ files_left > 1,
+ CANCEL, SKIP_ALL, SKIP,
+ NULL);
+
+ if (error)
+ {
+ g_error_free (error);
+ }
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (common);
+ }
+ else if (response == 1) /* skip all */
+ {
+ common->skip_all_error = TRUE;
+ }
+ else if (response == 2) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+
+out:
+ g_object_unref (dest);
}
static void
-link_task_done (GObject *source_object,
+link_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- CopyMoveJob *job;
+ CopyMoveJob *job;
+
+ job = user_data;
+ if (job->done_callback)
+ {
+ job->done_callback (job->debuting_files,
+ !job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
- job = user_data;
- if (job->done_callback) {
- job->done_callback (job->debuting_files,
- !job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
+ g_list_free_full (job->files, g_object_unref);
+ g_object_unref (job->destination);
+ g_hash_table_unref (job->debuting_files);
+ g_free (job->icon_positions);
- g_list_free_full (job->files, g_object_unref);
- g_object_unref (job->destination);
- g_hash_table_unref (job->debuting_files);
- g_free (job->icon_positions);
-
- finalize_common ((CommonJob *)job);
+ finalize_common ((CommonJob *) job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
static void
-link_task_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+link_task_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- CopyMoveJob *job;
- CommonJob *common;
- GFile *src;
- GdkPoint *point;
- char *dest_fs_type;
- int total, left;
- int i;
- GList *l;
-
- job = task_data;
- common = &job->common;
-
- dest_fs_type = NULL;
-
- nautilus_progress_info_start (job->common.progress);
-
- verify_destination (&job->common,
- job->destination,
- NULL,
- -1);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- total = left = g_list_length (job->files);
-
- report_preparing_link_progress (job, total, left);
-
- i = 0;
- for (l = job->files;
- l != NULL && !job_aborted (common);
- l = l->next) {
- src = l->data;
-
- if (i < job->n_icon_positions) {
- point = &job->icon_positions[i];
- } else {
- point = NULL;
- }
-
-
- link_file (job, src, job->destination,
- &dest_fs_type, job->debuting_files,
- point, left);
- report_preparing_link_progress (job, total, --left);
- i++;
-
- }
-
- aborted:
- g_free (dest_fs_type);
+ CopyMoveJob *job;
+ CommonJob *common;
+ GFile *src;
+ GdkPoint *point;
+ char *dest_fs_type;
+ int total, left;
+ int i;
+ GList *l;
+
+ job = task_data;
+ common = &job->common;
+
+ dest_fs_type = NULL;
+
+ nautilus_progress_info_start (job->common.progress);
+
+ verify_destination (&job->common,
+ job->destination,
+ NULL,
+ -1);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
+
+ total = left = g_list_length (job->files);
+
+ report_preparing_link_progress (job, total, left);
+
+ i = 0;
+ for (l = job->files;
+ l != NULL && !job_aborted (common);
+ l = l->next)
+ {
+ src = l->data;
+
+ if (i < job->n_icon_positions)
+ {
+ point = &job->icon_positions[i];
+ }
+ else
+ {
+ point = NULL;
+ }
+
+
+ link_file (job, src, job->destination,
+ &dest_fs_type, job->debuting_files,
+ point, left);
+ report_preparing_link_progress (job, total, --left);
+ i++;
+ }
+
+aborted:
+ g_free (dest_fs_type);
}
void
-nautilus_file_operations_link (GList *files,
- GArray *relative_item_points,
- GFile *target_dir,
- GtkWindow *parent_window,
- NautilusCopyCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CopyMoveJob *job;
-
- job = op_job_new (CopyMoveJob, parent_window);
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
- job->destination = g_object_ref (target_dir);
- /* Need to indicate the destination for the operation notification open
- * button. */
- nautilus_progress_info_set_destination (((CommonJob *)job)->progress, target_dir);
- if (relative_item_points != NULL &&
- relative_item_points->len > 0) {
- job->icon_positions =
- g_memdup (relative_item_points->data,
- sizeof (GdkPoint) * relative_item_points->len);
- job->n_icon_positions = relative_item_points->len;
- }
- job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- GFile* src_dir;
-
- src_dir = g_file_get_parent (files->data);
- job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_CREATE_LINK,
- g_list_length (files),
- src_dir, target_dir);
- g_object_unref (src_dir);
- }
-
- task = g_task_new (NULL, job->common.cancellable, link_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, link_task_thread_func);
- g_object_unref (task);
+nautilus_file_operations_link (GList *files,
+ GArray *relative_item_points,
+ GFile *target_dir,
+ GtkWindow *parent_window,
+ NautilusCopyCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CopyMoveJob *job;
+
+ job = op_job_new (CopyMoveJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
+ job->destination = g_object_ref (target_dir);
+ /* Need to indicate the destination for the operation notification open
+ * button. */
+ nautilus_progress_info_set_destination (((CommonJob *) job)->progress, target_dir);
+ if (relative_item_points != NULL &&
+ relative_item_points->len > 0)
+ {
+ job->icon_positions =
+ g_memdup (relative_item_points->data,
+ sizeof (GdkPoint) * relative_item_points->len);
+ job->n_icon_positions = relative_item_points->len;
+ }
+ job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ GFile *src_dir;
+
+ src_dir = g_file_get_parent (files->data);
+ job->common.undo_info = nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_CREATE_LINK,
+ g_list_length (files),
+ src_dir, target_dir);
+ g_object_unref (src_dir);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, link_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, link_task_thread_func);
+ g_object_unref (task);
}
void
-nautilus_file_operations_duplicate (GList *files,
- GArray *relative_item_points,
- GtkWindow *parent_window,
- NautilusCopyCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CopyMoveJob *job;
- GFile *parent;
-
- job = op_job_new (CopyMoveJob, parent_window);
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
- job->destination = NULL;
- /* Duplicate files doesn't have a destination, since is the same as source.
- * For that set as destination the source parent folder */
- parent = g_file_get_parent (files->data);
- /* Need to indicate the destination for the operation notification open
- * button. */
- nautilus_progress_info_set_destination (((CommonJob *)job)->progress, parent);
- if (relative_item_points != NULL &&
- relative_item_points->len > 0) {
- job->icon_positions =
- g_memdup (relative_item_points->data,
- sizeof (GdkPoint) * relative_item_points->len);
- job->n_icon_positions = relative_item_points->len;
- }
- job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal, g_object_unref, NULL);
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- GFile* src_dir;
-
- src_dir = g_file_get_parent (files->data);
- job->common.undo_info =
- nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_DUPLICATE,
- g_list_length (files),
- src_dir, src_dir);
- g_object_unref (src_dir);
- }
-
- task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, copy_task_thread_func);
- g_object_unref (task);
-
- g_object_unref (parent);
+nautilus_file_operations_duplicate (GList *files,
+ GArray *relative_item_points,
+ GtkWindow *parent_window,
+ NautilusCopyCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CopyMoveJob *job;
+ GFile *parent;
+
+ job = op_job_new (CopyMoveJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->files = g_list_copy_deep (files, (GCopyFunc) g_object_ref, NULL);
+ job->destination = NULL;
+ /* Duplicate files doesn't have a destination, since is the same as source.
+ * For that set as destination the source parent folder */
+ parent = g_file_get_parent (files->data);
+ /* Need to indicate the destination for the operation notification open
+ * button. */
+ nautilus_progress_info_set_destination (((CommonJob *) job)->progress, parent);
+ if (relative_item_points != NULL &&
+ relative_item_points->len > 0)
+ {
+ job->icon_positions =
+ g_memdup (relative_item_points->data,
+ sizeof (GdkPoint) * relative_item_points->len);
+ job->n_icon_positions = relative_item_points->len;
+ }
+ job->debuting_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ GFile *src_dir;
+
+ src_dir = g_file_get_parent (files->data);
+ job->common.undo_info =
+ nautilus_file_undo_info_ext_new (NAUTILUS_FILE_UNDO_OP_DUPLICATE,
+ g_list_length (files),
+ src_dir, src_dir);
+ g_object_unref (src_dir);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, copy_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, copy_task_thread_func);
+ g_object_unref (task);
+
+ g_object_unref (parent);
}
static void
-set_permissions_task_done (GObject *source_object,
+set_permissions_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- SetPermissionsJob *job;
+ SetPermissionsJob *job;
+
+ job = user_data;
+
+ g_object_unref (job->file);
- job = user_data;
-
- g_object_unref (job->file);
+ if (job->done_callback)
+ {
+ job->done_callback (!job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
- if (job->done_callback) {
- job->done_callback (!job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
-
- finalize_common ((CommonJob *)job);
+ finalize_common ((CommonJob *) job);
}
static void
set_permissions_file (SetPermissionsJob *job,
- GFile *file,
- GFileInfo *info)
-{
- CommonJob *common;
- GFileInfo *child_info;
- gboolean free_info;
- guint32 current;
- guint32 value;
- guint32 mask;
- GFileEnumerator *enumerator;
- GFile *child;
-
- common = (CommonJob *)job;
-
- nautilus_progress_info_pulse_progress (common->progress);
-
- free_info = FALSE;
- if (info == NULL) {
- free_info = TRUE;
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE","
- G_FILE_ATTRIBUTE_UNIX_MODE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- common->cancellable,
- NULL);
- /* Ignore errors */
- if (info == NULL) {
- return;
- }
- }
-
- if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
- value = job->dir_permissions;
- mask = job->dir_mask;
- } else {
- value = job->file_permissions;
- mask = job->file_mask;
- }
-
-
- if (!job_aborted (common) &&
- g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) {
- current = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
-
- if (common->undo_info != NULL) {
- nautilus_file_undo_info_rec_permissions_add_file (NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (common->undo_info),
- file, current);
- }
-
- current = (current & ~mask) | value;
-
- g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE,
- current, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- common->cancellable, NULL);
- }
-
- if (!job_aborted (common) &&
- g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
- enumerator = g_file_enumerate_children (file,
- G_FILE_ATTRIBUTE_STANDARD_NAME","
- G_FILE_ATTRIBUTE_STANDARD_TYPE","
- G_FILE_ATTRIBUTE_UNIX_MODE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- common->cancellable,
- NULL);
- if (enumerator) {
- while (!job_aborted (common) &&
- (child_info = g_file_enumerator_next_file (enumerator, common->cancellable, NULL)) != NULL) {
- child = g_file_get_child (file,
- g_file_info_get_name (child_info));
- set_permissions_file (job, child, child_info);
- g_object_unref (child);
- g_object_unref (child_info);
- }
- g_file_enumerator_close (enumerator, common->cancellable, NULL);
- g_object_unref (enumerator);
- }
- }
- if (free_info) {
- g_object_unref (info);
- }
+ GFile *file,
+ GFileInfo *info)
+{
+ CommonJob *common;
+ GFileInfo *child_info;
+ gboolean free_info;
+ guint32 current;
+ guint32 value;
+ guint32 mask;
+ GFileEnumerator *enumerator;
+ GFile *child;
+
+ common = (CommonJob *) job;
+
+ nautilus_progress_info_pulse_progress (common->progress);
+
+ free_info = FALSE;
+ if (info == NULL)
+ {
+ free_info = TRUE;
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ common->cancellable,
+ NULL);
+ /* Ignore errors */
+ if (info == NULL)
+ {
+ return;
+ }
+ }
+
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ value = job->dir_permissions;
+ mask = job->dir_mask;
+ }
+ else
+ {
+ value = job->file_permissions;
+ mask = job->file_mask;
+ }
+
+
+ if (!job_aborted (common) &&
+ g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE))
+ {
+ current = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+
+ if (common->undo_info != NULL)
+ {
+ nautilus_file_undo_info_rec_permissions_add_file (NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (common->undo_info),
+ file, current);
+ }
+
+ current = (current & ~mask) | value;
+
+ g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE,
+ current, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ common->cancellable, NULL);
+ }
+
+ if (!job_aborted (common) &&
+ g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ common->cancellable,
+ NULL);
+ if (enumerator)
+ {
+ while (!job_aborted (common) &&
+ (child_info = g_file_enumerator_next_file (enumerator, common->cancellable, NULL)) != NULL)
+ {
+ child = g_file_get_child (file,
+ g_file_info_get_name (child_info));
+ set_permissions_file (job, child, child_info);
+ g_object_unref (child);
+ g_object_unref (child_info);
+ }
+ g_file_enumerator_close (enumerator, common->cancellable, NULL);
+ g_object_unref (enumerator);
+ }
+ }
+ if (free_info)
+ {
+ g_object_unref (info);
+ }
}
static void
-set_permissions_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+set_permissions_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- SetPermissionsJob *job = task_data;
- CommonJob *common;
-
- common = (CommonJob *)job;
-
- nautilus_progress_info_set_status (common->progress,
- _("Setting permissions"));
+ SetPermissionsJob *job = task_data;
+ CommonJob *common;
- nautilus_progress_info_start (job->common.progress);
+ common = (CommonJob *) job;
- set_permissions_file (job, job->file, NULL);
+ nautilus_progress_info_set_status (common->progress,
+ _("Setting permissions"));
+
+ nautilus_progress_info_start (job->common.progress);
+
+ set_permissions_file (job, job->file, NULL);
}
void
-nautilus_file_set_permissions_recursive (const char *directory,
- guint32 file_permissions,
- guint32 file_mask,
- guint32 dir_permissions,
- guint32 dir_mask,
- NautilusOpCallback callback,
- gpointer callback_data)
-{
- GTask *task;
- SetPermissionsJob *job;
-
- job = op_job_new (SetPermissionsJob, NULL);
- job->file = g_file_new_for_uri (directory);
- job->file_permissions = file_permissions;
- job->file_mask = file_mask;
- job->dir_permissions = dir_permissions;
- job->dir_mask = dir_mask;
- job->done_callback = callback;
- job->done_callback_data = callback_data;
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- job->common.undo_info =
- nautilus_file_undo_info_rec_permissions_new (job->file,
- file_permissions, file_mask,
- dir_permissions, dir_mask);
- }
-
- task = g_task_new (NULL, NULL, set_permissions_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, set_permissions_thread_func);
- g_object_unref (task);
+nautilus_file_set_permissions_recursive (const char *directory,
+ guint32 file_permissions,
+ guint32 file_mask,
+ guint32 dir_permissions,
+ guint32 dir_mask,
+ NautilusOpCallback callback,
+ gpointer callback_data)
+{
+ GTask *task;
+ SetPermissionsJob *job;
+
+ job = op_job_new (SetPermissionsJob, NULL);
+ job->file = g_file_new_for_uri (directory);
+ job->file_permissions = file_permissions;
+ job->file_mask = file_mask;
+ job->dir_permissions = dir_permissions;
+ job->dir_mask = dir_mask;
+ job->done_callback = callback;
+ job->done_callback_data = callback_data;
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ job->common.undo_info =
+ nautilus_file_undo_info_rec_permissions_new (job->file,
+ file_permissions, file_mask,
+ dir_permissions, dir_mask);
+ }
+
+ task = g_task_new (NULL, NULL, set_permissions_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, set_permissions_thread_func);
+ g_object_unref (task);
}
static GList *
location_list_from_uri_list (const GList *uris)
{
- const GList *l;
- GList *files;
- GFile *f;
+ const GList *l;
+ GList *files;
+ GFile *f;
- files = NULL;
- for (l = uris; l != NULL; l = l->next) {
- f = g_file_new_for_uri (l->data);
- files = g_list_prepend (files, f);
- }
+ files = NULL;
+ for (l = uris; l != NULL; l = l->next)
+ {
+ f = g_file_new_for_uri (l->data);
+ files = g_list_prepend (files, f);
+ }
- return g_list_reverse (files);
+ return g_list_reverse (files);
}
-typedef struct {
- NautilusCopyCallback real_callback;
- gpointer real_data;
+typedef struct
+{
+ NautilusCopyCallback real_callback;
+ gpointer real_data;
} MoveTrashCBData;
static void
-callback_for_move_to_trash (GHashTable *debuting_uris,
- gboolean user_cancelled,
- MoveTrashCBData *data)
+callback_for_move_to_trash (GHashTable *debuting_uris,
+ gboolean user_cancelled,
+ MoveTrashCBData *data)
{
- if (data->real_callback)
- data->real_callback (debuting_uris, !user_cancelled, data->real_data);
- g_slice_free (MoveTrashCBData, data);
+ if (data->real_callback)
+ {
+ data->real_callback (debuting_uris, !user_cancelled, data->real_data);
+ }
+ g_slice_free (MoveTrashCBData, data);
}
void
-nautilus_file_operations_copy_move (const GList *item_uris,
- GArray *relative_item_points,
- const char *target_dir,
- GdkDragAction copy_action,
- GtkWidget *parent_view,
- NautilusCopyCallback done_callback,
- gpointer done_callback_data)
-{
- GList *locations;
- GList *p;
- GFile *dest, *src_dir;
- GtkWindow *parent_window;
- gboolean target_is_mapping;
- gboolean have_nonmapping_source;
-
- dest = NULL;
- target_is_mapping = FALSE;
- have_nonmapping_source = FALSE;
-
- if (target_dir) {
- dest = g_file_new_for_uri (target_dir);
- if (g_file_has_uri_scheme (dest, "burn")) {
- target_is_mapping = TRUE;
- }
- }
-
- locations = location_list_from_uri_list (item_uris);
-
- for (p = locations; p != NULL; p = p->next) {
- if (!g_file_has_uri_scheme ((GFile* )p->data, "burn")) {
- have_nonmapping_source = TRUE;
- }
- }
-
- if (target_is_mapping && have_nonmapping_source && copy_action == GDK_ACTION_MOVE) {
- /* never move to "burn:///", but fall back to copy.
- * This is a workaround, because otherwise the source files would be removed.
- */
- copy_action = GDK_ACTION_COPY;
- }
-
- parent_window = NULL;
- if (parent_view) {
- parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
- }
-
- if (copy_action == GDK_ACTION_COPY) {
- src_dir = g_file_get_parent (locations->data);
- if (target_dir == NULL ||
- (src_dir != NULL &&
- g_file_equal (src_dir, dest))) {
-
- nautilus_file_operations_duplicate (locations,
- relative_item_points,
- parent_window,
- done_callback, done_callback_data);
- } else {
- nautilus_file_operations_copy (locations,
- relative_item_points,
- dest,
- parent_window,
- done_callback, done_callback_data);
- }
- if (src_dir) {
- g_object_unref (src_dir);
- }
-
- } else if (copy_action == GDK_ACTION_MOVE) {
- if (g_file_has_uri_scheme (dest, "trash")) {
- MoveTrashCBData *cb_data;
-
- cb_data = g_slice_new0 (MoveTrashCBData);
- cb_data->real_callback = done_callback;
- cb_data->real_data = done_callback_data;
-
- nautilus_file_operations_trash_or_delete (locations,
- parent_window,
- (NautilusDeleteCallback) callback_for_move_to_trash,
- cb_data);
- } else {
-
- nautilus_file_operations_move (locations,
- relative_item_points,
- dest,
- parent_window,
- done_callback, done_callback_data);
- }
- } else {
-
- nautilus_file_operations_link (locations,
- relative_item_points,
- dest,
- parent_window,
- done_callback, done_callback_data);
- }
-
- g_list_free_full (locations, g_object_unref);
- if (dest) {
- g_object_unref (dest);
- }
+nautilus_file_operations_copy_move (const GList *item_uris,
+ GArray *relative_item_points,
+ const char *target_dir,
+ GdkDragAction copy_action,
+ GtkWidget *parent_view,
+ NautilusCopyCallback done_callback,
+ gpointer done_callback_data)
+{
+ GList *locations;
+ GList *p;
+ GFile *dest, *src_dir;
+ GtkWindow *parent_window;
+ gboolean target_is_mapping;
+ gboolean have_nonmapping_source;
+
+ dest = NULL;
+ target_is_mapping = FALSE;
+ have_nonmapping_source = FALSE;
+
+ if (target_dir)
+ {
+ dest = g_file_new_for_uri (target_dir);
+ if (g_file_has_uri_scheme (dest, "burn"))
+ {
+ target_is_mapping = TRUE;
+ }
+ }
+
+ locations = location_list_from_uri_list (item_uris);
+
+ for (p = locations; p != NULL; p = p->next)
+ {
+ if (!g_file_has_uri_scheme ((GFile * ) p->data, "burn"))
+ {
+ have_nonmapping_source = TRUE;
+ }
+ }
+
+ if (target_is_mapping && have_nonmapping_source && copy_action == GDK_ACTION_MOVE)
+ {
+ /* never move to "burn:///", but fall back to copy.
+ * This is a workaround, because otherwise the source files would be removed.
+ */
+ copy_action = GDK_ACTION_COPY;
+ }
+
+ parent_window = NULL;
+ if (parent_view)
+ {
+ parent_window = (GtkWindow *) gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
+ }
+
+ if (copy_action == GDK_ACTION_COPY)
+ {
+ src_dir = g_file_get_parent (locations->data);
+ if (target_dir == NULL ||
+ (src_dir != NULL &&
+ g_file_equal (src_dir, dest)))
+ {
+ nautilus_file_operations_duplicate (locations,
+ relative_item_points,
+ parent_window,
+ done_callback, done_callback_data);
+ }
+ else
+ {
+ nautilus_file_operations_copy (locations,
+ relative_item_points,
+ dest,
+ parent_window,
+ done_callback, done_callback_data);
+ }
+ if (src_dir)
+ {
+ g_object_unref (src_dir);
+ }
+ }
+ else if (copy_action == GDK_ACTION_MOVE)
+ {
+ if (g_file_has_uri_scheme (dest, "trash"))
+ {
+ MoveTrashCBData *cb_data;
+
+ cb_data = g_slice_new0 (MoveTrashCBData);
+ cb_data->real_callback = done_callback;
+ cb_data->real_data = done_callback_data;
+
+ nautilus_file_operations_trash_or_delete (locations,
+ parent_window,
+ (NautilusDeleteCallback) callback_for_move_to_trash,
+ cb_data);
+ }
+ else
+ {
+ nautilus_file_operations_move (locations,
+ relative_item_points,
+ dest,
+ parent_window,
+ done_callback, done_callback_data);
+ }
+ }
+ else
+ {
+ nautilus_file_operations_link (locations,
+ relative_item_points,
+ dest,
+ parent_window,
+ done_callback, done_callback_data);
+ }
+
+ g_list_free_full (locations, g_object_unref);
+ if (dest)
+ {
+ g_object_unref (dest);
+ }
}
static void
-create_task_done (GObject *source_object,
+create_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- CreateJob *job;
+ CreateJob *job;
- job = user_data;
- if (job->done_callback) {
- job->done_callback (job->created_file,
- !job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
+ job = user_data;
+ if (job->done_callback)
+ {
+ job->done_callback (job->created_file,
+ !job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
+
+ g_object_unref (job->dest_dir);
+ if (job->src)
+ {
+ g_object_unref (job->src);
+ }
+ g_free (job->src_data);
+ g_free (job->filename);
+ if (job->created_file)
+ {
+ g_object_unref (job->created_file);
+ }
- g_object_unref (job->dest_dir);
- if (job->src) {
- g_object_unref (job->src);
- }
- g_free (job->src_data);
- g_free (job->filename);
- if (job->created_file) {
- g_object_unref (job->created_file);
- }
-
- finalize_common ((CommonJob *)job);
+ finalize_common ((CommonJob *) job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
static void
-create_task_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+create_task_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- CreateJob *job;
- CommonJob *common;
- int count;
- GFile *dest;
- char *basename;
- char *filename, *filename2, *new_filename;
- char *filename_base, *suffix;
- char *dest_fs_type;
- GError *error;
- gboolean res;
- gboolean filename_is_utf8;
- char *primary, *secondary, *details;
- int response;
- char *data;
- int length;
- GFileOutputStream *out;
- gboolean handled_invalid_filename;
- int max_length, offset;
-
- job = task_data;
- common = &job->common;
-
- nautilus_progress_info_start (job->common.progress);
-
- handled_invalid_filename = FALSE;
-
- dest_fs_type = NULL;
- filename = NULL;
- dest = NULL;
-
- max_length = get_max_name_length (job->dest_dir);
-
- verify_destination (common,
- job->dest_dir,
- NULL, -1);
- if (job_aborted (common)) {
- goto aborted;
- }
-
- filename = g_strdup (job->filename);
- filename_is_utf8 = FALSE;
- if (filename) {
- filename_is_utf8 = g_utf8_validate (filename, -1, NULL);
- }
- if (filename == NULL) {
- if (job->make_dir) {
- /* localizers: the initial name of a new folder */
- filename = g_strdup (_("Untitled Folder"));
- filename_is_utf8 = TRUE; /* Pass in utf8 */
- } else {
- if (job->src != NULL) {
- basename = g_file_get_basename (job->src);
- /* localizers: the initial name of a new template document */
- filename = g_strdup_printf ("%s", basename);
-
- g_free (basename);
- }
- if (filename == NULL) {
- /* localizers: the initial name of a new empty document */
- filename = g_strdup (_("Untitled Document"));
- filename_is_utf8 = TRUE; /* Pass in utf8 */
- }
- }
- }
-
- make_file_name_valid_for_dest_fs (filename, dest_fs_type);
- if (filename_is_utf8) {
- dest = g_file_get_child_for_display_name (job->dest_dir, filename, NULL);
- }
- if (dest == NULL) {
- dest = g_file_get_child (job->dest_dir, filename);
- }
- count = 1;
-
- retry:
-
- error = NULL;
- if (job->make_dir) {
- res = g_file_make_directory (dest,
- common->cancellable,
- &error);
-
- if (res) {
- GFile *real;
-
- real = map_possibly_volatile_file_to_real (dest, common->cancellable, &error);
- if (real == NULL) {
- res = FALSE;
- } else {
- g_object_unref (dest);
- dest = real;
- }
- }
-
- if (res && common->undo_info != NULL) {
- nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE (common->undo_info),
- dest, NULL, 0);
- }
-
- } else {
- if (job->src) {
- res = g_file_copy (job->src,
- dest,
- G_FILE_COPY_NONE,
- common->cancellable,
- NULL, NULL,
- &error);
-
- if (res) {
- GFile *real;
-
- real = map_possibly_volatile_file_to_real (dest, common->cancellable, &error);
- if (real == NULL) {
- res = FALSE;
- } else {
- g_object_unref (dest);
- dest = real;
- }
- }
-
- if (res && common->undo_info != NULL) {
- gchar *uri;
-
- uri = g_file_get_uri (job->src);
- nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE (common->undo_info),
- dest, uri, 0);
-
- g_free (uri);
- }
-
- } else {
- data = "";
- length = 0;
- if (job->src_data) {
- data = job->src_data;
- length = job->length;
- }
-
- out = g_file_create (dest,
- G_FILE_CREATE_NONE,
- common->cancellable,
- &error);
- if (out) {
- GFile *real;
-
- real = map_possibly_volatile_file_to_real_on_write (dest,
- out,
- common->cancellable,
- &error);
- if (real == NULL) {
- res = FALSE;
- g_object_unref (out);
- } else {
- g_object_unref (dest);
- dest = real;
-
- res = g_output_stream_write_all (G_OUTPUT_STREAM (out),
- data, length,
- NULL,
- common->cancellable,
- &error);
- if (res) {
- res = g_output_stream_close (G_OUTPUT_STREAM (out),
- common->cancellable,
- &error);
-
- if (res && common->undo_info != NULL) {
- nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE (common->undo_info),
- dest, data, length);
- }
- }
-
- /* This will close if the write failed and we didn't close */
- g_object_unref (out);
- }
- } else {
- res = FALSE;
- }
- }
- }
-
- if (res) {
- job->created_file = g_object_ref (dest);
- nautilus_file_changes_queue_file_added (dest);
- if (job->has_position) {
- nautilus_file_changes_queue_schedule_position_set (dest, job->position, common->screen_num);
- } else {
- nautilus_file_changes_queue_schedule_position_remove (dest);
- }
- } else {
- g_assert (error != NULL);
-
- if (IS_IO_ERROR (error, INVALID_FILENAME) &&
- !handled_invalid_filename) {
- handled_invalid_filename = TRUE;
-
- g_assert (dest_fs_type == NULL);
- dest_fs_type = query_fs_type (job->dest_dir, common->cancellable);
-
- if (count == 1) {
- new_filename = g_strdup (filename);
- } else {
- filename_base = eel_filename_strip_extension (filename);
- offset = strlen (filename_base);
- suffix = g_strdup (filename + offset);
-
- filename2 = g_strdup_printf ("%s %d%s", filename_base, count, suffix);
-
- new_filename = NULL;
- if (max_length > 0 && strlen (filename2) > max_length) {
- new_filename = shorten_utf8_string (filename2, strlen (filename2) - max_length);
- }
-
- if (new_filename == NULL) {
- new_filename = g_strdup (filename2);
- }
-
- g_free (filename2);
- g_free (suffix);
- }
-
- if (make_file_name_valid_for_dest_fs (new_filename, dest_fs_type)) {
- g_object_unref (dest);
-
- if (filename_is_utf8) {
- dest = g_file_get_child_for_display_name (job->dest_dir, new_filename, NULL);
- }
- if (dest == NULL) {
- dest = g_file_get_child (job->dest_dir, new_filename);
- }
-
- g_free (new_filename);
- g_error_free (error);
- goto retry;
- }
- g_free (new_filename);
- }
-
- if (IS_IO_ERROR (error, EXISTS)) {
- g_object_unref (dest);
- dest = NULL;
- filename_base = eel_filename_strip_extension (filename);
- offset = strlen (filename_base);
- suffix = g_strdup (filename + offset);
-
- filename2 = g_strdup_printf ("%s %d%s", filename_base, ++count, suffix);
-
- if (max_length > 0 && strlen (filename2) > max_length) {
- new_filename = shorten_utf8_string (filename2, strlen (filename2) - max_length);
- if (new_filename != NULL) {
- g_free (filename2);
- filename2 = new_filename;
- }
- }
-
- make_file_name_valid_for_dest_fs (filename2, dest_fs_type);
- if (filename_is_utf8) {
- dest = g_file_get_child_for_display_name (job->dest_dir, filename2, NULL);
- }
- if (dest == NULL) {
- dest = g_file_get_child (job->dest_dir, filename2);
- }
- g_free (filename2);
- g_free (suffix);
- g_error_free (error);
- goto retry;
- }
-
- else if (IS_IO_ERROR (error, CANCELLED)) {
- g_error_free (error);
- }
-
- /* Other error */
- else {
- if (job->make_dir) {
- primary = f (_("Error while creating directory %B."), dest);
- } else {
- primary = f (_("Error while creating file %B."), dest);
- }
- secondary = f (_("There was an error creating the directory in %F."), job->dest_dir);
- details = error->message;
-
- response = run_warning (common,
- primary,
- secondary,
- details,
- FALSE,
- CANCEL, SKIP,
- NULL);
-
- g_error_free (error);
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (common);
- } else if (response == 1) { /* skip */
- /* do nothing */
- } else {
- g_assert_not_reached ();
- }
- }
- }
-
- aborted:
- if (dest) {
- g_object_unref (dest);
- }
- g_free (filename);
- g_free (dest_fs_type);
-}
-
-void
-nautilus_file_operations_new_folder (GtkWidget *parent_view,
- GdkPoint *target_point,
- const char *parent_dir,
- const char *folder_name,
- NautilusCreateCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CreateJob *job;
- GtkWindow *parent_window;
-
- parent_window = NULL;
- if (parent_view) {
- parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
- }
-
- job = op_job_new (CreateJob, parent_window);
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->dest_dir = g_file_new_for_uri (parent_dir);
- job->filename = g_strdup (folder_name);
- job->make_dir = TRUE;
- if (target_point != NULL) {
- job->position = *target_point;
- job->has_position = TRUE;
- }
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER);
- }
-
- task = g_task_new (NULL, job->common.cancellable, create_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, create_task_thread_func);
- g_object_unref (task);
-}
-
-void
-nautilus_file_operations_new_file_from_template (GtkWidget *parent_view,
- GdkPoint *target_point,
- const char *parent_dir,
- const char *target_filename,
- const char *template_uri,
- NautilusCreateCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CreateJob *job;
- GtkWindow *parent_window;
-
- parent_window = NULL;
- if (parent_view) {
- parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
- }
-
- job = op_job_new (CreateJob, parent_window);
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->dest_dir = g_file_new_for_uri (parent_dir);
- if (target_point != NULL) {
- job->position = *target_point;
- job->has_position = TRUE;
- }
- job->filename = g_strdup (target_filename);
-
- if (template_uri) {
- job->src = g_file_new_for_uri (template_uri);
- }
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE);
- }
-
- task = g_task_new (NULL, job->common.cancellable, create_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, create_task_thread_func);
- g_object_unref (task);
-}
-
-void
-nautilus_file_operations_new_file (GtkWidget *parent_view,
- GdkPoint *target_point,
- const char *parent_dir,
- const char *target_filename,
- const char *initial_contents,
- int length,
- NautilusCreateCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- CreateJob *job;
- GtkWindow *parent_window;
-
- parent_window = NULL;
- if (parent_view) {
- parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
- }
-
- job = op_job_new (CreateJob, parent_window);
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
- job->dest_dir = g_file_new_for_uri (parent_dir);
- if (target_point != NULL) {
- job->position = *target_point;
- job->has_position = TRUE;
- }
- job->src_data = g_memdup (initial_contents, length);
- job->length = length;
- job->filename = g_strdup (target_filename);
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE);
- }
-
- task = g_task_new (NULL, job->common.cancellable, create_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, create_task_thread_func);
- g_object_unref (task);
+ CreateJob *job;
+ CommonJob *common;
+ int count;
+ GFile *dest;
+ char *basename;
+ char *filename, *filename2, *new_filename;
+ char *filename_base, *suffix;
+ char *dest_fs_type;
+ GError *error;
+ gboolean res;
+ gboolean filename_is_utf8;
+ char *primary, *secondary, *details;
+ int response;
+ char *data;
+ int length;
+ GFileOutputStream *out;
+ gboolean handled_invalid_filename;
+ int max_length, offset;
+
+ job = task_data;
+ common = &job->common;
+
+ nautilus_progress_info_start (job->common.progress);
+
+ handled_invalid_filename = FALSE;
+
+ dest_fs_type = NULL;
+ filename = NULL;
+ dest = NULL;
+
+ max_length = get_max_name_length (job->dest_dir);
+
+ verify_destination (common,
+ job->dest_dir,
+ NULL, -1);
+ if (job_aborted (common))
+ {
+ goto aborted;
+ }
+
+ filename = g_strdup (job->filename);
+ filename_is_utf8 = FALSE;
+ if (filename)
+ {
+ filename_is_utf8 = g_utf8_validate (filename, -1, NULL);
+ }
+ if (filename == NULL)
+ {
+ if (job->make_dir)
+ {
+ /* localizers: the initial name of a new folder */
+ filename = g_strdup (_("Untitled Folder"));
+ filename_is_utf8 = TRUE; /* Pass in utf8 */
+ }
+ else
+ {
+ if (job->src != NULL)
+ {
+ basename = g_file_get_basename (job->src);
+ /* localizers: the initial name of a new template document */
+ filename = g_strdup_printf ("%s", basename);
+
+ g_free (basename);
+ }
+ if (filename == NULL)
+ {
+ /* localizers: the initial name of a new empty document */
+ filename = g_strdup (_("Untitled Document"));
+ filename_is_utf8 = TRUE; /* Pass in utf8 */
+ }
+ }
+ }
+
+ make_file_name_valid_for_dest_fs (filename, dest_fs_type);
+ if (filename_is_utf8)
+ {
+ dest = g_file_get_child_for_display_name (job->dest_dir, filename, NULL);
+ }
+ if (dest == NULL)
+ {
+ dest = g_file_get_child (job->dest_dir, filename);
+ }
+ count = 1;
+
+retry:
+
+ error = NULL;
+ if (job->make_dir)
+ {
+ res = g_file_make_directory (dest,
+ common->cancellable,
+ &error);
+
+ if (res)
+ {
+ GFile *real;
+
+ real = map_possibly_volatile_file_to_real (dest, common->cancellable, &error);
+ if (real == NULL)
+ {
+ res = FALSE;
+ }
+ else
+ {
+ g_object_unref (dest);
+ dest = real;
+ }
+ }
+
+ if (res && common->undo_info != NULL)
+ {
+ nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE (common->undo_info),
+ dest, NULL, 0);
+ }
+ }
+ else
+ {
+ if (job->src)
+ {
+ res = g_file_copy (job->src,
+ dest,
+ G_FILE_COPY_NONE,
+ common->cancellable,
+ NULL, NULL,
+ &error);
+
+ if (res)
+ {
+ GFile *real;
+
+ real = map_possibly_volatile_file_to_real (dest, common->cancellable, &error);
+ if (real == NULL)
+ {
+ res = FALSE;
+ }
+ else
+ {
+ g_object_unref (dest);
+ dest = real;
+ }
+ }
+
+ if (res && common->undo_info != NULL)
+ {
+ gchar *uri;
+
+ uri = g_file_get_uri (job->src);
+ nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE (common->undo_info),
+ dest, uri, 0);
+
+ g_free (uri);
+ }
+ }
+ else
+ {
+ data = "";
+ length = 0;
+ if (job->src_data)
+ {
+ data = job->src_data;
+ length = job->length;
+ }
+
+ out = g_file_create (dest,
+ G_FILE_CREATE_NONE,
+ common->cancellable,
+ &error);
+ if (out)
+ {
+ GFile *real;
+
+ real = map_possibly_volatile_file_to_real_on_write (dest,
+ out,
+ common->cancellable,
+ &error);
+ if (real == NULL)
+ {
+ res = FALSE;
+ g_object_unref (out);
+ }
+ else
+ {
+ g_object_unref (dest);
+ dest = real;
+
+ res = g_output_stream_write_all (G_OUTPUT_STREAM (out),
+ data, length,
+ NULL,
+ common->cancellable,
+ &error);
+ if (res)
+ {
+ res = g_output_stream_close (G_OUTPUT_STREAM (out),
+ common->cancellable,
+ &error);
+
+ if (res && common->undo_info != NULL)
+ {
+ nautilus_file_undo_info_create_set_data (NAUTILUS_FILE_UNDO_INFO_CREATE (common->undo_info),
+ dest, data, length);
+ }
+ }
+
+ /* This will close if the write failed and we didn't close */
+ g_object_unref (out);
+ }
+ }
+ else
+ {
+ res = FALSE;
+ }
+ }
+ }
+
+ if (res)
+ {
+ job->created_file = g_object_ref (dest);
+ nautilus_file_changes_queue_file_added (dest);
+ if (job->has_position)
+ {
+ nautilus_file_changes_queue_schedule_position_set (dest, job->position, common->screen_num);
+ }
+ else
+ {
+ nautilus_file_changes_queue_schedule_position_remove (dest);
+ }
+ }
+ else
+ {
+ g_assert (error != NULL);
+
+ if (IS_IO_ERROR (error, INVALID_FILENAME) &&
+ !handled_invalid_filename)
+ {
+ handled_invalid_filename = TRUE;
+
+ g_assert (dest_fs_type == NULL);
+ dest_fs_type = query_fs_type (job->dest_dir, common->cancellable);
+
+ if (count == 1)
+ {
+ new_filename = g_strdup (filename);
+ }
+ else
+ {
+ filename_base = eel_filename_strip_extension (filename);
+ offset = strlen (filename_base);
+ suffix = g_strdup (filename + offset);
+
+ filename2 = g_strdup_printf ("%s %d%s", filename_base, count, suffix);
+
+ new_filename = NULL;
+ if (max_length > 0 && strlen (filename2) > max_length)
+ {
+ new_filename = shorten_utf8_string (filename2, strlen (filename2) - max_length);
+ }
+
+ if (new_filename == NULL)
+ {
+ new_filename = g_strdup (filename2);
+ }
+
+ g_free (filename2);
+ g_free (suffix);
+ }
+
+ if (make_file_name_valid_for_dest_fs (new_filename, dest_fs_type))
+ {
+ g_object_unref (dest);
+
+ if (filename_is_utf8)
+ {
+ dest = g_file_get_child_for_display_name (job->dest_dir, new_filename, NULL);
+ }
+ if (dest == NULL)
+ {
+ dest = g_file_get_child (job->dest_dir, new_filename);
+ }
+
+ g_free (new_filename);
+ g_error_free (error);
+ goto retry;
+ }
+ g_free (new_filename);
+ }
+
+ if (IS_IO_ERROR (error, EXISTS))
+ {
+ g_object_unref (dest);
+ dest = NULL;
+ filename_base = eel_filename_strip_extension (filename);
+ offset = strlen (filename_base);
+ suffix = g_strdup (filename + offset);
+
+ filename2 = g_strdup_printf ("%s %d%s", filename_base, ++count, suffix);
+
+ if (max_length > 0 && strlen (filename2) > max_length)
+ {
+ new_filename = shorten_utf8_string (filename2, strlen (filename2) - max_length);
+ if (new_filename != NULL)
+ {
+ g_free (filename2);
+ filename2 = new_filename;
+ }
+ }
+
+ make_file_name_valid_for_dest_fs (filename2, dest_fs_type);
+ if (filename_is_utf8)
+ {
+ dest = g_file_get_child_for_display_name (job->dest_dir, filename2, NULL);
+ }
+ if (dest == NULL)
+ {
+ dest = g_file_get_child (job->dest_dir, filename2);
+ }
+ g_free (filename2);
+ g_free (suffix);
+ g_error_free (error);
+ goto retry;
+ }
+ else if (IS_IO_ERROR (error, CANCELLED))
+ {
+ g_error_free (error);
+ }
+ /* Other error */
+ else
+ {
+ if (job->make_dir)
+ {
+ primary = f (_("Error while creating directory %B."), dest);
+ }
+ else
+ {
+ primary = f (_("Error while creating file %B."), dest);
+ }
+ secondary = f (_("There was an error creating the directory in %F."), job->dest_dir);
+ details = error->message;
+
+ response = run_warning (common,
+ primary,
+ secondary,
+ details,
+ FALSE,
+ CANCEL, SKIP,
+ NULL);
+
+ g_error_free (error);
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (common);
+ }
+ else if (response == 1) /* skip */
+ { /* do nothing */
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
+ }
+
+aborted:
+ if (dest)
+ {
+ g_object_unref (dest);
+ }
+ g_free (filename);
+ g_free (dest_fs_type);
+}
+
+void
+nautilus_file_operations_new_folder (GtkWidget *parent_view,
+ GdkPoint *target_point,
+ const char *parent_dir,
+ const char *folder_name,
+ NautilusCreateCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CreateJob *job;
+ GtkWindow *parent_window;
+
+ parent_window = NULL;
+ if (parent_view)
+ {
+ parent_window = (GtkWindow *) gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
+ }
+
+ job = op_job_new (CreateJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->dest_dir = g_file_new_for_uri (parent_dir);
+ job->filename = g_strdup (folder_name);
+ job->make_dir = TRUE;
+ if (target_point != NULL)
+ {
+ job->position = *target_point;
+ job->has_position = TRUE;
+ }
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, create_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, create_task_thread_func);
+ g_object_unref (task);
+}
+
+void
+nautilus_file_operations_new_file_from_template (GtkWidget *parent_view,
+ GdkPoint *target_point,
+ const char *parent_dir,
+ const char *target_filename,
+ const char *template_uri,
+ NautilusCreateCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CreateJob *job;
+ GtkWindow *parent_window;
+
+ parent_window = NULL;
+ if (parent_view)
+ {
+ parent_window = (GtkWindow *) gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
+ }
+
+ job = op_job_new (CreateJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->dest_dir = g_file_new_for_uri (parent_dir);
+ if (target_point != NULL)
+ {
+ job->position = *target_point;
+ job->has_position = TRUE;
+ }
+ job->filename = g_strdup (target_filename);
+
+ if (template_uri)
+ {
+ job->src = g_file_new_for_uri (template_uri);
+ }
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, create_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, create_task_thread_func);
+ g_object_unref (task);
+}
+
+void
+nautilus_file_operations_new_file (GtkWidget *parent_view,
+ GdkPoint *target_point,
+ const char *parent_dir,
+ const char *target_filename,
+ const char *initial_contents,
+ int length,
+ NautilusCreateCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ CreateJob *job;
+ GtkWindow *parent_window;
+
+ parent_window = NULL;
+ if (parent_view)
+ {
+ parent_window = (GtkWindow *) gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
+ }
+
+ job = op_job_new (CreateJob, parent_window);
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+ job->dest_dir = g_file_new_for_uri (parent_dir);
+ if (target_point != NULL)
+ {
+ job->position = *target_point;
+ job->has_position = TRUE;
+ }
+ job->src_data = g_memdup (initial_contents, length);
+ job->length = length;
+ job->filename = g_strdup (target_filename);
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ job->common.undo_info = nautilus_file_undo_info_create_new (NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE);
+ }
+
+ task = g_task_new (NULL, job->common.cancellable, create_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, create_task_thread_func);
+ g_object_unref (task);
}
static void
delete_trash_file (CommonJob *job,
- GFile *file,
- gboolean del_file,
- gboolean del_children)
-{
- GFileInfo *info;
- GFile *child;
- GFileEnumerator *enumerator;
-
- if (job_aborted (job)) {
- return;
- }
-
- if (del_children) {
- enumerator = g_file_enumerate_children (file,
- G_FILE_ATTRIBUTE_STANDARD_NAME ","
- G_FILE_ATTRIBUTE_STANDARD_TYPE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- job->cancellable,
- NULL);
- if (enumerator) {
- while (!job_aborted (job) &&
- (info = g_file_enumerator_next_file (enumerator, job->cancellable, NULL)) != NULL) {
- child = g_file_get_child (file,
- g_file_info_get_name (info));
- delete_trash_file (job, child, TRUE,
- g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY);
- g_object_unref (child);
- g_object_unref (info);
- }
- g_file_enumerator_close (enumerator, job->cancellable, NULL);
- g_object_unref (enumerator);
- }
- }
-
- if (!job_aborted (job) && del_file) {
- g_file_delete (file, job->cancellable, NULL);
- }
+ GFile *file,
+ gboolean del_file,
+ gboolean del_children)
+{
+ GFileInfo *info;
+ GFile *child;
+ GFileEnumerator *enumerator;
+
+ if (job_aborted (job))
+ {
+ return;
+ }
+
+ if (del_children)
+ {
+ enumerator = g_file_enumerate_children (file,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ job->cancellable,
+ NULL);
+ if (enumerator)
+ {
+ while (!job_aborted (job) &&
+ (info = g_file_enumerator_next_file (enumerator, job->cancellable, NULL)) != NULL)
+ {
+ child = g_file_get_child (file,
+ g_file_info_get_name (info));
+ delete_trash_file (job, child, TRUE,
+ g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY);
+ g_object_unref (child);
+ g_object_unref (info);
+ }
+ g_file_enumerator_close (enumerator, job->cancellable, NULL);
+ g_object_unref (enumerator);
+ }
+ }
+
+ if (!job_aborted (job) && del_file)
+ {
+ g_file_delete (file, job->cancellable, NULL);
+ }
}
static void
-empty_trash_task_done (GObject *source_object,
+empty_trash_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- EmptyTrashJob *job;
+ EmptyTrashJob *job;
+
+ job = user_data;
+
+ g_list_free_full (job->trash_dirs, g_object_unref);
- job = user_data;
-
- g_list_free_full (job->trash_dirs, g_object_unref);
+ if (job->done_callback)
+ {
+ job->done_callback (!job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
- if (job->done_callback) {
- job->done_callback (!job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
-
- finalize_common ((CommonJob *)job);
+ finalize_common ((CommonJob *) job);
}
static void
-empty_trash_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+empty_trash_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- EmptyTrashJob *job = task_data;
- CommonJob *common;
- GList *l;
- gboolean confirmed;
-
- common = (CommonJob *)job;
-
- nautilus_progress_info_start (job->common.progress);
-
- if (job->should_confirm) {
- confirmed = confirm_empty_trash (common);
- } else {
- confirmed = TRUE;
- }
- if (confirmed) {
- for (l = job->trash_dirs;
- l != NULL && !job_aborted (common);
- l = l->next) {
- delete_trash_file (common, l->data, FALSE, TRUE);
- }
- }
-}
-
-void
+ EmptyTrashJob *job = task_data;
+ CommonJob *common;
+ GList *l;
+ gboolean confirmed;
+
+ common = (CommonJob *) job;
+
+ nautilus_progress_info_start (job->common.progress);
+
+ if (job->should_confirm)
+ {
+ confirmed = confirm_empty_trash (common);
+ }
+ else
+ {
+ confirmed = TRUE;
+ }
+ if (confirmed)
+ {
+ for (l = job->trash_dirs;
+ l != NULL && !job_aborted (common);
+ l = l->next)
+ {
+ delete_trash_file (common, l->data, FALSE, TRUE);
+ }
+ }
+}
+
+void
nautilus_file_operations_empty_trash (GtkWidget *parent_view)
{
- GTask *task;
- EmptyTrashJob *job;
- GtkWindow *parent_window;
+ GTask *task;
+ EmptyTrashJob *job;
+ GtkWindow *parent_window;
- parent_window = NULL;
- if (parent_view) {
- parent_window = (GtkWindow *)gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
- }
+ parent_window = NULL;
+ if (parent_view)
+ {
+ parent_window = (GtkWindow *) gtk_widget_get_ancestor (parent_view, GTK_TYPE_WINDOW);
+ }
- job = op_job_new (EmptyTrashJob, parent_window);
- job->trash_dirs = g_list_prepend (job->trash_dirs,
- g_file_new_for_uri ("trash:"));
- job->should_confirm = TRUE;
+ job = op_job_new (EmptyTrashJob, parent_window);
+ job->trash_dirs = g_list_prepend (job->trash_dirs,
+ g_file_new_for_uri ("trash:"));
+ job->should_confirm = TRUE;
- inhibit_power_manager ((CommonJob *)job, _("Emptying Trash"));
+ inhibit_power_manager ((CommonJob *) job, _("Emptying Trash"));
- task = g_task_new (NULL, NULL, empty_trash_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, empty_trash_thread_func);
- g_object_unref (task);
+ task = g_task_new (NULL, NULL, empty_trash_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, empty_trash_thread_func);
+ g_object_unref (task);
}
static void
-mark_trusted_task_done (GObject *source_object,
+mark_trusted_task_done (GObject *source_object,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- MarkTrustedJob *job = user_data;
-
- g_object_unref (job->file);
+ MarkTrustedJob *job = user_data;
- if (job->done_callback) {
- job->done_callback (!job_aborted ((CommonJob *) job),
- job->done_callback_data);
- }
-
- finalize_common ((CommonJob *)job);
+ g_object_unref (job->file);
+
+ if (job->done_callback)
+ {
+ job->done_callback (!job_aborted ((CommonJob *) job),
+ job->done_callback_data);
+ }
+
+ finalize_common ((CommonJob *) job);
}
#define TRUSTED_SHEBANG "#!/usr/bin/env xdg-open\n"
static void
-mark_desktop_file_trusted (CommonJob *common,
- GCancellable *cancellable,
- GFile *file,
- gboolean interactive)
-{
- char *contents, *new_contents;
- gsize length, new_length;
- GError *error;
- guint32 current_perms, new_perms;
- int response;
- GFileInfo *info;
-
- retry:
- error = NULL;
- if (!g_file_load_contents (file,
- cancellable,
- &contents, &length,
- NULL, &error)) {
- if (interactive) {
- response = run_error (common,
- g_strdup (_("Unable to mark launcher trusted (executable)")),
- error->message,
- NULL,
- FALSE,
- CANCEL, RETRY,
- NULL);
- } else {
- response = 0;
- }
-
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (common);
- } else if (response == 1) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
-
- if (!g_str_has_prefix (contents, "#!")) {
- new_length = length + strlen (TRUSTED_SHEBANG);
- new_contents = g_malloc (new_length);
-
- strcpy (new_contents, TRUSTED_SHEBANG);
- memcpy (new_contents + strlen (TRUSTED_SHEBANG),
- contents, length);
-
- if (!g_file_replace_contents (file,
- new_contents,
- new_length,
- NULL,
- FALSE, 0,
- NULL, cancellable, &error)) {
- g_free (contents);
- g_free (new_contents);
-
- if (interactive) {
- response = run_error (common,
- g_strdup (_("Unable to mark launcher trusted (executable)")),
- error->message,
- NULL,
- FALSE,
- CANCEL, RETRY,
- NULL);
- } else {
- response = 0;
- }
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (common);
- } else if (response == 1) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
- g_free (new_contents);
-
- }
- g_free (contents);
-
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_TYPE","
- G_FILE_ATTRIBUTE_UNIX_MODE,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- common->cancellable,
- &error);
-
- if (info == NULL) {
- if (interactive) {
- response = run_error (common,
- g_strdup (_("Unable to mark launcher trusted (executable)")),
- error->message,
- NULL,
- FALSE,
- CANCEL, RETRY,
- NULL);
- } else {
- response = 0;
- }
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (common);
- } else if (response == 1) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
-
-
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE)) {
- current_perms = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
- new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH;
-
- if ((current_perms != new_perms) &&
- !g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE,
- new_perms, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- common->cancellable, &error))
- {
- g_object_unref (info);
-
- if (interactive) {
- response = run_error (common,
- g_strdup (_("Unable to mark launcher trusted (executable)")),
- error->message,
- NULL,
- FALSE,
- CANCEL, RETRY,
- NULL);
- } else {
- response = 0;
- }
-
- if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT) {
- abort_job (common);
- } else if (response == 1) {
- goto retry;
- } else {
- g_assert_not_reached ();
- }
-
- goto out;
- }
- }
- g_object_unref (info);
- out:
- ;
+mark_desktop_file_trusted (CommonJob *common,
+ GCancellable *cancellable,
+ GFile *file,
+ gboolean interactive)
+{
+ char *contents, *new_contents;
+ gsize length, new_length;
+ GError *error;
+ guint32 current_perms, new_perms;
+ int response;
+ GFileInfo *info;
+
+retry:
+ error = NULL;
+ if (!g_file_load_contents (file,
+ cancellable,
+ &contents, &length,
+ NULL, &error))
+ {
+ if (interactive)
+ {
+ response = run_error (common,
+ g_strdup (_("Unable to mark launcher trusted (executable)")),
+ error->message,
+ NULL,
+ FALSE,
+ CANCEL, RETRY,
+ NULL);
+ }
+ else
+ {
+ response = 0;
+ }
+
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (common);
+ }
+ else if (response == 1)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+
+ if (!g_str_has_prefix (contents, "#!"))
+ {
+ new_length = length + strlen (TRUSTED_SHEBANG);
+ new_contents = g_malloc (new_length);
+
+ strcpy (new_contents, TRUSTED_SHEBANG);
+ memcpy (new_contents + strlen (TRUSTED_SHEBANG),
+ contents, length);
+
+ if (!g_file_replace_contents (file,
+ new_contents,
+ new_length,
+ NULL,
+ FALSE, 0,
+ NULL, cancellable, &error))
+ {
+ g_free (contents);
+ g_free (new_contents);
+
+ if (interactive)
+ {
+ response = run_error (common,
+ g_strdup (_("Unable to mark launcher trusted (executable)")),
+ error->message,
+ NULL,
+ FALSE,
+ CANCEL, RETRY,
+ NULL);
+ }
+ else
+ {
+ response = 0;
+ }
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (common);
+ }
+ else if (response == 1)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+ g_free (new_contents);
+ }
+ g_free (contents);
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE ","
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ common->cancellable,
+ &error);
+
+ if (info == NULL)
+ {
+ if (interactive)
+ {
+ response = run_error (common,
+ g_strdup (_("Unable to mark launcher trusted (executable)")),
+ error->message,
+ NULL,
+ FALSE,
+ CANCEL, RETRY,
+ NULL);
+ }
+ else
+ {
+ response = 0;
+ }
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (common);
+ }
+ else if (response == 1)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+
+
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE))
+ {
+ current_perms = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+ new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH;
+
+ if ((current_perms != new_perms) &&
+ !g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE,
+ new_perms, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ common->cancellable, &error))
+ {
+ g_object_unref (info);
+
+ if (interactive)
+ {
+ response = run_error (common,
+ g_strdup (_("Unable to mark launcher trusted (executable)")),
+ error->message,
+ NULL,
+ FALSE,
+ CANCEL, RETRY,
+ NULL);
+ }
+ else
+ {
+ response = 0;
+ }
+
+ if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job (common);
+ }
+ else if (response == 1)
+ {
+ goto retry;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ goto out;
+ }
+ }
+ g_object_unref (info);
+out:
+ ;
}
static void
-mark_trusted_task_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
+mark_trusted_task_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- MarkTrustedJob *job = task_data;
- CommonJob *common;
-
- common = (CommonJob *)job;
-
- nautilus_progress_info_start (job->common.progress);
+ MarkTrustedJob *job = task_data;
+ CommonJob *common;
+
+ common = (CommonJob *) job;
- mark_desktop_file_trusted (common,
- cancellable,
- job->file,
- job->interactive);
+ nautilus_progress_info_start (job->common.progress);
+
+ mark_desktop_file_trusted (common,
+ cancellable,
+ job->file,
+ job->interactive);
}
void
-nautilus_file_mark_desktop_file_trusted (GFile *file,
- GtkWindow *parent_window,
- gboolean interactive,
- NautilusOpCallback done_callback,
- gpointer done_callback_data)
-{
- GTask *task;
- MarkTrustedJob *job;
-
- job = op_job_new (MarkTrustedJob, parent_window);
- job->file = g_object_ref (file);
- job->interactive = interactive;
- job->done_callback = done_callback;
- job->done_callback_data = done_callback_data;
-
- task = g_task_new (NULL, NULL, mark_trusted_task_done, job);
- g_task_set_task_data (task, job, NULL);
- g_task_run_in_thread (task, mark_trusted_task_thread_func);
- g_object_unref (task);
+nautilus_file_mark_desktop_file_trusted (GFile *file,
+ GtkWindow *parent_window,
+ gboolean interactive,
+ NautilusOpCallback done_callback,
+ gpointer done_callback_data)
+{
+ GTask *task;
+ MarkTrustedJob *job;
+
+ job = op_job_new (MarkTrustedJob, parent_window);
+ job->file = g_object_ref (file);
+ job->interactive = interactive;
+ job->done_callback = done_callback;
+ job->done_callback_data = done_callback_data;
+
+ task = g_task_new (NULL, NULL, mark_trusted_task_done, job);
+ g_task_set_task_data (task, job, NULL);
+ g_task_run_in_thread (task, mark_trusted_task_thread_func);
+ g_object_unref (task);
}
static void
@@ -7072,50 +8110,52 @@ extract_task_done (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- ExtractJob *extract_job;
+ ExtractJob *extract_job;
- extract_job = user_data;
+ extract_job = user_data;
- if (extract_job->done_callback) {
- extract_job->done_callback (extract_job->output_files,
- extract_job->done_callback_data);
- }
+ if (extract_job->done_callback)
+ {
+ extract_job->done_callback (extract_job->output_files,
+ extract_job->done_callback_data);
+ }
- g_list_free_full (extract_job->source_files, g_object_unref);
- g_list_free_full (extract_job->output_files, g_object_unref);
- g_object_unref (extract_job->destination_directory);
+ g_list_free_full (extract_job->source_files, g_object_unref);
+ g_list_free_full (extract_job->output_files, g_object_unref);
+ g_object_unref (extract_job->destination_directory);
- finalize_common ((CommonJob *)extract_job);
+ finalize_common ((CommonJob *) extract_job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
-static GFile*
+static GFile *
extract_job_on_decide_destination (AutoarExtractor *extractor,
GFile *destination,
GList *files,
gpointer user_data)
{
- ExtractJob *extract_job = user_data;
- GFile *decided_destination;
- g_autofree char *basename;
+ ExtractJob *extract_job = user_data;
+ GFile *decided_destination;
+ g_autofree char *basename;
- nautilus_progress_info_set_details (extract_job->common.progress,
- _("Verifying destination"));
+ nautilus_progress_info_set_details (extract_job->common.progress,
+ _("Verifying destination"));
- basename = g_file_get_basename (destination);
- decided_destination = nautilus_generate_unique_file_in_directory (extract_job->destination_directory,
- basename);
+ basename = g_file_get_basename (destination);
+ decided_destination = nautilus_generate_unique_file_in_directory (extract_job->destination_directory,
+ basename);
- if (job_aborted ((CommonJob *)extract_job)) {
- g_object_unref (decided_destination);
- return NULL;
- }
+ if (job_aborted ((CommonJob *) extract_job))
+ {
+ g_object_unref (decided_destination);
+ return NULL;
+ }
- extract_job->output_files = g_list_prepend (extract_job->output_files,
- decided_destination);
+ extract_job->output_files = g_list_prepend (extract_job->output_files,
+ decided_destination);
- return g_object_ref (decided_destination);
+ return g_object_ref (decided_destination);
}
static void
@@ -7124,85 +8164,92 @@ extract_job_on_progress (AutoarExtractor *extractor,
guint archive_current_decompressed_files,
gpointer user_data)
{
- ExtractJob *extract_job = user_data;
- CommonJob *common = user_data;
- GFile *source_file;
- char *details;
- double elapsed;
- double transfer_rate;
- int remaining_time;
- guint64 archive_total_decompressed_size;
- gdouble archive_weight;
- gdouble archive_decompress_progress;
- guint64 job_completed_size;
- gdouble job_progress;
-
- source_file = autoar_extractor_get_source_file (extractor);
-
- nautilus_progress_info_take_status (common->progress,
- f (_("Extracting “%B”"), source_file));
-
- archive_total_decompressed_size = autoar_extractor_get_total_size (extractor);
-
- archive_decompress_progress = (gdouble)archive_current_decompressed_size /
- (gdouble)archive_total_decompressed_size;
-
- archive_weight = 0;
- if (extract_job->total_compressed_size) {
- archive_weight = (gdouble)extract_job->archive_compressed_size /
- (gdouble)extract_job->total_compressed_size;
- }
+ ExtractJob *extract_job = user_data;
+ CommonJob *common = user_data;
+ GFile *source_file;
+ char *details;
+ double elapsed;
+ double transfer_rate;
+ int remaining_time;
+ guint64 archive_total_decompressed_size;
+ gdouble archive_weight;
+ gdouble archive_decompress_progress;
+ guint64 job_completed_size;
+ gdouble job_progress;
+
+ source_file = autoar_extractor_get_source_file (extractor);
+
+ nautilus_progress_info_take_status (common->progress,
+ f (_("Extracting “%B”"), source_file));
+
+ archive_total_decompressed_size = autoar_extractor_get_total_size (extractor);
+
+ archive_decompress_progress = (gdouble) archive_current_decompressed_size /
+ (gdouble) archive_total_decompressed_size;
+
+ archive_weight = 0;
+ if (extract_job->total_compressed_size)
+ {
+ archive_weight = (gdouble) extract_job->archive_compressed_size /
+ (gdouble) extract_job->total_compressed_size;
+ }
- job_progress = archive_decompress_progress * archive_weight + extract_job->base_progress;
+ job_progress = archive_decompress_progress * archive_weight + extract_job->base_progress;
- elapsed = g_timer_elapsed (common->time, NULL);
+ elapsed = g_timer_elapsed (common->time, NULL);
- transfer_rate = 0;
- remaining_time = -1;
+ transfer_rate = 0;
+ remaining_time = -1;
- job_completed_size = job_progress * extract_job->total_compressed_size;
+ job_completed_size = job_progress * extract_job->total_compressed_size;
- if (elapsed > 0) {
- transfer_rate = job_completed_size / elapsed;
- }
- if (transfer_rate > 0) {
- remaining_time = (extract_job->total_compressed_size - job_completed_size) /
- transfer_rate;
- }
+ if (elapsed > 0)
+ {
+ transfer_rate = job_completed_size / elapsed;
+ }
+ if (transfer_rate > 0)
+ {
+ remaining_time = (extract_job->total_compressed_size - job_completed_size) /
+ transfer_rate;
+ }
- if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE ||
- transfer_rate == 0) {
- /* To translators: %S will expand to a size like "2 bytes" or
- * "3 MB", so something like "4 kb / 4 MB"
- */
- details = f (_("%S / %S"), job_completed_size, extract_job->total_compressed_size);
- } else {
- /* To translators: %S will expand to a size like "2 bytes" or
- * "3 MB", %T to a time duration like "2 minutes". So the whole
- * thing will be something like
- * "2 kb / 4 MB -- 2 hours left (4kb/sec)"
- *
- * The singular/plural form will be used depending on the
- * remaining time (i.e. the %T argument).
- */
- details = f (ngettext ("%S / %S \xE2\x80\x94 %T left (%S/sec)",
- "%S / %S \xE2\x80\x94 %T left (%S/sec)",
- seconds_count_format_time_units (remaining_time)),
- job_completed_size, extract_job->total_compressed_size,
- remaining_time,
- (goffset)transfer_rate);
- }
+ if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE ||
+ transfer_rate == 0)
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or
+ * "3 MB", so something like "4 kb / 4 MB"
+ */
+ details = f (_("%S / %S"), job_completed_size, extract_job->total_compressed_size);
+ }
+ else
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or
+ * "3 MB", %T to a time duration like "2 minutes". So the whole
+ * thing will be something like
+ * "2 kb / 4 MB -- 2 hours left (4kb/sec)"
+ *
+ * The singular/plural form will be used depending on the
+ * remaining time (i.e. the %T argument).
+ */
+ details = f (ngettext ("%S / %S \xE2\x80\x94 %T left (%S/sec)",
+ "%S / %S \xE2\x80\x94 %T left (%S/sec)",
+ seconds_count_format_time_units (remaining_time)),
+ job_completed_size, extract_job->total_compressed_size,
+ remaining_time,
+ (goffset) transfer_rate);
+ }
- nautilus_progress_info_take_details (common->progress, details);
+ nautilus_progress_info_take_details (common->progress, details);
- if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE) {
- nautilus_progress_info_set_remaining_time (common->progress,
- remaining_time);
- nautilus_progress_info_set_elapsed_time (common->progress,
- elapsed);
- }
+ if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE)
+ {
+ nautilus_progress_info_set_remaining_time (common->progress,
+ remaining_time);
+ nautilus_progress_info_set_elapsed_time (common->progress,
+ elapsed);
+ }
- nautilus_progress_info_set_progress (common->progress, job_progress, 1);
+ nautilus_progress_info_set_progress (common->progress, job_progress, 1);
}
static void
@@ -7210,74 +8257,77 @@ extract_job_on_error (AutoarExtractor *extractor,
GError *error,
gpointer user_data)
{
- ExtractJob *extract_job = user_data;
- GFile *source_file;
- gint response_id;
-
- source_file = autoar_extractor_get_source_file (extractor);
-
- nautilus_progress_info_take_status (extract_job->common.progress,
- f (_("Error extracting “%B”"),
- source_file));
-
- response_id = run_warning ((CommonJob *)extract_job,
- f (_("There was an error while extracting “%B”."),
- source_file),
- g_strdup (error->message),
- NULL,
- FALSE,
- CANCEL,
- SKIP,
- NULL);
-
- if (response_id == 0 || response_id == GTK_RESPONSE_DELETE_EVENT) {
- abort_job ((CommonJob *)extract_job);
- }
+ ExtractJob *extract_job = user_data;
+ GFile *source_file;
+ gint response_id;
+
+ source_file = autoar_extractor_get_source_file (extractor);
+
+ nautilus_progress_info_take_status (extract_job->common.progress,
+ f (_("Error extracting “%B”"),
+ source_file));
+
+ response_id = run_warning ((CommonJob *) extract_job,
+ f (_("There was an error while extracting “%B”."),
+ source_file),
+ g_strdup (error->message),
+ NULL,
+ FALSE,
+ CANCEL,
+ SKIP,
+ NULL);
+
+ if (response_id == 0 || response_id == GTK_RESPONSE_DELETE_EVENT)
+ {
+ abort_job ((CommonJob *) extract_job);
+ }
}
static void
extract_job_on_completed (AutoarExtractor *extractor,
gpointer user_data)
{
- ExtractJob *extract_job = user_data;
- GFile *output_file;
+ ExtractJob *extract_job = user_data;
+ GFile *output_file;
- output_file = G_FILE (extract_job->output_files->data);
+ output_file = G_FILE (extract_job->output_files->data);
- nautilus_file_changes_queue_file_added (output_file);
+ nautilus_file_changes_queue_file_added (output_file);
}
static void
report_extract_final_progress (ExtractJob *extract_job,
gint total_files)
{
- char *status;
+ char *status;
- nautilus_progress_info_set_destination (extract_job->common.progress,
- extract_job->destination_directory);
+ nautilus_progress_info_set_destination (extract_job->common.progress,
+ extract_job->destination_directory);
- if (total_files == 1) {
- GFile *source_file;
-
- source_file = G_FILE (extract_job->source_files->data);
- status = f (_("Extracted “%B” to “%B”"),
- source_file,
- extract_job->destination_directory);
- } else {
- status = f (ngettext ("Extracted %'d file to “%B”",
- "Extracted %'d files to “%B”",
- total_files),
- total_files,
- extract_job->destination_directory);
+ if (total_files == 1)
+ {
+ GFile *source_file;
- }
+ source_file = G_FILE (extract_job->source_files->data);
+ status = f (_("Extracted “%B” to “%B”"),
+ source_file,
+ extract_job->destination_directory);
+ }
+ else
+ {
+ status = f (ngettext ("Extracted %'d file to “%B”",
+ "Extracted %'d files to “%B”",
+ total_files),
+ total_files,
+ extract_job->destination_directory);
+ }
- nautilus_progress_info_take_status (extract_job->common.progress,
- status);
- nautilus_progress_info_take_details (extract_job->common.progress,
- f (_("%S / %S"),
- extract_job->total_compressed_size,
- extract_job->total_compressed_size));
+ nautilus_progress_info_take_status (extract_job->common.progress,
+ status);
+ nautilus_progress_info_take_details (extract_job->common.progress,
+ f (_("%S / %S"),
+ extract_job->total_compressed_size,
+ extract_job->total_compressed_size));
}
static void
@@ -7286,114 +8336,124 @@ extract_task_thread_func (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- ExtractJob *extract_job = task_data;
- GList *l;
- GList *existing_output_files = NULL;
- gint total_files;
- g_autofree guint64 *archive_compressed_sizes;
- gint i;
+ ExtractJob *extract_job = task_data;
+ GList *l;
+ GList *existing_output_files = NULL;
+ gint total_files;
+ g_autofree guint64 *archive_compressed_sizes;
+ gint i;
- g_timer_start (extract_job->common.time);
+ g_timer_start (extract_job->common.time);
- nautilus_progress_info_start (extract_job->common.progress);
+ nautilus_progress_info_start (extract_job->common.progress);
- nautilus_progress_info_set_details (extract_job->common.progress,
- _("Preparing to extract"));
+ nautilus_progress_info_set_details (extract_job->common.progress,
+ _("Preparing to extract"));
- total_files = g_list_length (extract_job->source_files);
+ total_files = g_list_length (extract_job->source_files);
- archive_compressed_sizes = g_malloc0_n (total_files, sizeof (guint64));
- extract_job->total_compressed_size = 0;
+ archive_compressed_sizes = g_malloc0_n (total_files, sizeof (guint64));
+ extract_job->total_compressed_size = 0;
- for (l = extract_job->source_files, i = 0;
- l != NULL && !job_aborted ((CommonJob *)extract_job);
- l = l->next, i++) {
- GFile *source_file;
- g_autoptr (GFileInfo) info;
-
- source_file = G_FILE (l->data);
- info = g_file_query_info (source_file,
- G_FILE_ATTRIBUTE_STANDARD_SIZE,
- G_FILE_COPY_NOFOLLOW_SYMLINKS,
- extract_job->common.cancellable,
- NULL);
-
- if (info) {
- archive_compressed_sizes[i] = g_file_info_get_size (info);
- extract_job->total_compressed_size += archive_compressed_sizes[i];
- }
+ for (l = extract_job->source_files, i = 0;
+ l != NULL && !job_aborted ((CommonJob *) extract_job);
+ l = l->next, i++)
+ {
+ GFile *source_file;
+ g_autoptr (GFileInfo) info;
+
+ source_file = G_FILE (l->data);
+ info = g_file_query_info (source_file,
+ G_FILE_ATTRIBUTE_STANDARD_SIZE,
+ G_FILE_COPY_NOFOLLOW_SYMLINKS,
+ extract_job->common.cancellable,
+ NULL);
+
+ if (info)
+ {
+ archive_compressed_sizes[i] = g_file_info_get_size (info);
+ extract_job->total_compressed_size += archive_compressed_sizes[i];
}
+ }
- extract_job->base_progress = 0;
+ extract_job->base_progress = 0;
- for (l = extract_job->source_files, i = 0;
- l != NULL && !job_aborted ((CommonJob *)extract_job);
- l = l->next, i++) {
- g_autoptr (AutoarExtractor) extractor;
+ for (l = extract_job->source_files, i = 0;
+ l != NULL && !job_aborted ((CommonJob *) extract_job);
+ l = l->next, i++)
+ {
+ g_autoptr (AutoarExtractor) extractor;
- extractor = autoar_extractor_new (G_FILE (l->data),
- extract_job->destination_directory);
+ extractor = autoar_extractor_new (G_FILE (l->data),
+ extract_job->destination_directory);
- autoar_extractor_set_notify_interval (extractor,
- PROGRESS_NOTIFY_INTERVAL);
+ autoar_extractor_set_notify_interval (extractor,
+ PROGRESS_NOTIFY_INTERVAL);
- g_signal_connect (extractor, "error",
- G_CALLBACK (extract_job_on_error),
- extract_job);
- g_signal_connect (extractor, "decide-destination",
- G_CALLBACK (extract_job_on_decide_destination),
- extract_job);
- g_signal_connect (extractor, "progress",
- G_CALLBACK (extract_job_on_progress),
- extract_job);
- g_signal_connect (extractor, "completed",
- G_CALLBACK (extract_job_on_completed),
- extract_job);
+ g_signal_connect (extractor, "error",
+ G_CALLBACK (extract_job_on_error),
+ extract_job);
+ g_signal_connect (extractor, "decide-destination",
+ G_CALLBACK (extract_job_on_decide_destination),
+ extract_job);
+ g_signal_connect (extractor, "progress",
+ G_CALLBACK (extract_job_on_progress),
+ extract_job);
+ g_signal_connect (extractor, "completed",
+ G_CALLBACK (extract_job_on_completed),
+ extract_job);
- extract_job->archive_compressed_size = archive_compressed_sizes[i];
+ extract_job->archive_compressed_size = archive_compressed_sizes[i];
- autoar_extractor_start (extractor,
- extract_job->common.cancellable);
+ autoar_extractor_start (extractor,
+ extract_job->common.cancellable);
- g_signal_handlers_disconnect_by_data (extractor,
- extract_job);
+ g_signal_handlers_disconnect_by_data (extractor,
+ extract_job);
- extract_job->base_progress += (gdouble)extract_job->archive_compressed_size /
- (gdouble)extract_job->total_compressed_size;
- }
+ extract_job->base_progress += (gdouble) extract_job->archive_compressed_size /
+ (gdouble) extract_job->total_compressed_size;
+ }
- if (!job_aborted ((CommonJob *)extract_job)) {
- report_extract_final_progress (extract_job, total_files);
- }
+ if (!job_aborted ((CommonJob *) extract_job))
+ {
+ report_extract_final_progress (extract_job, total_files);
+ }
- for (l = extract_job->output_files; l != NULL; l = l->next) {
- GFile *output_file;
+ for (l = extract_job->output_files; l != NULL; l = l->next)
+ {
+ GFile *output_file;
- output_file = G_FILE (l->data);
+ output_file = G_FILE (l->data);
- if (g_file_query_exists (output_file, NULL)) {
- existing_output_files = g_list_prepend (existing_output_files,
- g_object_ref (output_file));
- }
+ if (g_file_query_exists (output_file, NULL))
+ {
+ existing_output_files = g_list_prepend (existing_output_files,
+ g_object_ref (output_file));
}
+ }
- g_list_free_full (extract_job->output_files, g_object_unref);
+ g_list_free_full (extract_job->output_files, g_object_unref);
- extract_job->output_files = existing_output_files;
+ extract_job->output_files = existing_output_files;
- if (extract_job->common.undo_info) {
- if (extract_job->output_files) {
- NautilusFileUndoInfoExtract *undo_info;
+ if (extract_job->common.undo_info)
+ {
+ if (extract_job->output_files)
+ {
+ NautilusFileUndoInfoExtract *undo_info;
- undo_info = NAUTILUS_FILE_UNDO_INFO_EXTRACT (extract_job->common.undo_info);
+ undo_info = NAUTILUS_FILE_UNDO_INFO_EXTRACT (extract_job->common.undo_info);
- nautilus_file_undo_info_extract_set_outputs (undo_info,
- extract_job->output_files);
- } else {
- /* There is nothing to undo if there is no output */
- g_clear_object (&extract_job->common.undo_info);
- }
+ nautilus_file_undo_info_extract_set_outputs (undo_info,
+ extract_job->output_files);
+ }
+ else
+ {
+ /* There is nothing to undo if there is no output */
+ g_clear_object (&extract_job->common.undo_info);
}
+ }
}
void
@@ -7403,28 +8463,29 @@ nautilus_file_operations_extract_files (GList *files,
NautilusExtractCallback done_callback,
gpointer done_callback_data)
{
- ExtractJob *extract_job;
- g_autoptr (GTask) task;
+ ExtractJob *extract_job;
+ g_autoptr (GTask) task;
- extract_job = op_job_new (ExtractJob, parent_window);
- extract_job->source_files = g_list_copy_deep (files,
- (GCopyFunc)g_object_ref,
- NULL);
- extract_job->destination_directory = g_object_ref (destination_directory);
- extract_job->done_callback = done_callback;
- extract_job->done_callback_data = done_callback_data;
+ extract_job = op_job_new (ExtractJob, parent_window);
+ extract_job->source_files = g_list_copy_deep (files,
+ (GCopyFunc) g_object_ref,
+ NULL);
+ extract_job->destination_directory = g_object_ref (destination_directory);
+ extract_job->done_callback = done_callback;
+ extract_job->done_callback_data = done_callback_data;
- inhibit_power_manager ((CommonJob *)extract_job, _("Extracting Files"));
+ inhibit_power_manager ((CommonJob *) extract_job, _("Extracting Files"));
- if (!nautilus_file_undo_manager_is_operating ()) {
- extract_job->common.undo_info = nautilus_file_undo_info_extract_new (files,
- destination_directory);
- }
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ extract_job->common.undo_info = nautilus_file_undo_info_extract_new (files,
+ destination_directory);
+ }
- task = g_task_new (NULL, extract_job->common.cancellable,
- extract_task_done, extract_job);
- g_task_set_task_data (task, extract_job, NULL);
- g_task_run_in_thread (task, extract_task_thread_func);
+ task = g_task_new (NULL, extract_job->common.cancellable,
+ extract_task_done, extract_job);
+ g_task_set_task_data (task, extract_job, NULL);
+ g_task_run_in_thread (task, extract_task_thread_func);
}
static void
@@ -7432,20 +8493,21 @@ compress_task_done (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- CompressJob *compress_job = user_data;
+ CompressJob *compress_job = user_data;
- if (compress_job->done_callback) {
- compress_job->done_callback (compress_job->output_file,
- compress_job->success,
- compress_job->done_callback_data);
- }
+ if (compress_job->done_callback)
+ {
+ compress_job->done_callback (compress_job->output_file,
+ compress_job->success,
+ compress_job->done_callback_data);
+ }
- g_object_unref (compress_job->output_file);
- g_list_free_full (compress_job->source_files, g_object_unref);
+ g_object_unref (compress_job->output_file);
+ g_list_free_full (compress_job->source_files, g_object_unref);
- finalize_common ((CommonJob *)compress_job);
+ finalize_common ((CommonJob *) compress_job);
- nautilus_file_changes_consume_changes (TRUE);
+ nautilus_file_changes_consume_changes (TRUE);
}
static void
@@ -7454,112 +8516,134 @@ compress_job_on_progress (AutoarCompressor *compressor,
guint completed_files,
gpointer user_data)
{
- CompressJob *compress_job = user_data;
- CommonJob *common = user_data;
- char *status;
- char *details;
- int files_left;
- double elapsed;
- double transfer_rate;
- int remaining_time;
-
- files_left = compress_job->total_files - completed_files;
-
- if (compress_job->total_files == 1) {
- status = f (_("Compressing “%B” into “%B”"),
- G_FILE (compress_job->source_files->data),
- compress_job->output_file);
- } else {
- status = f (ngettext ("Compressing %'d file into “%B”",
- "Compressing %'d files into “%B”",
- compress_job->total_files),
- compress_job->total_files,
- compress_job->output_file);
-
- }
+ CompressJob *compress_job = user_data;
+ CommonJob *common = user_data;
+ char *status;
+ char *details;
+ int files_left;
+ double elapsed;
+ double transfer_rate;
+ int remaining_time;
+
+ files_left = compress_job->total_files - completed_files;
+
+ if (compress_job->total_files == 1)
+ {
+ status = f (_("Compressing “%B” into “%B”"),
+ G_FILE (compress_job->source_files->data),
+ compress_job->output_file);
+ }
+ else
+ {
+ status = f (ngettext ("Compressing %'d file into “%B”",
+ "Compressing %'d files into “%B”",
+ compress_job->total_files),
+ compress_job->total_files,
+ compress_job->output_file);
+ }
- nautilus_progress_info_take_status (common->progress, status);
+ nautilus_progress_info_take_status (common->progress, status);
- elapsed = g_timer_elapsed (common->time, NULL);
+ elapsed = g_timer_elapsed (common->time, NULL);
- transfer_rate = 0;
- remaining_time = -1;
+ transfer_rate = 0;
+ remaining_time = -1;
- if (elapsed > 0) {
- if (completed_size > 0) {
- transfer_rate = completed_size / elapsed;
- remaining_time = (compress_job->total_size - completed_size) / transfer_rate;
- } else if (completed_files > 0) {
- transfer_rate = completed_files / elapsed;
- remaining_time = (compress_job->total_files - completed_files) / transfer_rate;
- }
+ if (elapsed > 0)
+ {
+ if (completed_size > 0)
+ {
+ transfer_rate = completed_size / elapsed;
+ remaining_time = (compress_job->total_size - completed_size) / transfer_rate;
}
+ else if (completed_files > 0)
+ {
+ transfer_rate = completed_files / elapsed;
+ remaining_time = (compress_job->total_files - completed_files) / transfer_rate;
+ }
+ }
- if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE ||
- transfer_rate == 0) {
- if (compress_job->total_files == 1) {
- /* To translators: %S will expand to a size like "2 bytes" or "3 MB", so something like "4 kb / 4 MB" */
- details = f (_("%S / %S"), completed_size, compress_job->total_size);
- } else {
- details = f (_("%'d / %'d"),
- files_left > 0 ? completed_files + 1 : completed_files,
- compress_job->total_files);
- }
- } else {
- if (compress_job->total_files == 1) {
- if (files_left > 0) {
- /* To translators: %S will expand to a size like "2 bytes" or "3 MB", %T to a time duration like
- * "2 minutes". So the whole thing will be something like "2 kb / 4 MB -- 2 hours left (4kb/sec)"
- *
- * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
- */
- details = f (ngettext ("%S / %S \xE2\x80\x94 %T left (%S/sec)",
- "%S / %S \xE2\x80\x94 %T left (%S/sec)",
- seconds_count_format_time_units (remaining_time)),
- completed_size, compress_job->total_size,
- remaining_time,
- (goffset)transfer_rate);
- } else {
- /* To translators: %S will expand to a size like "2 bytes" or "3 MB". */
- details = f (_("%S / %S"),
- completed_size,
- compress_job->total_size);
- }
- } else {
- if (files_left > 0) {
- /* To translators: %T will expand to a time duration like "2 minutes".
- * So the whole thing will be something like "1 / 5 -- 2 hours left (4kb/sec)"
- *
- * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
- */
- details = f (ngettext ("%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
- "%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
- seconds_count_format_time_units (remaining_time)),
- completed_files + 1, compress_job->total_files,
- remaining_time,
- (goffset)transfer_rate);
- } else {
- /* To translators: %'d is the number of files completed for the operation,
- * so it will be something like 2/14. */
- details = f (_("%'d / %'d"),
- completed_files,
- compress_job->total_files);
- }
- }
+ if (elapsed < SECONDS_NEEDED_FOR_RELIABLE_TRANSFER_RATE ||
+ transfer_rate == 0)
+ {
+ if (compress_job->total_files == 1)
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or "3 MB", so something like "4 kb / 4 MB" */
+ details = f (_("%S / %S"), completed_size, compress_job->total_size);
+ }
+ else
+ {
+ details = f (_("%'d / %'d"),
+ files_left > 0 ? completed_files + 1 : completed_files,
+ compress_job->total_files);
+ }
+ }
+ else
+ {
+ if (compress_job->total_files == 1)
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or "3 MB", %T to a time duration like
+ * "2 minutes". So the whole thing will be something like "2 kb / 4 MB -- 2 hours left (4kb/sec)"
+ *
+ * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
+ */
+ details = f (ngettext ("%S / %S \xE2\x80\x94 %T left (%S/sec)",
+ "%S / %S \xE2\x80\x94 %T left (%S/sec)",
+ seconds_count_format_time_units (remaining_time)),
+ completed_size, compress_job->total_size,
+ remaining_time,
+ (goffset) transfer_rate);
+ }
+ else
+ {
+ /* To translators: %S will expand to a size like "2 bytes" or "3 MB". */
+ details = f (_("%S / %S"),
+ completed_size,
+ compress_job->total_size);
+ }
+ }
+ else
+ {
+ if (files_left > 0)
+ {
+ /* To translators: %T will expand to a time duration like "2 minutes".
+ * So the whole thing will be something like "1 / 5 -- 2 hours left (4kb/sec)"
+ *
+ * The singular/plural form will be used depending on the remaining time (i.e. the %T argument).
+ */
+ details = f (ngettext ("%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
+ "%'d / %'d \xE2\x80\x94 %T left (%S/sec)",
+ seconds_count_format_time_units (remaining_time)),
+ completed_files + 1, compress_job->total_files,
+ remaining_time,
+ (goffset) transfer_rate);
+ }
+ else
+ {
+ /* To translators: %'d is the number of files completed for the operation,
+ * so it will be something like 2/14. */
+ details = f (_("%'d / %'d"),
+ completed_files,
+ compress_job->total_files);
+ }
}
+ }
- nautilus_progress_info_take_details (common->progress, details);
+ nautilus_progress_info_take_details (common->progress, details);
- if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE) {
- nautilus_progress_info_set_remaining_time (common->progress,
- remaining_time);
- nautilus_progress_info_set_elapsed_time (common->progress,
- elapsed);
- }
+ if (elapsed > SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE)
+ {
+ nautilus_progress_info_set_remaining_time (common->progress,
+ remaining_time);
+ nautilus_progress_info_set_elapsed_time (common->progress,
+ elapsed);
+ }
- nautilus_progress_info_set_progress (common->progress,
- completed_size,
- compress_job->total_size);
+ nautilus_progress_info_set_progress (common->progress,
+ completed_size,
+ compress_job->total_size);
}
static void
@@ -7567,63 +8651,69 @@ compress_job_on_error (AutoarCompressor *compressor,
GError *error,
gpointer user_data)
{
- CompressJob *compress_job = user_data;
- char *status;
+ CompressJob *compress_job = user_data;
+ char *status;
- if (compress_job->total_files == 1) {
- status = f (_("Error compressing “%B” into “%B”"),
- G_FILE (compress_job->source_files->data),
- compress_job->output_file);
- } else {
- status = f (ngettext ("Error compressing %'d file into “%B”",
- "Error compressing %'d files into “%B”",
- compress_job->total_files),
- compress_job->total_files,
- compress_job->output_file);
- }
+ if (compress_job->total_files == 1)
+ {
+ status = f (_("Error compressing “%B” into “%B”"),
+ G_FILE (compress_job->source_files->data),
+ compress_job->output_file);
+ }
+ else
+ {
+ status = f (ngettext ("Error compressing %'d file into “%B”",
+ "Error compressing %'d files into “%B”",
+ compress_job->total_files),
+ compress_job->total_files,
+ compress_job->output_file);
+ }
- nautilus_progress_info_take_status (compress_job->common.progress,
- status);
+ nautilus_progress_info_take_status (compress_job->common.progress,
+ status);
- run_error ((CommonJob *)compress_job,
- g_strdup (_("There was an error while compressing files.")),
- g_strdup (error->message),
- NULL,
- FALSE,
- CANCEL,
- NULL);
+ run_error ((CommonJob *) compress_job,
+ g_strdup (_("There was an error while compressing files.")),
+ g_strdup (error->message),
+ NULL,
+ FALSE,
+ CANCEL,
+ NULL);
- abort_job ((CommonJob *)compress_job);
+ abort_job ((CommonJob *) compress_job);
}
static void
compress_job_on_completed (AutoarCompressor *compressor,
gpointer user_data)
{
- CompressJob *compress_job = user_data;
- g_autoptr (GFile) destination_directory;
- char *status;
+ CompressJob *compress_job = user_data;
+ g_autoptr (GFile) destination_directory;
+ char *status;
- if (compress_job->total_files == 1) {
- status = f (_("Compressed “%B” into “%B”"),
- G_FILE (compress_job->source_files->data),
- compress_job->output_file);
- } else {
- status = f (ngettext ("Compressed %'d file into “%B”",
- "Compressed %'d files into “%B”",
- compress_job->total_files),
- compress_job->total_files,
- compress_job->output_file);
- }
+ if (compress_job->total_files == 1)
+ {
+ status = f (_("Compressed “%B” into “%B”"),
+ G_FILE (compress_job->source_files->data),
+ compress_job->output_file);
+ }
+ else
+ {
+ status = f (ngettext ("Compressed %'d file into “%B”",
+ "Compressed %'d files into “%B”",
+ compress_job->total_files),
+ compress_job->total_files,
+ compress_job->output_file);
+ }
- nautilus_progress_info_take_status (compress_job->common.progress,
- status);
+ nautilus_progress_info_take_status (compress_job->common.progress,
+ status);
- nautilus_file_changes_queue_file_added (compress_job->output_file);
+ nautilus_file_changes_queue_file_added (compress_job->output_file);
- destination_directory = g_file_get_parent (compress_job->output_file);
- nautilus_progress_info_set_destination (compress_job->common.progress,
- destination_directory);
+ destination_directory = g_file_get_parent (compress_job->output_file);
+ nautilus_progress_info_set_destination (compress_job->common.progress,
+ destination_directory);
}
static void
@@ -7632,49 +8722,50 @@ compress_task_thread_func (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- CompressJob *compress_job = task_data;
- SourceInfo source_info;
- g_autoptr (AutoarCompressor) compressor;
+ CompressJob *compress_job = task_data;
+ SourceInfo source_info;
+ g_autoptr (AutoarCompressor) compressor;
- g_timer_start (compress_job->common.time);
+ g_timer_start (compress_job->common.time);
- nautilus_progress_info_start (compress_job->common.progress);
+ nautilus_progress_info_start (compress_job->common.progress);
- scan_sources (compress_job->source_files,
- &source_info,
- (CommonJob *)compress_job,
- OP_KIND_COMPRESS);
+ scan_sources (compress_job->source_files,
+ &source_info,
+ (CommonJob *) compress_job,
+ OP_KIND_COMPRESS);
- compress_job->total_files = source_info.num_files;
- compress_job->total_size = source_info.num_bytes;
+ compress_job->total_files = source_info.num_files;
+ compress_job->total_size = source_info.num_bytes;
- compressor = autoar_compressor_new (compress_job->source_files,
- compress_job->output_file,
- compress_job->format,
- compress_job->filter,
- FALSE);
+ compressor = autoar_compressor_new (compress_job->source_files,
+ compress_job->output_file,
+ compress_job->format,
+ compress_job->filter,
+ FALSE);
- autoar_compressor_set_output_is_dest (compressor, TRUE);
+ autoar_compressor_set_output_is_dest (compressor, TRUE);
- autoar_compressor_set_notify_interval (compressor,
- PROGRESS_NOTIFY_INTERVAL);
+ autoar_compressor_set_notify_interval (compressor,
+ PROGRESS_NOTIFY_INTERVAL);
- g_signal_connect (compressor, "progress",
- G_CALLBACK (compress_job_on_progress), compress_job);
- g_signal_connect (compressor, "error",
- G_CALLBACK (compress_job_on_error), compress_job);
- g_signal_connect (compressor, "completed",
- G_CALLBACK (compress_job_on_completed), compress_job);
- autoar_compressor_start (compressor,
- compress_job->common.cancellable);
+ g_signal_connect (compressor, "progress",
+ G_CALLBACK (compress_job_on_progress), compress_job);
+ g_signal_connect (compressor, "error",
+ G_CALLBACK (compress_job_on_error), compress_job);
+ g_signal_connect (compressor, "completed",
+ G_CALLBACK (compress_job_on_completed), compress_job);
+ autoar_compressor_start (compressor,
+ compress_job->common.cancellable);
- compress_job->success = g_file_query_exists (compress_job->output_file,
- NULL);
+ compress_job->success = g_file_query_exists (compress_job->output_file,
+ NULL);
- /* There is nothing to undo if the output was not created */
- if (compress_job->common.undo_info != NULL && !compress_job->success) {
- g_clear_object (&compress_job->common.undo_info);
- }
+ /* There is nothing to undo if the output was not created */
+ if (compress_job->common.undo_info != NULL && !compress_job->success)
+ {
+ g_clear_object (&compress_job->common.undo_info);
+ }
}
void
@@ -7686,32 +8777,33 @@ nautilus_file_operations_compress (GList *files,
NautilusCreateCallback done_callback,
gpointer done_callback_data)
{
- g_autoptr (GTask) task;
- CompressJob *compress_job;
-
- compress_job = op_job_new (CompressJob, parent_window);
- compress_job->source_files = g_list_copy_deep (files,
- (GCopyFunc)g_object_ref,
- NULL);
- compress_job->output_file = g_object_ref (output);
- compress_job->format = format;
- compress_job->filter = filter;
- compress_job->done_callback = done_callback;
- compress_job->done_callback_data = done_callback_data;
-
- inhibit_power_manager ((CommonJob *)compress_job, _("Compressing Files"));
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- compress_job->common.undo_info = nautilus_file_undo_info_compress_new (files,
- output,
- format,
- filter);
- }
+ g_autoptr (GTask) task;
+ CompressJob *compress_job;
+
+ compress_job = op_job_new (CompressJob, parent_window);
+ compress_job->source_files = g_list_copy_deep (files,
+ (GCopyFunc) g_object_ref,
+ NULL);
+ compress_job->output_file = g_object_ref (output);
+ compress_job->format = format;
+ compress_job->filter = filter;
+ compress_job->done_callback = done_callback;
+ compress_job->done_callback_data = done_callback_data;
+
+ inhibit_power_manager ((CommonJob *) compress_job, _("Compressing Files"));
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ compress_job->common.undo_info = nautilus_file_undo_info_compress_new (files,
+ output,
+ format,
+ filter);
+ }
- task = g_task_new (NULL, compress_job->common.cancellable,
- compress_task_done, compress_job);
- g_task_set_task_data (task, compress_job, NULL);
- g_task_run_in_thread (task, compress_task_thread_func);
+ task = g_task_new (NULL, compress_job->common.cancellable,
+ compress_task_done, compress_job);
+ g_task_set_task_data (task, compress_job, NULL);
+ g_task_run_in_thread (task, compress_task_thread_func);
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
@@ -7719,53 +8811,53 @@ nautilus_file_operations_compress (GList *files,
void
nautilus_self_check_file_operations (void)
{
- setlocale (LC_MESSAGES, "C");
-
-
- /* test the next duplicate name generator */
- EEL_CHECK_STRING_RESULT (get_duplicate_name (" (copy)", 1, -1), " (another copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo", 1, -1), "foo (copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name (".bashrc", 1, -1), ".bashrc (copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name (".foo.txt", 1, -1), ".foo (copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo", 1, -1), "foo foo (copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo.txt", 1, -1), "foo (copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo.txt", 1, -1), "foo foo (copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo.txt txt", 1, -1), "foo foo (copy).txt txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo...txt", 1, -1), "foo.. (copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo...", 1, -1), "foo... (copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo. (copy)", 1, -1), "foo. (another copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (copy)", 1, -1), "foo (another copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (copy).txt", 1, -1), "foo (another copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (another copy)", 1, -1), "foo (3rd copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (another copy).txt", 1, -1), "foo (3rd copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (another copy).txt", 1, -1), "foo foo (3rd copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (13th copy)", 1, -1), "foo (14th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (13th copy).txt", 1, -1), "foo (14th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (21st copy)", 1, -1), "foo (22nd copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (21st copy).txt", 1, -1), "foo (22nd copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (22nd copy)", 1, -1), "foo (23rd copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (22nd copy).txt", 1, -1), "foo (23rd copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (23rd copy)", 1, -1), "foo (24th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (23rd copy).txt", 1, -1), "foo (24th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (24th copy)", 1, -1), "foo (25th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (24th copy).txt", 1, -1), "foo (25th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (24th copy)", 1, -1), "foo foo (25th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (24th copy).txt", 1, -1), "foo foo (25th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (100000000000000th copy).txt", 1, -1), "foo foo (copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (10th copy)", 1, -1), "foo (11th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (10th copy).txt", 1, -1), "foo (11th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (11th copy)", 1, -1), "foo (12th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (11th copy).txt", 1, -1), "foo (12th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (12th copy)", 1, -1), "foo (13th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (12th copy).txt", 1, -1), "foo (13th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (110th copy)", 1, -1), "foo (111th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (110th copy).txt", 1, -1), "foo (111th copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (122nd copy)", 1, -1), "foo (123rd copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (122nd copy).txt", 1, -1), "foo (123rd copy).txt");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (123rd copy)", 1, -1), "foo (124th copy)");
- EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (123rd copy).txt", 1, -1), "foo (124th copy).txt");
-
- setlocale (LC_MESSAGES, "");
+ setlocale (LC_MESSAGES, "C");
+
+
+ /* test the next duplicate name generator */
+ EEL_CHECK_STRING_RESULT (get_duplicate_name (" (copy)", 1, -1), " (another copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo", 1, -1), "foo (copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name (".bashrc", 1, -1), ".bashrc (copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name (".foo.txt", 1, -1), ".foo (copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo", 1, -1), "foo foo (copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo.txt", 1, -1), "foo (copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo.txt", 1, -1), "foo foo (copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo.txt txt", 1, -1), "foo foo (copy).txt txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo...txt", 1, -1), "foo.. (copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo...", 1, -1), "foo... (copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo. (copy)", 1, -1), "foo. (another copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (copy)", 1, -1), "foo (another copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (copy).txt", 1, -1), "foo (another copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (another copy)", 1, -1), "foo (3rd copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (another copy).txt", 1, -1), "foo (3rd copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (another copy).txt", 1, -1), "foo foo (3rd copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (13th copy)", 1, -1), "foo (14th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (13th copy).txt", 1, -1), "foo (14th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (21st copy)", 1, -1), "foo (22nd copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (21st copy).txt", 1, -1), "foo (22nd copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (22nd copy)", 1, -1), "foo (23rd copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (22nd copy).txt", 1, -1), "foo (23rd copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (23rd copy)", 1, -1), "foo (24th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (23rd copy).txt", 1, -1), "foo (24th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (24th copy)", 1, -1), "foo (25th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (24th copy).txt", 1, -1), "foo (25th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (24th copy)", 1, -1), "foo foo (25th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (24th copy).txt", 1, -1), "foo foo (25th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo foo (100000000000000th copy).txt", 1, -1), "foo foo (copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (10th copy)", 1, -1), "foo (11th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (10th copy).txt", 1, -1), "foo (11th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (11th copy)", 1, -1), "foo (12th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (11th copy).txt", 1, -1), "foo (12th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (12th copy)", 1, -1), "foo (13th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (12th copy).txt", 1, -1), "foo (13th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (110th copy)", 1, -1), "foo (111th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (110th copy).txt", 1, -1), "foo (111th copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (122nd copy)", 1, -1), "foo (123rd copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (122nd copy).txt", 1, -1), "foo (123rd copy).txt");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (123rd copy)", 1, -1), "foo (124th copy)");
+ EEL_CHECK_STRING_RESULT (get_duplicate_name ("foo (123rd copy).txt", 1, -1), "foo (124th copy).txt");
+
+ setlocale (LC_MESSAGES, "");
}
#endif
diff --git a/src/nautilus-file-queue.c b/src/nautilus-file-queue.c
index 846b1c4df..026ded1d4 100644
--- a/src/nautilus-file-queue.c
+++ b/src/nautilus-file-queue.c
@@ -1,122 +1,130 @@
/*
- Copyright (C) 2001 Maciej Stachowiak
-
- 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, see <http://www.gnu.org/licenses/>.
-
- Author: Maciej Stachowiak <mjs@noisehavoc.org>
-*/
+ * Copyright (C) 2001 Maciej Stachowiak
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Maciej Stachowiak <mjs@noisehavoc.org>
+ */
#include <config.h>
#include "nautilus-file-queue.h"
#include <glib.h>
-struct NautilusFileQueue {
- GList *head;
- GList *tail;
- GHashTable *item_to_link_map;
+struct NautilusFileQueue
+{
+ GList *head;
+ GList *tail;
+ GHashTable *item_to_link_map;
};
NautilusFileQueue *
nautilus_file_queue_new (void)
{
- NautilusFileQueue *queue;
-
- queue = g_new0 (NautilusFileQueue, 1);
- queue->item_to_link_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+ NautilusFileQueue *queue;
+
+ queue = g_new0 (NautilusFileQueue, 1);
+ queue->item_to_link_map = g_hash_table_new (g_direct_hash, g_direct_equal);
- return queue;
+ return queue;
}
void
nautilus_file_queue_destroy (NautilusFileQueue *queue)
{
- g_hash_table_destroy (queue->item_to_link_map);
- nautilus_file_list_free (queue->head);
- g_free (queue);
+ g_hash_table_destroy (queue->item_to_link_map);
+ nautilus_file_list_free (queue->head);
+ g_free (queue);
}
void
nautilus_file_queue_enqueue (NautilusFileQueue *queue,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (g_hash_table_lookup (queue->item_to_link_map, file) != NULL) {
- /* It's already on the queue. */
- return;
- }
-
- if (queue->tail == NULL) {
- queue->head = g_list_append (NULL, file);
- queue->tail = queue->head;
- } else {
- queue->tail = g_list_append (queue->tail, file);
- queue->tail = queue->tail->next;
- }
-
- nautilus_file_ref (file);
- g_hash_table_insert (queue->item_to_link_map, file, queue->tail);
+ if (g_hash_table_lookup (queue->item_to_link_map, file) != NULL)
+ {
+ /* It's already on the queue. */
+ return;
+ }
+
+ if (queue->tail == NULL)
+ {
+ queue->head = g_list_append (NULL, file);
+ queue->tail = queue->head;
+ }
+ else
+ {
+ queue->tail = g_list_append (queue->tail, file);
+ queue->tail = queue->tail->next;
+ }
+
+ nautilus_file_ref (file);
+ g_hash_table_insert (queue->item_to_link_map, file, queue->tail);
}
NautilusFile *
nautilus_file_queue_dequeue (NautilusFileQueue *queue)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_file_queue_head (queue);
- nautilus_file_queue_remove (queue, file);
+ file = nautilus_file_queue_head (queue);
+ nautilus_file_queue_remove (queue, file);
- return file;
+ return file;
}
void
nautilus_file_queue_remove (NautilusFileQueue *queue,
- NautilusFile *file)
+ NautilusFile *file)
{
- GList *link;
+ GList *link;
- link = g_hash_table_lookup (queue->item_to_link_map, file);
+ link = g_hash_table_lookup (queue->item_to_link_map, file);
- if (link == NULL) {
- /* It's not on the queue */
- return;
- }
+ if (link == NULL)
+ {
+ /* It's not on the queue */
+ return;
+ }
- if (link == queue->tail) {
- /* Need to special-case removing the tail. */
- queue->tail = queue->tail->prev;
- }
+ if (link == queue->tail)
+ {
+ /* Need to special-case removing the tail. */
+ queue->tail = queue->tail->prev;
+ }
- queue->head = g_list_remove_link (queue->head, link);
- g_list_free (link);
- g_hash_table_remove (queue->item_to_link_map, file);
+ queue->head = g_list_remove_link (queue->head, link);
+ g_list_free (link);
+ g_hash_table_remove (queue->item_to_link_map, file);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
NautilusFile *
nautilus_file_queue_head (NautilusFileQueue *queue)
{
- if (queue->head == NULL) {
- return NULL;
- }
+ if (queue->head == NULL)
+ {
+ return NULL;
+ }
- return NAUTILUS_FILE (queue->head->data);
+ return NAUTILUS_FILE (queue->head->data);
}
gboolean
nautilus_file_queue_is_empty (NautilusFileQueue *queue)
{
- return (queue->head == NULL);
+ return (queue->head == NULL);
}
diff --git a/src/nautilus-file-undo-manager.c b/src/nautilus-file-undo-manager.c
index 6db605e0f..cd6498a5f 100644
--- a/src/nautilus-file-undo-manager.c
+++ b/src/nautilus-file-undo-manager.c
@@ -1,4 +1,3 @@
-
/* nautilus-file-undo-manager.c - Manages the undo/redo stack
*
* Copyright (C) 2007-2011 Amos Brocco
@@ -35,9 +34,10 @@
#define DEBUG_FLAG NAUTILUS_DEBUG_UNDO
#include "nautilus-debug.h"
-enum {
- SIGNAL_UNDO_CHANGED,
- NUM_SIGNALS,
+enum
+{
+ SIGNAL_UNDO_CHANGED,
+ NUM_SIGNALS,
};
static guint signals[NUM_SIGNALS] = { 0, };
@@ -46,13 +46,13 @@ G_DEFINE_TYPE (NautilusFileUndoManager, nautilus_file_undo_manager, G_TYPE_OBJEC
struct _NautilusFileUndoManagerPrivate
{
- NautilusFileUndoInfo *info;
- NautilusFileUndoManagerState state;
- NautilusFileUndoManagerState last_state;
+ NautilusFileUndoInfo *info;
+ NautilusFileUndoManagerState state;
+ NautilusFileUndoManagerState last_state;
- guint is_operating : 1;
+ guint is_operating : 1;
- gulong trash_signal_id;
+ gulong trash_signal_id;
};
static NautilusFileUndoManager *undo_singleton = NULL;
@@ -60,204 +60,219 @@ static NautilusFileUndoManager *undo_singleton = NULL;
NautilusFileUndoManager *
nautilus_file_undo_manager_new (void)
{
- if (undo_singleton != NULL) {
- return g_object_ref (undo_singleton);
- }
+ if (undo_singleton != NULL)
+ {
+ return g_object_ref (undo_singleton);
+ }
- undo_singleton = g_object_new (NAUTILUS_TYPE_FILE_UNDO_MANAGER, NULL);
- g_object_add_weak_pointer (G_OBJECT (undo_singleton), (gpointer) &undo_singleton);
+ undo_singleton = g_object_new (NAUTILUS_TYPE_FILE_UNDO_MANAGER, NULL);
+ g_object_add_weak_pointer (G_OBJECT (undo_singleton), (gpointer) & undo_singleton);
- return undo_singleton;
+ return undo_singleton;
}
static void
file_undo_manager_clear (NautilusFileUndoManager *self)
{
- g_clear_object (&self->priv->info);
- self->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_NONE;
+ g_clear_object (&self->priv->info);
+ self->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_NONE;
}
static void
trash_state_changed_cb (NautilusTrashMonitor *monitor,
- gboolean is_empty,
- gpointer user_data)
+ gboolean is_empty,
+ gpointer user_data)
{
- NautilusFileUndoManager *self = user_data;
-
- /* A trash operation cannot be undone if the trash is empty */
- if (is_empty &&
- self->priv->state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO &&
- NAUTILUS_IS_FILE_UNDO_INFO_TRASH (self->priv->info)) {
- file_undo_manager_clear (self);
- g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
- }
+ NautilusFileUndoManager *self = user_data;
+
+ /* A trash operation cannot be undone if the trash is empty */
+ if (is_empty &&
+ self->priv->state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO &&
+ NAUTILUS_IS_FILE_UNDO_INFO_TRASH (self->priv->info))
+ {
+ file_undo_manager_clear (self);
+ g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
+ }
}
static void
-nautilus_file_undo_manager_init (NautilusFileUndoManager * self)
+nautilus_file_undo_manager_init (NautilusFileUndoManager *self)
{
- NautilusFileUndoManagerPrivate *priv = self->priv =
- G_TYPE_INSTANCE_GET_PRIVATE (self,
- NAUTILUS_TYPE_FILE_UNDO_MANAGER,
- NautilusFileUndoManagerPrivate);
-
- priv->trash_signal_id = g_signal_connect (nautilus_trash_monitor_get (),
- "trash-state-changed",
- G_CALLBACK (trash_state_changed_cb), self);
+ NautilusFileUndoManagerPrivate *priv = self->priv =
+ G_TYPE_INSTANCE_GET_PRIVATE (self,
+ NAUTILUS_TYPE_FILE_UNDO_MANAGER,
+ NautilusFileUndoManagerPrivate);
+
+ priv->trash_signal_id = g_signal_connect (nautilus_trash_monitor_get (),
+ "trash-state-changed",
+ G_CALLBACK (trash_state_changed_cb), self);
}
static void
-nautilus_file_undo_manager_finalize (GObject * object)
+nautilus_file_undo_manager_finalize (GObject *object)
{
- NautilusFileUndoManager *self = NAUTILUS_FILE_UNDO_MANAGER (object);
- NautilusFileUndoManagerPrivate *priv = self->priv;
+ NautilusFileUndoManager *self = NAUTILUS_FILE_UNDO_MANAGER (object);
+ NautilusFileUndoManagerPrivate *priv = self->priv;
- if (priv->trash_signal_id != 0) {
- g_signal_handler_disconnect (nautilus_trash_monitor_get (),
- priv->trash_signal_id);
- priv->trash_signal_id = 0;
- }
+ if (priv->trash_signal_id != 0)
+ {
+ g_signal_handler_disconnect (nautilus_trash_monitor_get (),
+ priv->trash_signal_id);
+ priv->trash_signal_id = 0;
+ }
- file_undo_manager_clear (self);
+ file_undo_manager_clear (self);
- G_OBJECT_CLASS (nautilus_file_undo_manager_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_file_undo_manager_parent_class)->finalize (object);
}
static void
nautilus_file_undo_manager_class_init (NautilusFileUndoManagerClass *klass)
{
- GObjectClass *oclass;
+ GObjectClass *oclass;
- oclass = G_OBJECT_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
- oclass->finalize = nautilus_file_undo_manager_finalize;
+ oclass->finalize = nautilus_file_undo_manager_finalize;
- signals[SIGNAL_UNDO_CHANGED] =
- g_signal_new ("undo-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ signals[SIGNAL_UNDO_CHANGED] =
+ g_signal_new ("undo-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
- g_type_class_add_private (klass, sizeof (NautilusFileUndoManagerPrivate));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoManagerPrivate));
}
static void
-undo_info_apply_ready (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
+undo_info_apply_ready (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusFileUndoManager *self = user_data;
- NautilusFileUndoInfo *info = NAUTILUS_FILE_UNDO_INFO (source);
- gboolean success, user_cancel;
-
- success = nautilus_file_undo_info_apply_finish (info, res, &user_cancel, NULL);
-
- self->priv->is_operating = FALSE;
-
- /* just return in case we got another another operation set */
- if ((self->priv->info != NULL) &&
- (self->priv->info != info)) {
- return;
- }
-
- if (success) {
- if (self->priv->last_state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO) {
- self->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_REDO;
- } else if (self->priv->last_state == NAUTILUS_FILE_UNDO_MANAGER_STATE_REDO) {
- self->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
- }
-
- self->priv->info = g_object_ref (info);
- } else if (user_cancel) {
- self->priv->state = self->priv->last_state;
- self->priv->info = g_object_ref (info);
- } else {
- file_undo_manager_clear (self);
- }
-
- g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
+ NautilusFileUndoManager *self = user_data;
+ NautilusFileUndoInfo *info = NAUTILUS_FILE_UNDO_INFO (source);
+ gboolean success, user_cancel;
+
+ success = nautilus_file_undo_info_apply_finish (info, res, &user_cancel, NULL);
+
+ self->priv->is_operating = FALSE;
+
+ /* just return in case we got another another operation set */
+ if ((self->priv->info != NULL) &&
+ (self->priv->info != info))
+ {
+ return;
+ }
+
+ if (success)
+ {
+ if (self->priv->last_state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO)
+ {
+ self->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_REDO;
+ }
+ else if (self->priv->last_state == NAUTILUS_FILE_UNDO_MANAGER_STATE_REDO)
+ {
+ self->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
+ }
+
+ self->priv->info = g_object_ref (info);
+ }
+ else if (user_cancel)
+ {
+ self->priv->state = self->priv->last_state;
+ self->priv->info = g_object_ref (info);
+ }
+ else
+ {
+ file_undo_manager_clear (self);
+ }
+
+ g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
}
static void
do_undo_redo (NautilusFileUndoManager *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- gboolean undo = self->priv->state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
+ gboolean undo = self->priv->state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
- self->priv->last_state = self->priv->state;
+ self->priv->last_state = self->priv->state;
- self->priv->is_operating = TRUE;
- nautilus_file_undo_info_apply_async (self->priv->info, undo, parent_window,
- undo_info_apply_ready, self);
+ self->priv->is_operating = TRUE;
+ nautilus_file_undo_info_apply_async (self->priv->info, undo, parent_window,
+ undo_info_apply_ready, self);
- /* clear actions while undoing */
- file_undo_manager_clear (self);
- g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
+ /* clear actions while undoing */
+ file_undo_manager_clear (self);
+ g_signal_emit (self, signals[SIGNAL_UNDO_CHANGED], 0);
}
void
nautilus_file_undo_manager_redo (GtkWindow *parent_window)
{
- if (undo_singleton->priv->state != NAUTILUS_FILE_UNDO_MANAGER_STATE_REDO) {
- g_warning ("Called redo, but state is %s!", undo_singleton->priv->state == 0 ?
- "none" : "undo");
- return;
- }
-
- do_undo_redo (undo_singleton, parent_window);
+ if (undo_singleton->priv->state != NAUTILUS_FILE_UNDO_MANAGER_STATE_REDO)
+ {
+ g_warning ("Called redo, but state is %s!", undo_singleton->priv->state == 0 ?
+ "none" : "undo");
+ return;
+ }
+
+ do_undo_redo (undo_singleton, parent_window);
}
void
nautilus_file_undo_manager_undo (GtkWindow *parent_window)
{
- if (undo_singleton->priv->state != NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO) {
- g_warning ("Called undo, but state is %s!", undo_singleton->priv->state == 0 ?
- "none" : "redo");
- return;
- }
-
- do_undo_redo (undo_singleton, parent_window);
+ if (undo_singleton->priv->state != NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO)
+ {
+ g_warning ("Called undo, but state is %s!", undo_singleton->priv->state == 0 ?
+ "none" : "redo");
+ return;
+ }
+
+ do_undo_redo (undo_singleton, parent_window);
}
void
nautilus_file_undo_manager_set_action (NautilusFileUndoInfo *info)
{
- DEBUG ("Setting undo information %p", info);
+ DEBUG ("Setting undo information %p", info);
- file_undo_manager_clear (undo_singleton);
+ file_undo_manager_clear (undo_singleton);
- if (info != NULL) {
- undo_singleton->priv->info = g_object_ref (info);
- undo_singleton->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
- undo_singleton->priv->last_state = NAUTILUS_FILE_UNDO_MANAGER_STATE_NONE;
- }
+ if (info != NULL)
+ {
+ undo_singleton->priv->info = g_object_ref (info);
+ undo_singleton->priv->state = NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
+ undo_singleton->priv->last_state = NAUTILUS_FILE_UNDO_MANAGER_STATE_NONE;
+ }
- g_signal_emit (undo_singleton, signals[SIGNAL_UNDO_CHANGED], 0);
+ g_signal_emit (undo_singleton, signals[SIGNAL_UNDO_CHANGED], 0);
}
NautilusFileUndoInfo *
nautilus_file_undo_manager_get_action (void)
{
- return undo_singleton->priv->info;
+ return undo_singleton->priv->info;
}
-NautilusFileUndoManagerState
+NautilusFileUndoManagerState
nautilus_file_undo_manager_get_state (void)
{
- return undo_singleton->priv->state;
+ return undo_singleton->priv->state;
}
gboolean
nautilus_file_undo_manager_is_operating ()
{
- return undo_singleton->priv->is_operating;
+ return undo_singleton->priv->is_operating;
}
NautilusFileUndoManager *
nautilus_file_undo_manager_get ()
{
- return undo_singleton;
+ return undo_singleton;
}
diff --git a/src/nautilus-file-undo-operations.c b/src/nautilus-file-undo-operations.c
index 3ec2832f8..5748d4259 100644
--- a/src/nautilus-file-undo-operations.c
+++ b/src/nautilus-file-undo-operations.c
@@ -1,4 +1,3 @@
-
/* nautilus-file-undo-operations.c - Manages undo/redo of file operations
*
* Copyright (C) 2007-2011 Amos Brocco
@@ -43,1963 +42,2098 @@
G_DEFINE_TYPE (NautilusFileUndoInfo, nautilus_file_undo_info, G_TYPE_OBJECT)
-enum {
- PROP_OP_TYPE = 1,
- PROP_ITEM_COUNT,
- N_PROPERTIES
+enum
+{
+ PROP_OP_TYPE = 1,
+ PROP_ITEM_COUNT,
+ N_PROPERTIES
};
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
-struct _NautilusFileUndoInfoDetails {
- NautilusFileUndoOp op_type;
- guint count; /* Number of items */
+struct _NautilusFileUndoInfoDetails
+{
+ NautilusFileUndoOp op_type;
+ guint count; /* Number of items */
- GTask *apply_async_task;
+ GTask *apply_async_task;
- gchar *undo_label;
- gchar *redo_label;
- gchar *undo_description;
- gchar *redo_description;
+ gchar *undo_label;
+ gchar *redo_label;
+ gchar *undo_description;
+ gchar *redo_description;
};
/* description helpers */
static void
nautilus_file_undo_info_init (NautilusFileUndoInfo *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_FILE_UNDO_INFO,
- NautilusFileUndoInfoDetails);
- self->priv->apply_async_task = NULL;
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_FILE_UNDO_INFO,
+ NautilusFileUndoInfoDetails);
+ self->priv->apply_async_task = NULL;
}
static void
-nautilus_file_undo_info_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_file_undo_info_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusFileUndoInfo *self = NAUTILUS_FILE_UNDO_INFO (object);
+ NautilusFileUndoInfo *self = NAUTILUS_FILE_UNDO_INFO (object);
+
+ switch (property_id)
+ {
+ case PROP_OP_TYPE:
+ {
+ g_value_set_int (value, self->priv->op_type);
+ }
+ break;
+
+ case PROP_ITEM_COUNT:
+ {
+ g_value_set_int (value, self->priv->count);
+ }
+ break;
- switch (property_id) {
- case PROP_OP_TYPE:
- g_value_set_int (value, self->priv->op_type);
- break;
- case PROP_ITEM_COUNT:
- g_value_set_int (value, self->priv->count);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_file_undo_info_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_file_undo_info_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusFileUndoInfo *self = NAUTILUS_FILE_UNDO_INFO (object);
+ NautilusFileUndoInfo *self = NAUTILUS_FILE_UNDO_INFO (object);
- switch (property_id) {
- case PROP_OP_TYPE:
- self->priv->op_type = g_value_get_int (value);
- break;
- case PROP_ITEM_COUNT:
- self->priv->count = g_value_get_int (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ switch (property_id)
+ {
+ case PROP_OP_TYPE:
+ {
+ self->priv->op_type = g_value_get_int (value);
+ }
+ break;
+
+ case PROP_ITEM_COUNT:
+ {
+ self->priv->count = g_value_get_int (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_file_redo_info_warn_redo (NautilusFileUndoInfo *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- g_critical ("Object %p of type %s does not implement redo_func!!",
- self, G_OBJECT_TYPE_NAME (self));
+ g_critical ("Object %p of type %s does not implement redo_func!!",
+ self, G_OBJECT_TYPE_NAME (self));
}
static void
nautilus_file_undo_info_warn_undo (NautilusFileUndoInfo *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- g_critical ("Object %p of type %s does not implement undo_func!!",
- self, G_OBJECT_TYPE_NAME (self));
+ g_critical ("Object %p of type %s does not implement undo_func!!",
+ self, G_OBJECT_TYPE_NAME (self));
}
static void
-nautilus_file_undo_info_strings_func (NautilusFileUndoInfo *self,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+nautilus_file_undo_info_strings_func (NautilusFileUndoInfo *self,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- if (undo_label != NULL) {
- *undo_label = g_strdup (_("Undo"));
- }
- if (undo_description != NULL) {
- *undo_description = g_strdup (_("Undo last action"));
- }
+ if (undo_label != NULL)
+ {
+ *undo_label = g_strdup (_("Undo"));
+ }
+ if (undo_description != NULL)
+ {
+ *undo_description = g_strdup (_("Undo last action"));
+ }
- if (redo_label != NULL) {
- *redo_label = g_strdup (_("Redo"));
- }
- if (redo_description != NULL) {
- *redo_description = g_strdup (_("Redo last undone action"));
- }
+ if (redo_label != NULL)
+ {
+ *redo_label = g_strdup (_("Redo"));
+ }
+ if (redo_description != NULL)
+ {
+ *redo_description = g_strdup (_("Redo last undone action"));
+ }
}
static void
nautilus_file_undo_info_finalize (GObject *obj)
{
- NautilusFileUndoInfo *self = NAUTILUS_FILE_UNDO_INFO (obj);
+ NautilusFileUndoInfo *self = NAUTILUS_FILE_UNDO_INFO (obj);
- g_clear_object (&self->priv->apply_async_task);
+ g_clear_object (&self->priv->apply_async_task);
- G_OBJECT_CLASS (nautilus_file_undo_info_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_class_init (NautilusFileUndoInfoClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_finalize;
- oclass->get_property = nautilus_file_undo_info_get_property;
- oclass->set_property = nautilus_file_undo_info_set_property;
+ oclass->finalize = nautilus_file_undo_info_finalize;
+ oclass->get_property = nautilus_file_undo_info_get_property;
+ oclass->set_property = nautilus_file_undo_info_set_property;
- klass->undo_func = nautilus_file_undo_info_warn_undo;
- klass->redo_func = nautilus_file_redo_info_warn_redo;
- klass->strings_func = nautilus_file_undo_info_strings_func;
+ klass->undo_func = nautilus_file_undo_info_warn_undo;
+ klass->redo_func = nautilus_file_redo_info_warn_redo;
+ klass->strings_func = nautilus_file_undo_info_strings_func;
- properties[PROP_OP_TYPE] =
- g_param_spec_int ("op-type",
- "Undo info op type",
- "Type of undo operation",
- 0, NAUTILUS_FILE_UNDO_OP_NUM_TYPES - 1, 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
- properties[PROP_ITEM_COUNT] =
- g_param_spec_int ("item-count",
- "Number of items",
- "Number of items",
- 0, G_MAXINT, 0,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_OP_TYPE] =
+ g_param_spec_int ("op-type",
+ "Undo info op type",
+ "Type of undo operation",
+ 0, NAUTILUS_FILE_UNDO_OP_NUM_TYPES - 1, 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY);
+ properties[PROP_ITEM_COUNT] =
+ g_param_spec_int ("item-count",
+ "Number of items",
+ "Number of items",
+ 0, G_MAXINT, 0,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY);
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoDetails));
- g_object_class_install_properties (oclass, N_PROPERTIES, properties);
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoDetails));
+ g_object_class_install_properties (oclass, N_PROPERTIES, properties);
}
NautilusFileUndoOp
nautilus_file_undo_info_get_op_type (NautilusFileUndoInfo *self)
{
- return self->priv->op_type;
+ return self->priv->op_type;
}
static gint
nautilus_file_undo_info_get_item_count (NautilusFileUndoInfo *self)
{
- return self->priv->count;
+ return self->priv->count;
}
void
nautilus_file_undo_info_apply_async (NautilusFileUndoInfo *self,
- gboolean undo,
- GtkWindow *parent_window,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ gboolean undo,
+ GtkWindow *parent_window,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- g_assert (self->priv->apply_async_task == NULL);
+ g_assert (self->priv->apply_async_task == NULL);
- self->priv->apply_async_task = g_task_new (G_OBJECT (self),
- NULL,
- callback,
- user_data);
+ self->priv->apply_async_task = g_task_new (G_OBJECT (self),
+ NULL,
+ callback,
+ user_data);
- if (undo) {
- NAUTILUS_FILE_UNDO_INFO_CLASS (G_OBJECT_GET_CLASS (self))->undo_func (self, parent_window);
- } else {
- NAUTILUS_FILE_UNDO_INFO_CLASS (G_OBJECT_GET_CLASS (self))->redo_func (self, parent_window);
- }
+ if (undo)
+ {
+ NAUTILUS_FILE_UNDO_INFO_CLASS (G_OBJECT_GET_CLASS (self))->undo_func (self, parent_window);
+ }
+ else
+ {
+ NAUTILUS_FILE_UNDO_INFO_CLASS (G_OBJECT_GET_CLASS (self))->redo_func (self, parent_window);
+ }
}
-typedef struct {
- gboolean success;
- gboolean user_cancel;
+typedef struct
+{
+ gboolean success;
+ gboolean user_cancel;
} FileUndoInfoOpRes;
static void
file_undo_info_op_res_free (gpointer data)
{
- g_slice_free (FileUndoInfoOpRes, data);
+ g_slice_free (FileUndoInfoOpRes, data);
}
gboolean
-nautilus_file_undo_info_apply_finish (NautilusFileUndoInfo *self,
- GAsyncResult *res,
- gboolean *user_cancel,
- GError **error)
+nautilus_file_undo_info_apply_finish (NautilusFileUndoInfo *self,
+ GAsyncResult *res,
+ gboolean *user_cancel,
+ GError **error)
{
- FileUndoInfoOpRes *op_res;
- gboolean success = FALSE;
+ FileUndoInfoOpRes *op_res;
+ gboolean success = FALSE;
- op_res = g_task_propagate_pointer (G_TASK (res), error);
+ op_res = g_task_propagate_pointer (G_TASK (res), error);
- if (op_res != NULL) {
- *user_cancel = op_res->user_cancel;
- success = op_res->success;
+ if (op_res != NULL)
+ {
+ *user_cancel = op_res->user_cancel;
+ success = op_res->success;
- file_undo_info_op_res_free (op_res);
- }
+ file_undo_info_op_res_free (op_res);
+ }
- return success;
+ return success;
}
void
-nautilus_file_undo_info_get_strings (NautilusFileUndoInfo *self,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+nautilus_file_undo_info_get_strings (NautilusFileUndoInfo *self,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NAUTILUS_FILE_UNDO_INFO_CLASS (G_OBJECT_GET_CLASS (self))->strings_func (self,
- undo_label, undo_description,
- redo_label, redo_description);
+ NAUTILUS_FILE_UNDO_INFO_CLASS (G_OBJECT_GET_CLASS (self))->strings_func (self,
+ undo_label, undo_description,
+ redo_label, redo_description);
}
static void
file_undo_info_complete_apply (NautilusFileUndoInfo *self,
- gboolean success,
- gboolean user_cancel)
+ gboolean success,
+ gboolean user_cancel)
{
- FileUndoInfoOpRes *op_res = g_slice_new0 (FileUndoInfoOpRes);
+ FileUndoInfoOpRes *op_res = g_slice_new0 (FileUndoInfoOpRes);
- op_res->user_cancel = user_cancel;
- op_res->success = success;
+ op_res->user_cancel = user_cancel;
+ op_res->success = success;
- g_task_return_pointer (self->priv->apply_async_task, op_res,
- file_undo_info_op_res_free);
+ g_task_return_pointer (self->priv->apply_async_task, op_res,
+ file_undo_info_op_res_free);
- g_clear_object (&self->priv->apply_async_task);
+ g_clear_object (&self->priv->apply_async_task);
}
static void
-file_undo_info_transfer_callback (GHashTable * debuting_uris,
- gboolean success,
- gpointer user_data)
+file_undo_info_transfer_callback (GHashTable *debuting_uris,
+ gboolean success,
+ gpointer user_data)
{
- NautilusFileUndoInfo *self = user_data;
+ NautilusFileUndoInfo *self = user_data;
- /* TODO: we need to forward the cancelled state from
- * the file operation to the file undo info object.
- */
- file_undo_info_complete_apply (self, success, FALSE);
+ /* TODO: we need to forward the cancelled state from
+ * the file operation to the file undo info object.
+ */
+ file_undo_info_complete_apply (self, success, FALSE);
}
static void
-file_undo_info_operation_callback (NautilusFile * file,
- GFile * result_location,
- GError * error,
- gpointer user_data)
+file_undo_info_operation_callback (NautilusFile *file,
+ GFile *result_location,
+ GError *error,
+ gpointer user_data)
{
- NautilusFileUndoInfo *self = user_data;
+ NautilusFileUndoInfo *self = user_data;
- file_undo_info_complete_apply (self, (error == NULL),
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED));
+ file_undo_info_complete_apply (self, (error == NULL),
+ g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED));
}
static void
file_undo_info_delete_callback (GHashTable *debuting_uris,
- gboolean user_cancel,
- gpointer user_data)
+ gboolean user_cancel,
+ gpointer user_data)
{
- NautilusFileUndoInfo *self = user_data;
+ NautilusFileUndoInfo *self = user_data;
- file_undo_info_complete_apply (self,
- !user_cancel,
- user_cancel);
+ file_undo_info_complete_apply (self,
+ !user_cancel,
+ user_cancel);
}
/* copy/move/duplicate/link/restore from trash */
G_DEFINE_TYPE (NautilusFileUndoInfoExt, nautilus_file_undo_info_ext, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoExtDetails {
- GFile *src_dir;
- GFile *dest_dir;
- GQueue *sources; /* Relative to src_dir */
- GQueue *destinations; /* Relative to dest_dir */
+struct _NautilusFileUndoInfoExtDetails
+{
+ GFile *src_dir;
+ GFile *dest_dir;
+ GQueue *sources; /* Relative to src_dir */
+ GQueue *destinations; /* Relative to dest_dir */
};
static char *
ext_get_first_target_short_name (NautilusFileUndoInfoExt *self)
{
- GList *targets_first;
- char *file_name = NULL;
-
- targets_first = g_queue_peek_head_link (self->priv->destinations);
-
- if (targets_first != NULL &&
- targets_first->data != NULL) {
- file_name = g_file_get_basename (targets_first->data);
- }
-
- return file_name;
-}
-
-static void
-ext_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
-{
- NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
- gint count = nautilus_file_undo_info_get_item_count (info);
- gchar *name = NULL, *source, *destination;
-
- source = g_file_get_path (self->priv->src_dir);
- destination = g_file_get_path (self->priv->dest_dir);
-
- if (count <= 1) {
- name = ext_get_first_target_short_name (self);
- }
-
- if (op_type == NAUTILUS_FILE_UNDO_OP_MOVE) {
- if (count > 1) {
- *undo_description = g_strdup_printf (ngettext ("Move %d item back to '%s'",
- "Move %d items back to '%s'", count),
- count, source);
- *redo_description = g_strdup_printf (ngettext ("Move %d item to '%s'",
- "Move %d items to '%s'", count),
- count, destination);
-
- *undo_label = g_strdup_printf (ngettext ("_Undo Move %d item",
- "_Undo Move %d items", count),
- count);
- *redo_label = g_strdup_printf (ngettext ("_Redo Move %d item",
- "_Redo Move %d items", count),
- count);
- } else {
- *undo_description = g_strdup_printf (_("Move '%s' back to '%s'"), name, source);
- *redo_description = g_strdup_printf (_("Move '%s' to '%s'"), name, destination);
-
- *undo_label = g_strdup (_("_Undo Move"));
- *redo_label = g_strdup (_("_Redo Move"));
- }
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH) {
- *undo_label = g_strdup (_("_Undo Restore from Trash"));
- *redo_label = g_strdup (_("_Redo Restore from Trash"));
-
- if (count > 1) {
- *undo_description = g_strdup_printf (ngettext ("Move %d item back to trash",
- "Move %d items back to trash", count),
- count);
- *redo_description = g_strdup_printf (ngettext ("Restore %d item from trash",
- "Restore %d items from trash", count),
- count);
- } else {
- *undo_description = g_strdup_printf (_("Move '%s' back to trash"), name);
- *redo_description = g_strdup_printf (_("Restore '%s' from trash"), name);
- }
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_COPY) {
- if (count > 1) {
- *undo_description = g_strdup_printf (ngettext ("Delete %d copied item",
- "Delete %d copied items", count),
- count);
- *redo_description = g_strdup_printf (ngettext ("Copy %d item to '%s'",
- "Copy %d items to '%s'", count),
- count, destination);
-
- *undo_label = g_strdup_printf (ngettext ("_Undo Copy %d item",
- "_Undo Copy %d items", count),
- count);
- *redo_label = g_strdup_printf (ngettext ("_Redo Copy %d item",
- "_Redo Copy %d items", count),
- count);
- } else {
- *undo_description = g_strdup_printf (_("Delete '%s'"), name);
- *redo_description = g_strdup_printf (_("Copy '%s' to '%s'"), name, destination);
-
- *undo_label = g_strdup (_("_Undo Copy"));
- *redo_label = g_strdup (_("_Redo Copy"));
- }
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE) {
- if (count > 1) {
- *undo_description = g_strdup_printf (ngettext ("Delete %d duplicated item",
- "Delete %d duplicated items", count),
- count);
- *redo_description = g_strdup_printf (ngettext ("Duplicate %d item in '%s'",
- "Duplicate %d items in '%s'", count),
- count, destination);
-
- *undo_label = g_strdup_printf (ngettext ("_Undo Duplicate %d item",
- "_Undo Duplicate %d items", count),
- count);
- *redo_label = g_strdup_printf (ngettext ("_Redo Duplicate %d item",
- "_Redo Duplicate %d items", count),
- count);
- } else {
- *undo_description = g_strdup_printf (_("Delete '%s'"), name);
- *redo_description = g_strdup_printf (_("Duplicate '%s' in '%s'"),
- name, destination);
-
- *undo_label = g_strdup (_("_Undo Duplicate"));
- *redo_label = g_strdup (_("_Redo Duplicate"));
- }
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_LINK) {
- if (count > 1) {
- *undo_description = g_strdup_printf (ngettext ("Delete links to %d item",
- "Delete links to %d items", count),
- count);
- *redo_description = g_strdup_printf (ngettext ("Create links to %d item",
- "Create links to %d items", count),
- count);
- } else {
- *undo_description = g_strdup_printf (_("Delete link to '%s'"), name);
- *redo_description = g_strdup_printf (_("Create link to '%s'"), name);
-
- *undo_label = g_strdup (_("_Undo Create Link"));
- *redo_label = g_strdup (_("_Redo Create Link"));
- }
- } else {
- g_assert_not_reached ();
- }
-
- g_free (name);
- g_free (source);
- g_free (destination);
+ GList *targets_first;
+ char *file_name = NULL;
+
+ targets_first = g_queue_peek_head_link (self->priv->destinations);
+
+ if (targets_first != NULL &&
+ targets_first->data != NULL)
+ {
+ file_name = g_file_get_basename (targets_first->data);
+ }
+
+ return file_name;
+}
+
+static void
+ext_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
+{
+ NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
+ gint count = nautilus_file_undo_info_get_item_count (info);
+ gchar *name = NULL, *source, *destination;
+
+ source = g_file_get_path (self->priv->src_dir);
+ destination = g_file_get_path (self->priv->dest_dir);
+
+ if (count <= 1)
+ {
+ name = ext_get_first_target_short_name (self);
+ }
+
+ if (op_type == NAUTILUS_FILE_UNDO_OP_MOVE)
+ {
+ if (count > 1)
+ {
+ *undo_description = g_strdup_printf (ngettext ("Move %d item back to '%s'",
+ "Move %d items back to '%s'", count),
+ count, source);
+ *redo_description = g_strdup_printf (ngettext ("Move %d item to '%s'",
+ "Move %d items to '%s'", count),
+ count, destination);
+
+ *undo_label = g_strdup_printf (ngettext ("_Undo Move %d item",
+ "_Undo Move %d items", count),
+ count);
+ *redo_label = g_strdup_printf (ngettext ("_Redo Move %d item",
+ "_Redo Move %d items", count),
+ count);
+ }
+ else
+ {
+ *undo_description = g_strdup_printf (_("Move '%s' back to '%s'"), name, source);
+ *redo_description = g_strdup_printf (_("Move '%s' to '%s'"), name, destination);
+
+ *undo_label = g_strdup (_("_Undo Move"));
+ *redo_label = g_strdup (_("_Redo Move"));
+ }
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH)
+ {
+ *undo_label = g_strdup (_("_Undo Restore from Trash"));
+ *redo_label = g_strdup (_("_Redo Restore from Trash"));
+
+ if (count > 1)
+ {
+ *undo_description = g_strdup_printf (ngettext ("Move %d item back to trash",
+ "Move %d items back to trash", count),
+ count);
+ *redo_description = g_strdup_printf (ngettext ("Restore %d item from trash",
+ "Restore %d items from trash", count),
+ count);
+ }
+ else
+ {
+ *undo_description = g_strdup_printf (_("Move '%s' back to trash"), name);
+ *redo_description = g_strdup_printf (_("Restore '%s' from trash"), name);
+ }
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_COPY)
+ {
+ if (count > 1)
+ {
+ *undo_description = g_strdup_printf (ngettext ("Delete %d copied item",
+ "Delete %d copied items", count),
+ count);
+ *redo_description = g_strdup_printf (ngettext ("Copy %d item to '%s'",
+ "Copy %d items to '%s'", count),
+ count, destination);
+
+ *undo_label = g_strdup_printf (ngettext ("_Undo Copy %d item",
+ "_Undo Copy %d items", count),
+ count);
+ *redo_label = g_strdup_printf (ngettext ("_Redo Copy %d item",
+ "_Redo Copy %d items", count),
+ count);
+ }
+ else
+ {
+ *undo_description = g_strdup_printf (_("Delete '%s'"), name);
+ *redo_description = g_strdup_printf (_("Copy '%s' to '%s'"), name, destination);
+
+ *undo_label = g_strdup (_("_Undo Copy"));
+ *redo_label = g_strdup (_("_Redo Copy"));
+ }
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE)
+ {
+ if (count > 1)
+ {
+ *undo_description = g_strdup_printf (ngettext ("Delete %d duplicated item",
+ "Delete %d duplicated items", count),
+ count);
+ *redo_description = g_strdup_printf (ngettext ("Duplicate %d item in '%s'",
+ "Duplicate %d items in '%s'", count),
+ count, destination);
+
+ *undo_label = g_strdup_printf (ngettext ("_Undo Duplicate %d item",
+ "_Undo Duplicate %d items", count),
+ count);
+ *redo_label = g_strdup_printf (ngettext ("_Redo Duplicate %d item",
+ "_Redo Duplicate %d items", count),
+ count);
+ }
+ else
+ {
+ *undo_description = g_strdup_printf (_("Delete '%s'"), name);
+ *redo_description = g_strdup_printf (_("Duplicate '%s' in '%s'"),
+ name, destination);
+
+ *undo_label = g_strdup (_("_Undo Duplicate"));
+ *redo_label = g_strdup (_("_Redo Duplicate"));
+ }
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_LINK)
+ {
+ if (count > 1)
+ {
+ *undo_description = g_strdup_printf (ngettext ("Delete links to %d item",
+ "Delete links to %d items", count),
+ count);
+ *redo_description = g_strdup_printf (ngettext ("Create links to %d item",
+ "Create links to %d items", count),
+ count);
+ }
+ else
+ {
+ *undo_description = g_strdup_printf (_("Delete link to '%s'"), name);
+ *redo_description = g_strdup_printf (_("Create link to '%s'"), name);
+
+ *undo_label = g_strdup (_("_Undo Create Link"));
+ *redo_label = g_strdup (_("_Redo Create Link"));
+ }
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+
+ g_free (name);
+ g_free (source);
+ g_free (destination);
}
static void
ext_create_link_redo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- nautilus_file_operations_link (g_queue_peek_head_link (self->priv->sources),
- NULL,
- self->priv->dest_dir,
- parent_window,
- file_undo_info_transfer_callback,
- self);
+ nautilus_file_operations_link (g_queue_peek_head_link (self->priv->sources),
+ NULL,
+ self->priv->dest_dir,
+ parent_window,
+ file_undo_info_transfer_callback,
+ self);
}
static void
ext_duplicate_redo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- nautilus_file_operations_duplicate (g_queue_peek_head_link (self->priv->sources),
- NULL,
- parent_window,
- file_undo_info_transfer_callback,
- self);
+ nautilus_file_operations_duplicate (g_queue_peek_head_link (self->priv->sources),
+ NULL,
+ parent_window,
+ file_undo_info_transfer_callback,
+ self);
}
static void
ext_copy_redo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- nautilus_file_operations_copy (g_queue_peek_head_link (self->priv->sources),
- NULL,
- self->priv->dest_dir,
- parent_window,
- file_undo_info_transfer_callback,
- self);
+ nautilus_file_operations_copy (g_queue_peek_head_link (self->priv->sources),
+ NULL,
+ self->priv->dest_dir,
+ parent_window,
+ file_undo_info_transfer_callback,
+ self);
}
static void
ext_move_restore_redo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- nautilus_file_operations_move (g_queue_peek_head_link (self->priv->sources),
- NULL,
- self->priv->dest_dir,
- parent_window,
- file_undo_info_transfer_callback,
- self);
+ nautilus_file_operations_move (g_queue_peek_head_link (self->priv->sources),
+ NULL,
+ self->priv->dest_dir,
+ parent_window,
+ file_undo_info_transfer_callback,
+ self);
}
static void
ext_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
-{
- NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
-
- if (op_type == NAUTILUS_FILE_UNDO_OP_MOVE ||
- op_type == NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH) {
- ext_move_restore_redo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_COPY) {
- ext_copy_redo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE) {
- ext_duplicate_redo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_LINK) {
- ext_create_link_redo_func (self, parent_window);
- } else {
- g_assert_not_reached ();
- }
+ GtkWindow *parent_window)
+{
+ NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
+
+ if (op_type == NAUTILUS_FILE_UNDO_OP_MOVE ||
+ op_type == NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH)
+ {
+ ext_move_restore_redo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_COPY)
+ {
+ ext_copy_redo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE)
+ {
+ ext_duplicate_redo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_LINK)
+ {
+ ext_create_link_redo_func (self, parent_window);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
}
static void
ext_restore_undo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- nautilus_file_operations_trash_or_delete (g_queue_peek_head_link (self->priv->destinations),
- parent_window,
- file_undo_info_delete_callback,
- self);
+ nautilus_file_operations_trash_or_delete (g_queue_peek_head_link (self->priv->destinations),
+ parent_window,
+ file_undo_info_delete_callback,
+ self);
}
static void
ext_move_undo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- nautilus_file_operations_move (g_queue_peek_head_link (self->priv->destinations),
- NULL,
- self->priv->src_dir,
- parent_window,
- file_undo_info_transfer_callback,
- self);
+ nautilus_file_operations_move (g_queue_peek_head_link (self->priv->destinations),
+ NULL,
+ self->priv->src_dir,
+ parent_window,
+ file_undo_info_transfer_callback,
+ self);
}
static void
ext_copy_duplicate_undo_func (NautilusFileUndoInfoExt *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- GList *files;
+ GList *files;
- files = g_list_copy (g_queue_peek_head_link (self->priv->destinations));
- files = g_list_reverse (files); /* Deleting must be done in reverse */
+ files = g_list_copy (g_queue_peek_head_link (self->priv->destinations));
+ files = g_list_reverse (files); /* Deleting must be done in reverse */
- nautilus_file_operations_delete (files, parent_window,
- file_undo_info_delete_callback, self);
+ nautilus_file_operations_delete (files, parent_window,
+ file_undo_info_delete_callback, self);
- g_list_free (files);
+ g_list_free (files);
}
static void
ext_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
-{
- NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
-
- if (op_type == NAUTILUS_FILE_UNDO_OP_COPY ||
- op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE ||
- op_type == NAUTILUS_FILE_UNDO_OP_CREATE_LINK) {
- ext_copy_duplicate_undo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_MOVE) {
- ext_move_undo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH) {
- ext_restore_undo_func (self, parent_window);
- } else {
- g_assert_not_reached ();
- }
+ GtkWindow *parent_window)
+{
+ NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (info);
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
+
+ if (op_type == NAUTILUS_FILE_UNDO_OP_COPY ||
+ op_type == NAUTILUS_FILE_UNDO_OP_DUPLICATE ||
+ op_type == NAUTILUS_FILE_UNDO_OP_CREATE_LINK)
+ {
+ ext_copy_duplicate_undo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_MOVE)
+ {
+ ext_move_undo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_RESTORE_FROM_TRASH)
+ {
+ ext_restore_undo_func (self, parent_window);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
}
static void
nautilus_file_undo_info_ext_init (NautilusFileUndoInfoExt *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_ext_get_type (),
- NautilusFileUndoInfoExtDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_ext_get_type (),
+ NautilusFileUndoInfoExtDetails);
}
static void
nautilus_file_undo_info_ext_finalize (GObject *obj)
{
- NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (obj);
+ NautilusFileUndoInfoExt *self = NAUTILUS_FILE_UNDO_INFO_EXT (obj);
- if (self->priv->sources) {
- g_queue_free_full (self->priv->sources, g_object_unref);
- }
+ if (self->priv->sources)
+ {
+ g_queue_free_full (self->priv->sources, g_object_unref);
+ }
- if (self->priv->destinations) {
- g_queue_free_full (self->priv->destinations, g_object_unref);
- }
+ if (self->priv->destinations)
+ {
+ g_queue_free_full (self->priv->destinations, g_object_unref);
+ }
- g_clear_object (&self->priv->src_dir);
- g_clear_object (&self->priv->dest_dir);
+ g_clear_object (&self->priv->src_dir);
+ g_clear_object (&self->priv->dest_dir);
- G_OBJECT_CLASS (nautilus_file_undo_info_ext_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_ext_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_ext_class_init (NautilusFileUndoInfoExtClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_ext_finalize;
+ oclass->finalize = nautilus_file_undo_info_ext_finalize;
- iclass->undo_func = ext_undo_func;
- iclass->redo_func = ext_redo_func;
- iclass->strings_func = ext_strings_func;
+ iclass->undo_func = ext_undo_func;
+ iclass->redo_func = ext_redo_func;
+ iclass->strings_func = ext_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoExtDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoExtDetails));
}
NautilusFileUndoInfo *
-nautilus_file_undo_info_ext_new (NautilusFileUndoOp op_type,
- gint item_count,
- GFile *src_dir,
- GFile *target_dir)
+nautilus_file_undo_info_ext_new (NautilusFileUndoOp op_type,
+ gint item_count,
+ GFile *src_dir,
+ GFile *target_dir)
{
- NautilusFileUndoInfoExt *retval;
+ NautilusFileUndoInfoExt *retval;
- retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_EXT,
- "op-type", op_type,
- "item-count", item_count,
- NULL);
+ retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_EXT,
+ "op-type", op_type,
+ "item-count", item_count,
+ NULL);
- retval->priv->src_dir = g_object_ref (src_dir);
- retval->priv->dest_dir = g_object_ref (target_dir);
- retval->priv->sources = g_queue_new ();
- retval->priv->destinations = g_queue_new ();
+ retval->priv->src_dir = g_object_ref (src_dir);
+ retval->priv->dest_dir = g_object_ref (target_dir);
+ retval->priv->sources = g_queue_new ();
+ retval->priv->destinations = g_queue_new ();
- return NAUTILUS_FILE_UNDO_INFO (retval);
+ return NAUTILUS_FILE_UNDO_INFO (retval);
}
void
nautilus_file_undo_info_ext_add_origin_target_pair (NautilusFileUndoInfoExt *self,
- GFile *origin,
- GFile *target)
+ GFile *origin,
+ GFile *target)
{
- g_queue_push_tail (self->priv->sources, g_object_ref (origin));
- g_queue_push_tail (self->priv->destinations, g_object_ref (target));
+ g_queue_push_tail (self->priv->sources, g_object_ref (origin));
+ g_queue_push_tail (self->priv->destinations, g_object_ref (target));
}
/* create new file/folder */
G_DEFINE_TYPE (NautilusFileUndoInfoCreate, nautilus_file_undo_info_create, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoCreateDetails {
- char *template;
- GFile *target_file;
- gint length;
+struct _NautilusFileUndoInfoCreateDetails
+{
+ char *template;
+ GFile *target_file;
+ gint length;
};
static void
-create_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
-
+create_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (info);
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
- char *name;
+ NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (info);
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
+ char *name;
- name = g_file_get_parse_name (self->priv->target_file);
- *undo_description = g_strdup_printf (_("Delete '%s'"), name);
+ name = g_file_get_parse_name (self->priv->target_file);
+ *undo_description = g_strdup_printf (_("Delete '%s'"), name);
- if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE) {
- *redo_description = g_strdup_printf (_("Create an empty file '%s'"), name);
+ if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE)
+ {
+ *redo_description = g_strdup_printf (_("Create an empty file '%s'"), name);
- *undo_label = g_strdup (_("_Undo Create Empty File"));
- *redo_label = g_strdup (_("_Redo Create Empty File"));
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER) {
- *redo_description = g_strdup_printf (_("Create a new folder '%s'"), name);
+ *undo_label = g_strdup (_("_Undo Create Empty File"));
+ *redo_label = g_strdup (_("_Redo Create Empty File"));
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER)
+ {
+ *redo_description = g_strdup_printf (_("Create a new folder '%s'"), name);
- *undo_label = g_strdup (_("_Undo Create Folder"));
- *redo_label = g_strdup (_("_Redo Create Folder"));
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE) {
- *redo_description = g_strdup_printf (_("Create new file '%s' from template "), name);
+ *undo_label = g_strdup (_("_Undo Create Folder"));
+ *redo_label = g_strdup (_("_Redo Create Folder"));
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE)
+ {
+ *redo_description = g_strdup_printf (_("Create new file '%s' from template "), name);
- *undo_label = g_strdup (_("_Undo Create from Template"));
- *redo_label = g_strdup (_("_Redo Create from Template"));
- } else {
- g_assert_not_reached ();
- }
+ *undo_label = g_strdup (_("_Undo Create from Template"));
+ *redo_label = g_strdup (_("_Redo Create from Template"));
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
- g_free (name);
+ g_free (name);
}
static void
-create_callback (GFile * new_file,
- gboolean success,
- gpointer callback_data)
+create_callback (GFile *new_file,
+ gboolean success,
+ gpointer callback_data)
{
- file_undo_info_transfer_callback (NULL, success, callback_data);
+ file_undo_info_transfer_callback (NULL, success, callback_data);
}
static void
create_from_template_redo_func (NautilusFileUndoInfoCreate *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- GFile *parent;
- gchar *parent_uri, *new_name;
+ GFile *parent;
+ gchar *parent_uri, *new_name;
- parent = g_file_get_parent (self->priv->target_file);
- parent_uri = g_file_get_uri (parent);
- new_name = g_file_get_parse_name (self->priv->target_file);
- nautilus_file_operations_new_file_from_template (NULL, NULL,
- parent_uri, new_name,
- self->priv->template,
- create_callback, self);
+ parent = g_file_get_parent (self->priv->target_file);
+ parent_uri = g_file_get_uri (parent);
+ new_name = g_file_get_parse_name (self->priv->target_file);
+ nautilus_file_operations_new_file_from_template (NULL, NULL,
+ parent_uri, new_name,
+ self->priv->template,
+ create_callback, self);
- g_free (parent_uri);
- g_free (new_name);
- g_object_unref (parent);
+ g_free (parent_uri);
+ g_free (new_name);
+ g_object_unref (parent);
}
static void
create_folder_redo_func (NautilusFileUndoInfoCreate *self,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- GFile *parent;
- gchar *parent_uri;
- gchar *name;
+ GFile *parent;
+ gchar *parent_uri;
+ gchar *name;
- name = g_file_get_basename (self->priv->target_file);
- parent = g_file_get_parent (self->priv->target_file);
- parent_uri = g_file_get_uri (parent);
- nautilus_file_operations_new_folder (NULL, NULL, parent_uri, name,
- create_callback, self);
+ name = g_file_get_basename (self->priv->target_file);
+ parent = g_file_get_parent (self->priv->target_file);
+ parent_uri = g_file_get_uri (parent);
+ nautilus_file_operations_new_folder (NULL, NULL, parent_uri, name,
+ create_callback, self);
- g_free (name);
- g_free (parent_uri);
- g_object_unref (parent);
+ g_free (name);
+ g_free (parent_uri);
+ g_object_unref (parent);
}
static void
create_empty_redo_func (NautilusFileUndoInfoCreate *self,
- GtkWindow *parent_window)
-
+ GtkWindow *parent_window)
{
- GFile *parent;
- gchar *parent_uri;
- gchar *new_name;
+ GFile *parent;
+ gchar *parent_uri;
+ gchar *new_name;
- parent = g_file_get_parent (self->priv->target_file);
- parent_uri = g_file_get_uri (parent);
- new_name = g_file_get_parse_name (self->priv->target_file);
- nautilus_file_operations_new_file (NULL, NULL, parent_uri,
- new_name,
- self->priv->template,
- self->priv->length,
- create_callback, self);
+ parent = g_file_get_parent (self->priv->target_file);
+ parent_uri = g_file_get_uri (parent);
+ new_name = g_file_get_parse_name (self->priv->target_file);
+ nautilus_file_operations_new_file (NULL, NULL, parent_uri,
+ new_name,
+ self->priv->template,
+ self->priv->length,
+ create_callback, self);
- g_free (parent_uri);
- g_free (new_name);
- g_object_unref (parent);
+ g_free (parent_uri);
+ g_free (new_name);
+ g_object_unref (parent);
}
static void
create_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
-{
- NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (info);
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
-
- if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE) {
- create_empty_redo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER) {
- create_folder_redo_func (self, parent_window);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE) {
- create_from_template_redo_func (self, parent_window);
- } else {
- g_assert_not_reached ();
- }
+ GtkWindow *parent_window)
+{
+ NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (info);
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
+
+ if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_EMPTY_FILE)
+ {
+ create_empty_redo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FOLDER)
+ {
+ create_folder_redo_func (self, parent_window);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CREATE_FILE_FROM_TEMPLATE)
+ {
+ create_from_template_redo_func (self, parent_window);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
}
static void
create_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (info);
- GList *files = NULL;
+ NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (info);
+ GList *files = NULL;
- files = g_list_append (files, g_object_ref (self->priv->target_file));
- nautilus_file_operations_delete (files, parent_window,
- file_undo_info_delete_callback, self);
+ files = g_list_append (files, g_object_ref (self->priv->target_file));
+ nautilus_file_operations_delete (files, parent_window,
+ file_undo_info_delete_callback, self);
- g_list_free_full (files, g_object_unref);
+ g_list_free_full (files, g_object_unref);
}
static void
nautilus_file_undo_info_create_init (NautilusFileUndoInfoCreate *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_create_get_type (),
- NautilusFileUndoInfoCreateDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_create_get_type (),
+ NautilusFileUndoInfoCreateDetails);
}
static void
nautilus_file_undo_info_create_finalize (GObject *obj)
{
- NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (obj);
- g_clear_object (&self->priv->target_file);
- g_free (self->priv->template);
+ NautilusFileUndoInfoCreate *self = NAUTILUS_FILE_UNDO_INFO_CREATE (obj);
+ g_clear_object (&self->priv->target_file);
+ g_free (self->priv->template);
- G_OBJECT_CLASS (nautilus_file_undo_info_create_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_create_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_create_class_init (NautilusFileUndoInfoCreateClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_create_finalize;
+ oclass->finalize = nautilus_file_undo_info_create_finalize;
- iclass->undo_func = create_undo_func;
- iclass->redo_func = create_redo_func;
- iclass->strings_func = create_strings_func;
+ iclass->undo_func = create_undo_func;
+ iclass->redo_func = create_redo_func;
+ iclass->strings_func = create_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoCreateDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoCreateDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_create_new (NautilusFileUndoOp op_type)
{
- return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_CREATE,
- "op-type", op_type,
- "item-count", 1,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_CREATE,
+ "op-type", op_type,
+ "item-count", 1,
+ NULL);
}
void
nautilus_file_undo_info_create_set_data (NautilusFileUndoInfoCreate *self,
GFile *file,
const char *template,
- gint length)
+ gint length)
{
- self->priv->target_file = g_object_ref (file);
- self->priv->template = g_strdup (template);
- self->priv->length = length;
+ self->priv->target_file = g_object_ref (file);
+ self->priv->template = g_strdup (template);
+ self->priv->length = length;
}
/* rename */
G_DEFINE_TYPE (NautilusFileUndoInfoRename, nautilus_file_undo_info_rename, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoRenameDetails {
- GFile *old_file;
- GFile *new_file;
- gchar *old_display_name;
- gchar *new_display_name;
+struct _NautilusFileUndoInfoRenameDetails
+{
+ GFile *old_file;
+ GFile *new_file;
+ gchar *old_display_name;
+ gchar *new_display_name;
};
static void
-rename_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+rename_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (info);
- gchar *new_name, *old_name;
+ NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (info);
+ gchar *new_name, *old_name;
- new_name = g_file_get_parse_name (self->priv->new_file);
- old_name = g_file_get_parse_name (self->priv->old_file);
+ new_name = g_file_get_parse_name (self->priv->new_file);
+ old_name = g_file_get_parse_name (self->priv->old_file);
- *undo_description = g_strdup_printf (_("Rename '%s' as '%s'"), new_name, old_name);
- *redo_description = g_strdup_printf (_("Rename '%s' as '%s'"), old_name, new_name);
+ *undo_description = g_strdup_printf (_("Rename '%s' as '%s'"), new_name, old_name);
+ *redo_description = g_strdup_printf (_("Rename '%s' as '%s'"), old_name, new_name);
- *undo_label = g_strdup (_("_Undo Rename"));
- *redo_label = g_strdup (_("_Redo Rename"));
+ *undo_label = g_strdup (_("_Undo Rename"));
+ *redo_label = g_strdup (_("_Redo Rename"));
- g_free (old_name);
- g_free (new_name);
+ g_free (old_name);
+ g_free (new_name);
}
static void
rename_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (info);
- NautilusFile *file;
+ NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (info);
+ NautilusFile *file;
- file = nautilus_file_get (self->priv->old_file);
- nautilus_file_rename (file, self->priv->new_display_name,
- file_undo_info_operation_callback, self);
+ file = nautilus_file_get (self->priv->old_file);
+ nautilus_file_rename (file, self->priv->new_display_name,
+ file_undo_info_operation_callback, self);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
static void
rename_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (info);
- NautilusFile *file;
+ NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (info);
+ NautilusFile *file;
- file = nautilus_file_get (self->priv->new_file);
- nautilus_file_rename (file, self->priv->old_display_name,
- file_undo_info_operation_callback, self);
+ file = nautilus_file_get (self->priv->new_file);
+ nautilus_file_rename (file, self->priv->old_display_name,
+ file_undo_info_operation_callback, self);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
static void
nautilus_file_undo_info_rename_init (NautilusFileUndoInfoRename *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_rename_get_type (),
- NautilusFileUndoInfoRenameDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_rename_get_type (),
+ NautilusFileUndoInfoRenameDetails);
}
static void
nautilus_file_undo_info_rename_finalize (GObject *obj)
{
- NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (obj);
- g_clear_object (&self->priv->old_file);
- g_clear_object (&self->priv->new_file);
- g_free (self->priv->old_display_name);
- g_free (self->priv->new_display_name);
+ NautilusFileUndoInfoRename *self = NAUTILUS_FILE_UNDO_INFO_RENAME (obj);
+ g_clear_object (&self->priv->old_file);
+ g_clear_object (&self->priv->new_file);
+ g_free (self->priv->old_display_name);
+ g_free (self->priv->new_display_name);
- G_OBJECT_CLASS (nautilus_file_undo_info_rename_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_rename_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_rename_class_init (NautilusFileUndoInfoRenameClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_rename_finalize;
+ oclass->finalize = nautilus_file_undo_info_rename_finalize;
- iclass->undo_func = rename_undo_func;
- iclass->redo_func = rename_redo_func;
- iclass->strings_func = rename_strings_func;
+ iclass->undo_func = rename_undo_func;
+ iclass->redo_func = rename_redo_func;
+ iclass->strings_func = rename_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoRenameDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoRenameDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_rename_new (void)
{
- return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_RENAME,
- "op-type", NAUTILUS_FILE_UNDO_OP_RENAME,
- "item-count", 1,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_RENAME,
+ "op-type", NAUTILUS_FILE_UNDO_OP_RENAME,
+ "item-count", 1,
+ NULL);
}
void
nautilus_file_undo_info_rename_set_data_pre (NautilusFileUndoInfoRename *self,
- GFile *old_file,
- gchar *old_display_name,
- gchar *new_display_name)
+ GFile *old_file,
+ gchar *old_display_name,
+ gchar *new_display_name)
{
- self->priv->old_file = g_object_ref (old_file);
- self->priv->old_display_name = g_strdup (old_display_name);
- self->priv->new_display_name = g_strdup (new_display_name);
+ self->priv->old_file = g_object_ref (old_file);
+ self->priv->old_display_name = g_strdup (old_display_name);
+ self->priv->new_display_name = g_strdup (new_display_name);
}
void
nautilus_file_undo_info_rename_set_data_post (NautilusFileUndoInfoRename *self,
- GFile *new_file)
+ GFile *new_file)
{
- self->priv->new_file = g_object_ref (new_file);
+ self->priv->new_file = g_object_ref (new_file);
}
/* batch rename */
G_DEFINE_TYPE (NautilusFileUndoInfoBatchRename, nautilus_file_undo_info_batch_rename, NAUTILUS_TYPE_FILE_UNDO_INFO);
-struct _NautilusFileUndoInfoBatchRenameDetails {
- GList *old_files;
- GList *new_files;
- GList *old_display_names;
- GList *new_display_names;
+struct _NautilusFileUndoInfoBatchRenameDetails
+{
+ GList *old_files;
+ GList *new_files;
+ GList *old_display_names;
+ GList *new_display_names;
};
static void
-batch_rename_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+batch_rename_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (info);
+ NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (info);
- *undo_description = g_strdup_printf (_("Batch rename '%d' files"),
- g_list_length (self->priv->new_files));
- *redo_description = g_strdup_printf (_("Batch rename '%d' files"),
- g_list_length (self->priv->new_files));
+ *undo_description = g_strdup_printf (_("Batch rename '%d' files"),
+ g_list_length (self->priv->new_files));
+ *redo_description = g_strdup_printf (_("Batch rename '%d' files"),
+ g_list_length (self->priv->new_files));
- *undo_label = g_strdup (_("_Undo Batch rename"));
- *redo_label = g_strdup (_("_Redo Batch rename"));
+ *undo_label = g_strdup (_("_Undo Batch rename"));
+ *redo_label = g_strdup (_("_Redo Batch rename"));
}
static void
batch_rename_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
-{
- NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (info);
-
- GList *l, *files;
- NautilusFile *file;
- GFile *old_file;
- GFile *new_file;
- GList *l1;
- GList *l2;
- GList *l3;
- GList *l4;
- GList *l5;
- GList *l6;
- GList *l7;
- gchar *file_name;
- gchar *old_file_name;
- GString *new_file_name;
- GString *new_name;
- GString *old_name;
-
- files = NULL;
-
- for (l = self->priv->old_files; l != NULL; l = l->next) {
- old_file = l->data;
-
- file = nautilus_file_get (old_file);
- files = g_list_append (files, file);
+ GtkWindow *parent_window)
+{
+ NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (info);
+
+ GList *l, *files;
+ NautilusFile *file;
+ GFile *old_file;
+ GFile *new_file;
+ GList *l1;
+ GList *l2;
+ GList *l3;
+ GList *l4;
+ GList *l5;
+ GList *l6;
+ GList *l7;
+ gchar *file_name;
+ gchar *old_file_name;
+ GString *new_file_name;
+ GString *new_name;
+ GString *old_name;
+
+ files = NULL;
+
+ for (l = self->priv->old_files; l != NULL; l = l->next)
+ {
+ old_file = l->data;
+
+ file = nautilus_file_get (old_file);
+ files = g_list_append (files, file);
+ }
+
+ for (l1 = self->priv->new_display_names, l2 = files; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ old_file_name = nautilus_file_get_name (NAUTILUS_FILE (l2->data));
+ new_file_name = l1->data;
+
+ for (l3 = files, l4 = self->priv->new_display_names, l5 = self->priv->old_display_names, l6 = self->priv->old_files, l7 = self->priv->new_files;
+ l3 != NULL && l4 != NULL && l5 != NULL && l6 != NULL && l7 != NULL;
+ l3 = l3->next, l4 = l4->next, l5 = l5->next, l6 = l6->next, l7 = l7->next)
+ {
+ file_name = nautilus_file_get_name (NAUTILUS_FILE (l3->data));
+ if (l3 != l2 && g_strcmp0 (file_name, new_file_name->str) == 0)
+ {
+ file = NAUTILUS_FILE (l3->data);
+ new_name = l4->data;
+ old_name = l5->data;
+ old_file = l6->data;
+ new_file = l7->data;
+
+ files = g_list_remove_link (files, l3);
+ self->priv->new_display_names = g_list_remove_link (self->priv->new_display_names, l4);
+ self->priv->old_display_names = g_list_remove_link (self->priv->old_display_names, l5);
+ self->priv->old_files = g_list_remove_link (self->priv->old_files, l6);
+ self->priv->new_files = g_list_remove_link (self->priv->new_files, l7);
+
+ files = g_list_prepend (files, file);
+ self->priv->new_display_names = g_list_prepend (self->priv->new_display_names, new_name);
+ self->priv->old_display_names = g_list_prepend (self->priv->old_display_names, old_name);
+ self->priv->old_files = g_list_prepend (self->priv->old_files, old_file);
+ self->priv->new_files = g_list_prepend (self->priv->new_files, new_file);
+
+ g_free (file_name);
+
+ break;
+ }
+
+ g_free (file_name);
}
- for (l1 = self->priv->new_display_names, l2 = files; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- old_file_name = nautilus_file_get_name (NAUTILUS_FILE (l2->data));
- new_file_name = l1->data;
-
- for (l3 = files, l4 = self->priv->new_display_names, l5 = self->priv->old_display_names, l6 = self->priv->old_files, l7 = self->priv->new_files;
- l3 != NULL && l4 != NULL && l5 != NULL && l6 != NULL && l7 != NULL;
- l3 = l3->next, l4 = l4->next, l5 = l5->next, l6 = l6->next, l7 = l7->next) {
- file_name = nautilus_file_get_name (NAUTILUS_FILE (l3->data));
- if (l3 != l2 && g_strcmp0 (file_name, new_file_name->str) == 0) {
-
- file = NAUTILUS_FILE (l3->data);
- new_name = l4->data;
- old_name = l5->data;
- old_file = l6->data;
- new_file = l7->data;
-
- files = g_list_remove_link (files, l3);
- self->priv->new_display_names = g_list_remove_link (self->priv->new_display_names, l4);
- self->priv->old_display_names = g_list_remove_link (self->priv->old_display_names, l5);
- self->priv->old_files = g_list_remove_link (self->priv->old_files, l6);
- self->priv->new_files = g_list_remove_link (self->priv->new_files, l7);
-
- files = g_list_prepend (files, file);
- self->priv->new_display_names = g_list_prepend (self->priv->new_display_names, new_name);
- self->priv->old_display_names = g_list_prepend (self->priv->old_display_names, old_name);
- self->priv->old_files = g_list_prepend (self->priv->old_files, old_file);
- self->priv->new_files = g_list_prepend (self->priv->new_files, new_file);
-
- g_free (file_name);
-
- break;
- }
+ g_free (old_file_name);
+ }
- g_free (file_name);
- }
-
- g_free (old_file_name);
- }
-
- nautilus_file_batch_rename (files, self->priv->new_display_names, file_undo_info_operation_callback, self);
+ nautilus_file_batch_rename (files, self->priv->new_display_names, file_undo_info_operation_callback, self);
}
static void
batch_rename_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
-{
- NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (info);
-
- GList *l, *files;
- NautilusFile *file;
- GFile *new_file;
- GFile *old_file;
- GList *l1;
- GList *l2;
- GList *l3;
- GList *l4;
- GList *l5;
- GList *l6;
- GList *l7;
- gchar *file_name;
- gchar *old_file_name;
- GString *new_file_name;
- GString *new_name;
- GString *old_name;
-
- files = NULL;
-
- for (l = self->priv->new_files; l != NULL; l = l->next) {
- new_file = l->data;
-
- file = nautilus_file_get (new_file);
- files = g_list_append (files, file);
+ GtkWindow *parent_window)
+{
+ NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (info);
+
+ GList *l, *files;
+ NautilusFile *file;
+ GFile *new_file;
+ GFile *old_file;
+ GList *l1;
+ GList *l2;
+ GList *l3;
+ GList *l4;
+ GList *l5;
+ GList *l6;
+ GList *l7;
+ gchar *file_name;
+ gchar *old_file_name;
+ GString *new_file_name;
+ GString *new_name;
+ GString *old_name;
+
+ files = NULL;
+
+ for (l = self->priv->new_files; l != NULL; l = l->next)
+ {
+ new_file = l->data;
+
+ file = nautilus_file_get (new_file);
+ files = g_list_append (files, file);
+ }
+
+ for (l1 = self->priv->old_display_names, l2 = files; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ old_file_name = nautilus_file_get_name (NAUTILUS_FILE (l2->data));
+ new_file_name = l1->data;
+
+ for (l3 = files, l4 = self->priv->old_display_names, l5 = self->priv->new_display_names, l6 = self->priv->old_files, l7 = self->priv->new_files;
+ l3 != NULL && l4 != NULL && l5 != NULL && l6 != NULL && l7 != NULL;
+ l3 = l3->next, l4 = l4->next, l5 = l5->next, l6 = l6->next, l7 = l7->next)
+ {
+ file_name = nautilus_file_get_name (NAUTILUS_FILE (l3->data));
+ if (l3 != l2 && g_strcmp0 (file_name, new_file_name->str) == 0)
+ {
+ file = NAUTILUS_FILE (l3->data);
+ new_name = l4->data;
+ old_name = l5->data;
+ old_file = l6->data;
+ new_file = l7->data;
+
+ files = g_list_remove_link (files, l3);
+ self->priv->old_display_names = g_list_remove_link (self->priv->old_display_names, l4);
+ self->priv->new_display_names = g_list_remove_link (self->priv->new_display_names, l5);
+ self->priv->old_files = g_list_remove_link (self->priv->old_files, l6);
+ self->priv->new_files = g_list_remove_link (self->priv->new_files, l7);
+
+ files = g_list_prepend (files, file);
+ self->priv->old_display_names = g_list_prepend (self->priv->old_display_names, new_name);
+ self->priv->new_display_names = g_list_prepend (self->priv->new_display_names, old_name);
+ self->priv->old_files = g_list_prepend (self->priv->old_files, old_file);
+ self->priv->new_files = g_list_prepend (self->priv->new_files, new_file);
+
+ g_free (file_name);
+
+ break;
+ }
+
+ g_free (file_name);
}
- for (l1 = self->priv->old_display_names, l2 = files; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- old_file_name = nautilus_file_get_name (NAUTILUS_FILE (l2->data));
- new_file_name = l1->data;
-
- for (l3 = files, l4 = self->priv->old_display_names, l5 = self->priv->new_display_names, l6 = self->priv->old_files, l7 = self->priv->new_files;
- l3 != NULL && l4 != NULL && l5 != NULL && l6 != NULL && l7 != NULL;
- l3 = l3->next, l4 = l4->next, l5 = l5->next, l6 = l6->next, l7 = l7->next) {
- file_name = nautilus_file_get_name (NAUTILUS_FILE (l3->data));
- if (l3 != l2 && g_strcmp0 (file_name, new_file_name->str) == 0) {
- file = NAUTILUS_FILE (l3->data);
- new_name = l4->data;
- old_name = l5->data;
- old_file = l6->data;
- new_file = l7->data;
-
- files = g_list_remove_link (files, l3);
- self->priv->old_display_names = g_list_remove_link (self->priv->old_display_names, l4);
- self->priv->new_display_names = g_list_remove_link (self->priv->new_display_names, l5);
- self->priv->old_files = g_list_remove_link (self->priv->old_files, l6);
- self->priv->new_files = g_list_remove_link (self->priv->new_files, l7);
-
- files = g_list_prepend (files, file);
- self->priv->old_display_names = g_list_prepend (self->priv->old_display_names, new_name);
- self->priv->new_display_names = g_list_prepend (self->priv->new_display_names, old_name);
- self->priv->old_files = g_list_prepend (self->priv->old_files, old_file);
- self->priv->new_files = g_list_prepend (self->priv->new_files, new_file);
-
- g_free (file_name);
-
- break;
- }
-
- g_free (file_name);
- }
-
- g_free (old_file_name);
- }
+ g_free (old_file_name);
+ }
- nautilus_file_batch_rename (files, self->priv->old_display_names, file_undo_info_operation_callback, self);
+ nautilus_file_batch_rename (files, self->priv->old_display_names, file_undo_info_operation_callback, self);
}
static void
nautilus_file_undo_info_batch_rename_init (NautilusFileUndoInfoBatchRename *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_batch_rename_get_type (),
- NautilusFileUndoInfoBatchRenameDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_batch_rename_get_type (),
+ NautilusFileUndoInfoBatchRenameDetails);
}
static void
nautilus_file_undo_info_batch_rename_finalize (GObject *obj)
{
- GList *l;
- GFile *file;
- GString *string;
- NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (obj);
+ GList *l;
+ GFile *file;
+ GString *string;
+ NautilusFileUndoInfoBatchRename *self = NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (obj);
- for (l = self->priv->new_files; l != NULL; l = l->next){
- file = l->data;
+ for (l = self->priv->new_files; l != NULL; l = l->next)
+ {
+ file = l->data;
- g_clear_object (&file);
- }
+ g_clear_object (&file);
+ }
- for (l = self->priv->old_files; l != NULL; l = l->next){
- file = l->data;
+ for (l = self->priv->old_files; l != NULL; l = l->next)
+ {
+ file = l->data;
- g_clear_object (&file);
- }
+ g_clear_object (&file);
+ }
- for (l = self->priv->new_display_names; l != NULL; l = l->next) {
- string = l->data;
+ for (l = self->priv->new_display_names; l != NULL; l = l->next)
+ {
+ string = l->data;
- g_string_free (string, TRUE);
- }
+ g_string_free (string, TRUE);
+ }
- for (l = self->priv->old_display_names; l != NULL; l = l->next) {
- string = l->data;
+ for (l = self->priv->old_display_names; l != NULL; l = l->next)
+ {
+ string = l->data;
- g_string_free (string, TRUE);
- }
+ g_string_free (string, TRUE);
+ }
- g_list_free (self->priv->new_files);
- g_list_free (self->priv->old_files);
- g_list_free (self->priv->new_display_names);
- g_list_free (self->priv->old_display_names);
+ g_list_free (self->priv->new_files);
+ g_list_free (self->priv->old_files);
+ g_list_free (self->priv->new_display_names);
+ g_list_free (self->priv->old_display_names);
- G_OBJECT_CLASS (nautilus_file_undo_info_batch_rename_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_batch_rename_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_batch_rename_class_init (NautilusFileUndoInfoBatchRenameClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_batch_rename_finalize;
+ oclass->finalize = nautilus_file_undo_info_batch_rename_finalize;
- iclass->undo_func = batch_rename_undo_func;
- iclass->redo_func = batch_rename_redo_func;
- iclass->strings_func = batch_rename_strings_func;
+ iclass->undo_func = batch_rename_undo_func;
+ iclass->redo_func = batch_rename_redo_func;
+ iclass->strings_func = batch_rename_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoBatchRenameDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoBatchRenameDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_batch_rename_new (gint item_count)
{
- return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_BATCH_RENAME,
- "op-type", NAUTILUS_FILE_UNDO_OP_BATCH_RENAME,
- "item-count", item_count,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_BATCH_RENAME,
+ "op-type", NAUTILUS_FILE_UNDO_OP_BATCH_RENAME,
+ "item-count", item_count,
+ NULL);
}
void
nautilus_file_undo_info_batch_rename_set_data_pre (NautilusFileUndoInfoBatchRename *self,
GList *old_files)
{
- GList *l;
- GString *old_name;
- GFile *file;
+ GList *l;
+ GString *old_name;
+ GFile *file;
- self->priv->old_files = old_files;
- self->priv->old_display_names = NULL;
+ self->priv->old_files = old_files;
+ self->priv->old_display_names = NULL;
- for (l = old_files; l != NULL; l = l->next) {
- file = l->data;
+ for (l = old_files; l != NULL; l = l->next)
+ {
+ file = l->data;
- old_name = g_string_new (g_file_get_basename (file));
+ old_name = g_string_new (g_file_get_basename (file));
- self->priv->old_display_names = g_list_append (self->priv->old_display_names, old_name);
- }
+ self->priv->old_display_names = g_list_append (self->priv->old_display_names, old_name);
+ }
}
void
nautilus_file_undo_info_batch_rename_set_data_post (NautilusFileUndoInfoBatchRename *self,
GList *new_files)
{
- GList *l;
- GString *new_name;
- GFile *file;
+ GList *l;
+ GString *new_name;
+ GFile *file;
- self->priv->new_files = new_files;
- self->priv->new_display_names = NULL;
+ self->priv->new_files = new_files;
+ self->priv->new_display_names = NULL;
- for (l = new_files; l != NULL; l = l->next) {
- file = l->data;
+ for (l = new_files; l != NULL; l = l->next)
+ {
+ file = l->data;
- new_name = g_string_new (g_file_get_basename (file));
+ new_name = g_string_new (g_file_get_basename (file));
- self->priv->new_display_names = g_list_append (self->priv->new_display_names, new_name);
- }
+ self->priv->new_display_names = g_list_append (self->priv->new_display_names, new_name);
+ }
}
/* trash */
G_DEFINE_TYPE (NautilusFileUndoInfoTrash, nautilus_file_undo_info_trash, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoTrashDetails {
- GHashTable *trashed;
+struct _NautilusFileUndoInfoTrashDetails
+{
+ GHashTable *trashed;
};
static void
-trash_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
-{
- NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info);
- gint count = g_hash_table_size (self->priv->trashed);
-
- if (count != 1) {
- *undo_description = g_strdup_printf (ngettext ("Restore %d item from trash",
- "Restore %d items from trash", count),
- count);
- *redo_description = g_strdup_printf (ngettext ("Move %d item to trash",
- "Move %d items to trash", count),
- count);
- } else {
- GList *keys;
- char *name, *orig_path;
- GFile *file;
+trash_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
+{
+ NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info);
+ gint count = g_hash_table_size (self->priv->trashed);
+
+ if (count != 1)
+ {
+ *undo_description = g_strdup_printf (ngettext ("Restore %d item from trash",
+ "Restore %d items from trash", count),
+ count);
+ *redo_description = g_strdup_printf (ngettext ("Move %d item to trash",
+ "Move %d items to trash", count),
+ count);
+ }
+ else
+ {
+ GList *keys;
+ char *name, *orig_path;
+ GFile *file;
- keys = g_hash_table_get_keys (self->priv->trashed);
- file = keys->data;
- name = g_file_get_basename (file);
- orig_path = g_file_get_path (file);
- *undo_description = g_strdup_printf (_("Restore '%s' to '%s'"), name, orig_path);
+ keys = g_hash_table_get_keys (self->priv->trashed);
+ file = keys->data;
+ name = g_file_get_basename (file);
+ orig_path = g_file_get_path (file);
+ *undo_description = g_strdup_printf (_("Restore '%s' to '%s'"), name, orig_path);
- g_free (name);
- g_free (orig_path);
- g_list_free (keys);
+ g_free (name);
+ g_free (orig_path);
+ g_list_free (keys);
- name = g_file_get_parse_name (file);
- *redo_description = g_strdup_printf (_("Move '%s' to trash"), name);
+ name = g_file_get_parse_name (file);
+ *redo_description = g_strdup_printf (_("Move '%s' to trash"), name);
- g_free (name);
- }
+ g_free (name);
+ }
- *undo_label = g_strdup (_("_Undo Trash"));
- *redo_label = g_strdup (_("_Redo Trash"));
+ *undo_label = g_strdup (_("_Undo Trash"));
+ *redo_label = g_strdup (_("_Redo Trash"));
}
static void
trash_redo_func_callback (GHashTable *debuting_uris,
- gboolean user_cancel,
- gpointer user_data)
-{
- NautilusFileUndoInfoTrash *self = user_data;
- GHashTable *new_trashed_files;
- GTimeVal current_time;
- gsize updated_trash_time;
- GFile *file;
- GList *keys, *l;
-
- if (!user_cancel) {
- new_trashed_files =
- g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
- g_object_unref, NULL);
-
- keys = g_hash_table_get_keys (self->priv->trashed);
-
- g_get_current_time (&current_time);
- updated_trash_time = current_time.tv_sec;
-
- for (l = keys; l != NULL; l = l->next) {
- file = l->data;
- g_hash_table_insert (new_trashed_files,
- g_object_ref (file), GSIZE_TO_POINTER (updated_trash_time));
- }
+ gboolean user_cancel,
+ gpointer user_data)
+{
+ NautilusFileUndoInfoTrash *self = user_data;
+ GHashTable *new_trashed_files;
+ GTimeVal current_time;
+ gsize updated_trash_time;
+ GFile *file;
+ GList *keys, *l;
+
+ if (!user_cancel)
+ {
+ new_trashed_files =
+ g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
+ g_object_unref, NULL);
+
+ keys = g_hash_table_get_keys (self->priv->trashed);
+
+ g_get_current_time (&current_time);
+ updated_trash_time = current_time.tv_sec;
+
+ for (l = keys; l != NULL; l = l->next)
+ {
+ file = l->data;
+ g_hash_table_insert (new_trashed_files,
+ g_object_ref (file), GSIZE_TO_POINTER (updated_trash_time));
+ }
- g_list_free (keys);
- g_hash_table_destroy (self->priv->trashed);
+ g_list_free (keys);
+ g_hash_table_destroy (self->priv->trashed);
- self->priv->trashed = new_trashed_files;
- }
+ self->priv->trashed = new_trashed_files;
+ }
- file_undo_info_delete_callback (debuting_uris, user_cancel, user_data);
+ file_undo_info_delete_callback (debuting_uris, user_cancel, user_data);
}
static void
trash_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info);
+ NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info);
- if (g_hash_table_size (self->priv->trashed) > 0) {
- GList *locations;
+ if (g_hash_table_size (self->priv->trashed) > 0)
+ {
+ GList *locations;
- locations = g_hash_table_get_keys (self->priv->trashed);
- nautilus_file_operations_trash_or_delete (locations, parent_window,
- trash_redo_func_callback, self);
+ locations = g_hash_table_get_keys (self->priv->trashed);
+ nautilus_file_operations_trash_or_delete (locations, parent_window,
+ trash_redo_func_callback, self);
- g_list_free (locations);
- }
+ g_list_free (locations);
+ }
}
static void
-trash_retrieve_files_to_restore_thread (GTask *task,
- gpointer source_object,
- gpointer task_data,
+trash_retrieve_files_to_restore_thread (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
GCancellable *cancellable)
{
- NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (source_object);
- GFileEnumerator *enumerator;
- GHashTable *to_restore;
- GFile *trash;
- GError *error = NULL;
-
- to_restore = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
- g_object_unref, g_object_unref);
-
- trash = g_file_new_for_uri ("trash:///");
-
- enumerator = g_file_enumerate_children (trash,
- G_FILE_ATTRIBUTE_STANDARD_NAME","
- G_FILE_ATTRIBUTE_TRASH_DELETION_DATE","
- G_FILE_ATTRIBUTE_TRASH_ORIG_PATH,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, &error);
-
- if (enumerator) {
- GFileInfo *info;
- gpointer lookupvalue;
- GFile *item;
- glong trash_time, orig_trash_time;
- const char *origpath;
- GFile *origfile;
-
- while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL) {
- /* Retrieve the original file uri */
- origpath = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH);
- origfile = g_file_new_for_path (origpath);
-
- lookupvalue = g_hash_table_lookup (self->priv->trashed, origfile);
-
- if (lookupvalue) {
- GDateTime *date;
-
- orig_trash_time = GPOINTER_TO_SIZE (lookupvalue);
- trash_time = 0;
- date = g_file_info_get_deletion_date (info);
- if (date) {
- trash_time = g_date_time_to_unix (date);
- g_date_time_unref (date);
- }
-
- if (ABS (orig_trash_time - trash_time) <= TRASH_TIME_EPSILON) {
- /* File in the trash */
- item = g_file_get_child (trash, g_file_info_get_name (info));
- g_hash_table_insert (to_restore, item, g_object_ref (origfile));
- }
- }
-
- g_object_unref (origfile);
-
- }
- g_file_enumerator_close (enumerator, FALSE, NULL);
- g_object_unref (enumerator);
- }
- g_object_unref (trash);
-
- if (error != NULL) {
- g_task_return_error (task, error);
- g_hash_table_destroy (to_restore);
- } else {
- g_task_return_pointer (task, to_restore, NULL);
- }
+ NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (source_object);
+ GFileEnumerator *enumerator;
+ GHashTable *to_restore;
+ GFile *trash;
+ GError *error = NULL;
+
+ to_restore = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
+ g_object_unref, g_object_unref);
+
+ trash = g_file_new_for_uri ("trash:///");
+
+ enumerator = g_file_enumerate_children (trash,
+ G_FILE_ATTRIBUTE_STANDARD_NAME ","
+ G_FILE_ATTRIBUTE_TRASH_DELETION_DATE ","
+ G_FILE_ATTRIBUTE_TRASH_ORIG_PATH,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL, &error);
+
+ if (enumerator)
+ {
+ GFileInfo *info;
+ gpointer lookupvalue;
+ GFile *item;
+ glong trash_time, orig_trash_time;
+ const char *origpath;
+ GFile *origfile;
+
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL)
+ {
+ /* Retrieve the original file uri */
+ origpath = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_TRASH_ORIG_PATH);
+ origfile = g_file_new_for_path (origpath);
+
+ lookupvalue = g_hash_table_lookup (self->priv->trashed, origfile);
+
+ if (lookupvalue)
+ {
+ GDateTime *date;
+
+ orig_trash_time = GPOINTER_TO_SIZE (lookupvalue);
+ trash_time = 0;
+ date = g_file_info_get_deletion_date (info);
+ if (date)
+ {
+ trash_time = g_date_time_to_unix (date);
+ g_date_time_unref (date);
+ }
+
+ if (ABS (orig_trash_time - trash_time) <= TRASH_TIME_EPSILON)
+ {
+ /* File in the trash */
+ item = g_file_get_child (trash, g_file_info_get_name (info));
+ g_hash_table_insert (to_restore, item, g_object_ref (origfile));
+ }
+ }
+
+ g_object_unref (origfile);
+ }
+ g_file_enumerator_close (enumerator, FALSE, NULL);
+ g_object_unref (enumerator);
+ }
+ g_object_unref (trash);
+
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ g_hash_table_destroy (to_restore);
+ }
+ else
+ {
+ g_task_return_pointer (task, to_restore, NULL);
+ }
}
static void
trash_retrieve_files_to_restore_async (NautilusFileUndoInfoTrash *self,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GTask *task;
+ GTask *task;
- task = g_task_new (G_OBJECT (self), NULL, callback, user_data);
+ task = g_task_new (G_OBJECT (self), NULL, callback, user_data);
- g_task_run_in_thread (task, trash_retrieve_files_to_restore_thread);
+ g_task_run_in_thread (task, trash_retrieve_files_to_restore_thread);
- g_object_unref (task);
+ g_object_unref (task);
}
static void
-trash_retrieve_files_ready (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
+trash_retrieve_files_ready (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (source);
- GHashTable *files_to_restore;
- GError *error = NULL;
+ NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (source);
+ GHashTable *files_to_restore;
+ GError *error = NULL;
- files_to_restore = g_task_propagate_pointer (G_TASK (res), &error);
+ files_to_restore = g_task_propagate_pointer (G_TASK (res), &error);
- if (error == NULL && g_hash_table_size (files_to_restore) > 0) {
- GList *gfiles_in_trash, *l;
- GFile *item;
- GFile *dest;
+ if (error == NULL && g_hash_table_size (files_to_restore) > 0)
+ {
+ GList *gfiles_in_trash, *l;
+ GFile *item;
+ GFile *dest;
- gfiles_in_trash = g_hash_table_get_keys (files_to_restore);
+ gfiles_in_trash = g_hash_table_get_keys (files_to_restore);
- for (l = gfiles_in_trash; l != NULL; l = l->next) {
- item = l->data;
- dest = g_hash_table_lookup (files_to_restore, item);
+ for (l = gfiles_in_trash; l != NULL; l = l->next)
+ {
+ item = l->data;
+ dest = g_hash_table_lookup (files_to_restore, item);
- g_file_move (item, dest, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, NULL, NULL);
- }
+ g_file_move (item, dest, G_FILE_COPY_NOFOLLOW_SYMLINKS, NULL, NULL, NULL, NULL);
+ }
- g_list_free (gfiles_in_trash);
+ g_list_free (gfiles_in_trash);
- /* Here we must do what's necessary for the callback */
- file_undo_info_transfer_callback (NULL, (error == NULL), self);
- } else {
- file_undo_info_transfer_callback (NULL, FALSE, self);
- }
+ /* Here we must do what's necessary for the callback */
+ file_undo_info_transfer_callback (NULL, (error == NULL), self);
+ }
+ else
+ {
+ file_undo_info_transfer_callback (NULL, FALSE, self);
+ }
- if (files_to_restore != NULL) {
- g_hash_table_destroy (files_to_restore);
- }
+ if (files_to_restore != NULL)
+ {
+ g_hash_table_destroy (files_to_restore);
+ }
- g_clear_error (&error);
+ g_clear_error (&error);
}
static void
trash_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info);
+ NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (info);
- trash_retrieve_files_to_restore_async (self, trash_retrieve_files_ready, NULL);
+ trash_retrieve_files_to_restore_async (self, trash_retrieve_files_ready, NULL);
}
static void
nautilus_file_undo_info_trash_init (NautilusFileUndoInfoTrash *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_trash_get_type (),
- NautilusFileUndoInfoTrashDetails);
- self->priv->trashed =
- g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
- g_object_unref, NULL);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_trash_get_type (),
+ NautilusFileUndoInfoTrashDetails);
+ self->priv->trashed =
+ g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
+ g_object_unref, NULL);
}
static void
nautilus_file_undo_info_trash_finalize (GObject *obj)
{
- NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (obj);
- g_hash_table_destroy (self->priv->trashed);
+ NautilusFileUndoInfoTrash *self = NAUTILUS_FILE_UNDO_INFO_TRASH (obj);
+ g_hash_table_destroy (self->priv->trashed);
- G_OBJECT_CLASS (nautilus_file_undo_info_trash_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_trash_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_trash_class_init (NautilusFileUndoInfoTrashClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_trash_finalize;
+ oclass->finalize = nautilus_file_undo_info_trash_finalize;
- iclass->undo_func = trash_undo_func;
- iclass->redo_func = trash_redo_func;
- iclass->strings_func = trash_strings_func;
+ iclass->undo_func = trash_undo_func;
+ iclass->redo_func = trash_redo_func;
+ iclass->strings_func = trash_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoTrashDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoTrashDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_trash_new (gint item_count)
{
- return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_TRASH,
- "op-type", NAUTILUS_FILE_UNDO_OP_MOVE_TO_TRASH,
- "item-count", item_count,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_TRASH,
+ "op-type", NAUTILUS_FILE_UNDO_OP_MOVE_TO_TRASH,
+ "item-count", item_count,
+ NULL);
}
void
nautilus_file_undo_info_trash_add_file (NautilusFileUndoInfoTrash *self,
- GFile *file)
+ GFile *file)
{
- GTimeVal current_time;
- gsize orig_trash_time;
+ GTimeVal current_time;
+ gsize orig_trash_time;
- g_get_current_time (&current_time);
- orig_trash_time = current_time.tv_sec;
+ g_get_current_time (&current_time);
+ orig_trash_time = current_time.tv_sec;
- g_hash_table_insert (self->priv->trashed, g_object_ref (file), GSIZE_TO_POINTER (orig_trash_time));
+ g_hash_table_insert (self->priv->trashed, g_object_ref (file), GSIZE_TO_POINTER (orig_trash_time));
}
GList *
nautilus_file_undo_info_trash_get_files (NautilusFileUndoInfoTrash *self)
{
- return g_hash_table_get_keys (self->priv->trashed);
+ return g_hash_table_get_keys (self->priv->trashed);
}
/* recursive permissions */
G_DEFINE_TYPE (NautilusFileUndoInfoRecPermissions, nautilus_file_undo_info_rec_permissions, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoRecPermissionsDetails {
- GFile *dest_dir;
- GHashTable *original_permissions;
- guint32 dir_mask;
- guint32 dir_permissions;
- guint32 file_mask;
- guint32 file_permissions;
+struct _NautilusFileUndoInfoRecPermissionsDetails
+{
+ GFile *dest_dir;
+ GHashTable *original_permissions;
+ guint32 dir_mask;
+ guint32 dir_permissions;
+ guint32 file_mask;
+ guint32 file_permissions;
};
static void
-rec_permissions_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+rec_permissions_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info);
- char *name;
+ NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info);
+ char *name;
- name = g_file_get_path (self->priv->dest_dir);
+ name = g_file_get_path (self->priv->dest_dir);
- *undo_description = g_strdup_printf (_("Restore original permissions of items enclosed in '%s'"), name);
- *redo_description = g_strdup_printf (_("Set permissions of items enclosed in '%s'"), name);
+ *undo_description = g_strdup_printf (_("Restore original permissions of items enclosed in '%s'"), name);
+ *redo_description = g_strdup_printf (_("Set permissions of items enclosed in '%s'"), name);
- *undo_label = g_strdup (_("_Undo Change Permissions"));
- *redo_label = g_strdup (_("_Redo Change Permissions"));
+ *undo_label = g_strdup (_("_Undo Change Permissions"));
+ *redo_label = g_strdup (_("_Redo Change Permissions"));
- g_free (name);
+ g_free (name);
}
static void
rec_permissions_callback (gboolean success,
- gpointer callback_data)
+ gpointer callback_data)
{
- file_undo_info_transfer_callback (NULL, success, callback_data);
+ file_undo_info_transfer_callback (NULL, success, callback_data);
}
static void
rec_permissions_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info);
- gchar *parent_uri;
+ NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info);
+ gchar *parent_uri;
- parent_uri = g_file_get_uri (self->priv->dest_dir);
- nautilus_file_set_permissions_recursive (parent_uri,
- self->priv->file_permissions,
- self->priv->file_mask,
- self->priv->dir_permissions,
- self->priv->dir_mask,
- rec_permissions_callback, self);
- g_free (parent_uri);
+ parent_uri = g_file_get_uri (self->priv->dest_dir);
+ nautilus_file_set_permissions_recursive (parent_uri,
+ self->priv->file_permissions,
+ self->priv->file_mask,
+ self->priv->dir_permissions,
+ self->priv->dir_mask,
+ rec_permissions_callback, self);
+ g_free (parent_uri);
}
static void
rec_permissions_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info);
+ NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (info);
- if (g_hash_table_size (self->priv->original_permissions) > 0) {
- GList *gfiles_list;
- guint32 perm;
- GList *l;
- GFile *dest;
- char *item;
-
- gfiles_list = g_hash_table_get_keys (self->priv->original_permissions);
- for (l = gfiles_list; l != NULL; l = l->next) {
- item = l->data;
- perm = GPOINTER_TO_UINT (g_hash_table_lookup (self->priv->original_permissions, item));
- dest = g_file_new_for_uri (item);
- g_file_set_attribute_uint32 (dest,
- G_FILE_ATTRIBUTE_UNIX_MODE,
- perm, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
- g_object_unref (dest);
- }
+ if (g_hash_table_size (self->priv->original_permissions) > 0)
+ {
+ GList *gfiles_list;
+ guint32 perm;
+ GList *l;
+ GFile *dest;
+ char *item;
+
+ gfiles_list = g_hash_table_get_keys (self->priv->original_permissions);
+ for (l = gfiles_list; l != NULL; l = l->next)
+ {
+ item = l->data;
+ perm = GPOINTER_TO_UINT (g_hash_table_lookup (self->priv->original_permissions, item));
+ dest = g_file_new_for_uri (item);
+ g_file_set_attribute_uint32 (dest,
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ perm, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, NULL);
+ g_object_unref (dest);
+ }
- g_list_free (gfiles_list);
- /* Here we must do what's necessary for the callback */
- file_undo_info_transfer_callback (NULL, TRUE, self);
- }
+ g_list_free (gfiles_list);
+ /* Here we must do what's necessary for the callback */
+ file_undo_info_transfer_callback (NULL, TRUE, self);
+ }
}
static void
nautilus_file_undo_info_rec_permissions_init (NautilusFileUndoInfoRecPermissions *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_rec_permissions_get_type (),
- NautilusFileUndoInfoRecPermissionsDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_rec_permissions_get_type (),
+ NautilusFileUndoInfoRecPermissionsDetails);
- self->priv->original_permissions =
- g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ self->priv->original_permissions =
+ g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
}
static void
nautilus_file_undo_info_rec_permissions_finalize (GObject *obj)
{
- NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (obj);
+ NautilusFileUndoInfoRecPermissions *self = NAUTILUS_FILE_UNDO_INFO_REC_PERMISSIONS (obj);
- g_hash_table_destroy (self->priv->original_permissions);
- g_clear_object (&self->priv->dest_dir);
+ g_hash_table_destroy (self->priv->original_permissions);
+ g_clear_object (&self->priv->dest_dir);
- G_OBJECT_CLASS (nautilus_file_undo_info_rec_permissions_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_rec_permissions_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_rec_permissions_class_init (NautilusFileUndoInfoRecPermissionsClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_rec_permissions_finalize;
+ oclass->finalize = nautilus_file_undo_info_rec_permissions_finalize;
- iclass->undo_func = rec_permissions_undo_func;
- iclass->redo_func = rec_permissions_redo_func;
- iclass->strings_func = rec_permissions_strings_func;
+ iclass->undo_func = rec_permissions_undo_func;
+ iclass->redo_func = rec_permissions_redo_func;
+ iclass->strings_func = rec_permissions_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoRecPermissionsDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoRecPermissionsDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_rec_permissions_new (GFile *dest,
- guint32 file_permissions,
- guint32 file_mask,
- guint32 dir_permissions,
- guint32 dir_mask)
+ guint32 file_permissions,
+ guint32 file_mask,
+ guint32 dir_permissions,
+ guint32 dir_mask)
{
- NautilusFileUndoInfoRecPermissions *retval;
+ NautilusFileUndoInfoRecPermissions *retval;
- retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_REC_PERMISSIONS,
- "op-type", NAUTILUS_FILE_UNDO_OP_RECURSIVE_SET_PERMISSIONS,
- "item-count", 1,
- NULL);
+ retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_REC_PERMISSIONS,
+ "op-type", NAUTILUS_FILE_UNDO_OP_RECURSIVE_SET_PERMISSIONS,
+ "item-count", 1,
+ NULL);
- retval->priv->dest_dir = g_object_ref (dest);
- retval->priv->file_permissions = file_permissions;
- retval->priv->file_mask = file_mask;
- retval->priv->dir_permissions = dir_permissions;
- retval->priv->dir_mask = dir_mask;
+ retval->priv->dest_dir = g_object_ref (dest);
+ retval->priv->file_permissions = file_permissions;
+ retval->priv->file_mask = file_mask;
+ retval->priv->dir_permissions = dir_permissions;
+ retval->priv->dir_mask = dir_mask;
- return NAUTILUS_FILE_UNDO_INFO (retval);
+ return NAUTILUS_FILE_UNDO_INFO (retval);
}
void
nautilus_file_undo_info_rec_permissions_add_file (NautilusFileUndoInfoRecPermissions *self,
- GFile *file,
- guint32 permission)
+ GFile *file,
+ guint32 permission)
{
- gchar *original_uri = g_file_get_uri (file);
- g_hash_table_insert (self->priv->original_permissions, original_uri, GUINT_TO_POINTER (permission));
+ gchar *original_uri = g_file_get_uri (file);
+ g_hash_table_insert (self->priv->original_permissions, original_uri, GUINT_TO_POINTER (permission));
}
/* single file change permissions */
G_DEFINE_TYPE (NautilusFileUndoInfoPermissions, nautilus_file_undo_info_permissions, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoPermissionsDetails {
- GFile *target_file;
- guint32 current_permissions;
- guint32 new_permissions;
+struct _NautilusFileUndoInfoPermissionsDetails
+{
+ GFile *target_file;
+ guint32 current_permissions;
+ guint32 new_permissions;
};
static void
-permissions_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+permissions_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (info);
- gchar *name;
+ NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (info);
+ gchar *name;
- name = g_file_get_parse_name (self->priv->target_file);
- *undo_description = g_strdup_printf (_("Restore original permissions of '%s'"), name);
- *redo_description = g_strdup_printf (_("Set permissions of '%s'"), name);
+ name = g_file_get_parse_name (self->priv->target_file);
+ *undo_description = g_strdup_printf (_("Restore original permissions of '%s'"), name);
+ *redo_description = g_strdup_printf (_("Set permissions of '%s'"), name);
- *undo_label = g_strdup (_("_Undo Change Permissions"));
- *redo_label = g_strdup (_("_Redo Change Permissions"));
+ *undo_label = g_strdup (_("_Undo Change Permissions"));
+ *redo_label = g_strdup (_("_Redo Change Permissions"));
- g_free (name);
+ g_free (name);
}
static void
permissions_real_func (NautilusFileUndoInfoPermissions *self,
- guint32 permissions)
+ guint32 permissions)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_file_get (self->priv->target_file);
- nautilus_file_set_permissions (file, permissions,
- file_undo_info_operation_callback, self);
+ file = nautilus_file_get (self->priv->target_file);
+ nautilus_file_set_permissions (file, permissions,
+ file_undo_info_operation_callback, self);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
static void
-permissions_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+permissions_redo_func (NautilusFileUndoInfo *info,
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (info);
- permissions_real_func (self, self->priv->new_permissions);
+ NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (info);
+ permissions_real_func (self, self->priv->new_permissions);
}
static void
-permissions_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+permissions_undo_func (NautilusFileUndoInfo *info,
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (info);
- permissions_real_func (self, self->priv->current_permissions);
+ NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (info);
+ permissions_real_func (self, self->priv->current_permissions);
}
static void
nautilus_file_undo_info_permissions_init (NautilusFileUndoInfoPermissions *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_permissions_get_type (),
- NautilusFileUndoInfoPermissionsDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_permissions_get_type (),
+ NautilusFileUndoInfoPermissionsDetails);
}
static void
nautilus_file_undo_info_permissions_finalize (GObject *obj)
{
- NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (obj);
- g_clear_object (&self->priv->target_file);
+ NautilusFileUndoInfoPermissions *self = NAUTILUS_FILE_UNDO_INFO_PERMISSIONS (obj);
+ g_clear_object (&self->priv->target_file);
- G_OBJECT_CLASS (nautilus_file_undo_info_permissions_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_permissions_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_permissions_class_init (NautilusFileUndoInfoPermissionsClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_permissions_finalize;
+ oclass->finalize = nautilus_file_undo_info_permissions_finalize;
- iclass->undo_func = permissions_undo_func;
- iclass->redo_func = permissions_redo_func;
- iclass->strings_func = permissions_strings_func;
+ iclass->undo_func = permissions_undo_func;
+ iclass->redo_func = permissions_redo_func;
+ iclass->strings_func = permissions_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoPermissionsDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoPermissionsDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_permissions_new (GFile *file,
- guint32 current_permissions,
- guint32 new_permissions)
+ guint32 current_permissions,
+ guint32 new_permissions)
{
- NautilusFileUndoInfoPermissions *retval;
+ NautilusFileUndoInfoPermissions *retval;
- retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_PERMISSIONS,
- "op-type", NAUTILUS_FILE_UNDO_OP_SET_PERMISSIONS,
- "item-count", 1,
- NULL);
+ retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_PERMISSIONS,
+ "op-type", NAUTILUS_FILE_UNDO_OP_SET_PERMISSIONS,
+ "item-count", 1,
+ NULL);
- retval->priv->target_file = g_object_ref (file);
- retval->priv->current_permissions = current_permissions;
- retval->priv->new_permissions = new_permissions;
+ retval->priv->target_file = g_object_ref (file);
+ retval->priv->current_permissions = current_permissions;
+ retval->priv->new_permissions = new_permissions;
- return NAUTILUS_FILE_UNDO_INFO (retval);
+ return NAUTILUS_FILE_UNDO_INFO (retval);
}
/* group and owner change */
G_DEFINE_TYPE (NautilusFileUndoInfoOwnership, nautilus_file_undo_info_ownership, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoOwnershipDetails {
- GFile *target_file;
- char *original_ownership;
- char *new_ownership;
+struct _NautilusFileUndoInfoOwnershipDetails
+{
+ GFile *target_file;
+ char *original_ownership;
+ char *new_ownership;
};
static void
-ownership_strings_func (NautilusFileUndoInfo *info,
- gchar **undo_label,
- gchar **undo_description,
- gchar **redo_label,
- gchar **redo_description)
+ownership_strings_func (NautilusFileUndoInfo *info,
+ gchar **undo_label,
+ gchar **undo_description,
+ gchar **redo_label,
+ gchar **redo_description)
{
- NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (info);
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
- gchar *name;
+ NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (info);
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (info);
+ gchar *name;
- name = g_file_get_parse_name (self->priv->target_file);
+ name = g_file_get_parse_name (self->priv->target_file);
- if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_OWNER) {
- *undo_description = g_strdup_printf (_("Restore group of '%s' to '%s'"),
- name, self->priv->original_ownership);
- *redo_description = g_strdup_printf (_("Set group of '%s' to '%s'"),
- name, self->priv->new_ownership);
+ if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_OWNER)
+ {
+ *undo_description = g_strdup_printf (_("Restore group of '%s' to '%s'"),
+ name, self->priv->original_ownership);
+ *redo_description = g_strdup_printf (_("Set group of '%s' to '%s'"),
+ name, self->priv->new_ownership);
- *undo_label = g_strdup (_("_Undo Change Group"));
- *redo_label = g_strdup (_("_Redo Change Group"));
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_GROUP) {
- *undo_description = g_strdup_printf (_("Restore owner of '%s' to '%s'"),
- name, self->priv->original_ownership);
- *redo_description = g_strdup_printf (_("Set owner of '%s' to '%s'"),
- name, self->priv->new_ownership);
+ *undo_label = g_strdup (_("_Undo Change Group"));
+ *redo_label = g_strdup (_("_Redo Change Group"));
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_GROUP)
+ {
+ *undo_description = g_strdup_printf (_("Restore owner of '%s' to '%s'"),
+ name, self->priv->original_ownership);
+ *redo_description = g_strdup_printf (_("Set owner of '%s' to '%s'"),
+ name, self->priv->new_ownership);
- *undo_label = g_strdup (_("_Undo Change Owner"));
- *redo_label = g_strdup (_("_Redo Change Owner"));
- }
+ *undo_label = g_strdup (_("_Undo Change Owner"));
+ *redo_label = g_strdup (_("_Redo Change Owner"));
+ }
- g_free (name);
+ g_free (name);
}
static void
ownership_real_func (NautilusFileUndoInfoOwnership *self,
- const gchar *ownership)
+ const gchar *ownership)
{
- NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (NAUTILUS_FILE_UNDO_INFO (self));
- NautilusFile *file;
+ NautilusFileUndoOp op_type = nautilus_file_undo_info_get_op_type (NAUTILUS_FILE_UNDO_INFO (self));
+ NautilusFile *file;
- file = nautilus_file_get (self->priv->target_file);
+ file = nautilus_file_get (self->priv->target_file);
- if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_OWNER) {
- nautilus_file_set_owner (file,
- ownership,
- file_undo_info_operation_callback, self);
- } else if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_GROUP) {
- nautilus_file_set_group (file,
- ownership,
- file_undo_info_operation_callback, self);
- }
+ if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_OWNER)
+ {
+ nautilus_file_set_owner (file,
+ ownership,
+ file_undo_info_operation_callback, self);
+ }
+ else if (op_type == NAUTILUS_FILE_UNDO_OP_CHANGE_GROUP)
+ {
+ nautilus_file_set_group (file,
+ ownership,
+ file_undo_info_operation_callback, self);
+ }
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
static void
ownership_redo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (info);
- ownership_real_func (self, self->priv->new_ownership);
+ NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (info);
+ ownership_real_func (self, self->priv->new_ownership);
}
static void
ownership_undo_func (NautilusFileUndoInfo *info,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (info);
- ownership_real_func (self, self->priv->original_ownership);
+ NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (info);
+ ownership_real_func (self, self->priv->original_ownership);
}
static void
nautilus_file_undo_info_ownership_init (NautilusFileUndoInfoOwnership *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_ownership_get_type (),
- NautilusFileUndoInfoOwnershipDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_ownership_get_type (),
+ NautilusFileUndoInfoOwnershipDetails);
}
static void
nautilus_file_undo_info_ownership_finalize (GObject *obj)
{
- NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (obj);
+ NautilusFileUndoInfoOwnership *self = NAUTILUS_FILE_UNDO_INFO_OWNERSHIP (obj);
- g_clear_object (&self->priv->target_file);
- g_free (self->priv->original_ownership);
- g_free (self->priv->new_ownership);
+ g_clear_object (&self->priv->target_file);
+ g_free (self->priv->original_ownership);
+ g_free (self->priv->new_ownership);
- G_OBJECT_CLASS (nautilus_file_undo_info_ownership_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_ownership_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_ownership_class_init (NautilusFileUndoInfoOwnershipClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_ownership_finalize;
+ oclass->finalize = nautilus_file_undo_info_ownership_finalize;
- iclass->undo_func = ownership_undo_func;
- iclass->redo_func = ownership_redo_func;
- iclass->strings_func = ownership_strings_func;
+ iclass->undo_func = ownership_undo_func;
+ iclass->redo_func = ownership_redo_func;
+ iclass->strings_func = ownership_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoOwnershipDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoOwnershipDetails));
}
NautilusFileUndoInfo *
nautilus_file_undo_info_ownership_new (NautilusFileUndoOp op_type,
- GFile *file,
- const char *current_data,
- const char *new_data)
+ GFile *file,
+ const char *current_data,
+ const char *new_data)
{
- NautilusFileUndoInfoOwnership *retval;
+ NautilusFileUndoInfoOwnership *retval;
- retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_OWNERSHIP,
- "item-count", 1,
- "op-type", op_type,
- NULL);
+ retval = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_OWNERSHIP,
+ "item-count", 1,
+ "op-type", op_type,
+ NULL);
- retval->priv->target_file = g_object_ref (file);
- retval->priv->original_ownership = g_strdup (current_data);
- retval->priv->new_ownership = g_strdup (new_data);
+ retval->priv->target_file = g_object_ref (file);
+ retval->priv->original_ownership = g_strdup (current_data);
+ retval->priv->new_ownership = g_strdup (new_data);
- return NAUTILUS_FILE_UNDO_INFO (retval);
+ return NAUTILUS_FILE_UNDO_INFO (retval);
}
/* extract */
G_DEFINE_TYPE (NautilusFileUndoInfoExtract, nautilus_file_undo_info_extract, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoExtractDetails {
- GList *sources;
- GFile *destination_directory;
- GList *outputs;
+struct _NautilusFileUndoInfoExtractDetails
+{
+ GList *sources;
+ GFile *destination_directory;
+ GList *outputs;
};
static void
extract_callback (GList *outputs,
gpointer callback_data)
{
- NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (callback_data);
- gboolean success;
+ NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (callback_data);
+ gboolean success;
- nautilus_file_undo_info_extract_set_outputs (self, outputs);
+ nautilus_file_undo_info_extract_set_outputs (self, outputs);
- success = self->priv->outputs != NULL;
+ success = self->priv->outputs != NULL;
- file_undo_info_transfer_callback (NULL, success, self);
+ file_undo_info_transfer_callback (NULL, success, self);
}
static void
@@ -2009,146 +2143,155 @@ extract_strings_func (NautilusFileUndoInfo *info,
gchar **redo_label,
gchar **redo_description)
{
- NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
- gint total_sources;
- gint total_outputs;
+ NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
+ gint total_sources;
+ gint total_outputs;
- *undo_label = g_strdup (_("_Undo Extract"));
- *redo_label = g_strdup (_("_Redo Extract"));
+ *undo_label = g_strdup (_("_Undo Extract"));
+ *redo_label = g_strdup (_("_Redo Extract"));
- total_sources = g_list_length (self->priv->sources);
- total_outputs = g_list_length (self->priv->outputs);
+ total_sources = g_list_length (self->priv->sources);
+ total_outputs = g_list_length (self->priv->outputs);
- if (total_outputs == 1) {
- GFile *output;
- g_autofree gchar *name;
+ if (total_outputs == 1)
+ {
+ GFile *output;
+ g_autofree gchar *name;
- output = self->priv->outputs->data;
- name = g_file_get_parse_name (output);
+ output = self->priv->outputs->data;
+ name = g_file_get_parse_name (output);
- *undo_description = g_strdup_printf (_("Delete '%s'"), name);
- } else {
- *undo_description = g_strdup_printf (ngettext ("Delete %d extracted file",
- "Delete %d extracted files",
- total_outputs),
- total_outputs);
- }
+ *undo_description = g_strdup_printf (_("Delete '%s'"), name);
+ }
+ else
+ {
+ *undo_description = g_strdup_printf (ngettext ("Delete %d extracted file",
+ "Delete %d extracted files",
+ total_outputs),
+ total_outputs);
+ }
- if (total_sources == 1) {
- GFile *source;
- g_autofree gchar *name;
+ if (total_sources == 1)
+ {
+ GFile *source;
+ g_autofree gchar *name;
- source = self->priv->sources->data;
- name = g_file_get_parse_name (source);
+ source = self->priv->sources->data;
+ name = g_file_get_parse_name (source);
- *redo_description = g_strdup_printf (_("Extract '%s'"), name);
- } else {
- *redo_description = g_strdup_printf (ngettext ("Extract %d file",
- "Extract %d files",
- total_sources),
- total_sources);
- }
+ *redo_description = g_strdup_printf (_("Extract '%s'"), name);
+ }
+ else
+ {
+ *redo_description = g_strdup_printf (ngettext ("Extract %d file",
+ "Extract %d files",
+ total_sources),
+ total_sources);
+ }
}
static void
extract_redo_func (NautilusFileUndoInfo *info,
GtkWindow *parent_window)
{
- NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
+ NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
- nautilus_file_operations_extract_files (self->priv->sources,
- self->priv->destination_directory,
- parent_window,
- extract_callback,
- self);
+ nautilus_file_operations_extract_files (self->priv->sources,
+ self->priv->destination_directory,
+ parent_window,
+ extract_callback,
+ self);
}
static void
extract_undo_func (NautilusFileUndoInfo *info,
GtkWindow *parent_window)
{
- NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
+ NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (info);
- nautilus_file_operations_delete (self->priv->outputs, parent_window,
- file_undo_info_delete_callback, self);
+ nautilus_file_operations_delete (self->priv->outputs, parent_window,
+ file_undo_info_delete_callback, self);
}
static void
nautilus_file_undo_info_extract_init (NautilusFileUndoInfoExtract *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_extract_get_type (),
- NautilusFileUndoInfoExtractDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_extract_get_type (),
+ NautilusFileUndoInfoExtractDetails);
}
static void
nautilus_file_undo_info_extract_finalize (GObject *obj)
{
- NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (obj);
+ NautilusFileUndoInfoExtract *self = NAUTILUS_FILE_UNDO_INFO_EXTRACT (obj);
- g_object_unref (self->priv->destination_directory);
- g_list_free_full (self->priv->sources, g_object_unref);
- if (self->priv->outputs) {
- g_list_free_full (self->priv->outputs, g_object_unref);
- }
+ g_object_unref (self->priv->destination_directory);
+ g_list_free_full (self->priv->sources, g_object_unref);
+ if (self->priv->outputs)
+ {
+ g_list_free_full (self->priv->outputs, g_object_unref);
+ }
- G_OBJECT_CLASS (nautilus_file_undo_info_extract_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_extract_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_extract_class_init (NautilusFileUndoInfoExtractClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_extract_finalize;
+ oclass->finalize = nautilus_file_undo_info_extract_finalize;
- iclass->undo_func = extract_undo_func;
- iclass->redo_func = extract_redo_func;
- iclass->strings_func = extract_strings_func;
+ iclass->undo_func = extract_undo_func;
+ iclass->redo_func = extract_redo_func;
+ iclass->strings_func = extract_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoExtractDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoExtractDetails));
}
void
nautilus_file_undo_info_extract_set_outputs (NautilusFileUndoInfoExtract *self,
GList *outputs)
{
- if (self->priv->outputs) {
- g_list_free_full (self->priv->outputs, g_object_unref);
- }
- self->priv->outputs = g_list_copy_deep (outputs,
- (GCopyFunc)g_object_ref,
- NULL);
+ if (self->priv->outputs)
+ {
+ g_list_free_full (self->priv->outputs, g_object_unref);
+ }
+ self->priv->outputs = g_list_copy_deep (outputs,
+ (GCopyFunc) g_object_ref,
+ NULL);
}
NautilusFileUndoInfo *
nautilus_file_undo_info_extract_new (GList *sources,
GFile *destination_directory)
{
- NautilusFileUndoInfoExtract *self;
+ NautilusFileUndoInfoExtract *self;
- self = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_EXTRACT,
- "item-count", 1,
- "op-type", NAUTILUS_FILE_UNDO_OP_EXTRACT,
- NULL);
+ self = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_EXTRACT,
+ "item-count", 1,
+ "op-type", NAUTILUS_FILE_UNDO_OP_EXTRACT,
+ NULL);
- self->priv->sources = g_list_copy_deep (sources,
- (GCopyFunc)g_object_ref,
- NULL);
- self->priv->destination_directory = g_object_ref (destination_directory);
+ self->priv->sources = g_list_copy_deep (sources,
+ (GCopyFunc) g_object_ref,
+ NULL);
+ self->priv->destination_directory = g_object_ref (destination_directory);
- return NAUTILUS_FILE_UNDO_INFO (self);
+ return NAUTILUS_FILE_UNDO_INFO (self);
}
/* compress */
G_DEFINE_TYPE (NautilusFileUndoInfoCompress, nautilus_file_undo_info_compress, NAUTILUS_TYPE_FILE_UNDO_INFO)
-struct _NautilusFileUndoInfoCompressDetails {
- GList *sources;
- GFile *output;
- AutoarFormat format;
- AutoarFilter filter;
+struct _NautilusFileUndoInfoCompressDetails
+{
+ GList *sources;
+ GFile *output;
+ AutoarFormat format;
+ AutoarFilter filter;
};
static void
@@ -2156,15 +2299,16 @@ compress_callback (GFile *new_file,
gboolean success,
gpointer callback_data)
{
- NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (callback_data);
+ NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (callback_data);
- if (success) {
- g_object_unref (self->priv->output);
+ if (success)
+ {
+ g_object_unref (self->priv->output);
- self->priv->output = g_object_ref (new_file);
- }
+ self->priv->output = g_object_ref (new_file);
+ }
- file_undo_info_transfer_callback (NULL, success, self);
+ file_undo_info_transfer_callback (NULL, success, self);
}
static void
@@ -2174,94 +2318,97 @@ compress_strings_func (NautilusFileUndoInfo *info,
gchar **redo_label,
gchar **redo_description)
{
- NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (info);
- g_autofree gchar *output_name;
- gint sources_count;
+ NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (info);
+ g_autofree gchar *output_name;
+ gint sources_count;
- output_name = g_file_get_parse_name (self->priv->output);
- *undo_description = g_strdup_printf (_("Delete '%s'"), output_name);
+ output_name = g_file_get_parse_name (self->priv->output);
+ *undo_description = g_strdup_printf (_("Delete '%s'"), output_name);
- sources_count = g_list_length (self->priv->sources);
- if (sources_count == 1) {
- GFile *source;
- g_autofree gchar *source_name;
+ sources_count = g_list_length (self->priv->sources);
+ if (sources_count == 1)
+ {
+ GFile *source;
+ g_autofree gchar *source_name;
- source = self->priv->sources->data;
- source_name = g_file_get_parse_name (source);
+ source = self->priv->sources->data;
+ source_name = g_file_get_parse_name (source);
- *redo_description = g_strdup_printf (_("Compress '%s'"), source_name);
- } else {
- *redo_description = g_strdup_printf (ngettext ("Compress %d file",
- "Compress %d files",
- sources_count),
- sources_count);
- }
+ *redo_description = g_strdup_printf (_("Compress '%s'"), source_name);
+ }
+ else
+ {
+ *redo_description = g_strdup_printf (ngettext ("Compress %d file",
+ "Compress %d files",
+ sources_count),
+ sources_count);
+ }
- *undo_label = g_strdup (_("_Undo Compress"));
- *redo_label = g_strdup (_("_Redo Compress"));
+ *undo_label = g_strdup (_("_Undo Compress"));
+ *redo_label = g_strdup (_("_Redo Compress"));
}
static void
compress_redo_func (NautilusFileUndoInfo *info,
GtkWindow *parent_window)
{
- NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (info);
+ NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (info);
- nautilus_file_operations_compress (self->priv->sources,
- self->priv->output,
- self->priv->format,
- self->priv->filter,
- parent_window,
- compress_callback,
- self);
+ nautilus_file_operations_compress (self->priv->sources,
+ self->priv->output,
+ self->priv->format,
+ self->priv->filter,
+ parent_window,
+ compress_callback,
+ self);
}
static void
compress_undo_func (NautilusFileUndoInfo *info,
GtkWindow *parent_window)
{
- NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (info);
- GList *files = NULL;
+ NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (info);
+ GList *files = NULL;
- files = g_list_prepend (files, self->priv->output);
+ files = g_list_prepend (files, self->priv->output);
- nautilus_file_operations_delete (files, parent_window,
- file_undo_info_delete_callback, self);
+ nautilus_file_operations_delete (files, parent_window,
+ file_undo_info_delete_callback, self);
- g_list_free (files);
+ g_list_free (files);
}
static void
nautilus_file_undo_info_compress_init (NautilusFileUndoInfoCompress *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_compress_get_type (),
- NautilusFileUndoInfoCompressDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, nautilus_file_undo_info_compress_get_type (),
+ NautilusFileUndoInfoCompressDetails);
}
static void
nautilus_file_undo_info_compress_finalize (GObject *obj)
{
- NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (obj);
+ NautilusFileUndoInfoCompress *self = NAUTILUS_FILE_UNDO_INFO_COMPRESS (obj);
- g_list_free_full (self->priv->sources, g_object_unref);
- g_clear_object (&self->priv->output);
+ g_list_free_full (self->priv->sources, g_object_unref);
+ g_clear_object (&self->priv->output);
- G_OBJECT_CLASS (nautilus_file_undo_info_compress_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_file_undo_info_compress_parent_class)->finalize (obj);
}
static void
nautilus_file_undo_info_compress_class_init (NautilusFileUndoInfoCompressClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ NautilusFileUndoInfoClass *iclass = NAUTILUS_FILE_UNDO_INFO_CLASS (klass);
- oclass->finalize = nautilus_file_undo_info_compress_finalize;
+ oclass->finalize = nautilus_file_undo_info_compress_finalize;
- iclass->undo_func = compress_undo_func;
- iclass->redo_func = compress_redo_func;
- iclass->strings_func = compress_strings_func;
+ iclass->undo_func = compress_undo_func;
+ iclass->redo_func = compress_redo_func;
+ iclass->strings_func = compress_strings_func;
- g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoCompressDetails));
+ g_type_class_add_private (klass, sizeof (NautilusFileUndoInfoCompressDetails));
}
NautilusFileUndoInfo *
@@ -2270,17 +2417,17 @@ nautilus_file_undo_info_compress_new (GList *sources,
AutoarFormat format,
AutoarFilter filter)
{
- NautilusFileUndoInfoCompress *self;
+ NautilusFileUndoInfoCompress *self;
- self = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_COMPRESS,
- "item-count", 1,
- "op-type", NAUTILUS_FILE_UNDO_OP_COMPRESS,
- NULL);
+ self = g_object_new (NAUTILUS_TYPE_FILE_UNDO_INFO_COMPRESS,
+ "item-count", 1,
+ "op-type", NAUTILUS_FILE_UNDO_OP_COMPRESS,
+ NULL);
- self->priv->sources = g_list_copy_deep (sources, (GCopyFunc)g_object_ref, NULL);
- self->priv->output = g_object_ref (output);
- self->priv->format = format;
- self->priv->filter = filter;
+ self->priv->sources = g_list_copy_deep (sources, (GCopyFunc) g_object_ref, NULL);
+ self->priv->output = g_object_ref (output);
+ self->priv->format = format;
+ self->priv->filter = filter;
- return NAUTILUS_FILE_UNDO_INFO (self);
+ return NAUTILUS_FILE_UNDO_INFO (self);
}
diff --git a/src/nautilus-file-utilities.c b/src/nautilus-file-utilities.c
index 6ed4127a0..4a9100fa2 100644
--- a/src/nautilus-file-utilities.c
+++ b/src/nautilus-file-utilities.c
@@ -1,24 +1,23 @@
-
/* nautilus-file-utilities.c - implementation of file manipulation routines.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
-*/
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
#include "nautilus-file-utilities.h"
@@ -52,255 +51,301 @@
/* This or something equivalent will eventually go into glib/guri.h */
gboolean
nautilus_uri_parse (const char *uri,
- char **host,
- guint16 *port,
- char **userinfo)
+ char **host,
+ guint16 *port,
+ char **userinfo)
{
- char *tmp_str;
- const char *start, *p;
- char c;
-
- g_return_val_if_fail (uri != NULL, FALSE);
-
- if (host)
- *host = NULL;
+ char *tmp_str;
+ const char *start, *p;
+ char c;
- if (port)
- *port = 0;
+ g_return_val_if_fail (uri != NULL, FALSE);
- if (userinfo)
- *userinfo = NULL;
+ if (host)
+ {
+ *host = NULL;
+ }
- /* From RFC 3986 Decodes:
- * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
- * hier-part = "//" authority path-abempty
- * path-abempty = *( "/" segment )
- * authority = [ userinfo "@" ] host [ ":" port ]
- */
+ if (port)
+ {
+ *port = 0;
+ }
- /* Check we have a valid scheme */
- tmp_str = g_uri_parse_scheme (uri);
+ if (userinfo)
+ {
+ *userinfo = NULL;
+ }
- if (tmp_str == NULL)
- return FALSE;
+ /* From RFC 3986 Decodes:
+ * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
+ * hier-part = "//" authority path-abempty
+ * path-abempty = *( "/" segment )
+ * authority = [ userinfo "@" ] host [ ":" port ]
+ */
- g_free (tmp_str);
+ /* Check we have a valid scheme */
+ tmp_str = g_uri_parse_scheme (uri);
- /* Decode hier-part:
- * hier-part = "//" authority path-abempty
- */
- p = uri;
- start = strstr (p, "//");
+ if (tmp_str == NULL)
+ {
+ return FALSE;
+ }
- if (start == NULL)
- return FALSE;
+ g_free (tmp_str);
- start += 2;
+ /* Decode hier-part:
+ * hier-part = "//" authority path-abempty
+ */
+ p = uri;
+ start = strstr (p, "//");
- if (strchr (start, '@') != NULL)
+ if (start == NULL)
{
- /* Decode userinfo:
- * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
- * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
- * pct-encoded = "%" HEXDIG HEXDIG
- */
- p = start;
- while (1)
- {
- c = *p++;
+ return FALSE;
+ }
- if (c == '@')
- break;
+ start += 2;
- /* pct-encoded */
- if (c == '%')
- {
- if (!(g_ascii_isxdigit (p[0]) ||
- g_ascii_isxdigit (p[1])))
- return FALSE;
+ if (strchr (start, '@') != NULL)
+ {
+ /* Decode userinfo:
+ * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
+ * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
+ * pct-encoded = "%" HEXDIG HEXDIG
+ */
+ p = start;
+ while (1)
+ {
+ c = *p++;
+
+ if (c == '@')
+ {
+ break;
+ }
+
+ /* pct-encoded */
+ if (c == '%')
+ {
+ if (!(g_ascii_isxdigit (p[0]) ||
+ g_ascii_isxdigit (p[1])))
+ {
+ return FALSE;
+ }
- p++;
+ p++;
- continue;
- }
+ continue;
+ }
- /* unreserved / sub-delims / : */
- if (!(g_ascii_isalnum (c) ||
- strchr (G_URI_OTHER_UNRESERVED, c) ||
- strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
- c == ':'))
- return FALSE;
- }
+ /* unreserved / sub-delims / : */
+ if (!(g_ascii_isalnum (c) ||
+ strchr (G_URI_OTHER_UNRESERVED, c) ||
+ strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
+ c == ':'))
+ {
+ return FALSE;
+ }
+ }
- if (userinfo)
- *userinfo = g_strndup (start, p - start - 1);
+ if (userinfo)
+ {
+ *userinfo = g_strndup (start, p - start - 1);
+ }
- start = p;
+ start = p;
}
- else
+ else
{
- p = start;
+ p = start;
}
- /* decode host:
- * host = IP-literal / IPv4address / reg-name
- * reg-name = *( unreserved / pct-encoded / sub-delims )
- */
+ /* decode host:
+ * host = IP-literal / IPv4address / reg-name
+ * reg-name = *( unreserved / pct-encoded / sub-delims )
+ */
- /* If IPv6 or IPvFuture */
- if (*p == '[')
+ /* If IPv6 or IPvFuture */
+ if (*p == '[')
{
- start++;
- p++;
- while (1)
- {
- c = *p++;
-
- if (c == ']')
- break;
-
- /* unreserved / sub-delims */
- if (!(g_ascii_isalnum (c) ||
- strchr (G_URI_OTHER_UNRESERVED, c) ||
- strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
- c == ':' ||
- c == '.'))
- goto error;
- }
+ start++;
+ p++;
+ while (1)
+ {
+ c = *p++;
+
+ if (c == ']')
+ {
+ break;
+ }
+
+ /* unreserved / sub-delims */
+ if (!(g_ascii_isalnum (c) ||
+ strchr (G_URI_OTHER_UNRESERVED, c) ||
+ strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c) ||
+ c == ':' ||
+ c == '.'))
+ {
+ goto error;
+ }
+ }
}
- else
+ else
{
- while (1)
- {
- c = *p++;
-
- if (c == ':' ||
- c == '/' ||
- c == '?' ||
- c == '#' ||
- c == '\0')
- break;
-
- /* pct-encoded */
- if (c == '%')
- {
- if (!(g_ascii_isxdigit (p[0]) ||
- g_ascii_isxdigit (p[1])))
- goto error;
+ while (1)
+ {
+ c = *p++;
+
+ if (c == ':' ||
+ c == '/' ||
+ c == '?' ||
+ c == '#' ||
+ c == '\0')
+ {
+ break;
+ }
+
+ /* pct-encoded */
+ if (c == '%')
+ {
+ if (!(g_ascii_isxdigit (p[0]) ||
+ g_ascii_isxdigit (p[1])))
+ {
+ goto error;
+ }
- p++;
+ p++;
- continue;
- }
+ continue;
+ }
- /* unreserved / sub-delims */
- if (!(g_ascii_isalnum (c) ||
- strchr (G_URI_OTHER_UNRESERVED, c) ||
- strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c)))
- goto error;
- }
+ /* unreserved / sub-delims */
+ if (!(g_ascii_isalnum (c) ||
+ strchr (G_URI_OTHER_UNRESERVED, c) ||
+ strchr (G_URI_RESERVED_CHARS_SUBCOMPONENT_DELIMITERS, c)))
+ {
+ goto error;
+ }
+ }
}
- if (host)
- *host = g_uri_unescape_segment (start, p - 1, NULL);
-
- if (c == ':')
+ if (host)
{
- /* Decode pot:
- * port = *DIGIT
- */
- guint tmp = 0;
-
- while (1)
- {
- c = *p++;
-
- if (c == '/' ||
- c == '?' ||
- c == '#' ||
- c == '\0')
- break;
-
- if (!g_ascii_isdigit (c))
- goto error;
-
- tmp = (tmp * 10) + (c - '0');
+ *host = g_uri_unescape_segment (start, p - 1, NULL);
+ }
- if (tmp > 65535)
- goto error;
- }
- if (port)
- *port = (guint16) tmp;
+ if (c == ':')
+ {
+ /* Decode pot:
+ * port = *DIGIT
+ */
+ guint tmp = 0;
+
+ while (1)
+ {
+ c = *p++;
+
+ if (c == '/' ||
+ c == '?' ||
+ c == '#' ||
+ c == '\0')
+ {
+ break;
+ }
+
+ if (!g_ascii_isdigit (c))
+ {
+ goto error;
+ }
+
+ tmp = (tmp * 10) + (c - '0');
+
+ if (tmp > 65535)
+ {
+ goto error;
+ }
+ }
+ if (port)
+ {
+ *port = (guint16) tmp;
+ }
}
- return TRUE;
+ return TRUE;
error:
- if (host && *host)
+ if (host && *host)
{
- g_free (*host);
- *host = NULL;
+ g_free (*host);
+ *host = NULL;
}
- if (userinfo && *userinfo)
+ if (userinfo && *userinfo)
{
- g_free (*userinfo);
- *userinfo = NULL;
+ g_free (*userinfo);
+ *userinfo = NULL;
}
- return FALSE;
+ return FALSE;
}
char *
nautilus_compute_title_for_location (GFile *location)
{
- NautilusFile *file;
- GMount *mount;
- char *title;
+ NautilusFile *file;
+ GMount *mount;
+ char *title;
- /* TODO-gio: This doesn't really work all that great if the
- info about the file isn't known atm... */
+ /* TODO-gio: This doesn't really work all that great if the
+ * info about the file isn't known atm... */
- if (nautilus_is_home_directory (location)) {
- return g_strdup (_("Home"));
- }
+ if (nautilus_is_home_directory (location))
+ {
+ return g_strdup (_("Home"));
+ }
+
+ if ((mount = nautilus_get_mounted_mount_for_root (location)) != NULL)
+ {
+ title = g_mount_get_name (mount);
+
+ g_object_unref (mount);
- if ((mount = nautilus_get_mounted_mount_for_root (location)) != NULL) {
- title = g_mount_get_name(mount);
+ return title;
+ }
- g_object_unref(mount);
+ title = NULL;
+ if (location)
+ {
+ file = nautilus_file_get (location);
- return title;
+ if (nautilus_file_is_other_locations (file))
+ {
+ title = g_strdup (_("Other Locations"));
}
-
- title = NULL;
- if (location) {
- file = nautilus_file_get (location);
-
- if (nautilus_file_is_other_locations (file)) {
- title = g_strdup (_("Other Locations"));
- } else {
- title = nautilus_file_get_description (file);
-
- if (title == NULL) {
- title = nautilus_file_get_display_name (file);
- }
- }
- nautilus_file_unref (file);
- }
-
- if (title == NULL) {
- title = g_file_get_basename (location);
- }
-
- return title;
+ else
+ {
+ title = nautilus_file_get_description (file);
+
+ if (title == NULL)
+ {
+ title = nautilus_file_get_display_name (file);
+ }
+ }
+ nautilus_file_unref (file);
+ }
+
+ if (title == NULL)
+ {
+ title = g_file_get_basename (location);
+ }
+
+ return title;
}
/**
* nautilus_get_user_directory:
- *
+ *
* Get the path for the directory containing nautilus settings.
*
* Return value: the directory path.
@@ -308,24 +353,25 @@ nautilus_compute_title_for_location (GFile *location)
char *
nautilus_get_user_directory (void)
{
- char *user_directory = NULL;
-
- user_directory = g_build_filename (g_get_user_config_dir (),
- NAUTILUS_USER_DIRECTORY_NAME,
- NULL);
-
- if (!g_file_test (user_directory, G_FILE_TEST_EXISTS)) {
- g_mkdir (user_directory, DEFAULT_NAUTILUS_DIRECTORY_MODE);
- /* FIXME bugzilla.gnome.org 41286:
- * How should we handle the case where this mkdir fails?
- * Note that nautilus_application_startup will refuse to launch if this
- * directory doesn't get created, so that case is OK. But the directory
- * could be deleted after Nautilus was launched, and perhaps
- * there is some bad side-effect of not handling that case.
- */
- }
-
- return user_directory;
+ char *user_directory = NULL;
+
+ user_directory = g_build_filename (g_get_user_config_dir (),
+ NAUTILUS_USER_DIRECTORY_NAME,
+ NULL);
+
+ if (!g_file_test (user_directory, G_FILE_TEST_EXISTS))
+ {
+ g_mkdir (user_directory, DEFAULT_NAUTILUS_DIRECTORY_MODE);
+ /* FIXME bugzilla.gnome.org 41286:
+ * How should we handle the case where this mkdir fails?
+ * Note that nautilus_application_startup will refuse to launch if this
+ * directory doesn't get created, so that case is OK. But the directory
+ * could be deleted after Nautilus was launched, and perhaps
+ * there is some bad side-effect of not handling that case.
+ */
+ }
+
+ return user_directory;
}
/**
@@ -338,25 +384,26 @@ nautilus_get_user_directory (void)
char *
nautilus_get_scripts_directory_path (void)
{
- return g_build_filename (g_get_user_data_dir (), "nautilus", "scripts", NULL);
+ return g_build_filename (g_get_user_data_dir (), "nautilus", "scripts", NULL);
}
static const char *
get_desktop_path (void)
{
- const char *desktop_path;
+ const char *desktop_path;
- desktop_path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
- if (desktop_path == NULL) {
- desktop_path = g_get_home_dir ();
- }
+ desktop_path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+ if (desktop_path == NULL)
+ {
+ desktop_path = g_get_home_dir ();
+ }
- return desktop_path;
+ return desktop_path;
}
/**
* nautilus_get_desktop_directory:
- *
+ *
* Get the path for the directory containing files on the desktop.
*
* Return value: the directory path.
@@ -364,34 +411,35 @@ get_desktop_path (void)
char *
nautilus_get_desktop_directory (void)
{
- const char *desktop_directory;
-
- desktop_directory = get_desktop_path ();
-
- /* Don't try to create a home directory */
- if (!g_file_test (desktop_directory, G_FILE_TEST_EXISTS)) {
- g_mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
- /* FIXME bugzilla.gnome.org 41286:
- * How should we handle the case where this mkdir fails?
- * Note that nautilus_application_startup will refuse to launch if this
- * directory doesn't get created, so that case is OK. But the directory
- * could be deleted after Nautilus was launched, and perhaps
- * there is some bad side-effect of not handling that case.
- */
- }
-
- return g_strdup (desktop_directory);
+ const char *desktop_directory;
+
+ desktop_directory = get_desktop_path ();
+
+ /* Don't try to create a home directory */
+ if (!g_file_test (desktop_directory, G_FILE_TEST_EXISTS))
+ {
+ g_mkdir (desktop_directory, DEFAULT_DESKTOP_DIRECTORY_MODE);
+ /* FIXME bugzilla.gnome.org 41286:
+ * How should we handle the case where this mkdir fails?
+ * Note that nautilus_application_startup will refuse to launch if this
+ * directory doesn't get created, so that case is OK. But the directory
+ * could be deleted after Nautilus was launched, and perhaps
+ * there is some bad side-effect of not handling that case.
+ */
+ }
+
+ return g_strdup (desktop_directory);
}
GFile *
nautilus_get_desktop_location (void)
{
- return g_file_new_for_path (get_desktop_path ());
+ return g_file_new_for_path (get_desktop_path ());
}
/**
* nautilus_get_desktop_directory_uri:
- *
+ *
* Get the uri for the directory containing files on the desktop.
*
* Return value: the directory path.
@@ -399,49 +447,49 @@ nautilus_get_desktop_location (void)
char *
nautilus_get_desktop_directory_uri (void)
{
- char *desktop_path;
- char *desktop_uri;
-
- desktop_path = nautilus_get_desktop_directory ();
- desktop_uri = g_filename_to_uri (desktop_path, NULL, NULL);
- g_free (desktop_path);
-
- return desktop_uri;
+ char *desktop_path;
+ char *desktop_uri;
+
+ desktop_path = nautilus_get_desktop_directory ();
+ desktop_uri = g_filename_to_uri (desktop_path, NULL, NULL);
+ g_free (desktop_path);
+
+ return desktop_uri;
}
char *
nautilus_get_home_directory_uri (void)
{
- return g_filename_to_uri (g_get_home_dir (), NULL, NULL);
+ return g_filename_to_uri (g_get_home_dir (), NULL, NULL);
}
gboolean
nautilus_should_use_templates_directory (void)
{
- const char *dir;
- gboolean res;
+ const char *dir;
+ gboolean res;
- dir = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES);
- res = dir && (g_strcmp0 (dir, g_get_home_dir ()) != 0);
- return res;
+ dir = g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES);
+ res = dir && (g_strcmp0 (dir, g_get_home_dir ()) != 0);
+ return res;
}
char *
nautilus_get_templates_directory (void)
{
- return g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES));
+ return g_strdup (g_get_user_special_dir (G_USER_DIRECTORY_TEMPLATES));
}
char *
nautilus_get_templates_directory_uri (void)
{
- char *directory, *uri;
+ char *directory, *uri;
- directory = nautilus_get_templates_directory ();
- uri = g_filename_to_uri (directory, NULL, NULL);
- g_free (directory);
- return uri;
+ directory = nautilus_get_templates_directory ();
+ uri = g_filename_to_uri (directory, NULL, NULL);
+ g_free (directory);
+ return uri;
}
/* These need to be reset to NULL when desktop_is_home_dir changes */
@@ -452,232 +500,241 @@ static char *desktop_dir_filename = NULL;
static void
update_desktop_dir (void)
{
- const char *path;
- char *dirname;
-
- path = get_desktop_path ();
- desktop_dir = g_file_new_for_path (path);
-
- dirname = g_path_get_dirname (path);
- desktop_dir_dir = g_file_new_for_path (dirname);
- g_free (dirname);
- desktop_dir_filename = g_path_get_basename (path);
+ const char *path;
+ char *dirname;
+
+ path = get_desktop_path ();
+ desktop_dir = g_file_new_for_path (path);
+
+ dirname = g_path_get_dirname (path);
+ desktop_dir_dir = g_file_new_for_path (dirname);
+ g_free (dirname);
+ desktop_dir_filename = g_path_get_basename (path);
}
gboolean
-nautilus_is_home_directory_file (GFile *dir,
- const char *filename)
+nautilus_is_home_directory_file (GFile *dir,
+ const char *filename)
{
- char *dirname;
- static GFile *home_dir_dir = NULL;
- static char *home_dir_filename = NULL;
-
- if (home_dir_dir == NULL) {
- dirname = g_path_get_dirname (g_get_home_dir ());
- home_dir_dir = g_file_new_for_path (dirname);
- g_free (dirname);
- home_dir_filename = g_path_get_basename (g_get_home_dir ());
- }
-
- return (g_file_equal (dir, home_dir_dir) &&
- strcmp (filename, home_dir_filename) == 0);
+ char *dirname;
+ static GFile *home_dir_dir = NULL;
+ static char *home_dir_filename = NULL;
+
+ if (home_dir_dir == NULL)
+ {
+ dirname = g_path_get_dirname (g_get_home_dir ());
+ home_dir_dir = g_file_new_for_path (dirname);
+ g_free (dirname);
+ home_dir_filename = g_path_get_basename (g_get_home_dir ());
+ }
+
+ return (g_file_equal (dir, home_dir_dir) &&
+ strcmp (filename, home_dir_filename) == 0);
}
gboolean
nautilus_is_home_directory (GFile *dir)
{
- static GFile *home_dir = NULL;
-
- if (home_dir == NULL) {
- home_dir = g_file_new_for_path (g_get_home_dir ());
- }
+ static GFile *home_dir = NULL;
+
+ if (home_dir == NULL)
+ {
+ home_dir = g_file_new_for_path (g_get_home_dir ());
+ }
- return g_file_equal (dir, home_dir);
+ return g_file_equal (dir, home_dir);
}
gboolean
nautilus_is_root_directory (GFile *dir)
{
- static GFile *root_dir = NULL;
-
- if (root_dir == NULL) {
- root_dir = g_file_new_for_path ("/");
- }
+ static GFile *root_dir = NULL;
+
+ if (root_dir == NULL)
+ {
+ root_dir = g_file_new_for_path ("/");
+ }
- return g_file_equal (dir, root_dir);
+ return g_file_equal (dir, root_dir);
}
-
-
+
+
gboolean
-nautilus_is_desktop_directory_file (GFile *dir,
- const char *file)
+nautilus_is_desktop_directory_file (GFile *dir,
+ const char *file)
{
+ if (desktop_dir == NULL)
+ {
+ update_desktop_dir ();
+ }
- if (desktop_dir == NULL) {
- update_desktop_dir ();
- }
-
- return (g_file_equal (dir, desktop_dir_dir) &&
- strcmp (file, desktop_dir_filename) == 0);
+ return (g_file_equal (dir, desktop_dir_dir) &&
+ strcmp (file, desktop_dir_filename) == 0);
}
gboolean
nautilus_is_desktop_directory (GFile *dir)
{
+ if (desktop_dir == NULL)
+ {
+ update_desktop_dir ();
+ }
- if (desktop_dir == NULL) {
- update_desktop_dir ();
- }
-
- return g_file_equal (dir, desktop_dir);
+ return g_file_equal (dir, desktop_dir);
}
gboolean
nautilus_is_search_directory (GFile *dir)
{
- g_autofree gchar *uri = NULL;
+ g_autofree gchar *uri = NULL;
- uri = g_file_get_uri (dir);
- return eel_uri_is_search (uri);
+ uri = g_file_get_uri (dir);
+ return eel_uri_is_search (uri);
}
GMount *
nautilus_get_mounted_mount_for_root (GFile *location)
{
- GVolumeMonitor *volume_monitor;
- GList *mounts;
- GList *l;
- GMount *mount;
- GMount *result = NULL;
- GFile *root = NULL;
- GFile *default_location = NULL;
-
- volume_monitor = g_volume_monitor_get ();
- mounts = g_volume_monitor_get_mounts (volume_monitor);
-
- for (l = mounts; l != NULL; l = l->next) {
- mount = l->data;
-
- if (g_mount_is_shadowed (mount)) {
- continue;
- }
-
- root = g_mount_get_root (mount);
- if (g_file_equal (location, root)) {
- result = g_object_ref (mount);
- break;
- }
-
- default_location = g_mount_get_default_location (mount);
- if (!g_file_equal (default_location, root) &&
- g_file_equal (location, default_location)) {
- result = g_object_ref (mount);
- break;
- }
- }
-
- g_clear_object (&root);
- g_clear_object (&default_location);
- g_list_free_full (mounts, g_object_unref);
-
- return result;
+ GVolumeMonitor *volume_monitor;
+ GList *mounts;
+ GList *l;
+ GMount *mount;
+ GMount *result = NULL;
+ GFile *root = NULL;
+ GFile *default_location = NULL;
+
+ volume_monitor = g_volume_monitor_get ();
+ mounts = g_volume_monitor_get_mounts (volume_monitor);
+
+ for (l = mounts; l != NULL; l = l->next)
+ {
+ mount = l->data;
+
+ if (g_mount_is_shadowed (mount))
+ {
+ continue;
+ }
+
+ root = g_mount_get_root (mount);
+ if (g_file_equal (location, root))
+ {
+ result = g_object_ref (mount);
+ break;
+ }
+
+ default_location = g_mount_get_default_location (mount);
+ if (!g_file_equal (default_location, root) &&
+ g_file_equal (location, default_location))
+ {
+ result = g_object_ref (mount);
+ break;
+ }
+ }
+
+ g_clear_object (&root);
+ g_clear_object (&default_location);
+ g_list_free_full (mounts, g_object_unref);
+
+ return result;
}
GFile *
nautilus_generate_unique_file_in_directory (GFile *directory,
const char *basename)
{
- g_autofree char *basename_without_extension = NULL;
- const char *extension;
- GFile *child;
- int copy;
+ g_autofree char *basename_without_extension = NULL;
+ const char *extension;
+ GFile *child;
+ int copy;
- g_return_val_if_fail (directory != NULL, NULL);
- g_return_val_if_fail (basename != NULL, NULL);
- g_return_val_if_fail (g_file_query_exists (directory, NULL), NULL);
+ g_return_val_if_fail (directory != NULL, NULL);
+ g_return_val_if_fail (basename != NULL, NULL);
+ g_return_val_if_fail (g_file_query_exists (directory, NULL), NULL);
- basename_without_extension = eel_filename_strip_extension (basename);
- extension = eel_filename_get_extension_offset (basename);
+ basename_without_extension = eel_filename_strip_extension (basename);
+ extension = eel_filename_get_extension_offset (basename);
- child = g_file_get_child (directory, basename);
+ child = g_file_get_child (directory, basename);
- copy = 1;
- while (g_file_query_exists (child, NULL)) {
- g_autofree char *filename;
+ copy = 1;
+ while (g_file_query_exists (child, NULL))
+ {
+ g_autofree char *filename;
- g_object_unref (child);
+ g_object_unref (child);
- filename = g_strdup_printf ("%s (%d)%s",
- basename_without_extension,
- copy,
- extension ? extension : "");
- child = g_file_get_child (directory, filename);
+ filename = g_strdup_printf ("%s (%d)%s",
+ basename_without_extension,
+ copy,
+ extension ? extension : "");
+ child = g_file_get_child (directory, filename);
- copy++;
- }
+ copy++;
+ }
- return child;
+ return child;
}
GFile *
nautilus_find_existing_uri_in_hierarchy (GFile *location)
{
- GFileInfo *info;
- GFile *tmp;
-
- g_assert (location != NULL);
-
- location = g_object_ref (location);
- while (location != NULL) {
- info = g_file_query_info (location,
- G_FILE_ATTRIBUTE_STANDARD_NAME,
- 0, NULL, NULL);
- g_object_unref (info);
- if (info != NULL) {
- return location;
- }
- tmp = location;
- location = g_file_get_parent (location);
- g_object_unref (tmp);
- }
-
- return location;
+ GFileInfo *info;
+ GFile *tmp;
+
+ g_assert (location != NULL);
+
+ location = g_object_ref (location);
+ while (location != NULL)
+ {
+ info = g_file_query_info (location,
+ G_FILE_ATTRIBUTE_STANDARD_NAME,
+ 0, NULL, NULL);
+ g_object_unref (info);
+ if (info != NULL)
+ {
+ return location;
+ }
+ tmp = location;
+ location = g_file_get_parent (location);
+ g_object_unref (tmp);
+ }
+
+ return location;
}
static gboolean
have_program_in_path (const char *name)
{
- gchar *path;
- gboolean result;
+ gchar *path;
+ gboolean result;
- path = g_find_program_in_path (name);
- result = (path != NULL);
- g_free (path);
- return result;
+ path = g_find_program_in_path (name);
+ result = (path != NULL);
+ g_free (path);
+ return result;
}
static GIcon *
special_directory_get_icon (GUserDirectory directory,
- gboolean symbolic)
+ gboolean symbolic)
{
+#define ICON_CASE(x) \
+ case G_USER_DIRECTORY_ ## x: \
+ return (symbolic) ? g_themed_icon_new (NAUTILUS_ICON_FOLDER_ ## x) : g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_ ## x);
-#define ICON_CASE(x) \
- case G_USER_DIRECTORY_ ## x: \
- return (symbolic) ? g_themed_icon_new (NAUTILUS_ICON_FOLDER_ ## x) : g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER_ ## x);
-
- switch (directory) {
-
- ICON_CASE (DOCUMENTS);
- ICON_CASE (DOWNLOAD);
- ICON_CASE (MUSIC);
- ICON_CASE (PICTURES);
- ICON_CASE (PUBLIC_SHARE);
- ICON_CASE (TEMPLATES);
- ICON_CASE (VIDEOS);
-
- default:
- return (symbolic) ? g_themed_icon_new (NAUTILUS_ICON_FOLDER) : g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER);
- }
+ switch (directory)
+ {
+ ICON_CASE (DOCUMENTS);
+ ICON_CASE (DOWNLOAD);
+ ICON_CASE (MUSIC);
+ ICON_CASE (PICTURES);
+ ICON_CASE (PUBLIC_SHARE);
+ ICON_CASE (TEMPLATES);
+ ICON_CASE (VIDEOS);
+
+ default:
+ return (symbolic) ? g_themed_icon_new (NAUTILUS_ICON_FOLDER) : g_themed_icon_new (NAUTILUS_ICON_FULLCOLOR_FOLDER);
+ }
#undef ICON_CASE
}
@@ -685,510 +742,583 @@ special_directory_get_icon (GUserDirectory directory,
GIcon *
nautilus_special_directory_get_symbolic_icon (GUserDirectory directory)
{
- return special_directory_get_icon (directory, TRUE);
+ return special_directory_get_icon (directory, TRUE);
}
GIcon *
nautilus_special_directory_get_icon (GUserDirectory directory)
{
- return special_directory_get_icon (directory, FALSE);
+ return special_directory_get_icon (directory, FALSE);
}
gboolean
nautilus_is_file_roller_installed (void)
{
- static int installed = - 1;
+ static int installed = -1;
- if (installed < 0) {
- if (have_program_in_path ("file-roller")) {
- installed = 1;
- } else {
- installed = 0;
- }
- }
+ if (installed < 0)
+ {
+ if (have_program_in_path ("file-roller"))
+ {
+ installed = 1;
+ }
+ else
+ {
+ installed = 0;
+ }
+ }
- return installed > 0 ? TRUE : FALSE;
+ return installed > 0 ? TRUE : FALSE;
}
/* Returns TRUE if the file is in XDG_DATA_DIRS. This is used for
- deciding if a desktop file is "trusted" based on the path */
+ * deciding if a desktop file is "trusted" based on the path */
gboolean
nautilus_is_in_system_dir (GFile *file)
{
- const char * const * data_dirs;
- char *path;
- int i;
- gboolean res;
-
- if (!g_file_is_native (file)) {
- return FALSE;
- }
-
- path = g_file_get_path (file);
-
- res = FALSE;
-
- data_dirs = g_get_system_data_dirs ();
- for (i = 0; path != NULL && data_dirs[i] != NULL; i++) {
- if (g_str_has_prefix (path, data_dirs[i])) {
- res = TRUE;
- break;
- }
-
- }
-
- g_free (path);
-
- return res;
+ const char * const *data_dirs;
+ char *path;
+ int i;
+ gboolean res;
+
+ if (!g_file_is_native (file))
+ {
+ return FALSE;
+ }
+
+ path = g_file_get_path (file);
+
+ res = FALSE;
+
+ data_dirs = g_get_system_data_dirs ();
+ for (i = 0; path != NULL && data_dirs[i] != NULL; i++)
+ {
+ if (g_str_has_prefix (path, data_dirs[i]))
+ {
+ res = TRUE;
+ break;
+ }
+ }
+
+ g_free (path);
+
+ return res;
}
GHashTable *
-nautilus_trashed_files_get_original_directories (GList *files,
- GList **unhandled_files)
+nautilus_trashed_files_get_original_directories (GList *files,
+ GList **unhandled_files)
{
- GHashTable *directories;
- NautilusFile *file, *original_file, *original_dir;
- GList *l, *m;
-
- directories = NULL;
-
- if (unhandled_files != NULL) {
- *unhandled_files = NULL;
- }
-
- for (l = files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- original_file = nautilus_file_get_trash_original_file (file);
-
- original_dir = NULL;
- if (original_file != NULL) {
- original_dir = nautilus_file_get_parent (original_file);
- }
-
- if (original_dir != NULL) {
- if (directories == NULL) {
- directories = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- (GDestroyNotify) nautilus_file_unref,
- (GDestroyNotify) nautilus_file_list_free);
- }
- nautilus_file_ref (original_dir);
- m = g_hash_table_lookup (directories, original_dir);
- if (m != NULL) {
- g_hash_table_steal (directories, original_dir);
- nautilus_file_unref (original_dir);
- }
- m = g_list_append (m, nautilus_file_ref (file));
- g_hash_table_insert (directories, original_dir, m);
- } else if (unhandled_files != NULL) {
- *unhandled_files = g_list_append (*unhandled_files, nautilus_file_ref (file));
- }
-
- nautilus_file_unref (original_file);
- nautilus_file_unref (original_dir);
- }
-
- return directories;
+ GHashTable *directories;
+ NautilusFile *file, *original_file, *original_dir;
+ GList *l, *m;
+
+ directories = NULL;
+
+ if (unhandled_files != NULL)
+ {
+ *unhandled_files = NULL;
+ }
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ original_file = nautilus_file_get_trash_original_file (file);
+
+ original_dir = NULL;
+ if (original_file != NULL)
+ {
+ original_dir = nautilus_file_get_parent (original_file);
+ }
+
+ if (original_dir != NULL)
+ {
+ if (directories == NULL)
+ {
+ directories = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ (GDestroyNotify) nautilus_file_unref,
+ (GDestroyNotify) nautilus_file_list_free);
+ }
+ nautilus_file_ref (original_dir);
+ m = g_hash_table_lookup (directories, original_dir);
+ if (m != NULL)
+ {
+ g_hash_table_steal (directories, original_dir);
+ nautilus_file_unref (original_dir);
+ }
+ m = g_list_append (m, nautilus_file_ref (file));
+ g_hash_table_insert (directories, original_dir, m);
+ }
+ else if (unhandled_files != NULL)
+ {
+ *unhandled_files = g_list_append (*unhandled_files, nautilus_file_ref (file));
+ }
+
+ nautilus_file_unref (original_file);
+ nautilus_file_unref (original_dir);
+ }
+
+ return directories;
}
static GList *
locations_from_file_list (GList *file_list)
{
- NautilusFile *file;
- GList *l, *ret;
+ NautilusFile *file;
+ GList *l, *ret;
- ret = NULL;
+ ret = NULL;
- for (l = file_list; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- ret = g_list_prepend (ret, nautilus_file_get_location (file));
- }
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ ret = g_list_prepend (ret, nautilus_file_get_location (file));
+ }
- return g_list_reverse (ret);
+ return g_list_reverse (ret);
}
-typedef struct {
- GHashTable *original_dirs_hash;
- GtkWindow *parent_window;
+typedef struct
+{
+ GHashTable *original_dirs_hash;
+ GtkWindow *parent_window;
} RestoreFilesData;
static void
-ensure_dirs_task_ready_cb (GObject *_source,
- GAsyncResult *res,
- gpointer user_data)
+ensure_dirs_task_ready_cb (GObject *_source,
+ GAsyncResult *res,
+ gpointer user_data)
{
- NautilusFile *original_dir;
- GFile *original_dir_location;
- GList *original_dirs, *files, *locations, *l;
- RestoreFilesData *data = user_data;
+ NautilusFile *original_dir;
+ GFile *original_dir_location;
+ GList *original_dirs, *files, *locations, *l;
+ RestoreFilesData *data = user_data;
- original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
- for (l = original_dirs; l != NULL; l = l->next) {
- original_dir = NAUTILUS_FILE (l->data);
- original_dir_location = nautilus_file_get_location (original_dir);
+ original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
+ for (l = original_dirs; l != NULL; l = l->next)
+ {
+ original_dir = NAUTILUS_FILE (l->data);
+ original_dir_location = nautilus_file_get_location (original_dir);
- files = g_hash_table_lookup (data->original_dirs_hash, original_dir);
- locations = locations_from_file_list (files);
+ files = g_hash_table_lookup (data->original_dirs_hash, original_dir);
+ locations = locations_from_file_list (files);
- nautilus_file_operations_move
- (locations, NULL,
- original_dir_location,
- data->parent_window,
- NULL, NULL);
+ nautilus_file_operations_move
+ (locations, NULL,
+ original_dir_location,
+ data->parent_window,
+ NULL, NULL);
- g_list_free_full (locations, g_object_unref);
- g_object_unref (original_dir_location);
- }
+ g_list_free_full (locations, g_object_unref);
+ g_object_unref (original_dir_location);
+ }
- g_list_free (original_dirs);
+ g_list_free (original_dirs);
- g_hash_table_unref (data->original_dirs_hash);
- g_slice_free (RestoreFilesData, data);
+ g_hash_table_unref (data->original_dirs_hash);
+ g_slice_free (RestoreFilesData, data);
}
static void
-ensure_dirs_task_thread_func (GTask *task,
- gpointer source,
- gpointer task_data,
- GCancellable *cancellable)
+ensure_dirs_task_thread_func (GTask *task,
+ gpointer source,
+ gpointer task_data,
+ GCancellable *cancellable)
{
- RestoreFilesData *data = task_data;
- NautilusFile *original_dir;
- GFile *original_dir_location;
- GList *original_dirs, *l;
+ RestoreFilesData *data = task_data;
+ NautilusFile *original_dir;
+ GFile *original_dir_location;
+ GList *original_dirs, *l;
- original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
- for (l = original_dirs; l != NULL; l = l->next) {
- original_dir = NAUTILUS_FILE (l->data);
- original_dir_location = nautilus_file_get_location (original_dir);
+ original_dirs = g_hash_table_get_keys (data->original_dirs_hash);
+ for (l = original_dirs; l != NULL; l = l->next)
+ {
+ original_dir = NAUTILUS_FILE (l->data);
+ original_dir_location = nautilus_file_get_location (original_dir);
- g_file_make_directory_with_parents (original_dir_location, cancellable, NULL);
- g_object_unref (original_dir_location);
- }
+ g_file_make_directory_with_parents (original_dir_location, cancellable, NULL);
+ g_object_unref (original_dir_location);
+ }
- g_task_return_pointer (task, NULL, NULL);
+ g_task_return_pointer (task, NULL, NULL);
}
static void
restore_files_ensure_parent_directories (GHashTable *original_dirs_hash,
- GtkWindow *parent_window)
+ GtkWindow *parent_window)
{
- RestoreFilesData *data;
- GTask *ensure_dirs_task;
+ RestoreFilesData *data;
+ GTask *ensure_dirs_task;
- data = g_slice_new0 (RestoreFilesData);
- data->parent_window = parent_window;
- data->original_dirs_hash = g_hash_table_ref (original_dirs_hash);
+ data = g_slice_new0 (RestoreFilesData);
+ data->parent_window = parent_window;
+ data->original_dirs_hash = g_hash_table_ref (original_dirs_hash);
- ensure_dirs_task = g_task_new (NULL, NULL, ensure_dirs_task_ready_cb, data);
- g_task_set_task_data (ensure_dirs_task, data, NULL);
- g_task_run_in_thread (ensure_dirs_task, ensure_dirs_task_thread_func);
- g_object_unref (ensure_dirs_task);
+ ensure_dirs_task = g_task_new (NULL, NULL, ensure_dirs_task_ready_cb, data);
+ g_task_set_task_data (ensure_dirs_task, data, NULL);
+ g_task_run_in_thread (ensure_dirs_task, ensure_dirs_task_thread_func);
+ g_object_unref (ensure_dirs_task);
}
void
-nautilus_restore_files_from_trash (GList *files,
- GtkWindow *parent_window)
+nautilus_restore_files_from_trash (GList *files,
+ GtkWindow *parent_window)
{
- NautilusFile *file;
- GHashTable *original_dirs_hash;
- GList *unhandled_files, *l;
- char *message, *file_name;
-
- original_dirs_hash = nautilus_trashed_files_get_original_directories (files, &unhandled_files);
-
- for (l = unhandled_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- file_name = nautilus_file_get_display_name (file);
- message = g_strdup_printf (_("Could not determine original location of “%s” "), file_name);
- g_free (file_name);
-
- eel_show_warning_dialog (message,
- _("The item cannot be restored from trash"),
- parent_window);
- g_free (message);
- }
-
- if (original_dirs_hash != NULL) {
- restore_files_ensure_parent_directories (original_dirs_hash, parent_window);
- g_hash_table_unref (original_dirs_hash);
- }
-
- nautilus_file_list_unref (unhandled_files);
+ NautilusFile *file;
+ GHashTable *original_dirs_hash;
+ GList *unhandled_files, *l;
+ char *message, *file_name;
+
+ original_dirs_hash = nautilus_trashed_files_get_original_directories (files, &unhandled_files);
+
+ for (l = unhandled_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ file_name = nautilus_file_get_display_name (file);
+ message = g_strdup_printf (_("Could not determine original location of “%s” "), file_name);
+ g_free (file_name);
+
+ eel_show_warning_dialog (message,
+ _("The item cannot be restored from trash"),
+ parent_window);
+ g_free (message);
+ }
+
+ if (original_dirs_hash != NULL)
+ {
+ restore_files_ensure_parent_directories (original_dirs_hash, parent_window);
+ g_hash_table_unref (original_dirs_hash);
+ }
+
+ nautilus_file_list_unref (unhandled_files);
}
-typedef struct {
- NautilusMountGetContent callback;
- gpointer user_data;
+typedef struct
+{
+ NautilusMountGetContent callback;
+ gpointer user_data;
} GetContentTypesData;
static void
-get_types_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+get_types_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
{
- GetContentTypesData *data;
- char **types;
-
- data = user_data;
- types = g_mount_guess_content_type_finish (G_MOUNT (source_object), res, NULL);
-
- g_object_set_data_full (source_object,
- "nautilus-content-type-cache",
- g_strdupv (types),
- (GDestroyNotify)g_strfreev);
-
- if (data->callback) {
- data->callback ((const char **) types, data->user_data);
- }
- g_strfreev (types);
- g_slice_free (GetContentTypesData, data);
+ GetContentTypesData *data;
+ char **types;
+
+ data = user_data;
+ types = g_mount_guess_content_type_finish (G_MOUNT (source_object), res, NULL);
+
+ g_object_set_data_full (source_object,
+ "nautilus-content-type-cache",
+ g_strdupv (types),
+ (GDestroyNotify) g_strfreev);
+
+ if (data->callback)
+ {
+ data->callback ((const char **) types, data->user_data);
+ }
+ g_strfreev (types);
+ g_slice_free (GetContentTypesData, data);
}
void
-nautilus_get_x_content_types_for_mount_async (GMount *mount,
- NautilusMountGetContent callback,
- GCancellable *cancellable,
- gpointer user_data)
+nautilus_get_x_content_types_for_mount_async (GMount *mount,
+ NautilusMountGetContent callback,
+ GCancellable *cancellable,
+ gpointer user_data)
{
- char **cached;
- GetContentTypesData *data;
-
- if (mount == NULL) {
- if (callback) {
- callback (NULL, user_data);
- }
- return;
- }
-
- cached = g_object_get_data (G_OBJECT (mount), "nautilus-content-type-cache");
- if (cached != NULL) {
- if (callback) {
- callback ((const char **) cached, user_data);
- }
- return;
- }
-
- data = g_slice_new0 (GetContentTypesData);
- data->callback = callback;
- data->user_data = user_data;
-
- g_mount_guess_content_type (mount,
- FALSE,
- cancellable,
- get_types_cb,
- data);
+ char **cached;
+ GetContentTypesData *data;
+
+ if (mount == NULL)
+ {
+ if (callback)
+ {
+ callback (NULL, user_data);
+ }
+ return;
+ }
+
+ cached = g_object_get_data (G_OBJECT (mount), "nautilus-content-type-cache");
+ if (cached != NULL)
+ {
+ if (callback)
+ {
+ callback ((const char **) cached, user_data);
+ }
+ return;
+ }
+
+ data = g_slice_new0 (GetContentTypesData);
+ data->callback = callback;
+ data->user_data = user_data;
+
+ g_mount_guess_content_type (mount,
+ FALSE,
+ cancellable,
+ get_types_cb,
+ data);
}
char **
nautilus_get_cached_x_content_types_for_mount (GMount *mount)
{
- char **cached;
+ char **cached;
- if (mount == NULL) {
- return NULL;
- }
+ if (mount == NULL)
+ {
+ return NULL;
+ }
- cached = g_object_get_data (G_OBJECT (mount), "nautilus-content-type-cache");
- if (cached != NULL) {
- return g_strdupv (cached);
- }
+ cached = g_object_get_data (G_OBJECT (mount), "nautilus-content-type-cache");
+ if (cached != NULL)
+ {
+ return g_strdupv (cached);
+ }
- return NULL;
+ return NULL;
}
char *
get_message_for_content_type (const char *content_type)
{
- char *message;
- char *description;
-
- description = g_content_type_get_description (content_type);
-
- /* Customize greeting for well-known content types */
- /* translators: these describe the contents of removable media */
- if (strcmp (content_type, "x-content/audio-cdda") == 0) {
- message = g_strdup (_("Audio CD"));
- } else if (strcmp (content_type, "x-content/audio-dvd") == 0) {
- message = g_strdup (_("Audio DVD"));
- } else if (strcmp (content_type, "x-content/video-dvd") == 0) {
- message = g_strdup (_("Video DVD"));
- } else if (strcmp (content_type, "x-content/video-vcd") == 0) {
- message = g_strdup (_("Video CD"));
- } else if (strcmp (content_type, "x-content/video-svcd") == 0) {
- message = g_strdup (_("Super Video CD"));
- } else if (strcmp (content_type, "x-content/image-photocd") == 0) {
- message = g_strdup (_("Photo CD"));
- } else if (strcmp (content_type, "x-content/image-picturecd") == 0) {
- message = g_strdup (_("Picture CD"));
- } else if (strcmp (content_type, "x-content/image-dcf") == 0) {
- message = g_strdup (_("Contains digital photos"));
- } else if (strcmp (content_type, "x-content/audio-player") == 0) {
- message = g_strdup (_("Contains music"));
- } else if (strcmp (content_type, "x-content/unix-software") == 0) {
- message = g_strdup (_("Contains software"));
- } else {
- /* fallback to generic greeting */
- message = g_strdup_printf (_("Detected as “%s”"), description);
- }
-
- g_free (description);
-
- return message;
+ char *message;
+ char *description;
+
+ description = g_content_type_get_description (content_type);
+
+ /* Customize greeting for well-known content types */
+ /* translators: these describe the contents of removable media */
+ if (strcmp (content_type, "x-content/audio-cdda") == 0)
+ {
+ message = g_strdup (_("Audio CD"));
+ }
+ else if (strcmp (content_type, "x-content/audio-dvd") == 0)
+ {
+ message = g_strdup (_("Audio DVD"));
+ }
+ else if (strcmp (content_type, "x-content/video-dvd") == 0)
+ {
+ message = g_strdup (_("Video DVD"));
+ }
+ else if (strcmp (content_type, "x-content/video-vcd") == 0)
+ {
+ message = g_strdup (_("Video CD"));
+ }
+ else if (strcmp (content_type, "x-content/video-svcd") == 0)
+ {
+ message = g_strdup (_("Super Video CD"));
+ }
+ else if (strcmp (content_type, "x-content/image-photocd") == 0)
+ {
+ message = g_strdup (_("Photo CD"));
+ }
+ else if (strcmp (content_type, "x-content/image-picturecd") == 0)
+ {
+ message = g_strdup (_("Picture CD"));
+ }
+ else if (strcmp (content_type, "x-content/image-dcf") == 0)
+ {
+ message = g_strdup (_("Contains digital photos"));
+ }
+ else if (strcmp (content_type, "x-content/audio-player") == 0)
+ {
+ message = g_strdup (_("Contains music"));
+ }
+ else if (strcmp (content_type, "x-content/unix-software") == 0)
+ {
+ message = g_strdup (_("Contains software"));
+ }
+ else
+ {
+ /* fallback to generic greeting */
+ message = g_strdup_printf (_("Detected as “%s”"), description);
+ }
+
+ g_free (description);
+
+ return message;
}
char *
get_message_for_two_content_types (const char * const *content_types)
{
- char *message;
-
- g_assert (content_types[0] != NULL);
- g_assert (content_types[1] != NULL);
-
- /* few combinations make sense */
- if (strcmp (content_types[0], "x-content/image-dcf") == 0
- || strcmp (content_types[1], "x-content/image-dcf") == 0) {
-
- /* translators: these describe the contents of removable media */
- if (strcmp (content_types[0], "x-content/audio-player") == 0) {
- message = g_strdup (_("Contains music and photos"));
- } else if (strcmp (content_types[1], "x-content/audio-player") == 0) {
- message = g_strdup (_("Contains photos and music"));
- } else {
- message = g_strdup (_("Contains digital photos"));
- }
- } else if ((strcmp (content_types[0], "x-content/video-vcd") == 0
- || strcmp (content_types[1], "x-content/video-vcd") == 0)
- && (strcmp (content_types[0], "x-content/video-dvd") == 0
- || strcmp (content_types[1], "x-content/video-dvd") == 0)) {
- message = g_strdup_printf ("%s/%s",
- get_message_for_content_type (content_types[0]),
- get_message_for_content_type (content_types[1]));
- } else {
- message = get_message_for_content_type (content_types[0]);
- }
-
- return message;
+ char *message;
+
+ g_assert (content_types[0] != NULL);
+ g_assert (content_types[1] != NULL);
+
+ /* few combinations make sense */
+ if (strcmp (content_types[0], "x-content/image-dcf") == 0
+ || strcmp (content_types[1], "x-content/image-dcf") == 0)
+ {
+ /* translators: these describe the contents of removable media */
+ if (strcmp (content_types[0], "x-content/audio-player") == 0)
+ {
+ message = g_strdup (_("Contains music and photos"));
+ }
+ else if (strcmp (content_types[1], "x-content/audio-player") == 0)
+ {
+ message = g_strdup (_("Contains photos and music"));
+ }
+ else
+ {
+ message = g_strdup (_("Contains digital photos"));
+ }
+ }
+ else if ((strcmp (content_types[0], "x-content/video-vcd") == 0
+ || strcmp (content_types[1], "x-content/video-vcd") == 0)
+ && (strcmp (content_types[0], "x-content/video-dvd") == 0
+ || strcmp (content_types[1], "x-content/video-dvd") == 0))
+ {
+ message = g_strdup_printf ("%s/%s",
+ get_message_for_content_type (content_types[0]),
+ get_message_for_content_type (content_types[1]));
+ }
+ else
+ {
+ message = get_message_for_content_type (content_types[0]);
+ }
+
+ return message;
}
gboolean
should_handle_content_type (const char *content_type)
{
- GAppInfo *default_app;
+ GAppInfo *default_app;
- default_app = g_app_info_get_default_for_type (content_type, FALSE);
+ default_app = g_app_info_get_default_for_type (content_type, FALSE);
- return !g_str_has_prefix (content_type, "x-content/blank-") &&
- !g_content_type_is_a (content_type, "x-content/win32-software") &&
- default_app != NULL;
+ return !g_str_has_prefix (content_type, "x-content/blank-") &&
+ !g_content_type_is_a (content_type, "x-content/win32-software") &&
+ default_app != NULL;
}
gboolean
-should_handle_content_types (const char * const * content_types)
+should_handle_content_types (const char * const *content_types)
{
- int i;
+ int i;
- for (i = 0; content_types[i] != NULL; i++) {
- if (should_handle_content_type (content_types[i]))
- return TRUE;
+ for (i = 0; content_types[i] != NULL; i++)
+ {
+ if (should_handle_content_type (content_types[i]))
+ {
+ return TRUE;
}
+ }
- return FALSE;
+ return FALSE;
}
gboolean
nautilus_file_selection_equal (GList *selection_a,
- GList *selection_b)
+ GList *selection_b)
{
- GList *al, *bl;
- gboolean selection_matches;
+ GList *al, *bl;
+ gboolean selection_matches;
- if (selection_a == NULL || selection_b == NULL) {
- return (selection_a == selection_b);
- }
-
- if (g_list_length (selection_a) != g_list_length (selection_b)) {
- return FALSE;
- }
-
- selection_matches = TRUE;
+ if (selection_a == NULL || selection_b == NULL)
+ {
+ return (selection_a == selection_b);
+ }
- for (al = selection_a; al; al = al->next) {
- GFile *a_location = nautilus_file_get_location (NAUTILUS_FILE (al->data));
- gboolean found = FALSE;
+ if (g_list_length (selection_a) != g_list_length (selection_b))
+ {
+ return FALSE;
+ }
- for (bl = selection_b; bl; bl = bl->next) {
- GFile *b_location = nautilus_file_get_location (NAUTILUS_FILE (bl->data));
- found = g_file_equal (b_location, a_location);
- g_object_unref (b_location);
+ selection_matches = TRUE;
- if (found) {
- break;
- }
- }
+ for (al = selection_a; al; al = al->next)
+ {
+ GFile *a_location = nautilus_file_get_location (NAUTILUS_FILE (al->data));
+ gboolean found = FALSE;
+
+ for (bl = selection_b; bl; bl = bl->next)
+ {
+ GFile *b_location = nautilus_file_get_location (NAUTILUS_FILE (bl->data));
+ found = g_file_equal (b_location, a_location);
+ g_object_unref (b_location);
+
+ if (found)
+ {
+ break;
+ }
+ }
- selection_matches = found;
- g_object_unref (a_location);
+ selection_matches = found;
+ g_object_unref (a_location);
- if (!selection_matches) {
- break;
- }
- }
+ if (!selection_matches)
+ {
+ break;
+ }
+ }
- return selection_matches;
+ return selection_matches;
}
char *
nautilus_get_common_filename_prefix (GList *file_list,
int min_required_len)
{
- GList *l;
- GList *strs = NULL;
- char *name;
- char *result;
+ GList *l;
+ GList *strs = NULL;
+ char *name;
+ char *result;
- if (file_list == NULL)
- return NULL;
+ if (file_list == NULL)
+ {
+ return NULL;
+ }
- for (l = file_list; l != NULL; l = l->next) {
- g_return_val_if_fail (NAUTILUS_IS_FILE (l->data), NULL);
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ g_return_val_if_fail (NAUTILUS_IS_FILE (l->data), NULL);
- name = nautilus_file_get_display_name (l->data);
- strs = g_list_append (strs, name);
- }
+ name = nautilus_file_get_display_name (l->data);
+ strs = g_list_append (strs, name);
+ }
- result = nautilus_get_common_filename_prefix_from_filenames (strs, min_required_len);
- g_list_free_full (strs, g_free);
+ result = nautilus_get_common_filename_prefix_from_filenames (strs, min_required_len);
+ g_list_free_full (strs, g_free);
- return result;
+ return result;
}
char *
nautilus_get_common_filename_prefix_from_filenames (GList *filenames,
int min_required_len)
{
- char *common_prefix;
- char *truncated;
- int common_prefix_len;
+ char *common_prefix;
+ char *truncated;
+ int common_prefix_len;
- common_prefix = eel_str_get_common_prefix (filenames, min_required_len);
+ common_prefix = eel_str_get_common_prefix (filenames, min_required_len);
- if (common_prefix == NULL)
- return NULL;
+ if (common_prefix == NULL)
+ {
+ return NULL;
+ }
- truncated = eel_filename_strip_extension (common_prefix);
- g_free (common_prefix);
- common_prefix = truncated;
+ truncated = eel_filename_strip_extension (common_prefix);
+ g_free (common_prefix);
+ common_prefix = truncated;
- truncated = eel_str_rtrim_punctuation (common_prefix);
- g_free (common_prefix);
+ truncated = eel_str_rtrim_punctuation (common_prefix);
+ g_free (common_prefix);
- common_prefix_len = g_utf8_strlen (truncated, -1);
- if (common_prefix_len < min_required_len) {
- g_free (truncated);
- return NULL;
- }
+ common_prefix_len = g_utf8_strlen (truncated, -1);
+ if (common_prefix_len < min_required_len)
+ {
+ g_free (truncated);
+ return NULL;
+ }
- return truncated;
+ return truncated;
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
@@ -1201,22 +1331,22 @@ nautilus_self_check_file_utilities (void)
void
nautilus_ensure_extension_builtins (void)
{
- g_type_ensure (NAUTILUS_TYPE_SEARCH_DIRECTORY);
+ g_type_ensure (NAUTILUS_TYPE_SEARCH_DIRECTORY);
}
void
nautilus_ensure_extension_points (void)
{
- static gsize once_init_value = 0;
+ static gsize once_init_value = 0;
- if (g_once_init_enter (&once_init_value))
+ if (g_once_init_enter (&once_init_value))
{
- GIOExtensionPoint *extension_point;
+ GIOExtensionPoint *extension_point;
- extension_point = g_io_extension_point_register (NAUTILUS_DIRECTORY_PROVIDER_EXTENSION_POINT_NAME);
- g_io_extension_point_set_required_type (extension_point, NAUTILUS_TYPE_DIRECTORY);
+ extension_point = g_io_extension_point_register (NAUTILUS_DIRECTORY_PROVIDER_EXTENSION_POINT_NAME);
+ g_io_extension_point_set_required_type (extension_point, NAUTILUS_TYPE_DIRECTORY);
- g_once_init_leave (&once_init_value, 1);
+ g_once_init_leave (&once_init_value, 1);
}
}
@@ -1228,11 +1358,14 @@ nautilus_file_can_rename_files (GList *files)
GList *l;
NautilusFile *file;
- for (l = files; l != NULL; l = l->next) {
+ for (l = files; l != NULL; l = l->next)
+ {
file = NAUTILUS_FILE (l->data);
if (!nautilus_file_can_rename (file))
+ {
return FALSE;
+ }
}
return TRUE;
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index c68753e98..32d2af88a 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -1,23 +1,23 @@
/*
- nautilus-file.c: Nautilus file model.
-
- Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * nautilus-file.c: Nautilus file model.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
#include "nautilus-file.h"
@@ -71,7 +71,7 @@
#include "nautilus-debug.h"
/* Time in seconds to cache getpwuid results */
-#define GETPWUID_CACHE_TIME (5*60)
+#define GETPWUID_CACHE_TIME (5 * 60)
#define ICON_NAME_THUMBNAIL_LOADING "image-loading"
@@ -92,24 +92,28 @@
/* Name of Nautilus trash directories */
#define TRASH_DIRECTORY_NAME ".Trash"
-#define METADATA_ID_IS_LIST_MASK (1<<31)
+#define METADATA_ID_IS_LIST_MASK (1 << 31)
-typedef enum {
- SHOW_HIDDEN = 1 << 0,
+typedef enum
+{
+ SHOW_HIDDEN = 1 << 0,
} FilterOptions;
-typedef enum {
- NAUTILUS_DATE_FORMAT_REGULAR = 0,
- NAUTILUS_DATE_FORMAT_REGULAR_WITH_TIME = 1,
- NAUTILUS_DATE_FORMAT_FULL = 2,
+typedef enum
+{
+ NAUTILUS_DATE_FORMAT_REGULAR = 0,
+ NAUTILUS_DATE_FORMAT_REGULAR_WITH_TIME = 1,
+ NAUTILUS_DATE_FORMAT_FULL = 2,
} NautilusDateFormat;
-typedef void (* ModifyListFunction) (GList **list, NautilusFile *file);
+typedef void (*ModifyListFunction) (GList **list,
+ NautilusFile *file);
-enum {
- CHANGED,
- UPDATED_DEEP_COUNT_IN_PROGRESS,
- LAST_SIGNAL
+enum
+{
+ CHANGED,
+ UPDATED_DEEP_COUNT_IN_PROGRESS,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -123,837 +127,927 @@ static NautilusSpeedTradeoffValue show_file_thumbs;
static NautilusSpeedTradeoffValue show_directory_item_count;
static GQuark attribute_name_q,
- attribute_size_q,
- attribute_type_q,
- attribute_detailed_type_q,
- attribute_modification_date_q,
- attribute_date_modified_q,
- attribute_date_modified_full_q,
- attribute_date_modified_with_time_q,
- attribute_accessed_date_q,
- attribute_date_accessed_q,
- attribute_date_accessed_full_q,
- attribute_mime_type_q,
- attribute_size_detail_q,
- attribute_deep_size_q,
- attribute_deep_file_count_q,
- attribute_deep_directory_count_q,
- attribute_deep_total_count_q,
- attribute_search_relevance_q,
- attribute_trashed_on_q,
- attribute_trashed_on_full_q,
- attribute_trash_orig_path_q,
- attribute_permissions_q,
- attribute_selinux_context_q,
- attribute_octal_permissions_q,
- attribute_owner_q,
- attribute_group_q,
- attribute_uri_q,
- attribute_where_q,
- attribute_link_target_q,
- attribute_volume_q,
- attribute_free_space_q;
-
-static void nautilus_file_info_iface_init (NautilusFileInfoIface *iface);
-static char * nautilus_file_get_owner_as_string (NautilusFile *file,
- gboolean include_real_name);
-static char * nautilus_file_get_type_as_string (NautilusFile *file);
-static char * nautilus_file_get_detailed_type_as_string (NautilusFile *file);
-static gboolean update_info_and_name (NautilusFile *file,
- GFileInfo *info);
-static const char * nautilus_file_peek_display_name (NautilusFile *file);
-static const char * nautilus_file_peek_display_name_collation_key (NautilusFile *file);
-static void file_mount_unmounted (GMount *mount, gpointer data);
+ attribute_size_q,
+ attribute_type_q,
+ attribute_detailed_type_q,
+ attribute_modification_date_q,
+ attribute_date_modified_q,
+ attribute_date_modified_full_q,
+ attribute_date_modified_with_time_q,
+ attribute_accessed_date_q,
+ attribute_date_accessed_q,
+ attribute_date_accessed_full_q,
+ attribute_mime_type_q,
+ attribute_size_detail_q,
+ attribute_deep_size_q,
+ attribute_deep_file_count_q,
+ attribute_deep_directory_count_q,
+ attribute_deep_total_count_q,
+ attribute_search_relevance_q,
+ attribute_trashed_on_q,
+ attribute_trashed_on_full_q,
+ attribute_trash_orig_path_q,
+ attribute_permissions_q,
+ attribute_selinux_context_q,
+ attribute_octal_permissions_q,
+ attribute_owner_q,
+ attribute_group_q,
+ attribute_uri_q,
+ attribute_where_q,
+ attribute_link_target_q,
+ attribute_volume_q,
+ attribute_free_space_q;
+
+static void nautilus_file_info_iface_init (NautilusFileInfoIface *iface);
+static char *nautilus_file_get_owner_as_string (NautilusFile *file,
+ gboolean include_real_name);
+static char *nautilus_file_get_type_as_string (NautilusFile *file);
+static char *nautilus_file_get_detailed_type_as_string (NautilusFile *file);
+static gboolean update_info_and_name (NautilusFile *file,
+ GFileInfo *info);
+static const char *nautilus_file_peek_display_name (NautilusFile *file);
+static const char *nautilus_file_peek_display_name_collation_key (NautilusFile *file);
+static void file_mount_unmounted (GMount *mount,
+ gpointer data);
static void metadata_hash_free (GHashTable *hash);
static gboolean real_drag_can_accept_files (NautilusFile *drop_target_item);
G_DEFINE_TYPE_WITH_CODE (NautilusFile, nautilus_file, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_FILE_INFO,
- nautilus_file_info_iface_init));
+ G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_FILE_INFO,
+ nautilus_file_info_iface_init));
static void
nautilus_file_init (NautilusFile *file)
{
- file->details = G_TYPE_INSTANCE_GET_PRIVATE ((file), NAUTILUS_TYPE_FILE, NautilusFileDetails);
+ file->details = G_TYPE_INSTANCE_GET_PRIVATE ((file), NAUTILUS_TYPE_FILE, NautilusFileDetails);
- nautilus_file_clear_info (file);
- nautilus_file_invalidate_extension_info_internal (file);
+ nautilus_file_clear_info (file);
+ nautilus_file_invalidate_extension_info_internal (file);
- file->details->free_space = -1;
+ file->details->free_space = -1;
}
-static GObject*
+static GObject *
nautilus_file_constructor (GType type,
- guint n_construct_properties,
- GObjectConstructParam *construct_params)
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
{
- GObject *object;
- NautilusFile *file;
+ GObject *object;
+ NautilusFile *file;
+
+ object = (*G_OBJECT_CLASS (nautilus_file_parent_class)->constructor)(type,
+ n_construct_properties,
+ construct_params);
- object = (* G_OBJECT_CLASS (nautilus_file_parent_class)->constructor) (type,
- n_construct_properties,
- construct_params);
+ file = NAUTILUS_FILE (object);
- file = NAUTILUS_FILE (object);
+ /* Set to default type after full construction */
+ if (NAUTILUS_FILE_GET_CLASS (file)->default_file_type != G_FILE_TYPE_UNKNOWN)
+ {
+ file->details->type = NAUTILUS_FILE_GET_CLASS (file)->default_file_type;
+ }
- /* Set to default type after full construction */
- if (NAUTILUS_FILE_GET_CLASS (file)->default_file_type != G_FILE_TYPE_UNKNOWN) {
- file->details->type = NAUTILUS_FILE_GET_CLASS (file)->default_file_type;
- }
-
- return object;
+ return object;
}
gboolean
nautilus_file_set_display_name (NautilusFile *file,
- const char *display_name,
- const char *edit_name,
- gboolean custom)
-{
- gboolean changed;
-
- if (custom && display_name == NULL) {
- /* We're re-setting a custom display name, invalidate it if
- we already set it so that the old one is re-read */
- if (file->details->got_custom_display_name) {
- file->details->got_custom_display_name = FALSE;
- nautilus_file_invalidate_attributes (file,
- NAUTILUS_FILE_ATTRIBUTE_INFO);
- }
- return FALSE;
- }
-
- if (display_name == NULL || *display_name == 0) {
- return FALSE;
- }
-
- if (!custom && file->details->got_custom_display_name) {
- return FALSE;
- }
-
- if (edit_name == NULL) {
- edit_name = display_name;
- }
-
- changed = FALSE;
-
- if (g_strcmp0 (eel_ref_str_peek (file->details->display_name), display_name) != 0) {
- changed = TRUE;
-
- eel_ref_str_unref (file->details->display_name);
-
- if (g_strcmp0 (eel_ref_str_peek (file->details->name), display_name) == 0) {
- file->details->display_name = eel_ref_str_ref (file->details->name);
- } else {
- file->details->display_name = eel_ref_str_new (display_name);
- }
-
- g_free (file->details->display_name_collation_key);
- file->details->display_name_collation_key = g_utf8_collate_key_for_filename (display_name, -1);
- }
-
- if (g_strcmp0 (eel_ref_str_peek (file->details->edit_name), edit_name) != 0) {
- changed = TRUE;
-
- eel_ref_str_unref (file->details->edit_name);
- if (g_strcmp0 (eel_ref_str_peek (file->details->display_name), edit_name) == 0) {
- file->details->edit_name = eel_ref_str_ref (file->details->display_name);
- } else {
- file->details->edit_name = eel_ref_str_new (edit_name);
- }
- }
-
- file->details->got_custom_display_name = custom;
- return changed;
+ const char *display_name,
+ const char *edit_name,
+ gboolean custom)
+{
+ gboolean changed;
+
+ if (custom && display_name == NULL)
+ {
+ /* We're re-setting a custom display name, invalidate it if
+ * we already set it so that the old one is re-read */
+ if (file->details->got_custom_display_name)
+ {
+ file->details->got_custom_display_name = FALSE;
+ nautilus_file_invalidate_attributes (file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO);
+ }
+ return FALSE;
+ }
+
+ if (display_name == NULL || *display_name == 0)
+ {
+ return FALSE;
+ }
+
+ if (!custom && file->details->got_custom_display_name)
+ {
+ return FALSE;
+ }
+
+ if (edit_name == NULL)
+ {
+ edit_name = display_name;
+ }
+
+ changed = FALSE;
+
+ if (g_strcmp0 (eel_ref_str_peek (file->details->display_name), display_name) != 0)
+ {
+ changed = TRUE;
+
+ eel_ref_str_unref (file->details->display_name);
+
+ if (g_strcmp0 (eel_ref_str_peek (file->details->name), display_name) == 0)
+ {
+ file->details->display_name = eel_ref_str_ref (file->details->name);
+ }
+ else
+ {
+ file->details->display_name = eel_ref_str_new (display_name);
+ }
+
+ g_free (file->details->display_name_collation_key);
+ file->details->display_name_collation_key = g_utf8_collate_key_for_filename (display_name, -1);
+ }
+
+ if (g_strcmp0 (eel_ref_str_peek (file->details->edit_name), edit_name) != 0)
+ {
+ changed = TRUE;
+
+ eel_ref_str_unref (file->details->edit_name);
+ if (g_strcmp0 (eel_ref_str_peek (file->details->display_name), edit_name) == 0)
+ {
+ file->details->edit_name = eel_ref_str_ref (file->details->display_name);
+ }
+ else
+ {
+ file->details->edit_name = eel_ref_str_new (edit_name);
+ }
+ }
+
+ file->details->got_custom_display_name = custom;
+ return changed;
}
static void
nautilus_file_clear_display_name (NautilusFile *file)
{
- eel_ref_str_unref (file->details->display_name);
- file->details->display_name = NULL;
- g_free (file->details->display_name_collation_key);
- file->details->display_name_collation_key = NULL;
- eel_ref_str_unref (file->details->edit_name);
- file->details->edit_name = NULL;
+ eel_ref_str_unref (file->details->display_name);
+ file->details->display_name = NULL;
+ g_free (file->details->display_name_collation_key);
+ file->details->display_name_collation_key = NULL;
+ eel_ref_str_unref (file->details->edit_name);
+ file->details->edit_name = NULL;
}
static gboolean
-foreach_metadata_free (gpointer key,
- gpointer value,
- gpointer user_data)
+foreach_metadata_free (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- guint id;
+ guint id;
- id = GPOINTER_TO_UINT (key);
+ id = GPOINTER_TO_UINT (key);
- if (id & METADATA_ID_IS_LIST_MASK) {
- g_strfreev ((char **)value);
- } else {
- g_free ((char *)value);
- }
- return TRUE;
+ if (id & METADATA_ID_IS_LIST_MASK)
+ {
+ g_strfreev ((char **) value);
+ }
+ else
+ {
+ g_free ((char *) value);
+ }
+ return TRUE;
}
static void
metadata_hash_free (GHashTable *hash)
{
- g_hash_table_foreach_remove (hash,
- foreach_metadata_free,
- NULL);
- g_hash_table_destroy (hash);
+ g_hash_table_foreach_remove (hash,
+ foreach_metadata_free,
+ NULL);
+ g_hash_table_destroy (hash);
}
static gboolean
metadata_hash_equal (GHashTable *hash1,
- GHashTable *hash2)
-{
- GHashTableIter iter;
- gpointer key1, value1, value2;
- guint id;
-
- if (hash1 == NULL && hash2 == NULL) {
- return TRUE;
- }
-
- if (hash1 == NULL || hash2 == NULL) {
- return FALSE;
- }
-
- if (g_hash_table_size (hash1) !=
- g_hash_table_size (hash2)) {
- return FALSE;
- }
-
- g_hash_table_iter_init (&iter, hash1);
- while (g_hash_table_iter_next (&iter, &key1, &value1)) {
- value2 = g_hash_table_lookup (hash2, key1);
- if (value2 == NULL) {
- return FALSE;
- }
- id = GPOINTER_TO_UINT (key1);
- if (id & METADATA_ID_IS_LIST_MASK) {
- if (!eel_g_strv_equal ((char **)value1, (char **)value2)) {
- return FALSE;
- }
- } else {
- if (strcmp ((char *)value1, (char *)value2) != 0) {
- return FALSE;
- }
- }
- }
-
- return TRUE;
+ GHashTable *hash2)
+{
+ GHashTableIter iter;
+ gpointer key1, value1, value2;
+ guint id;
+
+ if (hash1 == NULL && hash2 == NULL)
+ {
+ return TRUE;
+ }
+
+ if (hash1 == NULL || hash2 == NULL)
+ {
+ return FALSE;
+ }
+
+ if (g_hash_table_size (hash1) !=
+ g_hash_table_size (hash2))
+ {
+ return FALSE;
+ }
+
+ g_hash_table_iter_init (&iter, hash1);
+ while (g_hash_table_iter_next (&iter, &key1, &value1))
+ {
+ value2 = g_hash_table_lookup (hash2, key1);
+ if (value2 == NULL)
+ {
+ return FALSE;
+ }
+ id = GPOINTER_TO_UINT (key1);
+ if (id & METADATA_ID_IS_LIST_MASK)
+ {
+ if (!eel_g_strv_equal ((char **) value1, (char **) value2))
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ if (strcmp ((char *) value1, (char *) value2) != 0)
+ {
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
}
static void
clear_metadata (NautilusFile *file)
{
- if (file->details->metadata) {
- metadata_hash_free (file->details->metadata);
- file->details->metadata = NULL;
- }
+ if (file->details->metadata)
+ {
+ metadata_hash_free (file->details->metadata);
+ file->details->metadata = NULL;
+ }
}
static GHashTable *
get_metadata_from_info (GFileInfo *info)
{
- GHashTable *metadata;
- char **attrs;
- guint id;
- int i;
- GFileAttributeType type;
- gpointer value;
+ GHashTable *metadata;
+ char **attrs;
+ guint id;
+ int i;
+ GFileAttributeType type;
+ gpointer value;
- attrs = g_file_info_list_attributes (info, "metadata");
+ attrs = g_file_info_list_attributes (info, "metadata");
- metadata = g_hash_table_new (NULL, NULL);
+ metadata = g_hash_table_new (NULL, NULL);
- for (i = 0; attrs[i] != NULL; i++) {
- id = nautilus_metadata_get_id (attrs[i] + strlen ("metadata::"));
- if (id == 0) {
- continue;
- }
+ for (i = 0; attrs[i] != NULL; i++)
+ {
+ id = nautilus_metadata_get_id (attrs[i] + strlen ("metadata::"));
+ if (id == 0)
+ {
+ continue;
+ }
- if (!g_file_info_get_attribute_data (info, attrs[i],
- &type, &value, NULL)) {
- continue;
- }
+ if (!g_file_info_get_attribute_data (info, attrs[i],
+ &type, &value, NULL))
+ {
+ continue;
+ }
- if (type == G_FILE_ATTRIBUTE_TYPE_STRING) {
- g_hash_table_insert (metadata, GUINT_TO_POINTER (id),
- g_strdup ((char *)value));
- } else if (type == G_FILE_ATTRIBUTE_TYPE_STRINGV) {
- id |= METADATA_ID_IS_LIST_MASK;
- g_hash_table_insert (metadata, GUINT_TO_POINTER (id),
- g_strdupv ((char **)value));
- }
- }
+ if (type == G_FILE_ATTRIBUTE_TYPE_STRING)
+ {
+ g_hash_table_insert (metadata, GUINT_TO_POINTER (id),
+ g_strdup ((char *) value));
+ }
+ else if (type == G_FILE_ATTRIBUTE_TYPE_STRINGV)
+ {
+ id |= METADATA_ID_IS_LIST_MASK;
+ g_hash_table_insert (metadata, GUINT_TO_POINTER (id),
+ g_strdupv ((char **) value));
+ }
+ }
- g_strfreev (attrs);
+ g_strfreev (attrs);
- return metadata;
+ return metadata;
}
gboolean
nautilus_file_update_metadata_from_info (NautilusFile *file,
- GFileInfo *info)
+ GFileInfo *info)
{
- gboolean changed = FALSE;
+ gboolean changed = FALSE;
- if (g_file_info_has_namespace (info, "metadata")) {
- GHashTable *metadata;
+ if (g_file_info_has_namespace (info, "metadata"))
+ {
+ GHashTable *metadata;
- metadata = get_metadata_from_info (info);
- if (!metadata_hash_equal (metadata,
- file->details->metadata)) {
- changed = TRUE;
- clear_metadata (file);
- file->details->metadata = metadata;
- } else {
- metadata_hash_free (metadata);
- }
- } else if (file->details->metadata) {
- changed = TRUE;
- clear_metadata (file);
- }
- return changed;
+ metadata = get_metadata_from_info (info);
+ if (!metadata_hash_equal (metadata,
+ file->details->metadata))
+ {
+ changed = TRUE;
+ clear_metadata (file);
+ file->details->metadata = metadata;
+ }
+ else
+ {
+ metadata_hash_free (metadata);
+ }
+ }
+ else if (file->details->metadata)
+ {
+ changed = TRUE;
+ clear_metadata (file);
+ }
+ return changed;
}
void
nautilus_file_clear_info (NautilusFile *file)
{
- file->details->got_file_info = FALSE;
- if (file->details->get_info_error) {
- g_error_free (file->details->get_info_error);
- file->details->get_info_error = NULL;
- }
- /* Reset to default type, which might be other than unknown for
- special kinds of files like the desktop or a search directory */
- file->details->type = NAUTILUS_FILE_GET_CLASS (file)->default_file_type;
-
- if (!file->details->got_custom_display_name) {
- nautilus_file_clear_display_name (file);
- }
-
- if (!file->details->got_custom_activation_uri &&
- file->details->activation_uri != NULL) {
- g_free (file->details->activation_uri);
- file->details->activation_uri = NULL;
- }
-
- if (file->details->icon != NULL) {
- g_object_unref (file->details->icon);
- file->details->icon = NULL;
- }
-
- g_free (file->details->thumbnail_path);
- file->details->thumbnail_path = NULL;
- file->details->thumbnailing_failed = FALSE;
-
- file->details->is_launcher = FALSE;
- file->details->is_foreign_link = FALSE;
- file->details->is_trusted_link = FALSE;
- file->details->is_symlink = FALSE;
- file->details->is_hidden = FALSE;
- file->details->is_mountpoint = FALSE;
- file->details->uid = -1;
- file->details->gid = -1;
- file->details->can_read = TRUE;
- file->details->can_write = TRUE;
- file->details->can_execute = TRUE;
- file->details->can_delete = TRUE;
- file->details->can_trash = TRUE;
- file->details->can_rename = TRUE;
- file->details->can_mount = FALSE;
- file->details->can_unmount = FALSE;
- file->details->can_eject = FALSE;
- file->details->can_start = FALSE;
- file->details->can_start_degraded = FALSE;
- file->details->can_stop = FALSE;
- file->details->start_stop_type = G_DRIVE_START_STOP_TYPE_UNKNOWN;
- file->details->can_poll_for_media = FALSE;
- file->details->is_media_check_automatic = FALSE;
- file->details->has_permissions = FALSE;
- file->details->permissions = 0;
- file->details->size = -1;
- file->details->sort_order = 0;
- file->details->mtime = 0;
- file->details->atime = 0;
- file->details->trash_time = 0;
- g_free (file->details->symlink_name);
- file->details->symlink_name = NULL;
- eel_ref_str_unref (file->details->mime_type);
- file->details->mime_type = NULL;
- g_free (file->details->selinux_context);
- file->details->selinux_context = NULL;
- g_free (file->details->description);
- file->details->description = NULL;
- eel_ref_str_unref (file->details->owner);
- file->details->owner = NULL;
- eel_ref_str_unref (file->details->owner_real);
- file->details->owner_real = NULL;
- eel_ref_str_unref (file->details->group);
- file->details->group = NULL;
-
- eel_ref_str_unref (file->details->filesystem_id);
- file->details->filesystem_id = NULL;
-
- clear_metadata (file);
+ file->details->got_file_info = FALSE;
+ if (file->details->get_info_error)
+ {
+ g_error_free (file->details->get_info_error);
+ file->details->get_info_error = NULL;
+ }
+ /* Reset to default type, which might be other than unknown for
+ * special kinds of files like the desktop or a search directory */
+ file->details->type = NAUTILUS_FILE_GET_CLASS (file)->default_file_type;
+
+ if (!file->details->got_custom_display_name)
+ {
+ nautilus_file_clear_display_name (file);
+ }
+
+ if (!file->details->got_custom_activation_uri &&
+ file->details->activation_uri != NULL)
+ {
+ g_free (file->details->activation_uri);
+ file->details->activation_uri = NULL;
+ }
+
+ if (file->details->icon != NULL)
+ {
+ g_object_unref (file->details->icon);
+ file->details->icon = NULL;
+ }
+
+ g_free (file->details->thumbnail_path);
+ file->details->thumbnail_path = NULL;
+ file->details->thumbnailing_failed = FALSE;
+
+ file->details->is_launcher = FALSE;
+ file->details->is_foreign_link = FALSE;
+ file->details->is_trusted_link = FALSE;
+ file->details->is_symlink = FALSE;
+ file->details->is_hidden = FALSE;
+ file->details->is_mountpoint = FALSE;
+ file->details->uid = -1;
+ file->details->gid = -1;
+ file->details->can_read = TRUE;
+ file->details->can_write = TRUE;
+ file->details->can_execute = TRUE;
+ file->details->can_delete = TRUE;
+ file->details->can_trash = TRUE;
+ file->details->can_rename = TRUE;
+ file->details->can_mount = FALSE;
+ file->details->can_unmount = FALSE;
+ file->details->can_eject = FALSE;
+ file->details->can_start = FALSE;
+ file->details->can_start_degraded = FALSE;
+ file->details->can_stop = FALSE;
+ file->details->start_stop_type = G_DRIVE_START_STOP_TYPE_UNKNOWN;
+ file->details->can_poll_for_media = FALSE;
+ file->details->is_media_check_automatic = FALSE;
+ file->details->has_permissions = FALSE;
+ file->details->permissions = 0;
+ file->details->size = -1;
+ file->details->sort_order = 0;
+ file->details->mtime = 0;
+ file->details->atime = 0;
+ file->details->trash_time = 0;
+ g_free (file->details->symlink_name);
+ file->details->symlink_name = NULL;
+ eel_ref_str_unref (file->details->mime_type);
+ file->details->mime_type = NULL;
+ g_free (file->details->selinux_context);
+ file->details->selinux_context = NULL;
+ g_free (file->details->description);
+ file->details->description = NULL;
+ eel_ref_str_unref (file->details->owner);
+ file->details->owner = NULL;
+ eel_ref_str_unref (file->details->owner_real);
+ file->details->owner_real = NULL;
+ eel_ref_str_unref (file->details->group);
+ file->details->group = NULL;
+
+ eel_ref_str_unref (file->details->filesystem_id);
+ file->details->filesystem_id = NULL;
+
+ clear_metadata (file);
}
void
-nautilus_file_set_directory (NautilusFile *file,
- NautilusDirectory *directory)
+nautilus_file_set_directory (NautilusFile *file,
+ NautilusDirectory *directory)
{
- char *parent_uri;
+ char *parent_uri;
- g_clear_object (&file->details->directory);
- g_free (file->details->directory_name_collation_key);
+ g_clear_object (&file->details->directory);
+ g_free (file->details->directory_name_collation_key);
- file->details->directory = nautilus_directory_ref (directory);
+ file->details->directory = nautilus_directory_ref (directory);
- parent_uri = nautilus_file_get_parent_uri (file);
- file->details->directory_name_collation_key = g_utf8_collate_key_for_filename (parent_uri, -1);
- g_free (parent_uri);
+ parent_uri = nautilus_file_get_parent_uri (file);
+ file->details->directory_name_collation_key = g_utf8_collate_key_for_filename (parent_uri, -1);
+ g_free (parent_uri);
}
static NautilusFile *
nautilus_file_new_from_filename (NautilusDirectory *directory,
- const char *filename,
- gboolean self_owned)
+ const char *filename,
+ gboolean self_owned)
{
- NautilusFile *file;
+ NautilusFile *file;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
- g_assert (filename != NULL);
- g_assert (filename[0] != '\0');
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (filename != NULL);
+ g_assert (filename[0] != '\0');
- file = nautilus_directory_new_file_from_filename (directory, filename, self_owned);
- file->details->name = eel_ref_str_new (filename);
+ file = nautilus_directory_new_file_from_filename (directory, filename, self_owned);
+ file->details->name = eel_ref_str_new (filename);
#ifdef NAUTILUS_FILE_DEBUG_REF
- DEBUG_REF_PRINTF("%10p ref'd", file);
+ DEBUG_REF_PRINTF ("%10p ref'd", file);
#endif
- return file;
+ return file;
}
static void
-modify_link_hash_table (NautilusFile *file,
- ModifyListFunction modify_function)
-{
- char *target_uri;
- gboolean found;
- gpointer original_key;
- GList **list_ptr;
-
- /* Check if there is a symlink name. If none, we are OK. */
- if (file->details->symlink_name == NULL || !nautilus_file_is_symbolic_link (file)) {
- return;
- }
-
- /* Create the hash table first time through. */
- if (symbolic_links == NULL) {
- symbolic_links = g_hash_table_new (g_str_hash, g_str_equal);
- }
-
- target_uri = nautilus_file_get_symbolic_link_target_uri (file);
-
- /* Find the old contents of the hash table. */
- found = g_hash_table_lookup_extended
- (symbolic_links, target_uri,
- &original_key, (gpointer *)&list_ptr);
- if (!found) {
- list_ptr = g_new0 (GList *, 1);
- original_key = g_strdup (target_uri);
- g_hash_table_insert (symbolic_links, original_key, list_ptr);
- }
- (* modify_function) (list_ptr, file);
- if (*list_ptr == NULL) {
- g_hash_table_remove (symbolic_links, target_uri);
- g_free (list_ptr);
- g_free (original_key);
- }
- g_free (target_uri);
+modify_link_hash_table (NautilusFile *file,
+ ModifyListFunction modify_function)
+{
+ char *target_uri;
+ gboolean found;
+ gpointer original_key;
+ GList **list_ptr;
+
+ /* Check if there is a symlink name. If none, we are OK. */
+ if (file->details->symlink_name == NULL || !nautilus_file_is_symbolic_link (file))
+ {
+ return;
+ }
+
+ /* Create the hash table first time through. */
+ if (symbolic_links == NULL)
+ {
+ symbolic_links = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ target_uri = nautilus_file_get_symbolic_link_target_uri (file);
+
+ /* Find the old contents of the hash table. */
+ found = g_hash_table_lookup_extended
+ (symbolic_links, target_uri,
+ &original_key, (gpointer *) &list_ptr);
+ if (!found)
+ {
+ list_ptr = g_new0 (GList *, 1);
+ original_key = g_strdup (target_uri);
+ g_hash_table_insert (symbolic_links, original_key, list_ptr);
+ }
+ (*modify_function)(list_ptr, file);
+ if (*list_ptr == NULL)
+ {
+ g_hash_table_remove (symbolic_links, target_uri);
+ g_free (list_ptr);
+ g_free (original_key);
+ }
+ g_free (target_uri);
}
static void
-symbolic_link_weak_notify (gpointer data,
- GObject *where_the_object_was)
+symbolic_link_weak_notify (gpointer data,
+ GObject *where_the_object_was)
{
- GList **list = data;
- /* This really shouldn't happen, but we're seeing some strange things in
- bug #358172 where the symlink hashtable isn't correctly updated. */
- *list = g_list_remove (*list, where_the_object_was);
+ GList **list = data;
+ /* This really shouldn't happen, but we're seeing some strange things in
+ * bug #358172 where the symlink hashtable isn't correctly updated. */
+ *list = g_list_remove (*list, where_the_object_was);
}
static void
-add_to_link_hash_table_list (GList **list, NautilusFile *file)
+add_to_link_hash_table_list (GList **list,
+ NautilusFile *file)
{
- if (g_list_find (*list, file) != NULL) {
- g_warning ("Adding file to symlink_table multiple times. "
- "Please add feedback of what you were doing at http://bugzilla.gnome.org/show_bug.cgi?id=358172\n");
- return;
- }
- g_object_weak_ref (G_OBJECT (file), symbolic_link_weak_notify, list);
- *list = g_list_prepend (*list, file);
+ if (g_list_find (*list, file) != NULL)
+ {
+ g_warning ("Adding file to symlink_table multiple times. "
+ "Please add feedback of what you were doing at http://bugzilla.gnome.org/show_bug.cgi?id=358172\n");
+ return;
+ }
+ g_object_weak_ref (G_OBJECT (file), symbolic_link_weak_notify, list);
+ *list = g_list_prepend (*list, file);
}
static void
add_to_link_hash_table (NautilusFile *file)
{
- modify_link_hash_table (file, add_to_link_hash_table_list);
+ modify_link_hash_table (file, add_to_link_hash_table_list);
}
static void
-remove_from_link_hash_table_list (GList **list, NautilusFile *file)
+remove_from_link_hash_table_list (GList **list,
+ NautilusFile *file)
{
- if (g_list_find (*list, file) != NULL) {
- g_object_weak_unref (G_OBJECT (file), symbolic_link_weak_notify, list);
- *list = g_list_remove (*list, file);
- }
+ if (g_list_find (*list, file) != NULL)
+ {
+ g_object_weak_unref (G_OBJECT (file), symbolic_link_weak_notify, list);
+ *list = g_list_remove (*list, file);
+ }
}
static void
remove_from_link_hash_table (NautilusFile *file)
{
- modify_link_hash_table (file, remove_from_link_hash_table_list);
+ modify_link_hash_table (file, remove_from_link_hash_table_list);
}
NautilusFile *
nautilus_file_new_from_info (NautilusDirectory *directory,
- GFileInfo *info)
+ GFileInfo *info)
{
- NautilusFile *file;
+ NautilusFile *file;
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
- g_return_val_if_fail (info != NULL, NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+ g_return_val_if_fail (info != NULL, NULL);
- file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
- nautilus_file_set_directory (file, directory);
+ file = NAUTILUS_FILE (g_object_new (NAUTILUS_TYPE_VFS_FILE, NULL));
+ nautilus_file_set_directory (file, directory);
- update_info_and_name (file, info);
+ update_info_and_name (file, info);
#ifdef NAUTILUS_FILE_DEBUG_REF
- DEBUG_REF_PRINTF("%10p ref'd", file);
+ DEBUG_REF_PRINTF ("%10p ref'd", file);
#endif
- return file;
+ return file;
}
static NautilusFile *
-nautilus_file_get_internal (GFile *location, gboolean create)
-{
- gboolean self_owned;
- NautilusDirectory *directory;
- NautilusFile *file;
- GFile *parent;
- char *basename;
-
- g_assert (location != NULL);
-
- parent = g_file_get_parent (location);
-
- self_owned = FALSE;
- if (parent == NULL) {
- self_owned = TRUE;
- parent = g_object_ref (location);
- }
-
- /* Get object that represents the directory. */
- directory = nautilus_directory_get_internal (parent, create);
-
- g_object_unref (parent);
-
- /* Get the name for the file. */
- if (self_owned && directory != NULL) {
- basename = nautilus_directory_get_name_for_self_as_new_file (directory);
- } else {
- basename = g_file_get_basename (location);
- }
- /* Check to see if it's a file that's already known. */
- if (directory == NULL) {
- file = NULL;
- } else if (self_owned) {
- file = directory->details->as_file;
- } else {
- file = nautilus_directory_find_file_by_name (directory, basename);
- }
-
- /* Ref or create the file. */
- if (file != NULL) {
- nautilus_file_ref (file);
- } else if (create) {
- file = nautilus_file_new_from_filename (directory, basename, self_owned);
- if (self_owned) {
- g_assert (directory->details->as_file == NULL);
- directory->details->as_file = file;
- } else {
- nautilus_directory_add_file (directory, file);
- }
- }
-
- g_free (basename);
- nautilus_directory_unref (directory);
-
- return file;
+nautilus_file_get_internal (GFile *location,
+ gboolean create)
+{
+ gboolean self_owned;
+ NautilusDirectory *directory;
+ NautilusFile *file;
+ GFile *parent;
+ char *basename;
+
+ g_assert (location != NULL);
+
+ parent = g_file_get_parent (location);
+
+ self_owned = FALSE;
+ if (parent == NULL)
+ {
+ self_owned = TRUE;
+ parent = g_object_ref (location);
+ }
+
+ /* Get object that represents the directory. */
+ directory = nautilus_directory_get_internal (parent, create);
+
+ g_object_unref (parent);
+
+ /* Get the name for the file. */
+ if (self_owned && directory != NULL)
+ {
+ basename = nautilus_directory_get_name_for_self_as_new_file (directory);
+ }
+ else
+ {
+ basename = g_file_get_basename (location);
+ }
+ /* Check to see if it's a file that's already known. */
+ if (directory == NULL)
+ {
+ file = NULL;
+ }
+ else if (self_owned)
+ {
+ file = directory->details->as_file;
+ }
+ else
+ {
+ file = nautilus_directory_find_file_by_name (directory, basename);
+ }
+
+ /* Ref or create the file. */
+ if (file != NULL)
+ {
+ nautilus_file_ref (file);
+ }
+ else if (create)
+ {
+ file = nautilus_file_new_from_filename (directory, basename, self_owned);
+ if (self_owned)
+ {
+ g_assert (directory->details->as_file == NULL);
+ directory->details->as_file = file;
+ }
+ else
+ {
+ nautilus_directory_add_file (directory, file);
+ }
+ }
+
+ g_free (basename);
+ nautilus_directory_unref (directory);
+
+ return file;
}
NautilusFile *
nautilus_file_get (GFile *location)
{
- return nautilus_file_get_internal (location, TRUE);
+ return nautilus_file_get_internal (location, TRUE);
}
NautilusFile *
nautilus_file_get_existing (GFile *location)
{
- return nautilus_file_get_internal (location, FALSE);
+ return nautilus_file_get_internal (location, FALSE);
}
NautilusFile *
nautilus_file_get_existing_by_uri (const char *uri)
{
- GFile *location;
- NautilusFile *file;
-
- location = g_file_new_for_uri (uri);
- file = nautilus_file_get_internal (location, FALSE);
- g_object_unref (location);
-
- return file;
+ GFile *location;
+ NautilusFile *file;
+
+ location = g_file_new_for_uri (uri);
+ file = nautilus_file_get_internal (location, FALSE);
+ g_object_unref (location);
+
+ return file;
}
NautilusFile *
nautilus_file_get_by_uri (const char *uri)
{
- GFile *location;
- NautilusFile *file;
-
- location = g_file_new_for_uri (uri);
- file = nautilus_file_get_internal (location, TRUE);
- g_object_unref (location);
-
- return file;
+ GFile *location;
+ NautilusFile *file;
+
+ location = g_file_new_for_uri (uri);
+ file = nautilus_file_get_internal (location, TRUE);
+ g_object_unref (location);
+
+ return file;
}
gboolean
nautilus_file_is_self_owned (NautilusFile *file)
{
- return file->details->directory->details->as_file == file;
+ return file->details->directory->details->as_file == file;
}
static void
finalize (GObject *object)
{
- NautilusDirectory *directory;
- NautilusFile *file;
- char *uri;
-
- file = NAUTILUS_FILE (object);
-
- g_assert (file->details->operations_in_progress == NULL);
-
- if (file->details->is_thumbnailing) {
- uri = nautilus_file_get_uri (file);
- nautilus_thumbnail_remove_from_queue (uri);
- g_free (uri);
- }
-
- nautilus_async_destroying_file (file);
-
- remove_from_link_hash_table (file);
-
- directory = file->details->directory;
-
- if (nautilus_file_is_self_owned (file)) {
- directory->details->as_file = NULL;
- } else {
- if (!file->details->is_gone) {
- nautilus_directory_remove_file (directory, file);
- }
- }
-
- if (file->details->get_info_error) {
- g_error_free (file->details->get_info_error);
- }
-
- nautilus_directory_unref (directory);
- eel_ref_str_unref (file->details->name);
- eel_ref_str_unref (file->details->display_name);
- g_free (file->details->display_name_collation_key);
- g_free (file->details->directory_name_collation_key);
- eel_ref_str_unref (file->details->edit_name);
- if (file->details->icon) {
- g_object_unref (file->details->icon);
- }
- g_free (file->details->thumbnail_path);
- g_free (file->details->symlink_name);
- eel_ref_str_unref (file->details->mime_type);
- eel_ref_str_unref (file->details->owner);
- eel_ref_str_unref (file->details->owner_real);
- eel_ref_str_unref (file->details->group);
- g_free (file->details->selinux_context);
- g_free (file->details->description);
- g_free (file->details->activation_uri);
- g_clear_object (&file->details->custom_icon);
-
- if (file->details->thumbnail) {
- g_object_unref (file->details->thumbnail);
- }
- if (file->details->scaled_thumbnail) {
- g_object_unref (file->details->scaled_thumbnail);
- }
-
- if (file->details->mount) {
- g_signal_handlers_disconnect_by_func (file->details->mount, file_mount_unmounted, file);
- g_object_unref (file->details->mount);
- }
-
- eel_ref_str_unref (file->details->filesystem_id);
- eel_ref_str_unref (file->details->filesystem_type);
- file->details->filesystem_type = NULL;
- g_free (file->details->trash_orig_path);
-
- g_list_free_full (file->details->mime_list, g_free);
- g_list_free_full (file->details->pending_extension_emblems, g_free);
- g_list_free_full (file->details->extension_emblems, g_free);
- g_list_free_full (file->details->pending_info_providers, g_object_unref);
-
- if (file->details->pending_extension_attributes) {
- g_hash_table_destroy (file->details->pending_extension_attributes);
- }
-
- if (file->details->extension_attributes) {
- g_hash_table_destroy (file->details->extension_attributes);
- }
-
- if (file->details->metadata) {
- metadata_hash_free (file->details->metadata);
- }
-
- G_OBJECT_CLASS (nautilus_file_parent_class)->finalize (object);
+ NautilusDirectory *directory;
+ NautilusFile *file;
+ char *uri;
+
+ file = NAUTILUS_FILE (object);
+
+ g_assert (file->details->operations_in_progress == NULL);
+
+ if (file->details->is_thumbnailing)
+ {
+ uri = nautilus_file_get_uri (file);
+ nautilus_thumbnail_remove_from_queue (uri);
+ g_free (uri);
+ }
+
+ nautilus_async_destroying_file (file);
+
+ remove_from_link_hash_table (file);
+
+ directory = file->details->directory;
+
+ if (nautilus_file_is_self_owned (file))
+ {
+ directory->details->as_file = NULL;
+ }
+ else
+ {
+ if (!file->details->is_gone)
+ {
+ nautilus_directory_remove_file (directory, file);
+ }
+ }
+
+ if (file->details->get_info_error)
+ {
+ g_error_free (file->details->get_info_error);
+ }
+
+ nautilus_directory_unref (directory);
+ eel_ref_str_unref (file->details->name);
+ eel_ref_str_unref (file->details->display_name);
+ g_free (file->details->display_name_collation_key);
+ g_free (file->details->directory_name_collation_key);
+ eel_ref_str_unref (file->details->edit_name);
+ if (file->details->icon)
+ {
+ g_object_unref (file->details->icon);
+ }
+ g_free (file->details->thumbnail_path);
+ g_free (file->details->symlink_name);
+ eel_ref_str_unref (file->details->mime_type);
+ eel_ref_str_unref (file->details->owner);
+ eel_ref_str_unref (file->details->owner_real);
+ eel_ref_str_unref (file->details->group);
+ g_free (file->details->selinux_context);
+ g_free (file->details->description);
+ g_free (file->details->activation_uri);
+ g_clear_object (&file->details->custom_icon);
+
+ if (file->details->thumbnail)
+ {
+ g_object_unref (file->details->thumbnail);
+ }
+ if (file->details->scaled_thumbnail)
+ {
+ g_object_unref (file->details->scaled_thumbnail);
+ }
+
+ if (file->details->mount)
+ {
+ g_signal_handlers_disconnect_by_func (file->details->mount, file_mount_unmounted, file);
+ g_object_unref (file->details->mount);
+ }
+
+ eel_ref_str_unref (file->details->filesystem_id);
+ eel_ref_str_unref (file->details->filesystem_type);
+ file->details->filesystem_type = NULL;
+ g_free (file->details->trash_orig_path);
+
+ g_list_free_full (file->details->mime_list, g_free);
+ g_list_free_full (file->details->pending_extension_emblems, g_free);
+ g_list_free_full (file->details->extension_emblems, g_free);
+ g_list_free_full (file->details->pending_info_providers, g_object_unref);
+
+ if (file->details->pending_extension_attributes)
+ {
+ g_hash_table_destroy (file->details->pending_extension_attributes);
+ }
+
+ if (file->details->extension_attributes)
+ {
+ g_hash_table_destroy (file->details->extension_attributes);
+ }
+
+ if (file->details->metadata)
+ {
+ metadata_hash_free (file->details->metadata);
+ }
+
+ G_OBJECT_CLASS (nautilus_file_parent_class)->finalize (object);
}
NautilusFile *
nautilus_file_ref (NautilusFile *file)
{
- if (file == NULL) {
- return NULL;
- }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ if (file == NULL)
+ {
+ return NULL;
+ }
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
#ifdef NAUTILUS_FILE_DEBUG_REF
- DEBUG_REF_PRINTF("%10p ref'd", file);
+ DEBUG_REF_PRINTF ("%10p ref'd", file);
#endif
-
- return g_object_ref (file);
+
+ return g_object_ref (file);
}
void
nautilus_file_unref (NautilusFile *file)
{
- if (file == NULL) {
- return;
- }
+ if (file == NULL)
+ {
+ return;
+ }
- g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
#ifdef NAUTILUS_FILE_DEBUG_REF
- DEBUG_REF_PRINTF("%10p unref'd", file);
+ DEBUG_REF_PRINTF ("%10p unref'd", file);
#endif
-
- g_object_unref (file);
+
+ g_object_unref (file);
}
/**
* nautilus_file_get_parent_uri_for_display:
- *
+ *
* Get the uri for the parent directory.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: A string representing the parent's location,
* formatted for user display (including stripping "file://").
* If the parent is NULL, returns the empty string.
- */
+ */
char *
-nautilus_file_get_parent_uri_for_display (NautilusFile *file)
+nautilus_file_get_parent_uri_for_display (NautilusFile *file)
{
- GFile *parent;
- char *result;
+ GFile *parent;
+ char *result;
+
+ g_assert (NAUTILUS_IS_FILE (file));
- g_assert (NAUTILUS_IS_FILE (file));
-
- parent = nautilus_file_get_parent_location (file);
- if (parent) {
- result = g_file_get_parse_name (parent);
- g_object_unref (parent);
- } else {
- result = g_strdup ("");
- }
+ parent = nautilus_file_get_parent_location (file);
+ if (parent)
+ {
+ result = g_file_get_parse_name (parent);
+ g_object_unref (parent);
+ }
+ else
+ {
+ result = g_strdup ("");
+ }
- return result;
+ return result;
}
/**
* nautilus_file_get_parent_uri:
- *
+ *
* Get the uri for the parent directory.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: A string for the parent's location, in "raw URI" form.
* Use nautilus_file_get_parent_uri_for_display instead if the
* result is to be displayed on-screen.
* If the parent is NULL, returns the empty string.
- */
+ */
char *
-nautilus_file_get_parent_uri (NautilusFile *file)
+nautilus_file_get_parent_uri (NautilusFile *file)
{
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_self_owned (file)) {
- /* Callers expect an empty string, not a NULL. */
- return g_strdup ("");
- }
+ g_assert (NAUTILUS_IS_FILE (file));
- return nautilus_directory_get_uri (file->details->directory);
+ if (nautilus_file_is_self_owned (file))
+ {
+ /* Callers expect an empty string, not a NULL. */
+ return g_strdup ("");
+ }
+
+ return nautilus_directory_get_uri (file->details->directory);
}
GFile *
-nautilus_file_get_parent_location (NautilusFile *file)
+nautilus_file_get_parent_location (NautilusFile *file)
{
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_self_owned (file)) {
- return NULL;
- }
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ if (nautilus_file_is_self_owned (file))
+ {
+ return NULL;
+ }
- return nautilus_directory_get_location (file->details->directory);
+ return nautilus_directory_get_location (file->details->directory);
}
NautilusFile *
nautilus_file_get_parent (NautilusFile *file)
{
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_self_owned (file)) {
- return NULL;
- }
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ if (nautilus_file_is_self_owned (file))
+ {
+ return NULL;
+ }
- return nautilus_directory_get_corresponding_file (file->details->directory);
+ return nautilus_directory_get_corresponding_file (file->details->directory);
}
/**
* nautilus_file_can_read:
- *
+ *
* Check whether the user is allowed to read the contents of this file.
- *
+ *
* @file: The file to check.
- *
+ *
* Return value: FALSE if the user is definitely not allowed to read
* the contents of the file. If the user has read permission, or
* the code can't tell whether the user has read permission,
@@ -962,18 +1056,18 @@ nautilus_file_get_parent (NautilusFile *file)
gboolean
nautilus_file_can_read (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- return file->details->can_read;
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ return file->details->can_read;
}
/**
* nautilus_file_can_write:
- *
+ *
* Check whether the user is allowed to write to this file.
- *
+ *
* @file: The file to check.
- *
+ *
* Return value: FALSE if the user is definitely not allowed to write
* to the file. If the user has write permission, or
* the code can't tell whether the user has write permission,
@@ -982,18 +1076,18 @@ nautilus_file_can_read (NautilusFile *file)
gboolean
nautilus_file_can_write (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return file->details->can_write;
+ return file->details->can_write;
}
/**
* nautilus_file_can_execute:
- *
+ *
* Check whether the user is allowed to execute this file.
- *
+ *
* @file: The file to check.
- *
+ *
* Return value: FALSE if the user is definitely not allowed to execute
* the file. If the user has execute permission, or
* the code can't tell whether the user has execute permission,
@@ -1002,487 +1096,557 @@ nautilus_file_can_write (NautilusFile *file)
gboolean
nautilus_file_can_execute (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return file->details->can_execute;
+ return file->details->can_execute;
}
gboolean
nautilus_file_can_mount (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- return file->details->can_mount;
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ return file->details->can_mount;
}
-
+
gboolean
nautilus_file_can_unmount (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return file->details->can_unmount ||
- (file->details->mount != NULL &&
- g_mount_can_unmount (file->details->mount));
+ return file->details->can_unmount ||
+ (file->details->mount != NULL &&
+ g_mount_can_unmount (file->details->mount));
}
-
+
gboolean
nautilus_file_can_eject (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return file->details->can_eject ||
- (file->details->mount != NULL &&
- g_mount_can_eject (file->details->mount));
+ return file->details->can_eject ||
+ (file->details->mount != NULL &&
+ g_mount_can_eject (file->details->mount));
}
gboolean
nautilus_file_can_start (NautilusFile *file)
{
- gboolean ret;
- GDrive *drive;
+ gboolean ret;
+ GDrive *drive;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- ret = FALSE;
+ ret = FALSE;
- if (file->details->can_start) {
- ret = TRUE;
- goto out;
- }
+ if (file->details->can_start)
+ {
+ ret = TRUE;
+ goto out;
+ }
- if (file->details->mount != NULL) {
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- ret = g_drive_can_start (drive);
- g_object_unref (drive);
- }
- }
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ ret = g_drive_can_start (drive);
+ g_object_unref (drive);
+ }
+ }
- out:
- return ret;
+out:
+ return ret;
}
gboolean
nautilus_file_can_start_degraded (NautilusFile *file)
{
- gboolean ret;
- GDrive *drive;
+ gboolean ret;
+ GDrive *drive;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- ret = FALSE;
+ ret = FALSE;
- if (file->details->can_start_degraded) {
- ret = TRUE;
- goto out;
- }
+ if (file->details->can_start_degraded)
+ {
+ ret = TRUE;
+ goto out;
+ }
- if (file->details->mount != NULL) {
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- ret = g_drive_can_start_degraded (drive);
- g_object_unref (drive);
- }
- }
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ ret = g_drive_can_start_degraded (drive);
+ g_object_unref (drive);
+ }
+ }
- out:
- return ret;
+out:
+ return ret;
}
gboolean
nautilus_file_can_poll_for_media (NautilusFile *file)
{
- gboolean ret;
- GDrive *drive;
+ gboolean ret;
+ GDrive *drive;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- ret = FALSE;
+ ret = FALSE;
- if (file->details->can_poll_for_media) {
- ret = TRUE;
- goto out;
- }
+ if (file->details->can_poll_for_media)
+ {
+ ret = TRUE;
+ goto out;
+ }
- if (file->details->mount != NULL) {
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- ret = g_drive_can_poll_for_media (drive);
- g_object_unref (drive);
- }
- }
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ ret = g_drive_can_poll_for_media (drive);
+ g_object_unref (drive);
+ }
+ }
- out:
- return ret;
+out:
+ return ret;
}
gboolean
nautilus_file_is_media_check_automatic (NautilusFile *file)
{
- gboolean ret;
- GDrive *drive;
+ gboolean ret;
+ GDrive *drive;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- ret = FALSE;
+ ret = FALSE;
- if (file->details->is_media_check_automatic) {
- ret = TRUE;
- goto out;
- }
+ if (file->details->is_media_check_automatic)
+ {
+ ret = TRUE;
+ goto out;
+ }
- if (file->details->mount != NULL) {
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- ret = g_drive_is_media_check_automatic (drive);
- g_object_unref (drive);
- }
- }
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ ret = g_drive_is_media_check_automatic (drive);
+ g_object_unref (drive);
+ }
+ }
- out:
- return ret;
+out:
+ return ret;
}
gboolean
nautilus_file_can_stop (NautilusFile *file)
{
- gboolean ret;
- GDrive *drive;
+ gboolean ret;
+ GDrive *drive;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- ret = FALSE;
+ ret = FALSE;
- if (file->details->can_stop) {
- ret = TRUE;
- goto out;
- }
+ if (file->details->can_stop)
+ {
+ ret = TRUE;
+ goto out;
+ }
- if (file->details->mount != NULL) {
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- ret = g_drive_can_stop (drive);
- g_object_unref (drive);
- }
- }
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ ret = g_drive_can_stop (drive);
+ g_object_unref (drive);
+ }
+ }
- out:
- return ret;
+out:
+ return ret;
}
GDriveStartStopType
nautilus_file_get_start_stop_type (NautilusFile *file)
{
- GDriveStartStopType ret;
- GDrive *drive;
+ GDriveStartStopType ret;
+ GDrive *drive;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- ret = file->details->start_stop_type;
- if (ret != G_DRIVE_START_STOP_TYPE_UNKNOWN)
- goto out;
+ ret = file->details->start_stop_type;
+ if (ret != G_DRIVE_START_STOP_TYPE_UNKNOWN)
+ {
+ goto out;
+ }
- if (file->details->mount != NULL) {
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- ret = g_drive_get_start_stop_type (drive);
- g_object_unref (drive);
- }
- }
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ ret = g_drive_get_start_stop_type (drive);
+ g_object_unref (drive);
+ }
+ }
- out:
- return ret;
+out:
+ return ret;
}
void
-nautilus_file_mount (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
-
- if (NAUTILUS_FILE_GET_CLASS (file)->mount == NULL) {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be mounted"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- } else {
- NAUTILUS_FILE_GET_CLASS (file)->mount (file, mount_op, cancellable, callback, callback_data);
- }
-}
-
-typedef struct {
- NautilusFile *file;
- NautilusFileOperationCallback callback;
- gpointer callback_data;
+nautilus_file_mount (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+
+ if (NAUTILUS_FILE_GET_CLASS (file)->mount == NULL)
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be mounted"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ }
+ else
+ {
+ NAUTILUS_FILE_GET_CLASS (file)->mount (file, mount_op, cancellable, callback, callback_data);
+ }
+}
+
+typedef struct
+{
+ NautilusFile *file;
+ NautilusFileOperationCallback callback;
+ gpointer callback_data;
} UnmountData;
static void
unmount_done (void *callback_data)
{
- UnmountData *data;
+ UnmountData *data;
- data = (UnmountData *)callback_data;
- if (data->callback) {
- data->callback (data->file, NULL, NULL, data->callback_data);
- }
- nautilus_file_unref (data->file);
- g_free (data);
+ data = (UnmountData *) callback_data;
+ if (data->callback)
+ {
+ data->callback (data->file, NULL, NULL, data->callback_data);
+ }
+ nautilus_file_unref (data->file);
+ g_free (data);
}
void
-nautilus_file_unmount (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
- UnmountData *data;
-
- if (file->details->can_unmount) {
- if (NAUTILUS_FILE_GET_CLASS (file)->unmount != NULL) {
- NAUTILUS_FILE_GET_CLASS (file)->unmount (file, mount_op, cancellable, callback, callback_data);
- } else {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be unmounted"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- }
- } else if (file->details->mount != NULL &&
- g_mount_can_unmount (file->details->mount)) {
- data = g_new0 (UnmountData, 1);
- data->file = nautilus_file_ref (file);
- data->callback = callback;
- data->callback_data = callback_data;
- nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, NULL, FALSE, TRUE, unmount_done, data);
- } else if (callback) {
- callback (file, NULL, NULL, callback_data);
- }
+nautilus_file_unmount (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+ UnmountData *data;
+
+ if (file->details->can_unmount)
+ {
+ if (NAUTILUS_FILE_GET_CLASS (file)->unmount != NULL)
+ {
+ NAUTILUS_FILE_GET_CLASS (file)->unmount (file, mount_op, cancellable, callback, callback_data);
+ }
+ else
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be unmounted"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ }
+ }
+ else if (file->details->mount != NULL &&
+ g_mount_can_unmount (file->details->mount))
+ {
+ data = g_new0 (UnmountData, 1);
+ data->file = nautilus_file_ref (file);
+ data->callback = callback;
+ data->callback_data = callback_data;
+ nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, NULL, FALSE, TRUE, unmount_done, data);
+ }
+ else if (callback)
+ {
+ callback (file, NULL, NULL, callback_data);
+ }
}
void
-nautilus_file_eject (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
- UnmountData *data;
-
- if (file->details->can_eject) {
- if (NAUTILUS_FILE_GET_CLASS (file)->eject != NULL) {
- NAUTILUS_FILE_GET_CLASS (file)->eject (file, mount_op, cancellable, callback, callback_data);
- } else {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be ejected"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- }
- } else if (file->details->mount != NULL &&
- g_mount_can_eject (file->details->mount)) {
- data = g_new0 (UnmountData, 1);
- data->file = nautilus_file_ref (file);
- data->callback = callback;
- data->callback_data = callback_data;
- nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, NULL, TRUE, TRUE, unmount_done, data);
- } else if (callback) {
- callback (file, NULL, NULL, callback_data);
- }
+nautilus_file_eject (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+ UnmountData *data;
+
+ if (file->details->can_eject)
+ {
+ if (NAUTILUS_FILE_GET_CLASS (file)->eject != NULL)
+ {
+ NAUTILUS_FILE_GET_CLASS (file)->eject (file, mount_op, cancellable, callback, callback_data);
+ }
+ else
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be ejected"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ }
+ }
+ else if (file->details->mount != NULL &&
+ g_mount_can_eject (file->details->mount))
+ {
+ data = g_new0 (UnmountData, 1);
+ data->file = nautilus_file_ref (file);
+ data->callback = callback;
+ data->callback_data = callback_data;
+ nautilus_file_operations_unmount_mount_full (NULL, file->details->mount, NULL, TRUE, TRUE, unmount_done, data);
+ }
+ else if (callback)
+ {
+ callback (file, NULL, NULL, callback_data);
+ }
}
void
-nautilus_file_start (NautilusFile *file,
- GMountOperation *start_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
-
- if ((file->details->can_start || file->details->can_start_degraded) &&
- NAUTILUS_FILE_GET_CLASS (file)->start != NULL) {
- NAUTILUS_FILE_GET_CLASS (file)->start (file, start_op, cancellable, callback, callback_data);
- } else {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be started"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- }
+nautilus_file_start (NautilusFile *file,
+ GMountOperation *start_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+
+ if ((file->details->can_start || file->details->can_start_degraded) &&
+ NAUTILUS_FILE_GET_CLASS (file)->start != NULL)
+ {
+ NAUTILUS_FILE_GET_CLASS (file)->start (file, start_op, cancellable, callback, callback_data);
+ }
+ else
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be started"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ }
}
static void
-file_stop_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
-{
- NautilusFileOperation *op;
- gboolean stopped;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- stopped = g_drive_stop_finish (G_DRIVE (source_object),
- res, &error);
-
- if (!stopped &&
- error->domain == G_IO_ERROR &&
- (error->code == G_IO_ERROR_FAILED_HANDLED ||
- error->code == G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
- error = NULL;
- }
+file_stop_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ gboolean stopped;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ stopped = g_drive_stop_finish (G_DRIVE (source_object),
+ res, &error);
+
+ if (!stopped &&
+ error->domain == G_IO_ERROR &&
+ (error->code == G_IO_ERROR_FAILED_HANDLED ||
+ error->code == G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ error = NULL;
+ }
- nautilus_file_operation_complete (op, NULL, error);
- if (error) {
- g_error_free (error);
- }
+ nautilus_file_operation_complete (op, NULL, error);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
void
-nautilus_file_stop (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
-
- if (NAUTILUS_FILE_GET_CLASS (file)->stop != NULL) {
- if (file->details->can_stop) {
- NAUTILUS_FILE_GET_CLASS (file)->stop (file, mount_op, cancellable, callback, callback_data);
- } else {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be stopped"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- }
- } else {
- GDrive *drive;
-
- drive = NULL;
- if (file->details->mount != NULL)
- drive = g_mount_get_drive (file->details->mount);
-
- if (drive != NULL && g_drive_can_stop (drive)) {
- NautilusFileOperation *op;
-
- op = nautilus_file_operation_new (file, callback, callback_data);
- if (cancellable) {
- g_object_unref (op->cancellable);
- op->cancellable = g_object_ref (cancellable);
- }
-
- g_drive_stop (drive,
- G_MOUNT_UNMOUNT_NONE,
- mount_op,
- op->cancellable,
- file_stop_callback,
- op);
- } else {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be stopped"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- }
-
- if (drive != NULL) {
- g_object_unref (drive);
- }
- }
+nautilus_file_stop (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+
+ if (NAUTILUS_FILE_GET_CLASS (file)->stop != NULL)
+ {
+ if (file->details->can_stop)
+ {
+ NAUTILUS_FILE_GET_CLASS (file)->stop (file, mount_op, cancellable, callback, callback_data);
+ }
+ else
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be stopped"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ }
+ }
+ else
+ {
+ GDrive *drive;
+
+ drive = NULL;
+ if (file->details->mount != NULL)
+ {
+ drive = g_mount_get_drive (file->details->mount);
+ }
+
+ if (drive != NULL && g_drive_can_stop (drive))
+ {
+ NautilusFileOperation *op;
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ if (cancellable)
+ {
+ g_object_unref (op->cancellable);
+ op->cancellable = g_object_ref (cancellable);
+ }
+
+ g_drive_stop (drive,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_op,
+ op->cancellable,
+ file_stop_callback,
+ op);
+ }
+ else
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be stopped"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ }
+
+ if (drive != NULL)
+ {
+ g_object_unref (drive);
+ }
+ }
}
void
nautilus_file_poll_for_media (NautilusFile *file)
{
- if (file->details->can_poll_for_media) {
- if (NAUTILUS_FILE_GET_CLASS (file)->stop != NULL) {
- NAUTILUS_FILE_GET_CLASS (file)->poll_for_media (file);
- }
- } else if (file->details->mount != NULL) {
- GDrive *drive;
- drive = g_mount_get_drive (file->details->mount);
- if (drive != NULL) {
- g_drive_poll_for_media (drive,
- NULL, /* cancellable */
- NULL, /* GAsyncReadyCallback */
- NULL); /* user_data */
- g_object_unref (drive);
- }
- }
+ if (file->details->can_poll_for_media)
+ {
+ if (NAUTILUS_FILE_GET_CLASS (file)->stop != NULL)
+ {
+ NAUTILUS_FILE_GET_CLASS (file)->poll_for_media (file);
+ }
+ }
+ else if (file->details->mount != NULL)
+ {
+ GDrive *drive;
+ drive = g_mount_get_drive (file->details->mount);
+ if (drive != NULL)
+ {
+ g_drive_poll_for_media (drive,
+ NULL, /* cancellable */
+ NULL, /* GAsyncReadyCallback */
+ NULL); /* user_data */
+ g_object_unref (drive);
+ }
+ }
}
/**
* nautilus_file_is_desktop_directory:
- *
+ *
* Check whether this file is the desktop directory.
- *
+ *
* @file: The file to check.
- *
+ *
* Return value: TRUE if this is the physical desktop directory.
*/
gboolean
nautilus_file_is_desktop_directory (NautilusFile *file)
{
- GFile *dir;
+ GFile *dir;
- dir = file->details->directory->details->location;
+ dir = file->details->directory->details->location;
- if (dir == NULL) {
- return FALSE;
- }
+ if (dir == NULL)
+ {
+ return FALSE;
+ }
- return nautilus_is_desktop_directory_file (dir, eel_ref_str_peek (file->details->name));
+ return nautilus_is_desktop_directory_file (dir, eel_ref_str_peek (file->details->name));
}
static gboolean
is_desktop_file (NautilusFile *file)
{
- return nautilus_file_is_mime_type (file, "application/x-desktop");
+ return nautilus_file_is_mime_type (file, "application/x-desktop");
}
static gboolean
can_rename_desktop_file (NautilusFile *file)
{
- GFile *location;
- gboolean res;
+ GFile *location;
+ gboolean res;
- location = nautilus_file_get_location (file);
- res = g_file_is_native (location);
- g_object_unref (location);
- return res;
+ location = nautilus_file_get_location (file);
+ res = g_file_is_native (location);
+ g_object_unref (location);
+ return res;
}
/**
* nautilus_file_can_rename:
- *
+ *
* Check whether the user is allowed to change the name of the file.
- *
+ *
* @file: The file to check.
- *
+ *
* Return value: FALSE if the user is definitely not allowed to change
* the name of the file. If the user is allowed to change the name, or
* the code can't tell whether the user is allowed to change the name,
@@ -1491,300 +1655,328 @@ can_rename_desktop_file (NautilusFile *file)
gboolean
nautilus_file_can_rename (NautilusFile *file)
{
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->can_rename (file);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->can_rename (file);
}
static gboolean
real_can_rename (NautilusFile *file)
{
- gboolean can_rename;
+ gboolean can_rename;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ /* Nonexistent files can't be renamed. */
+ if (nautilus_file_is_gone (file))
+ {
+ return FALSE;
+ }
- /* Nonexistent files can't be renamed. */
- if (nautilus_file_is_gone (file)) {
- return FALSE;
- }
+ /* Self-owned files can't be renamed */
+ if (nautilus_file_is_self_owned (file))
+ {
+ return FALSE;
+ }
- /* Self-owned files can't be renamed */
- if (nautilus_file_is_self_owned (file)) {
- return FALSE;
- }
+ if ((is_desktop_file (file) && !can_rename_desktop_file (file)) ||
+ nautilus_file_is_home (file))
+ {
+ return FALSE;
+ }
- if ((is_desktop_file (file) && !can_rename_desktop_file (file)) ||
- nautilus_file_is_home (file)) {
- return FALSE;
- }
-
- can_rename = TRUE;
+ can_rename = TRUE;
- if (!can_rename) {
- return FALSE;
- }
+ if (!can_rename)
+ {
+ return FALSE;
+ }
- return file->details->can_rename;
+ return file->details->can_rename;
}
gboolean
nautilus_file_can_delete (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- /* Nonexistent files can't be deleted. */
- if (nautilus_file_is_gone (file)) {
- return FALSE;
- }
+ /* Nonexistent files can't be deleted. */
+ if (nautilus_file_is_gone (file))
+ {
+ return FALSE;
+ }
- /* Self-owned files can't be deleted */
- if (nautilus_file_is_self_owned (file)) {
- return FALSE;
- }
+ /* Self-owned files can't be deleted */
+ if (nautilus_file_is_self_owned (file))
+ {
+ return FALSE;
+ }
- return file->details->can_delete;
+ return file->details->can_delete;
}
gboolean
nautilus_file_can_trash (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- /* Nonexistent files can't be deleted. */
- if (nautilus_file_is_gone (file)) {
- return FALSE;
- }
+ /* Nonexistent files can't be deleted. */
+ if (nautilus_file_is_gone (file))
+ {
+ return FALSE;
+ }
- /* Self-owned files can't be deleted */
- if (nautilus_file_is_self_owned (file)) {
- return FALSE;
- }
+ /* Self-owned files can't be deleted */
+ if (nautilus_file_is_self_owned (file))
+ {
+ return FALSE;
+ }
- return file->details->can_trash;
+ return file->details->can_trash;
}
GFile *
nautilus_file_get_location (NautilusFile *file)
{
- GFile *dir;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ GFile *dir;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- dir = file->details->directory->details->location;
-
- if (nautilus_file_is_self_owned (file)) {
- return g_object_ref (dir);
- }
-
- return g_file_get_child (dir, eel_ref_str_peek (file->details->name));
+ dir = file->details->directory->details->location;
+
+ if (nautilus_file_is_self_owned (file))
+ {
+ return g_object_ref (dir);
+ }
+
+ return g_file_get_child (dir, eel_ref_str_peek (file->details->name));
}
/* Return the actual uri associated with the passed-in file. */
char *
nautilus_file_get_uri (NautilusFile *file)
{
- char *uri;
- GFile *loc;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ char *uri;
+ GFile *loc;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+
+ loc = nautilus_file_get_location (file);
+ uri = g_file_get_uri (loc);
+ g_object_unref (loc);
- loc = nautilus_file_get_location (file);
- uri = g_file_get_uri (loc);
- g_object_unref (loc);
-
- return uri;
+ return uri;
}
char *
nautilus_file_get_uri_scheme (NautilusFile *file)
{
- GFile *loc;
- char *scheme;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ GFile *loc;
+ char *scheme;
- if (file->details->directory == NULL ||
- file->details->directory->details->location == NULL) {
- return NULL;
- }
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- loc = nautilus_directory_get_location (file->details->directory);
- scheme = g_file_get_uri_scheme (loc);
- g_object_unref (loc);
-
- return scheme;
+ if (file->details->directory == NULL ||
+ file->details->directory->details->location == NULL)
+ {
+ return NULL;
+ }
+
+ loc = nautilus_directory_get_location (file->details->directory);
+ scheme = g_file_get_uri_scheme (loc);
+ g_object_unref (loc);
+
+ return scheme;
}
gboolean
nautilus_file_opens_in_view (NautilusFile *file)
{
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->opens_in_view (file);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->opens_in_view (file);
}
static gboolean
real_opens_in_view (NautilusFile *file)
{
- return nautilus_file_is_directory (file);
+ return nautilus_file_is_directory (file);
}
NautilusFileOperation *
-nautilus_file_operation_new (NautilusFile *file,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+nautilus_file_operation_new (NautilusFile *file,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
+ NautilusFileOperation *op;
- op = g_new0 (NautilusFileOperation, 1);
- op->file = nautilus_file_ref (file);
- op->callback = callback;
- op->callback_data = callback_data;
- op->cancellable = g_cancellable_new ();
+ op = g_new0 (NautilusFileOperation, 1);
+ op->file = nautilus_file_ref (file);
+ op->callback = callback;
+ op->callback_data = callback_data;
+ op->cancellable = g_cancellable_new ();
- op->file->details->operations_in_progress = g_list_prepend
- (op->file->details->operations_in_progress, op);
+ op->file->details->operations_in_progress = g_list_prepend
+ (op->file->details->operations_in_progress, op);
- return op;
+ return op;
}
static void
nautilus_file_operation_remove (NautilusFileOperation *op)
{
- GList *l;
- NautilusFile *file;
+ GList *l;
+ NautilusFile *file;
- op->file->details->operations_in_progress = g_list_remove
- (op->file->details->operations_in_progress, op);
+ op->file->details->operations_in_progress = g_list_remove
+ (op->file->details->operations_in_progress, op);
- for (l = op->files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- file->details->operations_in_progress = g_list_remove
- (file->details->operations_in_progress, op);
- }
+ for (l = op->files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ file->details->operations_in_progress = g_list_remove
+ (file->details->operations_in_progress, op);
+ }
}
void
nautilus_file_operation_free (NautilusFileOperation *op)
{
- NautilusFile *file;
- GList *l;
-
- nautilus_file_operation_remove (op);
-
- if (op->files == NULL)
- nautilus_file_unref (op->file);
- else
- for (l = op->files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- nautilus_file_unref (file);
- }
+ NautilusFile *file;
+ GList *l;
+
+ nautilus_file_operation_remove (op);
+
+ if (op->files == NULL)
+ {
+ nautilus_file_unref (op->file);
+ }
+ else
+ {
+ for (l = op->files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ nautilus_file_unref (file);
+ }
+ }
- g_object_unref (op->cancellable);
- if (op->free_data) {
- op->free_data (op->data);
- }
+ g_object_unref (op->cancellable);
+ if (op->free_data)
+ {
+ op->free_data (op->data);
+ }
- if (op->undo_info != NULL) {
- nautilus_file_undo_manager_set_action (op->undo_info);
- g_object_unref (op->undo_info);
- }
+ if (op->undo_info != NULL)
+ {
+ nautilus_file_undo_manager_set_action (op->undo_info);
+ g_object_unref (op->undo_info);
+ }
- g_free (op);
+ g_free (op);
}
void
nautilus_file_operation_complete (NautilusFileOperation *op,
- GFile *result_file,
- GError *error)
+ GFile *result_file,
+ GError *error)
{
- /* Claim that something changed even if the operation failed.
- * This makes it easier for some clients who see the "reverting"
- * as "changing back".
- */
- nautilus_file_operation_remove (op);
+ /* Claim that something changed even if the operation failed.
+ * This makes it easier for some clients who see the "reverting"
+ * as "changing back".
+ */
+ nautilus_file_operation_remove (op);
- if (op->files == NULL)
- nautilus_file_changed (op->file);
+ if (op->files == NULL)
+ {
+ nautilus_file_changed (op->file);
+ }
- if (op->callback)
- (* op->callback) (op->file, result_file, error, op->callback_data);
+ if (op->callback)
+ {
+ (*op->callback)(op->file, result_file, error, op->callback_data);
+ }
- if (error != NULL) {
- g_clear_object (&op->undo_info);
- }
+ if (error != NULL)
+ {
+ g_clear_object (&op->undo_info);
+ }
- nautilus_file_operation_free (op);
+ nautilus_file_operation_free (op);
}
void
nautilus_file_operation_cancel (NautilusFileOperation *op)
{
- /* Cancel the operation if it's still in progress. */
- g_cancellable_cancel (op->cancellable);
+ /* Cancel the operation if it's still in progress. */
+ g_cancellable_cancel (op->cancellable);
}
static void
-rename_get_info_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
-{
- NautilusFileOperation *op;
- NautilusDirectory *directory;
- NautilusFile *existing_file;
- char *old_uri;
- char *new_uri;
- const char *new_name;
- GFileInfo *new_info;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
- if (new_info != NULL) {
- directory = op->file->details->directory;
-
- new_name = g_file_info_get_name (new_info);
-
- /* If there was another file by the same name in this
- * directory and it is not the same file that we are
- * renaming, mark it gone.
- */
- existing_file = nautilus_directory_find_file_by_name (directory, new_name);
- if (existing_file != NULL && existing_file != op->file) {
- nautilus_file_mark_gone (existing_file);
- nautilus_file_changed (existing_file);
- }
-
- old_uri = nautilus_file_get_uri (op->file);
-
- update_info_and_name (op->file, new_info);
-
- new_uri = nautilus_file_get_uri (op->file);
- nautilus_directory_moved (old_uri, new_uri);
- g_free (new_uri);
- g_free (old_uri);
-
- /* the rename could have affected the display name if e.g.
- * we're in a vfolder where the name comes from a desktop file
- * and a rename affects the contents of the desktop file.
- */
- if (op->file->details->got_custom_display_name) {
- nautilus_file_invalidate_attributes (op->file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
- }
-
- g_object_unref (new_info);
- }
- nautilus_file_operation_complete (op, NULL, error);
- if (error) {
- g_error_free (error);
- }
-}
-
-typedef struct {
- NautilusFileOperation *op;
- NautilusFile *file;
+rename_get_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ NautilusDirectory *directory;
+ NautilusFile *existing_file;
+ char *old_uri;
+ char *new_uri;
+ const char *new_name;
+ GFileInfo *new_info;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
+ if (new_info != NULL)
+ {
+ directory = op->file->details->directory;
+
+ new_name = g_file_info_get_name (new_info);
+
+ /* If there was another file by the same name in this
+ * directory and it is not the same file that we are
+ * renaming, mark it gone.
+ */
+ existing_file = nautilus_directory_find_file_by_name (directory, new_name);
+ if (existing_file != NULL && existing_file != op->file)
+ {
+ nautilus_file_mark_gone (existing_file);
+ nautilus_file_changed (existing_file);
+ }
+
+ old_uri = nautilus_file_get_uri (op->file);
+
+ update_info_and_name (op->file, new_info);
+
+ new_uri = nautilus_file_get_uri (op->file);
+ nautilus_directory_moved (old_uri, new_uri);
+ g_free (new_uri);
+ g_free (old_uri);
+
+ /* the rename could have affected the display name if e.g.
+ * we're in a vfolder where the name comes from a desktop file
+ * and a rename affects the contents of the desktop file.
+ */
+ if (op->file->details->got_custom_display_name)
+ {
+ nautilus_file_invalidate_attributes (op->file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
+ }
+
+ g_object_unref (new_info);
+ }
+ nautilus_file_operation_complete (op, NULL, error);
+ if (error)
+ {
+ g_error_free (error);
+ }
+}
+
+typedef struct
+{
+ NautilusFileOperation *op;
+ NautilusFile *file;
} BatchRenameData;
static void
@@ -1792,114 +1984,126 @@ batch_rename_get_info_callback (GObject *source_object,
GAsyncResult *res,
gpointer callback_data)
{
- NautilusFileOperation *op;
- NautilusDirectory *directory;
- NautilusFile *existing_file;
- char *old_uri;
- char *new_uri;
- const char *new_name;
- GFileInfo *new_info;
- GError *error;
- BatchRenameData *data;
+ NautilusFileOperation *op;
+ NautilusDirectory *directory;
+ NautilusFile *existing_file;
+ char *old_uri;
+ char *new_uri;
+ const char *new_name;
+ GFileInfo *new_info;
+ GError *error;
+ BatchRenameData *data;
- data = callback_data;
+ data = callback_data;
- op = data->op;
- op->file = data->file;
+ op = data->op;
+ op->file = data->file;
- error = NULL;
- new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
- if (new_info != NULL) {
- old_uri = nautilus_file_get_uri (op->file);
-
- new_name = g_file_info_get_name (new_info);
+ error = NULL;
+ new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
+ if (new_info != NULL)
+ {
+ old_uri = nautilus_file_get_uri (op->file);
- directory = op->file->details->directory;
+ new_name = g_file_info_get_name (new_info);
- /* If there was another file by the same name in this
- * directory and it is not the same file that we are
- * renaming, mark it gone.
- */
- existing_file = nautilus_directory_find_file_by_name (directory, new_name);
- if (existing_file != NULL && existing_file != op->file) {
- nautilus_file_mark_gone (existing_file);
- nautilus_file_changed (existing_file);
- }
+ directory = op->file->details->directory;
- update_info_and_name (op->file, new_info);
+ /* If there was another file by the same name in this
+ * directory and it is not the same file that we are
+ * renaming, mark it gone.
+ */
+ existing_file = nautilus_directory_find_file_by_name (directory, new_name);
+ if (existing_file != NULL && existing_file != op->file)
+ {
+ nautilus_file_mark_gone (existing_file);
+ nautilus_file_changed (existing_file);
+ }
- new_uri = nautilus_file_get_uri (op->file);
- nautilus_directory_moved (old_uri, new_uri);
- g_free (new_uri);
- g_free (old_uri);
+ update_info_and_name (op->file, new_info);
- /* the rename could have affected the display name if e.g.
- * we're in a vfolder where the name comes from a desktop file
- * and a rename affects the contents of the desktop file.
- */
- if (op->file->details->got_custom_display_name) {
- nautilus_file_invalidate_attributes (op->file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
- }
+ new_uri = nautilus_file_get_uri (op->file);
+ nautilus_directory_moved (old_uri, new_uri);
+ g_free (new_uri);
+ g_free (old_uri);
- g_object_unref (new_info);
+ /* the rename could have affected the display name if e.g.
+ * we're in a vfolder where the name comes from a desktop file
+ * and a rename affects the contents of the desktop file.
+ */
+ if (op->file->details->got_custom_display_name)
+ {
+ nautilus_file_invalidate_attributes (op->file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
}
- op->renamed_files++;
+ g_object_unref (new_info);
+ }
- if (op->renamed_files + op->skipped_files == g_list_length (op->files)) {
- nautilus_file_operation_complete (op, NULL, error);
- }
+ op->renamed_files++;
- if (op->files == NULL)
- nautilus_file_operation_complete (op, NULL, error);
+ if (op->renamed_files + op->skipped_files == g_list_length (op->files))
+ {
+ nautilus_file_operation_complete (op, NULL, error);
+ }
- g_free (data);
+ if (op->files == NULL)
+ {
+ nautilus_file_operation_complete (op, NULL, error);
+ }
- if (error) {
- g_error_free (error);
- }
+ g_free (data);
+
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-rename_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
-{
- NautilusFileOperation *op;
- GFile *new_file;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- new_file = g_file_set_display_name_finish (G_FILE (source_object),
- res, &error);
-
- if (new_file != NULL) {
- if (op->undo_info != NULL) {
- nautilus_file_undo_info_rename_set_data_post (NAUTILUS_FILE_UNDO_INFO_RENAME (op->undo_info),
- new_file);
- }
- g_file_query_info_async (new_file,
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0,
- G_PRIORITY_DEFAULT,
- op->cancellable,
- rename_get_info_callback, op);
- } else {
- nautilus_file_operation_complete (op, NULL, error);
- g_error_free (error);
- }
+rename_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ GFile *new_file;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ new_file = g_file_set_display_name_finish (G_FILE (source_object),
+ res, &error);
+
+ if (new_file != NULL)
+ {
+ if (op->undo_info != NULL)
+ {
+ nautilus_file_undo_info_rename_set_data_post (NAUTILUS_FILE_UNDO_INFO_RENAME (op->undo_info),
+ new_file);
+ }
+ g_file_query_info_async (new_file,
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0,
+ G_PRIORITY_DEFAULT,
+ op->cancellable,
+ rename_get_info_callback, op);
+ }
+ else
+ {
+ nautilus_file_operation_complete (op, NULL, error);
+ g_error_free (error);
+ }
}
static gboolean
-name_is (NautilusFile *file, const char *new_name)
+name_is (NautilusFile *file,
+ const char *new_name)
{
- const char *old_name;
- old_name = eel_ref_str_peek (file->details->name);
- return strcmp (new_name, old_name) == 0;
+ const char *old_name;
+ old_name = eel_ref_str_peek (file->details->name);
+ return strcmp (new_name, old_name) == 0;
}
void
@@ -1908,124 +2112,147 @@ nautilus_file_rename (NautilusFile *file,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->rename (file,
- new_name,
- callback,
- callback_data);
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->rename (file,
+ new_name,
+ callback,
+ callback_data);
}
-static gchar*
+static gchar *
nautilus_file_can_rename_file (NautilusFile *file,
const char *new_name,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- GError *error;
- gboolean is_renameable_desktop_file;
- gboolean success;
- gboolean name_changed;
- gchar *new_file_name;
- gchar *uri;
- gchar *old_name;
-
- is_renameable_desktop_file =
- is_desktop_file (file) && can_rename_desktop_file (file);
-
- /* Return an error for incoming names containing path separators.
- * But not for .desktop files as '/' are allowed for them */
- if (strstr (new_name, "/") != NULL && !is_renameable_desktop_file) {
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
- _("Slashes are not allowed in filenames"));
- if (callback != NULL)
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return NULL;
+ GError *error;
+ gboolean is_renameable_desktop_file;
+ gboolean success;
+ gboolean name_changed;
+ gchar *new_file_name;
+ gchar *uri;
+ gchar *old_name;
+
+ is_renameable_desktop_file =
+ is_desktop_file (file) && can_rename_desktop_file (file);
+
+ /* Return an error for incoming names containing path separators.
+ * But not for .desktop files as '/' are allowed for them */
+ if (strstr (new_name, "/") != NULL && !is_renameable_desktop_file)
+ {
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ _("Slashes are not allowed in filenames"));
+ if (callback != NULL)
+ {
+ (*callback)(file, NULL, error, callback_data);
}
-
- /* Can't rename a file that's already gone.
- * We need to check this here because there may be a new
- * file with the same name.
- */
- if (nautilus_file_rename_handle_file_gone (file, callback, callback_data)) {
- return NULL;
+ g_error_free (error);
+ return NULL;
+ }
+
+ /* Can't rename a file that's already gone.
+ * We need to check this here because there may be a new
+ * file with the same name.
+ */
+ if (nautilus_file_rename_handle_file_gone (file, callback, callback_data))
+ {
+ return NULL;
+ }
+
+ /* Test the name-hasn't-changed case explicitly, for two reasons.
+ * (1) rename returns an error if new & old are same.
+ * (2) We don't want to send file-changed signal if nothing changed.
+ */
+ if (!is_renameable_desktop_file &&
+ name_is (file, new_name))
+ {
+ if (callback != NULL)
+ {
+ (*callback)(file, NULL, NULL, callback_data);
}
-
- /* Test the name-hasn't-changed case explicitly, for two reasons.
- * (1) rename returns an error if new & old are same.
- * (2) We don't want to send file-changed signal if nothing changed.
+ return NULL;
+ }
+
+ /* Self-owned files can't be renamed. Test the name-not-actually-changing
+ * case before this case.
+ */
+ if (nautilus_file_is_self_owned (file))
+ {
+ /* Claim that something changed even if the rename
+ * failed. This makes it easier for some clients who
+ * see the "reverting" to the old name as "changing
+ * back".
*/
- if (!is_renameable_desktop_file &&
- name_is (file, new_name)) {
- if (callback != NULL)
- (* callback) (file, NULL, NULL, callback_data);
- return NULL;
- }
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("Toplevel files cannot be renamed"));
- /* Self-owned files can't be renamed. Test the name-not-actually-changing
- * case before this case.
- */
- if (nautilus_file_is_self_owned (file)) {
- /* Claim that something changed even if the rename
- * failed. This makes it easier for some clients who
- * see the "reverting" to the old name as "changing
- * back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("Toplevel files cannot be renamed"));
+ if (callback != NULL)
+ {
+ (*callback)(file, NULL, error, callback_data);
+ }
+ g_error_free (error);
- if (callback != NULL)
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
+ return NULL;
+ }
- return NULL;
+ if (is_renameable_desktop_file)
+ {
+ /* Don't actually change the name if the new name is the same.
+ * This helps for the vfolder method where this can happen and
+ * we want to minimize actual changes
+ */
+ uri = nautilus_file_get_uri (file);
+ old_name = nautilus_link_local_get_text (uri);
+ if (old_name != NULL && strcmp (new_name, old_name) == 0)
+ {
+ success = TRUE;
+ name_changed = FALSE;
}
+ else
+ {
+ success = nautilus_link_local_set_text (uri, new_name);
+ name_changed = TRUE;
+ }
+ g_free (old_name);
+ g_free (uri);
- if (is_renameable_desktop_file) {
- /* Don't actually change the name if the new name is the same.
- * This helps for the vfolder method where this can happen and
- * we want to minimize actual changes
- */
- uri = nautilus_file_get_uri (file);
- old_name = nautilus_link_local_get_text (uri);
- if (old_name != NULL && strcmp (new_name, old_name) == 0) {
- success = TRUE;
- name_changed = FALSE;
- } else {
- success = nautilus_link_local_set_text (uri, new_name);
- name_changed = TRUE;
- }
- g_free (old_name);
- g_free (uri);
-
- if (!success) {
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Probably the content of the file is an invalid desktop file format"));
- if (callback != NULL)
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return NULL;
- }
- new_file_name = g_strdup_printf ("%s.desktop", new_name);
- new_file_name = g_strdelimit (new_file_name, "/", '-');
-
- if (name_is (file, new_file_name)) {
- if (name_changed) {
- nautilus_file_invalidate_attributes (file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
- }
-
- if (callback != NULL)
- (* callback) (file, NULL, NULL, callback_data);
- g_free (new_file_name);
- return NULL;
- }
- } else {
- new_file_name = g_strdup (new_name);
+ if (!success)
+ {
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("Probably the content of the file is an invalid desktop file format"));
+ if (callback != NULL)
+ {
+ (*callback)(file, NULL, error, callback_data);
+ }
+ g_error_free (error);
+ return NULL;
+ }
+ new_file_name = g_strdup_printf ("%s.desktop", new_name);
+ new_file_name = g_strdelimit (new_file_name, "/", '-');
+
+ if (name_is (file, new_file_name))
+ {
+ if (name_changed)
+ {
+ nautilus_file_invalidate_attributes (file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
+ }
+
+ if (callback != NULL)
+ {
+ (*callback)(file, NULL, NULL, callback_data);
+ }
+ g_free (new_file_name);
+ return NULL;
}
+ }
+ else
+ {
+ new_file_name = g_strdup (new_name);
+ }
- return new_file_name;
+ return new_file_name;
}
static void
@@ -2034,95 +2261,100 @@ real_batch_rename (GList *files,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- GList *l1, *l2, *old_files, *new_files;
- NautilusFileOperation *op;
- GFile *location;
- gchar *new_file_name;
- GString *new_name;
- NautilusFile *file;
- GError *error;
- GFile *new_file;
- BatchRenameData *data;
-
- error = NULL;
- old_files = NULL;
- new_files = NULL;
-
- /* Set up a batch renaming operation. */
- op = nautilus_file_operation_new (files->data, callback, callback_data);
- op->files = files;
- op->renamed_files = 0;
- op->skipped_files = 0;
-
- for (l1 = files->next; l1 != NULL; l1 = l1->next) {
- file = NAUTILUS_FILE (l1->data);
-
- file->details->operations_in_progress = g_list_prepend (file->details->operations_in_progress,
- op);
+ GList *l1, *l2, *old_files, *new_files;
+ NautilusFileOperation *op;
+ GFile *location;
+ gchar *new_file_name;
+ GString *new_name;
+ NautilusFile *file;
+ GError *error;
+ GFile *new_file;
+ BatchRenameData *data;
+
+ error = NULL;
+ old_files = NULL;
+ new_files = NULL;
+
+ /* Set up a batch renaming operation. */
+ op = nautilus_file_operation_new (files->data, callback, callback_data);
+ op->files = files;
+ op->renamed_files = 0;
+ op->skipped_files = 0;
+
+ for (l1 = files->next; l1 != NULL; l1 = l1->next)
+ {
+ file = NAUTILUS_FILE (l1->data);
+
+ file->details->operations_in_progress = g_list_prepend (file->details->operations_in_progress,
+ op);
+ }
+
+ for (l1 = files, l2 = new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next)
+ {
+ file = NAUTILUS_FILE (l1->data);
+ new_name = l2->data;
+
+ location = nautilus_file_get_location (file);
+ old_files = g_list_append (old_files, location);
+
+ new_file_name = nautilus_file_can_rename_file (file,
+ new_name->str,
+ callback,
+ callback_data);
+
+ if (new_file_name == NULL)
+ {
+ op->skipped_files++;
+
+ new_file = nautilus_file_get_location (file);
+ new_files = g_list_append (new_files, new_file);
+
+ continue;
}
- for (l1 = files, l2 = new_names; l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next) {
- file = NAUTILUS_FILE (l1->data);
- new_name = l2->data;
-
- location = nautilus_file_get_location (file);
- old_files = g_list_append (old_files, location);
-
- new_file_name = nautilus_file_can_rename_file (file,
- new_name->str,
- callback,
- callback_data);
-
- if (new_file_name == NULL) {
- op->skipped_files++;
-
- new_file = nautilus_file_get_location (file);
- new_files = g_list_append (new_files, new_file);
-
- continue;
- }
-
- g_assert (G_IS_FILE (location));
-
- /* Do the renaming. */
- new_file = g_file_set_display_name (location,
- new_file_name,
- op->cancellable,
- &error);
-
- data = g_new0 (BatchRenameData, 1);
- data->op = op;
- data->file = file;
-
- new_files = g_list_append (new_files, new_file);
-
- g_file_query_info_async (new_file,
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0,
- G_PRIORITY_DEFAULT,
- op->cancellable,
- batch_rename_get_info_callback,
- data);
-
- if (error != NULL) {
- g_warning ("Batch rename for file \"%s\" failed", nautilus_file_get_name (file));
- g_error_free (error);
- error = NULL;
- }
+ g_assert (G_IS_FILE (location));
+
+ /* Do the renaming. */
+ new_file = g_file_set_display_name (location,
+ new_file_name,
+ op->cancellable,
+ &error);
+
+ data = g_new0 (BatchRenameData, 1);
+ data->op = op;
+ data->file = file;
+
+ new_files = g_list_append (new_files, new_file);
+
+ g_file_query_info_async (new_file,
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0,
+ G_PRIORITY_DEFAULT,
+ op->cancellable,
+ batch_rename_get_info_callback,
+ data);
+
+ if (error != NULL)
+ {
+ g_warning ("Batch rename for file \"%s\" failed", nautilus_file_get_name (file));
+ g_error_free (error);
+ error = NULL;
}
+ }
- /* Tell the undo manager a batch rename is taking place */
- if (!nautilus_file_undo_manager_is_operating ()) {
- op->undo_info = nautilus_file_undo_info_batch_rename_new (g_list_length (new_files));
+ /* Tell the undo manager a batch rename is taking place */
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ op->undo_info = nautilus_file_undo_info_batch_rename_new (g_list_length (new_files));
- nautilus_file_undo_info_batch_rename_set_data_pre (NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (op->undo_info),
- old_files);
+ nautilus_file_undo_info_batch_rename_set_data_pre (NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (op->undo_info),
+ old_files);
- nautilus_file_undo_info_batch_rename_set_data_post (NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (op->undo_info),
- new_files);
+ nautilus_file_undo_info_batch_rename_set_data_post (NAUTILUS_FILE_UNDO_INFO_BATCH_RENAME (op->undo_info),
+ new_files);
- nautilus_file_undo_manager_set_action (op->undo_info);
- }
+ nautilus_file_undo_manager_set_action (op->undo_info);
+ }
}
gboolean
@@ -2130,23 +2362,24 @@ nautilus_file_rename_handle_file_gone (NautilusFile *file,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- GError *error;
+ GError *error;
- if (nautilus_file_is_gone (file)) {
- /* Claim that something changed even if the rename
- * failed. This makes it easier for some clients who
- * see the "reverting" to the old name as "changing
- * back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- _("File not found"));
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return TRUE;
- }
+ if (nautilus_file_is_gone (file))
+ {
+ /* Claim that something changed even if the rename
+ * failed. This makes it easier for some clients who
+ * see the "reverting" to the old name as "changing
+ * back".
+ */
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+ _("File not found"));
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
void
@@ -2155,10 +2388,10 @@ nautilus_file_batch_rename (GList *files,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- real_batch_rename (files,
- new_names,
- callback,
- callback_data);
+ real_batch_rename (files,
+ new_names,
+ callback,
+ callback_data);
}
static void
@@ -2167,1180 +2400,1350 @@ real_rename (NautilusFile *file,
NautilusFileOperationCallback callback,
gpointer callback_data)
{
- NautilusFileOperation *op;
- char *old_name;
- char *new_file_name;
- GFile *location;
-
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (new_name != NULL);
- g_return_if_fail (callback != NULL);
-
- new_file_name = nautilus_file_can_rename_file (file,
- new_name,
- callback,
- callback_data);
-
- if (new_file_name == NULL)
- return;
-
- /* Set up a renaming operation. */
- op = nautilus_file_operation_new (file, callback, callback_data);
- op->is_rename = TRUE;
- location = nautilus_file_get_location (file);
-
- /* Tell the undo manager a rename is taking place */
- if (!nautilus_file_undo_manager_is_operating ()) {
- op->undo_info = nautilus_file_undo_info_rename_new ();
-
- old_name = nautilus_file_get_display_name (file);
- nautilus_file_undo_info_rename_set_data_pre (NAUTILUS_FILE_UNDO_INFO_RENAME (op->undo_info),
- location, old_name, new_file_name);
- g_free (old_name);
- }
-
- /* Do the renaming. */
- g_file_set_display_name_async (location,
- new_file_name,
- G_PRIORITY_DEFAULT,
- op->cancellable,
- rename_callback,
- op);
- g_free (new_file_name);
- g_object_unref (location);
+ NautilusFileOperation *op;
+ char *old_name;
+ char *new_file_name;
+ GFile *location;
+
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (new_name != NULL);
+ g_return_if_fail (callback != NULL);
+
+ new_file_name = nautilus_file_can_rename_file (file,
+ new_name,
+ callback,
+ callback_data);
+
+ if (new_file_name == NULL)
+ {
+ return;
+ }
+
+ /* Set up a renaming operation. */
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ op->is_rename = TRUE;
+ location = nautilus_file_get_location (file);
+
+ /* Tell the undo manager a rename is taking place */
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ op->undo_info = nautilus_file_undo_info_rename_new ();
+
+ old_name = nautilus_file_get_display_name (file);
+ nautilus_file_undo_info_rename_set_data_pre (NAUTILUS_FILE_UNDO_INFO_RENAME (op->undo_info),
+ location, old_name, new_file_name);
+ g_free (old_name);
+ }
+
+ /* Do the renaming. */
+ g_file_set_display_name_async (location,
+ new_file_name,
+ G_PRIORITY_DEFAULT,
+ op->cancellable,
+ rename_callback,
+ op);
+ g_free (new_file_name);
+ g_object_unref (location);
}
gboolean
nautilus_file_rename_in_progress (NautilusFile *file)
{
- GList *node;
- NautilusFileOperation *op;
+ GList *node;
+ NautilusFileOperation *op;
- for (node = file->details->operations_in_progress; node != NULL; node = node->next) {
- op = node->data;
- if (op->is_rename) {
- return TRUE;
- }
- }
- return FALSE;
+ for (node = file->details->operations_in_progress; node != NULL; node = node->next)
+ {
+ op = node->data;
+ if (op->is_rename)
+ {
+ return TRUE;
+ }
+ }
+ return FALSE;
}
void
-nautilus_file_cancel (NautilusFile *file,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+nautilus_file_cancel (NautilusFile *file,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- GList *node, *next;
- NautilusFileOperation *op;
+ GList *node, *next;
+ NautilusFileOperation *op;
- for (node = file->details->operations_in_progress; node != NULL; node = next) {
- next = node->next;
- op = node->data;
+ for (node = file->details->operations_in_progress; node != NULL; node = next)
+ {
+ next = node->next;
+ op = node->data;
- g_assert (op->file == file);
- if (op->callback == callback && op->callback_data == callback_data) {
- nautilus_file_operation_cancel (op);
- }
- }
+ g_assert (op->file == file);
+ if (op->callback == callback && op->callback_data == callback_data)
+ {
+ nautilus_file_operation_cancel (op);
+ }
+ }
}
-gboolean
-nautilus_file_matches_uri (NautilusFile *file, const char *match_uri)
+gboolean
+nautilus_file_matches_uri (NautilusFile *file,
+ const char *match_uri)
{
- GFile *match_file, *location;
- gboolean result;
+ GFile *match_file, *location;
+ gboolean result;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- g_return_val_if_fail (match_uri != NULL, FALSE);
-
- location = nautilus_file_get_location (file);
- match_file = g_file_new_for_uri (match_uri);
- result = g_file_equal (location, match_file);
- g_object_unref (location);
- g_object_unref (match_file);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (match_uri != NULL, FALSE);
- return result;
+ location = nautilus_file_get_location (file);
+ match_file = g_file_new_for_uri (match_uri);
+ result = g_file_equal (location, match_file);
+ g_object_unref (location);
+ g_object_unref (match_file);
+
+ return result;
}
int
nautilus_file_compare_location (NautilusFile *file_1,
NautilusFile *file_2)
{
- GFile *loc_a, *loc_b;
- gboolean res;
+ GFile *loc_a, *loc_b;
+ gboolean res;
- loc_a = nautilus_file_get_location (file_1);
- loc_b = nautilus_file_get_location (file_2);
+ loc_a = nautilus_file_get_location (file_1);
+ loc_b = nautilus_file_get_location (file_2);
- res = !g_file_equal (loc_a, loc_b);
+ res = !g_file_equal (loc_a, loc_b);
- g_object_unref (loc_a);
- g_object_unref (loc_b);
+ g_object_unref (loc_a);
+ g_object_unref (loc_b);
- return (gint) res;
+ return (gint) res;
}
gboolean
nautilus_file_is_local (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- return nautilus_directory_is_local (file->details->directory);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ return nautilus_directory_is_local (file->details->directory);
}
gboolean
nautilus_file_is_local_or_fuse (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return nautilus_directory_is_local_or_fuse (file->details->directory);
+ return nautilus_directory_is_local_or_fuse (file->details->directory);
}
static void
-update_link (NautilusFile *link_file, NautilusFile *target_file)
+update_link (NautilusFile *link_file,
+ NautilusFile *target_file)
{
- g_assert (NAUTILUS_IS_FILE (link_file));
- g_assert (NAUTILUS_IS_FILE (target_file));
+ g_assert (NAUTILUS_IS_FILE (link_file));
+ g_assert (NAUTILUS_IS_FILE (target_file));
- /* FIXME bugzilla.gnome.org 42044: If we don't put any code
- * here then the hash table is a waste of time.
- */
+ /* FIXME bugzilla.gnome.org 42044: If we don't put any code
+ * here then the hash table is a waste of time.
+ */
}
static GList *
get_link_files (NautilusFile *target_file)
{
- char *uri;
- GList **link_files;
-
- if (symbolic_links == NULL) {
- link_files = NULL;
- } else {
- uri = nautilus_file_get_uri (target_file);
- link_files = g_hash_table_lookup (symbolic_links, uri);
- g_free (uri);
- }
- if (link_files) {
- return nautilus_file_list_copy (*link_files);
- }
- return NULL;
+ char *uri;
+ GList **link_files;
+
+ if (symbolic_links == NULL)
+ {
+ link_files = NULL;
+ }
+ else
+ {
+ uri = nautilus_file_get_uri (target_file);
+ link_files = g_hash_table_lookup (symbolic_links, uri);
+ g_free (uri);
+ }
+ if (link_files)
+ {
+ return nautilus_file_list_copy (*link_files);
+ }
+ return NULL;
}
static void
update_links_if_target (NautilusFile *target_file)
{
- GList *link_files, *p;
+ GList *link_files, *p;
- link_files = get_link_files (target_file);
- for (p = link_files; p != NULL; p = p->next) {
- update_link (NAUTILUS_FILE (p->data), target_file);
- }
- nautilus_file_list_free (link_files);
+ link_files = get_link_files (target_file);
+ for (p = link_files; p != NULL; p = p->next)
+ {
+ update_link (NAUTILUS_FILE (p->data), target_file);
+ }
+ nautilus_file_list_free (link_files);
}
static gboolean
update_info_internal (NautilusFile *file,
- GFileInfo *info,
- gboolean update_name)
-{
- GList *node;
- gboolean changed;
- gboolean is_symlink, is_hidden, is_mountpoint;
- gboolean has_permissions;
- guint32 permissions;
- gboolean can_read, can_write, can_execute, can_delete, can_trash, can_rename, can_mount, can_unmount, can_eject;
- gboolean can_start, can_start_degraded, can_stop, can_poll_for_media, is_media_check_automatic;
- GDriveStartStopType start_stop_type;
- gboolean thumbnailing_failed;
- int uid, gid;
- goffset size;
- int sort_order;
- time_t atime, mtime;
- time_t trash_time;
- GTimeVal g_trash_time;
- const char * time_string;
- const char *symlink_name, *mime_type, *selinux_context, *name, *thumbnail_path;
- GFileType file_type;
- GIcon *icon;
- char *old_activation_uri;
- const char *activation_uri;
- const char *description;
- const char *filesystem_id;
- const char *trash_orig_path;
- const char *group, *owner, *owner_real;
- gboolean free_owner, free_group;
-
- if (file->details->is_gone) {
- return FALSE;
- }
-
- if (info == NULL) {
- nautilus_file_mark_gone (file);
- return TRUE;
- }
-
- file->details->file_info_is_up_to_date = TRUE;
-
- /* FIXME bugzilla.gnome.org 42044: Need to let links that
- * point to the old name know that the file has been renamed.
- */
-
- remove_from_link_hash_table (file);
-
- changed = FALSE;
-
- if (!file->details->got_file_info) {
- changed = TRUE;
- }
- file->details->got_file_info = TRUE;
-
- changed |= nautilus_file_set_display_name (file,
- g_file_info_get_display_name (info),
- g_file_info_get_edit_name (info),
- FALSE);
-
- file_type = g_file_info_get_file_type (info);
- if (file->details->type != file_type) {
- changed = TRUE;
- }
- file->details->type = file_type;
-
- if (!file->details->got_custom_activation_uri &&
- !nautilus_file_is_in_trash (file)) {
- activation_uri = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
- if (activation_uri == NULL) {
- if (file->details->activation_uri) {
- g_free (file->details->activation_uri);
- file->details->activation_uri = NULL;
- changed = TRUE;
- }
- } else {
- old_activation_uri = file->details->activation_uri;
- file->details->activation_uri = g_strdup (activation_uri);
-
- if (old_activation_uri) {
- if (strcmp (old_activation_uri,
- file->details->activation_uri) != 0) {
- changed = TRUE;
- }
- g_free (old_activation_uri);
- } else {
- changed = TRUE;
- }
- }
- }
-
- is_symlink = g_file_info_get_is_symlink (info);
- if (file->details->is_symlink != is_symlink) {
- changed = TRUE;
- }
- file->details->is_symlink = is_symlink;
-
- is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
- if (file->details->is_hidden != is_hidden) {
- changed = TRUE;
- }
- file->details->is_hidden = is_hidden;
-
- is_mountpoint = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT);
- if (file->details->is_mountpoint != is_mountpoint) {
- changed = TRUE;
- }
- file->details->is_mountpoint = is_mountpoint;
-
- has_permissions = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE);
- permissions = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);;
- if (file->details->has_permissions != has_permissions ||
- file->details->permissions != permissions) {
- changed = TRUE;
- }
- file->details->has_permissions = has_permissions;
- file->details->permissions = permissions;
-
- /* We default to TRUE for this if we can't know */
- can_read = TRUE;
- can_write = TRUE;
- can_execute = TRUE;
- can_delete = TRUE;
- can_rename = TRUE;
- can_trash = FALSE;
- can_mount = FALSE;
- can_unmount = FALSE;
- can_eject = FALSE;
- can_start = FALSE;
- can_start_degraded = FALSE;
- can_stop = FALSE;
- can_poll_for_media = FALSE;
- is_media_check_automatic = FALSE;
- start_stop_type = G_DRIVE_START_STOP_TYPE_UNKNOWN;
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
- can_read = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
- can_write = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) {
- can_execute = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE)) {
- can_delete = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH)) {
- can_trash = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME)) {
- can_rename = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT)) {
- can_mount = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT)) {
- can_unmount = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT)) {
- can_eject = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START)) {
- can_start = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START_DEGRADED)) {
- can_start_degraded = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START_DEGRADED);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_STOP)) {
- can_stop = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_STOP);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_START_STOP_TYPE)) {
- start_stop_type = g_file_info_get_attribute_uint32 (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_START_STOP_TYPE);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_POLL)) {
- can_poll_for_media = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_CAN_POLL);
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC)) {
- is_media_check_automatic = g_file_info_get_attribute_boolean (info,
- G_FILE_ATTRIBUTE_MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC);
- }
- if (file->details->can_read != can_read ||
- file->details->can_write != can_write ||
- file->details->can_execute != can_execute ||
- file->details->can_delete != can_delete ||
- file->details->can_trash != can_trash ||
- file->details->can_rename != can_rename ||
- file->details->can_mount != can_mount ||
- file->details->can_unmount != can_unmount ||
- file->details->can_eject != can_eject ||
- file->details->can_start != can_start ||
- file->details->can_start_degraded != can_start_degraded ||
- file->details->can_stop != can_stop ||
- file->details->start_stop_type != start_stop_type ||
- file->details->can_poll_for_media != can_poll_for_media ||
- file->details->is_media_check_automatic != is_media_check_automatic) {
- changed = TRUE;
- }
-
- file->details->can_read = can_read;
- file->details->can_write = can_write;
- file->details->can_execute = can_execute;
- file->details->can_delete = can_delete;
- file->details->can_trash = can_trash;
- file->details->can_rename = can_rename;
- file->details->can_mount = can_mount;
- file->details->can_unmount = can_unmount;
- file->details->can_eject = can_eject;
- file->details->can_start = can_start;
- file->details->can_start_degraded = can_start_degraded;
- file->details->can_stop = can_stop;
- file->details->start_stop_type = start_stop_type;
- file->details->can_poll_for_media = can_poll_for_media;
- file->details->is_media_check_automatic = is_media_check_automatic;
-
- free_owner = FALSE;
- owner = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER);
- owner_real = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER_REAL);
- free_group = FALSE;
- group = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
-
- uid = -1;
- gid = -1;
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_UID)) {
- uid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID);
- if (owner == NULL) {
- free_owner = TRUE;
- owner = g_strdup_printf ("%d", uid);
- }
- }
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_GID)) {
- gid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID);
- if (group == NULL) {
- free_group = TRUE;
- group = g_strdup_printf ("%d", gid);
- }
- }
- if (file->details->uid != uid ||
- file->details->gid != gid) {
- changed = TRUE;
- }
- file->details->uid = uid;
- file->details->gid = gid;
-
- if (g_strcmp0 (eel_ref_str_peek (file->details->owner), owner) != 0) {
- changed = TRUE;
- eel_ref_str_unref (file->details->owner);
- file->details->owner = eel_ref_str_get_unique (owner);
- }
-
- if (g_strcmp0 (eel_ref_str_peek (file->details->owner_real), owner_real) != 0) {
- changed = TRUE;
- eel_ref_str_unref (file->details->owner_real);
- file->details->owner_real = eel_ref_str_get_unique (owner_real);
- }
-
- if (g_strcmp0 (eel_ref_str_peek (file->details->group), group) != 0) {
- changed = TRUE;
- eel_ref_str_unref (file->details->group);
- file->details->group = eel_ref_str_get_unique (group);
- }
-
- if (free_owner) {
- g_free ((char *)owner);
- }
- if (free_group) {
- g_free ((char *)group);
- }
-
- size = -1;
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) {
- size = g_file_info_get_size (info);
- }
- if (file->details->size != size) {
- changed = TRUE;
- }
- file->details->size = size;
-
- sort_order = g_file_info_get_sort_order (info);
- if (file->details->sort_order != sort_order) {
- changed = TRUE;
- }
- file->details->sort_order = sort_order;
-
- atime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
- mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- if (file->details->atime != atime ||
- file->details->mtime != mtime) {
- if (file->details->thumbnail == NULL) {
- file->details->thumbnail_is_up_to_date = FALSE;
- }
-
- changed = TRUE;
- }
- file->details->atime = atime;
- file->details->mtime = mtime;
-
- if (file->details->thumbnail != NULL &&
- file->details->thumbnail_mtime != 0 &&
- file->details->thumbnail_mtime != mtime) {
- file->details->thumbnail_is_up_to_date = FALSE;
- changed = TRUE;
- }
-
- icon = g_file_info_get_icon (info);
- if (!g_icon_equal (icon, file->details->icon)) {
- changed = TRUE;
-
- if (file->details->icon) {
- g_object_unref (file->details->icon);
- }
- file->details->icon = g_object_ref (icon);
- }
-
- thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
- if (g_strcmp0 (file->details->thumbnail_path, thumbnail_path) != 0) {
- changed = TRUE;
- g_free (file->details->thumbnail_path);
- file->details->thumbnail_path = g_strdup (thumbnail_path);
- }
-
- thumbnailing_failed = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
- if (file->details->thumbnailing_failed != thumbnailing_failed) {
- changed = TRUE;
- file->details->thumbnailing_failed = thumbnailing_failed;
- }
-
- symlink_name = g_file_info_get_symlink_target (info);
- if (g_strcmp0 (file->details->symlink_name, symlink_name) != 0) {
- changed = TRUE;
- g_free (file->details->symlink_name);
- file->details->symlink_name = g_strdup (symlink_name);
- }
-
- mime_type = g_file_info_get_content_type (info);
- if (g_strcmp0 (eel_ref_str_peek (file->details->mime_type), mime_type) != 0) {
- changed = TRUE;
- eel_ref_str_unref (file->details->mime_type);
- file->details->mime_type = eel_ref_str_get_unique (mime_type);
- }
-
- selinux_context = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_SELINUX_CONTEXT);
- if (g_strcmp0 (file->details->selinux_context, selinux_context) != 0) {
- changed = TRUE;
- g_free (file->details->selinux_context);
- file->details->selinux_context = g_strdup (selinux_context);
- }
-
- description = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
- if (g_strcmp0 (file->details->description, description) != 0) {
- changed = TRUE;
- g_free (file->details->description);
- file->details->description = g_strdup (description);
- }
-
- filesystem_id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
- if (g_strcmp0 (eel_ref_str_peek (file->details->filesystem_id), filesystem_id) != 0) {
- changed = TRUE;
- eel_ref_str_unref (file->details->filesystem_id);
- file->details->filesystem_id = eel_ref_str_get_unique (filesystem_id);
- }
-
- trash_time = 0;
- time_string = g_file_info_get_attribute_string (info, "trash::deletion-date");
- if (time_string != NULL) {
- g_time_val_from_iso8601 (time_string, &g_trash_time);
- trash_time = g_trash_time.tv_sec;
- }
- if (file->details->trash_time != trash_time) {
- changed = TRUE;
- file->details->trash_time = trash_time;
- }
-
- trash_orig_path = g_file_info_get_attribute_byte_string (info, "trash::orig-path");
- if (g_strcmp0 (file->details->trash_orig_path, trash_orig_path) != 0) {
- changed = TRUE;
- g_free (file->details->trash_orig_path);
- file->details->trash_orig_path = g_strdup (trash_orig_path);
- }
-
- changed |=
- nautilus_file_update_metadata_from_info (file, info);
-
- if (update_name) {
- name = g_file_info_get_name (info);
- if (file->details->name == NULL ||
- strcmp (eel_ref_str_peek (file->details->name), name) != 0) {
- changed = TRUE;
-
- node = nautilus_directory_begin_file_name_change
- (file->details->directory, file);
-
- eel_ref_str_unref (file->details->name);
- if (g_strcmp0 (eel_ref_str_peek (file->details->display_name),
- name) == 0) {
- file->details->name = eel_ref_str_ref (file->details->display_name);
- } else {
- file->details->name = eel_ref_str_new (name);
- }
-
- if (!file->details->got_custom_display_name &&
- g_file_info_get_display_name (info) == NULL) {
- /* If the file info's display name is NULL,
- * nautilus_file_set_display_name() did
- * not unset the display name.
- */
- nautilus_file_clear_display_name (file);
- }
-
- nautilus_directory_end_file_name_change
- (file->details->directory, file, node);
- }
- }
-
- if (changed) {
- add_to_link_hash_table (file);
-
- update_links_if_target (file);
- }
-
- return changed;
+ GFileInfo *info,
+ gboolean update_name)
+{
+ GList *node;
+ gboolean changed;
+ gboolean is_symlink, is_hidden, is_mountpoint;
+ gboolean has_permissions;
+ guint32 permissions;
+ gboolean can_read, can_write, can_execute, can_delete, can_trash, can_rename, can_mount, can_unmount, can_eject;
+ gboolean can_start, can_start_degraded, can_stop, can_poll_for_media, is_media_check_automatic;
+ GDriveStartStopType start_stop_type;
+ gboolean thumbnailing_failed;
+ int uid, gid;
+ goffset size;
+ int sort_order;
+ time_t atime, mtime;
+ time_t trash_time;
+ GTimeVal g_trash_time;
+ const char *time_string;
+ const char *symlink_name, *mime_type, *selinux_context, *name, *thumbnail_path;
+ GFileType file_type;
+ GIcon *icon;
+ char *old_activation_uri;
+ const char *activation_uri;
+ const char *description;
+ const char *filesystem_id;
+ const char *trash_orig_path;
+ const char *group, *owner, *owner_real;
+ gboolean free_owner, free_group;
+
+ if (file->details->is_gone)
+ {
+ return FALSE;
+ }
+
+ if (info == NULL)
+ {
+ nautilus_file_mark_gone (file);
+ return TRUE;
+ }
+
+ file->details->file_info_is_up_to_date = TRUE;
+
+ /* FIXME bugzilla.gnome.org 42044: Need to let links that
+ * point to the old name know that the file has been renamed.
+ */
+
+ remove_from_link_hash_table (file);
+
+ changed = FALSE;
+
+ if (!file->details->got_file_info)
+ {
+ changed = TRUE;
+ }
+ file->details->got_file_info = TRUE;
+
+ changed |= nautilus_file_set_display_name (file,
+ g_file_info_get_display_name (info),
+ g_file_info_get_edit_name (info),
+ FALSE);
+
+ file_type = g_file_info_get_file_type (info);
+ if (file->details->type != file_type)
+ {
+ changed = TRUE;
+ }
+ file->details->type = file_type;
+
+ if (!file->details->got_custom_activation_uri &&
+ !nautilus_file_is_in_trash (file))
+ {
+ activation_uri = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI);
+ if (activation_uri == NULL)
+ {
+ if (file->details->activation_uri)
+ {
+ g_free (file->details->activation_uri);
+ file->details->activation_uri = NULL;
+ changed = TRUE;
+ }
+ }
+ else
+ {
+ old_activation_uri = file->details->activation_uri;
+ file->details->activation_uri = g_strdup (activation_uri);
+
+ if (old_activation_uri)
+ {
+ if (strcmp (old_activation_uri,
+ file->details->activation_uri) != 0)
+ {
+ changed = TRUE;
+ }
+ g_free (old_activation_uri);
+ }
+ else
+ {
+ changed = TRUE;
+ }
+ }
+ }
+
+ is_symlink = g_file_info_get_is_symlink (info);
+ if (file->details->is_symlink != is_symlink)
+ {
+ changed = TRUE;
+ }
+ file->details->is_symlink = is_symlink;
+
+ is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
+ if (file->details->is_hidden != is_hidden)
+ {
+ changed = TRUE;
+ }
+ file->details->is_hidden = is_hidden;
+
+ is_mountpoint = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT);
+ if (file->details->is_mountpoint != is_mountpoint)
+ {
+ changed = TRUE;
+ }
+ file->details->is_mountpoint = is_mountpoint;
+
+ has_permissions = g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+ permissions = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+ ;
+ if (file->details->has_permissions != has_permissions ||
+ file->details->permissions != permissions)
+ {
+ changed = TRUE;
+ }
+ file->details->has_permissions = has_permissions;
+ file->details->permissions = permissions;
+
+ /* We default to TRUE for this if we can't know */
+ can_read = TRUE;
+ can_write = TRUE;
+ can_execute = TRUE;
+ can_delete = TRUE;
+ can_rename = TRUE;
+ can_trash = FALSE;
+ can_mount = FALSE;
+ can_unmount = FALSE;
+ can_eject = FALSE;
+ can_start = FALSE;
+ can_start_degraded = FALSE;
+ can_stop = FALSE;
+ can_poll_for_media = FALSE;
+ is_media_check_automatic = FALSE;
+ start_stop_type = G_DRIVE_START_STOP_TYPE_UNKNOWN;
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ))
+ {
+ can_read = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_READ);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
+ {
+ can_write = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE))
+ {
+ can_execute = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE))
+ {
+ can_delete = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH))
+ {
+ can_trash = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME))
+ {
+ can_rename = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT))
+ {
+ can_mount = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT))
+ {
+ can_unmount = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT))
+ {
+ can_eject = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START))
+ {
+ can_start = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START_DEGRADED))
+ {
+ can_start_degraded = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_START_DEGRADED);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_STOP))
+ {
+ can_stop = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_STOP);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_START_STOP_TYPE))
+ {
+ start_stop_type = g_file_info_get_attribute_uint32 (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_START_STOP_TYPE);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_CAN_POLL))
+ {
+ can_poll_for_media = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_CAN_POLL);
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC))
+ {
+ is_media_check_automatic = g_file_info_get_attribute_boolean (info,
+ G_FILE_ATTRIBUTE_MOUNTABLE_IS_MEDIA_CHECK_AUTOMATIC);
+ }
+ if (file->details->can_read != can_read ||
+ file->details->can_write != can_write ||
+ file->details->can_execute != can_execute ||
+ file->details->can_delete != can_delete ||
+ file->details->can_trash != can_trash ||
+ file->details->can_rename != can_rename ||
+ file->details->can_mount != can_mount ||
+ file->details->can_unmount != can_unmount ||
+ file->details->can_eject != can_eject ||
+ file->details->can_start != can_start ||
+ file->details->can_start_degraded != can_start_degraded ||
+ file->details->can_stop != can_stop ||
+ file->details->start_stop_type != start_stop_type ||
+ file->details->can_poll_for_media != can_poll_for_media ||
+ file->details->is_media_check_automatic != is_media_check_automatic)
+ {
+ changed = TRUE;
+ }
+
+ file->details->can_read = can_read;
+ file->details->can_write = can_write;
+ file->details->can_execute = can_execute;
+ file->details->can_delete = can_delete;
+ file->details->can_trash = can_trash;
+ file->details->can_rename = can_rename;
+ file->details->can_mount = can_mount;
+ file->details->can_unmount = can_unmount;
+ file->details->can_eject = can_eject;
+ file->details->can_start = can_start;
+ file->details->can_start_degraded = can_start_degraded;
+ file->details->can_stop = can_stop;
+ file->details->start_stop_type = start_stop_type;
+ file->details->can_poll_for_media = can_poll_for_media;
+ file->details->is_media_check_automatic = is_media_check_automatic;
+
+ free_owner = FALSE;
+ owner = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER);
+ owner_real = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_USER_REAL);
+ free_group = FALSE;
+ group = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_OWNER_GROUP);
+
+ uid = -1;
+ gid = -1;
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_UID))
+ {
+ uid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID);
+ if (owner == NULL)
+ {
+ free_owner = TRUE;
+ owner = g_strdup_printf ("%d", uid);
+ }
+ }
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_GID))
+ {
+ gid = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID);
+ if (group == NULL)
+ {
+ free_group = TRUE;
+ group = g_strdup_printf ("%d", gid);
+ }
+ }
+ if (file->details->uid != uid ||
+ file->details->gid != gid)
+ {
+ changed = TRUE;
+ }
+ file->details->uid = uid;
+ file->details->gid = gid;
+
+ if (g_strcmp0 (eel_ref_str_peek (file->details->owner), owner) != 0)
+ {
+ changed = TRUE;
+ eel_ref_str_unref (file->details->owner);
+ file->details->owner = eel_ref_str_get_unique (owner);
+ }
+
+ if (g_strcmp0 (eel_ref_str_peek (file->details->owner_real), owner_real) != 0)
+ {
+ changed = TRUE;
+ eel_ref_str_unref (file->details->owner_real);
+ file->details->owner_real = eel_ref_str_get_unique (owner_real);
+ }
+
+ if (g_strcmp0 (eel_ref_str_peek (file->details->group), group) != 0)
+ {
+ changed = TRUE;
+ eel_ref_str_unref (file->details->group);
+ file->details->group = eel_ref_str_get_unique (group);
+ }
+
+ if (free_owner)
+ {
+ g_free ((char *) owner);
+ }
+ if (free_group)
+ {
+ g_free ((char *) group);
+ }
+
+ size = -1;
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
+ {
+ size = g_file_info_get_size (info);
+ }
+ if (file->details->size != size)
+ {
+ changed = TRUE;
+ }
+ file->details->size = size;
+
+ sort_order = g_file_info_get_sort_order (info);
+ if (file->details->sort_order != sort_order)
+ {
+ changed = TRUE;
+ }
+ file->details->sort_order = sort_order;
+
+ atime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_ACCESS);
+ mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ if (file->details->atime != atime ||
+ file->details->mtime != mtime)
+ {
+ if (file->details->thumbnail == NULL)
+ {
+ file->details->thumbnail_is_up_to_date = FALSE;
+ }
+
+ changed = TRUE;
+ }
+ file->details->atime = atime;
+ file->details->mtime = mtime;
+
+ if (file->details->thumbnail != NULL &&
+ file->details->thumbnail_mtime != 0 &&
+ file->details->thumbnail_mtime != mtime)
+ {
+ file->details->thumbnail_is_up_to_date = FALSE;
+ changed = TRUE;
+ }
+
+ icon = g_file_info_get_icon (info);
+ if (!g_icon_equal (icon, file->details->icon))
+ {
+ changed = TRUE;
+
+ if (file->details->icon)
+ {
+ g_object_unref (file->details->icon);
+ }
+ file->details->icon = g_object_ref (icon);
+ }
+
+ thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
+ if (g_strcmp0 (file->details->thumbnail_path, thumbnail_path) != 0)
+ {
+ changed = TRUE;
+ g_free (file->details->thumbnail_path);
+ file->details->thumbnail_path = g_strdup (thumbnail_path);
+ }
+
+ thumbnailing_failed = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
+ if (file->details->thumbnailing_failed != thumbnailing_failed)
+ {
+ changed = TRUE;
+ file->details->thumbnailing_failed = thumbnailing_failed;
+ }
+
+ symlink_name = g_file_info_get_symlink_target (info);
+ if (g_strcmp0 (file->details->symlink_name, symlink_name) != 0)
+ {
+ changed = TRUE;
+ g_free (file->details->symlink_name);
+ file->details->symlink_name = g_strdup (symlink_name);
+ }
+
+ mime_type = g_file_info_get_content_type (info);
+ if (g_strcmp0 (eel_ref_str_peek (file->details->mime_type), mime_type) != 0)
+ {
+ changed = TRUE;
+ eel_ref_str_unref (file->details->mime_type);
+ file->details->mime_type = eel_ref_str_get_unique (mime_type);
+ }
+
+ selinux_context = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_SELINUX_CONTEXT);
+ if (g_strcmp0 (file->details->selinux_context, selinux_context) != 0)
+ {
+ changed = TRUE;
+ g_free (file->details->selinux_context);
+ file->details->selinux_context = g_strdup (selinux_context);
+ }
+
+ description = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_DESCRIPTION);
+ if (g_strcmp0 (file->details->description, description) != 0)
+ {
+ changed = TRUE;
+ g_free (file->details->description);
+ file->details->description = g_strdup (description);
+ }
+
+ filesystem_id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
+ if (g_strcmp0 (eel_ref_str_peek (file->details->filesystem_id), filesystem_id) != 0)
+ {
+ changed = TRUE;
+ eel_ref_str_unref (file->details->filesystem_id);
+ file->details->filesystem_id = eel_ref_str_get_unique (filesystem_id);
+ }
+
+ trash_time = 0;
+ time_string = g_file_info_get_attribute_string (info, "trash::deletion-date");
+ if (time_string != NULL)
+ {
+ g_time_val_from_iso8601 (time_string, &g_trash_time);
+ trash_time = g_trash_time.tv_sec;
+ }
+ if (file->details->trash_time != trash_time)
+ {
+ changed = TRUE;
+ file->details->trash_time = trash_time;
+ }
+
+ trash_orig_path = g_file_info_get_attribute_byte_string (info, "trash::orig-path");
+ if (g_strcmp0 (file->details->trash_orig_path, trash_orig_path) != 0)
+ {
+ changed = TRUE;
+ g_free (file->details->trash_orig_path);
+ file->details->trash_orig_path = g_strdup (trash_orig_path);
+ }
+
+ changed |=
+ nautilus_file_update_metadata_from_info (file, info);
+
+ if (update_name)
+ {
+ name = g_file_info_get_name (info);
+ if (file->details->name == NULL ||
+ strcmp (eel_ref_str_peek (file->details->name), name) != 0)
+ {
+ changed = TRUE;
+
+ node = nautilus_directory_begin_file_name_change
+ (file->details->directory, file);
+
+ eel_ref_str_unref (file->details->name);
+ if (g_strcmp0 (eel_ref_str_peek (file->details->display_name),
+ name) == 0)
+ {
+ file->details->name = eel_ref_str_ref (file->details->display_name);
+ }
+ else
+ {
+ file->details->name = eel_ref_str_new (name);
+ }
+
+ if (!file->details->got_custom_display_name &&
+ g_file_info_get_display_name (info) == NULL)
+ {
+ /* If the file info's display name is NULL,
+ * nautilus_file_set_display_name() did
+ * not unset the display name.
+ */
+ nautilus_file_clear_display_name (file);
+ }
+
+ nautilus_directory_end_file_name_change
+ (file->details->directory, file, node);
+ }
+ }
+
+ if (changed)
+ {
+ add_to_link_hash_table (file);
+
+ update_links_if_target (file);
+ }
+
+ return changed;
}
static gboolean
update_info_and_name (NautilusFile *file,
- GFileInfo *info)
+ GFileInfo *info)
{
- return update_info_internal (file, info, TRUE);
+ return update_info_internal (file, info, TRUE);
}
gboolean
nautilus_file_update_info (NautilusFile *file,
- GFileInfo *info)
+ GFileInfo *info)
{
- return update_info_internal (file, info, FALSE);
+ return update_info_internal (file, info, FALSE);
}
static gboolean
update_name_internal (NautilusFile *file,
- const char *name,
- gboolean in_directory)
+ const char *name,
+ gboolean in_directory)
{
- GList *node;
+ GList *node;
- g_assert (name != NULL);
+ g_assert (name != NULL);
- if (file->details->is_gone) {
- return FALSE;
- }
+ if (file->details->is_gone)
+ {
+ return FALSE;
+ }
+
+ if (name_is (file, name))
+ {
+ return FALSE;
+ }
- if (name_is (file, name)) {
- return FALSE;
- }
-
- node = NULL;
- if (in_directory) {
- node = nautilus_directory_begin_file_name_change
- (file->details->directory, file);
- }
-
- eel_ref_str_unref (file->details->name);
- file->details->name = eel_ref_str_new (name);
+ node = NULL;
+ if (in_directory)
+ {
+ node = nautilus_directory_begin_file_name_change
+ (file->details->directory, file);
+ }
- if (!file->details->got_custom_display_name) {
- nautilus_file_clear_display_name (file);
- }
+ eel_ref_str_unref (file->details->name);
+ file->details->name = eel_ref_str_new (name);
- if (in_directory) {
- nautilus_directory_end_file_name_change
- (file->details->directory, file, node);
- }
+ if (!file->details->got_custom_display_name)
+ {
+ nautilus_file_clear_display_name (file);
+ }
- return TRUE;
+ if (in_directory)
+ {
+ nautilus_directory_end_file_name_change
+ (file->details->directory, file, node);
+ }
+
+ return TRUE;
}
gboolean
-nautilus_file_update_name (NautilusFile *file, const char *name)
+nautilus_file_update_name (NautilusFile *file,
+ const char *name)
{
- gboolean ret;
-
- ret = update_name_internal (file, name, TRUE);
+ gboolean ret;
+
+ ret = update_name_internal (file, name, TRUE);
- if (ret) {
- update_links_if_target (file);
- }
+ if (ret)
+ {
+ update_links_if_target (file);
+ }
- return ret;
+ return ret;
}
gboolean
-nautilus_file_update_name_and_directory (NautilusFile *file,
- const char *name,
- NautilusDirectory *new_directory)
-{
- NautilusDirectory *old_directory;
- FileMonitors *monitors;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (file->details->directory), FALSE);
- g_return_val_if_fail (!file->details->is_gone, FALSE);
- g_return_val_if_fail (!nautilus_file_is_self_owned (file), FALSE);
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (new_directory), FALSE);
-
- old_directory = file->details->directory;
- if (old_directory == new_directory) {
- if (name) {
- return update_name_internal (file, name, TRUE);
- } else {
- return FALSE;
- }
- }
+nautilus_file_update_name_and_directory (NautilusFile *file,
+ const char *name,
+ NautilusDirectory *new_directory)
+{
+ NautilusDirectory *old_directory;
+ FileMonitors *monitors;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (file->details->directory), FALSE);
+ g_return_val_if_fail (!file->details->is_gone, FALSE);
+ g_return_val_if_fail (!nautilus_file_is_self_owned (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (new_directory), FALSE);
+
+ old_directory = file->details->directory;
+ if (old_directory == new_directory)
+ {
+ if (name)
+ {
+ return update_name_internal (file, name, TRUE);
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
- nautilus_file_ref (file);
+ nautilus_file_ref (file);
- /* FIXME bugzilla.gnome.org 42044: Need to let links that
- * point to the old name know that the file has been moved.
- */
+ /* FIXME bugzilla.gnome.org 42044: Need to let links that
+ * point to the old name know that the file has been moved.
+ */
- remove_from_link_hash_table (file);
+ remove_from_link_hash_table (file);
- monitors = nautilus_directory_remove_file_monitors (old_directory, file);
- nautilus_directory_remove_file (old_directory, file);
+ monitors = nautilus_directory_remove_file_monitors (old_directory, file);
+ nautilus_directory_remove_file (old_directory, file);
- nautilus_file_set_directory (file, new_directory);
+ nautilus_file_set_directory (file, new_directory);
- if (name) {
- update_name_internal (file, name, FALSE);
- }
+ if (name)
+ {
+ update_name_internal (file, name, FALSE);
+ }
- nautilus_directory_add_file (new_directory, file);
- nautilus_directory_add_file_monitors (new_directory, file, monitors);
+ nautilus_directory_add_file (new_directory, file);
+ nautilus_directory_add_file_monitors (new_directory, file, monitors);
- add_to_link_hash_table (file);
+ add_to_link_hash_table (file);
- update_links_if_target (file);
+ update_links_if_target (file);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
- return TRUE;
+ return TRUE;
}
static Knowledge
get_item_count (NautilusFile *file,
- guint *count)
+ guint *count)
{
- gboolean known, unreadable;
+ gboolean known, unreadable;
- known = nautilus_file_get_directory_item_count
- (file, count, &unreadable);
- if (!known) {
- return UNKNOWN;
- }
- if (unreadable) {
- return UNKNOWABLE;
- }
- return KNOWN;
+ known = nautilus_file_get_directory_item_count
+ (file, count, &unreadable);
+ if (!known)
+ {
+ return UNKNOWN;
+ }
+ if (unreadable)
+ {
+ return UNKNOWABLE;
+ }
+ return KNOWN;
}
static Knowledge
get_size (NautilusFile *file,
- goffset *size)
-{
- /* If we tried and failed, then treat it like there is no size
- * to know.
- */
- if (file->details->get_info_failed) {
- return UNKNOWABLE;
- }
-
- /* If the info is NULL that means we haven't even tried yet,
- * so it's just unknown, not unknowable.
- */
- if (!file->details->got_file_info) {
- return UNKNOWN;
- }
-
- /* If we got info with no size in it, it means there is no
- * such thing as a size as far as gnome-vfs is concerned,
- * so "unknowable".
- */
- if (file->details->size == -1) {
- return UNKNOWABLE;
- }
-
- /* We have a size! */
- *size = file->details->size;
- return KNOWN;
+ goffset *size)
+{
+ /* If we tried and failed, then treat it like there is no size
+ * to know.
+ */
+ if (file->details->get_info_failed)
+ {
+ return UNKNOWABLE;
+ }
+
+ /* If the info is NULL that means we haven't even tried yet,
+ * so it's just unknown, not unknowable.
+ */
+ if (!file->details->got_file_info)
+ {
+ return UNKNOWN;
+ }
+
+ /* If we got info with no size in it, it means there is no
+ * such thing as a size as far as gnome-vfs is concerned,
+ * so "unknowable".
+ */
+ if (file->details->size == -1)
+ {
+ return UNKNOWABLE;
+ }
+
+ /* We have a size! */
+ *size = file->details->size;
+ return KNOWN;
}
static Knowledge
-get_time (NautilusFile *file,
- time_t *time_out,
- NautilusDateType type)
-{
- time_t time;
-
- /* If we tried and failed, then treat it like there is no size
- * to know.
- */
- if (file->details->get_info_failed) {
- return UNKNOWABLE;
- }
-
- /* If the info is NULL that means we haven't even tried yet,
- * so it's just unknown, not unknowable.
- */
- if (!file->details->got_file_info) {
- return UNKNOWN;
- }
-
- switch (type) {
- case NAUTILUS_DATE_TYPE_MODIFIED:
- time = file->details->mtime;
- break;
- case NAUTILUS_DATE_TYPE_ACCESSED:
- time = file->details->atime;
- break;
- case NAUTILUS_DATE_TYPE_TRASHED:
- time = file->details->trash_time;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- *time_out = time;
-
- /* If we got info with no modification time in it, it means
- * there is no such thing as a modification time as far as
- * gnome-vfs is concerned, so "unknowable".
- */
- if (time == 0) {
- return UNKNOWABLE;
- }
- return KNOWN;
-}
-
-static int
-compare_directories_by_count (NautilusFile *file_1, NautilusFile *file_2)
-{
- /* Sort order:
- * Directories with unknown # of items
- * Directories with "unknowable" # of items
- * Directories with 0 items
- * Directories with n items
- */
-
- Knowledge count_known_1, count_known_2;
- guint count_1, count_2;
+get_time (NautilusFile *file,
+ time_t *time_out,
+ NautilusDateType type)
+{
+ time_t time;
+
+ /* If we tried and failed, then treat it like there is no size
+ * to know.
+ */
+ if (file->details->get_info_failed)
+ {
+ return UNKNOWABLE;
+ }
+
+ /* If the info is NULL that means we haven't even tried yet,
+ * so it's just unknown, not unknowable.
+ */
+ if (!file->details->got_file_info)
+ {
+ return UNKNOWN;
+ }
+
+ switch (type)
+ {
+ case NAUTILUS_DATE_TYPE_MODIFIED:
+ {
+ time = file->details->mtime;
+ }
+ break;
- count_known_1 = get_item_count (file_1, &count_1);
- count_known_2 = get_item_count (file_2, &count_2);
+ case NAUTILUS_DATE_TYPE_ACCESSED:
+ {
+ time = file->details->atime;
+ }
+ break;
- if (count_known_1 > count_known_2) {
- return -1;
- }
- if (count_known_1 < count_known_2) {
- return +1;
- }
+ case NAUTILUS_DATE_TYPE_TRASHED:
+ {
+ time = file->details->trash_time;
+ }
+ break;
- /* count_known_1 and count_known_2 are equal now. Check if count
- * details are UNKNOWABLE or UNKNOWN.
- */
- if (count_known_1 == UNKNOWABLE || count_known_1 == UNKNOWN) {
- return 0;
- }
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
- if (count_1 < count_2) {
- return -1;
- }
- if (count_1 > count_2) {
- return +1;
- }
+ *time_out = time;
- return 0;
+ /* If we got info with no modification time in it, it means
+ * there is no such thing as a modification time as far as
+ * gnome-vfs is concerned, so "unknowable".
+ */
+ if (time == 0)
+ {
+ return UNKNOWABLE;
+ }
+ return KNOWN;
}
static int
-compare_files_by_size (NautilusFile *file_1, NautilusFile *file_2)
-{
- /* Sort order:
- * Files with unknown size.
- * Files with "unknowable" size.
- * Files with smaller sizes.
- * Files with large sizes.
- */
-
- Knowledge size_known_1, size_known_2;
- goffset size_1 = 0, size_2 = 0;
-
- size_known_1 = get_size (file_1, &size_1);
- size_known_2 = get_size (file_2, &size_2);
-
- if (size_known_1 > size_known_2) {
- return -1;
- }
- if (size_known_1 < size_known_2) {
- return +1;
- }
-
- /* size_known_1 and size_known_2 are equal now. Check if size
- * details are UNKNOWABLE or UNKNOWN
- */
- if (size_known_1 == UNKNOWABLE || size_known_1 == UNKNOWN) {
- return 0;
- }
-
- if (size_1 < size_2) {
- return -1;
- }
- if (size_1 > size_2) {
- return +1;
- }
-
- return 0;
+compare_directories_by_count (NautilusFile *file_1,
+ NautilusFile *file_2)
+{
+ /* Sort order:
+ * Directories with unknown # of items
+ * Directories with "unknowable" # of items
+ * Directories with 0 items
+ * Directories with n items
+ */
+
+ Knowledge count_known_1, count_known_2;
+ guint count_1, count_2;
+
+ count_known_1 = get_item_count (file_1, &count_1);
+ count_known_2 = get_item_count (file_2, &count_2);
+
+ if (count_known_1 > count_known_2)
+ {
+ return -1;
+ }
+ if (count_known_1 < count_known_2)
+ {
+ return +1;
+ }
+
+ /* count_known_1 and count_known_2 are equal now. Check if count
+ * details are UNKNOWABLE or UNKNOWN.
+ */
+ if (count_known_1 == UNKNOWABLE || count_known_1 == UNKNOWN)
+ {
+ return 0;
+ }
+
+ if (count_1 < count_2)
+ {
+ return -1;
+ }
+ if (count_1 > count_2)
+ {
+ return +1;
+ }
+
+ return 0;
}
static int
-compare_by_size (NautilusFile *file_1, NautilusFile *file_2)
-{
- /* Sort order:
- * Directories with n items
- * Directories with 0 items
- * Directories with "unknowable" # of items
- * Directories with unknown # of items
- * Files with large sizes.
- * Files with smaller sizes.
- * Files with "unknowable" size.
- * Files with unknown size.
- */
-
- gboolean is_directory_1, is_directory_2;
-
- is_directory_1 = nautilus_file_is_directory (file_1);
- is_directory_2 = nautilus_file_is_directory (file_2);
-
- if (is_directory_1 && !is_directory_2) {
- return -1;
- }
- if (is_directory_2 && !is_directory_1) {
- return +1;
- }
-
- if (is_directory_1) {
- return compare_directories_by_count (file_1, file_2);
- } else {
- return compare_files_by_size (file_1, file_2);
- }
+compare_files_by_size (NautilusFile *file_1,
+ NautilusFile *file_2)
+{
+ /* Sort order:
+ * Files with unknown size.
+ * Files with "unknowable" size.
+ * Files with smaller sizes.
+ * Files with large sizes.
+ */
+
+ Knowledge size_known_1, size_known_2;
+ goffset size_1 = 0, size_2 = 0;
+
+ size_known_1 = get_size (file_1, &size_1);
+ size_known_2 = get_size (file_2, &size_2);
+
+ if (size_known_1 > size_known_2)
+ {
+ return -1;
+ }
+ if (size_known_1 < size_known_2)
+ {
+ return +1;
+ }
+
+ /* size_known_1 and size_known_2 are equal now. Check if size
+ * details are UNKNOWABLE or UNKNOWN
+ */
+ if (size_known_1 == UNKNOWABLE || size_known_1 == UNKNOWN)
+ {
+ return 0;
+ }
+
+ if (size_1 < size_2)
+ {
+ return -1;
+ }
+ if (size_1 > size_2)
+ {
+ return +1;
+ }
+
+ return 0;
}
static int
-compare_by_display_name (NautilusFile *file_1, NautilusFile *file_2)
-{
- const char *name_1, *name_2;
- const char *key_1, *key_2;
- gboolean sort_last_1, sort_last_2;
- int compare;
-
- name_1 = nautilus_file_peek_display_name (file_1);
- name_2 = nautilus_file_peek_display_name (file_2);
-
- sort_last_1 = name_1[0] == SORT_LAST_CHAR1 || name_1[0] == SORT_LAST_CHAR2;
- sort_last_2 = name_2[0] == SORT_LAST_CHAR1 || name_2[0] == SORT_LAST_CHAR2;
-
- if (sort_last_1 && !sort_last_2) {
- compare = +1;
- } else if (!sort_last_1 && sort_last_2) {
- compare = -1;
- } else {
- key_1 = nautilus_file_peek_display_name_collation_key (file_1);
- key_2 = nautilus_file_peek_display_name_collation_key (file_2);
- compare = strcmp (key_1, key_2);
- }
+compare_by_size (NautilusFile *file_1,
+ NautilusFile *file_2)
+{
+ /* Sort order:
+ * Directories with n items
+ * Directories with 0 items
+ * Directories with "unknowable" # of items
+ * Directories with unknown # of items
+ * Files with large sizes.
+ * Files with smaller sizes.
+ * Files with "unknowable" size.
+ * Files with unknown size.
+ */
+
+ gboolean is_directory_1, is_directory_2;
+
+ is_directory_1 = nautilus_file_is_directory (file_1);
+ is_directory_2 = nautilus_file_is_directory (file_2);
+
+ if (is_directory_1 && !is_directory_2)
+ {
+ return -1;
+ }
+ if (is_directory_2 && !is_directory_1)
+ {
+ return +1;
+ }
+
+ if (is_directory_1)
+ {
+ return compare_directories_by_count (file_1, file_2);
+ }
+ else
+ {
+ return compare_files_by_size (file_1, file_2);
+ }
+}
- return compare;
+static int
+compare_by_display_name (NautilusFile *file_1,
+ NautilusFile *file_2)
+{
+ const char *name_1, *name_2;
+ const char *key_1, *key_2;
+ gboolean sort_last_1, sort_last_2;
+ int compare;
+
+ name_1 = nautilus_file_peek_display_name (file_1);
+ name_2 = nautilus_file_peek_display_name (file_2);
+
+ sort_last_1 = name_1[0] == SORT_LAST_CHAR1 || name_1[0] == SORT_LAST_CHAR2;
+ sort_last_2 = name_2[0] == SORT_LAST_CHAR1 || name_2[0] == SORT_LAST_CHAR2;
+
+ if (sort_last_1 && !sort_last_2)
+ {
+ compare = +1;
+ }
+ else if (!sort_last_1 && sort_last_2)
+ {
+ compare = -1;
+ }
+ else
+ {
+ key_1 = nautilus_file_peek_display_name_collation_key (file_1);
+ key_2 = nautilus_file_peek_display_name_collation_key (file_2);
+ compare = strcmp (key_1, key_2);
+ }
+
+ return compare;
}
static int
-compare_by_directory_name (NautilusFile *file_1, NautilusFile *file_2)
+compare_by_directory_name (NautilusFile *file_1,
+ NautilusFile *file_2)
{
- return strcmp (file_1->details->directory_name_collation_key,
- file_2->details->directory_name_collation_key);
+ return strcmp (file_1->details->directory_name_collation_key,
+ file_2->details->directory_name_collation_key);
}
static GList *
prepend_automatic_keywords (NautilusFile *file,
- GList *names)
-{
- /* Prepend in reverse order. */
- NautilusFile *parent;
-
- parent = nautilus_file_get_parent (file);
-
- /* Trash files are assumed to be read-only,
- * so we want to ignore them here. */
- if (!nautilus_file_can_write (file) &&
- !nautilus_file_is_in_trash (file) &&
- (parent == NULL || nautilus_file_can_write (parent))) {
- names = g_list_prepend
- (names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE));
- }
- if (!nautilus_file_can_read (file)) {
- names = g_list_prepend
- (names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_CANT_READ));
- }
- if (nautilus_file_is_symbolic_link (file)) {
- names = g_list_prepend
- (names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_SYMBOLIC_LINK));
- }
-
- if (parent) {
- nautilus_file_unref (parent);
- }
-
-
- return names;
+ GList *names)
+{
+ /* Prepend in reverse order. */
+ NautilusFile *parent;
+
+ parent = nautilus_file_get_parent (file);
+
+ /* Trash files are assumed to be read-only,
+ * so we want to ignore them here. */
+ if (!nautilus_file_can_write (file) &&
+ !nautilus_file_is_in_trash (file) &&
+ (parent == NULL || nautilus_file_can_write (parent)))
+ {
+ names = g_list_prepend
+ (names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE));
+ }
+ if (!nautilus_file_can_read (file))
+ {
+ names = g_list_prepend
+ (names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_CANT_READ));
+ }
+ if (nautilus_file_is_symbolic_link (file))
+ {
+ names = g_list_prepend
+ (names, g_strdup (NAUTILUS_FILE_EMBLEM_NAME_SYMBOLIC_LINK));
+ }
+
+ if (parent)
+ {
+ nautilus_file_unref (parent);
+ }
+
+
+ return names;
}
static int
-compare_by_type (NautilusFile *file_1, NautilusFile *file_2)
-{
- gboolean is_directory_1;
- gboolean is_directory_2;
- char *type_string_1;
- char *type_string_2;
- int result;
-
- /* Directories go first. Then, if mime types are identical,
- * don't bother getting strings (for speed). This assumes
- * that the string is dependent entirely on the mime type,
- * which is true now but might not be later.
- */
- is_directory_1 = nautilus_file_is_directory (file_1);
- is_directory_2 = nautilus_file_is_directory (file_2);
-
- if (is_directory_1 && is_directory_2) {
- return 0;
- }
-
- if (is_directory_1) {
- return -1;
- }
-
- if (is_directory_2) {
- return +1;
- }
-
- if (file_1->details->mime_type != NULL &&
- file_2->details->mime_type != NULL &&
- strcmp (eel_ref_str_peek (file_1->details->mime_type),
- eel_ref_str_peek (file_2->details->mime_type)) == 0) {
- return 0;
- }
-
- type_string_1 = nautilus_file_get_type_as_string (file_1);
- type_string_2 = nautilus_file_get_type_as_string (file_2);
-
- if (type_string_1 == NULL || type_string_2 == NULL) {
- if (type_string_1 != NULL) {
- return -1;
- }
+compare_by_type (NautilusFile *file_1,
+ NautilusFile *file_2)
+{
+ gboolean is_directory_1;
+ gboolean is_directory_2;
+ char *type_string_1;
+ char *type_string_2;
+ int result;
+
+ /* Directories go first. Then, if mime types are identical,
+ * don't bother getting strings (for speed). This assumes
+ * that the string is dependent entirely on the mime type,
+ * which is true now but might not be later.
+ */
+ is_directory_1 = nautilus_file_is_directory (file_1);
+ is_directory_2 = nautilus_file_is_directory (file_2);
+
+ if (is_directory_1 && is_directory_2)
+ {
+ return 0;
+ }
+
+ if (is_directory_1)
+ {
+ return -1;
+ }
+
+ if (is_directory_2)
+ {
+ return +1;
+ }
+
+ if (file_1->details->mime_type != NULL &&
+ file_2->details->mime_type != NULL &&
+ strcmp (eel_ref_str_peek (file_1->details->mime_type),
+ eel_ref_str_peek (file_2->details->mime_type)) == 0)
+ {
+ return 0;
+ }
+
+ type_string_1 = nautilus_file_get_type_as_string (file_1);
+ type_string_2 = nautilus_file_get_type_as_string (file_2);
+
+ if (type_string_1 == NULL || type_string_2 == NULL)
+ {
+ if (type_string_1 != NULL)
+ {
+ return -1;
+ }
- if (type_string_2 != NULL) {
- return 1;
- }
+ if (type_string_2 != NULL)
+ {
+ return 1;
+ }
- return 0;
- }
+ return 0;
+ }
- result = g_utf8_collate (type_string_1, type_string_2);
+ result = g_utf8_collate (type_string_1, type_string_2);
- g_free (type_string_1);
- g_free (type_string_2);
+ g_free (type_string_1);
+ g_free (type_string_2);
- return result;
+ return result;
}
static Knowledge
get_search_relevance (NautilusFile *file,
- gdouble *relevance_out)
+ gdouble *relevance_out)
{
- /* we're only called in search directories, and in that
- * case, the relevance is always known (or zero).
- */
- *relevance_out = file->details->search_relevance;
- return KNOWN;
+ /* we're only called in search directories, and in that
+ * case, the relevance is always known (or zero).
+ */
+ *relevance_out = file->details->search_relevance;
+ return KNOWN;
}
static int
-compare_by_search_relevance (NautilusFile *file_1, NautilusFile *file_2)
+compare_by_search_relevance (NautilusFile *file_1,
+ NautilusFile *file_2)
{
- gdouble r_1, r_2;
+ gdouble r_1, r_2;
- get_search_relevance (file_1, &r_1);
- get_search_relevance (file_2, &r_2);
+ get_search_relevance (file_1, &r_1);
+ get_search_relevance (file_2, &r_2);
- if (r_1 < r_2) {
- return -1;
- }
- if (r_1 > r_2) {
- return +1;
- }
+ if (r_1 < r_2)
+ {
+ return -1;
+ }
+ if (r_1 > r_2)
+ {
+ return +1;
+ }
- return 0;
+ return 0;
}
static int
-compare_by_time (NautilusFile *file_1, NautilusFile *file_2, NautilusDateType type)
-{
- /* Sort order:
- * Files with unknown times.
- * Files with "unknowable" times.
- * Files with older times.
- * Files with newer times.
- */
-
- Knowledge time_known_1, time_known_2;
- time_t time_1, time_2;
-
- time_1 = 0;
- time_2 = 0;
-
- time_known_1 = get_time (file_1, &time_1, type);
- time_known_2 = get_time (file_2, &time_2, type);
-
- if (time_known_1 > time_known_2) {
- return -1;
- }
- if (time_known_1 < time_known_2) {
- return +1;
- }
-
- /* Now time_known_1 is equal to time_known_2. Check whether
- * we failed to get modification times for files
- */
- if(time_known_1 == UNKNOWABLE || time_known_1 == UNKNOWN) {
- return 0;
- }
-
- if (time_1 < time_2) {
- return -1;
- }
- if (time_1 > time_2) {
- return +1;
- }
-
- return 0;
+compare_by_time (NautilusFile *file_1,
+ NautilusFile *file_2,
+ NautilusDateType type)
+{
+ /* Sort order:
+ * Files with unknown times.
+ * Files with "unknowable" times.
+ * Files with older times.
+ * Files with newer times.
+ */
+
+ Knowledge time_known_1, time_known_2;
+ time_t time_1, time_2;
+
+ time_1 = 0;
+ time_2 = 0;
+
+ time_known_1 = get_time (file_1, &time_1, type);
+ time_known_2 = get_time (file_2, &time_2, type);
+
+ if (time_known_1 > time_known_2)
+ {
+ return -1;
+ }
+ if (time_known_1 < time_known_2)
+ {
+ return +1;
+ }
+
+ /* Now time_known_1 is equal to time_known_2. Check whether
+ * we failed to get modification times for files
+ */
+ if(time_known_1 == UNKNOWABLE || time_known_1 == UNKNOWN)
+ {
+ return 0;
+ }
+
+ if (time_1 < time_2)
+ {
+ return -1;
+ }
+ if (time_1 > time_2)
+ {
+ return +1;
+ }
+
+ return 0;
}
static int
-compare_by_full_path (NautilusFile *file_1, NautilusFile *file_2)
+compare_by_full_path (NautilusFile *file_1,
+ NautilusFile *file_2)
{
- int compare;
+ int compare;
- compare = compare_by_directory_name (file_1, file_2);
- if (compare != 0) {
- return compare;
- }
- return compare_by_display_name (file_1, file_2);
+ compare = compare_by_directory_name (file_1, file_2);
+ if (compare != 0)
+ {
+ return compare;
+ }
+ return compare_by_display_name (file_1, file_2);
}
static int
nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
- NautilusFile *file_2,
- gboolean directories_first,
- gboolean reversed)
+ NautilusFile *file_2,
+ gboolean directories_first,
+ gboolean reversed)
{
- gboolean is_directory_1, is_directory_2;
+ gboolean is_directory_1, is_directory_2;
- if (directories_first) {
- is_directory_1 = nautilus_file_is_directory (file_1);
- is_directory_2 = nautilus_file_is_directory (file_2);
+ if (directories_first)
+ {
+ is_directory_1 = nautilus_file_is_directory (file_1);
+ is_directory_2 = nautilus_file_is_directory (file_2);
- if (is_directory_1 && !is_directory_2) {
- return -1;
- }
+ if (is_directory_1 && !is_directory_2)
+ {
+ return -1;
+ }
- if (is_directory_2 && !is_directory_1) {
- return +1;
- }
- }
+ if (is_directory_2 && !is_directory_1)
+ {
+ return +1;
+ }
+ }
- if (file_1->details->sort_order < file_2->details->sort_order) {
- return reversed ? 1 : -1;
- } else if (file_1->details->sort_order > file_2->details->sort_order) {
- return reversed ? -1 : 1;
- }
+ if (file_1->details->sort_order < file_2->details->sort_order)
+ {
+ return reversed ? 1 : -1;
+ }
+ else if (file_1->details->sort_order > file_2->details->sort_order)
+ {
+ return reversed ? -1 : 1;
+ }
- return 0;
+ return 0;
}
/**
@@ -3351,7 +3754,7 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
* @directories_first: Put all directories before any non-directories
* @reversed: Reverse the order of the items, except that
* the directories_first flag is still respected.
- *
+ *
* Return value: int < 0 if @file_1 should come before file_2 in a
* sorted list; int > 0 if @file_2 should come before file_1 in a
* sorted list; 0 if @file_1 and @file_2 are equal for this sort criterion. Note
@@ -3359,177 +3762,226 @@ nautilus_file_compare_for_sort_internal (NautilusFile *file_1,
* of the sort criterion being the primary but not only differentiator.
**/
int
-nautilus_file_compare_for_sort (NautilusFile *file_1,
- NautilusFile *file_2,
- NautilusFileSortType sort_type,
- gboolean directories_first,
- gboolean reversed)
-{
- int result;
-
- if (file_1 == file_2) {
- return 0;
- }
-
- result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
-
- if (result == 0) {
- switch (sort_type) {
- case NAUTILUS_FILE_SORT_BY_DISPLAY_NAME:
- result = compare_by_display_name (file_1, file_2);
- if (result == 0) {
- result = compare_by_directory_name (file_1, file_2);
- }
- break;
- case NAUTILUS_FILE_SORT_BY_SIZE:
- /* Compare directory sizes ourselves, then if necessary
- * use GnomeVFS to compare file sizes.
- */
- result = compare_by_size (file_1, file_2);
- if (result == 0) {
- result = compare_by_full_path (file_1, file_2);
- }
- break;
- case NAUTILUS_FILE_SORT_BY_TYPE:
- /* GnomeVFS doesn't know about our special text for certain
- * mime types, so we handle the mime-type sorting ourselves.
- */
- result = compare_by_type (file_1, file_2);
- if (result == 0) {
- result = compare_by_full_path (file_1, file_2);
- }
- break;
- case NAUTILUS_FILE_SORT_BY_MTIME:
- result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_MODIFIED);
- if (result == 0) {
- result = compare_by_full_path (file_1, file_2);
- }
- break;
- case NAUTILUS_FILE_SORT_BY_ATIME:
- result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_ACCESSED);
- if (result == 0) {
- result = compare_by_full_path (file_1, file_2);
- }
- break;
- case NAUTILUS_FILE_SORT_BY_TRASHED_TIME:
- result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_TRASHED);
- if (result == 0) {
- result = compare_by_full_path (file_1, file_2);
- }
- break;
- case NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE:
- result = compare_by_search_relevance (file_1, file_2);
- if (result == 0) {
- result = compare_by_full_path (file_1, file_2);
-
- /* ensure alphabetical order for files of the same relevance */
- reversed = FALSE;
- }
- break;
- default:
- g_return_val_if_reached (0);
- }
-
- if (reversed) {
- result = -result;
- }
- }
-
- return result;
+nautilus_file_compare_for_sort (NautilusFile *file_1,
+ NautilusFile *file_2,
+ NautilusFileSortType sort_type,
+ gboolean directories_first,
+ gboolean reversed)
+{
+ int result;
+
+ if (file_1 == file_2)
+ {
+ return 0;
+ }
+
+ result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
+
+ if (result == 0)
+ {
+ switch (sort_type)
+ {
+ case NAUTILUS_FILE_SORT_BY_DISPLAY_NAME:
+ {
+ result = compare_by_display_name (file_1, file_2);
+ if (result == 0)
+ {
+ result = compare_by_directory_name (file_1, file_2);
+ }
+ }
+ break;
+
+ case NAUTILUS_FILE_SORT_BY_SIZE:
+ {
+ /* Compare directory sizes ourselves, then if necessary
+ * use GnomeVFS to compare file sizes.
+ */
+ result = compare_by_size (file_1, file_2);
+ if (result == 0)
+ {
+ result = compare_by_full_path (file_1, file_2);
+ }
+ }
+ break;
+
+ case NAUTILUS_FILE_SORT_BY_TYPE:
+ {
+ /* GnomeVFS doesn't know about our special text for certain
+ * mime types, so we handle the mime-type sorting ourselves.
+ */
+ result = compare_by_type (file_1, file_2);
+ if (result == 0)
+ {
+ result = compare_by_full_path (file_1, file_2);
+ }
+ }
+ break;
+
+ case NAUTILUS_FILE_SORT_BY_MTIME:
+ {
+ result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_MODIFIED);
+ if (result == 0)
+ {
+ result = compare_by_full_path (file_1, file_2);
+ }
+ }
+ break;
+
+ case NAUTILUS_FILE_SORT_BY_ATIME:
+ {
+ result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_ACCESSED);
+ if (result == 0)
+ {
+ result = compare_by_full_path (file_1, file_2);
+ }
+ }
+ break;
+
+ case NAUTILUS_FILE_SORT_BY_TRASHED_TIME:
+ {
+ result = compare_by_time (file_1, file_2, NAUTILUS_DATE_TYPE_TRASHED);
+ if (result == 0)
+ {
+ result = compare_by_full_path (file_1, file_2);
+ }
+ }
+ break;
+
+ case NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE:
+ {
+ result = compare_by_search_relevance (file_1, file_2);
+ if (result == 0)
+ {
+ result = compare_by_full_path (file_1, file_2);
+
+ /* ensure alphabetical order for files of the same relevance */
+ reversed = FALSE;
+ }
+ }
+ break;
+
+ default:
+ g_return_val_if_reached (0);
+ }
+
+ if (reversed)
+ {
+ result = -result;
+ }
+ }
+
+ return result;
}
int
-nautilus_file_compare_for_sort_by_attribute_q (NautilusFile *file_1,
- NautilusFile *file_2,
- GQuark attribute,
- gboolean directories_first,
- gboolean reversed)
-{
- int result;
-
- if (file_1 == file_2) {
- return 0;
- }
-
- /* Convert certain attributes into NautilusFileSortTypes and use
- * nautilus_file_compare_for_sort()
- */
- if (attribute == 0 || attribute == attribute_name_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
- directories_first,
- reversed);
- } else if (attribute == attribute_size_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_SIZE,
- directories_first,
- reversed);
- } else if (attribute == attribute_type_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_TYPE,
- directories_first,
- reversed);
- } else if (attribute == attribute_modification_date_q || attribute == attribute_date_modified_q || attribute == attribute_date_modified_with_time_q || attribute == attribute_date_modified_full_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_MTIME,
- directories_first,
- reversed);
- } else if (attribute == attribute_accessed_date_q || attribute == attribute_date_accessed_q || attribute == attribute_date_accessed_full_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_ATIME,
- directories_first,
- reversed);
- } else if (attribute == attribute_trashed_on_q || attribute == attribute_trashed_on_full_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_TRASHED_TIME,
- directories_first,
- reversed);
- } else if (attribute == attribute_search_relevance_q) {
- return nautilus_file_compare_for_sort (file_1, file_2,
- NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE,
- directories_first,
- reversed);
- }
-
- /* it is a normal attribute, compare by strings */
-
- result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
-
- if (result == 0) {
- char *value_1;
- char *value_2;
-
- value_1 = nautilus_file_get_string_attribute_q (file_1,
- attribute);
- value_2 = nautilus_file_get_string_attribute_q (file_2,
- attribute);
-
- if (value_1 != NULL && value_2 != NULL) {
- result = strcmp (value_1, value_2);
- }
-
- g_free (value_1);
- g_free (value_2);
-
- if (reversed) {
- result = -result;
- }
- }
-
- return result;
+nautilus_file_compare_for_sort_by_attribute_q (NautilusFile *file_1,
+ NautilusFile *file_2,
+ GQuark attribute,
+ gboolean directories_first,
+ gboolean reversed)
+{
+ int result;
+
+ if (file_1 == file_2)
+ {
+ return 0;
+ }
+
+ /* Convert certain attributes into NautilusFileSortTypes and use
+ * nautilus_file_compare_for_sort()
+ */
+ if (attribute == 0 || attribute == attribute_name_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_DISPLAY_NAME,
+ directories_first,
+ reversed);
+ }
+ else if (attribute == attribute_size_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_SIZE,
+ directories_first,
+ reversed);
+ }
+ else if (attribute == attribute_type_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_TYPE,
+ directories_first,
+ reversed);
+ }
+ else if (attribute == attribute_modification_date_q || attribute == attribute_date_modified_q || attribute == attribute_date_modified_with_time_q || attribute == attribute_date_modified_full_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_MTIME,
+ directories_first,
+ reversed);
+ }
+ else if (attribute == attribute_accessed_date_q || attribute == attribute_date_accessed_q || attribute == attribute_date_accessed_full_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_ATIME,
+ directories_first,
+ reversed);
+ }
+ else if (attribute == attribute_trashed_on_q || attribute == attribute_trashed_on_full_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_TRASHED_TIME,
+ directories_first,
+ reversed);
+ }
+ else if (attribute == attribute_search_relevance_q)
+ {
+ return nautilus_file_compare_for_sort (file_1, file_2,
+ NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE,
+ directories_first,
+ reversed);
+ }
+
+ /* it is a normal attribute, compare by strings */
+
+ result = nautilus_file_compare_for_sort_internal (file_1, file_2, directories_first, reversed);
+
+ if (result == 0)
+ {
+ char *value_1;
+ char *value_2;
+
+ value_1 = nautilus_file_get_string_attribute_q (file_1,
+ attribute);
+ value_2 = nautilus_file_get_string_attribute_q (file_2,
+ attribute);
+
+ if (value_1 != NULL && value_2 != NULL)
+ {
+ result = strcmp (value_1, value_2);
+ }
+
+ g_free (value_1);
+ g_free (value_2);
+
+ if (reversed)
+ {
+ result = -result;
+ }
+ }
+
+ return result;
}
int
-nautilus_file_compare_for_sort_by_attribute (NautilusFile *file_1,
- NautilusFile *file_2,
- const char *attribute,
- gboolean directories_first,
- gboolean reversed)
+nautilus_file_compare_for_sort_by_attribute (NautilusFile *file_1,
+ NautilusFile *file_2,
+ const char *attribute,
+ gboolean directories_first,
+ gboolean reversed)
{
- return nautilus_file_compare_for_sort_by_attribute_q (file_1, file_2,
- g_quark_from_string (attribute),
- directories_first,
- reversed);
+ return nautilus_file_compare_for_sort_by_attribute_q (file_1, file_2,
+ g_quark_from_string (attribute),
+ directories_first,
+ reversed);
}
@@ -3537,28 +3989,28 @@ nautilus_file_compare_for_sort_by_attribute (NautilusFile
* nautilus_file_compare_name:
* @file: A file object
* @string: A string we are comparing it with
- *
+ *
* Return value: result of a comparison of the file name and the given string.
**/
int
nautilus_file_compare_display_name (NautilusFile *file,
- const char *string)
+ const char *string)
{
- const char *name;
- int result;
+ const char *name;
+ int result;
- g_return_val_if_fail (string != NULL, -1);
+ g_return_val_if_fail (string != NULL, -1);
- name = nautilus_file_peek_display_name (file);
- result = g_strcmp0 (name, string);
- return result;
+ name = nautilus_file_peek_display_name (file);
+ result = g_strcmp0 (name, string);
+ return result;
}
gboolean
nautilus_file_is_hidden_file (NautilusFile *file)
{
- return file->details->is_hidden;
+ return file->details->is_hidden;
}
/**
@@ -3566,91 +4018,95 @@ nautilus_file_is_hidden_file (NautilusFile *file)
* @file: the file to check
* @show_hidden: whether we want to show hidden files or not
* @show_foreign: whether we want to show foreign files or not
- *
+ *
* Determines if a #NautilusFile should be shown. Note that when browsing
- * a trash directory, this function will always return %TRUE.
+ * a trash directory, this function will always return %TRUE.
*
* Returns: %TRUE if the file should be shown, %FALSE if it shouldn't.
*/
-gboolean
-nautilus_file_should_show (NautilusFile *file,
- gboolean show_hidden,
- gboolean show_foreign)
-{
- /* Never hide any files in trash. */
- if (nautilus_file_is_in_trash (file)) {
- return TRUE;
- }
-
- if (!show_hidden && nautilus_file_is_hidden_file (file)) {
- return FALSE;
- }
+gboolean
+nautilus_file_should_show (NautilusFile *file,
+ gboolean show_hidden,
+ gboolean show_foreign)
+{
+ /* Never hide any files in trash. */
+ if (nautilus_file_is_in_trash (file))
+ {
+ return TRUE;
+ }
+
+ if (!show_hidden && nautilus_file_is_hidden_file (file))
+ {
+ return FALSE;
+ }
- if (!show_foreign && nautilus_file_is_foreign_link (file)) {
- return FALSE;
- }
+ if (!show_foreign && nautilus_file_is_foreign_link (file))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
gboolean
nautilus_file_is_home (NautilusFile *file)
{
- GFile *dir;
+ GFile *dir;
- dir = file->details->directory->details->location;
- if (dir == NULL) {
- return FALSE;
- }
+ dir = file->details->directory->details->location;
+ if (dir == NULL)
+ {
+ return FALSE;
+ }
- return nautilus_is_home_directory_file (dir,
- eel_ref_str_peek (file->details->name));
+ return nautilus_is_home_directory_file (dir,
+ eel_ref_str_peek (file->details->name));
}
gboolean
nautilus_file_is_in_search (NautilusFile *file)
{
- char *uri;
- gboolean ret;
+ char *uri;
+ gboolean ret;
- uri = nautilus_file_get_uri (file);
- ret = eel_uri_is_search (uri);
- g_free (uri);
+ uri = nautilus_file_get_uri (file);
+ ret = eel_uri_is_search (uri);
+ g_free (uri);
- return ret;
+ return ret;
}
static gboolean
filter_hidden_partition_callback (NautilusFile *file,
gpointer callback_data)
{
- FilterOptions options;
+ FilterOptions options;
- options = GPOINTER_TO_INT (callback_data);
+ options = GPOINTER_TO_INT (callback_data);
- return nautilus_file_should_show (file,
- options & SHOW_HIDDEN,
- TRUE);
+ return nautilus_file_should_show (file,
+ options & SHOW_HIDDEN,
+ TRUE);
}
GList *
nautilus_file_list_filter_hidden (GList *files,
- gboolean show_hidden)
+ gboolean show_hidden)
{
- GList *filtered_files;
- GList *removed_files;
+ GList *filtered_files;
+ GList *removed_files;
- /* FIXME bugzilla.gnome.org 40653:
- * Eventually this should become a generic filtering thingy.
- */
+ /* FIXME bugzilla.gnome.org 40653:
+ * Eventually this should become a generic filtering thingy.
+ */
- filtered_files = nautilus_file_list_filter (files,
- &removed_files,
- filter_hidden_partition_callback,
- GINT_TO_POINTER ((show_hidden ? SHOW_HIDDEN : 0)));
- nautilus_file_list_free (removed_files);
+ filtered_files = nautilus_file_list_filter (files,
+ &removed_files,
+ filter_hidden_partition_callback,
+ GINT_TO_POINTER ((show_hidden ? SHOW_HIDDEN : 0)));
+ nautilus_file_list_free (removed_files);
- return filtered_files;
+ return filtered_files;
}
/* This functions filters a file list when its items match a certain condition
@@ -3662,430 +4118,467 @@ nautilus_file_list_filter (GList *files,
NautilusFileFilterFunc filter_function,
gpointer user_data)
{
- GList *filtered = NULL;
- GList *l;
- GList *last;
- GList *reversed;
-
- *failed = NULL;
- /* Avoid using g_list_append since it's O(n) */
- reversed = g_list_copy (files);
- reversed = g_list_reverse (reversed);
- last = g_list_last (reversed);
- for (l = last; l != NULL; l = l->prev) {
- if (filter_function (l->data, user_data)) {
- filtered = g_list_prepend (filtered, nautilus_file_ref (l->data));
- } else {
- *failed = g_list_prepend (*failed, nautilus_file_ref (l->data));
- }
+ GList *filtered = NULL;
+ GList *l;
+ GList *last;
+ GList *reversed;
+
+ *failed = NULL;
+ /* Avoid using g_list_append since it's O(n) */
+ reversed = g_list_copy (files);
+ reversed = g_list_reverse (reversed);
+ last = g_list_last (reversed);
+ for (l = last; l != NULL; l = l->prev)
+ {
+ if (filter_function (l->data, user_data))
+ {
+ filtered = g_list_prepend (filtered, nautilus_file_ref (l->data));
+ }
+ else
+ {
+ *failed = g_list_prepend (*failed, nautilus_file_ref (l->data));
}
+ }
- g_list_free (reversed);
+ g_list_free (reversed);
- return filtered;
+ return filtered;
}
char *
nautilus_file_get_metadata (NautilusFile *file,
- const char *key,
- const char *default_metadata)
+ const char *key,
+ const char *default_metadata)
{
- guint id;
- char *value;
+ guint id;
+ char *value;
- g_return_val_if_fail (key != NULL, g_strdup (default_metadata));
- g_return_val_if_fail (key[0] != '\0', g_strdup (default_metadata));
+ g_return_val_if_fail (key != NULL, g_strdup (default_metadata));
+ g_return_val_if_fail (key[0] != '\0', g_strdup (default_metadata));
- if (file == NULL ||
- file->details->metadata == NULL) {
- return g_strdup (default_metadata);
- }
+ if (file == NULL ||
+ file->details->metadata == NULL)
+ {
+ return g_strdup (default_metadata);
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), g_strdup (default_metadata));
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), g_strdup (default_metadata));
- id = nautilus_metadata_get_id (key);
- value = g_hash_table_lookup (file->details->metadata, GUINT_TO_POINTER (id));
+ id = nautilus_metadata_get_id (key);
+ value = g_hash_table_lookup (file->details->metadata, GUINT_TO_POINTER (id));
- if (value) {
- return g_strdup (value);
- }
- return g_strdup (default_metadata);
+ if (value)
+ {
+ return g_strdup (value);
+ }
+ return g_strdup (default_metadata);
}
GList *
nautilus_file_get_metadata_list (NautilusFile *file,
- const char *key)
+ const char *key)
{
- GList *res;
- guint id;
- char **value;
- int i;
+ GList *res;
+ guint id;
+ char **value;
+ int i;
- g_return_val_if_fail (key != NULL, NULL);
- g_return_val_if_fail (key[0] != '\0', NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+ g_return_val_if_fail (key[0] != '\0', NULL);
- if (file == NULL ||
- file->details->metadata == NULL) {
- return NULL;
- }
+ if (file == NULL ||
+ file->details->metadata == NULL)
+ {
+ return NULL;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- id = nautilus_metadata_get_id (key);
- id |= METADATA_ID_IS_LIST_MASK;
+ id = nautilus_metadata_get_id (key);
+ id |= METADATA_ID_IS_LIST_MASK;
- value = g_hash_table_lookup (file->details->metadata, GUINT_TO_POINTER (id));
+ value = g_hash_table_lookup (file->details->metadata, GUINT_TO_POINTER (id));
- if (value) {
- res = NULL;
- for (i = 0; value[i] != NULL; i++) {
- res = g_list_prepend (res, g_strdup (value[i]));
- }
- return g_list_reverse (res);
- }
+ if (value)
+ {
+ res = NULL;
+ for (i = 0; value[i] != NULL; i++)
+ {
+ res = g_list_prepend (res, g_strdup (value[i]));
+ }
+ return g_list_reverse (res);
+ }
- return NULL;
+ return NULL;
}
void
nautilus_file_set_metadata (NautilusFile *file,
- const char *key,
- const char *default_metadata,
- const char *metadata)
+ const char *key,
+ const char *default_metadata,
+ const char *metadata)
{
- const char *val;
+ const char *val;
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (key != NULL);
- g_return_if_fail (key[0] != '\0');
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (key[0] != '\0');
- val = metadata;
- if (val == NULL) {
- val = default_metadata;
- }
+ val = metadata;
+ if (val == NULL)
+ {
+ val = default_metadata;
+ }
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->set_metadata (file, key, val);
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->set_metadata (file, key, val);
}
void
nautilus_file_set_metadata_list (NautilusFile *file,
- const char *key,
- GList *list)
+ const char *key,
+ GList *list)
{
- char **val;
- int len, i;
- GList *l;
+ char **val;
+ int len, i;
+ GList *l;
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (key != NULL);
- g_return_if_fail (key[0] != '\0');
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (key[0] != '\0');
- len = g_list_length (list);
- val = g_new (char *, len + 1);
- for (l = list, i = 0; l != NULL; l = l->next, i++) {
- val[i] = l->data;
- }
- val[i] = NULL;
+ len = g_list_length (list);
+ val = g_new (char *, len + 1);
+ for (l = list, i = 0; l != NULL; l = l->next, i++)
+ {
+ val[i] = l->data;
+ }
+ val[i] = NULL;
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->set_metadata_as_list (file, key, val);
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->set_metadata_as_list (file, key, val);
- g_free (val);
+ g_free (val);
}
gboolean
nautilus_file_get_boolean_metadata (NautilusFile *file,
- const char *key,
- gboolean default_metadata)
+ const char *key,
+ gboolean default_metadata)
{
- char *result_as_string;
- gboolean result;
+ char *result_as_string;
+ gboolean result;
- g_return_val_if_fail (key != NULL, default_metadata);
- g_return_val_if_fail (key[0] != '\0', default_metadata);
+ g_return_val_if_fail (key != NULL, default_metadata);
+ g_return_val_if_fail (key[0] != '\0', default_metadata);
- if (file == NULL) {
- return default_metadata;
- }
+ if (file == NULL)
+ {
+ return default_metadata;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata);
- result_as_string = nautilus_file_get_metadata
- (file, key, default_metadata ? "true" : "false");
- g_assert (result_as_string != NULL);
+ result_as_string = nautilus_file_get_metadata
+ (file, key, default_metadata ? "true" : "false");
+ g_assert (result_as_string != NULL);
- if (g_ascii_strcasecmp (result_as_string, "true") == 0) {
- result = TRUE;
- } else if (g_ascii_strcasecmp (result_as_string, "false") == 0) {
- result = FALSE;
- } else {
- g_error ("boolean metadata with value other than true or false");
- result = default_metadata;
- }
+ if (g_ascii_strcasecmp (result_as_string, "true") == 0)
+ {
+ result = TRUE;
+ }
+ else if (g_ascii_strcasecmp (result_as_string, "false") == 0)
+ {
+ result = FALSE;
+ }
+ else
+ {
+ g_error ("boolean metadata with value other than true or false");
+ result = default_metadata;
+ }
- g_free (result_as_string);
- return result;
+ g_free (result_as_string);
+ return result;
}
int
nautilus_file_get_integer_metadata (NautilusFile *file,
- const char *key,
- int default_metadata)
-{
- char *result_as_string;
- char default_as_string[32];
- int result;
- char c;
-
- g_return_val_if_fail (key != NULL, default_metadata);
- g_return_val_if_fail (key[0] != '\0', default_metadata);
-
- if (file == NULL) {
- return default_metadata;
- }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata);
-
- g_snprintf (default_as_string, sizeof (default_as_string), "%d", default_metadata);
- result_as_string = nautilus_file_get_metadata
- (file, key, default_as_string);
-
- /* Normally we can't get a a NULL, but we check for it here to
- * handle the oddball case of a non-existent directory.
- */
- if (result_as_string == NULL) {
- result = default_metadata;
- } else {
- if (sscanf (result_as_string, " %d %c", &result, &c) != 1) {
- result = default_metadata;
- }
- g_free (result_as_string);
- }
+ const char *key,
+ int default_metadata)
+{
+ char *result_as_string;
+ char default_as_string[32];
+ int result;
+ char c;
+
+ g_return_val_if_fail (key != NULL, default_metadata);
+ g_return_val_if_fail (key[0] != '\0', default_metadata);
+
+ if (file == NULL)
+ {
+ return default_metadata;
+ }
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), default_metadata);
+
+ g_snprintf (default_as_string, sizeof (default_as_string), "%d", default_metadata);
+ result_as_string = nautilus_file_get_metadata
+ (file, key, default_as_string);
+
+ /* Normally we can't get a a NULL, but we check for it here to
+ * handle the oddball case of a non-existent directory.
+ */
+ if (result_as_string == NULL)
+ {
+ result = default_metadata;
+ }
+ else
+ {
+ if (sscanf (result_as_string, " %d %c", &result, &c) != 1)
+ {
+ result = default_metadata;
+ }
+ g_free (result_as_string);
+ }
- return result;
+ return result;
}
static gboolean
get_time_from_time_string (const char *time_string,
- time_t *time)
+ time_t *time)
{
- long scanned_time;
- char c;
+ long scanned_time;
+ char c;
- g_assert (time != NULL);
+ g_assert (time != NULL);
- /* Only accept string if it has one integer with nothing
- * afterwards.
- */
- if (time_string == NULL ||
- sscanf (time_string, "%ld%c", &scanned_time, &c) != 1) {
- return FALSE;
- }
- *time = (time_t) scanned_time;
- return TRUE;
+ /* Only accept string if it has one integer with nothing
+ * afterwards.
+ */
+ if (time_string == NULL ||
+ sscanf (time_string, "%ld%c", &scanned_time, &c) != 1)
+ {
+ return FALSE;
+ }
+ *time = (time_t) scanned_time;
+ return TRUE;
}
time_t
nautilus_file_get_time_metadata (NautilusFile *file,
- const char *key)
+ const char *key)
{
- time_t time;
- char *time_string;
+ time_t time;
+ char *time_string;
- time_string = nautilus_file_get_metadata (file, key, NULL);
- if (!get_time_from_time_string (time_string, &time)) {
- time = UNDEFINED_TIME;
- }
- g_free (time_string);
+ time_string = nautilus_file_get_metadata (file, key, NULL);
+ if (!get_time_from_time_string (time_string, &time))
+ {
+ time = UNDEFINED_TIME;
+ }
+ g_free (time_string);
- return time;
+ return time;
}
void
nautilus_file_set_time_metadata (NautilusFile *file,
- const char *key,
- time_t time)
+ const char *key,
+ time_t time)
{
- char time_str[21];
- char *metadata;
+ char time_str[21];
+ char *metadata;
- if (time != UNDEFINED_TIME) {
- /* 2^64 turns out to be 20 characters */
- g_snprintf (time_str, 20, "%ld", (long int)time);
- time_str[20] = '\0';
- metadata = time_str;
- } else {
- metadata = NULL;
- }
+ if (time != UNDEFINED_TIME)
+ {
+ /* 2^64 turns out to be 20 characters */
+ g_snprintf (time_str, 20, "%ld", (long int) time);
+ time_str[20] = '\0';
+ metadata = time_str;
+ }
+ else
+ {
+ metadata = NULL;
+ }
- nautilus_file_set_metadata (file, key, NULL, metadata);
+ nautilus_file_set_metadata (file, key, NULL, metadata);
}
void
nautilus_file_set_boolean_metadata (NautilusFile *file,
- const char *key,
- gboolean default_metadata,
- gboolean metadata)
+ const char *key,
+ gboolean default_metadata,
+ gboolean metadata)
{
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (key != NULL);
- g_return_if_fail (key[0] != '\0');
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (key[0] != '\0');
- nautilus_file_set_metadata (file, key,
- default_metadata ? "true" : "false",
- metadata ? "true" : "false");
+ nautilus_file_set_metadata (file, key,
+ default_metadata ? "true" : "false",
+ metadata ? "true" : "false");
}
void
nautilus_file_set_integer_metadata (NautilusFile *file,
- const char *key,
- int default_metadata,
- int metadata)
+ const char *key,
+ int default_metadata,
+ int metadata)
{
- char value_as_string[32];
- char default_as_string[32];
+ char value_as_string[32];
+ char default_as_string[32];
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (key != NULL);
- g_return_if_fail (key[0] != '\0');
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (key != NULL);
+ g_return_if_fail (key[0] != '\0');
- g_snprintf (value_as_string, sizeof (value_as_string), "%d", metadata);
- g_snprintf (default_as_string, sizeof (default_as_string), "%d", default_metadata);
+ g_snprintf (value_as_string, sizeof (value_as_string), "%d", metadata);
+ g_snprintf (default_as_string, sizeof (default_as_string), "%d", default_metadata);
- nautilus_file_set_metadata (file, key,
- default_as_string, value_as_string);
+ nautilus_file_set_metadata (file, key,
+ default_as_string, value_as_string);
}
static const char *
nautilus_file_peek_display_name_collation_key (NautilusFile *file)
{
- const char *res;
+ const char *res;
- res = file->details->display_name_collation_key;
- if (res == NULL)
- res = "";
+ res = file->details->display_name_collation_key;
+ if (res == NULL)
+ {
+ res = "";
+ }
- return res;
+ return res;
}
static const char *
nautilus_file_peek_display_name (NautilusFile *file)
{
- const char *name;
- char *escaped_name;
-
- /* FIXME: for some reason we can get a NautilusFile instance which is
- * no longer valid or could be freed somewhere else in the same time.
- * There's race condition somewhere. See bug 602500.
- */
- if (file == NULL || nautilus_file_is_gone (file))
- return "";
-
- /* Default to display name based on filename if its not set yet */
-
- if (file->details->display_name == NULL) {
- name = eel_ref_str_peek (file->details->name);
- if (g_utf8_validate (name, -1, NULL)) {
- nautilus_file_set_display_name (file,
- name,
- NULL,
- FALSE);
- } else {
- escaped_name = g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
- nautilus_file_set_display_name (file,
- escaped_name,
- NULL,
- FALSE);
- g_free (escaped_name);
- }
- }
-
- return file->details->display_name ?
- eel_ref_str_peek (file->details->display_name) : "";
+ const char *name;
+ char *escaped_name;
+
+ /* FIXME: for some reason we can get a NautilusFile instance which is
+ * no longer valid or could be freed somewhere else in the same time.
+ * There's race condition somewhere. See bug 602500.
+ */
+ if (file == NULL || nautilus_file_is_gone (file))
+ {
+ return "";
+ }
+
+ /* Default to display name based on filename if its not set yet */
+
+ if (file->details->display_name == NULL)
+ {
+ name = eel_ref_str_peek (file->details->name);
+ if (g_utf8_validate (name, -1, NULL))
+ {
+ nautilus_file_set_display_name (file,
+ name,
+ NULL,
+ FALSE);
+ }
+ else
+ {
+ escaped_name = g_uri_escape_string (name, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
+ nautilus_file_set_display_name (file,
+ escaped_name,
+ NULL,
+ FALSE);
+ g_free (escaped_name);
+ }
+ }
+
+ return file->details->display_name ?
+ eel_ref_str_peek (file->details->display_name) : "";
}
char *
nautilus_file_get_display_name (NautilusFile *file)
{
- return g_strdup (nautilus_file_peek_display_name (file));
+ return g_strdup (nautilus_file_peek_display_name (file));
}
char *
nautilus_file_get_edit_name (NautilusFile *file)
{
- const char *res;
-
- res = eel_ref_str_peek (file->details->edit_name);
- if (res == NULL)
- res = "";
-
- return g_strdup (res);
+ const char *res;
+
+ res = eel_ref_str_peek (file->details->edit_name);
+ if (res == NULL)
+ {
+ res = "";
+ }
+
+ return g_strdup (res);
}
char *
nautilus_file_get_name (NautilusFile *file)
{
- return g_strdup (eel_ref_str_peek (file->details->name));
+ return g_strdup (eel_ref_str_peek (file->details->name));
}
/**
* nautilus_file_get_description:
* @file: a #NautilusFile.
- *
- * Gets the standard::description key from @file, if
+ *
+ * Gets the standard::description key from @file, if
* it has been cached.
- *
- * Returns: a string containing the value of the standard::description
- * key, or %NULL.
+ *
+ * Returns: a string containing the value of the standard::description
+ * key, or %NULL.
*/
char *
nautilus_file_get_description (NautilusFile *file)
{
- return g_strdup (file->details->description);
+ return g_strdup (file->details->description);
}
-
-void
-nautilus_file_monitor_add (NautilusFile *file,
- gconstpointer client,
- NautilusFileAttributes attributes)
+
+void
+nautilus_file_monitor_add (NautilusFile *file,
+ gconstpointer client,
+ NautilusFileAttributes attributes)
{
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (client != NULL);
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (client != NULL);
+
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->monitor_add (file, client, attributes);
+}
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->monitor_add (file, client, attributes);
-}
-
void
-nautilus_file_monitor_remove (NautilusFile *file,
- gconstpointer client)
+nautilus_file_monitor_remove (NautilusFile *file,
+ gconstpointer client)
{
- g_return_if_fail (NAUTILUS_IS_FILE (file));
- g_return_if_fail (client != NULL);
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (client != NULL);
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->monitor_remove (file, client);
-}
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->monitor_remove (file, client);
+}
gboolean
nautilus_file_is_launcher (NautilusFile *file)
{
- return file->details->is_launcher;
+ return file->details->is_launcher;
}
gboolean
nautilus_file_is_foreign_link (NautilusFile *file)
{
- return file->details->is_foreign_link;
+ return file->details->is_foreign_link;
}
gboolean
nautilus_file_is_trusted_link (NautilusFile *file)
{
- return file->details->is_trusted_link;
+ return file->details->is_trusted_link;
}
gboolean
nautilus_file_has_activation_uri (NautilusFile *file)
{
- return file->details->activation_uri != NULL;
+ return file->details->activation_uri != NULL;
}
@@ -4096,368 +4589,423 @@ nautilus_file_has_activation_uri (NautilusFile *file)
char *
nautilus_file_get_activation_uri (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+
+ if (file->details->activation_uri != NULL)
+ {
+ return g_strdup (file->details->activation_uri);
+ }
- if (file->details->activation_uri != NULL) {
- return g_strdup (file->details->activation_uri);
- }
-
- return nautilus_file_get_uri (file);
+ return nautilus_file_get_uri (file);
}
GFile *
nautilus_file_get_activation_location (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- if (file->details->activation_uri != NULL) {
- return g_file_new_for_uri (file->details->activation_uri);
- }
-
- return nautilus_file_get_location (file);
+ if (file->details->activation_uri != NULL)
+ {
+ return g_file_new_for_uri (file->details->activation_uri);
+ }
+
+ return nautilus_file_get_location (file);
}
char *
nautilus_file_get_target_uri (NautilusFile *file)
{
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_target_uri (file);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_target_uri (file);
}
static char *
real_get_target_uri (NautilusFile *file)
{
- char *uri, *target_uri;
- GFile *location;
+ char *uri, *target_uri;
+ GFile *location;
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- uri = nautilus_file_get_uri (file);
+ uri = nautilus_file_get_uri (file);
- /* Check for Nautilus link */
- if (nautilus_file_is_nautilus_link (file)) {
- location = nautilus_file_get_location (file);
- /* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */
- if (g_file_is_native (location)) {
- target_uri = nautilus_link_local_get_link_uri (uri);
- if (target_uri != NULL) {
- g_free (uri);
- uri = target_uri;
- }
- }
- g_object_unref (location);
- }
+ /* Check for Nautilus link */
+ if (nautilus_file_is_nautilus_link (file))
+ {
+ location = nautilus_file_get_location (file);
+ /* FIXME bugzilla.gnome.org 43020: This does sync. I/O and works only locally. */
+ if (g_file_is_native (location))
+ {
+ target_uri = nautilus_link_local_get_link_uri (uri);
+ if (target_uri != NULL)
+ {
+ g_free (uri);
+ uri = target_uri;
+ }
+ }
+ g_object_unref (location);
+ }
- return uri;
+ return uri;
}
static gboolean
is_uri_relative (const char *uri)
{
- char *scheme;
- gboolean ret;
+ char *scheme;
+ gboolean ret;
- scheme = g_uri_parse_scheme (uri);
- ret = (scheme == NULL);
- g_free (scheme);
- return ret;
+ scheme = g_uri_parse_scheme (uri);
+ ret = (scheme == NULL);
+ g_free (scheme);
+ return ret;
}
static char *
get_custom_icon_metadata_uri (NautilusFile *file)
{
- char *custom_icon_uri;
- char *uri;
- char *dir_uri;
-
- uri = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
- if (uri != NULL &&
- nautilus_file_is_directory (file) &&
- is_uri_relative (uri)) {
- dir_uri = nautilus_file_get_uri (file);
- custom_icon_uri = g_build_filename (dir_uri, uri, NULL);
- g_free (dir_uri);
- g_free (uri);
- } else {
- custom_icon_uri = uri;
- }
- return custom_icon_uri;
+ char *custom_icon_uri;
+ char *uri;
+ char *dir_uri;
+
+ uri = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
+ if (uri != NULL &&
+ nautilus_file_is_directory (file) &&
+ is_uri_relative (uri))
+ {
+ dir_uri = nautilus_file_get_uri (file);
+ custom_icon_uri = g_build_filename (dir_uri, uri, NULL);
+ g_free (dir_uri);
+ g_free (uri);
+ }
+ else
+ {
+ custom_icon_uri = uri;
+ }
+ return custom_icon_uri;
}
static char *
get_custom_icon_metadata_name (NautilusFile *file)
{
- char *icon_name;
+ char *icon_name;
- icon_name = nautilus_file_get_metadata (file,
- NAUTILUS_METADATA_KEY_CUSTOM_ICON_NAME, NULL);
+ icon_name = nautilus_file_get_metadata (file,
+ NAUTILUS_METADATA_KEY_CUSTOM_ICON_NAME, NULL);
- return icon_name;
+ return icon_name;
}
static GIcon *
get_mount_icon (NautilusFile *file)
{
- GMount *mount;
- GIcon *mount_icon;
+ GMount *mount;
+ GIcon *mount_icon;
- mount = nautilus_file_get_mount (file);
- mount_icon = NULL;
+ mount = nautilus_file_get_mount (file);
+ mount_icon = NULL;
- if (mount != NULL) {
- mount_icon = g_mount_get_icon (mount);
- g_object_unref (mount);
- }
+ if (mount != NULL)
+ {
+ mount_icon = g_mount_get_icon (mount);
+ g_object_unref (mount);
+ }
- return mount_icon;
+ return mount_icon;
}
static GIcon *
get_link_icon (NautilusFile *file)
{
- GIcon *icon = NULL;
+ GIcon *icon = NULL;
- if (file->details->got_link_info && file->details->custom_icon != NULL) {
- icon = g_object_ref (file->details->custom_icon);
- }
+ if (file->details->got_link_info && file->details->custom_icon != NULL)
+ {
+ icon = g_object_ref (file->details->custom_icon);
+ }
- return icon;
+ return icon;
}
static GIcon *
get_custom_icon (NautilusFile *file)
{
- char *custom_icon_uri, *custom_icon_name;
- GFile *icon_file;
- GIcon *icon;
-
- if (file == NULL) {
- return NULL;
- }
-
- icon = NULL;
-
- /* Metadata takes precedence; first we look at the custom
- * icon URI, then at the custom icon name.
- */
- custom_icon_uri = get_custom_icon_metadata_uri (file);
-
- if (custom_icon_uri) {
- icon_file = g_file_new_for_uri (custom_icon_uri);
- icon = g_file_icon_new (icon_file);
- g_object_unref (icon_file);
- g_free (custom_icon_uri);
- }
-
- if (icon == NULL) {
- custom_icon_name = get_custom_icon_metadata_name (file);
-
- if (custom_icon_name != NULL) {
- icon = g_themed_icon_new_with_default_fallbacks (custom_icon_name);
- g_free (custom_icon_name);
- }
- }
+ char *custom_icon_uri, *custom_icon_name;
+ GFile *icon_file;
+ GIcon *icon;
+
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
+ icon = NULL;
+
+ /* Metadata takes precedence; first we look at the custom
+ * icon URI, then at the custom icon name.
+ */
+ custom_icon_uri = get_custom_icon_metadata_uri (file);
+
+ if (custom_icon_uri)
+ {
+ icon_file = g_file_new_for_uri (custom_icon_uri);
+ icon = g_file_icon_new (icon_file);
+ g_object_unref (icon_file);
+ g_free (custom_icon_uri);
+ }
+
+ if (icon == NULL)
+ {
+ custom_icon_name = get_custom_icon_metadata_name (file);
+
+ if (custom_icon_name != NULL)
+ {
+ icon = g_themed_icon_new_with_default_fallbacks (custom_icon_name);
+ g_free (custom_icon_name);
+ }
+ }
- return icon;
+ return icon;
}
static GIcon *
get_custom_or_link_icon (NautilusFile *file)
{
- GIcon *icon;
+ GIcon *icon;
- icon = get_custom_icon (file);
- if (icon != NULL) {
- return icon;
- }
+ icon = get_custom_icon (file);
+ if (icon != NULL)
+ {
+ return icon;
+ }
- icon = get_link_icon (file);
- if (icon != NULL) {
- return icon;
- }
+ icon = get_link_icon (file);
+ if (icon != NULL)
+ {
+ return icon;
+ }
- return NULL;
+ return NULL;
}
static GIcon *
get_default_file_icon (void)
{
- static GIcon *fallback_icon = NULL;
- if (fallback_icon == NULL) {
- fallback_icon = g_themed_icon_new ("text-x-generic");
- }
+ static GIcon *fallback_icon = NULL;
+ if (fallback_icon == NULL)
+ {
+ fallback_icon = g_themed_icon_new ("text-x-generic");
+ }
- return fallback_icon;
+ return fallback_icon;
}
GFilesystemPreviewType
nautilus_file_get_filesystem_use_preview (NautilusFile *file)
{
- GFilesystemPreviewType use_preview;
- NautilusFile *parent;
+ GFilesystemPreviewType use_preview;
+ NautilusFile *parent;
- parent = nautilus_file_get_parent (file);
- if (parent != NULL) {
- use_preview = parent->details->filesystem_use_preview;
- g_object_unref (parent);
- } else {
- use_preview = 0;
- }
+ parent = nautilus_file_get_parent (file);
+ if (parent != NULL)
+ {
+ use_preview = parent->details->filesystem_use_preview;
+ g_object_unref (parent);
+ }
+ else
+ {
+ use_preview = 0;
+ }
- return use_preview;
+ return use_preview;
}
char *
nautilus_file_get_filesystem_type (NautilusFile *file)
{
- NautilusFile *parent;
- char *filesystem_type = NULL;
-
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_directory (file)) {
- filesystem_type = g_strdup (eel_ref_str_peek (file->details->filesystem_type));
- } else {
- parent = nautilus_file_get_parent (file);
- if (parent != NULL) {
- filesystem_type = g_strdup (eel_ref_str_peek (parent->details->filesystem_type));
- nautilus_file_unref (parent);
- }
+ NautilusFile *parent;
+ char *filesystem_type = NULL;
+
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ if (nautilus_file_is_directory (file))
+ {
+ filesystem_type = g_strdup (eel_ref_str_peek (file->details->filesystem_type));
+ }
+ else
+ {
+ parent = nautilus_file_get_parent (file);
+ if (parent != NULL)
+ {
+ filesystem_type = g_strdup (eel_ref_str_peek (parent->details->filesystem_type));
+ nautilus_file_unref (parent);
}
+ }
- return filesystem_type;
+ return filesystem_type;
}
gboolean
nautilus_file_should_show_thumbnail (NautilusFile *file)
{
- const char *mime_type;
- GFilesystemPreviewType use_preview;
-
- use_preview = nautilus_file_get_filesystem_use_preview (file);
-
- mime_type = eel_ref_str_peek (file->details->mime_type);
- if (mime_type == NULL) {
- mime_type = "application/octet-stream";
- }
-
- /* If the thumbnail has already been created, don't care about the size
- * of the original file.
- */
- if (nautilus_thumbnail_is_mimetype_limited_by_size (mime_type) &&
- file->details->thumbnail_path == NULL &&
- nautilus_file_get_size (file) > cached_thumbnail_limit) {
- return FALSE;
- }
-
- if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_ALWAYS) {
- if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
- return FALSE;
- } else {
- return TRUE;
- }
- } else if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_NEVER) {
- return FALSE;
- } else {
- if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
- /* file system says to never thumbnail anything */
- return FALSE;
- } else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL) {
- /* file system says we should treat file as if it's local */
- return TRUE;
- } else {
- /* only local files */
- return nautilus_file_is_local (file);
- }
- }
-
- return FALSE;
+ const char *mime_type;
+ GFilesystemPreviewType use_preview;
+
+ use_preview = nautilus_file_get_filesystem_use_preview (file);
+
+ mime_type = eel_ref_str_peek (file->details->mime_type);
+ if (mime_type == NULL)
+ {
+ mime_type = "application/octet-stream";
+ }
+
+ /* If the thumbnail has already been created, don't care about the size
+ * of the original file.
+ */
+ if (nautilus_thumbnail_is_mimetype_limited_by_size (mime_type) &&
+ file->details->thumbnail_path == NULL &&
+ nautilus_file_get_size (file) > cached_thumbnail_limit)
+ {
+ return FALSE;
+ }
+
+ if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
+ {
+ if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
+ {
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+ else if (show_file_thumbs == NAUTILUS_SPEED_TRADEOFF_NEVER)
+ {
+ return FALSE;
+ }
+ else
+ {
+ if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
+ {
+ /* file system says to never thumbnail anything */
+ return FALSE;
+ }
+ else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL)
+ {
+ /* file system says we should treat file as if it's local */
+ return TRUE;
+ }
+ else
+ {
+ /* only local files */
+ return nautilus_file_is_local (file);
+ }
+ }
+
+ return FALSE;
}
static gboolean
nautilus_is_video_file (NautilusFile *file)
{
- const char *mime_type;
- guint i;
+ const char *mime_type;
+ guint i;
- mime_type = eel_ref_str_peek (file->details->mime_type);
- if (mime_type == NULL)
- return FALSE;
+ mime_type = eel_ref_str_peek (file->details->mime_type);
+ if (mime_type == NULL)
+ {
+ return FALSE;
+ }
- for (i = 0; video_mime_types[i] != NULL; i++) {
- if (g_content_type_equals (video_mime_types[i], mime_type))
- return TRUE;
- }
+ for (i = 0; video_mime_types[i] != NULL; i++)
+ {
+ if (g_content_type_equals (video_mime_types[i], mime_type))
+ {
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static GList *
sort_keyword_list_and_remove_duplicates (GList *keywords)
{
- GList *p;
- GList *duplicate_link;
-
- if (keywords != NULL) {
- keywords = g_list_sort (keywords, (GCompareFunc) g_utf8_collate);
-
- p = keywords;
- while (p->next != NULL) {
- if (strcmp ((const char *) p->data, (const char *) p->next->data) == 0) {
- duplicate_link = p->next;
- keywords = g_list_remove_link (keywords, duplicate_link);
- g_list_free_full (duplicate_link, g_free);
- } else {
- p = p->next;
- }
- }
- }
+ GList *p;
+ GList *duplicate_link;
+
+ if (keywords != NULL)
+ {
+ keywords = g_list_sort (keywords, (GCompareFunc) g_utf8_collate);
+
+ p = keywords;
+ while (p->next != NULL)
+ {
+ if (strcmp ((const char *) p->data, (const char *) p->next->data) == 0)
+ {
+ duplicate_link = p->next;
+ keywords = g_list_remove_link (keywords, duplicate_link);
+ g_list_free_full (duplicate_link, g_free);
+ }
+ else
+ {
+ p = p->next;
+ }
+ }
+ }
- return keywords;
+ return keywords;
}
static void
-clean_up_metadata_keywords (NautilusFile *file,
- GList **metadata_keywords)
-{
- NautilusFile *parent_file;
- GList *l, *res = NULL;
- char *exclude[4];
- char *keyword;
- gboolean found;
- gint i;
-
- i = 0;
- exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_TRASH;
- exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_NOTE;
-
- parent_file = nautilus_file_get_parent (file);
- if (parent_file) {
- if (!nautilus_file_can_write (parent_file)) {
- exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE;
- }
- nautilus_file_unref (parent_file);
- }
- exclude[i++] = NULL;
-
- for (l = *metadata_keywords; l != NULL; l = l->next) {
- keyword = l->data;
- found = FALSE;
-
- for (i = 0; exclude[i] != NULL; i++) {
- if (strcmp (exclude[i], keyword) == 0) {
- found = TRUE;
- break;
- }
- }
-
- if (!found) {
- res = g_list_prepend (res, keyword);
- }
- }
-
- g_list_free (*metadata_keywords);
- *metadata_keywords = res;
+clean_up_metadata_keywords (NautilusFile *file,
+ GList **metadata_keywords)
+{
+ NautilusFile *parent_file;
+ GList *l, *res = NULL;
+ char *exclude[4];
+ char *keyword;
+ gboolean found;
+ gint i;
+
+ i = 0;
+ exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_TRASH;
+ exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_NOTE;
+
+ parent_file = nautilus_file_get_parent (file);
+ if (parent_file)
+ {
+ if (!nautilus_file_can_write (parent_file))
+ {
+ exclude[i++] = NAUTILUS_FILE_EMBLEM_NAME_CANT_WRITE;
+ }
+ nautilus_file_unref (parent_file);
+ }
+ exclude[i++] = NULL;
+
+ for (l = *metadata_keywords; l != NULL; l = l->next)
+ {
+ keyword = l->data;
+ found = FALSE;
+
+ for (i = 0; exclude[i] != NULL; i++)
+ {
+ if (strcmp (exclude[i], keyword) == 0)
+ {
+ found = TRUE;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ res = g_list_prepend (res, keyword);
+ }
+ }
+
+ g_list_free (*metadata_keywords);
+ *metadata_keywords = res;
}
/**
@@ -4472,22 +5020,23 @@ clean_up_metadata_keywords (NautilusFile *file,
static GList *
nautilus_file_get_keywords (NautilusFile *file)
{
- GList *keywords, *metadata_keywords;
+ GList *keywords, *metadata_keywords;
- if (file == NULL) {
- return NULL;
- }
+ if (file == NULL)
+ {
+ return NULL;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- keywords = g_list_copy_deep (file->details->extension_emblems, (GCopyFunc) g_strdup, NULL);
- keywords = g_list_concat (keywords, g_list_copy_deep (file->details->pending_extension_emblems, (GCopyFunc) g_strdup, NULL));
+ keywords = g_list_copy_deep (file->details->extension_emblems, (GCopyFunc) g_strdup, NULL);
+ keywords = g_list_concat (keywords, g_list_copy_deep (file->details->pending_extension_emblems, (GCopyFunc) g_strdup, NULL));
- metadata_keywords = nautilus_file_get_metadata_list (file, NAUTILUS_METADATA_KEY_EMBLEMS);
- clean_up_metadata_keywords (file, &metadata_keywords);
- keywords = g_list_concat (keywords, metadata_keywords);
+ metadata_keywords = nautilus_file_get_metadata_list (file, NAUTILUS_METADATA_KEY_EMBLEMS);
+ clean_up_metadata_keywords (file, &metadata_keywords);
+ keywords = g_list_concat (keywords, metadata_keywords);
- return sort_keyword_list_and_remove_duplicates (keywords);
+ return sort_keyword_list_and_remove_duplicates (keywords);
}
/**
@@ -4503,708 +5052,832 @@ nautilus_file_get_keywords (NautilusFile *file)
static GList *
nautilus_file_get_emblem_icons (NautilusFile *file)
{
- GList *keywords, *l;
- GList *icons;
- char *icon_names[2];
- char *keyword;
- GIcon *icon;
+ GList *keywords, *l;
+ GList *icons;
+ char *icon_names[2];
+ char *keyword;
+ GIcon *icon;
- if (file == NULL) {
- return NULL;
- }
+ if (file == NULL)
+ {
+ return NULL;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- keywords = nautilus_file_get_keywords (file);
- keywords = prepend_automatic_keywords (file, keywords);
+ keywords = nautilus_file_get_keywords (file);
+ keywords = prepend_automatic_keywords (file, keywords);
- icons = NULL;
- for (l = keywords; l != NULL; l = l->next) {
- keyword = l->data;
+ icons = NULL;
+ for (l = keywords; l != NULL; l = l->next)
+ {
+ keyword = l->data;
- icon_names[0] = g_strconcat ("emblem-", keyword, NULL);
- icon_names[1] = keyword;
- icon = g_themed_icon_new_from_names (icon_names, 2);
- g_free (icon_names[0]);
+ icon_names[0] = g_strconcat ("emblem-", keyword, NULL);
+ icon_names[1] = keyword;
+ icon = g_themed_icon_new_from_names (icon_names, 2);
+ g_free (icon_names[0]);
- icons = g_list_prepend (icons, icon);
- }
+ icons = g_list_prepend (icons, icon);
+ }
- icon = get_mount_icon (file);
- if (icon != NULL) {
- icons = g_list_prepend (icons, icon);
- }
+ icon = get_mount_icon (file);
+ if (icon != NULL)
+ {
+ icons = g_list_prepend (icons, icon);
+ }
- g_list_free_full (keywords, g_free);
+ g_list_free_full (keywords, g_free);
- return icons;
+ return icons;
}
static void
-prepend_icon_name (const char *name,
- GThemedIcon *icon)
+prepend_icon_name (const char *name,
+ GThemedIcon *icon)
{
- g_themed_icon_prepend_name(icon, name);
+ g_themed_icon_prepend_name (icon, name);
}
static GIcon *
-apply_emblems_to_icon (NautilusFile *file,
- GIcon *icon,
- NautilusFileIconFlags flags)
-{
- GIcon *emblemed_icon;
- GEmblem *emblem;
- GList *emblems, *l;
-
- emblemed_icon = NULL;
- emblems = nautilus_file_get_emblem_icons (file);
-
- for (l = emblems; l != NULL; l = l->next) {
- if (g_icon_equal (l->data, icon)) {
- continue;
- }
+apply_emblems_to_icon (NautilusFile *file,
+ GIcon *icon,
+ NautilusFileIconFlags flags)
+{
+ GIcon *emblemed_icon;
+ GEmblem *emblem;
+ GList *emblems, *l;
+
+ emblemed_icon = NULL;
+ emblems = nautilus_file_get_emblem_icons (file);
+
+ for (l = emblems; l != NULL; l = l->next)
+ {
+ if (g_icon_equal (l->data, icon))
+ {
+ continue;
+ }
- emblem = g_emblem_new (l->data);
+ emblem = g_emblem_new (l->data);
- if (emblemed_icon == NULL) {
- emblemed_icon = g_emblemed_icon_new (icon, emblem);
- } else {
- g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem);
- }
+ if (emblemed_icon == NULL)
+ {
+ emblemed_icon = g_emblemed_icon_new (icon, emblem);
+ }
+ else
+ {
+ g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (emblemed_icon), emblem);
+ }
- if (emblemed_icon != NULL &&
- (flags & NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM)) {
- break;
- }
- }
+ if (emblemed_icon != NULL &&
+ (flags & NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM))
+ {
+ break;
+ }
+ }
- if (emblems != NULL) {
- g_list_free_full (emblems, g_object_unref);
- }
+ if (emblems != NULL)
+ {
+ g_list_free_full (emblems, g_object_unref);
+ }
- if (emblemed_icon != NULL) {
- return emblemed_icon;
- } else {
- return g_object_ref (icon);
- }
+ if (emblemed_icon != NULL)
+ {
+ return emblemed_icon;
+ }
+ else
+ {
+ return g_object_ref (icon);
+ }
}
GIcon *
-nautilus_file_get_gicon (NautilusFile *file,
- NautilusFileIconFlags flags)
-{
- const char * const * names;
- const char *name;
- GPtrArray *prepend_array;
- GIcon *icon, *emblemed_icon;
- int i;
- gboolean is_folder = FALSE, is_inode_directory = FALSE;
-
- if (file == NULL) {
- return NULL;
- }
-
- icon = get_custom_or_link_icon (file);
- if (icon != NULL) {
- return icon;
- }
-
- if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON) {
- icon = get_mount_icon (file);
-
- if (icon != NULL) {
- goto out;
- }
- }
-
- if (file->details->icon) {
- icon = NULL;
-
- if (((flags & NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT) ||
- (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_OPEN_FOLDER) ||
- (flags & NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON) ||
- (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS)) &&
- G_IS_THEMED_ICON (file->details->icon)) {
- names = g_themed_icon_get_names (G_THEMED_ICON (file->details->icon));
- prepend_array = g_ptr_array_new ();
-
- for (i = 0; names[i] != NULL; i++) {
- name = names[i];
-
- if (strcmp (name, "folder") == 0) {
- is_folder = TRUE;
- }
- if (strcmp (name, "inode-directory") == 0) {
- is_inode_directory = TRUE;
- }
- }
-
- /* Here, we add icons in reverse order of precedence,
- * because they are later prepended */
-
- /* "folder" should override "inode-directory", not the other way around */
- if (is_inode_directory) {
- g_ptr_array_add (prepend_array, "folder");
- }
- if (is_folder && (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_OPEN_FOLDER)) {
- g_ptr_array_add (prepend_array, "folder-open");
- }
- if (is_folder &&
- (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT)) {
- g_ptr_array_add (prepend_array, "folder-drag-accept");
- }
-
- if (prepend_array->len) {
- /* When constructing GThemed Icon, pointers from the array
- * are reused, but not the array itself, so the cast is safe */
- icon = g_themed_icon_new_from_names ((char**) names, -1);
- g_ptr_array_foreach (prepend_array, (GFunc) prepend_icon_name, icon);
- }
-
- g_ptr_array_free (prepend_array, TRUE);
- }
-
- if (icon == NULL) {
- icon = g_object_ref (file->details->icon);
- }
- }
-
- out:
- if (icon == NULL) {
- icon = g_object_ref (get_default_file_icon ());
- }
-
- if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS) {
- emblemed_icon = apply_emblems_to_icon (file, icon, flags);
- g_object_unref (icon);
- icon = emblemed_icon;
- }
-
- return icon;
+nautilus_file_get_gicon (NautilusFile *file,
+ NautilusFileIconFlags flags)
+{
+ const char * const *names;
+ const char *name;
+ GPtrArray *prepend_array;
+ GIcon *icon, *emblemed_icon;
+ int i;
+ gboolean is_folder = FALSE, is_inode_directory = FALSE;
+
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
+ icon = get_custom_or_link_icon (file);
+ if (icon != NULL)
+ {
+ return icon;
+ }
+
+ if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON)
+ {
+ icon = get_mount_icon (file);
+
+ if (icon != NULL)
+ {
+ goto out;
+ }
+ }
+
+ if (file->details->icon)
+ {
+ icon = NULL;
+
+ if (((flags & NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT) ||
+ (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_OPEN_FOLDER) ||
+ (flags & NAUTILUS_FILE_ICON_FLAGS_USE_MOUNT_ICON) ||
+ (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS)) &&
+ G_IS_THEMED_ICON (file->details->icon))
+ {
+ names = g_themed_icon_get_names (G_THEMED_ICON (file->details->icon));
+ prepend_array = g_ptr_array_new ();
+
+ for (i = 0; names[i] != NULL; i++)
+ {
+ name = names[i];
+
+ if (strcmp (name, "folder") == 0)
+ {
+ is_folder = TRUE;
+ }
+ if (strcmp (name, "inode-directory") == 0)
+ {
+ is_inode_directory = TRUE;
+ }
+ }
+
+ /* Here, we add icons in reverse order of precedence,
+ * because they are later prepended */
+
+ /* "folder" should override "inode-directory", not the other way around */
+ if (is_inode_directory)
+ {
+ g_ptr_array_add (prepend_array, "folder");
+ }
+ if (is_folder && (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_OPEN_FOLDER))
+ {
+ g_ptr_array_add (prepend_array, "folder-open");
+ }
+ if (is_folder &&
+ (flags & NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT))
+ {
+ g_ptr_array_add (prepend_array, "folder-drag-accept");
+ }
+
+ if (prepend_array->len)
+ {
+ /* When constructing GThemed Icon, pointers from the array
+ * are reused, but not the array itself, so the cast is safe */
+ icon = g_themed_icon_new_from_names ((char **) names, -1);
+ g_ptr_array_foreach (prepend_array, (GFunc) prepend_icon_name, icon);
+ }
+
+ g_ptr_array_free (prepend_array, TRUE);
+ }
+
+ if (icon == NULL)
+ {
+ icon = g_object_ref (file->details->icon);
+ }
+ }
+
+out:
+ if (icon == NULL)
+ {
+ icon = g_object_ref (get_default_file_icon ());
+ }
+
+ if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS)
+ {
+ emblemed_icon = apply_emblems_to_icon (file, icon, flags);
+ g_object_unref (icon);
+ icon = emblemed_icon;
+ }
+
+ return icon;
}
char *
nautilus_file_get_thumbnail_path (NautilusFile *file)
{
- return g_strdup (file->details->thumbnail_path);
+ return g_strdup (file->details->thumbnail_path);
}
static NautilusIconInfo *
-nautilus_file_get_thumbnail_icon (NautilusFile *file,
- int size,
- int scale,
- NautilusFileIconFlags flags)
-{
- int modified_size;
- GdkPixbuf *pixbuf;
- int w, h, s;
- double thumb_scale;
- GIcon *gicon, *emblemed_icon;
- NautilusIconInfo *icon;
-
- icon = NULL;
- gicon = NULL;
- pixbuf = NULL;
-
- if (flags & NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE) {
- modified_size = size * scale;
- } else {
- modified_size = size * scale * cached_thumbnail_size / NAUTILUS_CANVAS_ICON_SIZE_SMALL;
- DEBUG ("Modifying icon size to %d, as our cached thumbnail size is %d",
- modified_size, cached_thumbnail_size);
- }
-
- if (file->details->thumbnail) {
- w = gdk_pixbuf_get_width (file->details->thumbnail);
- h = gdk_pixbuf_get_height (file->details->thumbnail);
-
- s = MAX (w, h);
- /* Don't scale up small thumbnails in the standard view */
- if (s <= cached_thumbnail_size) {
- thumb_scale = (double) size / NAUTILUS_CANVAS_ICON_SIZE_SMALL;
- } else {
- thumb_scale = (double) modified_size / s;
- }
-
- /* Make sure that icons don't get smaller than NAUTILUS_LIST_ICON_SIZE_SMALL */
- if (s * thumb_scale <= NAUTILUS_LIST_ICON_SIZE_SMALL) {
- thumb_scale = (double) NAUTILUS_LIST_ICON_SIZE_SMALL / s;
- }
-
- if (file->details->thumbnail_scale == thumb_scale &&
- file->details->scaled_thumbnail != NULL) {
- pixbuf = file->details->scaled_thumbnail;
- } else {
- pixbuf = gdk_pixbuf_scale_simple (file->details->thumbnail,
- MAX (w * thumb_scale, 1),
- MAX (h * thumb_scale, 1),
- GDK_INTERP_BILINEAR);
-
- /* We don't want frames around small icons */
- if (!gdk_pixbuf_get_has_alpha (file->details->thumbnail) || s >= 128 * scale) {
- if (nautilus_is_video_file (file)) {
- nautilus_ui_frame_video (&pixbuf);
- } else {
- nautilus_ui_frame_image (&pixbuf);
- }
- }
-
- g_clear_object (&file->details->scaled_thumbnail);
- file->details->scaled_thumbnail = pixbuf;
- file->details->thumbnail_scale = thumb_scale;
- }
-
- /* Don't scale up if more than 25%, then read the original
- image instead. We don't want to compare to exactly 100%,
- since the zoom level 150% gives thumbnails at 144, which is
- ok to scale up from 128. */
- if (modified_size > 128 * 1.25 * scale &&
- !file->details->thumbnail_wants_original &&
- nautilus_can_thumbnail_internally (file)) {
- /* Invalidate if we resize upward */
- file->details->thumbnail_wants_original = TRUE;
- nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL);
- }
-
- DEBUG ("Returning thumbnailed image, at size %d %d",
- (int) (w * thumb_scale), (int) (h * thumb_scale));
- } else if (file->details->thumbnail_path == NULL &&
- file->details->can_read &&
- !file->details->is_thumbnailing &&
- !file->details->thumbnailing_failed &&
- nautilus_can_thumbnail (file)) {
- nautilus_create_thumbnail (file);
- }
-
- if (pixbuf != NULL) {
- gicon = g_object_ref (pixbuf);
- } else if (file->details->is_thumbnailing) {
- gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
- }
-
- if (gicon != NULL) {
- emblemed_icon = apply_emblems_to_icon (file, gicon, flags);
- g_object_unref (gicon);
-
- if (g_icon_equal (emblemed_icon, G_ICON (pixbuf))) {
- icon = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
- } else {
- icon = nautilus_icon_info_lookup (emblemed_icon, size, scale);
- }
-
- g_object_unref (emblemed_icon);
- }
-
- return icon;
-}
-
-static gboolean
-nautilus_thumbnail_is_limited_by_zoom (int size,
- int scale)
-{
- int zoom_level;
+nautilus_file_get_thumbnail_icon (NautilusFile *file,
+ int size,
+ int scale,
+ NautilusFileIconFlags flags)
+{
+ int modified_size;
+ GdkPixbuf *pixbuf;
+ int w, h, s;
+ double thumb_scale;
+ GIcon *gicon, *emblemed_icon;
+ NautilusIconInfo *icon;
+
+ icon = NULL;
+ gicon = NULL;
+ pixbuf = NULL;
+
+ if (flags & NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE)
+ {
+ modified_size = size * scale;
+ }
+ else
+ {
+ modified_size = size * scale * cached_thumbnail_size / NAUTILUS_CANVAS_ICON_SIZE_SMALL;
+ DEBUG ("Modifying icon size to %d, as our cached thumbnail size is %d",
+ modified_size, cached_thumbnail_size);
+ }
+
+ if (file->details->thumbnail)
+ {
+ w = gdk_pixbuf_get_width (file->details->thumbnail);
+ h = gdk_pixbuf_get_height (file->details->thumbnail);
+
+ s = MAX (w, h);
+ /* Don't scale up small thumbnails in the standard view */
+ if (s <= cached_thumbnail_size)
+ {
+ thumb_scale = (double) size / NAUTILUS_CANVAS_ICON_SIZE_SMALL;
+ }
+ else
+ {
+ thumb_scale = (double) modified_size / s;
+ }
- zoom_level = size * scale;
+ /* Make sure that icons don't get smaller than NAUTILUS_LIST_ICON_SIZE_SMALL */
+ if (s * thumb_scale <= NAUTILUS_LIST_ICON_SIZE_SMALL)
+ {
+ thumb_scale = (double) NAUTILUS_LIST_ICON_SIZE_SMALL / s;
+ }
- if (zoom_level <= NAUTILUS_LIST_ICON_SIZE_SMALL)
- return TRUE;
+ if (file->details->thumbnail_scale == thumb_scale &&
+ file->details->scaled_thumbnail != NULL)
+ {
+ pixbuf = file->details->scaled_thumbnail;
+ }
+ else
+ {
+ pixbuf = gdk_pixbuf_scale_simple (file->details->thumbnail,
+ MAX (w * thumb_scale, 1),
+ MAX (h * thumb_scale, 1),
+ GDK_INTERP_BILINEAR);
+
+ /* We don't want frames around small icons */
+ if (!gdk_pixbuf_get_has_alpha (file->details->thumbnail) || s >= 128 * scale)
+ {
+ if (nautilus_is_video_file (file))
+ {
+ nautilus_ui_frame_video (&pixbuf);
+ }
+ else
+ {
+ nautilus_ui_frame_image (&pixbuf);
+ }
+ }
- return FALSE;
-}
+ g_clear_object (&file->details->scaled_thumbnail);
+ file->details->scaled_thumbnail = pixbuf;
+ file->details->thumbnail_scale = thumb_scale;
+ }
-NautilusIconInfo *
-nautilus_file_get_icon (NautilusFile *file,
- int size,
- int scale,
- NautilusFileIconFlags flags)
-{
- NautilusIconInfo *icon;
- GIcon *gicon;
+ /* Don't scale up if more than 25%, then read the original
+ * image instead. We don't want to compare to exactly 100%,
+ * since the zoom level 150% gives thumbnails at 144, which is
+ * ok to scale up from 128. */
+ if (modified_size > 128 * 1.25 * scale &&
+ !file->details->thumbnail_wants_original &&
+ nautilus_can_thumbnail_internally (file))
+ {
+ /* Invalidate if we resize upward */
+ file->details->thumbnail_wants_original = TRUE;
+ nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL);
+ }
- icon = NULL;
+ DEBUG ("Returning thumbnailed image, at size %d %d",
+ (int) (w * thumb_scale), (int) (h * thumb_scale));
+ }
+ else if (file->details->thumbnail_path == NULL &&
+ file->details->can_read &&
+ !file->details->is_thumbnailing &&
+ !file->details->thumbnailing_failed &&
+ nautilus_can_thumbnail (file))
+ {
+ nautilus_create_thumbnail (file);
+ }
+
+ if (pixbuf != NULL)
+ {
+ gicon = g_object_ref (pixbuf);
+ }
+ else if (file->details->is_thumbnailing)
+ {
+ gicon = g_themed_icon_new (ICON_NAME_THUMBNAIL_LOADING);
+ }
+
+ if (gicon != NULL)
+ {
+ emblemed_icon = apply_emblems_to_icon (file, gicon, flags);
+ g_object_unref (gicon);
+
+ if (g_icon_equal (emblemed_icon, G_ICON (pixbuf)))
+ {
+ icon = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
+ }
+ else
+ {
+ icon = nautilus_icon_info_lookup (emblemed_icon, size, scale);
+ }
- if (file == NULL) {
- goto out;
- }
+ g_object_unref (emblemed_icon);
+ }
- gicon = get_custom_or_link_icon (file);
- if (gicon != NULL) {
- icon = nautilus_icon_info_lookup (gicon, size, scale);
- g_object_unref (gicon);
+ return icon;
+}
- goto out;
- }
+static gboolean
+nautilus_thumbnail_is_limited_by_zoom (int size,
+ int scale)
+{
+ int zoom_level;
- DEBUG ("Called file_get_icon(), at size %d, force thumbnail %d", size,
- flags & NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE);
+ zoom_level = size * scale;
- if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS &&
- nautilus_file_should_show_thumbnail (file) &&
- !nautilus_thumbnail_is_limited_by_zoom (size, scale)) {
- icon = nautilus_file_get_thumbnail_icon (file, size, scale, flags);
- }
+ if (zoom_level <= NAUTILUS_LIST_ICON_SIZE_SMALL)
+ {
+ return TRUE;
+ }
- if (icon == NULL) {
- gicon = nautilus_file_get_gicon (file, flags);
- icon = nautilus_icon_info_lookup (gicon, size, scale);
- g_object_unref (gicon);
+ return FALSE;
+}
- if (nautilus_icon_info_is_fallback (icon)) {
- g_object_unref (icon);
- icon = nautilus_icon_info_lookup (get_default_file_icon (), size, scale);
- }
- }
+NautilusIconInfo *
+nautilus_file_get_icon (NautilusFile *file,
+ int size,
+ int scale,
+ NautilusFileIconFlags flags)
+{
+ NautilusIconInfo *icon;
+ GIcon *gicon;
+
+ icon = NULL;
+
+ if (file == NULL)
+ {
+ goto out;
+ }
+
+ gicon = get_custom_or_link_icon (file);
+ if (gicon != NULL)
+ {
+ icon = nautilus_icon_info_lookup (gicon, size, scale);
+ g_object_unref (gicon);
+
+ goto out;
+ }
+
+ DEBUG ("Called file_get_icon(), at size %d, force thumbnail %d", size,
+ flags & NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE);
+
+ if (flags & NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS &&
+ nautilus_file_should_show_thumbnail (file) &&
+ !nautilus_thumbnail_is_limited_by_zoom (size, scale))
+ {
+ icon = nautilus_file_get_thumbnail_icon (file, size, scale, flags);
+ }
+
+ if (icon == NULL)
+ {
+ gicon = nautilus_file_get_gicon (file, flags);
+ icon = nautilus_icon_info_lookup (gicon, size, scale);
+ g_object_unref (gicon);
+
+ if (nautilus_icon_info_is_fallback (icon))
+ {
+ g_object_unref (icon);
+ icon = nautilus_icon_info_lookup (get_default_file_icon (), size, scale);
+ }
+ }
- out:
- return icon;
+out:
+ return icon;
}
GdkPixbuf *
-nautilus_file_get_icon_pixbuf (NautilusFile *file,
- int size,
- gboolean force_size,
- int scale,
- NautilusFileIconFlags flags)
-{
- NautilusIconInfo *info;
- GdkPixbuf *pixbuf;
-
- info = nautilus_file_get_icon (file, size, scale, flags);
- if (force_size) {
- pixbuf = nautilus_icon_info_get_pixbuf_at_size (info, size);
- } else {
- pixbuf = nautilus_icon_info_get_pixbuf (info);
- }
- g_object_unref (info);
-
- return pixbuf;
-}
-
-gboolean
-nautilus_file_get_date (NautilusFile *file,
- NautilusDateType date_type,
- time_t *date)
+nautilus_file_get_icon_pixbuf (NautilusFile *file,
+ int size,
+ gboolean force_size,
+ int scale,
+ NautilusFileIconFlags flags)
{
- if (date != NULL) {
- *date = 0;
- }
+ NautilusIconInfo *info;
+ GdkPixbuf *pixbuf;
+
+ info = nautilus_file_get_icon (file, size, scale, flags);
+ if (force_size)
+ {
+ pixbuf = nautilus_icon_info_get_pixbuf_at_size (info, size);
+ }
+ else
+ {
+ pixbuf = nautilus_icon_info_get_pixbuf (info);
+ }
+ g_object_unref (info);
- g_return_val_if_fail (date_type == NAUTILUS_DATE_TYPE_ACCESSED
- || date_type == NAUTILUS_DATE_TYPE_MODIFIED
- || date_type == NAUTILUS_DATE_TYPE_TRASHED,
- FALSE);
+ return pixbuf;
+}
- if (file == NULL) {
- return FALSE;
- }
+gboolean
+nautilus_file_get_date (NautilusFile *file,
+ NautilusDateType date_type,
+ time_t *date)
+{
+ if (date != NULL)
+ {
+ *date = 0;
+ }
+
+ g_return_val_if_fail (date_type == NAUTILUS_DATE_TYPE_ACCESSED
+ || date_type == NAUTILUS_DATE_TYPE_MODIFIED
+ || date_type == NAUTILUS_DATE_TYPE_TRASHED,
+ FALSE);
+
+ if (file == NULL)
+ {
+ return FALSE;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_date (file, date_type, date);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_date (file, date_type, date);
}
static char *
nautilus_file_get_where_string (NautilusFile *file)
{
- if (file == NULL) {
- return NULL;
- }
+ if (file == NULL)
+ {
+ return NULL;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_where_string (file);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_where_string (file);
}
static char *
nautilus_file_get_trash_original_file_parent_as_string (NautilusFile *file)
{
- NautilusFile *orig_file, *parent;
- GFile *location;
- char *filename;
+ NautilusFile *orig_file, *parent;
+ GFile *location;
+ char *filename;
- if (file->details->trash_orig_path != NULL) {
- orig_file = nautilus_file_get_trash_original_file (file);
- parent = nautilus_file_get_parent (orig_file);
- location = nautilus_file_get_location (parent);
+ if (file->details->trash_orig_path != NULL)
+ {
+ orig_file = nautilus_file_get_trash_original_file (file);
+ parent = nautilus_file_get_parent (orig_file);
+ location = nautilus_file_get_location (parent);
- filename = g_file_get_basename (location);
+ filename = g_file_get_basename (location);
- g_object_unref (location);
- nautilus_file_unref (parent);
- nautilus_file_unref (orig_file);
+ g_object_unref (location);
+ nautilus_file_unref (parent);
+ nautilus_file_unref (orig_file);
- return filename;
- }
+ return filename;
+ }
- return NULL;
+ return NULL;
}
/**
* nautilus_file_get_date_as_string:
- *
- * Get a user-displayable string representing a file modification date.
+ *
+ * Get a user-displayable string representing a file modification date.
* The caller is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_date_as_string (NautilusFile *file,
NautilusDateType date_type,
NautilusDateFormat date_format)
{
- time_t file_time_raw;
- GDateTime *file_date_time, *now;
- GDateTime *today_midnight;
- gint days_ago;
- gboolean use_24;
- const gchar *format;
- gchar *result;
- gchar *result_with_ratio;
-
- if (!nautilus_file_get_date (file, date_type, &file_time_raw))
- return NULL;
-
- file_date_time = g_date_time_new_from_unix_local (file_time_raw);
- if (date_format != NAUTILUS_DATE_FORMAT_FULL) {
- GDateTime *file_date;
-
- now = g_date_time_new_now_local ();
- today_midnight = g_date_time_new_local (g_date_time_get_year (now),
- g_date_time_get_month (now),
- g_date_time_get_day_of_month (now),
- 0, 0, 0);
-
- file_date = g_date_time_new_local (g_date_time_get_year (file_date_time),
- g_date_time_get_month (file_date_time),
- g_date_time_get_day_of_month (file_date_time),
- 0, 0, 0);
-
- days_ago = g_date_time_difference (today_midnight, file_date) / G_TIME_SPAN_DAY;
-
- use_24 = g_settings_get_enum (gnome_interface_preferences, "clock-format") ==
- G_DESKTOP_CLOCK_FORMAT_24H;
-
- // Show only the time if date is on today
- if (days_ago < 1) {
- if (use_24) {
- /* Translators: Time in 24h format */
- format = _("%H:%M");
- } else {
- /* Translators: Time in 12h format */
- format = _("%l:%M %p");
- }
- }
- // Show the word "Yesterday" and time if date is on yesterday
- else if (days_ago < 2) {
- if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
- // xgettext:no-c-format
- format = _("Yesterday");
- } else {
- if (use_24) {
- /* Translators: this is the word Yesterday followed by
- * a time in 24h format. i.e. "Yesterday 23:04" */
- // xgettext:no-c-format
- format = _("Yesterday %H:%M");
- } else {
- /* Translators: this is the word Yesterday followed by
- * a time in 12h format. i.e. "Yesterday 9:04 PM" */
- // xgettext:no-c-format
- format = _("Yesterday %l:%M %p");
- }
- }
- }
- // Show a week day and time if date is in the last week
- else if (days_ago < 7) {
- if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
- // xgettext:no-c-format
- format = _("%a");
- } else {
- if (use_24) {
- /* Translators: this is the name of the week day followed by
- * a time in 24h format. i.e. "Monday 23:04" */
- // xgettext:no-c-format
- format = _("%a %H:%M");
- } else {
- /* Translators: this is the week day name followed by
- * a time in 12h format. i.e. "Monday 9:04 PM" */
- // xgettext:no-c-format
- format = _("%a %l:%M %p");
- }
- }
- } else if (g_date_time_get_year (file_date) == g_date_time_get_year (now)) {
- if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
- /* Translators: this is the day of the month followed
- * by the abbreviated month name i.e. "3 Feb" */
- // xgettext:no-c-format
- format = _("%-e %b");
- } else {
- if (use_24) {
- /* Translators: this is the day of the month followed
- * by the abbreviated month name followed by a time in
- * 24h format i.e. "3 Feb 23:04" */
- // xgettext:no-c-format
- format = _("%-e %b %H:%M");
- } else {
- /* Translators: this is the day of the month followed
- * by the abbreviated month name followed by a time in
- * 12h format i.e. "3 Feb 9:04" */
- // xgettext:no-c-format
- format = _("%-e %b %l:%M %p");
- }
- }
- } else {
- if (date_format == NAUTILUS_DATE_FORMAT_REGULAR) {
- /* Translators: this is the day of the month followed by the abbreviated
- * month name followed by the year i.e. "3 Feb 2015" */
- // xgettext:no-c-format
- format = _("%-e %b %Y");
- } else {
- if (use_24) {
- /* Translators: this is the day number followed
- * by the abbreviated month name followed by the year followed
- * by a time in 24h format i.e. "3 Feb 2015 23:04" */
- // xgettext:no-c-format
- format = _("%-e %b %Y %H:%M");
- } else {
- /* Translators: this is the day number followed
- * by the abbreviated month name followed by the year followed
- * by a time in 12h format i.e. "3 Feb 2015 9:04 PM" */
- // xgettext:no-c-format
- format = _("%-e %b %Y %l:%M %p");
- }
- }
- }
-
- g_date_time_unref (file_date);
- g_date_time_unref (now);
- g_date_time_unref (today_midnight);
- } else {
- // xgettext:no-c-format
- format = _("%c");
- }
-
- result = g_date_time_format (file_date_time, format);
- g_date_time_unref (file_date_time);
-
- /* Replace ":" with ratio. Replacement is done afterward because g_date_time_format
- * may fail with utf8 chars in some locales */
- result_with_ratio = eel_str_replace_substring (result, ":", "∶");
- g_free (result);
-
- return result_with_ratio;
+ time_t file_time_raw;
+ GDateTime *file_date_time, *now;
+ GDateTime *today_midnight;
+ gint days_ago;
+ gboolean use_24;
+ const gchar *format;
+ gchar *result;
+ gchar *result_with_ratio;
+
+ if (!nautilus_file_get_date (file, date_type, &file_time_raw))
+ {
+ return NULL;
+ }
+
+ file_date_time = g_date_time_new_from_unix_local (file_time_raw);
+ if (date_format != NAUTILUS_DATE_FORMAT_FULL)
+ {
+ GDateTime *file_date;
+
+ now = g_date_time_new_now_local ();
+ today_midnight = g_date_time_new_local (g_date_time_get_year (now),
+ g_date_time_get_month (now),
+ g_date_time_get_day_of_month (now),
+ 0, 0, 0);
+
+ file_date = g_date_time_new_local (g_date_time_get_year (file_date_time),
+ g_date_time_get_month (file_date_time),
+ g_date_time_get_day_of_month (file_date_time),
+ 0, 0, 0);
+
+ days_ago = g_date_time_difference (today_midnight, file_date) / G_TIME_SPAN_DAY;
+
+ use_24 = g_settings_get_enum (gnome_interface_preferences, "clock-format") ==
+ G_DESKTOP_CLOCK_FORMAT_24H;
+
+ /* Show only the time if date is on today */
+ if (days_ago < 1)
+ {
+ if (use_24)
+ {
+ /* Translators: Time in 24h format */
+ format = _("%H:%M");
+ }
+ else
+ {
+ /* Translators: Time in 12h format */
+ format = _("%l:%M %p");
+ }
+ }
+ /* Show the word "Yesterday" and time if date is on yesterday */
+ else if (days_ago < 2)
+ {
+ if (date_format == NAUTILUS_DATE_FORMAT_REGULAR)
+ {
+ /* xgettext:no-c-format */
+ format = _("Yesterday");
+ }
+ else
+ {
+ if (use_24)
+ {
+ /* Translators: this is the word Yesterday followed by
+ * a time in 24h format. i.e. "Yesterday 23:04" */
+ /* xgettext:no-c-format */
+ format = _("Yesterday %H:%M");
+ }
+ else
+ {
+ /* Translators: this is the word Yesterday followed by
+ * a time in 12h format. i.e. "Yesterday 9:04 PM" */
+ /* xgettext:no-c-format */
+ format = _("Yesterday %l:%M %p");
+ }
+ }
+ }
+ /* Show a week day and time if date is in the last week */
+ else if (days_ago < 7)
+ {
+ if (date_format == NAUTILUS_DATE_FORMAT_REGULAR)
+ {
+ /* xgettext:no-c-format */
+ format = _("%a");
+ }
+ else
+ {
+ if (use_24)
+ {
+ /* Translators: this is the name of the week day followed by
+ * a time in 24h format. i.e. "Monday 23:04" */
+ /* xgettext:no-c-format */
+ format = _("%a %H:%M");
+ }
+ else
+ {
+ /* Translators: this is the week day name followed by
+ * a time in 12h format. i.e. "Monday 9:04 PM" */
+ /* xgettext:no-c-format */
+ format = _("%a %l:%M %p");
+ }
+ }
+ }
+ else if (g_date_time_get_year (file_date) == g_date_time_get_year (now))
+ {
+ if (date_format == NAUTILUS_DATE_FORMAT_REGULAR)
+ {
+ /* Translators: this is the day of the month followed
+ * by the abbreviated month name i.e. "3 Feb" */
+ /* xgettext:no-c-format */
+ format = _("%-e %b");
+ }
+ else
+ {
+ if (use_24)
+ {
+ /* Translators: this is the day of the month followed
+ * by the abbreviated month name followed by a time in
+ * 24h format i.e. "3 Feb 23:04" */
+ /* xgettext:no-c-format */
+ format = _("%-e %b %H:%M");
+ }
+ else
+ {
+ /* Translators: this is the day of the month followed
+ * by the abbreviated month name followed by a time in
+ * 12h format i.e. "3 Feb 9:04" */
+ /* xgettext:no-c-format */
+ format = _("%-e %b %l:%M %p");
+ }
+ }
+ }
+ else
+ {
+ if (date_format == NAUTILUS_DATE_FORMAT_REGULAR)
+ {
+ /* Translators: this is the day of the month followed by the abbreviated
+ * month name followed by the year i.e. "3 Feb 2015" */
+ /* xgettext:no-c-format */
+ format = _("%-e %b %Y");
+ }
+ else
+ {
+ if (use_24)
+ {
+ /* Translators: this is the day number followed
+ * by the abbreviated month name followed by the year followed
+ * by a time in 24h format i.e. "3 Feb 2015 23:04" */
+ /* xgettext:no-c-format */
+ format = _("%-e %b %Y %H:%M");
+ }
+ else
+ {
+ /* Translators: this is the day number followed
+ * by the abbreviated month name followed by the year followed
+ * by a time in 12h format i.e. "3 Feb 2015 9:04 PM" */
+ /* xgettext:no-c-format */
+ format = _("%-e %b %Y %l:%M %p");
+ }
+ }
+ }
+
+ g_date_time_unref (file_date);
+ g_date_time_unref (now);
+ g_date_time_unref (today_midnight);
+ }
+ else
+ {
+ /* xgettext:no-c-format */
+ format = _("%c");
+ }
+
+ result = g_date_time_format (file_date_time, format);
+ g_date_time_unref (file_date_time);
+
+ /* Replace ":" with ratio. Replacement is done afterward because g_date_time_format
+ * may fail with utf8 chars in some locales */
+ result_with_ratio = eel_str_replace_substring (result, ":", "∶");
+ g_free (result);
+
+ return result_with_ratio;
}
static void
show_directory_item_count_changed_callback (gpointer callback_data)
{
- show_directory_item_count = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS);
+ show_directory_item_count = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS);
}
static gboolean
-get_speed_tradeoff_preference_for_file (NautilusFile *file, NautilusSpeedTradeoffValue value)
-{
- GFilesystemPreviewType use_preview;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- use_preview = nautilus_file_get_filesystem_use_preview (file);
-
- if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS) {
- if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
- return FALSE;
- } else {
- return TRUE;
- }
- }
-
- if (value == NAUTILUS_SPEED_TRADEOFF_NEVER) {
- return FALSE;
- }
-
- g_assert (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
-
- if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER) {
- /* file system says to never preview anything */
- return FALSE;
- } else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL) {
- /* file system says we should treat file as if it's local */
- return TRUE;
- } else {
- /* only local files */
- return nautilus_file_is_local (file);
- }
+get_speed_tradeoff_preference_for_file (NautilusFile *file,
+ NautilusSpeedTradeoffValue value)
+{
+ GFilesystemPreviewType use_preview;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ use_preview = nautilus_file_get_filesystem_use_preview (file);
+
+ if (value == NAUTILUS_SPEED_TRADEOFF_ALWAYS)
+ {
+ if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
+ {
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+
+ if (value == NAUTILUS_SPEED_TRADEOFF_NEVER)
+ {
+ return FALSE;
+ }
+
+ g_assert (value == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
+
+ if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_NEVER)
+ {
+ /* file system says to never preview anything */
+ return FALSE;
+ }
+ else if (use_preview == G_FILESYSTEM_PREVIEW_TYPE_IF_LOCAL)
+ {
+ /* file system says we should treat file as if it's local */
+ return TRUE;
+ }
+ else
+ {
+ /* only local files */
+ return nautilus_file_is_local (file);
+ }
}
gboolean
nautilus_file_should_show_directory_item_count (NautilusFile *file)
{
- static gboolean show_directory_item_count_callback_added = FALSE;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- if (file->details->mime_type &&
- strcmp (eel_ref_str_peek (file->details->mime_type), "x-directory/smb-share") == 0) {
- return FALSE;
- }
-
- /* Add the callback once for the life of our process */
- if (!show_directory_item_count_callback_added) {
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
- G_CALLBACK(show_directory_item_count_changed_callback),
- NULL);
- show_directory_item_count_callback_added = TRUE;
-
- /* Peek for the first time */
- show_directory_item_count_changed_callback (NULL);
- }
-
- return get_speed_tradeoff_preference_for_file (file, show_directory_item_count);
+ static gboolean show_directory_item_count_callback_added = FALSE;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ if (file->details->mime_type &&
+ strcmp (eel_ref_str_peek (file->details->mime_type), "x-directory/smb-share") == 0)
+ {
+ return FALSE;
+ }
+
+ /* Add the callback once for the life of our process */
+ if (!show_directory_item_count_callback_added)
+ {
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
+ G_CALLBACK (show_directory_item_count_changed_callback),
+ NULL);
+ show_directory_item_count_callback_added = TRUE;
+
+ /* Peek for the first time */
+ show_directory_item_count_changed_callback (NULL);
+ }
+
+ return get_speed_tradeoff_preference_for_file (file, show_directory_item_count);
}
/**
* nautilus_file_get_directory_item_count
- *
+ *
* Get the number of items in a directory.
* @file: NautilusFile representing a directory.
* @count: Place to put count.
* @count_unreadable: Set to TRUE (if non-NULL) if permissions prevent
* the item count from being read on this directory. Otherwise set to FALSE.
- *
+ *
* Returns: TRUE if count is available.
- *
+ *
**/
gboolean
-nautilus_file_get_directory_item_count (NautilusFile *file,
- guint *count,
- gboolean *count_unreadable)
-{
- if (count != NULL) {
- *count = 0;
- }
- if (count_unreadable != NULL) {
- *count_unreadable = FALSE;
- }
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- if (!nautilus_file_is_directory (file)) {
- return FALSE;
- }
+nautilus_file_get_directory_item_count (NautilusFile *file,
+ guint *count,
+ gboolean *count_unreadable)
+{
+ if (count != NULL)
+ {
+ *count = 0;
+ }
+ if (count_unreadable != NULL)
+ {
+ *count_unreadable = FALSE;
+ }
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ if (!nautilus_file_is_directory (file))
+ {
+ return FALSE;
+ }
- if (!nautilus_file_should_show_directory_item_count (file)) {
- return FALSE;
- }
+ if (!nautilus_file_should_show_directory_item_count (file))
+ {
+ return FALSE;
+ }
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_item_count
- (file, count, count_unreadable);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_item_count
+ (file, count, count_unreadable);
}
/**
* nautilus_file_get_deep_counts
- *
+ *
* Get the statistics about items inside a directory.
* @file: NautilusFile representing a directory or file.
* @directory_count: Place to put count of directories inside.
@@ -5215,205 +5888,220 @@ nautilus_file_get_directory_item_count (NautilusFile *file,
* @force: Whether the deep counts should even be collected if
* nautilus_file_should_show_directory_item_count returns FALSE
* for this file.
- *
+ *
* Returns: Status to indicate whether sizes are available.
- *
+ *
**/
NautilusRequestStatus
nautilus_file_get_deep_counts (NautilusFile *file,
- guint *directory_count,
- guint *file_count,
- guint *unreadable_directory_count,
- goffset *total_size,
- gboolean force)
-{
- if (directory_count != NULL) {
- *directory_count = 0;
- }
- if (file_count != NULL) {
- *file_count = 0;
- }
- if (unreadable_directory_count != NULL) {
- *unreadable_directory_count = 0;
- }
- if (total_size != NULL) {
- *total_size = 0;
- }
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NAUTILUS_REQUEST_DONE);
-
- if (!force && !nautilus_file_should_show_directory_item_count (file)) {
- /* Set field so an existing value isn't treated as up-to-date
- * when preference changes later.
- */
- file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
- return file->details->deep_counts_status;
- }
-
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_deep_counts
- (file, directory_count, file_count,
- unreadable_directory_count, total_size);
+ guint *directory_count,
+ guint *file_count,
+ guint *unreadable_directory_count,
+ goffset *total_size,
+ gboolean force)
+{
+ if (directory_count != NULL)
+ {
+ *directory_count = 0;
+ }
+ if (file_count != NULL)
+ {
+ *file_count = 0;
+ }
+ if (unreadable_directory_count != NULL)
+ {
+ *unreadable_directory_count = 0;
+ }
+ if (total_size != NULL)
+ {
+ *total_size = 0;
+ }
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NAUTILUS_REQUEST_DONE);
+
+ if (!force && !nautilus_file_should_show_directory_item_count (file))
+ {
+ /* Set field so an existing value isn't treated as up-to-date
+ * when preference changes later.
+ */
+ file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
+ return file->details->deep_counts_status;
+ }
+
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->get_deep_counts
+ (file, directory_count, file_count,
+ unreadable_directory_count, total_size);
}
void
nautilus_file_recompute_deep_counts (NautilusFile *file)
{
- if (file->details->deep_counts_status != NAUTILUS_REQUEST_IN_PROGRESS) {
- file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
- if (file->details->directory != NULL) {
- nautilus_directory_add_file_to_work_queue (file->details->directory, file);
- nautilus_directory_async_state_changed (file->details->directory);
- }
- }
+ if (file->details->deep_counts_status != NAUTILUS_REQUEST_IN_PROGRESS)
+ {
+ file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
+ if (file->details->directory != NULL)
+ {
+ nautilus_directory_add_file_to_work_queue (file->details->directory, file);
+ nautilus_directory_async_state_changed (file->details->directory);
+ }
+ }
}
gboolean
nautilus_file_can_get_size (NautilusFile *file)
{
- return file->details->size == -1;
+ return file->details->size == -1;
}
-
+
/**
* nautilus_file_get_size
- *
+ *
* Get the file size.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Size in bytes.
- *
+ *
**/
goffset
nautilus_file_get_size (NautilusFile *file)
{
- /* Before we have info on the file, we don't know the size. */
- if (file->details->size == -1)
- return 0;
- return file->details->size;
+ /* Before we have info on the file, we don't know the size. */
+ if (file->details->size == -1)
+ {
+ return 0;
+ }
+ return file->details->size;
}
time_t
nautilus_file_get_mtime (NautilusFile *file)
{
- return file->details->mtime;
+ return file->details->mtime;
}
time_t
nautilus_file_get_atime (NautilusFile *file)
{
- return file->details->atime;
+ return file->details->atime;
}
static void
-set_attributes_get_info_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
-{
- NautilusFileOperation *op;
- GFileInfo *new_info;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
- if (new_info != NULL) {
- if (nautilus_file_update_info (op->file, new_info)) {
- nautilus_file_changed (op->file);
- }
- g_object_unref (new_info);
- }
- nautilus_file_operation_complete (op, NULL, error);
- if (error) {
- g_error_free (error);
- }
+set_attributes_get_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ GFileInfo *new_info;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
+ if (new_info != NULL)
+ {
+ if (nautilus_file_update_info (op->file, new_info))
+ {
+ nautilus_file_changed (op->file);
+ }
+ g_object_unref (new_info);
+ }
+ nautilus_file_operation_complete (op, NULL, error);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-set_attributes_callback (GObject *source_object,
- GAsyncResult *result,
- gpointer callback_data)
-{
- NautilusFileOperation *op;
- GError *error;
- gboolean res;
-
- op = callback_data;
-
- error = NULL;
- res = g_file_set_attributes_finish (G_FILE (source_object),
- result,
- NULL,
- &error);
-
- if (res) {
- g_file_query_info_async (G_FILE (source_object),
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0,
- G_PRIORITY_DEFAULT,
- op->cancellable,
- set_attributes_get_info_callback, op);
- } else {
- nautilus_file_operation_complete (op, NULL, error);
- g_error_free (error);
- }
+set_attributes_callback (GObject *source_object,
+ GAsyncResult *result,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ GError *error;
+ gboolean res;
+
+ op = callback_data;
+
+ error = NULL;
+ res = g_file_set_attributes_finish (G_FILE (source_object),
+ result,
+ NULL,
+ &error);
+
+ if (res)
+ {
+ g_file_query_info_async (G_FILE (source_object),
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0,
+ G_PRIORITY_DEFAULT,
+ op->cancellable,
+ set_attributes_get_info_callback, op);
+ }
+ else
+ {
+ nautilus_file_operation_complete (op, NULL, error);
+ g_error_free (error);
+ }
}
void
-nautilus_file_set_attributes (NautilusFile *file,
- GFileInfo *attributes,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- NautilusFileOperation *op;
- GFile *location;
-
- op = nautilus_file_operation_new (file, callback, callback_data);
-
- location = nautilus_file_get_location (file);
- g_file_set_attributes_async (location,
- attributes,
- 0,
- G_PRIORITY_DEFAULT,
- op->cancellable,
- set_attributes_callback,
- op);
- g_object_unref (location);
+nautilus_file_set_attributes (NautilusFile *file,
+ GFileInfo *attributes,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ NautilusFileOperation *op;
+ GFile *location;
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+
+ location = nautilus_file_get_location (file);
+ g_file_set_attributes_async (location,
+ attributes,
+ 0,
+ G_PRIORITY_DEFAULT,
+ op->cancellable,
+ set_attributes_callback,
+ op);
+ g_object_unref (location);
}
void
nautilus_file_set_search_relevance (NautilusFile *file,
- gdouble relevance)
+ gdouble relevance)
{
- file->details->search_relevance = relevance;
+ file->details->search_relevance = relevance;
}
/**
* nautilus_file_can_get_permissions:
- *
+ *
* Check whether the permissions for a file are determinable.
* This might not be the case for files on non-UNIX file systems.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the permissions are valid.
*/
gboolean
nautilus_file_can_get_permissions (NautilusFile *file)
{
- return file->details->has_permissions;
+ return file->details->has_permissions;
}
/**
* nautilus_file_can_set_permissions:
- *
+ *
* Check whether the current user is allowed to change
* the permissions of a file.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the current user can change the
* permissions of @file, FALSE otherwise. It's always possible
* that when you actually try to do it, you will fail.
@@ -5421,310 +6109,340 @@ nautilus_file_can_get_permissions (NautilusFile *file)
gboolean
nautilus_file_can_set_permissions (NautilusFile *file)
{
- uid_t user_id;
+ uid_t user_id;
- if (file->details->uid != -1 &&
- nautilus_file_is_local (file)) {
- /* Check the user. */
- user_id = geteuid();
+ if (file->details->uid != -1 &&
+ nautilus_file_is_local (file))
+ {
+ /* Check the user. */
+ user_id = geteuid ();
- /* Owner is allowed to set permissions. */
- if (user_id == (uid_t) file->details->uid) {
- return TRUE;
- }
+ /* Owner is allowed to set permissions. */
+ if (user_id == (uid_t) file->details->uid)
+ {
+ return TRUE;
+ }
- /* Root is also allowed to set permissions. */
- if (user_id == 0) {
- return TRUE;
- }
+ /* Root is also allowed to set permissions. */
+ if (user_id == 0)
+ {
+ return TRUE;
+ }
- /* Nobody else is allowed. */
- return FALSE;
- }
+ /* Nobody else is allowed. */
+ return FALSE;
+ }
- /* pretend to have full chmod rights when no info is available, relevant when
- * the FS can't provide ownership info, for instance for FTP */
- return TRUE;
+ /* pretend to have full chmod rights when no info is available, relevant when
+ * the FS can't provide ownership info, for instance for FTP */
+ return TRUE;
}
guint
nautilus_file_get_permissions (NautilusFile *file)
{
- g_return_val_if_fail (nautilus_file_can_get_permissions (file), 0);
+ g_return_val_if_fail (nautilus_file_can_get_permissions (file), 0);
- return file->details->permissions;
+ return file->details->permissions;
}
/**
* nautilus_file_set_permissions:
- *
+ *
* Change a file's permissions. This should only be called if
* nautilus_file_can_set_permissions returned TRUE.
- *
+ *
* @file: NautilusFile representing the file in question.
* @new_permissions: New permissions value. This is the whole
* set of permissions, not a delta.
**/
void
-nautilus_file_set_permissions (NautilusFile *file,
- guint32 new_permissions,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GFileInfo *info;
- GError *error;
-
- if (!nautilus_file_can_set_permissions (file)) {
- /* Claim that something changed even if the permission change failed.
- * This makes it easier for some clients who see the "reverting"
- * to the old permissions as "changing back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
- _("Not allowed to set permissions"));
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return;
- }
-
- /* Test the permissions-haven't-changed case explicitly
- * because we don't want to send the file-changed signal if
- * nothing changed.
- */
- if (new_permissions == file->details->permissions) {
- (* callback) (file, NULL, NULL, callback_data);
- return;
- }
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- NautilusFileUndoInfo *undo_info;
-
- undo_info = nautilus_file_undo_info_permissions_new (nautilus_file_get_location (file),
- file->details->permissions,
- new_permissions);
- nautilus_file_undo_manager_set_action (undo_info);
- }
-
- info = g_file_info_new ();
- g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE, new_permissions);
- nautilus_file_set_attributes (file, info, callback, callback_data);
-
- g_object_unref (info);
+nautilus_file_set_permissions (NautilusFile *file,
+ guint32 new_permissions,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GFileInfo *info;
+ GError *error;
+
+ if (!nautilus_file_can_set_permissions (file))
+ {
+ /* Claim that something changed even if the permission change failed.
+ * This makes it easier for some clients who see the "reverting"
+ * to the old permissions as "changing back".
+ */
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+ _("Not allowed to set permissions"));
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ return;
+ }
+
+ /* Test the permissions-haven't-changed case explicitly
+ * because we don't want to send the file-changed signal if
+ * nothing changed.
+ */
+ if (new_permissions == file->details->permissions)
+ {
+ (*callback)(file, NULL, NULL, callback_data);
+ return;
+ }
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ NautilusFileUndoInfo *undo_info;
+
+ undo_info = nautilus_file_undo_info_permissions_new (nautilus_file_get_location (file),
+ file->details->permissions,
+ new_permissions);
+ nautilus_file_undo_manager_set_action (undo_info);
+ }
+
+ info = g_file_info_new ();
+ g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE, new_permissions);
+ nautilus_file_set_attributes (file, info, callback, callback_data);
+
+ g_object_unref (info);
}
/**
* nautilus_file_can_get_selinux_context:
- *
+ *
* Check whether the selinux context for a file are determinable.
* This might not be the case for files on non-UNIX file systems,
* files without a context or systems that don't support selinux.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the permissions are valid.
*/
gboolean
nautilus_file_can_get_selinux_context (NautilusFile *file)
{
- return file->details->selinux_context != NULL;
+ return file->details->selinux_context != NULL;
}
/**
* nautilus_file_get_selinux_context:
- *
+ *
* Get a user-displayable string representing a file's selinux
* context
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
char *
nautilus_file_get_selinux_context (NautilusFile *file)
{
- char *translated;
- char *raw;
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ char *translated;
+ char *raw;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- if (!nautilus_file_can_get_selinux_context (file)) {
- return NULL;
- }
+ if (!nautilus_file_can_get_selinux_context (file))
+ {
+ return NULL;
+ }
- raw = file->details->selinux_context;
+ raw = file->details->selinux_context;
#ifdef HAVE_SELINUX
- if (selinux_raw_to_trans_context (raw, &translated) == 0) {
- char *tmp;
- tmp = g_strdup (translated);
- freecon (translated);
- translated = tmp;
- }
- else
+ if (selinux_raw_to_trans_context (raw, &translated) == 0)
+ {
+ char *tmp;
+ tmp = g_strdup (translated);
+ freecon (translated);
+ translated = tmp;
+ }
+ else
#endif
- {
- translated = g_strdup (raw);
- }
-
- return translated;
+ {
+ translated = g_strdup (raw);
+ }
+
+ return translated;
}
static char *
-get_real_name (const char *name, const char *gecos)
-{
- char *locale_string, *part_before_comma, *capitalized_login_name, *real_name;
-
- if (gecos == NULL) {
- return NULL;
- }
-
- locale_string = eel_str_strip_substring_and_after (gecos, ",");
- if (!g_utf8_validate (locale_string, -1, NULL)) {
- part_before_comma = g_locale_to_utf8 (locale_string, -1, NULL, NULL, NULL);
- g_free (locale_string);
- } else {
- part_before_comma = locale_string;
- }
-
- if (!g_utf8_validate (name, -1, NULL)) {
- locale_string = g_locale_to_utf8 (name, -1, NULL, NULL, NULL);
- } else {
- locale_string = g_strdup (name);
- }
-
- capitalized_login_name = eel_str_capitalize (locale_string);
- g_free (locale_string);
-
- if (capitalized_login_name == NULL) {
- real_name = part_before_comma;
- } else {
- real_name = eel_str_replace_substring
- (part_before_comma, "&", capitalized_login_name);
- g_free (part_before_comma);
- }
-
-
- if (g_strcmp0 (real_name, NULL) == 0
- || g_strcmp0 (name, real_name) == 0
- || g_strcmp0 (capitalized_login_name, real_name) == 0) {
- g_free (real_name);
- real_name = NULL;
- }
-
- g_free (capitalized_login_name);
-
- return real_name;
+get_real_name (const char *name,
+ const char *gecos)
+{
+ char *locale_string, *part_before_comma, *capitalized_login_name, *real_name;
+
+ if (gecos == NULL)
+ {
+ return NULL;
+ }
+
+ locale_string = eel_str_strip_substring_and_after (gecos, ",");
+ if (!g_utf8_validate (locale_string, -1, NULL))
+ {
+ part_before_comma = g_locale_to_utf8 (locale_string, -1, NULL, NULL, NULL);
+ g_free (locale_string);
+ }
+ else
+ {
+ part_before_comma = locale_string;
+ }
+
+ if (!g_utf8_validate (name, -1, NULL))
+ {
+ locale_string = g_locale_to_utf8 (name, -1, NULL, NULL, NULL);
+ }
+ else
+ {
+ locale_string = g_strdup (name);
+ }
+
+ capitalized_login_name = eel_str_capitalize (locale_string);
+ g_free (locale_string);
+
+ if (capitalized_login_name == NULL)
+ {
+ real_name = part_before_comma;
+ }
+ else
+ {
+ real_name = eel_str_replace_substring
+ (part_before_comma, "&", capitalized_login_name);
+ g_free (part_before_comma);
+ }
+
+
+ if (g_strcmp0 (real_name, NULL) == 0
+ || g_strcmp0 (name, real_name) == 0
+ || g_strcmp0 (capitalized_login_name, real_name) == 0)
+ {
+ g_free (real_name);
+ real_name = NULL;
+ }
+
+ g_free (capitalized_login_name);
+
+ return real_name;
}
static gboolean
-get_group_id_from_group_name (const char *group_name, uid_t *gid)
+get_group_id_from_group_name (const char *group_name,
+ uid_t *gid)
{
- struct group *group;
+ struct group *group;
- g_assert (gid != NULL);
+ g_assert (gid != NULL);
- group = getgrnam (group_name);
+ group = getgrnam (group_name);
- if (group == NULL) {
- return FALSE;
- }
+ if (group == NULL)
+ {
+ return FALSE;
+ }
- *gid = group->gr_gid;
+ *gid = group->gr_gid;
- return TRUE;
+ return TRUE;
}
static gboolean
-get_ids_from_user_name (const char *user_name, uid_t *uid, uid_t *gid)
+get_ids_from_user_name (const char *user_name,
+ uid_t *uid,
+ uid_t *gid)
{
- struct passwd *password_info;
+ struct passwd *password_info;
- g_assert (uid != NULL || gid != NULL);
+ g_assert (uid != NULL || gid != NULL);
- password_info = getpwnam (user_name);
+ password_info = getpwnam (user_name);
- if (password_info == NULL) {
- return FALSE;
- }
+ if (password_info == NULL)
+ {
+ return FALSE;
+ }
- if (uid != NULL) {
- *uid = password_info->pw_uid;
- }
+ if (uid != NULL)
+ {
+ *uid = password_info->pw_uid;
+ }
- if (gid != NULL) {
- *gid = password_info->pw_gid;
- }
+ if (gid != NULL)
+ {
+ *gid = password_info->pw_gid;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
-get_user_id_from_user_name (const char *user_name, uid_t *id)
+get_user_id_from_user_name (const char *user_name,
+ uid_t *id)
{
- return get_ids_from_user_name (user_name, id, NULL);
+ return get_ids_from_user_name (user_name, id, NULL);
}
static gboolean
-get_id_from_digit_string (const char *digit_string, uid_t *id)
+get_id_from_digit_string (const char *digit_string,
+ uid_t *id)
{
- long scanned_id;
- char c;
+ long scanned_id;
+ char c;
- g_assert (id != NULL);
+ g_assert (id != NULL);
- /* Only accept string if it has one integer with nothing
- * afterwards.
- */
- if (sscanf (digit_string, "%ld%c", &scanned_id, &c) != 1) {
- return FALSE;
- }
- *id = scanned_id;
- return TRUE;
+ /* Only accept string if it has one integer with nothing
+ * afterwards.
+ */
+ if (sscanf (digit_string, "%ld%c", &scanned_id, &c) != 1)
+ {
+ return FALSE;
+ }
+ *id = scanned_id;
+ return TRUE;
}
/**
* nautilus_file_can_get_owner:
- *
+ *
* Check whether the owner a file is determinable.
* This might not be the case for files on non-UNIX file systems.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the owner is valid.
*/
gboolean
nautilus_file_can_get_owner (NautilusFile *file)
{
- /* Before we have info on a file, the owner is unknown. */
- return file->details->uid != -1;
+ /* Before we have info on a file, the owner is unknown. */
+ return file->details->uid != -1;
}
/**
* nautilus_file_get_owner_name:
- *
+ *
* Get the user name of the file's owner. If the owner has no
* name, returns the userid as a string. The caller is responsible
* for g_free-ing this string.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: A newly-allocated string.
*/
char *
nautilus_file_get_owner_name (NautilusFile *file)
{
- return nautilus_file_get_owner_as_string (file, FALSE);
+ return nautilus_file_get_owner_as_string (file, FALSE);
}
/**
* nautilus_file_can_set_owner:
- *
+ *
* Check whether the current user is allowed to change
* the owner of a file.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the current user can change the
* owner of @file, FALSE otherwise. It's always possible
* that when you actually try to do it, you will fail.
@@ -5732,24 +6450,25 @@ nautilus_file_get_owner_name (NautilusFile *file)
gboolean
nautilus_file_can_set_owner (NautilusFile *file)
{
- /* Not allowed to set the owner if we can't
- * even read it. This can happen on non-UNIX file
- * systems.
- */
- if (!nautilus_file_can_get_owner (file)) {
- return FALSE;
- }
+ /* Not allowed to set the owner if we can't
+ * even read it. This can happen on non-UNIX file
+ * systems.
+ */
+ if (!nautilus_file_can_get_owner (file))
+ {
+ return FALSE;
+ }
- /* Only root is also allowed to set the owner. */
- return geteuid() == 0;
+ /* Only root is also allowed to set the owner. */
+ return geteuid () == 0;
}
/**
* nautilus_file_set_owner:
- *
+ *
* Set the owner of a file. This will only have any effect if
* nautilus_file_can_set_owner returns TRUE.
- *
+ *
* @file: The file in question.
* @user_name_or_id: The user name to set the owner to.
* If the string does not match any user name, and the
@@ -5759,154 +6478,162 @@ nautilus_file_can_set_owner (NautilusFile *file)
* @callback_data: Parameter passed back with callback function.
*/
void
-nautilus_file_set_owner (NautilusFile *file,
- const char *user_name_or_id,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
- GFileInfo *info;
- uid_t new_id;
-
- if (!nautilus_file_can_set_owner (file)) {
- /* Claim that something changed even if the permission
- * change failed. This makes it easier for some
- * clients who see the "reverting" to the old owner as
- * "changing back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
- _("Not allowed to set owner"));
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return;
- }
-
- /* If no match treating user_name_or_id as name, try treating
- * it as id.
- */
- if (!get_user_id_from_user_name (user_name_or_id, &new_id)
- && !get_id_from_digit_string (user_name_or_id, &new_id)) {
- /* Claim that something changed even if the permission
- * change failed. This makes it easier for some
- * clients who see the "reverting" to the old owner as
- * "changing back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
- _("Specified owner '%s' doesn't exist"), user_name_or_id);
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return;
- }
-
- /* Test the owner-hasn't-changed case explicitly because we
- * don't want to send the file-changed signal if nothing
- * changed.
- */
- if (new_id == (uid_t) file->details->uid) {
- (* callback) (file, NULL, NULL, callback_data);
- return;
- }
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- NautilusFileUndoInfo *undo_info;
- char* current_owner;
-
- current_owner = nautilus_file_get_owner_as_string (file, FALSE);
-
- undo_info = nautilus_file_undo_info_ownership_new (NAUTILUS_FILE_UNDO_OP_CHANGE_OWNER,
- nautilus_file_get_location (file),
- current_owner,
- user_name_or_id);
- nautilus_file_undo_manager_set_action (undo_info);
-
- g_free (current_owner);
- }
-
- info = g_file_info_new ();
- g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID, new_id);
- nautilus_file_set_attributes (file, info, callback, callback_data);
- g_object_unref (info);
+nautilus_file_set_owner (NautilusFile *file,
+ const char *user_name_or_id,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+ GFileInfo *info;
+ uid_t new_id;
+
+ if (!nautilus_file_can_set_owner (file))
+ {
+ /* Claim that something changed even if the permission
+ * change failed. This makes it easier for some
+ * clients who see the "reverting" to the old owner as
+ * "changing back".
+ */
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+ _("Not allowed to set owner"));
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ return;
+ }
+
+ /* If no match treating user_name_or_id as name, try treating
+ * it as id.
+ */
+ if (!get_user_id_from_user_name (user_name_or_id, &new_id)
+ && !get_id_from_digit_string (user_name_or_id, &new_id))
+ {
+ /* Claim that something changed even if the permission
+ * change failed. This makes it easier for some
+ * clients who see the "reverting" to the old owner as
+ * "changing back".
+ */
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ _("Specified owner '%s' doesn't exist"), user_name_or_id);
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ return;
+ }
+
+ /* Test the owner-hasn't-changed case explicitly because we
+ * don't want to send the file-changed signal if nothing
+ * changed.
+ */
+ if (new_id == (uid_t) file->details->uid)
+ {
+ (*callback)(file, NULL, NULL, callback_data);
+ return;
+ }
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ NautilusFileUndoInfo *undo_info;
+ char *current_owner;
+
+ current_owner = nautilus_file_get_owner_as_string (file, FALSE);
+
+ undo_info = nautilus_file_undo_info_ownership_new (NAUTILUS_FILE_UNDO_OP_CHANGE_OWNER,
+ nautilus_file_get_location (file),
+ current_owner,
+ user_name_or_id);
+ nautilus_file_undo_manager_set_action (undo_info);
+
+ g_free (current_owner);
+ }
+
+ info = g_file_info_new ();
+ g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_UID, new_id);
+ nautilus_file_set_attributes (file, info, callback, callback_data);
+ g_object_unref (info);
}
/**
* nautilus_get_user_names:
- *
- * Get a list of user names. For users with a different associated
- * "real name", the real name follows the standard user name, separated
- * by a carriage return. The caller is responsible for freeing this list
+ *
+ * Get a list of user names. For users with a different associated
+ * "real name", the real name follows the standard user name, separated
+ * by a carriage return. The caller is responsible for freeing this list
* and its contents.
*/
GList *
nautilus_get_user_names (void)
{
- GList *list;
- char *real_name, *name;
- struct passwd *user;
+ GList *list;
+ char *real_name, *name;
+ struct passwd *user;
+
+ list = NULL;
- list = NULL;
-
- setpwent ();
+ setpwent ();
- while ((user = getpwent ()) != NULL) {
- real_name = get_real_name (user->pw_name, user->pw_gecos);
- if (real_name != NULL) {
- name = g_strconcat (user->pw_name, "\n", real_name, NULL);
- } else {
- name = g_strdup (user->pw_name);
- }
- g_free (real_name);
- list = g_list_prepend (list, name);
- }
+ while ((user = getpwent ()) != NULL)
+ {
+ real_name = get_real_name (user->pw_name, user->pw_gecos);
+ if (real_name != NULL)
+ {
+ name = g_strconcat (user->pw_name, "\n", real_name, NULL);
+ }
+ else
+ {
+ name = g_strdup (user->pw_name);
+ }
+ g_free (real_name);
+ list = g_list_prepend (list, name);
+ }
- endpwent ();
+ endpwent ();
- return g_list_sort (list, (GCompareFunc) g_utf8_collate);
+ return g_list_sort (list, (GCompareFunc) g_utf8_collate);
}
/**
* nautilus_file_can_get_group:
- *
+ *
* Check whether the group a file is determinable.
* This might not be the case for files on non-UNIX file systems.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the group is valid.
*/
gboolean
nautilus_file_can_get_group (NautilusFile *file)
{
- /* Before we have info on a file, the group is unknown. */
- return file->details->gid != -1;
+ /* Before we have info on a file, the group is unknown. */
+ return file->details->gid != -1;
}
/**
* nautilus_file_get_group_name:
- *
+ *
* Get the name of the file's group. If the group has no
* name, returns the groupid as a string. The caller is responsible
* for g_free-ing this string.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: A newly-allocated string.
**/
char *
nautilus_file_get_group_name (NautilusFile *file)
{
- return g_strdup (eel_ref_str_peek (file->details->group));
+ return g_strdup (eel_ref_str_peek (file->details->group));
}
/**
* nautilus_file_can_set_group:
- *
+ *
* Check whether the current user is allowed to change
* the group of a file.
- *
+ *
* @file: The file in question.
- *
+ *
* Return value: TRUE if the current user can change the
* group of @file, FALSE otherwise. It's always possible
* that when you actually try to do it, you will fail.
@@ -5914,31 +6641,34 @@ nautilus_file_get_group_name (NautilusFile *file)
gboolean
nautilus_file_can_set_group (NautilusFile *file)
{
- uid_t user_id;
+ uid_t user_id;
- /* Not allowed to set the permissions if we can't
- * even read them. This can happen on non-UNIX file
- * systems.
- */
- if (!nautilus_file_can_get_group (file)) {
- return FALSE;
- }
+ /* Not allowed to set the permissions if we can't
+ * even read them. This can happen on non-UNIX file
+ * systems.
+ */
+ if (!nautilus_file_can_get_group (file))
+ {
+ return FALSE;
+ }
- /* Check the user. */
- user_id = geteuid();
+ /* Check the user. */
+ user_id = geteuid ();
- /* Owner is allowed to set group (with restrictions). */
- if (user_id == (uid_t) file->details->uid) {
- return TRUE;
- }
+ /* Owner is allowed to set group (with restrictions). */
+ if (user_id == (uid_t) file->details->uid)
+ {
+ return TRUE;
+ }
- /* Root is also allowed to set group. */
- if (user_id == 0) {
- return TRUE;
- }
+ /* Root is also allowed to set group. */
+ if (user_id == 0)
+ {
+ return TRUE;
+ }
- /* Nobody else is allowed. */
- return FALSE;
+ /* Nobody else is allowed. */
+ return FALSE;
}
/* Get a list of group names, filtered to only the ones
@@ -5948,90 +6678,101 @@ nautilus_file_can_set_group (NautilusFile *file)
static GList *
nautilus_get_group_names_for_user (void)
{
- GList *list;
- struct group *group;
- int count, i;
- gid_t gid_list[NGROUPS_MAX + 1];
-
+ GList *list;
+ struct group *group;
+ int count, i;
+ gid_t gid_list[NGROUPS_MAX + 1];
+
+
+ list = NULL;
- list = NULL;
+ count = getgroups (NGROUPS_MAX + 1, gid_list);
+ for (i = 0; i < count; i++)
+ {
+ group = getgrgid (gid_list[i]);
+ if (group == NULL)
+ {
+ break;
+ }
- count = getgroups (NGROUPS_MAX + 1, gid_list);
- for (i = 0; i < count; i++) {
- group = getgrgid (gid_list[i]);
- if (group == NULL)
- break;
-
- list = g_list_prepend (list, g_strdup (group->gr_name));
- }
+ list = g_list_prepend (list, g_strdup (group->gr_name));
+ }
- return g_list_sort (list, (GCompareFunc) g_utf8_collate);
+ return g_list_sort (list, (GCompareFunc) g_utf8_collate);
}
/**
* nautilus_get_group_names:
- *
+ *
* Get a list of all group names.
*/
GList *
nautilus_get_all_group_names (void)
{
- GList *list;
- struct group *group;
-
- list = NULL;
+ GList *list;
+ struct group *group;
+
+ list = NULL;
+
+ setgrent ();
+
+ while ((group = getgrent ()) != NULL)
+ {
+ list = g_list_prepend (list, g_strdup (group->gr_name));
+ }
+
+ endgrent ();
- setgrent ();
-
- while ((group = getgrent ()) != NULL)
- list = g_list_prepend (list, g_strdup (group->gr_name));
-
- endgrent ();
-
- return g_list_sort (list, (GCompareFunc) g_utf8_collate);
+ return g_list_sort (list, (GCompareFunc) g_utf8_collate);
}
/**
* nautilus_file_get_settable_group_names:
- *
+ *
* Get a list of all group names that the current user
* can set the group of a specific file to.
- *
+ *
* @file: The NautilusFile in question.
*/
GList *
nautilus_file_get_settable_group_names (NautilusFile *file)
{
- uid_t user_id;
- GList *result;
+ uid_t user_id;
+ GList *result;
- if (!nautilus_file_can_set_group (file)) {
- return NULL;
- }
+ if (!nautilus_file_can_set_group (file))
+ {
+ return NULL;
+ }
- /* Check the user. */
- user_id = geteuid();
+ /* Check the user. */
+ user_id = geteuid ();
- if (user_id == 0) {
- /* Root is allowed to set group to anything. */
- result = nautilus_get_all_group_names ();
- } else if (user_id == (uid_t) file->details->uid) {
- /* Owner is allowed to set group to any that owner is member of. */
- result = nautilus_get_group_names_for_user ();
- } else {
- g_warning ("unhandled case in nautilus_get_settable_group_names");
- result = NULL;
- }
+ if (user_id == 0)
+ {
+ /* Root is allowed to set group to anything. */
+ result = nautilus_get_all_group_names ();
+ }
+ else if (user_id == (uid_t) file->details->uid)
+ {
+ /* Owner is allowed to set group to any that owner is member of. */
+ result = nautilus_get_group_names_for_user ();
+ }
+ else
+ {
+ g_warning ("unhandled case in nautilus_get_settable_group_names");
+ result = NULL;
+ }
- return result;
+ return result;
}
/**
* nautilus_file_set_group:
- *
+ *
* Set the group of a file. This will only have any effect if
* nautilus_file_can_set_group returns TRUE.
- *
+ *
* @file: The file in question.
* @group_name_or_id: The group name to set the owner to.
* If the string does not match any group name, and the
@@ -6041,423 +6782,462 @@ nautilus_file_get_settable_group_names (NautilusFile *file)
* @callback_data: Parameter passed back with callback function.
*/
void
-nautilus_file_set_group (NautilusFile *file,
- const char *group_name_or_id,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
-{
- GError *error;
- GFileInfo *info;
- uid_t new_id;
-
- if (!nautilus_file_can_set_group (file)) {
- /* Claim that something changed even if the group
- * change failed. This makes it easier for some
- * clients who see the "reverting" to the old group as
- * "changing back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
- _("Not allowed to set group"));
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return;
- }
-
- /* If no match treating group_name_or_id as name, try treating
- * it as id.
- */
- if (!get_group_id_from_group_name (group_name_or_id, &new_id)
- && !get_id_from_digit_string (group_name_or_id, &new_id)) {
- /* Claim that something changed even if the group
- * change failed. This makes it easier for some
- * clients who see the "reverting" to the old group as
- * "changing back".
- */
- nautilus_file_changed (file);
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
- _("Specified group '%s' doesn't exist"), group_name_or_id);
- (* callback) (file, NULL, error, callback_data);
- g_error_free (error);
- return;
- }
-
- if (new_id == (gid_t) file->details->gid) {
- (* callback) (file, NULL, NULL, callback_data);
- return;
- }
-
- if (!nautilus_file_undo_manager_is_operating ()) {
- NautilusFileUndoInfo *undo_info;
- char *current_group;
-
- current_group = nautilus_file_get_group_name (file);
- undo_info = nautilus_file_undo_info_ownership_new (NAUTILUS_FILE_UNDO_OP_CHANGE_GROUP,
- nautilus_file_get_location (file),
- current_group,
- group_name_or_id);
- nautilus_file_undo_manager_set_action (undo_info);
-
- g_free (current_group);
- }
-
- info = g_file_info_new ();
- g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID, new_id);
- nautilus_file_set_attributes (file, info, callback, callback_data);
- g_object_unref (info);
+nautilus_file_set_group (NautilusFile *file,
+ const char *group_name_or_id,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
+{
+ GError *error;
+ GFileInfo *info;
+ uid_t new_id;
+
+ if (!nautilus_file_can_set_group (file))
+ {
+ /* Claim that something changed even if the group
+ * change failed. This makes it easier for some
+ * clients who see the "reverting" to the old group as
+ * "changing back".
+ */
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
+ _("Not allowed to set group"));
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ return;
+ }
+
+ /* If no match treating group_name_or_id as name, try treating
+ * it as id.
+ */
+ if (!get_group_id_from_group_name (group_name_or_id, &new_id)
+ && !get_id_from_digit_string (group_name_or_id, &new_id))
+ {
+ /* Claim that something changed even if the group
+ * change failed. This makes it easier for some
+ * clients who see the "reverting" to the old group as
+ * "changing back".
+ */
+ nautilus_file_changed (file);
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ _("Specified group '%s' doesn't exist"), group_name_or_id);
+ (*callback)(file, NULL, error, callback_data);
+ g_error_free (error);
+ return;
+ }
+
+ if (new_id == (gid_t) file->details->gid)
+ {
+ (*callback)(file, NULL, NULL, callback_data);
+ return;
+ }
+
+ if (!nautilus_file_undo_manager_is_operating ())
+ {
+ NautilusFileUndoInfo *undo_info;
+ char *current_group;
+
+ current_group = nautilus_file_get_group_name (file);
+ undo_info = nautilus_file_undo_info_ownership_new (NAUTILUS_FILE_UNDO_OP_CHANGE_GROUP,
+ nautilus_file_get_location (file),
+ current_group,
+ group_name_or_id);
+ nautilus_file_undo_manager_set_action (undo_info);
+
+ g_free (current_group);
+ }
+
+ info = g_file_info_new ();
+ g_file_info_set_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_GID, new_id);
+ nautilus_file_set_attributes (file, info, callback, callback_data);
+ g_object_unref (info);
}
/**
* nautilus_file_get_octal_permissions_as_string:
- *
+ *
* Get a user-displayable string representing a file's permissions
* as an octal number. The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_octal_permissions_as_string (NautilusFile *file)
{
- guint32 permissions;
+ guint32 permissions;
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- if (!nautilus_file_can_get_permissions (file)) {
- return NULL;
- }
+ if (!nautilus_file_can_get_permissions (file))
+ {
+ return NULL;
+ }
- permissions = file->details->permissions;
- return g_strdup_printf ("%03o", permissions);
+ permissions = file->details->permissions;
+ return g_strdup_printf ("%03o", permissions);
}
/**
* nautilus_file_get_permissions_as_string:
- *
+ *
* Get a user-displayable string representing a file's permissions. The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_permissions_as_string (NautilusFile *file)
{
- guint32 permissions;
- gboolean is_directory;
- gboolean is_link;
- gboolean suid, sgid, sticky;
-
- if (!nautilus_file_can_get_permissions (file)) {
- return NULL;
- }
-
- g_assert (NAUTILUS_IS_FILE (file));
-
- permissions = file->details->permissions;
- is_directory = nautilus_file_is_directory (file);
- is_link = nautilus_file_is_symbolic_link (file);
-
- /* We use ls conventions for displaying these three obscure flags */
- suid = permissions & S_ISUID;
- sgid = permissions & S_ISGID;
- sticky = permissions & S_ISVTX;
-
- return g_strdup_printf ("%c%c%c%c%c%c%c%c%c%c",
- is_link ? 'l' : is_directory ? 'd' : '-',
- permissions & S_IRUSR ? 'r' : '-',
- permissions & S_IWUSR ? 'w' : '-',
- permissions & S_IXUSR
- ? (suid ? 's' : 'x')
- : (suid ? 'S' : '-'),
- permissions & S_IRGRP ? 'r' : '-',
- permissions & S_IWGRP ? 'w' : '-',
- permissions & S_IXGRP
- ? (sgid ? 's' : 'x')
- : (sgid ? 'S' : '-'),
- permissions & S_IROTH ? 'r' : '-',
- permissions & S_IWOTH ? 'w' : '-',
- permissions & S_IXOTH
- ? (sticky ? 't' : 'x')
- : (sticky ? 'T' : '-'));
+ guint32 permissions;
+ gboolean is_directory;
+ gboolean is_link;
+ gboolean suid, sgid, sticky;
+
+ if (!nautilus_file_can_get_permissions (file))
+ {
+ return NULL;
+ }
+
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ permissions = file->details->permissions;
+ is_directory = nautilus_file_is_directory (file);
+ is_link = nautilus_file_is_symbolic_link (file);
+
+ /* We use ls conventions for displaying these three obscure flags */
+ suid = permissions & S_ISUID;
+ sgid = permissions & S_ISGID;
+ sticky = permissions & S_ISVTX;
+
+ return g_strdup_printf ("%c%c%c%c%c%c%c%c%c%c",
+ is_link ? 'l' : is_directory ? 'd' : '-',
+ permissions & S_IRUSR ? 'r' : '-',
+ permissions & S_IWUSR ? 'w' : '-',
+ permissions & S_IXUSR
+ ? (suid ? 's' : 'x')
+ : (suid ? 'S' : '-'),
+ permissions & S_IRGRP ? 'r' : '-',
+ permissions & S_IWGRP ? 'w' : '-',
+ permissions & S_IXGRP
+ ? (sgid ? 's' : 'x')
+ : (sgid ? 'S' : '-'),
+ permissions & S_IROTH ? 'r' : '-',
+ permissions & S_IWOTH ? 'w' : '-',
+ permissions & S_IXOTH
+ ? (sticky ? 't' : 'x')
+ : (sticky ? 'T' : '-'));
}
/**
* nautilus_file_get_owner_as_string:
- *
+ *
* Get a user-displayable string representing a file's owner. The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
* @include_real_name: Whether or not to append the real name (if any)
* for this user after the user name.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
-nautilus_file_get_owner_as_string (NautilusFile *file, gboolean include_real_name)
-{
- char *user_name;
-
- /* Before we have info on a file, the owner is unknown. */
- if (file->details->owner == NULL &&
- file->details->owner_real == NULL) {
- return NULL;
- }
-
- if (include_real_name &&
- file->details->uid == getuid ()) {
- /* Translators: "Me" is used to indicate the file is owned by me (the current user) */
- user_name = g_strdup (_("Me"));
- } else if (file->details->owner_real == NULL) {
- user_name = g_strdup (eel_ref_str_peek (file->details->owner));
- } else if (file->details->owner == NULL) {
- user_name = g_strdup (eel_ref_str_peek (file->details->owner_real));
- } else if (include_real_name &&
- strcmp (eel_ref_str_peek (file->details->owner), eel_ref_str_peek (file->details->owner_real)) != 0) {
- user_name = g_strdup (eel_ref_str_peek (file->details->owner_real));
- } else {
- user_name = g_strdup (eel_ref_str_peek (file->details->owner));
- }
-
- return user_name;
+nautilus_file_get_owner_as_string (NautilusFile *file,
+ gboolean include_real_name)
+{
+ char *user_name;
+
+ /* Before we have info on a file, the owner is unknown. */
+ if (file->details->owner == NULL &&
+ file->details->owner_real == NULL)
+ {
+ return NULL;
+ }
+
+ if (include_real_name &&
+ file->details->uid == getuid ())
+ {
+ /* Translators: "Me" is used to indicate the file is owned by me (the current user) */
+ user_name = g_strdup (_("Me"));
+ }
+ else if (file->details->owner_real == NULL)
+ {
+ user_name = g_strdup (eel_ref_str_peek (file->details->owner));
+ }
+ else if (file->details->owner == NULL)
+ {
+ user_name = g_strdup (eel_ref_str_peek (file->details->owner_real));
+ }
+ else if (include_real_name &&
+ strcmp (eel_ref_str_peek (file->details->owner), eel_ref_str_peek (file->details->owner_real)) != 0)
+ {
+ user_name = g_strdup (eel_ref_str_peek (file->details->owner_real));
+ }
+ else
+ {
+ user_name = g_strdup (eel_ref_str_peek (file->details->owner));
+ }
+
+ return user_name;
}
static char *
-format_item_count_for_display (guint item_count,
- gboolean includes_directories,
- gboolean includes_files)
+format_item_count_for_display (guint item_count,
+ gboolean includes_directories,
+ gboolean includes_files)
{
- g_assert (includes_directories || includes_files);
+ g_assert (includes_directories || includes_files);
- return g_strdup_printf (includes_directories
- ? (includes_files
- ? ngettext ("%'u item", "%'u items", item_count)
- : ngettext ("%'u folder", "%'u folders", item_count))
- : ngettext ("%'u file", "%'u files", item_count), item_count);
+ return g_strdup_printf (includes_directories
+ ? (includes_files
+ ? ngettext ("%'u item", "%'u items", item_count)
+ : ngettext ("%'u folder", "%'u folders", item_count))
+ : ngettext ("%'u file", "%'u files", item_count), item_count);
}
/**
* nautilus_file_get_size_as_string:
- *
+ *
* Get a user-displayable string representing a file size. The caller
* is responsible for g_free-ing this string. The string is an item
* count for directories.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_size_as_string (NautilusFile *file)
{
- guint item_count;
- gboolean count_unreadable;
-
- if (file == NULL) {
- return NULL;
- }
-
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_directory (file)) {
- if (!nautilus_file_get_directory_item_count (file, &item_count, &count_unreadable)) {
- return NULL;
- }
- return format_item_count_for_display (item_count, TRUE, TRUE);
- }
-
- if (file->details->size == -1) {
- return NULL;
- }
- return g_format_size (file->details->size);
+ guint item_count;
+ gboolean count_unreadable;
+
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ if (nautilus_file_is_directory (file))
+ {
+ if (!nautilus_file_get_directory_item_count (file, &item_count, &count_unreadable))
+ {
+ return NULL;
+ }
+ return format_item_count_for_display (item_count, TRUE, TRUE);
+ }
+
+ if (file->details->size == -1)
+ {
+ return NULL;
+ }
+ return g_format_size (file->details->size);
}
/**
* nautilus_file_get_size_as_string_with_real_size:
- *
+ *
* Get a user-displayable string representing a file size. The caller
* is responsible for g_free-ing this string. The string is an item
* count for directories.
* This function adds the real size in the string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_size_as_string_with_real_size (NautilusFile *file)
{
- guint item_count;
- gboolean count_unreadable;
+ guint item_count;
+ gboolean count_unreadable;
+
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
+ g_assert (NAUTILUS_IS_FILE (file));
- if (file == NULL) {
- return NULL;
- }
-
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_directory (file)) {
- if (!nautilus_file_get_directory_item_count (file, &item_count, &count_unreadable)) {
- return NULL;
- }
- return format_item_count_for_display (item_count, TRUE, TRUE);
- }
-
- if (file->details->size == -1) {
- return NULL;
- }
+ if (nautilus_file_is_directory (file))
+ {
+ if (!nautilus_file_get_directory_item_count (file, &item_count, &count_unreadable))
+ {
+ return NULL;
+ }
+ return format_item_count_for_display (item_count, TRUE, TRUE);
+ }
+
+ if (file->details->size == -1)
+ {
+ return NULL;
+ }
- return g_format_size_full (file->details->size, G_FORMAT_SIZE_LONG_FORMAT);
+ return g_format_size_full (file->details->size, G_FORMAT_SIZE_LONG_FORMAT);
}
static char *
nautilus_file_get_deep_count_as_string_internal (NautilusFile *file,
- gboolean report_size,
- gboolean report_directory_count,
- gboolean report_file_count)
-{
- NautilusRequestStatus status;
- guint directory_count;
- guint file_count;
- guint unreadable_count;
- guint total_count;
- goffset total_size;
-
- /* Must ask for size or some kind of count, but not both. */
- g_assert (!report_size || (!report_directory_count && !report_file_count));
- g_assert (report_size || report_directory_count || report_file_count);
-
- if (file == NULL) {
- return NULL;
- }
-
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (nautilus_file_is_directory (file));
-
- status = nautilus_file_get_deep_counts
- (file, &directory_count, &file_count, &unreadable_count, &total_size, FALSE);
-
- /* Check whether any info is available. */
- if (status == NAUTILUS_REQUEST_NOT_STARTED) {
- return NULL;
- }
-
- total_count = file_count + directory_count;
-
- if (total_count == 0) {
- switch (status) {
- case NAUTILUS_REQUEST_IN_PROGRESS:
- /* Don't return confident "zero" until we're finished looking,
- * because of next case.
- */
- return NULL;
- case NAUTILUS_REQUEST_DONE:
- /* Don't return "zero" if we there were contents but we couldn't read them. */
- if (unreadable_count != 0) {
- return NULL;
- }
- default: break;
- }
- }
-
- /* Note that we don't distinguish the "everything was readable" case
- * from the "some things but not everything was readable" case here.
- * Callers can distinguish them using nautilus_file_get_deep_counts
- * directly if desired.
- */
- if (report_size) {
- return g_format_size (total_size);
- }
-
- return format_item_count_for_display (report_directory_count
- ? (report_file_count ? total_count : directory_count)
- : file_count,
- report_directory_count, report_file_count);
+ gboolean report_size,
+ gboolean report_directory_count,
+ gboolean report_file_count)
+{
+ NautilusRequestStatus status;
+ guint directory_count;
+ guint file_count;
+ guint unreadable_count;
+ guint total_count;
+ goffset total_size;
+
+ /* Must ask for size or some kind of count, but not both. */
+ g_assert (!report_size || (!report_directory_count && !report_file_count));
+ g_assert (report_size || report_directory_count || report_file_count);
+
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (nautilus_file_is_directory (file));
+
+ status = nautilus_file_get_deep_counts
+ (file, &directory_count, &file_count, &unreadable_count, &total_size, FALSE);
+
+ /* Check whether any info is available. */
+ if (status == NAUTILUS_REQUEST_NOT_STARTED)
+ {
+ return NULL;
+ }
+
+ total_count = file_count + directory_count;
+
+ if (total_count == 0)
+ {
+ switch (status)
+ {
+ case NAUTILUS_REQUEST_IN_PROGRESS:
+ {
+ /* Don't return confident "zero" until we're finished looking,
+ * because of next case.
+ */
+ return NULL;
+ }
+
+ case NAUTILUS_REQUEST_DONE:
+ {
+ /* Don't return "zero" if we there were contents but we couldn't read them. */
+ if (unreadable_count != 0)
+ {
+ return NULL;
+ }
+ }
+
+ default:
+ {}
+ break;
+ }
+ }
+
+ /* Note that we don't distinguish the "everything was readable" case
+ * from the "some things but not everything was readable" case here.
+ * Callers can distinguish them using nautilus_file_get_deep_counts
+ * directly if desired.
+ */
+ if (report_size)
+ {
+ return g_format_size (total_size);
+ }
+
+ return format_item_count_for_display (report_directory_count
+ ? (report_file_count ? total_count : directory_count)
+ : file_count,
+ report_directory_count, report_file_count);
}
/**
* nautilus_file_get_deep_size_as_string:
- *
+ *
* Get a user-displayable string representing the size of all contained
* items (only makes sense for directories). The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_deep_size_as_string (NautilusFile *file)
{
- return nautilus_file_get_deep_count_as_string_internal (file, TRUE, FALSE, FALSE);
+ return nautilus_file_get_deep_count_as_string_internal (file, TRUE, FALSE, FALSE);
}
/**
* nautilus_file_get_deep_total_count_as_string:
- *
+ *
* Get a user-displayable string representing the count of all contained
* items (only makes sense for directories). The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_deep_total_count_as_string (NautilusFile *file)
{
- return nautilus_file_get_deep_count_as_string_internal (file, FALSE, TRUE, TRUE);
+ return nautilus_file_get_deep_count_as_string_internal (file, FALSE, TRUE, TRUE);
}
/**
* nautilus_file_get_deep_file_count_as_string:
- *
+ *
* Get a user-displayable string representing the count of all contained
* items, not including directories. It only makes sense to call this
* function on a directory. The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_deep_file_count_as_string (NautilusFile *file)
{
- return nautilus_file_get_deep_count_as_string_internal (file, FALSE, FALSE, TRUE);
+ return nautilus_file_get_deep_count_as_string_internal (file, FALSE, FALSE, TRUE);
}
/**
* nautilus_file_get_deep_directory_count_as_string:
- *
+ *
* Get a user-displayable string representing the count of all contained
* directories. It only makes sense to call this
* function on a directory. The caller
* is responsible for g_free-ing this string.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: Newly allocated string ready to display to the user.
- *
+ *
**/
static char *
nautilus_file_get_deep_directory_count_as_string (NautilusFile *file)
{
- return nautilus_file_get_deep_count_as_string_internal (file, FALSE, TRUE, FALSE);
+ return nautilus_file_get_deep_count_as_string_internal (file, FALSE, TRUE, FALSE);
}
/**
* nautilus_file_get_string_attribute:
- *
+ *
* Get a user-displayable string from a named attribute. Use g_free to
* free this string. If the value is unknown, returns NULL. You can call
* nautilus_file_get_string_attribute_with_default if you want a non-NULL
* default.
- *
+ *
* @file: NautilusFile representing the file in question.
* @attribute_name: The name of the desired attribute. The currently supported
* set includes "name", "type", "detailed_type", "mime_type", "size", "deep_size", "deep_directory_count",
@@ -6465,584 +7245,666 @@ nautilus_file_get_deep_directory_count_as_string (NautilusFile *file)
* "date_modified_full", "date_accessed_full",
* "owner", "group", "permissions", "octal_permissions", "uri", "where",
* "link_target", "volume", "free_space", "selinux_context", "trashed_on", "trashed_on_full", "trashed_orig_path"
- *
+ *
* Returns: Newly allocated string ready to display to the user, or NULL
* if the value is unknown or @attribute_name is not supported.
- *
+ *
**/
char *
-nautilus_file_get_string_attribute_q (NautilusFile *file, GQuark attribute_q)
-{
- char *extension_attribute;
-
- if (attribute_q == attribute_name_q) {
- return nautilus_file_get_display_name (file);
- }
- if (attribute_q == attribute_type_q) {
- return nautilus_file_get_type_as_string (file);
- }
- if (attribute_q == attribute_detailed_type_q) {
- return nautilus_file_get_detailed_type_as_string (file);
- }
- if (attribute_q == attribute_mime_type_q) {
- return nautilus_file_get_mime_type (file);
- }
- if (attribute_q == attribute_size_q) {
- return nautilus_file_get_size_as_string (file);
- }
- if (attribute_q == attribute_size_detail_q) {
- return nautilus_file_get_size_as_string_with_real_size (file);
- }
- if (attribute_q == attribute_deep_size_q) {
- return nautilus_file_get_deep_size_as_string (file);
- }
- if (attribute_q == attribute_deep_file_count_q) {
- return nautilus_file_get_deep_file_count_as_string (file);
- }
- if (attribute_q == attribute_deep_directory_count_q) {
- return nautilus_file_get_deep_directory_count_as_string (file);
- }
- if (attribute_q == attribute_deep_total_count_q) {
- return nautilus_file_get_deep_total_count_as_string (file);
- }
- if (attribute_q == attribute_trash_orig_path_q) {
- return nautilus_file_get_trash_original_file_parent_as_string (file);
- }
- if (attribute_q == attribute_date_modified_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_MODIFIED,
- NAUTILUS_DATE_FORMAT_REGULAR);
- }
- if (attribute_q == attribute_date_modified_full_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_MODIFIED,
- NAUTILUS_DATE_FORMAT_FULL);
- }
- if (attribute_q == attribute_date_modified_with_time_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_MODIFIED,
- NAUTILUS_DATE_FORMAT_REGULAR_WITH_TIME);
- }
- if (attribute_q == attribute_date_accessed_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_ACCESSED,
- NAUTILUS_DATE_FORMAT_REGULAR);
- }
- if (attribute_q == attribute_date_accessed_full_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_ACCESSED,
- NAUTILUS_DATE_FORMAT_FULL);
- }
- if (attribute_q == attribute_trashed_on_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_TRASHED,
- NAUTILUS_DATE_FORMAT_REGULAR);
- }
- if (attribute_q == attribute_trashed_on_full_q) {
- return nautilus_file_get_date_as_string (file,
- NAUTILUS_DATE_TYPE_TRASHED,
- NAUTILUS_DATE_FORMAT_FULL);
- }
- if (attribute_q == attribute_permissions_q) {
- return nautilus_file_get_permissions_as_string (file);
- }
- if (attribute_q == attribute_selinux_context_q) {
- return nautilus_file_get_selinux_context (file);
- }
- if (attribute_q == attribute_octal_permissions_q) {
- return nautilus_file_get_octal_permissions_as_string (file);
- }
- if (attribute_q == attribute_owner_q) {
- return nautilus_file_get_owner_as_string (file, TRUE);
- }
- if (attribute_q == attribute_group_q) {
- return nautilus_file_get_group_name (file);
- }
- if (attribute_q == attribute_uri_q) {
- return nautilus_file_get_uri (file);
- }
- if (attribute_q == attribute_where_q) {
- return nautilus_file_get_where_string (file);
- }
- if (attribute_q == attribute_link_target_q) {
- return nautilus_file_get_symbolic_link_target_path (file);
- }
- if (attribute_q == attribute_volume_q) {
- return nautilus_file_get_volume_name (file);
- }
- if (attribute_q == attribute_free_space_q) {
- return nautilus_file_get_volume_free_space (file);
- }
-
- extension_attribute = NULL;
-
- if (file->details->pending_extension_attributes) {
- extension_attribute = g_hash_table_lookup (file->details->pending_extension_attributes,
- GINT_TO_POINTER (attribute_q));
- }
-
- if (extension_attribute == NULL && file->details->extension_attributes) {
- extension_attribute = g_hash_table_lookup (file->details->extension_attributes,
- GINT_TO_POINTER (attribute_q));
- }
-
- return g_strdup (extension_attribute);
+nautilus_file_get_string_attribute_q (NautilusFile *file,
+ GQuark attribute_q)
+{
+ char *extension_attribute;
+
+ if (attribute_q == attribute_name_q)
+ {
+ return nautilus_file_get_display_name (file);
+ }
+ if (attribute_q == attribute_type_q)
+ {
+ return nautilus_file_get_type_as_string (file);
+ }
+ if (attribute_q == attribute_detailed_type_q)
+ {
+ return nautilus_file_get_detailed_type_as_string (file);
+ }
+ if (attribute_q == attribute_mime_type_q)
+ {
+ return nautilus_file_get_mime_type (file);
+ }
+ if (attribute_q == attribute_size_q)
+ {
+ return nautilus_file_get_size_as_string (file);
+ }
+ if (attribute_q == attribute_size_detail_q)
+ {
+ return nautilus_file_get_size_as_string_with_real_size (file);
+ }
+ if (attribute_q == attribute_deep_size_q)
+ {
+ return nautilus_file_get_deep_size_as_string (file);
+ }
+ if (attribute_q == attribute_deep_file_count_q)
+ {
+ return nautilus_file_get_deep_file_count_as_string (file);
+ }
+ if (attribute_q == attribute_deep_directory_count_q)
+ {
+ return nautilus_file_get_deep_directory_count_as_string (file);
+ }
+ if (attribute_q == attribute_deep_total_count_q)
+ {
+ return nautilus_file_get_deep_total_count_as_string (file);
+ }
+ if (attribute_q == attribute_trash_orig_path_q)
+ {
+ return nautilus_file_get_trash_original_file_parent_as_string (file);
+ }
+ if (attribute_q == attribute_date_modified_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_MODIFIED,
+ NAUTILUS_DATE_FORMAT_REGULAR);
+ }
+ if (attribute_q == attribute_date_modified_full_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_MODIFIED,
+ NAUTILUS_DATE_FORMAT_FULL);
+ }
+ if (attribute_q == attribute_date_modified_with_time_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_MODIFIED,
+ NAUTILUS_DATE_FORMAT_REGULAR_WITH_TIME);
+ }
+ if (attribute_q == attribute_date_accessed_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_ACCESSED,
+ NAUTILUS_DATE_FORMAT_REGULAR);
+ }
+ if (attribute_q == attribute_date_accessed_full_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_ACCESSED,
+ NAUTILUS_DATE_FORMAT_FULL);
+ }
+ if (attribute_q == attribute_trashed_on_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_TRASHED,
+ NAUTILUS_DATE_FORMAT_REGULAR);
+ }
+ if (attribute_q == attribute_trashed_on_full_q)
+ {
+ return nautilus_file_get_date_as_string (file,
+ NAUTILUS_DATE_TYPE_TRASHED,
+ NAUTILUS_DATE_FORMAT_FULL);
+ }
+ if (attribute_q == attribute_permissions_q)
+ {
+ return nautilus_file_get_permissions_as_string (file);
+ }
+ if (attribute_q == attribute_selinux_context_q)
+ {
+ return nautilus_file_get_selinux_context (file);
+ }
+ if (attribute_q == attribute_octal_permissions_q)
+ {
+ return nautilus_file_get_octal_permissions_as_string (file);
+ }
+ if (attribute_q == attribute_owner_q)
+ {
+ return nautilus_file_get_owner_as_string (file, TRUE);
+ }
+ if (attribute_q == attribute_group_q)
+ {
+ return nautilus_file_get_group_name (file);
+ }
+ if (attribute_q == attribute_uri_q)
+ {
+ return nautilus_file_get_uri (file);
+ }
+ if (attribute_q == attribute_where_q)
+ {
+ return nautilus_file_get_where_string (file);
+ }
+ if (attribute_q == attribute_link_target_q)
+ {
+ return nautilus_file_get_symbolic_link_target_path (file);
+ }
+ if (attribute_q == attribute_volume_q)
+ {
+ return nautilus_file_get_volume_name (file);
+ }
+ if (attribute_q == attribute_free_space_q)
+ {
+ return nautilus_file_get_volume_free_space (file);
+ }
+
+ extension_attribute = NULL;
+
+ if (file->details->pending_extension_attributes)
+ {
+ extension_attribute = g_hash_table_lookup (file->details->pending_extension_attributes,
+ GINT_TO_POINTER (attribute_q));
+ }
+
+ if (extension_attribute == NULL && file->details->extension_attributes)
+ {
+ extension_attribute = g_hash_table_lookup (file->details->extension_attributes,
+ GINT_TO_POINTER (attribute_q));
+ }
+
+ return g_strdup (extension_attribute);
}
char *
-nautilus_file_get_string_attribute (NautilusFile *file, const char *attribute_name)
+nautilus_file_get_string_attribute (NautilusFile *file,
+ const char *attribute_name)
{
- return nautilus_file_get_string_attribute_q (file, g_quark_from_string (attribute_name));
+ return nautilus_file_get_string_attribute_q (file, g_quark_from_string (attribute_name));
}
/**
* nautilus_file_get_string_attribute_with_default:
- *
+ *
* Get a user-displayable string from a named attribute. Use g_free to
* free this string. If the value is unknown, returns a string representing
* the unknown value, which varies with attribute. You can call
* nautilus_file_get_string_attribute if you want NULL instead of a default
* result.
- *
+ *
* @file: NautilusFile representing the file in question.
* @attribute_name: The name of the desired attribute. See the description of
* nautilus_file_get_string for the set of available attributes.
- *
+ *
* Returns: Newly allocated string ready to display to the user, or a string
* such as "unknown" if the value is unknown or @attribute_name is not supported.
- *
+ *
**/
char *
-nautilus_file_get_string_attribute_with_default_q (NautilusFile *file, GQuark attribute_q)
-{
- char *result;
- guint item_count;
- gboolean count_unreadable;
- NautilusRequestStatus status;
-
- result = nautilus_file_get_string_attribute_q (file, attribute_q);
- if (result != NULL) {
- return result;
- }
-
- /* Supply default values for the ones we know about. */
- /* FIXME bugzilla.gnome.org 40646:
- * Use hash table and switch statement or function pointers for speed?
- */
- if (attribute_q == attribute_size_q) {
- if (!nautilus_file_should_show_directory_item_count (file)) {
- return g_strdup ("--");
- }
- count_unreadable = FALSE;
- if (nautilus_file_is_directory (file)) {
- nautilus_file_get_directory_item_count (file, &item_count, &count_unreadable);
- }
- return g_strdup (count_unreadable ? _("? items") : "...");
- }
- if (attribute_q == attribute_deep_size_q) {
- status = nautilus_file_get_deep_counts (file, NULL, NULL, NULL, NULL, FALSE);
- if (status == NAUTILUS_REQUEST_DONE) {
- /* This means no contents at all were readable */
- return g_strdup (_("? bytes"));
- }
- return g_strdup ("...");
- }
- if (attribute_q == attribute_deep_file_count_q
- || attribute_q == attribute_deep_directory_count_q
- || attribute_q == attribute_deep_total_count_q) {
- status = nautilus_file_get_deep_counts (file, NULL, NULL, NULL, NULL, FALSE);
- if (status == NAUTILUS_REQUEST_DONE) {
- /* This means no contents at all were readable */
- return g_strdup (_("? items"));
- }
- return g_strdup ("...");
- }
- if (attribute_q == attribute_type_q
- || attribute_q == attribute_detailed_type_q
- || attribute_q == attribute_mime_type_q) {
- return g_strdup (_("Unknown"));
- }
- if (attribute_q == attribute_trashed_on_q) {
- /* If n/a */
- return g_strdup ("");
- }
- if (attribute_q == attribute_trash_orig_path_q) {
- /* If n/a */
- return g_strdup ("");
- }
-
- /* Fallback, use for both unknown attributes and attributes
- * for which we have no more appropriate default.
- */
- return g_strdup (_("unknown"));
+nautilus_file_get_string_attribute_with_default_q (NautilusFile *file,
+ GQuark attribute_q)
+{
+ char *result;
+ guint item_count;
+ gboolean count_unreadable;
+ NautilusRequestStatus status;
+
+ result = nautilus_file_get_string_attribute_q (file, attribute_q);
+ if (result != NULL)
+ {
+ return result;
+ }
+
+ /* Supply default values for the ones we know about. */
+ /* FIXME bugzilla.gnome.org 40646:
+ * Use hash table and switch statement or function pointers for speed?
+ */
+ if (attribute_q == attribute_size_q)
+ {
+ if (!nautilus_file_should_show_directory_item_count (file))
+ {
+ return g_strdup ("--");
+ }
+ count_unreadable = FALSE;
+ if (nautilus_file_is_directory (file))
+ {
+ nautilus_file_get_directory_item_count (file, &item_count, &count_unreadable);
+ }
+ return g_strdup (count_unreadable ? _("? items") : "...");
+ }
+ if (attribute_q == attribute_deep_size_q)
+ {
+ status = nautilus_file_get_deep_counts (file, NULL, NULL, NULL, NULL, FALSE);
+ if (status == NAUTILUS_REQUEST_DONE)
+ {
+ /* This means no contents at all were readable */
+ return g_strdup (_("? bytes"));
+ }
+ return g_strdup ("...");
+ }
+ if (attribute_q == attribute_deep_file_count_q
+ || attribute_q == attribute_deep_directory_count_q
+ || attribute_q == attribute_deep_total_count_q)
+ {
+ status = nautilus_file_get_deep_counts (file, NULL, NULL, NULL, NULL, FALSE);
+ if (status == NAUTILUS_REQUEST_DONE)
+ {
+ /* This means no contents at all were readable */
+ return g_strdup (_("? items"));
+ }
+ return g_strdup ("...");
+ }
+ if (attribute_q == attribute_type_q
+ || attribute_q == attribute_detailed_type_q
+ || attribute_q == attribute_mime_type_q)
+ {
+ return g_strdup (_("Unknown"));
+ }
+ if (attribute_q == attribute_trashed_on_q)
+ {
+ /* If n/a */
+ return g_strdup ("");
+ }
+ if (attribute_q == attribute_trash_orig_path_q)
+ {
+ /* If n/a */
+ return g_strdup ("");
+ }
+
+ /* Fallback, use for both unknown attributes and attributes
+ * for which we have no more appropriate default.
+ */
+ return g_strdup (_("unknown"));
}
char *
-nautilus_file_get_string_attribute_with_default (NautilusFile *file, const char *attribute_name)
+nautilus_file_get_string_attribute_with_default (NautilusFile *file,
+ const char *attribute_name)
{
- return nautilus_file_get_string_attribute_with_default_q (file, g_quark_from_string (attribute_name));
+ return nautilus_file_get_string_attribute_with_default_q (file, g_quark_from_string (attribute_name));
}
gboolean
nautilus_file_is_date_sort_attribute_q (GQuark attribute_q)
{
- if (attribute_q == attribute_modification_date_q ||
- attribute_q == attribute_date_modified_q ||
- attribute_q == attribute_date_modified_full_q ||
- attribute_q == attribute_date_modified_with_time_q ||
- attribute_q == attribute_accessed_date_q ||
- attribute_q == attribute_date_accessed_q ||
- attribute_q == attribute_date_accessed_full_q ||
- attribute_q == attribute_trashed_on_q ||
- attribute_q == attribute_trashed_on_full_q) {
- return TRUE;
- }
-
- return FALSE;
-}
-
-struct {
- const char *icon_name;
- const char *display_name;
-} mime_type_map[] = {
- { "application-x-executable", N_("Program") },
- { "audio-x-generic", N_("Audio") },
- { "font-x-generic", N_("Font") },
- { "image-x-generic", N_("Image") },
- { "package-x-generic", N_("Archive") },
- { "text-html", N_("Markup") },
- { "text-x-generic", N_("Text") },
- { "text-x-generic-template", N_("Text") },
- { "text-x-script", N_("Program") },
- { "video-x-generic", N_("Video") },
- { "x-office-address-book", N_("Contacts") },
- { "x-office-calendar", N_("Calendar") },
- { "x-office-document", N_("Document") },
- { "x-office-presentation", N_("Presentation") },
- { "x-office-spreadsheet", N_("Spreadsheet") },
+ if (attribute_q == attribute_modification_date_q ||
+ attribute_q == attribute_date_modified_q ||
+ attribute_q == attribute_date_modified_full_q ||
+ attribute_q == attribute_date_modified_with_time_q ||
+ attribute_q == attribute_accessed_date_q ||
+ attribute_q == attribute_date_accessed_q ||
+ attribute_q == attribute_date_accessed_full_q ||
+ attribute_q == attribute_trashed_on_q ||
+ attribute_q == attribute_trashed_on_full_q)
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+struct
+{
+ const char *icon_name;
+ const char *display_name;
+} mime_type_map[] =
+{
+ { "application-x-executable", N_("Program") },
+ { "audio-x-generic", N_("Audio") },
+ { "font-x-generic", N_("Font") },
+ { "image-x-generic", N_("Image") },
+ { "package-x-generic", N_("Archive") },
+ { "text-html", N_("Markup") },
+ { "text-x-generic", N_("Text") },
+ { "text-x-generic-template", N_("Text") },
+ { "text-x-script", N_("Program") },
+ { "video-x-generic", N_("Video") },
+ { "x-office-address-book", N_("Contacts") },
+ { "x-office-calendar", N_("Calendar") },
+ { "x-office-document", N_("Document") },
+ { "x-office-presentation", N_("Presentation") },
+ { "x-office-spreadsheet", N_("Spreadsheet") },
};
static char *
get_basic_type_for_mime_type (const char *mime_type)
{
- char *icon_name;
- char *basic_type = NULL;
-
- icon_name = g_content_type_get_generic_icon_name (mime_type);
- if (icon_name != NULL) {
- int i;
-
- for (i = 0; i < G_N_ELEMENTS (mime_type_map); i++) {
- if (strcmp (mime_type_map[i].icon_name, icon_name) == 0) {
- basic_type = g_strdup (gettext (mime_type_map[i].display_name));
- break;
- }
- }
+ char *icon_name;
+ char *basic_type = NULL;
+
+ icon_name = g_content_type_get_generic_icon_name (mime_type);
+ if (icon_name != NULL)
+ {
+ int i;
+
+ for (i = 0; i < G_N_ELEMENTS (mime_type_map); i++)
+ {
+ if (strcmp (mime_type_map[i].icon_name, icon_name) == 0)
+ {
+ basic_type = g_strdup (gettext (mime_type_map[i].display_name));
+ break;
+ }
}
+ }
- if (basic_type == NULL) {
- basic_type = g_strdup (_("Unknown"));
- }
+ if (basic_type == NULL)
+ {
+ basic_type = g_strdup (_("Unknown"));
+ }
- g_free (icon_name);
+ g_free (icon_name);
- return basic_type;
+ return basic_type;
}
static char *
get_description (NautilusFile *file,
- gboolean detailed)
+ gboolean detailed)
{
- const char *mime_type;
-
- g_assert (NAUTILUS_IS_FILE (file));
-
- mime_type = eel_ref_str_peek (file->details->mime_type);
- if (mime_type == NULL) {
- return NULL;
- }
-
- if (g_content_type_is_unknown (mime_type)) {
- if (nautilus_file_is_executable (file)) {
- return g_strdup (_("Program"));
- }
- return g_strdup (_("Binary"));
- }
+ const char *mime_type;
- if (strcmp (mime_type, "inode/directory") == 0) {
- return g_strdup (_("Folder"));
- }
+ g_assert (NAUTILUS_IS_FILE (file));
- if (detailed) {
- char *description;
+ mime_type = eel_ref_str_peek (file->details->mime_type);
+ if (mime_type == NULL)
+ {
+ return NULL;
+ }
- description = g_content_type_get_description (mime_type);
- if (description != NULL) {
- return description;
- }
- } else {
- char *category;
-
- category = get_basic_type_for_mime_type (mime_type);
- if (category != NULL) {
- return category;
- }
- }
+ if (g_content_type_is_unknown (mime_type))
+ {
+ if (nautilus_file_is_executable (file))
+ {
+ return g_strdup (_("Program"));
+ }
+ return g_strdup (_("Binary"));
+ }
+
+ if (strcmp (mime_type, "inode/directory") == 0)
+ {
+ return g_strdup (_("Folder"));
+ }
+
+ if (detailed)
+ {
+ char *description;
+
+ description = g_content_type_get_description (mime_type);
+ if (description != NULL)
+ {
+ return description;
+ }
+ }
+ else
+ {
+ char *category;
+
+ category = get_basic_type_for_mime_type (mime_type);
+ if (category != NULL)
+ {
+ return category;
+ }
+ }
- return g_strdup (mime_type);
+ return g_strdup (mime_type);
}
/* Takes ownership of string */
static char *
-update_description_for_link (NautilusFile *file, char *string)
-{
- char *res;
-
- if (nautilus_file_is_symbolic_link (file)) {
- g_assert (!nautilus_file_is_broken_symbolic_link (file));
- if (string == NULL) {
- return g_strdup (_("Link"));
- }
- /* Note to localizers: convert file type string for file
- * (e.g. "folder", "plain text") to file type for symbolic link
- * to that kind of file (e.g. "link to folder").
- */
- res = g_strdup_printf (_("Link to %s"), string);
- g_free (string);
- return res;
- }
-
- return string;
+update_description_for_link (NautilusFile *file,
+ char *string)
+{
+ char *res;
+
+ if (nautilus_file_is_symbolic_link (file))
+ {
+ g_assert (!nautilus_file_is_broken_symbolic_link (file));
+ if (string == NULL)
+ {
+ return g_strdup (_("Link"));
+ }
+ /* Note to localizers: convert file type string for file
+ * (e.g. "folder", "plain text") to file type for symbolic link
+ * to that kind of file (e.g. "link to folder").
+ */
+ res = g_strdup_printf (_("Link to %s"), string);
+ g_free (string);
+ return res;
+ }
+
+ return string;
}
static char *
nautilus_file_get_type_as_string (NautilusFile *file)
{
- if (file == NULL) {
- return NULL;
- }
+ if (file == NULL)
+ {
+ return NULL;
+ }
- if (nautilus_file_is_broken_symbolic_link (file)) {
- return g_strdup (_("Link (broken)"));
- }
-
- return update_description_for_link (file, get_description (file, FALSE));
+ if (nautilus_file_is_broken_symbolic_link (file))
+ {
+ return g_strdup (_("Link (broken)"));
+ }
+
+ return update_description_for_link (file, get_description (file, FALSE));
}
static char *
nautilus_file_get_detailed_type_as_string (NautilusFile *file)
{
- if (file == NULL) {
- return NULL;
- }
+ if (file == NULL)
+ {
+ return NULL;
+ }
+
+ if (nautilus_file_is_broken_symbolic_link (file))
+ {
+ return g_strdup (_("Link (broken)"));
+ }
- if (nautilus_file_is_broken_symbolic_link (file)) {
- return g_strdup (_("Link (broken)"));
- }
-
- return update_description_for_link (file, get_description (file, TRUE));
+ return update_description_for_link (file, get_description (file, TRUE));
}
/**
* nautilus_file_get_file_type
- *
+ *
* Return this file's type.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: The type.
- *
+ *
**/
GFileType
nautilus_file_get_file_type (NautilusFile *file)
{
- if (file == NULL) {
- return G_FILE_TYPE_UNKNOWN;
- }
-
- return file->details->type;
+ if (file == NULL)
+ {
+ return G_FILE_TYPE_UNKNOWN;
+ }
+
+ return file->details->type;
}
/**
* nautilus_file_get_mime_type
- *
+ *
* Return this file's default mime type.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: The mime type.
- *
+ *
**/
char *
nautilus_file_get_mime_type (NautilusFile *file)
{
- if (file != NULL) {
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
- if (file->details->mime_type != NULL) {
- return g_strdup (eel_ref_str_peek (file->details->mime_type));
- }
- }
- return g_strdup ("application/octet-stream");
+ if (file != NULL)
+ {
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), NULL);
+ if (file->details->mime_type != NULL)
+ {
+ return g_strdup (eel_ref_str_peek (file->details->mime_type));
+ }
+ }
+ return g_strdup ("application/octet-stream");
}
/**
* nautilus_file_is_mime_type
- *
+ *
* Check whether a file is of a particular MIME type, or inherited
* from it.
* @file: NautilusFile representing the file in question.
* @mime_type: The MIME-type string to test (e.g. "text/plain")
- *
+ *
* Return value: TRUE if @mime_type exactly matches the
* file's MIME type.
- *
+ *
**/
gboolean
-nautilus_file_is_mime_type (NautilusFile *file, const char *mime_type)
+nautilus_file_is_mime_type (NautilusFile *file,
+ const char *mime_type)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- g_return_val_if_fail (mime_type != NULL, FALSE);
-
- if (file->details->mime_type == NULL) {
- return FALSE;
- }
- return g_content_type_is_a (eel_ref_str_peek (file->details->mime_type),
- mime_type);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (mime_type != NULL, FALSE);
+
+ if (file->details->mime_type == NULL)
+ {
+ return FALSE;
+ }
+ return g_content_type_is_a (eel_ref_str_peek (file->details->mime_type),
+ mime_type);
}
char *
nautilus_file_get_extension (NautilusFile *file)
{
- char *name;
- char *extension = NULL;
+ char *name;
+ char *extension = NULL;
- name = nautilus_file_get_name (file);
- if (name != NULL) {
- extension = g_strdup (eel_filename_get_extension_offset (name));
- g_free (name);
- }
+ name = nautilus_file_get_name (file);
+ if (name != NULL)
+ {
+ extension = g_strdup (eel_filename_get_extension_offset (name));
+ g_free (name);
+ }
- return extension;
+ return extension;
}
gboolean
nautilus_file_is_launchable (NautilusFile *file)
{
- gboolean type_can_be_executable;
+ gboolean type_can_be_executable;
- type_can_be_executable = FALSE;
- if (file->details->mime_type != NULL) {
- type_can_be_executable =
- g_content_type_can_be_executable (eel_ref_str_peek (file->details->mime_type));
- }
-
- return type_can_be_executable &&
- nautilus_file_can_get_permissions (file) &&
- nautilus_file_can_execute (file) &&
- nautilus_file_is_executable (file) &&
- !nautilus_file_is_directory (file);
+ type_can_be_executable = FALSE;
+ if (file->details->mime_type != NULL)
+ {
+ type_can_be_executable =
+ g_content_type_can_be_executable (eel_ref_str_peek (file->details->mime_type));
+ }
+
+ return type_can_be_executable &&
+ nautilus_file_can_get_permissions (file) &&
+ nautilus_file_can_execute (file) &&
+ nautilus_file_is_executable (file) &&
+ !nautilus_file_is_directory (file);
}
/**
* nautilus_file_is_symbolic_link
- *
+ *
* Check if this file is a symbolic link.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: True if the file is a symbolic link.
- *
+ *
**/
gboolean
nautilus_file_is_symbolic_link (NautilusFile *file)
{
- return file->details->is_symlink;
+ return file->details->is_symlink;
}
GMount *
nautilus_file_get_mount (NautilusFile *file)
{
- if (file->details->mount) {
- return g_object_ref (file->details->mount);
- }
- return NULL;
+ if (file->details->mount)
+ {
+ return g_object_ref (file->details->mount);
+ }
+ return NULL;
}
static void
-file_mount_unmounted (GMount *mount,
- gpointer data)
+file_mount_unmounted (GMount *mount,
+ gpointer data)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = NAUTILUS_FILE (data);
+ file = NAUTILUS_FILE (data);
- nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_MOUNT);
+ nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_MOUNT);
}
void
nautilus_file_set_mount (NautilusFile *file,
- GMount *mount)
+ GMount *mount)
{
- if (file->details->mount) {
- g_signal_handlers_disconnect_by_func (file->details->mount, file_mount_unmounted, file);
- g_object_unref (file->details->mount);
- file->details->mount = NULL;
- }
+ if (file->details->mount)
+ {
+ g_signal_handlers_disconnect_by_func (file->details->mount, file_mount_unmounted, file);
+ g_object_unref (file->details->mount);
+ file->details->mount = NULL;
+ }
- if (mount) {
- file->details->mount = g_object_ref (mount);
- g_signal_connect (mount, "unmounted",
- G_CALLBACK (file_mount_unmounted), file);
- }
+ if (mount)
+ {
+ file->details->mount = g_object_ref (mount);
+ g_signal_connect (mount, "unmounted",
+ G_CALLBACK (file_mount_unmounted), file);
+ }
}
/**
* nautilus_file_is_broken_symbolic_link
- *
+ *
* Check if this file is a symbolic link with a missing target.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: True if the file is a symbolic link with a missing target.
- *
+ *
**/
gboolean
nautilus_file_is_broken_symbolic_link (NautilusFile *file)
{
- if (file == NULL) {
- return FALSE;
- }
-
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ if (file == NULL)
+ {
+ return FALSE;
+ }
+
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- /* Non-broken symbolic links return the target's type for get_file_type. */
- return nautilus_file_get_file_type (file) == G_FILE_TYPE_SYMBOLIC_LINK;
+ /* Non-broken symbolic links return the target's type for get_file_type. */
+ return nautilus_file_get_file_type (file) == G_FILE_TYPE_SYMBOLIC_LINK;
}
static void
-get_fs_free_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- NautilusFile *file;
- guint64 free_space;
- GFileInfo *info;
-
- file = NAUTILUS_FILE (user_data);
-
- free_space = (guint64)-1;
- info = g_file_query_filesystem_info_finish (G_FILE (source_object),
- res, NULL);
- if (info) {
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE)) {
- free_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
- }
- g_object_unref (info);
- }
-
- if (file->details->free_space != free_space) {
- file->details->free_space = free_space;
- nautilus_file_emit_changed (file);
- }
-
- nautilus_file_unref (file);
+get_fs_free_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NautilusFile *file;
+ guint64 free_space;
+ GFileInfo *info;
+
+ file = NAUTILUS_FILE (user_data);
+
+ free_space = (guint64) - 1;
+ info = g_file_query_filesystem_info_finish (G_FILE (source_object),
+ res, NULL);
+ if (info)
+ {
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE))
+ {
+ free_space = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+ }
+ g_object_unref (info);
+ }
+
+ if (file->details->free_space != free_space)
+ {
+ file->details->free_space = free_space;
+ nautilus_file_emit_changed (file);
+ }
+
+ nautilus_file_unref (file);
}
/**
@@ -7055,153 +7917,164 @@ get_fs_free_cb (GObject *source_object,
char *
nautilus_file_get_volume_free_space (NautilusFile *file)
{
- GFile *location;
- char *res;
- time_t now;
-
- now = time (NULL);
- /* Update first time and then every 2 seconds */
- if (file->details->free_space_read == 0 ||
- (now - file->details->free_space_read) > 2) {
- file->details->free_space_read = now;
- location = nautilus_file_get_location (file);
- g_file_query_filesystem_info_async (location,
- G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
- 0, NULL,
- get_fs_free_cb,
- nautilus_file_ref (file));
- g_object_unref (location);
- }
-
- res = NULL;
- if (file->details->free_space != (guint64)-1) {
- res = g_format_size (file->details->free_space);
- }
-
- return res;
+ GFile *location;
+ char *res;
+ time_t now;
+
+ now = time (NULL);
+ /* Update first time and then every 2 seconds */
+ if (file->details->free_space_read == 0 ||
+ (now - file->details->free_space_read) > 2)
+ {
+ file->details->free_space_read = now;
+ location = nautilus_file_get_location (file);
+ g_file_query_filesystem_info_async (location,
+ G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
+ 0, NULL,
+ get_fs_free_cb,
+ nautilus_file_ref (file));
+ g_object_unref (location);
+ }
+
+ res = NULL;
+ if (file->details->free_space != (guint64) - 1)
+ {
+ res = g_format_size (file->details->free_space);
+ }
+
+ return res;
}
/**
* nautilus_file_get_volume_name
* Get the path of the volume the file resides on
* @file: NautilusFile representing the file in question.
- *
- * Returns: newly-allocated copy of the volume name of the target file,
+ *
+ * Returns: newly-allocated copy of the volume name of the target file,
* if the volume name isn't set, it returns the mount path of the volume
- */
+ */
char *
nautilus_file_get_volume_name (NautilusFile *file)
{
- GFile *location;
- char *res;
- GMount *mount;
+ GFile *location;
+ char *res;
+ GMount *mount;
+
+ res = NULL;
- res = NULL;
-
- location = nautilus_file_get_location (file);
- mount = g_file_find_enclosing_mount (location, NULL, NULL);
- if (mount) {
- res = g_strdup (g_mount_get_name (mount));
- g_object_unref (mount);
- }
- g_object_unref (location);
+ location = nautilus_file_get_location (file);
+ mount = g_file_find_enclosing_mount (location, NULL, NULL);
+ if (mount)
+ {
+ res = g_strdup (g_mount_get_name (mount));
+ g_object_unref (mount);
+ }
+ g_object_unref (location);
- return res;
+ return res;
}
/**
* nautilus_file_get_symbolic_link_target_path
- *
- * Get the file path of the target of a symbolic link. It is an error
+ *
+ * Get the file path of the target of a symbolic link. It is an error
* to call this function on a file that isn't a symbolic link.
* @file: NautilusFile representing the symbolic link in question.
- *
+ *
* Returns: newly-allocated copy of the file path of the target of the symbolic link.
*/
char *
nautilus_file_get_symbolic_link_target_path (NautilusFile *file)
{
- if (!nautilus_file_is_symbolic_link (file)) {
- g_warning ("File has symlink target, but is not marked as symlink");
- }
+ if (!nautilus_file_is_symbolic_link (file))
+ {
+ g_warning ("File has symlink target, but is not marked as symlink");
+ }
- return g_strdup (file->details->symlink_name);
+ return g_strdup (file->details->symlink_name);
}
/**
* nautilus_file_get_symbolic_link_target_uri
- *
- * Get the uri of the target of a symbolic link. It is an error
+ *
+ * Get the uri of the target of a symbolic link. It is an error
* to call this function on a file that isn't a symbolic link.
* @file: NautilusFile representing the symbolic link in question.
- *
+ *
* Returns: newly-allocated copy of the uri of the target of the symbolic link.
*/
char *
nautilus_file_get_symbolic_link_target_uri (NautilusFile *file)
{
- GFile *location, *parent, *target;
- char *target_uri;
-
- if (!nautilus_file_is_symbolic_link (file)) {
- g_warning ("File has symlink target, but is not marked as symlink");
- }
-
- if (file->details->symlink_name == NULL) {
- return NULL;
- } else {
- target = NULL;
-
- location = nautilus_file_get_location (file);
- parent = g_file_get_parent (location);
- g_object_unref (location);
- if (parent) {
- target = g_file_resolve_relative_path (parent, file->details->symlink_name);
- g_object_unref (parent);
- }
-
- target_uri = NULL;
- if (target) {
- target_uri = g_file_get_uri (target);
- g_object_unref (target);
- }
- return target_uri;
- }
+ GFile *location, *parent, *target;
+ char *target_uri;
+
+ if (!nautilus_file_is_symbolic_link (file))
+ {
+ g_warning ("File has symlink target, but is not marked as symlink");
+ }
+
+ if (file->details->symlink_name == NULL)
+ {
+ return NULL;
+ }
+ else
+ {
+ target = NULL;
+
+ location = nautilus_file_get_location (file);
+ parent = g_file_get_parent (location);
+ g_object_unref (location);
+ if (parent)
+ {
+ target = g_file_resolve_relative_path (parent, file->details->symlink_name);
+ g_object_unref (parent);
+ }
+
+ target_uri = NULL;
+ if (target)
+ {
+ target_uri = g_file_get_uri (target);
+ g_object_unref (target);
+ }
+ return target_uri;
+ }
}
/**
* nautilus_file_is_nautilus_link
- *
+ *
* Check if this file is a "nautilus link", meaning a historical
* nautilus xml link file or a desktop file.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: True if the file is a nautilus link.
- *
+ *
**/
gboolean
nautilus_file_is_nautilus_link (NautilusFile *file)
{
- if (file->details->mime_type == NULL) {
- return FALSE;
- }
- return g_content_type_equals (eel_ref_str_peek (file->details->mime_type),
- "application/x-desktop");
+ if (file->details->mime_type == NULL)
+ {
+ return FALSE;
+ }
+ return g_content_type_equals (eel_ref_str_peek (file->details->mime_type),
+ "application/x-desktop");
}
/**
* nautilus_file_is_directory
- *
+ *
* Check if this file is a directory.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: TRUE if @file is a directory.
- *
+ *
**/
gboolean
nautilus_file_is_directory (NautilusFile *file)
{
- return nautilus_file_get_file_type (file) == G_FILE_TYPE_DIRECTORY;
+ return nautilus_file_get_file_type (file) == G_FILE_TYPE_DIRECTORY;
}
/**
@@ -7210,99 +8083,101 @@ nautilus_file_is_directory (NautilusFile *file)
* Check if this file is a special platform directory.
* @file: NautilusFile representing the file in question.
* @special_directory: GUserDirectory representing the type to test for
- *
+ *
* Returns: TRUE if @file is a special directory of the given kind.
*/
gboolean
-nautilus_file_is_user_special_directory (NautilusFile *file,
- GUserDirectory special_directory)
+nautilus_file_is_user_special_directory (NautilusFile *file,
+ GUserDirectory special_directory)
{
- gboolean is_special_dir;
- const gchar *special_dir;
+ gboolean is_special_dir;
+ const gchar *special_dir;
- special_dir = g_get_user_special_dir (special_directory);
- is_special_dir = FALSE;
+ special_dir = g_get_user_special_dir (special_directory);
+ is_special_dir = FALSE;
- if (special_dir) {
- GFile *loc;
- GFile *special_gfile;
+ if (special_dir)
+ {
+ GFile *loc;
+ GFile *special_gfile;
- loc = nautilus_file_get_location (file);
- special_gfile = g_file_new_for_path (special_dir);
- is_special_dir = g_file_equal (loc, special_gfile);
- g_object_unref (special_gfile);
- g_object_unref (loc);
- }
+ loc = nautilus_file_get_location (file);
+ special_gfile = g_file_new_for_path (special_dir);
+ is_special_dir = g_file_equal (loc, special_gfile);
+ g_object_unref (special_gfile);
+ g_object_unref (loc);
+ }
- return is_special_dir;
+ return is_special_dir;
}
gboolean
nautilus_file_is_special_link (NautilusFile *file)
{
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->is_special_link (file);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->is_special_link (file);
}
static gboolean
real_is_special_link (NautilusFile *file)
{
- return FALSE;
+ return FALSE;
}
gboolean
nautilus_file_is_archive (NautilusFile *file)
{
- g_autofree char *mime_type;
+ g_autofree char *mime_type;
- mime_type = nautilus_file_get_mime_type (file);
+ mime_type = nautilus_file_get_mime_type (file);
- return autoar_check_mime_type_supported (mime_type);
+ return autoar_check_mime_type_supported (mime_type);
}
/**
* nautilus_file_is_in_trash
- *
+ *
* Check if this file is a file in trash.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: TRUE if @file is in a trash.
- *
+ *
**/
gboolean
nautilus_file_is_in_trash (NautilusFile *file)
{
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- return nautilus_directory_is_in_trash (file->details->directory);
+ return nautilus_directory_is_in_trash (file->details->directory);
}
/**
* nautilus_file_is_in_recent
- *
+ *
* Check if this file is a file in Recent.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: TRUE if @file is in Recent.
- *
+ *
**/
gboolean
nautilus_file_is_in_recent (NautilusFile *file)
{
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- return nautilus_directory_is_in_recent (file->details->directory);
+ return nautilus_directory_is_in_recent (file->details->directory);
}
-static const gchar * const remote_types[] = {
- "afp",
- "google-drive",
- "sftp",
- "webdav",
- "ftp",
- "nfs",
- "cifs",
- NULL
+static const gchar * const remote_types[] =
+{
+ "afp",
+ "google-drive",
+ "sftp",
+ "webdav",
+ "ftp",
+ "nfs",
+ "cifs",
+ NULL
};
/**
@@ -7312,18 +8187,18 @@ static const gchar * const remote_types[] = {
* @file: NautilusFile representing the file in question.
*
* Returns: TRUE if @file is in a remote filesystem.
- *
+ *
**/
gboolean
nautilus_file_is_remote (NautilusFile *file)
{
- char *filesystem_type;
+ char *filesystem_type;
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- filesystem_type = nautilus_file_get_filesystem_type (file);
+ filesystem_type = nautilus_file_get_filesystem_type (file);
- return filesystem_type != NULL && g_strv_contains (remote_types, filesystem_type);
+ return filesystem_type != NULL && g_strv_contains (remote_types, filesystem_type);
}
/**
@@ -7338,179 +8213,190 @@ nautilus_file_is_remote (NautilusFile *file)
gboolean
nautilus_file_is_other_locations (NautilusFile *file)
{
- gboolean is_other_locations;
- gchar *uri;
+ gboolean is_other_locations;
+ gchar *uri;
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- uri = nautilus_file_get_uri (file);
- is_other_locations = g_strcmp0 (uri, "other-locations:///") == 0;
+ uri = nautilus_file_get_uri (file);
+ is_other_locations = g_strcmp0 (uri, "other-locations:///") == 0;
- g_free (uri);
+ g_free (uri);
- return is_other_locations;
+ return is_other_locations;
}
GError *
nautilus_file_get_file_info_error (NautilusFile *file)
{
- if (!file->details->get_info_failed) {
- return NULL;
- }
+ if (!file->details->get_info_failed)
+ {
+ return NULL;
+ }
- return file->details->get_info_error;
+ return file->details->get_info_error;
}
/**
* nautilus_file_contains_text
- *
+ *
* Check if this file contains text.
* This is private and is used to decide whether or not to read the top left text.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: TRUE if @file has a text MIME type.
- *
+ *
**/
gboolean
nautilus_file_contains_text (NautilusFile *file)
{
- if (file == NULL) {
- return FALSE;
- }
+ if (file == NULL)
+ {
+ return FALSE;
+ }
- /* All text files inherit from text/plain */
- return nautilus_file_is_mime_type (file, "text/plain");
+ /* All text files inherit from text/plain */
+ return nautilus_file_is_mime_type (file, "text/plain");
}
/**
* nautilus_file_is_executable
- *
+ *
* Check if this file is executable at all.
* @file: NautilusFile representing the file in question.
- *
+ *
* Returns: TRUE if any of the execute bits are set. FALSE if
* not, or if the permissions are unknown.
- *
+ *
**/
gboolean
nautilus_file_is_executable (NautilusFile *file)
{
- if (!file->details->has_permissions) {
- /* File's permissions field is not valid.
- * Can't access specific permissions, so return FALSE.
- */
- return FALSE;
- }
+ if (!file->details->has_permissions)
+ {
+ /* File's permissions field is not valid.
+ * Can't access specific permissions, so return FALSE.
+ */
+ return FALSE;
+ }
- return file->details->can_execute;
+ return file->details->can_execute;
}
char *
nautilus_file_get_filesystem_id (NautilusFile *file)
{
- return g_strdup (eel_ref_str_peek (file->details->filesystem_id));
+ return g_strdup (eel_ref_str_peek (file->details->filesystem_id));
}
NautilusFile *
nautilus_file_get_trash_original_file (NautilusFile *file)
{
- GFile *location;
- NautilusFile *original_file;
+ GFile *location;
+ NautilusFile *original_file;
- original_file = NULL;
+ original_file = NULL;
- if (file->details->trash_orig_path != NULL) {
- location = g_file_new_for_path (file->details->trash_orig_path);
- original_file = nautilus_file_get (location);
- g_object_unref (location);
- }
-
- return original_file;
+ if (file->details->trash_orig_path != NULL)
+ {
+ location = g_file_new_for_path (file->details->trash_orig_path);
+ original_file = nautilus_file_get (location);
+ g_object_unref (location);
+ }
+ return original_file;
}
void
nautilus_file_mark_gone (NautilusFile *file)
{
- NautilusDirectory *directory;
+ NautilusDirectory *directory;
- if (file->details->is_gone)
- return;
+ if (file->details->is_gone)
+ {
+ return;
+ }
- file->details->is_gone = TRUE;
+ file->details->is_gone = TRUE;
- update_links_if_target (file);
+ update_links_if_target (file);
- /* Drop it from the symlink hash ! */
- remove_from_link_hash_table (file);
+ /* Drop it from the symlink hash ! */
+ remove_from_link_hash_table (file);
- /* Let the directory know it's gone. */
- directory = file->details->directory;
- if (!nautilus_file_is_self_owned (file)) {
- nautilus_directory_remove_file (directory, file);
- }
+ /* Let the directory know it's gone. */
+ directory = file->details->directory;
+ if (!nautilus_file_is_self_owned (file))
+ {
+ nautilus_directory_remove_file (directory, file);
+ }
- nautilus_file_clear_info (file);
+ nautilus_file_clear_info (file);
- /* FIXME bugzilla.gnome.org 42429:
- * Maybe we can get rid of the name too eventually, but
- * for now that would probably require too many if statements
- * everywhere anyone deals with the name. Maybe we can give it
- * a hard-coded "<deleted>" name or something.
- */
+ /* FIXME bugzilla.gnome.org 42429:
+ * Maybe we can get rid of the name too eventually, but
+ * for now that would probably require too many if statements
+ * everywhere anyone deals with the name. Maybe we can give it
+ * a hard-coded "<deleted>" name or something.
+ */
}
/**
* nautilus_file_changed
- *
+ *
* Notify the user that this file has changed.
* @file: NautilusFile representing the file in question.
**/
void
nautilus_file_changed (NautilusFile *file)
{
- GList fake_list;
+ GList fake_list;
- g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
- if (nautilus_file_is_self_owned (file)) {
- nautilus_file_emit_changed (file);
- } else {
- fake_list.data = file;
- fake_list.next = NULL;
- fake_list.prev = NULL;
- nautilus_directory_emit_change_signals
- (file->details->directory, &fake_list);
- }
+ if (nautilus_file_is_self_owned (file))
+ {
+ nautilus_file_emit_changed (file);
+ }
+ else
+ {
+ fake_list.data = file;
+ fake_list.next = NULL;
+ fake_list.prev = NULL;
+ nautilus_directory_emit_change_signals
+ (file->details->directory, &fake_list);
+ }
}
/**
* nautilus_file_updated_deep_count_in_progress
- *
+ *
* Notify clients that a newer deep count is available for
* the directory in question.
*/
void
-nautilus_file_updated_deep_count_in_progress (NautilusFile *file) {
- GList *link_files, *node;
+nautilus_file_updated_deep_count_in_progress (NautilusFile *file)
+{
+ GList *link_files, *node;
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (nautilus_file_is_directory (file));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (nautilus_file_is_directory (file));
- /* Send out a signal. */
- g_signal_emit (file, signals[UPDATED_DEEP_COUNT_IN_PROGRESS], 0, file);
+ /* Send out a signal. */
+ g_signal_emit (file, signals[UPDATED_DEEP_COUNT_IN_PROGRESS], 0, file);
- /* Tell link files pointing to this object about the change. */
- link_files = get_link_files (file);
- for (node = link_files; node != NULL; node = node->next) {
- nautilus_file_updated_deep_count_in_progress (NAUTILUS_FILE (node->data));
- }
- nautilus_file_list_free (link_files);
+ /* Tell link files pointing to this object about the change. */
+ link_files = get_link_files (file);
+ for (node = link_files; node != NULL; node = node->next)
+ {
+ nautilus_file_updated_deep_count_in_progress (NAUTILUS_FILE (node->data));
+ }
+ nautilus_file_list_free (link_files);
}
/**
* nautilus_file_emit_changed
- *
+ *
* Emit a file changed signal.
* This can only be called by the directory, since the directory
* also has to emit a files_changed signal.
@@ -7520,26 +8406,28 @@ nautilus_file_updated_deep_count_in_progress (NautilusFile *file) {
void
nautilus_file_emit_changed (NautilusFile *file)
{
- GList *link_files, *p;
+ GList *link_files, *p;
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- /* Send out a signal. */
- g_signal_emit (file, signals[CHANGED], 0, file);
+ /* Send out a signal. */
+ g_signal_emit (file, signals[CHANGED], 0, file);
- /* Tell link files pointing to this object about the change. */
- link_files = get_link_files (file);
- for (p = link_files; p != NULL; p = p->next) {
- if (p->data != file) {
- nautilus_file_changed (NAUTILUS_FILE (p->data));
- }
- }
- nautilus_file_list_free (link_files);
+ /* Tell link files pointing to this object about the change. */
+ link_files = get_link_files (file);
+ for (p = link_files; p != NULL; p = p->next)
+ {
+ if (p->data != file)
+ {
+ nautilus_file_changed (NAUTILUS_FILE (p->data));
+ }
+ }
+ nautilus_file_list_free (link_files);
}
/**
* nautilus_file_is_gone
- *
+ *
* Check if a file has already been deleted.
* @file: NautilusFile representing the file in question.
*
@@ -7548,14 +8436,14 @@ nautilus_file_emit_changed (NautilusFile *file)
gboolean
nautilus_file_is_gone (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return file->details->is_gone;
+ return file->details->is_gone;
}
/**
* nautilus_file_is_not_yet_confirmed
- *
+ *
* Check if we're in a state where we don't know if a file really
* exists or not, before the initial I/O is complete.
* @file: NautilusFile representing the file in question.
@@ -7565,9 +8453,9 @@ nautilus_file_is_gone (NautilusFile *file)
gboolean
nautilus_file_is_not_yet_confirmed (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return !file->details->got_file_info;
+ return !file->details->got_file_info;
}
/**
@@ -7581,223 +8469,236 @@ nautilus_file_is_not_yet_confirmed (NautilusFile *file)
*
* @file: The file being queried.
* @file_attributes: A bit-mask with the desired information.
- *
+ *
* Return value: TRUE if all of the specified attributes are currently readable.
*/
gboolean
-nautilus_file_check_if_ready (NautilusFile *file,
- NautilusFileAttributes file_attributes)
+nautilus_file_check_if_ready (NautilusFile *file,
+ NautilusFileAttributes file_attributes)
{
- /* To be parallel with call_when_ready, return
- * TRUE for NULL file.
- */
- if (file == NULL) {
- return TRUE;
- }
+ /* To be parallel with call_when_ready, return
+ * TRUE for NULL file.
+ */
+ if (file == NULL)
+ {
+ return TRUE;
+ }
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->check_if_ready (file, file_attributes);
-}
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->check_if_ready (file, file_attributes);
+}
void
-nautilus_file_call_when_ready (NautilusFile *file,
- NautilusFileAttributes file_attributes,
- NautilusFileCallback callback,
- gpointer callback_data)
-
+nautilus_file_call_when_ready (NautilusFile *file,
+ NautilusFileAttributes file_attributes,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- if (file == NULL) {
- (* callback) (file, callback_data);
- return;
- }
+ if (file == NULL)
+ {
+ (*callback)(file, callback_data);
+ return;
+ }
- g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->call_when_ready
- (file, file_attributes, callback, callback_data);
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->call_when_ready
+ (file, file_attributes, callback, callback_data);
}
void
-nautilus_file_cancel_call_when_ready (NautilusFile *file,
- NautilusFileCallback callback,
- gpointer callback_data)
+nautilus_file_cancel_call_when_ready (NautilusFile *file,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- g_return_if_fail (callback != NULL);
+ g_return_if_fail (callback != NULL);
- if (file == NULL) {
- return;
- }
+ if (file == NULL)
+ {
+ return;
+ }
- g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->cancel_call_when_ready
- (file, callback, callback_data);
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->cancel_call_when_ready
+ (file, callback, callback_data);
}
static void
invalidate_directory_count (NautilusFile *file)
{
- file->details->directory_count_is_up_to_date = FALSE;
+ file->details->directory_count_is_up_to_date = FALSE;
}
static void
invalidate_deep_counts (NautilusFile *file)
{
- file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
+ file->details->deep_counts_status = NAUTILUS_REQUEST_NOT_STARTED;
}
static void
invalidate_mime_list (NautilusFile *file)
{
- file->details->mime_list_is_up_to_date = FALSE;
+ file->details->mime_list_is_up_to_date = FALSE;
}
static void
invalidate_file_info (NautilusFile *file)
{
- file->details->file_info_is_up_to_date = FALSE;
+ file->details->file_info_is_up_to_date = FALSE;
}
static void
invalidate_link_info (NautilusFile *file)
{
- file->details->link_info_is_up_to_date = FALSE;
+ file->details->link_info_is_up_to_date = FALSE;
}
static void
invalidate_thumbnail (NautilusFile *file)
{
- file->details->thumbnail_is_up_to_date = FALSE;
+ file->details->thumbnail_is_up_to_date = FALSE;
}
static void
invalidate_mount (NautilusFile *file)
{
- file->details->mount_is_up_to_date = FALSE;
+ file->details->mount_is_up_to_date = FALSE;
}
void
nautilus_file_invalidate_extension_info_internal (NautilusFile *file)
{
- if (file->details->pending_info_providers)
- g_list_free_full (file->details->pending_info_providers, g_object_unref);
+ if (file->details->pending_info_providers)
+ {
+ g_list_free_full (file->details->pending_info_providers, g_object_unref);
+ }
- file->details->pending_info_providers =
- nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_INFO_PROVIDER);
+ file->details->pending_info_providers =
+ nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_INFO_PROVIDER);
}
void
nautilus_file_invalidate_attributes_internal (NautilusFile *file,
NautilusFileAttributes file_attributes)
{
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->invalidate_attributes_internal (file, file_attributes);
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->invalidate_attributes_internal (file, file_attributes);
}
static void
real_invalidate_attributes_internal (NautilusFile *file,
NautilusFileAttributes file_attributes)
{
- Request request;
-
- if (file == NULL) {
- return;
- }
-
- request = nautilus_directory_set_up_request (file_attributes);
-
- if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT)) {
- invalidate_directory_count (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT)) {
- invalidate_deep_counts (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST)) {
- invalidate_mime_list (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO)) {
- invalidate_file_info (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO)) {
- invalidate_link_info (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_EXTENSION_INFO)) {
- nautilus_file_invalidate_extension_info_internal (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL)) {
- invalidate_thumbnail (file);
- }
- if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT)) {
- invalidate_mount (file);
- }
-
- /* FIXME bugzilla.gnome.org 45075: implement invalidating metadata */
+ Request request;
+
+ if (file == NULL)
+ {
+ return;
+ }
+
+ request = nautilus_directory_set_up_request (file_attributes);
+
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DIRECTORY_COUNT))
+ {
+ invalidate_directory_count (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_DEEP_COUNT))
+ {
+ invalidate_deep_counts (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MIME_LIST))
+ {
+ invalidate_mime_list (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_FILE_INFO))
+ {
+ invalidate_file_info (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_LINK_INFO))
+ {
+ invalidate_link_info (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_EXTENSION_INFO))
+ {
+ nautilus_file_invalidate_extension_info_internal (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_THUMBNAIL))
+ {
+ invalidate_thumbnail (file);
+ }
+ if (REQUEST_WANTS_TYPE (request, REQUEST_MOUNT))
+ {
+ invalidate_mount (file);
+ }
+
+ /* FIXME bugzilla.gnome.org 45075: implement invalidating metadata */
}
gboolean
nautilus_file_is_thumbnailing (NautilusFile *file)
{
- g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
-
- return file->details->is_thumbnailing;
+ g_return_val_if_fail (NAUTILUS_IS_FILE (file), FALSE);
+
+ return file->details->is_thumbnailing;
}
void
nautilus_file_set_is_thumbnailing (NautilusFile *file,
- gboolean is_thumbnailing)
+ gboolean is_thumbnailing)
{
- g_return_if_fail (NAUTILUS_IS_FILE (file));
-
- file->details->is_thumbnailing = is_thumbnailing;
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
+
+ file->details->is_thumbnailing = is_thumbnailing;
}
/**
* nautilus_file_invalidate_attributes
- *
+ *
* Invalidate the specified attributes and force a reload.
* @file: NautilusFile representing the file in question.
* @file_attributes: attributes to froget.
**/
void
-nautilus_file_invalidate_attributes (NautilusFile *file,
- NautilusFileAttributes file_attributes)
+nautilus_file_invalidate_attributes (NautilusFile *file,
+ NautilusFileAttributes file_attributes)
{
- /* Cancel possible in-progress loads of any of these attributes */
- nautilus_directory_cancel_loading_file_attributes (file->details->directory,
- file,
- file_attributes);
-
- /* Actually invalidate the values */
- nautilus_file_invalidate_attributes_internal (file, file_attributes);
+ /* Cancel possible in-progress loads of any of these attributes */
+ nautilus_directory_cancel_loading_file_attributes (file->details->directory,
+ file,
+ file_attributes);
- nautilus_directory_add_file_to_work_queue (file->details->directory, file);
-
- /* Kick off I/O if necessary */
- nautilus_directory_async_state_changed (file->details->directory);
+ /* Actually invalidate the values */
+ nautilus_file_invalidate_attributes_internal (file, file_attributes);
+
+ nautilus_directory_add_file_to_work_queue (file->details->directory, file);
+
+ /* Kick off I/O if necessary */
+ nautilus_directory_async_state_changed (file->details->directory);
}
-NautilusFileAttributes
+NautilusFileAttributes
nautilus_file_get_all_attributes (void)
{
- return NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
- NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES |
- NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO |
- NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT;
+ return NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES |
+ NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT;
}
void
nautilus_file_invalidate_all_attributes (NautilusFile *file)
{
- NautilusFileAttributes all_attributes;
+ NautilusFileAttributes all_attributes;
- all_attributes = nautilus_file_get_all_attributes ();
- nautilus_file_invalidate_attributes (file, all_attributes);
+ all_attributes = nautilus_file_get_all_attributes ();
+ nautilus_file_invalidate_attributes (file, all_attributes);
}
@@ -7812,44 +8713,65 @@ nautilus_file_invalidate_all_attributes (NautilusFile *file)
void
nautilus_file_dump (NautilusFile *file)
{
- long size = file->details->deep_size;
- char *uri;
- const char *file_kind;
-
- uri = nautilus_file_get_uri (file);
- g_print ("uri: %s \n", uri);
- if (!file->details->got_file_info) {
- g_print ("no file info \n");
- } else if (file->details->get_info_failed) {
- g_print ("failed to get file info \n");
- } else {
- g_print ("size: %ld \n", size);
- switch (file->details->type) {
- case G_FILE_TYPE_REGULAR:
- file_kind = "regular file";
- break;
- case G_FILE_TYPE_DIRECTORY:
- file_kind = "folder";
- break;
- case G_FILE_TYPE_SPECIAL:
- file_kind = "special";
- break;
- case G_FILE_TYPE_SYMBOLIC_LINK:
- file_kind = "symbolic link";
- break;
- case G_FILE_TYPE_UNKNOWN:
- default:
- file_kind = "unknown";
- break;
- }
- g_print ("kind: %s \n", file_kind);
- if (file->details->type == G_FILE_TYPE_SYMBOLIC_LINK) {
- g_print ("link to %s \n", file->details->symlink_name);
- /* FIXME bugzilla.gnome.org 42430: add following of symlinks here */
- }
- /* FIXME bugzilla.gnome.org 42431: add permissions and other useful stuff here */
- }
- g_free (uri);
+ long size = file->details->deep_size;
+ char *uri;
+ const char *file_kind;
+
+ uri = nautilus_file_get_uri (file);
+ g_print ("uri: %s \n", uri);
+ if (!file->details->got_file_info)
+ {
+ g_print ("no file info \n");
+ }
+ else if (file->details->get_info_failed)
+ {
+ g_print ("failed to get file info \n");
+ }
+ else
+ {
+ g_print ("size: %ld \n", size);
+ switch (file->details->type)
+ {
+ case G_FILE_TYPE_REGULAR:
+ {
+ file_kind = "regular file";
+ }
+ break;
+
+ case G_FILE_TYPE_DIRECTORY:
+ {
+ file_kind = "folder";
+ }
+ break;
+
+ case G_FILE_TYPE_SPECIAL:
+ {
+ file_kind = "special";
+ }
+ break;
+
+ case G_FILE_TYPE_SYMBOLIC_LINK:
+ {
+ file_kind = "symbolic link";
+ }
+ break;
+
+ case G_FILE_TYPE_UNKNOWN:
+ default:
+ {
+ file_kind = "unknown";
+ }
+ break;
+ }
+ g_print ("kind: %s \n", file_kind);
+ if (file->details->type == G_FILE_TYPE_SYMBOLIC_LINK)
+ {
+ g_print ("link to %s \n", file->details->symlink_name);
+ /* FIXME bugzilla.gnome.org 42430: add following of symlinks here */
+ }
+ /* FIXME bugzilla.gnome.org 42431: add permissions and other useful stuff here */
+ }
+ g_free (uri);
}
/**
@@ -7861,8 +8783,8 @@ nautilus_file_dump (NautilusFile *file)
GList *
nautilus_file_list_ref (GList *list)
{
- g_list_foreach (list, (GFunc) nautilus_file_ref, NULL);
- return list;
+ g_list_foreach (list, (GFunc) nautilus_file_ref, NULL);
+ return list;
}
/**
@@ -7874,7 +8796,7 @@ nautilus_file_list_ref (GList *list)
void
nautilus_file_list_unref (GList *list)
{
- g_list_foreach (list, (GFunc) nautilus_file_unref, NULL);
+ g_list_foreach (list, (GFunc) nautilus_file_unref, NULL);
}
/**
@@ -7886,8 +8808,8 @@ nautilus_file_list_unref (GList *list)
void
nautilus_file_list_free (GList *list)
{
- nautilus_file_list_unref (list);
- g_list_free (list);
+ nautilus_file_list_unref (list);
+ g_list_free (list);
}
/**
@@ -7899,495 +8821,537 @@ nautilus_file_list_free (GList *list)
GList *
nautilus_file_list_copy (GList *list)
{
- return g_list_copy (nautilus_file_list_ref (list));
+ return g_list_copy (nautilus_file_list_ref (list));
}
static gboolean
get_attributes_for_default_sort_type (NautilusFile *file,
- gboolean *is_recent,
- gboolean *is_download,
- gboolean *is_trash,
- gboolean *is_search)
-{
- gboolean is_recent_dir, is_download_dir, is_desktop_dir, is_trash_dir, is_search_dir, retval;
-
- *is_recent = FALSE;
- *is_download = FALSE;
- *is_trash = FALSE;
- *is_search = FALSE;
- retval = FALSE;
-
- /* special handling for certain directories */
- if (file && nautilus_file_is_directory (file)) {
- is_recent_dir =
- nautilus_file_is_in_recent (file);
- is_download_dir =
- nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_DOWNLOAD);
- is_desktop_dir =
- nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_DESKTOP);
- is_trash_dir =
- nautilus_file_is_in_trash (file);
- is_search_dir =
- nautilus_file_is_in_search (file);
-
- if (is_download_dir && !is_desktop_dir) {
- *is_download = TRUE;
- retval = TRUE;
- } else if (is_trash_dir) {
- *is_trash = TRUE;
- retval = TRUE;
- } else if (is_recent_dir) {
- *is_recent = TRUE;
- retval = TRUE;
- } else if (is_search_dir) {
- *is_search = TRUE;
- retval = TRUE;
- }
- }
-
- return retval;
+ gboolean *is_recent,
+ gboolean *is_download,
+ gboolean *is_trash,
+ gboolean *is_search)
+{
+ gboolean is_recent_dir, is_download_dir, is_desktop_dir, is_trash_dir, is_search_dir, retval;
+
+ *is_recent = FALSE;
+ *is_download = FALSE;
+ *is_trash = FALSE;
+ *is_search = FALSE;
+ retval = FALSE;
+
+ /* special handling for certain directories */
+ if (file && nautilus_file_is_directory (file))
+ {
+ is_recent_dir =
+ nautilus_file_is_in_recent (file);
+ is_download_dir =
+ nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_DOWNLOAD);
+ is_desktop_dir =
+ nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_DESKTOP);
+ is_trash_dir =
+ nautilus_file_is_in_trash (file);
+ is_search_dir =
+ nautilus_file_is_in_search (file);
+
+ if (is_download_dir && !is_desktop_dir)
+ {
+ *is_download = TRUE;
+ retval = TRUE;
+ }
+ else if (is_trash_dir)
+ {
+ *is_trash = TRUE;
+ retval = TRUE;
+ }
+ else if (is_recent_dir)
+ {
+ *is_recent = TRUE;
+ retval = TRUE;
+ }
+ else if (is_search_dir)
+ {
+ *is_search = TRUE;
+ retval = TRUE;
+ }
+ }
+
+ return retval;
}
NautilusFileSortType
nautilus_file_get_default_sort_type (NautilusFile *file,
- gboolean *reversed)
+ gboolean *reversed)
{
- NautilusFileSortType retval;
- gboolean is_recent, is_download, is_trash, is_search, res;
+ NautilusFileSortType retval;
+ gboolean is_recent, is_download, is_trash, is_search, res;
- retval = NAUTILUS_FILE_SORT_NONE;
- is_recent = is_download = is_trash = is_search = FALSE;
- res = get_attributes_for_default_sort_type (file, &is_recent, &is_download, &is_trash, &is_search);
+ retval = NAUTILUS_FILE_SORT_NONE;
+ is_recent = is_download = is_trash = is_search = FALSE;
+ res = get_attributes_for_default_sort_type (file, &is_recent, &is_download, &is_trash, &is_search);
- if (res) {
- if (is_recent) {
- retval = NAUTILUS_FILE_SORT_BY_ATIME;
- } else if (is_download) {
- retval = NAUTILUS_FILE_SORT_BY_MTIME;
- } else if (is_trash) {
- retval = NAUTILUS_FILE_SORT_BY_TRASHED_TIME;
- } else if (is_search) {
- retval = NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE;
- }
+ if (res)
+ {
+ if (is_recent)
+ {
+ retval = NAUTILUS_FILE_SORT_BY_ATIME;
+ }
+ else if (is_download)
+ {
+ retval = NAUTILUS_FILE_SORT_BY_MTIME;
+ }
+ else if (is_trash)
+ {
+ retval = NAUTILUS_FILE_SORT_BY_TRASHED_TIME;
+ }
+ else if (is_search)
+ {
+ retval = NAUTILUS_FILE_SORT_BY_SEARCH_RELEVANCE;
+ }
- if (reversed != NULL) {
- *reversed = res;
- }
- }
+ if (reversed != NULL)
+ {
+ *reversed = res;
+ }
+ }
- return retval;
+ return retval;
}
const gchar *
nautilus_file_get_default_sort_attribute (NautilusFile *file,
- gboolean *reversed)
+ gboolean *reversed)
{
- const gchar *retval;
- gboolean is_recent, is_download, is_trash, is_search, res;
+ const gchar *retval;
+ gboolean is_recent, is_download, is_trash, is_search, res;
- retval = NULL;
- is_download = is_trash = is_search = FALSE;
- res = get_attributes_for_default_sort_type (file, &is_recent, &is_download, &is_trash, &is_search);
+ retval = NULL;
+ is_download = is_trash = is_search = FALSE;
+ res = get_attributes_for_default_sort_type (file, &is_recent, &is_download, &is_trash, &is_search);
- if (res) {
- if (is_recent || is_download) {
- retval = g_quark_to_string (attribute_date_modified_q);
- } else if (is_trash) {
- retval = g_quark_to_string (attribute_trashed_on_q);
- } else if (is_search) {
- retval = g_quark_to_string (attribute_search_relevance_q);
- }
+ if (res)
+ {
+ if (is_recent || is_download)
+ {
+ retval = g_quark_to_string (attribute_date_modified_q);
+ }
+ else if (is_trash)
+ {
+ retval = g_quark_to_string (attribute_trashed_on_q);
+ }
+ else if (is_search)
+ {
+ retval = g_quark_to_string (attribute_search_relevance_q);
+ }
- if (reversed != NULL) {
- *reversed = res;
- }
- }
+ if (reversed != NULL)
+ {
+ *reversed = res;
+ }
+ }
- return retval;
+ return retval;
}
static int
-compare_by_display_name_cover (gconstpointer a, gconstpointer b)
+compare_by_display_name_cover (gconstpointer a,
+ gconstpointer b)
{
- return compare_by_display_name (NAUTILUS_FILE (a), NAUTILUS_FILE (b));
+ return compare_by_display_name (NAUTILUS_FILE (a), NAUTILUS_FILE (b));
}
/**
* nautilus_file_list_sort_by_display_name
- *
+ *
* Sort the list of files by file name.
* @list: GList of files.
**/
GList *
nautilus_file_list_sort_by_display_name (GList *list)
{
- return g_list_sort (list, compare_by_display_name_cover);
+ return g_list_sort (list, compare_by_display_name_cover);
}
static GList *ready_data_list = NULL;
-typedef struct
+typedef struct
{
- GList *file_list;
- GList *remaining_files;
- NautilusFileListCallback callback;
- gpointer callback_data;
+ GList *file_list;
+ GList *remaining_files;
+ NautilusFileListCallback callback;
+ gpointer callback_data;
} FileListReadyData;
static void
file_list_ready_data_free (FileListReadyData *data)
{
- GList *l;
+ GList *l;
- l = g_list_find (ready_data_list, data);
- if (l != NULL) {
- ready_data_list = g_list_delete_link (ready_data_list, l);
+ l = g_list_find (ready_data_list, data);
+ if (l != NULL)
+ {
+ ready_data_list = g_list_delete_link (ready_data_list, l);
- nautilus_file_list_free (data->file_list);
- g_list_free (data->remaining_files);
- g_free (data);
- }
+ nautilus_file_list_free (data->file_list);
+ g_list_free (data->remaining_files);
+ g_free (data);
+ }
}
static FileListReadyData *
-file_list_ready_data_new (GList *file_list,
- NautilusFileListCallback callback,
- gpointer callback_data)
+file_list_ready_data_new (GList *file_list,
+ NautilusFileListCallback callback,
+ gpointer callback_data)
{
- FileListReadyData *data;
+ FileListReadyData *data;
- data = g_new0 (FileListReadyData, 1);
- data->file_list = nautilus_file_list_copy (file_list);
- data->remaining_files = g_list_copy (file_list);
- data->callback = callback;
- data->callback_data = callback_data;
+ data = g_new0 (FileListReadyData, 1);
+ data->file_list = nautilus_file_list_copy (file_list);
+ data->remaining_files = g_list_copy (file_list);
+ data->callback = callback;
+ data->callback_data = callback_data;
- ready_data_list = g_list_prepend (ready_data_list, data);
+ ready_data_list = g_list_prepend (ready_data_list, data);
- return data;
+ return data;
}
static void
file_list_file_ready_callback (NautilusFile *file,
- gpointer user_data)
+ gpointer user_data)
{
- FileListReadyData *data;
+ FileListReadyData *data;
+
+ data = user_data;
+ data->remaining_files = g_list_remove (data->remaining_files, file);
- data = user_data;
- data->remaining_files = g_list_remove (data->remaining_files, file);
-
- if (data->remaining_files == NULL) {
- if (data->callback) {
- (*data->callback) (data->file_list, data->callback_data);
- }
+ if (data->remaining_files == NULL)
+ {
+ if (data->callback)
+ {
+ (*data->callback)(data->file_list, data->callback_data);
+ }
- file_list_ready_data_free (data);
- }
+ file_list_ready_data_free (data);
+ }
}
-void
-nautilus_file_list_call_when_ready (GList *file_list,
- NautilusFileAttributes attributes,
- NautilusFileListHandle **handle,
- NautilusFileListCallback callback,
- gpointer callback_data)
+void
+nautilus_file_list_call_when_ready (GList *file_list,
+ NautilusFileAttributes attributes,
+ NautilusFileListHandle **handle,
+ NautilusFileListCallback callback,
+ gpointer callback_data)
{
- GList *l;
- FileListReadyData *data;
- NautilusFile *file;
-
- g_return_if_fail (file_list != NULL);
+ GList *l;
+ FileListReadyData *data;
+ NautilusFile *file;
+
+ g_return_if_fail (file_list != NULL);
- data = file_list_ready_data_new
- (file_list, callback, callback_data);
+ data = file_list_ready_data_new
+ (file_list, callback, callback_data);
- if (handle) {
- *handle = (NautilusFileListHandle *) data;
- }
+ if (handle)
+ {
+ *handle = (NautilusFileListHandle *) data;
+ }
- l = file_list;
- while (l != NULL) {
- file = NAUTILUS_FILE (l->data);
- /* Need to do this here, as the list can be modified by this call */
- l = l->next;
- nautilus_file_call_when_ready (file,
- attributes,
- file_list_file_ready_callback,
- data);
- }
+ l = file_list;
+ while (l != NULL)
+ {
+ file = NAUTILUS_FILE (l->data);
+ /* Need to do this here, as the list can be modified by this call */
+ l = l->next;
+ nautilus_file_call_when_ready (file,
+ attributes,
+ file_list_file_ready_callback,
+ data);
+ }
}
void
nautilus_file_list_cancel_call_when_ready (NautilusFileListHandle *handle)
{
- GList *l;
- NautilusFile *file;
- FileListReadyData *data;
+ GList *l;
+ NautilusFile *file;
+ FileListReadyData *data;
- g_return_if_fail (handle != NULL);
+ g_return_if_fail (handle != NULL);
- data = (FileListReadyData *) handle;
+ data = (FileListReadyData *) handle;
- l = g_list_find (ready_data_list, data);
- if (l != NULL) {
- for (l = data->remaining_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
+ l = g_list_find (ready_data_list, data);
+ if (l != NULL)
+ {
+ for (l = data->remaining_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
- NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->cancel_call_when_ready
- (file, file_list_file_ready_callback, data);
- }
+ NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (file))->cancel_call_when_ready
+ (file, file_list_file_ready_callback, data);
+ }
- file_list_ready_data_free (data);
- }
+ file_list_ready_data_free (data);
+ }
}
static void
thumbnail_limit_changed_callback (gpointer user_data)
{
- g_settings_get (nautilus_preferences,
- NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
- "t", &cached_thumbnail_limit);
+ g_settings_get (nautilus_preferences,
+ NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
+ "t", &cached_thumbnail_limit);
- /* Tell the world that icons might have changed. We could invent a narrower-scope
- * signal to mean only "thumbnails might have changed" if this ends up being slow
- * for some reason.
- */
- emit_change_signals_for_all_files_in_all_directories ();
+ /* Tell the world that icons might have changed. We could invent a narrower-scope
+ * signal to mean only "thumbnails might have changed" if this ends up being slow
+ * for some reason.
+ */
+ emit_change_signals_for_all_files_in_all_directories ();
}
static void
thumbnail_size_changed_callback (gpointer user_data)
{
- cached_thumbnail_size = g_settings_get_int (nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_THUMBNAIL_SIZE);
+ cached_thumbnail_size = g_settings_get_int (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_THUMBNAIL_SIZE);
- /* Tell the world that icons might have changed. We could invent a narrower-scope
- * signal to mean only "thumbnails might have changed" if this ends up being slow
- * for some reason.
- */
- emit_change_signals_for_all_files_in_all_directories ();
+ /* Tell the world that icons might have changed. We could invent a narrower-scope
+ * signal to mean only "thumbnails might have changed" if this ends up being slow
+ * for some reason.
+ */
+ emit_change_signals_for_all_files_in_all_directories ();
}
static void
show_thumbnails_changed_callback (gpointer user_data)
{
- show_file_thumbs = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS);
+ show_file_thumbs = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS);
- /* Tell the world that icons might have changed. We could invent a narrower-scope
- * signal to mean only "thumbnails might have changed" if this ends up being slow
- * for some reason.
- */
- emit_change_signals_for_all_files_in_all_directories ();
+ /* Tell the world that icons might have changed. We could invent a narrower-scope
+ * signal to mean only "thumbnails might have changed" if this ends up being slow
+ * for some reason.
+ */
+ emit_change_signals_for_all_files_in_all_directories ();
}
static void
-mime_type_data_changed_callback (GObject *signaller, gpointer user_data)
+mime_type_data_changed_callback (GObject *signaller,
+ gpointer user_data)
{
- /* Tell the world that icons might have changed. We could invent a narrower-scope
- * signal to mean only "thumbnails might have changed" if this ends up being slow
- * for some reason.
- */
- emit_change_signals_for_all_files_in_all_directories ();
+ /* Tell the world that icons might have changed. We could invent a narrower-scope
+ * signal to mean only "thumbnails might have changed" if this ends up being slow
+ * for some reason.
+ */
+ emit_change_signals_for_all_files_in_all_directories ();
}
static void
icon_theme_changed_callback (GtkIconTheme *icon_theme,
- gpointer user_data)
+ gpointer user_data)
{
- /* Clear all pixmap caches as the icon => pixmap lookup changed */
- nautilus_icon_info_clear_caches ();
+ /* Clear all pixmap caches as the icon => pixmap lookup changed */
+ nautilus_icon_info_clear_caches ();
- /* Tell the world that icons might have changed. We could invent a narrower-scope
- * signal to mean only "thumbnails might have changed" if this ends up being slow
- * for some reason.
- */
- emit_change_signals_for_all_files_in_all_directories ();
+ /* Tell the world that icons might have changed. We could invent a narrower-scope
+ * signal to mean only "thumbnails might have changed" if this ends up being slow
+ * for some reason.
+ */
+ emit_change_signals_for_all_files_in_all_directories ();
}
static void
-real_set_metadata (NautilusFile *file,
- const char *key,
- const char *value)
+real_set_metadata (NautilusFile *file,
+ const char *key,
+ const char *value)
{
- /* Dummy default impl */
+ /* Dummy default impl */
}
static void
-real_set_metadata_as_list (NautilusFile *file,
- const char *key,
- char **value)
+real_set_metadata_as_list (NautilusFile *file,
+ const char *key,
+ char **value)
{
- /* Dummy default impl */
+ /* Dummy default impl */
}
static void
nautilus_file_class_init (NautilusFileClass *class)
{
- GtkIconTheme *icon_theme;
-
- nautilus_file_info_getter = nautilus_file_get_internal;
-
- attribute_name_q = g_quark_from_static_string ("name");
- attribute_size_q = g_quark_from_static_string ("size");
- attribute_type_q = g_quark_from_static_string ("type");
- attribute_detailed_type_q = g_quark_from_static_string ("detailed_type");
- attribute_modification_date_q = g_quark_from_static_string ("modification_date");
- attribute_date_modified_q = g_quark_from_static_string ("date_modified");
- attribute_date_modified_full_q = g_quark_from_static_string ("date_modified_full");
- attribute_date_modified_with_time_q = g_quark_from_static_string ("date_modified_with_time");
- attribute_accessed_date_q = g_quark_from_static_string ("accessed_date");
- attribute_date_accessed_q = g_quark_from_static_string ("date_accessed");
- attribute_date_accessed_full_q = g_quark_from_static_string ("date_accessed_full");
- attribute_mime_type_q = g_quark_from_static_string ("mime_type");
- attribute_size_detail_q = g_quark_from_static_string ("size_detail");
- attribute_deep_size_q = g_quark_from_static_string ("deep_size");
- attribute_deep_file_count_q = g_quark_from_static_string ("deep_file_count");
- attribute_deep_directory_count_q = g_quark_from_static_string ("deep_directory_count");
- attribute_deep_total_count_q = g_quark_from_static_string ("deep_total_count");
- attribute_search_relevance_q = g_quark_from_static_string ("search_relevance");
- attribute_trashed_on_q = g_quark_from_static_string ("trashed_on");
- attribute_trashed_on_full_q = g_quark_from_static_string ("trashed_on_full");
- attribute_trash_orig_path_q = g_quark_from_static_string ("trash_orig_path");
- attribute_permissions_q = g_quark_from_static_string ("permissions");
- attribute_selinux_context_q = g_quark_from_static_string ("selinux_context");
- attribute_octal_permissions_q = g_quark_from_static_string ("octal_permissions");
- attribute_owner_q = g_quark_from_static_string ("owner");
- attribute_group_q = g_quark_from_static_string ("group");
- attribute_uri_q = g_quark_from_static_string ("uri");
- attribute_where_q = g_quark_from_static_string ("where");
- attribute_link_target_q = g_quark_from_static_string ("link_target");
- attribute_volume_q = g_quark_from_static_string ("volume");
- attribute_free_space_q = g_quark_from_static_string ("free_space");
-
- G_OBJECT_CLASS (class)->finalize = finalize;
- G_OBJECT_CLASS (class)->constructor = nautilus_file_constructor;
-
- class->set_metadata = real_set_metadata;
- class->set_metadata_as_list = real_set_metadata_as_list;
- class->can_rename = real_can_rename;
- class->rename = real_rename;
- class->get_target_uri = real_get_target_uri;
- class->drag_can_accept_files = real_drag_can_accept_files;
- class->invalidate_attributes_internal = real_invalidate_attributes_internal;
- class->opens_in_view = real_opens_in_view;
- class->is_special_link = real_is_special_link;
-
- signals[CHANGED] =
- g_signal_new ("changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFileClass, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[UPDATED_DEEP_COUNT_IN_PROGRESS] =
- g_signal_new ("updated-deep-count-in-progress",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFileClass, updated_deep_count_in_progress),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_type_class_add_private (class, sizeof (NautilusFileDetails));
-
- thumbnail_limit_changed_callback (NULL);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
- G_CALLBACK (thumbnail_limit_changed_callback),
- NULL);
- thumbnail_size_changed_callback (NULL);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_THUMBNAIL_SIZE,
- G_CALLBACK (thumbnail_size_changed_callback),
- NULL);
- show_thumbnails_changed_callback (NULL);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS,
- G_CALLBACK (show_thumbnails_changed_callback),
- NULL);
-
- icon_theme = gtk_icon_theme_get_default ();
- g_signal_connect_object (icon_theme,
- "changed",
- G_CALLBACK (icon_theme_changed_callback),
- NULL, 0);
-
- g_signal_connect (nautilus_signaller_get_current (),
- "mime-data-changed",
- G_CALLBACK (mime_type_data_changed_callback),
- NULL);
+ GtkIconTheme *icon_theme;
+
+ nautilus_file_info_getter = nautilus_file_get_internal;
+
+ attribute_name_q = g_quark_from_static_string ("name");
+ attribute_size_q = g_quark_from_static_string ("size");
+ attribute_type_q = g_quark_from_static_string ("type");
+ attribute_detailed_type_q = g_quark_from_static_string ("detailed_type");
+ attribute_modification_date_q = g_quark_from_static_string ("modification_date");
+ attribute_date_modified_q = g_quark_from_static_string ("date_modified");
+ attribute_date_modified_full_q = g_quark_from_static_string ("date_modified_full");
+ attribute_date_modified_with_time_q = g_quark_from_static_string ("date_modified_with_time");
+ attribute_accessed_date_q = g_quark_from_static_string ("accessed_date");
+ attribute_date_accessed_q = g_quark_from_static_string ("date_accessed");
+ attribute_date_accessed_full_q = g_quark_from_static_string ("date_accessed_full");
+ attribute_mime_type_q = g_quark_from_static_string ("mime_type");
+ attribute_size_detail_q = g_quark_from_static_string ("size_detail");
+ attribute_deep_size_q = g_quark_from_static_string ("deep_size");
+ attribute_deep_file_count_q = g_quark_from_static_string ("deep_file_count");
+ attribute_deep_directory_count_q = g_quark_from_static_string ("deep_directory_count");
+ attribute_deep_total_count_q = g_quark_from_static_string ("deep_total_count");
+ attribute_search_relevance_q = g_quark_from_static_string ("search_relevance");
+ attribute_trashed_on_q = g_quark_from_static_string ("trashed_on");
+ attribute_trashed_on_full_q = g_quark_from_static_string ("trashed_on_full");
+ attribute_trash_orig_path_q = g_quark_from_static_string ("trash_orig_path");
+ attribute_permissions_q = g_quark_from_static_string ("permissions");
+ attribute_selinux_context_q = g_quark_from_static_string ("selinux_context");
+ attribute_octal_permissions_q = g_quark_from_static_string ("octal_permissions");
+ attribute_owner_q = g_quark_from_static_string ("owner");
+ attribute_group_q = g_quark_from_static_string ("group");
+ attribute_uri_q = g_quark_from_static_string ("uri");
+ attribute_where_q = g_quark_from_static_string ("where");
+ attribute_link_target_q = g_quark_from_static_string ("link_target");
+ attribute_volume_q = g_quark_from_static_string ("volume");
+ attribute_free_space_q = g_quark_from_static_string ("free_space");
+
+ G_OBJECT_CLASS (class)->finalize = finalize;
+ G_OBJECT_CLASS (class)->constructor = nautilus_file_constructor;
+
+ class->set_metadata = real_set_metadata;
+ class->set_metadata_as_list = real_set_metadata_as_list;
+ class->can_rename = real_can_rename;
+ class->rename = real_rename;
+ class->get_target_uri = real_get_target_uri;
+ class->drag_can_accept_files = real_drag_can_accept_files;
+ class->invalidate_attributes_internal = real_invalidate_attributes_internal;
+ class->opens_in_view = real_opens_in_view;
+ class->is_special_link = real_is_special_link;
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFileClass, changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[UPDATED_DEEP_COUNT_IN_PROGRESS] =
+ g_signal_new ("updated-deep-count-in-progress",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFileClass, updated_deep_count_in_progress),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (class, sizeof (NautilusFileDetails));
+
+ thumbnail_limit_changed_callback (NULL);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
+ G_CALLBACK (thumbnail_limit_changed_callback),
+ NULL);
+ thumbnail_size_changed_callback (NULL);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_ICON_VIEW_THUMBNAIL_SIZE,
+ G_CALLBACK (thumbnail_size_changed_callback),
+ NULL);
+ show_thumbnails_changed_callback (NULL);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS,
+ G_CALLBACK (show_thumbnails_changed_callback),
+ NULL);
+
+ icon_theme = gtk_icon_theme_get_default ();
+ g_signal_connect_object (icon_theme,
+ "changed",
+ G_CALLBACK (icon_theme_changed_callback),
+ NULL, 0);
+
+ g_signal_connect (nautilus_signaller_get_current (),
+ "mime-data-changed",
+ G_CALLBACK (mime_type_data_changed_callback),
+ NULL);
}
static void
nautilus_file_add_emblem (NautilusFile *file,
- const char *emblem_name)
+ const char *emblem_name)
{
- if (file->details->pending_info_providers) {
- file->details->pending_extension_emblems = g_list_prepend (file->details->pending_extension_emblems,
- g_strdup (emblem_name));
- } else {
- file->details->extension_emblems = g_list_prepend (file->details->extension_emblems,
- g_strdup (emblem_name));
- }
+ if (file->details->pending_info_providers)
+ {
+ file->details->pending_extension_emblems = g_list_prepend (file->details->pending_extension_emblems,
+ g_strdup (emblem_name));
+ }
+ else
+ {
+ file->details->extension_emblems = g_list_prepend (file->details->extension_emblems,
+ g_strdup (emblem_name));
+ }
- nautilus_file_changed (file);
+ nautilus_file_changed (file);
}
static void
nautilus_file_add_string_attribute (NautilusFile *file,
- const char *attribute_name,
- const char *value)
-{
- if (file->details->pending_info_providers) {
- /* Lazily create hashtable */
- if (!file->details->pending_extension_attributes) {
- file->details->pending_extension_attributes =
- g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL,
- (GDestroyNotify)g_free);
- }
- g_hash_table_insert (file->details->pending_extension_attributes,
- GINT_TO_POINTER (g_quark_from_string (attribute_name)),
- g_strdup (value));
- } else {
- if (!file->details->extension_attributes) {
- file->details->extension_attributes =
- g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL,
- (GDestroyNotify)g_free);
- }
- g_hash_table_insert (file->details->extension_attributes,
- GINT_TO_POINTER (g_quark_from_string (attribute_name)),
- g_strdup (value));
- }
-
- nautilus_file_changed (file);
+ const char *attribute_name,
+ const char *value)
+{
+ if (file->details->pending_info_providers)
+ {
+ /* Lazily create hashtable */
+ if (!file->details->pending_extension_attributes)
+ {
+ file->details->pending_extension_attributes =
+ g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL,
+ (GDestroyNotify) g_free);
+ }
+ g_hash_table_insert (file->details->pending_extension_attributes,
+ GINT_TO_POINTER (g_quark_from_string (attribute_name)),
+ g_strdup (value));
+ }
+ else
+ {
+ if (!file->details->extension_attributes)
+ {
+ file->details->extension_attributes =
+ g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL,
+ (GDestroyNotify) g_free);
+ }
+ g_hash_table_insert (file->details->extension_attributes,
+ GINT_TO_POINTER (g_quark_from_string (attribute_name)),
+ g_strdup (value));
+ }
+
+ nautilus_file_changed (file);
}
static void
nautilus_file_invalidate_extension_info (NautilusFile *file)
{
- nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO);
+ nautilus_file_invalidate_attributes (file, NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO);
}
void
nautilus_file_info_providers_done (NautilusFile *file)
{
- g_list_free_full (file->details->extension_emblems, g_free);
- file->details->extension_emblems = file->details->pending_extension_emblems;
- file->details->pending_extension_emblems = NULL;
+ g_list_free_full (file->details->extension_emblems, g_free);
+ file->details->extension_emblems = file->details->pending_extension_emblems;
+ file->details->pending_extension_emblems = NULL;
- if (file->details->extension_attributes) {
- g_hash_table_destroy (file->details->extension_attributes);
- }
-
- file->details->extension_attributes = file->details->pending_extension_attributes;
- file->details->pending_extension_attributes = NULL;
+ if (file->details->extension_attributes)
+ {
+ g_hash_table_destroy (file->details->extension_attributes);
+ }
- nautilus_file_changed (file);
+ file->details->extension_attributes = file->details->pending_extension_attributes;
+ file->details->pending_extension_attributes = NULL;
+
+ nautilus_file_changed (file);
}
/* DND */
@@ -8395,72 +9359,80 @@ nautilus_file_info_providers_done (NautilusFile *file)
static gboolean
nautilus_drag_can_accept_files (NautilusFile *drop_target_item)
{
- return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (drop_target_item))->drag_can_accept_files (drop_target_item);
+ return NAUTILUS_FILE_CLASS (G_OBJECT_GET_CLASS (drop_target_item))->drag_can_accept_files (drop_target_item);
}
static gboolean
real_drag_can_accept_files (NautilusFile *drop_target_item)
{
- if (nautilus_file_is_directory (drop_target_item)) {
- NautilusDirectory *directory;
- gboolean res;
+ if (nautilus_file_is_directory (drop_target_item))
+ {
+ NautilusDirectory *directory;
+ gboolean res;
- /* target is a directory, accept if editable */
- directory = nautilus_directory_get_for_file (drop_target_item);
- res = nautilus_directory_is_editable (directory) &&
- nautilus_file_can_write (drop_target_item);
- nautilus_directory_unref (directory);
- return res;
- }
+ /* target is a directory, accept if editable */
+ directory = nautilus_directory_get_for_file (drop_target_item);
+ res = nautilus_directory_is_editable (directory) &&
+ nautilus_file_can_write (drop_target_item);
+ nautilus_directory_unref (directory);
+ return res;
+ }
- /* Launchers are an acceptable drop target */
- if (nautilus_file_is_launcher (drop_target_item)) {
- return TRUE;
- }
+ /* Launchers are an acceptable drop target */
+ if (nautilus_file_is_launcher (drop_target_item))
+ {
+ return TRUE;
+ }
- if (nautilus_is_file_roller_installed () &&
- nautilus_file_is_archive (drop_target_item)) {
- return TRUE;
- }
+ if (nautilus_is_file_roller_installed () &&
+ nautilus_file_is_archive (drop_target_item))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
gboolean
nautilus_drag_can_accept_item (NautilusFile *drop_target_item,
const char *item_uri)
{
- if (nautilus_file_matches_uri (drop_target_item, item_uri)) {
- /* can't accept itself */
- return FALSE;
- }
+ if (nautilus_file_matches_uri (drop_target_item, item_uri))
+ {
+ /* can't accept itself */
+ return FALSE;
+ }
- return nautilus_drag_can_accept_files (drop_target_item);
+ return nautilus_drag_can_accept_files (drop_target_item);
}
gboolean
nautilus_drag_can_accept_items (NautilusFile *drop_target_item,
const GList *items)
{
- int max;
+ int max;
- if (drop_target_item == NULL)
- return FALSE;
-
- g_assert (NAUTILUS_IS_FILE (drop_target_item));
-
- /* Iterate through selection checking if item will get accepted by the
- * drop target. If more than 100 items selected, return an over-optimisic
- * result
- */
- for (max = 100; items != NULL && max >= 0; items = items->next, max--) {
- if (!nautilus_drag_can_accept_item (drop_target_item,
- ((NautilusDragSelectionItem *)items->data)->uri)) {
- return FALSE;
- }
- }
+ if (drop_target_item == NULL)
+ {
+ return FALSE;
+ }
+
+ g_assert (NAUTILUS_IS_FILE (drop_target_item));
+
+ /* Iterate through selection checking if item will get accepted by the
+ * drop target. If more than 100 items selected, return an over-optimisic
+ * result
+ */
+ for (max = 100; items != NULL && max >= 0; items = items->next, max--)
+ {
+ if (!nautilus_drag_can_accept_item (drop_target_item,
+ ((NautilusDragSelectionItem *) items->data)->uri))
+ {
+ return FALSE;
+ }
+ }
- return TRUE;
+ return TRUE;
}
gboolean
@@ -8468,50 +9440,59 @@ nautilus_drag_can_accept_info (NautilusFile *drop_target_item,
NautilusIconDndTargetType drag_type,
const GList *items)
{
- switch (drag_type) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
- return nautilus_drag_can_accept_items (drop_target_item, items);
-
- case NAUTILUS_ICON_DND_URI_LIST:
- case NAUTILUS_ICON_DND_NETSCAPE_URL:
- case NAUTILUS_ICON_DND_TEXT:
- return nautilus_drag_can_accept_files (drop_target_item);
-
- case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
- case NAUTILUS_ICON_DND_RAW:
- return nautilus_drag_can_accept_files (drop_target_item); /* Check if we can accept files at this location */
-
- case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
- return FALSE;
-
- default:
- g_assert_not_reached ();
- return FALSE;
- }
+ switch (drag_type)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ return nautilus_drag_can_accept_items (drop_target_item, items);
+ }
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ case NAUTILUS_ICON_DND_NETSCAPE_URL:
+ case NAUTILUS_ICON_DND_TEXT:
+ {
+ return nautilus_drag_can_accept_files (drop_target_item);
+ }
+
+ case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+ case NAUTILUS_ICON_DND_RAW:
+ {
+ return nautilus_drag_can_accept_files (drop_target_item); /* Check if we can accept files at this location */
+ }
+
+ case NAUTILUS_ICON_DND_ROOTWINDOW_DROP:
+ {
+ return FALSE;
+ }
+
+ default:
+ g_assert_not_reached ();
+ return FALSE;
+ }
}
static void
nautilus_file_info_iface_init (NautilusFileInfoIface *iface)
{
- iface->is_gone = nautilus_file_is_gone;
- iface->get_name = nautilus_file_get_name;
- iface->get_file_type = nautilus_file_get_file_type;
- iface->get_location = nautilus_file_get_location;
- iface->get_uri = nautilus_file_get_uri;
- iface->get_parent_location = nautilus_file_get_parent_location;
- iface->get_parent_uri = nautilus_file_get_parent_uri;
- iface->get_parent_info = nautilus_file_get_parent;
- iface->get_mount = nautilus_file_get_mount;
- iface->get_uri_scheme = nautilus_file_get_uri_scheme;
- iface->get_activation_uri = nautilus_file_get_activation_uri;
- iface->get_mime_type = nautilus_file_get_mime_type;
- iface->is_mime_type = nautilus_file_is_mime_type;
- iface->is_directory = nautilus_file_is_directory;
- iface->can_write = nautilus_file_can_write;
- iface->add_emblem = nautilus_file_add_emblem;
- iface->get_string_attribute = nautilus_file_get_string_attribute;
- iface->add_string_attribute = nautilus_file_add_string_attribute;
- iface->invalidate_extension_info = nautilus_file_invalidate_extension_info;
+ iface->is_gone = nautilus_file_is_gone;
+ iface->get_name = nautilus_file_get_name;
+ iface->get_file_type = nautilus_file_get_file_type;
+ iface->get_location = nautilus_file_get_location;
+ iface->get_uri = nautilus_file_get_uri;
+ iface->get_parent_location = nautilus_file_get_parent_location;
+ iface->get_parent_uri = nautilus_file_get_parent_uri;
+ iface->get_parent_info = nautilus_file_get_parent;
+ iface->get_mount = nautilus_file_get_mount;
+ iface->get_uri_scheme = nautilus_file_get_uri_scheme;
+ iface->get_activation_uri = nautilus_file_get_activation_uri;
+ iface->get_mime_type = nautilus_file_get_mime_type;
+ iface->is_mime_type = nautilus_file_is_mime_type;
+ iface->is_directory = nautilus_file_is_directory;
+ iface->can_write = nautilus_file_can_write;
+ iface->add_emblem = nautilus_file_add_emblem;
+ iface->get_string_attribute = nautilus_file_get_string_attribute;
+ iface->add_string_attribute = nautilus_file_add_string_attribute;
+ iface->invalidate_extension_info = nautilus_file_invalidate_extension_info;
}
#if !defined (NAUTILUS_OMIT_SELF_CHECK)
@@ -8519,91 +9500,91 @@ nautilus_file_info_iface_init (NautilusFileInfoIface *iface)
void
nautilus_self_check_file (void)
{
- NautilusFile *file_1;
- NautilusFile *file_2;
- GList *list;
+ NautilusFile *file_1;
+ NautilusFile *file_2;
+ GList *list;
+
+ /* refcount checks */
+
+ EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 0);
+
+ file_1 = nautilus_file_get_by_uri ("file:///home/");
+
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 1);
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1->details->directory)->ref_count, 1);
+ EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 1);
- /* refcount checks */
+ nautilus_file_unref (file_1);
- EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 0);
+ EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 0);
- file_1 = nautilus_file_get_by_uri ("file:///home/");
+ file_1 = nautilus_file_get_by_uri ("file:///etc");
+ file_2 = nautilus_file_get_by_uri ("file:///usr");
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 1);
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1->details->directory)->ref_count, 1);
- EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 1);
+ list = NULL;
+ list = g_list_prepend (list, file_1);
+ list = g_list_prepend (list, file_2);
- nautilus_file_unref (file_1);
+ nautilus_file_list_ref (list);
- EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 0);
-
- file_1 = nautilus_file_get_by_uri ("file:///etc");
- file_2 = nautilus_file_get_by_uri ("file:///usr");
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 2);
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_2)->ref_count, 2);
- list = NULL;
- list = g_list_prepend (list, file_1);
- list = g_list_prepend (list, file_2);
+ nautilus_file_list_unref (list);
- nautilus_file_list_ref (list);
-
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 2);
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_2)->ref_count, 2);
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 1);
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_2)->ref_count, 1);
- nautilus_file_list_unref (list);
-
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 1);
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_2)->ref_count, 1);
+ nautilus_file_list_free (list);
- nautilus_file_list_free (list);
+ EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 0);
- EEL_CHECK_INTEGER_RESULT (nautilus_directory_number_outstanding (), 0);
-
- /* name checks */
- file_1 = nautilus_file_get_by_uri ("file:///home/");
+ /* name checks */
+ file_1 = nautilus_file_get_by_uri ("file:///home/");
- EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
+ EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_by_uri ("file:///home/") == file_1, TRUE);
- nautilus_file_unref (file_1);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_by_uri ("file:///home/") == file_1, TRUE);
+ nautilus_file_unref (file_1);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_by_uri ("file:///home") == file_1, TRUE);
- nautilus_file_unref (file_1);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_get_by_uri ("file:///home") == file_1, TRUE);
+ nautilus_file_unref (file_1);
- nautilus_file_unref (file_1);
+ nautilus_file_unref (file_1);
- file_1 = nautilus_file_get_by_uri ("file:///home");
- EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
- nautilus_file_unref (file_1);
+ file_1 = nautilus_file_get_by_uri ("file:///home");
+ EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "home");
+ nautilus_file_unref (file_1);
- /* ALEX: I removed this, because it was breaking distchecks.
- * It used to work, but when canonical uris changed from
- * foo: to foo:/// it broke. I don't expect it to matter
- * in real life */
- file_1 = nautilus_file_get_by_uri (":");
- EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), ":");
- nautilus_file_unref (file_1);
+ /* ALEX: I removed this, because it was breaking distchecks.
+ * It used to work, but when canonical uris changed from
+ * foo: to foo:/// it broke. I don't expect it to matter
+ * in real life */
+ file_1 = nautilus_file_get_by_uri (":");
+ EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), ":");
+ nautilus_file_unref (file_1);
- file_1 = nautilus_file_get_by_uri ("eazel:");
- EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "eazel:///");
- nautilus_file_unref (file_1);
+ file_1 = nautilus_file_get_by_uri ("eazel:");
+ EEL_CHECK_STRING_RESULT (nautilus_file_get_name (file_1), "eazel:///");
+ nautilus_file_unref (file_1);
- /* sorting */
- file_1 = nautilus_file_get_by_uri ("file:///etc");
- file_2 = nautilus_file_get_by_uri ("file:///usr");
+ /* sorting */
+ file_1 = nautilus_file_get_by_uri ("file:///etc");
+ file_2 = nautilus_file_get_by_uri ("file:///usr");
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 1);
- EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_2)->ref_count, 1);
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_1)->ref_count, 1);
+ EEL_CHECK_INTEGER_RESULT (G_OBJECT (file_2)->ref_count, 1);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, FALSE) < 0, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, TRUE) > 0, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, FALSE) == 0, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, TRUE, FALSE) == 0, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, TRUE) == 0, TRUE);
- EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, TRUE, TRUE) == 0, TRUE);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, FALSE) < 0, TRUE);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_2, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, TRUE) > 0, TRUE);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, FALSE) == 0, TRUE);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, TRUE, FALSE) == 0, TRUE);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, FALSE, TRUE) == 0, TRUE);
+ EEL_CHECK_BOOLEAN_RESULT (nautilus_file_compare_for_sort (file_1, file_1, NAUTILUS_FILE_SORT_BY_DISPLAY_NAME, TRUE, TRUE) == 0, TRUE);
- nautilus_file_unref (file_1);
- nautilus_file_unref (file_2);
+ nautilus_file_unref (file_1);
+ nautilus_file_unref (file_2);
}
#endif /* !NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/nautilus-files-view-dnd.c b/src/nautilus-files-view-dnd.c
index eeba6631c..9f73624a5 100644
--- a/src/nautilus-files-view-dnd.c
+++ b/src/nautilus-files-view-dnd.c
@@ -1,4 +1,3 @@
-
/*
* nautilus-view-dnd.c: DnD helpers for NautilusFilesView
*
@@ -41,17 +40,18 @@
#include "nautilus-global-preferences.h"
#define GET_ANCESTOR(obj) \
- GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (obj), GTK_TYPE_WINDOW))
+ GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (obj), GTK_TYPE_WINDOW))
static inline void
view_widget_to_file_operation_position (NautilusFilesView *view,
GdkPoint *position)
{
- NautilusFilesViewClass *class = NAUTILUS_FILES_VIEW_GET_CLASS (view);
+ NautilusFilesViewClass *class = NAUTILUS_FILES_VIEW_GET_CLASS (view);
- if (class->widget_to_file_operation_position != NULL) {
- class->widget_to_file_operation_position (view, position);
- }
+ if (class->widget_to_file_operation_position != NULL)
+ {
+ class->widget_to_file_operation_position (view, position);
+ }
}
static void
@@ -59,32 +59,35 @@ view_widget_to_file_operation_position_xy (NautilusFilesView *view,
int *x,
int *y)
{
- GdkPoint position;
+ GdkPoint position;
- position.x = *x;
- position.y = *y;
- view_widget_to_file_operation_position (view, &position);
- *x = position.x;
- *y = position.y;
+ position.x = *x;
+ position.y = *y;
+ view_widget_to_file_operation_position (view, &position);
+ *x = position.x;
+ *y = position.y;
}
-typedef struct {
- NautilusFilesView *view;
- char *link_name;
- char *target_uri;
- char *url;
- GdkPoint point;
+typedef struct
+{
+ NautilusFilesView *view;
+ char *link_name;
+ char *target_uri;
+ char *url;
+ GdkPoint point;
} NetscapeUrlDropLink;
static void
revert_slashes (char *string)
{
- while (*string != 0) {
- if (*string == '/') {
- *string = '\\';
- }
- string++;
+ while (*string != 0)
+ {
+ if (*string == '/')
+ {
+ *string = '\\';
}
+ string++;
+ }
}
static void
@@ -92,62 +95,65 @@ handle_netscape_url_drop_link_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- NetscapeUrlDropLink *data = user_data;
- char *link_name = data->link_name;
- char *link_display_name;
- gint screen_num;
- GFileInfo *info;
- char *icon_name = NULL;
- GdkScreen *screen;
-
- info = g_file_query_info_finish (G_FILE (source_object),
- res, NULL);
-
- if (info != NULL) {
- GIcon *icon;
- const char * const *names;
-
- icon = g_file_info_get_icon (info);
-
- if (G_IS_THEMED_ICON (icon)) {
- names = g_themed_icon_get_names (G_THEMED_ICON (icon));
- icon_name = g_strdup (names[0]);
- }
-
- g_object_unref (info);
+ NetscapeUrlDropLink *data = user_data;
+ char *link_name = data->link_name;
+ char *link_display_name;
+ gint screen_num;
+ GFileInfo *info;
+ char *icon_name = NULL;
+ GdkScreen *screen;
+
+ info = g_file_query_info_finish (G_FILE (source_object),
+ res, NULL);
+
+ if (info != NULL)
+ {
+ GIcon *icon;
+ const char * const *names;
+
+ icon = g_file_info_get_icon (info);
+
+ if (G_IS_THEMED_ICON (icon))
+ {
+ names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+ icon_name = g_strdup (names[0]);
}
- if (icon_name == NULL) {
- icon_name = g_strdup ("text-html");
- }
+ g_object_unref (info);
+ }
- link_display_name = g_strdup_printf (_("Link to %s"), link_name);
+ if (icon_name == NULL)
+ {
+ icon_name = g_strdup ("text-html");
+ }
- /* The filename can't contain slashes, strip em.
- (the basename of http://foo/ is http://foo/) */
- revert_slashes (link_name);
+ link_display_name = g_strdup_printf (_("Link to %s"), link_name);
- screen = gtk_widget_get_screen (GTK_WIDGET (data->view));
- screen_num = gdk_screen_get_number (screen);
+ /* The filename can't contain slashes, strip em.
+ * (the basename of http://foo/ is http://foo/) */
+ revert_slashes (link_name);
- nautilus_link_local_create (data->target_uri,
- link_name,
- link_display_name,
- icon_name,
- data->url,
- &data->point,
- screen_num,
- TRUE);
+ screen = gtk_widget_get_screen (GTK_WIDGET (data->view));
+ screen_num = gdk_screen_get_number (screen);
- g_free (link_display_name);
- g_free (icon_name);
+ nautilus_link_local_create (data->target_uri,
+ link_name,
+ link_display_name,
+ icon_name,
+ data->url,
+ &data->point,
+ screen_num,
+ TRUE);
- g_free (data->url);
- g_free (data->link_name);
- g_free (data->target_uri);
+ g_free (link_display_name);
+ g_free (icon_name);
- g_object_unref (data->view);
- g_slice_free (NetscapeUrlDropLink, data);
+ g_free (data->url);
+ g_free (data->link_name);
+ g_free (data->target_uri);
+
+ g_object_unref (data->view);
+ g_slice_free (NetscapeUrlDropLink, data);
}
void
@@ -158,99 +164,115 @@ nautilus_files_view_handle_netscape_url_drop (NautilusFilesView *view,
int x,
int y)
{
- char *url, *title;
- char *link_name;
- GArray *points;
- char **bits;
- GList *uri_list = NULL;
- GFile *f;
-
- f = g_file_new_for_uri (target_uri);
-
- if (!g_file_is_native (f)) {
- eel_show_warning_dialog (_("Drag and drop is not supported."),
- _("Drag and drop is only supported on local file systems."),
- GET_ANCESTOR (view));
- g_object_unref (f);
- return;
- }
-
+ char *url, *title;
+ char *link_name;
+ GArray *points;
+ char **bits;
+ GList *uri_list = NULL;
+ GFile *f;
+
+ f = g_file_new_for_uri (target_uri);
+
+ if (!g_file_is_native (f))
+ {
+ eel_show_warning_dialog (_("Drag and drop is not supported."),
+ _("Drag and drop is only supported on local file systems."),
+ GET_ANCESTOR (view));
g_object_unref (f);
+ return;
+ }
- /* _NETSCAPE_URL_ works like this: $URL\n$TITLE */
- bits = g_strsplit (encoded_url, "\n", 0);
- switch (g_strv_length (bits)) {
+ g_object_unref (f);
+
+ /* _NETSCAPE_URL_ works like this: $URL\n$TITLE */
+ bits = g_strsplit (encoded_url, "\n", 0);
+ switch (g_strv_length (bits))
+ {
case 0:
- g_strfreev (bits);
- return;
+ {
+ g_strfreev (bits);
+ return;
+ }
+
case 1:
- url = bits[0];
- title = NULL;
- break;
+ {
+ url = bits[0];
+ title = NULL;
+ }
+ break;
+
default:
- url = bits[0];
- title = bits[1];
+ url = bits[0];
+ title = bits[1];
+ }
+
+ f = g_file_new_for_uri (url);
+
+ view_widget_to_file_operation_position_xy (view, &x, &y);
+
+ /* We don't support GDK_ACTION_ASK or GDK_ACTION_PRIVATE
+ * and we don't support combinations either. */
+ if ((action != GDK_ACTION_DEFAULT) &&
+ (action != GDK_ACTION_COPY) &&
+ (action != GDK_ACTION_MOVE) &&
+ (action != GDK_ACTION_LINK))
+ {
+ eel_show_warning_dialog (_("Drag and drop is not supported."),
+ _("An invalid drag type was used."),
+ GET_ANCESTOR (view));
+ return;
+ }
+
+ if (action == GDK_ACTION_LINK)
+ {
+ if (g_strcmp0 (title, NULL) == 0)
+ {
+ link_name = g_file_get_basename (f);
+ }
+ else
+ {
+ link_name = g_strdup (title);
}
- f = g_file_new_for_uri (url);
+ if (g_strcmp0 (link_name, NULL) != 0)
+ {
+ NetscapeUrlDropLink *data;
+
+ data = g_slice_new0 (NetscapeUrlDropLink);
+ data->link_name = link_name;
+ data->point.x = x;
+ data->point.y = y;
+ data->view = g_object_ref (view);
+ data->target_uri = g_strdup (target_uri);
+ data->url = g_strdup (url);
+
+ g_file_query_info_async (f,
+ G_FILE_ATTRIBUTE_STANDARD_ICON,
+ 0, 0, NULL,
+ handle_netscape_url_drop_link_cb,
+ data);
+ }
+ }
+ else
+ {
+ GdkPoint tmp_point = { 0, 0 };
- view_widget_to_file_operation_position_xy (view, &x, &y);
+ /* pass in a 1-item array of icon positions, relative to x, y */
+ points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
+ g_array_append_val (points, tmp_point);
- /* We don't support GDK_ACTION_ASK or GDK_ACTION_PRIVATE
- * and we don't support combinations either. */
- if ((action != GDK_ACTION_DEFAULT) &&
- (action != GDK_ACTION_COPY) &&
- (action != GDK_ACTION_MOVE) &&
- (action != GDK_ACTION_LINK)) {
- eel_show_warning_dialog (_("Drag and drop is not supported."),
- _("An invalid drag type was used."),
- GET_ANCESTOR (view));
- return;
- }
+ uri_list = g_list_append (uri_list, url);
- if (action == GDK_ACTION_LINK) {
- if (g_strcmp0 (title, NULL) == 0) {
- link_name = g_file_get_basename (f);
- } else {
- link_name = g_strdup (title);
- }
-
- if (g_strcmp0 (link_name, NULL) != 0) {
- NetscapeUrlDropLink *data;
-
- data = g_slice_new0 (NetscapeUrlDropLink);
- data->link_name = link_name;
- data->point.x = x;
- data->point.y = y;
- data->view = g_object_ref (view);
- data->target_uri = g_strdup (target_uri);
- data->url = g_strdup (url);
-
- g_file_query_info_async (f,
- G_FILE_ATTRIBUTE_STANDARD_ICON,
- 0, 0, NULL,
- handle_netscape_url_drop_link_cb,
- data);
- }
- } else {
- GdkPoint tmp_point = { 0, 0 };
-
- /* pass in a 1-item array of icon positions, relative to x, y */
- points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
- g_array_append_val (points, tmp_point);
-
- uri_list = g_list_append (uri_list, url);
-
- nautilus_files_view_move_copy_items (view, uri_list, points,
- target_uri,
- action, x, y);
-
- g_list_free (uri_list);
- g_array_free (points, TRUE);
- }
+ nautilus_files_view_move_copy_items (view, uri_list, points,
+ target_uri,
+ action, x, y);
- g_object_unref (f);
- g_strfreev (bits);
+ g_list_free (uri_list);
+ g_array_free (points, TRUE);
+ }
+
+ g_object_unref (f);
+ g_strfreev (bits);
}
void
@@ -261,81 +283,93 @@ nautilus_files_view_handle_uri_list_drop (NautilusFilesView *view,
int x,
int y)
{
- gchar **uri_list;
- GList *real_uri_list = NULL;
- char *container_uri;
- int n_uris, i;
- GArray *points;
-
- if (item_uris == NULL) {
- return;
- }
-
- container_uri = NULL;
- if (target_uri == NULL) {
- container_uri = nautilus_files_view_get_backing_uri (view);
- g_assert (container_uri != NULL);
- }
-
- if (action == GDK_ACTION_ASK) {
- action = nautilus_drag_drop_action_ask
- (GTK_WIDGET (view),
- GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
- if (action == 0) {
- g_free (container_uri);
- return;
- }
- }
-
- /* We don't support GDK_ACTION_ASK or GDK_ACTION_PRIVATE
- * and we don't support combinations either. */
- if ((action != GDK_ACTION_DEFAULT) &&
- (action != GDK_ACTION_COPY) &&
- (action != GDK_ACTION_MOVE) &&
- (action != GDK_ACTION_LINK)) {
- eel_show_warning_dialog (_("Drag and drop is not supported."),
- _("An invalid drag type was used."),
- GET_ANCESTOR (view));
- g_free (container_uri);
- return;
- }
-
- n_uris = 0;
- uri_list = g_uri_list_extract_uris (item_uris);
- for (i = 0; uri_list[i] != NULL; i++) {
- real_uri_list = g_list_append (real_uri_list, uri_list[i]);
- n_uris++;
- }
- g_free (uri_list);
-
- /* do nothing if no real uris are left */
- if (n_uris == 0) {
- g_free (container_uri);
- return;
+ gchar **uri_list;
+ GList *real_uri_list = NULL;
+ char *container_uri;
+ int n_uris, i;
+ GArray *points;
+
+ if (item_uris == NULL)
+ {
+ return;
+ }
+
+ container_uri = NULL;
+ if (target_uri == NULL)
+ {
+ container_uri = nautilus_files_view_get_backing_uri (view);
+ g_assert (container_uri != NULL);
+ }
+
+ if (action == GDK_ACTION_ASK)
+ {
+ action = nautilus_drag_drop_action_ask
+ (GTK_WIDGET (view),
+ GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
+ if (action == 0)
+ {
+ g_free (container_uri);
+ return;
}
+ }
+
+ /* We don't support GDK_ACTION_ASK or GDK_ACTION_PRIVATE
+ * and we don't support combinations either. */
+ if ((action != GDK_ACTION_DEFAULT) &&
+ (action != GDK_ACTION_COPY) &&
+ (action != GDK_ACTION_MOVE) &&
+ (action != GDK_ACTION_LINK))
+ {
+ eel_show_warning_dialog (_("Drag and drop is not supported."),
+ _("An invalid drag type was used."),
+ GET_ANCESTOR (view));
+ g_free (container_uri);
+ return;
+ }
+
+ n_uris = 0;
+ uri_list = g_uri_list_extract_uris (item_uris);
+ for (i = 0; uri_list[i] != NULL; i++)
+ {
+ real_uri_list = g_list_append (real_uri_list, uri_list[i]);
+ n_uris++;
+ }
+ g_free (uri_list);
+
+ /* do nothing if no real uris are left */
+ if (n_uris == 0)
+ {
+ g_free (container_uri);
+ return;
+ }
- if (n_uris == 1) {
- GdkPoint tmp_point = { 0, 0 };
+ if (n_uris == 1)
+ {
+ GdkPoint tmp_point = { 0, 0 };
- /* pass in a 1-item array of icon positions, relative to x, y */
- points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
- g_array_append_val (points, tmp_point);
- } else {
- points = NULL;
- }
+ /* pass in a 1-item array of icon positions, relative to x, y */
+ points = g_array_new (FALSE, TRUE, sizeof (GdkPoint));
+ g_array_append_val (points, tmp_point);
+ }
+ else
+ {
+ points = NULL;
+ }
- view_widget_to_file_operation_position_xy (view, &x, &y);
+ view_widget_to_file_operation_position_xy (view, &x, &y);
- nautilus_files_view_move_copy_items (view, real_uri_list, points,
- target_uri != NULL ? target_uri : container_uri,
- action, x, y);
+ nautilus_files_view_move_copy_items (view, real_uri_list, points,
+ target_uri != NULL ? target_uri : container_uri,
+ action, x, y);
- g_list_free_full (real_uri_list, g_free);
+ g_list_free_full (real_uri_list, g_free);
- if (points != NULL)
- g_array_free (points, TRUE);
+ if (points != NULL)
+ {
+ g_array_free (points, TRUE);
+ }
- g_free (container_uri);
+ g_free (container_uri);
}
#define MAX_LEN_FILENAME 128
@@ -344,56 +378,72 @@ nautilus_files_view_handle_uri_list_drop (NautilusFilesView *view,
static char *
get_drop_filename (const char *text)
{
- char *filename;
- char trimmed[MAX_LEN_FILENAME];
- int i;
- int last_word = -1;
- int last_sentence = -1;
- int last_nonspace = -1;
- int num_attrs;
- PangoLogAttr *attrs;
- gchar *current_char;
-
- num_attrs = MIN (g_utf8_strlen (text, -1), MAX_LEN_FILENAME) + 1;
- attrs = g_new (PangoLogAttr, num_attrs);
- g_utf8_strncpy (trimmed, text, num_attrs - 1);
- pango_get_log_attrs (trimmed, -1, -1, pango_language_get_default (), attrs, num_attrs);
-
- /* since the end of the text will always match a word boundary don't include it */
- for (i = 0; (i < num_attrs - 1); i++) {
- if (!attrs[i].is_white)
- last_nonspace = i;
- if (attrs[i].is_sentence_end)
- last_sentence = last_nonspace;
- if (attrs[i].is_word_boundary)
- last_word = last_nonspace;
+ char *filename;
+ char trimmed[MAX_LEN_FILENAME];
+ int i;
+ int last_word = -1;
+ int last_sentence = -1;
+ int last_nonspace = -1;
+ int num_attrs;
+ PangoLogAttr *attrs;
+ gchar *current_char;
+
+ num_attrs = MIN (g_utf8_strlen (text, -1), MAX_LEN_FILENAME) + 1;
+ attrs = g_new (PangoLogAttr, num_attrs);
+ g_utf8_strncpy (trimmed, text, num_attrs - 1);
+ pango_get_log_attrs (trimmed, -1, -1, pango_language_get_default (), attrs, num_attrs);
+
+ /* since the end of the text will always match a word boundary don't include it */
+ for (i = 0; (i < num_attrs - 1); i++)
+ {
+ if (!attrs[i].is_white)
+ {
+ last_nonspace = i;
}
- g_free (attrs);
-
- if (last_sentence > 0)
- i = last_sentence;
- else
- i = last_word;
-
- if (i > MIN_LEN_FILENAME) {
- char basename[MAX_LEN_FILENAME];
- g_utf8_strncpy (basename, trimmed, i);
- filename = g_strdup_printf ("%s.txt", basename);
- } else {
- /* Translator: This is the filename used for when you dnd text to a directory */
- filename = g_strdup (_("Dropped Text.txt"));
+ if (attrs[i].is_sentence_end)
+ {
+ last_sentence = last_nonspace;
}
-
- /* Remove any invalid characters */
- for (current_char = filename;
- *current_char;
- current_char = g_utf8_next_char (current_char)) {
- if ( G_IS_DIR_SEPARATOR ( g_utf8_get_char (current_char))) {
- *current_char = '-';
- }
+ if (attrs[i].is_word_boundary)
+ {
+ last_word = last_nonspace;
+ }
+ }
+ g_free (attrs);
+
+ if (last_sentence > 0)
+ {
+ i = last_sentence;
+ }
+ else
+ {
+ i = last_word;
+ }
+
+ if (i > MIN_LEN_FILENAME)
+ {
+ char basename[MAX_LEN_FILENAME];
+ g_utf8_strncpy (basename, trimmed, i);
+ filename = g_strdup_printf ("%s.txt", basename);
+ }
+ else
+ {
+ /* Translator: This is the filename used for when you dnd text to a directory */
+ filename = g_strdup (_("Dropped Text.txt"));
+ }
+
+ /* Remove any invalid characters */
+ for (current_char = filename;
+ *current_char;
+ current_char = g_utf8_next_char (current_char))
+ {
+ if (G_IS_DIR_SEPARATOR (g_utf8_get_char (current_char)))
+ {
+ *current_char = '-';
}
+ }
- return filename;
+ return filename;
}
void
@@ -404,40 +454,42 @@ nautilus_files_view_handle_text_drop (NautilusFilesView *view,
int x,
int y)
{
- int length;
- char *container_uri;
- GdkPoint pos;
- char *filename;
-
- if (text == NULL) {
- return;
- }
-
- g_return_if_fail (action == GDK_ACTION_COPY);
-
- container_uri = NULL;
- if (target_uri == NULL) {
- container_uri = nautilus_files_view_get_backing_uri (view);
- g_assert (container_uri != NULL);
- }
-
- length = strlen (text);
-
- pos.x = x;
- pos.y = y;
- view_widget_to_file_operation_position (view, &pos);
-
- /* try to get text to use as a filename */
- filename = get_drop_filename (text);
-
- nautilus_files_view_new_file_with_initial_contents (view,
- target_uri != NULL ? target_uri : container_uri,
- filename,
- text,
- length,
- &pos);
- g_free (filename);
- g_free (container_uri);
+ int length;
+ char *container_uri;
+ GdkPoint pos;
+ char *filename;
+
+ if (text == NULL)
+ {
+ return;
+ }
+
+ g_return_if_fail (action == GDK_ACTION_COPY);
+
+ container_uri = NULL;
+ if (target_uri == NULL)
+ {
+ container_uri = nautilus_files_view_get_backing_uri (view);
+ g_assert (container_uri != NULL);
+ }
+
+ length = strlen (text);
+
+ pos.x = x;
+ pos.y = y;
+ view_widget_to_file_operation_position (view, &pos);
+
+ /* try to get text to use as a filename */
+ filename = get_drop_filename (text);
+
+ nautilus_files_view_new_file_with_initial_contents (view,
+ target_uri != NULL ? target_uri : container_uri,
+ filename,
+ text,
+ length,
+ &pos);
+ g_free (filename);
+ g_free (container_uri);
}
void
@@ -450,44 +502,48 @@ nautilus_files_view_handle_raw_drop (NautilusFilesView *view,
int x,
int y)
{
- char *container_uri, *filename;
- GFile *direct_save_full;
- GdkPoint pos;
-
- if (raw_data == NULL) {
- return;
- }
-
- g_return_if_fail (action == GDK_ACTION_COPY);
-
- container_uri = NULL;
- if (target_uri == NULL) {
- container_uri = nautilus_files_view_get_backing_uri (view);
- g_assert (container_uri != NULL);
- }
-
- pos.x = x;
- pos.y = y;
- view_widget_to_file_operation_position (view, &pos);
-
- filename = NULL;
- if (direct_save_uri != NULL) {
- direct_save_full = g_file_new_for_uri (direct_save_uri);
- filename = g_file_get_basename (direct_save_full);
- }
- if (filename == NULL) {
- /* Translator: This is the filename used for when you dnd raw
- * data to a directory, if the source didn't supply a name.
- */
- filename = g_strdup (_("dropped data"));
- }
-
- nautilus_files_view_new_file_with_initial_contents (
- view, target_uri != NULL ? target_uri : container_uri,
- filename, raw_data, length, &pos);
-
- g_free (container_uri);
- g_free (filename);
+ char *container_uri, *filename;
+ GFile *direct_save_full;
+ GdkPoint pos;
+
+ if (raw_data == NULL)
+ {
+ return;
+ }
+
+ g_return_if_fail (action == GDK_ACTION_COPY);
+
+ container_uri = NULL;
+ if (target_uri == NULL)
+ {
+ container_uri = nautilus_files_view_get_backing_uri (view);
+ g_assert (container_uri != NULL);
+ }
+
+ pos.x = x;
+ pos.y = y;
+ view_widget_to_file_operation_position (view, &pos);
+
+ filename = NULL;
+ if (direct_save_uri != NULL)
+ {
+ direct_save_full = g_file_new_for_uri (direct_save_uri);
+ filename = g_file_get_basename (direct_save_full);
+ }
+ if (filename == NULL)
+ {
+ /* Translator: This is the filename used for when you dnd raw
+ * data to a directory, if the source didn't supply a name.
+ */
+ filename = g_strdup (_("dropped data"));
+ }
+
+ nautilus_files_view_new_file_with_initial_contents (
+ view, target_uri != NULL ? target_uri : container_uri,
+ filename, raw_data, length, &pos);
+
+ g_free (container_uri);
+ g_free (filename);
}
void
@@ -496,60 +552,64 @@ nautilus_files_view_drop_proxy_received_uris (NautilusFilesView *view,
const char *target_uri,
GdkDragAction action)
{
- char *container_uri;
-
- container_uri = NULL;
- if (target_uri == NULL) {
- container_uri = nautilus_files_view_get_backing_uri (view);
- g_assert (container_uri != NULL);
+ char *container_uri;
+
+ container_uri = NULL;
+ if (target_uri == NULL)
+ {
+ container_uri = nautilus_files_view_get_backing_uri (view);
+ g_assert (container_uri != NULL);
+ }
+
+ if (action == GDK_ACTION_ASK)
+ {
+ action = nautilus_drag_drop_action_ask
+ (GTK_WIDGET (view),
+ GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
+ if (action == 0)
+ {
+ return;
}
+ }
- if (action == GDK_ACTION_ASK) {
- action = nautilus_drag_drop_action_ask
- (GTK_WIDGET (view),
- GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
- if (action == 0) {
- return;
- }
- }
-
- nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
- source_uri_list,
- nautilus_files_view_get_copied_files_atom (view));
+ nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
+ source_uri_list,
+ nautilus_files_view_get_copied_files_atom (view));
- nautilus_files_view_move_copy_items (view, source_uri_list, NULL,
- target_uri != NULL ? target_uri : container_uri,
- action, 0, 0);
+ nautilus_files_view_move_copy_items (view, source_uri_list, NULL,
+ target_uri != NULL ? target_uri : container_uri,
+ action, 0, 0);
- g_free (container_uri);
+ g_free (container_uri);
}
void
nautilus_files_view_handle_hover (NautilusFilesView *view,
const char *target_uri)
{
- NautilusWindowSlot *slot;
- GFile *location;
- GFile *current_location;
- NautilusFile *target_file;
- gboolean target_is_dir;
- gboolean open_folder_on_hover;
-
- slot = nautilus_files_view_get_nautilus_window_slot (view);
-
- location = g_file_new_for_uri (target_uri);
- target_file = nautilus_file_get_existing (location);
- target_is_dir = nautilus_file_get_file_type (target_file) == G_FILE_TYPE_DIRECTORY;
- current_location = nautilus_window_slot_get_location (slot);
- open_folder_on_hover = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_OPEN_FOLDER_ON_DND_HOVER);
-
- if (target_is_dir && open_folder_on_hover &&
- !(current_location != NULL && g_file_equal(location, current_location))) {
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location, NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
- NULL, NULL, slot);
- }
- g_object_unref (location);
- nautilus_file_unref (target_file);
+ NautilusWindowSlot *slot;
+ GFile *location;
+ GFile *current_location;
+ NautilusFile *target_file;
+ gboolean target_is_dir;
+ gboolean open_folder_on_hover;
+
+ slot = nautilus_files_view_get_nautilus_window_slot (view);
+
+ location = g_file_new_for_uri (target_uri);
+ target_file = nautilus_file_get_existing (location);
+ target_is_dir = nautilus_file_get_file_type (target_file) == G_FILE_TYPE_DIRECTORY;
+ current_location = nautilus_window_slot_get_location (slot);
+ open_folder_on_hover = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_OPEN_FOLDER_ON_DND_HOVER);
+
+ if (target_is_dir && open_folder_on_hover &&
+ !(current_location != NULL && g_file_equal (location, current_location)))
+ {
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location, NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
+ NULL, NULL, slot);
+ }
+ g_object_unref (location);
+ nautilus_file_unref (target_file);
}
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index b1acfe845..73c88a17c 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -130,31 +130,33 @@
#define MIN_COMMON_FILENAME_PREFIX_LENGTH 4
-enum {
- ADD_FILE,
- BEGIN_FILE_CHANGES,
- BEGIN_LOADING,
- CLEAR,
- END_FILE_CHANGES,
- END_LOADING,
- FILE_CHANGED,
- MOVE_COPY_ITEMS,
- REMOVE_FILE,
- SELECTION_CHANGED,
- TRASH,
- DELETE,
- LAST_SIGNAL
+enum
+{
+ ADD_FILE,
+ BEGIN_FILE_CHANGES,
+ BEGIN_LOADING,
+ CLEAR,
+ END_FILE_CHANGES,
+ END_LOADING,
+ FILE_CHANGED,
+ MOVE_COPY_ITEMS,
+ REMOVE_FILE,
+ SELECTION_CHANGED,
+ TRASH,
+ DELETE,
+ LAST_SIGNAL
};
-enum {
- PROP_WINDOW_SLOT = 1,
- PROP_SUPPORTS_ZOOMING,
- PROP_ICON,
- PROP_IS_SEARCH,
- PROP_IS_LOADING,
- PROP_LOCATION,
- PROP_SEARCH_QUERY,
- NUM_PROPERTIES
+enum
+{
+ PROP_WINDOW_SLOT = 1,
+ PROP_SUPPORTS_ZOOMING,
+ PROP_ICON,
+ PROP_IS_SEARCH,
+ PROP_IS_LOADING,
+ PROP_LOCATION,
+ PROP_SEARCH_QUERY,
+ NUM_PROPERTIES
};
static guint signals[LAST_SIGNAL];
@@ -168,185 +170,188 @@ static GHashTable *script_accels = NULL;
struct NautilusFilesViewDetails
{
- /* Main components */
- GtkWidget *overlay;
+ /* Main components */
+ GtkWidget *overlay;
- NautilusWindowSlot *slot;
- NautilusDirectory *model;
- NautilusFile *directory_as_file;
- GFile *location;
- guint dir_merge_id;
+ NautilusWindowSlot *slot;
+ NautilusDirectory *model;
+ NautilusFile *directory_as_file;
+ GFile *location;
+ guint dir_merge_id;
- NautilusQuery *search_query;
+ NautilusQuery *search_query;
- NautilusRenameFilePopoverController *rename_file_controller;
- NautilusNewFolderDialogController *new_folder_controller;
- NautilusCompressDialogController *compress_controller;
+ NautilusRenameFilePopoverController *rename_file_controller;
+ NautilusNewFolderDialogController *new_folder_controller;
+ NautilusCompressDialogController *compress_controller;
- gboolean supports_zooming;
+ gboolean supports_zooming;
- GList *scripts_directory_list;
- GList *templates_directory_list;
+ GList *scripts_directory_list;
+ GList *templates_directory_list;
- guint display_selection_idle_id;
- guint update_context_menus_timeout_id;
- guint update_status_idle_id;
- guint reveal_selection_idle_id;
+ guint display_selection_idle_id;
+ guint update_context_menus_timeout_id;
+ guint update_status_idle_id;
+ guint reveal_selection_idle_id;
- guint display_pending_source_id;
- guint changes_timeout_id;
+ guint display_pending_source_id;
+ guint changes_timeout_id;
- guint update_interval;
- guint64 last_queued;
+ guint update_interval;
+ guint64 last_queued;
- guint files_added_handler_id;
- guint files_changed_handler_id;
- guint load_error_handler_id;
- guint done_loading_handler_id;
- guint file_changed_handler_id;
+ guint files_added_handler_id;
+ guint files_changed_handler_id;
+ guint load_error_handler_id;
+ guint done_loading_handler_id;
+ guint file_changed_handler_id;
- GList *new_added_files;
- GList *new_changed_files;
+ GList *new_added_files;
+ GList *new_changed_files;
- GHashTable *non_ready_files;
+ GHashTable *non_ready_files;
- GList *old_added_files;
- GList *old_changed_files;
+ GList *old_added_files;
+ GList *old_changed_files;
- GList *pending_selection;
- GHashTable *pending_reveal;
+ GList *pending_selection;
+ GHashTable *pending_reveal;
- /* whether we are in the active slot */
- gboolean active;
+ /* whether we are in the active slot */
+ gboolean active;
- /* loading indicates whether this view has begun loading a directory.
- * This flag should need not be set inside subclasses. NautilusFilesView automatically
- * sets 'loading' to TRUE before it begins loading a directory's contents and to FALSE
- * after it finishes loading the directory and its view.
- */
- gboolean loading;
- gboolean templates_present;
- gboolean scripts_present;
+ /* loading indicates whether this view has begun loading a directory.
+ * This flag should need not be set inside subclasses. NautilusFilesView automatically
+ * sets 'loading' to TRUE before it begins loading a directory's contents and to FALSE
+ * after it finishes loading the directory and its view.
+ */
+ gboolean loading;
+ gboolean templates_present;
+ gboolean scripts_present;
- gboolean in_destruction;
+ gboolean in_destruction;
- gboolean sort_directories_first;
+ gboolean sort_directories_first;
- gboolean show_foreign_files;
- gboolean show_hidden_files;
- gboolean ignore_hidden_file_preferences;
+ gboolean show_foreign_files;
+ gboolean show_hidden_files;
+ gboolean ignore_hidden_file_preferences;
- gboolean batching_selection_level;
- gboolean selection_changed_while_batched;
+ gboolean batching_selection_level;
+ gboolean selection_changed_while_batched;
- gboolean selection_was_removed;
+ gboolean selection_was_removed;
- gboolean metadata_for_directory_as_file_pending;
- gboolean metadata_for_files_in_directory_pending;
+ gboolean metadata_for_directory_as_file_pending;
+ gboolean metadata_for_files_in_directory_pending;
- GList *subdirectory_list;
+ GList *subdirectory_list;
- GdkPoint context_menu_position;
+ GdkPoint context_menu_position;
- GMenu *selection_menu;
- GMenu *background_menu;
+ GMenu *selection_menu;
+ GMenu *background_menu;
- GActionGroup *view_action_group;
+ GActionGroup *view_action_group;
- GtkWidget *scrolled_window;
+ GtkWidget *scrolled_window;
- /* Empty states */
- GtkWidget *folder_is_empty_widget;
- GtkWidget *no_search_results_widget;
+ /* Empty states */
+ GtkWidget *folder_is_empty_widget;
+ GtkWidget *no_search_results_widget;
- /* Floating bar */
- guint floating_bar_set_status_timeout_id;
- guint floating_bar_loading_timeout_id;
- GtkWidget *floating_bar;
+ /* Floating bar */
+ guint floating_bar_set_status_timeout_id;
+ guint floating_bar_loading_timeout_id;
+ GtkWidget *floating_bar;
- /* Toolbar menu */
- NautilusToolbarMenuSections *toolbar_menu_sections;
- GtkWidget *sort_menu;
- GtkWidget *sort_trash_time;
- GtkWidget *visible_columns;
- GtkWidget *stop;
- GtkWidget *reload;
- GtkWidget *zoom_controls_box;
- GtkWidget *zoom_level_label;
+ /* Toolbar menu */
+ NautilusToolbarMenuSections *toolbar_menu_sections;
+ GtkWidget *sort_menu;
+ GtkWidget *sort_trash_time;
+ GtkWidget *visible_columns;
+ GtkWidget *stop;
+ GtkWidget *reload;
+ GtkWidget *zoom_controls_box;
+ GtkWidget *zoom_level_label;
- gulong stop_signal_handler;
- gulong reload_signal_handler;
+ gulong stop_signal_handler;
+ gulong reload_signal_handler;
};
-typedef struct {
- NautilusFile *file;
- NautilusDirectory *directory;
+typedef struct
+{
+ NautilusFile *file;
+ NautilusDirectory *directory;
} FileAndDirectory;
/* forward declarations */
-static gboolean display_selection_info_idle_callback (gpointer data);
-static void trash_or_delete_files (GtkWindow *parent_window,
- const GList *files,
- NautilusFilesView *view);
-static void load_directory (NautilusFilesView *view,
- NautilusDirectory *directory);
-static void clipboard_changed_callback (NautilusClipboardMonitor *monitor,
- NautilusFilesView *view);
-static void open_one_in_new_window (gpointer data,
- gpointer callback_data);
-static void schedule_update_context_menus (NautilusFilesView *view);
-static void remove_update_context_menus_timeout_callback (NautilusFilesView *view);
-static void schedule_update_status (NautilusFilesView *view);
-static void remove_update_status_idle_callback (NautilusFilesView *view);
-static void reset_update_interval (NautilusFilesView *view);
-static void schedule_idle_display_of_pending_files (NautilusFilesView *view);
-static void unschedule_display_of_pending_files (NautilusFilesView *view);
-static void disconnect_model_handlers (NautilusFilesView *view);
-static void metadata_for_directory_as_file_ready_callback (NautilusFile *file,
- gpointer callback_data);
-static void metadata_for_files_in_directory_ready_callback (NautilusDirectory *directory,
- GList *files,
- gpointer callback_data);
-static void nautilus_files_view_trash_state_changed_callback (NautilusTrashMonitor *trash,
- gboolean state,
- gpointer callback_data);
-static void nautilus_files_view_select_file (NautilusFilesView *view,
- NautilusFile *file);
-
-static void update_templates_directory (NautilusFilesView *view);
-
-static void extract_files (NautilusFilesView *view,
+static gboolean display_selection_info_idle_callback (gpointer data);
+static void trash_or_delete_files (GtkWindow *parent_window,
+ const GList *files,
+ NautilusFilesView *view);
+static void load_directory (NautilusFilesView *view,
+ NautilusDirectory *directory);
+static void clipboard_changed_callback (NautilusClipboardMonitor *monitor,
+ NautilusFilesView *view);
+static void open_one_in_new_window (gpointer data,
+ gpointer callback_data);
+static void schedule_update_context_menus (NautilusFilesView *view);
+static void remove_update_context_menus_timeout_callback (NautilusFilesView *view);
+static void schedule_update_status (NautilusFilesView *view);
+static void remove_update_status_idle_callback (NautilusFilesView *view);
+static void reset_update_interval (NautilusFilesView *view);
+static void schedule_idle_display_of_pending_files (NautilusFilesView *view);
+static void unschedule_display_of_pending_files (NautilusFilesView *view);
+static void disconnect_model_handlers (NautilusFilesView *view);
+static void metadata_for_directory_as_file_ready_callback (NautilusFile *file,
+ gpointer callback_data);
+static void metadata_for_files_in_directory_ready_callback (NautilusDirectory *directory,
GList *files,
- GFile *destination_directory);
-static void extract_files_to_chosen_location (NautilusFilesView *view,
- GList *files);
+ gpointer callback_data);
+static void nautilus_files_view_trash_state_changed_callback (NautilusTrashMonitor *trash,
+ gboolean state,
+ gpointer callback_data);
+static void nautilus_files_view_select_file (NautilusFilesView *view,
+ NautilusFile *file);
+
+static void update_templates_directory (NautilusFilesView *view);
+
+static void extract_files (NautilusFilesView *view,
+ GList *files,
+ GFile *destination_directory);
+static void extract_files_to_chosen_location (NautilusFilesView *view,
+ GList *files);
-static void nautilus_files_view_check_empty_states (NautilusFilesView *view);
+static void nautilus_files_view_check_empty_states (NautilusFilesView *view);
-static gboolean nautilus_files_view_is_searching (NautilusView *view);
+static gboolean nautilus_files_view_is_searching (NautilusView *view);
-static void nautilus_files_view_iface_init (NautilusViewInterface *view);
+static void nautilus_files_view_iface_init (NautilusViewInterface *view);
-static void set_search_query_internal (NautilusFilesView *files_view,
- NautilusQuery *query,
- NautilusDirectory *base_model);
+static void set_search_query_internal (NautilusFilesView *files_view,
+ NautilusQuery *query,
+ NautilusDirectory *base_model);
-static gboolean nautilus_files_view_is_read_only (NautilusFilesView *view);
+static gboolean nautilus_files_view_is_read_only (NautilusFilesView *view);
G_DEFINE_TYPE_WITH_CODE (NautilusFilesView,
nautilus_files_view,
GTK_TYPE_GRID,
G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_VIEW, nautilus_files_view_iface_init));
-static const struct {
- unsigned int keyval;
- const char *action;
-} extra_view_keybindings [] = {
+static const struct
+{
+ unsigned int keyval;
+ const char *action;
+} extra_view_keybindings [] =
+{
#ifdef HAVE_X11_XF86KEYSYM_H
- /* View actions */
- { XF86XK_ZoomIn, "zoom-in" },
- { XF86XK_ZoomOut, "zoom-out" },
+ /* View actions */
+ { XF86XK_ZoomIn, "zoom-in" },
+ { XF86XK_ZoomOut, "zoom-out" },
#endif
};
@@ -357,69 +362,73 @@ static const struct {
static void
remove_loading_floating_bar (NautilusFilesView *view)
{
- if (view->details->floating_bar_loading_timeout_id != 0) {
- g_source_remove (view->details->floating_bar_loading_timeout_id);
- view->details->floating_bar_loading_timeout_id = 0;
- }
+ if (view->details->floating_bar_loading_timeout_id != 0)
+ {
+ g_source_remove (view->details->floating_bar_loading_timeout_id);
+ view->details->floating_bar_loading_timeout_id = 0;
+ }
- gtk_widget_hide (view->details->floating_bar);
- nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
+ gtk_widget_hide (view->details->floating_bar);
+ nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
}
static void
real_setup_loading_floating_bar (NautilusFilesView *view)
{
- gboolean disable_chrome;
+ gboolean disable_chrome;
- g_object_get (nautilus_files_view_get_window (view),
- "disable-chrome", &disable_chrome,
- NULL);
+ g_object_get (nautilus_files_view_get_window (view),
+ "disable-chrome", &disable_chrome,
+ NULL);
- if (disable_chrome) {
- gtk_widget_hide (view->details->floating_bar);
- return;
- }
+ if (disable_chrome)
+ {
+ gtk_widget_hide (view->details->floating_bar);
+ return;
+ }
- nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
- nautilus_floating_bar_set_primary_label (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
- nautilus_view_is_searching (NAUTILUS_VIEW (view)) ? _("Searching…") : _("Loading…"));
- nautilus_floating_bar_set_details_label (NAUTILUS_FLOATING_BAR (view->details->floating_bar), NULL);
- nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (view->details->floating_bar), view->details->loading);
- nautilus_floating_bar_add_action (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
- "process-stop-symbolic",
- NAUTILUS_FLOATING_BAR_ACTION_ID_STOP);
+ nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
+ nautilus_floating_bar_set_primary_label (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
+ nautilus_view_is_searching (NAUTILUS_VIEW (view)) ? _("Searching…") : _("Loading…"));
+ nautilus_floating_bar_set_details_label (NAUTILUS_FLOATING_BAR (view->details->floating_bar), NULL);
+ nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (view->details->floating_bar), view->details->loading);
+ nautilus_floating_bar_add_action (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
+ "process-stop-symbolic",
+ NAUTILUS_FLOATING_BAR_ACTION_ID_STOP);
- gtk_widget_set_halign (view->details->floating_bar, GTK_ALIGN_END);
- gtk_widget_show (view->details->floating_bar);
+ gtk_widget_set_halign (view->details->floating_bar, GTK_ALIGN_END);
+ gtk_widget_show (view->details->floating_bar);
}
static gboolean
setup_loading_floating_bar_timeout_cb (gpointer user_data)
{
- NautilusFilesView *view = user_data;
+ NautilusFilesView *view = user_data;
- view->details->floating_bar_loading_timeout_id = 0;
- real_setup_loading_floating_bar (view);
+ view->details->floating_bar_loading_timeout_id = 0;
+ real_setup_loading_floating_bar (view);
- return FALSE;
+ return FALSE;
}
static void
setup_loading_floating_bar (NautilusFilesView *view)
{
- /* setup loading overlay */
- if (view->details->floating_bar_set_status_timeout_id != 0) {
- g_source_remove (view->details->floating_bar_set_status_timeout_id);
- view->details->floating_bar_set_status_timeout_id = 0;
- }
+ /* setup loading overlay */
+ if (view->details->floating_bar_set_status_timeout_id != 0)
+ {
+ g_source_remove (view->details->floating_bar_set_status_timeout_id);
+ view->details->floating_bar_set_status_timeout_id = 0;
+ }
- if (view->details->floating_bar_loading_timeout_id != 0) {
- g_source_remove (view->details->floating_bar_loading_timeout_id);
- view->details->floating_bar_loading_timeout_id = 0;
- }
+ if (view->details->floating_bar_loading_timeout_id != 0)
+ {
+ g_source_remove (view->details->floating_bar_loading_timeout_id);
+ view->details->floating_bar_loading_timeout_id = 0;
+ }
- view->details->floating_bar_loading_timeout_id =
- g_timeout_add (FLOATING_BAR_LOADING_DELAY, setup_loading_floating_bar_timeout_cb, view);
+ view->details->floating_bar_loading_timeout_id =
+ g_timeout_add (FLOATING_BAR_LOADING_DELAY, setup_loading_floating_bar_timeout_cb, view);
}
static void
@@ -427,10 +436,11 @@ floating_bar_action_cb (NautilusFloatingBar *floating_bar,
gint action,
NautilusFilesView *view)
{
- if (action == NAUTILUS_FLOATING_BAR_ACTION_ID_STOP) {
- remove_loading_floating_bar (view);
- nautilus_window_slot_stop_loading (view->details->slot);
- }
+ if (action == NAUTILUS_FLOATING_BAR_ACTION_ID_STOP)
+ {
+ remove_loading_floating_bar (view);
+ nautilus_window_slot_stop_loading (view->details->slot);
+ }
}
static void
@@ -438,60 +448,64 @@ real_floating_bar_set_short_status (NautilusFilesView *view,
const gchar *primary_status,
const gchar *detail_status)
{
- gboolean disable_chrome;
+ gboolean disable_chrome;
- if (view->details->loading)
- return;
+ if (view->details->loading)
+ {
+ return;
+ }
- nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
- nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
- FALSE);
+ nautilus_floating_bar_cleanup_actions (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
+ nautilus_floating_bar_set_show_spinner (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
+ FALSE);
- g_object_get (nautilus_files_view_get_window (view),
- "disable-chrome", &disable_chrome,
- NULL);
+ g_object_get (nautilus_files_view_get_window (view),
+ "disable-chrome", &disable_chrome,
+ NULL);
- if ((primary_status == NULL && detail_status == NULL) || disable_chrome) {
- gtk_widget_hide (view->details->floating_bar);
- nautilus_floating_bar_remove_hover_timeout (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
- return;
- }
+ if ((primary_status == NULL && detail_status == NULL) || disable_chrome)
+ {
+ gtk_widget_hide (view->details->floating_bar);
+ nautilus_floating_bar_remove_hover_timeout (NAUTILUS_FLOATING_BAR (view->details->floating_bar));
+ return;
+ }
- nautilus_floating_bar_set_labels (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
- primary_status,
- detail_status);
+ nautilus_floating_bar_set_labels (NAUTILUS_FLOATING_BAR (view->details->floating_bar),
+ primary_status,
+ detail_status);
- gtk_widget_show (view->details->floating_bar);
+ gtk_widget_show (view->details->floating_bar);
}
-typedef struct {
- gchar *primary_status;
- gchar *detail_status;
- NautilusFilesView *view;
+typedef struct
+{
+ gchar *primary_status;
+ gchar *detail_status;
+ NautilusFilesView *view;
} FloatingBarSetStatusData;
static void
floating_bar_set_status_data_free (gpointer data)
{
- FloatingBarSetStatusData *status_data = data;
+ FloatingBarSetStatusData *status_data = data;
- g_free (status_data->primary_status);
- g_free (status_data->detail_status);
+ g_free (status_data->primary_status);
+ g_free (status_data->detail_status);
- g_slice_free (FloatingBarSetStatusData, data);
+ g_slice_free (FloatingBarSetStatusData, data);
}
static gboolean
floating_bar_set_status_timeout_cb (gpointer data)
{
- FloatingBarSetStatusData *status_data = data;
+ FloatingBarSetStatusData *status_data = data;
- status_data->view->details->floating_bar_set_status_timeout_id = 0;
- real_floating_bar_set_short_status (status_data->view,
- status_data->primary_status,
- status_data->detail_status);
+ status_data->view->details->floating_bar_set_status_timeout_id = 0;
+ real_floating_bar_set_short_status (status_data->view,
+ status_data->primary_status,
+ status_data->detail_status);
- return FALSE;
+ return FALSE;
}
static void
@@ -499,47 +513,49 @@ set_floating_bar_status (NautilusFilesView *view,
const gchar *primary_status,
const gchar *detail_status)
{
- GtkSettings *settings;
- gint double_click_time;
- FloatingBarSetStatusData *status_data;
-
- if (view->details->floating_bar_set_status_timeout_id != 0) {
- g_source_remove (view->details->floating_bar_set_status_timeout_id);
- view->details->floating_bar_set_status_timeout_id = 0;
- }
-
- settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (view)));
- g_object_get (settings,
- "gtk-double-click-time", &double_click_time,
- NULL);
-
- status_data = g_slice_new0 (FloatingBarSetStatusData);
- status_data->primary_status = g_strdup (primary_status);
- status_data->detail_status = g_strdup (detail_status);
- status_data->view = view;
-
- /* waiting for half of the double-click-time before setting
- * the status seems to be a good approximation of not setting it
- * too often and not delaying the statusbar too much.
- */
- view->details->floating_bar_set_status_timeout_id =
- g_timeout_add_full (G_PRIORITY_DEFAULT,
- (guint) (double_click_time / 2),
- floating_bar_set_status_timeout_cb,
- status_data,
- floating_bar_set_status_data_free);
+ GtkSettings *settings;
+ gint double_click_time;
+ FloatingBarSetStatusData *status_data;
+
+ if (view->details->floating_bar_set_status_timeout_id != 0)
+ {
+ g_source_remove (view->details->floating_bar_set_status_timeout_id);
+ view->details->floating_bar_set_status_timeout_id = 0;
+ }
+
+ settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (view)));
+ g_object_get (settings,
+ "gtk-double-click-time", &double_click_time,
+ NULL);
+
+ status_data = g_slice_new0 (FloatingBarSetStatusData);
+ status_data->primary_status = g_strdup (primary_status);
+ status_data->detail_status = g_strdup (detail_status);
+ status_data->view = view;
+
+ /* waiting for half of the double-click-time before setting
+ * the status seems to be a good approximation of not setting it
+ * too often and not delaying the statusbar too much.
+ */
+ view->details->floating_bar_set_status_timeout_id =
+ g_timeout_add_full (G_PRIORITY_DEFAULT,
+ (guint) (double_click_time / 2),
+ floating_bar_set_status_timeout_cb,
+ status_data,
+ floating_bar_set_status_data_free);
}
static char *
real_get_backing_uri (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- if (view->details->model == NULL) {
- return NULL;
- }
+ if (view->details->model == NULL)
+ {
+ return NULL;
+ }
- return nautilus_directory_get_uri (view->details->model);
+ return nautilus_directory_get_uri (view->details->model);
}
/**
@@ -553,9 +569,9 @@ real_get_backing_uri (NautilusFilesView *view)
char *
nautilus_files_view_get_backing_uri (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_backing_uri (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_backing_uri (view);
}
/**
@@ -567,41 +583,42 @@ nautilus_files_view_get_backing_uri (NautilusFilesView *view)
static void
nautilus_files_view_select_all (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_all (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_all (view);
}
static void
nautilus_files_view_select_first (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_first (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->select_first (view);
}
static void
-nautilus_files_view_call_set_selection (NautilusFilesView *view, GList *selection)
+nautilus_files_view_call_set_selection (NautilusFilesView *view,
+ GList *selection)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->set_selection (view, selection);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->set_selection (view, selection);
}
static GList *
nautilus_files_view_get_selection_for_file_transfer (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_selection_for_file_transfer (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_selection_for_file_transfer (view);
}
static void
nautilus_files_view_invert_selection (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->invert_selection (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->invert_selection (view);
}
/**
@@ -612,17 +629,17 @@ nautilus_files_view_invert_selection (NautilusFilesView *view)
static void
nautilus_files_view_reveal_selection (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->reveal_selection (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->reveal_selection (view);
}
static gboolean
-nautilus_files_view_using_manual_layout (NautilusFilesView *view)
+nautilus_files_view_using_manual_layout (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->using_manual_layout (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->using_manual_layout (view);
}
/**
@@ -633,12 +650,12 @@ nautilus_files_view_using_manual_layout (NautilusFilesView *view)
*
* Returns: (transfer none): the #Gicon that represents @view
*/
-static GIcon*
+static GIcon *
nautilus_files_view_get_icon (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_icon (NAUTILUS_FILES_VIEW (view));
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_icon (NAUTILUS_FILES_VIEW (view));
}
/**
@@ -654,61 +671,63 @@ nautilus_files_view_get_icon (NautilusView *view)
static NautilusToolbarMenuSections *
nautilus_files_view_get_toolbar_menu_sections (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return NAUTILUS_FILES_VIEW (view)->details->toolbar_menu_sections;
+ return NAUTILUS_FILES_VIEW (view)->details->toolbar_menu_sections;
}
static gboolean
showing_trash_directory (NautilusFilesView *view)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL) {
- return nautilus_file_is_in_trash (file);
- }
- return FALSE;
+ file = nautilus_files_view_get_directory_as_file (view);
+ if (file != NULL)
+ {
+ return nautilus_file_is_in_trash (file);
+ }
+ return FALSE;
}
static gboolean
showing_recent_directory (NautilusFilesView *view)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL) {
- return nautilus_file_is_in_recent (file);
- }
- return FALSE;
+ file = nautilus_files_view_get_directory_as_file (view);
+ if (file != NULL)
+ {
+ return nautilus_file_is_in_recent (file);
+ }
+ return FALSE;
}
static gboolean
nautilus_files_view_supports_creating_files (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return !nautilus_files_view_is_read_only (view)
- && !showing_trash_directory (view)
- && !showing_recent_directory (view);
+ return !nautilus_files_view_is_read_only (view)
+ && !showing_trash_directory (view)
+ && !showing_recent_directory (view);
}
static gboolean
nautilus_files_view_supports_extract_here (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return nautilus_files_view_supports_creating_files (view)
- && !nautilus_directory_is_remote (view->details->model)
- && !nautilus_view_is_searching (NAUTILUS_VIEW (view));
+ return nautilus_files_view_supports_creating_files (view)
+ && !nautilus_directory_is_remote (view->details->model)
+ && !nautilus_view_is_searching (NAUTILUS_VIEW (view));
}
static gboolean
nautilus_files_view_is_empty (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->is_empty (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->is_empty (view);
}
/**
@@ -719,15 +738,16 @@ nautilus_files_view_is_empty (NautilusFilesView *view)
**/
void
nautilus_files_view_bump_zoom_level (NautilusFilesView *view,
- int zoom_increment)
+ int zoom_increment)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- if (!nautilus_files_view_supports_zooming (view)) {
- return;
- }
+ if (!nautilus_files_view_supports_zooming (view))
+ {
+ return;
+ }
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->bump_zoom_level (view, zoom_increment);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->bump_zoom_level (view, zoom_increment);
}
/**
@@ -742,13 +762,14 @@ nautilus_files_view_bump_zoom_level (NautilusFilesView *view,
gboolean
nautilus_files_view_can_zoom_in (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- if (!nautilus_files_view_supports_zooming (view)) {
- return FALSE;
- }
+ if (!nautilus_files_view_supports_zooming (view))
+ {
+ return FALSE;
+ }
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->can_zoom_in (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->can_zoom_in (view);
}
/**
@@ -763,21 +784,22 @@ nautilus_files_view_can_zoom_in (NautilusFilesView *view)
gboolean
nautilus_files_view_can_zoom_out (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- if (!nautilus_files_view_supports_zooming (view)) {
- return FALSE;
- }
+ if (!nautilus_files_view_supports_zooming (view))
+ {
+ return FALSE;
+ }
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->can_zoom_out (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->can_zoom_out (view);
}
gboolean
nautilus_files_view_supports_zooming (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return view->details->supports_zooming;
+ return view->details->supports_zooming;
}
/**
@@ -788,50 +810,54 @@ nautilus_files_view_supports_zooming (NautilusFilesView *view)
static void
nautilus_files_view_restore_standard_zoom_level (NautilusFilesView *view)
{
- if (!nautilus_files_view_supports_zooming (view))
- return;
+ if (!nautilus_files_view_supports_zooming (view))
+ {
+ return;
+ }
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->restore_standard_zoom_level (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->restore_standard_zoom_level (view);
}
static gfloat
nautilus_files_view_get_zoom_level_percentage (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), 1);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), 1);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_zoom_level_percentage (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_zoom_level_percentage (view);
}
gboolean
nautilus_files_view_is_searching (NautilusView *view)
{
- NautilusFilesView *files_view;
+ NautilusFilesView *files_view;
- files_view = NAUTILUS_FILES_VIEW (view);
+ files_view = NAUTILUS_FILES_VIEW (view);
- if (!files_view->details->model)
- return FALSE;
+ if (!files_view->details->model)
+ {
+ return FALSE;
+ }
- return NAUTILUS_IS_SEARCH_DIRECTORY (files_view->details->model);
+ return NAUTILUS_IS_SEARCH_DIRECTORY (files_view->details->model);
}
guint
nautilus_files_view_get_view_id (NautilusFilesView *view)
{
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_view_id (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_view_id (view);
}
char *
nautilus_files_view_get_first_visible_file (NautilusFilesView *view)
{
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_first_visible_file (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_first_visible_file (view);
}
void
nautilus_files_view_scroll_to_file (NautilusFilesView *view,
- const char *uri)
+ const char *uri)
{
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->scroll_to_file (view, uri);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->scroll_to_file (view, uri);
}
/**
@@ -846,36 +872,39 @@ nautilus_files_view_scroll_to_file (NautilusFilesView *view,
* Return value: GList of NautilusFile pointers representing the selection.
*
**/
-static GList*
+static GList *
nautilus_files_view_get_selection (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_selection (NAUTILUS_FILES_VIEW (view));
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->get_selection (NAUTILUS_FILES_VIEW (view));
}
-typedef struct {
- NautilusFile *file;
- NautilusFilesView *directory_view;
+typedef struct
+{
+ NautilusFile *file;
+ NautilusFilesView *directory_view;
} ScriptLaunchParameters;
-typedef struct {
- NautilusFile *file;
- NautilusFilesView *directory_view;
+typedef struct
+{
+ NautilusFile *file;
+ NautilusFilesView *directory_view;
} CreateTemplateParameters;
static GList *
file_and_directory_list_to_files (GList *fad_list)
{
- GList *res, *l;
- FileAndDirectory *fad;
+ GList *res, *l;
+ FileAndDirectory *fad;
- res = NULL;
- for (l = fad_list; l != NULL; l = l->next) {
- fad = l->data;
- res = g_list_prepend (res, nautilus_file_ref (fad->file));
- }
- return g_list_reverse (res);
+ res = NULL;
+ for (l = fad_list; l != NULL; l = l->next)
+ {
+ fad = l->data;
+ res = g_list_prepend (res, nautilus_file_ref (fad->file));
+ }
+ return g_list_reverse (res);
}
@@ -883,115 +912,117 @@ static GList *
file_and_directory_list_from_files (NautilusDirectory *directory,
GList *files)
{
- GList *res, *l;
- FileAndDirectory *fad;
+ GList *res, *l;
+ FileAndDirectory *fad;
- res = NULL;
- for (l = files; l != NULL; l = l->next) {
- fad = g_new0 (FileAndDirectory, 1);
- fad->directory = nautilus_directory_ref (directory);
- fad->file = nautilus_file_ref (l->data);
- res = g_list_prepend (res, fad);
- }
- return g_list_reverse (res);
+ res = NULL;
+ for (l = files; l != NULL; l = l->next)
+ {
+ fad = g_new0 (FileAndDirectory, 1);
+ fad->directory = nautilus_directory_ref (directory);
+ fad->file = nautilus_file_ref (l->data);
+ res = g_list_prepend (res, fad);
+ }
+ return g_list_reverse (res);
}
static void
file_and_directory_free (FileAndDirectory *fad)
{
- nautilus_directory_unref (fad->directory);
- nautilus_file_unref (fad->file);
- g_free (fad);
+ nautilus_directory_unref (fad->directory);
+ nautilus_file_unref (fad->file);
+ g_free (fad);
}
static void
file_and_directory_list_free (GList *list)
{
- GList *l;
+ GList *l;
- for (l = list; l != NULL; l = l->next) {
- file_and_directory_free (l->data);
- }
+ for (l = list; l != NULL; l = l->next)
+ {
+ file_and_directory_free (l->data);
+ }
- g_list_free (list);
+ g_list_free (list);
}
static gboolean
file_and_directory_equal (gconstpointer v1,
gconstpointer v2)
{
- const FileAndDirectory *fad1, *fad2;
- fad1 = v1;
- fad2 = v2;
+ const FileAndDirectory *fad1, *fad2;
+ fad1 = v1;
+ fad2 = v2;
- return (fad1->file == fad2->file &&
- fad1->directory == fad2->directory);
+ return (fad1->file == fad2->file &&
+ fad1->directory == fad2->directory);
}
static guint
-file_and_directory_hash (gconstpointer v)
+file_and_directory_hash (gconstpointer v)
{
- const FileAndDirectory *fad;
+ const FileAndDirectory *fad;
- fad = v;
- return GPOINTER_TO_UINT (fad->file) ^ GPOINTER_TO_UINT (fad->directory);
+ fad = v;
+ return GPOINTER_TO_UINT (fad->file) ^ GPOINTER_TO_UINT (fad->directory);
}
static ScriptLaunchParameters *
-script_launch_parameters_new (NautilusFile *file,
+script_launch_parameters_new (NautilusFile *file,
NautilusFilesView *directory_view)
{
- ScriptLaunchParameters *result;
+ ScriptLaunchParameters *result;
- result = g_new0 (ScriptLaunchParameters, 1);
- result->directory_view = directory_view;
- nautilus_file_ref (file);
- result->file = file;
+ result = g_new0 (ScriptLaunchParameters, 1);
+ result->directory_view = directory_view;
+ nautilus_file_ref (file);
+ result->file = file;
- return result;
+ return result;
}
static void
script_launch_parameters_free (ScriptLaunchParameters *parameters)
{
- nautilus_file_unref (parameters->file);
- g_free (parameters);
+ nautilus_file_unref (parameters->file);
+ g_free (parameters);
}
static CreateTemplateParameters *
create_template_parameters_new (NautilusFile *file,
NautilusFilesView *directory_view)
{
- CreateTemplateParameters *result;
+ CreateTemplateParameters *result;
- result = g_new0 (CreateTemplateParameters, 1);
- result->directory_view = directory_view;
- nautilus_file_ref (file);
- result->file = file;
+ result = g_new0 (CreateTemplateParameters, 1);
+ result->directory_view = directory_view;
+ nautilus_file_ref (file);
+ result->file = file;
- return result;
+ return result;
}
static void
create_templates_parameters_free (CreateTemplateParameters *parameters)
{
- nautilus_file_unref (parameters->file);
- g_free (parameters);
+ nautilus_file_unref (parameters->file);
+ g_free (parameters);
}
NautilusWindow *
-nautilus_files_view_get_window (NautilusFilesView *view)
+nautilus_files_view_get_window (NautilusFilesView *view)
{
- return nautilus_window_slot_get_window (view->details->slot);
+ return nautilus_window_slot_get_window (view->details->slot);
}
NautilusWindowSlot *
-nautilus_files_view_get_nautilus_window_slot (NautilusFilesView *view)
+nautilus_files_view_get_nautilus_window_slot (NautilusFilesView *view)
{
- g_assert (view->details->slot != NULL);
+ g_assert (view->details->slot != NULL);
- return view->details->slot;
+ return view->details->slot;
}
/* Returns the GtkWindow that this directory view occupies, or NULL
@@ -1001,16 +1032,17 @@ nautilus_files_view_get_nautilus_window_slot (NautilusFilesView *view)
static GtkWindow *
nautilus_files_view_get_containing_window (NautilusFilesView *view)
{
- GtkWidget *window;
+ GtkWidget *window;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- window = gtk_widget_get_ancestor (GTK_WIDGET (view), GTK_TYPE_WINDOW);
- if (window == NULL) {
- return NULL;
- }
+ window = gtk_widget_get_ancestor (GTK_WIDGET (view), GTK_TYPE_WINDOW);
+ if (window == NULL)
+ {
+ return NULL;
+ }
- return GTK_WINDOW (window);
+ return GTK_WINDOW (window);
}
static gboolean
@@ -1018,63 +1050,68 @@ nautilus_files_view_confirm_multiple (GtkWindow *parent_window,
int count,
gboolean tabs)
{
- GtkDialog *dialog;
- char *prompt;
- char *detail;
- int response;
-
- if (count <= SILENT_WINDOW_OPEN_LIMIT) {
- return TRUE;
- }
+ GtkDialog *dialog;
+ char *prompt;
+ char *detail;
+ int response;
- prompt = _("Are you sure you want to open all files?");
- if (tabs) {
- detail = g_strdup_printf (ngettext("This will open %'d separate tab.",
- "This will open %'d separate tabs.", count), count);
- } else {
- detail = g_strdup_printf (ngettext("This will open %'d separate window.",
- "This will open %'d separate windows.", count), count);
- }
- dialog = eel_show_yes_no_dialog (prompt, detail,
- _("_OK"), _("_Cancel"),
- parent_window);
- g_free (detail);
-
- response = gtk_dialog_run (dialog);
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- return response == GTK_RESPONSE_YES;
+ if (count <= SILENT_WINDOW_OPEN_LIMIT)
+ {
+ return TRUE;
+ }
+
+ prompt = _("Are you sure you want to open all files?");
+ if (tabs)
+ {
+ detail = g_strdup_printf (ngettext ("This will open %'d separate tab.",
+ "This will open %'d separate tabs.", count), count);
+ }
+ else
+ {
+ detail = g_strdup_printf (ngettext ("This will open %'d separate window.",
+ "This will open %'d separate windows.", count), count);
+ }
+ dialog = eel_show_yes_no_dialog (prompt, detail,
+ _("_OK"), _("_Cancel"),
+ parent_window);
+ g_free (detail);
+
+ response = gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ return response == GTK_RESPONSE_YES;
}
static gboolean
selection_not_empty_in_menu_callback (NautilusFilesView *view,
GList *selection)
{
- if (selection != NULL) {
- return TRUE;
- }
+ if (selection != NULL)
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static char *
get_view_directory (NautilusFilesView *view)
{
- char *uri, *path;
- GFile *f;
+ char *uri, *path;
+ GFile *f;
- uri = nautilus_directory_get_uri (view->details->model);
- if (eel_uri_is_desktop (uri)) {
- g_free (uri);
- uri = nautilus_get_desktop_directory_uri ();
-
- }
- f = g_file_new_for_uri (uri);
- path = g_file_get_path (f);
- g_object_unref (f);
+ uri = nautilus_directory_get_uri (view->details->model);
+ if (eel_uri_is_desktop (uri))
+ {
g_free (uri);
+ uri = nautilus_get_desktop_directory_uri ();
+ }
+ f = g_file_new_for_uri (uri);
+ path = g_file_get_path (f);
+ g_object_unref (f);
+ g_free (uri);
- return path;
+ return path;
}
void
@@ -1082,36 +1119,38 @@ nautilus_files_view_preview_files (NautilusFilesView *view,
GList *files,
GArray *locations)
{
- gchar *uri;
- guint xid = 0;
- GtkWidget *toplevel;
- GdkWindow *window;
+ gchar *uri;
+ guint xid = 0;
+ GtkWidget *toplevel;
+ GdkWindow *window;
- uri = nautilus_file_get_uri (files->data);
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ uri = nautilus_file_get_uri (files->data);
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
#ifdef GDK_WINDOWING_X11
- window = gtk_widget_get_window (toplevel);
- if (GDK_IS_X11_WINDOW (window))
- xid = gdk_x11_window_get_xid (gtk_widget_get_window (toplevel));
+ window = gtk_widget_get_window (toplevel);
+ if (GDK_IS_X11_WINDOW (window))
+ {
+ xid = gdk_x11_window_get_xid (gtk_widget_get_window (toplevel));
+ }
#endif
- nautilus_previewer_call_show_file (uri, xid, TRUE);
+ nautilus_previewer_call_show_file (uri, xid, TRUE);
- g_free (uri);
+ g_free (uri);
}
void
nautilus_files_view_activate_selection (NautilusFilesView *view)
{
- GList *selection;
+ GList *selection;
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- nautilus_files_view_activate_files (view,
- selection,
- 0,
- TRUE);
- nautilus_file_list_free (selection);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ nautilus_files_view_activate_files (view,
+ selection,
+ 0,
+ TRUE);
+ nautilus_file_list_free (selection);
}
void
@@ -1120,33 +1159,36 @@ nautilus_files_view_activate_files (NautilusFilesView *view,
NautilusWindowOpenFlags flags,
gboolean confirm_multiple)
{
- GList *files_to_extract;
- GList *files_to_activate;
- char *path;
+ GList *files_to_extract;
+ GList *files_to_activate;
+ char *path;
- files_to_extract = nautilus_file_list_filter (files,
- &files_to_activate,
- (NautilusFileFilterFunc)nautilus_mime_file_extracts,
- NULL);
+ files_to_extract = nautilus_file_list_filter (files,
+ &files_to_activate,
+ (NautilusFileFilterFunc) nautilus_mime_file_extracts,
+ NULL);
- if (nautilus_files_view_supports_extract_here (view)) {
- extract_files (view, files_to_extract,
- nautilus_view_get_location (NAUTILUS_VIEW (view)));
- } else {
- extract_files_to_chosen_location (view, files_to_extract);
- }
+ if (nautilus_files_view_supports_extract_here (view))
+ {
+ extract_files (view, files_to_extract,
+ nautilus_view_get_location (NAUTILUS_VIEW (view)));
+ }
+ else
+ {
+ extract_files_to_chosen_location (view, files_to_extract);
+ }
- path = get_view_directory (view);
- nautilus_mime_activate_files (nautilus_files_view_get_containing_window (view),
- view->details->slot,
- files_to_activate,
- path,
- flags,
- confirm_multiple);
+ path = get_view_directory (view);
+ nautilus_mime_activate_files (nautilus_files_view_get_containing_window (view),
+ view->details->slot,
+ files_to_activate,
+ path,
+ flags,
+ confirm_multiple);
- g_free (path);
- g_list_free (files_to_extract);
- g_list_free (files_to_activate);
+ g_free (path);
+ g_list_free (files_to_extract);
+ g_list_free (files_to_activate);
}
static void
@@ -1154,33 +1196,37 @@ nautilus_files_view_activate_file (NautilusFilesView *view,
NautilusFile *file,
NautilusWindowOpenFlags flags)
{
- char *path;
+ char *path;
- if (nautilus_mime_file_extracts (file)) {
- GList *files = NULL;
+ if (nautilus_mime_file_extracts (file))
+ {
+ GList *files = NULL;
- files = g_list_prepend (files, file);
+ files = g_list_prepend (files, file);
- if (nautilus_files_view_supports_extract_here (view)) {
- extract_files (view, files,
- nautilus_view_get_location (NAUTILUS_VIEW (view)));
- } else {
- extract_files_to_chosen_location (view, files);
- }
+ if (nautilus_files_view_supports_extract_here (view))
+ {
+ extract_files (view, files,
+ nautilus_view_get_location (NAUTILUS_VIEW (view)));
+ }
+ else
+ {
+ extract_files_to_chosen_location (view, files);
+ }
- g_list_free (files);
+ g_list_free (files);
- return;
- }
+ return;
+ }
- path = get_view_directory (view);
- nautilus_mime_activate_file (nautilus_files_view_get_containing_window (view),
- view->details->slot,
- file,
- path,
- flags);
+ path = get_view_directory (view);
+ nautilus_mime_activate_file (nautilus_files_view_get_containing_window (view),
+ view->details->slot,
+ file,
+ path,
+ flags);
- g_free (path);
+ g_free (path);
}
static void
@@ -1188,27 +1234,27 @@ action_open_with_default_application (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
- nautilus_files_view_activate_selection (view);
+ view = NAUTILUS_FILES_VIEW (user_data);
+ nautilus_files_view_activate_selection (view);
}
static void
action_open_file_and_close_window (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- GList *selection;
- NautilusFilesView *view;
+ GList *selection;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- nautilus_files_view_activate_files (view,
- selection,
- NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND,
- TRUE);
- nautilus_file_list_free (selection);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ nautilus_files_view_activate_files (view,
+ selection,
+ NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND,
+ TRUE);
+ nautilus_file_list_free (selection);
}
static void
@@ -1216,9 +1262,9 @@ got_it_clicked (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- g_settings_set_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG,
- FALSE);
+ g_settings_set_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG,
+ FALSE);
}
static void
@@ -1226,59 +1272,62 @@ action_show_move_to_trash_shortcut_changed_dialog (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GtkWindow *dialog;
- GtkBuilder *builder;
- gboolean show_dialog_preference;
+ NautilusFilesView *view;
+ GtkWindow *dialog;
+ GtkBuilder *builder;
+ gboolean show_dialog_preference;
- view = NAUTILUS_FILES_VIEW (user_data);
- show_dialog_preference = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG);
- if (show_dialog_preference) {
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-move-to-trash-shortcut-changed.ui");
- dialog = GTK_WINDOW (gtk_builder_get_object (builder, "move_to_trash_shortcut_changed_dialog"));
+ view = NAUTILUS_FILES_VIEW (user_data);
+ show_dialog_preference = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_SHOW_MOVE_TO_TRASH_SHORTCUT_CHANGED_DIALOG);
+ if (show_dialog_preference)
+ {
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-move-to-trash-shortcut-changed.ui");
+ dialog = GTK_WINDOW (gtk_builder_get_object (builder, "move_to_trash_shortcut_changed_dialog"));
- gtk_window_set_transient_for (dialog, GTK_WINDOW (nautilus_files_view_get_window (view)));
- g_signal_connect (dialog, "response",
- G_CALLBACK (got_it_clicked),
- view);
+ gtk_window_set_transient_for (dialog, GTK_WINDOW (nautilus_files_view_get_window (view)));
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (got_it_clicked),
+ view);
- gtk_widget_show (GTK_WIDGET (dialog));
- gtk_dialog_run(GTK_DIALOG (dialog));
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_show (GTK_WIDGET (dialog));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
- g_object_unref (builder);
- }
+ g_object_unref (builder);
+ }
}
static void
action_open_item_location (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
- NautilusFile *item;
- GFile *activation_location;
- NautilusFile *activation_file;
- NautilusFile *location;
+ NautilusFilesView *view;
+ GList *selection;
+ NautilusFile *item;
+ GFile *activation_location;
+ NautilusFile *activation_file;
+ NautilusFile *location;
- view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ view = NAUTILUS_FILES_VIEW (user_data);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- if (!selection)
- return;
+ if (!selection)
+ {
+ return;
+ }
- item = NAUTILUS_FILE (selection->data);
- activation_location = nautilus_file_get_activation_location (item);
- activation_file = nautilus_file_get (activation_location);
- location = nautilus_file_get_parent (activation_file);
+ item = NAUTILUS_FILE (selection->data);
+ activation_location = nautilus_file_get_activation_location (item);
+ activation_file = nautilus_file_get (activation_location);
+ location = nautilus_file_get_parent (activation_file);
- nautilus_files_view_activate_file (view, location, 0);
+ nautilus_files_view_activate_file (view, location, 0);
- nautilus_file_unref (location);
- nautilus_file_unref (activation_file);
- g_object_unref (activation_location);
- nautilus_file_list_free (selection);
+ nautilus_file_unref (location);
+ nautilus_file_unref (activation_file);
+ g_object_unref (activation_location);
+ nautilus_file_list_free (selection);
}
static void
@@ -1286,24 +1335,25 @@ action_open_item_new_tab (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
- GtkWindow *window;
+ NautilusFilesView *view;
+ GList *selection;
+ GtkWindow *window;
- view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ view = NAUTILUS_FILES_VIEW (user_data);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- window = nautilus_files_view_get_containing_window (view);
+ window = nautilus_files_view_get_containing_window (view);
- if (nautilus_files_view_confirm_multiple (window, g_list_length (selection), TRUE)) {
- nautilus_files_view_activate_files (view,
- selection,
- NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB |
- NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
- FALSE);
- }
+ if (nautilus_files_view_confirm_multiple (window, g_list_length (selection), TRUE))
+ {
+ nautilus_files_view_activate_files (view,
+ selection,
+ NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB |
+ NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
+ FALSE);
+ }
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static void
@@ -1311,65 +1361,67 @@ app_chooser_dialog_response_cb (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- GtkWindow *parent_window;
- GList *files;
- GAppInfo *info;
+ GtkWindow *parent_window;
+ GList *files;
+ GAppInfo *info;
- parent_window = user_data;
- files = g_object_get_data (G_OBJECT (dialog), "directory-view:files");
+ parent_window = user_data;
+ files = g_object_get_data (G_OBJECT (dialog), "directory-view:files");
- if (response_id != GTK_RESPONSE_OK)
- goto out;
+ if (response_id != GTK_RESPONSE_OK)
+ {
+ goto out;
+ }
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
- nautilus_launch_application (info, files, parent_window);
+ nautilus_launch_application (info, files, parent_window);
- g_object_unref (info);
+ g_object_unref (info);
out:
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
choose_program (NautilusFilesView *view,
GList *files)
{
- GtkWidget *dialog;
- gchar *mime_type;
- GtkWindow *parent_window;
+ GtkWidget *dialog;
+ gchar *mime_type;
+ GtkWindow *parent_window;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- mime_type = nautilus_file_get_mime_type (files->data);
- parent_window = nautilus_files_view_get_containing_window (view);
+ mime_type = nautilus_file_get_mime_type (files->data);
+ parent_window = nautilus_files_view_get_containing_window (view);
- dialog = gtk_app_chooser_dialog_new_for_content_type (parent_window,
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT |
- GTK_DIALOG_USE_HEADER_BAR,
- mime_type);
- g_object_set_data_full (G_OBJECT (dialog),
- "directory-view:files",
- files,
- (GDestroyNotify) nautilus_file_list_free);
- gtk_widget_show (dialog);
+ dialog = gtk_app_chooser_dialog_new_for_content_type (parent_window,
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_USE_HEADER_BAR,
+ mime_type);
+ g_object_set_data_full (G_OBJECT (dialog),
+ "directory-view:files",
+ files,
+ (GDestroyNotify) nautilus_file_list_free);
+ gtk_widget_show (dialog);
- g_signal_connect_object (dialog, "response",
- G_CALLBACK (app_chooser_dialog_response_cb),
- parent_window, 0);
+ g_signal_connect_object (dialog, "response",
+ G_CALLBACK (app_chooser_dialog_response_cb),
+ parent_window, 0);
}
static void
open_with_other_program (NautilusFilesView *view)
{
- GList *selection;
+ GList *selection;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- choose_program (view, selection);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ choose_program (view, selection);
}
static void
@@ -1377,28 +1429,29 @@ action_open_with_other_application (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- open_with_other_program (NAUTILUS_FILES_VIEW (user_data));
+ open_with_other_program (NAUTILUS_FILES_VIEW (user_data));
}
static void
trash_or_delete_selected_files (NautilusFilesView *view)
{
- GList *selection;
+ GList *selection;
- /* This might be rapidly called multiple times for the same selection
- * when using keybindings. So we remember if the current selection
- * was already removed (but the view doesn't know about it yet).
- */
- if (!view->details->selection_was_removed) {
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
- trash_or_delete_files (nautilus_files_view_get_containing_window (view),
- selection,
- view);
- nautilus_file_list_free (selection);
- view->details->selection_was_removed = TRUE;
- }
+ /* This might be rapidly called multiple times for the same selection
+ * when using keybindings. So we remember if the current selection
+ * was already removed (but the view doesn't know about it yet).
+ */
+ if (!view->details->selection_was_removed)
+ {
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ trash_or_delete_files (nautilus_files_view_get_containing_window (view),
+ selection,
+ view);
+ nautilus_file_list_free (selection);
+ view->details->selection_was_removed = TRUE;
+ }
}
static void
@@ -1406,7 +1459,7 @@ action_move_to_trash (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- trash_or_delete_selected_files (NAUTILUS_FILES_VIEW (user_data));
+ trash_or_delete_selected_files (NAUTILUS_FILES_VIEW (user_data));
}
static void
@@ -1414,35 +1467,37 @@ action_remove_from_recent (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- /* TODO:implement a set of functions for this, is very confusing to
- * call trash_or_delete_file to remove from recent, even if it does like
- * that not deleting/moving the files to trash */
- trash_or_delete_selected_files (NAUTILUS_FILES_VIEW (user_data));
+ /* TODO:implement a set of functions for this, is very confusing to
+ * call trash_or_delete_file to remove from recent, even if it does like
+ * that not deleting/moving the files to trash */
+ trash_or_delete_selected_files (NAUTILUS_FILES_VIEW (user_data));
}
static void
delete_selected_files (NautilusFilesView *view)
{
- GList *selection;
- GList *node;
- GList *locations;
+ GList *selection;
+ GList *node;
+ GList *locations;
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
- if (selection == NULL) {
- return;
- }
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ if (selection == NULL)
+ {
+ return;
+ }
- locations = NULL;
- for (node = selection; node != NULL; node = node->next) {
- locations = g_list_prepend (locations,
- nautilus_file_get_location ((NautilusFile *) node->data));
- }
- locations = g_list_reverse (locations);
+ locations = NULL;
+ for (node = selection; node != NULL; node = node->next)
+ {
+ locations = g_list_prepend (locations,
+ nautilus_file_get_location ((NautilusFile *) node->data));
+ }
+ locations = g_list_reverse (locations);
- nautilus_file_operations_delete (locations, nautilus_files_view_get_containing_window (view), NULL, NULL);
+ nautilus_file_operations_delete (locations, nautilus_files_view_get_containing_window (view), NULL, NULL);
- g_list_free_full (locations, g_object_unref);
- nautilus_file_list_free (selection);
+ g_list_free_full (locations, g_object_unref);
+ nautilus_file_list_free (selection);
}
static void
@@ -1450,7 +1505,7 @@ action_delete (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- delete_selected_files (NAUTILUS_FILES_VIEW (user_data));
+ delete_selected_files (NAUTILUS_FILES_VIEW (user_data));
}
static void
@@ -1458,17 +1513,16 @@ action_restore_from_trash (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
+ NautilusFilesView *view;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
- nautilus_restore_files_from_trash (selection,
- nautilus_files_view_get_containing_window (view));
-
- nautilus_file_list_free (selection);
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ nautilus_restore_files_from_trash (selection,
+ nautilus_files_view_get_containing_window (view));
+ nautilus_file_list_free (selection);
}
static void
@@ -1476,13 +1530,13 @@ action_select_all (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- nautilus_files_view_select_all (view);
+ nautilus_files_view_select_all (view);
}
static void
@@ -1490,9 +1544,9 @@ action_invert_selection (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- nautilus_files_view_invert_selection (user_data);
+ nautilus_files_view_invert_selection (user_data);
}
static void
@@ -1500,97 +1554,105 @@ pattern_select_response_cb (GtkWidget *dialog,
int response,
gpointer user_data)
{
- NautilusFilesView *view;
- NautilusDirectory *directory;
- GtkWidget *entry;
- GList *selection;
+ NautilusFilesView *view;
+ NautilusDirectory *directory;
+ GtkWidget *entry;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- switch (response) {
- case GTK_RESPONSE_OK :
- entry = g_object_get_data (G_OBJECT (dialog), "entry");
- directory = nautilus_files_view_get_model (view);
- selection = nautilus_directory_match_pattern (directory,
- gtk_entry_get_text (GTK_ENTRY (entry)));
+ switch (response)
+ {
+ case GTK_RESPONSE_OK:
+ {
+ entry = g_object_get_data (G_OBJECT (dialog), "entry");
+ directory = nautilus_files_view_get_model (view);
+ selection = nautilus_directory_match_pattern (directory,
+ gtk_entry_get_text (GTK_ENTRY (entry)));
- if (selection) {
- nautilus_files_view_call_set_selection (view, selection);
- nautilus_file_list_free (selection);
+ if (selection)
+ {
+ nautilus_files_view_call_set_selection (view, selection);
+ nautilus_file_list_free (selection);
- nautilus_files_view_reveal_selection(view);
- }
- /* fall through */
- case GTK_RESPONSE_NONE :
- case GTK_RESPONSE_DELETE_EVENT :
- case GTK_RESPONSE_CANCEL :
- gtk_widget_destroy (GTK_WIDGET (dialog));
- break;
- default :
- g_assert_not_reached ();
+ nautilus_files_view_reveal_selection (view);
+ }
+ /* fall through */
+ }
+
+ case GTK_RESPONSE_NONE:
+ case GTK_RESPONSE_DELETE_EVENT:
+ case GTK_RESPONSE_CANCEL:
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
}
static void
select_pattern (NautilusFilesView *view)
{
- GtkWidget *dialog;
- GtkWidget *label;
- GtkWidget *example;
- GtkWidget *grid;
- GtkWidget *entry;
- char *example_pattern;
-
- dialog = gtk_dialog_new_with_buttons (_("Select Items Matching"),
- nautilus_files_view_get_containing_window (view),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
- _("_Cancel"),
- GTK_RESPONSE_CANCEL,
- _("_Select"),
- GTK_RESPONSE_OK,
- NULL);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- GTK_RESPONSE_OK);
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
- gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2);
-
- label = gtk_label_new_with_mnemonic (_("_Pattern:"));
- gtk_widget_set_halign (label, GTK_ALIGN_START);
-
- example = gtk_label_new (NULL);
- gtk_widget_set_halign (example, GTK_ALIGN_START);
- example_pattern = g_strdup_printf ("%s<i>%s</i> ",
- _("Examples: "),
- "*.png, file\?\?.txt, pict*.\?\?\?");
- gtk_label_set_markup (GTK_LABEL (example), example_pattern);
- g_free (example_pattern);
-
- entry = gtk_entry_new ();
- gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
- gtk_widget_set_hexpand (entry, TRUE);
-
- grid = gtk_grid_new ();
- g_object_set (grid,
- "orientation", GTK_ORIENTATION_VERTICAL,
- "border-width", 6,
- "row-spacing", 6,
- "column-spacing", 12,
- NULL);
-
- gtk_container_add (GTK_CONTAINER (grid), label);
- gtk_grid_attach_next_to (GTK_GRID (grid), entry, label,
- GTK_POS_RIGHT, 1, 1);
- gtk_grid_attach_next_to (GTK_GRID (grid), example, entry,
- GTK_POS_BOTTOM, 1, 1);
-
- gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
- gtk_widget_show_all (grid);
- gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid);
- g_object_set_data (G_OBJECT (dialog), "entry", entry);
- g_signal_connect (dialog, "response",
- G_CALLBACK (pattern_select_response_cb),
- view);
- gtk_widget_show_all (dialog);
+ GtkWidget *dialog;
+ GtkWidget *label;
+ GtkWidget *example;
+ GtkWidget *grid;
+ GtkWidget *entry;
+ char *example_pattern;
+
+ dialog = gtk_dialog_new_with_buttons (_("Select Items Matching"),
+ nautilus_files_view_get_containing_window (view),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
+ _("_Cancel"),
+ GTK_RESPONSE_CANCEL,
+ _("_Select"),
+ GTK_RESPONSE_OK,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_OK);
+ gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+ gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2);
+
+ label = gtk_label_new_with_mnemonic (_("_Pattern:"));
+ gtk_widget_set_halign (label, GTK_ALIGN_START);
+
+ example = gtk_label_new (NULL);
+ gtk_widget_set_halign (example, GTK_ALIGN_START);
+ example_pattern = g_strdup_printf ("%s<i>%s</i> ",
+ _("Examples: "),
+ "*.png, file\?\?.txt, pict*.\?\?\?");
+ gtk_label_set_markup (GTK_LABEL (example), example_pattern);
+ g_free (example_pattern);
+
+ entry = gtk_entry_new ();
+ gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
+ gtk_widget_set_hexpand (entry, TRUE);
+
+ grid = gtk_grid_new ();
+ g_object_set (grid,
+ "orientation", GTK_ORIENTATION_VERTICAL,
+ "border-width", 6,
+ "row-spacing", 6,
+ "column-spacing", 12,
+ NULL);
+
+ gtk_container_add (GTK_CONTAINER (grid), label);
+ gtk_grid_attach_next_to (GTK_GRID (grid), entry, label,
+ GTK_POS_RIGHT, 1, 1);
+ gtk_grid_attach_next_to (GTK_GRID (grid), example, entry,
+ GTK_POS_BOTTOM, 1, 1);
+
+ gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+ gtk_widget_show_all (grid);
+ gtk_container_add (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), grid);
+ g_object_set_data (G_OBJECT (dialog), "entry", entry);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (pattern_select_response_cb),
+ view);
+ gtk_widget_show_all (dialog);
}
static void
@@ -1598,21 +1660,23 @@ action_select_pattern (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- select_pattern(user_data);
+ select_pattern (user_data);
}
-typedef struct {
- NautilusFilesView *directory_view;
- GHashTable *added_locations;
- GList *selection;
+typedef struct
+{
+ NautilusFilesView *directory_view;
+ GHashTable *added_locations;
+ GList *selection;
} NewFolderData;
-typedef struct {
- NautilusFilesView *directory_view;
- GHashTable *to_remove_locations;
- NautilusFile *new_folder;
+typedef struct
+{
+ NautilusFilesView *directory_view;
+ GHashTable *to_remove_locations;
+ NautilusFile *new_folder;
} NewFolderSelectionData;
static void
@@ -1621,11 +1685,11 @@ track_newly_added_locations (NautilusFilesView *view,
NautilusDirectory *directory,
gpointer user_data)
{
- GHashTable *added_locations;
+ GHashTable *added_locations;
- added_locations = user_data;
+ added_locations = user_data;
- g_hash_table_add (added_locations, nautilus_file_get_location (new_file));
+ g_hash_table_add (added_locations, nautilus_file_get_location (new_file));
}
static void
@@ -1633,81 +1697,89 @@ new_folder_done (GFile *new_folder,
gboolean success,
gpointer user_data)
{
- NautilusFilesView *directory_view;
- NautilusFile *file;
- char screen_string[32];
- GdkScreen *screen;
- NewFolderData *data;
+ NautilusFilesView *directory_view;
+ NautilusFile *file;
+ char screen_string[32];
+ GdkScreen *screen;
+ NewFolderData *data;
- data = (NewFolderData *)user_data;
+ data = (NewFolderData *) user_data;
- directory_view = data->directory_view;
+ directory_view = data->directory_view;
- if (directory_view == NULL) {
- goto fail;
- }
+ if (directory_view == NULL)
+ {
+ goto fail;
+ }
- g_signal_handlers_disconnect_by_func (directory_view,
- G_CALLBACK (track_newly_added_locations),
- data->added_locations);
+ g_signal_handlers_disconnect_by_func (directory_view,
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations);
- if (new_folder == NULL) {
- goto fail;
- }
+ if (new_folder == NULL)
+ {
+ goto fail;
+ }
- screen = gtk_widget_get_screen (GTK_WIDGET (directory_view));
- g_snprintf (screen_string, sizeof (screen_string), "%d", gdk_screen_get_number (screen));
+ screen = gtk_widget_get_screen (GTK_WIDGET (directory_view));
+ g_snprintf (screen_string, sizeof (screen_string), "%d", gdk_screen_get_number (screen));
- file = nautilus_file_get (new_folder);
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_SCREEN,
- NULL,
- screen_string);
+ file = nautilus_file_get (new_folder);
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_SCREEN,
+ NULL,
+ screen_string);
- if (data->selection != NULL) {
- GList *uris, *l;
- char *target_uri;
+ if (data->selection != NULL)
+ {
+ GList *uris, *l;
+ char *target_uri;
- uris = NULL;
- for (l = data->selection; l != NULL; l = l->next) {
- uris = g_list_prepend (uris, nautilus_file_get_uri ((NautilusFile *) l->data));
- }
- uris = g_list_reverse (uris);
+ uris = NULL;
+ for (l = data->selection; l != NULL; l = l->next)
+ {
+ uris = g_list_prepend (uris, nautilus_file_get_uri ((NautilusFile *) l->data));
+ }
+ uris = g_list_reverse (uris);
- target_uri = nautilus_file_get_uri (file);
+ target_uri = nautilus_file_get_uri (file);
- nautilus_files_view_move_copy_items (directory_view,
- uris,
- NULL,
- target_uri,
- GDK_ACTION_MOVE,
- 0, 0);
- g_list_free_full (uris, g_free);
- g_free (target_uri);
- }
+ nautilus_files_view_move_copy_items (directory_view,
+ uris,
+ NULL,
+ target_uri,
+ GDK_ACTION_MOVE,
+ 0, 0);
+ g_list_free_full (uris, g_free);
+ g_free (target_uri);
+ }
- if (g_hash_table_contains (data->added_locations, new_folder)) {
- /* The file was already added */
- nautilus_files_view_select_file (directory_view, file);
- nautilus_files_view_reveal_selection (directory_view);
- } else {
- g_hash_table_insert (directory_view->details->pending_reveal,
- file,
- GUINT_TO_POINTER (TRUE));
- }
+ if (g_hash_table_contains (data->added_locations, new_folder))
+ {
+ /* The file was already added */
+ nautilus_files_view_select_file (directory_view, file);
+ nautilus_files_view_reveal_selection (directory_view);
+ }
+ else
+ {
+ g_hash_table_insert (directory_view->details->pending_reveal,
+ file,
+ GUINT_TO_POINTER (TRUE));
+ }
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
- fail:
- g_hash_table_destroy (data->added_locations);
+fail:
+ g_hash_table_destroy (data->added_locations);
- if (data->directory_view != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (data->directory_view),
- (gpointer *) &data->directory_view);
- }
+ if (data->directory_view != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (data->directory_view),
+ (gpointer *) &data->directory_view);
+ }
- nautilus_file_list_free (data->selection);
- g_free (data);
+ nautilus_file_list_free (data->selection);
+ g_free (data);
}
@@ -1715,196 +1787,205 @@ static NewFolderData *
new_folder_data_new (NautilusFilesView *directory_view,
gboolean with_selection)
{
- NewFolderData *data;
+ NewFolderData *data;
- data = g_new (NewFolderData, 1);
- data->directory_view = directory_view;
- data->added_locations = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal,
- g_object_unref, NULL);
- if (with_selection) {
- data->selection = nautilus_files_view_get_selection_for_file_transfer (directory_view);
- } else {
- data->selection = NULL;
- }
- g_object_add_weak_pointer (G_OBJECT (data->directory_view),
- (gpointer *) &data->directory_view);
+ data = g_new (NewFolderData, 1);
+ data->directory_view = directory_view;
+ data->added_locations = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
+ g_object_unref, NULL);
+ if (with_selection)
+ {
+ data->selection = nautilus_files_view_get_selection_for_file_transfer (directory_view);
+ }
+ else
+ {
+ data->selection = NULL;
+ }
+ g_object_add_weak_pointer (G_OBJECT (data->directory_view),
+ (gpointer *) &data->directory_view);
- return data;
+ return data;
}
static GdkPoint *
context_menu_to_file_operation_position (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- if (nautilus_files_view_using_manual_layout (view)
- && view->details->context_menu_position.x >= 0
- && view->details->context_menu_position.y >= 0) {
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->widget_to_file_operation_position
- (view, &view->details->context_menu_position);
- return &view->details->context_menu_position;
- } else {
- return NULL;
- }
+ if (nautilus_files_view_using_manual_layout (view)
+ && view->details->context_menu_position.x >= 0
+ && view->details->context_menu_position.y >= 0)
+ {
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->widget_to_file_operation_position
+ (view, &view->details->context_menu_position);
+ return &view->details->context_menu_position;
+ }
+ else
+ {
+ return NULL;
+ }
}
-static GdkRectangle*
+static GdkRectangle *
nautilus_files_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
{
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->compute_rename_popover_pointing_to (view);
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->compute_rename_popover_pointing_to (view);
}
static void
rename_file_popover_controller_on_name_accepted (NautilusFileNameWidgetController *controller,
gpointer user_data)
{
- NautilusFilesView *view;
- NautilusFile *target_file;
- g_autofree gchar *name;
+ NautilusFilesView *view;
+ NautilusFile *target_file;
+ g_autofree gchar *name;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- name = nautilus_file_name_widget_controller_get_new_name (controller);
+ name = nautilus_file_name_widget_controller_get_new_name (controller);
- target_file =
- nautilus_rename_file_popover_controller_get_target_file (view->details->rename_file_controller);
+ target_file =
+ nautilus_rename_file_popover_controller_get_target_file (view->details->rename_file_controller);
- /* Put it on the queue for reveal after the view acknowledges the change */
- g_hash_table_insert (view->details->pending_reveal,
- target_file,
- GUINT_TO_POINTER (FALSE));
+ /* Put it on the queue for reveal after the view acknowledges the change */
+ g_hash_table_insert (view->details->pending_reveal,
+ target_file,
+ GUINT_TO_POINTER (FALSE));
- nautilus_rename_file (target_file, name, NULL, NULL);
+ nautilus_rename_file (target_file, name, NULL, NULL);
- g_clear_object (&view->details->rename_file_controller);
+ g_clear_object (&view->details->rename_file_controller);
}
static void
rename_file_popover_controller_on_cancelled (NautilusFileNameWidgetController *controller,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- g_clear_object (&view->details->rename_file_controller);
+ g_clear_object (&view->details->rename_file_controller);
}
static void
nautilus_files_view_rename_file_popover_new (NautilusFilesView *view,
NautilusFile *target_file)
{
- GdkRectangle *pointing_to;
+ GdkRectangle *pointing_to;
- if (view->details->rename_file_controller != NULL) {
- return;
- }
+ if (view->details->rename_file_controller != NULL)
+ {
+ return;
+ }
- pointing_to = nautilus_files_view_compute_rename_popover_pointing_to (view);
+ pointing_to = nautilus_files_view_compute_rename_popover_pointing_to (view);
- view->details->rename_file_controller =
- nautilus_rename_file_popover_controller_new (target_file,
- pointing_to,
- GTK_WIDGET (view));
+ view->details->rename_file_controller =
+ nautilus_rename_file_popover_controller_new (target_file,
+ pointing_to,
+ GTK_WIDGET (view));
- g_signal_connect (view->details->rename_file_controller,
- "name-accepted",
- (GCallback)rename_file_popover_controller_on_name_accepted,
- view);
- g_signal_connect (view->details->rename_file_controller,
- "cancelled",
- (GCallback)rename_file_popover_controller_on_cancelled,
- view);
+ g_signal_connect (view->details->rename_file_controller,
+ "name-accepted",
+ (GCallback) rename_file_popover_controller_on_name_accepted,
+ view);
+ g_signal_connect (view->details->rename_file_controller,
+ "cancelled",
+ (GCallback) rename_file_popover_controller_on_cancelled,
+ view);
}
static void
new_folder_dialog_controller_on_name_accepted (NautilusFileNameWidgetController *controller,
gpointer user_data)
{
- NautilusFilesView *view;
- NewFolderData *data;
- GdkPoint *position;
- g_autofree gchar *parent_uri;
- g_autofree gchar *name;
- gboolean with_selection;
+ NautilusFilesView *view;
+ NewFolderData *data;
+ GdkPoint *position;
+ g_autofree gchar *parent_uri;
+ g_autofree gchar *name;
+ gboolean with_selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- with_selection =
- nautilus_new_folder_dialog_controller_get_with_selection (view->details->new_folder_controller);
+ with_selection =
+ nautilus_new_folder_dialog_controller_get_with_selection (view->details->new_folder_controller);
- data = new_folder_data_new (view, with_selection);
+ data = new_folder_data_new (view, with_selection);
- name = nautilus_file_name_widget_controller_get_new_name (controller);
- g_signal_connect_data (view,
- "add-file",
- G_CALLBACK (track_newly_added_locations),
- data->added_locations,
- (GClosureNotify)NULL,
- G_CONNECT_AFTER);
+ name = nautilus_file_name_widget_controller_get_new_name (controller);
+ g_signal_connect_data (view,
+ "add-file",
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations,
+ (GClosureNotify) NULL,
+ G_CONNECT_AFTER);
- position = context_menu_to_file_operation_position (view);
+ position = context_menu_to_file_operation_position (view);
- parent_uri = nautilus_files_view_get_backing_uri (view);
- nautilus_file_operations_new_folder (GTK_WIDGET (view),
- position, parent_uri, name,
- new_folder_done, data);
+ parent_uri = nautilus_files_view_get_backing_uri (view);
+ nautilus_file_operations_new_folder (GTK_WIDGET (view),
+ position, parent_uri, name,
+ new_folder_done, data);
- g_clear_object (&view->details->new_folder_controller);
+ g_clear_object (&view->details->new_folder_controller);
}
static void
new_folder_dialog_controller_on_cancelled (NautilusNewFolderDialogController *controller,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- g_clear_object (&view->details->new_folder_controller);
+ g_clear_object (&view->details->new_folder_controller);
}
static void
nautilus_files_view_new_folder_dialog_new (NautilusFilesView *view,
gboolean with_selection)
{
- NautilusDirectory *containing_directory;
- GList *selection;
- g_autofree char *uri = NULL;
- g_autofree char *common_prefix = NULL;
+ NautilusDirectory *containing_directory;
+ GList *selection;
+ g_autofree char *uri = NULL;
+ g_autofree char *common_prefix = NULL;
- if (view->details->new_folder_controller != NULL) {
- return;
- }
+ if (view->details->new_folder_controller != NULL)
+ {
+ return;
+ }
- uri = nautilus_files_view_get_backing_uri (view);
- containing_directory = nautilus_directory_get_by_uri (uri);
+ uri = nautilus_files_view_get_backing_uri (view);
+ containing_directory = nautilus_directory_get_by_uri (uri);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- common_prefix = nautilus_get_common_filename_prefix (selection, MIN_COMMON_FILENAME_PREFIX_LENGTH);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ common_prefix = nautilus_get_common_filename_prefix (selection, MIN_COMMON_FILENAME_PREFIX_LENGTH);
- view->details->new_folder_controller =
- nautilus_new_folder_dialog_controller_new (nautilus_files_view_get_containing_window (view),
- containing_directory,
- with_selection,
- common_prefix);
+ view->details->new_folder_controller =
+ nautilus_new_folder_dialog_controller_new (nautilus_files_view_get_containing_window (view),
+ containing_directory,
+ with_selection,
+ common_prefix);
- g_signal_connect (view->details->new_folder_controller,
- "name-accepted",
- (GCallback)new_folder_dialog_controller_on_name_accepted,
- view);
- g_signal_connect (view->details->new_folder_controller,
- "cancelled",
- (GCallback)new_folder_dialog_controller_on_cancelled,
- view);
+ g_signal_connect (view->details->new_folder_controller,
+ "name-accepted",
+ (GCallback) new_folder_dialog_controller_on_name_accepted,
+ view);
+ g_signal_connect (view->details->new_folder_controller,
+ "cancelled",
+ (GCallback) new_folder_dialog_controller_on_cancelled,
+ view);
- nautilus_file_list_free (selection);
- nautilus_directory_unref (containing_directory);
+ nautilus_file_list_free (selection);
+ nautilus_directory_unref (containing_directory);
}
-typedef struct {
- NautilusFilesView *view;
- GHashTable *added_locations;
+typedef struct
+{
+ NautilusFilesView *view;
+ GHashTable *added_locations;
} CompressData;
static void
@@ -1912,200 +1993,220 @@ compress_done (GFile *new_file,
gboolean success,
gpointer user_data)
{
- CompressData *data;
- NautilusFilesView *view;
- NautilusFile *file;
+ CompressData *data;
+ NautilusFilesView *view;
+ NautilusFile *file;
- data = user_data;
- view = data->view;
+ data = user_data;
+ view = data->view;
- if (view == NULL) {
- goto out;
- }
+ if (view == NULL)
+ {
+ goto out;
+ }
- g_signal_handlers_disconnect_by_func (view,
- G_CALLBACK (track_newly_added_locations),
- data->added_locations);
+ g_signal_handlers_disconnect_by_func (view,
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations);
- if (!success) {
- goto out;
- }
+ if (!success)
+ {
+ goto out;
+ }
- file = nautilus_file_get (new_file);
+ file = nautilus_file_get (new_file);
- if (g_hash_table_contains (data->added_locations, new_file)) {
- /* The file was already added */
- nautilus_files_view_select_file (view, file);
- nautilus_files_view_reveal_selection (view);
- } else {
- g_hash_table_insert (view->details->pending_reveal,
- file,
- GUINT_TO_POINTER (TRUE));
- }
+ if (g_hash_table_contains (data->added_locations, new_file))
+ {
+ /* The file was already added */
+ nautilus_files_view_select_file (view, file);
+ nautilus_files_view_reveal_selection (view);
+ }
+ else
+ {
+ g_hash_table_insert (view->details->pending_reveal,
+ file,
+ GUINT_TO_POINTER (TRUE));
+ }
- nautilus_file_unref (file);
- out:
- g_hash_table_destroy (data->added_locations);
+ nautilus_file_unref (file);
+out:
+ g_hash_table_destroy (data->added_locations);
- if (data->view != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
- }
+ if (data->view != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (data->view),
+ (gpointer *) &data->view);
+ }
- g_free (data);
+ g_free (data);
}
static void
compress_dialog_controller_on_name_accepted (NautilusFileNameWidgetController *controller,
gpointer user_data)
{
- NautilusFilesView *view;
- g_autofree gchar *name;
- GList *selection;
- GList *source_files = NULL;
- GList *l;
- CompressData *data;
- g_autoptr (GFile) output;
- NautilusCompressionFormat compression_format;
- AutoarFormat format;
- AutoarFilter filter;
-
- view = NAUTILUS_FILES_VIEW (user_data);
-
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
-
- for (l = selection; l != NULL; l = l->next) {
- source_files = g_list_prepend (source_files,
- nautilus_file_get_location (l->data));
+ NautilusFilesView *view;
+ g_autofree gchar *name;
+ GList *selection;
+ GList *source_files = NULL;
+ GList *l;
+ CompressData *data;
+ g_autoptr (GFile) output;
+ NautilusCompressionFormat compression_format;
+ AutoarFormat format;
+ AutoarFilter filter;
+
+ view = NAUTILUS_FILES_VIEW (user_data);
+
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+
+ for (l = selection; l != NULL; l = l->next)
+ {
+ source_files = g_list_prepend (source_files,
+ nautilus_file_get_location (l->data));
+ }
+ source_files = g_list_reverse (source_files);
+
+ name = nautilus_file_name_widget_controller_get_new_name (controller);
+ output = g_file_get_child (view->details->location, name);
+
+ data = g_new (CompressData, 1);
+ data->view = view;
+ data->added_locations = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal,
+ g_object_unref, NULL);
+ g_object_add_weak_pointer (G_OBJECT (data->view),
+ (gpointer *) &data->view);
+
+ g_signal_connect_data (view,
+ "add-file",
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations,
+ NULL,
+ G_CONNECT_AFTER);
+
+ compression_format = g_settings_get_enum (nautilus_compression_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT);
+
+ switch (compression_format)
+ {
+ case NAUTILUS_COMPRESSION_ZIP:
+ {
+ format = AUTOAR_FORMAT_ZIP;
+ filter = AUTOAR_FILTER_NONE;
}
- source_files = g_list_reverse (source_files);
-
- name = nautilus_file_name_widget_controller_get_new_name (controller);
- output = g_file_get_child (view->details->location, name);
-
- data = g_new (CompressData, 1);
- data->view = view;
- data->added_locations = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal,
- g_object_unref, NULL);
- g_object_add_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
+ break;
- g_signal_connect_data (view,
- "add-file",
- G_CALLBACK (track_newly_added_locations),
- data->added_locations,
- NULL,
- G_CONNECT_AFTER);
+ case NAUTILUS_COMPRESSION_TAR_XZ:
+ {
+ format = AUTOAR_FORMAT_TAR;
+ filter = AUTOAR_FILTER_XZ;
+ }
+ break;
- compression_format = g_settings_get_enum (nautilus_compression_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_COMPRESSION_FORMAT);
-
- switch (compression_format) {
- case NAUTILUS_COMPRESSION_ZIP:
- format = AUTOAR_FORMAT_ZIP;
- filter = AUTOAR_FILTER_NONE;
- break;
- case NAUTILUS_COMPRESSION_TAR_XZ:
- format = AUTOAR_FORMAT_TAR;
- filter = AUTOAR_FILTER_XZ;
- break;
- case NAUTILUS_COMPRESSION_7ZIP:
- format = AUTOAR_FORMAT_7ZIP;
- filter = AUTOAR_FILTER_NONE;
- break;
- default:
- g_assert_not_reached ();
+ case NAUTILUS_COMPRESSION_7ZIP:
+ {
+ format = AUTOAR_FORMAT_7ZIP;
+ filter = AUTOAR_FILTER_NONE;
}
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
- nautilus_file_operations_compress (source_files, output,
- format,
- filter,
- nautilus_files_view_get_containing_window (view),
- compress_done,
- data);
+ nautilus_file_operations_compress (source_files, output,
+ format,
+ filter,
+ nautilus_files_view_get_containing_window (view),
+ compress_done,
+ data);
- nautilus_file_list_free (selection);
- g_list_free_full (source_files, g_object_unref);
- g_clear_object (&view->details->compress_controller);
+ nautilus_file_list_free (selection);
+ g_list_free_full (source_files, g_object_unref);
+ g_clear_object (&view->details->compress_controller);
}
static void
compress_dialog_controller_on_cancelled (NautilusNewFolderDialogController *controller,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- g_clear_object (&view->details->compress_controller);
+ g_clear_object (&view->details->compress_controller);
}
static void
nautilus_files_view_compress_dialog_new (NautilusFilesView *view)
{
+ NautilusDirectory *containing_directory;
+ GList *selection;
+ g_autofree char *common_prefix = NULL;
- NautilusDirectory *containing_directory;
- GList *selection;
- g_autofree char *common_prefix = NULL;
+ if (view->details->compress_controller != NULL)
+ {
+ return;
+ }
- if (view->details->compress_controller != NULL) {
- return;
- }
+ containing_directory = nautilus_directory_get_by_uri (nautilus_files_view_get_backing_uri (view));
- containing_directory = nautilus_directory_get_by_uri (nautilus_files_view_get_backing_uri (view));
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ if (g_list_length (selection) == 1)
+ {
+ g_autofree char *display_name;
- if (g_list_length (selection) == 1) {
- g_autofree char *display_name;
+ display_name = nautilus_file_get_display_name (selection->data);
- display_name = nautilus_file_get_display_name (selection->data);
+ common_prefix = eel_filename_strip_extension (display_name);
+ }
+ else
+ {
+ common_prefix = nautilus_get_common_filename_prefix (selection,
+ MIN_COMMON_FILENAME_PREFIX_LENGTH);
+ }
- common_prefix = eel_filename_strip_extension (display_name);
- } else {
- common_prefix = nautilus_get_common_filename_prefix (selection,
- MIN_COMMON_FILENAME_PREFIX_LENGTH);
- }
+ view->details->compress_controller = nautilus_compress_dialog_controller_new (nautilus_files_view_get_containing_window (view),
+ containing_directory,
+ common_prefix);
- view->details->compress_controller = nautilus_compress_dialog_controller_new (nautilus_files_view_get_containing_window (view),
- containing_directory,
- common_prefix);
+ g_signal_connect (view->details->compress_controller,
+ "name-accepted",
+ (GCallback) compress_dialog_controller_on_name_accepted,
+ view);
+ g_signal_connect (view->details->compress_controller,
+ "cancelled",
+ (GCallback) compress_dialog_controller_on_cancelled,
+ view);
- g_signal_connect (view->details->compress_controller,
- "name-accepted",
- (GCallback)compress_dialog_controller_on_name_accepted,
- view);
- g_signal_connect (view->details->compress_controller,
- "cancelled",
- (GCallback)compress_dialog_controller_on_cancelled,
- view);
-
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static void
nautilus_files_view_new_folder (NautilusFilesView *directory_view,
gboolean with_selection)
{
- nautilus_files_view_new_folder_dialog_new (directory_view, with_selection);
+ nautilus_files_view_new_folder_dialog_new (directory_view, with_selection);
}
static NewFolderData *
setup_new_folder_data (NautilusFilesView *directory_view)
{
- NewFolderData *data;
+ NewFolderData *data;
- data = new_folder_data_new (directory_view, FALSE);
+ data = new_folder_data_new (directory_view, FALSE);
- g_signal_connect_data (directory_view,
- "add-file",
- G_CALLBACK (track_newly_added_locations),
- data->added_locations,
- (GClosureNotify)NULL,
- G_CONNECT_AFTER);
+ g_signal_connect_data (directory_view,
+ "add-file",
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations,
+ (GClosureNotify) NULL,
+ G_CONNECT_AFTER);
- return data;
+ return data;
}
void
@@ -2116,20 +2217,21 @@ nautilus_files_view_new_file_with_initial_contents (NautilusFilesView *view,
int length,
GdkPoint *pos)
{
- NewFolderData *data;
+ NewFolderData *data;
- g_assert (parent_uri != NULL);
+ g_assert (parent_uri != NULL);
- data = setup_new_folder_data (view);
+ data = setup_new_folder_data (view);
- if (pos == NULL) {
- pos = context_menu_to_file_operation_position (view);
- }
+ if (pos == NULL)
+ {
+ pos = context_menu_to_file_operation_position (view);
+ }
- nautilus_file_operations_new_file (GTK_WIDGET (view),
- pos, parent_uri, filename,
- initial_contents, length,
- new_folder_done, data);
+ nautilus_file_operations_new_file (GTK_WIDGET (view),
+ pos, parent_uri, filename,
+ initial_contents, length,
+ new_folder_done, data);
}
static void
@@ -2137,45 +2239,47 @@ nautilus_files_view_new_file (NautilusFilesView *directory_view,
const char *parent_uri,
NautilusFile *source)
{
- GdkPoint *pos;
- NewFolderData *data;
- char *source_uri;
- char *container_uri;
-
- container_uri = NULL;
- if (parent_uri == NULL) {
- container_uri = nautilus_files_view_get_backing_uri (directory_view);
- g_assert (container_uri != NULL);
- }
-
- if (source == NULL) {
- nautilus_files_view_new_file_with_initial_contents (directory_view,
- parent_uri != NULL ? parent_uri : container_uri,
- NULL,
- NULL,
- 0,
- NULL);
- g_free (container_uri);
- return;
- }
+ GdkPoint *pos;
+ NewFolderData *data;
+ char *source_uri;
+ char *container_uri;
+
+ container_uri = NULL;
+ if (parent_uri == NULL)
+ {
+ container_uri = nautilus_files_view_get_backing_uri (directory_view);
+ g_assert (container_uri != NULL);
+ }
+
+ if (source == NULL)
+ {
+ nautilus_files_view_new_file_with_initial_contents (directory_view,
+ parent_uri != NULL ? parent_uri : container_uri,
+ NULL,
+ NULL,
+ 0,
+ NULL);
+ g_free (container_uri);
+ return;
+ }
- g_return_if_fail (nautilus_file_is_local (source));
+ g_return_if_fail (nautilus_file_is_local (source));
- pos = context_menu_to_file_operation_position (directory_view);
+ pos = context_menu_to_file_operation_position (directory_view);
- data = setup_new_folder_data (directory_view);
+ data = setup_new_folder_data (directory_view);
- source_uri = nautilus_file_get_uri (source);
+ source_uri = nautilus_file_get_uri (source);
- nautilus_file_operations_new_file_from_template (GTK_WIDGET (directory_view),
- pos,
- parent_uri != NULL ? parent_uri : container_uri,
- NULL,
- source_uri,
- new_folder_done, data);
+ nautilus_file_operations_new_file_from_template (GTK_WIDGET (directory_view),
+ pos,
+ parent_uri != NULL ? parent_uri : container_uri,
+ NULL,
+ source_uri,
+ new_folder_done, data);
- g_free (source_uri);
- g_free (container_uri);
+ g_free (source_uri);
+ g_free (container_uri);
}
static void
@@ -2183,14 +2287,14 @@ action_new_folder (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- window = nautilus_files_view_get_window (NAUTILUS_FILES_VIEW (user_data));
- nautilus_window_hide_view_menu (window);
+ window = nautilus_files_view_get_window (NAUTILUS_FILES_VIEW (user_data));
+ nautilus_window_hide_view_menu (window);
- nautilus_files_view_new_folder (NAUTILUS_FILES_VIEW (user_data), FALSE);
+ nautilus_files_view_new_folder (NAUTILUS_FILES_VIEW (user_data), FALSE);
}
static void
@@ -2198,9 +2302,9 @@ action_new_folder_with_selection (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- nautilus_files_view_new_folder (NAUTILUS_FILES_VIEW (user_data), TRUE);
+ nautilus_files_view_new_folder (NAUTILUS_FILES_VIEW (user_data), TRUE);
}
static void
@@ -2208,47 +2312,54 @@ action_properties (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
- GList *files;
+ NautilusFilesView *view;
+ GList *selection;
+ GList *files;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- if (g_list_length (selection) == 0) {
- if (view->details->directory_as_file != NULL) {
- files = g_list_append (NULL, nautilus_file_ref (view->details->directory_as_file));
+ view = NAUTILUS_FILES_VIEW (user_data);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ if (g_list_length (selection) == 0)
+ {
+ if (view->details->directory_as_file != NULL)
+ {
+ files = g_list_append (NULL, nautilus_file_ref (view->details->directory_as_file));
- nautilus_properties_window_present (files, GTK_WIDGET (view), NULL);
+ nautilus_properties_window_present (files, GTK_WIDGET (view), NULL);
- nautilus_file_list_free (files);
- }
- } else {
- nautilus_properties_window_present (selection, GTK_WIDGET (view), NULL);
+ nautilus_file_list_free (files);
}
- nautilus_file_list_free (selection);
+ }
+ else
+ {
+ nautilus_properties_window_present (selection, GTK_WIDGET (view), NULL);
+ }
+ nautilus_file_list_free (selection);
}
static void
nautilus_files_view_set_show_hidden_files (NautilusFilesView *view,
gboolean show_hidden)
{
- if (view->details->ignore_hidden_file_preferences) {
- return;
- }
+ if (view->details->ignore_hidden_file_preferences)
+ {
+ return;
+ }
- if (show_hidden != view->details->show_hidden_files) {
- view->details->show_hidden_files = show_hidden;
+ if (show_hidden != view->details->show_hidden_files)
+ {
+ view->details->show_hidden_files = show_hidden;
- g_settings_set_boolean (gtk_filechooser_preferences,
- NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
- show_hidden);
+ g_settings_set_boolean (gtk_filechooser_preferences,
+ NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
+ show_hidden);
- if (view->details->model != NULL) {
- load_directory (view, view->details->model);
- }
+ if (view->details->model != NULL)
+ {
+ load_directory (view, view->details->model);
}
+ }
}
static void
@@ -2256,17 +2367,17 @@ action_show_hidden_files (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- gboolean show_hidden;
- NautilusFilesView *view;
+ gboolean show_hidden;
+ NautilusFilesView *view;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
- show_hidden = g_variant_get_boolean (state);
+ view = NAUTILUS_FILES_VIEW (user_data);
+ show_hidden = g_variant_get_boolean (state);
- nautilus_files_view_set_show_hidden_files (view, show_hidden);
+ nautilus_files_view_set_show_hidden_files (view, show_hidden);
- g_simple_action_set_state (action, state);
+ g_simple_action_set_state (action, state);
}
static void
@@ -2274,13 +2385,13 @@ action_zoom_in (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- nautilus_files_view_bump_zoom_level (view, 1);
+ nautilus_files_view_bump_zoom_level (view, 1);
}
static void
@@ -2288,13 +2399,13 @@ action_zoom_out (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- nautilus_files_view_bump_zoom_level (view, -1);
+ nautilus_files_view_bump_zoom_level (view, -1);
}
static void
@@ -2302,7 +2413,7 @@ action_zoom_standard (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- nautilus_files_view_restore_standard_zoom_level (user_data);
+ nautilus_files_view_restore_standard_zoom_level (user_data);
}
static void
@@ -2310,19 +2421,20 @@ action_open_item_new_window (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GtkWindow *window;
- GList *selection;
+ NautilusFilesView *view;
+ GtkWindow *window;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- window = GTK_WINDOW (nautilus_files_view_get_containing_window (view));
+ view = NAUTILUS_FILES_VIEW (user_data);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ window = GTK_WINDOW (nautilus_files_view_get_containing_window (view));
- if (nautilus_files_view_confirm_multiple (window, g_list_length (selection), TRUE)) {
- g_list_foreach (selection, open_one_in_new_window, view);
- }
+ if (nautilus_files_view_confirm_multiple (window, g_list_length (selection), TRUE))
+ {
+ g_list_foreach (selection, open_one_in_new_window, view);
+ }
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static void
@@ -2331,23 +2443,25 @@ handle_clipboard_data (NautilusFilesView *view,
char *destination_uri,
GdkDragAction action)
{
- GList *item_uris;
+ GList *item_uris;
- item_uris = nautilus_clipboard_get_uri_list_from_selection_data (selection_data, NULL,
- copied_files_atom);
+ item_uris = nautilus_clipboard_get_uri_list_from_selection_data (selection_data, NULL,
+ copied_files_atom);
- if (item_uris != NULL && destination_uri != NULL) {
- nautilus_files_view_move_copy_items (view, item_uris, NULL, destination_uri,
- action,
- 0, 0);
-
- /* If items are cut then remove from clipboard */
- if (action == GDK_ACTION_MOVE) {
- gtk_clipboard_clear (nautilus_clipboard_get (GTK_WIDGET (view)));
- }
+ if (item_uris != NULL && destination_uri != NULL)
+ {
+ nautilus_files_view_move_copy_items (view, item_uris, NULL, destination_uri,
+ action,
+ 0, 0);
- g_list_free_full (item_uris, g_free);
+ /* If items are cut then remove from clipboard */
+ if (action == GDK_ACTION_MOVE)
+ {
+ gtk_clipboard_clear (nautilus_clipboard_get (GTK_WIDGET (view)));
}
+
+ g_list_free_full (item_uris, g_free);
+ }
}
static void
@@ -2355,12 +2469,12 @@ paste_clipboard_data (NautilusFilesView *view,
GtkSelectionData *selection_data,
char *destination_uri)
{
- GdkDragAction action;
+ GdkDragAction action;
- action = nautilus_clipboard_monitor_is_cut (nautilus_clipboard_monitor_get ()) ?
- GDK_ACTION_MOVE : GDK_ACTION_COPY;
+ action = nautilus_clipboard_monitor_is_cut (nautilus_clipboard_monitor_get ()) ?
+ GDK_ACTION_MOVE : GDK_ACTION_COPY;
- handle_clipboard_data (view, selection_data, destination_uri, action);
+ handle_clipboard_data (view, selection_data, destination_uri, action);
}
static void
@@ -2368,20 +2482,21 @@ paste_clipboard_received_callback (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
gpointer data)
{
- NautilusFilesView *view;
- char *view_uri;
+ NautilusFilesView *view;
+ char *view_uri;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- view_uri = nautilus_files_view_get_backing_uri (view);
+ view_uri = nautilus_files_view_get_backing_uri (view);
- if (view->details->slot != NULL) {
- paste_clipboard_data (view, selection_data, view_uri);
- }
+ if (view->details->slot != NULL)
+ {
+ paste_clipboard_data (view, selection_data, view_uri);
+ }
- g_free (view_uri);
+ g_free (view_uri);
- g_object_unref (view);
+ g_object_unref (view);
}
static void
@@ -2389,17 +2504,17 @@ action_paste_files (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- g_object_ref (view);
- gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
- copied_files_atom,
- paste_clipboard_received_callback,
- view);
+ g_object_ref (view);
+ gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
+ copied_files_atom,
+ paste_clipboard_received_callback,
+ view);
}
static void
@@ -2407,20 +2522,21 @@ create_links_clipboard_received_callback (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
gpointer data)
{
- NautilusFilesView *view;
- char *view_uri;
+ NautilusFilesView *view;
+ char *view_uri;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- view_uri = nautilus_files_view_get_backing_uri (view);
+ view_uri = nautilus_files_view_get_backing_uri (view);
- if (view->details->slot != NULL) {
- handle_clipboard_data (view, selection_data, view_uri, GDK_ACTION_LINK);
- }
+ if (view->details->slot != NULL)
+ {
+ handle_clipboard_data (view, selection_data, view_uri, GDK_ACTION_LINK);
+ }
- g_free (view_uri);
+ g_free (view_uri);
- g_object_unref (view);
+ g_object_unref (view);
}
static void
@@ -2428,163 +2544,173 @@ action_create_links (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- g_object_ref (view);
- gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
- copied_files_atom,
- create_links_clipboard_received_callback,
- view);
+ g_object_ref (view);
+ gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
+ copied_files_atom,
+ create_links_clipboard_received_callback,
+ view);
}
static void
click_policy_changed_callback (gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->click_policy_changed (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->click_policy_changed (view);
}
gboolean
nautilus_files_view_should_sort_directories_first (NautilusFilesView *view)
{
- return view->details->sort_directories_first;
+ return view->details->sort_directories_first;
}
static void
sort_directories_first_changed_callback (gpointer callback_data)
{
- NautilusFilesView *view;
- gboolean preference_value;
+ NautilusFilesView *view;
+ gboolean preference_value;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- preference_value =
- g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+ preference_value =
+ g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
- if (preference_value != view->details->sort_directories_first) {
- view->details->sort_directories_first = preference_value;
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->sort_directories_first_changed (view);
- }
+ if (preference_value != view->details->sort_directories_first)
+ {
+ view->details->sort_directories_first = preference_value;
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->sort_directories_first_changed (view);
+ }
}
static void
show_hidden_files_changed_callback (gpointer callback_data)
{
- NautilusFilesView *view;
- gboolean preference_value;
+ NautilusFilesView *view;
+ gboolean preference_value;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- preference_value =
- g_settings_get_boolean (gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
+ preference_value =
+ g_settings_get_boolean (gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
- nautilus_files_view_set_show_hidden_files (view, preference_value);
+ nautilus_files_view_set_show_hidden_files (view, preference_value);
}
static gboolean
set_up_scripts_directory_global (void)
{
- g_autofree gchar *old_scripts_directory_path = NULL;
- g_autoptr (GFile) old_scripts_directory = NULL;
- g_autofree gchar *scripts_directory_path = NULL;
- g_autoptr (GFile) scripts_directory = NULL;
- const char *override;
- GFileType file_type;
- g_autoptr (GError) error = NULL;
-
- if (scripts_directory_uri != NULL) {
- return TRUE;
- }
-
- scripts_directory_path = nautilus_get_scripts_directory_path ();
-
- override = g_getenv ("GNOME22_USER_DIR");
-
- if (override) {
- old_scripts_directory_path = g_build_filename (override,
- "nautilus-scripts",
- NULL);
- } else {
- old_scripts_directory_path = g_build_filename (g_get_home_dir (),
- ".gnome2",
- "nautilus-scripts",
- NULL);
- }
-
- old_scripts_directory = g_file_new_for_path (old_scripts_directory_path);
- scripts_directory = g_file_new_for_path (scripts_directory_path);
+ g_autofree gchar *old_scripts_directory_path = NULL;
+ g_autoptr (GFile) old_scripts_directory = NULL;
+ g_autofree gchar *scripts_directory_path = NULL;
+ g_autoptr (GFile) scripts_directory = NULL;
+ const char *override;
+ GFileType file_type;
+ g_autoptr (GError) error = NULL;
- file_type = g_file_query_file_type (old_scripts_directory,
- G_FILE_QUERY_INFO_NONE,
- NULL);
-
- if (file_type == G_FILE_TYPE_DIRECTORY &&
- !g_file_query_exists (scripts_directory, NULL)) {
- g_autoptr (GFile) updated;
- const char *message;
-
- /* test if we already attempted to migrate first */
- updated = g_file_get_child (old_scripts_directory, "DEPRECATED-DIRECTORY");
- message = _("Nautilus 3.6 deprecated this directory and tried migrating "
- "this configuration to ~/.local/share/nautilus");
- if (!g_file_query_exists (updated, NULL)) {
- g_autoptr (GFile) parent = g_file_get_parent (scripts_directory);
- g_autoptr (GError) error = NULL;
-
- g_file_make_directory_with_parents (parent, NULL, &error);
-
- if (error == NULL ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
- g_clear_error (&error);
-
- g_file_set_attribute_uint32 (parent,
- G_FILE_ATTRIBUTE_UNIX_MODE,
- S_IRWXU,
- G_FILE_QUERY_INFO_NONE,
- NULL, NULL);
-
- g_file_move (old_scripts_directory,
- scripts_directory,
- G_FILE_COPY_NONE,
- NULL, NULL, NULL,
- &error);
-
- if (error == NULL) {
- g_file_replace_contents (updated,
- message, strlen (message),
- NULL,
- FALSE,
- G_FILE_CREATE_PRIVATE,
- NULL, NULL, NULL);
- }
- }
-
- g_clear_error (&error);
- }
- }
-
- g_file_make_directory_with_parents (scripts_directory, NULL, &error);
+ if (scripts_directory_uri != NULL)
+ {
+ return TRUE;
+ }
+
+ scripts_directory_path = nautilus_get_scripts_directory_path ();
+
+ override = g_getenv ("GNOME22_USER_DIR");
+
+ if (override)
+ {
+ old_scripts_directory_path = g_build_filename (override,
+ "nautilus-scripts",
+ NULL);
+ }
+ else
+ {
+ old_scripts_directory_path = g_build_filename (g_get_home_dir (),
+ ".gnome2",
+ "nautilus-scripts",
+ NULL);
+ }
+
+ old_scripts_directory = g_file_new_for_path (old_scripts_directory_path);
+ scripts_directory = g_file_new_for_path (scripts_directory_path);
+
+ file_type = g_file_query_file_type (old_scripts_directory,
+ G_FILE_QUERY_INFO_NONE,
+ NULL);
- if (error == NULL ||
- g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
- g_file_set_attribute_uint32 (scripts_directory,
+ if (file_type == G_FILE_TYPE_DIRECTORY &&
+ !g_file_query_exists (scripts_directory, NULL))
+ {
+ g_autoptr (GFile) updated;
+ const char *message;
+
+ /* test if we already attempted to migrate first */
+ updated = g_file_get_child (old_scripts_directory, "DEPRECATED-DIRECTORY");
+ message = _("Nautilus 3.6 deprecated this directory and tried migrating "
+ "this configuration to ~/.local/share/nautilus");
+ if (!g_file_query_exists (updated, NULL))
+ {
+ g_autoptr (GFile) parent = g_file_get_parent (scripts_directory);
+ g_autoptr (GError) error = NULL;
+
+ g_file_make_directory_with_parents (parent, NULL, &error);
+
+ if (error == NULL ||
+ g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+ {
+ g_clear_error (&error);
+
+ g_file_set_attribute_uint32 (parent,
G_FILE_ATTRIBUTE_UNIX_MODE,
S_IRWXU,
G_FILE_QUERY_INFO_NONE,
NULL, NULL);
- scripts_directory_uri = g_file_get_uri (scripts_directory);
- scripts_directory_uri_length = strlen (scripts_directory_uri);
+ g_file_move (old_scripts_directory,
+ scripts_directory,
+ G_FILE_COPY_NONE,
+ NULL, NULL, NULL,
+ &error);
+
+ if (error == NULL)
+ {
+ g_file_replace_contents (updated,
+ message, strlen (message),
+ NULL,
+ FALSE,
+ G_FILE_CREATE_PRIVATE,
+ NULL, NULL, NULL);
+ }
+ }
+
+ g_clear_error (&error);
}
+ }
+
+ g_file_make_directory_with_parents (scripts_directory, NULL, &error);
+
+ if (error == NULL ||
+ g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS))
+ {
+ g_file_set_attribute_uint32 (scripts_directory,
+ G_FILE_ATTRIBUTE_UNIX_MODE,
+ S_IRWXU,
+ G_FILE_QUERY_INFO_NONE,
+ NULL, NULL);
- return scripts_directory_uri != NULL;
+ scripts_directory_uri = g_file_get_uri (scripts_directory);
+ scripts_directory_uri_length = strlen (scripts_directory_uri);
+ }
+
+ return scripts_directory_uri != NULL;
}
static void
@@ -2592,13 +2718,14 @@ scripts_added_or_changed_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- if (view->details->active) {
- schedule_update_context_menus (view);
- }
+ if (view->details->active)
+ {
+ schedule_update_context_menus (view);
+ }
}
static void
@@ -2606,13 +2733,14 @@ templates_added_or_changed_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- if (view->details->active) {
- schedule_update_context_menus (view);
- }
+ if (view->details->active)
+ {
+ schedule_update_context_menus (view);
+ }
}
static void
@@ -2621,27 +2749,28 @@ add_directory_to_directory_list (NautilusFilesView *view,
GList **directory_list,
GCallback changed_callback)
{
- NautilusFileAttributes attributes;
+ NautilusFileAttributes attributes;
- if (g_list_find (*directory_list, directory) == NULL) {
- nautilus_directory_ref (directory);
+ if (g_list_find (*directory_list, directory) == NULL)
+ {
+ nautilus_directory_ref (directory);
- attributes =
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT;
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT;
- nautilus_directory_file_monitor_add (directory, directory_list,
- FALSE, attributes,
- (NautilusDirectoryCallback)changed_callback, view);
+ nautilus_directory_file_monitor_add (directory, directory_list,
+ FALSE, attributes,
+ (NautilusDirectoryCallback) changed_callback, view);
- g_signal_connect_object (directory, "files-added",
- G_CALLBACK (changed_callback), view, 0);
- g_signal_connect_object (directory, "files-changed",
- G_CALLBACK (changed_callback), view, 0);
+ g_signal_connect_object (directory, "files-added",
+ G_CALLBACK (changed_callback), view, 0);
+ g_signal_connect_object (directory, "files-changed",
+ G_CALLBACK (changed_callback), view, 0);
- *directory_list = g_list_append (*directory_list, directory);
- }
+ *directory_list = g_list_append (*directory_list, directory);
+ }
}
static void
@@ -2650,15 +2779,15 @@ remove_directory_from_directory_list (NautilusFilesView *view,
GList **directory_list,
GCallback changed_callback)
{
- *directory_list = g_list_remove (*directory_list, directory);
+ *directory_list = g_list_remove (*directory_list, directory);
- g_signal_handlers_disconnect_by_func (directory,
- G_CALLBACK (changed_callback),
- view);
+ g_signal_handlers_disconnect_by_func (directory,
+ G_CALLBACK (changed_callback),
+ view);
- nautilus_directory_file_monitor_remove (directory, directory_list);
+ nautilus_directory_file_monitor_remove (directory, directory_list);
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
}
@@ -2666,243 +2795,257 @@ static void
add_directory_to_scripts_directory_list (NautilusFilesView *view,
NautilusDirectory *directory)
{
- add_directory_to_directory_list (view, directory,
- &view->details->scripts_directory_list,
- G_CALLBACK (scripts_added_or_changed_callback));
+ add_directory_to_directory_list (view, directory,
+ &view->details->scripts_directory_list,
+ G_CALLBACK (scripts_added_or_changed_callback));
}
static void
remove_directory_from_scripts_directory_list (NautilusFilesView *view,
NautilusDirectory *directory)
{
- remove_directory_from_directory_list (view, directory,
- &view->details->scripts_directory_list,
- G_CALLBACK (scripts_added_or_changed_callback));
+ remove_directory_from_directory_list (view, directory,
+ &view->details->scripts_directory_list,
+ G_CALLBACK (scripts_added_or_changed_callback));
}
static void
add_directory_to_templates_directory_list (NautilusFilesView *view,
NautilusDirectory *directory)
{
- add_directory_to_directory_list (view, directory,
- &view->details->templates_directory_list,
- G_CALLBACK (templates_added_or_changed_callback));
+ add_directory_to_directory_list (view, directory,
+ &view->details->templates_directory_list,
+ G_CALLBACK (templates_added_or_changed_callback));
}
static void
remove_directory_from_templates_directory_list (NautilusFilesView *view,
NautilusDirectory *directory)
{
- remove_directory_from_directory_list (view, directory,
- &view->details->templates_directory_list,
- G_CALLBACK (templates_added_or_changed_callback));
+ remove_directory_from_directory_list (view, directory,
+ &view->details->templates_directory_list,
+ G_CALLBACK (templates_added_or_changed_callback));
}
static void
slot_active (NautilusWindowSlot *slot,
NautilusFilesView *view)
{
- if (view->details->active) {
- return;
- }
+ if (view->details->active)
+ {
+ return;
+ }
- view->details->active = TRUE;
+ view->details->active = TRUE;
- /* Avoid updating the toolbar withouth making sure the toolbar
- * zoom slider has the correct adjustment that changes when the
- * view mode changes
- */
- nautilus_files_view_update_context_menus(view);
- nautilus_files_view_update_toolbar_menus (view);
+ /* Avoid updating the toolbar withouth making sure the toolbar
+ * zoom slider has the correct adjustment that changes when the
+ * view mode changes
+ */
+ nautilus_files_view_update_context_menus (view);
+ nautilus_files_view_update_toolbar_menus (view);
- schedule_update_context_menus (view);
+ schedule_update_context_menus (view);
- gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
- "view",
- G_ACTION_GROUP (view->details->view_action_group));
+ gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
+ "view",
+ G_ACTION_GROUP (view->details->view_action_group));
}
static void
slot_inactive (NautilusWindowSlot *slot,
NautilusFilesView *view)
{
- if (!view->details->active) {
- return;
- }
+ if (!view->details->active)
+ {
+ return;
+ }
- view->details->active = FALSE;
+ view->details->active = FALSE;
- remove_update_context_menus_timeout_callback (view);
- gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
- "view",
- NULL);
+ remove_update_context_menus_timeout_callback (view);
+ gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
+ "view",
+ NULL);
}
static void
nautilus_files_view_grab_focus (GtkWidget *widget)
{
- /* focus the child of the scrolled window if it exists */
- NautilusFilesView *view;
- GtkWidget *child;
+ /* focus the child of the scrolled window if it exists */
+ NautilusFilesView *view;
+ GtkWidget *child;
- view = NAUTILUS_FILES_VIEW (widget);
- child = gtk_bin_get_child (GTK_BIN (view->details->scrolled_window));
+ view = NAUTILUS_FILES_VIEW (widget);
+ child = gtk_bin_get_child (GTK_BIN (view->details->scrolled_window));
- GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->grab_focus (widget);
+ GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->grab_focus (widget);
- if (child) {
- gtk_widget_grab_focus (GTK_WIDGET (child));
- }
+ if (child)
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (child));
+ }
}
static void
nautilus_files_view_set_selection (NautilusView *nautilus_files_view,
GList *selection)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (nautilus_files_view);
+ view = NAUTILUS_FILES_VIEW (nautilus_files_view);
- if (!view->details->loading) {
- /* If we aren't still loading, set the selection right now,
- * and reveal the new selection.
- */
- nautilus_files_view_call_set_selection (view, selection);
- nautilus_files_view_reveal_selection (view);
- } else {
- /* If we are still loading, set the list of pending URIs instead.
- * done_loading() will eventually select the pending URIs and reveal them.
- */
- g_list_free_full (view->details->pending_selection, g_object_unref);
- view->details->pending_selection =
- g_list_copy_deep (selection, (GCopyFunc) g_object_ref, NULL);
- }
+ if (!view->details->loading)
+ {
+ /* If we aren't still loading, set the selection right now,
+ * and reveal the new selection.
+ */
+ nautilus_files_view_call_set_selection (view, selection);
+ nautilus_files_view_reveal_selection (view);
+ }
+ else
+ {
+ /* If we are still loading, set the list of pending URIs instead.
+ * done_loading() will eventually select the pending URIs and reveal them.
+ */
+ g_list_free_full (view->details->pending_selection, g_object_unref);
+ view->details->pending_selection =
+ g_list_copy_deep (selection, (GCopyFunc) g_object_ref, NULL);
+ }
}
static char *
get_bulk_rename_tool ()
{
- char *bulk_rename_tool;
- g_settings_get (nautilus_preferences, NAUTILUS_PREFERENCES_BULK_RENAME_TOOL, "^ay", &bulk_rename_tool);
- return g_strstrip (bulk_rename_tool);
+ char *bulk_rename_tool;
+ g_settings_get (nautilus_preferences, NAUTILUS_PREFERENCES_BULK_RENAME_TOOL, "^ay", &bulk_rename_tool);
+ return g_strstrip (bulk_rename_tool);
}
static gboolean
have_bulk_rename_tool ()
{
- char *bulk_rename_tool;
- gboolean have_tool;
+ char *bulk_rename_tool;
+ gboolean have_tool;
- bulk_rename_tool = get_bulk_rename_tool ();
- have_tool = ((bulk_rename_tool != NULL) && (*bulk_rename_tool != '\0'));
- g_free (bulk_rename_tool);
- return have_tool;
+ bulk_rename_tool = get_bulk_rename_tool ();
+ have_tool = ((bulk_rename_tool != NULL) && (*bulk_rename_tool != '\0'));
+ g_free (bulk_rename_tool);
+ return have_tool;
}
static void
nautilus_files_view_destroy (GtkWidget *object)
{
- NautilusFilesView *view;
- GList *node, *next;
+ NautilusFilesView *view;
+ GList *node, *next;
- view = NAUTILUS_FILES_VIEW (object);
+ view = NAUTILUS_FILES_VIEW (object);
- view->details->in_destruction = TRUE;
- nautilus_files_view_stop_loading (view);
+ view->details->in_destruction = TRUE;
+ nautilus_files_view_stop_loading (view);
- if (view->details->model) {
- nautilus_directory_unref (view->details->model);
- view->details->model = NULL;
- }
+ if (view->details->model)
+ {
+ nautilus_directory_unref (view->details->model);
+ view->details->model = NULL;
+ }
- for (node = view->details->scripts_directory_list; node != NULL; node = next) {
- next = node->next;
- remove_directory_from_scripts_directory_list (view, node->data);
- }
+ for (node = view->details->scripts_directory_list; node != NULL; node = next)
+ {
+ next = node->next;
+ remove_directory_from_scripts_directory_list (view, node->data);
+ }
- for (node = view->details->templates_directory_list; node != NULL; node = next) {
- next = node->next;
- remove_directory_from_templates_directory_list (view, node->data);
- }
+ for (node = view->details->templates_directory_list; node != NULL; node = next)
+ {
+ next = node->next;
+ remove_directory_from_templates_directory_list (view, node->data);
+ }
- while (view->details->subdirectory_list != NULL) {
- nautilus_files_view_remove_subdirectory (view,
- view->details->subdirectory_list->data);
- }
+ while (view->details->subdirectory_list != NULL)
+ {
+ nautilus_files_view_remove_subdirectory (view,
+ view->details->subdirectory_list->data);
+ }
- remove_update_context_menus_timeout_callback (view);
- remove_update_status_idle_callback (view);
+ remove_update_context_menus_timeout_callback (view);
+ remove_update_status_idle_callback (view);
- if (view->details->display_selection_idle_id != 0) {
- g_source_remove (view->details->display_selection_idle_id);
- view->details->display_selection_idle_id = 0;
- }
+ if (view->details->display_selection_idle_id != 0)
+ {
+ g_source_remove (view->details->display_selection_idle_id);
+ view->details->display_selection_idle_id = 0;
+ }
- if (view->details->reveal_selection_idle_id != 0) {
- g_source_remove (view->details->reveal_selection_idle_id);
- view->details->reveal_selection_idle_id = 0;
- }
+ if (view->details->reveal_selection_idle_id != 0)
+ {
+ g_source_remove (view->details->reveal_selection_idle_id);
+ view->details->reveal_selection_idle_id = 0;
+ }
- if (view->details->floating_bar_set_status_timeout_id != 0) {
- g_source_remove (view->details->floating_bar_set_status_timeout_id);
- view->details->floating_bar_set_status_timeout_id = 0;
- }
+ if (view->details->floating_bar_set_status_timeout_id != 0)
+ {
+ g_source_remove (view->details->floating_bar_set_status_timeout_id);
+ view->details->floating_bar_set_status_timeout_id = 0;
+ }
- if (view->details->floating_bar_loading_timeout_id != 0) {
- g_source_remove (view->details->floating_bar_loading_timeout_id);
- view->details->floating_bar_loading_timeout_id = 0;
- }
+ if (view->details->floating_bar_loading_timeout_id != 0)
+ {
+ g_source_remove (view->details->floating_bar_loading_timeout_id);
+ view->details->floating_bar_loading_timeout_id = 0;
+ }
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- schedule_update_context_menus, view);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- click_policy_changed_callback, view);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- sort_directories_first_changed_callback, view);
- g_signal_handlers_disconnect_by_func (gtk_filechooser_preferences,
- show_hidden_files_changed_callback, view);
- g_signal_handlers_disconnect_by_func (nautilus_window_state,
- nautilus_files_view_display_selection_info, view);
- g_signal_handlers_disconnect_by_func (gnome_lockdown_preferences,
- schedule_update_context_menus, view);
- g_signal_handlers_disconnect_by_func (nautilus_trash_monitor_get (),
- nautilus_files_view_trash_state_changed_callback, view);
- g_signal_handlers_disconnect_by_func (nautilus_clipboard_monitor_get (),
- clipboard_changed_callback, view);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ schedule_update_context_menus, view);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ click_policy_changed_callback, view);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ sort_directories_first_changed_callback, view);
+ g_signal_handlers_disconnect_by_func (gtk_filechooser_preferences,
+ show_hidden_files_changed_callback, view);
+ g_signal_handlers_disconnect_by_func (nautilus_window_state,
+ nautilus_files_view_display_selection_info, view);
+ g_signal_handlers_disconnect_by_func (gnome_lockdown_preferences,
+ schedule_update_context_menus, view);
+ g_signal_handlers_disconnect_by_func (nautilus_trash_monitor_get (),
+ nautilus_files_view_trash_state_changed_callback, view);
+ g_signal_handlers_disconnect_by_func (nautilus_clipboard_monitor_get (),
+ clipboard_changed_callback, view);
- nautilus_file_unref (view->details->directory_as_file);
- view->details->directory_as_file = NULL;
+ nautilus_file_unref (view->details->directory_as_file);
+ view->details->directory_as_file = NULL;
- g_clear_object (&view->details->search_query);
- g_clear_object (&view->details->location);
+ g_clear_object (&view->details->search_query);
+ g_clear_object (&view->details->location);
- /* We don't own the slot, so no unref */
- view->details->slot = NULL;
+ /* We don't own the slot, so no unref */
+ view->details->slot = NULL;
- GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->destroy (object);
}
static void
nautilus_files_view_finalize (GObject *object)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (object);
+ view = NAUTILUS_FILES_VIEW (object);
- g_clear_object (&view->details->view_action_group);
- g_clear_object (&view->details->background_menu);
- g_clear_object (&view->details->selection_menu);
- g_clear_object (&view->details->toolbar_menu_sections->zoom_section);
- g_clear_object (&view->details->toolbar_menu_sections->extended_section);
- g_clear_object (&view->details->rename_file_controller);
- g_clear_object (&view->details->new_folder_controller);
- g_clear_object (&view->details->compress_controller);
- g_free (view->details->toolbar_menu_sections);
+ g_clear_object (&view->details->view_action_group);
+ g_clear_object (&view->details->background_menu);
+ g_clear_object (&view->details->selection_menu);
+ g_clear_object (&view->details->toolbar_menu_sections->zoom_section);
+ g_clear_object (&view->details->toolbar_menu_sections->extended_section);
+ g_clear_object (&view->details->rename_file_controller);
+ g_clear_object (&view->details->new_folder_controller);
+ g_clear_object (&view->details->compress_controller);
+ g_free (view->details->toolbar_menu_sections);
- g_hash_table_destroy (view->details->non_ready_files);
- g_hash_table_destroy (view->details->pending_reveal);
+ g_hash_table_destroy (view->details->non_ready_files);
+ g_hash_table_destroy (view->details->pending_reveal);
- G_OBJECT_CLASS (nautilus_files_view_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_files_view_parent_class)->finalize (object);
}
/**
@@ -2915,328 +3058,388 @@ nautilus_files_view_finalize (GObject *object)
void
nautilus_files_view_display_selection_info (NautilusFilesView *view)
{
- GList *selection;
- goffset non_folder_size;
- gboolean non_folder_size_known;
- guint non_folder_count, folder_count, folder_item_count;
- gboolean folder_item_count_known;
- guint file_item_count;
- GList *p;
- char *first_item_name;
- char *non_folder_count_str;
- char *non_folder_item_count_str;
- char *folder_count_str;
- char *folder_item_count_str;
- char *primary_status;
- char *detail_status;
- NautilusFile *file;
-
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
-
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
-
- folder_item_count_known = TRUE;
- folder_count = 0;
- folder_item_count = 0;
- non_folder_count = 0;
- non_folder_size_known = FALSE;
- non_folder_size = 0;
- first_item_name = NULL;
- folder_count_str = NULL;
- folder_item_count_str = NULL;
- non_folder_count_str = NULL;
- non_folder_item_count_str = NULL;
-
- for (p = selection; p != NULL; p = p->next) {
- file = p->data;
- if (nautilus_file_is_directory (file)) {
- folder_count++;
- if (nautilus_file_get_directory_item_count (file, &file_item_count, NULL)) {
- folder_item_count += file_item_count;
- } else {
- folder_item_count_known = FALSE;
- }
- } else {
- non_folder_count++;
- if (!nautilus_file_can_get_size (file)) {
- non_folder_size_known = TRUE;
- non_folder_size += nautilus_file_get_size (file);
- }
- }
-
- if (first_item_name == NULL) {
- first_item_name = nautilus_file_get_display_name (file);
- }
+ GList *selection;
+ goffset non_folder_size;
+ gboolean non_folder_size_known;
+ guint non_folder_count, folder_count, folder_item_count;
+ gboolean folder_item_count_known;
+ guint file_item_count;
+ GList *p;
+ char *first_item_name;
+ char *non_folder_count_str;
+ char *non_folder_item_count_str;
+ char *folder_count_str;
+ char *folder_item_count_str;
+ char *primary_status;
+ char *detail_status;
+ NautilusFile *file;
+
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+
+ folder_item_count_known = TRUE;
+ folder_count = 0;
+ folder_item_count = 0;
+ non_folder_count = 0;
+ non_folder_size_known = FALSE;
+ non_folder_size = 0;
+ first_item_name = NULL;
+ folder_count_str = NULL;
+ folder_item_count_str = NULL;
+ non_folder_count_str = NULL;
+ non_folder_item_count_str = NULL;
+
+ for (p = selection; p != NULL; p = p->next)
+ {
+ file = p->data;
+ if (nautilus_file_is_directory (file))
+ {
+ folder_count++;
+ if (nautilus_file_get_directory_item_count (file, &file_item_count, NULL))
+ {
+ folder_item_count += file_item_count;
+ }
+ else
+ {
+ folder_item_count_known = FALSE;
+ }
+ }
+ else
+ {
+ non_folder_count++;
+ if (!nautilus_file_can_get_size (file))
+ {
+ non_folder_size_known = TRUE;
+ non_folder_size += nautilus_file_get_size (file);
+ }
}
- nautilus_file_list_free (selection);
-
- /* Break out cases for localization's sake. But note that there are still pieces
- * being assembled in a particular order, which may be a problem for some localizers.
- */
+ if (first_item_name == NULL)
+ {
+ first_item_name = nautilus_file_get_display_name (file);
+ }
+ }
- if (folder_count != 0) {
- if (folder_count == 1 && non_folder_count == 0) {
- folder_count_str = g_strdup_printf (_("“%s” selected"), first_item_name);
- } else {
- folder_count_str = g_strdup_printf (ngettext("%'d folder selected",
- "%'d folders selected",
- folder_count),
- folder_count);
- }
+ nautilus_file_list_free (selection);
- if (folder_count == 1) {
- if (!folder_item_count_known) {
- folder_item_count_str = g_strdup ("");
- } else {
- folder_item_count_str = g_strdup_printf (ngettext("(containing %'d item)",
- "(containing %'d items)",
- folder_item_count),
- folder_item_count);
- }
- }
- else {
- if (!folder_item_count_known) {
- folder_item_count_str = g_strdup ("");
- } else {
- /* translators: this is preceded with a string of form 'N folders' (N more than 1) */
- folder_item_count_str = g_strdup_printf (ngettext("(containing a total of %'d item)",
- "(containing a total of %'d items)",
- folder_item_count),
- folder_item_count);
- }
+ /* Break out cases for localization's sake. But note that there are still pieces
+ * being assembled in a particular order, which may be a problem for some localizers.
+ */
- }
+ if (folder_count != 0)
+ {
+ if (folder_count == 1 && non_folder_count == 0)
+ {
+ folder_count_str = g_strdup_printf (_("“%s” selected"), first_item_name);
+ }
+ else
+ {
+ folder_count_str = g_strdup_printf (ngettext ("%'d folder selected",
+ "%'d folders selected",
+ folder_count),
+ folder_count);
}
- if (non_folder_count != 0) {
- if (folder_count == 0) {
- if (non_folder_count == 1) {
- non_folder_count_str = g_strdup_printf (_("“%s” selected"),
- first_item_name);
- } else {
- non_folder_count_str = g_strdup_printf (ngettext("%'d item selected",
- "%'d items selected",
- non_folder_count),
- non_folder_count);
- }
- } else {
- /* Folders selected also, use "other" terminology */
- non_folder_count_str = g_strdup_printf (ngettext("%'d other item selected",
- "%'d other items selected",
- non_folder_count),
- non_folder_count);
- }
-
- if (non_folder_size_known) {
- char *size_string;
-
- size_string = g_format_size (non_folder_size);
- /* This is marked for translation in case a localiser
- * needs to use something other than parentheses. The
- * the message in parentheses is the size of the selected items.
- */
- non_folder_item_count_str = g_strdup_printf (_("(%s)"), size_string);
- g_free (size_string);
- } else {
- non_folder_item_count_str = g_strdup ("");
- }
+ if (folder_count == 1)
+ {
+ if (!folder_item_count_known)
+ {
+ folder_item_count_str = g_strdup ("");
+ }
+ else
+ {
+ folder_item_count_str = g_strdup_printf (ngettext ("(containing %'d item)",
+ "(containing %'d items)",
+ folder_item_count),
+ folder_item_count);
+ }
}
+ else
+ {
+ if (!folder_item_count_known)
+ {
+ folder_item_count_str = g_strdup ("");
+ }
+ else
+ {
+ /* translators: this is preceded with a string of form 'N folders' (N more than 1) */
+ folder_item_count_str = g_strdup_printf (ngettext ("(containing a total of %'d item)",
+ "(containing a total of %'d items)",
+ folder_item_count),
+ folder_item_count);
+ }
+ }
+ }
- if (folder_count == 0 && non_folder_count == 0) {
- primary_status = NULL;
- detail_status = NULL;
- } else if (folder_count == 0) {
- primary_status = g_strdup (non_folder_count_str);
- detail_status = g_strdup (non_folder_item_count_str);
- } else if (non_folder_count == 0) {
- primary_status = g_strdup (folder_count_str);
- detail_status = g_strdup (folder_item_count_str);
- } else {
- /* This is marked for translation in case a localizer
- * needs to change ", " to something else. The comma
- * is between the message about the number of folders
- * and the number of items in those folders and the
- * message about the number of other items and the
- * total size of those items.
- */
- primary_status = g_strdup_printf (_("%s %s, %s %s"),
- folder_count_str,
- folder_item_count_str,
- non_folder_count_str,
- non_folder_item_count_str);
- detail_status = NULL;
+ if (non_folder_count != 0)
+ {
+ if (folder_count == 0)
+ {
+ if (non_folder_count == 1)
+ {
+ non_folder_count_str = g_strdup_printf (_("“%s” selected"),
+ first_item_name);
+ }
+ else
+ {
+ non_folder_count_str = g_strdup_printf (ngettext ("%'d item selected",
+ "%'d items selected",
+ non_folder_count),
+ non_folder_count);
+ }
}
+ else
+ {
+ /* Folders selected also, use "other" terminology */
+ non_folder_count_str = g_strdup_printf (ngettext ("%'d other item selected",
+ "%'d other items selected",
+ non_folder_count),
+ non_folder_count);
+ }
+
+ if (non_folder_size_known)
+ {
+ char *size_string;
+
+ size_string = g_format_size (non_folder_size);
+ /* This is marked for translation in case a localiser
+ * needs to use something other than parentheses. The
+ * the message in parentheses is the size of the selected items.
+ */
+ non_folder_item_count_str = g_strdup_printf (_("(%s)"), size_string);
+ g_free (size_string);
+ }
+ else
+ {
+ non_folder_item_count_str = g_strdup ("");
+ }
+ }
+
+ if (folder_count == 0 && non_folder_count == 0)
+ {
+ primary_status = NULL;
+ detail_status = NULL;
+ }
+ else if (folder_count == 0)
+ {
+ primary_status = g_strdup (non_folder_count_str);
+ detail_status = g_strdup (non_folder_item_count_str);
+ }
+ else if (non_folder_count == 0)
+ {
+ primary_status = g_strdup (folder_count_str);
+ detail_status = g_strdup (folder_item_count_str);
+ }
+ else
+ {
+ /* This is marked for translation in case a localizer
+ * needs to change ", " to something else. The comma
+ * is between the message about the number of folders
+ * and the number of items in those folders and the
+ * message about the number of other items and the
+ * total size of those items.
+ */
+ primary_status = g_strdup_printf (_("%s %s, %s %s"),
+ folder_count_str,
+ folder_item_count_str,
+ non_folder_count_str,
+ non_folder_item_count_str);
+ detail_status = NULL;
+ }
- g_free (first_item_name);
- g_free (folder_count_str);
- g_free (folder_item_count_str);
- g_free (non_folder_count_str);
- g_free (non_folder_item_count_str);
+ g_free (first_item_name);
+ g_free (folder_count_str);
+ g_free (folder_item_count_str);
+ g_free (non_folder_count_str);
+ g_free (non_folder_item_count_str);
- set_floating_bar_status (view, primary_status, detail_status);
+ set_floating_bar_status (view, primary_status, detail_status);
- g_free (primary_status);
- g_free (detail_status);
+ g_free (primary_status);
+ g_free (detail_status);
}
static void
nautilus_files_view_send_selection_change (NautilusFilesView *view)
{
- g_signal_emit (view, signals[SELECTION_CHANGED], 0);
+ g_signal_emit (view, signals[SELECTION_CHANGED], 0);
}
static void
nautilus_files_view_set_location (NautilusView *view,
GFile *location)
{
- NautilusDirectory *directory;
- NautilusFilesView *files_view;
-
- nautilus_profile_start (NULL);
- files_view = NAUTILUS_FILES_VIEW (view);
- directory = nautilus_directory_get (location);
-
- nautilus_files_view_stop_loading (files_view);
- /* In case we want to load a previous search we need to extract the real
- * location and the search location, and load the directory when everything
- * is ready. That's why we cannot use the nautilus_view_set_query, because
- * to set a query we need a previous location loaded, but to load a search
- * location we need to know the real location behind it. */
- if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
- NautilusQuery *previous_query;
- NautilusDirectory *base_model;
-
- base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory));
- previous_query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
- set_search_query_internal (files_view, previous_query, base_model);
- g_object_unref (previous_query);
- } else {
- load_directory (NAUTILUS_FILES_VIEW (view), directory);
- }
- nautilus_directory_unref (directory);
- nautilus_profile_end (NULL);
+ NautilusDirectory *directory;
+ NautilusFilesView *files_view;
+
+ nautilus_profile_start (NULL);
+ files_view = NAUTILUS_FILES_VIEW (view);
+ directory = nautilus_directory_get (location);
+
+ nautilus_files_view_stop_loading (files_view);
+ /* In case we want to load a previous search we need to extract the real
+ * location and the search location, and load the directory when everything
+ * is ready. That's why we cannot use the nautilus_view_set_query, because
+ * to set a query we need a previous location loaded, but to load a search
+ * location we need to know the real location behind it. */
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ NautilusQuery *previous_query;
+ NautilusDirectory *base_model;
+
+ base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory));
+ previous_query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
+ set_search_query_internal (files_view, previous_query, base_model);
+ g_object_unref (previous_query);
+ }
+ else
+ {
+ load_directory (NAUTILUS_FILES_VIEW (view), directory);
+ }
+ nautilus_directory_unref (directory);
+ nautilus_profile_end (NULL);
}
static gboolean
reveal_selection_idle_callback (gpointer data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- view->details->reveal_selection_idle_id = 0;
- nautilus_files_view_reveal_selection (view);
+ view->details->reveal_selection_idle_id = 0;
+ nautilus_files_view_reveal_selection (view);
- return FALSE;
+ return FALSE;
}
static void
nautilus_files_view_check_empty_states (NautilusFilesView *view)
{
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->check_empty_states (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->check_empty_states (view);
}
static void
real_check_empty_states (NautilusFilesView *view)
{
- gtk_widget_hide (view->details->no_search_results_widget);
- gtk_widget_hide (view->details->folder_is_empty_widget);
- if (!view->details->loading &&
- nautilus_files_view_is_empty (view)) {
- if (nautilus_view_is_searching (NAUTILUS_VIEW (view))) {
- gtk_widget_show (view->details->no_search_results_widget);
- } else {
- gtk_widget_show (view->details->folder_is_empty_widget);
- }
+ gtk_widget_hide (view->details->no_search_results_widget);
+ gtk_widget_hide (view->details->folder_is_empty_widget);
+ if (!view->details->loading &&
+ nautilus_files_view_is_empty (view))
+ {
+ if (nautilus_view_is_searching (NAUTILUS_VIEW (view)))
+ {
+ gtk_widget_show (view->details->no_search_results_widget);
+ }
+ else
+ {
+ gtk_widget_show (view->details->folder_is_empty_widget);
}
+ }
}
static void
done_loading (NautilusFilesView *view,
gboolean all_files_seen)
{
- GList *pending_selection;
- GList *selection;
- gboolean do_reveal = FALSE;
+ GList *pending_selection;
+ GList *selection;
+ gboolean do_reveal = FALSE;
- if (!view->details->loading) {
- return;
- }
+ if (!view->details->loading)
+ {
+ return;
+ }
+
+ nautilus_profile_start (NULL);
+
+ if (!view->details->in_destruction)
+ {
+ remove_loading_floating_bar (view);
+ schedule_update_context_menus (view);
+ schedule_update_status (view);
+ nautilus_files_view_update_toolbar_menus (view);
+ reset_update_interval (view);
- nautilus_profile_start (NULL);
+ pending_selection = view->details->pending_selection;
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- if (!view->details->in_destruction) {
- remove_loading_floating_bar (view);
- schedule_update_context_menus (view);
- schedule_update_status (view);
- nautilus_files_view_update_toolbar_menus (view);
- reset_update_interval (view);
+ if (nautilus_view_is_searching (NAUTILUS_VIEW (view)) &&
+ all_files_seen && !selection && !pending_selection)
+ {
+ nautilus_files_view_select_first (view);
+ do_reveal = TRUE;
+ }
+ else if (pending_selection != NULL && all_files_seen)
+ {
+ view->details->pending_selection = NULL;
- pending_selection = view->details->pending_selection;
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ nautilus_files_view_call_set_selection (view, pending_selection);
+ do_reveal = TRUE;
+ }
- if (nautilus_view_is_searching (NAUTILUS_VIEW (view)) &&
- all_files_seen && !selection && !pending_selection) {
- nautilus_files_view_select_first (view);
- do_reveal = TRUE;
- } else if (pending_selection != NULL && all_files_seen) {
- view->details->pending_selection = NULL;
+ if (selection)
+ {
+ g_list_free_full (selection, g_object_unref);
+ }
- nautilus_files_view_call_set_selection (view, pending_selection);
- do_reveal = TRUE;
- }
+ if (pending_selection)
+ {
+ g_list_free_full (pending_selection, g_object_unref);
+ }
- if (selection)
- g_list_free_full (selection, g_object_unref);
-
- if (pending_selection)
- g_list_free_full (pending_selection, g_object_unref);
-
- if (do_reveal) {
- if (NAUTILUS_IS_LIST_VIEW (view)) {
- /* HACK: We should be able to directly call reveal_selection here,
- * but at this point the GtkTreeView hasn't allocated the new nodes
- * yet, and it has a bug in the scroll calculation dealing with this
- * special case. It would always make the selection the top row, even
- * if no scrolling would be neccessary to reveal it. So we let it
- * allocate before revealing.
- */
- if (view->details->reveal_selection_idle_id != 0) {
- g_source_remove (view->details->reveal_selection_idle_id);
- }
- view->details->reveal_selection_idle_id =
- g_idle_add (reveal_selection_idle_callback, view);
- } else {
- nautilus_files_view_reveal_selection (view);
- }
+ if (do_reveal)
+ {
+ if (NAUTILUS_IS_LIST_VIEW (view))
+ {
+ /* HACK: We should be able to directly call reveal_selection here,
+ * but at this point the GtkTreeView hasn't allocated the new nodes
+ * yet, and it has a bug in the scroll calculation dealing with this
+ * special case. It would always make the selection the top row, even
+ * if no scrolling would be neccessary to reveal it. So we let it
+ * allocate before revealing.
+ */
+ if (view->details->reveal_selection_idle_id != 0)
+ {
+ g_source_remove (view->details->reveal_selection_idle_id);
}
- nautilus_files_view_display_selection_info (view);
+ view->details->reveal_selection_idle_id =
+ g_idle_add (reveal_selection_idle_callback, view);
+ }
+ else
+ {
+ nautilus_files_view_reveal_selection (view);
+ }
}
+ nautilus_files_view_display_selection_info (view);
+ }
- view->details->loading = FALSE;
- g_signal_emit (view, signals[END_LOADING], 0, all_files_seen);
- g_object_notify (G_OBJECT (view), "is-loading");
+ view->details->loading = FALSE;
+ g_signal_emit (view, signals[END_LOADING], 0, all_files_seen);
+ g_object_notify (G_OBJECT (view), "is-loading");
- if (!view->details->in_destruction) {
- nautilus_files_view_check_empty_states (view);
- }
+ if (!view->details->in_destruction)
+ {
+ nautilus_files_view_check_empty_states (view);
+ }
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
-typedef struct {
- GHashTable *debuting_files;
- GList *added_files;
+typedef struct
+{
+ GHashTable *debuting_files;
+ GList *added_files;
} DebutingFilesData;
static void
debuting_files_data_free (DebutingFilesData *data)
{
- g_hash_table_unref (data->debuting_files);
- nautilus_file_list_free (data->added_files);
- g_free (data);
+ g_hash_table_unref (data->debuting_files);
+ nautilus_file_list_free (data->added_files);
+ g_free (data);
}
/* This signal handler watch for the arrival of the icons created
@@ -3249,47 +3452,51 @@ debuting_files_add_file_callback (NautilusFilesView *view,
NautilusDirectory *directory,
DebutingFilesData *data)
{
- GFile *location;
+ GFile *location;
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- location = nautilus_file_get_location (new_file);
+ location = nautilus_file_get_location (new_file);
- if (g_hash_table_remove (data->debuting_files, location)) {
- nautilus_file_ref (new_file);
- data->added_files = g_list_prepend (data->added_files, new_file);
+ if (g_hash_table_remove (data->debuting_files, location))
+ {
+ nautilus_file_ref (new_file);
+ data->added_files = g_list_prepend (data->added_files, new_file);
- if (g_hash_table_size (data->debuting_files) == 0) {
- nautilus_files_view_call_set_selection (view, data->added_files);
- nautilus_files_view_reveal_selection (view);
- g_signal_handlers_disconnect_by_func (view,
- G_CALLBACK (debuting_files_add_file_callback),
- data);
- }
+ if (g_hash_table_size (data->debuting_files) == 0)
+ {
+ nautilus_files_view_call_set_selection (view, data->added_files);
+ nautilus_files_view_reveal_selection (view);
+ g_signal_handlers_disconnect_by_func (view,
+ G_CALLBACK (debuting_files_add_file_callback),
+ data);
}
+ }
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
- g_object_unref (location);
+ g_object_unref (location);
}
-typedef struct {
- GList *added_files;
- NautilusFilesView *directory_view;
+typedef struct
+{
+ GList *added_files;
+ NautilusFilesView *directory_view;
} CopyMoveDoneData;
static void
copy_move_done_data_free (CopyMoveDoneData *data)
{
- g_assert (data != NULL);
+ g_assert (data != NULL);
- if (data->directory_view != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (data->directory_view),
- (gpointer *) &data->directory_view);
- }
+ if (data->directory_view != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (data->directory_view),
+ (gpointer *) &data->directory_view);
+ }
- nautilus_file_list_free (data->added_files);
- g_free (data);
+ nautilus_file_list_free (data->added_files);
+ g_free (data);
}
static void
@@ -3298,8 +3505,8 @@ pre_copy_move_add_file_callback (NautilusFilesView *view,
NautilusDirectory *directory,
CopyMoveDoneData *data)
{
- nautilus_file_ref (new_file);
- data->added_files = g_list_prepend (data->added_files, new_file);
+ nautilus_file_ref (new_file);
+ data->added_files = g_list_prepend (data->added_files, new_file);
}
/* This needs to be called prior to nautilus_file_operations_copy_move.
@@ -3310,22 +3517,22 @@ pre_copy_move_add_file_callback (NautilusFilesView *view,
static CopyMoveDoneData *
pre_copy_move (NautilusFilesView *directory_view)
{
- CopyMoveDoneData *copy_move_done_data;
+ CopyMoveDoneData *copy_move_done_data;
- copy_move_done_data = g_new0 (CopyMoveDoneData, 1);
- copy_move_done_data->directory_view = directory_view;
+ copy_move_done_data = g_new0 (CopyMoveDoneData, 1);
+ copy_move_done_data->directory_view = directory_view;
- g_object_add_weak_pointer (G_OBJECT (copy_move_done_data->directory_view),
- (gpointer *) &copy_move_done_data->directory_view);
+ g_object_add_weak_pointer (G_OBJECT (copy_move_done_data->directory_view),
+ (gpointer *) &copy_move_done_data->directory_view);
- /* We need to run after the default handler adds the folder we want to
- * operate on. The ADD_FILE signal is registered as G_SIGNAL_RUN_LAST, so we
- * must use connect_after.
- */
- g_signal_connect (directory_view, "add-file",
- G_CALLBACK (pre_copy_move_add_file_callback), copy_move_done_data);
+ /* We need to run after the default handler adds the folder we want to
+ * operate on. The ADD_FILE signal is registered as G_SIGNAL_RUN_LAST, so we
+ * must use connect_after.
+ */
+ g_signal_connect (directory_view, "add-file",
+ G_CALLBACK (pre_copy_move_add_file_callback), copy_move_done_data);
- return copy_move_done_data;
+ return copy_move_done_data;
}
/* This function is used to pull out any debuting uris that were added
@@ -3335,14 +3542,14 @@ static gboolean
copy_move_done_partition_func (NautilusFile *file,
gpointer callback_data)
{
- GFile *location;
- gboolean result;
+ GFile *location;
+ gboolean result;
- location = nautilus_file_get_location (file);
- result = g_hash_table_remove ((GHashTable *) callback_data, location);
- g_object_unref (location);
+ location = nautilus_file_get_location (file);
+ result = g_hash_table_remove ((GHashTable *) callback_data, location);
+ g_object_unref (location);
- return result;
+ return result;
}
static gboolean
@@ -3350,19 +3557,20 @@ remove_not_really_moved_files (gpointer key,
gpointer value,
gpointer callback_data)
{
- GList **added_files;
- GFile *loc;
+ GList **added_files;
+ GFile *loc;
- loc = key;
+ loc = key;
- if (GPOINTER_TO_INT (value)) {
- return FALSE;
- }
+ if (GPOINTER_TO_INT (value))
+ {
+ return FALSE;
+ }
- added_files = callback_data;
- *added_files = g_list_prepend (*added_files,
- nautilus_file_get (loc));
- return TRUE;
+ added_files = callback_data;
+ *added_files = g_list_prepend (*added_files,
+ nautilus_file_get (loc));
+ return TRUE;
}
/* When this function is invoked, the file operation is over, but all
@@ -3377,68 +3585,73 @@ copy_move_done_callback (GHashTable *debuting_files,
gboolean success,
gpointer data)
{
- NautilusFilesView *directory_view;
- CopyMoveDoneData *copy_move_done_data;
- DebutingFilesData *debuting_files_data;
- GList *failed_files;
-
- copy_move_done_data = (CopyMoveDoneData *) data;
- directory_view = copy_move_done_data->directory_view;
-
- if (directory_view != NULL) {
- g_assert (NAUTILUS_IS_FILES_VIEW (directory_view));
-
- debuting_files_data = g_new (DebutingFilesData, 1);
- debuting_files_data->debuting_files = g_hash_table_ref (debuting_files);
- debuting_files_data->added_files = nautilus_file_list_filter (copy_move_done_data->added_files,
- &failed_files,
- copy_move_done_partition_func,
- debuting_files);
- nautilus_file_list_free (copy_move_done_data->added_files);
- copy_move_done_data->added_files = failed_files;
-
- /* We're passed the same data used by pre_copy_move_add_file_callback, so disconnecting
- * it will free data. We've already siphoned off the added_files we need, and stashed the
- * directory_view pointer.
- */
- g_signal_handlers_disconnect_by_func (directory_view,
- G_CALLBACK (pre_copy_move_add_file_callback),
- data);
-
- /* Any items in the debuting_files hash table that have
- * "FALSE" as their value aren't really being copied
- * or moved, so we can't wait for an add_file signal
- * to come in for those.
- */
- g_hash_table_foreach_remove (debuting_files,
- remove_not_really_moved_files,
- &debuting_files_data->added_files);
-
- if (g_hash_table_size (debuting_files) == 0) {
- /* on the off-chance that all the icons have already been added */
- if (debuting_files_data->added_files != NULL) {
- nautilus_files_view_call_set_selection (directory_view,
- debuting_files_data->added_files);
- nautilus_files_view_reveal_selection (directory_view);
- }
- debuting_files_data_free (debuting_files_data);
- } else {
- /* We need to run after the default handler adds the folder we want to
- * operate on. The ADD_FILE signal is registered as G_SIGNAL_RUN_LAST, so we
- * must use connect_after.
- */
- g_signal_connect_data (directory_view,
- "add-file",
- G_CALLBACK (debuting_files_add_file_callback),
- debuting_files_data,
- (GClosureNotify) debuting_files_data_free,
- G_CONNECT_AFTER);
- }
- /* Schedule menu update for undo items */
- schedule_update_context_menus (directory_view);
+ NautilusFilesView *directory_view;
+ CopyMoveDoneData *copy_move_done_data;
+ DebutingFilesData *debuting_files_data;
+ GList *failed_files;
+
+ copy_move_done_data = (CopyMoveDoneData *) data;
+ directory_view = copy_move_done_data->directory_view;
+
+ if (directory_view != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILES_VIEW (directory_view));
+
+ debuting_files_data = g_new (DebutingFilesData, 1);
+ debuting_files_data->debuting_files = g_hash_table_ref (debuting_files);
+ debuting_files_data->added_files = nautilus_file_list_filter (copy_move_done_data->added_files,
+ &failed_files,
+ copy_move_done_partition_func,
+ debuting_files);
+ nautilus_file_list_free (copy_move_done_data->added_files);
+ copy_move_done_data->added_files = failed_files;
+
+ /* We're passed the same data used by pre_copy_move_add_file_callback, so disconnecting
+ * it will free data. We've already siphoned off the added_files we need, and stashed the
+ * directory_view pointer.
+ */
+ g_signal_handlers_disconnect_by_func (directory_view,
+ G_CALLBACK (pre_copy_move_add_file_callback),
+ data);
+
+ /* Any items in the debuting_files hash table that have
+ * "FALSE" as their value aren't really being copied
+ * or moved, so we can't wait for an add_file signal
+ * to come in for those.
+ */
+ g_hash_table_foreach_remove (debuting_files,
+ remove_not_really_moved_files,
+ &debuting_files_data->added_files);
+
+ if (g_hash_table_size (debuting_files) == 0)
+ {
+ /* on the off-chance that all the icons have already been added */
+ if (debuting_files_data->added_files != NULL)
+ {
+ nautilus_files_view_call_set_selection (directory_view,
+ debuting_files_data->added_files);
+ nautilus_files_view_reveal_selection (directory_view);
+ }
+ debuting_files_data_free (debuting_files_data);
+ }
+ else
+ {
+ /* We need to run after the default handler adds the folder we want to
+ * operate on. The ADD_FILE signal is registered as G_SIGNAL_RUN_LAST, so we
+ * must use connect_after.
+ */
+ g_signal_connect_data (directory_view,
+ "add-file",
+ G_CALLBACK (debuting_files_add_file_callback),
+ debuting_files_data,
+ (GClosureNotify) debuting_files_data_free,
+ G_CONNECT_AFTER);
}
+ /* Schedule menu update for undo items */
+ schedule_update_context_menus (directory_view);
+ }
- copy_move_done_data_free (copy_move_done_data);
+ copy_move_done_data_free (copy_move_done_data);
}
static gboolean
@@ -3446,12 +3659,13 @@ view_file_still_belongs (NautilusFilesView *view,
NautilusFile *file,
NautilusDirectory *directory)
{
- if (view->details->model != directory &&
- g_list_find (view->details->subdirectory_list, directory) == NULL) {
- return FALSE;
- }
+ if (view->details->model != directory &&
+ g_list_find (view->details->subdirectory_list, directory) == NULL)
+ {
+ return FALSE;
+ }
- return nautilus_directory_contains_file (directory, file);
+ return nautilus_directory_contains_file (directory, file);
}
static gboolean
@@ -3459,15 +3673,15 @@ still_should_show_file (NautilusFilesView *view,
NautilusFile *file,
NautilusDirectory *directory)
{
- return nautilus_files_view_should_show_file (view, file) &&
- view_file_still_belongs (view, file, directory);
+ return nautilus_files_view_should_show_file (view, file) &&
+ view_file_still_belongs (view, file, directory);
}
static gboolean
ready_to_load (NautilusFile *file)
{
- return nautilus_file_check_if_ready (file,
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
+ return nautilus_file_check_if_ready (file,
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
}
static int
@@ -3475,26 +3689,31 @@ compare_files_cover (gconstpointer a,
gconstpointer b,
gpointer callback_data)
{
- const FileAndDirectory *fad1, *fad2;
- NautilusFilesView *view;
+ const FileAndDirectory *fad1, *fad2;
+ NautilusFilesView *view;
- view = callback_data;
- fad1 = a; fad2 = b;
+ view = callback_data;
+ fad1 = a;
+ fad2 = b;
- if (fad1->directory < fad2->directory) {
- return -1;
- } else if (fad1->directory > fad2->directory) {
- return 1;
- } else {
- return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->compare_files (view, fad1->file, fad2->file);
- }
+ if (fad1->directory < fad2->directory)
+ {
+ return -1;
+ }
+ else if (fad1->directory > fad2->directory)
+ {
+ return 1;
+ }
+ else
+ {
+ return NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->compare_files (view, fad1->file, fad2->file);
+ }
}
static void
sort_files (NautilusFilesView *view,
GList **list)
{
- *list = g_list_sort_with_data (*list, compare_files_cover, view);
-
+ *list = g_list_sort_with_data (*list, compare_files_cover, view);
}
/* Go through all the new added and changed files.
@@ -3505,323 +3724,354 @@ sort_files (NautilusFilesView *view,
static void
process_new_files (NautilusFilesView *view)
{
- GList *new_added_files, *new_changed_files, *old_added_files, *old_changed_files;
- GHashTable *non_ready_files;
- GList *node, *next;
- FileAndDirectory *pending;
- gboolean in_non_ready;
-
- new_added_files = view->details->new_added_files;
- view->details->new_added_files = NULL;
- new_changed_files = view->details->new_changed_files;
- view->details->new_changed_files = NULL;
-
- non_ready_files = view->details->non_ready_files;
-
- old_added_files = view->details->old_added_files;
- old_changed_files = view->details->old_changed_files;
-
- /* Newly added files go into the old_added_files list if they're
- * ready, and into the hash table if they're not.
- */
- for (node = new_added_files; node != NULL; node = next) {
- next = node->next;
- pending = (FileAndDirectory *)node->data;
- in_non_ready = g_hash_table_lookup (non_ready_files, pending) != NULL;
- if (nautilus_files_view_should_show_file (view, pending->file)) {
- if (ready_to_load (pending->file)) {
- if (in_non_ready) {
- g_hash_table_remove (non_ready_files, pending);
- }
- new_added_files = g_list_delete_link (new_added_files, node);
- old_added_files = g_list_prepend (old_added_files, pending);
- } else {
- if (!in_non_ready) {
- new_added_files = g_list_delete_link (new_added_files, node);
- g_hash_table_insert (non_ready_files, pending, pending);
- }
- }
+ GList *new_added_files, *new_changed_files, *old_added_files, *old_changed_files;
+ GHashTable *non_ready_files;
+ GList *node, *next;
+ FileAndDirectory *pending;
+ gboolean in_non_ready;
+
+ new_added_files = view->details->new_added_files;
+ view->details->new_added_files = NULL;
+ new_changed_files = view->details->new_changed_files;
+ view->details->new_changed_files = NULL;
+
+ non_ready_files = view->details->non_ready_files;
+
+ old_added_files = view->details->old_added_files;
+ old_changed_files = view->details->old_changed_files;
+
+ /* Newly added files go into the old_added_files list if they're
+ * ready, and into the hash table if they're not.
+ */
+ for (node = new_added_files; node != NULL; node = next)
+ {
+ next = node->next;
+ pending = (FileAndDirectory *) node->data;
+ in_non_ready = g_hash_table_lookup (non_ready_files, pending) != NULL;
+ if (nautilus_files_view_should_show_file (view, pending->file))
+ {
+ if (ready_to_load (pending->file))
+ {
+ if (in_non_ready)
+ {
+ g_hash_table_remove (non_ready_files, pending);
}
- }
- file_and_directory_list_free (new_added_files);
-
- /* Newly changed files go into the old_added_files list if they're ready
- * and were seen non-ready in the past, into the old_changed_files list
- * if they are read and were not seen non-ready in the past, and into
- * the hash table if they're not ready.
- */
- for (node = new_changed_files; node != NULL; node = next) {
- next = node->next;
- pending = (FileAndDirectory *)node->data;
- if (!still_should_show_file (view, pending->file, pending->directory) || ready_to_load (pending->file)) {
- if (g_hash_table_lookup (non_ready_files, pending) != NULL) {
- g_hash_table_remove (non_ready_files, pending);
- if (still_should_show_file (view, pending->file, pending->directory)) {
- new_changed_files = g_list_delete_link (new_changed_files, node);
- old_added_files = g_list_prepend (old_added_files, pending);
- }
- } else {
- new_changed_files = g_list_delete_link (new_changed_files, node);
- old_changed_files = g_list_prepend (old_changed_files, pending);
- }
+ new_added_files = g_list_delete_link (new_added_files, node);
+ old_added_files = g_list_prepend (old_added_files, pending);
+ }
+ else
+ {
+ if (!in_non_ready)
+ {
+ new_added_files = g_list_delete_link (new_added_files, node);
+ g_hash_table_insert (non_ready_files, pending, pending);
}
+ }
}
- file_and_directory_list_free (new_changed_files);
-
- /* If any files were added to old_added_files, then resort it. */
- if (old_added_files != view->details->old_added_files) {
- view->details->old_added_files = old_added_files;
- sort_files (view, &view->details->old_added_files);
+ }
+ file_and_directory_list_free (new_added_files);
+
+ /* Newly changed files go into the old_added_files list if they're ready
+ * and were seen non-ready in the past, into the old_changed_files list
+ * if they are read and were not seen non-ready in the past, and into
+ * the hash table if they're not ready.
+ */
+ for (node = new_changed_files; node != NULL; node = next)
+ {
+ next = node->next;
+ pending = (FileAndDirectory *) node->data;
+ if (!still_should_show_file (view, pending->file, pending->directory) || ready_to_load (pending->file))
+ {
+ if (g_hash_table_lookup (non_ready_files, pending) != NULL)
+ {
+ g_hash_table_remove (non_ready_files, pending);
+ if (still_should_show_file (view, pending->file, pending->directory))
+ {
+ new_changed_files = g_list_delete_link (new_changed_files, node);
+ old_added_files = g_list_prepend (old_added_files, pending);
+ }
+ }
+ else
+ {
+ new_changed_files = g_list_delete_link (new_changed_files, node);
+ old_changed_files = g_list_prepend (old_changed_files, pending);
+ }
}
+ }
+ file_and_directory_list_free (new_changed_files);
- /* Resort old_changed_files too, since file attributes
- * relevant to sorting could have changed.
- */
- if (old_changed_files != view->details->old_changed_files) {
- view->details->old_changed_files = old_changed_files;
- sort_files (view, &view->details->old_changed_files);
- }
+ /* If any files were added to old_added_files, then resort it. */
+ if (old_added_files != view->details->old_added_files)
+ {
+ view->details->old_added_files = old_added_files;
+ sort_files (view, &view->details->old_added_files);
+ }
+ /* Resort old_changed_files too, since file attributes
+ * relevant to sorting could have changed.
+ */
+ if (old_changed_files != view->details->old_changed_files)
+ {
+ view->details->old_changed_files = old_changed_files;
+ sort_files (view, &view->details->old_changed_files);
+ }
}
static void
on_end_file_changes (NautilusFilesView *view)
{
- /* Addition and removal of files modify the empty state */
- nautilus_files_view_check_empty_states (view);
- /* If the view is empty, zoom slider and sort menu are insensitive */
- nautilus_files_view_update_toolbar_menus (view);
-
- /* Reveal files that were pending to be revealed, only if all of them
- * were acknowledged by the view
- */
- if (g_hash_table_size (view->details->pending_reveal) > 0) {
- GList *keys;
- GList *l;
- gboolean all_files_acknowledged = TRUE;
-
- keys = g_hash_table_get_keys (view->details->pending_reveal);
- for (l = keys; l && all_files_acknowledged; l = l->next) {
- all_files_acknowledged = GPOINTER_TO_UINT (g_hash_table_lookup (view->details->pending_reveal,
- l->data));
- }
+ /* Addition and removal of files modify the empty state */
+ nautilus_files_view_check_empty_states (view);
+ /* If the view is empty, zoom slider and sort menu are insensitive */
+ nautilus_files_view_update_toolbar_menus (view);
+
+ /* Reveal files that were pending to be revealed, only if all of them
+ * were acknowledged by the view
+ */
+ if (g_hash_table_size (view->details->pending_reveal) > 0)
+ {
+ GList *keys;
+ GList *l;
+ gboolean all_files_acknowledged = TRUE;
- if (all_files_acknowledged) {
- nautilus_files_view_set_selection (NAUTILUS_VIEW (view), keys);
- nautilus_files_view_reveal_selection (view);
- g_hash_table_remove_all (view->details->pending_reveal);
- }
+ keys = g_hash_table_get_keys (view->details->pending_reveal);
+ for (l = keys; l && all_files_acknowledged; l = l->next)
+ {
+ all_files_acknowledged = GPOINTER_TO_UINT (g_hash_table_lookup (view->details->pending_reveal,
+ l->data));
+ }
- g_list_free (keys);
+ if (all_files_acknowledged)
+ {
+ nautilus_files_view_set_selection (NAUTILUS_VIEW (view), keys);
+ nautilus_files_view_reveal_selection (view);
+ g_hash_table_remove_all (view->details->pending_reveal);
}
+
+ g_list_free (keys);
+ }
}
static void
process_old_files (NautilusFilesView *view)
{
- GList *files_added, *files_changed, *node;
- FileAndDirectory *pending;
- GList *selection, *files;
+ GList *files_added, *files_changed, *node;
+ FileAndDirectory *pending;
+ GList *selection, *files;
- files_added = view->details->old_added_files;
- files_changed = view->details->old_changed_files;
+ files_added = view->details->old_added_files;
+ files_changed = view->details->old_changed_files;
- if (files_added != NULL || files_changed != NULL) {
- gboolean send_selection_change = FALSE;
+ if (files_added != NULL || files_changed != NULL)
+ {
+ gboolean send_selection_change = FALSE;
- g_signal_emit (view, signals[BEGIN_FILE_CHANGES], 0);
+ g_signal_emit (view, signals[BEGIN_FILE_CHANGES], 0);
- for (node = files_added; node != NULL; node = node->next) {
- pending = node->data;
- g_signal_emit (view,
- signals[ADD_FILE], 0, pending->file, pending->directory);
- /* Acknowledge the files that were pending to be revealed */
- if (g_hash_table_contains (view->details->pending_reveal, pending->file)) {
- g_hash_table_insert (view->details->pending_reveal,
- pending->file,
- GUINT_TO_POINTER (TRUE));
- }
- }
+ for (node = files_added; node != NULL; node = node->next)
+ {
+ pending = node->data;
+ g_signal_emit (view,
+ signals[ADD_FILE], 0, pending->file, pending->directory);
+ /* Acknowledge the files that were pending to be revealed */
+ if (g_hash_table_contains (view->details->pending_reveal, pending->file))
+ {
+ g_hash_table_insert (view->details->pending_reveal,
+ pending->file,
+ GUINT_TO_POINTER (TRUE));
+ }
+ }
- for (node = files_changed; node != NULL; node = node->next) {
- gboolean should_show_file;
- pending = node->data;
- should_show_file = still_should_show_file (view, pending->file, pending->directory);
- g_signal_emit (view,
- signals[should_show_file ? FILE_CHANGED : REMOVE_FILE], 0,
- pending->file, pending->directory);
-
- /* Acknowledge the files that were pending to be revealed */
- if (g_hash_table_contains (view->details->pending_reveal, pending->file)) {
- if (should_show_file) {
- g_hash_table_insert (view->details->pending_reveal,
- pending->file,
- GUINT_TO_POINTER (TRUE));
- } else {
- g_hash_table_remove (view->details->pending_reveal,
- pending->file);
- }
- }
+ for (node = files_changed; node != NULL; node = node->next)
+ {
+ gboolean should_show_file;
+ pending = node->data;
+ should_show_file = still_should_show_file (view, pending->file, pending->directory);
+ g_signal_emit (view,
+ signals[should_show_file ? FILE_CHANGED : REMOVE_FILE], 0,
+ pending->file, pending->directory);
+
+ /* Acknowledge the files that were pending to be revealed */
+ if (g_hash_table_contains (view->details->pending_reveal, pending->file))
+ {
+ if (should_show_file)
+ {
+ g_hash_table_insert (view->details->pending_reveal,
+ pending->file,
+ GUINT_TO_POINTER (TRUE));
}
-
- if (files_changed != NULL) {
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- files = file_and_directory_list_to_files (files_changed);
- send_selection_change = eel_g_lists_sort_and_check_for_intersection
- (&files, &selection);
- nautilus_file_list_free (files);
- nautilus_file_list_free (selection);
+ else
+ {
+ g_hash_table_remove (view->details->pending_reveal,
+ pending->file);
}
+ }
+ }
- file_and_directory_list_free (view->details->old_added_files);
- view->details->old_added_files = NULL;
+ if (files_changed != NULL)
+ {
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ files = file_and_directory_list_to_files (files_changed);
+ send_selection_change = eel_g_lists_sort_and_check_for_intersection
+ (&files, &selection);
+ nautilus_file_list_free (files);
+ nautilus_file_list_free (selection);
+ }
- file_and_directory_list_free (view->details->old_changed_files);
- view->details->old_changed_files = NULL;
+ file_and_directory_list_free (view->details->old_added_files);
+ view->details->old_added_files = NULL;
- if (send_selection_change) {
- /* Send a selection change since some file names could
- * have changed.
- */
- nautilus_files_view_send_selection_change (view);
- }
+ file_and_directory_list_free (view->details->old_changed_files);
+ view->details->old_changed_files = NULL;
- g_signal_emit (view, signals[END_FILE_CHANGES], 0);
+ if (send_selection_change)
+ {
+ /* Send a selection change since some file names could
+ * have changed.
+ */
+ nautilus_files_view_send_selection_change (view);
}
+
+ g_signal_emit (view, signals[END_FILE_CHANGES], 0);
+ }
}
static void
display_pending_files (NautilusFilesView *view)
{
- GList *selection;
+ GList *selection;
- process_new_files (view);
- process_old_files (view);
+ process_new_files (view);
+ process_old_files (view);
- selection = nautilus_files_view_get_selection (NAUTILUS_VIEW (view));
+ selection = nautilus_files_view_get_selection (NAUTILUS_VIEW (view));
- if (selection == NULL &&
- !view->details->pending_selection &&
- nautilus_view_is_searching (NAUTILUS_VIEW (view))) {
- nautilus_files_view_select_first (view);
+ if (selection == NULL &&
+ !view->details->pending_selection &&
+ nautilus_view_is_searching (NAUTILUS_VIEW (view)))
+ {
+ nautilus_files_view_select_first (view);
+ }
- }
-
- if (view->details->model != NULL
- && nautilus_directory_are_all_files_seen (view->details->model)
- && g_hash_table_size (view->details->non_ready_files) == 0) {
- done_loading (view, TRUE);
- }
+ if (view->details->model != NULL
+ && nautilus_directory_are_all_files_seen (view->details->model)
+ && g_hash_table_size (view->details->non_ready_files) == 0)
+ {
+ done_loading (view, TRUE);
+ }
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static gboolean
display_selection_info_idle_callback (gpointer data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- g_object_ref (G_OBJECT (view));
+ g_object_ref (G_OBJECT (view));
- view->details->display_selection_idle_id = 0;
- nautilus_files_view_display_selection_info (view);
- nautilus_files_view_send_selection_change (view);
+ view->details->display_selection_idle_id = 0;
+ nautilus_files_view_display_selection_info (view);
+ nautilus_files_view_send_selection_change (view);
- g_object_unref (G_OBJECT (view));
+ g_object_unref (G_OBJECT (view));
- return FALSE;
+ return FALSE;
}
static void
remove_update_context_menus_timeout_callback (NautilusFilesView *view)
{
- if (view->details->update_context_menus_timeout_id != 0) {
- g_source_remove (view->details->update_context_menus_timeout_id);
- view->details->update_context_menus_timeout_id = 0;
- }
+ if (view->details->update_context_menus_timeout_id != 0)
+ {
+ g_source_remove (view->details->update_context_menus_timeout_id);
+ view->details->update_context_menus_timeout_id = 0;
+ }
}
static void
update_context_menus_if_pending (NautilusFilesView *view)
{
- remove_update_context_menus_timeout_callback (view);
+ remove_update_context_menus_timeout_callback (view);
- nautilus_files_view_update_context_menus(view);
+ nautilus_files_view_update_context_menus (view);
}
static gboolean
update_context_menus_timeout_callback (gpointer data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- g_object_ref (G_OBJECT (view));
+ g_object_ref (G_OBJECT (view));
- view->details->update_context_menus_timeout_id = 0;
- nautilus_files_view_update_context_menus(view);
+ view->details->update_context_menus_timeout_id = 0;
+ nautilus_files_view_update_context_menus (view);
- g_object_unref (G_OBJECT (view));
+ g_object_unref (G_OBJECT (view));
- return FALSE;
+ return FALSE;
}
static gboolean
display_pending_callback (gpointer data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- g_object_ref (G_OBJECT (view));
+ g_object_ref (G_OBJECT (view));
- view->details->display_pending_source_id = 0;
+ view->details->display_pending_source_id = 0;
- display_pending_files (view);
+ display_pending_files (view);
- g_object_unref (G_OBJECT (view));
+ g_object_unref (G_OBJECT (view));
- return FALSE;
+ return FALSE;
}
static void
schedule_idle_display_of_pending_files (NautilusFilesView *view)
{
- /* Get rid of a pending source as it might be a timeout */
- unschedule_display_of_pending_files (view);
+ /* Get rid of a pending source as it might be a timeout */
+ unschedule_display_of_pending_files (view);
- /* We want higher priority than the idle that handles the relayout
- to avoid a resort on each add. But we still want to allow repaints
- and other hight prio events while we have pending files to show. */
- view->details->display_pending_source_id =
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE - 20,
- display_pending_callback, view, NULL);
+ /* We want higher priority than the idle that handles the relayout
+ * to avoid a resort on each add. But we still want to allow repaints
+ * and other hight prio events while we have pending files to show. */
+ view->details->display_pending_source_id =
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE - 20,
+ display_pending_callback, view, NULL);
}
static void
schedule_timeout_display_of_pending_files (NautilusFilesView *view,
guint interval)
{
- /* No need to schedule an update if there's already one pending. */
- if (view->details->display_pending_source_id != 0) {
- return;
- }
+ /* No need to schedule an update if there's already one pending. */
+ if (view->details->display_pending_source_id != 0)
+ {
+ return;
+ }
- view->details->display_pending_source_id =
- g_timeout_add (interval, display_pending_callback, view);
+ view->details->display_pending_source_id =
+ g_timeout_add (interval, display_pending_callback, view);
}
static void
unschedule_display_of_pending_files (NautilusFilesView *view)
{
- /* Get rid of source if it's active. */
- if (view->details->display_pending_source_id != 0) {
- g_source_remove (view->details->display_pending_source_id);
- view->details->display_pending_source_id = 0;
- }
+ /* Get rid of source if it's active. */
+ if (view->details->display_pending_source_id != 0)
+ {
+ g_source_remove (view->details->display_pending_source_id);
+ view->details->display_pending_source_id = 0;
+ }
}
static void
@@ -3830,91 +4080,100 @@ queue_pending_files (NautilusFilesView *view,
GList *files,
GList **pending_list)
{
- if (files == NULL) {
- return;
- }
+ if (files == NULL)
+ {
+ return;
+ }
- *pending_list = g_list_concat (file_and_directory_list_from_files (directory, files),
- *pending_list);
- /* Generally we don't want to show the files while the directory is loading
- * the files themselves, so we avoid jumping and oddities. However, for
- * search it can be a long wait, and we actually want to show files as
- * they are getting found. So for search is fine if not all files are
- * seen */
- if (!view->details->loading ||
- (nautilus_directory_are_all_files_seen (directory) ||
- nautilus_view_is_searching (NAUTILUS_VIEW (view)))) {
- schedule_timeout_display_of_pending_files (view, view->details->update_interval);
- }
+ *pending_list = g_list_concat (file_and_directory_list_from_files (directory, files),
+ *pending_list);
+ /* Generally we don't want to show the files while the directory is loading
+ * the files themselves, so we avoid jumping and oddities. However, for
+ * search it can be a long wait, and we actually want to show files as
+ * they are getting found. So for search is fine if not all files are
+ * seen */
+ if (!view->details->loading ||
+ (nautilus_directory_are_all_files_seen (directory) ||
+ nautilus_view_is_searching (NAUTILUS_VIEW (view))))
+ {
+ schedule_timeout_display_of_pending_files (view, view->details->update_interval);
+ }
}
static void
remove_changes_timeout_callback (NautilusFilesView *view)
{
- if (view->details->changes_timeout_id != 0) {
- g_source_remove (view->details->changes_timeout_id);
- view->details->changes_timeout_id = 0;
- }
+ if (view->details->changes_timeout_id != 0)
+ {
+ g_source_remove (view->details->changes_timeout_id);
+ view->details->changes_timeout_id = 0;
+ }
}
static void
reset_update_interval (NautilusFilesView *view)
{
- view->details->update_interval = UPDATE_INTERVAL_MIN;
- remove_changes_timeout_callback (view);
- /* Reschedule a pending timeout to idle */
- if (view->details->display_pending_source_id != 0) {
- schedule_idle_display_of_pending_files (view);
- }
+ view->details->update_interval = UPDATE_INTERVAL_MIN;
+ remove_changes_timeout_callback (view);
+ /* Reschedule a pending timeout to idle */
+ if (view->details->display_pending_source_id != 0)
+ {
+ schedule_idle_display_of_pending_files (view);
+ }
}
static gboolean
changes_timeout_callback (gpointer data)
{
- gint64 now;
- gint64 time_delta;
- gboolean ret;
- NautilusFilesView *view;
+ gint64 now;
+ gint64 time_delta;
+ gboolean ret;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (data);
+ view = NAUTILUS_FILES_VIEW (data);
- g_object_ref (G_OBJECT (view));
+ g_object_ref (G_OBJECT (view));
- now = g_get_monotonic_time ();
- time_delta = now - view->details->last_queued;
+ now = g_get_monotonic_time ();
+ time_delta = now - view->details->last_queued;
- if (time_delta < UPDATE_INTERVAL_RESET*1000) {
- if (view->details->update_interval < UPDATE_INTERVAL_MAX &&
- view->details->loading) {
- /* Increase */
- view->details->update_interval += UPDATE_INTERVAL_INC;
- }
- ret = TRUE;
- } else {
- /* Reset */
- reset_update_interval (view);
- ret = FALSE;
+ if (time_delta < UPDATE_INTERVAL_RESET * 1000)
+ {
+ if (view->details->update_interval < UPDATE_INTERVAL_MAX &&
+ view->details->loading)
+ {
+ /* Increase */
+ view->details->update_interval += UPDATE_INTERVAL_INC;
}
+ ret = TRUE;
+ }
+ else
+ {
+ /* Reset */
+ reset_update_interval (view);
+ ret = FALSE;
+ }
- g_object_unref (G_OBJECT (view));
+ g_object_unref (G_OBJECT (view));
- return ret;
+ return ret;
}
static void
schedule_changes (NautilusFilesView *view)
{
- /* Remember when the change was queued */
- view->details->last_queued = g_get_monotonic_time ();
+ /* Remember when the change was queued */
+ view->details->last_queued = g_get_monotonic_time ();
- /* No need to schedule if there are already changes pending or during loading */
- if (view->details->changes_timeout_id != 0 ||
- view->details->loading) {
- return;
- }
+ /* No need to schedule if there are already changes pending or during loading */
+ if (view->details->changes_timeout_id != 0 ||
+ view->details->loading)
+ {
+ return;
+ }
- view->details->changes_timeout_id =
- g_timeout_add (UPDATE_INTERVAL_TIMEOUT_INTERVAL, changes_timeout_callback, view);
+ view->details->changes_timeout_id =
+ g_timeout_add (UPDATE_INTERVAL_TIMEOUT_INTERVAL, changes_timeout_callback, view);
}
static void
@@ -3922,28 +4181,28 @@ files_added_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
- NautilusFilesView *view;
- GtkWindow *window;
- char *uri;
+ NautilusFilesView *view;
+ GtkWindow *window;
+ char *uri;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- window = nautilus_files_view_get_containing_window (view);
- uri = nautilus_files_view_get_uri (view);
- DEBUG_FILES (files, "Files added in window %p: %s",
- window, uri ? uri : "(no directory)");
- g_free (uri);
+ window = nautilus_files_view_get_containing_window (view);
+ uri = nautilus_files_view_get_uri (view);
+ DEBUG_FILES (files, "Files added in window %p: %s",
+ window, uri ? uri : "(no directory)");
+ g_free (uri);
- schedule_changes (view);
+ schedule_changes (view);
- queue_pending_files (view, directory, files, &view->details->new_added_files);
+ queue_pending_files (view, directory, files, &view->details->new_added_files);
- /* The number of items could have changed */
- schedule_update_status (view);
+ /* The number of items could have changed */
+ schedule_update_status (view);
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static void
@@ -3951,52 +4210,53 @@ files_changed_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
- NautilusFilesView *view;
- GtkWindow *window;
- char *uri;
+ NautilusFilesView *view;
+ GtkWindow *window;
+ char *uri;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- window = nautilus_files_view_get_containing_window (view);
- uri = nautilus_files_view_get_uri (view);
- DEBUG_FILES (files, "Files changed in window %p: %s",
- window, uri ? uri : "(no directory)");
- g_free (uri);
+ window = nautilus_files_view_get_containing_window (view);
+ uri = nautilus_files_view_get_uri (view);
+ DEBUG_FILES (files, "Files changed in window %p: %s",
+ window, uri ? uri : "(no directory)");
+ g_free (uri);
- schedule_changes (view);
+ schedule_changes (view);
- queue_pending_files (view, directory, files, &view->details->new_changed_files);
+ queue_pending_files (view, directory, files, &view->details->new_changed_files);
- /* The free space or the number of items could have changed */
- schedule_update_status (view);
+ /* The free space or the number of items could have changed */
+ schedule_update_status (view);
- /* A change in MIME type could affect the Open with menu, for
- * one thing, so we need to update menus when files change.
- */
- schedule_update_context_menus (view);
+ /* A change in MIME type could affect the Open with menu, for
+ * one thing, so we need to update menus when files change.
+ */
+ schedule_update_context_menus (view);
}
static void
done_loading_callback (NautilusDirectory *directory,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- nautilus_profile_start (NULL);
- process_new_files (view);
- if (g_hash_table_size (view->details->non_ready_files) == 0) {
- /* Unschedule a pending update and schedule a new one with the minimal
- * update interval. This gives the view a short chance at gathering the
- * (cached) deep counts.
- */
- unschedule_display_of_pending_files (view);
- schedule_timeout_display_of_pending_files (view, UPDATE_INTERVAL_MIN);
+ nautilus_profile_start (NULL);
+ process_new_files (view);
+ if (g_hash_table_size (view->details->non_ready_files) == 0)
+ {
+ /* Unschedule a pending update and schedule a new one with the minimal
+ * update interval. This gives the view a short chance at gathering the
+ * (cached) deep counts.
+ */
+ unschedule_display_of_pending_files (view);
+ schedule_timeout_display_of_pending_files (view, UPDATE_INTERVAL_MIN);
- remove_loading_floating_bar (view);
- }
- nautilus_profile_end (NULL);
+ remove_loading_floating_bar (view);
+ }
+ nautilus_profile_end (NULL);
}
static void
@@ -4004,75 +4264,75 @@ load_error_callback (NautilusDirectory *directory,
GError *error,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- /* FIXME: By doing a stop, we discard some pending files. Is
- * that OK?
- */
- nautilus_files_view_stop_loading (view);
+ /* FIXME: By doing a stop, we discard some pending files. Is
+ * that OK?
+ */
+ nautilus_files_view_stop_loading (view);
- nautilus_report_error_loading_directory
- (nautilus_files_view_get_directory_as_file (view),
- error,
- nautilus_files_view_get_containing_window (view));
+ nautilus_report_error_loading_directory
+ (nautilus_files_view_get_directory_as_file (view),
+ error,
+ nautilus_files_view_get_containing_window (view));
}
void
nautilus_files_view_add_subdirectory (NautilusFilesView *view,
NautilusDirectory *directory)
{
- NautilusFileAttributes attributes;
+ NautilusFileAttributes attributes;
- g_assert (!g_list_find (view->details->subdirectory_list, directory));
+ g_assert (!g_list_find (view->details->subdirectory_list, directory));
- nautilus_directory_ref (directory);
+ nautilus_directory_ref (directory);
- attributes =
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT |
- NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
-
- nautilus_directory_file_monitor_add (directory,
- &view->details->model,
- view->details->show_hidden_files,
- attributes,
- files_added_callback, view);
-
- g_signal_connect
- (directory, "files-added",
- G_CALLBACK (files_added_callback), view);
- g_signal_connect
- (directory, "files-changed",
- G_CALLBACK (files_changed_callback), view);
-
- view->details->subdirectory_list = g_list_prepend (
- view->details->subdirectory_list, directory);
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
+
+ nautilus_directory_file_monitor_add (directory,
+ &view->details->model,
+ view->details->show_hidden_files,
+ attributes,
+ files_added_callback, view);
+
+ g_signal_connect
+ (directory, "files-added",
+ G_CALLBACK (files_added_callback), view);
+ g_signal_connect
+ (directory, "files-changed",
+ G_CALLBACK (files_changed_callback), view);
+
+ view->details->subdirectory_list = g_list_prepend (
+ view->details->subdirectory_list, directory);
}
void
nautilus_files_view_remove_subdirectory (NautilusFilesView *view,
NautilusDirectory *directory)
{
- g_assert (g_list_find (view->details->subdirectory_list, directory));
+ g_assert (g_list_find (view->details->subdirectory_list, directory));
- view->details->subdirectory_list = g_list_remove (
- view->details->subdirectory_list, directory);
+ view->details->subdirectory_list = g_list_remove (
+ view->details->subdirectory_list, directory);
- g_signal_handlers_disconnect_by_func (directory,
- G_CALLBACK (files_added_callback),
- view);
- g_signal_handlers_disconnect_by_func (directory,
- G_CALLBACK (files_changed_callback),
- view);
+ g_signal_handlers_disconnect_by_func (directory,
+ G_CALLBACK (files_added_callback),
+ view);
+ g_signal_handlers_disconnect_by_func (directory,
+ G_CALLBACK (files_changed_callback),
+ view);
- nautilus_directory_file_monitor_remove (directory, &view->details->model);
+ nautilus_directory_file_monitor_remove (directory, &view->details->model);
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
}
/**
@@ -4085,9 +4345,9 @@ nautilus_files_view_remove_subdirectory (NautilusFilesView *view,
gboolean
nautilus_files_view_get_loading (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return view->details->loading;
+ return view->details->loading;
}
/**
@@ -4102,25 +4362,25 @@ nautilus_files_view_get_loading (NautilusFilesView *view)
NautilusDirectory *
nautilus_files_view_get_model (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return view->details->model;
+ return view->details->model;
}
-GtkWidget*
+GtkWidget *
nautilus_files_view_get_content_widget (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- return view->details->scrolled_window;
+ return view->details->scrolled_window;
}
GdkAtom
nautilus_files_view_get_copied_files_atom (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), GDK_NONE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), GDK_NONE);
- return copied_files_atom;
+ return copied_files_atom;
}
static void
@@ -4128,39 +4388,43 @@ offset_drop_points (GArray *relative_item_points,
int x_offset,
int y_offset)
{
- guint index;
+ guint index;
- if (relative_item_points == NULL) {
- return;
- }
+ if (relative_item_points == NULL)
+ {
+ return;
+ }
- for (index = 0; index < relative_item_points->len; index++) {
- g_array_index (relative_item_points, GdkPoint, index).x += x_offset;
- g_array_index (relative_item_points, GdkPoint, index).y += y_offset;
- }
+ for (index = 0; index < relative_item_points->len; index++)
+ {
+ g_array_index (relative_item_points, GdkPoint, index).x += x_offset;
+ g_array_index (relative_item_points, GdkPoint, index).y += y_offset;
+ }
}
static gboolean
nautilus_files_view_special_link_in_selection (NautilusFilesView *view,
GList *selection)
{
- gboolean saw_link;
- GList *node;
- NautilusFile *file;
+ gboolean saw_link;
+ GList *node;
+ NautilusFile *file;
- saw_link = FALSE;
+ saw_link = FALSE;
- for (node = selection; node != NULL; node = node->next) {
- file = NAUTILUS_FILE (node->data);
+ for (node = selection; node != NULL; node = node->next)
+ {
+ file = NAUTILUS_FILE (node->data);
- saw_link = nautilus_file_is_special_link (file);
+ saw_link = nautilus_file_is_special_link (file);
- if (saw_link) {
- break;
- }
+ if (saw_link)
+ {
+ break;
}
+ }
- return saw_link;
+ return saw_link;
}
/* desktop_or_home_dir_in_selection
@@ -4171,25 +4435,27 @@ nautilus_files_view_special_link_in_selection (NautilusFilesView *view,
static gboolean
desktop_or_home_dir_in_selection (GList *selection)
{
- gboolean saw_desktop_or_home_dir;
- GList *node;
- NautilusFile *file;
+ gboolean saw_desktop_or_home_dir;
+ GList *node;
+ NautilusFile *file;
- saw_desktop_or_home_dir = FALSE;
+ saw_desktop_or_home_dir = FALSE;
- for (node = selection; node != NULL; node = node->next) {
- file = NAUTILUS_FILE (node->data);
+ for (node = selection; node != NULL; node = node->next)
+ {
+ file = NAUTILUS_FILE (node->data);
- saw_desktop_or_home_dir =
- nautilus_file_is_home (file)
- || nautilus_file_is_desktop_directory (file);
+ saw_desktop_or_home_dir =
+ nautilus_file_is_home (file)
+ || nautilus_file_is_desktop_directory (file);
- if (saw_desktop_or_home_dir) {
- break;
- }
+ if (saw_desktop_or_home_dir)
+ {
+ break;
}
+ }
- return saw_desktop_or_home_dir;
+ return saw_desktop_or_home_dir;
}
static void
@@ -4197,9 +4463,10 @@ trash_or_delete_done_cb (GHashTable *debuting_uris,
gboolean user_cancel,
NautilusFilesView *view)
{
- if (user_cancel) {
- view->details->selection_was_removed = FALSE;
- }
+ if (user_cancel)
+ {
+ view->details->selection_was_removed = FALSE;
+ }
}
static void
@@ -4207,133 +4474,139 @@ trash_or_delete_files (GtkWindow *parent_window,
const GList *files,
NautilusFilesView *view)
{
- GList *locations;
- const GList *node;
+ GList *locations;
+ const GList *node;
- locations = NULL;
- for (node = files; node != NULL; node = node->next) {
- locations = g_list_prepend (locations,
- nautilus_file_get_location ((NautilusFile *) node->data));
- }
+ locations = NULL;
+ for (node = files; node != NULL; node = node->next)
+ {
+ locations = g_list_prepend (locations,
+ nautilus_file_get_location ((NautilusFile *) node->data));
+ }
- locations = g_list_reverse (locations);
+ locations = g_list_reverse (locations);
- nautilus_file_operations_trash_or_delete (locations,
- parent_window,
- (NautilusDeleteCallback) trash_or_delete_done_cb,
- view);
- g_list_free_full (locations, g_object_unref);
+ nautilus_file_operations_trash_or_delete (locations,
+ parent_window,
+ (NautilusDeleteCallback) trash_or_delete_done_cb,
+ view);
+ g_list_free_full (locations, g_object_unref);
}
static void
open_one_in_new_window (gpointer data,
gpointer callback_data)
{
- g_assert (NAUTILUS_IS_FILE (data));
- g_assert (NAUTILUS_IS_FILES_VIEW (callback_data));
+ g_assert (NAUTILUS_IS_FILE (data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (callback_data));
- nautilus_files_view_activate_file (NAUTILUS_FILES_VIEW (callback_data),
- NAUTILUS_FILE (data),
- NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW);
+ nautilus_files_view_activate_file (NAUTILUS_FILES_VIEW (callback_data),
+ NAUTILUS_FILE (data),
+ NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW);
}
static void
update_context_menu_position_from_event (NautilusFilesView *view,
GdkEventButton *event)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- if (event != NULL) {
- view->details->context_menu_position.x = event->x;
- view->details->context_menu_position.y = event->y;
- } else {
- view->details->context_menu_position.x = -1;
- view->details->context_menu_position.y = -1;
- }
+ if (event != NULL)
+ {
+ view->details->context_menu_position.x = event->x;
+ view->details->context_menu_position.y = event->y;
+ }
+ else
+ {
+ view->details->context_menu_position.x = -1;
+ view->details->context_menu_position.y = -1;
+ }
}
NautilusFile *
nautilus_files_view_get_directory_as_file (NautilusFilesView *view)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- return view->details->directory_as_file;
+ return view->details->directory_as_file;
}
static GdkPixbuf *
get_menu_icon_for_file (NautilusFile *file,
GtkWidget *widget)
{
- NautilusIconInfo *info;
- GdkPixbuf *pixbuf;
- int size, scale;
+ NautilusIconInfo *info;
+ GdkPixbuf *pixbuf;
+ int size, scale;
- size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
- scale = gtk_widget_get_scale_factor (widget);
+ size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
+ scale = gtk_widget_get_scale_factor (widget);
- info = nautilus_file_get_icon (file, size, scale, 0);
- pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size);
- g_object_unref (info);
+ info = nautilus_file_get_icon (file, size, scale, 0);
+ pixbuf = nautilus_icon_info_get_pixbuf_nodefault_at_size (info, size);
+ g_object_unref (info);
- return pixbuf;
+ return pixbuf;
}
static GList *
get_extension_selection_menu_items (NautilusFilesView *view)
{
- NautilusWindow *window;
- GList *items;
- GList *providers;
- GList *l;
- GList *selection;
+ NautilusWindow *window;
+ GList *items;
+ GList *providers;
+ GList *l;
+ GList *selection;
- window = nautilus_files_view_get_window (view);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
- items = NULL;
-
- for (l = providers; l != NULL; l = l->next) {
- NautilusMenuProvider *provider;
- GList *file_items;
-
- provider = NAUTILUS_MENU_PROVIDER (l->data);
- file_items = nautilus_menu_provider_get_file_items (provider,
- GTK_WIDGET (window),
- selection);
- items = g_list_concat (items, file_items);
- }
+ window = nautilus_files_view_get_window (view);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
+ items = NULL;
- nautilus_module_extension_list_free (providers);
+ for (l = providers; l != NULL; l = l->next)
+ {
+ NautilusMenuProvider *provider;
+ GList *file_items;
- return items;
+ provider = NAUTILUS_MENU_PROVIDER (l->data);
+ file_items = nautilus_menu_provider_get_file_items (provider,
+ GTK_WIDGET (window),
+ selection);
+ items = g_list_concat (items, file_items);
+ }
+
+ nautilus_module_extension_list_free (providers);
+
+ return items;
}
static GList *
get_extension_background_menu_items (NautilusFilesView *view)
{
- NautilusWindow *window;
- GList *items;
- GList *providers;
- GList *l;
+ NautilusWindow *window;
+ GList *items;
+ GList *providers;
+ GList *l;
- window = nautilus_files_view_get_window (view);
- providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
- items = NULL;
+ window = nautilus_files_view_get_window (view);
+ providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_MENU_PROVIDER);
+ items = NULL;
- for (l = providers; l != NULL; l = l->next) {
- NautilusMenuProvider *provider;
- GList *file_items;
+ for (l = providers; l != NULL; l = l->next)
+ {
+ NautilusMenuProvider *provider;
+ GList *file_items;
- provider = NAUTILUS_MENU_PROVIDER (l->data);
- file_items = nautilus_menu_provider_get_background_items (provider,
- GTK_WIDGET (window),
- view->details->directory_as_file);
- items = g_list_concat (items, file_items);
- }
+ provider = NAUTILUS_MENU_PROVIDER (l->data);
+ file_items = nautilus_menu_provider_get_background_items (provider,
+ GTK_WIDGET (window),
+ view->details->directory_as_file);
+ items = g_list_concat (items, file_items);
+ }
- nautilus_module_extension_list_free (providers);
+ nautilus_module_extension_list_free (providers);
- return items;
+ return items;
}
static void
@@ -4341,8 +4614,8 @@ extension_action_callback (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusMenuItem *item = user_data;
- nautilus_menu_item_activate (item);
+ NautilusMenuItem *item = user_data;
+ nautilus_menu_item_activate (item);
}
static void
@@ -4350,24 +4623,24 @@ add_extension_action (NautilusFilesView *view,
NautilusMenuItem *item,
const char *action_name)
{
- gboolean sensitive;
- GSimpleAction *action;
+ gboolean sensitive;
+ GSimpleAction *action;
- g_object_get (item,
- "sensitive", &sensitive,
- NULL);
+ g_object_get (item,
+ "sensitive", &sensitive,
+ NULL);
- action = g_simple_action_new (action_name, NULL);
- g_signal_connect_data (action, "activate",
- G_CALLBACK (extension_action_callback),
- g_object_ref (item),
- (GClosureNotify) g_object_unref, 0);
+ action = g_simple_action_new (action_name, NULL);
+ g_signal_connect_data (action, "activate",
+ G_CALLBACK (extension_action_callback),
+ g_object_ref (item),
+ (GClosureNotify) g_object_unref, 0);
- g_action_map_add_action (G_ACTION_MAP (view->details->view_action_group),
- G_ACTION (action));
- g_simple_action_set_enabled (action, sensitive);
+ g_action_map_add_action (G_ACTION_MAP (view->details->view_action_group),
+ G_ACTION (action));
+ g_simple_action_set_enabled (action, sensitive);
- g_object_unref (action);
+ g_object_unref (action);
}
static GMenu *
@@ -4375,60 +4648,62 @@ build_menu_for_extension_menu_items (NautilusFilesView *view,
const gchar *extension_prefix,
GList *menu_items)
{
- GList *l;
- GMenu *gmenu;
- gint idx = 0;
+ GList *l;
+ GMenu *gmenu;
+ gint idx = 0;
- gmenu = g_menu_new ();
+ gmenu = g_menu_new ();
- for (l = menu_items; l; l = l->next) {
- NautilusMenuItem *item;
- NautilusMenu *menu;
- GMenuItem *menu_item;
- char *name, *label;
- char *extension_id, *prefix, *parsed_name, *detailed_action_name;
+ for (l = menu_items; l; l = l->next)
+ {
+ NautilusMenuItem *item;
+ NautilusMenu *menu;
+ GMenuItem *menu_item;
+ char *name, *label;
+ char *extension_id, *prefix, *parsed_name, *detailed_action_name;
- item = NAUTILUS_MENU_ITEM (l->data);
+ item = NAUTILUS_MENU_ITEM (l->data);
- g_object_get (item,
- "label", &label,
- "menu", &menu,
- "name", &name,
- NULL);
+ g_object_get (item,
+ "label", &label,
+ "menu", &menu,
+ "name", &name,
+ NULL);
- extension_id = g_strdup_printf ("%s_%d", extension_prefix, idx);
- prefix = g_strdup_printf ("extension_%s_", extension_id);
- parsed_name = nautilus_escape_action_name (name, prefix);
- add_extension_action (view, item, parsed_name);
+ extension_id = g_strdup_printf ("%s_%d", extension_prefix, idx);
+ prefix = g_strdup_printf ("extension_%s_", extension_id);
+ parsed_name = nautilus_escape_action_name (name, prefix);
+ add_extension_action (view, item, parsed_name);
- detailed_action_name = g_strconcat ("view.", parsed_name, NULL);
- menu_item = g_menu_item_new (label, detailed_action_name);
+ detailed_action_name = g_strconcat ("view.", parsed_name, NULL);
+ menu_item = g_menu_item_new (label, detailed_action_name);
- if (menu != NULL) {
- GList *children;
- GMenu *children_menu;
+ if (menu != NULL)
+ {
+ GList *children;
+ GMenu *children_menu;
- children = nautilus_menu_get_items (menu);
- children_menu = build_menu_for_extension_menu_items (view, extension_id, children);
- g_menu_item_set_submenu (menu_item, G_MENU_MODEL (children_menu));
+ children = nautilus_menu_get_items (menu);
+ children_menu = build_menu_for_extension_menu_items (view, extension_id, children);
+ g_menu_item_set_submenu (menu_item, G_MENU_MODEL (children_menu));
- nautilus_menu_item_list_free (children);
- g_object_unref (children_menu);
- }
+ nautilus_menu_item_list_free (children);
+ g_object_unref (children_menu);
+ }
- g_menu_append_item (gmenu, menu_item);
- idx++;
+ g_menu_append_item (gmenu, menu_item);
+ idx++;
- g_free (extension_id);
- g_free (parsed_name);
- g_free (prefix);
- g_free (detailed_action_name);
- g_free (name);
- g_free (label);
- g_object_unref (menu_item);
- }
+ g_free (extension_id);
+ g_free (parsed_name);
+ g_free (prefix);
+ g_free (detailed_action_name);
+ g_free (name);
+ g_free (label);
+ g_object_unref (menu_item);
+ }
- return gmenu;
+ return gmenu;
}
static void
@@ -4437,153 +4712,166 @@ add_extension_menu_items (NautilusFilesView *view,
GList *menu_items,
GMenu *insertion_menu)
{
- GMenu *menu;
+ GMenu *menu;
- menu = build_menu_for_extension_menu_items (view, extension_prefix, menu_items);
- nautilus_gmenu_merge (insertion_menu,
- menu,
- "extensions",
- FALSE);
+ menu = build_menu_for_extension_menu_items (view, extension_prefix, menu_items);
+ nautilus_gmenu_merge (insertion_menu,
+ menu,
+ "extensions",
+ FALSE);
- g_object_unref (menu);
+ g_object_unref (menu);
}
static void
update_extensions_menus (NautilusFilesView *view)
{
- GList *selection_items, *background_items;
-
- selection_items = get_extension_selection_menu_items (view);
- if (selection_items != NULL) {
- add_extension_menu_items (view,
- "selection",
- selection_items,
- view->details->selection_menu);
- nautilus_menu_item_list_free (selection_items);
- }
-
- background_items = get_extension_background_menu_items (view);
- if (background_items != NULL) {
- add_extension_menu_items (view,
- "background",
- background_items,
- view->details->background_menu);
- nautilus_menu_item_list_free (background_items);
- }
+ GList *selection_items, *background_items;
+
+ selection_items = get_extension_selection_menu_items (view);
+ if (selection_items != NULL)
+ {
+ add_extension_menu_items (view,
+ "selection",
+ selection_items,
+ view->details->selection_menu);
+ nautilus_menu_item_list_free (selection_items);
+ }
+
+ background_items = get_extension_background_menu_items (view);
+ if (background_items != NULL)
+ {
+ add_extension_menu_items (view,
+ "background",
+ background_items,
+ view->details->background_menu);
+ nautilus_menu_item_list_free (background_items);
+ }
}
static char *
change_to_view_directory (NautilusFilesView *view)
{
- char *path;
- char *old_path;
+ char *path;
+ char *old_path;
- old_path = g_get_current_dir ();
+ old_path = g_get_current_dir ();
- path = get_view_directory (view);
+ path = get_view_directory (view);
- /* FIXME: What to do about non-local directories? */
- if (path != NULL) {
- g_chdir (path);
- }
+ /* FIXME: What to do about non-local directories? */
+ if (path != NULL)
+ {
+ g_chdir (path);
+ }
- g_free (path);
+ g_free (path);
- return old_path;
+ return old_path;
}
static char **
get_file_names_as_parameter_array (GList *selection,
NautilusDirectory *model)
{
- NautilusFile *file;
- char **parameters;
- GList *node;
- GFile *file_location;
- GFile *model_location;
- int i;
-
- if (model == NULL) {
- return NULL;
- }
+ NautilusFile *file;
+ char **parameters;
+ GList *node;
+ GFile *file_location;
+ GFile *model_location;
+ int i;
- parameters = g_new (char *, g_list_length (selection) + 1);
+ if (model == NULL)
+ {
+ return NULL;
+ }
- model_location = nautilus_directory_get_location (model);
+ parameters = g_new (char *, g_list_length (selection) + 1);
- for (node = selection, i = 0; node != NULL; node = node->next, i++) {
- file = NAUTILUS_FILE (node->data);
+ model_location = nautilus_directory_get_location (model);
- if (!nautilus_file_is_local (file)) {
- parameters[i] = NULL;
- g_strfreev (parameters);
- return NULL;
- }
+ for (node = selection, i = 0; node != NULL; node = node->next, i++)
+ {
+ file = NAUTILUS_FILE (node->data);
- file_location = nautilus_file_get_location (NAUTILUS_FILE (node->data));
- parameters[i] = g_file_get_relative_path (model_location, file_location);
- if (parameters[i] == NULL) {
- parameters[i] = g_file_get_path (file_location);
- }
- g_object_unref (file_location);
+ if (!nautilus_file_is_local (file))
+ {
+ parameters[i] = NULL;
+ g_strfreev (parameters);
+ return NULL;
}
- g_object_unref (model_location);
+ file_location = nautilus_file_get_location (NAUTILUS_FILE (node->data));
+ parameters[i] = g_file_get_relative_path (model_location, file_location);
+ if (parameters[i] == NULL)
+ {
+ parameters[i] = g_file_get_path (file_location);
+ }
+ g_object_unref (file_location);
+ }
+
+ g_object_unref (model_location);
- parameters[i] = NULL;
- return parameters;
+ parameters[i] = NULL;
+ return parameters;
}
-static char*
+static char *
get_file_paths_or_uris_as_newline_delimited_string (NautilusFilesView *view,
GList *selection,
gboolean get_paths)
{
- char *path;
- char *uri;
- char *result;
- GString *expanding_string;
- GList *node;
-
- expanding_string = g_string_new ("");
- for (node = selection; node != NULL; node = node->next) {
- uri = nautilus_file_get_target_uri (NAUTILUS_FILE (node->data));
- if (uri == NULL) {
- continue;
- }
+ char *path;
+ char *uri;
+ char *result;
+ GString *expanding_string;
+ GList *node;
- if (get_paths) {
- path = g_filename_from_uri (uri, NULL, NULL);
- if (path != NULL) {
- g_string_append (expanding_string, path);
- g_free (path);
- g_string_append (expanding_string, "\n");
- }
- } else {
- g_string_append (expanding_string, uri);
- g_string_append (expanding_string, "\n");
- }
- g_free (uri);
+ expanding_string = g_string_new ("");
+ for (node = selection; node != NULL; node = node->next)
+ {
+ uri = nautilus_file_get_target_uri (NAUTILUS_FILE (node->data));
+ if (uri == NULL)
+ {
+ continue;
+ }
+
+ if (get_paths)
+ {
+ path = g_filename_from_uri (uri, NULL, NULL);
+ if (path != NULL)
+ {
+ g_string_append (expanding_string, path);
+ g_free (path);
+ g_string_append (expanding_string, "\n");
+ }
+ }
+ else
+ {
+ g_string_append (expanding_string, uri);
+ g_string_append (expanding_string, "\n");
}
+ g_free (uri);
+ }
- result = expanding_string->str;
- g_string_free (expanding_string, FALSE);
+ result = expanding_string->str;
+ g_string_free (expanding_string, FALSE);
- return result;
+ return result;
}
static char *
get_file_paths_as_newline_delimited_string (NautilusFilesView *view,
GList *selection)
{
- return get_file_paths_or_uris_as_newline_delimited_string (view, selection, TRUE);
+ return get_file_paths_or_uris_as_newline_delimited_string (view, selection, TRUE);
}
static char *
get_file_uris_as_newline_delimited_string (NautilusFilesView *view,
GList *selection)
{
- return get_file_paths_or_uris_as_newline_delimited_string (view, selection, FALSE);
+ return get_file_paths_or_uris_as_newline_delimited_string (view, selection, FALSE);
}
/* returns newly allocated strings for setting the environment variables */
@@ -4594,28 +4882,32 @@ get_strings_for_environment_variables (NautilusFilesView *view,
char **uris,
char **uri)
{
- char *directory_uri;
-
- /* We need to check that the directory uri starts with "file:" since
- * nautilus_directory_is_local returns FALSE for nfs.
- */
- directory_uri = nautilus_directory_get_uri (view->details->model);
- if (g_str_has_prefix (directory_uri, "file:") ||
- eel_uri_is_desktop (directory_uri) ||
- eel_uri_is_trash (directory_uri)) {
- *file_paths = get_file_paths_as_newline_delimited_string (view, selected_files);
- } else {
- *file_paths = g_strdup ("");
- }
- g_free (directory_uri);
-
- *uris = get_file_uris_as_newline_delimited_string (view, selected_files);
-
- *uri = nautilus_directory_get_uri (view->details->model);
- if (eel_uri_is_desktop (*uri)) {
- g_free (*uri);
- *uri = nautilus_get_desktop_directory_uri ();
- }
+ char *directory_uri;
+
+ /* We need to check that the directory uri starts with "file:" since
+ * nautilus_directory_is_local returns FALSE for nfs.
+ */
+ directory_uri = nautilus_directory_get_uri (view->details->model);
+ if (g_str_has_prefix (directory_uri, "file:") ||
+ eel_uri_is_desktop (directory_uri) ||
+ eel_uri_is_trash (directory_uri))
+ {
+ *file_paths = get_file_paths_as_newline_delimited_string (view, selected_files);
+ }
+ else
+ {
+ *file_paths = g_strdup ("");
+ }
+ g_free (directory_uri);
+
+ *uris = get_file_uris_as_newline_delimited_string (view, selected_files);
+
+ *uri = nautilus_directory_get_uri (view->details->model);
+ if (eel_uri_is_desktop (*uri))
+ {
+ g_free (*uri);
+ *uri = nautilus_get_desktop_directory_uri ();
+ }
}
/*
@@ -4626,37 +4918,37 @@ static void
set_script_environment_variables (NautilusFilesView *view,
GList *selected_files)
{
- char *file_paths;
- char *uris;
- char *uri;
- char *geometry_string;
+ char *file_paths;
+ char *uris;
+ char *uri;
+ char *geometry_string;
- get_strings_for_environment_variables (view, selected_files,
- &file_paths, &uris, &uri);
+ get_strings_for_environment_variables (view, selected_files,
+ &file_paths, &uris, &uri);
- g_setenv ("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS", file_paths, TRUE);
- g_free (file_paths);
+ g_setenv ("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS", file_paths, TRUE);
+ g_free (file_paths);
- g_setenv ("NAUTILUS_SCRIPT_SELECTED_URIS", uris, TRUE);
- g_free (uris);
+ g_setenv ("NAUTILUS_SCRIPT_SELECTED_URIS", uris, TRUE);
+ g_free (uris);
- g_setenv ("NAUTILUS_SCRIPT_CURRENT_URI", uri, TRUE);
- g_free (uri);
+ g_setenv ("NAUTILUS_SCRIPT_CURRENT_URI", uri, TRUE);
+ g_free (uri);
- geometry_string = eel_gtk_window_get_geometry_string
- (GTK_WINDOW (nautilus_files_view_get_containing_window (view)));
- g_setenv ("NAUTILUS_SCRIPT_WINDOW_GEOMETRY", geometry_string, TRUE);
- g_free (geometry_string);
+ geometry_string = eel_gtk_window_get_geometry_string
+ (GTK_WINDOW (nautilus_files_view_get_containing_window (view)));
+ g_setenv ("NAUTILUS_SCRIPT_WINDOW_GEOMETRY", geometry_string, TRUE);
+ g_free (geometry_string);
}
/* Unset all the special script environment variables. */
static void
unset_script_environment_variables (void)
{
- g_unsetenv ("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS");
- g_unsetenv ("NAUTILUS_SCRIPT_SELECTED_URIS");
- g_unsetenv ("NAUTILUS_SCRIPT_CURRENT_URI");
- g_unsetenv ("NAUTILUS_SCRIPT_WINDOW_GEOMETRY");
+ g_unsetenv ("NAUTILUS_SCRIPT_SELECTED_FILE_PATHS");
+ g_unsetenv ("NAUTILUS_SCRIPT_SELECTED_URIS");
+ g_unsetenv ("NAUTILUS_SCRIPT_CURRENT_URI");
+ g_unsetenv ("NAUTILUS_SCRIPT_WINDOW_GEOMETRY");
}
static void
@@ -4664,47 +4956,47 @@ run_script (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- ScriptLaunchParameters *launch_parameters;
- GdkScreen *screen;
- GList *selected_files;
- char *file_uri;
- char *local_file_path;
- char *quoted_path;
- char *old_working_dir;
- char **parameters;
+ ScriptLaunchParameters *launch_parameters;
+ GdkScreen *screen;
+ GList *selected_files;
+ char *file_uri;
+ char *local_file_path;
+ char *quoted_path;
+ char *old_working_dir;
+ char **parameters;
- launch_parameters = (ScriptLaunchParameters *) user_data;
+ launch_parameters = (ScriptLaunchParameters *) user_data;
- file_uri = nautilus_file_get_uri (launch_parameters->file);
- local_file_path = g_filename_from_uri (file_uri, NULL, NULL);
- g_assert (local_file_path != NULL);
- g_free (file_uri);
+ file_uri = nautilus_file_get_uri (launch_parameters->file);
+ local_file_path = g_filename_from_uri (file_uri, NULL, NULL);
+ g_assert (local_file_path != NULL);
+ g_free (file_uri);
- quoted_path = g_shell_quote (local_file_path);
- g_free (local_file_path);
+ quoted_path = g_shell_quote (local_file_path);
+ g_free (local_file_path);
- old_working_dir = change_to_view_directory (launch_parameters->directory_view);
+ old_working_dir = change_to_view_directory (launch_parameters->directory_view);
- selected_files = nautilus_view_get_selection (NAUTILUS_VIEW (launch_parameters->directory_view));
- set_script_environment_variables (launch_parameters->directory_view, selected_files);
+ selected_files = nautilus_view_get_selection (NAUTILUS_VIEW (launch_parameters->directory_view));
+ set_script_environment_variables (launch_parameters->directory_view, selected_files);
- parameters = get_file_names_as_parameter_array (selected_files,
- launch_parameters->directory_view->details->model);
+ parameters = get_file_names_as_parameter_array (selected_files,
+ launch_parameters->directory_view->details->model);
- screen = gtk_widget_get_screen (GTK_WIDGET (launch_parameters->directory_view));
+ screen = gtk_widget_get_screen (GTK_WIDGET (launch_parameters->directory_view));
- DEBUG ("run_script, script_path=“%s” (omitting script parameters)",
- local_file_path);
+ DEBUG ("run_script, script_path=“%s” (omitting script parameters)",
+ local_file_path);
- nautilus_launch_application_from_command_array (screen, quoted_path, FALSE,
- (const char * const *) parameters);
- g_strfreev (parameters);
+ nautilus_launch_application_from_command_array (screen, quoted_path, FALSE,
+ (const char * const *) parameters);
+ g_strfreev (parameters);
- nautilus_file_list_free (selected_files);
- unset_script_environment_variables ();
- g_chdir (old_working_dir);
- g_free (old_working_dir);
- g_free (quoted_path);
+ nautilus_file_list_free (selected_files);
+ unset_script_environment_variables ();
+ g_chdir (old_working_dir);
+ g_free (old_working_dir);
+ g_free (quoted_path);
}
static void
@@ -4712,178 +5004,196 @@ add_script_to_scripts_menus (NautilusFilesView *view,
NautilusFile *file,
GMenu *menu)
{
- gchar *name;
- GdkPixbuf *mimetype_icon;
- gchar *action_name, *detailed_action_name;
- ScriptLaunchParameters *launch_parameters;
- GAction *action;
- GMenuItem *menu_item;
- const gchar *shortcut;
+ gchar *name;
+ GdkPixbuf *mimetype_icon;
+ gchar *action_name, *detailed_action_name;
+ ScriptLaunchParameters *launch_parameters;
+ GAction *action;
+ GMenuItem *menu_item;
+ const gchar *shortcut;
- launch_parameters = script_launch_parameters_new (file, view);
+ launch_parameters = script_launch_parameters_new (file, view);
- name = nautilus_file_get_display_name (file);
- action_name = nautilus_escape_action_name (name, "script_");
+ name = nautilus_file_get_display_name (file);
+ action_name = nautilus_escape_action_name (name, "script_");
- action = G_ACTION (g_simple_action_new (action_name, NULL));
+ action = G_ACTION (g_simple_action_new (action_name, NULL));
- g_signal_connect_data (action, "activate",
- G_CALLBACK (run_script),
- launch_parameters,
- (GClosureNotify)script_launch_parameters_free, 0);
+ g_signal_connect_data (action, "activate",
+ G_CALLBACK (run_script),
+ launch_parameters,
+ (GClosureNotify) script_launch_parameters_free, 0);
- g_action_map_add_action (G_ACTION_MAP (view->details->view_action_group), action);
+ g_action_map_add_action (G_ACTION_MAP (view->details->view_action_group), action);
- g_object_unref (action);
+ g_object_unref (action);
- detailed_action_name = g_strconcat ("view.", action_name, NULL);
- menu_item = g_menu_item_new (name, detailed_action_name);
+ detailed_action_name = g_strconcat ("view.", action_name, NULL);
+ menu_item = g_menu_item_new (name, detailed_action_name);
- mimetype_icon = get_menu_icon_for_file (file, GTK_WIDGET (view));
- if (mimetype_icon != NULL) {
- g_menu_item_set_icon (menu_item, G_ICON (mimetype_icon));
- g_object_unref (mimetype_icon);
- }
+ mimetype_icon = get_menu_icon_for_file (file, GTK_WIDGET (view));
+ if (mimetype_icon != NULL)
+ {
+ g_menu_item_set_icon (menu_item, G_ICON (mimetype_icon));
+ g_object_unref (mimetype_icon);
+ }
- g_menu_append_item (menu, menu_item);
+ g_menu_append_item (menu, menu_item);
- if ((shortcut = g_hash_table_lookup (script_accels, name))) {
- nautilus_application_set_accelerator (g_application_get_default(),
- detailed_action_name, shortcut);
- }
+ if ((shortcut = g_hash_table_lookup (script_accels, name)))
+ {
+ nautilus_application_set_accelerator (g_application_get_default (),
+ detailed_action_name, shortcut);
+ }
- g_free (name);
- g_free (action_name);
- g_free (detailed_action_name);
- g_object_unref (menu_item);
+ g_free (name);
+ g_free (action_name);
+ g_free (detailed_action_name);
+ g_object_unref (menu_item);
}
static gboolean
directory_belongs_in_scripts_menu (const char *uri)
{
- int num_levels;
- int i;
+ int num_levels;
+ int i;
- if (!g_str_has_prefix (uri, scripts_directory_uri)) {
- return FALSE;
- }
+ if (!g_str_has_prefix (uri, scripts_directory_uri))
+ {
+ return FALSE;
+ }
- num_levels = 0;
- for (i = scripts_directory_uri_length; uri[i] != '\0'; i++) {
- if (uri[i] == '/') {
- num_levels++;
- }
+ num_levels = 0;
+ for (i = scripts_directory_uri_length; uri[i] != '\0'; i++)
+ {
+ if (uri[i] == '/')
+ {
+ num_levels++;
}
+ }
- if (num_levels > MAX_MENU_LEVELS) {
- return FALSE;
- }
+ if (num_levels > MAX_MENU_LEVELS)
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
/* Expected format: accel script_name */
static void
nautilus_load_custom_accel_for_scripts (void)
{
- gchar *path, *contents;
- gchar **lines, **result;
- GError *error = NULL;
- const int max_len = 100;
- int i;
+ gchar *path, *contents;
+ gchar **lines, **result;
+ GError *error = NULL;
+ const int max_len = 100;
+ int i;
- path = g_build_filename (g_get_user_config_dir (), SHORTCUTS_PATH, NULL);
+ path = g_build_filename (g_get_user_config_dir (), SHORTCUTS_PATH, NULL);
- if (g_file_get_contents (path, &contents, NULL, &error)) {
- lines = g_strsplit (contents, "\n", -1);
- for (i = 0; lines[i] && (strstr (lines[i], " ") > 0); i++) {
- result = g_strsplit (lines[i], " ", 2);
- g_hash_table_insert (script_accels,
- g_strndup (result[1], max_len),
- g_strndup (result[0], max_len));
- g_strfreev (result);
- }
+ if (g_file_get_contents (path, &contents, NULL, &error))
+ {
+ lines = g_strsplit (contents, "\n", -1);
+ for (i = 0; lines[i] && (strstr (lines[i], " ") > 0); i++)
+ {
+ result = g_strsplit (lines[i], " ", 2);
+ g_hash_table_insert (script_accels,
+ g_strndup (result[1], max_len),
+ g_strndup (result[0], max_len));
+ g_strfreev (result);
+ }
- g_free (contents);
- g_strfreev (lines);
- } else {
- DEBUG ("Unable to open '%s', error message: %s", path, error->message);
- g_clear_error (&error);
- }
+ g_free (contents);
+ g_strfreev (lines);
+ }
+ else
+ {
+ DEBUG ("Unable to open '%s', error message: %s", path, error->message);
+ g_clear_error (&error);
+ }
- g_free (path);
+ g_free (path);
}
static GMenu *
update_directory_in_scripts_menu (NautilusFilesView *view,
NautilusDirectory *directory)
{
- GList *file_list, *filtered, *node;
- GMenu *menu, *children_menu;
- GMenuItem *menu_item;
- gboolean any_scripts;
- NautilusFile *file;
- NautilusDirectory *dir;
- char *uri;
- gchar *file_name;
- int num;
-
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
-
- if (script_accels == NULL) {
- script_accels = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, g_free);
- nautilus_load_custom_accel_for_scripts ();
- }
-
- file_list = nautilus_directory_get_file_list (directory);
- filtered = nautilus_file_list_filter_hidden (file_list, FALSE);
- nautilus_file_list_free (file_list);
- menu = g_menu_new ();
-
- filtered = nautilus_file_list_sort_by_display_name (filtered);
-
- num = 0;
- any_scripts = FALSE;
- for (node = filtered; num < TEMPLATE_LIMIT && node != NULL; node = node->next, num++) {
- file = node->data;
- if (nautilus_file_is_directory (file)) {
- uri = nautilus_file_get_uri (file);
- if (directory_belongs_in_scripts_menu (uri)) {
- dir = nautilus_directory_get_by_uri (uri);
- add_directory_to_scripts_directory_list (view, dir);
-
- children_menu = update_directory_in_scripts_menu (view, dir);
-
- if (children_menu != NULL) {
- file_name = nautilus_file_get_display_name (file);
- menu_item = g_menu_item_new_submenu (file_name,
- G_MENU_MODEL (children_menu));
- g_menu_append_item (menu, menu_item);
- any_scripts = TRUE;
- g_object_unref (menu_item);
- g_object_unref (children_menu);
- g_free (file_name);
- }
-
- nautilus_directory_unref (dir);
- }
- g_free (uri);
- } else if (nautilus_file_is_launchable (file)) {
- add_script_to_scripts_menus (view, file, menu);
- any_scripts = TRUE;
+ GList *file_list, *filtered, *node;
+ GMenu *menu, *children_menu;
+ GMenuItem *menu_item;
+ gboolean any_scripts;
+ NautilusFile *file;
+ NautilusDirectory *dir;
+ char *uri;
+ gchar *file_name;
+ int num;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+
+ if (script_accels == NULL)
+ {
+ script_accels = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_free);
+ nautilus_load_custom_accel_for_scripts ();
+ }
+
+ file_list = nautilus_directory_get_file_list (directory);
+ filtered = nautilus_file_list_filter_hidden (file_list, FALSE);
+ nautilus_file_list_free (file_list);
+ menu = g_menu_new ();
+
+ filtered = nautilus_file_list_sort_by_display_name (filtered);
+
+ num = 0;
+ any_scripts = FALSE;
+ for (node = filtered; num < TEMPLATE_LIMIT && node != NULL; node = node->next, num++)
+ {
+ file = node->data;
+ if (nautilus_file_is_directory (file))
+ {
+ uri = nautilus_file_get_uri (file);
+ if (directory_belongs_in_scripts_menu (uri))
+ {
+ dir = nautilus_directory_get_by_uri (uri);
+ add_directory_to_scripts_directory_list (view, dir);
+
+ children_menu = update_directory_in_scripts_menu (view, dir);
+
+ if (children_menu != NULL)
+ {
+ file_name = nautilus_file_get_display_name (file);
+ menu_item = g_menu_item_new_submenu (file_name,
+ G_MENU_MODEL (children_menu));
+ g_menu_append_item (menu, menu_item);
+ any_scripts = TRUE;
+ g_object_unref (menu_item);
+ g_object_unref (children_menu);
+ g_free (file_name);
}
+
+ nautilus_directory_unref (dir);
+ }
+ g_free (uri);
+ }
+ else if (nautilus_file_is_launchable (file))
+ {
+ add_script_to_scripts_menus (view, file, menu);
+ any_scripts = TRUE;
}
+ }
- nautilus_file_list_free (filtered);
+ nautilus_file_list_free (filtered);
- if (!any_scripts) {
- g_object_unref (menu);
- menu = NULL;
- }
+ if (!any_scripts)
+ {
+ g_object_unref (menu);
+ menu = NULL;
+ }
- return menu;
+ return menu;
}
@@ -4891,38 +5201,41 @@ update_directory_in_scripts_menu (NautilusFilesView *view,
static void
update_scripts_menu (NautilusFilesView *view)
{
- GList *sorted_copy, *node;
- NautilusDirectory *directory;
- GMenu *submenu;
- char *uri;
+ GList *sorted_copy, *node;
+ NautilusDirectory *directory;
+ GMenu *submenu;
+ char *uri;
- sorted_copy = nautilus_directory_list_sort_by_uri
- (nautilus_directory_list_copy (view->details->scripts_directory_list));
+ sorted_copy = nautilus_directory_list_sort_by_uri
+ (nautilus_directory_list_copy (view->details->scripts_directory_list));
- for (node = sorted_copy; node != NULL; node = node->next) {
- directory = node->data;
+ for (node = sorted_copy; node != NULL; node = node->next)
+ {
+ directory = node->data;
- uri = nautilus_directory_get_uri (directory);
- if (!directory_belongs_in_scripts_menu (uri)) {
- remove_directory_from_scripts_directory_list (view, directory);
- }
- g_free (uri);
- }
- nautilus_directory_list_free (sorted_copy);
-
- directory = nautilus_directory_get_by_uri (scripts_directory_uri);
- submenu = update_directory_in_scripts_menu (view, directory);
- if (submenu != NULL) {
- nautilus_gmenu_merge (view->details->selection_menu,
- submenu,
- "scripts-submenu",
- TRUE);
- g_object_unref (submenu);
+ uri = nautilus_directory_get_uri (directory);
+ if (!directory_belongs_in_scripts_menu (uri))
+ {
+ remove_directory_from_scripts_directory_list (view, directory);
}
+ g_free (uri);
+ }
+ nautilus_directory_list_free (sorted_copy);
- nautilus_directory_unref (directory);
+ directory = nautilus_directory_get_by_uri (scripts_directory_uri);
+ submenu = update_directory_in_scripts_menu (view, directory);
+ if (submenu != NULL)
+ {
+ nautilus_gmenu_merge (view->details->selection_menu,
+ submenu,
+ "scripts-submenu",
+ TRUE);
+ g_object_unref (submenu);
+ }
- view->details->scripts_present = submenu != NULL;
+ nautilus_directory_unref (directory);
+
+ view->details->scripts_present = submenu != NULL;
}
static void
@@ -4930,12 +5243,11 @@ create_template (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
+ CreateTemplateParameters *parameters;
- CreateTemplateParameters *parameters;
-
- parameters = user_data;
+ parameters = user_data;
- nautilus_files_view_new_file (parameters->directory_view, NULL, parameters->file);
+ nautilus_files_view_new_file (parameters->directory_view, NULL, parameters->file);
}
static void
@@ -4943,162 +5255,177 @@ add_template_to_templates_menus (NautilusFilesView *view,
NautilusFile *file,
GMenu *menu)
{
- char *tmp, *uri, *name;
- GdkPixbuf *mimetype_icon;
- char *action_name, *detailed_action_name;
- CreateTemplateParameters *parameters;
- GAction *action;
- GMenuItem *menu_item;
+ char *tmp, *uri, *name;
+ GdkPixbuf *mimetype_icon;
+ char *action_name, *detailed_action_name;
+ CreateTemplateParameters *parameters;
+ GAction *action;
+ GMenuItem *menu_item;
- tmp = nautilus_file_get_display_name (file);
- name = eel_filename_strip_extension (tmp);
- g_free (tmp);
+ tmp = nautilus_file_get_display_name (file);
+ name = eel_filename_strip_extension (tmp);
+ g_free (tmp);
- uri = nautilus_file_get_uri (file);
- action_name = nautilus_escape_action_name (uri, "template_");
- action = G_ACTION (g_simple_action_new (action_name, NULL));
- parameters = create_template_parameters_new (file, view);
+ uri = nautilus_file_get_uri (file);
+ action_name = nautilus_escape_action_name (uri, "template_");
+ action = G_ACTION (g_simple_action_new (action_name, NULL));
+ parameters = create_template_parameters_new (file, view);
- g_signal_connect_data (action, "activate",
- G_CALLBACK (create_template),
- parameters,
- (GClosureNotify)create_templates_parameters_free, 0);
+ g_signal_connect_data (action, "activate",
+ G_CALLBACK (create_template),
+ parameters,
+ (GClosureNotify) create_templates_parameters_free, 0);
- g_action_map_add_action (G_ACTION_MAP (view->details->view_action_group), action);
+ g_action_map_add_action (G_ACTION_MAP (view->details->view_action_group), action);
- detailed_action_name = g_strconcat ("view.", action_name, NULL);
- menu_item = g_menu_item_new (name, detailed_action_name);
+ detailed_action_name = g_strconcat ("view.", action_name, NULL);
+ menu_item = g_menu_item_new (name, detailed_action_name);
- mimetype_icon = get_menu_icon_for_file (file, GTK_WIDGET (view));
- if (mimetype_icon != NULL) {
- g_menu_item_set_icon (menu_item, G_ICON (mimetype_icon));
- g_object_unref (mimetype_icon);
- }
+ mimetype_icon = get_menu_icon_for_file (file, GTK_WIDGET (view));
+ if (mimetype_icon != NULL)
+ {
+ g_menu_item_set_icon (menu_item, G_ICON (mimetype_icon));
+ g_object_unref (mimetype_icon);
+ }
- g_menu_append_item (menu, menu_item);
+ g_menu_append_item (menu, menu_item);
- g_free (name);
- g_free (uri);
- g_free (action_name);
- g_free (detailed_action_name);
- g_object_unref (action);
- g_object_unref (menu_item);
+ g_free (name);
+ g_free (uri);
+ g_free (action_name);
+ g_free (detailed_action_name);
+ g_object_unref (action);
+ g_object_unref (menu_item);
}
static void
update_templates_directory (NautilusFilesView *view)
{
- NautilusDirectory *templates_directory;
- GList *node, *next;
- char *templates_uri;
+ NautilusDirectory *templates_directory;
+ GList *node, *next;
+ char *templates_uri;
- for (node = view->details->templates_directory_list; node != NULL; node = next) {
- next = node->next;
- remove_directory_from_templates_directory_list (view, node->data);
- }
+ for (node = view->details->templates_directory_list; node != NULL; node = next)
+ {
+ next = node->next;
+ remove_directory_from_templates_directory_list (view, node->data);
+ }
- if (nautilus_should_use_templates_directory ()) {
- templates_uri = nautilus_get_templates_directory_uri ();
- templates_directory = nautilus_directory_get_by_uri (templates_uri);
- g_free (templates_uri);
- add_directory_to_templates_directory_list (view, templates_directory);
- nautilus_directory_unref (templates_directory);
- }
+ if (nautilus_should_use_templates_directory ())
+ {
+ templates_uri = nautilus_get_templates_directory_uri ();
+ templates_directory = nautilus_directory_get_by_uri (templates_uri);
+ g_free (templates_uri);
+ add_directory_to_templates_directory_list (view, templates_directory);
+ nautilus_directory_unref (templates_directory);
+ }
}
static gboolean
directory_belongs_in_templates_menu (const char *templates_directory_uri,
const char *uri)
{
- int num_levels;
- int i;
+ int num_levels;
+ int i;
- if (templates_directory_uri == NULL) {
- return FALSE;
- }
+ if (templates_directory_uri == NULL)
+ {
+ return FALSE;
+ }
- if (!g_str_has_prefix (uri, templates_directory_uri)) {
- return FALSE;
- }
+ if (!g_str_has_prefix (uri, templates_directory_uri))
+ {
+ return FALSE;
+ }
- num_levels = 0;
- for (i = strlen (templates_directory_uri); uri[i] != '\0'; i++) {
- if (uri[i] == '/') {
- num_levels++;
- }
+ num_levels = 0;
+ for (i = strlen (templates_directory_uri); uri[i] != '\0'; i++)
+ {
+ if (uri[i] == '/')
+ {
+ num_levels++;
}
+ }
- if (num_levels > MAX_MENU_LEVELS) {
- return FALSE;
- }
+ if (num_levels > MAX_MENU_LEVELS)
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static GMenu *
update_directory_in_templates_menu (NautilusFilesView *view,
NautilusDirectory *directory)
{
- GList *file_list, *filtered, *node;
- GMenu *menu, *children_menu;
- GMenuItem *menu_item;
- gboolean any_templates;
- NautilusFile *file;
- NautilusDirectory *dir;
- char *uri;
- char *templates_directory_uri;
- int num;
-
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
-
- file_list = nautilus_directory_get_file_list (directory);
- filtered = nautilus_file_list_filter_hidden (file_list, FALSE);
- nautilus_file_list_free (file_list);
- templates_directory_uri = nautilus_get_templates_directory_uri ();
- menu = g_menu_new ();
-
- filtered = nautilus_file_list_sort_by_display_name (filtered);
-
- num = 0;
- any_templates = FALSE;
- for (node = filtered; num < TEMPLATE_LIMIT && node != NULL; node = node->next, num++) {
- file = node->data;
- if (nautilus_file_is_directory (file)) {
- uri = nautilus_file_get_uri (file);
- if (directory_belongs_in_templates_menu (templates_directory_uri, uri)) {
- dir = nautilus_directory_get_by_uri (uri);
- add_directory_to_templates_directory_list (view, dir);
-
- children_menu = update_directory_in_templates_menu (view, dir);
-
- if (children_menu != NULL) {
- menu_item = g_menu_item_new_submenu (nautilus_file_get_display_name (file),
- G_MENU_MODEL (children_menu));
- g_menu_append_item (menu, menu_item);
- any_templates = TRUE;
- g_object_unref (menu_item);
- g_object_unref (children_menu);
- }
-
- nautilus_directory_unref (dir);
- }
- g_free (uri);
- } else if (nautilus_file_can_read (file)) {
- add_template_to_templates_menus (view, file, menu);
- any_templates = TRUE;
+ GList *file_list, *filtered, *node;
+ GMenu *menu, *children_menu;
+ GMenuItem *menu_item;
+ gboolean any_templates;
+ NautilusFile *file;
+ NautilusDirectory *dir;
+ char *uri;
+ char *templates_directory_uri;
+ int num;
+
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_DIRECTORY (directory), NULL);
+
+ file_list = nautilus_directory_get_file_list (directory);
+ filtered = nautilus_file_list_filter_hidden (file_list, FALSE);
+ nautilus_file_list_free (file_list);
+ templates_directory_uri = nautilus_get_templates_directory_uri ();
+ menu = g_menu_new ();
+
+ filtered = nautilus_file_list_sort_by_display_name (filtered);
+
+ num = 0;
+ any_templates = FALSE;
+ for (node = filtered; num < TEMPLATE_LIMIT && node != NULL; node = node->next, num++)
+ {
+ file = node->data;
+ if (nautilus_file_is_directory (file))
+ {
+ uri = nautilus_file_get_uri (file);
+ if (directory_belongs_in_templates_menu (templates_directory_uri, uri))
+ {
+ dir = nautilus_directory_get_by_uri (uri);
+ add_directory_to_templates_directory_list (view, dir);
+
+ children_menu = update_directory_in_templates_menu (view, dir);
+
+ if (children_menu != NULL)
+ {
+ menu_item = g_menu_item_new_submenu (nautilus_file_get_display_name (file),
+ G_MENU_MODEL (children_menu));
+ g_menu_append_item (menu, menu_item);
+ any_templates = TRUE;
+ g_object_unref (menu_item);
+ g_object_unref (children_menu);
}
+
+ nautilus_directory_unref (dir);
+ }
+ g_free (uri);
}
+ else if (nautilus_file_can_read (file))
+ {
+ add_template_to_templates_menus (view, file, menu);
+ any_templates = TRUE;
+ }
+ }
- nautilus_file_list_free (filtered);
- g_free (templates_directory_uri);
+ nautilus_file_list_free (filtered);
+ g_free (templates_directory_uri);
- if (!any_templates) {
- g_object_unref (menu);
- menu = NULL;
- }
+ if (!any_templates)
+ {
+ g_object_unref (menu);
+ menu = NULL;
+ }
- return menu;
+ return menu;
}
@@ -5106,49 +5433,55 @@ update_directory_in_templates_menu (NautilusFilesView *view,
static void
update_templates_menu (NautilusFilesView *view)
{
- GList *sorted_copy, *node;
- NautilusDirectory *directory;
- GMenu *submenu;
- char *uri;
- char *templates_directory_uri;
+ GList *sorted_copy, *node;
+ NautilusDirectory *directory;
+ GMenu *submenu;
+ char *uri;
+ char *templates_directory_uri;
- if (nautilus_should_use_templates_directory ()) {
- templates_directory_uri = nautilus_get_templates_directory_uri ();
- } else {
- view->details->templates_present = FALSE;
- return;
- }
+ if (nautilus_should_use_templates_directory ())
+ {
+ templates_directory_uri = nautilus_get_templates_directory_uri ();
+ }
+ else
+ {
+ view->details->templates_present = FALSE;
+ return;
+ }
- sorted_copy = nautilus_directory_list_sort_by_uri
- (nautilus_directory_list_copy (view->details->templates_directory_list));
+ sorted_copy = nautilus_directory_list_sort_by_uri
+ (nautilus_directory_list_copy (view->details->templates_directory_list));
- for (node = sorted_copy; node != NULL; node = node->next) {
- directory = node->data;
+ for (node = sorted_copy; node != NULL; node = node->next)
+ {
+ directory = node->data;
- uri = nautilus_directory_get_uri (directory);
- if (!directory_belongs_in_templates_menu (templates_directory_uri, uri)) {
- remove_directory_from_templates_directory_list (view, directory);
- }
- g_free (uri);
- }
- nautilus_directory_list_free (sorted_copy);
-
- directory = nautilus_directory_get_by_uri (templates_directory_uri);
- submenu = update_directory_in_templates_menu (view, directory);
- if (submenu != NULL) {
- nautilus_gmenu_merge (view->details->background_menu,
- submenu,
- "templates-submenu",
- FALSE);
- g_object_unref (submenu);
+ uri = nautilus_directory_get_uri (directory);
+ if (!directory_belongs_in_templates_menu (templates_directory_uri, uri))
+ {
+ remove_directory_from_templates_directory_list (view, directory);
}
+ g_free (uri);
+ }
+ nautilus_directory_list_free (sorted_copy);
+
+ directory = nautilus_directory_get_by_uri (templates_directory_uri);
+ submenu = update_directory_in_templates_menu (view, directory);
+ if (submenu != NULL)
+ {
+ nautilus_gmenu_merge (view->details->background_menu,
+ submenu,
+ "templates-submenu",
+ FALSE);
+ g_object_unref (submenu);
+ }
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
- view->details->templates_present = submenu != NULL;
+ view->details->templates_present = submenu != NULL;
- g_free (templates_directory_uri);
+ g_free (templates_directory_uri);
}
@@ -5157,65 +5490,68 @@ action_open_scripts_folder (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- static GFile *location = NULL;
+ static GFile *location = NULL;
- if (location == NULL) {
- location = g_file_new_for_uri (scripts_directory_uri);
- }
+ if (location == NULL)
+ {
+ location = g_file_new_for_uri (scripts_directory_uri);
+ }
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location, 0, NULL, NULL, NULL);
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location, 0, NULL, NULL, NULL);
}
-typedef struct _CopyCallbackData {
- NautilusFilesView *view;
- GtkFileChooser *chooser;
- GHashTable *locations;
- GList *selection;
- gboolean is_move;
+typedef struct _CopyCallbackData
+{
+ NautilusFilesView *view;
+ GtkFileChooser *chooser;
+ GHashTable *locations;
+ GList *selection;
+ gboolean is_move;
} CopyCallbackData;
static void
copy_data_free (CopyCallbackData *data)
{
- nautilus_file_list_free (data->selection);
- g_hash_table_destroy (data->locations);
- g_free (data);
+ nautilus_file_list_free (data->selection);
+ g_hash_table_destroy (data->locations);
+ g_free (data);
}
static gboolean
uri_is_parent_of_selection (GList *selection,
const char *uri)
{
- gboolean found;
- GList *l;
- GFile *file;
+ gboolean found;
+ GList *l;
+ GFile *file;
- found = FALSE;
+ found = FALSE;
- file = g_file_new_for_uri (uri);
- for (l = selection; !found && l != NULL; l = l->next) {
- GFile *parent;
- parent = nautilus_file_get_parent_location (l->data);
- found = g_file_equal (file, parent);
- g_object_unref (parent);
- }
- g_object_unref (file);
- return found;
+ file = g_file_new_for_uri (uri);
+ for (l = selection; !found && l != NULL; l = l->next)
+ {
+ GFile *parent;
+ parent = nautilus_file_get_parent_location (l->data);
+ found = g_file_equal (file, parent);
+ g_object_unref (parent);
+ }
+ g_object_unref (file);
+ return found;
}
static void
on_destination_dialog_folder_changed (GtkFileChooser *chooser,
gpointer user_data)
{
- CopyCallbackData *copy_data = user_data;
- char *uri;
- gboolean found;
+ CopyCallbackData *copy_data = user_data;
+ char *uri;
+ gboolean found;
- uri = gtk_file_chooser_get_current_folder_uri (chooser);
- found = uri_is_parent_of_selection (copy_data->selection, uri);
- gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_OK, !found);
- g_free (uri);
+ uri = gtk_file_chooser_get_current_folder_uri (chooser);
+ found = uri_is_parent_of_selection (copy_data->selection, uri);
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser), GTK_RESPONSE_OK, !found);
+ g_free (uri);
}
static void
@@ -5223,132 +5559,143 @@ on_destination_dialog_response (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- CopyCallbackData *copy_data = user_data;
+ CopyCallbackData *copy_data = user_data;
- if (response_id == GTK_RESPONSE_OK) {
- char *target_uri;
- GList *uris, *l;
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ char *target_uri;
+ GList *uris, *l;
- target_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+ target_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
- uris = NULL;
- for (l = copy_data->selection; l != NULL; l = l->next) {
- uris = g_list_prepend (uris,
- nautilus_file_get_uri ((NautilusFile *) l->data));
- }
- uris = g_list_reverse (uris);
+ uris = NULL;
+ for (l = copy_data->selection; l != NULL; l = l->next)
+ {
+ uris = g_list_prepend (uris,
+ nautilus_file_get_uri ((NautilusFile *) l->data));
+ }
+ uris = g_list_reverse (uris);
- nautilus_files_view_move_copy_items (copy_data->view, uris, NULL, target_uri,
- copy_data->is_move ? GDK_ACTION_MOVE : GDK_ACTION_COPY,
- 0, 0);
+ nautilus_files_view_move_copy_items (copy_data->view, uris, NULL, target_uri,
+ copy_data->is_move ? GDK_ACTION_MOVE : GDK_ACTION_COPY,
+ 0, 0);
- g_list_free_full (uris, g_free);
- g_free (target_uri);
- }
+ g_list_free_full (uris, g_free);
+ g_free (target_uri);
+ }
- copy_data_free (copy_data);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ copy_data_free (copy_data);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static gboolean
destination_dialog_filter_cb (const GtkFileFilterInfo *filter_info,
gpointer user_data)
{
- GList *selection = user_data;
- GList *l;
+ GList *selection = user_data;
+ GList *l;
- for (l = selection; l != NULL; l = l->next) {
- char *uri;
- uri = nautilus_file_get_uri (l->data);
- if (strcmp (uri, filter_info->uri) == 0) {
- g_free (uri);
- return FALSE;
- }
- g_free (uri);
+ for (l = selection; l != NULL; l = l->next)
+ {
+ char *uri;
+ uri = nautilus_file_get_uri (l->data);
+ if (strcmp (uri, filter_info->uri) == 0)
+ {
+ g_free (uri);
+ return FALSE;
}
+ g_free (uri);
+ }
- return TRUE;
+ return TRUE;
}
static GList *
get_selected_folders (GList *selection)
{
- GList *folders;
- GList *l;
+ GList *folders;
+ GList *l;
- folders = NULL;
- for (l = selection; l != NULL; l = l->next) {
- if (nautilus_file_is_directory (l->data))
- folders = g_list_prepend (folders, nautilus_file_ref (l->data));
+ folders = NULL;
+ for (l = selection; l != NULL; l = l->next)
+ {
+ if (nautilus_file_is_directory (l->data))
+ {
+ folders = g_list_prepend (folders, nautilus_file_ref (l->data));
}
- return g_list_reverse (folders);
+ }
+ return g_list_reverse (folders);
}
static void
copy_or_move_selection (NautilusFilesView *view,
gboolean is_move)
{
- GtkWidget *dialog;
- char *uri;
- CopyCallbackData *copy_data;
- GList *selection;
- const gchar *title;
-
- if (is_move) {
- title = _("Select Move Destination");
- } else {
- title = _("Select Copy Destination");
- }
+ GtkWidget *dialog;
+ char *uri;
+ CopyCallbackData *copy_data;
+ GList *selection;
+ const gchar *title;
+
+ if (is_move)
+ {
+ title = _("Select Move Destination");
+ }
+ else
+ {
+ title = _("Select Copy Destination");
+ }
+
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+
+ dialog = gtk_file_chooser_dialog_new (title,
+ GTK_WINDOW (nautilus_files_view_get_window (view)),
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Select"), GTK_RESPONSE_OK,
+ NULL);
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_OK);
+
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ copy_data = g_new0 (CopyCallbackData, 1);
+ copy_data->view = view;
+ copy_data->selection = selection;
+ copy_data->is_move = is_move;
+ copy_data->chooser = GTK_FILE_CHOOSER (dialog);
+ copy_data->locations = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ if (selection != NULL)
+ {
+ GtkFileFilter *filter;
+ GList *folders;
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ folders = get_selected_folders (selection);
- dialog = gtk_file_chooser_dialog_new (title,
- GTK_WINDOW (nautilus_files_view_get_window (view)),
- GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_Select"), GTK_RESPONSE_OK,
- NULL);
- gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
-
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- GTK_RESPONSE_OK);
-
- gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- copy_data = g_new0 (CopyCallbackData, 1);
- copy_data->view = view;
- copy_data->selection = selection;
- copy_data->is_move = is_move;
- copy_data->chooser = GTK_FILE_CHOOSER (dialog);
- copy_data->locations = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
- if (selection != NULL) {
- GtkFileFilter *filter;
- GList *folders;
-
- folders = get_selected_folders (selection);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_add_custom (filter,
- GTK_FILE_FILTER_URI,
- destination_dialog_filter_cb,
- folders,
- (GDestroyNotify)nautilus_file_list_free);
- gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
- }
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_add_custom (filter,
+ GTK_FILE_FILTER_URI,
+ destination_dialog_filter_cb,
+ folders,
+ (GDestroyNotify) nautilus_file_list_free);
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+ }
- uri = nautilus_directory_get_uri (view->details->model);
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
- g_free (uri);
- g_signal_connect (dialog, "current-folder-changed",
- G_CALLBACK (on_destination_dialog_folder_changed),
- copy_data);
- g_signal_connect (dialog, "response",
- G_CALLBACK (on_destination_dialog_response),
- copy_data);
+ uri = nautilus_directory_get_uri (view->details->model);
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
+ g_free (uri);
+ g_signal_connect (dialog, "current-folder-changed",
+ G_CALLBACK (on_destination_dialog_folder_changed),
+ copy_data);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (on_destination_dialog_response),
+ copy_data);
- gtk_widget_show_all (dialog);
+ gtk_widget_show_all (dialog);
}
static void
@@ -5356,29 +5703,29 @@ copy_or_cut_files (NautilusFilesView *view,
GList *clipboard_contents,
gboolean cut)
{
- NautilusClipboardInfo info;
- GtkTargetList *target_list;
- GtkTargetEntry *targets;
- int n_targets;
+ NautilusClipboardInfo info;
+ GtkTargetList *target_list;
+ GtkTargetEntry *targets;
+ int n_targets;
- info.files = clipboard_contents;
- info.cut = cut;
+ info.files = clipboard_contents;
+ info.cut = cut;
- target_list = gtk_target_list_new (NULL, 0);
- gtk_target_list_add (target_list, copied_files_atom, 0, 0);
- gtk_target_list_add_uri_targets (target_list, 0);
- gtk_target_list_add_text_targets (target_list, 0);
+ target_list = gtk_target_list_new (NULL, 0);
+ gtk_target_list_add (target_list, copied_files_atom, 0, 0);
+ gtk_target_list_add_uri_targets (target_list, 0);
+ gtk_target_list_add_text_targets (target_list, 0);
- targets = gtk_target_table_new_from_list (target_list, &n_targets);
- gtk_target_list_unref (target_list);
+ targets = gtk_target_table_new_from_list (target_list, &n_targets);
+ gtk_target_list_unref (target_list);
- gtk_clipboard_set_with_data (nautilus_clipboard_get (GTK_WIDGET (view)),
- targets, n_targets,
- nautilus_get_clipboard_callback, nautilus_clear_clipboard_callback,
- NULL);
- gtk_target_table_free (targets, n_targets);
+ gtk_clipboard_set_with_data (nautilus_clipboard_get (GTK_WIDGET (view)),
+ targets, n_targets,
+ nautilus_get_clipboard_callback, nautilus_clear_clipboard_callback,
+ NULL);
+ gtk_target_table_free (targets, n_targets);
- nautilus_clipboard_monitor_set_clipboard_info (nautilus_clipboard_monitor_get (), &info);
+ nautilus_clipboard_monitor_set_clipboard_info (nautilus_clipboard_monitor_get (), &info);
}
static void
@@ -5386,14 +5733,14 @@ action_copy (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
+ NautilusFilesView *view;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
- copy_or_cut_files (view, selection, FALSE);
- nautilus_file_list_free (selection);
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ copy_or_cut_files (view, selection, FALSE);
+ nautilus_file_list_free (selection);
}
static void
@@ -5401,14 +5748,14 @@ action_cut (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
+ NautilusFilesView *view;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
- copy_or_cut_files (view, selection, TRUE);
- nautilus_file_list_free (selection);
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ copy_or_cut_files (view, selection, TRUE);
+ nautilus_file_list_free (selection);
}
static void
@@ -5416,30 +5763,31 @@ action_create_links_in_place (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
- GList *item_uris;
- GList *l;
- char *destination_uri;
+ NautilusFilesView *view;
+ GList *selection;
+ GList *item_uris;
+ GList *l;
+ char *destination_uri;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_files_view_get_selection_for_file_transfer (view);
+ selection = nautilus_files_view_get_selection_for_file_transfer (view);
- item_uris = NULL;
- for (l = selection; l != NULL; l = l->next) {
- item_uris = g_list_prepend (item_uris, nautilus_file_get_uri(l->data));
- }
- item_uris = g_list_reverse (item_uris);
+ item_uris = NULL;
+ for (l = selection; l != NULL; l = l->next)
+ {
+ item_uris = g_list_prepend (item_uris, nautilus_file_get_uri (l->data));
+ }
+ item_uris = g_list_reverse (item_uris);
- destination_uri = nautilus_files_view_get_backing_uri (view);
+ destination_uri = nautilus_files_view_get_backing_uri (view);
- nautilus_files_view_move_copy_items (view, item_uris, NULL, destination_uri,
- GDK_ACTION_LINK,
- 0, 0);
+ nautilus_files_view_move_copy_items (view, item_uris, NULL, destination_uri,
+ GDK_ACTION_LINK,
+ 0, 0);
- g_list_free_full (item_uris, g_free);
- nautilus_file_list_free (selection);
+ g_list_free_full (item_uris, g_free);
+ nautilus_file_list_free (selection);
}
static void
@@ -5447,10 +5795,10 @@ action_copy_to (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
- copy_or_move_selection (view, FALSE);
+ view = NAUTILUS_FILES_VIEW (user_data);
+ copy_or_move_selection (view, FALSE);
}
static void
@@ -5458,15 +5806,16 @@ action_move_to (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
- copy_or_move_selection (view, TRUE);
+ view = NAUTILUS_FILES_VIEW (user_data);
+ copy_or_move_selection (view, TRUE);
}
-typedef struct {
- NautilusFilesView *view;
- NautilusFile *target;
+typedef struct
+{
+ NautilusFilesView *view;
+ NautilusFile *target;
} PasteIntoData;
static void
@@ -5474,45 +5823,46 @@ paste_into_clipboard_received_callback (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
gpointer callback_data)
{
- PasteIntoData *data;
- NautilusFilesView *view;
- char *directory_uri;
+ PasteIntoData *data;
+ NautilusFilesView *view;
+ char *directory_uri;
- data = (PasteIntoData *) callback_data;
+ data = (PasteIntoData *) callback_data;
- view = NAUTILUS_FILES_VIEW (data->view);
+ view = NAUTILUS_FILES_VIEW (data->view);
- if (view->details->slot != NULL) {
- directory_uri = nautilus_file_get_activation_uri (data->target);
+ if (view->details->slot != NULL)
+ {
+ directory_uri = nautilus_file_get_activation_uri (data->target);
- paste_clipboard_data (view, selection_data, directory_uri);
+ paste_clipboard_data (view, selection_data, directory_uri);
- g_free (directory_uri);
- }
+ g_free (directory_uri);
+ }
- g_object_unref (view);
- nautilus_file_unref (data->target);
- g_free (data);
+ g_object_unref (view);
+ nautilus_file_unref (data->target);
+ g_free (data);
}
static void
paste_into (NautilusFilesView *view,
NautilusFile *target)
{
- PasteIntoData *data;
+ PasteIntoData *data;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
- g_assert (NAUTILUS_IS_FILE (target));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILE (target));
- data = g_new (PasteIntoData, 1);
+ data = g_new (PasteIntoData, 1);
- data->view = g_object_ref (view);
- data->target = nautilus_file_ref (target);
+ data->view = g_object_ref (view);
+ data->target = nautilus_file_ref (target);
- gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
- copied_files_atom,
- paste_into_clipboard_received_callback,
- data);
+ gtk_clipboard_request_contents (nautilus_clipboard_get (GTK_WIDGET (view)),
+ copied_files_atom,
+ paste_into_clipboard_received_callback,
+ data);
}
static void
@@ -5520,89 +5870,97 @@ action_paste_files_into (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
-
- view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- if (selection != NULL) {
- paste_into (view, NAUTILUS_FILE (selection->data));
- nautilus_file_list_free (selection);
- }
+ NautilusFilesView *view;
+ GList *selection;
+ view = NAUTILUS_FILES_VIEW (user_data);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ if (selection != NULL)
+ {
+ paste_into (view, NAUTILUS_FILE (selection->data));
+ nautilus_file_list_free (selection);
+ }
}
static void
invoke_external_bulk_rename_utility (NautilusFilesView *view,
GList *selection)
{
- GString *cmd;
- char *parameter;
- char *quoted_parameter;
- char *bulk_rename_tool;
- GList *walk;
- NautilusFile *file;
-
- /* assemble command line */
- bulk_rename_tool = get_bulk_rename_tool ();
- cmd = g_string_new (bulk_rename_tool);
- g_free (bulk_rename_tool);
- for (walk = selection; walk; walk = walk->next) {
- file = walk->data;
- parameter = nautilus_file_get_uri (file);
- quoted_parameter = g_shell_quote (parameter);
- g_free (parameter);
- cmd = g_string_append (cmd, " ");
- cmd = g_string_append (cmd, quoted_parameter);
- g_free (quoted_parameter);
- }
-
- /* spawning and error handling */
- nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (view)),
- cmd->str, FALSE, NULL);
- g_string_free (cmd, TRUE);
+ GString *cmd;
+ char *parameter;
+ char *quoted_parameter;
+ char *bulk_rename_tool;
+ GList *walk;
+ NautilusFile *file;
+
+ /* assemble command line */
+ bulk_rename_tool = get_bulk_rename_tool ();
+ cmd = g_string_new (bulk_rename_tool);
+ g_free (bulk_rename_tool);
+ for (walk = selection; walk; walk = walk->next)
+ {
+ file = walk->data;
+ parameter = nautilus_file_get_uri (file);
+ quoted_parameter = g_shell_quote (parameter);
+ g_free (parameter);
+ cmd = g_string_append (cmd, " ");
+ cmd = g_string_append (cmd, quoted_parameter);
+ g_free (quoted_parameter);
+ }
+
+ /* spawning and error handling */
+ nautilus_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (view)),
+ cmd->str, FALSE, NULL);
+ g_string_free (cmd, TRUE);
}
static void
real_action_rename (NautilusFilesView *view)
{
- NautilusFile *file;
- GList *selection;
- GtkWidget *dialog;
+ NautilusFile *file;
+ GList *selection;
+ GtkWidget *dialog;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- if (selection_not_empty_in_menu_callback (view, selection)) {
- /* If there is more than one file selected, invoke a batch renamer */
- if (selection->next != NULL) {
- if (have_bulk_rename_tool ()) {
- invoke_external_bulk_rename_utility (view, selection);
- } else {
- GdkCursor *cursor;
- GdkDisplay *display;
-
- display = gtk_widget_get_display (GTK_WIDGET (nautilus_files_view_get_window (view)));
- cursor = gdk_cursor_new_from_name (display, "progress");
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (nautilus_files_view_get_window (view))),
- cursor);
- g_object_unref (cursor);
-
- dialog = nautilus_batch_rename_dialog_new (nautilus_files_view_get_selection (NAUTILUS_VIEW (view)),
- nautilus_files_view_get_model (view),
- nautilus_files_view_get_window (view));
-
- gtk_widget_show (GTK_WIDGET (dialog));
- }
- } else {
- file = NAUTILUS_FILE (selection->data);
-
- nautilus_files_view_rename_file_popover_new (view, file);
- }
+ if (selection_not_empty_in_menu_callback (view, selection))
+ {
+ /* If there is more than one file selected, invoke a batch renamer */
+ if (selection->next != NULL)
+ {
+ if (have_bulk_rename_tool ())
+ {
+ invoke_external_bulk_rename_utility (view, selection);
+ }
+ else
+ {
+ GdkCursor *cursor;
+ GdkDisplay *display;
+
+ display = gtk_widget_get_display (GTK_WIDGET (nautilus_files_view_get_window (view)));
+ cursor = gdk_cursor_new_from_name (display, "progress");
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (nautilus_files_view_get_window (view))),
+ cursor);
+ g_object_unref (cursor);
+
+ dialog = nautilus_batch_rename_dialog_new (nautilus_files_view_get_selection (NAUTILUS_VIEW (view)),
+ nautilus_files_view_get_model (view),
+ nautilus_files_view_get_window (view));
+
+ gtk_widget_show (GTK_WIDGET (dialog));
+ }
}
+ else
+ {
+ file = NAUTILUS_FILE (selection->data);
- nautilus_file_list_free (selection);
+ nautilus_files_view_rename_file_popover_new (view, file);
+ }
+ }
+
+ nautilus_file_list_free (selection);
}
static void
@@ -5610,76 +5968,86 @@ action_rename (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- real_action_rename (NAUTILUS_FILES_VIEW (user_data));
+ real_action_rename (NAUTILUS_FILES_VIEW (user_data));
}
-typedef struct {
- NautilusFilesView *view;
- GHashTable *added_locations;
+typedef struct
+{
+ NautilusFilesView *view;
+ GHashTable *added_locations;
} ExtractData;
static void
extract_done (GList *outputs,
gpointer user_data)
{
- ExtractData *data;
- GList *l;
- gboolean all_files_acknowledged;
+ ExtractData *data;
+ GList *l;
+ gboolean all_files_acknowledged;
- data = user_data;
+ data = user_data;
- if (data->view == NULL) {
- goto out;
- }
+ if (data->view == NULL)
+ {
+ goto out;
+ }
- g_signal_handlers_disconnect_by_func (data->view,
- G_CALLBACK (track_newly_added_locations),
- data->added_locations);
+ g_signal_handlers_disconnect_by_func (data->view,
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations);
- if (outputs == NULL) {
- goto out;
- }
+ if (outputs == NULL)
+ {
+ goto out;
+ }
- all_files_acknowledged = TRUE;
- for (l = outputs; l && all_files_acknowledged; l = l->next) {
- all_files_acknowledged = g_hash_table_contains (data->added_locations,
- l->data);
- }
+ all_files_acknowledged = TRUE;
+ for (l = outputs; l && all_files_acknowledged; l = l->next)
+ {
+ all_files_acknowledged = g_hash_table_contains (data->added_locations,
+ l->data);
+ }
- if (all_files_acknowledged) {
- GList *selection = NULL;
+ if (all_files_acknowledged)
+ {
+ GList *selection = NULL;
- for (l = outputs; l != NULL; l = l->next) {
- selection = g_list_prepend (selection,
- nautilus_file_get (l->data));
- }
+ for (l = outputs; l != NULL; l = l->next)
+ {
+ selection = g_list_prepend (selection,
+ nautilus_file_get (l->data));
+ }
- nautilus_files_view_set_selection (NAUTILUS_VIEW (data->view),
- selection);
- nautilus_files_view_reveal_selection (data->view);
+ nautilus_files_view_set_selection (NAUTILUS_VIEW (data->view),
+ selection);
+ nautilus_files_view_reveal_selection (data->view);
- nautilus_file_list_free (selection);
- } else {
- for (l = outputs; l != NULL; l = l->next) {
- gboolean acknowledged;
+ nautilus_file_list_free (selection);
+ }
+ else
+ {
+ for (l = outputs; l != NULL; l = l->next)
+ {
+ gboolean acknowledged;
- acknowledged = g_hash_table_contains (data->added_locations,
- l->data);
+ acknowledged = g_hash_table_contains (data->added_locations,
+ l->data);
- g_hash_table_insert (data->view->details->pending_reveal,
- nautilus_file_get (l->data),
- GUINT_TO_POINTER (acknowledged));
- }
+ g_hash_table_insert (data->view->details->pending_reveal,
+ nautilus_file_get (l->data),
+ GUINT_TO_POINTER (acknowledged));
}
+ }
out:
- g_hash_table_destroy (data->added_locations);
+ g_hash_table_destroy (data->added_locations);
- if (data->view != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
- }
+ if (data->view != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (data->view),
+ (gpointer *) &data->view);
+ }
- g_free (data);
+ g_free (data);
}
static void
@@ -5687,63 +6055,69 @@ extract_files (NautilusFilesView *view,
GList *files,
GFile *destination_directory)
{
- GList *locations = NULL;
- GList *l;
- gboolean extracting_to_current_directory;
+ GList *locations = NULL;
+ GList *l;
+ gboolean extracting_to_current_directory;
- if (files == NULL) {
- return;
- }
+ if (files == NULL)
+ {
+ return;
+ }
- for (l = files; l != NULL; l = l->next) {
- locations = g_list_prepend (locations,
- nautilus_file_get_location (l->data));
- }
+ for (l = files; l != NULL; l = l->next)
+ {
+ locations = g_list_prepend (locations,
+ nautilus_file_get_location (l->data));
+ }
- locations = g_list_reverse (locations);
-
- extracting_to_current_directory = g_file_equal (destination_directory,
- nautilus_view_get_location (NAUTILUS_VIEW (view)));
-
- if (extracting_to_current_directory) {
- ExtractData *data;
-
- data = g_new (ExtractData, 1);
- data->view = view;
- data->added_locations = g_hash_table_new_full (g_file_hash,
- (GEqualFunc)g_file_equal,
- g_object_unref, NULL);
-
-
- g_object_add_weak_pointer (G_OBJECT (data->view),
- (gpointer *) &data->view);
-
- g_signal_connect_data (view,
- "add-file",
- G_CALLBACK (track_newly_added_locations),
- data->added_locations,
- NULL,
- G_CONNECT_AFTER);
-
- nautilus_file_operations_extract_files (locations,
- destination_directory,
- nautilus_files_view_get_containing_window (view),
- extract_done,
- data);
- } else {
- nautilus_file_operations_extract_files (locations,
- destination_directory,
- nautilus_files_view_get_containing_window (view),
- NULL,
- NULL);
- }
+ locations = g_list_reverse (locations);
+
+ extracting_to_current_directory = g_file_equal (destination_directory,
+ nautilus_view_get_location (NAUTILUS_VIEW (view)));
+
+ if (extracting_to_current_directory)
+ {
+ ExtractData *data;
+
+ data = g_new (ExtractData, 1);
+ data->view = view;
+ data->added_locations = g_hash_table_new_full (g_file_hash,
+ (GEqualFunc) g_file_equal,
+ g_object_unref, NULL);
- g_list_free_full (locations, g_object_unref);
+
+ g_object_add_weak_pointer (G_OBJECT (data->view),
+ (gpointer *) &data->view);
+
+ g_signal_connect_data (view,
+ "add-file",
+ G_CALLBACK (track_newly_added_locations),
+ data->added_locations,
+ NULL,
+ G_CONNECT_AFTER);
+
+ nautilus_file_operations_extract_files (locations,
+ destination_directory,
+ nautilus_files_view_get_containing_window (view),
+ extract_done,
+ data);
+ }
+ else
+ {
+ nautilus_file_operations_extract_files (locations,
+ destination_directory,
+ nautilus_files_view_get_containing_window (view),
+ NULL,
+ NULL);
+ }
+
+ g_list_free_full (locations, g_object_unref);
}
-typedef struct {
- NautilusFilesView *view;
- GList *files;
+typedef struct
+{
+ NautilusFilesView *view;
+ GList *files;
} ExtractToData;
static void
@@ -5751,62 +6125,64 @@ on_extract_destination_dialog_response (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- ExtractToData *data;
+ ExtractToData *data;
- data = user_data;
+ data = user_data;
- if (response_id == GTK_RESPONSE_OK) {
- g_autoptr (GFile) destination_directory;
+ if (response_id == GTK_RESPONSE_OK)
+ {
+ g_autoptr (GFile) destination_directory;
- destination_directory = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ destination_directory = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
- extract_files (data->view, data->files, destination_directory);
- }
+ extract_files (data->view, data->files, destination_directory);
+ }
- gtk_widget_destroy (GTK_WIDGET (dialog));
- nautilus_file_list_free (data->files);
- g_free (data);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ nautilus_file_list_free (data->files);
+ g_free (data);
}
static void
extract_files_to_chosen_location (NautilusFilesView *view,
GList *files)
{
- ExtractToData *data;
- GtkWidget *dialog;
- g_autofree char *uri = NULL;
+ ExtractToData *data;
+ GtkWidget *dialog;
+ g_autofree char *uri = NULL;
- if (files == NULL) {
- return;
- }
+ if (files == NULL)
+ {
+ return;
+ }
- data = g_new (ExtractToData, 1);
+ data = g_new (ExtractToData, 1);
- dialog = gtk_file_chooser_dialog_new (_("Select Extract Destination"),
- GTK_WINDOW (nautilus_files_view_get_window (view)),
- GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_Select"), GTK_RESPONSE_OK,
- NULL);
- gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
+ dialog = gtk_file_chooser_dialog_new (_("Select Extract Destination"),
+ GTK_WINDOW (nautilus_files_view_get_window (view)),
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Select"), GTK_RESPONSE_OK,
+ NULL);
+ gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), FALSE);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- GTK_RESPONSE_OK);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog),
+ GTK_RESPONSE_OK);
- gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
- uri = nautilus_directory_get_uri (view->details->model);
- gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
+ uri = nautilus_directory_get_uri (view->details->model);
+ gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (dialog), uri);
- data->view = view;
- data->files = nautilus_file_list_copy (files);
+ data->view = view;
+ data->files = nautilus_file_list_copy (files);
- g_signal_connect (dialog, "response",
- G_CALLBACK (on_extract_destination_dialog_response),
- data);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (on_extract_destination_dialog_response),
+ data);
- gtk_widget_show_all (dialog);
+ gtk_widget_show_all (dialog);
}
static void
@@ -5814,17 +6190,17 @@ action_extract_here (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
+ NautilusFilesView *view;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- extract_files (view, selection,
- nautilus_view_get_location (NAUTILUS_VIEW (view)));
+ extract_files (view, selection,
+ nautilus_view_get_location (NAUTILUS_VIEW (view)));
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static void
@@ -5832,16 +6208,16 @@ action_extract_to (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view;
- GList *selection;
+ NautilusFilesView *view;
+ GList *selection;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- extract_files_to_chosen_location (view, selection);
+ extract_files_to_chosen_location (view, selection);
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static void
@@ -5849,9 +6225,9 @@ action_compress (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFilesView *view = user_data;
+ NautilusFilesView *view = user_data;
- nautilus_files_view_compress_dialog_new (view);
+ nautilus_files_view_compress_dialog_new (view);
}
@@ -5864,23 +6240,25 @@ action_compress (GSimpleAction *action,
static void
set_uri_as_wallpaper (const char *uri)
{
- GSettings *settings;
+ GSettings *settings;
- settings = gnome_background_preferences;
+ settings = gnome_background_preferences;
- g_settings_delay (settings);
+ g_settings_delay (settings);
- if (uri == NULL)
- uri = "";
+ if (uri == NULL)
+ {
+ uri = "";
+ }
- 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);
+ 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);
+ /* Apply changes atomically. */
+ g_settings_apply (settings);
}
static void
@@ -5888,36 +6266,39 @@ wallpaper_copy_done_callback (GHashTable *debuting_files,
gboolean success,
gpointer data)
{
- GHashTableIter iter;
- gpointer key, value;
+ 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;
- }
+ 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;
+ NautilusFile *file;
- if (g_list_length (selection) != 1) {
- return FALSE;
- }
+ if (g_list_length (selection) != 1)
+ {
+ return FALSE;
+ }
- file = NAUTILUS_FILE (selection->data);
- if (!nautilus_file_is_mime_type (file, "image/*")) {
- return FALSE;
- }
+ file = NAUTILUS_FILE (selection->data);
+ if (!nautilus_file_is_mime_type (file, "image/*"))
+ {
+ return FALSE;
+ }
- /* FIXME: check file size? */
+ /* FIXME: check file size? */
- return TRUE;
+ return TRUE;
}
static void
@@ -5925,44 +6306,45 @@ action_set_as_wallpaper (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- GList *selection;
-
- /* Copy the item to Pictures/Wallpaper since it may be
- remote. Then set it as the current wallpaper. */
-
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
-
- selection = nautilus_view_get_selection (user_data);
-
- if (can_set_wallpaper (selection)
- && selection_not_empty_in_menu_callback (user_data, 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 (user_data),
- wallpaper_copy_done_callback,
- NULL);
- g_free (target_uri);
- g_list_free_full (uris, g_free);
- }
+ GList *selection;
- nautilus_file_list_free (selection);
+ /* Copy the item to Pictures/Wallpaper since it may be
+ * remote. Then set it as the current wallpaper. */
+
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+
+ selection = nautilus_view_get_selection (user_data);
+
+ if (can_set_wallpaper (selection)
+ && selection_not_empty_in_menu_callback (user_data, 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 (user_data),
+ wallpaper_copy_done_callback,
+ NULL);
+ g_free (target_uri);
+ g_list_free_full (uris, g_free);
+ }
+
+ nautilus_file_list_free (selection);
}
static void
@@ -5971,25 +6353,26 @@ file_mount_callback (NautilusFile *file,
GError *error,
gpointer callback_data)
{
- NautilusFilesView *view;
-
- view = NAUTILUS_FILES_VIEW (callback_data);
-
- if (error != NULL &&
- (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED &&
- error->code != G_IO_ERROR_ALREADY_MOUNTED))) {
- char *text;
- char *name;
- name = nautilus_file_get_display_name (file);
- /* Translators: %s is a file name formatted for display */
- text = g_strdup_printf (_("Unable to access “%s”"), name);
- eel_show_error_dialog (text, error->message,
- GTK_WINDOW (nautilus_files_view_get_window (view)));
- g_free (text);
- g_free (name);
- }
+ NautilusFilesView *view;
+
+ view = NAUTILUS_FILES_VIEW (callback_data);
+
+ if (error != NULL &&
+ (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED &&
+ error->code != G_IO_ERROR_ALREADY_MOUNTED)))
+ {
+ char *text;
+ char *name;
+ name = nautilus_file_get_display_name (file);
+ /* Translators: %s is a file name formatted for display */
+ text = g_strdup_printf (_("Unable to access “%s”"), name);
+ eel_show_error_dialog (text, error->message,
+ GTK_WINDOW (nautilus_files_view_get_window (view)));
+ g_free (text);
+ g_free (name);
+ }
}
static void
@@ -5998,25 +6381,26 @@ file_unmount_callback (NautilusFile *file,
GError *error,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
- g_object_unref (view);
+ view = NAUTILUS_FILES_VIEW (callback_data);
+ g_object_unref (view);
- if (error != NULL &&
- (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED))) {
- char *text;
- char *name;
- name = nautilus_file_get_display_name (file);
- /* Translators: %s is a file name formatted for display */
- text = g_strdup_printf (_("Unable to remove “%s”"), name);
- eel_show_error_dialog (text, error->message,
- GTK_WINDOW (nautilus_files_view_get_window (view)));
- g_free (text);
- g_free (name);
- }
+ if (error != NULL &&
+ (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED)))
+ {
+ char *text;
+ char *name;
+ name = nautilus_file_get_display_name (file);
+ /* Translators: %s is a file name formatted for display */
+ text = g_strdup_printf (_("Unable to remove “%s”"), name);
+ eel_show_error_dialog (text, error->message,
+ GTK_WINDOW (nautilus_files_view_get_window (view)));
+ g_free (text);
+ g_free (name);
+ }
}
static void
@@ -6025,25 +6409,26 @@ file_eject_callback (NautilusFile *file,
GError *error,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
- g_object_unref (view);
+ view = NAUTILUS_FILES_VIEW (callback_data);
+ g_object_unref (view);
- if (error != NULL &&
- (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED))) {
- char *text;
- char *name;
- name = nautilus_file_get_display_name (file);
- /* Translators: %s is a file name formatted for display */
- text = g_strdup_printf (_("Unable to eject “%s”"), name);
- eel_show_error_dialog (text, error->message,
- GTK_WINDOW (nautilus_files_view_get_window (view)));
- g_free (text);
- g_free (name);
- }
+ if (error != NULL &&
+ (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED)))
+ {
+ char *text;
+ char *name;
+ name = nautilus_file_get_display_name (file);
+ /* Translators: %s is a file name formatted for display */
+ text = g_strdup_printf (_("Unable to eject “%s”"), name);
+ eel_show_error_dialog (text, error->message,
+ GTK_WINDOW (nautilus_files_view_get_window (view)));
+ g_free (text);
+ g_free (name);
+ }
}
static void
@@ -6052,18 +6437,19 @@ file_stop_callback (NautilusFile *file,
GError *error,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (callback_data);
+ view = NAUTILUS_FILES_VIEW (callback_data);
- if (error != NULL &&
- (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED))) {
- eel_show_error_dialog (_("Unable to stop drive"),
- error->message,
- GTK_WINDOW (nautilus_files_view_get_window (view)));
- }
+ if (error != NULL &&
+ (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED)))
+ {
+ eel_show_error_dialog (_("Unable to stop drive"),
+ error->message,
+ GTK_WINDOW (nautilus_files_view_get_window (view)));
+ }
}
static void
@@ -6071,27 +6457,29 @@ action_mount_volume (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFile *file;
- GList *selection, *l;
- NautilusFilesView *view;
- GMountOperation *mount_op;
+ NautilusFile *file;
+ GList *selection, *l;
+ NautilusFilesView *view;
+ GMountOperation *mount_op;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_can_mount (file)) {
- mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
- g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
- nautilus_file_mount (file, mount_op, NULL,
- file_mount_callback,
- view);
- g_object_unref (mount_op);
- }
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_can_mount (file))
+ {
+ mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
+ g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
+ nautilus_file_mount (file, mount_op, NULL,
+ file_mount_callback,
+ view);
+ g_object_unref (mount_op);
}
- nautilus_file_list_free (selection);
+ }
+ nautilus_file_list_free (selection);
}
static void
@@ -6099,25 +6487,27 @@ action_unmount_volume (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFile *file;
- GList *selection, *l;
- NautilusFilesView *view;
+ NautilusFile *file;
+ GList *selection, *l;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- if (nautilus_file_can_unmount (file)) {
- GMountOperation *mount_op;
- mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
- nautilus_file_unmount (file, mount_op, NULL,
- file_unmount_callback, g_object_ref (view));
- g_object_unref (mount_op);
- }
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ if (nautilus_file_can_unmount (file))
+ {
+ GMountOperation *mount_op;
+ mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
+ nautilus_file_unmount (file, mount_op, NULL,
+ file_unmount_callback, g_object_ref (view));
+ g_object_unref (mount_op);
}
- nautilus_file_list_free (selection);
+ }
+ nautilus_file_list_free (selection);
}
static void
@@ -6125,25 +6515,27 @@ action_eject_volume (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFile *file;
- GList *selection, *l;
- NautilusFilesView *view;
+ NautilusFile *file;
+ GList *selection, *l;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_can_eject (file)) {
- GMountOperation *mount_op;
- mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
- nautilus_file_eject (file, mount_op, NULL,
- file_eject_callback, g_object_ref (view));
- g_object_unref (mount_op);
- }
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_can_eject (file))
+ {
+ GMountOperation *mount_op;
+ mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
+ nautilus_file_eject (file, mount_op, NULL,
+ file_eject_callback, g_object_ref (view));
+ g_object_unref (mount_op);
}
- nautilus_file_list_free (selection);
+ }
+ nautilus_file_list_free (selection);
}
static void
@@ -6152,25 +6544,26 @@ file_start_callback (NautilusFile *file,
GError *error,
gpointer callback_data)
{
- NautilusFilesView *view;
-
- view = NAUTILUS_FILES_VIEW (callback_data);
-
- if (error != NULL &&
- (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED &&
- error->code != G_IO_ERROR_ALREADY_MOUNTED))) {
- char *text;
- char *name;
- name = nautilus_file_get_display_name (file);
- /* Translators: %s is a file name formatted for display */
- text = g_strdup_printf (_("Unable to start “%s”"), name);
- eel_show_error_dialog (text, error->message,
- GTK_WINDOW (nautilus_files_view_get_window (view)));
- g_free (text);
- g_free (name);
- }
+ NautilusFilesView *view;
+
+ view = NAUTILUS_FILES_VIEW (callback_data);
+
+ if (error != NULL &&
+ (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED &&
+ error->code != G_IO_ERROR_ALREADY_MOUNTED)))
+ {
+ char *text;
+ char *name;
+ name = nautilus_file_get_display_name (file);
+ /* Translators: %s is a file name formatted for display */
+ text = g_strdup_printf (_("Unable to start “%s”"), name);
+ eel_show_error_dialog (text, error->message,
+ GTK_WINDOW (nautilus_files_view_get_window (view)));
+ g_free (text);
+ g_free (name);
+ }
}
static void
@@ -6178,25 +6571,27 @@ action_start_volume (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFile *file;
- GList *selection, *l;
- NautilusFilesView *view;
- GMountOperation *mount_op;
+ NautilusFile *file;
+ GList *selection, *l;
+ NautilusFilesView *view;
+ GMountOperation *mount_op;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_can_start (file) || nautilus_file_can_start_degraded (file)) {
- mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
- nautilus_file_start (file, mount_op, NULL,
- file_start_callback, view);
- g_object_unref (mount_op);
- }
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_can_start (file) || nautilus_file_can_start_degraded (file))
+ {
+ mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
+ nautilus_file_start (file, mount_op, NULL,
+ file_start_callback, view);
+ g_object_unref (mount_op);
}
- nautilus_file_list_free (selection);
+ }
+ nautilus_file_list_free (selection);
}
static void
@@ -6204,25 +6599,27 @@ action_stop_volume (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFile *file;
- GList *selection, *l;
- NautilusFilesView *view;
+ NautilusFile *file;
+ GList *selection, *l;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_can_stop (file)) {
- GMountOperation *mount_op;
- mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
- nautilus_file_stop (file, mount_op, NULL,
- file_stop_callback, view);
- g_object_unref (mount_op);
- }
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_can_stop (file))
+ {
+ GMountOperation *mount_op;
+ mount_op = gtk_mount_operation_new (nautilus_files_view_get_containing_window (view));
+ nautilus_file_stop (file, mount_op, NULL,
+ file_stop_callback, view);
+ g_object_unref (mount_op);
}
- nautilus_file_list_free (selection);
+ }
+ nautilus_file_list_free (selection);
}
static void
@@ -6230,115 +6627,120 @@ action_detect_media (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusFile *file;
- GList *selection, *l;
- NautilusView *view;
-
- view = NAUTILUS_VIEW (user_data);
-
- selection = nautilus_view_get_selection (view);
- for (l = selection; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_can_poll_for_media (file) && !nautilus_file_is_media_check_automatic (file)) {
- nautilus_file_poll_for_media (file);
- }
- }
- nautilus_file_list_free (selection);
-}
-
-const GActionEntry view_entries[] = {
- /* Toolbar menu */
- { "zoom-in", action_zoom_in },
- { "zoom-out", action_zoom_out },
- { "zoom-standard", action_zoom_standard },
- { "show-hidden-files", NULL, NULL, "true", action_show_hidden_files },
- /* Background menu */
- { "new-folder", action_new_folder },
- { "select-all", action_select_all },
- { "paste", action_paste_files },
- { "create-link", action_create_links },
- { "new-document" },
- /* Selection menu */
- { "scripts" },
- { "new-folder-with-selection", action_new_folder_with_selection },
- { "open-scripts-folder", action_open_scripts_folder },
- { "open-item-location", action_open_item_location },
- { "open-with-default-application", action_open_with_default_application },
- { "open-with-other-application", action_open_with_other_application },
- { "open-item-new-window", action_open_item_new_window },
- { "open-item-new-tab", action_open_item_new_tab },
- { "cut", action_cut},
- { "copy", action_copy},
- { "create-link-in-place", action_create_links_in_place },
- { "move-to", action_move_to},
- { "copy-to", action_copy_to},
- { "move-to-trash", action_move_to_trash},
- { "delete-from-trash", action_delete },
- /* We separate the shortcut and the menu item since we want the shortcut
- * to always be available, but we don't want the menu item shown if not
- * completely necesary. Since the visibility of the menu item is based on
- * the action enability, we need to split the actions for the menu and the
- * shortcut. */
- { "delete-permanently-shortcut", action_delete },
- { "delete-permanently-menu-item", action_delete },
- /* This is only shown when the setting to show always delete permanently
- * is set and when the common use cases for delete permanently which uses
- * Delete as a shortcut are not needed. For instance this will be only
- * present when the setting is true and when it can trash files */
- { "permanent-delete-permanently-menu-item", action_delete },
- { "remove-from-recent", action_remove_from_recent },
- { "restore-from-trash", action_restore_from_trash},
- { "paste-into", action_paste_files_into },
- { "rename", action_rename},
- { "extract-here", action_extract_here },
- { "extract-to", action_extract_to },
- { "compress", action_compress },
- { "properties", action_properties},
- { "set-as-wallpaper", action_set_as_wallpaper },
- { "mount-volume", action_mount_volume },
- { "unmount-volume", action_unmount_volume },
- { "eject-volume", action_eject_volume },
- { "start-volume", action_start_volume },
- { "stop-volume", action_stop_volume },
- { "detect-media", action_detect_media },
- /* Only accesible by shorcuts */
- { "select-pattern", action_select_pattern },
- { "invert-selection", action_invert_selection },
- { "open-file-and-close-window", action_open_file_and_close_window },
- /* Warning dialog for the change of the shorcut to move to trash */
- { "show-move-to-trash-shortcut-changed-dialog", action_show_move_to_trash_shortcut_changed_dialog }
+ NautilusFile *file;
+ GList *selection, *l;
+ NautilusView *view;
+
+ view = NAUTILUS_VIEW (user_data);
+
+ selection = nautilus_view_get_selection (view);
+ for (l = selection; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_can_poll_for_media (file) && !nautilus_file_is_media_check_automatic (file))
+ {
+ nautilus_file_poll_for_media (file);
+ }
+ }
+ nautilus_file_list_free (selection);
+}
+
+const GActionEntry view_entries[] =
+{
+ /* Toolbar menu */
+ { "zoom-in", action_zoom_in },
+ { "zoom-out", action_zoom_out },
+ { "zoom-standard", action_zoom_standard },
+ { "show-hidden-files", NULL, NULL, "true", action_show_hidden_files },
+ /* Background menu */
+ { "new-folder", action_new_folder },
+ { "select-all", action_select_all },
+ { "paste", action_paste_files },
+ { "create-link", action_create_links },
+ { "new-document" },
+ /* Selection menu */
+ { "scripts" },
+ { "new-folder-with-selection", action_new_folder_with_selection },
+ { "open-scripts-folder", action_open_scripts_folder },
+ { "open-item-location", action_open_item_location },
+ { "open-with-default-application", action_open_with_default_application },
+ { "open-with-other-application", action_open_with_other_application },
+ { "open-item-new-window", action_open_item_new_window },
+ { "open-item-new-tab", action_open_item_new_tab },
+ { "cut", action_cut},
+ { "copy", action_copy},
+ { "create-link-in-place", action_create_links_in_place },
+ { "move-to", action_move_to},
+ { "copy-to", action_copy_to},
+ { "move-to-trash", action_move_to_trash},
+ { "delete-from-trash", action_delete },
+ /* We separate the shortcut and the menu item since we want the shortcut
+ * to always be available, but we don't want the menu item shown if not
+ * completely necesary. Since the visibility of the menu item is based on
+ * the action enability, we need to split the actions for the menu and the
+ * shortcut. */
+ { "delete-permanently-shortcut", action_delete },
+ { "delete-permanently-menu-item", action_delete },
+ /* This is only shown when the setting to show always delete permanently
+ * is set and when the common use cases for delete permanently which uses
+ * Delete as a shortcut are not needed. For instance this will be only
+ * present when the setting is true and when it can trash files */
+ { "permanent-delete-permanently-menu-item", action_delete },
+ { "remove-from-recent", action_remove_from_recent },
+ { "restore-from-trash", action_restore_from_trash},
+ { "paste-into", action_paste_files_into },
+ { "rename", action_rename},
+ { "extract-here", action_extract_here },
+ { "extract-to", action_extract_to },
+ { "compress", action_compress },
+ { "properties", action_properties},
+ { "set-as-wallpaper", action_set_as_wallpaper },
+ { "mount-volume", action_mount_volume },
+ { "unmount-volume", action_unmount_volume },
+ { "eject-volume", action_eject_volume },
+ { "start-volume", action_start_volume },
+ { "stop-volume", action_stop_volume },
+ { "detect-media", action_detect_media },
+ /* Only accesible by shorcuts */
+ { "select-pattern", action_select_pattern },
+ { "invert-selection", action_invert_selection },
+ { "open-file-and-close-window", action_open_file_and_close_window },
+ /* Warning dialog for the change of the shorcut to move to trash */
+ { "show-move-to-trash-shortcut-changed-dialog", action_show_move_to_trash_shortcut_changed_dialog }
};
static gboolean
can_paste_into_file (NautilusFile *file)
{
- if (nautilus_file_is_directory (file) &&
- nautilus_file_can_write (file)) {
- return TRUE;
- }
- if (nautilus_file_has_activation_uri (file)) {
- GFile *location;
- NautilusFile *activation_file;
- gboolean res;
+ if (nautilus_file_is_directory (file) &&
+ nautilus_file_can_write (file))
+ {
+ return TRUE;
+ }
+ if (nautilus_file_has_activation_uri (file))
+ {
+ GFile *location;
+ NautilusFile *activation_file;
+ gboolean res;
- location = nautilus_file_get_activation_location (file);
- activation_file = nautilus_file_get (location);
- g_object_unref (location);
+ location = nautilus_file_get_activation_location (file);
+ activation_file = nautilus_file_get (location);
+ g_object_unref (location);
- /* The target location might not have data for it read yet,
- and we can't want to do sync I/O, so treat the unknown
- case as can-write */
- res = (nautilus_file_get_file_type (activation_file) == G_FILE_TYPE_UNKNOWN) ||
- (nautilus_file_get_file_type (activation_file) == G_FILE_TYPE_DIRECTORY &&
- nautilus_file_can_write (activation_file));
+ /* The target location might not have data for it read yet,
+ * and we can't want to do sync I/O, so treat the unknown
+ * case as can-write */
+ res = (nautilus_file_get_file_type (activation_file) == G_FILE_TYPE_UNKNOWN) ||
+ (nautilus_file_get_file_type (activation_file) == G_FILE_TYPE_DIRECTORY &&
+ nautilus_file_can_write (activation_file));
- nautilus_file_unref (activation_file);
+ nautilus_file_unref (activation_file);
- return res;
- }
+ return res;
+ }
- return FALSE;
+ return FALSE;
}
static void
@@ -6347,49 +6749,53 @@ clipboard_targets_received (GtkClipboard *clipboard,
int n_targets,
gpointer user_data)
{
- NautilusFilesView *view;
- gboolean is_data_copied;
- int i;
- GAction *action;
-
- view = NAUTILUS_FILES_VIEW (user_data);
- is_data_copied = FALSE;
+ NautilusFilesView *view;
+ gboolean is_data_copied;
+ int i;
+ GAction *action;
- if (view->details->slot == NULL ||
- !view->details->active) {
- /* We've been destroyed or became inactive since call */
- g_object_unref (view);
- return;
- }
+ view = NAUTILUS_FILES_VIEW (user_data);
+ is_data_copied = FALSE;
- if (targets) {
- for (i = 0; i < n_targets; i++) {
- if (targets[i] == copied_files_atom) {
- is_data_copied = TRUE;
- }
- }
+ if (view->details->slot == NULL ||
+ !view->details->active)
+ {
+ /* We've been destroyed or became inactive since call */
+ g_object_unref (view);
+ return;
+ }
+
+ if (targets)
+ {
+ for (i = 0; i < n_targets; i++)
+ {
+ if (targets[i] == copied_files_atom)
+ {
+ is_data_copied = TRUE;
+ }
}
+ }
- action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
- "paste");
- /* Take into account if the action was previously disabled for other reasons,
- * like the directory not being writabble */
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- is_data_copied && g_action_get_enabled (action));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
+ "paste");
+ /* Take into account if the action was previously disabled for other reasons,
+ * like the directory not being writabble */
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ is_data_copied && g_action_get_enabled (action));
- action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
- "paste-into");
+ action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
+ "paste-into");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- is_data_copied && g_action_get_enabled (action));
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ is_data_copied && g_action_get_enabled (action));
- action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
- "create-link");
+ action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
+ "create-link");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- is_data_copied && g_action_get_enabled (action));
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ is_data_copied && g_action_get_enabled (action));
- g_object_unref (view);
+ g_object_unref (view);
}
static void
@@ -6402,512 +6808,544 @@ file_should_show_foreach (NautilusFile *file,
gboolean *show_poll,
GDriveStartStopType *start_stop_type)
{
- *show_mount = FALSE;
- *show_unmount = FALSE;
- *show_eject = FALSE;
- *show_start = FALSE;
- *show_stop = FALSE;
- *show_poll = FALSE;
+ *show_mount = FALSE;
+ *show_unmount = FALSE;
+ *show_eject = FALSE;
+ *show_start = FALSE;
+ *show_stop = FALSE;
+ *show_poll = FALSE;
- if (nautilus_file_can_eject (file)) {
- *show_eject = TRUE;
- }
+ if (nautilus_file_can_eject (file))
+ {
+ *show_eject = TRUE;
+ }
- if (nautilus_file_can_mount (file)) {
- *show_mount = TRUE;
- }
+ if (nautilus_file_can_mount (file))
+ {
+ *show_mount = TRUE;
+ }
- if (nautilus_file_can_start (file) || nautilus_file_can_start_degraded (file)) {
- *show_start = TRUE;
- }
+ if (nautilus_file_can_start (file) || nautilus_file_can_start_degraded (file))
+ {
+ *show_start = TRUE;
+ }
- if (nautilus_file_can_stop (file)) {
- *show_stop = TRUE;
- }
+ if (nautilus_file_can_stop (file))
+ {
+ *show_stop = TRUE;
+ }
- /* Dot not show both Unmount and Eject/Safe Removal; too confusing to
- * have too many menu entries */
- if (nautilus_file_can_unmount (file) && !*show_eject && !*show_stop) {
- *show_unmount = TRUE;
- }
+ /* Dot not show both Unmount and Eject/Safe Removal; too confusing to
+ * have too many menu entries */
+ if (nautilus_file_can_unmount (file) && !*show_eject && !*show_stop)
+ {
+ *show_unmount = TRUE;
+ }
- if (nautilus_file_can_poll_for_media (file) && !nautilus_file_is_media_check_automatic (file)) {
- *show_poll = TRUE;
- }
+ if (nautilus_file_can_poll_for_media (file) && !nautilus_file_is_media_check_automatic (file))
+ {
+ *show_poll = TRUE;
+ }
- *start_stop_type = nautilus_file_get_start_stop_type (file);
+ *start_stop_type = nautilus_file_get_start_stop_type (file);
}
static gboolean
can_restore_from_trash (GList *files)
{
- NautilusFile *original_file;
- NautilusFile *original_dir;
- GHashTable *original_dirs_hash;
- GList *original_dirs;
- gboolean can_restore;
-
- original_file = NULL;
- original_dir = NULL;
- original_dirs = NULL;
- original_dirs_hash = NULL;
-
- if (files != NULL) {
- if (g_list_length (files) == 1) {
- original_file = nautilus_file_get_trash_original_file (files->data);
- } else {
- original_dirs_hash = nautilus_trashed_files_get_original_directories (files, NULL);
- if (original_dirs_hash != NULL) {
- original_dirs = g_hash_table_get_keys (original_dirs_hash);
- if (g_list_length (original_dirs) == 1) {
- original_dir = nautilus_file_ref (NAUTILUS_FILE (original_dirs->data));
- }
- }
+ NautilusFile *original_file;
+ NautilusFile *original_dir;
+ GHashTable *original_dirs_hash;
+ GList *original_dirs;
+ gboolean can_restore;
+
+ original_file = NULL;
+ original_dir = NULL;
+ original_dirs = NULL;
+ original_dirs_hash = NULL;
+
+ if (files != NULL)
+ {
+ if (g_list_length (files) == 1)
+ {
+ original_file = nautilus_file_get_trash_original_file (files->data);
+ }
+ else
+ {
+ original_dirs_hash = nautilus_trashed_files_get_original_directories (files, NULL);
+ if (original_dirs_hash != NULL)
+ {
+ original_dirs = g_hash_table_get_keys (original_dirs_hash);
+ if (g_list_length (original_dirs) == 1)
+ {
+ original_dir = nautilus_file_ref (NAUTILUS_FILE (original_dirs->data));
}
+ }
}
+ }
- can_restore = original_file != NULL || original_dirs != NULL;
+ can_restore = original_file != NULL || original_dirs != NULL;
- nautilus_file_unref (original_file);
- nautilus_file_unref (original_dir);
- g_list_free (original_dirs);
+ nautilus_file_unref (original_file);
+ nautilus_file_unref (original_dir);
+ g_list_free (original_dirs);
- if (original_dirs_hash != NULL) {
- g_hash_table_destroy (original_dirs_hash);
- }
- return can_restore;
+ if (original_dirs_hash != NULL)
+ {
+ g_hash_table_destroy (original_dirs_hash);
+ }
+ return can_restore;
}
static void
clipboard_changed_callback (NautilusClipboardMonitor *monitor,
NautilusFilesView *view)
{
- /* Update paste menu item */
- nautilus_files_view_update_context_menus (view);
+ /* Update paste menu item */
+ nautilus_files_view_update_context_menus (view);
}
static gboolean
can_delete_all (GList *files)
{
- NautilusFile *file;
- GList *l;
+ NautilusFile *file;
+ GList *l;
- for (l = files; l != NULL; l = l->next) {
- file = l->data;
- if (!nautilus_file_can_delete (file)) {
- return FALSE;
- }
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = l->data;
+ if (!nautilus_file_can_delete (file))
+ {
+ return FALSE;
}
- return TRUE;
+ }
+ return TRUE;
}
static gboolean
can_trash_all (GList *files)
{
- NautilusFile *file;
- GList *l;
+ NautilusFile *file;
+ GList *l;
- for (l = files; l != NULL; l = l->next) {
- file = l->data;
- if (!nautilus_file_can_trash (file)) {
- return FALSE;
- }
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = l->data;
+ if (!nautilus_file_can_trash (file))
+ {
+ return FALSE;
}
- return TRUE;
+ }
+ return TRUE;
}
static gboolean
all_in_trash (GList *files)
{
- NautilusFile *file;
- GList *l;
+ NautilusFile *file;
+ GList *l;
- for (l = files; l != NULL; l = l->next) {
- file = l->data;
- if (!nautilus_file_is_in_trash (file)) {
- return FALSE;
- }
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = l->data;
+ if (!nautilus_file_is_in_trash (file))
+ {
+ return FALSE;
}
- return TRUE;
+ }
+ return TRUE;
}
static gboolean
can_extract_all (GList *files)
{
- NautilusFile *file;
- GList *l;
+ NautilusFile *file;
+ GList *l;
- for (l = files; l != NULL; l = l->next) {
- file = l->data;
- if (!nautilus_file_is_archive (file)) {
- return FALSE;
- }
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = l->data;
+ if (!nautilus_file_is_archive (file))
+ {
+ return FALSE;
}
- return TRUE;
+ }
+ return TRUE;
}
GActionGroup *
nautilus_files_view_get_action_group (NautilusFilesView *view)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- return view->details->view_action_group;
+ return view->details->view_action_group;
}
static void
real_update_actions_state (NautilusFilesView *view)
{
- GList *selection, *l;
- NautilusFile *file;
- gint selection_count;
- gboolean selection_contains_special_link;
- gboolean selection_contains_desktop_or_home_dir;
- gboolean selection_contains_recent;
- gboolean selection_contains_search;
- gboolean selection_all_in_trash;
- gboolean selection_is_read_only;
- gboolean can_create_files;
- gboolean can_delete_files;
- gboolean can_move_files;
- gboolean can_trash_files;
- gboolean can_copy_files;
- gboolean can_link_from_copied_files;
- gboolean can_paste_files_into;
- gboolean can_extract_files;
- gboolean can_extract_here;
- gboolean item_opens_in_view;
- gboolean is_read_only;
- GAction *action;
- GActionGroup *view_action_group;
- gboolean show_mount;
- gboolean show_unmount;
- gboolean show_eject;
- gboolean show_start;
- gboolean show_stop;
- gboolean show_detect_media;
- gboolean settings_show_delete_permanently;
- gboolean settings_show_create_link;
- gboolean settings_automatic_decompression;
- GDriveStartStopType start_stop_type;
-
- view_action_group = view->details->view_action_group;
-
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- selection_count = g_list_length (selection);
- selection_contains_special_link = nautilus_files_view_special_link_in_selection (view, selection);
- selection_contains_desktop_or_home_dir = desktop_or_home_dir_in_selection (selection);
- selection_contains_recent = showing_recent_directory (view);
- selection_contains_search = nautilus_view_is_searching (NAUTILUS_VIEW (view));
- selection_is_read_only = selection_count == 1 &&
- (!nautilus_file_can_write (NAUTILUS_FILE (selection->data)) &&
- !nautilus_file_has_activation_uri (NAUTILUS_FILE (selection->data)));
- selection_all_in_trash = all_in_trash (selection);
-
- is_read_only = nautilus_files_view_is_read_only (view);
- can_create_files = nautilus_files_view_supports_creating_files (view);
- can_delete_files =
- can_delete_all (selection) &&
- selection_count != 0 &&
- !selection_contains_special_link &&
- !selection_contains_desktop_or_home_dir;
- can_trash_files =
- can_trash_all (selection) &&
- selection_count != 0 &&
- !selection_contains_special_link &&
- !selection_contains_desktop_or_home_dir;
- can_copy_files = selection_count != 0
- && !selection_contains_special_link;
- can_link_from_copied_files = !nautilus_clipboard_monitor_is_cut (nautilus_clipboard_monitor_get ()) &&
- !selection_contains_recent && !is_read_only;
- can_move_files = can_delete_files && !selection_contains_recent;
- can_paste_files_into = (!selection_contains_recent &&
- selection_count == 1 &&
- can_paste_into_file (NAUTILUS_FILE (selection->data)));
- can_extract_files = selection_count != 0 &&
- can_extract_all (selection);
- can_extract_here = nautilus_files_view_supports_extract_here (view);
- settings_show_delete_permanently = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY);
- settings_show_create_link = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_SHOW_CREATE_LINK);
- settings_automatic_decompression = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
-
- /* Right click actions */
- /* Selection menu actions */
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "new-folder-with-selection");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_create_files && can_delete_files && (selection_count > 1) && !selection_contains_recent);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "rename");
- if (selection_count > 1) {
- if (have_bulk_rename_tool())
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- have_bulk_rename_tool ());
- else
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- nautilus_file_can_rename_files (selection));
- } else {
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- selection_count == 1 &&
- nautilus_file_can_rename (selection->data));
- }
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "extract-here");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_extract_files &&
- !settings_automatic_decompression &&
- can_extract_here);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "extract-to");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_extract_files &&
- (!settings_automatic_decompression ||
- can_extract_here));
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "compress");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !can_extract_files && can_create_files);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "open-item-location");
-
+ GList *selection, *l;
+ NautilusFile *file;
+ gint selection_count;
+ gboolean selection_contains_special_link;
+ gboolean selection_contains_desktop_or_home_dir;
+ gboolean selection_contains_recent;
+ gboolean selection_contains_search;
+ gboolean selection_all_in_trash;
+ gboolean selection_is_read_only;
+ gboolean can_create_files;
+ gboolean can_delete_files;
+ gboolean can_move_files;
+ gboolean can_trash_files;
+ gboolean can_copy_files;
+ gboolean can_link_from_copied_files;
+ gboolean can_paste_files_into;
+ gboolean can_extract_files;
+ gboolean can_extract_here;
+ gboolean item_opens_in_view;
+ gboolean is_read_only;
+ GAction *action;
+ GActionGroup *view_action_group;
+ gboolean show_mount;
+ gboolean show_unmount;
+ gboolean show_eject;
+ gboolean show_start;
+ gboolean show_stop;
+ gboolean show_detect_media;
+ gboolean settings_show_delete_permanently;
+ gboolean settings_show_create_link;
+ gboolean settings_automatic_decompression;
+ GDriveStartStopType start_stop_type;
+
+ view_action_group = view->details->view_action_group;
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection_count = g_list_length (selection);
+ selection_contains_special_link = nautilus_files_view_special_link_in_selection (view, selection);
+ selection_contains_desktop_or_home_dir = desktop_or_home_dir_in_selection (selection);
+ selection_contains_recent = showing_recent_directory (view);
+ selection_contains_search = nautilus_view_is_searching (NAUTILUS_VIEW (view));
+ selection_is_read_only = selection_count == 1 &&
+ (!nautilus_file_can_write (NAUTILUS_FILE (selection->data)) &&
+ !nautilus_file_has_activation_uri (NAUTILUS_FILE (selection->data)));
+ selection_all_in_trash = all_in_trash (selection);
+
+ is_read_only = nautilus_files_view_is_read_only (view);
+ can_create_files = nautilus_files_view_supports_creating_files (view);
+ can_delete_files =
+ can_delete_all (selection) &&
+ selection_count != 0 &&
+ !selection_contains_special_link &&
+ !selection_contains_desktop_or_home_dir;
+ can_trash_files =
+ can_trash_all (selection) &&
+ selection_count != 0 &&
+ !selection_contains_special_link &&
+ !selection_contains_desktop_or_home_dir;
+ can_copy_files = selection_count != 0
+ && !selection_contains_special_link;
+ can_link_from_copied_files = !nautilus_clipboard_monitor_is_cut (nautilus_clipboard_monitor_get ()) &&
+ !selection_contains_recent && !is_read_only;
+ can_move_files = can_delete_files && !selection_contains_recent;
+ can_paste_files_into = (!selection_contains_recent &&
+ selection_count == 1 &&
+ can_paste_into_file (NAUTILUS_FILE (selection->data)));
+ can_extract_files = selection_count != 0 &&
+ can_extract_all (selection);
+ can_extract_here = nautilus_files_view_supports_extract_here (view);
+ settings_show_delete_permanently = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY);
+ settings_show_create_link = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_SHOW_CREATE_LINK);
+ settings_automatic_decompression = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
+
+ /* Right click actions */
+ /* Selection menu actions */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "new-folder-with-selection");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_create_files && can_delete_files && (selection_count > 1) && !selection_contains_recent);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "rename");
+ if (selection_count > 1)
+ {
+ if (have_bulk_rename_tool ())
+ {
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ have_bulk_rename_tool ());
+ }
+ else
+ {
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ nautilus_file_can_rename_files (selection));
+ }
+ }
+ else
+ {
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
selection_count == 1 &&
- (selection_contains_recent || selection_contains_search));
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "new-folder");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
-
- item_opens_in_view = selection_count != 0;
-
- for (l = selection; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (selection->data);
-
- if (!nautilus_file_opens_in_view (file)) {
- item_opens_in_view = FALSE;
- }
-
- if (!item_opens_in_view) {
- break;
- }
- }
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "open-with-default-application");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count != 0);
-
- /* Allow to select a different application to open the item */
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "open-with-other-application");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- selection_count > 0);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "open-item-new-tab");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), item_opens_in_view);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "open-item-new-window");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), item_opens_in_view);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "set-as-wallpaper");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_set_wallpaper (selection));
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "restore-from-trash");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_restore_from_trash (selection));
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "move-to-trash");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_trash_files);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "delete-from-trash");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_delete_files && selection_all_in_trash);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "delete-permanently-shortcut");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_delete_files);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "delete-permanently-menu-item");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_delete_files && !can_trash_files &&
- !selection_all_in_trash && !selection_contains_recent);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "permanent-delete-permanently-menu-item");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_delete_files && can_trash_files &&
- settings_show_delete_permanently &&
- !selection_all_in_trash && !selection_contains_recent);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "remove-from-recent");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- selection_contains_recent && selection_count > 0);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "cut");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_move_files && !selection_contains_recent);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "copy");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_copy_files);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "create-link-in-place");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_copy_files &&
- can_create_files &&
- settings_show_create_link);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "copy-to");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_copy_files);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "move-to");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_move_files && !selection_contains_recent);
-
- /* Drive menu */
- show_mount = show_unmount = show_eject = show_start = show_stop = show_detect_media = FALSE;
- for (l = selection; l != NULL && (show_mount || show_unmount
- || show_eject
- || show_start || show_stop
- || show_detect_media);
- l = l->next) {
- gboolean show_mount_one;
- gboolean show_unmount_one;
- gboolean show_eject_one;
- gboolean show_start_one;
- gboolean show_stop_one;
- gboolean show_detect_media_one;
-
- file = NAUTILUS_FILE (l->data);
- file_should_show_foreach (file,
- &show_mount_one,
- &show_unmount_one,
- &show_eject_one,
- &show_start_one,
- &show_stop_one,
- &show_detect_media_one,
- &start_stop_type);
-
- show_mount &= show_mount_one;
- show_unmount &= show_unmount_one;
- show_eject &= show_eject_one;
- show_start &= show_start_one;
- show_stop &= show_stop_one;
- show_detect_media &= show_detect_media_one;
- }
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "mount-volume");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- show_mount);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "unmount-volume");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- show_unmount);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "eject-volume");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- show_eject);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "start-volume");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- show_start);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "stop-volume");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- show_stop);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "detect-media");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- show_detect_media);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "scripts");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- view->details->scripts_present);
-
- /* Background menu actions */
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "new-folder");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "paste");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !is_read_only && !selection_contains_recent);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "create-link");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_link_from_copied_files &&
- settings_show_create_link);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "paste-into");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !selection_is_read_only && !selection_contains_recent &&
- can_paste_files_into);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "properties");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- TRUE);
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "new-document");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- can_create_files &&
- !selection_contains_recent &&
- view->details->templates_present);
-
- /* Ask the clipboard */
- g_object_ref (view); /* Need to keep the object alive until we get the reply */
- gtk_clipboard_request_targets (nautilus_clipboard_get (GTK_WIDGET (view)),
- clipboard_targets_received,
- view);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "select-all");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !nautilus_files_view_is_empty (view));
-
- /* Toolbar menu actions */
- g_action_group_change_action_state (view_action_group,
- "show-hidden-files",
- g_variant_new_boolean (view->details->show_hidden_files));
+ nautilus_file_can_rename (selection->data));
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "extract-here");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_extract_files &&
+ !settings_automatic_decompression &&
+ can_extract_here);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "extract-to");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_extract_files &&
+ (!settings_automatic_decompression ||
+ can_extract_here));
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "compress");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !can_extract_files && can_create_files);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-item-location");
+
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selection_count == 1 &&
+ (selection_contains_recent || selection_contains_search));
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "new-folder");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
+
+ item_opens_in_view = selection_count != 0;
+
+ for (l = selection; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
- /* Zoom */
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "zoom-in");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- nautilus_files_view_can_zoom_in (view));
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "zoom-out");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- nautilus_files_view_can_zoom_out (view));
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "zoom-standard");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- nautilus_files_view_supports_zooming (view));
- action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
- "zoom-to-level");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !nautilus_files_view_is_empty (view));
+ file = NAUTILUS_FILE (selection->data);
- nautilus_file_list_free (selection);
+ if (!nautilus_file_opens_in_view (file))
+ {
+ item_opens_in_view = FALSE;
+ }
+
+ if (!item_opens_in_view)
+ {
+ break;
+ }
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-with-default-application");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), selection_count != 0);
+
+ /* Allow to select a different application to open the item */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-with-other-application");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selection_count > 0);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-item-new-tab");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), item_opens_in_view);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "open-item-new-window");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), item_opens_in_view);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "set-as-wallpaper");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_set_wallpaper (selection));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "restore-from-trash");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_restore_from_trash (selection));
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "move-to-trash");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_trash_files);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "delete-from-trash");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_delete_files && selection_all_in_trash);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "delete-permanently-shortcut");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_delete_files);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "delete-permanently-menu-item");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_delete_files && !can_trash_files &&
+ !selection_all_in_trash && !selection_contains_recent);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "permanent-delete-permanently-menu-item");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_delete_files && can_trash_files &&
+ settings_show_delete_permanently &&
+ !selection_all_in_trash && !selection_contains_recent);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "remove-from-recent");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selection_contains_recent && selection_count > 0);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "cut");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_move_files && !selection_contains_recent);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "copy");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_copy_files);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "create-link-in-place");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_copy_files &&
+ can_create_files &&
+ settings_show_create_link);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "copy-to");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_copy_files);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "move-to");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_move_files && !selection_contains_recent);
+
+ /* Drive menu */
+ show_mount = show_unmount = show_eject = show_start = show_stop = show_detect_media = FALSE;
+ for (l = selection; l != NULL && (show_mount || show_unmount
+ || show_eject
+ || show_start || show_stop
+ || show_detect_media);
+ l = l->next)
+ {
+ gboolean show_mount_one;
+ gboolean show_unmount_one;
+ gboolean show_eject_one;
+ gboolean show_start_one;
+ gboolean show_stop_one;
+ gboolean show_detect_media_one;
+
+ file = NAUTILUS_FILE (l->data);
+ file_should_show_foreach (file,
+ &show_mount_one,
+ &show_unmount_one,
+ &show_eject_one,
+ &show_start_one,
+ &show_stop_one,
+ &show_detect_media_one,
+ &start_stop_type);
+
+ show_mount &= show_mount_one;
+ show_unmount &= show_unmount_one;
+ show_eject &= show_eject_one;
+ show_start &= show_start_one;
+ show_stop &= show_stop_one;
+ show_detect_media &= show_detect_media_one;
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "mount-volume");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ show_mount);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "unmount-volume");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ show_unmount);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "eject-volume");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ show_eject);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "start-volume");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ show_start);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "stop-volume");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ show_stop);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "detect-media");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ show_detect_media);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "scripts");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ view->details->scripts_present);
+
+ /* Background menu actions */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "new-folder");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_create_files);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "paste");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !is_read_only && !selection_contains_recent);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "create-link");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_link_from_copied_files &&
+ settings_show_create_link);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "paste-into");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !selection_is_read_only && !selection_contains_recent &&
+ can_paste_files_into);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "properties");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ TRUE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "new-document");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ can_create_files &&
+ !selection_contains_recent &&
+ view->details->templates_present);
+
+ /* Ask the clipboard */
+ g_object_ref (view); /* Need to keep the object alive until we get the reply */
+ gtk_clipboard_request_targets (nautilus_clipboard_get (GTK_WIDGET (view)),
+ clipboard_targets_received,
+ view);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "select-all");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !nautilus_files_view_is_empty (view));
+
+ /* Toolbar menu actions */
+ g_action_group_change_action_state (view_action_group,
+ "show-hidden-files",
+ g_variant_new_boolean (view->details->show_hidden_files));
+
+ /* Zoom */
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "zoom-in");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ nautilus_files_view_can_zoom_in (view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "zoom-out");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ nautilus_files_view_can_zoom_out (view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "zoom-standard");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ nautilus_files_view_supports_zooming (view));
+ action = g_action_map_lookup_action (G_ACTION_MAP (view_action_group),
+ "zoom-to-level");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !nautilus_files_view_is_empty (view));
+
+ nautilus_file_list_free (selection);
}
/* Convenience function to be called when updating menus,
@@ -6918,241 +7356,289 @@ real_update_actions_state (NautilusFilesView *view)
void
nautilus_files_view_update_actions_state (NautilusFilesView *view)
{
- g_assert(NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->update_actions_state (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->update_actions_state (view);
}
static void
update_selection_menu (NautilusFilesView *view)
{
- GList *selection, *l;
+ GList *selection, *l;
+ NautilusFile *file;
+ gint selection_count;
+ gboolean show_app;
+ gboolean show_run;
+ gboolean show_extract;
+ gboolean item_opens_in_view;
+ gchar *item_label;
+ GAppInfo *app;
+ GIcon *app_icon;
+ GMenuItem *menu_item;
+ gboolean show_mount;
+ gboolean show_unmount;
+ gboolean show_eject;
+ gboolean show_start;
+ gboolean show_stop;
+ gboolean show_detect_media;
+ GDriveStartStopType start_stop_type;
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ selection_count = g_list_length (selection);
+
+ show_mount = (selection != NULL);
+ show_unmount = (selection != NULL);
+ show_eject = (selection != NULL);
+ show_start = (selection != NULL && selection_count == 1);
+ show_stop = (selection != NULL && selection_count == 1);
+ show_detect_media = (selection != NULL && selection_count == 1);
+ start_stop_type = G_DRIVE_START_STOP_TYPE_UNKNOWN;
+ item_label = g_strdup_printf (ngettext ("New Folder with Selection (%'d Item)",
+ "New Folder with Selection (%'d Items)",
+ selection_count),
+ selection_count);
+ menu_item = g_menu_item_new (item_label, "view.new-folder-with-selection");
+ g_menu_item_set_attribute (menu_item, "hidden-when", "s", "action-disabled");
+ nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
+ menu_item,
+ "new-folder-with-selection-section",
+ FALSE);
+ g_object_unref (menu_item);
+ g_free (item_label);
+
+ /* Open With <App> menu item */
+ show_extract = show_app = show_run = item_opens_in_view = selection_count != 0;
+ for (l = selection; l != NULL; l = l->next)
+ {
NautilusFile *file;
- gint selection_count;
- gboolean show_app;
- gboolean show_run;
- gboolean show_extract;
- gboolean item_opens_in_view;
- gchar *item_label;
- GAppInfo *app;
- GIcon *app_icon;
- GMenuItem *menu_item;
- gboolean show_mount;
- gboolean show_unmount;
- gboolean show_eject;
- gboolean show_start;
- gboolean show_stop;
- gboolean show_detect_media;
- GDriveStartStopType start_stop_type;
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- selection_count = g_list_length (selection);
-
- show_mount = (selection != NULL);
- show_unmount = (selection != NULL);
- show_eject = (selection != NULL);
- show_start = (selection != NULL && selection_count == 1);
- show_stop = (selection != NULL && selection_count == 1);
- show_detect_media = (selection != NULL && selection_count == 1);
- start_stop_type = G_DRIVE_START_STOP_TYPE_UNKNOWN;
- item_label = g_strdup_printf (ngettext ("New Folder with Selection (%'d Item)",
- "New Folder with Selection (%'d Items)",
- selection_count),
- selection_count);
- menu_item = g_menu_item_new (item_label, "view.new-folder-with-selection");
- g_menu_item_set_attribute (menu_item, "hidden-when", "s", "action-disabled");
- nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
- menu_item,
- "new-folder-with-selection-section",
- FALSE);
- g_object_unref (menu_item);
- g_free (item_label);
+ file = NAUTILUS_FILE (l->data);
- /* Open With <App> menu item */
- show_extract = show_app = show_run = item_opens_in_view = selection_count != 0;
- for (l = selection; l != NULL; l = l->next) {
- NautilusFile *file;
+ if (!nautilus_mime_file_extracts (file))
+ {
+ show_extract = FALSE;
+ }
- file = NAUTILUS_FILE (l->data);
+ if (!nautilus_mime_file_opens_in_external_app (file))
+ {
+ show_app = FALSE;
+ }
- if (!nautilus_mime_file_extracts (file)) {
- show_extract = FALSE;
- }
+ if (!nautilus_mime_file_launches (file))
+ {
+ show_run = FALSE;
+ }
- if (!nautilus_mime_file_opens_in_external_app (file)) {
- show_app = FALSE;
- }
+ if (!nautilus_file_opens_in_view (file))
+ {
+ item_opens_in_view = FALSE;
+ }
- if (!nautilus_mime_file_launches (file)) {
- show_run = FALSE;
- }
+ if (!show_extract && !show_app && !show_run && !item_opens_in_view)
+ {
+ break;
+ }
+ }
- if (!nautilus_file_opens_in_view (file)) {
- item_opens_in_view = FALSE;
- }
+ item_label = NULL;
+ app = NULL;
+ app_icon = NULL;
+ if (show_app)
+ {
+ app = nautilus_mime_get_default_application_for_files (selection);
+ }
- if (!show_extract && !show_app && !show_run && !item_opens_in_view) {
- break;
- }
- }
+ char *escaped_app;
- item_label = NULL;
- app = NULL;
- app_icon = NULL;
- if (show_app) {
- app = nautilus_mime_get_default_application_for_files (selection);
- }
+ if (app != NULL)
+ {
+ escaped_app = eel_str_double_underscores (g_app_info_get_name (app));
+ item_label = g_strdup_printf (_("Open With %s"), escaped_app);
- char *escaped_app;
+ app_icon = g_app_info_get_icon (app);
+ if (app_icon != NULL)
+ {
+ g_object_ref (app_icon);
+ }
+ g_free (escaped_app);
+ g_object_unref (app);
+ }
+ else if (show_run)
+ {
+ item_label = g_strdup (_("Run"));
+ }
+ else if (show_extract)
+ {
+ item_label = nautilus_files_view_supports_extract_here (view) ?
+ g_strdup (_("Extract Here")) :
+ g_strdup (_("Extract to…"));
+ }
+ else
+ {
+ item_label = g_strdup (_("Open"));
+ }
+
+ menu_item = g_menu_item_new (item_label, "view.open-with-default-application");
+ if (app_icon != NULL)
+ {
+ g_menu_item_set_icon (menu_item, app_icon);
+ }
+
+ nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
+ menu_item,
+ "open-with-default-application-section",
+ FALSE);
+
+ g_free (item_label);
+ g_object_unref (menu_item);
+
+ /* Drives */
+ for (l = selection; l != NULL && (show_mount || show_unmount
+ || show_eject
+ || show_start || show_stop
+ || show_detect_media);
+ l = l->next)
+ {
+ gboolean show_mount_one;
+ gboolean show_unmount_one;
+ gboolean show_eject_one;
+ gboolean show_start_one;
+ gboolean show_stop_one;
+ gboolean show_detect_media_one;
+
+ file = NAUTILUS_FILE (l->data);
+ file_should_show_foreach (file,
+ &show_mount_one,
+ &show_unmount_one,
+ &show_eject_one,
+ &show_start_one,
+ &show_stop_one,
+ &show_detect_media_one,
+ &start_stop_type);
+
+ show_mount &= show_mount_one;
+ show_unmount &= show_unmount_one;
+ show_eject &= show_eject_one;
+ show_start &= show_start_one;
+ show_stop &= show_stop_one;
+ show_detect_media &= show_detect_media_one;
+ }
+
+ if (show_start)
+ {
+ switch (start_stop_type)
+ {
+ default:
+ case G_DRIVE_START_STOP_TYPE_UNKNOWN:
+ case G_DRIVE_START_STOP_TYPE_SHUTDOWN:
+ {
+ item_label = _("_Start");
+ }
+ break;
- if (app != NULL) {
- escaped_app = eel_str_double_underscores (g_app_info_get_name (app));
- item_label = g_strdup_printf (_("Open With %s"), escaped_app);
+ case G_DRIVE_START_STOP_TYPE_NETWORK:
+ {
+ item_label = _("_Connect");
+ }
+ break;
- app_icon = g_app_info_get_icon (app);
- if (app_icon != NULL) {
- g_object_ref (app_icon);
+ case G_DRIVE_START_STOP_TYPE_MULTIDISK:
+ {
+ item_label = _("_Start Multi-disk Drive");
}
- g_free (escaped_app);
- g_object_unref (app);
- } else if (show_run) {
- item_label = g_strdup (_("Run"));
- } else if (show_extract) {
- item_label = nautilus_files_view_supports_extract_here (view) ?
- g_strdup (_("Extract Here")) :
- g_strdup (_("Extract to…"));
- } else {
- item_label = g_strdup (_("Open"));
- }
+ break;
- menu_item = g_menu_item_new (item_label, "view.open-with-default-application");
- if (app_icon != NULL)
- g_menu_item_set_icon (menu_item, app_icon);
+ case G_DRIVE_START_STOP_TYPE_PASSWORD:
+ {
+ item_label = _("U_nlock Drive");
+ }
+ break;
+ }
+ menu_item = g_menu_item_new (item_label, "view.start-volume");
nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
menu_item,
- "open-with-default-application-section",
+ "drive-section",
FALSE);
-
- g_free (item_label);
g_object_unref (menu_item);
+ }
+
+ if (show_stop)
+ {
+ switch (start_stop_type)
+ {
+ default:
+ case G_DRIVE_START_STOP_TYPE_UNKNOWN:
+ {
+ item_label = _("Stop Drive");
+ }
+ break;
- /* Drives */
- for (l = selection; l != NULL && (show_mount || show_unmount
- || show_eject
- || show_start || show_stop
- || show_detect_media);
- l = l->next) {
- gboolean show_mount_one;
- gboolean show_unmount_one;
- gboolean show_eject_one;
- gboolean show_start_one;
- gboolean show_stop_one;
- gboolean show_detect_media_one;
-
- file = NAUTILUS_FILE (l->data);
- file_should_show_foreach (file,
- &show_mount_one,
- &show_unmount_one,
- &show_eject_one,
- &show_start_one,
- &show_stop_one,
- &show_detect_media_one,
- &start_stop_type);
-
- show_mount &= show_mount_one;
- show_unmount &= show_unmount_one;
- show_eject &= show_eject_one;
- show_start &= show_start_one;
- show_stop &= show_stop_one;
- show_detect_media &= show_detect_media_one;
- }
-
- if (show_start) {
- switch (start_stop_type) {
- default:
- case G_DRIVE_START_STOP_TYPE_UNKNOWN:
- case G_DRIVE_START_STOP_TYPE_SHUTDOWN:
- item_label = _("_Start");
- break;
- case G_DRIVE_START_STOP_TYPE_NETWORK:
- item_label = _("_Connect");
- break;
- case G_DRIVE_START_STOP_TYPE_MULTIDISK:
- item_label = _("_Start Multi-disk Drive");
- break;
- case G_DRIVE_START_STOP_TYPE_PASSWORD:
- item_label = _("U_nlock Drive");
- break;
+ case G_DRIVE_START_STOP_TYPE_SHUTDOWN:
+ {
+ item_label = _("_Safely Remove Drive");
}
+ break;
- menu_item = g_menu_item_new (item_label, "view.start-volume");
- nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
- menu_item,
- "drive-section",
- FALSE);
- g_object_unref (menu_item);
- }
+ case G_DRIVE_START_STOP_TYPE_NETWORK:
+ {
+ item_label = _("_Disconnect");
+ }
+ break;
- if (show_stop) {
- switch (start_stop_type) {
- default:
- case G_DRIVE_START_STOP_TYPE_UNKNOWN:
- item_label = _("Stop Drive");
- break;
- case G_DRIVE_START_STOP_TYPE_SHUTDOWN:
- item_label = _("_Safely Remove Drive");
- break;
- case G_DRIVE_START_STOP_TYPE_NETWORK:
- item_label = _("_Disconnect");
- break;
- case G_DRIVE_START_STOP_TYPE_MULTIDISK:
- item_label = _("_Stop Multi-disk Drive");
- break;
- case G_DRIVE_START_STOP_TYPE_PASSWORD:
- item_label = _("_Lock Drive");
- break;
+ case G_DRIVE_START_STOP_TYPE_MULTIDISK:
+ {
+ item_label = _("_Stop Multi-disk Drive");
}
+ break;
- menu_item = g_menu_item_new (item_label, "view.stop-volume");
- nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
- menu_item,
- "drive-section",
- FALSE);
- g_object_unref (menu_item);
+ case G_DRIVE_START_STOP_TYPE_PASSWORD:
+ {
+ item_label = _("_Lock Drive");
+ }
+ break;
}
- nautilus_file_list_free (selection);
+ menu_item = g_menu_item_new (item_label, "view.stop-volume");
+ nautilus_gmenu_add_item_in_submodel (view->details->selection_menu,
+ menu_item,
+ "drive-section",
+ FALSE);
+ g_object_unref (menu_item);
+ }
+
+ nautilus_file_list_free (selection);
- update_scripts_menu (view);
+ update_scripts_menu (view);
}
static void
update_background_menu (NautilusFilesView *view)
{
-
- if (nautilus_files_view_supports_creating_files (view) &&
- !showing_recent_directory (view))
- update_templates_menu (view);
+ if (nautilus_files_view_supports_creating_files (view) &&
+ !showing_recent_directory (view))
+ {
+ update_templates_menu (view);
+ }
}
static void
real_update_context_menus (NautilusFilesView *view)
{
- g_clear_object (&view->details->background_menu);
- g_clear_object (&view->details->selection_menu);
+ g_clear_object (&view->details->background_menu);
+ g_clear_object (&view->details->selection_menu);
- GtkBuilder *builder;
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-files-view-context-menus.ui");
- view->details->background_menu = g_object_ref_sink (G_MENU (gtk_builder_get_object (builder, "background-menu")));
- view->details->selection_menu = g_object_ref_sink (G_MENU (gtk_builder_get_object (builder, "selection-menu")));
- g_object_unref (builder);
+ GtkBuilder *builder;
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-files-view-context-menus.ui");
+ view->details->background_menu = g_object_ref_sink (G_MENU (gtk_builder_get_object (builder, "background-menu")));
+ view->details->selection_menu = g_object_ref_sink (G_MENU (gtk_builder_get_object (builder, "selection-menu")));
+ g_object_unref (builder);
- update_selection_menu (view);
- update_background_menu (view);
- update_extensions_menus (view);
+ update_selection_menu (view);
+ update_background_menu (view);
+ update_extensions_menus (view);
- nautilus_files_view_update_actions_state (view);
+ nautilus_files_view_update_actions_state (view);
}
/* Convenience function to reset the context menus owned by the view and update
@@ -7165,54 +7651,58 @@ real_update_context_menus (NautilusFilesView *view)
void
nautilus_files_view_update_context_menus (NautilusFilesView *view)
{
- g_assert(NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->update_context_menus (view);
+ NAUTILUS_FILES_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->update_context_menus (view);
}
static void
nautilus_files_view_reset_view_menu (NautilusFilesView *view)
{
- GActionGroup *view_action_group;
- GVariant *variant;
- GVariantIter iter;
- gboolean show_sort_trash, show_sort_access, show_sort_modification, sort_available;
- const gchar *hint;
- g_autofree gchar *zoom_level_percent = NULL;
-
- view_action_group = nautilus_files_view_get_action_group (view);
-
- gtk_widget_set_visible (view->details->visible_columns,
- g_action_group_has_action (view_action_group, "visible-columns"));
-
- sort_available = g_action_group_get_action_enabled (view_action_group, "sort");
- show_sort_trash = show_sort_modification = show_sort_access = FALSE;
- gtk_widget_set_visible (view->details->sort_menu, sort_available);
-
- /* We want to make insensitive available actions but that are not current
- * available due to the directory
- */
- gtk_widget_set_sensitive (view->details->sort_menu,
- !nautilus_files_view_is_empty (view));
- gtk_widget_set_sensitive (view->details->zoom_controls_box,
- !nautilus_files_view_is_empty (view));
-
- if (sort_available) {
- variant = g_action_group_get_action_state_hint (view_action_group, "sort");
- g_variant_iter_init (&iter, variant);
-
- while (g_variant_iter_next (&iter, "&s", &hint)) {
- if (g_strcmp0 (hint, "trash-time") == 0)
- show_sort_trash = TRUE;
- }
-
- g_variant_unref (variant);
+ GActionGroup *view_action_group;
+ GVariant *variant;
+ GVariantIter iter;
+ gboolean show_sort_trash, show_sort_access, show_sort_modification, sort_available;
+ const gchar *hint;
+ g_autofree gchar *zoom_level_percent = NULL;
+
+ view_action_group = nautilus_files_view_get_action_group (view);
+
+ gtk_widget_set_visible (view->details->visible_columns,
+ g_action_group_has_action (view_action_group, "visible-columns"));
+
+ sort_available = g_action_group_get_action_enabled (view_action_group, "sort");
+ show_sort_trash = show_sort_modification = show_sort_access = FALSE;
+ gtk_widget_set_visible (view->details->sort_menu, sort_available);
+
+ /* We want to make insensitive available actions but that are not current
+ * available due to the directory
+ */
+ gtk_widget_set_sensitive (view->details->sort_menu,
+ !nautilus_files_view_is_empty (view));
+ gtk_widget_set_sensitive (view->details->zoom_controls_box,
+ !nautilus_files_view_is_empty (view));
+
+ if (sort_available)
+ {
+ variant = g_action_group_get_action_state_hint (view_action_group, "sort");
+ g_variant_iter_init (&iter, variant);
+
+ while (g_variant_iter_next (&iter, "&s", &hint))
+ {
+ if (g_strcmp0 (hint, "trash-time") == 0)
+ {
+ show_sort_trash = TRUE;
+ }
}
- gtk_widget_set_visible (view->details->sort_trash_time, show_sort_trash);
+ g_variant_unref (variant);
+ }
- zoom_level_percent = g_strdup_printf ("%.0f%%", nautilus_files_view_get_zoom_level_percentage (view) * 100.0);
- gtk_label_set_label (GTK_LABEL (view->details->zoom_level_label), zoom_level_percent);
+ gtk_widget_set_visible (view->details->sort_trash_time, show_sort_trash);
+
+ zoom_level_percent = g_strdup_printf ("%.0f%%", nautilus_files_view_get_zoom_level_percentage (view) * 100.0);
+ gtk_label_set_label (GTK_LABEL (view->details->zoom_level_label), zoom_level_percent);
}
/* Convenience function to reset the menus owned by the view but managed on
@@ -7223,22 +7713,23 @@ nautilus_files_view_reset_view_menu (NautilusFilesView *view)
void
nautilus_files_view_update_toolbar_menus (NautilusFilesView *view)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- /* Don't update after destroy (#349551),
- * or if we are not active.
- */
- if (view->details->slot == NULL ||
- !view->details->active) {
- return;
- }
- window = nautilus_files_view_get_window (view);
- nautilus_window_reset_menus (window);
+ /* Don't update after destroy (#349551),
+ * or if we are not active.
+ */
+ if (view->details->slot == NULL ||
+ !view->details->active)
+ {
+ return;
+ }
+ window = nautilus_files_view_get_window (view);
+ nautilus_window_reset_menus (window);
- nautilus_files_view_update_actions_state (view);
- nautilus_files_view_reset_view_menu (view);
+ nautilus_files_view_update_actions_state (view);
+ nautilus_files_view_reset_view_menu (view);
}
/**
@@ -7253,16 +7744,16 @@ void
nautilus_files_view_pop_up_selection_context_menu (NautilusFilesView *view,
GdkEventButton *event)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- /* Make the context menu items not flash as they update to proper disabled,
- * etc. states by forcing menus to update now.
- */
- update_context_menus_if_pending (view);
+ /* Make the context menu items not flash as they update to proper disabled,
+ * etc. states by forcing menus to update now.
+ */
+ update_context_menus_if_pending (view);
- update_context_menu_position_from_event (view, event);
+ update_context_menu_position_from_event (view, event);
- nautilus_pop_up_context_menu (GTK_WIDGET (view), view->details->selection_menu, event);
+ nautilus_pop_up_context_menu (GTK_WIDGET (view), view->details->selection_menu, event);
}
/**
@@ -7276,78 +7767,84 @@ void
nautilus_files_view_pop_up_background_context_menu (NautilusFilesView *view,
GdkEventButton *event)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- /* Make the context menu items not flash as they update to proper disabled,
- * etc. states by forcing menus to update now.
- */
- update_context_menus_if_pending (view);
+ /* Make the context menu items not flash as they update to proper disabled,
+ * etc. states by forcing menus to update now.
+ */
+ update_context_menus_if_pending (view);
- update_context_menu_position_from_event (view, event);
+ update_context_menu_position_from_event (view, event);
- nautilus_pop_up_context_menu (GTK_WIDGET (view), view->details->background_menu, event);
+ nautilus_pop_up_context_menu (GTK_WIDGET (view), view->details->background_menu, event);
}
static void
schedule_update_context_menus (NautilusFilesView *view)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- /* Don't schedule updates after destroy (#349551),
- * or if we are not active.
- */
- if (view->details->slot == NULL ||
- !view->details->active) {
- return;
- }
+ /* Don't schedule updates after destroy (#349551),
+ * or if we are not active.
+ */
+ if (view->details->slot == NULL ||
+ !view->details->active)
+ {
+ return;
+ }
- /* Schedule a menu update with the current update interval */
- if (view->details->update_context_menus_timeout_id == 0) {
- view->details->update_context_menus_timeout_id
- = g_timeout_add (view->details->update_interval, update_context_menus_timeout_callback, view);
- }
+ /* Schedule a menu update with the current update interval */
+ if (view->details->update_context_menus_timeout_id == 0)
+ {
+ view->details->update_context_menus_timeout_id
+ = g_timeout_add (view->details->update_interval, update_context_menus_timeout_callback, view);
+ }
}
static void
remove_update_status_idle_callback (NautilusFilesView *view)
{
- if (view->details->update_status_idle_id != 0) {
- g_source_remove (view->details->update_status_idle_id);
- view->details->update_status_idle_id = 0;
- }
+ if (view->details->update_status_idle_id != 0)
+ {
+ g_source_remove (view->details->update_status_idle_id);
+ view->details->update_status_idle_id = 0;
+ }
}
static gboolean
update_status_idle_callback (gpointer data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (data);
- nautilus_files_view_display_selection_info (view);
- view->details->update_status_idle_id = 0;
- return FALSE;
+ view = NAUTILUS_FILES_VIEW (data);
+ nautilus_files_view_display_selection_info (view);
+ view->details->update_status_idle_id = 0;
+ return FALSE;
}
static void
schedule_update_status (NautilusFilesView *view)
{
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- /* Make sure we haven't already destroyed it */
- if (view->details->slot == NULL) {
- return;
- }
+ /* Make sure we haven't already destroyed it */
+ if (view->details->slot == NULL)
+ {
+ return;
+ }
- if (view->details->loading) {
- /* Don't update status bar while loading the dir */
- return;
- }
+ if (view->details->loading)
+ {
+ /* Don't update status bar while loading the dir */
+ return;
+ }
- if (view->details->update_status_idle_id == 0) {
- view->details->update_status_idle_id =
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE - 20,
- update_status_idle_callback, view, NULL);
- }
+ if (view->details->update_status_idle_id == 0)
+ {
+ view->details->update_status_idle_id =
+ g_idle_add_full (G_PRIORITY_DEFAULT_IDLE - 20,
+ update_status_idle_callback, view, NULL);
+ }
}
/**
@@ -7361,49 +7858,53 @@ schedule_update_status (NautilusFilesView *view)
void
nautilus_files_view_notify_selection_changed (NautilusFilesView *view)
{
- GtkWindow *window;
- GList *selection;
+ GtkWindow *window;
+ GList *selection;
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- window = nautilus_files_view_get_containing_window (view);
- DEBUG_FILES (selection, "Selection changed in window %p", window);
- nautilus_file_list_free (selection);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ window = nautilus_files_view_get_containing_window (view);
+ DEBUG_FILES (selection, "Selection changed in window %p", window);
+ nautilus_file_list_free (selection);
- view->details->selection_was_removed = FALSE;
+ view->details->selection_was_removed = FALSE;
- /* Schedule a display of the new selection. */
- if (view->details->display_selection_idle_id == 0) {
- view->details->display_selection_idle_id
- = g_idle_add (display_selection_info_idle_callback,
- view);
- }
-
- if (view->details->batching_selection_level != 0) {
- view->details->selection_changed_while_batched = TRUE;
- } else {
- /* Here is the work we do only when we're not
- * batching selection changes. In other words, it's the slower
- * stuff that we don't want to slow down selection techniques
- * such as rubberband-selecting in icon view.
- */
+ /* Schedule a display of the new selection. */
+ if (view->details->display_selection_idle_id == 0)
+ {
+ view->details->display_selection_idle_id
+ = g_idle_add (display_selection_info_idle_callback,
+ view);
+ }
+
+ if (view->details->batching_selection_level != 0)
+ {
+ view->details->selection_changed_while_batched = TRUE;
+ }
+ else
+ {
+ /* Here is the work we do only when we're not
+ * batching selection changes. In other words, it's the slower
+ * stuff that we don't want to slow down selection techniques
+ * such as rubberband-selecting in icon view.
+ */
- /* Schedule an update of menu item states to match selection */
- schedule_update_context_menus (view);
- }
+ /* Schedule an update of menu item states to match selection */
+ schedule_update_context_menus (view);
+ }
}
static void
file_changed_callback (NautilusFile *file,
gpointer callback_data)
{
- NautilusFilesView *view = NAUTILUS_FILES_VIEW (callback_data);
+ NautilusFilesView *view = NAUTILUS_FILES_VIEW (callback_data);
- schedule_changes (view);
+ schedule_changes (view);
- schedule_update_context_menus (view);
- schedule_update_status (view);
+ schedule_update_context_menus (view);
+ schedule_update_status (view);
}
/**
@@ -7419,175 +7920,179 @@ static void
load_directory (NautilusFilesView *view,
NautilusDirectory *directory)
{
- NautilusFileAttributes attributes;
-
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
-
- nautilus_profile_start (NULL);
-
- nautilus_files_view_stop_loading (view);
- g_signal_emit (view, signals[CLEAR], 0);
-
- view->details->loading = TRUE;
-
- setup_loading_floating_bar (view);
-
- /* Update menus when directory is empty, before going to new
- * location, so they won't have any false lingering knowledge
- * of old selection.
- */
- schedule_update_context_menus (view);
-
- while (view->details->subdirectory_list != NULL) {
- nautilus_files_view_remove_subdirectory (view,
- view->details->subdirectory_list->data);
- }
-
- /* Avoid freeing it and won't be able to ref it */
- if (view->details->model != directory) {
- nautilus_directory_unref (view->details->model);
- view->details->model = nautilus_directory_ref (directory);
- }
-
- nautilus_file_unref (view->details->directory_as_file);
- view->details->directory_as_file = nautilus_directory_get_corresponding_file (directory);
-
- g_clear_object (&view->details->location);
- view->details->location = nautilus_directory_get_location (directory);
-
- g_object_notify (G_OBJECT (view), "location");
- g_object_notify (G_OBJECT (view), "is-loading");
- g_object_notify (G_OBJECT (view), "is-searching");
-
- /* FIXME bugzilla.gnome.org 45062: In theory, we also need to monitor metadata here (as
- * well as doing a call when ready), in case external forces
- * change the directory's file metadata.
- */
- attributes =
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT |
- NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO;
- view->details->metadata_for_directory_as_file_pending = TRUE;
- view->details->metadata_for_files_in_directory_pending = TRUE;
- nautilus_file_call_when_ready
- (view->details->directory_as_file,
- attributes,
- metadata_for_directory_as_file_ready_callback, view);
- nautilus_directory_call_when_ready
- (view->details->model,
- attributes,
- FALSE,
- metadata_for_files_in_directory_ready_callback, view);
-
- /* If capabilities change, then we need to update the menus
- * because of New Folder, and relative emblems.
- */
- attributes =
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO;
- nautilus_file_monitor_add (view->details->directory_as_file,
- &view->details->directory_as_file,
- attributes);
-
- view->details->file_changed_handler_id = g_signal_connect
- (view->details->directory_as_file, "changed",
- G_CALLBACK (file_changed_callback), view);
-
- nautilus_profile_end (NULL);
+ NautilusFileAttributes attributes;
+
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
+
+ nautilus_profile_start (NULL);
+
+ nautilus_files_view_stop_loading (view);
+ g_signal_emit (view, signals[CLEAR], 0);
+
+ view->details->loading = TRUE;
+
+ setup_loading_floating_bar (view);
+
+ /* Update menus when directory is empty, before going to new
+ * location, so they won't have any false lingering knowledge
+ * of old selection.
+ */
+ schedule_update_context_menus (view);
+
+ while (view->details->subdirectory_list != NULL)
+ {
+ nautilus_files_view_remove_subdirectory (view,
+ view->details->subdirectory_list->data);
+ }
+
+ /* Avoid freeing it and won't be able to ref it */
+ if (view->details->model != directory)
+ {
+ nautilus_directory_unref (view->details->model);
+ view->details->model = nautilus_directory_ref (directory);
+ }
+
+ nautilus_file_unref (view->details->directory_as_file);
+ view->details->directory_as_file = nautilus_directory_get_corresponding_file (directory);
+
+ g_clear_object (&view->details->location);
+ view->details->location = nautilus_directory_get_location (directory);
+
+ g_object_notify (G_OBJECT (view), "location");
+ g_object_notify (G_OBJECT (view), "is-loading");
+ g_object_notify (G_OBJECT (view), "is-searching");
+
+ /* FIXME bugzilla.gnome.org 45062: In theory, we also need to monitor metadata here (as
+ * well as doing a call when ready), in case external forces
+ * change the directory's file metadata.
+ */
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO;
+ view->details->metadata_for_directory_as_file_pending = TRUE;
+ view->details->metadata_for_files_in_directory_pending = TRUE;
+ nautilus_file_call_when_ready
+ (view->details->directory_as_file,
+ attributes,
+ metadata_for_directory_as_file_ready_callback, view);
+ nautilus_directory_call_when_ready
+ (view->details->model,
+ attributes,
+ FALSE,
+ metadata_for_files_in_directory_ready_callback, view);
+
+ /* If capabilities change, then we need to update the menus
+ * because of New Folder, and relative emblems.
+ */
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO;
+ nautilus_file_monitor_add (view->details->directory_as_file,
+ &view->details->directory_as_file,
+ attributes);
+
+ view->details->file_changed_handler_id = g_signal_connect
+ (view->details->directory_as_file, "changed",
+ G_CALLBACK (file_changed_callback), view);
+
+ nautilus_profile_end (NULL);
}
static void
finish_loading (NautilusFilesView *view)
{
- NautilusFileAttributes attributes;
+ NautilusFileAttributes attributes;
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- /* Tell interested parties that we've begun loading this directory now.
- * Subclasses use this to know that the new metadata is now available.
- */
- nautilus_profile_start ("BEGIN_LOADING");
- g_signal_emit (view, signals[BEGIN_LOADING], 0);
- nautilus_profile_end ("BEGIN_LOADING");
-
- nautilus_files_view_check_empty_states (view);
+ /* Tell interested parties that we've begun loading this directory now.
+ * Subclasses use this to know that the new metadata is now available.
+ */
+ nautilus_profile_start ("BEGIN_LOADING");
+ g_signal_emit (view, signals[BEGIN_LOADING], 0);
+ nautilus_profile_end ("BEGIN_LOADING");
- if (nautilus_directory_are_all_files_seen (view->details->model)) {
- /* Unschedule a pending update and schedule a new one with the minimal
- * update interval. This gives the view a short chance at gathering the
- * (cached) deep counts.
- */
- unschedule_display_of_pending_files (view);
- schedule_timeout_display_of_pending_files (view, UPDATE_INTERVAL_MIN);
- }
+ nautilus_files_view_check_empty_states (view);
- /* Start loading. */
-
- /* Connect handlers to learn about loading progress. */
- view->details->done_loading_handler_id = g_signal_connect
- (view->details->model, "done-loading",
- G_CALLBACK (done_loading_callback), view);
- view->details->load_error_handler_id = g_signal_connect
- (view->details->model, "load-error",
- G_CALLBACK (load_error_callback), view);
-
- /* Monitor the things needed to get the right icon. Also
- * monitor a directory's item count because the "size"
- * attribute is based on that, and the file's metadata
- * and possible custom name.
+ if (nautilus_directory_are_all_files_seen (view->details->model))
+ {
+ /* Unschedule a pending update and schedule a new one with the minimal
+ * update interval. This gives the view a short chance at gathering the
+ * (cached) deep counts.
*/
- attributes =
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT |
- NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
-
- nautilus_directory_file_monitor_add (view->details->model,
- &view->details->model,
- view->details->show_hidden_files,
- attributes,
- files_added_callback, view);
-
- view->details->files_added_handler_id = g_signal_connect
- (view->details->model, "files-added",
- G_CALLBACK (files_added_callback), view);
- view->details->files_changed_handler_id = g_signal_connect
- (view->details->model, "files-changed",
- G_CALLBACK (files_changed_callback), view);
-
- nautilus_profile_end (NULL);
+ unschedule_display_of_pending_files (view);
+ schedule_timeout_display_of_pending_files (view, UPDATE_INTERVAL_MIN);
+ }
+
+ /* Start loading. */
+
+ /* Connect handlers to learn about loading progress. */
+ view->details->done_loading_handler_id = g_signal_connect
+ (view->details->model, "done-loading",
+ G_CALLBACK (done_loading_callback), view);
+ view->details->load_error_handler_id = g_signal_connect
+ (view->details->model, "load-error",
+ G_CALLBACK (load_error_callback), view);
+
+ /* Monitor the things needed to get the right icon. Also
+ * monitor a directory's item count because the "size"
+ * attribute is based on that, and the file's metadata
+ * and possible custom name.
+ */
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
+
+ nautilus_directory_file_monitor_add (view->details->model,
+ &view->details->model,
+ view->details->show_hidden_files,
+ attributes,
+ files_added_callback, view);
+
+ view->details->files_added_handler_id = g_signal_connect
+ (view->details->model, "files-added",
+ G_CALLBACK (files_added_callback), view);
+ view->details->files_changed_handler_id = g_signal_connect
+ (view->details->model, "files-changed",
+ G_CALLBACK (files_changed_callback), view);
+
+ nautilus_profile_end (NULL);
}
static void
finish_loading_if_all_metadata_loaded (NautilusFilesView *view)
{
- if (!view->details->metadata_for_directory_as_file_pending &&
- !view->details->metadata_for_files_in_directory_pending) {
- finish_loading (view);
- }
+ if (!view->details->metadata_for_directory_as_file_pending &&
+ !view->details->metadata_for_files_in_directory_pending)
+ {
+ finish_loading (view);
+ }
}
static void
metadata_for_directory_as_file_ready_callback (NautilusFile *file,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = callback_data;
+ view = callback_data;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
- g_assert (view->details->directory_as_file == file);
- g_assert (view->details->metadata_for_directory_as_file_pending);
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (view->details->directory_as_file == file);
+ g_assert (view->details->metadata_for_directory_as_file_pending);
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- view->details->metadata_for_directory_as_file_pending = FALSE;
+ view->details->metadata_for_directory_as_file_pending = FALSE;
- finish_loading_if_all_metadata_loaded (view);
- nautilus_profile_end (NULL);
+ finish_loading_if_all_metadata_loaded (view);
+ nautilus_profile_end (NULL);
}
static void
@@ -7595,79 +8100,81 @@ metadata_for_files_in_directory_ready_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = callback_data;
+ view = callback_data;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
- g_assert (view->details->model == directory);
- g_assert (view->details->metadata_for_files_in_directory_pending);
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ g_assert (view->details->model == directory);
+ g_assert (view->details->metadata_for_files_in_directory_pending);
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- view->details->metadata_for_files_in_directory_pending = FALSE;
+ view->details->metadata_for_files_in_directory_pending = FALSE;
- finish_loading_if_all_metadata_loaded (view);
- nautilus_profile_end (NULL);
+ finish_loading_if_all_metadata_loaded (view);
+ nautilus_profile_end (NULL);
}
static void
disconnect_handler (GObject *object,
guint *id)
{
- if (*id != 0) {
- g_signal_handler_disconnect (object, *id);
- *id = 0;
- }
+ if (*id != 0)
+ {
+ g_signal_handler_disconnect (object, *id);
+ *id = 0;
+ }
}
static void
disconnect_directory_handler (NautilusFilesView *view,
guint *id)
{
- disconnect_handler (G_OBJECT (view->details->model), id);
+ disconnect_handler (G_OBJECT (view->details->model), id);
}
static void
disconnect_directory_as_file_handler (NautilusFilesView *view,
guint *id)
{
- disconnect_handler (G_OBJECT (view->details->directory_as_file), id);
+ disconnect_handler (G_OBJECT (view->details->directory_as_file), id);
}
static void
disconnect_model_handlers (NautilusFilesView *view)
{
- if (view->details->model == NULL) {
- return;
- }
- disconnect_directory_handler (view, &view->details->files_added_handler_id);
- disconnect_directory_handler (view, &view->details->files_changed_handler_id);
- disconnect_directory_handler (view, &view->details->done_loading_handler_id);
- disconnect_directory_handler (view, &view->details->load_error_handler_id);
- disconnect_directory_as_file_handler (view, &view->details->file_changed_handler_id);
- nautilus_file_cancel_call_when_ready (view->details->directory_as_file,
- metadata_for_directory_as_file_ready_callback,
- view);
- nautilus_directory_cancel_callback (view->details->model,
- metadata_for_files_in_directory_ready_callback,
- view);
- nautilus_directory_file_monitor_remove (view->details->model,
- &view->details->model);
- nautilus_file_monitor_remove (view->details->directory_as_file,
- &view->details->directory_as_file);
+ if (view->details->model == NULL)
+ {
+ return;
+ }
+ disconnect_directory_handler (view, &view->details->files_added_handler_id);
+ disconnect_directory_handler (view, &view->details->files_changed_handler_id);
+ disconnect_directory_handler (view, &view->details->done_loading_handler_id);
+ disconnect_directory_handler (view, &view->details->load_error_handler_id);
+ disconnect_directory_as_file_handler (view, &view->details->file_changed_handler_id);
+ nautilus_file_cancel_call_when_ready (view->details->directory_as_file,
+ metadata_for_directory_as_file_ready_callback,
+ view);
+ nautilus_directory_cancel_callback (view->details->model,
+ metadata_for_files_in_directory_ready_callback,
+ view);
+ nautilus_directory_file_monitor_remove (view->details->model,
+ &view->details->model);
+ nautilus_file_monitor_remove (view->details->directory_as_file,
+ &view->details->directory_as_file);
}
static void
nautilus_files_view_select_file (NautilusFilesView *view,
NautilusFile *file)
{
- GList file_list;
+ GList file_list;
- file_list.data = file;
- file_list.next = NULL;
- file_list.prev = NULL;
- nautilus_files_view_call_set_selection (view, &file_list);
+ file_list.data = file;
+ file_list.next = NULL;
+ file_list.prev = NULL;
+ nautilus_files_view_call_set_selection (view, &file_list);
}
static gboolean
@@ -7675,7 +8182,7 @@ remove_all (gpointer key,
gpointer value,
gpointer callback_data)
{
- return TRUE;
+ return TRUE;
}
/**
@@ -7688,62 +8195,65 @@ remove_all (gpointer key,
void
nautilus_files_view_stop_loading (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- unschedule_display_of_pending_files (view);
- reset_update_interval (view);
+ unschedule_display_of_pending_files (view);
+ reset_update_interval (view);
- /* Free extra undisplayed files */
- file_and_directory_list_free (view->details->new_added_files);
- view->details->new_added_files = NULL;
+ /* Free extra undisplayed files */
+ file_and_directory_list_free (view->details->new_added_files);
+ view->details->new_added_files = NULL;
- file_and_directory_list_free (view->details->new_changed_files);
- view->details->new_changed_files = NULL;
+ file_and_directory_list_free (view->details->new_changed_files);
+ view->details->new_changed_files = NULL;
- g_hash_table_foreach_remove (view->details->non_ready_files, remove_all, NULL);
+ g_hash_table_foreach_remove (view->details->non_ready_files, remove_all, NULL);
- file_and_directory_list_free (view->details->old_added_files);
- view->details->old_added_files = NULL;
+ file_and_directory_list_free (view->details->old_added_files);
+ view->details->old_added_files = NULL;
- file_and_directory_list_free (view->details->old_changed_files);
- view->details->old_changed_files = NULL;
+ file_and_directory_list_free (view->details->old_changed_files);
+ view->details->old_changed_files = NULL;
- g_list_free_full (view->details->pending_selection, g_object_unref);
- view->details->pending_selection = NULL;
+ g_list_free_full (view->details->pending_selection, g_object_unref);
+ view->details->pending_selection = NULL;
- done_loading (view, FALSE);
+ done_loading (view, FALSE);
- disconnect_model_handlers (view);
+ disconnect_model_handlers (view);
}
gboolean
nautilus_files_view_is_editable (NautilusFilesView *view)
{
- NautilusDirectory *directory;
+ NautilusDirectory *directory;
- directory = nautilus_files_view_get_model (view);
+ directory = nautilus_files_view_get_model (view);
- if (directory != NULL) {
- return nautilus_directory_is_editable (directory);
- }
+ if (directory != NULL)
+ {
+ return nautilus_directory_is_editable (directory);
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
nautilus_files_view_is_read_only (NautilusFilesView *view)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (!nautilus_files_view_is_editable (view)) {
- return TRUE;
- }
+ if (!nautilus_files_view_is_editable (view))
+ {
+ return TRUE;
+ }
- file = nautilus_files_view_get_directory_as_file (view);
- if (file != NULL) {
- return !nautilus_file_can_write (file);
- }
- return FALSE;
+ file = nautilus_files_view_get_directory_as_file (view);
+ if (file != NULL)
+ {
+ return !nautilus_file_can_write (file);
+ }
+ return FALSE;
}
/**
@@ -7756,47 +8266,49 @@ gboolean
nautilus_files_view_should_show_file (NautilusFilesView *view,
NautilusFile *file)
{
- return nautilus_file_should_show (file,
- view->details->show_hidden_files,
- view->details->show_foreign_files);
+ return nautilus_file_should_show (file,
+ view->details->show_hidden_files,
+ view->details->show_foreign_files);
}
static gboolean
real_using_manual_layout (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), FALSE);
- return FALSE;
+ return FALSE;
}
void
nautilus_files_view_ignore_hidden_file_preferences (NautilusFilesView *view)
{
- g_return_if_fail (view->details->model == NULL);
+ g_return_if_fail (view->details->model == NULL);
- if (view->details->ignore_hidden_file_preferences) {
- return;
- }
+ if (view->details->ignore_hidden_file_preferences)
+ {
+ return;
+ }
- view->details->show_hidden_files = FALSE;
- view->details->ignore_hidden_file_preferences = TRUE;
+ view->details->show_hidden_files = FALSE;
+ view->details->ignore_hidden_file_preferences = TRUE;
}
void
nautilus_files_view_set_show_foreign (NautilusFilesView *view,
gboolean show_foreign)
{
- view->details->show_foreign_files = show_foreign;
+ view->details->show_foreign_files = show_foreign;
}
char *
nautilus_files_view_get_uri (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
- if (view->details->model == NULL) {
- return NULL;
- }
- return nautilus_directory_get_uri (view->details->model);
+ g_return_val_if_fail (NAUTILUS_IS_FILES_VIEW (view), NULL);
+ if (view->details->model == NULL)
+ {
+ return NULL;
+ }
+ return nautilus_directory_get_uri (view->details->model);
}
void
@@ -7808,66 +8320,71 @@ nautilus_files_view_move_copy_items (NautilusFilesView *view,
int x,
int y)
{
- NautilusFile *target_file;
+ NautilusFile *target_file;
- g_assert (relative_item_points == NULL
- || relative_item_points->len == 0
- || g_list_length ((GList *)item_uris) == relative_item_points->len);
+ g_assert (relative_item_points == NULL
+ || relative_item_points->len == 0
+ || g_list_length ((GList *) item_uris) == relative_item_points->len);
- /* add the drop location to the icon offsets */
- offset_drop_points (relative_item_points, x, y);
+ /* add the drop location to the icon offsets */
+ offset_drop_points (relative_item_points, x, y);
- target_file = nautilus_file_get_existing_by_uri (target_uri);
- /* special-case "command:" here instead of starting a move/copy */
- if (target_file != NULL && nautilus_file_is_launcher (target_file)) {
- nautilus_file_unref (target_file);
- nautilus_launch_desktop_file (
- gtk_widget_get_screen (GTK_WIDGET (view)),
- target_uri, item_uris,
- nautilus_files_view_get_containing_window (view));
- return;
- } else if (copy_action == GDK_ACTION_COPY &&
- nautilus_is_file_roller_installed () &&
- target_file != NULL &&
- nautilus_file_is_archive (target_file)) {
- char *command, *quoted_uri, *tmp;
- const GList *l;
- GdkScreen *screen;
+ target_file = nautilus_file_get_existing_by_uri (target_uri);
+ /* special-case "command:" here instead of starting a move/copy */
+ if (target_file != NULL && nautilus_file_is_launcher (target_file))
+ {
+ nautilus_file_unref (target_file);
+ nautilus_launch_desktop_file (
+ gtk_widget_get_screen (GTK_WIDGET (view)),
+ target_uri, item_uris,
+ nautilus_files_view_get_containing_window (view));
+ return;
+ }
+ else if (copy_action == GDK_ACTION_COPY &&
+ nautilus_is_file_roller_installed () &&
+ target_file != NULL &&
+ nautilus_file_is_archive (target_file))
+ {
+ char *command, *quoted_uri, *tmp;
+ const GList *l;
+ GdkScreen *screen;
- /* Handle dropping onto a file-roller archiver file, instead of starting a move/copy */
+ /* Handle dropping onto a file-roller archiver file, instead of starting a move/copy */
- nautilus_file_unref (target_file);
+ nautilus_file_unref (target_file);
- quoted_uri = g_shell_quote (target_uri);
- command = g_strconcat ("file-roller -a ", quoted_uri, NULL);
- g_free (quoted_uri);
+ quoted_uri = g_shell_quote (target_uri);
+ command = g_strconcat ("file-roller -a ", quoted_uri, NULL);
+ g_free (quoted_uri);
- for (l = item_uris; l != NULL; l = l->next) {
- quoted_uri = g_shell_quote ((char *) l->data);
+ for (l = item_uris; l != NULL; l = l->next)
+ {
+ quoted_uri = g_shell_quote ((char *) l->data);
- tmp = g_strconcat (command, " ", quoted_uri, NULL);
- g_free (command);
- command = tmp;
+ tmp = g_strconcat (command, " ", quoted_uri, NULL);
+ g_free (command);
+ command = tmp;
- g_free (quoted_uri);
- }
+ g_free (quoted_uri);
+ }
- screen = gtk_widget_get_screen (GTK_WIDGET (view));
- if (screen == NULL) {
- screen = gdk_screen_get_default ();
- }
+ screen = gtk_widget_get_screen (GTK_WIDGET (view));
+ if (screen == NULL)
+ {
+ screen = gdk_screen_get_default ();
+ }
- nautilus_launch_application_from_command (screen, command, FALSE, NULL);
- g_free (command);
+ nautilus_launch_application_from_command (screen, command, FALSE, NULL);
+ g_free (command);
- return;
- }
- nautilus_file_unref (target_file);
+ return;
+ }
+ nautilus_file_unref (target_file);
- nautilus_file_operations_copy_move
- (item_uris, relative_item_points,
- target_uri, copy_action, GTK_WIDGET (view),
- copy_move_done_callback, pre_copy_move (view));
+ nautilus_file_operations_copy_move
+ (item_uris, relative_item_points,
+ target_uri, copy_action, GTK_WIDGET (view),
+ copy_move_done_callback, pre_copy_move (view));
}
static void
@@ -7875,34 +8392,36 @@ nautilus_files_view_trash_state_changed_callback (NautilusTrashMonitor *trash_mo
gboolean state,
gpointer callback_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = (NautilusFilesView *) callback_data;
- g_assert (NAUTILUS_IS_FILES_VIEW (view));
+ view = (NautilusFilesView *) callback_data;
+ g_assert (NAUTILUS_IS_FILES_VIEW (view));
- schedule_update_context_menus (view);
+ schedule_update_context_menus (view);
}
void
nautilus_files_view_start_batching_selection_changes (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- ++view->details->batching_selection_level;
- view->details->selection_changed_while_batched = FALSE;
+ ++view->details->batching_selection_level;
+ view->details->selection_changed_while_batched = FALSE;
}
void
nautilus_files_view_stop_batching_selection_changes (NautilusFilesView *view)
{
- g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
- g_return_if_fail (view->details->batching_selection_level > 0);
+ g_return_if_fail (NAUTILUS_IS_FILES_VIEW (view));
+ g_return_if_fail (view->details->batching_selection_level > 0);
- if (--view->details->batching_selection_level == 0) {
- if (view->details->selection_changed_while_batched) {
- nautilus_files_view_notify_selection_changed (view);
- }
+ if (--view->details->batching_selection_level == 0)
+ {
+ if (view->details->selection_changed_while_batched)
+ {
+ nautilus_files_view_notify_selection_changed (view);
}
+ }
}
static void
@@ -7911,33 +8430,43 @@ nautilus_files_view_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusFilesView *view = NAUTILUS_FILES_VIEW (object);
+ NautilusFilesView *view = NAUTILUS_FILES_VIEW (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_ICON:
+ {
g_value_set_object (value, nautilus_view_get_icon (NAUTILUS_VIEW (view)));
- break;
+ }
+ break;
case PROP_IS_LOADING:
+ {
g_value_set_boolean (value, nautilus_view_is_loading (NAUTILUS_VIEW (view)));
- break;
+ }
+ break;
case PROP_IS_SEARCH:
+ {
g_value_set_boolean (value, nautilus_view_is_searching (NAUTILUS_VIEW (view)));
- break;
+ }
+ break;
case PROP_LOCATION:
+ {
g_value_set_object (value, nautilus_view_get_location (NAUTILUS_VIEW (view)));
- break;
+ }
+ break;
case PROP_SEARCH_QUERY:
+ {
g_value_set_object (value, view->details->search_query);
- break;
+ }
+ break;
default:
- g_assert_not_reached ();
-
- }
+ g_assert_not_reached ();
+ }
}
static void
@@ -7946,13 +8475,15 @@ nautilus_files_view_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- NautilusFilesView *directory_view;
- NautilusWindowSlot *slot;
+ NautilusFilesView *directory_view;
+ NautilusWindowSlot *slot;
- directory_view = NAUTILUS_FILES_VIEW (object);
+ directory_view = NAUTILUS_FILES_VIEW (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_WINDOW_SLOT:
+ {
g_assert (directory_view->details->slot == NULL);
slot = NAUTILUS_WINDOW_SLOT (g_value_get_object (value));
@@ -7964,23 +8495,33 @@ nautilus_files_view_set_property (GObject *object,
g_signal_connect_object (directory_view->details->slot,
"inactive", G_CALLBACK (slot_inactive),
directory_view, 0);
- break;
+ }
+ break;
+
case PROP_SUPPORTS_ZOOMING:
+ {
directory_view->details->supports_zooming = g_value_get_boolean (value);
- break;
+ }
+ break;
case PROP_LOCATION:
+ {
nautilus_view_set_location (NAUTILUS_VIEW (directory_view), g_value_get_object (value));
- break;
+ }
+ break;
case PROP_SEARCH_QUERY:
+ {
nautilus_view_set_search_query (NAUTILUS_VIEW (directory_view), g_value_get_object (value));
- break;
+ }
+ break;
default:
+ {
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ }
+ break;
+ }
}
@@ -7988,53 +8529,68 @@ gboolean
nautilus_files_view_handle_scroll_event (NautilusFilesView *directory_view,
GdkEventScroll *event)
{
- static gdouble total_delta_y = 0;
- gdouble delta_x, delta_y;
+ static gdouble total_delta_y = 0;
+ gdouble delta_x, delta_y;
+
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ switch (event->direction)
+ {
+ case GDK_SCROLL_UP:
+ {
+ /* Zoom In */
+ nautilus_files_view_bump_zoom_level (directory_view, 1);
+ return TRUE;
+ }
- if (event->state & GDK_CONTROL_MASK) {
- switch (event->direction) {
- case GDK_SCROLL_UP:
- /* Zoom In */
- nautilus_files_view_bump_zoom_level (directory_view, 1);
- return TRUE;
+ case GDK_SCROLL_DOWN:
+ {
+ /* Zoom Out */
+ nautilus_files_view_bump_zoom_level (directory_view, -1);
+ return TRUE;
+ }
+
+ case GDK_SCROLL_SMOOTH:
+ {
+ gdk_event_get_scroll_deltas ((const GdkEvent *) event,
+ &delta_x, &delta_y);
- case GDK_SCROLL_DOWN:
- /* Zoom Out */
+ /* try to emulate a normal scrolling event by summing deltas */
+ total_delta_y += delta_y;
+
+ if (total_delta_y >= 1)
+ {
+ total_delta_y = 0;
+ /* emulate scroll down */
nautilus_files_view_bump_zoom_level (directory_view, -1);
return TRUE;
+ }
+ else if (total_delta_y <= -1)
+ {
+ total_delta_y = 0;
+ /* emulate scroll up */
+ nautilus_files_view_bump_zoom_level (directory_view, 1);
+ return TRUE;
+ }
+ else
+ {
+ /* eat event */
+ return TRUE;
+ }
+ }
- case GDK_SCROLL_SMOOTH:
- gdk_event_get_scroll_deltas ((const GdkEvent *) event,
- &delta_x, &delta_y);
-
- /* try to emulate a normal scrolling event by summing deltas */
- total_delta_y += delta_y;
-
- if (total_delta_y >= 1) {
- total_delta_y = 0;
- /* emulate scroll down */
- nautilus_files_view_bump_zoom_level (directory_view, -1);
- return TRUE;
- } else if (total_delta_y <= - 1) {
- total_delta_y = 0;
- /* emulate scroll up */
- nautilus_files_view_bump_zoom_level (directory_view, 1);
- return TRUE;
- } else {
- /* eat event */
- return TRUE;
- }
-
- case GDK_SCROLL_LEFT:
- case GDK_SCROLL_RIGHT:
- break;
-
- default:
- g_assert_not_reached ();
+ case GDK_SCROLL_LEFT:
+ case GDK_SCROLL_RIGHT:
+ {
}
+ break;
+
+ default:
+ g_assert_not_reached ();
}
+ }
- return FALSE;
+ return FALSE;
}
/* handle Shift+Scroll, which will cause a zoom-in/out */
@@ -8042,14 +8598,15 @@ static gboolean
nautilus_files_view_scroll_event (GtkWidget *widget,
GdkEventScroll *event)
{
- NautilusFilesView *directory_view;
+ NautilusFilesView *directory_view;
- directory_view = NAUTILUS_FILES_VIEW (widget);
- if (nautilus_files_view_handle_scroll_event (directory_view, event)) {
- return TRUE;
- }
+ directory_view = NAUTILUS_FILES_VIEW (widget);
+ if (nautilus_files_view_handle_scroll_event (directory_view, event))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
@@ -8059,7 +8616,7 @@ action_reload_enabled_changed (GActionGroup *action_group,
gboolean enabled,
NautilusFilesView *view)
{
- gtk_widget_set_visible (view->details->reload, enabled);
+ gtk_widget_set_visible (view->details->reload, enabled);
}
static void
@@ -8068,106 +8625,116 @@ action_stop_enabled_changed (GActionGroup *action_group,
gboolean enabled,
NautilusFilesView *view)
{
- gtk_widget_set_visible (view->details->stop, enabled);
+ gtk_widget_set_visible (view->details->stop, enabled);
}
static void
nautilus_files_view_parent_set (GtkWidget *widget,
GtkWidget *old_parent)
{
- NautilusWindow *window;
- NautilusFilesView *view;
- GtkWidget *parent;
-
- view = NAUTILUS_FILES_VIEW (widget);
-
- parent = gtk_widget_get_parent (widget);
- window = nautilus_files_view_get_window (view);
- g_assert (parent == NULL || old_parent == NULL);
-
- if (GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->parent_set != NULL) {
- GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->parent_set (widget, old_parent);
- }
-
- if (view->details->stop_signal_handler > 0) {
- g_signal_handler_disconnect (window, view->details->stop_signal_handler);
- view->details->stop_signal_handler = 0;
- }
-
- if (view->details->reload_signal_handler > 0) {
- g_signal_handler_disconnect (window, view->details->reload_signal_handler);
- view->details->reload_signal_handler = 0;
- }
-
- if (parent != NULL) {
- g_assert (old_parent == NULL);
-
- if (view->details->slot == nautilus_window_get_active_slot (window)) {
- view->details->active = TRUE;
- gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
- "view",
- G_ACTION_GROUP (view->details->view_action_group));
- }
-
- view->details->stop_signal_handler =
- g_signal_connect (window,
- "action-enabled-changed::stop",
- G_CALLBACK (action_stop_enabled_changed),
- view);
- view->details->reload_signal_handler =
- g_signal_connect (window,
- "action-enabled-changed::reload",
- G_CALLBACK (action_reload_enabled_changed),
- view);
- } else {
- remove_update_context_menus_timeout_callback (view);
- /* Only remove the action group if it matchs the current view
- * action group. If not, we can remove an action group set by
- * a different view i.e. if the slot_active function is called
- * before this one
- */
- if (gtk_widget_get_action_group (GTK_WIDGET (window), "view") ==
- view->details->view_action_group) {
- gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
- "view",
- NULL);
-
- }
+ NautilusWindow *window;
+ NautilusFilesView *view;
+ GtkWidget *parent;
+
+ view = NAUTILUS_FILES_VIEW (widget);
+
+ parent = gtk_widget_get_parent (widget);
+ window = nautilus_files_view_get_window (view);
+ g_assert (parent == NULL || old_parent == NULL);
+
+ if (GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->parent_set != NULL)
+ {
+ GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->parent_set (widget, old_parent);
+ }
+
+ if (view->details->stop_signal_handler > 0)
+ {
+ g_signal_handler_disconnect (window, view->details->stop_signal_handler);
+ view->details->stop_signal_handler = 0;
+ }
+
+ if (view->details->reload_signal_handler > 0)
+ {
+ g_signal_handler_disconnect (window, view->details->reload_signal_handler);
+ view->details->reload_signal_handler = 0;
+ }
+
+ if (parent != NULL)
+ {
+ g_assert (old_parent == NULL);
+
+ if (view->details->slot == nautilus_window_get_active_slot (window))
+ {
+ view->details->active = TRUE;
+ gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
+ "view",
+ G_ACTION_GROUP (view->details->view_action_group));
+ }
+
+ view->details->stop_signal_handler =
+ g_signal_connect (window,
+ "action-enabled-changed::stop",
+ G_CALLBACK (action_stop_enabled_changed),
+ view);
+ view->details->reload_signal_handler =
+ g_signal_connect (window,
+ "action-enabled-changed::reload",
+ G_CALLBACK (action_reload_enabled_changed),
+ view);
+ }
+ else
+ {
+ remove_update_context_menus_timeout_callback (view);
+ /* Only remove the action group if it matchs the current view
+ * action group. If not, we can remove an action group set by
+ * a different view i.e. if the slot_active function is called
+ * before this one
+ */
+ if (gtk_widget_get_action_group (GTK_WIDGET (window), "view") ==
+ view->details->view_action_group)
+ {
+ gtk_widget_insert_action_group (GTK_WIDGET (nautilus_files_view_get_window (view)),
+ "view",
+ NULL);
}
+ }
}
static gboolean
nautilus_files_view_key_press_event (GtkWidget *widget,
GdkEventKey *event)
{
- NautilusFilesView *view;
- gint i;
+ NautilusFilesView *view;
+ gint i;
- view = NAUTILUS_FILES_VIEW (widget);
+ view = NAUTILUS_FILES_VIEW (widget);
- for (i = 0; i < G_N_ELEMENTS (extra_view_keybindings); i++) {
- if (extra_view_keybindings[i].keyval == event->keyval) {
- GAction *action;
+ for (i = 0; i < G_N_ELEMENTS (extra_view_keybindings); i++)
+ {
+ if (extra_view_keybindings[i].keyval == event->keyval)
+ {
+ GAction *action;
- action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
- extra_view_keybindings[i].action);
+ action = g_action_map_lookup_action (G_ACTION_MAP (view->details->view_action_group),
+ extra_view_keybindings[i].action);
- if (g_action_get_enabled (action)) {
- g_action_activate (action, NULL);
- return GDK_EVENT_STOP;
- }
+ if (g_action_get_enabled (action))
+ {
+ g_action_activate (action, NULL);
+ return GDK_EVENT_STOP;
+ }
- break;
- }
+ break;
}
+ }
- return GDK_EVENT_PROPAGATE;
+ return GDK_EVENT_PROPAGATE;
}
-static NautilusQuery*
+static NautilusQuery *
nautilus_files_view_get_search_query (NautilusView *view)
{
- return NAUTILUS_FILES_VIEW (view)->details->search_query;
+ return NAUTILUS_FILES_VIEW (view)->details->search_query;
}
static void
@@ -8175,492 +8742,521 @@ set_search_query_internal (NautilusFilesView *files_view,
NautilusQuery *query,
NautilusDirectory *base_model)
{
- GFile *location;
+ GFile *location;
- location = NULL;
-
- g_set_object (&files_view->details->search_query, query);
- g_object_notify (G_OBJECT (files_view), "search-query");
-
- if (!nautilus_query_is_empty (query)) {
- if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view))) {
- /*
- * Reuse the search directory and reload it.
- */
- nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (files_view->details->model), query);
- /* It's important to use load_directory instead of set_location,
- * since the location is already correct, however we need
- * to reload the directory with the new query set. But
- * set_location has a check for wheter the location is a
- * search directory, so setting the location to a search
- * directory when is already serching will enter a loop.
- */
- load_directory (files_view, files_view->details->model);
- } else {
- NautilusDirectory *directory;
- gchar *uri;
-
- uri = nautilus_search_directory_generate_new_uri ();
- location = g_file_new_for_uri (uri);
-
- directory = nautilus_directory_get (location);
- g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
- nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), base_model);
- nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);
-
- load_directory (files_view, directory);
-
- g_object_notify (G_OBJECT (files_view), "is-searching");
-
- nautilus_directory_unref (directory);
- g_free (uri);
- }
- } else {
- if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view))) {
- location = nautilus_directory_get_location (base_model);
+ location = NULL;
- nautilus_view_set_location (NAUTILUS_VIEW (files_view), location);
- }
+ g_set_object (&files_view->details->search_query, query);
+ g_object_notify (G_OBJECT (files_view), "search-query");
+
+ if (!nautilus_query_is_empty (query))
+ {
+ if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view)))
+ {
+ /*
+ * Reuse the search directory and reload it.
+ */
+ nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (files_view->details->model), query);
+ /* It's important to use load_directory instead of set_location,
+ * since the location is already correct, however we need
+ * to reload the directory with the new query set. But
+ * set_location has a check for wheter the location is a
+ * search directory, so setting the location to a search
+ * directory when is already serching will enter a loop.
+ */
+ load_directory (files_view, files_view->details->model);
+ }
+ else
+ {
+ NautilusDirectory *directory;
+ gchar *uri;
+
+ uri = nautilus_search_directory_generate_new_uri ();
+ location = g_file_new_for_uri (uri);
+
+ directory = nautilus_directory_get (location);
+ g_assert (NAUTILUS_IS_SEARCH_DIRECTORY (directory));
+ nautilus_search_directory_set_base_model (NAUTILUS_SEARCH_DIRECTORY (directory), base_model);
+ nautilus_search_directory_set_query (NAUTILUS_SEARCH_DIRECTORY (directory), query);
+
+ load_directory (files_view, directory);
+
+ g_object_notify (G_OBJECT (files_view), "is-searching");
+
+ nautilus_directory_unref (directory);
+ g_free (uri);
+ }
+ }
+ else
+ {
+ if (nautilus_view_is_searching (NAUTILUS_VIEW (files_view)))
+ {
+ location = nautilus_directory_get_location (base_model);
+
+ nautilus_view_set_location (NAUTILUS_VIEW (files_view), location);
}
- g_clear_object (&location);
+ }
+ g_clear_object (&location);
}
static void
nautilus_files_view_set_search_query (NautilusView *view,
NautilusQuery *query)
{
- NautilusDirectory *base_model;
- NautilusFilesView *files_view;
+ NautilusDirectory *base_model;
+ NautilusFilesView *files_view;
- files_view = NAUTILUS_FILES_VIEW (view);
+ files_view = NAUTILUS_FILES_VIEW (view);
- if (nautilus_view_is_searching (view)) {
- base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (files_view->details->model));
- } else {
- base_model = files_view->details->model;
- }
+ if (nautilus_view_is_searching (view))
+ {
+ base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (files_view->details->model));
+ }
+ else
+ {
+ base_model = files_view->details->model;
+ }
- set_search_query_internal (NAUTILUS_FILES_VIEW (view), query, base_model);
+ set_search_query_internal (NAUTILUS_FILES_VIEW (view), query, base_model);
}
-static GFile*
+static GFile *
nautilus_files_view_get_location (NautilusView *view)
{
- NautilusFilesView *files_view;
+ NautilusFilesView *files_view;
- files_view = NAUTILUS_FILES_VIEW (view);
+ files_view = NAUTILUS_FILES_VIEW (view);
- return files_view->details->location;
+ return files_view->details->location;
}
static gboolean
nautilus_files_view_is_loading (NautilusView *view)
{
- NautilusFilesView *files_view;
+ NautilusFilesView *files_view;
- files_view = NAUTILUS_FILES_VIEW (view);
+ files_view = NAUTILUS_FILES_VIEW (view);
- return files_view->details->loading;
+ return files_view->details->loading;
}
static void
nautilus_files_view_iface_init (NautilusViewInterface *iface)
{
- iface->get_icon = nautilus_files_view_get_icon;
- iface->get_location = nautilus_files_view_get_location;
- iface->set_location = nautilus_files_view_set_location;
- iface->get_selection = nautilus_files_view_get_selection;
- iface->set_selection = nautilus_files_view_set_selection;
- iface->get_search_query = nautilus_files_view_get_search_query;
- iface->set_search_query = nautilus_files_view_set_search_query;
- iface->get_toolbar_menu_sections = nautilus_files_view_get_toolbar_menu_sections;
- iface->is_searching = nautilus_files_view_is_searching;
- iface->is_loading = nautilus_files_view_is_loading;
+ iface->get_icon = nautilus_files_view_get_icon;
+ iface->get_location = nautilus_files_view_get_location;
+ iface->set_location = nautilus_files_view_set_location;
+ iface->get_selection = nautilus_files_view_get_selection;
+ iface->set_selection = nautilus_files_view_set_selection;
+ iface->get_search_query = nautilus_files_view_get_search_query;
+ iface->set_search_query = nautilus_files_view_set_search_query;
+ iface->get_toolbar_menu_sections = nautilus_files_view_get_toolbar_menu_sections;
+ iface->is_searching = nautilus_files_view_is_searching;
+ iface->is_loading = nautilus_files_view_is_loading;
}
static void
nautilus_files_view_class_init (NautilusFilesViewClass *klass)
{
- GObjectClass *oclass;
- GtkWidgetClass *widget_class;
-
- widget_class = GTK_WIDGET_CLASS (klass);
- oclass = G_OBJECT_CLASS (klass);
-
- oclass->finalize = nautilus_files_view_finalize;
- oclass->get_property = nautilus_files_view_get_property;
- oclass->set_property = nautilus_files_view_set_property;
-
- widget_class->destroy = nautilus_files_view_destroy;
- widget_class->key_press_event = nautilus_files_view_key_press_event;
- widget_class->scroll_event = nautilus_files_view_scroll_event;
- widget_class->parent_set = nautilus_files_view_parent_set;
- widget_class->grab_focus = nautilus_files_view_grab_focus;
-
- g_type_class_add_private (klass, sizeof (NautilusFilesViewDetails));
-
- signals[ADD_FILE] =
- g_signal_new ("add-file",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, add_file),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
- signals[BEGIN_FILE_CHANGES] =
- g_signal_new ("begin-file-changes",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, begin_file_changes),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[BEGIN_LOADING] =
- g_signal_new ("begin-loading",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, begin_loading),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[CLEAR] =
- g_signal_new ("clear",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, clear),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[END_FILE_CHANGES] =
- g_signal_new ("end-file-changes",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, end_file_changes),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[END_LOADING] =
- g_signal_new ("end-loading",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, end_loading),
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals[FILE_CHANGED] =
- g_signal_new ("file-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, file_changed),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
- signals[REMOVE_FILE] =
- g_signal_new ("remove-file",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusFilesViewClass, remove_file),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
- signals[SELECTION_CHANGED] =
- g_signal_new ("selection-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- klass->get_backing_uri = real_get_backing_uri;
- klass->using_manual_layout = real_using_manual_layout;
- klass->get_window = nautilus_files_view_get_window;
- klass->update_context_menus = real_update_context_menus;
- klass->update_actions_state = real_update_actions_state;
- klass->check_empty_states = real_check_empty_states;
-
- copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
-
- g_object_class_install_property (
- oclass,
- PROP_WINDOW_SLOT,
- g_param_spec_object ("window-slot",
- "Window Slot",
- "The parent window slot reference",
- NAUTILUS_TYPE_WINDOW_SLOT,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (
- oclass,
- PROP_SUPPORTS_ZOOMING,
- g_param_spec_boolean ("supports-zooming",
- "Supports zooming",
- "Whether the view supports zooming",
- TRUE,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
-
- g_object_class_override_property (oclass, PROP_ICON, "icon");
- g_object_class_override_property (oclass, PROP_IS_LOADING, "is-loading");
- g_object_class_override_property (oclass, PROP_IS_SEARCH, "is-searching");
- g_object_class_override_property (oclass, PROP_LOCATION, "location");
- g_object_class_override_property (oclass, PROP_SEARCH_QUERY, "search-query");
+ GObjectClass *oclass;
+ GtkWidgetClass *widget_class;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
+
+ oclass->finalize = nautilus_files_view_finalize;
+ oclass->get_property = nautilus_files_view_get_property;
+ oclass->set_property = nautilus_files_view_set_property;
+
+ widget_class->destroy = nautilus_files_view_destroy;
+ widget_class->key_press_event = nautilus_files_view_key_press_event;
+ widget_class->scroll_event = nautilus_files_view_scroll_event;
+ widget_class->parent_set = nautilus_files_view_parent_set;
+ widget_class->grab_focus = nautilus_files_view_grab_focus;
+
+ g_type_class_add_private (klass, sizeof (NautilusFilesViewDetails));
+
+ signals[ADD_FILE] =
+ g_signal_new ("add-file",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, add_file),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
+ signals[BEGIN_FILE_CHANGES] =
+ g_signal_new ("begin-file-changes",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, begin_file_changes),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[BEGIN_LOADING] =
+ g_signal_new ("begin-loading",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, begin_loading),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[CLEAR] =
+ g_signal_new ("clear",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, clear),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[END_FILE_CHANGES] =
+ g_signal_new ("end-file-changes",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, end_file_changes),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[END_LOADING] =
+ g_signal_new ("end-loading",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, end_loading),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+ signals[FILE_CHANGED] =
+ g_signal_new ("file-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, file_changed),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
+ signals[REMOVE_FILE] =
+ g_signal_new ("remove-file",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusFilesViewClass, remove_file),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2, NAUTILUS_TYPE_FILE, NAUTILUS_TYPE_DIRECTORY);
+ signals[SELECTION_CHANGED] =
+ g_signal_new ("selection-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ klass->get_backing_uri = real_get_backing_uri;
+ klass->using_manual_layout = real_using_manual_layout;
+ klass->get_window = nautilus_files_view_get_window;
+ klass->update_context_menus = real_update_context_menus;
+ klass->update_actions_state = real_update_actions_state;
+ klass->check_empty_states = real_check_empty_states;
+
+ copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
+
+ g_object_class_install_property (
+ oclass,
+ PROP_WINDOW_SLOT,
+ g_param_spec_object ("window-slot",
+ "Window Slot",
+ "The parent window slot reference",
+ NAUTILUS_TYPE_WINDOW_SLOT,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (
+ oclass,
+ PROP_SUPPORTS_ZOOMING,
+ g_param_spec_boolean ("supports-zooming",
+ "Supports zooming",
+ "Whether the view supports zooming",
+ TRUE,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_override_property (oclass, PROP_ICON, "icon");
+ g_object_class_override_property (oclass, PROP_IS_LOADING, "is-loading");
+ g_object_class_override_property (oclass, PROP_IS_SEARCH, "is-searching");
+ g_object_class_override_property (oclass, PROP_LOCATION, "location");
+ g_object_class_override_property (oclass, PROP_SEARCH_QUERY, "search-query");
}
static void
nautilus_files_view_init (NautilusFilesView *view)
{
- GtkBuilder *builder;
- AtkObject *atk_object;
- NautilusDirectory *scripts_directory;
- NautilusDirectory *templates_directory;
- gchar *templates_uri;
- GApplication *app;
- const gchar *open_accels[] = {
- "<control>o",
- "<alt>Down",
- NULL
- };
- const gchar *open_properties[] = {
- "<control>i",
- "<alt>Return",
- NULL
- };
- const gchar *zoom_in_accels[] = {
- "<control>equal",
- "<control>plus",
- NULL
- };
-
- nautilus_profile_start (NULL);
-
- view->details = G_TYPE_INSTANCE_GET_PRIVATE (view, NAUTILUS_TYPE_FILES_VIEW,
- NautilusFilesViewDetails);
-
- /* Toolbar menu */
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-view-menu.ui");
- view->details->toolbar_menu_sections = g_new0 (NautilusToolbarMenuSections, 1);
- view->details->toolbar_menu_sections->supports_undo_redo = TRUE;
- view->details->toolbar_menu_sections->zoom_section = g_object_ref_sink (gtk_builder_get_object (builder, "zoom_section"));
- view->details->toolbar_menu_sections->extended_section = g_object_ref_sink (gtk_builder_get_object (builder, "extended_section"));
- view->details->zoom_controls_box = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_controls_box"));
- view->details->zoom_level_label = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_level_label"));
-
- view->details->sort_menu = GTK_WIDGET (gtk_builder_get_object (builder, "sort_menu"));
- view->details->sort_trash_time = GTK_WIDGET (gtk_builder_get_object (builder, "sort_trash_time"));
- view->details->visible_columns = GTK_WIDGET (gtk_builder_get_object (builder, "visible_columns"));
- view->details->reload = GTK_WIDGET (gtk_builder_get_object (builder, "reload"));
- view->details->stop = GTK_WIDGET (gtk_builder_get_object (builder, "stop"));
-
- g_signal_connect (view,
- "end-file-changes",
- G_CALLBACK (on_end_file_changes),
- view);
-
- g_object_unref (builder);
-
- /* Main widgets */
- gtk_orientable_set_orientation (GTK_ORIENTABLE (view), GTK_ORIENTATION_VERTICAL);
- view->details->overlay = gtk_overlay_new ();
- gtk_widget_set_vexpand (view->details->overlay, TRUE);
- gtk_widget_set_hexpand (view->details->overlay, TRUE);
- gtk_container_add (GTK_CONTAINER (view), view->details->overlay);
- gtk_widget_show (view->details->overlay);
-
- /* NautilusFloatingBar listen to its parent's 'enter-notify-event' signal
- * and GtkOverlay doesn't have it enabled by default, so we have to add them
- * here.
- */
- gtk_widget_add_events (GTK_WIDGET (view->details->overlay),
- GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
-
- /* Scrolled Window */
- view->details->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->details->scrolled_window),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_widget_show (view->details->scrolled_window);
-
- g_signal_connect_swapped (view->details->scrolled_window,
- "scroll-event",
- G_CALLBACK (nautilus_files_view_scroll_event),
- view);
-
- gtk_container_add (GTK_CONTAINER (view->details->overlay), view->details->scrolled_window);
-
- /* Empty states */
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-no-search-results.ui");
- view->details->no_search_results_widget = GTK_WIDGET (gtk_builder_get_object (builder, "no_search_results"));
- gtk_overlay_add_overlay (GTK_OVERLAY (view->details->overlay), view->details->no_search_results_widget);
- gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (view->details->overlay),
- view->details->no_search_results_widget,
- TRUE);
- g_object_unref (builder);
-
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-folder-is-empty.ui");
- view->details->folder_is_empty_widget = GTK_WIDGET (gtk_builder_get_object (builder, "folder_is_empty"));
- gtk_overlay_add_overlay (GTK_OVERLAY (view->details->overlay), view->details->folder_is_empty_widget);
- gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (view->details->overlay),
- view->details->folder_is_empty_widget,
- TRUE);
- g_object_unref (builder);
-
- /* Floating bar */
- view->details->floating_bar = nautilus_floating_bar_new (NULL, NULL, FALSE);
- gtk_widget_set_halign (view->details->floating_bar, GTK_ALIGN_END);
- gtk_widget_set_valign (view->details->floating_bar, GTK_ALIGN_END);
- gtk_overlay_add_overlay (GTK_OVERLAY (view->details->overlay), view->details->floating_bar);
-
- g_signal_connect (view->details->floating_bar,
- "action",
- G_CALLBACK (floating_bar_action_cb),
- view);
-
- /* Default to true; desktop-icon-view sets to false */
- view->details->show_foreign_files = TRUE;
-
- view->details->non_ready_files =
- g_hash_table_new_full (file_and_directory_hash,
- file_and_directory_equal,
- (GDestroyNotify)file_and_directory_free,
- NULL);
-
- view->details->pending_reveal = g_hash_table_new (NULL, NULL);
-
- gtk_style_context_set_junction_sides (gtk_widget_get_style_context (GTK_WIDGET (view)),
- GTK_JUNCTION_TOP | GTK_JUNCTION_LEFT);
-
- if (set_up_scripts_directory_global ()) {
- scripts_directory = nautilus_directory_get_by_uri (scripts_directory_uri);
- add_directory_to_scripts_directory_list (view, scripts_directory);
- nautilus_directory_unref (scripts_directory);
- } else {
- g_warning ("Ignoring scripts directory, it may be a broken link\n");
- }
-
- if (nautilus_should_use_templates_directory ()) {
- templates_uri = nautilus_get_templates_directory_uri ();
- templates_directory = nautilus_directory_get_by_uri (templates_uri);
- g_free (templates_uri);
- add_directory_to_templates_directory_list (view, templates_directory);
- nautilus_directory_unref (templates_directory);
- }
- update_templates_directory (view);
-
- view->details->sort_directories_first =
- g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
- view->details->show_hidden_files =
- g_settings_get_boolean (gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
-
- g_signal_connect_object (nautilus_trash_monitor_get (), "trash-state-changed",
- G_CALLBACK (nautilus_files_view_trash_state_changed_callback), view, 0);
-
- /* React to clipboard changes */
- g_signal_connect_object (nautilus_clipboard_monitor_get (), "clipboard-changed",
- G_CALLBACK (clipboard_changed_callback), view, 0);
-
- /* Register to menu provider extension signal managing menu updates */
- g_signal_connect_object (nautilus_signaller_get_current (), "popup-menu-changed",
- G_CALLBACK (schedule_update_context_menus), view, G_CONNECT_SWAPPED);
-
- gtk_widget_show (GTK_WIDGET (view));
-
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_CLICK_POLICY,
- G_CALLBACK (click_policy_changed_callback),
- view);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
- G_CALLBACK (sort_directories_first_changed_callback), view);
- g_signal_connect_swapped (gtk_filechooser_preferences,
- "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
- G_CALLBACK (show_hidden_files_changed_callback), view);
- g_signal_connect_swapped (gnome_lockdown_preferences,
- "changed::" NAUTILUS_PREFERENCES_LOCKDOWN_COMMAND_LINE,
- G_CALLBACK (schedule_update_context_menus), view);
-
- view->details->in_destruction = FALSE;
-
- /* Accessibility */
- atk_object = gtk_widget_get_accessible (GTK_WIDGET (view));
- atk_object_set_name (atk_object, _("Content View"));
- atk_object_set_description (atk_object, _("View of the current folder"));
-
- view->details->view_action_group = G_ACTION_GROUP (g_simple_action_group_new ());
- g_action_map_add_action_entries (G_ACTION_MAP (view->details->view_action_group),
- view_entries,
- G_N_ELEMENTS (view_entries),
- view);
- gtk_widget_insert_action_group (GTK_WIDGET (view),
- "view",
- G_ACTION_GROUP (view->details->view_action_group));
- app = g_application_get_default ();
-
- /* Toolbar menu */
- nautilus_application_set_accelerators (app, "view.zoom-in", zoom_in_accels);
- nautilus_application_set_accelerator (app, "view.zoom-out", "<control>minus");
- nautilus_application_set_accelerator (app, "view.show-hidden-files", "<control>h");
- /* Background menu */
- nautilus_application_set_accelerator (app, "view.select-all", "<control>a");
- nautilus_application_set_accelerator (app, "view.paste", "<control>v");
- nautilus_application_set_accelerator (app, "view.create-link", "<control>m");
- /* Selection menu */
- nautilus_application_set_accelerators (app, "view.open-with-default-application", open_accels);
- nautilus_application_set_accelerator (app, "view.open-item-new-tab", "<shift><control>t");
- nautilus_application_set_accelerator (app, "view.open-item-new-window", "<shift><control>w");
- nautilus_application_set_accelerator (app, "view.move-to-trash", "Delete");
- nautilus_application_set_accelerator (app, "view.delete-from-trash", "Delete");
- nautilus_application_set_accelerator (app, "view.delete-permanently-shortcut", "<shift>Delete");
- /* When trash is not available, allow the "Delete" key to delete permanently, that is, when
- * the menu item is available, since we never make both the trash and delete-permanently-menu-item
- * actions active */
- nautilus_application_set_accelerator (app, "view.delete-permanently-menu-item", "Delete");
- nautilus_application_set_accelerator (app, "view.permanent-delete-permanently-menu-item", "<shift>Delete");
- nautilus_application_set_accelerators (app, "view.properties", open_properties);
- nautilus_application_set_accelerator (app, "view.open-item-location", "<control><alt>o");
- nautilus_application_set_accelerator (app, "view.rename", "F2");
- nautilus_application_set_accelerator (app, "view.cut", "<control>x");
- nautilus_application_set_accelerator (app, "view.copy", "<control>c");
- nautilus_application_set_accelerator (app, "view.create-link-in-place", "<control><shift>m");
- nautilus_application_set_accelerator (app, "view.new-folder", "<control><shift>n");
- /* Only accesible by shorcuts */
- nautilus_application_set_accelerator (app, "view.select-pattern", "<control>s");
- nautilus_application_set_accelerator (app, "view.zoom-standard", "<control>0");
- nautilus_application_set_accelerator (app, "view.invert-selection", "<shift><control>i");
- nautilus_application_set_accelerator (app, "view.open-file-and-close-window", "<control><shift>Down");
-
- /* Show a warning dialog to inform the user that the shorcut for move to trash
- * changed */
- nautilus_application_set_accelerator (app, "view.show-move-to-trash-shortcut-changed-dialog", "<control>Delete");
-
- nautilus_profile_end (NULL);
+ GtkBuilder *builder;
+ AtkObject *atk_object;
+ NautilusDirectory *scripts_directory;
+ NautilusDirectory *templates_directory;
+ gchar *templates_uri;
+ GApplication *app;
+ const gchar *open_accels[] =
+ {
+ "<control>o",
+ "<alt>Down",
+ NULL
+ };
+ const gchar *open_properties[] =
+ {
+ "<control>i",
+ "<alt>Return",
+ NULL
+ };
+ const gchar *zoom_in_accels[] =
+ {
+ "<control>equal",
+ "<control>plus",
+ NULL
+ };
+
+ nautilus_profile_start (NULL);
+
+ view->details = G_TYPE_INSTANCE_GET_PRIVATE (view, NAUTILUS_TYPE_FILES_VIEW,
+ NautilusFilesViewDetails);
+
+ /* Toolbar menu */
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-view-menu.ui");
+ view->details->toolbar_menu_sections = g_new0 (NautilusToolbarMenuSections, 1);
+ view->details->toolbar_menu_sections->supports_undo_redo = TRUE;
+ view->details->toolbar_menu_sections->zoom_section = g_object_ref_sink (gtk_builder_get_object (builder, "zoom_section"));
+ view->details->toolbar_menu_sections->extended_section = g_object_ref_sink (gtk_builder_get_object (builder, "extended_section"));
+ view->details->zoom_controls_box = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_controls_box"));
+ view->details->zoom_level_label = GTK_WIDGET (gtk_builder_get_object (builder, "zoom_level_label"));
+
+ view->details->sort_menu = GTK_WIDGET (gtk_builder_get_object (builder, "sort_menu"));
+ view->details->sort_trash_time = GTK_WIDGET (gtk_builder_get_object (builder, "sort_trash_time"));
+ view->details->visible_columns = GTK_WIDGET (gtk_builder_get_object (builder, "visible_columns"));
+ view->details->reload = GTK_WIDGET (gtk_builder_get_object (builder, "reload"));
+ view->details->stop = GTK_WIDGET (gtk_builder_get_object (builder, "stop"));
+
+ g_signal_connect (view,
+ "end-file-changes",
+ G_CALLBACK (on_end_file_changes),
+ view);
+
+ g_object_unref (builder);
+
+ /* Main widgets */
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (view), GTK_ORIENTATION_VERTICAL);
+ view->details->overlay = gtk_overlay_new ();
+ gtk_widget_set_vexpand (view->details->overlay, TRUE);
+ gtk_widget_set_hexpand (view->details->overlay, TRUE);
+ gtk_container_add (GTK_CONTAINER (view), view->details->overlay);
+ gtk_widget_show (view->details->overlay);
+
+ /* NautilusFloatingBar listen to its parent's 'enter-notify-event' signal
+ * and GtkOverlay doesn't have it enabled by default, so we have to add them
+ * here.
+ */
+ gtk_widget_add_events (GTK_WIDGET (view->details->overlay),
+ GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
+
+ /* Scrolled Window */
+ view->details->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view->details->scrolled_window),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_widget_show (view->details->scrolled_window);
+
+ g_signal_connect_swapped (view->details->scrolled_window,
+ "scroll-event",
+ G_CALLBACK (nautilus_files_view_scroll_event),
+ view);
+
+ gtk_container_add (GTK_CONTAINER (view->details->overlay), view->details->scrolled_window);
+
+ /* Empty states */
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-no-search-results.ui");
+ view->details->no_search_results_widget = GTK_WIDGET (gtk_builder_get_object (builder, "no_search_results"));
+ gtk_overlay_add_overlay (GTK_OVERLAY (view->details->overlay), view->details->no_search_results_widget);
+ gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (view->details->overlay),
+ view->details->no_search_results_widget,
+ TRUE);
+ g_object_unref (builder);
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-folder-is-empty.ui");
+ view->details->folder_is_empty_widget = GTK_WIDGET (gtk_builder_get_object (builder, "folder_is_empty"));
+ gtk_overlay_add_overlay (GTK_OVERLAY (view->details->overlay), view->details->folder_is_empty_widget);
+ gtk_overlay_set_overlay_pass_through (GTK_OVERLAY (view->details->overlay),
+ view->details->folder_is_empty_widget,
+ TRUE);
+ g_object_unref (builder);
+
+ /* Floating bar */
+ view->details->floating_bar = nautilus_floating_bar_new (NULL, NULL, FALSE);
+ gtk_widget_set_halign (view->details->floating_bar, GTK_ALIGN_END);
+ gtk_widget_set_valign (view->details->floating_bar, GTK_ALIGN_END);
+ gtk_overlay_add_overlay (GTK_OVERLAY (view->details->overlay), view->details->floating_bar);
+
+ g_signal_connect (view->details->floating_bar,
+ "action",
+ G_CALLBACK (floating_bar_action_cb),
+ view);
+
+ /* Default to true; desktop-icon-view sets to false */
+ view->details->show_foreign_files = TRUE;
+
+ view->details->non_ready_files =
+ g_hash_table_new_full (file_and_directory_hash,
+ file_and_directory_equal,
+ (GDestroyNotify) file_and_directory_free,
+ NULL);
+
+ view->details->pending_reveal = g_hash_table_new (NULL, NULL);
+
+ gtk_style_context_set_junction_sides (gtk_widget_get_style_context (GTK_WIDGET (view)),
+ GTK_JUNCTION_TOP | GTK_JUNCTION_LEFT);
+
+ if (set_up_scripts_directory_global ())
+ {
+ scripts_directory = nautilus_directory_get_by_uri (scripts_directory_uri);
+ add_directory_to_scripts_directory_list (view, scripts_directory);
+ nautilus_directory_unref (scripts_directory);
+ }
+ else
+ {
+ g_warning ("Ignoring scripts directory, it may be a broken link\n");
+ }
+
+ if (nautilus_should_use_templates_directory ())
+ {
+ templates_uri = nautilus_get_templates_directory_uri ();
+ templates_directory = nautilus_directory_get_by_uri (templates_uri);
+ g_free (templates_uri);
+ add_directory_to_templates_directory_list (view, templates_directory);
+ nautilus_directory_unref (templates_directory);
+ }
+ update_templates_directory (view);
+
+ view->details->sort_directories_first =
+ g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+ view->details->show_hidden_files =
+ g_settings_get_boolean (gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
+
+ g_signal_connect_object (nautilus_trash_monitor_get (), "trash-state-changed",
+ G_CALLBACK (nautilus_files_view_trash_state_changed_callback), view, 0);
+
+ /* React to clipboard changes */
+ g_signal_connect_object (nautilus_clipboard_monitor_get (), "clipboard-changed",
+ G_CALLBACK (clipboard_changed_callback), view, 0);
+
+ /* Register to menu provider extension signal managing menu updates */
+ g_signal_connect_object (nautilus_signaller_get_current (), "popup-menu-changed",
+ G_CALLBACK (schedule_update_context_menus), view, G_CONNECT_SWAPPED);
+
+ gtk_widget_show (GTK_WIDGET (view));
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_CLICK_POLICY,
+ G_CALLBACK (click_policy_changed_callback),
+ view);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ G_CALLBACK (sort_directories_first_changed_callback), view);
+ g_signal_connect_swapped (gtk_filechooser_preferences,
+ "changed::" NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
+ G_CALLBACK (show_hidden_files_changed_callback), view);
+ g_signal_connect_swapped (gnome_lockdown_preferences,
+ "changed::" NAUTILUS_PREFERENCES_LOCKDOWN_COMMAND_LINE,
+ G_CALLBACK (schedule_update_context_menus), view);
+
+ view->details->in_destruction = FALSE;
+
+ /* Accessibility */
+ atk_object = gtk_widget_get_accessible (GTK_WIDGET (view));
+ atk_object_set_name (atk_object, _("Content View"));
+ atk_object_set_description (atk_object, _("View of the current folder"));
+
+ view->details->view_action_group = G_ACTION_GROUP (g_simple_action_group_new ());
+ g_action_map_add_action_entries (G_ACTION_MAP (view->details->view_action_group),
+ view_entries,
+ G_N_ELEMENTS (view_entries),
+ view);
+ gtk_widget_insert_action_group (GTK_WIDGET (view),
+ "view",
+ G_ACTION_GROUP (view->details->view_action_group));
+ app = g_application_get_default ();
+
+ /* Toolbar menu */
+ nautilus_application_set_accelerators (app, "view.zoom-in", zoom_in_accels);
+ nautilus_application_set_accelerator (app, "view.zoom-out", "<control>minus");
+ nautilus_application_set_accelerator (app, "view.show-hidden-files", "<control>h");
+ /* Background menu */
+ nautilus_application_set_accelerator (app, "view.select-all", "<control>a");
+ nautilus_application_set_accelerator (app, "view.paste", "<control>v");
+ nautilus_application_set_accelerator (app, "view.create-link", "<control>m");
+ /* Selection menu */
+ nautilus_application_set_accelerators (app, "view.open-with-default-application", open_accels);
+ nautilus_application_set_accelerator (app, "view.open-item-new-tab", "<shift><control>t");
+ nautilus_application_set_accelerator (app, "view.open-item-new-window", "<shift><control>w");
+ nautilus_application_set_accelerator (app, "view.move-to-trash", "Delete");
+ nautilus_application_set_accelerator (app, "view.delete-from-trash", "Delete");
+ nautilus_application_set_accelerator (app, "view.delete-permanently-shortcut", "<shift>Delete");
+ /* When trash is not available, allow the "Delete" key to delete permanently, that is, when
+ * the menu item is available, since we never make both the trash and delete-permanently-menu-item
+ * actions active */
+ nautilus_application_set_accelerator (app, "view.delete-permanently-menu-item", "Delete");
+ nautilus_application_set_accelerator (app, "view.permanent-delete-permanently-menu-item", "<shift>Delete");
+ nautilus_application_set_accelerators (app, "view.properties", open_properties);
+ nautilus_application_set_accelerator (app, "view.open-item-location", "<control><alt>o");
+ nautilus_application_set_accelerator (app, "view.rename", "F2");
+ nautilus_application_set_accelerator (app, "view.cut", "<control>x");
+ nautilus_application_set_accelerator (app, "view.copy", "<control>c");
+ nautilus_application_set_accelerator (app, "view.create-link-in-place", "<control><shift>m");
+ nautilus_application_set_accelerator (app, "view.new-folder", "<control><shift>n");
+ /* Only accesible by shorcuts */
+ nautilus_application_set_accelerator (app, "view.select-pattern", "<control>s");
+ nautilus_application_set_accelerator (app, "view.zoom-standard", "<control>0");
+ nautilus_application_set_accelerator (app, "view.invert-selection", "<shift><control>i");
+ nautilus_application_set_accelerator (app, "view.open-file-and-close-window", "<control><shift>Down");
+
+ /* Show a warning dialog to inform the user that the shorcut for move to trash
+ * changed */
+ nautilus_application_set_accelerator (app, "view.show-move-to-trash-shortcut-changed-dialog", "<control>Delete");
+
+ nautilus_profile_end (NULL);
}
NautilusFilesView *
-nautilus_files_view_new (guint id,
+nautilus_files_view_new (guint id,
NautilusWindowSlot *slot)
{
- NautilusFilesView *view = NULL;
+ NautilusFilesView *view = NULL;
- switch (id) {
+ switch (id)
+ {
case NAUTILUS_VIEW_GRID_ID:
+ {
view = nautilus_canvas_view_new (slot);
- break;
+ }
+ break;
+
case NAUTILUS_VIEW_LIST_ID:
+ {
view = nautilus_list_view_new (slot);
- break;
+ }
+ break;
+
#if ENABLE_EMPTY_VIEW
case NAUTILUS_VIEW_EMPTY_ID:
+ {
view = nautilus_empty_view_new (slot);
- break;
+ }
+ break;
#endif
- }
-
- if (view == NULL) {
- g_critical ("Unknown view type ID: %d", id);
- } else if (g_object_is_floating (view)) {
- g_object_ref_sink (view);
- }
-
- return view;
+ }
+
+ if (view == NULL)
+ {
+ g_critical ("Unknown view type ID: %d", id);
+ }
+ else if (g_object_is_floating (view))
+ {
+ g_object_ref_sink (view);
+ }
+
+ return view;
}
diff --git a/src/nautilus-floating-bar.c b/src/nautilus-floating-bar.c
index 97c223a7d..dc866c013 100644
--- a/src/nautilus-floating-bar.c
+++ b/src/nautilus-floating-bar.c
@@ -1,4 +1,3 @@
-
/* Nautilus - Floating status bar.
*
* Copyright (C) 2011 Red Hat Inc.
@@ -28,28 +27,31 @@
#define HOVER_HIDE_TIMEOUT_INTERVAL 100
-struct _NautilusFloatingBarDetails {
- gchar *primary_label;
- gchar *details_label;
-
- GtkWidget *primary_label_widget;
- GtkWidget *details_label_widget;
- GtkWidget *spinner;
- gboolean show_spinner;
- gboolean is_interactive;
- guint hover_timeout_id;
+struct _NautilusFloatingBarDetails
+{
+ gchar *primary_label;
+ gchar *details_label;
+
+ GtkWidget *primary_label_widget;
+ GtkWidget *details_label_widget;
+ GtkWidget *spinner;
+ gboolean show_spinner;
+ gboolean is_interactive;
+ guint hover_timeout_id;
};
-enum {
- PROP_PRIMARY_LABEL = 1,
- PROP_DETAILS_LABEL,
- PROP_SHOW_SPINNER,
- NUM_PROPERTIES
+enum
+{
+ PROP_PRIMARY_LABEL = 1,
+ PROP_DETAILS_LABEL,
+ PROP_SHOW_SPINNER,
+ NUM_PROPERTIES
};
-enum {
- ACTION,
- NUM_SIGNALS
+enum
+{
+ ACTION,
+ NUM_SIGNALS
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
@@ -59,509 +61,547 @@ G_DEFINE_TYPE (NautilusFloatingBar, nautilus_floating_bar,
GTK_TYPE_BOX);
static void
-action_button_clicked_cb (GtkButton *button,
- NautilusFloatingBar *self)
+action_button_clicked_cb (GtkButton *button,
+ NautilusFloatingBar *self)
{
- gint action_id;
+ gint action_id;
- action_id = GPOINTER_TO_INT
- (g_object_get_data (G_OBJECT (button), "action-id"));
-
- g_signal_emit (self, signals[ACTION], 0, action_id);
+ action_id = GPOINTER_TO_INT
+ (g_object_get_data (G_OBJECT (button), "action-id"));
+
+ g_signal_emit (self, signals[ACTION], 0, action_id);
}
static void
nautilus_floating_bar_finalize (GObject *obj)
{
- NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj);
+ NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj);
- nautilus_floating_bar_remove_hover_timeout (self);
- g_free (self->priv->primary_label);
- g_free (self->priv->details_label);
+ nautilus_floating_bar_remove_hover_timeout (self);
+ g_free (self->priv->primary_label);
+ g_free (self->priv->details_label);
- G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->finalize (obj);
}
static void
-nautilus_floating_bar_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_floating_bar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (object);
-
- switch (property_id) {
- case PROP_PRIMARY_LABEL:
- g_value_set_string (value, self->priv->primary_label);
- break;
- case PROP_DETAILS_LABEL:
- g_value_set_string (value, self->priv->details_label);
- break;
- case PROP_SHOW_SPINNER:
- g_value_set_boolean (value, self->priv->show_spinner);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (object);
+
+ switch (property_id)
+ {
+ case PROP_PRIMARY_LABEL:
+ {
+ g_value_set_string (value, self->priv->primary_label);
+ }
+ break;
+
+ case PROP_DETAILS_LABEL:
+ {
+ g_value_set_string (value, self->priv->details_label);
+ }
+ break;
+
+ case PROP_SHOW_SPINNER:
+ {
+ g_value_set_boolean (value, self->priv->show_spinner);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_floating_bar_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_floating_bar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (object);
-
- switch (property_id) {
- case PROP_PRIMARY_LABEL:
- nautilus_floating_bar_set_primary_label (self, g_value_get_string (value));
- break;
- case PROP_DETAILS_LABEL:
- nautilus_floating_bar_set_details_label (self, g_value_get_string (value));
- break;
- case PROP_SHOW_SPINNER:
- nautilus_floating_bar_set_show_spinner (self, g_value_get_boolean (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (object);
+
+ switch (property_id)
+ {
+ case PROP_PRIMARY_LABEL:
+ {
+ nautilus_floating_bar_set_primary_label (self, g_value_get_string (value));
+ }
+ break;
+
+ case PROP_DETAILS_LABEL:
+ {
+ nautilus_floating_bar_set_details_label (self, g_value_get_string (value));
+ }
+ break;
+
+ case PROP_SHOW_SPINNER:
+ {
+ nautilus_floating_bar_set_show_spinner (self, g_value_get_boolean (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
update_labels (NautilusFloatingBar *self)
{
- gboolean primary_visible, details_visible;
+ gboolean primary_visible, details_visible;
- primary_visible = (self->priv->primary_label != NULL) &&
- (strlen (self->priv->primary_label) > 0);
- details_visible = (self->priv->details_label != NULL) &&
- (strlen (self->priv->details_label) > 0);
+ primary_visible = (self->priv->primary_label != NULL) &&
+ (strlen (self->priv->primary_label) > 0);
+ details_visible = (self->priv->details_label != NULL) &&
+ (strlen (self->priv->details_label) > 0);
- gtk_label_set_text (GTK_LABEL (self->priv->primary_label_widget),
- self->priv->primary_label);
- gtk_widget_set_visible (self->priv->primary_label_widget, primary_visible);
+ gtk_label_set_text (GTK_LABEL (self->priv->primary_label_widget),
+ self->priv->primary_label);
+ gtk_widget_set_visible (self->priv->primary_label_widget, primary_visible);
- gtk_label_set_text (GTK_LABEL (self->priv->details_label_widget),
- self->priv->details_label);
- gtk_widget_set_visible (self->priv->details_label_widget, details_visible);
+ gtk_label_set_text (GTK_LABEL (self->priv->details_label_widget),
+ self->priv->details_label);
+ gtk_widget_set_visible (self->priv->details_label_widget, details_visible);
}
void
nautilus_floating_bar_remove_hover_timeout (NautilusFloatingBar *self)
{
- if (self->priv->hover_timeout_id != 0) {
- g_source_remove (self->priv->hover_timeout_id);
- self->priv->hover_timeout_id = 0;
- }
+ if (self->priv->hover_timeout_id != 0)
+ {
+ g_source_remove (self->priv->hover_timeout_id);
+ self->priv->hover_timeout_id = 0;
+ }
}
-typedef struct {
- GtkWidget *overlay;
- GtkWidget *floating_bar;
- GdkDevice *device;
- gint y_down_limit;
- gint y_upper_limit;
+typedef struct
+{
+ GtkWidget *overlay;
+ GtkWidget *floating_bar;
+ GdkDevice *device;
+ gint y_down_limit;
+ gint y_upper_limit;
} CheckPointerData;
static void
check_pointer_data_free (gpointer data)
{
- g_slice_free (CheckPointerData, data);
+ g_slice_free (CheckPointerData, data);
}
static gboolean
check_pointer_timeout (gpointer user_data)
{
- CheckPointerData *data = user_data;
- gint pointer_y = -1;
+ CheckPointerData *data = user_data;
+ gint pointer_y = -1;
- gdk_window_get_device_position (gtk_widget_get_window (data->overlay), data->device,
- NULL, &pointer_y, NULL);
+ gdk_window_get_device_position (gtk_widget_get_window (data->overlay), data->device,
+ NULL, &pointer_y, NULL);
- if (pointer_y == -1 || pointer_y < data->y_down_limit || pointer_y > data->y_upper_limit) {
- gtk_widget_show (data->floating_bar);
- NAUTILUS_FLOATING_BAR (data->floating_bar)->priv->hover_timeout_id = 0;
+ if (pointer_y == -1 || pointer_y < data->y_down_limit || pointer_y > data->y_upper_limit)
+ {
+ gtk_widget_show (data->floating_bar);
+ NAUTILUS_FLOATING_BAR (data->floating_bar)->priv->hover_timeout_id = 0;
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
+ }
+ else
+ {
+ gtk_widget_hide (data->floating_bar);
+ }
- } else {
- gtk_widget_hide (data->floating_bar);
- }
-
- return G_SOURCE_CONTINUE;
+ return G_SOURCE_CONTINUE;
}
static gboolean
overlay_enter_notify_cb (GtkWidget *parent,
- GdkEventCrossing *event,
- gpointer user_data)
+ GdkEventCrossing *event,
+ gpointer user_data)
{
- GtkWidget *widget = user_data;
- CheckPointerData *data;
- GtkAllocation alloc_parent;
- gint y_pos;
+ GtkWidget *widget = user_data;
+ CheckPointerData *data;
+ GtkAllocation alloc_parent;
+ gint y_pos;
- NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
+ NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
- if (self->priv->hover_timeout_id != 0) {
- g_source_remove (self->priv->hover_timeout_id);
- }
+ if (self->priv->hover_timeout_id != 0)
+ {
+ g_source_remove (self->priv->hover_timeout_id);
+ }
- if (event->window != gtk_widget_get_window (widget)) {
- return GDK_EVENT_PROPAGATE;
- }
+ if (event->window != gtk_widget_get_window (widget))
+ {
+ return GDK_EVENT_PROPAGATE;
+ }
- if (NAUTILUS_FLOATING_BAR (widget)->priv->is_interactive) {
- return GDK_EVENT_PROPAGATE;
- }
+ if (NAUTILUS_FLOATING_BAR (widget)->priv->is_interactive)
+ {
+ return GDK_EVENT_PROPAGATE;
+ }
- gtk_widget_get_allocation (parent, &alloc_parent);
- gdk_window_get_position (gtk_widget_get_window (widget), NULL, &y_pos);
+ gtk_widget_get_allocation (parent, &alloc_parent);
+ gdk_window_get_position (gtk_widget_get_window (widget), NULL, &y_pos);
- data = g_slice_new (CheckPointerData);
- data->overlay = parent;
- data->floating_bar = widget;
- data->device = gdk_event_get_device ((GdkEvent *) event);
- data->y_down_limit = y_pos;
- data->y_upper_limit = alloc_parent.height;
+ data = g_slice_new (CheckPointerData);
+ data->overlay = parent;
+ data->floating_bar = widget;
+ data->device = gdk_event_get_device ((GdkEvent *) event);
+ data->y_down_limit = y_pos;
+ data->y_upper_limit = alloc_parent.height;
- self->priv->hover_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, HOVER_HIDE_TIMEOUT_INTERVAL,
- check_pointer_timeout, data,
- check_pointer_data_free);
+ self->priv->hover_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, HOVER_HIDE_TIMEOUT_INTERVAL,
+ check_pointer_timeout, data,
+ check_pointer_data_free);
- g_source_set_name_by_id (self->priv->hover_timeout_id, "[nautilus-floating-bar] overlay_enter_notify_cb");
+ g_source_set_name_by_id (self->priv->hover_timeout_id, "[nautilus-floating-bar] overlay_enter_notify_cb");
- return GDK_EVENT_STOP;
+ return GDK_EVENT_STOP;
}
static void
nautilus_floating_bar_parent_set (GtkWidget *widget,
- GtkWidget *old_parent)
+ GtkWidget *old_parent)
{
- GtkWidget *parent;
+ GtkWidget *parent;
- parent = gtk_widget_get_parent (widget);
+ parent = gtk_widget_get_parent (widget);
- if (old_parent != NULL) {
- g_signal_handlers_disconnect_by_func (old_parent,
- overlay_enter_notify_cb, widget);
- }
+ if (old_parent != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (old_parent,
+ overlay_enter_notify_cb, widget);
+ }
- if (parent != NULL) {
- g_signal_connect (parent, "enter-notify-event",
- G_CALLBACK (overlay_enter_notify_cb), widget);
- }
+ if (parent != NULL)
+ {
+ g_signal_connect (parent, "enter-notify-event",
+ G_CALLBACK (overlay_enter_notify_cb), widget);
+ }
}
static void
get_padding_and_border (GtkWidget *widget,
GtkBorder *border)
{
- GtkStyleContext *context;
- GtkStateFlags state;
- GtkBorder tmp;
-
- context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
-
- gtk_style_context_get_padding (context, state, border);
- gtk_style_context_get_border (context, state, &tmp);
- border->top += tmp.top;
- border->right += tmp.right;
- border->bottom += tmp.bottom;
- border->left += tmp.left;
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder tmp;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_widget_get_state_flags (widget);
+
+ gtk_style_context_get_padding (context, state, border);
+ gtk_style_context_get_border (context, state, &tmp);
+ border->top += tmp.top;
+ border->right += tmp.right;
+ border->bottom += tmp.bottom;
+ border->left += tmp.left;
}
static void
nautilus_floating_bar_get_preferred_width (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
+ gint *minimum_size,
+ gint *natural_size)
{
- GtkBorder border;
+ GtkBorder border;
- get_padding_and_border (widget, &border);
+ get_padding_and_border (widget, &border);
- GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_width (widget,
- minimum_size,
- natural_size);
+ GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_width (widget,
+ minimum_size,
+ natural_size);
- *minimum_size += border.left + border.right;
- *natural_size += border.left + border.right;
+ *minimum_size += border.left + border.right;
+ *natural_size += border.left + border.right;
}
static void
nautilus_floating_bar_get_preferred_width_for_height (GtkWidget *widget,
- gint height,
- gint *minimum_size,
- gint *natural_size)
+ gint height,
+ gint *minimum_size,
+ gint *natural_size)
{
- GtkBorder border;
+ GtkBorder border;
- get_padding_and_border (widget, &border);
+ get_padding_and_border (widget, &border);
- GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_width_for_height (widget,
- height,
- minimum_size,
- natural_size);
+ GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_width_for_height (widget,
+ height,
+ minimum_size,
+ natural_size);
- *minimum_size += border.left + border.right;
- *natural_size += border.left + border.right;
+ *minimum_size += border.left + border.right;
+ *natural_size += border.left + border.right;
}
static void
nautilus_floating_bar_get_preferred_height (GtkWidget *widget,
- gint *minimum_size,
- gint *natural_size)
+ gint *minimum_size,
+ gint *natural_size)
{
- GtkBorder border;
+ GtkBorder border;
- get_padding_and_border (widget, &border);
+ get_padding_and_border (widget, &border);
- GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_height (widget,
- minimum_size,
- natural_size);
+ GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_height (widget,
+ minimum_size,
+ natural_size);
- *minimum_size += border.top + border.bottom;
- *natural_size += border.top + border.bottom;
+ *minimum_size += border.top + border.bottom;
+ *natural_size += border.top + border.bottom;
}
static void
nautilus_floating_bar_get_preferred_height_for_width (GtkWidget *widget,
- gint width,
- gint *minimum_size,
- gint *natural_size)
+ gint width,
+ gint *minimum_size,
+ gint *natural_size)
{
- GtkBorder border;
+ GtkBorder border;
- get_padding_and_border (widget, &border);
+ get_padding_and_border (widget, &border);
- GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_height_for_width (widget,
- width,
- minimum_size,
- natural_size);
+ GTK_WIDGET_CLASS (nautilus_floating_bar_parent_class)->get_preferred_height_for_width (widget,
+ width,
+ minimum_size,
+ natural_size);
- *minimum_size += border.top + border.bottom;
- *natural_size += border.top + border.bottom;
+ *minimum_size += border.top + border.bottom;
+ *natural_size += border.top + border.bottom;
}
static void
nautilus_floating_bar_constructed (GObject *obj)
{
- NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj);
- GtkWidget *w, *box, *labels_box;
-
- G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->constructed (obj);
-
- box = GTK_WIDGET (obj);
-
- w = gtk_spinner_new ();
- gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
- gtk_widget_set_visible (w, self->priv->show_spinner);
- gtk_spinner_start (GTK_SPINNER (w));
- self->priv->spinner = w;
-
- gtk_widget_set_size_request (w, 16, 16);
- gtk_widget_set_margin_start (w, 8);
-
- labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_box_pack_start (GTK_BOX (box), labels_box, TRUE, TRUE, 0);
- g_object_set (labels_box,
- "margin-top", 2,
- "margin-bottom", 2,
- "margin-start", 12,
- "margin-end", 12,
- NULL);
- gtk_widget_show (labels_box);
-
- w = gtk_label_new (NULL);
- gtk_label_set_ellipsize (GTK_LABEL (w), PANGO_ELLIPSIZE_MIDDLE);
- gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
- gtk_container_add (GTK_CONTAINER (labels_box), w);
- self->priv->primary_label_widget = w;
- gtk_widget_show (w);
-
- w = gtk_label_new (NULL);
- gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
- gtk_container_add (GTK_CONTAINER (labels_box), w);
- self->priv->details_label_widget = w;
- gtk_widget_show (w);
+ NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj);
+ GtkWidget *w, *box, *labels_box;
+
+ G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->constructed (obj);
+
+ box = GTK_WIDGET (obj);
+
+ w = gtk_spinner_new ();
+ gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
+ gtk_widget_set_visible (w, self->priv->show_spinner);
+ gtk_spinner_start (GTK_SPINNER (w));
+ self->priv->spinner = w;
+
+ gtk_widget_set_size_request (w, 16, 16);
+ gtk_widget_set_margin_start (w, 8);
+
+ labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_box_pack_start (GTK_BOX (box), labels_box, TRUE, TRUE, 0);
+ g_object_set (labels_box,
+ "margin-top", 2,
+ "margin-bottom", 2,
+ "margin-start", 12,
+ "margin-end", 12,
+ NULL);
+ gtk_widget_show (labels_box);
+
+ w = gtk_label_new (NULL);
+ gtk_label_set_ellipsize (GTK_LABEL (w), PANGO_ELLIPSIZE_MIDDLE);
+ gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
+ gtk_container_add (GTK_CONTAINER (labels_box), w);
+ self->priv->primary_label_widget = w;
+ gtk_widget_show (w);
+
+ w = gtk_label_new (NULL);
+ gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
+ gtk_container_add (GTK_CONTAINER (labels_box), w);
+ self->priv->details_label_widget = w;
+ gtk_widget_show (w);
}
static void
nautilus_floating_bar_init (NautilusFloatingBar *self)
{
- GtkStyleContext *context;
+ GtkStyleContext *context;
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_FLOATING_BAR,
- NautilusFloatingBarDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_FLOATING_BAR,
+ NautilusFloatingBarDetails);
- context = gtk_widget_get_style_context (GTK_WIDGET (self));
- gtk_style_context_add_class (context, "floating-bar");
+ context = gtk_widget_get_style_context (GTK_WIDGET (self));
+ gtk_style_context_add_class (context, "floating-bar");
}
static void
nautilus_floating_bar_class_init (NautilusFloatingBarClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
-
- oclass->constructed = nautilus_floating_bar_constructed;
- oclass->set_property = nautilus_floating_bar_set_property;
- oclass->get_property = nautilus_floating_bar_get_property;
- oclass->finalize = nautilus_floating_bar_finalize;
-
- wclass->get_preferred_width = nautilus_floating_bar_get_preferred_width;
- wclass->get_preferred_width_for_height = nautilus_floating_bar_get_preferred_width_for_height;
- wclass->get_preferred_height = nautilus_floating_bar_get_preferred_height;
- wclass->get_preferred_height_for_width = nautilus_floating_bar_get_preferred_height_for_width;
- wclass->parent_set = nautilus_floating_bar_parent_set;
-
- properties[PROP_PRIMARY_LABEL] =
- g_param_spec_string ("primary-label",
- "Bar's primary label",
- "Primary label displayed by the bar",
- NULL,
- G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
- properties[PROP_DETAILS_LABEL] =
- g_param_spec_string ("details-label",
- "Bar's details label",
- "Details label displayed by the bar",
- NULL,
- G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
- properties[PROP_SHOW_SPINNER] =
- g_param_spec_boolean ("show-spinner",
- "Show spinner",
- "Whether a spinner should be shown in the floating bar",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- signals[ACTION] =
- g_signal_new ("action",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE, 1,
- G_TYPE_INT);
-
- g_type_class_add_private (klass, sizeof (NautilusFloatingBarDetails));
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
+
+ oclass->constructed = nautilus_floating_bar_constructed;
+ oclass->set_property = nautilus_floating_bar_set_property;
+ oclass->get_property = nautilus_floating_bar_get_property;
+ oclass->finalize = nautilus_floating_bar_finalize;
+
+ wclass->get_preferred_width = nautilus_floating_bar_get_preferred_width;
+ wclass->get_preferred_width_for_height = nautilus_floating_bar_get_preferred_width_for_height;
+ wclass->get_preferred_height = nautilus_floating_bar_get_preferred_height;
+ wclass->get_preferred_height_for_width = nautilus_floating_bar_get_preferred_height_for_width;
+ wclass->parent_set = nautilus_floating_bar_parent_set;
+
+ properties[PROP_PRIMARY_LABEL] =
+ g_param_spec_string ("primary-label",
+ "Bar's primary label",
+ "Primary label displayed by the bar",
+ NULL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
+ properties[PROP_DETAILS_LABEL] =
+ g_param_spec_string ("details-label",
+ "Bar's details label",
+ "Details label displayed by the bar",
+ NULL,
+ G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS);
+ properties[PROP_SHOW_SPINNER] =
+ g_param_spec_boolean ("show-spinner",
+ "Show spinner",
+ "Whether a spinner should be shown in the floating bar",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ signals[ACTION] =
+ g_signal_new ("action",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__INT,
+ G_TYPE_NONE, 1,
+ G_TYPE_INT);
+
+ g_type_class_add_private (klass, sizeof (NautilusFloatingBarDetails));
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
void
nautilus_floating_bar_set_primary_label (NautilusFloatingBar *self,
- const gchar *label)
+ const gchar *label)
{
- if (g_strcmp0 (self->priv->primary_label, label) != 0) {
- g_free (self->priv->primary_label);
- self->priv->primary_label = g_strdup (label);
+ if (g_strcmp0 (self->priv->primary_label, label) != 0)
+ {
+ g_free (self->priv->primary_label);
+ self->priv->primary_label = g_strdup (label);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PRIMARY_LABEL]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PRIMARY_LABEL]);
- update_labels (self);
- }
+ update_labels (self);
+ }
}
void
nautilus_floating_bar_set_details_label (NautilusFloatingBar *self,
- const gchar *label)
+ const gchar *label)
{
- if (g_strcmp0 (self->priv->details_label, label) != 0) {
- g_free (self->priv->details_label);
- self->priv->details_label = g_strdup (label);
+ if (g_strcmp0 (self->priv->details_label, label) != 0)
+ {
+ g_free (self->priv->details_label);
+ self->priv->details_label = g_strdup (label);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DETAILS_LABEL]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DETAILS_LABEL]);
- update_labels (self);
- }
+ update_labels (self);
+ }
}
void
nautilus_floating_bar_set_labels (NautilusFloatingBar *self,
- const gchar *primary_label,
- const gchar *details_label)
+ const gchar *primary_label,
+ const gchar *details_label)
{
- nautilus_floating_bar_set_primary_label (self, primary_label);
- nautilus_floating_bar_set_details_label (self, details_label);
+ nautilus_floating_bar_set_primary_label (self, primary_label);
+ nautilus_floating_bar_set_details_label (self, details_label);
}
void
nautilus_floating_bar_set_show_spinner (NautilusFloatingBar *self,
- gboolean show_spinner)
+ gboolean show_spinner)
{
- if (self->priv->show_spinner != show_spinner) {
- self->priv->show_spinner = show_spinner;
- gtk_widget_set_visible (self->priv->spinner,
- show_spinner);
-
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SPINNER]);
- }
+ if (self->priv->show_spinner != show_spinner)
+ {
+ self->priv->show_spinner = show_spinner;
+ gtk_widget_set_visible (self->priv->spinner,
+ show_spinner);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SPINNER]);
+ }
}
GtkWidget *
nautilus_floating_bar_new (const gchar *primary_label,
- const gchar *details_label,
- gboolean show_spinner)
+ const gchar *details_label,
+ gboolean show_spinner)
{
- return g_object_new (NAUTILUS_TYPE_FLOATING_BAR,
- "primary-label", primary_label,
- "details-label", details_label,
- "show-spinner", show_spinner,
- "orientation", GTK_ORIENTATION_HORIZONTAL,
- "spacing", 8,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_FLOATING_BAR,
+ "primary-label", primary_label,
+ "details-label", details_label,
+ "show-spinner", show_spinner,
+ "orientation", GTK_ORIENTATION_HORIZONTAL,
+ "spacing", 8,
+ NULL);
}
void
nautilus_floating_bar_add_action (NautilusFloatingBar *self,
- const gchar *icon_name,
- gint action_id)
+ const gchar *icon_name,
+ gint action_id)
{
- GtkWidget *button;
- GtkStyleContext *context;
+ GtkWidget *button;
+ GtkStyleContext *context;
- button = gtk_button_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
- context = gtk_widget_get_style_context (button);
- gtk_style_context_add_class (context, "circular");
- gtk_style_context_add_class (context, "flat");
- gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
- gtk_box_pack_end (GTK_BOX (self), button, FALSE, FALSE, 0);
- gtk_widget_show (button);
+ button = gtk_button_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ context = gtk_widget_get_style_context (button);
+ gtk_style_context_add_class (context, "circular");
+ gtk_style_context_add_class (context, "flat");
+ gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
+ gtk_box_pack_end (GTK_BOX (self), button, FALSE, FALSE, 0);
+ gtk_widget_show (button);
- g_object_set_data (G_OBJECT (button), "action-id",
- GINT_TO_POINTER (action_id));
+ g_object_set_data (G_OBJECT (button), "action-id",
+ GINT_TO_POINTER (action_id));
- g_signal_connect (button, "clicked",
- G_CALLBACK (action_button_clicked_cb), self);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (action_button_clicked_cb), self);
- self->priv->is_interactive = TRUE;
+ self->priv->is_interactive = TRUE;
}
void
nautilus_floating_bar_cleanup_actions (NautilusFloatingBar *self)
{
- GtkWidget *widget;
- GList *children, *l;
- gpointer data;
+ GtkWidget *widget;
+ GList *children, *l;
+ gpointer data;
- children = gtk_container_get_children (GTK_CONTAINER (self));
- l = children;
+ children = gtk_container_get_children (GTK_CONTAINER (self));
+ l = children;
- while (l != NULL) {
- widget = l->data;
- data = g_object_get_data (G_OBJECT (widget), "action-id");
- l = l->next;
+ while (l != NULL)
+ {
+ widget = l->data;
+ data = g_object_get_data (G_OBJECT (widget), "action-id");
+ l = l->next;
- if (data != NULL) {
- /* destroy this */
- gtk_widget_destroy (widget);
- }
- }
+ if (data != NULL)
+ {
+ /* destroy this */
+ gtk_widget_destroy (widget);
+ }
+ }
- g_list_free (children);
+ g_list_free (children);
- self->priv->is_interactive = FALSE;
+ self->priv->is_interactive = FALSE;
}
diff --git a/src/nautilus-freedesktop-dbus.c b/src/nautilus-freedesktop-dbus.c
index 7d03bc086..c4657aba3 100644
--- a/src/nautilus-freedesktop-dbus.c
+++ b/src/nautilus-freedesktop-dbus.c
@@ -32,197 +32,207 @@
#include <gio/gio.h>
-struct _NautilusFreedesktopDBus {
- GObject parent;
+struct _NautilusFreedesktopDBus
+{
+ GObject parent;
- /* Id from g_dbus_own_name() */
- guint owner_id;
+ /* Id from g_dbus_own_name() */
+ guint owner_id;
- /* Our DBus implementation skeleton */
- NautilusFreedesktopFileManager1 *skeleton;
+ /* Our DBus implementation skeleton */
+ NautilusFreedesktopFileManager1 *skeleton;
};
-struct _NautilusFreedesktopDBusClass {
- GObjectClass parent_class;
+struct _NautilusFreedesktopDBusClass
+{
+ GObjectClass parent_class;
};
G_DEFINE_TYPE (NautilusFreedesktopDBus, nautilus_freedesktop_dbus, G_TYPE_OBJECT);
static gboolean
skeleton_handle_show_items_cb (NautilusFreedesktopFileManager1 *object,
- GDBusMethodInvocation *invocation,
- const gchar *const *uris,
- const gchar *startup_id,
- gpointer data)
+ GDBusMethodInvocation *invocation,
+ const gchar * const *uris,
+ const gchar *startup_id,
+ gpointer data)
{
- NautilusApplication *application;
- int i;
+ NautilusApplication *application;
+ int i;
- application = NAUTILUS_APPLICATION (g_application_get_default ());
+ application = NAUTILUS_APPLICATION (g_application_get_default ());
- for (i = 0; uris[i] != NULL; i++) {
- GFile *file;
- GFile *parent;
+ for (i = 0; uris[i] != NULL; i++)
+ {
+ GFile *file;
+ GFile *parent;
- file = g_file_new_for_uri (uris[i]);
- parent = g_file_get_parent (file);
+ file = g_file_new_for_uri (uris[i]);
+ parent = g_file_get_parent (file);
- if (parent != NULL) {
- nautilus_application_open_location (application, parent, file, startup_id);
- g_object_unref (parent);
- } else {
- nautilus_application_open_location (application, file, NULL, startup_id);
- }
+ if (parent != NULL)
+ {
+ nautilus_application_open_location (application, parent, file, startup_id);
+ g_object_unref (parent);
+ }
+ else
+ {
+ nautilus_application_open_location (application, file, NULL, startup_id);
+ }
- g_object_unref (file);
- }
+ g_object_unref (file);
+ }
- nautilus_freedesktop_file_manager1_complete_show_items (object, invocation);
- return TRUE;
+ nautilus_freedesktop_file_manager1_complete_show_items (object, invocation);
+ return TRUE;
}
static gboolean
skeleton_handle_show_folders_cb (NautilusFreedesktopFileManager1 *object,
- GDBusMethodInvocation *invocation,
- const gchar *const *uris,
- const gchar *startup_id,
- gpointer data)
+ GDBusMethodInvocation *invocation,
+ const gchar * const *uris,
+ const gchar *startup_id,
+ gpointer data)
{
- NautilusApplication *application;
- int i;
+ NautilusApplication *application;
+ int i;
- application = NAUTILUS_APPLICATION (g_application_get_default ());
+ application = NAUTILUS_APPLICATION (g_application_get_default ());
- for (i = 0; uris[i] != NULL; i++) {
- GFile *file;
+ for (i = 0; uris[i] != NULL; i++)
+ {
+ GFile *file;
- file = g_file_new_for_uri (uris[i]);
+ file = g_file_new_for_uri (uris[i]);
- nautilus_application_open_location (application, file, NULL, startup_id);
+ nautilus_application_open_location (application, file, NULL, startup_id);
- g_object_unref (file);
- }
+ g_object_unref (file);
+ }
- nautilus_freedesktop_file_manager1_complete_show_folders (object, invocation);
- return TRUE;
+ nautilus_freedesktop_file_manager1_complete_show_folders (object, invocation);
+ return TRUE;
}
static gboolean
skeleton_handle_show_item_properties_cb (NautilusFreedesktopFileManager1 *object,
- GDBusMethodInvocation *invocation,
- const gchar *const *uris,
- const gchar *startup_id,
- gpointer data)
+ GDBusMethodInvocation *invocation,
+ const gchar * const *uris,
+ const gchar *startup_id,
+ gpointer data)
{
- GList *files;
- int i;
+ GList *files;
+ int i;
- files = NULL;
+ files = NULL;
- for (i = 0; uris[i] != NULL; i++) {
- files = g_list_prepend (files, nautilus_file_get_by_uri (uris[i]));
- }
+ for (i = 0; uris[i] != NULL; i++)
+ {
+ files = g_list_prepend (files, nautilus_file_get_by_uri (uris[i]));
+ }
- files = g_list_reverse (files);
+ files = g_list_reverse (files);
- nautilus_properties_window_present (files, NULL, startup_id);
+ nautilus_properties_window_present (files, NULL, startup_id);
- nautilus_file_list_free (files);
+ nautilus_file_list_free (files);
- nautilus_freedesktop_file_manager1_complete_show_item_properties (object, invocation);
- return TRUE;
+ nautilus_freedesktop_file_manager1_complete_show_item_properties (object, invocation);
+ return TRUE;
}
static void
bus_acquired_cb (GDBusConnection *conn,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- NautilusFreedesktopDBus *fdb = user_data;
+ NautilusFreedesktopDBus *fdb = user_data;
- DEBUG ("Bus acquired at %s", name);
+ DEBUG ("Bus acquired at %s", name);
- fdb->skeleton = nautilus_freedesktop_file_manager1_skeleton_new ();
+ fdb->skeleton = nautilus_freedesktop_file_manager1_skeleton_new ();
- g_signal_connect (fdb->skeleton, "handle-show-items",
- G_CALLBACK (skeleton_handle_show_items_cb), fdb);
- g_signal_connect (fdb->skeleton, "handle-show-folders",
- G_CALLBACK (skeleton_handle_show_folders_cb), fdb);
- g_signal_connect (fdb->skeleton, "handle-show-item-properties",
- G_CALLBACK (skeleton_handle_show_item_properties_cb), fdb);
+ g_signal_connect (fdb->skeleton, "handle-show-items",
+ G_CALLBACK (skeleton_handle_show_items_cb), fdb);
+ g_signal_connect (fdb->skeleton, "handle-show-folders",
+ G_CALLBACK (skeleton_handle_show_folders_cb), fdb);
+ g_signal_connect (fdb->skeleton, "handle-show-item-properties",
+ G_CALLBACK (skeleton_handle_show_item_properties_cb), fdb);
- g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (fdb->skeleton), conn, NAUTILUS_FDO_DBUS_PATH, NULL);
+ g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (fdb->skeleton), conn, NAUTILUS_FDO_DBUS_PATH, NULL);
}
static void
name_acquired_cb (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- DEBUG ("Acquired the name %s on the session message bus\n", name);
+ DEBUG ("Acquired the name %s on the session message bus\n", name);
}
static void
name_lost_cb (GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
- DEBUG ("Lost (or failed to acquire) the name %s on the session message bus\n", name);
+ DEBUG ("Lost (or failed to acquire) the name %s on the session message bus\n", name);
}
static void
nautilus_freedesktop_dbus_dispose (GObject *object)
{
- NautilusFreedesktopDBus *fdb = (NautilusFreedesktopDBus *) object;
-
- if (fdb->owner_id != 0) {
- g_bus_unown_name (fdb->owner_id);
- fdb->owner_id = 0;
- }
-
- if (fdb->skeleton != NULL) {
- g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (fdb->skeleton));
- g_object_unref (fdb->skeleton);
- fdb->skeleton = NULL;
- }
-
- G_OBJECT_CLASS (nautilus_freedesktop_dbus_parent_class)->dispose (object);
+ NautilusFreedesktopDBus *fdb = (NautilusFreedesktopDBus *) object;
+
+ if (fdb->owner_id != 0)
+ {
+ g_bus_unown_name (fdb->owner_id);
+ fdb->owner_id = 0;
+ }
+
+ if (fdb->skeleton != NULL)
+ {
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (fdb->skeleton));
+ g_object_unref (fdb->skeleton);
+ fdb->skeleton = NULL;
+ }
+
+ G_OBJECT_CLASS (nautilus_freedesktop_dbus_parent_class)->dispose (object);
}
static void
nautilus_freedesktop_dbus_class_init (NautilusFreedesktopDBusClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->dispose = nautilus_freedesktop_dbus_dispose;
+ object_class->dispose = nautilus_freedesktop_dbus_dispose;
}
static void
nautilus_freedesktop_dbus_init (NautilusFreedesktopDBus *fdb)
{
- fdb->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
- NAUTILUS_FDO_DBUS_NAME,
- G_BUS_NAME_OWNER_FLAGS_NONE,
- bus_acquired_cb,
- name_acquired_cb,
- name_lost_cb,
- fdb,
- NULL);
+ fdb->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ NAUTILUS_FDO_DBUS_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ bus_acquired_cb,
+ name_acquired_cb,
+ name_lost_cb,
+ fdb,
+ NULL);
}
void
-nautilus_freedesktop_dbus_set_open_locations (NautilusFreedesktopDBus *fdb,
- const gchar **locations)
+nautilus_freedesktop_dbus_set_open_locations (NautilusFreedesktopDBus *fdb,
+ const gchar **locations)
{
- g_return_if_fail (NAUTILUS_IS_FREEDESKTOP_DBUS (fdb));
+ g_return_if_fail (NAUTILUS_IS_FREEDESKTOP_DBUS (fdb));
- nautilus_freedesktop_file_manager1_set_open_locations (fdb->skeleton, locations);
+ nautilus_freedesktop_file_manager1_set_open_locations (fdb->skeleton, locations);
}
/* Tries to own the org.freedesktop.FileManager1 service name */
NautilusFreedesktopDBus *
nautilus_freedesktop_dbus_new (void)
-{
- return g_object_new (nautilus_freedesktop_dbus_get_type (),
- NULL);
+{
+ return g_object_new (nautilus_freedesktop_dbus_get_type (),
+ NULL);
}
diff --git a/src/nautilus-global-preferences.c b/src/nautilus-global-preferences.c
index efbc620d5..94326b94a 100644
--- a/src/nautilus-global-preferences.c
+++ b/src/nautilus-global-preferences.c
@@ -1,25 +1,24 @@
-
/* nautilus-global-preferences.c - Nautilus specific preference keys and
- functions.
-
- Copyright (C) 1999, 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Ramiro Estrugo <ramiro@eazel.com>
-*/
+ * functions.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Ramiro Estrugo <ramiro@eazel.com>
+ */
#include <config.h>
#include "nautilus-global-preferences.h"
@@ -48,25 +47,26 @@ GSettings *gnome_privacy_preferences;
void
nautilus_global_preferences_init (void)
{
- static gboolean initialized = FALSE;
+ static gboolean initialized = FALSE;
- if (initialized) {
- return;
- }
+ if (initialized)
+ {
+ return;
+ }
- initialized = TRUE;
+ initialized = TRUE;
- nautilus_preferences = g_settings_new("org.gnome.nautilus.preferences");
- nautilus_compression_preferences = g_settings_new ("org.gnome.nautilus.compression");
- nautilus_window_state = g_settings_new("org.gnome.nautilus.window-state");
- nautilus_icon_view_preferences = g_settings_new("org.gnome.nautilus.icon-view");
- nautilus_list_view_preferences = g_settings_new("org.gnome.nautilus.list-view");
- nautilus_desktop_preferences = g_settings_new("org.gnome.nautilus.desktop");
- /* Some settings such as show hidden files are shared between Nautilus and GTK file chooser */
- gtk_filechooser_preferences = g_settings_new_with_path ("org.gtk.Settings.FileChooser",
- "/org/gtk/settings/file-chooser/");
- gnome_lockdown_preferences = g_settings_new("org.gnome.desktop.lockdown");
- gnome_background_preferences = g_settings_new("org.gnome.desktop.background");
- gnome_interface_preferences = g_settings_new ("org.gnome.desktop.interface");
- gnome_privacy_preferences = g_settings_new ("org.gnome.desktop.privacy");
+ nautilus_preferences = g_settings_new ("org.gnome.nautilus.preferences");
+ nautilus_compression_preferences = g_settings_new ("org.gnome.nautilus.compression");
+ nautilus_window_state = g_settings_new ("org.gnome.nautilus.window-state");
+ nautilus_icon_view_preferences = g_settings_new ("org.gnome.nautilus.icon-view");
+ nautilus_list_view_preferences = g_settings_new ("org.gnome.nautilus.list-view");
+ nautilus_desktop_preferences = g_settings_new ("org.gnome.nautilus.desktop");
+ /* Some settings such as show hidden files are shared between Nautilus and GTK file chooser */
+ gtk_filechooser_preferences = g_settings_new_with_path ("org.gtk.Settings.FileChooser",
+ "/org/gtk/settings/file-chooser/");
+ gnome_lockdown_preferences = g_settings_new ("org.gnome.desktop.lockdown");
+ gnome_background_preferences = g_settings_new ("org.gnome.desktop.background");
+ gnome_interface_preferences = g_settings_new ("org.gnome.desktop.interface");
+ gnome_privacy_preferences = g_settings_new ("org.gnome.desktop.privacy");
}
diff --git a/src/nautilus-icon-info.c b/src/nautilus-icon-info.c
index 9c4bc2ad2..0a83c7411 100644
--- a/src/nautilus-icon-info.c
+++ b/src/nautilus-icon-info.c
@@ -25,555 +25,602 @@
struct _NautilusIconInfo
{
- GObject parent;
+ GObject parent;
- gboolean sole_owner;
- gint64 last_use_time;
- GdkPixbuf *pixbuf;
-
- char *icon_name;
+ gboolean sole_owner;
+ gint64 last_use_time;
+ GdkPixbuf *pixbuf;
- gint orig_scale;
+ char *icon_name;
+
+ gint orig_scale;
};
struct _NautilusIconInfoClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
static void schedule_reap_cache (void);
G_DEFINE_TYPE (NautilusIconInfo,
- nautilus_icon_info,
- G_TYPE_OBJECT);
+ nautilus_icon_info,
+ G_TYPE_OBJECT);
static void
nautilus_icon_info_init (NautilusIconInfo *icon)
{
- icon->last_use_time = g_get_monotonic_time ();
- icon->sole_owner = TRUE;
+ icon->last_use_time = g_get_monotonic_time ();
+ icon->sole_owner = TRUE;
}
gboolean
-nautilus_icon_info_is_fallback (NautilusIconInfo *icon)
+nautilus_icon_info_is_fallback (NautilusIconInfo *icon)
{
- return icon->pixbuf == NULL;
+ return icon->pixbuf == NULL;
}
static void
-pixbuf_toggle_notify (gpointer info,
- GObject *object,
- gboolean is_last_ref)
-{
- NautilusIconInfo *icon = info;
-
- if (is_last_ref) {
- icon->sole_owner = TRUE;
- g_object_remove_toggle_ref (object,
- pixbuf_toggle_notify,
- info);
- icon->last_use_time = g_get_monotonic_time ();
- schedule_reap_cache ();
- }
+pixbuf_toggle_notify (gpointer info,
+ GObject *object,
+ gboolean is_last_ref)
+{
+ NautilusIconInfo *icon = info;
+
+ if (is_last_ref)
+ {
+ icon->sole_owner = TRUE;
+ g_object_remove_toggle_ref (object,
+ pixbuf_toggle_notify,
+ info);
+ icon->last_use_time = g_get_monotonic_time ();
+ schedule_reap_cache ();
+ }
}
static void
nautilus_icon_info_finalize (GObject *object)
{
- NautilusIconInfo *icon;
+ NautilusIconInfo *icon;
- icon = NAUTILUS_ICON_INFO (object);
+ icon = NAUTILUS_ICON_INFO (object);
- if (!icon->sole_owner && icon->pixbuf) {
- g_object_remove_toggle_ref (G_OBJECT (icon->pixbuf),
- pixbuf_toggle_notify,
- icon);
- }
+ if (!icon->sole_owner && icon->pixbuf)
+ {
+ g_object_remove_toggle_ref (G_OBJECT (icon->pixbuf),
+ pixbuf_toggle_notify,
+ icon);
+ }
- if (icon->pixbuf) {
- g_object_unref (icon->pixbuf);
- }
- g_free (icon->icon_name);
+ if (icon->pixbuf)
+ {
+ g_object_unref (icon->pixbuf);
+ }
+ g_free (icon->icon_name);
- G_OBJECT_CLASS (nautilus_icon_info_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_icon_info_parent_class)->finalize (object);
}
static void
nautilus_icon_info_class_init (NautilusIconInfoClass *icon_info_class)
{
- GObjectClass *gobject_class;
-
- gobject_class = (GObjectClass *) icon_info_class;
+ GObjectClass *gobject_class;
- gobject_class->finalize = nautilus_icon_info_finalize;
+ gobject_class = (GObjectClass *) icon_info_class;
+ gobject_class->finalize = nautilus_icon_info_finalize;
}
NautilusIconInfo *
nautilus_icon_info_new_for_pixbuf (GdkPixbuf *pixbuf,
- gint scale)
+ gint scale)
{
- NautilusIconInfo *icon;
+ NautilusIconInfo *icon;
- icon = g_object_new (NAUTILUS_TYPE_ICON_INFO, NULL);
+ icon = g_object_new (NAUTILUS_TYPE_ICON_INFO, NULL);
- if (pixbuf) {
- icon->pixbuf = g_object_ref (pixbuf);
- }
+ if (pixbuf)
+ {
+ icon->pixbuf = g_object_ref (pixbuf);
+ }
- icon->orig_scale = scale;
-
- return icon;
+ icon->orig_scale = scale;
+
+ return icon;
}
static NautilusIconInfo *
nautilus_icon_info_new_for_icon_info (GtkIconInfo *icon_info,
- gint scale)
+ gint scale)
{
- NautilusIconInfo *icon;
- const char *filename;
- char *basename, *p;
-
- icon = g_object_new (NAUTILUS_TYPE_ICON_INFO, NULL);
-
- icon->pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+ NautilusIconInfo *icon;
+ const char *filename;
+ char *basename, *p;
+
+ icon = g_object_new (NAUTILUS_TYPE_ICON_INFO, NULL);
+
+ icon->pixbuf = gtk_icon_info_load_icon (icon_info, NULL);
+
+ filename = gtk_icon_info_get_filename (icon_info);
+ if (filename != NULL)
+ {
+ basename = g_path_get_basename (filename);
+ p = strrchr (basename, '.');
+ if (p)
+ {
+ *p = 0;
+ }
+ icon->icon_name = basename;
+ }
- filename = gtk_icon_info_get_filename (icon_info);
- if (filename != NULL) {
- basename = g_path_get_basename (filename);
- p = strrchr (basename, '.');
- if (p) {
- *p = 0;
- }
- icon->icon_name = basename;
- }
+ icon->orig_scale = scale;
- icon->orig_scale = scale;
-
- return icon;
+ return icon;
}
-typedef struct {
- GIcon *icon;
- int size;
+typedef struct
+{
+ GIcon *icon;
+ int size;
} LoadableIconKey;
-typedef struct {
- char *filename;
- int size;
+typedef struct
+{
+ char *filename;
+ int size;
} ThemedIconKey;
static GHashTable *loadable_icon_cache = NULL;
static GHashTable *themed_icon_cache = NULL;
static guint reap_cache_timeout = 0;
-#define MICROSEC_PER_SEC ((guint64)1000000L)
+#define MICROSEC_PER_SEC ((guint64) 1000000L)
static guint time_now;
static gboolean
-reap_old_icon (gpointer key,
- gpointer value,
- gpointer user_info)
-{
- NautilusIconInfo *icon = value;
- gboolean *reapable_icons_left = user_info;
-
- if (icon->sole_owner) {
- if (time_now - icon->last_use_time > 30 * MICROSEC_PER_SEC) {
- /* This went unused 30 secs ago. reap */
- return TRUE;
- } else {
- /* We can reap this soon */
- *reapable_icons_left = TRUE;
- }
- }
-
- return FALSE;
+reap_old_icon (gpointer key,
+ gpointer value,
+ gpointer user_info)
+{
+ NautilusIconInfo *icon = value;
+ gboolean *reapable_icons_left = user_info;
+
+ if (icon->sole_owner)
+ {
+ if (time_now - icon->last_use_time > 30 * MICROSEC_PER_SEC)
+ {
+ /* This went unused 30 secs ago. reap */
+ return TRUE;
+ }
+ else
+ {
+ /* We can reap this soon */
+ *reapable_icons_left = TRUE;
+ }
+ }
+
+ return FALSE;
}
static gboolean
reap_cache (gpointer data)
{
- gboolean reapable_icons_left;
-
- reapable_icons_left = TRUE;
-
- time_now = g_get_monotonic_time ();
-
- if (loadable_icon_cache) {
- g_hash_table_foreach_remove (loadable_icon_cache,
- reap_old_icon,
- &reapable_icons_left);
- }
-
- if (themed_icon_cache) {
- g_hash_table_foreach_remove (themed_icon_cache,
- reap_old_icon,
- &reapable_icons_left);
- }
-
- if (reapable_icons_left) {
- return TRUE;
- } else {
- reap_cache_timeout = 0;
- return FALSE;
- }
+ gboolean reapable_icons_left;
+
+ reapable_icons_left = TRUE;
+
+ time_now = g_get_monotonic_time ();
+
+ if (loadable_icon_cache)
+ {
+ g_hash_table_foreach_remove (loadable_icon_cache,
+ reap_old_icon,
+ &reapable_icons_left);
+ }
+
+ if (themed_icon_cache)
+ {
+ g_hash_table_foreach_remove (themed_icon_cache,
+ reap_old_icon,
+ &reapable_icons_left);
+ }
+
+ if (reapable_icons_left)
+ {
+ return TRUE;
+ }
+ else
+ {
+ reap_cache_timeout = 0;
+ return FALSE;
+ }
}
static void
schedule_reap_cache (void)
{
- if (reap_cache_timeout == 0) {
- reap_cache_timeout = g_timeout_add_seconds_full (0, 5,
- reap_cache,
- NULL, NULL);
- }
+ if (reap_cache_timeout == 0)
+ {
+ reap_cache_timeout = g_timeout_add_seconds_full (0, 5,
+ reap_cache,
+ NULL, NULL);
+ }
}
void
nautilus_icon_info_clear_caches (void)
{
- if (loadable_icon_cache) {
- g_hash_table_remove_all (loadable_icon_cache);
- }
-
- if (themed_icon_cache) {
- g_hash_table_remove_all (themed_icon_cache);
- }
+ if (loadable_icon_cache)
+ {
+ g_hash_table_remove_all (loadable_icon_cache);
+ }
+
+ if (themed_icon_cache)
+ {
+ g_hash_table_remove_all (themed_icon_cache);
+ }
}
static guint
loadable_icon_key_hash (LoadableIconKey *key)
{
- return g_icon_hash (key->icon) ^ key->size;
+ return g_icon_hash (key->icon) ^ key->size;
}
static gboolean
loadable_icon_key_equal (const LoadableIconKey *a,
- const LoadableIconKey *b)
+ const LoadableIconKey *b)
{
- return a->size == b->size &&
- g_icon_equal (a->icon, b->icon);
+ return a->size == b->size &&
+ g_icon_equal (a->icon, b->icon);
}
static LoadableIconKey *
-loadable_icon_key_new (GIcon *icon, int size)
+loadable_icon_key_new (GIcon *icon,
+ int size)
{
- LoadableIconKey *key;
+ LoadableIconKey *key;
- key = g_slice_new (LoadableIconKey);
- key->icon = g_object_ref (icon);
- key->size = size;
+ key = g_slice_new (LoadableIconKey);
+ key->icon = g_object_ref (icon);
+ key->size = size;
- return key;
+ return key;
}
static void
loadable_icon_key_free (LoadableIconKey *key)
{
- g_object_unref (key->icon);
- g_slice_free (LoadableIconKey, key);
+ g_object_unref (key->icon);
+ g_slice_free (LoadableIconKey, key);
}
static guint
themed_icon_key_hash (ThemedIconKey *key)
{
- return g_str_hash (key->filename) ^ key->size;
+ return g_str_hash (key->filename) ^ key->size;
}
static gboolean
themed_icon_key_equal (const ThemedIconKey *a,
- const ThemedIconKey *b)
+ const ThemedIconKey *b)
{
- return a->size == b->size &&
- g_str_equal (a->filename, b->filename);
+ return a->size == b->size &&
+ g_str_equal (a->filename, b->filename);
}
static ThemedIconKey *
-themed_icon_key_new (const char *filename, int size)
+themed_icon_key_new (const char *filename,
+ int size)
{
- ThemedIconKey *key;
+ ThemedIconKey *key;
- key = g_slice_new (ThemedIconKey);
- key->filename = g_strdup (filename);
- key->size = size;
+ key = g_slice_new (ThemedIconKey);
+ key->filename = g_strdup (filename);
+ key->size = size;
- return key;
+ return key;
}
static void
themed_icon_key_free (ThemedIconKey *key)
{
- g_free (key->filename);
- g_slice_free (ThemedIconKey, key);
+ g_free (key->filename);
+ g_slice_free (ThemedIconKey, key);
}
NautilusIconInfo *
nautilus_icon_info_lookup (GIcon *icon,
- int size,
- int scale)
-{
- NautilusIconInfo *icon_info;
- GdkPixbuf *pixbuf;
-
- if (G_IS_LOADABLE_ICON (icon)) {
- LoadableIconKey lookup_key;
- LoadableIconKey *key;
- GInputStream *stream;
-
- if (loadable_icon_cache == NULL) {
- loadable_icon_cache =
- g_hash_table_new_full ((GHashFunc)loadable_icon_key_hash,
- (GEqualFunc)loadable_icon_key_equal,
- (GDestroyNotify) loadable_icon_key_free,
- (GDestroyNotify) g_object_unref);
- }
-
- lookup_key.icon = icon;
- lookup_key.size = size;
-
- icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
- if (icon_info) {
- return g_object_ref (icon_info);
- }
-
- pixbuf = NULL;
- stream = g_loadable_icon_load (G_LOADABLE_ICON (icon),
- size * scale,
- NULL, NULL, NULL);
- if (stream) {
- pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
- size * scale, size * scale,
- TRUE,
- NULL, NULL);
- g_input_stream_close (stream, NULL, NULL);
- g_object_unref (stream);
- }
-
- icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
-
- key = loadable_icon_key_new (icon, size);
- g_hash_table_insert (loadable_icon_cache, key, icon_info);
-
- return g_object_ref (icon_info);
- } else if (G_IS_THEMED_ICON (icon)) {
- const char * const *names;
- ThemedIconKey lookup_key;
- ThemedIconKey *key;
- GtkIconTheme *icon_theme;
- GtkIconInfo *gtkicon_info;
- const char *filename;
-
- if (themed_icon_cache == NULL) {
- themed_icon_cache =
- g_hash_table_new_full ((GHashFunc)themed_icon_key_hash,
- (GEqualFunc)themed_icon_key_equal,
- (GDestroyNotify) themed_icon_key_free,
- (GDestroyNotify) g_object_unref);
- }
-
- names = g_themed_icon_get_names (G_THEMED_ICON (icon));
-
- icon_theme = gtk_icon_theme_get_default ();
- gtkicon_info = gtk_icon_theme_choose_icon_for_scale (icon_theme, (const char **)names,
- size, scale, GTK_ICON_LOOKUP_FORCE_SIZE);
-
- if (gtkicon_info == NULL) {
- return nautilus_icon_info_new_for_pixbuf (NULL, scale);
- }
-
- filename = gtk_icon_info_get_filename (gtkicon_info);
- if (filename == NULL) {
- g_object_unref (gtkicon_info);
- return nautilus_icon_info_new_for_pixbuf (NULL, scale);
- }
-
- lookup_key.filename = (char *)filename;
- lookup_key.size = size;
-
- icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
- if (icon_info) {
- g_object_unref (gtkicon_info);
- return g_object_ref (icon_info);
- }
-
- icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info, scale);
-
- key = themed_icon_key_new (filename, size);
- g_hash_table_insert (themed_icon_cache, key, icon_info);
-
- g_object_unref (gtkicon_info);
-
- return g_object_ref (icon_info);
- } else {
- GdkPixbuf *pixbuf;
- GtkIconInfo *gtk_icon_info;
-
- gtk_icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
- icon,
- size,
- scale,
- GTK_ICON_LOOKUP_FORCE_SIZE);
- if (gtk_icon_info != NULL) {
- pixbuf = gtk_icon_info_load_icon (gtk_icon_info, NULL);
- g_object_unref (gtk_icon_info);
- } else {
- pixbuf = NULL;
- }
-
- icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
-
- if (pixbuf != NULL) {
- g_object_unref (pixbuf);
- }
-
- return icon_info;
+ int size,
+ int scale)
+{
+ NautilusIconInfo *icon_info;
+ GdkPixbuf *pixbuf;
+
+ if (G_IS_LOADABLE_ICON (icon))
+ {
+ LoadableIconKey lookup_key;
+ LoadableIconKey *key;
+ GInputStream *stream;
+
+ if (loadable_icon_cache == NULL)
+ {
+ loadable_icon_cache =
+ g_hash_table_new_full ((GHashFunc) loadable_icon_key_hash,
+ (GEqualFunc) loadable_icon_key_equal,
+ (GDestroyNotify) loadable_icon_key_free,
+ (GDestroyNotify) g_object_unref);
+ }
+
+ lookup_key.icon = icon;
+ lookup_key.size = size;
+
+ icon_info = g_hash_table_lookup (loadable_icon_cache, &lookup_key);
+ if (icon_info)
+ {
+ return g_object_ref (icon_info);
}
+
+ pixbuf = NULL;
+ stream = g_loadable_icon_load (G_LOADABLE_ICON (icon),
+ size * scale,
+ NULL, NULL, NULL);
+ if (stream)
+ {
+ pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
+ size * scale, size * scale,
+ TRUE,
+ NULL, NULL);
+ g_input_stream_close (stream, NULL, NULL);
+ g_object_unref (stream);
+ }
+
+ icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
+
+ key = loadable_icon_key_new (icon, size);
+ g_hash_table_insert (loadable_icon_cache, key, icon_info);
+
+ return g_object_ref (icon_info);
+ }
+ else if (G_IS_THEMED_ICON (icon))
+ {
+ const char * const *names;
+ ThemedIconKey lookup_key;
+ ThemedIconKey *key;
+ GtkIconTheme *icon_theme;
+ GtkIconInfo *gtkicon_info;
+ const char *filename;
+
+ if (themed_icon_cache == NULL)
+ {
+ themed_icon_cache =
+ g_hash_table_new_full ((GHashFunc) themed_icon_key_hash,
+ (GEqualFunc) themed_icon_key_equal,
+ (GDestroyNotify) themed_icon_key_free,
+ (GDestroyNotify) g_object_unref);
+ }
+
+ names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+
+ icon_theme = gtk_icon_theme_get_default ();
+ gtkicon_info = gtk_icon_theme_choose_icon_for_scale (icon_theme, (const char **) names,
+ size, scale, GTK_ICON_LOOKUP_FORCE_SIZE);
+
+ if (gtkicon_info == NULL)
+ {
+ return nautilus_icon_info_new_for_pixbuf (NULL, scale);
+ }
+
+ filename = gtk_icon_info_get_filename (gtkicon_info);
+ if (filename == NULL)
+ {
+ g_object_unref (gtkicon_info);
+ return nautilus_icon_info_new_for_pixbuf (NULL, scale);
+ }
+
+ lookup_key.filename = (char *) filename;
+ lookup_key.size = size;
+
+ icon_info = g_hash_table_lookup (themed_icon_cache, &lookup_key);
+ if (icon_info)
+ {
+ g_object_unref (gtkicon_info);
+ return g_object_ref (icon_info);
+ }
+
+ icon_info = nautilus_icon_info_new_for_icon_info (gtkicon_info, scale);
+
+ key = themed_icon_key_new (filename, size);
+ g_hash_table_insert (themed_icon_cache, key, icon_info);
+
+ g_object_unref (gtkicon_info);
+
+ return g_object_ref (icon_info);
+ }
+ else
+ {
+ GdkPixbuf *pixbuf;
+ GtkIconInfo *gtk_icon_info;
+
+ gtk_icon_info = gtk_icon_theme_lookup_by_gicon_for_scale (gtk_icon_theme_get_default (),
+ icon,
+ size,
+ scale,
+ GTK_ICON_LOOKUP_FORCE_SIZE);
+ if (gtk_icon_info != NULL)
+ {
+ pixbuf = gtk_icon_info_load_icon (gtk_icon_info, NULL);
+ g_object_unref (gtk_icon_info);
+ }
+ else
+ {
+ pixbuf = NULL;
+ }
+
+ icon_info = nautilus_icon_info_new_for_pixbuf (pixbuf, scale);
+
+ if (pixbuf != NULL)
+ {
+ g_object_unref (pixbuf);
+ }
+
+ return icon_info;
+ }
}
NautilusIconInfo *
nautilus_icon_info_lookup_from_name (const char *name,
- int size,
- int scale)
+ int size,
+ int scale)
{
- GIcon *icon;
- NautilusIconInfo *info;
+ GIcon *icon;
+ NautilusIconInfo *info;
- icon = g_themed_icon_new (name);
- info = nautilus_icon_info_lookup (icon, size, scale);
- g_object_unref (icon);
- return info;
+ icon = g_themed_icon_new (name);
+ info = nautilus_icon_info_lookup (icon, size, scale);
+ g_object_unref (icon);
+ return info;
}
NautilusIconInfo *
nautilus_icon_info_lookup_from_path (const char *path,
- int size,
- int scale)
-{
- GFile *icon_file;
- GIcon *icon;
- NautilusIconInfo *info;
-
- icon_file = g_file_new_for_path (path);
- icon = g_file_icon_new (icon_file);
- info = nautilus_icon_info_lookup (icon, size, scale);
- g_object_unref (icon);
- g_object_unref (icon_file);
- return info;
+ int size,
+ int scale)
+{
+ GFile *icon_file;
+ GIcon *icon;
+ NautilusIconInfo *info;
+
+ icon_file = g_file_new_for_path (path);
+ icon = g_file_icon_new (icon_file);
+ info = nautilus_icon_info_lookup (icon, size, scale);
+ g_object_unref (icon);
+ g_object_unref (icon_file);
+ return info;
}
GdkPixbuf *
-nautilus_icon_info_get_pixbuf_nodefault (NautilusIconInfo *icon)
-{
- GdkPixbuf *res;
-
- if (icon->pixbuf == NULL) {
- res = NULL;
- } else {
- res = g_object_ref (icon->pixbuf);
-
- if (icon->sole_owner) {
- icon->sole_owner = FALSE;
- g_object_add_toggle_ref (G_OBJECT (res),
- pixbuf_toggle_notify,
- icon);
- }
- }
-
- return res;
+nautilus_icon_info_get_pixbuf_nodefault (NautilusIconInfo *icon)
+{
+ GdkPixbuf *res;
+
+ if (icon->pixbuf == NULL)
+ {
+ res = NULL;
+ }
+ else
+ {
+ res = g_object_ref (icon->pixbuf);
+
+ if (icon->sole_owner)
+ {
+ icon->sole_owner = FALSE;
+ g_object_add_toggle_ref (G_OBJECT (res),
+ pixbuf_toggle_notify,
+ icon);
+ }
+ }
+
+ return res;
}
GdkPixbuf *
nautilus_icon_info_get_pixbuf (NautilusIconInfo *icon)
{
- GdkPixbuf *res;
-
- res = nautilus_icon_info_get_pixbuf_nodefault (icon);
- if (res == NULL) {
- res = gdk_pixbuf_new_from_data (nautilus_default_file_icon,
- GDK_COLORSPACE_RGB,
- TRUE,
- 8,
- nautilus_default_file_icon_width,
- nautilus_default_file_icon_height,
- nautilus_default_file_icon_width * 4, /* stride */
- NULL, /* don't destroy info */
- NULL);
- }
-
- return res;
+ GdkPixbuf *res;
+
+ res = nautilus_icon_info_get_pixbuf_nodefault (icon);
+ if (res == NULL)
+ {
+ res = gdk_pixbuf_new_from_data (nautilus_default_file_icon,
+ GDK_COLORSPACE_RGB,
+ TRUE,
+ 8,
+ nautilus_default_file_icon_width,
+ nautilus_default_file_icon_height,
+ nautilus_default_file_icon_width * 4, /* stride */
+ NULL, /* don't destroy info */
+ NULL);
+ }
+
+ return res;
}
GdkPixbuf *
-nautilus_icon_info_get_pixbuf_nodefault_at_size (NautilusIconInfo *icon,
- gsize forced_size)
-{
- GdkPixbuf *pixbuf, *scaled_pixbuf;
- int w, h, s;
- double scale;
-
- pixbuf = nautilus_icon_info_get_pixbuf_nodefault (icon);
-
- if (pixbuf == NULL)
- return NULL;
-
- w = gdk_pixbuf_get_width (pixbuf) / icon->orig_scale;
- h = gdk_pixbuf_get_height (pixbuf) / icon->orig_scale;
- s = MAX (w, h);
- if (s == forced_size) {
- return pixbuf;
- }
-
- scale = (double)forced_size / s;
- scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
- w * scale, h * scale,
- GDK_INTERP_BILINEAR);
- g_object_unref (pixbuf);
- return scaled_pixbuf;
+nautilus_icon_info_get_pixbuf_nodefault_at_size (NautilusIconInfo *icon,
+ gsize forced_size)
+{
+ GdkPixbuf *pixbuf, *scaled_pixbuf;
+ int w, h, s;
+ double scale;
+
+ pixbuf = nautilus_icon_info_get_pixbuf_nodefault (icon);
+
+ if (pixbuf == NULL)
+ {
+ return NULL;
+ }
+
+ w = gdk_pixbuf_get_width (pixbuf) / icon->orig_scale;
+ h = gdk_pixbuf_get_height (pixbuf) / icon->orig_scale;
+ s = MAX (w, h);
+ if (s == forced_size)
+ {
+ return pixbuf;
+ }
+
+ scale = (double) forced_size / s;
+ scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ w * scale, h * scale,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ return scaled_pixbuf;
}
GdkPixbuf *
-nautilus_icon_info_get_pixbuf_at_size (NautilusIconInfo *icon,
- gsize forced_size)
-{
- GdkPixbuf *pixbuf, *scaled_pixbuf;
- int w, h, s;
- double scale;
-
- pixbuf = nautilus_icon_info_get_pixbuf (icon);
-
- w = gdk_pixbuf_get_width (pixbuf) / icon->orig_scale;
- h = gdk_pixbuf_get_height (pixbuf) / icon->orig_scale;
- s = MAX (w, h);
- if (s == forced_size) {
- return pixbuf;
- }
-
- scale = (double)forced_size / s;
- scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
- w * scale, h * scale,
- GDK_INTERP_BILINEAR);
- g_object_unref (pixbuf);
- return scaled_pixbuf;
+nautilus_icon_info_get_pixbuf_at_size (NautilusIconInfo *icon,
+ gsize forced_size)
+{
+ GdkPixbuf *pixbuf, *scaled_pixbuf;
+ int w, h, s;
+ double scale;
+
+ pixbuf = nautilus_icon_info_get_pixbuf (icon);
+
+ w = gdk_pixbuf_get_width (pixbuf) / icon->orig_scale;
+ h = gdk_pixbuf_get_height (pixbuf) / icon->orig_scale;
+ s = MAX (w, h);
+ if (s == forced_size)
+ {
+ return pixbuf;
+ }
+
+ scale = (double) forced_size / s;
+ scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ w * scale, h * scale,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ return scaled_pixbuf;
}
const char *
-nautilus_icon_info_get_used_name (NautilusIconInfo *icon)
+nautilus_icon_info_get_used_name (NautilusIconInfo *icon)
{
- return icon->icon_name;
+ return icon->icon_name;
}
gint
nautilus_get_icon_size_for_stock_size (GtkIconSize size)
{
- gint w, h;
+ gint w, h;
- if (gtk_icon_size_lookup (size, &w, &h)) {
- return MAX (w, h);
- }
- return NAUTILUS_CANVAS_ICON_SIZE_SMALL;
+ if (gtk_icon_size_lookup (size, &w, &h))
+ {
+ return MAX (w, h);
+ }
+ return NAUTILUS_CANVAS_ICON_SIZE_SMALL;
}
diff --git a/src/nautilus-image-properties-page.c b/src/nautilus-image-properties-page.c
index 3cf3253c5..4ff95a267 100644
--- a/src/nautilus-image-properties-page.c
+++ b/src/nautilus-image-properties-page.c
@@ -1,5 +1,4 @@
-
-/*
+/*
* Copyright (C) 2004 Red Hat, Inc
* Copyright (c) 2007 Novell, Inc.
*
@@ -43,208 +42,225 @@
#define LOAD_BUFFER_SIZE 8192
-struct NautilusImagePropertiesPageDetails {
- GCancellable *cancellable;
- GtkWidget *grid;
- GdkPixbufLoader *loader;
- gboolean got_size;
- gboolean pixbuf_still_loading;
- char buffer[LOAD_BUFFER_SIZE];
- int width;
- int height;
+struct NautilusImagePropertiesPageDetails
+{
+ GCancellable *cancellable;
+ GtkWidget *grid;
+ GdkPixbufLoader *loader;
+ gboolean got_size;
+ gboolean pixbuf_still_loading;
+ char buffer[LOAD_BUFFER_SIZE];
+ int width;
+ int height;
#ifdef HAVE_EXIF
- ExifLoader *exifldr;
+ ExifLoader *exifldr;
#endif /*HAVE_EXIF*/
#ifdef HAVE_EXEMPI
- XmpPtr xmp;
+ XmpPtr xmp;
#endif
};
#ifdef HAVE_EXIF
-struct ExifAttribute {
- ExifTag tag;
- char *value;
- gboolean found;
+struct ExifAttribute
+{
+ ExifTag tag;
+ char *value;
+ gboolean found;
};
#endif /*HAVE_EXIF*/
-enum {
- PROP_URI
+enum
+{
+ PROP_URI
};
-typedef struct {
- GObject parent;
+typedef struct
+{
+ GObject parent;
} NautilusImagePropertiesPageProvider;
-typedef struct {
- GObjectClass parent;
+typedef struct
+{
+ GObjectClass parent;
} NautilusImagePropertiesPageProviderClass;
static GType nautilus_image_properties_page_provider_get_type (void);
-static void property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface);
+static void property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface);
G_DEFINE_TYPE (NautilusImagePropertiesPage, nautilus_image_properties_page, GTK_TYPE_BOX);
G_DEFINE_TYPE_WITH_CODE (NautilusImagePropertiesPageProvider, nautilus_image_properties_page_provider, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
- property_page_provider_iface_init));
+ G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
+ property_page_provider_iface_init));
static void
nautilus_image_properties_page_finalize (GObject *object)
{
- NautilusImagePropertiesPage *page;
+ NautilusImagePropertiesPage *page;
- page = NAUTILUS_IMAGE_PROPERTIES_PAGE (object);
+ page = NAUTILUS_IMAGE_PROPERTIES_PAGE (object);
- if (page->details->cancellable) {
- g_cancellable_cancel (page->details->cancellable);
- g_object_unref (page->details->cancellable);
- page->details->cancellable = NULL;
- }
+ if (page->details->cancellable)
+ {
+ g_cancellable_cancel (page->details->cancellable);
+ g_object_unref (page->details->cancellable);
+ page->details->cancellable = NULL;
+ }
- G_OBJECT_CLASS (nautilus_image_properties_page_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_image_properties_page_parent_class)->finalize (object);
}
static void
file_close_callback (GObject *object,
- GAsyncResult *res,
- gpointer data)
+ GAsyncResult *res,
+ gpointer data)
{
- NautilusImagePropertiesPage *page;
- GInputStream *stream;
+ NautilusImagePropertiesPage *page;
+ GInputStream *stream;
- page = NAUTILUS_IMAGE_PROPERTIES_PAGE (data);
- stream = G_INPUT_STREAM (object);
+ page = NAUTILUS_IMAGE_PROPERTIES_PAGE (data);
+ stream = G_INPUT_STREAM (object);
- g_input_stream_close_finish (stream, res, NULL);
+ g_input_stream_close_finish (stream, res, NULL);
- g_object_unref (page->details->cancellable);
- page->details->cancellable = NULL;
+ g_object_unref (page->details->cancellable);
+ page->details->cancellable = NULL;
}
static void
append_item (NautilusImagePropertiesPage *page,
- const char *name,
- const char *value)
-{
- GtkWidget *name_label;
- GtkWidget *label;
- PangoAttrList *attrs;
-
- name_label = gtk_label_new (name);
- attrs = pango_attr_list_new ();
- pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
- gtk_label_set_attributes (GTK_LABEL (name_label), attrs);
- pango_attr_list_unref (attrs);
- gtk_label_set_xalign (GTK_LABEL (name_label), 0);
- gtk_label_set_yalign (GTK_LABEL (name_label), 0);
- gtk_container_add (GTK_CONTAINER (page->details->grid), name_label);
- gtk_widget_show (name_label);
-
- if (value != NULL) {
- label = gtk_label_new (value);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_label_set_yalign (GTK_LABEL (label), 0);
- gtk_grid_attach_next_to (GTK_GRID (page->details->grid), label,
- name_label, GTK_POS_RIGHT,
- 1, 1);
- gtk_widget_show (label);
- }
+ const char *name,
+ const char *value)
+{
+ GtkWidget *name_label;
+ GtkWidget *label;
+ PangoAttrList *attrs;
+
+ name_label = gtk_label_new (name);
+ attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+ gtk_label_set_attributes (GTK_LABEL (name_label), attrs);
+ pango_attr_list_unref (attrs);
+ gtk_label_set_xalign (GTK_LABEL (name_label), 0);
+ gtk_label_set_yalign (GTK_LABEL (name_label), 0);
+ gtk_container_add (GTK_CONTAINER (page->details->grid), name_label);
+ gtk_widget_show (name_label);
+
+ if (value != NULL)
+ {
+ label = gtk_label_new (value);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_label_set_yalign (GTK_LABEL (label), 0);
+ gtk_grid_attach_next_to (GTK_GRID (page->details->grid), label,
+ name_label, GTK_POS_RIGHT,
+ 1, 1);
+ gtk_widget_show (label);
+ }
}
#ifdef HAVE_EXIF
static char *
exif_string_to_utf8 (const char *exif_str)
{
- char *utf8_str;
-
- if (g_utf8_validate (exif_str, -1, NULL)) {
- return g_strdup (exif_str);
- }
-
- utf8_str = g_locale_to_utf8 (exif_str, -1, NULL, NULL, NULL);
- if (utf8_str != NULL) {
- return utf8_str;
- }
-
- return eel_make_valid_utf8 (exif_str);
+ char *utf8_str;
+
+ if (g_utf8_validate (exif_str, -1, NULL))
+ {
+ return g_strdup (exif_str);
+ }
+
+ utf8_str = g_locale_to_utf8 (exif_str, -1, NULL, NULL, NULL);
+ if (utf8_str != NULL)
+ {
+ return utf8_str;
+ }
+
+ return eel_make_valid_utf8 (exif_str);
}
static void
-exif_content_callback (ExifContent *content, gpointer data)
+exif_content_callback (ExifContent *content,
+ gpointer data)
{
- struct ExifAttribute *attribute;
- char b[1024];
+ struct ExifAttribute *attribute;
+ char b[1024];
- attribute = (struct ExifAttribute *)data;
- if (attribute->found) {
- return;
- }
+ attribute = (struct ExifAttribute *) data;
+ if (attribute->found)
+ {
+ return;
+ }
- attribute->value = g_strdup (exif_content_get_value (content, attribute->tag, b, sizeof(b)));
+ attribute->value = g_strdup (exif_content_get_value (content, attribute->tag, b, sizeof (b)));
- if (attribute->value != NULL) {
- attribute->found = TRUE;
- }
+ if (attribute->value != NULL)
+ {
+ attribute->found = TRUE;
+ }
}
static char *
-exifdata_get_tag_name_utf8 (ExifTag tag)
+exifdata_get_tag_name_utf8 (ExifTag tag)
{
- return exif_string_to_utf8 (exif_tag_get_name (tag));
+ return exif_string_to_utf8 (exif_tag_get_name (tag));
}
static char *
-exifdata_get_tag_value_utf8 (ExifData *data, ExifTag tag)
+exifdata_get_tag_value_utf8 (ExifData *data,
+ ExifTag tag)
{
- struct ExifAttribute attribute;
- char *utf8_value;
-
- attribute.tag = tag;
- attribute.value = NULL;
- attribute.found = FALSE;
-
- exif_data_foreach_content (data, exif_content_callback, &attribute);
-
- if (attribute.found) {
- utf8_value = exif_string_to_utf8 (attribute.value);
- g_free (attribute.value);
- } else {
- utf8_value = NULL;
- }
-
- return utf8_value;
+ struct ExifAttribute attribute;
+ char *utf8_value;
+
+ attribute.tag = tag;
+ attribute.value = NULL;
+ attribute.found = FALSE;
+
+ exif_data_foreach_content (data, exif_content_callback, &attribute);
+
+ if (attribute.found)
+ {
+ utf8_value = exif_string_to_utf8 (attribute.value);
+ g_free (attribute.value);
+ }
+ else
+ {
+ utf8_value = NULL;
+ }
+
+ return utf8_value;
}
static gboolean
append_tag_value_pair (NautilusImagePropertiesPage *page,
- ExifData *data,
- ExifTag tag,
- char *description)
+ ExifData *data,
+ ExifTag tag,
+ char *description)
{
- char *utf_attribute;
- char *utf_value;
+ char *utf_attribute;
+ char *utf_value;
- utf_attribute = exifdata_get_tag_name_utf8 (tag);
- utf_value = exifdata_get_tag_value_utf8 (data, tag);
-
- if ((utf_attribute == NULL) || (utf_value == NULL)) {
- g_free (utf_attribute);
- g_free (utf_value);
- return FALSE;
- }
-
- append_item (page,
- description ? description : utf_attribute,
- utf_value);
+ utf_attribute = exifdata_get_tag_name_utf8 (tag);
+ utf_value = exifdata_get_tag_value_utf8 (data, tag);
+ if ((utf_attribute == NULL) || (utf_value == NULL))
+ {
g_free (utf_attribute);
g_free (utf_value);
+ return FALSE;
+ }
+
+ append_item (page,
+ description ? description : utf_attribute,
+ utf_value);
+
+ g_free (utf_attribute);
+ g_free (utf_value);
- return TRUE;
+ return TRUE;
}
#endif /*HAVE_EXIF*/
@@ -252,155 +268,175 @@ append_tag_value_pair (NautilusImagePropertiesPage *page,
#ifdef HAVE_EXEMPI
static void
append_xmp_value_pair (NautilusImagePropertiesPage *page,
- XmpPtr xmp,
- const char *ns,
- const char *propname,
- char *descr)
-{
- uint32_t options;
- XmpStringPtr value;
-
- value = xmp_string_new();
- if (xmp_get_property (xmp, ns, propname, value, &options)) {
- if (XMP_IS_PROP_SIMPLE (options)) {
- append_item (page, descr, xmp_string_cstr (value));
- }
- else if (XMP_IS_PROP_ARRAY (options)) {
- XmpIteratorPtr iter;
-
- iter = xmp_iterator_new (xmp, ns, propname, XMP_ITER_JUSTLEAFNODES);
- if (iter) {
- GString *str;
- gboolean first = TRUE;
-
- str = g_string_new (NULL);
-
- while (xmp_iterator_next (iter, NULL, NULL, value, &options)
- && !XMP_IS_PROP_QUALIFIER(options)) {
- if (!first) {
- g_string_append_printf (str, ", ");
- }
- else {
- first = FALSE;
- }
- g_string_append_printf (str,
- "%s",
- xmp_string_cstr(value));
- }
- xmp_iterator_free(iter);
- append_item (page, descr, g_string_free (str, FALSE));
- }
- }
- }
- xmp_string_free(value);
+ XmpPtr xmp,
+ const char *ns,
+ const char *propname,
+ char *descr)
+{
+ uint32_t options;
+ XmpStringPtr value;
+
+ value = xmp_string_new ();
+ if (xmp_get_property (xmp, ns, propname, value, &options))
+ {
+ if (XMP_IS_PROP_SIMPLE (options))
+ {
+ append_item (page, descr, xmp_string_cstr (value));
+ }
+ else if (XMP_IS_PROP_ARRAY (options))
+ {
+ XmpIteratorPtr iter;
+
+ iter = xmp_iterator_new (xmp, ns, propname, XMP_ITER_JUSTLEAFNODES);
+ if (iter)
+ {
+ GString *str;
+ gboolean first = TRUE;
+
+ str = g_string_new (NULL);
+
+ while (xmp_iterator_next (iter, NULL, NULL, value, &options)
+ && !XMP_IS_PROP_QUALIFIER (options))
+ {
+ if (!first)
+ {
+ g_string_append_printf (str, ", ");
+ }
+ else
+ {
+ first = FALSE;
+ }
+ g_string_append_printf (str,
+ "%s",
+ xmp_string_cstr (value));
+ }
+ xmp_iterator_free (iter);
+ append_item (page, descr, g_string_free (str, FALSE));
+ }
+ }
+ }
+ xmp_string_free (value);
}
#endif /*HAVE EXEMPI*/
static gboolean
append_option_value_pair (NautilusImagePropertiesPage *page,
- GdkPixbuf *pixbuf,
- const char *key,
- char *description)
+ GdkPixbuf *pixbuf,
+ const char *key,
+ char *description)
{
- const char *value;
+ const char *value;
- value = gdk_pixbuf_get_option (pixbuf, key);
- if (value == NULL)
- return FALSE;
+ value = gdk_pixbuf_get_option (pixbuf, key);
+ if (value == NULL)
+ {
+ return FALSE;
+ }
- append_item (page, description, value);
- return TRUE;
+ append_item (page, description, value);
+ return TRUE;
}
static void
append_basic_info (NautilusImagePropertiesPage *page)
{
- GdkPixbufFormat *format;
- char *name;
- char *desc;
- char *value;
-
- format = gdk_pixbuf_loader_get_format (page->details->loader);
-
- name = gdk_pixbuf_format_get_name (format);
- desc = gdk_pixbuf_format_get_description (format);
- value = g_strdup_printf ("%s (%s)", name, desc);
- g_free (name);
- g_free (desc);
- append_item (page, _("Image Type"), value);
- g_free (value);
- value = g_strdup_printf (ngettext ("%d pixel",
- "%d pixels",
- page->details->width),
- page->details->width);
- append_item (page, _("Width"), value);
- g_free (value);
- value = g_strdup_printf (ngettext ("%d pixel",
- "%d pixels",
- page->details->height),
- page->details->height);
- append_item (page, _("Height"), value);
- g_free (value);
+ GdkPixbufFormat *format;
+ char *name;
+ char *desc;
+ char *value;
+
+ format = gdk_pixbuf_loader_get_format (page->details->loader);
+
+ name = gdk_pixbuf_format_get_name (format);
+ desc = gdk_pixbuf_format_get_description (format);
+ value = g_strdup_printf ("%s (%s)", name, desc);
+ g_free (name);
+ g_free (desc);
+ append_item (page, _("Image Type"), value);
+ g_free (value);
+ value = g_strdup_printf (ngettext ("%d pixel",
+ "%d pixels",
+ page->details->width),
+ page->details->width);
+ append_item (page, _("Width"), value);
+ g_free (value);
+ value = g_strdup_printf (ngettext ("%d pixel",
+ "%d pixels",
+ page->details->height),
+ page->details->height);
+ append_item (page, _("Height"), value);
+ g_free (value);
}
static void
append_options_info (NautilusImagePropertiesPage *page)
{
- GdkPixbuf *pixbuf;
-
- pixbuf = gdk_pixbuf_loader_get_pixbuf (page->details->loader);
- if (pixbuf == NULL)
- return;
-
- if (!append_option_value_pair (page, pixbuf, "Title", _("Title")))
- append_option_value_pair (page, pixbuf, "tEXt::Title", _("Title"));
- if (!append_option_value_pair (page, pixbuf, "Author", _("Author")))
- append_option_value_pair (page, pixbuf, "tEXt::Author", _("Author"));
-
- append_option_value_pair (page, pixbuf, "tEXt::Description", _("Description"));
- append_option_value_pair (page, pixbuf, "tEXt::Copyright", _("Copyright"));
- append_option_value_pair (page, pixbuf, "tEXt::Creation Time", _("Created On"));
- append_option_value_pair (page, pixbuf, "tEXt::Software", _("Created By"));
- /* Translators: this refers to a legal disclaimer string embedded in
- * the metadata of an image */
- append_option_value_pair (page, pixbuf, "tEXt::Disclaimer", _("Disclaimer"));
- append_option_value_pair (page, pixbuf, "tEXt::Warning", _("Warning"));
- append_option_value_pair (page, pixbuf, "tEXt::Source", _("Source"));
- append_option_value_pair (page, pixbuf, "tEXt::Comment", _("Comment"));
+ GdkPixbuf *pixbuf;
+
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (page->details->loader);
+ if (pixbuf == NULL)
+ {
+ return;
+ }
+
+ if (!append_option_value_pair (page, pixbuf, "Title", _("Title")))
+ {
+ append_option_value_pair (page, pixbuf, "tEXt::Title", _("Title"));
+ }
+ if (!append_option_value_pair (page, pixbuf, "Author", _("Author")))
+ {
+ append_option_value_pair (page, pixbuf, "tEXt::Author", _("Author"));
+ }
+
+ append_option_value_pair (page, pixbuf, "tEXt::Description", _("Description"));
+ append_option_value_pair (page, pixbuf, "tEXt::Copyright", _("Copyright"));
+ append_option_value_pair (page, pixbuf, "tEXt::Creation Time", _("Created On"));
+ append_option_value_pair (page, pixbuf, "tEXt::Software", _("Created By"));
+ /* Translators: this refers to a legal disclaimer string embedded in
+ * the metadata of an image */
+ append_option_value_pair (page, pixbuf, "tEXt::Disclaimer", _("Disclaimer"));
+ append_option_value_pair (page, pixbuf, "tEXt::Warning", _("Warning"));
+ append_option_value_pair (page, pixbuf, "tEXt::Source", _("Source"));
+ append_option_value_pair (page, pixbuf, "tEXt::Comment", _("Comment"));
}
static void
append_exif_info (NautilusImagePropertiesPage *page)
{
#ifdef HAVE_EXIF
- ExifData *exifdata;
-
- exifdata = exif_loader_get_data (page->details->exifldr);
- if (exifdata == NULL)
- return;
-
- if (exifdata->ifd[0] && exifdata->ifd[0]->count) {
- append_tag_value_pair (page, exifdata, EXIF_TAG_MAKE, _("Camera Brand"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_MODEL, _("Camera Model"));
-
- /* Choose which date to show in order of relevance */
- if (!append_tag_value_pair (page, exifdata, EXIF_TAG_DATE_TIME_ORIGINAL, _("Date Taken"))) {
- if (!append_tag_value_pair (page, exifdata, EXIF_TAG_DATE_TIME_DIGITIZED, _("Date Digitized"))) {
- append_tag_value_pair (page, exifdata, EXIF_TAG_DATE_TIME, _("Date Modified"));
- }
- }
-
- append_tag_value_pair (page, exifdata, EXIF_TAG_EXPOSURE_TIME, _("Exposure Time"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_APERTURE_VALUE, _("Aperture Value"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_ISO_SPEED_RATINGS, _("ISO Speed Rating"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_FLASH,_("Flash Fired"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_METERING_MODE, _("Metering Mode"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_EXPOSURE_PROGRAM, _("Exposure Program"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_FOCAL_LENGTH,_("Focal Length"));
- append_tag_value_pair (page, exifdata, EXIF_TAG_SOFTWARE, _("Software"));
- }
-
- exif_data_unref (exifdata);
+ ExifData *exifdata;
+
+ exifdata = exif_loader_get_data (page->details->exifldr);
+ if (exifdata == NULL)
+ {
+ return;
+ }
+
+ if (exifdata->ifd[0] && exifdata->ifd[0]->count)
+ {
+ append_tag_value_pair (page, exifdata, EXIF_TAG_MAKE, _("Camera Brand"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_MODEL, _("Camera Model"));
+
+ /* Choose which date to show in order of relevance */
+ if (!append_tag_value_pair (page, exifdata, EXIF_TAG_DATE_TIME_ORIGINAL, _("Date Taken")))
+ {
+ if (!append_tag_value_pair (page, exifdata, EXIF_TAG_DATE_TIME_DIGITIZED, _("Date Digitized")))
+ {
+ append_tag_value_pair (page, exifdata, EXIF_TAG_DATE_TIME, _("Date Modified"));
+ }
+ }
+
+ append_tag_value_pair (page, exifdata, EXIF_TAG_EXPOSURE_TIME, _("Exposure Time"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_APERTURE_VALUE, _("Aperture Value"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_ISO_SPEED_RATINGS, _("ISO Speed Rating"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_FLASH, _("Flash Fired"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_METERING_MODE, _("Metering Mode"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_EXPOSURE_PROGRAM, _("Exposure Program"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_FOCAL_LENGTH, _("Focal Length"));
+ append_tag_value_pair (page, exifdata, EXIF_TAG_SOFTWARE, _("Software"));
+ }
+
+ exif_data_unref (exifdata);
#endif
}
@@ -408,377 +444,405 @@ static void
append_xmp_info (NautilusImagePropertiesPage *page)
{
#ifdef HAVE_EXEMPI
- if (page->details->xmp == NULL)
- return;
-
- append_xmp_value_pair (page, page->details->xmp, NS_IPTC4XMP, "Location", _("Location"));
- append_xmp_value_pair (page, page->details->xmp, NS_DC, "description", _("Description"));
- append_xmp_value_pair (page, page->details->xmp, NS_DC, "subject", _("Keywords"));
- append_xmp_value_pair (page, page->details->xmp, NS_DC, "creator", _("Creator"));
- append_xmp_value_pair (page, page->details->xmp, NS_DC, "rights", _("Copyright"));
- append_xmp_value_pair (page, page->details->xmp, NS_XAP,"Rating", _("Rating"));
- /* TODO add CC licenses */
+ if (page->details->xmp == NULL)
+ {
+ return;
+ }
+
+ append_xmp_value_pair (page, page->details->xmp, NS_IPTC4XMP, "Location", _("Location"));
+ append_xmp_value_pair (page, page->details->xmp, NS_DC, "description", _("Description"));
+ append_xmp_value_pair (page, page->details->xmp, NS_DC, "subject", _("Keywords"));
+ append_xmp_value_pair (page, page->details->xmp, NS_DC, "creator", _("Creator"));
+ append_xmp_value_pair (page, page->details->xmp, NS_DC, "rights", _("Copyright"));
+ append_xmp_value_pair (page, page->details->xmp, NS_XAP, "Rating", _("Rating"));
+ /* TODO add CC licenses */
#endif /*HAVE EXEMPI*/
}
static void
load_finished (NautilusImagePropertiesPage *page)
{
- GtkWidget *label;
-
- label = gtk_grid_get_child_at (GTK_GRID (page->details->grid), 0, 0);
- gtk_container_remove (GTK_CONTAINER (page->details->grid), label);
-
- if (page->details->loader != NULL) {
- gdk_pixbuf_loader_close (page->details->loader, NULL);
- }
-
- if (page->details->got_size) {
- append_basic_info (page);
- append_options_info (page);
- append_exif_info (page);
- append_xmp_info (page);
- } else {
- append_item (page, _("Failed to load image information"), NULL);
- }
-
- if (page->details->loader != NULL) {
- g_object_unref (page->details->loader);
- page->details->loader = NULL;
- }
+ GtkWidget *label;
+
+ label = gtk_grid_get_child_at (GTK_GRID (page->details->grid), 0, 0);
+ gtk_container_remove (GTK_CONTAINER (page->details->grid), label);
+
+ if (page->details->loader != NULL)
+ {
+ gdk_pixbuf_loader_close (page->details->loader, NULL);
+ }
+
+ if (page->details->got_size)
+ {
+ append_basic_info (page);
+ append_options_info (page);
+ append_exif_info (page);
+ append_xmp_info (page);
+ }
+ else
+ {
+ append_item (page, _("Failed to load image information"), NULL);
+ }
+
+ if (page->details->loader != NULL)
+ {
+ g_object_unref (page->details->loader);
+ page->details->loader = NULL;
+ }
#ifdef HAVE_EXIF
- if (page->details->exifldr != NULL) {
- exif_loader_unref (page->details->exifldr);
- page->details->exifldr = NULL;
- }
+ if (page->details->exifldr != NULL)
+ {
+ exif_loader_unref (page->details->exifldr);
+ page->details->exifldr = NULL;
+ }
#endif /*HAVE_EXIF*/
#ifdef HAVE_EXEMPI
- if (page->details->xmp != NULL) {
- xmp_free (page->details->xmp);
- page->details->xmp = NULL;
- }
+ if (page->details->xmp != NULL)
+ {
+ xmp_free (page->details->xmp);
+ page->details->xmp = NULL;
+ }
#endif
}
static void
file_read_callback (GObject *object,
- GAsyncResult *res,
- gpointer data)
+ GAsyncResult *res,
+ gpointer data)
{
- NautilusImagePropertiesPage *page;
- GInputStream *stream;
- gssize count_read;
- GError *error;
- int exif_still_loading;
- gboolean done_reading;
+ NautilusImagePropertiesPage *page;
+ GInputStream *stream;
+ gssize count_read;
+ GError *error;
+ int exif_still_loading;
+ gboolean done_reading;
- page = NAUTILUS_IMAGE_PROPERTIES_PAGE (data);
- stream = G_INPUT_STREAM (object);
+ page = NAUTILUS_IMAGE_PROPERTIES_PAGE (data);
+ stream = G_INPUT_STREAM (object);
- error = NULL;
- done_reading = FALSE;
- count_read = g_input_stream_read_finish (stream, res, &error);
+ error = NULL;
+ done_reading = FALSE;
+ count_read = g_input_stream_read_finish (stream, res, &error);
- if (count_read > 0) {
-
- g_assert (count_read <= sizeof(page->details->buffer));
+ if (count_read > 0)
+ {
+ g_assert (count_read <= sizeof (page->details->buffer));
#ifdef HAVE_EXIF
- exif_still_loading = exif_loader_write (page->details->exifldr,
- (guchar *) page->details->buffer,
- count_read);
+ exif_still_loading = exif_loader_write (page->details->exifldr,
+ (guchar *) page->details->buffer,
+ count_read);
#else
- exif_still_loading = 0;
+ exif_still_loading = 0;
#endif
- if (page->details->pixbuf_still_loading) {
- if (!gdk_pixbuf_loader_write (page->details->loader,
- (const guchar *) page->details->buffer,
- count_read,
- NULL)) {
- page->details->pixbuf_still_loading = FALSE;
- }
- }
-
- if (page->details->pixbuf_still_loading ||
- (exif_still_loading == 1)) {
- g_input_stream_read_async (G_INPUT_STREAM (stream),
- page->details->buffer,
- sizeof (page->details->buffer),
- 0,
- page->details->cancellable,
- file_read_callback,
- page);
- }
- else {
- done_reading = TRUE;
- }
- }
- else {
- /* either EOF, cancelled or an error occurred */
- done_reading = TRUE;
- }
-
- if (error != NULL) {
- char *uri = g_file_get_uri (G_FILE (object));
- g_warning ("Error reading %s: %s", uri, error->message);
- g_free (uri);
- g_clear_error (&error);
- }
-
- if (done_reading) {
- load_finished (page);
- g_input_stream_close_async (stream,
- 0,
- page->details->cancellable,
- file_close_callback,
- page);
- }
+ if (page->details->pixbuf_still_loading)
+ {
+ if (!gdk_pixbuf_loader_write (page->details->loader,
+ (const guchar *) page->details->buffer,
+ count_read,
+ NULL))
+ {
+ page->details->pixbuf_still_loading = FALSE;
+ }
+ }
+
+ if (page->details->pixbuf_still_loading ||
+ (exif_still_loading == 1))
+ {
+ g_input_stream_read_async (G_INPUT_STREAM (stream),
+ page->details->buffer,
+ sizeof (page->details->buffer),
+ 0,
+ page->details->cancellable,
+ file_read_callback,
+ page);
+ }
+ else
+ {
+ done_reading = TRUE;
+ }
+ }
+ else
+ {
+ /* either EOF, cancelled or an error occurred */
+ done_reading = TRUE;
+ }
+
+ if (error != NULL)
+ {
+ char *uri = g_file_get_uri (G_FILE (object));
+ g_warning ("Error reading %s: %s", uri, error->message);
+ g_free (uri);
+ g_clear_error (&error);
+ }
+
+ if (done_reading)
+ {
+ load_finished (page);
+ g_input_stream_close_async (stream,
+ 0,
+ page->details->cancellable,
+ file_close_callback,
+ page);
+ }
}
static void
-size_prepared_callback (GdkPixbufLoader *loader,
- int width,
- int height,
- gpointer callback_data)
+size_prepared_callback (GdkPixbufLoader *loader,
+ int width,
+ int height,
+ gpointer callback_data)
{
- NautilusImagePropertiesPage *page;
+ NautilusImagePropertiesPage *page;
- page = NAUTILUS_IMAGE_PROPERTIES_PAGE (callback_data);
+ page = NAUTILUS_IMAGE_PROPERTIES_PAGE (callback_data);
- page->details->height = height;
- page->details->width = width;
- page->details->got_size = TRUE;
- page->details->pixbuf_still_loading = FALSE;
+ page->details->height = height;
+ page->details->width = width;
+ page->details->got_size = TRUE;
+ page->details->pixbuf_still_loading = FALSE;
}
-typedef struct {
- NautilusImagePropertiesPage *page;
- NautilusFileInfo *info;
+typedef struct
+{
+ NautilusImagePropertiesPage *page;
+ NautilusFileInfo *info;
} FileOpenData;
static void
file_open_callback (GObject *object,
- GAsyncResult *res,
- gpointer user_data)
-{
- FileOpenData *data = user_data;
- NautilusImagePropertiesPage *page = data->page;
- GFile *file;
- GFileInputStream *stream;
- GError *error;
- char *uri;
-
- file = G_FILE (object);
- uri = g_file_get_uri (file);
-
- error = NULL;
- stream = g_file_read_finish (file, res, &error);
- if (stream) {
- char *mime_type;
-
- mime_type = nautilus_file_info_get_mime_type (data->info);
- page->details->loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
- if (error != NULL) {
- g_warning ("Error creating loader for %s: %s", uri, error->message);
- g_clear_error (&error);
- }
- page->details->pixbuf_still_loading = TRUE;
- page->details->width = 0;
- page->details->height = 0;
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ FileOpenData *data = user_data;
+ NautilusImagePropertiesPage *page = data->page;
+ GFile *file;
+ GFileInputStream *stream;
+ GError *error;
+ char *uri;
+
+ file = G_FILE (object);
+ uri = g_file_get_uri (file);
+
+ error = NULL;
+ stream = g_file_read_finish (file, res, &error);
+ if (stream)
+ {
+ char *mime_type;
+
+ mime_type = nautilus_file_info_get_mime_type (data->info);
+ page->details->loader = gdk_pixbuf_loader_new_with_mime_type (mime_type, &error);
+ if (error != NULL)
+ {
+ g_warning ("Error creating loader for %s: %s", uri, error->message);
+ g_clear_error (&error);
+ }
+ page->details->pixbuf_still_loading = TRUE;
+ page->details->width = 0;
+ page->details->height = 0;
#ifdef HAVE_EXIF
- page->details->exifldr = exif_loader_new ();
+ page->details->exifldr = exif_loader_new ();
#endif /*HAVE_EXIF*/
- g_free (mime_type);
-
- g_signal_connect (page->details->loader,
- "size-prepared",
- G_CALLBACK (size_prepared_callback),
- page);
-
- g_input_stream_read_async (G_INPUT_STREAM (stream),
- page->details->buffer,
- sizeof (page->details->buffer),
- 0,
- page->details->cancellable,
- file_read_callback,
- page);
-
- g_object_unref (stream);
- } else {
- g_warning ("Error reading %s: %s", uri, error->message);
- g_clear_error (&error);
- load_finished (page);
- }
-
- g_free (uri);
- g_free (data);
+ g_free (mime_type);
+
+ g_signal_connect (page->details->loader,
+ "size-prepared",
+ G_CALLBACK (size_prepared_callback),
+ page);
+
+ g_input_stream_read_async (G_INPUT_STREAM (stream),
+ page->details->buffer,
+ sizeof (page->details->buffer),
+ 0,
+ page->details->cancellable,
+ file_read_callback,
+ page);
+
+ g_object_unref (stream);
+ }
+ else
+ {
+ g_warning ("Error reading %s: %s", uri, error->message);
+ g_clear_error (&error);
+ load_finished (page);
+ }
+
+ g_free (uri);
+ g_free (data);
}
static void
load_location (NautilusImagePropertiesPage *page,
- NautilusFileInfo *info)
+ NautilusFileInfo *info)
{
- GFile *file;
- char *uri;
- FileOpenData *data;
+ GFile *file;
+ char *uri;
+ FileOpenData *data;
- g_assert (NAUTILUS_IS_IMAGE_PROPERTIES_PAGE (page));
- g_assert (info != NULL);
+ g_assert (NAUTILUS_IS_IMAGE_PROPERTIES_PAGE (page));
+ g_assert (info != NULL);
- page->details->cancellable = g_cancellable_new ();
+ page->details->cancellable = g_cancellable_new ();
- uri = nautilus_file_info_get_uri (info);
- file = g_file_new_for_uri (uri);
+ uri = nautilus_file_info_get_uri (info);
+ file = g_file_new_for_uri (uri);
#ifdef HAVE_EXEMPI
- {
- /* Current Exempi does not support setting custom IO to be able to use Gnome-vfs */
- /* So it will only work with local files. Future version might remove this limitation */
- XmpFilePtr xf;
- char *localname;
-
- localname = g_filename_from_uri (uri, NULL, NULL);
- if (localname) {
- xf = xmp_files_open_new (localname, 0);
- page->details->xmp = xmp_files_get_new_xmp (xf); /* only load when loading */
- xmp_files_close (xf, 0);
- g_free (localname);
- }
- else {
- page->details->xmp = NULL;
- }
- }
+ {
+ /* Current Exempi does not support setting custom IO to be able to use Gnome-vfs */
+ /* So it will only work with local files. Future version might remove this limitation */
+ XmpFilePtr xf;
+ char *localname;
+
+ localname = g_filename_from_uri (uri, NULL, NULL);
+ if (localname)
+ {
+ xf = xmp_files_open_new (localname, 0);
+ page->details->xmp = xmp_files_get_new_xmp (xf); /* only load when loading */
+ xmp_files_close (xf, 0);
+ g_free (localname);
+ }
+ else
+ {
+ page->details->xmp = NULL;
+ }
+ }
#endif /*HAVE_EXEMPI*/
- data = g_new0 (FileOpenData, 1);
- data->page = page;
- data->info = info;
+ data = g_new0 (FileOpenData, 1);
+ data->page = page;
+ data->info = info;
- g_file_read_async (file,
- 0,
- page->details->cancellable,
- file_open_callback,
- data);
+ g_file_read_async (file,
+ 0,
+ page->details->cancellable,
+ file_open_callback,
+ data);
- g_object_unref (file);
- g_free (uri);
+ g_object_unref (file);
+ g_free (uri);
}
static void
nautilus_image_properties_page_class_init (NautilusImagePropertiesPageClass *class)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
- object_class = G_OBJECT_CLASS (class);
+ object_class = G_OBJECT_CLASS (class);
- object_class->finalize = nautilus_image_properties_page_finalize;
+ object_class->finalize = nautilus_image_properties_page_finalize;
- g_type_class_add_private (object_class, sizeof(NautilusImagePropertiesPageDetails));
+ g_type_class_add_private (object_class, sizeof (NautilusImagePropertiesPageDetails));
}
static void
nautilus_image_properties_page_init (NautilusImagePropertiesPage *page)
{
- GtkWidget *sw;
-
- page->details = G_TYPE_INSTANCE_GET_PRIVATE (page,
- NAUTILUS_TYPE_IMAGE_PROPERTIES_PAGE,
- NautilusImagePropertiesPageDetails);
-
- gtk_orientable_set_orientation (GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
- gtk_box_set_homogeneous (GTK_BOX (page), FALSE);
- gtk_box_set_spacing (GTK_BOX (page), 0);
- gtk_container_set_border_width (GTK_CONTAINER (page), 0);
-
- sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_set_border_width (GTK_CONTAINER (sw), 0);
- gtk_widget_set_vexpand (GTK_WIDGET (sw), TRUE);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
- GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start (GTK_BOX (page), sw, FALSE, TRUE, 2);
-
- page->details->grid = gtk_grid_new ();
- gtk_container_set_border_width (GTK_CONTAINER (page->details->grid), 6);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (page->details->grid), GTK_ORIENTATION_VERTICAL);
- gtk_grid_set_row_spacing (GTK_GRID (page->details->grid), 6);
- gtk_grid_set_column_spacing (GTK_GRID (page->details->grid), 20);
- append_item (page, _("Loading…"), NULL);
- gtk_container_add (GTK_CONTAINER (sw), page->details->grid);
-
- gtk_widget_show_all (GTK_WIDGET (page));
+ GtkWidget *sw;
+
+ page->details = G_TYPE_INSTANCE_GET_PRIVATE (page,
+ NAUTILUS_TYPE_IMAGE_PROPERTIES_PAGE,
+ NautilusImagePropertiesPageDetails);
+
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
+ gtk_box_set_homogeneous (GTK_BOX (page), FALSE);
+ gtk_box_set_spacing (GTK_BOX (page), 0);
+ gtk_container_set_border_width (GTK_CONTAINER (page), 0);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_container_set_border_width (GTK_CONTAINER (sw), 0);
+ gtk_widget_set_vexpand (GTK_WIDGET (sw), TRUE);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_AUTOMATIC);
+ gtk_box_pack_start (GTK_BOX (page), sw, FALSE, TRUE, 2);
+
+ page->details->grid = gtk_grid_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (page->details->grid), 6);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (page->details->grid), GTK_ORIENTATION_VERTICAL);
+ gtk_grid_set_row_spacing (GTK_GRID (page->details->grid), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (page->details->grid), 20);
+ append_item (page, _("Loading…"), NULL);
+ gtk_container_add (GTK_CONTAINER (sw), page->details->grid);
+
+ gtk_widget_show_all (GTK_WIDGET (page));
}
static gboolean
is_mime_type_supported (const char *mime_type)
{
- gboolean supported;
- GSList *formats;
- GSList *l;
-
- supported = FALSE;
- formats = gdk_pixbuf_get_formats ();
-
- for (l = formats; supported == FALSE && l != NULL; l = l->next) {
- GdkPixbufFormat *format = l->data;
- char **mime_types = gdk_pixbuf_format_get_mime_types (format);
- int i;
-
- for (i = 0; mime_types[i] != NULL; i++) {
- if (strcmp (mime_types[i], mime_type) == 0) {
- supported = TRUE;
- break;
- }
- }
- g_strfreev (mime_types);
- }
- g_slist_free (formats);
-
- return supported;
+ gboolean supported;
+ GSList *formats;
+ GSList *l;
+
+ supported = FALSE;
+ formats = gdk_pixbuf_get_formats ();
+
+ for (l = formats; supported == FALSE && l != NULL; l = l->next)
+ {
+ GdkPixbufFormat *format = l->data;
+ char **mime_types = gdk_pixbuf_format_get_mime_types (format);
+ int i;
+
+ for (i = 0; mime_types[i] != NULL; i++)
+ {
+ if (strcmp (mime_types[i], mime_type) == 0)
+ {
+ supported = TRUE;
+ break;
+ }
+ }
+ g_strfreev (mime_types);
+ }
+ g_slist_free (formats);
+
+ return supported;
}
static GList *
get_property_pages (NautilusPropertyPageProvider *provider,
- GList *files)
+ GList *files)
{
- GList *pages;
- NautilusFileInfo *file;
- char *mime_type;
-
- /* Only show the property page if 1 file is selected */
- if (!files || files->next != NULL) {
- return NULL;
- }
-
- pages = NULL;
- file = NAUTILUS_FILE_INFO (files->data);
-
- mime_type = nautilus_file_info_get_mime_type (file);
- if (mime_type != NULL
- && is_mime_type_supported (mime_type)) {
- NautilusImagePropertiesPage *page;
- NautilusPropertyPage *real_page;
-
- page = g_object_new (nautilus_image_properties_page_get_type (), NULL);
- load_location (page, file);
-
- real_page = nautilus_property_page_new
- ("NautilusImagePropertiesPage::property_page",
- gtk_label_new (_("Image")),
- GTK_WIDGET (page));
- pages = g_list_append (pages, real_page);
- }
-
- g_free (mime_type);
-
- return pages;
+ GList *pages;
+ NautilusFileInfo *file;
+ char *mime_type;
+
+ /* Only show the property page if 1 file is selected */
+ if (!files || files->next != NULL)
+ {
+ return NULL;
+ }
+
+ pages = NULL;
+ file = NAUTILUS_FILE_INFO (files->data);
+
+ mime_type = nautilus_file_info_get_mime_type (file);
+ if (mime_type != NULL
+ && is_mime_type_supported (mime_type))
+ {
+ NautilusImagePropertiesPage *page;
+ NautilusPropertyPage *real_page;
+
+ page = g_object_new (nautilus_image_properties_page_get_type (), NULL);
+ load_location (page, file);
+
+ real_page = nautilus_property_page_new
+ ("NautilusImagePropertiesPage::property_page",
+ gtk_label_new (_("Image")),
+ GTK_WIDGET (page));
+ pages = g_list_append (pages, real_page);
+ }
+
+ g_free (mime_type);
+
+ return pages;
}
-static void
+static void
property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface)
{
- iface->get_pages = get_property_pages;
+ iface->get_pages = get_property_pages;
}
@@ -795,6 +859,5 @@ nautilus_image_properties_page_provider_class_init (NautilusImagePropertiesPageP
void
nautilus_image_properties_page_register (void)
{
- nautilus_module_add_type (nautilus_image_properties_page_provider_get_type ());
+ nautilus_module_add_type (nautilus_image_properties_page_provider_get_type ());
}
-
diff --git a/src/nautilus-keyfile-metadata.c b/src/nautilus-keyfile-metadata.c
index e74711a40..76b4fae11 100644
--- a/src/nautilus-keyfile-metadata.c
+++ b/src/nautilus-keyfile-metadata.c
@@ -34,9 +34,10 @@
#include <sys/stat.h>
#include <fcntl.h>
-typedef struct {
- GKeyFile *keyfile;
- guint save_in_idle_id;
+typedef struct
+{
+ GKeyFile *keyfile;
+ guint save_in_idle_id;
} KeyfileMetadataData;
static GHashTable *data_hash = NULL;
@@ -44,273 +45,299 @@ static GHashTable *data_hash = NULL;
static KeyfileMetadataData *
keyfile_metadata_data_new (const char *keyfile_filename)
{
- KeyfileMetadataData *data;
- GKeyFile *retval;
- GError *error = NULL;
-
- retval = g_key_file_new ();
-
- g_key_file_load_from_file (retval,
- keyfile_filename,
- G_KEY_FILE_NONE,
- &error);
-
- if (error != NULL) {
- if (!g_error_matches (error,
- G_FILE_ERROR,
- G_FILE_ERROR_NOENT)) {
- g_print ("Unable to open the desktop metadata keyfile: %s\n",
- error->message);
- }
-
- g_error_free (error);
- }
-
- data = g_slice_new0 (KeyfileMetadataData);
- data->keyfile = retval;
-
- return data;
+ KeyfileMetadataData *data;
+ GKeyFile *retval;
+ GError *error = NULL;
+
+ retval = g_key_file_new ();
+
+ g_key_file_load_from_file (retval,
+ keyfile_filename,
+ G_KEY_FILE_NONE,
+ &error);
+
+ if (error != NULL)
+ {
+ if (!g_error_matches (error,
+ G_FILE_ERROR,
+ G_FILE_ERROR_NOENT))
+ {
+ g_print ("Unable to open the desktop metadata keyfile: %s\n",
+ error->message);
+ }
+
+ g_error_free (error);
+ }
+
+ data = g_slice_new0 (KeyfileMetadataData);
+ data->keyfile = retval;
+
+ return data;
}
static void
keyfile_metadata_data_free (KeyfileMetadataData *data)
{
- g_key_file_unref (data->keyfile);
+ g_key_file_unref (data->keyfile);
- if (data->save_in_idle_id != 0) {
- g_source_remove (data->save_in_idle_id);
- }
+ if (data->save_in_idle_id != 0)
+ {
+ g_source_remove (data->save_in_idle_id);
+ }
- g_slice_free (KeyfileMetadataData, data);
+ g_slice_free (KeyfileMetadataData, data);
}
static GKeyFile *
get_keyfile (const char *keyfile_filename)
{
- KeyfileMetadataData *data;
+ KeyfileMetadataData *data;
- if (data_hash == NULL) {
- data_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- (GDestroyNotify) keyfile_metadata_data_free);
- }
+ if (data_hash == NULL)
+ {
+ data_hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ (GDestroyNotify) keyfile_metadata_data_free);
+ }
- data = g_hash_table_lookup (data_hash, keyfile_filename);
+ data = g_hash_table_lookup (data_hash, keyfile_filename);
- if (data == NULL) {
- data = keyfile_metadata_data_new (keyfile_filename);
+ if (data == NULL)
+ {
+ data = keyfile_metadata_data_new (keyfile_filename);
- g_hash_table_insert (data_hash,
- g_strdup (keyfile_filename),
- data);
- }
+ g_hash_table_insert (data_hash,
+ g_strdup (keyfile_filename),
+ data);
+ }
- return data->keyfile;
+ return data->keyfile;
}
static gboolean
save_in_idle_cb (const gchar *keyfile_filename)
{
- KeyfileMetadataData *data;
- gchar *contents;
- gsize length;
- GError *error = NULL;
-
- data = g_hash_table_lookup (data_hash, keyfile_filename);
- data->save_in_idle_id = 0;
-
- contents = g_key_file_to_data (data->keyfile, &length, NULL);
-
- if (contents != NULL) {
- g_file_set_contents (keyfile_filename,
- contents, length,
- &error);
- g_free (contents);
- }
-
- if (error != NULL) {
- g_warning ("Couldn't save the desktop metadata keyfile to disk: %s",
- error->message);
- g_error_free (error);
- }
-
- return FALSE;
+ KeyfileMetadataData *data;
+ gchar *contents;
+ gsize length;
+ GError *error = NULL;
+
+ data = g_hash_table_lookup (data_hash, keyfile_filename);
+ data->save_in_idle_id = 0;
+
+ contents = g_key_file_to_data (data->keyfile, &length, NULL);
+
+ if (contents != NULL)
+ {
+ g_file_set_contents (keyfile_filename,
+ contents, length,
+ &error);
+ g_free (contents);
+ }
+
+ if (error != NULL)
+ {
+ g_warning ("Couldn't save the desktop metadata keyfile to disk: %s",
+ error->message);
+ g_error_free (error);
+ }
+
+ return FALSE;
}
static void
save_in_idle (const char *keyfile_filename)
{
- KeyfileMetadataData *data;
+ KeyfileMetadataData *data;
- g_return_if_fail (data_hash != NULL);
+ g_return_if_fail (data_hash != NULL);
- data = g_hash_table_lookup (data_hash, keyfile_filename);
- g_return_if_fail (data != NULL);
+ data = g_hash_table_lookup (data_hash, keyfile_filename);
+ g_return_if_fail (data != NULL);
- if (data->save_in_idle_id != 0) {
- return;
- }
+ if (data->save_in_idle_id != 0)
+ {
+ return;
+ }
- data->save_in_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
- (GSourceFunc) save_in_idle_cb,
- g_strdup (keyfile_filename),
- g_free);
+ data->save_in_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+ (GSourceFunc) save_in_idle_cb,
+ g_strdup (keyfile_filename),
+ g_free);
}
void
nautilus_keyfile_metadata_set_string (NautilusFile *file,
- const char *keyfile_filename,
- const gchar *name,
- const gchar *key,
- const gchar *string)
+ const char *keyfile_filename,
+ const gchar *name,
+ const gchar *key,
+ const gchar *string)
{
- GKeyFile *keyfile;
+ GKeyFile *keyfile;
- keyfile = get_keyfile (keyfile_filename);
+ keyfile = get_keyfile (keyfile_filename);
- g_key_file_set_string (keyfile,
- name,
- key,
- string);
+ g_key_file_set_string (keyfile,
+ name,
+ key,
+ string);
- save_in_idle (keyfile_filename);
+ save_in_idle (keyfile_filename);
- if (nautilus_keyfile_metadata_update_from_keyfile (file, keyfile_filename, name)) {
- nautilus_file_changed (file);
- }
+ if (nautilus_keyfile_metadata_update_from_keyfile (file, keyfile_filename, name))
+ {
+ nautilus_file_changed (file);
+ }
}
#define STRV_TERMINATOR "@x-nautilus-desktop-metadata-term@"
void
-nautilus_keyfile_metadata_set_stringv (NautilusFile *file,
- const char *keyfile_filename,
- const char *name,
- const char *key,
+nautilus_keyfile_metadata_set_stringv (NautilusFile *file,
+ const char *keyfile_filename,
+ const char *name,
+ const char *key,
const char * const *stringv)
{
- GKeyFile *keyfile;
- guint length;
- gchar **actual_stringv = NULL;
- gboolean free_strv = FALSE;
-
- keyfile = get_keyfile (keyfile_filename);
-
- /* if we would be setting a single-length strv, append a fake
- * terminator to the array, to be able to differentiate it later from
- * the single string case
- */
- length = g_strv_length ((gchar **) stringv);
-
- if (length == 1) {
- actual_stringv = g_malloc0 (3 * sizeof (gchar *));
- actual_stringv[0] = (gchar *) stringv[0];
- actual_stringv[1] = STRV_TERMINATOR;
- actual_stringv[2] = NULL;
-
- length = 2;
- free_strv = TRUE;
- } else {
- actual_stringv = (gchar **) stringv;
- }
-
- g_key_file_set_string_list (keyfile,
- name,
- key,
- (const gchar **) actual_stringv,
- length);
-
- save_in_idle (keyfile_filename);
-
- if (nautilus_keyfile_metadata_update_from_keyfile (file, keyfile_filename, name)) {
- nautilus_file_changed (file);
- }
-
- if (free_strv) {
- g_free (actual_stringv);
- }
+ GKeyFile *keyfile;
+ guint length;
+ gchar **actual_stringv = NULL;
+ gboolean free_strv = FALSE;
+
+ keyfile = get_keyfile (keyfile_filename);
+
+ /* if we would be setting a single-length strv, append a fake
+ * terminator to the array, to be able to differentiate it later from
+ * the single string case
+ */
+ length = g_strv_length ((gchar **) stringv);
+
+ if (length == 1)
+ {
+ actual_stringv = g_malloc0 (3 * sizeof (gchar *));
+ actual_stringv[0] = (gchar *) stringv[0];
+ actual_stringv[1] = STRV_TERMINATOR;
+ actual_stringv[2] = NULL;
+
+ length = 2;
+ free_strv = TRUE;
+ }
+ else
+ {
+ actual_stringv = (gchar **) stringv;
+ }
+
+ g_key_file_set_string_list (keyfile,
+ name,
+ key,
+ (const gchar **) actual_stringv,
+ length);
+
+ save_in_idle (keyfile_filename);
+
+ if (nautilus_keyfile_metadata_update_from_keyfile (file, keyfile_filename, name))
+ {
+ nautilus_file_changed (file);
+ }
+
+ if (free_strv)
+ {
+ g_free (actual_stringv);
+ }
}
gboolean
nautilus_keyfile_metadata_update_from_keyfile (NautilusFile *file,
- const char *keyfile_filename,
- const gchar *name)
+ const char *keyfile_filename,
+ const gchar *name)
{
- gchar **keys, **values;
- const gchar *actual_values[2];
- const gchar *key, *value;
- gchar *gio_key;
- gsize length, values_length;
- GKeyFile *keyfile;
- GFileInfo *info;
- gint idx;
- gboolean res;
-
- keyfile = get_keyfile (keyfile_filename);
-
- keys = g_key_file_get_keys (keyfile,
- name,
- &length,
- NULL);
-
- if (keys == NULL) {
- return FALSE;
- }
-
- info = g_file_info_new ();
-
- for (idx = 0; idx < length; idx++) {
- key = keys[idx];
- values = g_key_file_get_string_list (keyfile,
- name,
- key,
- &values_length,
- NULL);
-
- gio_key = g_strconcat ("metadata::", key, NULL);
-
- if (values_length < 1) {
- continue;
- } else if (values_length == 1) {
- g_file_info_set_attribute_string (info,
- gio_key,
- values[0]);
- } else if (values_length == 2) {
- /* deal with the fact that single-length strv are stored
- * with an additional terminator in the keyfile string, to differentiate
- * them from the regular string case.
- */
- value = values[1];
-
- if (g_strcmp0 (value, STRV_TERMINATOR) == 0) {
- /* if the 2nd value is the terminator, remove it */
- actual_values[0] = values[0];
- actual_values[1] = NULL;
-
- g_file_info_set_attribute_stringv (info,
- gio_key,
- (gchar **) actual_values);
- } else {
- /* otherwise, set it as a regular strv */
- g_file_info_set_attribute_stringv (info,
- gio_key,
- values);
- }
- } else {
- g_file_info_set_attribute_stringv (info,
- gio_key,
- values);
- }
-
- g_free (gio_key);
- g_strfreev (values);
- }
-
- res = nautilus_file_update_metadata_from_info (file, info);
-
- g_strfreev (keys);
- g_object_unref (info);
-
- return res;
+ gchar **keys, **values;
+ const gchar *actual_values[2];
+ const gchar *key, *value;
+ gchar *gio_key;
+ gsize length, values_length;
+ GKeyFile *keyfile;
+ GFileInfo *info;
+ gint idx;
+ gboolean res;
+
+ keyfile = get_keyfile (keyfile_filename);
+
+ keys = g_key_file_get_keys (keyfile,
+ name,
+ &length,
+ NULL);
+
+ if (keys == NULL)
+ {
+ return FALSE;
+ }
+
+ info = g_file_info_new ();
+
+ for (idx = 0; idx < length; idx++)
+ {
+ key = keys[idx];
+ values = g_key_file_get_string_list (keyfile,
+ name,
+ key,
+ &values_length,
+ NULL);
+
+ gio_key = g_strconcat ("metadata::", key, NULL);
+
+ if (values_length < 1)
+ {
+ continue;
+ }
+ else if (values_length == 1)
+ {
+ g_file_info_set_attribute_string (info,
+ gio_key,
+ values[0]);
+ }
+ else if (values_length == 2)
+ {
+ /* deal with the fact that single-length strv are stored
+ * with an additional terminator in the keyfile string, to differentiate
+ * them from the regular string case.
+ */
+ value = values[1];
+
+ if (g_strcmp0 (value, STRV_TERMINATOR) == 0)
+ {
+ /* if the 2nd value is the terminator, remove it */
+ actual_values[0] = values[0];
+ actual_values[1] = NULL;
+
+ g_file_info_set_attribute_stringv (info,
+ gio_key,
+ (gchar **) actual_values);
+ }
+ else
+ {
+ /* otherwise, set it as a regular strv */
+ g_file_info_set_attribute_stringv (info,
+ gio_key,
+ values);
+ }
+ }
+ else
+ {
+ g_file_info_set_attribute_stringv (info,
+ gio_key,
+ values);
+ }
+
+ g_free (gio_key);
+ g_strfreev (values);
+ }
+
+ res = nautilus_file_update_metadata_from_info (file, info);
+
+ g_strfreev (keys);
+ g_object_unref (info);
+
+ return res;
}
diff --git a/src/nautilus-lib-self-check-functions.c b/src/nautilus-lib-self-check-functions.c
index 5793fca0a..11f9288bb 100644
--- a/src/nautilus-lib-self-check-functions.c
+++ b/src/nautilus-lib-self-check-functions.c
@@ -1,35 +1,35 @@
/*
- nautilus-lib-self-check-functions.c: Wrapper for all self check functions
- in Nautilus proper.
-
- Copyright (C) 2000 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * nautilus-lib-self-check-functions.c: Wrapper for all self check functions
+ * in Nautilus proper.
+ *
+ * Copyright (C) 2000 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
-#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
#include "nautilus-lib-self-check-functions.h"
void
nautilus_run_lib_self_checks (void)
{
- NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION (EEL_CALL_SELF_CHECK_FUNCTION)
+ NAUTILUS_LIB_FOR_EACH_SELF_CHECK_FUNCTION (EEL_CALL_SELF_CHECK_FUNCTION)
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/nautilus-link.c b/src/nautilus-link.c
index ddd989649..a16efa212 100644
--- a/src/nautilus-link.c
+++ b/src/nautilus-link.c
@@ -1,24 +1,24 @@
/*
- nautilus-link.c: .desktop link files.
-
- Copyright (C) 2001 Red Hat, 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 historicalied 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, see <http://www.gnu.org/licenses/>.
-
- Authors: Jonathan Blandford <jrb@redhat.com>
- Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-link.c: .desktop link files.
+ *
+ * Copyright (C) 2001 Red Hat, 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 historicalied 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Jonathan Blandford <jrb@redhat.com>
+ * Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include "nautilus-link.h"
@@ -37,551 +37,613 @@
#define MAIN_GROUP "Desktop Entry"
-#define NAUTILUS_LINK_GENERIC_TAG "Link"
-#define NAUTILUS_LINK_TRASH_TAG "X-nautilus-trash"
-#define NAUTILUS_LINK_MOUNT_TAG "FSDevice"
-#define NAUTILUS_LINK_HOME_TAG "X-nautilus-home"
+#define NAUTILUS_LINK_GENERIC_TAG "Link"
+#define NAUTILUS_LINK_TRASH_TAG "X-nautilus-trash"
+#define NAUTILUS_LINK_MOUNT_TAG "FSDevice"
+#define NAUTILUS_LINK_HOME_TAG "X-nautilus-home"
static gboolean
is_link_mime_type (const char *mime_type)
{
- if (mime_type != NULL &&
- g_ascii_strcasecmp (mime_type, "application/x-desktop") == 0) {
- return TRUE;
- }
+ if (mime_type != NULL &&
+ g_ascii_strcasecmp (mime_type, "application/x-desktop") == 0)
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
is_local_file_a_link (const char *uri)
{
- gboolean link;
- GFile *file;
- GFileInfo *info;
- GError *error;
-
- error = NULL;
- link = FALSE;
-
- file = g_file_new_for_uri (uri);
-
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- 0, NULL, &error);
- if (info) {
- link = is_link_mime_type (g_file_info_get_content_type (info));
- g_object_unref (info);
- }
- else {
- g_warning ("Error getting info: %s\n", error->message);
- g_error_free (error);
- }
-
- g_object_unref (file);
-
- return link;
+ gboolean link;
+ GFile *file;
+ GFileInfo *info;
+ GError *error;
+
+ error = NULL;
+ link = FALSE;
+
+ file = g_file_new_for_uri (uri);
+
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ 0, NULL, &error);
+ if (info)
+ {
+ link = is_link_mime_type (g_file_info_get_content_type (info));
+ g_object_unref (info);
+ }
+ else
+ {
+ g_warning ("Error getting info: %s\n", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (file);
+
+ return link;
}
static gboolean
-_g_key_file_load_from_gfile (GKeyFile *key_file,
- GFile *file,
- GKeyFileFlags flags,
- GError **error)
+_g_key_file_load_from_gfile (GKeyFile *key_file,
+ GFile *file,
+ GKeyFileFlags flags,
+ GError **error)
{
- char *data;
- gsize len;
- gboolean res;
-
- if (!g_file_load_contents (file, NULL, &data, &len, NULL, error)) {
- return FALSE;
- }
-
- res = g_key_file_load_from_data (key_file, data, len, flags, error);
-
- g_free (data);
-
- return res;
+ char *data;
+ gsize len;
+ gboolean res;
+
+ if (!g_file_load_contents (file, NULL, &data, &len, NULL, error))
+ {
+ return FALSE;
+ }
+
+ res = g_key_file_load_from_data (key_file, data, len, flags, error);
+
+ g_free (data);
+
+ return res;
}
static gboolean
-_g_key_file_save_to_gfile (GKeyFile *key_file,
- GFile *file,
- GError **error)
+_g_key_file_save_to_gfile (GKeyFile *key_file,
+ GFile *file,
+ GError **error)
{
- char *data;
- gsize len;
-
- data = g_key_file_to_data (key_file, &len, error);
- if (data == NULL) {
- return FALSE;
- }
-
- if (!g_file_replace_contents (file,
- data, len,
- NULL, FALSE,
- G_FILE_CREATE_NONE,
- NULL, NULL, error)) {
- g_free (data);
- return FALSE;
- }
- g_free (data);
- return TRUE;
+ char *data;
+ gsize len;
+
+ data = g_key_file_to_data (key_file, &len, error);
+ if (data == NULL)
+ {
+ return FALSE;
+ }
+
+ if (!g_file_replace_contents (file,
+ data, len,
+ NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL, NULL, error))
+ {
+ g_free (data);
+ return FALSE;
+ }
+ g_free (data);
+ return TRUE;
}
static GKeyFile *
-_g_key_file_new_from_uri (const char *uri,
- GKeyFileFlags flags,
- GError **error)
+_g_key_file_new_from_uri (const char *uri,
+ GKeyFileFlags flags,
+ GError **error)
{
- GKeyFile *key_file;
- GFile *file;
-
- file = g_file_new_for_uri (uri);
- key_file = g_key_file_new ();
- if (!_g_key_file_load_from_gfile (key_file, file, flags, error)) {
- g_key_file_free (key_file);
- key_file = NULL;
- }
- g_object_unref (file);
- return key_file;
+ GKeyFile *key_file;
+ GFile *file;
+
+ file = g_file_new_for_uri (uri);
+ key_file = g_key_file_new ();
+ if (!_g_key_file_load_from_gfile (key_file, file, flags, error))
+ {
+ g_key_file_free (key_file);
+ key_file = NULL;
+ }
+ g_object_unref (file);
+ return key_file;
}
static char *
slurp_key_string (const char *uri,
- const char *keyname,
+ const char *keyname,
gboolean localize)
{
- GKeyFile *key_file;
- char *result;
-
- key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
- if (key_file == NULL) {
- return NULL;
- }
-
- if (localize) {
- result = g_key_file_get_locale_string (key_file, MAIN_GROUP, keyname, NULL, NULL);
- } else {
- result = g_key_file_get_string (key_file, MAIN_GROUP, keyname, NULL);
- }
- g_key_file_free (key_file);
-
- return result;
+ GKeyFile *key_file;
+ char *result;
+
+ key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
+ if (key_file == NULL)
+ {
+ return NULL;
+ }
+
+ if (localize)
+ {
+ result = g_key_file_get_locale_string (key_file, MAIN_GROUP, keyname, NULL, NULL);
+ }
+ else
+ {
+ result = g_key_file_get_string (key_file, MAIN_GROUP, keyname, NULL);
+ }
+ g_key_file_free (key_file);
+
+ return result;
}
gboolean
nautilus_link_local_create (const char *directory_uri,
- const char *base_name,
- const char *display_name,
- const char *image,
- const char *target_uri,
- const GdkPoint *point,
- int screen,
- gboolean unique_filename)
+ const char *base_name,
+ const char *display_name,
+ const char *image,
+ const char *target_uri,
+ const GdkPoint *point,
+ int screen,
+ gboolean unique_filename)
{
- char *real_directory_uri;
- char *contents;
- GFile *file;
- GList dummy_list;
- NautilusFileChangesQueuePosition item;
- g_autofree char *link_name = NULL;
- g_autoptr (GFile) directory = NULL;
-
- g_return_val_if_fail (directory_uri != NULL, FALSE);
- g_return_val_if_fail (base_name != NULL, FALSE);
- g_return_val_if_fail (display_name != NULL, FALSE);
- g_return_val_if_fail (target_uri != NULL, FALSE);
-
- if (eel_uri_is_trash (directory_uri) ||
- eel_uri_is_search (directory_uri)) {
- return FALSE;
- }
-
- if (eel_uri_is_desktop (directory_uri)) {
- real_directory_uri = nautilus_get_desktop_directory_uri ();
- } else {
- real_directory_uri = g_strdup (directory_uri);
- }
-
- link_name = g_strdup_printf ("%s.desktop", base_name);
- directory = g_file_new_for_uri (real_directory_uri);
-
- if (unique_filename) {
- file = nautilus_generate_unique_file_in_directory (directory,
- link_name);
- } else {
- /* replace '/' with '-', just in case */
- g_strdelimit (link_name, "/", '-');
-
- file = g_file_get_child (directory, link_name);
- }
-
- g_free (real_directory_uri);
-
- contents = g_strdup_printf ("[Desktop Entry]\n"
- "Encoding=UTF-8\n"
- "Name=%s\n"
- "Type=Link\n"
- "URL=%s\n"
- "%s%s\n",
- display_name,
- target_uri,
- image != NULL ? "Icon=" : "",
- image != NULL ? image : "");
-
-
- if (!g_file_replace_contents (file,
- contents, strlen (contents),
- NULL, FALSE,
- G_FILE_CREATE_NONE,
- NULL, NULL, NULL)) {
- g_free (contents);
- g_object_unref (file);
- return FALSE;
- }
- g_free (contents);
-
- dummy_list.data = file;
- dummy_list.next = NULL;
- dummy_list.prev = NULL;
- nautilus_directory_notify_files_added (&dummy_list);
-
- if (point != NULL) {
- item.location = file;
- item.set = TRUE;
- item.point.x = point->x;
- item.point.y = point->y;
- item.screen = screen;
- dummy_list.data = &item;
- dummy_list.next = NULL;
- dummy_list.prev = NULL;
-
- nautilus_directory_schedule_position_set (&dummy_list);
- }
-
- g_object_unref (file);
- return TRUE;
+ char *real_directory_uri;
+ char *contents;
+ GFile *file;
+ GList dummy_list;
+ NautilusFileChangesQueuePosition item;
+ g_autofree char *link_name = NULL;
+ g_autoptr (GFile) directory = NULL;
+
+ g_return_val_if_fail (directory_uri != NULL, FALSE);
+ g_return_val_if_fail (base_name != NULL, FALSE);
+ g_return_val_if_fail (display_name != NULL, FALSE);
+ g_return_val_if_fail (target_uri != NULL, FALSE);
+
+ if (eel_uri_is_trash (directory_uri) ||
+ eel_uri_is_search (directory_uri))
+ {
+ return FALSE;
+ }
+
+ if (eel_uri_is_desktop (directory_uri))
+ {
+ real_directory_uri = nautilus_get_desktop_directory_uri ();
+ }
+ else
+ {
+ real_directory_uri = g_strdup (directory_uri);
+ }
+
+ link_name = g_strdup_printf ("%s.desktop", base_name);
+ directory = g_file_new_for_uri (real_directory_uri);
+
+ if (unique_filename)
+ {
+ file = nautilus_generate_unique_file_in_directory (directory,
+ link_name);
+ }
+ else
+ {
+ /* replace '/' with '-', just in case */
+ g_strdelimit (link_name, "/", '-');
+
+ file = g_file_get_child (directory, link_name);
+ }
+
+ g_free (real_directory_uri);
+
+ contents = g_strdup_printf ("[Desktop Entry]\n"
+ "Encoding=UTF-8\n"
+ "Name=%s\n"
+ "Type=Link\n"
+ "URL=%s\n"
+ "%s%s\n",
+ display_name,
+ target_uri,
+ image != NULL ? "Icon=" : "",
+ image != NULL ? image : "");
+
+
+ if (!g_file_replace_contents (file,
+ contents, strlen (contents),
+ NULL, FALSE,
+ G_FILE_CREATE_NONE,
+ NULL, NULL, NULL))
+ {
+ g_free (contents);
+ g_object_unref (file);
+ return FALSE;
+ }
+ g_free (contents);
+
+ dummy_list.data = file;
+ dummy_list.next = NULL;
+ dummy_list.prev = NULL;
+ nautilus_directory_notify_files_added (&dummy_list);
+
+ if (point != NULL)
+ {
+ item.location = file;
+ item.set = TRUE;
+ item.point.x = point->x;
+ item.point.y = point->y;
+ item.screen = screen;
+ dummy_list.data = &item;
+ dummy_list.next = NULL;
+ dummy_list.prev = NULL;
+
+ nautilus_directory_schedule_position_set (&dummy_list);
+ }
+
+ g_object_unref (file);
+ return TRUE;
}
static const char *
get_language (void)
{
- const char * const *langs_pointer;
- int i;
-
- langs_pointer = g_get_language_names ();
- for (i = 0; langs_pointer[i] != NULL; i++) {
- /* find first without encoding */
- if (strchr (langs_pointer[i], '.') == NULL) {
- return langs_pointer[i];
- }
- }
- return NULL;
-}
+ const char * const *langs_pointer;
+ int i;
+
+ langs_pointer = g_get_language_names ();
+ for (i = 0; langs_pointer[i] != NULL; i++)
+ {
+ /* find first without encoding */
+ if (strchr (langs_pointer[i], '.') == NULL)
+ {
+ return langs_pointer[i];
+ }
+ }
+ return NULL;
+}
static gboolean
nautilus_link_local_set_key (const char *uri,
- const char *key,
- const char *value,
- gboolean localize)
+ const char *key,
+ const char *value,
+ gboolean localize)
{
- gboolean success;
- GKeyFile *key_file;
- GFile *file;
-
- file = g_file_new_for_uri (uri);
- key_file = g_key_file_new ();
- if (!_g_key_file_load_from_gfile (key_file, file, G_KEY_FILE_KEEP_COMMENTS, NULL)) {
- g_key_file_free (key_file);
- g_object_unref (file);
- return FALSE;
- }
- if (localize) {
- g_key_file_set_locale_string (key_file,
- MAIN_GROUP,
- key,
- get_language (),
- value);
- } else {
- g_key_file_set_string (key_file, MAIN_GROUP, key, value);
- }
-
-
- success = _g_key_file_save_to_gfile (key_file, file, NULL);
- g_key_file_free (key_file);
- g_object_unref (file);
- return success;
+ gboolean success;
+ GKeyFile *key_file;
+ GFile *file;
+
+ file = g_file_new_for_uri (uri);
+ key_file = g_key_file_new ();
+ if (!_g_key_file_load_from_gfile (key_file, file, G_KEY_FILE_KEEP_COMMENTS, NULL))
+ {
+ g_key_file_free (key_file);
+ g_object_unref (file);
+ return FALSE;
+ }
+ if (localize)
+ {
+ g_key_file_set_locale_string (key_file,
+ MAIN_GROUP,
+ key,
+ get_language (),
+ value);
+ }
+ else
+ {
+ g_key_file_set_string (key_file, MAIN_GROUP, key, value);
+ }
+
+
+ success = _g_key_file_save_to_gfile (key_file, file, NULL);
+ g_key_file_free (key_file);
+ g_object_unref (file);
+ return success;
}
gboolean
nautilus_link_local_set_text (const char *uri,
- const char *text)
+ const char *text)
{
- return nautilus_link_local_set_key (uri, "Name", text, TRUE);
+ return nautilus_link_local_set_key (uri, "Name", text, TRUE);
}
gboolean
-nautilus_link_local_set_icon (const char *uri,
- const char *icon)
+nautilus_link_local_set_icon (const char *uri,
+ const char *icon)
{
- return nautilus_link_local_set_key (uri, "Icon", icon, FALSE);
+ return nautilus_link_local_set_key (uri, "Icon", icon, FALSE);
}
char *
nautilus_link_local_get_text (const char *path)
{
- return slurp_key_string (path, "Name", TRUE);
+ return slurp_key_string (path, "Name", TRUE);
}
static char *
-nautilus_link_get_link_uri_from_desktop (GKeyFile *key_file, const char *desktop_file_uri)
+nautilus_link_get_link_uri_from_desktop (GKeyFile *key_file,
+ const char *desktop_file_uri)
{
- GFile *file, *parent;
- char *type;
- char *retval;
- char *scheme;
-
- retval = NULL;
-
- type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
- if (type == NULL) {
- return NULL;
- }
-
- if (strcmp (type, "URL") == 0) {
- /* Some old broken desktop files use this nonstandard feature, we need handle it though */
- retval = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL);
- } else if ((strcmp (type, NAUTILUS_LINK_GENERIC_TAG) == 0) ||
- (strcmp (type, NAUTILUS_LINK_MOUNT_TAG) == 0) ||
- (strcmp (type, NAUTILUS_LINK_TRASH_TAG) == 0) ||
- (strcmp (type, NAUTILUS_LINK_HOME_TAG) == 0)) {
- retval = g_key_file_get_string (key_file, MAIN_GROUP, "URL", NULL);
- }
- g_free (type);
-
- if (retval != NULL && desktop_file_uri != NULL) {
- /* Handle local file names.
- * Ideally, we'd be able to use
- * g_file_parse_name(), but it does not know how to resolve
- * relative file names, since the base directory is unknown.
- */
- scheme = g_uri_parse_scheme (retval);
- if (scheme == NULL) {
- file = g_file_new_for_uri (desktop_file_uri);
- parent = g_file_get_parent (file);
- g_object_unref (file);
-
- if (parent != NULL) {
- file = g_file_resolve_relative_path (parent, retval);
- g_free (retval);
- retval = g_file_get_uri (file);
- g_object_unref (file);
- g_object_unref (parent);
- }
- }
- g_free (scheme);
- }
-
- return retval;
+ GFile *file, *parent;
+ char *type;
+ char *retval;
+ char *scheme;
+
+ retval = NULL;
+
+ type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
+ if (type == NULL)
+ {
+ return NULL;
+ }
+
+ if (strcmp (type, "URL") == 0)
+ {
+ /* Some old broken desktop files use this nonstandard feature, we need handle it though */
+ retval = g_key_file_get_string (key_file, MAIN_GROUP, "Exec", NULL);
+ }
+ else if ((strcmp (type, NAUTILUS_LINK_GENERIC_TAG) == 0) ||
+ (strcmp (type, NAUTILUS_LINK_MOUNT_TAG) == 0) ||
+ (strcmp (type, NAUTILUS_LINK_TRASH_TAG) == 0) ||
+ (strcmp (type, NAUTILUS_LINK_HOME_TAG) == 0))
+ {
+ retval = g_key_file_get_string (key_file, MAIN_GROUP, "URL", NULL);
+ }
+ g_free (type);
+
+ if (retval != NULL && desktop_file_uri != NULL)
+ {
+ /* Handle local file names.
+ * Ideally, we'd be able to use
+ * g_file_parse_name(), but it does not know how to resolve
+ * relative file names, since the base directory is unknown.
+ */
+ scheme = g_uri_parse_scheme (retval);
+ if (scheme == NULL)
+ {
+ file = g_file_new_for_uri (desktop_file_uri);
+ parent = g_file_get_parent (file);
+ g_object_unref (file);
+
+ if (parent != NULL)
+ {
+ file = g_file_resolve_relative_path (parent, retval);
+ g_free (retval);
+ retval = g_file_get_uri (file);
+ g_object_unref (file);
+ g_object_unref (parent);
+ }
+ }
+ g_free (scheme);
+ }
+
+ return retval;
}
static char *
nautilus_link_get_link_name_from_desktop (GKeyFile *key_file)
{
- return g_key_file_get_locale_string (key_file, MAIN_GROUP, "Name", NULL, NULL);
+ return g_key_file_get_locale_string (key_file, MAIN_GROUP, "Name", NULL, NULL);
}
static GIcon *
nautilus_link_get_link_icon_from_desktop (GKeyFile *key_file)
{
- char *icon_str, *p, *type = NULL;
- GFile *file;
- GIcon *icon;
-
- /* Look at the Icon: key */
- icon_str = g_key_file_get_string (key_file, MAIN_GROUP, "Icon", NULL);
-
- /* if it's an absolute path, return a GFileIcon for that path */
- if (icon_str != NULL && g_path_is_absolute (icon_str)) {
- file = g_file_new_for_path (icon_str);
- icon = g_file_icon_new (file);
-
- g_object_unref (file);
-
- goto out;
- }
-
- type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
-
- if (icon_str == NULL) {
- if (g_strcmp0 (type, "Application") == 0) {
- icon_str = g_strdup ("application-x-executable");
- } else if (g_strcmp0 (type, "FSDevice") == 0) {
- icon_str = g_strdup ("drive-harddisk");
- } else if (g_strcmp0 (type, "Directory") == 0) {
- icon_str = g_strdup (NAUTILUS_ICON_FOLDER);
- } else if (g_strcmp0 (type, "Service") == 0 ||
- g_strcmp0 (type, "ServiceType") == 0) {
- icon_str = g_strdup ("folder-remote");
- } else {
- icon_str = g_strdup ("text-x-preview");
- }
- } else {
- /* Strip out any extension on non-filename icons. Old desktop files may have this */
- p = strchr (icon_str, '.');
- /* Only strip known icon extensions */
- if ((p != NULL) &&
- ((g_ascii_strcasecmp (p, ".png") == 0)
- || (g_ascii_strcasecmp (p, ".svn") == 0)
- || (g_ascii_strcasecmp (p, ".jpg") == 0)
- || (g_ascii_strcasecmp (p, ".xpm") == 0)
- || (g_ascii_strcasecmp (p, ".bmp") == 0)
- || (g_ascii_strcasecmp (p, ".jpeg") == 0))) {
- *p = 0;
- }
- }
-
- icon = g_themed_icon_new_with_default_fallbacks (icon_str);
-
- /* apply a link emblem if it's a link */
- if (g_strcmp0 (type, "Link") == 0) {
- GIcon *emblemed, *emblem_icon;
- GEmblem *emblem;
-
- emblem_icon = g_themed_icon_new ("emblem-symbolic-link");
- emblem = g_emblem_new (emblem_icon);
-
- emblemed = g_emblemed_icon_new (icon, emblem);
-
- g_object_unref (icon);
- g_object_unref (emblem_icon);
- g_object_unref (emblem);
-
- icon = emblemed;
- }
-
- out:
- g_free (icon_str);
- g_free (type);
-
- return icon;
+ char *icon_str, *p, *type = NULL;
+ GFile *file;
+ GIcon *icon;
+
+ /* Look at the Icon: key */
+ icon_str = g_key_file_get_string (key_file, MAIN_GROUP, "Icon", NULL);
+
+ /* if it's an absolute path, return a GFileIcon for that path */
+ if (icon_str != NULL && g_path_is_absolute (icon_str))
+ {
+ file = g_file_new_for_path (icon_str);
+ icon = g_file_icon_new (file);
+
+ g_object_unref (file);
+
+ goto out;
+ }
+
+ type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
+
+ if (icon_str == NULL)
+ {
+ if (g_strcmp0 (type, "Application") == 0)
+ {
+ icon_str = g_strdup ("application-x-executable");
+ }
+ else if (g_strcmp0 (type, "FSDevice") == 0)
+ {
+ icon_str = g_strdup ("drive-harddisk");
+ }
+ else if (g_strcmp0 (type, "Directory") == 0)
+ {
+ icon_str = g_strdup (NAUTILUS_ICON_FOLDER);
+ }
+ else if (g_strcmp0 (type, "Service") == 0 ||
+ g_strcmp0 (type, "ServiceType") == 0)
+ {
+ icon_str = g_strdup ("folder-remote");
+ }
+ else
+ {
+ icon_str = g_strdup ("text-x-preview");
+ }
+ }
+ else
+ {
+ /* Strip out any extension on non-filename icons. Old desktop files may have this */
+ p = strchr (icon_str, '.');
+ /* Only strip known icon extensions */
+ if ((p != NULL) &&
+ ((g_ascii_strcasecmp (p, ".png") == 0)
+ || (g_ascii_strcasecmp (p, ".svn") == 0)
+ || (g_ascii_strcasecmp (p, ".jpg") == 0)
+ || (g_ascii_strcasecmp (p, ".xpm") == 0)
+ || (g_ascii_strcasecmp (p, ".bmp") == 0)
+ || (g_ascii_strcasecmp (p, ".jpeg") == 0)))
+ {
+ *p = 0;
+ }
+ }
+
+ icon = g_themed_icon_new_with_default_fallbacks (icon_str);
+
+ /* apply a link emblem if it's a link */
+ if (g_strcmp0 (type, "Link") == 0)
+ {
+ GIcon *emblemed, *emblem_icon;
+ GEmblem *emblem;
+
+ emblem_icon = g_themed_icon_new ("emblem-symbolic-link");
+ emblem = g_emblem_new (emblem_icon);
+
+ emblemed = g_emblemed_icon_new (icon, emblem);
+
+ g_object_unref (icon);
+ g_object_unref (emblem_icon);
+ g_object_unref (emblem);
+
+ icon = emblemed;
+ }
+
+out:
+ g_free (icon_str);
+ g_free (type);
+
+ return icon;
}
char *
nautilus_link_local_get_link_uri (const char *uri)
{
- GKeyFile *key_file;
- char *retval;
+ GKeyFile *key_file;
+ char *retval;
- if (!is_local_file_a_link (uri)) {
- return NULL;
- }
+ if (!is_local_file_a_link (uri))
+ {
+ return NULL;
+ }
- key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
- if (key_file == NULL) {
- return NULL;
- }
+ key_file = _g_key_file_new_from_uri (uri, G_KEY_FILE_NONE, NULL);
+ if (key_file == NULL)
+ {
+ return NULL;
+ }
- retval = nautilus_link_get_link_uri_from_desktop (key_file, uri);
- g_key_file_free (key_file);
+ retval = nautilus_link_get_link_uri_from_desktop (key_file, uri);
+ g_key_file_free (key_file);
- return retval;
+ return retval;
}
static gboolean
string_array_contains (gchar **array,
gchar **desktop_names)
{
- gchar **p;
- gchar **desktop;
-
- if (!array)
- return FALSE;
-
- for (p = array; *p; p++) {
- for (desktop = desktop_names; *desktop; desktop++) {
- if (g_ascii_strcasecmp (*p, *desktop) == 0)
- return TRUE;
- }
- }
-
- return FALSE;
+ gchar **p;
+ gchar **desktop;
+
+ if (!array)
+ {
+ return FALSE;
+ }
+
+ for (p = array; *p; p++)
+ {
+ for (desktop = desktop_names; *desktop; desktop++)
+ {
+ if (g_ascii_strcasecmp (*p, *desktop) == 0)
+ {
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
}
static gchar **
get_desktop_names (void)
{
- const gchar *current_desktop;
+ const gchar *current_desktop;
- current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
+ current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
- if (current_desktop == NULL || current_desktop[0] == 0) {
- /* historic behavior */
- current_desktop = "GNOME";
- }
+ if (current_desktop == NULL || current_desktop[0] == 0)
+ {
+ /* historic behavior */
+ current_desktop = "GNOME";
+ }
- return g_strsplit (current_desktop, ":", -1);
+ return g_strsplit (current_desktop, ":", -1);
}
void
nautilus_link_get_link_info_given_file_contents (const char *file_contents,
- int link_file_size,
- const char *file_uri,
- char **uri,
- char **name,
- GIcon **icon,
- gboolean *is_launcher,
- gboolean *is_foreign)
+ int link_file_size,
+ const char *file_uri,
+ char **uri,
+ char **name,
+ GIcon **icon,
+ gboolean *is_launcher,
+ gboolean *is_foreign)
{
- GKeyFile *key_file;
- gchar **desktop_names;
- char *type;
- char **only_show_in;
- char **not_show_in;
-
- key_file = g_key_file_new ();
- if (!g_key_file_load_from_data (key_file,
- file_contents,
- link_file_size,
- G_KEY_FILE_NONE,
- NULL)) {
- g_key_file_free (key_file);
- return;
- }
-
- desktop_names = get_desktop_names ();
-
- *uri = nautilus_link_get_link_uri_from_desktop (key_file, file_uri);
- *name = nautilus_link_get_link_name_from_desktop (key_file);
- *icon = nautilus_link_get_link_icon_from_desktop (key_file);
-
- *is_launcher = FALSE;
- type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
- if (g_strcmp0 (type, "Application") == 0 &&
- g_key_file_has_key (key_file, MAIN_GROUP, "Exec", NULL)) {
- *is_launcher = TRUE;
- }
- g_free (type);
-
- *is_foreign = FALSE;
- only_show_in = g_key_file_get_string_list (key_file, MAIN_GROUP,
- "OnlyShowIn", NULL, NULL);
- if (only_show_in && !string_array_contains (only_show_in, desktop_names)) {
- *is_foreign = TRUE;
- }
- g_strfreev (only_show_in);
-
- not_show_in = g_key_file_get_string_list (key_file, MAIN_GROUP,
- "NotShowIn", NULL, NULL);
- if (not_show_in && string_array_contains (not_show_in, desktop_names)) {
- *is_foreign = TRUE;
- }
- g_strfreev (not_show_in);
-
- g_strfreev (desktop_names);
- g_key_file_free (key_file);
+ GKeyFile *key_file;
+ gchar **desktop_names;
+ char *type;
+ char **only_show_in;
+ char **not_show_in;
+
+ key_file = g_key_file_new ();
+ if (!g_key_file_load_from_data (key_file,
+ file_contents,
+ link_file_size,
+ G_KEY_FILE_NONE,
+ NULL))
+ {
+ g_key_file_free (key_file);
+ return;
+ }
+
+ desktop_names = get_desktop_names ();
+
+ *uri = nautilus_link_get_link_uri_from_desktop (key_file, file_uri);
+ *name = nautilus_link_get_link_name_from_desktop (key_file);
+ *icon = nautilus_link_get_link_icon_from_desktop (key_file);
+
+ *is_launcher = FALSE;
+ type = g_key_file_get_string (key_file, MAIN_GROUP, "Type", NULL);
+ if (g_strcmp0 (type, "Application") == 0 &&
+ g_key_file_has_key (key_file, MAIN_GROUP, "Exec", NULL))
+ {
+ *is_launcher = TRUE;
+ }
+ g_free (type);
+
+ *is_foreign = FALSE;
+ only_show_in = g_key_file_get_string_list (key_file, MAIN_GROUP,
+ "OnlyShowIn", NULL, NULL);
+ if (only_show_in && !string_array_contains (only_show_in, desktop_names))
+ {
+ *is_foreign = TRUE;
+ }
+ g_strfreev (only_show_in);
+
+ not_show_in = g_key_file_get_string_list (key_file, MAIN_GROUP,
+ "NotShowIn", NULL, NULL);
+ if (not_show_in && string_array_contains (not_show_in, desktop_names))
+ {
+ *is_foreign = TRUE;
+ }
+ g_strfreev (not_show_in);
+
+ g_strfreev (desktop_names);
+ g_key_file_free (key_file);
}
diff --git a/src/nautilus-list-model.c b/src/nautilus-list-model.c
index fe7fea2cf..3bf0d917e 100644
--- a/src/nautilus-list-model.c
+++ b/src/nautilus-list-model.c
@@ -1,26 +1,25 @@
-
-/* fm-list-model.h - a GtkTreeModel for file lists.
-
- Copyright (C) 2001, 2002 Anders Carlsson
- Copyright (C) 2003, Soeren Sandmann
- Copyright (C) 2004, Novell, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Anders Carlsson <andersca@gnu.org>, Soeren Sandmann (sandmann@daimi.au.dk), Dave Camp <dave@ximian.com>
-*/
+/* fm-list-model.h - a GtkTreeModel for file lists.
+ *
+ * Copyright (C) 2001, 2002 Anders Carlsson
+ * Copyright (C) 2003, Soeren Sandmann
+ * Copyright (C) 2004, Novell, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Anders Carlsson <andersca@gnu.org>, Soeren Sandmann (sandmann@daimi.au.dk), Dave Camp <dave@ximian.com>
+ */
#include <config.h>
@@ -35,15 +34,16 @@
#include <eel/eel-graphic-effects.h>
#include "nautilus-dnd.h"
-enum {
- SUBDIRECTORY_UNLOADED,
- GET_ICON_SCALE,
- LAST_SIGNAL
+enum
+{
+ SUBDIRECTORY_UNLOADED,
+ GET_ICON_SCALE,
+ LAST_SIGNAL
};
static GQuark attribute_name_q,
- attribute_modification_date_q,
- attribute_date_modified_q;
+ attribute_modification_date_q,
+ attribute_date_modified_q;
/* msec delay after Loading... dummy row turns into (empty) */
#define LOADING_TO_EMPTY_DELAY 100
@@ -51,1366 +51,1586 @@ static GQuark attribute_name_q,
static guint list_model_signals[LAST_SIGNAL] = { 0 };
static int nautilus_list_model_file_entry_compare_func (gconstpointer a,
- gconstpointer b,
- gpointer user_data);
+ gconstpointer b,
+ gpointer user_data);
static void nautilus_list_model_tree_model_init (GtkTreeModelIface *iface);
static void nautilus_list_model_sortable_init (GtkTreeSortableIface *iface);
-struct NautilusListModelDetails {
- GSequence *files;
- GHashTable *directory_reverse_map; /* map from directory to GSequenceIter's */
- GHashTable *top_reverse_map; /* map from files in top dir to GSequenceIter's */
+struct NautilusListModelDetails
+{
+ GSequence *files;
+ GHashTable *directory_reverse_map; /* map from directory to GSequenceIter's */
+ GHashTable *top_reverse_map; /* map from files in top dir to GSequenceIter's */
- int stamp;
+ int stamp;
- GQuark sort_attribute;
- GtkSortType order;
+ GQuark sort_attribute;
+ GtkSortType order;
- gboolean sort_directories_first;
+ gboolean sort_directories_first;
- GtkTreeView *drag_view;
- int drag_begin_x;
- int drag_begin_y;
+ GtkTreeView *drag_view;
+ int drag_begin_x;
+ int drag_begin_y;
- GPtrArray *columns;
+ GPtrArray *columns;
- GList *highlight_files;
+ GList *highlight_files;
};
-typedef struct {
- NautilusListModel *model;
-
- GList *path_list;
+typedef struct
+{
+ NautilusListModel *model;
+
+ GList *path_list;
} DragDataGetInfo;
typedef struct FileEntry FileEntry;
-struct FileEntry {
- NautilusFile *file;
- GHashTable *reverse_map; /* map from files to GSequenceIter's */
- NautilusDirectory *subdirectory;
- FileEntry *parent;
- GSequence *files;
- GSequenceIter *ptr;
- guint loaded : 1;
+struct FileEntry
+{
+ NautilusFile *file;
+ GHashTable *reverse_map; /* map from files to GSequenceIter's */
+ NautilusDirectory *subdirectory;
+ FileEntry *parent;
+ GSequence *files;
+ GSequenceIter *ptr;
+ guint loaded : 1;
};
G_DEFINE_TYPE_WITH_CODE (NautilusListModel, nautilus_list_model, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
- nautilus_list_model_tree_model_init)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE,
- nautilus_list_model_sortable_init));
-
-static const GtkTargetEntry drag_types [] = {
- { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
- { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
+ nautilus_list_model_tree_model_init)
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE,
+ nautilus_list_model_sortable_init));
+
+static const GtkTargetEntry drag_types [] =
+{
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
+ { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
};
static void
file_entry_free (FileEntry *file_entry)
{
- nautilus_file_unref (file_entry->file);
- if (file_entry->reverse_map) {
- g_hash_table_destroy (file_entry->reverse_map);
- file_entry->reverse_map = NULL;
- }
- if (file_entry->subdirectory != NULL) {
- nautilus_directory_unref (file_entry->subdirectory);
- }
- if (file_entry->files != NULL) {
- g_sequence_free (file_entry->files);
- }
- g_free (file_entry);
+ nautilus_file_unref (file_entry->file);
+ if (file_entry->reverse_map)
+ {
+ g_hash_table_destroy (file_entry->reverse_map);
+ file_entry->reverse_map = NULL;
+ }
+ if (file_entry->subdirectory != NULL)
+ {
+ nautilus_directory_unref (file_entry->subdirectory);
+ }
+ if (file_entry->files != NULL)
+ {
+ g_sequence_free (file_entry->files);
+ }
+ g_free (file_entry);
}
static GtkTreeModelFlags
nautilus_list_model_get_flags (GtkTreeModel *tree_model)
{
- return GTK_TREE_MODEL_ITERS_PERSIST;
+ return GTK_TREE_MODEL_ITERS_PERSIST;
}
static int
nautilus_list_model_get_n_columns (GtkTreeModel *tree_model)
{
- return NAUTILUS_LIST_MODEL_NUM_COLUMNS + NAUTILUS_LIST_MODEL (tree_model)->details->columns->len;
+ return NAUTILUS_LIST_MODEL_NUM_COLUMNS + NAUTILUS_LIST_MODEL (tree_model)->details->columns->len;
}
static GType
-nautilus_list_model_get_column_type (GtkTreeModel *tree_model, int index)
-{
- switch (index) {
- case NAUTILUS_LIST_MODEL_FILE_COLUMN:
- return NAUTILUS_TYPE_FILE;
- case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
- return NAUTILUS_TYPE_DIRECTORY;
- case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
- case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
- case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
- case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
- return CAIRO_GOBJECT_TYPE_SURFACE;
- case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
- return G_TYPE_BOOLEAN;
- default:
- if (index < NAUTILUS_LIST_MODEL_NUM_COLUMNS + NAUTILUS_LIST_MODEL (tree_model)->details->columns->len) {
- return G_TYPE_STRING;
- } else {
- return G_TYPE_INVALID;
- }
- }
+nautilus_list_model_get_column_type (GtkTreeModel *tree_model,
+ int index)
+{
+ switch (index)
+ {
+ case NAUTILUS_LIST_MODEL_FILE_COLUMN:
+ {
+ return NAUTILUS_TYPE_FILE;
+ }
+
+ case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
+ {
+ return NAUTILUS_TYPE_DIRECTORY;
+ }
+
+ case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
+ case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
+ case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
+ case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
+ {
+ return CAIRO_GOBJECT_TYPE_SURFACE;
+ }
+
+ case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
+ {
+ return G_TYPE_BOOLEAN;
+ }
+
+ default:
+ if (index < NAUTILUS_LIST_MODEL_NUM_COLUMNS + NAUTILUS_LIST_MODEL (tree_model)->details->columns->len)
+ {
+ return G_TYPE_STRING;
+ }
+ else
+ {
+ return G_TYPE_INVALID;
+ }
+ }
}
static void
-nautilus_list_model_ptr_to_iter (NautilusListModel *model, GSequenceIter *ptr, GtkTreeIter *iter)
+nautilus_list_model_ptr_to_iter (NautilusListModel *model,
+ GSequenceIter *ptr,
+ GtkTreeIter *iter)
{
- g_assert (!g_sequence_iter_is_end (ptr));
- if (iter != NULL) {
- iter->stamp = model->details->stamp;
- iter->user_data = ptr;
- }
+ g_assert (!g_sequence_iter_is_end (ptr));
+ if (iter != NULL)
+ {
+ iter->stamp = model->details->stamp;
+ iter->user_data = ptr;
+ }
}
static gboolean
-nautilus_list_model_get_iter (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreePath *path)
-{
- NautilusListModel *model;
- GSequence *files;
- GSequenceIter *ptr;
- FileEntry *file_entry;
- int i, d;
-
- model = (NautilusListModel *)tree_model;
- ptr = NULL;
-
- files = model->details->files;
- for (d = 0; d < gtk_tree_path_get_depth (path); d++) {
- i = gtk_tree_path_get_indices (path)[d];
-
- if (files == NULL || i >= g_sequence_get_length (files)) {
- return FALSE;
- }
-
- ptr = g_sequence_get_iter_at_pos (files, i);
- file_entry = g_sequence_get (ptr);
- files = file_entry->files;
- }
-
- nautilus_list_model_ptr_to_iter (model, ptr, iter);
-
- return TRUE;
+nautilus_list_model_get_iter (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreePath *path)
+{
+ NautilusListModel *model;
+ GSequence *files;
+ GSequenceIter *ptr;
+ FileEntry *file_entry;
+ int i, d;
+
+ model = (NautilusListModel *) tree_model;
+ ptr = NULL;
+
+ files = model->details->files;
+ for (d = 0; d < gtk_tree_path_get_depth (path); d++)
+ {
+ i = gtk_tree_path_get_indices (path)[d];
+
+ if (files == NULL || i >= g_sequence_get_length (files))
+ {
+ return FALSE;
+ }
+
+ ptr = g_sequence_get_iter_at_pos (files, i);
+ file_entry = g_sequence_get (ptr);
+ files = file_entry->files;
+ }
+
+ nautilus_list_model_ptr_to_iter (model, ptr, iter);
+
+ return TRUE;
}
static GtkTreePath *
-nautilus_list_model_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter)
-{
- GtkTreePath *path;
- NautilusListModel *model;
- GSequenceIter *ptr;
- FileEntry *file_entry;
-
-
- model = (NautilusListModel *)tree_model;
-
- g_return_val_if_fail (iter->stamp == model->details->stamp, NULL);
-
- if (g_sequence_iter_is_end (iter->user_data)) {
- /* FIXME is this right? */
- return NULL;
- }
-
- path = gtk_tree_path_new ();
- ptr = iter->user_data;
- while (ptr != NULL) {
- gtk_tree_path_prepend_index (path, g_sequence_iter_get_position (ptr));
- file_entry = g_sequence_get (ptr);
- if (file_entry->parent != NULL) {
- ptr = file_entry->parent->ptr;
- } else {
- ptr = NULL;
- }
- }
-
- return path;
+nautilus_list_model_get_path (GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ GtkTreePath *path;
+ NautilusListModel *model;
+ GSequenceIter *ptr;
+ FileEntry *file_entry;
+
+
+ model = (NautilusListModel *) tree_model;
+
+ g_return_val_if_fail (iter->stamp == model->details->stamp, NULL);
+
+ if (g_sequence_iter_is_end (iter->user_data))
+ {
+ /* FIXME is this right? */
+ return NULL;
+ }
+
+ path = gtk_tree_path_new ();
+ ptr = iter->user_data;
+ while (ptr != NULL)
+ {
+ gtk_tree_path_prepend_index (path, g_sequence_iter_get_position (ptr));
+ file_entry = g_sequence_get (ptr);
+ if (file_entry->parent != NULL)
+ {
+ ptr = file_entry->parent->ptr;
+ }
+ else
+ {
+ ptr = NULL;
+ }
+ }
+
+ return path;
}
static gint
nautilus_list_model_get_icon_scale (NautilusListModel *model)
{
- gint retval = -1;
+ gint retval = -1;
- g_signal_emit (model, list_model_signals[GET_ICON_SCALE], 0,
- &retval);
+ g_signal_emit (model, list_model_signals[GET_ICON_SCALE], 0,
+ &retval);
- if (retval == -1) {
- retval = gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), 0);
- }
+ if (retval == -1)
+ {
+ retval = gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), 0);
+ }
- return retval;
+ return retval;
}
guint
nautilus_list_model_get_icon_size_for_zoom_level (NautilusListZoomLevel zoom_level)
{
- switch (zoom_level) {
- case NAUTILUS_LIST_ZOOM_LEVEL_SMALL:
- return NAUTILUS_LIST_ICON_SIZE_SMALL;
- case NAUTILUS_LIST_ZOOM_LEVEL_STANDARD:
- return NAUTILUS_LIST_ICON_SIZE_STANDARD;
- case NAUTILUS_LIST_ZOOM_LEVEL_LARGE:
- return NAUTILUS_LIST_ICON_SIZE_LARGE;
- case NAUTILUS_LIST_ZOOM_LEVEL_LARGER:
- return NAUTILUS_LIST_ICON_SIZE_LARGER;
- }
- g_return_val_if_reached (NAUTILUS_LIST_ICON_SIZE_STANDARD);
+ switch (zoom_level)
+ {
+ case NAUTILUS_LIST_ZOOM_LEVEL_SMALL:
+ {
+ return NAUTILUS_LIST_ICON_SIZE_SMALL;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_STANDARD:
+ {
+ return NAUTILUS_LIST_ICON_SIZE_STANDARD;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_LARGE:
+ {
+ return NAUTILUS_LIST_ICON_SIZE_LARGE;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_LARGER:
+ return NAUTILUS_LIST_ICON_SIZE_LARGER;
+ }
+ g_return_val_if_reached (NAUTILUS_LIST_ICON_SIZE_STANDARD);
}
static void
-nautilus_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
-{
- NautilusListModel *model;
- FileEntry *file_entry;
- NautilusFile *file;
- char *str;
- GdkPixbuf *icon, *rendered_icon;
- int icon_size, icon_scale;
- NautilusListZoomLevel zoom_level;
- NautilusFileIconFlags flags;
- cairo_surface_t *surface;
-
- model = (NautilusListModel *)tree_model;
-
- g_return_if_fail (model->details->stamp == iter->stamp);
- g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));
-
- file_entry = g_sequence_get (iter->user_data);
- file = file_entry->file;
-
- switch (column) {
- case NAUTILUS_LIST_MODEL_FILE_COLUMN:
- g_value_init (value, NAUTILUS_TYPE_FILE);
-
- g_value_set_object (value, file);
- break;
- case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
- g_value_init (value, NAUTILUS_TYPE_DIRECTORY);
-
- g_value_set_object (value, file_entry->subdirectory);
- break;
- case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
- case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
- case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
- case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
- g_value_init (value, CAIRO_GOBJECT_TYPE_SURFACE);
-
- if (file != NULL) {
- zoom_level = nautilus_list_model_get_zoom_level_from_column_id (column);
- icon_size = nautilus_list_model_get_icon_size_for_zoom_level (zoom_level);
- icon_scale = nautilus_list_model_get_icon_scale (model);
-
- flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
- NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
- NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS |
- NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM;
-
- if (model->details->drag_view != NULL) {
- GtkTreePath *path_a, *path_b;
-
- gtk_tree_view_get_drag_dest_row (model->details->drag_view,
- &path_a,
- NULL);
- if (path_a != NULL) {
- path_b = gtk_tree_model_get_path (tree_model, iter);
-
- if (gtk_tree_path_compare (path_a, path_b) == 0) {
- flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
- }
-
- gtk_tree_path_free (path_a);
- gtk_tree_path_free (path_b);
- }
- }
-
- icon = nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, icon_scale, flags);
-
- if (model->details->highlight_files != NULL &&
- g_list_find_custom (model->details->highlight_files,
- file, (GCompareFunc) nautilus_file_compare_location))
- {
- rendered_icon = eel_create_spotlight_pixbuf (icon);
-
- if (rendered_icon != NULL) {
- g_object_unref (icon);
- icon = rendered_icon;
- }
- }
-
- surface = gdk_cairo_surface_create_from_pixbuf (icon, icon_scale, NULL);
- g_value_take_boxed (value, surface);
- g_object_unref (icon);
- }
- break;
- case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
- g_value_init (value, G_TYPE_BOOLEAN);
-
+nautilus_list_model_get_value (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ int column,
+ GValue *value)
+{
+ NautilusListModel *model;
+ FileEntry *file_entry;
+ NautilusFile *file;
+ char *str;
+ GdkPixbuf *icon, *rendered_icon;
+ int icon_size, icon_scale;
+ NautilusListZoomLevel zoom_level;
+ NautilusFileIconFlags flags;
+ cairo_surface_t *surface;
+
+ model = (NautilusListModel *) tree_model;
+
+ g_return_if_fail (model->details->stamp == iter->stamp);
+ g_return_if_fail (!g_sequence_iter_is_end (iter->user_data));
+
+ file_entry = g_sequence_get (iter->user_data);
+ file = file_entry->file;
+
+ switch (column)
+ {
+ case NAUTILUS_LIST_MODEL_FILE_COLUMN:
+ {
+ g_value_init (value, NAUTILUS_TYPE_FILE);
+
+ g_value_set_object (value, file);
+ }
+ break;
+
+ case NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN:
+ {
+ g_value_init (value, NAUTILUS_TYPE_DIRECTORY);
+
+ g_value_set_object (value, file_entry->subdirectory);
+ }
+ break;
+
+ case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
+ case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
+ case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
+ case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
+ {
+ g_value_init (value, CAIRO_GOBJECT_TYPE_SURFACE);
+
+ if (file != NULL)
+ {
+ zoom_level = nautilus_list_model_get_zoom_level_from_column_id (column);
+ icon_size = nautilus_list_model_get_icon_size_for_zoom_level (zoom_level);
+ icon_scale = nautilus_list_model_get_icon_scale (model);
+
+ flags = NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
+ NAUTILUS_FILE_ICON_FLAGS_FORCE_THUMBNAIL_SIZE |
+ NAUTILUS_FILE_ICON_FLAGS_USE_EMBLEMS |
+ NAUTILUS_FILE_ICON_FLAGS_USE_ONE_EMBLEM;
+
+ if (model->details->drag_view != NULL)
+ {
+ GtkTreePath *path_a, *path_b;
+
+ gtk_tree_view_get_drag_dest_row (model->details->drag_view,
+ &path_a,
+ NULL);
+ if (path_a != NULL)
+ {
+ path_b = gtk_tree_model_get_path (tree_model, iter);
+
+ if (gtk_tree_path_compare (path_a, path_b) == 0)
+ {
+ flags |= NAUTILUS_FILE_ICON_FLAGS_FOR_DRAG_ACCEPT;
+ }
+
+ gtk_tree_path_free (path_a);
+ gtk_tree_path_free (path_b);
+ }
+ }
+
+ icon = nautilus_file_get_icon_pixbuf (file, icon_size, TRUE, icon_scale, flags);
+
+ if (model->details->highlight_files != NULL &&
+ g_list_find_custom (model->details->highlight_files,
+ file, (GCompareFunc) nautilus_file_compare_location))
+ {
+ rendered_icon = eel_create_spotlight_pixbuf (icon);
+
+ if (rendered_icon != NULL)
+ {
+ g_object_unref (icon);
+ icon = rendered_icon;
+ }
+ }
+
+ surface = gdk_cairo_surface_create_from_pixbuf (icon, icon_scale, NULL);
+ g_value_take_boxed (value, surface);
+ g_object_unref (icon);
+ }
+ }
+ break;
+
+ case NAUTILUS_LIST_MODEL_FILE_NAME_IS_EDITABLE_COLUMN:
+ {
+ g_value_init (value, G_TYPE_BOOLEAN);
+
g_value_set_boolean (value, file != NULL && nautilus_file_can_rename (file));
- break;
- default:
- if (column >= NAUTILUS_LIST_MODEL_NUM_COLUMNS || column < NAUTILUS_LIST_MODEL_NUM_COLUMNS + model->details->columns->len) {
- NautilusColumn *nautilus_column;
- GQuark attribute;
- nautilus_column = model->details->columns->pdata[column - NAUTILUS_LIST_MODEL_NUM_COLUMNS];
-
- g_value_init (value, G_TYPE_STRING);
- g_object_get (nautilus_column,
- "attribute_q", &attribute,
- NULL);
- if (file != NULL) {
- str = nautilus_file_get_string_attribute_with_default_q (file,
- attribute);
- g_value_take_string (value, str);
- } else if (attribute == attribute_name_q) {
- if (file_entry->parent->loaded) {
- g_value_set_string (value, _("(Empty)"));
- } else {
- g_value_set_string (value, _("Loading…"));
- }
- }
- } else {
- g_assert_not_reached ();
- }
- }
+ }
+ break;
+
+ default:
+ if (column >= NAUTILUS_LIST_MODEL_NUM_COLUMNS || column < NAUTILUS_LIST_MODEL_NUM_COLUMNS + model->details->columns->len)
+ {
+ NautilusColumn *nautilus_column;
+ GQuark attribute;
+ nautilus_column = model->details->columns->pdata[column - NAUTILUS_LIST_MODEL_NUM_COLUMNS];
+
+ g_value_init (value, G_TYPE_STRING);
+ g_object_get (nautilus_column,
+ "attribute_q", &attribute,
+ NULL);
+ if (file != NULL)
+ {
+ str = nautilus_file_get_string_attribute_with_default_q (file,
+ attribute);
+ g_value_take_string (value, str);
+ }
+ else if (attribute == attribute_name_q)
+ {
+ if (file_entry->parent->loaded)
+ {
+ g_value_set_string (value, _("(Empty)"));
+ }
+ else
+ {
+ g_value_set_string (value, _("Loading…"));
+ }
+ }
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+ }
}
static gboolean
-nautilus_list_model_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter)
+nautilus_list_model_iter_next (GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
{
- NautilusListModel *model;
+ NautilusListModel *model;
- model = (NautilusListModel *)tree_model;
+ model = (NautilusListModel *) tree_model;
- g_return_val_if_fail (model->details->stamp == iter->stamp, FALSE);
+ g_return_val_if_fail (model->details->stamp == iter->stamp, FALSE);
- iter->user_data = g_sequence_iter_next (iter->user_data);
+ iter->user_data = g_sequence_iter_next (iter->user_data);
- return !g_sequence_iter_is_end (iter->user_data);
+ return !g_sequence_iter_is_end (iter->user_data);
}
static gboolean
-nautilus_list_model_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent)
+nautilus_list_model_iter_children (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent)
{
- NautilusListModel *model;
- GSequence *files;
- FileEntry *file_entry;
-
- model = (NautilusListModel *)tree_model;
-
- if (parent == NULL) {
- files = model->details->files;
- } else {
- file_entry = g_sequence_get (parent->user_data);
- files = file_entry->files;
- }
-
- if (files == NULL || g_sequence_get_length (files) == 0) {
- return FALSE;
- }
-
- iter->stamp = model->details->stamp;
- iter->user_data = g_sequence_get_begin_iter (files);
-
- return TRUE;
+ NautilusListModel *model;
+ GSequence *files;
+ FileEntry *file_entry;
+
+ model = (NautilusListModel *) tree_model;
+
+ if (parent == NULL)
+ {
+ files = model->details->files;
+ }
+ else
+ {
+ file_entry = g_sequence_get (parent->user_data);
+ files = file_entry->files;
+ }
+
+ if (files == NULL || g_sequence_get_length (files) == 0)
+ {
+ return FALSE;
+ }
+
+ iter->stamp = model->details->stamp;
+ iter->user_data = g_sequence_get_begin_iter (files);
+
+ return TRUE;
}
static gboolean
-nautilus_list_model_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter)
+nautilus_list_model_iter_has_child (GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
{
- FileEntry *file_entry;
+ FileEntry *file_entry;
- if (iter == NULL) {
- return !nautilus_list_model_is_empty (NAUTILUS_LIST_MODEL (tree_model));
- }
+ if (iter == NULL)
+ {
+ return !nautilus_list_model_is_empty (NAUTILUS_LIST_MODEL (tree_model));
+ }
- file_entry = g_sequence_get (iter->user_data);
+ file_entry = g_sequence_get (iter->user_data);
- return (file_entry->files != NULL && g_sequence_get_length (file_entry->files) > 0);
+ return (file_entry->files != NULL && g_sequence_get_length (file_entry->files) > 0);
}
static int
-nautilus_list_model_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter)
+nautilus_list_model_iter_n_children (GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
{
- NautilusListModel *model;
- GSequence *files;
- FileEntry *file_entry;
-
- model = (NautilusListModel *)tree_model;
-
- if (iter == NULL) {
- files = model->details->files;
- } else {
- file_entry = g_sequence_get (iter->user_data);
- files = file_entry->files;
- }
-
- return g_sequence_get_length (files);
+ NautilusListModel *model;
+ GSequence *files;
+ FileEntry *file_entry;
+
+ model = (NautilusListModel *) tree_model;
+
+ if (iter == NULL)
+ {
+ files = model->details->files;
+ }
+ else
+ {
+ file_entry = g_sequence_get (iter->user_data);
+ files = file_entry->files;
+ }
+
+ return g_sequence_get_length (files);
}
static gboolean
-nautilus_list_model_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, int n)
+nautilus_list_model_iter_nth_child (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent,
+ int n)
{
- NautilusListModel *model;
- GSequenceIter *child;
- GSequence *files;
- FileEntry *file_entry;
-
- model = (NautilusListModel *)tree_model;
-
- if (parent != NULL) {
- file_entry = g_sequence_get (parent->user_data);
- files = file_entry->files;
- } else {
- files = model->details->files;
- }
-
- child = g_sequence_get_iter_at_pos (files, n);
-
- if (g_sequence_iter_is_end (child)) {
- return FALSE;
- }
-
- iter->stamp = model->details->stamp;
- iter->user_data = child;
-
- return TRUE;
+ NautilusListModel *model;
+ GSequenceIter *child;
+ GSequence *files;
+ FileEntry *file_entry;
+
+ model = (NautilusListModel *) tree_model;
+
+ if (parent != NULL)
+ {
+ file_entry = g_sequence_get (parent->user_data);
+ files = file_entry->files;
+ }
+ else
+ {
+ files = model->details->files;
+ }
+
+ child = g_sequence_get_iter_at_pos (files, n);
+
+ if (g_sequence_iter_is_end (child))
+ {
+ return FALSE;
+ }
+
+ iter->stamp = model->details->stamp;
+ iter->user_data = child;
+
+ return TRUE;
}
static gboolean
-nautilus_list_model_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child)
+nautilus_list_model_iter_parent (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *child)
{
- NautilusListModel *model;
- FileEntry *file_entry;
+ NautilusListModel *model;
+ FileEntry *file_entry;
- model = (NautilusListModel *)tree_model;
+ model = (NautilusListModel *) tree_model;
- file_entry = g_sequence_get (child->user_data);
+ file_entry = g_sequence_get (child->user_data);
- if (file_entry->parent == NULL) {
- return FALSE;
- }
+ if (file_entry->parent == NULL)
+ {
+ return FALSE;
+ }
- iter->stamp = model->details->stamp;
- iter->user_data = file_entry->parent->ptr;
+ iter->stamp = model->details->stamp;
+ iter->user_data = file_entry->parent->ptr;
- return TRUE;
+ return TRUE;
}
static GSequenceIter *
-lookup_file (NautilusListModel *model, NautilusFile *file,
- NautilusDirectory *directory)
-{
- FileEntry *file_entry;
- GSequenceIter *ptr, *parent_ptr;
-
- parent_ptr = NULL;
- if (directory) {
- parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
- directory);
- }
-
- if (parent_ptr) {
- file_entry = g_sequence_get (parent_ptr);
- ptr = g_hash_table_lookup (file_entry->reverse_map, file);
- } else {
- ptr = g_hash_table_lookup (model->details->top_reverse_map, file);
- }
-
- if (ptr) {
- g_assert (((FileEntry *)g_sequence_get (ptr))->file == file);
- }
-
- return ptr;
+lookup_file (NautilusListModel *model,
+ NautilusFile *file,
+ NautilusDirectory *directory)
+{
+ FileEntry *file_entry;
+ GSequenceIter *ptr, *parent_ptr;
+
+ parent_ptr = NULL;
+ if (directory)
+ {
+ parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
+ directory);
+ }
+
+ if (parent_ptr)
+ {
+ file_entry = g_sequence_get (parent_ptr);
+ ptr = g_hash_table_lookup (file_entry->reverse_map, file);
+ }
+ else
+ {
+ ptr = g_hash_table_lookup (model->details->top_reverse_map, file);
+ }
+
+ if (ptr)
+ {
+ g_assert (((FileEntry *) g_sequence_get (ptr))->file == file);
+ }
+
+ return ptr;
}
-struct GetIters {
- NautilusListModel *model;
- NautilusFile *file;
- GList *iters;
+struct GetIters
+{
+ NautilusListModel *model;
+ NautilusFile *file;
+ GList *iters;
};
static void
dir_to_iters (struct GetIters *data,
- GHashTable *reverse_map)
-{
- GSequenceIter *ptr;
-
- ptr = g_hash_table_lookup (reverse_map, data->file);
- if (ptr) {
- GtkTreeIter *iter;
- iter = g_new0 (GtkTreeIter, 1);
- nautilus_list_model_ptr_to_iter (data->model, ptr, iter);
- data->iters = g_list_prepend (data->iters, iter);
- }
+ GHashTable *reverse_map)
+{
+ GSequenceIter *ptr;
+
+ ptr = g_hash_table_lookup (reverse_map, data->file);
+ if (ptr)
+ {
+ GtkTreeIter *iter;
+ iter = g_new0 (GtkTreeIter, 1);
+ nautilus_list_model_ptr_to_iter (data->model, ptr, iter);
+ data->iters = g_list_prepend (data->iters, iter);
+ }
}
static void
-file_to_iter_cb (gpointer key,
- gpointer value,
- gpointer user_data)
+file_to_iter_cb (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- struct GetIters *data;
- FileEntry *dir_file_entry;
+ struct GetIters *data;
+ FileEntry *dir_file_entry;
- data = user_data;
- dir_file_entry = g_sequence_get ((GSequenceIter *)value);
- dir_to_iters (data, dir_file_entry->reverse_map);
+ data = user_data;
+ dir_file_entry = g_sequence_get ((GSequenceIter *) value);
+ dir_to_iters (data, dir_file_entry->reverse_map);
}
GList *
-nautilus_list_model_get_all_iters_for_file (NautilusListModel *model, NautilusFile *file)
+nautilus_list_model_get_all_iters_for_file (NautilusListModel *model,
+ NautilusFile *file)
{
- struct GetIters data;
+ struct GetIters data;
+
+ data.file = file;
+ data.model = model;
+ data.iters = NULL;
- data.file = file;
- data.model = model;
- data.iters = NULL;
-
- dir_to_iters (&data, model->details->top_reverse_map);
- g_hash_table_foreach (model->details->directory_reverse_map,
- file_to_iter_cb, &data);
+ dir_to_iters (&data, model->details->top_reverse_map);
+ g_hash_table_foreach (model->details->directory_reverse_map,
+ file_to_iter_cb, &data);
- return g_list_reverse (data.iters);
+ return g_list_reverse (data.iters);
}
gboolean
-nautilus_list_model_get_first_iter_for_file (NautilusListModel *model,
- NautilusFile *file,
- GtkTreeIter *iter)
-{
- GList *list;
- gboolean res;
-
- res = FALSE;
-
- list = nautilus_list_model_get_all_iters_for_file (model, file);
- if (list != NULL) {
- res = TRUE;
- *iter = *(GtkTreeIter *)list->data;
- }
- g_list_free_full (list, g_free);
-
- return res;
+nautilus_list_model_get_first_iter_for_file (NautilusListModel *model,
+ NautilusFile *file,
+ GtkTreeIter *iter)
+{
+ GList *list;
+ gboolean res;
+
+ res = FALSE;
+
+ list = nautilus_list_model_get_all_iters_for_file (model, file);
+ if (list != NULL)
+ {
+ res = TRUE;
+ *iter = *(GtkTreeIter *) list->data;
+ }
+ g_list_free_full (list, g_free);
+
+ return res;
}
gboolean
-nautilus_list_model_get_tree_iter_from_file (NautilusListModel *model, NautilusFile *file,
- NautilusDirectory *directory,
- GtkTreeIter *iter)
+nautilus_list_model_get_tree_iter_from_file (NautilusListModel *model,
+ NautilusFile *file,
+ NautilusDirectory *directory,
+ GtkTreeIter *iter)
{
- GSequenceIter *ptr;
+ GSequenceIter *ptr;
+
+ ptr = lookup_file (model, file, directory);
+ if (!ptr)
+ {
+ return FALSE;
+ }
- ptr = lookup_file (model, file, directory);
- if (!ptr) {
- return FALSE;
- }
+ nautilus_list_model_ptr_to_iter (model, ptr, iter);
- nautilus_list_model_ptr_to_iter (model, ptr, iter);
-
- return TRUE;
+ return TRUE;
}
static int
nautilus_list_model_file_entry_compare_func (gconstpointer a,
- gconstpointer b,
- gpointer user_data)
-{
- FileEntry *file_entry1;
- FileEntry *file_entry2;
- NautilusListModel *model;
- int result;
-
- model = (NautilusListModel *)user_data;
-
- file_entry1 = (FileEntry *)a;
- file_entry2 = (FileEntry *)b;
-
- if (file_entry1->file != NULL && file_entry2->file != NULL) {
- result = nautilus_file_compare_for_sort_by_attribute_q (file_entry1->file, file_entry2->file,
- model->details->sort_attribute,
- model->details->sort_directories_first,
- (model->details->order == GTK_SORT_DESCENDING));
- } else if (file_entry1->file == NULL) {
- return -1;
- } else {
- return 1;
- }
-
- return result;
+ gconstpointer b,
+ gpointer user_data)
+{
+ FileEntry *file_entry1;
+ FileEntry *file_entry2;
+ NautilusListModel *model;
+ int result;
+
+ model = (NautilusListModel *) user_data;
+
+ file_entry1 = (FileEntry *) a;
+ file_entry2 = (FileEntry *) b;
+
+ if (file_entry1->file != NULL && file_entry2->file != NULL)
+ {
+ result = nautilus_file_compare_for_sort_by_attribute_q (file_entry1->file, file_entry2->file,
+ model->details->sort_attribute,
+ model->details->sort_directories_first,
+ (model->details->order == GTK_SORT_DESCENDING));
+ }
+ else if (file_entry1->file == NULL)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+
+ return result;
}
int
nautilus_list_model_compare_func (NautilusListModel *model,
- NautilusFile *file1,
- NautilusFile *file2)
+ NautilusFile *file1,
+ NautilusFile *file2)
{
- int result;
+ int result;
- result = nautilus_file_compare_for_sort_by_attribute_q (file1, file2,
- model->details->sort_attribute,
- model->details->sort_directories_first,
- (model->details->order == GTK_SORT_DESCENDING));
+ result = nautilus_file_compare_for_sort_by_attribute_q (file1, file2,
+ model->details->sort_attribute,
+ model->details->sort_directories_first,
+ (model->details->order == GTK_SORT_DESCENDING));
- return result;
+ return result;
}
static void
-nautilus_list_model_sort_file_entries (NautilusListModel *model, GSequence *files, GtkTreePath *path)
-{
- GSequenceIter **old_order;
- GtkTreeIter iter;
- int *new_order;
- int length;
- int i;
- FileEntry *file_entry;
- gboolean has_iter;
-
- length = g_sequence_get_length (files);
-
- if (length <= 1) {
- return;
- }
-
- /* generate old order of GSequenceIter's */
- old_order = g_new (GSequenceIter *, length);
- for (i = 0; i < length; ++i) {
- GSequenceIter *ptr = g_sequence_get_iter_at_pos (files, i);
-
- file_entry = g_sequence_get (ptr);
- if (file_entry->files != NULL) {
- gtk_tree_path_append_index (path, i);
- nautilus_list_model_sort_file_entries (model, file_entry->files, path);
- gtk_tree_path_up (path);
- }
-
- old_order[i] = ptr;
- }
-
- /* sort */
- g_sequence_sort (files, nautilus_list_model_file_entry_compare_func, model);
-
- /* generate new order */
- new_order = g_new (int, length);
- /* Note: new_order[newpos] = oldpos */
- for (i = 0; i < length; ++i) {
- new_order[g_sequence_iter_get_position (old_order[i])] = i;
- }
-
- /* Let the world know about our new order */
-
- g_assert (new_order != NULL);
-
- has_iter = FALSE;
- if (gtk_tree_path_get_depth (path) != 0) {
- gboolean get_iter_result;
- has_iter = TRUE;
- get_iter_result = gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
- g_assert (get_iter_result);
- }
-
- gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model),
- path, has_iter ? &iter : NULL, new_order);
-
- g_free (old_order);
- g_free (new_order);
+nautilus_list_model_sort_file_entries (NautilusListModel *model,
+ GSequence *files,
+ GtkTreePath *path)
+{
+ GSequenceIter **old_order;
+ GtkTreeIter iter;
+ int *new_order;
+ int length;
+ int i;
+ FileEntry *file_entry;
+ gboolean has_iter;
+
+ length = g_sequence_get_length (files);
+
+ if (length <= 1)
+ {
+ return;
+ }
+
+ /* generate old order of GSequenceIter's */
+ old_order = g_new (GSequenceIter *, length);
+ for (i = 0; i < length; ++i)
+ {
+ GSequenceIter *ptr = g_sequence_get_iter_at_pos (files, i);
+
+ file_entry = g_sequence_get (ptr);
+ if (file_entry->files != NULL)
+ {
+ gtk_tree_path_append_index (path, i);
+ nautilus_list_model_sort_file_entries (model, file_entry->files, path);
+ gtk_tree_path_up (path);
+ }
+
+ old_order[i] = ptr;
+ }
+
+ /* sort */
+ g_sequence_sort (files, nautilus_list_model_file_entry_compare_func, model);
+
+ /* generate new order */
+ new_order = g_new (int, length);
+ /* Note: new_order[newpos] = oldpos */
+ for (i = 0; i < length; ++i)
+ {
+ new_order[g_sequence_iter_get_position (old_order[i])] = i;
+ }
+
+ /* Let the world know about our new order */
+
+ g_assert (new_order != NULL);
+
+ has_iter = FALSE;
+ if (gtk_tree_path_get_depth (path) != 0)
+ {
+ gboolean get_iter_result;
+ has_iter = TRUE;
+ get_iter_result = gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
+ g_assert (get_iter_result);
+ }
+
+ gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model),
+ path, has_iter ? &iter : NULL, new_order);
+
+ g_free (old_order);
+ g_free (new_order);
}
static void
nautilus_list_model_sort (NautilusListModel *model)
{
- GtkTreePath *path;
+ GtkTreePath *path;
- path = gtk_tree_path_new ();
+ path = gtk_tree_path_new ();
- nautilus_list_model_sort_file_entries (model, model->details->files, path);
+ nautilus_list_model_sort_file_entries (model, model->details->files, path);
- gtk_tree_path_free (path);
+ gtk_tree_path_free (path);
}
static gboolean
nautilus_list_model_get_sort_column_id (GtkTreeSortable *sortable,
- gint *sort_column_id,
- GtkSortType *order)
-{
- NautilusListModel *model;
- int id;
-
- model = (NautilusListModel *)sortable;
-
- id = nautilus_list_model_get_sort_column_id_from_attribute
- (model, model->details->sort_attribute);
-
- if (id == -1) {
- return FALSE;
- }
-
- if (sort_column_id != NULL) {
- *sort_column_id = id;
- }
-
- if (order != NULL) {
- *order = model->details->order;
- }
-
- return TRUE;
+ gint *sort_column_id,
+ GtkSortType *order)
+{
+ NautilusListModel *model;
+ int id;
+
+ model = (NautilusListModel *) sortable;
+
+ id = nautilus_list_model_get_sort_column_id_from_attribute
+ (model, model->details->sort_attribute);
+
+ if (id == -1)
+ {
+ return FALSE;
+ }
+
+ if (sort_column_id != NULL)
+ {
+ *sort_column_id = id;
+ }
+
+ if (order != NULL)
+ {
+ *order = model->details->order;
+ }
+
+ return TRUE;
}
static void
-nautilus_list_model_set_sort_column_id (GtkTreeSortable *sortable, gint sort_column_id, GtkSortType order)
+nautilus_list_model_set_sort_column_id (GtkTreeSortable *sortable,
+ gint sort_column_id,
+ GtkSortType order)
{
- NautilusListModel *model;
+ NautilusListModel *model;
- model = (NautilusListModel *)sortable;
+ model = (NautilusListModel *) sortable;
- model->details->sort_attribute = nautilus_list_model_get_attribute_from_sort_column_id (model, sort_column_id);
+ model->details->sort_attribute = nautilus_list_model_get_attribute_from_sort_column_id (model, sort_column_id);
- model->details->order = order;
+ model->details->order = order;
- nautilus_list_model_sort (model);
- gtk_tree_sortable_sort_column_changed (sortable);
+ nautilus_list_model_sort (model);
+ gtk_tree_sortable_sort_column_changed (sortable);
}
static gboolean
nautilus_list_model_has_default_sort_func (GtkTreeSortable *sortable)
{
- return FALSE;
+ return FALSE;
}
static void
-add_dummy_row (NautilusListModel *model, FileEntry *parent_entry)
-{
- FileEntry *dummy_file_entry;
- GtkTreeIter iter;
- GtkTreePath *path;
-
- dummy_file_entry = g_new0 (FileEntry, 1);
- dummy_file_entry->parent = parent_entry;
- dummy_file_entry->ptr = g_sequence_insert_sorted (parent_entry->files, dummy_file_entry,
- nautilus_list_model_file_entry_compare_func, model);
- iter.stamp = model->details->stamp;
- iter.user_data = dummy_file_entry->ptr;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
+add_dummy_row (NautilusListModel *model,
+ FileEntry *parent_entry)
+{
+ FileEntry *dummy_file_entry;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ dummy_file_entry = g_new0 (FileEntry, 1);
+ dummy_file_entry->parent = parent_entry;
+ dummy_file_entry->ptr = g_sequence_insert_sorted (parent_entry->files, dummy_file_entry,
+ nautilus_list_model_file_entry_compare_func, model);
+ iter.stamp = model->details->stamp;
+ iter.user_data = dummy_file_entry->ptr;
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
}
gboolean
-nautilus_list_model_add_file (NautilusListModel *model, NautilusFile *file,
- NautilusDirectory *directory)
-{
- GtkTreeIter iter;
- GtkTreePath *path;
- FileEntry *file_entry;
- GSequenceIter *ptr, *parent_ptr;
- GSequence *files;
- gboolean replace_dummy;
- GHashTable *parent_hash;
-
- parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
- directory);
- if (parent_ptr) {
- file_entry = g_sequence_get (parent_ptr);
- ptr = g_hash_table_lookup (file_entry->reverse_map, file);
- } else {
- file_entry = NULL;
- ptr = g_hash_table_lookup (model->details->top_reverse_map, file);
- }
-
- if (ptr != NULL) {
- g_warning ("file already in tree (parent_ptr: %p)!!!\n", parent_ptr);
- return FALSE;
- }
-
- file_entry = g_new0 (FileEntry, 1);
- file_entry->file = nautilus_file_ref (file);
- file_entry->parent = NULL;
- file_entry->subdirectory = NULL;
- file_entry->files = NULL;
-
- files = model->details->files;
- parent_hash = model->details->top_reverse_map;
-
- replace_dummy = FALSE;
-
- if (parent_ptr != NULL) {
- file_entry->parent = g_sequence_get (parent_ptr);
- /* At this point we set loaded. Either we saw
- * "done" and ignored it waiting for this, or we do this
- * earlier, but then we replace the dummy row anyway,
- * so it doesn't matter */
- file_entry->parent->loaded = 1;
- parent_hash = file_entry->parent->reverse_map;
- files = file_entry->parent->files;
- if (g_sequence_get_length (files) == 1) {
- GSequenceIter *dummy_ptr = g_sequence_get_iter_at_pos (files, 0);
- FileEntry *dummy_entry = g_sequence_get (dummy_ptr);
- if (dummy_entry->file == NULL) {
- /* replace the dummy loading entry */
- model->details->stamp++;
- g_sequence_remove (dummy_ptr);
-
- replace_dummy = TRUE;
- }
- }
- }
-
-
- file_entry->ptr = g_sequence_insert_sorted (files, file_entry,
- nautilus_list_model_file_entry_compare_func, model);
-
- g_hash_table_insert (parent_hash, file, file_entry->ptr);
-
- iter.stamp = model->details->stamp;
- iter.user_data = file_entry->ptr;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- if (replace_dummy) {
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
- } else {
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
- }
-
- if (nautilus_file_is_directory (file)) {
- file_entry->files = g_sequence_new ((GDestroyNotify)file_entry_free);
-
- add_dummy_row (model, file_entry);
-
- gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model),
- path, &iter);
- }
- gtk_tree_path_free (path);
-
- return TRUE;
+nautilus_list_model_add_file (NautilusListModel *model,
+ NautilusFile *file,
+ NautilusDirectory *directory)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ FileEntry *file_entry;
+ GSequenceIter *ptr, *parent_ptr;
+ GSequence *files;
+ gboolean replace_dummy;
+ GHashTable *parent_hash;
+
+ parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
+ directory);
+ if (parent_ptr)
+ {
+ file_entry = g_sequence_get (parent_ptr);
+ ptr = g_hash_table_lookup (file_entry->reverse_map, file);
+ }
+ else
+ {
+ file_entry = NULL;
+ ptr = g_hash_table_lookup (model->details->top_reverse_map, file);
+ }
+
+ if (ptr != NULL)
+ {
+ g_warning ("file already in tree (parent_ptr: %p)!!!\n", parent_ptr);
+ return FALSE;
+ }
+
+ file_entry = g_new0 (FileEntry, 1);
+ file_entry->file = nautilus_file_ref (file);
+ file_entry->parent = NULL;
+ file_entry->subdirectory = NULL;
+ file_entry->files = NULL;
+
+ files = model->details->files;
+ parent_hash = model->details->top_reverse_map;
+
+ replace_dummy = FALSE;
+
+ if (parent_ptr != NULL)
+ {
+ file_entry->parent = g_sequence_get (parent_ptr);
+ /* At this point we set loaded. Either we saw
+ * "done" and ignored it waiting for this, or we do this
+ * earlier, but then we replace the dummy row anyway,
+ * so it doesn't matter */
+ file_entry->parent->loaded = 1;
+ parent_hash = file_entry->parent->reverse_map;
+ files = file_entry->parent->files;
+ if (g_sequence_get_length (files) == 1)
+ {
+ GSequenceIter *dummy_ptr = g_sequence_get_iter_at_pos (files, 0);
+ FileEntry *dummy_entry = g_sequence_get (dummy_ptr);
+ if (dummy_entry->file == NULL)
+ {
+ /* replace the dummy loading entry */
+ model->details->stamp++;
+ g_sequence_remove (dummy_ptr);
+
+ replace_dummy = TRUE;
+ }
+ }
+ }
+
+
+ file_entry->ptr = g_sequence_insert_sorted (files, file_entry,
+ nautilus_list_model_file_entry_compare_func, model);
+
+ g_hash_table_insert (parent_hash, file, file_entry->ptr);
+
+ iter.stamp = model->details->stamp;
+ iter.user_data = file_entry->ptr;
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ if (replace_dummy)
+ {
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ }
+ else
+ {
+ gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
+ }
+
+ if (nautilus_file_is_directory (file))
+ {
+ file_entry->files = g_sequence_new ((GDestroyNotify) file_entry_free);
+
+ add_dummy_row (model, file_entry);
+
+ gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model),
+ path, &iter);
+ }
+ gtk_tree_path_free (path);
+
+ return TRUE;
}
void
-nautilus_list_model_file_changed (NautilusListModel *model, NautilusFile *file,
- NautilusDirectory *directory)
-{
- FileEntry *parent_file_entry;
- GtkTreeIter iter;
- GtkTreePath *path, *parent_path;
- GSequenceIter *ptr;
- int pos_before, pos_after, length, i, old;
- int *new_order;
- gboolean has_iter;
- GSequence *files;
-
- ptr = lookup_file (model, file, directory);
- if (!ptr) {
- return;
- }
-
-
- pos_before = g_sequence_iter_get_position (ptr);
-
- g_sequence_sort_changed (ptr, nautilus_list_model_file_entry_compare_func, model);
-
- pos_after = g_sequence_iter_get_position (ptr);
-
- if (pos_before != pos_after) {
- /* The file moved, we need to send rows_reordered */
-
- parent_file_entry = ((FileEntry *)g_sequence_get (ptr))->parent;
-
- if (parent_file_entry == NULL) {
- has_iter = FALSE;
- parent_path = gtk_tree_path_new ();
- files = model->details->files;
- } else {
- has_iter = TRUE;
- nautilus_list_model_ptr_to_iter (model, parent_file_entry->ptr, &iter);
- parent_path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- files = parent_file_entry->files;
- }
-
- length = g_sequence_get_length (files);
- new_order = g_new (int, length);
- /* Note: new_order[newpos] = oldpos */
- for (i = 0, old = 0; i < length; ++i) {
- if (i == pos_after) {
- new_order[i] = pos_before;
- } else {
- if (old == pos_before)
- old++;
- new_order[i] = old++;
- }
- }
-
- gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model),
- parent_path, has_iter ? &iter : NULL, new_order);
-
- gtk_tree_path_free (parent_path);
- g_free (new_order);
- }
-
- nautilus_list_model_ptr_to_iter (model, ptr, &iter);
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
+nautilus_list_model_file_changed (NautilusListModel *model,
+ NautilusFile *file,
+ NautilusDirectory *directory)
+{
+ FileEntry *parent_file_entry;
+ GtkTreeIter iter;
+ GtkTreePath *path, *parent_path;
+ GSequenceIter *ptr;
+ int pos_before, pos_after, length, i, old;
+ int *new_order;
+ gboolean has_iter;
+ GSequence *files;
+
+ ptr = lookup_file (model, file, directory);
+ if (!ptr)
+ {
+ return;
+ }
+
+
+ pos_before = g_sequence_iter_get_position (ptr);
+
+ g_sequence_sort_changed (ptr, nautilus_list_model_file_entry_compare_func, model);
+
+ pos_after = g_sequence_iter_get_position (ptr);
+
+ if (pos_before != pos_after)
+ {
+ /* The file moved, we need to send rows_reordered */
+
+ parent_file_entry = ((FileEntry *) g_sequence_get (ptr))->parent;
+
+ if (parent_file_entry == NULL)
+ {
+ has_iter = FALSE;
+ parent_path = gtk_tree_path_new ();
+ files = model->details->files;
+ }
+ else
+ {
+ has_iter = TRUE;
+ nautilus_list_model_ptr_to_iter (model, parent_file_entry->ptr, &iter);
+ parent_path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ files = parent_file_entry->files;
+ }
+
+ length = g_sequence_get_length (files);
+ new_order = g_new (int, length);
+ /* Note: new_order[newpos] = oldpos */
+ for (i = 0, old = 0; i < length; ++i)
+ {
+ if (i == pos_after)
+ {
+ new_order[i] = pos_before;
+ }
+ else
+ {
+ if (old == pos_before)
+ {
+ old++;
+ }
+ new_order[i] = old++;
+ }
+ }
+
+ gtk_tree_model_rows_reordered (GTK_TREE_MODEL (model),
+ parent_path, has_iter ? &iter : NULL, new_order);
+
+ gtk_tree_path_free (parent_path);
+ g_free (new_order);
+ }
+
+ nautilus_list_model_ptr_to_iter (model, ptr, &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
}
gboolean
nautilus_list_model_is_empty (NautilusListModel *model)
{
- return (g_sequence_get_length (model->details->files) == 0);
+ return (g_sequence_get_length (model->details->files) == 0);
}
static void
-nautilus_list_model_remove (NautilusListModel *model, GtkTreeIter *iter)
-{
- GSequenceIter *ptr, *child_ptr;
- FileEntry *file_entry, *child_file_entry, *parent_file_entry;
- GtkTreePath *path;
- GtkTreeIter parent_iter;
-
- ptr = iter->user_data;
- file_entry = g_sequence_get (ptr);
-
- if (file_entry->files != NULL) {
- while (g_sequence_get_length (file_entry->files) > 0) {
- child_ptr = g_sequence_get_begin_iter (file_entry->files);
- child_file_entry = g_sequence_get (child_ptr);
- if (child_file_entry->file != NULL) {
- nautilus_list_model_remove_file (model,
- child_file_entry->file,
- file_entry->subdirectory);
- } else {
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
- gtk_tree_path_append_index (path, 0);
- model->details->stamp++;
- g_sequence_remove (child_ptr);
- gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
- gtk_tree_path_free (path);
- }
-
- /* the parent iter didn't actually change */
- iter->stamp = model->details->stamp;
- }
-
- }
-
- if (file_entry->file != NULL) { /* Don't try to remove dummy row */
- if (file_entry->parent != NULL) {
- g_hash_table_remove (file_entry->parent->reverse_map, file_entry->file);
- } else {
- g_hash_table_remove (model->details->top_reverse_map, file_entry->file);
- }
- }
-
- parent_file_entry = file_entry->parent;
- if (parent_file_entry && g_sequence_get_length (parent_file_entry->files) == 1 &&
- file_entry->file != NULL) {
- /* this is the last non-dummy child, add a dummy node */
- /* We need to do this before removing the last file to avoid
- * collapsing the row.
- */
- add_dummy_row (model, parent_file_entry);
- }
-
- if (file_entry->subdirectory != NULL) {
- g_signal_emit (model,
- list_model_signals[SUBDIRECTORY_UNLOADED], 0,
- file_entry->subdirectory);
- g_hash_table_remove (model->details->directory_reverse_map,
- file_entry->subdirectory);
- }
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
-
- g_sequence_remove (ptr);
- model->details->stamp++;
- gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
-
- gtk_tree_path_free (path);
-
- if (parent_file_entry && g_sequence_get_length (parent_file_entry->files) == 0) {
- parent_iter.stamp = model->details->stamp;
- parent_iter.user_data = parent_file_entry->ptr;
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &parent_iter);
- gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model),
- path, &parent_iter);
- gtk_tree_path_free (path);
- }
+nautilus_list_model_remove (NautilusListModel *model,
+ GtkTreeIter *iter)
+{
+ GSequenceIter *ptr, *child_ptr;
+ FileEntry *file_entry, *child_file_entry, *parent_file_entry;
+ GtkTreePath *path;
+ GtkTreeIter parent_iter;
+
+ ptr = iter->user_data;
+ file_entry = g_sequence_get (ptr);
+
+ if (file_entry->files != NULL)
+ {
+ while (g_sequence_get_length (file_entry->files) > 0)
+ {
+ child_ptr = g_sequence_get_begin_iter (file_entry->files);
+ child_file_entry = g_sequence_get (child_ptr);
+ if (child_file_entry->file != NULL)
+ {
+ nautilus_list_model_remove_file (model,
+ child_file_entry->file,
+ file_entry->subdirectory);
+ }
+ else
+ {
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
+ gtk_tree_path_append_index (path, 0);
+ model->details->stamp++;
+ g_sequence_remove (child_ptr);
+ gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
+ gtk_tree_path_free (path);
+ }
+
+ /* the parent iter didn't actually change */
+ iter->stamp = model->details->stamp;
+ }
+ }
+
+ if (file_entry->file != NULL) /* Don't try to remove dummy row */
+ {
+ if (file_entry->parent != NULL)
+ {
+ g_hash_table_remove (file_entry->parent->reverse_map, file_entry->file);
+ }
+ else
+ {
+ g_hash_table_remove (model->details->top_reverse_map, file_entry->file);
+ }
+ }
+
+ parent_file_entry = file_entry->parent;
+ if (parent_file_entry && g_sequence_get_length (parent_file_entry->files) == 1 &&
+ file_entry->file != NULL)
+ {
+ /* this is the last non-dummy child, add a dummy node */
+ /* We need to do this before removing the last file to avoid
+ * collapsing the row.
+ */
+ add_dummy_row (model, parent_file_entry);
+ }
+
+ if (file_entry->subdirectory != NULL)
+ {
+ g_signal_emit (model,
+ list_model_signals[SUBDIRECTORY_UNLOADED], 0,
+ file_entry->subdirectory);
+ g_hash_table_remove (model->details->directory_reverse_map,
+ file_entry->subdirectory);
+ }
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter);
+
+ g_sequence_remove (ptr);
+ model->details->stamp++;
+ gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
+
+ gtk_tree_path_free (path);
+
+ if (parent_file_entry && g_sequence_get_length (parent_file_entry->files) == 0)
+ {
+ parent_iter.stamp = model->details->stamp;
+ parent_iter.user_data = parent_file_entry->ptr;
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &parent_iter);
+ gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model),
+ path, &parent_iter);
+ gtk_tree_path_free (path);
+ }
}
void
-nautilus_list_model_remove_file (NautilusListModel *model, NautilusFile *file,
- NautilusDirectory *directory)
+nautilus_list_model_remove_file (NautilusListModel *model,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
- GtkTreeIter iter;
+ GtkTreeIter iter;
- if (nautilus_list_model_get_tree_iter_from_file (model, file, directory, &iter)) {
- nautilus_list_model_remove (model, &iter);
- }
+ if (nautilus_list_model_get_tree_iter_from_file (model, file, directory, &iter))
+ {
+ nautilus_list_model_remove (model, &iter);
+ }
}
static void
-nautilus_list_model_clear_directory (NautilusListModel *model, GSequence *files)
-{
- GtkTreeIter iter;
- FileEntry *file_entry;
-
- while (g_sequence_get_length (files) > 0) {
- iter.user_data = g_sequence_get_begin_iter (files);
-
- file_entry = g_sequence_get (iter.user_data);
- if (file_entry->files != NULL) {
- nautilus_list_model_clear_directory (model, file_entry->files);
- }
-
- iter.stamp = model->details->stamp;
- nautilus_list_model_remove (model, &iter);
- }
+nautilus_list_model_clear_directory (NautilusListModel *model,
+ GSequence *files)
+{
+ GtkTreeIter iter;
+ FileEntry *file_entry;
+
+ while (g_sequence_get_length (files) > 0)
+ {
+ iter.user_data = g_sequence_get_begin_iter (files);
+
+ file_entry = g_sequence_get (iter.user_data);
+ if (file_entry->files != NULL)
+ {
+ nautilus_list_model_clear_directory (model, file_entry->files);
+ }
+
+ iter.stamp = model->details->stamp;
+ nautilus_list_model_remove (model, &iter);
+ }
}
void
nautilus_list_model_clear (NautilusListModel *model)
{
- g_return_if_fail (model != NULL);
+ g_return_if_fail (model != NULL);
- nautilus_list_model_clear_directory (model, model->details->files);
+ nautilus_list_model_clear_directory (model, model->details->files);
}
NautilusFile *
-nautilus_list_model_file_for_path (NautilusListModel *model, GtkTreePath *path)
-{
- NautilusFile *file;
- GtkTreeIter iter;
-
- file = NULL;
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model),
- &iter, path)) {
- gtk_tree_model_get (GTK_TREE_MODEL (model),
- &iter,
- NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
- -1);
- }
- return file;
+nautilus_list_model_file_for_path (NautilusListModel *model,
+ GtkTreePath *path)
+{
+ NautilusFile *file;
+ GtkTreeIter iter;
+
+ file = NULL;
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model),
+ &iter, path))
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (model),
+ &iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
+ }
+ return file;
}
gboolean
-nautilus_list_model_load_subdirectory (NautilusListModel *model, GtkTreePath *path, NautilusDirectory **directory)
-{
- GtkTreeIter iter;
- FileEntry *file_entry;
- NautilusDirectory *subdirectory;
-
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path)) {
- return FALSE;
- }
-
- file_entry = g_sequence_get (iter.user_data);
- if (file_entry->file == NULL ||
- file_entry->subdirectory != NULL) {
- return FALSE;
- }
-
- subdirectory = nautilus_directory_get_for_file (file_entry->file);
-
- if (g_hash_table_lookup (model->details->directory_reverse_map,
- subdirectory) != NULL) {
- nautilus_directory_unref (subdirectory);
- g_warning ("Already in directory_reverse_map, failing\n");
- return FALSE;
- }
-
- file_entry->subdirectory = subdirectory,
- g_hash_table_insert (model->details->directory_reverse_map,
- subdirectory, file_entry->ptr);
- file_entry->reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
-
- /* Return a ref too */
- nautilus_directory_ref (subdirectory);
- *directory = subdirectory;
-
- return TRUE;
+nautilus_list_model_load_subdirectory (NautilusListModel *model,
+ GtkTreePath *path,
+ NautilusDirectory **directory)
+{
+ GtkTreeIter iter;
+ FileEntry *file_entry;
+ NautilusDirectory *subdirectory;
+
+ if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
+ {
+ return FALSE;
+ }
+
+ file_entry = g_sequence_get (iter.user_data);
+ if (file_entry->file == NULL ||
+ file_entry->subdirectory != NULL)
+ {
+ return FALSE;
+ }
+
+ subdirectory = nautilus_directory_get_for_file (file_entry->file);
+
+ if (g_hash_table_lookup (model->details->directory_reverse_map,
+ subdirectory) != NULL)
+ {
+ nautilus_directory_unref (subdirectory);
+ g_warning ("Already in directory_reverse_map, failing\n");
+ return FALSE;
+ }
+
+ file_entry->subdirectory = subdirectory,
+ g_hash_table_insert (model->details->directory_reverse_map,
+ subdirectory, file_entry->ptr);
+ file_entry->reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+ /* Return a ref too */
+ nautilus_directory_ref (subdirectory);
+ *directory = subdirectory;
+
+ return TRUE;
}
/* removes all children of the subfolder and unloads the subdirectory */
void
-nautilus_list_model_unload_subdirectory (NautilusListModel *model, GtkTreeIter *iter)
-{
- GSequenceIter *child_ptr;
- FileEntry *file_entry, *child_file_entry;
- GtkTreeIter child_iter;
-
- file_entry = g_sequence_get (iter->user_data);
- if (file_entry->file == NULL ||
- file_entry->subdirectory == NULL) {
- return;
- }
-
- file_entry->loaded = 0;
-
- /* Remove all children */
- while (g_sequence_get_length (file_entry->files) > 0) {
- child_ptr = g_sequence_get_begin_iter (file_entry->files);
- child_file_entry = g_sequence_get (child_ptr);
- if (child_file_entry->file == NULL) {
- /* Don't delete the dummy node */
- break;
- } else {
- nautilus_list_model_ptr_to_iter (model, child_ptr, &child_iter);
- nautilus_list_model_remove (model, &child_iter);
- }
- }
-
- /* Emit unload signal */
- g_signal_emit (model,
- list_model_signals[SUBDIRECTORY_UNLOADED], 0,
- file_entry->subdirectory);
-
- /* actually unload */
- g_hash_table_remove (model->details->directory_reverse_map,
- file_entry->subdirectory);
- nautilus_directory_unref (file_entry->subdirectory);
- file_entry->subdirectory = NULL;
-
- g_assert (g_hash_table_size (file_entry->reverse_map) == 0);
- g_hash_table_destroy (file_entry->reverse_map);
- file_entry->reverse_map = NULL;
+nautilus_list_model_unload_subdirectory (NautilusListModel *model,
+ GtkTreeIter *iter)
+{
+ GSequenceIter *child_ptr;
+ FileEntry *file_entry, *child_file_entry;
+ GtkTreeIter child_iter;
+
+ file_entry = g_sequence_get (iter->user_data);
+ if (file_entry->file == NULL ||
+ file_entry->subdirectory == NULL)
+ {
+ return;
+ }
+
+ file_entry->loaded = 0;
+
+ /* Remove all children */
+ while (g_sequence_get_length (file_entry->files) > 0)
+ {
+ child_ptr = g_sequence_get_begin_iter (file_entry->files);
+ child_file_entry = g_sequence_get (child_ptr);
+ if (child_file_entry->file == NULL)
+ {
+ /* Don't delete the dummy node */
+ break;
+ }
+ else
+ {
+ nautilus_list_model_ptr_to_iter (model, child_ptr, &child_iter);
+ nautilus_list_model_remove (model, &child_iter);
+ }
+ }
+
+ /* Emit unload signal */
+ g_signal_emit (model,
+ list_model_signals[SUBDIRECTORY_UNLOADED], 0,
+ file_entry->subdirectory);
+
+ /* actually unload */
+ g_hash_table_remove (model->details->directory_reverse_map,
+ file_entry->subdirectory);
+ nautilus_directory_unref (file_entry->subdirectory);
+ file_entry->subdirectory = NULL;
+
+ g_assert (g_hash_table_size (file_entry->reverse_map) == 0);
+ g_hash_table_destroy (file_entry->reverse_map);
+ file_entry->reverse_map = NULL;
}
void
-nautilus_list_model_set_should_sort_directories_first (NautilusListModel *model, gboolean sort_directories_first)
+nautilus_list_model_set_should_sort_directories_first (NautilusListModel *model,
+ gboolean sort_directories_first)
{
- if (model->details->sort_directories_first == sort_directories_first) {
- return;
- }
+ if (model->details->sort_directories_first == sort_directories_first)
+ {
+ return;
+ }
- model->details->sort_directories_first = sort_directories_first;
- nautilus_list_model_sort (model);
+ model->details->sort_directories_first = sort_directories_first;
+ nautilus_list_model_sort (model);
}
int
nautilus_list_model_get_sort_column_id_from_attribute (NautilusListModel *model,
- GQuark attribute)
-{
- guint i;
-
- if (attribute == 0) {
- return -1;
- }
-
- /* Hack - the preferences dialog sets modification_date for some
- * rather than date_modified for some reason. Make sure that
- * works. */
- if (attribute == attribute_modification_date_q) {
- attribute = attribute_date_modified_q;
- }
-
- for (i = 0; i < model->details->columns->len; i++) {
- NautilusColumn *column;
- GQuark column_attribute;
-
- column =
- NAUTILUS_COLUMN (model->details->columns->pdata[i]);
- g_object_get (G_OBJECT (column),
- "attribute_q", &column_attribute,
- NULL);
- if (column_attribute == attribute) {
- return NAUTILUS_LIST_MODEL_NUM_COLUMNS + i;
- }
- }
-
- return -1;
+ GQuark attribute)
+{
+ guint i;
+
+ if (attribute == 0)
+ {
+ return -1;
+ }
+
+ /* Hack - the preferences dialog sets modification_date for some
+ * rather than date_modified for some reason. Make sure that
+ * works. */
+ if (attribute == attribute_modification_date_q)
+ {
+ attribute = attribute_date_modified_q;
+ }
+
+ for (i = 0; i < model->details->columns->len; i++)
+ {
+ NautilusColumn *column;
+ GQuark column_attribute;
+
+ column =
+ NAUTILUS_COLUMN (model->details->columns->pdata[i]);
+ g_object_get (G_OBJECT (column),
+ "attribute_q", &column_attribute,
+ NULL);
+ if (column_attribute == attribute)
+ {
+ return NAUTILUS_LIST_MODEL_NUM_COLUMNS + i;
+ }
+ }
+
+ return -1;
}
GQuark
nautilus_list_model_get_attribute_from_sort_column_id (NautilusListModel *model,
- int sort_column_id)
+ int sort_column_id)
{
- NautilusColumn *column;
- int index;
- GQuark attribute;
-
- index = sort_column_id - NAUTILUS_LIST_MODEL_NUM_COLUMNS;
+ NautilusColumn *column;
+ int index;
+ GQuark attribute;
- if (index < 0 || index >= model->details->columns->len) {
- g_warning ("unknown sort column id: %d", sort_column_id);
- return 0;
- }
+ index = sort_column_id - NAUTILUS_LIST_MODEL_NUM_COLUMNS;
- column = NAUTILUS_COLUMN (model->details->columns->pdata[index]);
- g_object_get (G_OBJECT (column), "attribute_q", &attribute, NULL);
+ if (index < 0 || index >= model->details->columns->len)
+ {
+ g_warning ("unknown sort column id: %d", sort_column_id);
+ return 0;
+ }
- return attribute;
+ column = NAUTILUS_COLUMN (model->details->columns->pdata[index]);
+ g_object_get (G_OBJECT (column), "attribute_q", &attribute, NULL);
+
+ return attribute;
}
NautilusListZoomLevel
nautilus_list_model_get_zoom_level_from_column_id (int column)
{
- switch (column) {
- case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
- return NAUTILUS_LIST_ZOOM_LEVEL_SMALL;
- case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
- return NAUTILUS_LIST_ZOOM_LEVEL_STANDARD;
- case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
- return NAUTILUS_LIST_ZOOM_LEVEL_LARGE;
- case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
- return NAUTILUS_LIST_ZOOM_LEVEL_LARGER;
- }
-
- g_return_val_if_reached (NAUTILUS_LIST_ZOOM_LEVEL_STANDARD);
+ switch (column)
+ {
+ case NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN:
+ {
+ return NAUTILUS_LIST_ZOOM_LEVEL_SMALL;
+ }
+
+ case NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN:
+ {
+ return NAUTILUS_LIST_ZOOM_LEVEL_STANDARD;
+ }
+
+ case NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN:
+ {
+ return NAUTILUS_LIST_ZOOM_LEVEL_LARGE;
+ }
+
+ case NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN:
+ return NAUTILUS_LIST_ZOOM_LEVEL_LARGER;
+ }
+
+ g_return_val_if_reached (NAUTILUS_LIST_ZOOM_LEVEL_STANDARD);
}
int
nautilus_list_model_get_column_id_from_zoom_level (NautilusListZoomLevel zoom_level)
{
- switch (zoom_level) {
- case NAUTILUS_LIST_ZOOM_LEVEL_SMALL:
- return NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN;
- case NAUTILUS_LIST_ZOOM_LEVEL_STANDARD:
- return NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN;
- case NAUTILUS_LIST_ZOOM_LEVEL_LARGE:
- return NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN;
- case NAUTILUS_LIST_ZOOM_LEVEL_LARGER:
- return NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN;
- }
-
- g_return_val_if_reached (NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN);
+ switch (zoom_level)
+ {
+ case NAUTILUS_LIST_ZOOM_LEVEL_SMALL:
+ {
+ return NAUTILUS_LIST_MODEL_SMALL_ICON_COLUMN;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_STANDARD:
+ {
+ return NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_LARGE:
+ {
+ return NAUTILUS_LIST_MODEL_LARGE_ICON_COLUMN;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_LARGER:
+ return NAUTILUS_LIST_MODEL_LARGER_ICON_COLUMN;
+ }
+
+ g_return_val_if_reached (NAUTILUS_LIST_MODEL_STANDARD_ICON_COLUMN);
}
void
nautilus_list_model_set_drag_view (NautilusListModel *model,
- GtkTreeView *view,
- int drag_begin_x,
- int drag_begin_y)
-{
- g_return_if_fail (model != NULL);
- g_return_if_fail (NAUTILUS_IS_LIST_MODEL (model));
- g_return_if_fail (!view || GTK_IS_TREE_VIEW (view));
-
- model->details->drag_view = view;
- model->details->drag_begin_x = drag_begin_x;
- model->details->drag_begin_y = drag_begin_y;
+ GtkTreeView *view,
+ int drag_begin_x,
+ int drag_begin_y)
+{
+ g_return_if_fail (model != NULL);
+ g_return_if_fail (NAUTILUS_IS_LIST_MODEL (model));
+ g_return_if_fail (!view || GTK_IS_TREE_VIEW (view));
+
+ model->details->drag_view = view;
+ model->details->drag_begin_x = drag_begin_x;
+ model->details->drag_begin_y = drag_begin_y;
}
GtkTreeView *
nautilus_list_model_get_drag_view (NautilusListModel *model,
- int *drag_begin_x,
- int *drag_begin_y)
+ int *drag_begin_x,
+ int *drag_begin_y)
{
- if (drag_begin_x != NULL) {
- *drag_begin_x = model->details->drag_begin_x;
- }
+ if (drag_begin_x != NULL)
+ {
+ *drag_begin_x = model->details->drag_begin_x;
+ }
- if (drag_begin_y != NULL) {
- *drag_begin_y = model->details->drag_begin_y;
- }
+ if (drag_begin_y != NULL)
+ {
+ *drag_begin_y = model->details->drag_begin_y;
+ }
- return model->details->drag_view;
+ return model->details->drag_view;
}
GtkTargetList *
nautilus_list_model_get_drag_target_list ()
{
- GtkTargetList *target_list;
+ GtkTargetList *target_list;
- target_list = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types));
- gtk_target_list_add_text_targets (target_list, NAUTILUS_ICON_DND_TEXT);
+ target_list = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types));
+ gtk_target_list_add_text_targets (target_list, NAUTILUS_ICON_DND_TEXT);
- return target_list;
+ return target_list;
}
-int
+int
nautilus_list_model_add_column (NautilusListModel *model,
- NautilusColumn *column)
+ NautilusColumn *column)
{
- g_ptr_array_add (model->details->columns, column);
- g_object_ref (column);
+ g_ptr_array_add (model->details->columns, column);
+ g_object_ref (column);
- return NAUTILUS_LIST_MODEL_NUM_COLUMNS + (model->details->columns->len - 1);
+ return NAUTILUS_LIST_MODEL_NUM_COLUMNS + (model->details->columns->len - 1);
}
static void
nautilus_list_model_dispose (GObject *object)
{
- NautilusListModel *model;
- int i;
-
- model = NAUTILUS_LIST_MODEL (object);
-
- if (model->details->columns) {
- for (i = 0; i < model->details->columns->len; i++) {
- g_object_unref (model->details->columns->pdata[i]);
- }
- g_ptr_array_free (model->details->columns, TRUE);
- model->details->columns = NULL;
- }
-
- if (model->details->files) {
- g_sequence_free (model->details->files);
- model->details->files = NULL;
- }
-
- if (model->details->top_reverse_map) {
- g_hash_table_destroy (model->details->top_reverse_map);
- model->details->top_reverse_map = NULL;
- }
- if (model->details->directory_reverse_map) {
- g_hash_table_destroy (model->details->directory_reverse_map);
- model->details->directory_reverse_map = NULL;
- }
-
- G_OBJECT_CLASS (nautilus_list_model_parent_class)->dispose (object);
+ NautilusListModel *model;
+ int i;
+
+ model = NAUTILUS_LIST_MODEL (object);
+
+ if (model->details->columns)
+ {
+ for (i = 0; i < model->details->columns->len; i++)
+ {
+ g_object_unref (model->details->columns->pdata[i]);
+ }
+ g_ptr_array_free (model->details->columns, TRUE);
+ model->details->columns = NULL;
+ }
+
+ if (model->details->files)
+ {
+ g_sequence_free (model->details->files);
+ model->details->files = NULL;
+ }
+
+ if (model->details->top_reverse_map)
+ {
+ g_hash_table_destroy (model->details->top_reverse_map);
+ model->details->top_reverse_map = NULL;
+ }
+ if (model->details->directory_reverse_map)
+ {
+ g_hash_table_destroy (model->details->directory_reverse_map);
+ model->details->directory_reverse_map = NULL;
+ }
+
+ G_OBJECT_CLASS (nautilus_list_model_parent_class)->dispose (object);
}
static void
nautilus_list_model_finalize (GObject *object)
{
- NautilusListModel *model;
+ NautilusListModel *model;
- model = NAUTILUS_LIST_MODEL (object);
+ model = NAUTILUS_LIST_MODEL (object);
- if (model->details->highlight_files != NULL) {
- nautilus_file_list_free (model->details->highlight_files);
- model->details->highlight_files = NULL;
- }
+ if (model->details->highlight_files != NULL)
+ {
+ nautilus_file_list_free (model->details->highlight_files);
+ model->details->highlight_files = NULL;
+ }
- g_free (model->details);
+ g_free (model->details);
- G_OBJECT_CLASS (nautilus_list_model_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_list_model_parent_class)->finalize (object);
}
static void
nautilus_list_model_init (NautilusListModel *model)
{
- model->details = g_new0 (NautilusListModelDetails, 1);
- model->details->files = g_sequence_new ((GDestroyNotify)file_entry_free);
- model->details->top_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
- model->details->directory_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
- model->details->stamp = g_random_int ();
- model->details->sort_attribute = 0;
- model->details->columns = g_ptr_array_new ();
+ model->details = g_new0 (NautilusListModelDetails, 1);
+ model->details->files = g_sequence_new ((GDestroyNotify) file_entry_free);
+ model->details->top_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+ model->details->directory_reverse_map = g_hash_table_new (g_direct_hash, g_direct_equal);
+ model->details->stamp = g_random_int ();
+ model->details->sort_attribute = 0;
+ model->details->columns = g_ptr_array_new ();
}
static void
nautilus_list_model_class_init (NautilusListModelClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
+
+ attribute_name_q = g_quark_from_static_string ("name");
+ attribute_modification_date_q = g_quark_from_static_string ("modification_date");
+ attribute_date_modified_q = g_quark_from_static_string ("date_modified");
- attribute_name_q = g_quark_from_static_string ("name");
- attribute_modification_date_q = g_quark_from_static_string ("modification_date");
- attribute_date_modified_q = g_quark_from_static_string ("date_modified");
-
- object_class = (GObjectClass *)klass;
- object_class->finalize = nautilus_list_model_finalize;
- object_class->dispose = nautilus_list_model_dispose;
+ object_class = (GObjectClass *) klass;
+ object_class->finalize = nautilus_list_model_finalize;
+ object_class->dispose = nautilus_list_model_dispose;
- list_model_signals[SUBDIRECTORY_UNLOADED] =
+ list_model_signals[SUBDIRECTORY_UNLOADED] =
g_signal_new ("subdirectory-unloaded",
NAUTILUS_TYPE_LIST_MODEL,
G_SIGNAL_RUN_FIRST,
@@ -1420,120 +1640,127 @@ nautilus_list_model_class_init (NautilusListModelClass *klass)
G_TYPE_NONE, 1,
NAUTILUS_TYPE_DIRECTORY);
- list_model_signals[GET_ICON_SCALE] =
- g_signal_new ("get-icon-scale",
- NAUTILUS_TYPE_LIST_MODEL,
- G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- NULL,
- G_TYPE_INT, 0);
+ list_model_signals[GET_ICON_SCALE] =
+ g_signal_new ("get-icon-scale",
+ NAUTILUS_TYPE_LIST_MODEL,
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ NULL,
+ G_TYPE_INT, 0);
}
static void
nautilus_list_model_tree_model_init (GtkTreeModelIface *iface)
{
- iface->get_flags = nautilus_list_model_get_flags;
- iface->get_n_columns = nautilus_list_model_get_n_columns;
- iface->get_column_type = nautilus_list_model_get_column_type;
- iface->get_iter = nautilus_list_model_get_iter;
- iface->get_path = nautilus_list_model_get_path;
- iface->get_value = nautilus_list_model_get_value;
- iface->iter_next = nautilus_list_model_iter_next;
- iface->iter_children = nautilus_list_model_iter_children;
- iface->iter_has_child = nautilus_list_model_iter_has_child;
- iface->iter_n_children = nautilus_list_model_iter_n_children;
- iface->iter_nth_child = nautilus_list_model_iter_nth_child;
- iface->iter_parent = nautilus_list_model_iter_parent;
+ iface->get_flags = nautilus_list_model_get_flags;
+ iface->get_n_columns = nautilus_list_model_get_n_columns;
+ iface->get_column_type = nautilus_list_model_get_column_type;
+ iface->get_iter = nautilus_list_model_get_iter;
+ iface->get_path = nautilus_list_model_get_path;
+ iface->get_value = nautilus_list_model_get_value;
+ iface->iter_next = nautilus_list_model_iter_next;
+ iface->iter_children = nautilus_list_model_iter_children;
+ iface->iter_has_child = nautilus_list_model_iter_has_child;
+ iface->iter_n_children = nautilus_list_model_iter_n_children;
+ iface->iter_nth_child = nautilus_list_model_iter_nth_child;
+ iface->iter_parent = nautilus_list_model_iter_parent;
}
static void
nautilus_list_model_sortable_init (GtkTreeSortableIface *iface)
{
- iface->get_sort_column_id = nautilus_list_model_get_sort_column_id;
- iface->set_sort_column_id = nautilus_list_model_set_sort_column_id;
- iface->has_default_sort_func = nautilus_list_model_has_default_sort_func;
+ iface->get_sort_column_id = nautilus_list_model_get_sort_column_id;
+ iface->set_sort_column_id = nautilus_list_model_set_sort_column_id;
+ iface->has_default_sort_func = nautilus_list_model_has_default_sort_func;
}
void
-nautilus_list_model_subdirectory_done_loading (NautilusListModel *model, NautilusDirectory *directory)
-{
- GtkTreeIter iter;
- GtkTreePath *path;
- FileEntry *file_entry, *dummy_entry;
- GSequenceIter *parent_ptr, *dummy_ptr;
- GSequence *files;
-
- if (model == NULL || model->details->directory_reverse_map == NULL) {
- return;
- }
- parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
- directory);
- if (parent_ptr == NULL) {
- return;
- }
-
- file_entry = g_sequence_get (parent_ptr);
- files = file_entry->files;
-
- /* Only swap loading -> empty if we saw no files yet at "done",
- * otherwise, toggle loading at first added file to the model.
- */
- if (!nautilus_directory_is_not_empty (directory) &&
- g_sequence_get_length (files) == 1) {
- dummy_ptr = g_sequence_get_iter_at_pos (file_entry->files, 0);
- dummy_entry = g_sequence_get (dummy_ptr);
- if (dummy_entry->file == NULL) {
- /* was the dummy file */
- file_entry->loaded = 1;
-
- iter.stamp = model->details->stamp;
- iter.user_data = dummy_ptr;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
- }
- }
+nautilus_list_model_subdirectory_done_loading (NautilusListModel *model,
+ NautilusDirectory *directory)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ FileEntry *file_entry, *dummy_entry;
+ GSequenceIter *parent_ptr, *dummy_ptr;
+ GSequence *files;
+
+ if (model == NULL || model->details->directory_reverse_map == NULL)
+ {
+ return;
+ }
+ parent_ptr = g_hash_table_lookup (model->details->directory_reverse_map,
+ directory);
+ if (parent_ptr == NULL)
+ {
+ return;
+ }
+
+ file_entry = g_sequence_get (parent_ptr);
+ files = file_entry->files;
+
+ /* Only swap loading -> empty if we saw no files yet at "done",
+ * otherwise, toggle loading at first added file to the model.
+ */
+ if (!nautilus_directory_is_not_empty (directory) &&
+ g_sequence_get_length (files) == 1)
+ {
+ dummy_ptr = g_sequence_get_iter_at_pos (file_entry->files, 0);
+ dummy_entry = g_sequence_get (dummy_ptr);
+ if (dummy_entry->file == NULL)
+ {
+ /* was the dummy file */
+ file_entry->loaded = 1;
+
+ iter.stamp = model->details->stamp;
+ iter.user_data = dummy_ptr;
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+ }
+ }
}
static void
refresh_row (gpointer data,
gpointer user_data)
{
- NautilusFile *file;
- NautilusListModel *model;
- GList *iters, *l;
- GtkTreePath *path;
+ NautilusFile *file;
+ NautilusListModel *model;
+ GList *iters, *l;
+ GtkTreePath *path;
- model = user_data;
- file = data;
+ model = user_data;
+ file = data;
- iters = nautilus_list_model_get_all_iters_for_file (model, file);
- for (l = iters; l != NULL; l = l->next) {
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), l->data);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, l->data);
+ iters = nautilus_list_model_get_all_iters_for_file (model, file);
+ for (l = iters; l != NULL; l = l->next)
+ {
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), l->data);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, l->data);
- gtk_tree_path_free (path);
- }
+ gtk_tree_path_free (path);
+ }
- g_list_free_full (iters, g_free);
+ g_list_free_full (iters, g_free);
}
void
nautilus_list_model_set_highlight_for_files (NautilusListModel *model,
- GList *files)
+ GList *files)
{
- if (model->details->highlight_files != NULL) {
- g_list_foreach (model->details->highlight_files,
- refresh_row, model);
- nautilus_file_list_free (model->details->highlight_files);
- model->details->highlight_files = NULL;
- }
-
- if (files != NULL) {
- model->details->highlight_files = nautilus_file_list_copy (files);
- g_list_foreach (model->details->highlight_files,
- refresh_row, model);
-
- }
+ if (model->details->highlight_files != NULL)
+ {
+ g_list_foreach (model->details->highlight_files,
+ refresh_row, model);
+ nautilus_file_list_free (model->details->highlight_files);
+ model->details->highlight_files = NULL;
+ }
+
+ if (files != NULL)
+ {
+ model->details->highlight_files = nautilus_file_list_copy (files);
+ g_list_foreach (model->details->highlight_files,
+ refresh_row, model);
+ }
}
diff --git a/src/nautilus-list-view-dnd.c b/src/nautilus-list-view-dnd.c
index 1706b2679..4baa28eb1 100644
--- a/src/nautilus-list-view-dnd.c
+++ b/src/nautilus-list-view-dnd.c
@@ -21,7 +21,7 @@
#include "nautilus-list-view-dnd.h"
#include "nautilus-list-view-private.h"
-static GtkTargetList * source_target_list = NULL;
+static GtkTargetList *source_target_list = NULL;
static void
drag_info_data_free (NautilusListView *list_view);
@@ -34,65 +34,70 @@ drag_data_get_callback (GtkWidget *widget,
guint time,
gpointer user_data)
{
- GtkTreeView *tree_view;
- GtkTreeModel *model;
- NautilusListView *list_view;
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
+ NautilusListView *list_view;
- tree_view = GTK_TREE_VIEW (widget);
- list_view = NAUTILUS_LIST_VIEW (user_data);
+ tree_view = GTK_TREE_VIEW (widget);
+ list_view = NAUTILUS_LIST_VIEW (user_data);
- model = gtk_tree_view_get_model (tree_view);
+ model = gtk_tree_view_get_model (tree_view);
- if (model == NULL)
- return;
+ if (model == NULL)
+ {
+ return;
+ }
- if (list_view->details->drag_source_info == NULL ||
- list_view->details->drag_source_info->selection_cache == NULL)
- return;
+ if (list_view->details->drag_source_info == NULL ||
+ list_view->details->drag_source_info->selection_cache == NULL)
+ {
+ return;
+ }
- nautilus_drag_drag_data_get_from_cache (list_view->details->drag_source_info->selection_cache,
- context, selection_data, info, time);
+ nautilus_drag_drag_data_get_from_cache (list_view->details->drag_source_info->selection_cache,
+ context, selection_data, info, time);
}
static cairo_surface_t *
get_drag_surface (NautilusListView *view)
{
- GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeIter iter;
- cairo_surface_t *ret;
- GdkRectangle cell_area;
-
- ret = NULL;
-
- if (gtk_tree_view_get_path_at_pos (view->details->tree_view,
- view->details->drag_x,
- view->details->drag_y,
- &path, NULL, NULL, NULL))
+ GtkTreeModel *model;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ cairo_surface_t *ret;
+ GdkRectangle cell_area;
+
+ ret = NULL;
+
+ if (gtk_tree_view_get_path_at_pos (view->details->tree_view,
+ view->details->drag_x,
+ view->details->drag_y,
+ &path, NULL, NULL, NULL))
{
- model = gtk_tree_view_get_model (view->details->tree_view);
- gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter,
- nautilus_list_model_get_column_id_from_zoom_level (view->details->zoom_level),
- &ret,
- -1);
+ model = gtk_tree_view_get_model (view->details->tree_view);
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_get (model, &iter,
+ nautilus_list_model_get_column_id_from_zoom_level (view->details->zoom_level),
+ &ret,
+ -1);
}
- gtk_tree_view_get_cell_area (view->details->tree_view,
- path,
- view->details->file_name_column,
- &cell_area);
+ gtk_tree_view_get_cell_area (view->details->tree_view,
+ path,
+ view->details->file_name_column,
+ &cell_area);
- gtk_tree_path_free (path);
+ gtk_tree_path_free (path);
- return ret;
+ return ret;
}
/* iteration glue struct */
-typedef struct {
- NautilusListView *view;
- NautilusDragEachSelectedItemDataGet iteratee;
- gpointer iteratee_data;
+typedef struct
+{
+ NautilusListView *view;
+ NautilusDragEachSelectedItemDataGet iteratee;
+ gpointer iteratee_data;
} ListGetDataBinderContext;
static void
@@ -101,44 +106,50 @@ item_get_data_binder (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
- ListGetDataBinderContext *context = data;
- NautilusFile *file;
- GtkTreeView *treeview;
- GtkTreeViewColumn *column;
- GdkRectangle cell_area;
- int drag_begin_y = 0;
- char *uri;
-
- treeview = nautilus_list_model_get_drag_view (context->view->details->model,
- NULL,
- &drag_begin_y);
- column = gtk_tree_view_get_column (treeview, 0);
-
- file = nautilus_list_model_file_for_path (NAUTILUS_LIST_MODEL (model), path);
- if (file == NULL)
- return;
-
- gtk_tree_view_get_cell_area (treeview,
- path,
- column,
- &cell_area);
-
- if (nautilus_file_is_nautilus_link (file))
- uri = nautilus_file_get_uri (file);
- else
- uri = nautilus_file_get_activation_uri (file);
-
- nautilus_file_unref (file);
-
- /* pass the uri, mouse-relative x/y and icon width/height */
- context->iteratee (uri,
- 0,
- cell_area.y - drag_begin_y,
- cell_area.width,
- cell_area.height,
- context->iteratee_data);
-
- g_free (uri);
+ ListGetDataBinderContext *context = data;
+ NautilusFile *file;
+ GtkTreeView *treeview;
+ GtkTreeViewColumn *column;
+ GdkRectangle cell_area;
+ int drag_begin_y = 0;
+ char *uri;
+
+ treeview = nautilus_list_model_get_drag_view (context->view->details->model,
+ NULL,
+ &drag_begin_y);
+ column = gtk_tree_view_get_column (treeview, 0);
+
+ file = nautilus_list_model_file_for_path (NAUTILUS_LIST_MODEL (model), path);
+ if (file == NULL)
+ {
+ return;
+ }
+
+ gtk_tree_view_get_cell_area (treeview,
+ path,
+ column,
+ &cell_area);
+
+ if (nautilus_file_is_nautilus_link (file))
+ {
+ uri = nautilus_file_get_uri (file);
+ }
+ else
+ {
+ uri = nautilus_file_get_activation_uri (file);
+ }
+
+ nautilus_file_unref (file);
+
+ /* pass the uri, mouse-relative x/y and icon width/height */
+ context->iteratee (uri,
+ 0,
+ cell_area.y - drag_begin_y,
+ cell_area.width,
+ cell_area.height,
+ context->iteratee_data);
+
+ g_free (uri);
}
static void
@@ -146,16 +157,16 @@ each_item_get_data_binder (NautilusDragEachSelectedItemDataGet iteratee,
gpointer iterator_context,
gpointer data)
{
- NautilusListView *view = NAUTILUS_LIST_VIEW (iterator_context);
- ListGetDataBinderContext context;
- GtkTreeSelection *selection;
+ NautilusListView *view = NAUTILUS_LIST_VIEW (iterator_context);
+ ListGetDataBinderContext context;
+ GtkTreeSelection *selection;
- context.view = view;
- context.iteratee = iteratee;
- context.iteratee_data = data;
+ context.view = view;
+ context.iteratee = iteratee;
+ context.iteratee_data = data;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view->details->tree_view));
- gtk_tree_selection_selected_foreach (selection, item_get_data_binder, &context);
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view->details->tree_view));
+ gtk_tree_selection_selected_foreach (selection, item_get_data_binder, &context);
}
static void
@@ -163,28 +174,28 @@ drag_begin_callback (GtkWidget *widget,
GdkDragContext *context,
NautilusListView *view)
{
- cairo_surface_t *surface;
- NautilusWindow *window;
+ cairo_surface_t *surface;
+ NautilusWindow *window;
- window = nautilus_files_view_get_window (NAUTILUS_FILES_VIEW (view));
- surface = get_drag_surface (view);
- if (surface)
+ window = nautilus_files_view_get_window (NAUTILUS_FILES_VIEW (view));
+ surface = get_drag_surface (view);
+ if (surface)
{
- gtk_drag_set_icon_surface (context, surface);
- cairo_surface_destroy (surface);
+ gtk_drag_set_icon_surface (context, surface);
+ cairo_surface_destroy (surface);
}
- else
+ else
{
- gtk_drag_set_icon_default (context);
+ gtk_drag_set_icon_default (context);
}
- view->details->drag_button = 0;
- view->details->drag_started = TRUE;
+ view->details->drag_button = 0;
+ view->details->drag_started = TRUE;
- view->details->drag_source_info->selection_cache = nautilus_drag_create_selection_cache (view,
- each_item_get_data_binder);
+ view->details->drag_source_info->selection_cache = nautilus_drag_create_selection_cache (view,
+ each_item_get_data_binder);
- nautilus_window_start_dnd (window, context);
+ nautilus_window_start_dnd (window, context);
}
static void
@@ -192,95 +203,103 @@ drag_end_callback (GtkWidget *widget,
GdkDragContext *context,
NautilusListView *list_view)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = nautilus_files_view_get_window (NAUTILUS_FILES_VIEW (list_view));
+ window = nautilus_files_view_get_window (NAUTILUS_FILES_VIEW (list_view));
- nautilus_window_end_dnd (window, context);
+ nautilus_window_end_dnd (window, context);
- drag_info_data_free (list_view);
+ drag_info_data_free (list_view);
}
static void
drag_info_data_free (NautilusListView *list_view)
{
- nautilus_drag_destroy_selection_list (list_view->details->drag_source_info->selection_cache);
- list_view->details->drag_source_info->selection_cache = NULL;
+ nautilus_drag_destroy_selection_list (list_view->details->drag_source_info->selection_cache);
+ list_view->details->drag_source_info->selection_cache = NULL;
- g_free (list_view->details->drag_source_info);
- list_view->details->drag_source_info = NULL;
+ g_free (list_view->details->drag_source_info);
+ list_view->details->drag_source_info = NULL;
- g_signal_handlers_disconnect_by_func (list_view->details->tree_view, drag_begin_callback, list_view);
- g_signal_handlers_disconnect_by_func (list_view->details->tree_view, drag_data_get_callback, list_view);
- g_signal_handlers_disconnect_by_func (list_view->details->tree_view, drag_end_callback, list_view);
+ g_signal_handlers_disconnect_by_func (list_view->details->tree_view, drag_begin_callback, list_view);
+ g_signal_handlers_disconnect_by_func (list_view->details->tree_view, drag_data_get_callback, list_view);
+ g_signal_handlers_disconnect_by_func (list_view->details->tree_view, drag_end_callback, list_view);
}
NautilusDragInfo *
nautilus_list_view_dnd_get_drag_source_data (NautilusListView *list_view,
GdkDragContext *context)
{
- GtkTreeView *tree_view;
- GtkTreeModel *model;
+ GtkTreeView *tree_view;
+ GtkTreeModel *model;
- tree_view = GTK_TREE_VIEW (list_view->details->tree_view);
+ tree_view = GTK_TREE_VIEW (list_view->details->tree_view);
- model = gtk_tree_view_get_model (tree_view);
+ model = gtk_tree_view_get_model (tree_view);
- if (model == NULL)
- return NULL;
+ if (model == NULL)
+ {
+ return NULL;
+ }
- if (list_view->details->drag_source_info == NULL ||
- list_view->details->drag_source_info->selection_cache == NULL)
- return NULL;
+ if (list_view->details->drag_source_info == NULL ||
+ list_view->details->drag_source_info->selection_cache == NULL)
+ {
+ return NULL;
+ }
- return list_view->details->drag_source_info;
+ return list_view->details->drag_source_info;
}
void
nautilus_list_view_dnd_init (NautilusListView *list_view)
{
- if (list_view->details->drag_source_info != NULL)
- return;
+ if (list_view->details->drag_source_info != NULL)
+ {
+ return;
+ }
- list_view->details->drag_source_info = g_new0 (NautilusDragInfo, 1);
+ list_view->details->drag_source_info = g_new0 (NautilusDragInfo, 1);
- g_signal_connect_object (list_view->details->tree_view, "drag-begin",
- G_CALLBACK (drag_begin_callback), list_view, 0);
- g_signal_connect_object (list_view->details->tree_view, "drag-end",
- G_CALLBACK (drag_end_callback), list_view, 0);
- g_signal_connect_object (list_view->details->tree_view, "drag-data-get",
- G_CALLBACK (drag_data_get_callback), list_view, 0);
+ g_signal_connect_object (list_view->details->tree_view, "drag-begin",
+ G_CALLBACK (drag_begin_callback), list_view, 0);
+ g_signal_connect_object (list_view->details->tree_view, "drag-end",
+ G_CALLBACK (drag_end_callback), list_view, 0);
+ g_signal_connect_object (list_view->details->tree_view, "drag-data-get",
+ G_CALLBACK (drag_data_get_callback), list_view, 0);
}
gboolean
nautilus_list_view_dnd_drag_begin (NautilusListView *list_view,
GdkEventMotion *event)
{
- if (list_view->details->drag_button != 0)
+ if (list_view->details->drag_button != 0)
{
- if (!source_target_list)
- source_target_list = nautilus_list_model_get_drag_target_list ();
-
- if (gtk_drag_check_threshold (GTK_WIDGET (list_view->details->tree_view),
- list_view->details->drag_x,
- list_view->details->drag_y,
- event->x,
- event->y))
+ if (!source_target_list)
+ {
+ source_target_list = nautilus_list_model_get_drag_target_list ();
+ }
+
+ if (gtk_drag_check_threshold (GTK_WIDGET (list_view->details->tree_view),
+ list_view->details->drag_x,
+ list_view->details->drag_y,
+ event->x,
+ event->y))
{
- guint32 actions;
-
- actions = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK;
- list_view->details->drag_source_info->source_actions = actions;
- gtk_drag_begin_with_coordinates (GTK_WIDGET (list_view->details->tree_view),
- source_target_list,
- actions,
- list_view->details->drag_button,
- (GdkEvent*)event,
- -1,
- -1);
+ guint32 actions;
+
+ actions = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK;
+ list_view->details->drag_source_info->source_actions = actions;
+ gtk_drag_begin_with_coordinates (GTK_WIDGET (list_view->details->tree_view),
+ source_target_list,
+ actions,
+ list_view->details->drag_button,
+ (GdkEvent *) event,
+ -1,
+ -1);
}
- return TRUE;
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 4e69434b6..490b4bafb 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -1,27 +1,26 @@
-
/* fm-list-view.c - implementation of list view of directory.
-
- Copyright (C) 2000 Eazel, Inc.
- Copyright (C) 2001, 2002 Anders Carlsson <andersca@gnu.org>
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: John Sullivan <sullivan@eazel.com>
- Anders Carlsson <andersca@gnu.org>
- David Emory Watson <dwatson@cs.ucr.edu>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ * Copyright (C) 2001, 2002 Anders Carlsson <andersca@gnu.org>
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: John Sullivan <sullivan@eazel.com>
+ * Anders Carlsson <andersca@gnu.org>
+ * David Emory Watson <dwatson@cs.ucr.edu>
+ */
#include <config.h>
#include "nautilus-list-view.h"
@@ -65,9 +64,10 @@
* in the edges if the window is small */
#define RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH 40
-struct SelectionForeachData {
- GList *list;
- GtkTreeSelection *selection;
+struct SelectionForeachData
+{
+ GList *list;
+ GtkTreeSelection *selection;
};
/*
@@ -75,1335 +75,1520 @@ struct SelectionForeachData {
* Computing this would be costly, so we just choose a number
* that works well with the set of emblems we've designed.
*/
-#define LIST_VIEW_MINIMUM_ROW_HEIGHT 28
+#define LIST_VIEW_MINIMUM_ROW_HEIGHT 28
/* We wait two seconds after row is collapsed to unload the subdirectory */
#define COLLAPSE_TO_UNLOAD_DELAY 2
-static GdkCursor * hand_cursor = NULL;
+static GdkCursor *hand_cursor = NULL;
-static GList *nautilus_list_view_get_selection (NautilusFilesView *view);
-static GList *nautilus_list_view_get_selection_for_file_transfer (NautilusFilesView *view);
-static void nautilus_list_view_set_zoom_level (NautilusListView *view,
- NautilusListZoomLevel new_level);
-static void nautilus_list_view_scroll_to_file (NautilusListView *view,
- NautilusFile *file);
+static GList *nautilus_list_view_get_selection (NautilusFilesView *view);
+static GList *nautilus_list_view_get_selection_for_file_transfer (NautilusFilesView *view);
+static void nautilus_list_view_set_zoom_level (NautilusListView *view,
+ NautilusListZoomLevel new_level);
+static void nautilus_list_view_scroll_to_file (NautilusListView *view,
+ NautilusFile *file);
-static void apply_columns_settings (NautilusListView *list_view,
- char **column_order,
- char **visible_columns);
-static char **get_visible_columns (NautilusListView *list_view);
-static char **get_default_visible_columns (NautilusListView *list_view);
-static char **get_column_order (NautilusListView *list_view);
-static char **get_default_column_order (NautilusListView *list_view);
+static void apply_columns_settings (NautilusListView *list_view,
+ char **column_order,
+ char **visible_columns);
+static char **get_visible_columns (NautilusListView *list_view);
+static char **get_default_visible_columns (NautilusListView *list_view);
+static char **get_column_order (NautilusListView *list_view);
+static char **get_default_column_order (NautilusListView *list_view);
G_DEFINE_TYPE (NautilusListView, nautilus_list_view, NAUTILUS_TYPE_FILES_VIEW);
-static const char * default_search_visible_columns[] = {
- "name", "size", "where", NULL
+static const char *default_search_visible_columns[] =
+{
+ "name", "size", "where", NULL
};
-static const char * default_search_columns_order[] = {
- "name", "size", "where", NULL
+static const char *default_search_columns_order[] =
+{
+ "name", "size", "where", NULL
};
-static const char * default_trash_visible_columns[] = {
- "name", "size", "trash_orig_path", "trashed_on", NULL
+static const char *default_trash_visible_columns[] =
+{
+ "name", "size", "trash_orig_path", "trashed_on", NULL
};
-static const char * default_trash_columns_order[] = {
- "name", "size", "trash_orig_path", "trashed_on", NULL
+static const char *default_trash_columns_order[] =
+{
+ "name", "size", "trash_orig_path", "trashed_on", NULL
};
-static const gchar*
-get_default_sort_order (NautilusFile *file, gboolean *reversed)
+static const gchar *
+get_default_sort_order (NautilusFile *file,
+ gboolean *reversed)
{
- NautilusFileSortType default_sort_order;
- gboolean default_sort_reversed;
- const gchar *retval;
- const char *attributes[] = {
- "name", /* is really "manually" which doesn't apply to lists */
- "name",
- "size",
- "type",
- "date_modified",
- "date_accessed",
- "trashed_on",
- NULL
- };
+ NautilusFileSortType default_sort_order;
+ gboolean default_sort_reversed;
+ const gchar *retval;
+ const char *attributes[] =
+ {
+ "name", /* is really "manually" which doesn't apply to lists */
+ "name",
+ "size",
+ "type",
+ "date_modified",
+ "date_accessed",
+ "trashed_on",
+ NULL
+ };
- retval = nautilus_file_get_default_sort_attribute (file, reversed);
+ retval = nautilus_file_get_default_sort_attribute (file, reversed);
- if (retval == NULL) {
- default_sort_order = g_settings_get_enum (nautilus_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
- default_sort_reversed = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
+ if (retval == NULL)
+ {
+ default_sort_order = g_settings_get_enum (nautilus_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER);
+ default_sort_reversed = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
- retval = attributes[default_sort_order];
- *reversed = default_sort_reversed;
- }
+ retval = attributes[default_sort_order];
+ *reversed = default_sort_reversed;
+ }
- return retval;
+ return retval;
}
static void
-list_selection_changed_callback (GtkTreeSelection *selection, gpointer user_data)
+list_selection_changed_callback (GtkTreeSelection *selection,
+ gpointer user_data)
{
- NautilusFilesView *view;
+ NautilusFilesView *view;
- view = NAUTILUS_FILES_VIEW (user_data);
+ view = NAUTILUS_FILES_VIEW (user_data);
- nautilus_files_view_notify_selection_changed (view);
+ nautilus_files_view_notify_selection_changed (view);
}
/* Move these to eel? */
static void
tree_selection_foreach_set_boolean (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer callback_data)
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer callback_data)
{
- * (gboolean *) callback_data = TRUE;
+ *(gboolean *) callback_data = TRUE;
}
static gboolean
tree_selection_not_empty (GtkTreeSelection *selection)
{
- gboolean not_empty;
+ gboolean not_empty;
- not_empty = FALSE;
- gtk_tree_selection_selected_foreach (selection,
- tree_selection_foreach_set_boolean,
- &not_empty);
- return not_empty;
+ not_empty = FALSE;
+ gtk_tree_selection_selected_foreach (selection,
+ tree_selection_foreach_set_boolean,
+ &not_empty);
+ return not_empty;
}
static gboolean
tree_view_has_selection (GtkTreeView *view)
{
- return tree_selection_not_empty (gtk_tree_view_get_selection (view));
+ return tree_selection_not_empty (gtk_tree_view_get_selection (view));
}
static void
preview_selected_items (NautilusListView *view)
{
- GList *file_list;
-
- file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
+ GList *file_list;
+
+ file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
- if (file_list != NULL) {
- nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (view),
- file_list, NULL);
- nautilus_file_list_free (file_list);
- }
+ if (file_list != NULL)
+ {
+ nautilus_files_view_preview_files (NAUTILUS_FILES_VIEW (view),
+ file_list, NULL);
+ nautilus_file_list_free (file_list);
+ }
}
static void
activate_selected_items (NautilusListView *view)
{
- GList *file_list;
-
- file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
- nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (view),
- file_list,
- 0, TRUE);
- nautilus_file_list_free (file_list);
+ GList *file_list;
+ file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
+ nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (view),
+ file_list,
+ 0, TRUE);
+ nautilus_file_list_free (file_list);
}
static void
activate_selected_items_alternate (NautilusListView *view,
- NautilusFile *file,
- gboolean open_in_tab)
-{
- GList *file_list;
- NautilusWindowOpenFlags flags;
-
- flags = 0;
-
- if (open_in_tab) {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
- } else {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- }
-
- if (file != NULL) {
- nautilus_file_ref (file);
- file_list = g_list_prepend (NULL, file);
- } else {
- file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
- }
- nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (view),
- file_list,
- flags,
- TRUE);
- nautilus_file_list_free (file_list);
-
+ NautilusFile *file,
+ gboolean open_in_tab)
+{
+ GList *file_list;
+ NautilusWindowOpenFlags flags;
+
+ flags = 0;
+
+ if (open_in_tab)
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
+ }
+ else
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ }
+
+ if (file != NULL)
+ {
+ nautilus_file_ref (file);
+ file_list = g_list_prepend (NULL, file);
+ }
+ else
+ {
+ file_list = nautilus_list_view_get_selection (NAUTILUS_FILES_VIEW (view));
+ }
+ nautilus_files_view_activate_files (NAUTILUS_FILES_VIEW (view),
+ file_list,
+ flags,
+ TRUE);
+ nautilus_file_list_free (file_list);
}
static gboolean
button_event_modifies_selection (GdkEventButton *event)
{
- return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
+ return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
}
static int
get_click_policy (void)
{
- return g_settings_get_enum (nautilus_preferences,
- NAUTILUS_PREFERENCES_CLICK_POLICY);
+ return g_settings_get_enum (nautilus_preferences,
+ NAUTILUS_PREFERENCES_CLICK_POLICY);
}
static void
nautilus_list_view_did_not_drag (NautilusListView *view,
- GdkEventButton *event)
-{
- GtkTreeView *tree_view;
- GtkTreeSelection *selection;
- GtkTreePath *path;
-
- tree_view = view->details->tree_view;
- selection = gtk_tree_view_get_selection (tree_view);
-
- if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
- &path, NULL, NULL, NULL)) {
- if ((event->button == 1 || event->button == 2)
- && ((event->state & GDK_CONTROL_MASK) != 0 ||
- (event->state & GDK_SHIFT_MASK) == 0)
- && view->details->row_selected_on_button_down) {
- if (!button_event_modifies_selection (event)) {
- gtk_tree_selection_unselect_all (selection);
- gtk_tree_selection_select_path (selection, path);
- } else {
- gtk_tree_selection_unselect_path (selection, path);
- }
- }
-
- if ((get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
- && !button_event_modifies_selection(event)) {
- if (event->button == 1) {
- activate_selected_items (view);
- } else if (event->button == 2) {
- activate_selected_items_alternate (view, NULL, TRUE);
- }
- }
- gtk_tree_path_free (path);
- }
-
+ GdkEventButton *event)
+{
+ GtkTreeView *tree_view;
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+
+ tree_view = view->details->tree_view;
+ selection = gtk_tree_view_get_selection (tree_view);
+
+ if (gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
+ &path, NULL, NULL, NULL))
+ {
+ if ((event->button == 1 || event->button == 2)
+ && ((event->state & GDK_CONTROL_MASK) != 0 ||
+ (event->state & GDK_SHIFT_MASK) == 0)
+ && view->details->row_selected_on_button_down)
+ {
+ if (!button_event_modifies_selection (event))
+ {
+ gtk_tree_selection_unselect_all (selection);
+ gtk_tree_selection_select_path (selection, path);
+ }
+ else
+ {
+ gtk_tree_selection_unselect_path (selection, path);
+ }
+ }
+
+ if ((get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+ && !button_event_modifies_selection (event))
+ {
+ if (event->button == 1)
+ {
+ activate_selected_items (view);
+ }
+ else if (event->button == 2)
+ {
+ activate_selected_items_alternate (view, NULL, TRUE);
+ }
+ }
+ gtk_tree_path_free (path);
+ }
}
static gboolean
-motion_notify_callback (GtkWidget *widget,
- GdkEventMotion *event,
- gpointer callback_data)
-{
- NautilusListView *view;
- gboolean handled = FALSE;
-
- view = NAUTILUS_LIST_VIEW (callback_data);
-
- if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget))) {
- return FALSE;
- }
-
- if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
- GtkTreePath *old_hover_path;
-
- old_hover_path = view->details->hover_path;
- gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
- event->x, event->y,
- &view->details->hover_path,
- NULL, NULL, NULL);
-
- if ((old_hover_path != NULL) != (view->details->hover_path != NULL)) {
- if (view->details->hover_path != NULL) {
- gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
- } else {
- gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
- }
- }
+motion_notify_callback (GtkWidget *widget,
+ GdkEventMotion *event,
+ gpointer callback_data)
+{
+ NautilusListView *view;
+ gboolean handled = FALSE;
+
+ view = NAUTILUS_LIST_VIEW (callback_data);
+
+ if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget)))
+ {
+ return FALSE;
+ }
+
+ if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+ {
+ GtkTreePath *old_hover_path;
+
+ old_hover_path = view->details->hover_path;
+ gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
+ event->x, event->y,
+ &view->details->hover_path,
+ NULL, NULL, NULL);
+
+ if ((old_hover_path != NULL) != (view->details->hover_path != NULL))
+ {
+ if (view->details->hover_path != NULL)
+ {
+ gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
+ }
+ else
+ {
+ gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
+ }
+ }
- if (old_hover_path != NULL) {
- gtk_tree_path_free (old_hover_path);
- }
- }
+ if (old_hover_path != NULL)
+ {
+ gtk_tree_path_free (old_hover_path);
+ }
+ }
- nautilus_list_view_dnd_init (view);
- handled = nautilus_list_view_dnd_drag_begin (view, event);
+ nautilus_list_view_dnd_init (view);
+ handled = nautilus_list_view_dnd_drag_begin (view, event);
- return handled;
+ return handled;
}
static gboolean
-leave_notify_callback (GtkWidget *widget,
- GdkEventCrossing *event,
- gpointer callback_data)
+leave_notify_callback (GtkWidget *widget,
+ GdkEventCrossing *event,
+ gpointer callback_data)
{
- NautilusListView *view;
+ NautilusListView *view;
- view = NAUTILUS_LIST_VIEW (callback_data);
+ view = NAUTILUS_LIST_VIEW (callback_data);
- if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE &&
- view->details->hover_path != NULL) {
- gtk_tree_path_free (view->details->hover_path);
- view->details->hover_path = NULL;
- }
+ if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE &&
+ view->details->hover_path != NULL)
+ {
+ gtk_tree_path_free (view->details->hover_path);
+ view->details->hover_path = NULL;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
-enter_notify_callback (GtkWidget *widget,
- GdkEventCrossing *event,
- gpointer callback_data)
+enter_notify_callback (GtkWidget *widget,
+ GdkEventCrossing *event,
+ gpointer callback_data)
{
- NautilusListView *view;
+ NautilusListView *view;
- view = NAUTILUS_LIST_VIEW (callback_data);
+ view = NAUTILUS_LIST_VIEW (callback_data);
- if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
- if (view->details->hover_path != NULL) {
- gtk_tree_path_free (view->details->hover_path);
- }
+ if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+ {
+ if (view->details->hover_path != NULL)
+ {
+ gtk_tree_path_free (view->details->hover_path);
+ }
- gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
- event->x, event->y,
- &view->details->hover_path,
- NULL, NULL, NULL);
+ gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
+ event->x, event->y,
+ &view->details->hover_path,
+ NULL, NULL, NULL);
- if (view->details->hover_path != NULL) {
- gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
- }
- }
+ if (view->details->hover_path != NULL)
+ {
+ gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
+ }
+ }
- return FALSE;
+ return FALSE;
}
static void
-do_popup_menu (GtkWidget *widget, NautilusListView *view, GdkEventButton *event)
+do_popup_menu (GtkWidget *widget,
+ NautilusListView *view,
+ GdkEventButton *event)
{
- if (tree_view_has_selection (GTK_TREE_VIEW (widget))) {
- nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
- } else {
- nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
- }
+ if (tree_view_has_selection (GTK_TREE_VIEW (widget)))
+ {
+ nautilus_files_view_pop_up_selection_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ }
+ else
+ {
+ nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (view), event);
+ }
}
static void
-row_activated_callback (GtkTreeView *treeview, GtkTreePath *path,
- GtkTreeViewColumn *column, NautilusListView *view)
+row_activated_callback (GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ NautilusListView *view)
{
- activate_selected_items (view);
+ activate_selected_items (view);
}
static gboolean
-button_press_callback (GtkWidget *widget, GdkEventButton *event, gpointer callback_data)
-{
- NautilusListView *view;
- GtkTreeView *tree_view;
- GtkTreePath *path;
- GtkTreeSelection *selection;
- GtkWidgetClass *tree_view_class;
- gint64 current_time;
- static gint64 last_click_time = 0;
- static int click_count = 0;
- int double_click_time;
- gboolean call_parent, on_expander, show_expanders;
- gboolean is_simple_click, path_selected;
- NautilusFile *file;
-
- view = NAUTILUS_LIST_VIEW (callback_data);
- tree_view = GTK_TREE_VIEW (widget);
- tree_view_class = GTK_WIDGET_GET_CLASS (tree_view);
- selection = gtk_tree_view_get_selection (tree_view);
- view->details->last_event_button_x = event->x;
- view->details->last_event_button_y = event->y;
-
- /* Don't handle extra mouse buttons here */
- if (event->button > 5) {
- return FALSE;
- }
-
- if (event->window != gtk_tree_view_get_bin_window (tree_view)) {
- return FALSE;
- }
-
- nautilus_list_model_set_drag_view
- (NAUTILUS_LIST_MODEL (gtk_tree_view_get_model (tree_view)),
- tree_view,
- event->x, event->y);
-
- g_object_get (G_OBJECT (gtk_widget_get_settings (widget)),
- "gtk-double-click-time", &double_click_time,
- NULL);
-
- /* Determine click count */
- current_time = g_get_monotonic_time ();
- if (current_time - last_click_time < double_click_time * 1000) {
- click_count++;
- } else {
- click_count = 0;
- }
-
- /* Stash time for next compare */
- last_click_time = current_time;
-
- /* Ignore double click if we are in single click mode */
- if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE && click_count >= 2) {
- return TRUE;
- }
-
- view->details->ignore_button_release = FALSE;
- is_simple_click = ((event->button == 1 || event->button == 2) && (event->type == GDK_BUTTON_PRESS));
-
- /* No item at this position */
- if (!gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
- &path, NULL, NULL, NULL)) {
- if (is_simple_click) {
- g_clear_pointer (&view->details->double_click_path[1], gtk_tree_path_free);
- view->details->double_click_path[1] = view->details->double_click_path[0];
- view->details->double_click_path[0] = NULL;
- }
-
- /* Deselect if people click outside any row. It's OK to
- let default code run; it won't reselect anything. */
- gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (tree_view));
- tree_view_class->button_press_event (widget, event);
-
- if (event->button == 3) {
- do_popup_menu (widget, view, event);
- }
-
- return TRUE;
- }
-
- call_parent = TRUE;
- on_expander = FALSE;
- path_selected = gtk_tree_selection_path_is_selected (selection, path);
- show_expanders = g_settings_get_boolean (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
-
- if (show_expanders) {
- int expander_size, horizontal_separator;
- gtk_widget_style_get (widget,
- "expander-size", &expander_size,
- "horizontal-separator", &horizontal_separator,
- NULL);
- /* TODO we should not hardcode this extra padding. It is
- * EXPANDER_EXTRA_PADDING from GtkTreeView.
- */
- expander_size += 4;
- on_expander = (event->x <= horizontal_separator / 2 +
- gtk_tree_path_get_depth (path) * expander_size);
- }
-
- /* Keep track of path of last click so double clicks only happen
- * on the same item */
- if (is_simple_click) {
- g_clear_pointer (&view->details->double_click_path[1], gtk_tree_path_free);
- view->details->double_click_path[1] = view->details->double_click_path[0];
- view->details->double_click_path[0] = gtk_tree_path_copy (path);
- }
-
- if (event->type == GDK_2BUTTON_PRESS) {
- /* Double clicking does not trigger a D&D action. */
- view->details->drag_button = 0;
-
- /* NOTE: Activation can actually destroy the view if we're switching */
- if (!on_expander &&
- view->details->double_click_path[1] &&
- gtk_tree_path_compare (view->details->double_click_path[0], view->details->double_click_path[1]) == 0) {
- if ((event->button == 1) && button_event_modifies_selection (event)) {
- file = nautilus_list_model_file_for_path (view->details->model, path);
- if (file != NULL) {
- activate_selected_items_alternate (view, file, TRUE);
- nautilus_file_unref (file);
- }
- } else {
- if ((event->button == 1 || event->button == 3)) {
- activate_selected_items (view);
- } else if (event->button == 2) {
- activate_selected_items_alternate (view, NULL, TRUE);
- }
- }
- } else {
- tree_view_class->button_press_event (widget, event);
- }
- } else {
- /* We're going to filter out some situations where
- * we can't let the default code run because all
- * but one row would be would be deselected. We don't
- * want that; we want the right click menu or single
- * click to apply to everything that's currently selected.
- */
- if (event->button == 3 && path_selected) {
- call_parent = FALSE;
- }
-
- if ((event->button == 1 || event->button == 2) &&
- ((event->state & GDK_CONTROL_MASK) != 0 || (event->state & GDK_SHIFT_MASK) == 0)) {
- view->details->row_selected_on_button_down = path_selected;
-
- if (path_selected) {
- call_parent = on_expander;
- view->details->ignore_button_release = on_expander;
- } else if ((event->state & GDK_CONTROL_MASK) != 0) {
- GList *selected_rows, *l;
-
- call_parent = FALSE;
- if ((event->state & GDK_SHIFT_MASK) != 0) {
- GtkTreePath *cursor;
- gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
- if (cursor != NULL) {
- gtk_tree_selection_select_range (selection, cursor, path);
- } else {
- gtk_tree_selection_select_path (selection, path);
- }
- } else {
- gtk_tree_selection_select_path (selection, path);
- }
- selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
-
- /* This unselects everything */
- gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
-
- /* So select it again */
- for (l = selected_rows; l != NULL; l = l->next) {
- gtk_tree_selection_select_path (selection, l->data);
- }
- g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
- } else {
- view->details->ignore_button_release = on_expander;
- }
- }
-
- if (call_parent) {
- g_signal_handlers_block_by_func (tree_view, row_activated_callback, view);
- tree_view_class->button_press_event (widget, event);
- g_signal_handlers_unblock_by_func (tree_view, row_activated_callback, view);
- } else if (path_selected) {
- gtk_widget_grab_focus (widget);
- }
-
- if (is_simple_click && !on_expander) {
- view->details->drag_started = FALSE;
- view->details->drag_button = event->button;
- view->details->drag_x = event->x;
- view->details->drag_y = event->y;
- }
-
- if (event->button == 3) {
- do_popup_menu (widget, view, event);
- }
- }
-
- gtk_tree_path_free (path);
-
- /* We chained to the default handler in this method, so never
- * let the default handler run */
- return TRUE;
+button_press_callback (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer callback_data)
+{
+ NautilusListView *view;
+ GtkTreeView *tree_view;
+ GtkTreePath *path;
+ GtkTreeSelection *selection;
+ GtkWidgetClass *tree_view_class;
+ gint64 current_time;
+ static gint64 last_click_time = 0;
+ static int click_count = 0;
+ int double_click_time;
+ gboolean call_parent, on_expander, show_expanders;
+ gboolean is_simple_click, path_selected;
+ NautilusFile *file;
+
+ view = NAUTILUS_LIST_VIEW (callback_data);
+ tree_view = GTK_TREE_VIEW (widget);
+ tree_view_class = GTK_WIDGET_GET_CLASS (tree_view);
+ selection = gtk_tree_view_get_selection (tree_view);
+ view->details->last_event_button_x = event->x;
+ view->details->last_event_button_y = event->y;
+
+ /* Don't handle extra mouse buttons here */
+ if (event->button > 5)
+ {
+ return FALSE;
+ }
+
+ if (event->window != gtk_tree_view_get_bin_window (tree_view))
+ {
+ return FALSE;
+ }
+
+ nautilus_list_model_set_drag_view
+ (NAUTILUS_LIST_MODEL (gtk_tree_view_get_model (tree_view)),
+ tree_view,
+ event->x, event->y);
+
+ g_object_get (G_OBJECT (gtk_widget_get_settings (widget)),
+ "gtk-double-click-time", &double_click_time,
+ NULL);
+
+ /* Determine click count */
+ current_time = g_get_monotonic_time ();
+ if (current_time - last_click_time < double_click_time * 1000)
+ {
+ click_count++;
+ }
+ else
+ {
+ click_count = 0;
+ }
+
+ /* Stash time for next compare */
+ last_click_time = current_time;
+
+ /* Ignore double click if we are in single click mode */
+ if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE && click_count >= 2)
+ {
+ return TRUE;
+ }
+
+ view->details->ignore_button_release = FALSE;
+ is_simple_click = ((event->button == 1 || event->button == 2) && (event->type == GDK_BUTTON_PRESS));
+
+ /* No item at this position */
+ if (!gtk_tree_view_get_path_at_pos (tree_view, event->x, event->y,
+ &path, NULL, NULL, NULL))
+ {
+ if (is_simple_click)
+ {
+ g_clear_pointer (&view->details->double_click_path[1], gtk_tree_path_free);
+ view->details->double_click_path[1] = view->details->double_click_path[0];
+ view->details->double_click_path[0] = NULL;
+ }
+
+ /* Deselect if people click outside any row. It's OK to
+ * let default code run; it won't reselect anything. */
+ gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (tree_view));
+ tree_view_class->button_press_event (widget, event);
+
+ if (event->button == 3)
+ {
+ do_popup_menu (widget, view, event);
+ }
+
+ return TRUE;
+ }
+
+ call_parent = TRUE;
+ on_expander = FALSE;
+ path_selected = gtk_tree_selection_path_is_selected (selection, path);
+ show_expanders = g_settings_get_boolean (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
+
+ if (show_expanders)
+ {
+ int expander_size, horizontal_separator;
+ gtk_widget_style_get (widget,
+ "expander-size", &expander_size,
+ "horizontal-separator", &horizontal_separator,
+ NULL);
+ /* TODO we should not hardcode this extra padding. It is
+ * EXPANDER_EXTRA_PADDING from GtkTreeView.
+ */
+ expander_size += 4;
+ on_expander = (event->x <= horizontal_separator / 2 +
+ gtk_tree_path_get_depth (path) * expander_size);
+ }
+
+ /* Keep track of path of last click so double clicks only happen
+ * on the same item */
+ if (is_simple_click)
+ {
+ g_clear_pointer (&view->details->double_click_path[1], gtk_tree_path_free);
+ view->details->double_click_path[1] = view->details->double_click_path[0];
+ view->details->double_click_path[0] = gtk_tree_path_copy (path);
+ }
+
+ if (event->type == GDK_2BUTTON_PRESS)
+ {
+ /* Double clicking does not trigger a D&D action. */
+ view->details->drag_button = 0;
+
+ /* NOTE: Activation can actually destroy the view if we're switching */
+ if (!on_expander &&
+ view->details->double_click_path[1] &&
+ gtk_tree_path_compare (view->details->double_click_path[0], view->details->double_click_path[1]) == 0)
+ {
+ if ((event->button == 1) && button_event_modifies_selection (event))
+ {
+ file = nautilus_list_model_file_for_path (view->details->model, path);
+ if (file != NULL)
+ {
+ activate_selected_items_alternate (view, file, TRUE);
+ nautilus_file_unref (file);
+ }
+ }
+ else
+ {
+ if ((event->button == 1 || event->button == 3))
+ {
+ activate_selected_items (view);
+ }
+ else if (event->button == 2)
+ {
+ activate_selected_items_alternate (view, NULL, TRUE);
+ }
+ }
+ }
+ else
+ {
+ tree_view_class->button_press_event (widget, event);
+ }
+ }
+ else
+ {
+ /* We're going to filter out some situations where
+ * we can't let the default code run because all
+ * but one row would be would be deselected. We don't
+ * want that; we want the right click menu or single
+ * click to apply to everything that's currently selected.
+ */
+ if (event->button == 3 && path_selected)
+ {
+ call_parent = FALSE;
+ }
+
+ if ((event->button == 1 || event->button == 2) &&
+ ((event->state & GDK_CONTROL_MASK) != 0 || (event->state & GDK_SHIFT_MASK) == 0))
+ {
+ view->details->row_selected_on_button_down = path_selected;
+
+ if (path_selected)
+ {
+ call_parent = on_expander;
+ view->details->ignore_button_release = on_expander;
+ }
+ else if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ GList *selected_rows, *l;
+
+ call_parent = FALSE;
+ if ((event->state & GDK_SHIFT_MASK) != 0)
+ {
+ GtkTreePath *cursor;
+ gtk_tree_view_get_cursor (tree_view, &cursor, NULL);
+ if (cursor != NULL)
+ {
+ gtk_tree_selection_select_range (selection, cursor, path);
+ }
+ else
+ {
+ gtk_tree_selection_select_path (selection, path);
+ }
+ }
+ else
+ {
+ gtk_tree_selection_select_path (selection, path);
+ }
+ selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
+
+ /* This unselects everything */
+ gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
+
+ /* So select it again */
+ for (l = selected_rows; l != NULL; l = l->next)
+ {
+ gtk_tree_selection_select_path (selection, l->data);
+ }
+ g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
+ }
+ else
+ {
+ view->details->ignore_button_release = on_expander;
+ }
+ }
+
+ if (call_parent)
+ {
+ g_signal_handlers_block_by_func (tree_view, row_activated_callback, view);
+ tree_view_class->button_press_event (widget, event);
+ g_signal_handlers_unblock_by_func (tree_view, row_activated_callback, view);
+ }
+ else if (path_selected)
+ {
+ gtk_widget_grab_focus (widget);
+ }
+
+ if (is_simple_click && !on_expander)
+ {
+ view->details->drag_started = FALSE;
+ view->details->drag_button = event->button;
+ view->details->drag_x = event->x;
+ view->details->drag_y = event->y;
+ }
+
+ if (event->button == 3)
+ {
+ do_popup_menu (widget, view, event);
+ }
+ }
+
+ gtk_tree_path_free (path);
+
+ /* We chained to the default handler in this method, so never
+ * let the default handler run */
+ return TRUE;
}
static gboolean
-button_release_callback (GtkWidget *widget,
- GdkEventButton *event,
- gpointer callback_data)
+button_release_callback (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer callback_data)
{
- NautilusListView *view;
-
- view = NAUTILUS_LIST_VIEW (callback_data);
+ NautilusListView *view;
- if (event->button == view->details->drag_button) {
- view->details->drag_button = 0;
- if (!view->details->drag_started &&
- !view->details->ignore_button_release) {
- nautilus_list_view_did_not_drag (view, event);
- }
- }
- return FALSE;
+ view = NAUTILUS_LIST_VIEW (callback_data);
+
+ if (event->button == view->details->drag_button)
+ {
+ view->details->drag_button = 0;
+ if (!view->details->drag_started &&
+ !view->details->ignore_button_release)
+ {
+ nautilus_list_view_did_not_drag (view, event);
+ }
+ }
+ return FALSE;
}
static gboolean
-popup_menu_callback (GtkWidget *widget, gpointer callback_data)
+popup_menu_callback (GtkWidget *widget,
+ gpointer callback_data)
{
- NautilusListView *view;
+ NautilusListView *view;
- view = NAUTILUS_LIST_VIEW (callback_data);
+ view = NAUTILUS_LIST_VIEW (callback_data);
- do_popup_menu (widget, view, NULL);
+ do_popup_menu (widget, view, NULL);
- return TRUE;
+ return TRUE;
}
static void
-subdirectory_done_loading_callback (NautilusDirectory *directory, NautilusListView *view)
+subdirectory_done_loading_callback (NautilusDirectory *directory,
+ NautilusListView *view)
{
- nautilus_list_model_subdirectory_done_loading (view->details->model, directory);
+ nautilus_list_model_subdirectory_done_loading (view->details->model, directory);
}
static void
row_expanded_callback (GtkTreeView *treeview,
- GtkTreeIter *iter,
- GtkTreePath *path,
- gpointer callback_data)
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer callback_data)
{
- NautilusListView *view;
- NautilusDirectory *directory;
- char *uri;
+ NautilusListView *view;
+ NautilusDirectory *directory;
+ char *uri;
- view = NAUTILUS_LIST_VIEW (callback_data);
+ view = NAUTILUS_LIST_VIEW (callback_data);
- if (!nautilus_list_model_load_subdirectory (view->details->model, path, &directory)) {
- return;
- }
+ if (!nautilus_list_model_load_subdirectory (view->details->model, path, &directory))
+ {
+ return;
+ }
- uri = nautilus_directory_get_uri (directory);
- DEBUG ("Row expaded callback for uri %s", uri);
- g_free (uri);
+ uri = nautilus_directory_get_uri (directory);
+ DEBUG ("Row expaded callback for uri %s", uri);
+ g_free (uri);
- nautilus_files_view_add_subdirectory (NAUTILUS_FILES_VIEW (view), directory);
+ nautilus_files_view_add_subdirectory (NAUTILUS_FILES_VIEW (view), directory);
- if (nautilus_directory_are_all_files_seen (directory)) {
- nautilus_list_model_subdirectory_done_loading (view->details->model,
- directory);
- } else {
- g_signal_connect_object (directory, "done-loading",
- G_CALLBACK (subdirectory_done_loading_callback),
- view, 0);
- }
+ if (nautilus_directory_are_all_files_seen (directory))
+ {
+ nautilus_list_model_subdirectory_done_loading (view->details->model,
+ directory);
+ }
+ else
+ {
+ g_signal_connect_object (directory, "done-loading",
+ G_CALLBACK (subdirectory_done_loading_callback),
+ view, 0);
+ }
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
}
-typedef struct {
- NautilusFile *file;
- NautilusDirectory *directory;
- NautilusListView *view;
+typedef struct
+{
+ NautilusFile *file;
+ NautilusDirectory *directory;
+ NautilusListView *view;
} UnloadDelayData;
static void
unload_delay_data_free (UnloadDelayData *unload_data)
{
- if (unload_data->view != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (unload_data->view),
- (gpointer *) &unload_data->view);
- }
+ if (unload_data->view != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (unload_data->view),
+ (gpointer *) &unload_data->view);
+ }
- nautilus_directory_unref (unload_data->directory);
- nautilus_file_unref (unload_data->file);
+ nautilus_directory_unref (unload_data->directory);
+ nautilus_file_unref (unload_data->file);
- g_slice_free (UnloadDelayData, unload_data);
+ g_slice_free (UnloadDelayData, unload_data);
}
static UnloadDelayData *
-unload_delay_data_new (NautilusFile *file,
- NautilusDirectory *parent_directory,
- NautilusListView *view)
+unload_delay_data_new (NautilusFile *file,
+ NautilusDirectory *parent_directory,
+ NautilusListView *view)
{
- UnloadDelayData *unload_data;
+ UnloadDelayData *unload_data;
- unload_data = g_slice_new0 (UnloadDelayData);
- unload_data->view = view;
- unload_data->file = nautilus_file_ref (file);
- unload_data->directory = nautilus_directory_ref (parent_directory);
+ unload_data = g_slice_new0 (UnloadDelayData);
+ unload_data->view = view;
+ unload_data->file = nautilus_file_ref (file);
+ unload_data->directory = nautilus_directory_ref (parent_directory);
- g_object_add_weak_pointer (G_OBJECT (unload_data->view),
- (gpointer *) &unload_data->view);
+ g_object_add_weak_pointer (G_OBJECT (unload_data->view),
+ (gpointer *) &unload_data->view);
- return unload_data;
+ return unload_data;
}
static gboolean
unload_file_timeout (gpointer data)
{
- UnloadDelayData *unload_data = data;
- GtkTreeIter iter;
- NautilusListModel *model;
- GtkTreePath *path;
-
- if (unload_data->view == NULL) {
- goto out;
- }
-
- model = unload_data->view->details->model;
- if (nautilus_list_model_get_tree_iter_from_file (model,
- unload_data->file,
- unload_data->directory,
- &iter)) {
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
- if (!gtk_tree_view_row_expanded (unload_data->view->details->tree_view,
- path)) {
- nautilus_list_model_unload_subdirectory (model, &iter);
- }
- gtk_tree_path_free (path);
- }
+ UnloadDelayData *unload_data = data;
+ GtkTreeIter iter;
+ NautilusListModel *model;
+ GtkTreePath *path;
+
+ if (unload_data->view == NULL)
+ {
+ goto out;
+ }
+
+ model = unload_data->view->details->model;
+ if (nautilus_list_model_get_tree_iter_from_file (model,
+ unload_data->file,
+ unload_data->directory,
+ &iter))
+ {
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &iter);
+ if (!gtk_tree_view_row_expanded (unload_data->view->details->tree_view,
+ path))
+ {
+ nautilus_list_model_unload_subdirectory (model, &iter);
+ }
+ gtk_tree_path_free (path);
+ }
- out:
- unload_delay_data_free (unload_data);
- return FALSE;
+out:
+ unload_delay_data_free (unload_data);
+ return FALSE;
}
static void
row_collapsed_callback (GtkTreeView *treeview,
- GtkTreeIter *iter,
- GtkTreePath *path,
- gpointer callback_data)
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gpointer callback_data)
{
- NautilusListView *view;
- NautilusFile *file;
- NautilusDirectory *directory;
- GtkTreeIter parent;
- UnloadDelayData *unload_data;
- GtkTreeModel *model;
- char *uri;
+ NautilusListView *view;
+ NautilusFile *file;
+ NautilusDirectory *directory;
+ GtkTreeIter parent;
+ UnloadDelayData *unload_data;
+ GtkTreeModel *model;
+ char *uri;
- view = NAUTILUS_LIST_VIEW (callback_data);
- model = GTK_TREE_MODEL (view->details->model);
+ view = NAUTILUS_LIST_VIEW (callback_data);
+ model = GTK_TREE_MODEL (view->details->model);
- gtk_tree_model_get (model, iter,
- NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
- -1);
+ gtk_tree_model_get (model, iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
- uri = nautilus_file_get_uri (file);
- DEBUG ("Row collapsed callback for uri %s", uri);
- g_free (uri);
+ uri = nautilus_file_get_uri (file);
+ DEBUG ("Row collapsed callback for uri %s", uri);
+ g_free (uri);
- directory = NULL;
- if (gtk_tree_model_iter_parent (model, &parent, iter)) {
- gtk_tree_model_get (model, &parent,
- NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN, &directory,
- -1);
- }
+ directory = NULL;
+ if (gtk_tree_model_iter_parent (model, &parent, iter))
+ {
+ gtk_tree_model_get (model, &parent,
+ NAUTILUS_LIST_MODEL_SUBDIRECTORY_COLUMN, &directory,
+ -1);
+ }
- unload_data = unload_delay_data_new (file, directory, view);
- g_timeout_add_seconds (COLLAPSE_TO_UNLOAD_DELAY,
- unload_file_timeout,
- unload_data);
+ unload_data = unload_delay_data_new (file, directory, view);
+ g_timeout_add_seconds (COLLAPSE_TO_UNLOAD_DELAY,
+ unload_file_timeout,
+ unload_data);
- nautilus_file_unref (file);
- nautilus_directory_unref (directory);
+ nautilus_file_unref (file);
+ nautilus_directory_unref (directory);
}
static void
subdirectory_unloaded_callback (NautilusListModel *model,
- NautilusDirectory *directory,
- gpointer callback_data)
+ NautilusDirectory *directory,
+ gpointer callback_data)
{
- NautilusListView *view;
-
- g_return_if_fail (NAUTILUS_IS_LIST_MODEL (model));
- g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+ NautilusListView *view;
- view = NAUTILUS_LIST_VIEW(callback_data);
-
- g_signal_handlers_disconnect_by_func (directory,
- G_CALLBACK (subdirectory_done_loading_callback),
- view);
- nautilus_files_view_remove_subdirectory (NAUTILUS_FILES_VIEW (view), directory);
+ g_return_if_fail (NAUTILUS_IS_LIST_MODEL (model));
+ g_return_if_fail (NAUTILUS_IS_DIRECTORY (directory));
+
+ view = NAUTILUS_LIST_VIEW (callback_data);
+
+ g_signal_handlers_disconnect_by_func (directory,
+ G_CALLBACK (subdirectory_done_loading_callback),
+ view);
+ nautilus_files_view_remove_subdirectory (NAUTILUS_FILES_VIEW (view), directory);
}
static gboolean
-key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer callback_data)
-{
- NautilusFilesView *view;
- GdkEventButton button_event = { 0 };
- gboolean handled;
- GtkTreeView *tree_view;
- GtkTreePath *path;
-
- tree_view = GTK_TREE_VIEW (widget);
-
- view = NAUTILUS_FILES_VIEW (callback_data);
- handled = FALSE;
-
- NAUTILUS_LIST_VIEW (view)->details->last_event_button_x = -1;
- NAUTILUS_LIST_VIEW (view)->details->last_event_button_y = -1;
-
- switch (event->keyval) {
- case GDK_KEY_F10:
- if (event->state & GDK_CONTROL_MASK) {
- nautilus_files_view_pop_up_background_context_menu (view, &button_event);
- handled = TRUE;
- }
- break;
- case GDK_KEY_Right:
- gtk_tree_view_get_cursor (tree_view, &path, NULL);
- if (path) {
- gtk_tree_view_expand_row (tree_view, path, FALSE);
- gtk_tree_path_free (path);
- }
- handled = TRUE;
- break;
- case GDK_KEY_Left:
- gtk_tree_view_get_cursor (tree_view, &path, NULL);
- if (path) {
- if (!gtk_tree_view_collapse_row (tree_view, path)) {
- /* if the row is already collapsed or doesn't have any children,
- * jump to the parent row instead.
- */
- if ((gtk_tree_path_get_depth (path) > 1) && gtk_tree_path_up (path)) {
- gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
- }
- }
-
- gtk_tree_path_free (path);
- }
- handled = TRUE;
- break;
- case GDK_KEY_space:
- if (event->state & GDK_CONTROL_MASK) {
- handled = FALSE;
- break;
- }
- if (!gtk_widget_has_focus (GTK_WIDGET (NAUTILUS_LIST_VIEW (view)->details->tree_view))) {
- handled = FALSE;
- break;
- }
- if ((event->state & GDK_SHIFT_MASK) != 0) {
- activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
- } else {
- preview_selected_items (NAUTILUS_LIST_VIEW (view));
- }
- handled = TRUE;
- break;
- case GDK_KEY_Return:
- case GDK_KEY_KP_Enter:
- if ((event->state & GDK_SHIFT_MASK) != 0) {
- activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
- } else {
- activate_selected_items (NAUTILUS_LIST_VIEW (view));
- }
- handled = TRUE;
- break;
- case GDK_KEY_v:
- /* Eat Control + v to not enable type ahead */
- if ((event->state & GDK_CONTROL_MASK) != 0) {
- handled = TRUE;
- }
- break;
-
- default:
- handled = FALSE;
- }
-
- return handled;
+key_press_callback (GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer callback_data)
+{
+ NautilusFilesView *view;
+ GdkEventButton button_event = { 0 };
+ gboolean handled;
+ GtkTreeView *tree_view;
+ GtkTreePath *path;
+
+ tree_view = GTK_TREE_VIEW (widget);
+
+ view = NAUTILUS_FILES_VIEW (callback_data);
+ handled = FALSE;
+
+ NAUTILUS_LIST_VIEW (view)->details->last_event_button_x = -1;
+ NAUTILUS_LIST_VIEW (view)->details->last_event_button_y = -1;
+
+ switch (event->keyval)
+ {
+ case GDK_KEY_F10:
+ {
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ nautilus_files_view_pop_up_background_context_menu (view, &button_event);
+ handled = TRUE;
+ }
+ }
+ break;
+
+ case GDK_KEY_Right:
+ {
+ gtk_tree_view_get_cursor (tree_view, &path, NULL);
+ if (path)
+ {
+ gtk_tree_view_expand_row (tree_view, path, FALSE);
+ gtk_tree_path_free (path);
+ }
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_Left:
+ {
+ gtk_tree_view_get_cursor (tree_view, &path, NULL);
+ if (path)
+ {
+ if (!gtk_tree_view_collapse_row (tree_view, path))
+ {
+ /* if the row is already collapsed or doesn't have any children,
+ * jump to the parent row instead.
+ */
+ if ((gtk_tree_path_get_depth (path) > 1) && gtk_tree_path_up (path))
+ {
+ gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
+ }
+ }
+
+ gtk_tree_path_free (path);
+ }
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_space:
+ {
+ if (event->state & GDK_CONTROL_MASK)
+ {
+ handled = FALSE;
+ break;
+ }
+ if (!gtk_widget_has_focus (GTK_WIDGET (NAUTILUS_LIST_VIEW (view)->details->tree_view)))
+ {
+ handled = FALSE;
+ break;
+ }
+ if ((event->state & GDK_SHIFT_MASK) != 0)
+ {
+ activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
+ }
+ else
+ {
+ preview_selected_items (NAUTILUS_LIST_VIEW (view));
+ }
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ {
+ if ((event->state & GDK_SHIFT_MASK) != 0)
+ {
+ activate_selected_items_alternate (NAUTILUS_LIST_VIEW (view), NULL, TRUE);
+ }
+ else
+ {
+ activate_selected_items (NAUTILUS_LIST_VIEW (view));
+ }
+ handled = TRUE;
+ }
+ break;
+
+ case GDK_KEY_v:
+ {
+ /* Eat Control + v to not enable type ahead */
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ handled = TRUE;
+ }
+ }
+ break;
+
+ default:
+ handled = FALSE;
+ }
+
+ return handled;
}
static gboolean
test_expand_row_callback (GtkTreeView *tree_view,
- GtkTreeIter *iter,
- GtkTreePath *path,
- gboolean user_data)
+ GtkTreeIter *iter,
+ GtkTreePath *path,
+ gboolean user_data)
{
- return !g_settings_get_boolean (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
+ return !g_settings_get_boolean (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
}
static void
nautilus_list_view_reveal_selection (NautilusFilesView *view)
{
- GList *selection;
+ GList *selection;
- g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
+
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+
+ /* Make sure at least one of the selected items is scrolled into view */
+ if (selection != NULL)
+ {
+ NautilusListView *list_view;
+ NautilusFile *file;
+ GtkTreeIter iter;
+ GtkTreePath *path;
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ list_view = NAUTILUS_LIST_VIEW (view);
+ file = selection->data;
+ if (nautilus_list_model_get_first_iter_for_file (list_view->details->model, file, &iter))
+ {
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_view->details->model), &iter);
- /* Make sure at least one of the selected items is scrolled into view */
- if (selection != NULL) {
- NautilusListView *list_view;
- NautilusFile *file;
- GtkTreeIter iter;
- GtkTreePath *path;
-
- list_view = NAUTILUS_LIST_VIEW (view);
- file = selection->data;
- if (nautilus_list_model_get_first_iter_for_file (list_view->details->model, file, &iter)) {
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (list_view->details->model), &iter);
+ gtk_tree_view_scroll_to_cell (list_view->details->tree_view, path, NULL, FALSE, 0.0, 0.0);
- gtk_tree_view_scroll_to_cell (list_view->details->tree_view, path, NULL, FALSE, 0.0, 0.0);
-
- gtk_tree_path_free (path);
- }
- }
+ gtk_tree_path_free (path);
+ }
+ }
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static gboolean
sort_criterion_changes_due_to_user (GtkTreeView *tree_view)
{
- GList *columns, *p;
- GtkTreeViewColumn *column;
- GSignalInvocationHint *ihint;
- gboolean ret;
-
- ret = FALSE;
-
- columns = gtk_tree_view_get_columns (tree_view);
- for (p = columns; p != NULL; p = p->next) {
- column = p->data;
- ihint = g_signal_get_invocation_hint (column);
- if (ihint != NULL) {
- ret = TRUE;
- break;
- }
- }
- g_list_free (columns);
+ GList *columns, *p;
+ GtkTreeViewColumn *column;
+ GSignalInvocationHint *ihint;
+ gboolean ret;
+
+ ret = FALSE;
+
+ columns = gtk_tree_view_get_columns (tree_view);
+ for (p = columns; p != NULL; p = p->next)
+ {
+ column = p->data;
+ ihint = g_signal_get_invocation_hint (column);
+ if (ihint != NULL)
+ {
+ ret = TRUE;
+ break;
+ }
+ }
+ g_list_free (columns);
- return ret;
+ return ret;
}
static void
-sort_column_changed_callback (GtkTreeSortable *sortable,
- NautilusListView *view)
+sort_column_changed_callback (GtkTreeSortable *sortable,
+ NautilusListView *view)
{
- NautilusFile *file;
- gint sort_column_id, default_sort_column_id;
- GtkSortType reversed;
- GQuark sort_attr, default_sort_attr;
- char *reversed_attr, *default_reversed_attr;
- gboolean default_sort_reversed;
+ NautilusFile *file;
+ gint sort_column_id, default_sort_column_id;
+ GtkSortType reversed;
+ GQuark sort_attr, default_sort_attr;
+ char *reversed_attr, *default_reversed_attr;
+ gboolean default_sort_reversed;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
- gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &reversed);
- sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, sort_column_id);
+ gtk_tree_sortable_get_sort_column_id (sortable, &sort_column_id, &reversed);
+ sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, sort_column_id);
- default_sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (view->details->model,
- g_quark_from_string (get_default_sort_order (file, &default_sort_reversed)));
- default_sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, default_sort_column_id);
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
- g_quark_to_string (default_sort_attr), g_quark_to_string (sort_attr));
+ default_sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (view->details->model,
+ g_quark_from_string (get_default_sort_order (file, &default_sort_reversed)));
+ default_sort_attr = nautilus_list_model_get_attribute_from_sort_column_id (view->details->model, default_sort_column_id);
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
+ g_quark_to_string (default_sort_attr), g_quark_to_string (sort_attr));
- default_reversed_attr = (default_sort_reversed ? "true" : "false");
+ default_reversed_attr = (default_sort_reversed ? "true" : "false");
- if (view->details->last_sort_attr != sort_attr &&
- sort_criterion_changes_due_to_user (view->details->tree_view)) {
- /* at this point, the sort order is always GTK_SORT_ASCENDING, if the sort column ID
- * switched. Invert the sort order, if it's the default criterion with a reversed preference,
- * or if it makes sense for the attribute (i.e. date). */
- if (sort_attr == default_sort_attr) {
- /* use value from preferences */
- reversed = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
- } else {
- reversed = nautilus_file_is_date_sort_attribute_q (sort_attr);
- }
+ if (view->details->last_sort_attr != sort_attr &&
+ sort_criterion_changes_due_to_user (view->details->tree_view))
+ {
+ /* at this point, the sort order is always GTK_SORT_ASCENDING, if the sort column ID
+ * switched. Invert the sort order, if it's the default criterion with a reversed preference,
+ * or if it makes sense for the attribute (i.e. date). */
+ if (sort_attr == default_sort_attr)
+ {
+ /* use value from preferences */
+ reversed = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER);
+ }
+ else
+ {
+ reversed = nautilus_file_is_date_sort_attribute_q (sort_attr);
+ }
- if (reversed) {
- g_signal_handlers_block_by_func (sortable, sort_column_changed_callback, view);
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (view->details->model),
- sort_column_id,
- GTK_SORT_DESCENDING);
- g_signal_handlers_unblock_by_func (sortable, sort_column_changed_callback, view);
- }
- }
+ if (reversed)
+ {
+ g_signal_handlers_block_by_func (sortable, sort_column_changed_callback, view);
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (view->details->model),
+ sort_column_id,
+ GTK_SORT_DESCENDING);
+ g_signal_handlers_unblock_by_func (sortable, sort_column_changed_callback, view);
+ }
+ }
- reversed_attr = (reversed ? "true" : "false");
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
- default_reversed_attr, reversed_attr);
+ reversed_attr = (reversed ? "true" : "false");
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
+ default_reversed_attr, reversed_attr);
- /* Make sure selected item(s) is visible after sort */
- nautilus_list_view_reveal_selection (NAUTILUS_FILES_VIEW (view));
+ /* Make sure selected item(s) is visible after sort */
+ nautilus_list_view_reveal_selection (NAUTILUS_FILES_VIEW (view));
- view->details->last_sort_attr = sort_attr;
+ view->details->last_sort_attr = sort_attr;
}
static char *
get_root_uri_callback (NautilusTreeViewDragDest *dest,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusListView *view;
-
- view = NAUTILUS_LIST_VIEW (user_data);
+ NautilusListView *view;
+
+ view = NAUTILUS_LIST_VIEW (user_data);
- return nautilus_files_view_get_uri (NAUTILUS_FILES_VIEW (view));
+ return nautilus_files_view_get_uri (NAUTILUS_FILES_VIEW (view));
}
static NautilusFile *
get_file_for_path_callback (NautilusTreeViewDragDest *dest,
- GtkTreePath *path,
- gpointer user_data)
+ GtkTreePath *path,
+ gpointer user_data)
{
- NautilusListView *view;
-
- view = NAUTILUS_LIST_VIEW (user_data);
+ NautilusListView *view;
- return nautilus_list_model_file_for_path (view->details->model, path);
+ view = NAUTILUS_LIST_VIEW (user_data);
+
+ return nautilus_list_model_file_for_path (view->details->model, path);
}
/* Handles an URL received from Mozilla */
static void
-list_view_handle_netscape_url (NautilusTreeViewDragDest *dest, const char *encoded_url,
- const char *target_uri, GdkDragAction action, int x, int y, NautilusListView *view)
+list_view_handle_netscape_url (NautilusTreeViewDragDest *dest,
+ const char *encoded_url,
+ const char *target_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusListView *view)
{
- nautilus_files_view_handle_netscape_url_drop (NAUTILUS_FILES_VIEW (view),
- encoded_url, target_uri, action, x, y);
+ nautilus_files_view_handle_netscape_url_drop (NAUTILUS_FILES_VIEW (view),
+ encoded_url, target_uri, action, x, y);
}
static void
-list_view_handle_uri_list (NautilusTreeViewDragDest *dest, const char *item_uris,
- const char *target_uri,
- GdkDragAction action, int x, int y, NautilusListView *view)
+list_view_handle_uri_list (NautilusTreeViewDragDest *dest,
+ const char *item_uris,
+ const char *target_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusListView *view)
{
- nautilus_files_view_handle_uri_list_drop (NAUTILUS_FILES_VIEW (view),
- item_uris, target_uri, action, x, y);
+ nautilus_files_view_handle_uri_list_drop (NAUTILUS_FILES_VIEW (view),
+ item_uris, target_uri, action, x, y);
}
static void
-list_view_handle_text (NautilusTreeViewDragDest *dest, const char *text,
- const char *target_uri,
- GdkDragAction action, int x, int y, NautilusListView *view)
+list_view_handle_text (NautilusTreeViewDragDest *dest,
+ const char *text,
+ const char *target_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusListView *view)
{
- nautilus_files_view_handle_text_drop (NAUTILUS_FILES_VIEW (view),
- text, target_uri, action, x, y);
+ nautilus_files_view_handle_text_drop (NAUTILUS_FILES_VIEW (view),
+ text, target_uri, action, x, y);
}
static void
-list_view_handle_raw (NautilusTreeViewDragDest *dest, const char *raw_data,
- int length, const char *target_uri, const char *direct_save_uri,
- GdkDragAction action, int x, int y, NautilusListView *view)
+list_view_handle_raw (NautilusTreeViewDragDest *dest,
+ const char *raw_data,
+ int length,
+ const char *target_uri,
+ const char *direct_save_uri,
+ GdkDragAction action,
+ int x,
+ int y,
+ NautilusListView *view)
{
- nautilus_files_view_handle_raw_drop (NAUTILUS_FILES_VIEW (view),
- raw_data, length, target_uri, direct_save_uri,
- action, x, y);
+ nautilus_files_view_handle_raw_drop (NAUTILUS_FILES_VIEW (view),
+ raw_data, length, target_uri, direct_save_uri,
+ action, x, y);
}
static void
list_view_handle_hover (NautilusTreeViewDragDest *dest,
- const char *target_uri,
- NautilusListView *view)
+ const char *target_uri,
+ NautilusListView *view)
{
- nautilus_files_view_handle_hover (NAUTILUS_FILES_VIEW (view), target_uri);
+ nautilus_files_view_handle_hover (NAUTILUS_FILES_VIEW (view), target_uri);
}
static void
move_copy_items_callback (NautilusTreeViewDragDest *dest,
- const GList *item_uris,
- const char *target_uri,
- guint action,
- int x,
- int y,
- gpointer user_data)
-
+ const GList *item_uris,
+ const char *target_uri,
+ guint action,
+ int x,
+ int y,
+ gpointer user_data)
{
- NautilusFilesView *view = user_data;
+ NautilusFilesView *view = user_data;
- nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
- item_uris,
- nautilus_files_view_get_copied_files_atom (view));
- nautilus_files_view_move_copy_items (view,
- item_uris,
- NULL,
- target_uri,
- action,
- x, y);
+ nautilus_clipboard_clear_if_colliding_uris (GTK_WIDGET (view),
+ item_uris,
+ nautilus_files_view_get_copied_files_atom (view));
+ nautilus_files_view_move_copy_items (view,
+ item_uris,
+ NULL,
+ target_uri,
+ action,
+ x, y);
}
static void
column_header_menu_toggled (GtkCheckMenuItem *menu_item,
NautilusListView *list_view)
{
- NautilusFile *file;
- char **visible_columns;
- char **column_order;
- const char *column;
- GList *list = NULL;
- GList *l;
- int i;
+ NautilusFile *file;
+ char **visible_columns;
+ char **column_order;
+ const char *column;
+ GList *list = NULL;
+ GList *l;
+ int i;
+
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ visible_columns = get_visible_columns (list_view);
+ column_order = get_column_order (list_view);
+ column = g_object_get_data (G_OBJECT (menu_item), "column-name");
+
+ for (i = 0; visible_columns[i] != NULL; ++i)
+ {
+ list = g_list_prepend (list, visible_columns[i]);
+ }
+
+ if (gtk_check_menu_item_get_active (menu_item))
+ {
+ list = g_list_prepend (list, g_strdup (column));
+ }
+ else
+ {
+ l = g_list_find_custom (list, column, (GCompareFunc) g_strcmp0);
+ list = g_list_delete_link (list, l);
+ }
+
+ list = g_list_reverse (list);
+ nautilus_file_set_metadata_list (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
+ list);
+
+ g_free (visible_columns);
+
+ visible_columns = g_new0 (char *, g_list_length (list) + 1);
+ for (i = 0, l = list; l != NULL; ++i, l = l->next)
+ {
+ visible_columns[i] = l->data;
+ }
+
+ /* set view values ourselves, as new metadata could not have been
+ * updated yet.
+ */
+ apply_columns_settings (list_view, column_order, visible_columns);
+
+ g_list_free (list);
+ g_strfreev (column_order);
+ g_strfreev (visible_columns);
+}
+
+static void
+column_header_menu_use_default (GtkMenuItem *menu_item,
+ NautilusListView *list_view)
+{
+ NautilusFile *file;
+ char **default_columns;
+ char **default_order;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- visible_columns = get_visible_columns (list_view);
- column_order = get_column_order (list_view);
- column = g_object_get_data (G_OBJECT (menu_item), "column-name");
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- for (i = 0; visible_columns[i] != NULL; ++i) {
- list = g_list_prepend (list, visible_columns[i]);
- }
+ nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER, NULL);
+ nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS, NULL);
- if (gtk_check_menu_item_get_active (menu_item)) {
- list = g_list_prepend (list, g_strdup (column));
- } else {
- l = g_list_find_custom (list, column, (GCompareFunc) g_strcmp0);
- list = g_list_delete_link (list, l);
- }
+ default_columns = get_default_visible_columns (list_view);
+ default_order = get_default_column_order (list_view);
- list = g_list_reverse (list);
- nautilus_file_set_metadata_list (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
- list);
+ /* set view values ourselves, as new metadata could not have been
+ * updated yet.
+ */
+ apply_columns_settings (list_view, default_order, default_columns);
- g_free (visible_columns);
+ g_strfreev (default_columns);
+ g_strfreev (default_order);
+}
- visible_columns = g_new0 (char *, g_list_length (list) + 1);
- for (i = 0, l = list; l != NULL; ++i, l = l->next) {
- visible_columns[i] = l->data;
- }
+static gboolean
+column_header_clicked (GtkWidget *column_button,
+ GdkEventButton *event,
+ NautilusListView *list_view)
+{
+ NautilusFile *file;
+ char **visible_columns;
+ char **column_order;
+ GList *all_columns;
+ GHashTable *visible_columns_hash;
+ int i;
+ GList *l;
+ GtkWidget *menu;
+ GtkWidget *menu_item;
+
+ if (event->button != GDK_BUTTON_SECONDARY)
+ {
+ return FALSE;
+ }
+
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+
+ visible_columns = get_visible_columns (list_view);
+ column_order = get_column_order (list_view);
+
+ all_columns = nautilus_get_columns_for_file (file);
+ all_columns = nautilus_sort_columns (all_columns, column_order);
+
+ /* hash table to lookup if a given column should be visible */
+ visible_columns_hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+ /* always show name column */
+ g_hash_table_insert (visible_columns_hash, g_strdup ("name"), g_strdup ("name"));
+ if (visible_columns != NULL)
+ {
+ for (i = 0; visible_columns[i] != NULL; ++i)
+ {
+ g_hash_table_insert (visible_columns_hash,
+ g_ascii_strdown (visible_columns[i], -1),
+ g_ascii_strdown (visible_columns[i], -1));
+ }
+ }
- /* set view values ourselves, as new metadata could not have been
- * updated yet.
- */
- apply_columns_settings (list_view, column_order, visible_columns);
+ menu = gtk_menu_new ();
- g_list_free (list);
- g_strfreev (column_order);
- g_strfreev (visible_columns);
-}
+ for (l = all_columns; l != NULL; l = l->next)
+ {
+ char *name;
+ char *label;
+ char *lowercase;
-static void
-column_header_menu_use_default (GtkMenuItem *menu_item,
- NautilusListView *list_view)
-{
- NautilusFile *file;
- char **default_columns;
- char **default_order;
+ g_object_get (G_OBJECT (l->data),
+ "name", &name,
+ "label", &label,
+ NULL);
+ lowercase = g_ascii_strdown (name, -1);
+
+ menu_item = gtk_check_menu_item_new_with_label (label);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ g_object_set_data_full (G_OBJECT (menu_item),
+ "column-name", name, g_free);
- nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER, NULL);
- nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS, NULL);
+ /* name is always visible */
+ if (strcmp (lowercase, "name") == 0)
+ {
+ gtk_widget_set_sensitive (menu_item, FALSE);
+ }
- default_columns = get_default_visible_columns (list_view);
- default_order = get_default_column_order (list_view);
+ if (g_hash_table_lookup (visible_columns_hash, lowercase) != NULL)
+ {
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
+ TRUE);
+ }
- /* set view values ourselves, as new metadata could not have been
- * updated yet.
- */
- apply_columns_settings (list_view, default_order, default_columns);
+ g_signal_connect (menu_item,
+ "toggled",
+ G_CALLBACK (column_header_menu_toggled),
+ list_view);
+
+ g_free (lowercase);
+ g_free (label);
+ }
+
+ menu_item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+ menu_item = gtk_menu_item_new_with_label (_("Use Default"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+ g_signal_connect (menu_item,
+ "activate",
+ G_CALLBACK (column_header_menu_use_default),
+ list_view);
+
+ gtk_widget_show_all (menu);
+ gtk_menu_popup_for_device (GTK_MENU (menu),
+ gdk_event_get_device ((GdkEvent *) event),
+ NULL, NULL, NULL, NULL, NULL,
+ event->button, event->time);
+
+ g_hash_table_destroy (visible_columns_hash);
+ nautilus_column_list_free (all_columns);
+ g_strfreev (column_order);
+ g_strfreev (visible_columns);
+
+ return TRUE;
+}
+
+static void
+apply_columns_settings (NautilusListView *list_view,
+ char **column_order,
+ char **visible_columns)
+{
+ GList *all_columns;
+ NautilusFile *file;
+ GList *old_view_columns, *view_columns;
+ GHashTable *visible_columns_hash;
+ GtkTreeViewColumn *prev_view_column;
+ GList *l;
+ int i;
+
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+
+ /* prepare ordered list of view columns using column_order and visible_columns */
+ view_columns = NULL;
+
+ all_columns = nautilus_get_columns_for_file (file);
+ all_columns = nautilus_sort_columns (all_columns, column_order);
+
+ /* hash table to lookup if a given column should be visible */
+ visible_columns_hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ (GDestroyNotify) g_free);
+ /* always show name column */
+ g_hash_table_insert (visible_columns_hash, g_strdup ("name"), g_strdup ("name"));
+ if (visible_columns != NULL)
+ {
+ for (i = 0; visible_columns[i] != NULL; ++i)
+ {
+ g_hash_table_insert (visible_columns_hash,
+ g_ascii_strdown (visible_columns[i], -1),
+ g_ascii_strdown (visible_columns[i], -1));
+ }
+ }
- g_strfreev (default_columns);
- g_strfreev (default_order);
-}
+ for (l = all_columns; l != NULL; l = l->next)
+ {
+ char *name;
+ char *lowercase;
-static gboolean
-column_header_clicked (GtkWidget *column_button,
- GdkEventButton *event,
- NautilusListView *list_view)
-{
- NautilusFile *file;
- char **visible_columns;
- char **column_order;
- GList *all_columns;
- GHashTable *visible_columns_hash;
- int i;
- GList *l;
- GtkWidget *menu;
- GtkWidget *menu_item;
-
- if (event->button != GDK_BUTTON_SECONDARY) {
- return FALSE;
- }
-
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
-
- visible_columns = get_visible_columns (list_view);
- column_order = get_column_order (list_view);
-
- all_columns = nautilus_get_columns_for_file (file);
- all_columns = nautilus_sort_columns (all_columns, column_order);
-
- /* hash table to lookup if a given column should be visible */
- visible_columns_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
- /* always show name column */
- g_hash_table_insert (visible_columns_hash, g_strdup ("name"), g_strdup ("name"));
- if (visible_columns != NULL) {
- for (i = 0; visible_columns[i] != NULL; ++i) {
- g_hash_table_insert (visible_columns_hash,
- g_ascii_strdown (visible_columns[i], -1),
- g_ascii_strdown (visible_columns[i], -1));
- }
- }
-
- menu = gtk_menu_new ();
-
- for (l = all_columns; l != NULL; l = l->next) {
- char *name;
- char *label;
- char *lowercase;
-
- g_object_get (G_OBJECT (l->data),
- "name", &name,
- "label", &label,
- NULL);
- lowercase = g_ascii_strdown (name, -1);
-
- menu_item = gtk_check_menu_item_new_with_label (label);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- g_object_set_data_full (G_OBJECT (menu_item),
- "column-name", name, g_free);
-
- /* name is always visible */
- if (strcmp (lowercase, "name") == 0) {
- gtk_widget_set_sensitive (menu_item, FALSE);
- }
-
- if (g_hash_table_lookup (visible_columns_hash, lowercase) != NULL) {
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
- TRUE);
- }
-
- g_signal_connect (menu_item,
- "toggled",
- G_CALLBACK (column_header_menu_toggled),
- list_view);
-
- g_free (lowercase);
- g_free (label);
- }
-
- menu_item = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- menu_item = gtk_menu_item_new_with_label (_("Use Default"));
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- g_signal_connect (menu_item,
- "activate",
- G_CALLBACK (column_header_menu_use_default),
- list_view);
-
- gtk_widget_show_all (menu);
- gtk_menu_popup_for_device (GTK_MENU (menu),
- gdk_event_get_device ((GdkEvent *) event),
- NULL, NULL, NULL, NULL, NULL,
- event->button, event->time);
-
- g_hash_table_destroy (visible_columns_hash);
- nautilus_column_list_free (all_columns);
- g_strfreev (column_order);
- g_strfreev (visible_columns);
-
- return TRUE;
-}
-
-static void
-apply_columns_settings (NautilusListView *list_view,
- char **column_order,
- char **visible_columns)
-{
- GList *all_columns;
- NautilusFile *file;
- GList *old_view_columns, *view_columns;
- GHashTable *visible_columns_hash;
- GtkTreeViewColumn *prev_view_column;
- GList *l;
- int i;
-
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
-
- /* prepare ordered list of view columns using column_order and visible_columns */
- view_columns = NULL;
-
- all_columns = nautilus_get_columns_for_file (file);
- all_columns = nautilus_sort_columns (all_columns, column_order);
-
- /* hash table to lookup if a given column should be visible */
- visible_columns_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_free);
- /* always show name column */
- g_hash_table_insert (visible_columns_hash, g_strdup ("name"), g_strdup ("name"));
- if (visible_columns != NULL) {
- for (i = 0; visible_columns[i] != NULL; ++i) {
- g_hash_table_insert (visible_columns_hash,
- g_ascii_strdown (visible_columns[i], -1),
- g_ascii_strdown (visible_columns[i], -1));
- }
- }
-
- for (l = all_columns; l != NULL; l = l->next) {
- char *name;
- char *lowercase;
-
- g_object_get (G_OBJECT (l->data), "name", &name, NULL);
- lowercase = g_ascii_strdown (name, -1);
-
- if (g_hash_table_lookup (visible_columns_hash, lowercase) != NULL) {
- GtkTreeViewColumn *view_column;
-
- view_column = g_hash_table_lookup (list_view->details->columns, name);
- if (view_column != NULL) {
- view_columns = g_list_prepend (view_columns, view_column);
- }
- }
-
- g_free (name);
- g_free (lowercase);
- }
-
- g_hash_table_destroy (visible_columns_hash);
- nautilus_column_list_free (all_columns);
-
- view_columns = g_list_reverse (view_columns);
-
- /* hide columns that are not present in the configuration */
- old_view_columns = gtk_tree_view_get_columns (list_view->details->tree_view);
- for (l = old_view_columns; l != NULL; l = l->next) {
- if (g_list_find (view_columns, l->data) == NULL) {
- gtk_tree_view_column_set_visible (l->data, FALSE);
- }
- }
- g_list_free (old_view_columns);
-
- /* show new columns from the configuration */
- for (l = view_columns; l != NULL; l = l->next) {
- gtk_tree_view_column_set_visible (l->data, TRUE);
- }
+ g_object_get (G_OBJECT (l->data), "name", &name, NULL);
+ lowercase = g_ascii_strdown (name, -1);
- /* place columns in the correct order */
- prev_view_column = NULL;
- for (l = view_columns; l != NULL; l = l->next) {
- gtk_tree_view_move_column_after (list_view->details->tree_view, l->data, prev_view_column);
- prev_view_column = l->data;
- }
- g_list_free (view_columns);
+ if (g_hash_table_lookup (visible_columns_hash, lowercase) != NULL)
+ {
+ GtkTreeViewColumn *view_column;
+
+ view_column = g_hash_table_lookup (list_view->details->columns, name);
+ if (view_column != NULL)
+ {
+ view_columns = g_list_prepend (view_columns, view_column);
+ }
+ }
+
+ g_free (name);
+ g_free (lowercase);
+ }
+
+ g_hash_table_destroy (visible_columns_hash);
+ nautilus_column_list_free (all_columns);
+
+ view_columns = g_list_reverse (view_columns);
+
+ /* hide columns that are not present in the configuration */
+ old_view_columns = gtk_tree_view_get_columns (list_view->details->tree_view);
+ for (l = old_view_columns; l != NULL; l = l->next)
+ {
+ if (g_list_find (view_columns, l->data) == NULL)
+ {
+ gtk_tree_view_column_set_visible (l->data, FALSE);
+ }
+ }
+ g_list_free (old_view_columns);
+
+ /* show new columns from the configuration */
+ for (l = view_columns; l != NULL; l = l->next)
+ {
+ gtk_tree_view_column_set_visible (l->data, TRUE);
+ }
+
+ /* place columns in the correct order */
+ prev_view_column = NULL;
+ for (l = view_columns; l != NULL; l = l->next)
+ {
+ gtk_tree_view_move_column_after (list_view->details->tree_view, l->data, prev_view_column);
+ prev_view_column = l->data;
+ }
+ g_list_free (view_columns);
}
static void
filename_cell_data_func (GtkTreeViewColumn *column,
- GtkCellRenderer *renderer,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- NautilusListView *view)
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ NautilusListView *view)
{
- char *text;
- GtkTreePath *path;
- PangoUnderline underline;
+ char *text;
+ GtkTreePath *path;
+ PangoUnderline underline;
- gtk_tree_model_get (model, iter,
- view->details->file_name_column_num, &text,
- -1);
+ gtk_tree_model_get (model, iter,
+ view->details->file_name_column_num, &text,
+ -1);
- if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
- path = gtk_tree_model_get_path (model, iter);
+ if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+ {
+ path = gtk_tree_model_get_path (model, iter);
- if (view->details->hover_path == NULL ||
- gtk_tree_path_compare (path, view->details->hover_path)) {
- underline = PANGO_UNDERLINE_NONE;
- } else {
- underline = PANGO_UNDERLINE_SINGLE;
- }
+ if (view->details->hover_path == NULL ||
+ gtk_tree_path_compare (path, view->details->hover_path))
+ {
+ underline = PANGO_UNDERLINE_NONE;
+ }
+ else
+ {
+ underline = PANGO_UNDERLINE_SINGLE;
+ }
- gtk_tree_path_free (path);
- } else {
- underline = PANGO_UNDERLINE_NONE;
- }
+ gtk_tree_path_free (path);
+ }
+ else
+ {
+ underline = PANGO_UNDERLINE_NONE;
+ }
- g_object_set (G_OBJECT (renderer),
- "text", text,
- "underline", underline,
- NULL);
- g_free (text);
+ g_object_set (G_OBJECT (renderer),
+ "text", text,
+ "underline", underline,
+ NULL);
+ g_free (text);
}
static void
@@ -1414,100 +1599,119 @@ location_cell_data_func (GtkTreeViewColumn *column,
NautilusListView *view,
gboolean show_trash_orig)
{
- NautilusDirectory *directory;
- GFile *home_location;
- NautilusFile *file;
- GFile *dir_location;
- GFile *base_location;
- gchar *where = NULL;
-
- directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
+ NautilusDirectory *directory;
+ GFile *home_location;
+ NautilusFile *file;
+ GFile *dir_location;
+ GFile *base_location;
+ gchar *where = NULL;
- home_location = g_file_new_for_path (g_get_home_dir ());
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (view));
- gtk_tree_model_get (model, iter,
- NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
- -1);
+ home_location = g_file_new_for_path (g_get_home_dir ());
- /* The file might be NULL if we just toggled an expander
- * and we're still loading the subdirectory.
- */
- if (file == NULL) {
- return;
- }
+ gtk_tree_model_get (model, iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
- if (show_trash_orig && nautilus_file_is_in_trash (file)) {
- NautilusFile *orig_file;
+ /* The file might be NULL if we just toggled an expander
+ * and we're still loading the subdirectory.
+ */
+ if (file == NULL)
+ {
+ return;
+ }
- orig_file = nautilus_file_get_trash_original_file (file);
+ if (show_trash_orig && nautilus_file_is_in_trash (file))
+ {
+ NautilusFile *orig_file;
- if (orig_file != NULL) {
- nautilus_file_unref (file);
- file = orig_file;
- }
- }
+ orig_file = nautilus_file_get_trash_original_file (file);
- if (!nautilus_file_is_in_recent (file)) {
- dir_location = nautilus_file_get_parent_location (file);
- } else {
- GFile *activation_location;
-
- activation_location = nautilus_file_get_activation_location (file);
- dir_location = g_file_get_parent (activation_location);
-
- g_object_unref (activation_location);
- }
-
- if (!NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
- base_location = g_object_ref (home_location);
- } else {
- NautilusQuery *query;
- NautilusFile *base;
- GFile *location;
-
- query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
- location = nautilus_query_get_location (query);
- base = nautilus_file_get (location);
-
- if (!nautilus_file_is_in_recent (base)) {
- base_location = nautilus_file_get_location (base);
- } else {
- base_location = g_object_ref (home_location);
- }
+ if (orig_file != NULL)
+ {
+ nautilus_file_unref (file);
+ file = orig_file;
+ }
+ }
+
+ if (!nautilus_file_is_in_recent (file))
+ {
+ dir_location = nautilus_file_get_parent_location (file);
+ }
+ else
+ {
+ GFile *activation_location;
+
+ activation_location = nautilus_file_get_activation_location (file);
+ dir_location = g_file_get_parent (activation_location);
+
+ g_object_unref (activation_location);
+ }
+
+ if (!NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ base_location = g_object_ref (home_location);
+ }
+ else
+ {
+ NautilusQuery *query;
+ NautilusFile *base;
+ GFile *location;
+
+ query = nautilus_search_directory_get_query (NAUTILUS_SEARCH_DIRECTORY (directory));
+ location = nautilus_query_get_location (query);
+ base = nautilus_file_get (location);
+
+ if (!nautilus_file_is_in_recent (base))
+ {
+ base_location = nautilus_file_get_location (base);
+ }
+ else
+ {
+ base_location = g_object_ref (home_location);
+ }
- nautilus_file_unref (base);
- g_object_unref (location);
- g_object_unref (query);
- }
+ nautilus_file_unref (base);
+ g_object_unref (location);
+ g_object_unref (query);
+ }
- if (g_file_equal (base_location, dir_location)) {
- /* Only occurs when search result is
- * a direct child of the base location
- */
- where = g_strdup ("");
- } else if (g_file_equal (home_location, dir_location)) {
- where = g_strdup (_("Home"));
- } else if (g_file_has_prefix (dir_location, base_location)) {
- gchar *relative_path;
+ if (g_file_equal (base_location, dir_location))
+ {
+ /* Only occurs when search result is
+ * a direct child of the base location
+ */
+ where = g_strdup ("");
+ }
+ else if (g_file_equal (home_location, dir_location))
+ {
+ where = g_strdup (_("Home"));
+ }
+ else if (g_file_has_prefix (dir_location, base_location))
+ {
+ gchar *relative_path;
- relative_path = g_file_get_relative_path (base_location, dir_location);
- where = g_filename_display_name (relative_path);
+ relative_path = g_file_get_relative_path (base_location, dir_location);
+ where = g_filename_display_name (relative_path);
- g_free (relative_path);
- } else {
- where = g_file_get_path (dir_location);
- }
+ g_free (relative_path);
+ }
+ else
+ {
+ where = g_file_get_path (dir_location);
+ }
- g_object_set (G_OBJECT (renderer),
- "text", where,
- NULL);
+ g_object_set (G_OBJECT (renderer),
+ "text", where,
+ NULL);
- g_free (where);
+ g_free (where);
- g_object_unref (base_location);
- g_object_unref (dir_location);
- nautilus_file_unref (file);
- g_object_unref (home_location);
+ g_object_unref (base_location);
+ g_object_unref (dir_location);
+ nautilus_file_unref (file);
+ g_object_unref (home_location);
}
@@ -1518,7 +1722,7 @@ where_cell_data_func (GtkTreeViewColumn *column,
GtkTreeIter *iter,
NautilusListView *view)
{
- location_cell_data_func (column, renderer, model, iter, view, FALSE);
+ location_cell_data_func (column, renderer, model, iter, view, FALSE);
}
static void
@@ -1528,7 +1732,7 @@ trash_orig_path_cell_data_func (GtkTreeViewColumn *column,
GtkTreeIter *iter,
NautilusListView *view)
{
- location_cell_data_func (column, renderer, model, iter, view, TRUE);
+ location_cell_data_func (column, renderer, model, iter, view, TRUE);
}
#define SMALL_ZOOM_ICON_PADDING 0
@@ -1539,1692 +1743,1815 @@ trash_orig_path_cell_data_func (GtkTreeViewColumn *column,
static gint
nautilus_list_view_get_icon_padding_for_zoom_level (NautilusListZoomLevel zoom_level)
{
- switch (zoom_level) {
- case NAUTILUS_LIST_ZOOM_LEVEL_SMALL:
- return SMALL_ZOOM_ICON_PADDING;
- case NAUTILUS_LIST_ZOOM_LEVEL_STANDARD:
- return STANDARD_ZOOM_ICON_PADDING;
- case NAUTILUS_LIST_ZOOM_LEVEL_LARGE:
- return LARGE_ZOOM_ICON_PADDING;
- case NAUTILUS_LIST_ZOOM_LEVEL_LARGER:
- return LARGER_ZOOM_ICON_PADDING;
- default:
- g_assert_not_reached ();
- }
+ switch (zoom_level)
+ {
+ case NAUTILUS_LIST_ZOOM_LEVEL_SMALL:
+ {
+ return SMALL_ZOOM_ICON_PADDING;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_STANDARD:
+ {
+ return STANDARD_ZOOM_ICON_PADDING;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_LARGE:
+ {
+ return LARGE_ZOOM_ICON_PADDING;
+ }
+
+ case NAUTILUS_LIST_ZOOM_LEVEL_LARGER:
+ {
+ return LARGER_ZOOM_ICON_PADDING;
+ }
+
+ default:
+ g_assert_not_reached ();
+ }
}
static void
set_up_pixbuf_size (NautilusListView *view)
{
- int icon_size, icon_padding;
+ int icon_size, icon_padding;
- /* Make all rows the same size. */
- icon_size = nautilus_list_model_get_icon_size_for_zoom_level (view->details->zoom_level);
- icon_padding = nautilus_list_view_get_icon_padding_for_zoom_level (view->details->zoom_level);
- gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->pixbuf_cell),
- -1, icon_size + 2 * icon_padding);
+ /* Make all rows the same size. */
+ icon_size = nautilus_list_model_get_icon_size_for_zoom_level (view->details->zoom_level);
+ icon_padding = nautilus_list_view_get_icon_padding_for_zoom_level (view->details->zoom_level);
+ gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->pixbuf_cell),
+ -1, icon_size + 2 * icon_padding);
- /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=641518 */
- gtk_tree_view_columns_autosize (view->details->tree_view);
+ /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=641518 */
+ gtk_tree_view_columns_autosize (view->details->tree_view);
}
static gint
get_icon_scale_callback (NautilusListModel *model,
- NautilusListView *view)
+ NautilusListView *view)
{
- return gtk_widget_get_scale_factor (GTK_WIDGET (view->details->tree_view));
+ return gtk_widget_get_scale_factor (GTK_WIDGET (view->details->tree_view));
}
static void
create_and_set_up_tree_view (NautilusListView *view)
{
- GtkCellRenderer *cell;
- GtkTreeViewColumn *column;
- AtkObject *atk_obj;
- GList *nautilus_columns;
- GList *l;
- gchar **default_column_order, **default_visible_columns;
- GtkWidget *content_widget;
-
- content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
- view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
- view->details->columns = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- NULL);
- gtk_tree_view_set_enable_search (view->details->tree_view, FALSE);
-
- view->details->drag_dest =
- nautilus_tree_view_drag_dest_new (view->details->tree_view);
-
- g_signal_connect_object (view->details->drag_dest,
- "get-root-uri",
- G_CALLBACK (get_root_uri_callback),
- view, 0);
- g_signal_connect_object (view->details->drag_dest,
- "get-file-for-path",
- G_CALLBACK (get_file_for_path_callback),
- view, 0);
- g_signal_connect_object (view->details->drag_dest,
- "move-copy-items",
- G_CALLBACK (move_copy_items_callback),
- view, 0);
- g_signal_connect_object (view->details->drag_dest, "handle-netscape-url",
- G_CALLBACK (list_view_handle_netscape_url), view, 0);
- g_signal_connect_object (view->details->drag_dest, "handle-uri-list",
- G_CALLBACK (list_view_handle_uri_list), view, 0);
- g_signal_connect_object (view->details->drag_dest, "handle-text",
- G_CALLBACK (list_view_handle_text), view, 0);
- g_signal_connect_object (view->details->drag_dest, "handle-raw",
- G_CALLBACK (list_view_handle_raw), view, 0);
- g_signal_connect_object (view->details->drag_dest, "handle-hover",
- G_CALLBACK (list_view_handle_hover), view, 0);
-
- g_signal_connect_object (gtk_tree_view_get_selection (view->details->tree_view),
- "changed",
- G_CALLBACK (list_selection_changed_callback), view, 0);
-
- g_signal_connect_object (view->details->tree_view, "motion-notify-event",
- G_CALLBACK (motion_notify_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "enter-notify-event",
- G_CALLBACK (enter_notify_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "leave-notify-event",
- G_CALLBACK (leave_notify_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "button-press-event",
- G_CALLBACK (button_press_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "button-release-event",
- G_CALLBACK (button_release_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "key-press-event",
- G_CALLBACK (key_press_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "test-expand-row",
- G_CALLBACK (test_expand_row_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "popup-menu",
- G_CALLBACK (popup_menu_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "row-expanded",
- G_CALLBACK (row_expanded_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "row-collapsed",
- G_CALLBACK (row_collapsed_callback), view, 0);
- g_signal_connect_object (view->details->tree_view, "row-activated",
- G_CALLBACK (row_activated_callback), view, 0);
-
- view->details->model = g_object_new (NAUTILUS_TYPE_LIST_MODEL, NULL);
- gtk_tree_view_set_model (view->details->tree_view, GTK_TREE_MODEL (view->details->model));
- /* Need the model for the dnd drop icon "accept" change */
- nautilus_list_model_set_drag_view (NAUTILUS_LIST_MODEL (view->details->model),
- view->details->tree_view, 0, 0);
-
- g_signal_connect_object (view->details->model, "sort-column-changed",
- G_CALLBACK (sort_column_changed_callback), view, 0);
-
- g_signal_connect_object (view->details->model, "subdirectory-unloaded",
- G_CALLBACK (subdirectory_unloaded_callback), view, 0);
-
- g_signal_connect_object (view->details->model, "get-icon-scale",
- G_CALLBACK (get_icon_scale_callback), view, 0);
-
- gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view->details->tree_view), GTK_SELECTION_MULTIPLE);
-
- g_settings_bind (nautilus_list_view_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE,
- view->details->tree_view, "show-expanders",
- G_SETTINGS_BIND_DEFAULT);
-
- nautilus_columns = nautilus_get_all_columns ();
-
- for (l = nautilus_columns; l != NULL; l = l->next) {
- NautilusColumn *nautilus_column;
- int column_num;
- char *name;
- char *label;
- float xalign;
- GtkSortType sort_order;
-
- nautilus_column = NAUTILUS_COLUMN (l->data);
-
- g_object_get (nautilus_column,
- "name", &name,
- "label", &label,
- "xalign", &xalign,
- "default-sort-order", &sort_order,
- NULL);
-
- column_num = nautilus_list_model_add_column (view->details->model,
- nautilus_column);
-
- /* Created the name column specially, because it
- * has the icon in it.*/
- if (!strcmp (name, "name")) {
- /* Create the file name column */
- view->details->file_name_column = gtk_tree_view_column_new ();
- gtk_tree_view_append_column (view->details->tree_view,
- view->details->file_name_column);
- view->details->file_name_column_num = column_num;
-
- g_hash_table_insert (view->details->columns,
- g_strdup ("name"),
- view->details->file_name_column);
-
- g_signal_connect (gtk_tree_view_column_get_button (view->details->file_name_column),
- "button-press-event",
- G_CALLBACK (column_header_clicked),
- view);
-
- gtk_tree_view_set_search_column (view->details->tree_view, column_num);
-
- gtk_tree_view_column_set_sort_column_id (view->details->file_name_column, column_num);
- gtk_tree_view_column_set_title (view->details->file_name_column, _("Name"));
- gtk_tree_view_column_set_resizable (view->details->file_name_column, TRUE);
- gtk_tree_view_column_set_expand (view->details->file_name_column, TRUE);
-
- /* Initial padding */
- cell = gtk_cell_renderer_text_new ();
- gtk_tree_view_column_pack_start (view->details->file_name_column, cell, FALSE);
- g_object_set (cell, "xpad", 6, NULL);
- g_settings_bind (nautilus_list_view_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE,
- cell, "visible",
- G_SETTINGS_BIND_INVERT_BOOLEAN | G_SETTINGS_BIND_GET);
-
- /* File icon */
- cell = gtk_cell_renderer_pixbuf_new ();
- view->details->pixbuf_cell = (GtkCellRendererPixbuf *)cell;
- set_up_pixbuf_size (view);
-
- gtk_tree_view_column_pack_start (view->details->file_name_column, cell, FALSE);
- gtk_tree_view_column_set_attributes (view->details->file_name_column,
- cell,
- "surface", nautilus_list_model_get_column_id_from_zoom_level (view->details->zoom_level),
- NULL);
-
- cell = gtk_cell_renderer_text_new ();
- view->details->file_name_cell = (GtkCellRendererText *)cell;
- g_object_set (cell,
- "ellipsize", PANGO_ELLIPSIZE_END,
- "single-paragraph-mode", TRUE,
- "width-chars", 30,
- "xpad", 5,
- NULL);
-
- gtk_tree_view_column_pack_start (view->details->file_name_column, cell, TRUE);
- gtk_tree_view_column_set_cell_data_func (view->details->file_name_column, cell,
- (GtkTreeCellDataFunc) filename_cell_data_func,
- view, NULL);
- } else {
- /* We need to use libgd */
- cell = gd_styled_text_renderer_new ();
- /* FIXME: should be just dim-label.
- * See https://bugzilla.gnome.org/show_bug.cgi?id=744397
- */
- gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (cell),
- "nautilus-list-dim-label");
-
- g_object_set (cell,
- "xalign", xalign,
- "xpad", 5,
- NULL);
- if (!strcmp (name, "permissions")) {
- g_object_set (cell,
- "family", "Monospace",
- NULL);
- }
- view->details->cells = g_list_append (view->details->cells,
- cell);
- column = gtk_tree_view_column_new_with_attributes (label,
- cell,
- "text", column_num,
- NULL);
- gtk_tree_view_append_column (view->details->tree_view, column);
- gtk_tree_view_column_set_sort_column_id (column, column_num);
- g_hash_table_insert (view->details->columns,
- g_strdup (name),
- column);
-
- g_signal_connect (gtk_tree_view_column_get_button (column),
- "button-press-event",
- G_CALLBACK (column_header_clicked),
- view);
-
- gtk_tree_view_column_set_resizable (column, TRUE);
- gtk_tree_view_column_set_sort_order (column, sort_order);
-
- if (!strcmp (name, "where")) {
- gtk_tree_view_column_set_cell_data_func (column, cell,
- (GtkTreeCellDataFunc) where_cell_data_func,
- view, NULL);
- } else if (!strcmp (name, "trash_orig_path")) {
- gtk_tree_view_column_set_cell_data_func (column, cell,
- (GtkTreeCellDataFunc) trash_orig_path_cell_data_func,
- view, NULL);
- }
- }
- g_free (name);
- g_free (label);
- }
- nautilus_column_list_free (nautilus_columns);
-
- default_visible_columns = g_settings_get_strv (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
- default_column_order = g_settings_get_strv (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
-
- /* Apply the default column order and visible columns, to get it
- * right most of the time. The metadata will be checked when a
- * folder is loaded */
- apply_columns_settings (view,
- default_column_order,
- default_visible_columns);
-
- gtk_widget_show (GTK_WIDGET (view->details->tree_view));
- gtk_container_add (GTK_CONTAINER (content_widget), GTK_WIDGET (view->details->tree_view));
-
- atk_obj = gtk_widget_get_accessible (GTK_WIDGET (view->details->tree_view));
- atk_object_set_name (atk_obj, _("List View"));
-
- g_strfreev (default_visible_columns);
- g_strfreev (default_column_order);
-}
-
-static void
-nautilus_list_view_add_file (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
-{
- NautilusListModel *model;
-
- model = NAUTILUS_LIST_VIEW (view)->details->model;
- nautilus_list_model_add_file (model, file, directory);
+ GtkCellRenderer *cell;
+ GtkTreeViewColumn *column;
+ AtkObject *atk_obj;
+ GList *nautilus_columns;
+ GList *l;
+ gchar **default_column_order, **default_visible_columns;
+ GtkWidget *content_widget;
+
+ content_widget = nautilus_files_view_get_content_widget (NAUTILUS_FILES_VIEW (view));
+ view->details->tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
+ view->details->columns = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ (GDestroyNotify) g_free,
+ NULL);
+ gtk_tree_view_set_enable_search (view->details->tree_view, FALSE);
+
+ view->details->drag_dest =
+ nautilus_tree_view_drag_dest_new (view->details->tree_view);
+
+ g_signal_connect_object (view->details->drag_dest,
+ "get-root-uri",
+ G_CALLBACK (get_root_uri_callback),
+ view, 0);
+ g_signal_connect_object (view->details->drag_dest,
+ "get-file-for-path",
+ G_CALLBACK (get_file_for_path_callback),
+ view, 0);
+ g_signal_connect_object (view->details->drag_dest,
+ "move-copy-items",
+ G_CALLBACK (move_copy_items_callback),
+ view, 0);
+ g_signal_connect_object (view->details->drag_dest, "handle-netscape-url",
+ G_CALLBACK (list_view_handle_netscape_url), view, 0);
+ g_signal_connect_object (view->details->drag_dest, "handle-uri-list",
+ G_CALLBACK (list_view_handle_uri_list), view, 0);
+ g_signal_connect_object (view->details->drag_dest, "handle-text",
+ G_CALLBACK (list_view_handle_text), view, 0);
+ g_signal_connect_object (view->details->drag_dest, "handle-raw",
+ G_CALLBACK (list_view_handle_raw), view, 0);
+ g_signal_connect_object (view->details->drag_dest, "handle-hover",
+ G_CALLBACK (list_view_handle_hover), view, 0);
+
+ g_signal_connect_object (gtk_tree_view_get_selection (view->details->tree_view),
+ "changed",
+ G_CALLBACK (list_selection_changed_callback), view, 0);
+
+ g_signal_connect_object (view->details->tree_view, "motion-notify-event",
+ G_CALLBACK (motion_notify_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "enter-notify-event",
+ G_CALLBACK (enter_notify_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "leave-notify-event",
+ G_CALLBACK (leave_notify_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "button-press-event",
+ G_CALLBACK (button_press_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "button-release-event",
+ G_CALLBACK (button_release_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "key-press-event",
+ G_CALLBACK (key_press_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "test-expand-row",
+ G_CALLBACK (test_expand_row_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "popup-menu",
+ G_CALLBACK (popup_menu_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "row-expanded",
+ G_CALLBACK (row_expanded_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "row-collapsed",
+ G_CALLBACK (row_collapsed_callback), view, 0);
+ g_signal_connect_object (view->details->tree_view, "row-activated",
+ G_CALLBACK (row_activated_callback), view, 0);
+
+ view->details->model = g_object_new (NAUTILUS_TYPE_LIST_MODEL, NULL);
+ gtk_tree_view_set_model (view->details->tree_view, GTK_TREE_MODEL (view->details->model));
+ /* Need the model for the dnd drop icon "accept" change */
+ nautilus_list_model_set_drag_view (NAUTILUS_LIST_MODEL (view->details->model),
+ view->details->tree_view, 0, 0);
+
+ g_signal_connect_object (view->details->model, "sort-column-changed",
+ G_CALLBACK (sort_column_changed_callback), view, 0);
+
+ g_signal_connect_object (view->details->model, "subdirectory-unloaded",
+ G_CALLBACK (subdirectory_unloaded_callback), view, 0);
+
+ g_signal_connect_object (view->details->model, "get-icon-scale",
+ G_CALLBACK (get_icon_scale_callback), view, 0);
+
+ gtk_tree_selection_set_mode (gtk_tree_view_get_selection (view->details->tree_view), GTK_SELECTION_MULTIPLE);
+
+ g_settings_bind (nautilus_list_view_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE,
+ view->details->tree_view, "show-expanders",
+ G_SETTINGS_BIND_DEFAULT);
+
+ nautilus_columns = nautilus_get_all_columns ();
+
+ for (l = nautilus_columns; l != NULL; l = l->next)
+ {
+ NautilusColumn *nautilus_column;
+ int column_num;
+ char *name;
+ char *label;
+ float xalign;
+ GtkSortType sort_order;
+
+ nautilus_column = NAUTILUS_COLUMN (l->data);
+
+ g_object_get (nautilus_column,
+ "name", &name,
+ "label", &label,
+ "xalign", &xalign,
+ "default-sort-order", &sort_order,
+ NULL);
+
+ column_num = nautilus_list_model_add_column (view->details->model,
+ nautilus_column);
+
+ /* Created the name column specially, because it
+ * has the icon in it.*/
+ if (!strcmp (name, "name"))
+ {
+ /* Create the file name column */
+ view->details->file_name_column = gtk_tree_view_column_new ();
+ gtk_tree_view_append_column (view->details->tree_view,
+ view->details->file_name_column);
+ view->details->file_name_column_num = column_num;
+
+ g_hash_table_insert (view->details->columns,
+ g_strdup ("name"),
+ view->details->file_name_column);
+
+ g_signal_connect (gtk_tree_view_column_get_button (view->details->file_name_column),
+ "button-press-event",
+ G_CALLBACK (column_header_clicked),
+ view);
+
+ gtk_tree_view_set_search_column (view->details->tree_view, column_num);
+
+ gtk_tree_view_column_set_sort_column_id (view->details->file_name_column, column_num);
+ gtk_tree_view_column_set_title (view->details->file_name_column, _("Name"));
+ gtk_tree_view_column_set_resizable (view->details->file_name_column, TRUE);
+ gtk_tree_view_column_set_expand (view->details->file_name_column, TRUE);
+
+ /* Initial padding */
+ cell = gtk_cell_renderer_text_new ();
+ gtk_tree_view_column_pack_start (view->details->file_name_column, cell, FALSE);
+ g_object_set (cell, "xpad", 6, NULL);
+ g_settings_bind (nautilus_list_view_preferences, NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE,
+ cell, "visible",
+ G_SETTINGS_BIND_INVERT_BOOLEAN | G_SETTINGS_BIND_GET);
+
+ /* File icon */
+ cell = gtk_cell_renderer_pixbuf_new ();
+ view->details->pixbuf_cell = (GtkCellRendererPixbuf *) cell;
+ set_up_pixbuf_size (view);
+
+ gtk_tree_view_column_pack_start (view->details->file_name_column, cell, FALSE);
+ gtk_tree_view_column_set_attributes (view->details->file_name_column,
+ cell,
+ "surface", nautilus_list_model_get_column_id_from_zoom_level (view->details->zoom_level),
+ NULL);
+
+ cell = gtk_cell_renderer_text_new ();
+ view->details->file_name_cell = (GtkCellRendererText *) cell;
+ g_object_set (cell,
+ "ellipsize", PANGO_ELLIPSIZE_END,
+ "single-paragraph-mode", TRUE,
+ "width-chars", 30,
+ "xpad", 5,
+ NULL);
+
+ gtk_tree_view_column_pack_start (view->details->file_name_column, cell, TRUE);
+ gtk_tree_view_column_set_cell_data_func (view->details->file_name_column, cell,
+ (GtkTreeCellDataFunc) filename_cell_data_func,
+ view, NULL);
+ }
+ else
+ {
+ /* We need to use libgd */
+ cell = gd_styled_text_renderer_new ();
+ /* FIXME: should be just dim-label.
+ * See https://bugzilla.gnome.org/show_bug.cgi?id=744397
+ */
+ gd_styled_text_renderer_add_class (GD_STYLED_TEXT_RENDERER (cell),
+ "nautilus-list-dim-label");
+
+ g_object_set (cell,
+ "xalign", xalign,
+ "xpad", 5,
+ NULL);
+ if (!strcmp (name, "permissions"))
+ {
+ g_object_set (cell,
+ "family", "Monospace",
+ NULL);
+ }
+ view->details->cells = g_list_append (view->details->cells,
+ cell);
+ column = gtk_tree_view_column_new_with_attributes (label,
+ cell,
+ "text", column_num,
+ NULL);
+ gtk_tree_view_append_column (view->details->tree_view, column);
+ gtk_tree_view_column_set_sort_column_id (column, column_num);
+ g_hash_table_insert (view->details->columns,
+ g_strdup (name),
+ column);
+
+ g_signal_connect (gtk_tree_view_column_get_button (column),
+ "button-press-event",
+ G_CALLBACK (column_header_clicked),
+ view);
+
+ gtk_tree_view_column_set_resizable (column, TRUE);
+ gtk_tree_view_column_set_sort_order (column, sort_order);
+
+ if (!strcmp (name, "where"))
+ {
+ gtk_tree_view_column_set_cell_data_func (column, cell,
+ (GtkTreeCellDataFunc) where_cell_data_func,
+ view, NULL);
+ }
+ else if (!strcmp (name, "trash_orig_path"))
+ {
+ gtk_tree_view_column_set_cell_data_func (column, cell,
+ (GtkTreeCellDataFunc) trash_orig_path_cell_data_func,
+ view, NULL);
+ }
+ }
+ g_free (name);
+ g_free (label);
+ }
+ nautilus_column_list_free (nautilus_columns);
+
+ default_visible_columns = g_settings_get_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
+ default_column_order = g_settings_get_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
+
+ /* Apply the default column order and visible columns, to get it
+ * right most of the time. The metadata will be checked when a
+ * folder is loaded */
+ apply_columns_settings (view,
+ default_column_order,
+ default_visible_columns);
+
+ gtk_widget_show (GTK_WIDGET (view->details->tree_view));
+ gtk_container_add (GTK_CONTAINER (content_widget), GTK_WIDGET (view->details->tree_view));
+
+ atk_obj = gtk_widget_get_accessible (GTK_WIDGET (view->details->tree_view));
+ atk_object_set_name (atk_obj, _("List View"));
+
+ g_strfreev (default_visible_columns);
+ g_strfreev (default_column_order);
+}
+
+static void
+nautilus_list_view_add_file (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
+{
+ NautilusListModel *model;
+
+ model = NAUTILUS_LIST_VIEW (view)->details->model;
+ nautilus_list_model_add_file (model, file, directory);
}
static char **
get_default_visible_columns (NautilusListView *list_view)
{
- NautilusFile *file;
- NautilusDirectory *directory;
+ NautilusFile *file;
+ NautilusDirectory *directory;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- if (nautilus_file_is_in_trash (file)) {
- return g_strdupv ((gchar **) default_trash_visible_columns);
- }
+ if (nautilus_file_is_in_trash (file))
+ {
+ return g_strdupv ((gchar **) default_trash_visible_columns);
+ }
- directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
- if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
- return g_strdupv ((gchar **) default_search_visible_columns);
- }
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ return g_strdupv ((gchar **) default_search_visible_columns);
+ }
- return g_settings_get_strv (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
+ return g_settings_get_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
}
static char **
get_visible_columns (NautilusListView *list_view)
{
- NautilusFile *file;
- GList *visible_columns;
+ NautilusFile *file;
+ GList *visible_columns;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- visible_columns = nautilus_file_get_metadata_list
- (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS);
+ visible_columns = nautilus_file_get_metadata_list
+ (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS);
- if (visible_columns) {
- GPtrArray *res;
- GList *l;
+ if (visible_columns)
+ {
+ GPtrArray *res;
+ GList *l;
- res = g_ptr_array_new ();
- for (l = visible_columns; l != NULL; l = l->next) {
- g_ptr_array_add (res, l->data);
- }
- g_ptr_array_add (res, NULL);
+ res = g_ptr_array_new ();
+ for (l = visible_columns; l != NULL; l = l->next)
+ {
+ g_ptr_array_add (res, l->data);
+ }
+ g_ptr_array_add (res, NULL);
- g_list_free (visible_columns);
+ g_list_free (visible_columns);
- return (char **) g_ptr_array_free (res, FALSE);
- }
+ return (char **) g_ptr_array_free (res, FALSE);
+ }
- return get_default_visible_columns (list_view);
+ return get_default_visible_columns (list_view);
}
static char **
get_default_column_order (NautilusListView *list_view)
{
- NautilusFile *file;
- NautilusDirectory *directory;
+ NautilusFile *file;
+ NautilusDirectory *directory;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- if (nautilus_file_is_in_trash (file)) {
- return g_strdupv ((gchar **) default_trash_columns_order);
- }
+ if (nautilus_file_is_in_trash (file))
+ {
+ return g_strdupv ((gchar **) default_trash_columns_order);
+ }
- directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
- if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
- return g_strdupv ((gchar **) default_search_columns_order);
- }
+ directory = nautilus_files_view_get_model (NAUTILUS_FILES_VIEW (list_view));
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ return g_strdupv ((gchar **) default_search_columns_order);
+ }
- return g_settings_get_strv (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
+ return g_settings_get_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
}
static char **
get_column_order (NautilusListView *list_view)
{
- NautilusFile *file;
- GList *column_order;
+ NautilusFile *file;
+ GList *column_order;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- column_order = nautilus_file_get_metadata_list
- (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER);
+ column_order = nautilus_file_get_metadata_list
+ (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER);
- if (column_order) {
- GPtrArray *res;
- GList *l;
+ if (column_order)
+ {
+ GPtrArray *res;
+ GList *l;
- res = g_ptr_array_new ();
- for (l = column_order; l != NULL; l = l->next) {
- g_ptr_array_add (res, l->data);
- }
- g_ptr_array_add (res, NULL);
+ res = g_ptr_array_new ();
+ for (l = column_order; l != NULL; l = l->next)
+ {
+ g_ptr_array_add (res, l->data);
+ }
+ g_ptr_array_add (res, NULL);
- g_list_free (column_order);
+ g_list_free (column_order);
- return (char **) g_ptr_array_free (res, FALSE);
- }
+ return (char **) g_ptr_array_free (res, FALSE);
+ }
- return get_default_column_order (list_view);
+ return get_default_column_order (list_view);
}
static void
check_allow_sort (NautilusListView *list_view)
{
- GList *column_names;
- GList *l;
- NautilusFile *file;
- GtkTreeViewColumn *column;
- gboolean allow_sorting;
- int sort_column_id;
-
- column_names = g_hash_table_get_keys (list_view->details->columns);
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- allow_sorting = ! (nautilus_file_is_in_recent (file) || nautilus_file_is_in_search (file));
-
- for (l = column_names; l != NULL; l = l->next) {
- column = g_hash_table_lookup (list_view->details->columns, l->data);
- if (allow_sorting) {
- sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
- g_quark_from_string (l->data));
- /* Restore its original sorting id. We rely on that the keys of the hashmap
- * use the same string than the sort criterias */
- gtk_tree_view_column_set_sort_column_id (column, sort_column_id);
- } else {
- /* This disables the header and any sorting capability (like shortcuts),
- * but leaving them interactionable so the user can still resize them */
- gtk_tree_view_column_set_sort_column_id (column, -1);
- }
+ GList *column_names;
+ GList *l;
+ NautilusFile *file;
+ GtkTreeViewColumn *column;
+ gboolean allow_sorting;
+ int sort_column_id;
+
+ column_names = g_hash_table_get_keys (list_view->details->columns);
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ allow_sorting = !(nautilus_file_is_in_recent (file) || nautilus_file_is_in_search (file));
+
+ for (l = column_names; l != NULL; l = l->next)
+ {
+ column = g_hash_table_lookup (list_view->details->columns, l->data);
+ if (allow_sorting)
+ {
+ sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
+ g_quark_from_string (l->data));
+ /* Restore its original sorting id. We rely on that the keys of the hashmap
+ * use the same string than the sort criterias */
+ gtk_tree_view_column_set_sort_column_id (column, sort_column_id);
}
+ else
+ {
+ /* This disables the header and any sorting capability (like shortcuts),
+ * but leaving them interactionable so the user can still resize them */
+ gtk_tree_view_column_set_sort_column_id (column, -1);
+ }
+ }
- g_list_free (column_names);
+ g_list_free (column_names);
}
static void
set_columns_settings_from_metadata_and_preferences (NautilusListView *list_view)
{
- char **column_order;
- char **visible_columns;
+ char **column_order;
+ char **visible_columns;
- column_order = get_column_order (list_view);
- visible_columns = get_visible_columns (list_view);
+ column_order = get_column_order (list_view);
+ visible_columns = get_visible_columns (list_view);
- apply_columns_settings (list_view, column_order, visible_columns);
+ apply_columns_settings (list_view, column_order, visible_columns);
- g_strfreev (column_order);
- g_strfreev (visible_columns);
+ g_strfreev (column_order);
+ g_strfreev (visible_columns);
}
static void
set_sort_order_from_metadata_and_preferences (NautilusListView *list_view)
{
- char *sort_attribute;
- int sort_column_id;
- NautilusFile *file;
- gboolean sort_reversed, default_sort_reversed;
- const gchar *default_sort_order;
-
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
- default_sort_order = get_default_sort_order (file, &default_sort_reversed);
- if (!(nautilus_file_is_in_recent (file) || nautilus_file_is_in_search (file))) {
- sort_attribute = nautilus_file_get_metadata (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
- NULL);
- sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
- g_quark_from_string (sort_attribute));
- g_free (sort_attribute);
-
- if (sort_column_id == -1) {
- sort_column_id =
- nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
- g_quark_from_string (default_sort_order));
- }
-
- sort_reversed = nautilus_file_get_boolean_metadata (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
- default_sort_reversed);
- } else {
- /* Make sure we use the default one and not one that the user used previously
- * of the change to not allow sorting on search and recent, or the
- * case that the user or some app modified directly the metadata */
- sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
- g_quark_from_string (default_sort_order));
- sort_reversed = default_sort_reversed;
- }
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_view->details->model),
- sort_column_id,
- sort_reversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING);
+ char *sort_attribute;
+ int sort_column_id;
+ NautilusFile *file;
+ gboolean sort_reversed, default_sort_reversed;
+ const gchar *default_sort_order;
+
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (list_view));
+ default_sort_order = get_default_sort_order (file, &default_sort_reversed);
+ if (!(nautilus_file_is_in_recent (file) || nautilus_file_is_in_search (file)))
+ {
+ sort_attribute = nautilus_file_get_metadata (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
+ NULL);
+ sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
+ g_quark_from_string (sort_attribute));
+ g_free (sort_attribute);
+
+ if (sort_column_id == -1)
+ {
+ sort_column_id =
+ nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
+ g_quark_from_string (default_sort_order));
+ }
+
+ sort_reversed = nautilus_file_get_boolean_metadata (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
+ default_sort_reversed);
+ }
+ else
+ {
+ /* Make sure we use the default one and not one that the user used previously
+ * of the change to not allow sorting on search and recent, or the
+ * case that the user or some app modified directly the metadata */
+ sort_column_id = nautilus_list_model_get_sort_column_id_from_attribute (list_view->details->model,
+ g_quark_from_string (default_sort_order));
+ sort_reversed = default_sort_reversed;
+ }
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (list_view->details->model),
+ sort_column_id,
+ sort_reversed ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING);
}
static NautilusListZoomLevel
-get_default_zoom_level (void) {
- NautilusListZoomLevel default_zoom_level;
+get_default_zoom_level (void)
+{
+ NautilusListZoomLevel default_zoom_level;
- default_zoom_level = g_settings_get_enum (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL);
+ default_zoom_level = g_settings_get_enum (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL);
- if (default_zoom_level < NAUTILUS_LIST_ZOOM_LEVEL_SMALL
- || default_zoom_level > NAUTILUS_LIST_ZOOM_LEVEL_LARGER) {
- default_zoom_level = NAUTILUS_LIST_ZOOM_LEVEL_STANDARD;
- }
+ if (default_zoom_level < NAUTILUS_LIST_ZOOM_LEVEL_SMALL
+ || default_zoom_level > NAUTILUS_LIST_ZOOM_LEVEL_LARGER)
+ {
+ default_zoom_level = NAUTILUS_LIST_ZOOM_LEVEL_STANDARD;
+ }
- return default_zoom_level;
+ return default_zoom_level;
}
static void
nautilus_list_view_begin_loading (NautilusFilesView *view)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (view);
+ list_view = NAUTILUS_LIST_VIEW (view);
- set_sort_order_from_metadata_and_preferences (list_view);
- set_columns_settings_from_metadata_and_preferences (list_view);
- check_allow_sort (list_view);
+ set_sort_order_from_metadata_and_preferences (list_view);
+ set_columns_settings_from_metadata_and_preferences (list_view);
+ check_allow_sort (list_view);
}
static void
nautilus_list_view_clear (NautilusFilesView *view)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (view);
+ list_view = NAUTILUS_LIST_VIEW (view);
- if (list_view->details->model != NULL) {
- nautilus_list_model_clear (list_view->details->model);
- }
+ if (list_view->details->model != NULL)
+ {
+ nautilus_list_model_clear (list_view->details->model);
+ }
}
static void
-nautilus_list_view_file_changed (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
+nautilus_list_view_file_changed (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
{
- NautilusListView *listview;
+ NautilusListView *listview;
- listview = NAUTILUS_LIST_VIEW (view);
-
- nautilus_list_model_file_changed (listview->details->model, file, directory);
+ listview = NAUTILUS_LIST_VIEW (view);
+
+ nautilus_list_model_file_changed (listview->details->model, file, directory);
}
-typedef struct {
- GtkTreePath *path;
- gboolean is_common;
- gboolean is_root;
+typedef struct
+{
+ GtkTreePath *path;
+ gboolean is_common;
+ gboolean is_root;
} HasCommonParentData;
static void
tree_selection_has_common_parent_foreach_func (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
- HasCommonParentData *data;
- GtkTreePath *parent_path;
- gboolean has_parent;
+ HasCommonParentData *data;
+ GtkTreePath *parent_path;
+ gboolean has_parent;
- data = (HasCommonParentData *) user_data;
+ data = (HasCommonParentData *) user_data;
- parent_path = gtk_tree_path_copy (path);
- gtk_tree_path_up (parent_path);
+ parent_path = gtk_tree_path_copy (path);
+ gtk_tree_path_up (parent_path);
- has_parent = (gtk_tree_path_get_depth (parent_path) > 0) ? TRUE : FALSE;
+ has_parent = (gtk_tree_path_get_depth (parent_path) > 0) ? TRUE : FALSE;
- if (!has_parent) {
- data->is_root = TRUE;
- }
+ if (!has_parent)
+ {
+ data->is_root = TRUE;
+ }
- if (data->is_common && !data->is_root) {
- if (data->path == NULL) {
- data->path = gtk_tree_path_copy (parent_path);
- } else if (gtk_tree_path_compare (data->path, parent_path) != 0) {
- data->is_common = FALSE;
- }
- }
+ if (data->is_common && !data->is_root)
+ {
+ if (data->path == NULL)
+ {
+ data->path = gtk_tree_path_copy (parent_path);
+ }
+ else if (gtk_tree_path_compare (data->path, parent_path) != 0)
+ {
+ data->is_common = FALSE;
+ }
+ }
- gtk_tree_path_free (parent_path);
+ gtk_tree_path_free (parent_path);
}
static void
tree_selection_has_common_parent (GtkTreeSelection *selection,
- gboolean *is_common,
- gboolean *is_root)
+ gboolean *is_common,
+ gboolean *is_root)
{
- HasCommonParentData data;
+ HasCommonParentData data;
- g_assert (is_common != NULL);
- g_assert (is_root != NULL);
+ g_assert (is_common != NULL);
+ g_assert (is_root != NULL);
- data.path = NULL;
- data.is_common = *is_common = TRUE;
- data.is_root = *is_root = FALSE;
+ data.path = NULL;
+ data.is_common = *is_common = TRUE;
+ data.is_root = *is_root = FALSE;
- gtk_tree_selection_selected_foreach (selection,
- tree_selection_has_common_parent_foreach_func,
- &data);
+ gtk_tree_selection_selected_foreach (selection,
+ tree_selection_has_common_parent_foreach_func,
+ &data);
- *is_common = data.is_common;
- *is_root = data.is_root;
+ *is_common = data.is_common;
+ *is_root = data.is_root;
- if (data.path != NULL) {
- gtk_tree_path_free (data.path);
- }
+ if (data.path != NULL)
+ {
+ gtk_tree_path_free (data.path);
+ }
}
static char *
nautilus_list_view_get_backing_uri (NautilusFilesView *view)
{
- NautilusListView *list_view;
- NautilusListModel *list_model;
- NautilusFile *file;
- GtkTreeView *tree_view;
- GtkTreeSelection *selection;
- GtkTreePath *path;
- GList *paths;
- guint length;
- char *uri;
-
- g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), NULL);
-
- list_view = NAUTILUS_LIST_VIEW (view);
- list_model = list_view->details->model;
- tree_view = list_view->details->tree_view;
-
- g_assert (list_model);
-
- /* We currently handle three common cases here:
- * (a) if the selection contains non-filesystem items (i.e., the
- * "(Empty)" label), we return the uri of the parent.
- * (b) if the selection consists of exactly one _expanded_ directory, we
- * return its URI.
- * (c) if the selection consists of either exactly one item which is not
- * an expanded directory) or multiple items in the same directory,
- * we return the URI of the common parent.
- */
-
- uri = NULL;
-
- selection = gtk_tree_view_get_selection (tree_view);
- length = gtk_tree_selection_count_selected_rows (selection);
-
- if (length == 1) {
-
- paths = gtk_tree_selection_get_selected_rows (selection, NULL);
- path = (GtkTreePath *) paths->data;
-
- file = nautilus_list_model_file_for_path (list_model, path);
- if (file == NULL) {
- /* The selected item is a label, not a file */
- gtk_tree_path_up (path);
- file = nautilus_list_model_file_for_path (list_model, path);
- }
-
- if (file != NULL) {
- if (nautilus_file_is_directory (file) &&
- gtk_tree_view_row_expanded (tree_view, path)) {
- uri = nautilus_file_get_uri (file);
- }
- nautilus_file_unref (file);
- }
+ NautilusListView *list_view;
+ NautilusListModel *list_model;
+ NautilusFile *file;
+ GtkTreeView *tree_view;
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+ GList *paths;
+ guint length;
+ char *uri;
+
+ g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), NULL);
+
+ list_view = NAUTILUS_LIST_VIEW (view);
+ list_model = list_view->details->model;
+ tree_view = list_view->details->tree_view;
+
+ g_assert (list_model);
+
+ /* We currently handle three common cases here:
+ * (a) if the selection contains non-filesystem items (i.e., the
+ * "(Empty)" label), we return the uri of the parent.
+ * (b) if the selection consists of exactly one _expanded_ directory, we
+ * return its URI.
+ * (c) if the selection consists of either exactly one item which is not
+ * an expanded directory) or multiple items in the same directory,
+ * we return the URI of the common parent.
+ */
+
+ uri = NULL;
+
+ selection = gtk_tree_view_get_selection (tree_view);
+ length = gtk_tree_selection_count_selected_rows (selection);
+
+ if (length == 1)
+ {
+ paths = gtk_tree_selection_get_selected_rows (selection, NULL);
+ path = (GtkTreePath *) paths->data;
+
+ file = nautilus_list_model_file_for_path (list_model, path);
+ if (file == NULL)
+ {
+ /* The selected item is a label, not a file */
+ gtk_tree_path_up (path);
+ file = nautilus_list_model_file_for_path (list_model, path);
+ }
- gtk_tree_path_free (path);
- g_list_free (paths);
- }
+ if (file != NULL)
+ {
+ if (nautilus_file_is_directory (file) &&
+ gtk_tree_view_row_expanded (tree_view, path))
+ {
+ uri = nautilus_file_get_uri (file);
+ }
+ nautilus_file_unref (file);
+ }
- if (uri == NULL && length > 0) {
+ gtk_tree_path_free (path);
+ g_list_free (paths);
+ }
- gboolean is_common, is_root;
+ if (uri == NULL && length > 0)
+ {
+ gboolean is_common, is_root;
- /* Check that all the selected items belong to the same
- * directory and that directory is not the root directory (which
- * is handled by NautilusFilesView::get_backing_directory.) */
+ /* Check that all the selected items belong to the same
+ * directory and that directory is not the root directory (which
+ * is handled by NautilusFilesView::get_backing_directory.) */
- tree_selection_has_common_parent (selection, &is_common, &is_root);
+ tree_selection_has_common_parent (selection, &is_common, &is_root);
- if (is_common && !is_root) {
- paths = gtk_tree_selection_get_selected_rows (selection, NULL);
- path = (GtkTreePath *) paths->data;
+ if (is_common && !is_root)
+ {
+ paths = gtk_tree_selection_get_selected_rows (selection, NULL);
+ path = (GtkTreePath *) paths->data;
- file = nautilus_list_model_file_for_path (list_model, path);
- g_assert (file != NULL);
- uri = nautilus_file_get_parent_uri (file);
- nautilus_file_unref (file);
+ file = nautilus_list_model_file_for_path (list_model, path);
+ g_assert (file != NULL);
+ uri = nautilus_file_get_parent_uri (file);
+ nautilus_file_unref (file);
- g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
- }
- }
+ g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
+ }
+ }
- if (uri != NULL) {
- return uri;
- }
+ if (uri != NULL)
+ {
+ return uri;
+ }
- return NAUTILUS_FILES_VIEW_CLASS (nautilus_list_view_parent_class)->get_backing_uri (view);
+ return NAUTILUS_FILES_VIEW_CLASS (nautilus_list_view_parent_class)->get_backing_uri (view);
}
static void
-nautilus_list_view_get_selection_foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
+nautilus_list_view_get_selection_foreach_func (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
{
- GList **list;
- NautilusFile *file;
-
- list = data;
+ GList **list;
+ NautilusFile *file;
+
+ list = data;
- gtk_tree_model_get (model, iter,
- NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
- -1);
+ gtk_tree_model_get (model, iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
- if (file != NULL) {
- (* list) = g_list_prepend ((* list), file);
- }
+ if (file != NULL)
+ {
+ (*list) = g_list_prepend ((*list), file);
+ }
}
static GList *
nautilus_list_view_get_selection (NautilusFilesView *view)
{
- GList *list;
+ GList *list;
- list = NULL;
+ list = NULL;
- gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view),
- nautilus_list_view_get_selection_foreach_func, &list);
+ gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view),
+ nautilus_list_view_get_selection_foreach_func, &list);
- return g_list_reverse (list);
+ return g_list_reverse (list);
}
static void
-nautilus_list_view_get_selection_for_file_transfer_foreach_func (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data)
+nautilus_list_view_get_selection_for_file_transfer_foreach_func (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ gpointer data)
{
- NautilusFile *file;
- struct SelectionForeachData *selection_data;
- GtkTreeIter parent, child;
+ NautilusFile *file;
+ struct SelectionForeachData *selection_data;
+ GtkTreeIter parent, child;
- selection_data = data;
+ selection_data = data;
- gtk_tree_model_get (model, iter,
- NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
- -1);
+ gtk_tree_model_get (model, iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
+
+ if (file != NULL)
+ {
+ /* If the parent folder is also selected, don't include this file in the
+ * file operation, since that would copy it to the toplevel target instead
+ * of keeping it as a child of the copied folder
+ */
+ child = *iter;
+ while (gtk_tree_model_iter_parent (model, &parent, &child))
+ {
+ if (gtk_tree_selection_iter_is_selected (selection_data->selection,
+ &parent))
+ {
+ return;
+ }
+ child = parent;
+ }
- if (file != NULL) {
- /* If the parent folder is also selected, don't include this file in the
- * file operation, since that would copy it to the toplevel target instead
- * of keeping it as a child of the copied folder
- */
- child = *iter;
- while (gtk_tree_model_iter_parent (model, &parent, &child)) {
- if (gtk_tree_selection_iter_is_selected (selection_data->selection,
- &parent)) {
- return;
- }
- child = parent;
- }
-
- nautilus_file_ref (file);
- selection_data->list = g_list_prepend (selection_data->list, file);
- }
+ nautilus_file_ref (file);
+ selection_data->list = g_list_prepend (selection_data->list, file);
+ }
}
static GList *
nautilus_list_view_get_selection_for_file_transfer (NautilusFilesView *view)
{
- struct SelectionForeachData selection_data;
+ struct SelectionForeachData selection_data;
- selection_data.list = NULL;
- selection_data.selection = gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view);
+ selection_data.list = NULL;
+ selection_data.selection = gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view);
- gtk_tree_selection_selected_foreach (selection_data.selection,
- nautilus_list_view_get_selection_for_file_transfer_foreach_func, &selection_data);
+ gtk_tree_selection_selected_foreach (selection_data.selection,
+ nautilus_list_view_get_selection_for_file_transfer_foreach_func, &selection_data);
- return g_list_reverse (selection_data.list);
+ return g_list_reverse (selection_data.list);
}
static gboolean
nautilus_list_view_is_empty (NautilusFilesView *view)
{
- return nautilus_list_model_is_empty (NAUTILUS_LIST_VIEW (view)->details->model);
+ return nautilus_list_model_is_empty (NAUTILUS_LIST_VIEW (view)->details->model);
}
static void
nautilus_list_view_end_file_changes (NautilusFilesView *view)
{
- NautilusListView *list_view;
-
- list_view = NAUTILUS_LIST_VIEW (view);
-
- if (list_view->details->new_selection_path) {
- gtk_tree_view_set_cursor (list_view->details->tree_view,
- list_view->details->new_selection_path,
- NULL, FALSE);
- gtk_tree_path_free (list_view->details->new_selection_path);
- list_view->details->new_selection_path = NULL;
- }
-}
-
-static void
-nautilus_list_view_remove_file (NautilusFilesView *view, NautilusFile *file, NautilusDirectory *directory)
-{
- GtkTreePath *path;
- GtkTreePath *file_path;
- GtkTreeIter iter;
- GtkTreeIter temp_iter;
- GtkTreeRowReference* row_reference;
- NautilusListView *list_view;
- GtkTreeModel* tree_model;
- GtkTreeSelection *selection;
-
- path = NULL;
- row_reference = NULL;
- list_view = NAUTILUS_LIST_VIEW (view);
- tree_model = GTK_TREE_MODEL(list_view->details->model);
-
- if (nautilus_list_model_get_tree_iter_from_file (list_view->details->model, file, directory, &iter)) {
- selection = gtk_tree_view_get_selection (list_view->details->tree_view);
- file_path = gtk_tree_model_get_path (tree_model, &iter);
-
- if (gtk_tree_selection_path_is_selected (selection, file_path)) {
- /* get reference for next element in the list view. If the element to be deleted is the
- * last one, get reference to previous element. If there is only one element in view
- * no need to select anything.
- */
- temp_iter = iter;
-
- if (gtk_tree_model_iter_next (tree_model, &iter)) {
- path = gtk_tree_model_get_path (tree_model, &iter);
- row_reference = gtk_tree_row_reference_new (tree_model, path);
- } else {
- path = gtk_tree_model_get_path (tree_model, &temp_iter);
- if (gtk_tree_path_prev (path)) {
- row_reference = gtk_tree_row_reference_new (tree_model, path);
- }
- }
- gtk_tree_path_free (path);
- }
-
- gtk_tree_path_free (file_path);
-
- nautilus_list_model_remove_file (list_view->details->model, file, directory);
-
- if (gtk_tree_row_reference_valid (row_reference)) {
- if (list_view->details->new_selection_path) {
- gtk_tree_path_free (list_view->details->new_selection_path);
- }
- list_view->details->new_selection_path = gtk_tree_row_reference_get_path (row_reference);
- }
-
- if (row_reference) {
- gtk_tree_row_reference_free (row_reference);
- }
- }
-
-
-}
-
-static void
-nautilus_list_view_set_selection (NautilusFilesView *view, GList *selection)
-{
- NautilusListView *list_view;
- GtkTreeSelection *tree_selection;
- GList *node;
- GList *iters, *l;
- NautilusFile *file;
-
- list_view = NAUTILUS_LIST_VIEW (view);
- tree_selection = gtk_tree_view_get_selection (list_view->details->tree_view);
-
- g_signal_handlers_block_by_func (tree_selection, list_selection_changed_callback, view);
-
- gtk_tree_selection_unselect_all (tree_selection);
- for (node = selection; node != NULL; node = node->next) {
- file = node->data;
- iters = nautilus_list_model_get_all_iters_for_file (list_view->details->model, file);
-
- for (l = iters; l != NULL; l = l->next) {
- gtk_tree_selection_select_iter (tree_selection,
- (GtkTreeIter *)l->data);
- }
- g_list_free_full (iters, g_free);
- }
-
- g_signal_handlers_unblock_by_func (tree_selection, list_selection_changed_callback, view);
- nautilus_files_view_notify_selection_changed (view);
+ NautilusListView *list_view;
+
+ list_view = NAUTILUS_LIST_VIEW (view);
+
+ if (list_view->details->new_selection_path)
+ {
+ gtk_tree_view_set_cursor (list_view->details->tree_view,
+ list_view->details->new_selection_path,
+ NULL, FALSE);
+ gtk_tree_path_free (list_view->details->new_selection_path);
+ list_view->details->new_selection_path = NULL;
+ }
+}
+
+static void
+nautilus_list_view_remove_file (NautilusFilesView *view,
+ NautilusFile *file,
+ NautilusDirectory *directory)
+{
+ GtkTreePath *path;
+ GtkTreePath *file_path;
+ GtkTreeIter iter;
+ GtkTreeIter temp_iter;
+ GtkTreeRowReference *row_reference;
+ NautilusListView *list_view;
+ GtkTreeModel *tree_model;
+ GtkTreeSelection *selection;
+
+ path = NULL;
+ row_reference = NULL;
+ list_view = NAUTILUS_LIST_VIEW (view);
+ tree_model = GTK_TREE_MODEL (list_view->details->model);
+
+ if (nautilus_list_model_get_tree_iter_from_file (list_view->details->model, file, directory, &iter))
+ {
+ selection = gtk_tree_view_get_selection (list_view->details->tree_view);
+ file_path = gtk_tree_model_get_path (tree_model, &iter);
+
+ if (gtk_tree_selection_path_is_selected (selection, file_path))
+ {
+ /* get reference for next element in the list view. If the element to be deleted is the
+ * last one, get reference to previous element. If there is only one element in view
+ * no need to select anything.
+ */
+ temp_iter = iter;
+
+ if (gtk_tree_model_iter_next (tree_model, &iter))
+ {
+ path = gtk_tree_model_get_path (tree_model, &iter);
+ row_reference = gtk_tree_row_reference_new (tree_model, path);
+ }
+ else
+ {
+ path = gtk_tree_model_get_path (tree_model, &temp_iter);
+ if (gtk_tree_path_prev (path))
+ {
+ row_reference = gtk_tree_row_reference_new (tree_model, path);
+ }
+ }
+ gtk_tree_path_free (path);
+ }
+
+ gtk_tree_path_free (file_path);
+
+ nautilus_list_model_remove_file (list_view->details->model, file, directory);
+
+ if (gtk_tree_row_reference_valid (row_reference))
+ {
+ if (list_view->details->new_selection_path)
+ {
+ gtk_tree_path_free (list_view->details->new_selection_path);
+ }
+ list_view->details->new_selection_path = gtk_tree_row_reference_get_path (row_reference);
+ }
+
+ if (row_reference)
+ {
+ gtk_tree_row_reference_free (row_reference);
+ }
+ }
+}
+
+static void
+nautilus_list_view_set_selection (NautilusFilesView *view,
+ GList *selection)
+{
+ NautilusListView *list_view;
+ GtkTreeSelection *tree_selection;
+ GList *node;
+ GList *iters, *l;
+ NautilusFile *file;
+
+ list_view = NAUTILUS_LIST_VIEW (view);
+ tree_selection = gtk_tree_view_get_selection (list_view->details->tree_view);
+
+ g_signal_handlers_block_by_func (tree_selection, list_selection_changed_callback, view);
+
+ gtk_tree_selection_unselect_all (tree_selection);
+ for (node = selection; node != NULL; node = node->next)
+ {
+ file = node->data;
+ iters = nautilus_list_model_get_all_iters_for_file (list_view->details->model, file);
+
+ for (l = iters; l != NULL; l = l->next)
+ {
+ gtk_tree_selection_select_iter (tree_selection,
+ (GtkTreeIter *) l->data);
+ }
+ g_list_free_full (iters, g_free);
+ }
+
+ g_signal_handlers_unblock_by_func (tree_selection, list_selection_changed_callback, view);
+ nautilus_files_view_notify_selection_changed (view);
}
static void
nautilus_list_view_invert_selection (NautilusFilesView *view)
{
- NautilusListView *list_view;
- GtkTreeSelection *tree_selection;
- GList *node;
- GList *iters, *l;
- NautilusFile *file;
- GList *selection = NULL;
-
- list_view = NAUTILUS_LIST_VIEW (view);
- tree_selection = gtk_tree_view_get_selection (list_view->details->tree_view);
+ NautilusListView *list_view;
+ GtkTreeSelection *tree_selection;
+ GList *node;
+ GList *iters, *l;
+ NautilusFile *file;
+ GList *selection = NULL;
+
+ list_view = NAUTILUS_LIST_VIEW (view);
+ tree_selection = gtk_tree_view_get_selection (list_view->details->tree_view);
+
+ g_signal_handlers_block_by_func (tree_selection, list_selection_changed_callback, view);
- g_signal_handlers_block_by_func (tree_selection, list_selection_changed_callback, view);
-
- gtk_tree_selection_selected_foreach (tree_selection,
- nautilus_list_view_get_selection_foreach_func, &selection);
+ gtk_tree_selection_selected_foreach (tree_selection,
+ nautilus_list_view_get_selection_foreach_func, &selection);
- gtk_tree_selection_select_all (tree_selection);
-
- for (node = selection; node != NULL; node = node->next) {
- file = node->data;
- iters = nautilus_list_model_get_all_iters_for_file (list_view->details->model, file);
+ gtk_tree_selection_select_all (tree_selection);
- for (l = iters; l != NULL; l = l->next) {
- gtk_tree_selection_unselect_iter (tree_selection,
- (GtkTreeIter *)l->data);
- }
- g_list_free_full (iters, g_free);
- }
+ for (node = selection; node != NULL; node = node->next)
+ {
+ file = node->data;
+ iters = nautilus_list_model_get_all_iters_for_file (list_view->details->model, file);
- g_list_free (selection);
+ for (l = iters; l != NULL; l = l->next)
+ {
+ gtk_tree_selection_unselect_iter (tree_selection,
+ (GtkTreeIter *) l->data);
+ }
+ g_list_free_full (iters, g_free);
+ }
+
+ g_list_free (selection);
- g_signal_handlers_unblock_by_func (tree_selection, list_selection_changed_callback, view);
- nautilus_files_view_notify_selection_changed (view);
+ g_signal_handlers_unblock_by_func (tree_selection, list_selection_changed_callback, view);
+ nautilus_files_view_notify_selection_changed (view);
}
static void
nautilus_list_view_select_all (NautilusFilesView *view)
{
- gtk_tree_selection_select_all (gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view));
+ gtk_tree_selection_select_all (gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view));
}
static void
nautilus_list_view_select_first (NautilusFilesView *view)
{
- GtkTreeSelection *selection;
- GtkTreeIter iter;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
- if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (NAUTILUS_LIST_VIEW (view)->details->model), &iter)) {
- return;
- }
- selection = gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view);
- gtk_tree_selection_unselect_all (selection);
- gtk_tree_selection_select_iter (selection, &iter);
+ if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (NAUTILUS_LIST_VIEW (view)->details->model), &iter))
+ {
+ return;
+ }
+ selection = gtk_tree_view_get_selection (NAUTILUS_LIST_VIEW (view)->details->tree_view);
+ gtk_tree_selection_unselect_all (selection);
+ gtk_tree_selection_select_iter (selection, &iter);
}
static void
nautilus_list_view_zoom_to_level (NautilusFilesView *view,
- gint zoom_level)
+ gint zoom_level)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
- list_view = NAUTILUS_LIST_VIEW (view);
+ list_view = NAUTILUS_LIST_VIEW (view);
- if (list_view->details->zoom_level == zoom_level) {
- return;
- }
+ if (list_view->details->zoom_level == zoom_level)
+ {
+ return;
+ }
- nautilus_list_view_set_zoom_level (list_view, zoom_level);
- g_action_group_change_action_state (nautilus_files_view_get_action_group (view),
- "zoom-to-level", g_variant_new_int32 (zoom_level));
+ nautilus_list_view_set_zoom_level (list_view, zoom_level);
+ g_action_group_change_action_state (nautilus_files_view_get_action_group (view),
+ "zoom-to-level", g_variant_new_int32 (zoom_level));
- nautilus_files_view_update_toolbar_menus (view);
+ nautilus_files_view_update_toolbar_menus (view);
}
static void
action_zoom_to_level (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusFilesView *view;
- NautilusListZoomLevel zoom_level;
+ NautilusFilesView *view;
+ NautilusListZoomLevel zoom_level;
- g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
+ g_assert (NAUTILUS_IS_FILES_VIEW (user_data));
- view = NAUTILUS_FILES_VIEW (user_data);
- zoom_level = g_variant_get_int32 (state);
- nautilus_list_view_zoom_to_level (view, zoom_level);
+ view = NAUTILUS_FILES_VIEW (user_data);
+ zoom_level = g_variant_get_int32 (state);
+ nautilus_list_view_zoom_to_level (view, zoom_level);
- g_simple_action_set_state (G_SIMPLE_ACTION (action), state);
- if (g_settings_get_enum (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL) != zoom_level) {
- g_settings_set_enum (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL,
- zoom_level);
- }
+ g_simple_action_set_state (G_SIMPLE_ACTION (action), state);
+ if (g_settings_get_enum (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL) != zoom_level)
+ {
+ g_settings_set_enum (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL,
+ zoom_level);
+ }
}
static void
-column_editor_response_callback (GtkWidget *dialog,
- int response_id,
- gpointer user_data)
+column_editor_response_callback (GtkWidget *dialog,
+ int response_id,
+ gpointer user_data)
{
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
column_chooser_changed_callback (NautilusColumnChooser *chooser,
- NautilusListView *view)
+ NautilusListView *view)
{
- NautilusFile *file;
- char **visible_columns;
- char **column_order;
- GList *list;
- int i;
+ NautilusFile *file;
+ char **visible_columns;
+ char **column_order;
+ GList *list;
+ int i;
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
- nautilus_column_chooser_get_settings (chooser,
- &visible_columns,
- &column_order);
+ nautilus_column_chooser_get_settings (chooser,
+ &visible_columns,
+ &column_order);
- list = NULL;
- for (i = 0; visible_columns[i] != NULL; ++i) {
- list = g_list_prepend (list, visible_columns[i]);
- }
- list = g_list_reverse (list);
- nautilus_file_set_metadata_list (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
- list);
- g_list_free (list);
+ list = NULL;
+ for (i = 0; visible_columns[i] != NULL; ++i)
+ {
+ list = g_list_prepend (list, visible_columns[i]);
+ }
+ list = g_list_reverse (list);
+ nautilus_file_set_metadata_list (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
+ list);
+ g_list_free (list);
- list = NULL;
- for (i = 0; column_order[i] != NULL; ++i) {
- list = g_list_prepend (list, column_order[i]);
- }
- list = g_list_reverse (list);
- nautilus_file_set_metadata_list (file,
- NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER,
- list);
- g_list_free (list);
+ list = NULL;
+ for (i = 0; column_order[i] != NULL; ++i)
+ {
+ list = g_list_prepend (list, column_order[i]);
+ }
+ list = g_list_reverse (list);
+ nautilus_file_set_metadata_list (file,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER,
+ list);
+ g_list_free (list);
- apply_columns_settings (view, column_order, visible_columns);
+ apply_columns_settings (view, column_order, visible_columns);
- g_strfreev (visible_columns);
- g_strfreev (column_order);
+ g_strfreev (visible_columns);
+ g_strfreev (column_order);
}
static void
-column_chooser_set_from_arrays (NautilusColumnChooser *chooser,
- NautilusListView *view,
- char **visible_columns,
- char **column_order)
+column_chooser_set_from_arrays (NautilusColumnChooser *chooser,
+ NautilusListView *view,
+ char **visible_columns,
+ char **column_order)
{
- g_signal_handlers_block_by_func
- (chooser, G_CALLBACK (column_chooser_changed_callback), view);
+ g_signal_handlers_block_by_func
+ (chooser, G_CALLBACK (column_chooser_changed_callback), view);
- nautilus_column_chooser_set_settings (chooser,
- visible_columns,
- column_order);
+ nautilus_column_chooser_set_settings (chooser,
+ visible_columns,
+ column_order);
- g_signal_handlers_unblock_by_func
- (chooser, G_CALLBACK (column_chooser_changed_callback), view);
+ g_signal_handlers_unblock_by_func
+ (chooser, G_CALLBACK (column_chooser_changed_callback), view);
}
static void
column_chooser_set_from_settings (NautilusColumnChooser *chooser,
- NautilusListView *view)
+ NautilusListView *view)
{
- char **visible_columns;
- char **column_order;
+ char **visible_columns;
+ char **column_order;
- visible_columns = get_visible_columns (view);
- column_order = get_column_order (view);
+ visible_columns = get_visible_columns (view);
+ column_order = get_column_order (view);
- column_chooser_set_from_arrays (chooser, view,
- visible_columns, column_order);
+ column_chooser_set_from_arrays (chooser, view,
+ visible_columns, column_order);
- g_strfreev (visible_columns);
- g_strfreev (column_order);
+ g_strfreev (visible_columns);
+ g_strfreev (column_order);
}
static void
column_chooser_use_default_callback (NautilusColumnChooser *chooser,
- NautilusListView *view)
+ NautilusListView *view)
{
- NautilusFile *file;
- char **default_columns;
- char **default_order;
+ NautilusFile *file;
+ char **default_columns;
+ char **default_order;
- file = nautilus_files_view_get_directory_as_file
- (NAUTILUS_FILES_VIEW (view));
+ file = nautilus_files_view_get_directory_as_file
+ (NAUTILUS_FILES_VIEW (view));
- nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER, NULL);
- nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS, NULL);
+ nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER, NULL);
+ nautilus_file_set_metadata_list (file, NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS, NULL);
- /* set view values ourselves, as new metadata could not have been
- * updated yet.
- */
- default_columns = get_default_visible_columns (view);
- default_order = get_default_column_order (view);
+ /* set view values ourselves, as new metadata could not have been
+ * updated yet.
+ */
+ default_columns = get_default_visible_columns (view);
+ default_order = get_default_column_order (view);
- apply_columns_settings (view, default_order, default_columns);
- column_chooser_set_from_arrays (chooser, view,
- default_columns, default_order);
+ apply_columns_settings (view, default_order, default_columns);
+ column_chooser_set_from_arrays (chooser, view,
+ default_columns, default_order);
- g_strfreev (default_columns);
- g_strfreev (default_order);
+ g_strfreev (default_columns);
+ g_strfreev (default_order);
}
static GtkWidget *
create_column_editor (NautilusListView *view)
{
- GtkWidget *window;
- GtkWidget *label;
- GtkWidget *box;
- GtkWidget *column_chooser;
- NautilusFile *file;
- char *str;
- char *name;
- const char *label_text;
-
- file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
- name = nautilus_file_get_display_name (file);
- str = g_strdup_printf (_("%s Visible Columns"), name);
- g_free (name);
-
- window = gtk_dialog_new_with_buttons (str,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
- NULL, NULL);
- g_free (str);
- g_signal_connect (window, "response",
- G_CALLBACK (column_editor_response_callback), NULL);
-
- gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
-
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_container_set_border_width (GTK_CONTAINER (box), 12);
- gtk_widget_set_hexpand (box, TRUE);
- gtk_widget_show (box);
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))), box,
- TRUE, TRUE, 0);
-
- label_text = _("Choose the order of information to appear in this folder:");
- str = g_strconcat ("<b>", label_text, "</b>", NULL);
- label = gtk_label_new (NULL);
- gtk_label_set_markup (GTK_LABEL (label), str);
- gtk_label_set_line_wrap (GTK_LABEL (label), FALSE);
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_label_set_yalign (GTK_LABEL (label), 0);
- gtk_widget_show (label);
- gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
-
- g_free (str);
-
- column_chooser = nautilus_column_chooser_new (file);
- gtk_widget_set_margin_start (column_chooser, 12);
- gtk_widget_show (column_chooser);
- gtk_box_pack_start (GTK_BOX (box), column_chooser, TRUE, TRUE, 0);
-
- g_signal_connect (column_chooser, "changed",
- G_CALLBACK (column_chooser_changed_callback),
- view);
- g_signal_connect (column_chooser, "use-default",
- G_CALLBACK (column_chooser_use_default_callback),
- view);
-
- column_chooser_set_from_settings
- (NAUTILUS_COLUMN_CHOOSER (column_chooser), view);
-
- return window;
+ GtkWidget *window;
+ GtkWidget *label;
+ GtkWidget *box;
+ GtkWidget *column_chooser;
+ NautilusFile *file;
+ char *str;
+ char *name;
+ const char *label_text;
+
+ file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view));
+ name = nautilus_file_get_display_name (file);
+ str = g_strdup_printf (_("%s Visible Columns"), name);
+ g_free (name);
+
+ window = gtk_dialog_new_with_buttons (str,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
+ NULL, NULL);
+ g_free (str);
+ g_signal_connect (window, "response",
+ G_CALLBACK (column_editor_response_callback), NULL);
+
+ gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 12);
+ gtk_widget_set_hexpand (box, TRUE);
+ gtk_widget_show (box);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))), box,
+ TRUE, TRUE, 0);
+
+ label_text = _("Choose the order of information to appear in this folder:");
+ str = g_strconcat ("<b>", label_text, "</b>", NULL);
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label), str);
+ gtk_label_set_line_wrap (GTK_LABEL (label), FALSE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_label_set_yalign (GTK_LABEL (label), 0);
+ gtk_widget_show (label);
+ gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+
+ g_free (str);
+
+ column_chooser = nautilus_column_chooser_new (file);
+ gtk_widget_set_margin_start (column_chooser, 12);
+ gtk_widget_show (column_chooser);
+ gtk_box_pack_start (GTK_BOX (box), column_chooser, TRUE, TRUE, 0);
+
+ g_signal_connect (column_chooser, "changed",
+ G_CALLBACK (column_chooser_changed_callback),
+ view);
+ g_signal_connect (column_chooser, "use-default",
+ G_CALLBACK (column_chooser_use_default_callback),
+ view);
+
+ column_chooser_set_from_settings
+ (NAUTILUS_COLUMN_CHOOSER (column_chooser), view);
+
+ return window;
}
static void
action_visible_columns (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
-{
- NautilusListView *list_view;
-
- list_view = NAUTILUS_LIST_VIEW (user_data);
-
- if (list_view->details->column_editor) {
- gtk_window_present (GTK_WINDOW (list_view->details->column_editor));
- } else {
- list_view->details->column_editor = create_column_editor (list_view);
- g_object_add_weak_pointer (G_OBJECT (list_view->details->column_editor),
- (gpointer *) &list_view->details->column_editor);
-
- gtk_widget_show (list_view->details->column_editor);
- }
-}
-
-const GActionEntry list_view_entries[] = {
- { "visible-columns", action_visible_columns },
- { "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
+ GVariant *state,
+ gpointer user_data)
+{
+ NautilusListView *list_view;
+
+ list_view = NAUTILUS_LIST_VIEW (user_data);
+
+ if (list_view->details->column_editor)
+ {
+ gtk_window_present (GTK_WINDOW (list_view->details->column_editor));
+ }
+ else
+ {
+ list_view->details->column_editor = create_column_editor (list_view);
+ g_object_add_weak_pointer (G_OBJECT (list_view->details->column_editor),
+ (gpointer *) &list_view->details->column_editor);
+
+ gtk_widget_show (list_view->details->column_editor);
+ }
+}
+
+const GActionEntry list_view_entries[] =
+{
+ { "visible-columns", action_visible_columns },
+ { "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
};
static void
-nautilus_list_view_set_zoom_level (NautilusListView *view,
- NautilusListZoomLevel new_level)
+nautilus_list_view_set_zoom_level (NautilusListView *view,
+ NautilusListZoomLevel new_level)
{
- int column;
+ int column;
- g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
- g_return_if_fail (new_level >= NAUTILUS_LIST_ZOOM_LEVEL_SMALL &&
- new_level <= NAUTILUS_LIST_ZOOM_LEVEL_LARGER);
+ g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
+ g_return_if_fail (new_level >= NAUTILUS_LIST_ZOOM_LEVEL_SMALL &&
+ new_level <= NAUTILUS_LIST_ZOOM_LEVEL_LARGER);
- if (view->details->zoom_level == new_level) {
- return;
- }
+ if (view->details->zoom_level == new_level)
+ {
+ return;
+ }
- view->details->zoom_level = new_level;
+ view->details->zoom_level = new_level;
- /* Select correctly scaled icons. */
- column = nautilus_list_model_get_column_id_from_zoom_level (new_level);
- gtk_tree_view_column_set_attributes (view->details->file_name_column,
- GTK_CELL_RENDERER (view->details->pixbuf_cell),
- "surface", column,
- NULL);
- set_up_pixbuf_size (view);
+ /* Select correctly scaled icons. */
+ column = nautilus_list_model_get_column_id_from_zoom_level (new_level);
+ gtk_tree_view_column_set_attributes (view->details->file_name_column,
+ GTK_CELL_RENDERER (view->details->pixbuf_cell),
+ "surface", column,
+ NULL);
+ set_up_pixbuf_size (view);
}
static void
-nautilus_list_view_bump_zoom_level (NautilusFilesView *view, int zoom_increment)
+nautilus_list_view_bump_zoom_level (NautilusFilesView *view,
+ int zoom_increment)
{
- NautilusListView *list_view;
- gint new_level;
+ NautilusListView *list_view;
+ gint new_level;
- g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
+ g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
- list_view = NAUTILUS_LIST_VIEW (view);
- new_level = list_view->details->zoom_level + zoom_increment;
+ list_view = NAUTILUS_LIST_VIEW (view);
+ new_level = list_view->details->zoom_level + zoom_increment;
- if (new_level >= NAUTILUS_LIST_ZOOM_LEVEL_SMALL &&
- new_level <= NAUTILUS_LIST_ZOOM_LEVEL_LARGER) {
- nautilus_list_view_zoom_to_level (view, new_level);
- }
+ if (new_level >= NAUTILUS_LIST_ZOOM_LEVEL_SMALL &&
+ new_level <= NAUTILUS_LIST_ZOOM_LEVEL_LARGER)
+ {
+ nautilus_list_view_zoom_to_level (view, new_level);
+ }
}
static void
nautilus_list_view_restore_standard_zoom_level (NautilusFilesView *view)
{
- nautilus_list_view_zoom_to_level (view, NAUTILUS_LIST_ZOOM_LEVEL_STANDARD);
+ nautilus_list_view_zoom_to_level (view, NAUTILUS_LIST_ZOOM_LEVEL_STANDARD);
}
-static gboolean
-nautilus_list_view_can_zoom_in (NautilusFilesView *view)
+static gboolean
+nautilus_list_view_can_zoom_in (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), FALSE);
- return NAUTILUS_LIST_VIEW (view)->details->zoom_level < NAUTILUS_LIST_ZOOM_LEVEL_LARGER;
+ return NAUTILUS_LIST_VIEW (view)->details->zoom_level < NAUTILUS_LIST_ZOOM_LEVEL_LARGER;
}
-static gboolean
-nautilus_list_view_can_zoom_out (NautilusFilesView *view)
+static gboolean
+nautilus_list_view_can_zoom_out (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), FALSE);
- return NAUTILUS_LIST_VIEW (view)->details->zoom_level > NAUTILUS_LIST_ZOOM_LEVEL_SMALL;
+ return NAUTILUS_LIST_VIEW (view)->details->zoom_level > NAUTILUS_LIST_ZOOM_LEVEL_SMALL;
}
static gfloat
nautilus_list_view_get_zoom_level_percentage (NautilusFilesView *view)
{
- NautilusListView *list_view;
- guint icon_size;
+ NautilusListView *list_view;
+ guint icon_size;
- g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), 1.0);
+ g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), 1.0);
- list_view = NAUTILUS_LIST_VIEW (view);
- icon_size = nautilus_list_model_get_icon_size_for_zoom_level (list_view->details->zoom_level);
+ list_view = NAUTILUS_LIST_VIEW (view);
+ icon_size = nautilus_list_model_get_icon_size_for_zoom_level (list_view->details->zoom_level);
- return (gfloat) icon_size / NAUTILUS_LIST_ICON_SIZE_STANDARD;
+ return (gfloat) icon_size / NAUTILUS_LIST_ICON_SIZE_STANDARD;
}
static void
nautilus_list_view_click_policy_changed (NautilusFilesView *directory_view)
{
- GdkWindow *win;
- GdkDisplay *display;
- NautilusListView *view;
- GtkTreeIter iter;
- GtkTreeView *tree;
-
- view = NAUTILUS_LIST_VIEW (directory_view);
- display = gtk_widget_get_display (GTK_WIDGET (view));
-
- /* ensure that we unset the hand cursor and refresh underlined rows */
- if (get_click_policy () == NAUTILUS_CLICK_POLICY_DOUBLE) {
- if (view->details->hover_path != NULL) {
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (view->details->model),
- &iter, view->details->hover_path)) {
- gtk_tree_model_row_changed (GTK_TREE_MODEL (view->details->model),
- view->details->hover_path, &iter);
- }
-
- gtk_tree_path_free (view->details->hover_path);
- view->details->hover_path = NULL;
- }
+ GdkWindow *win;
+ GdkDisplay *display;
+ NautilusListView *view;
+ GtkTreeIter iter;
+ GtkTreeView *tree;
+
+ view = NAUTILUS_LIST_VIEW (directory_view);
+ display = gtk_widget_get_display (GTK_WIDGET (view));
+
+ /* ensure that we unset the hand cursor and refresh underlined rows */
+ if (get_click_policy () == NAUTILUS_CLICK_POLICY_DOUBLE)
+ {
+ if (view->details->hover_path != NULL)
+ {
+ if (gtk_tree_model_get_iter (GTK_TREE_MODEL (view->details->model),
+ &iter, view->details->hover_path))
+ {
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (view->details->model),
+ view->details->hover_path, &iter);
+ }
+
+ gtk_tree_path_free (view->details->hover_path);
+ view->details->hover_path = NULL;
+ }
- tree = view->details->tree_view;
- if (gtk_widget_get_realized (GTK_WIDGET (tree))) {
- win = gtk_widget_get_window (GTK_WIDGET (tree));
- gdk_window_set_cursor (win, NULL);
+ tree = view->details->tree_view;
+ if (gtk_widget_get_realized (GTK_WIDGET (tree)))
+ {
+ win = gtk_widget_get_window (GTK_WIDGET (tree));
+ gdk_window_set_cursor (win, NULL);
- if (display != NULL) {
- gdk_display_flush (display);
- }
- }
+ if (display != NULL)
+ {
+ gdk_display_flush (display);
+ }
+ }
- g_clear_object (&hand_cursor);
- } else if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE) {
- if (hand_cursor == NULL) {
- hand_cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
- }
- }
+ g_clear_object (&hand_cursor);
+ }
+ else if (get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+ {
+ if (hand_cursor == NULL)
+ {
+ hand_cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
+ }
+ }
}
static void
default_sort_order_changed_callback (gpointer callback_data)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (callback_data);
+ list_view = NAUTILUS_LIST_VIEW (callback_data);
- set_sort_order_from_metadata_and_preferences (list_view);
+ set_sort_order_from_metadata_and_preferences (list_view);
}
static void
default_visible_columns_changed_callback (gpointer callback_data)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (callback_data);
+ list_view = NAUTILUS_LIST_VIEW (callback_data);
- set_columns_settings_from_metadata_and_preferences (list_view);
+ set_columns_settings_from_metadata_and_preferences (list_view);
}
static void
default_column_order_changed_callback (gpointer callback_data)
{
- NautilusListView *list_view;
-
- list_view = NAUTILUS_LIST_VIEW (callback_data);
+ NautilusListView *list_view;
+
+ list_view = NAUTILUS_LIST_VIEW (callback_data);
- set_columns_settings_from_metadata_and_preferences (list_view);
+ set_columns_settings_from_metadata_and_preferences (list_view);
}
static void
nautilus_list_view_sort_directories_first_changed (NautilusFilesView *view)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (view);
+ list_view = NAUTILUS_LIST_VIEW (view);
- nautilus_list_model_set_should_sort_directories_first (list_view->details->model,
- nautilus_files_view_should_sort_directories_first (view));
+ nautilus_list_model_set_should_sort_directories_first (list_view->details->model,
+ nautilus_files_view_should_sort_directories_first (view));
}
static int
-nautilus_list_view_compare_files (NautilusFilesView *view, NautilusFile *file1, NautilusFile *file2)
+nautilus_list_view_compare_files (NautilusFilesView *view,
+ NautilusFile *file1,
+ NautilusFile *file2)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (view);
- return nautilus_list_model_compare_func (list_view->details->model, file1, file2);
+ list_view = NAUTILUS_LIST_VIEW (view);
+ return nautilus_list_model_compare_func (list_view->details->model, file1, file2);
}
static gboolean
nautilus_list_view_using_manual_layout (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), FALSE);
- return FALSE;
+ return FALSE;
}
static void
nautilus_list_view_dispose (GObject *object)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (object);
+ list_view = NAUTILUS_LIST_VIEW (object);
- if (list_view->details->model) {
- g_object_unref (list_view->details->model);
- list_view->details->model = NULL;
- }
+ if (list_view->details->model)
+ {
+ g_object_unref (list_view->details->model);
+ list_view->details->model = NULL;
+ }
- if (list_view->details->drag_dest) {
- g_object_unref (list_view->details->drag_dest);
- list_view->details->drag_dest = NULL;
- }
+ if (list_view->details->drag_dest)
+ {
+ g_object_unref (list_view->details->drag_dest);
+ list_view->details->drag_dest = NULL;
+ }
- if (list_view->details->clipboard_handler_id != 0) {
- g_signal_handler_disconnect (nautilus_clipboard_monitor_get (),
- list_view->details->clipboard_handler_id);
- list_view->details->clipboard_handler_id = 0;
- }
+ if (list_view->details->clipboard_handler_id != 0)
+ {
+ g_signal_handler_disconnect (nautilus_clipboard_monitor_get (),
+ list_view->details->clipboard_handler_id);
+ list_view->details->clipboard_handler_id = 0;
+ }
- G_OBJECT_CLASS (nautilus_list_view_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_list_view_parent_class)->dispose (object);
}
static void
nautilus_list_view_finalize (GObject *object)
{
- NautilusListView *list_view;
+ NautilusListView *list_view;
- list_view = NAUTILUS_LIST_VIEW (object);
+ list_view = NAUTILUS_LIST_VIEW (object);
- g_free (list_view->details->original_name);
- list_view->details->original_name = NULL;
-
- if (list_view->details->double_click_path[0]) {
- gtk_tree_path_free (list_view->details->double_click_path[0]);
- }
- if (list_view->details->double_click_path[1]) {
- gtk_tree_path_free (list_view->details->double_click_path[1]);
- }
- if (list_view->details->new_selection_path) {
- gtk_tree_path_free (list_view->details->new_selection_path);
- }
-
- g_list_free (list_view->details->cells);
- g_hash_table_destroy (list_view->details->columns);
+ g_free (list_view->details->original_name);
+ list_view->details->original_name = NULL;
- if (list_view->details->hover_path != NULL) {
- gtk_tree_path_free (list_view->details->hover_path);
- }
+ if (list_view->details->double_click_path[0])
+ {
+ gtk_tree_path_free (list_view->details->double_click_path[0]);
+ }
+ if (list_view->details->double_click_path[1])
+ {
+ gtk_tree_path_free (list_view->details->double_click_path[1]);
+ }
+ if (list_view->details->new_selection_path)
+ {
+ gtk_tree_path_free (list_view->details->new_selection_path);
+ }
- if (list_view->details->column_editor != NULL) {
- gtk_widget_destroy (list_view->details->column_editor);
- }
+ g_list_free (list_view->details->cells);
+ g_hash_table_destroy (list_view->details->columns);
- g_clear_object (&list_view->details->icon);
+ if (list_view->details->hover_path != NULL)
+ {
+ gtk_tree_path_free (list_view->details->hover_path);
+ }
- g_free (list_view->details);
+ if (list_view->details->column_editor != NULL)
+ {
+ gtk_widget_destroy (list_view->details->column_editor);
+ }
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- default_sort_order_changed_callback,
- list_view);
- g_signal_handlers_disconnect_by_func (nautilus_list_view_preferences,
- default_visible_columns_changed_callback,
- list_view);
- g_signal_handlers_disconnect_by_func (nautilus_list_view_preferences,
- default_column_order_changed_callback,
- list_view);
+ g_clear_object (&list_view->details->icon);
- G_OBJECT_CLASS (nautilus_list_view_parent_class)->finalize (object);
+ g_free (list_view->details);
+
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ default_sort_order_changed_callback,
+ list_view);
+ g_signal_handlers_disconnect_by_func (nautilus_list_view_preferences,
+ default_visible_columns_changed_callback,
+ list_view);
+ g_signal_handlers_disconnect_by_func (nautilus_list_view_preferences,
+ default_column_order_changed_callback,
+ list_view);
+
+ G_OBJECT_CLASS (nautilus_list_view_parent_class)->finalize (object);
}
static char *
nautilus_list_view_get_first_visible_file (NautilusFilesView *view)
{
- NautilusFile *file;
- GtkTreePath *path;
- GtkTreeIter iter;
- NautilusListView *list_view;
-
- list_view = NAUTILUS_LIST_VIEW (view);
-
- if (gtk_tree_view_get_path_at_pos (list_view->details->tree_view,
- 0, 0,
- &path, NULL, NULL, NULL)) {
- gtk_tree_model_get_iter (GTK_TREE_MODEL (list_view->details->model),
- &iter, path);
-
- gtk_tree_path_free (path);
-
- gtk_tree_model_get (GTK_TREE_MODEL (list_view->details->model),
- &iter,
- NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
- -1);
- if (file) {
- char *uri;
-
- uri = nautilus_file_get_uri (file);
-
- nautilus_file_unref (file);
-
- return uri;
- }
- }
-
- return NULL;
+ NautilusFile *file;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ NautilusListView *list_view;
+
+ list_view = NAUTILUS_LIST_VIEW (view);
+
+ if (gtk_tree_view_get_path_at_pos (list_view->details->tree_view,
+ 0, 0,
+ &path, NULL, NULL, NULL))
+ {
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (list_view->details->model),
+ &iter, path);
+
+ gtk_tree_path_free (path);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (list_view->details->model),
+ &iter,
+ NAUTILUS_LIST_MODEL_FILE_COLUMN, &file,
+ -1);
+ if (file)
+ {
+ char *uri;
+
+ uri = nautilus_file_get_uri (file);
+
+ nautilus_file_unref (file);
+
+ return uri;
+ }
+ }
+
+ return NULL;
}
static void
nautilus_list_view_scroll_to_file (NautilusListView *view,
- NautilusFile *file)
+ NautilusFile *file)
{
- GtkTreePath *path;
- GtkTreeIter iter;
-
- if (!nautilus_list_model_get_first_iter_for_file (view->details->model, file, &iter)) {
- return;
- }
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (view->details->model), &iter);
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ if (!nautilus_list_model_get_first_iter_for_file (view->details->model, file, &iter))
+ {
+ return;
+ }
- gtk_tree_view_scroll_to_cell (view->details->tree_view,
- path, NULL,
- TRUE, 0.0, 0.0);
-
- gtk_tree_path_free (path);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (view->details->model), &iter);
+
+ gtk_tree_view_scroll_to_cell (view->details->tree_view,
+ path, NULL,
+ TRUE, 0.0, 0.0);
+
+ gtk_tree_path_free (path);
}
static void
list_view_scroll_to_file (NautilusFilesView *view,
- const char *uri)
-{
- NautilusFile *file;
-
- if (uri != NULL) {
- /* Only if existing, since we don't want to add the file to
- the directory if it has been removed since then */
- file = nautilus_file_get_existing_by_uri (uri);
- if (file != NULL) {
- nautilus_list_view_scroll_to_file (NAUTILUS_LIST_VIEW (view), file);
- nautilus_file_unref (file);
- }
- }
+ const char *uri)
+{
+ NautilusFile *file;
+
+ if (uri != NULL)
+ {
+ /* Only if existing, since we don't want to add the file to
+ * the directory if it has been removed since then */
+ file = nautilus_file_get_existing_by_uri (uri);
+ if (file != NULL)
+ {
+ nautilus_list_view_scroll_to_file (NAUTILUS_LIST_VIEW (view), file);
+ nautilus_file_unref (file);
+ }
+ }
}
static void
list_view_notify_clipboard_info (NautilusClipboardMonitor *monitor,
- NautilusClipboardInfo *info,
- NautilusListView *view)
+ NautilusClipboardInfo *info,
+ NautilusListView *view)
{
- /* this could be called as a result of _end_loading() being
- * called after _dispose(), where the model is cleared.
- */
- if (view->details->model == NULL) {
- return;
- }
+ /* this could be called as a result of _end_loading() being
+ * called after _dispose(), where the model is cleared.
+ */
+ if (view->details->model == NULL)
+ {
+ return;
+ }
- if (info != NULL && info->cut) {
- nautilus_list_model_set_highlight_for_files (view->details->model, info->files);
- } else {
- nautilus_list_model_set_highlight_for_files (view->details->model, NULL);
- }
+ if (info != NULL && info->cut)
+ {
+ nautilus_list_model_set_highlight_for_files (view->details->model, info->files);
+ }
+ else
+ {
+ nautilus_list_model_set_highlight_for_files (view->details->model, NULL);
+ }
}
static void
nautilus_list_view_end_loading (NautilusFilesView *view,
- gboolean all_files_seen)
+ gboolean all_files_seen)
{
- NautilusClipboardMonitor *monitor;
- NautilusClipboardInfo *info;
+ NautilusClipboardMonitor *monitor;
+ NautilusClipboardInfo *info;
- monitor = nautilus_clipboard_monitor_get ();
- info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
+ monitor = nautilus_clipboard_monitor_get ();
+ info = nautilus_clipboard_monitor_get_clipboard_info (monitor);
- list_view_notify_clipboard_info (monitor, info, NAUTILUS_LIST_VIEW (view));
+ list_view_notify_clipboard_info (monitor, info, NAUTILUS_LIST_VIEW (view));
}
static guint
nautilus_list_view_get_id (NautilusFilesView *view)
{
- return NAUTILUS_VIEW_LIST_ID;
+ return NAUTILUS_VIEW_LIST_ID;
}
-static GdkRectangle*
+static GdkRectangle *
nautilus_list_view_compute_rename_popover_pointing_to (NautilusFilesView *view)
{
- GtkTreeSelection *selection;
- GtkTreePath *path;
- GdkRectangle *rect;
- GtkTreeModel *model;
- GtkTreeView *tree_view;
- GList *list;
- NautilusListView *list_view;
-
- rect = g_malloc0 (sizeof(GdkRectangle));
- list_view = NAUTILUS_LIST_VIEW (view);
- tree_view = list_view->details->tree_view;
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view->details->tree_view));
- model = GTK_TREE_MODEL (list_view->details->model);
- list = gtk_tree_selection_get_selected_rows (selection, &model);
- path = list->data;
- gtk_tree_view_get_cell_area (tree_view, path, NULL, rect);
- gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
- rect->x, rect->y,
- &rect->x, &rect->y);
-
- if (list_view->details->last_event_button_x > 0) {
- rect->x = list_view->details->last_event_button_x;
- } else {
- rect->x = CLAMP (gtk_tree_view_column_get_width (list_view->details->file_name_column) * 0.5 -
- RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH * 0.5,
- 0,
- gtk_tree_view_column_get_width (list_view->details->file_name_column) -
- RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH);
- }
- rect->width = RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH;
-
- g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
-
- return rect;
-}
-
-static GIcon*
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+ GdkRectangle *rect;
+ GtkTreeModel *model;
+ GtkTreeView *tree_view;
+ GList *list;
+ NautilusListView *list_view;
+
+ rect = g_malloc0 (sizeof (GdkRectangle));
+ list_view = NAUTILUS_LIST_VIEW (view);
+ tree_view = list_view->details->tree_view;
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view->details->tree_view));
+ model = GTK_TREE_MODEL (list_view->details->model);
+ list = gtk_tree_selection_get_selected_rows (selection, &model);
+ path = list->data;
+ gtk_tree_view_get_cell_area (tree_view, path, NULL, rect);
+ gtk_tree_view_convert_bin_window_to_widget_coords (tree_view,
+ rect->x, rect->y,
+ &rect->x, &rect->y);
+
+ if (list_view->details->last_event_button_x > 0)
+ {
+ rect->x = list_view->details->last_event_button_x;
+ }
+ else
+ {
+ rect->x = CLAMP (gtk_tree_view_column_get_width (list_view->details->file_name_column) * 0.5 -
+ RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH * 0.5,
+ 0,
+ gtk_tree_view_column_get_width (list_view->details->file_name_column) -
+ RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH);
+ }
+ rect->width = RENAME_POPOVER_RELATIVE_TO_RECTANGLE_WIDTH;
+
+ g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+
+ return rect;
+}
+
+static GIcon *
nautilus_list_view_get_icon (NautilusFilesView *view)
{
- g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_LIST_VIEW (view), NULL);
- return NAUTILUS_LIST_VIEW (view)->details->icon;
+ return NAUTILUS_LIST_VIEW (view)->details->icon;
}
static void
nautilus_list_view_class_init (NautilusListViewClass *class)
{
- NautilusFilesViewClass *nautilus_files_view_class;
-
- nautilus_files_view_class = NAUTILUS_FILES_VIEW_CLASS (class);
-
- G_OBJECT_CLASS (class)->dispose = nautilus_list_view_dispose;
- G_OBJECT_CLASS (class)->finalize = nautilus_list_view_finalize;
-
- nautilus_files_view_class->add_file = nautilus_list_view_add_file;
- nautilus_files_view_class->begin_loading = nautilus_list_view_begin_loading;
- nautilus_files_view_class->end_loading = nautilus_list_view_end_loading;
- nautilus_files_view_class->bump_zoom_level = nautilus_list_view_bump_zoom_level;
- nautilus_files_view_class->can_zoom_in = nautilus_list_view_can_zoom_in;
- nautilus_files_view_class->can_zoom_out = nautilus_list_view_can_zoom_out;
- nautilus_files_view_class->get_zoom_level_percentage = nautilus_list_view_get_zoom_level_percentage;
- nautilus_files_view_class->click_policy_changed = nautilus_list_view_click_policy_changed;
- nautilus_files_view_class->clear = nautilus_list_view_clear;
- nautilus_files_view_class->file_changed = nautilus_list_view_file_changed;
- nautilus_files_view_class->get_backing_uri = nautilus_list_view_get_backing_uri;
- nautilus_files_view_class->get_selection = nautilus_list_view_get_selection;
- nautilus_files_view_class->get_selection_for_file_transfer = nautilus_list_view_get_selection_for_file_transfer;
- nautilus_files_view_class->is_empty = nautilus_list_view_is_empty;
- nautilus_files_view_class->remove_file = nautilus_list_view_remove_file;
- nautilus_files_view_class->restore_standard_zoom_level = nautilus_list_view_restore_standard_zoom_level;
- nautilus_files_view_class->reveal_selection = nautilus_list_view_reveal_selection;
- nautilus_files_view_class->select_all = nautilus_list_view_select_all;
- nautilus_files_view_class->select_first = nautilus_list_view_select_first;
- nautilus_files_view_class->set_selection = nautilus_list_view_set_selection;
- nautilus_files_view_class->invert_selection = nautilus_list_view_invert_selection;
- nautilus_files_view_class->compare_files = nautilus_list_view_compare_files;
- nautilus_files_view_class->sort_directories_first_changed = nautilus_list_view_sort_directories_first_changed;
- nautilus_files_view_class->end_file_changes = nautilus_list_view_end_file_changes;
- nautilus_files_view_class->using_manual_layout = nautilus_list_view_using_manual_layout;
- nautilus_files_view_class->get_view_id = nautilus_list_view_get_id;
- nautilus_files_view_class->get_first_visible_file = nautilus_list_view_get_first_visible_file;
- nautilus_files_view_class->scroll_to_file = list_view_scroll_to_file;
- nautilus_files_view_class->compute_rename_popover_pointing_to = nautilus_list_view_compute_rename_popover_pointing_to;
- nautilus_files_view_class->get_icon = nautilus_list_view_get_icon;
+ NautilusFilesViewClass *nautilus_files_view_class;
+
+ nautilus_files_view_class = NAUTILUS_FILES_VIEW_CLASS (class);
+
+ G_OBJECT_CLASS (class)->dispose = nautilus_list_view_dispose;
+ G_OBJECT_CLASS (class)->finalize = nautilus_list_view_finalize;
+
+ nautilus_files_view_class->add_file = nautilus_list_view_add_file;
+ nautilus_files_view_class->begin_loading = nautilus_list_view_begin_loading;
+ nautilus_files_view_class->end_loading = nautilus_list_view_end_loading;
+ nautilus_files_view_class->bump_zoom_level = nautilus_list_view_bump_zoom_level;
+ nautilus_files_view_class->can_zoom_in = nautilus_list_view_can_zoom_in;
+ nautilus_files_view_class->can_zoom_out = nautilus_list_view_can_zoom_out;
+ nautilus_files_view_class->get_zoom_level_percentage = nautilus_list_view_get_zoom_level_percentage;
+ nautilus_files_view_class->click_policy_changed = nautilus_list_view_click_policy_changed;
+ nautilus_files_view_class->clear = nautilus_list_view_clear;
+ nautilus_files_view_class->file_changed = nautilus_list_view_file_changed;
+ nautilus_files_view_class->get_backing_uri = nautilus_list_view_get_backing_uri;
+ nautilus_files_view_class->get_selection = nautilus_list_view_get_selection;
+ nautilus_files_view_class->get_selection_for_file_transfer = nautilus_list_view_get_selection_for_file_transfer;
+ nautilus_files_view_class->is_empty = nautilus_list_view_is_empty;
+ nautilus_files_view_class->remove_file = nautilus_list_view_remove_file;
+ nautilus_files_view_class->restore_standard_zoom_level = nautilus_list_view_restore_standard_zoom_level;
+ nautilus_files_view_class->reveal_selection = nautilus_list_view_reveal_selection;
+ nautilus_files_view_class->select_all = nautilus_list_view_select_all;
+ nautilus_files_view_class->select_first = nautilus_list_view_select_first;
+ nautilus_files_view_class->set_selection = nautilus_list_view_set_selection;
+ nautilus_files_view_class->invert_selection = nautilus_list_view_invert_selection;
+ nautilus_files_view_class->compare_files = nautilus_list_view_compare_files;
+ nautilus_files_view_class->sort_directories_first_changed = nautilus_list_view_sort_directories_first_changed;
+ nautilus_files_view_class->end_file_changes = nautilus_list_view_end_file_changes;
+ nautilus_files_view_class->using_manual_layout = nautilus_list_view_using_manual_layout;
+ nautilus_files_view_class->get_view_id = nautilus_list_view_get_id;
+ nautilus_files_view_class->get_first_visible_file = nautilus_list_view_get_first_visible_file;
+ nautilus_files_view_class->scroll_to_file = list_view_scroll_to_file;
+ nautilus_files_view_class->compute_rename_popover_pointing_to = nautilus_list_view_compute_rename_popover_pointing_to;
+ nautilus_files_view_class->get_icon = nautilus_list_view_get_icon;
}
static void
nautilus_list_view_init (NautilusListView *list_view)
{
- GActionGroup *view_action_group;
- list_view->details = g_new0 (NautilusListViewDetails, 1);
-
- list_view->details->icon = g_themed_icon_new ("view-list-symbolic");
-
- /* ensure that the zoom level is always set before settings up the tree view columns */
- list_view->details->zoom_level = get_default_zoom_level ();
-
- create_and_set_up_tree_view (list_view);
-
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (list_view)),
- "nautilus-list-view");
-
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER,
- G_CALLBACK (default_sort_order_changed_callback),
- list_view);
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER,
- G_CALLBACK (default_sort_order_changed_callback),
- list_view);
- g_signal_connect_swapped (nautilus_list_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS,
- G_CALLBACK (default_visible_columns_changed_callback),
- list_view);
- g_signal_connect_swapped (nautilus_list_view_preferences,
- "changed::" NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER,
- G_CALLBACK (default_column_order_changed_callback),
- list_view);
-
- nautilus_list_view_click_policy_changed (NAUTILUS_FILES_VIEW (list_view));
-
- nautilus_list_view_sort_directories_first_changed (NAUTILUS_FILES_VIEW (list_view));
- nautilus_list_view_set_zoom_level (list_view, get_default_zoom_level ());
-
- list_view->details->hover_path = NULL;
- list_view->details->clipboard_handler_id =
- g_signal_connect (nautilus_clipboard_monitor_get (),
- "clipboard-info",
- G_CALLBACK (list_view_notify_clipboard_info), list_view);
-
- view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (list_view));
- g_action_map_add_action_entries (G_ACTION_MAP (view_action_group),
- list_view_entries,
- G_N_ELEMENTS (list_view_entries),
- list_view);
- /* Keep the action synced with the actual value, so the toolbar can poll it */
- g_action_group_change_action_state (nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (list_view)),
- "zoom-to-level", g_variant_new_int32 (get_default_zoom_level ()));
+ GActionGroup *view_action_group;
+ list_view->details = g_new0 (NautilusListViewDetails, 1);
+
+ list_view->details->icon = g_themed_icon_new ("view-list-symbolic");
+
+ /* ensure that the zoom level is always set before settings up the tree view columns */
+ list_view->details->zoom_level = get_default_zoom_level ();
+
+ create_and_set_up_tree_view (list_view);
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (list_view)),
+ "nautilus-list-view");
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_ORDER,
+ G_CALLBACK (default_sort_order_changed_callback),
+ list_view);
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_DEFAULT_SORT_IN_REVERSE_ORDER,
+ G_CALLBACK (default_sort_order_changed_callback),
+ list_view);
+ g_signal_connect_swapped (nautilus_list_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS,
+ G_CALLBACK (default_visible_columns_changed_callback),
+ list_view);
+ g_signal_connect_swapped (nautilus_list_view_preferences,
+ "changed::" NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER,
+ G_CALLBACK (default_column_order_changed_callback),
+ list_view);
+
+ nautilus_list_view_click_policy_changed (NAUTILUS_FILES_VIEW (list_view));
+
+ nautilus_list_view_sort_directories_first_changed (NAUTILUS_FILES_VIEW (list_view));
+ nautilus_list_view_set_zoom_level (list_view, get_default_zoom_level ());
+
+ list_view->details->hover_path = NULL;
+ list_view->details->clipboard_handler_id =
+ g_signal_connect (nautilus_clipboard_monitor_get (),
+ "clipboard-info",
+ G_CALLBACK (list_view_notify_clipboard_info), list_view);
+
+ view_action_group = nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (list_view));
+ g_action_map_add_action_entries (G_ACTION_MAP (view_action_group),
+ list_view_entries,
+ G_N_ELEMENTS (list_view_entries),
+ list_view);
+ /* Keep the action synced with the actual value, so the toolbar can poll it */
+ g_action_group_change_action_state (nautilus_files_view_get_action_group (NAUTILUS_FILES_VIEW (list_view)),
+ "zoom-to-level", g_variant_new_int32 (get_default_zoom_level ()));
}
NautilusFilesView *
nautilus_list_view_new (NautilusWindowSlot *slot)
{
- return g_object_new (NAUTILUS_TYPE_LIST_VIEW,
- "window-slot", slot,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_LIST_VIEW,
+ "window-slot", slot,
+ NULL);
}
diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c
index 306b6e4b7..73af0efa5 100644
--- a/src/nautilus-location-entry.c
+++ b/src/nautilus-location-entry.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -21,7 +20,7 @@
* Author: Maciej Stachowiak <mjs@eazel.com>
* Ettore Perazzoli <ettore@gnu.org>
* Michael Meeks <michael@nuclecu.unam.mx>
- * Andy Hertzfeld <andy@eazel.com>
+ * Andy Hertzfeld <andy@eazel.com>
*
*/
@@ -46,43 +45,48 @@
#include <stdio.h>
#include <string.h>
-#define NAUTILUS_DND_URI_LIST_TYPE "text/uri-list"
-#define NAUTILUS_DND_TEXT_PLAIN_TYPE "text/plain"
+#define NAUTILUS_DND_URI_LIST_TYPE "text/uri-list"
+#define NAUTILUS_DND_TEXT_PLAIN_TYPE "text/plain"
-enum {
- NAUTILUS_DND_URI_LIST,
- NAUTILUS_DND_TEXT_PLAIN,
- NAUTILUS_DND_NTARGETS
+enum
+{
+ NAUTILUS_DND_URI_LIST,
+ NAUTILUS_DND_TEXT_PLAIN,
+ NAUTILUS_DND_NTARGETS
};
-static const GtkTargetEntry drag_types [] = {
- { NAUTILUS_DND_URI_LIST_TYPE, 0, NAUTILUS_DND_URI_LIST },
- { NAUTILUS_DND_TEXT_PLAIN_TYPE, 0, NAUTILUS_DND_TEXT_PLAIN },
+static const GtkTargetEntry drag_types [] =
+{
+ { NAUTILUS_DND_URI_LIST_TYPE, 0, NAUTILUS_DND_URI_LIST },
+ { NAUTILUS_DND_TEXT_PLAIN_TYPE, 0, NAUTILUS_DND_TEXT_PLAIN },
};
-static const GtkTargetEntry drop_types [] = {
- { NAUTILUS_DND_URI_LIST_TYPE, 0, NAUTILUS_DND_URI_LIST },
- { NAUTILUS_DND_TEXT_PLAIN_TYPE, 0, NAUTILUS_DND_TEXT_PLAIN },
+static const GtkTargetEntry drop_types [] =
+{
+ { NAUTILUS_DND_URI_LIST_TYPE, 0, NAUTILUS_DND_URI_LIST },
+ { NAUTILUS_DND_TEXT_PLAIN_TYPE, 0, NAUTILUS_DND_TEXT_PLAIN },
};
-struct NautilusLocationEntryDetails {
- char *current_directory;
- GFilenameCompleter *completer;
+struct NautilusLocationEntryDetails
+{
+ char *current_directory;
+ GFilenameCompleter *completer;
- guint idle_id;
+ guint idle_id;
- GFile *last_location;
+ GFile *last_location;
- gboolean has_special_text;
- gboolean setting_special_text;
- gchar *special_text;
- NautilusLocationEntryAction secondary_action;
+ gboolean has_special_text;
+ gboolean setting_special_text;
+ gchar *special_text;
+ NautilusLocationEntryAction secondary_action;
};
-enum {
- CANCEL,
- LOCATION_CHANGED,
- LAST_SIGNAL
+enum
+{
+ CANCEL,
+ LOCATION_CHANGED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -92,291 +96,312 @@ G_DEFINE_TYPE (NautilusLocationEntry, nautilus_location_entry, NAUTILUS_TYPE_ENT
void
nautilus_location_entry_focus (NautilusLocationEntry *entry)
{
- /* Put the keyboard focus in the text field when switching to this mode,
- * and select all text for easy overtyping
- */
- gtk_widget_grab_focus (GTK_WIDGET (entry));
- nautilus_entry_select_all (NAUTILUS_ENTRY (entry));
+ /* Put the keyboard focus in the text field when switching to this mode,
+ * and select all text for easy overtyping
+ */
+ gtk_widget_grab_focus (GTK_WIDGET (entry));
+ nautilus_entry_select_all (NAUTILUS_ENTRY (entry));
}
static GFile *
nautilus_location_entry_get_location (NautilusLocationEntry *entry)
{
- char *user_location;
- GFile *location;
+ char *user_location;
+ GFile *location;
- user_location = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
- location = g_file_parse_name (user_location);
- g_free (user_location);
+ user_location = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
+ location = g_file_parse_name (user_location);
+ g_free (user_location);
- return location;
+ return location;
}
static void
emit_location_changed (NautilusLocationEntry *entry)
{
- GFile *location;
+ GFile *location;
- location = nautilus_location_entry_get_location (entry);
- g_signal_emit (entry, signals[LOCATION_CHANGED], 0, location);
- g_object_unref (location);
+ location = nautilus_location_entry_get_location (entry);
+ g_signal_emit (entry, signals[LOCATION_CHANGED], 0, location);
+ g_object_unref (location);
}
static void
nautilus_location_entry_update_action (NautilusLocationEntry *entry)
{
- const char *current_text;
- GFile *location;
-
- if (entry->details->last_location == NULL){
- nautilus_location_entry_set_secondary_action (entry,
- NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
- return;
- }
-
- current_text = gtk_entry_get_text (GTK_ENTRY (entry));
- location = g_file_parse_name (current_text);
-
- if (g_file_equal (entry->details->last_location, location)) {
- nautilus_location_entry_set_secondary_action (entry,
- NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR);
- } else {
- nautilus_location_entry_set_secondary_action (entry,
- NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
- }
-
- g_object_unref (location);
+ const char *current_text;
+ GFile *location;
+
+ if (entry->details->last_location == NULL)
+ {
+ nautilus_location_entry_set_secondary_action (entry,
+ NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
+ return;
+ }
+
+ current_text = gtk_entry_get_text (GTK_ENTRY (entry));
+ location = g_file_parse_name (current_text);
+
+ if (g_file_equal (entry->details->last_location, location))
+ {
+ nautilus_location_entry_set_secondary_action (entry,
+ NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR);
+ }
+ else
+ {
+ nautilus_location_entry_set_secondary_action (entry,
+ NAUTILUS_LOCATION_ENTRY_ACTION_GOTO);
+ }
+
+ g_object_unref (location);
}
static int
get_editable_number_of_chars (GtkEditable *editable)
{
- char *text;
- int length;
+ char *text;
+ int length;
- text = gtk_editable_get_chars (editable, 0, -1);
- length = g_utf8_strlen (text, -1);
- g_free (text);
- return length;
+ text = gtk_editable_get_chars (editable, 0, -1);
+ length = g_utf8_strlen (text, -1);
+ g_free (text);
+ return length;
}
static void
set_position_and_selection_to_end (GtkEditable *editable)
{
- int end;
+ int end;
- end = get_editable_number_of_chars (editable);
- gtk_editable_select_region (editable, end, end);
- gtk_editable_set_position (editable, end);
+ end = get_editable_number_of_chars (editable);
+ gtk_editable_select_region (editable, end, end);
+ gtk_editable_set_position (editable, end);
}
static void
nautilus_location_entry_update_current_uri (NautilusLocationEntry *entry,
- const char *uri)
+ const char *uri)
{
- g_free (entry->details->current_directory);
- entry->details->current_directory = g_strdup (uri);
+ g_free (entry->details->current_directory);
+ entry->details->current_directory = g_strdup (uri);
- nautilus_entry_set_text (NAUTILUS_ENTRY (entry), uri);
- set_position_and_selection_to_end (GTK_EDITABLE (entry));
+ nautilus_entry_set_text (NAUTILUS_ENTRY (entry), uri);
+ set_position_and_selection_to_end (GTK_EDITABLE (entry));
}
void
nautilus_location_entry_set_location (NautilusLocationEntry *entry,
- GFile *location)
+ GFile *location)
{
- gchar *uri, *formatted_uri;
-
- g_assert (location != NULL);
-
- /* Note: This is called in reaction to external changes, and
- * thus should not emit the LOCATION_CHANGED signal. */
- uri = g_file_get_uri (location);
- formatted_uri = g_file_get_parse_name (location);
-
- if (eel_uri_is_search (uri)) {
- nautilus_location_entry_set_special_text (entry, "");
- } else {
- nautilus_location_entry_update_current_uri (entry, formatted_uri);
- }
-
- /* remember the original location for later comparison */
- if (!entry->details->last_location ||
- !g_file_equal (entry->details->last_location, location)) {
- g_clear_object (&entry->details->last_location);
- entry->details->last_location = g_object_ref (location);
- }
-
- nautilus_location_entry_update_action (entry);
-
- g_free (uri);
- g_free (formatted_uri);
+ gchar *uri, *formatted_uri;
+
+ g_assert (location != NULL);
+
+ /* Note: This is called in reaction to external changes, and
+ * thus should not emit the LOCATION_CHANGED signal. */
+ uri = g_file_get_uri (location);
+ formatted_uri = g_file_get_parse_name (location);
+
+ if (eel_uri_is_search (uri))
+ {
+ nautilus_location_entry_set_special_text (entry, "");
+ }
+ else
+ {
+ nautilus_location_entry_update_current_uri (entry, formatted_uri);
+ }
+
+ /* remember the original location for later comparison */
+ if (!entry->details->last_location ||
+ !g_file_equal (entry->details->last_location, location))
+ {
+ g_clear_object (&entry->details->last_location);
+ entry->details->last_location = g_object_ref (location);
+ }
+
+ nautilus_location_entry_update_action (entry);
+
+ g_free (uri);
+ g_free (formatted_uri);
}
static void
-drag_data_received_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- GtkSelectionData *data,
- guint info,
- guint32 time,
- gpointer callback_data)
-{
- char **names;
- int name_count;
- GtkWidget *window;
- gboolean new_windows_for_extras;
- char *prompt;
- char *detail;
- GFile *location;
- NautilusLocationEntry *self = NAUTILUS_LOCATION_ENTRY (widget);
-
- g_assert (data != NULL);
- g_assert (callback_data == NULL);
-
- names = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (data));
-
- if (names == NULL || *names == NULL) {
- g_warning ("No D&D URI's");
- gtk_drag_finish (context, FALSE, FALSE, time);
- return;
- }
-
- window = gtk_widget_get_toplevel (widget);
- new_windows_for_extras = FALSE;
- /* Ask user if they really want to open multiple windows
- * for multiple dropped URIs. This is likely to have been
- * a mistake.
- */
- name_count = g_strv_length (names);
- if (name_count > 1) {
- prompt = g_strdup_printf (ngettext("Do you want to view %d location?",
- "Do you want to view %d locations?",
- name_count),
- name_count);
- detail = g_strdup_printf (ngettext("This will open %d separate window.",
- "This will open %d separate windows.",
- name_count),
- name_count);
- /* eel_run_simple_dialog should really take in pairs
- * like gtk_dialog_new_with_buttons() does. */
- new_windows_for_extras = eel_run_simple_dialog (GTK_WIDGET (window),
- TRUE,
- GTK_MESSAGE_QUESTION,
- prompt,
- detail,
- _("_Cancel"), _("_OK"),
- NULL) != 0 /* GNOME_OK */;
-
- g_free (prompt);
- g_free (detail);
-
- if (!new_windows_for_extras) {
- gtk_drag_finish (context, FALSE, FALSE, time);
- return;
- }
- }
-
- location = g_file_new_for_uri (names[0]);
- nautilus_location_entry_set_location (self, location);
- emit_location_changed (self);
- g_object_unref (location);
-
- if (new_windows_for_extras) {
- int i;
-
- for (i = 1; names[i] != NULL; ++i) {
- location = g_file_new_for_uri (names[i]);
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location, NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW, NULL, NULL, NULL);
- g_object_unref (location);
- }
- }
-
- g_strfreev (names);
-
- gtk_drag_finish (context, TRUE, FALSE, time);
+drag_data_received_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ GtkSelectionData *data,
+ guint info,
+ guint32 time,
+ gpointer callback_data)
+{
+ char **names;
+ int name_count;
+ GtkWidget *window;
+ gboolean new_windows_for_extras;
+ char *prompt;
+ char *detail;
+ GFile *location;
+ NautilusLocationEntry *self = NAUTILUS_LOCATION_ENTRY (widget);
+
+ g_assert (data != NULL);
+ g_assert (callback_data == NULL);
+
+ names = g_uri_list_extract_uris ((const gchar *) gtk_selection_data_get_data (data));
+
+ if (names == NULL || *names == NULL)
+ {
+ g_warning ("No D&D URI's");
+ gtk_drag_finish (context, FALSE, FALSE, time);
+ return;
+ }
+
+ window = gtk_widget_get_toplevel (widget);
+ new_windows_for_extras = FALSE;
+ /* Ask user if they really want to open multiple windows
+ * for multiple dropped URIs. This is likely to have been
+ * a mistake.
+ */
+ name_count = g_strv_length (names);
+ if (name_count > 1)
+ {
+ prompt = g_strdup_printf (ngettext ("Do you want to view %d location?",
+ "Do you want to view %d locations?",
+ name_count),
+ name_count);
+ detail = g_strdup_printf (ngettext ("This will open %d separate window.",
+ "This will open %d separate windows.",
+ name_count),
+ name_count);
+ /* eel_run_simple_dialog should really take in pairs
+ * like gtk_dialog_new_with_buttons() does. */
+ new_windows_for_extras = eel_run_simple_dialog (GTK_WIDGET (window),
+ TRUE,
+ GTK_MESSAGE_QUESTION,
+ prompt,
+ detail,
+ _("_Cancel"), _("_OK"),
+ NULL) != 0 /* GNOME_OK */;
+
+ g_free (prompt);
+ g_free (detail);
+
+ if (!new_windows_for_extras)
+ {
+ gtk_drag_finish (context, FALSE, FALSE, time);
+ return;
+ }
+ }
+
+ location = g_file_new_for_uri (names[0]);
+ nautilus_location_entry_set_location (self, location);
+ emit_location_changed (self);
+ g_object_unref (location);
+
+ if (new_windows_for_extras)
+ {
+ int i;
+
+ for (i = 1; names[i] != NULL; ++i)
+ {
+ location = g_file_new_for_uri (names[i]);
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location, NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW, NULL, NULL, NULL);
+ g_object_unref (location);
+ }
+ }
+
+ g_strfreev (names);
+
+ gtk_drag_finish (context, TRUE, FALSE, time);
}
static void
-drag_data_get_callback (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint32 time,
- gpointer callback_data)
-{
- NautilusLocationEntry *self;
- GFile *location;
- gchar *uri;
-
- g_assert (selection_data != NULL);
- self = callback_data;
-
- location = nautilus_location_entry_get_location (self);
- uri = g_file_get_uri (location);
-
- switch (info) {
- case NAUTILUS_DND_URI_LIST:
- case NAUTILUS_DND_TEXT_PLAIN:
- gtk_selection_data_set (selection_data,
- gtk_selection_data_get_target (selection_data),
- 8, (guchar *) uri,
- strlen (uri));
- break;
- default:
- g_assert_not_reached ();
- }
- g_free (uri);
- g_object_unref (location);
+drag_data_get_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint32 time,
+ gpointer callback_data)
+{
+ NautilusLocationEntry *self;
+ GFile *location;
+ gchar *uri;
+
+ g_assert (selection_data != NULL);
+ self = callback_data;
+
+ location = nautilus_location_entry_get_location (self);
+ uri = g_file_get_uri (location);
+
+ switch (info)
+ {
+ case NAUTILUS_DND_URI_LIST:
+ case NAUTILUS_DND_TEXT_PLAIN:
+ {
+ gtk_selection_data_set (selection_data,
+ gtk_selection_data_get_target (selection_data),
+ 8, (guchar *) uri,
+ strlen (uri));
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+ g_free (uri);
+ g_object_unref (location);
}
/* routine that performs the tab expansion. Extract the directory name and
- incomplete basename, then iterate through the directory trying to complete it. If we
- find something, add it to the entry */
-
+ * incomplete basename, then iterate through the directory trying to complete it. If we
+ * find something, add it to the entry */
+
static gboolean
try_to_expand_path (gpointer callback_data)
{
- NautilusLocationEntry *entry;
- GtkEditable *editable;
- char *suffix, *user_location, *absolute_location, *uri_scheme;
- int user_location_length, pos;
-
- entry = NAUTILUS_LOCATION_ENTRY (callback_data);
- editable = GTK_EDITABLE (entry);
- user_location = gtk_editable_get_chars (editable, 0, -1);
- user_location_length = g_utf8_strlen (user_location, -1);
- entry->details->idle_id = 0;
-
- uri_scheme = g_uri_parse_scheme (user_location);
-
- if (!g_path_is_absolute (user_location) && uri_scheme == NULL && user_location[0] != '~') {
- absolute_location = g_build_filename (entry->details->current_directory, user_location, NULL);
- suffix = g_filename_completer_get_completion_suffix (entry->details->completer,
- absolute_location);
- g_free (absolute_location);
- } else {
- suffix = g_filename_completer_get_completion_suffix (entry->details->completer,
- user_location);
- }
-
- g_free (user_location);
- g_free (uri_scheme);
-
- /* if we've got something, add it to the entry */
- if (suffix != NULL) {
- pos = user_location_length;
- gtk_editable_insert_text (editable,
- suffix, -1, &pos);
- pos = user_location_length;
- gtk_editable_select_region (editable, pos, -1);
-
- g_free (suffix);
- }
-
- return FALSE;
+ NautilusLocationEntry *entry;
+ GtkEditable *editable;
+ char *suffix, *user_location, *absolute_location, *uri_scheme;
+ int user_location_length, pos;
+
+ entry = NAUTILUS_LOCATION_ENTRY (callback_data);
+ editable = GTK_EDITABLE (entry);
+ user_location = gtk_editable_get_chars (editable, 0, -1);
+ user_location_length = g_utf8_strlen (user_location, -1);
+ entry->details->idle_id = 0;
+
+ uri_scheme = g_uri_parse_scheme (user_location);
+
+ if (!g_path_is_absolute (user_location) && uri_scheme == NULL && user_location[0] != '~')
+ {
+ absolute_location = g_build_filename (entry->details->current_directory, user_location, NULL);
+ suffix = g_filename_completer_get_completion_suffix (entry->details->completer,
+ absolute_location);
+ g_free (absolute_location);
+ }
+ else
+ {
+ suffix = g_filename_completer_get_completion_suffix (entry->details->completer,
+ user_location);
+ }
+
+ g_free (user_location);
+ g_free (uri_scheme);
+
+ /* if we've got something, add it to the entry */
+ if (suffix != NULL)
+ {
+ pos = user_location_length;
+ gtk_editable_insert_text (editable,
+ suffix, -1, &pos);
+ pos = user_location_length;
+ gtk_editable_select_region (editable, pos, -1);
+
+ g_free (suffix);
+ }
+
+ return FALSE;
}
/* Until we have a more elegant solution, this is how we figure out if
@@ -387,380 +412,418 @@ try_to_expand_path (gpointer callback_data)
static gboolean
entry_would_have_inserted_characters (const GdkEventKey *event)
{
- switch (event->keyval) {
- case GDK_KEY_BackSpace:
- case GDK_KEY_Clear:
- case GDK_KEY_Insert:
- case GDK_KEY_Delete:
- case GDK_KEY_Home:
- case GDK_KEY_End:
- case GDK_KEY_KP_Home:
- case GDK_KEY_KP_End:
- case GDK_KEY_Left:
- case GDK_KEY_Right:
- case GDK_KEY_KP_Left:
- case GDK_KEY_KP_Right:
- case GDK_KEY_Return:
- return FALSE;
- default:
- if (event->keyval >= 0x20 && event->keyval <= 0xFF) {
- if ((event->state & GDK_CONTROL_MASK) != 0) {
- return FALSE;
- }
- if ((event->state & GDK_MOD1_MASK) != 0) {
- return FALSE;
- }
- }
- return event->length > 0;
- }
+ switch (event->keyval)
+ {
+ case GDK_KEY_BackSpace:
+ case GDK_KEY_Clear:
+ case GDK_KEY_Insert:
+ case GDK_KEY_Delete:
+ case GDK_KEY_Home:
+ case GDK_KEY_End:
+ case GDK_KEY_KP_Home:
+ case GDK_KEY_KP_End:
+ case GDK_KEY_Left:
+ case GDK_KEY_Right:
+ case GDK_KEY_KP_Left:
+ case GDK_KEY_KP_Right:
+ case GDK_KEY_Return:
+ {
+ return FALSE;
+ }
+
+ default:
+ if (event->keyval >= 0x20 && event->keyval <= 0xFF)
+ {
+ if ((event->state & GDK_CONTROL_MASK) != 0)
+ {
+ return FALSE;
+ }
+ if ((event->state & GDK_MOD1_MASK) != 0)
+ {
+ return FALSE;
+ }
+ }
+ return event->length > 0;
+ }
}
static gboolean
position_and_selection_are_at_end (GtkEditable *editable)
{
- int end;
- int start_sel, end_sel;
-
- end = get_editable_number_of_chars (editable);
- if (gtk_editable_get_selection_bounds (editable, &start_sel, &end_sel)) {
- if (start_sel != end || end_sel != end) {
- return FALSE;
- }
- }
- return gtk_editable_get_position (editable) == end;
+ int end;
+ int start_sel, end_sel;
+
+ end = get_editable_number_of_chars (editable);
+ if (gtk_editable_get_selection_bounds (editable, &start_sel, &end_sel))
+ {
+ if (start_sel != end || end_sel != end)
+ {
+ return FALSE;
+ }
+ }
+ return gtk_editable_get_position (editable) == end;
}
static void
-got_completion_data_callback (GFilenameCompleter *completer,
- NautilusLocationEntry *entry)
-{
- if (entry->details->idle_id) {
- g_source_remove (entry->details->idle_id);
- entry->details->idle_id = 0;
- }
- try_to_expand_path (entry);
+got_completion_data_callback (GFilenameCompleter *completer,
+ NautilusLocationEntry *entry)
+{
+ if (entry->details->idle_id)
+ {
+ g_source_remove (entry->details->idle_id);
+ entry->details->idle_id = 0;
+ }
+ try_to_expand_path (entry);
}
static void
-editable_event_after_callback (GtkEntry *entry,
- GdkEvent *event,
- NautilusLocationEntry *location_entry)
-{
- GtkEditable *editable;
- GdkEventKey *keyevent;
-
- if (event->type != GDK_KEY_PRESS) {
- return;
- }
-
- editable = GTK_EDITABLE (entry);
- keyevent = (GdkEventKey *)event;
-
- /* After typing the right arrow key we move the selection to
- * the end, if we have a valid selection - since this is most
- * likely an auto-completion. We ignore shift / control since
- * they can validly be used to extend the selection.
- */
- if ((keyevent->keyval == GDK_KEY_Right || keyevent->keyval == GDK_KEY_End) &&
- !(keyevent->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) &&
- gtk_editable_get_selection_bounds (editable, NULL, NULL)) {
- set_position_and_selection_to_end (editable);
- }
-
- /* Only do expanding when we are typing at the end of the
- * text. Do the expand at idle time to avoid slowing down
- * typing when the directory is large. Only trigger the expand
- * when we type a key that would have inserted characters.
- */
- if (position_and_selection_are_at_end (editable)) {
- if (entry_would_have_inserted_characters (keyevent)) {
- if (location_entry->details->idle_id == 0) {
- location_entry->details->idle_id = g_idle_add (try_to_expand_path, location_entry);
- }
- }
- } else {
- /* FIXME: Also might be good to do this when you click
- * to change the position or selection.
- */
- if (location_entry->details->idle_id != 0) {
- g_source_remove (location_entry->details->idle_id);
- location_entry->details->idle_id = 0;
- }
- }
+editable_event_after_callback (GtkEntry *entry,
+ GdkEvent *event,
+ NautilusLocationEntry *location_entry)
+{
+ GtkEditable *editable;
+ GdkEventKey *keyevent;
+
+ if (event->type != GDK_KEY_PRESS)
+ {
+ return;
+ }
+
+ editable = GTK_EDITABLE (entry);
+ keyevent = (GdkEventKey *) event;
+
+ /* After typing the right arrow key we move the selection to
+ * the end, if we have a valid selection - since this is most
+ * likely an auto-completion. We ignore shift / control since
+ * they can validly be used to extend the selection.
+ */
+ if ((keyevent->keyval == GDK_KEY_Right || keyevent->keyval == GDK_KEY_End) &&
+ !(keyevent->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) &&
+ gtk_editable_get_selection_bounds (editable, NULL, NULL))
+ {
+ set_position_and_selection_to_end (editable);
+ }
+
+ /* Only do expanding when we are typing at the end of the
+ * text. Do the expand at idle time to avoid slowing down
+ * typing when the directory is large. Only trigger the expand
+ * when we type a key that would have inserted characters.
+ */
+ if (position_and_selection_are_at_end (editable))
+ {
+ if (entry_would_have_inserted_characters (keyevent))
+ {
+ if (location_entry->details->idle_id == 0)
+ {
+ location_entry->details->idle_id = g_idle_add (try_to_expand_path, location_entry);
+ }
+ }
+ }
+ else
+ {
+ /* FIXME: Also might be good to do this when you click
+ * to change the position or selection.
+ */
+ if (location_entry->details->idle_id != 0)
+ {
+ g_source_remove (location_entry->details->idle_id);
+ location_entry->details->idle_id = 0;
+ }
+ }
}
static void
finalize (GObject *object)
{
- NautilusLocationEntry *entry;
+ NautilusLocationEntry *entry;
- entry = NAUTILUS_LOCATION_ENTRY (object);
+ entry = NAUTILUS_LOCATION_ENTRY (object);
- g_object_unref (entry->details->completer);
- g_free (entry->details->special_text);
+ g_object_unref (entry->details->completer);
+ g_free (entry->details->special_text);
- g_clear_object (&entry->details->last_location);
+ g_clear_object (&entry->details->last_location);
- G_OBJECT_CLASS (nautilus_location_entry_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_location_entry_parent_class)->finalize (object);
}
static void
destroy (GtkWidget *object)
{
- NautilusLocationEntry *entry;
-
- entry = NAUTILUS_LOCATION_ENTRY (object);
-
- /* cancel the pending idle call, if any */
- if (entry->details->idle_id != 0) {
- g_source_remove (entry->details->idle_id);
- entry->details->idle_id = 0;
- }
-
- g_free (entry->details->current_directory);
- entry->details->current_directory = NULL;
-
- GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->destroy (object);
+ NautilusLocationEntry *entry;
+
+ entry = NAUTILUS_LOCATION_ENTRY (object);
+
+ /* cancel the pending idle call, if any */
+ if (entry->details->idle_id != 0)
+ {
+ g_source_remove (entry->details->idle_id);
+ entry->details->idle_id = 0;
+ }
+
+ g_free (entry->details->current_directory);
+ entry->details->current_directory = NULL;
+
+ GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->destroy (object);
}
static void
nautilus_location_entry_text_changed (NautilusLocationEntry *entry,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- if (entry->details->setting_special_text) {
- return;
- }
+ if (entry->details->setting_special_text)
+ {
+ return;
+ }
- entry->details->has_special_text = FALSE;
+ entry->details->has_special_text = FALSE;
}
static void
-nautilus_location_entry_icon_release (GtkEntry *gentry,
- GtkEntryIconPosition position,
- GdkEvent *event,
- gpointer unused)
-{
- switch (NAUTILUS_LOCATION_ENTRY (gentry)->details->secondary_action) {
- case NAUTILUS_LOCATION_ENTRY_ACTION_GOTO:
- g_signal_emit_by_name (gentry, "activate", gentry);
- break;
- case NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR:
- gtk_entry_set_text (gentry, "");
- break;
- default:
- g_assert_not_reached ();
- }
+nautilus_location_entry_icon_release (GtkEntry *gentry,
+ GtkEntryIconPosition position,
+ GdkEvent *event,
+ gpointer unused)
+{
+ switch (NAUTILUS_LOCATION_ENTRY (gentry)->details->secondary_action)
+ {
+ case NAUTILUS_LOCATION_ENTRY_ACTION_GOTO:
+ {
+ g_signal_emit_by_name (gentry, "activate", gentry);
+ }
+ break;
+
+ case NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR:
+ {
+ gtk_entry_set_text (gentry, "");
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
}
static gboolean
nautilus_location_entry_focus_in (GtkWidget *widget,
- GdkEventFocus *event)
+ GdkEventFocus *event)
{
- NautilusLocationEntry *entry = NAUTILUS_LOCATION_ENTRY (widget);
+ NautilusLocationEntry *entry = NAUTILUS_LOCATION_ENTRY (widget);
- if (entry->details->has_special_text) {
- entry->details->setting_special_text = TRUE;
- gtk_entry_set_text (GTK_ENTRY (entry), "");
- entry->details->setting_special_text = FALSE;
- }
+ if (entry->details->has_special_text)
+ {
+ entry->details->setting_special_text = TRUE;
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
+ entry->details->setting_special_text = FALSE;
+ }
- return GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->focus_in_event (widget, event);
+ return GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->focus_in_event (widget, event);
}
static void
nautilus_location_entry_activate (GtkEntry *entry)
{
- NautilusLocationEntry *loc_entry;
- const gchar *entry_text;
- gchar *full_path, *uri_scheme = NULL;
+ NautilusLocationEntry *loc_entry;
+ const gchar *entry_text;
+ gchar *full_path, *uri_scheme = NULL;
- loc_entry = NAUTILUS_LOCATION_ENTRY (entry);
- entry_text = gtk_entry_get_text (entry);
+ loc_entry = NAUTILUS_LOCATION_ENTRY (entry);
+ entry_text = gtk_entry_get_text (entry);
- if (entry_text != NULL && *entry_text != '\0') {
- uri_scheme = g_uri_parse_scheme (entry_text);
+ if (entry_text != NULL && *entry_text != '\0')
+ {
+ uri_scheme = g_uri_parse_scheme (entry_text);
- if (!g_path_is_absolute (entry_text) && uri_scheme == NULL && entry_text[0] != '~') {
- /* Fix non absolute paths */
- full_path = g_build_filename (loc_entry->details->current_directory, entry_text, NULL);
- gtk_entry_set_text (entry, full_path);
- g_free (full_path);
- }
+ if (!g_path_is_absolute (entry_text) && uri_scheme == NULL && entry_text[0] != '~')
+ {
+ /* Fix non absolute paths */
+ full_path = g_build_filename (loc_entry->details->current_directory, entry_text, NULL);
+ gtk_entry_set_text (entry, full_path);
+ g_free (full_path);
+ }
- g_free (uri_scheme);
- }
+ g_free (uri_scheme);
+ }
- GTK_ENTRY_CLASS (nautilus_location_entry_parent_class)->activate (entry);
+ GTK_ENTRY_CLASS (nautilus_location_entry_parent_class)->activate (entry);
}
static void
nautilus_location_entry_cancel (NautilusLocationEntry *entry)
{
- nautilus_location_entry_set_location (entry, entry->details->last_location);
+ nautilus_location_entry_set_location (entry, entry->details->last_location);
}
static void
nautilus_location_entry_class_init (NautilusLocationEntryClass *class)
{
- GtkWidgetClass *widget_class;
- GObjectClass *gobject_class;
- GtkEntryClass *entry_class;
- GtkBindingSet *binding_set;
-
- widget_class = GTK_WIDGET_CLASS (class);
- widget_class->focus_in_event = nautilus_location_entry_focus_in;
- widget_class->destroy = destroy;
-
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->finalize = finalize;
-
- entry_class = GTK_ENTRY_CLASS (class);
- entry_class->activate = nautilus_location_entry_activate;
-
- class->cancel = nautilus_location_entry_cancel;
-
- signals[CANCEL] = g_signal_new
- ("cancel",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (NautilusLocationEntryClass,
- cancel),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[LOCATION_CHANGED] = g_signal_new
- ("location-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST, 0,
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
-
- binding_set = gtk_binding_set_by_class (class);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "cancel", 0);
-
- g_type_class_add_private (class, sizeof (NautilusLocationEntryDetails));
+ GtkWidgetClass *widget_class;
+ GObjectClass *gobject_class;
+ GtkEntryClass *entry_class;
+ GtkBindingSet *binding_set;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->focus_in_event = nautilus_location_entry_focus_in;
+ widget_class->destroy = destroy;
+
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->finalize = finalize;
+
+ entry_class = GTK_ENTRY_CLASS (class);
+ entry_class->activate = nautilus_location_entry_activate;
+
+ class->cancel = nautilus_location_entry_cancel;
+
+ signals[CANCEL] = g_signal_new
+ ("cancel",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (NautilusLocationEntryClass,
+ cancel),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[LOCATION_CHANGED] = g_signal_new
+ ("location-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST, 0,
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1, G_TYPE_OBJECT);
+
+ binding_set = gtk_binding_set_by_class (class);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "cancel", 0);
+
+ g_type_class_add_private (class, sizeof (NautilusLocationEntryDetails));
}
void
-nautilus_location_entry_set_secondary_action (NautilusLocationEntry *entry,
- NautilusLocationEntryAction secondary_action)
-{
- if (entry->details->secondary_action == secondary_action) {
- return;
- }
-
- switch (secondary_action) {
- case NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR:
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY,
- "edit-clear-symbolic");
- break;
- case NAUTILUS_LOCATION_ENTRY_ACTION_GOTO:
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY,
- "go-next-symbolic");
- break;
- default:
- g_assert_not_reached ();
- }
- entry->details->secondary_action = secondary_action;
+nautilus_location_entry_set_secondary_action (NautilusLocationEntry *entry,
+ NautilusLocationEntryAction secondary_action)
+{
+ if (entry->details->secondary_action == secondary_action)
+ {
+ return;
+ }
+
+ switch (secondary_action)
+ {
+ case NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR:
+ {
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ "edit-clear-symbolic");
+ }
+ break;
+
+ case NAUTILUS_LOCATION_ENTRY_ACTION_GOTO:
+ {
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ "go-next-symbolic");
+ }
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+ entry->details->secondary_action = secondary_action;
}
static void
editable_activate_callback (GtkEntry *entry,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusLocationEntry *self = user_data;
- const char *entry_text;
-
- entry_text = gtk_entry_get_text (entry);
- if (entry_text != NULL && *entry_text != '\0') {
- emit_location_changed (self);
- }
+ NautilusLocationEntry *self = user_data;
+ const char *entry_text;
+
+ entry_text = gtk_entry_get_text (entry);
+ if (entry_text != NULL && *entry_text != '\0')
+ {
+ emit_location_changed (self);
+ }
}
static void
editable_changed_callback (GtkEntry *entry,
- gpointer user_data)
+ gpointer user_data)
{
- nautilus_location_entry_update_action (NAUTILUS_LOCATION_ENTRY (entry));
+ nautilus_location_entry_update_action (NAUTILUS_LOCATION_ENTRY (entry));
}
static void
nautilus_location_entry_init (NautilusLocationEntry *entry)
{
- GtkTargetList *targetlist;
+ GtkTargetList *targetlist;
- entry->details = G_TYPE_INSTANCE_GET_PRIVATE (entry, NAUTILUS_TYPE_LOCATION_ENTRY,
- NautilusLocationEntryDetails);
+ entry->details = G_TYPE_INSTANCE_GET_PRIVATE (entry, NAUTILUS_TYPE_LOCATION_ENTRY,
+ NautilusLocationEntryDetails);
- entry->details->completer = g_filename_completer_new ();
- g_filename_completer_set_dirs_only (entry->details->completer, TRUE);
+ entry->details->completer = g_filename_completer_new ();
+ g_filename_completer_set_dirs_only (entry->details->completer, TRUE);
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, "folder-symbolic");
- gtk_entry_set_icon_activatable (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, FALSE);
- targetlist = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types));
- gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, targetlist, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
- gtk_target_list_unref (targetlist);
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, "folder-symbolic");
+ gtk_entry_set_icon_activatable (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, FALSE);
+ targetlist = gtk_target_list_new (drag_types, G_N_ELEMENTS (drag_types));
+ gtk_entry_set_icon_drag_source (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, targetlist, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+ gtk_target_list_unref (targetlist);
- nautilus_location_entry_set_secondary_action (entry,
- NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR);
+ nautilus_location_entry_set_secondary_action (entry,
+ NAUTILUS_LOCATION_ENTRY_ACTION_CLEAR);
- nautilus_entry_set_special_tab_handling (NAUTILUS_ENTRY (entry), TRUE);
+ nautilus_entry_set_special_tab_handling (NAUTILUS_ENTRY (entry), TRUE);
- g_signal_connect (entry, "event-after",
- G_CALLBACK (editable_event_after_callback), entry);
+ g_signal_connect (entry, "event-after",
+ G_CALLBACK (editable_event_after_callback), entry);
- g_signal_connect (entry, "notify::text",
- G_CALLBACK (nautilus_location_entry_text_changed), NULL);
+ g_signal_connect (entry, "notify::text",
+ G_CALLBACK (nautilus_location_entry_text_changed), NULL);
- g_signal_connect (entry, "icon-release",
- G_CALLBACK (nautilus_location_entry_icon_release), NULL);
+ g_signal_connect (entry, "icon-release",
+ G_CALLBACK (nautilus_location_entry_icon_release), NULL);
- g_signal_connect (entry->details->completer, "got-completion-data",
- G_CALLBACK (got_completion_data_callback), entry);
+ g_signal_connect (entry->details->completer, "got-completion-data",
+ G_CALLBACK (got_completion_data_callback), entry);
- /* Drag source */
- g_signal_connect_object (entry, "drag-data-get",
- G_CALLBACK (drag_data_get_callback), entry, 0);
+ /* Drag source */
+ g_signal_connect_object (entry, "drag-data-get",
+ G_CALLBACK (drag_data_get_callback), entry, 0);
- /* Drag dest. */
- gtk_drag_dest_set (GTK_WIDGET (entry),
- GTK_DEST_DEFAULT_ALL,
- drop_types, G_N_ELEMENTS (drop_types),
- GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
- g_signal_connect (entry, "drag-data-received",
- G_CALLBACK (drag_data_received_callback), NULL);
+ /* Drag dest. */
+ gtk_drag_dest_set (GTK_WIDGET (entry),
+ GTK_DEST_DEFAULT_ALL,
+ drop_types, G_N_ELEMENTS (drop_types),
+ GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+ g_signal_connect (entry, "drag-data-received",
+ G_CALLBACK (drag_data_received_callback), NULL);
- g_signal_connect_object (entry, "activate",
- G_CALLBACK (editable_activate_callback), entry, G_CONNECT_AFTER);
- g_signal_connect_object (entry, "changed",
- G_CALLBACK (editable_changed_callback), entry, 0);
+ g_signal_connect_object (entry, "activate",
+ G_CALLBACK (editable_activate_callback), entry, G_CONNECT_AFTER);
+ g_signal_connect_object (entry, "changed",
+ G_CALLBACK (editable_changed_callback), entry, 0);
}
GtkWidget *
nautilus_location_entry_new (void)
{
- GtkWidget *entry;
+ GtkWidget *entry;
- entry = gtk_widget_new (NAUTILUS_TYPE_LOCATION_ENTRY, "max-width-chars", 350, NULL);
+ entry = gtk_widget_new (NAUTILUS_TYPE_LOCATION_ENTRY, "max-width-chars", 350, NULL);
- return entry;
+ return entry;
}
void
nautilus_location_entry_set_special_text (NautilusLocationEntry *entry,
- const char *special_text)
+ const char *special_text)
{
- entry->details->has_special_text = TRUE;
-
- g_free (entry->details->special_text);
- entry->details->special_text = g_strdup (special_text);
+ entry->details->has_special_text = TRUE;
- entry->details->setting_special_text = TRUE;
- gtk_entry_set_text (GTK_ENTRY (entry), special_text);
- entry->details->setting_special_text = FALSE;
-}
+ g_free (entry->details->special_text);
+ entry->details->special_text = g_strdup (special_text);
+ entry->details->setting_special_text = TRUE;
+ gtk_entry_set_text (GTK_ENTRY (entry), special_text);
+ entry->details->setting_special_text = FALSE;
+}
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index e54d5ad39..1471e86cd 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -55,54 +54,57 @@
#endif
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- gint retval;
- NautilusApplication *application;
-
+ gint retval;
+ NautilusApplication *application;
+
#if defined (HAVE_MALLOPT) && defined(M_MMAP_THRESHOLD)
- /* Nautilus uses lots and lots of small and medium size allocations,
- * and then a few large ones for the desktop background. By default
- * glibc uses a dynamic treshold for how large allocations should
- * be mmaped. Unfortunately this triggers quickly for nautilus when
- * it does the desktop background allocations, raising the limit
- * such that a lot of temporary large allocations end up on the
- * heap and are thus not returned to the OS. To fix this we set
- * a hardcoded limit. I don't know what a good value is, but 128K
- * was the old glibc static limit, lets use that.
- */
- mallopt (M_MMAP_THRESHOLD, 128 *1024);
+ /* Nautilus uses lots and lots of small and medium size allocations,
+ * and then a few large ones for the desktop background. By default
+ * glibc uses a dynamic treshold for how large allocations should
+ * be mmaped. Unfortunately this triggers quickly for nautilus when
+ * it does the desktop background allocations, raising the limit
+ * such that a lot of temporary large allocations end up on the
+ * heap and are thus not returned to the OS. To fix this we set
+ * a hardcoded limit. I don't know what a good value is, but 128K
+ * was the old glibc static limit, lets use that.
+ */
+ mallopt (M_MMAP_THRESHOLD, 128 * 1024);
#endif
- if (g_getenv ("NAUTILUS_DEBUG") != NULL) {
- eel_make_warnings_and_criticals_stop_in_debugger ();
- }
-
- /* Initialize gettext support */
- bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
- textdomain (GETTEXT_PACKAGE);
+ if (g_getenv ("NAUTILUS_DEBUG") != NULL)
+ {
+ eel_make_warnings_and_criticals_stop_in_debugger ();
+ }
+
+ /* Initialize gettext support */
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
- g_set_prgname ("nautilus");
+ g_set_prgname ("nautilus");
#ifdef HAVE_EXEMPI
- xmp_init();
+ xmp_init ();
#endif
- nautilus_register_resource ();
- /* Run the nautilus application. */
- application = nautilus_application_new ();
+ nautilus_register_resource ();
+ /* Run the nautilus application. */
+ application = nautilus_application_new ();
- /* hold indefinitely if we're asked to persist */
- if (g_getenv ("NAUTILUS_PERSIST") != NULL) {
- g_application_hold (G_APPLICATION (application));
- }
+ /* hold indefinitely if we're asked to persist */
+ if (g_getenv ("NAUTILUS_PERSIST") != NULL)
+ {
+ g_application_hold (G_APPLICATION (application));
+ }
- retval = g_application_run (G_APPLICATION (application),
- argc, argv);
+ retval = g_application_run (G_APPLICATION (application),
+ argc, argv);
- g_object_unref (application);
+ g_object_unref (application);
- eel_debug_shut_down ();
+ eel_debug_shut_down ();
- return retval;
+ return retval;
}
diff --git a/src/nautilus-metadata.c b/src/nautilus-metadata.c
index 3147f0c8b..8316426f9 100644
--- a/src/nautilus-metadata.c
+++ b/src/nautilus-metadata.c
@@ -1,4 +1,3 @@
-
/* nautilus-metadata.c - metadata utils
*
* Copyright (C) 2009 Red Hatl, Inc.
@@ -21,53 +20,56 @@
#include "nautilus-metadata.h"
#include <glib.h>
-static char *used_metadata_names[] = {
- NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
- NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
- NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT,
- NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY,
- NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
- NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
- NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP,
- NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
- NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
- NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
- NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
- NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER,
- NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY,
- NAUTILUS_METADATA_KEY_WINDOW_SCROLL_POSITION,
- NAUTILUS_METADATA_KEY_WINDOW_SHOW_HIDDEN_FILES,
- NAUTILUS_METADATA_KEY_WINDOW_MAXIMIZED,
- NAUTILUS_METADATA_KEY_WINDOW_STICKY,
- NAUTILUS_METADATA_KEY_WINDOW_KEEP_ABOVE,
- NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_COLOR,
- NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_IMAGE,
- NAUTILUS_METADATA_KEY_SIDEBAR_BUTTONS,
- NAUTILUS_METADATA_KEY_ANNOTATION,
- NAUTILUS_METADATA_KEY_ICON_POSITION,
- NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
- NAUTILUS_METADATA_KEY_ICON_SCALE,
- NAUTILUS_METADATA_KEY_CUSTOM_ICON,
- NAUTILUS_METADATA_KEY_CUSTOM_ICON_NAME,
- NAUTILUS_METADATA_KEY_SCREEN,
- NAUTILUS_METADATA_KEY_EMBLEMS,
- NULL
+static char *used_metadata_names[] =
+{
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_COLOR,
+ NAUTILUS_METADATA_KEY_LOCATION_BACKGROUND_IMAGE,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_AUTO_LAYOUT,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_BY,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_SORT_REVERSED,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_KEEP_ALIGNED,
+ NAUTILUS_METADATA_KEY_ICON_VIEW_LAYOUT_TIMESTAMP,
+ NAUTILUS_METADATA_KEY_DESKTOP_ICON_SIZE,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_COLUMN,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_SORT_REVERSED,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS,
+ NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER,
+ NAUTILUS_METADATA_KEY_WINDOW_GEOMETRY,
+ NAUTILUS_METADATA_KEY_WINDOW_SCROLL_POSITION,
+ NAUTILUS_METADATA_KEY_WINDOW_SHOW_HIDDEN_FILES,
+ NAUTILUS_METADATA_KEY_WINDOW_MAXIMIZED,
+ NAUTILUS_METADATA_KEY_WINDOW_STICKY,
+ NAUTILUS_METADATA_KEY_WINDOW_KEEP_ABOVE,
+ NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_COLOR,
+ NAUTILUS_METADATA_KEY_SIDEBAR_BACKGROUND_IMAGE,
+ NAUTILUS_METADATA_KEY_SIDEBAR_BUTTONS,
+ NAUTILUS_METADATA_KEY_ANNOTATION,
+ NAUTILUS_METADATA_KEY_ICON_POSITION,
+ NAUTILUS_METADATA_KEY_ICON_POSITION_TIMESTAMP,
+ NAUTILUS_METADATA_KEY_ICON_SCALE,
+ NAUTILUS_METADATA_KEY_CUSTOM_ICON,
+ NAUTILUS_METADATA_KEY_CUSTOM_ICON_NAME,
+ NAUTILUS_METADATA_KEY_SCREEN,
+ NAUTILUS_METADATA_KEY_EMBLEMS,
+ NULL
};
guint
nautilus_metadata_get_id (const char *metadata)
{
- static GHashTable *hash;
- int i;
+ static GHashTable *hash;
+ int i;
- if (hash == NULL)
+ if (hash == NULL)
{
- hash = g_hash_table_new (g_str_hash, g_str_equal);
- for (i = 0; used_metadata_names[i] != NULL; i++)
- g_hash_table_insert (hash,
- used_metadata_names[i],
- GINT_TO_POINTER (i + 1));
+ hash = g_hash_table_new (g_str_hash, g_str_equal);
+ for (i = 0; used_metadata_names[i] != NULL; i++)
+ {
+ g_hash_table_insert (hash,
+ used_metadata_names[i],
+ GINT_TO_POINTER (i + 1));
+ }
}
- return GPOINTER_TO_INT (g_hash_table_lookup (hash, metadata));
+ return GPOINTER_TO_INT (g_hash_table_lookup (hash, metadata));
}
diff --git a/src/nautilus-mime-actions.c b/src/nautilus-mime-actions.c
index 1e06b7890..893070d69 100644
--- a/src/nautilus-mime-actions.c
+++ b/src/nautilus-mime-actions.c
@@ -1,24 +1,23 @@
-
/* nautilus-mime-actions.c - uri-specific versions of mime action functions
-
- Copyright (C) 2000, 2001 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Maciej Stachowiak <mjs@eazel.com>
-*/
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Maciej Stachowiak <mjs@eazel.com>
+ */
#include <config.h>
@@ -47,187 +46,173 @@
#define DEBUG_FLAG NAUTILUS_DEBUG_MIME
#include "nautilus-debug.h"
-typedef enum {
- ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE,
- ACTIVATION_ACTION_ASK,
- ACTIVATION_ACTION_LAUNCH,
- ACTIVATION_ACTION_LAUNCH_IN_TERMINAL,
- ACTIVATION_ACTION_OPEN_IN_VIEW,
- ACTIVATION_ACTION_OPEN_IN_APPLICATION,
- ACTIVATION_ACTION_EXTRACT,
- ACTIVATION_ACTION_DO_NOTHING,
+typedef enum
+{
+ ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE,
+ ACTIVATION_ACTION_ASK,
+ ACTIVATION_ACTION_LAUNCH,
+ ACTIVATION_ACTION_LAUNCH_IN_TERMINAL,
+ ACTIVATION_ACTION_OPEN_IN_VIEW,
+ ACTIVATION_ACTION_OPEN_IN_APPLICATION,
+ ACTIVATION_ACTION_EXTRACT,
+ ACTIVATION_ACTION_DO_NOTHING,
} ActivationAction;
-typedef struct {
- NautilusFile *file;
- char *uri;
+typedef struct
+{
+ NautilusFile *file;
+ char *uri;
} LaunchLocation;
-typedef struct {
- GAppInfo *application;
- GList *uris;
+typedef struct
+{
+ GAppInfo *application;
+ GList *uris;
} ApplicationLaunchParameters;
-typedef struct {
- NautilusWindowSlot *slot;
- gpointer window;
- GtkWindow *parent_window;
- GCancellable *cancellable;
- GList *locations;
- GList *mountables;
- GList *start_mountables;
- GList *not_mounted;
- NautilusWindowOpenFlags flags;
- char *timed_wait_prompt;
- gboolean timed_wait_active;
- NautilusFileListHandle *files_handle;
- gboolean tried_mounting;
- char *activation_directory;
- gboolean user_confirmation;
+typedef struct
+{
+ NautilusWindowSlot *slot;
+ gpointer window;
+ GtkWindow *parent_window;
+ GCancellable *cancellable;
+ GList *locations;
+ GList *mountables;
+ GList *start_mountables;
+ GList *not_mounted;
+ NautilusWindowOpenFlags flags;
+ char *timed_wait_prompt;
+ gboolean timed_wait_active;
+ NautilusFileListHandle *files_handle;
+ gboolean tried_mounting;
+ char *activation_directory;
+ gboolean user_confirmation;
} ActivateParameters;
-struct {
- char *name;
- char *mimetypes[20];
-} mimetype_groups[] = {
- {
- N_("Anything"),
- { NULL }
- },
- {
- N_("Files"),
- { "application/octet-stream",
- "text/plain",
- NULL
- }
- },
- {
- N_("Folders"),
- { "inode/directory",
- NULL
- }
- },
- { N_("Documents"),
- { "application/rtf",
- "application/msword",
- "application/vnd.sun.xml.writer",
- "application/vnd.sun.xml.writer.global",
- "application/vnd.sun.xml.writer.template",
- "application/vnd.oasis.opendocument.text",
- "application/vnd.oasis.opendocument.text-template",
- "application/x-abiword",
- "application/x-applix-word",
- "application/x-mswrite",
- "application/docbook+xml",
- "application/x-kword",
- "application/x-kword-crypt",
- "application/x-lyx",
- NULL
- }
- },
- { N_("Illustration"),
- { "application/illustrator",
- "application/vnd.corel-draw",
- "application/vnd.stardivision.draw",
- "application/vnd.oasis.opendocument.graphics",
- "application/x-dia-diagram",
- "application/x-karbon",
- "application/x-killustrator",
- "application/x-kivio",
- "application/x-kontour",
- "application/x-wpg",
- NULL
- }
- },
- { N_("Music"),
- { "application/ogg",
- "audio/x-vorbis+ogg",
- "audio/ac3",
- "audio/basic",
- "audio/midi",
- "audio/x-flac",
- "audio/mp4",
- "audio/mpeg",
- "audio/x-mpeg",
- "audio/x-ms-asx",
- "audio/x-pn-realaudio",
- NULL
- }
- },
- { N_("PDF / PostScript"),
- { "application/pdf",
- "application/postscript",
- "application/x-dvi",
- "image/x-eps",
- NULL
- }
- },
- { N_("Picture"),
- { "application/vnd.oasis.opendocument.image",
- "application/x-krita",
- "image/bmp",
- "image/cgm",
- "image/gif",
- "image/jpeg",
- "image/jpeg2000",
- "image/png",
- "image/svg+xml",
- "image/tiff",
- "image/x-compressed-xcf",
- "image/x-pcx",
- "image/x-photo-cd",
- "image/x-psd",
- "image/x-tga",
- "image/x-xcf",
- NULL
- }
- },
- { N_("Presentation"),
- { "application/vnd.ms-powerpoint",
- "application/vnd.sun.xml.impress",
- "application/vnd.oasis.opendocument.presentation",
- "application/x-magicpoint",
- "application/x-kpresenter",
- NULL
- }
- },
- { N_("Spreadsheet"),
- { "application/vnd.lotus-1-2-3",
- "application/vnd.ms-excel",
- "application/vnd.stardivision.calc",
- "application/vnd.sun.xml.calc",
- "application/vnd.oasis.opendocument.spreadsheet",
- "application/x-applix-spreadsheet",
- "application/x-gnumeric",
- "application/x-kspread",
- "application/x-kspread-crypt",
- "application/x-quattropro",
- "application/x-sc",
- "application/x-siag",
- NULL
- }
- },
- { N_("Text File"),
- { "text/plain",
- NULL
- }
- },
- { N_("Video"),
- { "video/mp4",
- "video/3gpp",
- "video/mpeg",
- "video/quicktime",
- "video/vivo",
- "video/x-avi",
- "video/x-mng",
- "video/x-ms-asf",
- "video/x-ms-wmv",
- "video/x-msvideo",
- "video/x-nsv",
- "video/x-real-video",
- NULL
- }
- }
+struct
+{
+ char *name;
+ char *mimetypes[20];
+} mimetype_groups[] =
+{
+ {
+ N_("Anything"),
+ { NULL }
+},
+ {
+ N_("Files"),
+ { "application/octet-stream",
+ "text/plain",
+ NULL}
+},
+ {
+ N_("Folders"),
+ { "inode/directory",
+ NULL}
+},
+ { N_("Documents"),
+ { "application/rtf",
+ "application/msword",
+ "application/vnd.sun.xml.writer",
+ "application/vnd.sun.xml.writer.global",
+ "application/vnd.sun.xml.writer.template",
+ "application/vnd.oasis.opendocument.text",
+ "application/vnd.oasis.opendocument.text-template",
+ "application/x-abiword",
+ "application/x-applix-word",
+ "application/x-mswrite",
+ "application/docbook+xml",
+ "application/x-kword",
+ "application/x-kword-crypt",
+ "application/x-lyx",
+ NULL}},
+ { N_("Illustration"),
+ { "application/illustrator",
+ "application/vnd.corel-draw",
+ "application/vnd.stardivision.draw",
+ "application/vnd.oasis.opendocument.graphics",
+ "application/x-dia-diagram",
+ "application/x-karbon",
+ "application/x-killustrator",
+ "application/x-kivio",
+ "application/x-kontour",
+ "application/x-wpg",
+ NULL}},
+ { N_("Music"),
+ { "application/ogg",
+ "audio/x-vorbis+ogg",
+ "audio/ac3",
+ "audio/basic",
+ "audio/midi",
+ "audio/x-flac",
+ "audio/mp4",
+ "audio/mpeg",
+ "audio/x-mpeg",
+ "audio/x-ms-asx",
+ "audio/x-pn-realaudio",
+ NULL}},
+ { N_("PDF / PostScript"),
+ { "application/pdf",
+ "application/postscript",
+ "application/x-dvi",
+ "image/x-eps",
+ NULL}},
+ { N_("Picture"),
+ { "application/vnd.oasis.opendocument.image",
+ "application/x-krita",
+ "image/bmp",
+ "image/cgm",
+ "image/gif",
+ "image/jpeg",
+ "image/jpeg2000",
+ "image/png",
+ "image/svg+xml",
+ "image/tiff",
+ "image/x-compressed-xcf",
+ "image/x-pcx",
+ "image/x-photo-cd",
+ "image/x-psd",
+ "image/x-tga",
+ "image/x-xcf",
+ NULL}},
+ { N_("Presentation"),
+ { "application/vnd.ms-powerpoint",
+ "application/vnd.sun.xml.impress",
+ "application/vnd.oasis.opendocument.presentation",
+ "application/x-magicpoint",
+ "application/x-kpresenter",
+ NULL}},
+ { N_("Spreadsheet"),
+ { "application/vnd.lotus-1-2-3",
+ "application/vnd.ms-excel",
+ "application/vnd.stardivision.calc",
+ "application/vnd.sun.xml.calc",
+ "application/vnd.oasis.opendocument.spreadsheet",
+ "application/x-applix-spreadsheet",
+ "application/x-gnumeric",
+ "application/x-kspread",
+ "application/x-kspread-crypt",
+ "application/x-quattropro",
+ "application/x-sc",
+ "application/x-siag",
+ NULL}},
+ { N_("Text File"),
+ { "text/plain",
+ NULL}},
+ { N_("Video"),
+ { "video/mp4",
+ "video/3gpp",
+ "video/mpeg",
+ "video/quicktime",
+ "video/vivo",
+ "video/x-avi",
+ "video/x-mng",
+ "video/x-ms-asf",
+ "video/x-ms-wmv",
+ "video/x-msvideo",
+ "video/x-nsv",
+ "video/x-real-video",
+ NULL}}
};
/* Number of seconds until cancel dialog shows up */
@@ -248,533 +233,598 @@ struct {
*/
#define MAX_URI_IN_DIALOG_LENGTH 60
-static void cancel_activate_callback (gpointer callback_data);
-static void activate_activation_uris_ready_callback (GList *files,
- gpointer callback_data);
-static void activation_mount_mountables (ActivateParameters *parameters);
-static void activation_start_mountables (ActivateParameters *parameters);
-static void activate_callback (GList *files,
- gpointer callback_data);
-static void activation_mount_not_mounted (ActivateParameters *parameters);
+static void cancel_activate_callback (gpointer callback_data);
+static void activate_activation_uris_ready_callback (GList *files,
+ gpointer callback_data);
+static void activation_mount_mountables (ActivateParameters *parameters);
+static void activation_start_mountables (ActivateParameters *parameters);
+static void activate_callback (GList *files,
+ gpointer callback_data);
+static void activation_mount_not_mounted (ActivateParameters *parameters);
static void
launch_location_free (LaunchLocation *location)
{
- nautilus_file_unref (location->file);
- g_free (location->uri);
- g_free (location);
+ nautilus_file_unref (location->file);
+ g_free (location->uri);
+ g_free (location);
}
static void
launch_location_list_free (GList *list)
{
- g_list_foreach (list, (GFunc)launch_location_free, NULL);
- g_list_free (list);
+ g_list_foreach (list, (GFunc) launch_location_free, NULL);
+ g_list_free (list);
}
static GList *
get_file_list_for_launch_locations (GList *locations)
{
- GList *files, *l;
- LaunchLocation *location;
+ GList *files, *l;
+ LaunchLocation *location;
- files = NULL;
- for (l = locations; l != NULL; l = l->next) {
- location = l->data;
+ files = NULL;
+ for (l = locations; l != NULL; l = l->next)
+ {
+ location = l->data;
- files = g_list_prepend (files,
- nautilus_file_ref (location->file));
- }
- return g_list_reverse (files);
+ files = g_list_prepend (files,
+ nautilus_file_ref (location->file));
+ }
+ return g_list_reverse (files);
}
static LaunchLocation *
launch_location_from_file (NautilusFile *file)
{
- LaunchLocation *location;
- location = g_new (LaunchLocation, 1);
- location->file = nautilus_file_ref (file);
- location->uri = nautilus_file_get_uri (file);
-
- return location;
+ LaunchLocation *location;
+ location = g_new (LaunchLocation, 1);
+ location->file = nautilus_file_ref (file);
+ location->uri = nautilus_file_get_uri (file);
+
+ return location;
}
static void
launch_location_update_from_file (LaunchLocation *location,
- NautilusFile *file)
+ NautilusFile *file)
{
- nautilus_file_unref (location->file);
- g_free (location->uri);
- location->file = nautilus_file_ref (file);
- location->uri = nautilus_file_get_uri (file);
+ nautilus_file_unref (location->file);
+ g_free (location->uri);
+ location->file = nautilus_file_ref (file);
+ location->uri = nautilus_file_get_uri (file);
}
static void
launch_location_update_from_uri (LaunchLocation *location,
- const char *uri)
+ const char *uri)
{
- nautilus_file_unref (location->file);
- g_free (location->uri);
- location->file = nautilus_file_get_by_uri (uri);
- location->uri = g_strdup (uri);
+ nautilus_file_unref (location->file);
+ g_free (location->uri);
+ location->file = nautilus_file_get_by_uri (uri);
+ location->uri = g_strdup (uri);
}
static LaunchLocation *
-find_launch_location_for_file (GList *list,
- NautilusFile *file)
+find_launch_location_for_file (GList *list,
+ NautilusFile *file)
{
- LaunchLocation *location;
- GList *l;
+ LaunchLocation *location;
+ GList *l;
- for (l = list; l != NULL; l = l->next) {
- location = l->data;
+ for (l = list; l != NULL; l = l->next)
+ {
+ location = l->data;
- if (location->file == file) {
- return location;
- }
- }
- return NULL;
+ if (location->file == file)
+ {
+ return location;
+ }
+ }
+ return NULL;
}
static GList *
launch_locations_from_file_list (GList *list)
{
- GList *new;
+ GList *new;
- new = NULL;
- while (list) {
- new = g_list_prepend (new,
- launch_location_from_file (list->data));
- list = list->next;
- }
- new = g_list_reverse (new);
- return new;
+ new = NULL;
+ while (list)
+ {
+ new = g_list_prepend (new,
+ launch_location_from_file (list->data));
+ list = list->next;
+ }
+ new = g_list_reverse (new);
+ return new;
}
static ApplicationLaunchParameters *
application_launch_parameters_new (GAppInfo *application,
- GList *uris)
+ GList *uris)
{
- ApplicationLaunchParameters *result;
+ ApplicationLaunchParameters *result;
- result = g_new0 (ApplicationLaunchParameters, 1);
- result->application = g_object_ref (application);
- result->uris = g_list_copy_deep (uris, (GCopyFunc) g_strdup, NULL);
+ result = g_new0 (ApplicationLaunchParameters, 1);
+ result->application = g_object_ref (application);
+ result->uris = g_list_copy_deep (uris, (GCopyFunc) g_strdup, NULL);
- return result;
+ return result;
}
static void
application_launch_parameters_free (ApplicationLaunchParameters *parameters)
{
- g_object_unref (parameters->application);
- g_list_free_full (parameters->uris, g_free);
+ g_object_unref (parameters->application);
+ g_list_free_full (parameters->uris, g_free);
- g_free (parameters);
+ g_free (parameters);
}
static gboolean
nautilus_mime_actions_check_if_required_attributes_ready (NautilusFile *file)
{
- NautilusFileAttributes attributes;
- gboolean ready;
+ NautilusFileAttributes attributes;
+ gboolean ready;
- attributes = nautilus_mime_actions_get_required_file_attributes ();
- ready = nautilus_file_check_if_ready (file, attributes);
+ attributes = nautilus_mime_actions_get_required_file_attributes ();
+ ready = nautilus_file_check_if_ready (file, attributes);
- return ready;
+ return ready;
}
-NautilusFileAttributes
+NautilusFileAttributes
nautilus_mime_actions_get_required_file_attributes (void)
{
- return NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO;
+ return NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO;
}
GAppInfo *
nautilus_mime_get_default_application_for_file (NautilusFile *file)
{
- GAppInfo *app;
- char *mime_type;
- char *uri_scheme;
+ GAppInfo *app;
+ char *mime_type;
+ char *uri_scheme;
- if (!nautilus_mime_actions_check_if_required_attributes_ready (file)) {
- return NULL;
- }
+ if (!nautilus_mime_actions_check_if_required_attributes_ready (file))
+ {
+ return NULL;
+ }
- mime_type = nautilus_file_get_mime_type (file);
- app = g_app_info_get_default_for_type (mime_type,
- !nautilus_file_is_local_or_fuse (file));
- g_free (mime_type);
+ mime_type = nautilus_file_get_mime_type (file);
+ app = g_app_info_get_default_for_type (mime_type,
+ !nautilus_file_is_local_or_fuse (file));
+ g_free (mime_type);
+
+ if (app == NULL)
+ {
+ uri_scheme = nautilus_file_get_uri_scheme (file);
+ if (uri_scheme != NULL)
+ {
+ app = g_app_info_get_default_for_uri_scheme (uri_scheme);
+ g_free (uri_scheme);
+ }
+ }
- if (app == NULL) {
- uri_scheme = nautilus_file_get_uri_scheme (file);
- if (uri_scheme != NULL) {
- app = g_app_info_get_default_for_uri_scheme (uri_scheme);
- g_free (uri_scheme);
- }
- }
-
- return app;
+ return app;
}
static int
file_compare_by_mime_type (NautilusFile *file_a,
- NautilusFile *file_b)
-{
- char *mime_type_a, *mime_type_b;
- int ret;
-
- mime_type_a = nautilus_file_get_mime_type (file_a);
- mime_type_b = nautilus_file_get_mime_type (file_b);
-
- ret = strcmp (mime_type_a, mime_type_b);
-
- g_free (mime_type_a);
- g_free (mime_type_b);
-
- return ret;
+ NautilusFile *file_b)
+{
+ char *mime_type_a, *mime_type_b;
+ int ret;
+
+ mime_type_a = nautilus_file_get_mime_type (file_a);
+ mime_type_b = nautilus_file_get_mime_type (file_b);
+
+ ret = strcmp (mime_type_a, mime_type_b);
+
+ g_free (mime_type_a);
+ g_free (mime_type_b);
+
+ return ret;
}
static int
file_compare_by_parent_uri (NautilusFile *file_a,
- NautilusFile *file_b) {
- char *parent_uri_a, *parent_uri_b;
- int ret;
+ NautilusFile *file_b)
+{
+ char *parent_uri_a, *parent_uri_b;
+ int ret;
- parent_uri_a = nautilus_file_get_parent_uri (file_a);
- parent_uri_b = nautilus_file_get_parent_uri (file_b);
+ parent_uri_a = nautilus_file_get_parent_uri (file_a);
+ parent_uri_b = nautilus_file_get_parent_uri (file_b);
- ret = strcmp (parent_uri_a, parent_uri_b);
+ ret = strcmp (parent_uri_a, parent_uri_b);
- g_free (parent_uri_a);
- g_free (parent_uri_b);
+ g_free (parent_uri_a);
+ g_free (parent_uri_b);
- return ret;
+ return ret;
}
GAppInfo *
nautilus_mime_get_default_application_for_files (GList *files)
{
- GList *l, *sorted_files;
- NautilusFile *file;
- GAppInfo *app, *one_app;
+ GList *l, *sorted_files;
+ NautilusFile *file;
+ GAppInfo *app, *one_app;
- g_assert (files != NULL);
+ g_assert (files != NULL);
- sorted_files = g_list_sort (g_list_copy (files), (GCompareFunc) file_compare_by_mime_type);
+ sorted_files = g_list_sort (g_list_copy (files), (GCompareFunc) file_compare_by_mime_type);
- app = NULL;
- for (l = sorted_files; l != NULL; l = l->next) {
- file = l->data;
+ app = NULL;
+ for (l = sorted_files; l != NULL; l = l->next)
+ {
+ file = l->data;
- if (l->prev &&
- file_compare_by_mime_type (file, l->prev->data) == 0 &&
- file_compare_by_parent_uri (file, l->prev->data) == 0) {
- continue;
- }
+ if (l->prev &&
+ file_compare_by_mime_type (file, l->prev->data) == 0 &&
+ file_compare_by_parent_uri (file, l->prev->data) == 0)
+ {
+ continue;
+ }
- one_app = nautilus_mime_get_default_application_for_file (file);
- if (one_app == NULL || (app != NULL && !g_app_info_equal (app, one_app))) {
- if (app) {
- g_object_unref (app);
- }
- if (one_app) {
- g_object_unref (one_app);
- }
- app = NULL;
- break;
- }
+ one_app = nautilus_mime_get_default_application_for_file (file);
+ if (one_app == NULL || (app != NULL && !g_app_info_equal (app, one_app)))
+ {
+ if (app)
+ {
+ g_object_unref (app);
+ }
+ if (one_app)
+ {
+ g_object_unref (one_app);
+ }
+ app = NULL;
+ break;
+ }
- if (app == NULL) {
- app = one_app;
- } else {
- g_object_unref (one_app);
- }
- }
+ if (app == NULL)
+ {
+ app = one_app;
+ }
+ else
+ {
+ g_object_unref (one_app);
+ }
+ }
- g_list_free (sorted_files);
+ g_list_free (sorted_files);
- return app;
+ return app;
}
static void
-trash_or_delete_files (GtkWindow *parent_window,
- const GList *files,
- gboolean delete_if_all_already_in_trash)
-{
- GList *locations;
- const GList *node;
-
- locations = NULL;
- for (node = files; node != NULL; node = node->next) {
- locations = g_list_prepend (locations,
- nautilus_file_get_location ((NautilusFile *) node->data));
- }
-
- locations = g_list_reverse (locations);
-
- nautilus_file_operations_trash_or_delete (locations,
- parent_window,
- NULL, NULL);
- g_list_free_full (locations, g_object_unref);
+trash_or_delete_files (GtkWindow *parent_window,
+ const GList *files,
+ gboolean delete_if_all_already_in_trash)
+{
+ GList *locations;
+ const GList *node;
+
+ locations = NULL;
+ for (node = files; node != NULL; node = node->next)
+ {
+ locations = g_list_prepend (locations,
+ nautilus_file_get_location ((NautilusFile *) node->data));
+ }
+
+ locations = g_list_reverse (locations);
+
+ nautilus_file_operations_trash_or_delete (locations,
+ parent_window,
+ NULL, NULL);
+ g_list_free_full (locations, g_object_unref);
}
static void
-report_broken_symbolic_link (GtkWindow *parent_window, NautilusFile *file)
-{
- char *target_path;
- char *display_name;
- char *prompt;
- char *detail;
- GtkDialog *dialog;
- GList file_as_list;
- int response;
- gboolean can_trash;
-
- g_assert (nautilus_file_is_broken_symbolic_link (file));
-
- display_name = nautilus_file_get_display_name (file);
- can_trash = nautilus_file_can_trash (file) && !nautilus_file_is_in_trash (file);
-
- if (can_trash) {
- prompt = g_strdup_printf (_("The link “%s” is broken. Move it to Trash?"), display_name);
- } else {
- prompt = g_strdup_printf (_("The link “%s” is broken."), display_name);
- }
- g_free (display_name);
-
- target_path = nautilus_file_get_symbolic_link_target_path (file);
- if (target_path == NULL) {
- detail = g_strdup (_("This link cannot be used because it has no target."));
- } else {
- detail = g_strdup_printf (_("This link cannot be used because its target "
- "“%s” doesn't exist."), target_path);
- }
-
- if (!can_trash) {
- eel_run_simple_dialog (GTK_WIDGET (parent_window), FALSE, GTK_MESSAGE_WARNING,
- prompt, detail, _("_Cancel"), NULL);
- goto out;
- }
-
- dialog = eel_show_yes_no_dialog (prompt, detail, _("Mo_ve to Trash"), _("_Cancel"),
- parent_window);
-
- gtk_dialog_set_default_response (dialog, GTK_RESPONSE_CANCEL);
-
- /* Make this modal to avoid problems with reffing the view & file
- * to keep them around in case the view changes, which would then
- * cause the old view not to be destroyed, which would cause its
- * merged Bonobo items not to be un-merged. Maybe we need to unmerge
- * explicitly when disconnecting views instead of relying on the
- * unmerge in Destroy. But since BonoboUIHandler is probably going
- * to change wildly, I don't want to mess with this now.
- */
-
- response = gtk_dialog_run (dialog);
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- if (response == GTK_RESPONSE_YES) {
- file_as_list.data = file;
- file_as_list.next = NULL;
- file_as_list.prev = NULL;
- trash_or_delete_files (parent_window, &file_as_list, TRUE);
- }
+report_broken_symbolic_link (GtkWindow *parent_window,
+ NautilusFile *file)
+{
+ char *target_path;
+ char *display_name;
+ char *prompt;
+ char *detail;
+ GtkDialog *dialog;
+ GList file_as_list;
+ int response;
+ gboolean can_trash;
+
+ g_assert (nautilus_file_is_broken_symbolic_link (file));
+
+ display_name = nautilus_file_get_display_name (file);
+ can_trash = nautilus_file_can_trash (file) && !nautilus_file_is_in_trash (file);
+
+ if (can_trash)
+ {
+ prompt = g_strdup_printf (_("The link “%s” is broken. Move it to Trash?"), display_name);
+ }
+ else
+ {
+ prompt = g_strdup_printf (_("The link “%s” is broken."), display_name);
+ }
+ g_free (display_name);
+
+ target_path = nautilus_file_get_symbolic_link_target_path (file);
+ if (target_path == NULL)
+ {
+ detail = g_strdup (_("This link cannot be used because it has no target."));
+ }
+ else
+ {
+ detail = g_strdup_printf (_("This link cannot be used because its target "
+ "“%s” doesn't exist."), target_path);
+ }
+
+ if (!can_trash)
+ {
+ eel_run_simple_dialog (GTK_WIDGET (parent_window), FALSE, GTK_MESSAGE_WARNING,
+ prompt, detail, _("_Cancel"), NULL);
+ goto out;
+ }
+
+ dialog = eel_show_yes_no_dialog (prompt, detail, _("Mo_ve to Trash"), _("_Cancel"),
+ parent_window);
+
+ gtk_dialog_set_default_response (dialog, GTK_RESPONSE_CANCEL);
+
+ /* Make this modal to avoid problems with reffing the view & file
+ * to keep them around in case the view changes, which would then
+ * cause the old view not to be destroyed, which would cause its
+ * merged Bonobo items not to be un-merged. Maybe we need to unmerge
+ * explicitly when disconnecting views instead of relying on the
+ * unmerge in Destroy. But since BonoboUIHandler is probably going
+ * to change wildly, I don't want to mess with this now.
+ */
+
+ response = gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ if (response == GTK_RESPONSE_YES)
+ {
+ file_as_list.data = file;
+ file_as_list.next = NULL;
+ file_as_list.prev = NULL;
+ trash_or_delete_files (parent_window, &file_as_list, TRUE);
+ }
out:
- g_free (prompt);
- g_free (target_path);
- g_free (detail);
+ g_free (prompt);
+ g_free (target_path);
+ g_free (detail);
}
static ActivationAction
-get_executable_text_file_action (GtkWindow *parent_window, NautilusFile *file)
-{
- GtkDialog *dialog;
- char *file_name;
- char *prompt;
- char *detail;
- int preferences_value;
- int response;
-
- g_assert (nautilus_file_contains_text (file));
-
- preferences_value = g_settings_get_enum (nautilus_preferences,
- NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
- switch (preferences_value) {
- case NAUTILUS_EXECUTABLE_TEXT_LAUNCH:
- return ACTIVATION_ACTION_LAUNCH;
- case NAUTILUS_EXECUTABLE_TEXT_DISPLAY:
- return ACTIVATION_ACTION_OPEN_IN_APPLICATION;
- case NAUTILUS_EXECUTABLE_TEXT_ASK:
- break;
- default:
- /* Complain non-fatally, since preference data can't be trusted */
- g_warning ("Unknown value %d for NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION",
- preferences_value);
-
- }
-
-
- file_name = nautilus_file_get_display_name (file);
- prompt = g_strdup_printf (_("Do you want to run “%s”, or display its contents?"),
- file_name);
- detail = g_strdup_printf (_("“%s” is an executable text file."),
- file_name);
- g_free (file_name);
-
- dialog = eel_create_question_dialog (prompt,
- detail,
- _("Run in _Terminal"), RESPONSE_RUN_IN_TERMINAL,
- _("_Display"), RESPONSE_DISPLAY,
- parent_window);
- gtk_dialog_add_button (dialog, _("_Cancel"), GTK_RESPONSE_CANCEL);
- gtk_dialog_add_button (dialog, _("_Run"), RESPONSE_RUN);
- gtk_dialog_set_default_response (dialog, GTK_RESPONSE_CANCEL);
- gtk_widget_show (GTK_WIDGET (dialog));
-
- g_free (prompt);
- g_free (detail);
-
- response = gtk_dialog_run (dialog);
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- switch (response) {
- case RESPONSE_RUN:
- return ACTIVATION_ACTION_LAUNCH;
- case RESPONSE_RUN_IN_TERMINAL:
- return ACTIVATION_ACTION_LAUNCH_IN_TERMINAL;
- case RESPONSE_DISPLAY:
- return ACTIVATION_ACTION_OPEN_IN_APPLICATION;
- default:
- return ACTIVATION_ACTION_DO_NOTHING;
- }
+get_executable_text_file_action (GtkWindow *parent_window,
+ NautilusFile *file)
+{
+ GtkDialog *dialog;
+ char *file_name;
+ char *prompt;
+ char *detail;
+ int preferences_value;
+ int response;
+
+ g_assert (nautilus_file_contains_text (file));
+
+ preferences_value = g_settings_get_enum (nautilus_preferences,
+ NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
+ switch (preferences_value)
+ {
+ case NAUTILUS_EXECUTABLE_TEXT_LAUNCH:
+ {
+ return ACTIVATION_ACTION_LAUNCH;
+ }
+
+ case NAUTILUS_EXECUTABLE_TEXT_DISPLAY:
+ {
+ return ACTIVATION_ACTION_OPEN_IN_APPLICATION;
+ }
+
+ case NAUTILUS_EXECUTABLE_TEXT_ASK:
+ {
+ }
+ break;
+
+ default:
+ /* Complain non-fatally, since preference data can't be trusted */
+ g_warning ("Unknown value %d for NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION",
+ preferences_value);
+ }
+
+
+ file_name = nautilus_file_get_display_name (file);
+ prompt = g_strdup_printf (_("Do you want to run “%s”, or display its contents?"),
+ file_name);
+ detail = g_strdup_printf (_("“%s” is an executable text file."),
+ file_name);
+ g_free (file_name);
+
+ dialog = eel_create_question_dialog (prompt,
+ detail,
+ _("Run in _Terminal"), RESPONSE_RUN_IN_TERMINAL,
+ _("_Display"), RESPONSE_DISPLAY,
+ parent_window);
+ gtk_dialog_add_button (dialog, _("_Cancel"), GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (dialog, _("_Run"), RESPONSE_RUN);
+ gtk_dialog_set_default_response (dialog, GTK_RESPONSE_CANCEL);
+ gtk_widget_show (GTK_WIDGET (dialog));
+
+ g_free (prompt);
+ g_free (detail);
+
+ response = gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ switch (response)
+ {
+ case RESPONSE_RUN:
+ {
+ return ACTIVATION_ACTION_LAUNCH;
+ }
+
+ case RESPONSE_RUN_IN_TERMINAL:
+ {
+ return ACTIVATION_ACTION_LAUNCH_IN_TERMINAL;
+ }
+
+ case RESPONSE_DISPLAY:
+ {
+ return ACTIVATION_ACTION_OPEN_IN_APPLICATION;
+ }
+
+ default:
+ return ACTIVATION_ACTION_DO_NOTHING;
+ }
}
static ActivationAction
get_default_executable_text_file_action (void)
{
- int preferences_value;
-
- preferences_value = g_settings_get_enum (nautilus_preferences,
- NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
- switch (preferences_value) {
- case NAUTILUS_EXECUTABLE_TEXT_LAUNCH:
- return ACTIVATION_ACTION_LAUNCH;
- case NAUTILUS_EXECUTABLE_TEXT_DISPLAY:
- return ACTIVATION_ACTION_OPEN_IN_APPLICATION;
- case NAUTILUS_EXECUTABLE_TEXT_ASK:
- default:
- return ACTIVATION_ACTION_ASK;
- }
+ int preferences_value;
+
+ preferences_value = g_settings_get_enum (nautilus_preferences,
+ NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION);
+ switch (preferences_value)
+ {
+ case NAUTILUS_EXECUTABLE_TEXT_LAUNCH:
+ {
+ return ACTIVATION_ACTION_LAUNCH;
+ }
+
+ case NAUTILUS_EXECUTABLE_TEXT_DISPLAY:
+ {
+ return ACTIVATION_ACTION_OPEN_IN_APPLICATION;
+ }
+
+ case NAUTILUS_EXECUTABLE_TEXT_ASK:
+ default:
+ return ACTIVATION_ACTION_ASK;
+ }
}
static ActivationAction
get_activation_action (NautilusFile *file)
{
- ActivationAction action;
- char *activation_uri;
- gboolean can_extract;
- can_extract = g_settings_get_boolean (nautilus_preferences,
- NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
+ ActivationAction action;
+ char *activation_uri;
+ gboolean can_extract;
+ can_extract = g_settings_get_boolean (nautilus_preferences,
+ NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
+
+ if (can_extract && nautilus_file_is_archive (file))
+ {
+ return ACTIVATION_ACTION_EXTRACT;
+ }
+
+ if (nautilus_file_is_nautilus_link (file))
+ {
+ return ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE;
+ }
+
+ activation_uri = nautilus_file_get_activation_uri (file);
+ if (activation_uri == NULL)
+ {
+ activation_uri = nautilus_file_get_uri (file);
+ }
+
+ action = ACTIVATION_ACTION_DO_NOTHING;
+ if (nautilus_file_is_launchable (file))
+ {
+ char *executable_path;
+
+ action = ACTIVATION_ACTION_LAUNCH;
+
+ executable_path = g_filename_from_uri (activation_uri, NULL, NULL);
+ if (!executable_path)
+ {
+ action = ACTIVATION_ACTION_DO_NOTHING;
+ }
+ else if (nautilus_file_contains_text (file))
+ {
+ action = get_default_executable_text_file_action ();
+ }
+ g_free (executable_path);
+ }
- if (can_extract && nautilus_file_is_archive (file)) {
- return ACTIVATION_ACTION_EXTRACT;
+ if (action == ACTIVATION_ACTION_DO_NOTHING)
+ {
+ if (nautilus_file_opens_in_view (file))
+ {
+ action = ACTIVATION_ACTION_OPEN_IN_VIEW;
}
+ else
+ {
+ action = ACTIVATION_ACTION_OPEN_IN_APPLICATION;
+ }
+ }
+ g_free (activation_uri);
- if (nautilus_file_is_nautilus_link (file)) {
- return ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE;
- }
-
- activation_uri = nautilus_file_get_activation_uri (file);
- if (activation_uri == NULL) {
- activation_uri = nautilus_file_get_uri (file);
- }
-
- action = ACTIVATION_ACTION_DO_NOTHING;
- if (nautilus_file_is_launchable (file)) {
- char *executable_path;
-
- action = ACTIVATION_ACTION_LAUNCH;
-
- executable_path = g_filename_from_uri (activation_uri, NULL, NULL);
- if (!executable_path) {
- action = ACTIVATION_ACTION_DO_NOTHING;
- } else if (nautilus_file_contains_text (file)) {
- action = get_default_executable_text_file_action ();
- }
- g_free (executable_path);
- }
-
- if (action == ACTIVATION_ACTION_DO_NOTHING) {
- if (nautilus_file_opens_in_view (file)) {
- action = ACTIVATION_ACTION_OPEN_IN_VIEW;
- } else {
- action = ACTIVATION_ACTION_OPEN_IN_APPLICATION;
- }
- }
- g_free (activation_uri);
-
- return action;
+ return action;
}
gboolean
nautilus_mime_file_extracts (NautilusFile *file)
{
- return get_activation_action (file) == ACTIVATION_ACTION_EXTRACT;
+ return get_activation_action (file) == ACTIVATION_ACTION_EXTRACT;
}
gboolean
nautilus_mime_file_launches (NautilusFile *file)
{
- ActivationAction activation_action;
+ ActivationAction activation_action;
- activation_action = get_activation_action (file);
+ activation_action = get_activation_action (file);
- return (activation_action == ACTIVATION_ACTION_LAUNCH);
+ return (activation_action == ACTIVATION_ACTION_LAUNCH);
}
gboolean
nautilus_mime_file_opens_in_external_app (NautilusFile *file)
{
- ActivationAction activation_action;
-
- activation_action = get_activation_action (file);
-
- return (activation_action == ACTIVATION_ACTION_OPEN_IN_APPLICATION);
+ ActivationAction activation_action;
+
+ activation_action = get_activation_action (file);
+
+ return (activation_action == ACTIVATION_ACTION_OPEN_IN_APPLICATION);
}
static unsigned int
mime_application_hash (GAppInfo *app)
{
- const char *id;
+ const char *id;
- id = g_app_info_get_id (app);
+ id = g_app_info_get_id (app);
- if (id == NULL) {
- return GPOINTER_TO_UINT(app);
- }
+ if (id == NULL)
+ {
+ return GPOINTER_TO_UINT (app);
+ }
- return g_str_hash (id);
+ return g_str_hash (id);
}
static void
-list_to_parameters_foreach (GAppInfo *application,
- GList *uris,
- GList **ret)
+list_to_parameters_foreach (GAppInfo *application,
+ GList *uris,
+ GList **ret)
{
- ApplicationLaunchParameters *parameters;
+ ApplicationLaunchParameters *parameters;
- uris = g_list_reverse (uris);
+ uris = g_list_reverse (uris);
- parameters = application_launch_parameters_new
- (application, uris);
- *ret = g_list_prepend (*ret, parameters);
+ parameters = application_launch_parameters_new
+ (application, uris);
+ *ret = g_list_prepend (*ret, parameters);
}
@@ -787,1533 +837,1699 @@ list_to_parameters_foreach (GAppInfo *application,
*
* @files: Files to use for construction.
* @unhandled_files: Files without any default application will be put here.
- *
+ *
* Return value: Newly allocated list of ApplicationLaunchParameters.
**/
static GList *
-make_activation_parameters (GList *uris,
- GList **unhandled_uris)
-{
- GList *ret, *l, *app_uris;
- NautilusFile *file;
- GAppInfo *app, *old_app;
- GHashTable *app_table;
- char *uri;
-
- ret = NULL;
- *unhandled_uris = NULL;
-
- app_table = g_hash_table_new_full
- ((GHashFunc) mime_application_hash,
- (GEqualFunc) g_app_info_equal,
- (GDestroyNotify) g_object_unref,
- (GDestroyNotify) g_list_free);
-
- for (l = uris; l != NULL; l = l->next) {
- uri = l->data;
- file = nautilus_file_get_by_uri (uri);
-
- app = nautilus_mime_get_default_application_for_file (file);
- if (app != NULL) {
- app_uris = NULL;
-
- if (g_hash_table_lookup_extended (app_table, app,
- (gpointer *) &old_app,
- (gpointer *) &app_uris)) {
- g_hash_table_steal (app_table, old_app);
-
- app_uris = g_list_prepend (app_uris, uri);
-
- g_object_unref (app);
- app = old_app;
- } else {
- app_uris = g_list_prepend (NULL, uri);
- }
-
- g_hash_table_insert (app_table, app, app_uris);
- } else {
- *unhandled_uris = g_list_prepend (*unhandled_uris, uri);
- }
- nautilus_file_unref (file);
- }
+make_activation_parameters (GList *uris,
+ GList **unhandled_uris)
+{
+ GList *ret, *l, *app_uris;
+ NautilusFile *file;
+ GAppInfo *app, *old_app;
+ GHashTable *app_table;
+ char *uri;
+
+ ret = NULL;
+ *unhandled_uris = NULL;
+
+ app_table = g_hash_table_new_full
+ ((GHashFunc) mime_application_hash,
+ (GEqualFunc) g_app_info_equal,
+ (GDestroyNotify) g_object_unref,
+ (GDestroyNotify) g_list_free);
+
+ for (l = uris; l != NULL; l = l->next)
+ {
+ uri = l->data;
+ file = nautilus_file_get_by_uri (uri);
+
+ app = nautilus_mime_get_default_application_for_file (file);
+ if (app != NULL)
+ {
+ app_uris = NULL;
+
+ if (g_hash_table_lookup_extended (app_table, app,
+ (gpointer *) &old_app,
+ (gpointer *) &app_uris))
+ {
+ g_hash_table_steal (app_table, old_app);
+
+ app_uris = g_list_prepend (app_uris, uri);
+
+ g_object_unref (app);
+ app = old_app;
+ }
+ else
+ {
+ app_uris = g_list_prepend (NULL, uri);
+ }
+
+ g_hash_table_insert (app_table, app, app_uris);
+ }
+ else
+ {
+ *unhandled_uris = g_list_prepend (*unhandled_uris, uri);
+ }
+ nautilus_file_unref (file);
+ }
- g_hash_table_foreach (app_table,
- (GHFunc) list_to_parameters_foreach,
- &ret);
+ g_hash_table_foreach (app_table,
+ (GHFunc) list_to_parameters_foreach,
+ &ret);
- g_hash_table_destroy (app_table);
+ g_hash_table_destroy (app_table);
- *unhandled_uris = g_list_reverse (*unhandled_uris);
+ *unhandled_uris = g_list_reverse (*unhandled_uris);
- return g_list_reverse (ret);
+ return g_list_reverse (ret);
}
static gboolean
file_was_cancelled (NautilusFile *file)
{
- GError *error;
-
- error = nautilus_file_get_file_info_error (file);
- return
- error != NULL &&
- error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_CANCELLED;
+ GError *error;
+
+ error = nautilus_file_get_file_info_error (file);
+ return
+ error != NULL &&
+ error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_CANCELLED;
}
static gboolean
file_was_not_mounted (NautilusFile *file)
{
- GError *error;
-
- error = nautilus_file_get_file_info_error (file);
- return
- error != NULL &&
- error->domain == G_IO_ERROR &&
- error->code == G_IO_ERROR_NOT_MOUNTED;
+ GError *error;
+
+ error = nautilus_file_get_file_info_error (file);
+ return
+ error != NULL &&
+ error->domain == G_IO_ERROR &&
+ error->code == G_IO_ERROR_NOT_MOUNTED;
}
static void
activation_parameters_free (ActivateParameters *parameters)
{
- if (parameters->timed_wait_active) {
- eel_timed_wait_stop (cancel_activate_callback, parameters);
- }
-
- if (parameters->slot) {
- g_object_remove_weak_pointer (G_OBJECT (parameters->slot), (gpointer *)&parameters->slot);
- }
- if (parameters->parent_window) {
- g_object_remove_weak_pointer (G_OBJECT (parameters->parent_window), (gpointer *)&parameters->parent_window);
- }
- g_object_unref (parameters->cancellable);
- launch_location_list_free (parameters->locations);
- nautilus_file_list_free (parameters->mountables);
- nautilus_file_list_free (parameters->start_mountables);
- nautilus_file_list_free (parameters->not_mounted);
- g_free (parameters->activation_directory);
- g_free (parameters->timed_wait_prompt);
- g_assert (parameters->files_handle == NULL);
- g_free (parameters);
+ if (parameters->timed_wait_active)
+ {
+ eel_timed_wait_stop (cancel_activate_callback, parameters);
+ }
+
+ if (parameters->slot)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (parameters->slot), (gpointer *) &parameters->slot);
+ }
+ if (parameters->parent_window)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (parameters->parent_window), (gpointer *) &parameters->parent_window);
+ }
+ g_object_unref (parameters->cancellable);
+ launch_location_list_free (parameters->locations);
+ nautilus_file_list_free (parameters->mountables);
+ nautilus_file_list_free (parameters->start_mountables);
+ nautilus_file_list_free (parameters->not_mounted);
+ g_free (parameters->activation_directory);
+ g_free (parameters->timed_wait_prompt);
+ g_assert (parameters->files_handle == NULL);
+ g_free (parameters);
}
static void
cancel_activate_callback (gpointer callback_data)
{
- ActivateParameters *parameters = callback_data;
+ ActivateParameters *parameters = callback_data;
- parameters->timed_wait_active = FALSE;
-
- g_cancellable_cancel (parameters->cancellable);
+ parameters->timed_wait_active = FALSE;
- if (parameters->files_handle) {
- nautilus_file_list_cancel_call_when_ready (parameters->files_handle);
- parameters->files_handle = NULL;
- activation_parameters_free (parameters);
- }
+ g_cancellable_cancel (parameters->cancellable);
+
+ if (parameters->files_handle)
+ {
+ nautilus_file_list_cancel_call_when_ready (parameters->files_handle);
+ parameters->files_handle = NULL;
+ activation_parameters_free (parameters);
+ }
}
static void
activation_start_timed_cancel (ActivateParameters *parameters)
{
- parameters->timed_wait_active = TRUE;
- eel_timed_wait_start_with_duration
- (DELAY_UNTIL_CANCEL_MSECS,
- cancel_activate_callback,
- parameters,
- parameters->timed_wait_prompt,
- parameters->parent_window);
+ parameters->timed_wait_active = TRUE;
+ eel_timed_wait_start_with_duration
+ (DELAY_UNTIL_CANCEL_MSECS,
+ cancel_activate_callback,
+ parameters,
+ parameters->timed_wait_prompt,
+ parameters->parent_window);
}
static void
pause_activation_timed_cancel (ActivateParameters *parameters)
{
- if (parameters->timed_wait_active) {
- eel_timed_wait_stop (cancel_activate_callback, parameters);
- parameters->timed_wait_active = FALSE;
- }
+ if (parameters->timed_wait_active)
+ {
+ eel_timed_wait_stop (cancel_activate_callback, parameters);
+ parameters->timed_wait_active = FALSE;
+ }
}
static void
unpause_activation_timed_cancel (ActivateParameters *parameters)
{
- if (!parameters->timed_wait_active) {
- activation_start_timed_cancel (parameters);
- }
+ if (!parameters->timed_wait_active)
+ {
+ activation_start_timed_cancel (parameters);
+ }
}
static void
-activate_mount_op_active (GtkMountOperation *operation,
- GParamSpec *pspec,
- ActivateParameters *parameters)
+activate_mount_op_active (GtkMountOperation *operation,
+ GParamSpec *pspec,
+ ActivateParameters *parameters)
{
- gboolean is_active;
+ gboolean is_active;
- g_object_get (operation, "is-showing", &is_active, NULL);
+ g_object_get (operation, "is-showing", &is_active, NULL);
- if (is_active) {
- pause_activation_timed_cancel (parameters);
- } else {
- unpause_activation_timed_cancel (parameters);
- }
+ if (is_active)
+ {
+ pause_activation_timed_cancel (parameters);
+ }
+ else
+ {
+ unpause_activation_timed_cancel (parameters);
+ }
}
static gboolean
confirm_multiple_windows (GtkWindow *parent_window,
- int count,
- gboolean use_tabs)
-{
- GtkDialog *dialog;
- char *prompt;
- char *detail;
- int response;
-
- if (count <= SILENT_WINDOW_OPEN_LIMIT) {
- return TRUE;
- }
-
- prompt = _("Are you sure you want to open all files?");
- if (use_tabs) {
- detail = g_strdup_printf (ngettext("This will open %d separate tab.",
- "This will open %d separate tabs.", count), count);
- } else {
- detail = g_strdup_printf (ngettext("This will open %d separate window.",
- "This will open %d separate windows.", count), count);
- }
- dialog = eel_show_yes_no_dialog (prompt, detail,
- _("_OK"), _("_Cancel"),
- parent_window);
- g_free (detail);
-
- response = gtk_dialog_run (dialog);
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- return response == GTK_RESPONSE_YES;
-}
-
-typedef struct {
- NautilusWindowSlot *slot;
- GtkWindow *parent_window;
- NautilusFile *file;
- GList *files;
- NautilusWindowOpenFlags flags;
- char *activation_directory;
- gboolean user_confirmation;
- char *uri;
- GDBusProxy *proxy;
- GtkWidget *dialog;
+ int count,
+ gboolean use_tabs)
+{
+ GtkDialog *dialog;
+ char *prompt;
+ char *detail;
+ int response;
+
+ if (count <= SILENT_WINDOW_OPEN_LIMIT)
+ {
+ return TRUE;
+ }
+
+ prompt = _("Are you sure you want to open all files?");
+ if (use_tabs)
+ {
+ detail = g_strdup_printf (ngettext ("This will open %d separate tab.",
+ "This will open %d separate tabs.", count), count);
+ }
+ else
+ {
+ detail = g_strdup_printf (ngettext ("This will open %d separate window.",
+ "This will open %d separate windows.", count), count);
+ }
+ dialog = eel_show_yes_no_dialog (prompt, detail,
+ _("_OK"), _("_Cancel"),
+ parent_window);
+ g_free (detail);
+
+ response = gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ return response == GTK_RESPONSE_YES;
+}
+
+typedef struct
+{
+ NautilusWindowSlot *slot;
+ GtkWindow *parent_window;
+ NautilusFile *file;
+ GList *files;
+ NautilusWindowOpenFlags flags;
+ char *activation_directory;
+ gboolean user_confirmation;
+ char *uri;
+ GDBusProxy *proxy;
+ GtkWidget *dialog;
} ActivateParametersInstall;
static void
activate_parameters_install_free (ActivateParametersInstall *parameters_install)
{
- if (parameters_install->slot) {
- g_object_remove_weak_pointer (G_OBJECT (parameters_install->slot), (gpointer *)&parameters_install->slot);
- }
- if (parameters_install->parent_window) {
- g_object_remove_weak_pointer (G_OBJECT (parameters_install->parent_window), (gpointer *)&parameters_install->parent_window);
- }
+ if (parameters_install->slot)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (parameters_install->slot), (gpointer *) &parameters_install->slot);
+ }
+ if (parameters_install->parent_window)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (parameters_install->parent_window), (gpointer *) &parameters_install->parent_window);
+ }
- if (parameters_install->proxy != NULL) {
- g_object_unref (parameters_install->proxy);
- }
+ if (parameters_install->proxy != NULL)
+ {
+ g_object_unref (parameters_install->proxy);
+ }
- nautilus_file_unref (parameters_install->file);
- nautilus_file_list_free (parameters_install->files);
- g_free (parameters_install->activation_directory);
- g_free (parameters_install->uri);
- g_free (parameters_install);
+ nautilus_file_unref (parameters_install->file);
+ nautilus_file_list_free (parameters_install->files);
+ g_free (parameters_install->activation_directory);
+ g_free (parameters_install->uri);
+ g_free (parameters_install);
}
static char *
-get_application_no_mime_type_handler_message (NautilusFile *file, char *uri)
+get_application_no_mime_type_handler_message (NautilusFile *file,
+ char *uri)
{
- char *uri_for_display;
- char *name;
- char *error_message;
+ char *uri_for_display;
+ char *name;
+ char *error_message;
- name = nautilus_file_get_display_name (file);
+ name = nautilus_file_get_display_name (file);
- /* Truncate the URI so it doesn't get insanely wide. Note that even
- * though the dialog uses wrapped text, if the URI doesn't contain
- * white space then the text-wrapping code is too stupid to wrap it.
- */
- uri_for_display = eel_str_middle_truncate (name, MAX_URI_IN_DIALOG_LENGTH);
- error_message = g_strdup_printf (_("Could not display “%s”."), uri_for_display);
- g_free (uri_for_display);
- g_free (name);
+ /* Truncate the URI so it doesn't get insanely wide. Note that even
+ * though the dialog uses wrapped text, if the URI doesn't contain
+ * white space then the text-wrapping code is too stupid to wrap it.
+ */
+ uri_for_display = eel_str_middle_truncate (name, MAX_URI_IN_DIALOG_LENGTH);
+ error_message = g_strdup_printf (_("Could not display “%s”."), uri_for_display);
+ g_free (uri_for_display);
+ g_free (name);
- return error_message;
+ return error_message;
}
static void
open_with_response_cb (GtkDialog *dialog,
- gint response_id,
- gpointer user_data)
-{
- GtkWindow *parent_window;
- NautilusFile *file;
- GList files;
- GAppInfo *info;
- ActivateParametersInstall *parameters = user_data;
-
- if (response_id != GTK_RESPONSE_OK) {
- gtk_widget_destroy (GTK_WIDGET (dialog));
- return;
- }
+ gint response_id,
+ gpointer user_data)
+{
+ GtkWindow *parent_window;
+ NautilusFile *file;
+ GList files;
+ GAppInfo *info;
+ ActivateParametersInstall *parameters = user_data;
+
+ if (response_id != GTK_RESPONSE_OK)
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ return;
+ }
- parent_window = parameters->parent_window;
- file = g_object_get_data (G_OBJECT (dialog), "mime-action:file");
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
+ parent_window = parameters->parent_window;
+ file = g_object_get_data (G_OBJECT (dialog), "mime-action:file");
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (dialog));
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dialog));
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
- files.next = NULL;
- files.prev = NULL;
- files.data = file;
- nautilus_launch_application (info, &files, parent_window);
+ files.next = NULL;
+ files.prev = NULL;
+ files.data = file;
+ nautilus_launch_application (info, &files, parent_window);
- g_object_unref (info);
+ g_object_unref (info);
- activate_parameters_install_free (parameters);
+ activate_parameters_install_free (parameters);
}
static void
-choose_program (GtkDialog *message_dialog, int response, gpointer callback_data)
-{
- GtkWidget *dialog;
- NautilusFile *file;
- GFile *location;
- ActivateParametersInstall *parameters = callback_data;
-
- if (response != GTK_RESPONSE_ACCEPT){
- gtk_widget_destroy (GTK_WIDGET (message_dialog));
- activate_parameters_install_free (parameters);
- return;
- }
+choose_program (GtkDialog *message_dialog,
+ int response,
+ gpointer callback_data)
+{
+ GtkWidget *dialog;
+ NautilusFile *file;
+ GFile *location;
+ ActivateParametersInstall *parameters = callback_data;
+
+ if (response != GTK_RESPONSE_ACCEPT)
+ {
+ gtk_widget_destroy (GTK_WIDGET (message_dialog));
+ activate_parameters_install_free (parameters);
+ return;
+ }
- file = g_object_get_data (G_OBJECT (message_dialog), "mime-action:file");
+ file = g_object_get_data (G_OBJECT (message_dialog), "mime-action:file");
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- location = nautilus_file_get_location (file);
- nautilus_file_ref (file);
+ location = nautilus_file_get_location (file);
+ nautilus_file_ref (file);
- /* Destroy the message dialog after ref:ing the file */
- gtk_widget_destroy (GTK_WIDGET (message_dialog));
+ /* Destroy the message dialog after ref:ing the file */
+ gtk_widget_destroy (GTK_WIDGET (message_dialog));
- dialog = gtk_app_chooser_dialog_new (parameters->parent_window,
- GTK_DIALOG_MODAL,
- location);
- g_object_set_data_full (G_OBJECT (dialog),
- "mime-action:file",
- nautilus_file_ref (file),
- (GDestroyNotify)nautilus_file_unref);
+ dialog = gtk_app_chooser_dialog_new (parameters->parent_window,
+ GTK_DIALOG_MODAL,
+ location);
+ g_object_set_data_full (G_OBJECT (dialog),
+ "mime-action:file",
+ nautilus_file_ref (file),
+ (GDestroyNotify) nautilus_file_unref);
- gtk_widget_show (dialog);
+ gtk_widget_show (dialog);
- g_signal_connect (dialog,
- "response",
- G_CALLBACK (open_with_response_cb),
- parameters);
+ g_signal_connect (dialog,
+ "response",
+ G_CALLBACK (open_with_response_cb),
+ parameters);
- g_object_unref (location);
- nautilus_file_unref (file);
+ g_object_unref (location);
+ nautilus_file_unref (file);
}
static void
show_unhandled_type_error (ActivateParametersInstall *parameters)
{
- GtkWidget *dialog;
-
- char *mime_type = nautilus_file_get_mime_type (parameters->file);
- char *error_message = get_application_no_mime_type_handler_message (parameters->file, parameters->uri);
- if (g_content_type_is_unknown (mime_type)) {
- dialog = gtk_message_dialog_new (parameters->parent_window,
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- 0,
- "%s", error_message);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("The file is of an unknown type"));
- } else {
- char *text;
- text = g_strdup_printf (_("There is no application installed for “%s” files"), g_content_type_get_description (mime_type));
-
- dialog = gtk_message_dialog_new (parameters->parent_window,
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- 0,
- "%s", error_message);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", text);
+ GtkWidget *dialog;
+
+ char *mime_type = nautilus_file_get_mime_type (parameters->file);
+ char *error_message = get_application_no_mime_type_handler_message (parameters->file, parameters->uri);
+ if (g_content_type_is_unknown (mime_type))
+ {
+ dialog = gtk_message_dialog_new (parameters->parent_window,
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ 0,
+ "%s", error_message);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("The file is of an unknown type"));
+ }
+ else
+ {
+ char *text;
+ text = g_strdup_printf (_("There is no application installed for “%s” files"), g_content_type_get_description (mime_type));
+
+ dialog = gtk_message_dialog_new (parameters->parent_window,
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ 0,
+ "%s", error_message);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", text);
+
+ g_free (text);
+ }
- g_free (text);
- }
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Select Application"), GTK_RESPONSE_ACCEPT);
- gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Select Application"), GTK_RESPONSE_ACCEPT);
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("_OK"), GTK_RESPONSE_OK);
- gtk_dialog_add_button (GTK_DIALOG (dialog), _("_OK"), GTK_RESPONSE_OK);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+ g_object_set_data_full (G_OBJECT (dialog),
+ "mime-action:file",
+ nautilus_file_ref (parameters->file),
+ (GDestroyNotify) nautilus_file_unref);
- g_object_set_data_full (G_OBJECT (dialog),
- "mime-action:file",
- nautilus_file_ref (parameters->file),
- (GDestroyNotify)nautilus_file_unref);
+ gtk_widget_show (GTK_WIDGET (dialog));
- gtk_widget_show (GTK_WIDGET (dialog));
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (choose_program), parameters);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (choose_program), parameters);
- g_free (error_message);
- g_free (mime_type);
+ g_free (error_message);
+ g_free (mime_type);
}
static void
search_for_application_dbus_call_notify_cb (GDBusProxy *proxy,
- GAsyncResult *result,
- gpointer user_data)
-{
- ActivateParametersInstall *parameters_install = user_data;
- GVariant *variant;
- GError *error = NULL;
-
- variant = g_dbus_proxy_call_finish (proxy, result, &error);
- if (variant == NULL) {
- if (!g_dbus_error_is_remote_error (error) ||
- g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Failed") == 0) {
- char *message;
-
- message = g_strdup_printf ("%s\n%s",
- _("There was an internal error trying to search for applications:"),
- error->message);
- eel_show_error_dialog (_("Unable to search for application"), message,
- parameters_install->parent_window);
- g_free (message);
- } else {
- g_warning ("Error while trying to search for applications: %s",
- error->message);
- }
-
- g_error_free (error);
- activate_parameters_install_free (parameters_install);
- return;
- }
-
- g_variant_unref (variant);
-
- /* activate the file again */
- nautilus_mime_activate_files (parameters_install->parent_window,
- parameters_install->slot,
- parameters_install->files,
- parameters_install->activation_directory,
- parameters_install->flags,
- parameters_install->user_confirmation);
-
- activate_parameters_install_free (parameters_install);
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ActivateParametersInstall *parameters_install = user_data;
+ GVariant *variant;
+ GError *error = NULL;
+
+ variant = g_dbus_proxy_call_finish (proxy, result, &error);
+ if (variant == NULL)
+ {
+ if (!g_dbus_error_is_remote_error (error) ||
+ g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Failed") == 0)
+ {
+ char *message;
+
+ message = g_strdup_printf ("%s\n%s",
+ _("There was an internal error trying to search for applications:"),
+ error->message);
+ eel_show_error_dialog (_("Unable to search for application"), message,
+ parameters_install->parent_window);
+ g_free (message);
+ }
+ else
+ {
+ g_warning ("Error while trying to search for applications: %s",
+ error->message);
+ }
+
+ g_error_free (error);
+ activate_parameters_install_free (parameters_install);
+ return;
+ }
+
+ g_variant_unref (variant);
+
+ /* activate the file again */
+ nautilus_mime_activate_files (parameters_install->parent_window,
+ parameters_install->slot,
+ parameters_install->files,
+ parameters_install->activation_directory,
+ parameters_install->flags,
+ parameters_install->user_confirmation);
+
+ activate_parameters_install_free (parameters_install);
}
static void
-search_for_application_mime_type (ActivateParametersInstall *parameters_install, const gchar *mime_type)
+search_for_application_mime_type (ActivateParametersInstall *parameters_install,
+ const gchar *mime_type)
{
- GdkWindow *window;
- guint xid = 0;
- const char *mime_types[2];
+ GdkWindow *window;
+ guint xid = 0;
+ const char *mime_types[2];
- g_assert (parameters_install->proxy != NULL);
+ g_assert (parameters_install->proxy != NULL);
- /* get XID from parent window */
- window = gtk_widget_get_window (GTK_WIDGET (parameters_install->parent_window));
- if (window != NULL) {
- xid = GDK_WINDOW_XID (window);
- }
+ /* get XID from parent window */
+ window = gtk_widget_get_window (GTK_WIDGET (parameters_install->parent_window));
+ if (window != NULL)
+ {
+ xid = GDK_WINDOW_XID (window);
+ }
- mime_types[0] = mime_type;
- mime_types[1] = NULL;
+ mime_types[0] = mime_type;
+ mime_types[1] = NULL;
- g_dbus_proxy_call (parameters_install->proxy,
- "InstallMimeTypes",
- g_variant_new ("(u^ass)",
- xid,
- mime_types,
- "hide-confirm-search"),
- G_DBUS_CALL_FLAGS_NONE,
- G_MAXINT /* no timeout */,
- NULL /* cancellable */,
- (GAsyncReadyCallback) search_for_application_dbus_call_notify_cb,
- parameters_install);
+ g_dbus_proxy_call (parameters_install->proxy,
+ "InstallMimeTypes",
+ g_variant_new ("(u^ass)",
+ xid,
+ mime_types,
+ "hide-confirm-search"),
+ G_DBUS_CALL_FLAGS_NONE,
+ G_MAXINT /* no timeout */,
+ NULL /* cancellable */,
+ (GAsyncReadyCallback) search_for_application_dbus_call_notify_cb,
+ parameters_install);
- DEBUG ("InstallMimeType method invoked for %s", mime_type);
+ DEBUG ("InstallMimeType method invoked for %s", mime_type);
}
static void
-application_unhandled_file_install (GtkDialog *dialog,
- gint response_id,
+application_unhandled_file_install (GtkDialog *dialog,
+ gint response_id,
ActivateParametersInstall *parameters_install)
{
- char *mime_type;
+ char *mime_type;
- gtk_widget_destroy (GTK_WIDGET (dialog));
- parameters_install->dialog = NULL;
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ parameters_install->dialog = NULL;
- if (response_id == GTK_RESPONSE_YES) {
- mime_type = nautilus_file_get_mime_type (parameters_install->file);
- search_for_application_mime_type (parameters_install, mime_type);
- g_free (mime_type);
- } else {
- /* free as we're not going to get the async dbus callback */
- activate_parameters_install_free (parameters_install);
- }
+ if (response_id == GTK_RESPONSE_YES)
+ {
+ mime_type = nautilus_file_get_mime_type (parameters_install->file);
+ search_for_application_mime_type (parameters_install, mime_type);
+ g_free (mime_type);
+ }
+ else
+ {
+ /* free as we're not going to get the async dbus callback */
+ activate_parameters_install_free (parameters_install);
+ }
}
static gboolean
delete_cb (GtkDialog *dialog)
{
- gtk_dialog_response (dialog, GTK_RESPONSE_DELETE_EVENT);
- return TRUE;
+ gtk_dialog_response (dialog, GTK_RESPONSE_DELETE_EVENT);
+ return TRUE;
}
static void
-pk_proxy_appeared_cb (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- ActivateParametersInstall *parameters_install = user_data;
- char *mime_type, *name_owner;
- char *error_message;
- GtkWidget *dialog;
- GDBusProxy *proxy;
- GError *error = NULL;
-
- proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
- name_owner = g_dbus_proxy_get_name_owner (proxy);
-
- if (error != NULL || name_owner == NULL) {
- g_warning ("Couldn't call Modify on the PackageKit interface: %s",
- error != NULL ? error->message : "no owner for PackageKit");
- g_clear_error (&error);
-
- /* show an unhelpful dialog */
- show_unhandled_type_error (parameters_install);
-
- return;
- }
-
- g_free (name_owner);
-
- mime_type = nautilus_file_get_mime_type (parameters_install->file);
- error_message = get_application_no_mime_type_handler_message (parameters_install->file,
- parameters_install->uri);
- /* use a custom dialog to prompt the user to install new software */
- dialog = gtk_message_dialog_new (parameters_install->parent_window, 0,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_YES_NO,
- "%s", error_message);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("There is no application installed for “%s” files.\n"
- "Do you want to search for an application to open this file?"),
- g_content_type_get_description (mime_type));
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
- parameters_install->dialog = dialog;
- parameters_install->proxy = proxy;
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (application_unhandled_file_install),
- parameters_install);
- g_signal_connect (dialog, "delete-event",
- G_CALLBACK (delete_cb), NULL);
- gtk_widget_show_all (dialog);
- g_free (mime_type);
+pk_proxy_appeared_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ActivateParametersInstall *parameters_install = user_data;
+ char *mime_type, *name_owner;
+ char *error_message;
+ GtkWidget *dialog;
+ GDBusProxy *proxy;
+ GError *error = NULL;
+
+ proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+ name_owner = g_dbus_proxy_get_name_owner (proxy);
+
+ if (error != NULL || name_owner == NULL)
+ {
+ g_warning ("Couldn't call Modify on the PackageKit interface: %s",
+ error != NULL ? error->message : "no owner for PackageKit");
+ g_clear_error (&error);
+
+ /* show an unhelpful dialog */
+ show_unhandled_type_error (parameters_install);
+
+ return;
+ }
+
+ g_free (name_owner);
+
+ mime_type = nautilus_file_get_mime_type (parameters_install->file);
+ error_message = get_application_no_mime_type_handler_message (parameters_install->file,
+ parameters_install->uri);
+ /* use a custom dialog to prompt the user to install new software */
+ dialog = gtk_message_dialog_new (parameters_install->parent_window, 0,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_YES_NO,
+ "%s", error_message);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("There is no application installed for “%s” files.\n"
+ "Do you want to search for an application to open this file?"),
+ g_content_type_get_description (mime_type));
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+ parameters_install->dialog = dialog;
+ parameters_install->proxy = proxy;
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (application_unhandled_file_install),
+ parameters_install);
+ g_signal_connect (dialog, "delete-event",
+ G_CALLBACK (delete_cb), NULL);
+ gtk_widget_show_all (dialog);
+ g_free (mime_type);
}
static void
-application_unhandled_uri (ActivateParameters *parameters, char *uri)
-{
- gboolean show_install_mime;
- char *mime_type;
- NautilusFile *file;
- ActivateParametersInstall *parameters_install;
-
- file = nautilus_file_get_by_uri (uri);
-
- mime_type = nautilus_file_get_mime_type (file);
-
- /* copy the parts of parameters we are interested in as the orignal will be unref'd */
- parameters_install = g_new0 (ActivateParametersInstall, 1);
- parameters_install->slot = parameters->slot;
- g_object_add_weak_pointer (G_OBJECT (parameters_install->slot), (gpointer *)&parameters_install->slot);
- if (parameters->parent_window) {
- parameters_install->parent_window = parameters->parent_window;
- g_object_add_weak_pointer (G_OBJECT (parameters_install->parent_window), (gpointer *)&parameters_install->parent_window);
- }
- parameters_install->activation_directory = g_strdup (parameters->activation_directory);
- parameters_install->file = file;
- parameters_install->files = get_file_list_for_launch_locations (parameters->locations);
- parameters_install->flags = parameters->flags;
- parameters_install->user_confirmation = parameters->user_confirmation;
- parameters_install->uri = g_strdup(uri);
+application_unhandled_uri (ActivateParameters *parameters,
+ char *uri)
+{
+ gboolean show_install_mime;
+ char *mime_type;
+ NautilusFile *file;
+ ActivateParametersInstall *parameters_install;
+
+ file = nautilus_file_get_by_uri (uri);
+
+ mime_type = nautilus_file_get_mime_type (file);
+
+ /* copy the parts of parameters we are interested in as the orignal will be unref'd */
+ parameters_install = g_new0 (ActivateParametersInstall, 1);
+ parameters_install->slot = parameters->slot;
+ g_object_add_weak_pointer (G_OBJECT (parameters_install->slot), (gpointer *) &parameters_install->slot);
+ if (parameters->parent_window)
+ {
+ parameters_install->parent_window = parameters->parent_window;
+ g_object_add_weak_pointer (G_OBJECT (parameters_install->parent_window), (gpointer *) &parameters_install->parent_window);
+ }
+ parameters_install->activation_directory = g_strdup (parameters->activation_directory);
+ parameters_install->file = file;
+ parameters_install->files = get_file_list_for_launch_locations (parameters->locations);
+ parameters_install->flags = parameters->flags;
+ parameters_install->user_confirmation = parameters->user_confirmation;
+ parameters_install->uri = g_strdup (uri);
#ifdef ENABLE_PACKAGEKIT
- /* allow an admin to disable the PackageKit search functionality */
- show_install_mime = g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_INSTALL_MIME_ACTIVATION);
+ /* allow an admin to disable the PackageKit search functionality */
+ show_install_mime = g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_INSTALL_MIME_ACTIVATION);
#else
- /* we have no install functionality */
- show_install_mime = FALSE;
+ /* we have no install functionality */
+ show_install_mime = FALSE;
#endif
- /* There is no use trying to look for handlers of application/octet-stream */
- if (g_content_type_is_unknown (mime_type)) {
- show_install_mime = FALSE;
- }
+ /* There is no use trying to look for handlers of application/octet-stream */
+ if (g_content_type_is_unknown (mime_type))
+ {
+ show_install_mime = FALSE;
+ }
- g_free (mime_type);
+ g_free (mime_type);
- if (!show_install_mime) {
- goto out;
- }
+ if (!show_install_mime)
+ {
+ goto out;
+ }
- g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.PackageKit",
- "/org/freedesktop/PackageKit",
- "org.freedesktop.PackageKit.Modify",
- NULL,
- pk_proxy_appeared_cb,
- parameters_install);
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit.Modify",
+ NULL,
+ pk_proxy_appeared_cb,
+ parameters_install);
- return;
+ return;
out:
- /* show an unhelpful dialog */
- show_unhandled_type_error (parameters_install);
+ /* show an unhelpful dialog */
+ show_unhandled_type_error (parameters_install);
}
-typedef struct {
- GtkWindow *parent_window;
- NautilusFile *file;
+typedef struct
+{
+ GtkWindow *parent_window;
+ NautilusFile *file;
} ActivateParametersDesktop;
static void
activate_parameters_desktop_free (ActivateParametersDesktop *parameters_desktop)
{
- if (parameters_desktop->parent_window) {
- g_object_remove_weak_pointer (G_OBJECT (parameters_desktop->parent_window), (gpointer *)&parameters_desktop->parent_window);
- }
- nautilus_file_unref (parameters_desktop->file);
- g_free (parameters_desktop);
+ if (parameters_desktop->parent_window)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (parameters_desktop->parent_window), (gpointer *) &parameters_desktop->parent_window);
+ }
+ nautilus_file_unref (parameters_desktop->file);
+ g_free (parameters_desktop);
}
static void
-untrusted_launcher_response_callback (GtkDialog *dialog,
- int response_id,
- ActivateParametersDesktop *parameters)
-{
- GdkScreen *screen;
- char *uri;
- GFile *file;
-
- switch (response_id) {
- case RESPONSE_RUN:
- screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
- uri = nautilus_file_get_uri (parameters->file);
- DEBUG ("Launching untrusted launcher %s", uri);
- nautilus_launch_desktop_file (screen, uri, NULL,
- parameters->parent_window);
- g_free (uri);
- break;
- case RESPONSE_MARK_TRUSTED:
- file = nautilus_file_get_location (parameters->file);
- nautilus_file_mark_desktop_file_trusted (file,
- parameters->parent_window,
- TRUE,
- NULL, NULL);
- g_object_unref (file);
- break;
- default:
- /* Just destroy dialog */
- break;
- }
-
- gtk_widget_destroy (GTK_WIDGET (dialog));
- activate_parameters_desktop_free (parameters);
+untrusted_launcher_response_callback (GtkDialog *dialog,
+ int response_id,
+ ActivateParametersDesktop *parameters)
+{
+ GdkScreen *screen;
+ char *uri;
+ GFile *file;
+
+ switch (response_id)
+ {
+ case RESPONSE_RUN:
+ {
+ screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
+ uri = nautilus_file_get_uri (parameters->file);
+ DEBUG ("Launching untrusted launcher %s", uri);
+ nautilus_launch_desktop_file (screen, uri, NULL,
+ parameters->parent_window);
+ g_free (uri);
+ }
+ break;
+
+ case RESPONSE_MARK_TRUSTED:
+ {
+ file = nautilus_file_get_location (parameters->file);
+ nautilus_file_mark_desktop_file_trusted (file,
+ parameters->parent_window,
+ TRUE,
+ NULL, NULL);
+ g_object_unref (file);
+ }
+ break;
+
+ default:
+ {
+ /* Just destroy dialog */
+ }
+ break;
+ }
+
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ activate_parameters_desktop_free (parameters);
}
static void
activate_desktop_file (ActivateParameters *parameters,
- NautilusFile *file)
-{
- ActivateParametersDesktop *parameters_desktop;
- char *primary, *secondary, *display_name;
- GtkWidget *dialog;
- GdkScreen *screen;
- char *uri;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
-
- if (!nautilus_file_is_trusted_link (file)) {
- /* copy the parts of parameters we are interested in as the orignal will be freed */
- parameters_desktop = g_new0 (ActivateParametersDesktop, 1);
- if (parameters->parent_window) {
- parameters_desktop->parent_window = parameters->parent_window;
- g_object_add_weak_pointer (G_OBJECT (parameters_desktop->parent_window), (gpointer *)&parameters_desktop->parent_window);
- }
- parameters_desktop->file = nautilus_file_ref (file);
-
- primary = _("Untrusted application launcher");
- display_name = nautilus_file_get_display_name (file);
- secondary =
- g_strdup_printf (_("The application launcher “%s” has not been marked as trusted. "
- "If you do not know the source of this file, launching it may be unsafe."
- ),
- display_name);
-
- dialog = gtk_message_dialog_new (parameters->parent_window,
- 0,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_NONE,
- NULL);
- g_object_set (dialog,
- "text", primary,
- "secondary-text", secondary,
- NULL);
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- _("_Launch Anyway"), RESPONSE_RUN);
- if (nautilus_file_can_set_permissions (file)) {
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- _("Mark as _Trusted"), RESPONSE_MARK_TRUSTED);
- }
- gtk_dialog_add_button (GTK_DIALOG (dialog),
- _("_Cancel"), GTK_RESPONSE_CANCEL);
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (untrusted_launcher_response_callback),
- parameters_desktop);
- gtk_widget_show (dialog);
-
- g_free (display_name);
- g_free (secondary);
- return;
- }
-
- uri = nautilus_file_get_uri (file);
- DEBUG ("Launching trusted launcher %s", uri);
- nautilus_launch_desktop_file (screen, uri, NULL,
- parameters->parent_window);
- g_free (uri);
+ NautilusFile *file)
+{
+ ActivateParametersDesktop *parameters_desktop;
+ char *primary, *secondary, *display_name;
+ GtkWidget *dialog;
+ GdkScreen *screen;
+ char *uri;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
+
+ if (!nautilus_file_is_trusted_link (file))
+ {
+ /* copy the parts of parameters we are interested in as the orignal will be freed */
+ parameters_desktop = g_new0 (ActivateParametersDesktop, 1);
+ if (parameters->parent_window)
+ {
+ parameters_desktop->parent_window = parameters->parent_window;
+ g_object_add_weak_pointer (G_OBJECT (parameters_desktop->parent_window), (gpointer *) &parameters_desktop->parent_window);
+ }
+ parameters_desktop->file = nautilus_file_ref (file);
+
+ primary = _("Untrusted application launcher");
+ display_name = nautilus_file_get_display_name (file);
+ secondary =
+ g_strdup_printf (_("The application launcher “%s” has not been marked as trusted. "
+ "If you do not know the source of this file, launching it may be unsafe."
+ ),
+ display_name);
+
+ dialog = gtk_message_dialog_new (parameters->parent_window,
+ 0,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ NULL);
+ g_object_set (dialog,
+ "text", primary,
+ "secondary-text", secondary,
+ NULL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("_Launch Anyway"), RESPONSE_RUN);
+ if (nautilus_file_can_set_permissions (file))
+ {
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("Mark as _Trusted"), RESPONSE_MARK_TRUSTED);
+ }
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("_Cancel"), GTK_RESPONSE_CANCEL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (untrusted_launcher_response_callback),
+ parameters_desktop);
+ gtk_widget_show (dialog);
+
+ g_free (display_name);
+ g_free (secondary);
+ return;
+ }
+
+ uri = nautilus_file_get_uri (file);
+ DEBUG ("Launching trusted launcher %s", uri);
+ nautilus_launch_desktop_file (screen, uri, NULL,
+ parameters->parent_window);
+ g_free (uri);
}
static void
activate_files (ActivateParameters *parameters)
{
- NautilusWindow *window;
- NautilusWindowOpenFlags flags;
- NautilusFile *file;
- GList *launch_desktop_files;
- GList *launch_files;
- GList *launch_in_terminal_files;
- GList *open_in_app_uris;
- GList *open_in_app_parameters;
- GList *unhandled_open_in_app_uris;
- ApplicationLaunchParameters *one_parameters;
- GList *open_in_view_files;
- GList *l;
- int count;
- char *uri;
- char *executable_path, *quoted_path;
- char *old_working_dir;
- ActivationAction action;
- GdkScreen *screen;
- LaunchLocation *location;
- gint num_apps;
- gint num_unhandled;
- gint num_files;
- gboolean open_files;
-
- screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
-
- launch_desktop_files = NULL;
- launch_files = NULL;
- launch_in_terminal_files = NULL;
- open_in_app_uris = NULL;
- open_in_view_files = NULL;
-
- for (l = parameters->locations; l != NULL; l = l->next) {
- location = l->data;
- file = location->file;
-
- if (file_was_cancelled (file)) {
- continue;
- }
-
- action = get_activation_action (file);
- if (action == ACTIVATION_ACTION_ASK) {
- /* Special case for executable text files, since it might be
- * dangerous & unexpected to launch these.
- */
- pause_activation_timed_cancel (parameters);
- action = get_executable_text_file_action (parameters->parent_window, file);
- unpause_activation_timed_cancel (parameters);
- }
-
- switch (action) {
- case ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE :
- launch_desktop_files = g_list_prepend (launch_desktop_files, file);
- break;
- case ACTIVATION_ACTION_LAUNCH :
- launch_files = g_list_prepend (launch_files, file);
- break;
- case ACTIVATION_ACTION_LAUNCH_IN_TERMINAL :
- launch_in_terminal_files = g_list_prepend (launch_in_terminal_files, file);
- break;
- case ACTIVATION_ACTION_OPEN_IN_VIEW :
- open_in_view_files = g_list_prepend (open_in_view_files, file);
- break;
- case ACTIVATION_ACTION_OPEN_IN_APPLICATION :
- open_in_app_uris = g_list_prepend (open_in_app_uris, location->uri);
- break;
- case ACTIVATION_ACTION_DO_NOTHING :
- break;
- case ACTIVATION_ACTION_EXTRACT :
- /* Extraction of files should be handled in the view */
- g_assert_not_reached ();
- break;
- case ACTIVATION_ACTION_ASK :
- g_assert_not_reached ();
- break;
- }
- }
-
- launch_desktop_files = g_list_reverse (launch_desktop_files);
- for (l = launch_desktop_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- activate_desktop_file (parameters, file);
- }
-
- old_working_dir = NULL;
- if (parameters->activation_directory &&
- (launch_files != NULL || launch_in_terminal_files != NULL)) {
- old_working_dir = g_get_current_dir ();
- g_chdir (parameters->activation_directory);
-
- }
-
- launch_files = g_list_reverse (launch_files);
- for (l = launch_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- uri = nautilus_file_get_activation_uri (file);
- executable_path = g_filename_from_uri (uri, NULL, NULL);
- quoted_path = g_shell_quote (executable_path);
-
- DEBUG ("Launching file path %s", quoted_path);
-
- nautilus_launch_application_from_command (screen, quoted_path, FALSE, NULL);
- g_free (quoted_path);
- g_free (executable_path);
- g_free (uri);
-
- }
-
- launch_in_terminal_files = g_list_reverse (launch_in_terminal_files);
- for (l = launch_in_terminal_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- uri = nautilus_file_get_activation_uri (file);
- executable_path = g_filename_from_uri (uri, NULL, NULL);
- quoted_path = g_shell_quote (executable_path);
-
- DEBUG ("Launching in terminal file quoted path %s", quoted_path);
-
- nautilus_launch_application_from_command (screen, quoted_path, TRUE, NULL);
-
- g_free (quoted_path);
- g_free (executable_path);
- g_free (uri);
- }
-
- if (old_working_dir != NULL) {
- g_chdir (old_working_dir);
- g_free (old_working_dir);
- }
-
- open_in_view_files = g_list_reverse (open_in_view_files);
- count = g_list_length (open_in_view_files);
-
- flags = parameters->flags;
- if (count > 1) {
- if ((parameters->flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) == 0) {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
- } else {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- }
- }
-
- if (parameters->slot != NULL &&
- (!parameters->user_confirmation ||
- confirm_multiple_windows (parameters->parent_window, count,
- (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0))) {
-
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0 &&
- g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION) ==
- NAUTILUS_NEW_TAB_POSITION_AFTER_CURRENT_TAB) {
- /* When inserting N tabs after the current one,
- * we first open tab N, then tab N-1, ..., then tab 0.
- * Each of them is appended to the current tab, i.e.
- * prepended to the list of tabs to open.
- */
- open_in_view_files = g_list_reverse (open_in_view_files);
- }
-
-
- for (l = open_in_view_files; l != NULL; l = l->next) {
- GFile *f;
- /* The ui should ask for navigation or object windows
- * depending on what the current one is */
- file = NAUTILUS_FILE (l->data);
-
- uri = nautilus_file_get_activation_uri (file);
- f = g_file_new_for_uri (uri);
- /* FIXME: we need to pass the parent_window, but we only use it for the current active window,
- * which nautilus-application should take care of. However is not working and creating regressions
- * in some cases. Until we figure out what's going on, continue to use the parameters->slot
- * to make splicit the window we want to use for activating the files */
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- f, flags, NULL, NULL, parameters->slot);
- g_object_unref (f);
- g_free (uri);
- }
- }
-
- open_in_app_parameters = NULL;
- unhandled_open_in_app_uris = NULL;
-
- if (open_in_app_uris != NULL) {
- open_in_app_uris = g_list_reverse (open_in_app_uris);
-
- open_in_app_parameters = make_activation_parameters
- (open_in_app_uris, &unhandled_open_in_app_uris);
- }
-
- num_apps = g_list_length (open_in_app_parameters);
- num_unhandled = g_list_length (unhandled_open_in_app_uris);
- num_files = g_list_length (open_in_app_uris);
- open_files = TRUE;
-
- if (open_in_app_uris != NULL &&
- (!parameters->user_confirmation ||
- num_files + num_unhandled > SILENT_OPEN_LIMIT) &&
- num_apps > 1) {
- GtkDialog *dialog;
- char *prompt;
- char *detail;
- int response;
-
- pause_activation_timed_cancel (parameters);
-
- prompt = _("Are you sure you want to open all files?");
- detail = g_strdup_printf (ngettext ("This will open %d separate application.",
- "This will open %d separate applications.", num_apps), num_apps);
- dialog = eel_show_yes_no_dialog (prompt, detail,
- _("_OK"), _("_Cancel"),
- parameters->parent_window);
- g_free (detail);
-
- response = gtk_dialog_run (dialog);
- gtk_widget_destroy (GTK_WIDGET (dialog));
-
- unpause_activation_timed_cancel (parameters);
-
- if (response != GTK_RESPONSE_YES) {
- open_files = FALSE;
- }
- }
-
- if (open_files) {
- for (l = open_in_app_parameters; l != NULL; l = l->next) {
- one_parameters = l->data;
-
- nautilus_launch_application_by_uri (one_parameters->application,
- one_parameters->uris,
- parameters->parent_window);
- application_launch_parameters_free (one_parameters);
- }
-
- for (l = unhandled_open_in_app_uris; l != NULL; l = l->next) {
- uri = l->data;
-
- /* this does not block */
- application_unhandled_uri (parameters, uri);
- }
- }
-
- window = NULL;
- if (parameters->slot != NULL) {
- window = nautilus_window_slot_get_window (parameters->slot);
- }
-
- if (open_in_app_parameters != NULL ||
- unhandled_open_in_app_uris != NULL) {
- if ((parameters->flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0 &&
- window != NULL) {
- nautilus_window_close (window);
- }
- }
-
- g_list_free (launch_desktop_files);
- g_list_free (launch_files);
- g_list_free (launch_in_terminal_files);
- g_list_free (open_in_view_files);
- g_list_free (open_in_app_uris);
- g_list_free (open_in_app_parameters);
- g_list_free (unhandled_open_in_app_uris);
-
- activation_parameters_free (parameters);
-}
-
-static void
-activation_mount_not_mounted_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- ActivateParameters *parameters = user_data;
- GError *error;
- NautilusFile *file;
- LaunchLocation *loc;
-
- file = parameters->not_mounted->data;
-
- error = NULL;
- if (!g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error)) {
- if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED &&
- error->code != G_IO_ERROR_ALREADY_MOUNTED)) {
- eel_show_error_dialog (_("Unable to access location"), error->message, parameters->parent_window);
- }
-
- if (error->domain != G_IO_ERROR ||
- error->code != G_IO_ERROR_ALREADY_MOUNTED) {
- loc = find_launch_location_for_file (parameters->locations,
- file);
- if (loc) {
- parameters->locations =
- g_list_remove (parameters->locations, loc);
- launch_location_free (loc);
- }
- }
-
- g_error_free (error);
- }
-
- parameters->not_mounted = g_list_delete_link (parameters->not_mounted,
- parameters->not_mounted);
- nautilus_file_unref (file);
-
- activation_mount_not_mounted (parameters);
+ NautilusWindow *window;
+ NautilusWindowOpenFlags flags;
+ NautilusFile *file;
+ GList *launch_desktop_files;
+ GList *launch_files;
+ GList *launch_in_terminal_files;
+ GList *open_in_app_uris;
+ GList *open_in_app_parameters;
+ GList *unhandled_open_in_app_uris;
+ ApplicationLaunchParameters *one_parameters;
+ GList *open_in_view_files;
+ GList *l;
+ int count;
+ char *uri;
+ char *executable_path, *quoted_path;
+ char *old_working_dir;
+ ActivationAction action;
+ GdkScreen *screen;
+ LaunchLocation *location;
+ gint num_apps;
+ gint num_unhandled;
+ gint num_files;
+ gboolean open_files;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (parameters->parent_window));
+
+ launch_desktop_files = NULL;
+ launch_files = NULL;
+ launch_in_terminal_files = NULL;
+ open_in_app_uris = NULL;
+ open_in_view_files = NULL;
+
+ for (l = parameters->locations; l != NULL; l = l->next)
+ {
+ location = l->data;
+ file = location->file;
+
+ if (file_was_cancelled (file))
+ {
+ continue;
+ }
+
+ action = get_activation_action (file);
+ if (action == ACTIVATION_ACTION_ASK)
+ {
+ /* Special case for executable text files, since it might be
+ * dangerous & unexpected to launch these.
+ */
+ pause_activation_timed_cancel (parameters);
+ action = get_executable_text_file_action (parameters->parent_window, file);
+ unpause_activation_timed_cancel (parameters);
+ }
+
+ switch (action)
+ {
+ case ACTIVATION_ACTION_LAUNCH_DESKTOP_FILE:
+ {
+ launch_desktop_files = g_list_prepend (launch_desktop_files, file);
+ }
+ break;
+
+ case ACTIVATION_ACTION_LAUNCH:
+ {
+ launch_files = g_list_prepend (launch_files, file);
+ }
+ break;
+
+ case ACTIVATION_ACTION_LAUNCH_IN_TERMINAL:
+ {
+ launch_in_terminal_files = g_list_prepend (launch_in_terminal_files, file);
+ }
+ break;
+
+ case ACTIVATION_ACTION_OPEN_IN_VIEW:
+ {
+ open_in_view_files = g_list_prepend (open_in_view_files, file);
+ }
+ break;
+
+ case ACTIVATION_ACTION_OPEN_IN_APPLICATION:
+ {
+ open_in_app_uris = g_list_prepend (open_in_app_uris, location->uri);
+ }
+ break;
+
+ case ACTIVATION_ACTION_DO_NOTHING:
+ {
+ }
+ break;
+
+ case ACTIVATION_ACTION_EXTRACT:
+ {
+ /* Extraction of files should be handled in the view */
+ g_assert_not_reached ();
+ }
+ break;
+
+ case ACTIVATION_ACTION_ASK:
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
+ }
+
+ launch_desktop_files = g_list_reverse (launch_desktop_files);
+ for (l = launch_desktop_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ activate_desktop_file (parameters, file);
+ }
+
+ old_working_dir = NULL;
+ if (parameters->activation_directory &&
+ (launch_files != NULL || launch_in_terminal_files != NULL))
+ {
+ old_working_dir = g_get_current_dir ();
+ g_chdir (parameters->activation_directory);
+ }
+
+ launch_files = g_list_reverse (launch_files);
+ for (l = launch_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ uri = nautilus_file_get_activation_uri (file);
+ executable_path = g_filename_from_uri (uri, NULL, NULL);
+ quoted_path = g_shell_quote (executable_path);
+
+ DEBUG ("Launching file path %s", quoted_path);
+
+ nautilus_launch_application_from_command (screen, quoted_path, FALSE, NULL);
+ g_free (quoted_path);
+ g_free (executable_path);
+ g_free (uri);
+ }
+
+ launch_in_terminal_files = g_list_reverse (launch_in_terminal_files);
+ for (l = launch_in_terminal_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ uri = nautilus_file_get_activation_uri (file);
+ executable_path = g_filename_from_uri (uri, NULL, NULL);
+ quoted_path = g_shell_quote (executable_path);
+
+ DEBUG ("Launching in terminal file quoted path %s", quoted_path);
+
+ nautilus_launch_application_from_command (screen, quoted_path, TRUE, NULL);
+
+ g_free (quoted_path);
+ g_free (executable_path);
+ g_free (uri);
+ }
+
+ if (old_working_dir != NULL)
+ {
+ g_chdir (old_working_dir);
+ g_free (old_working_dir);
+ }
+
+ open_in_view_files = g_list_reverse (open_in_view_files);
+ count = g_list_length (open_in_view_files);
+
+ flags = parameters->flags;
+ if (count > 1)
+ {
+ if ((parameters->flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) == 0)
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
+ }
+ else
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ }
+ }
+
+ if (parameters->slot != NULL &&
+ (!parameters->user_confirmation ||
+ confirm_multiple_windows (parameters->parent_window, count,
+ (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0)))
+ {
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0 &&
+ g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION) ==
+ NAUTILUS_NEW_TAB_POSITION_AFTER_CURRENT_TAB)
+ {
+ /* When inserting N tabs after the current one,
+ * we first open tab N, then tab N-1, ..., then tab 0.
+ * Each of them is appended to the current tab, i.e.
+ * prepended to the list of tabs to open.
+ */
+ open_in_view_files = g_list_reverse (open_in_view_files);
+ }
+
+
+ for (l = open_in_view_files; l != NULL; l = l->next)
+ {
+ GFile *f;
+ /* The ui should ask for navigation or object windows
+ * depending on what the current one is */
+ file = NAUTILUS_FILE (l->data);
+
+ uri = nautilus_file_get_activation_uri (file);
+ f = g_file_new_for_uri (uri);
+ /* FIXME: we need to pass the parent_window, but we only use it for the current active window,
+ * which nautilus-application should take care of. However is not working and creating regressions
+ * in some cases. Until we figure out what's going on, continue to use the parameters->slot
+ * to make splicit the window we want to use for activating the files */
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ f, flags, NULL, NULL, parameters->slot);
+ g_object_unref (f);
+ g_free (uri);
+ }
+ }
+
+ open_in_app_parameters = NULL;
+ unhandled_open_in_app_uris = NULL;
+
+ if (open_in_app_uris != NULL)
+ {
+ open_in_app_uris = g_list_reverse (open_in_app_uris);
+
+ open_in_app_parameters = make_activation_parameters
+ (open_in_app_uris, &unhandled_open_in_app_uris);
+ }
+
+ num_apps = g_list_length (open_in_app_parameters);
+ num_unhandled = g_list_length (unhandled_open_in_app_uris);
+ num_files = g_list_length (open_in_app_uris);
+ open_files = TRUE;
+
+ if (open_in_app_uris != NULL &&
+ (!parameters->user_confirmation ||
+ num_files + num_unhandled > SILENT_OPEN_LIMIT) &&
+ num_apps > 1)
+ {
+ GtkDialog *dialog;
+ char *prompt;
+ char *detail;
+ int response;
+
+ pause_activation_timed_cancel (parameters);
+
+ prompt = _("Are you sure you want to open all files?");
+ detail = g_strdup_printf (ngettext ("This will open %d separate application.",
+ "This will open %d separate applications.", num_apps), num_apps);
+ dialog = eel_show_yes_no_dialog (prompt, detail,
+ _("_OK"), _("_Cancel"),
+ parameters->parent_window);
+ g_free (detail);
+
+ response = gtk_dialog_run (dialog);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ unpause_activation_timed_cancel (parameters);
+
+ if (response != GTK_RESPONSE_YES)
+ {
+ open_files = FALSE;
+ }
+ }
+
+ if (open_files)
+ {
+ for (l = open_in_app_parameters; l != NULL; l = l->next)
+ {
+ one_parameters = l->data;
+
+ nautilus_launch_application_by_uri (one_parameters->application,
+ one_parameters->uris,
+ parameters->parent_window);
+ application_launch_parameters_free (one_parameters);
+ }
+
+ for (l = unhandled_open_in_app_uris; l != NULL; l = l->next)
+ {
+ uri = l->data;
+
+ /* this does not block */
+ application_unhandled_uri (parameters, uri);
+ }
+ }
+
+ window = NULL;
+ if (parameters->slot != NULL)
+ {
+ window = nautilus_window_slot_get_window (parameters->slot);
+ }
+
+ if (open_in_app_parameters != NULL ||
+ unhandled_open_in_app_uris != NULL)
+ {
+ if ((parameters->flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0 &&
+ window != NULL)
+ {
+ nautilus_window_close (window);
+ }
+ }
+
+ g_list_free (launch_desktop_files);
+ g_list_free (launch_files);
+ g_list_free (launch_in_terminal_files);
+ g_list_free (open_in_view_files);
+ g_list_free (open_in_app_uris);
+ g_list_free (open_in_app_parameters);
+ g_list_free (unhandled_open_in_app_uris);
+
+ activation_parameters_free (parameters);
+}
+
+static void
+activation_mount_not_mounted_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ ActivateParameters *parameters = user_data;
+ GError *error;
+ NautilusFile *file;
+ LaunchLocation *loc;
+
+ file = parameters->not_mounted->data;
+
+ error = NULL;
+ if (!g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error))
+ {
+ if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED &&
+ error->code != G_IO_ERROR_ALREADY_MOUNTED))
+ {
+ eel_show_error_dialog (_("Unable to access location"), error->message, parameters->parent_window);
+ }
+
+ if (error->domain != G_IO_ERROR ||
+ error->code != G_IO_ERROR_ALREADY_MOUNTED)
+ {
+ loc = find_launch_location_for_file (parameters->locations,
+ file);
+ if (loc)
+ {
+ parameters->locations =
+ g_list_remove (parameters->locations, loc);
+ launch_location_free (loc);
+ }
+ }
+
+ g_error_free (error);
+ }
+
+ parameters->not_mounted = g_list_delete_link (parameters->not_mounted,
+ parameters->not_mounted);
+ nautilus_file_unref (file);
+
+ activation_mount_not_mounted (parameters);
}
static void
activation_mount_not_mounted (ActivateParameters *parameters)
{
- NautilusFile *file;
- GFile *location;
- LaunchLocation *loc;
- GMountOperation *mount_op;
- GList *l, *next, *files;
-
- if (parameters->not_mounted != NULL) {
- file = parameters->not_mounted->data;
- mount_op = gtk_mount_operation_new (parameters->parent_window);
- g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
- g_signal_connect (mount_op, "notify::is-showing",
- G_CALLBACK (activate_mount_op_active), parameters);
- location = nautilus_file_get_location (file);
- g_file_mount_enclosing_volume (location, 0, mount_op, parameters->cancellable,
- activation_mount_not_mounted_callback, parameters);
- g_object_unref (location);
- /* unref mount_op here - g_file_mount_enclosing_volume() does ref for itself */
- g_object_unref (mount_op);
- return;
- }
-
- parameters->tried_mounting = TRUE;
-
- if (parameters->locations == NULL) {
- activation_parameters_free (parameters);
- return;
- }
-
- /* once the mount is finished, refresh all attributes */
- /* - fixes new windows not appearing after successful mount */
- for (l = parameters->locations; l != NULL; l = next) {
- loc = l->data;
- next = l->next;
- nautilus_file_invalidate_all_attributes (loc->file);
- }
-
- files = get_file_list_for_launch_locations (parameters->locations);
- nautilus_file_list_call_when_ready
- (files,
- nautilus_mime_actions_get_required_file_attributes (),
- &parameters->files_handle,
- activate_callback, parameters);
- nautilus_file_list_free (files);
+ NautilusFile *file;
+ GFile *location;
+ LaunchLocation *loc;
+ GMountOperation *mount_op;
+ GList *l, *next, *files;
+
+ if (parameters->not_mounted != NULL)
+ {
+ file = parameters->not_mounted->data;
+ mount_op = gtk_mount_operation_new (parameters->parent_window);
+ g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
+ g_signal_connect (mount_op, "notify::is-showing",
+ G_CALLBACK (activate_mount_op_active), parameters);
+ location = nautilus_file_get_location (file);
+ g_file_mount_enclosing_volume (location, 0, mount_op, parameters->cancellable,
+ activation_mount_not_mounted_callback, parameters);
+ g_object_unref (location);
+ /* unref mount_op here - g_file_mount_enclosing_volume() does ref for itself */
+ g_object_unref (mount_op);
+ return;
+ }
+
+ parameters->tried_mounting = TRUE;
+
+ if (parameters->locations == NULL)
+ {
+ activation_parameters_free (parameters);
+ return;
+ }
+
+ /* once the mount is finished, refresh all attributes */
+ /* - fixes new windows not appearing after successful mount */
+ for (l = parameters->locations; l != NULL; l = next)
+ {
+ loc = l->data;
+ next = l->next;
+ nautilus_file_invalidate_all_attributes (loc->file);
+ }
+
+ files = get_file_list_for_launch_locations (parameters->locations);
+ nautilus_file_list_call_when_ready
+ (files,
+ nautilus_mime_actions_get_required_file_attributes (),
+ &parameters->files_handle,
+ activate_callback, parameters);
+ nautilus_file_list_free (files);
}
static void
-activate_callback (GList *files, gpointer callback_data)
-{
- ActivateParameters *parameters = callback_data;
- GList *l, *next;
- NautilusFile *file;
- LaunchLocation *location;
-
- parameters->files_handle = NULL;
-
- for (l = parameters->locations; l != NULL; l = next) {
- location = l->data;
- file = location->file;
- next = l->next;
-
- if (file_was_cancelled (file)) {
- launch_location_free (location);
- parameters->locations = g_list_delete_link (parameters->locations, l);
- continue;
- }
-
- if (file_was_not_mounted (file)) {
- if (parameters->tried_mounting) {
- launch_location_free (location);
- parameters->locations = g_list_delete_link (parameters->locations, l);
- } else {
- parameters->not_mounted = g_list_prepend (parameters->not_mounted,
- nautilus_file_ref (file));
- }
- continue;
- }
- }
-
-
- if (parameters->not_mounted != NULL) {
- activation_mount_not_mounted (parameters);
- } else {
- activate_files (parameters);
- }
+activate_callback (GList *files,
+ gpointer callback_data)
+{
+ ActivateParameters *parameters = callback_data;
+ GList *l, *next;
+ NautilusFile *file;
+ LaunchLocation *location;
+
+ parameters->files_handle = NULL;
+
+ for (l = parameters->locations; l != NULL; l = next)
+ {
+ location = l->data;
+ file = location->file;
+ next = l->next;
+
+ if (file_was_cancelled (file))
+ {
+ launch_location_free (location);
+ parameters->locations = g_list_delete_link (parameters->locations, l);
+ continue;
+ }
+
+ if (file_was_not_mounted (file))
+ {
+ if (parameters->tried_mounting)
+ {
+ launch_location_free (location);
+ parameters->locations = g_list_delete_link (parameters->locations, l);
+ }
+ else
+ {
+ parameters->not_mounted = g_list_prepend (parameters->not_mounted,
+ nautilus_file_ref (file));
+ }
+ continue;
+ }
+ }
+
+
+ if (parameters->not_mounted != NULL)
+ {
+ activation_mount_not_mounted (parameters);
+ }
+ else
+ {
+ activate_files (parameters);
+ }
}
static void
-activate_activation_uris_ready_callback (GList *files_ignore,
- gpointer callback_data)
-{
- ActivateParameters *parameters = callback_data;
- GList *l, *next, *files;
- NautilusFile *file;
- LaunchLocation *location;
-
- parameters->files_handle = NULL;
-
- for (l = parameters->locations; l != NULL; l = next) {
- location = l->data;
- file = location->file;
- next = l->next;
-
- if (file_was_cancelled (file)) {
- launch_location_free (location);
- parameters->locations = g_list_delete_link (parameters->locations, l);
- continue;
- }
-
- if (nautilus_file_is_broken_symbolic_link (file)) {
- launch_location_free (location);
- parameters->locations = g_list_delete_link (parameters->locations, l);
- pause_activation_timed_cancel (parameters);
- report_broken_symbolic_link (parameters->parent_window, file);
- unpause_activation_timed_cancel (parameters);
- continue;
- }
-
- if (nautilus_file_get_file_type (file) == G_FILE_TYPE_MOUNTABLE &&
- !nautilus_file_has_activation_uri (file)) {
- /* Don't launch these... There is nothing we
- can do */
- launch_location_free (location);
- parameters->locations = g_list_delete_link (parameters->locations, l);
- continue;
- }
-
- }
-
- if (parameters->locations == NULL) {
- activation_parameters_free (parameters);
- return;
- }
-
- /* Convert the files to the actual activation uri files */
- for (l = parameters->locations; l != NULL; l = l->next) {
- char *uri;
- location = l->data;
-
- /* We want the file for the activation URI since we care
- * about the attributes for that, not for the original file.
- */
- uri = nautilus_file_get_activation_uri (location->file);
- if (uri != NULL) {
- launch_location_update_from_uri (location, uri);
- }
- g_free (uri);
- }
-
-
- /* get the parameters for the actual files */
- files = get_file_list_for_launch_locations (parameters->locations);
- nautilus_file_list_call_when_ready
- (files,
- nautilus_mime_actions_get_required_file_attributes (),
- &parameters->files_handle,
- activate_callback, parameters);
- nautilus_file_list_free (files);
+activate_activation_uris_ready_callback (GList *files_ignore,
+ gpointer callback_data)
+{
+ ActivateParameters *parameters = callback_data;
+ GList *l, *next, *files;
+ NautilusFile *file;
+ LaunchLocation *location;
+
+ parameters->files_handle = NULL;
+
+ for (l = parameters->locations; l != NULL; l = next)
+ {
+ location = l->data;
+ file = location->file;
+ next = l->next;
+
+ if (file_was_cancelled (file))
+ {
+ launch_location_free (location);
+ parameters->locations = g_list_delete_link (parameters->locations, l);
+ continue;
+ }
+
+ if (nautilus_file_is_broken_symbolic_link (file))
+ {
+ launch_location_free (location);
+ parameters->locations = g_list_delete_link (parameters->locations, l);
+ pause_activation_timed_cancel (parameters);
+ report_broken_symbolic_link (parameters->parent_window, file);
+ unpause_activation_timed_cancel (parameters);
+ continue;
+ }
+
+ if (nautilus_file_get_file_type (file) == G_FILE_TYPE_MOUNTABLE &&
+ !nautilus_file_has_activation_uri (file))
+ {
+ /* Don't launch these... There is nothing we
+ * can do */
+ launch_location_free (location);
+ parameters->locations = g_list_delete_link (parameters->locations, l);
+ continue;
+ }
+ }
+
+ if (parameters->locations == NULL)
+ {
+ activation_parameters_free (parameters);
+ return;
+ }
+
+ /* Convert the files to the actual activation uri files */
+ for (l = parameters->locations; l != NULL; l = l->next)
+ {
+ char *uri;
+ location = l->data;
+
+ /* We want the file for the activation URI since we care
+ * about the attributes for that, not for the original file.
+ */
+ uri = nautilus_file_get_activation_uri (location->file);
+ if (uri != NULL)
+ {
+ launch_location_update_from_uri (location, uri);
+ }
+ g_free (uri);
+ }
+
+
+ /* get the parameters for the actual files */
+ files = get_file_list_for_launch_locations (parameters->locations);
+ nautilus_file_list_call_when_ready
+ (files,
+ nautilus_mime_actions_get_required_file_attributes (),
+ &parameters->files_handle,
+ activate_callback, parameters);
+ nautilus_file_list_free (files);
}
static void
activation_get_activation_uris (ActivateParameters *parameters)
{
- GList *l, *files;
- NautilusFile *file;
- LaunchLocation *location;
-
- /* link target info might be stale, re-read it */
- for (l = parameters->locations; l != NULL; l = l->next) {
- location = l->data;
- file = location->file;
-
- if (file_was_cancelled (file)) {
- launch_location_free (location);
- parameters->locations = g_list_delete_link (parameters->locations, l);
- continue;
- }
- }
+ GList *l, *files;
+ NautilusFile *file;
+ LaunchLocation *location;
+
+ /* link target info might be stale, re-read it */
+ for (l = parameters->locations; l != NULL; l = l->next)
+ {
+ location = l->data;
+ file = location->file;
+
+ if (file_was_cancelled (file))
+ {
+ launch_location_free (location);
+ parameters->locations = g_list_delete_link (parameters->locations, l);
+ continue;
+ }
+ }
- if (parameters->locations == NULL) {
- activation_parameters_free (parameters);
- return;
- }
+ if (parameters->locations == NULL)
+ {
+ activation_parameters_free (parameters);
+ return;
+ }
- files = get_file_list_for_launch_locations (parameters->locations);
- nautilus_file_list_call_when_ready
- (files, nautilus_mime_actions_get_required_file_attributes (),
- &parameters->files_handle,
- activate_activation_uris_ready_callback, parameters);
- nautilus_file_list_free (files);
+ files = get_file_list_for_launch_locations (parameters->locations);
+ nautilus_file_list_call_when_ready
+ (files, nautilus_mime_actions_get_required_file_attributes (),
+ &parameters->files_handle,
+ activate_activation_uris_ready_callback, parameters);
+ nautilus_file_list_free (files);
}
static void
-activation_mountable_mounted (NautilusFile *file,
- GFile *result_location,
- GError *error,
- gpointer callback_data)
-{
- ActivateParameters *parameters = callback_data;
- NautilusFile *target_file;
- LaunchLocation *location;
-
- /* Remove from list of files that have to be mounted */
- parameters->mountables = g_list_remove (parameters->mountables, file);
- nautilus_file_unref (file);
-
-
- if (error == NULL) {
- /* Replace file with the result of the mount */
- target_file = nautilus_file_get (result_location);
-
- location = find_launch_location_for_file (parameters->locations,
- file);
- if (location) {
- launch_location_update_from_file (location, target_file);
- }
- nautilus_file_unref (target_file);
- } else {
- /* Remove failed file */
-
- if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_FAILED_HANDLED &&
- error->code != G_IO_ERROR_ALREADY_MOUNTED)) {
- location = find_launch_location_for_file (parameters->locations,
- file);
- if (location) {
- parameters->locations =
- g_list_remove (parameters->locations,
- location);
- launch_location_free (location);
- }
- }
-
- if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED &&
- error->code != G_IO_ERROR_ALREADY_MOUNTED)) {
- eel_show_error_dialog (_("Unable to access location"),
- error->message, parameters->parent_window);
- }
-
- if (error->code == G_IO_ERROR_CANCELLED) {
- activation_parameters_free (parameters);
- return;
- }
- }
-
- /* Mount more mountables */
- activation_mount_mountables (parameters);
+activation_mountable_mounted (NautilusFile *file,
+ GFile *result_location,
+ GError *error,
+ gpointer callback_data)
+{
+ ActivateParameters *parameters = callback_data;
+ NautilusFile *target_file;
+ LaunchLocation *location;
+
+ /* Remove from list of files that have to be mounted */
+ parameters->mountables = g_list_remove (parameters->mountables, file);
+ nautilus_file_unref (file);
+
+
+ if (error == NULL)
+ {
+ /* Replace file with the result of the mount */
+ target_file = nautilus_file_get (result_location);
+
+ location = find_launch_location_for_file (parameters->locations,
+ file);
+ if (location)
+ {
+ launch_location_update_from_file (location, target_file);
+ }
+ nautilus_file_unref (target_file);
+ }
+ else
+ {
+ /* Remove failed file */
+
+ if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_FAILED_HANDLED &&
+ error->code != G_IO_ERROR_ALREADY_MOUNTED))
+ {
+ location = find_launch_location_for_file (parameters->locations,
+ file);
+ if (location)
+ {
+ parameters->locations =
+ g_list_remove (parameters->locations,
+ location);
+ launch_location_free (location);
+ }
+ }
+
+ if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED &&
+ error->code != G_IO_ERROR_ALREADY_MOUNTED))
+ {
+ eel_show_error_dialog (_("Unable to access location"),
+ error->message, parameters->parent_window);
+ }
+
+ if (error->code == G_IO_ERROR_CANCELLED)
+ {
+ activation_parameters_free (parameters);
+ return;
+ }
+ }
+
+ /* Mount more mountables */
+ activation_mount_mountables (parameters);
}
static void
activation_mount_mountables (ActivateParameters *parameters)
{
- NautilusFile *file;
- GMountOperation *mount_op;
-
- if (parameters->mountables != NULL) {
- file = parameters->mountables->data;
- mount_op = gtk_mount_operation_new (parameters->parent_window);
- g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
- g_signal_connect (mount_op, "notify::is-showing",
- G_CALLBACK (activate_mount_op_active), parameters);
- nautilus_file_mount (file,
- mount_op,
- parameters->cancellable,
- activation_mountable_mounted,
- parameters);
- g_object_unref (mount_op);
- return;
- }
+ NautilusFile *file;
+ GMountOperation *mount_op;
+
+ if (parameters->mountables != NULL)
+ {
+ file = parameters->mountables->data;
+ mount_op = gtk_mount_operation_new (parameters->parent_window);
+ g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
+ g_signal_connect (mount_op, "notify::is-showing",
+ G_CALLBACK (activate_mount_op_active), parameters);
+ nautilus_file_mount (file,
+ mount_op,
+ parameters->cancellable,
+ activation_mountable_mounted,
+ parameters);
+ g_object_unref (mount_op);
+ return;
+ }
- if (parameters->mountables == NULL && parameters->start_mountables == NULL)
- activation_get_activation_uris (parameters);
+ if (parameters->mountables == NULL && parameters->start_mountables == NULL)
+ {
+ activation_get_activation_uris (parameters);
+ }
}
static void
-activation_mountable_started (NautilusFile *file,
- GFile *gfile_of_file,
- GError *error,
- gpointer callback_data)
-{
- ActivateParameters *parameters = callback_data;
- LaunchLocation *location;
-
- /* Remove from list of files that have to be mounted */
- parameters->start_mountables = g_list_remove (parameters->start_mountables, file);
- nautilus_file_unref (file);
-
- if (error == NULL) {
- /* Remove file */
- location = find_launch_location_for_file (parameters->locations, file);
- if (location != NULL) {
- parameters->locations = g_list_remove (parameters->locations, location);
- launch_location_free (location);
- }
-
- } else {
- /* Remove failed file */
- if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_FAILED_HANDLED)) {
- location = find_launch_location_for_file (parameters->locations,
- file);
- if (location) {
- parameters->locations =
- g_list_remove (parameters->locations,
- location);
- launch_location_free (location);
- }
- }
-
- if (error->domain != G_IO_ERROR ||
- (error->code != G_IO_ERROR_CANCELLED &&
- error->code != G_IO_ERROR_FAILED_HANDLED)) {
- eel_show_error_dialog (_("Unable to start location"),
- error->message, NULL);
- }
-
- if (error->code == G_IO_ERROR_CANCELLED) {
- activation_parameters_free (parameters);
- return;
- }
- }
-
- /* Start more mountables */
- activation_start_mountables (parameters);
+activation_mountable_started (NautilusFile *file,
+ GFile *gfile_of_file,
+ GError *error,
+ gpointer callback_data)
+{
+ ActivateParameters *parameters = callback_data;
+ LaunchLocation *location;
+
+ /* Remove from list of files that have to be mounted */
+ parameters->start_mountables = g_list_remove (parameters->start_mountables, file);
+ nautilus_file_unref (file);
+
+ if (error == NULL)
+ {
+ /* Remove file */
+ location = find_launch_location_for_file (parameters->locations, file);
+ if (location != NULL)
+ {
+ parameters->locations = g_list_remove (parameters->locations, location);
+ launch_location_free (location);
+ }
+ }
+ else
+ {
+ /* Remove failed file */
+ if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_FAILED_HANDLED))
+ {
+ location = find_launch_location_for_file (parameters->locations,
+ file);
+ if (location)
+ {
+ parameters->locations =
+ g_list_remove (parameters->locations,
+ location);
+ launch_location_free (location);
+ }
+ }
+
+ if (error->domain != G_IO_ERROR ||
+ (error->code != G_IO_ERROR_CANCELLED &&
+ error->code != G_IO_ERROR_FAILED_HANDLED))
+ {
+ eel_show_error_dialog (_("Unable to start location"),
+ error->message, NULL);
+ }
+
+ if (error->code == G_IO_ERROR_CANCELLED)
+ {
+ activation_parameters_free (parameters);
+ return;
+ }
+ }
+
+ /* Start more mountables */
+ activation_start_mountables (parameters);
}
static void
activation_start_mountables (ActivateParameters *parameters)
{
- NautilusFile *file;
- GMountOperation *start_op;
-
- if (parameters->start_mountables != NULL) {
- file = parameters->start_mountables->data;
- start_op = gtk_mount_operation_new (parameters->parent_window);
- g_signal_connect (start_op, "notify::is-showing",
- G_CALLBACK (activate_mount_op_active), parameters);
- nautilus_file_start (file,
- start_op,
- parameters->cancellable,
- activation_mountable_started,
- parameters);
- g_object_unref (start_op);
- return;
- }
+ NautilusFile *file;
+ GMountOperation *start_op;
+
+ if (parameters->start_mountables != NULL)
+ {
+ file = parameters->start_mountables->data;
+ start_op = gtk_mount_operation_new (parameters->parent_window);
+ g_signal_connect (start_op, "notify::is-showing",
+ G_CALLBACK (activate_mount_op_active), parameters);
+ nautilus_file_start (file,
+ start_op,
+ parameters->cancellable,
+ activation_mountable_started,
+ parameters);
+ g_object_unref (start_op);
+ return;
+ }
- if (parameters->mountables == NULL && parameters->start_mountables == NULL)
- activation_get_activation_uris (parameters);
+ if (parameters->mountables == NULL && parameters->start_mountables == NULL)
+ {
+ activation_get_activation_uris (parameters);
+ }
}
/**
* nautilus_mime_activate_files:
- *
+ *
* Activate a list of files. Each one might launch with an application or
* with a component. This is normally called only by subclasses.
* @view: FMDirectoryView in question.
* @files: A GList of NautilusFiles to activate.
- *
+ *
**/
void
-nautilus_mime_activate_files (GtkWindow *parent_window,
- NautilusWindowSlot *slot,
- GList *files,
- const char *launch_directory,
- NautilusWindowOpenFlags flags,
- gboolean user_confirmation)
-{
- ActivateParameters *parameters;
- char *file_name;
- int file_count;
- GList *l, *next;
- NautilusFile *file;
- LaunchLocation *location;
-
- if (files == NULL) {
- return;
- }
-
- DEBUG_FILES (files, "Calling activate_files() with files:");
-
- parameters = g_new0 (ActivateParameters, 1);
- parameters->slot = slot;
- g_object_add_weak_pointer (G_OBJECT (parameters->slot), (gpointer *)&parameters->slot);
- if (parent_window) {
- parameters->parent_window = parent_window;
- g_object_add_weak_pointer (G_OBJECT (parameters->parent_window), (gpointer *)&parameters->parent_window);
- }
- parameters->cancellable = g_cancellable_new ();
- parameters->activation_directory = g_strdup (launch_directory);
- parameters->locations = launch_locations_from_file_list (files);
- parameters->flags = flags;
- parameters->user_confirmation = user_confirmation;
-
- file_count = g_list_length (files);
- if (file_count == 1) {
- file_name = nautilus_file_get_display_name (files->data);
- parameters->timed_wait_prompt = g_strdup_printf (_("Opening “%s”."), file_name);
- g_free (file_name);
- } else {
- parameters->timed_wait_prompt = g_strdup_printf (ngettext ("Opening %d item.",
- "Opening %d items.",
- file_count),
- file_count);
- }
-
-
- for (l = parameters->locations; l != NULL; l = next) {
- location = l->data;
- file = location->file;
- next = l->next;
-
- if (nautilus_file_can_mount (file)) {
- parameters->mountables = g_list_prepend (parameters->mountables,
- nautilus_file_ref (file));
- }
-
- if (nautilus_file_can_start (file)) {
- parameters->start_mountables = g_list_prepend (parameters->start_mountables,
- nautilus_file_ref (file));
- }
- }
-
- activation_start_timed_cancel (parameters);
- if (parameters->mountables != NULL)
- activation_mount_mountables (parameters);
- if (parameters->start_mountables != NULL)
- activation_start_mountables (parameters);
- if (parameters->mountables == NULL && parameters->start_mountables == NULL)
- activation_get_activation_uris (parameters);
+nautilus_mime_activate_files (GtkWindow *parent_window,
+ NautilusWindowSlot *slot,
+ GList *files,
+ const char *launch_directory,
+ NautilusWindowOpenFlags flags,
+ gboolean user_confirmation)
+{
+ ActivateParameters *parameters;
+ char *file_name;
+ int file_count;
+ GList *l, *next;
+ NautilusFile *file;
+ LaunchLocation *location;
+
+ if (files == NULL)
+ {
+ return;
+ }
+
+ DEBUG_FILES (files, "Calling activate_files() with files:");
+
+ parameters = g_new0 (ActivateParameters, 1);
+ parameters->slot = slot;
+ g_object_add_weak_pointer (G_OBJECT (parameters->slot), (gpointer *) &parameters->slot);
+ if (parent_window)
+ {
+ parameters->parent_window = parent_window;
+ g_object_add_weak_pointer (G_OBJECT (parameters->parent_window), (gpointer *) &parameters->parent_window);
+ }
+ parameters->cancellable = g_cancellable_new ();
+ parameters->activation_directory = g_strdup (launch_directory);
+ parameters->locations = launch_locations_from_file_list (files);
+ parameters->flags = flags;
+ parameters->user_confirmation = user_confirmation;
+
+ file_count = g_list_length (files);
+ if (file_count == 1)
+ {
+ file_name = nautilus_file_get_display_name (files->data);
+ parameters->timed_wait_prompt = g_strdup_printf (_("Opening “%s”."), file_name);
+ g_free (file_name);
+ }
+ else
+ {
+ parameters->timed_wait_prompt = g_strdup_printf (ngettext ("Opening %d item.",
+ "Opening %d items.",
+ file_count),
+ file_count);
+ }
+
+
+ for (l = parameters->locations; l != NULL; l = next)
+ {
+ location = l->data;
+ file = location->file;
+ next = l->next;
+
+ if (nautilus_file_can_mount (file))
+ {
+ parameters->mountables = g_list_prepend (parameters->mountables,
+ nautilus_file_ref (file));
+ }
+
+ if (nautilus_file_can_start (file))
+ {
+ parameters->start_mountables = g_list_prepend (parameters->start_mountables,
+ nautilus_file_ref (file));
+ }
+ }
+
+ activation_start_timed_cancel (parameters);
+ if (parameters->mountables != NULL)
+ {
+ activation_mount_mountables (parameters);
+ }
+ if (parameters->start_mountables != NULL)
+ {
+ activation_start_mountables (parameters);
+ }
+ if (parameters->mountables == NULL && parameters->start_mountables == NULL)
+ {
+ activation_get_activation_uris (parameters);
+ }
}
/**
* nautilus_mime_activate_file:
- *
+ *
* Activate a file in this view. This might involve switching the displayed
* location for the current window, or launching an application.
* @view: FMDirectoryView in question.
* @file: A NautilusFile representing the file in this view to activate.
* @use_new_window: Should this item be opened in a new window?
- *
+ *
**/
void
-nautilus_mime_activate_file (GtkWindow *parent_window,
- NautilusWindowSlot *slot,
- NautilusFile *file,
- const char *launch_directory,
- NautilusWindowOpenFlags flags)
+nautilus_mime_activate_file (GtkWindow *parent_window,
+ NautilusWindowSlot *slot,
+ NautilusFile *file,
+ const char *launch_directory,
+ NautilusWindowOpenFlags flags)
{
- GList *files;
+ GList *files;
- g_return_if_fail (NAUTILUS_IS_FILE (file));
+ g_return_if_fail (NAUTILUS_IS_FILE (file));
- files = g_list_prepend (NULL, file);
- nautilus_mime_activate_files (parent_window, slot, files, launch_directory, flags, FALSE);
- g_list_free (files);
+ files = g_list_prepend (NULL, file);
+ nautilus_mime_activate_files (parent_window, slot, files, launch_directory, flags, FALSE);
+ g_list_free (files);
}
gint
nautilus_mime_types_get_number_of_groups (void)
{
- return G_N_ELEMENTS (mimetype_groups);
+ return G_N_ELEMENTS (mimetype_groups);
}
-const gchar*
+const gchar *
nautilus_mime_types_group_get_name (gint group_index)
{
- g_return_val_if_fail (group_index < G_N_ELEMENTS (mimetype_groups), NULL);
+ g_return_val_if_fail (group_index < G_N_ELEMENTS (mimetype_groups), NULL);
- return gettext (mimetype_groups[group_index].name);
+ return gettext (mimetype_groups[group_index].name);
}
-GList*
+GList *
nautilus_mime_types_group_get_mimetypes (gint group_index)
{
- GList *mimetypes;
- gint i;
+ GList *mimetypes;
+ gint i;
- g_return_val_if_fail (group_index < G_N_ELEMENTS (mimetype_groups), NULL);
+ g_return_val_if_fail (group_index < G_N_ELEMENTS (mimetype_groups), NULL);
- mimetypes = NULL;
+ mimetypes = NULL;
- /* Setup the new mimetypes set */
- for (i = 0; mimetype_groups[group_index].mimetypes[i]; i++)
- {
- mimetypes = g_list_append (mimetypes, mimetype_groups[group_index].mimetypes[i]);
- }
+ /* Setup the new mimetypes set */
+ for (i = 0; mimetype_groups[group_index].mimetypes[i]; i++)
+ {
+ mimetypes = g_list_append (mimetypes, mimetype_groups[group_index].mimetypes[i]);
+ }
- return mimetypes;
+ return mimetypes;
}
diff --git a/src/nautilus-mime-application-chooser.c b/src/nautilus-mime-application-chooser.c
index ebe069fa3..813eaeca3 100644
--- a/src/nautilus-mime-application-chooser.c
+++ b/src/nautilus-mime-application-chooser.c
@@ -1,4 +1,3 @@
-
/*
* nautilus-mime-application-chooser.c: an mime-application chooser
*
@@ -37,22 +36,24 @@
#include <gtk/gtk.h>
#include <gio/gio.h>
-struct _NautilusMimeApplicationChooserDetails {
- GList *files;
+struct _NautilusMimeApplicationChooserDetails
+{
+ GList *files;
- char *content_type;
+ char *content_type;
- GtkWidget *label;
- GtkWidget *entry;
- GtkWidget *set_as_default_button;
- GtkWidget *open_with_widget;
- GtkWidget *add_button;
+ GtkWidget *label;
+ GtkWidget *entry;
+ GtkWidget *set_as_default_button;
+ GtkWidget *open_with_widget;
+ GtkWidget *add_button;
};
-enum {
- PROP_CONTENT_TYPE = 1,
- PROP_FILES,
- NUM_PROPERTIES
+enum
+{
+ PROP_CONTENT_TYPE = 1,
+ PROP_FILES,
+ NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
@@ -61,413 +62,448 @@ G_DEFINE_TYPE (NautilusMimeApplicationChooser, nautilus_mime_application_chooser
static void
add_clicked_cb (GtkButton *button,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusMimeApplicationChooser *chooser = user_data;
- GAppInfo *info;
- gchar *message;
- GError *error = NULL;
-
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
-
- if (info == NULL)
- return;
-
- g_app_info_set_as_last_used_for_type (info, chooser->details->content_type, &error);
-
- if (error != NULL) {
- message = g_strdup_printf (_("Error while adding “%s”: %s"),
- g_app_info_get_display_name (info), error->message);
- eel_show_error_dialog (_("Could not add application"),
- message,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser))));
- g_error_free (error);
- g_free (message);
- } else {
- gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
- }
-
- g_object_unref (info);
+ NautilusMimeApplicationChooser *chooser = user_data;
+ GAppInfo *info;
+ gchar *message;
+ GError *error = NULL;
+
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+
+ if (info == NULL)
+ {
+ return;
+ }
+
+ g_app_info_set_as_last_used_for_type (info, chooser->details->content_type, &error);
+
+ if (error != NULL)
+ {
+ message = g_strdup_printf (_("Error while adding “%s”: %s"),
+ g_app_info_get_display_name (info), error->message);
+ eel_show_error_dialog (_("Could not add application"),
+ message,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser))));
+ g_error_free (error);
+ g_free (message);
+ }
+ else
+ {
+ gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+ g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ }
+
+ g_object_unref (info);
}
static void
-remove_clicked_cb (GtkMenuItem *item,
- gpointer user_data)
+remove_clicked_cb (GtkMenuItem *item,
+ gpointer user_data)
{
- NautilusMimeApplicationChooser *chooser = user_data;
- GError *error;
- GAppInfo *info;
-
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
-
- if (info) {
- error = NULL;
- if (!g_app_info_remove_supports_type (info,
- chooser->details->content_type,
- &error)) {
- eel_show_error_dialog (_("Could not forget association"),
- error->message,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser))));
- g_error_free (error);
-
- }
-
- gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
- g_object_unref (info);
- }
-
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ NautilusMimeApplicationChooser *chooser = user_data;
+ GError *error;
+ GAppInfo *info;
+
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+
+ if (info)
+ {
+ error = NULL;
+ if (!g_app_info_remove_supports_type (info,
+ chooser->details->content_type,
+ &error))
+ {
+ eel_show_error_dialog (_("Could not forget association"),
+ error->message,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser))));
+ g_error_free (error);
+ }
+
+ gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+ g_object_unref (info);
+ }
+
+ g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
}
static void
populate_popup_cb (GtkAppChooserWidget *widget,
- GtkMenu *menu,
- GAppInfo *app,
- gpointer user_data)
+ GtkMenu *menu,
+ GAppInfo *app,
+ gpointer user_data)
{
- GtkWidget *item;
- NautilusMimeApplicationChooser *chooser = user_data;
-
- if (g_app_info_can_remove_supports_type (app)) {
- item = gtk_menu_item_new_with_label (_("Forget association"));
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
-
- g_signal_connect (item, "activate",
- G_CALLBACK (remove_clicked_cb), chooser);
- }
+ GtkWidget *item;
+ NautilusMimeApplicationChooser *chooser = user_data;
+
+ if (g_app_info_can_remove_supports_type (app))
+ {
+ item = gtk_menu_item_new_with_label (_("Forget association"));
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ g_signal_connect (item, "activate",
+ G_CALLBACK (remove_clicked_cb), chooser);
+ }
}
static void
reset_clicked_cb (GtkButton *button,
gpointer user_data)
{
- NautilusMimeApplicationChooser *chooser;
-
- chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (user_data);
+ NautilusMimeApplicationChooser *chooser;
+
+ chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (user_data);
- g_app_info_reset_type_associations (chooser->details->content_type);
- gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+ g_app_info_reset_type_associations (chooser->details->content_type);
+ gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
}
static void
set_as_default_clicked_cb (GtkButton *button,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusMimeApplicationChooser *chooser = user_data;
- GAppInfo *info;
- GError *error = NULL;
- gchar *message = NULL;
+ NautilusMimeApplicationChooser *chooser = user_data;
+ GAppInfo *info;
+ GError *error = NULL;
+ gchar *message = NULL;
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
- g_app_info_set_as_default_for_type (info, chooser->details->content_type,
- &error);
+ g_app_info_set_as_default_for_type (info, chooser->details->content_type,
+ &error);
- if (error != NULL) {
- message = g_strdup_printf (_("Error while setting “%s” as default application: %s"),
- g_app_info_get_display_name (info), error->message);
- eel_show_error_dialog (_("Could not set as default"),
- message,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser))));
- }
+ if (error != NULL)
+ {
+ message = g_strdup_printf (_("Error while setting “%s” as default application: %s"),
+ g_app_info_get_display_name (info), error->message);
+ eel_show_error_dialog (_("Could not set as default"),
+ message,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (chooser))));
+ }
- g_object_unref (info);
+ g_object_unref (info);
- gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
- g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
+ gtk_app_chooser_refresh (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+ g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
}
static gint
app_compare (gconstpointer a,
- gconstpointer b)
+ gconstpointer b)
{
- return !g_app_info_equal (G_APP_INFO (a), G_APP_INFO (b));
+ return !g_app_info_equal (G_APP_INFO (a), G_APP_INFO (b));
}
static gboolean
-app_info_can_add (GAppInfo *info,
- const gchar *content_type)
+app_info_can_add (GAppInfo *info,
+ const gchar *content_type)
{
- GList *recommended, *fallback;
- gboolean retval = FALSE;
+ GList *recommended, *fallback;
+ gboolean retval = FALSE;
- recommended = g_app_info_get_recommended_for_type (content_type);
- fallback = g_app_info_get_fallback_for_type (content_type);
+ recommended = g_app_info_get_recommended_for_type (content_type);
+ fallback = g_app_info_get_fallback_for_type (content_type);
- if (g_list_find_custom (recommended, info, app_compare)) {
- goto out;
- }
+ if (g_list_find_custom (recommended, info, app_compare))
+ {
+ goto out;
+ }
- if (g_list_find_custom (fallback, info, app_compare)) {
- goto out;
- }
+ if (g_list_find_custom (fallback, info, app_compare))
+ {
+ goto out;
+ }
- retval = TRUE;
+ retval = TRUE;
- out:
- g_list_free_full (recommended, g_object_unref);
- g_list_free_full (fallback, g_object_unref);
+out:
+ g_list_free_full (recommended, g_object_unref);
+ g_list_free_full (fallback, g_object_unref);
- return retval;
+ return retval;
}
static void
application_selected_cb (GtkAppChooserWidget *widget,
- GAppInfo *info,
- gpointer user_data)
+ GAppInfo *info,
+ gpointer user_data)
{
- NautilusMimeApplicationChooser *chooser = user_data;
- GAppInfo *default_app;
-
- default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE);
- if (default_app != NULL) {
- gtk_widget_set_sensitive (chooser->details->set_as_default_button,
- !g_app_info_equal (info, default_app));
- g_object_unref (default_app);
- }
- gtk_widget_set_sensitive (chooser->details->add_button,
- app_info_can_add (info, chooser->details->content_type));
+ NautilusMimeApplicationChooser *chooser = user_data;
+ GAppInfo *default_app;
+
+ default_app = g_app_info_get_default_for_type (chooser->details->content_type, FALSE);
+ if (default_app != NULL)
+ {
+ gtk_widget_set_sensitive (chooser->details->set_as_default_button,
+ !g_app_info_equal (info, default_app));
+ g_object_unref (default_app);
+ }
+ gtk_widget_set_sensitive (chooser->details->add_button,
+ app_info_can_add (info, chooser->details->content_type));
}
static void
nautilus_mime_application_chooser_apply_labels (NautilusMimeApplicationChooser *chooser)
{
- gchar *label, *extension = NULL, *description = NULL;
- gint num_files;
- NautilusFile *file;
-
- num_files = g_list_length (chooser->details->files);
- file = chooser->details->files->data;
-
- /* here we assume all files are of the same content type */
- if (g_content_type_is_unknown (chooser->details->content_type)) {
- extension = nautilus_file_get_extension (file);
-
- /* Translators: the %s here is a file extension */
- description = g_strdup_printf (_("%s document"), extension);
- } else {
- description = g_content_type_get_description (chooser->details->content_type);
- }
-
- if (num_files > 1) {
- /* Translators; %s here is a mime-type description */
- label = g_strdup_printf (_("Open all files of type “%s” with"),
- description);
- } else {
- gchar *display_name;
- display_name = nautilus_file_get_display_name (file);
-
- /* Translators: first %s is filename, second %s is mime-type description */
- label = g_strdup_printf (_("Select an application to open “%s” and other files of type “%s”"),
- display_name, description);
-
- g_free (display_name);
- }
-
- gtk_label_set_markup (GTK_LABEL (chooser->details->label), label);
-
- g_free (label);
- g_free (extension);
- g_free (description);
+ gchar *label, *extension = NULL, *description = NULL;
+ gint num_files;
+ NautilusFile *file;
+
+ num_files = g_list_length (chooser->details->files);
+ file = chooser->details->files->data;
+
+ /* here we assume all files are of the same content type */
+ if (g_content_type_is_unknown (chooser->details->content_type))
+ {
+ extension = nautilus_file_get_extension (file);
+
+ /* Translators: the %s here is a file extension */
+ description = g_strdup_printf (_("%s document"), extension);
+ }
+ else
+ {
+ description = g_content_type_get_description (chooser->details->content_type);
+ }
+
+ if (num_files > 1)
+ {
+ /* Translators; %s here is a mime-type description */
+ label = g_strdup_printf (_("Open all files of type “%s” with"),
+ description);
+ }
+ else
+ {
+ gchar *display_name;
+ display_name = nautilus_file_get_display_name (file);
+
+ /* Translators: first %s is filename, second %s is mime-type description */
+ label = g_strdup_printf (_("Select an application to open “%s” and other files of type “%s”"),
+ display_name, description);
+
+ g_free (display_name);
+ }
+
+ gtk_label_set_markup (GTK_LABEL (chooser->details->label), label);
+
+ g_free (label);
+ g_free (extension);
+ g_free (description);
}
static void
nautilus_mime_application_chooser_build_ui (NautilusMimeApplicationChooser *chooser)
{
- GtkWidget *box, *button;
- GAppInfo *info;
-
- gtk_container_set_border_width (GTK_CONTAINER (chooser), 8);
- gtk_box_set_spacing (GTK_BOX (chooser), 0);
- gtk_box_set_homogeneous (GTK_BOX (chooser), FALSE);
-
- chooser->details->label = gtk_label_new ("");
- gtk_label_set_xalign (GTK_LABEL (chooser->details->label), 0);
- gtk_label_set_line_wrap (GTK_LABEL (chooser->details->label), TRUE);
- gtk_label_set_line_wrap_mode (GTK_LABEL (chooser->details->label),
- PANGO_WRAP_WORD_CHAR);
- gtk_label_set_max_width_chars (GTK_LABEL (chooser->details->label), 60);
- gtk_box_pack_start (GTK_BOX (chooser), chooser->details->label,
- FALSE, FALSE, 0);
-
- gtk_widget_show (chooser->details->label);
-
- chooser->details->open_with_widget = gtk_app_chooser_widget_new (chooser->details->content_type);
- gtk_app_chooser_widget_set_show_default (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
- TRUE);
- gtk_app_chooser_widget_set_show_fallback (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
- TRUE);
- gtk_app_chooser_widget_set_show_other (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
- TRUE);
- gtk_box_pack_start (GTK_BOX (chooser), chooser->details->open_with_widget,
- TRUE, TRUE, 6);
- gtk_widget_show (chooser->details->open_with_widget);
-
- box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_box_set_spacing (GTK_BOX (box), 6);
- gtk_button_box_set_layout (GTK_BUTTON_BOX (box), GTK_BUTTONBOX_END);
- gtk_box_pack_start (GTK_BOX (chooser), box, FALSE, FALSE, 6);
- gtk_widget_show (box);
-
- button = gtk_button_new_with_label (_("Reset"));
- g_signal_connect (button, "clicked",
- G_CALLBACK (reset_clicked_cb),
- chooser);
- gtk_widget_show (button);
- gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
- gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (box), button, TRUE);
-
- button = gtk_button_new_with_mnemonic (_("_Add"));
- g_signal_connect (button, "clicked",
- G_CALLBACK (add_clicked_cb),
- chooser);
- gtk_widget_show (button);
- gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
- chooser->details->add_button = button;
-
- button = gtk_button_new_with_label (_("Set as default"));
- g_signal_connect (button, "clicked",
- G_CALLBACK (set_as_default_clicked_cb),
- chooser);
- gtk_widget_show (button);
- gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
-
- chooser->details->set_as_default_button = button;
-
- /* initialize sensitivity */
- info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
- if (info != NULL) {
- application_selected_cb (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
- info, chooser);
- g_object_unref (info);
- }
-
- g_signal_connect (chooser->details->open_with_widget,
- "application-selected",
- G_CALLBACK (application_selected_cb),
- chooser);
- g_signal_connect (chooser->details->open_with_widget,
- "populate-popup",
- G_CALLBACK (populate_popup_cb),
- chooser);
+ GtkWidget *box, *button;
+ GAppInfo *info;
+
+ gtk_container_set_border_width (GTK_CONTAINER (chooser), 8);
+ gtk_box_set_spacing (GTK_BOX (chooser), 0);
+ gtk_box_set_homogeneous (GTK_BOX (chooser), FALSE);
+
+ chooser->details->label = gtk_label_new ("");
+ gtk_label_set_xalign (GTK_LABEL (chooser->details->label), 0);
+ gtk_label_set_line_wrap (GTK_LABEL (chooser->details->label), TRUE);
+ gtk_label_set_line_wrap_mode (GTK_LABEL (chooser->details->label),
+ PANGO_WRAP_WORD_CHAR);
+ gtk_label_set_max_width_chars (GTK_LABEL (chooser->details->label), 60);
+ gtk_box_pack_start (GTK_BOX (chooser), chooser->details->label,
+ FALSE, FALSE, 0);
+
+ gtk_widget_show (chooser->details->label);
+
+ chooser->details->open_with_widget = gtk_app_chooser_widget_new (chooser->details->content_type);
+ gtk_app_chooser_widget_set_show_default (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
+ TRUE);
+ gtk_app_chooser_widget_set_show_fallback (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
+ TRUE);
+ gtk_app_chooser_widget_set_show_other (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
+ TRUE);
+ gtk_box_pack_start (GTK_BOX (chooser), chooser->details->open_with_widget,
+ TRUE, TRUE, 6);
+ gtk_widget_show (chooser->details->open_with_widget);
+
+ box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_box_set_spacing (GTK_BOX (box), 6);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (box), GTK_BUTTONBOX_END);
+ gtk_box_pack_start (GTK_BOX (chooser), box, FALSE, FALSE, 6);
+ gtk_widget_show (box);
+
+ button = gtk_button_new_with_label (_("Reset"));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (reset_clicked_cb),
+ chooser);
+ gtk_widget_show (button);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (box), button, TRUE);
+
+ button = gtk_button_new_with_mnemonic (_("_Add"));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (add_clicked_cb),
+ chooser);
+ gtk_widget_show (button);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+ chooser->details->add_button = button;
+
+ button = gtk_button_new_with_label (_("Set as default"));
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (set_as_default_clicked_cb),
+ chooser);
+ gtk_widget_show (button);
+ gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
+
+ chooser->details->set_as_default_button = button;
+
+ /* initialize sensitivity */
+ info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (chooser->details->open_with_widget));
+ if (info != NULL)
+ {
+ application_selected_cb (GTK_APP_CHOOSER_WIDGET (chooser->details->open_with_widget),
+ info, chooser);
+ g_object_unref (info);
+ }
+
+ g_signal_connect (chooser->details->open_with_widget,
+ "application-selected",
+ G_CALLBACK (application_selected_cb),
+ chooser);
+ g_signal_connect (chooser->details->open_with_widget,
+ "populate-popup",
+ G_CALLBACK (populate_popup_cb),
+ chooser);
}
static void
nautilus_mime_application_chooser_init (NautilusMimeApplicationChooser *chooser)
{
- chooser->details = G_TYPE_INSTANCE_GET_PRIVATE (chooser, NAUTILUS_TYPE_MIME_APPLICATION_CHOOSER,
- NautilusMimeApplicationChooserDetails);
+ chooser->details = G_TYPE_INSTANCE_GET_PRIVATE (chooser, NAUTILUS_TYPE_MIME_APPLICATION_CHOOSER,
+ NautilusMimeApplicationChooserDetails);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (chooser),
- GTK_ORIENTATION_VERTICAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (chooser),
+ GTK_ORIENTATION_VERTICAL);
}
static void
nautilus_mime_application_chooser_constructed (GObject *object)
{
- NautilusMimeApplicationChooser *chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
+ NautilusMimeApplicationChooser *chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
- if (G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->constructed != NULL)
- G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->constructed (object);
+ if (G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->constructed != NULL)
+ {
+ G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->constructed (object);
+ }
- nautilus_mime_application_chooser_build_ui (chooser);
- nautilus_mime_application_chooser_apply_labels (chooser);
+ nautilus_mime_application_chooser_build_ui (chooser);
+ nautilus_mime_application_chooser_apply_labels (chooser);
}
static void
nautilus_mime_application_chooser_finalize (GObject *object)
{
- NautilusMimeApplicationChooser *chooser;
+ NautilusMimeApplicationChooser *chooser;
- chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
+ chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
- g_free (chooser->details->content_type);
- nautilus_file_list_free (chooser->details->files);
+ g_free (chooser->details->content_type);
+ nautilus_file_list_free (chooser->details->files);
- G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_mime_application_chooser_parent_class)->finalize (object);
}
static void
-nautilus_mime_application_chooser_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_mime_application_chooser_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusMimeApplicationChooser *chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
-
- switch (property_id) {
- case PROP_CONTENT_TYPE:
- g_value_set_string (value, chooser->details->content_type);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusMimeApplicationChooser *chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
+
+ switch (property_id)
+ {
+ case PROP_CONTENT_TYPE:
+ {
+ g_value_set_string (value, chooser->details->content_type);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_mime_application_chooser_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_mime_application_chooser_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusMimeApplicationChooser *chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
-
- switch (property_id) {
- case PROP_CONTENT_TYPE:
- chooser->details->content_type = g_value_dup_string (value);
- break;
- case PROP_FILES:
- chooser->details->files = nautilus_file_list_copy (g_value_get_pointer (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusMimeApplicationChooser *chooser = NAUTILUS_MIME_APPLICATION_CHOOSER (object);
+
+ switch (property_id)
+ {
+ case PROP_CONTENT_TYPE:
+ {
+ chooser->details->content_type = g_value_dup_string (value);
+ }
+ break;
+
+ case PROP_FILES:
+ {
+ chooser->details->files = nautilus_file_list_copy (g_value_get_pointer (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_mime_application_chooser_class_init (NautilusMimeApplicationChooserClass *class)
{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->set_property = nautilus_mime_application_chooser_set_property;
- gobject_class->get_property = nautilus_mime_application_chooser_get_property;
- gobject_class->finalize = nautilus_mime_application_chooser_finalize;
- gobject_class->constructed = nautilus_mime_application_chooser_constructed;
-
- properties[PROP_CONTENT_TYPE] = g_param_spec_string ("content-type",
- "Content type",
- "Content type for this widget",
- NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- properties[PROP_FILES] = g_param_spec_pointer ("files",
- "Files",
- "Files for this widget",
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
-
- g_type_class_add_private (class, sizeof (NautilusMimeApplicationChooserDetails));
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->set_property = nautilus_mime_application_chooser_set_property;
+ gobject_class->get_property = nautilus_mime_application_chooser_get_property;
+ gobject_class->finalize = nautilus_mime_application_chooser_finalize;
+ gobject_class->constructed = nautilus_mime_application_chooser_constructed;
+
+ properties[PROP_CONTENT_TYPE] = g_param_spec_string ("content-type",
+ "Content type",
+ "Content type for this widget",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ properties[PROP_FILES] = g_param_spec_pointer ("files",
+ "Files",
+ "Files for this widget",
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
+
+ g_type_class_add_private (class, sizeof (NautilusMimeApplicationChooserDetails));
}
GtkWidget *
-nautilus_mime_application_chooser_new (GList *files,
- const char *mime_type)
+nautilus_mime_application_chooser_new (GList *files,
+ const char *mime_type)
{
- GtkWidget *chooser;
+ GtkWidget *chooser;
- chooser = g_object_new (NAUTILUS_TYPE_MIME_APPLICATION_CHOOSER,
- "files", files,
- "content-type", mime_type,
- NULL);
+ chooser = g_object_new (NAUTILUS_TYPE_MIME_APPLICATION_CHOOSER,
+ "files", files,
+ "content-type", mime_type,
+ NULL);
- return chooser;
+ return chooser;
}
diff --git a/src/nautilus-module.c b/src/nautilus-module.c
index 7e52243fd..bf474bd6f 100644
--- a/src/nautilus-module.c
+++ b/src/nautilus-module.c
@@ -1,6 +1,6 @@
/*
* nautilus-module.h - Interface to nautilus extensions
- *
+ *
* Copyright (C) 2003 Novell, Inc.
*
* This library is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Dave Camp <dave@ximian.com>
- *
+ *
*/
#include <config.h>
@@ -26,32 +26,33 @@
#include <eel/eel-debug.h>
#include <gmodule.h>
-#define NAUTILUS_TYPE_MODULE (nautilus_module_get_type ())
-#define NAUTILUS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_MODULE, NautilusModule))
-#define NAUTILUS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_MODULE, NautilusModule))
-#define NAUTILUS_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_MODULE))
-#define NAUTILUS_IS_MODULE_CLASS(klass) (G_TYPE_CLASS_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_MODULE))
+#define NAUTILUS_TYPE_MODULE (nautilus_module_get_type ())
+#define NAUTILUS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_MODULE, NautilusModule))
+#define NAUTILUS_MODULE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_MODULE, NautilusModule))
+#define NAUTILUS_IS_MODULE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_MODULE))
+#define NAUTILUS_IS_MODULE_CLASS(klass) (G_TYPE_CLASS_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_MODULE))
-typedef struct _NautilusModule NautilusModule;
-typedef struct _NautilusModuleClass NautilusModuleClass;
+typedef struct _NautilusModule NautilusModule;
+typedef struct _NautilusModuleClass NautilusModuleClass;
-struct _NautilusModule {
- GTypeModule parent;
-
- GModule *library;
+struct _NautilusModule
+{
+ GTypeModule parent;
- char *path;
+ GModule *library;
- void (*initialize) (GTypeModule *module);
- void (*shutdown) (void);
+ char *path;
- void (*list_types) (const GType **types,
- int *num_types);
+ void (*initialize) (GTypeModule *module);
+ void (*shutdown) (void);
+ void (*list_types) (const GType **types,
+ int *num_types);
};
-struct _NautilusModuleClass {
- GTypeModuleClass parent;
+struct _NautilusModuleClass
+{
+ GTypeModuleClass parent;
};
static GList *module_objects = NULL;
@@ -63,85 +64,87 @@ G_DEFINE_TYPE (NautilusModule, nautilus_module, G_TYPE_TYPE_MODULE);
static gboolean
module_pulls_in_orbit (GModule *module)
{
- gpointer symbol;
- gboolean res;
+ gpointer symbol;
+ gboolean res;
- res = g_module_symbol (module, "ORBit_realloc_tcval", &symbol);
+ res = g_module_symbol (module, "ORBit_realloc_tcval", &symbol);
- return res;
+ return res;
}
static gboolean
nautilus_module_load (GTypeModule *gmodule)
{
- NautilusModule *module;
-
- module = NAUTILUS_MODULE (gmodule);
-
- module->library = g_module_open (module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
-
- if (!module->library) {
- g_warning ("%s", g_module_error ());
- return FALSE;
- }
-
- /* ORBit installs atexit() handlers, which would get unloaded together
- * with the module now that the main process doesn't depend on GConf anymore,
- * causing nautilus to sefgault at exit.
- * If we detect that an extension would pull in ORBit, we make the
- * module resident to prevent that.
- */
- if (module_pulls_in_orbit (module->library)) {
- g_module_make_resident (module->library);
- }
-
- if (!g_module_symbol (module->library,
- "nautilus_module_initialize",
- (gpointer *)&module->initialize) ||
- !g_module_symbol (module->library,
- "nautilus_module_shutdown",
- (gpointer *)&module->shutdown) ||
- !g_module_symbol (module->library,
- "nautilus_module_list_types",
- (gpointer *)&module->list_types)) {
-
- g_warning ("%s", g_module_error ());
- g_module_close (module->library);
-
- return FALSE;
- }
-
- module->initialize (gmodule);
-
- return TRUE;
+ NautilusModule *module;
+
+ module = NAUTILUS_MODULE (gmodule);
+
+ module->library = g_module_open (module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+
+ if (!module->library)
+ {
+ g_warning ("%s", g_module_error ());
+ return FALSE;
+ }
+
+ /* ORBit installs atexit() handlers, which would get unloaded together
+ * with the module now that the main process doesn't depend on GConf anymore,
+ * causing nautilus to sefgault at exit.
+ * If we detect that an extension would pull in ORBit, we make the
+ * module resident to prevent that.
+ */
+ if (module_pulls_in_orbit (module->library))
+ {
+ g_module_make_resident (module->library);
+ }
+
+ if (!g_module_symbol (module->library,
+ "nautilus_module_initialize",
+ (gpointer *) &module->initialize) ||
+ !g_module_symbol (module->library,
+ "nautilus_module_shutdown",
+ (gpointer *) &module->shutdown) ||
+ !g_module_symbol (module->library,
+ "nautilus_module_list_types",
+ (gpointer *) &module->list_types))
+ {
+ g_warning ("%s", g_module_error ());
+ g_module_close (module->library);
+
+ return FALSE;
+ }
+
+ module->initialize (gmodule);
+
+ return TRUE;
}
static void
nautilus_module_unload (GTypeModule *gmodule)
{
- NautilusModule *module;
-
- module = NAUTILUS_MODULE (gmodule);
-
- module->shutdown ();
-
- g_module_close (module->library);
-
- module->initialize = NULL;
- module->shutdown = NULL;
- module->list_types = NULL;
+ NautilusModule *module;
+
+ module = NAUTILUS_MODULE (gmodule);
+
+ module->shutdown ();
+
+ g_module_close (module->library);
+
+ module->initialize = NULL;
+ module->shutdown = NULL;
+ module->list_types = NULL;
}
static void
nautilus_module_finalize (GObject *object)
{
- NautilusModule *module;
-
- module = NAUTILUS_MODULE (object);
+ NautilusModule *module;
+
+ module = NAUTILUS_MODULE (object);
+
+ g_free (module->path);
- g_free (module->path);
-
- G_OBJECT_CLASS (nautilus_module_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_module_parent_class)->finalize (object);
}
static void
@@ -152,143 +155,157 @@ nautilus_module_init (NautilusModule *module)
static void
nautilus_module_class_init (NautilusModuleClass *class)
{
- G_OBJECT_CLASS (class)->finalize = nautilus_module_finalize;
- G_TYPE_MODULE_CLASS (class)->load = nautilus_module_load;
- G_TYPE_MODULE_CLASS (class)->unload = nautilus_module_unload;
+ G_OBJECT_CLASS (class)->finalize = nautilus_module_finalize;
+ G_TYPE_MODULE_CLASS (class)->load = nautilus_module_load;
+ G_TYPE_MODULE_CLASS (class)->unload = nautilus_module_unload;
}
static void
-module_object_weak_notify (gpointer user_data, GObject *object)
+module_object_weak_notify (gpointer user_data,
+ GObject *object)
{
- module_objects = g_list_remove (module_objects, object);
+ module_objects = g_list_remove (module_objects, object);
}
static void
add_module_objects (NautilusModule *module)
{
- const GType *types;
- int num_types;
- int i;
-
- module->list_types (&types, &num_types);
-
- for (i = 0; i < num_types; i++) {
- if (types[i] == 0) { /* Work around broken extensions */
- break;
- }
- nautilus_module_add_type (types[i]);
- }
+ const GType *types;
+ int num_types;
+ int i;
+
+ module->list_types (&types, &num_types);
+
+ for (i = 0; i < num_types; i++)
+ {
+ if (types[i] == 0) /* Work around broken extensions */
+ {
+ break;
+ }
+ nautilus_module_add_type (types[i]);
+ }
}
static NautilusModule *
nautilus_module_load_file (const char *filename)
{
- NautilusModule *module;
-
- module = g_object_new (NAUTILUS_TYPE_MODULE, NULL);
- module->path = g_strdup (filename);
-
- if (g_type_module_use (G_TYPE_MODULE (module))) {
- add_module_objects (module);
- g_type_module_unuse (G_TYPE_MODULE (module));
- return module;
- } else {
- g_object_unref (module);
- return NULL;
- }
+ NautilusModule *module;
+
+ module = g_object_new (NAUTILUS_TYPE_MODULE, NULL);
+ module->path = g_strdup (filename);
+
+ if (g_type_module_use (G_TYPE_MODULE (module)))
+ {
+ add_module_objects (module);
+ g_type_module_unuse (G_TYPE_MODULE (module));
+ return module;
+ }
+ else
+ {
+ g_object_unref (module);
+ return NULL;
+ }
}
static void
load_module_dir (const char *dirname)
{
- GDir *dir;
-
- dir = g_dir_open (dirname, 0, NULL);
-
- if (dir) {
- const char *name;
-
- while ((name = g_dir_read_name (dir))) {
- if (g_str_has_suffix (name, "." G_MODULE_SUFFIX)) {
- char *filename;
-
- filename = g_build_filename (dirname,
- name,
- NULL);
- nautilus_module_load_file (filename);
- g_free (filename);
- }
- }
-
- g_dir_close (dir);
- }
+ GDir *dir;
+
+ dir = g_dir_open (dirname, 0, NULL);
+
+ if (dir)
+ {
+ const char *name;
+
+ while ((name = g_dir_read_name (dir)))
+ {
+ if (g_str_has_suffix (name, "." G_MODULE_SUFFIX))
+ {
+ char *filename;
+
+ filename = g_build_filename (dirname,
+ name,
+ NULL);
+ nautilus_module_load_file (filename);
+ g_free (filename);
+ }
+ }
+
+ g_dir_close (dir);
+ }
}
static void
free_module_objects (void)
{
- GList *l, *next;
-
- for (l = module_objects; l != NULL; l = next) {
- next = l->next;
- g_object_unref (l->data);
- }
-
- g_list_free (module_objects);
+ GList *l, *next;
+
+ for (l = module_objects; l != NULL; l = next)
+ {
+ next = l->next;
+ g_object_unref (l->data);
+ }
+
+ g_list_free (module_objects);
}
void
nautilus_module_setup (void)
{
- static gboolean initialized = FALSE;
+ static gboolean initialized = FALSE;
- if (!initialized) {
- initialized = TRUE;
-
- load_module_dir (NAUTILUS_EXTENSIONDIR);
+ if (!initialized)
+ {
+ initialized = TRUE;
- eel_debug_call_at_shutdown (free_module_objects);
- }
+ load_module_dir (NAUTILUS_EXTENSIONDIR);
+
+ eel_debug_call_at_shutdown (free_module_objects);
+ }
}
GList *
nautilus_module_get_extensions_for_type (GType type)
{
- GList *l;
- GList *ret = NULL;
-
- for (l = module_objects; l != NULL; l = l->next) {
- if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (l->data),
- type)) {
- g_object_ref (l->data);
- ret = g_list_prepend (ret, l->data);
- }
- }
-
- return ret;
+ GList *l;
+ GList *ret = NULL;
+
+ for (l = module_objects; l != NULL; l = l->next)
+ {
+ if (G_TYPE_CHECK_INSTANCE_TYPE (G_OBJECT (l->data),
+ type))
+ {
+ g_object_ref (l->data);
+ ret = g_list_prepend (ret, l->data);
+ }
+ }
+
+ return ret;
}
void
nautilus_module_extension_list_free (GList *extensions)
{
- GList *l, *next;
-
- for (l = extensions; l != NULL; l = next) {
- next = l->next;
- g_object_unref (l->data);
- }
- g_list_free (extensions);
+ GList *l, *next;
+
+ for (l = extensions; l != NULL; l = next)
+ {
+ next = l->next;
+ g_object_unref (l->data);
+ }
+ g_list_free (extensions);
}
-void
+void
nautilus_module_add_type (GType type)
{
- GObject *object;
-
- object = g_object_new (type, NULL);
- g_object_weak_ref (object,
- (GWeakNotify)module_object_weak_notify,
- NULL);
-
- module_objects = g_list_prepend (module_objects, object);
+ GObject *object;
+
+ object = g_object_new (type, NULL);
+ g_object_weak_ref (object,
+ (GWeakNotify) module_object_weak_notify,
+ NULL);
+
+ module_objects = g_list_prepend (module_objects, object);
}
diff --git a/src/nautilus-monitor.c b/src/nautilus-monitor.c
index 38e63d6d1..12710b83e 100644
--- a/src/nautilus-monitor.c
+++ b/src/nautilus-monitor.c
@@ -1,27 +1,27 @@
/*
- nautilus-monitor.c: file and directory change monitoring for nautilus
-
- Copyright (C) 2000, 2001 Eazel, Inc.
- Copyright (C) 2016 Red Hat
-
- 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, see <http://www.gnu.org/licenses/>.
-
- Authors: Seth Nickell <seth@eazel.com>
- Darin Adler <darin@bentspoon.com>
- Alex Graveley <alex@ximian.com>
- Carlos Soriano <csoriano@gnome.org>
-*/
+ * nautilus-monitor.c: file and directory change monitoring for nautilus
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ * Copyright (C) 2016 Red Hat
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Seth Nickell <seth@eazel.com>
+ * Darin Adler <darin@bentspoon.com>
+ * Alex Graveley <alex@ximian.com>
+ * Carlos Soriano <csoriano@gnome.org>
+ */
#include <config.h>
#include "nautilus-monitor.h"
@@ -30,10 +30,11 @@
#include <gio/gio.h>
-struct NautilusMonitor {
- GFileMonitor *monitor;
- GVolumeMonitor *volume_monitor;
- GFile *location;
+struct NautilusMonitor
+{
+ GFileMonitor *monitor;
+ GVolumeMonitor *volume_monitor;
+ GFile *location;
};
static gboolean call_consume_changes_idle_id = 0;
@@ -41,121 +42,143 @@ static gboolean call_consume_changes_idle_id = 0;
static gboolean
call_consume_changes_idle_cb (gpointer not_used)
{
- nautilus_file_changes_consume_changes (TRUE);
- call_consume_changes_idle_id = 0;
- return FALSE;
+ nautilus_file_changes_consume_changes (TRUE);
+ call_consume_changes_idle_id = 0;
+ return FALSE;
}
static void
schedule_call_consume_changes (void)
{
- if (call_consume_changes_idle_id == 0) {
- call_consume_changes_idle_id =
- g_idle_add (call_consume_changes_idle_cb, NULL);
- }
+ if (call_consume_changes_idle_id == 0)
+ {
+ call_consume_changes_idle_id =
+ g_idle_add (call_consume_changes_idle_cb, NULL);
+ }
}
static void
mount_removed (GVolumeMonitor *volume_monitor,
- GMount *mount,
- gpointer user_data)
+ GMount *mount,
+ gpointer user_data)
{
- NautilusMonitor *monitor = user_data;
- GFile *mount_location;
+ NautilusMonitor *monitor = user_data;
+ GFile *mount_location;
- mount_location = g_mount_get_root (mount);
+ mount_location = g_mount_get_root (mount);
- if (g_file_has_prefix (monitor->location, mount_location)) {
- nautilus_file_changes_queue_file_removed (monitor->location);
- schedule_call_consume_changes ();
- }
+ if (g_file_has_prefix (monitor->location, mount_location))
+ {
+ nautilus_file_changes_queue_file_removed (monitor->location);
+ schedule_call_consume_changes ();
+ }
- g_object_unref (mount_location);
+ g_object_unref (mount_location);
}
static void
-dir_changed (GFileMonitor* monitor,
- GFile *child,
- GFile *other_file,
- GFileMonitorEvent event_type,
- gpointer user_data)
+dir_changed (GFileMonitor *monitor,
+ GFile *child,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
{
- char *uri, *to_uri;
-
- uri = g_file_get_uri (child);
- to_uri = NULL;
- if (other_file) {
- to_uri = g_file_get_uri (other_file);
- }
-
- switch (event_type) {
- default:
- case G_FILE_MONITOR_EVENT_CHANGED:
- /* ignore */
- break;
- case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
- case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
- nautilus_file_changes_queue_file_changed (child);
- break;
- case G_FILE_MONITOR_EVENT_UNMOUNTED:
- case G_FILE_MONITOR_EVENT_DELETED:
- nautilus_file_changes_queue_file_removed (child);
- break;
- case G_FILE_MONITOR_EVENT_CREATED:
- nautilus_file_changes_queue_file_added (child);
- break;
- }
-
- g_free (uri);
- g_free (to_uri);
-
- schedule_call_consume_changes ();
+ char *uri, *to_uri;
+
+ uri = g_file_get_uri (child);
+ to_uri = NULL;
+ if (other_file)
+ {
+ to_uri = g_file_get_uri (other_file);
+ }
+
+ switch (event_type)
+ {
+ default:
+ case G_FILE_MONITOR_EVENT_CHANGED:
+ {
+ /* ignore */
+ }
+ break;
+
+ case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
+ case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
+ {
+ nautilus_file_changes_queue_file_changed (child);
+ }
+ break;
+
+ case G_FILE_MONITOR_EVENT_UNMOUNTED:
+ case G_FILE_MONITOR_EVENT_DELETED:
+ {
+ nautilus_file_changes_queue_file_removed (child);
+ }
+ break;
+
+ case G_FILE_MONITOR_EVENT_CREATED:
+ {
+ nautilus_file_changes_queue_file_added (child);
+ }
+ break;
+ }
+
+ g_free (uri);
+ g_free (to_uri);
+
+ schedule_call_consume_changes ();
}
-
+
NautilusMonitor *
nautilus_monitor_directory (GFile *location)
{
- GFileMonitor *dir_monitor;
- NautilusMonitor *ret;
-
- ret = g_slice_new0 (NautilusMonitor);
- dir_monitor = g_file_monitor_directory (location, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL);
-
- if (dir_monitor != NULL) {
- ret->monitor = dir_monitor;
- } else if (!g_file_is_native (location)) {
- ret->location = g_object_ref (location);
- ret->volume_monitor = g_volume_monitor_get ();
- }
-
- if (ret->monitor != NULL) {
- g_signal_connect (ret->monitor, "changed",
- G_CALLBACK (dir_changed), ret);
- }
-
- if (ret->volume_monitor != NULL) {
- g_signal_connect (ret->volume_monitor, "mount-removed",
- G_CALLBACK (mount_removed), ret);
- }
-
- /* We return a monitor even on failure, so we can avoid later trying again */
- return ret;
+ GFileMonitor *dir_monitor;
+ NautilusMonitor *ret;
+
+ ret = g_slice_new0 (NautilusMonitor);
+ dir_monitor = g_file_monitor_directory (location, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL);
+
+ if (dir_monitor != NULL)
+ {
+ ret->monitor = dir_monitor;
+ }
+ else if (!g_file_is_native (location))
+ {
+ ret->location = g_object_ref (location);
+ ret->volume_monitor = g_volume_monitor_get ();
+ }
+
+ if (ret->monitor != NULL)
+ {
+ g_signal_connect (ret->monitor, "changed",
+ G_CALLBACK (dir_changed), ret);
+ }
+
+ if (ret->volume_monitor != NULL)
+ {
+ g_signal_connect (ret->volume_monitor, "mount-removed",
+ G_CALLBACK (mount_removed), ret);
+ }
+
+ /* We return a monitor even on failure, so we can avoid later trying again */
+ return ret;
}
-void
+void
nautilus_monitor_cancel (NautilusMonitor *monitor)
{
- if (monitor->monitor != NULL) {
- g_signal_handlers_disconnect_by_func (monitor->monitor, dir_changed, monitor);
- g_file_monitor_cancel (monitor->monitor);
- g_object_unref (monitor->monitor);
- }
-
- if (monitor->volume_monitor != NULL) {
- g_signal_handlers_disconnect_by_func (monitor->volume_monitor, mount_removed, monitor);
- g_object_unref (monitor->volume_monitor);
- }
-
- g_clear_object (&monitor->location);
- g_slice_free (NautilusMonitor, monitor);
+ if (monitor->monitor != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (monitor->monitor, dir_changed, monitor);
+ g_file_monitor_cancel (monitor->monitor);
+ g_object_unref (monitor->monitor);
+ }
+
+ if (monitor->volume_monitor != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (monitor->volume_monitor, mount_removed, monitor);
+ g_object_unref (monitor->volume_monitor);
+ }
+
+ g_clear_object (&monitor->location);
+ g_slice_free (NautilusMonitor, monitor);
}
diff --git a/src/nautilus-new-folder-dialog-controller.c b/src/nautilus-new-folder-dialog-controller.c
index 667e82b58..f4c604444 100644
--- a/src/nautilus-new-folder-dialog-controller.c
+++ b/src/nautilus-new-folder-dialog-controller.c
@@ -5,14 +5,15 @@
#include "nautilus-new-folder-dialog-controller.h"
-struct _NautilusNewFolderDialogController {
- NautilusFileNameWidgetController parent_instance;
+struct _NautilusNewFolderDialogController
+{
+ NautilusFileNameWidgetController parent_instance;
- GtkWidget *new_folder_dialog;
+ GtkWidget *new_folder_dialog;
- gboolean with_selection;
+ gboolean with_selection;
- gint response_handler_id;
+ gint response_handler_id;
};
G_DEFINE_TYPE (NautilusNewFolderDialogController, nautilus_new_folder_dialog_controller, NAUTILUS_TYPE_FILE_NAME_WIDGET_CONTROLLER)
@@ -22,19 +23,25 @@ nautilus_new_folder_dialog_controller_name_is_valid (NautilusFileNameWidgetContr
gchar *name,
gchar **error_message)
{
- if (strlen (name) == 0) {
- return FALSE;
- }
-
- if (strstr (name, "/") != NULL) {
- *error_message = _("Folder names cannot contain “/”.");
- } else if (strcmp (name, ".") == 0){
- *error_message = _("A folder cannot be called “.”.");
- } else if (strcmp (name, "..") == 0){
- *error_message = _("A folder cannot be called “..”.");
- }
-
- return *error_message == NULL;
+ if (strlen (name) == 0)
+ {
+ return FALSE;
+ }
+
+ if (strstr (name, "/") != NULL)
+ {
+ *error_message = _("Folder names cannot contain “/”.");
+ }
+ else if (strcmp (name, ".") == 0)
+ {
+ *error_message = _("A folder cannot be called “.”.");
+ }
+ else if (strcmp (name, "..") == 0)
+ {
+ *error_message = _("A folder cannot be called “..”.");
+ }
+
+ return *error_message == NULL;
}
static void
@@ -42,13 +49,14 @@ new_folder_dialog_controller_on_response (GtkDialog *dialog,
gint response_id,
gpointer user_data)
{
- NautilusNewFolderDialogController *controller;
+ NautilusNewFolderDialogController *controller;
- controller = NAUTILUS_NEW_FOLDER_DIALOG_CONTROLLER (user_data);
+ controller = NAUTILUS_NEW_FOLDER_DIALOG_CONTROLLER (user_data);
- if (response_id != GTK_RESPONSE_OK) {
- g_signal_emit_by_name (controller, "cancelled");
- }
+ if (response_id != GTK_RESPONSE_OK)
+ {
+ g_signal_emit_by_name (controller, "cancelled");
+ }
}
NautilusNewFolderDialogController *
@@ -57,94 +65,96 @@ nautilus_new_folder_dialog_controller_new (GtkWindow *parent_window,
gboolean with_selection,
gchar *initial_name)
{
- NautilusNewFolderDialogController *self;
- g_autoptr (GtkBuilder) builder;
- GtkWidget *new_folder_dialog;
- GtkWidget *error_revealer;
- GtkWidget *error_label;
- GtkWidget *name_entry;
- GtkWidget *activate_button;
- GtkWidget *name_label;
-
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-create-folder-dialog.ui");
- new_folder_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "create_folder_dialog"));
- error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
- error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
- name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
- activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "ok_button"));
- name_label = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
-
- gtk_window_set_transient_for (GTK_WINDOW (new_folder_dialog),
- parent_window);
-
- self = g_object_new (NAUTILUS_TYPE_NEW_FOLDER_DIALOG_CONTROLLER,
- "error-revealer", error_revealer,
- "error-label", error_label,
- "name-entry", name_entry,
- "activate-button", activate_button,
- "containing-directory", destination_directory, NULL);
-
- self->with_selection = with_selection;
-
- self->new_folder_dialog = new_folder_dialog;
-
- self->response_handler_id = g_signal_connect (new_folder_dialog,
- "response",
- (GCallback)new_folder_dialog_controller_on_response,
- self);
-
- if (initial_name != NULL) {
- gtk_entry_set_text (GTK_ENTRY (name_entry), initial_name);
- }
-
- gtk_button_set_label (GTK_BUTTON (activate_button), _("Create"));
- gtk_label_set_text (GTK_LABEL (name_label), _("Folder name"));
- gtk_window_set_title (GTK_WINDOW (new_folder_dialog), _("New Folder"));
-
- gtk_widget_show_all (new_folder_dialog);
-
- return self;
+ NautilusNewFolderDialogController *self;
+ g_autoptr (GtkBuilder) builder;
+ GtkWidget *new_folder_dialog;
+ GtkWidget *error_revealer;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
+ GtkWidget *name_label;
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-create-folder-dialog.ui");
+ new_folder_dialog = GTK_WIDGET (gtk_builder_get_object (builder, "create_folder_dialog"));
+ error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
+ error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
+ name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "ok_button"));
+ name_label = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
+
+ gtk_window_set_transient_for (GTK_WINDOW (new_folder_dialog),
+ parent_window);
+
+ self = g_object_new (NAUTILUS_TYPE_NEW_FOLDER_DIALOG_CONTROLLER,
+ "error-revealer", error_revealer,
+ "error-label", error_label,
+ "name-entry", name_entry,
+ "activate-button", activate_button,
+ "containing-directory", destination_directory, NULL);
+
+ self->with_selection = with_selection;
+
+ self->new_folder_dialog = new_folder_dialog;
+
+ self->response_handler_id = g_signal_connect (new_folder_dialog,
+ "response",
+ (GCallback) new_folder_dialog_controller_on_response,
+ self);
+
+ if (initial_name != NULL)
+ {
+ gtk_entry_set_text (GTK_ENTRY (name_entry), initial_name);
+ }
+
+ gtk_button_set_label (GTK_BUTTON (activate_button), _("Create"));
+ gtk_label_set_text (GTK_LABEL (name_label), _("Folder name"));
+ gtk_window_set_title (GTK_WINDOW (new_folder_dialog), _("New Folder"));
+
+ gtk_widget_show_all (new_folder_dialog);
+
+ return self;
}
gboolean
nautilus_new_folder_dialog_controller_get_with_selection (NautilusNewFolderDialogController *self)
{
- return self->with_selection;
+ return self->with_selection;
}
static void
nautilus_new_folder_dialog_controller_init (NautilusNewFolderDialogController *self)
{
-
}
static void
nautilus_new_folder_dialog_controller_finalize (GObject *object)
{
- NautilusNewFolderDialogController *self;
-
- self = NAUTILUS_NEW_FOLDER_DIALOG_CONTROLLER (object);
-
- if (self->new_folder_dialog != NULL) {
- if (self->response_handler_id) {
- g_signal_handler_disconnect (self->new_folder_dialog,
- self->response_handler_id);
- self->response_handler_id = 0;
- }
- gtk_widget_destroy (self->new_folder_dialog);
- self->new_folder_dialog = NULL;
+ NautilusNewFolderDialogController *self;
+
+ self = NAUTILUS_NEW_FOLDER_DIALOG_CONTROLLER (object);
+
+ if (self->new_folder_dialog != NULL)
+ {
+ if (self->response_handler_id)
+ {
+ g_signal_handler_disconnect (self->new_folder_dialog,
+ self->response_handler_id);
+ self->response_handler_id = 0;
}
+ gtk_widget_destroy (self->new_folder_dialog);
+ self->new_folder_dialog = NULL;
+ }
- G_OBJECT_CLASS (nautilus_new_folder_dialog_controller_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_new_folder_dialog_controller_parent_class)->finalize (object);
}
static void
nautilus_new_folder_dialog_controller_class_init (NautilusNewFolderDialogControllerClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass);
- object_class->finalize = nautilus_new_folder_dialog_controller_finalize;
+ object_class->finalize = nautilus_new_folder_dialog_controller_finalize;
- parent_class->name_is_valid = nautilus_new_folder_dialog_controller_name_is_valid;
+ parent_class->name_is_valid = nautilus_new_folder_dialog_controller_name_is_valid;
}
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 31dde3173..6bf852ec8 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -37,18 +37,18 @@
#define AFTER_ALL_TABS -1
-static int nautilus_notebook_insert_page (GtkNotebook *notebook,
- GtkWidget *child,
- GtkWidget *tab_label,
- GtkWidget *menu_label,
- int position);
-static void nautilus_notebook_remove (GtkContainer *container,
- GtkWidget *tab_widget);
+static int nautilus_notebook_insert_page (GtkNotebook *notebook,
+ GtkWidget *child,
+ GtkWidget *tab_label,
+ GtkWidget *menu_label,
+ int position);
+static void nautilus_notebook_remove (GtkContainer *container,
+ GtkWidget *tab_widget);
enum
{
- TAB_CLOSE_REQUEST,
- LAST_SIGNAL
+ TAB_CLOSE_REQUEST,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -58,449 +58,476 @@ G_DEFINE_TYPE (NautilusNotebook, nautilus_notebook, GTK_TYPE_NOTEBOOK);
static void
nautilus_notebook_class_init (NautilusNotebookClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
- GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
-
- container_class->remove = nautilus_notebook_remove;
-
- notebook_class->insert_page = nautilus_notebook_insert_page;
-
- signals[TAB_CLOSE_REQUEST] =
- g_signal_new ("tab-close-request",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusNotebookClass, tab_close_request),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- NAUTILUS_TYPE_WINDOW_SLOT);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+ GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
+
+ container_class->remove = nautilus_notebook_remove;
+
+ notebook_class->insert_page = nautilus_notebook_insert_page;
+
+ signals[TAB_CLOSE_REQUEST] =
+ g_signal_new ("tab-close-request",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusNotebookClass, tab_close_request),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ NAUTILUS_TYPE_WINDOW_SLOT);
}
static gint
-find_tab_num_at_pos (NautilusNotebook *notebook, gint abs_x, gint abs_y)
+find_tab_num_at_pos (NautilusNotebook *notebook,
+ gint abs_x,
+ gint abs_y)
{
- GtkPositionType tab_pos;
- int page_num = 0;
- GtkNotebook *nb = GTK_NOTEBOOK (notebook);
- GtkWidget *page;
- GtkAllocation allocation;
-
- tab_pos = gtk_notebook_get_tab_pos (GTK_NOTEBOOK (notebook));
-
- while ((page = gtk_notebook_get_nth_page (nb, page_num)))
- {
- GtkWidget *tab;
- gint max_x, max_y;
- gint x_root, y_root;
-
- tab = gtk_notebook_get_tab_label (nb, page);
- g_return_val_if_fail (tab != NULL, -1);
-
- if (!gtk_widget_get_mapped (GTK_WIDGET (tab)))
- {
- page_num++;
- continue;
- }
-
- gdk_window_get_origin (gtk_widget_get_window (tab),
- &x_root, &y_root);
- gtk_widget_get_allocation (tab, &allocation);
-
- max_x = x_root + allocation.x + allocation.width;
- max_y = y_root + allocation.y + allocation.height;
-
- if (((tab_pos == GTK_POS_TOP)
- || (tab_pos == GTK_POS_BOTTOM))
- &&(abs_x<=max_x))
- {
- return page_num;
- }
- else if (((tab_pos == GTK_POS_LEFT)
- || (tab_pos == GTK_POS_RIGHT))
- && (abs_y<=max_y))
- {
- return page_num;
- }
-
- page_num++;
- }
- return AFTER_ALL_TABS;
+ GtkPositionType tab_pos;
+ int page_num = 0;
+ GtkNotebook *nb = GTK_NOTEBOOK (notebook);
+ GtkWidget *page;
+ GtkAllocation allocation;
+
+ tab_pos = gtk_notebook_get_tab_pos (GTK_NOTEBOOK (notebook));
+
+ while ((page = gtk_notebook_get_nth_page (nb, page_num)))
+ {
+ GtkWidget *tab;
+ gint max_x, max_y;
+ gint x_root, y_root;
+
+ tab = gtk_notebook_get_tab_label (nb, page);
+ g_return_val_if_fail (tab != NULL, -1);
+
+ if (!gtk_widget_get_mapped (GTK_WIDGET (tab)))
+ {
+ page_num++;
+ continue;
+ }
+
+ gdk_window_get_origin (gtk_widget_get_window (tab),
+ &x_root, &y_root);
+ gtk_widget_get_allocation (tab, &allocation);
+
+ max_x = x_root + allocation.x + allocation.width;
+ max_y = y_root + allocation.y + allocation.height;
+
+ if (((tab_pos == GTK_POS_TOP)
+ || (tab_pos == GTK_POS_BOTTOM))
+ && (abs_x <= max_x))
+ {
+ return page_num;
+ }
+ else if (((tab_pos == GTK_POS_LEFT)
+ || (tab_pos == GTK_POS_RIGHT))
+ && (abs_y <= max_y))
+ {
+ return page_num;
+ }
+
+ page_num++;
+ }
+ return AFTER_ALL_TABS;
}
static gboolean
button_press_cb (NautilusNotebook *notebook,
- GdkEventButton *event,
- gpointer data)
+ GdkEventButton *event,
+ gpointer data)
{
- int tab_clicked;
-
- tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root);
-
- if (event->type == GDK_BUTTON_PRESS &&
- event->button == 3 &&
- (event->state & gtk_accelerator_get_default_mod_mask ()) == 0)
- {
- if (tab_clicked == -1)
- {
- /* consume event, so that we don't pop up the context menu when
- * the mouse if not over a tab label
- */
- return TRUE;
- }
-
- /* switch to the page the mouse is over, but don't consume the event */
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked);
- }
-
- return FALSE;
+ int tab_clicked;
+
+ tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root);
+
+ if (event->type == GDK_BUTTON_PRESS &&
+ event->button == 3 &&
+ (event->state & gtk_accelerator_get_default_mod_mask ()) == 0)
+ {
+ if (tab_clicked == -1)
+ {
+ /* consume event, so that we don't pop up the context menu when
+ * the mouse if not over a tab label
+ */
+ return TRUE;
+ }
+
+ /* switch to the page the mouse is over, but don't consume the event */
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked);
+ }
+
+ return FALSE;
}
static void
nautilus_notebook_init (NautilusNotebook *notebook)
{
- gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
+ gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
+ gtk_notebook_set_show_border (GTK_NOTEBOOK (notebook), FALSE);
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
- g_signal_connect (notebook, "button-press-event",
- (GCallback)button_press_cb, NULL);
+ g_signal_connect (notebook, "button-press-event",
+ (GCallback) button_press_cb, NULL);
}
gboolean
nautilus_notebook_contains_slot (NautilusNotebook *notebook,
NautilusWindowSlot *slot)
{
- GList *children;
- GList *l;
- gboolean found = FALSE;
+ GList *children;
+ GList *l;
+ gboolean found = FALSE;
- children = gtk_container_get_children (GTK_CONTAINER (notebook));
- for (l = children; l != NULL && !found; l = l->next) {
- found = l->data == slot;
- }
+ children = gtk_container_get_children (GTK_CONTAINER (notebook));
+ for (l = children; l != NULL && !found; l = l->next)
+ {
+ found = l->data == slot;
+ }
- g_list_free (children);
+ g_list_free (children);
- return found;
+ return found;
}
void
-nautilus_notebook_sync_loading (NautilusNotebook *notebook,
- NautilusWindowSlot *slot)
+nautilus_notebook_sync_loading (NautilusNotebook *notebook,
+ NautilusWindowSlot *slot)
{
- GtkWidget *tab_label, *spinner, *icon;
- gboolean active, allow_stop;
-
- g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
- g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
-
- tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook),
- GTK_WIDGET (slot));
- g_return_if_fail (GTK_IS_WIDGET (tab_label));
-
- spinner = GTK_WIDGET (g_object_get_data (G_OBJECT (tab_label), "spinner"));
- icon = GTK_WIDGET (g_object_get_data (G_OBJECT (tab_label), "icon"));
- g_return_if_fail (spinner != NULL && icon != NULL);
-
- active = FALSE;
- g_object_get (spinner, "active", &active, NULL);
- allow_stop = nautilus_window_slot_get_allow_stop (slot);
-
- if (active == allow_stop) {
- return;
- }
-
- if (allow_stop) {
- gtk_widget_hide (icon);
- gtk_widget_show (spinner);
- gtk_spinner_start (GTK_SPINNER (spinner));
- } else {
- gtk_spinner_stop (GTK_SPINNER (spinner));
- gtk_widget_hide (spinner);
- gtk_widget_show (icon);
- }
+ GtkWidget *tab_label, *spinner, *icon;
+ gboolean active, allow_stop;
+
+ g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
+
+ tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook),
+ GTK_WIDGET (slot));
+ g_return_if_fail (GTK_IS_WIDGET (tab_label));
+
+ spinner = GTK_WIDGET (g_object_get_data (G_OBJECT (tab_label), "spinner"));
+ icon = GTK_WIDGET (g_object_get_data (G_OBJECT (tab_label), "icon"));
+ g_return_if_fail (spinner != NULL && icon != NULL);
+
+ active = FALSE;
+ g_object_get (spinner, "active", &active, NULL);
+ allow_stop = nautilus_window_slot_get_allow_stop (slot);
+
+ if (active == allow_stop)
+ {
+ return;
+ }
+
+ if (allow_stop)
+ {
+ gtk_widget_hide (icon);
+ gtk_widget_show (spinner);
+ gtk_spinner_start (GTK_SPINNER (spinner));
+ }
+ else
+ {
+ gtk_spinner_stop (GTK_SPINNER (spinner));
+ gtk_widget_hide (spinner);
+ gtk_widget_show (icon);
+ }
}
void
-nautilus_notebook_sync_tab_label (NautilusNotebook *notebook,
- NautilusWindowSlot *slot)
+nautilus_notebook_sync_tab_label (NautilusNotebook *notebook,
+ NautilusWindowSlot *slot)
{
- GtkWidget *hbox, *label;
- char *location_name;
- GFile *location;
- const gchar *title_name;
-
- g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
- g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
-
- hbox = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook), GTK_WIDGET (slot));
- g_return_if_fail (GTK_IS_WIDGET (hbox));
-
- label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label"));
- g_return_if_fail (GTK_IS_WIDGET (label));
-
- gtk_label_set_text (GTK_LABEL (label), nautilus_window_slot_get_title (slot));
- location = nautilus_window_slot_get_location (slot);
-
- if (location != NULL) {
- /* Set the tooltip on the label's parent (the tab label hbox),
- * so it covers all of the tab label.
- */
- location_name = g_file_get_parse_name (location);
- title_name = nautilus_window_slot_get_title (slot);
- if (g_str_has_prefix (location_name, EEL_SEARCH_URI)) {
- gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), title_name);
- } else {
- gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), location_name);
- }
- g_free (location_name);
- } else {
- gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), NULL);
- }
+ GtkWidget *hbox, *label;
+ char *location_name;
+ GFile *location;
+ const gchar *title_name;
+
+ g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot));
+
+ hbox = gtk_notebook_get_tab_label (GTK_NOTEBOOK (notebook), GTK_WIDGET (slot));
+ g_return_if_fail (GTK_IS_WIDGET (hbox));
+
+ label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label"));
+ g_return_if_fail (GTK_IS_WIDGET (label));
+
+ gtk_label_set_text (GTK_LABEL (label), nautilus_window_slot_get_title (slot));
+ location = nautilus_window_slot_get_location (slot);
+
+ if (location != NULL)
+ {
+ /* Set the tooltip on the label's parent (the tab label hbox),
+ * so it covers all of the tab label.
+ */
+ location_name = g_file_get_parse_name (location);
+ title_name = nautilus_window_slot_get_title (slot);
+ if (g_str_has_prefix (location_name, EEL_SEARCH_URI))
+ {
+ gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), title_name);
+ }
+ else
+ {
+ gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), location_name);
+ }
+ g_free (location_name);
+ }
+ else
+ {
+ gtk_widget_set_tooltip_text (gtk_widget_get_parent (label), NULL);
+ }
}
static void
-close_button_clicked_cb (GtkWidget *widget,
- NautilusWindowSlot *slot)
+close_button_clicked_cb (GtkWidget *widget,
+ NautilusWindowSlot *slot)
{
- GtkWidget *notebook;
+ GtkWidget *notebook;
- notebook = gtk_widget_get_ancestor (GTK_WIDGET (slot), NAUTILUS_TYPE_NOTEBOOK);
- if (notebook != NULL) {
- g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, slot);
- }
+ notebook = gtk_widget_get_ancestor (GTK_WIDGET (slot), NAUTILUS_TYPE_NOTEBOOK);
+ if (notebook != NULL)
+ {
+ g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, slot);
+ }
}
static GtkWidget *
-build_tab_label (NautilusNotebook *nb, NautilusWindowSlot *slot)
+build_tab_label (NautilusNotebook *nb,
+ NautilusWindowSlot *slot)
{
- GtkWidget *hbox, *label, *close_button, *image, *spinner, *icon;
- GtkWidget *box;
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
- gtk_widget_show (box);
-
- /* set hbox spacing and label padding (see below) so that there's an
- * equal amount of space around the label */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- gtk_widget_show (hbox);
- gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
- gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
-
- /* setup load feedback */
- spinner = gtk_spinner_new ();
- gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
-
- /* setup site icon, empty by default */
- icon = gtk_image_new ();
- gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
- /* don't show the icon */
-
- /* setup label */
- label = gtk_label_new (NULL);
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0.5);
- gtk_label_set_yalign (GTK_LABEL (label), 0.5);
- gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
- gtk_widget_show (label);
-
- /* setup close button */
- close_button = gtk_button_new ();
- gtk_button_set_relief (GTK_BUTTON (close_button),
- GTK_RELIEF_NONE);
- /* don't allow focus on the close button */
- gtk_widget_set_focus_on_click (close_button, FALSE);
-
- gtk_widget_set_name (close_button, "nautilus-tab-close-button");
-
- image = gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU);
- gtk_widget_set_tooltip_text (close_button, _("Close tab"));
- g_signal_connect_object (close_button, "clicked",
- G_CALLBACK (close_button_clicked_cb), slot, 0);
-
- gtk_container_add (GTK_CONTAINER (close_button), image);
- gtk_widget_show (image);
-
- gtk_box_pack_start (GTK_BOX (box), close_button, FALSE, FALSE, 0);
- gtk_widget_show (close_button);
-
- g_object_set_data (G_OBJECT (box), "nautilus-notebook-tab", GINT_TO_POINTER (1));
- nautilus_drag_slot_proxy_init (box, NULL, slot);
-
- g_object_set_data (G_OBJECT (box), "label", label);
- g_object_set_data (G_OBJECT (box), "spinner", spinner);
- g_object_set_data (G_OBJECT (box), "icon", icon);
- g_object_set_data (G_OBJECT (box), "close-button", close_button);
-
- return box;
+ GtkWidget *hbox, *label, *close_button, *image, *spinner, *icon;
+ GtkWidget *box;
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+ gtk_widget_show (box);
+
+ /* set hbox spacing and label padding (see below) so that there's an
+ * equal amount of space around the label */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ gtk_widget_show (hbox);
+ gtk_widget_set_halign (hbox, GTK_ALIGN_CENTER);
+ gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 0);
+
+ /* setup load feedback */
+ spinner = gtk_spinner_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
+
+ /* setup site icon, empty by default */
+ icon = gtk_image_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), icon, FALSE, FALSE, 0);
+ /* don't show the icon */
+
+ /* setup label */
+ label = gtk_label_new (NULL);
+ gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+ gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE);
+ gtk_label_set_xalign (GTK_LABEL (label), 0.5);
+ gtk_label_set_yalign (GTK_LABEL (label), 0.5);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ gtk_widget_show (label);
+
+ /* setup close button */
+ close_button = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (close_button),
+ GTK_RELIEF_NONE);
+ /* don't allow focus on the close button */
+ gtk_widget_set_focus_on_click (close_button, FALSE);
+
+ gtk_widget_set_name (close_button, "nautilus-tab-close-button");
+
+ image = gtk_image_new_from_icon_name ("window-close-symbolic", GTK_ICON_SIZE_MENU);
+ gtk_widget_set_tooltip_text (close_button, _("Close tab"));
+ g_signal_connect_object (close_button, "clicked",
+ G_CALLBACK (close_button_clicked_cb), slot, 0);
+
+ gtk_container_add (GTK_CONTAINER (close_button), image);
+ gtk_widget_show (image);
+
+ gtk_box_pack_start (GTK_BOX (box), close_button, FALSE, FALSE, 0);
+ gtk_widget_show (close_button);
+
+ g_object_set_data (G_OBJECT (box), "nautilus-notebook-tab", GINT_TO_POINTER (1));
+ nautilus_drag_slot_proxy_init (box, NULL, slot);
+
+ g_object_set_data (G_OBJECT (box), "label", label);
+ g_object_set_data (G_OBJECT (box), "spinner", spinner);
+ g_object_set_data (G_OBJECT (box), "icon", icon);
+ g_object_set_data (G_OBJECT (box), "close-button", close_button);
+
+ return box;
}
static int
nautilus_notebook_insert_page (GtkNotebook *gnotebook,
- GtkWidget *tab_widget,
- GtkWidget *tab_label,
- GtkWidget *menu_label,
- int position)
+ GtkWidget *tab_widget,
+ GtkWidget *tab_label,
+ GtkWidget *menu_label,
+ int position)
{
- g_assert (GTK_IS_WIDGET (tab_widget));
+ g_assert (GTK_IS_WIDGET (tab_widget));
- position = GTK_NOTEBOOK_CLASS (nautilus_notebook_parent_class)->insert_page (gnotebook,
- tab_widget,
- tab_label,
- menu_label,
- position);
+ position = GTK_NOTEBOOK_CLASS (nautilus_notebook_parent_class)->insert_page (gnotebook,
+ tab_widget,
+ tab_label,
+ menu_label,
+ position);
- gtk_notebook_set_show_tabs (gnotebook,
- gtk_notebook_get_n_pages (gnotebook) > 1);
- gtk_notebook_set_tab_reorderable (gnotebook, tab_widget, TRUE);
- gtk_notebook_set_tab_detachable (gnotebook, tab_widget, TRUE);
+ gtk_notebook_set_show_tabs (gnotebook,
+ gtk_notebook_get_n_pages (gnotebook) > 1);
+ gtk_notebook_set_tab_reorderable (gnotebook, tab_widget, TRUE);
+ gtk_notebook_set_tab_detachable (gnotebook, tab_widget, TRUE);
- return position;
+ return position;
}
int
-nautilus_notebook_add_tab (NautilusNotebook *notebook,
- NautilusWindowSlot *slot,
- int position,
- gboolean jump_to)
+nautilus_notebook_add_tab (NautilusNotebook *notebook,
+ NautilusWindowSlot *slot,
+ int position,
+ gboolean jump_to)
{
- GtkNotebook *gnotebook = GTK_NOTEBOOK (notebook);
- GtkWidget *tab_label;
+ GtkNotebook *gnotebook = GTK_NOTEBOOK (notebook);
+ GtkWidget *tab_label;
- g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), -1);
- g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), -1);
+ g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), -1);
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (slot), -1);
- tab_label = build_tab_label (notebook, slot);
+ tab_label = build_tab_label (notebook, slot);
- position = gtk_notebook_insert_page (GTK_NOTEBOOK (notebook),
- GTK_WIDGET (slot),
- tab_label,
- position);
+ position = gtk_notebook_insert_page (GTK_NOTEBOOK (notebook),
+ GTK_WIDGET (slot),
+ tab_label,
+ position);
- gtk_container_child_set (GTK_CONTAINER (notebook),
- GTK_WIDGET (slot),
- "tab-expand", TRUE,
- NULL);
+ gtk_container_child_set (GTK_CONTAINER (notebook),
+ GTK_WIDGET (slot),
+ "tab-expand", TRUE,
+ NULL);
- nautilus_notebook_sync_tab_label (notebook, slot);
- nautilus_notebook_sync_loading (notebook, slot);
+ nautilus_notebook_sync_tab_label (notebook, slot);
+ nautilus_notebook_sync_loading (notebook, slot);
- if (jump_to) {
- gtk_notebook_set_current_page (gnotebook, position);
- }
+ if (jump_to)
+ {
+ gtk_notebook_set_current_page (gnotebook, position);
+ }
- return position;
+ return position;
}
static void
nautilus_notebook_remove (GtkContainer *container,
- GtkWidget *tab_widget)
+ GtkWidget *tab_widget)
{
- GtkNotebook *gnotebook = GTK_NOTEBOOK (container);
- GTK_CONTAINER_CLASS (nautilus_notebook_parent_class)->remove (container, tab_widget);
-
- gtk_notebook_set_show_tabs (gnotebook,
- gtk_notebook_get_n_pages (gnotebook) > 1);
+ GtkNotebook *gnotebook = GTK_NOTEBOOK (container);
+ GTK_CONTAINER_CLASS (nautilus_notebook_parent_class)->remove (container, tab_widget);
+ gtk_notebook_set_show_tabs (gnotebook,
+ gtk_notebook_get_n_pages (gnotebook) > 1);
}
void
nautilus_notebook_reorder_current_child_relative (NautilusNotebook *notebook,
- int offset)
+ int offset)
{
- GtkNotebook *gnotebook;
- GtkWidget *child;
- int page;
+ GtkNotebook *gnotebook;
+ GtkWidget *child;
+ int page;
- g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+ g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
- if (!nautilus_notebook_can_reorder_current_child_relative (notebook, offset)) {
- return;
- }
+ if (!nautilus_notebook_can_reorder_current_child_relative (notebook, offset))
+ {
+ return;
+ }
- gnotebook = GTK_NOTEBOOK (notebook);
+ gnotebook = GTK_NOTEBOOK (notebook);
- page = gtk_notebook_get_current_page (gnotebook);
- child = gtk_notebook_get_nth_page (gnotebook, page);
- gtk_notebook_reorder_child (gnotebook, child, page + offset);
+ page = gtk_notebook_get_current_page (gnotebook);
+ child = gtk_notebook_get_nth_page (gnotebook, page);
+ gtk_notebook_reorder_child (gnotebook, child, page + offset);
}
static gboolean
nautilus_notebook_is_valid_relative_position (NautilusNotebook *notebook,
- int offset)
+ int offset)
{
- GtkNotebook *gnotebook;
- int page;
- int n_pages;
-
- gnotebook = GTK_NOTEBOOK (notebook);
-
- page = gtk_notebook_get_current_page (gnotebook);
- n_pages = gtk_notebook_get_n_pages (gnotebook) - 1;
- if (page < 0 ||
- (offset < 0 && page < -offset) ||
- (offset > 0 && page > n_pages - offset)) {
- return FALSE;
- }
-
- return TRUE;
+ GtkNotebook *gnotebook;
+ int page;
+ int n_pages;
+
+ gnotebook = GTK_NOTEBOOK (notebook);
+
+ page = gtk_notebook_get_current_page (gnotebook);
+ n_pages = gtk_notebook_get_n_pages (gnotebook) - 1;
+ if (page < 0 ||
+ (offset < 0 && page < -offset) ||
+ (offset > 0 && page > n_pages - offset))
+ {
+ return FALSE;
+ }
+
+ return TRUE;
}
gboolean
nautilus_notebook_can_reorder_current_child_relative (NautilusNotebook *notebook,
- int offset)
+ int offset)
{
- g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_NOTEBOOK (notebook), FALSE);
- return nautilus_notebook_is_valid_relative_position (notebook, offset);
+ return nautilus_notebook_is_valid_relative_position (notebook, offset);
}
void
nautilus_notebook_next_page (NautilusNotebook *notebook)
{
- gint current_page, n_pages;
+ gint current_page, n_pages;
- g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+ g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
- current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+ current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- if (current_page < n_pages - 1)
- gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
- else {
- gboolean wrap_around;
+ if (current_page < n_pages - 1)
+ {
+ gtk_notebook_next_page (GTK_NOTEBOOK (notebook));
+ }
+ else
+ {
+ gboolean wrap_around;
- g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
- "gtk-keynav-wrap-around", &wrap_around,
- NULL);
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
+ "gtk-keynav-wrap-around", &wrap_around,
+ NULL);
- if (wrap_around)
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
- }
+ if (wrap_around)
+ {
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 0);
+ }
+ }
}
void
nautilus_notebook_prev_page (NautilusNotebook *notebook)
{
- gint current_page;
+ gint current_page;
- g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
+ g_return_if_fail (NAUTILUS_IS_NOTEBOOK (notebook));
- current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
+ current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
- if (current_page > 0)
- gtk_notebook_prev_page (GTK_NOTEBOOK (notebook));
- else {
- gboolean wrap_around;
+ if (current_page > 0)
+ {
+ gtk_notebook_prev_page (GTK_NOTEBOOK (notebook));
+ }
+ else
+ {
+ gboolean wrap_around;
- g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
- "gtk-keynav-wrap-around", &wrap_around,
- NULL);
+ g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
+ "gtk-keynav-wrap-around", &wrap_around,
+ NULL);
- if (wrap_around)
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), -1);
- }
+ if (wrap_around)
+ {
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), -1);
+ }
+ }
}
diff --git a/src/nautilus-operations-ui-manager.c b/src/nautilus-operations-ui-manager.c
index 022c8ccc0..dfbb13b74 100644
--- a/src/nautilus-operations-ui-manager.c
+++ b/src/nautilus-operations-ui-manager.c
@@ -6,12 +6,13 @@
#include "nautilus-file-operations.h"
#include "nautilus-file-conflict-dialog.h"
-typedef struct {
- GSourceFunc source_func;
- gpointer user_data;
- GMutex mutex;
- GCond cond;
- gboolean completed;
+typedef struct
+{
+ GSourceFunc source_func;
+ gpointer user_data;
+ GMutex mutex;
+ GCond cond;
+ gboolean completed;
} ContextInvokeData;
G_LOCK_DEFINE_STATIC (main_context_sync);
@@ -19,18 +20,21 @@ G_LOCK_DEFINE_STATIC (main_context_sync);
static gboolean
invoke_main_context_source_func_wrapper (gpointer user_data)
{
- ContextInvokeData *data = user_data;
+ ContextInvokeData *data = user_data;
- g_mutex_lock (&data->mutex);
+ g_mutex_lock (&data->mutex);
- while (data->source_func (data->user_data));
+ while (data->source_func (data->user_data))
+ {
+ ;
+ }
- data->completed = TRUE;
+ data->completed = TRUE;
- g_cond_signal (&data->cond);
- g_mutex_unlock (&data->mutex);
+ g_cond_signal (&data->cond);
+ g_mutex_unlock (&data->mutex);
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
}
/* This function is used to run UI on the main thread in order to ask the user
@@ -44,380 +48,416 @@ invoke_main_context_sync (GMainContext *main_context,
GSourceFunc source_func,
gpointer user_data)
{
- ContextInvokeData data;
- /* Allow only one thread at a time to invoke the main context so we
- * don't get race conditions which could lead to multiple dialogs being
- * displayed at the same time
- */
- G_LOCK (main_context_sync);
+ ContextInvokeData data;
+ /* Allow only one thread at a time to invoke the main context so we
+ * don't get race conditions which could lead to multiple dialogs being
+ * displayed at the same time
+ */
+ G_LOCK (main_context_sync);
- data.source_func = source_func;
- data.user_data = user_data;
+ data.source_func = source_func;
+ data.user_data = user_data;
- g_mutex_init (&data.mutex);
- g_cond_init (&data.cond);
- data.completed = FALSE;
+ g_mutex_init (&data.mutex);
+ g_cond_init (&data.cond);
+ data.completed = FALSE;
- g_mutex_lock (&data.mutex);
+ g_mutex_lock (&data.mutex);
- g_main_context_invoke (main_context,
- invoke_main_context_source_func_wrapper,
- &data);
+ g_main_context_invoke (main_context,
+ invoke_main_context_source_func_wrapper,
+ &data);
- while (!data.completed) {
- g_cond_wait (&data.cond, &data.mutex);
- }
+ while (!data.completed)
+ {
+ g_cond_wait (&data.cond, &data.mutex);
+ }
- g_mutex_unlock (&data.mutex);
+ g_mutex_unlock (&data.mutex);
- G_UNLOCK (main_context_sync);
+ G_UNLOCK (main_context_sync);
- g_mutex_clear (&data.mutex);
- g_cond_clear (&data.cond);
+ g_mutex_clear (&data.mutex);
+ g_cond_clear (&data.cond);
}
-typedef struct {
- GFile *source_name;
- GFile *destination_name;
- GFile *destination_directory_name;
+typedef struct
+{
+ GFile *source_name;
+ GFile *destination_name;
+ GFile *destination_directory_name;
- GtkWindow *parent;
+ GtkWindow *parent;
- FileConflictResponse *response;
+ FileConflictResponse *response;
- NautilusFile *source;
- NautilusFile *destination;
- NautilusFile *destination_directory;
+ NautilusFile *source;
+ NautilusFile *destination;
+ NautilusFile *destination_directory;
- NautilusFileConflictDialog *dialog;
+ NautilusFileConflictDialog *dialog;
- NautilusFileListCallback on_file_list_ready;
- NautilusFileListHandle *handle;
- gulong source_handler_id;
- gulong destination_handler_id;
+ NautilusFileListCallback on_file_list_ready;
+ NautilusFileListHandle *handle;
+ gulong source_handler_id;
+ gulong destination_handler_id;
} FileConflictDialogData;
void
file_conflict_response_free (FileConflictResponse *response)
{
- g_free (response->new_name);
- g_slice_free (FileConflictResponse, response);
+ g_free (response->new_name);
+ g_slice_free (FileConflictResponse, response);
}
static void
set_copy_move_dialog_text (FileConflictDialogData *data)
{
- g_autofree gchar *primary_text = NULL;
- g_autofree gchar *secondary_text = NULL;
- const gchar *message_extra;
- time_t source_mtime;
- time_t destination_mtime;
- g_autofree gchar *message = NULL;
- g_autofree gchar *destination_name;
- g_autofree gchar *destination_directory_name;
- gboolean source_is_directory;
- gboolean destination_is_directory;
-
- source_mtime = nautilus_file_get_mtime (data->source);
- destination_mtime = nautilus_file_get_mtime (data->destination);
-
- destination_name = nautilus_file_get_display_name (data->destination);
- destination_directory_name = nautilus_file_get_display_name (data->destination_directory);
-
- source_is_directory = nautilus_file_is_directory (data->source);
- destination_is_directory = nautilus_file_is_directory (data->destination);
-
- if (destination_is_directory) {
- if (source_is_directory) {
- primary_text = g_strdup_printf (_("Merge folder “%s”?"),
- destination_name);
-
- message_extra = _("Merging will ask for confirmation before replacing any files in "
- "the folder that conflict with the files being copied.");
-
- if (source_mtime > destination_mtime) {
- message = g_strdup_printf (_("An older folder with the same name already exists in “%s”."),
- destination_directory_name);
- } else if (source_mtime < destination_mtime) {
- message = g_strdup_printf (_("A newer folder with the same name already exists in “%s”."),
- destination_directory_name);
- } else {
- message = g_strdup_printf (_("Another folder with the same name already exists in “%s”."),
- destination_directory_name);
- }
- } else {
- primary_text = g_strdup_printf (_("Replace folder “%s”?"),
- destination_name);
- message_extra = _("Replacing it will remove all files in the folder.");
- message = g_strdup_printf (_("A folder with the same name already exists in “%s”."),
- destination_directory_name);
- }
- } else {
- primary_text = g_strdup_printf (_("Replace file “%s”?"),
- destination_name);
-
- message_extra = _("Replacing it will overwrite its content.");
-
- if (source_mtime > destination_mtime) {
- message = g_strdup_printf (_("An older file with the same name already exists in “%s”."),
- destination_directory_name);
- } else if (source_mtime < destination_mtime) {
- message = g_strdup_printf (_("A newer file with the same name already exists in “%s”."),
- destination_directory_name);
- } else {
- message = g_strdup_printf (_("Another file with the same name already exists in “%s”."),
- destination_directory_name);
- }
+ g_autofree gchar *primary_text = NULL;
+ g_autofree gchar *secondary_text = NULL;
+ const gchar *message_extra;
+ time_t source_mtime;
+ time_t destination_mtime;
+ g_autofree gchar *message = NULL;
+ g_autofree gchar *destination_name;
+ g_autofree gchar *destination_directory_name;
+ gboolean source_is_directory;
+ gboolean destination_is_directory;
+
+ source_mtime = nautilus_file_get_mtime (data->source);
+ destination_mtime = nautilus_file_get_mtime (data->destination);
+
+ destination_name = nautilus_file_get_display_name (data->destination);
+ destination_directory_name = nautilus_file_get_display_name (data->destination_directory);
+
+ source_is_directory = nautilus_file_is_directory (data->source);
+ destination_is_directory = nautilus_file_is_directory (data->destination);
+
+ if (destination_is_directory)
+ {
+ if (source_is_directory)
+ {
+ primary_text = g_strdup_printf (_("Merge folder “%s”?"),
+ destination_name);
+
+ message_extra = _("Merging will ask for confirmation before replacing any files in "
+ "the folder that conflict with the files being copied.");
+
+ if (source_mtime > destination_mtime)
+ {
+ message = g_strdup_printf (_("An older folder with the same name already exists in “%s”."),
+ destination_directory_name);
+ }
+ else if (source_mtime < destination_mtime)
+ {
+ message = g_strdup_printf (_("A newer folder with the same name already exists in “%s”."),
+ destination_directory_name);
+ }
+ else
+ {
+ message = g_strdup_printf (_("Another folder with the same name already exists in “%s”."),
+ destination_directory_name);
+ }
+ }
+ else
+ {
+ primary_text = g_strdup_printf (_("Replace folder “%s”?"),
+ destination_name);
+ message_extra = _("Replacing it will remove all files in the folder.");
+ message = g_strdup_printf (_("A folder with the same name already exists in “%s”."),
+ destination_directory_name);
+ }
+ }
+ else
+ {
+ primary_text = g_strdup_printf (_("Replace file “%s”?"),
+ destination_name);
+
+ message_extra = _("Replacing it will overwrite its content.");
+
+ if (source_mtime > destination_mtime)
+ {
+ message = g_strdup_printf (_("An older file with the same name already exists in “%s”."),
+ destination_directory_name);
+ }
+ else if (source_mtime < destination_mtime)
+ {
+ message = g_strdup_printf (_("A newer file with the same name already exists in “%s”."),
+ destination_directory_name);
}
+ else
+ {
+ message = g_strdup_printf (_("Another file with the same name already exists in “%s”."),
+ destination_directory_name);
+ }
+ }
- secondary_text = g_strdup_printf ("%s\n%s", message, message_extra);
+ secondary_text = g_strdup_printf ("%s\n%s", message, message_extra);
- nautilus_file_conflict_dialog_set_text (data->dialog,
- primary_text,
- secondary_text);
+ nautilus_file_conflict_dialog_set_text (data->dialog,
+ primary_text,
+ secondary_text);
}
static void
set_images (FileConflictDialogData *data)
{
- GdkPixbuf *source_pixbuf;
- GdkPixbuf *destination_pixbuf;
-
- destination_pixbuf = nautilus_file_get_icon_pixbuf (data->destination,
- NAUTILUS_CANVAS_ICON_SIZE_SMALL,
- TRUE,
- 1,
- NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);
-
- source_pixbuf = nautilus_file_get_icon_pixbuf (data->source,
- NAUTILUS_CANVAS_ICON_SIZE_SMALL,
- TRUE,
- 1,
- NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);
-
- nautilus_file_conflict_dialog_set_images (data->dialog,
- destination_pixbuf,
- source_pixbuf);
-
- g_object_unref (destination_pixbuf);
- g_object_unref (source_pixbuf);
+ GdkPixbuf *source_pixbuf;
+ GdkPixbuf *destination_pixbuf;
+
+ destination_pixbuf = nautilus_file_get_icon_pixbuf (data->destination,
+ NAUTILUS_CANVAS_ICON_SIZE_SMALL,
+ TRUE,
+ 1,
+ NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);
+
+ source_pixbuf = nautilus_file_get_icon_pixbuf (data->source,
+ NAUTILUS_CANVAS_ICON_SIZE_SMALL,
+ TRUE,
+ 1,
+ NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS);
+
+ nautilus_file_conflict_dialog_set_images (data->dialog,
+ destination_pixbuf,
+ source_pixbuf);
+
+ g_object_unref (destination_pixbuf);
+ g_object_unref (source_pixbuf);
}
static void
set_file_labels (FileConflictDialogData *data)
{
- GString *destination_label;
- GString *source_label;
- gboolean source_is_directory;
- gboolean destination_is_directory;
- gboolean should_show_type;
- g_autofree char *destination_mime_type = NULL;
- g_autofree char *destination_date = NULL;
- g_autofree char *destination_size = NULL;
- g_autofree char *destination_type = NULL;
- g_autofree char *source_date = NULL;
- g_autofree char *source_size = NULL;
- g_autofree char *source_type = NULL;
-
- source_is_directory = nautilus_file_is_directory (data->source);
- destination_is_directory = nautilus_file_is_directory (data->destination);
-
- destination_mime_type = nautilus_file_get_mime_type (data->destination);
- should_show_type = !nautilus_file_is_mime_type (data->source,
- destination_mime_type);
-
- destination_date = nautilus_file_get_string_attribute (data->destination,
- "date_modified");
- destination_size = nautilus_file_get_string_attribute (data->destination,
- "size");
-
- if (should_show_type) {
- destination_type = nautilus_file_get_string_attribute (data->destination,
- "type");
- }
-
- destination_label = g_string_new (NULL);
- if (destination_is_directory) {
- g_string_append_printf (destination_label, "<b>%s</b>\n", _("Original folder"));
- g_string_append_printf (destination_label, "%s %s\n", _("Items:"), destination_size);
- }
- else {
- g_string_append_printf (destination_label, "<b>%s</b>\n", _("Original file"));
- g_string_append_printf (destination_label, "%s %s\n", _("Size:"), destination_size);
- }
-
- if (should_show_type) {
- g_string_append_printf (destination_label, "%s %s\n", _("Type:"), destination_type);
- }
-
- g_string_append_printf (destination_label, "%s %s", _("Last modified:"), destination_date);
-
- source_date = nautilus_file_get_string_attribute (data->source,
- "date_modified");
- source_size = nautilus_file_get_string_attribute (data->source,
- "size");
-
- if (should_show_type) {
- source_type = nautilus_file_get_string_attribute (data->source,
- "type");
- }
-
- source_label = g_string_new (NULL);
- if (source_is_directory) {
- g_string_append_printf (source_label, "<b>%s</b>\n",
- destination_is_directory ?
- _("Merge with") : _("Replace with"));
- g_string_append_printf (source_label, "%s %s\n", _("Items:"), source_size);
- }
- else {
- g_string_append_printf (source_label, "<b>%s</b>\n", _("Replace with"));
- g_string_append_printf (source_label, "%s %s\n", _("Size:"), source_size);
- }
-
- if (should_show_type) {
- g_string_append_printf (source_label, "%s %s\n", _("Type:"), source_type);
- }
-
- g_string_append_printf (source_label, "%s %s", _("Last modified:"), source_date);
-
- nautilus_file_conflict_dialog_set_file_labels (data->dialog,
- destination_label->str,
- source_label->str);
-
- g_string_free (destination_label, TRUE);
- g_string_free (source_label, TRUE);
+ GString *destination_label;
+ GString *source_label;
+ gboolean source_is_directory;
+ gboolean destination_is_directory;
+ gboolean should_show_type;
+ g_autofree char *destination_mime_type = NULL;
+ g_autofree char *destination_date = NULL;
+ g_autofree char *destination_size = NULL;
+ g_autofree char *destination_type = NULL;
+ g_autofree char *source_date = NULL;
+ g_autofree char *source_size = NULL;
+ g_autofree char *source_type = NULL;
+
+ source_is_directory = nautilus_file_is_directory (data->source);
+ destination_is_directory = nautilus_file_is_directory (data->destination);
+
+ destination_mime_type = nautilus_file_get_mime_type (data->destination);
+ should_show_type = !nautilus_file_is_mime_type (data->source,
+ destination_mime_type);
+
+ destination_date = nautilus_file_get_string_attribute (data->destination,
+ "date_modified");
+ destination_size = nautilus_file_get_string_attribute (data->destination,
+ "size");
+
+ if (should_show_type)
+ {
+ destination_type = nautilus_file_get_string_attribute (data->destination,
+ "type");
+ }
+
+ destination_label = g_string_new (NULL);
+ if (destination_is_directory)
+ {
+ g_string_append_printf (destination_label, "<b>%s</b>\n", _("Original folder"));
+ g_string_append_printf (destination_label, "%s %s\n", _("Items:"), destination_size);
+ }
+ else
+ {
+ g_string_append_printf (destination_label, "<b>%s</b>\n", _("Original file"));
+ g_string_append_printf (destination_label, "%s %s\n", _("Size:"), destination_size);
+ }
+
+ if (should_show_type)
+ {
+ g_string_append_printf (destination_label, "%s %s\n", _("Type:"), destination_type);
+ }
+
+ g_string_append_printf (destination_label, "%s %s", _("Last modified:"), destination_date);
+
+ source_date = nautilus_file_get_string_attribute (data->source,
+ "date_modified");
+ source_size = nautilus_file_get_string_attribute (data->source,
+ "size");
+
+ if (should_show_type)
+ {
+ source_type = nautilus_file_get_string_attribute (data->source,
+ "type");
+ }
+
+ source_label = g_string_new (NULL);
+ if (source_is_directory)
+ {
+ g_string_append_printf (source_label, "<b>%s</b>\n",
+ destination_is_directory ?
+ _("Merge with") : _("Replace with"));
+ g_string_append_printf (source_label, "%s %s\n", _("Items:"), source_size);
+ }
+ else
+ {
+ g_string_append_printf (source_label, "<b>%s</b>\n", _("Replace with"));
+ g_string_append_printf (source_label, "%s %s\n", _("Size:"), source_size);
+ }
+
+ if (should_show_type)
+ {
+ g_string_append_printf (source_label, "%s %s\n", _("Type:"), source_type);
+ }
+
+ g_string_append_printf (source_label, "%s %s", _("Last modified:"), source_date);
+
+ nautilus_file_conflict_dialog_set_file_labels (data->dialog,
+ destination_label->str,
+ source_label->str);
+
+ g_string_free (destination_label, TRUE);
+ g_string_free (source_label, TRUE);
}
static void
set_conflict_name (FileConflictDialogData *data)
{
- g_autofree gchar *edit_name;
+ g_autofree gchar *edit_name;
- edit_name = nautilus_file_get_edit_name (data->destination);
+ edit_name = nautilus_file_get_edit_name (data->destination);
- nautilus_file_conflict_dialog_set_conflict_name (data->dialog,
- edit_name);
+ nautilus_file_conflict_dialog_set_conflict_name (data->dialog,
+ edit_name);
}
static void
set_replace_button_label (FileConflictDialogData *data)
{
- gboolean source_is_directory, destination_is_directory;
+ gboolean source_is_directory, destination_is_directory;
- source_is_directory = nautilus_file_is_directory (data->source);
- destination_is_directory = nautilus_file_is_directory (data->destination);
+ source_is_directory = nautilus_file_is_directory (data->source);
+ destination_is_directory = nautilus_file_is_directory (data->destination);
- if (source_is_directory && destination_is_directory) {
- nautilus_file_conflict_dialog_set_replace_button_label (data->dialog,
- _("Merge"));
- }
+ if (source_is_directory && destination_is_directory)
+ {
+ nautilus_file_conflict_dialog_set_replace_button_label (data->dialog,
+ _("Merge"));
+ }
}
static void
file_icons_changed (NautilusFile *file,
FileConflictDialogData *data)
{
- set_images (data);
+ set_images (data);
}
static void
copy_move_conflict_on_file_list_ready (GList *files,
gpointer user_data)
{
- FileConflictDialogData *data = user_data;
- g_autofree gchar *title;
-
- data->handle = NULL;
-
- if (nautilus_file_is_directory (data->source)) {
- title = g_strdup (nautilus_file_is_directory (data->destination) ?
- _("Merge Folder") :
- _("File and Folder conflict"));
- } else {
- title = g_strdup (nautilus_file_is_directory (data->destination) ?
- _("File and Folder conflict") :
- _("File conflict"));
- }
+ FileConflictDialogData *data = user_data;
+ g_autofree gchar *title;
+
+ data->handle = NULL;
+
+ if (nautilus_file_is_directory (data->source))
+ {
+ title = g_strdup (nautilus_file_is_directory (data->destination) ?
+ _("Merge Folder") :
+ _("File and Folder conflict"));
+ }
+ else
+ {
+ title = g_strdup (nautilus_file_is_directory (data->destination) ?
+ _("File and Folder conflict") :
+ _("File conflict"));
+ }
- gtk_window_set_title (GTK_WINDOW (data->dialog), title);
+ gtk_window_set_title (GTK_WINDOW (data->dialog), title);
- set_copy_move_dialog_text (data);
+ set_copy_move_dialog_text (data);
- set_images (data);
+ set_images (data);
- set_file_labels (data);
+ set_file_labels (data);
- set_conflict_name (data);
+ set_conflict_name (data);
- set_replace_button_label (data);
+ set_replace_button_label (data);
- nautilus_file_monitor_add (data->source, data, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
- nautilus_file_monitor_add (data->destination, data, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
+ nautilus_file_monitor_add (data->source, data, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
+ nautilus_file_monitor_add (data->destination, data, NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
- data->source_handler_id = g_signal_connect (data->source, "changed",
- G_CALLBACK (file_icons_changed), data);
- data->destination_handler_id = g_signal_connect (data->destination, "changed",
- G_CALLBACK (file_icons_changed), data);
+ data->source_handler_id = g_signal_connect (data->source, "changed",
+ G_CALLBACK (file_icons_changed), data);
+ data->destination_handler_id = g_signal_connect (data->destination, "changed",
+ G_CALLBACK (file_icons_changed), data);
}
static gboolean
run_file_conflict_dialog (gpointer user_data)
{
- FileConflictDialogData *data = user_data;
- int response_id;
- GList *files = NULL;
-
- data->source = nautilus_file_get (data->source_name);
- data->destination = nautilus_file_get (data->destination_name);
- data->destination_directory = nautilus_file_get (data->destination_directory_name);
-
- data->dialog = nautilus_file_conflict_dialog_new (data->parent);
-
- files = g_list_prepend (files, data->source);
- files = g_list_prepend (files, data->destination);
- files = g_list_prepend (files, data->destination_directory);
-
- nautilus_file_list_call_when_ready (files,
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON,
- &data->handle,
- data->on_file_list_ready,
- data);
-
- response_id = gtk_dialog_run (GTK_DIALOG (data->dialog));
-
- if (data->handle != NULL) {
- nautilus_file_list_cancel_call_when_ready (data->handle);
- }
-
- if (data->source_handler_id) {
- g_signal_handler_disconnect (data->source, data->source_handler_id);
- nautilus_file_monitor_remove (data->source, data);
- }
-
- if (data->destination_handler_id) {
- g_signal_handler_disconnect (data->destination, data->destination_handler_id);
- nautilus_file_monitor_remove (data->destination, data);
- }
-
- if (response_id == CONFLICT_RESPONSE_RENAME) {
- data->response->new_name =
- nautilus_file_conflict_dialog_get_new_name (data->dialog);
- } else if (response_id != GTK_RESPONSE_CANCEL ||
- response_id != GTK_RESPONSE_NONE) {
- data->response->apply_to_all =
- nautilus_file_conflict_dialog_get_apply_to_all (data->dialog);
- }
-
- data->response->id = response_id;
-
- gtk_widget_destroy (GTK_WIDGET (data->dialog));
-
- nautilus_file_unref (data->source);
- nautilus_file_unref (data->destination);
- nautilus_file_unref (data->destination_directory);
- g_list_free (files);
-
- return G_SOURCE_REMOVE;
+ FileConflictDialogData *data = user_data;
+ int response_id;
+ GList *files = NULL;
+
+ data->source = nautilus_file_get (data->source_name);
+ data->destination = nautilus_file_get (data->destination_name);
+ data->destination_directory = nautilus_file_get (data->destination_directory_name);
+
+ data->dialog = nautilus_file_conflict_dialog_new (data->parent);
+
+ files = g_list_prepend (files, data->source);
+ files = g_list_prepend (files, data->destination);
+ files = g_list_prepend (files, data->destination_directory);
+
+ nautilus_file_list_call_when_ready (files,
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON,
+ &data->handle,
+ data->on_file_list_ready,
+ data);
+
+ response_id = gtk_dialog_run (GTK_DIALOG (data->dialog));
+
+ if (data->handle != NULL)
+ {
+ nautilus_file_list_cancel_call_when_ready (data->handle);
+ }
+
+ if (data->source_handler_id)
+ {
+ g_signal_handler_disconnect (data->source, data->source_handler_id);
+ nautilus_file_monitor_remove (data->source, data);
+ }
+
+ if (data->destination_handler_id)
+ {
+ g_signal_handler_disconnect (data->destination, data->destination_handler_id);
+ nautilus_file_monitor_remove (data->destination, data);
+ }
+
+ if (response_id == CONFLICT_RESPONSE_RENAME)
+ {
+ data->response->new_name =
+ nautilus_file_conflict_dialog_get_new_name (data->dialog);
+ }
+ else if (response_id != GTK_RESPONSE_CANCEL ||
+ response_id != GTK_RESPONSE_NONE)
+ {
+ data->response->apply_to_all =
+ nautilus_file_conflict_dialog_get_apply_to_all (data->dialog);
+ }
+
+ data->response->id = response_id;
+
+ gtk_widget_destroy (GTK_WIDGET (data->dialog));
+
+ nautilus_file_unref (data->source);
+ nautilus_file_unref (data->destination);
+ nautilus_file_unref (data->destination_directory);
+ g_list_free (files);
+
+ return G_SOURCE_REMOVE;
}
FileConflictResponse *
@@ -426,24 +466,24 @@ copy_move_conflict_ask_user_action (GtkWindow *parent_window,
GFile *destination_name,
GFile *destination_directory_name)
{
- FileConflictDialogData *data;
+ FileConflictDialogData *data;
- data = g_slice_new0 (FileConflictDialogData);
- data->parent = parent_window;
- data->source_name = source_name;
- data->destination_name = destination_name;
- data->destination_directory_name = destination_directory_name;
+ data = g_slice_new0 (FileConflictDialogData);
+ data->parent = parent_window;
+ data->source_name = source_name;
+ data->destination_name = destination_name;
+ data->destination_directory_name = destination_directory_name;
- data->response = g_slice_new0 (FileConflictResponse);
- data->response->new_name = NULL;
+ data->response = g_slice_new0 (FileConflictResponse);
+ data->response->new_name = NULL;
- data->on_file_list_ready = copy_move_conflict_on_file_list_ready;
+ data->on_file_list_ready = copy_move_conflict_on_file_list_ready;
- invoke_main_context_sync (NULL,
- run_file_conflict_dialog,
- data);
+ invoke_main_context_sync (NULL,
+ run_file_conflict_dialog,
+ data);
- g_slice_free (FileConflictDialogData, data);
+ g_slice_free (FileConflictDialogData, data);
- return data->response;
+ return data->response;
}
diff --git a/src/nautilus-other-locations-window-slot.c b/src/nautilus-other-locations-window-slot.c
index 27d16ec14..f08e12a77 100644
--- a/src/nautilus-other-locations-window-slot.c
+++ b/src/nautilus-other-locations-window-slot.c
@@ -21,7 +21,7 @@
struct _NautilusOtherLocationsWindowSlot
{
- NautilusWindowSlot parent_instance;
+ NautilusWindowSlot parent_instance;
};
G_DEFINE_TYPE (NautilusOtherLocationsWindowSlot, nautilus_other_locations_window_slot, NAUTILUS_TYPE_WINDOW_SLOT)
@@ -30,51 +30,51 @@ static gboolean
real_handles_location (NautilusWindowSlot *self,
GFile *location)
{
- NautilusFile *file;
- gboolean handles_location;
+ NautilusFile *file;
+ gboolean handles_location;
- file = nautilus_file_get (location);
- handles_location = nautilus_file_is_other_locations (file);
- nautilus_file_unref (file);
+ file = nautilus_file_get (location);
+ handles_location = nautilus_file_is_other_locations (file);
+ nautilus_file_unref (file);
- return handles_location;
+ return handles_location;
}
static NautilusView *
real_get_view_for_location (NautilusWindowSlot *self,
GFile *location)
{
- return NAUTILUS_VIEW (nautilus_places_view_new ());
+ return NAUTILUS_VIEW (nautilus_places_view_new ());
}
NautilusOtherLocationsWindowSlot *
nautilus_other_locations_window_slot_new (NautilusWindow *window)
{
- return g_object_new (NAUTILUS_TYPE_OTHER_LOCATIONS_WINDOW_SLOT,
- "window", window,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_OTHER_LOCATIONS_WINDOW_SLOT,
+ "window", window,
+ NULL);
}
static void
nautilus_other_locations_window_slot_class_init (NautilusOtherLocationsWindowSlotClass *klass)
{
- NautilusWindowSlotClass *parent_class = NAUTILUS_WINDOW_SLOT_CLASS (klass);
+ NautilusWindowSlotClass *parent_class = NAUTILUS_WINDOW_SLOT_CLASS (klass);
- parent_class->get_view_for_location = real_get_view_for_location;
- parent_class->handles_location = real_handles_location;
+ parent_class->get_view_for_location = real_get_view_for_location;
+ parent_class->handles_location = real_handles_location;
}
static void
nautilus_other_locations_window_slot_init (NautilusOtherLocationsWindowSlot *self)
{
- GAction *action;
- GActionGroup *action_group;
+ GAction *action;
+ GActionGroup *action_group;
- /* Disable the ability to change between types of views */
- action_group = gtk_widget_get_action_group (GTK_WIDGET (self), "slot");
+ /* Disable the ability to change between types of views */
+ action_group = gtk_widget_get_action_group (GTK_WIDGET (self), "slot");
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
- action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode-toggle");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "files-view-mode-toggle");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
}
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index efd228ee9..54b344f22 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -34,21 +34,23 @@
#include "nautilus-window-slot-dnd.h"
-enum {
- OPEN_LOCATION,
- PATH_CLICKED,
- LAST_SIGNAL
+enum
+{
+ OPEN_LOCATION,
+ PATH_CLICKED,
+ LAST_SIGNAL
};
-typedef enum {
- NORMAL_BUTTON,
- OTHER_LOCATIONS_BUTTON,
- ROOT_BUTTON,
- HOME_BUTTON,
- MOUNT_BUTTON
+typedef enum
+{
+ NORMAL_BUTTON,
+ OTHER_LOCATIONS_BUTTON,
+ ROOT_BUTTON,
+ HOME_BUTTON,
+ MOUNT_BUTTON
} ButtonType;
-#define BUTTON_DATA(x) ((ButtonData *)(x))
+#define BUTTON_DATA(x) ((ButtonData *) (x))
#define SCROLL_TIMEOUT 150
#define INITIAL_SCROLL_TIMEOUT 300
@@ -58,360 +60,383 @@ static guint path_bar_signals [LAST_SIGNAL] = { 0 };
#define NAUTILUS_PATH_BAR_ICON_SIZE 16
#define NAUTILUS_PATH_BAR_BUTTON_MAX_WIDTH 250
-typedef struct {
- GtkWidget *button;
- ButtonType type;
- char *dir_name;
- GFile *path;
- NautilusFile *file;
- unsigned int file_changed_signal_id;
-
- GtkWidget *image;
- GtkWidget *label;
- GtkWidget *bold_label;
-
- guint ignore_changes : 1;
- guint is_root : 1;
+typedef struct
+{
+ GtkWidget *button;
+ ButtonType type;
+ char *dir_name;
+ GFile *path;
+ NautilusFile *file;
+ unsigned int file_changed_signal_id;
+
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *bold_label;
+
+ guint ignore_changes : 1;
+ guint is_root : 1;
} ButtonData;
-struct _NautilusPathBarDetails {
- GdkWindow *event_window;
+struct _NautilusPathBarDetails
+{
+ GdkWindow *event_window;
- GFile *current_path;
- gpointer current_button_data;
+ GFile *current_path;
+ gpointer current_button_data;
- GList *button_list;
- GList *first_scrolled_button;
- GtkWidget *up_slider_button;
- GtkWidget *down_slider_button;
- guint settings_signal_id;
- guint timer;
- guint slider_visible : 1;
- guint need_timer : 1;
- guint ignore_click : 1;
+ GList *button_list;
+ GList *first_scrolled_button;
+ GtkWidget *up_slider_button;
+ GtkWidget *down_slider_button;
+ guint settings_signal_id;
+ guint timer;
+ guint slider_visible : 1;
+ guint need_timer : 1;
+ guint ignore_click : 1;
- unsigned int drag_slider_timeout;
- gboolean drag_slider_timeout_for_up_button;
+ unsigned int drag_slider_timeout;
+ gboolean drag_slider_timeout_for_up_button;
- GActionGroup *action_group;
+ GActionGroup *action_group;
- GMenu *context_menu;
- NautilusFile *context_menu_file;
- GdkEventButton *context_menu_event;
+ GMenu *context_menu;
+ NautilusFile *context_menu_file;
+ GdkEventButton *context_menu_event;
};
G_DEFINE_TYPE (NautilusPathBar, nautilus_path_bar,
- GTK_TYPE_CONTAINER);
-
-static void nautilus_path_bar_scroll_up (NautilusPathBar *path_bar);
-static void nautilus_path_bar_scroll_down (NautilusPathBar *path_bar);
-static void nautilus_path_bar_stop_scrolling (NautilusPathBar *path_bar);
-static gboolean nautilus_path_bar_slider_button_press (GtkWidget *widget,
- GdkEventButton *event,
- NautilusPathBar *path_bar);
-static gboolean nautilus_path_bar_slider_button_release (GtkWidget *widget,
- GdkEventButton *event,
- NautilusPathBar *path_bar);
-static void nautilus_path_bar_check_icon_theme (NautilusPathBar *path_bar);
-static void nautilus_path_bar_update_button_appearance (ButtonData *button_data);
-static void nautilus_path_bar_update_button_state (ButtonData *button_data,
- gboolean current_dir);
-static void nautilus_path_bar_update_path (NautilusPathBar *path_bar,
- GFile *file_path);
-static void unschedule_pop_up_context_menu (NautilusPathBar *path_bar);
-static void action_pathbar_open_item_new_window (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
-static void action_pathbar_open_item_new_tab (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
-static void action_pathbar_properties (GSimpleAction *action,
- GVariant *state,
- gpointer user_data);
-
-const GActionEntry path_bar_actions[] = {
- { "open-item-new-tab", action_pathbar_open_item_new_tab },
- { "open-item-new-window", action_pathbar_open_item_new_window },
- { "properties", action_pathbar_properties}
+ GTK_TYPE_CONTAINER);
+
+static void nautilus_path_bar_scroll_up (NautilusPathBar *path_bar);
+static void nautilus_path_bar_scroll_down (NautilusPathBar *path_bar);
+static void nautilus_path_bar_stop_scrolling (NautilusPathBar *path_bar);
+static gboolean nautilus_path_bar_slider_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ NautilusPathBar *path_bar);
+static gboolean nautilus_path_bar_slider_button_release (GtkWidget *widget,
+ GdkEventButton *event,
+ NautilusPathBar *path_bar);
+static void nautilus_path_bar_check_icon_theme (NautilusPathBar *path_bar);
+static void nautilus_path_bar_update_button_appearance (ButtonData *button_data);
+static void nautilus_path_bar_update_button_state (ButtonData *button_data,
+ gboolean current_dir);
+static void nautilus_path_bar_update_path (NautilusPathBar *path_bar,
+ GFile *file_path);
+static void unschedule_pop_up_context_menu (NautilusPathBar *path_bar);
+static void action_pathbar_open_item_new_window (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+static void action_pathbar_open_item_new_tab (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+static void action_pathbar_properties (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data);
+
+const GActionEntry path_bar_actions[] =
+{
+ { "open-item-new-tab", action_pathbar_open_item_new_tab },
+ { "open-item-new-window", action_pathbar_open_item_new_window },
+ { "properties", action_pathbar_properties}
};
static void
action_pathbar_open_item_new_tab (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusPathBar *path_bar;
- GFile *location;
+ NautilusPathBar *path_bar;
+ GFile *location;
- path_bar = NAUTILUS_PATH_BAR (user_data);
+ path_bar = NAUTILUS_PATH_BAR (user_data);
- if (!path_bar->priv->context_menu_file) {
- return;
- }
+ if (!path_bar->priv->context_menu_file)
+ {
+ return;
+ }
- location = nautilus_file_get_location (path_bar->priv->context_menu_file);
+ location = nautilus_file_get_location (path_bar->priv->context_menu_file);
- if (location) {
- g_signal_emit (user_data, path_bar_signals[OPEN_LOCATION], 0, location, GTK_PLACES_OPEN_NEW_TAB);
- g_object_unref (location);
- }
+ if (location)
+ {
+ g_signal_emit (user_data, path_bar_signals[OPEN_LOCATION], 0, location, GTK_PLACES_OPEN_NEW_TAB);
+ g_object_unref (location);
+ }
}
static void
action_pathbar_open_item_new_window (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusPathBar *path_bar;
- GFile *location;
+ NautilusPathBar *path_bar;
+ GFile *location;
- path_bar = NAUTILUS_PATH_BAR (user_data);
+ path_bar = NAUTILUS_PATH_BAR (user_data);
- if (!path_bar->priv->context_menu_file) {
- return;
- }
+ if (!path_bar->priv->context_menu_file)
+ {
+ return;
+ }
- location = nautilus_file_get_location (path_bar->priv->context_menu_file);
+ location = nautilus_file_get_location (path_bar->priv->context_menu_file);
- if (location) {
- g_signal_emit (user_data, path_bar_signals[OPEN_LOCATION], 0, location, GTK_PLACES_OPEN_NEW_WINDOW);
- g_object_unref (location);
- }
+ if (location)
+ {
+ g_signal_emit (user_data, path_bar_signals[OPEN_LOCATION], 0, location, GTK_PLACES_OPEN_NEW_WINDOW);
+ g_object_unref (location);
+ }
}
static void
action_pathbar_properties (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusPathBar *path_bar;
- GList *files;
+ NautilusPathBar *path_bar;
+ GList *files;
- path_bar = NAUTILUS_PATH_BAR (user_data);
- g_assert (NAUTILUS_IS_FILE (path_bar->priv->context_menu_file));
+ path_bar = NAUTILUS_PATH_BAR (user_data);
+ g_assert (NAUTILUS_IS_FILE (path_bar->priv->context_menu_file));
- files = g_list_append (NULL, nautilus_file_ref (path_bar->priv->context_menu_file));
+ files = g_list_append (NULL, nautilus_file_ref (path_bar->priv->context_menu_file));
- nautilus_properties_window_present (files, GTK_WIDGET (path_bar), NULL);
+ nautilus_properties_window_present (files, GTK_WIDGET (path_bar), NULL);
- nautilus_file_list_free (files);
+ nautilus_file_list_free (files);
}
static GtkWidget *
get_slider_button (NautilusPathBar *path_bar,
const gchar *arrow_type)
{
- GtkWidget *button;
+ GtkWidget *button;
- gtk_widget_push_composite_child ();
+ gtk_widget_push_composite_child ();
- button = gtk_button_new ();
- gtk_widget_set_focus_on_click (button, FALSE);
- gtk_widget_add_events (button, GDK_SCROLL_MASK);
- gtk_container_add (GTK_CONTAINER (button),
- gtk_image_new_from_icon_name (arrow_type, GTK_ICON_SIZE_MENU));
- gtk_container_add (GTK_CONTAINER (path_bar), button);
- gtk_widget_show_all (button);
+ button = gtk_button_new ();
+ gtk_widget_set_focus_on_click (button, FALSE);
+ gtk_widget_add_events (button, GDK_SCROLL_MASK);
+ gtk_container_add (GTK_CONTAINER (button),
+ gtk_image_new_from_icon_name (arrow_type, GTK_ICON_SIZE_MENU));
+ gtk_container_add (GTK_CONTAINER (path_bar), button);
+ gtk_widget_show_all (button);
- gtk_widget_pop_composite_child ();
+ gtk_widget_pop_composite_child ();
- return button;
+ return button;
}
static gboolean
slider_timeout (gpointer user_data)
{
- NautilusPathBar *path_bar;
+ NautilusPathBar *path_bar;
- path_bar = NAUTILUS_PATH_BAR (user_data);
+ path_bar = NAUTILUS_PATH_BAR (user_data);
- path_bar->priv->drag_slider_timeout = 0;
+ path_bar->priv->drag_slider_timeout = 0;
- if (gtk_widget_get_visible (GTK_WIDGET (path_bar))) {
- if (path_bar->priv->drag_slider_timeout_for_up_button) {
- nautilus_path_bar_scroll_up (path_bar);
- } else {
- nautilus_path_bar_scroll_down (path_bar);
- }
- }
+ if (gtk_widget_get_visible (GTK_WIDGET (path_bar)))
+ {
+ if (path_bar->priv->drag_slider_timeout_for_up_button)
+ {
+ nautilus_path_bar_scroll_up (path_bar);
+ }
+ else
+ {
+ nautilus_path_bar_scroll_down (path_bar);
+ }
+ }
- return FALSE;
+ return FALSE;
}
static void
nautilus_path_bar_slider_drag_motion (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- unsigned int time,
- gpointer user_data)
+ GdkDragContext *context,
+ int x,
+ int y,
+ unsigned int time,
+ gpointer user_data)
{
- NautilusPathBar *path_bar;
- GtkSettings *settings;
- unsigned int timeout;
+ NautilusPathBar *path_bar;
+ GtkSettings *settings;
+ unsigned int timeout;
- path_bar = NAUTILUS_PATH_BAR (user_data);
+ path_bar = NAUTILUS_PATH_BAR (user_data);
- if (path_bar->priv->drag_slider_timeout == 0) {
- settings = gtk_widget_get_settings (widget);
+ if (path_bar->priv->drag_slider_timeout == 0)
+ {
+ settings = gtk_widget_get_settings (widget);
- g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
- path_bar->priv->drag_slider_timeout =
- g_timeout_add (timeout,
- slider_timeout,
- path_bar);
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+ path_bar->priv->drag_slider_timeout =
+ g_timeout_add (timeout,
+ slider_timeout,
+ path_bar);
- path_bar->priv->drag_slider_timeout_for_up_button =
- widget == path_bar->priv->up_slider_button;
- }
+ path_bar->priv->drag_slider_timeout_for_up_button =
+ widget == path_bar->priv->up_slider_button;
+ }
}
static void
nautilus_path_bar_slider_drag_leave (GtkWidget *widget,
- GdkDragContext *context,
- unsigned int time,
- gpointer user_data)
+ GdkDragContext *context,
+ unsigned int time,
+ gpointer user_data)
{
- NautilusPathBar *path_bar;
+ NautilusPathBar *path_bar;
- path_bar = NAUTILUS_PATH_BAR (user_data);
+ path_bar = NAUTILUS_PATH_BAR (user_data);
- if (path_bar->priv->drag_slider_timeout != 0) {
- g_source_remove (path_bar->priv->drag_slider_timeout);
- path_bar->priv->drag_slider_timeout = 0;
- }
+ if (path_bar->priv->drag_slider_timeout != 0)
+ {
+ g_source_remove (path_bar->priv->drag_slider_timeout);
+ path_bar->priv->drag_slider_timeout = 0;
+ }
}
static void
nautilus_path_bar_init (NautilusPathBar *path_bar)
{
- GtkBuilder *builder;
-
- path_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (path_bar, NAUTILUS_TYPE_PATH_BAR, NautilusPathBarDetails);
-
- /* Action group */
- path_bar->priv->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
- g_action_map_add_action_entries (G_ACTION_MAP (path_bar->priv->action_group),
- path_bar_actions,
- G_N_ELEMENTS (path_bar_actions),
- path_bar);
- gtk_widget_insert_action_group (GTK_WIDGET (path_bar),
- "pathbar",
- G_ACTION_GROUP (path_bar->priv->action_group));
-
- /* Context menu */
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-pathbar-context-menu.ui");
- path_bar->priv->context_menu = g_object_ref (G_MENU (gtk_builder_get_object (builder, "pathbar-menu")));
- g_object_unref (builder);
-
- gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
- gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
-
- path_bar->priv->up_slider_button = get_slider_button (path_bar, "pan-start-symbolic");
- path_bar->priv->down_slider_button = get_slider_button (path_bar, "pan-end-symbolic");
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar->priv->up_slider_button)),
- "slider-button");
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar->priv->down_slider_button)),
- "slider-button");
-
- g_signal_connect_swapped (path_bar->priv->up_slider_button, "clicked", G_CALLBACK (nautilus_path_bar_scroll_up), path_bar);
- g_signal_connect_swapped (path_bar->priv->down_slider_button, "clicked", G_CALLBACK (nautilus_path_bar_scroll_down), path_bar);
-
- g_signal_connect (path_bar->priv->up_slider_button, "button-press-event", G_CALLBACK (nautilus_path_bar_slider_button_press), path_bar);
- g_signal_connect (path_bar->priv->up_slider_button, "button-release-event", G_CALLBACK (nautilus_path_bar_slider_button_release), path_bar);
- g_signal_connect (path_bar->priv->down_slider_button, "button-press-event", G_CALLBACK (nautilus_path_bar_slider_button_press), path_bar);
- g_signal_connect (path_bar->priv->down_slider_button, "button-release-event", G_CALLBACK (nautilus_path_bar_slider_button_release), path_bar);
-
- gtk_drag_dest_set (GTK_WIDGET (path_bar->priv->up_slider_button),
- 0, NULL, 0, 0);
- gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->priv->up_slider_button), TRUE);
- g_signal_connect (path_bar->priv->up_slider_button,
- "drag-motion",
- G_CALLBACK (nautilus_path_bar_slider_drag_motion),
- path_bar);
- g_signal_connect (path_bar->priv->up_slider_button,
- "drag-leave",
- G_CALLBACK (nautilus_path_bar_slider_drag_leave),
- path_bar);
-
- gtk_drag_dest_set (GTK_WIDGET (path_bar->priv->down_slider_button),
- 0, NULL, 0, 0);
- gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->priv->down_slider_button), TRUE);
- g_signal_connect (path_bar->priv->down_slider_button,
- "drag-motion",
- G_CALLBACK (nautilus_path_bar_slider_drag_motion),
- path_bar);
- g_signal_connect (path_bar->priv->down_slider_button,
- "drag-leave",
- G_CALLBACK (nautilus_path_bar_slider_drag_leave),
- path_bar);
-
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar)),
- GTK_STYLE_CLASS_LINKED);
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar)),
- "path-bar");
+ GtkBuilder *builder;
+
+ path_bar->priv = G_TYPE_INSTANCE_GET_PRIVATE (path_bar, NAUTILUS_TYPE_PATH_BAR, NautilusPathBarDetails);
+
+ /* Action group */
+ path_bar->priv->action_group = G_ACTION_GROUP (g_simple_action_group_new ());
+ g_action_map_add_action_entries (G_ACTION_MAP (path_bar->priv->action_group),
+ path_bar_actions,
+ G_N_ELEMENTS (path_bar_actions),
+ path_bar);
+ gtk_widget_insert_action_group (GTK_WIDGET (path_bar),
+ "pathbar",
+ G_ACTION_GROUP (path_bar->priv->action_group));
+
+ /* Context menu */
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-pathbar-context-menu.ui");
+ path_bar->priv->context_menu = g_object_ref (G_MENU (gtk_builder_get_object (builder, "pathbar-menu")));
+ g_object_unref (builder);
+
+ gtk_widget_set_has_window (GTK_WIDGET (path_bar), FALSE);
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (path_bar), FALSE);
+
+ path_bar->priv->up_slider_button = get_slider_button (path_bar, "pan-start-symbolic");
+ path_bar->priv->down_slider_button = get_slider_button (path_bar, "pan-end-symbolic");
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar->priv->up_slider_button)),
+ "slider-button");
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar->priv->down_slider_button)),
+ "slider-button");
+
+ g_signal_connect_swapped (path_bar->priv->up_slider_button, "clicked", G_CALLBACK (nautilus_path_bar_scroll_up), path_bar);
+ g_signal_connect_swapped (path_bar->priv->down_slider_button, "clicked", G_CALLBACK (nautilus_path_bar_scroll_down), path_bar);
+
+ g_signal_connect (path_bar->priv->up_slider_button, "button-press-event", G_CALLBACK (nautilus_path_bar_slider_button_press), path_bar);
+ g_signal_connect (path_bar->priv->up_slider_button, "button-release-event", G_CALLBACK (nautilus_path_bar_slider_button_release), path_bar);
+ g_signal_connect (path_bar->priv->down_slider_button, "button-press-event", G_CALLBACK (nautilus_path_bar_slider_button_press), path_bar);
+ g_signal_connect (path_bar->priv->down_slider_button, "button-release-event", G_CALLBACK (nautilus_path_bar_slider_button_release), path_bar);
+
+ gtk_drag_dest_set (GTK_WIDGET (path_bar->priv->up_slider_button),
+ 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->priv->up_slider_button), TRUE);
+ g_signal_connect (path_bar->priv->up_slider_button,
+ "drag-motion",
+ G_CALLBACK (nautilus_path_bar_slider_drag_motion),
+ path_bar);
+ g_signal_connect (path_bar->priv->up_slider_button,
+ "drag-leave",
+ G_CALLBACK (nautilus_path_bar_slider_drag_leave),
+ path_bar);
+
+ gtk_drag_dest_set (GTK_WIDGET (path_bar->priv->down_slider_button),
+ 0, NULL, 0, 0);
+ gtk_drag_dest_set_track_motion (GTK_WIDGET (path_bar->priv->down_slider_button), TRUE);
+ g_signal_connect (path_bar->priv->down_slider_button,
+ "drag-motion",
+ G_CALLBACK (nautilus_path_bar_slider_drag_motion),
+ path_bar);
+ g_signal_connect (path_bar->priv->down_slider_button,
+ "drag-leave",
+ G_CALLBACK (nautilus_path_bar_slider_drag_leave),
+ path_bar);
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar)),
+ GTK_STYLE_CLASS_LINKED);
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (path_bar)),
+ "path-bar");
}
static void
nautilus_path_bar_finalize (GObject *object)
{
- NautilusPathBar *path_bar;
+ NautilusPathBar *path_bar;
- path_bar = NAUTILUS_PATH_BAR (object);
+ path_bar = NAUTILUS_PATH_BAR (object);
- nautilus_path_bar_stop_scrolling (path_bar);
+ nautilus_path_bar_stop_scrolling (path_bar);
- if (path_bar->priv->drag_slider_timeout != 0) {
- g_source_remove (path_bar->priv->drag_slider_timeout);
- path_bar->priv->drag_slider_timeout = 0;
- }
+ if (path_bar->priv->drag_slider_timeout != 0)
+ {
+ g_source_remove (path_bar->priv->drag_slider_timeout);
+ path_bar->priv->drag_slider_timeout = 0;
+ }
- g_list_free (path_bar->priv->button_list);
+ g_list_free (path_bar->priv->button_list);
- unschedule_pop_up_context_menu (NAUTILUS_PATH_BAR (object));
- if (path_bar->priv->context_menu_event) {
- gdk_event_free ((GdkEvent *) path_bar->priv->context_menu_event);
- }
+ unschedule_pop_up_context_menu (NAUTILUS_PATH_BAR (object));
+ if (path_bar->priv->context_menu_event)
+ {
+ gdk_event_free ((GdkEvent *) path_bar->priv->context_menu_event);
+ }
- G_OBJECT_CLASS (nautilus_path_bar_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_path_bar_parent_class)->finalize (object);
}
/* Removes the settings signal handler. It's safe to call multiple times */
static void
remove_settings_signal (NautilusPathBar *path_bar,
- GdkScreen *screen)
-{
- if (path_bar->priv->settings_signal_id) {
- GtkSettings *settings;
-
- settings = gtk_settings_get_for_screen (screen);
- g_signal_handler_disconnect (settings,
- path_bar->priv->settings_signal_id);
- path_bar->priv->settings_signal_id = 0;
- }
+ GdkScreen *screen)
+{
+ if (path_bar->priv->settings_signal_id)
+ {
+ GtkSettings *settings;
+
+ settings = gtk_settings_get_for_screen (screen);
+ g_signal_handler_disconnect (settings,
+ path_bar->priv->settings_signal_id);
+ path_bar->priv->settings_signal_id = 0;
+ }
}
static void
nautilus_path_bar_dispose (GObject *object)
{
- remove_settings_signal (NAUTILUS_PATH_BAR (object), gtk_widget_get_screen (GTK_WIDGET (object)));
+ remove_settings_signal (NAUTILUS_PATH_BAR (object), gtk_widget_get_screen (GTK_WIDGET (object)));
- G_OBJECT_CLASS (nautilus_path_bar_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_path_bar_parent_class)->dispose (object);
}
static const char *
get_dir_name (ButtonData *button_data)
{
- switch (button_data->type) {
+ switch (button_data->type)
+ {
case HOME_BUTTON:
+ {
return _("Home");
+ }
+
case OTHER_LOCATIONS_BUTTON:
+ {
return _("Other Locations");
+ }
+
default:
- return button_data->dir_name;
- }
+ return button_data->dir_name;
+ }
}
/* We always want to request the same size for the label, whether
@@ -420,144 +445,155 @@ get_dir_name (ButtonData *button_data)
static void
set_label_size_request (ButtonData *button_data)
{
- gint width, height;
- GtkRequisition nat_req, bold_req;
+ gint width, height;
+ GtkRequisition nat_req, bold_req;
- if (button_data->label == NULL) {
- return;
- }
+ if (button_data->label == NULL)
+ {
+ return;
+ }
- gtk_widget_get_preferred_size (button_data->label, NULL, &nat_req);
- gtk_widget_get_preferred_size (button_data->bold_label, &bold_req, NULL);
+ gtk_widget_get_preferred_size (button_data->label, NULL, &nat_req);
+ gtk_widget_get_preferred_size (button_data->bold_label, &bold_req, NULL);
- width = MAX (nat_req.width, bold_req.width);
- width = MIN (width, NAUTILUS_PATH_BAR_BUTTON_MAX_WIDTH);
- height = MAX (nat_req.height, bold_req.height);
+ width = MAX (nat_req.width, bold_req.width);
+ width = MIN (width, NAUTILUS_PATH_BAR_BUTTON_MAX_WIDTH);
+ height = MAX (nat_req.height, bold_req.height);
- gtk_widget_set_size_request (button_data->label, width, height);
+ gtk_widget_set_size_request (button_data->label, width, height);
}
/* Size requisition:
- *
+ *
* Ideally, our size is determined by another widget, and we are just filling
* available space.
*/
static void
nautilus_path_bar_get_preferred_width (GtkWidget *widget,
- gint *minimum,
- gint *natural)
-{
- ButtonData *button_data;
- NautilusPathBar *path_bar;
- GList *list;
- gint child_height;
- gint height;
- gint child_min, child_nat;
- gint up_slider_width;
- gint down_slider_width;
-
- path_bar = NAUTILUS_PATH_BAR (widget);
-
- *minimum = *natural = 0;
- height = 0;
-
- for (list = path_bar->priv->button_list; list; list = list->next) {
- button_data = BUTTON_DATA (list->data);
- set_label_size_request (button_data);
-
- gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
- gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
- height = MAX (height, child_height);
-
- if (button_data->type == NORMAL_BUTTON) {
- /* Use 2*Height as button width because of ellipsized label. */
- child_min = MAX (child_min, child_height * 2);
- child_nat = MAX (child_min, child_height * 2);
- }
-
- *minimum = MAX (*minimum, child_min);
- *natural = *natural + child_nat;
- }
-
- /* Add space for slider, if we have more than one path */
- /* Theoretically, the slider could be bigger than the other button. But we're
- * not going to worry about that now.
- */
- gtk_widget_get_preferred_width (path_bar->priv->down_slider_button,
- &down_slider_width,
- NULL);
- gtk_widget_get_preferred_width (path_bar->priv->up_slider_button,
- &up_slider_width,
- NULL);
-
- if (path_bar->priv->button_list) {
- *minimum += (down_slider_width + up_slider_width);
- *natural += (down_slider_width + up_slider_width);
- }
+ gint *minimum,
+ gint *natural)
+{
+ ButtonData *button_data;
+ NautilusPathBar *path_bar;
+ GList *list;
+ gint child_height;
+ gint height;
+ gint child_min, child_nat;
+ gint up_slider_width;
+ gint down_slider_width;
+
+ path_bar = NAUTILUS_PATH_BAR (widget);
+
+ *minimum = *natural = 0;
+ height = 0;
+
+ for (list = path_bar->priv->button_list; list; list = list->next)
+ {
+ button_data = BUTTON_DATA (list->data);
+ set_label_size_request (button_data);
+
+ gtk_widget_get_preferred_width (button_data->button, &child_min, &child_nat);
+ gtk_widget_get_preferred_height (button_data->button, &child_height, NULL);
+ height = MAX (height, child_height);
+
+ if (button_data->type == NORMAL_BUTTON)
+ {
+ /* Use 2*Height as button width because of ellipsized label. */
+ child_min = MAX (child_min, child_height * 2);
+ child_nat = MAX (child_min, child_height * 2);
+ }
+
+ *minimum = MAX (*minimum, child_min);
+ *natural = *natural + child_nat;
+ }
+
+ /* Add space for slider, if we have more than one path */
+ /* Theoretically, the slider could be bigger than the other button. But we're
+ * not going to worry about that now.
+ */
+ gtk_widget_get_preferred_width (path_bar->priv->down_slider_button,
+ &down_slider_width,
+ NULL);
+ gtk_widget_get_preferred_width (path_bar->priv->up_slider_button,
+ &up_slider_width,
+ NULL);
+
+ if (path_bar->priv->button_list)
+ {
+ *minimum += (down_slider_width + up_slider_width);
+ *natural += (down_slider_width + up_slider_width);
+ }
}
static void
nautilus_path_bar_get_preferred_height (GtkWidget *widget,
- gint *minimum,
- gint *natural)
+ gint *minimum,
+ gint *natural)
{
- ButtonData *button_data;
- NautilusPathBar *path_bar;
- GList *list;
- gint child_min, child_nat;
+ ButtonData *button_data;
+ NautilusPathBar *path_bar;
+ GList *list;
+ gint child_min, child_nat;
- path_bar = NAUTILUS_PATH_BAR (widget);
+ path_bar = NAUTILUS_PATH_BAR (widget);
- *minimum = *natural = 0;
+ *minimum = *natural = 0;
- for (list = path_bar->priv->button_list; list; list = list->next) {
- button_data = BUTTON_DATA (list->data);
- set_label_size_request (button_data);
+ for (list = path_bar->priv->button_list; list; list = list->next)
+ {
+ button_data = BUTTON_DATA (list->data);
+ set_label_size_request (button_data);
- gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
+ gtk_widget_get_preferred_height (button_data->button, &child_min, &child_nat);
- *minimum = MAX (*minimum, child_min);
- *natural = MAX (*natural, child_nat);
- }
+ *minimum = MAX (*minimum, child_min);
+ *natural = MAX (*natural, child_nat);
+ }
}
static void
nautilus_path_bar_update_slider_buttons (NautilusPathBar *path_bar)
{
- if (path_bar->priv->button_list) {
-
- GtkWidget *button;
-
- button = BUTTON_DATA (path_bar->priv->button_list->data)->button;
- if (gtk_widget_get_child_visible (button)) {
- gtk_widget_set_sensitive (path_bar->priv->down_slider_button, FALSE);
- } else {
- gtk_widget_set_sensitive (path_bar->priv->down_slider_button, TRUE);
- }
- button = BUTTON_DATA (g_list_last (path_bar->priv->button_list)->data)->button;
- if (gtk_widget_get_child_visible (button)) {
- gtk_widget_set_sensitive (path_bar->priv->up_slider_button, FALSE);
- } else {
- gtk_widget_set_sensitive (path_bar->priv->up_slider_button, TRUE);
- }
- }
+ if (path_bar->priv->button_list)
+ {
+ GtkWidget *button;
+
+ button = BUTTON_DATA (path_bar->priv->button_list->data)->button;
+ if (gtk_widget_get_child_visible (button))
+ {
+ gtk_widget_set_sensitive (path_bar->priv->down_slider_button, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (path_bar->priv->down_slider_button, TRUE);
+ }
+ button = BUTTON_DATA (g_list_last (path_bar->priv->button_list)->data)->button;
+ if (gtk_widget_get_child_visible (button))
+ {
+ gtk_widget_set_sensitive (path_bar->priv->up_slider_button, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (path_bar->priv->up_slider_button, TRUE);
+ }
+ }
}
static void
nautilus_path_bar_unmap (GtkWidget *widget)
{
- nautilus_path_bar_stop_scrolling (NAUTILUS_PATH_BAR (widget));
- gdk_window_hide (NAUTILUS_PATH_BAR (widget)->priv->event_window);
+ nautilus_path_bar_stop_scrolling (NAUTILUS_PATH_BAR (widget));
+ gdk_window_hide (NAUTILUS_PATH_BAR (widget)->priv->event_window);
- GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->unmap (widget);
+ GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->unmap (widget);
}
static void
nautilus_path_bar_map (GtkWidget *widget)
{
- gdk_window_show (NAUTILUS_PATH_BAR (widget)->priv->event_window);
+ gdk_window_show (NAUTILUS_PATH_BAR (widget)->priv->event_window);
- GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->map (widget);
+ GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->map (widget);
}
#define BUTTON_BOTTOM_SHADOW 1
@@ -566,740 +602,845 @@ static void
union_with_clip (GtkWidget *widget,
gpointer clip)
{
- GtkAllocation widget_clip;
+ GtkAllocation widget_clip;
- if (!gtk_widget_is_drawable (widget)) {
- return;
- }
+ if (!gtk_widget_is_drawable (widget))
+ {
+ return;
+ }
- gtk_widget_get_clip (widget, &widget_clip);
+ gtk_widget_get_clip (widget, &widget_clip);
- gdk_rectangle_union (&widget_clip, clip, clip);
+ gdk_rectangle_union (&widget_clip, clip, clip);
}
static void
_set_simple_bottom_clip (GtkWidget *widget,
- gint pixels)
+ gint pixels)
{
- GtkAllocation clip;
+ GtkAllocation clip;
- gtk_widget_get_allocation (widget, &clip);
- clip.height += pixels;
+ gtk_widget_get_allocation (widget, &clip);
+ clip.height += pixels;
- gtk_container_forall (GTK_CONTAINER (widget), union_with_clip, &clip);
- gtk_widget_set_clip (widget, &clip);
+ gtk_container_forall (GTK_CONTAINER (widget), union_with_clip, &clip);
+ gtk_widget_set_clip (widget, &clip);
}
/* This is a tad complicated */
static void
nautilus_path_bar_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkWidget *child;
- NautilusPathBar *path_bar;
- GtkTextDirection direction;
- gint up_slider_width;
- gint down_slider_width;
- GtkAllocation child_allocation;
- GList *list, *first_button;
- gint width;
- gint largest_width;
- gboolean need_sliders;
- gint up_slider_offset;
- gint down_slider_offset;
- GtkRequisition child_requisition;
-
- need_sliders = TRUE;
- up_slider_offset = 0;
- down_slider_offset = 0;
- path_bar = NAUTILUS_PATH_BAR (widget);
-
- gtk_widget_set_allocation (widget, allocation);
-
- if (gtk_widget_get_realized (widget)) {
- gdk_window_move_resize (path_bar->priv->event_window,
- allocation->x, allocation->y,
- allocation->width, allocation->height);
- }
-
- /* No path is set so we don't have to allocate anything. */
- if (path_bar->priv->button_list == NULL) {
- _set_simple_bottom_clip (widget, BUTTON_BOTTOM_SHADOW);
- return;
- }
- direction = gtk_widget_get_direction (widget);
- gtk_widget_get_preferred_width (path_bar->priv->up_slider_button,
- &up_slider_width,
- NULL);
- gtk_widget_get_preferred_width (path_bar->priv->down_slider_button,
- &down_slider_width,
- NULL);
-
- /* First, we check to see if we need the scrollbars. */
- width = 0;
-
- gtk_widget_get_preferred_size (BUTTON_DATA (path_bar->priv->button_list->data)->button,
- &child_requisition, NULL);
- width += child_requisition.width;
-
- for (list = path_bar->priv->button_list->next; list; list = list->next) {
- child = BUTTON_DATA (list->data)->button;
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
- width += child_requisition.width;
+ GtkAllocation *allocation)
+{
+ GtkWidget *child;
+ NautilusPathBar *path_bar;
+ GtkTextDirection direction;
+ gint up_slider_width;
+ gint down_slider_width;
+ GtkAllocation child_allocation;
+ GList *list, *first_button;
+ gint width;
+ gint largest_width;
+ gboolean need_sliders;
+ gint up_slider_offset;
+ gint down_slider_offset;
+ GtkRequisition child_requisition;
+
+ need_sliders = TRUE;
+ up_slider_offset = 0;
+ down_slider_offset = 0;
+ path_bar = NAUTILUS_PATH_BAR (widget);
+
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (gtk_widget_get_realized (widget))
+ {
+ gdk_window_move_resize (path_bar->priv->event_window,
+ allocation->x, allocation->y,
+ allocation->width, allocation->height);
+ }
+
+ /* No path is set so we don't have to allocate anything. */
+ if (path_bar->priv->button_list == NULL)
+ {
+ _set_simple_bottom_clip (widget, BUTTON_BOTTOM_SHADOW);
+ return;
+ }
+ direction = gtk_widget_get_direction (widget);
+ gtk_widget_get_preferred_width (path_bar->priv->up_slider_button,
+ &up_slider_width,
+ NULL);
+ gtk_widget_get_preferred_width (path_bar->priv->down_slider_button,
+ &down_slider_width,
+ NULL);
+
+ /* First, we check to see if we need the scrollbars. */
+ width = 0;
+
+ gtk_widget_get_preferred_size (BUTTON_DATA (path_bar->priv->button_list->data)->button,
+ &child_requisition, NULL);
+ width += child_requisition.width;
+
+ for (list = path_bar->priv->button_list->next; list; list = list->next)
+ {
+ child = BUTTON_DATA (list->data)->button;
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+ width += child_requisition.width;
+ }
+
+ if (width <= allocation->width && !need_sliders)
+ {
+ first_button = g_list_last (path_bar->priv->button_list);
+ }
+ else
+ {
+ gboolean reached_end;
+ gint slider_space;
+ reached_end = FALSE;
+ slider_space = down_slider_width + up_slider_width;
+
+ if (path_bar->priv->first_scrolled_button)
+ {
+ first_button = path_bar->priv->first_scrolled_button;
}
-
- if (width <= allocation->width && !need_sliders) {
- first_button = g_list_last (path_bar->priv->button_list);
- } else {
- gboolean reached_end;
- gint slider_space;
- reached_end = FALSE;
- slider_space = down_slider_width + up_slider_width;
-
- if (path_bar->priv->first_scrolled_button) {
- first_button = path_bar->priv->first_scrolled_button;
- } else {
- first_button = path_bar->priv->button_list;
- }
-
- need_sliders = TRUE;
- /* To see how much space we have, and how many buttons we can display.
- * We start at the first button, count forward until hit the new
- * button, then count backwards.
- */
- /* Count down the path chain towards the end. */
- gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
- &child_requisition, NULL);
- width = child_requisition.width;
- list = first_button->prev;
- while (list && !reached_end) {
- child = BUTTON_DATA (list->data)->button;
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- if (width + child_requisition.width + slider_space > allocation->width) {
- reached_end = TRUE;
- } else {
- width += child_requisition.width;
- }
-
- list = list->prev;
- }
-
- /* Finally, we walk up, seeing how many of the previous buttons we can add*/
-
- while (first_button->next && ! reached_end) {
- child = BUTTON_DATA (first_button->next->data)->button;
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- if (width + child_requisition.width + slider_space > allocation->width) {
- reached_end = TRUE;
- } else {
- width += child_requisition.width;
- first_button = first_button->next;
- }
- }
+ else
+ {
+ first_button = path_bar->priv->button_list;
}
- /* Now, we allocate space to the buttons */
- child_allocation.y = allocation->y;
- child_allocation.height = allocation->height;
-
- if (direction == GTK_TEXT_DIR_RTL) {
- child_allocation.x = allocation->x + allocation->width;
- if (need_sliders) {
- child_allocation.x -= up_slider_width;
- up_slider_offset = allocation->width - up_slider_width;
- }
- } else {
- child_allocation.x = allocation->x;
- if (need_sliders) {
- up_slider_offset = 0;
- child_allocation.x += up_slider_width;
- }
+ need_sliders = TRUE;
+ /* To see how much space we have, and how many buttons we can display.
+ * We start at the first button, count forward until hit the new
+ * button, then count backwards.
+ */
+ /* Count down the path chain towards the end. */
+ gtk_widget_get_preferred_size (BUTTON_DATA (first_button->data)->button,
+ &child_requisition, NULL);
+ width = child_requisition.width;
+ list = first_button->prev;
+ while (list && !reached_end)
+ {
+ child = BUTTON_DATA (list->data)->button;
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+
+ if (width + child_requisition.width + slider_space > allocation->width)
+ {
+ reached_end = TRUE;
+ }
+ else
+ {
+ width += child_requisition.width;
+ }
+
+ list = list->prev;
}
- /* Determine the largest possible allocation size */
- largest_width = allocation->width;
- if (need_sliders) {
- largest_width -= (down_slider_width + up_slider_width);
+ /* Finally, we walk up, seeing how many of the previous buttons we can add*/
+
+ while (first_button->next && !reached_end)
+ {
+ child = BUTTON_DATA (first_button->next->data)->button;
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+
+ if (width + child_requisition.width + slider_space > allocation->width)
+ {
+ reached_end = TRUE;
+ }
+ else
+ {
+ width += child_requisition.width;
+ first_button = first_button->next;
+ }
}
+ }
- for (list = first_button; list; list = list->prev) {
- child = BUTTON_DATA (list->data)->button;
- gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-
- child_allocation.width = MIN (child_requisition.width, largest_width);
- if (direction == GTK_TEXT_DIR_RTL) {
- child_allocation.x -= child_allocation.width;
- }
- /* Check to see if we've don't have any more space to allocate buttons */
- if (need_sliders && direction == GTK_TEXT_DIR_RTL) {
- if (child_allocation.x - down_slider_width < allocation->x) {
- break;
- }
- } else {
- if (need_sliders && direction == GTK_TEXT_DIR_LTR) {
- if (child_allocation.x + child_allocation.width + down_slider_width > allocation->x + allocation->width) {
- break;
- }
- }
- }
-
- gtk_widget_set_child_visible (child, TRUE);
- gtk_widget_size_allocate (child, &child_allocation);
-
- if (direction == GTK_TEXT_DIR_RTL) {
- down_slider_offset = child_allocation.x - allocation->x - down_slider_width;
- } else {
- down_slider_offset += child_allocation.width;
- child_allocation.x += child_allocation.width;
- }
+ /* Now, we allocate space to the buttons */
+ child_allocation.y = allocation->y;
+ child_allocation.height = allocation->height;
+
+ if (direction == GTK_TEXT_DIR_RTL)
+ {
+ child_allocation.x = allocation->x + allocation->width;
+ if (need_sliders)
+ {
+ child_allocation.x -= up_slider_width;
+ up_slider_offset = allocation->width - up_slider_width;
}
- /* Now we go hide all the widgets that don't fit */
- while (list) {
- child = BUTTON_DATA (list->data)->button;
- gtk_widget_set_child_visible (child, FALSE);
- list = list->prev;
+ }
+ else
+ {
+ child_allocation.x = allocation->x;
+ if (need_sliders)
+ {
+ up_slider_offset = 0;
+ child_allocation.x += up_slider_width;
}
- for (list = first_button->next; list; list = list->next) {
- child = BUTTON_DATA (list->data)->button;
- gtk_widget_set_child_visible (child, FALSE);
+ }
+
+ /* Determine the largest possible allocation size */
+ largest_width = allocation->width;
+ if (need_sliders)
+ {
+ largest_width -= (down_slider_width + up_slider_width);
+ }
+
+ for (list = first_button; list; list = list->prev)
+ {
+ child = BUTTON_DATA (list->data)->button;
+ gtk_widget_get_preferred_size (child, &child_requisition, NULL);
+
+ child_allocation.width = MIN (child_requisition.width, largest_width);
+ if (direction == GTK_TEXT_DIR_RTL)
+ {
+ child_allocation.x -= child_allocation.width;
}
-
- if (need_sliders) {
- child_allocation.width = up_slider_width;
- child_allocation.x = up_slider_offset + allocation->x;
- gtk_widget_size_allocate (path_bar->priv->up_slider_button, &child_allocation);
-
- gtk_widget_set_child_visible (path_bar->priv->up_slider_button, TRUE);
- gtk_widget_show_all (path_bar->priv->up_slider_button);
-
- if (direction == GTK_TEXT_DIR_LTR) {
- down_slider_offset += up_slider_width;
- }
- } else {
- gtk_widget_set_child_visible (path_bar->priv->up_slider_button, FALSE);
+ /* Check to see if we've don't have any more space to allocate buttons */
+ if (need_sliders && direction == GTK_TEXT_DIR_RTL)
+ {
+ if (child_allocation.x - down_slider_width < allocation->x)
+ {
+ break;
+ }
+ }
+ else
+ {
+ if (need_sliders && direction == GTK_TEXT_DIR_LTR)
+ {
+ if (child_allocation.x + child_allocation.width + down_slider_width > allocation->x + allocation->width)
+ {
+ break;
+ }
+ }
}
-
- if (need_sliders) {
- child_allocation.width = down_slider_width;
- child_allocation.x = down_slider_offset + allocation->x;
- gtk_widget_size_allocate (path_bar->priv->down_slider_button, &child_allocation);
- gtk_widget_set_child_visible (path_bar->priv->down_slider_button, TRUE);
- gtk_widget_show_all (path_bar->priv->down_slider_button);
- nautilus_path_bar_update_slider_buttons (path_bar);
- } else {
- gtk_widget_set_child_visible (path_bar->priv->down_slider_button, FALSE);
- }
+ gtk_widget_set_child_visible (child, TRUE);
+ gtk_widget_size_allocate (child, &child_allocation);
- _set_simple_bottom_clip (widget, BUTTON_BOTTOM_SHADOW);
+ if (direction == GTK_TEXT_DIR_RTL)
+ {
+ down_slider_offset = child_allocation.x - allocation->x - down_slider_width;
+ }
+ else
+ {
+ down_slider_offset += child_allocation.width;
+ child_allocation.x += child_allocation.width;
+ }
+ }
+ /* Now we go hide all the widgets that don't fit */
+ while (list)
+ {
+ child = BUTTON_DATA (list->data)->button;
+ gtk_widget_set_child_visible (child, FALSE);
+ list = list->prev;
+ }
+ for (list = first_button->next; list; list = list->next)
+ {
+ child = BUTTON_DATA (list->data)->button;
+ gtk_widget_set_child_visible (child, FALSE);
+ }
+
+ if (need_sliders)
+ {
+ child_allocation.width = up_slider_width;
+ child_allocation.x = up_slider_offset + allocation->x;
+ gtk_widget_size_allocate (path_bar->priv->up_slider_button, &child_allocation);
+
+ gtk_widget_set_child_visible (path_bar->priv->up_slider_button, TRUE);
+ gtk_widget_show_all (path_bar->priv->up_slider_button);
+
+ if (direction == GTK_TEXT_DIR_LTR)
+ {
+ down_slider_offset += up_slider_width;
+ }
+ }
+ else
+ {
+ gtk_widget_set_child_visible (path_bar->priv->up_slider_button, FALSE);
+ }
+
+ if (need_sliders)
+ {
+ child_allocation.width = down_slider_width;
+ child_allocation.x = down_slider_offset + allocation->x;
+ gtk_widget_size_allocate (path_bar->priv->down_slider_button, &child_allocation);
+
+ gtk_widget_set_child_visible (path_bar->priv->down_slider_button, TRUE);
+ gtk_widget_show_all (path_bar->priv->down_slider_button);
+ nautilus_path_bar_update_slider_buttons (path_bar);
+ }
+ else
+ {
+ gtk_widget_set_child_visible (path_bar->priv->down_slider_button, FALSE);
+ }
+
+ _set_simple_bottom_clip (widget, BUTTON_BOTTOM_SHADOW);
}
static void
nautilus_path_bar_style_updated (GtkWidget *widget)
{
- GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->style_updated (widget);
+ GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->style_updated (widget);
- nautilus_path_bar_check_icon_theme (NAUTILUS_PATH_BAR (widget));
+ nautilus_path_bar_check_icon_theme (NAUTILUS_PATH_BAR (widget));
}
static void
nautilus_path_bar_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen)
+ GdkScreen *previous_screen)
{
- if (GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->screen_changed) {
- GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->screen_changed (widget, previous_screen);
- }
- /* We might nave a new settings, so we remove the old one */
- if (previous_screen) {
- remove_settings_signal (NAUTILUS_PATH_BAR (widget), previous_screen);
- }
- nautilus_path_bar_check_icon_theme (NAUTILUS_PATH_BAR (widget));
+ if (GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->screen_changed)
+ {
+ GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->screen_changed (widget, previous_screen);
+ }
+ /* We might nave a new settings, so we remove the old one */
+ if (previous_screen)
+ {
+ remove_settings_signal (NAUTILUS_PATH_BAR (widget), previous_screen);
+ }
+ nautilus_path_bar_check_icon_theme (NAUTILUS_PATH_BAR (widget));
}
static gboolean
nautilus_path_bar_scroll (GtkWidget *widget,
- GdkEventScroll *event)
+ GdkEventScroll *event)
{
- NautilusPathBar *path_bar;
+ NautilusPathBar *path_bar;
+
+ path_bar = NAUTILUS_PATH_BAR (widget);
- path_bar = NAUTILUS_PATH_BAR (widget);
+ switch (event->direction)
+ {
+ case GDK_SCROLL_RIGHT:
+ case GDK_SCROLL_DOWN:
+ {
+ nautilus_path_bar_scroll_down (path_bar);
+ return TRUE;
+ }
- switch (event->direction) {
- case GDK_SCROLL_RIGHT:
- case GDK_SCROLL_DOWN:
- nautilus_path_bar_scroll_down (path_bar);
- return TRUE;
+ case GDK_SCROLL_LEFT:
+ case GDK_SCROLL_UP:
+ {
+ nautilus_path_bar_scroll_up (path_bar);
+ return TRUE;
+ }
- case GDK_SCROLL_LEFT:
- case GDK_SCROLL_UP:
- nautilus_path_bar_scroll_up (path_bar);
- return TRUE;
- case GDK_SCROLL_SMOOTH:
- break;
- }
+ case GDK_SCROLL_SMOOTH:
+ {
+ }
+ break;
+ }
- return FALSE;
+ return FALSE;
}
static void
nautilus_path_bar_realize (GtkWidget *widget)
{
- NautilusPathBar *path_bar;
- GtkAllocation allocation;
- GdkWindow *window;
- GdkWindowAttr attributes;
- gint attributes_mask;
+ NautilusPathBar *path_bar;
+ GtkAllocation allocation;
+ GdkWindow *window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
- gtk_widget_set_realized (widget, TRUE);
+ gtk_widget_set_realized (widget, TRUE);
- path_bar = NAUTILUS_PATH_BAR (widget);
- window = gtk_widget_get_parent_window (widget);
- gtk_widget_set_window (widget, window);
- g_object_ref (window);
+ path_bar = NAUTILUS_PATH_BAR (widget);
+ window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_window (widget, window);
+ g_object_ref (window);
- gtk_widget_get_allocation (widget, &allocation);
+ gtk_widget_get_allocation (widget, &allocation);
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = allocation.x;
- attributes.y = allocation.y;
- attributes.width = allocation.width;
- attributes.height = allocation.height;
- attributes.wclass = GDK_INPUT_ONLY;
- attributes.event_mask = gtk_widget_get_events (widget);
- attributes.event_mask |=
- GDK_SCROLL_MASK |
- GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK |
- GDK_POINTER_MOTION_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.wclass = GDK_INPUT_ONLY;
+ attributes.event_mask = gtk_widget_get_events (widget);
+ attributes.event_mask |=
+ GDK_SCROLL_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_MASK;
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
- path_bar->priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
- gdk_window_set_user_data (path_bar->priv->event_window, widget);
+ path_bar->priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gdk_window_set_user_data (path_bar->priv->event_window, widget);
}
static void
nautilus_path_bar_unrealize (GtkWidget *widget)
{
- NautilusPathBar *path_bar;
+ NautilusPathBar *path_bar;
- path_bar = NAUTILUS_PATH_BAR (widget);
+ path_bar = NAUTILUS_PATH_BAR (widget);
- gdk_window_set_user_data (path_bar->priv->event_window, NULL);
- gdk_window_destroy (path_bar->priv->event_window);
- path_bar->priv->event_window = NULL;
+ gdk_window_set_user_data (path_bar->priv->event_window, NULL);
+ gdk_window_destroy (path_bar->priv->event_window);
+ path_bar->priv->event_window = NULL;
- GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->unrealize (widget);
+ GTK_WIDGET_CLASS (nautilus_path_bar_parent_class)->unrealize (widget);
}
static void
nautilus_path_bar_add (GtkContainer *container,
- GtkWidget *widget)
+ GtkWidget *widget)
{
- gtk_widget_set_parent (widget, GTK_WIDGET (container));
+ gtk_widget_set_parent (widget, GTK_WIDGET (container));
}
static void
nautilus_path_bar_remove_1 (GtkContainer *container,
- GtkWidget *widget)
+ GtkWidget *widget)
{
- gboolean was_visible = gtk_widget_get_visible (widget);
- gtk_widget_unparent (widget);
- if (was_visible) {
- gtk_widget_queue_resize (GTK_WIDGET (container));
- }
+ gboolean was_visible = gtk_widget_get_visible (widget);
+ gtk_widget_unparent (widget);
+ if (was_visible)
+ {
+ gtk_widget_queue_resize (GTK_WIDGET (container));
+ }
}
static void
nautilus_path_bar_remove (GtkContainer *container,
- GtkWidget *widget)
-{
- NautilusPathBar *path_bar;
- GList *children;
-
- path_bar = NAUTILUS_PATH_BAR (container);
-
- if (widget == path_bar->priv->up_slider_button) {
- nautilus_path_bar_remove_1 (container, widget);
- path_bar->priv->up_slider_button = NULL;
- return;
- }
-
- if (widget == path_bar->priv->down_slider_button) {
- nautilus_path_bar_remove_1 (container, widget);
- path_bar->priv->down_slider_button = NULL;
- return;
- }
-
- children = path_bar->priv->button_list;
- while (children) {
- if (widget == BUTTON_DATA (children->data)->button) {
- nautilus_path_bar_remove_1 (container, widget);
- path_bar->priv->button_list = g_list_remove_link (path_bar->priv->button_list, children);
- g_list_free_1 (children);
- return;
- }
- children = children->next;
+ GtkWidget *widget)
+{
+ NautilusPathBar *path_bar;
+ GList *children;
+
+ path_bar = NAUTILUS_PATH_BAR (container);
+
+ if (widget == path_bar->priv->up_slider_button)
+ {
+ nautilus_path_bar_remove_1 (container, widget);
+ path_bar->priv->up_slider_button = NULL;
+ return;
+ }
+
+ if (widget == path_bar->priv->down_slider_button)
+ {
+ nautilus_path_bar_remove_1 (container, widget);
+ path_bar->priv->down_slider_button = NULL;
+ return;
+ }
+
+ children = path_bar->priv->button_list;
+ while (children)
+ {
+ if (widget == BUTTON_DATA (children->data)->button)
+ {
+ nautilus_path_bar_remove_1 (container, widget);
+ path_bar->priv->button_list = g_list_remove_link (path_bar->priv->button_list, children);
+ g_list_free_1 (children);
+ return;
}
+ children = children->next;
+ }
}
static void
nautilus_path_bar_forall (GtkContainer *container,
- gboolean include_internals,
- GtkCallback callback,
- gpointer callback_data)
-{
- NautilusPathBar *path_bar;
- GList *children;
-
- g_return_if_fail (callback != NULL);
- path_bar = NAUTILUS_PATH_BAR (container);
-
- children = path_bar->priv->button_list;
- while (children) {
- GtkWidget *child;
- child = BUTTON_DATA (children->data)->button;
- children = children->next;
- (* callback) (child, callback_data);
- }
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ NautilusPathBar *path_bar;
+ GList *children;
- if (path_bar->priv->up_slider_button) {
- (* callback) (path_bar->priv->up_slider_button, callback_data);
- }
+ g_return_if_fail (callback != NULL);
+ path_bar = NAUTILUS_PATH_BAR (container);
- if (path_bar->priv->down_slider_button) {
- (* callback) (path_bar->priv->down_slider_button, callback_data);
- }
+ children = path_bar->priv->button_list;
+ while (children)
+ {
+ GtkWidget *child;
+ child = BUTTON_DATA (children->data)->button;
+ children = children->next;
+ (*callback)(child, callback_data);
+ }
+
+ if (path_bar->priv->up_slider_button)
+ {
+ (*callback)(path_bar->priv->up_slider_button, callback_data);
+ }
+
+ if (path_bar->priv->down_slider_button)
+ {
+ (*callback)(path_bar->priv->down_slider_button, callback_data);
+ }
}
static void
nautilus_path_bar_grab_notify (GtkWidget *widget,
- gboolean was_grabbed)
+ gboolean was_grabbed)
{
- if (!was_grabbed) {
- nautilus_path_bar_stop_scrolling (NAUTILUS_PATH_BAR (widget));
- }
+ if (!was_grabbed)
+ {
+ nautilus_path_bar_stop_scrolling (NAUTILUS_PATH_BAR (widget));
+ }
}
static void
nautilus_path_bar_state_changed (GtkWidget *widget,
- GtkStateType previous_state)
+ GtkStateType previous_state)
{
- if (!gtk_widget_get_sensitive (widget)) {
- nautilus_path_bar_stop_scrolling (NAUTILUS_PATH_BAR (widget));
- }
+ if (!gtk_widget_get_sensitive (widget))
+ {
+ nautilus_path_bar_stop_scrolling (NAUTILUS_PATH_BAR (widget));
+ }
}
static GtkWidgetPath *
nautilus_path_bar_get_path_for_child (GtkContainer *container,
- GtkWidget *child)
+ GtkWidget *child)
{
- NautilusPathBar *path_bar = NAUTILUS_PATH_BAR (container);
- GtkWidgetPath *path;
+ NautilusPathBar *path_bar = NAUTILUS_PATH_BAR (container);
+ GtkWidgetPath *path;
- path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (path_bar)));
+ path = gtk_widget_path_copy (gtk_widget_get_path (GTK_WIDGET (path_bar)));
- if (gtk_widget_get_visible (child) &&
- gtk_widget_get_child_visible (child)) {
- GtkWidgetPath *sibling_path;
- GList *visible_children;
- GList *l;
- int pos;
+ if (gtk_widget_get_visible (child) &&
+ gtk_widget_get_child_visible (child))
+ {
+ GtkWidgetPath *sibling_path;
+ GList *visible_children;
+ GList *l;
+ int pos;
- /* 1. Build the list of visible children, in visually left-to-right order
- * (i.e. independently of the widget's direction). Note that our
- * button_list is stored in innermost-to-outermost path order!
- */
+ /* 1. Build the list of visible children, in visually left-to-right order
+ * (i.e. independently of the widget's direction). Note that our
+ * button_list is stored in innermost-to-outermost path order!
+ */
- visible_children = NULL;
+ visible_children = NULL;
- if (gtk_widget_get_visible (path_bar->priv->down_slider_button) &&
- gtk_widget_get_child_visible (path_bar->priv->down_slider_button)) {
- visible_children = g_list_prepend (visible_children, path_bar->priv->down_slider_button);
- }
+ if (gtk_widget_get_visible (path_bar->priv->down_slider_button) &&
+ gtk_widget_get_child_visible (path_bar->priv->down_slider_button))
+ {
+ visible_children = g_list_prepend (visible_children, path_bar->priv->down_slider_button);
+ }
- for (l = path_bar->priv->button_list; l; l = l->next) {
- ButtonData *data = l->data;
-
- if (gtk_widget_get_visible (data->button) &&
- gtk_widget_get_child_visible (data->button))
- visible_children = g_list_prepend (visible_children, data->button);
- }
+ for (l = path_bar->priv->button_list; l; l = l->next)
+ {
+ ButtonData *data = l->data;
- if (gtk_widget_get_visible (path_bar->priv->up_slider_button) &&
- gtk_widget_get_child_visible (path_bar->priv->up_slider_button)) {
- visible_children = g_list_prepend (visible_children, path_bar->priv->up_slider_button);
- }
+ if (gtk_widget_get_visible (data->button) &&
+ gtk_widget_get_child_visible (data->button))
+ {
+ visible_children = g_list_prepend (visible_children, data->button);
+ }
+ }
- if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL) {
- visible_children = g_list_reverse (visible_children);
- }
+ if (gtk_widget_get_visible (path_bar->priv->up_slider_button) &&
+ gtk_widget_get_child_visible (path_bar->priv->up_slider_button))
+ {
+ visible_children = g_list_prepend (visible_children, path_bar->priv->up_slider_button);
+ }
- /* 2. Find the index of the child within that list */
+ if (gtk_widget_get_direction (GTK_WIDGET (path_bar)) == GTK_TEXT_DIR_RTL)
+ {
+ visible_children = g_list_reverse (visible_children);
+ }
- pos = 0;
+ /* 2. Find the index of the child within that list */
- for (l = visible_children; l; l = l->next) {
- GtkWidget *button = l->data;
+ pos = 0;
- if (button == child) {
- break;
- }
+ for (l = visible_children; l; l = l->next)
+ {
+ GtkWidget *button = l->data;
- pos++;
- }
+ if (button == child)
+ {
+ break;
+ }
- /* 3. Build the path */
+ pos++;
+ }
- sibling_path = gtk_widget_path_new ();
+ /* 3. Build the path */
- for (l = visible_children; l; l = l->next) {
- gtk_widget_path_append_for_widget (sibling_path, l->data);
- }
+ sibling_path = gtk_widget_path_new ();
- gtk_widget_path_append_with_siblings (path, sibling_path, pos);
+ for (l = visible_children; l; l = l->next)
+ {
+ gtk_widget_path_append_for_widget (sibling_path, l->data);
+ }
- g_list_free (visible_children);
- gtk_widget_path_unref (sibling_path);
- } else {
- gtk_widget_path_append_for_widget (path, child);
- }
+ gtk_widget_path_append_with_siblings (path, sibling_path, pos);
- return path;
+ g_list_free (visible_children);
+ gtk_widget_path_unref (sibling_path);
+ }
+ else
+ {
+ gtk_widget_path_append_for_widget (path, child);
+ }
+
+ return path;
}
static void
nautilus_path_bar_class_init (NautilusPathBarClass *path_bar_class)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
-
- gobject_class = (GObjectClass *) path_bar_class;
- widget_class = (GtkWidgetClass *) path_bar_class;
- container_class = (GtkContainerClass *) path_bar_class;
-
- gobject_class->finalize = nautilus_path_bar_finalize;
- gobject_class->dispose = nautilus_path_bar_dispose;
-
- widget_class->get_preferred_height = nautilus_path_bar_get_preferred_height;
- widget_class->get_preferred_width = nautilus_path_bar_get_preferred_width;
- widget_class->realize = nautilus_path_bar_realize;
- widget_class->unrealize = nautilus_path_bar_unrealize;
- widget_class->unmap = nautilus_path_bar_unmap;
- widget_class->map = nautilus_path_bar_map;
- widget_class->size_allocate = nautilus_path_bar_size_allocate;
- widget_class->style_updated = nautilus_path_bar_style_updated;
- widget_class->screen_changed = nautilus_path_bar_screen_changed;
- widget_class->grab_notify = nautilus_path_bar_grab_notify;
- widget_class->state_changed = nautilus_path_bar_state_changed;
- widget_class->scroll_event = nautilus_path_bar_scroll;
-
- container_class->add = nautilus_path_bar_add;
- container_class->forall = nautilus_path_bar_forall;
- container_class->remove = nautilus_path_bar_remove;
- container_class->get_path_for_child = nautilus_path_bar_get_path_for_child;
-
- path_bar_signals [OPEN_LOCATION] =
- g_signal_new ("open-location",
- G_OBJECT_CLASS_TYPE (path_bar_class),
- G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusPathBarClass, open_location),
- NULL, NULL, NULL,
- G_TYPE_NONE, 2,
- G_TYPE_FILE,
- GTK_TYPE_PLACES_OPEN_FLAGS);
- path_bar_signals [PATH_CLICKED] =
- g_signal_new ("path-clicked",
- G_OBJECT_CLASS_TYPE (path_bar_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (NautilusPathBarClass, path_clicked),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- G_TYPE_FILE);
-
- gtk_container_class_handle_border_width (container_class);
- g_type_class_add_private (path_bar_class, sizeof (NautilusPathBarDetails));
+ GObjectClass *gobject_class;
+ GtkWidgetClass *widget_class;
+ GtkContainerClass *container_class;
+
+ gobject_class = (GObjectClass *) path_bar_class;
+ widget_class = (GtkWidgetClass *) path_bar_class;
+ container_class = (GtkContainerClass *) path_bar_class;
+
+ gobject_class->finalize = nautilus_path_bar_finalize;
+ gobject_class->dispose = nautilus_path_bar_dispose;
+
+ widget_class->get_preferred_height = nautilus_path_bar_get_preferred_height;
+ widget_class->get_preferred_width = nautilus_path_bar_get_preferred_width;
+ widget_class->realize = nautilus_path_bar_realize;
+ widget_class->unrealize = nautilus_path_bar_unrealize;
+ widget_class->unmap = nautilus_path_bar_unmap;
+ widget_class->map = nautilus_path_bar_map;
+ widget_class->size_allocate = nautilus_path_bar_size_allocate;
+ widget_class->style_updated = nautilus_path_bar_style_updated;
+ widget_class->screen_changed = nautilus_path_bar_screen_changed;
+ widget_class->grab_notify = nautilus_path_bar_grab_notify;
+ widget_class->state_changed = nautilus_path_bar_state_changed;
+ widget_class->scroll_event = nautilus_path_bar_scroll;
+
+ container_class->add = nautilus_path_bar_add;
+ container_class->forall = nautilus_path_bar_forall;
+ container_class->remove = nautilus_path_bar_remove;
+ container_class->get_path_for_child = nautilus_path_bar_get_path_for_child;
+
+ path_bar_signals [OPEN_LOCATION] =
+ g_signal_new ("open-location",
+ G_OBJECT_CLASS_TYPE (path_bar_class),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusPathBarClass, open_location),
+ NULL, NULL, NULL,
+ G_TYPE_NONE, 2,
+ G_TYPE_FILE,
+ GTK_TYPE_PLACES_OPEN_FLAGS);
+ path_bar_signals [PATH_CLICKED] =
+ g_signal_new ("path-clicked",
+ G_OBJECT_CLASS_TYPE (path_bar_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (NautilusPathBarClass, path_clicked),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ G_TYPE_FILE);
+
+ gtk_container_class_handle_border_width (container_class);
+ g_type_class_add_private (path_bar_class, sizeof (NautilusPathBarDetails));
}
static void
nautilus_path_bar_scroll_down (NautilusPathBar *path_bar)
{
- GList *list;
- GList *down_button;
- GList *up_button;
- gint space_available;
- gint space_needed;
- GtkTextDirection direction;
- GtkAllocation allocation, button_allocation, slider_allocation;
+ GList *list;
+ GList *down_button;
+ GList *up_button;
+ gint space_available;
+ gint space_needed;
+ GtkTextDirection direction;
+ GtkAllocation allocation, button_allocation, slider_allocation;
- down_button = NULL;
- up_button = NULL;
+ down_button = NULL;
+ up_button = NULL;
- if (path_bar->priv->ignore_click) {
- path_bar->priv->ignore_click = FALSE;
- return;
- }
+ if (path_bar->priv->ignore_click)
+ {
+ path_bar->priv->ignore_click = FALSE;
+ return;
+ }
- gtk_widget_queue_resize (GTK_WIDGET (path_bar));
-
- direction = gtk_widget_get_direction (GTK_WIDGET (path_bar));
-
- /* We find the button at the 'down' end that we have to make */
- /* visible */
- for (list = path_bar->priv->button_list; list; list = list->next) {
- if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button)) {
- down_button = list;
- break;
- }
- }
+ gtk_widget_queue_resize (GTK_WIDGET (path_bar));
+
+ direction = gtk_widget_get_direction (GTK_WIDGET (path_bar));
- if (down_button == NULL) {
- return;
- }
-
- /* Find the last visible button on the 'up' end */
- for (list = g_list_last (path_bar->priv->button_list); list; list = list->prev) {
- if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button)) {
- up_button = list;
- break;
- }
+ /* We find the button at the 'down' end that we have to make */
+ /* visible */
+ for (list = path_bar->priv->button_list; list; list = list->next)
+ {
+ if (list->next && gtk_widget_get_child_visible (BUTTON_DATA (list->next->data)->button))
+ {
+ down_button = list;
+ break;
}
+ }
+
+ if (down_button == NULL)
+ {
+ return;
+ }
- gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
- gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
- gtk_widget_get_allocation (path_bar->priv->down_slider_button, &slider_allocation);
-
- space_needed = button_allocation.width;
- if (direction == GTK_TEXT_DIR_RTL) {
- space_available = slider_allocation.x - allocation.x;
- } else {
- space_available = (allocation.x + allocation.width) -
- (slider_allocation.x + slider_allocation.width);
- }
-
- /* We have space_available extra space that's not being used. We
- * need space_needed space to make the button fit. So we walk down
- * from the end, removing buttons until we get all the space we
- * need. */
- gtk_widget_get_allocation (BUTTON_DATA (up_button->data)->button, &button_allocation);
- while ((space_available < space_needed) &&
- (up_button != NULL)) {
- space_available += button_allocation.width;
- up_button = up_button->prev;
- path_bar->priv->first_scrolled_button = up_button;
+ /* Find the last visible button on the 'up' end */
+ for (list = g_list_last (path_bar->priv->button_list); list; list = list->prev)
+ {
+ if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
+ {
+ up_button = list;
+ break;
}
+ }
+
+ gtk_widget_get_allocation (BUTTON_DATA (down_button->data)->button, &button_allocation);
+ gtk_widget_get_allocation (GTK_WIDGET (path_bar), &allocation);
+ gtk_widget_get_allocation (path_bar->priv->down_slider_button, &slider_allocation);
+
+ space_needed = button_allocation.width;
+ if (direction == GTK_TEXT_DIR_RTL)
+ {
+ space_available = slider_allocation.x - allocation.x;
+ }
+ else
+ {
+ space_available = (allocation.x + allocation.width) -
+ (slider_allocation.x + slider_allocation.width);
+ }
+
+ /* We have space_available extra space that's not being used. We
+ * need space_needed space to make the button fit. So we walk down
+ * from the end, removing buttons until we get all the space we
+ * need. */
+ gtk_widget_get_allocation (BUTTON_DATA (up_button->data)->button, &button_allocation);
+ while ((space_available < space_needed) &&
+ (up_button != NULL))
+ {
+ space_available += button_allocation.width;
+ up_button = up_button->prev;
+ path_bar->priv->first_scrolled_button = up_button;
+ }
}
static void
nautilus_path_bar_scroll_up (NautilusPathBar *path_bar)
{
- GList *list;
+ GList *list;
- if (path_bar->priv->ignore_click) {
- path_bar->priv->ignore_click = FALSE;
- return;
- }
+ if (path_bar->priv->ignore_click)
+ {
+ path_bar->priv->ignore_click = FALSE;
+ return;
+ }
- gtk_widget_queue_resize (GTK_WIDGET (path_bar));
+ gtk_widget_queue_resize (GTK_WIDGET (path_bar));
- for (list = g_list_last (path_bar->priv->button_list); list; list = list->prev) {
- if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button)) {
- path_bar->priv->first_scrolled_button = list;
- return;
- }
+ for (list = g_list_last (path_bar->priv->button_list); list; list = list->prev)
+ {
+ if (list->prev && gtk_widget_get_child_visible (BUTTON_DATA (list->prev->data)->button))
+ {
+ path_bar->priv->first_scrolled_button = list;
+ return;
}
+ }
}
static gboolean
nautilus_path_bar_scroll_timeout (NautilusPathBar *path_bar)
{
- gboolean retval = FALSE;
-
- if (path_bar->priv->timer) {
- if (gtk_widget_has_focus (path_bar->priv->up_slider_button)) {
- nautilus_path_bar_scroll_up (path_bar);
- } else {
- if (gtk_widget_has_focus (path_bar->priv->down_slider_button)) {
- nautilus_path_bar_scroll_down (path_bar);
- }
- }
- if (path_bar->priv->need_timer) {
- path_bar->priv->need_timer = FALSE;
-
- path_bar->priv->timer =
- g_timeout_add (SCROLL_TIMEOUT,
- (GSourceFunc) nautilus_path_bar_scroll_timeout,
- path_bar);
-
- } else {
- retval = TRUE;
- }
+ gboolean retval = FALSE;
+
+ if (path_bar->priv->timer)
+ {
+ if (gtk_widget_has_focus (path_bar->priv->up_slider_button))
+ {
+ nautilus_path_bar_scroll_up (path_bar);
+ }
+ else
+ {
+ if (gtk_widget_has_focus (path_bar->priv->down_slider_button))
+ {
+ nautilus_path_bar_scroll_down (path_bar);
+ }
}
+ if (path_bar->priv->need_timer)
+ {
+ path_bar->priv->need_timer = FALSE;
- return retval;
+ path_bar->priv->timer =
+ g_timeout_add (SCROLL_TIMEOUT,
+ (GSourceFunc) nautilus_path_bar_scroll_timeout,
+ path_bar);
+ }
+ else
+ {
+ retval = TRUE;
+ }
+ }
+
+ return retval;
}
-static void
+static void
nautilus_path_bar_stop_scrolling (NautilusPathBar *path_bar)
{
- if (path_bar->priv->timer) {
- g_source_remove (path_bar->priv->timer);
- path_bar->priv->timer = 0;
- path_bar->priv->need_timer = FALSE;
- }
+ if (path_bar->priv->timer)
+ {
+ g_source_remove (path_bar->priv->timer);
+ path_bar->priv->timer = 0;
+ path_bar->priv->need_timer = FALSE;
+ }
}
static gboolean
-nautilus_path_bar_slider_button_press (GtkWidget *widget,
- GdkEventButton *event,
- NautilusPathBar *path_bar)
+nautilus_path_bar_slider_button_press (GtkWidget *widget,
+ GdkEventButton *event,
+ NautilusPathBar *path_bar)
{
- if (!gtk_widget_has_focus (widget)) {
- gtk_widget_grab_focus (widget);
- }
+ if (!gtk_widget_has_focus (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ }
- if (event->type != GDK_BUTTON_PRESS || event->button != 1) {
- return FALSE;
- }
+ if (event->type != GDK_BUTTON_PRESS || event->button != 1)
+ {
+ return FALSE;
+ }
- path_bar->priv->ignore_click = FALSE;
+ path_bar->priv->ignore_click = FALSE;
- if (widget == path_bar->priv->up_slider_button) {
- nautilus_path_bar_scroll_up (path_bar);
- } else {
- if (widget == path_bar->priv->down_slider_button) {
- nautilus_path_bar_scroll_down (path_bar);
- }
- }
-
- if (!path_bar->priv->timer) {
- path_bar->priv->need_timer = TRUE;
- path_bar->priv->timer =
- g_timeout_add (INITIAL_SCROLL_TIMEOUT,
- (GSourceFunc) nautilus_path_bar_scroll_timeout,
- path_bar);
+ if (widget == path_bar->priv->up_slider_button)
+ {
+ nautilus_path_bar_scroll_up (path_bar);
+ }
+ else
+ {
+ if (widget == path_bar->priv->down_slider_button)
+ {
+ nautilus_path_bar_scroll_down (path_bar);
}
+ }
- return FALSE;
+ if (!path_bar->priv->timer)
+ {
+ path_bar->priv->need_timer = TRUE;
+ path_bar->priv->timer =
+ g_timeout_add (INITIAL_SCROLL_TIMEOUT,
+ (GSourceFunc) nautilus_path_bar_scroll_timeout,
+ path_bar);
+ }
+
+ return FALSE;
}
static gboolean
-nautilus_path_bar_slider_button_release (GtkWidget *widget,
- GdkEventButton *event,
- NautilusPathBar *path_bar)
+nautilus_path_bar_slider_button_release (GtkWidget *widget,
+ GdkEventButton *event,
+ NautilusPathBar *path_bar)
{
- if (event->type != GDK_BUTTON_RELEASE) {
- return FALSE;
- }
+ if (event->type != GDK_BUTTON_RELEASE)
+ {
+ return FALSE;
+ }
- path_bar->priv->ignore_click = TRUE;
- nautilus_path_bar_stop_scrolling (path_bar);
+ path_bar->priv->ignore_click = TRUE;
+ nautilus_path_bar_stop_scrolling (path_bar);
- return FALSE;
+ return FALSE;
}
@@ -1307,115 +1448,121 @@ nautilus_path_bar_slider_button_release (GtkWidget *widget,
static void
reload_icons (NautilusPathBar *path_bar)
{
- GList *list;
-
- for (list = path_bar->priv->button_list; list; list = list->next) {
- ButtonData *button_data;
+ GList *list;
- button_data = BUTTON_DATA (list->data);
- if (button_data->type != NORMAL_BUTTON || button_data->is_root) {
- nautilus_path_bar_update_button_appearance (button_data);
- }
+ for (list = path_bar->priv->button_list; list; list = list->next)
+ {
+ ButtonData *button_data;
+ button_data = BUTTON_DATA (list->data);
+ if (button_data->type != NORMAL_BUTTON || button_data->is_root)
+ {
+ nautilus_path_bar_update_button_appearance (button_data);
}
+ }
}
/* Callback used when a GtkSettings value changes */
static void
-settings_notify_cb (GObject *object,
- GParamSpec *pspec,
- NautilusPathBar *path_bar)
+settings_notify_cb (GObject *object,
+ GParamSpec *pspec,
+ NautilusPathBar *path_bar)
{
- const char *name;
+ const char *name;
- name = g_param_spec_get_name (pspec);
+ name = g_param_spec_get_name (pspec);
- if (! strcmp (name, "gtk-icon-theme-name") || ! strcmp (name, "gtk-icon-sizes")) {
- reload_icons (path_bar);
- }
+ if (!strcmp (name, "gtk-icon-theme-name") || !strcmp (name, "gtk-icon-sizes"))
+ {
+ reload_icons (path_bar);
+ }
}
static void
nautilus_path_bar_check_icon_theme (NautilusPathBar *path_bar)
{
- GtkSettings *settings;
+ GtkSettings *settings;
- if (path_bar->priv->settings_signal_id) {
- return;
- }
+ if (path_bar->priv->settings_signal_id)
+ {
+ return;
+ }
- settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
- path_bar->priv->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
+ settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (path_bar)));
+ path_bar->priv->settings_signal_id = g_signal_connect (settings, "notify", G_CALLBACK (settings_notify_cb), path_bar);
- reload_icons (path_bar);
+ reload_icons (path_bar);
}
/* Public functions and their helpers */
static void
nautilus_path_bar_clear_buttons (NautilusPathBar *path_bar)
{
- while (path_bar->priv->button_list != NULL) {
- gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->priv->button_list->data)->button);
- }
- path_bar->priv->first_scrolled_button = NULL;
+ while (path_bar->priv->button_list != NULL)
+ {
+ gtk_container_remove (GTK_CONTAINER (path_bar), BUTTON_DATA (path_bar->priv->button_list->data)->button);
+ }
+ path_bar->priv->first_scrolled_button = NULL;
}
static void
button_clicked_cb (GtkWidget *button,
- gpointer data)
+ gpointer data)
{
- ButtonData *button_data;
- NautilusPathBar *path_bar;
- GList *button_list;
+ ButtonData *button_data;
+ NautilusPathBar *path_bar;
+ GList *button_list;
- button_data = BUTTON_DATA (data);
- if (button_data->ignore_changes) {
- return;
- }
+ button_data = BUTTON_DATA (data);
+ if (button_data->ignore_changes)
+ {
+ return;
+ }
- path_bar = NAUTILUS_PATH_BAR (gtk_widget_get_parent (button));
+ path_bar = NAUTILUS_PATH_BAR (gtk_widget_get_parent (button));
- button_list = g_list_find (path_bar->priv->button_list, button_data);
- g_assert (button_list != NULL);
+ button_list = g_list_find (path_bar->priv->button_list, button_data);
+ g_assert (button_list != NULL);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
- g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0, button_data->path);
+ g_signal_emit (path_bar, path_bar_signals [PATH_CLICKED], 0, button_data->path);
}
static void
real_pop_up_pathbar_context_menu (NautilusPathBar *path_bar)
{
- nautilus_pop_up_context_menu (GTK_WIDGET (path_bar),
- path_bar->priv->context_menu,
- path_bar->priv->context_menu_event);
+ nautilus_pop_up_context_menu (GTK_WIDGET (path_bar),
+ path_bar->priv->context_menu,
+ path_bar->priv->context_menu_event);
}
static void
pathbar_popup_file_attributes_ready (NautilusFile *file,
gpointer data)
{
- NautilusPathBar *path_bar;
+ NautilusPathBar *path_bar;
- path_bar = NAUTILUS_PATH_BAR (data);
- g_assert (NAUTILUS_IS_PATH_BAR (path_bar));
+ path_bar = NAUTILUS_PATH_BAR (data);
+ g_assert (NAUTILUS_IS_PATH_BAR (path_bar));
- g_assert (file == path_bar->priv->context_menu_file);
+ g_assert (file == path_bar->priv->context_menu_file);
- real_pop_up_pathbar_context_menu (path_bar);
+ real_pop_up_pathbar_context_menu (path_bar);
}
static void
unschedule_pop_up_context_menu (NautilusPathBar *path_bar)
{
- if (path_bar->priv->context_menu_file) {
- g_assert (NAUTILUS_IS_FILE (path_bar->priv->context_menu_file));
- nautilus_file_cancel_call_when_ready (path_bar->priv->context_menu_file,
- pathbar_popup_file_attributes_ready,
- path_bar);
- g_clear_pointer (&path_bar->priv->context_menu_file, nautilus_file_unref);
- }
+ if (path_bar->priv->context_menu_file)
+ {
+ g_assert (NAUTILUS_IS_FILE (path_bar->priv->context_menu_file));
+ nautilus_file_cancel_call_when_ready (path_bar->priv->context_menu_file,
+ pathbar_popup_file_attributes_ready,
+ path_bar);
+ g_clear_pointer (&path_bar->priv->context_menu_file, nautilus_file_unref);
+ }
}
static void
@@ -1423,31 +1570,36 @@ schedule_pop_up_context_menu (NautilusPathBar *path_bar,
GdkEventButton *event,
NautilusFile *file)
{
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_FILE (file));
- if (path_bar->priv->context_menu_event != NULL) {
- gdk_event_free ((GdkEvent *) path_bar->priv->context_menu_event);
- }
- path_bar->priv->context_menu_event = (GdkEventButton *) gdk_event_copy ((GdkEvent *)event);
-
- if (file == path_bar->priv->context_menu_file) {
- if (nautilus_file_check_if_ready (file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT |
- NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO)) {
- real_pop_up_pathbar_context_menu (path_bar);
- }
- } else {
- unschedule_pop_up_context_menu (path_bar);
-
- path_bar->priv->context_menu_file = nautilus_file_ref (file);
- nautilus_file_call_when_ready (path_bar->priv->context_menu_file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT |
- NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO,
- pathbar_popup_file_attributes_ready,
- path_bar);
+ if (path_bar->priv->context_menu_event != NULL)
+ {
+ gdk_event_free ((GdkEvent *) path_bar->priv->context_menu_event);
+ }
+ path_bar->priv->context_menu_event = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
+
+ if (file == path_bar->priv->context_menu_file)
+ {
+ if (nautilus_file_check_if_ready (file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO))
+ {
+ real_pop_up_pathbar_context_menu (path_bar);
}
+ }
+ else
+ {
+ unschedule_pop_up_context_menu (path_bar);
+
+ path_bar->priv->context_menu_file = nautilus_file_ref (file);
+ nautilus_file_call_when_ready (path_bar->priv->context_menu_file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_FILESYSTEM_INFO,
+ pathbar_popup_file_attributes_ready,
+ path_bar);
+ }
}
static void
@@ -1455,557 +1607,640 @@ pop_up_pathbar_context_menu (NautilusPathBar *path_bar,
GdkEventButton *event,
NautilusFile *file)
{
- if (file) {
- schedule_pop_up_context_menu (path_bar, event, file);
- }
+ if (file)
+ {
+ schedule_pop_up_context_menu (path_bar, event, file);
+ }
}
static gboolean
-button_event_cb (GtkWidget *button,
- GdkEventButton *event,
- gpointer data)
+button_event_cb (GtkWidget *button,
+ GdkEventButton *event,
+ gpointer data)
{
- GtkPlacesOpenFlags flags;
- ButtonData *button_data;
- NautilusPathBar *path_bar;
- int mask;
+ GtkPlacesOpenFlags flags;
+ ButtonData *button_data;
+ NautilusPathBar *path_bar;
+ int mask;
- button_data = BUTTON_DATA (data);
- path_bar = NAUTILUS_PATH_BAR (gtk_widget_get_parent (button));
+ button_data = BUTTON_DATA (data);
+ path_bar = NAUTILUS_PATH_BAR (gtk_widget_get_parent (button));
- if (event->type == GDK_BUTTON_PRESS) {
- g_object_set_data (G_OBJECT (button), "handle-button-release", GINT_TO_POINTER (TRUE));
-
- if (event->button == 3) {
- pop_up_pathbar_context_menu (path_bar, event, button_data->file);
- return TRUE;
- }
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ g_object_set_data (G_OBJECT (button), "handle-button-release", GINT_TO_POINTER (TRUE));
- } else if (event->type == GDK_BUTTON_RELEASE) {
- mask = event->state & gtk_accelerator_get_default_mod_mask ();
- flags = 0;
-
- if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "handle-button-release"))) {
- return FALSE;
- }
+ if (event->button == 3)
+ {
+ pop_up_pathbar_context_menu (path_bar, event, button_data->file);
+ return TRUE;
+ }
+ }
+ else if (event->type == GDK_BUTTON_RELEASE)
+ {
+ mask = event->state & gtk_accelerator_get_default_mod_mask ();
+ flags = 0;
- if (event->button == 2 && mask == 0) {
- flags = GTK_PLACES_OPEN_NEW_TAB;
- } else if (event->button == 1 && mask == GDK_CONTROL_MASK) {
- flags = GTK_PLACES_OPEN_NEW_WINDOW;
- }
+ if (!GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (button), "handle-button-release")))
+ {
+ return FALSE;
+ }
- if (flags != 0) {
- g_signal_emit (path_bar, path_bar_signals[OPEN_LOCATION], 0, button_data->path, flags);
- }
+ if (event->button == 2 && mask == 0)
+ {
+ flags = GTK_PLACES_OPEN_NEW_TAB;
+ }
+ else if (event->button == 1 && mask == GDK_CONTROL_MASK)
+ {
+ flags = GTK_PLACES_OPEN_NEW_WINDOW;
+ }
- return FALSE;
+ if (flags != 0)
+ {
+ g_signal_emit (path_bar, path_bar_signals[OPEN_LOCATION], 0, button_data->path, flags);
}
return FALSE;
+ }
+
+ return FALSE;
}
static void
-button_drag_begin_cb (GtkWidget *widget,
- GdkDragContext *drag_context,
- gpointer user_data)
+button_drag_begin_cb (GtkWidget *widget,
+ GdkDragContext *drag_context,
+ gpointer user_data)
{
- g_object_set_data (G_OBJECT (widget), "handle-button-release",
- GINT_TO_POINTER (FALSE));
+ g_object_set_data (G_OBJECT (widget), "handle-button-release",
+ GINT_TO_POINTER (FALSE));
}
static GIcon *
get_gicon_for_mount (ButtonData *button_data)
{
- GIcon *icon;
- GMount *mount;
+ GIcon *icon;
+ GMount *mount;
- icon = NULL;
- mount = nautilus_get_mounted_mount_for_root (button_data->path);
+ icon = NULL;
+ mount = nautilus_get_mounted_mount_for_root (button_data->path);
- if (mount != NULL) {
- icon = g_mount_get_symbolic_icon (mount);
- g_object_unref (mount);
- }
+ if (mount != NULL)
+ {
+ icon = g_mount_get_symbolic_icon (mount);
+ g_object_unref (mount);
+ }
- return icon;
+ return icon;
}
static GIcon *
get_gicon (ButtonData *button_data)
{
- switch (button_data->type)
- {
- case ROOT_BUTTON:
- return g_themed_icon_new (NAUTILUS_ICON_FILESYSTEM);
- case HOME_BUTTON:
- return g_themed_icon_new (NAUTILUS_ICON_HOME);
- case MOUNT_BUTTON:
- return get_gicon_for_mount (button_data);
- default:
- return NULL;
- }
-
- return NULL;
+ switch (button_data->type)
+ {
+ case ROOT_BUTTON:
+ {
+ return g_themed_icon_new (NAUTILUS_ICON_FILESYSTEM);
+ }
+
+ case HOME_BUTTON:
+ {
+ return g_themed_icon_new (NAUTILUS_ICON_HOME);
+ }
+
+ case MOUNT_BUTTON:
+ {
+ return get_gicon_for_mount (button_data);
+ }
+
+ default:
+ return NULL;
+ }
+
+ return NULL;
}
static void
button_data_free (ButtonData *button_data)
{
- g_object_unref (button_data->path);
- g_free (button_data->dir_name);
- if (button_data->file != NULL) {
- g_signal_handler_disconnect (button_data->file,
- button_data->file_changed_signal_id);
- nautilus_file_monitor_remove (button_data->file, button_data);
- nautilus_file_unref (button_data->file);
- }
+ g_object_unref (button_data->path);
+ g_free (button_data->dir_name);
+ if (button_data->file != NULL)
+ {
+ g_signal_handler_disconnect (button_data->file,
+ button_data->file_changed_signal_id);
+ nautilus_file_monitor_remove (button_data->file, button_data);
+ nautilus_file_unref (button_data->file);
+ }
- g_free (button_data);
+ g_free (button_data);
}
static void
nautilus_path_bar_update_button_appearance (ButtonData *button_data)
{
- const gchar *dir_name = get_dir_name (button_data);
- GIcon *icon;
-
- if (button_data->label != NULL) {
- char *markup;
+ const gchar *dir_name = get_dir_name (button_data);
+ GIcon *icon;
- markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
+ if (button_data->label != NULL)
+ {
+ char *markup;
- if (gtk_label_get_use_markup (GTK_LABEL (button_data->label))) {
- gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
- } else {
- gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
- }
+ markup = g_markup_printf_escaped ("<b>%s</b>", dir_name);
- gtk_label_set_markup (GTK_LABEL (button_data->bold_label), markup);
- g_free (markup);
+ if (gtk_label_get_use_markup (GTK_LABEL (button_data->label)))
+ {
+ gtk_label_set_markup (GTK_LABEL (button_data->label), markup);
+ }
+ else
+ {
+ gtk_label_set_text (GTK_LABEL (button_data->label), dir_name);
}
- icon = get_gicon (button_data);
- if (icon != NULL) {
- gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), icon, GTK_ICON_SIZE_MENU);
- gtk_style_context_add_class (gtk_widget_get_style_context (button_data->button),
- "image-button");
- gtk_widget_show (GTK_WIDGET (button_data->image));
- g_object_unref (icon);
- } else {
- gtk_widget_hide (GTK_WIDGET (button_data->image));
- gtk_style_context_remove_class (gtk_widget_get_style_context (button_data->button),
- "image-button");
- }
+ gtk_label_set_markup (GTK_LABEL (button_data->bold_label), markup);
+ g_free (markup);
+ }
+
+ icon = get_gicon (button_data);
+ if (icon != NULL)
+ {
+ gtk_image_set_from_gicon (GTK_IMAGE (button_data->image), icon, GTK_ICON_SIZE_MENU);
+ gtk_style_context_add_class (gtk_widget_get_style_context (button_data->button),
+ "image-button");
+ gtk_widget_show (GTK_WIDGET (button_data->image));
+ g_object_unref (icon);
+ }
+ else
+ {
+ gtk_widget_hide (GTK_WIDGET (button_data->image));
+ gtk_style_context_remove_class (gtk_widget_get_style_context (button_data->button),
+ "image-button");
+ }
}
static void
nautilus_path_bar_update_button_state (ButtonData *button_data,
- gboolean current_dir)
+ gboolean current_dir)
{
- if (button_data->label != NULL) {
- gtk_label_set_label (GTK_LABEL (button_data->label), NULL);
- gtk_label_set_label (GTK_LABEL (button_data->bold_label), NULL);
- gtk_label_set_use_markup (GTK_LABEL (button_data->label), current_dir);
- }
+ if (button_data->label != NULL)
+ {
+ gtk_label_set_label (GTK_LABEL (button_data->label), NULL);
+ gtk_label_set_label (GTK_LABEL (button_data->bold_label), NULL);
+ gtk_label_set_use_markup (GTK_LABEL (button_data->label), current_dir);
+ }
- nautilus_path_bar_update_button_appearance (button_data);
+ nautilus_path_bar_update_button_appearance (button_data);
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir) {
- button_data->ignore_changes = TRUE;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
- button_data->ignore_changes = FALSE;
- }
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_data->button)) != current_dir)
+ {
+ button_data->ignore_changes = TRUE;
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_data->button), current_dir);
+ button_data->ignore_changes = FALSE;
+ }
}
static void
-setup_button_type (ButtonData *button_data,
- NautilusPathBar *path_bar,
- GFile *location)
-{
- GMount *mount;
- gchar *uri;
-
- uri = g_file_get_uri (location);
-
- if (g_strcmp0 (uri, "other-locations:///") == 0) {
- button_data->type = OTHER_LOCATIONS_BUTTON;
- } else if (nautilus_is_root_directory (location)) {
- button_data->type = ROOT_BUTTON;
- } else if (nautilus_is_home_directory (location)) {
- button_data->type = HOME_BUTTON;
- button_data->is_root = TRUE;
- } else if ((mount = nautilus_get_mounted_mount_for_root (location)) != NULL) {
- button_data->dir_name = g_mount_get_name (mount);
- button_data->type = MOUNT_BUTTON;
- button_data->is_root = TRUE;
-
- g_object_unref (mount);
- } else {
- button_data->type = NORMAL_BUTTON;
- }
-
- g_free (uri);
+setup_button_type (ButtonData *button_data,
+ NautilusPathBar *path_bar,
+ GFile *location)
+{
+ GMount *mount;
+ gchar *uri;
+
+ uri = g_file_get_uri (location);
+
+ if (g_strcmp0 (uri, "other-locations:///") == 0)
+ {
+ button_data->type = OTHER_LOCATIONS_BUTTON;
+ }
+ else if (nautilus_is_root_directory (location))
+ {
+ button_data->type = ROOT_BUTTON;
+ }
+ else if (nautilus_is_home_directory (location))
+ {
+ button_data->type = HOME_BUTTON;
+ button_data->is_root = TRUE;
+ }
+ else if ((mount = nautilus_get_mounted_mount_for_root (location)) != NULL)
+ {
+ button_data->dir_name = g_mount_get_name (mount);
+ button_data->type = MOUNT_BUTTON;
+ button_data->is_root = TRUE;
+
+ g_object_unref (mount);
+ }
+ else
+ {
+ button_data->type = NORMAL_BUTTON;
+ }
+
+ g_free (uri);
}
static void
-button_drag_data_get_cb (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint time_,
- gpointer user_data)
+button_drag_data_get_cb (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time_,
+ gpointer user_data)
{
- ButtonData *button_data;
- char *uri_list[2];
- char *tmp;
+ ButtonData *button_data;
+ char *uri_list[2];
+ char *tmp;
- button_data = user_data;
+ button_data = user_data;
- uri_list[0] = g_file_get_uri (button_data->path);
- uri_list[1] = NULL;
+ uri_list[0] = g_file_get_uri (button_data->path);
+ uri_list[1] = NULL;
- if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
- tmp = g_strdup_printf ("%s\r\n", uri_list[0]);
- gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
- 8, (const guchar *) tmp, strlen (tmp));
- g_free (tmp);
- } else if (info == NAUTILUS_ICON_DND_URI_LIST) {
- gtk_selection_data_set_uris (selection_data, uri_list);
- }
+ if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ tmp = g_strdup_printf ("%s\r\n", uri_list[0]);
+ gtk_selection_data_set (selection_data, gtk_selection_data_get_target (selection_data),
+ 8, (const guchar *) tmp, strlen (tmp));
+ g_free (tmp);
+ }
+ else if (info == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ gtk_selection_data_set_uris (selection_data, uri_list);
+ }
- g_free (uri_list[0]);
+ g_free (uri_list[0]);
}
static void
setup_button_drag_source (ButtonData *button_data)
{
- GtkTargetList *target_list;
- const GtkTargetEntry targets[] = {
- { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }
- };
+ GtkTargetList *target_list;
+ const GtkTargetEntry targets[] =
+ {
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST }
+ };
- gtk_drag_source_set (button_data->button,
- GDK_BUTTON1_MASK |
- GDK_BUTTON2_MASK,
- NULL, 0,
- GDK_ACTION_MOVE |
- GDK_ACTION_COPY |
- GDK_ACTION_LINK |
- GDK_ACTION_ASK);
+ gtk_drag_source_set (button_data->button,
+ GDK_BUTTON1_MASK |
+ GDK_BUTTON2_MASK,
+ NULL, 0,
+ GDK_ACTION_MOVE |
+ GDK_ACTION_COPY |
+ GDK_ACTION_LINK |
+ GDK_ACTION_ASK);
- target_list = gtk_target_list_new (targets, G_N_ELEMENTS (targets));
- gtk_target_list_add_uri_targets (target_list, NAUTILUS_ICON_DND_URI_LIST);
- gtk_drag_source_set_target_list (button_data->button, target_list);
- gtk_target_list_unref (target_list);
+ target_list = gtk_target_list_new (targets, G_N_ELEMENTS (targets));
+ gtk_target_list_add_uri_targets (target_list, NAUTILUS_ICON_DND_URI_LIST);
+ gtk_drag_source_set_target_list (button_data->button, target_list);
+ gtk_target_list_unref (target_list);
- g_signal_connect (button_data->button, "drag-data-get",
- G_CALLBACK (button_drag_data_get_cb),
- button_data);
+ g_signal_connect (button_data->button, "drag-data-get",
+ G_CALLBACK (button_drag_data_get_cb),
+ button_data);
}
static void
button_data_file_changed (NautilusFile *file,
- ButtonData *button_data)
-{
- GFile *location, *current_location, *parent, *button_parent;
- ButtonData *current_button_data;
- char *display_name;
- NautilusPathBar *path_bar;
- gboolean renamed, child;
-
- path_bar = (NautilusPathBar *) gtk_widget_get_ancestor (button_data->button,
- NAUTILUS_TYPE_PATH_BAR);
- if (path_bar == NULL) {
- return;
- }
-
- g_assert (path_bar->priv->current_path != NULL);
- g_assert (path_bar->priv->current_button_data != NULL);
-
- current_button_data = path_bar->priv->current_button_data;
-
- location = nautilus_file_get_location (file);
- if (!g_file_equal (button_data->path, location)) {
- parent = g_file_get_parent (location);
- button_parent = g_file_get_parent (button_data->path);
-
- renamed = (parent != NULL && button_parent != NULL) &&
- g_file_equal (parent, button_parent);
-
- if (parent != NULL) {
- g_object_unref (parent);
- }
- if (button_parent != NULL) {
- g_object_unref (button_parent);
- }
-
- if (renamed) {
- button_data->path = g_object_ref (location);
- } else {
- /* the file has been moved.
- * If it was below the currently displayed location, remove it.
- * If it was not below the currently displayed location, update the path bar
- */
- child = g_file_has_prefix (button_data->path,
- path_bar->priv->current_path);
-
- if (child) {
- /* moved file inside current path hierarchy */
- g_object_unref (location);
- location = g_file_get_parent (button_data->path);
- current_location = g_object_ref (path_bar->priv->current_path);
- } else {
- /* moved current path, or file outside current path hierarchy.
- * Update path bar to new locations.
- */
- current_location = nautilus_file_get_location (current_button_data->file);
- }
-
- nautilus_path_bar_update_path (path_bar, location);
- nautilus_path_bar_set_path (path_bar, current_location);
- g_object_unref (location);
- g_object_unref (current_location);
- return;
- }
- } else if (nautilus_file_is_gone (file)) {
- gint idx, position;
-
- /* if the current or a parent location are gone, clear all the buttons,
- * the view will set the new path.
- */
- current_location = nautilus_file_get_location (current_button_data->file);
-
- if (g_file_has_prefix (current_location, location) ||
- g_file_equal (current_location, location)) {
- nautilus_path_bar_clear_buttons (path_bar);
- } else if (g_file_has_prefix (location, current_location)) {
- /* remove this and the following buttons */
- position = g_list_position (path_bar->priv->button_list,
- g_list_find (path_bar->priv->button_list, button_data));
-
- if (position != -1) {
- for (idx = 0; idx <= position; idx++) {
- gtk_container_remove (GTK_CONTAINER (path_bar),
- BUTTON_DATA (path_bar->priv->button_list->data)->button);
- }
- }
- }
-
- g_object_unref (current_location);
- g_object_unref (location);
- return;
- }
- g_object_unref (location);
-
- /* MOUNTs use the GMount as the name, so don't update for those */
- if (button_data->type != MOUNT_BUTTON) {
- display_name = nautilus_file_get_display_name (file);
- if (g_strcmp0 (display_name, button_data->dir_name) != 0) {
- g_free (button_data->dir_name);
- button_data->dir_name = g_strdup (display_name);
- }
-
- g_free (display_name);
- }
- nautilus_path_bar_update_button_appearance (button_data);
-}
-
-static ButtonData *
-make_button_data (NautilusPathBar *path_bar,
- NautilusFile *file,
- gboolean current_dir)
+ ButtonData *button_data)
{
- GFile *path;
- GtkWidget *child;
- ButtonData *button_data;
+ GFile *location, *current_location, *parent, *button_parent;
+ ButtonData *current_button_data;
+ char *display_name;
+ NautilusPathBar *path_bar;
+ gboolean renamed, child;
- path = nautilus_file_get_location (file);
- child = NULL;
-
- /* Is it a special button? */
- button_data = g_new0 (ButtonData, 1);
-
- setup_button_type (button_data, path_bar, path);
- button_data->button = gtk_toggle_button_new ();
- gtk_style_context_add_class (gtk_widget_get_style_context (button_data->button),
- "text-button");
- gtk_widget_set_focus_on_click (button_data->button, FALSE);
- gtk_widget_add_events (button_data->button, GDK_SCROLL_MASK);
- /* TODO update button type when xdg directories change */
-
- button_data->image = gtk_image_new ();
-
- switch (button_data->type) {
- case ROOT_BUTTON:
- child = button_data->image;
- button_data->label = NULL;
- break;
- case HOME_BUTTON:
- case MOUNT_BUTTON:
- case NORMAL_BUTTON:
- default:
- button_data->label = gtk_label_new (NULL);
- child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
- gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
- break;
- }
+ path_bar = (NautilusPathBar *) gtk_widget_get_ancestor (button_data->button,
+ NAUTILUS_TYPE_PATH_BAR);
+ if (path_bar == NULL)
+ {
+ return;
+ }
- if (button_data->label != NULL) {
- gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_MIDDLE);
- gtk_label_set_single_line_mode (GTK_LABEL (button_data->label), TRUE);
+ g_assert (path_bar->priv->current_path != NULL);
+ g_assert (path_bar->priv->current_button_data != NULL);
- button_data->bold_label = gtk_label_new (NULL);
- gtk_widget_set_no_show_all (button_data->bold_label, TRUE);
- gtk_label_set_single_line_mode (GTK_LABEL (button_data->bold_label), TRUE);
- gtk_box_pack_start (GTK_BOX (child), button_data->bold_label, FALSE, FALSE, 0);
- }
+ current_button_data = path_bar->priv->current_button_data;
- if (button_data->path == NULL) {
- button_data->path = g_object_ref (path);
- }
- if (button_data->dir_name == NULL) {
- button_data->dir_name = nautilus_file_get_display_name (file);
- }
- if (button_data->file == NULL) {
- button_data->file = nautilus_file_ref (file);
- nautilus_file_monitor_add (button_data->file, button_data,
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
- button_data->file_changed_signal_id =
- g_signal_connect (button_data->file, "changed",
- G_CALLBACK (button_data_file_changed),
- button_data);
- }
-
- gtk_container_add (GTK_CONTAINER (button_data->button), child);
- gtk_widget_show_all (button_data->button);
+ location = nautilus_file_get_location (file);
+ if (!g_file_equal (button_data->path, location))
+ {
+ parent = g_file_get_parent (location);
+ button_parent = g_file_get_parent (button_data->path);
- nautilus_path_bar_update_button_state (button_data, current_dir);
+ renamed = (parent != NULL && button_parent != NULL) &&
+ g_file_equal (parent, button_parent);
- g_signal_connect (button_data->button, "clicked", G_CALLBACK (button_clicked_cb), button_data);
- g_signal_connect (button_data->button, "button-press-event", G_CALLBACK (button_event_cb), button_data);
- g_signal_connect (button_data->button, "button-release-event", G_CALLBACK (button_event_cb), button_data);
- g_signal_connect (button_data->button, "drag-begin", G_CALLBACK (button_drag_begin_cb), button_data);
- g_object_weak_ref (G_OBJECT (button_data->button), (GWeakNotify) button_data_free, button_data);
+ if (parent != NULL)
+ {
+ g_object_unref (parent);
+ }
+ if (button_parent != NULL)
+ {
+ g_object_unref (button_parent);
+ }
- setup_button_drag_source (button_data);
+ if (renamed)
+ {
+ button_data->path = g_object_ref (location);
+ }
+ else
+ {
+ /* the file has been moved.
+ * If it was below the currently displayed location, remove it.
+ * If it was not below the currently displayed location, update the path bar
+ */
+ child = g_file_has_prefix (button_data->path,
+ path_bar->priv->current_path);
+
+ if (child)
+ {
+ /* moved file inside current path hierarchy */
+ g_object_unref (location);
+ location = g_file_get_parent (button_data->path);
+ current_location = g_object_ref (path_bar->priv->current_path);
+ }
+ else
+ {
+ /* moved current path, or file outside current path hierarchy.
+ * Update path bar to new locations.
+ */
+ current_location = nautilus_file_get_location (current_button_data->file);
+ }
+
+ nautilus_path_bar_update_path (path_bar, location);
+ nautilus_path_bar_set_path (path_bar, current_location);
+ g_object_unref (location);
+ g_object_unref (current_location);
+ return;
+ }
+ }
+ else if (nautilus_file_is_gone (file))
+ {
+ gint idx, position;
+
+ /* if the current or a parent location are gone, clear all the buttons,
+ * the view will set the new path.
+ */
+ current_location = nautilus_file_get_location (current_button_data->file);
+
+ if (g_file_has_prefix (current_location, location) ||
+ g_file_equal (current_location, location))
+ {
+ nautilus_path_bar_clear_buttons (path_bar);
+ }
+ else if (g_file_has_prefix (location, current_location))
+ {
+ /* remove this and the following buttons */
+ position = g_list_position (path_bar->priv->button_list,
+ g_list_find (path_bar->priv->button_list, button_data));
+
+ if (position != -1)
+ {
+ for (idx = 0; idx <= position; idx++)
+ {
+ gtk_container_remove (GTK_CONTAINER (path_bar),
+ BUTTON_DATA (path_bar->priv->button_list->data)->button);
+ }
+ }
+ }
- nautilus_drag_slot_proxy_init (button_data->button, button_data->file, NULL);
+ g_object_unref (current_location);
+ g_object_unref (location);
+ return;
+ }
+ g_object_unref (location);
+
+ /* MOUNTs use the GMount as the name, so don't update for those */
+ if (button_data->type != MOUNT_BUTTON)
+ {
+ display_name = nautilus_file_get_display_name (file);
+ if (g_strcmp0 (display_name, button_data->dir_name) != 0)
+ {
+ g_free (button_data->dir_name);
+ button_data->dir_name = g_strdup (display_name);
+ }
+
+ g_free (display_name);
+ }
+ nautilus_path_bar_update_button_appearance (button_data);
+}
- g_object_unref (path);
+static ButtonData *
+make_button_data (NautilusPathBar *path_bar,
+ NautilusFile *file,
+ gboolean current_dir)
+{
+ GFile *path;
+ GtkWidget *child;
+ ButtonData *button_data;
+
+ path = nautilus_file_get_location (file);
+ child = NULL;
+
+ /* Is it a special button? */
+ button_data = g_new0 (ButtonData, 1);
+
+ setup_button_type (button_data, path_bar, path);
+ button_data->button = gtk_toggle_button_new ();
+ gtk_style_context_add_class (gtk_widget_get_style_context (button_data->button),
+ "text-button");
+ gtk_widget_set_focus_on_click (button_data->button, FALSE);
+ gtk_widget_add_events (button_data->button, GDK_SCROLL_MASK);
+ /* TODO update button type when xdg directories change */
+
+ button_data->image = gtk_image_new ();
+
+ switch (button_data->type)
+ {
+ case ROOT_BUTTON:
+ {
+ child = button_data->image;
+ button_data->label = NULL;
+ }
+ break;
- return button_data;
+ case HOME_BUTTON:
+ case MOUNT_BUTTON:
+ case NORMAL_BUTTON:
+ default:
+ {
+ button_data->label = gtk_label_new (NULL);
+ child = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
+ gtk_box_pack_start (GTK_BOX (child), button_data->image, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (child), button_data->label, FALSE, FALSE, 0);
+ }
+ break;
+ }
+
+ if (button_data->label != NULL)
+ {
+ gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_MIDDLE);
+ gtk_label_set_single_line_mode (GTK_LABEL (button_data->label), TRUE);
+
+ button_data->bold_label = gtk_label_new (NULL);
+ gtk_widget_set_no_show_all (button_data->bold_label, TRUE);
+ gtk_label_set_single_line_mode (GTK_LABEL (button_data->bold_label), TRUE);
+ gtk_box_pack_start (GTK_BOX (child), button_data->bold_label, FALSE, FALSE, 0);
+ }
+
+ if (button_data->path == NULL)
+ {
+ button_data->path = g_object_ref (path);
+ }
+ if (button_data->dir_name == NULL)
+ {
+ button_data->dir_name = nautilus_file_get_display_name (file);
+ }
+ if (button_data->file == NULL)
+ {
+ button_data->file = nautilus_file_ref (file);
+ nautilus_file_monitor_add (button_data->file, button_data,
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON);
+ button_data->file_changed_signal_id =
+ g_signal_connect (button_data->file, "changed",
+ G_CALLBACK (button_data_file_changed),
+ button_data);
+ }
+
+ gtk_container_add (GTK_CONTAINER (button_data->button), child);
+ gtk_widget_show_all (button_data->button);
+
+ nautilus_path_bar_update_button_state (button_data, current_dir);
+
+ g_signal_connect (button_data->button, "clicked", G_CALLBACK (button_clicked_cb), button_data);
+ g_signal_connect (button_data->button, "button-press-event", G_CALLBACK (button_event_cb), button_data);
+ g_signal_connect (button_data->button, "button-release-event", G_CALLBACK (button_event_cb), button_data);
+ g_signal_connect (button_data->button, "drag-begin", G_CALLBACK (button_drag_begin_cb), button_data);
+ g_object_weak_ref (G_OBJECT (button_data->button), (GWeakNotify) button_data_free, button_data);
+
+ setup_button_drag_source (button_data);
+
+ nautilus_drag_slot_proxy_init (button_data->button, button_data->file, NULL);
+
+ g_object_unref (path);
+
+ return button_data;
}
static gboolean
-nautilus_path_bar_check_parent_path (NautilusPathBar *path_bar,
- GFile *location,
- ButtonData **current_button_data)
-{
- GList *list;
- ButtonData *button_data, *current_data;
- gboolean is_active;
-
- current_data = NULL;
-
- for (list = path_bar->priv->button_list; list; list = list->next) {
- button_data = list->data;
- if (g_file_equal (location, button_data->path)) {
- current_data = button_data;
- is_active = TRUE;
-
- if (!gtk_widget_get_child_visible (current_data->button)) {
- path_bar->priv->first_scrolled_button = list;
- gtk_widget_queue_resize (GTK_WIDGET (path_bar));
- }
- } else {
- is_active = FALSE;
- }
-
- nautilus_path_bar_update_button_state (button_data, is_active);
+nautilus_path_bar_check_parent_path (NautilusPathBar *path_bar,
+ GFile *location,
+ ButtonData **current_button_data)
+{
+ GList *list;
+ ButtonData *button_data, *current_data;
+ gboolean is_active;
+
+ current_data = NULL;
+
+ for (list = path_bar->priv->button_list; list; list = list->next)
+ {
+ button_data = list->data;
+ if (g_file_equal (location, button_data->path))
+ {
+ current_data = button_data;
+ is_active = TRUE;
+
+ if (!gtk_widget_get_child_visible (current_data->button))
+ {
+ path_bar->priv->first_scrolled_button = list;
+ gtk_widget_queue_resize (GTK_WIDGET (path_bar));
+ }
+ }
+ else
+ {
+ is_active = FALSE;
}
- if (current_button_data != NULL) {
- *current_button_data = current_data;
- }
+ nautilus_path_bar_update_button_state (button_data, is_active);
+ }
- return (current_data != NULL);
+ if (current_button_data != NULL)
+ {
+ *current_button_data = current_data;
+ }
+
+ return (current_data != NULL);
}
static void
nautilus_path_bar_update_path (NautilusPathBar *path_bar,
- GFile *file_path)
+ GFile *file_path)
{
- NautilusFile *file;
- gboolean first_directory;
- GList *new_buttons, *l;
- ButtonData *button_data;
+ NautilusFile *file;
+ gboolean first_directory;
+ GList *new_buttons, *l;
+ ButtonData *button_data;
- g_return_if_fail (NAUTILUS_IS_PATH_BAR (path_bar));
- g_return_if_fail (file_path != NULL);
+ g_return_if_fail (NAUTILUS_IS_PATH_BAR (path_bar));
+ g_return_if_fail (file_path != NULL);
- first_directory = TRUE;
- new_buttons = NULL;
+ first_directory = TRUE;
+ new_buttons = NULL;
- file = nautilus_file_get (file_path);
+ file = nautilus_file_get (file_path);
- gtk_widget_push_composite_child ();
+ gtk_widget_push_composite_child ();
- while (file != NULL) {
- NautilusFile *parent_file;
+ while (file != NULL)
+ {
+ NautilusFile *parent_file;
- parent_file = nautilus_file_get_parent (file);
- button_data = make_button_data (path_bar, file, first_directory);
- nautilus_file_unref (file);
+ parent_file = nautilus_file_get_parent (file);
+ button_data = make_button_data (path_bar, file, first_directory);
+ nautilus_file_unref (file);
- if (first_directory) {
- first_directory = FALSE;
- }
+ if (first_directory)
+ {
+ first_directory = FALSE;
+ }
- new_buttons = g_list_prepend (new_buttons, button_data);
+ new_buttons = g_list_prepend (new_buttons, button_data);
- if (parent_file != NULL &&
- button_data->is_root) {
- nautilus_file_unref (parent_file);
- break;
- }
-
- file = parent_file;
+ if (parent_file != NULL &&
+ button_data->is_root)
+ {
+ nautilus_file_unref (parent_file);
+ break;
}
- nautilus_path_bar_clear_buttons (path_bar);
- path_bar->priv->button_list = g_list_reverse (new_buttons);
+ file = parent_file;
+ }
+
+ nautilus_path_bar_clear_buttons (path_bar);
+ path_bar->priv->button_list = g_list_reverse (new_buttons);
- for (l = path_bar->priv->button_list; l; l = l->next) {
- GtkWidget *button;
- button = BUTTON_DATA (l->data)->button;
- gtk_container_add (GTK_CONTAINER (path_bar), button);
- }
+ for (l = path_bar->priv->button_list; l; l = l->next)
+ {
+ GtkWidget *button;
+ button = BUTTON_DATA (l->data)->button;
+ gtk_container_add (GTK_CONTAINER (path_bar), button);
+ }
- gtk_widget_pop_composite_child ();
+ gtk_widget_pop_composite_child ();
}
void
-nautilus_path_bar_set_path (NautilusPathBar *path_bar,
- GFile *file_path)
-{
- ButtonData *button_data;
-
- g_return_if_fail (NAUTILUS_IS_PATH_BAR (path_bar));
- g_return_if_fail (file_path != NULL);
-
- /* Check whether the new path is already present in the pathbar as buttons.
- * This could be a parent directory or a previous selected subdirectory. */
- if (!nautilus_path_bar_check_parent_path (path_bar, file_path, &button_data)) {
- nautilus_path_bar_update_path (path_bar, file_path);
- button_data = g_list_nth_data (path_bar->priv->button_list, 0);
- }
-
- if (path_bar->priv->current_path != NULL) {
- g_object_unref (path_bar->priv->current_path);
- }
-
- path_bar->priv->current_path = g_object_ref (file_path);
- path_bar->priv->current_button_data = button_data;
+nautilus_path_bar_set_path (NautilusPathBar *path_bar,
+ GFile *file_path)
+{
+ ButtonData *button_data;
+
+ g_return_if_fail (NAUTILUS_IS_PATH_BAR (path_bar));
+ g_return_if_fail (file_path != NULL);
+
+ /* Check whether the new path is already present in the pathbar as buttons.
+ * This could be a parent directory or a previous selected subdirectory. */
+ if (!nautilus_path_bar_check_parent_path (path_bar, file_path, &button_data))
+ {
+ nautilus_path_bar_update_path (path_bar, file_path);
+ button_data = g_list_nth_data (path_bar->priv->button_list, 0);
+ }
+
+ if (path_bar->priv->current_path != NULL)
+ {
+ g_object_unref (path_bar->priv->current_path);
+ }
+
+ path_bar->priv->current_path = g_object_ref (file_path);
+ path_bar->priv->current_button_data = button_data;
}
diff --git a/src/nautilus-places-view.c b/src/nautilus-places-view.c
index 4b79da886..151e424e4 100644
--- a/src/nautilus-places-view.c
+++ b/src/nautilus-places-view.c
@@ -25,33 +25,34 @@
typedef struct
{
- GFile *location;
- GIcon *icon;
- NautilusQuery *search_query;
- NautilusToolbarMenuSections *toolbar_menu_sections;
+ GFile *location;
+ GIcon *icon;
+ NautilusQuery *search_query;
+ NautilusToolbarMenuSections *toolbar_menu_sections;
- GtkWidget *places_view;
+ GtkWidget *places_view;
} NautilusPlacesViewPrivate;
struct _NautilusPlacesView
{
- GtkFrameClass parent;
+ GtkFrameClass parent;
};
-static void nautilus_places_view_iface_init (NautilusViewInterface *iface);
+static void nautilus_places_view_iface_init (NautilusViewInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NautilusPlacesView, nautilus_places_view, GTK_TYPE_BOX,
G_ADD_PRIVATE (NautilusPlacesView)
G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_VIEW, nautilus_places_view_iface_init));
-enum {
- PROP_0,
- PROP_ICON,
- PROP_LOCATION,
- PROP_SEARCH_QUERY,
- PROP_IS_LOADING,
- PROP_IS_SEARCHING,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_ICON,
+ PROP_LOCATION,
+ PROP_SEARCH_QUERY,
+ PROP_IS_LOADING,
+ PROP_IS_SEARCHING,
+ LAST_PROP
};
static void
@@ -59,49 +60,57 @@ open_location_cb (NautilusPlacesView *view,
GFile *location,
GtkPlacesOpenFlags open_flags)
{
- NautilusWindowOpenFlags flags;
- GtkWidget *slot;
+ NautilusWindowOpenFlags flags;
+ GtkWidget *slot;
- slot = gtk_widget_get_ancestor (GTK_WIDGET (view), NAUTILUS_TYPE_WINDOW_SLOT);
+ slot = gtk_widget_get_ancestor (GTK_WIDGET (view), NAUTILUS_TYPE_WINDOW_SLOT);
- switch (open_flags) {
+ switch (open_flags)
+ {
case GTK_PLACES_OPEN_NEW_TAB:
- flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB |
- NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
- break;
+ {
+ flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB |
+ NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
+ }
+ break;
case GTK_PLACES_OPEN_NEW_WINDOW:
- flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- break;
+ {
+ flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ }
+ break;
case GTK_PLACES_OPEN_NORMAL: /* fall-through */
default:
- flags = 0;
- break;
+ {
+ flags = 0;
}
+ break;
+ }
- if (slot) {
- NautilusFile *file;
- GtkWidget *window;
- char *path;
-
- path = "other-locations:///";
- file = nautilus_file_get (location);
- window = gtk_widget_get_toplevel (GTK_WIDGET (view));
-
- nautilus_mime_activate_file (GTK_WINDOW (window),
- NAUTILUS_WINDOW_SLOT (slot),
- file,
- path,
- flags);
- nautilus_file_unref (file);
- }
+ if (slot)
+ {
+ NautilusFile *file;
+ GtkWidget *window;
+ char *path;
+
+ path = "other-locations:///";
+ file = nautilus_file_get (location);
+ window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+
+ nautilus_mime_activate_file (GTK_WINDOW (window),
+ NAUTILUS_WINDOW_SLOT (slot),
+ file,
+ path,
+ flags);
+ nautilus_file_unref (file);
+ }
}
static void
loading_cb (NautilusView *view)
{
- g_object_notify (G_OBJECT (view), "is-loading");
+ g_object_notify (G_OBJECT (view), "is-loading");
}
static void
@@ -109,37 +118,37 @@ show_error_message_cb (NautilusGtkPlacesView *view,
const gchar *primary,
const gchar *secondary)
{
- GtkWidget *dialog;
- GtkWidget *window;
+ GtkWidget *dialog;
+ GtkWidget *window;
- window = gtk_widget_get_toplevel (GTK_WIDGET (view));
+ window = gtk_widget_get_toplevel (GTK_WIDGET (view));
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s", primary);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", secondary);
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", primary);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", secondary);
- gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+ gtk_widget_destroy (dialog);
}
static void
nautilus_places_view_finalize (GObject *object)
{
- NautilusPlacesView *self = (NautilusPlacesView *)object;
- NautilusPlacesViewPrivate *priv = nautilus_places_view_get_instance_private (self);
+ NautilusPlacesView *self = (NautilusPlacesView *) object;
+ NautilusPlacesViewPrivate *priv = nautilus_places_view_get_instance_private (self);
- g_clear_object (&priv->icon);
- g_clear_object (&priv->location);
- g_clear_object (&priv->search_query);
+ g_clear_object (&priv->icon);
+ g_clear_object (&priv->location);
+ g_clear_object (&priv->search_query);
- g_free (priv->toolbar_menu_sections);
+ g_free (priv->toolbar_menu_sections);
- G_OBJECT_CLASS (nautilus_places_view_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_places_view_parent_class)->finalize (object);
}
static void
@@ -148,24 +157,31 @@ nautilus_places_view_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusView *view = NAUTILUS_VIEW (object);
+ NautilusView *view = NAUTILUS_VIEW (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_ICON:
- g_value_set_object (value, nautilus_view_get_icon (view));
- break;
+ {
+ g_value_set_object (value, nautilus_view_get_icon (view));
+ }
+ break;
case PROP_LOCATION:
- g_value_set_object (value, nautilus_view_get_location (view));
- break;
+ {
+ g_value_set_object (value, nautilus_view_get_location (view));
+ }
+ break;
case PROP_SEARCH_QUERY:
- g_value_set_object (value, nautilus_view_get_search_query (view));
- break;
+ {
+ g_value_set_object (value, nautilus_view_get_search_query (view));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
@@ -174,223 +190,233 @@ nautilus_places_view_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- NautilusView *view = NAUTILUS_VIEW (object);
+ NautilusView *view = NAUTILUS_VIEW (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_LOCATION:
- nautilus_view_set_location (view, g_value_get_object (value));
- break;
+ {
+ nautilus_view_set_location (view, g_value_get_object (value));
+ }
+ break;
case PROP_SEARCH_QUERY:
- nautilus_view_set_search_query (view, g_value_get_object (value));
- break;
+ {
+ nautilus_view_set_search_query (view, g_value_get_object (value));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
-static GIcon*
+static GIcon *
nautilus_places_view_get_icon (NautilusView *view)
{
- NautilusPlacesViewPrivate *priv;
+ NautilusPlacesViewPrivate *priv;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- return priv->icon;
+ return priv->icon;
}
-static GFile*
+static GFile *
nautilus_places_view_get_location (NautilusView *view)
{
- NautilusPlacesViewPrivate *priv;
+ NautilusPlacesViewPrivate *priv;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- return priv->location;
+ return priv->location;
}
static void
nautilus_places_view_set_location (NautilusView *view,
GFile *location)
{
- if (location) {
- NautilusPlacesViewPrivate *priv;
- gchar *uri;
-
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- uri = g_file_get_uri (location);
-
- /*
- * If it's not trying to open the places view itself, simply
- * delegates the location to application, which takes care of
- * selecting the appropriate view.
- */
- if (g_strcmp0 (uri, "other-locations:///") != 0) {
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location, 0, NULL, NULL, NULL);
- } else {
- g_set_object (&priv->location, location);
- }
-
- g_free (uri);
+ if (location)
+ {
+ NautilusPlacesViewPrivate *priv;
+ gchar *uri;
+
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ uri = g_file_get_uri (location);
+
+ /*
+ * If it's not trying to open the places view itself, simply
+ * delegates the location to application, which takes care of
+ * selecting the appropriate view.
+ */
+ if (g_strcmp0 (uri, "other-locations:///") != 0)
+ {
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location, 0, NULL, NULL, NULL);
+ }
+ else
+ {
+ g_set_object (&priv->location, location);
}
+
+ g_free (uri);
+ }
}
-static GList*
+static GList *
nautilus_places_view_get_selection (NautilusView *view)
{
- /* STUB */
- return NULL;
+ /* STUB */
+ return NULL;
}
static void
nautilus_places_view_set_selection (NautilusView *view,
GList *selection)
{
- /* STUB */
+ /* STUB */
}
-static NautilusQuery*
+static NautilusQuery *
nautilus_places_view_get_search_query (NautilusView *view)
{
- NautilusPlacesViewPrivate *priv;
+ NautilusPlacesViewPrivate *priv;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- return priv->search_query;
+ return priv->search_query;
}
static void
nautilus_places_view_set_search_query (NautilusView *view,
NautilusQuery *query)
{
- NautilusPlacesViewPrivate *priv;
- gchar *text;
+ NautilusPlacesViewPrivate *priv;
+ gchar *text;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- g_set_object (&priv->search_query, query);
+ g_set_object (&priv->search_query, query);
- text = query ? nautilus_query_get_text (query) : NULL;
+ text = query ? nautilus_query_get_text (query) : NULL;
- nautilus_gtk_places_view_set_search_query (NAUTILUS_GTK_PLACES_VIEW (priv->places_view), text);
+ nautilus_gtk_places_view_set_search_query (NAUTILUS_GTK_PLACES_VIEW (priv->places_view), text);
- g_free (text);
+ g_free (text);
}
static NautilusToolbarMenuSections *
nautilus_places_view_get_toolbar_menu_sections (NautilusView *view)
{
- NautilusPlacesViewPrivate *priv;
+ NautilusPlacesViewPrivate *priv;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- return priv->toolbar_menu_sections;
+ return priv->toolbar_menu_sections;
}
static gboolean
nautilus_places_view_is_loading (NautilusView *view)
{
- NautilusPlacesViewPrivate *priv;
+ NautilusPlacesViewPrivate *priv;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- return nautilus_gtk_places_view_get_loading (NAUTILUS_GTK_PLACES_VIEW (priv->places_view));
+ return nautilus_gtk_places_view_get_loading (NAUTILUS_GTK_PLACES_VIEW (priv->places_view));
}
static gboolean
nautilus_places_view_is_searching (NautilusView *view)
{
- NautilusPlacesViewPrivate *priv;
+ NautilusPlacesViewPrivate *priv;
- priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
+ priv = nautilus_places_view_get_instance_private (NAUTILUS_PLACES_VIEW (view));
- return priv->search_query != NULL;
+ return priv->search_query != NULL;
}
static void
nautilus_places_view_iface_init (NautilusViewInterface *iface)
{
- iface->get_icon = nautilus_places_view_get_icon;
- iface->get_location = nautilus_places_view_get_location;
- iface->set_location = nautilus_places_view_set_location;
- iface->get_selection = nautilus_places_view_get_selection;
- iface->set_selection = nautilus_places_view_set_selection;
- iface->get_search_query = nautilus_places_view_get_search_query;
- iface->set_search_query = nautilus_places_view_set_search_query;
- iface->get_toolbar_menu_sections = nautilus_places_view_get_toolbar_menu_sections;
- iface->is_loading = nautilus_places_view_is_loading;
- iface->is_searching = nautilus_places_view_is_searching;
+ iface->get_icon = nautilus_places_view_get_icon;
+ iface->get_location = nautilus_places_view_get_location;
+ iface->set_location = nautilus_places_view_set_location;
+ iface->get_selection = nautilus_places_view_get_selection;
+ iface->set_selection = nautilus_places_view_set_selection;
+ iface->get_search_query = nautilus_places_view_get_search_query;
+ iface->set_search_query = nautilus_places_view_set_search_query;
+ iface->get_toolbar_menu_sections = nautilus_places_view_get_toolbar_menu_sections;
+ iface->is_loading = nautilus_places_view_is_loading;
+ iface->is_searching = nautilus_places_view_is_searching;
}
static void
nautilus_places_view_class_init (NautilusPlacesViewClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = nautilus_places_view_finalize;
- object_class->get_property = nautilus_places_view_get_property;
- object_class->set_property = nautilus_places_view_set_property;
+ object_class->finalize = nautilus_places_view_finalize;
+ object_class->get_property = nautilus_places_view_get_property;
+ object_class->set_property = nautilus_places_view_set_property;
- g_object_class_override_property (object_class, PROP_ICON, "icon");
- g_object_class_override_property (object_class, PROP_IS_LOADING, "is-loading");
- g_object_class_override_property (object_class, PROP_IS_SEARCHING, "is-searching");
- g_object_class_override_property (object_class, PROP_LOCATION, "location");
- g_object_class_override_property (object_class, PROP_SEARCH_QUERY, "search-query");
+ g_object_class_override_property (object_class, PROP_ICON, "icon");
+ g_object_class_override_property (object_class, PROP_IS_LOADING, "is-loading");
+ g_object_class_override_property (object_class, PROP_IS_SEARCHING, "is-searching");
+ g_object_class_override_property (object_class, PROP_LOCATION, "location");
+ g_object_class_override_property (object_class, PROP_SEARCH_QUERY, "search-query");
}
static void
nautilus_places_view_init (NautilusPlacesView *self)
{
- NautilusPlacesViewPrivate *priv;
-
- priv = nautilus_places_view_get_instance_private (self);
-
- /* Icon */
- priv->icon = g_themed_icon_new_with_default_fallbacks ("view-list-symbolic");
-
- /* Location */
- priv->location = g_file_new_for_uri ("other-locations:///");
-
- /* Places view */
- priv->places_view = nautilus_gtk_places_view_new ();
- nautilus_gtk_places_view_set_open_flags (NAUTILUS_GTK_PLACES_VIEW (priv->places_view),
- GTK_PLACES_OPEN_NEW_TAB | GTK_PLACES_OPEN_NEW_WINDOW | GTK_PLACES_OPEN_NORMAL);
- gtk_widget_set_hexpand (priv->places_view, TRUE);
- gtk_widget_set_vexpand (priv->places_view, TRUE);
- gtk_widget_show (priv->places_view);
- gtk_container_add (GTK_CONTAINER (self), priv->places_view);
-
- g_signal_connect_swapped (priv->places_view,
- "notify::loading",
- G_CALLBACK (loading_cb),
- self);
-
- g_signal_connect_swapped (priv->places_view,
- "open-location",
- G_CALLBACK (open_location_cb),
- self);
-
- g_signal_connect_swapped (priv->places_view,
- "show-error-message",
- G_CALLBACK (show_error_message_cb),
- self);
-
- /* Toolbar menu */
- priv->toolbar_menu_sections = g_new0 (NautilusToolbarMenuSections, 1);
- priv->toolbar_menu_sections->supports_undo_redo = FALSE;
+ NautilusPlacesViewPrivate *priv;
+
+ priv = nautilus_places_view_get_instance_private (self);
+
+ /* Icon */
+ priv->icon = g_themed_icon_new_with_default_fallbacks ("view-list-symbolic");
+
+ /* Location */
+ priv->location = g_file_new_for_uri ("other-locations:///");
+
+ /* Places view */
+ priv->places_view = nautilus_gtk_places_view_new ();
+ nautilus_gtk_places_view_set_open_flags (NAUTILUS_GTK_PLACES_VIEW (priv->places_view),
+ GTK_PLACES_OPEN_NEW_TAB | GTK_PLACES_OPEN_NEW_WINDOW | GTK_PLACES_OPEN_NORMAL);
+ gtk_widget_set_hexpand (priv->places_view, TRUE);
+ gtk_widget_set_vexpand (priv->places_view, TRUE);
+ gtk_widget_show (priv->places_view);
+ gtk_container_add (GTK_CONTAINER (self), priv->places_view);
+
+ g_signal_connect_swapped (priv->places_view,
+ "notify::loading",
+ G_CALLBACK (loading_cb),
+ self);
+
+ g_signal_connect_swapped (priv->places_view,
+ "open-location",
+ G_CALLBACK (open_location_cb),
+ self);
+
+ g_signal_connect_swapped (priv->places_view,
+ "show-error-message",
+ G_CALLBACK (show_error_message_cb),
+ self);
+
+ /* Toolbar menu */
+ priv->toolbar_menu_sections = g_new0 (NautilusToolbarMenuSections, 1);
+ priv->toolbar_menu_sections->supports_undo_redo = FALSE;
}
NautilusPlacesView *
nautilus_places_view_new (void)
{
- NautilusPlacesView *view;
+ NautilusPlacesView *view;
- view = g_object_new (NAUTILUS_TYPE_PLACES_VIEW, NULL);
- if (g_object_is_floating (view)) {
- g_object_ref_sink (view);
- }
+ view = g_object_new (NAUTILUS_TYPE_PLACES_VIEW, NULL);
+ if (g_object_is_floating (view))
+ {
+ g_object_ref_sink (view);
+ }
- return view;
+ return view;
}
diff --git a/src/nautilus-preferences-window.c b/src/nautilus-preferences-window.c
index 875b23397..2df9e4afe 100644
--- a/src/nautilus-preferences-window.c
+++ b/src/nautilus-preferences-window.c
@@ -1,26 +1,25 @@
-
/* nautilus-preferences-window.c - Functions to create and show the nautilus
- preference window.
-
- Copyright (C) 2002 Jan Arne Petersen
- Copyright (C) 2016 Carlos Soriano <csoriano@gnome.com>
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Jan Arne Petersen <jpetersen@uni-bonn.de>
-*/
+ * preference window.
+ *
+ * Copyright (C) 2002 Jan Arne Petersen
+ * Copyright (C) 2016 Carlos Soriano <csoriano@gnome.com>
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Jan Arne Petersen <jpetersen@uni-bonn.de>
+ */
#include <config.h>
@@ -43,466 +42,537 @@
/* string enum preferences */
#define NAUTILUS_PREFERENCES_DIALOG_DEFAULT_VIEW_WIDGET "default_view_combobox"
#define NAUTILUS_PREFERENCES_DIALOG_PREVIEW_FILES_WIDGET \
- "preview_image_combobox"
+ "preview_image_combobox"
#define NAUTILUS_PREFERENCES_DIALOG_PREVIEW_FOLDER_WIDGET \
- "preview_folder_combobox"
+ "preview_folder_combobox"
/* bool preferences */
#define NAUTILUS_PREFERENCES_DIALOG_FOLDERS_FIRST_WIDGET \
- "sort_folders_first_checkbutton"
+ "sort_folders_first_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_DELETE_PERMANENTLY_WIDGET \
- "show_delete_permanently_checkbutton"
+ "show_delete_permanently_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_CREATE_LINK_WIDGET \
- "show_create_link_checkbutton"
+ "show_create_link_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_LIST_VIEW_USE_TREE_WIDGET \
- "use_tree_view_checkbutton"
+ "use_tree_view_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_TRASH_CONFIRM_WIDGET \
- "trash_confirm_checkbutton"
+ "trash_confirm_checkbutton"
#define NAUTILUS_PREFERENCES_DIALOG_AUTOMATIC_DECOMPRESSION_WIDGET \
- "automatic_decompression_checkbutton"
+ "automatic_decompression_checkbutton"
/* int enums */
#define NAUTILUS_PREFERENCES_DIALOG_THUMBNAIL_LIMIT_WIDGET \
- "preview_image_size_combobox"
+ "preview_image_size_combobox"
-static const char *const speed_tradeoff_values[] = {"local-only", "always", "never",
- NULL};
+static const char * const speed_tradeoff_values[] =
+{
+ "local-only", "always", "never",
+ NULL
+};
-static const char *const click_behavior_components[] = {
- "single_click_radiobutton", "double_click_radiobutton", NULL};
+static const char * const click_behavior_components[] =
+{
+ "single_click_radiobutton", "double_click_radiobutton", NULL
+};
-static const char *const click_behavior_values[] = {"single", "double", NULL};
+static const char * const click_behavior_values[] = {"single", "double", NULL};
-static const char *const executable_text_components[] = {
+static const char * const executable_text_components[] =
+{
"scripts_execute_radiobutton", "scripts_view_radiobutton",
- "scripts_confirm_radiobutton", NULL};
-
-static const char *const executable_text_values[] = {"launch", "display", "ask",
- NULL};
-
-static const char *const recursive_search_components[] = {
- "search_recursive_only_this_computer_radiobutton", "search_recursive_all_locations_radiobutton", "search_recursive_never_radiobutton", NULL};
-
-static const char *const thumbnails_components[] = {
- "thumbnails_only_this_computer_radiobutton", "thumbnails_all_files_radiobutton", "thumbnails_never_radiobutton", NULL};
-
-static const char *const count_components[] = {
- "count_only_this_computer_radiobutton", "count_all_files_radiobutton", "count_never_radiobutton", NULL};
-
-static const guint64 thumbnail_limit_values[] = {
- 102400, 512000, 1048576, 3145728, 5242880,
- 10485760, 104857600, 1073741824, 2147483648U, 4294967295U};
-
-static const char *const icon_captions_components[] = {
- "captions_0_combobox", "captions_1_combobox", "captions_2_combobox", NULL};
+ "scripts_confirm_radiobutton", NULL
+};
+
+static const char * const executable_text_values[] =
+{
+ "launch", "display", "ask",
+ NULL
+};
+
+static const char * const recursive_search_components[] =
+{
+ "search_recursive_only_this_computer_radiobutton", "search_recursive_all_locations_radiobutton", "search_recursive_never_radiobutton", NULL
+};
+
+static const char * const thumbnails_components[] =
+{
+ "thumbnails_only_this_computer_radiobutton", "thumbnails_all_files_radiobutton", "thumbnails_never_radiobutton", NULL
+};
+
+static const char * const count_components[] =
+{
+ "count_only_this_computer_radiobutton", "count_all_files_radiobutton", "count_never_radiobutton", NULL
+};
+
+static const guint64 thumbnail_limit_values[] =
+{
+ 102400, 512000, 1048576, 3145728, 5242880,
+ 10485760, 104857600, 1073741824, 2147483648U, 4294967295U
+};
+
+static const char * const icon_captions_components[] =
+{
+ "captions_0_combobox", "captions_1_combobox", "captions_2_combobox", NULL
+};
static GtkWidget *preferences_window = NULL;
static void columns_changed_callback(NautilusColumnChooser *chooser,
- gpointer callback_data) {
- char **visible_columns;
- char **column_order;
-
- nautilus_column_chooser_get_settings(NAUTILUS_COLUMN_CHOOSER(chooser),
- &visible_columns, &column_order);
-
- g_settings_set_strv(nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS,
- (const char *const *)visible_columns);
- g_settings_set_strv(nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER,
- (const char *const *)column_order);
-
- g_strfreev(visible_columns);
- g_strfreev(column_order);
+ gpointer callback_data)
+{
+ char **visible_columns;
+ char **column_order;
+
+ nautilus_column_chooser_get_settings (NAUTILUS_COLUMN_CHOOSER (chooser),
+ &visible_columns, &column_order);
+
+ g_settings_set_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS,
+ (const char * const *) visible_columns);
+ g_settings_set_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER,
+ (const char * const *) column_order);
+
+ g_strfreev (visible_columns);
+ g_strfreev (column_order);
}
-static void free_column_names_array(GPtrArray *column_names) {
- g_ptr_array_foreach(column_names, (GFunc)g_free, NULL);
- g_ptr_array_free(column_names, TRUE);
+static void free_column_names_array(GPtrArray *column_names)
+{
+ g_ptr_array_foreach (column_names, (GFunc) g_free, NULL);
+ g_ptr_array_free (column_names, TRUE);
}
static void create_icon_caption_combo_box_items(GtkComboBoxText *combo_box,
- GList *columns) {
- GList *l;
- GPtrArray *column_names;
+ GList *columns)
+{
+ GList *l;
+ GPtrArray *column_names;
- column_names = g_ptr_array_new();
+ column_names = g_ptr_array_new ();
- /* Translators: this is referred to captions under icons. */
- gtk_combo_box_text_append_text(combo_box, _("None"));
- g_ptr_array_add(column_names, g_strdup("none"));
+ /* Translators: this is referred to captions under icons. */
+ gtk_combo_box_text_append_text (combo_box, _("None"));
+ g_ptr_array_add (column_names, g_strdup ("none"));
- for (l = columns; l != NULL; l = l->next) {
- NautilusColumn *column;
- char *name;
- char *label;
+ for (l = columns; l != NULL; l = l->next)
+ {
+ NautilusColumn *column;
+ char *name;
+ char *label;
- column = NAUTILUS_COLUMN(l->data);
+ column = NAUTILUS_COLUMN (l->data);
- g_object_get(G_OBJECT(column), "name", &name, "label", &label, NULL);
+ g_object_get (G_OBJECT (column), "name", &name, "label", &label, NULL);
- /* Don't show name here, it doesn't make sense */
- if (!strcmp(name, "name")) {
- g_free(name);
- g_free(label);
- continue;
- }
+ /* Don't show name here, it doesn't make sense */
+ if (!strcmp (name, "name"))
+ {
+ g_free (name);
+ g_free (label);
+ continue;
+ }
- gtk_combo_box_text_append_text(combo_box, label);
- g_ptr_array_add(column_names, name);
+ gtk_combo_box_text_append_text (combo_box, label);
+ g_ptr_array_add (column_names, name);
- g_free(label);
- }
- g_object_set_data_full(G_OBJECT(combo_box), "column_names", column_names,
- (GDestroyNotify)free_column_names_array);
+ g_free (label);
+ }
+ g_object_set_data_full (G_OBJECT (combo_box), "column_names", column_names,
+ (GDestroyNotify) free_column_names_array);
}
static void icon_captions_changed_callback(GtkComboBox *combo_box,
- gpointer user_data) {
- GPtrArray *captions;
- GtkBuilder *builder;
- int i;
+ gpointer user_data)
+{
+ GPtrArray *captions;
+ GtkBuilder *builder;
+ int i;
- builder = GTK_BUILDER(user_data);
+ builder = GTK_BUILDER (user_data);
- captions = g_ptr_array_new();
+ captions = g_ptr_array_new ();
- for (i = 0; icon_captions_components[i] != NULL; i++) {
- GtkWidget *combo_box;
- int active;
- GPtrArray *column_names;
- char *name;
+ for (i = 0; icon_captions_components[i] != NULL; i++)
+ {
+ GtkWidget *combo_box;
+ int active;
+ GPtrArray *column_names;
+ char *name;
- combo_box = GTK_WIDGET(
- gtk_builder_get_object(builder, icon_captions_components[i]));
- active = gtk_combo_box_get_active(GTK_COMBO_BOX(combo_box));
+ combo_box = GTK_WIDGET (
+ gtk_builder_get_object (builder, icon_captions_components[i]));
+ active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box));
- column_names = g_object_get_data(G_OBJECT(combo_box), "column_names");
+ column_names = g_object_get_data (G_OBJECT (combo_box), "column_names");
- name = g_ptr_array_index(column_names, active);
- g_ptr_array_add(captions, name);
- }
- g_ptr_array_add(captions, NULL);
+ name = g_ptr_array_index (column_names, active);
+ g_ptr_array_add (captions, name);
+ }
+ g_ptr_array_add (captions, NULL);
- g_settings_set_strv(nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
- (const char **)captions->pdata);
- g_ptr_array_free(captions, TRUE);
+ g_settings_set_strv (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
+ (const char **) captions->pdata);
+ g_ptr_array_free (captions, TRUE);
}
static void update_caption_combo_box(GtkBuilder *builder,
const char *combo_box_name,
- const char *name) {
- GtkWidget *combo_box;
- int i;
- GPtrArray *column_names;
+ const char *name)
+{
+ GtkWidget *combo_box;
+ int i;
+ GPtrArray *column_names;
- combo_box = GTK_WIDGET(gtk_builder_get_object(builder, combo_box_name));
+ combo_box = GTK_WIDGET (gtk_builder_get_object (builder, combo_box_name));
- g_signal_handlers_block_by_func(
- combo_box, G_CALLBACK(icon_captions_changed_callback), builder);
+ g_signal_handlers_block_by_func (
+ combo_box, G_CALLBACK (icon_captions_changed_callback), builder);
- column_names = g_object_get_data(G_OBJECT(combo_box), "column_names");
+ column_names = g_object_get_data (G_OBJECT (combo_box), "column_names");
- for (i = 0; i < column_names->len; ++i) {
- if (!strcmp(name, g_ptr_array_index(column_names, i))) {
- gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), i);
- break;
+ for (i = 0; i < column_names->len; ++i)
+ {
+ if (!strcmp (name, g_ptr_array_index (column_names, i)))
+ {
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), i);
+ break;
+ }
}
- }
- g_signal_handlers_unblock_by_func(
- combo_box, G_CALLBACK(icon_captions_changed_callback), builder);
+ g_signal_handlers_unblock_by_func (
+ combo_box, G_CALLBACK (icon_captions_changed_callback), builder);
}
-static void update_icon_captions_from_settings(GtkBuilder *builder) {
- char **captions;
- int i, j;
-
- captions = g_settings_get_strv(nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
- if (captions == NULL)
- return;
-
- for (i = 0, j = 0; icon_captions_components[i] != NULL; i++) {
- char *data;
+static void update_icon_captions_from_settings(GtkBuilder *builder)
+{
+ char **captions;
+ int i, j;
- if (captions[j]) {
- data = captions[j];
- ++j;
- } else {
- data = "none";
+ captions = g_settings_get_strv (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
+ if (captions == NULL)
+ {
+ return;
}
- update_caption_combo_box(builder, icon_captions_components[i], data);
- }
+ for (i = 0, j = 0; icon_captions_components[i] != NULL; i++)
+ {
+ char *data;
+
+ if (captions[j])
+ {
+ data = captions[j];
+ ++j;
+ }
+ else
+ {
+ data = "none";
+ }
+
+ update_caption_combo_box (builder, icon_captions_components[i], data);
+ }
- g_strfreev(captions);
+ g_strfreev (captions);
}
static void
-nautilus_preferences_window_setup_icon_caption_page(GtkBuilder *builder) {
- GList *columns;
- int i;
- gboolean writable;
+nautilus_preferences_window_setup_icon_caption_page (GtkBuilder *builder)
+{
+ GList *columns;
+ int i;
+ gboolean writable;
- writable = g_settings_is_writable(nautilus_icon_view_preferences,
- NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
+ writable = g_settings_is_writable (nautilus_icon_view_preferences,
+ NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS);
- columns = nautilus_get_common_columns();
+ columns = nautilus_get_common_columns ();
- for (i = 0; icon_captions_components[i] != NULL; i++) {
- GtkWidget *combo_box;
+ for (i = 0; icon_captions_components[i] != NULL; i++)
+ {
+ GtkWidget *combo_box;
- combo_box = GTK_WIDGET(
- gtk_builder_get_object(builder, icon_captions_components[i]));
+ combo_box = GTK_WIDGET (
+ gtk_builder_get_object (builder, icon_captions_components[i]));
- create_icon_caption_combo_box_items(GTK_COMBO_BOX_TEXT(combo_box), columns);
- gtk_widget_set_sensitive(combo_box, writable);
+ create_icon_caption_combo_box_items (GTK_COMBO_BOX_TEXT (combo_box), columns);
+ gtk_widget_set_sensitive (combo_box, writable);
- g_signal_connect_data(
- combo_box, "changed", G_CALLBACK(icon_captions_changed_callback),
- g_object_ref(builder), (GClosureNotify)g_object_unref, 0);
- }
+ g_signal_connect_data (
+ combo_box, "changed", G_CALLBACK (icon_captions_changed_callback),
+ g_object_ref (builder), (GClosureNotify) g_object_unref, 0);
+ }
- nautilus_column_list_free(columns);
+ nautilus_column_list_free (columns);
- update_icon_captions_from_settings(builder);
+ update_icon_captions_from_settings (builder);
}
-static void set_columns_from_settings(NautilusColumnChooser *chooser) {
- char **visible_columns;
- char **column_order;
+static void set_columns_from_settings(NautilusColumnChooser *chooser)
+{
+ char **visible_columns;
+ char **column_order;
- visible_columns = g_settings_get_strv(
- nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
- column_order =
- g_settings_get_strv(nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
+ visible_columns = g_settings_get_strv (
+ nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
+ column_order =
+ g_settings_get_strv (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
- nautilus_column_chooser_set_settings(NAUTILUS_COLUMN_CHOOSER(chooser),
- visible_columns, column_order);
+ nautilus_column_chooser_set_settings (NAUTILUS_COLUMN_CHOOSER (chooser),
+ visible_columns, column_order);
- g_strfreev(visible_columns);
- g_strfreev(column_order);
+ g_strfreev (visible_columns);
+ g_strfreev (column_order);
}
static void use_default_callback(NautilusColumnChooser *chooser,
- gpointer user_data) {
- g_settings_reset(nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
- g_settings_reset(nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
- set_columns_from_settings(chooser);
+ gpointer user_data)
+{
+ g_settings_reset (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS);
+ g_settings_reset (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER);
+ set_columns_from_settings (chooser);
}
static void
-nautilus_preferences_window_setup_list_column_page(GtkBuilder *builder) {
- GtkWidget *chooser;
- GtkWidget *box;
+nautilus_preferences_window_setup_list_column_page (GtkBuilder *builder)
+{
+ GtkWidget *chooser;
+ GtkWidget *box;
- chooser = nautilus_column_chooser_new(NULL);
- g_signal_connect(chooser, "changed", G_CALLBACK(columns_changed_callback),
- chooser);
- g_signal_connect(chooser, "use-default", G_CALLBACK(use_default_callback),
- chooser);
+ chooser = nautilus_column_chooser_new (NULL);
+ g_signal_connect (chooser, "changed", G_CALLBACK (columns_changed_callback),
+ chooser);
+ g_signal_connect (chooser, "use-default", G_CALLBACK (use_default_callback),
+ chooser);
- set_columns_from_settings(NAUTILUS_COLUMN_CHOOSER(chooser));
+ set_columns_from_settings (NAUTILUS_COLUMN_CHOOSER (chooser));
- gtk_widget_show(chooser);
- box = GTK_WIDGET(gtk_builder_get_object(builder, "list_columns_vbox"));
+ gtk_widget_show (chooser);
+ box = GTK_WIDGET (gtk_builder_get_object (builder, "list_columns_vbox"));
- gtk_box_pack_start(GTK_BOX(box), chooser, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), chooser, TRUE, TRUE, 0);
}
-static void bind_builder_bool(GtkBuilder *builder, GSettings *settings,
- const char *widget_name, const char *prefs) {
- g_settings_bind(settings, prefs, gtk_builder_get_object(builder, widget_name),
- "active", G_SETTINGS_BIND_DEFAULT);
+static void bind_builder_bool(GtkBuilder *builder,
+ GSettings *settings,
+ const char *widget_name,
+ const char *prefs)
+{
+ g_settings_bind (settings, prefs, gtk_builder_get_object (builder, widget_name),
+ "active", G_SETTINGS_BIND_DEFAULT);
}
-typedef struct {
- const guint64 *values;
- int n_values;
+typedef struct
+{
+ const guint64 *values;
+ int n_values;
} UIntEnumBinding;
-static gboolean uint_enum_get_mapping(GValue *value, GVariant *variant,
- gpointer user_data) {
- UIntEnumBinding *binding = user_data;
- guint64 v;
- int i;
-
- v = g_variant_get_uint64(variant);
- for (i = 0; i < binding->n_values; i++) {
- if (binding->values[i] >= v) {
- g_value_set_int(value, i);
- return TRUE;
+static gboolean uint_enum_get_mapping(GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ UIntEnumBinding *binding = user_data;
+ guint64 v;
+ int i;
+
+ v = g_variant_get_uint64 (variant);
+ for (i = 0; i < binding->n_values; i++)
+ {
+ if (binding->values[i] >= v)
+ {
+ g_value_set_int (value, i);
+ return TRUE;
+ }
}
- }
- return FALSE;
+ return FALSE;
}
-static GVariant *uint_enum_set_mapping(const GValue *value,
+static GVariant *uint_enum_set_mapping(const GValue *value,
const GVariantType *expected_type,
- gpointer user_data) {
- UIntEnumBinding *binding = user_data;
+ gpointer user_data)
+{
+ UIntEnumBinding *binding = user_data;
- return g_variant_new_uint64(binding->values[g_value_get_int(value)]);
+ return g_variant_new_uint64 (binding->values[g_value_get_int (value)]);
}
-static void bind_builder_uint_enum(GtkBuilder *builder, GSettings *settings,
- const char *widget_name, const char *prefs,
- const guint64 *values, int n_values) {
- UIntEnumBinding *binding;
-
- binding = g_new(UIntEnumBinding, 1);
- binding->values = values;
- binding->n_values = n_values;
-
- g_settings_bind_with_mapping(
- settings, prefs, gtk_builder_get_object(builder, widget_name), "active",
- G_SETTINGS_BIND_DEFAULT, uint_enum_get_mapping, uint_enum_set_mapping,
- binding, g_free);
+static void bind_builder_uint_enum(GtkBuilder *builder,
+ GSettings *settings,
+ const char *widget_name,
+ const char *prefs,
+ const guint64 *values,
+ int n_values)
+{
+ UIntEnumBinding *binding;
+
+ binding = g_new (UIntEnumBinding, 1);
+ binding->values = values;
+ binding->n_values = n_values;
+
+ g_settings_bind_with_mapping (
+ settings, prefs, gtk_builder_get_object (builder, widget_name), "active",
+ G_SETTINGS_BIND_DEFAULT, uint_enum_get_mapping, uint_enum_set_mapping,
+ binding, g_free);
}
-static GVariant *radio_mapping_set(const GValue *gvalue,
+static GVariant *radio_mapping_set(const GValue *gvalue,
const GVariantType *expected_type,
- gpointer user_data) {
- const gchar *widget_value = user_data;
- GVariant *retval = NULL;
-
- if (g_value_get_boolean(gvalue)) {
- retval = g_variant_new_string(widget_value);
- }
+ gpointer user_data)
+{
+ const gchar *widget_value = user_data;
+ GVariant *retval = NULL;
+
+ if (g_value_get_boolean (gvalue))
+ {
+ retval = g_variant_new_string (widget_value);
+ }
- return retval;
+ return retval;
}
-static gboolean radio_mapping_get(GValue *gvalue, GVariant *variant,
- gpointer user_data) {
- const gchar *widget_value = user_data;
- const gchar *value;
+static gboolean radio_mapping_get(GValue *gvalue,
+ GVariant *variant,
+ gpointer user_data)
+{
+ const gchar *widget_value = user_data;
+ const gchar *value;
- value = g_variant_get_string(variant, NULL);
+ value = g_variant_get_string (variant, NULL);
- if (g_strcmp0(value, widget_value) == 0) {
- g_value_set_boolean(gvalue, TRUE);
- } else {
- g_value_set_boolean(gvalue, FALSE);
- }
+ if (g_strcmp0 (value, widget_value) == 0)
+ {
+ g_value_set_boolean (gvalue, TRUE);
+ }
+ else
+ {
+ g_value_set_boolean (gvalue, FALSE);
+ }
- return TRUE;
+ return TRUE;
}
-static void bind_builder_radio(GtkBuilder *builder, GSettings *settings,
- const char **widget_names, const char *prefs,
- const char **values) {
- GtkWidget *button;
- int i;
-
- for (i = 0; widget_names[i] != NULL; i++) {
- button = GTK_WIDGET(gtk_builder_get_object(builder, widget_names[i]));
-
- g_settings_bind_with_mapping(settings, prefs, button, "active",
- G_SETTINGS_BIND_DEFAULT, radio_mapping_get,
- radio_mapping_set, (gpointer)values[i], NULL);
- }
+static void bind_builder_radio(GtkBuilder *builder,
+ GSettings *settings,
+ const char **widget_names,
+ const char *prefs,
+ const char **values)
+{
+ GtkWidget *button;
+ int i;
+
+ for (i = 0; widget_names[i] != NULL; i++)
+ {
+ button = GTK_WIDGET (gtk_builder_get_object (builder, widget_names[i]));
+
+ g_settings_bind_with_mapping (settings, prefs, button, "active",
+ G_SETTINGS_BIND_DEFAULT, radio_mapping_get,
+ radio_mapping_set, (gpointer) values[i], NULL);
+ }
}
-static void set_gtk_filechooser_sort_first(GObject *object, GParamSpec *pspec) {
- g_settings_set_boolean(
- gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
- gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object)));
+static void set_gtk_filechooser_sort_first(GObject *object,
+ GParamSpec *pspec)
+{
+ g_settings_set_boolean (
+ gtk_filechooser_preferences, NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object)));
}
static void nautilus_preferences_window_setup(GtkBuilder *builder,
- GtkWindow *parent_window) {
- GtkWidget *window;
-
- /* setup preferences */
- bind_builder_bool(builder, nautilus_preferences,
- NAUTILUS_PREFERENCES_DIALOG_FOLDERS_FIRST_WIDGET,
- NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
- g_signal_connect(
- gtk_builder_get_object(builder,
- NAUTILUS_PREFERENCES_DIALOG_FOLDERS_FIRST_WIDGET),
- "notify::active", G_CALLBACK(set_gtk_filechooser_sort_first), NULL);
-
- bind_builder_bool(builder, nautilus_preferences,
- NAUTILUS_PREFERENCES_DIALOG_TRASH_CONFIRM_WIDGET,
- NAUTILUS_PREFERENCES_CONFIRM_TRASH);
- bind_builder_bool (builder, nautilus_preferences,
- NAUTILUS_PREFERENCES_DIALOG_AUTOMATIC_DECOMPRESSION_WIDGET,
- NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
- bind_builder_bool(builder, nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_DIALOG_LIST_VIEW_USE_TREE_WIDGET,
- NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
- bind_builder_bool(builder, nautilus_preferences,
- NAUTILUS_PREFERENCES_DIALOG_CREATE_LINK_WIDGET,
- NAUTILUS_PREFERENCES_SHOW_CREATE_LINK);
- bind_builder_bool(builder, nautilus_preferences,
- NAUTILUS_PREFERENCES_DIALOG_DELETE_PERMANENTLY_WIDGET,
- NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY);
-
- bind_builder_radio(
- builder, nautilus_preferences, (const char **)click_behavior_components,
- NAUTILUS_PREFERENCES_CLICK_POLICY, (const char **)click_behavior_values);
- bind_builder_radio(builder, nautilus_preferences,
- (const char **)executable_text_components,
- NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
- (const char **)executable_text_values);
- bind_builder_radio(builder, nautilus_preferences,
- (const char **)recursive_search_components,
- NAUTILUS_PREFERENCES_RECURSIVE_SEARCH,
- (const char **)speed_tradeoff_values);
- bind_builder_radio(builder, nautilus_preferences,
- (const char **)thumbnails_components,
- NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS,
- (const char **)speed_tradeoff_values);
- bind_builder_radio(builder, nautilus_preferences,
- (const char **)count_components,
- NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
- (const char **)speed_tradeoff_values);
-
- bind_builder_uint_enum(builder, nautilus_preferences,
- NAUTILUS_PREFERENCES_DIALOG_THUMBNAIL_LIMIT_WIDGET,
- NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
- thumbnail_limit_values,
- G_N_ELEMENTS(thumbnail_limit_values));
-
- nautilus_preferences_window_setup_icon_caption_page(builder);
- nautilus_preferences_window_setup_list_column_page(builder);
-
- /* UI callbacks */
- window = GTK_WIDGET(gtk_builder_get_object(builder, "preferences_window"));
- preferences_window = window;
-
- gtk_window_set_icon_name(GTK_WINDOW(preferences_window), "system-file-manager");
-
- g_object_add_weak_pointer(G_OBJECT(window), (gpointer *)&preferences_window);
-
- gtk_window_set_transient_for(GTK_WINDOW(preferences_window), parent_window);
-
- gtk_widget_show(preferences_window);
+ GtkWindow *parent_window)
+{
+ GtkWidget *window;
+
+ /* setup preferences */
+ bind_builder_bool (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_FOLDERS_FIRST_WIDGET,
+ NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST);
+ g_signal_connect (
+ gtk_builder_get_object (builder,
+ NAUTILUS_PREFERENCES_DIALOG_FOLDERS_FIRST_WIDGET),
+ "notify::active", G_CALLBACK (set_gtk_filechooser_sort_first), NULL);
+
+ bind_builder_bool (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_TRASH_CONFIRM_WIDGET,
+ NAUTILUS_PREFERENCES_CONFIRM_TRASH);
+ bind_builder_bool (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_AUTOMATIC_DECOMPRESSION_WIDGET,
+ NAUTILUS_PREFERENCES_AUTOMATIC_DECOMPRESSION);
+ bind_builder_bool (builder, nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_LIST_VIEW_USE_TREE_WIDGET,
+ NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
+ bind_builder_bool (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_CREATE_LINK_WIDGET,
+ NAUTILUS_PREFERENCES_SHOW_CREATE_LINK);
+ bind_builder_bool (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_DELETE_PERMANENTLY_WIDGET,
+ NAUTILUS_PREFERENCES_SHOW_DELETE_PERMANENTLY);
+
+ bind_builder_radio (
+ builder, nautilus_preferences, (const char **) click_behavior_components,
+ NAUTILUS_PREFERENCES_CLICK_POLICY, (const char **) click_behavior_values);
+ bind_builder_radio (builder, nautilus_preferences,
+ (const char **) executable_text_components,
+ NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
+ (const char **) executable_text_values);
+ bind_builder_radio (builder, nautilus_preferences,
+ (const char **) recursive_search_components,
+ NAUTILUS_PREFERENCES_RECURSIVE_SEARCH,
+ (const char **) speed_tradeoff_values);
+ bind_builder_radio (builder, nautilus_preferences,
+ (const char **) thumbnails_components,
+ NAUTILUS_PREFERENCES_SHOW_FILE_THUMBNAILS,
+ (const char **) speed_tradeoff_values);
+ bind_builder_radio (builder, nautilus_preferences,
+ (const char **) count_components,
+ NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
+ (const char **) speed_tradeoff_values);
+
+ bind_builder_uint_enum (builder, nautilus_preferences,
+ NAUTILUS_PREFERENCES_DIALOG_THUMBNAIL_LIMIT_WIDGET,
+ NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
+ thumbnail_limit_values,
+ G_N_ELEMENTS (thumbnail_limit_values));
+
+ nautilus_preferences_window_setup_icon_caption_page (builder);
+ nautilus_preferences_window_setup_list_column_page (builder);
+
+ /* UI callbacks */
+ window = GTK_WIDGET (gtk_builder_get_object (builder, "preferences_window"));
+ preferences_window = window;
+
+ gtk_window_set_icon_name (GTK_WINDOW (preferences_window), "system-file-manager");
+
+ g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &preferences_window);
+
+ gtk_window_set_transient_for (GTK_WINDOW (preferences_window), parent_window);
+
+ gtk_widget_show (preferences_window);
}
-void nautilus_preferences_window_show(GtkWindow *window) {
- GtkBuilder *builder;
+void nautilus_preferences_window_show(GtkWindow *window)
+{
+ GtkBuilder *builder;
- if (preferences_window != NULL) {
- gtk_window_present(GTK_WINDOW(preferences_window));
- return;
- }
+ if (preferences_window != NULL)
+ {
+ gtk_window_present (GTK_WINDOW (preferences_window));
+ return;
+ }
- builder = gtk_builder_new();
+ builder = gtk_builder_new ();
- gtk_builder_add_from_resource(
- builder, "/org/gnome/nautilus/ui/nautilus-preferences-window.ui", NULL);
+ gtk_builder_add_from_resource (
+ builder, "/org/gnome/nautilus/ui/nautilus-preferences-window.ui", NULL);
- nautilus_preferences_window_setup(builder, window);
+ nautilus_preferences_window_setup (builder, window);
- g_object_unref(builder);
+ g_object_unref (builder);
}
diff --git a/src/nautilus-previewer.c b/src/nautilus-previewer.c
index 272abed70..17e666d89 100644
--- a/src/nautilus-previewer.c
+++ b/src/nautilus-previewer.c
@@ -34,80 +34,82 @@
#define PREVIEWER_DBUS_PATH "/org/gnome/NautilusPreviewer"
static void
-previewer_show_file_ready_cb (GObject *source,
+previewer_show_file_ready_cb (GObject *source,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- GError *error = NULL;
+ GError *error = NULL;
- g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
- res, &error);
+ g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
+ res, &error);
- if (error != NULL) {
- DEBUG ("Unable to call ShowFile on NautilusPreviewer: %s",
- error->message);
- g_error_free (error);
- }
+ if (error != NULL)
+ {
+ DEBUG ("Unable to call ShowFile on NautilusPreviewer: %s",
+ error->message);
+ g_error_free (error);
+ }
}
static void
-previewer_close_ready_cb (GObject *source,
+previewer_close_ready_cb (GObject *source,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- GError *error = NULL;
+ GError *error = NULL;
- g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
- res, &error);
+ g_dbus_connection_call_finish (G_DBUS_CONNECTION (source),
+ res, &error);
- if (error != NULL) {
- DEBUG ("Unable to call Close on NautilusPreviewer: %s",
- error->message);
- g_error_free (error);
- }
+ if (error != NULL)
+ {
+ DEBUG ("Unable to call Close on NautilusPreviewer: %s",
+ error->message);
+ g_error_free (error);
+ }
}
void
nautilus_previewer_call_show_file (const gchar *uri,
- guint xid,
- gboolean close_if_already_visible)
+ guint xid,
+ gboolean close_if_already_visible)
{
- GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
- GVariant *variant;
-
- variant = g_variant_new ("(sib)",
- uri, xid, close_if_already_visible);
-
- g_dbus_connection_call (connection,
- PREVIEWER_DBUS_NAME,
- PREVIEWER_DBUS_PATH,
- PREVIEWER_DBUS_IFACE,
- "ShowFile",
- variant,
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- -1,
- NULL,
- previewer_show_file_ready_cb,
- NULL);
+ GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
+ GVariant *variant;
+
+ variant = g_variant_new ("(sib)",
+ uri, xid, close_if_already_visible);
+
+ g_dbus_connection_call (connection,
+ PREVIEWER_DBUS_NAME,
+ PREVIEWER_DBUS_PATH,
+ PREVIEWER_DBUS_IFACE,
+ "ShowFile",
+ variant,
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ previewer_show_file_ready_cb,
+ NULL);
}
void
nautilus_previewer_call_close (void)
{
- GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
-
- /* don't autostart the previewer if it's not running */
- g_dbus_connection_call (connection,
- PREVIEWER_DBUS_NAME,
- PREVIEWER_DBUS_PATH,
- PREVIEWER_DBUS_IFACE,
- "Close",
- NULL,
- NULL,
- G_DBUS_CALL_FLAGS_NO_AUTO_START,
- -1,
- NULL,
- previewer_close_ready_cb,
- NULL);
+ GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
+
+ /* don't autostart the previewer if it's not running */
+ g_dbus_connection_call (connection,
+ PREVIEWER_DBUS_NAME,
+ PREVIEWER_DBUS_PATH,
+ PREVIEWER_DBUS_IFACE,
+ "Close",
+ NULL,
+ NULL,
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1,
+ NULL,
+ previewer_close_ready_cb,
+ NULL);
}
diff --git a/src/nautilus-profile.c b/src/nautilus-profile.c
index 444fdc061..3f6c64059 100644
--- a/src/nautilus-profile.c
+++ b/src/nautilus-profile.c
@@ -38,26 +38,32 @@ _nautilus_profile_log (const char *func,
const char *format,
...)
{
- va_list args;
- char *str;
- char *formatted;
-
- if (format == NULL) {
- formatted = g_strdup ("");
- } else {
- va_start (args, format);
- formatted = g_strdup_vprintf (format, args);
- va_end (args);
- }
-
- if (func != NULL) {
- str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname(), func, note ? note : "", formatted);
- } else {
- str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname(), note ? note : "", formatted);
- }
-
- g_free (formatted);
-
- g_access (str, F_OK);
- g_free (str);
+ va_list args;
+ char *str;
+ char *formatted;
+
+ if (format == NULL)
+ {
+ formatted = g_strdup ("");
+ }
+ else
+ {
+ va_start (args, format);
+ formatted = g_strdup_vprintf (format, args);
+ va_end (args);
+ }
+
+ if (func != NULL)
+ {
+ str = g_strdup_printf ("MARK: %s %s: %s %s", g_get_prgname (), func, note ? note : "", formatted);
+ }
+ else
+ {
+ str = g_strdup_printf ("MARK: %s: %s %s", g_get_prgname (), note ? note : "", formatted);
+ }
+
+ g_free (formatted);
+
+ g_access (str, F_OK);
+ g_free (str);
}
diff --git a/src/nautilus-program-choosing.c b/src/nautilus-program-choosing.c
index 871ca7053..92c6ddcf7 100644
--- a/src/nautilus-program-choosing.c
+++ b/src/nautilus-program-choosing.c
@@ -1,25 +1,24 @@
-
/* nautilus-program-choosing.c - functions for selecting and activating
- programs for opening/viewing particular files.
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Author: John Sullivan <sullivan@eazel.com>
-*/
+ * programs for opening/viewing particular files.
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Author: John Sullivan <sullivan@eazel.com>
+ */
#include <config.h>
#include "nautilus-program-choosing.h"
@@ -39,364 +38,395 @@
#include <gdk/gdkx.h>
void
-nautilus_launch_application_for_mount (GAppInfo *app_info,
- GMount *mount,
- GtkWindow *parent_window)
+nautilus_launch_application_for_mount (GAppInfo *app_info,
+ GMount *mount,
+ GtkWindow *parent_window)
{
- GFile *root;
- NautilusFile *file;
- GList *files;
+ GFile *root;
+ NautilusFile *file;
+ GList *files;
- root = g_mount_get_root (mount);
- file = nautilus_file_get (root);
- g_object_unref (root);
+ root = g_mount_get_root (mount);
+ file = nautilus_file_get (root);
+ g_object_unref (root);
- files = g_list_append (NULL, file);
- nautilus_launch_application (app_info,
- files,
- parent_window);
+ files = g_list_append (NULL, file);
+ nautilus_launch_application (app_info,
+ files,
+ parent_window);
- g_list_free_full (files, (GDestroyNotify) nautilus_file_unref);
+ g_list_free_full (files, (GDestroyNotify) nautilus_file_unref);
}
/**
* nautilus_launch_application:
- *
+ *
* Fork off a process to launch an application with a given file as a
- * parameter. Provide a parent window for error dialogs.
- *
+ * parameter. Provide a parent window for error dialogs.
+ *
* @application: The application to be launched.
* @uris: The files whose locations should be passed as a parameter to the application.
* @parent_window: A window to use as the parent for any error dialogs.
*/
void
-nautilus_launch_application (GAppInfo *application,
- GList *files,
- GtkWindow *parent_window)
+nautilus_launch_application (GAppInfo *application,
+ GList *files,
+ GtkWindow *parent_window)
{
- GList *uris, *l;
-
- uris = NULL;
- for (l = files; l != NULL; l = l->next) {
- uris = g_list_prepend (uris, nautilus_file_get_activation_uri (l->data));
- }
- uris = g_list_reverse (uris);
- nautilus_launch_application_by_uri (application, uris,
- parent_window);
- g_list_free_full (uris, g_free);
+ GList *uris, *l;
+
+ uris = NULL;
+ for (l = files; l != NULL; l = l->next)
+ {
+ uris = g_list_prepend (uris, nautilus_file_get_activation_uri (l->data));
+ }
+ uris = g_list_reverse (uris);
+ nautilus_launch_application_by_uri (application, uris,
+ parent_window);
+ g_list_free_full (uris, g_free);
}
void
-nautilus_launch_application_by_uri (GAppInfo *application,
- GList *uris,
- GtkWindow *parent_window)
+nautilus_launch_application_by_uri (GAppInfo *application,
+ GList *uris,
+ GtkWindow *parent_window)
{
- char *uri;
- GList *locations, *l;
- GFile *location;
- NautilusFile *file;
- gboolean result;
- GError *error;
- GdkDisplay *display;
- GdkAppLaunchContext *launch_context;
- NautilusIconInfo *icon;
- int count, total;
-
- g_assert (uris != NULL);
-
- /* count the number of uris with local paths */
- count = 0;
- total = g_list_length (uris);
- locations = NULL;
- for (l = uris; l != NULL; l = l->next) {
- uri = l->data;
-
- location = g_file_new_for_uri (uri);
- if (g_file_is_native (location)) {
- count++;
- }
- locations = g_list_prepend (locations, location);
- }
- locations = g_list_reverse (locations);
-
- if (parent_window != NULL) {
- display = gtk_widget_get_display (GTK_WIDGET (parent_window));
- } else {
- display = gdk_display_get_default ();
- }
-
- launch_context = gdk_display_get_app_launch_context (display);
-
- if (parent_window != NULL) {
- gdk_app_launch_context_set_screen (launch_context,
- gtk_window_get_screen (parent_window));
- }
-
- file = nautilus_file_get_by_uri (uris->data);
- icon = nautilus_file_get_icon (file,
- 48, gtk_widget_get_scale_factor (GTK_WIDGET (parent_window)),
- 0);
- nautilus_file_unref (file);
- if (icon) {
- gdk_app_launch_context_set_icon_name (launch_context,
- nautilus_icon_info_get_used_name (icon));
- g_object_unref (icon);
- }
-
- error = NULL;
-
- if (count == total) {
- /* All files are local, so we can use g_app_info_launch () with
- * the file list we constructed before.
- */
- result = g_app_info_launch (application,
- locations,
- G_APP_LAUNCH_CONTEXT (launch_context),
- &error);
- } else {
- /* Some files are non local, better use g_app_info_launch_uris ().
- */
- result = g_app_info_launch_uris (application,
- uris,
- G_APP_LAUNCH_CONTEXT (launch_context),
- &error);
- }
-
- g_object_unref (launch_context);
-
- if (result) {
- for (l = uris; l != NULL; l = l->next) {
- file = nautilus_file_get_by_uri (l->data);
- nautilus_recent_add_file (file, application);
- nautilus_file_unref (file);
- }
- }
-
- g_list_free_full (locations, g_object_unref);
+ char *uri;
+ GList *locations, *l;
+ GFile *location;
+ NautilusFile *file;
+ gboolean result;
+ GError *error;
+ GdkDisplay *display;
+ GdkAppLaunchContext *launch_context;
+ NautilusIconInfo *icon;
+ int count, total;
+
+ g_assert (uris != NULL);
+
+ /* count the number of uris with local paths */
+ count = 0;
+ total = g_list_length (uris);
+ locations = NULL;
+ for (l = uris; l != NULL; l = l->next)
+ {
+ uri = l->data;
+
+ location = g_file_new_for_uri (uri);
+ if (g_file_is_native (location))
+ {
+ count++;
+ }
+ locations = g_list_prepend (locations, location);
+ }
+ locations = g_list_reverse (locations);
+
+ if (parent_window != NULL)
+ {
+ display = gtk_widget_get_display (GTK_WIDGET (parent_window));
+ }
+ else
+ {
+ display = gdk_display_get_default ();
+ }
+
+ launch_context = gdk_display_get_app_launch_context (display);
+
+ if (parent_window != NULL)
+ {
+ gdk_app_launch_context_set_screen (launch_context,
+ gtk_window_get_screen (parent_window));
+ }
+
+ file = nautilus_file_get_by_uri (uris->data);
+ icon = nautilus_file_get_icon (file,
+ 48, gtk_widget_get_scale_factor (GTK_WIDGET (parent_window)),
+ 0);
+ nautilus_file_unref (file);
+ if (icon)
+ {
+ gdk_app_launch_context_set_icon_name (launch_context,
+ nautilus_icon_info_get_used_name (icon));
+ g_object_unref (icon);
+ }
+
+ error = NULL;
+
+ if (count == total)
+ {
+ /* All files are local, so we can use g_app_info_launch () with
+ * the file list we constructed before.
+ */
+ result = g_app_info_launch (application,
+ locations,
+ G_APP_LAUNCH_CONTEXT (launch_context),
+ &error);
+ }
+ else
+ {
+ /* Some files are non local, better use g_app_info_launch_uris ().
+ */
+ result = g_app_info_launch_uris (application,
+ uris,
+ G_APP_LAUNCH_CONTEXT (launch_context),
+ &error);
+ }
+
+ g_object_unref (launch_context);
+
+ if (result)
+ {
+ for (l = uris; l != NULL; l = l->next)
+ {
+ file = nautilus_file_get_by_uri (l->data);
+ nautilus_recent_add_file (file, application);
+ nautilus_file_unref (file);
+ }
+ }
+
+ g_list_free_full (locations, g_object_unref);
}
static void
launch_application_from_command_internal (const gchar *full_command,
- GdkScreen *screen,
- gboolean use_terminal)
+ GdkScreen *screen,
+ gboolean use_terminal)
{
- GAppInfo *app;
- GdkAppLaunchContext *ctx;
- GdkDisplay *display;
-
- if (use_terminal) {
- eel_gnome_open_terminal_on_screen (full_command, screen);
- } else {
- app = g_app_info_create_from_commandline (full_command, NULL, 0, NULL);
-
- if (app != NULL) {
- display = gdk_screen_get_display (screen);
- ctx = gdk_display_get_app_launch_context (display);
- gdk_app_launch_context_set_screen (ctx, screen);
-
- g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), NULL);
-
- g_object_unref (app);
- g_object_unref (ctx);
- }
- }
-}
+ GAppInfo *app;
+ GdkAppLaunchContext *ctx;
+ GdkDisplay *display;
+
+ if (use_terminal)
+ {
+ eel_gnome_open_terminal_on_screen (full_command, screen);
+ }
+ else
+ {
+ app = g_app_info_create_from_commandline (full_command, NULL, 0, NULL);
+
+ if (app != NULL)
+ {
+ display = gdk_screen_get_display (screen);
+ ctx = gdk_display_get_app_launch_context (display);
+ gdk_app_launch_context_set_screen (ctx, screen);
+
+ g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), NULL);
+
+ g_object_unref (app);
+ g_object_unref (ctx);
+ }
+ }
+}
/**
* nautilus_launch_application_from_command:
- *
+ *
* Fork off a process to launch an application with a given uri as
* a parameter.
- *
+ *
* @command_string: The application to be launched, with any desired
* command-line options.
* @...: Passed as parameters to the application after quoting each of them.
*/
void
nautilus_launch_application_from_command (GdkScreen *screen,
- const char *command_string,
- gboolean use_terminal,
- ...)
+ const char *command_string,
+ gboolean use_terminal,
+ ...)
{
- char *full_command, *tmp;
- char *quoted_parameter;
- char *parameter;
- va_list ap;
+ char *full_command, *tmp;
+ char *quoted_parameter;
+ char *parameter;
+ va_list ap;
- full_command = g_strdup (command_string);
+ full_command = g_strdup (command_string);
- va_start (ap, use_terminal);
+ va_start (ap, use_terminal);
- while ((parameter = va_arg (ap, char *)) != NULL) {
- quoted_parameter = g_shell_quote (parameter);
- tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
- g_free (quoted_parameter);
+ while ((parameter = va_arg (ap, char *)) != NULL)
+ {
+ quoted_parameter = g_shell_quote (parameter);
+ tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
+ g_free (quoted_parameter);
- g_free (full_command);
- full_command = tmp;
+ g_free (full_command);
+ full_command = tmp;
+ }
- }
+ va_end (ap);
- va_end (ap);
+ launch_application_from_command_internal (full_command, screen, use_terminal);
- launch_application_from_command_internal (full_command, screen, use_terminal);
-
- g_free (full_command);
+ g_free (full_command);
}
/**
* nautilus_launch_application_from_command:
- *
+ *
* Fork off a process to launch an application with a given uri as
* a parameter.
- *
+ *
* @command_string: The application to be launched, with any desired
* command-line options.
* @parameters: Passed as parameters to the application after quoting each of them.
*/
void
-nautilus_launch_application_from_command_array (GdkScreen *screen,
- const char *command_string,
- gboolean use_terminal,
- const char * const * parameters)
+nautilus_launch_application_from_command_array (GdkScreen *screen,
+ const char *command_string,
+ gboolean use_terminal,
+ const char * const *parameters)
{
- char *full_command, *tmp;
- char *quoted_parameter;
- const char * const *p;
+ char *full_command, *tmp;
+ char *quoted_parameter;
+ const char * const *p;
- full_command = g_strdup (command_string);
+ full_command = g_strdup (command_string);
- if (parameters != NULL) {
- for (p = parameters; *p != NULL; p++) {
- quoted_parameter = g_shell_quote (*p);
- tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
- g_free (quoted_parameter);
+ if (parameters != NULL)
+ {
+ for (p = parameters; *p != NULL; p++)
+ {
+ quoted_parameter = g_shell_quote (*p);
+ tmp = g_strconcat (full_command, " ", quoted_parameter, NULL);
+ g_free (quoted_parameter);
- g_free (full_command);
- full_command = tmp;
- }
- }
+ g_free (full_command);
+ full_command = tmp;
+ }
+ }
- launch_application_from_command_internal (full_command, screen, use_terminal);
+ launch_application_from_command_internal (full_command, screen, use_terminal);
- g_free (full_command);
+ g_free (full_command);
}
void
nautilus_launch_desktop_file (GdkScreen *screen,
- const char *desktop_file_uri,
- const GList *parameter_uris,
- GtkWindow *parent_window)
+ const char *desktop_file_uri,
+ const GList *parameter_uris,
+ GtkWindow *parent_window)
{
- GError *error;
- char *message, *desktop_file_path;
- const GList *p;
- GList *files;
- int total, count;
- GFile *file, *desktop_file;
- GDesktopAppInfo *app_info;
- GdkAppLaunchContext *context;
-
- /* Don't allow command execution from remote locations
- * to partially mitigate the security
- * risk of executing arbitrary commands.
- */
- desktop_file = g_file_new_for_uri (desktop_file_uri);
- desktop_file_path = g_file_get_path (desktop_file);
- if (!g_file_is_native (desktop_file)) {
- g_free (desktop_file_path);
- g_object_unref (desktop_file);
- eel_show_error_dialog
- (_("Sorry, but you cannot execute commands from "
- "a remote site."),
- _("This is disabled due to security considerations."),
- parent_window);
-
- return;
- }
- g_object_unref (desktop_file);
-
- app_info = g_desktop_app_info_new_from_filename (desktop_file_path);
- g_free (desktop_file_path);
- if (app_info == NULL) {
- eel_show_error_dialog
- (_("There was an error launching the application."),
- NULL,
- parent_window);
- return;
- }
-
- /* count the number of uris with local paths */
- count = 0;
- total = g_list_length ((GList *) parameter_uris);
- files = NULL;
- for (p = parameter_uris; p != NULL; p = p->next) {
- file = g_file_new_for_uri ((const char *) p->data);
- if (g_file_is_native (file)) {
- count++;
- }
- files = g_list_prepend (files, file);
- }
-
- /* check if this app only supports local files */
- if (g_app_info_supports_files (G_APP_INFO (app_info)) &&
- !g_app_info_supports_uris (G_APP_INFO (app_info)) &&
- parameter_uris != NULL) {
- if (count == 0) {
- /* all files are non-local */
- eel_show_error_dialog
- (_("This drop target only supports local files."),
- _("To open non-local files copy them to a local folder and then"
- " drop them again."),
- parent_window);
-
- g_list_free_full (files, g_object_unref);
- g_object_unref (app_info);
- return;
- } else if (count != total) {
- /* some files are non-local */
- eel_show_warning_dialog
- (_("This drop target only supports local files."),
- _("To open non-local files copy them to a local folder and then"
- " drop them again. The local files you dropped have already been opened."),
- parent_window);
- }
- }
-
- error = NULL;
- context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (parent_window)));
- /* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */
- gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME);
- gdk_app_launch_context_set_screen (context,
- gtk_window_get_screen (parent_window));
- if (count == total) {
- /* All files are local, so we can use g_app_info_launch () with
- * the file list we constructed before.
- */
- g_app_info_launch (G_APP_INFO (app_info),
- files,
- G_APP_LAUNCH_CONTEXT (context),
- &error);
- } else {
- /* Some files are non local, better use g_app_info_launch_uris ().
- */
- g_app_info_launch_uris (G_APP_INFO (app_info),
- (GList *) parameter_uris,
- G_APP_LAUNCH_CONTEXT (context),
- &error);
- }
- if (error != NULL) {
- message = g_strconcat (_("Details: "), error->message, NULL);
- eel_show_error_dialog
- (_("There was an error launching the application."),
- message,
- parent_window);
-
- g_error_free (error);
- g_free (message);
- }
-
- g_list_free_full (files, g_object_unref);
- g_object_unref (context);
- g_object_unref (app_info);
+ GError *error;
+ char *message, *desktop_file_path;
+ const GList *p;
+ GList *files;
+ int total, count;
+ GFile *file, *desktop_file;
+ GDesktopAppInfo *app_info;
+ GdkAppLaunchContext *context;
+
+ /* Don't allow command execution from remote locations
+ * to partially mitigate the security
+ * risk of executing arbitrary commands.
+ */
+ desktop_file = g_file_new_for_uri (desktop_file_uri);
+ desktop_file_path = g_file_get_path (desktop_file);
+ if (!g_file_is_native (desktop_file))
+ {
+ g_free (desktop_file_path);
+ g_object_unref (desktop_file);
+ eel_show_error_dialog
+ (_("Sorry, but you cannot execute commands from "
+ "a remote site."),
+ _("This is disabled due to security considerations."),
+ parent_window);
+
+ return;
+ }
+ g_object_unref (desktop_file);
+
+ app_info = g_desktop_app_info_new_from_filename (desktop_file_path);
+ g_free (desktop_file_path);
+ if (app_info == NULL)
+ {
+ eel_show_error_dialog
+ (_("There was an error launching the application."),
+ NULL,
+ parent_window);
+ return;
+ }
+
+ /* count the number of uris with local paths */
+ count = 0;
+ total = g_list_length ((GList *) parameter_uris);
+ files = NULL;
+ for (p = parameter_uris; p != NULL; p = p->next)
+ {
+ file = g_file_new_for_uri ((const char *) p->data);
+ if (g_file_is_native (file))
+ {
+ count++;
+ }
+ files = g_list_prepend (files, file);
+ }
+
+ /* check if this app only supports local files */
+ if (g_app_info_supports_files (G_APP_INFO (app_info)) &&
+ !g_app_info_supports_uris (G_APP_INFO (app_info)) &&
+ parameter_uris != NULL)
+ {
+ if (count == 0)
+ {
+ /* all files are non-local */
+ eel_show_error_dialog
+ (_("This drop target only supports local files."),
+ _("To open non-local files copy them to a local folder and then"
+ " drop them again."),
+ parent_window);
+
+ g_list_free_full (files, g_object_unref);
+ g_object_unref (app_info);
+ return;
+ }
+ else if (count != total)
+ {
+ /* some files are non-local */
+ eel_show_warning_dialog
+ (_("This drop target only supports local files."),
+ _("To open non-local files copy them to a local folder and then"
+ " drop them again. The local files you dropped have already been opened."),
+ parent_window);
+ }
+ }
+
+ error = NULL;
+ context = gdk_display_get_app_launch_context (gtk_widget_get_display (GTK_WIDGET (parent_window)));
+ /* TODO: Ideally we should accept a timestamp here instead of using GDK_CURRENT_TIME */
+ gdk_app_launch_context_set_timestamp (context, GDK_CURRENT_TIME);
+ gdk_app_launch_context_set_screen (context,
+ gtk_window_get_screen (parent_window));
+ if (count == total)
+ {
+ /* All files are local, so we can use g_app_info_launch () with
+ * the file list we constructed before.
+ */
+ g_app_info_launch (G_APP_INFO (app_info),
+ files,
+ G_APP_LAUNCH_CONTEXT (context),
+ &error);
+ }
+ else
+ {
+ /* Some files are non local, better use g_app_info_launch_uris ().
+ */
+ g_app_info_launch_uris (G_APP_INFO (app_info),
+ (GList *) parameter_uris,
+ G_APP_LAUNCH_CONTEXT (context),
+ &error);
+ }
+ if (error != NULL)
+ {
+ message = g_strconcat (_("Details: "), error->message, NULL);
+ eel_show_error_dialog
+ (_("There was an error launching the application."),
+ message,
+ parent_window);
+
+ g_error_free (error);
+ g_free (message);
+ }
+
+ g_list_free_full (files, g_object_unref);
+ g_object_unref (context);
+ g_object_unref (app_info);
}
diff --git a/src/nautilus-progress-info-manager.c b/src/nautilus-progress-info-manager.c
index 29046c933..e4be79934 100644
--- a/src/nautilus-progress-info-manager.c
+++ b/src/nautilus-progress-info-manager.c
@@ -24,15 +24,17 @@
#include "nautilus-progress-info-manager.h"
-struct _NautilusProgressInfoManagerPriv {
- GList *progress_infos;
- GList *current_viewers;
+struct _NautilusProgressInfoManagerPriv
+{
+ GList *progress_infos;
+ GList *current_viewers;
};
-enum {
- NEW_PROGRESS_INFO,
- HAS_VIEWERS_CHANGED,
- LAST_SIGNAL
+enum
+{
+ NEW_PROGRESS_INFO,
+ HAS_VIEWERS_CHANGED,
+ LAST_SIGNAL
};
static NautilusProgressInfoManager *singleton = NULL;
@@ -42,183 +44,198 @@ static guint signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (NautilusProgressInfoManager, nautilus_progress_info_manager,
G_TYPE_OBJECT);
-static void remove_viewer (NautilusProgressInfoManager *self, GObject *viewer);
+static void remove_viewer (NautilusProgressInfoManager *self,
+ GObject *viewer);
static void
nautilus_progress_info_manager_finalize (GObject *obj)
{
- GList *l;
- NautilusProgressInfoManager *self = NAUTILUS_PROGRESS_INFO_MANAGER (obj);
+ GList *l;
+ NautilusProgressInfoManager *self = NAUTILUS_PROGRESS_INFO_MANAGER (obj);
- if (self->priv->progress_infos != NULL) {
- g_list_free_full (self->priv->progress_infos, g_object_unref);
- }
+ if (self->priv->progress_infos != NULL)
+ {
+ g_list_free_full (self->priv->progress_infos, g_object_unref);
+ }
- for (l = self->priv->current_viewers; l != NULL; l = l->next) {
- g_object_weak_unref (l->data, (GWeakNotify) remove_viewer, self);
- }
- g_list_free (self->priv->current_viewers);
+ for (l = self->priv->current_viewers; l != NULL; l = l->next)
+ {
+ g_object_weak_unref (l->data, (GWeakNotify) remove_viewer, self);
+ }
+ g_list_free (self->priv->current_viewers);
- G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->finalize (obj);
}
static GObject *
-nautilus_progress_info_manager_constructor (GType type,
- guint n_props,
- GObjectConstructParam *props)
+nautilus_progress_info_manager_constructor (GType type,
+ guint n_props,
+ GObjectConstructParam *props)
{
- GObject *retval;
+ GObject *retval;
- if (singleton != NULL) {
- return g_object_ref (singleton);
- }
+ if (singleton != NULL)
+ {
+ return g_object_ref (singleton);
+ }
- retval = G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->constructor
- (type, n_props, props);
+ retval = G_OBJECT_CLASS (nautilus_progress_info_manager_parent_class)->constructor
+ (type, n_props, props);
- singleton = NAUTILUS_PROGRESS_INFO_MANAGER (retval);
- g_object_add_weak_pointer (retval, (gpointer) &singleton);
+ singleton = NAUTILUS_PROGRESS_INFO_MANAGER (retval);
+ g_object_add_weak_pointer (retval, (gpointer) & singleton);
- return retval;
+ return retval;
}
static void
nautilus_progress_info_manager_init (NautilusProgressInfoManager *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_INFO_MANAGER,
- NautilusProgressInfoManagerPriv);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_INFO_MANAGER,
+ NautilusProgressInfoManagerPriv);
}
static void
nautilus_progress_info_manager_class_init (NautilusProgressInfoManagerClass *klass)
{
- GObjectClass *oclass;
-
- oclass = G_OBJECT_CLASS (klass);
- oclass->constructor = nautilus_progress_info_manager_constructor;
- oclass->finalize = nautilus_progress_info_manager_finalize;
-
- signals[NEW_PROGRESS_INFO] =
- g_signal_new ("new-progress-info",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- NAUTILUS_TYPE_PROGRESS_INFO);
-
- signals[HAS_VIEWERS_CHANGED] =
- g_signal_new ("has-viewers-changed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-
- g_type_class_add_private (klass, sizeof (NautilusProgressInfoManagerPriv));
+ GObjectClass *oclass;
+
+ oclass = G_OBJECT_CLASS (klass);
+ oclass->constructor = nautilus_progress_info_manager_constructor;
+ oclass->finalize = nautilus_progress_info_manager_finalize;
+
+ signals[NEW_PROGRESS_INFO] =
+ g_signal_new ("new-progress-info",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ NAUTILUS_TYPE_PROGRESS_INFO);
+
+ signals[HAS_VIEWERS_CHANGED] =
+ g_signal_new ("has-viewers-changed",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+
+ g_type_class_add_private (klass, sizeof (NautilusProgressInfoManagerPriv));
}
NautilusProgressInfoManager *
nautilus_progress_info_manager_dup_singleton (void)
{
- return g_object_new (NAUTILUS_TYPE_PROGRESS_INFO_MANAGER, NULL);
+ return g_object_new (NAUTILUS_TYPE_PROGRESS_INFO_MANAGER, NULL);
}
void
nautilus_progress_info_manager_add_new_info (NautilusProgressInfoManager *self,
- NautilusProgressInfo *info)
+ NautilusProgressInfo *info)
{
- if (g_list_find (self->priv->progress_infos, info) != NULL) {
- g_warning ("Adding two times the same progress info object to the manager");
- return;
- }
-
- self->priv->progress_infos =
- g_list_prepend (self->priv->progress_infos, g_object_ref (info));
-
- g_signal_emit (self, signals[NEW_PROGRESS_INFO], 0, info);
+ if (g_list_find (self->priv->progress_infos, info) != NULL)
+ {
+ g_warning ("Adding two times the same progress info object to the manager");
+ return;
+ }
+
+ self->priv->progress_infos =
+ g_list_prepend (self->priv->progress_infos, g_object_ref (info));
+
+ g_signal_emit (self, signals[NEW_PROGRESS_INFO], 0, info);
}
void
nautilus_progress_info_manager_remove_finished_or_cancelled_infos (NautilusProgressInfoManager *self)
{
- GList *l;
- GList *next;
-
- l = self->priv->progress_infos;
- while (l != NULL) {
- next = l->next;
- if (nautilus_progress_info_get_is_finished (l->data) ||
- nautilus_progress_info_get_is_cancelled (l->data)) {
- self->priv->progress_infos = g_list_remove (self->priv->progress_infos,
- l->data);
- }
- l = next;
+ GList *l;
+ GList *next;
+
+ l = self->priv->progress_infos;
+ while (l != NULL)
+ {
+ next = l->next;
+ if (nautilus_progress_info_get_is_finished (l->data) ||
+ nautilus_progress_info_get_is_cancelled (l->data))
+ {
+ self->priv->progress_infos = g_list_remove (self->priv->progress_infos,
+ l->data);
}
+ l = next;
+ }
}
GList *
nautilus_progress_info_manager_get_all_infos (NautilusProgressInfoManager *self)
{
- return self->priv->progress_infos;
+ return self->priv->progress_infos;
}
gboolean
nautilus_progress_manager_are_all_infos_finished_or_cancelled (NautilusProgressInfoManager *self)
{
- GList *l;
-
- for (l = self->priv->progress_infos; l != NULL; l = l->next) {
- if (!(nautilus_progress_info_get_is_finished (l->data) ||
- nautilus_progress_info_get_is_cancelled (l->data))) {
- return FALSE;
- }
+ GList *l;
+
+ for (l = self->priv->progress_infos; l != NULL; l = l->next)
+ {
+ if (!(nautilus_progress_info_get_is_finished (l->data) ||
+ nautilus_progress_info_get_is_cancelled (l->data)))
+ {
+ return FALSE;
}
+ }
- return TRUE;
+ return TRUE;
}
static void
remove_viewer (NautilusProgressInfoManager *self,
GObject *viewer)
{
- self->priv->current_viewers = g_list_remove (self->priv->current_viewers, viewer);
+ self->priv->current_viewers = g_list_remove (self->priv->current_viewers, viewer);
- if (self->priv->current_viewers == NULL)
- g_signal_emit (self, signals[HAS_VIEWERS_CHANGED], 0);
+ if (self->priv->current_viewers == NULL)
+ {
+ g_signal_emit (self, signals[HAS_VIEWERS_CHANGED], 0);
+ }
}
void
nautilus_progress_manager_add_viewer (NautilusProgressInfoManager *self,
GObject *viewer)
{
- GList *viewers;
-
- viewers = self->priv->current_viewers;
- if (g_list_find (viewers, viewer) == NULL) {
- g_object_weak_ref (viewer, (GWeakNotify) remove_viewer, self);
- viewers = g_list_append (viewers, viewer);
- self->priv->current_viewers = viewers;
-
- if (g_list_length (viewers) == 1)
- g_signal_emit (self, signals[HAS_VIEWERS_CHANGED], 0);
+ GList *viewers;
+
+ viewers = self->priv->current_viewers;
+ if (g_list_find (viewers, viewer) == NULL)
+ {
+ g_object_weak_ref (viewer, (GWeakNotify) remove_viewer, self);
+ viewers = g_list_append (viewers, viewer);
+ self->priv->current_viewers = viewers;
+
+ if (g_list_length (viewers) == 1)
+ {
+ g_signal_emit (self, signals[HAS_VIEWERS_CHANGED], 0);
}
+ }
}
void
nautilus_progress_manager_remove_viewer (NautilusProgressInfoManager *self,
GObject *viewer)
{
- if (g_list_find (self->priv->current_viewers, viewer) != NULL) {
- g_object_weak_unref (viewer, (GWeakNotify) remove_viewer, self);
- remove_viewer (self, viewer);
- }
+ if (g_list_find (self->priv->current_viewers, viewer) != NULL)
+ {
+ g_object_weak_unref (viewer, (GWeakNotify) remove_viewer, self);
+ remove_viewer (self, viewer);
+ }
}
gboolean
nautilus_progress_manager_has_viewers (NautilusProgressInfoManager *self)
{
- return self->priv->current_viewers != NULL;
+ return self->priv->current_viewers != NULL;
}
diff --git a/src/nautilus-progress-info-widget.c b/src/nautilus-progress-info-widget.c
index a2d711c0b..1cf350ba5 100644
--- a/src/nautilus-progress-info-widget.c
+++ b/src/nautilus-progress-info-widget.c
@@ -24,19 +24,21 @@
#include <config.h>
#include "nautilus-progress-info-widget.h"
-struct _NautilusProgressInfoWidgetPrivate {
- NautilusProgressInfo *info;
-
- GtkWidget *status; /* GtkLabel */
- GtkWidget *details; /* GtkLabel */
- GtkWidget *progress_bar;
- GtkWidget *button;
- GtkWidget *done_image;
+struct _NautilusProgressInfoWidgetPrivate
+{
+ NautilusProgressInfo *info;
+
+ GtkWidget *status; /* GtkLabel */
+ GtkWidget *details; /* GtkLabel */
+ GtkWidget *progress_bar;
+ GtkWidget *button;
+ GtkWidget *done_image;
};
-enum {
- PROP_INFO = 1,
- NUM_PROPERTIES
+enum
+{
+ PROP_INFO = 1,
+ NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL };
@@ -47,169 +49,181 @@ G_DEFINE_TYPE_WITH_PRIVATE (NautilusProgressInfoWidget, nautilus_progress_info_w
static void
info_finished (NautilusProgressInfoWidget *self)
{
- gtk_button_set_image (GTK_BUTTON (self->priv->button), self->priv->done_image);
- gtk_widget_set_sensitive (self->priv->button, FALSE);
+ gtk_button_set_image (GTK_BUTTON (self->priv->button), self->priv->done_image);
+ gtk_widget_set_sensitive (self->priv->button, FALSE);
}
static void
info_cancelled (NautilusProgressInfoWidget *self)
{
- gtk_widget_set_sensitive (self->priv->button, FALSE);
+ gtk_widget_set_sensitive (self->priv->button, FALSE);
}
static void
update_data (NautilusProgressInfoWidget *self)
{
- char *status, *details;
- char *markup;
-
- status = nautilus_progress_info_get_status (self->priv->info);
- gtk_label_set_text (GTK_LABEL (self->priv->status), status);
- g_free (status);
-
- details = nautilus_progress_info_get_details (self->priv->info);
- markup = g_markup_printf_escaped ("<span size='small'>%s</span>", details);
- gtk_label_set_markup (GTK_LABEL (self->priv->details), markup);
- g_free (details);
- g_free (markup);
+ char *status, *details;
+ char *markup;
+
+ status = nautilus_progress_info_get_status (self->priv->info);
+ gtk_label_set_text (GTK_LABEL (self->priv->status), status);
+ g_free (status);
+
+ details = nautilus_progress_info_get_details (self->priv->info);
+ markup = g_markup_printf_escaped ("<span size='small'>%s</span>", details);
+ gtk_label_set_markup (GTK_LABEL (self->priv->details), markup);
+ g_free (details);
+ g_free (markup);
}
static void
update_progress (NautilusProgressInfoWidget *self)
{
- double progress;
-
- progress = nautilus_progress_info_get_progress (self->priv->info);
- if (progress < 0) {
- gtk_progress_bar_pulse (GTK_PROGRESS_BAR (self->priv->progress_bar));
- } else {
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (self->priv->progress_bar), progress);
- }
+ double progress;
+
+ progress = nautilus_progress_info_get_progress (self->priv->info);
+ if (progress < 0)
+ {
+ gtk_progress_bar_pulse (GTK_PROGRESS_BAR (self->priv->progress_bar));
+ }
+ else
+ {
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (self->priv->progress_bar), progress);
+ }
}
static void
-button_clicked (GtkWidget *button,
- NautilusProgressInfoWidget *self)
+button_clicked (GtkWidget *button,
+ NautilusProgressInfoWidget *self)
{
- if (!nautilus_progress_info_get_is_finished (self->priv->info)) {
- nautilus_progress_info_cancel (self->priv->info);
- }
+ if (!nautilus_progress_info_get_is_finished (self->priv->info))
+ {
+ nautilus_progress_info_cancel (self->priv->info);
+ }
}
static void
nautilus_progress_info_widget_dispose (GObject *obj)
{
- NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
+ NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
- if (self->priv->info != NULL) {
- g_signal_handlers_disconnect_by_data (self->priv->info, self);
- }
- g_clear_object (&self->priv->info);
+ if (self->priv->info != NULL)
+ {
+ g_signal_handlers_disconnect_by_data (self->priv->info, self);
+ }
+ g_clear_object (&self->priv->info);
- G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->dispose (obj);
+ G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->dispose (obj);
}
static void
nautilus_progress_info_widget_constructed (GObject *obj)
{
- NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
-
- G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->constructed (obj);
-
- g_signal_connect_swapped (self->priv->info,
- "changed",
- G_CALLBACK (update_data), self);
- g_signal_connect_swapped (self->priv->info,
- "progress-changed",
- G_CALLBACK (update_progress), self);
- g_signal_connect_swapped (self->priv->info,
- "finished",
- G_CALLBACK (info_finished), self);
- g_signal_connect_swapped (self->priv->info,
- "cancelled",
- G_CALLBACK (info_cancelled), self);
-
- update_data (self);
- update_progress (self);
+ NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (obj);
+
+ G_OBJECT_CLASS (nautilus_progress_info_widget_parent_class)->constructed (obj);
+
+ g_signal_connect_swapped (self->priv->info,
+ "changed",
+ G_CALLBACK (update_data), self);
+ g_signal_connect_swapped (self->priv->info,
+ "progress-changed",
+ G_CALLBACK (update_progress), self);
+ g_signal_connect_swapped (self->priv->info,
+ "finished",
+ G_CALLBACK (info_finished), self);
+ g_signal_connect_swapped (self->priv->info,
+ "cancelled",
+ G_CALLBACK (info_cancelled), self);
+
+ update_data (self);
+ update_progress (self);
}
static void
-nautilus_progress_info_widget_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_progress_info_widget_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (object);
-
- switch (property_id) {
- case PROP_INFO:
- self->priv->info = g_value_dup_object (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusProgressInfoWidget *self = NAUTILUS_PROGRESS_INFO_WIDGET (object);
+
+ switch (property_id)
+ {
+ case PROP_INFO:
+ {
+ self->priv->info = g_value_dup_object (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_progress_info_widget_init (NautilusProgressInfoWidget *self)
{
- self->priv = nautilus_progress_info_widget_get_instance_private (self);
+ self->priv = nautilus_progress_info_widget_get_instance_private (self);
- gtk_widget_init_template (GTK_WIDGET (self));
+ gtk_widget_init_template (GTK_WIDGET (self));
- g_signal_connect (self->priv->button, "clicked",
- G_CALLBACK (button_clicked), self);
+ g_signal_connect (self->priv->button, "clicked",
+ G_CALLBACK (button_clicked), self);
}
static void
nautilus_progress_info_widget_class_init (NautilusProgressInfoWidgetClass *klass)
{
- GObjectClass *oclass;
- GtkWidgetClass *widget_class;
-
- widget_class = GTK_WIDGET_CLASS (klass);
- oclass = G_OBJECT_CLASS (klass);
- oclass->set_property = nautilus_progress_info_widget_set_property;
- oclass->constructed = nautilus_progress_info_widget_constructed;
- oclass->dispose = nautilus_progress_info_widget_dispose;
-
- properties[PROP_INFO] =
- g_param_spec_object ("info",
- "NautilusProgressInfo",
- "The NautilusProgressInfo associated with this widget",
- NAUTILUS_TYPE_PROGRESS_INFO,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
-
- gtk_widget_class_set_template_from_resource (widget_class,
- "/org/gnome/nautilus/ui/nautilus-progress-info-widget.ui");
-
- gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, status);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, details);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, progress_bar);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, button);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, done_image);
+ GObjectClass *oclass;
+ GtkWidgetClass *widget_class;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
+ oclass->set_property = nautilus_progress_info_widget_set_property;
+ oclass->constructed = nautilus_progress_info_widget_constructed;
+ oclass->dispose = nautilus_progress_info_widget_dispose;
+
+ properties[PROP_INFO] =
+ g_param_spec_object ("info",
+ "NautilusProgressInfo",
+ "The NautilusProgressInfo associated with this widget",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/nautilus/ui/nautilus-progress-info-widget.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, status);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, details);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, progress_bar);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, button);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusProgressInfoWidget, done_image);
}
GtkWidget *
nautilus_progress_info_widget_new (NautilusProgressInfo *info)
{
- NautilusProgressInfoWidget *self;
+ NautilusProgressInfoWidget *self;
- self = g_object_new (NAUTILUS_TYPE_PROGRESS_INFO_WIDGET,
- "info", info,
- NULL);
+ self = g_object_new (NAUTILUS_TYPE_PROGRESS_INFO_WIDGET,
+ "info", info,
+ NULL);
- if (nautilus_progress_info_get_is_finished (self->priv->info)) {
- gtk_button_set_image (GTK_BUTTON (self->priv->button), self->priv->done_image);
- }
+ if (nautilus_progress_info_get_is_finished (self->priv->info))
+ {
+ gtk_button_set_image (GTK_BUTTON (self->priv->button), self->priv->done_image);
+ }
- gtk_widget_set_sensitive (self->priv->button,
- !nautilus_progress_info_get_is_finished (self->priv->info) &&
- !nautilus_progress_info_get_is_cancelled (self->priv->info));
+ gtk_widget_set_sensitive (self->priv->button,
+ !nautilus_progress_info_get_is_finished (self->priv->info) &&
+ !nautilus_progress_info_get_is_cancelled (self->priv->info));
- return GTK_WIDGET (self);
+ return GTK_WIDGET (self);
}
diff --git a/src/nautilus-progress-info.c b/src/nautilus-progress-info.c
index 0a4e0aa04..5a4c7d208 100644
--- a/src/nautilus-progress-info.c
+++ b/src/nautilus-progress-info.c
@@ -1,23 +1,23 @@
/*
- nautilus-progress-info.h: file operation progress info.
-
- Copyright (C) 2007 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Alexander Larsson <alexl@redhat.com>
-*/
+ * nautilus-progress-info.h: file operation progress info.
+ *
+ * Copyright (C) 2007 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
#include <math.h>
@@ -28,13 +28,14 @@
#include "nautilus-progress-info-manager.h"
#include "nautilus-icon-info.h"
-enum {
- CHANGED,
- PROGRESS_CHANGED,
- STARTED,
- FINISHED,
- CANCELLED,
- LAST_SIGNAL
+enum
+{
+ CHANGED,
+ PROGRESS_CHANGED,
+ STARTED,
+ FINISHED,
+ CANCELLED,
+ LAST_SIGNAL
};
#define SIGNAL_DELAY_MSEC 100
@@ -43,247 +44,261 @@ static guint signals[LAST_SIGNAL] = { 0 };
struct _NautilusProgressInfo
{
- GObject parent_instance;
-
- GCancellable *cancellable;
- guint cancellable_id;
- GCancellable *details_in_thread_cancellable;
-
- GTimer *progress_timer;
-
- char *status;
- char *details;
- double progress;
- gdouble remaining_time;
- gdouble elapsed_time;
- gboolean activity_mode;
- gboolean started;
- gboolean finished;
- gboolean paused;
-
- GSource *idle_source;
- gboolean source_is_now;
-
- gboolean start_at_idle;
- gboolean finish_at_idle;
- gboolean cancel_at_idle;
- gboolean changed_at_idle;
- gboolean progress_at_idle;
-
- GFile *destination;
+ GObject parent_instance;
+
+ GCancellable *cancellable;
+ guint cancellable_id;
+ GCancellable *details_in_thread_cancellable;
+
+ GTimer *progress_timer;
+
+ char *status;
+ char *details;
+ double progress;
+ gdouble remaining_time;
+ gdouble elapsed_time;
+ gboolean activity_mode;
+ gboolean started;
+ gboolean finished;
+ gboolean paused;
+
+ GSource *idle_source;
+ gboolean source_is_now;
+
+ gboolean start_at_idle;
+ gboolean finish_at_idle;
+ gboolean cancel_at_idle;
+ gboolean changed_at_idle;
+ gboolean progress_at_idle;
+
+ GFile *destination;
};
struct _NautilusProgressInfoClass
{
- GObjectClass parent_class;
+ GObjectClass parent_class;
};
-G_LOCK_DEFINE_STATIC(progress_info);
+G_LOCK_DEFINE_STATIC (progress_info);
G_DEFINE_TYPE (NautilusProgressInfo, nautilus_progress_info, G_TYPE_OBJECT)
static void
nautilus_progress_info_finalize (GObject *object)
{
- NautilusProgressInfo *info;
-
- info = NAUTILUS_PROGRESS_INFO (object);
+ NautilusProgressInfo *info;
+
+ info = NAUTILUS_PROGRESS_INFO (object);
+
+ g_free (info->status);
+ g_free (info->details);
+ g_clear_pointer (&info->progress_timer, (GDestroyNotify) g_timer_destroy);
+ g_cancellable_disconnect (info->cancellable, info->cancellable_id);
+ g_object_unref (info->cancellable);
+ g_cancellable_cancel (info->details_in_thread_cancellable);
+ g_clear_object (&info->details_in_thread_cancellable);
+ g_clear_object (&info->destination);
- g_free (info->status);
- g_free (info->details);
- g_clear_pointer (&info->progress_timer, (GDestroyNotify) g_timer_destroy);
- g_cancellable_disconnect (info->cancellable, info->cancellable_id);
- g_object_unref (info->cancellable);
- g_cancellable_cancel (info->details_in_thread_cancellable);
- g_clear_object (&info->details_in_thread_cancellable);
- g_clear_object (&info->destination);
-
- if (G_OBJECT_CLASS (nautilus_progress_info_parent_class)->finalize) {
- (*G_OBJECT_CLASS (nautilus_progress_info_parent_class)->finalize) (object);
- }
+ if (G_OBJECT_CLASS (nautilus_progress_info_parent_class)->finalize)
+ {
+ (*G_OBJECT_CLASS (nautilus_progress_info_parent_class)->finalize)(object);
+ }
}
static void
nautilus_progress_info_dispose (GObject *object)
{
- NautilusProgressInfo *info;
-
- info = NAUTILUS_PROGRESS_INFO (object);
+ NautilusProgressInfo *info;
- G_LOCK (progress_info);
+ info = NAUTILUS_PROGRESS_INFO (object);
- /* Destroy source in dispose, because the callback
- could come here before the destroy, which should
- ressurect the object for a while */
- if (info->idle_source) {
- g_source_destroy (info->idle_source);
- g_source_unref (info->idle_source);
- info->idle_source = NULL;
- }
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+
+ /* Destroy source in dispose, because the callback
+ * could come here before the destroy, which should
+ * ressurect the object for a while */
+ if (info->idle_source)
+ {
+ g_source_destroy (info->idle_source);
+ g_source_unref (info->idle_source);
+ info->idle_source = NULL;
+ }
+ G_UNLOCK (progress_info);
}
static void
nautilus_progress_info_class_init (NautilusProgressInfoClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->finalize = nautilus_progress_info_finalize;
- gobject_class->dispose = nautilus_progress_info_dispose;
-
- signals[CHANGED] =
- g_signal_new ("changed",
- NAUTILUS_TYPE_PROGRESS_INFO,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[PROGRESS_CHANGED] =
- g_signal_new ("progress-changed",
- NAUTILUS_TYPE_PROGRESS_INFO,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[STARTED] =
- g_signal_new ("started",
- NAUTILUS_TYPE_PROGRESS_INFO,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[FINISHED] =
- g_signal_new ("finished",
- NAUTILUS_TYPE_PROGRESS_INFO,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[CANCELLED] =
- g_signal_new ("cancelled",
- NAUTILUS_TYPE_PROGRESS_INFO,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = nautilus_progress_info_finalize;
+ gobject_class->dispose = nautilus_progress_info_dispose;
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[PROGRESS_CHANGED] =
+ g_signal_new ("progress-changed",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[STARTED] =
+ g_signal_new ("started",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[FINISHED] =
+ g_signal_new ("finished",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[CANCELLED] =
+ g_signal_new ("cancelled",
+ NAUTILUS_TYPE_PROGRESS_INFO,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
static gboolean
idle_callback (gpointer data)
{
- NautilusProgressInfo *info = data;
- gboolean start_at_idle;
- gboolean finish_at_idle;
- gboolean changed_at_idle;
- gboolean progress_at_idle;
- gboolean cancelled_at_idle;
- GSource *source;
-
- source = g_main_current_source ();
-
- G_LOCK (progress_info);
-
- /* Protect agains races where the source has
- been destroyed on another thread while it
- was being dispatched.
- Similar to what gdk_threads_add_idle does.
- */
- if (g_source_is_destroyed (source)) {
- G_UNLOCK (progress_info);
- return FALSE;
- }
-
- /* We hadn't destroyed the source, so take a ref.
- * This might ressurect the object from dispose, but
- * that should be ok.
- */
- g_object_ref (info);
-
- g_assert (source == info->idle_source);
-
- g_source_unref (source);
- info->idle_source = NULL;
-
- start_at_idle = info->start_at_idle;
- finish_at_idle = info->finish_at_idle;
- changed_at_idle = info->changed_at_idle;
- progress_at_idle = info->progress_at_idle;
- cancelled_at_idle = info->cancel_at_idle;
-
- info->start_at_idle = FALSE;
- info->finish_at_idle = FALSE;
- info->changed_at_idle = FALSE;
- info->progress_at_idle = FALSE;
- info->cancel_at_idle = FALSE;
-
- G_UNLOCK (progress_info);
-
- if (start_at_idle) {
- g_signal_emit (info,
- signals[STARTED],
- 0);
- }
-
- if (changed_at_idle) {
- g_signal_emit (info,
- signals[CHANGED],
- 0);
- }
-
- if (progress_at_idle) {
- g_signal_emit (info,
- signals[PROGRESS_CHANGED],
- 0);
- }
-
- if (finish_at_idle) {
- g_signal_emit (info,
- signals[FINISHED],
- 0);
- }
-
- if (cancelled_at_idle) {
- g_signal_emit (info,
- signals[CANCELLED],
- 0);
- }
-
- g_object_unref (info);
-
- return FALSE;
+ NautilusProgressInfo *info = data;
+ gboolean start_at_idle;
+ gboolean finish_at_idle;
+ gboolean changed_at_idle;
+ gboolean progress_at_idle;
+ gboolean cancelled_at_idle;
+ GSource *source;
+
+ source = g_main_current_source ();
+
+ G_LOCK (progress_info);
+
+ /* Protect agains races where the source has
+ * been destroyed on another thread while it
+ * was being dispatched.
+ * Similar to what gdk_threads_add_idle does.
+ */
+ if (g_source_is_destroyed (source))
+ {
+ G_UNLOCK (progress_info);
+ return FALSE;
+ }
+
+ /* We hadn't destroyed the source, so take a ref.
+ * This might ressurect the object from dispose, but
+ * that should be ok.
+ */
+ g_object_ref (info);
+
+ g_assert (source == info->idle_source);
+
+ g_source_unref (source);
+ info->idle_source = NULL;
+
+ start_at_idle = info->start_at_idle;
+ finish_at_idle = info->finish_at_idle;
+ changed_at_idle = info->changed_at_idle;
+ progress_at_idle = info->progress_at_idle;
+ cancelled_at_idle = info->cancel_at_idle;
+
+ info->start_at_idle = FALSE;
+ info->finish_at_idle = FALSE;
+ info->changed_at_idle = FALSE;
+ info->progress_at_idle = FALSE;
+ info->cancel_at_idle = FALSE;
+
+ G_UNLOCK (progress_info);
+
+ if (start_at_idle)
+ {
+ g_signal_emit (info,
+ signals[STARTED],
+ 0);
+ }
+
+ if (changed_at_idle)
+ {
+ g_signal_emit (info,
+ signals[CHANGED],
+ 0);
+ }
+
+ if (progress_at_idle)
+ {
+ g_signal_emit (info,
+ signals[PROGRESS_CHANGED],
+ 0);
+ }
+
+ if (finish_at_idle)
+ {
+ g_signal_emit (info,
+ signals[FINISHED],
+ 0);
+ }
+
+ if (cancelled_at_idle)
+ {
+ g_signal_emit (info,
+ signals[CANCELLED],
+ 0);
+ }
+
+ g_object_unref (info);
+
+ return FALSE;
}
/* Called with lock held */
static void
-queue_idle (NautilusProgressInfo *info, gboolean now)
-{
- if (info->idle_source == NULL ||
- (now && !info->source_is_now)) {
- if (info->idle_source) {
- g_source_destroy (info->idle_source);
- g_source_unref (info->idle_source);
- info->idle_source = NULL;
- }
-
- info->source_is_now = now;
- if (now) {
- info->idle_source = g_idle_source_new ();
- } else {
- info->idle_source = g_timeout_source_new (SIGNAL_DELAY_MSEC);
- }
- g_source_set_callback (info->idle_source, idle_callback, info, NULL);
- g_source_attach (info->idle_source, NULL);
- }
+queue_idle (NautilusProgressInfo *info,
+ gboolean now)
+{
+ if (info->idle_source == NULL ||
+ (now && !info->source_is_now))
+ {
+ if (info->idle_source)
+ {
+ g_source_destroy (info->idle_source);
+ g_source_unref (info->idle_source);
+ info->idle_source = NULL;
+ }
+
+ info->source_is_now = now;
+ if (now)
+ {
+ info->idle_source = g_idle_source_new ();
+ }
+ else
+ {
+ info->idle_source = g_timeout_source_new (SIGNAL_DELAY_MSEC);
+ }
+ g_source_set_callback (info->idle_source, idle_callback, info, NULL);
+ g_source_attach (info->idle_source, NULL);
+ }
}
static void
@@ -292,446 +307,475 @@ set_details_in_thread (GTask *task,
gpointer user_data,
GCancellable *cancellable)
{
- if (!g_cancellable_is_cancelled (cancellable)) {
- nautilus_progress_info_set_details (info, _("Canceled"));
- G_LOCK (progress_info);
- info->cancel_at_idle = TRUE;
- g_timer_stop (info->progress_timer);
- queue_idle (info, TRUE);
- G_UNLOCK (progress_info);
- }
+ if (!g_cancellable_is_cancelled (cancellable))
+ {
+ nautilus_progress_info_set_details (info, _("Canceled"));
+ G_LOCK (progress_info);
+ info->cancel_at_idle = TRUE;
+ g_timer_stop (info->progress_timer);
+ queue_idle (info, TRUE);
+ G_UNLOCK (progress_info);
+ }
}
static void
on_canceled (GCancellable *cancellable,
NautilusProgressInfo *info)
{
- GTask *task;
+ GTask *task;
- /* We can't do any lock operaton here, since this is probably the main
- * thread, so modify the details in another thread. Also it can happens
- * that we were finalizing the object, so create a new cancellable here
- * so it can be cancelled in finalize */
- info->details_in_thread_cancellable = g_cancellable_new ();
- task = g_task_new (info, info->details_in_thread_cancellable, NULL, NULL);
- g_task_run_in_thread (task, (GTaskThreadFunc) set_details_in_thread);
+ /* We can't do any lock operaton here, since this is probably the main
+ * thread, so modify the details in another thread. Also it can happens
+ * that we were finalizing the object, so create a new cancellable here
+ * so it can be cancelled in finalize */
+ info->details_in_thread_cancellable = g_cancellable_new ();
+ task = g_task_new (info, info->details_in_thread_cancellable, NULL, NULL);
+ g_task_run_in_thread (task, (GTaskThreadFunc) set_details_in_thread);
- g_object_unref (task);
+ g_object_unref (task);
}
static void
nautilus_progress_info_init (NautilusProgressInfo *info)
{
- NautilusProgressInfoManager *manager;
+ NautilusProgressInfoManager *manager;
- info->cancellable = g_cancellable_new ();
- info->cancellable_id = g_cancellable_connect (info->cancellable,
- G_CALLBACK (on_canceled),
- info,
- NULL);
+ info->cancellable = g_cancellable_new ();
+ info->cancellable_id = g_cancellable_connect (info->cancellable,
+ G_CALLBACK (on_canceled),
+ info,
+ NULL);
- manager = nautilus_progress_info_manager_dup_singleton ();
- nautilus_progress_info_manager_add_new_info (manager, info);
- g_object_unref (manager);
- info->progress_timer = g_timer_new ();
+ manager = nautilus_progress_info_manager_dup_singleton ();
+ nautilus_progress_info_manager_add_new_info (manager, info);
+ g_object_unref (manager);
+ info->progress_timer = g_timer_new ();
}
NautilusProgressInfo *
nautilus_progress_info_new (void)
{
- NautilusProgressInfo *info;
-
- info = g_object_new (NAUTILUS_TYPE_PROGRESS_INFO, NULL);
-
- return info;
+ NautilusProgressInfo *info;
+
+ info = g_object_new (NAUTILUS_TYPE_PROGRESS_INFO, NULL);
+
+ return info;
}
char *
nautilus_progress_info_get_status (NautilusProgressInfo *info)
{
- char *res;
-
- G_LOCK (progress_info);
-
- if (info->status) {
- res = g_strdup (info->status);
- } else {
- res = g_strdup (_("Preparing"));
- }
-
- G_UNLOCK (progress_info);
-
- return res;
+ char *res;
+
+ G_LOCK (progress_info);
+
+ if (info->status)
+ {
+ res = g_strdup (info->status);
+ }
+ else
+ {
+ res = g_strdup (_("Preparing"));
+ }
+
+ G_UNLOCK (progress_info);
+
+ return res;
}
char *
nautilus_progress_info_get_details (NautilusProgressInfo *info)
{
- char *res;
-
- G_LOCK (progress_info);
-
- if (info->details) {
- res = g_strdup (info->details);
- } else {
- res = g_strdup (_("Preparing"));
- }
-
- G_UNLOCK (progress_info);
+ char *res;
+
+ G_LOCK (progress_info);
+
+ if (info->details)
+ {
+ res = g_strdup (info->details);
+ }
+ else
+ {
+ res = g_strdup (_("Preparing"));
+ }
- return res;
+ G_UNLOCK (progress_info);
+
+ return res;
}
double
nautilus_progress_info_get_progress (NautilusProgressInfo *info)
{
- double res;
-
- G_LOCK (progress_info);
+ double res;
+
+ G_LOCK (progress_info);
+
+ if (info->activity_mode)
+ {
+ res = -1.0;
+ }
+ else
+ {
+ res = info->progress;
+ }
- if (info->activity_mode) {
- res = -1.0;
- } else {
- res = info->progress;
- }
-
- G_UNLOCK (progress_info);
-
- return res;
+ G_UNLOCK (progress_info);
+
+ return res;
}
void
nautilus_progress_info_cancel (NautilusProgressInfo *info)
{
- G_LOCK (progress_info);
-
- g_cancellable_cancel (info->cancellable);
- g_timer_stop (info->progress_timer);
-
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+
+ g_cancellable_cancel (info->cancellable);
+ g_timer_stop (info->progress_timer);
+
+ G_UNLOCK (progress_info);
}
GCancellable *
nautilus_progress_info_get_cancellable (NautilusProgressInfo *info)
{
- GCancellable *c;
-
- G_LOCK (progress_info);
-
- c = g_object_ref (info->cancellable);
-
- G_UNLOCK (progress_info);
-
- return c;
+ GCancellable *c;
+
+ G_LOCK (progress_info);
+
+ c = g_object_ref (info->cancellable);
+
+ G_UNLOCK (progress_info);
+
+ return c;
}
gboolean
nautilus_progress_info_get_is_cancelled (NautilusProgressInfo *info)
{
- gboolean cancelled;
+ gboolean cancelled;
- G_LOCK (progress_info);
- cancelled = g_cancellable_is_cancelled (info->cancellable);
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ cancelled = g_cancellable_is_cancelled (info->cancellable);
+ G_UNLOCK (progress_info);
- return cancelled;
+ return cancelled;
}
gboolean
nautilus_progress_info_get_is_started (NautilusProgressInfo *info)
{
- gboolean res;
-
- G_LOCK (progress_info);
-
- res = info->started;
-
- G_UNLOCK (progress_info);
-
- return res;
+ gboolean res;
+
+ G_LOCK (progress_info);
+
+ res = info->started;
+
+ G_UNLOCK (progress_info);
+
+ return res;
}
gboolean
nautilus_progress_info_get_is_finished (NautilusProgressInfo *info)
{
- gboolean res;
-
- G_LOCK (progress_info);
-
- res = info->finished;
-
- G_UNLOCK (progress_info);
-
- return res;
+ gboolean res;
+
+ G_LOCK (progress_info);
+
+ res = info->finished;
+
+ G_UNLOCK (progress_info);
+
+ return res;
}
gboolean
nautilus_progress_info_get_is_paused (NautilusProgressInfo *info)
{
- gboolean res;
-
- G_LOCK (progress_info);
-
- res = info->paused;
-
- G_UNLOCK (progress_info);
-
- return res;
+ gboolean res;
+
+ G_LOCK (progress_info);
+
+ res = info->paused;
+
+ G_UNLOCK (progress_info);
+
+ return res;
}
void
nautilus_progress_info_pause (NautilusProgressInfo *info)
{
- G_LOCK (progress_info);
+ G_LOCK (progress_info);
- if (!info->paused) {
- info->paused = TRUE;
- g_timer_stop (info->progress_timer);
- }
+ if (!info->paused)
+ {
+ info->paused = TRUE;
+ g_timer_stop (info->progress_timer);
+ }
- G_UNLOCK (progress_info);
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_resume (NautilusProgressInfo *info)
{
- G_LOCK (progress_info);
+ G_LOCK (progress_info);
- if (info->paused) {
- info->paused = FALSE;
- g_timer_continue (info->progress_timer);
- }
+ if (info->paused)
+ {
+ info->paused = FALSE;
+ g_timer_continue (info->progress_timer);
+ }
- G_UNLOCK (progress_info);
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_start (NautilusProgressInfo *info)
{
- G_LOCK (progress_info);
-
- if (!info->started) {
- info->started = TRUE;
- g_timer_start (info->progress_timer);
-
- info->start_at_idle = TRUE;
- queue_idle (info, TRUE);
- }
-
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+
+ if (!info->started)
+ {
+ info->started = TRUE;
+ g_timer_start (info->progress_timer);
+
+ info->start_at_idle = TRUE;
+ queue_idle (info, TRUE);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_finish (NautilusProgressInfo *info)
{
- G_LOCK (progress_info);
-
- if (!info->finished) {
- info->finished = TRUE;
- g_timer_stop (info->progress_timer);
-
- info->finish_at_idle = TRUE;
- queue_idle (info, TRUE);
- }
-
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+
+ if (!info->finished)
+ {
+ info->finished = TRUE;
+ g_timer_stop (info->progress_timer);
+
+ info->finish_at_idle = TRUE;
+ queue_idle (info, TRUE);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_take_status (NautilusProgressInfo *info,
- char *status)
-{
- G_LOCK (progress_info);
-
- if (g_strcmp0 (info->status, status) != 0) {
- g_free (info->status);
- info->status = status;
-
- info->changed_at_idle = TRUE;
- queue_idle (info, FALSE);
- } else {
- g_free (status);
- }
-
- G_UNLOCK (progress_info);
+ char *status)
+{
+ G_LOCK (progress_info);
+
+ if (g_strcmp0 (info->status, status) != 0)
+ {
+ g_free (info->status);
+ info->status = status;
+
+ info->changed_at_idle = TRUE;
+ queue_idle (info, FALSE);
+ }
+ else
+ {
+ g_free (status);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_set_status (NautilusProgressInfo *info,
- const char *status)
+ const char *status)
{
- G_LOCK (progress_info);
-
- if (g_strcmp0 (info->status, status) != 0) {
- g_free (info->status);
- info->status = g_strdup (status);
-
- info->changed_at_idle = TRUE;
- queue_idle (info, FALSE);
- }
-
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+
+ if (g_strcmp0 (info->status, status) != 0)
+ {
+ g_free (info->status);
+ info->status = g_strdup (status);
+
+ info->changed_at_idle = TRUE;
+ queue_idle (info, FALSE);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_take_details (NautilusProgressInfo *info,
- char *details)
-{
- G_LOCK (progress_info);
-
- if (g_strcmp0 (info->details, details) != 0) {
- g_free (info->details);
- info->details = details;
-
- info->changed_at_idle = TRUE;
- queue_idle (info, FALSE);
- } else {
- g_free (details);
- }
-
- G_UNLOCK (progress_info);
+ char *details)
+{
+ G_LOCK (progress_info);
+
+ if (g_strcmp0 (info->details, details) != 0)
+ {
+ g_free (info->details);
+ info->details = details;
+
+ info->changed_at_idle = TRUE;
+ queue_idle (info, FALSE);
+ }
+ else
+ {
+ g_free (details);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_set_details (NautilusProgressInfo *info,
- const char *details)
+ const char *details)
{
- G_LOCK (progress_info);
-
- if (g_strcmp0 (info->details, details) != 0) {
- g_free (info->details);
- info->details = g_strdup (details);
-
- info->changed_at_idle = TRUE;
- queue_idle (info, FALSE);
- }
-
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+
+ if (g_strcmp0 (info->details, details) != 0)
+ {
+ g_free (info->details);
+ info->details = g_strdup (details);
+
+ info->changed_at_idle = TRUE;
+ queue_idle (info, FALSE);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_pulse_progress (NautilusProgressInfo *info)
{
- G_LOCK (progress_info);
+ G_LOCK (progress_info);
+
+ info->activity_mode = TRUE;
+ info->progress = 0.0;
+ info->progress_at_idle = TRUE;
+ queue_idle (info, FALSE);
- info->activity_mode = TRUE;
- info->progress = 0.0;
- info->progress_at_idle = TRUE;
- queue_idle (info, FALSE);
-
- G_UNLOCK (progress_info);
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_set_progress (NautilusProgressInfo *info,
- double current,
- double total)
-{
- double current_percent;
-
- if (total <= 0) {
- current_percent = 1.0;
- } else {
- current_percent = current / total;
-
- if (current_percent < 0) {
- current_percent = 0;
- }
-
- if (current_percent > 1.0) {
- current_percent = 1.0;
- }
- }
-
- G_LOCK (progress_info);
-
- if (info->activity_mode || /* emit on switch from activity mode */
- fabs (current_percent - info->progress) > 0.005 /* Emit on change of 0.5 percent */
- ) {
- info->activity_mode = FALSE;
- info->progress = current_percent;
- info->progress_at_idle = TRUE;
- queue_idle (info, FALSE);
- }
-
- G_UNLOCK (progress_info);
+ double current,
+ double total)
+{
+ double current_percent;
+
+ if (total <= 0)
+ {
+ current_percent = 1.0;
+ }
+ else
+ {
+ current_percent = current / total;
+
+ if (current_percent < 0)
+ {
+ current_percent = 0;
+ }
+
+ if (current_percent > 1.0)
+ {
+ current_percent = 1.0;
+ }
+ }
+
+ G_LOCK (progress_info);
+
+ if (info->activity_mode || /* emit on switch from activity mode */
+ fabs (current_percent - info->progress) > 0.005 /* Emit on change of 0.5 percent */
+ )
+ {
+ info->activity_mode = FALSE;
+ info->progress = current_percent;
+ info->progress_at_idle = TRUE;
+ queue_idle (info, FALSE);
+ }
+
+ G_UNLOCK (progress_info);
}
void
nautilus_progress_info_set_remaining_time (NautilusProgressInfo *info,
gdouble time)
{
- G_LOCK (progress_info);
- info->remaining_time = time;
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ info->remaining_time = time;
+ G_UNLOCK (progress_info);
}
gdouble
nautilus_progress_info_get_remaining_time (NautilusProgressInfo *info)
{
- gint remaining_time;
+ gint remaining_time;
- G_LOCK (progress_info);
- remaining_time = info->remaining_time;
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ remaining_time = info->remaining_time;
+ G_UNLOCK (progress_info);
- return remaining_time;
+ return remaining_time;
}
void
nautilus_progress_info_set_elapsed_time (NautilusProgressInfo *info,
gdouble time)
{
- G_LOCK (progress_info);
- info->elapsed_time = time;
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ info->elapsed_time = time;
+ G_UNLOCK (progress_info);
}
gdouble
nautilus_progress_info_get_elapsed_time (NautilusProgressInfo *info)
{
- gint elapsed_time;
+ gint elapsed_time;
- G_LOCK (progress_info);
- elapsed_time = info->elapsed_time;
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ elapsed_time = info->elapsed_time;
+ G_UNLOCK (progress_info);
- return elapsed_time;
+ return elapsed_time;
}
gdouble
nautilus_progress_info_get_total_elapsed_time (NautilusProgressInfo *info)
{
- gdouble elapsed_time;
+ gdouble elapsed_time;
- G_LOCK (progress_info);
- elapsed_time = g_timer_elapsed (info->progress_timer, NULL);
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ elapsed_time = g_timer_elapsed (info->progress_timer, NULL);
+ G_UNLOCK (progress_info);
- return elapsed_time;
+ return elapsed_time;
}
void
nautilus_progress_info_set_destination (NautilusProgressInfo *info,
GFile *file)
{
- G_LOCK (progress_info);
- g_clear_object (&info->destination);
- info->destination = g_object_ref (file);
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ g_clear_object (&info->destination);
+ info->destination = g_object_ref (file);
+ G_UNLOCK (progress_info);
}
GFile *
nautilus_progress_info_get_destination (NautilusProgressInfo *info)
{
- GFile *destination = NULL;
+ GFile *destination = NULL;
- G_LOCK (progress_info);
- if (info->destination) {
- destination = g_object_ref (info->destination);
- }
- G_UNLOCK (progress_info);
+ G_LOCK (progress_info);
+ if (info->destination)
+ {
+ destination = g_object_ref (info->destination);
+ }
+ G_UNLOCK (progress_info);
- return destination;
+ return destination;
}
diff --git a/src/nautilus-progress-persistence-handler.c b/src/nautilus-progress-persistence-handler.c
index 3c704cdd2..f2b0a4f40 100644
--- a/src/nautilus-progress-persistence-handler.c
+++ b/src/nautilus-progress-persistence-handler.c
@@ -34,11 +34,12 @@
#include "nautilus-progress-info.h"
#include "nautilus-progress-info-manager.h"
-struct _NautilusProgressPersistenceHandlerPriv {
- NautilusProgressInfoManager *manager;
+struct _NautilusProgressPersistenceHandlerPriv
+{
+ NautilusProgressInfoManager *manager;
- NautilusApplication *app;
- guint active_infos;
+ NautilusApplication *app;
+ guint active_infos;
};
G_DEFINE_TYPE (NautilusProgressPersistenceHandler, nautilus_progress_persistence_handler, G_TYPE_OBJECT);
@@ -65,207 +66,219 @@ static gboolean server_has_persistence (void);
static void
show_file_transfers (NautilusProgressPersistenceHandler *self)
{
- GFile *home;
+ GFile *home;
- home = g_file_new_for_path (g_get_home_dir ());
- nautilus_application_open_location (self->priv->app, home, NULL, NULL);
+ home = g_file_new_for_path (g_get_home_dir ());
+ nautilus_application_open_location (self->priv->app, home, NULL, NULL);
- g_object_unref (home);
+ g_object_unref (home);
}
static void
action_show_file_transfers (GSimpleAction *action,
- GVariant *parameter,
- gpointer user_data)
+ GVariant *parameter,
+ gpointer user_data)
{
- NautilusProgressPersistenceHandler *self;
+ NautilusProgressPersistenceHandler *self;
- self = NAUTILUS_PROGRESS_PERSISTENCE_HANDLER (user_data);
- show_file_transfers (self);
+ self = NAUTILUS_PROGRESS_PERSISTENCE_HANDLER (user_data);
+ show_file_transfers (self);
}
-static GActionEntry progress_persistence_entries[] = {
- { "show-file-transfers", action_show_file_transfers, NULL, NULL, NULL }
+static GActionEntry progress_persistence_entries[] =
+{
+ { "show-file-transfers", action_show_file_transfers, NULL, NULL, NULL }
};
static void
progress_persistence_handler_update_notification (NautilusProgressPersistenceHandler *self)
{
- GNotification *notification;
- gchar *body;
-
- if (!server_has_persistence ()) {
- return;
- }
-
- notification = g_notification_new (_("File Operations"));
- g_notification_set_default_action (notification, "app.show-file-transfers");
- g_notification_add_button (notification, _("Show Details"),
- "app.show-file-transfers");
-
- body = g_strdup_printf (ngettext ("%'d file operation active",
- "%'d file operations active",
- self->priv->active_infos),
- self->priv->active_infos);
- g_notification_set_body (notification, body);
-
- nautilus_application_send_notification (self->priv->app,
- "progress", notification);
-
- g_object_unref (notification);
- g_free (body);
+ GNotification *notification;
+ gchar *body;
+
+ if (!server_has_persistence ())
+ {
+ return;
+ }
+
+ notification = g_notification_new (_("File Operations"));
+ g_notification_set_default_action (notification, "app.show-file-transfers");
+ g_notification_add_button (notification, _("Show Details"),
+ "app.show-file-transfers");
+
+ body = g_strdup_printf (ngettext ("%'d file operation active",
+ "%'d file operations active",
+ self->priv->active_infos),
+ self->priv->active_infos);
+ g_notification_set_body (notification, body);
+
+ nautilus_application_send_notification (self->priv->app,
+ "progress", notification);
+
+ g_object_unref (notification);
+ g_free (body);
}
void
nautilus_progress_persistence_handler_make_persistent (NautilusProgressPersistenceHandler *self)
{
- GList *windows;
-
- windows = nautilus_application_get_windows (self->priv->app);
- if (self->priv->active_infos > 0 &&
- g_list_length (windows) == 0) {
- progress_persistence_handler_update_notification (self);
- }
+ GList *windows;
+
+ windows = nautilus_application_get_windows (self->priv->app);
+ if (self->priv->active_infos > 0 &&
+ g_list_length (windows) == 0)
+ {
+ progress_persistence_handler_update_notification (self);
+ }
}
static void
progress_persistence_handler_show_complete_notification (NautilusProgressPersistenceHandler *self)
{
- GNotification *complete_notification;
+ GNotification *complete_notification;
- if (!server_has_persistence ()) {
- return;
- }
+ if (!server_has_persistence ())
+ {
+ return;
+ }
- complete_notification = g_notification_new (_("File Operations"));
- g_notification_set_body (complete_notification,
- _("All file operations have been successfully completed"));
- nautilus_application_send_notification (self->priv->app,
- "transfer-complete",
- complete_notification);
+ complete_notification = g_notification_new (_("File Operations"));
+ g_notification_set_body (complete_notification,
+ _("All file operations have been successfully completed"));
+ nautilus_application_send_notification (self->priv->app,
+ "transfer-complete",
+ complete_notification);
- g_object_unref (complete_notification);
+ g_object_unref (complete_notification);
}
static void
progress_persistence_handler_hide_notification (NautilusProgressPersistenceHandler *self)
{
- if (!server_has_persistence ()) {
- return;
- }
+ if (!server_has_persistence ())
+ {
+ return;
+ }
- nautilus_application_withdraw_notification (self->priv->app,
- "progress");
+ nautilus_application_withdraw_notification (self->priv->app,
+ "progress");
}
static void
progress_info_finished_cb (NautilusProgressInfo *info,
NautilusProgressPersistenceHandler *self)
{
- GList *windows;
-
- self->priv->active_infos--;
-
- windows = nautilus_application_get_windows (self->priv->app);
- if (self->priv->active_infos > 0) {
- if (g_list_length (windows) == 0) {
- progress_persistence_handler_update_notification (self);
- }
- } else if (g_list_length (windows) == 0) {
- progress_persistence_handler_hide_notification (self);
- progress_persistence_handler_show_complete_notification (self);
- }
+ GList *windows;
+ self->priv->active_infos--;
+
+ windows = nautilus_application_get_windows (self->priv->app);
+ if (self->priv->active_infos > 0)
+ {
+ if (g_list_length (windows) == 0)
+ {
+ progress_persistence_handler_update_notification (self);
+ }
+ }
+ else if (g_list_length (windows) == 0)
+ {
+ progress_persistence_handler_hide_notification (self);
+ progress_persistence_handler_show_complete_notification (self);
+ }
}
static void
handle_new_progress_info (NautilusProgressPersistenceHandler *self,
NautilusProgressInfo *info)
{
- GList *windows;
- g_signal_connect (info, "finished",
- G_CALLBACK (progress_info_finished_cb), self);
+ GList *windows;
+ g_signal_connect (info, "finished",
+ G_CALLBACK (progress_info_finished_cb), self);
- self->priv->active_infos++;
- windows = nautilus_application_get_windows (self->priv->app);
+ self->priv->active_infos++;
+ windows = nautilus_application_get_windows (self->priv->app);
- if (g_list_length (windows) == 0) {
- progress_persistence_handler_update_notification (self);
- }
+ if (g_list_length (windows) == 0)
+ {
+ progress_persistence_handler_update_notification (self);
+ }
}
-typedef struct {
- NautilusProgressInfo *info;
- NautilusProgressPersistenceHandler *self;
+typedef struct
+{
+ NautilusProgressInfo *info;
+ NautilusProgressPersistenceHandler *self;
} TimeoutData;
static void
timeout_data_free (TimeoutData *data)
{
- g_clear_object (&data->self);
- g_clear_object (&data->info);
+ g_clear_object (&data->self);
+ g_clear_object (&data->info);
- g_slice_free (TimeoutData, data);
+ g_slice_free (TimeoutData, data);
}
static TimeoutData *
timeout_data_new (NautilusProgressPersistenceHandler *self,
NautilusProgressInfo *info)
{
- TimeoutData *retval;
+ TimeoutData *retval;
- retval = g_slice_new0 (TimeoutData);
- retval->self = g_object_ref (self);
- retval->info = g_object_ref (info);
+ retval = g_slice_new0 (TimeoutData);
+ retval->self = g_object_ref (self);
+ retval->info = g_object_ref (info);
- return retval;
+ return retval;
}
static gboolean
new_op_started_timeout (TimeoutData *data)
{
- NautilusProgressInfo *info = data->info;
- NautilusProgressPersistenceHandler *self = data->self;
+ NautilusProgressInfo *info = data->info;
+ NautilusProgressPersistenceHandler *self = data->self;
- if (nautilus_progress_info_get_is_paused (info)) {
- return TRUE;
- }
+ if (nautilus_progress_info_get_is_paused (info))
+ {
+ return TRUE;
+ }
- if (!nautilus_progress_info_get_is_finished (info)) {
- handle_new_progress_info (self, info);
- }
+ if (!nautilus_progress_info_get_is_finished (info))
+ {
+ handle_new_progress_info (self, info);
+ }
- timeout_data_free (data);
+ timeout_data_free (data);
- return FALSE;
+ return FALSE;
}
static void
release_application (NautilusProgressInfo *info,
NautilusProgressPersistenceHandler *self)
{
- /* release the GApplication hold we acquired */
- g_application_release (g_application_get_default ());
+ /* release the GApplication hold we acquired */
+ g_application_release (g_application_get_default ());
}
static void
progress_info_started_cb (NautilusProgressInfo *info,
NautilusProgressPersistenceHandler *self)
{
- TimeoutData *data;
+ TimeoutData *data;
- /* hold GApplication so we never quit while there's an operation pending */
- g_application_hold (g_application_get_default ());
+ /* hold GApplication so we never quit while there's an operation pending */
+ g_application_hold (g_application_get_default ());
- g_signal_connect (info, "finished",
- G_CALLBACK (release_application), self);
+ g_signal_connect (info, "finished",
+ G_CALLBACK (release_application), self);
- data = timeout_data_new (self, info);
+ data = timeout_data_new (self, info);
- /* timeout for the progress window to appear */
- g_timeout_add_seconds (2,
- (GSourceFunc) new_op_started_timeout,
- data);
+ /* timeout for the progress window to appear */
+ g_timeout_add_seconds (2,
+ (GSourceFunc) new_op_started_timeout,
+ data);
}
static void
@@ -273,92 +286,99 @@ new_progress_info_cb (NautilusProgressInfoManager *manager,
NautilusProgressInfo *info,
NautilusProgressPersistenceHandler *self)
{
- g_signal_connect (info, "started",
- G_CALLBACK (progress_info_started_cb), self);
+ g_signal_connect (info, "started",
+ G_CALLBACK (progress_info_started_cb), self);
}
static void
nautilus_progress_persistence_handler_dispose (GObject *obj)
{
- NautilusProgressPersistenceHandler *self = NAUTILUS_PROGRESS_PERSISTENCE_HANDLER (obj);
+ NautilusProgressPersistenceHandler *self = NAUTILUS_PROGRESS_PERSISTENCE_HANDLER (obj);
- g_clear_object (&self->priv->manager);
+ g_clear_object (&self->priv->manager);
- G_OBJECT_CLASS (nautilus_progress_persistence_handler_parent_class)->dispose (obj);
+ G_OBJECT_CLASS (nautilus_progress_persistence_handler_parent_class)->dispose (obj);
}
static gboolean
server_has_persistence (void)
{
- static gboolean retval = FALSE;
- GDBusConnection *conn;
- GVariant *result;
- char **cap, **caps;
- static gboolean initialized = FALSE;
-
- if (initialized) {
- return retval;
+ static gboolean retval = FALSE;
+ GDBusConnection *conn;
+ GVariant *result;
+ char **cap, **caps;
+ static gboolean initialized = FALSE;
+
+ if (initialized)
+ {
+ return retval;
+ }
+ initialized = TRUE;
+
+ conn = g_application_get_dbus_connection (g_application_get_default ());
+ result = g_dbus_connection_call_sync (conn,
+ "org.freedesktop.Notifications",
+ "/org/freedesktop/Notifications",
+ "org.freedesktop.Notifications",
+ "GetCapabilities",
+ g_variant_new ("()"),
+ G_VARIANT_TYPE ("(as)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, NULL);
+
+ if (result == NULL)
+ {
+ return FALSE;
+ }
+
+ g_variant_get (result, "(^a&s)", &caps);
+
+ for (cap = caps; *cap != NULL; cap++)
+ {
+ if (g_strcmp0 ("persistence", *cap) == 0)
+ {
+ retval = TRUE;
}
- initialized = TRUE;
+ }
- conn = g_application_get_dbus_connection (g_application_get_default ());
- result = g_dbus_connection_call_sync (conn,
- "org.freedesktop.Notifications",
- "/org/freedesktop/Notifications",
- "org.freedesktop.Notifications",
- "GetCapabilities",
- g_variant_new ("()"),
- G_VARIANT_TYPE ("(as)"),
- G_DBUS_CALL_FLAGS_NONE,
- -1, NULL, NULL);
+ g_free (caps);
+ g_variant_unref (result);
- if (result == NULL)
- return FALSE;
-
- g_variant_get (result, "(^a&s)", &caps);
-
- for (cap = caps; *cap != NULL; cap++)
- if (g_strcmp0 ("persistence", *cap) == 0)
- retval = TRUE;
-
- g_free (caps);
- g_variant_unref (result);
-
- return retval;
+ return retval;
}
static void
nautilus_progress_persistence_handler_init (NautilusProgressPersistenceHandler *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_PERSISTENCE_HANDLER,
- NautilusProgressPersistenceHandlerPriv);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_PROGRESS_PERSISTENCE_HANDLER,
+ NautilusProgressPersistenceHandlerPriv);
- self->priv->manager = nautilus_progress_info_manager_dup_singleton ();
- g_signal_connect (self->priv->manager, "new-progress-info",
- G_CALLBACK (new_progress_info_cb), self);
+ self->priv->manager = nautilus_progress_info_manager_dup_singleton ();
+ g_signal_connect (self->priv->manager, "new-progress-info",
+ G_CALLBACK (new_progress_info_cb), self);
}
static void
nautilus_progress_persistence_handler_class_init (NautilusProgressPersistenceHandlerClass *klass)
{
- GObjectClass *oclass;
+ GObjectClass *oclass;
- oclass = G_OBJECT_CLASS (klass);
- oclass->dispose = nautilus_progress_persistence_handler_dispose;
+ oclass = G_OBJECT_CLASS (klass);
+ oclass->dispose = nautilus_progress_persistence_handler_dispose;
- g_type_class_add_private (klass, sizeof (NautilusProgressPersistenceHandlerPriv));
+ g_type_class_add_private (klass, sizeof (NautilusProgressPersistenceHandlerPriv));
}
NautilusProgressPersistenceHandler *
nautilus_progress_persistence_handler_new (GObject *app)
{
- NautilusProgressPersistenceHandler *self;
+ NautilusProgressPersistenceHandler *self;
- self = g_object_new (NAUTILUS_TYPE_PROGRESS_PERSISTENCE_HANDLER, NULL);
- self->priv->app = NAUTILUS_APPLICATION (app);
+ self = g_object_new (NAUTILUS_TYPE_PROGRESS_PERSISTENCE_HANDLER, NULL);
+ self->priv->app = NAUTILUS_APPLICATION (app);
- g_action_map_add_action_entries (G_ACTION_MAP (self->priv->app),
- progress_persistence_entries, G_N_ELEMENTS (progress_persistence_entries),
- self);
- return self;
+ g_action_map_add_action_entries (G_ACTION_MAP (self->priv->app),
+ progress_persistence_entries, G_N_ELEMENTS (progress_persistence_entries),
+ self);
+ return self;
}
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 2fb33c74e..1ef0dd782 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -1,24 +1,23 @@
-
/* fm-properties-window.c - window that lets user modify file properties
-
- Copyright (C) 2000 Eazel, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Darin Adler <darin@bentspoon.com>
-*/
+ *
+ * Copyright (C) 2000 Eazel, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
@@ -73,106 +72,113 @@
static GHashTable *windows;
static GHashTable *pending_lists;
-typedef struct {
- NautilusFile *file;
- char *owner;
- GtkWindow *window;
- unsigned int timeout;
- gboolean cancelled;
+typedef struct
+{
+ NautilusFile *file;
+ char *owner;
+ GtkWindow *window;
+ unsigned int timeout;
+ gboolean cancelled;
} OwnerChange;
-typedef struct {
- NautilusFile *file;
- char *group;
- GtkWindow *window;
- unsigned int timeout;
- gboolean cancelled;
+typedef struct
+{
+ NautilusFile *file;
+ char *group;
+ GtkWindow *window;
+ unsigned int timeout;
+ gboolean cancelled;
} GroupChange;
-struct NautilusPropertiesWindowDetails {
- GList *original_files;
- GList *target_files;
-
- GtkNotebook *notebook;
-
- GtkGrid *basic_grid;
+struct NautilusPropertiesWindowDetails
+{
+ GList *original_files;
+ GList *target_files;
+
+ GtkNotebook *notebook;
- GtkWidget *icon_button;
- GtkWidget *icon_image;
- GtkWidget *icon_chooser;
+ GtkGrid *basic_grid;
- GtkLabel *name_label;
- GtkWidget *name_field;
- unsigned int name_row;
- char *pending_name;
+ GtkWidget *icon_button;
+ GtkWidget *icon_image;
+ GtkWidget *icon_chooser;
- GtkLabel *directory_contents_title_field;
- GtkLabel *directory_contents_value_field;
- GtkWidget *directory_contents_spinner;
- guint update_directory_contents_timeout_id;
- guint update_files_timeout_id;
+ GtkLabel *name_label;
+ GtkWidget *name_field;
+ unsigned int name_row;
+ char *pending_name;
- GroupChange *group_change;
- OwnerChange *owner_change;
+ GtkLabel *directory_contents_title_field;
+ GtkLabel *directory_contents_value_field;
+ GtkWidget *directory_contents_spinner;
+ guint update_directory_contents_timeout_id;
+ guint update_files_timeout_id;
- GList *permission_buttons;
- GList *permission_combos;
- GList *change_permission_combos;
- GHashTable *initial_permissions;
- gboolean has_recursive_apply;
+ GroupChange *group_change;
+ OwnerChange *owner_change;
- GList *value_fields;
+ GList *permission_buttons;
+ GList *permission_combos;
+ GList *change_permission_combos;
+ GHashTable *initial_permissions;
+ gboolean has_recursive_apply;
- GList *mime_list;
+ GList *value_fields;
- gboolean deep_count_finished;
- GList *deep_count_files;
- guint deep_count_spinner_timeout_id;
+ GList *mime_list;
- guint total_count;
- goffset total_size;
+ gboolean deep_count_finished;
+ GList *deep_count_files;
+ guint deep_count_spinner_timeout_id;
- guint long_operation_underway;
+ guint total_count;
+ goffset total_size;
- GList *changed_files;
+ guint long_operation_underway;
- guint64 volume_capacity;
- guint64 volume_free;
- guint64 volume_used;
+ GList *changed_files;
+
+ guint64 volume_capacity;
+ guint64 volume_free;
+ guint64 volume_used;
};
-enum {
- COLUMN_NAME,
- COLUMN_VALUE,
- COLUMN_USE_ORIGINAL,
- COLUMN_ID,
- NUM_COLUMNS
+enum
+{
+ COLUMN_NAME,
+ COLUMN_VALUE,
+ COLUMN_USE_ORIGINAL,
+ COLUMN_ID,
+ NUM_COLUMNS
};
-typedef struct {
- GList *original_files;
- GList *target_files;
- GtkWidget *parent_widget;
- GtkWindow *parent_window;
- char *startup_id;
- char *pending_key;
- GHashTable *pending_files;
+typedef struct
+{
+ GList *original_files;
+ GList *target_files;
+ GtkWidget *parent_widget;
+ GtkWindow *parent_window;
+ char *startup_id;
+ char *pending_key;
+ GHashTable *pending_files;
} StartupData;
/* drag and drop definitions */
-enum {
- TARGET_URI_LIST,
- TARGET_GNOME_URI_LIST,
+enum
+{
+ TARGET_URI_LIST,
+ TARGET_GNOME_URI_LIST,
};
-static const GtkTargetEntry target_table[] = {
- { "text/uri-list", 0, TARGET_URI_LIST },
- { "x-special/gnome-icon-list", 0, TARGET_GNOME_URI_LIST },
+static const GtkTargetEntry target_table[] =
+{
+ { "text/uri-list", 0, TARGET_URI_LIST },
+ { "x-special/gnome-icon-list", 0, TARGET_GNOME_URI_LIST },
};
-#define DIRECTORY_CONTENTS_UPDATE_INTERVAL 200 /* milliseconds */
-#define FILES_UPDATE_INTERVAL 200 /* milliseconds */
+#define DIRECTORY_CONTENTS_UPDATE_INTERVAL 200 /* milliseconds */
+#define FILES_UPDATE_INTERVAL 200 /* milliseconds */
/*
* A timeout before changes through the user/group combo box will be applied.
@@ -182,1369 +188,1528 @@ static const GtkTargetEntry target_table[] = {
* Both combos react on changes by scheduling a new change and unscheduling
* or cancelling old pending changes.
*/
-#define CHOWN_CHGRP_TIMEOUT 300 /* milliseconds */
+#define CHOWN_CHGRP_TIMEOUT 300 /* milliseconds */
-static void schedule_directory_contents_update (NautilusPropertiesWindow *window);
+static void schedule_directory_contents_update (NautilusPropertiesWindow *window);
static void directory_contents_value_field_update (NautilusPropertiesWindow *window);
-static void file_changed_callback (NautilusFile *file,
- gpointer user_data);
-static void permission_button_update (NautilusPropertiesWindow *window,
- GtkToggleButton *button);
-static void permission_combo_update (NautilusPropertiesWindow *window,
- GtkComboBox *combo);
-static void value_field_update (NautilusPropertiesWindow *window,
- GtkLabel *field);
-static void properties_window_update (NautilusPropertiesWindow *window,
- GList *files);
-static void is_directory_ready_callback (NautilusFile *file,
- gpointer data);
-static void cancel_group_change_callback (GroupChange *change);
-static void cancel_owner_change_callback (OwnerChange *change);
-static void parent_widget_destroyed_callback (GtkWidget *widget,
- gpointer callback_data);
-static void select_image_button_callback (GtkWidget *widget,
- NautilusPropertiesWindow *properties_window);
-static void set_icon (const char *icon_path,
- NautilusPropertiesWindow *properties_window);
-static void remove_pending (StartupData *data,
- gboolean cancel_call_when_ready,
- gboolean cancel_timed_wait,
- gboolean cancel_destroy_handler);
-static void append_extension_pages (NautilusPropertiesWindow *window);
-
-static gboolean name_field_focus_out (NautilusEntry *name_field,
- GdkEventFocus *event,
- gpointer callback_data);
-static void name_field_activate (NautilusEntry *name_field,
- gpointer callback_data);
-static GtkLabel *attach_ellipsizing_value_label (GtkGrid *grid,
- GtkWidget *sibling,
- const char *initial_text);
-
-static GtkWidget* create_pie_widget (NautilusPropertiesWindow *window);
+static void file_changed_callback (NautilusFile *file,
+ gpointer user_data);
+static void permission_button_update (NautilusPropertiesWindow *window,
+ GtkToggleButton *button);
+static void permission_combo_update (NautilusPropertiesWindow *window,
+ GtkComboBox *combo);
+static void value_field_update (NautilusPropertiesWindow *window,
+ GtkLabel *field);
+static void properties_window_update (NautilusPropertiesWindow *window,
+ GList *files);
+static void is_directory_ready_callback (NautilusFile *file,
+ gpointer data);
+static void cancel_group_change_callback (GroupChange *change);
+static void cancel_owner_change_callback (OwnerChange *change);
+static void parent_widget_destroyed_callback (GtkWidget *widget,
+ gpointer callback_data);
+static void select_image_button_callback (GtkWidget *widget,
+ NautilusPropertiesWindow *properties_window);
+static void set_icon (const char *icon_path,
+ NautilusPropertiesWindow *properties_window);
+static void remove_pending (StartupData *data,
+ gboolean cancel_call_when_ready,
+ gboolean cancel_timed_wait,
+ gboolean cancel_destroy_handler);
+static void append_extension_pages (NautilusPropertiesWindow *window);
+
+static gboolean name_field_focus_out (NautilusEntry *name_field,
+ GdkEventFocus *event,
+ gpointer callback_data);
+static void name_field_activate (NautilusEntry *name_field,
+ gpointer callback_data);
+static GtkLabel *attach_ellipsizing_value_label (GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *initial_text);
+
+static GtkWidget *create_pie_widget (NautilusPropertiesWindow *window);
G_DEFINE_TYPE (NautilusPropertiesWindow, nautilus_properties_window, GTK_TYPE_DIALOG);
static gboolean
is_multi_file_window (NautilusPropertiesWindow *window)
{
- GList *l;
- int count;
-
- count = 0;
-
- for (l = window->details->original_files; l != NULL; l = l->next) {
- if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data))) {
- count++;
- if (count > 1) {
- return TRUE;
- }
- }
- }
+ GList *l;
+ int count;
- return FALSE;
+ count = 0;
+
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data)))
+ {
+ count++;
+ if (count > 1)
+ {
+ return TRUE;
+ }
+ }
+ }
+
+ return FALSE;
}
static int
get_not_gone_original_file_count (NautilusPropertiesWindow *window)
{
- GList *l;
- int count;
+ GList *l;
+ int count;
- count = 0;
+ count = 0;
- for (l = window->details->original_files; l != NULL; l = l->next) {
- if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data))) {
- count++;
- }
- }
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ if (!nautilus_file_is_gone (NAUTILUS_FILE (l->data)))
+ {
+ count++;
+ }
+ }
- return count;
+ return count;
}
static NautilusFile *
-get_original_file (NautilusPropertiesWindow *window)
+get_original_file (NautilusPropertiesWindow *window)
{
- g_return_val_if_fail (!is_multi_file_window (window), NULL);
+ g_return_val_if_fail (!is_multi_file_window (window), NULL);
- if (window->details->original_files == NULL) {
- return NULL;
- }
+ if (window->details->original_files == NULL)
+ {
+ return NULL;
+ }
- return NAUTILUS_FILE (window->details->original_files->data);
+ return NAUTILUS_FILE (window->details->original_files->data);
}
static NautilusFile *
get_target_file_for_original_file (NautilusFile *file)
{
- NautilusFile *target_file;
- g_autoptr (GFile) location;
- g_autofree char *uri_to_display;
+ NautilusFile *target_file;
+ g_autoptr (GFile) location;
+ g_autofree char *uri_to_display;
- uri_to_display = nautilus_file_get_target_uri (file);
- location = g_file_new_for_uri (uri_to_display);
- target_file = nautilus_file_get (location);
+ uri_to_display = nautilus_file_get_target_uri (file);
+ location = g_file_new_for_uri (uri_to_display);
+ target_file = nautilus_file_get (location);
- return target_file;
+ return target_file;
}
static NautilusFile *
get_target_file (NautilusPropertiesWindow *window)
{
- return NAUTILUS_FILE (window->details->target_files->data);
+ return NAUTILUS_FILE (window->details->target_files->data);
}
static void
-add_prompt (GtkWidget *vbox, const char *prompt_text, gboolean pack_at_start)
-{
- GtkWidget *prompt;
-
- prompt = gtk_label_new (prompt_text);
- gtk_label_set_justify (GTK_LABEL (prompt), GTK_JUSTIFY_LEFT);
- gtk_label_set_line_wrap (GTK_LABEL (prompt), TRUE);
- gtk_widget_show (prompt);
- if (pack_at_start) {
- gtk_box_pack_start (GTK_BOX (vbox), prompt, FALSE, FALSE, 0);
- } else {
- gtk_box_pack_end (GTK_BOX (vbox), prompt, FALSE, FALSE, 0);
- }
+add_prompt (GtkWidget *vbox,
+ const char *prompt_text,
+ gboolean pack_at_start)
+{
+ GtkWidget *prompt;
+
+ prompt = gtk_label_new (prompt_text);
+ gtk_label_set_justify (GTK_LABEL (prompt), GTK_JUSTIFY_LEFT);
+ gtk_label_set_line_wrap (GTK_LABEL (prompt), TRUE);
+ gtk_widget_show (prompt);
+ if (pack_at_start)
+ {
+ gtk_box_pack_start (GTK_BOX (vbox), prompt, FALSE, FALSE, 0);
+ }
+ else
+ {
+ gtk_box_pack_end (GTK_BOX (vbox), prompt, FALSE, FALSE, 0);
+ }
}
static void
-add_prompt_and_separator (GtkWidget *vbox, const char *prompt_text)
+add_prompt_and_separator (GtkWidget *vbox,
+ const char *prompt_text)
{
- GtkWidget *separator_line;
+ GtkWidget *separator_line;
- add_prompt (vbox, prompt_text, FALSE);
+ add_prompt (vbox, prompt_text, FALSE);
- separator_line = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_widget_show (separator_line);
- gtk_box_pack_end (GTK_BOX (vbox), separator_line, TRUE, TRUE, 2*ROW_PAD);
+ separator_line = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_show (separator_line);
+ gtk_box_pack_end (GTK_BOX (vbox), separator_line, TRUE, TRUE, 2 * ROW_PAD);
}
static void
-get_image_for_properties_window (NautilusPropertiesWindow *window,
- char **icon_name,
- GdkPixbuf **icon_pixbuf)
-{
- NautilusIconInfo *icon, *new_icon;
- GList *l;
- gint icon_scale;
-
- icon = NULL;
- icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (window->details->notebook));
-
- for (l = window->details->original_files; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
-
- if (!icon) {
- icon = nautilus_file_get_icon (file, NAUTILUS_CANVAS_ICON_SIZE_SMALL, icon_scale,
- NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
- NAUTILUS_FILE_ICON_FLAGS_IGNORE_VISITING);
- } else {
- new_icon = nautilus_file_get_icon (file, NAUTILUS_CANVAS_ICON_SIZE_SMALL, icon_scale,
- NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
- NAUTILUS_FILE_ICON_FLAGS_IGNORE_VISITING);
- if (!new_icon || new_icon != icon) {
- g_object_unref (icon);
- g_object_unref (new_icon);
- icon = NULL;
- break;
- }
- g_object_unref (new_icon);
- }
- }
-
- if (!icon) {
- icon = nautilus_icon_info_lookup_from_name ("text-x-generic",
- NAUTILUS_CANVAS_ICON_SIZE_STANDARD,
- icon_scale);
- }
-
- if (icon_name != NULL) {
- *icon_name = g_strdup (nautilus_icon_info_get_used_name (icon));
- }
-
- if (icon_pixbuf != NULL) {
- *icon_pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon, NAUTILUS_CANVAS_ICON_SIZE_SMALL);
- }
-
- g_object_unref (icon);
+get_image_for_properties_window (NautilusPropertiesWindow *window,
+ char **icon_name,
+ GdkPixbuf **icon_pixbuf)
+{
+ NautilusIconInfo *icon, *new_icon;
+ GList *l;
+ gint icon_scale;
+
+ icon = NULL;
+ icon_scale = gtk_widget_get_scale_factor (GTK_WIDGET (window->details->notebook));
+
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (!icon)
+ {
+ icon = nautilus_file_get_icon (file, NAUTILUS_CANVAS_ICON_SIZE_SMALL, icon_scale,
+ NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
+ NAUTILUS_FILE_ICON_FLAGS_IGNORE_VISITING);
+ }
+ else
+ {
+ new_icon = nautilus_file_get_icon (file, NAUTILUS_CANVAS_ICON_SIZE_SMALL, icon_scale,
+ NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS |
+ NAUTILUS_FILE_ICON_FLAGS_IGNORE_VISITING);
+ if (!new_icon || new_icon != icon)
+ {
+ g_object_unref (icon);
+ g_object_unref (new_icon);
+ icon = NULL;
+ break;
+ }
+ g_object_unref (new_icon);
+ }
+ }
+
+ if (!icon)
+ {
+ icon = nautilus_icon_info_lookup_from_name ("text-x-generic",
+ NAUTILUS_CANVAS_ICON_SIZE_STANDARD,
+ icon_scale);
+ }
+
+ if (icon_name != NULL)
+ {
+ *icon_name = g_strdup (nautilus_icon_info_get_used_name (icon));
+ }
+
+ if (icon_pixbuf != NULL)
+ {
+ *icon_pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon, NAUTILUS_CANVAS_ICON_SIZE_SMALL);
+ }
+
+ g_object_unref (icon);
}
static void
update_properties_window_icon (NautilusPropertiesWindow *window)
{
- GdkPixbuf *pixbuf;
- cairo_surface_t *surface;
- char *name;
+ GdkPixbuf *pixbuf;
+ cairo_surface_t *surface;
+ char *name;
- get_image_for_properties_window (window, &name, &pixbuf);
+ get_image_for_properties_window (window, &name, &pixbuf);
- if (name != NULL) {
- gtk_window_set_icon_name (GTK_WINDOW (window), name);
- } else {
- gtk_window_set_icon (GTK_WINDOW (window), pixbuf);
- }
+ if (name != NULL)
+ {
+ gtk_window_set_icon_name (GTK_WINDOW (window), name);
+ }
+ else
+ {
+ gtk_window_set_icon (GTK_WINDOW (window), pixbuf);
+ }
- surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, gtk_widget_get_scale_factor (GTK_WIDGET (window)),
- gtk_widget_get_window (GTK_WIDGET (window)));
- gtk_image_set_from_surface (GTK_IMAGE (window->details->icon_image), surface);
+ surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, gtk_widget_get_scale_factor (GTK_WIDGET (window)),
+ gtk_widget_get_window (GTK_WIDGET (window)));
+ gtk_image_set_from_surface (GTK_IMAGE (window->details->icon_image), surface);
- g_free (name);
- g_object_unref (pixbuf);
- cairo_surface_destroy (surface);
+ g_free (name);
+ g_object_unref (pixbuf);
+ cairo_surface_destroy (surface);
}
/* utility to test if a uri refers to a local image */
static gboolean
uri_is_local_image (const char *uri)
{
- GdkPixbuf *pixbuf;
- char *image_path;
-
- image_path = g_filename_from_uri (uri, NULL, NULL);
- if (image_path == NULL) {
- return FALSE;
- }
+ GdkPixbuf *pixbuf;
+ char *image_path;
+
+ image_path = g_filename_from_uri (uri, NULL, NULL);
+ if (image_path == NULL)
+ {
+ return FALSE;
+ }
- pixbuf = gdk_pixbuf_new_from_file (image_path, NULL);
- g_free (image_path);
-
- if (pixbuf == NULL) {
- return FALSE;
- }
- g_object_unref (pixbuf);
- return TRUE;
+ pixbuf = gdk_pixbuf_new_from_file (image_path, NULL);
+ g_free (image_path);
+
+ if (pixbuf == NULL)
+ {
+ return FALSE;
+ }
+ g_object_unref (pixbuf);
+ return TRUE;
}
static void
reset_icon (NautilusPropertiesWindow *properties_window)
{
- GList *l;
-
- for (l = properties_window->details->original_files; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
-
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_ICON_SCALE,
- NULL, NULL);
- nautilus_file_set_metadata (file,
- NAUTILUS_METADATA_KEY_CUSTOM_ICON,
- NULL, NULL);
- }
-}
-
-
-static void
-nautilus_properties_window_drag_data_received (GtkWidget *widget, GdkDragContext *context,
- int x, int y,
- GtkSelectionData *selection_data,
- guint info, guint time)
-{
- char **uris;
- gboolean exactly_one;
- GtkImage *image;
- GtkWindow *window;
-
- image = GTK_IMAGE (widget);
- window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (image)));
-
- uris = g_strsplit ((const gchar *) gtk_selection_data_get_data (selection_data), "\r\n", 0);
- exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
-
-
- if (!exactly_one) {
- eel_show_error_dialog
- (_("You cannot assign more than one custom icon at a time!"),
- _("Please drop just one image to set a custom icon."),
- window);
- } else {
- if (uri_is_local_image (uris[0])) {
- set_icon (uris[0], NAUTILUS_PROPERTIES_WINDOW (window));
- } else {
- GFile *f;
-
- f = g_file_new_for_uri (uris[0]);
- if (!g_file_is_native (f)) {
- eel_show_error_dialog
- (_("The file that you dropped is not local."),
- _("You can only use local images as custom icons."),
- window);
-
- } else {
- eel_show_error_dialog
- (_("The file that you dropped is not an image."),
- _("You can only use local images as custom icons."),
- window);
- }
- g_object_unref (f);
- }
- }
- g_strfreev (uris);
+ GList *l;
+
+ for (l = properties_window->details->original_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+
+ file = NAUTILUS_FILE (l->data);
+
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_ICON_SCALE,
+ NULL, NULL);
+ nautilus_file_set_metadata (file,
+ NAUTILUS_METADATA_KEY_CUSTOM_ICON,
+ NULL, NULL);
+ }
+}
+
+
+static void
+nautilus_properties_window_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ char **uris;
+ gboolean exactly_one;
+ GtkImage *image;
+ GtkWindow *window;
+
+ image = GTK_IMAGE (widget);
+ window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (image)));
+
+ uris = g_strsplit ((const gchar *) gtk_selection_data_get_data (selection_data), "\r\n", 0);
+ exactly_one = uris[0] != NULL && (uris[1] == NULL || uris[1][0] == '\0');
+
+
+ if (!exactly_one)
+ {
+ eel_show_error_dialog
+ (_("You cannot assign more than one custom icon at a time!"),
+ _("Please drop just one image to set a custom icon."),
+ window);
+ }
+ else
+ {
+ if (uri_is_local_image (uris[0]))
+ {
+ set_icon (uris[0], NAUTILUS_PROPERTIES_WINDOW (window));
+ }
+ else
+ {
+ GFile *f;
+
+ f = g_file_new_for_uri (uris[0]);
+ if (!g_file_is_native (f))
+ {
+ eel_show_error_dialog
+ (_("The file that you dropped is not local."),
+ _("You can only use local images as custom icons."),
+ window);
+ }
+ else
+ {
+ eel_show_error_dialog
+ (_("The file that you dropped is not an image."),
+ _("You can only use local images as custom icons."),
+ window);
+ }
+ g_object_unref (f);
+ }
+ }
+ g_strfreev (uris);
}
static GtkWidget *
create_image_widget (NautilusPropertiesWindow *window,
- gboolean is_customizable)
+ gboolean is_customizable)
{
- GtkWidget *button;
- GtkWidget *image;
-
- image = gtk_image_new ();
- window->details->icon_image = image;
+ GtkWidget *button;
+ GtkWidget *image;
- update_properties_window_icon (window);
- gtk_widget_show (image);
+ image = gtk_image_new ();
+ window->details->icon_image = image;
- button = NULL;
- if (is_customizable) {
- button = gtk_button_new ();
- gtk_container_add (GTK_CONTAINER (button), image);
+ update_properties_window_icon (window);
+ gtk_widget_show (image);
- /* prepare the image to receive dropped objects to assign custom images */
- gtk_drag_dest_set (GTK_WIDGET (image),
- GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
- target_table, G_N_ELEMENTS (target_table),
- GDK_ACTION_COPY | GDK_ACTION_MOVE);
+ button = NULL;
+ if (is_customizable)
+ {
+ button = gtk_button_new ();
+ gtk_container_add (GTK_CONTAINER (button), image);
- g_signal_connect (image, "drag-data-received",
- G_CALLBACK (nautilus_properties_window_drag_data_received), NULL);
- g_signal_connect (button, "clicked",
- G_CALLBACK (select_image_button_callback), window);
- }
+ /* prepare the image to receive dropped objects to assign custom images */
+ gtk_drag_dest_set (GTK_WIDGET (image),
+ GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
+ target_table, G_N_ELEMENTS (target_table),
+ GDK_ACTION_COPY | GDK_ACTION_MOVE);
- window->details->icon_button = button;
+ g_signal_connect (image, "drag-data-received",
+ G_CALLBACK (nautilus_properties_window_drag_data_received), NULL);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (select_image_button_callback), window);
+ }
- return button != NULL ? button : image;
+ window->details->icon_button = button;
+
+ return button != NULL ? button : image;
}
static void
set_name_field (NautilusPropertiesWindow *window,
- const gchar *original_name,
- const gchar *name)
-{
- gboolean new_widget;
- gboolean use_label;
-
- /* There are four cases here:
- * 1) Changing the text of a label
- * 2) Changing the text of an entry
- * 3) Creating label (potentially replacing entry)
- * 4) Creating entry (potentially replacing label)
- */
- use_label = is_multi_file_window (window) || !nautilus_file_can_rename (get_original_file (window));
- new_widget = !window->details->name_field || (use_label ? NAUTILUS_IS_ENTRY (window->details->name_field) : GTK_IS_LABEL (window->details->name_field));
-
- if (new_widget) {
- if (window->details->name_field) {
- gtk_widget_destroy (window->details->name_field);
- }
-
- if (use_label) {
- window->details->name_field = GTK_WIDGET
- (attach_ellipsizing_value_label (window->details->basic_grid,
- GTK_WIDGET (window->details->name_label),
- name));
- } else {
- window->details->name_field = nautilus_entry_new ();
- gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name);
- gtk_widget_show (window->details->name_field);
-
- gtk_grid_attach_next_to (window->details->basic_grid, window->details->name_field,
- GTK_WIDGET (window->details->name_label),
- GTK_POS_RIGHT, 1, 1);
- gtk_label_set_mnemonic_widget (GTK_LABEL (window->details->name_label), window->details->name_field);
-
- g_signal_connect_object (window->details->name_field, "focus-out-event",
- G_CALLBACK (name_field_focus_out), window, 0);
- g_signal_connect_object (window->details->name_field, "activate",
- G_CALLBACK (name_field_activate), window, 0);
- }
-
- gtk_widget_show (window->details->name_field);
- }
- /* Only replace text if the file's name has changed. */
- else if (original_name == NULL || strcmp (original_name, name) != 0) {
-
- if (use_label) {
- gtk_label_set_text (GTK_LABEL (window->details->name_field), name);
- } else {
- /* Only reset the text if it's different from what is
- * currently showing. This causes minimal ripples (e.g.
- * selection change).
- */
- gchar *displayed_name = gtk_editable_get_chars (GTK_EDITABLE (window->details->name_field), 0, -1);
- if (strcmp (displayed_name, name) != 0) {
- gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name);
- }
- g_free (displayed_name);
- }
- }
+ const gchar *original_name,
+ const gchar *name)
+{
+ gboolean new_widget;
+ gboolean use_label;
+
+ /* There are four cases here:
+ * 1) Changing the text of a label
+ * 2) Changing the text of an entry
+ * 3) Creating label (potentially replacing entry)
+ * 4) Creating entry (potentially replacing label)
+ */
+ use_label = is_multi_file_window (window) || !nautilus_file_can_rename (get_original_file (window));
+ new_widget = !window->details->name_field || (use_label ? NAUTILUS_IS_ENTRY (window->details->name_field) : GTK_IS_LABEL (window->details->name_field));
+
+ if (new_widget)
+ {
+ if (window->details->name_field)
+ {
+ gtk_widget_destroy (window->details->name_field);
+ }
+
+ if (use_label)
+ {
+ window->details->name_field = GTK_WIDGET
+ (attach_ellipsizing_value_label (window->details->basic_grid,
+ GTK_WIDGET (window->details->name_label),
+ name));
+ }
+ else
+ {
+ window->details->name_field = nautilus_entry_new ();
+ gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name);
+ gtk_widget_show (window->details->name_field);
+
+ gtk_grid_attach_next_to (window->details->basic_grid, window->details->name_field,
+ GTK_WIDGET (window->details->name_label),
+ GTK_POS_RIGHT, 1, 1);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (window->details->name_label), window->details->name_field);
+
+ g_signal_connect_object (window->details->name_field, "focus-out-event",
+ G_CALLBACK (name_field_focus_out), window, 0);
+ g_signal_connect_object (window->details->name_field, "activate",
+ G_CALLBACK (name_field_activate), window, 0);
+ }
+
+ gtk_widget_show (window->details->name_field);
+ }
+ /* Only replace text if the file's name has changed. */
+ else if (original_name == NULL || strcmp (original_name, name) != 0)
+ {
+ if (use_label)
+ {
+ gtk_label_set_text (GTK_LABEL (window->details->name_field), name);
+ }
+ else
+ {
+ /* Only reset the text if it's different from what is
+ * currently showing. This causes minimal ripples (e.g.
+ * selection change).
+ */
+ gchar *displayed_name = gtk_editable_get_chars (GTK_EDITABLE (window->details->name_field), 0, -1);
+ if (strcmp (displayed_name, name) != 0)
+ {
+ gtk_entry_set_text (GTK_ENTRY (window->details->name_field), name);
+ }
+ g_free (displayed_name);
+ }
+ }
}
static void
update_name_field (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
-
- gtk_label_set_text_with_mnemonic (window->details->name_label,
- ngettext ("_Name:", "_Names:",
- get_not_gone_original_file_count (window)));
-
- if (is_multi_file_window (window)) {
- /* Multifile property dialog, show all names */
- GString *str;
- char *name;
- gboolean first;
- GList *l;
-
- str = g_string_new ("");
-
- first = TRUE;
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (!nautilus_file_is_gone (file)) {
- if (!first) {
- g_string_append (str, ", ");
- }
- first = FALSE;
-
- name = nautilus_file_get_display_name (file);
- g_string_append (str, name);
- g_free (name);
- }
- }
- set_name_field (window, NULL, str->str);
- g_string_free (str, TRUE);
- } else {
- const char *original_name = NULL;
- char *current_name;
-
- file = get_original_file (window);
-
- if (file == NULL || nautilus_file_is_gone (file)) {
- current_name = g_strdup ("");
- } else {
- current_name = nautilus_file_get_display_name (file);
- }
-
- /* If the file name has changed since the original name was stored,
- * update the text in the text field, possibly (deliberately) clobbering
- * an edit in progress. If the name hasn't changed (but some other
- * aspect of the file might have), then don't clobber changes.
- */
- if (window->details->name_field) {
- original_name = (const char *) g_object_get_data (G_OBJECT (window->details->name_field), "original_name");
- }
-
- set_name_field (window, original_name, current_name);
-
- if (original_name == NULL ||
- g_strcmp0 (original_name, current_name) != 0) {
- g_object_set_data_full (G_OBJECT (window->details->name_field),
- "original_name",
- current_name,
- g_free);
- } else {
- g_free (current_name);
- }
- }
+ NautilusFile *file;
+
+ gtk_label_set_text_with_mnemonic (window->details->name_label,
+ ngettext ("_Name:", "_Names:",
+ get_not_gone_original_file_count (window)));
+
+ if (is_multi_file_window (window))
+ {
+ /* Multifile property dialog, show all names */
+ GString *str;
+ char *name;
+ gboolean first;
+ GList *l;
+
+ str = g_string_new ("");
+
+ first = TRUE;
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (!nautilus_file_is_gone (file))
+ {
+ if (!first)
+ {
+ g_string_append (str, ", ");
+ }
+ first = FALSE;
+
+ name = nautilus_file_get_display_name (file);
+ g_string_append (str, name);
+ g_free (name);
+ }
+ }
+ set_name_field (window, NULL, str->str);
+ g_string_free (str, TRUE);
+ }
+ else
+ {
+ const char *original_name = NULL;
+ char *current_name;
+
+ file = get_original_file (window);
+
+ if (file == NULL || nautilus_file_is_gone (file))
+ {
+ current_name = g_strdup ("");
+ }
+ else
+ {
+ current_name = nautilus_file_get_display_name (file);
+ }
+
+ /* If the file name has changed since the original name was stored,
+ * update the text in the text field, possibly (deliberately) clobbering
+ * an edit in progress. If the name hasn't changed (but some other
+ * aspect of the file might have), then don't clobber changes.
+ */
+ if (window->details->name_field)
+ {
+ original_name = (const char *) g_object_get_data (G_OBJECT (window->details->name_field), "original_name");
+ }
+
+ set_name_field (window, original_name, current_name);
+
+ if (original_name == NULL ||
+ g_strcmp0 (original_name, current_name) != 0)
+ {
+ g_object_set_data_full (G_OBJECT (window->details->name_field),
+ "original_name",
+ current_name,
+ g_free);
+ }
+ else
+ {
+ g_free (current_name);
+ }
+ }
}
static void
name_field_restore_original_name (NautilusEntry *name_field)
{
- const char *original_name;
- char *displayed_name;
+ const char *original_name;
+ char *displayed_name;
- original_name = (const char *) g_object_get_data (G_OBJECT (name_field),
- "original_name");
+ original_name = (const char *) g_object_get_data (G_OBJECT (name_field),
+ "original_name");
- if (!original_name) {
- return;
- }
+ if (!original_name)
+ {
+ return;
+ }
- displayed_name = gtk_editable_get_chars (GTK_EDITABLE (name_field), 0, -1);
+ displayed_name = gtk_editable_get_chars (GTK_EDITABLE (name_field), 0, -1);
- if (strcmp (original_name, displayed_name) != 0) {
- gtk_entry_set_text (GTK_ENTRY (name_field), original_name);
- }
- nautilus_entry_select_all (name_field);
+ if (strcmp (original_name, displayed_name) != 0)
+ {
+ gtk_entry_set_text (GTK_ENTRY (name_field), original_name);
+ }
+ nautilus_entry_select_all (name_field);
- g_free (displayed_name);
+ g_free (displayed_name);
}
static void
-rename_callback (NautilusFile *file, GFile *res_loc, GError *error, gpointer callback_data)
+rename_callback (NautilusFile *file,
+ GFile *res_loc,
+ GError *error,
+ gpointer callback_data)
{
- NautilusPropertiesWindow *window;
+ NautilusPropertiesWindow *window;
- window = NAUTILUS_PROPERTIES_WINDOW (callback_data);
+ window = NAUTILUS_PROPERTIES_WINDOW (callback_data);
- /* Complain to user if rename failed. */
- if (error != NULL) {
- nautilus_report_error_renaming_file (file,
- window->details->pending_name,
- error,
- GTK_WINDOW (window));
- if (window->details->name_field != NULL) {
- name_field_restore_original_name (NAUTILUS_ENTRY (window->details->name_field));
- }
- }
+ /* Complain to user if rename failed. */
+ if (error != NULL)
+ {
+ nautilus_report_error_renaming_file (file,
+ window->details->pending_name,
+ error,
+ GTK_WINDOW (window));
+ if (window->details->name_field != NULL)
+ {
+ name_field_restore_original_name (NAUTILUS_ENTRY (window->details->name_field));
+ }
+ }
- g_object_unref (window);
+ g_object_unref (window);
}
static void
-set_pending_name (NautilusPropertiesWindow *window, const char *name)
+set_pending_name (NautilusPropertiesWindow *window,
+ const char *name)
{
- g_free (window->details->pending_name);
- window->details->pending_name = g_strdup (name);
+ g_free (window->details->pending_name);
+ window->details->pending_name = g_strdup (name);
}
static void
-name_field_done_editing (NautilusEntry *name_field, NautilusPropertiesWindow *window)
-{
- NautilusFile *file;
- char *new_name;
- const char *original_name;
-
- g_return_if_fail (NAUTILUS_IS_ENTRY (name_field));
-
- /* Don't apply if the dialog has more than one file */
- if (is_multi_file_window (window)) {
- return;
- }
-
- file = get_original_file (window);
-
- /* This gets called when the window is closed, which might be
- * caused by the file having been deleted.
- */
- if (file == NULL || nautilus_file_is_gone (file)) {
- return;
- }
-
- new_name = gtk_editable_get_chars (GTK_EDITABLE (name_field), 0, -1);
-
- /* Special case: silently revert text if new text is empty. */
- if (strlen (new_name) == 0) {
- name_field_restore_original_name (NAUTILUS_ENTRY (name_field));
- } else {
- original_name = (const char *) g_object_get_data (G_OBJECT (window->details->name_field),
- "original_name");
- /* Don't rename if not changed since we read the display name.
- This is needed so that we don't save the display name to the
- file when nothing is changed */
- if (strcmp (new_name, original_name) != 0) {
- set_pending_name (window, new_name);
- g_object_ref (window);
- nautilus_file_rename (file, new_name,
- rename_callback, window);
- }
- }
-
- g_free (new_name);
+name_field_done_editing (NautilusEntry *name_field,
+ NautilusPropertiesWindow *window)
+{
+ NautilusFile *file;
+ char *new_name;
+ const char *original_name;
+
+ g_return_if_fail (NAUTILUS_IS_ENTRY (name_field));
+
+ /* Don't apply if the dialog has more than one file */
+ if (is_multi_file_window (window))
+ {
+ return;
+ }
+
+ file = get_original_file (window);
+
+ /* This gets called when the window is closed, which might be
+ * caused by the file having been deleted.
+ */
+ if (file == NULL || nautilus_file_is_gone (file))
+ {
+ return;
+ }
+
+ new_name = gtk_editable_get_chars (GTK_EDITABLE (name_field), 0, -1);
+
+ /* Special case: silently revert text if new text is empty. */
+ if (strlen (new_name) == 0)
+ {
+ name_field_restore_original_name (NAUTILUS_ENTRY (name_field));
+ }
+ else
+ {
+ original_name = (const char *) g_object_get_data (G_OBJECT (window->details->name_field),
+ "original_name");
+ /* Don't rename if not changed since we read the display name.
+ * This is needed so that we don't save the display name to the
+ * file when nothing is changed */
+ if (strcmp (new_name, original_name) != 0)
+ {
+ set_pending_name (window, new_name);
+ g_object_ref (window);
+ nautilus_file_rename (file, new_name,
+ rename_callback, window);
+ }
+ }
+
+ g_free (new_name);
}
static gboolean
name_field_focus_out (NautilusEntry *name_field,
- GdkEventFocus *event,
- gpointer callback_data)
+ GdkEventFocus *event,
+ gpointer callback_data)
{
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (callback_data));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (callback_data));
- if (gtk_widget_get_sensitive (GTK_WIDGET (name_field))) {
- name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (callback_data));
- }
+ if (gtk_widget_get_sensitive (GTK_WIDGET (name_field)))
+ {
+ name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (callback_data));
+ }
- return FALSE;
+ return FALSE;
}
static void
-name_field_activate (NautilusEntry *name_field, gpointer callback_data)
+name_field_activate (NautilusEntry *name_field,
+ gpointer callback_data)
{
- g_assert (NAUTILUS_IS_ENTRY (name_field));
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (callback_data));
+ g_assert (NAUTILUS_IS_ENTRY (name_field));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (callback_data));
- /* Accept changes. */
- name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (callback_data));
+ /* Accept changes. */
+ name_field_done_editing (name_field, NAUTILUS_PROPERTIES_WINDOW (callback_data));
- nautilus_entry_select_all_at_idle (name_field);
+ nautilus_entry_select_all_at_idle (name_field);
}
static void
update_properties_window_title (NautilusPropertiesWindow *window)
{
- char *name, *title;
- NautilusFile *file;
+ char *name, *title;
+ NautilusFile *file;
+
+ g_return_if_fail (GTK_IS_WINDOW (window));
- g_return_if_fail (GTK_IS_WINDOW (window));
+ title = g_strdup_printf (_("Properties"));
- title = g_strdup_printf (_("Properties"));
+ if (!is_multi_file_window (window))
+ {
+ file = get_original_file (window);
- if (!is_multi_file_window (window)) {
- file = get_original_file (window);
+ if (file != NULL)
+ {
+ g_free (title);
+ name = nautilus_file_get_display_name (file);
+ if (nautilus_file_is_directory (file))
+ {
+ /* To translators: %s is the name of the folder. */
+ title = g_strdup_printf (C_("folder", "%s Properties"), name);
+ }
+ else
+ {
+ /* To translators: %s is the name of the file. */
+ title = g_strdup_printf (C_("file", "%s Properties"), name);
+ }
- if (file != NULL) {
- g_free (title);
- name = nautilus_file_get_display_name (file);
- if (nautilus_file_is_directory (file)) {
- /* To translators: %s is the name of the folder. */
- title = g_strdup_printf (C_("folder", "%s Properties"), name);
- } else {
- /* To translators: %s is the name of the file. */
- title = g_strdup_printf (C_("file", "%s Properties"), name);
- }
+ g_free (name);
+ }
+ }
- g_free (name);
- }
- }
-
- gtk_window_set_title (GTK_WINDOW (window), title);
+ gtk_window_set_title (GTK_WINDOW (window), title);
- g_free (title);
+ g_free (title);
}
static void
clear_extension_pages (NautilusPropertiesWindow *window)
{
- int i;
- int num_pages;
- GtkWidget *page;
+ int i;
+ int num_pages;
+ GtkWidget *page;
- num_pages = gtk_notebook_get_n_pages
- (GTK_NOTEBOOK (window->details->notebook));
+ num_pages = gtk_notebook_get_n_pages
+ (GTK_NOTEBOOK (window->details->notebook));
- for (i = 0; i < num_pages; i++) {
- page = gtk_notebook_get_nth_page
- (GTK_NOTEBOOK (window->details->notebook), i);
+ for (i = 0; i < num_pages; i++)
+ {
+ page = gtk_notebook_get_nth_page
+ (GTK_NOTEBOOK (window->details->notebook), i);
- if (g_object_get_data (G_OBJECT (page), "is-extension-page")) {
- gtk_notebook_remove_page
- (GTK_NOTEBOOK (window->details->notebook), i);
- num_pages--;
- i--;
- }
- }
+ if (g_object_get_data (G_OBJECT (page), "is-extension-page"))
+ {
+ gtk_notebook_remove_page
+ (GTK_NOTEBOOK (window->details->notebook), i);
+ num_pages--;
+ i--;
+ }
+ }
}
static void
refresh_extension_pages (NautilusPropertiesWindow *window)
{
- clear_extension_pages (window);
- append_extension_pages (window);
+ clear_extension_pages (window);
+ append_extension_pages (window);
}
static void
remove_from_dialog (NautilusPropertiesWindow *window,
- NautilusFile *file)
+ NautilusFile *file)
{
- int index;
- GList *original_link;
- GList *target_link;
- NautilusFile *original_file;
- NautilusFile *target_file;
+ int index;
+ GList *original_link;
+ GList *target_link;
+ NautilusFile *original_file;
+ NautilusFile *target_file;
- index = g_list_index (window->details->target_files, file);
- if (index == -1) {
- index = g_list_index (window->details->original_files, file);
- g_return_if_fail (index != -1);
- }
+ index = g_list_index (window->details->target_files, file);
+ if (index == -1)
+ {
+ index = g_list_index (window->details->original_files, file);
+ g_return_if_fail (index != -1);
+ }
- original_link = g_list_nth (window->details->original_files, index);
- target_link = g_list_nth (window->details->target_files, index);
+ original_link = g_list_nth (window->details->original_files, index);
+ target_link = g_list_nth (window->details->target_files, index);
- g_return_if_fail (original_link && target_link);
+ g_return_if_fail (original_link && target_link);
- original_file = NAUTILUS_FILE (original_link->data);
- target_file = NAUTILUS_FILE (target_link->data);
-
- window->details->original_files = g_list_remove_link (window->details->original_files, original_link);
- g_list_free (original_link);
+ original_file = NAUTILUS_FILE (original_link->data);
+ target_file = NAUTILUS_FILE (target_link->data);
- window->details->target_files = g_list_remove_link (window->details->target_files, target_link);
- g_list_free (target_link);
+ window->details->original_files = g_list_remove_link (window->details->original_files, original_link);
+ g_list_free (original_link);
- g_hash_table_remove (window->details->initial_permissions, target_file);
+ window->details->target_files = g_list_remove_link (window->details->target_files, target_link);
+ g_list_free (target_link);
- g_signal_handlers_disconnect_by_func (original_file,
- G_CALLBACK (file_changed_callback),
- window);
- g_signal_handlers_disconnect_by_func (target_file,
- G_CALLBACK (file_changed_callback),
- window);
+ g_hash_table_remove (window->details->initial_permissions, target_file);
- nautilus_file_monitor_remove (original_file, &window->details->original_files);
- nautilus_file_monitor_remove (target_file, &window->details->target_files);
+ g_signal_handlers_disconnect_by_func (original_file,
+ G_CALLBACK (file_changed_callback),
+ window);
+ g_signal_handlers_disconnect_by_func (target_file,
+ G_CALLBACK (file_changed_callback),
+ window);
- nautilus_file_unref (original_file);
- nautilus_file_unref (target_file);
-
+ nautilus_file_monitor_remove (original_file, &window->details->original_files);
+ nautilus_file_monitor_remove (target_file, &window->details->target_files);
+
+ nautilus_file_unref (original_file);
+ nautilus_file_unref (target_file);
}
static gboolean
-mime_list_equal (GList *a, GList *b)
+mime_list_equal (GList *a,
+ GList *b)
{
- while (a && b) {
- if (strcmp (a->data, b->data)) {
- return FALSE;
- }
- a = a->next;
- b = b->next;
- }
+ while (a && b)
+ {
+ if (strcmp (a->data, b->data))
+ {
+ return FALSE;
+ }
+ a = a->next;
+ b = b->next;
+ }
- return (a == b);
+ return (a == b);
}
static GList *
get_mime_list (NautilusPropertiesWindow *window)
{
- GList *ret;
- GList *l;
-
- ret = NULL;
- for (l = window->details->target_files; l != NULL; l = l->next) {
- ret = g_list_append (ret, nautilus_file_get_mime_type (NAUTILUS_FILE (l->data)));
- }
- ret = g_list_reverse (ret);
- return ret;
+ GList *ret;
+ GList *l;
+
+ ret = NULL;
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ ret = g_list_append (ret, nautilus_file_get_mime_type (NAUTILUS_FILE (l->data)));
+ }
+ ret = g_list_reverse (ret);
+ return ret;
}
static gboolean
start_spinner_callback (NautilusPropertiesWindow *window)
{
- gtk_widget_show (window->details->directory_contents_spinner);
- gtk_spinner_start (GTK_SPINNER (window->details->directory_contents_spinner));
- window->details->deep_count_spinner_timeout_id = 0;
+ gtk_widget_show (window->details->directory_contents_spinner);
+ gtk_spinner_start (GTK_SPINNER (window->details->directory_contents_spinner));
+ window->details->deep_count_spinner_timeout_id = 0;
- return FALSE;
+ return FALSE;
}
static void
schedule_start_spinner (NautilusPropertiesWindow *window)
{
- if (window->details->deep_count_spinner_timeout_id == 0) {
- window->details->deep_count_spinner_timeout_id
- = g_timeout_add_seconds (1,
- (GSourceFunc)start_spinner_callback,
- window);
- }
+ if (window->details->deep_count_spinner_timeout_id == 0)
+ {
+ window->details->deep_count_spinner_timeout_id
+ = g_timeout_add_seconds (1,
+ (GSourceFunc) start_spinner_callback,
+ window);
+ }
}
static void
stop_spinner (NautilusPropertiesWindow *window)
{
- gtk_spinner_stop (GTK_SPINNER (window->details->directory_contents_spinner));
- gtk_widget_hide (window->details->directory_contents_spinner);
- if (window->details->deep_count_spinner_timeout_id > 0) {
- g_source_remove (window->details->deep_count_spinner_timeout_id);
- window->details->deep_count_spinner_timeout_id = 0;
- }
+ gtk_spinner_stop (GTK_SPINNER (window->details->directory_contents_spinner));
+ gtk_widget_hide (window->details->directory_contents_spinner);
+ if (window->details->deep_count_spinner_timeout_id > 0)
+ {
+ g_source_remove (window->details->deep_count_spinner_timeout_id);
+ window->details->deep_count_spinner_timeout_id = 0;
+ }
}
static void
stop_deep_count_for_file (NautilusPropertiesWindow *window,
- NautilusFile *file)
+ NautilusFile *file)
{
- if (g_list_find (window->details->deep_count_files, file)) {
- g_signal_handlers_disconnect_by_func (file,
- G_CALLBACK (schedule_directory_contents_update),
- window);
- nautilus_file_unref (file);
- window->details->deep_count_files = g_list_remove (window->details->deep_count_files, file);
- }
+ if (g_list_find (window->details->deep_count_files, file))
+ {
+ g_signal_handlers_disconnect_by_func (file,
+ G_CALLBACK (schedule_directory_contents_update),
+ window);
+ nautilus_file_unref (file);
+ window->details->deep_count_files = g_list_remove (window->details->deep_count_files, file);
+ }
}
static void
start_deep_count_for_file (NautilusPropertiesWindow *window,
- NautilusFile *file)
-{
- if (!nautilus_file_is_directory (file)) {
- return;
- }
-
- if (!g_list_find (window->details->deep_count_files, file)) {
- nautilus_file_ref (file);
- window->details->deep_count_files = g_list_prepend (window->details->deep_count_files, file);
-
- nautilus_file_recompute_deep_counts (file);
- if (!window->details->deep_count_finished) {
- g_signal_connect_object (file,
- "updated-deep-count-in-progress",
- G_CALLBACK (schedule_directory_contents_update),
- window, G_CONNECT_SWAPPED);
- schedule_start_spinner (window);
- }
- }
+ NautilusFile *file)
+{
+ if (!nautilus_file_is_directory (file))
+ {
+ return;
+ }
+
+ if (!g_list_find (window->details->deep_count_files, file))
+ {
+ nautilus_file_ref (file);
+ window->details->deep_count_files = g_list_prepend (window->details->deep_count_files, file);
+
+ nautilus_file_recompute_deep_counts (file);
+ if (!window->details->deep_count_finished)
+ {
+ g_signal_connect_object (file,
+ "updated-deep-count-in-progress",
+ G_CALLBACK (schedule_directory_contents_update),
+ window, G_CONNECT_SWAPPED);
+ schedule_start_spinner (window);
+ }
+ }
}
static void
-properties_window_update (NautilusPropertiesWindow *window,
- GList *files)
-{
- GList *l;
- GList *mime_list;
- GList *tmp;
- NautilusFile *changed_file;
- gboolean dirty_original = FALSE;
- gboolean dirty_target = FALSE;
-
- if (files == NULL) {
- dirty_original = TRUE;
- dirty_target = TRUE;
- }
-
- for (tmp = files; tmp != NULL; tmp = tmp->next) {
- changed_file = NAUTILUS_FILE (tmp->data);
-
- if (changed_file && nautilus_file_is_gone (changed_file)) {
- /* Remove the file from the property dialog */
- remove_from_dialog (window, changed_file);
- changed_file = NULL;
-
- if (window->details->original_files == NULL) {
- return;
- }
- }
- if (changed_file == NULL ||
- g_list_find (window->details->original_files, changed_file)) {
- dirty_original = TRUE;
- }
- if (changed_file == NULL ||
- g_list_find (window->details->target_files, changed_file)) {
- dirty_target = TRUE;
- }
- if (changed_file != NULL) {
- start_deep_count_for_file (window, changed_file);
- }
- }
-
- if (dirty_original) {
- update_properties_window_title (window);
- update_properties_window_icon (window);
- update_name_field (window);
-
- /* If any of the value fields start to depend on the original
- * value, value_field_updates should be added here */
- }
-
- if (dirty_target) {
- for (l = window->details->permission_buttons; l != NULL; l = l->next) {
- permission_button_update (window, GTK_TOGGLE_BUTTON (l->data));
- }
-
- for (l = window->details->permission_combos; l != NULL; l = l->next) {
- permission_combo_update (window, GTK_COMBO_BOX (l->data));
- }
-
- for (l = window->details->value_fields; l != NULL; l = l->next) {
- value_field_update (window, GTK_LABEL (l->data));
- }
- }
-
- mime_list = get_mime_list (window);
-
- if (!window->details->mime_list) {
- window->details->mime_list = mime_list;
- } else {
- if (!mime_list_equal (window->details->mime_list, mime_list)) {
- refresh_extension_pages (window);
- }
-
- g_list_free_full (window->details->mime_list, g_free);
- window->details->mime_list = mime_list;
- }
+properties_window_update (NautilusPropertiesWindow *window,
+ GList *files)
+{
+ GList *l;
+ GList *mime_list;
+ GList *tmp;
+ NautilusFile *changed_file;
+ gboolean dirty_original = FALSE;
+ gboolean dirty_target = FALSE;
+
+ if (files == NULL)
+ {
+ dirty_original = TRUE;
+ dirty_target = TRUE;
+ }
+
+ for (tmp = files; tmp != NULL; tmp = tmp->next)
+ {
+ changed_file = NAUTILUS_FILE (tmp->data);
+
+ if (changed_file && nautilus_file_is_gone (changed_file))
+ {
+ /* Remove the file from the property dialog */
+ remove_from_dialog (window, changed_file);
+ changed_file = NULL;
+
+ if (window->details->original_files == NULL)
+ {
+ return;
+ }
+ }
+ if (changed_file == NULL ||
+ g_list_find (window->details->original_files, changed_file))
+ {
+ dirty_original = TRUE;
+ }
+ if (changed_file == NULL ||
+ g_list_find (window->details->target_files, changed_file))
+ {
+ dirty_target = TRUE;
+ }
+ if (changed_file != NULL)
+ {
+ start_deep_count_for_file (window, changed_file);
+ }
+ }
+
+ if (dirty_original)
+ {
+ update_properties_window_title (window);
+ update_properties_window_icon (window);
+ update_name_field (window);
+
+ /* If any of the value fields start to depend on the original
+ * value, value_field_updates should be added here */
+ }
+
+ if (dirty_target)
+ {
+ for (l = window->details->permission_buttons; l != NULL; l = l->next)
+ {
+ permission_button_update (window, GTK_TOGGLE_BUTTON (l->data));
+ }
+
+ for (l = window->details->permission_combos; l != NULL; l = l->next)
+ {
+ permission_combo_update (window, GTK_COMBO_BOX (l->data));
+ }
+
+ for (l = window->details->value_fields; l != NULL; l = l->next)
+ {
+ value_field_update (window, GTK_LABEL (l->data));
+ }
+ }
+
+ mime_list = get_mime_list (window);
+
+ if (!window->details->mime_list)
+ {
+ window->details->mime_list = mime_list;
+ }
+ else
+ {
+ if (!mime_list_equal (window->details->mime_list, mime_list))
+ {
+ refresh_extension_pages (window);
+ }
+
+ g_list_free_full (window->details->mime_list, g_free);
+ window->details->mime_list = mime_list;
+ }
}
static gboolean
update_files_callback (gpointer data)
{
- NautilusPropertiesWindow *window;
-
- window = NAUTILUS_PROPERTIES_WINDOW (data);
-
- window->details->update_files_timeout_id = 0;
-
- properties_window_update (window, window->details->changed_files);
-
- if (window->details->original_files == NULL) {
- /* Close the window if no files are left */
- gtk_widget_destroy (GTK_WIDGET (window));
- } else {
- nautilus_file_list_free (window->details->changed_files);
- window->details->changed_files = NULL;
- }
-
- return FALSE;
- }
+ NautilusPropertiesWindow *window;
+
+ window = NAUTILUS_PROPERTIES_WINDOW (data);
+
+ window->details->update_files_timeout_id = 0;
+
+ properties_window_update (window, window->details->changed_files);
+
+ if (window->details->original_files == NULL)
+ {
+ /* Close the window if no files are left */
+ gtk_widget_destroy (GTK_WIDGET (window));
+ }
+ else
+ {
+ nautilus_file_list_free (window->details->changed_files);
+ window->details->changed_files = NULL;
+ }
+
+ return FALSE;
+}
static void
schedule_files_update (NautilusPropertiesWindow *window)
- {
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
-
- if (window->details->update_files_timeout_id == 0) {
- window->details->update_files_timeout_id
- = g_timeout_add (FILES_UPDATE_INTERVAL,
- update_files_callback,
- window);
- }
- }
+{
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+
+ if (window->details->update_files_timeout_id == 0)
+ {
+ window->details->update_files_timeout_id
+ = g_timeout_add (FILES_UPDATE_INTERVAL,
+ update_files_callback,
+ window);
+ }
+}
static gboolean
-file_list_attributes_identical (GList *file_list, const char *attribute_name)
-{
- gboolean identical;
- char *first_attr;
- GList *l;
-
- first_attr = NULL;
- identical = TRUE;
-
- for (l = file_list; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_is_gone (file)) {
- continue;
- }
-
- if (first_attr == NULL) {
- first_attr = nautilus_file_get_string_attribute_with_default (file, attribute_name);
- } else {
- char *attr;
- attr = nautilus_file_get_string_attribute_with_default (file, attribute_name);
- if (strcmp (attr, first_attr)) {
- identical = FALSE;
- g_free (attr);
- break;
- }
- g_free (attr);
- }
- }
-
- g_free (first_attr);
- return identical;
+file_list_attributes_identical (GList *file_list,
+ const char *attribute_name)
+{
+ gboolean identical;
+ char *first_attr;
+ GList *l;
+
+ first_attr = NULL;
+ identical = TRUE;
+
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_is_gone (file))
+ {
+ continue;
+ }
+
+ if (first_attr == NULL)
+ {
+ first_attr = nautilus_file_get_string_attribute_with_default (file, attribute_name);
+ }
+ else
+ {
+ char *attr;
+ attr = nautilus_file_get_string_attribute_with_default (file, attribute_name);
+ if (strcmp (attr, first_attr))
+ {
+ identical = FALSE;
+ g_free (attr);
+ break;
+ }
+ g_free (attr);
+ }
+ }
+
+ g_free (first_attr);
+ return identical;
}
static char *
-file_list_get_string_attribute (GList *file_list,
- const char *attribute_name,
- const char *inconsistent_value)
-{
- if (file_list_attributes_identical (file_list, attribute_name)) {
- GList *l;
-
- for (l = file_list; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
- if (!nautilus_file_is_gone (file)) {
- return nautilus_file_get_string_attribute_with_default
- (file,
- attribute_name);
- }
- }
- return g_strdup (_("unknown"));
- } else {
- return g_strdup (inconsistent_value);
- }
+file_list_get_string_attribute (GList *file_list,
+ const char *attribute_name,
+ const char *inconsistent_value)
+{
+ if (file_list_attributes_identical (file_list, attribute_name))
+ {
+ GList *l;
+
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+
+ file = NAUTILUS_FILE (l->data);
+ if (!nautilus_file_is_gone (file))
+ {
+ return nautilus_file_get_string_attribute_with_default
+ (file,
+ attribute_name);
+ }
+ }
+ return g_strdup (_("unknown"));
+ }
+ else
+ {
+ return g_strdup (inconsistent_value);
+ }
}
static gboolean
file_list_all_directories (GList *file_list)
{
- GList *l;
- for (l = file_list; l != NULL; l = l->next) {
- if (!nautilus_file_is_directory (NAUTILUS_FILE (l->data))) {
- return FALSE;
- }
- }
- return TRUE;
+ GList *l;
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ if (!nautilus_file_is_directory (NAUTILUS_FILE (l->data)))
+ {
+ return FALSE;
+ }
+ }
+ return TRUE;
}
static void
-value_field_update_internal (GtkLabel *label,
- GList *file_list)
-{
- const char *attribute_name;
- char *attribute_value;
- char *inconsistent_string;
- char *mime_type, *tmp;
-
- g_assert (GTK_IS_LABEL (label));
-
- attribute_name = g_object_get_data (G_OBJECT (label), "file_attribute");
- inconsistent_string = g_object_get_data (G_OBJECT (label), "inconsistent_string");
- attribute_value = file_list_get_string_attribute (file_list,
- attribute_name,
- inconsistent_string);
- if (!strcmp (attribute_name, "detailed_type") && strcmp (attribute_value, inconsistent_string)) {
- mime_type = file_list_get_string_attribute (file_list,
- "mime_type",
- inconsistent_string);
- if (strcmp (mime_type, inconsistent_string)) {
- tmp = attribute_value;
- attribute_value = g_strdup_printf (C_("MIME type description (MIME type)", "%s (%s)"), attribute_value, mime_type);
- g_free (tmp);
- }
- g_free (mime_type);
- }
-
- gtk_label_set_text (label, attribute_value);
- g_free (attribute_value);
+value_field_update_internal (GtkLabel *label,
+ GList *file_list)
+{
+ const char *attribute_name;
+ char *attribute_value;
+ char *inconsistent_string;
+ char *mime_type, *tmp;
+
+ g_assert (GTK_IS_LABEL (label));
+
+ attribute_name = g_object_get_data (G_OBJECT (label), "file_attribute");
+ inconsistent_string = g_object_get_data (G_OBJECT (label), "inconsistent_string");
+ attribute_value = file_list_get_string_attribute (file_list,
+ attribute_name,
+ inconsistent_string);
+ if (!strcmp (attribute_name, "detailed_type") && strcmp (attribute_value, inconsistent_string))
+ {
+ mime_type = file_list_get_string_attribute (file_list,
+ "mime_type",
+ inconsistent_string);
+ if (strcmp (mime_type, inconsistent_string))
+ {
+ tmp = attribute_value;
+ attribute_value = g_strdup_printf (C_("MIME type description (MIME type)", "%s (%s)"), attribute_value, mime_type);
+ g_free (tmp);
+ }
+ g_free (mime_type);
+ }
+
+ gtk_label_set_text (label, attribute_value);
+ g_free (attribute_value);
}
static void
-value_field_update (NautilusPropertiesWindow *window, GtkLabel *label)
+value_field_update (NautilusPropertiesWindow *window,
+ GtkLabel *label)
{
- gboolean use_original;
+ gboolean use_original;
- use_original = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "show_original"));
+ use_original = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (label), "show_original"));
- value_field_update_internal (label,
- (use_original ?
- window->details->original_files :
- window->details->target_files));
+ value_field_update_internal (label,
+ (use_original ?
+ window->details->original_files :
+ window->details->target_files));
}
static GtkLabel *
-attach_label (GtkGrid *grid,
- GtkWidget *sibling,
- const char *initial_text,
- gboolean ellipsize_text,
- gboolean selectable,
- gboolean mnemonic)
-{
- GtkWidget *label_field;
-
- if (ellipsize_text) {
- label_field = gtk_label_new (initial_text);
- gtk_label_set_ellipsize (GTK_LABEL (label_field),
- PANGO_ELLIPSIZE_END);
- } else if (mnemonic) {
- label_field = gtk_label_new_with_mnemonic (initial_text);
- } else {
- label_field = gtk_label_new (initial_text);
- }
-
- if (selectable) {
- gtk_label_set_selectable (GTK_LABEL (label_field), TRUE);
- }
-
- gtk_label_set_xalign (GTK_LABEL (label_field), 0);
- gtk_widget_show (label_field);
-
- if (ellipsize_text) {
- gtk_widget_set_hexpand (label_field, TRUE);
- gtk_label_set_max_width_chars (GTK_LABEL (label_field), 24);
- }
-
- if (sibling != NULL) {
- gtk_grid_attach_next_to (grid, label_field, sibling,
- GTK_POS_RIGHT, 1, 1);
- } else {
- gtk_container_add (GTK_CONTAINER (grid), label_field);
- }
-
- return GTK_LABEL (label_field);
-}
+attach_label (GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *initial_text,
+ gboolean ellipsize_text,
+ gboolean selectable,
+ gboolean mnemonic)
+{
+ GtkWidget *label_field;
+
+ if (ellipsize_text)
+ {
+ label_field = gtk_label_new (initial_text);
+ gtk_label_set_ellipsize (GTK_LABEL (label_field),
+ PANGO_ELLIPSIZE_END);
+ }
+ else if (mnemonic)
+ {
+ label_field = gtk_label_new_with_mnemonic (initial_text);
+ }
+ else
+ {
+ label_field = gtk_label_new (initial_text);
+ }
+
+ if (selectable)
+ {
+ gtk_label_set_selectable (GTK_LABEL (label_field), TRUE);
+ }
+
+ gtk_label_set_xalign (GTK_LABEL (label_field), 0);
+ gtk_widget_show (label_field);
+
+ if (ellipsize_text)
+ {
+ gtk_widget_set_hexpand (label_field, TRUE);
+ gtk_label_set_max_width_chars (GTK_LABEL (label_field), 24);
+ }
+
+ if (sibling != NULL)
+ {
+ gtk_grid_attach_next_to (grid, label_field, sibling,
+ GTK_POS_RIGHT, 1, 1);
+ }
+ else
+ {
+ gtk_container_add (GTK_CONTAINER (grid), label_field);
+ }
+
+ return GTK_LABEL (label_field);
+}
static GtkLabel *
-attach_value_label (GtkGrid *grid,
- GtkWidget *sibling,
- const char *initial_text)
+attach_value_label (GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *initial_text)
{
- return attach_label (grid, sibling, initial_text, FALSE, TRUE, FALSE);
+ return attach_label (grid, sibling, initial_text, FALSE, TRUE, FALSE);
}
static GtkLabel *
-attach_ellipsizing_value_label (GtkGrid *grid,
- GtkWidget *sibling,
- const char *initial_text)
+attach_ellipsizing_value_label (GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *initial_text)
{
- return attach_label (grid, sibling, initial_text, TRUE, TRUE, FALSE);
+ return attach_label (grid, sibling, initial_text, TRUE, TRUE, FALSE);
}
-static GtkWidget*
+static GtkWidget *
attach_value_field_internal (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- GtkWidget *sibling,
- const char *file_attribute_name,
- const char *inconsistent_string,
- gboolean show_original,
- gboolean ellipsize_text)
+ GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *file_attribute_name,
+ const char *inconsistent_string,
+ gboolean show_original,
+ gboolean ellipsize_text)
{
- GtkLabel *value_field;
+ GtkLabel *value_field;
- if (ellipsize_text) {
- value_field = attach_ellipsizing_value_label (grid, sibling, "");
- } else {
- value_field = attach_value_label (grid, sibling, "");
- }
+ if (ellipsize_text)
+ {
+ value_field = attach_ellipsizing_value_label (grid, sibling, "");
+ }
+ else
+ {
+ value_field = attach_value_label (grid, sibling, "");
+ }
- /* Stash a copy of the file attribute name in this field for the callback's sake. */
- g_object_set_data_full (G_OBJECT (value_field), "file_attribute",
- g_strdup (file_attribute_name), g_free);
+ /* Stash a copy of the file attribute name in this field for the callback's sake. */
+ g_object_set_data_full (G_OBJECT (value_field), "file_attribute",
+ g_strdup (file_attribute_name), g_free);
- g_object_set_data_full (G_OBJECT (value_field), "inconsistent_string",
- g_strdup (inconsistent_string), g_free);
+ g_object_set_data_full (G_OBJECT (value_field), "inconsistent_string",
+ g_strdup (inconsistent_string), g_free);
- g_object_set_data (G_OBJECT (value_field), "show_original", GINT_TO_POINTER (show_original));
+ g_object_set_data (G_OBJECT (value_field), "show_original", GINT_TO_POINTER (show_original));
- window->details->value_fields = g_list_prepend (window->details->value_fields,
- value_field);
- return GTK_WIDGET(value_field);
-}
+ window->details->value_fields = g_list_prepend (window->details->value_fields,
+ value_field);
+ return GTK_WIDGET (value_field);
+}
-static GtkWidget*
+static GtkWidget *
attach_value_field (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- GtkWidget *sibling,
- const char *file_attribute_name,
- const char *inconsistent_string,
- gboolean show_original)
+ GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *file_attribute_name,
+ const char *inconsistent_string,
+ gboolean show_original)
{
- return attach_value_field_internal (window,
- grid, sibling,
- file_attribute_name,
- inconsistent_string,
- show_original,
- FALSE);
+ return attach_value_field_internal (window,
+ grid, sibling,
+ file_attribute_name,
+ inconsistent_string,
+ show_original,
+ FALSE);
}
-static GtkWidget*
+static GtkWidget *
attach_ellipsizing_value_field (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- GtkWidget *sibling,
- const char *file_attribute_name,
- const char *inconsistent_string,
- gboolean show_original)
+ GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *file_attribute_name,
+ const char *inconsistent_string,
+ gboolean show_original)
{
- return attach_value_field_internal (window,
- grid, sibling,
- file_attribute_name,
- inconsistent_string,
- show_original,
- TRUE);
+ return attach_value_field_internal (window,
+ grid, sibling,
+ file_attribute_name,
+ inconsistent_string,
+ show_original,
+ TRUE);
}
static void
group_change_free (GroupChange *change)
{
- nautilus_file_unref (change->file);
- g_free (change->group);
- g_object_unref (change->window);
+ nautilus_file_unref (change->file);
+ g_free (change->group);
+ g_object_unref (change->window);
- g_free (change);
+ g_free (change);
}
static void
group_change_callback (NautilusFile *file,
- GFile *res_loc,
- GError *error,
- GroupChange *change)
+ GFile *res_loc,
+ GError *error,
+ GroupChange *change)
{
- NautilusPropertiesWindow *window;
+ NautilusPropertiesWindow *window;
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
- g_assert (NAUTILUS_IS_FILE (change->file));
- g_assert (change->group != NULL);
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
+ g_assert (NAUTILUS_IS_FILE (change->file));
+ g_assert (change->group != NULL);
- if (!change->cancelled) {
- /* Report the error if it's an error. */
- eel_timed_wait_stop ((EelCancelCallback) cancel_group_change_callback, change);
- nautilus_report_error_setting_group (change->file, error, change->window);
- }
+ if (!change->cancelled)
+ {
+ /* Report the error if it's an error. */
+ eel_timed_wait_stop ((EelCancelCallback) cancel_group_change_callback, change);
+ nautilus_report_error_setting_group (change->file, error, change->window);
+ }
- window = NAUTILUS_PROPERTIES_WINDOW(change->window);
- if (window->details->group_change == change) {
- window->details->group_change = NULL;
- }
+ window = NAUTILUS_PROPERTIES_WINDOW (change->window);
+ if (window->details->group_change == change)
+ {
+ window->details->group_change = NULL;
+ }
- group_change_free (change);
+ group_change_free (change);
}
static void
cancel_group_change_callback (GroupChange *change)
{
- g_assert (NAUTILUS_IS_FILE (change->file));
- g_assert (change->group != NULL);
+ g_assert (NAUTILUS_IS_FILE (change->file));
+ g_assert (change->group != NULL);
- change->cancelled = TRUE;
- nautilus_file_cancel (change->file, (NautilusFileOperationCallback) group_change_callback, change);
+ change->cancelled = TRUE;
+ nautilus_file_cancel (change->file, (NautilusFileOperationCallback) group_change_callback, change);
}
static gboolean
schedule_group_change_timeout (GroupChange *change)
{
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
- g_assert (NAUTILUS_IS_FILE (change->file));
- g_assert (change->group != NULL);
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
+ g_assert (NAUTILUS_IS_FILE (change->file));
+ g_assert (change->group != NULL);
- change->timeout = 0;
+ change->timeout = 0;
- eel_timed_wait_start
- ((EelCancelCallback) cancel_group_change_callback,
- change,
- _("Cancel Group Change?"),
- change->window);
+ eel_timed_wait_start
+ ((EelCancelCallback) cancel_group_change_callback,
+ change,
+ _("Cancel Group Change?"),
+ change->window);
- nautilus_file_set_group
- (change->file, change->group,
- (NautilusFileOperationCallback) group_change_callback, change);
+ nautilus_file_set_group
+ (change->file, change->group,
+ (NautilusFileOperationCallback) group_change_callback, change);
- return FALSE;
+ return FALSE;
}
static void
schedule_group_change (NautilusPropertiesWindow *window,
- NautilusFile *file,
- const char *group)
+ NautilusFile *file,
+ const char *group)
{
- GroupChange *change;
+ GroupChange *change;
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
- g_assert (window->details->group_change == NULL);
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+ g_assert (window->details->group_change == NULL);
+ g_assert (NAUTILUS_IS_FILE (file));
- change = g_new0 (GroupChange, 1);
+ change = g_new0 (GroupChange, 1);
- change->file = nautilus_file_ref (file);
- change->group = g_strdup (group);
- change->window = g_object_ref (G_OBJECT (window));
- change->timeout =
- g_timeout_add (CHOWN_CHGRP_TIMEOUT,
- (GSourceFunc) schedule_group_change_timeout,
- change);
+ change->file = nautilus_file_ref (file);
+ change->group = g_strdup (group);
+ change->window = g_object_ref (G_OBJECT (window));
+ change->timeout =
+ g_timeout_add (CHOWN_CHGRP_TIMEOUT,
+ (GSourceFunc) schedule_group_change_timeout,
+ change);
- window->details->group_change = change;
+ window->details->group_change = change;
}
static void
unschedule_or_cancel_group_change (NautilusPropertiesWindow *window)
{
- GroupChange *change;
+ GroupChange *change;
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
- change = window->details->group_change;
+ change = window->details->group_change;
- if (change != NULL) {
- if (change->timeout == 0) {
- /* The operation was started, cancel it and let the operation callback free the change */
- cancel_group_change_callback (change);
- eel_timed_wait_stop ((EelCancelCallback) cancel_group_change_callback, change);
- } else {
- g_source_remove (change->timeout);
- group_change_free (change);
- }
+ if (change != NULL)
+ {
+ if (change->timeout == 0)
+ {
+ /* The operation was started, cancel it and let the operation callback free the change */
+ cancel_group_change_callback (change);
+ eel_timed_wait_stop ((EelCancelCallback) cancel_group_change_callback, change);
+ }
+ else
+ {
+ g_source_remove (change->timeout);
+ group_change_free (change);
+ }
- window->details->group_change = NULL;
- }
+ window->details->group_change = NULL;
+ }
}
static void
-changed_group_callback (GtkComboBox *combo_box, NautilusFile *file)
+changed_group_callback (GtkComboBox *combo_box,
+ NautilusFile *file)
{
- NautilusPropertiesWindow *window;
- char *group;
- char *cur_group;
+ NautilusPropertiesWindow *window;
+ char *group;
+ char *cur_group;
- g_assert (GTK_IS_COMBO_BOX (combo_box));
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (GTK_IS_COMBO_BOX (combo_box));
+ g_assert (NAUTILUS_IS_FILE (file));
- group = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo_box));
- cur_group = nautilus_file_get_group_name (file);
+ group = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (combo_box));
+ cur_group = nautilus_file_get_group_name (file);
- if (group != NULL && strcmp (group, cur_group) != 0) {
- /* Try to change file group. If this fails, complain to user. */
- window = NAUTILUS_PROPERTIES_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (combo_box), GTK_TYPE_WINDOW));
+ if (group != NULL && strcmp (group, cur_group) != 0)
+ {
+ /* Try to change file group. If this fails, complain to user. */
+ window = NAUTILUS_PROPERTIES_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (combo_box), GTK_TYPE_WINDOW));
- unschedule_or_cancel_group_change (window);
- schedule_group_change (window, file, group);
- }
- g_free (group);
- g_free (cur_group);
+ unschedule_or_cancel_group_change (window);
+ schedule_group_change (window, file, group);
+ }
+ g_free (group);
+ g_free (cur_group);
}
/* checks whether the given column at the first level
* of model has the specified entries in the given order. */
static gboolean
tree_model_entries_equal (GtkTreeModel *model,
- unsigned int column,
- GList *entries)
+ unsigned int column,
+ GList *entries)
{
- GtkTreeIter iter;
- gboolean empty_model;
+ GtkTreeIter iter;
+ gboolean empty_model;
- g_assert (GTK_IS_TREE_MODEL (model));
- g_assert (gtk_tree_model_get_column_type (model, column) == G_TYPE_STRING);
+ g_assert (GTK_IS_TREE_MODEL (model));
+ g_assert (gtk_tree_model_get_column_type (model, column) == G_TYPE_STRING);
- empty_model = !gtk_tree_model_get_iter_first (model, &iter);
+ empty_model = !gtk_tree_model_get_iter_first (model, &iter);
- if (!empty_model && entries != NULL) {
- GList *l;
+ if (!empty_model && entries != NULL)
+ {
+ GList *l;
- l = entries;
+ l = entries;
- do {
- char *val;
+ do
+ {
+ char *val;
- gtk_tree_model_get (model, &iter,
- column, &val,
- -1);
- if ((val == NULL && l->data != NULL) ||
- (val != NULL && l->data == NULL) ||
- (val != NULL && strcmp (val, l->data))) {
- g_free (val);
- return FALSE;
- }
+ gtk_tree_model_get (model, &iter,
+ column, &val,
+ -1);
+ if ((val == NULL && l->data != NULL) ||
+ (val != NULL && l->data == NULL) ||
+ (val != NULL && strcmp (val, l->data)))
+ {
+ g_free (val);
+ return FALSE;
+ }
- g_free (val);
- l = l->next;
- } while (gtk_tree_model_iter_next (model, &iter));
+ g_free (val);
+ l = l->next;
+ }
+ while (gtk_tree_model_iter_next (model, &iter));
- return l == NULL;
- } else {
- return (empty_model && entries == NULL) ||
- (!empty_model && entries != NULL);
- }
+ return l == NULL;
+ }
+ else
+ {
+ return (empty_model && entries == NULL) ||
+ (!empty_model && entries != NULL);
+ }
}
static char *
combo_box_get_active_entry (GtkComboBox *combo_box,
- unsigned int column)
+ unsigned int column)
{
- GtkTreeModel *model;
- GtkTreeIter iter;
- char *val;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ char *val;
- g_assert (GTK_IS_COMBO_BOX (combo_box));
+ g_assert (GTK_IS_COMBO_BOX (combo_box));
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter)) {
- model = gtk_combo_box_get_model (combo_box);
- g_assert (GTK_IS_TREE_MODEL (model));
+ if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter))
+ {
+ model = gtk_combo_box_get_model (combo_box);
+ g_assert (GTK_IS_TREE_MODEL (model));
- gtk_tree_model_get (model, &iter,
- column, &val,
- -1);
- return val;
- }
+ gtk_tree_model_get (model, &iter,
+ column, &val,
+ -1);
+ return val;
+ }
- return NULL;
+ return NULL;
}
/* returns the index of the given entry in the the given column
@@ -1553,3418 +1718,3770 @@ combo_box_get_active_entry (GtkComboBox *combo_box,
* */
static int
tree_model_get_entry_index (GtkTreeModel *model,
- unsigned int column,
- const char *entry)
+ unsigned int column,
+ const char *entry)
{
- GtkTreeIter iter;
- int index;
- gboolean empty_model;
+ GtkTreeIter iter;
+ int index;
+ gboolean empty_model;
- g_assert (GTK_IS_TREE_MODEL (model));
- g_assert (gtk_tree_model_get_column_type (model, column) == G_TYPE_STRING);
+ g_assert (GTK_IS_TREE_MODEL (model));
+ g_assert (gtk_tree_model_get_column_type (model, column) == G_TYPE_STRING);
- empty_model = !gtk_tree_model_get_iter_first (model, &iter);
- if (!empty_model && entry != NULL) {
- index = 0;
+ empty_model = !gtk_tree_model_get_iter_first (model, &iter);
+ if (!empty_model && entry != NULL)
+ {
+ index = 0;
- do {
- char *val;
+ do
+ {
+ char *val;
- gtk_tree_model_get (model, &iter,
- column, &val,
- -1);
- if (val != NULL && !strcmp (val, entry)) {
- g_free (val);
- return index;
- }
+ gtk_tree_model_get (model, &iter,
+ column, &val,
+ -1);
+ if (val != NULL && !strcmp (val, entry))
+ {
+ g_free (val);
+ return index;
+ }
- g_free (val);
- index++;
- } while (gtk_tree_model_iter_next (model, &iter));
- }
+ g_free (val);
+ index++;
+ }
+ while (gtk_tree_model_iter_next (model, &iter));
+ }
- return -1;
+ return -1;
}
static void
-synch_groups_combo_box (GtkComboBox *combo_box, NautilusFile *file)
-{
- GList *groups;
- GList *node;
- GtkTreeModel *model;
- GtkListStore *store;
- const char *group_name;
- char *current_group_name;
- int group_index;
- int current_group_index;
-
- g_assert (GTK_IS_COMBO_BOX (combo_box));
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_gone (file)) {
- return;
- }
-
- groups = nautilus_file_get_settable_group_names (file);
-
- model = gtk_combo_box_get_model (combo_box);
- store = GTK_LIST_STORE (model);
- g_assert (GTK_IS_LIST_STORE (model));
-
- if (!tree_model_entries_equal (model, 0, groups)) {
- /* Clear the contents of ComboBox in a wacky way because there
- * is no function to clear all items and also no function to obtain
- * the number of items in a combobox.
- */
- gtk_list_store_clear (store);
-
- for (node = groups, group_index = 0; node != NULL; node = node->next, ++group_index) {
- group_name = (const char *)node->data;
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), group_name);
- }
- }
-
- current_group_name = nautilus_file_get_group_name (file);
- current_group_index = tree_model_get_entry_index (model, 0, current_group_name);
-
- /* If current group wasn't in list, we prepend it (with a separator).
- * This can happen if the current group is an id with no matching
- * group in the groups file.
- */
- if (current_group_index < 0 && current_group_name != NULL) {
- if (groups != NULL) {
- /* add separator */
- gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (combo_box), "-");
- }
-
- gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (combo_box), current_group_name);
- current_group_index = 0;
- }
- gtk_combo_box_set_active (combo_box, current_group_index);
-
- g_free (current_group_name);
- g_list_free_full (groups, g_free);
+synch_groups_combo_box (GtkComboBox *combo_box,
+ NautilusFile *file)
+{
+ GList *groups;
+ GList *node;
+ GtkTreeModel *model;
+ GtkListStore *store;
+ const char *group_name;
+ char *current_group_name;
+ int group_index;
+ int current_group_index;
+
+ g_assert (GTK_IS_COMBO_BOX (combo_box));
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ if (nautilus_file_is_gone (file))
+ {
+ return;
+ }
+
+ groups = nautilus_file_get_settable_group_names (file);
+
+ model = gtk_combo_box_get_model (combo_box);
+ store = GTK_LIST_STORE (model);
+ g_assert (GTK_IS_LIST_STORE (model));
+
+ if (!tree_model_entries_equal (model, 0, groups))
+ {
+ /* Clear the contents of ComboBox in a wacky way because there
+ * is no function to clear all items and also no function to obtain
+ * the number of items in a combobox.
+ */
+ gtk_list_store_clear (store);
+
+ for (node = groups, group_index = 0; node != NULL; node = node->next, ++group_index)
+ {
+ group_name = (const char *) node->data;
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), group_name);
+ }
+ }
+
+ current_group_name = nautilus_file_get_group_name (file);
+ current_group_index = tree_model_get_entry_index (model, 0, current_group_name);
+
+ /* If current group wasn't in list, we prepend it (with a separator).
+ * This can happen if the current group is an id with no matching
+ * group in the groups file.
+ */
+ if (current_group_index < 0 && current_group_name != NULL)
+ {
+ if (groups != NULL)
+ {
+ /* add separator */
+ gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (combo_box), "-");
+ }
+
+ gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (combo_box), current_group_name);
+ current_group_index = 0;
+ }
+ gtk_combo_box_set_active (combo_box, current_group_index);
+
+ g_free (current_group_name);
+ g_list_free_full (groups, g_free);
}
static gboolean
combo_box_row_separator_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer data)
+ GtkTreeIter *iter,
+ gpointer data)
{
- gchar *text;
- gboolean ret;
+ gchar *text;
+ gboolean ret;
- gtk_tree_model_get (model, iter, 0, &text, -1);
+ gtk_tree_model_get (model, iter, 0, &text, -1);
- if (text == NULL) {
- return FALSE;
- }
+ if (text == NULL)
+ {
+ return FALSE;
+ }
- if (strcmp (text, "-") == 0) {
- ret = TRUE;
- } else {
- ret = FALSE;
- }
-
- g_free (text);
- return ret;
+ if (strcmp (text, "-") == 0)
+ {
+ ret = TRUE;
+ }
+ else
+ {
+ ret = FALSE;
+ }
+
+ g_free (text);
+ return ret;
}
static GtkComboBox *
-attach_combo_box (GtkGrid *grid,
- GtkWidget *sibling,
- gboolean three_columns)
+attach_combo_box (GtkGrid *grid,
+ GtkWidget *sibling,
+ gboolean three_columns)
{
- GtkWidget *combo_box;
+ GtkWidget *combo_box;
- if (!three_columns) {
- combo_box = gtk_combo_box_text_new ();
- } else {
- GtkTreeModel *model;
- GtkCellRenderer *renderer;
+ if (!three_columns)
+ {
+ combo_box = gtk_combo_box_text_new ();
+ }
+ else
+ {
+ GtkTreeModel *model;
+ GtkCellRenderer *renderer;
- model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
- combo_box = gtk_combo_box_new_with_model (model);
- g_object_unref (G_OBJECT (model));
+ model = GTK_TREE_MODEL (gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
+ combo_box = gtk_combo_box_new_with_model (model);
+ g_object_unref (G_OBJECT (model));
- renderer = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
- gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box), renderer,
- "text", 0);
-
- }
- gtk_widget_set_halign (combo_box, GTK_ALIGN_START);
- gtk_widget_show (combo_box);
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box), renderer,
+ "text", 0);
+ }
+ gtk_widget_set_halign (combo_box, GTK_ALIGN_START);
+ gtk_widget_show (combo_box);
- gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box),
- combo_box_row_separator_func,
- NULL,
- NULL);
+ gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (combo_box),
+ combo_box_row_separator_func,
+ NULL,
+ NULL);
- gtk_grid_attach_next_to (grid, combo_box, sibling,
- GTK_POS_RIGHT, 1, 1);
+ gtk_grid_attach_next_to (grid, combo_box, sibling,
+ GTK_POS_RIGHT, 1, 1);
- return GTK_COMBO_BOX (combo_box);
-}
+ return GTK_COMBO_BOX (combo_box);
+}
-static GtkComboBox*
-attach_group_combo_box (GtkGrid *grid,
- GtkWidget *sibling,
- NautilusFile *file)
+static GtkComboBox *
+attach_group_combo_box (GtkGrid *grid,
+ GtkWidget *sibling,
+ NautilusFile *file)
{
- GtkComboBox *combo_box;
+ GtkComboBox *combo_box;
- combo_box = attach_combo_box (grid, sibling, FALSE);
+ combo_box = attach_combo_box (grid, sibling, FALSE);
- synch_groups_combo_box (combo_box, file);
+ synch_groups_combo_box (combo_box, file);
- /* Connect to signal to update menu when file changes. */
- g_signal_connect_object (file, "changed",
- G_CALLBACK (synch_groups_combo_box),
- combo_box, G_CONNECT_SWAPPED);
- g_signal_connect_data (combo_box, "changed",
- G_CALLBACK (changed_group_callback),
- nautilus_file_ref (file),
- (GClosureNotify)nautilus_file_unref, 0);
+ /* Connect to signal to update menu when file changes. */
+ g_signal_connect_object (file, "changed",
+ G_CALLBACK (synch_groups_combo_box),
+ combo_box, G_CONNECT_SWAPPED);
+ g_signal_connect_data (combo_box, "changed",
+ G_CALLBACK (changed_group_callback),
+ nautilus_file_ref (file),
+ (GClosureNotify) nautilus_file_unref, 0);
- return combo_box;
-}
+ return combo_box;
+}
static void
owner_change_free (OwnerChange *change)
{
- nautilus_file_unref (change->file);
- g_free (change->owner);
- g_object_unref (change->window);
+ nautilus_file_unref (change->file);
+ g_free (change->owner);
+ g_object_unref (change->window);
- g_free (change);
+ g_free (change);
}
static void
owner_change_callback (NautilusFile *file,
- GFile *result_location,
- GError *error,
- OwnerChange *change)
+ GFile *result_location,
+ GError *error,
+ OwnerChange *change)
{
- NautilusPropertiesWindow *window;
+ NautilusPropertiesWindow *window;
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
- g_assert (NAUTILUS_IS_FILE (change->file));
- g_assert (change->owner != NULL);
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
+ g_assert (NAUTILUS_IS_FILE (change->file));
+ g_assert (change->owner != NULL);
- if (!change->cancelled) {
- /* Report the error if it's an error. */
- eel_timed_wait_stop ((EelCancelCallback) cancel_owner_change_callback, change);
- nautilus_report_error_setting_owner (file, error, change->window);
- }
+ if (!change->cancelled)
+ {
+ /* Report the error if it's an error. */
+ eel_timed_wait_stop ((EelCancelCallback) cancel_owner_change_callback, change);
+ nautilus_report_error_setting_owner (file, error, change->window);
+ }
- window = NAUTILUS_PROPERTIES_WINDOW(change->window);
- if (window->details->owner_change == change) {
- window->details->owner_change = NULL;
- }
+ window = NAUTILUS_PROPERTIES_WINDOW (change->window);
+ if (window->details->owner_change == change)
+ {
+ window->details->owner_change = NULL;
+ }
- owner_change_free (change);
+ owner_change_free (change);
}
static void
cancel_owner_change_callback (OwnerChange *change)
{
- g_assert (NAUTILUS_IS_FILE (change->file));
- g_assert (change->owner != NULL);
+ g_assert (NAUTILUS_IS_FILE (change->file));
+ g_assert (change->owner != NULL);
- change->cancelled = TRUE;
- nautilus_file_cancel (change->file, (NautilusFileOperationCallback) owner_change_callback, change);
+ change->cancelled = TRUE;
+ nautilus_file_cancel (change->file, (NautilusFileOperationCallback) owner_change_callback, change);
}
static gboolean
schedule_owner_change_timeout (OwnerChange *change)
{
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
- g_assert (NAUTILUS_IS_FILE (change->file));
- g_assert (change->owner != NULL);
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (change->window));
+ g_assert (NAUTILUS_IS_FILE (change->file));
+ g_assert (change->owner != NULL);
- change->timeout = 0;
+ change->timeout = 0;
- eel_timed_wait_start
- ((EelCancelCallback) cancel_owner_change_callback,
- change,
- _("Cancel Owner Change?"),
- change->window);
+ eel_timed_wait_start
+ ((EelCancelCallback) cancel_owner_change_callback,
+ change,
+ _("Cancel Owner Change?"),
+ change->window);
- nautilus_file_set_owner
- (change->file, change->owner,
- (NautilusFileOperationCallback) owner_change_callback, change);
+ nautilus_file_set_owner
+ (change->file, change->owner,
+ (NautilusFileOperationCallback) owner_change_callback, change);
- return FALSE;
+ return FALSE;
}
static void
schedule_owner_change (NautilusPropertiesWindow *window,
- NautilusFile *file,
- const char *owner)
+ NautilusFile *file,
+ const char *owner)
{
- OwnerChange *change;
+ OwnerChange *change;
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
- g_assert (window->details->owner_change == NULL);
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+ g_assert (window->details->owner_change == NULL);
+ g_assert (NAUTILUS_IS_FILE (file));
- change = g_new0 (OwnerChange, 1);
+ change = g_new0 (OwnerChange, 1);
- change->file = nautilus_file_ref (file);
- change->owner = g_strdup (owner);
- change->window = g_object_ref (G_OBJECT (window));
- change->timeout =
- g_timeout_add (CHOWN_CHGRP_TIMEOUT,
- (GSourceFunc) schedule_owner_change_timeout,
- change);
+ change->file = nautilus_file_ref (file);
+ change->owner = g_strdup (owner);
+ change->window = g_object_ref (G_OBJECT (window));
+ change->timeout =
+ g_timeout_add (CHOWN_CHGRP_TIMEOUT,
+ (GSourceFunc) schedule_owner_change_timeout,
+ change);
- window->details->owner_change = change;
+ window->details->owner_change = change;
}
static void
unschedule_or_cancel_owner_change (NautilusPropertiesWindow *window)
{
- OwnerChange *change;
+ OwnerChange *change;
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
- change = window->details->owner_change;
+ change = window->details->owner_change;
- if (change != NULL) {
- g_assert (NAUTILUS_IS_FILE (change->file));
+ if (change != NULL)
+ {
+ g_assert (NAUTILUS_IS_FILE (change->file));
- if (change->timeout == 0) {
- /* The operation was started, cancel it and let the operation callback free the change */
- cancel_owner_change_callback (change);
- eel_timed_wait_stop ((EelCancelCallback) cancel_owner_change_callback, change);
- } else {
- g_source_remove (change->timeout);
- owner_change_free (change);
- }
+ if (change->timeout == 0)
+ {
+ /* The operation was started, cancel it and let the operation callback free the change */
+ cancel_owner_change_callback (change);
+ eel_timed_wait_stop ((EelCancelCallback) cancel_owner_change_callback, change);
+ }
+ else
+ {
+ g_source_remove (change->timeout);
+ owner_change_free (change);
+ }
- window->details->owner_change = NULL;
- }
+ window->details->owner_change = NULL;
+ }
}
static void
-changed_owner_callback (GtkComboBox *combo_box, NautilusFile* file)
+changed_owner_callback (GtkComboBox *combo_box,
+ NautilusFile *file)
{
- NautilusPropertiesWindow *window;
- char *new_owner;
- char *cur_owner;
+ NautilusPropertiesWindow *window;
+ char *new_owner;
+ char *cur_owner;
- g_assert (GTK_IS_COMBO_BOX (combo_box));
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (GTK_IS_COMBO_BOX (combo_box));
+ g_assert (NAUTILUS_IS_FILE (file));
- new_owner = combo_box_get_active_entry (combo_box, 2);
- if (! new_owner)
- return;
- cur_owner = nautilus_file_get_owner_name (file);
+ new_owner = combo_box_get_active_entry (combo_box, 2);
+ if (!new_owner)
+ {
+ return;
+ }
+ cur_owner = nautilus_file_get_owner_name (file);
- if (strcmp (new_owner, cur_owner) != 0) {
- /* Try to change file owner. If this fails, complain to user. */
- window = NAUTILUS_PROPERTIES_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (combo_box), GTK_TYPE_WINDOW));
+ if (strcmp (new_owner, cur_owner) != 0)
+ {
+ /* Try to change file owner. If this fails, complain to user. */
+ window = NAUTILUS_PROPERTIES_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (combo_box), GTK_TYPE_WINDOW));
- unschedule_or_cancel_owner_change (window);
- schedule_owner_change (window, file, new_owner);
- }
- g_free (new_owner);
- g_free (cur_owner);
+ unschedule_or_cancel_owner_change (window);
+ schedule_owner_change (window, file, new_owner);
+ }
+ g_free (new_owner);
+ g_free (cur_owner);
}
static void
-synch_user_menu (GtkComboBox *combo_box, NautilusFile *file)
-{
- GList *users;
- GList *node;
- GtkTreeModel *model;
- GtkListStore *store;
- GtkTreeIter iter;
- char *user_name;
- char *owner_name;
- char *nice_owner_name;
- int user_index;
- int owner_index;
- char **name_array;
- char *combo_text;
-
- g_assert (GTK_IS_COMBO_BOX (combo_box));
- g_assert (NAUTILUS_IS_FILE (file));
-
- if (nautilus_file_is_gone (file)) {
- return;
- }
-
- users = nautilus_get_user_names ();
-
- model = gtk_combo_box_get_model (combo_box);
- store = GTK_LIST_STORE (model);
- g_assert (GTK_IS_LIST_STORE (model));
-
- if (!tree_model_entries_equal (model, 1, users)) {
- /* Clear the contents of ComboBox in a wacky way because there
- * is no function to clear all items and also no function to obtain
- * the number of items in a combobox.
- */
- gtk_list_store_clear (store);
-
- for (node = users, user_index = 0; node != NULL; node = node->next, ++user_index) {
- user_name = (char *)node->data;
-
- name_array = g_strsplit (user_name, "\n", 2);
- if (name_array[1] != NULL && *name_array[1] != 0) {
- combo_text = g_strdup_printf ("%s - %s", name_array[0], name_array[1]);
- } else {
- combo_text = g_strdup (name_array[0]);
- }
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, combo_text,
- 1, user_name,
- 2, name_array[0],
- -1);
-
- g_strfreev (name_array);
- g_free (combo_text);
- }
- }
-
- owner_name = nautilus_file_get_owner_name (file);
- owner_index = tree_model_get_entry_index (model, 2, owner_name);
- nice_owner_name = nautilus_file_get_string_attribute (file, "owner");
-
- /* If owner wasn't in list, we prepend it (with a separator).
- * This can happen if the owner is an id with no matching
- * identifier in the passwords file.
- */
- if (owner_index < 0 && owner_name != NULL) {
- if (users != NULL) {
- /* add separator */
- gtk_list_store_prepend (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, "-",
- 1, NULL,
- 2, NULL,
- -1);
- }
-
- owner_index = 0;
-
- gtk_list_store_prepend (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, nice_owner_name,
- 1, owner_name,
- 2, owner_name,
- -1);
- }
-
- gtk_combo_box_set_active (combo_box, owner_index);
-
- g_free (owner_name);
- g_free (nice_owner_name);
- g_list_free_full (users, g_free);
-}
-
-static GtkComboBox*
-attach_owner_combo_box (GtkGrid *grid,
- GtkWidget *sibling,
- NautilusFile *file)
-{
- GtkComboBox *combo_box;
-
- combo_box = attach_combo_box (grid, sibling, TRUE);
-
- synch_user_menu (combo_box, file);
-
- /* Connect to signal to update menu when file changes. */
- g_signal_connect_object (file, "changed",
- G_CALLBACK (synch_user_menu),
- combo_box, G_CONNECT_SWAPPED);
- g_signal_connect_data (combo_box, "changed",
- G_CALLBACK (changed_owner_callback),
- nautilus_file_ref (file),
- (GClosureNotify)nautilus_file_unref, 0);
-
- return combo_box;
+synch_user_menu (GtkComboBox *combo_box,
+ NautilusFile *file)
+{
+ GList *users;
+ GList *node;
+ GtkTreeModel *model;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ char *user_name;
+ char *owner_name;
+ char *nice_owner_name;
+ int user_index;
+ int owner_index;
+ char **name_array;
+ char *combo_text;
+
+ g_assert (GTK_IS_COMBO_BOX (combo_box));
+ g_assert (NAUTILUS_IS_FILE (file));
+
+ if (nautilus_file_is_gone (file))
+ {
+ return;
+ }
+
+ users = nautilus_get_user_names ();
+
+ model = gtk_combo_box_get_model (combo_box);
+ store = GTK_LIST_STORE (model);
+ g_assert (GTK_IS_LIST_STORE (model));
+
+ if (!tree_model_entries_equal (model, 1, users))
+ {
+ /* Clear the contents of ComboBox in a wacky way because there
+ * is no function to clear all items and also no function to obtain
+ * the number of items in a combobox.
+ */
+ gtk_list_store_clear (store);
+
+ for (node = users, user_index = 0; node != NULL; node = node->next, ++user_index)
+ {
+ user_name = (char *) node->data;
+
+ name_array = g_strsplit (user_name, "\n", 2);
+ if (name_array[1] != NULL && *name_array[1] != 0)
+ {
+ combo_text = g_strdup_printf ("%s - %s", name_array[0], name_array[1]);
+ }
+ else
+ {
+ combo_text = g_strdup (name_array[0]);
+ }
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, combo_text,
+ 1, user_name,
+ 2, name_array[0],
+ -1);
+
+ g_strfreev (name_array);
+ g_free (combo_text);
+ }
+ }
+
+ owner_name = nautilus_file_get_owner_name (file);
+ owner_index = tree_model_get_entry_index (model, 2, owner_name);
+ nice_owner_name = nautilus_file_get_string_attribute (file, "owner");
+
+ /* If owner wasn't in list, we prepend it (with a separator).
+ * This can happen if the owner is an id with no matching
+ * identifier in the passwords file.
+ */
+ if (owner_index < 0 && owner_name != NULL)
+ {
+ if (users != NULL)
+ {
+ /* add separator */
+ gtk_list_store_prepend (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, "-",
+ 1, NULL,
+ 2, NULL,
+ -1);
+ }
+
+ owner_index = 0;
+
+ gtk_list_store_prepend (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, nice_owner_name,
+ 1, owner_name,
+ 2, owner_name,
+ -1);
+ }
+
+ gtk_combo_box_set_active (combo_box, owner_index);
+
+ g_free (owner_name);
+ g_free (nice_owner_name);
+ g_list_free_full (users, g_free);
+}
+
+static GtkComboBox *
+attach_owner_combo_box (GtkGrid *grid,
+ GtkWidget *sibling,
+ NautilusFile *file)
+{
+ GtkComboBox *combo_box;
+
+ combo_box = attach_combo_box (grid, sibling, TRUE);
+
+ synch_user_menu (combo_box, file);
+
+ /* Connect to signal to update menu when file changes. */
+ g_signal_connect_object (file, "changed",
+ G_CALLBACK (synch_user_menu),
+ combo_box, G_CONNECT_SWAPPED);
+ g_signal_connect_data (combo_box, "changed",
+ G_CALLBACK (changed_owner_callback),
+ nautilus_file_ref (file),
+ (GClosureNotify) nautilus_file_unref, 0);
+
+ return combo_box;
}
static gboolean
file_has_prefix (NautilusFile *file,
- GList *prefix_candidates)
+ GList *prefix_candidates)
{
- GList *p;
- GFile *location, *candidate_location;
+ GList *p;
+ GFile *location, *candidate_location;
- location = nautilus_file_get_location (file);
+ location = nautilus_file_get_location (file);
- for (p = prefix_candidates; p != NULL; p = p->next) {
- if (file == p->data) {
- continue;
- }
+ for (p = prefix_candidates; p != NULL; p = p->next)
+ {
+ if (file == p->data)
+ {
+ continue;
+ }
- candidate_location = nautilus_file_get_location (NAUTILUS_FILE (p->data));
- if (g_file_has_prefix (location, candidate_location)) {
- g_object_unref (location);
- g_object_unref (candidate_location);
- return TRUE;
- }
- g_object_unref (candidate_location);
- }
+ candidate_location = nautilus_file_get_location (NAUTILUS_FILE (p->data));
+ if (g_file_has_prefix (location, candidate_location))
+ {
+ g_object_unref (location);
+ g_object_unref (candidate_location);
+ return TRUE;
+ }
+ g_object_unref (candidate_location);
+ }
- g_object_unref (location);
+ g_object_unref (location);
- return FALSE;
+ return FALSE;
}
static void
directory_contents_value_field_update (NautilusPropertiesWindow *window)
{
- NautilusRequestStatus file_status;
- char *text, *temp;
- guint directory_count;
- guint file_count;
- guint total_count;
- guint unreadable_directory_count;
- goffset total_size;
- gboolean used_two_lines;
- NautilusFile *file;
- GList *l;
- guint file_unreadable;
- goffset file_size;
- gboolean deep_count_active;
-
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
-
- total_count = window->details->total_count;
- total_size = window->details->total_size;
- unreadable_directory_count = FALSE;
-
- for (l = window->details->target_files; l; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- if (file_has_prefix (file, window->details->target_files)) {
- /* don't count nested files twice */
- continue;
- }
-
- if (nautilus_file_is_directory (file)) {
- file_status = nautilus_file_get_deep_counts (file,
- &directory_count,
- &file_count,
- &file_unreadable,
- &file_size,
- TRUE);
- total_count += (file_count + directory_count);
- total_size += file_size;
-
- if (file_unreadable) {
- unreadable_directory_count = TRUE;
- }
-
- if (file_status == NAUTILUS_REQUEST_DONE) {
- stop_deep_count_for_file (window, file);
- }
- } else {
- ++total_count;
- total_size += nautilus_file_get_size (file);
- }
- }
-
- deep_count_active = (g_list_length (window->details->deep_count_files) > 0);
- /* If we've already displayed the total once, don't do another visible
- * count-up if the deep_count happens to get invalidated.
- * But still display the new total, since it might have changed.
- */
- if (window->details->deep_count_finished && deep_count_active) {
- return;
- }
-
- text = NULL;
- used_two_lines = FALSE;
-
- if (total_count == 0) {
- if (!deep_count_active) {
- if (unreadable_directory_count == 0) {
- text = g_strdup (_("nothing"));
- } else {
- text = g_strdup (_("unreadable"));
- }
- } else {
- text = g_strdup ("…");
- }
- } else {
- char *size_str;
- size_str = g_format_size (total_size);
- text = g_strdup_printf (ngettext("%'d item, with size %s",
- "%'d items, totalling %s",
- total_count),
- total_count, size_str);
- g_free (size_str);
-
- if (unreadable_directory_count != 0) {
- temp = text;
- text = g_strconcat (temp, "\n",
- _("(some contents unreadable)"),
- NULL);
- g_free (temp);
- used_two_lines = TRUE;
- }
- }
-
- gtk_label_set_text (window->details->directory_contents_value_field,
- text);
- g_free (text);
-
- /* Also set the title field here, with a trailing carriage return &
- * space if the value field has two lines. This is a hack to get the
- * "Contents:" title to line up with the first line of the
- * 2-line value. Maybe there's a better way to do this, but I
- * couldn't think of one.
- */
- text = g_strdup (_("Contents:"));
- if (used_two_lines) {
- temp = text;
- text = g_strconcat (temp, "\n ", NULL);
- g_free (temp);
- }
- gtk_label_set_text (window->details->directory_contents_title_field,
- text);
- g_free (text);
-
- if (!deep_count_active) {
- window->details->deep_count_finished = TRUE;
- stop_spinner (window);
- }
+ NautilusRequestStatus file_status;
+ char *text, *temp;
+ guint directory_count;
+ guint file_count;
+ guint total_count;
+ guint unreadable_directory_count;
+ goffset total_size;
+ gboolean used_two_lines;
+ NautilusFile *file;
+ GList *l;
+ guint file_unreadable;
+ goffset file_size;
+ gboolean deep_count_active;
+
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+
+ total_count = window->details->total_count;
+ total_size = window->details->total_size;
+ unreadable_directory_count = FALSE;
+
+ for (l = window->details->target_files; l; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ if (file_has_prefix (file, window->details->target_files))
+ {
+ /* don't count nested files twice */
+ continue;
+ }
+
+ if (nautilus_file_is_directory (file))
+ {
+ file_status = nautilus_file_get_deep_counts (file,
+ &directory_count,
+ &file_count,
+ &file_unreadable,
+ &file_size,
+ TRUE);
+ total_count += (file_count + directory_count);
+ total_size += file_size;
+
+ if (file_unreadable)
+ {
+ unreadable_directory_count = TRUE;
+ }
+
+ if (file_status == NAUTILUS_REQUEST_DONE)
+ {
+ stop_deep_count_for_file (window, file);
+ }
+ }
+ else
+ {
+ ++total_count;
+ total_size += nautilus_file_get_size (file);
+ }
+ }
+
+ deep_count_active = (g_list_length (window->details->deep_count_files) > 0);
+ /* If we've already displayed the total once, don't do another visible
+ * count-up if the deep_count happens to get invalidated.
+ * But still display the new total, since it might have changed.
+ */
+ if (window->details->deep_count_finished && deep_count_active)
+ {
+ return;
+ }
+
+ text = NULL;
+ used_two_lines = FALSE;
+
+ if (total_count == 0)
+ {
+ if (!deep_count_active)
+ {
+ if (unreadable_directory_count == 0)
+ {
+ text = g_strdup (_("nothing"));
+ }
+ else
+ {
+ text = g_strdup (_("unreadable"));
+ }
+ }
+ else
+ {
+ text = g_strdup ("…");
+ }
+ }
+ else
+ {
+ char *size_str;
+ size_str = g_format_size (total_size);
+ text = g_strdup_printf (ngettext ("%'d item, with size %s",
+ "%'d items, totalling %s",
+ total_count),
+ total_count, size_str);
+ g_free (size_str);
+
+ if (unreadable_directory_count != 0)
+ {
+ temp = text;
+ text = g_strconcat (temp, "\n",
+ _("(some contents unreadable)"),
+ NULL);
+ g_free (temp);
+ used_two_lines = TRUE;
+ }
+ }
+
+ gtk_label_set_text (window->details->directory_contents_value_field,
+ text);
+ g_free (text);
+
+ /* Also set the title field here, with a trailing carriage return &
+ * space if the value field has two lines. This is a hack to get the
+ * "Contents:" title to line up with the first line of the
+ * 2-line value. Maybe there's a better way to do this, but I
+ * couldn't think of one.
+ */
+ text = g_strdup (_("Contents:"));
+ if (used_two_lines)
+ {
+ temp = text;
+ text = g_strconcat (temp, "\n ", NULL);
+ g_free (temp);
+ }
+ gtk_label_set_text (window->details->directory_contents_title_field,
+ text);
+ g_free (text);
+
+ if (!deep_count_active)
+ {
+ window->details->deep_count_finished = TRUE;
+ stop_spinner (window);
+ }
}
static gboolean
update_directory_contents_callback (gpointer data)
{
- NautilusPropertiesWindow *window;
+ NautilusPropertiesWindow *window;
- window = NAUTILUS_PROPERTIES_WINDOW (data);
+ window = NAUTILUS_PROPERTIES_WINDOW (data);
- window->details->update_directory_contents_timeout_id = 0;
- directory_contents_value_field_update (window);
+ window->details->update_directory_contents_timeout_id = 0;
+ directory_contents_value_field_update (window);
- return FALSE;
+ return FALSE;
}
static void
schedule_directory_contents_update (NautilusPropertiesWindow *window)
{
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
- if (window->details->update_directory_contents_timeout_id == 0) {
- window->details->update_directory_contents_timeout_id
- = g_timeout_add (DIRECTORY_CONTENTS_UPDATE_INTERVAL,
- update_directory_contents_callback,
- window);
- }
+ if (window->details->update_directory_contents_timeout_id == 0)
+ {
+ window->details->update_directory_contents_timeout_id
+ = g_timeout_add (DIRECTORY_CONTENTS_UPDATE_INTERVAL,
+ update_directory_contents_callback,
+ window);
+ }
}
static GtkLabel *
attach_directory_contents_value_field (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- GtkWidget *sibling)
+ GtkGrid *grid,
+ GtkWidget *sibling)
{
- GtkLabel *value_field;
+ GtkLabel *value_field;
- value_field = attach_value_label (grid, sibling, "");
+ value_field = attach_value_label (grid, sibling, "");
- g_assert (window->details->directory_contents_value_field == NULL);
- window->details->directory_contents_value_field = value_field;
+ g_assert (window->details->directory_contents_value_field == NULL);
+ window->details->directory_contents_value_field = value_field;
- gtk_label_set_line_wrap (value_field, TRUE);
+ gtk_label_set_line_wrap (value_field, TRUE);
- return value_field;
+ return value_field;
}
static GtkLabel *
-attach_title_field (GtkGrid *grid,
- const char *title)
+attach_title_field (GtkGrid *grid,
+ const char *title)
{
- return attach_label (grid, NULL, title, FALSE, FALSE, TRUE);
-}
+ return attach_label (grid, NULL, title, FALSE, FALSE, TRUE);
+}
#define INCONSISTENT_STATE_STRING \
- "\xE2\x80\x92"
+ "\xE2\x80\x92"
static void
append_title_value_pair (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- const char *title,
- const char *file_attribute_name,
- const char *inconsistent_state,
- gboolean show_original)
+ GtkGrid *grid,
+ const char *title,
+ const char *file_attribute_name,
+ const char *inconsistent_state,
+ gboolean show_original)
{
- GtkLabel *title_label;
- GtkWidget *value;
+ GtkLabel *title_label;
+ GtkWidget *value;
- title_label = attach_title_field (grid, title);
- value = attach_value_field (window, grid, GTK_WIDGET (title_label),
- file_attribute_name,
- inconsistent_state,
- show_original);
- gtk_label_set_mnemonic_widget (title_label, value);
+ title_label = attach_title_field (grid, title);
+ value = attach_value_field (window, grid, GTK_WIDGET (title_label),
+ file_attribute_name,
+ inconsistent_state,
+ show_original);
+ gtk_label_set_mnemonic_widget (title_label, value);
}
static void
append_title_and_ellipsizing_value (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- const char *title,
- const char *file_attribute_name,
- const char *inconsistent_state,
- gboolean show_original)
+ GtkGrid *grid,
+ const char *title,
+ const char *file_attribute_name,
+ const char *inconsistent_state,
+ gboolean show_original)
{
- GtkLabel *title_label;
- GtkWidget *value;
+ GtkLabel *title_label;
+ GtkWidget *value;
- title_label = attach_title_field (grid, title);
- value = attach_ellipsizing_value_field (window, grid,
- GTK_WIDGET (title_label),
- file_attribute_name,
- inconsistent_state,
- show_original);
- gtk_label_set_mnemonic_widget (title_label, value);
+ title_label = attach_title_field (grid, title);
+ value = attach_ellipsizing_value_field (window, grid,
+ GTK_WIDGET (title_label),
+ file_attribute_name,
+ inconsistent_state,
+ show_original);
+ gtk_label_set_mnemonic_widget (title_label, value);
}
static void
append_directory_contents_fields (NautilusPropertiesWindow *window,
- GtkGrid *grid)
+ GtkGrid *grid)
{
- GtkLabel *title_field, *value_field;
- GList *l;
+ GtkLabel *title_field, *value_field;
+ GList *l;
- title_field = attach_title_field (grid, "");
- window->details->directory_contents_title_field = title_field;
- gtk_label_set_line_wrap (title_field, TRUE);
+ title_field = attach_title_field (grid, "");
+ window->details->directory_contents_title_field = title_field;
+ gtk_label_set_line_wrap (title_field, TRUE);
- value_field = attach_directory_contents_value_field (window, grid, GTK_WIDGET (title_field));
+ value_field = attach_directory_contents_value_field (window, grid, GTK_WIDGET (title_field));
- window->details->directory_contents_spinner = gtk_spinner_new ();
+ window->details->directory_contents_spinner = gtk_spinner_new ();
- gtk_grid_attach_next_to (grid,
- window->details->directory_contents_spinner,
- GTK_WIDGET (value_field),
- GTK_POS_RIGHT,
- 1, 1);
+ gtk_grid_attach_next_to (grid,
+ window->details->directory_contents_spinner,
+ GTK_WIDGET (value_field),
+ GTK_POS_RIGHT,
+ 1, 1);
- for (l = window->details->target_files; l; l = l->next) {
- NautilusFile *file;
+ for (l = window->details->target_files; l; l = l->next)
+ {
+ NautilusFile *file;
- file = NAUTILUS_FILE (l->data);
- start_deep_count_for_file (window, file);
- }
+ file = NAUTILUS_FILE (l->data);
+ start_deep_count_for_file (window, file);
+ }
- /* Fill in the initial value. */
- directory_contents_value_field_update (window);
+ /* Fill in the initial value. */
+ directory_contents_value_field_update (window);
- gtk_label_set_mnemonic_widget (title_field, GTK_WIDGET(value_field));
+ gtk_label_set_mnemonic_widget (title_field, GTK_WIDGET (value_field));
}
static GtkWidget *
create_page_with_hbox (GtkNotebook *notebook,
- const char *title,
- const char *help_uri)
+ const char *title,
+ const char *help_uri)
{
- GtkWidget *hbox;
+ GtkWidget *hbox;
- g_assert (GTK_IS_NOTEBOOK (notebook));
- g_assert (title != NULL);
+ g_assert (GTK_IS_NOTEBOOK (notebook));
+ g_assert (title != NULL);
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (hbox);
- gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
- gtk_box_set_spacing (GTK_BOX (hbox), 12);
- gtk_notebook_append_page (notebook, hbox, gtk_label_new (title));
- gtk_container_child_set (GTK_CONTAINER (notebook),
- hbox,
- "tab-expand", TRUE,
- NULL);
- g_object_set_data_full (G_OBJECT (hbox), "help-uri", g_strdup (help_uri), g_free);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_show (hbox);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
+ gtk_box_set_spacing (GTK_BOX (hbox), 12);
+ gtk_notebook_append_page (notebook, hbox, gtk_label_new (title));
+ gtk_container_child_set (GTK_CONTAINER (notebook),
+ hbox,
+ "tab-expand", TRUE,
+ NULL);
+ g_object_set_data_full (G_OBJECT (hbox), "help-uri", g_strdup (help_uri), g_free);
- return hbox;
+ return hbox;
}
static GtkWidget *
create_page_with_vbox (GtkNotebook *notebook,
- const char *title,
- const char *help_uri)
+ const char *title,
+ const char *help_uri)
{
- GtkWidget *vbox;
+ GtkWidget *vbox;
- g_assert (GTK_IS_NOTEBOOK (notebook));
- g_assert (title != NULL);
+ g_assert (GTK_IS_NOTEBOOK (notebook));
+ g_assert (title != NULL);
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_show (vbox);
- gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
- gtk_notebook_append_page (notebook, vbox, gtk_label_new (title));
- gtk_container_child_set (GTK_CONTAINER (notebook),
- vbox,
- "tab-expand", TRUE,
- NULL);
- g_object_set_data_full (G_OBJECT (vbox), "help-uri", g_strdup (help_uri), g_free);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_show (vbox);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
+ gtk_notebook_append_page (notebook, vbox, gtk_label_new (title));
+ gtk_container_child_set (GTK_CONTAINER (notebook),
+ vbox,
+ "tab-expand", TRUE,
+ NULL);
+ g_object_set_data_full (G_OBJECT (vbox), "help-uri", g_strdup (help_uri), g_free);
- return vbox;
-}
+ return vbox;
+}
static GtkWidget *
append_blank_row (GtkGrid *grid)
{
- return GTK_WIDGET (attach_title_field (grid, ""));
+ return GTK_WIDGET (attach_title_field (grid, ""));
}
static void
append_blank_slim_row (GtkGrid *grid)
{
- GtkWidget *w;
- PangoAttribute *attribute;
- PangoAttrList *attr_list;
+ GtkWidget *w;
+ PangoAttribute *attribute;
+ PangoAttrList *attr_list;
- attr_list = pango_attr_list_new ();
- attribute = pango_attr_scale_new (0.30);
- pango_attr_list_insert (attr_list, attribute);
+ attr_list = pango_attr_list_new ();
+ attribute = pango_attr_scale_new (0.30);
+ pango_attr_list_insert (attr_list, attribute);
- w = gtk_label_new (NULL);
- gtk_label_set_attributes (GTK_LABEL (w), attr_list);
- gtk_widget_show (w);
+ w = gtk_label_new (NULL);
+ gtk_label_set_attributes (GTK_LABEL (w), attr_list);
+ gtk_widget_show (w);
- pango_attr_list_unref (attr_list);
+ pango_attr_list_unref (attr_list);
- gtk_container_add (GTK_CONTAINER (grid), w);
+ gtk_container_add (GTK_CONTAINER (grid), w);
}
static GtkWidget *
create_grid_with_standard_properties (void)
{
- GtkWidget *grid;
+ GtkWidget *grid;
- grid = gtk_grid_new ();
- gtk_container_set_border_width (GTK_CONTAINER (grid), 6);
- gtk_grid_set_row_spacing (GTK_GRID (grid), ROW_PAD);
- gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
- gtk_widget_show (grid);
+ grid = gtk_grid_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (grid), 6);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), ROW_PAD);
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
+ gtk_widget_show (grid);
- return grid;
+ return grid;
}
static gboolean
-is_merged_trash_directory (NautilusFile *file)
+is_merged_trash_directory (NautilusFile *file)
{
- char *file_uri;
- gboolean result;
+ char *file_uri;
+ gboolean result;
- file_uri = nautilus_file_get_uri (file);
- result = strcmp (file_uri, "trash:///") == 0;
- g_free (file_uri);
+ file_uri = nautilus_file_get_uri (file);
+ result = strcmp (file_uri, "trash:///") == 0;
+ g_free (file_uri);
- return result;
+ return result;
}
static gboolean
is_computer_directory (NautilusFile *file)
{
- char *file_uri;
- gboolean result;
-
- file_uri = nautilus_file_get_uri (file);
- result = strcmp (file_uri, "computer:///") == 0;
- g_free (file_uri);
-
- return result;
+ char *file_uri;
+ gboolean result;
+
+ file_uri = nautilus_file_get_uri (file);
+ result = strcmp (file_uri, "computer:///") == 0;
+ g_free (file_uri);
+
+ return result;
}
static gboolean
is_root_directory (NautilusFile *file)
{
- GFile *location;
- gboolean result;
+ GFile *location;
+ gboolean result;
- location = nautilus_file_get_location (file);
- result = nautilus_is_root_directory (location);
- g_object_unref (location);
+ location = nautilus_file_get_location (file);
+ result = nautilus_is_root_directory (location);
+ g_object_unref (location);
- return result;
+ return result;
}
static gboolean
is_network_directory (NautilusFile *file)
{
- char *file_uri;
- gboolean result;
-
- file_uri = nautilus_file_get_uri (file);
- result = strcmp (file_uri, "network:///") == 0;
- g_free (file_uri);
-
- return result;
+ char *file_uri;
+ gboolean result;
+
+ file_uri = nautilus_file_get_uri (file);
+ result = strcmp (file_uri, "network:///") == 0;
+ g_free (file_uri);
+
+ return result;
}
static gboolean
is_burn_directory (NautilusFile *file)
{
- char *file_uri;
- gboolean result;
-
- file_uri = nautilus_file_get_uri (file);
- result = strcmp (file_uri, "burn:///") == 0;
- g_free (file_uri);
-
- return result;
+ char *file_uri;
+ gboolean result;
+
+ file_uri = nautilus_file_get_uri (file);
+ result = strcmp (file_uri, "burn:///") == 0;
+ g_free (file_uri);
+
+ return result;
}
static gboolean
is_recent_directory (NautilusFile *file)
{
- char *file_uri;
- gboolean result;
+ char *file_uri;
+ gboolean result;
- file_uri = nautilus_file_get_uri (file);
- result = strcmp (file_uri, "recent:///") == 0;
- g_free (file_uri);
+ file_uri = nautilus_file_get_uri (file);
+ result = strcmp (file_uri, "recent:///") == 0;
+ g_free (file_uri);
- return result;
+ return result;
}
static gboolean
-should_show_custom_icon_buttons (NautilusPropertiesWindow *window)
+should_show_custom_icon_buttons (NautilusPropertiesWindow *window)
{
- if (is_multi_file_window (window)) {
- return FALSE;
- }
+ if (is_multi_file_window (window))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
-should_show_file_type (NautilusPropertiesWindow *window)
+should_show_file_type (NautilusPropertiesWindow *window)
{
- if (!is_multi_file_window (window)
- && (is_merged_trash_directory (get_target_file (window)) ||
- is_computer_directory (get_target_file (window)) ||
- is_network_directory (get_target_file (window)) ||
- is_burn_directory (get_target_file (window)))) {
- return FALSE;
- }
+ if (!is_multi_file_window (window)
+ && (is_merged_trash_directory (get_target_file (window)) ||
+ is_computer_directory (get_target_file (window)) ||
+ is_network_directory (get_target_file (window)) ||
+ is_burn_directory (get_target_file (window))))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
should_show_location_info (NautilusPropertiesWindow *window)
{
- if (!is_multi_file_window (window)
- && (is_merged_trash_directory (get_target_file (window)) ||
- is_root_directory (get_target_file (window)) ||
- is_computer_directory (get_target_file (window)) ||
- is_network_directory (get_target_file (window)) ||
- is_burn_directory (get_target_file (window)))) {
- return FALSE;
- }
+ if (!is_multi_file_window (window)
+ && (is_merged_trash_directory (get_target_file (window)) ||
+ is_root_directory (get_target_file (window)) ||
+ is_computer_directory (get_target_file (window)) ||
+ is_network_directory (get_target_file (window)) ||
+ is_burn_directory (get_target_file (window))))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
-should_show_accessed_date (NautilusPropertiesWindow *window)
+should_show_accessed_date (NautilusPropertiesWindow *window)
{
- /* Accessed date for directory seems useless. If we some
- * day decide that it is useful, we should separately
- * consider whether it's useful for "trash:".
- */
- if (file_list_all_directories (window->details->target_files)) {
- return FALSE;
- }
+ /* Accessed date for directory seems useless. If we some
+ * day decide that it is useful, we should separately
+ * consider whether it's useful for "trash:".
+ */
+ if (file_list_all_directories (window->details->target_files))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
should_show_link_target (NautilusPropertiesWindow *window)
{
- if (!is_multi_file_window (window)
- && nautilus_file_is_symbolic_link (get_target_file (window))) {
- return TRUE;
- }
+ if (!is_multi_file_window (window)
+ && nautilus_file_is_symbolic_link (get_target_file (window)))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
location_show_original (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
+ NautilusFile *file;
- /* there is no way a recent item will be mixed with
- other items so just pick the first file to check */
- file = NAUTILUS_FILE (g_list_nth_data (window->details->original_files, 0));
- return (file != NULL && !nautilus_file_is_in_recent (file));
+ /* there is no way a recent item will be mixed with
+ * other items so just pick the first file to check */
+ file = NAUTILUS_FILE (g_list_nth_data (window->details->original_files, 0));
+ return (file != NULL && !nautilus_file_is_in_recent (file));
}
static gboolean
should_show_free_space (NautilusPropertiesWindow *window)
{
- if (!is_multi_file_window (window)
- && (is_merged_trash_directory (get_target_file (window)) ||
- is_computer_directory (get_target_file (window)) ||
- is_network_directory (get_target_file (window)) ||
- is_recent_directory (get_target_file (window)) ||
- is_burn_directory (get_target_file (window)))) {
- return FALSE;
- }
+ if (!is_multi_file_window (window)
+ && (is_merged_trash_directory (get_target_file (window)) ||
+ is_computer_directory (get_target_file (window)) ||
+ is_network_directory (get_target_file (window)) ||
+ is_recent_directory (get_target_file (window)) ||
+ is_burn_directory (get_target_file (window))))
+ {
+ return FALSE;
+ }
- if (file_list_all_directories (window->details->target_files)) {
- return TRUE;
- }
+ if (file_list_all_directories (window->details->target_files))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
should_show_volume_info (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
+ NautilusFile *file;
- if (is_multi_file_window (window)) {
- return FALSE;
- }
+ if (is_multi_file_window (window))
+ {
+ return FALSE;
+ }
- file = get_original_file (window);
+ file = get_original_file (window);
- if (file == NULL) {
- return FALSE;
- }
+ if (file == NULL)
+ {
+ return FALSE;
+ }
- if (nautilus_file_can_unmount (file)) {
- return TRUE;
- }
+ if (nautilus_file_can_unmount (file))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
should_show_volume_usage (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
- gboolean success = FALSE;
+ NautilusFile *file;
+ gboolean success = FALSE;
- if (is_multi_file_window (window)) {
- return FALSE;
- }
+ if (is_multi_file_window (window))
+ {
+ return FALSE;
+ }
- file = get_original_file (window);
+ file = get_original_file (window);
- if (file == NULL) {
- return FALSE;
- }
+ if (file == NULL)
+ {
+ return FALSE;
+ }
- if (nautilus_file_can_unmount (file)) {
- return TRUE;
- }
+ if (nautilus_file_can_unmount (file))
+ {
+ return TRUE;
+ }
- success = is_root_directory (file);
+ success = is_root_directory (file);
#ifdef TODO_GIO
- /* Look at is_mountpoint for activation uri */
+ /* Look at is_mountpoint for activation uri */
#endif
- return success;
+ return success;
}
static void
paint_legend (GtkWidget *widget,
- cairo_t *cr,
- gpointer data)
+ cairo_t *cr,
+ gpointer data)
{
- GtkStyleContext *context;
- GtkAllocation allocation;
+ GtkStyleContext *context;
+ GtkAllocation allocation;
- gtk_widget_get_allocation (widget, &allocation);
- context = gtk_widget_get_style_context (widget);
+ gtk_widget_get_allocation (widget, &allocation);
+ context = gtk_widget_get_style_context (widget);
- gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height);
- gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height);
+ gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height);
+ gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height);
}
static void
-paint_slice (GtkWidget *widget,
- cairo_t *cr,
- double percent_start,
- double percent_width,
- const gchar *style_class)
-{
- double angle1;
- double angle2;
- gboolean full;
- double offset = G_PI / 2.0;
- GdkRGBA stroke, fill;
- GtkStateFlags state;
- GtkBorder border;
- GtkStyleContext *context;
- double x, y, radius;
- gint width, height;
-
- if (percent_width < .01) {
- return;
- }
-
- context = gtk_widget_get_style_context (widget);
- state = gtk_style_context_get_state (context);
- gtk_style_context_get_border (context, state, &border);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, style_class);
- gtk_style_context_get_background_color (context, state, &fill);
- gtk_style_context_get_border_color (context, state, &stroke);
- gtk_style_context_restore (context);
-
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
- x = width / 2;
- y = height / 2;
-
- if (width < height) {
- radius = (width - border.left) / 2;
- } else {
- radius = (height - border.top) / 2;
- }
-
- angle1 = (percent_start * 2 * G_PI) - offset;
- angle2 = angle1 + (percent_width * 2 * G_PI);
-
- full = (percent_width > .99);
-
- if (!full) {
- cairo_move_to (cr, x, y);
- }
- cairo_arc (cr, x, y, radius, angle1, angle2);
-
- if (!full) {
- cairo_line_to (cr, x, y);
- }
-
- cairo_set_line_width (cr, border.top);
- gdk_cairo_set_source_rgba (cr, &fill);
- cairo_fill_preserve (cr);
-
- gdk_cairo_set_source_rgba (cr, &stroke);
- cairo_stroke (cr);
+paint_slice (GtkWidget *widget,
+ cairo_t *cr,
+ double percent_start,
+ double percent_width,
+ const gchar *style_class)
+{
+ double angle1;
+ double angle2;
+ gboolean full;
+ double offset = G_PI / 2.0;
+ GdkRGBA stroke, fill;
+ GtkStateFlags state;
+ GtkBorder border;
+ GtkStyleContext *context;
+ double x, y, radius;
+ gint width, height;
+
+ if (percent_width < .01)
+ {
+ return;
+ }
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_style_context_get_state (context);
+ gtk_style_context_get_border (context, state, &border);
+
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, style_class);
+ gtk_style_context_get_background_color (context, state, &fill);
+ gtk_style_context_get_border_color (context, state, &stroke);
+ gtk_style_context_restore (context);
+
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+ x = width / 2;
+ y = height / 2;
+
+ if (width < height)
+ {
+ radius = (width - border.left) / 2;
+ }
+ else
+ {
+ radius = (height - border.top) / 2;
+ }
+
+ angle1 = (percent_start * 2 * G_PI) - offset;
+ angle2 = angle1 + (percent_width * 2 * G_PI);
+
+ full = (percent_width > .99);
+
+ if (!full)
+ {
+ cairo_move_to (cr, x, y);
+ }
+ cairo_arc (cr, x, y, radius, angle1, angle2);
+
+ if (!full)
+ {
+ cairo_line_to (cr, x, y);
+ }
+
+ cairo_set_line_width (cr, border.top);
+ gdk_cairo_set_source_rgba (cr, &fill);
+ cairo_fill_preserve (cr);
+
+ gdk_cairo_set_source_rgba (cr, &stroke);
+ cairo_stroke (cr);
}
static void
paint_pie_chart (GtkWidget *widget,
- cairo_t *cr,
- gpointer data)
+ cairo_t *cr,
+ gpointer data)
{
- NautilusPropertiesWindow *window;
- double free, used, reserved;
+ NautilusPropertiesWindow *window;
+ double free, used, reserved;
- window = NAUTILUS_PROPERTIES_WINDOW (data);
+ window = NAUTILUS_PROPERTIES_WINDOW (data);
- free = (double)window->details->volume_free / (double)window->details->volume_capacity;
- used = (double)window->details->volume_used / (double)window->details->volume_capacity;
- reserved = 1.0 - (used + free);
+ free = (double) window->details->volume_free / (double) window->details->volume_capacity;
+ used = (double) window->details->volume_used / (double) window->details->volume_capacity;
+ reserved = 1.0 - (used + free);
- paint_slice (widget, cr,
- 0, free, "free");
- paint_slice (widget, cr,
- free + used, reserved, "unknown");
- /* paint the used last so its slice strokes are on top */
- paint_slice (widget, cr,
- free, used, "used");
+ paint_slice (widget, cr,
+ 0, free, "free");
+ paint_slice (widget, cr,
+ free + used, reserved, "unknown");
+ /* paint the used last so its slice strokes are on top */
+ paint_slice (widget, cr,
+ free, used, "used");
}
-static GtkWidget*
+static GtkWidget *
create_pie_widget (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
- GtkGrid *grid;
- GtkStyleContext *style;
- GtkWidget *pie_canvas;
- GtkWidget *used_canvas;
- GtkWidget *used_label;
- GtkWidget *used_type_label;
- GtkWidget *free_canvas;
- GtkWidget *free_label;
- GtkWidget *free_type_label;
- GtkWidget *capacity_label;
- GtkWidget *capacity_value_label;
- GtkWidget *fstype_label;
- GtkWidget *fstype_value_label;
- GtkWidget *spacer_label;
- gchar *capacity;
- gchar *used;
- gchar *free;
- const char *fs_type;
- gchar *uri;
- GFile *location;
- GFileInfo *info;
-
- capacity = g_format_size (window->details->volume_capacity);
- free = g_format_size (window->details->volume_free);
- used = g_format_size (window->details->volume_used);
-
- file = get_original_file (window);
-
- uri = nautilus_file_get_activation_uri (file);
-
- grid = GTK_GRID (gtk_grid_new ());
- gtk_widget_set_hexpand (GTK_WIDGET (grid), FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
- gtk_grid_set_row_spacing (GTK_GRID (grid), 10);
- gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
-
- pie_canvas = gtk_drawing_area_new ();
- gtk_widget_set_size_request (pie_canvas, 200, 200);
- style = gtk_widget_get_style_context (pie_canvas);
- gtk_style_context_add_class (style, "disk-space-display");
-
- used_canvas = gtk_drawing_area_new ();
- gtk_widget_set_size_request (used_canvas, 20, 20);
- style = gtk_widget_get_style_context (used_canvas);
- gtk_style_context_add_class (style, "disk-space-display");
- gtk_style_context_add_class (style, "used");
-
- used_label = gtk_label_new (used);
- /* Translators: "used" refers to the capacity of the filesystem */
- used_type_label = gtk_label_new (_("used"));
-
- free_canvas = gtk_drawing_area_new ();
- gtk_widget_set_size_request (free_canvas, 20, 20);
- style = gtk_widget_get_style_context (free_canvas);
- gtk_style_context_add_class (style, "disk-space-display");
- gtk_style_context_add_class (style, "free");
-
- free_label = gtk_label_new (free);
- /* Translators: "free" refers to the capacity of the filesystem */
- free_type_label = gtk_label_new (_("free"));
-
- capacity_label = gtk_label_new (_("Total capacity:"));
- capacity_value_label = gtk_label_new (capacity);
-
- fstype_label = gtk_label_new (_("Filesystem type:"));
- fstype_value_label = gtk_label_new (NULL);
-
- spacer_label = gtk_label_new ("");
-
- location = g_file_new_for_uri (uri);
- info = g_file_query_filesystem_info (location, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
- NULL, NULL);
- if (info) {
- fs_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
- if (fs_type != NULL) {
- gtk_label_set_text (GTK_LABEL (fstype_value_label), fs_type);
- }
-
- g_object_unref (info);
- }
- g_object_unref (location);
-
- g_free (uri);
- g_free (capacity);
- g_free (used);
- g_free (free);
-
- gtk_container_add_with_properties (GTK_CONTAINER (grid), pie_canvas,
- "height", 5,
- NULL);
-
- gtk_widget_set_vexpand (spacer_label, TRUE);
- gtk_grid_attach_next_to (grid, spacer_label, pie_canvas,
- GTK_POS_RIGHT, 1, 1);
-
- gtk_widget_set_halign (used_canvas, GTK_ALIGN_END);
- gtk_widget_set_vexpand (used_canvas, FALSE);
- gtk_grid_attach_next_to (grid, used_canvas, spacer_label,
- GTK_POS_BOTTOM, 1, 1);
- gtk_widget_set_halign (used_label, GTK_ALIGN_END);
- gtk_widget_set_vexpand (used_label, FALSE);
- gtk_grid_attach_next_to (grid, used_label, used_canvas,
- GTK_POS_RIGHT, 1, 1);
- gtk_widget_set_halign (used_type_label, GTK_ALIGN_START);
- gtk_widget_set_vexpand (used_type_label, FALSE);
- gtk_grid_attach_next_to (grid, used_type_label, used_label,
- GTK_POS_RIGHT, 1, 1);
-
- gtk_widget_set_halign (free_canvas, GTK_ALIGN_END);
- gtk_widget_set_vexpand (free_canvas, FALSE);
- gtk_grid_attach_next_to (grid, free_canvas, used_canvas,
- GTK_POS_BOTTOM, 1, 1);
- gtk_widget_set_halign (free_label, GTK_ALIGN_END);
- gtk_widget_set_vexpand (free_label, FALSE);
- gtk_grid_attach_next_to (grid, free_label, free_canvas,
- GTK_POS_RIGHT, 1, 1);
- gtk_widget_set_halign (free_type_label, GTK_ALIGN_START);
- gtk_widget_set_vexpand (free_type_label, FALSE);
- gtk_grid_attach_next_to (grid, free_type_label, free_label,
- GTK_POS_RIGHT, 1, 1);
-
- gtk_widget_set_halign (capacity_label, GTK_ALIGN_END);
- gtk_widget_set_vexpand (capacity_label, FALSE);
- gtk_grid_attach_next_to (grid, capacity_label, free_canvas,
- GTK_POS_BOTTOM, 1, 1);
- gtk_widget_set_halign (capacity_value_label, GTK_ALIGN_START);
- gtk_widget_set_vexpand (capacity_value_label, FALSE);
- gtk_grid_attach_next_to (grid, capacity_value_label, capacity_label,
- GTK_POS_RIGHT, 1, 1);
-
- gtk_widget_set_halign (fstype_label, GTK_ALIGN_END);
- gtk_widget_set_vexpand (fstype_label, FALSE);
- gtk_grid_attach_next_to (grid, fstype_label, capacity_label,
- GTK_POS_BOTTOM, 1, 1);
- gtk_widget_set_halign (fstype_value_label, GTK_ALIGN_START);
- gtk_widget_set_vexpand (fstype_value_label, FALSE);
- gtk_grid_attach_next_to (grid, fstype_value_label, fstype_label,
- GTK_POS_RIGHT, 1, 1);
-
- g_signal_connect (pie_canvas, "draw",
- G_CALLBACK (paint_pie_chart), window);
- g_signal_connect (used_canvas, "draw",
- G_CALLBACK (paint_legend), window);
- g_signal_connect (free_canvas, "draw",
- G_CALLBACK (paint_legend), window);
-
- return GTK_WIDGET (grid);
-}
-
-static GtkWidget*
+ NautilusFile *file;
+ GtkGrid *grid;
+ GtkStyleContext *style;
+ GtkWidget *pie_canvas;
+ GtkWidget *used_canvas;
+ GtkWidget *used_label;
+ GtkWidget *used_type_label;
+ GtkWidget *free_canvas;
+ GtkWidget *free_label;
+ GtkWidget *free_type_label;
+ GtkWidget *capacity_label;
+ GtkWidget *capacity_value_label;
+ GtkWidget *fstype_label;
+ GtkWidget *fstype_value_label;
+ GtkWidget *spacer_label;
+ gchar *capacity;
+ gchar *used;
+ gchar *free;
+ const char *fs_type;
+ gchar *uri;
+ GFile *location;
+ GFileInfo *info;
+
+ capacity = g_format_size (window->details->volume_capacity);
+ free = g_format_size (window->details->volume_free);
+ used = g_format_size (window->details->volume_used);
+
+ file = get_original_file (window);
+
+ uri = nautilus_file_get_activation_uri (file);
+
+ grid = GTK_GRID (gtk_grid_new ());
+ gtk_widget_set_hexpand (GTK_WIDGET (grid), FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 10);
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 10);
+
+ pie_canvas = gtk_drawing_area_new ();
+ gtk_widget_set_size_request (pie_canvas, 200, 200);
+ style = gtk_widget_get_style_context (pie_canvas);
+ gtk_style_context_add_class (style, "disk-space-display");
+
+ used_canvas = gtk_drawing_area_new ();
+ gtk_widget_set_size_request (used_canvas, 20, 20);
+ style = gtk_widget_get_style_context (used_canvas);
+ gtk_style_context_add_class (style, "disk-space-display");
+ gtk_style_context_add_class (style, "used");
+
+ used_label = gtk_label_new (used);
+ /* Translators: "used" refers to the capacity of the filesystem */
+ used_type_label = gtk_label_new (_("used"));
+
+ free_canvas = gtk_drawing_area_new ();
+ gtk_widget_set_size_request (free_canvas, 20, 20);
+ style = gtk_widget_get_style_context (free_canvas);
+ gtk_style_context_add_class (style, "disk-space-display");
+ gtk_style_context_add_class (style, "free");
+
+ free_label = gtk_label_new (free);
+ /* Translators: "free" refers to the capacity of the filesystem */
+ free_type_label = gtk_label_new (_("free"));
+
+ capacity_label = gtk_label_new (_("Total capacity:"));
+ capacity_value_label = gtk_label_new (capacity);
+
+ fstype_label = gtk_label_new (_("Filesystem type:"));
+ fstype_value_label = gtk_label_new (NULL);
+
+ spacer_label = gtk_label_new ("");
+
+ location = g_file_new_for_uri (uri);
+ info = g_file_query_filesystem_info (location, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
+ NULL, NULL);
+ if (info)
+ {
+ fs_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
+ if (fs_type != NULL)
+ {
+ gtk_label_set_text (GTK_LABEL (fstype_value_label), fs_type);
+ }
+
+ g_object_unref (info);
+ }
+ g_object_unref (location);
+
+ g_free (uri);
+ g_free (capacity);
+ g_free (used);
+ g_free (free);
+
+ gtk_container_add_with_properties (GTK_CONTAINER (grid), pie_canvas,
+ "height", 5,
+ NULL);
+
+ gtk_widget_set_vexpand (spacer_label, TRUE);
+ gtk_grid_attach_next_to (grid, spacer_label, pie_canvas,
+ GTK_POS_RIGHT, 1, 1);
+
+ gtk_widget_set_halign (used_canvas, GTK_ALIGN_END);
+ gtk_widget_set_vexpand (used_canvas, FALSE);
+ gtk_grid_attach_next_to (grid, used_canvas, spacer_label,
+ GTK_POS_BOTTOM, 1, 1);
+ gtk_widget_set_halign (used_label, GTK_ALIGN_END);
+ gtk_widget_set_vexpand (used_label, FALSE);
+ gtk_grid_attach_next_to (grid, used_label, used_canvas,
+ GTK_POS_RIGHT, 1, 1);
+ gtk_widget_set_halign (used_type_label, GTK_ALIGN_START);
+ gtk_widget_set_vexpand (used_type_label, FALSE);
+ gtk_grid_attach_next_to (grid, used_type_label, used_label,
+ GTK_POS_RIGHT, 1, 1);
+
+ gtk_widget_set_halign (free_canvas, GTK_ALIGN_END);
+ gtk_widget_set_vexpand (free_canvas, FALSE);
+ gtk_grid_attach_next_to (grid, free_canvas, used_canvas,
+ GTK_POS_BOTTOM, 1, 1);
+ gtk_widget_set_halign (free_label, GTK_ALIGN_END);
+ gtk_widget_set_vexpand (free_label, FALSE);
+ gtk_grid_attach_next_to (grid, free_label, free_canvas,
+ GTK_POS_RIGHT, 1, 1);
+ gtk_widget_set_halign (free_type_label, GTK_ALIGN_START);
+ gtk_widget_set_vexpand (free_type_label, FALSE);
+ gtk_grid_attach_next_to (grid, free_type_label, free_label,
+ GTK_POS_RIGHT, 1, 1);
+
+ gtk_widget_set_halign (capacity_label, GTK_ALIGN_END);
+ gtk_widget_set_vexpand (capacity_label, FALSE);
+ gtk_grid_attach_next_to (grid, capacity_label, free_canvas,
+ GTK_POS_BOTTOM, 1, 1);
+ gtk_widget_set_halign (capacity_value_label, GTK_ALIGN_START);
+ gtk_widget_set_vexpand (capacity_value_label, FALSE);
+ gtk_grid_attach_next_to (grid, capacity_value_label, capacity_label,
+ GTK_POS_RIGHT, 1, 1);
+
+ gtk_widget_set_halign (fstype_label, GTK_ALIGN_END);
+ gtk_widget_set_vexpand (fstype_label, FALSE);
+ gtk_grid_attach_next_to (grid, fstype_label, capacity_label,
+ GTK_POS_BOTTOM, 1, 1);
+ gtk_widget_set_halign (fstype_value_label, GTK_ALIGN_START);
+ gtk_widget_set_vexpand (fstype_value_label, FALSE);
+ gtk_grid_attach_next_to (grid, fstype_value_label, fstype_label,
+ GTK_POS_RIGHT, 1, 1);
+
+ g_signal_connect (pie_canvas, "draw",
+ G_CALLBACK (paint_pie_chart), window);
+ g_signal_connect (used_canvas, "draw",
+ G_CALLBACK (paint_legend), window);
+ g_signal_connect (free_canvas, "draw",
+ G_CALLBACK (paint_legend), window);
+
+ return GTK_WIDGET (grid);
+}
+
+static GtkWidget *
create_volume_usage_widget (NautilusPropertiesWindow *window)
{
- GtkWidget *piewidget = NULL;
- gchar *uri;
- NautilusFile *file;
- GFile *location;
- GFileInfo *info;
+ GtkWidget *piewidget = NULL;
+ gchar *uri;
+ NautilusFile *file;
+ GFile *location;
+ GFileInfo *info;
- file = get_original_file (window);
+ file = get_original_file (window);
- uri = nautilus_file_get_activation_uri (file);
+ uri = nautilus_file_get_activation_uri (file);
- location = g_file_new_for_uri (uri);
- info = g_file_query_filesystem_info (location, "filesystem::*", NULL, NULL);
+ location = g_file_new_for_uri (uri);
+ info = g_file_query_filesystem_info (location, "filesystem::*", NULL, NULL);
- if (info) {
- window->details->volume_capacity = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
- window->details->volume_free = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED)) {
- window->details->volume_used = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED);
- } else {
- window->details->volume_used = window->details->volume_capacity - window->details->volume_free;
- }
+ if (info)
+ {
+ window->details->volume_capacity = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_SIZE);
+ window->details->volume_free = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED))
+ {
+ window->details->volume_used = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_USED);
+ }
+ else
+ {
+ window->details->volume_used = window->details->volume_capacity - window->details->volume_free;
+ }
- g_object_unref (info);
- } else {
- window->details->volume_capacity = 0;
- window->details->volume_free = 0;
- window->details->volume_used = 0;
- }
+ g_object_unref (info);
+ }
+ else
+ {
+ window->details->volume_capacity = 0;
+ window->details->volume_free = 0;
+ window->details->volume_used = 0;
+ }
- g_object_unref (location);
+ g_object_unref (location);
- if (window->details->volume_capacity > 0) {
- piewidget = create_pie_widget (window);
- gtk_widget_show_all (piewidget);
- }
+ if (window->details->volume_capacity > 0)
+ {
+ piewidget = create_pie_widget (window);
+ gtk_widget_show_all (piewidget);
+ }
- return piewidget;
+ return piewidget;
}
static void
create_basic_page (NautilusPropertiesWindow *window)
{
- GtkGrid *grid;
- GtkWidget *icon_pixmap_widget;
- GtkWidget *volume_usage;
- GtkWidget *hbox, *vbox;
-
- hbox = create_page_with_hbox (window->details->notebook, _("Basic"),
- "help:gnome-help/nautilus-file-properties-basic");
-
- /* Icon pixmap */
-
- icon_pixmap_widget = create_image_widget (
- window, should_show_custom_icon_buttons (window));
- gtk_widget_set_valign (icon_pixmap_widget, GTK_ALIGN_START);
- gtk_widget_show (icon_pixmap_widget);
-
- gtk_box_pack_start (GTK_BOX (hbox), icon_pixmap_widget, FALSE, FALSE, 0);
-
- window->details->icon_chooser = NULL;
-
- /* Grid */
-
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_show (vbox);
- gtk_container_add (GTK_CONTAINER (hbox), vbox);
-
- grid = GTK_GRID (create_grid_with_standard_properties ());
- gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (grid), FALSE, FALSE, 0);
- window->details->basic_grid = grid;
-
- /* Name label. The text will be determined in update_name_field */
- window->details->name_label = attach_title_field (grid, NULL);
-
- /* Name field */
- window->details->name_field = NULL;
- update_name_field (window);
-
- /* Start with name field selected, if it's an entry. */
- if (NAUTILUS_IS_ENTRY (window->details->name_field)) {
- nautilus_entry_select_all (NAUTILUS_ENTRY (window->details->name_field));
- gtk_widget_grab_focus (GTK_WIDGET (window->details->name_field));
- }
-
- if (nautilus_desktop_item_properties_should_show (window->details->target_files)) {
- GtkSizeGroup *label_size_group;
- GtkWidget *box;
-
- label_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- gtk_size_group_add_widget (label_size_group,
- GTK_WIDGET (window->details->name_label));
- box = nautilus_desktop_item_properties_make_box (label_size_group,
- window->details->target_files);
-
- gtk_grid_attach_next_to (window->details->basic_grid, box,
- GTK_WIDGET (window->details->name_label),
- GTK_POS_BOTTOM, 2, 1);
- }
-
- if (should_show_file_type (window)) {
- append_title_and_ellipsizing_value (window, grid,
- _("Type:"),
- "detailed_type",
- INCONSISTENT_STATE_STRING,
- FALSE);
- }
-
- if (should_show_link_target (window)) {
- append_title_and_ellipsizing_value (window, grid,
- _("Link target:"),
- "link_target",
- INCONSISTENT_STATE_STRING,
- FALSE);
- }
-
- if (is_multi_file_window (window) ||
- nautilus_file_is_directory (get_target_file (window))) {
- append_directory_contents_fields (window, grid);
- } else {
- append_title_value_pair (window, grid, _("Size:"),
- "size_detail",
- INCONSISTENT_STATE_STRING,
- FALSE);
- }
-
- append_blank_row (grid);
-
- if (should_show_location_info (window)) {
- append_title_and_ellipsizing_value (window, grid, _("Parent Folder:"),
- "where",
- INCONSISTENT_STATE_STRING,
- location_show_original (window));
- }
-
- if (should_show_volume_info (window)) {
- append_title_and_ellipsizing_value (window, grid,
- _("Volume:"),
- "volume",
- INCONSISTENT_STATE_STRING,
- FALSE);
- }
-
- if (should_show_accessed_date (window)) {
- append_blank_row (grid);
-
- append_title_value_pair (window, grid, _("Accessed:"),
- "date_accessed_full",
- INCONSISTENT_STATE_STRING,
- FALSE);
- append_title_value_pair (window, grid, _("Modified:"),
- "date_modified_full",
- INCONSISTENT_STATE_STRING,
- FALSE);
- }
-
- if (should_show_free_space (window)
- && ! should_show_volume_usage (window)) {
- append_blank_row (grid);
-
- append_title_value_pair (window, grid, _("Free space:"),
- "free_space",
- INCONSISTENT_STATE_STRING,
- FALSE);
- }
-
- if (should_show_volume_usage (window)) {
- volume_usage = create_volume_usage_widget (window);
- if (volume_usage != NULL) {
- gtk_container_add_with_properties (GTK_CONTAINER (grid),
- volume_usage,
- "width", 3,
- NULL);
- }
- }
-}
-
-static gboolean
+ GtkGrid *grid;
+ GtkWidget *icon_pixmap_widget;
+ GtkWidget *volume_usage;
+ GtkWidget *hbox, *vbox;
+
+ hbox = create_page_with_hbox (window->details->notebook, _("Basic"),
+ "help:gnome-help/nautilus-file-properties-basic");
+
+ /* Icon pixmap */
+
+ icon_pixmap_widget = create_image_widget (
+ window, should_show_custom_icon_buttons (window));
+ gtk_widget_set_valign (icon_pixmap_widget, GTK_ALIGN_START);
+ gtk_widget_show (icon_pixmap_widget);
+
+ gtk_box_pack_start (GTK_BOX (hbox), icon_pixmap_widget, FALSE, FALSE, 0);
+
+ window->details->icon_chooser = NULL;
+
+ /* Grid */
+
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_show (vbox);
+ gtk_container_add (GTK_CONTAINER (hbox), vbox);
+
+ grid = GTK_GRID (create_grid_with_standard_properties ());
+ gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (grid), FALSE, FALSE, 0);
+ window->details->basic_grid = grid;
+
+ /* Name label. The text will be determined in update_name_field */
+ window->details->name_label = attach_title_field (grid, NULL);
+
+ /* Name field */
+ window->details->name_field = NULL;
+ update_name_field (window);
+
+ /* Start with name field selected, if it's an entry. */
+ if (NAUTILUS_IS_ENTRY (window->details->name_field))
+ {
+ nautilus_entry_select_all (NAUTILUS_ENTRY (window->details->name_field));
+ gtk_widget_grab_focus (GTK_WIDGET (window->details->name_field));
+ }
+
+ if (nautilus_desktop_item_properties_should_show (window->details->target_files))
+ {
+ GtkSizeGroup *label_size_group;
+ GtkWidget *box;
+
+ label_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ gtk_size_group_add_widget (label_size_group,
+ GTK_WIDGET (window->details->name_label));
+ box = nautilus_desktop_item_properties_make_box (label_size_group,
+ window->details->target_files);
+
+ gtk_grid_attach_next_to (window->details->basic_grid, box,
+ GTK_WIDGET (window->details->name_label),
+ GTK_POS_BOTTOM, 2, 1);
+ }
+
+ if (should_show_file_type (window))
+ {
+ append_title_and_ellipsizing_value (window, grid,
+ _("Type:"),
+ "detailed_type",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ }
+
+ if (should_show_link_target (window))
+ {
+ append_title_and_ellipsizing_value (window, grid,
+ _("Link target:"),
+ "link_target",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ }
+
+ if (is_multi_file_window (window) ||
+ nautilus_file_is_directory (get_target_file (window)))
+ {
+ append_directory_contents_fields (window, grid);
+ }
+ else
+ {
+ append_title_value_pair (window, grid, _("Size:"),
+ "size_detail",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ }
+
+ append_blank_row (grid);
+
+ if (should_show_location_info (window))
+ {
+ append_title_and_ellipsizing_value (window, grid, _("Parent Folder:"),
+ "where",
+ INCONSISTENT_STATE_STRING,
+ location_show_original (window));
+ }
+
+ if (should_show_volume_info (window))
+ {
+ append_title_and_ellipsizing_value (window, grid,
+ _("Volume:"),
+ "volume",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ }
+
+ if (should_show_accessed_date (window))
+ {
+ append_blank_row (grid);
+
+ append_title_value_pair (window, grid, _("Accessed:"),
+ "date_accessed_full",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ append_title_value_pair (window, grid, _("Modified:"),
+ "date_modified_full",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ }
+
+ if (should_show_free_space (window)
+ && !should_show_volume_usage (window))
+ {
+ append_blank_row (grid);
+
+ append_title_value_pair (window, grid, _("Free space:"),
+ "free_space",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ }
+
+ if (should_show_volume_usage (window))
+ {
+ volume_usage = create_volume_usage_widget (window);
+ if (volume_usage != NULL)
+ {
+ gtk_container_add_with_properties (GTK_CONTAINER (grid),
+ volume_usage,
+ "width", 3,
+ NULL);
+ }
+ }
+}
+
+static gboolean
files_has_directory (NautilusPropertiesWindow *window)
{
- GList *l;
+ GList *l;
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- file = NAUTILUS_FILE (l->data);
- if (nautilus_file_is_directory (file)) {
- return TRUE;
- }
-
- }
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ file = NAUTILUS_FILE (l->data);
+ if (nautilus_file_is_directory (file))
+ {
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
files_has_changable_permissions_directory (NautilusPropertiesWindow *window)
{
- GList *l;
- gboolean changable = FALSE;
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- file = NAUTILUS_FILE (l->data);
- if (nautilus_file_is_directory (file) &&
- nautilus_file_can_get_permissions (file) &&
- nautilus_file_can_set_permissions (file)) {
- changable = TRUE;
- } else {
- changable = FALSE;
- break;
- }
- }
-
- return changable;
+ GList *l;
+ gboolean changable = FALSE;
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ file = NAUTILUS_FILE (l->data);
+ if (nautilus_file_is_directory (file) &&
+ nautilus_file_can_get_permissions (file) &&
+ nautilus_file_can_set_permissions (file))
+ {
+ changable = TRUE;
+ }
+ else
+ {
+ changable = FALSE;
+ break;
+ }
+ }
+
+ return changable;
}
static gboolean
files_has_file (NautilusPropertiesWindow *window)
{
- GList *l;
+ GList *l;
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- file = NAUTILUS_FILE (l->data);
- if (!nautilus_file_is_directory (file)) {
- return TRUE;
- }
- }
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ file = NAUTILUS_FILE (l->data);
+ if (!nautilus_file_is_directory (file))
+ {
+ return TRUE;
+ }
+ }
- return FALSE;
+ return FALSE;
}
static void
start_long_operation (NautilusPropertiesWindow *window)
{
- if (window->details->long_operation_underway == 0) {
- /* start long operation */
- GdkDisplay *display;
- GdkCursor * cursor;
+ if (window->details->long_operation_underway == 0)
+ {
+ /* start long operation */
+ GdkDisplay *display;
+ GdkCursor *cursor;
- display = gtk_widget_get_display (GTK_WIDGET (window));
- cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), cursor);
- g_object_unref (cursor);
- }
- window->details->long_operation_underway ++;
+ display = gtk_widget_get_display (GTK_WIDGET (window));
+ cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), cursor);
+ g_object_unref (cursor);
+ }
+ window->details->long_operation_underway++;
}
static void
end_long_operation (NautilusPropertiesWindow *window)
{
- if (gtk_widget_get_window (GTK_WIDGET (window)) != NULL &&
- window->details->long_operation_underway == 1) {
- /* finished !! */
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
- }
- window->details->long_operation_underway--;
+ if (gtk_widget_get_window (GTK_WIDGET (window)) != NULL &&
+ window->details->long_operation_underway == 1)
+ {
+ /* finished !! */
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
+ }
+ window->details->long_operation_underway--;
}
static void
permission_change_callback (NautilusFile *file,
- GFile *res_loc,
- GError *error,
- gpointer callback_data)
+ GFile *res_loc,
+ GError *error,
+ gpointer callback_data)
{
- NautilusPropertiesWindow *window;
- g_assert (callback_data != NULL);
+ NautilusPropertiesWindow *window;
+ g_assert (callback_data != NULL);
+
+ window = NAUTILUS_PROPERTIES_WINDOW (callback_data);
+ end_long_operation (window);
- window = NAUTILUS_PROPERTIES_WINDOW (callback_data);
- end_long_operation (window);
-
- /* Report the error if it's an error. */
- nautilus_report_error_setting_permissions (file, error, NULL);
+ /* Report the error if it's an error. */
+ nautilus_report_error_setting_permissions (file, error, NULL);
- g_object_unref (window);
+ g_object_unref (window);
}
static void
update_permissions (NautilusPropertiesWindow *window,
- guint32 vfs_new_perm,
- guint32 vfs_mask,
- gboolean is_folder,
- gboolean apply_to_both_folder_and_dir,
- gboolean use_original)
-{
- GList *l;
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- guint32 permissions;
-
- file = NAUTILUS_FILE (l->data);
-
- if (!nautilus_file_can_get_permissions (file)) {
- continue;
- }
-
- if (!apply_to_both_folder_and_dir &&
- ((nautilus_file_is_directory (file) && !is_folder) ||
- (!nautilus_file_is_directory (file) && is_folder))) {
- continue;
- }
-
- permissions = nautilus_file_get_permissions (file);
- if (use_original) {
- gpointer ptr;
- if (g_hash_table_lookup_extended (window->details->initial_permissions,
- file, NULL, &ptr)) {
- permissions = (permissions & ~vfs_mask) | (GPOINTER_TO_INT (ptr) & vfs_mask);
- }
- } else {
- permissions = (permissions & ~vfs_mask) | vfs_new_perm;
- }
-
- start_long_operation (window);
- g_object_ref (window);
- nautilus_file_set_permissions
- (file, permissions,
- permission_change_callback,
- window);
- }
+ guint32 vfs_new_perm,
+ guint32 vfs_mask,
+ gboolean is_folder,
+ gboolean apply_to_both_folder_and_dir,
+ gboolean use_original)
+{
+ GList *l;
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ guint32 permissions;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (!nautilus_file_can_get_permissions (file))
+ {
+ continue;
+ }
+
+ if (!apply_to_both_folder_and_dir &&
+ ((nautilus_file_is_directory (file) && !is_folder) ||
+ (!nautilus_file_is_directory (file) && is_folder)))
+ {
+ continue;
+ }
+
+ permissions = nautilus_file_get_permissions (file);
+ if (use_original)
+ {
+ gpointer ptr;
+ if (g_hash_table_lookup_extended (window->details->initial_permissions,
+ file, NULL, &ptr))
+ {
+ permissions = (permissions & ~vfs_mask) | (GPOINTER_TO_INT (ptr) & vfs_mask);
+ }
+ }
+ else
+ {
+ permissions = (permissions & ~vfs_mask) | vfs_new_perm;
+ }
+
+ start_long_operation (window);
+ g_object_ref (window);
+ nautilus_file_set_permissions
+ (file, permissions,
+ permission_change_callback,
+ window);
+ }
}
static gboolean
initial_permission_state_consistent (NautilusPropertiesWindow *window,
- guint32 mask,
- gboolean is_folder,
- gboolean both_folder_and_dir)
-{
- GList *l;
- gboolean first;
- guint32 first_permissions;
-
- first = TRUE;
- first_permissions = 0;
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- guint32 permissions;
-
- file = l->data;
-
- if (!both_folder_and_dir &&
- ((nautilus_file_is_directory (file) && !is_folder) ||
- (!nautilus_file_is_directory (file) && is_folder))) {
- continue;
- }
-
- permissions = GPOINTER_TO_INT (g_hash_table_lookup (window->details->initial_permissions,
- file));
-
- if (first) {
- if ((permissions & mask) != mask &&
- (permissions & mask) != 0) {
- /* Not fully on or off -> inconsistent */
- return FALSE;
- }
-
- first_permissions = permissions;
- first = FALSE;
-
- } else if ((permissions & mask) != first_permissions) {
- /* Not same permissions as first -> inconsistent */
- return FALSE;
- }
- }
- return TRUE;
+ guint32 mask,
+ gboolean is_folder,
+ gboolean both_folder_and_dir)
+{
+ GList *l;
+ gboolean first;
+ guint32 first_permissions;
+
+ first = TRUE;
+ first_permissions = 0;
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ guint32 permissions;
+
+ file = l->data;
+
+ if (!both_folder_and_dir &&
+ ((nautilus_file_is_directory (file) && !is_folder) ||
+ (!nautilus_file_is_directory (file) && is_folder)))
+ {
+ continue;
+ }
+
+ permissions = GPOINTER_TO_INT (g_hash_table_lookup (window->details->initial_permissions,
+ file));
+
+ if (first)
+ {
+ if ((permissions & mask) != mask &&
+ (permissions & mask) != 0)
+ {
+ /* Not fully on or off -> inconsistent */
+ return FALSE;
+ }
+
+ first_permissions = permissions;
+ first = FALSE;
+ }
+ else if ((permissions & mask) != first_permissions)
+ {
+ /* Not same permissions as first -> inconsistent */
+ return FALSE;
+ }
+ }
+ return TRUE;
}
static void
-permission_button_toggled (GtkToggleButton *button,
- NautilusPropertiesWindow *window)
-{
- gboolean is_folder, is_special;
- guint32 permission_mask;
- gboolean inconsistent;
- gboolean on;
-
- permission_mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
- "permission"));
- is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
- "is-folder"));
- is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
- "is-special"));
-
- if (gtk_toggle_button_get_active (button)
- && !gtk_toggle_button_get_inconsistent (button)) {
- /* Go to the initial state unless the initial state was
- consistent, or we support recursive apply */
- inconsistent = TRUE;
- on = TRUE;
-
- if (initial_permission_state_consistent (window, permission_mask, is_folder, is_special)) {
- inconsistent = FALSE;
- on = TRUE;
- }
- } else if (gtk_toggle_button_get_inconsistent (button)
- && !gtk_toggle_button_get_active (button)) {
- inconsistent = FALSE;
- on = TRUE;
- } else {
- inconsistent = FALSE;
- on = FALSE;
- }
-
- g_signal_handlers_block_by_func (G_OBJECT (button),
- G_CALLBACK (permission_button_toggled),
- window);
-
- gtk_toggle_button_set_active (button, on);
- gtk_toggle_button_set_inconsistent (button, inconsistent);
-
- g_signal_handlers_unblock_by_func (G_OBJECT (button),
- G_CALLBACK (permission_button_toggled),
- window);
-
- update_permissions (window,
- on?permission_mask:0,
- permission_mask,
- is_folder,
- is_special,
- inconsistent);
+permission_button_toggled (GtkToggleButton *button,
+ NautilusPropertiesWindow *window)
+{
+ gboolean is_folder, is_special;
+ guint32 permission_mask;
+ gboolean inconsistent;
+ gboolean on;
+
+ permission_mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+ "permission"));
+ is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+ "is-folder"));
+ is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+ "is-special"));
+
+ if (gtk_toggle_button_get_active (button)
+ && !gtk_toggle_button_get_inconsistent (button))
+ {
+ /* Go to the initial state unless the initial state was
+ * consistent, or we support recursive apply */
+ inconsistent = TRUE;
+ on = TRUE;
+
+ if (initial_permission_state_consistent (window, permission_mask, is_folder, is_special))
+ {
+ inconsistent = FALSE;
+ on = TRUE;
+ }
+ }
+ else if (gtk_toggle_button_get_inconsistent (button)
+ && !gtk_toggle_button_get_active (button))
+ {
+ inconsistent = FALSE;
+ on = TRUE;
+ }
+ else
+ {
+ inconsistent = FALSE;
+ on = FALSE;
+ }
+
+ g_signal_handlers_block_by_func (G_OBJECT (button),
+ G_CALLBACK (permission_button_toggled),
+ window);
+
+ gtk_toggle_button_set_active (button, on);
+ gtk_toggle_button_set_inconsistent (button, inconsistent);
+
+ g_signal_handlers_unblock_by_func (G_OBJECT (button),
+ G_CALLBACK (permission_button_toggled),
+ window);
+
+ update_permissions (window,
+ on ? permission_mask : 0,
+ permission_mask,
+ is_folder,
+ is_special,
+ inconsistent);
}
static void
permission_button_update (NautilusPropertiesWindow *window,
- GtkToggleButton *button)
-{
- GList *l;
- gboolean all_set;
- gboolean all_unset;
- gboolean all_cannot_set;
- gboolean is_folder, is_special;
- gboolean no_match;
- gboolean sensitive;
- guint32 button_permission;
-
- button_permission = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
- "permission"));
- is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
- "is-folder"));
- is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
- "is-special"));
-
- all_set = TRUE;
- all_unset = TRUE;
- all_cannot_set = TRUE;
- no_match = TRUE;
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- guint32 file_permissions;
-
- file = NAUTILUS_FILE (l->data);
-
- if (!nautilus_file_can_get_permissions (file)) {
- continue;
- }
-
- if (!is_special &&
- ((nautilus_file_is_directory (file) && !is_folder) ||
- (!nautilus_file_is_directory (file) && is_folder))) {
- continue;
- }
-
- no_match = FALSE;
-
- file_permissions = nautilus_file_get_permissions (file);
-
- if ((file_permissions & button_permission) == button_permission) {
- all_unset = FALSE;
- } else if ((file_permissions & button_permission) == 0) {
- all_set = FALSE;
- } else {
- all_unset = FALSE;
- all_set = FALSE;
- }
-
- if (nautilus_file_can_set_permissions (file)) {
- all_cannot_set = FALSE;
- }
- }
-
- sensitive = !all_cannot_set;
-
- g_signal_handlers_block_by_func (G_OBJECT (button),
- G_CALLBACK (permission_button_toggled),
- window);
-
- gtk_toggle_button_set_active (button, !all_unset);
- /* if actually inconsistent, or default value for file buttons
- if no files are selected. (useful for recursive apply) */
- gtk_toggle_button_set_inconsistent (button,
- (!all_unset && !all_set) ||
- (!is_folder && no_match));
- gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive);
-
- g_signal_handlers_unblock_by_func (G_OBJECT (button),
- G_CALLBACK (permission_button_toggled),
- window);
+ GtkToggleButton *button)
+{
+ GList *l;
+ gboolean all_set;
+ gboolean all_unset;
+ gboolean all_cannot_set;
+ gboolean is_folder, is_special;
+ gboolean no_match;
+ gboolean sensitive;
+ guint32 button_permission;
+
+ button_permission = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+ "permission"));
+ is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+ "is-folder"));
+ is_special = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
+ "is-special"));
+
+ all_set = TRUE;
+ all_unset = TRUE;
+ all_cannot_set = TRUE;
+ no_match = TRUE;
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ guint32 file_permissions;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (!nautilus_file_can_get_permissions (file))
+ {
+ continue;
+ }
+
+ if (!is_special &&
+ ((nautilus_file_is_directory (file) && !is_folder) ||
+ (!nautilus_file_is_directory (file) && is_folder)))
+ {
+ continue;
+ }
+
+ no_match = FALSE;
+
+ file_permissions = nautilus_file_get_permissions (file);
+
+ if ((file_permissions & button_permission) == button_permission)
+ {
+ all_unset = FALSE;
+ }
+ else if ((file_permissions & button_permission) == 0)
+ {
+ all_set = FALSE;
+ }
+ else
+ {
+ all_unset = FALSE;
+ all_set = FALSE;
+ }
+
+ if (nautilus_file_can_set_permissions (file))
+ {
+ all_cannot_set = FALSE;
+ }
+ }
+
+ sensitive = !all_cannot_set;
+
+ g_signal_handlers_block_by_func (G_OBJECT (button),
+ G_CALLBACK (permission_button_toggled),
+ window);
+
+ gtk_toggle_button_set_active (button, !all_unset);
+ /* if actually inconsistent, or default value for file buttons
+ * if no files are selected. (useful for recursive apply) */
+ gtk_toggle_button_set_inconsistent (button,
+ (!all_unset && !all_set) ||
+ (!is_folder && no_match));
+ gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive);
+
+ g_signal_handlers_unblock_by_func (G_OBJECT (button),
+ G_CALLBACK (permission_button_toggled),
+ window);
}
static void
set_up_permissions_checkbox (NautilusPropertiesWindow *window,
- GtkWidget *check_button,
- guint32 permission,
- gboolean is_folder)
-{
- /* Load up the check_button with data we'll need when updating its state. */
- g_object_set_data (G_OBJECT (check_button), "permission",
- GINT_TO_POINTER (permission));
- g_object_set_data (G_OBJECT (check_button), "properties_window",
- window);
- g_object_set_data (G_OBJECT (check_button), "is-folder",
- GINT_TO_POINTER (is_folder));
-
- window->details->permission_buttons =
- g_list_prepend (window->details->permission_buttons,
- check_button);
-
- g_signal_connect_object (check_button, "toggled",
- G_CALLBACK (permission_button_toggled),
- window,
- 0);
+ GtkWidget *check_button,
+ guint32 permission,
+ gboolean is_folder)
+{
+ /* Load up the check_button with data we'll need when updating its state. */
+ g_object_set_data (G_OBJECT (check_button), "permission",
+ GINT_TO_POINTER (permission));
+ g_object_set_data (G_OBJECT (check_button), "properties_window",
+ window);
+ g_object_set_data (G_OBJECT (check_button), "is-folder",
+ GINT_TO_POINTER (is_folder));
+
+ window->details->permission_buttons =
+ g_list_prepend (window->details->permission_buttons,
+ check_button);
+
+ g_signal_connect_object (check_button, "toggled",
+ G_CALLBACK (permission_button_toggled),
+ window,
+ 0);
}
static GtkWidget *
add_execute_checkbox_with_label (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- GtkWidget *sibling,
- const char *label,
- guint32 permission_to_check,
- GtkLabel *label_for,
- gboolean is_folder)
-{
- GtkWidget *check_button;
- gboolean a11y_enabled;
-
- check_button = gtk_check_button_new_with_mnemonic (label);
- gtk_widget_show (check_button);
-
- if (sibling) {
- gtk_grid_attach_next_to (grid, check_button, sibling,
- GTK_POS_RIGHT, 1, 1);
- } else {
- gtk_container_add (GTK_CONTAINER (grid), check_button);
- }
-
- set_up_permissions_checkbox (window,
- check_button,
- permission_to_check,
- is_folder);
-
- a11y_enabled = GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (check_button));
- if (a11y_enabled && label_for != NULL) {
- eel_accessibility_set_up_label_widget_relation (GTK_WIDGET (label_for),
- check_button);
- }
-
- return check_button;
-}
-
-enum {
- UNIX_PERM_SUID = S_ISUID,
- UNIX_PERM_SGID = S_ISGID,
- UNIX_PERM_STICKY = 01000, /* S_ISVTX not defined on all systems */
- UNIX_PERM_USER_READ = S_IRUSR,
- UNIX_PERM_USER_WRITE = S_IWUSR,
- UNIX_PERM_USER_EXEC = S_IXUSR,
- UNIX_PERM_USER_ALL = S_IRUSR | S_IWUSR | S_IXUSR,
- UNIX_PERM_GROUP_READ = S_IRGRP,
- UNIX_PERM_GROUP_WRITE = S_IWGRP,
- UNIX_PERM_GROUP_EXEC = S_IXGRP,
- UNIX_PERM_GROUP_ALL = S_IRGRP | S_IWGRP | S_IXGRP,
- UNIX_PERM_OTHER_READ = S_IROTH,
- UNIX_PERM_OTHER_WRITE = S_IWOTH,
- UNIX_PERM_OTHER_EXEC = S_IXOTH,
- UNIX_PERM_OTHER_ALL = S_IROTH | S_IWOTH | S_IXOTH
+ GtkGrid *grid,
+ GtkWidget *sibling,
+ const char *label,
+ guint32 permission_to_check,
+ GtkLabel *label_for,
+ gboolean is_folder)
+{
+ GtkWidget *check_button;
+ gboolean a11y_enabled;
+
+ check_button = gtk_check_button_new_with_mnemonic (label);
+ gtk_widget_show (check_button);
+
+ if (sibling)
+ {
+ gtk_grid_attach_next_to (grid, check_button, sibling,
+ GTK_POS_RIGHT, 1, 1);
+ }
+ else
+ {
+ gtk_container_add (GTK_CONTAINER (grid), check_button);
+ }
+
+ set_up_permissions_checkbox (window,
+ check_button,
+ permission_to_check,
+ is_folder);
+
+ a11y_enabled = GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (check_button));
+ if (a11y_enabled && label_for != NULL)
+ {
+ eel_accessibility_set_up_label_widget_relation (GTK_WIDGET (label_for),
+ check_button);
+ }
+
+ return check_button;
+}
+
+enum
+{
+ UNIX_PERM_SUID = S_ISUID,
+ UNIX_PERM_SGID = S_ISGID,
+ UNIX_PERM_STICKY = 01000, /* S_ISVTX not defined on all systems */
+ UNIX_PERM_USER_READ = S_IRUSR,
+ UNIX_PERM_USER_WRITE = S_IWUSR,
+ UNIX_PERM_USER_EXEC = S_IXUSR,
+ UNIX_PERM_USER_ALL = S_IRUSR | S_IWUSR | S_IXUSR,
+ UNIX_PERM_GROUP_READ = S_IRGRP,
+ UNIX_PERM_GROUP_WRITE = S_IWGRP,
+ UNIX_PERM_GROUP_EXEC = S_IXGRP,
+ UNIX_PERM_GROUP_ALL = S_IRGRP | S_IWGRP | S_IXGRP,
+ UNIX_PERM_OTHER_READ = S_IROTH,
+ UNIX_PERM_OTHER_WRITE = S_IWOTH,
+ UNIX_PERM_OTHER_EXEC = S_IXOTH,
+ UNIX_PERM_OTHER_ALL = S_IROTH | S_IWOTH | S_IXOTH
};
-typedef enum {
- PERMISSION_READ = (1<<0),
- PERMISSION_WRITE = (1<<1),
- PERMISSION_EXEC = (1<<2)
+typedef enum
+{
+ PERMISSION_READ = (1 << 0),
+ PERMISSION_WRITE = (1 << 1),
+ PERMISSION_EXEC = (1 << 2)
} PermissionValue;
-typedef enum {
- PERMISSION_USER,
- PERMISSION_GROUP,
- PERMISSION_OTHER
+typedef enum
+{
+ PERMISSION_USER,
+ PERMISSION_GROUP,
+ PERMISSION_OTHER
} PermissionType;
-static guint32 vfs_perms[3][3] = {
- {UNIX_PERM_USER_READ, UNIX_PERM_USER_WRITE, UNIX_PERM_USER_EXEC},
- {UNIX_PERM_GROUP_READ, UNIX_PERM_GROUP_WRITE, UNIX_PERM_GROUP_EXEC},
- {UNIX_PERM_OTHER_READ, UNIX_PERM_OTHER_WRITE, UNIX_PERM_OTHER_EXEC},
+static guint32 vfs_perms[3][3] =
+{
+ {UNIX_PERM_USER_READ, UNIX_PERM_USER_WRITE, UNIX_PERM_USER_EXEC},
+ {UNIX_PERM_GROUP_READ, UNIX_PERM_GROUP_WRITE, UNIX_PERM_GROUP_EXEC},
+ {UNIX_PERM_OTHER_READ, UNIX_PERM_OTHER_WRITE, UNIX_PERM_OTHER_EXEC},
};
-static guint32
-permission_to_vfs (PermissionType type, PermissionValue perm)
+static guint32
+permission_to_vfs (PermissionType type,
+ PermissionValue perm)
{
- guint32 vfs_perm;
- g_assert (type >= 0 && type < 3);
+ guint32 vfs_perm;
+ g_assert (type >= 0 && type < 3);
- vfs_perm = 0;
- if (perm & PERMISSION_READ) {
- vfs_perm |= vfs_perms[type][0];
- }
- if (perm & PERMISSION_WRITE) {
- vfs_perm |= vfs_perms[type][1];
- }
- if (perm & PERMISSION_EXEC) {
- vfs_perm |= vfs_perms[type][2];
- }
-
- return vfs_perm;
+ vfs_perm = 0;
+ if (perm & PERMISSION_READ)
+ {
+ vfs_perm |= vfs_perms[type][0];
+ }
+ if (perm & PERMISSION_WRITE)
+ {
+ vfs_perm |= vfs_perms[type][1];
+ }
+ if (perm & PERMISSION_EXEC)
+ {
+ vfs_perm |= vfs_perms[type][2];
+ }
+
+ return vfs_perm;
}
static PermissionValue
-permission_from_vfs (PermissionType type, guint32 vfs_perm)
+permission_from_vfs (PermissionType type,
+ guint32 vfs_perm)
{
- PermissionValue perm;
- g_assert (type >= 0 && type < 3);
+ PermissionValue perm;
+ g_assert (type >= 0 && type < 3);
+
+ perm = 0;
+ if (vfs_perm & vfs_perms[type][0])
+ {
+ perm |= PERMISSION_READ;
+ }
+ if (vfs_perm & vfs_perms[type][1])
+ {
+ perm |= PERMISSION_WRITE;
+ }
+ if (vfs_perm & vfs_perms[type][2])
+ {
+ perm |= PERMISSION_EXEC;
+ }
- perm = 0;
- if (vfs_perm & vfs_perms[type][0]) {
- perm |= PERMISSION_READ;
- }
- if (vfs_perm & vfs_perms[type][1]) {
- perm |= PERMISSION_WRITE;
- }
- if (vfs_perm & vfs_perms[type][2]) {
- perm |= PERMISSION_EXEC;
- }
-
- return perm;
+ return perm;
}
static void
-permission_combo_changed (GtkWidget *combo, NautilusPropertiesWindow *window)
-{
- GtkTreeIter iter;
- GtkTreeModel *model;
- gboolean is_folder, use_original;
- PermissionType type;
- int new_perm, mask;
- guint32 vfs_new_perm, vfs_mask;
-
- is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
- type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
-
- if (is_folder) {
- mask = PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC;
- } else {
- mask = PERMISSION_READ|PERMISSION_WRITE;
- }
-
- vfs_mask = permission_to_vfs (type, mask);
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
-
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
- return;
- }
- gtk_tree_model_get (model, &iter, COLUMN_VALUE, &new_perm,
- COLUMN_USE_ORIGINAL, &use_original, -1);
- vfs_new_perm = permission_to_vfs (type, new_perm);
-
- update_permissions (window, vfs_new_perm, vfs_mask,
- is_folder, FALSE, use_original);
+permission_combo_changed (GtkWidget *combo,
+ NautilusPropertiesWindow *window)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gboolean is_folder, use_original;
+ PermissionType type;
+ int new_perm, mask;
+ guint32 vfs_new_perm, vfs_mask;
+
+ is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
+ type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
+
+ if (is_folder)
+ {
+ mask = PERMISSION_READ | PERMISSION_WRITE | PERMISSION_EXEC;
+ }
+ else
+ {
+ mask = PERMISSION_READ | PERMISSION_WRITE;
+ }
+
+ vfs_mask = permission_to_vfs (type, mask);
+
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
+ {
+ return;
+ }
+ gtk_tree_model_get (model, &iter, COLUMN_VALUE, &new_perm,
+ COLUMN_USE_ORIGINAL, &use_original, -1);
+ vfs_new_perm = permission_to_vfs (type, new_perm);
+
+ update_permissions (window, vfs_new_perm, vfs_mask,
+ is_folder, FALSE, use_original);
}
static void
-permission_combo_add_multiple_choice (GtkComboBox *combo, GtkTreeIter *iter)
-{
- GtkTreeModel *model;
- GtkListStore *store;
- gboolean found;
-
- model = gtk_combo_box_get_model (combo);
- store = GTK_LIST_STORE (model);
-
- found = FALSE;
- gtk_tree_model_get_iter_first (model, iter);
- do {
- gboolean multi;
- gtk_tree_model_get (model, iter, COLUMN_USE_ORIGINAL, &multi, -1);
-
- if (multi) {
- found = TRUE;
- break;
- }
- } while (gtk_tree_model_iter_next (model, iter));
-
- if (!found) {
- gtk_list_store_append (store, iter);
- gtk_list_store_set (store, iter,
- COLUMN_NAME, "---",
- COLUMN_VALUE, 0,
- COLUMN_USE_ORIGINAL, TRUE, -1);
- }
+permission_combo_add_multiple_choice (GtkComboBox *combo,
+ GtkTreeIter *iter)
+{
+ GtkTreeModel *model;
+ GtkListStore *store;
+ gboolean found;
+
+ model = gtk_combo_box_get_model (combo);
+ store = GTK_LIST_STORE (model);
+
+ found = FALSE;
+ gtk_tree_model_get_iter_first (model, iter);
+ do
+ {
+ gboolean multi;
+ gtk_tree_model_get (model, iter, COLUMN_USE_ORIGINAL, &multi, -1);
+
+ if (multi)
+ {
+ found = TRUE;
+ break;
+ }
+ }
+ while (gtk_tree_model_iter_next (model, iter));
+
+ if (!found)
+ {
+ gtk_list_store_append (store, iter);
+ gtk_list_store_set (store, iter,
+ COLUMN_NAME, "---",
+ COLUMN_VALUE, 0,
+ COLUMN_USE_ORIGINAL, TRUE, -1);
+ }
}
static void
permission_combo_update (NautilusPropertiesWindow *window,
- GtkComboBox *combo)
-{
- PermissionType type;
- PermissionValue perm, all_dir_perm, all_file_perm, all_perm;
- gboolean is_folder, no_files, no_dirs, all_file_same, all_dir_same, all_same;
- gboolean all_dir_cannot_set, all_file_cannot_set, sensitive;
- GtkTreeIter iter;
- int mask;
- GtkTreeModel *model;
- GtkListStore *store;
- GList *l;
- gboolean is_multi;
-
- model = gtk_combo_box_get_model (combo);
-
- is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
- type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
-
- is_multi = FALSE;
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
- gtk_tree_model_get (model, &iter, COLUMN_USE_ORIGINAL, &is_multi, -1);
- }
-
- no_files = TRUE;
- no_dirs = TRUE;
- all_dir_same = TRUE;
- all_file_same = TRUE;
- all_dir_perm = 0;
- all_file_perm = 0;
- all_dir_cannot_set = TRUE;
- all_file_cannot_set = TRUE;
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- guint32 file_permissions;
-
- file = NAUTILUS_FILE (l->data);
-
- if (!nautilus_file_can_get_permissions (file)) {
- continue;
- }
-
- if (nautilus_file_is_directory (file)) {
- mask = PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC;
- } else {
- mask = PERMISSION_READ|PERMISSION_WRITE;
- }
-
- file_permissions = nautilus_file_get_permissions (file);
-
- perm = permission_from_vfs (type, file_permissions) & mask;
-
- if (nautilus_file_is_directory (file)) {
- if (no_dirs) {
- all_dir_perm = perm;
- no_dirs = FALSE;
- } else if (perm != all_dir_perm) {
- all_dir_same = FALSE;
- }
-
- if (nautilus_file_can_set_permissions (file)) {
- all_dir_cannot_set = FALSE;
- }
- } else {
- if (no_files) {
- all_file_perm = perm;
- no_files = FALSE;
- } else if (perm != all_file_perm) {
- all_file_same = FALSE;
- }
-
- if (nautilus_file_can_set_permissions (file)) {
- all_file_cannot_set = FALSE;
- }
- }
- }
-
- if (is_folder) {
- all_same = all_dir_same;
- all_perm = all_dir_perm;
- } else {
- all_same = all_file_same && !no_files;
- all_perm = all_file_perm;
- }
-
- store = GTK_LIST_STORE (model);
- if (all_same) {
- gboolean found;
-
- found = FALSE;
- gtk_tree_model_get_iter_first (model, &iter);
- do {
- int current_perm;
- gtk_tree_model_get (model, &iter, 1, &current_perm, -1);
-
- if (current_perm == all_perm) {
- found = TRUE;
- break;
- }
- } while (gtk_tree_model_iter_next (model, &iter));
-
- if (!found) {
- GString *str;
- str = g_string_new ("");
-
- if (!(all_perm & PERMISSION_READ)) {
- /* translators: this gets concatenated to "no read",
- * "no access", etc. (see following strings)
- */
- g_string_append (str, _("no "));
- }
- if (is_folder) {
- g_string_append (str, _("list"));
- } else {
- g_string_append (str, _("read"));
- }
-
- g_string_append (str, ", ");
-
- if (!(all_perm & PERMISSION_WRITE)) {
- g_string_append (str, _("no "));
- }
- if (is_folder) {
- g_string_append (str, _("create/delete"));
- } else {
- g_string_append (str, _("write"));
- }
-
- if (is_folder) {
- g_string_append (str, ", ");
-
- if (!(all_perm & PERMISSION_EXEC)) {
- g_string_append (str, _("no "));
- }
- g_string_append (str, _("access"));
- }
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, str->str,
- 1, all_perm, -1);
-
- g_string_free (str, TRUE);
- }
- } else {
- permission_combo_add_multiple_choice (combo, &iter);
- }
-
- g_signal_handlers_block_by_func (G_OBJECT (combo),
- G_CALLBACK (permission_combo_changed),
- window);
-
- gtk_combo_box_set_active_iter (combo, &iter);
-
- /* Also enable if no files found (for recursive
- file changes when only selecting folders) */
- if (is_folder) {
- sensitive = !all_dir_cannot_set;
- } else {
- sensitive = !all_file_cannot_set;
- }
- gtk_widget_set_sensitive (GTK_WIDGET (combo), sensitive);
-
- g_signal_handlers_unblock_by_func (G_OBJECT (combo),
- G_CALLBACK (permission_combo_changed),
- window);
-
+ GtkComboBox *combo)
+{
+ PermissionType type;
+ PermissionValue perm, all_dir_perm, all_file_perm, all_perm;
+ gboolean is_folder, no_files, no_dirs, all_file_same, all_dir_same, all_same;
+ gboolean all_dir_cannot_set, all_file_cannot_set, sensitive;
+ GtkTreeIter iter;
+ int mask;
+ GtkTreeModel *model;
+ GtkListStore *store;
+ GList *l;
+ gboolean is_multi;
+
+ model = gtk_combo_box_get_model (combo);
+
+ is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
+ type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
+
+ is_multi = FALSE;
+ if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
+ {
+ gtk_tree_model_get (model, &iter, COLUMN_USE_ORIGINAL, &is_multi, -1);
+ }
+
+ no_files = TRUE;
+ no_dirs = TRUE;
+ all_dir_same = TRUE;
+ all_file_same = TRUE;
+ all_dir_perm = 0;
+ all_file_perm = 0;
+ all_dir_cannot_set = TRUE;
+ all_file_cannot_set = TRUE;
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ guint32 file_permissions;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (!nautilus_file_can_get_permissions (file))
+ {
+ continue;
+ }
+
+ if (nautilus_file_is_directory (file))
+ {
+ mask = PERMISSION_READ | PERMISSION_WRITE | PERMISSION_EXEC;
+ }
+ else
+ {
+ mask = PERMISSION_READ | PERMISSION_WRITE;
+ }
+
+ file_permissions = nautilus_file_get_permissions (file);
+
+ perm = permission_from_vfs (type, file_permissions) & mask;
+
+ if (nautilus_file_is_directory (file))
+ {
+ if (no_dirs)
+ {
+ all_dir_perm = perm;
+ no_dirs = FALSE;
+ }
+ else if (perm != all_dir_perm)
+ {
+ all_dir_same = FALSE;
+ }
+
+ if (nautilus_file_can_set_permissions (file))
+ {
+ all_dir_cannot_set = FALSE;
+ }
+ }
+ else
+ {
+ if (no_files)
+ {
+ all_file_perm = perm;
+ no_files = FALSE;
+ }
+ else if (perm != all_file_perm)
+ {
+ all_file_same = FALSE;
+ }
+
+ if (nautilus_file_can_set_permissions (file))
+ {
+ all_file_cannot_set = FALSE;
+ }
+ }
+ }
+
+ if (is_folder)
+ {
+ all_same = all_dir_same;
+ all_perm = all_dir_perm;
+ }
+ else
+ {
+ all_same = all_file_same && !no_files;
+ all_perm = all_file_perm;
+ }
+
+ store = GTK_LIST_STORE (model);
+ if (all_same)
+ {
+ gboolean found;
+
+ found = FALSE;
+ gtk_tree_model_get_iter_first (model, &iter);
+ do
+ {
+ int current_perm;
+ gtk_tree_model_get (model, &iter, 1, &current_perm, -1);
+
+ if (current_perm == all_perm)
+ {
+ found = TRUE;
+ break;
+ }
+ }
+ while (gtk_tree_model_iter_next (model, &iter));
+
+ if (!found)
+ {
+ GString *str;
+ str = g_string_new ("");
+
+ if (!(all_perm & PERMISSION_READ))
+ {
+ /* translators: this gets concatenated to "no read",
+ * "no access", etc. (see following strings)
+ */
+ g_string_append (str, _("no "));
+ }
+ if (is_folder)
+ {
+ g_string_append (str, _("list"));
+ }
+ else
+ {
+ g_string_append (str, _("read"));
+ }
+
+ g_string_append (str, ", ");
+
+ if (!(all_perm & PERMISSION_WRITE))
+ {
+ g_string_append (str, _("no "));
+ }
+ if (is_folder)
+ {
+ g_string_append (str, _("create/delete"));
+ }
+ else
+ {
+ g_string_append (str, _("write"));
+ }
+
+ if (is_folder)
+ {
+ g_string_append (str, ", ");
+
+ if (!(all_perm & PERMISSION_EXEC))
+ {
+ g_string_append (str, _("no "));
+ }
+ g_string_append (str, _("access"));
+ }
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, str->str,
+ 1, all_perm, -1);
+
+ g_string_free (str, TRUE);
+ }
+ }
+ else
+ {
+ permission_combo_add_multiple_choice (combo, &iter);
+ }
+
+ g_signal_handlers_block_by_func (G_OBJECT (combo),
+ G_CALLBACK (permission_combo_changed),
+ window);
+
+ gtk_combo_box_set_active_iter (combo, &iter);
+
+ /* Also enable if no files found (for recursive
+ * file changes when only selecting folders) */
+ if (is_folder)
+ {
+ sensitive = !all_dir_cannot_set;
+ }
+ else
+ {
+ sensitive = !all_file_cannot_set;
+ }
+ gtk_widget_set_sensitive (GTK_WIDGET (combo), sensitive);
+
+ g_signal_handlers_unblock_by_func (G_OBJECT (combo),
+ G_CALLBACK (permission_combo_changed),
+ window);
}
static GtkWidget *
create_permissions_combo_box (PermissionType type,
- gboolean is_folder)
-{
- GtkWidget *combo;
- GtkListStore *store;
- GtkCellRenderer *cell;
- GtkTreeIter iter;
-
- store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_STRING);
- combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
- gtk_combo_box_set_id_column (GTK_COMBO_BOX (combo), COLUMN_ID);
-
- g_object_set_data (G_OBJECT (combo), "is-folder", GINT_TO_POINTER (is_folder));
- g_object_set_data (G_OBJECT (combo), "permission-type", GINT_TO_POINTER (type));
-
- if (is_folder) {
- if (type != PERMISSION_USER) {
- gtk_list_store_append (store, &iter);
- /* Translators: this is referred to the permissions
- * the user has in a directory.
- */
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("None"),
- COLUMN_VALUE, 0,
- COLUMN_ID, "none",
- -1);
- }
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("List files only"),
- COLUMN_VALUE, PERMISSION_READ,
- COLUMN_ID, "r",
- -1);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("Access files"),
- COLUMN_VALUE, PERMISSION_READ|PERMISSION_EXEC,
- COLUMN_ID, "rx",
- -1);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("Create and delete files"),
- COLUMN_VALUE, PERMISSION_READ|PERMISSION_EXEC|PERMISSION_WRITE,
- COLUMN_ID, "rwx",
- -1);
- } else {
- if (type != PERMISSION_USER) {
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("None"),
- COLUMN_VALUE, 0,
- COLUMN_ID, "none",
- -1);
- }
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("Read-only"),
- COLUMN_VALUE, PERMISSION_READ,
- COLUMN_ID, "r",
- -1);
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_NAME, _("Read and write"),
- COLUMN_VALUE, PERMISSION_READ|PERMISSION_WRITE,
- COLUMN_ID, "rw",
- -1);
- }
- g_object_unref (store);
-
- cell = gtk_cell_renderer_text_new ();
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
- "text", COLUMN_NAME,
- NULL);
-
- return combo;
+ gboolean is_folder)
+{
+ GtkWidget *combo;
+ GtkListStore *store;
+ GtkCellRenderer *cell;
+ GtkTreeIter iter;
+
+ store = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_STRING);
+ combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
+ gtk_combo_box_set_id_column (GTK_COMBO_BOX (combo), COLUMN_ID);
+
+ g_object_set_data (G_OBJECT (combo), "is-folder", GINT_TO_POINTER (is_folder));
+ g_object_set_data (G_OBJECT (combo), "permission-type", GINT_TO_POINTER (type));
+
+ if (is_folder)
+ {
+ if (type != PERMISSION_USER)
+ {
+ gtk_list_store_append (store, &iter);
+ /* Translators: this is referred to the permissions
+ * the user has in a directory.
+ */
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("None"),
+ COLUMN_VALUE, 0,
+ COLUMN_ID, "none",
+ -1);
+ }
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("List files only"),
+ COLUMN_VALUE, PERMISSION_READ,
+ COLUMN_ID, "r",
+ -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("Access files"),
+ COLUMN_VALUE, PERMISSION_READ | PERMISSION_EXEC,
+ COLUMN_ID, "rx",
+ -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("Create and delete files"),
+ COLUMN_VALUE, PERMISSION_READ | PERMISSION_EXEC | PERMISSION_WRITE,
+ COLUMN_ID, "rwx",
+ -1);
+ }
+ else
+ {
+ if (type != PERMISSION_USER)
+ {
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("None"),
+ COLUMN_VALUE, 0,
+ COLUMN_ID, "none",
+ -1);
+ }
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("Read-only"),
+ COLUMN_VALUE, PERMISSION_READ,
+ COLUMN_ID, "r",
+ -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ COLUMN_NAME, _("Read and write"),
+ COLUMN_VALUE, PERMISSION_READ | PERMISSION_WRITE,
+ COLUMN_ID, "rw",
+ -1);
+ }
+ g_object_unref (store);
+
+ cell = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
+ "text", COLUMN_NAME,
+ NULL);
+
+ return combo;
}
static void
add_permissions_combo_box (NautilusPropertiesWindow *window,
- GtkGrid *grid,
- PermissionType type,
- gboolean is_folder,
- gboolean short_label)
+ GtkGrid *grid,
+ PermissionType type,
+ gboolean is_folder,
+ gboolean short_label)
{
- GtkWidget *combo;
- GtkLabel *label;
+ GtkWidget *combo;
+ GtkLabel *label;
- if (short_label) {
- label = attach_title_field (grid, _("Access:"));
- } else if (is_folder) {
- label = attach_title_field (grid, _("Folder access:"));
- } else {
- label = attach_title_field (grid, _("File access:"));
- }
+ if (short_label)
+ {
+ label = attach_title_field (grid, _("Access:"));
+ }
+ else if (is_folder)
+ {
+ label = attach_title_field (grid, _("Folder access:"));
+ }
+ else
+ {
+ label = attach_title_field (grid, _("File access:"));
+ }
- combo = create_permissions_combo_box (type, is_folder);
+ combo = create_permissions_combo_box (type, is_folder);
- window->details->permission_combos = g_list_prepend (window->details->permission_combos,
- combo);
+ window->details->permission_combos = g_list_prepend (window->details->permission_combos,
+ combo);
- g_signal_connect (combo, "changed", G_CALLBACK (permission_combo_changed), window);
+ g_signal_connect (combo, "changed", G_CALLBACK (permission_combo_changed), window);
- gtk_label_set_mnemonic_widget (label, combo);
- gtk_widget_show (combo);
+ gtk_label_set_mnemonic_widget (label, combo);
+ gtk_widget_show (combo);
- gtk_grid_attach_next_to (grid, combo, GTK_WIDGET (label),
- GTK_POS_RIGHT, 1, 1);
+ gtk_grid_attach_next_to (grid, combo, GTK_WIDGET (label),
+ GTK_POS_RIGHT, 1, 1);
}
static gboolean
all_can_get_permissions (GList *file_list)
{
- GList *l;
- for (l = file_list; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
-
- if (!nautilus_file_can_get_permissions (file)) {
- return FALSE;
- }
- }
+ GList *l;
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (!nautilus_file_can_get_permissions (file))
+ {
+ return FALSE;
+ }
+ }
- return TRUE;
+ return TRUE;
}
static gboolean
all_can_set_permissions (GList *file_list)
{
- GList *l;
- for (l = file_list; l != NULL; l = l->next) {
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
+ GList *l;
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
- if (!nautilus_file_can_set_permissions (file)) {
- return FALSE;
- }
- }
+ file = NAUTILUS_FILE (l->data);
- return TRUE;
+ if (!nautilus_file_can_set_permissions (file))
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
}
static GHashTable *
get_initial_permissions (GList *file_list)
{
- GHashTable *ret;
- GList *l;
+ GHashTable *ret;
+ GList *l;
+
+ ret = g_hash_table_new (g_direct_hash,
+ g_direct_equal);
+
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ guint32 permissions;
+ NautilusFile *file;
- ret = g_hash_table_new (g_direct_hash,
- g_direct_equal);
-
- for (l = file_list; l != NULL; l = l->next) {
- guint32 permissions;
- NautilusFile *file;
-
- file = NAUTILUS_FILE (l->data);
-
- permissions = nautilus_file_get_permissions (file);
- g_hash_table_insert (ret, file,
- GINT_TO_POINTER (permissions));
- }
+ file = NAUTILUS_FILE (l->data);
- return ret;
+ permissions = nautilus_file_get_permissions (file);
+ g_hash_table_insert (ret, file,
+ GINT_TO_POINTER (permissions));
+ }
+
+ return ret;
}
static void
-create_simple_permissions (NautilusPropertiesWindow *window, GtkGrid *page_grid)
-{
- gboolean has_directory;
- gboolean has_file;
- GtkLabel *group_label;
- GtkLabel *owner_label;
- GtkWidget *value;
- GtkComboBox *group_combo_box;
- GtkComboBox *owner_combo_box;
-
- has_directory = files_has_directory (window);
- has_file = files_has_file (window);
-
- if (!is_multi_file_window (window) && nautilus_file_can_set_owner (get_target_file (window))) {
- owner_label = attach_title_field (page_grid, _("_Owner:"));
- /* Combo box in this case. */
- owner_combo_box = attach_owner_combo_box (page_grid,
- GTK_WIDGET (owner_label),
- get_target_file (window));
- gtk_label_set_mnemonic_widget (owner_label,
- GTK_WIDGET (owner_combo_box));
- } else {
- owner_label = attach_title_field (page_grid, _("Owner:"));
- /* Static text in this case. */
- value = attach_value_field (window,
- page_grid, GTK_WIDGET (owner_label),
- "owner",
- INCONSISTENT_STATE_STRING,
- FALSE);
- gtk_label_set_mnemonic_widget (owner_label, value);
- }
- if (has_directory && has_file) {
- add_permissions_combo_box (window, page_grid,
- PERMISSION_USER, TRUE, FALSE);
- add_permissions_combo_box (window, page_grid,
- PERMISSION_USER, FALSE, FALSE);
- } else {
- add_permissions_combo_box (window, page_grid,
- PERMISSION_USER, has_directory, TRUE);
- }
-
- append_blank_slim_row (page_grid);
-
- if (!is_multi_file_window (window) && nautilus_file_can_set_group (get_target_file (window))) {
- group_label = attach_title_field (page_grid, _("_Group:"));
-
- /* Combo box in this case. */
- group_combo_box = attach_group_combo_box (page_grid, GTK_WIDGET (group_label),
- get_target_file (window));
- gtk_label_set_mnemonic_widget (group_label,
- GTK_WIDGET (group_combo_box));
- } else {
- group_label = attach_title_field (page_grid, _("Group:"));
-
- /* Static text in this case. */
- value = attach_value_field (window, page_grid,
- GTK_WIDGET (group_label),
- "group",
- INCONSISTENT_STATE_STRING,
- FALSE);
- gtk_label_set_mnemonic_widget (group_label, value);
- }
- if (has_directory && has_file) {
- add_permissions_combo_box (window, page_grid,
- PERMISSION_GROUP, TRUE, FALSE);
- add_permissions_combo_box (window, page_grid,
- PERMISSION_GROUP, FALSE, FALSE);
- } else {
- add_permissions_combo_box (window, page_grid,
- PERMISSION_GROUP, has_directory, TRUE);
- }
-
- append_blank_slim_row (page_grid);
- attach_title_field (page_grid, _("Others"));
- if (has_directory && has_file) {
- add_permissions_combo_box (window, page_grid,
- PERMISSION_OTHER, TRUE, FALSE);
- add_permissions_combo_box (window, page_grid,
- PERMISSION_OTHER, FALSE, FALSE);
- } else {
- add_permissions_combo_box (window, page_grid,
- PERMISSION_OTHER, has_directory, TRUE);
- }
-
- if (!has_directory) {
- GtkLabel *execute_label;
- append_blank_slim_row (page_grid);
-
- execute_label = attach_title_field (page_grid, _("Execute:"));
- add_execute_checkbox_with_label (window, page_grid,
- GTK_WIDGET (execute_label),
- _("Allow _executing file as program"),
- UNIX_PERM_USER_EXEC|UNIX_PERM_GROUP_EXEC|UNIX_PERM_OTHER_EXEC,
- execute_label, FALSE);
- }
+create_simple_permissions (NautilusPropertiesWindow *window,
+ GtkGrid *page_grid)
+{
+ gboolean has_directory;
+ gboolean has_file;
+ GtkLabel *group_label;
+ GtkLabel *owner_label;
+ GtkWidget *value;
+ GtkComboBox *group_combo_box;
+ GtkComboBox *owner_combo_box;
+
+ has_directory = files_has_directory (window);
+ has_file = files_has_file (window);
+
+ if (!is_multi_file_window (window) && nautilus_file_can_set_owner (get_target_file (window)))
+ {
+ owner_label = attach_title_field (page_grid, _("_Owner:"));
+ /* Combo box in this case. */
+ owner_combo_box = attach_owner_combo_box (page_grid,
+ GTK_WIDGET (owner_label),
+ get_target_file (window));
+ gtk_label_set_mnemonic_widget (owner_label,
+ GTK_WIDGET (owner_combo_box));
+ }
+ else
+ {
+ owner_label = attach_title_field (page_grid, _("Owner:"));
+ /* Static text in this case. */
+ value = attach_value_field (window,
+ page_grid, GTK_WIDGET (owner_label),
+ "owner",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ gtk_label_set_mnemonic_widget (owner_label, value);
+ }
+ if (has_directory && has_file)
+ {
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_USER, TRUE, FALSE);
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_USER, FALSE, FALSE);
+ }
+ else
+ {
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_USER, has_directory, TRUE);
+ }
+
+ append_blank_slim_row (page_grid);
+
+ if (!is_multi_file_window (window) && nautilus_file_can_set_group (get_target_file (window)))
+ {
+ group_label = attach_title_field (page_grid, _("_Group:"));
+
+ /* Combo box in this case. */
+ group_combo_box = attach_group_combo_box (page_grid, GTK_WIDGET (group_label),
+ get_target_file (window));
+ gtk_label_set_mnemonic_widget (group_label,
+ GTK_WIDGET (group_combo_box));
+ }
+ else
+ {
+ group_label = attach_title_field (page_grid, _("Group:"));
+
+ /* Static text in this case. */
+ value = attach_value_field (window, page_grid,
+ GTK_WIDGET (group_label),
+ "group",
+ INCONSISTENT_STATE_STRING,
+ FALSE);
+ gtk_label_set_mnemonic_widget (group_label, value);
+ }
+ if (has_directory && has_file)
+ {
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_GROUP, TRUE, FALSE);
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_GROUP, FALSE, FALSE);
+ }
+ else
+ {
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_GROUP, has_directory, TRUE);
+ }
+
+ append_blank_slim_row (page_grid);
+ attach_title_field (page_grid, _("Others"));
+ if (has_directory && has_file)
+ {
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_OTHER, TRUE, FALSE);
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_OTHER, FALSE, FALSE);
+ }
+ else
+ {
+ add_permissions_combo_box (window, page_grid,
+ PERMISSION_OTHER, has_directory, TRUE);
+ }
+
+ if (!has_directory)
+ {
+ GtkLabel *execute_label;
+ append_blank_slim_row (page_grid);
+
+ execute_label = attach_title_field (page_grid, _("Execute:"));
+ add_execute_checkbox_with_label (window, page_grid,
+ GTK_WIDGET (execute_label),
+ _("Allow _executing file as program"),
+ UNIX_PERM_USER_EXEC | UNIX_PERM_GROUP_EXEC | UNIX_PERM_OTHER_EXEC,
+ execute_label, FALSE);
+ }
}
static void
set_recursive_permissions_done (gboolean success,
- gpointer callback_data)
+ gpointer callback_data)
{
- NautilusPropertiesWindow *window;
+ NautilusPropertiesWindow *window;
- window = NAUTILUS_PROPERTIES_WINDOW (callback_data);
- end_long_operation (window);
+ window = NAUTILUS_PROPERTIES_WINDOW (callback_data);
+ end_long_operation (window);
- g_object_unref (window);
+ g_object_unref (window);
}
static void
on_change_permissions_response (GtkDialog *dialog,
- int response,
- NautilusPropertiesWindow *window)
-{
- if (response != GTK_RESPONSE_OK) {
- gtk_widget_destroy (GTK_WIDGET (dialog));
- return;
- }
- guint32 file_permission, file_permission_mask;
- guint32 dir_permission, dir_permission_mask;
- guint32 vfs_mask, vfs_new_perm;
- GtkWidget *combo;
- gboolean is_folder, use_original;
- GList *l;
- GtkTreeModel *model;
- GtkTreeIter iter;
- PermissionType type;
- int new_perm, mask;
-
- file_permission = 0;
- file_permission_mask = 0;
- dir_permission = 0;
- dir_permission_mask = 0;
-
- /* Simple mode, minus exec checkbox */
- for (l = window->details->change_permission_combos; l != NULL; l = l->next) {
- combo = l->data;
-
- if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) {
- continue;
- }
-
- type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
- is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
- gtk_tree_model_get (model, &iter,
- COLUMN_VALUE, &new_perm,
- COLUMN_USE_ORIGINAL, &use_original, -1);
- if (use_original) {
- continue;
- }
- vfs_new_perm = permission_to_vfs (type, new_perm);
-
- if (is_folder) {
- mask = PERMISSION_READ|PERMISSION_WRITE|PERMISSION_EXEC;
- } else {
- mask = PERMISSION_READ|PERMISSION_WRITE;
- }
- vfs_mask = permission_to_vfs (type, mask);
-
- if (is_folder) {
- dir_permission_mask |= vfs_mask;
- dir_permission |= vfs_new_perm;
- } else {
- file_permission_mask |= vfs_mask;
- file_permission |= vfs_new_perm;
- }
- }
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- char *uri;
-
- file = NAUTILUS_FILE (l->data);
-
- if (nautilus_file_is_directory (file) &&
- nautilus_file_can_set_permissions (file)) {
- uri = nautilus_file_get_uri (file);
- start_long_operation (window);
- g_object_ref (window);
- nautilus_file_set_permissions_recursive (uri,
- file_permission,
- file_permission_mask,
- dir_permission,
- dir_permission_mask,
- set_recursive_permissions_done,
- window);
- g_free (uri);
- }
- }
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ int response,
+ NautilusPropertiesWindow *window)
+{
+ if (response != GTK_RESPONSE_OK)
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ return;
+ }
+ guint32 file_permission, file_permission_mask;
+ guint32 dir_permission, dir_permission_mask;
+ guint32 vfs_mask, vfs_new_perm;
+ GtkWidget *combo;
+ gboolean is_folder, use_original;
+ GList *l;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ PermissionType type;
+ int new_perm, mask;
+
+ file_permission = 0;
+ file_permission_mask = 0;
+ dir_permission = 0;
+ dir_permission_mask = 0;
+
+ /* Simple mode, minus exec checkbox */
+ for (l = window->details->change_permission_combos; l != NULL; l = l->next)
+ {
+ combo = l->data;
+
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter))
+ {
+ continue;
+ }
+
+ type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "permission-type"));
+ is_folder = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "is-folder"));
+
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
+ gtk_tree_model_get (model, &iter,
+ COLUMN_VALUE, &new_perm,
+ COLUMN_USE_ORIGINAL, &use_original, -1);
+ if (use_original)
+ {
+ continue;
+ }
+ vfs_new_perm = permission_to_vfs (type, new_perm);
+
+ if (is_folder)
+ {
+ mask = PERMISSION_READ | PERMISSION_WRITE | PERMISSION_EXEC;
+ }
+ else
+ {
+ mask = PERMISSION_READ | PERMISSION_WRITE;
+ }
+ vfs_mask = permission_to_vfs (type, mask);
+
+ if (is_folder)
+ {
+ dir_permission_mask |= vfs_mask;
+ dir_permission |= vfs_new_perm;
+ }
+ else
+ {
+ file_permission_mask |= vfs_mask;
+ file_permission |= vfs_new_perm;
+ }
+ }
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ char *uri;
+
+ file = NAUTILUS_FILE (l->data);
+
+ if (nautilus_file_is_directory (file) &&
+ nautilus_file_can_set_permissions (file))
+ {
+ uri = nautilus_file_get_uri (file);
+ start_long_operation (window);
+ g_object_ref (window);
+ nautilus_file_set_permissions_recursive (uri,
+ file_permission,
+ file_permission_mask,
+ dir_permission,
+ dir_permission_mask,
+ set_recursive_permissions_done,
+ window);
+ g_free (uri);
+ }
+ }
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
-set_active_from_umask (GtkWidget *combo,
- PermissionType type,
- gboolean is_folder)
-{
- mode_t initial;
- mode_t mask;
- mode_t p;
- const char *id;
-
- if (is_folder) {
- initial = (S_IRWXU | S_IRWXG | S_IRWXO);
- } else {
- initial = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
- }
-
- umask (mask = umask (0));
-
- p = ~mask & initial;
-
- if (type == PERMISSION_USER) {
- p &= ~(S_IRWXG | S_IRWXO);
- if ((p & S_IRWXU) == S_IRWXU) {
- id = "rwx";
- } else if ((p & (S_IRUSR | S_IWUSR)) == (S_IRUSR | S_IWUSR)) {
- id = "rw";
- } else if ((p & (S_IRUSR | S_IXUSR)) == (S_IRUSR | S_IXUSR)) {
- id = "rx";
- } else if ((p & S_IRUSR) == S_IRUSR) {
- id = "r";
- } else {
- id = "none";
- }
- } else if (type == PERMISSION_GROUP) {
- p &= ~(S_IRWXU | S_IRWXO);
- if ((p & S_IRWXG) == S_IRWXG) {
- id = "rwx";
- } else if ((p & (S_IRGRP | S_IWGRP)) == (S_IRGRP | S_IWGRP)) {
- id = "rw";
- } else if ((p & (S_IRGRP | S_IXGRP)) == (S_IRGRP | S_IXGRP)) {
- id = "rx";
- } else if ((p & S_IRGRP) == S_IRGRP) {
- id = "r";
- } else {
- id = "none";
- }
- } else {
- p &= ~(S_IRWXU | S_IRWXG);
- if ((p & S_IRWXO) == S_IRWXO) {
- id = "rwx";
- } else if ((p & (S_IROTH | S_IWOTH)) == (S_IROTH | S_IWOTH)) {
- id = "rw";
- } else if ((p & (S_IROTH | S_IXOTH)) == (S_IROTH | S_IXOTH)) {
- id = "rx";
- } else if ((p & S_IROTH) == S_IROTH) {
- id = "r";
- } else {
- id = "none";
- }
- }
-
- gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo), id);
+set_active_from_umask (GtkWidget *combo,
+ PermissionType type,
+ gboolean is_folder)
+{
+ mode_t initial;
+ mode_t mask;
+ mode_t p;
+ const char *id;
+
+ if (is_folder)
+ {
+ initial = (S_IRWXU | S_IRWXG | S_IRWXO);
+ }
+ else
+ {
+ initial = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+ }
+
+ umask (mask = umask (0));
+
+ p = ~mask & initial;
+
+ if (type == PERMISSION_USER)
+ {
+ p &= ~(S_IRWXG | S_IRWXO);
+ if ((p & S_IRWXU) == S_IRWXU)
+ {
+ id = "rwx";
+ }
+ else if ((p & (S_IRUSR | S_IWUSR)) == (S_IRUSR | S_IWUSR))
+ {
+ id = "rw";
+ }
+ else if ((p & (S_IRUSR | S_IXUSR)) == (S_IRUSR | S_IXUSR))
+ {
+ id = "rx";
+ }
+ else if ((p & S_IRUSR) == S_IRUSR)
+ {
+ id = "r";
+ }
+ else
+ {
+ id = "none";
+ }
+ }
+ else if (type == PERMISSION_GROUP)
+ {
+ p &= ~(S_IRWXU | S_IRWXO);
+ if ((p & S_IRWXG) == S_IRWXG)
+ {
+ id = "rwx";
+ }
+ else if ((p & (S_IRGRP | S_IWGRP)) == (S_IRGRP | S_IWGRP))
+ {
+ id = "rw";
+ }
+ else if ((p & (S_IRGRP | S_IXGRP)) == (S_IRGRP | S_IXGRP))
+ {
+ id = "rx";
+ }
+ else if ((p & S_IRGRP) == S_IRGRP)
+ {
+ id = "r";
+ }
+ else
+ {
+ id = "none";
+ }
+ }
+ else
+ {
+ p &= ~(S_IRWXU | S_IRWXG);
+ if ((p & S_IRWXO) == S_IRWXO)
+ {
+ id = "rwx";
+ }
+ else if ((p & (S_IROTH | S_IWOTH)) == (S_IROTH | S_IWOTH))
+ {
+ id = "rw";
+ }
+ else if ((p & (S_IROTH | S_IXOTH)) == (S_IROTH | S_IXOTH))
+ {
+ id = "rx";
+ }
+ else if ((p & S_IROTH) == S_IROTH)
+ {
+ id = "r";
+ }
+ else
+ {
+ id = "none";
+ }
+ }
+
+ gtk_combo_box_set_active_id (GTK_COMBO_BOX (combo), id);
}
static void
on_change_permissions_clicked (GtkWidget *button,
- NautilusPropertiesWindow *window)
-{
- GtkWidget *dialog;
- GtkWidget *label;
- GtkWidget *combo;
- GtkGrid *grid;
-
- dialog = gtk_dialog_new_with_buttons (_("Change Permissions for Enclosed Files"),
- GTK_WINDOW (window),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("Change"), GTK_RESPONSE_OK,
- NULL);
-
- grid = GTK_GRID (create_grid_with_standard_properties ());
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
- GTK_WIDGET (grid),
- TRUE, TRUE, 0);
-
- label = gtk_label_new (_("Files"));
- gtk_grid_attach (grid, label, 1, 0, 1, 1);
- label = gtk_label_new (_("Folders"));
- gtk_grid_attach (grid, label, 2, 0, 1, 1);
-
- label = gtk_label_new (_("Owner:"));
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_grid_attach (grid, label, 0, 1, 1, 1);
- combo = create_permissions_combo_box (PERMISSION_USER, FALSE);
- window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
- combo);
- set_active_from_umask (combo, PERMISSION_USER, FALSE);
- gtk_grid_attach (grid, combo, 1, 1, 1, 1);
- combo = create_permissions_combo_box (PERMISSION_USER, TRUE);
- window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
- combo);
- set_active_from_umask (combo, PERMISSION_USER, TRUE);
- gtk_grid_attach (grid, combo, 2, 1, 1, 1);
-
- label = gtk_label_new (_("Group:"));
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_grid_attach (grid, label, 0, 2, 1, 1);
- combo = create_permissions_combo_box (PERMISSION_GROUP, FALSE);
- window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
- combo);
- set_active_from_umask (combo, PERMISSION_GROUP, FALSE);
- gtk_grid_attach (grid, combo, 1, 2, 1, 1);
- combo = create_permissions_combo_box (PERMISSION_GROUP, TRUE);
- window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
- combo);
- set_active_from_umask (combo, PERMISSION_GROUP, TRUE);
- gtk_grid_attach (grid, combo, 2, 2, 1, 1);
-
- label = gtk_label_new (_("Others:"));
- gtk_label_set_xalign (GTK_LABEL (label), 0);
- gtk_grid_attach (grid, label, 0, 3, 1, 1);
- combo = create_permissions_combo_box (PERMISSION_OTHER, FALSE);
- window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
- combo);
- set_active_from_umask (combo, PERMISSION_OTHER, FALSE);
- gtk_grid_attach (grid, combo, 1, 3, 1, 1);
- combo = create_permissions_combo_box (PERMISSION_OTHER, TRUE);
- window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
- combo);
- set_active_from_umask (combo, PERMISSION_OTHER, TRUE);
- gtk_grid_attach (grid, combo, 2, 3, 1, 1);
-
- g_signal_connect (dialog, "response", G_CALLBACK (on_change_permissions_response), window);
- gtk_widget_show_all (dialog);
+ NautilusPropertiesWindow *window)
+{
+ GtkWidget *dialog;
+ GtkWidget *label;
+ GtkWidget *combo;
+ GtkGrid *grid;
+
+ dialog = gtk_dialog_new_with_buttons (_("Change Permissions for Enclosed Files"),
+ GTK_WINDOW (window),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("Change"), GTK_RESPONSE_OK,
+ NULL);
+
+ grid = GTK_GRID (create_grid_with_standard_properties ());
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+ GTK_WIDGET (grid),
+ TRUE, TRUE, 0);
+
+ label = gtk_label_new (_("Files"));
+ gtk_grid_attach (grid, label, 1, 0, 1, 1);
+ label = gtk_label_new (_("Folders"));
+ gtk_grid_attach (grid, label, 2, 0, 1, 1);
+
+ label = gtk_label_new (_("Owner:"));
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_grid_attach (grid, label, 0, 1, 1, 1);
+ combo = create_permissions_combo_box (PERMISSION_USER, FALSE);
+ window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
+ combo);
+ set_active_from_umask (combo, PERMISSION_USER, FALSE);
+ gtk_grid_attach (grid, combo, 1, 1, 1, 1);
+ combo = create_permissions_combo_box (PERMISSION_USER, TRUE);
+ window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
+ combo);
+ set_active_from_umask (combo, PERMISSION_USER, TRUE);
+ gtk_grid_attach (grid, combo, 2, 1, 1, 1);
+
+ label = gtk_label_new (_("Group:"));
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_grid_attach (grid, label, 0, 2, 1, 1);
+ combo = create_permissions_combo_box (PERMISSION_GROUP, FALSE);
+ window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
+ combo);
+ set_active_from_umask (combo, PERMISSION_GROUP, FALSE);
+ gtk_grid_attach (grid, combo, 1, 2, 1, 1);
+ combo = create_permissions_combo_box (PERMISSION_GROUP, TRUE);
+ window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
+ combo);
+ set_active_from_umask (combo, PERMISSION_GROUP, TRUE);
+ gtk_grid_attach (grid, combo, 2, 2, 1, 1);
+
+ label = gtk_label_new (_("Others:"));
+ gtk_label_set_xalign (GTK_LABEL (label), 0);
+ gtk_grid_attach (grid, label, 0, 3, 1, 1);
+ combo = create_permissions_combo_box (PERMISSION_OTHER, FALSE);
+ window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
+ combo);
+ set_active_from_umask (combo, PERMISSION_OTHER, FALSE);
+ gtk_grid_attach (grid, combo, 1, 3, 1, 1);
+ combo = create_permissions_combo_box (PERMISSION_OTHER, TRUE);
+ window->details->change_permission_combos = g_list_prepend (window->details->change_permission_combos,
+ combo);
+ set_active_from_umask (combo, PERMISSION_OTHER, TRUE);
+ gtk_grid_attach (grid, combo, 2, 3, 1, 1);
+
+ g_signal_connect (dialog, "response", G_CALLBACK (on_change_permissions_response), window);
+ gtk_widget_show_all (dialog);
}
static void
create_permissions_page (NautilusPropertiesWindow *window)
{
- GtkWidget *vbox, *button, *hbox;
- GtkGrid *page_grid;
- char *file_name, *prompt_text;
- GList *file_list;
+ GtkWidget *vbox, *button, *hbox;
+ GtkGrid *page_grid;
+ char *file_name, *prompt_text;
+ GList *file_list;
+
+ vbox = create_page_with_vbox (window->details->notebook,
+ _("Permissions"),
+ "help:gnome-help/nautilus-file-properties-permissions");
- vbox = create_page_with_vbox (window->details->notebook,
- _("Permissions"),
- "help:gnome-help/nautilus-file-properties-permissions");
+ file_list = window->details->original_files;
- file_list = window->details->original_files;
+ window->details->initial_permissions = NULL;
- window->details->initial_permissions = NULL;
-
- if (all_can_get_permissions (file_list) && all_can_get_permissions (window->details->target_files)) {
- window->details->initial_permissions = get_initial_permissions (window->details->target_files);
- window->details->has_recursive_apply = files_has_changable_permissions_directory (window);
-
- if (!all_can_set_permissions (file_list)) {
- add_prompt_and_separator (
- vbox,
- _("You are not the owner, so you cannot change these permissions."));
- }
+ if (all_can_get_permissions (file_list) && all_can_get_permissions (window->details->target_files))
+ {
+ window->details->initial_permissions = get_initial_permissions (window->details->target_files);
+ window->details->has_recursive_apply = files_has_changable_permissions_directory (window);
- page_grid = GTK_GRID (create_grid_with_standard_properties ());
+ if (!all_can_set_permissions (file_list))
+ {
+ add_prompt_and_separator (
+ vbox,
+ _("You are not the owner, so you cannot change these permissions."));
+ }
- gtk_widget_show (GTK_WIDGET (page_grid));
- gtk_box_pack_start (GTK_BOX (vbox),
- GTK_WIDGET (page_grid),
- TRUE, TRUE, 0);
+ page_grid = GTK_GRID (create_grid_with_standard_properties ());
- create_simple_permissions (window, page_grid);
+ gtk_widget_show (GTK_WIDGET (page_grid));
+ gtk_box_pack_start (GTK_BOX (vbox),
+ GTK_WIDGET (page_grid),
+ TRUE, TRUE, 0);
+
+ create_simple_permissions (window, page_grid);
#ifdef HAVE_SELINUX
- append_blank_slim_row (page_grid);
- append_title_value_pair
- (window, page_grid, _("Security context:"),
- "selinux_context", INCONSISTENT_STATE_STRING,
- FALSE);
+ append_blank_slim_row (page_grid);
+ append_title_value_pair
+ (window, page_grid, _("Security context:"),
+ "selinux_context", INCONSISTENT_STATE_STRING,
+ FALSE);
#endif
- append_blank_row (page_grid);
-
- if (window->details->has_recursive_apply) {
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_widget_show (hbox);
-
- gtk_container_add_with_properties (GTK_CONTAINER (page_grid), hbox,
- "width", 2,
- NULL);
-
- button = gtk_button_new_with_mnemonic (_("Change Permissions for Enclosed Files…"));
- gtk_widget_show (button);
- gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
- g_signal_connect (button, "clicked",
- G_CALLBACK (on_change_permissions_clicked),
- window);
- }
- } else {
- if (!is_multi_file_window (window)) {
- file_name = nautilus_file_get_display_name (get_target_file (window));
- prompt_text = g_strdup_printf (_("The permissions of “%s” could not be determined."), file_name);
- g_free (file_name);
- } else {
- prompt_text = g_strdup (_("The permissions of the selected file could not be determined."));
- }
-
- add_prompt (vbox, prompt_text, TRUE);
- g_free (prompt_text);
- }
+ append_blank_row (page_grid);
+
+ if (window->details->has_recursive_apply)
+ {
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_show (hbox);
+
+ gtk_container_add_with_properties (GTK_CONTAINER (page_grid), hbox,
+ "width", 2,
+ NULL);
+
+ button = gtk_button_new_with_mnemonic (_("Change Permissions for Enclosed Files…"));
+ gtk_widget_show (button);
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (on_change_permissions_clicked),
+ window);
+ }
+ }
+ else
+ {
+ if (!is_multi_file_window (window))
+ {
+ file_name = nautilus_file_get_display_name (get_target_file (window));
+ prompt_text = g_strdup_printf (_("The permissions of “%s” could not be determined."), file_name);
+ g_free (file_name);
+ }
+ else
+ {
+ prompt_text = g_strdup (_("The permissions of the selected file could not be determined."));
+ }
+
+ add_prompt (vbox, prompt_text, TRUE);
+ g_free (prompt_text);
+ }
}
static void
append_extension_pages (NautilusPropertiesWindow *window)
{
- GList *providers;
- GList *p;
-
- providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER);
-
- for (p = providers; p != NULL; p = p->next) {
- NautilusPropertyPageProvider *provider;
- GList *pages;
- GList *l;
-
- provider = NAUTILUS_PROPERTY_PAGE_PROVIDER (p->data);
-
- pages = nautilus_property_page_provider_get_pages
- (provider, window->details->original_files);
-
- for (l = pages; l != NULL; l = l->next) {
- NautilusPropertyPage *page;
- GtkWidget *page_widget;
- GtkWidget *label;
-
- page = NAUTILUS_PROPERTY_PAGE (l->data);
-
- g_object_get (G_OBJECT (page),
- "page", &page_widget, "label", &label,
- NULL);
-
- gtk_notebook_append_page (window->details->notebook,
- page_widget, label);
- gtk_container_child_set (GTK_CONTAINER (window->details->notebook),
- page_widget,
- "tab-expand", TRUE,
- NULL);
-
- g_object_set_data (G_OBJECT (page_widget),
- "is-extension-page",
- page);
-
- g_object_unref (page_widget);
- g_object_unref (label);
-
- g_object_unref (page);
- }
-
- g_list_free (pages);
- }
-
- nautilus_module_extension_list_free (providers);
+ GList *providers;
+ GList *p;
+
+ providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER);
+
+ for (p = providers; p != NULL; p = p->next)
+ {
+ NautilusPropertyPageProvider *provider;
+ GList *pages;
+ GList *l;
+
+ provider = NAUTILUS_PROPERTY_PAGE_PROVIDER (p->data);
+
+ pages = nautilus_property_page_provider_get_pages
+ (provider, window->details->original_files);
+
+ for (l = pages; l != NULL; l = l->next)
+ {
+ NautilusPropertyPage *page;
+ GtkWidget *page_widget;
+ GtkWidget *label;
+
+ page = NAUTILUS_PROPERTY_PAGE (l->data);
+
+ g_object_get (G_OBJECT (page),
+ "page", &page_widget, "label", &label,
+ NULL);
+
+ gtk_notebook_append_page (window->details->notebook,
+ page_widget, label);
+ gtk_container_child_set (GTK_CONTAINER (window->details->notebook),
+ page_widget,
+ "tab-expand", TRUE,
+ NULL);
+
+ g_object_set_data (G_OBJECT (page_widget),
+ "is-extension-page",
+ page);
+
+ g_object_unref (page_widget);
+ g_object_unref (label);
+
+ g_object_unref (page);
+ }
+
+ g_list_free (pages);
+ }
+
+ nautilus_module_extension_list_free (providers);
}
static gboolean
-should_show_permissions (NautilusPropertiesWindow *window)
+should_show_permissions (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = get_target_file (window);
+ file = get_target_file (window);
- /* Don't show permissions for Trash and Computer since they're not
- * really file system objects.
- */
- if (!is_multi_file_window (window)
- && (is_merged_trash_directory (file) ||
- is_recent_directory (file) ||
- is_computer_directory (file))) {
- return FALSE;
- }
+ /* Don't show permissions for Trash and Computer since they're not
+ * really file system objects.
+ */
+ if (!is_multi_file_window (window)
+ && (is_merged_trash_directory (file) ||
+ is_recent_directory (file) ||
+ is_computer_directory (file)))
+ {
+ return FALSE;
+ }
- return TRUE;
+ return TRUE;
}
static char *
get_pending_key (GList *file_list)
{
- GList *l;
- GList *uris;
- GString *key;
- char *ret;
-
- uris = NULL;
- for (l = file_list; l != NULL; l = l->next) {
- uris = g_list_prepend (uris, nautilus_file_get_uri (NAUTILUS_FILE (l->data)));
- }
- uris = g_list_sort (uris, (GCompareFunc)strcmp);
+ GList *l;
+ GList *uris;
+ GString *key;
+ char *ret;
+
+ uris = NULL;
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ uris = g_list_prepend (uris, nautilus_file_get_uri (NAUTILUS_FILE (l->data)));
+ }
+ uris = g_list_sort (uris, (GCompareFunc) strcmp);
- key = g_string_new ("");
- for (l = uris; l != NULL; l = l->next) {
- g_string_append (key, l->data);
- g_string_append (key, ";");
- }
+ key = g_string_new ("");
+ for (l = uris; l != NULL; l = l->next)
+ {
+ g_string_append (key, l->data);
+ g_string_append (key, ";");
+ }
- g_list_free_full (uris, g_free);
+ g_list_free_full (uris, g_free);
- ret = key->str;
- g_string_free (key, FALSE);
+ ret = key->str;
+ g_string_free (key, FALSE);
- return ret;
+ return ret;
}
static StartupData *
-startup_data_new (GList *original_files,
- GList *target_files,
- const char *pending_key,
- GtkWidget *parent_widget,
- GtkWindow *parent_window,
- const char *startup_id)
-{
- StartupData *data;
- GList *l;
-
- data = g_new0 (StartupData, 1);
- data->original_files = nautilus_file_list_copy (original_files);
- data->target_files = nautilus_file_list_copy (target_files);
- data->parent_widget = parent_widget;
- data->parent_window = parent_window;
- data->startup_id = g_strdup (startup_id);
- data->pending_key = g_strdup (pending_key);
- data->pending_files = g_hash_table_new (g_direct_hash,
- g_direct_equal);
-
- for (l = data->target_files; l != NULL; l = l->next) {
- g_hash_table_insert (data->pending_files, l->data, l->data);
- }
-
- return data;
+startup_data_new (GList *original_files,
+ GList *target_files,
+ const char *pending_key,
+ GtkWidget *parent_widget,
+ GtkWindow *parent_window,
+ const char *startup_id)
+{
+ StartupData *data;
+ GList *l;
+
+ data = g_new0 (StartupData, 1);
+ data->original_files = nautilus_file_list_copy (original_files);
+ data->target_files = nautilus_file_list_copy (target_files);
+ data->parent_widget = parent_widget;
+ data->parent_window = parent_window;
+ data->startup_id = g_strdup (startup_id);
+ data->pending_key = g_strdup (pending_key);
+ data->pending_files = g_hash_table_new (g_direct_hash,
+ g_direct_equal);
+
+ for (l = data->target_files; l != NULL; l = l->next)
+ {
+ g_hash_table_insert (data->pending_files, l->data, l->data);
+ }
+
+ return data;
}
static void
startup_data_free (StartupData *data)
{
- nautilus_file_list_free (data->original_files);
- nautilus_file_list_free (data->target_files);
- g_hash_table_destroy (data->pending_files);
- g_free (data->pending_key);
- g_free (data->startup_id);
- g_free (data);
+ nautilus_file_list_free (data->original_files);
+ nautilus_file_list_free (data->target_files);
+ g_hash_table_destroy (data->pending_files);
+ g_free (data->pending_key);
+ g_free (data->startup_id);
+ g_free (data);
}
static void
-file_changed_callback (NautilusFile *file, gpointer user_data)
+file_changed_callback (NautilusFile *file,
+ gpointer user_data)
{
- NautilusPropertiesWindow *window = NAUTILUS_PROPERTIES_WINDOW (user_data);
+ NautilusPropertiesWindow *window = NAUTILUS_PROPERTIES_WINDOW (user_data);
- if (!g_list_find (window->details->changed_files, file)) {
- nautilus_file_ref (file);
- window->details->changed_files = g_list_prepend (window->details->changed_files, file);
- schedule_files_update (window);
- }
+ if (!g_list_find (window->details->changed_files, file))
+ {
+ nautilus_file_ref (file);
+ window->details->changed_files = g_list_prepend (window->details->changed_files, file);
+ schedule_files_update (window);
+ }
}
static gboolean
is_a_special_file (NautilusFile *file)
{
- if (file == NULL ||
- nautilus_file_is_nautilus_link (file) ||
- is_merged_trash_directory (file) ||
- is_computer_directory (file)) {
- return TRUE;
- }
- return FALSE;
+ if (file == NULL ||
+ nautilus_file_is_nautilus_link (file) ||
+ is_merged_trash_directory (file) ||
+ is_computer_directory (file))
+ {
+ return TRUE;
+ }
+ return FALSE;
}
static gboolean
should_show_open_with (NautilusPropertiesWindow *window)
{
- NautilusFile *file;
- char *mime_type;
- char *extension;
- gboolean hide;
- g_autoptr (GAppInfo) app_info = NULL;
-
- /* Don't show open with tab for desktop special icons (trash, etc)
- * or desktop files. We don't get the open-with menu for these anyway.
- *
- * Also don't show it for folders. Changing the default app for folders
- * leads to all sort of hard to understand errors.
- */
-
- if (is_multi_file_window (window)) {
- GList *l;
-
- if (!file_list_attributes_identical (window->details->target_files,
- "mime_type")) {
- return FALSE;
- }
-
- for (l = window->details->target_files; l; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- app_info = nautilus_mime_get_default_application_for_file (file);
- if (nautilus_file_is_directory (file) || !app_info || is_a_special_file (file)) {
- return FALSE;
- }
- }
-
- /* since we just confirmed all the mime types are the
- same we only need to test one file */
- file = window->details->target_files->data;
- } else {
- file = get_target_file (window);
-
- app_info = nautilus_mime_get_default_application_for_file (file);
- if (nautilus_file_is_directory (file) || !app_info || is_a_special_file (file)) {
- return FALSE;
- }
- }
-
- mime_type = nautilus_file_get_mime_type (file);
- extension = nautilus_file_get_extension (file);
- hide = (g_content_type_is_unknown (mime_type) && extension == NULL);
- g_free (mime_type);
- g_free (extension);
-
- return !hide;
+ NautilusFile *file;
+ char *mime_type;
+ char *extension;
+ gboolean hide;
+ g_autoptr (GAppInfo) app_info = NULL;
+
+ /* Don't show open with tab for desktop special icons (trash, etc)
+ * or desktop files. We don't get the open-with menu for these anyway.
+ *
+ * Also don't show it for folders. Changing the default app for folders
+ * leads to all sort of hard to understand errors.
+ */
+
+ if (is_multi_file_window (window))
+ {
+ GList *l;
+
+ if (!file_list_attributes_identical (window->details->target_files,
+ "mime_type"))
+ {
+ return FALSE;
+ }
+
+ for (l = window->details->target_files; l; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ app_info = nautilus_mime_get_default_application_for_file (file);
+ if (nautilus_file_is_directory (file) || !app_info || is_a_special_file (file))
+ {
+ return FALSE;
+ }
+ }
+
+ /* since we just confirmed all the mime types are the
+ * same we only need to test one file */
+ file = window->details->target_files->data;
+ }
+ else
+ {
+ file = get_target_file (window);
+
+ app_info = nautilus_mime_get_default_application_for_file (file);
+ if (nautilus_file_is_directory (file) || !app_info || is_a_special_file (file))
+ {
+ return FALSE;
+ }
+ }
+
+ mime_type = nautilus_file_get_mime_type (file);
+ extension = nautilus_file_get_extension (file);
+ hide = (g_content_type_is_unknown (mime_type) && extension == NULL);
+ g_free (mime_type);
+ g_free (extension);
+
+ return !hide;
}
static void
create_open_with_page (NautilusPropertiesWindow *window)
{
- GtkWidget *vbox;
- char *mime_type;
- GList *files = NULL;
- NautilusFile *target_file;
+ GtkWidget *vbox;
+ char *mime_type;
+ GList *files = NULL;
+ NautilusFile *target_file;
- target_file = get_target_file (window);
- mime_type = nautilus_file_get_mime_type (target_file);
+ target_file = get_target_file (window);
+ mime_type = nautilus_file_get_mime_type (target_file);
- if (!is_multi_file_window (window)) {
- files = g_list_prepend (NULL, target_file);
- } else {
- files = g_list_copy (window->details->original_files);
- if (files == NULL) {
- return;
- }
- }
+ if (!is_multi_file_window (window))
+ {
+ files = g_list_prepend (NULL, target_file);
+ }
+ else
+ {
+ files = g_list_copy (window->details->original_files);
+ if (files == NULL)
+ {
+ return;
+ }
+ }
- vbox = nautilus_mime_application_chooser_new (files, mime_type);
+ vbox = nautilus_mime_application_chooser_new (files, mime_type);
- gtk_widget_show (vbox);
- g_free (mime_type);
- g_list_free (files);
+ gtk_widget_show (vbox);
+ g_free (mime_type);
+ g_list_free (files);
- g_object_set_data_full (G_OBJECT (vbox), "help-uri", g_strdup ("help:gnome-help/files-open"), g_free);
- gtk_notebook_append_page (window->details->notebook,
- vbox, gtk_label_new (_("Open With")));
- gtk_container_child_set (GTK_CONTAINER (window->details->notebook),
- vbox,
- "tab-expand", TRUE,
- NULL);
+ g_object_set_data_full (G_OBJECT (vbox), "help-uri", g_strdup ("help:gnome-help/files-open"), g_free);
+ gtk_notebook_append_page (window->details->notebook,
+ vbox, gtk_label_new (_("Open With")));
+ gtk_container_child_set (GTK_CONTAINER (window->details->notebook),
+ vbox,
+ "tab-expand", TRUE,
+ NULL);
}
static NautilusPropertiesWindow *
create_properties_window (StartupData *startup_data)
{
- NautilusPropertiesWindow *window;
- GList *l;
-
- window = NAUTILUS_PROPERTIES_WINDOW (gtk_widget_new (NAUTILUS_TYPE_PROPERTIES_WINDOW,
- "use-header-bar", TRUE,
- "type-hint", GDK_WINDOW_TYPE_HINT_DIALOG,
- "modal", TRUE,
- NULL));
-
- window->details->original_files = nautilus_file_list_copy (startup_data->original_files);
-
- window->details->target_files = nautilus_file_list_copy (startup_data->target_files);
-
- gtk_window_set_wmclass (GTK_WINDOW (window), "file_properties", "Nautilus");
-
- if (startup_data->parent_widget) {
- gtk_window_set_screen (GTK_WINDOW (window),
- gtk_widget_get_screen (startup_data->parent_widget));
- }
-
- if (startup_data->parent_window) {
- gtk_window_set_transient_for (GTK_WINDOW (window), startup_data->parent_window);
- }
-
- if (startup_data->startup_id) {
- gtk_window_set_startup_id (GTK_WINDOW (window), startup_data->startup_id);
- }
-
- /* Set initial window title */
- update_properties_window_title (window);
-
- /* Start monitoring the file attributes we display. Note that some
- * of the attributes are for the original file, and some for the
- * target files.
- */
-
- for (l = window->details->original_files; l != NULL; l = l->next) {
- NautilusFile *file;
- NautilusFileAttributes attributes;
-
- file = NAUTILUS_FILE (l->data);
-
- attributes =
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO;
-
- nautilus_file_monitor_add (file,
- &window->details->original_files,
- attributes);
- }
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- NautilusFile *file;
- NautilusFileAttributes attributes;
-
- file = NAUTILUS_FILE (l->data);
-
- attributes = 0;
- if (nautilus_file_is_directory (file)) {
- attributes |= NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS;
- }
-
- attributes |= NAUTILUS_FILE_ATTRIBUTE_INFO;
- nautilus_file_monitor_add (file, &window->details->target_files, attributes);
- }
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- g_signal_connect_object (NAUTILUS_FILE (l->data),
- "changed",
- G_CALLBACK (file_changed_callback),
- G_OBJECT (window),
- 0);
- }
-
- for (l = window->details->original_files; l != NULL; l = l->next) {
- g_signal_connect_object (NAUTILUS_FILE (l->data),
- "changed",
- G_CALLBACK (file_changed_callback),
- G_OBJECT (window),
- 0);
- }
-
- /* Create the notebook tabs. */
- window->details->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
- gtk_notebook_set_show_border (window->details->notebook, FALSE);
- gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (window))), 0);
- gtk_widget_show (GTK_WIDGET (window->details->notebook));
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
- GTK_WIDGET (window->details->notebook),
- TRUE, TRUE, 0);
-
- /* Create the pages. */
- create_basic_page (window);
-
- if (should_show_permissions (window)) {
- create_permissions_page (window);
- }
-
- if (should_show_open_with (window)) {
- create_open_with_page (window);
- }
-
- /* append pages from available views */
- append_extension_pages (window);
-
- /* Update from initial state */
- properties_window_update (window, NULL);
-
- return window;
+ NautilusPropertiesWindow *window;
+ GList *l;
+
+ window = NAUTILUS_PROPERTIES_WINDOW (gtk_widget_new (NAUTILUS_TYPE_PROPERTIES_WINDOW,
+ "use-header-bar", TRUE,
+ "type-hint", GDK_WINDOW_TYPE_HINT_DIALOG,
+ "modal", TRUE,
+ NULL));
+
+ window->details->original_files = nautilus_file_list_copy (startup_data->original_files);
+
+ window->details->target_files = nautilus_file_list_copy (startup_data->target_files);
+
+ gtk_window_set_wmclass (GTK_WINDOW (window), "file_properties", "Nautilus");
+
+ if (startup_data->parent_widget)
+ {
+ gtk_window_set_screen (GTK_WINDOW (window),
+ gtk_widget_get_screen (startup_data->parent_widget));
+ }
+
+ if (startup_data->parent_window)
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (window), startup_data->parent_window);
+ }
+
+ if (startup_data->startup_id)
+ {
+ gtk_window_set_startup_id (GTK_WINDOW (window), startup_data->startup_id);
+ }
+
+ /* Set initial window title */
+ update_properties_window_title (window);
+
+ /* Start monitoring the file attributes we display. Note that some
+ * of the attributes are for the original file, and some for the
+ * target files.
+ */
+
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ NautilusFileAttributes attributes;
+
+ file = NAUTILUS_FILE (l->data);
+
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO;
+
+ nautilus_file_monitor_add (file,
+ &window->details->original_files,
+ attributes);
+ }
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ NautilusFile *file;
+ NautilusFileAttributes attributes;
+
+ file = NAUTILUS_FILE (l->data);
+
+ attributes = 0;
+ if (nautilus_file_is_directory (file))
+ {
+ attributes |= NAUTILUS_FILE_ATTRIBUTE_DEEP_COUNTS;
+ }
+
+ attributes |= NAUTILUS_FILE_ATTRIBUTE_INFO;
+ nautilus_file_monitor_add (file, &window->details->target_files, attributes);
+ }
+
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ g_signal_connect_object (NAUTILUS_FILE (l->data),
+ "changed",
+ G_CALLBACK (file_changed_callback),
+ G_OBJECT (window),
+ 0);
+ }
+
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ g_signal_connect_object (NAUTILUS_FILE (l->data),
+ "changed",
+ G_CALLBACK (file_changed_callback),
+ G_OBJECT (window),
+ 0);
+ }
+
+ /* Create the notebook tabs. */
+ window->details->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
+ gtk_notebook_set_show_border (window->details->notebook, FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (window))), 0);
+ gtk_widget_show (GTK_WIDGET (window->details->notebook));
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (window))),
+ GTK_WIDGET (window->details->notebook),
+ TRUE, TRUE, 0);
+
+ /* Create the pages. */
+ create_basic_page (window);
+
+ if (should_show_permissions (window))
+ {
+ create_permissions_page (window);
+ }
+
+ if (should_show_open_with (window))
+ {
+ create_open_with_page (window);
+ }
+
+ /* append pages from available views */
+ append_extension_pages (window);
+
+ /* Update from initial state */
+ properties_window_update (window, NULL);
+
+ return window;
}
static GList *
get_target_file_list (GList *original_files)
{
- GList *ret;
- GList *l;
-
- ret = NULL;
-
- for (l = original_files; l != NULL; l = l->next) {
- NautilusFile *target;
-
- target = get_target_file_for_original_file (NAUTILUS_FILE (l->data));
-
- ret = g_list_prepend (ret, target);
- }
+ GList *ret;
+ GList *l;
+
+ ret = NULL;
+
+ for (l = original_files; l != NULL; l = l->next)
+ {
+ NautilusFile *target;
- ret = g_list_reverse (ret);
+ target = get_target_file_for_original_file (NAUTILUS_FILE (l->data));
- return ret;
+ ret = g_list_prepend (ret, target);
+ }
+
+ ret = g_list_reverse (ret);
+
+ return ret;
}
static void
add_window (NautilusPropertiesWindow *window)
{
- if (!is_multi_file_window (window)) {
- g_hash_table_insert (windows,
- get_original_file (window),
- window);
- g_object_set_data (G_OBJECT (window), "window_key",
- get_original_file (window));
- }
+ if (!is_multi_file_window (window))
+ {
+ g_hash_table_insert (windows,
+ get_original_file (window),
+ window);
+ g_object_set_data (G_OBJECT (window), "window_key",
+ get_original_file (window));
+ }
}
static void
remove_window (NautilusPropertiesWindow *window)
{
- gpointer key;
+ gpointer key;
- key = g_object_get_data (G_OBJECT (window), "window_key");
- if (key) {
- g_hash_table_remove (windows, key);
- }
+ key = g_object_get_data (G_OBJECT (window), "window_key");
+ if (key)
+ {
+ g_hash_table_remove (windows, key);
+ }
}
static GtkWindow *
get_existing_window (GList *file_list)
{
- if (!file_list->next) {
- return g_hash_table_lookup (windows, file_list->data);
- }
+ if (!file_list->next)
+ {
+ return g_hash_table_lookup (windows, file_list->data);
+ }
- return NULL;
+ return NULL;
}
static void
cancel_create_properties_window_callback (gpointer callback_data)
{
- remove_pending ((StartupData *)callback_data, TRUE, FALSE, TRUE);
+ remove_pending ((StartupData *) callback_data, TRUE, FALSE, TRUE);
}
static void
-parent_widget_destroyed_callback (GtkWidget *widget, gpointer callback_data)
+parent_widget_destroyed_callback (GtkWidget *widget,
+ gpointer callback_data)
{
- g_assert (widget == ((StartupData *)callback_data)->parent_widget);
-
- remove_pending ((StartupData *)callback_data, TRUE, TRUE, FALSE);
+ g_assert (widget == ((StartupData *) callback_data)->parent_widget);
+
+ remove_pending ((StartupData *) callback_data, TRUE, TRUE, FALSE);
}
static void
cancel_call_when_ready_callback (gpointer key,
- gpointer value,
- gpointer user_data)
+ gpointer value,
+ gpointer user_data)
{
- nautilus_file_cancel_call_when_ready
- (NAUTILUS_FILE (key),
- is_directory_ready_callback,
- user_data);
+ nautilus_file_cancel_call_when_ready
+ (NAUTILUS_FILE (key),
+ is_directory_ready_callback,
+ user_data);
}
static void
remove_pending (StartupData *startup_data,
- gboolean cancel_call_when_ready,
- gboolean cancel_timed_wait,
- gboolean cancel_destroy_handler)
-{
- if (cancel_call_when_ready) {
- g_hash_table_foreach (startup_data->pending_files,
- cancel_call_when_ready_callback,
- startup_data);
-
- }
- if (cancel_timed_wait) {
- eel_timed_wait_stop
- (cancel_create_properties_window_callback, startup_data);
- }
- if (cancel_destroy_handler && startup_data->parent_widget) {
- g_signal_handlers_disconnect_by_func (startup_data->parent_widget,
- G_CALLBACK (parent_widget_destroyed_callback),
- startup_data);
- }
-
- g_hash_table_remove (pending_lists, startup_data->pending_key);
-
- startup_data_free (startup_data);
+ gboolean cancel_call_when_ready,
+ gboolean cancel_timed_wait,
+ gboolean cancel_destroy_handler)
+{
+ if (cancel_call_when_ready)
+ {
+ g_hash_table_foreach (startup_data->pending_files,
+ cancel_call_when_ready_callback,
+ startup_data);
+ }
+ if (cancel_timed_wait)
+ {
+ eel_timed_wait_stop
+ (cancel_create_properties_window_callback, startup_data);
+ }
+ if (cancel_destroy_handler && startup_data->parent_widget)
+ {
+ g_signal_handlers_disconnect_by_func (startup_data->parent_widget,
+ G_CALLBACK (parent_widget_destroyed_callback),
+ startup_data);
+ }
+
+ g_hash_table_remove (pending_lists, startup_data->pending_key);
+
+ startup_data_free (startup_data);
}
static void
is_directory_ready_callback (NautilusFile *file,
- gpointer data)
+ gpointer data)
{
- StartupData *startup_data;
-
- startup_data = data;
-
- g_hash_table_remove (startup_data->pending_files, file);
+ StartupData *startup_data;
+
+ startup_data = data;
+
+ g_hash_table_remove (startup_data->pending_files, file);
- if (g_hash_table_size (startup_data->pending_files) == 0) {
- NautilusPropertiesWindow *new_window;
-
- new_window = create_properties_window (startup_data);
-
- add_window (new_window);
-
- remove_pending (startup_data, FALSE, TRUE, TRUE);
-
- gtk_window_present (GTK_WINDOW (new_window));
- }
+ if (g_hash_table_size (startup_data->pending_files) == 0)
+ {
+ NautilusPropertiesWindow *new_window;
+
+ new_window = create_properties_window (startup_data);
+
+ add_window (new_window);
+
+ remove_pending (startup_data, FALSE, TRUE, TRUE);
+
+ gtk_window_present (GTK_WINDOW (new_window));
+ }
}
void
nautilus_properties_window_present (GList *original_files,
- GtkWidget *parent_widget,
- const gchar *startup_id)
-{
- GList *l, *next;
- GtkWidget *parent_window;
- StartupData *startup_data;
- GList *target_files;
- GtkWindow *existing_window;
- char *pending_key;
-
- g_return_if_fail (original_files != NULL);
- g_return_if_fail (parent_widget == NULL || GTK_IS_WIDGET (parent_widget));
-
- /* Create the hash tables first time through. */
- if (windows == NULL) {
- windows = g_hash_table_new (NULL, NULL);
- }
-
- if (pending_lists == NULL) {
- pending_lists = g_hash_table_new (g_str_hash, g_str_equal);
- }
-
- /* Look to see if there's already a window for this file. */
- existing_window = get_existing_window (original_files);
- if (existing_window != NULL) {
- if (parent_widget)
- gtk_window_set_screen (existing_window,
- gtk_widget_get_screen (parent_widget));
- else if (startup_id)
- gtk_window_set_startup_id (existing_window, startup_id);
-
- gtk_window_present (existing_window);
- return;
- }
-
-
- pending_key = get_pending_key (original_files);
-
- /* Look to see if we're already waiting for a window for this file. */
- if (g_hash_table_lookup (pending_lists, pending_key) != NULL) {
- return;
- }
-
- target_files = get_target_file_list (original_files);
-
- if (parent_widget) {
- parent_window = gtk_widget_get_ancestor (parent_widget, GTK_TYPE_WINDOW);
- } else {
- parent_window = NULL;
- }
-
- startup_data = startup_data_new (original_files,
- target_files,
- pending_key,
- parent_widget,
- GTK_WINDOW (parent_window),
- startup_id);
-
- nautilus_file_list_free (target_files);
- g_free(pending_key);
-
- /* Wait until we can tell whether it's a directory before showing, since
- * some one-time layout decisions depend on that info.
- */
-
- g_hash_table_insert (pending_lists, startup_data->pending_key, startup_data->pending_key);
- if (parent_widget) {
- g_signal_connect (parent_widget, "destroy",
- G_CALLBACK (parent_widget_destroyed_callback), startup_data);
- }
-
- eel_timed_wait_start
- (cancel_create_properties_window_callback,
- startup_data,
- _("Creating Properties window."),
- parent_window == NULL ? NULL : GTK_WINDOW (parent_window));
-
- for (l = startup_data->target_files; l != NULL; l = next) {
- next = l->next;
- nautilus_file_call_when_ready
- (NAUTILUS_FILE (l->data),
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- is_directory_ready_callback,
- startup_data);
- }
+ GtkWidget *parent_widget,
+ const gchar *startup_id)
+{
+ GList *l, *next;
+ GtkWidget *parent_window;
+ StartupData *startup_data;
+ GList *target_files;
+ GtkWindow *existing_window;
+ char *pending_key;
+
+ g_return_if_fail (original_files != NULL);
+ g_return_if_fail (parent_widget == NULL || GTK_IS_WIDGET (parent_widget));
+
+ /* Create the hash tables first time through. */
+ if (windows == NULL)
+ {
+ windows = g_hash_table_new (NULL, NULL);
+ }
+
+ if (pending_lists == NULL)
+ {
+ pending_lists = g_hash_table_new (g_str_hash, g_str_equal);
+ }
+
+ /* Look to see if there's already a window for this file. */
+ existing_window = get_existing_window (original_files);
+ if (existing_window != NULL)
+ {
+ if (parent_widget)
+ {
+ gtk_window_set_screen (existing_window,
+ gtk_widget_get_screen (parent_widget));
+ }
+ else if (startup_id)
+ {
+ gtk_window_set_startup_id (existing_window, startup_id);
+ }
+
+ gtk_window_present (existing_window);
+ return;
+ }
+
+
+ pending_key = get_pending_key (original_files);
+
+ /* Look to see if we're already waiting for a window for this file. */
+ if (g_hash_table_lookup (pending_lists, pending_key) != NULL)
+ {
+ return;
+ }
+
+ target_files = get_target_file_list (original_files);
+
+ if (parent_widget)
+ {
+ parent_window = gtk_widget_get_ancestor (parent_widget, GTK_TYPE_WINDOW);
+ }
+ else
+ {
+ parent_window = NULL;
+ }
+
+ startup_data = startup_data_new (original_files,
+ target_files,
+ pending_key,
+ parent_widget,
+ GTK_WINDOW (parent_window),
+ startup_id);
+
+ nautilus_file_list_free (target_files);
+ g_free (pending_key);
+
+ /* Wait until we can tell whether it's a directory before showing, since
+ * some one-time layout decisions depend on that info.
+ */
+
+ g_hash_table_insert (pending_lists, startup_data->pending_key, startup_data->pending_key);
+ if (parent_widget)
+ {
+ g_signal_connect (parent_widget, "destroy",
+ G_CALLBACK (parent_widget_destroyed_callback), startup_data);
+ }
+
+ eel_timed_wait_start
+ (cancel_create_properties_window_callback,
+ startup_data,
+ _("Creating Properties window."),
+ parent_window == NULL ? NULL : GTK_WINDOW (parent_window));
+
+ for (l = startup_data->target_files; l != NULL; l = next)
+ {
+ next = l->next;
+ nautilus_file_call_when_ready
+ (NAUTILUS_FILE (l->data),
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ is_directory_ready_callback,
+ startup_data);
+ }
}
static void
real_response (GtkDialog *dialog,
- int response)
-{
- switch (response) {
- case GTK_RESPONSE_NONE:
- case GTK_RESPONSE_CLOSE:
- case GTK_RESPONSE_DELETE_EVENT:
- gtk_widget_destroy (GTK_WIDGET (dialog));
- break;
-
- default:
- g_assert_not_reached ();
- break;
- }
+ int response)
+{
+ switch (response)
+ {
+ case GTK_RESPONSE_NONE:
+ case GTK_RESPONSE_CLOSE:
+ case GTK_RESPONSE_DELETE_EVENT:
+ {
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
}
static void
real_destroy (GtkWidget *object)
{
- NautilusPropertiesWindow *window;
- GList *l;
+ NautilusPropertiesWindow *window;
+ GList *l;
+
+ window = NAUTILUS_PROPERTIES_WINDOW (object);
- window = NAUTILUS_PROPERTIES_WINDOW (object);
+ remove_window (window);
- remove_window (window);
+ unschedule_or_cancel_group_change (window);
+ unschedule_or_cancel_owner_change (window);
- unschedule_or_cancel_group_change (window);
- unschedule_or_cancel_owner_change (window);
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ nautilus_file_monitor_remove (NAUTILUS_FILE (l->data), &window->details->original_files);
+ }
+ nautilus_file_list_free (window->details->original_files);
+ window->details->original_files = NULL;
- for (l = window->details->original_files; l != NULL; l = l->next) {
- nautilus_file_monitor_remove (NAUTILUS_FILE (l->data), &window->details->original_files);
- }
- nautilus_file_list_free (window->details->original_files);
- window->details->original_files = NULL;
-
- for (l = window->details->target_files; l != NULL; l = l->next) {
- nautilus_file_monitor_remove (NAUTILUS_FILE (l->data), &window->details->target_files);
- }
- nautilus_file_list_free (window->details->target_files);
- window->details->target_files = NULL;
+ for (l = window->details->target_files; l != NULL; l = l->next)
+ {
+ nautilus_file_monitor_remove (NAUTILUS_FILE (l->data), &window->details->target_files);
+ }
+ nautilus_file_list_free (window->details->target_files);
+ window->details->target_files = NULL;
- nautilus_file_list_free (window->details->changed_files);
- window->details->changed_files = NULL;
+ nautilus_file_list_free (window->details->changed_files);
+ window->details->changed_files = NULL;
- if (window->details->deep_count_spinner_timeout_id > 0) {
- g_source_remove (window->details->deep_count_spinner_timeout_id);
- }
+ if (window->details->deep_count_spinner_timeout_id > 0)
+ {
+ g_source_remove (window->details->deep_count_spinner_timeout_id);
+ }
- while (window->details->deep_count_files) {
- stop_deep_count_for_file (window, window->details->deep_count_files->data);
- }
+ while (window->details->deep_count_files)
+ {
+ stop_deep_count_for_file (window, window->details->deep_count_files->data);
+ }
- window->details->name_field = NULL;
+ window->details->name_field = NULL;
- g_list_free (window->details->permission_buttons);
- window->details->permission_buttons = NULL;
+ g_list_free (window->details->permission_buttons);
+ window->details->permission_buttons = NULL;
- g_list_free (window->details->permission_combos);
- window->details->permission_combos = NULL;
+ g_list_free (window->details->permission_combos);
+ window->details->permission_combos = NULL;
- g_list_free (window->details->change_permission_combos);
- window->details->change_permission_combos = NULL;
+ g_list_free (window->details->change_permission_combos);
+ window->details->change_permission_combos = NULL;
- if (window->details->initial_permissions) {
- g_hash_table_destroy (window->details->initial_permissions);
- window->details->initial_permissions = NULL;
- }
+ if (window->details->initial_permissions)
+ {
+ g_hash_table_destroy (window->details->initial_permissions);
+ window->details->initial_permissions = NULL;
+ }
- g_list_free (window->details->value_fields);
- window->details->value_fields = NULL;
+ g_list_free (window->details->value_fields);
+ window->details->value_fields = NULL;
- if (window->details->update_directory_contents_timeout_id != 0) {
- g_source_remove (window->details->update_directory_contents_timeout_id);
- window->details->update_directory_contents_timeout_id = 0;
- }
+ if (window->details->update_directory_contents_timeout_id != 0)
+ {
+ g_source_remove (window->details->update_directory_contents_timeout_id);
+ window->details->update_directory_contents_timeout_id = 0;
+ }
- if (window->details->update_files_timeout_id != 0) {
- g_source_remove (window->details->update_files_timeout_id);
- window->details->update_files_timeout_id = 0;
- }
+ if (window->details->update_files_timeout_id != 0)
+ {
+ g_source_remove (window->details->update_files_timeout_id);
+ window->details->update_files_timeout_id = 0;
+ }
- GTK_WIDGET_CLASS (nautilus_properties_window_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (nautilus_properties_window_parent_class)->destroy (object);
}
static void
real_finalize (GObject *object)
{
- NautilusPropertiesWindow *window;
+ NautilusPropertiesWindow *window;
- window = NAUTILUS_PROPERTIES_WINDOW (object);
+ window = NAUTILUS_PROPERTIES_WINDOW (object);
- g_list_free_full (window->details->mime_list, g_free);
+ g_list_free_full (window->details->mime_list, g_free);
- g_free (window->details->pending_name);
+ g_free (window->details->pending_name);
- G_OBJECT_CLASS (nautilus_properties_window_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_properties_window_parent_class)->finalize (object);
}
/* converts
@@ -4979,251 +5496,285 @@ real_finalize (GObject *object)
* */
static char *
make_relative_uri_from_full (const char *uri,
- const char *base_uri)
+ const char *base_uri)
{
- g_assert (uri != NULL);
- g_assert (base_uri != NULL);
+ g_assert (uri != NULL);
+ g_assert (base_uri != NULL);
- if (g_str_has_prefix (uri, base_uri)) {
- uri += strlen (base_uri);
- if (*uri != '/') {
- return NULL;
- }
+ if (g_str_has_prefix (uri, base_uri))
+ {
+ uri += strlen (base_uri);
+ if (*uri != '/')
+ {
+ return NULL;
+ }
- while (*uri == '/') {
- uri++;
- }
+ while (*uri == '/')
+ {
+ uri++;
+ }
- if (*uri != '\0') {
- return g_strdup (uri);
- }
- }
+ if (*uri != '\0')
+ {
+ return g_strdup (uri);
+ }
+ }
- return NULL;
+ return NULL;
}
/* icon selection callback to set the image of the file object to the selected file */
static void
-set_icon (const char* icon_uri, NautilusPropertiesWindow *properties_window)
-{
- NautilusFile *file;
- char *file_uri;
- char *icon_path;
- char *real_icon_uri;
-
- g_assert (icon_uri != NULL);
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (properties_window));
-
- icon_path = g_filename_from_uri (icon_uri, NULL, NULL);
- /* we don't allow remote URIs */
- if (icon_path != NULL) {
- GList *l;
-
- for (l = properties_window->details->original_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
-
- file_uri = nautilus_file_get_uri (file);
-
- if (nautilus_file_is_mime_type (file, "application/x-desktop")) {
- if (nautilus_link_local_set_icon (file_uri, icon_path)) {
- nautilus_file_invalidate_attributes (file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
- }
- } else {
- real_icon_uri = make_relative_uri_from_full (icon_uri, file_uri);
- if (real_icon_uri == NULL) {
- real_icon_uri = g_strdup (icon_uri);
- }
-
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, real_icon_uri);
- nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ICON_SCALE, NULL, NULL);
-
- g_free (real_icon_uri);
- }
-
- g_free (file_uri);
- }
-
- g_free (icon_path);
- }
+set_icon (const char *icon_uri,
+ NautilusPropertiesWindow *properties_window)
+{
+ NautilusFile *file;
+ char *file_uri;
+ char *icon_path;
+ char *real_icon_uri;
+
+ g_assert (icon_uri != NULL);
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (properties_window));
+
+ icon_path = g_filename_from_uri (icon_uri, NULL, NULL);
+ /* we don't allow remote URIs */
+ if (icon_path != NULL)
+ {
+ GList *l;
+
+ for (l = properties_window->details->original_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+
+ file_uri = nautilus_file_get_uri (file);
+
+ if (nautilus_file_is_mime_type (file, "application/x-desktop"))
+ {
+ if (nautilus_link_local_set_icon (file_uri, icon_path))
+ {
+ nautilus_file_invalidate_attributes (file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO);
+ }
+ }
+ else
+ {
+ real_icon_uri = make_relative_uri_from_full (icon_uri, file_uri);
+ if (real_icon_uri == NULL)
+ {
+ real_icon_uri = g_strdup (icon_uri);
+ }
+
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL, real_icon_uri);
+ nautilus_file_set_metadata (file, NAUTILUS_METADATA_KEY_ICON_SCALE, NULL, NULL);
+
+ g_free (real_icon_uri);
+ }
+
+ g_free (file_uri);
+ }
+
+ g_free (icon_path);
+ }
}
static void
-update_preview_callback (GtkFileChooser *icon_chooser,
- NautilusPropertiesWindow *window)
-{
- GtkWidget *preview_widget;
- GdkPixbuf *pixbuf, *scaled_pixbuf;
- char *filename;
- double scale;
-
- pixbuf = NULL;
-
- filename = gtk_file_chooser_get_filename (icon_chooser);
- if (filename != NULL) {
- pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
- }
-
- if (pixbuf != NULL) {
- preview_widget = gtk_file_chooser_get_preview_widget (icon_chooser);
- gtk_file_chooser_set_preview_widget_active (icon_chooser, TRUE);
-
- if (gdk_pixbuf_get_width (pixbuf) > PREVIEW_IMAGE_WIDTH) {
- scale = (double)gdk_pixbuf_get_height (pixbuf) /
- gdk_pixbuf_get_width (pixbuf);
-
- scaled_pixbuf = gnome_desktop_thumbnail_scale_down_pixbuf
- (pixbuf,
- PREVIEW_IMAGE_WIDTH,
- scale * PREVIEW_IMAGE_WIDTH);
- g_object_unref (pixbuf);
- pixbuf = scaled_pixbuf;
- }
-
- gtk_image_set_from_pixbuf (GTK_IMAGE (preview_widget), pixbuf);
- } else {
- gtk_file_chooser_set_preview_widget_active (icon_chooser, FALSE);
- }
-
- g_free (filename);
-
- if (pixbuf != NULL) {
- g_object_unref (pixbuf);
- }
+update_preview_callback (GtkFileChooser *icon_chooser,
+ NautilusPropertiesWindow *window)
+{
+ GtkWidget *preview_widget;
+ GdkPixbuf *pixbuf, *scaled_pixbuf;
+ char *filename;
+ double scale;
+
+ pixbuf = NULL;
+
+ filename = gtk_file_chooser_get_filename (icon_chooser);
+ if (filename != NULL)
+ {
+ pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+ }
+
+ if (pixbuf != NULL)
+ {
+ preview_widget = gtk_file_chooser_get_preview_widget (icon_chooser);
+ gtk_file_chooser_set_preview_widget_active (icon_chooser, TRUE);
+
+ if (gdk_pixbuf_get_width (pixbuf) > PREVIEW_IMAGE_WIDTH)
+ {
+ scale = (double) gdk_pixbuf_get_height (pixbuf) /
+ gdk_pixbuf_get_width (pixbuf);
+
+ scaled_pixbuf = gnome_desktop_thumbnail_scale_down_pixbuf
+ (pixbuf,
+ PREVIEW_IMAGE_WIDTH,
+ scale * PREVIEW_IMAGE_WIDTH);
+ g_object_unref (pixbuf);
+ pixbuf = scaled_pixbuf;
+ }
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (preview_widget), pixbuf);
+ }
+ else
+ {
+ gtk_file_chooser_set_preview_widget_active (icon_chooser, FALSE);
+ }
+
+ g_free (filename);
+
+ if (pixbuf != NULL)
+ {
+ g_object_unref (pixbuf);
+ }
}
static void
-custom_icon_file_chooser_response_cb (GtkDialog *dialog,
- gint response,
- NautilusPropertiesWindow *window)
-{
- char *uri;
-
- switch (response) {
- case GTK_RESPONSE_NO:
- reset_icon (window);
- break;
-
- case GTK_RESPONSE_OK:
- uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
- if (uri != NULL) {
- set_icon (uri, window);
- } else {
- reset_icon (window);
- }
- g_free (uri);
- break;
-
- default:
- break;
- }
-
- gtk_widget_hide (GTK_WIDGET (dialog));
+custom_icon_file_chooser_response_cb (GtkDialog *dialog,
+ gint response,
+ NautilusPropertiesWindow *window)
+{
+ char *uri;
+
+ switch (response)
+ {
+ case GTK_RESPONSE_NO:
+ {
+ reset_icon (window);
+ }
+ break;
+
+ case GTK_RESPONSE_OK:
+ {
+ uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog));
+ if (uri != NULL)
+ {
+ set_icon (uri, window);
+ }
+ else
+ {
+ reset_icon (window);
+ }
+ g_free (uri);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
+
+ gtk_widget_hide (GTK_WIDGET (dialog));
}
static void
-select_image_button_callback (GtkWidget *widget,
- NautilusPropertiesWindow *window)
-{
- GtkWidget *dialog, *preview;
- GtkFileFilter *filter;
- GList *l;
- NautilusFile *file;
- char *uri;
- char *image_path;
- gboolean revert_is_sensitive;
-
- g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
-
- dialog = window->details->icon_chooser;
-
- if (dialog == NULL) {
- dialog = gtk_file_chooser_dialog_new (_("Select Custom Icon"), GTK_WINDOW (window),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- _("_Revert"), GTK_RESPONSE_NO,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("_Open"), GTK_RESPONSE_OK,
- NULL);
- gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
- g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
- NULL);
- gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
- gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
-
- filter = gtk_file_filter_new ();
- gtk_file_filter_add_pixbuf_formats (filter);
- gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
-
- preview = gtk_image_new ();
- gtk_widget_set_size_request (preview, PREVIEW_IMAGE_WIDTH, -1);
- gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview);
- gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (dialog), FALSE);
- gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER (dialog), FALSE);
-
- g_signal_connect (dialog, "update-preview",
- G_CALLBACK (update_preview_callback), window);
-
- window->details->icon_chooser = dialog;
-
- g_object_add_weak_pointer (G_OBJECT (dialog),
- (gpointer *) &window->details->icon_chooser);
- }
-
- /* it's likely that the user wants to pick an icon that is inside a local directory */
- if (g_list_length (window->details->original_files) == 1) {
- file = NAUTILUS_FILE (window->details->original_files->data);
-
- if (nautilus_file_is_directory (file)) {
- uri = nautilus_file_get_uri (file);
-
- image_path = g_filename_from_uri (uri, NULL, NULL);
- if (image_path != NULL) {
- gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), image_path);
- g_free (image_path);
- }
-
- g_free (uri);
- }
- }
-
- revert_is_sensitive = FALSE;
- for (l = window->details->original_files; l != NULL; l = l->next) {
- file = NAUTILUS_FILE (l->data);
- image_path = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
- revert_is_sensitive = (image_path != NULL);
- g_free (image_path);
-
- if (revert_is_sensitive) {
- break;
- }
- }
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_NO, revert_is_sensitive);
-
- g_signal_connect (dialog, "response",
- G_CALLBACK (custom_icon_file_chooser_response_cb), window);
- gtk_widget_show (dialog);
+select_image_button_callback (GtkWidget *widget,
+ NautilusPropertiesWindow *window)
+{
+ GtkWidget *dialog, *preview;
+ GtkFileFilter *filter;
+ GList *l;
+ NautilusFile *file;
+ char *uri;
+ char *image_path;
+ gboolean revert_is_sensitive;
+
+ g_assert (NAUTILUS_IS_PROPERTIES_WINDOW (window));
+
+ dialog = window->details->icon_chooser;
+
+ if (dialog == NULL)
+ {
+ dialog = gtk_file_chooser_dialog_new (_("Select Custom Icon"), GTK_WINDOW (window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ _("_Revert"), GTK_RESPONSE_NO,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Open"), GTK_RESPONSE_OK,
+ NULL);
+ gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
+ g_get_user_special_dir (G_USER_DIRECTORY_PICTURES),
+ NULL);
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ filter = gtk_file_filter_new ();
+ gtk_file_filter_add_pixbuf_formats (filter);
+ gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+
+ preview = gtk_image_new ();
+ gtk_widget_set_size_request (preview, PREVIEW_IMAGE_WIDTH, -1);
+ gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview);
+ gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (dialog), FALSE);
+ gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER (dialog), FALSE);
+
+ g_signal_connect (dialog, "update-preview",
+ G_CALLBACK (update_preview_callback), window);
+
+ window->details->icon_chooser = dialog;
+
+ g_object_add_weak_pointer (G_OBJECT (dialog),
+ (gpointer *) &window->details->icon_chooser);
+ }
+
+ /* it's likely that the user wants to pick an icon that is inside a local directory */
+ if (g_list_length (window->details->original_files) == 1)
+ {
+ file = NAUTILUS_FILE (window->details->original_files->data);
+
+ if (nautilus_file_is_directory (file))
+ {
+ uri = nautilus_file_get_uri (file);
+
+ image_path = g_filename_from_uri (uri, NULL, NULL);
+ if (image_path != NULL)
+ {
+ gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), image_path);
+ g_free (image_path);
+ }
+
+ g_free (uri);
+ }
+ }
+
+ revert_is_sensitive = FALSE;
+ for (l = window->details->original_files; l != NULL; l = l->next)
+ {
+ file = NAUTILUS_FILE (l->data);
+ image_path = nautilus_file_get_metadata (file, NAUTILUS_METADATA_KEY_CUSTOM_ICON, NULL);
+ revert_is_sensitive = (image_path != NULL);
+ g_free (image_path);
+
+ if (revert_is_sensitive)
+ {
+ break;
+ }
+ }
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_NO, revert_is_sensitive);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (custom_icon_file_chooser_response_cb), window);
+ gtk_widget_show (dialog);
}
static void
nautilus_properties_window_class_init (NautilusPropertiesWindowClass *class)
{
- GtkBindingSet *binding_set;
+ GtkBindingSet *binding_set;
- G_OBJECT_CLASS (class)->finalize = real_finalize;
- GTK_WIDGET_CLASS (class)->destroy = real_destroy;
- GTK_DIALOG_CLASS (class)->response = real_response;
+ G_OBJECT_CLASS (class)->finalize = real_finalize;
+ GTK_WIDGET_CLASS (class)->destroy = real_destroy;
+ GTK_DIALOG_CLASS (class)->response = real_response;
- binding_set = gtk_binding_set_by_class (class);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
- "close", 0);
+ binding_set = gtk_binding_set_by_class (class);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0,
+ "close", 0);
- g_type_class_add_private (class, sizeof (NautilusPropertiesWindowDetails));
+ g_type_class_add_private (class, sizeof (NautilusPropertiesWindowDetails));
}
static void
nautilus_properties_window_init (NautilusPropertiesWindow *window)
{
- window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_PROPERTIES_WINDOW,
- NautilusPropertiesWindowDetails);
+ window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_PROPERTIES_WINDOW,
+ NautilusPropertiesWindowDetails);
}
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 94611386f..85586f793 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -37,40 +37,45 @@
#include "nautilus-ui-utilities.h"
#include "nautilus-global-preferences.h"
-typedef struct {
- GtkWidget *entry;
- GtkWidget *popover;
- GtkWidget *label;
- GtkWidget *dropdown_button;
+typedef struct
+{
+ GtkWidget *entry;
+ GtkWidget *popover;
+ GtkWidget *label;
+ GtkWidget *dropdown_button;
- GdTaggedEntryTag *mime_types_tag;
- GdTaggedEntryTag *date_range_tag;
+ GdTaggedEntryTag *mime_types_tag;
+ GdTaggedEntryTag *date_range_tag;
- gboolean change_frozen;
+ gboolean change_frozen;
- GFile *location;
+ GFile *location;
- NautilusQuery *query;
+ NautilusQuery *query;
} NautilusQueryEditorPrivate;
-enum {
- ACTIVATED,
- CHANGED,
- CANCEL,
- LAST_SIGNAL
+enum
+{
+ ACTIVATED,
+ CHANGED,
+ CANCEL,
+ LAST_SIGNAL
};
-enum {
- PROP_0,
- PROP_LOCATION,
- PROP_QUERY,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_LOCATION,
+ PROP_QUERY,
+ LAST_PROP
};
static guint signals[LAST_SIGNAL];
-static void entry_activate_cb (GtkWidget *entry, NautilusQueryEditor *editor);
-static void entry_changed_cb (GtkWidget *entry, NautilusQueryEditor *editor);
+static void entry_activate_cb (GtkWidget *entry,
+ NautilusQueryEditor *editor);
+static void entry_changed_cb (GtkWidget *entry,
+ NautilusQueryEditor *editor);
static void nautilus_query_editor_changed (NautilusQueryEditor *editor);
G_DEFINE_TYPE_WITH_PRIVATE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE_SEARCH_BAR);
@@ -78,64 +83,79 @@ G_DEFINE_TYPE_WITH_PRIVATE (NautilusQueryEditor, nautilus_query_editor, GTK_TYPE
static gboolean
settings_search_is_recursive (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- NautilusFile *file;
- gboolean recursive;
+ NautilusQueryEditorPrivate *priv;
+ NautilusFile *file;
+ gboolean recursive;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- if (!priv->location)
- return TRUE;
+ if (!priv->location)
+ {
+ return TRUE;
+ }
- file = nautilus_file_get (priv->location);
+ file = nautilus_file_get (priv->location);
- if (nautilus_file_is_remote (file)) {
- recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS;
- } else {
- recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY ||
- g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS;
- }
+ if (nautilus_file_is_remote (file))
+ {
+ recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS;
+ }
+ else
+ {
+ recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY ||
+ g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS;
+ }
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
- return recursive;
+ return recursive;
}
static void
update_information_label (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
-
- priv = nautilus_query_editor_get_instance_private (editor);
-
- if (priv->location) {
- NautilusFile *file;
- gchar *label;
- gchar *uri;
-
- file = nautilus_file_get (priv->location);
- label = NULL;
- uri = g_file_get_uri (priv->location);
-
- if (nautilus_file_is_other_locations (file)) {
- label = _("Searching locations only");
- } else if (g_str_has_prefix (uri, "computer://")) {
- label = _("Searching devices only");
- } else if (g_str_has_prefix (uri, "network://")) {
- label = _("Searching network locations only");
- } else if (nautilus_file_is_remote (file) &&
- !settings_search_is_recursive (editor)) {
- label = _("Remote location - only searching the current folder");
- } else if (!settings_search_is_recursive (editor)) {
- label = _("Only searching the current folder");
- }
-
- gtk_widget_set_visible (priv->label, label != NULL);
- gtk_label_set_label (GTK_LABEL (priv->label), label);
-
- g_free (uri);
- nautilus_file_unref (file);
+ NautilusQueryEditorPrivate *priv;
+
+ priv = nautilus_query_editor_get_instance_private (editor);
+
+ if (priv->location)
+ {
+ NautilusFile *file;
+ gchar *label;
+ gchar *uri;
+
+ file = nautilus_file_get (priv->location);
+ label = NULL;
+ uri = g_file_get_uri (priv->location);
+
+ if (nautilus_file_is_other_locations (file))
+ {
+ label = _("Searching locations only");
+ }
+ else if (g_str_has_prefix (uri, "computer://"))
+ {
+ label = _("Searching devices only");
+ }
+ else if (g_str_has_prefix (uri, "network://"))
+ {
+ label = _("Searching network locations only");
}
+ else if (nautilus_file_is_remote (file) &&
+ !settings_search_is_recursive (editor))
+ {
+ label = _("Remote location - only searching the current folder");
+ }
+ else if (!settings_search_is_recursive (editor))
+ {
+ label = _("Only searching the current folder");
+ }
+
+ gtk_widget_set_visible (priv->label, label != NULL);
+ gtk_label_set_label (GTK_LABEL (priv->label), label);
+
+ g_free (uri);
+ nautilus_file_unref (file);
+ }
}
static void
@@ -143,53 +163,57 @@ recursive_search_preferences_changed (GSettings *settings,
gchar *key,
NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- gboolean recursive;
+ NautilusQueryEditorPrivate *priv;
+ gboolean recursive;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- if (!priv->location || !priv->query)
- return;
+ if (!priv->location || !priv->query)
+ {
+ return;
+ }
- recursive = settings_search_is_recursive (editor);
- if (recursive != nautilus_query_get_recursive (priv->query)) {
- nautilus_query_set_recursive (priv->query, recursive);
- nautilus_query_editor_changed (editor);
- }
+ recursive = settings_search_is_recursive (editor);
+ if (recursive != nautilus_query_get_recursive (priv->query))
+ {
+ nautilus_query_set_recursive (priv->query, recursive);
+ nautilus_query_editor_changed (editor);
+ }
- update_information_label (editor);
+ update_information_label (editor);
}
static void
nautilus_query_editor_dispose (GObject *object)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
- g_clear_object (&priv->location);
- g_clear_object (&priv->query);
+ g_clear_object (&priv->location);
+ g_clear_object (&priv->query);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- recursive_search_preferences_changed,
- object);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ recursive_search_preferences_changed,
+ object);
- G_OBJECT_CLASS (nautilus_query_editor_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_query_editor_parent_class)->dispose (object);
}
static void
nautilus_query_editor_grab_focus (GtkWidget *widget)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (widget));
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (widget));
- if (gtk_widget_get_visible (widget) && !gtk_widget_is_focus (priv->entry)) {
- /* avoid selecting the entry text */
- gtk_widget_grab_focus (priv->entry);
- gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1);
- }
+ if (gtk_widget_get_visible (widget) && !gtk_widget_is_focus (priv->entry))
+ {
+ /* avoid selecting the entry text */
+ gtk_widget_grab_focus (priv->entry);
+ gtk_editable_set_position (GTK_EDITABLE (priv->entry), -1);
+ }
}
static void
@@ -198,23 +222,27 @@ nautilus_query_editor_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (object));
- switch (prop_id)
- {
+ switch (prop_id)
+ {
case PROP_LOCATION:
- g_value_set_object (value, priv->location);
- break;
+ {
+ g_value_set_object (value, priv->location);
+ }
+ break;
case PROP_QUERY:
- g_value_set_object (value, priv->query);
- break;
+ {
+ g_value_set_object (value, priv->query);
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
@@ -223,165 +251,174 @@ nautilus_query_editor_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- NautilusQueryEditor *self;
+ NautilusQueryEditor *self;
- self = NAUTILUS_QUERY_EDITOR (object);
+ self = NAUTILUS_QUERY_EDITOR (object);
- switch (prop_id)
- {
+ switch (prop_id)
+ {
case PROP_LOCATION:
- nautilus_query_editor_set_location (self, g_value_get_object (value));
- break;
+ {
+ nautilus_query_editor_set_location (self, g_value_get_object (value));
+ }
+ break;
case PROP_QUERY:
- nautilus_query_editor_set_query (self, g_value_get_object (value));
- break;
+ {
+ nautilus_query_editor_set_query (self, g_value_get_object (value));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
nautilus_query_editor_class_init (NautilusQueryEditorClass *class)
{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
-
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->dispose = nautilus_query_editor_dispose;
- gobject_class->get_property = nautilus_query_editor_get_property;
- gobject_class->set_property = nautilus_query_editor_set_property;
-
- widget_class = GTK_WIDGET_CLASS (class);
- widget_class->grab_focus = nautilus_query_editor_grab_focus;
-
- signals[CHANGED] =
- g_signal_new ("changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusQueryEditorClass, changed),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 2, NAUTILUS_TYPE_QUERY, G_TYPE_BOOLEAN);
-
- signals[CANCEL] =
- g_signal_new ("cancel",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (NautilusQueryEditorClass, cancel),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[ACTIVATED] =
- g_signal_new ("activated",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (NautilusQueryEditorClass, activated),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- /**
- * NautilusQueryEditor::location:
- *
- * The current location of the query editor.
- */
- g_object_class_install_property (gobject_class,
- PROP_LOCATION,
- g_param_spec_object ("location",
- "Location of the search",
- "The current location of the editor",
- G_TYPE_FILE,
- G_PARAM_READWRITE));
-
- /**
- * NautilusQueryEditor::query:
- *
- * The current query of the query editor. It it always synchronized
- * with the filter popover's query.
- */
- g_object_class_install_property (gobject_class,
- PROP_QUERY,
- g_param_spec_object ("query",
- "Query of the search",
- "The query that the editor is handling",
- NAUTILUS_TYPE_QUERY,
- G_PARAM_READWRITE));
+ GObjectClass *gobject_class;
+ GtkWidgetClass *widget_class;
+
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->dispose = nautilus_query_editor_dispose;
+ gobject_class->get_property = nautilus_query_editor_get_property;
+ gobject_class->set_property = nautilus_query_editor_set_property;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->grab_focus = nautilus_query_editor_grab_focus;
+
+ signals[CHANGED] =
+ g_signal_new ("changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusQueryEditorClass, changed),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 2, NAUTILUS_TYPE_QUERY, G_TYPE_BOOLEAN);
+
+ signals[CANCEL] =
+ g_signal_new ("cancel",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (NautilusQueryEditorClass, cancel),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[ACTIVATED] =
+ g_signal_new ("activated",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (NautilusQueryEditorClass, activated),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
+ * NautilusQueryEditor::location:
+ *
+ * The current location of the query editor.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_LOCATION,
+ g_param_spec_object ("location",
+ "Location of the search",
+ "The current location of the editor",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQueryEditor::query:
+ *
+ * The current query of the query editor. It it always synchronized
+ * with the filter popover's query.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_QUERY,
+ g_param_spec_object ("query",
+ "Query of the search",
+ "The query that the editor is handling",
+ NAUTILUS_TYPE_QUERY,
+ G_PARAM_READWRITE));
}
GFile *
nautilus_query_editor_get_location (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (editor), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (editor), NULL);
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- return g_object_ref (priv->location);
+ return g_object_ref (priv->location);
}
static void
create_query (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- NautilusQuery *query;
- NautilusFile *file;
- gboolean recursive;
+ NautilusQueryEditorPrivate *priv;
+ NautilusQuery *query;
+ NautilusFile *file;
+ gboolean recursive;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- g_return_if_fail (!priv->query);
+ g_return_if_fail (!priv->query);
- file = nautilus_file_get (priv->location);
- query = nautilus_query_new ();
+ file = nautilus_file_get (priv->location);
+ query = nautilus_query_new ();
- recursive = settings_search_is_recursive (editor);
+ recursive = settings_search_is_recursive (editor);
- nautilus_query_set_text (query, gtk_entry_get_text (GTK_ENTRY (priv->entry)));
- nautilus_query_set_location (query, priv->location);
- nautilus_query_set_recursive (query, recursive);
+ nautilus_query_set_text (query, gtk_entry_get_text (GTK_ENTRY (priv->entry)));
+ nautilus_query_set_location (query, priv->location);
+ nautilus_query_set_recursive (query, recursive);
- nautilus_query_editor_set_query (editor, query);
+ nautilus_query_editor_set_query (editor, query);
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
}
static void
-entry_activate_cb (GtkWidget *entry, NautilusQueryEditor *editor)
+entry_activate_cb (GtkWidget *entry,
+ NautilusQueryEditor *editor)
{
- g_signal_emit (editor, signals[ACTIVATED], 0);
+ g_signal_emit (editor, signals[ACTIVATED], 0);
}
static void
-entry_changed_cb (GtkWidget *entry, NautilusQueryEditor *editor)
+entry_changed_cb (GtkWidget *entry,
+ NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- gchar *text;
+ NautilusQueryEditorPrivate *priv;
+ gchar *text;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- if (priv->change_frozen || !gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (editor))) {
- return;
- }
+ if (priv->change_frozen || !gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (editor)))
+ {
+ return;
+ }
- if (!priv->query)
- create_query (editor);
- text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))));
+ if (!priv->query)
+ {
+ create_query (editor);
+ }
+ text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))));
- nautilus_query_set_text (priv->query, text);
- nautilus_query_editor_changed (editor);
+ nautilus_query_set_text (priv->query, text);
+ nautilus_query_editor_changed (editor);
- g_free (text);
+ g_free (text);
}
static void
nautilus_query_editor_on_stop_search (GtkWidget *entry,
NautilusQueryEditor *editor)
{
- g_signal_emit (editor, signals[CANCEL], 0);
+ g_signal_emit (editor, signals[CANCEL], 0);
}
/* Type */
@@ -389,21 +426,22 @@ nautilus_query_editor_on_stop_search (GtkWidget *entry,
static void
nautilus_query_editor_init (NautilusQueryEditor *editor)
{
- g_signal_connect (nautilus_preferences,
- "changed::recursive-search",
- G_CALLBACK (recursive_search_preferences_changed),
- editor);
+ g_signal_connect (nautilus_preferences,
+ "changed::recursive-search",
+ G_CALLBACK (recursive_search_preferences_changed),
+ editor);
}
static gboolean
entry_key_press_event_cb (GtkWidget *widget,
- GdkEventKey *event,
- NautilusQueryEditor *editor)
+ GdkEventKey *event,
+ NautilusQueryEditor *editor)
{
- if (event->keyval == GDK_KEY_Down) {
- gtk_widget_grab_focus (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
- }
- return FALSE;
+ if (event->keyval == GDK_KEY_Down)
+ {
+ gtk_widget_grab_focus (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
+ }
+ return FALSE;
}
static void
@@ -411,14 +449,15 @@ search_mode_changed_cb (GObject *editor,
GParamSpec *pspec,
gpointer user_data)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
- if (!gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (editor))) {
- g_signal_emit (editor, signals[CANCEL], 0);
- gtk_widget_hide (priv->popover);
- }
+ if (!gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (editor)))
+ {
+ g_signal_emit (editor, signals[CANCEL], 0);
+ gtk_widget_hide (priv->popover);
+ }
}
static void
@@ -426,27 +465,30 @@ search_popover_date_range_changed_cb (NautilusSearchPopover *popover,
GPtrArray *date_range,
NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
-
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
- if (!priv->query)
- create_query (editor);
-
- gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (priv->entry),
- priv->date_range_tag);
- if (date_range) {
- g_autofree gchar *text_for_date_range;
-
- text_for_date_range = get_text_for_date_range (date_range);
- gd_tagged_entry_tag_set_label (priv->date_range_tag,
- text_for_date_range);
- gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
- GD_TAGGED_ENTRY_TAG (priv->date_range_tag));
- }
-
- nautilus_query_set_date_range (priv->query, date_range);
-
- nautilus_query_editor_changed (editor);
+ NautilusQueryEditorPrivate *priv;
+
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
+ if (!priv->query)
+ {
+ create_query (editor);
+ }
+
+ gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (priv->entry),
+ priv->date_range_tag);
+ if (date_range)
+ {
+ g_autofree gchar *text_for_date_range;
+
+ text_for_date_range = get_text_for_date_range (date_range);
+ gd_tagged_entry_tag_set_label (priv->date_range_tag,
+ text_for_date_range);
+ gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
+ GD_TAGGED_ENTRY_TAG (priv->date_range_tag));
+ }
+
+ nautilus_query_set_date_range (priv->query, date_range);
+
+ nautilus_query_editor_changed (editor);
}
static void
@@ -455,38 +497,45 @@ search_popover_mime_type_changed_cb (NautilusSearchPopover *popover,
const gchar *mimetype,
NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- GList *mimetypes = NULL;
-
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
- if (!priv->query)
- create_query (editor);
-
- gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (priv->entry),
- priv->mime_types_tag);
- /* group 0 is anything */
- if (mimetype_group == 0) {
- mimetypes = nautilus_mime_types_group_get_mimetypes (mimetype_group);
- } else if (mimetype_group > 0) {
- mimetypes = nautilus_mime_types_group_get_mimetypes (mimetype_group);
- gd_tagged_entry_tag_set_label (priv->mime_types_tag,
- nautilus_mime_types_group_get_name (mimetype_group));
- gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
- GD_TAGGED_ENTRY_TAG (priv->mime_types_tag));
- } else {
- g_autofree gchar *display_name;
-
- mimetypes = g_list_append (NULL, (gpointer) mimetype);
- display_name = g_content_type_get_description (mimetype);
- gd_tagged_entry_tag_set_label (priv->mime_types_tag, display_name);
- gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
- GD_TAGGED_ENTRY_TAG (priv->mime_types_tag));
- }
- nautilus_query_set_mime_types (priv->query, mimetypes);
-
- nautilus_query_editor_changed (editor);
-
- g_list_free (mimetypes);
+ NautilusQueryEditorPrivate *priv;
+ GList *mimetypes = NULL;
+
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
+ if (!priv->query)
+ {
+ create_query (editor);
+ }
+
+ gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (priv->entry),
+ priv->mime_types_tag);
+ /* group 0 is anything */
+ if (mimetype_group == 0)
+ {
+ mimetypes = nautilus_mime_types_group_get_mimetypes (mimetype_group);
+ }
+ else if (mimetype_group > 0)
+ {
+ mimetypes = nautilus_mime_types_group_get_mimetypes (mimetype_group);
+ gd_tagged_entry_tag_set_label (priv->mime_types_tag,
+ nautilus_mime_types_group_get_name (mimetype_group));
+ gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
+ GD_TAGGED_ENTRY_TAG (priv->mime_types_tag));
+ }
+ else
+ {
+ g_autofree gchar *display_name;
+
+ mimetypes = g_list_append (NULL, (gpointer) mimetype);
+ display_name = g_content_type_get_description (mimetype);
+ gd_tagged_entry_tag_set_label (priv->mime_types_tag, display_name);
+ gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (priv->entry),
+ GD_TAGGED_ENTRY_TAG (priv->mime_types_tag));
+ }
+ nautilus_query_set_mime_types (priv->query, mimetypes);
+
+ nautilus_query_editor_changed (editor);
+
+ g_list_free (mimetypes);
}
static void
@@ -494,246 +543,262 @@ search_popover_time_type_changed_cb (NautilusSearchPopover *popover,
NautilusQuerySearchType data,
NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
- if (!priv->query)
- create_query (editor);
+ priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
+ if (!priv->query)
+ {
+ create_query (editor);
+ }
- nautilus_query_set_search_type (priv->query, data);
+ nautilus_query_set_search_type (priv->query, data);
- nautilus_query_editor_changed (editor);
+ nautilus_query_editor_changed (editor);
}
static void
entry_tag_clicked (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (editor);
+ NautilusQueryEditorPrivate *priv;
+ priv = nautilus_query_editor_get_instance_private (editor);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->dropdown_button),
- TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->dropdown_button),
+ TRUE);
}
static void
entry_tag_close_button_clicked (NautilusQueryEditor *editor,
GdTaggedEntryTag *tag)
{
- NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (editor);
-
- if (tag == priv->mime_types_tag) {
- nautilus_search_popover_reset_mime_types (NAUTILUS_SEARCH_POPOVER (priv->popover));
- } else {
- nautilus_search_popover_reset_date_range (NAUTILUS_SEARCH_POPOVER (priv->popover));
- }
+ NautilusQueryEditorPrivate *priv;
+ priv = nautilus_query_editor_get_instance_private (editor);
+
+ if (tag == priv->mime_types_tag)
+ {
+ nautilus_search_popover_reset_mime_types (NAUTILUS_SEARCH_POPOVER (priv->popover));
+ }
+ else
+ {
+ nautilus_search_popover_reset_date_range (NAUTILUS_SEARCH_POPOVER (priv->popover));
+ }
}
static void
setup_widgets (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
- GtkWidget *hbox;
- GtkWidget *vbox;
-
- priv = nautilus_query_editor_get_instance_private (editor);
-
- /* vertical box that holds the search entry and the label below */
- vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_container_add (GTK_CONTAINER (editor), vbox);
-
- /* horizontal box */
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_style_context_add_class (gtk_widget_get_style_context (hbox), "linked");
- gtk_container_add (GTK_CONTAINER (vbox), hbox);
-
- /* create the search entry */
- priv->entry = GTK_WIDGET (gd_tagged_entry_new ());
- gtk_widget_set_size_request (GTK_WIDGET (priv->entry), 400, -1);
- gtk_search_bar_connect_entry (GTK_SEARCH_BAR (editor), GTK_ENTRY (priv->entry));
-
- gtk_container_add (GTK_CONTAINER (hbox), priv->entry);
-
- priv->mime_types_tag = gd_tagged_entry_tag_new (NULL);
- priv->date_range_tag = gd_tagged_entry_tag_new (NULL);
-
- g_signal_connect_swapped (priv->entry,
- "tag-clicked",
- G_CALLBACK (entry_tag_clicked),
- editor);
- g_signal_connect_swapped (priv->entry,
- "tag-button-clicked",
- G_CALLBACK (entry_tag_close_button_clicked),
- editor);
-
- /* additional information label */
- priv->label = gtk_label_new (NULL);
- gtk_widget_set_no_show_all (priv->label, TRUE);
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->label), "dim-label");
-
- gtk_container_add (GTK_CONTAINER (vbox), priv->label);
-
- /* setup the search popover */
- priv->popover = nautilus_search_popover_new ();
-
- g_signal_connect (priv->popover, "show", (GCallback) gtk_widget_grab_focus, NULL);
- g_signal_connect_swapped (priv->popover, "closed", (GCallback) gtk_widget_grab_focus, editor);
-
- g_object_bind_property (editor, "query",
- priv->popover, "query",
- G_BINDING_DEFAULT);
-
- /* setup the filter menu button */
- priv->dropdown_button = gtk_menu_button_new ();
- gtk_menu_button_set_popover (GTK_MENU_BUTTON (priv->dropdown_button), priv->popover);
- gtk_container_add (GTK_CONTAINER (hbox), priv->dropdown_button);
-
- g_signal_connect (editor, "notify::search-mode-enabled",
- G_CALLBACK (search_mode_changed_cb), NULL);
- g_signal_connect (priv->entry, "key-press-event",
- G_CALLBACK (entry_key_press_event_cb), editor);
- g_signal_connect (priv->entry, "activate",
- G_CALLBACK (entry_activate_cb), editor);
- g_signal_connect (priv->entry, "search-changed",
- G_CALLBACK (entry_changed_cb), editor);
- g_signal_connect (priv->entry, "stop-search",
- G_CALLBACK (nautilus_query_editor_on_stop_search), editor);
- g_signal_connect (priv->popover, "date-range",
- G_CALLBACK (search_popover_date_range_changed_cb), editor);
- g_signal_connect (priv->popover, "mime-type",
- G_CALLBACK (search_popover_mime_type_changed_cb), editor);
- g_signal_connect (priv->popover, "time-type",
- G_CALLBACK (search_popover_time_type_changed_cb), editor);
-
- /* show everything */
- gtk_widget_show_all (vbox);
+ NautilusQueryEditorPrivate *priv;
+ GtkWidget *hbox;
+ GtkWidget *vbox;
+
+ priv = nautilus_query_editor_get_instance_private (editor);
+
+ /* vertical box that holds the search entry and the label below */
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ gtk_container_add (GTK_CONTAINER (editor), vbox);
+
+ /* horizontal box */
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_style_context_add_class (gtk_widget_get_style_context (hbox), "linked");
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
+
+ /* create the search entry */
+ priv->entry = GTK_WIDGET (gd_tagged_entry_new ());
+ gtk_widget_set_size_request (GTK_WIDGET (priv->entry), 400, -1);
+ gtk_search_bar_connect_entry (GTK_SEARCH_BAR (editor), GTK_ENTRY (priv->entry));
+
+ gtk_container_add (GTK_CONTAINER (hbox), priv->entry);
+
+ priv->mime_types_tag = gd_tagged_entry_tag_new (NULL);
+ priv->date_range_tag = gd_tagged_entry_tag_new (NULL);
+
+ g_signal_connect_swapped (priv->entry,
+ "tag-clicked",
+ G_CALLBACK (entry_tag_clicked),
+ editor);
+ g_signal_connect_swapped (priv->entry,
+ "tag-button-clicked",
+ G_CALLBACK (entry_tag_close_button_clicked),
+ editor);
+
+ /* additional information label */
+ priv->label = gtk_label_new (NULL);
+ gtk_widget_set_no_show_all (priv->label, TRUE);
+ gtk_style_context_add_class (gtk_widget_get_style_context (priv->label), "dim-label");
+
+ gtk_container_add (GTK_CONTAINER (vbox), priv->label);
+
+ /* setup the search popover */
+ priv->popover = nautilus_search_popover_new ();
+
+ g_signal_connect (priv->popover, "show", (GCallback) gtk_widget_grab_focus, NULL);
+ g_signal_connect_swapped (priv->popover, "closed", (GCallback) gtk_widget_grab_focus, editor);
+
+ g_object_bind_property (editor, "query",
+ priv->popover, "query",
+ G_BINDING_DEFAULT);
+
+ /* setup the filter menu button */
+ priv->dropdown_button = gtk_menu_button_new ();
+ gtk_menu_button_set_popover (GTK_MENU_BUTTON (priv->dropdown_button), priv->popover);
+ gtk_container_add (GTK_CONTAINER (hbox), priv->dropdown_button);
+
+ g_signal_connect (editor, "notify::search-mode-enabled",
+ G_CALLBACK (search_mode_changed_cb), NULL);
+ g_signal_connect (priv->entry, "key-press-event",
+ G_CALLBACK (entry_key_press_event_cb), editor);
+ g_signal_connect (priv->entry, "activate",
+ G_CALLBACK (entry_activate_cb), editor);
+ g_signal_connect (priv->entry, "search-changed",
+ G_CALLBACK (entry_changed_cb), editor);
+ g_signal_connect (priv->entry, "stop-search",
+ G_CALLBACK (nautilus_query_editor_on_stop_search), editor);
+ g_signal_connect (priv->popover, "date-range",
+ G_CALLBACK (search_popover_date_range_changed_cb), editor);
+ g_signal_connect (priv->popover, "mime-type",
+ G_CALLBACK (search_popover_mime_type_changed_cb), editor);
+ g_signal_connect (priv->popover, "time-type",
+ G_CALLBACK (search_popover_time_type_changed_cb), editor);
+
+ /* show everything */
+ gtk_widget_show_all (vbox);
}
static void
nautilus_query_editor_changed (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- if (priv->change_frozen) {
- return;
- }
+ if (priv->change_frozen)
+ {
+ return;
+ }
- g_signal_emit (editor, signals[CHANGED], 0, priv->query, TRUE);
+ g_signal_emit (editor, signals[CHANGED], 0, priv->query, TRUE);
}
NautilusQuery *
nautilus_query_editor_get_query (NautilusQueryEditor *editor)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- if (editor == NULL || priv->entry == NULL || priv->query == NULL) {
- return NULL;
- }
+ if (editor == NULL || priv->entry == NULL || priv->query == NULL)
+ {
+ return NULL;
+ }
- return g_object_ref (priv->query);
+ return g_object_ref (priv->query);
}
GtkWidget *
nautilus_query_editor_new (void)
{
- GtkWidget *editor;
+ GtkWidget *editor;
- editor = g_object_new (NAUTILUS_TYPE_QUERY_EDITOR, NULL);
- setup_widgets (NAUTILUS_QUERY_EDITOR (editor));
+ editor = g_object_new (NAUTILUS_TYPE_QUERY_EDITOR, NULL);
+ setup_widgets (NAUTILUS_QUERY_EDITOR (editor));
- return editor;
+ return editor;
}
void
nautilus_query_editor_set_location (NautilusQueryEditor *editor,
- GFile *location)
+ GFile *location)
{
- NautilusQueryEditorPrivate *priv;
- NautilusDirectory *directory;
- NautilusDirectory *base_model;
- gboolean should_notify;
-
- priv = nautilus_query_editor_get_instance_private (editor);
-
- /* The client could set us a location that is actually a search directory,
- * like what happens with the slot when updating the query editor location.
- * However here we want the real location used as a model for the search,
- * not the search directory invented uri. */
- directory = nautilus_directory_get (location);
- if (NAUTILUS_IS_SEARCH_DIRECTORY (directory)) {
- GFile *real_location;
-
- base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory));
- real_location = nautilus_directory_get_location (base_model);
-
- should_notify = g_set_object (&priv->location, real_location);
-
- g_object_unref (real_location);
- } else {
- should_notify = g_set_object (&priv->location, location);
- }
-
- if (!priv->query)
- create_query (editor);
- nautilus_query_set_location (priv->query, priv->location);
-
- update_information_label (editor);
-
- if (should_notify) {
- g_object_notify (G_OBJECT (editor), "location");
- }
-
- g_clear_object (&directory);
-
+ NautilusQueryEditorPrivate *priv;
+ NautilusDirectory *directory;
+ NautilusDirectory *base_model;
+ gboolean should_notify;
+
+ priv = nautilus_query_editor_get_instance_private (editor);
+
+ /* The client could set us a location that is actually a search directory,
+ * like what happens with the slot when updating the query editor location.
+ * However here we want the real location used as a model for the search,
+ * not the search directory invented uri. */
+ directory = nautilus_directory_get (location);
+ if (NAUTILUS_IS_SEARCH_DIRECTORY (directory))
+ {
+ GFile *real_location;
+
+ base_model = nautilus_search_directory_get_base_model (NAUTILUS_SEARCH_DIRECTORY (directory));
+ real_location = nautilus_directory_get_location (base_model);
+
+ should_notify = g_set_object (&priv->location, real_location);
+
+ g_object_unref (real_location);
+ }
+ else
+ {
+ should_notify = g_set_object (&priv->location, location);
+ }
+
+ if (!priv->query)
+ {
+ create_query (editor);
+ }
+ nautilus_query_set_location (priv->query, priv->location);
+
+ update_information_label (editor);
+
+ if (should_notify)
+ {
+ g_object_notify (G_OBJECT (editor), "location");
+ }
+
+ g_clear_object (&directory);
}
void
-nautilus_query_editor_set_query (NautilusQueryEditor *editor,
- NautilusQuery *query)
+nautilus_query_editor_set_query (NautilusQueryEditor *editor,
+ NautilusQuery *query)
{
- NautilusQueryEditorPrivate *priv;
- char *text = NULL;
- char *current_text = NULL;
+ NautilusQueryEditorPrivate *priv;
+ char *text = NULL;
+ char *current_text = NULL;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- if (query != NULL) {
- text = nautilus_query_get_text (query);
- }
+ if (query != NULL)
+ {
+ text = nautilus_query_get_text (query);
+ }
- if (!text) {
- text = g_strdup ("");
- }
+ if (!text)
+ {
+ text = g_strdup ("");
+ }
- priv->change_frozen = TRUE;
+ priv->change_frozen = TRUE;
- current_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))));
- if (!g_str_equal (current_text, text)) {
- gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
- }
- g_free (current_text);
+ current_text = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry))));
+ if (!g_str_equal (current_text, text))
+ {
+ gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
+ }
+ g_free (current_text);
- if (g_set_object (&priv->query, query)) {
- g_object_notify (G_OBJECT (editor), "query");
- }
+ if (g_set_object (&priv->query, query))
+ {
+ g_object_notify (G_OBJECT (editor), "query");
+ }
- priv->change_frozen = FALSE;
+ priv->change_frozen = FALSE;
- g_free (text);
+ g_free (text);
}
void
nautilus_query_editor_set_text (NautilusQueryEditor *editor,
const gchar *text)
{
- NautilusQueryEditorPrivate *priv;
+ NautilusQueryEditorPrivate *priv;
- priv = nautilus_query_editor_get_instance_private (editor);
+ priv = nautilus_query_editor_get_instance_private (editor);
- /* The handler of the entry will take care of everything */
- gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
+ /* The handler of the entry will take care of everything */
+ gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
}
diff --git a/src/nautilus-query.c b/src/nautilus-query.c
index 96cc3a4bb..53771ce66 100644
--- a/src/nautilus-query.c
+++ b/src/nautilus-query.c
@@ -31,55 +31,57 @@
#include "nautilus-query.h"
#include "nautilus-enum-types.h"
-struct _NautilusQuery {
- GObject parent;
-
- char *text;
- GFile *location;
- GList *mime_types;
- gboolean show_hidden;
- GPtrArray *date_range;
- NautilusQuerySearchType search_type;
- NautilusQuerySearchContent search_content;
-
- gboolean searching;
- gboolean recursive;
- char **prepared_words;
- GMutex prepared_words_mutex;
+struct _NautilusQuery
+{
+ GObject parent;
+
+ char *text;
+ GFile *location;
+ GList *mime_types;
+ gboolean show_hidden;
+ GPtrArray *date_range;
+ NautilusQuerySearchType search_type;
+ NautilusQuerySearchContent search_content;
+
+ gboolean searching;
+ gboolean recursive;
+ char **prepared_words;
+ GMutex prepared_words_mutex;
};
-static void nautilus_query_class_init (NautilusQueryClass *class);
-static void nautilus_query_init (NautilusQuery *query);
+static void nautilus_query_class_init (NautilusQueryClass *class);
+static void nautilus_query_init (NautilusQuery *query);
G_DEFINE_TYPE (NautilusQuery, nautilus_query, G_TYPE_OBJECT);
-enum {
- PROP_0,
- PROP_DATE_RANGE,
- PROP_LOCATION,
- PROP_MIMETYPES,
- PROP_RECURSIVE,
- PROP_SEARCH_TYPE,
- PROP_SEARCHING,
- PROP_SHOW_HIDDEN,
- PROP_TEXT,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_DATE_RANGE,
+ PROP_LOCATION,
+ PROP_MIMETYPES,
+ PROP_RECURSIVE,
+ PROP_SEARCH_TYPE,
+ PROP_SEARCHING,
+ PROP_SHOW_HIDDEN,
+ PROP_TEXT,
+ LAST_PROP
};
static void
finalize (GObject *object)
{
- NautilusQuery *query;
+ NautilusQuery *query;
- query = NAUTILUS_QUERY (object);
+ query = NAUTILUS_QUERY (object);
- g_free (query->text);
- g_strfreev (query->prepared_words);
- g_clear_object (&query->location);
- g_clear_pointer (&query->date_range, g_ptr_array_unref);
- g_mutex_clear (&query->prepared_words_mutex);
+ g_free (query->text);
+ g_strfreev (query->prepared_words);
+ g_clear_object (&query->location);
+ g_clear_pointer (&query->date_range, g_ptr_array_unref);
+ g_mutex_clear (&query->prepared_words_mutex);
- G_OBJECT_CLASS (nautilus_query_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_query_parent_class)->finalize (object);
}
static void
@@ -88,44 +90,61 @@ nautilus_query_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusQuery *self = NAUTILUS_QUERY (object);
+ NautilusQuery *self = NAUTILUS_QUERY (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_DATE_RANGE:
- g_value_set_pointer (value, self->date_range);
- break;
+ {
+ g_value_set_pointer (value, self->date_range);
+ }
+ break;
case PROP_LOCATION:
- g_value_set_object (value, self->location);
- break;
+ {
+ g_value_set_object (value, self->location);
+ }
+ break;
case PROP_MIMETYPES:
- g_value_set_pointer (value, self->mime_types);
- break;
+ {
+ g_value_set_pointer (value, self->mime_types);
+ }
+ break;
case PROP_RECURSIVE:
- g_value_set_boolean (value, self->recursive);
- break;
+ {
+ g_value_set_boolean (value, self->recursive);
+ }
+ break;
case PROP_SEARCH_TYPE:
- g_value_set_enum (value, self->search_type);
- break;
+ {
+ g_value_set_enum (value, self->search_type);
+ }
+ break;
case PROP_SEARCHING:
- g_value_set_boolean (value, self->searching);
- break;
+ {
+ g_value_set_boolean (value, self->searching);
+ }
+ break;
case PROP_SHOW_HIDDEN:
- g_value_set_boolean (value, self->show_hidden);
- break;
+ {
+ g_value_set_boolean (value, self->show_hidden);
+ }
+ break;
case PROP_TEXT:
- g_value_set_string (value, self->text);
- break;
+ {
+ g_value_set_string (value, self->text);
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
@@ -134,382 +153,413 @@ nautilus_query_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- NautilusQuery *self = NAUTILUS_QUERY (object);
+ NautilusQuery *self = NAUTILUS_QUERY (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_DATE_RANGE:
- nautilus_query_set_date_range (self, g_value_get_pointer (value));
- break;
+ {
+ nautilus_query_set_date_range (self, g_value_get_pointer (value));
+ }
+ break;
case PROP_LOCATION:
- nautilus_query_set_location (self, g_value_get_object (value));
- break;
+ {
+ nautilus_query_set_location (self, g_value_get_object (value));
+ }
+ break;
case PROP_MIMETYPES:
- nautilus_query_set_mime_types (self, g_value_get_pointer (value));
- break;
+ {
+ nautilus_query_set_mime_types (self, g_value_get_pointer (value));
+ }
+ break;
case PROP_RECURSIVE:
- nautilus_query_set_recursive (self, g_value_get_boolean (value));
- break;
+ {
+ nautilus_query_set_recursive (self, g_value_get_boolean (value));
+ }
+ break;
case PROP_SEARCH_TYPE:
- nautilus_query_set_search_type (self, g_value_get_enum (value));
- break;
+ {
+ nautilus_query_set_search_type (self, g_value_get_enum (value));
+ }
+ break;
case PROP_SEARCHING:
- nautilus_query_set_searching (self, g_value_get_boolean (value));
- break;
+ {
+ nautilus_query_set_searching (self, g_value_get_boolean (value));
+ }
+ break;
+
case PROP_SHOW_HIDDEN:
- nautilus_query_set_show_hidden_files (self, g_value_get_boolean (value));
- break;
+ {
+ nautilus_query_set_show_hidden_files (self, g_value_get_boolean (value));
+ }
+ break;
case PROP_TEXT:
- nautilus_query_set_text (self, g_value_get_string (value));
- break;
+ {
+ nautilus_query_set_text (self, g_value_get_string (value));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
nautilus_query_class_init (NautilusQueryClass *class)
{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->finalize = finalize;
- gobject_class->get_property = nautilus_query_get_property;
- gobject_class->set_property = nautilus_query_set_property;
-
- /**
- * NautilusQuery::date-range:
- *
- * The date range of the query.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_DATE_RANGE,
- g_param_spec_pointer ("date-range",
- "Date range of the query",
- "The range date of the query",
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::location:
- *
- * The location of the query.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_LOCATION,
- g_param_spec_object ("location",
- "Location of the query",
- "The location of the query",
- G_TYPE_FILE,
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::mimetypes:
- *
- * MIME types the query holds.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_MIMETYPES,
- g_param_spec_pointer ("mimetypes",
- "MIME types of the query",
- "The MIME types of the query",
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::recursive:
- *
- * Whether the query is being performed on subdirectories or not.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_RECURSIVE,
- g_param_spec_boolean ("recursive",
- "Whether the query is being performed on subdirectories",
- "Whether the query is being performed on subdirectories or not",
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::search-type:
- *
- * The search type of the query.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_SEARCH_TYPE,
- g_param_spec_enum ("search-type",
- "Type of the query",
- "The type of the query",
- NAUTILUS_TYPE_QUERY_SEARCH_TYPE,
- NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED,
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::searching:
- *
- * Whether the query is being performed or not.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_SEARCHING,
- g_param_spec_boolean ("searching",
- "Whether the query is being performed",
- "Whether the query is being performed or not",
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::show-hidden:
- *
- * Whether the search should include hidden files.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_SHOW_HIDDEN,
- g_param_spec_boolean ("show-hidden",
- "Show hidden files",
- "Whether the search should show hidden files",
- FALSE,
- G_PARAM_READWRITE));
-
- /**
- * NautilusQuery::text:
- *
- * The search string.
- *
- */
- g_object_class_install_property (gobject_class,
- PROP_TEXT,
- g_param_spec_string ("text",
- "Text of the search",
- "The text string of the search",
- NULL,
- G_PARAM_READWRITE));
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->finalize = finalize;
+ gobject_class->get_property = nautilus_query_get_property;
+ gobject_class->set_property = nautilus_query_set_property;
+
+ /**
+ * NautilusQuery::date-range:
+ *
+ * The date range of the query.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_DATE_RANGE,
+ g_param_spec_pointer ("date-range",
+ "Date range of the query",
+ "The range date of the query",
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::location:
+ *
+ * The location of the query.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_LOCATION,
+ g_param_spec_object ("location",
+ "Location of the query",
+ "The location of the query",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::mimetypes:
+ *
+ * MIME types the query holds.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MIMETYPES,
+ g_param_spec_pointer ("mimetypes",
+ "MIME types of the query",
+ "The MIME types of the query",
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::recursive:
+ *
+ * Whether the query is being performed on subdirectories or not.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_RECURSIVE,
+ g_param_spec_boolean ("recursive",
+ "Whether the query is being performed on subdirectories",
+ "Whether the query is being performed on subdirectories or not",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::search-type:
+ *
+ * The search type of the query.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_SEARCH_TYPE,
+ g_param_spec_enum ("search-type",
+ "Type of the query",
+ "The type of the query",
+ NAUTILUS_TYPE_QUERY_SEARCH_TYPE,
+ NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED,
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::searching:
+ *
+ * Whether the query is being performed or not.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_SEARCHING,
+ g_param_spec_boolean ("searching",
+ "Whether the query is being performed",
+ "Whether the query is being performed or not",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::show-hidden:
+ *
+ * Whether the search should include hidden files.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_SHOW_HIDDEN,
+ g_param_spec_boolean ("show-hidden",
+ "Show hidden files",
+ "Whether the search should show hidden files",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ /**
+ * NautilusQuery::text:
+ *
+ * The search string.
+ *
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_TEXT,
+ g_param_spec_string ("text",
+ "Text of the search",
+ "The text string of the search",
+ NULL,
+ G_PARAM_READWRITE));
}
static void
nautilus_query_init (NautilusQuery *query)
{
- query->show_hidden = TRUE;
- query->location = g_file_new_for_path (g_get_home_dir ());
- query->search_type = g_settings_get_enum (nautilus_preferences, "search-filter-time-type");
- query->search_content = NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE;
- g_mutex_init (&query->prepared_words_mutex);
+ query->show_hidden = TRUE;
+ query->location = g_file_new_for_path (g_get_home_dir ());
+ query->search_type = g_settings_get_enum (nautilus_preferences, "search-filter-time-type");
+ query->search_content = NAUTILUS_QUERY_SEARCH_CONTENT_SIMPLE;
+ g_mutex_init (&query->prepared_words_mutex);
}
static gchar *
prepare_string_for_compare (const gchar *string)
{
- gchar *normalized, *res;
+ gchar *normalized, *res;
- normalized = g_utf8_normalize (string, -1, G_NORMALIZE_NFD);
- res = g_utf8_strdown (normalized, -1);
- g_free (normalized);
+ normalized = g_utf8_normalize (string, -1, G_NORMALIZE_NFD);
+ res = g_utf8_strdown (normalized, -1);
+ g_free (normalized);
- return res;
+ return res;
}
gdouble
nautilus_query_matches_string (NautilusQuery *query,
- const gchar *string)
+ const gchar *string)
{
- gchar *prepared_string, *ptr;
- gboolean found;
- gdouble retval;
- gint idx, nonexact_malus;
-
- if (!query->text) {
- return -1;
- }
-
- g_mutex_lock (&query->prepared_words_mutex);
- if (!query->prepared_words) {
- prepared_string = prepare_string_for_compare (query->text);
- query->prepared_words = g_strsplit (prepared_string, " ", -1);
- g_free (prepared_string);
- }
-
- prepared_string = prepare_string_for_compare (string);
- found = TRUE;
- ptr = NULL;
- nonexact_malus = 0;
-
- for (idx = 0; query->prepared_words[idx] != NULL; idx++) {
- if ((ptr = strstr (prepared_string, query->prepared_words[idx])) == NULL) {
- found = FALSE;
- break;
- }
-
- nonexact_malus += strlen (ptr) - strlen (query->prepared_words[idx]);
- }
- g_mutex_unlock (&query->prepared_words_mutex);
-
- if (!found) {
- g_free (prepared_string);
- return -1;
- }
-
- retval = MAX (10.0, 50.0 - (gdouble) (ptr - prepared_string) - nonexact_malus);
- g_free (prepared_string);
-
- return retval;
+ gchar *prepared_string, *ptr;
+ gboolean found;
+ gdouble retval;
+ gint idx, nonexact_malus;
+
+ if (!query->text)
+ {
+ return -1;
+ }
+
+ g_mutex_lock (&query->prepared_words_mutex);
+ if (!query->prepared_words)
+ {
+ prepared_string = prepare_string_for_compare (query->text);
+ query->prepared_words = g_strsplit (prepared_string, " ", -1);
+ g_free (prepared_string);
+ }
+
+ prepared_string = prepare_string_for_compare (string);
+ found = TRUE;
+ ptr = NULL;
+ nonexact_malus = 0;
+
+ for (idx = 0; query->prepared_words[idx] != NULL; idx++)
+ {
+ if ((ptr = strstr (prepared_string, query->prepared_words[idx])) == NULL)
+ {
+ found = FALSE;
+ break;
+ }
+
+ nonexact_malus += strlen (ptr) - strlen (query->prepared_words[idx]);
+ }
+ g_mutex_unlock (&query->prepared_words_mutex);
+
+ if (!found)
+ {
+ g_free (prepared_string);
+ return -1;
+ }
+
+ retval = MAX (10.0, 50.0 - (gdouble) (ptr - prepared_string) - nonexact_malus);
+ g_free (prepared_string);
+
+ return retval;
}
NautilusQuery *
nautilus_query_new (void)
{
- return g_object_new (NAUTILUS_TYPE_QUERY, NULL);
+ return g_object_new (NAUTILUS_TYPE_QUERY, NULL);
}
char *
nautilus_query_get_text (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
- return g_strdup (query->text);
+ return g_strdup (query->text);
}
-void
-nautilus_query_set_text (NautilusQuery *query, const char *text)
+void
+nautilus_query_set_text (NautilusQuery *query,
+ const char *text)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- g_free (query->text);
- query->text = g_strstrip (g_strdup (text));
+ g_free (query->text);
+ query->text = g_strstrip (g_strdup (text));
- g_mutex_lock (&query->prepared_words_mutex);
- g_strfreev (query->prepared_words);
- query->prepared_words = NULL;
- g_mutex_unlock (&query->prepared_words_mutex);
+ g_mutex_lock (&query->prepared_words_mutex);
+ g_strfreev (query->prepared_words);
+ query->prepared_words = NULL;
+ g_mutex_unlock (&query->prepared_words_mutex);
- g_object_notify (G_OBJECT (query), "text");
+ g_object_notify (G_OBJECT (query), "text");
}
-GFile*
+GFile *
nautilus_query_get_location (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
- return g_object_ref (query->location);
+ return g_object_ref (query->location);
}
void
nautilus_query_set_location (NautilusQuery *query,
GFile *location)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
-
- if (g_set_object (&query->location, location)) {
- g_object_notify (G_OBJECT (query), "location");
- }
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ if (g_set_object (&query->location, location))
+ {
+ g_object_notify (G_OBJECT (query), "location");
+ }
}
GList *
nautilus_query_get_mime_types (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
- return g_list_copy_deep (query->mime_types, (GCopyFunc) g_strdup, NULL);
+ return g_list_copy_deep (query->mime_types, (GCopyFunc) g_strdup, NULL);
}
void
-nautilus_query_set_mime_types (NautilusQuery *query, GList *mime_types)
+nautilus_query_set_mime_types (NautilusQuery *query,
+ GList *mime_types)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- g_list_free_full (query->mime_types, g_free);
- query->mime_types = g_list_copy_deep (mime_types, (GCopyFunc) g_strdup, NULL);
+ g_list_free_full (query->mime_types, g_free);
+ query->mime_types = g_list_copy_deep (mime_types, (GCopyFunc) g_strdup, NULL);
- g_object_notify (G_OBJECT (query), "mimetypes");
+ g_object_notify (G_OBJECT (query), "mimetypes");
}
void
-nautilus_query_add_mime_type (NautilusQuery *query, const char *mime_type)
+nautilus_query_add_mime_type (NautilusQuery *query,
+ const char *mime_type)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- query->mime_types = g_list_append (query->mime_types, g_strdup (mime_type));
+ query->mime_types = g_list_append (query->mime_types, g_strdup (mime_type));
- g_object_notify (G_OBJECT (query), "mimetypes");
+ g_object_notify (G_OBJECT (query), "mimetypes");
}
gboolean
nautilus_query_get_show_hidden_files (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
- return query->show_hidden;
+ return query->show_hidden;
}
void
-nautilus_query_set_show_hidden_files (NautilusQuery *query, gboolean show_hidden)
+nautilus_query_set_show_hidden_files (NautilusQuery *query,
+ gboolean show_hidden)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- if (query->show_hidden != show_hidden) {
- query->show_hidden = show_hidden;
- g_object_notify (G_OBJECT (query), "show-hidden");
- }
+ if (query->show_hidden != show_hidden)
+ {
+ query->show_hidden = show_hidden;
+ g_object_notify (G_OBJECT (query), "show-hidden");
+ }
}
char *
nautilus_query_to_readable_string (NautilusQuery *query)
{
- if (!query || !query->text || query->text[0] == '\0') {
- return g_strdup (_("Search"));
- }
+ if (!query || !query->text || query->text[0] == '\0')
+ {
+ return g_strdup (_("Search"));
+ }
- return g_strdup_printf (_("Search for “%s”"), query->text);
+ return g_strdup_printf (_("Search for “%s”"), query->text);
}
NautilusQuerySearchContent
nautilus_query_get_search_content (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), -1);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), -1);
- return query->search_content;
+ return query->search_content;
}
void
nautilus_query_set_search_content (NautilusQuery *query,
NautilusQuerySearchContent content)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- if (query->search_content != content) {
- query->search_content = content;
- g_object_notify (G_OBJECT (query), "search-type");
- }
+ if (query->search_content != content)
+ {
+ query->search_content = content;
+ g_object_notify (G_OBJECT (query), "search-type");
+ }
}
NautilusQuerySearchType
nautilus_query_get_search_type (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), -1);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), -1);
- return query->search_type;
+ return query->search_type;
}
void
nautilus_query_set_search_type (NautilusQuery *query,
NautilusQuerySearchType type)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- if (query->search_type != type) {
- query->search_type = type;
- g_object_notify (G_OBJECT (query), "search-type");
- }
+ if (query->search_type != type)
+ {
+ query->search_type = type;
+ g_object_notify (G_OBJECT (query), "search-type");
+ }
}
/**
@@ -521,94 +571,100 @@ nautilus_query_set_search_type (NautilusQuery *query,
*
* Returns: (transfer full): the #GptrArray composed of #GDateTime representing the date range.
*/
-GPtrArray*
+GPtrArray *
nautilus_query_get_date_range (NautilusQuery *query)
{
- static GMutex mutex;
+ static GMutex mutex;
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), NULL);
- g_mutex_lock (&mutex);
- if (query->date_range)
- g_ptr_array_ref (query->date_range);
- g_mutex_unlock (&mutex);
+ g_mutex_lock (&mutex);
+ if (query->date_range)
+ {
+ g_ptr_array_ref (query->date_range);
+ }
+ g_mutex_unlock (&mutex);
- return query->date_range;
+ return query->date_range;
}
void
nautilus_query_set_date_range (NautilusQuery *query,
GPtrArray *date_range)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- g_clear_pointer (&query->date_range, g_ptr_array_unref);
- if (date_range) {
- query->date_range = g_ptr_array_ref (date_range);
- }
+ g_clear_pointer (&query->date_range, g_ptr_array_unref);
+ if (date_range)
+ {
+ query->date_range = g_ptr_array_ref (date_range);
+ }
- g_object_notify (G_OBJECT (query), "date-range");
+ g_object_notify (G_OBJECT (query), "date-range");
}
gboolean
nautilus_query_get_searching (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
- return query->searching;
+ return query->searching;
}
void
nautilus_query_set_searching (NautilusQuery *query,
gboolean searching)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- searching = !!searching;
+ searching = !!searching;
- if (query->searching != searching) {
- query->searching = searching;
+ if (query->searching != searching)
+ {
+ query->searching = searching;
- g_object_notify (G_OBJECT (query), "searching");
- }
+ g_object_notify (G_OBJECT (query), "searching");
+ }
}
gboolean
nautilus_query_get_recursive (NautilusQuery *query)
{
- g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_QUERY (query), FALSE);
- return query->recursive;
+ return query->recursive;
}
void
nautilus_query_set_recursive (NautilusQuery *query,
gboolean recursive)
{
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- recursive = !!recursive;
+ recursive = !!recursive;
- if (query->recursive != recursive) {
- query->recursive = recursive;
+ if (query->recursive != recursive)
+ {
+ query->recursive = recursive;
- g_object_notify (G_OBJECT (query), "recursive");
- }
+ g_object_notify (G_OBJECT (query), "recursive");
+ }
}
gboolean
nautilus_query_is_empty (NautilusQuery *query)
{
- if (!query) {
- return TRUE;
-
- }
+ if (!query)
+ {
+ return TRUE;
+ }
- if (!query->date_range &&
- (!query->text || (query->text && query->text[0] == '\0')) &&
- !query->mime_types) {
- return TRUE;
+ if (!query->date_range &&
+ (!query->text || (query->text && query->text[0] == '\0')) &&
+ !query->mime_types)
+ {
+ return TRUE;
}
- return FALSE;
+ return FALSE;
}
diff --git a/src/nautilus-recent.c b/src/nautilus-recent.c
index 1e23a58dc..ab50fef8f 100644
--- a/src/nautilus-recent.c
+++ b/src/nautilus-recent.c
@@ -12,7 +12,7 @@
* 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, see <http://www.gnu.org/licenses/>.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
@@ -25,56 +25,63 @@
static GtkRecentManager *
nautilus_recent_get_manager (void)
{
- static GtkRecentManager *manager = NULL;
+ static GtkRecentManager *manager = NULL;
- if (manager == NULL) {
- manager = gtk_recent_manager_get_default ();
- }
+ if (manager == NULL)
+ {
+ manager = gtk_recent_manager_get_default ();
+ }
- return manager;
+ return manager;
}
void
nautilus_recent_add_file (NautilusFile *file,
- GAppInfo *application)
+ GAppInfo *application)
{
- GtkRecentData recent_data;
- char *uri;
-
- uri = nautilus_file_get_activation_uri (file);
- if (uri == NULL) {
- uri = nautilus_file_get_uri (file);
- }
-
- /* do not add trash:// etc */
- if (eel_uri_is_trash (uri) ||
- eel_uri_is_search (uri) ||
- eel_uri_is_recent (uri) ||
- eel_uri_is_desktop (uri)) {
- g_free (uri);
- return;
- }
-
- recent_data.display_name = NULL;
- recent_data.description = NULL;
-
- recent_data.mime_type = nautilus_file_get_mime_type (file);
- recent_data.app_name = g_strdup (g_get_application_name ());
-
- if (application != NULL)
- recent_data.app_exec = g_strdup (g_app_info_get_commandline (application));
- else
- recent_data.app_exec = g_strdup (DEFAULT_APP_EXEC);
-
- recent_data.groups = NULL;
- recent_data.is_private = FALSE;
-
- gtk_recent_manager_add_full (nautilus_recent_get_manager (),
- uri, &recent_data);
-
- g_free (recent_data.mime_type);
- g_free (recent_data.app_name);
- g_free (recent_data.app_exec);
-
- g_free (uri);
+ GtkRecentData recent_data;
+ char *uri;
+
+ uri = nautilus_file_get_activation_uri (file);
+ if (uri == NULL)
+ {
+ uri = nautilus_file_get_uri (file);
+ }
+
+ /* do not add trash:// etc */
+ if (eel_uri_is_trash (uri) ||
+ eel_uri_is_search (uri) ||
+ eel_uri_is_recent (uri) ||
+ eel_uri_is_desktop (uri))
+ {
+ g_free (uri);
+ return;
+ }
+
+ recent_data.display_name = NULL;
+ recent_data.description = NULL;
+
+ recent_data.mime_type = nautilus_file_get_mime_type (file);
+ recent_data.app_name = g_strdup (g_get_application_name ());
+
+ if (application != NULL)
+ {
+ recent_data.app_exec = g_strdup (g_app_info_get_commandline (application));
+ }
+ else
+ {
+ recent_data.app_exec = g_strdup (DEFAULT_APP_EXEC);
+ }
+
+ recent_data.groups = NULL;
+ recent_data.is_private = FALSE;
+
+ gtk_recent_manager_add_full (nautilus_recent_get_manager (),
+ uri, &recent_data);
+
+ g_free (recent_data.mime_type);
+ g_free (recent_data.app_name);
+ g_free (recent_data.app_exec);
+
+ g_free (uri);
}
diff --git a/src/nautilus-rename-file-popover-controller.c b/src/nautilus-rename-file-popover-controller.c
index 7dfaad6d9..8475f6a7c 100644
--- a/src/nautilus-rename-file-popover-controller.c
+++ b/src/nautilus-rename-file-popover-controller.c
@@ -11,15 +11,16 @@
#define RENAME_ENTRY_MIN_CHARS 20
#define RENAME_ENTRY_MAX_CHARS 35
-struct _NautilusRenameFilePopoverController {
- NautilusFileNameWidgetController parent_instance;
+struct _NautilusRenameFilePopoverController
+{
+ NautilusFileNameWidgetController parent_instance;
- NautilusFile *target_file;
- gboolean target_is_folder;
+ NautilusFile *target_file;
+ gboolean target_is_folder;
- GtkWidget *rename_file_popover;
+ GtkWidget *rename_file_popover;
- gint closed_handler_id;
+ gint closed_handler_id;
};
G_DEFINE_TYPE (NautilusRenameFilePopoverController, nautilus_rename_file_popover_controller, NAUTILUS_TYPE_FILE_NAME_WIDGET_CONTROLLER)
@@ -28,16 +29,16 @@ static void
rename_file_popover_controller_on_closed (GtkPopover *popover,
gpointer user_data)
{
- NautilusRenameFilePopoverController *controller;
+ NautilusRenameFilePopoverController *controller;
- controller = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (user_data);
+ controller = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (user_data);
- g_signal_handler_disconnect (controller->rename_file_popover,
- controller->closed_handler_id);
- controller->closed_handler_id = 0;
- controller->rename_file_popover = NULL;
+ g_signal_handler_disconnect (controller->rename_file_popover,
+ controller->closed_handler_id);
+ controller->closed_handler_id = 0;
+ controller->rename_file_popover = NULL;
- g_signal_emit_by_name (controller, "cancelled");
+ g_signal_emit_by_name (controller, "cancelled");
}
static gboolean
@@ -45,52 +46,64 @@ nautilus_rename_file_popover_controller_name_is_valid (NautilusFileNameWidgetCon
gchar *name,
gchar **error_message)
{
- NautilusRenameFilePopoverController *self;
+ NautilusRenameFilePopoverController *self;
- self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (controller);
+ self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (controller);
- if (strlen (name) == 0) {
- return FALSE;
- }
+ if (strlen (name) == 0)
+ {
+ return FALSE;
+ }
- if (strstr (name, "/") != NULL) {
- if (self->target_is_folder) {
- *error_message = _("Folder names cannot contain “/”.");
- }
- else {
- *error_message = _("File names cannot contain “/”.");
- }
- } else if (strcmp (name, ".") == 0){
- if (self->target_is_folder) {
- *error_message = _("A folder cannot be called “.”.");
- }
- else {
- *error_message = _("A file cannot be called “.”.");
- }
- } else if (strcmp (name, "..") == 0){
- if (self->target_is_folder) {
- *error_message = _("A folder cannot be called “..”.");
- }
- else {
- *error_message = _("A file cannot be called “..”.");
- }
+ if (strstr (name, "/") != NULL)
+ {
+ if (self->target_is_folder)
+ {
+ *error_message = _("Folder names cannot contain “/”.");
+ }
+ else
+ {
+ *error_message = _("File names cannot contain “/”.");
+ }
+ }
+ else if (strcmp (name, ".") == 0)
+ {
+ if (self->target_is_folder)
+ {
+ *error_message = _("A folder cannot be called “.”.");
+ }
+ else
+ {
+ *error_message = _("A file cannot be called “.”.");
+ }
+ }
+ else if (strcmp (name, "..") == 0)
+ {
+ if (self->target_is_folder)
+ {
+ *error_message = _("A folder cannot be called “..”.");
}
+ else
+ {
+ *error_message = _("A file cannot be called “..”.");
+ }
+ }
- return *error_message == NULL;
+ return *error_message == NULL;
}
static gboolean
nautilus_rename_file_popover_controller_ignore_existing_file (NautilusFileNameWidgetController *controller,
NautilusFile *existing_file)
{
- NautilusRenameFilePopoverController *self;
- g_autofree gchar *display_name;
+ NautilusRenameFilePopoverController *self;
+ g_autofree gchar *display_name;
- self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (controller);
+ self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (controller);
- display_name = nautilus_file_get_display_name (existing_file);
+ display_name = nautilus_file_get_display_name (existing_file);
- return nautilus_file_compare_display_name (self->target_file, display_name) == 0;
+ return nautilus_file_compare_display_name (self->target_file, display_name) == 0;
}
NautilusRenameFilePopoverController *
@@ -98,129 +111,133 @@ nautilus_rename_file_popover_controller_new (NautilusFile *target_file,
GdkRectangle *pointing_to,
GtkWidget *relative_to)
{
- NautilusRenameFilePopoverController *self;
- g_autoptr (GtkBuilder) builder;
- GtkWidget *rename_file_popover;
- GtkWidget *error_revealer;
- GtkWidget *error_label;
- GtkWidget *name_entry;
- GtkWidget *activate_button;
- GtkWidget *name_label;
- NautilusDirectory *containing_directory;
- gint start_offset;
- gint end_offset;
- gint n_chars;
-
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-rename-file-popover.ui");
- rename_file_popover = GTK_WIDGET (gtk_builder_get_object (builder, "rename_file_popover"));
- error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
- error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
- name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
- activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "rename_button"));
- name_label = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
-
- if (!nautilus_file_is_self_owned (target_file)) {
- NautilusFile *parent_location;
-
- parent_location = nautilus_file_get_parent (target_file);
- containing_directory = nautilus_directory_get_for_file (parent_location);
-
- nautilus_file_unref (parent_location);
- } else {
- containing_directory = nautilus_directory_get_for_file (target_file);
- }
-
- self = g_object_new (NAUTILUS_TYPE_RENAME_FILE_POPOVER_CONTROLLER,
- "error-revealer", error_revealer,
- "error-label", error_label,
- "name-entry", name_entry,
- "activate-button", activate_button,
- "containing-directory", containing_directory, NULL);
-
- self->target_is_folder = nautilus_file_is_directory (target_file);
- self->target_file = nautilus_file_ref (target_file);
-
- self->rename_file_popover = rename_file_popover;
-
- self->closed_handler_id = g_signal_connect (rename_file_popover,
- "closed",
- (GCallback)rename_file_popover_controller_on_closed,
- self);
- g_signal_connect (rename_file_popover,
- "unmap",
- (GCallback)gtk_widget_destroy,
- NULL);
-
- gtk_label_set_text (GTK_LABEL (name_label),
- self->target_is_folder ? _("Folder name") :
- _("File name"));
-
- gtk_entry_set_text (GTK_ENTRY (name_entry),
- nautilus_file_get_display_name (target_file));
-
- gtk_popover_set_default_widget (GTK_POPOVER (rename_file_popover), name_entry);
- gtk_popover_set_pointing_to (GTK_POPOVER (rename_file_popover), pointing_to);
- gtk_popover_set_relative_to (GTK_POPOVER (rename_file_popover), relative_to);
-
- gtk_widget_show (rename_file_popover);
-
- /* Select the name part withouth the file extension */
- eel_filename_get_rename_region (nautilus_file_get_display_name (target_file),
- &start_offset, &end_offset);
- n_chars = g_utf8_strlen (nautilus_file_get_display_name (target_file), -1);
- gtk_entry_set_width_chars (GTK_ENTRY (name_entry),
- MIN (MAX (n_chars, RENAME_ENTRY_MIN_CHARS), RENAME_ENTRY_MAX_CHARS));
- gtk_editable_select_region (GTK_EDITABLE (name_entry), start_offset, end_offset);
-
- nautilus_directory_unref (containing_directory);
-
- return self;
+ NautilusRenameFilePopoverController *self;
+ g_autoptr (GtkBuilder) builder;
+ GtkWidget *rename_file_popover;
+ GtkWidget *error_revealer;
+ GtkWidget *error_label;
+ GtkWidget *name_entry;
+ GtkWidget *activate_button;
+ GtkWidget *name_label;
+ NautilusDirectory *containing_directory;
+ gint start_offset;
+ gint end_offset;
+ gint n_chars;
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-rename-file-popover.ui");
+ rename_file_popover = GTK_WIDGET (gtk_builder_get_object (builder, "rename_file_popover"));
+ error_revealer = GTK_WIDGET (gtk_builder_get_object (builder, "error_revealer"));
+ error_label = GTK_WIDGET (gtk_builder_get_object (builder, "error_label"));
+ name_entry = GTK_WIDGET (gtk_builder_get_object (builder, "name_entry"));
+ activate_button = GTK_WIDGET (gtk_builder_get_object (builder, "rename_button"));
+ name_label = GTK_WIDGET (gtk_builder_get_object (builder, "name_label"));
+
+ if (!nautilus_file_is_self_owned (target_file))
+ {
+ NautilusFile *parent_location;
+
+ parent_location = nautilus_file_get_parent (target_file);
+ containing_directory = nautilus_directory_get_for_file (parent_location);
+
+ nautilus_file_unref (parent_location);
+ }
+ else
+ {
+ containing_directory = nautilus_directory_get_for_file (target_file);
+ }
+
+ self = g_object_new (NAUTILUS_TYPE_RENAME_FILE_POPOVER_CONTROLLER,
+ "error-revealer", error_revealer,
+ "error-label", error_label,
+ "name-entry", name_entry,
+ "activate-button", activate_button,
+ "containing-directory", containing_directory, NULL);
+
+ self->target_is_folder = nautilus_file_is_directory (target_file);
+ self->target_file = nautilus_file_ref (target_file);
+
+ self->rename_file_popover = rename_file_popover;
+
+ self->closed_handler_id = g_signal_connect (rename_file_popover,
+ "closed",
+ (GCallback) rename_file_popover_controller_on_closed,
+ self);
+ g_signal_connect (rename_file_popover,
+ "unmap",
+ (GCallback) gtk_widget_destroy,
+ NULL);
+
+ gtk_label_set_text (GTK_LABEL (name_label),
+ self->target_is_folder ? _("Folder name") :
+ _("File name"));
+
+ gtk_entry_set_text (GTK_ENTRY (name_entry),
+ nautilus_file_get_display_name (target_file));
+
+ gtk_popover_set_default_widget (GTK_POPOVER (rename_file_popover), name_entry);
+ gtk_popover_set_pointing_to (GTK_POPOVER (rename_file_popover), pointing_to);
+ gtk_popover_set_relative_to (GTK_POPOVER (rename_file_popover), relative_to);
+
+ gtk_widget_show (rename_file_popover);
+
+ /* Select the name part withouth the file extension */
+ eel_filename_get_rename_region (nautilus_file_get_display_name (target_file),
+ &start_offset, &end_offset);
+ n_chars = g_utf8_strlen (nautilus_file_get_display_name (target_file), -1);
+ gtk_entry_set_width_chars (GTK_ENTRY (name_entry),
+ MIN (MAX (n_chars, RENAME_ENTRY_MIN_CHARS), RENAME_ENTRY_MAX_CHARS));
+ gtk_editable_select_region (GTK_EDITABLE (name_entry), start_offset, end_offset);
+
+ nautilus_directory_unref (containing_directory);
+
+ return self;
}
NautilusFile *
nautilus_rename_file_popover_controller_get_target_file (NautilusRenameFilePopoverController *self)
{
- g_return_val_if_fail (NAUTILUS_IS_RENAME_FILE_POPOVER_CONTROLLER (self), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_RENAME_FILE_POPOVER_CONTROLLER (self), NULL);
- return self->target_file;
+ return self->target_file;
}
static void
nautilus_rename_file_popover_controller_init (NautilusRenameFilePopoverController *self)
{
-
}
static void
nautilus_rename_file_popover_controller_finalize (GObject *object)
{
- NautilusRenameFilePopoverController *self;
-
- self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (object);
-
- if (self->rename_file_popover) {
- if (self->closed_handler_id) {
- g_signal_handler_disconnect (self->rename_file_popover,
- self->closed_handler_id);
- self->closed_handler_id = 0;
- }
- gtk_widget_hide (self->rename_file_popover);
- self->rename_file_popover = NULL;
+ NautilusRenameFilePopoverController *self;
+
+ self = NAUTILUS_RENAME_FILE_POPOVER_CONTROLLER (object);
+
+ if (self->rename_file_popover)
+ {
+ if (self->closed_handler_id)
+ {
+ g_signal_handler_disconnect (self->rename_file_popover,
+ self->closed_handler_id);
+ self->closed_handler_id = 0;
}
+ gtk_widget_hide (self->rename_file_popover);
+ self->rename_file_popover = NULL;
+ }
- nautilus_file_unref (self->target_file);
+ nautilus_file_unref (self->target_file);
- G_OBJECT_CLASS (nautilus_rename_file_popover_controller_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_rename_file_popover_controller_parent_class)->finalize (object);
}
static void
nautilus_rename_file_popover_controller_class_init (NautilusRenameFilePopoverControllerClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ NautilusFileNameWidgetControllerClass *parent_class = NAUTILUS_FILE_NAME_WIDGET_CONTROLLER_CLASS (klass);
- object_class->finalize = nautilus_rename_file_popover_controller_finalize;
+ object_class->finalize = nautilus_rename_file_popover_controller_finalize;
- parent_class->name_is_valid = nautilus_rename_file_popover_controller_name_is_valid;
- parent_class->ignore_existing_file = nautilus_rename_file_popover_controller_ignore_existing_file;
+ parent_class->name_is_valid = nautilus_rename_file_popover_controller_name_is_valid;
+ parent_class->ignore_existing_file = nautilus_rename_file_popover_controller_ignore_existing_file;
}
diff --git a/src/nautilus-search-directory-file.c b/src/nautilus-search-directory-file.c
index 177494509..ffeffe08a 100644
--- a/src/nautilus-search-directory-file.c
+++ b/src/nautilus-search-directory-file.c
@@ -1,24 +1,24 @@
/*
- nautilus-search-directory-file.c: Subclass of NautilusFile to help implement the
- searches
-
- Copyright (C) 2005 Novell, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Anders Carlsson <andersca@imendio.com>
-*/
+ * nautilus-search-directory-file.c: Subclass of NautilusFile to help implement the
+ * searches
+ *
+ * Copyright (C) 2005 Novell, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Anders Carlsson <andersca@imendio.com>
+ */
#include <config.h>
#include "nautilus-search-directory-file.h"
@@ -35,261 +35,274 @@
#include <glib/gi18n.h>
#include <string.h>
-struct NautilusSearchDirectoryFileDetails {
- gchar *metadata_filename;
+struct NautilusSearchDirectoryFileDetails
+{
+ gchar *metadata_filename;
};
-G_DEFINE_TYPE(NautilusSearchDirectoryFile, nautilus_search_directory_file, NAUTILUS_TYPE_FILE);
+G_DEFINE_TYPE (NautilusSearchDirectoryFile, nautilus_search_directory_file, NAUTILUS_TYPE_FILE);
static void
-search_directory_file_monitor_add (NautilusFile *file,
- gconstpointer client,
- NautilusFileAttributes attributes)
+search_directory_file_monitor_add (NautilusFile *file,
+ gconstpointer client,
+ NautilusFileAttributes attributes)
{
- /* No need for monitoring, we always emit changed when files
- are added/removed, and no other metadata changes */
+ /* No need for monitoring, we always emit changed when files
+ * are added/removed, and no other metadata changes */
- /* Update display name, in case this didn't happen yet */
- nautilus_search_directory_file_update_display_name (NAUTILUS_SEARCH_DIRECTORY_FILE (file));
+ /* Update display name, in case this didn't happen yet */
+ nautilus_search_directory_file_update_display_name (NAUTILUS_SEARCH_DIRECTORY_FILE (file));
}
static void
-search_directory_file_monitor_remove (NautilusFile *file,
- gconstpointer client)
+search_directory_file_monitor_remove (NautilusFile *file,
+ gconstpointer client)
{
- /* Do nothing here, we don't have any monitors */
+ /* Do nothing here, we don't have any monitors */
}
static void
-search_directory_file_call_when_ready (NautilusFile *file,
- NautilusFileAttributes file_attributes,
- NautilusFileCallback callback,
- gpointer callback_data)
-
+search_directory_file_call_when_ready (NautilusFile *file,
+ NautilusFileAttributes file_attributes,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- /* Update display name, in case this didn't happen yet */
- nautilus_search_directory_file_update_display_name (NAUTILUS_SEARCH_DIRECTORY_FILE (file));
-
- /* All data for directory-as-file is always uptodate */
- (* callback) (file, callback_data);
+ /* Update display name, in case this didn't happen yet */
+ nautilus_search_directory_file_update_display_name (NAUTILUS_SEARCH_DIRECTORY_FILE (file));
+
+ /* All data for directory-as-file is always uptodate */
+ (*callback)(file, callback_data);
}
-
+
static void
-search_directory_file_cancel_call_when_ready (NautilusFile *file,
- NautilusFileCallback callback,
- gpointer callback_data)
+search_directory_file_cancel_call_when_ready (NautilusFile *file,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- /* Do nothing here, we don't have any pending calls */
+ /* Do nothing here, we don't have any pending calls */
}
static gboolean
-search_directory_file_check_if_ready (NautilusFile *file,
- NautilusFileAttributes attributes)
+search_directory_file_check_if_ready (NautilusFile *file,
+ NautilusFileAttributes attributes)
{
- return TRUE;
+ return TRUE;
}
static gboolean
-search_directory_file_get_item_count (NautilusFile *file,
- guint *count,
- gboolean *count_unreadable)
+search_directory_file_get_item_count (NautilusFile *file,
+ guint *count,
+ gboolean *count_unreadable)
{
- GList *file_list;
+ GList *file_list;
- if (count) {
- file_list = nautilus_directory_get_file_list (file->details->directory);
+ if (count)
+ {
+ file_list = nautilus_directory_get_file_list (file->details->directory);
- *count = g_list_length (file_list);
+ *count = g_list_length (file_list);
- nautilus_file_list_free (file_list);
- }
+ nautilus_file_list_free (file_list);
+ }
- return TRUE;
+ return TRUE;
}
static NautilusRequestStatus
search_directory_file_get_deep_counts (NautilusFile *file,
- guint *directory_count,
- guint *file_count,
- guint *unreadable_directory_count,
- goffset *total_size)
+ guint *directory_count,
+ guint *file_count,
+ guint *unreadable_directory_count,
+ goffset *total_size)
{
- NautilusFile *dir_file;
- GList *file_list, *l;
- guint dirs, files;
- GFileType type;
-
- file_list = nautilus_directory_get_file_list (file->details->directory);
-
- dirs = files = 0;
- for (l = file_list; l != NULL; l = l->next) {
- dir_file = NAUTILUS_FILE (l->data);
- type = nautilus_file_get_file_type (dir_file);
- if (type == G_FILE_TYPE_DIRECTORY) {
- dirs++;
- } else {
- files++;
- }
- }
-
- if (directory_count != NULL) {
- *directory_count = dirs;
- }
- if (file_count != NULL) {
- *file_count = files;
- }
- if (unreadable_directory_count != NULL) {
- *unreadable_directory_count = 0;
- }
- if (total_size != NULL) {
- /* FIXME: Maybe we want to calculate this? */
- *total_size = 0;
- }
-
- nautilus_file_list_free (file_list);
-
- return NAUTILUS_REQUEST_DONE;
+ NautilusFile *dir_file;
+ GList *file_list, *l;
+ guint dirs, files;
+ GFileType type;
+
+ file_list = nautilus_directory_get_file_list (file->details->directory);
+
+ dirs = files = 0;
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ dir_file = NAUTILUS_FILE (l->data);
+ type = nautilus_file_get_file_type (dir_file);
+ if (type == G_FILE_TYPE_DIRECTORY)
+ {
+ dirs++;
+ }
+ else
+ {
+ files++;
+ }
+ }
+
+ if (directory_count != NULL)
+ {
+ *directory_count = dirs;
+ }
+ if (file_count != NULL)
+ {
+ *file_count = files;
+ }
+ if (unreadable_directory_count != NULL)
+ {
+ *unreadable_directory_count = 0;
+ }
+ if (total_size != NULL)
+ {
+ /* FIXME: Maybe we want to calculate this? */
+ *total_size = 0;
+ }
+
+ nautilus_file_list_free (file_list);
+
+ return NAUTILUS_REQUEST_DONE;
}
static char *
search_directory_file_get_where_string (NautilusFile *file)
{
- return g_strdup (_("Search"));
+ return g_strdup (_("Search"));
}
static void
search_directory_file_set_metadata (NautilusFile *file,
- const char *key,
- const char *value)
+ const char *key,
+ const char *value)
{
- NautilusSearchDirectoryFile *search_file;
+ NautilusSearchDirectoryFile *search_file;
- search_file = NAUTILUS_SEARCH_DIRECTORY_FILE (file);
- nautilus_keyfile_metadata_set_string (file,
- search_file->details->metadata_filename,
- "directory", key, value);
+ search_file = NAUTILUS_SEARCH_DIRECTORY_FILE (file);
+ nautilus_keyfile_metadata_set_string (file,
+ search_file->details->metadata_filename,
+ "directory", key, value);
}
static void
-search_directory_file_set_metadata_as_list (NautilusFile *file,
- const char *key,
- char **value)
+search_directory_file_set_metadata_as_list (NautilusFile *file,
+ const char *key,
+ char **value)
{
- NautilusSearchDirectoryFile *search_file;
+ NautilusSearchDirectoryFile *search_file;
- search_file = NAUTILUS_SEARCH_DIRECTORY_FILE (file);
- nautilus_keyfile_metadata_set_stringv (file,
- search_file->details->metadata_filename,
- "directory", key, (const gchar **) value);
+ search_file = NAUTILUS_SEARCH_DIRECTORY_FILE (file);
+ nautilus_keyfile_metadata_set_stringv (file,
+ search_file->details->metadata_filename,
+ "directory", key, (const gchar **) value);
}
void
nautilus_search_directory_file_update_display_name (NautilusSearchDirectoryFile *search_file)
{
- NautilusFile *file;
- NautilusSearchDirectory *search_dir;
- NautilusQuery *query;
- char *display_name;
- gboolean changed;
-
-
- display_name = NULL;
- file = NAUTILUS_FILE (search_file);
- if (file->details->directory) {
- search_dir = NAUTILUS_SEARCH_DIRECTORY (file->details->directory);
- query = nautilus_search_directory_get_query (search_dir);
-
- if (query != NULL) {
- display_name = nautilus_query_to_readable_string (query);
- g_object_unref (query);
- }
- }
-
- if (display_name == NULL) {
- display_name = g_strdup (_("Search"));
- }
-
- changed = nautilus_file_set_display_name (file, display_name, NULL, TRUE);
- if (changed) {
- nautilus_file_emit_changed (file);
- }
-
- g_free (display_name);
+ NautilusFile *file;
+ NautilusSearchDirectory *search_dir;
+ NautilusQuery *query;
+ char *display_name;
+ gboolean changed;
+
+
+ display_name = NULL;
+ file = NAUTILUS_FILE (search_file);
+ if (file->details->directory)
+ {
+ search_dir = NAUTILUS_SEARCH_DIRECTORY (file->details->directory);
+ query = nautilus_search_directory_get_query (search_dir);
+
+ if (query != NULL)
+ {
+ display_name = nautilus_query_to_readable_string (query);
+ g_object_unref (query);
+ }
+ }
+
+ if (display_name == NULL)
+ {
+ display_name = g_strdup (_("Search"));
+ }
+
+ changed = nautilus_file_set_display_name (file, display_name, NULL, TRUE);
+ if (changed)
+ {
+ nautilus_file_emit_changed (file);
+ }
+
+ g_free (display_name);
}
static void
nautilus_search_directory_file_init (NautilusSearchDirectoryFile *search_file)
{
- NautilusFile *file;
- gchar *xdg_dir;
+ NautilusFile *file;
+ gchar *xdg_dir;
- file = NAUTILUS_FILE (search_file);
+ file = NAUTILUS_FILE (search_file);
- search_file->details = G_TYPE_INSTANCE_GET_PRIVATE (search_file,
- NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE,
- NautilusSearchDirectoryFileDetails);
+ search_file->details = G_TYPE_INSTANCE_GET_PRIVATE (search_file,
+ NAUTILUS_TYPE_SEARCH_DIRECTORY_FILE,
+ NautilusSearchDirectoryFileDetails);
- xdg_dir = nautilus_get_user_directory ();
- search_file->details->metadata_filename = g_build_filename (xdg_dir,
- "search-metadata",
- NULL);
- g_free (xdg_dir);
+ xdg_dir = nautilus_get_user_directory ();
+ search_file->details->metadata_filename = g_build_filename (xdg_dir,
+ "search-metadata",
+ NULL);
+ g_free (xdg_dir);
- file->details->got_file_info = TRUE;
- file->details->mime_type = eel_ref_str_get_unique ("x-directory/normal");
- file->details->type = G_FILE_TYPE_DIRECTORY;
- file->details->size = 0;
+ file->details->got_file_info = TRUE;
+ file->details->mime_type = eel_ref_str_get_unique ("x-directory/normal");
+ file->details->type = G_FILE_TYPE_DIRECTORY;
+ file->details->size = 0;
- file->details->file_info_is_up_to_date = TRUE;
+ file->details->file_info_is_up_to_date = TRUE;
- file->details->custom_icon = NULL;
- file->details->activation_uri = NULL;
- file->details->got_link_info = TRUE;
- file->details->link_info_is_up_to_date = TRUE;
+ file->details->custom_icon = NULL;
+ file->details->activation_uri = NULL;
+ file->details->got_link_info = TRUE;
+ file->details->link_info_is_up_to_date = TRUE;
- file->details->directory_count = 0;
- file->details->got_directory_count = TRUE;
- file->details->directory_count_is_up_to_date = TRUE;
+ file->details->directory_count = 0;
+ file->details->got_directory_count = TRUE;
+ file->details->directory_count_is_up_to_date = TRUE;
- nautilus_file_set_display_name (file, _("Search"), NULL, TRUE);
+ nautilus_file_set_display_name (file, _("Search"), NULL, TRUE);
}
static void
nautilus_search_directory_file_finalize (GObject *object)
{
- NautilusSearchDirectoryFile *search_file;
+ NautilusSearchDirectoryFile *search_file;
- search_file = NAUTILUS_SEARCH_DIRECTORY_FILE (object);
+ search_file = NAUTILUS_SEARCH_DIRECTORY_FILE (object);
- g_free (search_file->details->metadata_filename);
+ g_free (search_file->details->metadata_filename);
- G_OBJECT_CLASS (nautilus_search_directory_file_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_directory_file_parent_class)->finalize (object);
}
static void
nautilus_search_directory_file_class_init (NautilusSearchDirectoryFileClass *klass)
{
- GObjectClass *object_class;
- NautilusFileClass *file_class;
+ GObjectClass *object_class;
+ NautilusFileClass *file_class;
- object_class = G_OBJECT_CLASS (klass);
- file_class = NAUTILUS_FILE_CLASS (klass);
+ object_class = G_OBJECT_CLASS (klass);
+ file_class = NAUTILUS_FILE_CLASS (klass);
- object_class->finalize = nautilus_search_directory_file_finalize;
+ object_class->finalize = nautilus_search_directory_file_finalize;
- file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
+ file_class->default_file_type = G_FILE_TYPE_DIRECTORY;
- file_class->monitor_add = search_directory_file_monitor_add;
- file_class->monitor_remove = search_directory_file_monitor_remove;
- file_class->call_when_ready = search_directory_file_call_when_ready;
- file_class->cancel_call_when_ready = search_directory_file_cancel_call_when_ready;
- file_class->check_if_ready = search_directory_file_check_if_ready;
- file_class->get_item_count = search_directory_file_get_item_count;
- file_class->get_deep_counts = search_directory_file_get_deep_counts;
- file_class->get_where_string = search_directory_file_get_where_string;
- file_class->set_metadata = search_directory_file_set_metadata;
- file_class->set_metadata_as_list = search_directory_file_set_metadata_as_list;
+ file_class->monitor_add = search_directory_file_monitor_add;
+ file_class->monitor_remove = search_directory_file_monitor_remove;
+ file_class->call_when_ready = search_directory_file_call_when_ready;
+ file_class->cancel_call_when_ready = search_directory_file_cancel_call_when_ready;
+ file_class->check_if_ready = search_directory_file_check_if_ready;
+ file_class->get_item_count = search_directory_file_get_item_count;
+ file_class->get_deep_counts = search_directory_file_get_deep_counts;
+ file_class->get_where_string = search_directory_file_get_where_string;
+ file_class->set_metadata = search_directory_file_set_metadata;
+ file_class->set_metadata_as_list = search_directory_file_set_metadata_as_list;
- g_type_class_add_private (object_class, sizeof(NautilusSearchDirectoryFileDetails));
+ g_type_class_add_private (object_class, sizeof (NautilusSearchDirectoryFileDetails));
}
diff --git a/src/nautilus-search-directory.c b/src/nautilus-search-directory.c
index 559c531d7..53752b37d 100644
--- a/src/nautilus-search-directory.c
+++ b/src/nautilus-search-directory.c
@@ -1,21 +1,21 @@
/*
- Copyright (C) 2005 Novell, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Anders Carlsson <andersca@imendio.com>
-*/
+ * Copyright (C) 2005 Novell, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Anders Carlsson <andersca@imendio.com>
+ */
#include <config.h>
#include "nautilus-search-directory.h"
@@ -35,64 +35,68 @@
#include <string.h>
#include <sys/time.h>
-struct NautilusSearchDirectoryDetails {
- NautilusQuery *query;
-
- NautilusSearchEngine *engine;
-
- gboolean search_running;
- /* When the search directory is stopped or cancelled, we migth wait
- * until all data and signals from previous search are stopped and removed
- * from the search engine. While this situation happens we don't want to connect
- * clients to our signals, and we will wait until the search data and signals
- * are valid and ready.
- * The worst thing that can happens if we don't do this is that new clients
- * migth get the information of old searchs if they are waiting_for_file_list.
- * But that shouldn't be a big deal since old clients have the old information.
- * But anyway it's currently unused for this case since the only client is
- * nautilus-view and is not waiting_for_file_list :) .
- *
- * The other use case is for letting clients know if information of the directory
- * is outdated or not valid. This might happens for automatic
- * scheduled timeouts. */
- gboolean search_ready_and_valid;
-
- GList *files;
- GHashTable *files_hash;
-
- GList *monitor_list;
- GList *callback_list;
- GList *pending_callback_list;
-
- GBinding *binding;
-
- NautilusDirectory *base_model;
+struct NautilusSearchDirectoryDetails
+{
+ NautilusQuery *query;
+
+ NautilusSearchEngine *engine;
+
+ gboolean search_running;
+ /* When the search directory is stopped or cancelled, we migth wait
+ * until all data and signals from previous search are stopped and removed
+ * from the search engine. While this situation happens we don't want to connect
+ * clients to our signals, and we will wait until the search data and signals
+ * are valid and ready.
+ * The worst thing that can happens if we don't do this is that new clients
+ * migth get the information of old searchs if they are waiting_for_file_list.
+ * But that shouldn't be a big deal since old clients have the old information.
+ * But anyway it's currently unused for this case since the only client is
+ * nautilus-view and is not waiting_for_file_list :) .
+ *
+ * The other use case is for letting clients know if information of the directory
+ * is outdated or not valid. This might happens for automatic
+ * scheduled timeouts. */
+ gboolean search_ready_and_valid;
+
+ GList *files;
+ GHashTable *files_hash;
+
+ GList *monitor_list;
+ GList *callback_list;
+ GList *pending_callback_list;
+
+ GBinding *binding;
+
+ NautilusDirectory *base_model;
};
-typedef struct {
- gboolean monitor_hidden_files;
- NautilusFileAttributes monitor_attributes;
+typedef struct
+{
+ gboolean monitor_hidden_files;
+ NautilusFileAttributes monitor_attributes;
- gconstpointer client;
+ gconstpointer client;
} SearchMonitor;
-typedef struct {
- NautilusSearchDirectory *search_directory;
+typedef struct
+{
+ NautilusSearchDirectory *search_directory;
- NautilusDirectoryCallback callback;
- gpointer callback_data;
+ NautilusDirectoryCallback callback;
+ gpointer callback_data;
- NautilusFileAttributes wait_for_attributes;
- gboolean wait_for_file_list;
- GList *file_list;
- GHashTable *non_ready_hash;
+ NautilusFileAttributes wait_for_attributes;
+ gboolean wait_for_file_list;
+ GList *file_list;
+ GHashTable *non_ready_hash;
} SearchCallback;
-enum {
- PROP_0,
- PROP_BASE_MODEL,
- PROP_QUERY,
- NUM_PROPERTIES
+enum
+{
+ PROP_0,
+ PROP_BASE_MODEL,
+ PROP_QUERY,
+ NUM_PROPERTIES
};
G_DEFINE_TYPE_WITH_CODE (NautilusSearchDirectory, nautilus_search_directory, NAUTILUS_TYPE_DIRECTORY,
@@ -104,507 +108,564 @@ G_DEFINE_TYPE_WITH_CODE (NautilusSearchDirectory, nautilus_search_directory, NAU
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
-static void search_engine_hits_added (NautilusSearchEngine *engine, GList *hits, NautilusSearchDirectory *search);
-static void search_engine_error (NautilusSearchEngine *engine, const char *error, NautilusSearchDirectory *search);
-static void search_callback_file_ready_callback (NautilusFile *file, gpointer data);
-static void file_changed (NautilusFile *file, NautilusSearchDirectory *search);
+static void search_engine_hits_added (NautilusSearchEngine *engine,
+ GList *hits,
+ NautilusSearchDirectory *search);
+static void search_engine_error (NautilusSearchEngine *engine,
+ const char *error,
+ NautilusSearchDirectory *search);
+static void search_callback_file_ready_callback (NautilusFile *file,
+ gpointer data);
+static void file_changed (NautilusFile *file,
+ NautilusSearchDirectory *search);
static void
reset_file_list (NautilusSearchDirectory *search)
{
- GList *list, *monitor_list;
- NautilusFile *file;
- SearchMonitor *monitor;
-
- /* Remove file connections */
- for (list = search->details->files; list != NULL; list = list->next) {
- file = list->data;
-
- /* Disconnect change handler */
- g_signal_handlers_disconnect_by_func (file, file_changed, search);
+ GList *list, *monitor_list;
+ NautilusFile *file;
+ SearchMonitor *monitor;
+
+ /* Remove file connections */
+ for (list = search->details->files; list != NULL; list = list->next)
+ {
+ file = list->data;
+
+ /* Disconnect change handler */
+ g_signal_handlers_disconnect_by_func (file, file_changed, search);
+
+ /* Remove monitors */
+ for (monitor_list = search->details->monitor_list; monitor_list;
+ monitor_list = monitor_list->next)
+ {
+ monitor = monitor_list->data;
+ nautilus_file_monitor_remove (file, monitor);
+ }
+ }
- /* Remove monitors */
- for (monitor_list = search->details->monitor_list; monitor_list;
- monitor_list = monitor_list->next) {
- monitor = monitor_list->data;
- nautilus_file_monitor_remove (file, monitor);
- }
- }
-
- nautilus_file_list_free (search->details->files);
- search->details->files = NULL;
+ nautilus_file_list_free (search->details->files);
+ search->details->files = NULL;
- g_hash_table_remove_all (search->details->files_hash);
+ g_hash_table_remove_all (search->details->files_hash);
}
static void
set_hidden_files (NautilusSearchDirectory *search)
{
- GList *l;
- SearchMonitor *monitor;
- gboolean monitor_hidden = FALSE;
-
- for (l = search->details->monitor_list; l != NULL; l = l->next) {
- monitor = l->data;
- monitor_hidden |= monitor->monitor_hidden_files;
-
- if (monitor_hidden) {
- break;
- }
- }
+ GList *l;
+ SearchMonitor *monitor;
+ gboolean monitor_hidden = FALSE;
+
+ for (l = search->details->monitor_list; l != NULL; l = l->next)
+ {
+ monitor = l->data;
+ monitor_hidden |= monitor->monitor_hidden_files;
+
+ if (monitor_hidden)
+ {
+ break;
+ }
+ }
- nautilus_query_set_show_hidden_files (search->details->query, monitor_hidden);
+ nautilus_query_set_show_hidden_files (search->details->query, monitor_hidden);
}
static void
start_search (NautilusSearchDirectory *search)
{
- NautilusSearchEngineModel *model_provider;
- NautilusSearchEngineSimple *simple_provider;
- gboolean recursive;
+ NautilusSearchEngineModel *model_provider;
+ NautilusSearchEngineSimple *simple_provider;
+ gboolean recursive;
- if (!search->details->query) {
- return;
- }
+ if (!search->details->query)
+ {
+ return;
+ }
- if (search->details->search_running) {
- return;
- }
+ if (search->details->search_running)
+ {
+ return;
+ }
- if (!search->details->monitor_list && !search->details->pending_callback_list) {
- return;
- }
+ if (!search->details->monitor_list && !search->details->pending_callback_list)
+ {
+ return;
+ }
- /* We need to start the search engine */
- search->details->search_running = TRUE;
- search->details->search_ready_and_valid = FALSE;
+ /* We need to start the search engine */
+ search->details->search_running = TRUE;
+ search->details->search_ready_and_valid = FALSE;
- set_hidden_files (search);
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (search->details->engine),
- search->details->query);
+ set_hidden_files (search);
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (search->details->engine),
+ search->details->query);
- model_provider = nautilus_search_engine_get_model_provider (search->details->engine);
- nautilus_search_engine_model_set_model (model_provider, search->details->base_model);
+ model_provider = nautilus_search_engine_get_model_provider (search->details->engine);
+ nautilus_search_engine_model_set_model (model_provider, search->details->base_model);
- simple_provider = nautilus_search_engine_get_simple_provider (search->details->engine);
- recursive = nautilus_query_get_recursive (search->details->query);
- g_object_set (simple_provider, "recursive", recursive, NULL);
+ simple_provider = nautilus_search_engine_get_simple_provider (search->details->engine);
+ recursive = nautilus_query_get_recursive (search->details->query);
+ g_object_set (simple_provider, "recursive", recursive, NULL);
- reset_file_list (search);
+ reset_file_list (search);
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (search->details->engine));
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (search->details->engine));
}
static void
stop_search (NautilusSearchDirectory *search)
{
- if (!search->details->search_running) {
- return;
- }
+ if (!search->details->search_running)
+ {
+ return;
+ }
- search->details->search_running = FALSE;
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (search->details->engine));
+ search->details->search_running = FALSE;
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (search->details->engine));
- reset_file_list (search);
+ reset_file_list (search);
}
static void
-file_changed (NautilusFile *file, NautilusSearchDirectory *search)
+file_changed (NautilusFile *file,
+ NautilusSearchDirectory *search)
{
- GList list;
+ GList list;
- list.data = file;
- list.next = NULL;
+ list.data = file;
+ list.next = NULL;
- nautilus_directory_emit_files_changed (NAUTILUS_DIRECTORY (search), &list);
+ nautilus_directory_emit_files_changed (NAUTILUS_DIRECTORY (search), &list);
}
static void
-search_monitor_add (NautilusDirectory *directory,
- gconstpointer client,
- gboolean monitor_hidden_files,
- NautilusFileAttributes file_attributes,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+search_monitor_add (NautilusDirectory *directory,
+ gconstpointer client,
+ gboolean monitor_hidden_files,
+ NautilusFileAttributes file_attributes,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- GList *list;
- SearchMonitor *monitor;
- NautilusSearchDirectory *search;
- NautilusFile *file;
+ GList *list;
+ SearchMonitor *monitor;
+ NautilusSearchDirectory *search;
+ NautilusFile *file;
+
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ monitor = g_new0 (SearchMonitor, 1);
+ monitor->monitor_hidden_files = monitor_hidden_files;
+ monitor->monitor_attributes = file_attributes;
+ monitor->client = client;
- monitor = g_new0 (SearchMonitor, 1);
- monitor->monitor_hidden_files = monitor_hidden_files;
- monitor->monitor_attributes = file_attributes;
- monitor->client = client;
+ search->details->monitor_list = g_list_prepend (search->details->monitor_list, monitor);
- search->details->monitor_list = g_list_prepend (search->details->monitor_list, monitor);
-
- if (callback != NULL) {
- (* callback) (directory, search->details->files, callback_data);
- }
-
- for (list = search->details->files; list != NULL; list = list->next) {
- file = list->data;
+ if (callback != NULL)
+ {
+ (*callback)(directory, search->details->files, callback_data);
+ }
- /* Add monitors */
- nautilus_file_monitor_add (file, monitor, file_attributes);
- }
+ for (list = search->details->files; list != NULL; list = list->next)
+ {
+ file = list->data;
- start_search (search);
+ /* Add monitors */
+ nautilus_file_monitor_add (file, monitor, file_attributes);
+ }
+
+ start_search (search);
}
static void
-search_monitor_remove_file_monitors (SearchMonitor *monitor, NautilusSearchDirectory *search)
+search_monitor_remove_file_monitors (SearchMonitor *monitor,
+ NautilusSearchDirectory *search)
{
- GList *list;
- NautilusFile *file;
-
- for (list = search->details->files; list != NULL; list = list->next) {
- file = list->data;
+ GList *list;
+ NautilusFile *file;
+
+ for (list = search->details->files; list != NULL; list = list->next)
+ {
+ file = list->data;
- nautilus_file_monitor_remove (file, monitor);
- }
+ nautilus_file_monitor_remove (file, monitor);
+ }
}
static void
-search_monitor_destroy (SearchMonitor *monitor, NautilusSearchDirectory *search)
+search_monitor_destroy (SearchMonitor *monitor,
+ NautilusSearchDirectory *search)
{
- search_monitor_remove_file_monitors (monitor, search);
+ search_monitor_remove_file_monitors (monitor, search);
- g_free (monitor);
+ g_free (monitor);
}
static void
search_monitor_remove (NautilusDirectory *directory,
- gconstpointer client)
+ gconstpointer client)
{
- NautilusSearchDirectory *search;
- SearchMonitor *monitor;
- GList *list;
+ NautilusSearchDirectory *search;
+ SearchMonitor *monitor;
+ GList *list;
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
- for (list = search->details->monitor_list; list != NULL; list = list->next) {
- monitor = list->data;
+ for (list = search->details->monitor_list; list != NULL; list = list->next)
+ {
+ monitor = list->data;
- if (monitor->client == client) {
- search->details->monitor_list = g_list_delete_link (search->details->monitor_list, list);
+ if (monitor->client == client)
+ {
+ search->details->monitor_list = g_list_delete_link (search->details->monitor_list, list);
- search_monitor_destroy (monitor, search);
+ search_monitor_destroy (monitor, search);
- break;
- }
- }
+ break;
+ }
+ }
- if (!search->details->monitor_list) {
- stop_search (search);
- }
+ if (!search->details->monitor_list)
+ {
+ stop_search (search);
+ }
}
static void
-cancel_call_when_ready (gpointer key, gpointer value, gpointer user_data)
+cancel_call_when_ready (gpointer key,
+ gpointer value,
+ gpointer user_data)
{
- SearchCallback *search_callback;
- NautilusFile *file;
+ SearchCallback *search_callback;
+ NautilusFile *file;
- file = key;
- search_callback = user_data;
+ file = key;
+ search_callback = user_data;
- nautilus_file_cancel_call_when_ready (file, search_callback_file_ready_callback,
- search_callback);
+ nautilus_file_cancel_call_when_ready (file, search_callback_file_ready_callback,
+ search_callback);
}
static void
search_callback_destroy (SearchCallback *search_callback)
{
- if (search_callback->non_ready_hash) {
- g_hash_table_foreach (search_callback->non_ready_hash, cancel_call_when_ready, search_callback);
- g_hash_table_destroy (search_callback->non_ready_hash);
- }
+ if (search_callback->non_ready_hash)
+ {
+ g_hash_table_foreach (search_callback->non_ready_hash, cancel_call_when_ready, search_callback);
+ g_hash_table_destroy (search_callback->non_ready_hash);
+ }
- nautilus_file_list_free (search_callback->file_list);
+ nautilus_file_list_free (search_callback->file_list);
- g_free (search_callback);
+ g_free (search_callback);
}
static void
search_callback_invoke_and_destroy (SearchCallback *search_callback)
{
- search_callback->callback (NAUTILUS_DIRECTORY (search_callback->search_directory),
- search_callback->file_list,
- search_callback->callback_data);
+ search_callback->callback (NAUTILUS_DIRECTORY (search_callback->search_directory),
+ search_callback->file_list,
+ search_callback->callback_data);
- search_callback->search_directory->details->callback_list =
- g_list_remove (search_callback->search_directory->details->callback_list, search_callback);
+ search_callback->search_directory->details->callback_list =
+ g_list_remove (search_callback->search_directory->details->callback_list, search_callback);
- search_callback_destroy (search_callback);
+ search_callback_destroy (search_callback);
}
static void
-search_callback_file_ready_callback (NautilusFile *file, gpointer data)
+search_callback_file_ready_callback (NautilusFile *file,
+ gpointer data)
{
- SearchCallback *search_callback = data;
-
- g_hash_table_remove (search_callback->non_ready_hash, file);
+ SearchCallback *search_callback = data;
- if (g_hash_table_size (search_callback->non_ready_hash) == 0) {
- search_callback_invoke_and_destroy (search_callback);
- }
+ g_hash_table_remove (search_callback->non_ready_hash, file);
+
+ if (g_hash_table_size (search_callback->non_ready_hash) == 0)
+ {
+ search_callback_invoke_and_destroy (search_callback);
+ }
}
static void
search_callback_add_file_callbacks (SearchCallback *callback)
{
- GList *file_list_copy, *list;
- NautilusFile *file;
+ GList *file_list_copy, *list;
+ NautilusFile *file;
- file_list_copy = g_list_copy (callback->file_list);
+ file_list_copy = g_list_copy (callback->file_list);
- for (list = file_list_copy; list != NULL; list = list->next) {
- file = list->data;
+ for (list = file_list_copy; list != NULL; list = list->next)
+ {
+ file = list->data;
- nautilus_file_call_when_ready (file,
- callback->wait_for_attributes,
- search_callback_file_ready_callback,
- callback);
- }
- g_list_free (file_list_copy);
+ nautilus_file_call_when_ready (file,
+ callback->wait_for_attributes,
+ search_callback_file_ready_callback,
+ callback);
+ }
+ g_list_free (file_list_copy);
}
-
+
static SearchCallback *
-search_callback_find (NautilusSearchDirectory *search, NautilusDirectoryCallback callback, gpointer callback_data)
+search_callback_find (NautilusSearchDirectory *search,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- SearchCallback *search_callback;
- GList *list;
+ SearchCallback *search_callback;
+ GList *list;
- for (list = search->details->callback_list; list != NULL; list = list->next) {
- search_callback = list->data;
+ for (list = search->details->callback_list; list != NULL; list = list->next)
+ {
+ search_callback = list->data;
+
+ if (search_callback->callback == callback &&
+ search_callback->callback_data == callback_data)
+ {
+ return search_callback;
+ }
+ }
- if (search_callback->callback == callback &&
- search_callback->callback_data == callback_data) {
- return search_callback;
- }
- }
-
- return NULL;
+ return NULL;
}
static SearchCallback *
-search_callback_find_pending (NautilusSearchDirectory *search, NautilusDirectoryCallback callback, gpointer callback_data)
+search_callback_find_pending (NautilusSearchDirectory *search,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- SearchCallback *search_callback;
- GList *list;
+ SearchCallback *search_callback;
+ GList *list;
- for (list = search->details->pending_callback_list; list != NULL; list = list->next) {
- search_callback = list->data;
+ for (list = search->details->pending_callback_list; list != NULL; list = list->next)
+ {
+ search_callback = list->data;
- if (search_callback->callback == callback &&
- search_callback->callback_data == callback_data) {
- return search_callback;
- }
- }
-
- return NULL;
+ if (search_callback->callback == callback &&
+ search_callback->callback_data == callback_data)
+ {
+ return search_callback;
+ }
+ }
+
+ return NULL;
}
static GHashTable *
file_list_to_hash_table (GList *file_list)
{
- GList *list;
- GHashTable *table;
+ GList *list;
+ GHashTable *table;
- if (!file_list)
- return NULL;
+ if (!file_list)
+ {
+ return NULL;
+ }
- table = g_hash_table_new (NULL, NULL);
+ table = g_hash_table_new (NULL, NULL);
- for (list = file_list; list != NULL; list = list->next) {
- g_hash_table_insert (table, list->data, list->data);
- }
+ for (list = file_list; list != NULL; list = list->next)
+ {
+ g_hash_table_insert (table, list->data, list->data);
+ }
- return table;
+ return table;
}
static void
-search_call_when_ready (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes,
- gboolean wait_for_file_list,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+search_call_when_ready (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes,
+ gboolean wait_for_file_list,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- NautilusSearchDirectory *search;
- SearchCallback *search_callback;
-
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
-
- search_callback = search_callback_find (search, callback, callback_data);
- if (search_callback == NULL) {
- search_callback = search_callback_find_pending (search, callback, callback_data);
- }
-
- if (search_callback) {
- g_warning ("tried to add a new callback while an old one was pending");
- return;
- }
-
- search_callback = g_new0 (SearchCallback, 1);
- search_callback->search_directory = search;
- search_callback->callback = callback;
- search_callback->callback_data = callback_data;
- search_callback->wait_for_attributes = file_attributes;
- search_callback->wait_for_file_list = wait_for_file_list;
-
- if (wait_for_file_list && !search->details->search_ready_and_valid) {
- /* Add it to the pending callback list, which will be
- * processed when the directory has valid data from the new
- * search and all data and signals from previous searchs is removed. */
- search->details->pending_callback_list =
- g_list_prepend (search->details->pending_callback_list, search_callback);
-
- /* We might need to start the search engine */
- start_search (search);
- } else {
- search_callback->file_list = nautilus_file_list_copy (search->details->files);
- search_callback->non_ready_hash = file_list_to_hash_table (search->details->files);
-
- if (!search_callback->non_ready_hash) {
- /* If there are no ready files, we invoke the callback
- with an empty list.
- */
- search_callback_invoke_and_destroy (search_callback);
- } else {
- search->details->callback_list = g_list_prepend (search->details->callback_list, search_callback);
- search_callback_add_file_callbacks (search_callback);
- }
- }
+ NautilusSearchDirectory *search;
+ SearchCallback *search_callback;
+
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
+
+ search_callback = search_callback_find (search, callback, callback_data);
+ if (search_callback == NULL)
+ {
+ search_callback = search_callback_find_pending (search, callback, callback_data);
+ }
+
+ if (search_callback)
+ {
+ g_warning ("tried to add a new callback while an old one was pending");
+ return;
+ }
+
+ search_callback = g_new0 (SearchCallback, 1);
+ search_callback->search_directory = search;
+ search_callback->callback = callback;
+ search_callback->callback_data = callback_data;
+ search_callback->wait_for_attributes = file_attributes;
+ search_callback->wait_for_file_list = wait_for_file_list;
+
+ if (wait_for_file_list && !search->details->search_ready_and_valid)
+ {
+ /* Add it to the pending callback list, which will be
+ * processed when the directory has valid data from the new
+ * search and all data and signals from previous searchs is removed. */
+ search->details->pending_callback_list =
+ g_list_prepend (search->details->pending_callback_list, search_callback);
+
+ /* We might need to start the search engine */
+ start_search (search);
+ }
+ else
+ {
+ search_callback->file_list = nautilus_file_list_copy (search->details->files);
+ search_callback->non_ready_hash = file_list_to_hash_table (search->details->files);
+
+ if (!search_callback->non_ready_hash)
+ {
+ /* If there are no ready files, we invoke the callback
+ * with an empty list.
+ */
+ search_callback_invoke_and_destroy (search_callback);
+ }
+ else
+ {
+ search->details->callback_list = g_list_prepend (search->details->callback_list, search_callback);
+ search_callback_add_file_callbacks (search_callback);
+ }
+ }
}
static void
-search_cancel_callback (NautilusDirectory *directory,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+search_cancel_callback (NautilusDirectory *directory,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- NautilusSearchDirectory *search;
- SearchCallback *search_callback;
+ NautilusSearchDirectory *search;
+ SearchCallback *search_callback;
+
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ search_callback = search_callback_find (search, callback, callback_data);
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
- search_callback = search_callback_find (search, callback, callback_data);
-
- if (search_callback) {
- search->details->callback_list = g_list_remove (search->details->callback_list, search_callback);
-
- search_callback_destroy (search_callback);
+ if (search_callback)
+ {
+ search->details->callback_list = g_list_remove (search->details->callback_list, search_callback);
- goto done;
- }
+ search_callback_destroy (search_callback);
- /* Check for a pending callback */
- search_callback = search_callback_find_pending (search, callback, callback_data);
+ goto done;
+ }
- if (search_callback) {
- search->details->pending_callback_list = g_list_remove (search->details->pending_callback_list, search_callback);
+ /* Check for a pending callback */
+ search_callback = search_callback_find_pending (search, callback, callback_data);
- search_callback_destroy (search_callback);
- }
+ if (search_callback)
+ {
+ search->details->pending_callback_list = g_list_remove (search->details->pending_callback_list, search_callback);
+
+ search_callback_destroy (search_callback);
+ }
done:
- if (!search->details->callback_list && !search->details->pending_callback_list) {
- stop_search (search);
- }
+ if (!search->details->callback_list && !search->details->pending_callback_list)
+ {
+ stop_search (search);
+ }
}
static void
search_callback_add_pending_file_callbacks (SearchCallback *callback)
{
- callback->file_list = nautilus_file_list_copy (callback->search_directory->details->files);
- callback->non_ready_hash = file_list_to_hash_table (callback->search_directory->details->files);
+ callback->file_list = nautilus_file_list_copy (callback->search_directory->details->files);
+ callback->non_ready_hash = file_list_to_hash_table (callback->search_directory->details->files);
- search_callback_add_file_callbacks (callback);
+ search_callback_add_file_callbacks (callback);
}
static void
search_directory_add_pending_files_callbacks (NautilusSearchDirectory *search)
{
- /* Add all file callbacks */
- g_list_foreach (search->details->pending_callback_list,
- (GFunc)search_callback_add_pending_file_callbacks, NULL);
- search->details->callback_list = g_list_concat (search->details->callback_list,
- search->details->pending_callback_list);
-
- g_list_free (search->details->pending_callback_list);
- search->details->pending_callback_list = NULL;
+ /* Add all file callbacks */
+ g_list_foreach (search->details->pending_callback_list,
+ (GFunc) search_callback_add_pending_file_callbacks, NULL);
+ search->details->callback_list = g_list_concat (search->details->callback_list,
+ search->details->pending_callback_list);
+
+ g_list_free (search->details->pending_callback_list);
+ search->details->pending_callback_list = NULL;
}
static void
on_search_directory_search_ready_and_valid (NautilusSearchDirectory *search)
{
- search_directory_add_pending_files_callbacks (search);
- search->details->search_ready_and_valid = TRUE;
+ search_directory_add_pending_files_callbacks (search);
+ search->details->search_ready_and_valid = TRUE;
}
static void
-search_engine_hits_added (NautilusSearchEngine *engine, GList *hits,
- NautilusSearchDirectory *search)
+search_engine_hits_added (NautilusSearchEngine *engine,
+ GList *hits,
+ NautilusSearchDirectory *search)
{
- GList *hit_list;
- GList *file_list;
- NautilusFile *file;
- SearchMonitor *monitor;
- GList *monitor_list;
-
- file_list = NULL;
-
- for (hit_list = hits; hit_list != NULL; hit_list = hit_list->next) {
- NautilusSearchHit *hit = hit_list->data;
- const char *uri;
+ GList *hit_list;
+ GList *file_list;
+ NautilusFile *file;
+ SearchMonitor *monitor;
+ GList *monitor_list;
+
+ file_list = NULL;
+
+ for (hit_list = hits; hit_list != NULL; hit_list = hit_list->next)
+ {
+ NautilusSearchHit *hit = hit_list->data;
+ const char *uri;
+
+ uri = nautilus_search_hit_get_uri (hit);
+ if (g_str_has_suffix (uri, NAUTILUS_SAVED_SEARCH_EXTENSION))
+ {
+ /* Never return saved searches themselves as hits */
+ continue;
+ }
- uri = nautilus_search_hit_get_uri (hit);
- if (g_str_has_suffix (uri, NAUTILUS_SAVED_SEARCH_EXTENSION)) {
- /* Never return saved searches themselves as hits */
- continue;
- }
+ nautilus_search_hit_compute_scores (hit, search->details->query);
- nautilus_search_hit_compute_scores (hit, search->details->query);
+ file = nautilus_file_get_by_uri (uri);
+ nautilus_file_set_search_relevance (file, nautilus_search_hit_get_relevance (hit));
- file = nautilus_file_get_by_uri (uri);
- nautilus_file_set_search_relevance (file, nautilus_search_hit_get_relevance (hit));
+ for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next)
+ {
+ monitor = monitor_list->data;
- for (monitor_list = search->details->monitor_list; monitor_list; monitor_list = monitor_list->next) {
- monitor = monitor_list->data;
+ /* Add monitors */
+ nautilus_file_monitor_add (file, monitor, monitor->monitor_attributes);
+ }
- /* Add monitors */
- nautilus_file_monitor_add (file, monitor, monitor->monitor_attributes);
- }
+ g_signal_connect (file, "changed", G_CALLBACK (file_changed), search),
- g_signal_connect (file, "changed", G_CALLBACK (file_changed), search),
+ file_list = g_list_prepend (file_list, file);
+ g_hash_table_add (search->details->files_hash, file);
+ }
- file_list = g_list_prepend (file_list, file);
- g_hash_table_add (search->details->files_hash, file);
- }
-
- search->details->files = g_list_concat (search->details->files, file_list);
+ search->details->files = g_list_concat (search->details->files, file_list);
- nautilus_directory_emit_files_added (NAUTILUS_DIRECTORY (search), file_list);
+ nautilus_directory_emit_files_added (NAUTILUS_DIRECTORY (search), file_list);
- file = nautilus_directory_get_corresponding_file (NAUTILUS_DIRECTORY (search));
- nautilus_file_emit_changed (file);
- nautilus_file_unref (file);
+ file = nautilus_directory_get_corresponding_file (NAUTILUS_DIRECTORY (search));
+ nautilus_file_emit_changed (file);
+ nautilus_file_unref (file);
- search_directory_add_pending_files_callbacks (search);
+ search_directory_add_pending_files_callbacks (search);
}
static void
-search_engine_error (NautilusSearchEngine *engine, const char *error_message, NautilusSearchDirectory *search)
+search_engine_error (NautilusSearchEngine *engine,
+ const char *error_message,
+ NautilusSearchDirectory *search)
{
- GError *error;
+ GError *error;
- error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
- error_message);
- nautilus_directory_emit_load_error (NAUTILUS_DIRECTORY (search),
- error);
- g_error_free (error);
+ error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_FAILED,
+ error_message);
+ nautilus_directory_emit_load_error (NAUTILUS_DIRECTORY (search),
+ error);
+ g_error_free (error);
}
static void
@@ -612,145 +673,168 @@ search_engine_finished (NautilusSearchEngine *engine,
NautilusSearchProviderStatus status,
NautilusSearchDirectory *search)
{
- /* If the search engine is going to restart means it finished an old search
- * that was stopped or cancelled.
- * Don't emit the done loading signal in this case, since this means the search
- * directory tried to start a new search before all the search providers were finished
- * in the search engine.
- * If we emit the done-loading signal in this situation the client will think
- * that it finished the current search, not an old one like it's actually
- * happening. */
- if (status == NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL) {
- on_search_directory_search_ready_and_valid (search);
- nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (search));
- } else if (status == NAUTILUS_SEARCH_PROVIDER_STATUS_RESTARTING) {
- /* Remove file monitors of the files from an old search that just
- * actually finished */
- reset_file_list (search);
- }
+ /* If the search engine is going to restart means it finished an old search
+ * that was stopped or cancelled.
+ * Don't emit the done loading signal in this case, since this means the search
+ * directory tried to start a new search before all the search providers were finished
+ * in the search engine.
+ * If we emit the done-loading signal in this situation the client will think
+ * that it finished the current search, not an old one like it's actually
+ * happening. */
+ if (status == NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL)
+ {
+ on_search_directory_search_ready_and_valid (search);
+ nautilus_directory_emit_done_loading (NAUTILUS_DIRECTORY (search));
+ }
+ else if (status == NAUTILUS_SEARCH_PROVIDER_STATUS_RESTARTING)
+ {
+ /* Remove file monitors of the files from an old search that just
+ * actually finished */
+ reset_file_list (search);
+ }
}
static void
search_force_reload (NautilusDirectory *directory)
{
- NautilusSearchDirectory *search;
- NautilusFile *file;
+ NautilusSearchDirectory *search;
+ NautilusFile *file;
+
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ if (!search->details->query)
+ {
+ return;
+ }
- if (!search->details->query) {
- return;
- }
-
- search->details->search_ready_and_valid = FALSE;
+ search->details->search_ready_and_valid = FALSE;
- /* Remove file monitors */
- reset_file_list (search);
- stop_search (search);
+ /* Remove file monitors */
+ reset_file_list (search);
+ stop_search (search);
- file = nautilus_directory_get_corresponding_file (directory);
- nautilus_file_invalidate_all_attributes (file);
- nautilus_file_unref (file);
+ file = nautilus_directory_get_corresponding_file (directory);
+ nautilus_file_invalidate_all_attributes (file);
+ nautilus_file_unref (file);
}
static gboolean
search_are_all_files_seen (NautilusDirectory *directory)
{
- NautilusSearchDirectory *search;
+ NautilusSearchDirectory *search;
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
- return (!search->details->query ||
- search->details->search_ready_and_valid);
+ return (!search->details->query ||
+ search->details->search_ready_and_valid);
}
static gboolean
search_contains_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- NautilusSearchDirectory *search;
+ NautilusSearchDirectory *search;
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
- return (g_hash_table_lookup (search->details->files_hash, file) != NULL);
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ return (g_hash_table_lookup (search->details->files_hash, file) != NULL);
}
static GList *
search_get_file_list (NautilusDirectory *directory)
{
- NautilusSearchDirectory *search;
+ NautilusSearchDirectory *search;
- search = NAUTILUS_SEARCH_DIRECTORY (directory);
+ search = NAUTILUS_SEARCH_DIRECTORY (directory);
- return nautilus_file_list_copy (search->details->files);
+ return nautilus_file_list_copy (search->details->files);
}
static gboolean
search_is_editable (NautilusDirectory *directory)
{
- return FALSE;
+ return FALSE;
}
static gboolean
real_handles_location (GFile *location)
{
- g_autofree gchar *uri;
+ g_autofree gchar *uri;
- uri = g_file_get_uri (location);
+ uri = g_file_get_uri (location);
- return eel_uri_is_search (uri);
+ return eel_uri_is_search (uri);
}
static void
-search_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+search_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusSearchDirectory *search = NAUTILUS_SEARCH_DIRECTORY (object);
+ NautilusSearchDirectory *search = NAUTILUS_SEARCH_DIRECTORY (object);
- switch (property_id) {
- case PROP_BASE_MODEL:
- nautilus_search_directory_set_base_model (search, g_value_get_object (value));
- break;
- case PROP_QUERY:
- nautilus_search_directory_set_query (search, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ switch (property_id)
+ {
+ case PROP_BASE_MODEL:
+ {
+ nautilus_search_directory_set_base_model (search, g_value_get_object (value));
+ }
+ break;
+
+ case PROP_QUERY:
+ {
+ nautilus_search_directory_set_query (search, g_value_get_object (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-search_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+search_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusSearchDirectory *search = NAUTILUS_SEARCH_DIRECTORY (object);
+ NautilusSearchDirectory *search = NAUTILUS_SEARCH_DIRECTORY (object);
+
+ switch (property_id)
+ {
+ case PROP_BASE_MODEL:
+ {
+ g_value_set_object (value, nautilus_search_directory_get_base_model (search));
+ }
+ break;
- switch (property_id) {
- case PROP_BASE_MODEL:
- g_value_set_object (value, nautilus_search_directory_get_base_model (search));
- break;
- case PROP_QUERY:
- g_value_take_object (value, nautilus_search_directory_get_query (search));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ case PROP_QUERY:
+ {
+ g_value_take_object (value, nautilus_search_directory_get_query (search));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
clear_base_model (NautilusSearchDirectory *search)
{
- if (search->details->base_model != NULL) {
- nautilus_directory_file_monitor_remove (search->details->base_model,
- &search->details->base_model);
- g_clear_object (&search->details->base_model);
- }
+ if (search->details->base_model != NULL)
+ {
+ nautilus_directory_file_monitor_remove (search->details->base_model,
+ &search->details->base_model);
+ g_clear_object (&search->details->base_model);
+ }
}
static void
@@ -784,206 +868,218 @@ search_disconnect_engine (NautilusSearchDirectory *search)
static void
search_dispose (GObject *object)
{
- NautilusSearchDirectory *search;
- GList *list;
+ NautilusSearchDirectory *search;
+ GList *list;
- search = NAUTILUS_SEARCH_DIRECTORY (object);
+ search = NAUTILUS_SEARCH_DIRECTORY (object);
- clear_base_model (search);
+ clear_base_model (search);
- /* Remove search monitors */
- if (search->details->monitor_list) {
- for (list = search->details->monitor_list; list != NULL; list = list->next) {
- search_monitor_destroy ((SearchMonitor *)list->data, search);
- }
+ /* Remove search monitors */
+ if (search->details->monitor_list)
+ {
+ for (list = search->details->monitor_list; list != NULL; list = list->next)
+ {
+ search_monitor_destroy ((SearchMonitor *) list->data, search);
+ }
+
+ g_list_free (search->details->monitor_list);
+ search->details->monitor_list = NULL;
+ }
+
+ reset_file_list (search);
- g_list_free (search->details->monitor_list);
- search->details->monitor_list = NULL;
- }
+ if (search->details->callback_list)
+ {
+ /* Remove callbacks */
+ g_list_foreach (search->details->callback_list,
+ (GFunc) search_callback_destroy, NULL);
+ g_list_free (search->details->callback_list);
+ search->details->callback_list = NULL;
+ }
- reset_file_list (search);
-
- if (search->details->callback_list) {
- /* Remove callbacks */
- g_list_foreach (search->details->callback_list,
- (GFunc)search_callback_destroy, NULL);
- g_list_free (search->details->callback_list);
- search->details->callback_list = NULL;
- }
+ if (search->details->pending_callback_list)
+ {
+ g_list_foreach (search->details->pending_callback_list,
+ (GFunc) search_callback_destroy, NULL);
+ g_list_free (search->details->pending_callback_list);
+ search->details->pending_callback_list = NULL;
+ }
- if (search->details->pending_callback_list) {
- g_list_foreach (search->details->pending_callback_list,
- (GFunc)search_callback_destroy, NULL);
- g_list_free (search->details->pending_callback_list);
- search->details->pending_callback_list = NULL;
- }
+ g_clear_object (&search->details->query);
+ stop_search (search);
+ search_disconnect_engine (search);
- g_clear_object (&search->details->query);
- stop_search (search);
- search_disconnect_engine(search);
+ g_clear_object (&search->details->engine);
- g_clear_object (&search->details->engine);
-
- G_OBJECT_CLASS (nautilus_search_directory_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_search_directory_parent_class)->dispose (object);
}
static void
search_finalize (GObject *object)
{
- NautilusSearchDirectory *search;
+ NautilusSearchDirectory *search;
- search = NAUTILUS_SEARCH_DIRECTORY (object);
+ search = NAUTILUS_SEARCH_DIRECTORY (object);
- g_hash_table_destroy (search->details->files_hash);
+ g_hash_table_destroy (search->details->files_hash);
- G_OBJECT_CLASS (nautilus_search_directory_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_directory_parent_class)->finalize (object);
}
static void
nautilus_search_directory_init (NautilusSearchDirectory *search)
{
- search->details = G_TYPE_INSTANCE_GET_PRIVATE (search, NAUTILUS_TYPE_SEARCH_DIRECTORY,
- NautilusSearchDirectoryDetails);
+ search->details = G_TYPE_INSTANCE_GET_PRIVATE (search, NAUTILUS_TYPE_SEARCH_DIRECTORY,
+ NautilusSearchDirectoryDetails);
- search->details->files_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
+ search->details->files_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
- search->details->engine = nautilus_search_engine_new ();
- search_connect_engine (search);
+ search->details->engine = nautilus_search_engine_new ();
+ search_connect_engine (search);
}
static void
nautilus_search_directory_class_init (NautilusSearchDirectoryClass *class)
{
- NautilusDirectoryClass *directory_class = NAUTILUS_DIRECTORY_CLASS (class);
- GObjectClass *oclass = G_OBJECT_CLASS (class);
-
- oclass->dispose = search_dispose;
- oclass->finalize = search_finalize;
- oclass->get_property = search_get_property;
- oclass->set_property = search_set_property;
-
- directory_class->are_all_files_seen = search_are_all_files_seen;
- directory_class->contains_file = search_contains_file;
- directory_class->force_reload = search_force_reload;
- directory_class->call_when_ready = search_call_when_ready;
- directory_class->cancel_callback = search_cancel_callback;
-
- directory_class->file_monitor_add = search_monitor_add;
- directory_class->file_monitor_remove = search_monitor_remove;
-
- directory_class->get_file_list = search_get_file_list;
- directory_class->is_editable = search_is_editable;
- directory_class->handles_location = real_handles_location;
-
- properties[PROP_BASE_MODEL] =
- g_param_spec_object ("base-model",
- "The base model",
- "The base directory model for this directory",
- NAUTILUS_TYPE_DIRECTORY,
- G_PARAM_READWRITE);
- properties[PROP_QUERY] =
- g_param_spec_object ("query",
- "The query",
- "The query for this search directory",
- NAUTILUS_TYPE_QUERY,
- G_PARAM_READWRITE);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
- g_type_class_add_private (class, sizeof (NautilusSearchDirectoryDetails));
+ NautilusDirectoryClass *directory_class = NAUTILUS_DIRECTORY_CLASS (class);
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+
+ oclass->dispose = search_dispose;
+ oclass->finalize = search_finalize;
+ oclass->get_property = search_get_property;
+ oclass->set_property = search_set_property;
+
+ directory_class->are_all_files_seen = search_are_all_files_seen;
+ directory_class->contains_file = search_contains_file;
+ directory_class->force_reload = search_force_reload;
+ directory_class->call_when_ready = search_call_when_ready;
+ directory_class->cancel_callback = search_cancel_callback;
+
+ directory_class->file_monitor_add = search_monitor_add;
+ directory_class->file_monitor_remove = search_monitor_remove;
+
+ directory_class->get_file_list = search_get_file_list;
+ directory_class->is_editable = search_is_editable;
+ directory_class->handles_location = real_handles_location;
+
+ properties[PROP_BASE_MODEL] =
+ g_param_spec_object ("base-model",
+ "The base model",
+ "The base directory model for this directory",
+ NAUTILUS_TYPE_DIRECTORY,
+ G_PARAM_READWRITE);
+ properties[PROP_QUERY] =
+ g_param_spec_object ("query",
+ "The query",
+ "The query for this search directory",
+ NAUTILUS_TYPE_QUERY,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+ g_type_class_add_private (class, sizeof (NautilusSearchDirectoryDetails));
}
void
nautilus_search_directory_set_base_model (NautilusSearchDirectory *search,
- NautilusDirectory *base_model)
+ NautilusDirectory *base_model)
{
- if (search->details->base_model == base_model) {
- return;
- }
+ if (search->details->base_model == base_model)
+ {
+ return;
+ }
- if (search->details->query != NULL) {
- GFile *query_location, *model_location;
- gboolean is_equal;
+ if (search->details->query != NULL)
+ {
+ GFile *query_location, *model_location;
+ gboolean is_equal;
- query_location = nautilus_query_get_location (search->details->query);
- model_location = nautilus_directory_get_location (base_model);
+ query_location = nautilus_query_get_location (search->details->query);
+ model_location = nautilus_directory_get_location (base_model);
- is_equal = g_file_equal (model_location, query_location);
+ is_equal = g_file_equal (model_location, query_location);
- g_object_unref (model_location);
- g_object_unref (query_location);
+ g_object_unref (model_location);
+ g_object_unref (query_location);
- if (!is_equal) {
- return;
- }
- }
+ if (!is_equal)
+ {
+ return;
+ }
+ }
- clear_base_model (search);
- search->details->base_model = nautilus_directory_ref (base_model);
+ clear_base_model (search);
+ search->details->base_model = nautilus_directory_ref (base_model);
- if (search->details->base_model != NULL) {
- nautilus_directory_file_monitor_add (base_model, &search->details->base_model,
- TRUE, NAUTILUS_FILE_ATTRIBUTE_INFO,
- NULL, NULL);
- }
+ if (search->details->base_model != NULL)
+ {
+ nautilus_directory_file_monitor_add (base_model, &search->details->base_model,
+ TRUE, NAUTILUS_FILE_ATTRIBUTE_INFO,
+ NULL, NULL);
+ }
- g_object_notify_by_pspec (G_OBJECT (search), properties[PROP_BASE_MODEL]);
+ g_object_notify_by_pspec (G_OBJECT (search), properties[PROP_BASE_MODEL]);
}
NautilusDirectory *
nautilus_search_directory_get_base_model (NautilusSearchDirectory *search)
{
- return search->details->base_model;
+ return search->details->base_model;
}
char *
nautilus_search_directory_generate_new_uri (void)
{
- static int counter = 0;
- char *uri;
+ static int counter = 0;
+ char *uri;
- uri = g_strdup_printf (EEL_SEARCH_URI"//%d/", counter++);
+ uri = g_strdup_printf (EEL_SEARCH_URI "//%d/", counter++);
- return uri;
+ return uri;
}
void
nautilus_search_directory_set_query (NautilusSearchDirectory *search,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- NautilusFile *file;
- NautilusQuery *old_query;
+ NautilusFile *file;
+ NautilusQuery *old_query;
- old_query = search->details->query;
+ old_query = search->details->query;
- if (search->details->query != query) {
- search->details->query = g_object_ref (query);
+ if (search->details->query != query)
+ {
+ search->details->query = g_object_ref (query);
- g_clear_pointer (&search->details->binding, g_binding_unbind);
+ g_clear_pointer (&search->details->binding, g_binding_unbind);
- if (query) {
- search->details->binding = g_object_bind_property (search->details->engine, "running",
- query, "searching",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
- }
+ if (query)
+ {
+ search->details->binding = g_object_bind_property (search->details->engine, "running",
+ query, "searching",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
+ }
- g_object_notify_by_pspec (G_OBJECT (search), properties[PROP_QUERY]);
+ g_object_notify_by_pspec (G_OBJECT (search), properties[PROP_QUERY]);
- g_clear_object (&old_query);
- }
+ g_clear_object (&old_query);
+ }
- file = nautilus_directory_get_existing_corresponding_file (NAUTILUS_DIRECTORY (search));
- if (file != NULL) {
- nautilus_search_directory_file_update_display_name (NAUTILUS_SEARCH_DIRECTORY_FILE (file));
- }
- nautilus_file_unref (file);
+ file = nautilus_directory_get_existing_corresponding_file (NAUTILUS_DIRECTORY (search));
+ if (file != NULL)
+ {
+ nautilus_search_directory_file_update_display_name (NAUTILUS_SEARCH_DIRECTORY_FILE (file));
+ }
+ nautilus_file_unref (file);
}
NautilusQuery *
nautilus_search_directory_get_query (NautilusSearchDirectory *search)
{
- if (search->details->query != NULL) {
- return g_object_ref (search->details->query);
- }
-
- return NULL;
+ if (search->details->query != NULL)
+ {
+ return g_object_ref (search->details->query);
+ }
+
+ return NULL;
}
diff --git a/src/nautilus-search-engine-model.c b/src/nautilus-search-engine-model.c
index 3294bd077..b8f2a940f 100644
--- a/src/nautilus-search-engine-model.c
+++ b/src/nautilus-search-engine-model.c
@@ -34,241 +34,259 @@
#include <glib.h>
#include <gio/gio.h>
-struct NautilusSearchEngineModelDetails {
- NautilusQuery *query;
+struct NautilusSearchEngineModelDetails
+{
+ NautilusQuery *query;
- GList *hits;
- NautilusDirectory *directory;
+ GList *hits;
+ NautilusDirectory *directory;
- gboolean query_pending;
- guint finished_id;
+ gboolean query_pending;
+ guint finished_id;
};
-enum {
- PROP_0,
- PROP_RUNNING,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_RUNNING,
+ LAST_PROP
};
static void nautilus_search_provider_init (NautilusSearchProviderInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngineModel,
- nautilus_search_engine_model,
- G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
- nautilus_search_provider_init))
+ nautilus_search_engine_model,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
+ nautilus_search_provider_init))
static void
finalize (GObject *object)
{
- NautilusSearchEngineModel *model;
+ NautilusSearchEngineModel *model;
- model = NAUTILUS_SEARCH_ENGINE_MODEL (object);
+ model = NAUTILUS_SEARCH_ENGINE_MODEL (object);
- if (model->details->hits != NULL) {
- g_list_free_full (model->details->hits, g_object_unref);
- model->details->hits = NULL;
- }
+ if (model->details->hits != NULL)
+ {
+ g_list_free_full (model->details->hits, g_object_unref);
+ model->details->hits = NULL;
+ }
- if (model->details->finished_id != 0) {
- g_source_remove (model->details->finished_id);
- model->details->finished_id = 0;
- }
+ if (model->details->finished_id != 0)
+ {
+ g_source_remove (model->details->finished_id);
+ model->details->finished_id = 0;
+ }
- g_clear_object (&model->details->directory);
- g_clear_object (&model->details->query);
+ g_clear_object (&model->details->directory);
+ g_clear_object (&model->details->query);
- G_OBJECT_CLASS (nautilus_search_engine_model_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_engine_model_parent_class)->finalize (object);
}
static gboolean
search_finished (NautilusSearchEngineModel *model)
{
- model->details->finished_id = 0;
+ model->details->finished_id = 0;
- if (model->details->hits != NULL) {
- DEBUG ("Model engine hits added");
- nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (model),
- model->details->hits);
- g_list_free_full (model->details->hits, g_object_unref);
- model->details->hits = NULL;
- }
+ if (model->details->hits != NULL)
+ {
+ DEBUG ("Model engine hits added");
+ nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (model),
+ model->details->hits);
+ g_list_free_full (model->details->hits, g_object_unref);
+ model->details->hits = NULL;
+ }
- model->details->query_pending = FALSE;
+ model->details->query_pending = FALSE;
- g_object_notify (G_OBJECT (model), "running");
+ g_object_notify (G_OBJECT (model), "running");
- DEBUG ("Model engine finished");
- nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (model),
- NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
- g_object_unref (model);
+ DEBUG ("Model engine finished");
+ nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (model),
+ NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
+ g_object_unref (model);
- return FALSE;
+ return FALSE;
}
static void
search_finished_idle (NautilusSearchEngineModel *model)
{
- if (model->details->finished_id != 0) {
- return;
- }
+ if (model->details->finished_id != 0)
+ {
+ return;
+ }
- model->details->finished_id = g_idle_add ((GSourceFunc) search_finished, model);
+ model->details->finished_id = g_idle_add ((GSourceFunc) search_finished, model);
}
static void
-model_directory_ready_cb (NautilusDirectory *directory,
- GList *list,
- gpointer user_data)
+model_directory_ready_cb (NautilusDirectory *directory,
+ GList *list,
+ gpointer user_data)
{
- NautilusSearchEngineModel *model = user_data;
- gchar *uri, *display_name;
- GList *files, *hits, *mime_types, *l, *m;
- NautilusFile *file;
- gdouble match;
- gboolean found;
- NautilusSearchHit *hit;
- GDateTime *initial_date;
- GDateTime *end_date;
- GPtrArray *date_range;
-
- files = nautilus_directory_get_file_list (directory);
- mime_types = nautilus_query_get_mime_types (model->details->query);
- hits = NULL;
-
- for (l = files; l != NULL; l = l->next) {
- file = l->data;
-
- display_name = nautilus_file_get_display_name (file);
- match = nautilus_query_matches_string (model->details->query, display_name);
- found = (match > -1);
-
- if (found && mime_types) {
- found = FALSE;
-
- for (m = mime_types; m != NULL; m = m->next) {
- if (nautilus_file_is_mime_type (file, m->data)) {
- found = TRUE;
- break;
- }
- }
- }
-
- date_range = nautilus_query_get_date_range (model->details->query);
- if (found && date_range != NULL) {
- NautilusQuerySearchType type;
- guint64 current_file_unix_time;
-
- type = nautilus_query_get_search_type (model->details->query);
- initial_date = g_ptr_array_index (date_range, 0);
- end_date = g_ptr_array_index (date_range, 1);
-
- if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS) {
- current_file_unix_time = nautilus_file_get_atime (file);
- } else {
- current_file_unix_time = nautilus_file_get_mtime (file);
- }
-
- found = nautilus_file_date_in_between (current_file_unix_time,
- initial_date,
- end_date);
- g_ptr_array_unref (date_range);
+ NautilusSearchEngineModel *model = user_data;
+ gchar *uri, *display_name;
+ GList *files, *hits, *mime_types, *l, *m;
+ NautilusFile *file;
+ gdouble match;
+ gboolean found;
+ NautilusSearchHit *hit;
+ GDateTime *initial_date;
+ GDateTime *end_date;
+ GPtrArray *date_range;
+
+ files = nautilus_directory_get_file_list (directory);
+ mime_types = nautilus_query_get_mime_types (model->details->query);
+ hits = NULL;
+
+ for (l = files; l != NULL; l = l->next)
+ {
+ file = l->data;
+
+ display_name = nautilus_file_get_display_name (file);
+ match = nautilus_query_matches_string (model->details->query, display_name);
+ found = (match > -1);
+
+ if (found && mime_types)
+ {
+ found = FALSE;
+
+ for (m = mime_types; m != NULL; m = m->next)
+ {
+ if (nautilus_file_is_mime_type (file, m->data))
+ {
+ found = TRUE;
+ break;
}
+ }
+ }
- if (found) {
- uri = nautilus_file_get_uri (file);
- hit = nautilus_search_hit_new (uri);
- nautilus_search_hit_set_fts_rank (hit, match);
- hits = g_list_prepend (hits, hit);
- g_free (uri);
- }
+ date_range = nautilus_query_get_date_range (model->details->query);
+ if (found && date_range != NULL)
+ {
+ NautilusQuerySearchType type;
+ guint64 current_file_unix_time;
+
+ type = nautilus_query_get_search_type (model->details->query);
+ initial_date = g_ptr_array_index (date_range, 0);
+ end_date = g_ptr_array_index (date_range, 1);
+
+ if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+ {
+ current_file_unix_time = nautilus_file_get_atime (file);
+ }
+ else
+ {
+ current_file_unix_time = nautilus_file_get_mtime (file);
+ }
+
+ found = nautilus_file_date_in_between (current_file_unix_time,
+ initial_date,
+ end_date);
+ g_ptr_array_unref (date_range);
+ }
+
+ if (found)
+ {
+ uri = nautilus_file_get_uri (file);
+ hit = nautilus_search_hit_new (uri);
+ nautilus_search_hit_set_fts_rank (hit, match);
+ hits = g_list_prepend (hits, hit);
+ g_free (uri);
+ }
- g_free (display_name);
- }
+ g_free (display_name);
+ }
- g_list_free_full (mime_types, g_free);
- nautilus_file_list_free (files);
- model->details->hits = hits;
+ g_list_free_full (mime_types, g_free);
+ nautilus_file_list_free (files);
+ model->details->hits = hits;
- search_finished (model);
+ search_finished (model);
}
static void
nautilus_search_engine_model_start (NautilusSearchProvider *provider)
{
- NautilusSearchEngineModel *model;
+ NautilusSearchEngineModel *model;
- model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
+ model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
- if (model->details->query_pending) {
- return;
- }
+ if (model->details->query_pending)
+ {
+ return;
+ }
- DEBUG ("Model engine start");
+ DEBUG ("Model engine start");
- g_object_ref (model);
- model->details->query_pending = TRUE;
+ g_object_ref (model);
+ model->details->query_pending = TRUE;
- g_object_notify (G_OBJECT (provider), "running");
+ g_object_notify (G_OBJECT (provider), "running");
- if (model->details->directory == NULL) {
- search_finished_idle (model);
- return;
- }
+ if (model->details->directory == NULL)
+ {
+ search_finished_idle (model);
+ return;
+ }
- nautilus_directory_call_when_ready (model->details->directory,
- NAUTILUS_FILE_ATTRIBUTE_INFO,
- TRUE, model_directory_ready_cb, model);
+ nautilus_directory_call_when_ready (model->details->directory,
+ NAUTILUS_FILE_ATTRIBUTE_INFO,
+ TRUE, model_directory_ready_cb, model);
}
static void
nautilus_search_engine_model_stop (NautilusSearchProvider *provider)
{
- NautilusSearchEngineModel *model;
+ NautilusSearchEngineModel *model;
- model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
+ model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
- if (model->details->query_pending) {
- DEBUG ("Model engine stop");
+ if (model->details->query_pending)
+ {
+ DEBUG ("Model engine stop");
- nautilus_directory_cancel_callback (model->details->directory,
- model_directory_ready_cb, model);
- search_finished_idle (model);
- }
+ nautilus_directory_cancel_callback (model->details->directory,
+ model_directory_ready_cb, model);
+ search_finished_idle (model);
+ }
- g_clear_object (&model->details->directory);
+ g_clear_object (&model->details->directory);
}
static void
nautilus_search_engine_model_set_query (NautilusSearchProvider *provider,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- NautilusSearchEngineModel *model;
+ NautilusSearchEngineModel *model;
- model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
+ model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
- g_object_ref (query);
- g_clear_object (&model->details->query);
- model->details->query = query;
+ g_object_ref (query);
+ g_clear_object (&model->details->query);
+ model->details->query = query;
}
static gboolean
nautilus_search_engine_model_is_running (NautilusSearchProvider *provider)
{
- NautilusSearchEngineModel *model;
+ NautilusSearchEngineModel *model;
- model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
+ model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
- return model->details->query_pending;
+ return model->details->query_pending;
}
static void
nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
{
- iface->set_query = nautilus_search_engine_model_set_query;
- iface->start = nautilus_search_engine_model_start;
- iface->stop = nautilus_search_engine_model_stop;
- iface->is_running = nautilus_search_engine_model_is_running;
+ iface->set_query = nautilus_search_engine_model_set_query;
+ iface->start = nautilus_search_engine_model_start;
+ iface->stop = nautilus_search_engine_model_stop;
+ iface->is_running = nautilus_search_engine_model_is_running;
}
static void
@@ -277,64 +295,67 @@ nautilus_search_engine_model_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
+ NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_RUNNING:
- g_value_set_boolean (value, nautilus_search_engine_model_is_running (self));
- break;
+ {
+ g_value_set_boolean (value, nautilus_search_engine_model_is_running (self));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
nautilus_search_engine_model_class_init (NautilusSearchEngineModelClass *class)
{
- GObjectClass *gobject_class;
+ GObjectClass *gobject_class;
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->finalize = finalize;
- gobject_class->get_property = nautilus_search_engine_model_get_property;
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->finalize = finalize;
+ gobject_class->get_property = nautilus_search_engine_model_get_property;
- /**
- * NautilusSearchEngine::running:
- *
- * Whether the search engine is running a search.
- */
- g_object_class_override_property (gobject_class, PROP_RUNNING, "running");
+ /**
+ * NautilusSearchEngine::running:
+ *
+ * Whether the search engine is running a search.
+ */
+ g_object_class_override_property (gobject_class, PROP_RUNNING, "running");
- g_type_class_add_private (class, sizeof (NautilusSearchEngineModelDetails));
+ g_type_class_add_private (class, sizeof (NautilusSearchEngineModelDetails));
}
static void
nautilus_search_engine_model_init (NautilusSearchEngineModel *engine)
{
- engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_MODEL,
- NautilusSearchEngineModelDetails);
+ engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_MODEL,
+ NautilusSearchEngineModelDetails);
}
NautilusSearchEngineModel *
nautilus_search_engine_model_new (void)
{
- NautilusSearchEngineModel *engine;
+ NautilusSearchEngineModel *engine;
- engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_MODEL, NULL);
+ engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_MODEL, NULL);
- return engine;
+ return engine;
}
void
nautilus_search_engine_model_set_model (NautilusSearchEngineModel *model,
- NautilusDirectory *directory)
+ NautilusDirectory *directory)
{
- g_clear_object (&model->details->directory);
- model->details->directory = nautilus_directory_ref (directory);
+ g_clear_object (&model->details->directory);
+ model->details->directory = nautilus_directory_ref (directory);
}
NautilusDirectory *
nautilus_search_engine_model_get_model (NautilusSearchEngineModel *model)
{
- return model->details->directory;
+ return model->details->directory;
}
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index 253185aac..7aea120f0 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -33,493 +33,540 @@
#define BATCH_SIZE 500
-enum {
- PROP_RECURSIVE = 1,
- PROP_RUNNING,
- NUM_PROPERTIES
+enum
+{
+ PROP_RECURSIVE = 1,
+ PROP_RUNNING,
+ NUM_PROPERTIES
};
-typedef struct {
- NautilusSearchEngineSimple *engine;
- GCancellable *cancellable;
+typedef struct
+{
+ NautilusSearchEngineSimple *engine;
+ GCancellable *cancellable;
- GList *mime_types;
- GList *found_list;
+ GList *mime_types;
+ GList *found_list;
- GQueue *directories; /* GFiles */
+ GQueue *directories; /* GFiles */
- GHashTable *visited;
+ GHashTable *visited;
- gboolean recursive;
- gint n_processed_files;
- GList *hits;
+ gboolean recursive;
+ gint n_processed_files;
+ GList *hits;
- NautilusQuery *query;
+ NautilusQuery *query;
} SearchThreadData;
-struct NautilusSearchEngineSimpleDetails {
- NautilusQuery *query;
+struct NautilusSearchEngineSimpleDetails
+{
+ NautilusQuery *query;
- SearchThreadData *active_search;
+ SearchThreadData *active_search;
- gboolean recursive;
- gboolean query_finished;
+ gboolean recursive;
+ gboolean query_finished;
};
static void nautilus_search_provider_init (NautilusSearchProviderInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngineSimple,
- nautilus_search_engine_simple,
- G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
- nautilus_search_provider_init))
+ nautilus_search_engine_simple,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
+ nautilus_search_provider_init))
static void
finalize (GObject *object)
{
- NautilusSearchEngineSimple *simple;
+ NautilusSearchEngineSimple *simple;
- simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
- g_clear_object (&simple->details->query);
+ simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
+ g_clear_object (&simple->details->query);
- G_OBJECT_CLASS (nautilus_search_engine_simple_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_engine_simple_parent_class)->finalize (object);
}
static SearchThreadData *
search_thread_data_new (NautilusSearchEngineSimple *engine,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- SearchThreadData *data;
- GFile *location;
-
- data = g_new0 (SearchThreadData, 1);
+ SearchThreadData *data;
+ GFile *location;
- data->engine = g_object_ref (engine);
- data->directories = g_queue_new ();
- data->visited = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
- data->query = g_object_ref (query);
+ data = g_new0 (SearchThreadData, 1);
- location = nautilus_query_get_location (query);
+ data->engine = g_object_ref (engine);
+ data->directories = g_queue_new ();
+ data->visited = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ data->query = g_object_ref (query);
- g_queue_push_tail (data->directories, location);
- data->mime_types = nautilus_query_get_mime_types (query);
+ location = nautilus_query_get_location (query);
- data->cancellable = g_cancellable_new ();
-
- return data;
+ g_queue_push_tail (data->directories, location);
+ data->mime_types = nautilus_query_get_mime_types (query);
+
+ data->cancellable = g_cancellable_new ();
+
+ return data;
}
-static void
+static void
search_thread_data_free (SearchThreadData *data)
{
- g_queue_foreach (data->directories,
- (GFunc)g_object_unref, NULL);
- g_queue_free (data->directories);
- g_hash_table_destroy (data->visited);
- g_object_unref (data->cancellable);
- g_object_unref (data->query);
- g_list_free_full (data->mime_types, g_free);
- g_list_free_full (data->hits, g_object_unref);
- g_object_unref (data->engine);
-
- g_free (data);
+ g_queue_foreach (data->directories,
+ (GFunc) g_object_unref, NULL);
+ g_queue_free (data->directories);
+ g_hash_table_destroy (data->visited);
+ g_object_unref (data->cancellable);
+ g_object_unref (data->query);
+ g_list_free_full (data->mime_types, g_free);
+ g_list_free_full (data->hits, g_object_unref);
+ g_object_unref (data->engine);
+
+ g_free (data);
}
static gboolean
search_thread_done_idle (gpointer user_data)
{
- SearchThreadData *data = user_data;
- NautilusSearchEngineSimple *engine = data->engine;
+ SearchThreadData *data = user_data;
+ NautilusSearchEngineSimple *engine = data->engine;
- if (g_cancellable_is_cancelled (data->cancellable)) {
- DEBUG ("Simple engine finished and cancelled");
- } else {
- DEBUG ("Simple engine finished");
- }
- engine->details->active_search = NULL;
- nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (engine),
- NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
+ if (g_cancellable_is_cancelled (data->cancellable))
+ {
+ DEBUG ("Simple engine finished and cancelled");
+ }
+ else
+ {
+ DEBUG ("Simple engine finished");
+ }
+ engine->details->active_search = NULL;
+ nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (engine),
+ NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
- g_object_notify (G_OBJECT (engine), "running");
+ g_object_notify (G_OBJECT (engine), "running");
- search_thread_data_free (data);
+ search_thread_data_free (data);
- return FALSE;
+ return FALSE;
}
-typedef struct {
- GList *hits;
- SearchThreadData *thread_data;
+typedef struct
+{
+ GList *hits;
+ SearchThreadData *thread_data;
} SearchHitsData;
static gboolean
search_thread_add_hits_idle (gpointer user_data)
{
- SearchHitsData *data = user_data;
-
- if (!g_cancellable_is_cancelled (data->thread_data->cancellable)) {
- DEBUG ("Simple engine add hits");
- nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (data->thread_data->engine),
- data->hits);
- }
-
- g_list_free_full (data->hits, g_object_unref);
- g_free (data);
-
- return FALSE;
+ SearchHitsData *data = user_data;
+
+ if (!g_cancellable_is_cancelled (data->thread_data->cancellable))
+ {
+ DEBUG ("Simple engine add hits");
+ nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (data->thread_data->engine),
+ data->hits);
+ }
+
+ g_list_free_full (data->hits, g_object_unref);
+ g_free (data);
+
+ return FALSE;
}
static void
send_batch (SearchThreadData *thread_data)
{
- SearchHitsData *data;
-
- thread_data->n_processed_files = 0;
-
- if (thread_data->hits) {
- data = g_new (SearchHitsData, 1);
- data->hits = thread_data->hits;
- data->thread_data = thread_data;
- g_idle_add (search_thread_add_hits_idle, data);
- }
- thread_data->hits = NULL;
+ SearchHitsData *data;
+
+ thread_data->n_processed_files = 0;
+
+ if (thread_data->hits)
+ {
+ data = g_new (SearchHitsData, 1);
+ data->hits = thread_data->hits;
+ data->thread_data = thread_data;
+ g_idle_add (search_thread_add_hits_idle, data);
+ }
+ thread_data->hits = NULL;
}
#define STD_ATTRIBUTES \
- G_FILE_ATTRIBUTE_STANDARD_NAME "," \
- G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," \
- G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," \
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \
- G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
- G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
- G_FILE_ATTRIBUTE_TIME_ACCESS "," \
- G_FILE_ATTRIBUTE_ID_FILE
+ G_FILE_ATTRIBUTE_STANDARD_NAME "," \
+ G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," \
+ G_FILE_ATTRIBUTE_STANDARD_IS_BACKUP "," \
+ G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," \
+ G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
+ G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
+ G_FILE_ATTRIBUTE_TIME_ACCESS "," \
+ G_FILE_ATTRIBUTE_ID_FILE
static void
-visit_directory (GFile *dir, SearchThreadData *data)
+visit_directory (GFile *dir,
+ SearchThreadData *data)
{
- GFileEnumerator *enumerator;
- GFileInfo *info;
- GFile *child;
- const char *mime_type, *display_name;
- gdouble match;
- gboolean is_hidden, found;
- GList *l;
- const char *id;
- gboolean visited;
- guint64 atime;
- guint64 mtime;
- GPtrArray *date_range;
- GDateTime *initial_date;
- GDateTime *end_date;
-
-
- enumerator = g_file_enumerate_children (dir,
- data->mime_types != NULL ?
- STD_ATTRIBUTES ","
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
- :
- STD_ATTRIBUTES
- ,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- data->cancellable, NULL);
-
- if (enumerator == NULL) {
- return;
- }
-
- while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL) {
- display_name = g_file_info_get_display_name (info);
- if (display_name == NULL) {
- goto next;
- }
-
- is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
- if (is_hidden && !nautilus_query_get_show_hidden_files (data->query)) {
- goto next;
- }
-
- child = g_file_get_child (dir, g_file_info_get_name (info));
- match = nautilus_query_matches_string (data->query, display_name);
- found = (match > -1);
-
- if (found && data->mime_types) {
- mime_type = g_file_info_get_content_type (info);
- found = FALSE;
-
- for (l = data->mime_types; mime_type != NULL && l != NULL; l = l->next) {
- if (g_content_type_is_a (mime_type, l->data)) {
- found = TRUE;
- break;
- }
- }
- }
-
- mtime = g_file_info_get_attribute_uint64 (info, "time::modified");
- atime = g_file_info_get_attribute_uint64 (info, "time::access");
-
- date_range = nautilus_query_get_date_range (data->query);
- if (found && date_range != NULL) {
- NautilusQuerySearchType type;
- guint64 current_file_time;
-
- initial_date = g_ptr_array_index (date_range, 0);
- end_date = g_ptr_array_index (date_range, 1);
- type = nautilus_query_get_search_type (data->query);
-
- if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS) {
- current_file_time = atime;
- } else {
- current_file_time = mtime;
- }
- found = nautilus_file_date_in_between (current_file_time,
- initial_date,
- end_date);
- g_ptr_array_unref (date_range);
+ GFileEnumerator *enumerator;
+ GFileInfo *info;
+ GFile *child;
+ const char *mime_type, *display_name;
+ gdouble match;
+ gboolean is_hidden, found;
+ GList *l;
+ const char *id;
+ gboolean visited;
+ guint64 atime;
+ guint64 mtime;
+ GPtrArray *date_range;
+ GDateTime *initial_date;
+ GDateTime *end_date;
+
+
+ enumerator = g_file_enumerate_children (dir,
+ data->mime_types != NULL ?
+ STD_ATTRIBUTES ","
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
+ :
+ STD_ATTRIBUTES
+ ,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ data->cancellable, NULL);
+
+ if (enumerator == NULL)
+ {
+ return;
+ }
+
+ while ((info = g_file_enumerator_next_file (enumerator, data->cancellable, NULL)) != NULL)
+ {
+ display_name = g_file_info_get_display_name (info);
+ if (display_name == NULL)
+ {
+ goto next;
+ }
+
+ is_hidden = g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info);
+ if (is_hidden && !nautilus_query_get_show_hidden_files (data->query))
+ {
+ goto next;
+ }
+
+ child = g_file_get_child (dir, g_file_info_get_name (info));
+ match = nautilus_query_matches_string (data->query, display_name);
+ found = (match > -1);
+
+ if (found && data->mime_types)
+ {
+ mime_type = g_file_info_get_content_type (info);
+ found = FALSE;
+
+ for (l = data->mime_types; mime_type != NULL && l != NULL; l = l->next)
+ {
+ if (g_content_type_is_a (mime_type, l->data))
+ {
+ found = TRUE;
+ break;
}
+ }
+ }
+
+ mtime = g_file_info_get_attribute_uint64 (info, "time::modified");
+ atime = g_file_info_get_attribute_uint64 (info, "time::access");
+
+ date_range = nautilus_query_get_date_range (data->query);
+ if (found && date_range != NULL)
+ {
+ NautilusQuerySearchType type;
+ guint64 current_file_time;
+
+ initial_date = g_ptr_array_index (date_range, 0);
+ end_date = g_ptr_array_index (date_range, 1);
+ type = nautilus_query_get_search_type (data->query);
+
+ if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+ {
+ current_file_time = atime;
+ }
+ else
+ {
+ current_file_time = mtime;
+ }
+ found = nautilus_file_date_in_between (current_file_time,
+ initial_date,
+ end_date);
+ g_ptr_array_unref (date_range);
+ }
- if (found) {
- NautilusSearchHit *hit;
- GDateTime *date;
- char *uri;
-
- uri = g_file_get_uri (child);
- hit = nautilus_search_hit_new (uri);
- g_free (uri);
- nautilus_search_hit_set_fts_rank (hit, match);
- date = g_date_time_new_from_unix_local (mtime);
- nautilus_search_hit_set_modification_time (hit, date);
- g_date_time_unref (date);
-
- data->hits = g_list_prepend (data->hits, hit);
- }
-
- data->n_processed_files++;
- if (data->n_processed_files > BATCH_SIZE) {
- send_batch (data);
- }
-
- if (data->engine->details->recursive && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) {
- id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE);
- visited = FALSE;
- if (id) {
- if (g_hash_table_lookup_extended (data->visited,
- id, NULL, NULL)) {
- visited = TRUE;
- } else {
- g_hash_table_insert (data->visited, g_strdup (id), NULL);
- }
- }
-
- if (!visited) {
- g_queue_push_tail (data->directories, g_object_ref (child));
- }
- }
-
- g_object_unref (child);
- next:
- g_object_unref (info);
- }
-
- g_object_unref (enumerator);
+ if (found)
+ {
+ NautilusSearchHit *hit;
+ GDateTime *date;
+ char *uri;
+
+ uri = g_file_get_uri (child);
+ hit = nautilus_search_hit_new (uri);
+ g_free (uri);
+ nautilus_search_hit_set_fts_rank (hit, match);
+ date = g_date_time_new_from_unix_local (mtime);
+ nautilus_search_hit_set_modification_time (hit, date);
+ g_date_time_unref (date);
+
+ data->hits = g_list_prepend (data->hits, hit);
+ }
+
+ data->n_processed_files++;
+ if (data->n_processed_files > BATCH_SIZE)
+ {
+ send_batch (data);
+ }
+
+ if (data->engine->details->recursive && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE);
+ visited = FALSE;
+ if (id)
+ {
+ if (g_hash_table_lookup_extended (data->visited,
+ id, NULL, NULL))
+ {
+ visited = TRUE;
+ }
+ else
+ {
+ g_hash_table_insert (data->visited, g_strdup (id), NULL);
+ }
+ }
+
+ if (!visited)
+ {
+ g_queue_push_tail (data->directories, g_object_ref (child));
+ }
+ }
+
+ g_object_unref (child);
+next:
+ g_object_unref (info);
+ }
+
+ g_object_unref (enumerator);
}
-static gpointer
+static gpointer
search_thread_func (gpointer user_data)
{
- SearchThreadData *data;
- GFile *dir;
- GFileInfo *info;
- const char *id;
-
- data = user_data;
-
- /* Insert id for toplevel directory into visited */
- dir = g_queue_peek_head (data->directories);
- info = g_file_query_info (dir, G_FILE_ATTRIBUTE_ID_FILE, 0, data->cancellable, NULL);
- if (info) {
- id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE);
- if (id) {
- g_hash_table_insert (data->visited, g_strdup (id), NULL);
- }
- g_object_unref (info);
- }
-
- while (!g_cancellable_is_cancelled (data->cancellable) &&
- (dir = g_queue_pop_head (data->directories)) != NULL) {
- visit_directory (dir, data);
- g_object_unref (dir);
- }
-
- if (!g_cancellable_is_cancelled (data->cancellable)) {
- send_batch (data);
- }
-
- g_idle_add (search_thread_done_idle, data);
-
- return NULL;
+ SearchThreadData *data;
+ GFile *dir;
+ GFileInfo *info;
+ const char *id;
+
+ data = user_data;
+
+ /* Insert id for toplevel directory into visited */
+ dir = g_queue_peek_head (data->directories);
+ info = g_file_query_info (dir, G_FILE_ATTRIBUTE_ID_FILE, 0, data->cancellable, NULL);
+ if (info)
+ {
+ id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILE);
+ if (id)
+ {
+ g_hash_table_insert (data->visited, g_strdup (id), NULL);
+ }
+ g_object_unref (info);
+ }
+
+ while (!g_cancellable_is_cancelled (data->cancellable) &&
+ (dir = g_queue_pop_head (data->directories)) != NULL)
+ {
+ visit_directory (dir, data);
+ g_object_unref (dir);
+ }
+
+ if (!g_cancellable_is_cancelled (data->cancellable))
+ {
+ send_batch (data);
+ }
+
+ g_idle_add (search_thread_done_idle, data);
+
+ return NULL;
}
static void
nautilus_search_engine_simple_start (NautilusSearchProvider *provider)
{
- NautilusSearchEngineSimple *simple;
- SearchThreadData *data;
- GThread *thread;
-
- simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
+ NautilusSearchEngineSimple *simple;
+ SearchThreadData *data;
+ GThread *thread;
+
+ simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
- if (simple->details->active_search != NULL) {
- return;
- }
+ if (simple->details->active_search != NULL)
+ {
+ return;
+ }
- DEBUG ("Simple engine start");
-
- data = search_thread_data_new (simple, simple->details->query);
+ DEBUG ("Simple engine start");
- thread = g_thread_new ("nautilus-search-simple", search_thread_func, data);
- simple->details->active_search = data;
+ data = search_thread_data_new (simple, simple->details->query);
- g_object_notify (G_OBJECT (provider), "running");
+ thread = g_thread_new ("nautilus-search-simple", search_thread_func, data);
+ simple->details->active_search = data;
- g_thread_unref (thread);
+ g_object_notify (G_OBJECT (provider), "running");
+
+ g_thread_unref (thread);
}
static void
nautilus_search_engine_simple_stop (NautilusSearchProvider *provider)
{
- NautilusSearchEngineSimple *simple;
+ NautilusSearchEngineSimple *simple;
- simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
+ simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
- if (simple->details->active_search != NULL) {
- DEBUG ("Simple engine stop");
- g_cancellable_cancel (simple->details->active_search->cancellable);
- }
+ if (simple->details->active_search != NULL)
+ {
+ DEBUG ("Simple engine stop");
+ g_cancellable_cancel (simple->details->active_search->cancellable);
+ }
}
static void
nautilus_search_engine_simple_set_query (NautilusSearchProvider *provider,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- NautilusSearchEngineSimple *simple;
+ NautilusSearchEngineSimple *simple;
- simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
+ simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
- g_object_ref (query);
- g_clear_object (&simple->details->query);
- simple->details->query = query;
+ g_object_ref (query);
+ g_clear_object (&simple->details->query);
+ simple->details->query = query;
}
static gboolean
nautilus_search_engine_simple_is_running (NautilusSearchProvider *provider)
{
- NautilusSearchEngineSimple *simple;
+ NautilusSearchEngineSimple *simple;
- simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
+ simple = NAUTILUS_SEARCH_ENGINE_SIMPLE (provider);
- return simple->details->active_search != NULL;
+ return simple->details->active_search != NULL;
}
static void
-nautilus_search_engine_simple_set_property (GObject *object,
- guint arg_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_search_engine_simple_set_property (GObject *object,
+ guint arg_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusSearchEngineSimple *engine;
-
- engine = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
-
- switch (arg_id) {
- case PROP_RECURSIVE:
- engine->details->recursive = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
- break;
- }
+ NautilusSearchEngineSimple *engine;
+
+ engine = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
+
+ switch (arg_id)
+ {
+ case PROP_RECURSIVE:
+ {
+ engine->details->recursive = g_value_get_boolean (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_search_engine_simple_get_property (GObject *object,
- guint arg_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_search_engine_simple_get_property (GObject *object,
+ guint arg_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusSearchEngineSimple *engine;
-
- engine = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
-
- switch (arg_id) {
- case PROP_RUNNING:
- g_value_set_boolean (value, nautilus_search_engine_simple_is_running (NAUTILUS_SEARCH_PROVIDER (engine)));
- break;
- case PROP_RECURSIVE:
- g_value_set_boolean (value, engine->details->recursive);
- break;
- }
+ NautilusSearchEngineSimple *engine;
+
+ engine = NAUTILUS_SEARCH_ENGINE_SIMPLE (object);
+
+ switch (arg_id)
+ {
+ case PROP_RUNNING:
+ {
+ g_value_set_boolean (value, nautilus_search_engine_simple_is_running (NAUTILUS_SEARCH_PROVIDER (engine)));
+ }
+ break;
+
+ case PROP_RECURSIVE:
+ {
+ g_value_set_boolean (value, engine->details->recursive);
+ }
+ break;
+ }
}
static void
nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
{
- iface->set_query = nautilus_search_engine_simple_set_query;
- iface->start = nautilus_search_engine_simple_start;
- iface->stop = nautilus_search_engine_simple_stop;
- iface->is_running = nautilus_search_engine_simple_is_running;
+ iface->set_query = nautilus_search_engine_simple_set_query;
+ iface->start = nautilus_search_engine_simple_start;
+ iface->stop = nautilus_search_engine_simple_stop;
+ iface->is_running = nautilus_search_engine_simple_is_running;
}
static void
nautilus_search_engine_simple_class_init (NautilusSearchEngineSimpleClass *class)
{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->finalize = finalize;
- gobject_class->get_property = nautilus_search_engine_simple_get_property;
- gobject_class->set_property = nautilus_search_engine_simple_set_property;
-
- /**
- * NautilusSearchEngineSimple::recursive:
- *
- * Whether the search is recursive or not.
- */
- g_object_class_install_property (gobject_class,
- PROP_RECURSIVE,
- g_param_spec_boolean ("recursive",
- "recursive",
- "recursive",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
-
- /**
- * NautilusSearchEngine::running:
- *
- * Whether the search engine is running a search.
- */
- g_object_class_override_property (gobject_class, PROP_RUNNING, "running");
-
- g_type_class_add_private (class, sizeof (NautilusSearchEngineSimpleDetails));
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->finalize = finalize;
+ gobject_class->get_property = nautilus_search_engine_simple_get_property;
+ gobject_class->set_property = nautilus_search_engine_simple_set_property;
+
+ /**
+ * NautilusSearchEngineSimple::recursive:
+ *
+ * Whether the search is recursive or not.
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_RECURSIVE,
+ g_param_spec_boolean ("recursive",
+ "recursive",
+ "recursive",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
+
+ /**
+ * NautilusSearchEngine::running:
+ *
+ * Whether the search engine is running a search.
+ */
+ g_object_class_override_property (gobject_class, PROP_RUNNING, "running");
+
+ g_type_class_add_private (class, sizeof (NautilusSearchEngineSimpleDetails));
}
static void
nautilus_search_engine_simple_init (NautilusSearchEngineSimple *engine)
{
- engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_SIMPLE,
- NautilusSearchEngineSimpleDetails);
+ engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_SIMPLE,
+ NautilusSearchEngineSimpleDetails);
}
NautilusSearchEngineSimple *
nautilus_search_engine_simple_new (void)
{
- NautilusSearchEngineSimple *engine;
+ NautilusSearchEngineSimple *engine;
- engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_SIMPLE, NULL);
+ engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_SIMPLE, NULL);
- return engine;
+ return engine;
}
diff --git a/src/nautilus-search-engine-tracker.c b/src/nautilus-search-engine-tracker.c
index 680acf250..3bba5558e 100644
--- a/src/nautilus-search-engine-tracker.c
+++ b/src/nautilus-search-engine-tracker.c
@@ -32,120 +32,134 @@
#include <gio/gio.h>
#include <libtracker-sparql/tracker-sparql.h>
-struct NautilusSearchEngineTrackerDetails {
- TrackerSparqlConnection *connection;
- NautilusQuery *query;
+struct NautilusSearchEngineTrackerDetails
+{
+ TrackerSparqlConnection *connection;
+ NautilusQuery *query;
- gboolean query_pending;
- GQueue *hits_pending;
+ gboolean query_pending;
+ GQueue *hits_pending;
- gboolean recursive;
+ gboolean recursive;
- GCancellable *cancellable;
+ GCancellable *cancellable;
};
-enum {
- PROP_0,
- PROP_RUNNING,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_RUNNING,
+ LAST_PROP
};
static void nautilus_search_provider_init (NautilusSearchProviderInterface *iface);
G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngineTracker,
- nautilus_search_engine_tracker,
- G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
- nautilus_search_provider_init))
+ nautilus_search_engine_tracker,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
+ nautilus_search_provider_init))
static void
finalize (GObject *object)
{
- NautilusSearchEngineTracker *tracker;
+ NautilusSearchEngineTracker *tracker;
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (object);
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (object);
- if (tracker->details->cancellable) {
- g_cancellable_cancel (tracker->details->cancellable);
- g_clear_object (&tracker->details->cancellable);
- }
+ if (tracker->details->cancellable)
+ {
+ g_cancellable_cancel (tracker->details->cancellable);
+ g_clear_object (&tracker->details->cancellable);
+ }
- g_clear_object (&tracker->details->query);
- g_clear_object (&tracker->details->connection);
- g_queue_free_full (tracker->details->hits_pending, g_object_unref);
+ g_clear_object (&tracker->details->query);
+ g_clear_object (&tracker->details->connection);
+ g_queue_free_full (tracker->details->hits_pending, g_object_unref);
- G_OBJECT_CLASS (nautilus_search_engine_tracker_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_engine_tracker_parent_class)->finalize (object);
}
#define BATCH_SIZE 100
static void
check_pending_hits (NautilusSearchEngineTracker *tracker,
- gboolean force_send)
+ gboolean force_send)
{
- GList *hits = NULL;
- NautilusSearchHit *hit;
+ GList *hits = NULL;
+ NautilusSearchHit *hit;
- DEBUG ("Tracker engine add hits");
+ DEBUG ("Tracker engine add hits");
- if (!force_send &&
- g_queue_get_length (tracker->details->hits_pending) < BATCH_SIZE) {
- return;
- }
+ if (!force_send &&
+ g_queue_get_length (tracker->details->hits_pending) < BATCH_SIZE)
+ {
+ return;
+ }
- while ((hit = g_queue_pop_head (tracker->details->hits_pending))) {
- hits = g_list_prepend (hits, hit);
- }
+ while ((hit = g_queue_pop_head (tracker->details->hits_pending)))
+ {
+ hits = g_list_prepend (hits, hit);
+ }
- nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (tracker), hits);
- g_list_free_full (hits, g_object_unref);
+ nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (tracker), hits);
+ g_list_free_full (hits, g_object_unref);
}
static void
search_finished (NautilusSearchEngineTracker *tracker,
- GError *error)
+ GError *error)
{
- DEBUG ("Tracker engine finished");
-
- if (error == NULL) {
- check_pending_hits (tracker, TRUE);
- } else {
- g_queue_foreach (tracker->details->hits_pending, (GFunc) g_object_unref, NULL);
- g_queue_clear (tracker->details->hits_pending);
- }
-
- tracker->details->query_pending = FALSE;
-
- g_object_notify (G_OBJECT (tracker), "running");
-
- if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- DEBUG ("Tracker engine error %s", error->message);
- nautilus_search_provider_error (NAUTILUS_SEARCH_PROVIDER (tracker), error->message);
- } else {
- nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (tracker),
- NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
- DEBUG ("Tracker engine finished and cancelled");
- } else {
- DEBUG ("Tracker engine finished correctly");
- }
- }
-
- g_object_unref (tracker);
+ DEBUG ("Tracker engine finished");
+
+ if (error == NULL)
+ {
+ check_pending_hits (tracker, TRUE);
+ }
+ else
+ {
+ g_queue_foreach (tracker->details->hits_pending, (GFunc) g_object_unref, NULL);
+ g_queue_clear (tracker->details->hits_pending);
+ }
+
+ tracker->details->query_pending = FALSE;
+
+ g_object_notify (G_OBJECT (tracker), "running");
+
+ if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ DEBUG ("Tracker engine error %s", error->message);
+ nautilus_search_provider_error (NAUTILUS_SEARCH_PROVIDER (tracker), error->message);
+ }
+ else
+ {
+ nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (tracker),
+ NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ DEBUG ("Tracker engine finished and cancelled");
+ }
+ else
+ {
+ DEBUG ("Tracker engine finished correctly");
+ }
+ }
+
+ g_object_unref (tracker);
}
static void cursor_callback (GObject *object,
- GAsyncResult *result,
- gpointer user_data);
+ GAsyncResult *result,
+ gpointer user_data);
static void
cursor_next (NautilusSearchEngineTracker *tracker,
- TrackerSparqlCursor *cursor)
+ TrackerSparqlCursor *cursor)
{
- tracker_sparql_cursor_next_async (cursor,
- tracker->details->cancellable,
- cursor_callback,
- tracker);
+ tracker_sparql_cursor_next_async (cursor,
+ tracker->details->cancellable,
+ cursor_callback,
+ tracker);
}
static void
@@ -153,66 +167,73 @@ cursor_callback (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- NautilusSearchEngineTracker *tracker;
- GError *error = NULL;
- TrackerSparqlCursor *cursor;
- NautilusSearchHit *hit;
- const char *uri;
- const char *mtime_str;
- const char *atime_str;
- GTimeVal tv;
- gdouble rank, match;
- gboolean success;
- gchar *basename;
-
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (user_data);
-
- cursor = TRACKER_SPARQL_CURSOR (object);
- success = tracker_sparql_cursor_next_finish (cursor, result, &error);
-
- if (!success) {
- search_finished (tracker, error);
-
- g_clear_error (&error);
- g_clear_object (&cursor);
-
- return;
- }
-
- /* We iterate result by result, not n at a time. */
- uri = tracker_sparql_cursor_get_string (cursor, 0, NULL);
- rank = tracker_sparql_cursor_get_double (cursor, 1);
- mtime_str = tracker_sparql_cursor_get_string (cursor, 2, NULL);
- atime_str = tracker_sparql_cursor_get_string (cursor, 3, NULL);
- basename = g_path_get_basename (uri);
-
- hit = nautilus_search_hit_new (uri);
- match = nautilus_query_matches_string (tracker->details->query, basename);
- nautilus_search_hit_set_fts_rank (hit, rank + match);
- g_free (basename);
-
- if (g_time_val_from_iso8601 (mtime_str, &tv)) {
- GDateTime *date;
- date = g_date_time_new_from_timeval_local (&tv);
- nautilus_search_hit_set_modification_time (hit, date);
- g_date_time_unref (date);
- } else {
- g_warning ("unable to parse mtime: %s", mtime_str);
- }
- if (g_time_val_from_iso8601 (atime_str, &tv)) {
- GDateTime *date;
- date = g_date_time_new_from_timeval_local (&tv);
- nautilus_search_hit_set_access_time (hit, date);
- g_date_time_unref (date);
- } else {
- g_warning ("unable to parse atime: %s", atime_str);
- }
-
- g_queue_push_head (tracker->details->hits_pending, hit);
- check_pending_hits (tracker, FALSE);
-
- /* Get next */
- cursor_next (tracker, cursor);
+ NautilusSearchEngineTracker *tracker;
+ GError *error = NULL;
+ TrackerSparqlCursor *cursor;
+ NautilusSearchHit *hit;
+ const char *uri;
+ const char *mtime_str;
+ const char *atime_str;
+ GTimeVal tv;
+ gdouble rank, match;
+ gboolean success;
+ gchar *basename;
+
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (user_data);
+
+ cursor = TRACKER_SPARQL_CURSOR (object);
+ success = tracker_sparql_cursor_next_finish (cursor, result, &error);
+
+ if (!success)
+ {
+ search_finished (tracker, error);
+
+ g_clear_error (&error);
+ g_clear_object (&cursor);
+
+ return;
+ }
+
+ /* We iterate result by result, not n at a time. */
+ uri = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+ rank = tracker_sparql_cursor_get_double (cursor, 1);
+ mtime_str = tracker_sparql_cursor_get_string (cursor, 2, NULL);
+ atime_str = tracker_sparql_cursor_get_string (cursor, 3, NULL);
+ basename = g_path_get_basename (uri);
+
+ hit = nautilus_search_hit_new (uri);
+ match = nautilus_query_matches_string (tracker->details->query, basename);
+ nautilus_search_hit_set_fts_rank (hit, rank + match);
+ g_free (basename);
+
+ if (g_time_val_from_iso8601 (mtime_str, &tv))
+ {
+ GDateTime *date;
+ date = g_date_time_new_from_timeval_local (&tv);
+ nautilus_search_hit_set_modification_time (hit, date);
+ g_date_time_unref (date);
+ }
+ else
+ {
+ g_warning ("unable to parse mtime: %s", mtime_str);
+ }
+ if (g_time_val_from_iso8601 (atime_str, &tv))
+ {
+ GDateTime *date;
+ date = g_date_time_new_from_timeval_local (&tv);
+ nautilus_search_hit_set_access_time (hit, date);
+ g_date_time_unref (date);
+ }
+ else
+ {
+ g_warning ("unable to parse atime: %s", atime_str);
+ }
+
+ g_queue_push_head (tracker->details->hits_pending, hit);
+ check_pending_hits (tracker, FALSE);
+
+ /* Get next */
+ cursor_next (tracker, cursor);
}
static void
@@ -220,217 +241,234 @@ query_callback (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
- NautilusSearchEngineTracker *tracker;
- TrackerSparqlConnection *connection;
- TrackerSparqlCursor *cursor;
- GError *error = NULL;
-
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (user_data);
-
- connection = TRACKER_SPARQL_CONNECTION (object);
- cursor = tracker_sparql_connection_query_finish (connection,
- result,
- &error);
-
- if (error != NULL) {
- search_finished (tracker, error);
- g_error_free (error);
- } else {
- cursor_next (tracker, cursor);
- }
+ NautilusSearchEngineTracker *tracker;
+ TrackerSparqlConnection *connection;
+ TrackerSparqlCursor *cursor;
+ GError *error = NULL;
+
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (user_data);
+
+ connection = TRACKER_SPARQL_CONNECTION (object);
+ cursor = tracker_sparql_connection_query_finish (connection,
+ result,
+ &error);
+
+ if (error != NULL)
+ {
+ search_finished (tracker, error);
+ g_error_free (error);
+ }
+ else
+ {
+ cursor_next (tracker, cursor);
+ }
}
static gboolean
search_finished_idle (gpointer user_data)
{
- NautilusSearchEngineTracker *tracker = user_data;
+ NautilusSearchEngineTracker *tracker = user_data;
- DEBUG ("Tracker engine finished idle");
+ DEBUG ("Tracker engine finished idle");
- search_finished (tracker, NULL);
+ search_finished (tracker, NULL);
- return FALSE;
+ return FALSE;
}
static void
nautilus_search_engine_tracker_start (NautilusSearchProvider *provider)
{
- NautilusSearchEngineTracker *tracker;
- gchar *query_text, *search_text, *location_uri, *downcase;
- GFile *location;
- GString *sparql;
- GList *mimetypes, *l;
- gint mime_count;
- gboolean recursive;
- GPtrArray *date_range;
+ NautilusSearchEngineTracker *tracker;
+ gchar *query_text, *search_text, *location_uri, *downcase;
+ GFile *location;
+ GString *sparql;
+ GList *mimetypes, *l;
+ gint mime_count;
+ gboolean recursive;
+ GPtrArray *date_range;
+
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
+
+ if (tracker->details->query_pending)
+ {
+ return;
+ }
+
+ DEBUG ("Tracker engine start");
+ g_object_ref (tracker);
+ tracker->details->query_pending = TRUE;
+
+ g_object_notify (G_OBJECT (provider), "running");
+
+ if (tracker->details->connection == NULL)
+ {
+ g_idle_add (search_finished_idle, provider);
+ return;
+ }
+
+ recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY ||
+ g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS;
+ tracker->details->recursive = recursive;
+
+ query_text = nautilus_query_get_text (tracker->details->query);
+ downcase = g_utf8_strdown (query_text, -1);
+ search_text = tracker_sparql_escape_string (downcase);
+ g_free (query_text);
+ g_free (downcase);
+
+ location = nautilus_query_get_location (tracker->details->query);
+ location_uri = location ? g_file_get_uri (location) : NULL;
+ mimetypes = nautilus_query_get_mime_types (tracker->details->query);
+ mime_count = g_list_length (mimetypes);
+
+ sparql = g_string_new ("SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn) nfo:fileLastAccessed(?urn)\n"
+ "WHERE {"
+ " ?urn a nfo:FileDataObject;"
+ " nfo:fileLastModified ?mtime;"
+ " nfo:fileLastAccessed ?atime;"
+ " tracker:available true;");
+
+ g_string_append_printf (sparql, " fts:match '\"%s*\"'", search_text);
+
+ if (mime_count > 0)
+ {
+ g_string_append (sparql, "; nie:mimeType ?mime");
+ }
+
+ g_string_append_printf (sparql, " . FILTER( ");
+
+ if (!tracker->details->recursive)
+ {
+ g_string_append_printf (sparql, "tracker:uri-is-parent('%s', nie:url(?urn)) && ", location_uri);
+ }
+ else
+ {
+ g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', nie:url(?urn)) && ", location_uri);
+ }
+
+ g_string_append_printf (sparql, "fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')", search_text);
+
+ date_range = nautilus_query_get_date_range (tracker->details->query);
+ if (date_range)
+ {
+ NautilusQuerySearchType type;
+ gchar *initial_date_format;
+ gchar *end_date_format;
+ GDateTime *initial_date;
+ GDateTime *end_date;
+ GDateTime *shifted_end_date;
+
+ initial_date = g_ptr_array_index (date_range, 0);
+ end_date = g_ptr_array_index (date_range, 1);
+ /* As we do for other searches, we want to make the end date inclusive.
+ * For that, add a day to it */
+ shifted_end_date = g_date_time_add_days (end_date, 1);
+
+ type = nautilus_query_get_search_type (tracker->details->query);
+ initial_date_format = g_date_time_format (initial_date, "%Y-%m-%dT%H:%M:%S");
+ end_date_format = g_date_time_format (shifted_end_date, "%Y-%m-%dT%H:%M:%S");
+
+ g_string_append (sparql, " && ");
+
+ if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
+ {
+ g_string_append_printf (sparql, "?atime >= \"%s\"^^xsd:dateTime", initial_date_format);
+ g_string_append_printf (sparql, " && ?atime <= \"%s\"^^xsd:dateTime", end_date_format);
+ }
+ else
+ {
+ g_string_append_printf (sparql, "?mtime >= \"%s\"^^xsd:dateTime", initial_date_format);
+ g_string_append_printf (sparql, " && ?mtime <= \"%s\"^^xsd:dateTime", end_date_format);
+ }
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
- if (tracker->details->query_pending) {
- return;
- }
+ g_free (initial_date_format);
+ g_free (end_date_format);
+ g_ptr_array_unref (date_range);
+ }
- DEBUG ("Tracker engine start");
- g_object_ref (tracker);
- tracker->details->query_pending = TRUE;
+ if (mime_count > 0)
+ {
+ g_string_append (sparql, " && (");
- g_object_notify (G_OBJECT (provider), "running");
+ for (l = mimetypes; l != NULL; l = l->next)
+ {
+ if (l != mimetypes)
+ {
+ g_string_append (sparql, " || ");
+ }
- if (tracker->details->connection == NULL) {
- g_idle_add (search_finished_idle, provider);
- return;
- }
-
- recursive = g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY ||
- g_settings_get_enum (nautilus_preferences, "recursive-search") == NAUTILUS_SPEED_TRADEOFF_ALWAYS;
- tracker->details->recursive = recursive;
-
- query_text = nautilus_query_get_text (tracker->details->query);
- downcase = g_utf8_strdown (query_text, -1);
- search_text = tracker_sparql_escape_string (downcase);
- g_free (query_text);
- g_free (downcase);
-
- location = nautilus_query_get_location (tracker->details->query);
- location_uri = location ? g_file_get_uri (location) : NULL;
- mimetypes = nautilus_query_get_mime_types (tracker->details->query);
- mime_count = g_list_length (mimetypes);
-
- sparql = g_string_new ("SELECT DISTINCT nie:url(?urn) fts:rank(?urn) nfo:fileLastModified(?urn) nfo:fileLastAccessed(?urn)\n"
- "WHERE {"
- " ?urn a nfo:FileDataObject;"
- " nfo:fileLastModified ?mtime;"
- " nfo:fileLastAccessed ?atime;"
- " tracker:available true;");
-
- g_string_append_printf (sparql, " fts:match '\"%s*\"'", search_text);
-
- if (mime_count > 0) {
- g_string_append (sparql, "; nie:mimeType ?mime");
- }
-
- g_string_append_printf (sparql, " . FILTER( ");
-
- if (!tracker->details->recursive) {
- g_string_append_printf (sparql, "tracker:uri-is-parent('%s', nie:url(?urn)) && ", location_uri);
- } else {
- g_string_append_printf (sparql, "tracker:uri-is-descendant('%s', nie:url(?urn)) && ", location_uri);
- }
-
- g_string_append_printf (sparql, "fn:contains(fn:lower-case(nfo:fileName(?urn)), '%s')", search_text);
-
- date_range = nautilus_query_get_date_range (tracker->details->query);
- if (date_range) {
- NautilusQuerySearchType type;
- gchar *initial_date_format;
- gchar *end_date_format;
- GDateTime *initial_date;
- GDateTime *end_date;
- GDateTime *shifted_end_date;
-
- initial_date = g_ptr_array_index (date_range, 0);
- end_date = g_ptr_array_index (date_range, 1);
- /* As we do for other searches, we want to make the end date inclusive.
- * For that, add a day to it */
- shifted_end_date = g_date_time_add_days (end_date, 1);
-
- type = nautilus_query_get_search_type (tracker->details->query);
- initial_date_format = g_date_time_format (initial_date, "%Y-%m-%dT%H:%M:%S");
- end_date_format = g_date_time_format (shifted_end_date, "%Y-%m-%dT%H:%M:%S");
-
- g_string_append (sparql, " && ");
-
- if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS) {
- g_string_append_printf (sparql, "?atime >= \"%s\"^^xsd:dateTime", initial_date_format);
- g_string_append_printf (sparql, " && ?atime <= \"%s\"^^xsd:dateTime", end_date_format);
- } else {
- g_string_append_printf (sparql, "?mtime >= \"%s\"^^xsd:dateTime", initial_date_format);
- g_string_append_printf (sparql, " && ?mtime <= \"%s\"^^xsd:dateTime", end_date_format);
- }
-
-
- g_free (initial_date_format);
- g_free (end_date_format);
- g_ptr_array_unref (date_range);
+ g_string_append_printf (sparql, "fn:contains(?mime, '%s')",
+ (gchar *) l->data);
}
-
- if (mime_count > 0) {
- g_string_append (sparql, " && (");
-
- for (l = mimetypes; l != NULL; l = l->next) {
- if (l != mimetypes) {
- g_string_append (sparql, " || ");
- }
-
- g_string_append_printf (sparql, "fn:contains(?mime, '%s')",
- (gchar *) l->data);
- }
- g_string_append (sparql, ")\n");
- }
-
- g_string_append (sparql, ")} ORDER BY DESC (fts:rank(?urn))");
-
- tracker->details->cancellable = g_cancellable_new ();
- tracker_sparql_connection_query_async (tracker->details->connection,
- sparql->str,
- tracker->details->cancellable,
- query_callback,
- tracker);
- g_string_free (sparql, TRUE);
-
- g_free (search_text);
- g_free (location_uri);
- g_list_free_full (mimetypes, g_free);
- g_object_unref (location);
+ g_string_append (sparql, ")\n");
+ }
+
+ g_string_append (sparql, ")} ORDER BY DESC (fts:rank(?urn))");
+
+ tracker->details->cancellable = g_cancellable_new ();
+ tracker_sparql_connection_query_async (tracker->details->connection,
+ sparql->str,
+ tracker->details->cancellable,
+ query_callback,
+ tracker);
+ g_string_free (sparql, TRUE);
+
+ g_free (search_text);
+ g_free (location_uri);
+ g_list_free_full (mimetypes, g_free);
+ g_object_unref (location);
}
static void
nautilus_search_engine_tracker_stop (NautilusSearchProvider *provider)
{
- NautilusSearchEngineTracker *tracker;
-
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
-
- if (tracker->details->query_pending) {
- DEBUG ("Tracker engine stop");
- g_cancellable_cancel (tracker->details->cancellable);
- g_clear_object (&tracker->details->cancellable);
- tracker->details->query_pending = FALSE;
-
- g_object_notify (G_OBJECT (provider), "running");
- }
+ NautilusSearchEngineTracker *tracker;
+
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
+
+ if (tracker->details->query_pending)
+ {
+ DEBUG ("Tracker engine stop");
+ g_cancellable_cancel (tracker->details->cancellable);
+ g_clear_object (&tracker->details->cancellable);
+ tracker->details->query_pending = FALSE;
+
+ g_object_notify (G_OBJECT (provider), "running");
+ }
}
static void
nautilus_search_engine_tracker_set_query (NautilusSearchProvider *provider,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- NautilusSearchEngineTracker *tracker;
+ NautilusSearchEngineTracker *tracker;
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
- g_object_ref (query);
- g_clear_object (&tracker->details->query);
- tracker->details->query = query;
+ g_object_ref (query);
+ g_clear_object (&tracker->details->query);
+ tracker->details->query = query;
}
static gboolean
nautilus_search_engine_tracker_is_running (NautilusSearchProvider *provider)
{
- NautilusSearchEngineTracker *tracker;
+ NautilusSearchEngineTracker *tracker;
- tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
+ tracker = NAUTILUS_SEARCH_ENGINE_TRACKER (provider);
- return tracker->details->query_pending;
+ return tracker->details->query_pending;
}
static void
nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
{
- iface->set_query = nautilus_search_engine_tracker_set_query;
- iface->start = nautilus_search_engine_tracker_start;
- iface->stop = nautilus_search_engine_tracker_stop;
- iface->is_running = nautilus_search_engine_tracker_is_running;
+ iface->set_query = nautilus_search_engine_tracker_set_query;
+ iface->start = nautilus_search_engine_tracker_start;
+ iface->stop = nautilus_search_engine_tracker_stop;
+ iface->is_running = nautilus_search_engine_tracker_is_running;
}
static void
@@ -439,57 +477,61 @@ nautilus_search_engine_tracker_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
+ NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_RUNNING:
- g_value_set_boolean (value, nautilus_search_engine_tracker_is_running (self));
- break;
+ {
+ g_value_set_boolean (value, nautilus_search_engine_tracker_is_running (self));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
nautilus_search_engine_tracker_class_init (NautilusSearchEngineTrackerClass *class)
{
- GObjectClass *gobject_class;
+ GObjectClass *gobject_class;
- gobject_class = G_OBJECT_CLASS (class);
- gobject_class->finalize = finalize;
- gobject_class->get_property = nautilus_search_engine_tracker_get_property;
+ gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->finalize = finalize;
+ gobject_class->get_property = nautilus_search_engine_tracker_get_property;
- /**
- * NautilusSearchEngine::running:
- *
- * Whether the search engine is running a search.
- */
- g_object_class_override_property (gobject_class, PROP_RUNNING, "running");
+ /**
+ * NautilusSearchEngine::running:
+ *
+ * Whether the search engine is running a search.
+ */
+ g_object_class_override_property (gobject_class, PROP_RUNNING, "running");
- g_type_class_add_private (class, sizeof (NautilusSearchEngineTrackerDetails));
+ g_type_class_add_private (class, sizeof (NautilusSearchEngineTrackerDetails));
}
static void
nautilus_search_engine_tracker_init (NautilusSearchEngineTracker *engine)
{
- GError *error = NULL;
+ GError *error = NULL;
- engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER,
- NautilusSearchEngineTrackerDetails);
- engine->details->hits_pending = g_queue_new ();
+ engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER,
+ NautilusSearchEngineTrackerDetails);
+ engine->details->hits_pending = g_queue_new ();
- engine->details->connection = tracker_sparql_connection_get (NULL, &error);
+ engine->details->connection = tracker_sparql_connection_get (NULL, &error);
- if (error) {
- g_warning ("Could not establish a connection to Tracker: %s", error->message);
- g_error_free (error);
- }
+ if (error)
+ {
+ g_warning ("Could not establish a connection to Tracker: %s", error->message);
+ g_error_free (error);
+ }
}
NautilusSearchEngineTracker *
nautilus_search_engine_tracker_new (void)
{
- return g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER, NULL);
+ return g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_TRACKER, NULL);
}
diff --git a/src/nautilus-search-engine.c b/src/nautilus-search-engine.c
index 79404f0a1..9e109cc5d 100644
--- a/src/nautilus-search-engine.c
+++ b/src/nautilus-search-engine.c
@@ -36,24 +36,25 @@
struct NautilusSearchEngineDetails
{
#ifdef ENABLE_TRACKER
- NautilusSearchEngineTracker *tracker;
+ NautilusSearchEngineTracker *tracker;
#endif
- NautilusSearchEngineSimple *simple;
- NautilusSearchEngineModel *model;
+ NautilusSearchEngineSimple *simple;
+ NautilusSearchEngineModel *model;
- GHashTable *uris;
- guint providers_running;
- guint providers_finished;
- guint providers_error;
+ GHashTable *uris;
+ guint providers_running;
+ guint providers_finished;
+ guint providers_error;
- gboolean running;
- gboolean restart;
+ gboolean running;
+ gboolean restart;
};
-enum {
- PROP_0,
- PROP_RUNNING,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_RUNNING,
+ LAST_PROP
};
static void nautilus_search_provider_init (NautilusSearchProviderInterface *iface);
@@ -61,238 +62,255 @@ static void nautilus_search_provider_init (NautilusSearchProviderInterface *ifac
static gboolean nautilus_search_engine_is_running (NautilusSearchProvider *provider);
G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngine,
- nautilus_search_engine,
- G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
- nautilus_search_provider_init))
+ nautilus_search_engine,
+ G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
+ nautilus_search_provider_init))
static void
nautilus_search_engine_set_query (NautilusSearchProvider *provider,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (provider);
+ NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (provider);
#ifdef ENABLE_TRACKER
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine->details->tracker), query);
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine->details->tracker), query);
#endif
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine->details->model), query);
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine->details->simple), query);
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine->details->model), query);
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine->details->simple), query);
}
static void
search_engine_start_real (NautilusSearchEngine *engine)
{
- engine->details->providers_running = 0;
- engine->details->providers_finished = 0;
- engine->details->providers_error = 0;
+ engine->details->providers_running = 0;
+ engine->details->providers_finished = 0;
+ engine->details->providers_error = 0;
- engine->details->restart = FALSE;
+ engine->details->restart = FALSE;
- DEBUG ("Search engine start real");
+ DEBUG ("Search engine start real");
- g_object_ref (engine);
+ g_object_ref (engine);
#ifdef ENABLE_TRACKER
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine->details->tracker));
- engine->details->providers_running++;
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine->details->tracker));
+ engine->details->providers_running++;
#endif
- if (nautilus_search_engine_model_get_model (engine->details->model)) {
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine->details->model));
- engine->details->providers_running++;
- }
-
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine->details->simple));
- engine->details->providers_running++;
+ if (nautilus_search_engine_model_get_model (engine->details->model))
+ {
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine->details->model));
+ engine->details->providers_running++;
+ }
+
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine->details->simple));
+ engine->details->providers_running++;
}
static void
nautilus_search_engine_start (NautilusSearchProvider *provider)
{
- NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (provider);
- gint num_finished;
+ NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (provider);
+ gint num_finished;
- DEBUG ("Search engine start");
+ DEBUG ("Search engine start");
- num_finished = engine->details->providers_error + engine->details->providers_finished;
+ num_finished = engine->details->providers_error + engine->details->providers_finished;
- if (engine->details->running) {
- if (num_finished == engine->details->providers_running &&
- engine->details->restart) {
- search_engine_start_real (engine);
- }
+ if (engine->details->running)
+ {
+ if (num_finished == engine->details->providers_running &&
+ engine->details->restart)
+ {
+ search_engine_start_real (engine);
+ }
- return;
- }
+ return;
+ }
- engine->details->running = TRUE;
+ engine->details->running = TRUE;
- g_object_notify (G_OBJECT (provider), "running");
+ g_object_notify (G_OBJECT (provider), "running");
- if (num_finished < engine->details->providers_running) {
- engine->details->restart = TRUE;
- } else {
- search_engine_start_real (engine);
- }
+ if (num_finished < engine->details->providers_running)
+ {
+ engine->details->restart = TRUE;
+ }
+ else
+ {
+ search_engine_start_real (engine);
+ }
}
static void
nautilus_search_engine_stop (NautilusSearchProvider *provider)
{
- NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (provider);
+ NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (provider);
- DEBUG ("Search engine stop");
+ DEBUG ("Search engine stop");
#ifdef ENABLE_TRACKER
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine->details->tracker));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine->details->tracker));
#endif
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine->details->model));
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine->details->simple));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine->details->model));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine->details->simple));
- engine->details->running = FALSE;
- engine->details->restart = FALSE;
+ engine->details->running = FALSE;
+ engine->details->restart = FALSE;
- g_object_notify (G_OBJECT (provider), "running");
+ g_object_notify (G_OBJECT (provider), "running");
}
static void
search_provider_hits_added (NautilusSearchProvider *provider,
- GList *hits,
- NautilusSearchEngine *engine)
+ GList *hits,
+ NautilusSearchEngine *engine)
{
- GList *added = NULL;
- GList *l;
-
- if (!engine->details->running || engine->details->restart) {
- DEBUG ("Ignoring hits-added, since engine is %s",
- !engine->details->running ? "not running" : "waiting to restart");
- return;
- }
-
- for (l = hits; l != NULL; l = l->next) {
- NautilusSearchHit *hit = l->data;
- int count;
- const char *uri;
-
- uri = nautilus_search_hit_get_uri (hit);
- count = GPOINTER_TO_INT (g_hash_table_lookup (engine->details->uris, uri));
- if (count == 0)
- added = g_list_prepend (added, hit);
- g_hash_table_replace (engine->details->uris, g_strdup (uri), GINT_TO_POINTER (++count));
- }
- if (added != NULL) {
- added = g_list_reverse (added);
- nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (engine), added);
- g_list_free (added);
- }
+ GList *added = NULL;
+ GList *l;
+
+ if (!engine->details->running || engine->details->restart)
+ {
+ DEBUG ("Ignoring hits-added, since engine is %s",
+ !engine->details->running ? "not running" : "waiting to restart");
+ return;
+ }
+
+ for (l = hits; l != NULL; l = l->next)
+ {
+ NautilusSearchHit *hit = l->data;
+ int count;
+ const char *uri;
+
+ uri = nautilus_search_hit_get_uri (hit);
+ count = GPOINTER_TO_INT (g_hash_table_lookup (engine->details->uris, uri));
+ if (count == 0)
+ {
+ added = g_list_prepend (added, hit);
+ }
+ g_hash_table_replace (engine->details->uris, g_strdup (uri), GINT_TO_POINTER (++count));
+ }
+ if (added != NULL)
+ {
+ added = g_list_reverse (added);
+ nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (engine), added);
+ g_list_free (added);
+ }
}
static void
check_providers_status (NautilusSearchEngine *engine)
{
- gint num_finished = engine->details->providers_error + engine->details->providers_finished;
-
- if (num_finished < engine->details->providers_running) {
- return;
- }
-
- if (num_finished == engine->details->providers_error) {
- DEBUG ("Search engine error");
- nautilus_search_provider_error (NAUTILUS_SEARCH_PROVIDER (engine),
- _("Unable to complete the requested search"));
- } else {
- if (engine->details->restart) {
- DEBUG ("Search engine finished and restarting");
- } else {
- DEBUG ("Search engine finished");
- }
- nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (engine),
- engine->details->restart ? NAUTILUS_SEARCH_PROVIDER_STATUS_RESTARTING :
- NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
- }
-
- engine->details->running = FALSE;
- g_object_notify (G_OBJECT (engine), "running");
-
- g_hash_table_remove_all (engine->details->uris);
-
- if (engine->details->restart) {
- nautilus_search_engine_start (NAUTILUS_SEARCH_PROVIDER (engine));
- }
-
- g_object_unref (engine);
+ gint num_finished = engine->details->providers_error + engine->details->providers_finished;
+
+ if (num_finished < engine->details->providers_running)
+ {
+ return;
+ }
+
+ if (num_finished == engine->details->providers_error)
+ {
+ DEBUG ("Search engine error");
+ nautilus_search_provider_error (NAUTILUS_SEARCH_PROVIDER (engine),
+ _("Unable to complete the requested search"));
+ }
+ else
+ {
+ if (engine->details->restart)
+ {
+ DEBUG ("Search engine finished and restarting");
+ }
+ else
+ {
+ DEBUG ("Search engine finished");
+ }
+ nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (engine),
+ engine->details->restart ? NAUTILUS_SEARCH_PROVIDER_STATUS_RESTARTING :
+ NAUTILUS_SEARCH_PROVIDER_STATUS_NORMAL);
+ }
+
+ engine->details->running = FALSE;
+ g_object_notify (G_OBJECT (engine), "running");
+
+ g_hash_table_remove_all (engine->details->uris);
+
+ if (engine->details->restart)
+ {
+ nautilus_search_engine_start (NAUTILUS_SEARCH_PROVIDER (engine));
+ }
+
+ g_object_unref (engine);
}
static void
search_provider_error (NautilusSearchProvider *provider,
- const char *error_message,
- NautilusSearchEngine *engine)
-
+ const char *error_message,
+ NautilusSearchEngine *engine)
{
- DEBUG ("Search provider error: %s", error_message);
- engine->details->providers_error++;
+ DEBUG ("Search provider error: %s", error_message);
+ engine->details->providers_error++;
- check_providers_status (engine);
+ check_providers_status (engine);
}
static void
search_provider_finished (NautilusSearchProvider *provider,
NautilusSearchProviderStatus status,
NautilusSearchEngine *engine)
-
{
- DEBUG ("Search provider finished");
- engine->details->providers_finished++;
+ DEBUG ("Search provider finished");
+ engine->details->providers_finished++;
- check_providers_status (engine);
+ check_providers_status (engine);
}
static void
connect_provider_signals (NautilusSearchEngine *engine,
- NautilusSearchProvider *provider)
+ NautilusSearchProvider *provider)
{
- g_signal_connect (provider, "hits-added",
- G_CALLBACK (search_provider_hits_added),
- engine);
- g_signal_connect (provider, "finished",
- G_CALLBACK (search_provider_finished),
- engine);
- g_signal_connect (provider, "error",
- G_CALLBACK (search_provider_error),
- engine);
+ g_signal_connect (provider, "hits-added",
+ G_CALLBACK (search_provider_hits_added),
+ engine);
+ g_signal_connect (provider, "finished",
+ G_CALLBACK (search_provider_finished),
+ engine);
+ g_signal_connect (provider, "error",
+ G_CALLBACK (search_provider_error),
+ engine);
}
static gboolean
nautilus_search_engine_is_running (NautilusSearchProvider *provider)
{
- NautilusSearchEngine *engine;
+ NautilusSearchEngine *engine;
- engine = NAUTILUS_SEARCH_ENGINE (provider);
+ engine = NAUTILUS_SEARCH_ENGINE (provider);
- return engine->details->running;
+ return engine->details->running;
}
static void
nautilus_search_provider_init (NautilusSearchProviderInterface *iface)
{
- iface->set_query = nautilus_search_engine_set_query;
- iface->start = nautilus_search_engine_start;
- iface->stop = nautilus_search_engine_stop;
- iface->is_running = nautilus_search_engine_is_running;
+ iface->set_query = nautilus_search_engine_set_query;
+ iface->start = nautilus_search_engine_start;
+ iface->stop = nautilus_search_engine_stop;
+ iface->is_running = nautilus_search_engine_is_running;
}
static void
nautilus_search_engine_finalize (GObject *object)
{
- NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (object);
+ NautilusSearchEngine *engine = NAUTILUS_SEARCH_ENGINE (object);
- g_hash_table_destroy (engine->details->uris);
+ g_hash_table_destroy (engine->details->uris);
#ifdef ENABLE_TRACKER
- g_clear_object (&engine->details->tracker);
+ g_clear_object (&engine->details->tracker);
#endif
- g_clear_object (&engine->details->model);
- g_clear_object (&engine->details->simple);
+ g_clear_object (&engine->details->model);
+ g_clear_object (&engine->details->simple);
- G_OBJECT_CLASS (nautilus_search_engine_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_engine_parent_class)->finalize (object);
}
static void
@@ -301,76 +319,79 @@ nautilus_search_engine_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
+ NautilusSearchProvider *self = NAUTILUS_SEARCH_PROVIDER (object);
- switch (prop_id) {
+ switch (prop_id)
+ {
case PROP_RUNNING:
- g_value_set_boolean (value, nautilus_search_engine_is_running (self));
- break;
+ {
+ g_value_set_boolean (value, nautilus_search_engine_is_running (self));
+ }
+ break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
nautilus_search_engine_class_init (NautilusSearchEngineClass *class)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
- object_class = (GObjectClass *) class;
+ object_class = (GObjectClass *) class;
- object_class->finalize = nautilus_search_engine_finalize;
- object_class->get_property = nautilus_search_engine_get_property;
+ object_class->finalize = nautilus_search_engine_finalize;
+ object_class->get_property = nautilus_search_engine_get_property;
- /**
- * NautilusSearchEngine::running:
- *
- * Whether the search engine is running a search.
- */
- g_object_class_override_property (object_class, PROP_RUNNING, "running");
+ /**
+ * NautilusSearchEngine::running:
+ *
+ * Whether the search engine is running a search.
+ */
+ g_object_class_override_property (object_class, PROP_RUNNING, "running");
- g_type_class_add_private (class, sizeof (NautilusSearchEngineDetails));
+ g_type_class_add_private (class, sizeof (NautilusSearchEngineDetails));
}
static void
nautilus_search_engine_init (NautilusSearchEngine *engine)
{
- engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine,
- NAUTILUS_TYPE_SEARCH_ENGINE,
- NautilusSearchEngineDetails);
+ engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine,
+ NAUTILUS_TYPE_SEARCH_ENGINE,
+ NautilusSearchEngineDetails);
- engine->details->uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ engine->details->uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
#ifdef ENABLE_TRACKER
- engine->details->tracker = nautilus_search_engine_tracker_new ();
- connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (engine->details->tracker));
+ engine->details->tracker = nautilus_search_engine_tracker_new ();
+ connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (engine->details->tracker));
#endif
- engine->details->model = nautilus_search_engine_model_new ();
- connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (engine->details->model));
+ engine->details->model = nautilus_search_engine_model_new ();
+ connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (engine->details->model));
- engine->details->simple = nautilus_search_engine_simple_new ();
- connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (engine->details->simple));
+ engine->details->simple = nautilus_search_engine_simple_new ();
+ connect_provider_signals (engine, NAUTILUS_SEARCH_PROVIDER (engine->details->simple));
}
NautilusSearchEngine *
nautilus_search_engine_new (void)
{
- NautilusSearchEngine *engine;
+ NautilusSearchEngine *engine;
- engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE, NULL);
+ engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE, NULL);
- return engine;
+ return engine;
}
NautilusSearchEngineModel *
nautilus_search_engine_get_model_provider (NautilusSearchEngine *engine)
{
- return engine->details->model;
+ return engine->details->model;
}
NautilusSearchEngineSimple *
nautilus_search_engine_get_simple_provider (NautilusSearchEngine *engine)
{
- return engine->details->simple;
+ return engine->details->simple;
}
diff --git a/src/nautilus-search-hit.c b/src/nautilus-search-hit.c
index 5658872c8..b214e60a8 100644
--- a/src/nautilus-search-hit.c
+++ b/src/nautilus-search-hit.c
@@ -29,299 +29,371 @@
struct NautilusSearchHitDetails
{
- char *uri;
+ char *uri;
- GDateTime *modification_time;
- GDateTime *access_time;
- gdouble fts_rank;
+ GDateTime *modification_time;
+ GDateTime *access_time;
+ gdouble fts_rank;
- gdouble relevance;
+ gdouble relevance;
};
-enum {
- PROP_URI = 1,
- PROP_RELEVANCE,
- PROP_MODIFICATION_TIME,
- PROP_ACCESS_TIME,
- PROP_FTS_RANK,
- NUM_PROPERTIES
+enum
+{
+ PROP_URI = 1,
+ PROP_RELEVANCE,
+ PROP_MODIFICATION_TIME,
+ PROP_ACCESS_TIME,
+ PROP_FTS_RANK,
+ NUM_PROPERTIES
};
G_DEFINE_TYPE (NautilusSearchHit, nautilus_search_hit, G_TYPE_OBJECT)
void
nautilus_search_hit_compute_scores (NautilusSearchHit *hit,
- NautilusQuery *query)
+ NautilusQuery *query)
{
- GDateTime *now;
- GFile *query_location;
- GFile *hit_location;
- GTimeSpan m_diff = G_MAXINT64;
- GTimeSpan a_diff = G_MAXINT64;
- GTimeSpan t_diff = G_MAXINT64;
- gdouble recent_bonus = 0.0;
- gdouble proximity_bonus = 0.0;
- gdouble match_bonus = 0.0;
-
- query_location = nautilus_query_get_location (query);
- hit_location = g_file_new_for_uri (hit->details->uri);
-
- if (g_file_has_prefix (hit_location, query_location)) {
- GFile *parent, *location;
- guint dir_count = 0;
-
- parent = g_file_get_parent (hit_location);
-
- while (!g_file_equal (parent, query_location)) {
- dir_count++;
- location = parent;
- parent = g_file_get_parent (location);
- g_object_unref (location);
- }
- g_object_unref (parent);
-
- if (dir_count < 10) {
- proximity_bonus = 10000.0 - 1000.0 * dir_count;
- }
- }
- g_object_unref (hit_location);
-
- now = g_date_time_new_now_local ();
- if (hit->details->modification_time != NULL)
- m_diff = g_date_time_difference (now, hit->details->modification_time);
- if (hit->details->access_time != NULL)
- a_diff = g_date_time_difference (now, hit->details->access_time);
- m_diff /= G_TIME_SPAN_DAY;
- a_diff /= G_TIME_SPAN_DAY;
- t_diff = MIN (m_diff, a_diff);
- if (t_diff > 90) {
- recent_bonus = 0.0;
- } else if (t_diff > 30) {
- recent_bonus = 10.0;
- } else if (t_diff > 14) {
- recent_bonus = 30.0;
- } else if (t_diff > 7) {
- recent_bonus = 50.0;
- } else if (t_diff > 1) {
- recent_bonus = 70.0;
- } else {
- recent_bonus = 100.0;
- }
-
- if (hit->details->fts_rank > 0) {
- match_bonus = MIN (500, 10.0 * hit->details->fts_rank);
- } else {
- match_bonus = 0.0;
- }
-
- hit->details->relevance = recent_bonus + proximity_bonus + match_bonus;
- DEBUG ("Hit %s computed relevance %.2f (%.2f + %.2f + %.2f)", hit->details->uri, hit->details->relevance,
- proximity_bonus, recent_bonus, match_bonus);
-
- g_date_time_unref (now);
- g_object_unref (query_location);
+ GDateTime *now;
+ GFile *query_location;
+ GFile *hit_location;
+ GTimeSpan m_diff = G_MAXINT64;
+ GTimeSpan a_diff = G_MAXINT64;
+ GTimeSpan t_diff = G_MAXINT64;
+ gdouble recent_bonus = 0.0;
+ gdouble proximity_bonus = 0.0;
+ gdouble match_bonus = 0.0;
+
+ query_location = nautilus_query_get_location (query);
+ hit_location = g_file_new_for_uri (hit->details->uri);
+
+ if (g_file_has_prefix (hit_location, query_location))
+ {
+ GFile *parent, *location;
+ guint dir_count = 0;
+
+ parent = g_file_get_parent (hit_location);
+
+ while (!g_file_equal (parent, query_location))
+ {
+ dir_count++;
+ location = parent;
+ parent = g_file_get_parent (location);
+ g_object_unref (location);
+ }
+ g_object_unref (parent);
+
+ if (dir_count < 10)
+ {
+ proximity_bonus = 10000.0 - 1000.0 * dir_count;
+ }
+ }
+ g_object_unref (hit_location);
+
+ now = g_date_time_new_now_local ();
+ if (hit->details->modification_time != NULL)
+ {
+ m_diff = g_date_time_difference (now, hit->details->modification_time);
+ }
+ if (hit->details->access_time != NULL)
+ {
+ a_diff = g_date_time_difference (now, hit->details->access_time);
+ }
+ m_diff /= G_TIME_SPAN_DAY;
+ a_diff /= G_TIME_SPAN_DAY;
+ t_diff = MIN (m_diff, a_diff);
+ if (t_diff > 90)
+ {
+ recent_bonus = 0.0;
+ }
+ else if (t_diff > 30)
+ {
+ recent_bonus = 10.0;
+ }
+ else if (t_diff > 14)
+ {
+ recent_bonus = 30.0;
+ }
+ else if (t_diff > 7)
+ {
+ recent_bonus = 50.0;
+ }
+ else if (t_diff > 1)
+ {
+ recent_bonus = 70.0;
+ }
+ else
+ {
+ recent_bonus = 100.0;
+ }
+
+ if (hit->details->fts_rank > 0)
+ {
+ match_bonus = MIN (500, 10.0 * hit->details->fts_rank);
+ }
+ else
+ {
+ match_bonus = 0.0;
+ }
+
+ hit->details->relevance = recent_bonus + proximity_bonus + match_bonus;
+ DEBUG ("Hit %s computed relevance %.2f (%.2f + %.2f + %.2f)", hit->details->uri, hit->details->relevance,
+ proximity_bonus, recent_bonus, match_bonus);
+
+ g_date_time_unref (now);
+ g_object_unref (query_location);
}
const char *
nautilus_search_hit_get_uri (NautilusSearchHit *hit)
{
- return hit->details->uri;
+ return hit->details->uri;
}
gdouble
nautilus_search_hit_get_relevance (NautilusSearchHit *hit)
{
- return hit->details->relevance;
+ return hit->details->relevance;
}
static void
nautilus_search_hit_set_uri (NautilusSearchHit *hit,
- const char *uri)
+ const char *uri)
{
- g_free (hit->details->uri);
- hit->details->uri = g_strdup (uri);
+ g_free (hit->details->uri);
+ hit->details->uri = g_strdup (uri);
}
void
nautilus_search_hit_set_fts_rank (NautilusSearchHit *hit,
- gdouble rank)
+ gdouble rank)
{
- hit->details->fts_rank = rank;
+ hit->details->fts_rank = rank;
}
void
nautilus_search_hit_set_modification_time (NautilusSearchHit *hit,
- GDateTime *date)
+ GDateTime *date)
{
- if (hit->details->modification_time != NULL)
- g_date_time_unref (hit->details->modification_time);
- if (date != NULL)
- hit->details->modification_time = g_date_time_ref (date);
- else
- hit->details->modification_time = NULL;
+ if (hit->details->modification_time != NULL)
+ {
+ g_date_time_unref (hit->details->modification_time);
+ }
+ if (date != NULL)
+ {
+ hit->details->modification_time = g_date_time_ref (date);
+ }
+ else
+ {
+ hit->details->modification_time = NULL;
+ }
}
void
nautilus_search_hit_set_access_time (NautilusSearchHit *hit,
- GDateTime *date)
+ GDateTime *date)
{
- if (hit->details->access_time != NULL)
- g_date_time_unref (hit->details->access_time);
- if (date != NULL)
- hit->details->access_time = g_date_time_ref (date);
- else
- hit->details->access_time = NULL;
+ if (hit->details->access_time != NULL)
+ {
+ g_date_time_unref (hit->details->access_time);
+ }
+ if (date != NULL)
+ {
+ hit->details->access_time = g_date_time_ref (date);
+ }
+ else
+ {
+ hit->details->access_time = NULL;
+ }
}
static void
-nautilus_search_hit_set_property (GObject *object,
- guint arg_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_search_hit_set_property (GObject *object,
+ guint arg_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusSearchHit *hit;
-
- hit = NAUTILUS_SEARCH_HIT (object);
-
- switch (arg_id) {
- case PROP_RELEVANCE:
- hit->details->relevance = g_value_get_double (value);
- break;
- case PROP_FTS_RANK:
- nautilus_search_hit_set_fts_rank (hit, g_value_get_double (value));
- break;
- case PROP_URI:
- nautilus_search_hit_set_uri (hit, g_value_get_string (value));
- break;
- case PROP_MODIFICATION_TIME:
- nautilus_search_hit_set_modification_time (hit, g_value_get_boxed (value));
- break;
- case PROP_ACCESS_TIME:
- nautilus_search_hit_set_access_time (hit, g_value_get_boxed (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
- break;
- }
+ NautilusSearchHit *hit;
+
+ hit = NAUTILUS_SEARCH_HIT (object);
+
+ switch (arg_id)
+ {
+ case PROP_RELEVANCE:
+ {
+ hit->details->relevance = g_value_get_double (value);
+ }
+ break;
+
+ case PROP_FTS_RANK:
+ {
+ nautilus_search_hit_set_fts_rank (hit, g_value_get_double (value));
+ }
+ break;
+
+ case PROP_URI:
+ {
+ nautilus_search_hit_set_uri (hit, g_value_get_string (value));
+ }
+ break;
+
+ case PROP_MODIFICATION_TIME:
+ {
+ nautilus_search_hit_set_modification_time (hit, g_value_get_boxed (value));
+ }
+ break;
+
+ case PROP_ACCESS_TIME:
+ {
+ nautilus_search_hit_set_access_time (hit, g_value_get_boxed (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_search_hit_get_property (GObject *object,
- guint arg_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_search_hit_get_property (GObject *object,
+ guint arg_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusSearchHit *hit;
-
- hit = NAUTILUS_SEARCH_HIT (object);
-
- switch (arg_id) {
- case PROP_RELEVANCE:
- g_value_set_double (value, hit->details->relevance);
- break;
- case PROP_FTS_RANK:
- g_value_set_double (value, hit->details->fts_rank);
- break;
- case PROP_URI:
- g_value_set_string (value, hit->details->uri);
- break;
- case PROP_MODIFICATION_TIME:
- g_value_set_boxed (value, hit->details->modification_time);
- break;
- case PROP_ACCESS_TIME:
- g_value_set_boxed (value, hit->details->access_time);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
- break;
- }
+ NautilusSearchHit *hit;
+
+ hit = NAUTILUS_SEARCH_HIT (object);
+
+ switch (arg_id)
+ {
+ case PROP_RELEVANCE:
+ {
+ g_value_set_double (value, hit->details->relevance);
+ }
+ break;
+
+ case PROP_FTS_RANK:
+ {
+ g_value_set_double (value, hit->details->fts_rank);
+ }
+ break;
+
+ case PROP_URI:
+ {
+ g_value_set_string (value, hit->details->uri);
+ }
+ break;
+
+ case PROP_MODIFICATION_TIME:
+ {
+ g_value_set_boxed (value, hit->details->modification_time);
+ }
+ break;
+
+ case PROP_ACCESS_TIME:
+ {
+ g_value_set_boxed (value, hit->details->access_time);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_search_hit_finalize (GObject *object)
{
- NautilusSearchHit *hit = NAUTILUS_SEARCH_HIT (object);
+ NautilusSearchHit *hit = NAUTILUS_SEARCH_HIT (object);
- g_free (hit->details->uri);
+ g_free (hit->details->uri);
- if (hit->details->access_time != NULL) {
- g_date_time_unref (hit->details->access_time);
- }
- if (hit->details->modification_time != NULL) {
- g_date_time_unref (hit->details->modification_time);
- }
+ if (hit->details->access_time != NULL)
+ {
+ g_date_time_unref (hit->details->access_time);
+ }
+ if (hit->details->modification_time != NULL)
+ {
+ g_date_time_unref (hit->details->modification_time);
+ }
- G_OBJECT_CLASS (nautilus_search_hit_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_search_hit_parent_class)->finalize (object);
}
static void
nautilus_search_hit_class_init (NautilusSearchHitClass *class)
{
- GObjectClass *object_class;
-
- object_class = (GObjectClass *) class;
-
- object_class->finalize = nautilus_search_hit_finalize;
- object_class->get_property = nautilus_search_hit_get_property;
- object_class->set_property = nautilus_search_hit_set_property;
-
- g_object_class_install_property (object_class,
- PROP_URI,
- g_param_spec_string ("uri",
- "URI",
- "URI",
- NULL,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_MODIFICATION_TIME,
- g_param_spec_boxed ("modification-time",
- "Modification time",
- "Modification time",
- G_TYPE_DATE_TIME,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- g_object_class_install_property (object_class,
- PROP_ACCESS_TIME,
- g_param_spec_boxed ("access-time",
- "acess time",
- "access time",
- G_TYPE_DATE_TIME,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
- g_object_class_install_property (object_class,
- PROP_RELEVANCE,
- g_param_spec_double ("relevance",
- NULL,
- NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE,
- 0,
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_FTS_RANK,
- g_param_spec_double ("fts-rank",
- NULL,
- NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE,
- 0,
- G_PARAM_READWRITE));
-
- g_type_class_add_private (class, sizeof (NautilusSearchHitDetails));
+ GObjectClass *object_class;
+
+ object_class = (GObjectClass *) class;
+
+ object_class->finalize = nautilus_search_hit_finalize;
+ object_class->get_property = nautilus_search_hit_get_property;
+ object_class->set_property = nautilus_search_hit_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_URI,
+ g_param_spec_string ("uri",
+ "URI",
+ "URI",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_MODIFICATION_TIME,
+ g_param_spec_boxed ("modification-time",
+ "Modification time",
+ "Modification time",
+ G_TYPE_DATE_TIME,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_ACCESS_TIME,
+ g_param_spec_boxed ("access-time",
+ "acess time",
+ "access time",
+ G_TYPE_DATE_TIME,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ g_object_class_install_property (object_class,
+ PROP_RELEVANCE,
+ g_param_spec_double ("relevance",
+ NULL,
+ NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE,
+ 0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_FTS_RANK,
+ g_param_spec_double ("fts-rank",
+ NULL,
+ NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE,
+ 0,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (class, sizeof (NautilusSearchHitDetails));
}
static void
nautilus_search_hit_init (NautilusSearchHit *hit)
{
- hit->details = G_TYPE_INSTANCE_GET_PRIVATE (hit,
- NAUTILUS_TYPE_SEARCH_HIT,
- NautilusSearchHitDetails);
+ hit->details = G_TYPE_INSTANCE_GET_PRIVATE (hit,
+ NAUTILUS_TYPE_SEARCH_HIT,
+ NautilusSearchHitDetails);
}
NautilusSearchHit *
nautilus_search_hit_new (const char *uri)
{
- NautilusSearchHit *hit;
+ NautilusSearchHit *hit;
- hit = g_object_new (NAUTILUS_TYPE_SEARCH_HIT,
- "uri", uri,
- NULL);
+ hit = g_object_new (NAUTILUS_TYPE_SEARCH_HIT,
+ "uri", uri,
+ NULL);
- return hit;
+ return hit;
}
diff --git a/src/nautilus-search-popover.c b/src/nautilus-search-popover.c
index 9693305bf..387cbe8c9 100644
--- a/src/nautilus-search-popover.c
+++ b/src/nautilus-search-popover.c
@@ -29,47 +29,49 @@
struct _NautilusSearchPopover
{
- GtkPopover parent;
-
- GtkWidget *around_revealer;
- GtkWidget *around_stack;
- GtkWidget *calendar;
- GtkWidget *clear_date_button;
- GtkWidget *dates_listbox;
- GtkWidget *date_entry;
- GtkWidget *date_stack;
- GtkWidget *select_date_button;
- GtkWidget *select_date_button_label;
- GtkWidget *type_label;
- GtkWidget *type_listbox;
- GtkWidget *type_stack;
- GtkWidget *last_used_button;
- GtkWidget *last_modified_button;
-
- NautilusQuery *query;
+ GtkPopover parent;
+
+ GtkWidget *around_revealer;
+ GtkWidget *around_stack;
+ GtkWidget *calendar;
+ GtkWidget *clear_date_button;
+ GtkWidget *dates_listbox;
+ GtkWidget *date_entry;
+ GtkWidget *date_stack;
+ GtkWidget *select_date_button;
+ GtkWidget *select_date_button_label;
+ GtkWidget *type_label;
+ GtkWidget *type_listbox;
+ GtkWidget *type_stack;
+ GtkWidget *last_used_button;
+ GtkWidget *last_modified_button;
+
+ NautilusQuery *query;
};
-static void show_date_selection_widgets (NautilusSearchPopover *popover,
- gboolean visible);
+static void show_date_selection_widgets (NautilusSearchPopover *popover,
+ gboolean visible);
-static void show_other_types_dialog (NautilusSearchPopover *popover);
+static void show_other_types_dialog (NautilusSearchPopover *popover);
-static void update_date_label (NautilusSearchPopover *popover,
- GPtrArray *date_range);
+static void update_date_label (NautilusSearchPopover *popover,
+ GPtrArray *date_range);
G_DEFINE_TYPE (NautilusSearchPopover, nautilus_search_popover, GTK_TYPE_POPOVER)
-enum {
- PROP_0,
- PROP_QUERY,
- LAST_PROP
+enum
+{
+ PROP_0,
+ PROP_QUERY,
+ LAST_PROP
};
-enum {
- MIME_TYPE,
- TIME_TYPE,
- DATE_RANGE,
- LAST_SIGNAL
+enum
+{
+ MIME_TYPE,
+ TIME_TYPE,
+ DATE_RANGE,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -81,22 +83,22 @@ static void
calendar_day_selected (GtkCalendar *calendar,
NautilusSearchPopover *popover)
{
- GDateTime *date;
- guint year, month, day;
- GPtrArray *date_range;
+ GDateTime *date;
+ guint year, month, day;
+ GPtrArray *date_range;
- gtk_calendar_get_date (calendar, &year, &month, &day);
+ gtk_calendar_get_date (calendar, &year, &month, &day);
- date = g_date_time_new_local (year, month + 1, day, 0, 0, 0);
+ date = g_date_time_new_local (year, month + 1, day, 0, 0, 0);
- date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
- g_ptr_array_add (date_range, g_date_time_ref (date));
- g_ptr_array_add (date_range, g_date_time_ref (date));
- update_date_label (popover, date_range);
- g_signal_emit_by_name (popover, "date-range", date_range);
+ date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
+ g_ptr_array_add (date_range, g_date_time_ref (date));
+ g_ptr_array_add (date_range, g_date_time_ref (date));
+ update_date_label (popover, date_range);
+ g_signal_emit_by_name (popover, "date-range", date_range);
- g_ptr_array_unref (date_range);
- g_date_time_unref (date);
+ g_ptr_array_unref (date_range);
+ g_date_time_unref (date);
}
/* Range on dates are partially implemented. For now just use it for differentation
@@ -106,27 +108,28 @@ static void
setup_date (NautilusSearchPopover *popover,
NautilusQuery *query)
{
- GPtrArray *date_range;
- GDateTime *date_initial;
+ GPtrArray *date_range;
+ GDateTime *date_initial;
- date_range = nautilus_query_get_date_range (query);
+ date_range = nautilus_query_get_date_range (query);
- if (date_range) {
- date_initial = g_ptr_array_index (date_range, 0);
+ if (date_range)
+ {
+ date_initial = g_ptr_array_index (date_range, 0);
- g_signal_handlers_block_by_func (popover->calendar, calendar_day_selected, popover);
+ g_signal_handlers_block_by_func (popover->calendar, calendar_day_selected, popover);
- gtk_calendar_select_month (GTK_CALENDAR (popover->calendar),
- g_date_time_get_month (date_initial) - 1,
- g_date_time_get_year (date_initial));
+ gtk_calendar_select_month (GTK_CALENDAR (popover->calendar),
+ g_date_time_get_month (date_initial) - 1,
+ g_date_time_get_year (date_initial));
- gtk_calendar_select_day (GTK_CALENDAR (popover->calendar),
- g_date_time_get_day_of_month (date_initial));
+ gtk_calendar_select_day (GTK_CALENDAR (popover->calendar),
+ g_date_time_get_day_of_month (date_initial));
- update_date_label (popover, date_range);
+ update_date_label (popover, date_range);
- g_signal_handlers_unblock_by_func (popover->calendar, calendar_day_selected, popover);
- }
+ g_signal_handlers_unblock_by_func (popover->calendar, calendar_day_selected, popover);
+ }
}
static void
@@ -134,62 +137,62 @@ query_date_changed (GObject *object,
GParamSpec *pspec,
NautilusSearchPopover *popover)
{
- setup_date (popover, NAUTILUS_QUERY (object));
+ setup_date (popover, NAUTILUS_QUERY (object));
}
static void
clear_date_button_clicked (GtkButton *button,
NautilusSearchPopover *popover)
{
- nautilus_search_popover_reset_date_range (popover);
+ nautilus_search_popover_reset_date_range (popover);
}
static void
date_entry_activate (GtkEntry *entry,
NautilusSearchPopover *popover)
{
- if (gtk_entry_get_text_length (entry) > 0)
+ if (gtk_entry_get_text_length (entry) > 0)
{
- GDateTime *now;
- GDateTime *date_time;
- GDate *date;
+ GDateTime *now;
+ GDateTime *date_time;
+ GDate *date;
- date = g_date_new ();
- g_date_set_parse (date, gtk_entry_get_text (entry));
+ date = g_date_new ();
+ g_date_set_parse (date, gtk_entry_get_text (entry));
- /* Invalid date silently does nothing */
- if (!g_date_valid (date))
+ /* Invalid date silently does nothing */
+ if (!g_date_valid (date))
{
- g_date_free (date);
- return;
+ g_date_free (date);
+ return;
}
- now = g_date_time_new_now_local ();
- date_time = g_date_time_new_local (g_date_get_year (date),
- g_date_get_month (date),
- g_date_get_day (date),
- 0,
- 0,
- 0);
+ now = g_date_time_new_now_local ();
+ date_time = g_date_time_new_local (g_date_get_year (date),
+ g_date_get_month (date),
+ g_date_get_day (date),
+ 0,
+ 0,
+ 0);
- /* Future dates also silently fails */
- if (g_date_time_compare (date_time, now) != 1)
+ /* Future dates also silently fails */
+ if (g_date_time_compare (date_time, now) != 1)
{
- GPtrArray *date_range;
+ GPtrArray *date_range;
- date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
- g_ptr_array_add (date_range, g_date_time_ref (date_time));
- g_ptr_array_add (date_range, g_date_time_ref (date_time));
- update_date_label (popover, date_range);
- show_date_selection_widgets (popover, FALSE);
- g_signal_emit_by_name (popover, "date-range", date_range);
+ date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
+ g_ptr_array_add (date_range, g_date_time_ref (date_time));
+ g_ptr_array_add (date_range, g_date_time_ref (date_time));
+ update_date_label (popover, date_range);
+ show_date_selection_widgets (popover, FALSE);
+ g_signal_emit_by_name (popover, "date-range", date_range);
- g_ptr_array_unref (date_range);
+ g_ptr_array_unref (date_range);
}
- g_date_time_unref (now);
- g_date_time_unref (date_time);
- g_date_free (date);
+ g_date_time_unref (now);
+ g_date_time_unref (date_time);
+ g_date_free (date);
}
}
@@ -198,25 +201,27 @@ dates_listbox_row_activated (GtkListBox *listbox,
GtkListBoxRow *row,
NautilusSearchPopover *popover)
{
- GDateTime *date;
- GDateTime *now;
- GPtrArray *date_range = NULL;
+ GDateTime *date;
+ GDateTime *now;
+ GPtrArray *date_range = NULL;
- now = g_date_time_new_now_local ();
- date = g_object_get_data (G_OBJECT (row), "date");
- if (date)
+ now = g_date_time_new_now_local ();
+ date = g_object_get_data (G_OBJECT (row), "date");
+ if (date)
{
- date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
- g_ptr_array_add (date_range, g_date_time_ref (date));
- g_ptr_array_add (date_range, g_date_time_ref (now));
+ date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
+ g_ptr_array_add (date_range, g_date_time_ref (date));
+ g_ptr_array_add (date_range, g_date_time_ref (now));
}
- update_date_label (popover, date_range);
- show_date_selection_widgets (popover, FALSE);
- g_signal_emit_by_name (popover, "date-range", date_range);
+ update_date_label (popover, date_range);
+ show_date_selection_widgets (popover, FALSE);
+ g_signal_emit_by_name (popover, "date-range", date_range);
- if (date_range)
- g_ptr_array_unref (date_range);
- g_date_time_unref (now);
+ if (date_range)
+ {
+ g_ptr_array_unref (date_range);
+ }
+ g_date_time_unref (now);
}
static void
@@ -224,18 +229,18 @@ listbox_header_func (GtkListBoxRow *row,
GtkListBoxRow *before,
NautilusSearchPopover *popover)
{
- gboolean show_separator;
+ gboolean show_separator;
- show_separator = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "show-separator"));
+ show_separator = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "show-separator"));
- if (show_separator)
+ if (show_separator)
{
- GtkWidget *separator;
+ GtkWidget *separator;
- separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_widget_show (separator);
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_show (separator);
- gtk_list_box_row_set_header (row, separator);
+ gtk_list_box_row_set_header (row, separator);
}
}
@@ -243,25 +248,24 @@ static void
select_date_button_clicked (GtkButton *button,
NautilusSearchPopover *popover)
{
+ /* Hide the type selection widgets when date selection
+ * widgets are shown.
+ */
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
- /* Hide the type selection widgets when date selection
- * widgets are shown.
- */
- gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
-
- show_date_selection_widgets (popover, TRUE);
+ show_date_selection_widgets (popover, TRUE);
}
static void
select_type_button_clicked (GtkButton *button,
NautilusSearchPopover *popover)
{
- gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-list");
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-list");
- /* Hide the date selection widgets when the type selection
- * listbox is shown.
- */
- show_date_selection_widgets (popover, FALSE);
+ /* Hide the date selection widgets when the type selection
+ * listbox is shown.
+ */
+ show_date_selection_widgets (popover, FALSE);
}
static void
@@ -270,29 +274,29 @@ toggle_calendar_icon_clicked (GtkEntry *entry,
GdkEvent *event,
NautilusSearchPopover *popover)
{
- const gchar *current_visible_child;
- const gchar *child;
- const gchar *icon_name;
- const gchar *tooltip;
+ const gchar *current_visible_child;
+ const gchar *child;
+ const gchar *icon_name;
+ const gchar *tooltip;
- current_visible_child = gtk_stack_get_visible_child_name (GTK_STACK (popover->around_stack));
+ current_visible_child = gtk_stack_get_visible_child_name (GTK_STACK (popover->around_stack));
- if (g_strcmp0 (current_visible_child, "date-list") == 0)
+ if (g_strcmp0 (current_visible_child, "date-list") == 0)
{
- child = "date-calendar";
- icon_name = "view-list-symbolic";
- tooltip = _("Show a list to select the date");
+ child = "date-calendar";
+ icon_name = "view-list-symbolic";
+ tooltip = _("Show a list to select the date");
}
- else
+ else
{
- child = "date-list";
- icon_name = "x-office-calendar-symbolic";
- tooltip = _("Show a calendar to select the date");
+ child = "date-list";
+ icon_name = "x-office-calendar-symbolic";
+ tooltip = _("Show a calendar to select the date");
}
- gtk_stack_set_visible_child_name (GTK_STACK (popover->around_stack), child);
- gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, icon_name);
- gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, tooltip);
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->around_stack), child);
+ gtk_entry_set_icon_from_icon_name (entry, GTK_ENTRY_ICON_SECONDARY, icon_name);
+ gtk_entry_set_icon_tooltip_text (entry, GTK_ENTRY_ICON_SECONDARY, tooltip);
}
static void
@@ -300,362 +304,369 @@ types_listbox_row_activated (GtkListBox *listbox,
GtkListBoxRow *row,
NautilusSearchPopover *popover)
{
- gint group;
+ gint group;
- group = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "mimetype-group"));
+ group = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "mimetype-group"));
- /* The -1 group stands for the "Other Types" group, for which
- * we should show the mimetype dialog.
- */
- if (group == -1)
+ /* The -1 group stands for the "Other Types" group, for which
+ * we should show the mimetype dialog.
+ */
+ if (group == -1)
{
- show_other_types_dialog (popover);
+ show_other_types_dialog (popover);
}
- else
+ else
{
- gtk_label_set_label (GTK_LABEL (popover->type_label),
- nautilus_mime_types_group_get_name (group));
+ gtk_label_set_label (GTK_LABEL (popover->type_label),
+ nautilus_mime_types_group_get_name (group));
- g_signal_emit_by_name (popover, "mime-type", group, NULL);
+ g_signal_emit_by_name (popover, "mime-type", group, NULL);
}
- gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
}
static void
search_time_type_changed (GtkToggleButton *button,
NautilusSearchPopover *popover)
{
- NautilusQuerySearchType type = -1;
+ NautilusQuerySearchType type = -1;
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (popover->last_modified_button)))
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (popover->last_modified_button)))
{
- type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED;
+ type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED;
}
- else
+ else
{
- type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS;
+ type = NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS;
}
- g_settings_set_enum (nautilus_preferences, "search-filter-time-type", type);
+ g_settings_set_enum (nautilus_preferences, "search-filter-time-type", type);
- g_signal_emit_by_name (popover, "time-type", type, NULL);
+ g_signal_emit_by_name (popover, "time-type", type, NULL);
}
/* Auxiliary methods */
-static GtkWidget*
+static GtkWidget *
create_row_for_label (const gchar *text,
gboolean show_separator)
{
- GtkWidget *row;
- GtkWidget *label;
+ GtkWidget *row;
+ GtkWidget *label;
- row = gtk_list_box_row_new ();
+ row = gtk_list_box_row_new ();
- g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
+ g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
- label = g_object_new (GTK_TYPE_LABEL,
- "label", text,
- "hexpand", TRUE,
- "xalign", 0.0,
- "margin-start", 6,
- NULL);
+ label = g_object_new (GTK_TYPE_LABEL,
+ "label", text,
+ "hexpand", TRUE,
+ "xalign", 0.0,
+ "margin-start", 6,
+ NULL);
- gtk_container_add (GTK_CONTAINER (row), label);
- gtk_widget_show_all (row);
+ gtk_container_add (GTK_CONTAINER (row), label);
+ gtk_widget_show_all (row);
- return row;
+ return row;
}
static void
fill_fuzzy_dates_listbox (NautilusSearchPopover *popover)
{
- GDateTime *maximum_dt, *now;
- GtkWidget *row;
- GDateTime *current_date;
- GPtrArray *date_range;
- gint days, max_days;
-
- days = 1;
- maximum_dt = g_date_time_new_from_unix_local (0);
- now = g_date_time_new_now_local ();
- max_days = SEARCH_FILTER_MAX_YEARS * 365;
-
- /* Add the no date filter element first */
- row = create_row_for_label (_("Any time"), TRUE);
- gtk_container_add (GTK_CONTAINER (popover->dates_listbox), row);
-
- /* This is a tricky loop. The main intention here is that each
- * timeslice (day, week, month) have 2 or 3 entries.
- *
- * For the first appearance of each timeslice, there is made a
- * check in order to be sure that there is no offset added to days.
- */
- while (days <= max_days)
+ GDateTime *maximum_dt, *now;
+ GtkWidget *row;
+ GDateTime *current_date;
+ GPtrArray *date_range;
+ gint days, max_days;
+
+ days = 1;
+ maximum_dt = g_date_time_new_from_unix_local (0);
+ now = g_date_time_new_now_local ();
+ max_days = SEARCH_FILTER_MAX_YEARS * 365;
+
+ /* Add the no date filter element first */
+ row = create_row_for_label (_("Any time"), TRUE);
+ gtk_container_add (GTK_CONTAINER (popover->dates_listbox), row);
+
+ /* This is a tricky loop. The main intention here is that each
+ * timeslice (day, week, month) have 2 or 3 entries.
+ *
+ * For the first appearance of each timeslice, there is made a
+ * check in order to be sure that there is no offset added to days.
+ */
+ while (days <= max_days)
{
- gchar *label;
- gint normalized;
- gint step;
+ gchar *label;
+ gint normalized;
+ gint step;
- if (days < 7)
+ if (days < 7)
{
- /* days */
- normalized = days;
- step = 2;
+ /* days */
+ normalized = days;
+ step = 2;
}
- else if (days < 30)
+ else if (days < 30)
{
- /* weeks */
- normalized = days / 7;
- if (normalized == 1)
- days = 7;
- step = 7;
+ /* weeks */
+ normalized = days / 7;
+ if (normalized == 1)
+ {
+ days = 7;
+ }
+ step = 7;
}
- else if (days < 365)
+ else if (days < 365)
{
- /* months */
- normalized = days / 30;
- if (normalized == 1)
- days = 30;
- step = 90;
+ /* months */
+ normalized = days / 30;
+ if (normalized == 1)
+ {
+ days = 30;
+ }
+ step = 90;
}
- else
+ else
{
- /* years */
- normalized = days / 365;
- if (normalized == 1)
- days = 365;
- step = 365;
+ /* years */
+ normalized = days / 365;
+ if (normalized == 1)
+ {
+ days = 365;
+ }
+ step = 365;
}
- current_date = g_date_time_add_days (now, -days);
- date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
- g_ptr_array_add (date_range, g_date_time_ref (current_date));
- g_ptr_array_add (date_range, g_date_time_ref (now));
- label = get_text_for_date_range (date_range);
- row = create_row_for_label (label, normalized == 1);
- g_object_set_data (G_OBJECT (row), "date", g_date_time_ref (current_date));
+ current_date = g_date_time_add_days (now, -days);
+ date_range = g_ptr_array_new_full (2, (GDestroyNotify) g_date_time_unref);
+ g_ptr_array_add (date_range, g_date_time_ref (current_date));
+ g_ptr_array_add (date_range, g_date_time_ref (now));
+ label = get_text_for_date_range (date_range);
+ row = create_row_for_label (label, normalized == 1);
+ g_object_set_data (G_OBJECT (row), "date", g_date_time_ref (current_date));
- gtk_container_add (GTK_CONTAINER (popover->dates_listbox), row);
+ gtk_container_add (GTK_CONTAINER (popover->dates_listbox), row);
- g_free (label);
- g_date_time_unref (current_date);
- g_ptr_array_unref (date_range);
+ g_free (label);
+ g_date_time_unref (current_date);
+ g_ptr_array_unref (date_range);
- days += step;
+ days += step;
}
- g_date_time_unref (maximum_dt);
- g_date_time_unref (now);
+ g_date_time_unref (maximum_dt);
+ g_date_time_unref (now);
}
static void
fill_types_listbox (NautilusSearchPopover *popover)
{
- GtkWidget *row;
- int i;
- gint n_groups;
+ GtkWidget *row;
+ int i;
+ gint n_groups;
- n_groups = nautilus_mime_types_get_number_of_groups ();
- /* Mimetypes */
- for (i = 0; i < n_groups; i++)
+ n_groups = nautilus_mime_types_get_number_of_groups ();
+ /* Mimetypes */
+ for (i = 0; i < n_groups; i++)
{
+ /* On the third row, which is right below "Folders", there should be an
+ * separator to logically group the types.
+ */
+ row = create_row_for_label (nautilus_mime_types_group_get_name (i), i == 3);
+ g_object_set_data (G_OBJECT (row), "mimetype-group", GINT_TO_POINTER (i));
- /* On the third row, which is right below "Folders", there should be an
- * separator to logically group the types.
- */
- row = create_row_for_label (nautilus_mime_types_group_get_name (i), i == 3);
- g_object_set_data (G_OBJECT (row), "mimetype-group", GINT_TO_POINTER (i));
-
- gtk_container_add (GTK_CONTAINER (popover->type_listbox), row);
+ gtk_container_add (GTK_CONTAINER (popover->type_listbox), row);
}
- /* Other types */
- row = create_row_for_label (_("Other Type…"), TRUE);
- g_object_set_data (G_OBJECT (row), "mimetype-group", GINT_TO_POINTER (-1));
- gtk_container_add (GTK_CONTAINER (popover->type_listbox), row);
+ /* Other types */
+ row = create_row_for_label (_("Other Type…"), TRUE);
+ g_object_set_data (G_OBJECT (row), "mimetype-group", GINT_TO_POINTER (-1));
+ gtk_container_add (GTK_CONTAINER (popover->type_listbox), row);
}
static void
show_date_selection_widgets (NautilusSearchPopover *popover,
gboolean visible)
{
- gtk_stack_set_visible_child_name (GTK_STACK (popover->date_stack),
- visible ? "date-entry" : "date-button");
- gtk_stack_set_visible_child_name (GTK_STACK (popover->around_stack), "date-list");
- gtk_entry_set_icon_from_icon_name (GTK_ENTRY (popover->date_entry),
- GTK_ENTRY_ICON_SECONDARY,
- "x-office-calendar-symbolic");
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->date_stack),
+ visible ? "date-entry" : "date-button");
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->around_stack), "date-list");
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (popover->date_entry),
+ GTK_ENTRY_ICON_SECONDARY,
+ "x-office-calendar-symbolic");
- gtk_widget_set_visible (popover->around_revealer, visible);
+ gtk_widget_set_visible (popover->around_revealer, visible);
- gtk_revealer_set_reveal_child (GTK_REVEALER (popover->around_revealer), visible);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (popover->around_revealer), visible);
}
static void
show_other_types_dialog (NautilusSearchPopover *popover)
{
- GList *mime_infos, *l;
- GtkWidget *dialog;
- GtkWidget *scrolled, *treeview;
- GtkListStore *store;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkWidget *toplevel;
- GtkTreeSelection *selection;
-
- mime_infos = g_content_types_get_registered ();
-
- store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
- for (l = mime_infos; l != NULL; l = l->next)
+ GList *mime_infos, *l;
+ GtkWidget *dialog;
+ GtkWidget *scrolled, *treeview;
+ GtkListStore *store;
+ GtkTreeViewColumn *column;
+ GtkCellRenderer *renderer;
+ GtkWidget *toplevel;
+ GtkTreeSelection *selection;
+
+ mime_infos = g_content_types_get_registered ();
+
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
+ for (l = mime_infos; l != NULL; l = l->next)
{
- GtkTreeIter iter;
- char *mime_type = l->data;
- char *description;
+ GtkTreeIter iter;
+ char *mime_type = l->data;
+ char *description;
- description = g_content_type_get_description (mime_type);
- if (description == NULL)
+ description = g_content_type_get_description (mime_type);
+ if (description == NULL)
{
- description = g_strdup (mime_type);
+ description = g_strdup (mime_type);
}
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, description,
- 1, mime_type,
- -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, description,
+ 1, mime_type,
+ -1);
- g_free (mime_type);
- g_free (description);
+ g_free (mime_type);
+ g_free (description);
}
- g_list_free (mime_infos);
-
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (popover));
- dialog = gtk_dialog_new_with_buttons (_("Select type"),
- GTK_WINDOW (toplevel),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
- _("_Cancel"), GTK_RESPONSE_CANCEL,
- _("Select"), GTK_RESPONSE_OK,
- NULL);
- gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 600);
-
- scrolled = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- gtk_widget_show (scrolled);
- gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 0);
- gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), scrolled, TRUE, TRUE, 0);
-
- treeview = gtk_tree_view_new ();
- gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
- gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0, GTK_SORT_ASCENDING);
-
- selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
- gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
-
-
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ("Name",
- renderer,
- "text",
- 0,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
- gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
-
- gtk_widget_show (treeview);
- gtk_container_add (GTK_CONTAINER (scrolled), treeview);
-
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
+ g_list_free (mime_infos);
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (popover));
+ dialog = gtk_dialog_new_with_buttons (_("Select type"),
+ GTK_WINDOW (toplevel),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("Select"), GTK_RESPONSE_OK,
+ NULL);
+ gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 600);
+
+ scrolled = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ gtk_widget_show (scrolled);
+ gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 0);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), scrolled, TRUE, TRUE, 0);
+
+ treeview = gtk_tree_view_new ();
+ gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (store));
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), 0, GTK_SORT_ASCENDING);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
+
+
+ renderer = gtk_cell_renderer_text_new ();
+ column = gtk_tree_view_column_new_with_attributes ("Name",
+ renderer,
+ "text",
+ 0,
+ NULL);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
+
+ gtk_widget_show (treeview);
+ gtk_container_add (GTK_CONTAINER (scrolled), treeview);
+
+ if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
{
- GtkTreeIter iter;
- char *mimetype;
- char *description;
+ GtkTreeIter iter;
+ char *mimetype;
+ char *description;
- gtk_tree_selection_get_selected (selection, NULL, &iter);
- gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
- 0, &description,
- 1, &mimetype,
- -1);
+ gtk_tree_selection_get_selected (selection, NULL, &iter);
+ gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
+ 0, &description,
+ 1, &mimetype,
+ -1);
- gtk_label_set_label (GTK_LABEL (popover->type_label), description);
+ gtk_label_set_label (GTK_LABEL (popover->type_label), description);
- g_signal_emit_by_name (popover, "mime-type", -1, mimetype);
+ g_signal_emit_by_name (popover, "mime-type", -1, mimetype);
- gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
}
- gtk_widget_destroy (dialog);
+ gtk_widget_destroy (dialog);
}
static void
update_date_label (NautilusSearchPopover *popover,
GPtrArray *date_range)
{
- if (date_range)
+ if (date_range)
{
- gint days;
- GDateTime *initial_date;
- GDateTime *end_date;
- GDateTime *now;
- gchar *label;
+ gint days;
+ GDateTime *initial_date;
+ GDateTime *end_date;
+ GDateTime *now;
+ gchar *label;
- now = g_date_time_new_now_local ();
- initial_date = g_ptr_array_index (date_range, 0);
- end_date = g_ptr_array_index (date_range, 0);
- days = g_date_time_difference (end_date, initial_date) / G_TIME_SPAN_DAY;
+ now = g_date_time_new_now_local ();
+ initial_date = g_ptr_array_index (date_range, 0);
+ end_date = g_ptr_array_index (date_range, 0);
+ days = g_date_time_difference (end_date, initial_date) / G_TIME_SPAN_DAY;
- label = get_text_for_date_range (date_range);
+ label = get_text_for_date_range (date_range);
- gtk_entry_set_text (GTK_ENTRY (popover->date_entry), days < 1 ? label : "");
+ gtk_entry_set_text (GTK_ENTRY (popover->date_entry), days < 1 ? label : "");
- gtk_widget_show (popover->clear_date_button);
- gtk_label_set_label (GTK_LABEL (popover->select_date_button_label), label);
+ gtk_widget_show (popover->clear_date_button);
+ gtk_label_set_label (GTK_LABEL (popover->select_date_button_label), label);
- g_date_time_unref (now);
- g_free (label);
+ g_date_time_unref (now);
+ g_free (label);
}
- else
+ else
{
- gtk_label_set_label (GTK_LABEL (popover->select_date_button_label),
- _("Select Dates…"));
- gtk_entry_set_text (GTK_ENTRY (popover->date_entry), "");
- gtk_widget_hide (popover->clear_date_button);
+ gtk_label_set_label (GTK_LABEL (popover->select_date_button_label),
+ _("Select Dates…"));
+ gtk_entry_set_text (GTK_ENTRY (popover->date_entry), "");
+ gtk_widget_hide (popover->clear_date_button);
}
}
static void
nautilus_search_popover_closed (GtkPopover *popover)
{
- NautilusSearchPopover *self = NAUTILUS_SEARCH_POPOVER (popover);
- GDateTime *now;
+ NautilusSearchPopover *self = NAUTILUS_SEARCH_POPOVER (popover);
+ GDateTime *now;
- /* Always switch back to the initial states */
- gtk_stack_set_visible_child_name (GTK_STACK (self->type_stack), "type-button");
- show_date_selection_widgets (self, FALSE);
+ /* Always switch back to the initial states */
+ gtk_stack_set_visible_child_name (GTK_STACK (self->type_stack), "type-button");
+ show_date_selection_widgets (self, FALSE);
- /* If we're closing an ongoing query, the popover must not
- * clear the current settings.
- */
- if (self->query)
- return;
+ /* If we're closing an ongoing query, the popover must not
+ * clear the current settings.
+ */
+ if (self->query)
+ {
+ return;
+ }
- now = g_date_time_new_now_local ();
+ now = g_date_time_new_now_local ();
- /* Reselect today at the calendar */
- g_signal_handlers_block_by_func (self->calendar, calendar_day_selected, self);
+ /* Reselect today at the calendar */
+ g_signal_handlers_block_by_func (self->calendar, calendar_day_selected, self);
- gtk_calendar_select_month (GTK_CALENDAR (self->calendar),
- g_date_time_get_month (now) - 1,
- g_date_time_get_year (now));
+ gtk_calendar_select_month (GTK_CALENDAR (self->calendar),
+ g_date_time_get_month (now) - 1,
+ g_date_time_get_year (now));
- gtk_calendar_select_day (GTK_CALENDAR (self->calendar),
- g_date_time_get_day_of_month (now));
+ gtk_calendar_select_day (GTK_CALENDAR (self->calendar),
+ g_date_time_get_day_of_month (now));
- g_signal_handlers_unblock_by_func (self->calendar, calendar_day_selected, self);
+ g_signal_handlers_unblock_by_func (self->calendar, calendar_day_selected, self);
}
static void
@@ -664,18 +675,20 @@ nautilus_search_popover_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- NautilusSearchPopover *self;
+ NautilusSearchPopover *self;
- self = NAUTILUS_SEARCH_POPOVER (object);
+ self = NAUTILUS_SEARCH_POPOVER (object);
- switch (prop_id)
+ switch (prop_id)
{
- case PROP_QUERY:
- g_value_set_object (value, self->query);
+ case PROP_QUERY:
+ {
+ g_value_set_object (value, self->query);
+ }
break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
@@ -685,18 +698,20 @@ nautilus_search_popover_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- NautilusSearchPopover *self;
+ NautilusSearchPopover *self;
- self = NAUTILUS_SEARCH_POPOVER (object);
+ self = NAUTILUS_SEARCH_POPOVER (object);
- switch (prop_id)
+ switch (prop_id)
{
- case PROP_QUERY:
- nautilus_search_popover_set_query (self, g_value_get_object (value));
+ case PROP_QUERY:
+ {
+ nautilus_search_popover_set_query (self, g_value_get_object (value));
+ }
break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
@@ -704,130 +719,130 @@ nautilus_search_popover_set_property (GObject *object,
static void
nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass)
{
- GtkPopoverClass *popover_class = GTK_POPOVER_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->get_property = nautilus_search_popover_get_property;
- object_class->set_property = nautilus_search_popover_set_property;
-
- popover_class->closed = nautilus_search_popover_closed;
-
- signals[DATE_RANGE] = g_signal_new ("date-range",
- NAUTILUS_TYPE_SEARCH_POPOVER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
- signals[MIME_TYPE] = g_signal_new ("mime-type",
- NAUTILUS_TYPE_SEARCH_POPOVER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE,
- 2,
- G_TYPE_INT,
- G_TYPE_POINTER);
-
- signals[TIME_TYPE] = g_signal_new ("time-type",
- NAUTILUS_TYPE_SEARCH_POPOVER,
- G_SIGNAL_RUN_LAST,
- 0,
- NULL,
- NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE,
- 1,
- G_TYPE_INT);
-
- /**
- * NautilusSearchPopover::query:
- *
- * The current #NautilusQuery being edited.
- */
- g_object_class_install_property (object_class,
- PROP_QUERY,
- g_param_spec_object ("query",
- "Query of the popover",
- "The current query being edited",
- NAUTILUS_TYPE_QUERY,
- G_PARAM_READWRITE));
-
- gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/ui/nautilus-search-popover.ui");
-
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, around_revealer);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, around_stack);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, clear_date_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, calendar);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, dates_listbox);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, date_entry);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, date_stack);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, select_date_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, select_date_button_label);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_label);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_listbox);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_stack);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_used_button);
- gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_modified_button);
-
- gtk_widget_class_bind_template_callback (widget_class, calendar_day_selected);
- gtk_widget_class_bind_template_callback (widget_class, clear_date_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, date_entry_activate);
- gtk_widget_class_bind_template_callback (widget_class, dates_listbox_row_activated);
- gtk_widget_class_bind_template_callback (widget_class, select_date_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, select_type_button_clicked);
- gtk_widget_class_bind_template_callback (widget_class, toggle_calendar_icon_clicked);
- gtk_widget_class_bind_template_callback (widget_class, types_listbox_row_activated);
- gtk_widget_class_bind_template_callback (widget_class, search_time_type_changed);
+ GtkPopoverClass *popover_class = GTK_POPOVER_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = nautilus_search_popover_get_property;
+ object_class->set_property = nautilus_search_popover_set_property;
+
+ popover_class->closed = nautilus_search_popover_closed;
+
+ signals[DATE_RANGE] = g_signal_new ("date-range",
+ NAUTILUS_TYPE_SEARCH_POPOVER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ signals[MIME_TYPE] = g_signal_new ("mime-type",
+ NAUTILUS_TYPE_SEARCH_POPOVER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_INT,
+ G_TYPE_POINTER);
+
+ signals[TIME_TYPE] = g_signal_new ("time-type",
+ NAUTILUS_TYPE_SEARCH_POPOVER,
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_INT);
+
+ /**
+ * NautilusSearchPopover::query:
+ *
+ * The current #NautilusQuery being edited.
+ */
+ g_object_class_install_property (object_class,
+ PROP_QUERY,
+ g_param_spec_object ("query",
+ "Query of the popover",
+ "The current query being edited",
+ NAUTILUS_TYPE_QUERY,
+ G_PARAM_READWRITE));
+
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/ui/nautilus-search-popover.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, around_revealer);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, around_stack);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, clear_date_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, calendar);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, dates_listbox);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, date_entry);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, date_stack);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, select_date_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, select_date_button_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_label);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_listbox);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, type_stack);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_used_button);
+ gtk_widget_class_bind_template_child (widget_class, NautilusSearchPopover, last_modified_button);
+
+ gtk_widget_class_bind_template_callback (widget_class, calendar_day_selected);
+ gtk_widget_class_bind_template_callback (widget_class, clear_date_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, date_entry_activate);
+ gtk_widget_class_bind_template_callback (widget_class, dates_listbox_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, select_date_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, select_type_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, toggle_calendar_icon_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, types_listbox_row_activated);
+ gtk_widget_class_bind_template_callback (widget_class, search_time_type_changed);
}
static void
nautilus_search_popover_init (NautilusSearchPopover *self)
{
- NautilusQuerySearchType filter_time_type;
+ NautilusQuerySearchType filter_time_type;
- gtk_widget_init_template (GTK_WIDGET (self));
+ gtk_widget_init_template (GTK_WIDGET (self));
- /* Fuzzy dates listbox */
- gtk_list_box_set_header_func (GTK_LIST_BOX (self->dates_listbox),
- (GtkListBoxUpdateHeaderFunc) listbox_header_func,
- self,
- NULL);
+ /* Fuzzy dates listbox */
+ gtk_list_box_set_header_func (GTK_LIST_BOX (self->dates_listbox),
+ (GtkListBoxUpdateHeaderFunc) listbox_header_func,
+ self,
+ NULL);
- fill_fuzzy_dates_listbox (self);
+ fill_fuzzy_dates_listbox (self);
- /* Types listbox */
- gtk_list_box_set_header_func (GTK_LIST_BOX (self->type_listbox),
- (GtkListBoxUpdateHeaderFunc) listbox_header_func,
- self,
- NULL);
+ /* Types listbox */
+ gtk_list_box_set_header_func (GTK_LIST_BOX (self->type_listbox),
+ (GtkListBoxUpdateHeaderFunc) listbox_header_func,
+ self,
+ NULL);
- fill_types_listbox (self);
+ fill_types_listbox (self);
- filter_time_type = g_settings_get_enum (nautilus_preferences, "search-filter-time-type");
- if (filter_time_type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
+ filter_time_type = g_settings_get_enum (nautilus_preferences, "search-filter-time-type");
+ if (filter_time_type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), TRUE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), FALSE);
}
- else
+ else
{
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), FALSE);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), TRUE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_modified_button), FALSE);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->last_used_button), TRUE);
}
}
-GtkWidget*
+GtkWidget *
nautilus_search_popover_new (void)
{
- return g_object_new (NAUTILUS_TYPE_SEARCH_POPOVER, NULL);
+ return g_object_new (NAUTILUS_TYPE_SEARCH_POPOVER, NULL);
}
/**
@@ -838,12 +853,12 @@ nautilus_search_popover_new (void)
*
* Returns: (transfer none): the current #NautilusQuery from @popover.
*/
-NautilusQuery*
+NautilusQuery *
nautilus_search_popover_get_query (NautilusSearchPopover *popover)
{
- g_return_val_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover), NULL);
- return popover->query;
+ return popover->query;
}
/**
@@ -859,36 +874,36 @@ void
nautilus_search_popover_set_query (NautilusSearchPopover *popover,
NautilusQuery *query)
{
- NautilusQuery *previous_query;
+ NautilusQuery *previous_query;
- g_return_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover));
- previous_query = popover->query;
+ previous_query = popover->query;
- if (popover->query != query)
+ if (popover->query != query)
{
- /* Disconnect signals and bindings from the old query */
- if (previous_query)
+ /* Disconnect signals and bindings from the old query */
+ if (previous_query)
{
- g_signal_handlers_disconnect_by_func (previous_query, query_date_changed, popover);
+ g_signal_handlers_disconnect_by_func (previous_query, query_date_changed, popover);
}
- g_set_object (&popover->query, query);
+ g_set_object (&popover->query, query);
- if (query)
+ if (query)
{
- /* Date */
- setup_date (popover, query);
+ /* Date */
+ setup_date (popover, query);
- g_signal_connect (query,
- "notify::date",
- G_CALLBACK (query_date_changed),
- popover);
+ g_signal_connect (query,
+ "notify::date",
+ G_CALLBACK (query_date_changed),
+ popover);
}
- else
+ else
{
- nautilus_search_popover_reset_mime_types (popover);
- nautilus_search_popover_reset_date_range (popover);
+ nautilus_search_popover_reset_mime_types (popover);
+ nautilus_search_popover_reset_date_range (popover);
}
}
}
@@ -896,26 +911,26 @@ nautilus_search_popover_set_query (NautilusSearchPopover *popover,
void
nautilus_search_popover_reset_mime_types (NautilusSearchPopover *popover)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover));
- gtk_list_box_select_row (GTK_LIST_BOX (popover->type_listbox),
- gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->type_listbox), 0));
+ gtk_list_box_select_row (GTK_LIST_BOX (popover->type_listbox),
+ gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->type_listbox), 0));
- gtk_label_set_label (GTK_LABEL (popover->type_label),
- nautilus_mime_types_group_get_name (0));
- g_signal_emit_by_name (popover, "mime-type", 0, NULL);
- gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
+ gtk_label_set_label (GTK_LABEL (popover->type_label),
+ nautilus_mime_types_group_get_name (0));
+ g_signal_emit_by_name (popover, "mime-type", 0, NULL);
+ gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
}
void
nautilus_search_popover_reset_date_range (NautilusSearchPopover *popover)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_POPOVER (popover));
- gtk_list_box_select_row (GTK_LIST_BOX (popover->dates_listbox),
- gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->dates_listbox), 0));
+ gtk_list_box_select_row (GTK_LIST_BOX (popover->dates_listbox),
+ gtk_list_box_get_row_at_index (GTK_LIST_BOX (popover->dates_listbox), 0));
- update_date_label (popover, NULL);
- show_date_selection_widgets (popover, FALSE);
- g_signal_emit_by_name (popover, "date-range", NULL);
+ update_date_label (popover, NULL);
+ show_date_selection_widgets (popover, FALSE);
+ g_signal_emit_by_name (popover, "date-range", NULL);
}
diff --git a/src/nautilus-search-provider.c b/src/nautilus-search-provider.c
index ccbd7854d..eee91bc1b 100644
--- a/src/nautilus-search-provider.c
+++ b/src/nautilus-search-provider.c
@@ -22,11 +22,12 @@
#include <glib-object.h>
-enum {
- HITS_ADDED,
- FINISHED,
- ERROR,
- LAST_SIGNAL
+enum
+{
+ HITS_ADDED,
+ FINISHED,
+ ERROR,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -36,107 +37,109 @@ G_DEFINE_INTERFACE (NautilusSearchProvider, nautilus_search_provider, G_TYPE_OBJ
static void
nautilus_search_provider_default_init (NautilusSearchProviderInterface *iface)
{
-
- /**
- * NautilusSearchProvider::running:
- *
- * Whether the provider is running a search.
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("running",
- "Whether the provider is running",
- "Whether the provider is running a search",
- FALSE,
- G_PARAM_READABLE));
-
- signals[HITS_ADDED] = g_signal_new ("hits-added",
- NAUTILUS_TYPE_SEARCH_PROVIDER,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusSearchProviderInterface, hits_added),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- signals[FINISHED] = g_signal_new ("finished",
- NAUTILUS_TYPE_SEARCH_PROVIDER,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusSearchProviderInterface, finished),
- NULL, NULL,
- g_cclosure_marshal_VOID__ENUM,
- G_TYPE_NONE, 1,
- NAUTILUS_TYPE_SEARCH_PROVIDER_STATUS);
-
- signals[ERROR] = g_signal_new ("error",
- NAUTILUS_TYPE_SEARCH_PROVIDER,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusSearchProviderInterface, error),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1,
- G_TYPE_STRING);
+ /**
+ * NautilusSearchProvider::running:
+ *
+ * Whether the provider is running a search.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("running",
+ "Whether the provider is running",
+ "Whether the provider is running a search",
+ FALSE,
+ G_PARAM_READABLE));
+
+ signals[HITS_ADDED] = g_signal_new ("hits-added",
+ NAUTILUS_TYPE_SEARCH_PROVIDER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusSearchProviderInterface, hits_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ signals[FINISHED] = g_signal_new ("finished",
+ NAUTILUS_TYPE_SEARCH_PROVIDER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusSearchProviderInterface, finished),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__ENUM,
+ G_TYPE_NONE, 1,
+ NAUTILUS_TYPE_SEARCH_PROVIDER_STATUS);
+
+ signals[ERROR] = g_signal_new ("error",
+ NAUTILUS_TYPE_SEARCH_PROVIDER,
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusSearchProviderInterface, error),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
}
void
-nautilus_search_provider_set_query (NautilusSearchProvider *provider, NautilusQuery *query)
+nautilus_search_provider_set_query (NautilusSearchProvider *provider,
+ NautilusQuery *query)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
- g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query != NULL);
- g_return_if_fail (NAUTILUS_IS_QUERY (query));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query != NULL);
+ g_return_if_fail (NAUTILUS_IS_QUERY (query));
- NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query (provider, query);
+ NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query (provider, query);
}
void
nautilus_search_provider_start (NautilusSearchProvider *provider)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
- g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->start != NULL);
+ g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->start != NULL);
- NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->start (provider);
+ NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->start (provider);
}
void
nautilus_search_provider_stop (NautilusSearchProvider *provider)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
- g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->stop != NULL);
+ g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->stop != NULL);
- NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->stop (provider);
+ NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->stop (provider);
}
void
-nautilus_search_provider_hits_added (NautilusSearchProvider *provider, GList *hits)
+nautilus_search_provider_hits_added (NautilusSearchProvider *provider,
+ GList *hits)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
- g_signal_emit (provider, signals[HITS_ADDED], 0, hits);
+ g_signal_emit (provider, signals[HITS_ADDED], 0, hits);
}
void
nautilus_search_provider_finished (NautilusSearchProvider *provider,
NautilusSearchProviderStatus status)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
- g_signal_emit (provider, signals[FINISHED], 0, status);
+ g_signal_emit (provider, signals[FINISHED], 0, status);
}
void
-nautilus_search_provider_error (NautilusSearchProvider *provider, const char *error_message)
+nautilus_search_provider_error (NautilusSearchProvider *provider,
+ const char *error_message)
{
- g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
+ g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
- g_warning ("Provider %s failed with error %s\n",
- G_OBJECT_TYPE_NAME (provider), error_message);
- g_signal_emit (provider, signals[ERROR], 0, error_message);
+ g_warning ("Provider %s failed with error %s\n",
+ G_OBJECT_TYPE_NAME (provider), error_message);
+ g_signal_emit (provider, signals[ERROR], 0, error_message);
}
gboolean
nautilus_search_provider_is_running (NautilusSearchProvider *provider)
{
- g_return_val_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider), FALSE);
- g_return_val_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_running, FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider), FALSE);
+ g_return_val_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_running, FALSE);
- return NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_running (provider);
+ return NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->is_running (provider);
}
diff --git a/src/nautilus-selection-canvas-item.c b/src/nautilus-selection-canvas-item.c
index c1619ca8d..c62b99b7e 100644
--- a/src/nautilus-selection-canvas-item.c
+++ b/src/nautilus-selection-canvas-item.c
@@ -1,4 +1,3 @@
-
/* Nautilus - Canvas item for floating selection.
*
* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation
@@ -27,50 +26,53 @@
#include <math.h>
-enum {
- PROP_X1 = 1,
- PROP_Y1,
- PROP_X2,
- PROP_Y2,
- PROP_FILL_COLOR_RGBA,
- PROP_OUTLINE_COLOR_RGBA,
- PROP_OUTLINE_STIPPLING,
- PROP_WIDTH_PIXELS,
- NUM_PROPERTIES
+enum
+{
+ PROP_X1 = 1,
+ PROP_Y1,
+ PROP_X2,
+ PROP_Y2,
+ PROP_FILL_COLOR_RGBA,
+ PROP_OUTLINE_COLOR_RGBA,
+ PROP_OUTLINE_STIPPLING,
+ PROP_WIDTH_PIXELS,
+ NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL };
-typedef struct {
- /*< public >*/
- int x0, y0, x1, y1;
+typedef struct
+{
+ /*< public >*/
+ int x0, y0, x1, y1;
} Rect;
-struct _NautilusSelectionCanvasItemDetails {
- Rect last_update_rect;
- Rect last_outline_update_rect;
- int last_outline_update_width;
+struct _NautilusSelectionCanvasItemDetails
+{
+ Rect last_update_rect;
+ Rect last_outline_update_rect;
+ int last_outline_update_width;
- double x1, y1, x2, y2; /* Corners of item */
- double width; /* Outline width */
+ double x1, y1, x2, y2; /* Corners of item */
+ double width; /* Outline width */
- GdkRGBA fill_color;
- GdkRGBA outline_color;
+ GdkRGBA fill_color;
+ GdkRGBA outline_color;
- gboolean outline_stippling;
+ gboolean outline_stippling;
- /* Configuration flags */
+ /* Configuration flags */
- unsigned int fill_set : 1; /* Is fill color set? */
- unsigned int outline_set : 1; /* Is outline color set? */
+ unsigned int fill_set : 1; /* Is fill color set? */
+ unsigned int outline_set : 1; /* Is outline color set? */
- double fade_out_fill_alpha;
- double fade_out_outline_alpha;
+ double fade_out_fill_alpha;
+ double fade_out_outline_alpha;
- gint64 fade_out_start_time;
- gint64 fade_out_end_time;
+ gint64 fade_out_start_time;
+ gint64 fade_out_end_time;
- guint fade_out_tick_id;
+ guint fade_out_tick_id;
};
G_DEFINE_TYPE (NautilusSelectionCanvasItem, nautilus_selection_canvas_item, EEL_TYPE_CANVAS_ITEM);
@@ -78,635 +80,744 @@ G_DEFINE_TYPE (NautilusSelectionCanvasItem, nautilus_selection_canvas_item, EEL_
#define DASH_ON 0.8
#define DASH_OFF 1.7
static void
-nautilus_selection_canvas_item_draw (EelCanvasItem *item,
- cairo_t *cr,
- cairo_region_t *region)
+nautilus_selection_canvas_item_draw (EelCanvasItem *item,
+ cairo_t *cr,
+ cairo_region_t *region)
{
- NautilusSelectionCanvasItem *self;
- double x1, y1, x2, y2;
- int cx1, cy1, cx2, cy2;
- double i2w_dx, i2w_dy;
-
- self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
-
- /* Get canvas pixel coordinates */
- i2w_dx = 0.0;
- i2w_dy = 0.0;
- eel_canvas_item_i2w (item, &i2w_dx, &i2w_dy);
-
- x1 = self->priv->x1 + i2w_dx;
- y1 = self->priv->y1 + i2w_dy;
- x2 = self->priv->x2 + i2w_dx;
- y2 = self->priv->y2 + i2w_dy;
-
- eel_canvas_w2c (item->canvas, x1, y1, &cx1, &cy1);
- eel_canvas_w2c (item->canvas, x2, y2, &cx2, &cy2);
-
- if (cx2 <= cx1 || cy2 <= cy1 ) {
- return;
- }
-
- cairo_save (cr);
-
- if (self->priv->fill_set) {
- GdkRGBA actual_fill;
-
- actual_fill = self->priv->fill_color;
-
- if (self->priv->fade_out_tick_id != 0) {
- actual_fill.alpha = self->priv->fade_out_fill_alpha;
- }
-
- gdk_cairo_set_source_rgba (cr, &actual_fill);
- cairo_rectangle (cr,
- cx1, cy1,
- cx2 - cx1 + 1,
- cy2 - cy1 + 1);
- cairo_fill (cr);
- }
-
- if (self->priv->outline_set) {
- GdkRGBA actual_outline;
-
- actual_outline = self->priv->outline_color;
-
- if (self->priv->fade_out_tick_id != 0) {
- actual_outline.alpha = self->priv->fade_out_outline_alpha;
- }
-
- gdk_cairo_set_source_rgba (cr, &actual_outline);
- cairo_set_line_width (cr, (int) self->priv->width);
-
- if (self->priv->outline_stippling) {
- double dash[2] = { DASH_ON, DASH_OFF };
-
- cairo_set_dash (cr, dash, G_N_ELEMENTS (dash), 0);
- }
-
- cairo_rectangle (cr,
- cx1 + 0.5, cy1 + 0.5,
- cx2 - cx1,
- cy2 - cy1);
- cairo_stroke (cr);
- }
-
- cairo_restore (cr);
+ NautilusSelectionCanvasItem *self;
+ double x1, y1, x2, y2;
+ int cx1, cy1, cx2, cy2;
+ double i2w_dx, i2w_dy;
+
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
+
+ /* Get canvas pixel coordinates */
+ i2w_dx = 0.0;
+ i2w_dy = 0.0;
+ eel_canvas_item_i2w (item, &i2w_dx, &i2w_dy);
+
+ x1 = self->priv->x1 + i2w_dx;
+ y1 = self->priv->y1 + i2w_dy;
+ x2 = self->priv->x2 + i2w_dx;
+ y2 = self->priv->y2 + i2w_dy;
+
+ eel_canvas_w2c (item->canvas, x1, y1, &cx1, &cy1);
+ eel_canvas_w2c (item->canvas, x2, y2, &cx2, &cy2);
+
+ if (cx2 <= cx1 || cy2 <= cy1)
+ {
+ return;
+ }
+
+ cairo_save (cr);
+
+ if (self->priv->fill_set)
+ {
+ GdkRGBA actual_fill;
+
+ actual_fill = self->priv->fill_color;
+
+ if (self->priv->fade_out_tick_id != 0)
+ {
+ actual_fill.alpha = self->priv->fade_out_fill_alpha;
+ }
+
+ gdk_cairo_set_source_rgba (cr, &actual_fill);
+ cairo_rectangle (cr,
+ cx1, cy1,
+ cx2 - cx1 + 1,
+ cy2 - cy1 + 1);
+ cairo_fill (cr);
+ }
+
+ if (self->priv->outline_set)
+ {
+ GdkRGBA actual_outline;
+
+ actual_outline = self->priv->outline_color;
+
+ if (self->priv->fade_out_tick_id != 0)
+ {
+ actual_outline.alpha = self->priv->fade_out_outline_alpha;
+ }
+
+ gdk_cairo_set_source_rgba (cr, &actual_outline);
+ cairo_set_line_width (cr, (int) self->priv->width);
+
+ if (self->priv->outline_stippling)
+ {
+ double dash[2] = { DASH_ON, DASH_OFF };
+
+ cairo_set_dash (cr, dash, G_N_ELEMENTS (dash), 0);
+ }
+
+ cairo_rectangle (cr,
+ cx1 + 0.5, cy1 + 0.5,
+ cx2 - cx1,
+ cy2 - cy1);
+ cairo_stroke (cr);
+ }
+
+ cairo_restore (cr);
}
static double
-nautilus_selection_canvas_item_point (EelCanvasItem *item,
- double x,
- double y,
- int cx,
- int cy,
- EelCanvasItem **actual_item)
+nautilus_selection_canvas_item_point (EelCanvasItem *item,
+ double x,
+ double y,
+ int cx,
+ int cy,
+ EelCanvasItem **actual_item)
{
- NautilusSelectionCanvasItem *self;
- double x1, y1, x2, y2;
- double hwidth;
- double dx, dy;
- double tmp;
-
- self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
- *actual_item = item;
-
- /* Find the bounds for the rectangle plus its outline width */
-
- x1 = self->priv->x1;
- y1 = self->priv->y1;
- x2 = self->priv->x2;
- y2 = self->priv->y2;
-
- if (self->priv->outline_set) {
- hwidth = (self->priv->width / item->canvas->pixels_per_unit) / 2.0;
-
- x1 -= hwidth;
- y1 -= hwidth;
- x2 += hwidth;
- y2 += hwidth;
- } else
- hwidth = 0.0;
-
- /* Is point inside rectangle (which can be hollow if it has no fill set)? */
-
- if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
- if (self->priv->fill_set || !self->priv->outline_set)
- return 0.0;
-
- dx = x - x1;
- tmp = x2 - x;
- if (tmp < dx)
- dx = tmp;
-
- dy = y - y1;
- tmp = y2 - y;
- if (tmp < dy)
- dy = tmp;
-
- if (dy < dx)
- dx = dy;
-
- dx -= 2.0 * hwidth;
-
- if (dx < 0.0)
- return 0.0;
- else
- return dx;
- }
-
- /* Point is outside rectangle */
-
- if (x < x1)
- dx = x1 - x;
- else if (x > x2)
- dx = x - x2;
- else
- dx = 0.0;
-
- if (y < y1)
- dy = y1 - y;
- else if (y > y2)
- dy = y - y2;
- else
- dy = 0.0;
-
- return sqrt (dx * dx + dy * dy);
+ NautilusSelectionCanvasItem *self;
+ double x1, y1, x2, y2;
+ double hwidth;
+ double dx, dy;
+ double tmp;
+
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
+ *actual_item = item;
+
+ /* Find the bounds for the rectangle plus its outline width */
+
+ x1 = self->priv->x1;
+ y1 = self->priv->y1;
+ x2 = self->priv->x2;
+ y2 = self->priv->y2;
+
+ if (self->priv->outline_set)
+ {
+ hwidth = (self->priv->width / item->canvas->pixels_per_unit) / 2.0;
+
+ x1 -= hwidth;
+ y1 -= hwidth;
+ x2 += hwidth;
+ y2 += hwidth;
+ }
+ else
+ {
+ hwidth = 0.0;
+ }
+
+ /* Is point inside rectangle (which can be hollow if it has no fill set)? */
+
+ if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2))
+ {
+ if (self->priv->fill_set || !self->priv->outline_set)
+ {
+ return 0.0;
+ }
+
+ dx = x - x1;
+ tmp = x2 - x;
+ if (tmp < dx)
+ {
+ dx = tmp;
+ }
+
+ dy = y - y1;
+ tmp = y2 - y;
+ if (tmp < dy)
+ {
+ dy = tmp;
+ }
+
+ if (dy < dx)
+ {
+ dx = dy;
+ }
+
+ dx -= 2.0 * hwidth;
+
+ if (dx < 0.0)
+ {
+ return 0.0;
+ }
+ else
+ {
+ return dx;
+ }
+ }
+
+ /* Point is outside rectangle */
+
+ if (x < x1)
+ {
+ dx = x1 - x;
+ }
+ else if (x > x2)
+ {
+ dx = x - x2;
+ }
+ else
+ {
+ dx = 0.0;
+ }
+
+ if (y < y1)
+ {
+ dy = y1 - y;
+ }
+ else if (y > y2)
+ {
+ dy = y - y2;
+ }
+ else
+ {
+ dy = 0.0;
+ }
+
+ return sqrt (dx * dx + dy * dy);
}
static void
request_redraw_borders (EelCanvas *canvas,
- Rect *update_rect,
- int width)
+ Rect *update_rect,
+ int width)
{
- eel_canvas_request_redraw (canvas,
- update_rect->x0, update_rect->y0,
- update_rect->x1, update_rect->y0 + width);
- eel_canvas_request_redraw (canvas,
- update_rect->x0, update_rect->y1-width,
- update_rect->x1, update_rect->y1);
- eel_canvas_request_redraw (canvas,
- update_rect->x0, update_rect->y0,
- update_rect->x0+width, update_rect->y1);
- eel_canvas_request_redraw (canvas,
- update_rect->x1-width, update_rect->y0,
- update_rect->x1, update_rect->y1);
+ eel_canvas_request_redraw (canvas,
+ update_rect->x0, update_rect->y0,
+ update_rect->x1, update_rect->y0 + width);
+ eel_canvas_request_redraw (canvas,
+ update_rect->x0, update_rect->y1 - width,
+ update_rect->x1, update_rect->y1);
+ eel_canvas_request_redraw (canvas,
+ update_rect->x0, update_rect->y0,
+ update_rect->x0 + width, update_rect->y1);
+ eel_canvas_request_redraw (canvas,
+ update_rect->x1 - width, update_rect->y0,
+ update_rect->x1, update_rect->y1);
}
-static Rect make_rect (int x0, int y0, int x1, int y1);
+static Rect make_rect (int x0,
+ int y0,
+ int x1,
+ int y1);
static int
-rect_empty (const Rect *src) {
- return (src->x1 <= src->x0 || src->y1 <= src->y0);
+rect_empty (const Rect *src)
+{
+ return (src->x1 <= src->x0 || src->y1 <= src->y0);
}
static gboolean
-rects_intersect (Rect r1, Rect r2)
+rects_intersect (Rect r1,
+ Rect r2)
{
- if (r1.x0 >= r2.x1) {
- return FALSE;
- }
- if (r2.x0 >= r1.x1) {
- return FALSE;
- }
- if (r1.y0 >= r2.y1) {
- return FALSE;
- }
- if (r2.y0 >= r1.y1) {
- return FALSE;
- }
- return TRUE;
+ if (r1.x0 >= r2.x1)
+ {
+ return FALSE;
+ }
+ if (r2.x0 >= r1.x1)
+ {
+ return FALSE;
+ }
+ if (r1.y0 >= r2.y1)
+ {
+ return FALSE;
+ }
+ if (r2.y0 >= r1.y1)
+ {
+ return FALSE;
+ }
+ return TRUE;
}
static void
-diff_rects_guts (Rect ra, Rect rb, int *count, Rect result[4])
+diff_rects_guts (Rect ra,
+ Rect rb,
+ int *count,
+ Rect result[4])
{
- if (ra.x0 < rb.x0) {
- result[(*count)++] = make_rect (ra.x0, ra.y0, rb.x0, ra.y1);
- }
- if (ra.y0 < rb.y0) {
- result[(*count)++] = make_rect (ra.x0, ra.y0, ra.x1, rb.y0);
- }
- if (ra.x1 < rb.x1) {
- result[(*count)++] = make_rect (ra.x1, rb.y0, rb.x1, rb.y1);
- }
- if (ra.y1 < rb.y1) {
- result[(*count)++] = make_rect (rb.x0, ra.y1, rb.x1, rb.y1);
- }
+ if (ra.x0 < rb.x0)
+ {
+ result[(*count)++] = make_rect (ra.x0, ra.y0, rb.x0, ra.y1);
+ }
+ if (ra.y0 < rb.y0)
+ {
+ result[(*count)++] = make_rect (ra.x0, ra.y0, ra.x1, rb.y0);
+ }
+ if (ra.x1 < rb.x1)
+ {
+ result[(*count)++] = make_rect (ra.x1, rb.y0, rb.x1, rb.y1);
+ }
+ if (ra.y1 < rb.y1)
+ {
+ result[(*count)++] = make_rect (rb.x0, ra.y1, rb.x1, rb.y1);
+ }
}
static void
-diff_rects (Rect r1, Rect r2, int *count, Rect result[4])
+diff_rects (Rect r1,
+ Rect r2,
+ int *count,
+ Rect result[4])
{
- g_assert (count != NULL);
- g_assert (result != NULL);
-
- *count = 0;
-
- if (rects_intersect (r1, r2)) {
- diff_rects_guts (r1, r2, count, result);
- diff_rects_guts (r2, r1, count, result);
- } else {
- if (!rect_empty (&r1)) {
- result[(*count)++] = r1;
- }
- if (!rect_empty (&r2)) {
- result[(*count)++] = r2;
- }
- }
+ g_assert (count != NULL);
+ g_assert (result != NULL);
+
+ *count = 0;
+
+ if (rects_intersect (r1, r2))
+ {
+ diff_rects_guts (r1, r2, count, result);
+ diff_rects_guts (r2, r1, count, result);
+ }
+ else
+ {
+ if (!rect_empty (&r1))
+ {
+ result[(*count)++] = r1;
+ }
+ if (!rect_empty (&r2))
+ {
+ result[(*count)++] = r2;
+ }
+ }
}
static Rect
-make_rect (int x0, int y0, int x1, int y1)
+make_rect (int x0,
+ int y0,
+ int x1,
+ int y1)
{
- Rect r;
+ Rect r;
- r.x0 = x0;
- r.y0 = y0;
- r.x1 = x1;
- r.y1 = y1;
- return r;
+ r.x0 = x0;
+ r.y0 = y0;
+ r.x1 = x1;
+ r.y1 = y1;
+ return r;
}
static void
nautilus_selection_canvas_item_update (EelCanvasItem *item,
- double i2w_dx,
- double i2w_dy,
- gint flags)
+ double i2w_dx,
+ double i2w_dy,
+ gint flags)
{
- NautilusSelectionCanvasItem *self;
- NautilusSelectionCanvasItemDetails *priv;
- double x1, y1, x2, y2;
- int cx1, cy1, cx2, cy2;
- int repaint_rects_count, i;
- int width_pixels;
- int width_lt, width_rb;
- Rect update_rect, repaint_rects[4];
-
- if (EEL_CANVAS_ITEM_CLASS (nautilus_selection_canvas_item_parent_class)->update)
- (* EEL_CANVAS_ITEM_CLASS (nautilus_selection_canvas_item_parent_class)->update) (item, i2w_dx, i2w_dy, flags);
-
- self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
- priv = self->priv;
-
- x1 = priv->x1 + i2w_dx;
- y1 = priv->y1 + i2w_dy;
- x2 = priv->x2 + i2w_dx;
- y2 = priv->y2 + i2w_dy;
-
- eel_canvas_w2c (item->canvas, x1, y1, &cx1, &cy1);
- eel_canvas_w2c (item->canvas, x2, y2, &cx2, &cy2);
-
- update_rect = make_rect (cx1, cy1, cx2+1, cy2+1);
- diff_rects (update_rect, priv->last_update_rect,
- &repaint_rects_count, repaint_rects);
- for (i = 0; i < repaint_rects_count; i++) {
- eel_canvas_request_redraw (item->canvas,
- repaint_rects[i].x0, repaint_rects[i].y0,
- repaint_rects[i].x1, repaint_rects[i].y1);
- }
-
- priv->last_update_rect = update_rect;
-
- if (priv->outline_set) {
- /* Outline and bounding box */
- width_pixels = (int) priv->width;
- width_lt = width_pixels / 2;
- width_rb = (width_pixels + 1) / 2;
-
- cx1 -= width_lt;
- cy1 -= width_lt;
- cx2 += width_rb;
- cy2 += width_rb;
-
- update_rect = make_rect (cx1, cy1, cx2, cy2);
- request_redraw_borders (item->canvas, &update_rect,
- (width_lt + width_rb));
- request_redraw_borders (item->canvas, &priv->last_outline_update_rect,
- priv->last_outline_update_width);
- priv->last_outline_update_rect = update_rect;
- priv->last_outline_update_width = width_lt + width_rb;
-
- item->x1 = cx1;
- item->y1 = cy1;
- item->x2 = cx2+1;
- item->y2 = cy2+1;
- } else {
- item->x1 = cx1;
- item->y1 = cy1;
- item->x2 = cx2+1;
- item->y2 = cy2+1;
- }
+ NautilusSelectionCanvasItem *self;
+ NautilusSelectionCanvasItemDetails *priv;
+ double x1, y1, x2, y2;
+ int cx1, cy1, cx2, cy2;
+ int repaint_rects_count, i;
+ int width_pixels;
+ int width_lt, width_rb;
+ Rect update_rect, repaint_rects[4];
+
+ if (EEL_CANVAS_ITEM_CLASS (nautilus_selection_canvas_item_parent_class)->update)
+ {
+ (*EEL_CANVAS_ITEM_CLASS (nautilus_selection_canvas_item_parent_class)->update)(item, i2w_dx, i2w_dy, flags);
+ }
+
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
+ priv = self->priv;
+
+ x1 = priv->x1 + i2w_dx;
+ y1 = priv->y1 + i2w_dy;
+ x2 = priv->x2 + i2w_dx;
+ y2 = priv->y2 + i2w_dy;
+
+ eel_canvas_w2c (item->canvas, x1, y1, &cx1, &cy1);
+ eel_canvas_w2c (item->canvas, x2, y2, &cx2, &cy2);
+
+ update_rect = make_rect (cx1, cy1, cx2 + 1, cy2 + 1);
+ diff_rects (update_rect, priv->last_update_rect,
+ &repaint_rects_count, repaint_rects);
+ for (i = 0; i < repaint_rects_count; i++)
+ {
+ eel_canvas_request_redraw (item->canvas,
+ repaint_rects[i].x0, repaint_rects[i].y0,
+ repaint_rects[i].x1, repaint_rects[i].y1);
+ }
+
+ priv->last_update_rect = update_rect;
+
+ if (priv->outline_set)
+ {
+ /* Outline and bounding box */
+ width_pixels = (int) priv->width;
+ width_lt = width_pixels / 2;
+ width_rb = (width_pixels + 1) / 2;
+
+ cx1 -= width_lt;
+ cy1 -= width_lt;
+ cx2 += width_rb;
+ cy2 += width_rb;
+
+ update_rect = make_rect (cx1, cy1, cx2, cy2);
+ request_redraw_borders (item->canvas, &update_rect,
+ (width_lt + width_rb));
+ request_redraw_borders (item->canvas, &priv->last_outline_update_rect,
+ priv->last_outline_update_width);
+ priv->last_outline_update_rect = update_rect;
+ priv->last_outline_update_width = width_lt + width_rb;
+
+ item->x1 = cx1;
+ item->y1 = cy1;
+ item->x2 = cx2 + 1;
+ item->y2 = cy2 + 1;
+ }
+ else
+ {
+ item->x1 = cx1;
+ item->y1 = cy1;
+ item->x2 = cx2 + 1;
+ item->y2 = cy2 + 1;
+ }
}
static void
nautilus_selection_canvas_item_translate (EelCanvasItem *item,
- double dx,
- double dy)
+ double dx,
+ double dy)
{
- NautilusSelectionCanvasItem *self;
+ NautilusSelectionCanvasItem *self;
- self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
- self->priv->x1 += dx;
- self->priv->y1 += dy;
- self->priv->x2 += dx;
- self->priv->y2 += dy;
+ self->priv->x1 += dx;
+ self->priv->y1 += dy;
+ self->priv->x2 += dx;
+ self->priv->y2 += dy;
}
static void
nautilus_selection_canvas_item_bounds (EelCanvasItem *item,
- double *x1,
- double *y1,
- double *x2,
- double *y2)
+ double *x1,
+ double *y1,
+ double *x2,
+ double *y2)
{
- NautilusSelectionCanvasItem *self;
- double hwidth;
+ NautilusSelectionCanvasItem *self;
+ double hwidth;
- self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (item);
- hwidth = (self->priv->width / item->canvas->pixels_per_unit) / 2.0;
+ hwidth = (self->priv->width / item->canvas->pixels_per_unit) / 2.0;
- *x1 = self->priv->x1 - hwidth;
- *y1 = self->priv->y1 - hwidth;
- *x2 = self->priv->x2 + hwidth;
- *y2 = self->priv->y2 + hwidth;
+ *x1 = self->priv->x1 - hwidth;
+ *y1 = self->priv->y1 - hwidth;
+ *x2 = self->priv->x2 + hwidth;
+ *y2 = self->priv->y2 + hwidth;
}
static gboolean
-fade_and_request_redraw (GtkWidget *canvas,
- GdkFrameClock *frame_clock,
- gpointer user_data)
+fade_and_request_redraw (GtkWidget *canvas,
+ GdkFrameClock *frame_clock,
+ gpointer user_data)
{
- NautilusSelectionCanvasItem *self = user_data;
- gint64 frame_time;
- gdouble percentage;
+ NautilusSelectionCanvasItem *self = user_data;
+ gint64 frame_time;
+ gdouble percentage;
- frame_time = gdk_frame_clock_get_frame_time (frame_clock);
- if (frame_time >= self->priv->fade_out_end_time) {
- self->priv->fade_out_tick_id = 0;
- eel_canvas_item_destroy (EEL_CANVAS_ITEM (self));
+ frame_time = gdk_frame_clock_get_frame_time (frame_clock);
+ if (frame_time >= self->priv->fade_out_end_time)
+ {
+ self->priv->fade_out_tick_id = 0;
+ eel_canvas_item_destroy (EEL_CANVAS_ITEM (self));
- return G_SOURCE_REMOVE;
- }
+ return G_SOURCE_REMOVE;
+ }
- percentage = 1.0 - (gdouble) (frame_time - self->priv->fade_out_start_time) /
- (gdouble) (self->priv->fade_out_end_time - self->priv->fade_out_start_time);
+ percentage = 1.0 - (gdouble) (frame_time - self->priv->fade_out_start_time) /
+ (gdouble) (self->priv->fade_out_end_time - self->priv->fade_out_start_time);
- self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha * percentage;
- self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha * percentage;
+ self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha * percentage;
+ self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha * percentage;
- eel_canvas_item_request_redraw (EEL_CANVAS_ITEM (self));
+ eel_canvas_item_request_redraw (EEL_CANVAS_ITEM (self));
- return G_SOURCE_CONTINUE;
+ return G_SOURCE_CONTINUE;
}
void
nautilus_selection_canvas_item_fade_out (NautilusSelectionCanvasItem *self,
- guint transition_time)
+ guint transition_time)
{
- EelCanvasItem *item = EEL_CANVAS_ITEM (self);
- GtkWidget *widget;
- GdkFrameClock *clock;
+ EelCanvasItem *item = EEL_CANVAS_ITEM (self);
+ GtkWidget *widget;
+ GdkFrameClock *clock;
- self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha;
- self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha;
+ self->priv->fade_out_fill_alpha = self->priv->fill_color.alpha;
+ self->priv->fade_out_outline_alpha = self->priv->outline_color.alpha;
- widget = GTK_WIDGET (item->canvas);
- clock = gtk_widget_get_frame_clock (widget);
- self->priv->fade_out_start_time = gdk_frame_clock_get_frame_time (clock);
- self->priv->fade_out_end_time = self->priv->fade_out_start_time + 1000 * transition_time;
+ widget = GTK_WIDGET (item->canvas);
+ clock = gtk_widget_get_frame_clock (widget);
+ self->priv->fade_out_start_time = gdk_frame_clock_get_frame_time (clock);
+ self->priv->fade_out_end_time = self->priv->fade_out_start_time + 1000 * transition_time;
- self->priv->fade_out_tick_id =
- gtk_widget_add_tick_callback (GTK_WIDGET (item->canvas), fade_and_request_redraw, self, NULL);
+ self->priv->fade_out_tick_id =
+ gtk_widget_add_tick_callback (GTK_WIDGET (item->canvas), fade_and_request_redraw, self, NULL);
}
static void
nautilus_selection_canvas_item_dispose (GObject *obj)
{
- NautilusSelectionCanvasItem *self = NAUTILUS_SELECTION_CANVAS_ITEM (obj);
+ NautilusSelectionCanvasItem *self = NAUTILUS_SELECTION_CANVAS_ITEM (obj);
- if (self->priv->fade_out_tick_id != 0) {
- gtk_widget_remove_tick_callback (GTK_WIDGET (EEL_CANVAS_ITEM (self)->canvas), self->priv->fade_out_tick_id);
- self->priv->fade_out_tick_id = 0;
- }
+ if (self->priv->fade_out_tick_id != 0)
+ {
+ gtk_widget_remove_tick_callback (GTK_WIDGET (EEL_CANVAS_ITEM (self)->canvas), self->priv->fade_out_tick_id);
+ self->priv->fade_out_tick_id = 0;
+ }
- G_OBJECT_CLASS (nautilus_selection_canvas_item_parent_class)->dispose (obj);
+ G_OBJECT_CLASS (nautilus_selection_canvas_item_parent_class)->dispose (obj);
}
static void
do_set_fill (NautilusSelectionCanvasItem *self,
- gboolean fill_set)
+ gboolean fill_set)
{
- if (self->priv->fill_set != fill_set) {
- self->priv->fill_set = fill_set;
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (self));
- }
+ if (self->priv->fill_set != fill_set)
+ {
+ self->priv->fill_set = fill_set;
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (self));
+ }
}
static void
do_set_outline (NautilusSelectionCanvasItem *self,
- gboolean outline_set)
+ gboolean outline_set)
{
- if (self->priv->outline_set != outline_set) {
- self->priv->outline_set = outline_set;
- eel_canvas_item_request_update (EEL_CANVAS_ITEM (self));
- }
+ if (self->priv->outline_set != outline_set)
+ {
+ self->priv->outline_set = outline_set;
+ eel_canvas_item_request_update (EEL_CANVAS_ITEM (self));
+ }
}
static void
-nautilus_selection_canvas_item_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_selection_canvas_item_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- EelCanvasItem *item;
- NautilusSelectionCanvasItem *self;
+ EelCanvasItem *item;
+ NautilusSelectionCanvasItem *self;
- self = NAUTILUS_SELECTION_CANVAS_ITEM (object);
- item = EEL_CANVAS_ITEM (object);
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (object);
+ item = EEL_CANVAS_ITEM (object);
- switch (param_id) {
- case PROP_X1:
- self->priv->x1 = g_value_get_double (value);
+ switch (param_id)
+ {
+ case PROP_X1:
+ {
+ self->priv->x1 = g_value_get_double (value);
- eel_canvas_item_request_update (item);
- break;
+ eel_canvas_item_request_update (item);
+ }
+ break;
- case PROP_Y1:
- self->priv->y1 = g_value_get_double (value);
+ case PROP_Y1:
+ {
+ self->priv->y1 = g_value_get_double (value);
- eel_canvas_item_request_update (item);
- break;
+ eel_canvas_item_request_update (item);
+ }
+ break;
- case PROP_X2:
- self->priv->x2 = g_value_get_double (value);
+ case PROP_X2:
+ {
+ self->priv->x2 = g_value_get_double (value);
- eel_canvas_item_request_update (item);
- break;
+ eel_canvas_item_request_update (item);
+ }
+ break;
- case PROP_Y2:
- self->priv->y2 = g_value_get_double (value);
+ case PROP_Y2:
+ {
+ self->priv->y2 = g_value_get_double (value);
- eel_canvas_item_request_update (item);
- break;
+ eel_canvas_item_request_update (item);
+ }
+ break;
- case PROP_FILL_COLOR_RGBA: {
- GdkRGBA *color;
+ case PROP_FILL_COLOR_RGBA:
+ {
+ GdkRGBA *color;
- color = g_value_get_boxed (value);
+ color = g_value_get_boxed (value);
- do_set_fill (self, color != NULL);
+ do_set_fill (self, color != NULL);
- if (color != NULL) {
- self->priv->fill_color = *color;
- }
+ if (color != NULL)
+ {
+ self->priv->fill_color = *color;
+ }
- eel_canvas_item_request_redraw (item);
- break;
- }
+ eel_canvas_item_request_redraw (item);
+ break;
+ }
- case PROP_OUTLINE_COLOR_RGBA: {
- GdkRGBA *color;
+ case PROP_OUTLINE_COLOR_RGBA:
+ {
+ GdkRGBA *color;
- color = g_value_get_boxed (value);
+ color = g_value_get_boxed (value);
- do_set_outline (self, color != NULL);
+ do_set_outline (self, color != NULL);
- if (color != NULL) {
- self->priv->outline_color = *color;
- }
+ if (color != NULL)
+ {
+ self->priv->outline_color = *color;
+ }
- eel_canvas_item_request_redraw (item);
- break;
- }
+ eel_canvas_item_request_redraw (item);
+ break;
+ }
- case PROP_OUTLINE_STIPPLING:
- self->priv->outline_stippling = g_value_get_boolean (value);
+ case PROP_OUTLINE_STIPPLING:
+ {
+ self->priv->outline_stippling = g_value_get_boolean (value);
- eel_canvas_item_request_redraw (item);
- break;
+ eel_canvas_item_request_redraw (item);
+ }
+ break;
- case PROP_WIDTH_PIXELS:
- self->priv->width = g_value_get_uint (value);
+ case PROP_WIDTH_PIXELS:
+ {
+ self->priv->width = g_value_get_uint (value);
- eel_canvas_item_request_update (item);
- break;
+ eel_canvas_item_request_update (item);
+ }
+ break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_selection_canvas_item_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_selection_canvas_item_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusSelectionCanvasItem *self;
-
- self = NAUTILUS_SELECTION_CANVAS_ITEM (object);
-
- switch (param_id) {
- case PROP_X1:
- g_value_set_double (value, self->priv->x1);
- break;
-
- case PROP_Y1:
- g_value_set_double (value, self->priv->y1);
- break;
-
- case PROP_X2:
- g_value_set_double (value, self->priv->x2);
- break;
-
- case PROP_Y2:
- g_value_set_double (value, self->priv->y2);
- break;
-
- case PROP_FILL_COLOR_RGBA:
- g_value_set_boxed (value, &self->priv->fill_color);
- break;
-
- case PROP_OUTLINE_COLOR_RGBA:
- g_value_set_boxed (value, &self->priv->outline_color);
- break;
-
- case PROP_OUTLINE_STIPPLING:
- g_value_set_boolean (value, self->priv->outline_stippling);
- break;
- case PROP_WIDTH_PIXELS:
- g_value_set_uint (value, self->priv->width);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
- break;
- }
+ NautilusSelectionCanvasItem *self;
+
+ self = NAUTILUS_SELECTION_CANVAS_ITEM (object);
+
+ switch (param_id)
+ {
+ case PROP_X1:
+ {
+ g_value_set_double (value, self->priv->x1);
+ }
+ break;
+
+ case PROP_Y1:
+ {
+ g_value_set_double (value, self->priv->y1);
+ }
+ break;
+
+ case PROP_X2:
+ {
+ g_value_set_double (value, self->priv->x2);
+ }
+ break;
+
+ case PROP_Y2:
+ {
+ g_value_set_double (value, self->priv->y2);
+ }
+ break;
+
+ case PROP_FILL_COLOR_RGBA:
+ {
+ g_value_set_boxed (value, &self->priv->fill_color);
+ }
+ break;
+
+ case PROP_OUTLINE_COLOR_RGBA:
+ {
+ g_value_set_boxed (value, &self->priv->outline_color);
+ }
+ break;
+
+ case PROP_OUTLINE_STIPPLING:
+ {
+ g_value_set_boolean (value, self->priv->outline_stippling);
+ }
+ break;
+
+ case PROP_WIDTH_PIXELS:
+ {
+ g_value_set_uint (value, self->priv->width);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_selection_canvas_item_class_init (NautilusSelectionCanvasItemClass *klass)
{
- EelCanvasItemClass *item_class;
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (klass);
- item_class = EEL_CANVAS_ITEM_CLASS (klass);
-
- gobject_class->set_property = nautilus_selection_canvas_item_set_property;
- gobject_class->get_property = nautilus_selection_canvas_item_get_property;
- gobject_class->dispose = nautilus_selection_canvas_item_dispose;
-
- item_class->draw = nautilus_selection_canvas_item_draw;
- item_class->point = nautilus_selection_canvas_item_point;
- item_class->update = nautilus_selection_canvas_item_update;
- item_class->bounds = nautilus_selection_canvas_item_bounds;
- item_class->translate = nautilus_selection_canvas_item_translate;
-
- properties[PROP_X1] =
- g_param_spec_double ("x1", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- G_PARAM_READWRITE);
- properties[PROP_Y1] =
- g_param_spec_double ("y1", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- G_PARAM_READWRITE);
- properties[PROP_X2] =
- g_param_spec_double ("x2", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- G_PARAM_READWRITE);
- properties[PROP_Y2] =
- g_param_spec_double ("y2", NULL, NULL,
- -G_MAXDOUBLE, G_MAXDOUBLE, 0,
- G_PARAM_READWRITE);
- properties[PROP_FILL_COLOR_RGBA] =
- g_param_spec_boxed ("fill-color-rgba", NULL, NULL,
- GDK_TYPE_RGBA,
- G_PARAM_READWRITE);
- properties[PROP_OUTLINE_COLOR_RGBA] =
- g_param_spec_boxed ("outline-color-rgba", NULL, NULL,
- GDK_TYPE_RGBA,
- G_PARAM_READWRITE);
- properties[PROP_OUTLINE_STIPPLING] =
- g_param_spec_boolean ("outline-stippling", NULL, NULL,
- FALSE, G_PARAM_READWRITE);
- properties[PROP_WIDTH_PIXELS] =
- g_param_spec_uint ("width-pixels", NULL, NULL,
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE);
-
- g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
- g_type_class_add_private (klass, sizeof (NautilusSelectionCanvasItemDetails));
+ EelCanvasItemClass *item_class;
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ item_class = EEL_CANVAS_ITEM_CLASS (klass);
+
+ gobject_class->set_property = nautilus_selection_canvas_item_set_property;
+ gobject_class->get_property = nautilus_selection_canvas_item_get_property;
+ gobject_class->dispose = nautilus_selection_canvas_item_dispose;
+
+ item_class->draw = nautilus_selection_canvas_item_draw;
+ item_class->point = nautilus_selection_canvas_item_point;
+ item_class->update = nautilus_selection_canvas_item_update;
+ item_class->bounds = nautilus_selection_canvas_item_bounds;
+ item_class->translate = nautilus_selection_canvas_item_translate;
+
+ properties[PROP_X1] =
+ g_param_spec_double ("x1", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
+ G_PARAM_READWRITE);
+ properties[PROP_Y1] =
+ g_param_spec_double ("y1", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
+ G_PARAM_READWRITE);
+ properties[PROP_X2] =
+ g_param_spec_double ("x2", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
+ G_PARAM_READWRITE);
+ properties[PROP_Y2] =
+ g_param_spec_double ("y2", NULL, NULL,
+ -G_MAXDOUBLE, G_MAXDOUBLE, 0,
+ G_PARAM_READWRITE);
+ properties[PROP_FILL_COLOR_RGBA] =
+ g_param_spec_boxed ("fill-color-rgba", NULL, NULL,
+ GDK_TYPE_RGBA,
+ G_PARAM_READWRITE);
+ properties[PROP_OUTLINE_COLOR_RGBA] =
+ g_param_spec_boxed ("outline-color-rgba", NULL, NULL,
+ GDK_TYPE_RGBA,
+ G_PARAM_READWRITE);
+ properties[PROP_OUTLINE_STIPPLING] =
+ g_param_spec_boolean ("outline-stippling", NULL, NULL,
+ FALSE, G_PARAM_READWRITE);
+ properties[PROP_WIDTH_PIXELS] =
+ g_param_spec_uint ("width-pixels", NULL, NULL,
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
+ g_type_class_add_private (klass, sizeof (NautilusSelectionCanvasItemDetails));
}
static void
nautilus_selection_canvas_item_init (NautilusSelectionCanvasItem *self)
{
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
- NautilusSelectionCanvasItemDetails);
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_SELECTION_CANVAS_ITEM,
+ NautilusSelectionCanvasItemDetails);
}
-
-
-
diff --git a/src/nautilus-self-check-functions.c b/src/nautilus-self-check-functions.c
index 1f54a242f..6de4d70b8 100644
--- a/src/nautilus-self-check-functions.c
+++ b/src/nautilus-self-check-functions.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -19,20 +18,20 @@
*
* Author: Darin Adler <darin@bentspoon.com>
*/
-
+
/* nautilus-self-check-functions.c: Wrapper for all self check functions
* in Nautilus proper.
*/
#include <config.h>
-#if ! defined (NAUTILUS_OMIT_SELF_CHECK)
+#if !defined (NAUTILUS_OMIT_SELF_CHECK)
#include "nautilus-self-check-functions.h"
void nautilus_run_self_checks(void)
{
- NAUTILUS_FOR_EACH_SELF_CHECK_FUNCTION (NAUTILUS_CALL_SELF_CHECK_FUNCTION)
+ NAUTILUS_FOR_EACH_SELF_CHECK_FUNCTION (NAUTILUS_CALL_SELF_CHECK_FUNCTION)
}
#endif /* ! NAUTILUS_OMIT_SELF_CHECK */
diff --git a/src/nautilus-shell-search-provider.c b/src/nautilus-shell-search-provider.c
index 41ee0d9ac..a2ab54c03 100644
--- a/src/nautilus-shell-search-provider.c
+++ b/src/nautilus-shell-search-provider.c
@@ -39,79 +39,89 @@
#include "nautilus-shell-search-provider-generated.h"
#include "nautilus-shell-search-provider.h"
-typedef struct {
- NautilusShellSearchProvider *self;
+typedef struct
+{
+ NautilusShellSearchProvider *self;
- NautilusSearchEngine *engine;
- NautilusQuery *query;
+ NautilusSearchEngine *engine;
+ NautilusQuery *query;
- GHashTable *hits;
- GDBusMethodInvocation *invocation;
+ GHashTable *hits;
+ GDBusMethodInvocation *invocation;
- gint64 start_time;
+ gint64 start_time;
} PendingSearch;
-struct _NautilusShellSearchProvider {
- GObject parent;
+struct _NautilusShellSearchProvider
+{
+ GObject parent;
- NautilusShellSearchProvider2 *skeleton;
+ NautilusShellSearchProvider2 *skeleton;
- PendingSearch *current_search;
+ PendingSearch *current_search;
- GHashTable *metas_cache;
+ GHashTable *metas_cache;
};
G_DEFINE_TYPE (NautilusShellSearchProvider, nautilus_shell_search_provider, G_TYPE_OBJECT)
static gchar *
get_display_name (NautilusShellSearchProvider *self,
- NautilusFile *file)
+ NautilusFile *file)
{
- GFile *location;
- NautilusBookmark *bookmark;
- NautilusBookmarkList *bookmarks;
+ GFile *location;
+ NautilusBookmark *bookmark;
+ NautilusBookmarkList *bookmarks;
- bookmarks = nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ()));
+ bookmarks = nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ()));
- location = nautilus_file_get_location (file);
- bookmark = nautilus_bookmark_list_item_with_location (bookmarks, location, NULL);
- g_object_unref (location);
+ location = nautilus_file_get_location (file);
+ bookmark = nautilus_bookmark_list_item_with_location (bookmarks, location, NULL);
+ g_object_unref (location);
- if (bookmark)
- return g_strdup (nautilus_bookmark_get_name (bookmark));
- else
- return nautilus_file_get_display_name (file);
+ if (bookmark)
+ {
+ return g_strdup (nautilus_bookmark_get_name (bookmark));
+ }
+ else
+ {
+ return nautilus_file_get_display_name (file);
+ }
}
static GIcon *
get_gicon (NautilusShellSearchProvider *self,
- NautilusFile *file)
+ NautilusFile *file)
{
- GFile *location;
- NautilusBookmark *bookmark;
- NautilusBookmarkList *bookmarks;
+ GFile *location;
+ NautilusBookmark *bookmark;
+ NautilusBookmarkList *bookmarks;
- bookmarks = nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ()));
+ bookmarks = nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ()));
- location = nautilus_file_get_location (file);
- bookmark = nautilus_bookmark_list_item_with_location (bookmarks, location, NULL);
- g_object_unref (location);
+ location = nautilus_file_get_location (file);
+ bookmark = nautilus_bookmark_list_item_with_location (bookmarks, location, NULL);
+ g_object_unref (location);
- if (bookmark)
- return nautilus_bookmark_get_icon (bookmark);
- else
- return nautilus_file_get_gicon (file, 0);
+ if (bookmark)
+ {
+ return nautilus_bookmark_get_icon (bookmark);
+ }
+ else
+ {
+ return nautilus_file_get_gicon (file, 0);
+ }
}
static void
pending_search_free (PendingSearch *search)
{
- g_hash_table_destroy (search->hits);
- g_clear_object (&search->query);
- g_clear_object (&search->engine);
- g_clear_object (&search->invocation);
+ g_hash_table_destroy (search->hits);
+ g_clear_object (&search->query);
+ g_clear_object (&search->engine);
+ g_clear_object (&search->invocation);
- g_slice_free (PendingSearch, search);
+ g_slice_free (PendingSearch, search);
}
static void
@@ -119,66 +129,74 @@ pending_search_finish (PendingSearch *search,
GDBusMethodInvocation *invocation,
GVariant *result)
{
- NautilusShellSearchProvider *self = search->self;
+ NautilusShellSearchProvider *self = search->self;
- g_dbus_method_invocation_return_value (invocation, result);
+ g_dbus_method_invocation_return_value (invocation, result);
- if (search == self->current_search)
- self->current_search = NULL;
+ if (search == self->current_search)
+ {
+ self->current_search = NULL;
+ }
- g_application_release (g_application_get_default ());
- pending_search_free (search);
+ g_application_release (g_application_get_default ());
+ pending_search_free (search);
}
static void
cancel_current_search (NautilusShellSearchProvider *self)
{
- if (self->current_search != NULL)
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (self->current_search->engine));
+ if (self->current_search != NULL)
+ {
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (self->current_search->engine));
+ }
}
static void
search_hits_added_cb (NautilusSearchEngine *engine,
GList *hits,
gpointer user_data)
-
{
- PendingSearch *search = user_data;
- GList *l;
- NautilusSearchHit *hit;
- const gchar *hit_uri;
+ PendingSearch *search = user_data;
+ GList *l;
+ NautilusSearchHit *hit;
+ const gchar *hit_uri;
- g_debug ("*** Search engine hits added");
+ g_debug ("*** Search engine hits added");
- for (l = hits; l != NULL; l = l->next) {
- hit = l->data;
- nautilus_search_hit_compute_scores (hit, search->query);
- hit_uri = nautilus_search_hit_get_uri (hit);
- g_debug (" %s", hit_uri);
+ for (l = hits; l != NULL; l = l->next)
+ {
+ hit = l->data;
+ nautilus_search_hit_compute_scores (hit, search->query);
+ hit_uri = nautilus_search_hit_get_uri (hit);
+ g_debug (" %s", hit_uri);
- g_hash_table_replace (search->hits, g_strdup (hit_uri), g_object_ref (hit));
- }
+ g_hash_table_replace (search->hits, g_strdup (hit_uri), g_object_ref (hit));
+ }
}
static gint
search_hit_compare_relevance (gconstpointer a,
gconstpointer b)
{
- NautilusSearchHit *hit_a, *hit_b;
- gdouble relevance_a, relevance_b;
+ NautilusSearchHit *hit_a, *hit_b;
+ gdouble relevance_a, relevance_b;
- hit_a = NAUTILUS_SEARCH_HIT (a);
- hit_b = NAUTILUS_SEARCH_HIT (b);
+ hit_a = NAUTILUS_SEARCH_HIT (a);
+ hit_b = NAUTILUS_SEARCH_HIT (b);
- relevance_a = nautilus_search_hit_get_relevance (hit_a);
- relevance_b = nautilus_search_hit_get_relevance (hit_b);
+ relevance_a = nautilus_search_hit_get_relevance (hit_a);
+ relevance_b = nautilus_search_hit_get_relevance (hit_b);
- if (relevance_a > relevance_b)
- return -1;
- else if (relevance_a == relevance_b)
- return 0;
+ if (relevance_a > relevance_b)
+ {
+ return -1;
+ }
+ else if (relevance_a == relevance_b)
+ {
+ return 0;
+ }
- return 1;
+ return 1;
}
static void
@@ -186,29 +204,30 @@ search_finished_cb (NautilusSearchEngine *engine,
NautilusSearchProviderStatus status,
gpointer user_data)
{
- PendingSearch *search = user_data;
- GList *hits, *l;
- NautilusSearchHit *hit;
- GVariantBuilder builder;
- gint64 current_time;
+ PendingSearch *search = user_data;
+ GList *hits, *l;
+ NautilusSearchHit *hit;
+ GVariantBuilder builder;
+ gint64 current_time;
- current_time = g_get_monotonic_time ();
- g_debug ("*** Search engine search finished - time elapsed %dms",
- (gint) ((current_time - search->start_time) / 1000));
+ current_time = g_get_monotonic_time ();
+ g_debug ("*** Search engine search finished - time elapsed %dms",
+ (gint) ((current_time - search->start_time) / 1000));
- hits = g_hash_table_get_values (search->hits);
- hits = g_list_sort (hits, search_hit_compare_relevance);
+ hits = g_hash_table_get_values (search->hits);
+ hits = g_list_sort (hits, search_hit_compare_relevance);
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
- for (l = hits; l != NULL; l = l->next) {
- hit = l->data;
- g_variant_builder_add (&builder, "s", nautilus_search_hit_get_uri (hit));
- }
+ for (l = hits; l != NULL; l = l->next)
+ {
+ hit = l->data;
+ g_variant_builder_add (&builder, "s", nautilus_search_hit_get_uri (hit));
+ }
- g_list_free (hits);
- pending_search_finish (search, search->invocation,
- g_variant_new ("(as)", &builder));
+ g_list_free (hits);
+ pending_search_finish (search, search->invocation,
+ g_variant_new ("(as)", &builder));
}
static void
@@ -216,232 +235,253 @@ search_error_cb (NautilusSearchEngine *engine,
const gchar *error_message,
gpointer user_data)
{
- NautilusShellSearchProvider *self = user_data;
- PendingSearch *search = self->current_search;
+ NautilusShellSearchProvider *self = user_data;
+ PendingSearch *search = self->current_search;
- g_debug ("*** Search engine search error");
- pending_search_finish (search, search->invocation,
- g_variant_new ("(as)", NULL));
+ g_debug ("*** Search engine search error");
+ pending_search_finish (search, search->invocation,
+ g_variant_new ("(as)", NULL));
}
-typedef struct {
- gchar *uri;
- gchar *string_for_compare;
+typedef struct
+{
+ gchar *uri;
+ gchar *string_for_compare;
} SearchHitCandidate;
static void
search_hit_candidate_free (SearchHitCandidate *candidate)
{
- g_free (candidate->uri);
- g_free (candidate->string_for_compare);
+ g_free (candidate->uri);
+ g_free (candidate->string_for_compare);
- g_slice_free (SearchHitCandidate, candidate);
+ g_slice_free (SearchHitCandidate, candidate);
}
static SearchHitCandidate *
search_hit_candidate_new (const gchar *uri,
const gchar *name)
{
- SearchHitCandidate *candidate = g_slice_new0 (SearchHitCandidate);
+ SearchHitCandidate *candidate = g_slice_new0 (SearchHitCandidate);
- candidate->uri = g_strdup (uri);
- candidate->string_for_compare = g_strdup (name);
+ candidate->uri = g_strdup (uri);
+ candidate->string_for_compare = g_strdup (name);
- return candidate;
+ return candidate;
}
static void
search_add_volumes_and_bookmarks (PendingSearch *search)
{
- NautilusSearchHit *hit;
- NautilusBookmark *bookmark;
- const gchar *name;
- gchar *string, *uri;
- gdouble match;
- GList *l, *m, *drives, *volumes, *mounts, *mounts_to_check, *candidates;
- GDrive *drive;
- GVolume *volume;
- GMount *mount;
- GFile *location;
- SearchHitCandidate *candidate;
- NautilusBookmarkList *bookmarks;
- GList *all_bookmarks;
- GVolumeMonitor *volume_monitor;
-
- bookmarks = nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ()));
- all_bookmarks = nautilus_bookmark_list_get_all (bookmarks);
- volume_monitor = g_volume_monitor_get ();
- candidates = NULL;
-
- /* first add bookmarks */
- for (l = all_bookmarks; l != NULL; l = l->next) {
- bookmark = NAUTILUS_BOOKMARK (l->data);
- name = nautilus_bookmark_get_name (bookmark);
- if (name == NULL)
- continue;
-
- uri = nautilus_bookmark_get_uri (bookmark);
- candidate = search_hit_candidate_new (uri, name);
- candidates = g_list_prepend (candidates, candidate);
+ NautilusSearchHit *hit;
+ NautilusBookmark *bookmark;
+ const gchar *name;
+ gchar *string, *uri;
+ gdouble match;
+ GList *l, *m, *drives, *volumes, *mounts, *mounts_to_check, *candidates;
+ GDrive *drive;
+ GVolume *volume;
+ GMount *mount;
+ GFile *location;
+ SearchHitCandidate *candidate;
+ NautilusBookmarkList *bookmarks;
+ GList *all_bookmarks;
+ GVolumeMonitor *volume_monitor;
+
+ bookmarks = nautilus_application_get_bookmarks (NAUTILUS_APPLICATION (g_application_get_default ()));
+ all_bookmarks = nautilus_bookmark_list_get_all (bookmarks);
+ volume_monitor = g_volume_monitor_get ();
+ candidates = NULL;
+
+ /* first add bookmarks */
+ for (l = all_bookmarks; l != NULL; l = l->next)
+ {
+ bookmark = NAUTILUS_BOOKMARK (l->data);
+ name = nautilus_bookmark_get_name (bookmark);
+ if (name == NULL)
+ {
+ continue;
+ }
+
+ uri = nautilus_bookmark_get_uri (bookmark);
+ candidate = search_hit_candidate_new (uri, name);
+ candidates = g_list_prepend (candidates, candidate);
+
+ g_free (uri);
+ }
+ /* home dir */
+ uri = nautilus_get_home_directory_uri ();
+ candidate = search_hit_candidate_new (uri, _("Home"));
+ candidates = g_list_prepend (candidates, candidate);
g_free (uri);
- }
-
- /* home dir */
- uri = nautilus_get_home_directory_uri ();
- candidate = search_hit_candidate_new (uri, _("Home"));
- candidates = g_list_prepend (candidates, candidate);
- g_free (uri);
-
- /* trash */
- candidate = search_hit_candidate_new ("trash:///", _("Trash"));
- candidates = g_list_prepend (candidates, candidate);
-
- /* now add mounts */
- mounts_to_check = NULL;
-
- /* first check all connected drives */
- drives = g_volume_monitor_get_connected_drives (volume_monitor);
- for (l = drives; l != NULL; l = l->next) {
- drive = l->data;
- volumes = g_drive_get_volumes (drive);
-
- for (m = volumes; m != NULL; m = m->next) {
- volume = m->data;
- mount = g_volume_get_mount (volume);
- if (mount != NULL) {
- mounts_to_check = g_list_prepend (mounts_to_check, mount);
- }
- }
- g_list_free_full (volumes, g_object_unref);
- }
- g_list_free_full (drives, g_object_unref);
-
- /* then volumes that don't have a drive */
- volumes = g_volume_monitor_get_volumes (volume_monitor);
- for (l = volumes; l != NULL; l = l->next) {
- volume = l->data;
- drive = g_volume_get_drive (volume);
-
- if (drive == NULL) {
- mount = g_volume_get_mount (volume);
- if (mount != NULL) {
- mounts_to_check = g_list_prepend (mounts_to_check, mount);
- }
- }
- g_clear_object (&drive);
- }
- g_list_free_full (volumes, g_object_unref);
-
- /* then mounts that have no volume */
- mounts = g_volume_monitor_get_mounts (volume_monitor);
- for (l = mounts; l != NULL; l = l->next) {
- mount = l->data;
-
- if (g_mount_is_shadowed (mount))
- continue;
-
- volume = g_mount_get_volume (mount);
- if (volume == NULL)
- mounts_to_check = g_list_prepend (mounts_to_check, g_object_ref (mount));
- g_clear_object (&volume);
- }
- g_list_free_full (mounts, g_object_unref);
-
- /* actually add mounts to candidates */
- for (l = mounts_to_check; l != NULL; l = l->next) {
- mount = l->data;
-
- string = g_mount_get_name (mount);
- if (string == NULL)
- continue;
-
- location = g_mount_get_default_location (mount);
- uri = g_file_get_uri (location);
- candidate = search_hit_candidate_new (uri, string);
+ /* trash */
+ candidate = search_hit_candidate_new ("trash:///", _("Trash"));
candidates = g_list_prepend (candidates, candidate);
- g_free (uri);
- g_free (string);
- g_object_unref (location);
- }
- g_list_free_full (mounts_to_check, g_object_unref);
-
- /* now do the actual string matching */
- candidates = g_list_reverse (candidates);
-
- for (l = candidates; l != NULL; l = l->next) {
- candidate = l->data;
- match = nautilus_query_matches_string (search->query,
- candidate->string_for_compare);
-
- if (match > -1) {
- hit = nautilus_search_hit_new (candidate->uri);
- nautilus_search_hit_set_fts_rank (hit, match);
- nautilus_search_hit_compute_scores (hit, search->query);
- g_hash_table_replace (search->hits, g_strdup (candidate->uri), hit);
+ /* now add mounts */
+ mounts_to_check = NULL;
+
+ /* first check all connected drives */
+ drives = g_volume_monitor_get_connected_drives (volume_monitor);
+ for (l = drives; l != NULL; l = l->next)
+ {
+ drive = l->data;
+ volumes = g_drive_get_volumes (drive);
+
+ for (m = volumes; m != NULL; m = m->next)
+ {
+ volume = m->data;
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL)
+ {
+ mounts_to_check = g_list_prepend (mounts_to_check, mount);
+ }
+ }
+
+ g_list_free_full (volumes, g_object_unref);
+ }
+ g_list_free_full (drives, g_object_unref);
+
+ /* then volumes that don't have a drive */
+ volumes = g_volume_monitor_get_volumes (volume_monitor);
+ for (l = volumes; l != NULL; l = l->next)
+ {
+ volume = l->data;
+ drive = g_volume_get_drive (volume);
+
+ if (drive == NULL)
+ {
+ mount = g_volume_get_mount (volume);
+ if (mount != NULL)
+ {
+ mounts_to_check = g_list_prepend (mounts_to_check, mount);
+ }
+ }
+ g_clear_object (&drive);
+ }
+ g_list_free_full (volumes, g_object_unref);
+
+ /* then mounts that have no volume */
+ mounts = g_volume_monitor_get_mounts (volume_monitor);
+ for (l = mounts; l != NULL; l = l->next)
+ {
+ mount = l->data;
+
+ if (g_mount_is_shadowed (mount))
+ {
+ continue;
+ }
+
+ volume = g_mount_get_volume (mount);
+ if (volume == NULL)
+ {
+ mounts_to_check = g_list_prepend (mounts_to_check, g_object_ref (mount));
+ }
+ g_clear_object (&volume);
}
- }
- g_list_free_full (candidates, (GDestroyNotify) search_hit_candidate_free);
- g_object_unref (volume_monitor);
+ g_list_free_full (mounts, g_object_unref);
+
+ /* actually add mounts to candidates */
+ for (l = mounts_to_check; l != NULL; l = l->next)
+ {
+ mount = l->data;
+
+ string = g_mount_get_name (mount);
+ if (string == NULL)
+ {
+ continue;
+ }
+
+ location = g_mount_get_default_location (mount);
+ uri = g_file_get_uri (location);
+ candidate = search_hit_candidate_new (uri, string);
+ candidates = g_list_prepend (candidates, candidate);
+
+ g_free (uri);
+ g_free (string);
+ g_object_unref (location);
+ }
+ g_list_free_full (mounts_to_check, g_object_unref);
+
+ /* now do the actual string matching */
+ candidates = g_list_reverse (candidates);
+
+ for (l = candidates; l != NULL; l = l->next)
+ {
+ candidate = l->data;
+ match = nautilus_query_matches_string (search->query,
+ candidate->string_for_compare);
+
+ if (match > -1)
+ {
+ hit = nautilus_search_hit_new (candidate->uri);
+ nautilus_search_hit_set_fts_rank (hit, match);
+ nautilus_search_hit_compute_scores (hit, search->query);
+ g_hash_table_replace (search->hits, g_strdup (candidate->uri), hit);
+ }
+ }
+ g_list_free_full (candidates, (GDestroyNotify) search_hit_candidate_free);
+ g_object_unref (volume_monitor);
}
static void
-execute_search (NautilusShellSearchProvider *self,
- GDBusMethodInvocation *invocation,
- gchar **terms)
+execute_search (NautilusShellSearchProvider *self,
+ GDBusMethodInvocation *invocation,
+ gchar **terms)
{
- gchar *terms_joined;
- NautilusQuery *query;
- PendingSearch *pending_search;
- GFile *home;
-
- cancel_current_search (self);
-
- /* don't attempt searches for a single character */
- if (g_strv_length (terms) == 1 &&
- g_utf8_strlen (terms[0], -1) == 1) {
- g_dbus_method_invocation_return_value (invocation, g_variant_new ("(as)", NULL));
- return;
- }
-
- terms_joined = g_strjoinv (" ", terms);
- home = g_file_new_for_path (g_get_home_dir ());
-
- query = nautilus_query_new ();
- nautilus_query_set_show_hidden_files (query, FALSE);
- nautilus_query_set_text (query, terms_joined);
- nautilus_query_set_location (query, home);
-
- pending_search = g_slice_new0 (PendingSearch);
- pending_search->invocation = g_object_ref (invocation);
- pending_search->hits = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- pending_search->query = query;
- pending_search->engine = nautilus_search_engine_new ();
- pending_search->start_time = g_get_monotonic_time ();
- pending_search->self = self;
-
- g_signal_connect (pending_search->engine, "hits-added",
- G_CALLBACK (search_hits_added_cb), pending_search);
- g_signal_connect (pending_search->engine, "finished",
- G_CALLBACK (search_finished_cb), pending_search);
- g_signal_connect (pending_search->engine, "error",
- G_CALLBACK (search_error_cb), pending_search);
-
- self->current_search = pending_search;
- g_application_hold (g_application_get_default ());
-
- search_add_volumes_and_bookmarks (pending_search);
-
- /* start searching */
- g_debug ("*** Search engine search started");
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (pending_search->engine),
- query);
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (pending_search->engine));
-
- g_clear_object (&home);
- g_free (terms_joined);
+ gchar *terms_joined;
+ NautilusQuery *query;
+ PendingSearch *pending_search;
+ GFile *home;
+
+ cancel_current_search (self);
+
+ /* don't attempt searches for a single character */
+ if (g_strv_length (terms) == 1 &&
+ g_utf8_strlen (terms[0], -1) == 1)
+ {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(as)", NULL));
+ return;
+ }
+
+ terms_joined = g_strjoinv (" ", terms);
+ home = g_file_new_for_path (g_get_home_dir ());
+
+ query = nautilus_query_new ();
+ nautilus_query_set_show_hidden_files (query, FALSE);
+ nautilus_query_set_text (query, terms_joined);
+ nautilus_query_set_location (query, home);
+
+ pending_search = g_slice_new0 (PendingSearch);
+ pending_search->invocation = g_object_ref (invocation);
+ pending_search->hits = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ pending_search->query = query;
+ pending_search->engine = nautilus_search_engine_new ();
+ pending_search->start_time = g_get_monotonic_time ();
+ pending_search->self = self;
+
+ g_signal_connect (pending_search->engine, "hits-added",
+ G_CALLBACK (search_hits_added_cb), pending_search);
+ g_signal_connect (pending_search->engine, "finished",
+ G_CALLBACK (search_finished_cb), pending_search);
+ g_signal_connect (pending_search->engine, "error",
+ G_CALLBACK (search_error_cb), pending_search);
+
+ self->current_search = pending_search;
+ g_application_hold (g_application_get_default ());
+
+ search_add_volumes_and_bookmarks (pending_search);
+
+ /* start searching */
+ g_debug ("*** Search engine search started");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (pending_search->engine),
+ query);
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (pending_search->engine));
+
+ g_clear_object (&home);
+ g_free (terms_joined);
}
static gboolean
@@ -450,11 +490,11 @@ handle_get_initial_result_set (NautilusShellSearchProvider2 *skeleton,
gchar **terms,
gpointer user_data)
{
- NautilusShellSearchProvider *self = user_data;
+ NautilusShellSearchProvider *self = user_data;
- g_debug ("****** GetInitialResultSet");
- execute_search (self, invocation, terms);
- return TRUE;
+ g_debug ("****** GetInitialResultSet");
+ execute_search (self, invocation, terms);
+ return TRUE;
}
static gboolean
@@ -464,126 +504,133 @@ handle_get_subsearch_result_set (NautilusShellSearchProvider2 *skeleton,
gchar **terms,
gpointer user_data)
{
- NautilusShellSearchProvider *self = user_data;
+ NautilusShellSearchProvider *self = user_data;
- g_debug ("****** GetSubSearchResultSet");
- execute_search (self, invocation, terms);
- return TRUE;
+ g_debug ("****** GetSubSearchResultSet");
+ execute_search (self, invocation, terms);
+ return TRUE;
}
-typedef struct {
- NautilusShellSearchProvider *self;
+typedef struct
+{
+ NautilusShellSearchProvider *self;
- gint64 start_time;
- GDBusMethodInvocation *invocation;
+ gint64 start_time;
+ GDBusMethodInvocation *invocation;
- gchar **uris;
+ gchar **uris;
} ResultMetasData;
static void
result_metas_data_free (ResultMetasData *data)
{
- g_clear_object (&data->self);
- g_clear_object (&data->invocation);
- g_strfreev (data->uris);
+ g_clear_object (&data->self);
+ g_clear_object (&data->invocation);
+ g_strfreev (data->uris);
- g_slice_free (ResultMetasData, data);
+ g_slice_free (ResultMetasData, data);
}
static void
result_metas_return_from_cache (ResultMetasData *data)
{
- GVariantBuilder builder;
- GVariant *meta;
- gint64 current_time;
- gint idx;
-
- g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
-
- for (idx = 0; data->uris[idx] != NULL; idx++) {
- meta = g_hash_table_lookup (data->self->metas_cache,
- data->uris[idx]);
- g_variant_builder_add_value (&builder, meta);
- }
+ GVariantBuilder builder;
+ GVariant *meta;
+ gint64 current_time;
+ gint idx;
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
+
+ for (idx = 0; data->uris[idx] != NULL; idx++)
+ {
+ meta = g_hash_table_lookup (data->self->metas_cache,
+ data->uris[idx]);
+ g_variant_builder_add_value (&builder, meta);
+ }
- current_time = g_get_monotonic_time ();
- g_debug ("*** GetResultMetas completed - time elapsed %dms",
- (gint) ((current_time - data->start_time) / 1000));
+ current_time = g_get_monotonic_time ();
+ g_debug ("*** GetResultMetas completed - time elapsed %dms",
+ (gint) ((current_time - data->start_time) / 1000));
- g_dbus_method_invocation_return_value (data->invocation,
- g_variant_new ("(aa{sv})", &builder));
+ g_dbus_method_invocation_return_value (data->invocation,
+ g_variant_new ("(aa{sv})", &builder));
}
static void
result_list_attributes_ready_cb (GList *file_list,
gpointer user_data)
{
- ResultMetasData *data = user_data;
- GVariantBuilder meta;
- NautilusFile *file;
- GFile *file_location;
- GList *l;
- gchar *uri, *display_name;
- gchar *description;
- gchar *thumbnail_path;
- GIcon *gicon;
- GFile *location;
- GVariant *meta_variant;
- gint icon_scale;
-
- icon_scale = gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), 0);
-
- for (l = file_list; l != NULL; l = l->next) {
- file = l->data;
- g_variant_builder_init (&meta, G_VARIANT_TYPE ("a{sv}"));
-
- uri = nautilus_file_get_uri (file);
- display_name = get_display_name (data->self, file);
- file_location = nautilus_file_get_location (file);
- description = g_file_get_path (file_location);
-
- g_variant_builder_add (&meta, "{sv}",
- "id", g_variant_new_string (uri));
- g_variant_builder_add (&meta, "{sv}",
- "name", g_variant_new_string (display_name));
- /* Some backends like trash:/// don't have a path, so we show the uri itself. */
- g_variant_builder_add (&meta, "{sv}",
- "description", g_variant_new_string (description? description : uri));
-
- gicon = NULL;
- thumbnail_path = nautilus_file_get_thumbnail_path (file);
-
- if (thumbnail_path != NULL) {
- location = g_file_new_for_path (thumbnail_path);
- gicon = g_file_icon_new (location);
-
- g_free (thumbnail_path);
- g_object_unref (location);
- } else {
- gicon = get_gicon (data->self, file);
- }
-
- if (gicon == NULL) {
- gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, 128, TRUE,
- icon_scale,
- NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS));
+ ResultMetasData *data = user_data;
+ GVariantBuilder meta;
+ NautilusFile *file;
+ GFile *file_location;
+ GList *l;
+ gchar *uri, *display_name;
+ gchar *description;
+ gchar *thumbnail_path;
+ GIcon *gicon;
+ GFile *location;
+ GVariant *meta_variant;
+ gint icon_scale;
+
+ icon_scale = gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), 0);
+
+ for (l = file_list; l != NULL; l = l->next)
+ {
+ file = l->data;
+ g_variant_builder_init (&meta, G_VARIANT_TYPE ("a{sv}"));
+
+ uri = nautilus_file_get_uri (file);
+ display_name = get_display_name (data->self, file);
+ file_location = nautilus_file_get_location (file);
+ description = g_file_get_path (file_location);
+
+ g_variant_builder_add (&meta, "{sv}",
+ "id", g_variant_new_string (uri));
+ g_variant_builder_add (&meta, "{sv}",
+ "name", g_variant_new_string (display_name));
+ /* Some backends like trash:/// don't have a path, so we show the uri itself. */
+ g_variant_builder_add (&meta, "{sv}",
+ "description", g_variant_new_string (description ? description : uri));
+
+ gicon = NULL;
+ thumbnail_path = nautilus_file_get_thumbnail_path (file);
+
+ if (thumbnail_path != NULL)
+ {
+ location = g_file_new_for_path (thumbnail_path);
+ gicon = g_file_icon_new (location);
+
+ g_free (thumbnail_path);
+ g_object_unref (location);
+ }
+ else
+ {
+ gicon = get_gicon (data->self, file);
+ }
+
+ if (gicon == NULL)
+ {
+ gicon = G_ICON (nautilus_file_get_icon_pixbuf (file, 128, TRUE,
+ icon_scale,
+ NAUTILUS_FILE_ICON_FLAGS_USE_THUMBNAILS));
+ }
+
+ g_variant_builder_add (&meta, "{sv}",
+ "icon", g_icon_serialize (gicon));
+ g_object_unref (gicon);
+
+ meta_variant = g_variant_builder_end (&meta);
+ g_hash_table_insert (data->self->metas_cache,
+ g_strdup (uri), g_variant_ref_sink (meta_variant));
+
+ g_free (display_name);
+ g_free (description);
+ g_free (uri);
}
- g_variant_builder_add (&meta, "{sv}",
- "icon", g_icon_serialize (gicon));
- g_object_unref (gicon);
-
- meta_variant = g_variant_builder_end (&meta);
- g_hash_table_insert (data->self->metas_cache,
- g_strdup (uri), g_variant_ref_sink (meta_variant));
-
- g_free (display_name);
- g_free (description);
- g_free (uri);
- }
-
- result_metas_return_from_cache (data);
- result_metas_data_free (data);
+ result_metas_return_from_cache (data);
+ result_metas_data_free (data);
}
static gboolean
@@ -592,145 +639,149 @@ handle_get_result_metas (NautilusShellSearchProvider2 *skeleton,
gchar **results,
gpointer user_data)
{
- NautilusShellSearchProvider *self = user_data;
- GList *missing_files = NULL;
- const gchar *uri;
- ResultMetasData *data;
- gint idx;
-
- g_debug ("****** GetResultMetas");
-
- for (idx = 0; results[idx] != NULL; idx++) {
- uri = results[idx];
-
- if (!g_hash_table_lookup (self->metas_cache, uri)) {
- missing_files = g_list_prepend (missing_files, nautilus_file_get_by_uri (uri));
+ NautilusShellSearchProvider *self = user_data;
+ GList *missing_files = NULL;
+ const gchar *uri;
+ ResultMetasData *data;
+ gint idx;
+
+ g_debug ("****** GetResultMetas");
+
+ for (idx = 0; results[idx] != NULL; idx++)
+ {
+ uri = results[idx];
+
+ if (!g_hash_table_lookup (self->metas_cache, uri))
+ {
+ missing_files = g_list_prepend (missing_files, nautilus_file_get_by_uri (uri));
+ }
}
- }
- data = g_slice_new0 (ResultMetasData);
- data->self = g_object_ref (self);
- data->invocation = g_object_ref (invocation);
- data->start_time = g_get_monotonic_time ();
- data->uris = g_strdupv (results);
+ data = g_slice_new0 (ResultMetasData);
+ data->self = g_object_ref (self);
+ data->invocation = g_object_ref (invocation);
+ data->start_time = g_get_monotonic_time ();
+ data->uris = g_strdupv (results);
+
+ if (missing_files == NULL)
+ {
+ result_metas_return_from_cache (data);
+ result_metas_data_free (data);
+ return TRUE;
+ }
- if (missing_files == NULL) {
- result_metas_return_from_cache (data);
- result_metas_data_free (data);
+ nautilus_file_list_call_when_ready (missing_files,
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON,
+ NULL,
+ result_list_attributes_ready_cb,
+ data);
+ nautilus_file_list_free (missing_files);
return TRUE;
- }
-
- nautilus_file_list_call_when_ready (missing_files,
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON,
- NULL,
- result_list_attributes_ready_cb,
- data);
- nautilus_file_list_free (missing_files);
- return TRUE;
}
static gboolean
-handle_activate_result (NautilusShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar *result,
- gchar **terms,
- guint32 timestamp,
- gpointer user_data)
+handle_activate_result (NautilusShellSearchProvider2 *skeleton,
+ GDBusMethodInvocation *invocation,
+ gchar *result,
+ gchar **terms,
+ guint32 timestamp,
+ gpointer user_data)
{
- gboolean res;
- GFile *file;
+ gboolean res;
+ GFile *file;
- res = gtk_show_uri (NULL, result, timestamp, NULL);
+ res = gtk_show_uri (NULL, result, timestamp, NULL);
- if (!res) {
- file = g_file_new_for_uri (result);
- g_application_open (g_application_get_default (), &file, 1, "");
- g_object_unref (file);
- }
+ if (!res)
+ {
+ file = g_file_new_for_uri (result);
+ g_application_open (g_application_get_default (), &file, 1, "");
+ g_object_unref (file);
+ }
- nautilus_shell_search_provider2_complete_activate_result (skeleton, invocation);
- return TRUE;
+ nautilus_shell_search_provider2_complete_activate_result (skeleton, invocation);
+ return TRUE;
}
static gboolean
-handle_launch_search (NautilusShellSearchProvider2 *skeleton,
- GDBusMethodInvocation *invocation,
- gchar **terms,
- guint32 timestamp,
- gpointer user_data)
+handle_launch_search (NautilusShellSearchProvider2 *skeleton,
+ GDBusMethodInvocation *invocation,
+ gchar **terms,
+ guint32 timestamp,
+ gpointer user_data)
{
- GApplication *app = g_application_get_default ();
- gchar *string = g_strjoinv (" ", terms);
- gchar *uri = nautilus_get_home_directory_uri ();
+ GApplication *app = g_application_get_default ();
+ gchar *string = g_strjoinv (" ", terms);
+ gchar *uri = nautilus_get_home_directory_uri ();
- nautilus_application_search (NAUTILUS_APPLICATION (app), uri, string);
+ nautilus_application_search (NAUTILUS_APPLICATION (app), uri, string);
- g_free (string);
- g_free (uri);
+ g_free (string);
+ g_free (uri);
- nautilus_shell_search_provider2_complete_launch_search (skeleton, invocation);
- return TRUE;
+ nautilus_shell_search_provider2_complete_launch_search (skeleton, invocation);
+ return TRUE;
}
static void
search_provider_dispose (GObject *obj)
{
- NautilusShellSearchProvider *self = NAUTILUS_SHELL_SEARCH_PROVIDER (obj);
+ NautilusShellSearchProvider *self = NAUTILUS_SHELL_SEARCH_PROVIDER (obj);
- g_clear_object (&self->skeleton);
- g_hash_table_destroy (self->metas_cache);
- cancel_current_search (self);
+ g_clear_object (&self->skeleton);
+ g_hash_table_destroy (self->metas_cache);
+ cancel_current_search (self);
- G_OBJECT_CLASS (nautilus_shell_search_provider_parent_class)->dispose (obj);
+ G_OBJECT_CLASS (nautilus_shell_search_provider_parent_class)->dispose (obj);
}
static void
nautilus_shell_search_provider_init (NautilusShellSearchProvider *self)
{
- self->metas_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) g_variant_unref);
-
- self->skeleton = nautilus_shell_search_provider2_skeleton_new ();
-
- g_signal_connect (self->skeleton, "handle-get-initial-result-set",
- G_CALLBACK (handle_get_initial_result_set), self);
- g_signal_connect (self->skeleton, "handle-get-subsearch-result-set",
- G_CALLBACK (handle_get_subsearch_result_set), self);
- g_signal_connect (self->skeleton, "handle-get-result-metas",
- G_CALLBACK (handle_get_result_metas), self);
- g_signal_connect (self->skeleton, "handle-activate-result",
- G_CALLBACK (handle_activate_result), self);
- g_signal_connect (self->skeleton, "handle-launch-search",
- G_CALLBACK (handle_launch_search), self);
+ self->metas_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify) g_variant_unref);
+
+ self->skeleton = nautilus_shell_search_provider2_skeleton_new ();
+
+ g_signal_connect (self->skeleton, "handle-get-initial-result-set",
+ G_CALLBACK (handle_get_initial_result_set), self);
+ g_signal_connect (self->skeleton, "handle-get-subsearch-result-set",
+ G_CALLBACK (handle_get_subsearch_result_set), self);
+ g_signal_connect (self->skeleton, "handle-get-result-metas",
+ G_CALLBACK (handle_get_result_metas), self);
+ g_signal_connect (self->skeleton, "handle-activate-result",
+ G_CALLBACK (handle_activate_result), self);
+ g_signal_connect (self->skeleton, "handle-launch-search",
+ G_CALLBACK (handle_launch_search), self);
}
static void
nautilus_shell_search_provider_class_init (NautilusShellSearchProviderClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
- oclass->dispose = search_provider_dispose;
+ oclass->dispose = search_provider_dispose;
}
NautilusShellSearchProvider *
nautilus_shell_search_provider_new (void)
{
- return g_object_new (nautilus_shell_search_provider_get_type (),
- NULL);
+ return g_object_new (nautilus_shell_search_provider_get_type (),
+ NULL);
}
gboolean
-nautilus_shell_search_provider_register (NautilusShellSearchProvider *self,
- GDBusConnection *connection,
- GError **error)
+nautilus_shell_search_provider_register (NautilusShellSearchProvider *self,
+ GDBusConnection *connection,
+ GError **error)
{
- return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->skeleton),
- connection,
- "/org/gnome/Nautilus/SearchProvider", error);
+ return g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->skeleton),
+ connection,
+ "/org/gnome/Nautilus/SearchProvider", error);
}
void
nautilus_shell_search_provider_unregister (NautilusShellSearchProvider *self)
{
- g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->skeleton));
+ g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->skeleton));
}
diff --git a/src/nautilus-signaller.c b/src/nautilus-signaller.c
index b35877266..4020cb205 100644
--- a/src/nautilus-signaller.c
+++ b/src/nautilus-signaller.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -32,11 +31,12 @@
typedef GObject NautilusSignaller;
typedef GObjectClass NautilusSignallerClass;
-enum {
- HISTORY_LIST_CHANGED,
- POPUP_MENU_CHANGED,
- MIME_DATA_CHANGED,
- LAST_SIGNAL
+enum
+{
+ HISTORY_LIST_CHANGED,
+ POPUP_MENU_CHANGED,
+ MIME_DATA_CHANGED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
@@ -48,13 +48,14 @@ G_DEFINE_TYPE (NautilusSignaller, nautilus_signaller, G_TYPE_OBJECT);
GObject *
nautilus_signaller_get_current (void)
{
- static GObject *global_signaller = NULL;
+ static GObject *global_signaller = NULL;
- if (global_signaller == NULL) {
- global_signaller = g_object_new (nautilus_signaller_get_type (), NULL);
- }
+ if (global_signaller == NULL)
+ {
+ global_signaller = g_object_new (nautilus_signaller_get_type (), NULL);
+ }
- return global_signaller;
+ return global_signaller;
}
static void
@@ -65,28 +66,28 @@ nautilus_signaller_init (NautilusSignaller *signaller)
static void
nautilus_signaller_class_init (NautilusSignallerClass *class)
{
- signals[HISTORY_LIST_CHANGED] =
- g_signal_new ("history-list-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[POPUP_MENU_CHANGED] =
- g_signal_new ("popup-menu-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
- signals[MIME_DATA_CHANGED] =
- g_signal_new ("mime-data-changed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ signals[HISTORY_LIST_CHANGED] =
+ g_signal_new ("history-list-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[POPUP_MENU_CHANGED] =
+ g_signal_new ("popup-menu-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+ signals[MIME_DATA_CHANGED] =
+ g_signal_new ("mime-data-changed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
diff --git a/src/nautilus-special-location-bar.c b/src/nautilus-special-location-bar.c
index 001712bb7..85673107a 100644
--- a/src/nautilus-special-location-bar.c
+++ b/src/nautilus-special-location-bar.c
@@ -29,146 +29,169 @@
struct NautilusSpecialLocationBarPrivate
{
- GtkWidget *label;
- GtkWidget *learn_more_label;
- NautilusSpecialLocation special_location;
+ GtkWidget *label;
+ GtkWidget *learn_more_label;
+ NautilusSpecialLocation special_location;
};
-enum {
- PROP_0,
- PROP_SPECIAL_LOCATION,
+enum
+{
+ PROP_0,
+ PROP_SPECIAL_LOCATION,
};
G_DEFINE_TYPE (NautilusSpecialLocationBar, nautilus_special_location_bar, GTK_TYPE_INFO_BAR)
static void
set_special_location (NautilusSpecialLocationBar *bar,
- NautilusSpecialLocation location)
+ NautilusSpecialLocation location)
{
- char *message;
- char *learn_more_markup = NULL;
-
- switch (location) {
- case NAUTILUS_SPECIAL_LOCATION_TEMPLATES:
- message = g_strdup (_("Put files in this folder to use them as templates for new documents."));
- learn_more_markup = g_strdup (_("<a href=\"help:gnome-help/files-templates\" title=\"GNOME help for templates\">Learn more…</a>"));
- break;
- case NAUTILUS_SPECIAL_LOCATION_SCRIPTS:
- message = g_strdup (_("Executable files in this folder will appear in the Scripts menu."));
- break;
- default:
- g_assert_not_reached ();
- }
-
- gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
- g_free (message);
-
- gtk_widget_show (bar->priv->label);
-
- if (learn_more_markup) {
- gtk_label_set_markup (GTK_LABEL (bar->priv->learn_more_label),
- learn_more_markup);
- gtk_widget_show (bar->priv->learn_more_label);
- g_free (learn_more_markup);
- } else {
- gtk_widget_hide (bar->priv->learn_more_label);
+ char *message;
+ char *learn_more_markup = NULL;
+
+ switch (location)
+ {
+ case NAUTILUS_SPECIAL_LOCATION_TEMPLATES:
+ {
+ message = g_strdup (_("Put files in this folder to use them as templates for new documents."));
+ learn_more_markup = g_strdup (_("<a href=\"help:gnome-help/files-templates\" title=\"GNOME help for templates\">Learn more…</a>"));
+ }
+ break;
+
+ case NAUTILUS_SPECIAL_LOCATION_SCRIPTS:
+ {
+ message = g_strdup (_("Executable files in this folder will appear in the Scripts menu."));
}
+ break;
+
+ default:
+ g_assert_not_reached ();
+ }
+
+ gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
+ g_free (message);
+
+ gtk_widget_show (bar->priv->label);
+
+ if (learn_more_markup)
+ {
+ gtk_label_set_markup (GTK_LABEL (bar->priv->learn_more_label),
+ learn_more_markup);
+ gtk_widget_show (bar->priv->learn_more_label);
+ g_free (learn_more_markup);
+ }
+ else
+ {
+ gtk_widget_hide (bar->priv->learn_more_label);
+ }
}
static void
nautilus_special_location_bar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusSpecialLocationBar *bar;
-
- bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
-
- switch (prop_id) {
- case PROP_SPECIAL_LOCATION:
- set_special_location (bar, g_value_get_enum (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ NautilusSpecialLocationBar *bar;
+
+ bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_SPECIAL_LOCATION:
+ {
+ set_special_location (bar, g_value_get_enum (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_special_location_bar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusSpecialLocationBar *bar;
-
- bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
-
- switch (prop_id) {
- case PROP_SPECIAL_LOCATION:
- g_value_set_enum (value, bar->priv->special_location);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ NautilusSpecialLocationBar *bar;
+
+ bar = NAUTILUS_SPECIAL_LOCATION_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_SPECIAL_LOCATION:
+ {
+ g_value_set_enum (value, bar->priv->special_location);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_special_location_bar_class_init (NautilusSpecialLocationBarClass *klass)
{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = nautilus_special_location_bar_get_property;
- object_class->set_property = nautilus_special_location_bar_set_property;
-
- g_type_class_add_private (klass, sizeof (NautilusSpecialLocationBarPrivate));
-
- g_object_class_install_property (object_class,
- PROP_SPECIAL_LOCATION,
- g_param_spec_enum ("special-location",
- "special-location",
- "special-location",
- NAUTILUS_TYPE_SPECIAL_LOCATION,
- NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->get_property = nautilus_special_location_bar_get_property;
+ object_class->set_property = nautilus_special_location_bar_set_property;
+
+ g_type_class_add_private (klass, sizeof (NautilusSpecialLocationBarPrivate));
+
+ g_object_class_install_property (object_class,
+ PROP_SPECIAL_LOCATION,
+ g_param_spec_enum ("special-location",
+ "special-location",
+ "special-location",
+ NAUTILUS_TYPE_SPECIAL_LOCATION,
+ NAUTILUS_SPECIAL_LOCATION_TEMPLATES,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
nautilus_special_location_bar_init (NautilusSpecialLocationBar *bar)
{
- GtkWidget *location_area;
- GtkWidget *action_area;
- PangoAttrList *attrs;
+ GtkWidget *location_area;
+ GtkWidget *action_area;
+ PangoAttrList *attrs;
- bar->priv = NAUTILUS_SPECIAL_LOCATION_BAR_GET_PRIVATE (bar);
- location_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
- action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+ bar->priv = NAUTILUS_SPECIAL_LOCATION_BAR_GET_PRIVATE (bar);
+ location_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+ action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
- gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
- attrs = pango_attr_list_new ();
- pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
- bar->priv->label = gtk_label_new (NULL);
- gtk_label_set_attributes (GTK_LABEL (bar->priv->label), attrs);
- pango_attr_list_unref (attrs);
+ attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+ bar->priv->label = gtk_label_new (NULL);
+ gtk_label_set_attributes (GTK_LABEL (bar->priv->label), attrs);
+ pango_attr_list_unref (attrs);
- gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
- gtk_container_add (GTK_CONTAINER (location_area), bar->priv->label);
+ gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
+ gtk_container_add (GTK_CONTAINER (location_area), bar->priv->label);
- bar->priv->learn_more_label = gtk_label_new (NULL);
- gtk_widget_set_hexpand (bar->priv->learn_more_label, TRUE);
- gtk_widget_set_halign (bar->priv->learn_more_label, GTK_ALIGN_END);
- gtk_container_add (GTK_CONTAINER (location_area), bar->priv->learn_more_label);
+ bar->priv->learn_more_label = gtk_label_new (NULL);
+ gtk_widget_set_hexpand (bar->priv->learn_more_label, TRUE);
+ gtk_widget_set_halign (bar->priv->learn_more_label, GTK_ALIGN_END);
+ gtk_container_add (GTK_CONTAINER (location_area), bar->priv->learn_more_label);
}
GtkWidget *
nautilus_special_location_bar_new (NautilusSpecialLocation location)
{
- return g_object_new (NAUTILUS_TYPE_SPECIAL_LOCATION_BAR,
- "message-type", GTK_MESSAGE_QUESTION,
- "special-location", location,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_SPECIAL_LOCATION_BAR,
+ "message-type", GTK_MESSAGE_QUESTION,
+ "special-location", location,
+ NULL);
}
diff --git a/src/nautilus-thumbnails.c b/src/nautilus-thumbnails.c
index 5295df47e..040faeb5b 100644
--- a/src/nautilus-thumbnails.c
+++ b/src/nautilus-thumbnails.c
@@ -1,24 +1,24 @@
/*
- nautilus-thumbnails.h: Thumbnail code for icon factory.
-
- Copyright (C) 2000, 2001 Eazel, Inc.
- Copyright (C) 2002, 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Andy Hertzfeld <andy@eazel.com>
-*/
+ * nautilus-thumbnails.h: Thumbnail code for icon factory.
+ *
+ * Copyright (C) 2000, 2001 Eazel, Inc.
+ * Copyright (C) 2002, 2003 Red Hat, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Andy Hertzfeld <andy@eazel.com>
+ */
#include <config.h>
#include "nautilus-thumbnails.h"
@@ -62,10 +62,11 @@ static void thumbnail_thread_func (GTask *task,
/* structure used for making thumbnails, associating a uri with where the thumbnail is to be stored */
-typedef struct {
- char *image_uri;
- char *mime_type;
- time_t original_file_mtime;
+typedef struct
+{
+ char *image_uri;
+ char *mime_type;
+ time_t original_file_mtime;
} NautilusThumbnailInfo;
/*
@@ -73,20 +74,20 @@ typedef struct {
*/
/* The id of the idle handler used to start the thumbnail thread, or 0 if no
- idle handler is currently registered. */
+ * idle handler is currently registered. */
static guint thumbnail_thread_starter_id = 0;
/* Our mutex used when accessing data shared between the main thread and the
- thumbnail thread, i.e. the thumbnail_thread_is_running flag and the
- thumbnails_to_make list. */
+ * thumbnail thread, i.e. the thumbnail_thread_is_running flag and the
+ * thumbnails_to_make list. */
static GMutex thumbnails_mutex;
/* A flag to indicate whether a thumbnail thread is running, so we don't
- start more than one. Lock thumbnails_mutex when accessing this. */
+ * start more than one. Lock thumbnails_mutex when accessing this. */
static volatile gboolean thumbnail_thread_is_running = FALSE;
/* The list of NautilusThumbnailInfo structs containing information about the
- thumbnails we are making. Lock thumbnails_mutex when accessing this. */
+ * thumbnails we are making. Lock thumbnails_mutex when accessing this. */
static volatile GQueue thumbnails_to_make = G_QUEUE_INIT;
/* Quickly check if uri is in thumbnails_to_make list */
@@ -99,350 +100,372 @@ static NautilusThumbnailInfo *currently_thumbnailing = NULL;
static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL;
static gboolean
-get_file_mtime (const char *file_uri, time_t* mtime)
+get_file_mtime (const char *file_uri,
+ time_t *mtime)
{
- GFile *file;
- GFileInfo *info;
- gboolean ret;
-
- ret = FALSE;
- *mtime = INVALID_MTIME;
-
- file = g_file_new_for_uri (file_uri);
- info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
- if (info) {
- if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED)) {
- *mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- ret = TRUE;
- }
-
- g_object_unref (info);
- }
- g_object_unref (file);
-
- return ret;
+ GFile *file;
+ GFileInfo *info;
+ gboolean ret;
+
+ ret = FALSE;
+ *mtime = INVALID_MTIME;
+
+ file = g_file_new_for_uri (file_uri);
+ info = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, 0, NULL, NULL);
+ if (info)
+ {
+ if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
+ {
+ *mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ ret = TRUE;
+ }
+
+ g_object_unref (info);
+ }
+ g_object_unref (file);
+
+ return ret;
}
static void
free_thumbnail_info (NautilusThumbnailInfo *info)
{
- g_free (info->image_uri);
- g_free (info->mime_type);
- g_free (info);
+ g_free (info->image_uri);
+ g_free (info->mime_type);
+ g_free (info);
}
static GnomeDesktopThumbnailFactory *
get_thumbnail_factory (void)
{
- static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL;
+ static GnomeDesktopThumbnailFactory *thumbnail_factory = NULL;
- if (thumbnail_factory == NULL) {
- thumbnail_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
- }
+ if (thumbnail_factory == NULL)
+ {
+ thumbnail_factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE);
+ }
- return thumbnail_factory;
+ return thumbnail_factory;
}
/* This function is added as a very low priority idle function to start the
- thread to create any needed thumbnails. It is added with a very low priority
- so that it doesn't delay showing the directory in the icon/list views.
- We want to show the files in the directory as quickly as possible. */
+ * thread to create any needed thumbnails. It is added with a very low priority
+ * so that it doesn't delay showing the directory in the icon/list views.
+ * We want to show the files in the directory as quickly as possible. */
static gboolean
thumbnail_thread_starter_cb (gpointer data)
{
- GTask *task;
+ GTask *task;
- /* Don't do this in thread, since g_object_ref is not threadsafe */
- if (thumbnail_factory == NULL) {
- thumbnail_factory = get_thumbnail_factory ();
- }
+ /* Don't do this in thread, since g_object_ref is not threadsafe */
+ if (thumbnail_factory == NULL)
+ {
+ thumbnail_factory = get_thumbnail_factory ();
+ }
#ifdef DEBUG_THUMBNAILS
- g_message ("(Main Thread) Creating thumbnails thread\n");
+ g_message ("(Main Thread) Creating thumbnails thread\n");
#endif
- /* We set a flag to indicate the thread is running, so we don't create
- a new one. We don't need to lock a mutex here, as the thumbnail
- thread isn't running yet. And we know we won't create the thread
- twice, as we also check thumbnail_thread_starter_id before
- scheduling this idle function. */
- thumbnail_thread_is_running = TRUE;
- task = g_task_new (NULL, NULL, NULL, NULL);
- g_task_run_in_thread (task, thumbnail_thread_func);
- thumbnail_thread_starter_id = 0;
-
- g_object_unref (task);
-
- return FALSE;
+ /* We set a flag to indicate the thread is running, so we don't create
+ * a new one. We don't need to lock a mutex here, as the thumbnail
+ * thread isn't running yet. And we know we won't create the thread
+ * twice, as we also check thumbnail_thread_starter_id before
+ * scheduling this idle function. */
+ thumbnail_thread_is_running = TRUE;
+ task = g_task_new (NULL, NULL, NULL, NULL);
+ g_task_run_in_thread (task, thumbnail_thread_func);
+ thumbnail_thread_starter_id = 0;
+
+ g_object_unref (task);
+
+ return FALSE;
}
void
nautilus_thumbnail_remove_from_queue (const char *file_uri)
{
- GList *node;
-
+ GList *node;
+
#ifdef DEBUG_THUMBNAILS
- g_message ("(Remove from queue) Locking mutex\n");
+ g_message ("(Remove from queue) Locking mutex\n");
#endif
- g_mutex_lock (&thumbnails_mutex);
-
- /*********************************
- * MUTEX LOCKED
- *********************************/
-
- if (thumbnails_to_make_hash) {
- node = g_hash_table_lookup (thumbnails_to_make_hash, file_uri);
-
- if (node && node->data != currently_thumbnailing) {
- g_hash_table_remove (thumbnails_to_make_hash, file_uri);
- free_thumbnail_info (node->data);
- g_queue_delete_link ((GQueue *)&thumbnails_to_make, node);
- }
- }
-
- /*********************************
- * MUTEX UNLOCKED
- *********************************/
-
+ g_mutex_lock (&thumbnails_mutex);
+
+ /*********************************
+ * MUTEX LOCKED
+ *********************************/
+
+ if (thumbnails_to_make_hash)
+ {
+ node = g_hash_table_lookup (thumbnails_to_make_hash, file_uri);
+
+ if (node && node->data != currently_thumbnailing)
+ {
+ g_hash_table_remove (thumbnails_to_make_hash, file_uri);
+ free_thumbnail_info (node->data);
+ g_queue_delete_link ((GQueue *) &thumbnails_to_make, node);
+ }
+ }
+
+ /*********************************
+ * MUTEX UNLOCKED
+ *********************************/
+
#ifdef DEBUG_THUMBNAILS
- g_message ("(Remove from queue) Unlocking mutex\n");
+ g_message ("(Remove from queue) Unlocking mutex\n");
#endif
- g_mutex_unlock (&thumbnails_mutex);
+ g_mutex_unlock (&thumbnails_mutex);
}
void
nautilus_thumbnail_prioritize (const char *file_uri)
{
- GList *node;
+ GList *node;
#ifdef DEBUG_THUMBNAILS
- g_message ("(Prioritize) Locking mutex\n");
+ g_message ("(Prioritize) Locking mutex\n");
#endif
- g_mutex_lock (&thumbnails_mutex);
-
- /*********************************
- * MUTEX LOCKED
- *********************************/
-
- if (thumbnails_to_make_hash) {
- node = g_hash_table_lookup (thumbnails_to_make_hash, file_uri);
-
- if (node && node->data != currently_thumbnailing) {
- g_queue_unlink ((GQueue *)&thumbnails_to_make, node);
- g_queue_push_head_link ((GQueue *)&thumbnails_to_make, node);
- }
- }
-
- /*********************************
- * MUTEX UNLOCKED
- *********************************/
-
+ g_mutex_lock (&thumbnails_mutex);
+
+ /*********************************
+ * MUTEX LOCKED
+ *********************************/
+
+ if (thumbnails_to_make_hash)
+ {
+ node = g_hash_table_lookup (thumbnails_to_make_hash, file_uri);
+
+ if (node && node->data != currently_thumbnailing)
+ {
+ g_queue_unlink ((GQueue *) &thumbnails_to_make, node);
+ g_queue_push_head_link ((GQueue *) &thumbnails_to_make, node);
+ }
+ }
+
+ /*********************************
+ * MUTEX UNLOCKED
+ *********************************/
+
#ifdef DEBUG_THUMBNAILS
- g_message ("(Prioritize) Unlocking mutex\n");
+ g_message ("(Prioritize) Unlocking mutex\n");
#endif
- g_mutex_unlock (&thumbnails_mutex);
+ g_mutex_unlock (&thumbnails_mutex);
}
/***************************************************************************
- * Thumbnail Thread Functions.
- ***************************************************************************/
+* Thumbnail Thread Functions.
+***************************************************************************/
/* This is a one-shot idle callback called from the main loop to call
- notify_file_changed() for a thumbnail. It frees the uri afterwards.
- We do this in an idle callback as I don't think nautilus_file_changed() is
- thread-safe. */
+ * notify_file_changed() for a thumbnail. It frees the uri afterwards.
+ * We do this in an idle callback as I don't think nautilus_file_changed() is
+ * thread-safe. */
static gboolean
thumbnail_thread_notify_file_changed (gpointer image_uri)
{
- NautilusFile *file;
+ NautilusFile *file;
- file = nautilus_file_get_by_uri ((char *) image_uri);
+ file = nautilus_file_get_by_uri ((char *) image_uri);
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Notifying file changed file:%p uri: %s\n", file, (char*) image_uri);
+ g_message ("(Thumbnail Thread) Notifying file changed file:%p uri: %s\n", file, (char *) image_uri);
#endif
- if (file != NULL) {
- nautilus_file_set_is_thumbnailing (file, FALSE);
- nautilus_file_invalidate_attributes (file,
- NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL |
- NAUTILUS_FILE_ATTRIBUTE_INFO);
- nautilus_file_unref (file);
- }
- g_free (image_uri);
-
- return FALSE;
+ if (file != NULL)
+ {
+ nautilus_file_set_is_thumbnailing (file, FALSE);
+ nautilus_file_invalidate_attributes (file,
+ NAUTILUS_FILE_ATTRIBUTE_THUMBNAIL |
+ NAUTILUS_FILE_ATTRIBUTE_INFO);
+ nautilus_file_unref (file);
+ }
+ g_free (image_uri);
+
+ return FALSE;
}
static GHashTable *
get_types_table (void)
{
- static GHashTable *image_mime_types = NULL;
- GSList *format_list, *l;
- char **types;
- int i;
-
- if (image_mime_types == NULL) {
- image_mime_types =
- g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
-
- format_list = gdk_pixbuf_get_formats ();
- for (l = format_list; l; l = l->next) {
- types = gdk_pixbuf_format_get_mime_types (l->data);
-
- for (i = 0; types[i] != NULL; i++) {
- g_hash_table_insert (image_mime_types,
- types [i],
- GUINT_TO_POINTER (1));
- }
-
- g_free (types);
- }
-
- g_slist_free (format_list);
- }
-
- return image_mime_types;
+ static GHashTable *image_mime_types = NULL;
+ GSList *format_list, *l;
+ char **types;
+ int i;
+
+ if (image_mime_types == NULL)
+ {
+ image_mime_types =
+ g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, NULL);
+
+ format_list = gdk_pixbuf_get_formats ();
+ for (l = format_list; l; l = l->next)
+ {
+ types = gdk_pixbuf_format_get_mime_types (l->data);
+
+ for (i = 0; types[i] != NULL; i++)
+ {
+ g_hash_table_insert (image_mime_types,
+ types [i],
+ GUINT_TO_POINTER (1));
+ }
+
+ g_free (types);
+ }
+
+ g_slist_free (format_list);
+ }
+
+ return image_mime_types;
}
static gboolean
pixbuf_can_load_type (const char *mime_type)
{
- GHashTable *image_mime_types;
+ GHashTable *image_mime_types;
- image_mime_types = get_types_table ();
- if (g_hash_table_lookup (image_mime_types, mime_type)) {
- return TRUE;
- }
+ image_mime_types = get_types_table ();
+ if (g_hash_table_lookup (image_mime_types, mime_type))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
gboolean
nautilus_can_thumbnail_internally (NautilusFile *file)
{
- char *mime_type;
- gboolean res;
+ char *mime_type;
+ gboolean res;
- mime_type = nautilus_file_get_mime_type (file);
- res = pixbuf_can_load_type (mime_type);
- g_free (mime_type);
- return res;
+ mime_type = nautilus_file_get_mime_type (file);
+ res = pixbuf_can_load_type (mime_type);
+ g_free (mime_type);
+ return res;
}
gboolean
nautilus_thumbnail_is_mimetype_limited_by_size (const char *mime_type)
{
- return pixbuf_can_load_type (mime_type);
+ return pixbuf_can_load_type (mime_type);
}
gboolean
nautilus_can_thumbnail (NautilusFile *file)
{
- GnomeDesktopThumbnailFactory *factory;
- gboolean res;
- char *uri;
- time_t mtime;
- char *mime_type;
-
- uri = nautilus_file_get_uri (file);
- mime_type = nautilus_file_get_mime_type (file);
- mtime = nautilus_file_get_mtime (file);
-
- factory = get_thumbnail_factory ();
- res = gnome_desktop_thumbnail_factory_can_thumbnail (factory,
- uri,
- mime_type,
- mtime);
- g_free (mime_type);
- g_free (uri);
-
- return res;
+ GnomeDesktopThumbnailFactory *factory;
+ gboolean res;
+ char *uri;
+ time_t mtime;
+ char *mime_type;
+
+ uri = nautilus_file_get_uri (file);
+ mime_type = nautilus_file_get_mime_type (file);
+ mtime = nautilus_file_get_mtime (file);
+
+ factory = get_thumbnail_factory ();
+ res = gnome_desktop_thumbnail_factory_can_thumbnail (factory,
+ uri,
+ mime_type,
+ mtime);
+ g_free (mime_type);
+ g_free (uri);
+
+ return res;
}
void
nautilus_create_thumbnail (NautilusFile *file)
{
- time_t file_mtime = 0;
- NautilusThumbnailInfo *info;
- NautilusThumbnailInfo *existing_info;
- GList *existing, *node;
-
- nautilus_file_set_is_thumbnailing (file, TRUE);
-
- info = g_new0 (NautilusThumbnailInfo, 1);
- info->image_uri = nautilus_file_get_uri (file);
- info->mime_type = nautilus_file_get_mime_type (file);
-
- /* Hopefully the NautilusFile will already have the image file mtime,
- so we can just use that. Otherwise we have to get it ourselves. */
- if (file->details->got_file_info &&
- file->details->file_info_is_up_to_date &&
- file->details->mtime != 0) {
- file_mtime = file->details->mtime;
- } else {
- get_file_mtime (info->image_uri, &file_mtime);
- }
-
- info->original_file_mtime = file_mtime;
+ time_t file_mtime = 0;
+ NautilusThumbnailInfo *info;
+ NautilusThumbnailInfo *existing_info;
+ GList *existing, *node;
+
+ nautilus_file_set_is_thumbnailing (file, TRUE);
+
+ info = g_new0 (NautilusThumbnailInfo, 1);
+ info->image_uri = nautilus_file_get_uri (file);
+ info->mime_type = nautilus_file_get_mime_type (file);
+
+ /* Hopefully the NautilusFile will already have the image file mtime,
+ * so we can just use that. Otherwise we have to get it ourselves. */
+ if (file->details->got_file_info &&
+ file->details->file_info_is_up_to_date &&
+ file->details->mtime != 0)
+ {
+ file_mtime = file->details->mtime;
+ }
+ else
+ {
+ get_file_mtime (info->image_uri, &file_mtime);
+ }
+
+ info->original_file_mtime = file_mtime;
#ifdef DEBUG_THUMBNAILS
- g_message ("(Main Thread) Locking mutex\n");
+ g_message ("(Main Thread) Locking mutex\n");
#endif
- g_mutex_lock (&thumbnails_mutex);
-
- /*********************************
- * MUTEX LOCKED
- *********************************/
-
- if (thumbnails_to_make_hash == NULL) {
- thumbnails_to_make_hash = g_hash_table_new (g_str_hash,
- g_str_equal);
- }
-
- /* Check if it is already in the list of thumbnails to make. */
- existing = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
- if (existing == NULL) {
- /* Add the thumbnail to the list. */
+ g_mutex_lock (&thumbnails_mutex);
+
+ /*********************************
+ * MUTEX LOCKED
+ *********************************/
+
+ if (thumbnails_to_make_hash == NULL)
+ {
+ thumbnails_to_make_hash = g_hash_table_new (g_str_hash,
+ g_str_equal);
+ }
+
+ /* Check if it is already in the list of thumbnails to make. */
+ existing = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
+ if (existing == NULL)
+ {
+ /* Add the thumbnail to the list. */
#ifdef DEBUG_THUMBNAILS
- g_message ("(Main Thread) Adding thumbnail: %s\n",
- info->image_uri);
+ g_message ("(Main Thread) Adding thumbnail: %s\n",
+ info->image_uri);
#endif
- g_queue_push_tail ((GQueue *)&thumbnails_to_make, info);
- node = g_queue_peek_tail_link ((GQueue *)&thumbnails_to_make);
- g_hash_table_insert (thumbnails_to_make_hash,
- info->image_uri,
- node);
- /* If the thumbnail thread isn't running, and we haven't
- scheduled an idle function to start it up, do that now.
- We don't want to start it until all the other work is done,
- so the GUI will be updated as quickly as possible.*/
- if (thumbnail_thread_is_running == FALSE &&
- thumbnail_thread_starter_id == 0) {
- thumbnail_thread_starter_id = g_idle_add_full (G_PRIORITY_LOW, thumbnail_thread_starter_cb, NULL, NULL);
- }
- } else {
+ g_queue_push_tail ((GQueue *) &thumbnails_to_make, info);
+ node = g_queue_peek_tail_link ((GQueue *) &thumbnails_to_make);
+ g_hash_table_insert (thumbnails_to_make_hash,
+ info->image_uri,
+ node);
+ /* If the thumbnail thread isn't running, and we haven't
+ * scheduled an idle function to start it up, do that now.
+ * We don't want to start it until all the other work is done,
+ * so the GUI will be updated as quickly as possible.*/
+ if (thumbnail_thread_is_running == FALSE &&
+ thumbnail_thread_starter_id == 0)
+ {
+ thumbnail_thread_starter_id = g_idle_add_full (G_PRIORITY_LOW, thumbnail_thread_starter_cb, NULL, NULL);
+ }
+ }
+ else
+ {
#ifdef DEBUG_THUMBNAILS
- g_message ("(Main Thread) Updating non-current mtime: %s\n",
- info->image_uri);
+ g_message ("(Main Thread) Updating non-current mtime: %s\n",
+ info->image_uri);
#endif
- /* The file in the queue might need a new original mtime */
- existing_info = existing->data;
- existing_info->original_file_mtime = info->original_file_mtime;
- free_thumbnail_info (info);
- }
+ /* The file in the queue might need a new original mtime */
+ existing_info = existing->data;
+ existing_info->original_file_mtime = info->original_file_mtime;
+ free_thumbnail_info (info);
+ }
- /*********************************
- * MUTEX UNLOCKED
- *********************************/
+ /*********************************
+ * MUTEX UNLOCKED
+ *********************************/
#ifdef DEBUG_THUMBNAILS
- g_message ("(Main Thread) Unlocking mutex\n");
+ g_message ("(Main Thread) Unlocking mutex\n");
#endif
- g_mutex_unlock (&thumbnails_mutex);
+ g_mutex_unlock (&thumbnails_mutex);
}
/* thumbnail_thread is invoked as a separate thread to to make thumbnails. */
@@ -452,118 +475,125 @@ thumbnail_thread_func (GTask *task,
gpointer task_data,
GCancellable *cancellable)
{
- NautilusThumbnailInfo *info = NULL;
- GdkPixbuf *pixbuf;
- time_t current_orig_mtime = 0;
- time_t current_time;
- GList *node;
-
- /* We loop until there are no more thumbails to make, at which point
- we exit the thread. */
- for (;;) {
+ NautilusThumbnailInfo *info = NULL;
+ GdkPixbuf *pixbuf;
+ time_t current_orig_mtime = 0;
+ time_t current_time;
+ GList *node;
+
+ /* We loop until there are no more thumbails to make, at which point
+ * we exit the thread. */
+ for (;; )
+ {
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Locking mutex\n");
+ g_message ("(Thumbnail Thread) Locking mutex\n");
#endif
- g_mutex_lock (&thumbnails_mutex);
-
- /*********************************
- * MUTEX LOCKED
- *********************************/
-
- /* Pop the last thumbnail we just made off the head of the
- list and free it. I did this here so we only have to lock
- the mutex once per thumbnail, rather than once before
- creating it and once after.
- Don't pop the thumbnail off the queue if the original file
- mtime of the request changed. Then we need to redo the thumbnail.
- */
- if (currently_thumbnailing &&
- currently_thumbnailing->original_file_mtime == current_orig_mtime) {
- g_assert (info == currently_thumbnailing);
- node = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
- g_assert (node != NULL);
- g_hash_table_remove (thumbnails_to_make_hash, info->image_uri);
- free_thumbnail_info (info);
- g_queue_delete_link ((GQueue *)&thumbnails_to_make, node);
- }
- currently_thumbnailing = NULL;
-
- /* If there are no more thumbnails to make, reset the
- thumbnail_thread_is_running flag, unlock the mutex, and
- exit the thread. */
- if (g_queue_is_empty ((GQueue *)&thumbnails_to_make)) {
+ g_mutex_lock (&thumbnails_mutex);
+
+ /*********************************
+ * MUTEX LOCKED
+ *********************************/
+
+ /* Pop the last thumbnail we just made off the head of the
+ * list and free it. I did this here so we only have to lock
+ * the mutex once per thumbnail, rather than once before
+ * creating it and once after.
+ * Don't pop the thumbnail off the queue if the original file
+ * mtime of the request changed. Then we need to redo the thumbnail.
+ */
+ if (currently_thumbnailing &&
+ currently_thumbnailing->original_file_mtime == current_orig_mtime)
+ {
+ g_assert (info == currently_thumbnailing);
+ node = g_hash_table_lookup (thumbnails_to_make_hash, info->image_uri);
+ g_assert (node != NULL);
+ g_hash_table_remove (thumbnails_to_make_hash, info->image_uri);
+ free_thumbnail_info (info);
+ g_queue_delete_link ((GQueue *) &thumbnails_to_make, node);
+ }
+ currently_thumbnailing = NULL;
+
+ /* If there are no more thumbnails to make, reset the
+ * thumbnail_thread_is_running flag, unlock the mutex, and
+ * exit the thread. */
+ if (g_queue_is_empty ((GQueue *) &thumbnails_to_make))
+ {
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Exiting\n");
+ g_message ("(Thumbnail Thread) Exiting\n");
#endif
- thumbnail_thread_is_running = FALSE;
- g_mutex_unlock (&thumbnails_mutex);
- return;
- }
-
- /* Get the next one to make. We leave it on the list until it
- is created so the main thread doesn't add it again while we
- are creating it. */
- info = g_queue_peek_head ((GQueue *)&thumbnails_to_make);
- currently_thumbnailing = info;
- current_orig_mtime = info->original_file_mtime;
- /*********************************
- * MUTEX UNLOCKED
- *********************************/
+ thumbnail_thread_is_running = FALSE;
+ g_mutex_unlock (&thumbnails_mutex);
+ return;
+ }
+
+ /* Get the next one to make. We leave it on the list until it
+ * is created so the main thread doesn't add it again while we
+ * are creating it. */
+ info = g_queue_peek_head ((GQueue *) &thumbnails_to_make);
+ currently_thumbnailing = info;
+ current_orig_mtime = info->original_file_mtime;
+ /*********************************
+ * MUTEX UNLOCKED
+ *********************************/
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Unlocking mutex\n");
+ g_message ("(Thumbnail Thread) Unlocking mutex\n");
#endif
- g_mutex_unlock (&thumbnails_mutex);
+ g_mutex_unlock (&thumbnails_mutex);
- time (&current_time);
+ time (&current_time);
- /* Don't try to create a thumbnail if the file was modified recently.
- This prevents constant re-thumbnailing of changing files. */
- if (current_time < current_orig_mtime + THUMBNAIL_CREATION_DELAY_SECS &&
- current_time >= current_orig_mtime) {
+ /* Don't try to create a thumbnail if the file was modified recently.
+ * This prevents constant re-thumbnailing of changing files. */
+ if (current_time < current_orig_mtime + THUMBNAIL_CREATION_DELAY_SECS &&
+ current_time >= current_orig_mtime)
+ {
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Skipping: %s\n",
- info->image_uri);
+ g_message ("(Thumbnail Thread) Skipping: %s\n",
+ info->image_uri);
#endif
- /* Reschedule thumbnailing via a change notification */
- g_timeout_add_seconds (1, thumbnail_thread_notify_file_changed,
- g_strdup (info->image_uri));
- continue;
- }
+ /* Reschedule thumbnailing via a change notification */
+ g_timeout_add_seconds (1, thumbnail_thread_notify_file_changed,
+ g_strdup (info->image_uri));
+ continue;
+ }
- /* Create the thumbnail. */
+ /* Create the thumbnail. */
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Creating thumbnail: %s\n",
- info->image_uri);
+ g_message ("(Thumbnail Thread) Creating thumbnail: %s\n",
+ info->image_uri);
#endif
- pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumbnail_factory,
- info->image_uri,
- info->mime_type);
+ pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (thumbnail_factory,
+ info->image_uri,
+ info->mime_type);
- if (pixbuf) {
+ if (pixbuf)
+ {
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Saving thumbnail: %s\n",
- info->image_uri);
+ g_message ("(Thumbnail Thread) Saving thumbnail: %s\n",
+ info->image_uri);
#endif
- gnome_desktop_thumbnail_factory_save_thumbnail (thumbnail_factory,
- pixbuf,
- info->image_uri,
- current_orig_mtime);
- g_object_unref (pixbuf);
- } else {
+ gnome_desktop_thumbnail_factory_save_thumbnail (thumbnail_factory,
+ pixbuf,
+ info->image_uri,
+ current_orig_mtime);
+ g_object_unref (pixbuf);
+ }
+ else
+ {
#ifdef DEBUG_THUMBNAILS
- g_message ("(Thumbnail Thread) Thumbnail failed: %s\n",
- info->image_uri);
+ g_message ("(Thumbnail Thread) Thumbnail failed: %s\n",
+ info->image_uri);
#endif
- gnome_desktop_thumbnail_factory_create_failed_thumbnail (thumbnail_factory,
- info->image_uri,
- current_orig_mtime);
- }
- /* We need to call nautilus_file_changed(), but I don't think that is
- thread safe. So add an idle handler and do it from the main loop. */
- g_idle_add_full (G_PRIORITY_HIGH_IDLE,
- thumbnail_thread_notify_file_changed,
- g_strdup (info->image_uri), NULL);
- }
+ gnome_desktop_thumbnail_factory_create_failed_thumbnail (thumbnail_factory,
+ info->image_uri,
+ current_orig_mtime);
+ }
+ /* We need to call nautilus_file_changed(), but I don't think that is
+ * thread safe. So add an idle handler and do it from the main loop. */
+ g_idle_add_full (G_PRIORITY_HIGH_IDLE,
+ thumbnail_thread_notify_file_changed,
+ g_strdup (info->image_uri), NULL);
+ }
}
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index fb14346e9..67d3e5969 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -41,66 +40,69 @@
#include <glib/gi18n.h>
#include <math.h>
-#define OPERATION_MINIMUM_TIME 2 //s
-#define NEEDS_ATTENTION_ANIMATION_TIMEOUT 2000 //ms
-#define REMOVE_FINISHED_OPERATIONS_TIEMOUT 3 //s
+#define OPERATION_MINIMUM_TIME 2 /*s */
+#define NEEDS_ATTENTION_ANIMATION_TIMEOUT 2000 /*ms */
+#define REMOVE_FINISHED_OPERATIONS_TIEMOUT 3 /*s */
-typedef enum {
- NAUTILUS_NAVIGATION_DIRECTION_NONE,
- NAUTILUS_NAVIGATION_DIRECTION_BACK,
- NAUTILUS_NAVIGATION_DIRECTION_FORWARD
+typedef enum
+{
+ NAUTILUS_NAVIGATION_DIRECTION_NONE,
+ NAUTILUS_NAVIGATION_DIRECTION_BACK,
+ NAUTILUS_NAVIGATION_DIRECTION_FORWARD
} NautilusNavigationDirection;
-struct _NautilusToolbarPrivate {
- NautilusWindow *window;
-
- GtkWidget *path_bar_container;
- GtkWidget *location_entry_container;
- GtkWidget *path_bar;
- GtkWidget *location_entry;
-
- gboolean show_location_entry;
-
- guint popup_timeout_id;
- guint start_operations_timeout_id;
- guint remove_finished_operations_timeout_id;
- guint operations_button_attention_timeout_id;
-
- GtkWidget *operations_button;
- GtkWidget *view_button;
- GtkWidget *view_menu_zoom_section;
- GtkWidget *view_menu_undo_redo_section;
- GtkWidget *view_menu_extended_section;
- GtkWidget *undo_button;
- GtkWidget *redo_button;
- GtkWidget *view_toggle_button;
- GtkWidget *view_toggle_icon;
-
- GtkWidget *operations_popover;
- GtkWidget *operations_container;
- GtkWidget *operations_revealer;
- GtkWidget *operations_icon;
-
- GtkWidget *forward_button;
- GtkWidget *back_button;
-
- NautilusProgressInfoManager *progress_manager;
-
- /* active slot & bindings */
- NautilusWindowSlot *active_slot;
- GBinding *icon_binding;
- GBinding *view_widget_binding;
+struct _NautilusToolbarPrivate
+{
+ NautilusWindow *window;
+
+ GtkWidget *path_bar_container;
+ GtkWidget *location_entry_container;
+ GtkWidget *path_bar;
+ GtkWidget *location_entry;
+
+ gboolean show_location_entry;
+
+ guint popup_timeout_id;
+ guint start_operations_timeout_id;
+ guint remove_finished_operations_timeout_id;
+ guint operations_button_attention_timeout_id;
+
+ GtkWidget *operations_button;
+ GtkWidget *view_button;
+ GtkWidget *view_menu_zoom_section;
+ GtkWidget *view_menu_undo_redo_section;
+ GtkWidget *view_menu_extended_section;
+ GtkWidget *undo_button;
+ GtkWidget *redo_button;
+ GtkWidget *view_toggle_button;
+ GtkWidget *view_toggle_icon;
+
+ GtkWidget *operations_popover;
+ GtkWidget *operations_container;
+ GtkWidget *operations_revealer;
+ GtkWidget *operations_icon;
+
+ GtkWidget *forward_button;
+ GtkWidget *back_button;
+
+ NautilusProgressInfoManager *progress_manager;
+
+ /* active slot & bindings */
+ NautilusWindowSlot *active_slot;
+ GBinding *icon_binding;
+ GBinding *view_widget_binding;
};
-enum {
- PROP_WINDOW = 1,
- PROP_SHOW_LOCATION_ENTRY,
- NUM_PROPERTIES
+enum
+{
+ PROP_WINDOW = 1,
+ PROP_SHOW_LOCATION_ENTRY,
+ NUM_PROPERTIES
};
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
-G_DEFINE_TYPE_WITH_PRIVATE(NautilusToolbar, nautilus_toolbar, GTK_TYPE_HEADER_BAR);
+G_DEFINE_TYPE_WITH_PRIVATE (NautilusToolbar, nautilus_toolbar, GTK_TYPE_HEADER_BAR);
static void unschedule_menu_popup_timeout (NautilusToolbar *self);
static void update_operations (NautilusToolbar *self);
@@ -108,548 +110,596 @@ static void update_operations (NautilusToolbar *self);
static void
toolbar_update_appearance (NautilusToolbar *self)
{
- gboolean show_location_entry;
+ gboolean show_location_entry;
- show_location_entry = self->priv->show_location_entry ||
- g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY);
+ show_location_entry = self->priv->show_location_entry ||
+ g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY);
- gtk_widget_set_visible (self->priv->location_entry,
- show_location_entry);
- gtk_widget_set_visible (self->priv->path_bar,
- !show_location_entry);
+ gtk_widget_set_visible (self->priv->location_entry,
+ show_location_entry);
+ gtk_widget_set_visible (self->priv->path_bar,
+ !show_location_entry);
}
static void
-activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
- NautilusWindow *window,
- gboolean back)
+activate_back_or_forward_menu_item (GtkMenuItem *menu_item,
+ NautilusWindow *window,
+ gboolean back)
{
- int index;
-
- g_assert (GTK_IS_MENU_ITEM (menu_item));
+ int index;
+
+ g_assert (GTK_IS_MENU_ITEM (menu_item));
- index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "user_data"));
+ index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "user_data"));
- nautilus_window_back_or_forward (window, back, index, nautilus_event_get_window_open_flags ());
+ nautilus_window_back_or_forward (window, back, index, nautilus_event_get_window_open_flags ());
}
static void
-activate_back_menu_item_callback (GtkMenuItem *menu_item,
+activate_back_menu_item_callback (GtkMenuItem *menu_item,
NautilusWindow *window)
{
- activate_back_or_forward_menu_item (menu_item, window, TRUE);
+ activate_back_or_forward_menu_item (menu_item, window, TRUE);
}
static void
-activate_forward_menu_item_callback (GtkMenuItem *menu_item, NautilusWindow *window)
+activate_forward_menu_item_callback (GtkMenuItem *menu_item,
+ NautilusWindow *window)
{
- activate_back_or_forward_menu_item (menu_item, window, FALSE);
+ activate_back_or_forward_menu_item (menu_item, window, FALSE);
}
static void
fill_menu (NautilusWindow *window,
- GtkWidget *menu,
- gboolean back)
+ GtkWidget *menu,
+ gboolean back)
{
- NautilusWindowSlot *slot;
- GtkWidget *menu_item;
- int index;
- GList *list;
-
- slot = nautilus_window_get_active_slot (window);
- list = back ? nautilus_window_slot_get_back_history (slot) :
- nautilus_window_slot_get_forward_history (slot);
-
- index = 0;
- while (list != NULL) {
- menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list->data));
- g_object_set_data (G_OBJECT (menu_item), "user_data", GINT_TO_POINTER (index));
- gtk_widget_show (GTK_WIDGET (menu_item));
- g_signal_connect_object (menu_item, "activate",
- back
- ? G_CALLBACK (activate_back_menu_item_callback)
- : G_CALLBACK (activate_forward_menu_item_callback),
- window, 0);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
- list = g_list_next (list);
- ++index;
- }
+ NautilusWindowSlot *slot;
+ GtkWidget *menu_item;
+ int index;
+ GList *list;
+
+ slot = nautilus_window_get_active_slot (window);
+ list = back ? nautilus_window_slot_get_back_history (slot) :
+ nautilus_window_slot_get_forward_history (slot);
+
+ index = 0;
+ while (list != NULL)
+ {
+ menu_item = nautilus_bookmark_menu_item_new (NAUTILUS_BOOKMARK (list->data));
+ g_object_set_data (G_OBJECT (menu_item), "user_data", GINT_TO_POINTER (index));
+ gtk_widget_show (GTK_WIDGET (menu_item));
+ g_signal_connect_object (menu_item, "activate",
+ back
+ ? G_CALLBACK (activate_back_menu_item_callback)
+ : G_CALLBACK (activate_forward_menu_item_callback),
+ window, 0);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ list = g_list_next (list);
+ ++index;
+ }
}
/* adapted from gtk/gtkmenubutton.c */
static void
-menu_position_func (GtkMenu *menu,
- gint *x,
- gint *y,
- gboolean *push_in,
- GtkWidget *widget)
+menu_position_func (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ GtkWidget *widget)
{
- GtkWidget *toplevel;
- GtkRequisition menu_req;
- GdkRectangle monitor;
- gint monitor_num;
- GdkScreen *screen;
- GdkWindow *window;
- GtkAllocation allocation;
-
- /* Set the dropdown menu hint on the toplevel, so the WM can omit the top side
- * of the shadows.
- */
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
- gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
-
- window = gtk_widget_get_window (widget);
- screen = gtk_widget_get_screen (GTK_WIDGET (menu));
- monitor_num = gdk_screen_get_monitor_at_window (screen, window);
- if (monitor_num < 0) {
- monitor_num = 0;
- }
-
- gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
- gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
- gtk_widget_get_allocation (widget, &allocation);
- gdk_window_get_origin (window, x, y);
-
- *x += allocation.x;
- *y += allocation.y;
-
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) {
- *x -= MAX (menu_req.width - allocation.width, 0);
- } else {
- *x += MAX (allocation.width - menu_req.width, 0);
- }
-
- if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height) {
- *y += allocation.height;
- } else if ((*y - menu_req.height) >= monitor.y) {
- *y -= menu_req.height;
- } else if (monitor.y + monitor.height - (*y + allocation.height) > *y) {
- *y += allocation.height;
- } else {
- *y -= menu_req.height;
- }
-
- *push_in = FALSE;
+ GtkWidget *toplevel;
+ GtkRequisition menu_req;
+ GdkRectangle monitor;
+ gint monitor_num;
+ GdkScreen *screen;
+ GdkWindow *window;
+ GtkAllocation allocation;
+
+ /* Set the dropdown menu hint on the toplevel, so the WM can omit the top side
+ * of the shadows.
+ */
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
+ gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
+
+ window = gtk_widget_get_window (widget);
+ screen = gtk_widget_get_screen (GTK_WIDGET (menu));
+ monitor_num = gdk_screen_get_monitor_at_window (screen, window);
+ if (monitor_num < 0)
+ {
+ monitor_num = 0;
+ }
+
+ gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
+ gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_req, NULL);
+ gtk_widget_get_allocation (widget, &allocation);
+ gdk_window_get_origin (window, x, y);
+
+ *x += allocation.x;
+ *y += allocation.y;
+
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ {
+ *x -= MAX (menu_req.width - allocation.width, 0);
+ }
+ else
+ {
+ *x += MAX (allocation.width - menu_req.width, 0);
+ }
+
+ if ((*y + allocation.height + menu_req.height) <= monitor.y + monitor.height)
+ {
+ *y += allocation.height;
+ }
+ else if ((*y - menu_req.height) >= monitor.y)
+ {
+ *y -= menu_req.height;
+ }
+ else if (monitor.y + monitor.height - (*y + allocation.height) > *y)
+ {
+ *y += allocation.height;
+ }
+ else
+ {
+ *y -= menu_req.height;
+ }
+
+ *push_in = FALSE;
}
static void
show_menu (NautilusToolbar *self,
- GtkWidget *widget,
- guint button,
- guint32 event_time)
+ GtkWidget *widget,
+ guint button,
+ guint32 event_time)
{
- NautilusWindow *window;
- GtkWidget *menu;
- NautilusNavigationDirection direction;
-
- window = self->priv->window;
- menu = gtk_menu_new ();
-
- direction = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
- "nav-direction"));
-
- switch (direction) {
- case NAUTILUS_NAVIGATION_DIRECTION_FORWARD:
- fill_menu (window, menu, FALSE);
- break;
- case NAUTILUS_NAVIGATION_DIRECTION_BACK:
- fill_menu (window, menu, TRUE);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (window), NULL);
- gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
- (GtkMenuPositionFunc) menu_position_func, widget,
- button, event_time);
+ NautilusWindow *window;
+ GtkWidget *menu;
+ NautilusNavigationDirection direction;
+
+ window = self->priv->window;
+ menu = gtk_menu_new ();
+
+ direction = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget),
+ "nav-direction"));
+
+ switch (direction)
+ {
+ case NAUTILUS_NAVIGATION_DIRECTION_FORWARD:
+ {
+ fill_menu (window, menu, FALSE);
+ }
+ break;
+
+ case NAUTILUS_NAVIGATION_DIRECTION_BACK:
+ {
+ fill_menu (window, menu, TRUE);
+ }
+ break;
+
+ default:
+ {
+ g_assert_not_reached ();
+ }
+ break;
+ }
+
+ gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (window), NULL);
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+ (GtkMenuPositionFunc) menu_position_func, widget,
+ button, event_time);
}
#define MENU_POPUP_TIMEOUT 1200
-typedef struct {
- NautilusToolbar *self;
- GtkWidget *widget;
+typedef struct
+{
+ NautilusToolbar *self;
+ GtkWidget *widget;
} ScheduleMenuData;
static void
schedule_menu_data_free (ScheduleMenuData *data)
{
- g_slice_free (ScheduleMenuData, data);
+ g_slice_free (ScheduleMenuData, data);
}
static gboolean
popup_menu_timeout_cb (gpointer user_data)
{
- ScheduleMenuData *data = user_data;
+ ScheduleMenuData *data = user_data;
- show_menu (data->self, data->widget,
- 1, gtk_get_current_event_time ());
+ show_menu (data->self, data->widget,
+ 1, gtk_get_current_event_time ());
- return FALSE;
+ return FALSE;
}
static void
unschedule_menu_popup_timeout (NautilusToolbar *self)
{
- if (self->priv->popup_timeout_id != 0) {
- g_source_remove (self->priv->popup_timeout_id);
- self->priv->popup_timeout_id = 0;
- }
+ if (self->priv->popup_timeout_id != 0)
+ {
+ g_source_remove (self->priv->popup_timeout_id);
+ self->priv->popup_timeout_id = 0;
+ }
}
static void
schedule_menu_popup_timeout (NautilusToolbar *self,
- GtkWidget *widget)
+ GtkWidget *widget)
{
- ScheduleMenuData *data;
+ ScheduleMenuData *data;
- /* unschedule any previous timeouts */
- unschedule_menu_popup_timeout (self);
+ /* unschedule any previous timeouts */
+ unschedule_menu_popup_timeout (self);
- data = g_slice_new0 (ScheduleMenuData);
- data->self = self;
- data->widget = widget;
+ data = g_slice_new0 (ScheduleMenuData);
+ data->self = self;
+ data->widget = widget;
- self->priv->popup_timeout_id =
- g_timeout_add_full (G_PRIORITY_DEFAULT, MENU_POPUP_TIMEOUT,
- popup_menu_timeout_cb, data,
- (GDestroyNotify) schedule_menu_data_free);
+ self->priv->popup_timeout_id =
+ g_timeout_add_full (G_PRIORITY_DEFAULT, MENU_POPUP_TIMEOUT,
+ popup_menu_timeout_cb, data,
+ (GDestroyNotify) schedule_menu_data_free);
}
static gboolean
-navigation_button_press_cb (GtkButton *button,
- GdkEventButton *event,
- gpointer user_data)
+navigation_button_press_cb (GtkButton *button,
+ GdkEventButton *event,
+ gpointer user_data)
{
- NautilusToolbar *self = user_data;
+ NautilusToolbar *self = user_data;
- if (event->button == 3) {
- /* right click */
- show_menu (self, GTK_WIDGET (button), event->button, event->time);
- return TRUE;
- }
+ if (event->button == 3)
+ {
+ /* right click */
+ show_menu (self, GTK_WIDGET (button), event->button, event->time);
+ return TRUE;
+ }
- if (event->button == 1) {
- schedule_menu_popup_timeout (self, GTK_WIDGET (button));
- }
+ if (event->button == 1)
+ {
+ schedule_menu_popup_timeout (self, GTK_WIDGET (button));
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
-navigation_button_release_cb (GtkButton *button,
+navigation_button_release_cb (GtkButton *button,
GdkEventButton *event,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusToolbar *self = user_data;
+ NautilusToolbar *self = user_data;
- unschedule_menu_popup_timeout (self);
+ unschedule_menu_popup_timeout (self);
- return FALSE;
+ return FALSE;
}
static gboolean
should_show_progress_info (NautilusProgressInfo *info)
{
-
- return nautilus_progress_info_get_total_elapsed_time (info) +
- nautilus_progress_info_get_remaining_time (info) > OPERATION_MINIMUM_TIME;
+ return nautilus_progress_info_get_total_elapsed_time (info) +
+ nautilus_progress_info_get_remaining_time (info) > OPERATION_MINIMUM_TIME;
}
-static GList*
+static GList *
get_filtered_progress_infos (NautilusToolbar *self)
{
- GList *l;
- GList *filtered_progress_infos;
- GList *progress_infos;
-
- progress_infos = nautilus_progress_info_manager_get_all_infos (self->priv->progress_manager);
- filtered_progress_infos = NULL;
-
- for (l = progress_infos; l != NULL; l = l->next) {
- if (should_show_progress_info (l->data)) {
- filtered_progress_infos = g_list_append (filtered_progress_infos, l->data);
- }
+ GList *l;
+ GList *filtered_progress_infos;
+ GList *progress_infos;
+
+ progress_infos = nautilus_progress_info_manager_get_all_infos (self->priv->progress_manager);
+ filtered_progress_infos = NULL;
+
+ for (l = progress_infos; l != NULL; l = l->next)
+ {
+ if (should_show_progress_info (l->data))
+ {
+ filtered_progress_infos = g_list_append (filtered_progress_infos, l->data);
}
+ }
- return filtered_progress_infos;
+ return filtered_progress_infos;
}
static gboolean
should_hide_operations_button (NautilusToolbar *self)
{
- GList *progress_infos;
- GList *l;
-
- progress_infos = get_filtered_progress_infos (self);
-
- for (l = progress_infos; l != NULL; l = l->next) {
- if (nautilus_progress_info_get_total_elapsed_time (l->data) +
- nautilus_progress_info_get_remaining_time (l->data) > OPERATION_MINIMUM_TIME &&
- !nautilus_progress_info_get_is_cancelled (l->data) &&
- !nautilus_progress_info_get_is_finished (l->data)) {
- return FALSE;
- }
+ GList *progress_infos;
+ GList *l;
+
+ progress_infos = get_filtered_progress_infos (self);
+
+ for (l = progress_infos; l != NULL; l = l->next)
+ {
+ if (nautilus_progress_info_get_total_elapsed_time (l->data) +
+ nautilus_progress_info_get_remaining_time (l->data) > OPERATION_MINIMUM_TIME &&
+ !nautilus_progress_info_get_is_cancelled (l->data) &&
+ !nautilus_progress_info_get_is_finished (l->data))
+ {
+ return FALSE;
}
+ }
- g_list_free (progress_infos);
+ g_list_free (progress_infos);
- return TRUE;
+ return TRUE;
}
static gboolean
on_remove_finished_operations_timeout (NautilusToolbar *self)
{
- nautilus_progress_info_manager_remove_finished_or_cancelled_infos (self->priv->progress_manager);
- if (should_hide_operations_button (self)) {
- gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->operations_revealer),
- FALSE);
- } else {
- update_operations (self);
- }
+ nautilus_progress_info_manager_remove_finished_or_cancelled_infos (self->priv->progress_manager);
+ if (should_hide_operations_button (self))
+ {
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->operations_revealer),
+ FALSE);
+ }
+ else
+ {
+ update_operations (self);
+ }
- self->priv->remove_finished_operations_timeout_id = 0;
+ self->priv->remove_finished_operations_timeout_id = 0;
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
}
static void
unschedule_remove_finished_operations (NautilusToolbar *self)
{
- if (self->priv->remove_finished_operations_timeout_id != 0) {
- g_source_remove (self->priv->remove_finished_operations_timeout_id);
- self->priv->remove_finished_operations_timeout_id = 0;
- }
+ if (self->priv->remove_finished_operations_timeout_id != 0)
+ {
+ g_source_remove (self->priv->remove_finished_operations_timeout_id);
+ self->priv->remove_finished_operations_timeout_id = 0;
+ }
}
static void
schedule_remove_finished_operations (NautilusToolbar *self)
{
- if (self->priv->remove_finished_operations_timeout_id == 0) {
- self->priv->remove_finished_operations_timeout_id =
- g_timeout_add_seconds (REMOVE_FINISHED_OPERATIONS_TIEMOUT,
- (GSourceFunc) on_remove_finished_operations_timeout,
- self);
- }
+ if (self->priv->remove_finished_operations_timeout_id == 0)
+ {
+ self->priv->remove_finished_operations_timeout_id =
+ g_timeout_add_seconds (REMOVE_FINISHED_OPERATIONS_TIEMOUT,
+ (GSourceFunc) on_remove_finished_operations_timeout,
+ self);
+ }
}
static void
remove_operations_button_attention_style (NautilusToolbar *self)
{
- GtkStyleContext *style_context;
+ GtkStyleContext *style_context;
- style_context = gtk_widget_get_style_context (self->priv->operations_button);
- gtk_style_context_remove_class (style_context,
- "nautilus-operations-button-needs-attention");
+ style_context = gtk_widget_get_style_context (self->priv->operations_button);
+ gtk_style_context_remove_class (style_context,
+ "nautilus-operations-button-needs-attention");
}
static gboolean
on_remove_operations_button_attention_style_timeout (NautilusToolbar *self)
{
- remove_operations_button_attention_style (self);
- self->priv->operations_button_attention_timeout_id = 0;
+ remove_operations_button_attention_style (self);
+ self->priv->operations_button_attention_timeout_id = 0;
- return G_SOURCE_REMOVE;
+ return G_SOURCE_REMOVE;
}
static void
unschedule_operations_button_attention_style (NautilusToolbar *self)
{
- if (self->priv->operations_button_attention_timeout_id!= 0) {
- g_source_remove (self->priv->operations_button_attention_timeout_id);
- self->priv->operations_button_attention_timeout_id = 0;
- }
+ if (self->priv->operations_button_attention_timeout_id != 0)
+ {
+ g_source_remove (self->priv->operations_button_attention_timeout_id);
+ self->priv->operations_button_attention_timeout_id = 0;
+ }
}
static void
add_operations_button_attention_style (NautilusToolbar *self)
{
- GtkStyleContext *style_context;
+ GtkStyleContext *style_context;
- style_context = gtk_widget_get_style_context (self->priv->operations_button);
+ style_context = gtk_widget_get_style_context (self->priv->operations_button);
- unschedule_operations_button_attention_style (self);
- remove_operations_button_attention_style (self);
+ unschedule_operations_button_attention_style (self);
+ remove_operations_button_attention_style (self);
- gtk_style_context_add_class (style_context,
- "nautilus-operations-button-needs-attention");
- self->priv->operations_button_attention_timeout_id = g_timeout_add (NEEDS_ATTENTION_ANIMATION_TIMEOUT,
- (GSourceFunc) on_remove_operations_button_attention_style_timeout,
- self);
+ gtk_style_context_add_class (style_context,
+ "nautilus-operations-button-needs-attention");
+ self->priv->operations_button_attention_timeout_id = g_timeout_add (NEEDS_ATTENTION_ANIMATION_TIMEOUT,
+ (GSourceFunc) on_remove_operations_button_attention_style_timeout,
+ self);
}
static void
on_progress_info_cancelled (NautilusToolbar *self)
{
- /* Update the pie chart progress */
- gtk_widget_queue_draw (self->priv->operations_icon);
+ /* Update the pie chart progress */
+ gtk_widget_queue_draw (self->priv->operations_icon);
- if (!nautilus_progress_manager_has_viewers (self->priv->progress_manager)) {
- schedule_remove_finished_operations (self);
- }
+ if (!nautilus_progress_manager_has_viewers (self->priv->progress_manager))
+ {
+ schedule_remove_finished_operations (self);
+ }
}
static void
on_progress_info_progress_changed (NautilusToolbar *self)
{
- /* Update the pie chart progress */
- gtk_widget_queue_draw (self->priv->operations_icon);
+ /* Update the pie chart progress */
+ gtk_widget_queue_draw (self->priv->operations_icon);
}
static void
on_progress_info_finished (NautilusToolbar *self,
NautilusProgressInfo *info)
{
- gchar *main_label;
- GFile *folder_to_open;
-
- /* Update the pie chart progress */
- gtk_widget_queue_draw (self->priv->operations_icon);
-
- if (!nautilus_progress_manager_has_viewers (self->priv->progress_manager)) {
- schedule_remove_finished_operations (self);
- }
-
- folder_to_open = nautilus_progress_info_get_destination (info);
- /* If destination is null, don't show a notification. This happens when the
- * operation is a trash operation, which we already show a diferent kind of
- * notification */
- if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button)) &&
- folder_to_open != NULL) {
- add_operations_button_attention_style (self);
- main_label = nautilus_progress_info_get_status (info);
- nautilus_window_show_operation_notification (self->priv->window,
- main_label,
- folder_to_open);
- g_free (main_label);
- }
-
- g_clear_object (&folder_to_open);
+ gchar *main_label;
+ GFile *folder_to_open;
+
+ /* Update the pie chart progress */
+ gtk_widget_queue_draw (self->priv->operations_icon);
+
+ if (!nautilus_progress_manager_has_viewers (self->priv->progress_manager))
+ {
+ schedule_remove_finished_operations (self);
+ }
+
+ folder_to_open = nautilus_progress_info_get_destination (info);
+ /* If destination is null, don't show a notification. This happens when the
+ * operation is a trash operation, which we already show a diferent kind of
+ * notification */
+ if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button)) &&
+ folder_to_open != NULL)
+ {
+ add_operations_button_attention_style (self);
+ main_label = nautilus_progress_info_get_status (info);
+ nautilus_window_show_operation_notification (self->priv->window,
+ main_label,
+ folder_to_open);
+ g_free (main_label);
+ }
+
+ g_clear_object (&folder_to_open);
}
static void
disconnect_progress_infos (NautilusToolbar *self)
{
- GList *progress_infos;
- GList *l;
-
- progress_infos = nautilus_progress_info_manager_get_all_infos (self->priv->progress_manager);
- for (l = progress_infos; l != NULL; l = l->next) {
- g_signal_handlers_disconnect_by_data (l->data, self);
- }
+ GList *progress_infos;
+ GList *l;
+
+ progress_infos = nautilus_progress_info_manager_get_all_infos (self->priv->progress_manager);
+ for (l = progress_infos; l != NULL; l = l->next)
+ {
+ g_signal_handlers_disconnect_by_data (l->data, self);
+ }
}
static void
update_operations (NautilusToolbar *self)
{
- GList *progress_infos;
- GList *l;
- GtkWidget *progress;
- gboolean should_show_progress_button = FALSE;
-
- gtk_container_foreach (GTK_CONTAINER (self->priv->operations_container),
- (GtkCallback) gtk_widget_destroy,
- NULL);
-
- disconnect_progress_infos (self);
-
- progress_infos = get_filtered_progress_infos (self);
- for (l = progress_infos; l != NULL; l = l->next) {
- should_show_progress_button = should_show_progress_button ||
- should_show_progress_info (l->data);
-
- g_signal_connect_swapped (l->data, "finished",
- G_CALLBACK (on_progress_info_finished), self);
- g_signal_connect_swapped (l->data, "cancelled",
- G_CALLBACK (on_progress_info_cancelled), self);
- g_signal_connect_swapped (l->data, "progress-changed",
- G_CALLBACK (on_progress_info_progress_changed), self);
- progress = nautilus_progress_info_widget_new (l->data);
- gtk_box_pack_start (GTK_BOX (self->priv->operations_container),
- progress,
- FALSE, FALSE, 0);
- }
+ GList *progress_infos;
+ GList *l;
+ GtkWidget *progress;
+ gboolean should_show_progress_button = FALSE;
+
+ gtk_container_foreach (GTK_CONTAINER (self->priv->operations_container),
+ (GtkCallback) gtk_widget_destroy,
+ NULL);
+
+ disconnect_progress_infos (self);
+
+ progress_infos = get_filtered_progress_infos (self);
+ for (l = progress_infos; l != NULL; l = l->next)
+ {
+ should_show_progress_button = should_show_progress_button ||
+ should_show_progress_info (l->data);
+
+ g_signal_connect_swapped (l->data, "finished",
+ G_CALLBACK (on_progress_info_finished), self);
+ g_signal_connect_swapped (l->data, "cancelled",
+ G_CALLBACK (on_progress_info_cancelled), self);
+ g_signal_connect_swapped (l->data, "progress-changed",
+ G_CALLBACK (on_progress_info_progress_changed), self);
+ progress = nautilus_progress_info_widget_new (l->data);
+ gtk_box_pack_start (GTK_BOX (self->priv->operations_container),
+ progress,
+ FALSE, FALSE, 0);
+ }
+
+ g_list_free (progress_infos);
+
+ if (should_show_progress_button &&
+ !gtk_revealer_get_reveal_child (GTK_REVEALER (self->priv->operations_revealer)))
+ {
+ add_operations_button_attention_style (self);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->operations_revealer),
+ TRUE);
+ gtk_widget_queue_draw (self->priv->operations_icon);
- g_list_free (progress_infos);
-
- if (should_show_progress_button &&
- !gtk_revealer_get_reveal_child (GTK_REVEALER (self->priv->operations_revealer))) {
- add_operations_button_attention_style (self);
- gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->operations_revealer),
- TRUE);
- gtk_widget_queue_draw (self->priv->operations_icon);
-
- /* Show the popover at start to increase visibility.
- * Check whether the toolbar is visible or not before showing the
- * popover. This can happens if the window has the disables-chrome
- * property set. */
- if (gtk_widget_is_visible (GTK_WIDGET (self))) {
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->operations_button),
- TRUE);
- }
+ /* Show the popover at start to increase visibility.
+ * Check whether the toolbar is visible or not before showing the
+ * popover. This can happens if the window has the disables-chrome
+ * property set. */
+ if (gtk_widget_is_visible (GTK_WIDGET (self)))
+ {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->priv->operations_button),
+ TRUE);
}
+ }
- /* Since we removed the info widgets, we need to restore the focus */
- if (gtk_widget_get_visible (self->priv->operations_popover)) {
- gtk_widget_grab_focus (self->priv->operations_popover);
- }
+ /* Since we removed the info widgets, we need to restore the focus */
+ if (gtk_widget_get_visible (self->priv->operations_popover))
+ {
+ gtk_widget_grab_focus (self->priv->operations_popover);
+ }
}
static gboolean
on_progress_info_started_timeout (NautilusToolbar *self)
{
- GList *progress_infos;
- GList *filtered_progress_infos;
-
- update_operations (self);
-
- /* In case we didn't show the operations button because the operation total
- * time stimation is not good enough, update again to make sure we don't miss
- * a long time operation because of that */
-
- progress_infos = nautilus_progress_info_manager_get_all_infos (self->priv->progress_manager);
- filtered_progress_infos = get_filtered_progress_infos (self);
- if (!nautilus_progress_manager_are_all_infos_finished_or_cancelled (self->priv->progress_manager) &&
- g_list_length (progress_infos) != g_list_length (filtered_progress_infos)) {
- g_list_free (filtered_progress_infos);
- return G_SOURCE_CONTINUE;
- } else {
- g_list_free (filtered_progress_infos);
- self->priv->start_operations_timeout_id = 0;
- return G_SOURCE_REMOVE;
- }
+ GList *progress_infos;
+ GList *filtered_progress_infos;
+
+ update_operations (self);
+
+ /* In case we didn't show the operations button because the operation total
+ * time stimation is not good enough, update again to make sure we don't miss
+ * a long time operation because of that */
+
+ progress_infos = nautilus_progress_info_manager_get_all_infos (self->priv->progress_manager);
+ filtered_progress_infos = get_filtered_progress_infos (self);
+ if (!nautilus_progress_manager_are_all_infos_finished_or_cancelled (self->priv->progress_manager) &&
+ g_list_length (progress_infos) != g_list_length (filtered_progress_infos))
+ {
+ g_list_free (filtered_progress_infos);
+ return G_SOURCE_CONTINUE;
+ }
+ else
+ {
+ g_list_free (filtered_progress_infos);
+ self->priv->start_operations_timeout_id = 0;
+ return G_SOURCE_REMOVE;
+ }
}
static void
schedule_operations_start (NautilusToolbar *self)
{
- if (self->priv->start_operations_timeout_id == 0) {
- /* Timeout is a little more than what we require for a stimated operation
- * total time, to make sure the stimated total time is correct */
- self->priv->start_operations_timeout_id =
- g_timeout_add (SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE * 1000 + 500,
- (GSourceFunc) on_progress_info_started_timeout,
- self);
- }
+ if (self->priv->start_operations_timeout_id == 0)
+ {
+ /* Timeout is a little more than what we require for a stimated operation
+ * total time, to make sure the stimated total time is correct */
+ self->priv->start_operations_timeout_id =
+ g_timeout_add (SECONDS_NEEDED_FOR_APROXIMATE_TRANSFER_RATE * 1000 + 500,
+ (GSourceFunc) on_progress_info_started_timeout,
+ self);
+ }
}
static void
unschedule_operations_start (NautilusToolbar *self)
{
- if (self->priv->start_operations_timeout_id != 0) {
- g_source_remove (self->priv->start_operations_timeout_id);
- self->priv->start_operations_timeout_id = 0;
- }
+ if (self->priv->start_operations_timeout_id != 0)
+ {
+ g_source_remove (self->priv->start_operations_timeout_id);
+ self->priv->start_operations_timeout_id = 0;
+ }
}
static void
on_progress_info_started (NautilusProgressInfo *info,
NautilusToolbar *self)
{
- g_signal_handlers_disconnect_by_data (info, self);
- schedule_operations_start (self);
+ g_signal_handlers_disconnect_by_data (info, self);
+ schedule_operations_start (self);
}
static void
@@ -657,8 +707,8 @@ on_new_progress_info (NautilusProgressInfoManager *manager,
NautilusProgressInfo *info,
NautilusToolbar *self)
{
- g_signal_connect (info, "started",
- G_CALLBACK (on_progress_info_started), self);
+ g_signal_connect (info, "started",
+ G_CALLBACK (on_progress_info_started), self);
}
static void
@@ -666,96 +716,108 @@ on_operations_icon_draw (GtkWidget *widget,
cairo_t *cr,
NautilusToolbar *self)
{
- gfloat elapsed_progress = 0;
- gint remaining_progress = 0;
- gint total_progress;
- gdouble ratio;
- GList *progress_infos;
- GList *l;
- guint width;
- guint height;
- gboolean all_cancelled;
- GdkRGBA background;
- GdkRGBA foreground;
- GtkStyleContext *style_context;
-
- style_context = gtk_widget_get_style_context (widget);
- gtk_style_context_get_color (style_context, gtk_widget_get_state_flags (widget), &foreground);
- background = foreground;
- background.alpha *= 0.3;
-
- all_cancelled = TRUE;
- progress_infos = get_filtered_progress_infos (self);
- for (l = progress_infos; l != NULL; l = l->next) {
- if (!nautilus_progress_info_get_is_cancelled (l->data)) {
- all_cancelled = FALSE;
- remaining_progress += nautilus_progress_info_get_remaining_time (l->data);
- elapsed_progress += nautilus_progress_info_get_elapsed_time (l->data);
- }
+ gfloat elapsed_progress = 0;
+ gint remaining_progress = 0;
+ gint total_progress;
+ gdouble ratio;
+ GList *progress_infos;
+ GList *l;
+ guint width;
+ guint height;
+ gboolean all_cancelled;
+ GdkRGBA background;
+ GdkRGBA foreground;
+ GtkStyleContext *style_context;
+
+ style_context = gtk_widget_get_style_context (widget);
+ gtk_style_context_get_color (style_context, gtk_widget_get_state_flags (widget), &foreground);
+ background = foreground;
+ background.alpha *= 0.3;
+
+ all_cancelled = TRUE;
+ progress_infos = get_filtered_progress_infos (self);
+ for (l = progress_infos; l != NULL; l = l->next)
+ {
+ if (!nautilus_progress_info_get_is_cancelled (l->data))
+ {
+ all_cancelled = FALSE;
+ remaining_progress += nautilus_progress_info_get_remaining_time (l->data);
+ elapsed_progress += nautilus_progress_info_get_elapsed_time (l->data);
}
+ }
- g_list_free (progress_infos);
+ g_list_free (progress_infos);
- total_progress = remaining_progress + elapsed_progress;
+ total_progress = remaining_progress + elapsed_progress;
- if (all_cancelled) {
- ratio = 1.0;
- } else {
- if (total_progress > 0) {
- ratio = MAX (0.05, elapsed_progress / total_progress);
- } else {
- ratio = 0.05;
- }
+ if (all_cancelled)
+ {
+ ratio = 1.0;
+ }
+ else
+ {
+ if (total_progress > 0)
+ {
+ ratio = MAX (0.05, elapsed_progress / total_progress);
}
-
-
- width = gtk_widget_get_allocated_width (widget);
- height = gtk_widget_get_allocated_height (widget);
-
- gdk_cairo_set_source_rgba(cr, &background);
- cairo_arc (cr,
- width / 2.0, height / 2.0,
- MIN (width, height) / 2.0,
- 0, 2 *G_PI);
- cairo_fill (cr);
- cairo_move_to (cr, width / 2.0, height / 2.0);
- gdk_cairo_set_source_rgba (cr, &foreground);
- cairo_arc (cr,
- width / 2.0, height / 2.0,
- MIN (width, height) / 2.0,
- -G_PI / 2.0, ratio * 2 * G_PI - G_PI / 2.0);
-
- cairo_fill (cr);
+ else
+ {
+ ratio = 0.05;
+ }
+ }
+
+
+ width = gtk_widget_get_allocated_width (widget);
+ height = gtk_widget_get_allocated_height (widget);
+
+ gdk_cairo_set_source_rgba (cr, &background);
+ cairo_arc (cr,
+ width / 2.0, height / 2.0,
+ MIN (width, height) / 2.0,
+ 0, 2 * G_PI);
+ cairo_fill (cr);
+ cairo_move_to (cr, width / 2.0, height / 2.0);
+ gdk_cairo_set_source_rgba (cr, &foreground);
+ cairo_arc (cr,
+ width / 2.0, height / 2.0,
+ MIN (width, height) / 2.0,
+ -G_PI / 2.0, ratio * 2 * G_PI - G_PI / 2.0);
+
+ cairo_fill (cr);
}
static void
on_operations_button_toggled (NautilusToolbar *self,
GtkToggleButton *button)
{
- if (gtk_toggle_button_get_active (button)) {
- unschedule_remove_finished_operations (self);
- nautilus_progress_manager_add_viewer (self->priv->progress_manager,
- G_OBJECT (self));
- }
- else {
- nautilus_progress_manager_remove_viewer (self->priv->progress_manager,
- G_OBJECT (self));
- }
+ if (gtk_toggle_button_get_active (button))
+ {
+ unschedule_remove_finished_operations (self);
+ nautilus_progress_manager_add_viewer (self->priv->progress_manager,
+ G_OBJECT (self));
+ }
+ else
+ {
+ nautilus_progress_manager_remove_viewer (self->priv->progress_manager,
+ G_OBJECT (self));
+ }
}
static void
on_progress_has_viewers_changed (NautilusProgressInfoManager *manager,
NautilusToolbar *self)
{
- if (nautilus_progress_manager_has_viewers (manager)) {
- unschedule_remove_finished_operations (self);
- return;
- }
+ if (nautilus_progress_manager_has_viewers (manager))
+ {
+ unschedule_remove_finished_operations (self);
+ return;
+ }
- if (nautilus_progress_manager_are_all_infos_finished_or_cancelled (manager)) {
- unschedule_remove_finished_operations (self);
- schedule_remove_finished_operations (self);
- }
+ if (nautilus_progress_manager_are_all_infos_finished_or_cancelled (manager))
+ {
+ unschedule_remove_finished_operations (self);
+ schedule_remove_finished_operations (self);
+ }
}
static void
@@ -765,273 +827,290 @@ update_menu_item (GtkWidget *menu_item,
gboolean enabled,
char *label)
{
- GAction *action;
- GValue val = G_VALUE_INIT;
-
- /* Activate/deactivate */
- action = g_action_map_lookup_action (G_ACTION_MAP (self->priv->window), action_name);
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
-
- /* Set the text of the menu item. Can't use gtk_button_set_label here as
- * we need to set the text property, not the label. There's no equivalent
- * gtk_model_button_set_text function (refer to #766083 for discussion
- * on adding a set_text function)
- */
- g_value_init (&val, G_TYPE_STRING);
- g_value_set_string (&val, label);
- g_object_set_property (G_OBJECT (menu_item), "text", &val);
- g_value_unset (&val);
+ GAction *action;
+ GValue val = G_VALUE_INIT;
+
+ /* Activate/deactivate */
+ action = g_action_map_lookup_action (G_ACTION_MAP (self->priv->window), action_name);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
+
+ /* Set the text of the menu item. Can't use gtk_button_set_label here as
+ * we need to set the text property, not the label. There's no equivalent
+ * gtk_model_button_set_text function (refer to #766083 for discussion
+ * on adding a set_text function)
+ */
+ g_value_init (&val, G_TYPE_STRING);
+ g_value_set_string (&val, label);
+ g_object_set_property (G_OBJECT (menu_item), "text", &val);
+ g_value_unset (&val);
}
static void
undo_manager_changed (NautilusToolbar *self)
{
- NautilusFileUndoInfo *info;
- NautilusFileUndoManagerState undo_state;
- gboolean undo_active;
- gboolean redo_active;
- g_autofree gchar *undo_label = NULL;
- g_autofree gchar *redo_label = NULL;
- g_autofree gchar *undo_description = NULL;
- g_autofree gchar *redo_description = NULL;
- gboolean is_undo;
-
- /* Look up the last action from the undo manager, and get the text that
- * describes it, e.g. "Undo Create Folder"/"Redo Create Folder"
+ NautilusFileUndoInfo *info;
+ NautilusFileUndoManagerState undo_state;
+ gboolean undo_active;
+ gboolean redo_active;
+ g_autofree gchar *undo_label = NULL;
+ g_autofree gchar *redo_label = NULL;
+ g_autofree gchar *undo_description = NULL;
+ g_autofree gchar *redo_description = NULL;
+ gboolean is_undo;
+
+ /* Look up the last action from the undo manager, and get the text that
+ * describes it, e.g. "Undo Create Folder"/"Redo Create Folder"
+ */
+ info = nautilus_file_undo_manager_get_action ();
+ undo_state = nautilus_file_undo_manager_get_state ();
+ undo_active = redo_active = FALSE;
+ if (info != NULL && undo_state > NAUTILUS_FILE_UNDO_MANAGER_STATE_NONE)
+ {
+ is_undo = undo_state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
+
+ /* The last action can either be undone/redone. Activate the corresponding
+ * menu item and deactivate the other
*/
- info = nautilus_file_undo_manager_get_action ();
- undo_state = nautilus_file_undo_manager_get_state ();
- undo_active = redo_active = FALSE;
- if (info != NULL && undo_state > NAUTILUS_FILE_UNDO_MANAGER_STATE_NONE) {
- is_undo = undo_state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO;
-
- /* The last action can either be undone/redone. Activate the corresponding
- * menu item and deactivate the other
- */
- undo_active = is_undo;
- redo_active = !is_undo;
- nautilus_file_undo_info_get_strings (info, &undo_label, &undo_description,
- &redo_label, &redo_description);
- }
-
- /* Set the label of the undo and redo menu items, and activate them appropriately
- */
- undo_label = undo_active && undo_label != NULL ? undo_label : g_strdup (_("_Undo"));
- update_menu_item (self->priv->undo_button, self, "undo", undo_active, undo_label);
-
- redo_label = redo_active && redo_label != NULL ? redo_label : g_strdup (_("_Redo"));
- update_menu_item (self->priv->redo_button, self, "redo", redo_active, redo_label);
+ undo_active = is_undo;
+ redo_active = !is_undo;
+ nautilus_file_undo_info_get_strings (info, &undo_label, &undo_description,
+ &redo_label, &redo_description);
+ }
+
+ /* Set the label of the undo and redo menu items, and activate them appropriately
+ */
+ undo_label = undo_active && undo_label != NULL ? undo_label : g_strdup (_("_Undo"));
+ update_menu_item (self->priv->undo_button, self, "undo", undo_active, undo_label);
+
+ redo_label = redo_active && redo_label != NULL ? redo_label : g_strdup (_("_Redo"));
+ update_menu_item (self->priv->redo_button, self, "redo", redo_active, redo_label);
}
static void
nautilus_toolbar_init (NautilusToolbar *self)
{
- GtkBuilder *builder;
- GtkWidget *menu_popover;
-
- self->priv = nautilus_toolbar_get_instance_private (self);
- gtk_widget_init_template (GTK_WIDGET (self));
-
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-menu.ui");
- menu_popover = GTK_WIDGET (gtk_builder_get_object (builder, "menu_popover"));
- self->priv->view_menu_zoom_section = GTK_WIDGET (gtk_builder_get_object (builder, "view_menu_zoom_section"));
- self->priv->view_menu_undo_redo_section = GTK_WIDGET (gtk_builder_get_object (builder, "view_menu_undo_redo_section"));
- self->priv->view_menu_extended_section = GTK_WIDGET (gtk_builder_get_object (builder, "view_menu_extended_section"));
- self->priv->undo_button = GTK_WIDGET (gtk_builder_get_object (builder, "undo"));
- self->priv->redo_button = GTK_WIDGET (gtk_builder_get_object (builder, "redo"));
- gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->priv->view_button), menu_popover);
- g_object_unref (builder);
-
- self->priv->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL);
- gtk_container_add (GTK_CONTAINER (self->priv->path_bar_container),
- self->priv->path_bar);
-
- self->priv->location_entry = nautilus_location_entry_new ();
- gtk_container_add (GTK_CONTAINER (self->priv->location_entry_container),
- self->priv->location_entry);
-
- self->priv->progress_manager = nautilus_progress_info_manager_dup_singleton ();
- g_signal_connect (self->priv->progress_manager, "new-progress-info",
- G_CALLBACK (on_new_progress_info), self);
- g_signal_connect (self->priv->progress_manager, "has-viewers-changed",
- G_CALLBACK (on_progress_has_viewers_changed), self);
-
- update_operations (self);
-
- g_object_set_data (G_OBJECT (self->priv->back_button), "nav-direction",
- GUINT_TO_POINTER (NAUTILUS_NAVIGATION_DIRECTION_BACK));
- g_object_set_data (G_OBJECT (self->priv->forward_button), "nav-direction",
- GUINT_TO_POINTER (NAUTILUS_NAVIGATION_DIRECTION_FORWARD));
- g_signal_connect (self->priv->back_button, "button-press-event",
- G_CALLBACK (navigation_button_press_cb), self);
- g_signal_connect (self->priv->back_button, "button-release-event",
- G_CALLBACK (navigation_button_release_cb), self);
- g_signal_connect (self->priv->forward_button, "button-press-event",
- G_CALLBACK (navigation_button_press_cb), self);
- g_signal_connect (self->priv->forward_button, "button-release-event",
- G_CALLBACK (navigation_button_release_cb), self);
- g_signal_connect (self->priv->operations_popover, "show",
- (GCallback) gtk_widget_grab_focus, NULL);
- g_signal_connect_swapped (self->priv->operations_popover, "closed",
- (GCallback) gtk_widget_grab_focus, self);
-
- gtk_widget_show_all (GTK_WIDGET (self));
- toolbar_update_appearance (self);
+ GtkBuilder *builder;
+ GtkWidget *menu_popover;
+
+ self->priv = nautilus_toolbar_get_instance_private (self);
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-menu.ui");
+ menu_popover = GTK_WIDGET (gtk_builder_get_object (builder, "menu_popover"));
+ self->priv->view_menu_zoom_section = GTK_WIDGET (gtk_builder_get_object (builder, "view_menu_zoom_section"));
+ self->priv->view_menu_undo_redo_section = GTK_WIDGET (gtk_builder_get_object (builder, "view_menu_undo_redo_section"));
+ self->priv->view_menu_extended_section = GTK_WIDGET (gtk_builder_get_object (builder, "view_menu_extended_section"));
+ self->priv->undo_button = GTK_WIDGET (gtk_builder_get_object (builder, "undo"));
+ self->priv->redo_button = GTK_WIDGET (gtk_builder_get_object (builder, "redo"));
+ gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->priv->view_button), menu_popover);
+ g_object_unref (builder);
+
+ self->priv->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL);
+ gtk_container_add (GTK_CONTAINER (self->priv->path_bar_container),
+ self->priv->path_bar);
+
+ self->priv->location_entry = nautilus_location_entry_new ();
+ gtk_container_add (GTK_CONTAINER (self->priv->location_entry_container),
+ self->priv->location_entry);
+
+ self->priv->progress_manager = nautilus_progress_info_manager_dup_singleton ();
+ g_signal_connect (self->priv->progress_manager, "new-progress-info",
+ G_CALLBACK (on_new_progress_info), self);
+ g_signal_connect (self->priv->progress_manager, "has-viewers-changed",
+ G_CALLBACK (on_progress_has_viewers_changed), self);
+
+ update_operations (self);
+
+ g_object_set_data (G_OBJECT (self->priv->back_button), "nav-direction",
+ GUINT_TO_POINTER (NAUTILUS_NAVIGATION_DIRECTION_BACK));
+ g_object_set_data (G_OBJECT (self->priv->forward_button), "nav-direction",
+ GUINT_TO_POINTER (NAUTILUS_NAVIGATION_DIRECTION_FORWARD));
+ g_signal_connect (self->priv->back_button, "button-press-event",
+ G_CALLBACK (navigation_button_press_cb), self);
+ g_signal_connect (self->priv->back_button, "button-release-event",
+ G_CALLBACK (navigation_button_release_cb), self);
+ g_signal_connect (self->priv->forward_button, "button-press-event",
+ G_CALLBACK (navigation_button_press_cb), self);
+ g_signal_connect (self->priv->forward_button, "button-release-event",
+ G_CALLBACK (navigation_button_release_cb), self);
+ g_signal_connect (self->priv->operations_popover, "show",
+ (GCallback) gtk_widget_grab_focus, NULL);
+ g_signal_connect_swapped (self->priv->operations_popover, "closed",
+ (GCallback) gtk_widget_grab_focus, self);
+
+ gtk_widget_show_all (GTK_WIDGET (self));
+ toolbar_update_appearance (self);
}
void
nautilus_toolbar_on_window_constructed (NautilusToolbar *self)
{
- /* undo_manager_changed manipulates the window actions, so set it up
- * after the window and it's actions have been constructed
- */
- g_signal_connect_object (nautilus_file_undo_manager_get (),
- "undo-changed",
- G_CALLBACK (undo_manager_changed),
- self,
- G_CONNECT_SWAPPED);
-
- undo_manager_changed (self);
+ /* undo_manager_changed manipulates the window actions, so set it up
+ * after the window and it's actions have been constructed
+ */
+ g_signal_connect_object (nautilus_file_undo_manager_get (),
+ "undo-changed",
+ G_CALLBACK (undo_manager_changed),
+ self,
+ G_CONNECT_SWAPPED);
+
+ undo_manager_changed (self);
}
static void
-nautilus_toolbar_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_toolbar_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
-
- switch (property_id) {
- case PROP_SHOW_LOCATION_ENTRY:
- g_value_set_boolean (value, self->priv->show_location_entry);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
+
+ switch (property_id)
+ {
+ case PROP_SHOW_LOCATION_ENTRY:
+ {
+ g_value_set_boolean (value, self->priv->show_location_entry);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_toolbar_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_toolbar_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
-
- switch (property_id) {
- case PROP_WINDOW:
- self->priv->window = g_value_get_object (value);
- break;
- case PROP_SHOW_LOCATION_ENTRY:
- nautilus_toolbar_set_show_location_entry (self, g_value_get_boolean (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ NautilusToolbar *self = NAUTILUS_TOOLBAR (object);
+
+ switch (property_id)
+ {
+ case PROP_WINDOW:
+ {
+ self->priv->window = g_value_get_object (value);
+ }
+ break;
+
+ case PROP_SHOW_LOCATION_ENTRY:
+ {
+ nautilus_toolbar_set_show_location_entry (self, g_value_get_boolean (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_toolbar_finalize (GObject *obj)
{
- NautilusToolbar *self = NAUTILUS_TOOLBAR (obj);
+ NautilusToolbar *self = NAUTILUS_TOOLBAR (obj);
- g_signal_handlers_disconnect_by_func (nautilus_preferences,
- toolbar_update_appearance, self);
- disconnect_progress_infos (self);
- unschedule_menu_popup_timeout (self);
- unschedule_remove_finished_operations (self);
- unschedule_operations_start (self);
- unschedule_operations_button_attention_style (self);
+ g_signal_handlers_disconnect_by_func (nautilus_preferences,
+ toolbar_update_appearance, self);
+ disconnect_progress_infos (self);
+ unschedule_menu_popup_timeout (self);
+ unschedule_remove_finished_operations (self);
+ unschedule_operations_start (self);
+ unschedule_operations_button_attention_style (self);
- g_signal_handlers_disconnect_by_data (self->priv->progress_manager, self);
- g_clear_object (&self->priv->progress_manager);
+ g_signal_handlers_disconnect_by_data (self->priv->progress_manager, self);
+ g_clear_object (&self->priv->progress_manager);
- G_OBJECT_CLASS (nautilus_toolbar_parent_class)->finalize (obj);
+ G_OBJECT_CLASS (nautilus_toolbar_parent_class)->finalize (obj);
}
static void
nautilus_toolbar_class_init (NautilusToolbarClass *klass)
{
- GObjectClass *oclass;
- GtkWidgetClass *widget_class;
-
- widget_class = GTK_WIDGET_CLASS (klass);
- oclass = G_OBJECT_CLASS (klass);
- oclass->get_property = nautilus_toolbar_get_property;
- oclass->set_property = nautilus_toolbar_set_property;
- oclass->finalize = nautilus_toolbar_finalize;
-
- properties[PROP_WINDOW] =
- g_param_spec_object ("window",
- "The NautilusWindow",
- "The NautilusWindow this toolbar is part of",
- NAUTILUS_TYPE_WINDOW,
- G_PARAM_WRITABLE |
- G_PARAM_STATIC_STRINGS);
- properties[PROP_SHOW_LOCATION_ENTRY] =
- g_param_spec_boolean ("show-location-entry",
- "Whether to show the location entry",
- "Whether to show the location entry instead of the pathbar",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
-
- gtk_widget_class_set_template_from_resource (widget_class,
- "/org/gnome/nautilus/ui/nautilus-toolbar.ui");
-
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_button);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_icon);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_popover);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_container);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_revealer);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, view_button);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, view_toggle_button);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, view_toggle_icon);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, path_bar_container);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, location_entry_container);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, back_button);
- gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, forward_button);
-
- gtk_widget_class_bind_template_callback (widget_class, on_operations_icon_draw);
- gtk_widget_class_bind_template_callback (widget_class, on_operations_button_toggled);
+ GObjectClass *oclass;
+ GtkWidgetClass *widget_class;
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ oclass = G_OBJECT_CLASS (klass);
+ oclass->get_property = nautilus_toolbar_get_property;
+ oclass->set_property = nautilus_toolbar_set_property;
+ oclass->finalize = nautilus_toolbar_finalize;
+
+ properties[PROP_WINDOW] =
+ g_param_spec_object ("window",
+ "The NautilusWindow",
+ "The NautilusWindow this toolbar is part of",
+ NAUTILUS_TYPE_WINDOW,
+ G_PARAM_WRITABLE |
+ G_PARAM_STATIC_STRINGS);
+ properties[PROP_SHOW_LOCATION_ENTRY] =
+ g_param_spec_boolean ("show-location-entry",
+ "Whether to show the location entry",
+ "Whether to show the location entry instead of the pathbar",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/nautilus/ui/nautilus-toolbar.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_button);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_icon);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_popover);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_container);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, operations_revealer);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, view_button);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, view_toggle_button);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, view_toggle_icon);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, path_bar_container);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, location_entry_container);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, back_button);
+ gtk_widget_class_bind_template_child_private (widget_class, NautilusToolbar, forward_button);
+
+ gtk_widget_class_bind_template_callback (widget_class, on_operations_icon_draw);
+ gtk_widget_class_bind_template_callback (widget_class, on_operations_button_toggled);
}
GtkWidget *
nautilus_toolbar_new ()
{
- return g_object_new (NAUTILUS_TYPE_TOOLBAR,
- "show-close-button", TRUE,
- "custom-title", gtk_label_new (NULL),
- "valign", GTK_ALIGN_CENTER,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_TOOLBAR,
+ "show-close-button", TRUE,
+ "custom-title", gtk_label_new (NULL),
+ "valign", GTK_ALIGN_CENTER,
+ NULL);
}
GtkWidget *
nautilus_toolbar_get_path_bar (NautilusToolbar *self)
{
- return self->priv->path_bar;
+ return self->priv->path_bar;
}
GtkWidget *
nautilus_toolbar_get_location_entry (NautilusToolbar *self)
{
- return self->priv->location_entry;
+ return self->priv->location_entry;
}
void
nautilus_toolbar_set_show_location_entry (NautilusToolbar *self,
- gboolean show_location_entry)
+ gboolean show_location_entry)
{
- if (show_location_entry != self->priv->show_location_entry) {
- self->priv->show_location_entry = show_location_entry;
- toolbar_update_appearance (self);
+ if (show_location_entry != self->priv->show_location_entry)
+ {
+ self->priv->show_location_entry = show_location_entry;
+ toolbar_update_appearance (self);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_LOCATION_ENTRY]);
- }
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_LOCATION_ENTRY]);
+ }
}
static gboolean
@@ -1040,29 +1119,32 @@ nautilus_toolbar_view_toggle_icon_transform_to (GBinding *binding,
GValue *to_value,
gpointer user_data)
{
- GIcon *icon;
+ GIcon *icon;
- icon = g_value_get_object (from_value);
+ icon = g_value_get_object (from_value);
- /* As per design decision, we let the previous used icon if no
- * view menu is available */
- if (icon) {
- g_value_set_object (to_value, icon);
- }
+ /* As per design decision, we let the previous used icon if no
+ * view menu is available */
+ if (icon)
+ {
+ g_value_set_object (to_value, icon);
+ }
- return TRUE;
+ return TRUE;
}
static void
container_remove_all_children (GtkContainer *container)
{
- GList *children;
- GList *child;
-
- children = gtk_container_get_children (container);
- for (child = children; child != NULL; child = g_list_next (child))
- gtk_container_remove (container, GTK_WIDGET (child->data));
- g_list_free (children);
+ GList *children;
+ GList *child;
+
+ children = gtk_container_get_children (container);
+ for (child = children; child != NULL; child = g_list_next (child))
+ {
+ gtk_container_remove (container, GTK_WIDGET (child->data));
+ }
+ g_list_free (children);
}
static void
@@ -1070,68 +1152,78 @@ on_slot_toolbar_menu_sections_changed (NautilusToolbar *toolbar,
GParamSpec *param,
NautilusWindowSlot *slot)
{
- NautilusToolbarMenuSections *new_sections;
+ NautilusToolbarMenuSections *new_sections;
- container_remove_all_children (GTK_CONTAINER (toolbar->priv->view_menu_zoom_section));
- container_remove_all_children (GTK_CONTAINER (toolbar->priv->view_menu_extended_section));
+ container_remove_all_children (GTK_CONTAINER (toolbar->priv->view_menu_zoom_section));
+ container_remove_all_children (GTK_CONTAINER (toolbar->priv->view_menu_extended_section));
- new_sections = nautilus_window_slot_get_toolbar_menu_sections (slot);
- if (new_sections == NULL)
- return;
+ new_sections = nautilus_window_slot_get_toolbar_menu_sections (slot);
+ if (new_sections == NULL)
+ {
+ return;
+ }
- gtk_widget_set_visible (toolbar->priv->view_menu_undo_redo_section,
- new_sections->supports_undo_redo);
+ gtk_widget_set_visible (toolbar->priv->view_menu_undo_redo_section,
+ new_sections->supports_undo_redo);
- if (new_sections->zoom_section != NULL)
- gtk_box_pack_start (GTK_BOX (toolbar->priv->view_menu_zoom_section), new_sections->zoom_section, FALSE, FALSE, 0);
+ if (new_sections->zoom_section != NULL)
+ {
+ gtk_box_pack_start (GTK_BOX (toolbar->priv->view_menu_zoom_section), new_sections->zoom_section, FALSE, FALSE, 0);
+ }
- if (new_sections->extended_section != NULL)
- gtk_box_pack_start (GTK_BOX (toolbar->priv->view_menu_extended_section), new_sections->extended_section, FALSE, FALSE, 0);
+ if (new_sections->extended_section != NULL)
+ {
+ gtk_box_pack_start (GTK_BOX (toolbar->priv->view_menu_extended_section), new_sections->extended_section, FALSE, FALSE, 0);
+ }
}
static void
disconnect_toolbar_menu_sections_change_handler (NautilusToolbar *toolbar)
{
- if (toolbar->priv->active_slot == NULL)
- return;
-
- g_signal_handlers_disconnect_by_func (toolbar->priv->active_slot,
- G_CALLBACK (on_slot_toolbar_menu_sections_changed),
- toolbar);
+ if (toolbar->priv->active_slot == NULL)
+ {
+ return;
+ }
+
+ g_signal_handlers_disconnect_by_func (toolbar->priv->active_slot,
+ G_CALLBACK (on_slot_toolbar_menu_sections_changed),
+ toolbar);
}
void
nautilus_toolbar_set_active_slot (NautilusToolbar *toolbar,
NautilusWindowSlot *slot)
{
- g_return_if_fail (NAUTILUS_IS_TOOLBAR (toolbar));
-
- g_clear_pointer (&toolbar->priv->icon_binding, g_binding_unbind);
- g_clear_pointer (&toolbar->priv->view_widget_binding, g_binding_unbind);
-
- if (toolbar->priv->active_slot != slot) {
- disconnect_toolbar_menu_sections_change_handler (toolbar);
- toolbar->priv->active_slot = slot;
-
- if (slot) {
- toolbar->priv->icon_binding =
- g_object_bind_property_full (slot, "icon",
- toolbar->priv->view_toggle_icon, "gicon",
- G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE,
- (GBindingTransformFunc) nautilus_toolbar_view_toggle_icon_transform_to,
- NULL,
- toolbar,
- NULL);
-
- on_slot_toolbar_menu_sections_changed (toolbar, NULL, slot);
- g_signal_connect_swapped (slot, "notify::toolbar-menu-sections",
- G_CALLBACK (on_slot_toolbar_menu_sections_changed), toolbar);
- }
+ g_return_if_fail (NAUTILUS_IS_TOOLBAR (toolbar));
+
+ g_clear_pointer (&toolbar->priv->icon_binding, g_binding_unbind);
+ g_clear_pointer (&toolbar->priv->view_widget_binding, g_binding_unbind);
+
+ if (toolbar->priv->active_slot != slot)
+ {
+ disconnect_toolbar_menu_sections_change_handler (toolbar);
+ toolbar->priv->active_slot = slot;
+
+ if (slot)
+ {
+ toolbar->priv->icon_binding =
+ g_object_bind_property_full (slot, "icon",
+ toolbar->priv->view_toggle_icon, "gicon",
+ G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE,
+ (GBindingTransformFunc) nautilus_toolbar_view_toggle_icon_transform_to,
+ NULL,
+ toolbar,
+ NULL);
+
+ on_slot_toolbar_menu_sections_changed (toolbar, NULL, slot);
+ g_signal_connect_swapped (slot, "notify::toolbar-menu-sections",
+ G_CALLBACK (on_slot_toolbar_menu_sections_changed), toolbar);
}
+ }
}
gboolean
nautilus_toolbar_is_operations_button_active (NautilusToolbar *self)
{
- return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button));
+ return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->priv->operations_button));
}
diff --git a/src/nautilus-trash-bar.c b/src/nautilus-trash-bar.c
index dd4327a63..b73111036 100644
--- a/src/nautilus-trash-bar.c
+++ b/src/nautilus-trash-bar.c
@@ -31,206 +31,224 @@
#include "nautilus-file.h"
#include "nautilus-trash-monitor.h"
-#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o)\
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
+#define NAUTILUS_TRASH_BAR_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_TRASH_BAR, NautilusTrashBarPrivate))
-enum {
- PROP_VIEW = 1,
- NUM_PROPERTIES
+enum
+{
+ PROP_VIEW = 1,
+ NUM_PROPERTIES
};
-enum {
- TRASH_BAR_RESPONSE_EMPTY = 1,
- TRASH_BAR_RESPONSE_RESTORE
+enum
+{
+ TRASH_BAR_RESPONSE_EMPTY = 1,
+ TRASH_BAR_RESPONSE_RESTORE
};
struct NautilusTrashBarPrivate
{
- NautilusFilesView *view;
- gulong selection_handler_id;
+ NautilusFilesView *view;
+ gulong selection_handler_id;
};
G_DEFINE_TYPE (NautilusTrashBar, nautilus_trash_bar, GTK_TYPE_INFO_BAR);
static void
selection_changed_cb (NautilusFilesView *view,
- NautilusTrashBar *bar)
+ NautilusTrashBar *bar)
{
- GList *selection;
- int count;
+ GList *selection;
+ int count;
- selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
- count = g_list_length (selection);
+ selection = nautilus_view_get_selection (NAUTILUS_VIEW (view));
+ count = g_list_length (selection);
- gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
- TRASH_BAR_RESPONSE_RESTORE,
- (count > 0));
+ gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
+ TRASH_BAR_RESPONSE_RESTORE,
+ (count > 0));
- nautilus_file_list_free (selection);
+ nautilus_file_list_free (selection);
}
static void
connect_view_and_update_button (NautilusTrashBar *bar)
{
- bar->priv->selection_handler_id =
- g_signal_connect (bar->priv->view, "selection-changed",
- G_CALLBACK (selection_changed_cb), bar);
+ bar->priv->selection_handler_id =
+ g_signal_connect (bar->priv->view, "selection-changed",
+ G_CALLBACK (selection_changed_cb), bar);
- selection_changed_cb (bar->priv->view, bar);
+ selection_changed_cb (bar->priv->view, bar);
}
static void
nautilus_trash_bar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusTrashBar *bar;
-
- bar = NAUTILUS_TRASH_BAR (object);
-
- switch (prop_id) {
- case PROP_VIEW:
- bar->priv->view = g_value_get_object (value);
- connect_view_and_update_button (bar);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ NautilusTrashBar *bar;
+
+ bar = NAUTILUS_TRASH_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ {
+ bar->priv->view = g_value_get_object (value);
+ connect_view_and_update_button (bar);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_trash_bar_dispose (GObject *obj)
{
- NautilusTrashBar *bar;
+ NautilusTrashBar *bar;
- bar = NAUTILUS_TRASH_BAR (obj);
+ bar = NAUTILUS_TRASH_BAR (obj);
- if (bar->priv->selection_handler_id) {
- g_signal_handler_disconnect (bar->priv->view, bar->priv->selection_handler_id);
- bar->priv->selection_handler_id = 0;
- }
+ if (bar->priv->selection_handler_id)
+ {
+ g_signal_handler_disconnect (bar->priv->view, bar->priv->selection_handler_id);
+ bar->priv->selection_handler_id = 0;
+ }
- G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->dispose (obj);
+ G_OBJECT_CLASS (nautilus_trash_bar_parent_class)->dispose (obj);
}
static void
nautilus_trash_bar_trash_state_changed (NautilusTrashMonitor *trash_monitor,
- gboolean state,
- gpointer data)
+ gboolean state,
+ gpointer data)
{
- NautilusTrashBar *bar;
+ NautilusTrashBar *bar;
- bar = NAUTILUS_TRASH_BAR (data);
+ bar = NAUTILUS_TRASH_BAR (data);
- gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
- TRASH_BAR_RESPONSE_EMPTY,
- !nautilus_trash_monitor_is_empty ());
+ gtk_info_bar_set_response_sensitive (GTK_INFO_BAR (bar),
+ TRASH_BAR_RESPONSE_EMPTY,
+ !nautilus_trash_monitor_is_empty ());
}
static void
nautilus_trash_bar_class_init (NautilusTrashBarClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
- object_class = G_OBJECT_CLASS (klass);
+ object_class = G_OBJECT_CLASS (klass);
- object_class->set_property = nautilus_trash_bar_set_property;
- object_class->dispose = nautilus_trash_bar_dispose;
+ object_class->set_property = nautilus_trash_bar_set_property;
+ object_class->dispose = nautilus_trash_bar_dispose;
- g_object_class_install_property (object_class,
- PROP_VIEW,
- g_param_spec_object ("view",
- "view",
- "the NautilusFilesView",
- NAUTILUS_TYPE_FILES_VIEW,
- G_PARAM_WRITABLE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_VIEW,
+ g_param_spec_object ("view",
+ "view",
+ "the NautilusFilesView",
+ NAUTILUS_TYPE_FILES_VIEW,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
- g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
+ g_type_class_add_private (klass, sizeof (NautilusTrashBarPrivate));
}
static void
trash_bar_response_cb (GtkInfoBar *infobar,
- gint response_id,
- gpointer user_data)
+ gint response_id,
+ gpointer user_data)
{
- NautilusTrashBar *bar;
- GtkWidget *window;
- GList *files;
-
- bar = NAUTILUS_TRASH_BAR (infobar);
- window = gtk_widget_get_toplevel (GTK_WIDGET (bar));
-
- switch (response_id) {
- case TRASH_BAR_RESPONSE_EMPTY:
- nautilus_file_operations_empty_trash (window);
- break;
- case TRASH_BAR_RESPONSE_RESTORE:
- files = nautilus_view_get_selection (NAUTILUS_VIEW (bar->priv->view));
- nautilus_restore_files_from_trash (files, GTK_WINDOW (window));
- nautilus_file_list_free (files);
- break;
- default:
- break;
- }
+ NautilusTrashBar *bar;
+ GtkWidget *window;
+ GList *files;
+
+ bar = NAUTILUS_TRASH_BAR (infobar);
+ window = gtk_widget_get_toplevel (GTK_WIDGET (bar));
+
+ switch (response_id)
+ {
+ case TRASH_BAR_RESPONSE_EMPTY:
+ {
+ nautilus_file_operations_empty_trash (window);
+ }
+ break;
+
+ case TRASH_BAR_RESPONSE_RESTORE:
+ {
+ files = nautilus_view_get_selection (NAUTILUS_VIEW (bar->priv->view));
+ nautilus_restore_files_from_trash (files, GTK_WINDOW (window));
+ nautilus_file_list_free (files);
+ }
+ break;
+
+ default:
+ {
+ }
+ break;
+ }
}
static void
nautilus_trash_bar_init (NautilusTrashBar *bar)
{
- GtkWidget *content_area, *action_area, *w;
- GtkWidget *label;
- PangoAttrList *attrs;
-
- bar->priv = NAUTILUS_TRASH_BAR_GET_PRIVATE (bar);
- content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
- action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
-
- gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
- GTK_ORIENTATION_HORIZONTAL);
-
- attrs = pango_attr_list_new ();
- pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
- label = gtk_label_new (_("Trash"));
- gtk_label_set_attributes (GTK_LABEL (label), attrs);
- pango_attr_list_unref (attrs);
-
- gtk_widget_show (label);
- gtk_container_add (GTK_CONTAINER (content_area), label);
-
- w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
- _("_Restore"),
- TRASH_BAR_RESPONSE_RESTORE);
- gtk_widget_set_tooltip_text (w,
- _("Restore selected items to their original position"));
-
- w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
- /* Translators: "Empty" is an action (for the trash) , not a state */
- _("_Empty"),
- TRASH_BAR_RESPONSE_EMPTY);
- gtk_widget_set_tooltip_text (w,
- _("Delete all items in the Trash"));
-
- g_signal_connect_object (nautilus_trash_monitor_get (),
- "trash-state-changed",
- G_CALLBACK (nautilus_trash_bar_trash_state_changed),
- bar,
- 0);
- nautilus_trash_bar_trash_state_changed (nautilus_trash_monitor_get (),
- FALSE, bar);
-
- g_signal_connect (bar, "response",
- G_CALLBACK (trash_bar_response_cb), bar);
+ GtkWidget *content_area, *action_area, *w;
+ GtkWidget *label;
+ PangoAttrList *attrs;
+
+ bar->priv = NAUTILUS_TRASH_BAR_GET_PRIVATE (bar);
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+ action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area),
+ GTK_ORIENTATION_HORIZONTAL);
+
+ attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+ label = gtk_label_new (_("Trash"));
+ gtk_label_set_attributes (GTK_LABEL (label), attrs);
+ pango_attr_list_unref (attrs);
+
+ gtk_widget_show (label);
+ gtk_container_add (GTK_CONTAINER (content_area), label);
+
+ w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+ _("_Restore"),
+ TRASH_BAR_RESPONSE_RESTORE);
+ gtk_widget_set_tooltip_text (w,
+ _("Restore selected items to their original position"));
+
+ w = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+ /* Translators: "Empty" is an action (for the trash) , not a state */
+ _("_Empty"),
+ TRASH_BAR_RESPONSE_EMPTY);
+ gtk_widget_set_tooltip_text (w,
+ _("Delete all items in the Trash"));
+
+ g_signal_connect_object (nautilus_trash_monitor_get (),
+ "trash-state-changed",
+ G_CALLBACK (nautilus_trash_bar_trash_state_changed),
+ bar,
+ 0);
+ nautilus_trash_bar_trash_state_changed (nautilus_trash_monitor_get (),
+ FALSE, bar);
+
+ g_signal_connect (bar, "response",
+ G_CALLBACK (trash_bar_response_cb), bar);
}
GtkWidget *
nautilus_trash_bar_new (NautilusFilesView *view)
{
- return g_object_new (NAUTILUS_TYPE_TRASH_BAR,
- "view", view,
- "message-type", GTK_MESSAGE_QUESTION,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_TRASH_BAR,
+ "view", view,
+ "message-type", GTK_MESSAGE_QUESTION,
+ NULL);
}
diff --git a/src/nautilus-trash-monitor.c b/src/nautilus-trash-monitor.c
index fd26421aa..318926f80 100644
--- a/src/nautilus-trash-monitor.c
+++ b/src/nautilus-trash-monitor.c
@@ -1,24 +1,23 @@
-
-/*
- nautilus-trash-monitor.c: Nautilus trash state watcher.
-
- Copyright (C) 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Pavel Cisler <pavel@eazel.com>
-*/
+/*
+ * nautilus-trash-monitor.c: Nautilus trash state watcher.
+ *
+ * Copyright (C) 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Pavel Cisler <pavel@eazel.com>
+ */
#include <config.h>
#include "nautilus-trash-monitor.h"
@@ -30,71 +29,75 @@
#include <gio/gio.h>
#include <string.h>
-struct NautilusTrashMonitorDetails {
- gboolean empty;
- GFileMonitor *file_monitor;
+struct NautilusTrashMonitorDetails
+{
+ gboolean empty;
+ GFileMonitor *file_monitor;
};
-enum {
- TRASH_STATE_CHANGED,
- LAST_SIGNAL
+enum
+{
+ TRASH_STATE_CHANGED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
static NautilusTrashMonitor *nautilus_trash_monitor = NULL;
-G_DEFINE_TYPE(NautilusTrashMonitor, nautilus_trash_monitor, G_TYPE_OBJECT)
+G_DEFINE_TYPE (NautilusTrashMonitor, nautilus_trash_monitor, G_TYPE_OBJECT)
static void
nautilus_trash_monitor_finalize (GObject *object)
{
- NautilusTrashMonitor *trash_monitor;
+ NautilusTrashMonitor *trash_monitor;
- trash_monitor = NAUTILUS_TRASH_MONITOR (object);
+ trash_monitor = NAUTILUS_TRASH_MONITOR (object);
- if (trash_monitor->details->file_monitor) {
- g_object_unref (trash_monitor->details->file_monitor);
- }
+ if (trash_monitor->details->file_monitor)
+ {
+ g_object_unref (trash_monitor->details->file_monitor);
+ }
- G_OBJECT_CLASS (nautilus_trash_monitor_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_trash_monitor_parent_class)->finalize (object);
}
static void
nautilus_trash_monitor_class_init (NautilusTrashMonitorClass *klass)
{
- GObjectClass *object_class;
+ GObjectClass *object_class;
- object_class = G_OBJECT_CLASS (klass);
+ object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = nautilus_trash_monitor_finalize;
+ object_class->finalize = nautilus_trash_monitor_finalize;
- signals[TRASH_STATE_CHANGED] = g_signal_new
- ("trash-state-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTrashMonitorClass, trash_state_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1,
- G_TYPE_BOOLEAN);
+ signals[TRASH_STATE_CHANGED] = g_signal_new
+ ("trash-state-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTrashMonitorClass, trash_state_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1,
+ G_TYPE_BOOLEAN);
- g_type_class_add_private (object_class, sizeof(NautilusTrashMonitorDetails));
+ g_type_class_add_private (object_class, sizeof (NautilusTrashMonitorDetails));
}
static void
update_empty_info (NautilusTrashMonitor *trash_monitor,
- gboolean is_empty)
+ gboolean is_empty)
{
- if (trash_monitor->details->empty == is_empty) {
- return;
- }
-
- trash_monitor->details->empty = is_empty;
-
- /* trash got empty or full, notify everyone who cares */
- g_signal_emit (trash_monitor,
- signals[TRASH_STATE_CHANGED], 0,
- trash_monitor->details->empty);
+ if (trash_monitor->details->empty == is_empty)
+ {
+ return;
+ }
+
+ trash_monitor->details->empty = is_empty;
+
+ /* trash got empty or full, notify everyone who cares */
+ g_signal_emit (trash_monitor,
+ signals[TRASH_STATE_CHANGED], 0,
+ trash_monitor->details->empty);
}
/* Use G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT since we only want to know whether the
@@ -103,108 +106,109 @@ update_empty_info (NautilusTrashMonitor *trash_monitor,
* trash backend with enumeration requests when trashing > 1000 files
*/
static void
-trash_query_info_cb (GObject *source,
+trash_query_info_cb (GObject *source,
GAsyncResult *res,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusTrashMonitor *trash_monitor = user_data;
- GFileInfo *info;
- guint32 item_count;
- gboolean is_empty = TRUE;
-
- info = g_file_query_info_finish (G_FILE (source), res, NULL);
+ NautilusTrashMonitor *trash_monitor = user_data;
+ GFileInfo *info;
+ guint32 item_count;
+ gboolean is_empty = TRUE;
- if (info != NULL) {
- item_count = g_file_info_get_attribute_uint32 (info,
- G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT);
- is_empty = item_count == 0;
+ info = g_file_query_info_finish (G_FILE (source), res, NULL);
- g_object_unref (info);
+ if (info != NULL)
+ {
+ item_count = g_file_info_get_attribute_uint32 (info,
+ G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT);
+ is_empty = item_count == 0;
- }
+ g_object_unref (info);
+ }
- update_empty_info (trash_monitor, is_empty);
+ update_empty_info (trash_monitor, is_empty);
- g_object_unref (trash_monitor);
+ g_object_unref (trash_monitor);
}
static void
schedule_update_info (NautilusTrashMonitor *trash_monitor)
{
- GFile *location;
-
- location = g_file_new_for_uri ("trash:///");
- g_file_query_info_async (location,
- G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT, NULL,
- trash_query_info_cb, g_object_ref (trash_monitor));
-
- g_object_unref (location);
+ GFile *location;
+
+ location = g_file_new_for_uri ("trash:///");
+ g_file_query_info_async (location,
+ G_FILE_ATTRIBUTE_TRASH_ITEM_COUNT,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT, NULL,
+ trash_query_info_cb, g_object_ref (trash_monitor));
+
+ g_object_unref (location);
}
static void
-file_changed (GFileMonitor* monitor,
- GFile *child,
- GFile *other_file,
- GFileMonitorEvent event_type,
- gpointer user_data)
+file_changed (GFileMonitor *monitor,
+ GFile *child,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ gpointer user_data)
{
- NautilusTrashMonitor *trash_monitor;
+ NautilusTrashMonitor *trash_monitor;
- trash_monitor = NAUTILUS_TRASH_MONITOR (user_data);
+ trash_monitor = NAUTILUS_TRASH_MONITOR (user_data);
- schedule_update_info (trash_monitor);
+ schedule_update_info (trash_monitor);
}
static void
nautilus_trash_monitor_init (NautilusTrashMonitor *trash_monitor)
{
- GFile *location;
+ GFile *location;
- trash_monitor->details = G_TYPE_INSTANCE_GET_PRIVATE (trash_monitor,
- NAUTILUS_TYPE_TRASH_MONITOR,
- NautilusTrashMonitorDetails);
+ trash_monitor->details = G_TYPE_INSTANCE_GET_PRIVATE (trash_monitor,
+ NAUTILUS_TYPE_TRASH_MONITOR,
+ NautilusTrashMonitorDetails);
- trash_monitor->details->empty = TRUE;
+ trash_monitor->details->empty = TRUE;
- location = g_file_new_for_uri ("trash:///");
+ location = g_file_new_for_uri ("trash:///");
- trash_monitor->details->file_monitor = g_file_monitor_file (location, 0, NULL, NULL);
+ trash_monitor->details->file_monitor = g_file_monitor_file (location, 0, NULL, NULL);
- g_signal_connect (trash_monitor->details->file_monitor, "changed",
- (GCallback)file_changed, trash_monitor);
+ g_signal_connect (trash_monitor->details->file_monitor, "changed",
+ (GCallback) file_changed, trash_monitor);
- g_object_unref (location);
+ g_object_unref (location);
- schedule_update_info (trash_monitor);
+ schedule_update_info (trash_monitor);
}
static void
unref_trash_monitor (void)
{
- g_object_unref (nautilus_trash_monitor);
+ g_object_unref (nautilus_trash_monitor);
}
NautilusTrashMonitor *
nautilus_trash_monitor_get (void)
{
- if (nautilus_trash_monitor == NULL) {
- /* not running yet, start it up */
+ if (nautilus_trash_monitor == NULL)
+ {
+ /* not running yet, start it up */
- nautilus_trash_monitor = NAUTILUS_TRASH_MONITOR
- (g_object_new (NAUTILUS_TYPE_TRASH_MONITOR, NULL));
- eel_debug_call_at_shutdown (unref_trash_monitor);
- }
+ nautilus_trash_monitor = NAUTILUS_TRASH_MONITOR
+ (g_object_new (NAUTILUS_TYPE_TRASH_MONITOR, NULL));
+ eel_debug_call_at_shutdown (unref_trash_monitor);
+ }
- return nautilus_trash_monitor;
+ return nautilus_trash_monitor;
}
gboolean
nautilus_trash_monitor_is_empty (void)
{
- NautilusTrashMonitor *monitor;
+ NautilusTrashMonitor *monitor;
- monitor = nautilus_trash_monitor_get ();
- return monitor->details->empty;
+ monitor = nautilus_trash_monitor_get ();
+ return monitor->details->empty;
}
diff --git a/src/nautilus-tree-view-drag-dest.c b/src/nautilus-tree-view-drag-dest.c
index 97257dd94..b3d61b630 100644
--- a/src/nautilus-tree-view-drag-dest.c
+++ b/src/nautilus-tree-view-drag-dest.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -16,12 +15,12 @@
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
- *
+ *
* Author: Dave Camp <dave@ximian.com>
* XDS support: Benedikt Meurer <benny@xfce.org> (adapted by Amos Brocco <amos.brocco@unifr.ch>)
*/
-/* nautilus-tree-view-drag-dest.c: Handles drag and drop for treeviews which
+/* nautilus-tree-view-drag-dest.c: Handles drag and drop for treeviews which
* contain a hierarchy of files
*/
@@ -45,1182 +44,1311 @@
#define AUTO_SCROLL_MARGIN 20
#define HOVER_EXPAND_TIMEOUT 1
-struct _NautilusTreeViewDragDestDetails {
- GtkTreeView *tree_view;
+struct _NautilusTreeViewDragDestDetails
+{
+ GtkTreeView *tree_view;
- gboolean drop_occurred;
+ gboolean drop_occurred;
- gboolean have_drag_data;
- guint drag_type;
- GtkSelectionData *drag_data;
- GList *drag_list;
+ gboolean have_drag_data;
+ guint drag_type;
+ GtkSelectionData *drag_data;
+ GList *drag_list;
- guint hover_id;
- guint highlight_id;
- guint scroll_id;
- guint expand_id;
+ guint hover_id;
+ guint highlight_id;
+ guint scroll_id;
+ guint expand_id;
- char *direct_save_uri;
- char *target_uri;
+ char *direct_save_uri;
+ char *target_uri;
};
-enum {
- GET_ROOT_URI,
- GET_FILE_FOR_PATH,
- MOVE_COPY_ITEMS,
- HANDLE_NETSCAPE_URL,
- HANDLE_URI_LIST,
- HANDLE_TEXT,
- HANDLE_RAW,
- HANDLE_HOVER,
- LAST_SIGNAL
+enum
+{
+ GET_ROOT_URI,
+ GET_FILE_FOR_PATH,
+ MOVE_COPY_ITEMS,
+ HANDLE_NETSCAPE_URL,
+ HANDLE_URI_LIST,
+ HANDLE_TEXT,
+ HANDLE_RAW,
+ HANDLE_HOVER,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE (NautilusTreeViewDragDest, nautilus_tree_view_drag_dest,
- G_TYPE_OBJECT);
-
-static const GtkTargetEntry drag_types [] = {
- { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
- /* prefer "_NETSCAPE_URL" over "text/uri-list" to satisfy web browsers. */
- { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL },
- { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
- { NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, 0, NAUTILUS_ICON_DND_XDNDDIRECTSAVE }, /* XDS Protocol Type */
- { NAUTILUS_ICON_DND_RAW_TYPE, 0, NAUTILUS_ICON_DND_RAW }
+ G_TYPE_OBJECT);
+
+static const GtkTargetEntry drag_types [] =
+{
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
+ /* prefer "_NETSCAPE_URL" over "text/uri-list" to satisfy web browsers. */
+ { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL },
+ { NAUTILUS_ICON_DND_URI_LIST_TYPE, 0, NAUTILUS_ICON_DND_URI_LIST },
+ { NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, 0, NAUTILUS_ICON_DND_XDNDDIRECTSAVE }, /* XDS Protocol Type */
+ { NAUTILUS_ICON_DND_RAW_TYPE, 0, NAUTILUS_ICON_DND_RAW }
};
static void
gtk_tree_view_vertical_autoscroll (GtkTreeView *tree_view)
{
- GdkRectangle visible_rect;
- GtkAdjustment *vadjustment;
- GdkDisplay *display;
- GdkSeat *seat;
- GdkDevice *pointer;
- GdkWindow *window;
- int y;
- int offset;
- float value;
-
- window = gtk_tree_view_get_bin_window (tree_view);
- vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tree_view));
-
- display = gtk_widget_get_display (GTK_WIDGET (tree_view));
- seat = gdk_display_get_default_seat (display);
- pointer = gdk_seat_get_pointer (seat);
- gdk_window_get_device_position (window, pointer,
- NULL, &y, NULL);
-
- y += gtk_adjustment_get_value (vadjustment);
-
- gtk_tree_view_get_visible_rect (tree_view, &visible_rect);
-
- offset = y - (visible_rect.y + 2 * AUTO_SCROLL_MARGIN);
- if (offset > 0) {
- offset = y - (visible_rect.y + visible_rect.height - 2 * AUTO_SCROLL_MARGIN);
- if (offset < 0) {
- return;
- }
- }
-
- value = CLAMP (gtk_adjustment_get_value (vadjustment) + offset, 0.0,
- gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment));
- gtk_adjustment_set_value (vadjustment, value);
+ GdkRectangle visible_rect;
+ GtkAdjustment *vadjustment;
+ GdkDisplay *display;
+ GdkSeat *seat;
+ GdkDevice *pointer;
+ GdkWindow *window;
+ int y;
+ int offset;
+ float value;
+
+ window = gtk_tree_view_get_bin_window (tree_view);
+ vadjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tree_view));
+
+ display = gtk_widget_get_display (GTK_WIDGET (tree_view));
+ seat = gdk_display_get_default_seat (display);
+ pointer = gdk_seat_get_pointer (seat);
+ gdk_window_get_device_position (window, pointer,
+ NULL, &y, NULL);
+
+ y += gtk_adjustment_get_value (vadjustment);
+
+ gtk_tree_view_get_visible_rect (tree_view, &visible_rect);
+
+ offset = y - (visible_rect.y + 2 * AUTO_SCROLL_MARGIN);
+ if (offset > 0)
+ {
+ offset = y - (visible_rect.y + visible_rect.height - 2 * AUTO_SCROLL_MARGIN);
+ if (offset < 0)
+ {
+ return;
+ }
+ }
+
+ value = CLAMP (gtk_adjustment_get_value (vadjustment) + offset, 0.0,
+ gtk_adjustment_get_upper (vadjustment) - gtk_adjustment_get_page_size (vadjustment));
+ gtk_adjustment_set_value (vadjustment, value);
}
static int
scroll_timeout (gpointer data)
{
- GtkTreeView *tree_view = GTK_TREE_VIEW (data);
-
- gtk_tree_view_vertical_autoscroll (tree_view);
+ GtkTreeView *tree_view = GTK_TREE_VIEW (data);
- return TRUE;
+ gtk_tree_view_vertical_autoscroll (tree_view);
+
+ return TRUE;
}
static void
remove_scroll_timeout (NautilusTreeViewDragDest *dest)
{
- if (dest->details->scroll_id) {
- g_source_remove (dest->details->scroll_id);
- dest->details->scroll_id = 0;
- }
+ if (dest->details->scroll_id)
+ {
+ g_source_remove (dest->details->scroll_id);
+ dest->details->scroll_id = 0;
+ }
}
static int
expand_timeout (gpointer data)
{
- GtkTreeView *tree_view;
- GtkTreePath *drop_path;
+ GtkTreeView *tree_view;
+ GtkTreePath *drop_path;
- tree_view = GTK_TREE_VIEW (data);
+ tree_view = GTK_TREE_VIEW (data);
- gtk_tree_view_get_drag_dest_row (tree_view, &drop_path, NULL);
+ gtk_tree_view_get_drag_dest_row (tree_view, &drop_path, NULL);
- if (drop_path) {
- gtk_tree_view_expand_row (tree_view, drop_path, FALSE);
- gtk_tree_path_free (drop_path);
- }
+ if (drop_path)
+ {
+ gtk_tree_view_expand_row (tree_view, drop_path, FALSE);
+ gtk_tree_path_free (drop_path);
+ }
- return FALSE;
+ return FALSE;
}
static void
remove_expand_timer (NautilusTreeViewDragDest *dest)
{
- if (dest->details->expand_id) {
- g_source_remove (dest->details->expand_id);
- dest->details->expand_id = 0;
- }
+ if (dest->details->expand_id)
+ {
+ g_source_remove (dest->details->expand_id);
+ dest->details->expand_id = 0;
+ }
}
static gboolean
highlight_draw (GtkWidget *widget,
- cairo_t *cr,
- gpointer data)
+ cairo_t *cr,
+ gpointer data)
{
- GdkWindow *bin_window;
- int width;
- int height;
- GtkStyleContext *style;
+ GdkWindow *bin_window;
+ int width;
+ int height;
+ GtkStyleContext *style;
- /* FIXMEchpe: is bin window right here??? */
- bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget));
+ /* FIXMEchpe: is bin window right here??? */
+ bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget));
- width = gdk_window_get_width (bin_window);
- height = gdk_window_get_height (bin_window);
+ width = gdk_window_get_width (bin_window);
+ height = gdk_window_get_height (bin_window);
- style = gtk_widget_get_style_context (widget);
+ style = gtk_widget_get_style_context (widget);
- gtk_style_context_save (style);
- gtk_style_context_add_class (style, "treeview-drop-indicator");
+ gtk_style_context_save (style);
+ gtk_style_context_add_class (style, "treeview-drop-indicator");
- gtk_render_focus (style,
- cr,
- 0, 0, width, height);
+ gtk_render_focus (style,
+ cr,
+ 0, 0, width, height);
- gtk_style_context_restore (style);
+ gtk_style_context_restore (style);
- return FALSE;
+ return FALSE;
}
static void
-set_widget_highlight (NautilusTreeViewDragDest *dest, gboolean highlight)
+set_widget_highlight (NautilusTreeViewDragDest *dest,
+ gboolean highlight)
{
- if (!highlight && dest->details->highlight_id) {
- g_signal_handler_disconnect (dest->details->tree_view,
- dest->details->highlight_id);
- dest->details->highlight_id = 0;
- gtk_widget_queue_draw (GTK_WIDGET (dest->details->tree_view));
- }
-
- if (highlight && !dest->details->highlight_id) {
- dest->details->highlight_id =
- g_signal_connect_object (dest->details->tree_view,
- "draw",
- G_CALLBACK (highlight_draw),
- dest, 0);
- gtk_widget_queue_draw (GTK_WIDGET (dest->details->tree_view));
- }
+ if (!highlight && dest->details->highlight_id)
+ {
+ g_signal_handler_disconnect (dest->details->tree_view,
+ dest->details->highlight_id);
+ dest->details->highlight_id = 0;
+ gtk_widget_queue_draw (GTK_WIDGET (dest->details->tree_view));
+ }
+
+ if (highlight && !dest->details->highlight_id)
+ {
+ dest->details->highlight_id =
+ g_signal_connect_object (dest->details->tree_view,
+ "draw",
+ G_CALLBACK (highlight_draw),
+ dest, 0);
+ gtk_widget_queue_draw (GTK_WIDGET (dest->details->tree_view));
+ }
}
static void
set_drag_dest_row (NautilusTreeViewDragDest *dest,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- if (path) {
- set_widget_highlight (dest, FALSE);
- gtk_tree_view_set_drag_dest_row
- (dest->details->tree_view,
- path,
- GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
- } else {
- set_widget_highlight (dest, TRUE);
- gtk_tree_view_set_drag_dest_row (dest->details->tree_view,
- NULL,
- 0);
- }
+ if (path)
+ {
+ set_widget_highlight (dest, FALSE);
+ gtk_tree_view_set_drag_dest_row
+ (dest->details->tree_view,
+ path,
+ GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
+ }
+ else
+ {
+ set_widget_highlight (dest, TRUE);
+ gtk_tree_view_set_drag_dest_row (dest->details->tree_view,
+ NULL,
+ 0);
+ }
}
static void
clear_drag_dest_row (NautilusTreeViewDragDest *dest)
{
- gtk_tree_view_set_drag_dest_row (dest->details->tree_view, NULL, 0);
- set_widget_highlight (dest, FALSE);
+ gtk_tree_view_set_drag_dest_row (dest->details->tree_view, NULL, 0);
+ set_widget_highlight (dest, FALSE);
}
static gboolean
get_drag_data (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- guint32 time)
+ GdkDragContext *context,
+ guint32 time)
{
- GdkAtom target;
-
- target = gtk_drag_dest_find_target (GTK_WIDGET (dest->details->tree_view),
- context,
- NULL);
-
- if (target == GDK_NONE) {
- return FALSE;
- }
-
- if (target == gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE) &&
- !dest->details->drop_occurred) {
- dest->details->drag_type = NAUTILUS_ICON_DND_XDNDDIRECTSAVE;
- dest->details->have_drag_data = TRUE;
- return TRUE;
- }
-
- gtk_drag_get_data (GTK_WIDGET (dest->details->tree_view),
- context, target, time);
-
- return TRUE;
+ GdkAtom target;
+
+ target = gtk_drag_dest_find_target (GTK_WIDGET (dest->details->tree_view),
+ context,
+ NULL);
+
+ if (target == GDK_NONE)
+ {
+ return FALSE;
+ }
+
+ if (target == gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE) &&
+ !dest->details->drop_occurred)
+ {
+ dest->details->drag_type = NAUTILUS_ICON_DND_XDNDDIRECTSAVE;
+ dest->details->have_drag_data = TRUE;
+ return TRUE;
+ }
+
+ gtk_drag_get_data (GTK_WIDGET (dest->details->tree_view),
+ context, target, time);
+
+ return TRUE;
}
static void
remove_hover_timer (NautilusTreeViewDragDest *dest)
{
- if (dest->details->hover_id != 0) {
- g_source_remove (dest->details->hover_id);
- dest->details->hover_id = 0;
- }
+ if (dest->details->hover_id != 0)
+ {
+ g_source_remove (dest->details->hover_id);
+ dest->details->hover_id = 0;
+ }
}
static void
free_drag_data (NautilusTreeViewDragDest *dest)
{
- dest->details->have_drag_data = FALSE;
+ dest->details->have_drag_data = FALSE;
- if (dest->details->drag_data) {
- gtk_selection_data_free (dest->details->drag_data);
- dest->details->drag_data = NULL;
- }
+ if (dest->details->drag_data)
+ {
+ gtk_selection_data_free (dest->details->drag_data);
+ dest->details->drag_data = NULL;
+ }
- if (dest->details->drag_list) {
- nautilus_drag_destroy_selection_list (dest->details->drag_list);
- dest->details->drag_list = NULL;
- }
+ if (dest->details->drag_list)
+ {
+ nautilus_drag_destroy_selection_list (dest->details->drag_list);
+ dest->details->drag_list = NULL;
+ }
- g_free (dest->details->direct_save_uri);
- dest->details->direct_save_uri = NULL;
+ g_free (dest->details->direct_save_uri);
+ dest->details->direct_save_uri = NULL;
- g_free (dest->details->target_uri);
- dest->details->target_uri = NULL;
+ g_free (dest->details->target_uri);
+ dest->details->target_uri = NULL;
- remove_hover_timer (dest);
- remove_expand_timer (dest);
+ remove_hover_timer (dest);
+ remove_expand_timer (dest);
}
static gboolean
hover_timer (gpointer user_data)
{
- NautilusTreeViewDragDest *dest = user_data;
+ NautilusTreeViewDragDest *dest = user_data;
- dest->details->hover_id = 0;
+ dest->details->hover_id = 0;
- g_signal_emit (dest, signals[HANDLE_HOVER], 0, dest->details->target_uri);
+ g_signal_emit (dest, signals[HANDLE_HOVER], 0, dest->details->target_uri);
- return FALSE;
+ return FALSE;
}
static void
check_hover_timer (NautilusTreeViewDragDest *dest,
- const char *uri)
+ const char *uri)
{
- GtkSettings *settings;
- guint timeout;
-
- if (g_strcmp0 (uri, dest->details->target_uri) == 0) {
- return;
- }
- remove_hover_timer (dest);
-
- settings = gtk_widget_get_settings (GTK_WIDGET (dest->details->tree_view));
- g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
-
- g_free (dest->details->target_uri);
- dest->details->target_uri = NULL;
-
- if (uri != NULL) {
- dest->details->target_uri = g_strdup (uri);
- dest->details->hover_id =
- gdk_threads_add_timeout (timeout,
- hover_timer,
- dest);
- }
+ GtkSettings *settings;
+ guint timeout;
+
+ if (g_strcmp0 (uri, dest->details->target_uri) == 0)
+ {
+ return;
+ }
+ remove_hover_timer (dest);
+
+ settings = gtk_widget_get_settings (GTK_WIDGET (dest->details->tree_view));
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+
+ g_free (dest->details->target_uri);
+ dest->details->target_uri = NULL;
+
+ if (uri != NULL)
+ {
+ dest->details->target_uri = g_strdup (uri);
+ dest->details->hover_id =
+ gdk_threads_add_timeout (timeout,
+ hover_timer,
+ dest);
+ }
}
static void
check_expand_timer (NautilusTreeViewDragDest *dest,
- GtkTreePath *drop_path,
- GtkTreePath *old_drop_path)
+ GtkTreePath *drop_path,
+ GtkTreePath *old_drop_path)
{
- GtkTreeModel *model;
- GtkTreeIter drop_iter;
-
- model = gtk_tree_view_get_model (dest->details->tree_view);
-
- if (drop_path == NULL ||
- (old_drop_path != NULL && gtk_tree_path_compare (old_drop_path, drop_path) != 0)) {
- remove_expand_timer (dest);
- }
-
- if (dest->details->expand_id == 0 &&
- drop_path != NULL) {
- gtk_tree_model_get_iter (model, &drop_iter, drop_path);
- if (gtk_tree_model_iter_has_child (model, &drop_iter)) {
- dest->details->expand_id =
- g_timeout_add_seconds (HOVER_EXPAND_TIMEOUT,
- expand_timeout,
- dest->details->tree_view);
- }
- }
+ GtkTreeModel *model;
+ GtkTreeIter drop_iter;
+
+ model = gtk_tree_view_get_model (dest->details->tree_view);
+
+ if (drop_path == NULL ||
+ (old_drop_path != NULL && gtk_tree_path_compare (old_drop_path, drop_path) != 0))
+ {
+ remove_expand_timer (dest);
+ }
+
+ if (dest->details->expand_id == 0 &&
+ drop_path != NULL)
+ {
+ gtk_tree_model_get_iter (model, &drop_iter, drop_path);
+ if (gtk_tree_model_iter_has_child (model, &drop_iter))
+ {
+ dest->details->expand_id =
+ g_timeout_add_seconds (HOVER_EXPAND_TIMEOUT,
+ expand_timeout,
+ dest->details->tree_view);
+ }
+ }
}
static char *
get_root_uri (NautilusTreeViewDragDest *dest)
{
- char *uri;
-
- g_signal_emit (dest, signals[GET_ROOT_URI], 0, &uri);
-
- return uri;
+ char *uri;
+
+ g_signal_emit (dest, signals[GET_ROOT_URI], 0, &uri);
+
+ return uri;
}
static NautilusFile *
-file_for_path (NautilusTreeViewDragDest *dest, GtkTreePath *path)
+file_for_path (NautilusTreeViewDragDest *dest,
+ GtkTreePath *path)
{
- NautilusFile *file;
- char *uri;
-
- if (path) {
- g_signal_emit (dest, signals[GET_FILE_FOR_PATH], 0, path, &file);
- } else {
- uri = get_root_uri (dest);
-
- file = NULL;
- if (uri != NULL) {
- file = nautilus_file_get_by_uri (uri);
- }
-
- g_free (uri);
- }
-
- return file;
+ NautilusFile *file;
+ char *uri;
+
+ if (path)
+ {
+ g_signal_emit (dest, signals[GET_FILE_FOR_PATH], 0, path, &file);
+ }
+ else
+ {
+ uri = get_root_uri (dest);
+
+ file = NULL;
+ if (uri != NULL)
+ {
+ file = nautilus_file_get_by_uri (uri);
+ }
+
+ g_free (uri);
+ }
+
+ return file;
}
static char *
get_drop_target_uri_for_path (NautilusTreeViewDragDest *dest,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- NautilusFile *file;
- char *target = NULL;
- gboolean can;
-
- file = file_for_path (dest, path);
- if (file == NULL) {
- return NULL;
- }
- can = nautilus_drag_can_accept_info (file,
- dest->details->drag_type,
- dest->details->drag_list);
- if (can) {
- target = nautilus_file_get_target_uri (file);
- }
- nautilus_file_unref (file);
-
- return target;
+ NautilusFile *file;
+ char *target = NULL;
+ gboolean can;
+
+ file = file_for_path (dest, path);
+ if (file == NULL)
+ {
+ return NULL;
+ }
+ can = nautilus_drag_can_accept_info (file,
+ dest->details->drag_type,
+ dest->details->drag_list);
+ if (can)
+ {
+ target = nautilus_file_get_target_uri (file);
+ }
+ nautilus_file_unref (file);
+
+ return target;
}
static void
check_hover_expand_timer (NautilusTreeViewDragDest *dest,
- GtkTreePath *path,
- GtkTreePath *drop_path,
- GtkTreePath *old_drop_path)
+ GtkTreePath *path,
+ GtkTreePath *drop_path,
+ GtkTreePath *old_drop_path)
{
- gboolean use_tree = g_settings_get_boolean (nautilus_list_view_preferences,
- NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
-
- if (use_tree) {
- check_expand_timer (dest, drop_path, old_drop_path);
- } else {
- char *uri;
- uri = get_drop_target_uri_for_path (dest, path);
- check_hover_timer (dest, uri);
- g_free (uri);
- }
+ gboolean use_tree = g_settings_get_boolean (nautilus_list_view_preferences,
+ NAUTILUS_PREFERENCES_LIST_VIEW_USE_TREE);
+
+ if (use_tree)
+ {
+ check_expand_timer (dest, drop_path, old_drop_path);
+ }
+ else
+ {
+ char *uri;
+ uri = get_drop_target_uri_for_path (dest, path);
+ check_hover_timer (dest, uri);
+ g_free (uri);
+ }
}
static GtkTreePath *
get_drop_path (NautilusTreeViewDragDest *dest,
- GtkTreePath *path)
+ GtkTreePath *path)
{
- NautilusFile *file;
- GtkTreePath *ret;
-
- if (!path || !dest->details->have_drag_data) {
- return NULL;
- }
-
- ret = gtk_tree_path_copy (path);
- file = file_for_path (dest, ret);
-
- /* Go up the tree until we find a file that can accept a drop */
- while (file == NULL /* dummy row */ ||
- !nautilus_drag_can_accept_info (file,
- dest->details->drag_type,
- dest->details->drag_list)) {
- if (gtk_tree_path_get_depth (ret) == 1) {
- gtk_tree_path_free (ret);
- ret = NULL;
- break;
- } else {
- gtk_tree_path_up (ret);
-
- nautilus_file_unref (file);
- file = file_for_path (dest, ret);
- }
- }
- nautilus_file_unref (file);
-
- return ret;
+ NautilusFile *file;
+ GtkTreePath *ret;
+
+ if (!path || !dest->details->have_drag_data)
+ {
+ return NULL;
+ }
+
+ ret = gtk_tree_path_copy (path);
+ file = file_for_path (dest, ret);
+
+ /* Go up the tree until we find a file that can accept a drop */
+ while (file == NULL /* dummy row */ ||
+ !nautilus_drag_can_accept_info (file,
+ dest->details->drag_type,
+ dest->details->drag_list))
+ {
+ if (gtk_tree_path_get_depth (ret) == 1)
+ {
+ gtk_tree_path_free (ret);
+ ret = NULL;
+ break;
+ }
+ else
+ {
+ gtk_tree_path_up (ret);
+
+ nautilus_file_unref (file);
+ file = file_for_path (dest, ret);
+ }
+ }
+ nautilus_file_unref (file);
+
+ return ret;
}
static guint
-get_drop_action (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- GtkTreePath *path)
+get_drop_action (NautilusTreeViewDragDest *dest,
+ GdkDragContext *context,
+ GtkTreePath *path)
{
- char *drop_target;
- int action;
-
- if (!dest->details->have_drag_data ||
- (dest->details->drag_type == NAUTILUS_ICON_DND_GNOME_ICON_LIST &&
- dest->details->drag_list == NULL)) {
- return 0;
- }
-
- drop_target = get_drop_target_uri_for_path (dest, path);
- if (drop_target == NULL) {
- return 0;
- }
-
- action = 0;
- switch (dest->details->drag_type) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST :
- nautilus_drag_default_drop_action_for_icons
- (context,
- drop_target,
- dest->details->drag_list,
- 0,
- &action);
- break;
- case NAUTILUS_ICON_DND_NETSCAPE_URL:
- action = nautilus_drag_default_drop_action_for_netscape_url (context);
- break;
- case NAUTILUS_ICON_DND_URI_LIST :
- action = gdk_drag_context_get_suggested_action (context);
- break;
- case NAUTILUS_ICON_DND_TEXT:
- case NAUTILUS_ICON_DND_RAW:
- case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
- action = GDK_ACTION_COPY;
- break;
- }
-
- g_free (drop_target);
-
- return action;
+ char *drop_target;
+ int action;
+
+ if (!dest->details->have_drag_data ||
+ (dest->details->drag_type == NAUTILUS_ICON_DND_GNOME_ICON_LIST &&
+ dest->details->drag_list == NULL))
+ {
+ return 0;
+ }
+
+ drop_target = get_drop_target_uri_for_path (dest, path);
+ if (drop_target == NULL)
+ {
+ return 0;
+ }
+
+ action = 0;
+ switch (dest->details->drag_type)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ nautilus_drag_default_drop_action_for_icons
+ (context,
+ drop_target,
+ dest->details->drag_list,
+ 0,
+ &action);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_NETSCAPE_URL:
+ {
+ action = nautilus_drag_default_drop_action_for_netscape_url (context);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ {
+ action = gdk_drag_context_get_suggested_action (context);
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_TEXT:
+ case NAUTILUS_ICON_DND_RAW:
+ case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+ {
+ action = GDK_ACTION_COPY;
+ }
+ break;
+ }
+
+ g_free (drop_target);
+
+ return action;
}
static gboolean
-drag_motion_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- guint32 time,
- gpointer data)
+drag_motion_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ guint32 time,
+ gpointer data)
{
- NautilusTreeViewDragDest *dest;
- GtkTreePath *path;
- GtkTreePath *drop_path, *old_drop_path;
- GtkTreeViewDropPosition pos;
- GdkWindow *bin_window;
- guint action;
- gboolean res = TRUE;
-
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
-
- gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
- x, y, &path, &pos);
- if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
- pos == GTK_TREE_VIEW_DROP_AFTER) {
- gtk_tree_path_free (path);
- path = NULL;
- }
-
- if (!dest->details->have_drag_data) {
- res = get_drag_data (dest, context, time);
- }
-
- if (!res) {
- return FALSE;
- }
-
- drop_path = get_drop_path (dest, path);
-
- action = 0;
- bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget));
- if (bin_window != NULL) {
- int bin_x, bin_y;
- gdk_window_get_position (bin_window, &bin_x, &bin_y);
- if (bin_y <= y) {
- /* ignore drags on the header */
- action = get_drop_action (dest, context, drop_path);
- }
- }
-
- gtk_tree_view_get_drag_dest_row (GTK_TREE_VIEW (widget), &old_drop_path,
- NULL);
-
- if (action) {
- set_drag_dest_row (dest, drop_path);
- check_hover_expand_timer (dest, path, drop_path, old_drop_path);
- } else {
- clear_drag_dest_row (dest);
- remove_hover_timer (dest);
- remove_expand_timer (dest);
- }
-
- if (path) {
- gtk_tree_path_free (path);
- }
-
- if (drop_path) {
- gtk_tree_path_free (drop_path);
- }
-
- if (old_drop_path) {
- gtk_tree_path_free (old_drop_path);
- }
-
- if (dest->details->scroll_id == 0) {
- dest->details->scroll_id =
- g_timeout_add (150,
- scroll_timeout,
- dest->details->tree_view);
- }
-
- gdk_drag_status (context, action, time);
-
- return TRUE;
+ NautilusTreeViewDragDest *dest;
+ GtkTreePath *path;
+ GtkTreePath *drop_path, *old_drop_path;
+ GtkTreeViewDropPosition pos;
+ GdkWindow *bin_window;
+ guint action;
+ gboolean res = TRUE;
+
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
+
+ gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (widget),
+ x, y, &path, &pos);
+ if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
+ pos == GTK_TREE_VIEW_DROP_AFTER)
+ {
+ gtk_tree_path_free (path);
+ path = NULL;
+ }
+
+ if (!dest->details->have_drag_data)
+ {
+ res = get_drag_data (dest, context, time);
+ }
+
+ if (!res)
+ {
+ return FALSE;
+ }
+
+ drop_path = get_drop_path (dest, path);
+
+ action = 0;
+ bin_window = gtk_tree_view_get_bin_window (GTK_TREE_VIEW (widget));
+ if (bin_window != NULL)
+ {
+ int bin_x, bin_y;
+ gdk_window_get_position (bin_window, &bin_x, &bin_y);
+ if (bin_y <= y)
+ {
+ /* ignore drags on the header */
+ action = get_drop_action (dest, context, drop_path);
+ }
+ }
+
+ gtk_tree_view_get_drag_dest_row (GTK_TREE_VIEW (widget), &old_drop_path,
+ NULL);
+
+ if (action)
+ {
+ set_drag_dest_row (dest, drop_path);
+ check_hover_expand_timer (dest, path, drop_path, old_drop_path);
+ }
+ else
+ {
+ clear_drag_dest_row (dest);
+ remove_hover_timer (dest);
+ remove_expand_timer (dest);
+ }
+
+ if (path)
+ {
+ gtk_tree_path_free (path);
+ }
+
+ if (drop_path)
+ {
+ gtk_tree_path_free (drop_path);
+ }
+
+ if (old_drop_path)
+ {
+ gtk_tree_path_free (old_drop_path);
+ }
+
+ if (dest->details->scroll_id == 0)
+ {
+ dest->details->scroll_id =
+ g_timeout_add (150,
+ scroll_timeout,
+ dest->details->tree_view);
+ }
+
+ gdk_drag_status (context, action, time);
+
+ return TRUE;
}
static void
-drag_leave_callback (GtkWidget *widget,
- GdkDragContext *context,
- guint32 time,
- gpointer data)
+drag_leave_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ guint32 time,
+ gpointer data)
{
- NautilusTreeViewDragDest *dest;
+ NautilusTreeViewDragDest *dest;
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
- clear_drag_dest_row (dest);
+ clear_drag_dest_row (dest);
- free_drag_data (dest);
+ free_drag_data (dest);
- remove_scroll_timeout (dest);
+ remove_scroll_timeout (dest);
}
static char *
-get_drop_target_uri_at_pos (NautilusTreeViewDragDest *dest, int x, int y)
+get_drop_target_uri_at_pos (NautilusTreeViewDragDest *dest,
+ int x,
+ int y)
{
- char *drop_target = NULL;
- GtkTreePath *path;
- GtkTreePath *drop_path;
- GtkTreeViewDropPosition pos;
-
- gtk_tree_view_get_dest_row_at_pos (dest->details->tree_view, x, y,
- &path, &pos);
- if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
- pos == GTK_TREE_VIEW_DROP_AFTER) {
- gtk_tree_path_free (path);
- path = NULL;
- }
-
- drop_path = get_drop_path (dest, path);
-
- drop_target = get_drop_target_uri_for_path (dest, drop_path);
-
- if (path != NULL) {
- gtk_tree_path_free (path);
- }
-
- if (drop_path != NULL) {
- gtk_tree_path_free (drop_path);
- }
-
- return drop_target;
+ char *drop_target = NULL;
+ GtkTreePath *path;
+ GtkTreePath *drop_path;
+ GtkTreeViewDropPosition pos;
+
+ gtk_tree_view_get_dest_row_at_pos (dest->details->tree_view, x, y,
+ &path, &pos);
+ if (pos == GTK_TREE_VIEW_DROP_BEFORE ||
+ pos == GTK_TREE_VIEW_DROP_AFTER)
+ {
+ gtk_tree_path_free (path);
+ path = NULL;
+ }
+
+ drop_path = get_drop_path (dest, path);
+
+ drop_target = get_drop_target_uri_for_path (dest, drop_path);
+
+ if (path != NULL)
+ {
+ gtk_tree_path_free (path);
+ }
+
+ if (drop_path != NULL)
+ {
+ gtk_tree_path_free (drop_path);
+ }
+
+ return drop_target;
}
static void
receive_uris (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- GList *source_uris,
- int x, int y)
+ GdkDragContext *context,
+ GList *source_uris,
+ int x,
+ int y)
{
- char *drop_target;
- GdkDragAction action, real_action;
-
- drop_target = get_drop_target_uri_at_pos (dest, x, y);
- g_assert (drop_target != NULL);
-
- real_action = gdk_drag_context_get_selected_action (context);
-
- if (real_action == GDK_ACTION_ASK) {
- if (nautilus_drag_selection_includes_special_link (dest->details->drag_list)) {
- /* We only want to move the trash */
- action = GDK_ACTION_MOVE;
- } else {
- action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
- }
- real_action = nautilus_drag_drop_action_ask
- (GTK_WIDGET (dest->details->tree_view), action);
- }
-
- /* We only want to copy external uris */
- if (dest->details->drag_type == NAUTILUS_ICON_DND_URI_LIST) {
- real_action = GDK_ACTION_COPY;
- }
-
- if (real_action > 0) {
- if (!nautilus_drag_uris_local (drop_target, source_uris)
- || real_action != GDK_ACTION_MOVE) {
- g_signal_emit (dest, signals[MOVE_COPY_ITEMS], 0,
- source_uris,
- drop_target,
- real_action,
- x, y);
- }
- }
-
- g_free (drop_target);
+ char *drop_target;
+ GdkDragAction action, real_action;
+
+ drop_target = get_drop_target_uri_at_pos (dest, x, y);
+ g_assert (drop_target != NULL);
+
+ real_action = gdk_drag_context_get_selected_action (context);
+
+ if (real_action == GDK_ACTION_ASK)
+ {
+ if (nautilus_drag_selection_includes_special_link (dest->details->drag_list))
+ {
+ /* We only want to move the trash */
+ action = GDK_ACTION_MOVE;
+ }
+ else
+ {
+ action = GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK;
+ }
+ real_action = nautilus_drag_drop_action_ask
+ (GTK_WIDGET (dest->details->tree_view), action);
+ }
+
+ /* We only want to copy external uris */
+ if (dest->details->drag_type == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ real_action = GDK_ACTION_COPY;
+ }
+
+ if (real_action > 0)
+ {
+ if (!nautilus_drag_uris_local (drop_target, source_uris)
+ || real_action != GDK_ACTION_MOVE)
+ {
+ g_signal_emit (dest, signals[MOVE_COPY_ITEMS], 0,
+ source_uris,
+ drop_target,
+ real_action,
+ x, y);
+ }
+ }
+
+ g_free (drop_target);
}
static void
receive_dropped_icons (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- GList *source_uris;
- GList *l;
-
- /* FIXME: ignore local only moves */
-
- if (!dest->details->drag_list) {
- return;
- }
-
- source_uris = NULL;
- for (l = dest->details->drag_list; l != NULL; l = l->next) {
- source_uris = g_list_prepend (source_uris,
- ((NautilusDragSelectionItem *)l->data)->uri);
- }
-
- source_uris = g_list_reverse (source_uris);
-
- receive_uris (dest, context, source_uris, x, y);
-
- g_list_free (source_uris);
+ GList *source_uris;
+ GList *l;
+
+ /* FIXME: ignore local only moves */
+
+ if (!dest->details->drag_list)
+ {
+ return;
+ }
+
+ source_uris = NULL;
+ for (l = dest->details->drag_list; l != NULL; l = l->next)
+ {
+ source_uris = g_list_prepend (source_uris,
+ ((NautilusDragSelectionItem *) l->data)->uri);
+ }
+
+ source_uris = g_list_reverse (source_uris);
+
+ receive_uris (dest, context, source_uris, x, y);
+
+ g_list_free (source_uris);
}
static void
receive_dropped_uri_list (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
+ char *drop_target;
- if (!dest->details->drag_data) {
- return;
- }
+ if (!dest->details->drag_data)
+ {
+ return;
+ }
- drop_target = get_drop_target_uri_at_pos (dest, x, y);
- g_assert (drop_target != NULL);
+ drop_target = get_drop_target_uri_at_pos (dest, x, y);
+ g_assert (drop_target != NULL);
- g_signal_emit (dest, signals[HANDLE_URI_LIST], 0,
- (char*) gtk_selection_data_get_data (dest->details->drag_data),
- drop_target,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ g_signal_emit (dest, signals[HANDLE_URI_LIST], 0,
+ (char *) gtk_selection_data_get_data (dest->details->drag_data),
+ drop_target,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (drop_target);
+ g_free (drop_target);
}
static void
receive_dropped_text (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
- guchar *text;
+ char *drop_target;
+ guchar *text;
- if (!dest->details->drag_data) {
- return;
- }
+ if (!dest->details->drag_data)
+ {
+ return;
+ }
- drop_target = get_drop_target_uri_at_pos (dest, x, y);
- g_assert (drop_target != NULL);
+ drop_target = get_drop_target_uri_at_pos (dest, x, y);
+ g_assert (drop_target != NULL);
- text = gtk_selection_data_get_text (dest->details->drag_data);
- g_signal_emit (dest, signals[HANDLE_TEXT], 0,
- (char *) text, drop_target,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ text = gtk_selection_data_get_text (dest->details->drag_data);
+ g_signal_emit (dest, signals[HANDLE_TEXT], 0,
+ (char *) text, drop_target,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (text);
- g_free (drop_target);
+ g_free (text);
+ g_free (drop_target);
}
static void
receive_dropped_raw (NautilusTreeViewDragDest *dest,
- const char *raw_data, int length,
- GdkDragContext *context,
- int x, int y)
+ const char *raw_data,
+ int length,
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
+ char *drop_target;
- if (!dest->details->drag_data) {
- return;
- }
+ if (!dest->details->drag_data)
+ {
+ return;
+ }
- drop_target = get_drop_target_uri_at_pos (dest, x, y);
- g_assert (drop_target != NULL);
+ drop_target = get_drop_target_uri_at_pos (dest, x, y);
+ g_assert (drop_target != NULL);
- g_signal_emit (dest, signals[HANDLE_RAW], 0,
- raw_data, length, drop_target,
- dest->details->direct_save_uri,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ g_signal_emit (dest, signals[HANDLE_RAW], 0,
+ raw_data, length, drop_target,
+ dest->details->direct_save_uri,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (drop_target);
+ g_free (drop_target);
}
static void
receive_dropped_netscape_url (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- char *drop_target;
+ char *drop_target;
- if (!dest->details->drag_data) {
- return;
- }
+ if (!dest->details->drag_data)
+ {
+ return;
+ }
- drop_target = get_drop_target_uri_at_pos (dest, x, y);
- g_assert (drop_target != NULL);
+ drop_target = get_drop_target_uri_at_pos (dest, x, y);
+ g_assert (drop_target != NULL);
- g_signal_emit (dest, signals[HANDLE_NETSCAPE_URL], 0,
- (char*) gtk_selection_data_get_data (dest->details->drag_data),
- drop_target,
- gdk_drag_context_get_selected_action (context),
- x, y);
+ g_signal_emit (dest, signals[HANDLE_NETSCAPE_URL], 0,
+ (char *) gtk_selection_data_get_data (dest->details->drag_data),
+ drop_target,
+ gdk_drag_context_get_selected_action (context),
+ x, y);
- g_free (drop_target);
+ g_free (drop_target);
}
static gboolean
receive_xds (NautilusTreeViewDragDest *dest,
- GtkWidget *widget,
- guint32 time,
- GdkDragContext *context,
- int x, int y)
+ GtkWidget *widget,
+ guint32 time,
+ GdkDragContext *context,
+ int x,
+ int y)
{
- GFile *location;
- const guchar *selection_data;
- gint selection_format;
- gint selection_length;
-
- selection_data = gtk_selection_data_get_data (dest->details->drag_data);
- selection_format = gtk_selection_data_get_format (dest->details->drag_data);
- selection_length = gtk_selection_data_get_length (dest->details->drag_data);
-
- if (selection_format == 8
- && selection_length == 1
- && selection_data[0] == 'F') {
- gtk_drag_get_data (widget, context,
- gdk_atom_intern (NAUTILUS_ICON_DND_RAW_TYPE,
- FALSE),
- time);
- return FALSE;
- } else if (selection_format == 8
- && selection_length == 1
- && selection_data[0] == 'S') {
- g_assert (dest->details->direct_save_uri != NULL);
- location = g_file_new_for_uri (dest->details->direct_save_uri);
-
- nautilus_file_changes_queue_file_added (location);
- nautilus_file_changes_consume_changes (TRUE);
-
- g_object_unref (location);
- }
- return TRUE;
+ GFile *location;
+ const guchar *selection_data;
+ gint selection_format;
+ gint selection_length;
+
+ selection_data = gtk_selection_data_get_data (dest->details->drag_data);
+ selection_format = gtk_selection_data_get_format (dest->details->drag_data);
+ selection_length = gtk_selection_data_get_length (dest->details->drag_data);
+
+ if (selection_format == 8
+ && selection_length == 1
+ && selection_data[0] == 'F')
+ {
+ gtk_drag_get_data (widget, context,
+ gdk_atom_intern (NAUTILUS_ICON_DND_RAW_TYPE,
+ FALSE),
+ time);
+ return FALSE;
+ }
+ else if (selection_format == 8
+ && selection_length == 1
+ && selection_data[0] == 'S')
+ {
+ g_assert (dest->details->direct_save_uri != NULL);
+ location = g_file_new_for_uri (dest->details->direct_save_uri);
+
+ nautilus_file_changes_queue_file_added (location);
+ nautilus_file_changes_consume_changes (TRUE);
+
+ g_object_unref (location);
+ }
+ return TRUE;
}
static gboolean
-drag_data_received_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- GtkSelectionData *selection_data,
- guint info,
- guint32 time,
- gpointer data)
+drag_data_received_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint32 time,
+ gpointer data)
{
- NautilusTreeViewDragDest *dest;
- const gchar *tmp;
- int length;
- gboolean success, finished;
-
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
-
- if (!dest->details->have_drag_data) {
- dest->details->have_drag_data = TRUE;
- dest->details->drag_type = info;
- dest->details->drag_data =
- gtk_selection_data_copy (selection_data);
- if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
- dest->details->drag_list =
- nautilus_drag_build_selection_list (selection_data);
- }
- }
-
- if (dest->details->drop_occurred) {
- success = FALSE;
- finished = TRUE;
- switch (info) {
- case NAUTILUS_ICON_DND_GNOME_ICON_LIST :
- receive_dropped_icons (dest, context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_NETSCAPE_URL :
- receive_dropped_netscape_url (dest, context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_URI_LIST :
- receive_dropped_uri_list (dest, context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_TEXT:
- receive_dropped_text (dest, context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_RAW:
- length = gtk_selection_data_get_length (selection_data);
- tmp = (const gchar *) gtk_selection_data_get_data (selection_data);
- receive_dropped_raw (dest, tmp, length, context, x, y);
- success = TRUE;
- break;
- case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
- finished = receive_xds (dest, widget, time, context, x, y);
- success = TRUE;
- break;
- }
-
- if (finished) {
- dest->details->drop_occurred = FALSE;
- free_drag_data (dest);
- gtk_drag_finish (context, success, FALSE, time);
- }
- }
-
- /* appease GtkTreeView by preventing its drag_data_receive
- * from being called */
- g_signal_stop_emission_by_name (dest->details->tree_view,
- "drag-data-received");
-
- return TRUE;
+ NautilusTreeViewDragDest *dest;
+ const gchar *tmp;
+ int length;
+ gboolean success, finished;
+
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
+
+ if (!dest->details->have_drag_data)
+ {
+ dest->details->have_drag_data = TRUE;
+ dest->details->drag_type = info;
+ dest->details->drag_data =
+ gtk_selection_data_copy (selection_data);
+ if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ dest->details->drag_list =
+ nautilus_drag_build_selection_list (selection_data);
+ }
+ }
+
+ if (dest->details->drop_occurred)
+ {
+ success = FALSE;
+ finished = TRUE;
+ switch (info)
+ {
+ case NAUTILUS_ICON_DND_GNOME_ICON_LIST:
+ {
+ receive_dropped_icons (dest, context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_NETSCAPE_URL:
+ {
+ receive_dropped_netscape_url (dest, context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_URI_LIST:
+ {
+ receive_dropped_uri_list (dest, context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_TEXT:
+ {
+ receive_dropped_text (dest, context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_RAW:
+ {
+ length = gtk_selection_data_get_length (selection_data);
+ tmp = (const gchar *) gtk_selection_data_get_data (selection_data);
+ receive_dropped_raw (dest, tmp, length, context, x, y);
+ success = TRUE;
+ }
+ break;
+
+ case NAUTILUS_ICON_DND_XDNDDIRECTSAVE:
+ {
+ finished = receive_xds (dest, widget, time, context, x, y);
+ success = TRUE;
+ }
+ break;
+ }
+
+ if (finished)
+ {
+ dest->details->drop_occurred = FALSE;
+ free_drag_data (dest);
+ gtk_drag_finish (context, success, FALSE, time);
+ }
+ }
+
+ /* appease GtkTreeView by preventing its drag_data_receive
+ * from being called */
+ g_signal_stop_emission_by_name (dest->details->tree_view,
+ "drag-data-received");
+
+ return TRUE;
}
static char *
get_direct_save_filename (GdkDragContext *context)
{
- guchar *prop_text;
- gint prop_len;
-
- if (!gdk_property_get (gdk_drag_context_get_source_window (context), gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
- gdk_atom_intern ("text/plain", FALSE), 0, 1024, FALSE, NULL, NULL,
- &prop_len, &prop_text)) {
- return NULL;
- }
-
- /* Zero-terminate the string */
- prop_text = g_realloc (prop_text, prop_len + 1);
- prop_text[prop_len] = '\0';
-
- /* Verify that the file name provided by the source is valid */
- if (*prop_text == '\0' ||
- strchr ((const gchar *) prop_text, G_DIR_SEPARATOR) != NULL) {
- DEBUG ("Invalid filename provided by XDS drag site");
- g_free (prop_text);
- return NULL;
- }
-
- return (gchar *) prop_text;
+ guchar *prop_text;
+ gint prop_len;
+
+ if (!gdk_property_get (gdk_drag_context_get_source_window (context), gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
+ gdk_atom_intern ("text/plain", FALSE), 0, 1024, FALSE, NULL, NULL,
+ &prop_len, &prop_text))
+ {
+ return NULL;
+ }
+
+ /* Zero-terminate the string */
+ prop_text = g_realloc (prop_text, prop_len + 1);
+ prop_text[prop_len] = '\0';
+
+ /* Verify that the file name provided by the source is valid */
+ if (*prop_text == '\0' ||
+ strchr ((const gchar *) prop_text, G_DIR_SEPARATOR) != NULL)
+ {
+ DEBUG ("Invalid filename provided by XDS drag site");
+ g_free (prop_text);
+ return NULL;
+ }
+
+ return (gchar *) prop_text;
}
static gboolean
set_direct_save_uri (NautilusTreeViewDragDest *dest,
- GdkDragContext *context,
- int x, int y)
+ GdkDragContext *context,
+ int x,
+ int y)
{
- GFile *base, *child;
- char *drop_uri;
- char *filename, *uri;
-
- g_assert (dest->details->direct_save_uri == NULL);
-
- uri = NULL;
-
- drop_uri = get_drop_target_uri_at_pos (dest, x, y);
- if (drop_uri != NULL) {
- filename = get_direct_save_filename (context);
- if (filename != NULL) {
- /* Resolve relative path */
- base = g_file_new_for_uri (drop_uri);
- child = g_file_get_child (base, filename);
- uri = g_file_get_uri (child);
-
- g_object_unref (base);
- g_object_unref (child);
-
- /* Change the property */
- gdk_property_change (gdk_drag_context_get_source_window (context),
- gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
- gdk_atom_intern ("text/plain", FALSE), 8,
- GDK_PROP_MODE_REPLACE, (const guchar *) uri,
- strlen (uri));
-
- dest->details->direct_save_uri = uri;
- } else {
- DEBUG ("Invalid filename provided by XDS drag site");
- }
- } else {
- DEBUG ("Could not retrieve XDS drop destination");
- }
-
- return uri != NULL;
+ GFile *base, *child;
+ char *drop_uri;
+ char *filename, *uri;
+
+ g_assert (dest->details->direct_save_uri == NULL);
+
+ uri = NULL;
+
+ drop_uri = get_drop_target_uri_at_pos (dest, x, y);
+ if (drop_uri != NULL)
+ {
+ filename = get_direct_save_filename (context);
+ if (filename != NULL)
+ {
+ /* Resolve relative path */
+ base = g_file_new_for_uri (drop_uri);
+ child = g_file_get_child (base, filename);
+ uri = g_file_get_uri (child);
+
+ g_object_unref (base);
+ g_object_unref (child);
+
+ /* Change the property */
+ gdk_property_change (gdk_drag_context_get_source_window (context),
+ gdk_atom_intern (NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, FALSE),
+ gdk_atom_intern ("text/plain", FALSE), 8,
+ GDK_PROP_MODE_REPLACE, (const guchar *) uri,
+ strlen (uri));
+
+ dest->details->direct_save_uri = uri;
+ }
+ else
+ {
+ DEBUG ("Invalid filename provided by XDS drag site");
+ }
+ }
+ else
+ {
+ DEBUG ("Could not retrieve XDS drop destination");
+ }
+
+ return uri != NULL;
}
static gboolean
-drag_drop_callback (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- guint32 time,
- gpointer data)
+drag_drop_callback (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ guint32 time,
+ gpointer data)
{
- NautilusTreeViewDragDest *dest;
- guint info;
- GdkAtom target;
-
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
-
- target = gtk_drag_dest_find_target (GTK_WIDGET (dest->details->tree_view),
- context,
- NULL);
- if (target == GDK_NONE) {
- return FALSE;
- }
-
- info = dest->details->drag_type;
-
- if (info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE) {
- /* We need to set this or get_drop_path will fail, and it
- was unset by drag_leave_callback */
- dest->details->have_drag_data = TRUE;
- if (!set_direct_save_uri (dest, context, x, y)) {
- return FALSE;
- }
- dest->details->have_drag_data = FALSE;
- }
-
- dest->details->drop_occurred = TRUE;
-
- get_drag_data (dest, context, time);
- remove_scroll_timeout (dest);
- clear_drag_dest_row (dest);
-
- return TRUE;
+ NautilusTreeViewDragDest *dest;
+ guint info;
+ GdkAtom target;
+
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (data);
+
+ target = gtk_drag_dest_find_target (GTK_WIDGET (dest->details->tree_view),
+ context,
+ NULL);
+ if (target == GDK_NONE)
+ {
+ return FALSE;
+ }
+
+ info = dest->details->drag_type;
+
+ if (info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE)
+ {
+ /* We need to set this or get_drop_path will fail, and it
+ * was unset by drag_leave_callback */
+ dest->details->have_drag_data = TRUE;
+ if (!set_direct_save_uri (dest, context, x, y))
+ {
+ return FALSE;
+ }
+ dest->details->have_drag_data = FALSE;
+ }
+
+ dest->details->drop_occurred = TRUE;
+
+ get_drag_data (dest, context, time);
+ remove_scroll_timeout (dest);
+ clear_drag_dest_row (dest);
+
+ return TRUE;
}
static void
-tree_view_weak_notify (gpointer user_data,
- GObject *object)
+tree_view_weak_notify (gpointer user_data,
+ GObject *object)
{
- NautilusTreeViewDragDest *dest;
+ NautilusTreeViewDragDest *dest;
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (user_data);
-
- remove_scroll_timeout (dest);
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (user_data);
- dest->details->tree_view = NULL;
+ remove_scroll_timeout (dest);
+
+ dest->details->tree_view = NULL;
}
static void
nautilus_tree_view_drag_dest_dispose (GObject *object)
{
- NautilusTreeViewDragDest *dest;
-
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (object);
-
- if (dest->details->tree_view) {
- g_object_weak_unref (G_OBJECT (dest->details->tree_view),
- tree_view_weak_notify,
- dest);
- }
-
- remove_scroll_timeout (dest);
-
- G_OBJECT_CLASS (nautilus_tree_view_drag_dest_parent_class)->dispose (object);
+ NautilusTreeViewDragDest *dest;
+
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (object);
+
+ if (dest->details->tree_view)
+ {
+ g_object_weak_unref (G_OBJECT (dest->details->tree_view),
+ tree_view_weak_notify,
+ dest);
+ }
+
+ remove_scroll_timeout (dest);
+
+ G_OBJECT_CLASS (nautilus_tree_view_drag_dest_parent_class)->dispose (object);
}
static void
nautilus_tree_view_drag_dest_finalize (GObject *object)
{
- NautilusTreeViewDragDest *dest;
-
- dest = NAUTILUS_TREE_VIEW_DRAG_DEST (object);
- free_drag_data (dest);
+ NautilusTreeViewDragDest *dest;
+
+ dest = NAUTILUS_TREE_VIEW_DRAG_DEST (object);
+ free_drag_data (dest);
- G_OBJECT_CLASS (nautilus_tree_view_drag_dest_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_tree_view_drag_dest_parent_class)->finalize (object);
}
static void
nautilus_tree_view_drag_dest_init (NautilusTreeViewDragDest *dest)
{
- dest->details = G_TYPE_INSTANCE_GET_PRIVATE (dest, NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST,
- NautilusTreeViewDragDestDetails);
+ dest->details = G_TYPE_INSTANCE_GET_PRIVATE (dest, NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST,
+ NautilusTreeViewDragDestDetails);
}
static void
nautilus_tree_view_drag_dest_class_init (NautilusTreeViewDragDestClass *class)
{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (class);
-
- gobject_class->dispose = nautilus_tree_view_drag_dest_dispose;
- gobject_class->finalize = nautilus_tree_view_drag_dest_finalize;
-
- g_type_class_add_private (class, sizeof (NautilusTreeViewDragDestDetails));
-
- signals[GET_ROOT_URI] =
- g_signal_new ("get-root-uri",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- get_root_uri),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_STRING, 0);
- signals[GET_FILE_FOR_PATH] =
- g_signal_new ("get-file-for-path",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- get_file_for_path),
- NULL, NULL,
- g_cclosure_marshal_generic,
- NAUTILUS_TYPE_FILE, 1,
- GTK_TYPE_TREE_PATH);
- signals[MOVE_COPY_ITEMS] =
- g_signal_new ("move-copy-items",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- move_copy_items),
- NULL, NULL,
-
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_POINTER,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_NETSCAPE_URL] =
- g_signal_new ("handle-netscape-url",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- handle_netscape_url),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_URI_LIST] =
- g_signal_new ("handle-uri-list",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- handle_uri_list),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_TEXT] =
- g_signal_new ("handle-text",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- handle_text),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 5,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_RAW] =
- g_signal_new ("handle-raw",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- handle_raw),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 7,
- G_TYPE_POINTER,
- G_TYPE_INT,
- G_TYPE_STRING,
- G_TYPE_STRING,
- GDK_TYPE_DRAG_ACTION,
- G_TYPE_INT,
- G_TYPE_INT);
- signals[HANDLE_HOVER] =
- g_signal_new ("handle-hover",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
- handle_hover),
- NULL, NULL,
- g_cclosure_marshal_generic,
- G_TYPE_NONE, 1,
- G_TYPE_STRING);
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (class);
+
+ gobject_class->dispose = nautilus_tree_view_drag_dest_dispose;
+ gobject_class->finalize = nautilus_tree_view_drag_dest_finalize;
+
+ g_type_class_add_private (class, sizeof (NautilusTreeViewDragDestDetails));
+
+ signals[GET_ROOT_URI] =
+ g_signal_new ("get-root-uri",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ get_root_uri),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_STRING, 0);
+ signals[GET_FILE_FOR_PATH] =
+ g_signal_new ("get-file-for-path",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ get_file_for_path),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ NAUTILUS_TYPE_FILE, 1,
+ GTK_TYPE_TREE_PATH);
+ signals[MOVE_COPY_ITEMS] =
+ g_signal_new ("move-copy-items",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ move_copy_items),
+ NULL, NULL,
+
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_POINTER,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_NETSCAPE_URL] =
+ g_signal_new ("handle-netscape-url",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ handle_netscape_url),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_URI_LIST] =
+ g_signal_new ("handle-uri-list",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ handle_uri_list),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_TEXT] =
+ g_signal_new ("handle-text",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ handle_text),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 5,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_RAW] =
+ g_signal_new ("handle-raw",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ handle_raw),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 7,
+ G_TYPE_POINTER,
+ G_TYPE_INT,
+ G_TYPE_STRING,
+ G_TYPE_STRING,
+ GDK_TYPE_DRAG_ACTION,
+ G_TYPE_INT,
+ G_TYPE_INT);
+ signals[HANDLE_HOVER] =
+ g_signal_new ("handle-hover",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusTreeViewDragDestClass,
+ handle_hover),
+ NULL, NULL,
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
}
@@ -1228,38 +1356,38 @@ nautilus_tree_view_drag_dest_class_init (NautilusTreeViewDragDestClass *class)
NautilusTreeViewDragDest *
nautilus_tree_view_drag_dest_new (GtkTreeView *tree_view)
{
- NautilusTreeViewDragDest *dest;
- GtkTargetList *targets;
-
- dest = g_object_new (NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST, NULL);
-
- dest->details->tree_view = tree_view;
- g_object_weak_ref (G_OBJECT (dest->details->tree_view),
- tree_view_weak_notify, dest);
-
- gtk_drag_dest_set (GTK_WIDGET (tree_view),
- 0, drag_types, G_N_ELEMENTS (drag_types),
- GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK);
-
- targets = gtk_drag_dest_get_target_list (GTK_WIDGET (tree_view));
- gtk_target_list_add_text_targets (targets, NAUTILUS_ICON_DND_TEXT);
-
- g_signal_connect_object (tree_view,
- "drag-motion",
- G_CALLBACK (drag_motion_callback),
- dest, 0);
- g_signal_connect_object (tree_view,
- "drag-leave",
- G_CALLBACK (drag_leave_callback),
- dest, 0);
- g_signal_connect_object (tree_view,
- "drag-drop",
- G_CALLBACK (drag_drop_callback),
- dest, 0);
- g_signal_connect_object (tree_view,
- "drag-data-received",
- G_CALLBACK (drag_data_received_callback),
- dest, 0);
-
- return dest;
+ NautilusTreeViewDragDest *dest;
+ GtkTargetList *targets;
+
+ dest = g_object_new (NAUTILUS_TYPE_TREE_VIEW_DRAG_DEST, NULL);
+
+ dest->details->tree_view = tree_view;
+ g_object_weak_ref (G_OBJECT (dest->details->tree_view),
+ tree_view_weak_notify, dest);
+
+ gtk_drag_dest_set (GTK_WIDGET (tree_view),
+ 0, drag_types, G_N_ELEMENTS (drag_types),
+ GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_ASK);
+
+ targets = gtk_drag_dest_get_target_list (GTK_WIDGET (tree_view));
+ gtk_target_list_add_text_targets (targets, NAUTILUS_ICON_DND_TEXT);
+
+ g_signal_connect_object (tree_view,
+ "drag-motion",
+ G_CALLBACK (drag_motion_callback),
+ dest, 0);
+ g_signal_connect_object (tree_view,
+ "drag-leave",
+ G_CALLBACK (drag_leave_callback),
+ dest, 0);
+ g_signal_connect_object (tree_view,
+ "drag-drop",
+ G_CALLBACK (drag_drop_callback),
+ dest, 0);
+ g_signal_connect_object (tree_view,
+ "drag-data-received",
+ G_CALLBACK (drag_data_received_callback),
+ dest, 0);
+
+ return dest;
}
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 837178bc0..fedbb484b 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -1,24 +1,23 @@
-
/* nautilus-ui-utilities.c - helper functions for GtkUIManager stuff
-
- Copyright (C) 2004 Red Hat, Inc.
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Authors: Alexander Larsson <alexl@redhat.com>
-*/
+ *
+ * Copyright (C) 2004 Red Hat, Inc.
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Alexander Larsson <alexl@redhat.com>
+ */
#include <config.h>
@@ -34,52 +33,66 @@
static GMenuModel *
find_gmenu_model (GMenuModel *model,
- const gchar *model_id)
+ const gchar *model_id)
{
- gint i, n_items;
- GMenuModel *insertion_model = NULL;
-
- n_items = g_menu_model_get_n_items (model);
-
- for (i = 0; i < n_items && !insertion_model; i++) {
- gchar *id = NULL;
- if (g_menu_model_get_item_attribute (model, i, "id", "s", &id) &&
- g_strcmp0 (id, model_id) == 0) {
- insertion_model = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
- if (!insertion_model)
- insertion_model = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU);
- } else {
- GMenuModel *submodel;
- GMenuModel *submenu;
- gint j, j_items;
-
- submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
-
- if (!submodel)
- submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU);
-
- if (!submodel)
- continue;
-
- j_items = g_menu_model_get_n_items (submodel);
- for (j = 0; j < j_items; j++) {
- submenu = g_menu_model_get_item_link (submodel, j, G_MENU_LINK_SUBMENU);
- if (submenu) {
- insertion_model = find_gmenu_model (submenu, model_id);
- g_object_unref (submenu);
- }
-
- if (insertion_model)
- break;
- }
-
- g_object_unref (submodel);
- }
-
- g_free (id);
- }
-
- return insertion_model;
+ gint i, n_items;
+ GMenuModel *insertion_model = NULL;
+
+ n_items = g_menu_model_get_n_items (model);
+
+ for (i = 0; i < n_items && !insertion_model; i++)
+ {
+ gchar *id = NULL;
+ if (g_menu_model_get_item_attribute (model, i, "id", "s", &id) &&
+ g_strcmp0 (id, model_id) == 0)
+ {
+ insertion_model = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
+ if (!insertion_model)
+ {
+ insertion_model = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU);
+ }
+ }
+ else
+ {
+ GMenuModel *submodel;
+ GMenuModel *submenu;
+ gint j, j_items;
+
+ submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION);
+
+ if (!submodel)
+ {
+ submodel = g_menu_model_get_item_link (model, i, G_MENU_LINK_SUBMENU);
+ }
+
+ if (!submodel)
+ {
+ continue;
+ }
+
+ j_items = g_menu_model_get_n_items (submodel);
+ for (j = 0; j < j_items; j++)
+ {
+ submenu = g_menu_model_get_item_link (submodel, j, G_MENU_LINK_SUBMENU);
+ if (submenu)
+ {
+ insertion_model = find_gmenu_model (submenu, model_id);
+ g_object_unref (submenu);
+ }
+
+ if (insertion_model)
+ {
+ break;
+ }
+ }
+
+ g_object_unref (submodel);
+ }
+
+ g_free (id);
+ }
+
+ return insertion_model;
}
/*
@@ -89,33 +102,38 @@ find_gmenu_model (GMenuModel *model,
*/
void
nautilus_gmenu_merge (GMenu *original,
- GMenu *gmenu_to_merge,
- const gchar *submodel_name,
- gboolean prepend)
+ GMenu *gmenu_to_merge,
+ const gchar *submodel_name,
+ gboolean prepend)
{
- gint i, n_items;
- GMenuModel *submodel;
- GMenuItem *item;
+ gint i, n_items;
+ GMenuModel *submodel;
+ GMenuItem *item;
- g_return_if_fail (G_IS_MENU (original));
- g_return_if_fail (G_IS_MENU (gmenu_to_merge));
+ g_return_if_fail (G_IS_MENU (original));
+ g_return_if_fail (G_IS_MENU (gmenu_to_merge));
- submodel = find_gmenu_model (G_MENU_MODEL (original), submodel_name);
+ submodel = find_gmenu_model (G_MENU_MODEL (original), submodel_name);
- g_return_if_fail (submodel != NULL);
+ g_return_if_fail (submodel != NULL);
- n_items = g_menu_model_get_n_items (G_MENU_MODEL (gmenu_to_merge));
+ n_items = g_menu_model_get_n_items (G_MENU_MODEL (gmenu_to_merge));
- for (i = 0; i < n_items; i++) {
- item = g_menu_item_new_from_model (G_MENU_MODEL (gmenu_to_merge), i);
- if (prepend)
- g_menu_prepend_item (G_MENU (submodel), item);
- else
- g_menu_append_item (G_MENU (submodel), item);
- g_object_unref (item);
- }
+ for (i = 0; i < n_items; i++)
+ {
+ item = g_menu_item_new_from_model (G_MENU_MODEL (gmenu_to_merge), i);
+ if (prepend)
+ {
+ g_menu_prepend_item (G_MENU (submodel), item);
+ }
+ else
+ {
+ g_menu_append_item (G_MENU (submodel), item);
+ }
+ g_object_unref (item);
+ }
- g_object_unref (submodel);
+ g_object_unref (submodel);
}
/*
@@ -124,111 +142,145 @@ nautilus_gmenu_merge (GMenu *original,
*/
void
nautilus_gmenu_add_item_in_submodel (GMenu *menu,
- GMenuItem *item,
- const gchar *submodel_name,
- gboolean prepend)
+ GMenuItem *item,
+ const gchar *submodel_name,
+ gboolean prepend)
{
- GMenuModel *submodel;
+ GMenuModel *submodel;
- g_return_if_fail (G_IS_MENU (menu));
- g_return_if_fail (G_IS_MENU_ITEM (item));
+ g_return_if_fail (G_IS_MENU (menu));
+ g_return_if_fail (G_IS_MENU_ITEM (item));
- submodel = find_gmenu_model (G_MENU_MODEL (menu), submodel_name);
+ submodel = find_gmenu_model (G_MENU_MODEL (menu), submodel_name);
- g_return_if_fail (submodel != NULL);
- if (prepend)
- g_menu_prepend_item (G_MENU (submodel), item);
- else
- g_menu_append_item (G_MENU (submodel), item);
+ g_return_if_fail (submodel != NULL);
+ if (prepend)
+ {
+ g_menu_prepend_item (G_MENU (submodel), item);
+ }
+ else
+ {
+ g_menu_append_item (G_MENU (submodel), item);
+ }
- g_object_unref (submodel);
+ g_object_unref (submodel);
}
void
nautilus_pop_up_context_menu (GtkWidget *parent,
- GMenu *menu,
- GdkEventButton *event)
+ GMenu *menu,
+ GdkEventButton *event)
{
- GtkWidget *gtk_menu;
-
- int button;
-
- g_return_if_fail (G_IS_MENU (menu));
- g_return_if_fail (GTK_IS_WIDGET (parent));
-
- gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
- gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
-
- /* The event button needs to be 0 if we're popping up this menu from
- * a button release, else a 2nd click outside the menu with any button
- * other than the one that invoked the menu will be ignored (instead
- * of dismissing the menu). This is a subtle fragility of the GTK menu code.
- */
- if (event) {
- button = event->type == GDK_BUTTON_RELEASE
- ? 0
- : event->button;
- } else {
- button = 0;
- }
-
- gtk_menu_popup (GTK_MENU (gtk_menu), /* menu */
- NULL, /* parent_menu_shell */
- NULL, /* parent_menu_item */
- NULL, /* popup_position_func */
- NULL, /* popup_position_data */
- button, /* button */
- event ? event->time : gtk_get_current_event_time ()); /* activate_time */
-
- g_object_ref_sink (gtk_menu);
- g_object_unref (gtk_menu);
+ GtkWidget *gtk_menu;
+
+ int button;
+
+ g_return_if_fail (G_IS_MENU (menu));
+ g_return_if_fail (GTK_IS_WIDGET (parent));
+
+ gtk_menu = gtk_menu_new_from_model (G_MENU_MODEL (menu));
+ gtk_menu_attach_to_widget (GTK_MENU (gtk_menu), parent, NULL);
+
+ /* The event button needs to be 0 if we're popping up this menu from
+ * a button release, else a 2nd click outside the menu with any button
+ * other than the one that invoked the menu will be ignored (instead
+ * of dismissing the menu). This is a subtle fragility of the GTK menu code.
+ */
+ if (event)
+ {
+ button = event->type == GDK_BUTTON_RELEASE
+ ? 0
+ : event->button;
+ }
+ else
+ {
+ button = 0;
+ }
+
+ gtk_menu_popup (GTK_MENU (gtk_menu), /* menu */
+ NULL, /* parent_menu_shell */
+ NULL, /* parent_menu_item */
+ NULL, /* popup_position_func */
+ NULL, /* popup_position_data */
+ button, /* button */
+ event ? event->time : gtk_get_current_event_time ()); /* activate_time */
+
+ g_object_ref_sink (gtk_menu);
+ g_object_unref (gtk_menu);
}
char *
nautilus_escape_action_name (const char *action_name,
- const char *prefix)
+ const char *prefix)
{
- GString *s;
-
- if (action_name == NULL) {
- return NULL;
- }
-
- s = g_string_new (prefix);
-
- while (*action_name != 0) {
- switch (*action_name) {
- case '\\':
- g_string_append (s, "\\\\");
- break;
- case '/':
- g_string_append (s, "\\s");
- break;
- case '&':
- g_string_append (s, "\\a");
- break;
- case '"':
- g_string_append (s, "\\q");
- break;
- case ' ':
- g_string_append (s, "+");
- break;
- case '(':
- g_string_append (s, "#");
- break;
- case ')':
- g_string_append (s, "^");
- break;
- case ':':
- g_string_append (s, "\\\\");
- break;
- default:
- g_string_append_c (s, *action_name);
- }
-
- action_name ++;
- }
- return g_string_free (s, FALSE);
+ GString *s;
+
+ if (action_name == NULL)
+ {
+ return NULL;
+ }
+
+ s = g_string_new (prefix);
+
+ while (*action_name != 0)
+ {
+ switch (*action_name)
+ {
+ case '\\':
+ {
+ g_string_append (s, "\\\\");
+ }
+ break;
+
+ case '/':
+ {
+ g_string_append (s, "\\s");
+ }
+ break;
+
+ case '&':
+ {
+ g_string_append (s, "\\a");
+ }
+ break;
+
+ case '"':
+ {
+ g_string_append (s, "\\q");
+ }
+ break;
+
+ case ' ':
+ {
+ g_string_append (s, "+");
+ }
+ break;
+
+ case '(':
+ {
+ g_string_append (s, "#");
+ }
+ break;
+
+ case ')':
+ {
+ g_string_append (s, "^");
+ }
+ break;
+
+ case ':':
+ {
+ g_string_append (s, "\\\\");
+ }
+ break;
+
+ default:
+ g_string_append_c (s, *action_name);
+ }
+
+ action_name++;
+ }
+ return g_string_free (s, FALSE);
}
#define NAUTILUS_THUMBNAIL_FRAME_LEFT 3
@@ -239,20 +291,20 @@ nautilus_escape_action_name (const char *action_name,
void
nautilus_ui_frame_image (GdkPixbuf **pixbuf)
{
- GtkBorder border;
- GdkPixbuf *pixbuf_with_frame;
+ GtkBorder border;
+ GdkPixbuf *pixbuf_with_frame;
- border.left = NAUTILUS_THUMBNAIL_FRAME_LEFT;
- border.top = NAUTILUS_THUMBNAIL_FRAME_TOP;
- border.right = NAUTILUS_THUMBNAIL_FRAME_RIGHT;
- border.bottom = NAUTILUS_THUMBNAIL_FRAME_BOTTOM;
+ border.left = NAUTILUS_THUMBNAIL_FRAME_LEFT;
+ border.top = NAUTILUS_THUMBNAIL_FRAME_TOP;
+ border.right = NAUTILUS_THUMBNAIL_FRAME_RIGHT;
+ border.bottom = NAUTILUS_THUMBNAIL_FRAME_BOTTOM;
- pixbuf_with_frame = gd_embed_image_in_frame (*pixbuf,
- "resource:///org/gnome/nautilus/icons/thumbnail_frame.png",
- &border, &border);
- g_object_unref (*pixbuf);
+ pixbuf_with_frame = gd_embed_image_in_frame (*pixbuf,
+ "resource:///org/gnome/nautilus/icons/thumbnail_frame.png",
+ &border, &border);
+ g_object_unref (*pixbuf);
- *pixbuf = pixbuf_with_frame;
+ *pixbuf = pixbuf_with_frame;
}
static GdkPixbuf *filmholes_left = NULL;
@@ -261,47 +313,53 @@ static GdkPixbuf *filmholes_right = NULL;
static gboolean
ensure_filmholes (void)
{
- if (filmholes_left == NULL) {
- filmholes_left = gdk_pixbuf_new_from_resource ("/org/gnome/nautilus/icons/filmholes.png", NULL);
- }
- if (filmholes_right == NULL &&
- filmholes_left != NULL) {
- filmholes_right = gdk_pixbuf_flip (filmholes_left, TRUE);
- }
-
- return (filmholes_left && filmholes_right);
+ if (filmholes_left == NULL)
+ {
+ filmholes_left = gdk_pixbuf_new_from_resource ("/org/gnome/nautilus/icons/filmholes.png", NULL);
+ }
+ if (filmholes_right == NULL &&
+ filmholes_left != NULL)
+ {
+ filmholes_right = gdk_pixbuf_flip (filmholes_left, TRUE);
+ }
+
+ return (filmholes_left && filmholes_right);
}
void
nautilus_ui_frame_video (GdkPixbuf **pixbuf)
{
- int width, height;
- int holes_width, holes_height;
- int i;
-
- if (!ensure_filmholes ())
- return;
-
- width = gdk_pixbuf_get_width (*pixbuf);
- height = gdk_pixbuf_get_height (*pixbuf);
- holes_width = gdk_pixbuf_get_width (filmholes_left);
- holes_height = gdk_pixbuf_get_height (filmholes_left);
-
- for (i = 0; i < height; i += holes_height) {
- gdk_pixbuf_composite (filmholes_left, *pixbuf, 0, i,
- MIN (width, holes_width),
- MIN (height - i, holes_height),
- 0, i, 1, 1, GDK_INTERP_NEAREST, 255);
- }
-
- for (i = 0; i < height; i += holes_height) {
- gdk_pixbuf_composite (filmholes_right, *pixbuf,
- width - holes_width, i,
- MIN (width, holes_width),
- MIN (height - i, holes_height),
- width - holes_width, i,
- 1, 1, GDK_INTERP_NEAREST, 255);
- }
+ int width, height;
+ int holes_width, holes_height;
+ int i;
+
+ if (!ensure_filmholes ())
+ {
+ return;
+ }
+
+ width = gdk_pixbuf_get_width (*pixbuf);
+ height = gdk_pixbuf_get_height (*pixbuf);
+ holes_width = gdk_pixbuf_get_width (filmholes_left);
+ holes_height = gdk_pixbuf_get_height (filmholes_left);
+
+ for (i = 0; i < height; i += holes_height)
+ {
+ gdk_pixbuf_composite (filmholes_left, *pixbuf, 0, i,
+ MIN (width, holes_width),
+ MIN (height - i, holes_height),
+ 0, i, 1, 1, GDK_INTERP_NEAREST, 255);
+ }
+
+ for (i = 0; i < height; i += holes_height)
+ {
+ gdk_pixbuf_composite (filmholes_right, *pixbuf,
+ width - holes_width, i,
+ MIN (width, holes_width),
+ MIN (height - i, holes_height),
+ width - holes_width, i,
+ 1, 1, GDK_INTERP_NEAREST, 255);
+ }
}
gboolean
@@ -309,107 +367,108 @@ nautilus_file_date_in_between (guint64 unix_file_time,
GDateTime *initial_date,
GDateTime *end_date)
{
- GDateTime *date;
- gboolean in_between;
+ GDateTime *date;
+ gboolean in_between;
- /* Silently ignore errors */
- if (unix_file_time == 0)
+ /* Silently ignore errors */
+ if (unix_file_time == 0)
{
- return FALSE;
+ return FALSE;
}
- date = g_date_time_new_from_unix_local (unix_file_time);
+ date = g_date_time_new_from_unix_local (unix_file_time);
- /* For the end date, we want to make end_date inclusive,
- * for that the difference between the start of the day and the in_between
- * has to be more than -1 day
- */
- in_between = g_date_time_difference (date, initial_date) > 0 &&
- g_date_time_difference (end_date, date) / G_TIME_SPAN_DAY > -1;
+ /* For the end date, we want to make end_date inclusive,
+ * for that the difference between the start of the day and the in_between
+ * has to be more than -1 day
+ */
+ in_between = g_date_time_difference (date, initial_date) > 0 &&
+ g_date_time_difference (end_date, date) / G_TIME_SPAN_DAY > -1;
- g_date_time_unref (date);
+ g_date_time_unref (date);
- return in_between;
+ return in_between;
}
-static const gchar*
+static const gchar *
get_text_for_days_ago (gint days)
{
- if (days < 7)
+ if (days < 7)
{
- /* days */
- return ngettext ("%d day ago", "%d days ago", days);
+ /* days */
+ return ngettext ("%d day ago", "%d days ago", days);
}
- else if (days < 30)
+ else if (days < 30)
{
- /* weeks */
- return ngettext ("Last week", "%d weeks ago", days / 7);
+ /* weeks */
+ return ngettext ("Last week", "%d weeks ago", days / 7);
}
- else if (days < 365)
+ else if (days < 365)
{
- /* months */
- return ngettext ("Last month", "%d months ago", days / 30);
+ /* months */
+ return ngettext ("Last month", "%d months ago", days / 30);
}
- else
+ else
{
- /* years */
- return ngettext ("Last year", "%d years ago", days / 365);
+ /* years */
+ return ngettext ("Last year", "%d years ago", days / 365);
}
}
-gchar*
+gchar *
get_text_for_date_range (GPtrArray *date_range)
{
- gint days;
- gint normalized;
- GDateTime *initial_date;
- GDateTime *end_date;
- gchar *formatted_date;
- gchar *label;
-
- if (!date_range)
- return NULL;
-
- initial_date = g_ptr_array_index (date_range, 0);
- end_date = g_ptr_array_index (date_range, 1);
- days = g_date_time_difference (end_date, initial_date) / G_TIME_SPAN_DAY;
- formatted_date = g_date_time_format (initial_date, "%x");
-
- if (days < 1)
+ gint days;
+ gint normalized;
+ GDateTime *initial_date;
+ GDateTime *end_date;
+ gchar *formatted_date;
+ gchar *label;
+
+ if (!date_range)
+ {
+ return NULL;
+ }
+
+ initial_date = g_ptr_array_index (date_range, 0);
+ end_date = g_ptr_array_index (date_range, 1);
+ days = g_date_time_difference (end_date, initial_date) / G_TIME_SPAN_DAY;
+ formatted_date = g_date_time_format (initial_date, "%x");
+
+ if (days < 1)
{
- label = g_strdup (formatted_date);
+ label = g_strdup (formatted_date);
}
- else
+ else
{
- if (days < 7)
+ if (days < 7)
{
- /* days */
- normalized = days;
+ /* days */
+ normalized = days;
}
- else if (days < 30)
+ else if (days < 30)
{
- /* weeks */
- normalized = days / 7;
+ /* weeks */
+ normalized = days / 7;
}
- else if (days < 365)
+ else if (days < 365)
{
- /* months */
- normalized = days / 30;
+ /* months */
+ normalized = days / 30;
}
- else
+ else
{
- /* years */
- normalized = days / 365;
+ /* years */
+ normalized = days / 365;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
- label = g_strdup_printf (get_text_for_days_ago (days), normalized);
+ label = g_strdup_printf (get_text_for_days_ago (days), normalized);
#pragma GCC diagnostic pop
}
g_free (formatted_date);
- return label;
+ return label;
}
-
diff --git a/src/nautilus-vfs-directory.c b/src/nautilus-vfs-directory.c
index 778102b98..2f8f67cfb 100644
--- a/src/nautilus-vfs-directory.c
+++ b/src/nautilus-vfs-directory.c
@@ -1,24 +1,24 @@
/*
- nautilus-vfs-directory.c: Subclass of NautilusDirectory to help implement the
- virtual trash directory.
-
- Copyright (C) 1999, 2000 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * nautilus-vfs-directory.c: Subclass of NautilusDirectory to help implement the
+ * virtual trash directory.
+ *
+ * Copyright (C) 1999, 2000 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
#include "nautilus-vfs-directory.h"
@@ -31,122 +31,121 @@ G_DEFINE_TYPE (NautilusVFSDirectory, nautilus_vfs_directory, NAUTILUS_TYPE_DIREC
static void
nautilus_vfs_directory_init (NautilusVFSDirectory *directory)
{
-
}
static gboolean
vfs_contains_file (NautilusDirectory *directory,
- NautilusFile *file)
+ NautilusFile *file)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
- g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_FILE (file));
- return file->details->directory == directory;
+ return file->details->directory == directory;
}
static void
-vfs_call_when_ready (NautilusDirectory *directory,
- NautilusFileAttributes file_attributes,
- gboolean wait_for_file_list,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+vfs_call_when_ready (NautilusDirectory *directory,
+ NautilusFileAttributes file_attributes,
+ gboolean wait_for_file_list,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
-
- nautilus_directory_call_when_ready_internal
- (directory,
- NULL,
- file_attributes,
- wait_for_file_list,
- callback,
- NULL,
- callback_data);
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+
+ nautilus_directory_call_when_ready_internal
+ (directory,
+ NULL,
+ file_attributes,
+ wait_for_file_list,
+ callback,
+ NULL,
+ callback_data);
}
static void
-vfs_cancel_callback (NautilusDirectory *directory,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+vfs_cancel_callback (NautilusDirectory *directory,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
-
- nautilus_directory_cancel_callback_internal
- (directory,
- NULL,
- callback,
- NULL,
- callback_data);
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+
+ nautilus_directory_cancel_callback_internal
+ (directory,
+ NULL,
+ callback,
+ NULL,
+ callback_data);
}
static void
-vfs_file_monitor_add (NautilusDirectory *directory,
- gconstpointer client,
- gboolean monitor_hidden_files,
- NautilusFileAttributes file_attributes,
- NautilusDirectoryCallback callback,
- gpointer callback_data)
+vfs_file_monitor_add (NautilusDirectory *directory,
+ gconstpointer client,
+ gboolean monitor_hidden_files,
+ NautilusFileAttributes file_attributes,
+ NautilusDirectoryCallback callback,
+ gpointer callback_data)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
- g_assert (client != NULL);
-
- nautilus_directory_monitor_add_internal
- (directory, NULL,
- client,
- monitor_hidden_files,
- file_attributes,
- callback, callback_data);
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+ g_assert (client != NULL);
+
+ nautilus_directory_monitor_add_internal
+ (directory, NULL,
+ client,
+ monitor_hidden_files,
+ file_attributes,
+ callback, callback_data);
}
static void
vfs_file_monitor_remove (NautilusDirectory *directory,
- gconstpointer client)
+ gconstpointer client)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
- g_assert (client != NULL);
-
- nautilus_directory_monitor_remove_internal (directory, NULL, client);
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+ g_assert (client != NULL);
+
+ nautilus_directory_monitor_remove_internal (directory, NULL, client);
}
static void
vfs_force_reload (NautilusDirectory *directory)
{
- NautilusFileAttributes all_attributes;
+ NautilusFileAttributes all_attributes;
- g_assert (NAUTILUS_IS_DIRECTORY (directory));
+ g_assert (NAUTILUS_IS_DIRECTORY (directory));
- all_attributes = nautilus_file_get_all_attributes ();
- nautilus_directory_force_reload_internal (directory,
- all_attributes);
+ all_attributes = nautilus_file_get_all_attributes ();
+ nautilus_directory_force_reload_internal (directory,
+ all_attributes);
}
static gboolean
vfs_are_all_files_seen (NautilusDirectory *directory)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
-
- return directory->details->directory_loaded;
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+
+ return directory->details->directory_loaded;
}
static gboolean
vfs_is_not_empty (NautilusDirectory *directory)
{
- g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
- g_assert (nautilus_directory_is_anyone_monitoring_file_list (directory));
+ g_assert (NAUTILUS_IS_VFS_DIRECTORY (directory));
+ g_assert (nautilus_directory_is_anyone_monitoring_file_list (directory));
- return directory->details->file_list != NULL;
+ return directory->details->file_list != NULL;
}
static void
nautilus_vfs_directory_class_init (NautilusVFSDirectoryClass *klass)
{
- NautilusDirectoryClass *directory_class = NAUTILUS_DIRECTORY_CLASS (klass);
-
- directory_class->contains_file = vfs_contains_file;
- directory_class->call_when_ready = vfs_call_when_ready;
- directory_class->cancel_callback = vfs_cancel_callback;
- directory_class->file_monitor_add = vfs_file_monitor_add;
- directory_class->file_monitor_remove = vfs_file_monitor_remove;
- directory_class->force_reload = vfs_force_reload;
- directory_class->are_all_files_seen = vfs_are_all_files_seen;
- directory_class->is_not_empty = vfs_is_not_empty;
+ NautilusDirectoryClass *directory_class = NAUTILUS_DIRECTORY_CLASS (klass);
+
+ directory_class->contains_file = vfs_contains_file;
+ directory_class->call_when_ready = vfs_call_when_ready;
+ directory_class->cancel_callback = vfs_cancel_callback;
+ directory_class->file_monitor_add = vfs_file_monitor_add;
+ directory_class->file_monitor_remove = vfs_file_monitor_remove;
+ directory_class->force_reload = vfs_force_reload;
+ directory_class->are_all_files_seen = vfs_are_all_files_seen;
+ directory_class->is_not_empty = vfs_is_not_empty;
}
diff --git a/src/nautilus-vfs-file.c b/src/nautilus-vfs-file.c
index 0a37be573..0fff497f3 100644
--- a/src/nautilus-vfs-file.c
+++ b/src/nautilus-vfs-file.c
@@ -1,24 +1,24 @@
/*
- nautilus-vfs-file.c: Subclass of NautilusFile to help implement the
- virtual trash directory.
-
- Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
-
- Author: Darin Adler <darin@bentspoon.com>
-*/
+ * nautilus-vfs-file.c: Subclass of NautilusFile to help implement the
+ * virtual trash directory.
+ *
+ * Copyright (C) 1999, 2000, 2001 Eazel, 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Darin Adler <darin@bentspoon.com>
+ */
#include <config.h>
#include "nautilus-vfs-file.h"
@@ -30,640 +30,700 @@
G_DEFINE_TYPE (NautilusVFSFile, nautilus_vfs_file, NAUTILUS_TYPE_FILE);
-static void
-vfs_file_monitor_add (NautilusFile *file,
- gconstpointer client,
- NautilusFileAttributes attributes)
-{
- nautilus_directory_monitor_add_internal
- (file->details->directory, file,
- client, TRUE, attributes, NULL, NULL);
-}
-
static void
-vfs_file_monitor_remove (NautilusFile *file,
- gconstpointer client)
+vfs_file_monitor_add (NautilusFile *file,
+ gconstpointer client,
+ NautilusFileAttributes attributes)
{
- nautilus_directory_monitor_remove_internal
- (file->details->directory, file, client);
-}
+ nautilus_directory_monitor_add_internal
+ (file->details->directory, file,
+ client, TRUE, attributes, NULL, NULL);
+}
static void
-vfs_file_call_when_ready (NautilusFile *file,
- NautilusFileAttributes file_attributes,
- NautilusFileCallback callback,
- gpointer callback_data)
+vfs_file_monitor_remove (NautilusFile *file,
+ gconstpointer client)
+{
+ nautilus_directory_monitor_remove_internal
+ (file->details->directory, file, client);
+}
+static void
+vfs_file_call_when_ready (NautilusFile *file,
+ NautilusFileAttributes file_attributes,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- nautilus_directory_call_when_ready_internal
- (file->details->directory, file,
- file_attributes, FALSE, NULL, callback, callback_data);
+ nautilus_directory_call_when_ready_internal
+ (file->details->directory, file,
+ file_attributes, FALSE, NULL, callback, callback_data);
}
static void
-vfs_file_cancel_call_when_ready (NautilusFile *file,
- NautilusFileCallback callback,
- gpointer callback_data)
+vfs_file_cancel_call_when_ready (NautilusFile *file,
+ NautilusFileCallback callback,
+ gpointer callback_data)
{
- nautilus_directory_cancel_callback_internal
- (file->details->directory, file,
- NULL, callback, callback_data);
+ nautilus_directory_cancel_callback_internal
+ (file->details->directory, file,
+ NULL, callback, callback_data);
}
static gboolean
-vfs_file_check_if_ready (NautilusFile *file,
- NautilusFileAttributes file_attributes)
+vfs_file_check_if_ready (NautilusFile *file,
+ NautilusFileAttributes file_attributes)
{
- return nautilus_directory_check_if_ready_internal
- (file->details->directory, file,
- file_attributes);
+ return nautilus_directory_check_if_ready_internal
+ (file->details->directory, file,
+ file_attributes);
}
static void
-set_metadata_get_info_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+set_metadata_get_info_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFile *file;
- GFileInfo *new_info;
- GError *error;
-
- file = callback_data;
-
- error = NULL;
- new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
- if (new_info != NULL) {
- if (nautilus_file_update_info (file, new_info)) {
- nautilus_file_changed (file);
- }
- g_object_unref (new_info);
- }
- nautilus_file_unref (file);
- if (error) {
- g_error_free (error);
- }
+ NautilusFile *file;
+ GFileInfo *new_info;
+ GError *error;
+
+ file = callback_data;
+
+ error = NULL;
+ new_info = g_file_query_info_finish (G_FILE (source_object), res, &error);
+ if (new_info != NULL)
+ {
+ if (nautilus_file_update_info (file, new_info))
+ {
+ nautilus_file_changed (file);
+ }
+ g_object_unref (new_info);
+ }
+ nautilus_file_unref (file);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-set_metadata_callback (GObject *source_object,
- GAsyncResult *result,
- gpointer callback_data)
+set_metadata_callback (GObject *source_object,
+ GAsyncResult *result,
+ gpointer callback_data)
{
- NautilusFile *file;
- GError *error;
- gboolean res;
-
- file = callback_data;
-
- error = NULL;
- res = g_file_set_attributes_finish (G_FILE (source_object),
- result,
- NULL,
- &error);
-
- if (res) {
- g_file_query_info_async (G_FILE (source_object),
- NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
- 0,
- G_PRIORITY_DEFAULT,
- NULL,
- set_metadata_get_info_callback, file);
- } else {
- nautilus_file_unref (file);
- g_error_free (error);
- }
+ NautilusFile *file;
+ GError *error;
+ gboolean res;
+
+ file = callback_data;
+
+ error = NULL;
+ res = g_file_set_attributes_finish (G_FILE (source_object),
+ result,
+ NULL,
+ &error);
+
+ if (res)
+ {
+ g_file_query_info_async (G_FILE (source_object),
+ NAUTILUS_FILE_DEFAULT_ATTRIBUTES,
+ 0,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ set_metadata_get_info_callback, file);
+ }
+ else
+ {
+ nautilus_file_unref (file);
+ g_error_free (error);
+ }
}
static void
-vfs_file_set_metadata (NautilusFile *file,
- const char *key,
- const char *value)
+vfs_file_set_metadata (NautilusFile *file,
+ const char *key,
+ const char *value)
{
- GFileInfo *info;
- GFile *location;
- char *gio_key;
-
- info = g_file_info_new ();
-
- gio_key = g_strconcat ("metadata::", key, NULL);
- if (value != NULL) {
- g_file_info_set_attribute_string (info, gio_key, value);
- } else {
- /* Unset the key */
- g_file_info_set_attribute (info, gio_key,
- G_FILE_ATTRIBUTE_TYPE_INVALID,
- NULL);
- }
- g_free (gio_key);
-
- location = nautilus_file_get_location (file);
- g_file_set_attributes_async (location,
- info,
- 0,
- G_PRIORITY_DEFAULT,
- NULL,
- set_metadata_callback,
- nautilus_file_ref (file));
- g_object_unref (location);
- g_object_unref (info);
+ GFileInfo *info;
+ GFile *location;
+ char *gio_key;
+
+ info = g_file_info_new ();
+
+ gio_key = g_strconcat ("metadata::", key, NULL);
+ if (value != NULL)
+ {
+ g_file_info_set_attribute_string (info, gio_key, value);
+ }
+ else
+ {
+ /* Unset the key */
+ g_file_info_set_attribute (info, gio_key,
+ G_FILE_ATTRIBUTE_TYPE_INVALID,
+ NULL);
+ }
+ g_free (gio_key);
+
+ location = nautilus_file_get_location (file);
+ g_file_set_attributes_async (location,
+ info,
+ 0,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ set_metadata_callback,
+ nautilus_file_ref (file));
+ g_object_unref (location);
+ g_object_unref (info);
}
static void
-vfs_file_set_metadata_as_list (NautilusFile *file,
- const char *key,
- char **value)
+vfs_file_set_metadata_as_list (NautilusFile *file,
+ const char *key,
+ char **value)
{
- GFile *location;
- GFileInfo *info;
- char *gio_key;
-
- info = g_file_info_new ();
-
- gio_key = g_strconcat ("metadata::", key, NULL);
- g_file_info_set_attribute_stringv (info, gio_key, value);
- g_free (gio_key);
-
- location = nautilus_file_get_location (file);
- g_file_set_attributes_async (location,
- info,
- 0,
- G_PRIORITY_DEFAULT,
- NULL,
- set_metadata_callback,
- nautilus_file_ref (file));
- g_object_unref (info);
- g_object_unref (location);
+ GFile *location;
+ GFileInfo *info;
+ char *gio_key;
+
+ info = g_file_info_new ();
+
+ gio_key = g_strconcat ("metadata::", key, NULL);
+ g_file_info_set_attribute_stringv (info, gio_key, value);
+ g_free (gio_key);
+
+ location = nautilus_file_get_location (file);
+ g_file_set_attributes_async (location,
+ info,
+ 0,
+ G_PRIORITY_DEFAULT,
+ NULL,
+ set_metadata_callback,
+ nautilus_file_ref (file));
+ g_object_unref (info);
+ g_object_unref (location);
}
static gboolean
-vfs_file_get_item_count (NautilusFile *file,
- guint *count,
- gboolean *count_unreadable)
+vfs_file_get_item_count (NautilusFile *file,
+ guint *count,
+ gboolean *count_unreadable)
{
- if (count_unreadable != NULL) {
- *count_unreadable = file->details->directory_count_failed;
- }
- if (!file->details->got_directory_count) {
- if (count != NULL) {
- *count = 0;
- }
- return FALSE;
- }
- if (count != NULL) {
- *count = file->details->directory_count;
- }
- return TRUE;
+ if (count_unreadable != NULL)
+ {
+ *count_unreadable = file->details->directory_count_failed;
+ }
+ if (!file->details->got_directory_count)
+ {
+ if (count != NULL)
+ {
+ *count = 0;
+ }
+ return FALSE;
+ }
+ if (count != NULL)
+ {
+ *count = file->details->directory_count;
+ }
+ return TRUE;
}
static NautilusRequestStatus
vfs_file_get_deep_counts (NautilusFile *file,
- guint *directory_count,
- guint *file_count,
- guint *unreadable_directory_count,
- goffset *total_size)
+ guint *directory_count,
+ guint *file_count,
+ guint *unreadable_directory_count,
+ goffset *total_size)
{
- GFileType type;
-
- if (directory_count != NULL) {
- *directory_count = 0;
- }
- if (file_count != NULL) {
- *file_count = 0;
- }
- if (unreadable_directory_count != NULL) {
- *unreadable_directory_count = 0;
- }
- if (total_size != NULL) {
- *total_size = 0;
- }
-
- if (!nautilus_file_is_directory (file)) {
- return NAUTILUS_REQUEST_DONE;
- }
-
- if (file->details->deep_counts_status != NAUTILUS_REQUEST_NOT_STARTED) {
- if (directory_count != NULL) {
- *directory_count = file->details->deep_directory_count;
- }
- if (file_count != NULL) {
- *file_count = file->details->deep_file_count;
- }
- if (unreadable_directory_count != NULL) {
- *unreadable_directory_count = file->details->deep_unreadable_count;
- }
- if (total_size != NULL) {
- *total_size = file->details->deep_size;
- }
- return file->details->deep_counts_status;
- }
-
- /* For directories, or before we know the type, we haven't started. */
- type = nautilus_file_get_file_type (file);
- if (type == G_FILE_TYPE_UNKNOWN
- || type == G_FILE_TYPE_DIRECTORY) {
- return NAUTILUS_REQUEST_NOT_STARTED;
- }
-
- /* For other types, we are done, and the zeros are permanent. */
- return NAUTILUS_REQUEST_DONE;
+ GFileType type;
+
+ if (directory_count != NULL)
+ {
+ *directory_count = 0;
+ }
+ if (file_count != NULL)
+ {
+ *file_count = 0;
+ }
+ if (unreadable_directory_count != NULL)
+ {
+ *unreadable_directory_count = 0;
+ }
+ if (total_size != NULL)
+ {
+ *total_size = 0;
+ }
+
+ if (!nautilus_file_is_directory (file))
+ {
+ return NAUTILUS_REQUEST_DONE;
+ }
+
+ if (file->details->deep_counts_status != NAUTILUS_REQUEST_NOT_STARTED)
+ {
+ if (directory_count != NULL)
+ {
+ *directory_count = file->details->deep_directory_count;
+ }
+ if (file_count != NULL)
+ {
+ *file_count = file->details->deep_file_count;
+ }
+ if (unreadable_directory_count != NULL)
+ {
+ *unreadable_directory_count = file->details->deep_unreadable_count;
+ }
+ if (total_size != NULL)
+ {
+ *total_size = file->details->deep_size;
+ }
+ return file->details->deep_counts_status;
+ }
+
+ /* For directories, or before we know the type, we haven't started. */
+ type = nautilus_file_get_file_type (file);
+ if (type == G_FILE_TYPE_UNKNOWN
+ || type == G_FILE_TYPE_DIRECTORY)
+ {
+ return NAUTILUS_REQUEST_NOT_STARTED;
+ }
+
+ /* For other types, we are done, and the zeros are permanent. */
+ return NAUTILUS_REQUEST_DONE;
}
static gboolean
-vfs_file_get_date (NautilusFile *file,
- NautilusDateType date_type,
- time_t *date)
+vfs_file_get_date (NautilusFile *file,
+ NautilusDateType date_type,
+ time_t *date)
{
- switch (date_type) {
- case NAUTILUS_DATE_TYPE_ACCESSED:
- /* Before we have info on a file, the date is unknown. */
- if (file->details->atime == 0) {
- return FALSE;
- }
- if (date != NULL) {
- *date = file->details->atime;
- }
- return TRUE;
- case NAUTILUS_DATE_TYPE_MODIFIED:
- /* Before we have info on a file, the date is unknown. */
- if (file->details->mtime == 0) {
- return FALSE;
- }
- if (date != NULL) {
- *date = file->details->mtime;
- }
- return TRUE;
- case NAUTILUS_DATE_TYPE_TRASHED:
- /* Before we have info on a file, the date is unknown. */
- if (file->details->trash_time == 0) {
- return FALSE;
- }
- if (date != NULL) {
- *date = file->details->trash_time;
- }
- return TRUE;
- }
- return FALSE;
+ switch (date_type)
+ {
+ case NAUTILUS_DATE_TYPE_ACCESSED:
+ {
+ /* Before we have info on a file, the date is unknown. */
+ if (file->details->atime == 0)
+ {
+ return FALSE;
+ }
+ if (date != NULL)
+ {
+ *date = file->details->atime;
+ }
+ return TRUE;
+ }
+
+ case NAUTILUS_DATE_TYPE_MODIFIED:
+ {
+ /* Before we have info on a file, the date is unknown. */
+ if (file->details->mtime == 0)
+ {
+ return FALSE;
+ }
+ if (date != NULL)
+ {
+ *date = file->details->mtime;
+ }
+ return TRUE;
+ }
+
+ case NAUTILUS_DATE_TYPE_TRASHED:
+ /* Before we have info on a file, the date is unknown. */
+ if (file->details->trash_time == 0)
+ {
+ return FALSE;
+ }
+ if (date != NULL)
+ {
+ *date = file->details->trash_time;
+ }
+ return TRUE;
+ }
+ return FALSE;
}
static char *
vfs_file_get_where_string (NautilusFile *file)
{
- GFile *activation_location;
- NautilusFile *location;
- char *where_string;
-
- if (!nautilus_file_is_in_recent (file)) {
- location = nautilus_file_ref (file);
- } else {
- activation_location = nautilus_file_get_activation_location (file);
- location = nautilus_file_get (activation_location);
- g_object_unref (activation_location);
- }
-
- where_string = nautilus_file_get_parent_uri_for_display (location);
-
- nautilus_file_unref (location);
- return where_string;
+ GFile *activation_location;
+ NautilusFile *location;
+ char *where_string;
+
+ if (!nautilus_file_is_in_recent (file))
+ {
+ location = nautilus_file_ref (file);
+ }
+ else
+ {
+ activation_location = nautilus_file_get_activation_location (file);
+ location = nautilus_file_get (activation_location);
+ g_object_unref (activation_location);
+ }
+
+ where_string = nautilus_file_get_parent_uri_for_display (location);
+
+ nautilus_file_unref (location);
+ return where_string;
}
static void
-vfs_file_mount_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+vfs_file_mount_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- GFile *mounted_on;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- mounted_on = g_file_mount_mountable_finish (G_FILE (source_object),
- res, &error);
- nautilus_file_operation_complete (op, mounted_on, error);
- if (mounted_on) {
- g_object_unref (mounted_on);
- }
- if (error) {
- g_error_free (error);
- }
+ NautilusFileOperation *op;
+ GFile *mounted_on;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ mounted_on = g_file_mount_mountable_finish (G_FILE (source_object),
+ res, &error);
+ nautilus_file_operation_complete (op, mounted_on, error);
+ if (mounted_on)
+ {
+ g_object_unref (mounted_on);
+ }
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-vfs_file_mount (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+vfs_file_mount (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- GError *error;
- GFile *location;
-
- if (file->details->type != G_FILE_TYPE_MOUNTABLE) {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be mounted"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- return;
- }
-
- op = nautilus_file_operation_new (file, callback, callback_data);
- if (cancellable) {
- g_object_unref (op->cancellable);
- op->cancellable = g_object_ref (cancellable);
- }
-
- location = nautilus_file_get_location (file);
- g_file_mount_mountable (location,
- 0,
- mount_op,
- op->cancellable,
- vfs_file_mount_callback,
- op);
- g_object_unref (location);
+ NautilusFileOperation *op;
+ GError *error;
+ GFile *location;
+
+ if (file->details->type != G_FILE_TYPE_MOUNTABLE)
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be mounted"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ return;
+ }
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ if (cancellable)
+ {
+ g_object_unref (op->cancellable);
+ op->cancellable = g_object_ref (cancellable);
+ }
+
+ location = nautilus_file_get_location (file);
+ g_file_mount_mountable (location,
+ 0,
+ mount_op,
+ op->cancellable,
+ vfs_file_mount_callback,
+ op);
+ g_object_unref (location);
}
static void
-vfs_file_unmount_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+vfs_file_unmount_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- gboolean unmounted;
- GError *error;
+ NautilusFileOperation *op;
+ gboolean unmounted;
+ GError *error;
+
+ op = callback_data;
- op = callback_data;
+ error = NULL;
+ unmounted = g_file_unmount_mountable_with_operation_finish (G_FILE (source_object),
+ res, &error);
- error = NULL;
- unmounted = g_file_unmount_mountable_with_operation_finish (G_FILE (source_object),
- res, &error);
-
if (!unmounted &&
- error->domain == G_IO_ERROR &&
- (error->code == G_IO_ERROR_FAILED_HANDLED ||
- error->code == G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
- error = NULL;
+ error->domain == G_IO_ERROR &&
+ (error->code == G_IO_ERROR_FAILED_HANDLED ||
+ error->code == G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ error = NULL;
}
nautilus_file_operation_complete (op, G_FILE (source_object), error);
- if (error) {
- g_error_free (error);
- }
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-vfs_file_unmount (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+vfs_file_unmount (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- GFile *location;
-
- op = nautilus_file_operation_new (file, callback, callback_data);
- if (cancellable) {
- g_object_unref (op->cancellable);
- op->cancellable = g_object_ref (cancellable);
- }
-
- location = nautilus_file_get_location (file);
- g_file_unmount_mountable_with_operation (location,
- G_MOUNT_UNMOUNT_NONE,
- mount_op,
- op->cancellable,
- vfs_file_unmount_callback,
- op);
- g_object_unref (location);
+ NautilusFileOperation *op;
+ GFile *location;
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ if (cancellable)
+ {
+ g_object_unref (op->cancellable);
+ op->cancellable = g_object_ref (cancellable);
+ }
+
+ location = nautilus_file_get_location (file);
+ g_file_unmount_mountable_with_operation (location,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_op,
+ op->cancellable,
+ vfs_file_unmount_callback,
+ op);
+ g_object_unref (location);
}
static void
-vfs_file_eject_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+vfs_file_eject_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- gboolean ejected;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- ejected = g_file_eject_mountable_with_operation_finish (G_FILE (source_object),
- res, &error);
-
- if (!ejected &&
- error->domain == G_IO_ERROR &&
- (error->code == G_IO_ERROR_FAILED_HANDLED ||
- error->code == G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
- error = NULL;
- }
-
- nautilus_file_operation_complete (op, G_FILE (source_object), error);
- if (error) {
- g_error_free (error);
- }
+ NautilusFileOperation *op;
+ gboolean ejected;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ ejected = g_file_eject_mountable_with_operation_finish (G_FILE (source_object),
+ res, &error);
+
+ if (!ejected &&
+ error->domain == G_IO_ERROR &&
+ (error->code == G_IO_ERROR_FAILED_HANDLED ||
+ error->code == G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ error = NULL;
+ }
+
+ nautilus_file_operation_complete (op, G_FILE (source_object), error);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-vfs_file_eject (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+vfs_file_eject (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- GFile *location;
-
- op = nautilus_file_operation_new (file, callback, callback_data);
- if (cancellable) {
- g_object_unref (op->cancellable);
- op->cancellable = g_object_ref (cancellable);
- }
-
- location = nautilus_file_get_location (file);
- g_file_eject_mountable_with_operation (location,
- G_MOUNT_UNMOUNT_NONE,
- mount_op,
- op->cancellable,
- vfs_file_eject_callback,
- op);
- g_object_unref (location);
+ NautilusFileOperation *op;
+ GFile *location;
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ if (cancellable)
+ {
+ g_object_unref (op->cancellable);
+ op->cancellable = g_object_ref (cancellable);
+ }
+
+ location = nautilus_file_get_location (file);
+ g_file_eject_mountable_with_operation (location,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_op,
+ op->cancellable,
+ vfs_file_eject_callback,
+ op);
+ g_object_unref (location);
}
static void
-vfs_file_start_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+vfs_file_start_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- gboolean started;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- started = g_file_start_mountable_finish (G_FILE (source_object),
- res, &error);
-
- if (!started &&
- error->domain == G_IO_ERROR &&
- (error->code == G_IO_ERROR_FAILED_HANDLED ||
- error->code == G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
- error = NULL;
- }
-
- nautilus_file_operation_complete (op, G_FILE (source_object), error);
- if (error) {
- g_error_free (error);
- }
+ NautilusFileOperation *op;
+ gboolean started;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ started = g_file_start_mountable_finish (G_FILE (source_object),
+ res, &error);
+
+ if (!started &&
+ error->domain == G_IO_ERROR &&
+ (error->code == G_IO_ERROR_FAILED_HANDLED ||
+ error->code == G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ error = NULL;
+ }
+
+ nautilus_file_operation_complete (op, G_FILE (source_object), error);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-vfs_file_start (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+vfs_file_start (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- GError *error;
- GFile *location;
-
- if (file->details->type != G_FILE_TYPE_MOUNTABLE) {
- if (callback) {
- error = NULL;
- g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
- _("This file cannot be started"));
- callback (file, NULL, error, callback_data);
- g_error_free (error);
- }
- return;
- }
-
- op = nautilus_file_operation_new (file, callback, callback_data);
- if (cancellable) {
- g_object_unref (op->cancellable);
- op->cancellable = g_object_ref (cancellable);
- }
-
- location = nautilus_file_get_location (file);
- g_file_start_mountable (location,
- 0,
- mount_op,
- op->cancellable,
- vfs_file_start_callback,
- op);
- g_object_unref (location);
+ NautilusFileOperation *op;
+ GError *error;
+ GFile *location;
+
+ if (file->details->type != G_FILE_TYPE_MOUNTABLE)
+ {
+ if (callback)
+ {
+ error = NULL;
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ _("This file cannot be started"));
+ callback (file, NULL, error, callback_data);
+ g_error_free (error);
+ }
+ return;
+ }
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ if (cancellable)
+ {
+ g_object_unref (op->cancellable);
+ op->cancellable = g_object_ref (cancellable);
+ }
+
+ location = nautilus_file_get_location (file);
+ g_file_start_mountable (location,
+ 0,
+ mount_op,
+ op->cancellable,
+ vfs_file_start_callback,
+ op);
+ g_object_unref (location);
}
static void
-vfs_file_stop_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+vfs_file_stop_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- gboolean stopped;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- stopped = g_file_stop_mountable_finish (G_FILE (source_object),
- res, &error);
-
- if (!stopped &&
- error->domain == G_IO_ERROR &&
- (error->code == G_IO_ERROR_FAILED_HANDLED ||
- error->code == G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
- error = NULL;
- }
-
- nautilus_file_operation_complete (op, G_FILE (source_object), error);
- if (error) {
- g_error_free (error);
- }
+ NautilusFileOperation *op;
+ gboolean stopped;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ stopped = g_file_stop_mountable_finish (G_FILE (source_object),
+ res, &error);
+
+ if (!stopped &&
+ error->domain == G_IO_ERROR &&
+ (error->code == G_IO_ERROR_FAILED_HANDLED ||
+ error->code == G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ error = NULL;
+ }
+
+ nautilus_file_operation_complete (op, G_FILE (source_object), error);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
-vfs_file_stop (NautilusFile *file,
- GMountOperation *mount_op,
- GCancellable *cancellable,
- NautilusFileOperationCallback callback,
- gpointer callback_data)
+vfs_file_stop (NautilusFile *file,
+ GMountOperation *mount_op,
+ GCancellable *cancellable,
+ NautilusFileOperationCallback callback,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- GFile *location;
-
- op = nautilus_file_operation_new (file, callback, callback_data);
- if (cancellable) {
- g_object_unref (op->cancellable);
- op->cancellable = g_object_ref (cancellable);
- }
-
- location = nautilus_file_get_location (file);
- g_file_stop_mountable (location,
- G_MOUNT_UNMOUNT_NONE,
- mount_op,
- op->cancellable,
- vfs_file_stop_callback,
- op);
- g_object_unref (location);
+ NautilusFileOperation *op;
+ GFile *location;
+
+ op = nautilus_file_operation_new (file, callback, callback_data);
+ if (cancellable)
+ {
+ g_object_unref (op->cancellable);
+ op->cancellable = g_object_ref (cancellable);
+ }
+
+ location = nautilus_file_get_location (file);
+ g_file_stop_mountable (location,
+ G_MOUNT_UNMOUNT_NONE,
+ mount_op,
+ op->cancellable,
+ vfs_file_stop_callback,
+ op);
+ g_object_unref (location);
}
static void
-vfs_file_poll_callback (GObject *source_object,
- GAsyncResult *res,
- gpointer callback_data)
+vfs_file_poll_callback (GObject *source_object,
+ GAsyncResult *res,
+ gpointer callback_data)
{
- NautilusFileOperation *op;
- gboolean stopped;
- GError *error;
-
- op = callback_data;
-
- error = NULL;
- stopped = g_file_poll_mountable_finish (G_FILE (source_object),
- res, &error);
-
- if (!stopped &&
- error->domain == G_IO_ERROR &&
- (error->code == G_IO_ERROR_FAILED_HANDLED ||
- error->code == G_IO_ERROR_CANCELLED)) {
- g_error_free (error);
- error = NULL;
- }
-
- nautilus_file_operation_complete (op, G_FILE (source_object), error);
- if (error) {
- g_error_free (error);
- }
+ NautilusFileOperation *op;
+ gboolean stopped;
+ GError *error;
+
+ op = callback_data;
+
+ error = NULL;
+ stopped = g_file_poll_mountable_finish (G_FILE (source_object),
+ res, &error);
+
+ if (!stopped &&
+ error->domain == G_IO_ERROR &&
+ (error->code == G_IO_ERROR_FAILED_HANDLED ||
+ error->code == G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ error = NULL;
+ }
+
+ nautilus_file_operation_complete (op, G_FILE (source_object), error);
+ if (error)
+ {
+ g_error_free (error);
+ }
}
static void
vfs_file_poll_for_media (NautilusFile *file)
{
- NautilusFileOperation *op;
- GFile *location;
+ NautilusFileOperation *op;
+ GFile *location;
- op = nautilus_file_operation_new (file, NULL, NULL);
+ op = nautilus_file_operation_new (file, NULL, NULL);
- location = nautilus_file_get_location (file);
- g_file_poll_mountable (location,
- op->cancellable,
- vfs_file_poll_callback,
- op);
- g_object_unref (location);
+ location = nautilus_file_get_location (file);
+ g_file_poll_mountable (location,
+ op->cancellable,
+ vfs_file_poll_callback,
+ op);
+ g_object_unref (location);
}
static void
@@ -674,23 +734,23 @@ nautilus_vfs_file_init (NautilusVFSFile *file)
static void
nautilus_vfs_file_class_init (NautilusVFSFileClass *klass)
{
- NautilusFileClass *file_class = NAUTILUS_FILE_CLASS (klass);
-
- file_class->monitor_add = vfs_file_monitor_add;
- file_class->monitor_remove = vfs_file_monitor_remove;
- file_class->call_when_ready = vfs_file_call_when_ready;
- file_class->cancel_call_when_ready = vfs_file_cancel_call_when_ready;
- file_class->check_if_ready = vfs_file_check_if_ready;
- file_class->get_item_count = vfs_file_get_item_count;
- file_class->get_deep_counts = vfs_file_get_deep_counts;
- file_class->get_date = vfs_file_get_date;
- file_class->get_where_string = vfs_file_get_where_string;
- file_class->set_metadata = vfs_file_set_metadata;
- file_class->set_metadata_as_list = vfs_file_set_metadata_as_list;
- file_class->mount = vfs_file_mount;
- file_class->unmount = vfs_file_unmount;
- file_class->eject = vfs_file_eject;
- file_class->start = vfs_file_start;
- file_class->stop = vfs_file_stop;
- file_class->poll_for_media = vfs_file_poll_for_media;
+ NautilusFileClass *file_class = NAUTILUS_FILE_CLASS (klass);
+
+ file_class->monitor_add = vfs_file_monitor_add;
+ file_class->monitor_remove = vfs_file_monitor_remove;
+ file_class->call_when_ready = vfs_file_call_when_ready;
+ file_class->cancel_call_when_ready = vfs_file_cancel_call_when_ready;
+ file_class->check_if_ready = vfs_file_check_if_ready;
+ file_class->get_item_count = vfs_file_get_item_count;
+ file_class->get_deep_counts = vfs_file_get_deep_counts;
+ file_class->get_date = vfs_file_get_date;
+ file_class->get_where_string = vfs_file_get_where_string;
+ file_class->set_metadata = vfs_file_set_metadata;
+ file_class->set_metadata_as_list = vfs_file_set_metadata_as_list;
+ file_class->mount = vfs_file_mount;
+ file_class->unmount = vfs_file_unmount;
+ file_class->eject = vfs_file_eject;
+ file_class->start = vfs_file_start;
+ file_class->stop = vfs_file_stop;
+ file_class->poll_for_media = vfs_file_poll_for_media;
}
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index ac462b56b..a1930166f 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -25,65 +25,65 @@ G_DEFINE_INTERFACE (NautilusView, nautilus_view, GTK_TYPE_WIDGET)
static void
nautilus_view_default_init (NautilusViewInterface *iface)
{
- /**
- * NautilusView::icon:
- *
- * The #GIcon that represents the view, or %NULL.
- */
- g_object_interface_install_property (iface,
- g_param_spec_object ("icon",
- "Icon that represents the view",
- "The icon that represents the view",
- G_TYPE_ICON,
- G_PARAM_READABLE));
+ /**
+ * NautilusView::icon:
+ *
+ * The #GIcon that represents the view, or %NULL.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_object ("icon",
+ "Icon that represents the view",
+ "The icon that represents the view",
+ G_TYPE_ICON,
+ G_PARAM_READABLE));
- /**
- * NautilusView::is-loading:
- *
- * %TRUE if the view is loading the location, %FALSE otherwise.
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("is-loading",
- "Current view is loading",
- "Whether the current view is loading the location or not",
- FALSE,
- G_PARAM_READABLE));
+ /**
+ * NautilusView::is-loading:
+ *
+ * %TRUE if the view is loading the location, %FALSE otherwise.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("is-loading",
+ "Current view is loading",
+ "Whether the current view is loading the location or not",
+ FALSE,
+ G_PARAM_READABLE));
- /**
- * NautilusView::is-searching:
- *
- * %TRUE if the view is searching, %FALSE otherwise.
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("is-searching",
- "Current view is searching",
- "Whether the current view is searching or not",
- FALSE,
- G_PARAM_READABLE));
+ /**
+ * NautilusView::is-searching:
+ *
+ * %TRUE if the view is searching, %FALSE otherwise.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_boolean ("is-searching",
+ "Current view is searching",
+ "Whether the current view is searching or not",
+ FALSE,
+ G_PARAM_READABLE));
- /**
- * NautilusView::location:
- *
- * The current location of the view.
- */
- g_object_interface_install_property (iface,
- g_param_spec_object ("location",
- "Location displayed by the view",
- "The current location displayed by the view",
- G_TYPE_FILE,
- G_PARAM_READWRITE));
+ /**
+ * NautilusView::location:
+ *
+ * The current location of the view.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_object ("location",
+ "Location displayed by the view",
+ "The current location displayed by the view",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE));
- /**
- * NautilusView::search-query:
- *
- * The search query being performed, or NULL.
- */
- g_object_interface_install_property (iface,
- g_param_spec_object ("search-query",
- "Search query being performed",
- "The search query being performed on the view",
- NAUTILUS_TYPE_QUERY,
- G_PARAM_READWRITE));
+ /**
+ * NautilusView::search-query:
+ *
+ * The search query being performed, or NULL.
+ */
+ g_object_interface_install_property (iface,
+ g_param_spec_object ("search-query",
+ "Search query being performed",
+ "The search query being performed on the view",
+ NAUTILUS_TYPE_QUERY,
+ G_PARAM_READWRITE));
}
/**
@@ -94,12 +94,12 @@ nautilus_view_default_init (NautilusViewInterface *iface)
*
* Returns: (transfer none): a #GIcon
*/
-GIcon*
+GIcon *
nautilus_view_get_icon (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_icon, NULL);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_icon, NULL);
- return NAUTILUS_VIEW_GET_IFACE (view)->get_icon (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->get_icon (view);
}
/**
@@ -115,9 +115,9 @@ nautilus_view_get_icon (NautilusView *view)
NautilusToolbarMenuSections *
nautilus_view_get_toolbar_menu_sections (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections, NULL);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections, NULL);
- return NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->get_toolbar_menu_sections (view);
}
/**
@@ -128,12 +128,12 @@ nautilus_view_get_toolbar_menu_sections (NautilusView *view)
*
* Returns: (transfer none): a #GFile
*/
-GFile*
+GFile *
nautilus_view_get_location (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_location, NULL);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_location, NULL);
- return NAUTILUS_VIEW_GET_IFACE (view)->get_location (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->get_location (view);
}
/**
@@ -149,9 +149,9 @@ void
nautilus_view_set_location (NautilusView *view,
GFile *location)
{
- g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_location);
+ g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_location);
- NAUTILUS_VIEW_GET_IFACE (view)->set_location (view, location);
+ NAUTILUS_VIEW_GET_IFACE (view)->set_location (view, location);
}
/**
@@ -163,12 +163,12 @@ nautilus_view_set_location (NautilusView *view,
* Returns: (transfer full) (type GFile): a newly allocated list
* of the currently selected files.
*/
-GList*
+GList *
nautilus_view_get_selection (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_selection, NULL);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_selection, NULL);
- return NAUTILUS_VIEW_GET_IFACE (view)->get_selection (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->get_selection (view);
}
/**
@@ -184,9 +184,9 @@ void
nautilus_view_set_selection (NautilusView *view,
GList *selection)
{
- g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_selection);
+ g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_selection);
- NAUTILUS_VIEW_GET_IFACE (view)->set_selection (view, selection);
+ NAUTILUS_VIEW_GET_IFACE (view)->set_selection (view, selection);
}
/**
@@ -197,12 +197,12 @@ nautilus_view_set_selection (NautilusView *view,
*
* Returns: (transfer none): a #
*/
-NautilusQuery*
+NautilusQuery *
nautilus_view_get_search_query (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_search_query, NULL);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->get_search_query, NULL);
- return NAUTILUS_VIEW_GET_IFACE (view)->get_search_query (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->get_search_query (view);
}
/**
@@ -218,9 +218,9 @@ void
nautilus_view_set_search_query (NautilusView *view,
NautilusQuery *query)
{
- g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_search_query);
+ g_return_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->set_search_query);
- NAUTILUS_VIEW_GET_IFACE (view)->set_search_query (view, query);
+ NAUTILUS_VIEW_GET_IFACE (view)->set_search_query (view, query);
}
/**
@@ -234,9 +234,9 @@ nautilus_view_set_search_query (NautilusView *view,
gboolean
nautilus_view_is_loading (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_loading, FALSE);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_loading, FALSE);
- return NAUTILUS_VIEW_GET_IFACE (view)->is_loading (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->is_loading (view);
}
/**
@@ -250,7 +250,7 @@ nautilus_view_is_loading (NautilusView *view)
gboolean
nautilus_view_is_searching (NautilusView *view)
{
- g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_searching, FALSE);
+ g_return_val_if_fail (NAUTILUS_VIEW_GET_IFACE (view)->is_searching, FALSE);
- return NAUTILUS_VIEW_GET_IFACE (view)->is_searching (view);
+ return NAUTILUS_VIEW_GET_IFACE (view)->is_searching (view);
}
diff --git a/src/nautilus-window-slot-dnd.c b/src/nautilus-window-slot-dnd.c
index 335cfe005..fbf6c40eb 100644
--- a/src/nautilus-window-slot-dnd.c
+++ b/src/nautilus-window-slot-dnd.c
@@ -20,7 +20,7 @@
* see <http://www.gnu.org/licenses/>.
*
* Authors: Pavel Cisler <pavel@eazel.com>,
- * Ettore Perazzoli <ettore@gnu.org>
+ * Ettore Perazzoli <ettore@gnu.org>
*/
#include <config.h>
@@ -30,48 +30,51 @@
#include "nautilus-files-view-dnd.h"
#include "nautilus-window-slot-dnd.h"
-typedef struct {
- gboolean have_data;
- gboolean have_valid_data;
-
- gboolean drop_occured;
-
- unsigned int info;
- union {
- GList *selection_list;
- GList *uri_list;
- char *netscape_url;
- GtkSelectionData *selection_data;
- } data;
+typedef struct
+{
+ gboolean have_data;
+ gboolean have_valid_data;
- NautilusFile *target_file;
- NautilusWindowSlot *target_slot;
- GtkWidget *widget;
+ gboolean drop_occured;
- gboolean is_notebook;
- guint switch_location_timer;
+ unsigned int info;
+ union
+ {
+ GList *selection_list;
+ GList *uri_list;
+ char *netscape_url;
+ GtkSelectionData *selection_data;
+ } data;
+
+ NautilusFile *target_file;
+ NautilusWindowSlot *target_slot;
+ GtkWidget *widget;
+
+ gboolean is_notebook;
+ guint switch_location_timer;
} NautilusDragSlotProxyInfo;
static void
switch_tab (NautilusDragSlotProxyInfo *drag_info)
{
- GtkWidget *notebook, *slot;
- gint idx, n_pages;
+ GtkWidget *notebook, *slot;
+ gint idx, n_pages;
- if (drag_info->target_slot == NULL) {
- return;
- }
+ if (drag_info->target_slot == NULL)
+ {
+ return;
+ }
- notebook = gtk_widget_get_ancestor (GTK_WIDGET (drag_info->target_slot), NAUTILUS_TYPE_NOTEBOOK);
- n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
+ notebook = gtk_widget_get_ancestor (GTK_WIDGET (drag_info->target_slot), NAUTILUS_TYPE_NOTEBOOK);
+ n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- for (idx = 0; idx < n_pages; idx++)
+ for (idx = 0; idx < n_pages; idx++)
{
- slot = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), idx);
- if (NAUTILUS_WINDOW_SLOT (slot) == drag_info->target_slot)
+ slot = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), idx);
+ if (NAUTILUS_WINDOW_SLOT (slot) == drag_info->target_slot)
{
- gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), idx);
- break;
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), idx);
+ break;
}
}
}
@@ -79,437 +82,509 @@ switch_tab (NautilusDragSlotProxyInfo *drag_info)
static void
switch_location (NautilusDragSlotProxyInfo *drag_info)
{
- GFile *location;
- GtkWidget *window;
+ GFile *location;
+ GtkWidget *window;
- if (drag_info->target_file == NULL) {
- return;
- }
+ if (drag_info->target_file == NULL)
+ {
+ return;
+ }
- window = gtk_widget_get_toplevel (drag_info->widget);
- g_assert (NAUTILUS_IS_WINDOW (window));
+ window = gtk_widget_get_toplevel (drag_info->widget);
+ g_assert (NAUTILUS_IS_WINDOW (window));
- location = nautilus_file_get_location (drag_info->target_file);
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location, NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
- NULL, NAUTILUS_WINDOW (window), NULL);
- g_object_unref (location);
+ location = nautilus_file_get_location (drag_info->target_file);
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location, NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE,
+ NULL, NAUTILUS_WINDOW (window), NULL);
+ g_object_unref (location);
}
static gboolean
slot_proxy_switch_location_timer (gpointer user_data)
{
- NautilusDragSlotProxyInfo *drag_info = user_data;
+ NautilusDragSlotProxyInfo *drag_info = user_data;
- drag_info->switch_location_timer = 0;
+ drag_info->switch_location_timer = 0;
- if (drag_info->is_notebook)
- switch_tab (drag_info);
- else
- switch_location (drag_info);
+ if (drag_info->is_notebook)
+ {
+ switch_tab (drag_info);
+ }
+ else
+ {
+ switch_location (drag_info);
+ }
- return FALSE;
+ return FALSE;
}
static void
slot_proxy_check_switch_location_timer (NautilusDragSlotProxyInfo *drag_info,
- GtkWidget *widget)
+ GtkWidget *widget)
{
- GtkSettings *settings;
- guint timeout;
+ GtkSettings *settings;
+ guint timeout;
- if (drag_info->switch_location_timer)
- return;
+ if (drag_info->switch_location_timer)
+ {
+ return;
+ }
- settings = gtk_widget_get_settings (widget);
- g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
+ settings = gtk_widget_get_settings (widget);
+ g_object_get (settings, "gtk-timeout-expand", &timeout, NULL);
- drag_info->switch_location_timer =
- gdk_threads_add_timeout (timeout,
- slot_proxy_switch_location_timer,
- drag_info);
+ drag_info->switch_location_timer =
+ gdk_threads_add_timeout (timeout,
+ slot_proxy_switch_location_timer,
+ drag_info);
}
static void
slot_proxy_remove_switch_location_timer (NautilusDragSlotProxyInfo *drag_info)
{
- if (drag_info->switch_location_timer != 0)
+ if (drag_info->switch_location_timer != 0)
{
- g_source_remove (drag_info->switch_location_timer);
- drag_info->switch_location_timer = 0;
+ g_source_remove (drag_info->switch_location_timer);
+ drag_info->switch_location_timer = 0;
}
}
static gboolean
-slot_proxy_drag_motion (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- unsigned int time,
- gpointer user_data)
+slot_proxy_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ unsigned int time,
+ gpointer user_data)
{
- NautilusDragSlotProxyInfo *drag_info;
- NautilusWindowSlot *target_slot;
- GtkWidget *window;
- GdkAtom target;
- int action;
- char *target_uri;
- GFile *location;
- gboolean valid_text_drag;
- gboolean valid_xds_drag;
-
- drag_info = user_data;
-
- action = 0;
- valid_text_drag = FALSE;
- valid_xds_drag = FALSE;
-
- if (gtk_drag_get_source_widget (context) == widget) {
- goto out;
- }
-
- window = gtk_widget_get_toplevel (widget);
- g_assert (NAUTILUS_IS_WINDOW (window));
-
- if (!drag_info->have_data) {
- target = gtk_drag_dest_find_target (widget, context, NULL);
+ NautilusDragSlotProxyInfo *drag_info;
+ NautilusWindowSlot *target_slot;
+ GtkWidget *window;
+ GdkAtom target;
+ int action;
+ char *target_uri;
+ GFile *location;
+ gboolean valid_text_drag;
+ gboolean valid_xds_drag;
+
+ drag_info = user_data;
+
+ action = 0;
+ valid_text_drag = FALSE;
+ valid_xds_drag = FALSE;
+
+ if (gtk_drag_get_source_widget (context) == widget)
+ {
+ goto out;
+ }
- if (target == GDK_NONE) {
- goto out;
+ window = gtk_widget_get_toplevel (widget);
+ g_assert (NAUTILUS_IS_WINDOW (window));
+
+ if (!drag_info->have_data)
+ {
+ target = gtk_drag_dest_find_target (widget, context, NULL);
+
+ if (target == GDK_NONE)
+ {
+ goto out;
+ }
+
+ gtk_drag_get_data (widget, context, target, time);
}
- gtk_drag_get_data (widget, context, target, time);
- }
+ target_uri = NULL;
+ if (drag_info->target_file != NULL)
+ {
+ target_uri = nautilus_file_get_uri (drag_info->target_file);
+ }
+ else
+ {
+ if (drag_info->target_slot != NULL)
+ {
+ target_slot = drag_info->target_slot;
+ }
+ else
+ {
+ target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window));
+ }
- target_uri = NULL;
- if (drag_info->target_file != NULL) {
- target_uri = nautilus_file_get_uri (drag_info->target_file);
- } else {
- if (drag_info->target_slot != NULL) {
- target_slot = drag_info->target_slot;
- } else {
- target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window));
+ if (target_slot != NULL)
+ {
+ location = nautilus_window_slot_get_location (target_slot);
+ target_uri = g_file_get_uri (location);
+ }
}
- if (target_slot != NULL) {
- location = nautilus_window_slot_get_location (target_slot);
- target_uri = g_file_get_uri (location);
+ if (target_uri != NULL)
+ {
+ NautilusFile *file;
+ gboolean can;
+ file = nautilus_file_get_existing_by_uri (target_uri);
+ can = nautilus_file_can_write (file);
+ g_object_unref (file);
+ if (!can)
+ {
+ action = 0;
+ goto out;
+ }
+ }
+
+ if (drag_info->have_data &&
+ drag_info->have_valid_data)
+ {
+ if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ nautilus_drag_default_drop_action_for_icons (context, target_uri,
+ drag_info->data.selection_list,
+ 0,
+ &action);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ action = nautilus_drag_default_drop_action_for_uri_list (context, target_uri);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL)
+ {
+ action = nautilus_drag_default_drop_action_for_netscape_url (context);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_TEXT)
+ {
+ valid_text_drag = TRUE;
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE ||
+ drag_info->info == NAUTILUS_ICON_DND_RAW)
+ {
+ valid_xds_drag = TRUE;
+ }
}
- }
-
- if (target_uri != NULL) {
- NautilusFile *file;
- gboolean can;
- file = nautilus_file_get_existing_by_uri (target_uri);
- can = nautilus_file_can_write (file);
- g_object_unref (file);
- if (!can) {
- action = 0;
- goto out;
- }
- }
-
- if (drag_info->have_data &&
- drag_info->have_valid_data) {
- if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
- nautilus_drag_default_drop_action_for_icons (context, target_uri,
- drag_info->data.selection_list,
- 0,
- &action);
- } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) {
- action = nautilus_drag_default_drop_action_for_uri_list (context, target_uri);
- } else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) {
- action = nautilus_drag_default_drop_action_for_netscape_url (context);
- } else if (drag_info->info == NAUTILUS_ICON_DND_TEXT) {
- valid_text_drag = TRUE;
- } else if (drag_info->info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE ||
- drag_info->info == NAUTILUS_ICON_DND_RAW) {
- valid_xds_drag = TRUE;
- }
- }
-
- g_free (target_uri);
-
- out:
- if (action != 0 || valid_text_drag || valid_xds_drag) {
- gtk_drag_highlight (widget);
- slot_proxy_check_switch_location_timer (drag_info, widget);
- } else {
- gtk_drag_unhighlight (widget);
- slot_proxy_remove_switch_location_timer (drag_info);
- }
- gdk_drag_status (context, action, time);
+ g_free (target_uri);
- return TRUE;
+out:
+ if (action != 0 || valid_text_drag || valid_xds_drag)
+ {
+ gtk_drag_highlight (widget);
+ slot_proxy_check_switch_location_timer (drag_info, widget);
+ }
+ else
+ {
+ gtk_drag_unhighlight (widget);
+ slot_proxy_remove_switch_location_timer (drag_info);
+ }
+
+ gdk_drag_status (context, action, time);
+
+ return TRUE;
}
static void
drag_info_free (gpointer user_data)
{
- NautilusDragSlotProxyInfo *drag_info = user_data;
+ NautilusDragSlotProxyInfo *drag_info = user_data;
- g_clear_object (&drag_info->target_file);
- g_clear_object (&drag_info->target_slot);
+ g_clear_object (&drag_info->target_file);
+ g_clear_object (&drag_info->target_slot);
- g_slice_free (NautilusDragSlotProxyInfo, drag_info);
+ g_slice_free (NautilusDragSlotProxyInfo, drag_info);
}
static void
drag_info_clear (NautilusDragSlotProxyInfo *drag_info)
{
- slot_proxy_remove_switch_location_timer (drag_info);
-
- if (!drag_info->have_data) {
- goto out;
- }
-
- if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
- nautilus_drag_destroy_selection_list (drag_info->data.selection_list);
- } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) {
- g_list_free (drag_info->data.uri_list);
- } else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) {
- g_free (drag_info->data.netscape_url);
- } else if (drag_info->info == NAUTILUS_ICON_DND_TEXT ||
+ slot_proxy_remove_switch_location_timer (drag_info);
+
+ if (!drag_info->have_data)
+ {
+ goto out;
+ }
+
+ if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ nautilus_drag_destroy_selection_list (drag_info->data.selection_list);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ g_list_free (drag_info->data.uri_list);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL)
+ {
+ g_free (drag_info->data.netscape_url);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_TEXT ||
drag_info->info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE ||
- drag_info->info == NAUTILUS_ICON_DND_RAW) {
- if (drag_info->data.selection_data != NULL) {
- gtk_selection_data_free (drag_info->data.selection_data);
+ drag_info->info == NAUTILUS_ICON_DND_RAW)
+ {
+ if (drag_info->data.selection_data != NULL)
+ {
+ gtk_selection_data_free (drag_info->data.selection_data);
+ }
}
- }
- out:
- drag_info->have_data = FALSE;
- drag_info->have_valid_data = FALSE;
+out:
+ drag_info->have_data = FALSE;
+ drag_info->have_valid_data = FALSE;
- drag_info->drop_occured = FALSE;
+ drag_info->drop_occured = FALSE;
}
static void
-slot_proxy_drag_leave (GtkWidget *widget,
- GdkDragContext *context,
- unsigned int time,
- gpointer user_data)
+slot_proxy_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ unsigned int time,
+ gpointer user_data)
{
- NautilusDragSlotProxyInfo *drag_info;
+ NautilusDragSlotProxyInfo *drag_info;
- drag_info = user_data;
+ drag_info = user_data;
- gtk_drag_unhighlight (widget);
- drag_info_clear (drag_info);
+ gtk_drag_unhighlight (widget);
+ drag_info_clear (drag_info);
}
static gboolean
-slot_proxy_drag_drop (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- unsigned int time,
- gpointer user_data)
+slot_proxy_drag_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ unsigned int time,
+ gpointer user_data)
{
- GdkAtom target;
- NautilusDragSlotProxyInfo *drag_info;
+ GdkAtom target;
+ NautilusDragSlotProxyInfo *drag_info;
- drag_info = user_data;
- g_assert (!drag_info->have_data);
+ drag_info = user_data;
+ g_assert (!drag_info->have_data);
- drag_info->drop_occured = TRUE;
+ drag_info->drop_occured = TRUE;
- target = gtk_drag_dest_find_target (widget, context, NULL);
- gtk_drag_get_data (widget, context, target, time);
+ target = gtk_drag_dest_find_target (widget, context, NULL);
+ gtk_drag_get_data (widget, context, target, time);
- return TRUE;
+ return TRUE;
}
static void
-slot_proxy_handle_drop (GtkWidget *widget,
- GdkDragContext *context,
- unsigned int time,
- NautilusDragSlotProxyInfo *drag_info)
+slot_proxy_handle_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ unsigned int time,
+ NautilusDragSlotProxyInfo *drag_info)
{
- GtkWidget *window;
- NautilusWindowSlot *target_slot;
- NautilusFilesView *target_view;
- char *target_uri;
- GList *uri_list;
- GFile *location;
-
- if (!drag_info->have_data ||
- !drag_info->have_valid_data) {
- gtk_drag_finish (context, FALSE, FALSE, time);
- drag_info_clear (drag_info);
- return;
- }
-
- window = gtk_widget_get_toplevel (widget);
- g_assert (NAUTILUS_IS_WINDOW (window));
-
- if (drag_info->target_slot != NULL) {
- target_slot = drag_info->target_slot;
- } else {
- target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window));
- }
-
- target_uri = NULL;
- if (drag_info->target_file != NULL) {
- target_uri = nautilus_file_get_uri (drag_info->target_file);
- } else if (target_slot != NULL) {
- location = nautilus_window_slot_get_location (target_slot);
- target_uri = g_file_get_uri (location);
- }
-
- target_view = NULL;
- if (target_slot != NULL) {
+ GtkWidget *window;
+ NautilusWindowSlot *target_slot;
+ NautilusFilesView *target_view;
+ char *target_uri;
+ GList *uri_list;
+ GFile *location;
+
+ if (!drag_info->have_data ||
+ !drag_info->have_valid_data)
+ {
+ gtk_drag_finish (context, FALSE, FALSE, time);
+ drag_info_clear (drag_info);
+ return;
+ }
+
+ window = gtk_widget_get_toplevel (widget);
+ g_assert (NAUTILUS_IS_WINDOW (window));
+
+ if (drag_info->target_slot != NULL)
+ {
+ target_slot = drag_info->target_slot;
+ }
+ else
+ {
+ target_slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (window));
+ }
+
+ target_uri = NULL;
+ if (drag_info->target_file != NULL)
+ {
+ target_uri = nautilus_file_get_uri (drag_info->target_file);
+ }
+ else if (target_slot != NULL)
+ {
+ location = nautilus_window_slot_get_location (target_slot);
+ target_uri = g_file_get_uri (location);
+ }
+
+ target_view = NULL;
+ if (target_slot != NULL)
+ {
NautilusView *view;
view = nautilus_window_slot_get_current_view (target_slot);
- if (view && NAUTILUS_IS_FILES_VIEW (view)) {
- target_view = NAUTILUS_FILES_VIEW (view);
+ if (view && NAUTILUS_IS_FILES_VIEW (view))
+ {
+ target_view = NAUTILUS_FILES_VIEW (view);
+ }
+ }
+
+ if (target_slot != NULL && target_view != NULL)
+ {
+ if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ uri_list = nautilus_drag_uri_list_from_selection_list (drag_info->data.selection_list);
+ g_assert (uri_list != NULL);
+
+ nautilus_files_view_drop_proxy_received_uris (target_view,
+ uri_list,
+ target_uri,
+ gdk_drag_context_get_selected_action (context));
+ g_list_free_full (uri_list, g_free);
+ }
+ else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ nautilus_files_view_drop_proxy_received_uris (target_view,
+ drag_info->data.uri_list,
+ target_uri,
+ gdk_drag_context_get_selected_action (context));
+ }
+ if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL)
+ {
+ nautilus_files_view_handle_netscape_url_drop (target_view,
+ drag_info->data.netscape_url,
+ target_uri,
+ gdk_drag_context_get_selected_action (context),
+ 0, 0);
}
- }
-
- if (target_slot != NULL && target_view != NULL) {
- if (drag_info->info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
- uri_list = nautilus_drag_uri_list_from_selection_list (drag_info->data.selection_list);
- g_assert (uri_list != NULL);
-
- nautilus_files_view_drop_proxy_received_uris (target_view,
- uri_list,
- target_uri,
- gdk_drag_context_get_selected_action (context));
- g_list_free_full (uri_list, g_free);
- } else if (drag_info->info == NAUTILUS_ICON_DND_URI_LIST) {
- nautilus_files_view_drop_proxy_received_uris (target_view,
- drag_info->data.uri_list,
- target_uri,
- gdk_drag_context_get_selected_action (context));
- } if (drag_info->info == NAUTILUS_ICON_DND_NETSCAPE_URL) {
- nautilus_files_view_handle_netscape_url_drop (target_view,
- drag_info->data.netscape_url,
- target_uri,
- gdk_drag_context_get_selected_action (context),
- 0, 0);
- }
-
-
- gtk_drag_finish (context, TRUE, FALSE, time);
- } else {
- gtk_drag_finish (context, FALSE, FALSE, time);
- }
-
- g_free (target_uri);
-
- drag_info_clear (drag_info);
+
+
+ gtk_drag_finish (context, TRUE, FALSE, time);
+ }
+ else
+ {
+ gtk_drag_finish (context, FALSE, FALSE, time);
+ }
+
+ g_free (target_uri);
+
+ drag_info_clear (drag_info);
}
static void
-slot_proxy_drag_data_received (GtkWidget *widget,
- GdkDragContext *context,
- int x,
- int y,
- GtkSelectionData *data,
- unsigned int info,
- unsigned int time,
- gpointer user_data)
+slot_proxy_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ int x,
+ int y,
+ GtkSelectionData *data,
+ unsigned int info,
+ unsigned int time,
+ gpointer user_data)
{
- NautilusDragSlotProxyInfo *drag_info;
- char **uris;
+ NautilusDragSlotProxyInfo *drag_info;
+ char **uris;
- drag_info = user_data;
+ drag_info = user_data;
- g_assert (!drag_info->have_data);
+ g_assert (!drag_info->have_data);
- drag_info->have_data = TRUE;
- drag_info->info = info;
+ drag_info->have_data = TRUE;
+ drag_info->info = info;
- if (gtk_selection_data_get_length (data) < 0) {
- drag_info->have_valid_data = FALSE;
- return;
- }
+ if (gtk_selection_data_get_length (data) < 0)
+ {
+ drag_info->have_valid_data = FALSE;
+ return;
+ }
- if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST) {
- drag_info->data.selection_list = nautilus_drag_build_selection_list (data);
+ if (info == NAUTILUS_ICON_DND_GNOME_ICON_LIST)
+ {
+ drag_info->data.selection_list = nautilus_drag_build_selection_list (data);
- drag_info->have_valid_data = drag_info->data.selection_list != NULL;
- } else if (info == NAUTILUS_ICON_DND_URI_LIST) {
- uris = gtk_selection_data_get_uris (data);
- drag_info->data.uri_list = nautilus_drag_uri_list_from_array ((const char **) uris);
- g_strfreev (uris);
+ drag_info->have_valid_data = drag_info->data.selection_list != NULL;
+ }
+ else if (info == NAUTILUS_ICON_DND_URI_LIST)
+ {
+ uris = gtk_selection_data_get_uris (data);
+ drag_info->data.uri_list = nautilus_drag_uri_list_from_array ((const char **) uris);
+ g_strfreev (uris);
- drag_info->have_valid_data = drag_info->data.uri_list != NULL;
- } else if (info == NAUTILUS_ICON_DND_NETSCAPE_URL) {
- drag_info->data.netscape_url = g_strdup ((char *) gtk_selection_data_get_data (data));
+ drag_info->have_valid_data = drag_info->data.uri_list != NULL;
+ }
+ else if (info == NAUTILUS_ICON_DND_NETSCAPE_URL)
+ {
+ drag_info->data.netscape_url = g_strdup ((char *) gtk_selection_data_get_data (data));
- drag_info->have_valid_data = drag_info->data.netscape_url != NULL;
- } else if (info == NAUTILUS_ICON_DND_TEXT ||
+ drag_info->have_valid_data = drag_info->data.netscape_url != NULL;
+ }
+ else if (info == NAUTILUS_ICON_DND_TEXT ||
info == NAUTILUS_ICON_DND_XDNDDIRECTSAVE ||
- info == NAUTILUS_ICON_DND_RAW) {
- drag_info->data.selection_data = gtk_selection_data_copy (data);
- drag_info->have_valid_data = drag_info->data.selection_data != NULL;
- }
-
- if (drag_info->drop_occured) {
- slot_proxy_handle_drop (widget, context, time, drag_info);
- }
+ info == NAUTILUS_ICON_DND_RAW)
+ {
+ drag_info->data.selection_data = gtk_selection_data_copy (data);
+ drag_info->have_valid_data = drag_info->data.selection_data != NULL;
+ }
+
+ if (drag_info->drop_occured)
+ {
+ slot_proxy_handle_drop (widget, context, time, drag_info);
+ }
}
void
-nautilus_drag_slot_proxy_init (GtkWidget *widget,
- NautilusFile *target_file,
+nautilus_drag_slot_proxy_init (GtkWidget *widget,
+ NautilusFile *target_file,
NautilusWindowSlot *target_slot)
{
- NautilusDragSlotProxyInfo *drag_info;
-
- const GtkTargetEntry targets[] = {
- { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
- { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL },
- { NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, 0, NAUTILUS_ICON_DND_XDNDDIRECTSAVE }, /* XDS Protocol Type */
- { NAUTILUS_ICON_DND_RAW_TYPE, 0, NAUTILUS_ICON_DND_RAW }
- };
- GtkTargetList *target_list;
-
- g_assert (GTK_IS_WIDGET (widget));
-
- drag_info = g_slice_new0 (NautilusDragSlotProxyInfo);
-
- g_object_set_data_full (G_OBJECT (widget), "drag-slot-proxy-data", drag_info,
- drag_info_free);
-
- drag_info->is_notebook = (g_object_get_data (G_OBJECT (widget), "nautilus-notebook-tab") != NULL);
-
- if (target_file != NULL)
- drag_info->target_file = nautilus_file_ref (target_file);
-
- if (target_slot != NULL)
- drag_info->target_slot = g_object_ref (target_slot);
-
- drag_info->widget = widget;
-
- gtk_drag_dest_set (widget, 0,
- NULL, 0,
- GDK_ACTION_MOVE |
- GDK_ACTION_COPY |
- GDK_ACTION_LINK |
- GDK_ACTION_ASK);
-
- target_list = gtk_target_list_new (targets, G_N_ELEMENTS (targets));
- gtk_target_list_add_uri_targets (target_list, NAUTILUS_ICON_DND_URI_LIST);
- gtk_target_list_add_text_targets (target_list, NAUTILUS_ICON_DND_TEXT);
- gtk_drag_dest_set_target_list (widget, target_list);
- gtk_target_list_unref (target_list);
-
- g_signal_connect (widget, "drag-motion",
- G_CALLBACK (slot_proxy_drag_motion),
- drag_info);
- g_signal_connect (widget, "drag-drop",
- G_CALLBACK (slot_proxy_drag_drop),
- drag_info);
- g_signal_connect (widget, "drag-data-received",
- G_CALLBACK (slot_proxy_drag_data_received),
- drag_info);
- g_signal_connect (widget, "drag-leave",
- G_CALLBACK (slot_proxy_drag_leave),
- drag_info);
+ NautilusDragSlotProxyInfo *drag_info;
+
+ const GtkTargetEntry targets[] =
+ {
+ { NAUTILUS_ICON_DND_GNOME_ICON_LIST_TYPE, 0, NAUTILUS_ICON_DND_GNOME_ICON_LIST },
+ { NAUTILUS_ICON_DND_NETSCAPE_URL_TYPE, 0, NAUTILUS_ICON_DND_NETSCAPE_URL },
+ { NAUTILUS_ICON_DND_XDNDDIRECTSAVE_TYPE, 0, NAUTILUS_ICON_DND_XDNDDIRECTSAVE }, /* XDS Protocol Type */
+ { NAUTILUS_ICON_DND_RAW_TYPE, 0, NAUTILUS_ICON_DND_RAW }
+ };
+ GtkTargetList *target_list;
+
+ g_assert (GTK_IS_WIDGET (widget));
+
+ drag_info = g_slice_new0 (NautilusDragSlotProxyInfo);
+
+ g_object_set_data_full (G_OBJECT (widget), "drag-slot-proxy-data", drag_info,
+ drag_info_free);
+
+ drag_info->is_notebook = (g_object_get_data (G_OBJECT (widget), "nautilus-notebook-tab") != NULL);
+
+ if (target_file != NULL)
+ {
+ drag_info->target_file = nautilus_file_ref (target_file);
+ }
+
+ if (target_slot != NULL)
+ {
+ drag_info->target_slot = g_object_ref (target_slot);
+ }
+
+ drag_info->widget = widget;
+
+ gtk_drag_dest_set (widget, 0,
+ NULL, 0,
+ GDK_ACTION_MOVE |
+ GDK_ACTION_COPY |
+ GDK_ACTION_LINK |
+ GDK_ACTION_ASK);
+
+ target_list = gtk_target_list_new (targets, G_N_ELEMENTS (targets));
+ gtk_target_list_add_uri_targets (target_list, NAUTILUS_ICON_DND_URI_LIST);
+ gtk_target_list_add_text_targets (target_list, NAUTILUS_ICON_DND_TEXT);
+ gtk_drag_dest_set_target_list (widget, target_list);
+ gtk_target_list_unref (target_list);
+
+ g_signal_connect (widget, "drag-motion",
+ G_CALLBACK (slot_proxy_drag_motion),
+ drag_info);
+ g_signal_connect (widget, "drag-drop",
+ G_CALLBACK (slot_proxy_drag_drop),
+ drag_info);
+ g_signal_connect (widget, "drag-data-received",
+ G_CALLBACK (slot_proxy_drag_data_received),
+ drag_info);
+ g_signal_connect (widget, "drag-leave",
+ G_CALLBACK (slot_proxy_drag_leave),
+ drag_info);
}
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index af2eadf96..55d721486 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -1,23 +1,23 @@
/*
- nautilus-window-slot.c: Nautilus window slot
-
- Copyright (C) 2008 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, see <http://www.gnu.org/licenses/>.
-
- Author: Christian Neumair <cneumair@gnome.org>
-*/
+ * nautilus-window-slot.c: Nautilus window slot
+ *
+ * Copyright (C) 2008 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Christian Neumair <cneumair@gnome.org>
+ */
#include "config.h"
@@ -44,79 +44,82 @@
#include "nautilus-profile.h"
#include <libnautilus-extension/nautilus-location-widget-provider.h>
-enum {
- ACTIVE,
- INACTIVE,
- LAST_SIGNAL
+enum
+{
+ ACTIVE,
+ INACTIVE,
+ LAST_SIGNAL
};
-enum {
- PROP_ACTIVE = 1,
- PROP_WINDOW,
- PROP_ICON,
- PROP_TOOLBAR_MENU_SECTIONS,
- PROP_LOADING,
- PROP_LOCATION,
- NUM_PROPERTIES
+enum
+{
+ PROP_ACTIVE = 1,
+ PROP_WINDOW,
+ PROP_ICON,
+ PROP_TOOLBAR_MENU_SECTIONS,
+ PROP_LOADING,
+ PROP_LOCATION,
+ NUM_PROPERTIES
};
-typedef struct {
- NautilusWindow *window;
-
- gboolean active : 1;
- guint loading : 1;
-
- /* slot contains
- * 1) an vbox containing extra_location_widgets
- * 2) the view
- */
- GtkWidget *extra_location_widgets;
-
- /* Slot actions */
- GActionGroup *slot_action_group;
-
- /* Current location. */
- GFile *location;
- gchar *title;
-
- /* Viewed file */
- NautilusView *content_view;
- NautilusView *new_content_view;
- NautilusFile *viewed_file;
- gboolean viewed_file_seen;
- gboolean viewed_file_in_trash;
-
- /* Information about bookmarks and history list */
- NautilusBookmark *current_location_bookmark;
- NautilusBookmark *last_location_bookmark;
- GList *back_list;
- GList *forward_list;
-
- /* Query editor */
- NautilusQueryEditor *query_editor;
- gulong qe_changed_id;
- gulong qe_cancel_id;
- gulong qe_activated_id;
-
- /* Load state */
- GCancellable *find_mount_cancellable;
- /* It could be either the view is loading the files or the search didn't
- * finish. Used for showing a spinner to provide feedback to the user. */
- gboolean allow_stop;
- gboolean needs_reload;
- gchar *pending_search_text;
-
- /* New location. */
- GFile *pending_location;
- NautilusLocationChangeType location_change_type;
- guint location_change_distance;
- char *pending_scroll_to;
- GList *pending_selection;
- NautilusFile *determine_view_file;
- GCancellable *mount_cancellable;
- GError *mount_error;
- gboolean tried_mount;
- gint view_mode_before_search;
+typedef struct
+{
+ NautilusWindow *window;
+
+ gboolean active : 1;
+ guint loading : 1;
+
+ /* slot contains
+ * 1) an vbox containing extra_location_widgets
+ * 2) the view
+ */
+ GtkWidget *extra_location_widgets;
+
+ /* Slot actions */
+ GActionGroup *slot_action_group;
+
+ /* Current location. */
+ GFile *location;
+ gchar *title;
+
+ /* Viewed file */
+ NautilusView *content_view;
+ NautilusView *new_content_view;
+ NautilusFile *viewed_file;
+ gboolean viewed_file_seen;
+ gboolean viewed_file_in_trash;
+
+ /* Information about bookmarks and history list */
+ NautilusBookmark *current_location_bookmark;
+ NautilusBookmark *last_location_bookmark;
+ GList *back_list;
+ GList *forward_list;
+
+ /* Query editor */
+ NautilusQueryEditor *query_editor;
+ gulong qe_changed_id;
+ gulong qe_cancel_id;
+ gulong qe_activated_id;
+
+ /* Load state */
+ GCancellable *find_mount_cancellable;
+ /* It could be either the view is loading the files or the search didn't
+ * finish. Used for showing a spinner to provide feedback to the user. */
+ gboolean allow_stop;
+ gboolean needs_reload;
+ gchar *pending_search_text;
+
+ /* New location. */
+ GFile *pending_location;
+ NautilusLocationChangeType location_change_type;
+ guint location_change_distance;
+ char *pending_scroll_to;
+ GList *pending_selection;
+ NautilusFile *determine_view_file;
+ GCancellable *mount_cancellable;
+ GError *mount_error;
+ gboolean tried_mount;
+ gint view_mode_before_search;
} NautilusWindowSlotPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (NautilusWindowSlot, nautilus_window_slot, GTK_TYPE_BOX);
@@ -130,11 +133,15 @@ static void hide_query_editor (NautilusWindowSlot *self);
static void nautilus_window_slot_sync_actions (NautilusWindowSlot *self);
static void nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *self);
static void nautilus_window_slot_disconnect_content_view (NautilusWindowSlot *self);
-static gboolean nautilus_window_slot_content_view_matches (NautilusWindowSlot *self, guint id);
-static NautilusView* nautilus_window_slot_get_view_for_location (NautilusWindowSlot *self, GFile *location);
-static void nautilus_window_slot_set_content_view (NautilusWindowSlot *self, guint id);
-static void nautilus_window_slot_set_loading (NautilusWindowSlot *self, gboolean loading);
-char * nautilus_window_slot_get_location_uri (NautilusWindowSlot *self);
+static gboolean nautilus_window_slot_content_view_matches (NautilusWindowSlot *self,
+ guint id);
+static NautilusView *nautilus_window_slot_get_view_for_location (NautilusWindowSlot *self,
+ GFile *location);
+static void nautilus_window_slot_set_content_view (NautilusWindowSlot *self,
+ guint id);
+static void nautilus_window_slot_set_loading (NautilusWindowSlot *self,
+ gboolean loading);
+char *nautilus_window_slot_get_location_uri (NautilusWindowSlot *self);
static void nautilus_window_slot_set_search_visible (NautilusWindowSlot *self,
gboolean visible);
static gboolean nautilus_window_slot_get_search_visible (NautilusWindowSlot *self);
@@ -144,556 +151,633 @@ gboolean
nautilus_window_slot_handles_location (NautilusWindowSlot *self,
GFile *location)
{
- return NAUTILUS_WINDOW_SLOT_CLASS (G_OBJECT_GET_CLASS (self))->handles_location (self, location);
+ return NAUTILUS_WINDOW_SLOT_CLASS (G_OBJECT_GET_CLASS (self))->handles_location (self, location);
}
static gboolean
real_handles_location (NautilusWindowSlot *self,
GFile *location)
{
- NautilusFile *file;
- gboolean handles_location;
+ NautilusFile *file;
+ gboolean handles_location;
- file = nautilus_file_get (location);
- handles_location = !nautilus_file_is_other_locations (file) &&
- !nautilus_file_is_desktop_directory (file);
- nautilus_file_unref (file);
+ file = nautilus_file_get (location);
+ handles_location = !nautilus_file_is_other_locations (file) &&
+ !nautilus_file_is_desktop_directory (file);
+ nautilus_file_unref (file);
- return handles_location;
+ return handles_location;
}
-static NautilusView*
+static NautilusView *
nautilus_window_slot_get_view_for_location (NautilusWindowSlot *self,
GFile *location)
{
- return NAUTILUS_WINDOW_SLOT_CLASS (G_OBJECT_GET_CLASS (self))->get_view_for_location (self, location);
+ return NAUTILUS_WINDOW_SLOT_CLASS (G_OBJECT_GET_CLASS (self))->get_view_for_location (self, location);
}
-static NautilusView*
+static NautilusView *
real_get_view_for_location (NautilusWindowSlot *self,
GFile *location)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- NautilusView *view;
- NautilusFile *file;
+ NautilusView *view;
+ NautilusFile *file;
- priv = nautilus_window_slot_get_instance_private (self);
- file = nautilus_file_get (location);
- view = NULL;
- guint view_id;
-
- view_id = NAUTILUS_VIEW_INVALID_ID;
-
- /* If we are in search, try to use by default list view. */
- if (nautilus_file_is_in_search (file)) {
- /* If it's already set, is because we already made the change to search mode,
- * so the view mode of the current view will be the one search is using,
- * which is not the one we are interested in */
- if (priv->view_mode_before_search == NAUTILUS_VIEW_INVALID_ID) {
- priv->view_mode_before_search = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view));
- }
- view_id = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SEARCH_VIEW);
- } else if (priv->content_view != NULL) {
- /* If there is already a view, just use the view mode that it's currently using, or
- * if we were on search before, use what we were using before entering
- * search mode */
- if (priv->view_mode_before_search != NAUTILUS_VIEW_INVALID_ID) {
- view_id = priv->view_mode_before_search;
- priv->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;
- } else {
- view_id = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view));
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ file = nautilus_file_get (location);
+ view = NULL;
+ guint view_id;
- }
+ view_id = NAUTILUS_VIEW_INVALID_ID;
- /* If there is not previous view in this slot, use the default view mode
- * from preferences */
- if (view_id == NAUTILUS_VIEW_INVALID_ID) {
- view_id = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER);
+ /* If we are in search, try to use by default list view. */
+ if (nautilus_file_is_in_search (file))
+ {
+ /* If it's already set, is because we already made the change to search mode,
+ * so the view mode of the current view will be the one search is using,
+ * which is not the one we are interested in */
+ if (priv->view_mode_before_search == NAUTILUS_VIEW_INVALID_ID)
+ {
+ priv->view_mode_before_search = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view));
}
-
- /* Try to reuse the current view */
- if (nautilus_window_slot_content_view_matches (self, view_id)) {
- view = priv->content_view;
- } else {
- view = NAUTILUS_VIEW (nautilus_files_view_new (view_id, self));
+ view_id = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_SEARCH_VIEW);
+ }
+ else if (priv->content_view != NULL)
+ {
+ /* If there is already a view, just use the view mode that it's currently using, or
+ * if we were on search before, use what we were using before entering
+ * search mode */
+ if (priv->view_mode_before_search != NAUTILUS_VIEW_INVALID_ID)
+ {
+ view_id = priv->view_mode_before_search;
+ priv->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;
+ }
+ else
+ {
+ view_id = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view));
}
+ }
- nautilus_file_unref (file);
+ /* If there is not previous view in this slot, use the default view mode
+ * from preferences */
+ if (view_id == NAUTILUS_VIEW_INVALID_ID)
+ {
+ view_id = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER);
+ }
- return view;
+ /* Try to reuse the current view */
+ if (nautilus_window_slot_content_view_matches (self, view_id))
+ {
+ view = priv->content_view;
+ }
+ else
+ {
+ view = NAUTILUS_VIEW (nautilus_files_view_new (view_id, self));
+ }
+
+ nautilus_file_unref (file);
+
+ return view;
}
static gboolean
nautilus_window_slot_content_view_matches (NautilusWindowSlot *self,
- guint id)
+ guint id)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->content_view == NULL) {
- return FALSE;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->content_view == NULL)
+ {
+ return FALSE;
+ }
- if (id != NAUTILUS_VIEW_INVALID_ID && NAUTILUS_IS_FILES_VIEW (priv->content_view)) {
- return nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view)) == id;
- } else {
- return FALSE;
- }
+ if (id != NAUTILUS_VIEW_INVALID_ID && NAUTILUS_IS_FILES_VIEW (priv->content_view))
+ {
+ return nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view)) == id;
+ }
+ else
+ {
+ return FALSE;
+ }
}
static void
update_search_visible (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
- NautilusQuery *query;
- NautilusView *view;
-
- priv = nautilus_window_slot_get_instance_private (self);
-
- view = nautilus_window_slot_get_current_view (self);
- /* If we changed location just to another search location, for example,
- * when changing the query, just keep the search visible.
- * Make sure the search is visible though, since we could be returning
- * from a previous search location when using the history */
- if (nautilus_view_is_searching (view)) {
- nautilus_window_slot_set_search_visible (self, TRUE);
- return;
- }
-
- query = nautilus_query_editor_get_query (priv->query_editor);
- if (query) {
- /* If the view is not searching, but search is visible, and the
- * query is empty, we don't hide it. Some users enable the search
- * and then change locations, then they search. */
- if (!nautilus_query_is_empty (query))
- nautilus_window_slot_set_search_visible (self, FALSE);
- g_object_unref (query);
+ NautilusWindowSlotPrivate *priv;
+ NautilusQuery *query;
+ NautilusView *view;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+
+ view = nautilus_window_slot_get_current_view (self);
+ /* If we changed location just to another search location, for example,
+ * when changing the query, just keep the search visible.
+ * Make sure the search is visible though, since we could be returning
+ * from a previous search location when using the history */
+ if (nautilus_view_is_searching (view))
+ {
+ nautilus_window_slot_set_search_visible (self, TRUE);
+ return;
+ }
+
+ query = nautilus_query_editor_get_query (priv->query_editor);
+ if (query)
+ {
+ /* If the view is not searching, but search is visible, and the
+ * query is empty, we don't hide it. Some users enable the search
+ * and then change locations, then they search. */
+ if (!nautilus_query_is_empty (query))
+ {
+ nautilus_window_slot_set_search_visible (self, FALSE);
}
+ g_object_unref (query);
+ }
- if (priv->pending_search_text)
- nautilus_window_slot_search (self, g_strdup (priv->pending_search_text));
+ if (priv->pending_search_text)
+ {
+ nautilus_window_slot_search (self, g_strdup (priv->pending_search_text));
+ }
}
static void
nautilus_window_slot_sync_actions (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- GAction *action;
- GVariant *variant;
+ GAction *action;
+ GVariant *variant;
- priv = nautilus_window_slot_get_instance_private (self);
- if (!nautilus_window_slot_get_active (self)) {
- return;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (!nautilus_window_slot_get_active (self))
+ {
+ return;
+ }
- if (priv->content_view == NULL || priv->new_content_view != NULL) {
- return;
- }
+ if (priv->content_view == NULL || priv->new_content_view != NULL)
+ {
+ return;
+ }
- /* Check if we need to close the search or show search after changing the location.
- * Needs to be done after the change has been done, if not, a loop happens,
- * because setting the search enabled or not actually opens a location */
- update_search_visible (self);
+ /* Check if we need to close the search or show search after changing the location.
+ * Needs to be done after the change has been done, if not, a loop happens,
+ * because setting the search enabled or not actually opens a location */
+ update_search_visible (self);
- /* Files view mode */
- action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group), "files-view-mode");
- if (g_action_get_enabled (action)) {
- variant = g_variant_new_uint32 (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (nautilus_window_slot_get_current_view (self))));
- g_action_change_state (action, variant);
- }
+ /* Files view mode */
+ action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group), "files-view-mode");
+ if (g_action_get_enabled (action))
+ {
+ variant = g_variant_new_uint32 (nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (nautilus_window_slot_get_current_view (self))));
+ g_action_change_state (action, variant);
+ }
}
static void
query_editor_cancel_callback (NautilusQueryEditor *editor,
NautilusWindowSlot *self)
{
- nautilus_window_slot_set_search_visible (self, FALSE);
+ nautilus_window_slot_set_search_visible (self, FALSE);
}
static void
query_editor_activated_callback (NautilusQueryEditor *editor,
NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->content_view != NULL) {
- if (NAUTILUS_IS_FILES_VIEW (priv->content_view)) {
- nautilus_files_view_activate_selection (NAUTILUS_FILES_VIEW (priv->content_view));
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->content_view != NULL)
+ {
+ if (NAUTILUS_IS_FILES_VIEW (priv->content_view))
+ {
+ nautilus_files_view_activate_selection (NAUTILUS_FILES_VIEW (priv->content_view));
+ }
- nautilus_window_slot_set_search_visible (self, FALSE);
- }
+ nautilus_window_slot_set_search_visible (self, FALSE);
+ }
}
static void
query_editor_changed_callback (NautilusQueryEditor *editor,
- NautilusQuery *query,
- gboolean reload,
- NautilusWindowSlot *self)
+ NautilusQuery *query,
+ gboolean reload,
+ NautilusWindowSlot *self)
{
- NautilusView *view;
+ NautilusView *view;
- view = nautilus_window_slot_get_current_view (self);
+ view = nautilus_window_slot_get_current_view (self);
- nautilus_view_set_search_query (view, query);
- nautilus_window_slot_open_location_full (self, nautilus_view_get_location (view), 0, NULL);
+ nautilus_view_set_search_query (view, query);
+ nautilus_window_slot_open_location_full (self, nautilus_view_get_location (view), 0, NULL);
}
static void
hide_query_editor (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
- NautilusView *view;
-
- priv = nautilus_window_slot_get_instance_private (self);
- view = nautilus_window_slot_get_current_view (self);
-
- gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->query_editor), FALSE);
-
- if (priv->qe_changed_id > 0) {
- g_signal_handler_disconnect (priv->query_editor, priv->qe_changed_id);
- priv->qe_changed_id = 0;
- }
- if (priv->qe_cancel_id > 0) {
- g_signal_handler_disconnect (priv->query_editor, priv->qe_cancel_id);
- priv->qe_cancel_id = 0;
- }
- if (priv->qe_activated_id > 0) {
- g_signal_handler_disconnect (priv->query_editor, priv->qe_activated_id);
- priv->qe_activated_id = 0;
- }
-
- nautilus_query_editor_set_query (priv->query_editor, NULL);
-
- if (nautilus_view_is_searching (view)) {
- GList *selection;
+ NautilusWindowSlotPrivate *priv;
+ NautilusView *view;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ view = nautilus_window_slot_get_current_view (self);
+
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->query_editor), FALSE);
+
+ if (priv->qe_changed_id > 0)
+ {
+ g_signal_handler_disconnect (priv->query_editor, priv->qe_changed_id);
+ priv->qe_changed_id = 0;
+ }
+ if (priv->qe_cancel_id > 0)
+ {
+ g_signal_handler_disconnect (priv->query_editor, priv->qe_cancel_id);
+ priv->qe_cancel_id = 0;
+ }
+ if (priv->qe_activated_id > 0)
+ {
+ g_signal_handler_disconnect (priv->query_editor, priv->qe_activated_id);
+ priv->qe_activated_id = 0;
+ }
+
+ nautilus_query_editor_set_query (priv->query_editor, NULL);
+
+ if (nautilus_view_is_searching (view))
+ {
+ GList *selection;
- selection = nautilus_view_get_selection (view);
+ selection = nautilus_view_get_selection (view);
- nautilus_view_set_search_query (view, NULL);
- nautilus_window_slot_open_location_full (self,
- nautilus_view_get_location (view),
- 0,
- selection);
+ nautilus_view_set_search_query (view, NULL);
+ nautilus_window_slot_open_location_full (self,
+ nautilus_view_get_location (view),
+ 0,
+ selection);
- nautilus_file_list_free (selection);
- }
+ nautilus_file_list_free (selection);
+ }
- if (nautilus_window_slot_get_active (self)) {
- gtk_widget_grab_focus (GTK_WIDGET (priv->window));
- }
+ if (nautilus_window_slot_get_active (self))
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (priv->window));
+ }
}
static GFile *
nautilus_window_slot_get_current_location (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->pending_location != NULL) {
- return priv->pending_location;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->pending_location != NULL)
+ {
+ return priv->pending_location;
+ }
- if (priv->location != NULL) {
- return priv->location;
- }
+ if (priv->location != NULL)
+ {
+ return priv->location;
+ }
- return NULL;
+ return NULL;
}
static void
show_query_editor (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
- NautilusView *view;
+ NautilusWindowSlotPrivate *priv;
+ NautilusView *view;
- priv = nautilus_window_slot_get_instance_private (self);
- view = nautilus_window_slot_get_current_view (self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ view = nautilus_window_slot_get_current_view (self);
- if (nautilus_view_is_searching (view)) {
- NautilusQuery *query;
+ if (nautilus_view_is_searching (view))
+ {
+ NautilusQuery *query;
- query = nautilus_view_get_search_query (view);
+ query = nautilus_view_get_search_query (view);
- if (query != NULL) {
- nautilus_query_editor_set_query (priv->query_editor, query);
- }
+ if (query != NULL)
+ {
+ nautilus_query_editor_set_query (priv->query_editor, query);
}
-
- gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->query_editor), TRUE);
- gtk_widget_grab_focus (GTK_WIDGET (priv->query_editor));
-
- if (priv->qe_changed_id == 0) {
- priv->qe_changed_id =
- g_signal_connect (priv->query_editor, "changed",
- G_CALLBACK (query_editor_changed_callback), self);
- }
- if (priv->qe_cancel_id == 0) {
- priv->qe_cancel_id =
- g_signal_connect (priv->query_editor, "cancel",
- G_CALLBACK (query_editor_cancel_callback), self);
- }
- if (priv->qe_activated_id == 0) {
- priv->qe_activated_id =
- g_signal_connect (priv->query_editor, "activated",
- G_CALLBACK (query_editor_activated_callback), self);
- }
+ }
+
+ gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->query_editor), TRUE);
+ gtk_widget_grab_focus (GTK_WIDGET (priv->query_editor));
+
+ if (priv->qe_changed_id == 0)
+ {
+ priv->qe_changed_id =
+ g_signal_connect (priv->query_editor, "changed",
+ G_CALLBACK (query_editor_changed_callback), self);
+ }
+ if (priv->qe_cancel_id == 0)
+ {
+ priv->qe_cancel_id =
+ g_signal_connect (priv->query_editor, "cancel",
+ G_CALLBACK (query_editor_cancel_callback), self);
+ }
+ if (priv->qe_activated_id == 0)
+ {
+ priv->qe_activated_id =
+ g_signal_connect (priv->query_editor, "activated",
+ G_CALLBACK (query_editor_activated_callback), self);
+ }
}
static void
nautilus_window_slot_set_search_visible (NautilusWindowSlot *self,
- gboolean visible)
+ gboolean visible)
{
- NautilusWindowSlotPrivate *priv;
- GAction *action;
+ NautilusWindowSlotPrivate *priv;
+ GAction *action;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group),
- "search-visible");
- g_action_change_state (action, g_variant_new_boolean (visible));
+ action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group),
+ "search-visible");
+ g_action_change_state (action, g_variant_new_boolean (visible));
}
static gboolean
nautilus_window_slot_get_search_visible (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
- GAction *action;
- GVariant *state;
- gboolean searching;
+ NautilusWindowSlotPrivate *priv;
+ GAction *action;
+ GVariant *state;
+ gboolean searching;
- priv = nautilus_window_slot_get_instance_private (self);
- action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group),
- "search-visible");
- state = g_action_get_state (action);
- searching = g_variant_get_boolean (state);
+ priv = nautilus_window_slot_get_instance_private (self);
+ action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group),
+ "search-visible");
+ state = g_action_get_state (action);
+ searching = g_variant_get_boolean (state);
- g_variant_unref (state);
+ g_variant_unref (state);
- return searching;
+ return searching;
}
void
nautilus_window_slot_search (NautilusWindowSlot *self,
const gchar *text)
{
- NautilusWindowSlotPrivate *priv;
- NautilusView *view;
-
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->pending_search_text) {
- g_free (priv->pending_search_text);
- priv->pending_search_text = NULL;
- }
-
- view = nautilus_window_slot_get_current_view (self);
- /* We could call this when the location is still being checked in the
- * window slot. For that, save the search we want to do for once we have
- * a view set up */
- if (view) {
- nautilus_window_slot_set_search_visible (self, TRUE);
- nautilus_query_editor_set_text (priv->query_editor, text);
- } else {
- priv->pending_search_text = g_strdup (text);
- }
+ NautilusWindowSlotPrivate *priv;
+ NautilusView *view;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->pending_search_text)
+ {
+ g_free (priv->pending_search_text);
+ priv->pending_search_text = NULL;
+ }
+
+ view = nautilus_window_slot_get_current_view (self);
+ /* We could call this when the location is still being checked in the
+ * window slot. For that, save the search we want to do for once we have
+ * a view set up */
+ if (view)
+ {
+ nautilus_window_slot_set_search_visible (self, TRUE);
+ nautilus_query_editor_set_text (priv->query_editor, text);
+ }
+ else
+ {
+ priv->pending_search_text = g_strdup (text);
+ }
}
gboolean
nautilus_window_slot_handle_event (NautilusWindowSlot *self,
- GdkEventKey *event)
+ GdkEventKey *event)
{
- NautilusWindowSlotPrivate *priv;
- gboolean retval;
- GAction *action;
+ NautilusWindowSlotPrivate *priv;
+ gboolean retval;
+ GAction *action;
- priv = nautilus_window_slot_get_instance_private (self);
- retval = FALSE;
- action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group),
- "search-visible");
+ priv = nautilus_window_slot_get_instance_private (self);
+ retval = FALSE;
+ action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group),
+ "search-visible");
- /* If the action is not enabled, don't try to handle search */
- if (g_action_get_enabled (action)) {
- retval = gtk_search_bar_handle_event (GTK_SEARCH_BAR (priv->query_editor),
- (GdkEvent*) event);
- }
+ /* If the action is not enabled, don't try to handle search */
+ if (g_action_get_enabled (action))
+ {
+ retval = gtk_search_bar_handle_event (GTK_SEARCH_BAR (priv->query_editor),
+ (GdkEvent *) event);
+ }
- if (retval) {
- nautilus_window_slot_set_search_visible (self, TRUE);
- }
+ if (retval)
+ {
+ nautilus_window_slot_set_search_visible (self, TRUE);
+ }
- return retval;
+ return retval;
}
static void
real_active (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
- NautilusWindow *window;
- int page_num;
+ NautilusWindowSlotPrivate *priv;
+ NautilusWindow *window;
+ int page_num;
- priv = nautilus_window_slot_get_instance_private (self);
- window = priv->window;
- page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nautilus_window_get_notebook (window)),
- GTK_WIDGET (self));
- g_assert (page_num >= 0);
+ priv = nautilus_window_slot_get_instance_private (self);
+ window = priv->window;
+ page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nautilus_window_get_notebook (window)),
+ GTK_WIDGET (self));
+ g_assert (page_num >= 0);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (nautilus_window_get_notebook (window)), page_num);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (nautilus_window_get_notebook (window)), page_num);
- /* sync window to new slot */
- nautilus_window_sync_allow_stop (window, self);
- nautilus_window_sync_title (window, self);
- nautilus_window_sync_location_widgets (window);
- nautilus_window_slot_sync_actions (self);
+ /* sync window to new slot */
+ nautilus_window_sync_allow_stop (window, self);
+ nautilus_window_sync_title (window, self);
+ nautilus_window_sync_location_widgets (window);
+ nautilus_window_slot_sync_actions (self);
- gtk_widget_insert_action_group (GTK_WIDGET (window), "slot", priv->slot_action_group);
+ gtk_widget_insert_action_group (GTK_WIDGET (window), "slot", priv->slot_action_group);
}
static void
real_inactive (NautilusWindowSlot *self)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = nautilus_window_slot_get_window (self);
- g_assert (self == nautilus_window_get_active_slot (window));
+ window = nautilus_window_slot_get_window (self);
+ g_assert (self == nautilus_window_get_active_slot (window));
- gtk_widget_insert_action_group (GTK_WIDGET (window), "slot", NULL);
+ gtk_widget_insert_action_group (GTK_WIDGET (window), "slot", NULL);
}
static void
remove_all_extra_location_widgets (GtkWidget *widget,
- gpointer data)
+ gpointer data)
{
- NautilusWindowSlotPrivate *priv;
- NautilusWindowSlot *self = data;
- NautilusDirectory *directory;
+ NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlot *self = data;
+ NautilusDirectory *directory;
- priv = nautilus_window_slot_get_instance_private (self);
- directory = nautilus_directory_get (priv->location);
- if (widget != GTK_WIDGET (priv->query_editor)) {
- gtk_container_remove (GTK_CONTAINER (priv->extra_location_widgets), widget);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ directory = nautilus_directory_get (priv->location);
+ if (widget != GTK_WIDGET (priv->query_editor))
+ {
+ gtk_container_remove (GTK_CONTAINER (priv->extra_location_widgets), widget);
+ }
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
}
static void
nautilus_window_slot_remove_extra_location_widgets (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- gtk_container_foreach (GTK_CONTAINER (priv->extra_location_widgets),
- remove_all_extra_location_widgets,
- self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ gtk_container_foreach (GTK_CONTAINER (priv->extra_location_widgets),
+ remove_all_extra_location_widgets,
+ self);
}
static void
nautilus_window_slot_add_extra_location_widget (NautilusWindowSlot *self,
GtkWidget *widget)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- gtk_box_pack_start (GTK_BOX (priv->extra_location_widgets),
- widget, FALSE, TRUE, 0);
- gtk_widget_show (priv->extra_location_widgets);
+ priv = nautilus_window_slot_get_instance_private (self);
+ gtk_box_pack_start (GTK_BOX (priv->extra_location_widgets),
+ widget, FALSE, TRUE, 0);
+ gtk_widget_show (priv->extra_location_widgets);
}
static void
-nautilus_window_slot_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_window_slot_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (object);
+ NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (object);
- switch (property_id) {
+ switch (property_id)
+ {
case PROP_ACTIVE:
- nautilus_window_slot_set_active (self, g_value_get_boolean (value));
- break;
- case PROP_WINDOW:
- nautilus_window_slot_set_window (self, g_value_get_object (value));
- break;
- case PROP_LOCATION:
- nautilus_window_slot_set_location (self, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ {
+ nautilus_window_slot_set_active (self, g_value_get_boolean (value));
+ }
+ break;
+
+ case PROP_WINDOW:
+ {
+ nautilus_window_slot_set_window (self, g_value_get_object (value));
+ }
+ break;
+
+ case PROP_LOCATION:
+ {
+ nautilus_window_slot_set_location (self, g_value_get_object (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_window_slot_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_window_slot_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (object);
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (object);
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- switch (property_id) {
+ switch (property_id)
+ {
case PROP_ACTIVE:
- g_value_set_boolean (value, nautilus_window_slot_get_active (self));
- break;
- case PROP_WINDOW:
- g_value_set_object (value, priv->window);
- break;
+ {
+ g_value_set_boolean (value, nautilus_window_slot_get_active (self));
+ }
+ break;
+
+ case PROP_WINDOW:
+ {
+ g_value_set_object (value, priv->window);
+ }
+ break;
+
case PROP_ICON:
- g_value_set_object (value, nautilus_window_slot_get_icon (self));
- break;
+ {
+ g_value_set_object (value, nautilus_window_slot_get_icon (self));
+ }
+ break;
+
case PROP_TOOLBAR_MENU_SECTIONS:
- g_value_set_pointer (value, nautilus_window_slot_get_toolbar_menu_sections (self));
- break;
+ {
+ g_value_set_pointer (value, nautilus_window_slot_get_toolbar_menu_sections (self));
+ }
+ break;
+
case PROP_LOADING:
- g_value_set_boolean (value, nautilus_window_slot_get_loading (self));
- break;
+ {
+ g_value_set_boolean (value, nautilus_window_slot_get_loading (self));
+ }
+ break;
+
case PROP_LOCATION:
- g_value_set_object (value, nautilus_window_slot_get_current_location (self));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
- break;
- }
+ {
+ g_value_set_object (value, nautilus_window_slot_get_current_location (self));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_window_slot_constructed (GObject *object)
{
- NautilusWindowSlotPrivate *priv;
- NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (object);
- GtkWidget *extras_vbox;
- GtkStyleContext *style_context;
+ NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlot *self = NAUTILUS_WINDOW_SLOT (object);
+ GtkWidget *extras_vbox;
+ GtkStyleContext *style_context;
- priv = nautilus_window_slot_get_instance_private (self);
- G_OBJECT_CLASS (nautilus_window_slot_parent_class)->constructed (object);
+ priv = nautilus_window_slot_get_instance_private (self);
+ G_OBJECT_CLASS (nautilus_window_slot_parent_class)->constructed (object);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
- GTK_ORIENTATION_VERTICAL);
- gtk_widget_show (GTK_WIDGET (self));
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
+ GTK_ORIENTATION_VERTICAL);
+ gtk_widget_show (GTK_WIDGET (self));
- extras_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- style_context = gtk_widget_get_style_context (extras_vbox);
- gtk_style_context_add_class (style_context, "searchbar-container");
- priv->extra_location_widgets = extras_vbox;
- gtk_box_pack_start (GTK_BOX (self), extras_vbox, FALSE, FALSE, 0);
- gtk_widget_show (extras_vbox);
+ extras_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ style_context = gtk_widget_get_style_context (extras_vbox);
+ gtk_style_context_add_class (style_context, "searchbar-container");
+ priv->extra_location_widgets = extras_vbox;
+ gtk_box_pack_start (GTK_BOX (self), extras_vbox, FALSE, FALSE, 0);
+ gtk_widget_show (extras_vbox);
- priv->query_editor = NAUTILUS_QUERY_EDITOR (nautilus_query_editor_new ());
- gtk_widget_show (GTK_WIDGET (priv->query_editor));
- nautilus_window_slot_add_extra_location_widget (self, GTK_WIDGET (priv->query_editor));
+ priv->query_editor = NAUTILUS_QUERY_EDITOR (nautilus_query_editor_new ());
+ gtk_widget_show (GTK_WIDGET (priv->query_editor));
+ nautilus_window_slot_add_extra_location_widget (self, GTK_WIDGET (priv->query_editor));
- g_object_bind_property (self, "location",
- priv->query_editor, "location",
- G_BINDING_DEFAULT);
+ g_object_bind_property (self, "location",
+ priv->query_editor, "location",
+ G_BINDING_DEFAULT);
- priv->title = g_strdup (_("Loading…"));
+ priv->title = g_strdup (_("Loading…"));
}
static void
@@ -701,36 +785,40 @@ action_search_visible (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- NautilusWindowSlot *self;
- GVariant *current_state;
+ NautilusWindowSlot *self;
+ GVariant *current_state;
- self = NAUTILUS_WINDOW_SLOT (user_data);
- current_state = g_action_get_state (G_ACTION (action));
- if (g_variant_get_boolean (current_state) != g_variant_get_boolean (state)) {
- g_simple_action_set_state (action, state);
+ self = NAUTILUS_WINDOW_SLOT (user_data);
+ current_state = g_action_get_state (G_ACTION (action));
+ if (g_variant_get_boolean (current_state) != g_variant_get_boolean (state))
+ {
+ g_simple_action_set_state (action, state);
- if (g_variant_get_boolean (state)) {
- show_query_editor (self);
- } else {
- hide_query_editor (self);
- }
+ if (g_variant_get_boolean (state))
+ {
+ show_query_editor (self);
+ }
+ else
+ {
+ hide_query_editor (self);
}
+ }
- g_variant_unref (current_state);
+ g_variant_unref (current_state);
}
static void
change_files_view_mode (NautilusWindowSlot *self,
guint view_id)
{
- const gchar *preferences_key;
+ const gchar *preferences_key;
- nautilus_window_slot_set_content_view (self, view_id);
- preferences_key = nautilus_view_is_searching (nautilus_window_slot_get_current_view (self)) ?
- NAUTILUS_PREFERENCES_SEARCH_VIEW :
- NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER;
+ nautilus_window_slot_set_content_view (self, view_id);
+ preferences_key = nautilus_view_is_searching (nautilus_window_slot_get_current_view (self)) ?
+ NAUTILUS_PREFERENCES_SEARCH_VIEW :
+ NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER;
- g_settings_set_enum (nautilus_preferences, preferences_key, view_id);
+ g_settings_set_enum (nautilus_preferences, preferences_key, view_id);
}
static void
@@ -738,93 +826,102 @@ action_files_view_mode_toggle (GSimpleAction *action,
GVariant *value,
gpointer user_data)
{
- NautilusWindowSlot *self;
- NautilusWindowSlotPrivate *priv;
- guint current_view_id;
+ NautilusWindowSlot *self;
+ NautilusWindowSlotPrivate *priv;
+ guint current_view_id;
- self = NAUTILUS_WINDOW_SLOT (user_data);
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->content_view == NULL)
- return;
+ self = NAUTILUS_WINDOW_SLOT (user_data);
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->content_view == NULL)
+ {
+ return;
+ }
- current_view_id = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view));
- if (current_view_id == NAUTILUS_VIEW_LIST_ID)
- change_files_view_mode (self, NAUTILUS_VIEW_GRID_ID);
- else
- change_files_view_mode (self, NAUTILUS_VIEW_LIST_ID);
+ current_view_id = nautilus_files_view_get_view_id (NAUTILUS_FILES_VIEW (priv->content_view));
+ if (current_view_id == NAUTILUS_VIEW_LIST_ID)
+ {
+ change_files_view_mode (self, NAUTILUS_VIEW_GRID_ID);
+ }
+ else
+ {
+ change_files_view_mode (self, NAUTILUS_VIEW_LIST_ID);
+ }
}
static void
action_files_view_mode (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+ GVariant *value,
+ gpointer user_data)
{
- NautilusWindowSlot *self;
- guint view_id;
+ NautilusWindowSlot *self;
+ guint view_id;
- view_id = g_variant_get_uint32 (value);
- self = NAUTILUS_WINDOW_SLOT (user_data);
+ view_id = g_variant_get_uint32 (value);
+ self = NAUTILUS_WINDOW_SLOT (user_data);
- if (!NAUTILUS_IS_FILES_VIEW (nautilus_window_slot_get_current_view (self)))
- return;
+ if (!NAUTILUS_IS_FILES_VIEW (nautilus_window_slot_get_current_view (self)))
+ {
+ return;
+ }
- change_files_view_mode (self, view_id);
+ change_files_view_mode (self, view_id);
- g_simple_action_set_state (action, value);
+ g_simple_action_set_state (action, value);
}
-const GActionEntry slot_entries[] = {
- /* 4 is NAUTILUS_VIEW_INVALID_ID */
- { "files-view-mode", NULL, "u", "uint32 4", action_files_view_mode },
- { "files-view-mode-toggle", action_files_view_mode_toggle },
- { "search-visible", NULL, NULL, "false", action_search_visible },
+const GActionEntry slot_entries[] =
+{
+ /* 4 is NAUTILUS_VIEW_INVALID_ID */
+ { "files-view-mode", NULL, "u", "uint32 4", action_files_view_mode },
+ { "files-view-mode-toggle", action_files_view_mode_toggle },
+ { "search-visible", NULL, NULL, "false", action_search_visible },
};
static void
nautilus_window_slot_init (NautilusWindowSlot *self)
{
- GApplication *app;
- NautilusWindowSlotPrivate *priv;
+ GApplication *app;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- app = g_application_get_default ();
+ priv = nautilus_window_slot_get_instance_private (self);
+ app = g_application_get_default ();
- priv->slot_action_group = G_ACTION_GROUP (g_simple_action_group_new ());
- g_action_map_add_action_entries (G_ACTION_MAP (priv->slot_action_group),
- slot_entries,
- G_N_ELEMENTS (slot_entries),
- self);
- gtk_widget_insert_action_group (GTK_WIDGET (self),
- "slot",
- G_ACTION_GROUP (priv->slot_action_group));
- nautilus_application_set_accelerator (app, "slot.files-view-mode(uint32 1)", "<control>1");
- nautilus_application_set_accelerator (app, "slot.files-view-mode(uint32 0)", "<control>2");
- nautilus_application_set_accelerator (app, "slot.search-visible", "<control>f");
+ priv->slot_action_group = G_ACTION_GROUP (g_simple_action_group_new ());
+ g_action_map_add_action_entries (G_ACTION_MAP (priv->slot_action_group),
+ slot_entries,
+ G_N_ELEMENTS (slot_entries),
+ self);
+ gtk_widget_insert_action_group (GTK_WIDGET (self),
+ "slot",
+ G_ACTION_GROUP (priv->slot_action_group));
+ nautilus_application_set_accelerator (app, "slot.files-view-mode(uint32 1)", "<control>1");
+ nautilus_application_set_accelerator (app, "slot.files-view-mode(uint32 0)", "<control>2");
+ nautilus_application_set_accelerator (app, "slot.search-visible", "<control>f");
- priv->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;
+ priv->view_mode_before_search = NAUTILUS_VIEW_INVALID_ID;
}
#define DEBUG_FLAG NAUTILUS_DEBUG_WINDOW
#include "nautilus-debug.h"
-static void begin_location_change (NautilusWindowSlot *slot,
- GFile *location,
- GFile *previous_location,
- GList *new_selection,
- NautilusLocationChangeType type,
- guint distance,
- const char *scroll_pos);
-static void free_location_change (NautilusWindowSlot *self);
-static void end_location_change (NautilusWindowSlot *self);
-static void got_file_info_for_view_selection_callback (NautilusFile *file,
- gpointer callback_data);
-static gboolean setup_view (NautilusWindowSlot *self,
- NautilusView *view);
-static void load_new_location (NautilusWindowSlot *slot,
- GFile *location,
- GList *selection,
- gboolean tell_current_content_view,
- gboolean tell_new_content_view);
+static void begin_location_change (NautilusWindowSlot *slot,
+ GFile *location,
+ GFile *previous_location,
+ GList *new_selection,
+ NautilusLocationChangeType type,
+ guint distance,
+ const char *scroll_pos);
+static void free_location_change (NautilusWindowSlot *self);
+static void end_location_change (NautilusWindowSlot *self);
+static void got_file_info_for_view_selection_callback (NautilusFile *file,
+ gpointer callback_data);
+static gboolean setup_view (NautilusWindowSlot *self,
+ NautilusView *view);
+static void load_new_location (NautilusWindowSlot *slot,
+ GFile *location,
+ GList *selection,
+ gboolean tell_current_content_view,
+ gboolean tell_new_content_view);
void
nautilus_window_slot_open_location_full (NautilusWindowSlot *self,
@@ -832,108 +929,119 @@ nautilus_window_slot_open_location_full (NautilusWindowSlot *self,
NautilusWindowOpenFlags flags,
GList *new_selection)
{
- NautilusWindowSlotPrivate *priv;
- GFile *old_location;
- GList *old_selection;
+ NautilusWindowSlotPrivate *priv;
+ GFile *old_location;
+ GList *old_selection;
- priv = nautilus_window_slot_get_instance_private (self);
- old_selection = NULL;
- old_location = nautilus_window_slot_get_location (self);
-
- if (priv->content_view) {
- old_selection = nautilus_view_get_selection (priv->content_view);
- }
- if (old_location && g_file_equal (old_location, location) &&
- nautilus_file_selection_equal (old_selection, new_selection))
- goto done;
+ priv = nautilus_window_slot_get_instance_private (self);
+ old_selection = NULL;
+ old_location = nautilus_window_slot_get_location (self);
- begin_location_change (self, location, old_location, new_selection,
- NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL);
-
- done:
- nautilus_file_list_free (old_selection);
- nautilus_profile_end (NULL);
-}
+ if (priv->content_view)
+ {
+ old_selection = nautilus_view_get_selection (priv->content_view);
+ }
+ if (old_location && g_file_equal (old_location, location) &&
+ nautilus_file_selection_equal (old_selection, new_selection))
+ {
+ goto done;
+ }
-static GList*
-check_select_old_location_containing_folder (GList *new_selection,
- GFile *location,
- GFile *previous_location)
-{
- GFile *from_folder, *parent;
+ begin_location_change (self, location, old_location, new_selection,
+ NAUTILUS_LOCATION_CHANGE_STANDARD, 0, NULL);
- /* If there is no new selection and the new location is
- * a (grand)parent of the old location then we automatically
- * select the folder the previous location was in */
- if (new_selection == NULL && previous_location != NULL &&
- g_file_has_prefix (previous_location, location)) {
- from_folder = g_object_ref (previous_location);
- parent = g_file_get_parent (from_folder);
- while (parent != NULL && !g_file_equal (parent, location)) {
- g_object_unref (from_folder);
- from_folder = parent;
- parent = g_file_get_parent (from_folder);
- }
+done:
+ nautilus_file_list_free (old_selection);
+ nautilus_profile_end (NULL);
+}
+
+static GList *
+check_select_old_location_containing_folder (GList *new_selection,
+ GFile *location,
+ GFile *previous_location)
+{
+ GFile *from_folder, *parent;
+
+ /* If there is no new selection and the new location is
+ * a (grand)parent of the old location then we automatically
+ * select the folder the previous location was in */
+ if (new_selection == NULL && previous_location != NULL &&
+ g_file_has_prefix (previous_location, location))
+ {
+ from_folder = g_object_ref (previous_location);
+ parent = g_file_get_parent (from_folder);
+ while (parent != NULL && !g_file_equal (parent, location))
+ {
+ g_object_unref (from_folder);
+ from_folder = parent;
+ parent = g_file_get_parent (from_folder);
+ }
- if (parent != NULL) {
- new_selection = g_list_prepend (NULL, nautilus_file_get (from_folder));
- g_object_unref (parent);
- }
+ if (parent != NULL)
+ {
+ new_selection = g_list_prepend (NULL, nautilus_file_get (from_folder));
+ g_object_unref (parent);
+ }
- g_object_unref (from_folder);
- }
+ g_object_unref (from_folder);
+ }
- return new_selection;
+ return new_selection;
}
static void
check_force_reload (GFile *location,
NautilusLocationChangeType type)
{
- NautilusDirectory *directory;
- NautilusFile *file;
- gboolean force_reload;
-
- /* The code to force a reload is here because if we do it
- * after determining an initial view (in the components), then
- * we end up fetching things twice.
- */
- directory = nautilus_directory_get (location);
- file = nautilus_file_get (location);
-
- if (type == NAUTILUS_LOCATION_CHANGE_RELOAD) {
- force_reload = TRUE;
- } else {
- force_reload = !nautilus_directory_is_local (directory);
- }
-
- /* We need to invalidate file attributes as well due to how mounting works
- * in the window slot and to avoid other caching issues.
- * Read handle_mount_if_needed for one example */
- if (force_reload) {
- nautilus_file_invalidate_all_attributes (file);
- nautilus_directory_force_reload (directory);
- }
-
- nautilus_directory_unref (directory);
- nautilus_file_unref (file);
+ NautilusDirectory *directory;
+ NautilusFile *file;
+ gboolean force_reload;
+
+ /* The code to force a reload is here because if we do it
+ * after determining an initial view (in the components), then
+ * we end up fetching things twice.
+ */
+ directory = nautilus_directory_get (location);
+ file = nautilus_file_get (location);
+
+ if (type == NAUTILUS_LOCATION_CHANGE_RELOAD)
+ {
+ force_reload = TRUE;
+ }
+ else
+ {
+ force_reload = !nautilus_directory_is_local (directory);
+ }
+
+ /* We need to invalidate file attributes as well due to how mounting works
+ * in the window slot and to avoid other caching issues.
+ * Read handle_mount_if_needed for one example */
+ if (force_reload)
+ {
+ nautilus_file_invalidate_all_attributes (file);
+ nautilus_directory_force_reload (directory);
+ }
+
+ nautilus_directory_unref (directory);
+ nautilus_file_unref (file);
}
static void
save_scroll_position_for_history (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
-
- priv = nautilus_window_slot_get_instance_private (self);
- char *current_pos;
- /* Set current_bookmark scroll pos */
- if (priv->current_location_bookmark != NULL &&
- priv->content_view != NULL &&
- NAUTILUS_IS_FILES_VIEW (priv->content_view)) {
- current_pos = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW (priv->content_view));
- nautilus_bookmark_set_scroll_pos (priv->current_location_bookmark, current_pos);
- g_free (current_pos);
- }
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ char *current_pos;
+ /* Set current_bookmark scroll pos */
+ if (priv->current_location_bookmark != NULL &&
+ priv->content_view != NULL &&
+ NAUTILUS_IS_FILES_VIEW (priv->content_view))
+ {
+ current_pos = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW (priv->content_view));
+ nautilus_bookmark_set_scroll_pos (priv->current_location_bookmark, current_pos);
+ g_free (current_pos);
+ }
}
/*
@@ -961,201 +1069,218 @@ begin_location_change (NautilusWindowSlot *self,
guint distance,
const char *scroll_pos)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (self != NULL);
- g_assert (location != NULL);
- g_assert (type == NAUTILUS_LOCATION_CHANGE_BACK
- || type == NAUTILUS_LOCATION_CHANGE_FORWARD
- || distance == 0);
+ g_assert (self != NULL);
+ g_assert (location != NULL);
+ g_assert (type == NAUTILUS_LOCATION_CHANGE_BACK
+ || type == NAUTILUS_LOCATION_CHANGE_FORWARD
+ || distance == 0);
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- priv = nautilus_window_slot_get_instance_private (self);
- /* Avoid to update status from the current view in our async calls */
- nautilus_window_slot_disconnect_content_view (self);
- /* We are going to change the location, so make sure we stop any loading
- * or searching of the previous view, so we avoid to be slow */
- nautilus_window_slot_stop_loading (self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ /* Avoid to update status from the current view in our async calls */
+ nautilus_window_slot_disconnect_content_view (self);
+ /* We are going to change the location, so make sure we stop any loading
+ * or searching of the previous view, so we avoid to be slow */
+ nautilus_window_slot_stop_loading (self);
- nautilus_window_slot_set_allow_stop (self, TRUE);
+ nautilus_window_slot_set_allow_stop (self, TRUE);
- new_selection = check_select_old_location_containing_folder (new_selection, location, previous_location);
+ new_selection = check_select_old_location_containing_folder (new_selection, location, previous_location);
- g_assert (priv->pending_location == NULL);
+ g_assert (priv->pending_location == NULL);
- priv->pending_location = g_object_ref (location);
- priv->location_change_type = type;
- priv->location_change_distance = distance;
- priv->tried_mount = FALSE;
- priv->pending_selection = nautilus_file_list_copy (new_selection);
+ priv->pending_location = g_object_ref (location);
+ priv->location_change_type = type;
+ priv->location_change_distance = distance;
+ priv->tried_mount = FALSE;
+ priv->pending_selection = nautilus_file_list_copy (new_selection);
- priv->pending_scroll_to = g_strdup (scroll_pos);
+ priv->pending_scroll_to = g_strdup (scroll_pos);
- check_force_reload (location, type);
+ check_force_reload (location, type);
- save_scroll_position_for_history (self);
+ save_scroll_position_for_history (self);
- /* Get the info needed to make decisions about how to open the new location */
- priv->determine_view_file = nautilus_file_get (location);
- g_assert (priv->determine_view_file != NULL);
+ /* Get the info needed to make decisions about how to open the new location */
+ priv->determine_view_file = nautilus_file_get (location);
+ g_assert (priv->determine_view_file != NULL);
- nautilus_file_call_when_ready (priv->determine_view_file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT,
- got_file_info_for_view_selection_callback,
- self);
+ nautilus_file_call_when_ready (priv->determine_view_file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT,
+ got_file_info_for_view_selection_callback,
+ self);
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static void
nautilus_window_slot_set_location (NautilusWindowSlot *self,
GFile *location)
{
- NautilusWindowSlotPrivate *priv;
- GFile *old_location;
+ NautilusWindowSlotPrivate *priv;
+ GFile *old_location;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->location &&
- g_file_equal (location, priv->location)) {
- /* The location name could be updated even if the location
- * wasn't changed. This is the case for a search.
- */
- nautilus_window_slot_update_title (self);
- return;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->location &&
+ g_file_equal (location, priv->location))
+ {
+ /* The location name could be updated even if the location
+ * wasn't changed. This is the case for a search.
+ */
+ nautilus_window_slot_update_title (self);
+ return;
+ }
- old_location = priv->location;
- priv->location = g_object_ref (location);
+ old_location = priv->location;
+ priv->location = g_object_ref (location);
- if (nautilus_window_slot_get_active (self)) {
- nautilus_window_sync_location_widgets (priv->window);
- }
+ if (nautilus_window_slot_get_active (self))
+ {
+ nautilus_window_sync_location_widgets (priv->window);
+ }
- nautilus_window_slot_update_title (self);
+ nautilus_window_slot_update_title (self);
- if (old_location) {
- g_object_unref (old_location);
- }
+ if (old_location)
+ {
+ g_object_unref (old_location);
+ }
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCATION]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOCATION]);
}
static void
viewed_file_changed_callback (NautilusFile *file,
NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
- GFile *new_location;
- gboolean is_in_trash, was_in_trash;
+ NautilusWindowSlotPrivate *priv;
+ GFile *new_location;
+ gboolean is_in_trash, was_in_trash;
- g_assert (NAUTILUS_IS_FILE (file));
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_FILE (file));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- g_assert (file == priv->viewed_file);
+ priv = nautilus_window_slot_get_instance_private (self);
+ g_assert (file == priv->viewed_file);
- if (!nautilus_file_is_not_yet_confirmed (file)) {
- priv->viewed_file_seen = TRUE;
- }
+ if (!nautilus_file_is_not_yet_confirmed (file))
+ {
+ priv->viewed_file_seen = TRUE;
+ }
- was_in_trash = priv->viewed_file_in_trash;
+ was_in_trash = priv->viewed_file_in_trash;
- priv->viewed_file_in_trash = is_in_trash = nautilus_file_is_in_trash (file);
+ priv->viewed_file_in_trash = is_in_trash = nautilus_file_is_in_trash (file);
- if (nautilus_file_is_gone (file) || (is_in_trash && !was_in_trash)) {
- if (priv->viewed_file_seen) {
- GFile *go_to_file;
- GFile *parent;
- GFile *location;
- GMount *mount;
+ if (nautilus_file_is_gone (file) || (is_in_trash && !was_in_trash))
+ {
+ if (priv->viewed_file_seen)
+ {
+ GFile *go_to_file;
+ GFile *parent;
+ GFile *location;
+ GMount *mount;
- parent = NULL;
- location = nautilus_file_get_location (file);
+ parent = NULL;
+ location = nautilus_file_get_location (file);
- if (g_file_is_native (location)) {
- mount = nautilus_get_mounted_mount_for_root (location);
+ if (g_file_is_native (location))
+ {
+ mount = nautilus_get_mounted_mount_for_root (location);
- if (mount == NULL) {
- parent = g_file_get_parent (location);
- }
+ if (mount == NULL)
+ {
+ parent = g_file_get_parent (location);
+ }
- g_clear_object (&mount);
- }
+ g_clear_object (&mount);
+ }
- if (parent != NULL) {
- /* auto-show existing parent */
- go_to_file = nautilus_find_existing_uri_in_hierarchy (parent);
- } else {
- go_to_file = g_file_new_for_path (g_get_home_dir ());
- }
+ if (parent != NULL)
+ {
+ /* auto-show existing parent */
+ go_to_file = nautilus_find_existing_uri_in_hierarchy (parent);
+ }
+ else
+ {
+ go_to_file = g_file_new_for_path (g_get_home_dir ());
+ }
- nautilus_window_slot_open_location_full (self, go_to_file, 0, NULL);
+ nautilus_window_slot_open_location_full (self, go_to_file, 0, NULL);
- g_clear_object (&parent);
- g_object_unref (go_to_file);
- g_object_unref (location);
- }
- } else {
- new_location = nautilus_file_get_location (file);
- nautilus_window_slot_set_location (self, new_location);
- g_object_unref (new_location);
+ g_clear_object (&parent);
+ g_object_unref (go_to_file);
+ g_object_unref (location);
}
+ }
+ else
+ {
+ new_location = nautilus_file_get_location (file);
+ nautilus_window_slot_set_location (self, new_location);
+ g_object_unref (new_location);
+ }
}
static void
nautilus_window_slot_go_home (NautilusWindowSlot *self,
NautilusWindowOpenFlags flags)
{
- GFile *home;
+ GFile *home;
- g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (self));
- home = g_file_new_for_path (g_get_home_dir ());
- nautilus_window_slot_open_location_full (self, home, flags, NULL);
- g_object_unref (home);
+ home = g_file_new_for_path (g_get_home_dir ());
+ nautilus_window_slot_open_location_full (self, home, flags, NULL);
+ g_object_unref (home);
}
static void
nautilus_window_slot_set_viewed_file (NautilusWindowSlot *self,
NautilusFile *file)
{
- NautilusWindowSlotPrivate *priv;
- NautilusFileAttributes attributes;
+ NautilusWindowSlotPrivate *priv;
+ NautilusFileAttributes attributes;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->viewed_file == file) {
- return;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->viewed_file == file)
+ {
+ return;
+ }
- nautilus_file_ref (file);
+ nautilus_file_ref (file);
- if (priv->viewed_file != NULL) {
- g_signal_handlers_disconnect_by_func (priv->viewed_file,
- G_CALLBACK (viewed_file_changed_callback),
- self);
- nautilus_file_monitor_remove (priv->viewed_file,
- self);
- }
+ if (priv->viewed_file != NULL)
+ {
+ g_signal_handlers_disconnect_by_func (priv->viewed_file,
+ G_CALLBACK (viewed_file_changed_callback),
+ self);
+ nautilus_file_monitor_remove (priv->viewed_file,
+ self);
+ }
- if (file != NULL) {
- attributes =
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO;
- nautilus_file_monitor_add (file, self, attributes);
+ if (file != NULL)
+ {
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO;
+ nautilus_file_monitor_add (file, self, attributes);
- g_signal_connect_object (file, "changed",
- G_CALLBACK (viewed_file_changed_callback), self, 0);
- }
+ g_signal_connect_object (file, "changed",
+ G_CALLBACK (viewed_file_changed_callback), self, 0);
+ }
- nautilus_file_unref (priv->viewed_file);
- priv->viewed_file = file;
+ nautilus_file_unref (priv->viewed_file);
+ priv->viewed_file = file;
}
-typedef struct {
- GCancellable *cancellable;
- NautilusWindowSlot *slot;
+typedef struct
+{
+ GCancellable *cancellable;
+ NautilusWindowSlot *slot;
} MountNotMountedData;
static void
@@ -1163,44 +1288,48 @@ mount_not_mounted_callback (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- NautilusWindowSlotPrivate *priv;
- MountNotMountedData *data;
- NautilusWindowSlot *self;
- GError *error;
- GCancellable *cancellable;
-
- data = user_data;
- self = data->slot;
- priv = nautilus_window_slot_get_instance_private (self);
- cancellable = data->cancellable;
- g_free (data);
-
- if (g_cancellable_is_cancelled (cancellable)) {
- /* Cancelled, don't call back */
- g_object_unref (cancellable);
- return;
- }
-
- priv->mount_cancellable = NULL;
-
- priv->determine_view_file = nautilus_file_get (priv->pending_location);
-
- error = NULL;
- if (!g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error)) {
- priv->mount_error = error;
- got_file_info_for_view_selection_callback (priv->determine_view_file, self);
- priv->mount_error = NULL;
- g_error_free (error);
- } else {
- nautilus_file_invalidate_all_attributes (priv->determine_view_file);
- nautilus_file_call_when_ready (priv->determine_view_file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT,
- got_file_info_for_view_selection_callback,
- self);
- }
-
- g_object_unref (cancellable);
+ NautilusWindowSlotPrivate *priv;
+ MountNotMountedData *data;
+ NautilusWindowSlot *self;
+ GError *error;
+ GCancellable *cancellable;
+
+ data = user_data;
+ self = data->slot;
+ priv = nautilus_window_slot_get_instance_private (self);
+ cancellable = data->cancellable;
+ g_free (data);
+
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ /* Cancelled, don't call back */
+ g_object_unref (cancellable);
+ return;
+ }
+
+ priv->mount_cancellable = NULL;
+
+ priv->determine_view_file = nautilus_file_get (priv->pending_location);
+
+ error = NULL;
+ if (!g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &error))
+ {
+ priv->mount_error = error;
+ got_file_info_for_view_selection_callback (priv->determine_view_file, self);
+ priv->mount_error = NULL;
+ g_error_free (error);
+ }
+ else
+ {
+ nautilus_file_invalidate_all_attributes (priv->determine_view_file);
+ nautilus_file_call_when_ready (priv->determine_view_file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT,
+ got_file_info_for_view_selection_callback,
+ self);
+ }
+
+ g_object_unref (cancellable);
}
static void
@@ -1209,65 +1338,96 @@ nautilus_window_slot_display_view_selection_failure (NautilusWindow *window,
GFile *location,
GError *error)
{
- char *error_message;
- char *detail_message;
- char *scheme_string;
-
- /* Some sort of failure occurred. How 'bout we tell the user? */
-
- error_message = g_strdup (_("Oops! Something went wrong."));
- detail_message = NULL;
- if (error == NULL) {
- if (nautilus_file_is_directory (file)) {
- detail_message = g_strdup (_("Unable to display the contents of this folder."));
- } else {
- detail_message = g_strdup (_("This location doesn't appear to be a folder."));
- }
- } else if (error->domain == G_IO_ERROR) {
- switch (error->code) {
- case G_IO_ERROR_NOT_FOUND:
- detail_message = g_strdup (_("Unable to find the requested file. Please check the spelling and try again."));
- break;
- case G_IO_ERROR_NOT_SUPPORTED:
- scheme_string = g_file_get_uri_scheme (location);
- if (scheme_string != NULL) {
- detail_message = g_strdup_printf (_("“%s” locations are not supported."),
- scheme_string);
- } else {
- detail_message = g_strdup (_("Unable to handle this kind of location."));
- }
- g_free (scheme_string);
- break;
- case G_IO_ERROR_NOT_MOUNTED:
- detail_message = g_strdup (_("Unable to access the requested location."));
- break;
- case G_IO_ERROR_PERMISSION_DENIED:
- detail_message = g_strdup (_("Don't have permission to access the requested location."));
- break;
- case G_IO_ERROR_HOST_NOT_FOUND:
- /* This case can be hit for user-typed strings like "foo" due to
- * the code that guesses web addresses when there's no initial "/".
- * But this case is also hit for legitimate web addresses when
- * the proxy is set up wrong.
- */
- detail_message = g_strdup (_("Unable to find the requested location. Please check the spelling or the network settings."));
- break;
- case G_IO_ERROR_CANCELLED:
- case G_IO_ERROR_FAILED_HANDLED:
- goto done;
- default:
- break;
- }
- }
-
- if (detail_message == NULL) {
- detail_message = g_strdup_printf (_("Unhandled error message: %s"), error->message);
- }
-
- eel_show_error_dialog (error_message, detail_message, GTK_WINDOW (window));
- done:
- g_free (error_message);
- g_free (detail_message);
+ char *error_message;
+ char *detail_message;
+ char *scheme_string;
+
+ /* Some sort of failure occurred. How 'bout we tell the user? */
+
+ error_message = g_strdup (_("Oops! Something went wrong."));
+ detail_message = NULL;
+ if (error == NULL)
+ {
+ if (nautilus_file_is_directory (file))
+ {
+ detail_message = g_strdup (_("Unable to display the contents of this folder."));
+ }
+ else
+ {
+ detail_message = g_strdup (_("This location doesn't appear to be a folder."));
+ }
+ }
+ else if (error->domain == G_IO_ERROR)
+ {
+ switch (error->code)
+ {
+ case G_IO_ERROR_NOT_FOUND:
+ {
+ detail_message = g_strdup (_("Unable to find the requested file. Please check the spelling and try again."));
+ }
+ break;
+
+ case G_IO_ERROR_NOT_SUPPORTED:
+ {
+ scheme_string = g_file_get_uri_scheme (location);
+ if (scheme_string != NULL)
+ {
+ detail_message = g_strdup_printf (_("“%s” locations are not supported."),
+ scheme_string);
+ }
+ else
+ {
+ detail_message = g_strdup (_("Unable to handle this kind of location."));
+ }
+ g_free (scheme_string);
+ }
+ break;
+
+ case G_IO_ERROR_NOT_MOUNTED:
+ {
+ detail_message = g_strdup (_("Unable to access the requested location."));
+ }
+ break;
+
+ case G_IO_ERROR_PERMISSION_DENIED:
+ {
+ detail_message = g_strdup (_("Don't have permission to access the requested location."));
+ }
+ break;
+
+ case G_IO_ERROR_HOST_NOT_FOUND:
+ {
+ /* This case can be hit for user-typed strings like "foo" due to
+ * the code that guesses web addresses when there's no initial "/".
+ * But this case is also hit for legitimate web addresses when
+ * the proxy is set up wrong.
+ */
+ detail_message = g_strdup (_("Unable to find the requested location. Please check the spelling or the network settings."));
+ }
+ break;
+
+ case G_IO_ERROR_CANCELLED:
+ case G_IO_ERROR_FAILED_HANDLED:
+ {
+ goto done;
+ }
+
+ default:
+ {
+ }
+ break;
+ }
+ }
+
+ if (detail_message == NULL)
+ {
+ detail_message = g_strdup_printf (_("Unhandled error message: %s"), error->message);
+ }
+
+ eel_show_error_dialog (error_message, detail_message, GTK_WINDOW (window));
+done:
+ g_free (error_message);
+ g_free (detail_message);
}
/* FIXME: This works in the folowwing way. begin_location_change tries to get the
@@ -1291,199 +1451,231 @@ static gboolean
handle_mount_if_needed (NautilusWindowSlot *self,
NautilusFile *file)
{
- NautilusWindowSlotPrivate *priv;
- NautilusWindow *window;
- GMountOperation *mount_op;
- MountNotMountedData *data;
- GFile *location;
- GError *error = NULL;
- gboolean needs_mount_handling = FALSE;
-
- priv = nautilus_window_slot_get_instance_private (self);
- window = nautilus_window_slot_get_window (self);
- if (priv->mount_error) {
- error = g_error_copy (priv->mount_error);
- } else if (nautilus_file_get_file_info_error (file) != NULL) {
- error = g_error_copy (nautilus_file_get_file_info_error (file));
- }
-
- if (error && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_MOUNTED &&
- !priv->tried_mount) {
- priv->tried_mount = TRUE;
-
- mount_op = gtk_mount_operation_new (GTK_WINDOW (window));
- g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
- location = nautilus_file_get_location (file);
- data = g_new0 (MountNotMountedData, 1);
- data->cancellable = g_cancellable_new ();
- data->slot = self;
- priv->mount_cancellable = data->cancellable;
- g_file_mount_enclosing_volume (location, 0, mount_op, priv->mount_cancellable,
- mount_not_mounted_callback, data);
- g_object_unref (location);
- g_object_unref (mount_op);
-
- needs_mount_handling = TRUE;
- }
-
- g_clear_error (&error);
-
- return needs_mount_handling;
+ NautilusWindowSlotPrivate *priv;
+ NautilusWindow *window;
+ GMountOperation *mount_op;
+ MountNotMountedData *data;
+ GFile *location;
+ GError *error = NULL;
+ gboolean needs_mount_handling = FALSE;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ window = nautilus_window_slot_get_window (self);
+ if (priv->mount_error)
+ {
+ error = g_error_copy (priv->mount_error);
+ }
+ else if (nautilus_file_get_file_info_error (file) != NULL)
+ {
+ error = g_error_copy (nautilus_file_get_file_info_error (file));
+ }
+
+ if (error && error->domain == G_IO_ERROR && error->code == G_IO_ERROR_NOT_MOUNTED &&
+ !priv->tried_mount)
+ {
+ priv->tried_mount = TRUE;
+
+ mount_op = gtk_mount_operation_new (GTK_WINDOW (window));
+ g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
+ location = nautilus_file_get_location (file);
+ data = g_new0 (MountNotMountedData, 1);
+ data->cancellable = g_cancellable_new ();
+ data->slot = self;
+ priv->mount_cancellable = data->cancellable;
+ g_file_mount_enclosing_volume (location, 0, mount_op, priv->mount_cancellable,
+ mount_not_mounted_callback, data);
+ g_object_unref (location);
+ g_object_unref (mount_op);
+
+ needs_mount_handling = TRUE;
+ }
+
+ g_clear_error (&error);
+
+ return needs_mount_handling;
}
static gboolean
handle_regular_file_if_needed (NautilusWindowSlot *self,
NautilusFile *file)
{
- NautilusFile *parent_file;
- gboolean needs_regular_file_handling = FALSE;
- NautilusWindowSlotPrivate *priv;
-
- priv = nautilus_window_slot_get_instance_private (self);
- parent_file = nautilus_file_get_parent (file);
- if ((parent_file != NULL) &&
- nautilus_file_get_file_type (file) == G_FILE_TYPE_REGULAR) {
- if (priv->pending_selection != NULL) {
- nautilus_file_list_free (priv->pending_selection);
- }
+ NautilusFile *parent_file;
+ gboolean needs_regular_file_handling = FALSE;
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ parent_file = nautilus_file_get_parent (file);
+ if ((parent_file != NULL) &&
+ nautilus_file_get_file_type (file) == G_FILE_TYPE_REGULAR)
+ {
+ if (priv->pending_selection != NULL)
+ {
+ nautilus_file_list_free (priv->pending_selection);
+ }
- g_clear_object (&priv->pending_location);
- g_free (priv->pending_scroll_to);
+ g_clear_object (&priv->pending_location);
+ g_free (priv->pending_scroll_to);
- priv->pending_location = nautilus_file_get_parent_location (file);
- priv->pending_selection = g_list_prepend (NULL, nautilus_file_ref (file));
- priv->determine_view_file = nautilus_file_ref (parent_file);
- priv->pending_scroll_to = nautilus_file_get_uri (file);
+ priv->pending_location = nautilus_file_get_parent_location (file);
+ priv->pending_selection = g_list_prepend (NULL, nautilus_file_ref (file));
+ priv->determine_view_file = nautilus_file_ref (parent_file);
+ priv->pending_scroll_to = nautilus_file_get_uri (file);
- nautilus_file_invalidate_all_attributes (priv->determine_view_file);
- nautilus_file_call_when_ready (priv->determine_view_file,
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT,
- got_file_info_for_view_selection_callback,
- self);
+ nautilus_file_invalidate_all_attributes (priv->determine_view_file);
+ nautilus_file_call_when_ready (priv->determine_view_file,
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT,
+ got_file_info_for_view_selection_callback,
+ self);
- needs_regular_file_handling = TRUE;
- }
+ needs_regular_file_handling = TRUE;
+ }
- nautilus_file_unref (parent_file);
+ nautilus_file_unref (parent_file);
- return needs_regular_file_handling;
+ return needs_regular_file_handling;
}
static void
got_file_info_for_view_selection_callback (NautilusFile *file,
gpointer callback_data)
{
- NautilusWindowSlotPrivate *priv;
- GError *error = NULL;
- NautilusWindow *window;
- NautilusWindowSlot *self;
- NautilusFile *viewed_file;
- NautilusView *view;
- GFile *location;
-
- NautilusApplication *app;
-
- self = callback_data;
- priv = nautilus_window_slot_get_instance_private (self);
- window = nautilus_window_slot_get_window (self);
-
- g_assert (priv->determine_view_file == file);
- priv->determine_view_file = NULL;
-
- nautilus_profile_start (NULL);
-
- if (handle_mount_if_needed (self, file))
- goto done;
-
- if (handle_regular_file_if_needed (self, file))
- goto done;
-
- if (priv->mount_error) {
- error = g_error_copy (priv->mount_error);
- } else if (nautilus_file_get_file_info_error (file) != NULL) {
- error = g_error_copy (nautilus_file_get_file_info_error (file));
+ NautilusWindowSlotPrivate *priv;
+ GError *error = NULL;
+ NautilusWindow *window;
+ NautilusWindowSlot *self;
+ NautilusFile *viewed_file;
+ NautilusView *view;
+ GFile *location;
+
+ NautilusApplication *app;
+
+ self = callback_data;
+ priv = nautilus_window_slot_get_instance_private (self);
+ window = nautilus_window_slot_get_window (self);
+
+ g_assert (priv->determine_view_file == file);
+ priv->determine_view_file = NULL;
+
+ nautilus_profile_start (NULL);
+
+ if (handle_mount_if_needed (self, file))
+ {
+ goto done;
+ }
+
+ if (handle_regular_file_if_needed (self, file))
+ {
+ goto done;
+ }
+
+ if (priv->mount_error)
+ {
+ error = g_error_copy (priv->mount_error);
+ }
+ else if (nautilus_file_get_file_info_error (file) != NULL)
+ {
+ error = g_error_copy (nautilus_file_get_file_info_error (file));
+ }
+
+ location = priv->pending_location;
+
+ /* desktop and other-locations GFile operations report G_IO_ERROR_NOT_SUPPORTED,
+ * but it's not an actual error for Nautilus */
+ if (!error || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
+ {
+ view = nautilus_window_slot_get_view_for_location (self, location);
+ setup_view (self, view);
+ }
+ else
+ {
+ if (error == NULL)
+ {
+ error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
+ _("Unable to load location"));
+ }
+ nautilus_window_slot_display_view_selection_failure (window,
+ file,
+ location,
+ error);
+
+ if (!gtk_widget_get_visible (GTK_WIDGET (window)))
+ {
+ /* Destroy never-had-a-chance-to-be-seen window. This case
+ * happens when a new window cannot display its initial URI.
+ */
+ /* if this is the only window, we don't want to quit, so we redirect it to home */
+
+ app = NAUTILUS_APPLICATION (g_application_get_default ());
+
+ if (g_list_length (nautilus_application_get_windows (app)) == 1)
+ {
+ /* the user could have typed in a home directory that doesn't exist,
+ * in which case going home would cause an infinite loop, so we
+ * better test for that */
+
+ if (!nautilus_is_root_directory (location))
+ {
+ if (!nautilus_is_home_directory (location))
+ {
+ nautilus_window_slot_go_home (self, FALSE);
+ }
+ else
+ {
+ GFile *root;
+
+ root = g_file_new_for_path ("/");
+ /* the last fallback is to go to a known place that can't be deleted! */
+ nautilus_window_slot_open_location_full (self, location, 0, NULL);
+ g_object_unref (root);
+ }
+ }
+ else
+ {
+ gtk_widget_destroy (GTK_WIDGET (window));
+ }
+ }
+ else
+ {
+ /* Since this is a window, destroying it will also unref it. */
+ gtk_widget_destroy (GTK_WIDGET (window));
+ }
+ }
+ else
+ {
+ GFile *slot_location;
+
+ /* Clean up state of already-showing window */
+ end_location_change (self);
+ slot_location = nautilus_window_slot_get_location (self);
+
+ /* We're missing a previous location (if opened location
+ * in a new tab) so close it and return */
+ if (slot_location == NULL)
+ {
+ nautilus_window_slot_close (window, self);
+ }
+ else
+ {
+ /* We disconnected this, so we need to re-connect it */
+ viewed_file = nautilus_file_get (slot_location);
+ nautilus_window_slot_set_viewed_file (self, viewed_file);
+ nautilus_file_unref (viewed_file);
+
+ /* Leave the location bar showing the bad location that the user
+ * typed (or maybe achieved by dragging or something). Many times
+ * the mistake will just be an easily-correctable typo. The user
+ * can choose "Refresh" to get the original URI back in the location bar.
+ */
+ }
}
+ }
+
+done:
+ g_clear_error (&error);
- location = priv->pending_location;
-
- /* desktop and other-locations GFile operations report G_IO_ERROR_NOT_SUPPORTED,
- * but it's not an actual error for Nautilus */
- if (!error || g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) {
- view = nautilus_window_slot_get_view_for_location (self, location);
- setup_view (self, view);
- } else {
- if (error == NULL) {
- error = g_error_new (G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
- _("Unable to load location"));
- }
- nautilus_window_slot_display_view_selection_failure (window,
- file,
- location,
- error);
-
- if (!gtk_widget_get_visible (GTK_WIDGET (window))) {
- /* Destroy never-had-a-chance-to-be-seen window. This case
- * happens when a new window cannot display its initial URI.
- */
- /* if this is the only window, we don't want to quit, so we redirect it to home */
-
- app = NAUTILUS_APPLICATION (g_application_get_default ());
-
- if (g_list_length (nautilus_application_get_windows (app)) == 1) {
- /* the user could have typed in a home directory that doesn't exist,
- in which case going home would cause an infinite loop, so we
- better test for that */
-
- if (!nautilus_is_root_directory (location)) {
- if (!nautilus_is_home_directory (location)) {
- nautilus_window_slot_go_home (self, FALSE);
- } else {
- GFile *root;
-
- root = g_file_new_for_path ("/");
- /* the last fallback is to go to a known place that can't be deleted! */
- nautilus_window_slot_open_location_full (self, location, 0, NULL);
- g_object_unref (root);
- }
- } else {
- gtk_widget_destroy (GTK_WIDGET (window));
- }
- } else {
- /* Since this is a window, destroying it will also unref it. */
- gtk_widget_destroy (GTK_WIDGET (window));
- }
- } else {
- GFile *slot_location;
-
- /* Clean up state of already-showing window */
- end_location_change (self);
- slot_location = nautilus_window_slot_get_location (self);
-
- /* We're missing a previous location (if opened location
- * in a new tab) so close it and return */
- if (slot_location == NULL) {
- nautilus_window_slot_close (window, self);
- } else {
- /* We disconnected this, so we need to re-connect it */
- viewed_file = nautilus_file_get (slot_location);
- nautilus_window_slot_set_viewed_file (self, viewed_file);
- nautilus_file_unref (viewed_file);
-
- /* Leave the location bar showing the bad location that the user
- * typed (or maybe achieved by dragging or something). Many times
- * the mistake will just be an easily-correctable typo. The user
- * can choose "Refresh" to get the original URI back in the location bar.
- */
- }
- }
- }
-
- done:
- g_clear_error (&error);
-
- nautilus_file_unref (file);
- nautilus_profile_end (NULL);
+ nautilus_file_unref (file);
+ nautilus_profile_end (NULL);
}
/* Load a view into the window, either reusing the old one or creating
@@ -1497,55 +1689,60 @@ static gboolean
setup_view (NautilusWindowSlot *self,
NautilusView *view)
{
- gboolean ret = TRUE;
- GFile *old_location;
- NautilusWindowSlotPrivate *priv;
-
- nautilus_profile_start (NULL);
+ gboolean ret = TRUE;
+ GFile *old_location;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- nautilus_window_slot_disconnect_content_view (self);
+ nautilus_profile_start (NULL);
- priv->new_content_view = view;
+ priv = nautilus_window_slot_get_instance_private (self);
+ nautilus_window_slot_disconnect_content_view (self);
- nautilus_window_slot_connect_new_content_view (self);
+ priv->new_content_view = view;
- /* Forward search selection and state before loading the new model */
- old_location = priv->content_view ? nautilus_view_get_location (priv->content_view) : NULL;
+ nautilus_window_slot_connect_new_content_view (self);
- /* Actually load the pending location and selection: */
- if (priv->pending_location != NULL) {
- load_new_location (self,
- priv->pending_location,
- priv->pending_selection,
- FALSE,
- TRUE);
+ /* Forward search selection and state before loading the new model */
+ old_location = priv->content_view ? nautilus_view_get_location (priv->content_view) : NULL;
- nautilus_file_list_free (priv->pending_selection);
- priv->pending_selection = NULL;
- } else if (old_location != NULL) {
- GList *selection;
+ /* Actually load the pending location and selection: */
+ if (priv->pending_location != NULL)
+ {
+ load_new_location (self,
+ priv->pending_location,
+ priv->pending_selection,
+ FALSE,
+ TRUE);
- selection = nautilus_view_get_selection (priv->content_view);
+ nautilus_file_list_free (priv->pending_selection);
+ priv->pending_selection = NULL;
+ }
+ else if (old_location != NULL)
+ {
+ GList *selection;
- load_new_location (self,
- old_location,
- selection,
- FALSE,
- TRUE);
- nautilus_file_list_free (selection);
- } else {
- ret = FALSE;
- goto out;
- }
+ selection = nautilus_view_get_selection (priv->content_view);
- change_view (self);
- gtk_widget_show (GTK_WIDGET (priv->window));
+ load_new_location (self,
+ old_location,
+ selection,
+ FALSE,
+ TRUE);
+ nautilus_file_list_free (selection);
+ }
+ else
+ {
+ ret = FALSE;
+ goto out;
+ }
+
+ change_view (self);
+ gtk_widget_show (GTK_WIDGET (priv->window));
out:
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
- return ret;
+ return ret;
}
static void
@@ -1555,317 +1752,343 @@ load_new_location (NautilusWindowSlot *self,
gboolean tell_current_content_view,
gboolean tell_new_content_view)
{
- NautilusView *view;
- NautilusWindowSlotPrivate *priv;
+ NautilusView *view;
+ NautilusWindowSlotPrivate *priv;
- g_assert (self != NULL);
- g_assert (location != NULL);
+ g_assert (self != NULL);
+ g_assert (location != NULL);
- view = NULL;
- priv = nautilus_window_slot_get_instance_private (self);
+ view = NULL;
+ priv = nautilus_window_slot_get_instance_private (self);
- nautilus_profile_start (NULL);
- /* Note, these may recurse into report_load_underway */
- if (priv->content_view != NULL && tell_current_content_view) {
- view = priv->content_view;
- nautilus_view_set_location (priv->content_view, location);
- }
+ nautilus_profile_start (NULL);
+ /* Note, these may recurse into report_load_underway */
+ if (priv->content_view != NULL && tell_current_content_view)
+ {
+ view = priv->content_view;
+ nautilus_view_set_location (priv->content_view, location);
+ }
- if (priv->new_content_view != NULL && tell_new_content_view &&
- (!tell_current_content_view ||
- priv->new_content_view != priv->content_view) ) {
- view = priv->new_content_view;
- nautilus_view_set_location (priv->new_content_view, location);
- }
- if (view) {
- /* new_content_view might have changed here if
- report_load_underway was called from load_location */
- nautilus_view_set_selection (view, selection);
- }
+ if (priv->new_content_view != NULL && tell_new_content_view &&
+ (!tell_current_content_view ||
+ priv->new_content_view != priv->content_view))
+ {
+ view = priv->new_content_view;
+ nautilus_view_set_location (priv->new_content_view, location);
+ }
+ if (view)
+ {
+ /* new_content_view might have changed here if
+ * report_load_underway was called from load_location */
+ nautilus_view_set_selection (view, selection);
+ }
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static void
end_location_change (NautilusWindowSlot *self)
{
- char *uri;
- NautilusWindowSlotPrivate *priv;
+ char *uri;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- uri = nautilus_window_slot_get_location_uri (self);
- if (uri) {
- DEBUG ("Finished loading window for uri %s", uri);
- g_free (uri);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ uri = nautilus_window_slot_get_location_uri (self);
+ if (uri)
+ {
+ DEBUG ("Finished loading window for uri %s", uri);
+ g_free (uri);
+ }
- nautilus_window_slot_set_allow_stop (self, FALSE);
+ nautilus_window_slot_set_allow_stop (self, FALSE);
- /* Now we can free details->pending_scroll_to, since the load_complete
- * callback already has been emitted.
- */
- g_free (priv->pending_scroll_to);
- priv->pending_scroll_to = NULL;
+ /* Now we can free details->pending_scroll_to, since the load_complete
+ * callback already has been emitted.
+ */
+ g_free (priv->pending_scroll_to);
+ priv->pending_scroll_to = NULL;
- free_location_change (self);
+ free_location_change (self);
}
static void
free_location_change (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- g_clear_object (&priv->pending_location);
- nautilus_file_list_free (priv->pending_selection);
- priv->pending_selection = NULL;
+ priv = nautilus_window_slot_get_instance_private (self);
+ g_clear_object (&priv->pending_location);
+ nautilus_file_list_free (priv->pending_selection);
+ priv->pending_selection = NULL;
- /* Don't free details->pending_scroll_to, since thats needed until
- * the load_complete callback.
- */
+ /* Don't free details->pending_scroll_to, since thats needed until
+ * the load_complete callback.
+ */
- if (priv->mount_cancellable != NULL) {
- g_cancellable_cancel (priv->mount_cancellable);
- priv->mount_cancellable = NULL;
- }
+ if (priv->mount_cancellable != NULL)
+ {
+ g_cancellable_cancel (priv->mount_cancellable);
+ priv->mount_cancellable = NULL;
+ }
- if (priv->determine_view_file != NULL) {
- nautilus_file_cancel_call_when_ready
- (priv->determine_view_file,
- got_file_info_for_view_selection_callback, self);
- priv->determine_view_file = NULL;
- }
+ if (priv->determine_view_file != NULL)
+ {
+ nautilus_file_cancel_call_when_ready
+ (priv->determine_view_file,
+ got_file_info_for_view_selection_callback, self);
+ priv->determine_view_file = NULL;
+ }
}
static void
nautilus_window_slot_set_content_view (NautilusWindowSlot *self,
- guint id)
+ guint id)
{
- NautilusFilesView *view;
- GList *selection;
- char *uri;
- NautilusWindowSlotPrivate *priv;
+ NautilusFilesView *view;
+ GList *selection;
+ char *uri;
+ NautilusWindowSlotPrivate *priv;
- g_assert (self != NULL);
+ g_assert (self != NULL);
- priv = nautilus_window_slot_get_instance_private (self);
- uri = nautilus_window_slot_get_location_uri (self);
- DEBUG ("Change view of window %s to %d", uri, id);
- g_free (uri);
+ priv = nautilus_window_slot_get_instance_private (self);
+ uri = nautilus_window_slot_get_location_uri (self);
+ DEBUG ("Change view of window %s to %d", uri, id);
+ g_free (uri);
- if (nautilus_window_slot_content_view_matches (self, id)) {
- return;
- }
+ if (nautilus_window_slot_content_view_matches (self, id))
+ {
+ return;
+ }
- selection = nautilus_view_get_selection (priv->content_view);
- view = nautilus_files_view_new (id, self);
+ selection = nautilus_view_get_selection (priv->content_view);
+ view = nautilus_files_view_new (id, self);
- nautilus_window_slot_stop_loading (self);
+ nautilus_window_slot_stop_loading (self);
- nautilus_window_slot_set_allow_stop (self, TRUE);
+ nautilus_window_slot_set_allow_stop (self, TRUE);
- if (g_list_length (selection) == 0 && NAUTILUS_IS_FILES_VIEW (priv->content_view)) {
- /* If there is no selection, queue a scroll to the same icon that
- * is currently visible */
- priv->pending_scroll_to = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW (priv->content_view));
- }
+ if (g_list_length (selection) == 0 && NAUTILUS_IS_FILES_VIEW (priv->content_view))
+ {
+ /* If there is no selection, queue a scroll to the same icon that
+ * is currently visible */
+ priv->pending_scroll_to = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW (priv->content_view));
+ }
- priv->location_change_type = NAUTILUS_LOCATION_CHANGE_RELOAD;
+ priv->location_change_type = NAUTILUS_LOCATION_CHANGE_RELOAD;
- if (!setup_view (self, NAUTILUS_VIEW (view))) {
- /* Just load the homedir. */
- nautilus_window_slot_go_home (self, FALSE);
- }
+ if (!setup_view (self, NAUTILUS_VIEW (view)))
+ {
+ /* Just load the homedir. */
+ nautilus_window_slot_go_home (self, FALSE);
+ }
}
void
-nautilus_window_back_or_forward (NautilusWindow *window,
- gboolean back,
- guint distance,
- NautilusWindowOpenFlags flags)
-{
- NautilusWindowSlot *self;
- GList *list;
- GFile *location;
- guint len;
- NautilusBookmark *bookmark;
- GFile *old_location;
- NautilusWindowSlotPrivate *priv;
-
- self = nautilus_window_get_active_slot (window);
- priv = nautilus_window_slot_get_instance_private (self);
- list = back ? priv->back_list : priv->forward_list;
-
- len = (guint) g_list_length (list);
-
- /* If we can't move in the direction at all, just return. */
- if (len == 0)
- return;
-
- /* If the distance to move is off the end of the list, go to the end
- of the list. */
- if (distance >= len)
- distance = len - 1;
-
- bookmark = g_list_nth_data (list, distance);
- location = nautilus_bookmark_get_location (bookmark);
-
- if (flags != 0) {
- nautilus_window_slot_open_location_full (self, location, flags, NULL);
- } else {
- char *scroll_pos;
+nautilus_window_back_or_forward (NautilusWindow *window,
+ gboolean back,
+ guint distance,
+ NautilusWindowOpenFlags flags)
+{
+ NautilusWindowSlot *self;
+ GList *list;
+ GFile *location;
+ guint len;
+ NautilusBookmark *bookmark;
+ GFile *old_location;
+ NautilusWindowSlotPrivate *priv;
+
+ self = nautilus_window_get_active_slot (window);
+ priv = nautilus_window_slot_get_instance_private (self);
+ list = back ? priv->back_list : priv->forward_list;
+
+ len = (guint) g_list_length (list);
+
+ /* If we can't move in the direction at all, just return. */
+ if (len == 0)
+ {
+ return;
+ }
+
+ /* If the distance to move is off the end of the list, go to the end
+ * of the list. */
+ if (distance >= len)
+ {
+ distance = len - 1;
+ }
+
+ bookmark = g_list_nth_data (list, distance);
+ location = nautilus_bookmark_get_location (bookmark);
+
+ if (flags != 0)
+ {
+ nautilus_window_slot_open_location_full (self, location, flags, NULL);
+ }
+ else
+ {
+ char *scroll_pos;
- old_location = nautilus_window_slot_get_location (self);
- scroll_pos = nautilus_bookmark_get_scroll_pos (bookmark);
- begin_location_change
- (self,
- location, old_location, NULL,
- back ? NAUTILUS_LOCATION_CHANGE_BACK : NAUTILUS_LOCATION_CHANGE_FORWARD,
- distance,
- scroll_pos);
+ old_location = nautilus_window_slot_get_location (self);
+ scroll_pos = nautilus_bookmark_get_scroll_pos (bookmark);
+ begin_location_change
+ (self,
+ location, old_location, NULL,
+ back ? NAUTILUS_LOCATION_CHANGE_BACK : NAUTILUS_LOCATION_CHANGE_FORWARD,
+ distance,
+ scroll_pos);
- g_free (scroll_pos);
- }
+ g_free (scroll_pos);
+ }
- g_object_unref (location);
+ g_object_unref (location);
}
/* reload the contents of the window */
static void
nautilus_window_slot_force_reload (NautilusWindowSlot *self)
{
- GFile *location;
- char *current_pos;
- GList *selection;
- NautilusWindowSlotPrivate *priv;
-
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
-
- priv = nautilus_window_slot_get_instance_private (self);
- location = nautilus_window_slot_get_location (self);
- if (location == NULL) {
- return;
- }
-
- /* peek_slot_field (window, location) can be free'd during the processing
- * of begin_location_change, so make a copy
- */
- g_object_ref (location);
- current_pos = NULL;
- selection = NULL;
- if (priv->new_content_view) {
- selection = nautilus_view_get_selection (priv->content_view);
-
- if (NAUTILUS_IS_FILES_VIEW (priv->new_content_view)) {
- current_pos = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW (priv->content_view));
- }
- }
- begin_location_change
- (self, location, location, selection,
- NAUTILUS_LOCATION_CHANGE_RELOAD, 0, current_pos);
- g_free (current_pos);
- g_object_unref (location);
- nautilus_file_list_free (selection);
+ GFile *location;
+ char *current_pos;
+ GList *selection;
+ NautilusWindowSlotPrivate *priv;
+
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ location = nautilus_window_slot_get_location (self);
+ if (location == NULL)
+ {
+ return;
+ }
+
+ /* peek_slot_field (window, location) can be free'd during the processing
+ * of begin_location_change, so make a copy
+ */
+ g_object_ref (location);
+ current_pos = NULL;
+ selection = NULL;
+ if (priv->new_content_view)
+ {
+ selection = nautilus_view_get_selection (priv->content_view);
+
+ if (NAUTILUS_IS_FILES_VIEW (priv->new_content_view))
+ {
+ current_pos = nautilus_files_view_get_first_visible_file (NAUTILUS_FILES_VIEW (priv->content_view));
+ }
+ }
+ begin_location_change
+ (self, location, location, selection,
+ NAUTILUS_LOCATION_CHANGE_RELOAD, 0, current_pos);
+ g_free (current_pos);
+ g_object_unref (location);
+ nautilus_file_list_free (selection);
}
void
nautilus_window_slot_queue_reload (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- if (nautilus_window_slot_get_location (self) == NULL) {
- return;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (nautilus_window_slot_get_location (self) == NULL)
+ {
+ return;
+ }
- if (priv->pending_location != NULL
- || priv->content_view == NULL
- || nautilus_view_is_loading (priv->content_view)) {
- /* there is a reload in flight */
- priv->needs_reload = TRUE;
- return;
- }
+ if (priv->pending_location != NULL
+ || priv->content_view == NULL
+ || nautilus_view_is_loading (priv->content_view))
+ {
+ /* there is a reload in flight */
+ priv->needs_reload = TRUE;
+ return;
+ }
- nautilus_window_slot_force_reload (self);
+ nautilus_window_slot_force_reload (self);
}
static void
nautilus_window_slot_clear_forward_list (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- g_list_free_full (priv->forward_list, g_object_unref);
- priv->forward_list = NULL;
+ priv = nautilus_window_slot_get_instance_private (self);
+ g_list_free_full (priv->forward_list, g_object_unref);
+ priv->forward_list = NULL;
}
static void
nautilus_window_slot_clear_back_list (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- g_list_free_full (priv->back_list, g_object_unref);
- priv->back_list = NULL;
+ priv = nautilus_window_slot_get_instance_private (self);
+ g_list_free_full (priv->back_list, g_object_unref);
+ priv->back_list = NULL;
}
static void
nautilus_window_slot_update_bookmark (NautilusWindowSlot *self,
NautilusFile *file)
{
- gboolean recreate;
- GFile *new_location;
- NautilusWindowSlotPrivate *priv;
+ gboolean recreate;
+ GFile *new_location;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- new_location = nautilus_file_get_location (file);
+ priv = nautilus_window_slot_get_instance_private (self);
+ new_location = nautilus_file_get_location (file);
- if (priv->current_location_bookmark == NULL) {
- recreate = TRUE;
- } else {
- GFile *bookmark_location;
- bookmark_location = nautilus_bookmark_get_location (priv->current_location_bookmark);
- recreate = !g_file_equal (bookmark_location, new_location);
- g_object_unref (bookmark_location);
- }
+ if (priv->current_location_bookmark == NULL)
+ {
+ recreate = TRUE;
+ }
+ else
+ {
+ GFile *bookmark_location;
+ bookmark_location = nautilus_bookmark_get_location (priv->current_location_bookmark);
+ recreate = !g_file_equal (bookmark_location, new_location);
+ g_object_unref (bookmark_location);
+ }
- if (recreate) {
- char *display_name = NULL;
+ if (recreate)
+ {
+ char *display_name = NULL;
- /* We've changed locations, must recreate bookmark for current location. */
- g_clear_object (&priv->last_location_bookmark);
- priv->last_location_bookmark = priv->current_location_bookmark;
+ /* We've changed locations, must recreate bookmark for current location. */
+ g_clear_object (&priv->last_location_bookmark);
+ priv->last_location_bookmark = priv->current_location_bookmark;
- display_name = nautilus_file_get_display_name (file);
- priv->current_location_bookmark = nautilus_bookmark_new (new_location, display_name);
- g_free (display_name);
- }
+ display_name = nautilus_file_get_display_name (file);
+ priv->current_location_bookmark = nautilus_bookmark_new (new_location, display_name);
+ g_free (display_name);
+ }
- g_object_unref (new_location);
+ g_object_unref (new_location);
}
static void
check_bookmark_location_matches (NautilusBookmark *bookmark,
GFile *location)
{
- GFile *bookmark_location;
- char *bookmark_uri, *uri;
+ GFile *bookmark_location;
+ char *bookmark_uri, *uri;
- bookmark_location = nautilus_bookmark_get_location (bookmark);
- if (!g_file_equal (location, bookmark_location)) {
- bookmark_uri = g_file_get_uri (bookmark_location);
- uri = g_file_get_uri (location);
- g_warning ("bookmark uri is %s, but expected %s", bookmark_uri, uri);
- g_free (uri);
- g_free (bookmark_uri);
- }
- g_object_unref (bookmark_location);
+ bookmark_location = nautilus_bookmark_get_location (bookmark);
+ if (!g_file_equal (location, bookmark_location))
+ {
+ bookmark_uri = g_file_get_uri (bookmark_location);
+ uri = g_file_get_uri (location);
+ g_warning ("bookmark uri is %s, but expected %s", bookmark_uri, uri);
+ g_free (uri);
+ g_free (bookmark_uri);
+ }
+ g_object_unref (bookmark_location);
}
/* Debugging function used to verify that the last_location_bookmark
@@ -1875,86 +2098,89 @@ check_bookmark_location_matches (NautilusBookmark *bookmark,
static void
check_last_bookmark_location_matches_slot (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- check_bookmark_location_matches (priv->last_location_bookmark,
- nautilus_window_slot_get_location (self));
+ priv = nautilus_window_slot_get_instance_private (self);
+ check_bookmark_location_matches (priv->last_location_bookmark,
+ nautilus_window_slot_get_location (self));
}
static void
handle_go_direction (NautilusWindowSlot *self,
- GFile *location,
- gboolean forward)
-{
- GList **list_ptr, **other_list_ptr;
- GList *list, *other_list, *link;
- NautilusBookmark *bookmark;
- gint i;
- NautilusWindowSlotPrivate *priv;
-
- priv = nautilus_window_slot_get_instance_private (self);
- list_ptr = (forward) ? (&priv->forward_list) : (&priv->back_list);
- other_list_ptr = (forward) ? (&priv->back_list) : (&priv->forward_list);
- list = *list_ptr;
- other_list = *other_list_ptr;
-
- /* Move items from the list to the other list. */
- g_assert (g_list_length (list) > priv->location_change_distance);
- check_bookmark_location_matches (g_list_nth_data (list, priv->location_change_distance),
- location);
- g_assert (nautilus_window_slot_get_location (self) != NULL);
-
- /* Move current location to list */
- check_last_bookmark_location_matches_slot (self);
-
- /* Use the first bookmark in the history list rather than creating a new one. */
- other_list = g_list_prepend (other_list, priv->last_location_bookmark);
- g_object_ref (other_list->data);
-
- /* Move extra links from the list to the other list */
- for (i = 0; i < priv->location_change_distance; ++i) {
- bookmark = NAUTILUS_BOOKMARK (list->data);
- list = g_list_remove (list, bookmark);
- other_list = g_list_prepend (other_list, bookmark);
- }
-
- /* One bookmark falls out of back/forward lists and becomes viewed location */
- link = list;
- list = g_list_remove_link (list, link);
- g_object_unref (link->data);
- g_list_free_1 (link);
-
- *list_ptr = list;
- *other_list_ptr = other_list;
+ GFile *location,
+ gboolean forward)
+{
+ GList **list_ptr, **other_list_ptr;
+ GList *list, *other_list, *link;
+ NautilusBookmark *bookmark;
+ gint i;
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ list_ptr = (forward) ? (&priv->forward_list) : (&priv->back_list);
+ other_list_ptr = (forward) ? (&priv->back_list) : (&priv->forward_list);
+ list = *list_ptr;
+ other_list = *other_list_ptr;
+
+ /* Move items from the list to the other list. */
+ g_assert (g_list_length (list) > priv->location_change_distance);
+ check_bookmark_location_matches (g_list_nth_data (list, priv->location_change_distance),
+ location);
+ g_assert (nautilus_window_slot_get_location (self) != NULL);
+
+ /* Move current location to list */
+ check_last_bookmark_location_matches_slot (self);
+
+ /* Use the first bookmark in the history list rather than creating a new one. */
+ other_list = g_list_prepend (other_list, priv->last_location_bookmark);
+ g_object_ref (other_list->data);
+
+ /* Move extra links from the list to the other list */
+ for (i = 0; i < priv->location_change_distance; ++i)
+ {
+ bookmark = NAUTILUS_BOOKMARK (list->data);
+ list = g_list_remove (list, bookmark);
+ other_list = g_list_prepend (other_list, bookmark);
+ }
+
+ /* One bookmark falls out of back/forward lists and becomes viewed location */
+ link = list;
+ list = g_list_remove_link (list, link);
+ g_object_unref (link->data);
+ g_list_free_1 (link);
+
+ *list_ptr = list;
+ *other_list_ptr = other_list;
}
static void
handle_go_elsewhere (NautilusWindowSlot *self,
GFile *location)
{
- GFile *slot_location;
- NautilusWindowSlotPrivate *priv;
-
- priv = nautilus_window_slot_get_instance_private (self);
- /* Clobber the entire forward list, and move displayed location to back list */
- nautilus_window_slot_clear_forward_list (self);
- slot_location = nautilus_window_slot_get_location (self);
-
- if (slot_location != NULL) {
- /* If we're returning to the same uri somehow, don't put this uri on back list.
- * This also avoids a problem where set_displayed_location
- * didn't update last_location_bookmark since the uri didn't change.
- */
- if (!g_file_equal (slot_location, location)) {
- /* Store bookmark for current location in back list, unless there is no current location */
- check_last_bookmark_location_matches_slot (self);
- /* Use the first bookmark in the history list rather than creating a new one. */
- priv->back_list = g_list_prepend (priv->back_list,
- priv->last_location_bookmark);
- g_object_ref (priv->back_list->data);
- }
- }
+ GFile *slot_location;
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ /* Clobber the entire forward list, and move displayed location to back list */
+ nautilus_window_slot_clear_forward_list (self);
+ slot_location = nautilus_window_slot_get_location (self);
+
+ if (slot_location != NULL)
+ {
+ /* If we're returning to the same uri somehow, don't put this uri on back list.
+ * This also avoids a problem where set_displayed_location
+ * didn't update last_location_bookmark since the uri didn't change.
+ */
+ if (!g_file_equal (slot_location, location))
+ {
+ /* Store bookmark for current location in back list, unless there is no current location */
+ check_last_bookmark_location_matches_slot (self);
+ /* Use the first bookmark in the history list rather than creating a new one. */
+ priv->back_list = g_list_prepend (priv->back_list,
+ priv->last_location_bookmark);
+ g_object_ref (priv->back_list->data);
+ }
+ }
}
static void
@@ -1962,27 +2188,38 @@ update_history (NautilusWindowSlot *self,
NautilusLocationChangeType type,
GFile *new_location)
{
- switch (type) {
+ switch (type)
+ {
case NAUTILUS_LOCATION_CHANGE_STANDARD:
- handle_go_elsewhere (self, new_location);
+ {
+ handle_go_elsewhere (self, new_location);
return;
+ }
+
case NAUTILUS_LOCATION_CHANGE_RELOAD:
+ {
/* for reload there is no work to do */
return;
+ }
+
case NAUTILUS_LOCATION_CHANGE_BACK:
+ {
handle_go_direction (self, new_location, FALSE);
return;
+ }
+
case NAUTILUS_LOCATION_CHANGE_FORWARD:
- handle_go_direction (self, new_location, TRUE);
- return;
- }
- g_return_if_fail (FALSE);
+ handle_go_direction (self, new_location, TRUE);
+ return;
+ }
+ g_return_if_fail (FALSE);
}
-typedef struct {
- NautilusWindowSlot *slot;
- GCancellable *cancellable;
- GMount *mount;
+typedef struct
+{
+ NautilusWindowSlot *slot;
+ GCancellable *cancellable;
+ GMount *mount;
} FindMountData;
static void
@@ -1990,44 +2227,48 @@ nautilus_window_slot_show_x_content_bar (NautilusWindowSlot *self,
GMount *mount,
const char * const *x_content_types)
{
- GtkWidget *bar;
+ GtkWidget *bar;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- if (!should_handle_content_types (x_content_types))
- return;
+ if (!should_handle_content_types (x_content_types))
+ {
+ return;
+ }
- bar = nautilus_x_content_bar_new (mount, x_content_types);
- gtk_widget_show (bar);
- nautilus_window_slot_add_extra_location_widget (self, bar);
+ bar = nautilus_x_content_bar_new (mount, x_content_types);
+ gtk_widget_show (bar);
+ nautilus_window_slot_add_extra_location_widget (self, bar);
}
static void
found_content_type_cb (const char **x_content_types,
gpointer user_data)
{
- NautilusWindowSlot *self;
- FindMountData *data = user_data;
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlot *self;
+ FindMountData *data = user_data;
+ NautilusWindowSlotPrivate *priv;
- self = data->slot;
- priv = nautilus_window_slot_get_instance_private (self);
+ self = data->slot;
+ priv = nautilus_window_slot_get_instance_private (self);
- if (g_cancellable_is_cancelled (data->cancellable)) {
- goto out;
- }
+ if (g_cancellable_is_cancelled (data->cancellable))
+ {
+ goto out;
+ }
- if (x_content_types != NULL && x_content_types[0] != NULL) {
- nautilus_window_slot_show_x_content_bar (self, data->mount, (const char* const *) x_content_types);
- }
+ if (x_content_types != NULL && x_content_types[0] != NULL)
+ {
+ nautilus_window_slot_show_x_content_bar (self, data->mount, (const char * const *) x_content_types);
+ }
- priv->find_mount_cancellable = NULL;
+ priv->find_mount_cancellable = NULL;
- out:
- g_object_unref (data->mount);
- g_object_unref (data->cancellable);
- g_free (data);
+out:
+ g_object_unref (data->mount);
+ g_object_unref (data->cancellable);
+ g_free (data);
}
static void
@@ -2035,158 +2276,166 @@ found_mount_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- FindMountData *data = user_data;
- NautilusWindowSlot *self;
- GMount *mount;
- NautilusWindowSlotPrivate *priv;
-
- self = NAUTILUS_WINDOW_SLOT (data->slot);
- priv = nautilus_window_slot_get_instance_private (self);
- if (g_cancellable_is_cancelled (data->cancellable)) {
- goto out;
- }
-
- mount = g_file_find_enclosing_mount_finish (G_FILE (source_object),
- res,
- NULL);
- if (mount != NULL) {
- data->mount = mount;
- nautilus_get_x_content_types_for_mount_async (mount,
- found_content_type_cb,
- data->cancellable,
- data);
- return;
- }
-
- priv->find_mount_cancellable = NULL;
+ FindMountData *data = user_data;
+ NautilusWindowSlot *self;
+ GMount *mount;
+ NautilusWindowSlotPrivate *priv;
+
+ self = NAUTILUS_WINDOW_SLOT (data->slot);
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (g_cancellable_is_cancelled (data->cancellable))
+ {
+ goto out;
+ }
+
+ mount = g_file_find_enclosing_mount_finish (G_FILE (source_object),
+ res,
+ NULL);
+ if (mount != NULL)
+ {
+ data->mount = mount;
+ nautilus_get_x_content_types_for_mount_async (mount,
+ found_content_type_cb,
+ data->cancellable,
+ data);
+ return;
+ }
+
+ priv->find_mount_cancellable = NULL;
- out:
- g_object_unref (data->cancellable);
- g_free (data);
+out:
+ g_object_unref (data->cancellable);
+ g_free (data);
}
static void
nautilus_window_slot_show_trash_bar (NautilusWindowSlot *self)
{
- GtkWidget *bar;
- NautilusView *view;
+ GtkWidget *bar;
+ NautilusView *view;
- view = nautilus_window_slot_get_current_view (self);
- bar = nautilus_trash_bar_new (NAUTILUS_FILES_VIEW (view));
- gtk_widget_show (bar);
+ view = nautilus_window_slot_get_current_view (self);
+ bar = nautilus_trash_bar_new (NAUTILUS_FILES_VIEW (view));
+ gtk_widget_show (bar);
- nautilus_window_slot_add_extra_location_widget (self, bar);
+ nautilus_window_slot_add_extra_location_widget (self, bar);
}
static void
nautilus_window_slot_show_special_location_bar (NautilusWindowSlot *self,
NautilusSpecialLocation special_location)
{
- GtkWidget *bar;
+ GtkWidget *bar;
- bar = nautilus_special_location_bar_new (special_location);
- gtk_widget_show (bar);
+ bar = nautilus_special_location_bar_new (special_location);
+ gtk_widget_show (bar);
- nautilus_window_slot_add_extra_location_widget (self, bar);
+ nautilus_window_slot_add_extra_location_widget (self, bar);
}
static void
slot_add_extension_extra_widgets (NautilusWindowSlot *self)
{
- GList *providers, *l;
- GtkWidget *widget;
- char *uri;
- NautilusWindow *window;
+ GList *providers, *l;
+ GtkWidget *widget;
+ char *uri;
+ NautilusWindow *window;
- providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER);
- window = nautilus_window_slot_get_window (self);
+ providers = nautilus_module_get_extensions_for_type (NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER);
+ window = nautilus_window_slot_get_window (self);
- uri = nautilus_window_slot_get_location_uri (self);
- for (l = providers; l != NULL; l = l->next) {
- NautilusLocationWidgetProvider *provider;
+ uri = nautilus_window_slot_get_location_uri (self);
+ for (l = providers; l != NULL; l = l->next)
+ {
+ NautilusLocationWidgetProvider *provider;
- provider = NAUTILUS_LOCATION_WIDGET_PROVIDER (l->data);
- widget = nautilus_location_widget_provider_get_widget (provider, uri, GTK_WIDGET (window));
- if (widget != NULL) {
- nautilus_window_slot_add_extra_location_widget (self, widget);
- }
- }
- g_free (uri);
+ provider = NAUTILUS_LOCATION_WIDGET_PROVIDER (l->data);
+ widget = nautilus_location_widget_provider_get_widget (provider, uri, GTK_WIDGET (window));
+ if (widget != NULL)
+ {
+ nautilus_window_slot_add_extra_location_widget (self, widget);
+ }
+ }
+ g_free (uri);
- nautilus_module_extension_list_free (providers);
+ nautilus_module_extension_list_free (providers);
}
static void
nautilus_window_slot_update_for_new_location (NautilusWindowSlot *self)
{
- GFile *new_location;
- NautilusFile *file;
- NautilusWindowSlotPrivate *priv;
+ GFile *new_location;
+ NautilusFile *file;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- new_location = priv->pending_location;
- priv->pending_location = NULL;
+ priv = nautilus_window_slot_get_instance_private (self);
+ new_location = priv->pending_location;
+ priv->pending_location = NULL;
- file = nautilus_file_get (new_location);
- nautilus_window_slot_update_bookmark (self, file);
+ file = nautilus_file_get (new_location);
+ nautilus_window_slot_update_bookmark (self, file);
- update_history (self, priv->location_change_type, new_location);
+ update_history (self, priv->location_change_type, new_location);
- /* Create a NautilusFile for this location, so we can catch it
- * if it goes away.
- */
- nautilus_window_slot_set_viewed_file (self, file);
- priv->viewed_file_seen = !nautilus_file_is_not_yet_confirmed (file);
- priv->viewed_file_in_trash = nautilus_file_is_in_trash (file);
- nautilus_file_unref (file);
+ /* Create a NautilusFile for this location, so we can catch it
+ * if it goes away.
+ */
+ nautilus_window_slot_set_viewed_file (self, file);
+ priv->viewed_file_seen = !nautilus_file_is_not_yet_confirmed (file);
+ priv->viewed_file_in_trash = nautilus_file_is_in_trash (file);
+ nautilus_file_unref (file);
- nautilus_window_slot_set_location (self, new_location);
+ nautilus_window_slot_set_location (self, new_location);
- /* Sync the actions for this new location. */
- nautilus_window_slot_sync_actions (self);
+ /* Sync the actions for this new location. */
+ nautilus_window_slot_sync_actions (self);
}
static void
view_started_loading (NautilusWindowSlot *self,
NautilusView *view)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (view == priv->content_view) {
- nautilus_window_slot_set_allow_stop (self, TRUE);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (view == priv->content_view)
+ {
+ nautilus_window_slot_set_allow_stop (self, TRUE);
+ }
- gtk_widget_grab_focus (GTK_WIDGET (priv->window));
+ gtk_widget_grab_focus (GTK_WIDGET (priv->window));
- gtk_widget_show (GTK_WIDGET (priv->window));
+ gtk_widget_show (GTK_WIDGET (priv->window));
- nautilus_window_slot_set_loading (self, TRUE);
+ nautilus_window_slot_set_loading (self, TRUE);
}
static void
view_ended_loading (NautilusWindowSlot *self,
NautilusView *view)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (view == priv->content_view) {
- if (NAUTILUS_IS_FILES_VIEW (view) && priv->pending_scroll_to != NULL) {
- nautilus_files_view_scroll_to_file (NAUTILUS_FILES_VIEW (priv->content_view), priv->pending_scroll_to);
- }
-
- end_location_change (self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (view == priv->content_view)
+ {
+ if (NAUTILUS_IS_FILES_VIEW (view) && priv->pending_scroll_to != NULL)
+ {
+ nautilus_files_view_scroll_to_file (NAUTILUS_FILES_VIEW (priv->content_view), priv->pending_scroll_to);
}
- if (priv->needs_reload) {
- nautilus_window_slot_queue_reload (self);
- priv->needs_reload = FALSE;
- }
+ end_location_change (self);
+ }
- nautilus_window_slot_set_allow_stop (self, FALSE);
+ if (priv->needs_reload)
+ {
+ nautilus_window_slot_queue_reload (self);
+ priv->needs_reload = FALSE;
+ }
- nautilus_window_slot_set_loading (self, FALSE);
+ nautilus_window_slot_set_allow_stop (self, FALSE);
+
+ nautilus_window_slot_set_loading (self, FALSE);
}
static void
@@ -2194,395 +2443,422 @@ view_is_loading_changed_cb (GObject *object,
GParamSpec *pspec,
NautilusWindowSlot *self)
{
- NautilusView *view;
+ NautilusView *view;
- view = NAUTILUS_VIEW (object);
+ view = NAUTILUS_VIEW (object);
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- if (nautilus_view_is_loading (view)) {
- view_started_loading (self, view);
- } else {
- view_ended_loading (self, view);
- }
+ if (nautilus_view_is_loading (view))
+ {
+ view_started_loading (self, view);
+ }
+ else
+ {
+ view_ended_loading (self, view);
+ }
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static void
nautilus_window_slot_setup_extra_location_widgets (NautilusWindowSlot *self)
{
- GFile *location;
- FindMountData *data;
- NautilusDirectory *directory;
- NautilusWindowSlotPrivate *priv;
+ GFile *location;
+ FindMountData *data;
+ NautilusDirectory *directory;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- location = nautilus_window_slot_get_current_location (self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ location = nautilus_window_slot_get_current_location (self);
- if (location == NULL) {
- return;
- }
+ if (location == NULL)
+ {
+ return;
+ }
- directory = nautilus_directory_get (location);
+ directory = nautilus_directory_get (location);
- if (nautilus_directory_is_in_trash (directory)) {
- nautilus_window_slot_show_trash_bar (self);
- } else {
- NautilusFile *file;
- GFile *scripts_file;
- char *scripts_path = nautilus_get_scripts_directory_path ();
+ if (nautilus_directory_is_in_trash (directory))
+ {
+ nautilus_window_slot_show_trash_bar (self);
+ }
+ else
+ {
+ NautilusFile *file;
+ GFile *scripts_file;
+ char *scripts_path = nautilus_get_scripts_directory_path ();
- scripts_file = g_file_new_for_path (scripts_path);
- g_free (scripts_path);
+ scripts_file = g_file_new_for_path (scripts_path);
+ g_free (scripts_path);
- file = nautilus_file_get (location);
+ file = nautilus_file_get (location);
- if (nautilus_should_use_templates_directory () &&
- nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_TEMPLATES)) {
- nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_TEMPLATES);
- } else if (g_file_equal (location, scripts_file)) {
- nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SCRIPTS);
- }
+ if (nautilus_should_use_templates_directory () &&
+ nautilus_file_is_user_special_directory (file, G_USER_DIRECTORY_TEMPLATES))
+ {
+ nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_TEMPLATES);
+ }
+ else if (g_file_equal (location, scripts_file))
+ {
+ nautilus_window_slot_show_special_location_bar (self, NAUTILUS_SPECIAL_LOCATION_SCRIPTS);
+ }
- g_object_unref (scripts_file);
- nautilus_file_unref (file);
- }
+ g_object_unref (scripts_file);
+ nautilus_file_unref (file);
+ }
- /* need the mount to determine if we should put up the x-content cluebar */
- if (priv->find_mount_cancellable != NULL) {
- g_cancellable_cancel (priv->find_mount_cancellable);
- priv->find_mount_cancellable = NULL;
- }
+ /* need the mount to determine if we should put up the x-content cluebar */
+ if (priv->find_mount_cancellable != NULL)
+ {
+ g_cancellable_cancel (priv->find_mount_cancellable);
+ priv->find_mount_cancellable = NULL;
+ }
- data = g_new (FindMountData, 1);
- data->slot = self;
- data->cancellable = g_cancellable_new ();
- data->mount = NULL;
+ data = g_new (FindMountData, 1);
+ data->slot = self;
+ data->cancellable = g_cancellable_new ();
+ data->mount = NULL;
- priv->find_mount_cancellable = data->cancellable;
- g_file_find_enclosing_mount_async (location,
- G_PRIORITY_DEFAULT,
- data->cancellable,
- found_mount_cb,
- data);
+ priv->find_mount_cancellable = data->cancellable;
+ g_file_find_enclosing_mount_async (location,
+ G_PRIORITY_DEFAULT,
+ data->cancellable,
+ found_mount_cb,
+ data);
- nautilus_directory_unref (directory);
+ nautilus_directory_unref (directory);
- slot_add_extension_extra_widgets (self);
+ slot_add_extension_extra_widgets (self);
}
static void
nautilus_window_slot_connect_new_content_view (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->new_content_view) {
- g_signal_connect (priv->new_content_view,
- "notify::is-loading",
- G_CALLBACK (view_is_loading_changed_cb),
- self);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->new_content_view)
+ {
+ g_signal_connect (priv->new_content_view,
+ "notify::is-loading",
+ G_CALLBACK (view_is_loading_changed_cb),
+ self);
+ }
}
static void
nautilus_window_slot_disconnect_content_view (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->content_view) {
- /* disconnect old view */
- g_signal_handlers_disconnect_by_func (priv->content_view,
- G_CALLBACK (view_is_loading_changed_cb),
- self);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->content_view)
+ {
+ /* disconnect old view */
+ g_signal_handlers_disconnect_by_func (priv->content_view,
+ G_CALLBACK (view_is_loading_changed_cb),
+ self);
+ }
}
static void
nautilus_window_slot_switch_new_content_view (NautilusWindowSlot *self)
{
- GtkWidget *widget;
- gboolean reusing_view;
- NautilusWindowSlotPrivate *priv;
-
- priv = nautilus_window_slot_get_instance_private (self);
- reusing_view = priv->new_content_view &&
- gtk_widget_get_parent (GTK_WIDGET (priv->new_content_view)) != NULL;
- /* We are either reusing the view, so new_content_view and content_view
- * are the same, or the new_content_view is invalid */
- if (priv->new_content_view == NULL || reusing_view)
- goto done;
-
- if (priv->content_view != NULL) {
- widget = GTK_WIDGET (priv->content_view);
- gtk_widget_destroy (widget);
- g_object_unref (priv->content_view);
- priv->content_view = NULL;
- }
-
- if (priv->new_content_view != NULL) {
- priv->content_view = priv->new_content_view;
- priv->new_content_view = NULL;
-
- widget = GTK_WIDGET (priv->content_view);
- gtk_container_add (GTK_CONTAINER (self), widget);
- gtk_widget_set_vexpand (widget, TRUE);
- gtk_widget_show (widget);
-
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TOOLBAR_MENU_SECTIONS]);
- }
-
-done:
- /* Clean up, so we don't confuse having a new_content_view available or
- * just that we didn't care about it here */
+ GtkWidget *widget;
+ gboolean reusing_view;
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ reusing_view = priv->new_content_view &&
+ gtk_widget_get_parent (GTK_WIDGET (priv->new_content_view)) != NULL;
+ /* We are either reusing the view, so new_content_view and content_view
+ * are the same, or the new_content_view is invalid */
+ if (priv->new_content_view == NULL || reusing_view)
+ {
+ goto done;
+ }
+
+ if (priv->content_view != NULL)
+ {
+ widget = GTK_WIDGET (priv->content_view);
+ gtk_widget_destroy (widget);
+ g_object_unref (priv->content_view);
+ priv->content_view = NULL;
+ }
+
+ if (priv->new_content_view != NULL)
+ {
+ priv->content_view = priv->new_content_view;
priv->new_content_view = NULL;
+ widget = GTK_WIDGET (priv->content_view);
+ gtk_container_add (GTK_CONTAINER (self), widget);
+ gtk_widget_set_vexpand (widget, TRUE);
+ gtk_widget_show (widget);
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TOOLBAR_MENU_SECTIONS]);
+ }
+
+done:
+ /* Clean up, so we don't confuse having a new_content_view available or
+ * just that we didn't care about it here */
+ priv->new_content_view = NULL;
}
/* This is called when we have decided we can actually change to the new view/location situation. */
static void
change_view (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- /* Switch to the new content view.
- * Destroy the extra location widgets first, since they might hold
- * a pointer to the old view, which will possibly be destroyed inside
- * nautilus_window_slot_switch_new_content_view().
- */
- nautilus_window_slot_remove_extra_location_widgets (self);
- nautilus_window_slot_switch_new_content_view (self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ /* Switch to the new content view.
+ * Destroy the extra location widgets first, since they might hold
+ * a pointer to the old view, which will possibly be destroyed inside
+ * nautilus_window_slot_switch_new_content_view().
+ */
+ nautilus_window_slot_remove_extra_location_widgets (self);
+ nautilus_window_slot_switch_new_content_view (self);
- if (priv->pending_location != NULL) {
- /* Tell the window we are finished. */
- nautilus_window_slot_update_for_new_location (self);
- }
+ if (priv->pending_location != NULL)
+ {
+ /* Tell the window we are finished. */
+ nautilus_window_slot_update_for_new_location (self);
+ }
- /* Now that we finished switching to the new location,
- * add back the extra location widgets.
- */
- nautilus_window_slot_setup_extra_location_widgets (self);
+ /* Now that we finished switching to the new location,
+ * add back the extra location widgets.
+ */
+ nautilus_window_slot_setup_extra_location_widgets (self);
}
static void
nautilus_window_slot_dispose (GObject *object)
{
- NautilusWindowSlot *self;
- GtkWidget *widget;
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlot *self;
+ GtkWidget *widget;
+ NautilusWindowSlotPrivate *priv;
- self = NAUTILUS_WINDOW_SLOT (object);
- priv = nautilus_window_slot_get_instance_private (self);
+ self = NAUTILUS_WINDOW_SLOT (object);
+ priv = nautilus_window_slot_get_instance_private (self);
- nautilus_window_slot_clear_forward_list (self);
- nautilus_window_slot_clear_back_list (self);
+ nautilus_window_slot_clear_forward_list (self);
+ nautilus_window_slot_clear_back_list (self);
- nautilus_window_slot_remove_extra_location_widgets (self);
+ nautilus_window_slot_remove_extra_location_widgets (self);
- if (priv->content_view) {
- widget = GTK_WIDGET (priv->content_view);
- gtk_widget_destroy (widget);
- g_object_unref (priv->content_view);
- priv->content_view = NULL;
- }
+ if (priv->content_view)
+ {
+ widget = GTK_WIDGET (priv->content_view);
+ gtk_widget_destroy (widget);
+ g_object_unref (priv->content_view);
+ priv->content_view = NULL;
+ }
- if (priv->new_content_view) {
- widget = GTK_WIDGET (priv->new_content_view);
- gtk_widget_destroy (widget);
- g_object_unref (priv->new_content_view);
- priv->new_content_view = NULL;
- }
+ if (priv->new_content_view)
+ {
+ widget = GTK_WIDGET (priv->new_content_view);
+ gtk_widget_destroy (widget);
+ g_object_unref (priv->new_content_view);
+ priv->new_content_view = NULL;
+ }
- nautilus_window_slot_set_viewed_file (self, NULL);
+ nautilus_window_slot_set_viewed_file (self, NULL);
- g_clear_object (&priv->location);
+ g_clear_object (&priv->location);
- nautilus_file_list_free (priv->pending_selection);
- priv->pending_selection = NULL;
+ nautilus_file_list_free (priv->pending_selection);
+ priv->pending_selection = NULL;
- g_clear_object (&priv->current_location_bookmark);
- g_clear_object (&priv->last_location_bookmark);
+ g_clear_object (&priv->current_location_bookmark);
+ g_clear_object (&priv->last_location_bookmark);
- if (priv->find_mount_cancellable != NULL) {
- g_cancellable_cancel (priv->find_mount_cancellable);
- priv->find_mount_cancellable = NULL;
- }
+ if (priv->find_mount_cancellable != NULL)
+ {
+ g_cancellable_cancel (priv->find_mount_cancellable);
+ priv->find_mount_cancellable = NULL;
+ }
- priv->window = NULL;
+ priv->window = NULL;
- g_free (priv->title);
- priv->title = NULL;
+ g_free (priv->title);
+ priv->title = NULL;
- free_location_change (self);
+ free_location_change (self);
- G_OBJECT_CLASS (nautilus_window_slot_parent_class)->dispose (object);
+ G_OBJECT_CLASS (nautilus_window_slot_parent_class)->dispose (object);
}
static void
nautilus_window_slot_grab_focus (GtkWidget *widget)
{
- NautilusWindowSlot *self;
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlot *self;
+ NautilusWindowSlotPrivate *priv;
- self = NAUTILUS_WINDOW_SLOT (widget);
- priv = nautilus_window_slot_get_instance_private (self);
+ self = NAUTILUS_WINDOW_SLOT (widget);
+ priv = nautilus_window_slot_get_instance_private (self);
- GTK_WIDGET_CLASS (nautilus_window_slot_parent_class)->grab_focus (widget);
+ GTK_WIDGET_CLASS (nautilus_window_slot_parent_class)->grab_focus (widget);
- if (nautilus_window_slot_get_search_visible (self)) {
- gtk_widget_grab_focus (GTK_WIDGET (priv->query_editor));
- } else if (priv->content_view) {
- gtk_widget_grab_focus (GTK_WIDGET (priv->content_view));
- } else if (priv->new_content_view) {
- gtk_widget_grab_focus (GTK_WIDGET (priv->new_content_view));
- }
+ if (nautilus_window_slot_get_search_visible (self))
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (priv->query_editor));
+ }
+ else if (priv->content_view)
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (priv->content_view));
+ }
+ else if (priv->new_content_view)
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (priv->new_content_view));
+ }
}
static void
nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
{
- GObjectClass *oclass = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- klass->active = real_active;
- klass->inactive = real_inactive;
- klass->get_view_for_location = real_get_view_for_location;
- klass->handles_location = real_handles_location;
-
- oclass->dispose = nautilus_window_slot_dispose;
- oclass->constructed = nautilus_window_slot_constructed;
- oclass->set_property = nautilus_window_slot_set_property;
- oclass->get_property = nautilus_window_slot_get_property;
-
- widget_class->grab_focus = nautilus_window_slot_grab_focus;
-
- signals[ACTIVE] =
- g_signal_new ("active",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusWindowSlotClass, active),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- signals[INACTIVE] =
- g_signal_new ("inactive",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (NautilusWindowSlotClass, inactive),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- properties[PROP_ACTIVE] =
- g_param_spec_boolean ("active",
- "Whether the slot is active",
- "Whether the slot is the active slot of the window",
- FALSE,
- G_PARAM_READWRITE);
- properties[PROP_LOADING] =
- g_param_spec_boolean ("loading",
- "Whether the slot loading",
- "Whether the slot is loading a new location",
- FALSE,
- G_PARAM_READABLE);
-
- properties[PROP_WINDOW] =
- g_param_spec_object ("window",
- "The NautilusWindow",
- "The NautilusWindow this slot is part of",
- NAUTILUS_TYPE_WINDOW,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
-
- properties[PROP_ICON] =
- g_param_spec_object ("icon",
- "Icon that represents the slot",
- "The icon that represents the slot",
- G_TYPE_ICON,
- G_PARAM_READABLE);
-
- properties[PROP_TOOLBAR_MENU_SECTIONS] =
- g_param_spec_pointer ("toolbar-menu-sections",
- "Menu sections for the toolbar menu",
- "The menu sections to add to the toolbar menu for this slot",
- G_PARAM_READABLE);
-
- properties[PROP_LOCATION] =
- g_param_spec_object ("location",
- "Current location visible on the slot",
- "Either the location that is used currently, or the pending location. Clients will see the same value they set, and therefore it will be cosistent from clients point of view.",
- G_TYPE_FILE,
- G_PARAM_READWRITE);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ klass->active = real_active;
+ klass->inactive = real_inactive;
+ klass->get_view_for_location = real_get_view_for_location;
+ klass->handles_location = real_handles_location;
+
+ oclass->dispose = nautilus_window_slot_dispose;
+ oclass->constructed = nautilus_window_slot_constructed;
+ oclass->set_property = nautilus_window_slot_set_property;
+ oclass->get_property = nautilus_window_slot_get_property;
+
+ widget_class->grab_focus = nautilus_window_slot_grab_focus;
+
+ signals[ACTIVE] =
+ g_signal_new ("active",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusWindowSlotClass, active),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ signals[INACTIVE] =
+ g_signal_new ("inactive",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (NautilusWindowSlotClass, inactive),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ properties[PROP_ACTIVE] =
+ g_param_spec_boolean ("active",
+ "Whether the slot is active",
+ "Whether the slot is the active slot of the window",
+ FALSE,
+ G_PARAM_READWRITE);
+ properties[PROP_LOADING] =
+ g_param_spec_boolean ("loading",
+ "Whether the slot loading",
+ "Whether the slot is loading a new location",
+ FALSE,
+ G_PARAM_READABLE);
+
+ properties[PROP_WINDOW] =
+ g_param_spec_object ("window",
+ "The NautilusWindow",
+ "The NautilusWindow this slot is part of",
+ NAUTILUS_TYPE_WINDOW,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
+ properties[PROP_ICON] =
+ g_param_spec_object ("icon",
+ "Icon that represents the slot",
+ "The icon that represents the slot",
+ G_TYPE_ICON,
+ G_PARAM_READABLE);
+
+ properties[PROP_TOOLBAR_MENU_SECTIONS] =
+ g_param_spec_pointer ("toolbar-menu-sections",
+ "Menu sections for the toolbar menu",
+ "The menu sections to add to the toolbar menu for this slot",
+ G_PARAM_READABLE);
+
+ properties[PROP_LOCATION] =
+ g_param_spec_object ("location",
+ "Current location visible on the slot",
+ "Either the location that is used currently, or the pending location. Clients will see the same value they set, and therefore it will be cosistent from clients point of view.",
+ G_TYPE_FILE,
+ G_PARAM_READWRITE);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
GFile *
nautilus_window_slot_get_location (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (self != NULL);
+ g_assert (self != NULL);
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->location;
+ return priv->location;
}
const gchar *
nautilus_window_slot_get_title (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->title;
+ return priv->title;
}
char *
nautilus_window_slot_get_location_uri (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->location) {
- return g_file_get_uri (priv->location);
- }
- return NULL;
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->location)
+ {
+ return g_file_get_uri (priv->location);
+ }
+ return NULL;
}
NautilusWindow *
nautilus_window_slot_get_window (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->window;
+ return priv->window;
}
void
nautilus_window_slot_set_window (NautilusWindowSlot *self,
NautilusWindow *window)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- g_assert (NAUTILUS_IS_WINDOW (window));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW (window));
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->window != window) {
- priv->window = window;
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WINDOW]);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->window != window)
+ {
+ priv->window = window;
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WINDOW]);
+ }
}
/* nautilus_window_slot_update_title:
@@ -2595,240 +2871,254 @@ nautilus_window_slot_set_window (NautilusWindowSlot *self,
void
nautilus_window_slot_update_title (NautilusWindowSlot *self)
{
- NautilusWindow *window;
- char *title;
- gboolean do_sync = FALSE;
- NautilusWindowSlotPrivate *priv;
+ NautilusWindow *window;
+ char *title;
+ gboolean do_sync = FALSE;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- title = nautilus_compute_title_for_location (priv->location);
- window = nautilus_window_slot_get_window (self);
+ priv = nautilus_window_slot_get_instance_private (self);
+ title = nautilus_compute_title_for_location (priv->location);
+ window = nautilus_window_slot_get_window (self);
- if (g_strcmp0 (title, priv->title) != 0) {
- do_sync = TRUE;
+ if (g_strcmp0 (title, priv->title) != 0)
+ {
+ do_sync = TRUE;
- g_free (priv->title);
- priv->title = title;
- title = NULL;
- }
+ g_free (priv->title);
+ priv->title = title;
+ title = NULL;
+ }
- if (strlen (priv->title) > 0) {
- do_sync = TRUE;
- }
+ if (strlen (priv->title) > 0)
+ {
+ do_sync = TRUE;
+ }
- if (do_sync) {
- nautilus_window_sync_title (window, self);
- }
+ if (do_sync)
+ {
+ nautilus_window_sync_title (window, self);
+ }
- if (title != NULL) {
- g_free (title);
- }
+ if (title != NULL)
+ {
+ g_free (title);
+ }
}
gboolean
nautilus_window_slot_get_allow_stop (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->allow_stop;
+ return priv->allow_stop;
}
void
nautilus_window_slot_set_allow_stop (NautilusWindowSlot *self,
gboolean allow)
{
- NautilusWindow *window;
- NautilusWindowSlotPrivate *priv;
+ NautilusWindow *window;
+ NautilusWindowSlotPrivate *priv;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- priv->allow_stop = allow;
+ priv->allow_stop = allow;
- window = nautilus_window_slot_get_window (self);
- nautilus_window_sync_allow_stop (window, self);
+ window = nautilus_window_slot_get_window (self);
+ nautilus_window_sync_allow_stop (window, self);
}
void
nautilus_window_slot_stop_loading (NautilusWindowSlot *self)
{
- GList *selection;
- GFile *location;
- NautilusDirectory *directory;
- NautilusWindowSlotPrivate *priv;
-
- priv = nautilus_window_slot_get_instance_private (self);
- location = nautilus_window_slot_get_location (self);
- directory = nautilus_directory_get (priv->location);
-
- if (NAUTILUS_IS_FILES_VIEW (priv->content_view)) {
- nautilus_files_view_stop_loading (NAUTILUS_FILES_VIEW (priv->content_view));
- }
-
- nautilus_directory_unref (directory);
-
- if (priv->pending_location != NULL &&
- location != NULL &&
- priv->content_view != NULL &&
- NAUTILUS_IS_FILES_VIEW (priv->content_view)) {
- /* No need to tell the new view - either it is the
- * same as the old view, in which case it will already
- * be told, or it is the very pending change we wish
- * to cancel.
- */
- selection = nautilus_view_get_selection (priv->content_view);
- load_new_location (self,
- location,
- selection,
- TRUE,
- FALSE);
- nautilus_file_list_free (selection);
- }
-
- end_location_change (self);
-
- if (priv->new_content_view) {
- g_object_unref (priv->new_content_view);
- priv->new_content_view = NULL;
- }
+ GList *selection;
+ GFile *location;
+ NautilusDirectory *directory;
+ NautilusWindowSlotPrivate *priv;
+
+ priv = nautilus_window_slot_get_instance_private (self);
+ location = nautilus_window_slot_get_location (self);
+ directory = nautilus_directory_get (priv->location);
+
+ if (NAUTILUS_IS_FILES_VIEW (priv->content_view))
+ {
+ nautilus_files_view_stop_loading (NAUTILUS_FILES_VIEW (priv->content_view));
+ }
+
+ nautilus_directory_unref (directory);
+
+ if (priv->pending_location != NULL &&
+ location != NULL &&
+ priv->content_view != NULL &&
+ NAUTILUS_IS_FILES_VIEW (priv->content_view))
+ {
+ /* No need to tell the new view - either it is the
+ * same as the old view, in which case it will already
+ * be told, or it is the very pending change we wish
+ * to cancel.
+ */
+ selection = nautilus_view_get_selection (priv->content_view);
+ load_new_location (self,
+ location,
+ selection,
+ TRUE,
+ FALSE);
+ nautilus_file_list_free (selection);
+ }
+
+ end_location_change (self);
+
+ if (priv->new_content_view)
+ {
+ g_object_unref (priv->new_content_view);
+ priv->new_content_view = NULL;
+ }
}
-NautilusView*
+NautilusView *
nautilus_window_slot_get_current_view (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->content_view != NULL) {
- return priv->content_view;
- } else if (priv->new_content_view) {
- return priv->new_content_view;
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->content_view != NULL)
+ {
+ return priv->content_view;
+ }
+ else if (priv->new_content_view)
+ {
+ return priv->new_content_view;
+ }
- return NULL;
+ return NULL;
}
NautilusBookmark *
nautilus_window_slot_get_bookmark (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->current_location_bookmark;
+ return priv->current_location_bookmark;
}
GList *
nautilus_window_slot_get_back_history (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->back_list;
+ return priv->back_list;
}
GList *
nautilus_window_slot_get_forward_history (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->forward_list;
+ return priv->forward_list;
}
NautilusWindowSlot *
nautilus_window_slot_new (NautilusWindow *window)
{
- return g_object_new (NAUTILUS_TYPE_WINDOW_SLOT,
- "window", window,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_WINDOW_SLOT,
+ "window", window,
+ NULL);
}
-GIcon*
+GIcon *
nautilus_window_slot_get_icon (NautilusWindowSlot *self)
{
- NautilusView *view;
+ NautilusView *view;
- g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NULL);
- view = nautilus_window_slot_get_current_view (self);
+ view = nautilus_window_slot_get_current_view (self);
- return view ? nautilus_view_get_icon (view) : NULL;
+ return view ? nautilus_view_get_icon (view) : NULL;
}
NautilusToolbarMenuSections *
nautilus_window_slot_get_toolbar_menu_sections (NautilusWindowSlot *self)
{
- NautilusView *view;
+ NautilusView *view;
- g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NULL);
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), NULL);
- view = nautilus_window_slot_get_current_view (self);
+ view = nautilus_window_slot_get_current_view (self);
- return view ? nautilus_view_get_toolbar_menu_sections (view) : NULL;
+ return view ? nautilus_view_get_toolbar_menu_sections (view) : NULL;
}
gboolean
nautilus_window_slot_get_active (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), FALSE);
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->active;
+ return priv->active;
}
void
nautilus_window_slot_set_active (NautilusWindowSlot *self,
gboolean active)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- if (priv->active != active) {
- priv->active = active;
-
- if (active) {
- g_signal_emit (self, signals[ACTIVE], 0);
- } else {
- g_signal_emit (self, signals[INACTIVE], 0);
- }
+ priv = nautilus_window_slot_get_instance_private (self);
+ if (priv->active != active)
+ {
+ priv->active = active;
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIVE]);
+ if (active)
+ {
+ g_signal_emit (self, signals[ACTIVE], 0);
}
+ else
+ {
+ g_signal_emit (self, signals[INACTIVE], 0);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIVE]);
+ }
}
static void
nautilus_window_slot_set_loading (NautilusWindowSlot *self,
gboolean loading)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (self));
+ g_return_if_fail (NAUTILUS_IS_WINDOW_SLOT (self));
- priv = nautilus_window_slot_get_instance_private (self);
- priv->loading = loading;
+ priv = nautilus_window_slot_get_instance_private (self);
+ priv->loading = loading;
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOADING]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOADING]);
}
gboolean
nautilus_window_slot_get_loading (NautilusWindowSlot *self)
{
- NautilusWindowSlotPrivate *priv;
+ NautilusWindowSlotPrivate *priv;
- g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), FALSE);
+ g_return_val_if_fail (NAUTILUS_IS_WINDOW_SLOT (self), FALSE);
- priv = nautilus_window_slot_get_instance_private (self);
+ priv = nautilus_window_slot_get_instance_private (self);
- return priv->loading;
+ return priv->loading;
}
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 883ae9b10..b6bfc30e5 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1,4 +1,3 @@
-
/*
* Nautilus
*
@@ -19,7 +18,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* Authors: Elliot Lee <sopwith@redhat.com>
- * John Sullivan <sullivan@eazel.com>
+ * John Sullivan <sullivan@eazel.com>
* Alexander Larsson <alexl@redhat.com>
*/
@@ -75,82 +74,85 @@ static gboolean mouse_extra_buttons = TRUE;
static int mouse_forward_button = 9;
static int mouse_back_button = 8;
-static void mouse_back_button_changed (gpointer callback_data);
-static void mouse_forward_button_changed (gpointer callback_data);
-static void use_extra_mouse_buttons_changed (gpointer callback_data);
-static void nautilus_window_initialize_actions (NautilusWindow *window);
-static GtkWidget * nautilus_window_ensure_location_entry (NautilusWindow *window);
-static void close_slot (NautilusWindow *window,
- NautilusWindowSlot *slot,
- gboolean remove_from_notebook);
-
-/* Sanity check: highest mouse button value I could find was 14. 5 is our
- * lower threshold (well-documented to be the one of the button events for the
+static void mouse_back_button_changed (gpointer callback_data);
+static void mouse_forward_button_changed (gpointer callback_data);
+static void use_extra_mouse_buttons_changed (gpointer callback_data);
+static void nautilus_window_initialize_actions (NautilusWindow *window);
+static GtkWidget *nautilus_window_ensure_location_entry (NautilusWindow *window);
+static void close_slot (NautilusWindow *window,
+ NautilusWindowSlot *slot,
+ gboolean remove_from_notebook);
+
+/* Sanity check: highest mouse button value I could find was 14. 5 is our
+ * lower threshold (well-documented to be the one of the button events for the
* scrollwheel), so it's hardcoded in the functions below. However, if you have
- * a button that registers higher and want to map it, file a bug and
- * we'll move the bar. Makes you wonder why the X guys don't have
+ * a button that registers higher and want to map it, file a bug and
+ * we'll move the bar. Makes you wonder why the X guys don't have
* defined values for these like the XKB stuff, huh?
*/
#define UPPER_MOUSE_LIMIT 14
-#define NOTIFICATION_TIMEOUT 6 //s
+#define NOTIFICATION_TIMEOUT 6 /*s */
-struct _NautilusWindowPrivate {
- GtkWidget *notebook;
+struct _NautilusWindowPrivate
+{
+ GtkWidget *notebook;
- /* available slots, and active slot.
- * Both of them may never be NULL.
- */
- GList *slots;
- NautilusWindowSlot *active_slot;
-
- GtkWidget *content_paned;
-
- /* Side Pane */
- int side_pane_width;
- GtkWidget *sidebar; /* container for the GtkPlacesSidebar */
- GtkWidget *places_sidebar; /* the actual GtkPlacesSidebar */
- GVolume *selected_volume; /* the selected volume in the sidebar popup callback */
- GFile *selected_file; /* the selected file in the sidebar popup callback */
-
- /* Main view */
- GtkWidget *main_view;
-
- /* Notifications */
- GtkWidget *notification_delete;
- GtkWidget *notification_delete_label;
- GtkWidget *notification_delete_close;
- GtkWidget *notification_delete_undo;
- guint notification_delete_timeout_id;
- GtkWidget *notification_operation;
- GtkWidget *notification_operation_label;
- GtkWidget *notification_operation_close;
- GtkWidget *notification_operation_open;
- guint notification_operation_timeout_id;
- GFile *folder_to_open;
-
- /* Toolbar */
- GtkWidget *toolbar;
- gboolean temporary_navigation_bar;
-
- /* focus widget before the location bar has been shown temporarily */
- GtkWidget *last_focus_widget;
-
- gboolean disable_chrome;
-
- guint sidebar_width_handler_id;
- guint bookmarks_id;
+ /* available slots, and active slot.
+ * Both of them may never be NULL.
+ */
+ GList *slots;
+ NautilusWindowSlot *active_slot;
+
+ GtkWidget *content_paned;
+
+ /* Side Pane */
+ int side_pane_width;
+ GtkWidget *sidebar; /* container for the GtkPlacesSidebar */
+ GtkWidget *places_sidebar; /* the actual GtkPlacesSidebar */
+ GVolume *selected_volume; /* the selected volume in the sidebar popup callback */
+ GFile *selected_file; /* the selected file in the sidebar popup callback */
+
+ /* Main view */
+ GtkWidget *main_view;
+
+ /* Notifications */
+ GtkWidget *notification_delete;
+ GtkWidget *notification_delete_label;
+ GtkWidget *notification_delete_close;
+ GtkWidget *notification_delete_undo;
+ guint notification_delete_timeout_id;
+ GtkWidget *notification_operation;
+ GtkWidget *notification_operation_label;
+ GtkWidget *notification_operation_close;
+ GtkWidget *notification_operation_open;
+ guint notification_operation_timeout_id;
+ GFile *folder_to_open;
+
+ /* Toolbar */
+ GtkWidget *toolbar;
+ gboolean temporary_navigation_bar;
+
+ /* focus widget before the location bar has been shown temporarily */
+ GtkWidget *last_focus_widget;
+
+ gboolean disable_chrome;
+
+ guint sidebar_width_handler_id;
+ guint bookmarks_id;
};
-enum {
- PROP_DISABLE_CHROME = 1,
- NUM_PROPERTIES,
+enum
+{
+ PROP_DISABLE_CHROME = 1,
+ NUM_PROPERTIES,
};
-enum {
- SLOT_ADDED,
- SLOT_REMOVED,
- LAST_SIGNAL
+enum
+{
+ SLOT_ADDED,
+ SLOT_REMOVED,
+ LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
@@ -158,259 +160,265 @@ static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
G_DEFINE_TYPE_WITH_PRIVATE (NautilusWindow, nautilus_window, GTK_TYPE_APPLICATION_WINDOW);
-static const struct {
- unsigned int keyval;
- const char *action;
-} extra_window_keybindings [] = {
+static const struct
+{
+ unsigned int keyval;
+ const char *action;
+} extra_window_keybindings [] =
+{
#ifdef HAVE_X11_XF86KEYSYM_H
- /* Window actions */
- { XF86XK_AddFavorite, "bookmark-current-location" },
- { XF86XK_Favorites, "bookmarks" },
- { XF86XK_Go, "enter-location" },
- { XF86XK_HomePage, "go-home" },
- { XF86XK_OpenURL, "enter-location" },
- { XF86XK_Refresh, "reload" },
- { XF86XK_Reload, "reload" },
- { XF86XK_Search, "search" },
- { XF86XK_Start, "go-home" },
- { XF86XK_Stop, "stop" },
- { XF86XK_Back, "back" },
- { XF86XK_Forward, "forward" },
+ /* Window actions */
+ { XF86XK_AddFavorite, "bookmark-current-location" },
+ { XF86XK_Favorites, "bookmarks" },
+ { XF86XK_Go, "enter-location" },
+ { XF86XK_HomePage, "go-home" },
+ { XF86XK_OpenURL, "enter-location" },
+ { XF86XK_Refresh, "reload" },
+ { XF86XK_Reload, "reload" },
+ { XF86XK_Search, "search" },
+ { XF86XK_Start, "go-home" },
+ { XF86XK_Stop, "stop" },
+ { XF86XK_Back, "back" },
+ { XF86XK_Forward, "forward" },
#endif
};
static void
action_close_current_view (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window;
- NautilusWindowSlot *slot;
+ NautilusWindow *window;
+ NautilusWindowSlot *slot;
- window = NAUTILUS_WINDOW (user_data);
- slot = nautilus_window_get_active_slot (window);
+ window = NAUTILUS_WINDOW (user_data);
+ slot = nautilus_window_get_active_slot (window);
- nautilus_window_slot_close (window, slot);
+ nautilus_window_slot_close (window, slot);
}
static void
action_go_home (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window;
- GFile *home;
+ NautilusWindow *window;
+ GFile *home;
- window = NAUTILUS_WINDOW (user_data);
- home = g_file_new_for_path (g_get_home_dir ());
+ window = NAUTILUS_WINDOW (user_data);
+ home = g_file_new_for_path (g_get_home_dir ());
- nautilus_window_open_location_full (window, home, nautilus_event_get_window_open_flags (), NULL, NULL);
+ nautilus_window_open_location_full (window, home, nautilus_event_get_window_open_flags (), NULL, NULL);
- g_object_unref (home);
+ g_object_unref (home);
}
static void
action_reload (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindowSlot *slot;
+ NautilusWindowSlot *slot;
- slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
- nautilus_window_slot_queue_reload (slot);
+ slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
+ nautilus_window_slot_queue_reload (slot);
}
static void
action_stop (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window;
- NautilusWindowSlot *slot;
+ NautilusWindow *window;
+ NautilusWindowSlot *slot;
- window = NAUTILUS_WINDOW (user_data);
- slot = nautilus_window_get_active_slot (window);
+ window = NAUTILUS_WINDOW (user_data);
+ slot = nautilus_window_get_active_slot (window);
- nautilus_window_slot_stop_loading (slot);
+ nautilus_window_slot_stop_loading (slot);
}
static void
action_up (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindowSlot *slot;
- GFile *parent, *location;
+ NautilusWindowSlot *slot;
+ GFile *parent, *location;
- slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
- location = nautilus_window_slot_get_location (slot);
+ slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (user_data));
+ location = nautilus_window_slot_get_location (slot);
- if (location != NULL) {
- parent = g_file_get_parent (location);
- if (parent != NULL)
- nautilus_window_open_location_full (NAUTILUS_WINDOW (user_data),
- parent,
- nautilus_event_get_window_open_flags (),
- NULL, NULL);
+ if (location != NULL)
+ {
+ parent = g_file_get_parent (location);
+ if (parent != NULL)
+ {
+ nautilus_window_open_location_full (NAUTILUS_WINDOW (user_data),
+ parent,
+ nautilus_event_get_window_open_flags (),
+ NULL, NULL);
+ }
- g_clear_object (&parent);
- }
+ g_clear_object (&parent);
+ }
}
static void
action_back (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- nautilus_window_back_or_forward (NAUTILUS_WINDOW (user_data),
- TRUE, 0, nautilus_event_get_window_open_flags ());
+ nautilus_window_back_or_forward (NAUTILUS_WINDOW (user_data),
+ TRUE, 0, nautilus_event_get_window_open_flags ());
}
static void
action_forward (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- nautilus_window_back_or_forward (NAUTILUS_WINDOW (user_data),
- FALSE, 0, nautilus_event_get_window_open_flags ());
+ nautilus_window_back_or_forward (NAUTILUS_WINDOW (user_data),
+ FALSE, 0, nautilus_event_get_window_open_flags ());
}
static void
action_bookmark_current_location (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
- NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
- NautilusWindowSlot *slot;
+ NautilusWindow *window = user_data;
+ NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
+ NautilusWindowSlot *slot;
- slot = nautilus_window_get_active_slot (window);
- nautilus_bookmark_list_append (nautilus_application_get_bookmarks (app),
- nautilus_window_slot_get_bookmark (slot));
+ slot = nautilus_window_get_active_slot (window);
+ nautilus_bookmark_list_append (nautilus_application_get_bookmarks (app),
+ nautilus_window_slot_get_bookmark (slot));
}
static void
action_new_tab (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- nautilus_window_new_tab (NAUTILUS_WINDOW (user_data));
+ nautilus_window_new_tab (NAUTILUS_WINDOW (user_data));
}
static void
action_enter_location (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_window_ensure_location_entry (window);
+ nautilus_window_ensure_location_entry (window);
}
static void
action_tab_previous (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_notebook_prev_page (NAUTILUS_NOTEBOOK (window->priv->notebook));
+ nautilus_notebook_prev_page (NAUTILUS_NOTEBOOK (window->priv->notebook));
}
static void
action_tab_next (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_notebook_next_page (NAUTILUS_NOTEBOOK (window->priv->notebook));
+ nautilus_notebook_next_page (NAUTILUS_NOTEBOOK (window->priv->notebook));
}
static void
action_tab_move_left (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), -1);
+ nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), -1);
}
static void
action_tab_move_right (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), 1);
+ nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), 1);
}
static void
action_go_to_tab (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+ GVariant *value,
+ gpointer user_data)
{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- GtkNotebook *notebook;
- gint16 num;
+ NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+ GtkNotebook *notebook;
+ gint16 num;
- notebook = GTK_NOTEBOOK (window->priv->notebook);
+ notebook = GTK_NOTEBOOK (window->priv->notebook);
- num = g_variant_get_int32 (value);
- if (num < gtk_notebook_get_n_pages (notebook)) {
- gtk_notebook_set_current_page (notebook, num);
- }
+ num = g_variant_get_int32 (value);
+ if (num < gtk_notebook_get_n_pages (notebook))
+ {
+ gtk_notebook_set_current_page (notebook, num);
+ }
}
static void
action_prompt_for_location_root (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
- GFile *location;
- GtkWidget *entry;
+ NautilusWindow *window = user_data;
+ GFile *location;
+ GtkWidget *entry;
- location = g_file_new_for_path ("/");
- entry = nautilus_window_ensure_location_entry (window);
- nautilus_location_entry_set_location (NAUTILUS_LOCATION_ENTRY (entry), location);
+ location = g_file_new_for_path ("/");
+ entry = nautilus_window_ensure_location_entry (window);
+ nautilus_location_entry_set_location (NAUTILUS_LOCATION_ENTRY (entry), location);
- g_object_unref (location);
+ g_object_unref (location);
}
static void
action_prompt_for_location_home (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- GtkWidget *entry;
+ GtkWidget *entry;
- entry = nautilus_window_ensure_location_entry (NAUTILUS_WINDOW (user_data));
- nautilus_location_entry_set_special_text (NAUTILUS_LOCATION_ENTRY (entry),
- "~");
- gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+ entry = nautilus_window_ensure_location_entry (NAUTILUS_WINDOW (user_data));
+ nautilus_location_entry_set_special_text (NAUTILUS_LOCATION_ENTRY (entry),
+ "~");
+ gtk_editable_set_position (GTK_EDITABLE (entry), -1);
}
static void
action_redo (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_file_undo_manager_redo (GTK_WINDOW (window));
+ nautilus_file_undo_manager_redo (GTK_WINDOW (window));
}
static void
action_undo (GSimpleAction *action,
- GVariant *state,
- gpointer user_data)
+ GVariant *state,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_file_undo_manager_undo (GTK_WINDOW (window));
+ nautilus_file_undo_manager_undo (GTK_WINDOW (window));
}
static void
@@ -418,19 +426,19 @@ action_toggle_state_view_button (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
- GVariant *current_state;
+ GVariant *current_state;
- current_state = g_action_get_state (G_ACTION (action));
- g_action_change_state (G_ACTION (action),
- g_variant_new_boolean (!g_variant_get_boolean (current_state)));
- g_variant_unref (current_state);
+ current_state = g_action_get_state (G_ACTION (action));
+ g_action_change_state (G_ACTION (action),
+ g_variant_new_boolean (!g_variant_get_boolean (current_state)));
+ g_variant_unref (current_state);
}
static void
on_location_changed (NautilusWindow *window)
{
- gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
- nautilus_window_slot_get_location (nautilus_window_get_active_slot (window)));
+ gtk_places_sidebar_set_location (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+ nautilus_window_slot_get_location (nautilus_window_get_active_slot (window)));
}
static void
@@ -438,74 +446,80 @@ on_slot_location_changed (NautilusWindowSlot *slot,
GParamSpec *pspec,
NautilusWindow *window)
{
- if (nautilus_window_get_active_slot (window) == slot)
- on_location_changed (window);
+ if (nautilus_window_get_active_slot (window) == slot)
+ {
+ on_location_changed (window);
+ }
}
static void
notebook_switch_page_cb (GtkNotebook *notebook,
- GtkWidget *page,
- unsigned int page_num,
- NautilusWindow *window)
+ GtkWidget *page,
+ unsigned int page_num,
+ NautilusWindow *window)
{
- NautilusWindowSlot *slot;
- GtkWidget *widget;
+ NautilusWindowSlot *slot;
+ GtkWidget *widget;
- widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->priv->notebook), page_num);
- g_assert (widget != NULL);
+ widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (window->priv->notebook), page_num);
+ g_assert (widget != NULL);
- /* find slot corresponding to the target page */
- slot = NAUTILUS_WINDOW_SLOT (widget);
- g_assert (slot != NULL);
+ /* find slot corresponding to the target page */
+ slot = NAUTILUS_WINDOW_SLOT (widget);
+ g_assert (slot != NULL);
- nautilus_window_set_active_slot (nautilus_window_slot_get_window (slot),
- slot);
+ nautilus_window_set_active_slot (nautilus_window_slot_get_window (slot),
+ slot);
}
static void
connect_slot (NautilusWindow *window,
NautilusWindowSlot *slot)
{
- g_signal_connect (slot, "notify::location",
- G_CALLBACK (on_slot_location_changed), window);
+ g_signal_connect (slot, "notify::location",
+ G_CALLBACK (on_slot_location_changed), window);
}
static void
disconnect_slot (NautilusWindow *window,
NautilusWindowSlot *slot)
{
- g_signal_handlers_disconnect_by_data (slot, window);
+ g_signal_handlers_disconnect_by_data (slot, window);
}
static NautilusWindowSlot *
nautilus_window_create_slot (NautilusWindow *window,
GFile *location)
{
- return NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS(window))->create_slot (window, location);
+ return NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->create_slot (window, location);
}
static NautilusWindowSlot *
real_create_slot (NautilusWindow *window,
GFile *location)
{
- NautilusFile *file = NULL;
- NautilusWindowSlot *slot;
+ NautilusFile *file = NULL;
+ NautilusWindowSlot *slot;
- if (location) {
- file = nautilus_file_get (location);
- }
- /* If not file, assume we open the home directory. We will switch eventually
- * to a different location if not.
- */
- if (file && nautilus_file_is_other_locations (file)) {
- slot = NAUTILUS_WINDOW_SLOT (nautilus_other_locations_window_slot_new (window));
- } else {
- slot = nautilus_window_slot_new (window);
- }
+ if (location)
+ {
+ file = nautilus_file_get (location);
+ }
+ /* If not file, assume we open the home directory. We will switch eventually
+ * to a different location if not.
+ */
+ if (file && nautilus_file_is_other_locations (file))
+ {
+ slot = NAUTILUS_WINDOW_SLOT (nautilus_other_locations_window_slot_new (window));
+ }
+ else
+ {
+ slot = nautilus_window_slot_new (window);
+ }
- nautilus_file_unref (file);
+ nautilus_file_unref (file);
- return slot;
+ return slot;
}
static NautilusWindowSlot *
@@ -513,17 +527,18 @@ replace_active_slot (NautilusWindow *window,
GFile *location,
NautilusWindowOpenFlags flags)
{
- NautilusWindowSlot *new_slot;
- NautilusWindowSlot *active_slot;
+ NautilusWindowSlot *new_slot;
+ NautilusWindowSlot *active_slot;
- new_slot = nautilus_window_create_slot (window, location);
- nautilus_window_initialize_slot (window, new_slot, flags);
- active_slot = nautilus_window_get_active_slot (window);
- if (active_slot) {
- close_slot (window, active_slot, TRUE);
- }
+ new_slot = nautilus_window_create_slot (window, location);
+ nautilus_window_initialize_slot (window, new_slot, flags);
+ active_slot = nautilus_window_get_active_slot (window);
+ if (active_slot)
+ {
+ close_slot (window, active_slot, TRUE);
+ }
- return new_slot;
+ return new_slot;
}
void
@@ -531,26 +546,26 @@ nautilus_window_initialize_slot (NautilusWindow *window,
NautilusWindowSlot *slot,
NautilusWindowOpenFlags flags)
{
- g_assert (NAUTILUS_IS_WINDOW (window));
- g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
+ g_assert (NAUTILUS_IS_WINDOW (window));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
- connect_slot (window, slot);
+ connect_slot (window, slot);
- g_signal_handlers_block_by_func (window->priv->notebook,
- G_CALLBACK (notebook_switch_page_cb),
- window);
- nautilus_notebook_add_tab (NAUTILUS_NOTEBOOK (window->priv->notebook),
- slot,
- (flags & NAUTILUS_WINDOW_OPEN_SLOT_APPEND) != 0 ?
- -1 :
- gtk_notebook_get_current_page (GTK_NOTEBOOK (window->priv->notebook)) + 1,
- FALSE);
- g_signal_handlers_unblock_by_func (window->priv->notebook,
- G_CALLBACK (notebook_switch_page_cb),
- window);
+ g_signal_handlers_block_by_func (window->priv->notebook,
+ G_CALLBACK (notebook_switch_page_cb),
+ window);
+ nautilus_notebook_add_tab (NAUTILUS_NOTEBOOK (window->priv->notebook),
+ slot,
+ (flags & NAUTILUS_WINDOW_OPEN_SLOT_APPEND) != 0 ?
+ -1 :
+ gtk_notebook_get_current_page (GTK_NOTEBOOK (window->priv->notebook)) + 1,
+ FALSE);
+ g_signal_handlers_unblock_by_func (window->priv->notebook,
+ G_CALLBACK (notebook_switch_page_cb),
+ window);
- window->priv->slots = g_list_append (window->priv->slots, slot);
- g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
+ window->priv->slots = g_list_append (window->priv->slots, slot);
+ g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
}
void
@@ -560,271 +575,300 @@ nautilus_window_open_location_full (NautilusWindow *window,
GList *selection,
NautilusWindowSlot *target_slot)
{
- NautilusWindowSlot *active_slot;
- gboolean new_tab_at_end;
+ NautilusWindowSlot *active_slot;
+ gboolean new_tab_at_end;
- /* The location owner can be one of the slots requesting to handle an
- * unhandled location. But this slot can be destroyed when switching to
- * a new slot. So keep the location alive.
- */
- g_object_ref (location);
-
- /* Assert that we are not managing new windows */
- g_assert (! (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW));
- /* if the flags say we want a new tab, open a slot in the current window */
- if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0) {
- new_tab_at_end = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION) == NAUTILUS_NEW_TAB_POSITION_END;
- if (new_tab_at_end)
- flags |= NAUTILUS_WINDOW_OPEN_SLOT_APPEND;
- }
-
- active_slot = nautilus_window_get_active_slot (window);
- if (!target_slot)
- target_slot = active_slot;
-
- if (target_slot == NULL || (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0) {
- target_slot = nautilus_window_create_slot (window, location);
- nautilus_window_initialize_slot (window, target_slot, flags);
- } else if (!nautilus_window_slot_handles_location (target_slot, location)) {
- target_slot = replace_active_slot (window, location, flags);
- }
+ /* The location owner can be one of the slots requesting to handle an
+ * unhandled location. But this slot can be destroyed when switching to
+ * a new slot. So keep the location alive.
+ */
+ g_object_ref (location);
- /* Make the opened location the one active if we weren't ask for the
- * oposite, since it's the most usual use case */
- if (!(flags & NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE)) {
- gtk_window_present (GTK_WINDOW (window));
- nautilus_window_set_active_slot (window, target_slot);
+ /* Assert that we are not managing new windows */
+ g_assert (!(flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW));
+ /* if the flags say we want a new tab, open a slot in the current window */
+ if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0)
+ {
+ new_tab_at_end = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION) == NAUTILUS_NEW_TAB_POSITION_END;
+ if (new_tab_at_end)
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_SLOT_APPEND;
}
+ }
+
+ active_slot = nautilus_window_get_active_slot (window);
+ if (!target_slot)
+ {
+ target_slot = active_slot;
+ }
- nautilus_window_slot_open_location_full (target_slot, location, flags, selection);
+ if (target_slot == NULL || (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0)
+ {
+ target_slot = nautilus_window_create_slot (window, location);
+ nautilus_window_initialize_slot (window, target_slot, flags);
+ }
+ else if (!nautilus_window_slot_handles_location (target_slot, location))
+ {
+ target_slot = replace_active_slot (window, location, flags);
+ }
- g_object_unref (location);
+ /* Make the opened location the one active if we weren't ask for the
+ * oposite, since it's the most usual use case */
+ if (!(flags & NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE))
+ {
+ gtk_window_present (GTK_WINDOW (window));
+ nautilus_window_set_active_slot (window, target_slot);
+ }
+
+ nautilus_window_slot_open_location_full (target_slot, location, flags, selection);
+
+ g_object_unref (location);
}
static int
-bookmark_list_get_uri_index (GList *list, GFile *location)
+bookmark_list_get_uri_index (GList *list,
+ GFile *location)
{
- NautilusBookmark *bookmark;
- GList *l;
- GFile *tmp;
- int i;
+ NautilusBookmark *bookmark;
+ GList *l;
+ GFile *tmp;
+ int i;
- g_return_val_if_fail (location != NULL, -1);
+ g_return_val_if_fail (location != NULL, -1);
- for (i = 0, l = list; l != NULL; i++, l = l->next) {
- bookmark = NAUTILUS_BOOKMARK (l->data);
+ for (i = 0, l = list; l != NULL; i++, l = l->next)
+ {
+ bookmark = NAUTILUS_BOOKMARK (l->data);
- tmp = nautilus_bookmark_get_location (bookmark);
- if (g_file_equal (location, tmp)) {
- g_object_unref (tmp);
- return i;
- }
- g_object_unref (tmp);
- }
+ tmp = nautilus_bookmark_get_location (bookmark);
+ if (g_file_equal (location, tmp))
+ {
+ g_object_unref (tmp);
+ return i;
+ }
+ g_object_unref (tmp);
+ }
- return -1;
+ return -1;
}
static void
unset_focus_widget (NautilusWindow *window)
{
- if (window->priv->last_focus_widget != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (window->priv->last_focus_widget),
- (gpointer *) &window->priv->last_focus_widget);
- window->priv->last_focus_widget = NULL;
- }
+ if (window->priv->last_focus_widget != NULL)
+ {
+ g_object_remove_weak_pointer (G_OBJECT (window->priv->last_focus_widget),
+ (gpointer *) &window->priv->last_focus_widget);
+ window->priv->last_focus_widget = NULL;
+ }
}
static void
remember_focus_widget (NautilusWindow *window)
{
- GtkWidget *focus_widget;
+ GtkWidget *focus_widget;
- focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
- if (focus_widget != NULL) {
- unset_focus_widget (window);
+ focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
+ if (focus_widget != NULL)
+ {
+ unset_focus_widget (window);
- window->priv->last_focus_widget = focus_widget;
- g_object_add_weak_pointer (G_OBJECT (focus_widget),
- (gpointer *) &(window->priv->last_focus_widget));
- }
+ window->priv->last_focus_widget = focus_widget;
+ g_object_add_weak_pointer (G_OBJECT (focus_widget),
+ (gpointer *) &(window->priv->last_focus_widget));
+ }
}
static void
nautilus_window_grab_focus (GtkWidget *widget)
{
- NautilusWindowSlot *slot;
+ NautilusWindowSlot *slot;
- slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (widget));
+ slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (widget));
- GTK_WIDGET_CLASS (nautilus_window_parent_class)->grab_focus (widget);
+ GTK_WIDGET_CLASS (nautilus_window_parent_class)->grab_focus (widget);
- if (slot) {
- gtk_widget_grab_focus (GTK_WIDGET (slot));
- }
+ if (slot)
+ {
+ gtk_widget_grab_focus (GTK_WIDGET (slot));
+ }
}
static void
restore_focus_widget (NautilusWindow *window)
{
- if (window->priv->last_focus_widget != NULL) {
- gtk_widget_grab_focus (window->priv->last_focus_widget);
- unset_focus_widget (window);
- }
+ if (window->priv->last_focus_widget != NULL)
+ {
+ gtk_widget_grab_focus (window->priv->last_focus_widget);
+ unset_focus_widget (window);
+ }
}
static void
location_entry_cancel_callback (GtkWidget *widget,
- NautilusWindow *window)
+ NautilusWindow *window)
{
- nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), FALSE);
+ nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), FALSE);
- restore_focus_widget (window);
+ restore_focus_widget (window);
}
static void
location_entry_location_changed_callback (GtkWidget *widget,
- GFile *location,
- NautilusWindow *window)
+ GFile *location,
+ NautilusWindow *window)
{
- nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), FALSE);
+ nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), FALSE);
- restore_focus_widget (window);
+ restore_focus_widget (window);
- nautilus_window_open_location_full (window, location, 0, NULL, NULL);
+ nautilus_window_open_location_full (window, location, 0, NULL, NULL);
}
static void
close_slot (NautilusWindow *window,
- NautilusWindowSlot *slot,
- gboolean remove_from_notebook)
+ NautilusWindowSlot *slot,
+ gboolean remove_from_notebook)
{
- int page_num;
- GtkNotebook *notebook;
+ int page_num;
+ GtkNotebook *notebook;
- g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
+ g_assert (NAUTILUS_IS_WINDOW_SLOT (slot));
- DEBUG ("Closing slot %p", slot);
+ DEBUG ("Closing slot %p", slot);
- disconnect_slot (window, slot);
+ disconnect_slot (window, slot);
- window->priv->slots = g_list_remove (window->priv->slots, slot);
+ window->priv->slots = g_list_remove (window->priv->slots, slot);
- g_signal_emit (window, signals[SLOT_REMOVED], 0, slot);
+ g_signal_emit (window, signals[SLOT_REMOVED], 0, slot);
- notebook = GTK_NOTEBOOK (window->priv->notebook);
+ notebook = GTK_NOTEBOOK (window->priv->notebook);
- if (remove_from_notebook) {
- page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (slot));
- g_assert (page_num >= 0);
+ if (remove_from_notebook)
+ {
+ page_num = gtk_notebook_page_num (notebook, GTK_WIDGET (slot));
+ g_assert (page_num >= 0);
- /* this will call gtk_widget_destroy on the slot */
- gtk_notebook_remove_page (notebook, page_num);
- }
+ /* this will call gtk_widget_destroy on the slot */
+ gtk_notebook_remove_page (notebook, page_num);
+ }
}
void
nautilus_window_new_tab (NautilusWindow *window)
{
- NautilusWindowSlot *current_slot;
- NautilusWindowOpenFlags flags;
- GFile *location;
- char *scheme;
+ NautilusWindowSlot *current_slot;
+ NautilusWindowOpenFlags flags;
+ GFile *location;
+ char *scheme;
- current_slot = nautilus_window_get_active_slot (window);
- location = nautilus_window_slot_get_location (current_slot);
+ current_slot = nautilus_window_get_active_slot (window);
+ location = nautilus_window_slot_get_location (current_slot);
- if (location != NULL) {
- flags = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION);
+ if (location != NULL)
+ {
+ flags = g_settings_get_enum (nautilus_preferences, NAUTILUS_PREFERENCES_NEW_TAB_POSITION);
- scheme = g_file_get_uri_scheme (location);
- if (strcmp (scheme, "x-nautilus-search") == 0) {
- location = g_file_new_for_path (g_get_home_dir ());
- } else {
- g_object_ref (location);
- }
+ scheme = g_file_get_uri_scheme (location);
+ if (strcmp (scheme, "x-nautilus-search") == 0)
+ {
+ location = g_file_new_for_path (g_get_home_dir ());
+ }
+ else
+ {
+ g_object_ref (location);
+ }
- g_free (scheme);
+ g_free (scheme);
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
- nautilus_window_open_location_full (window, location, flags, NULL, NULL);
- g_object_unref (location);
- }
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+ nautilus_window_open_location_full (window, location, flags, NULL, NULL);
+ g_object_unref (location);
+ }
}
static void
update_cursor (NautilusWindow *window)
{
- NautilusWindowSlot *slot;
- GdkCursor *cursor;
+ NautilusWindowSlot *slot;
+ GdkCursor *cursor;
- slot = nautilus_window_get_active_slot (window);
+ slot = nautilus_window_get_active_slot (window);
- if (nautilus_window_slot_get_allow_stop (slot)) {
- GdkDisplay *display;
+ if (nautilus_window_slot_get_allow_stop (slot))
+ {
+ GdkDisplay *display;
- display = gtk_widget_get_display (GTK_WIDGET (window));
- cursor = gdk_cursor_new_from_name (display, "progress");
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), cursor);
- g_object_unref (cursor);
- } else {
- gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
- }
+ display = gtk_widget_get_display (GTK_WIDGET (window));
+ cursor = gdk_cursor_new_from_name (display, "progress");
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), cursor);
+ g_object_unref (cursor);
+ }
+ else
+ {
+ gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (window)), NULL);
+ }
}
void
nautilus_window_hide_view_menu (NautilusWindow *window)
{
- GAction *menu_action;
+ GAction *menu_action;
- menu_action = g_action_map_lookup_action (G_ACTION_MAP (window), "view-menu");
- g_action_change_state (menu_action, g_variant_new_boolean (FALSE));
+ menu_action = g_action_map_lookup_action (G_ACTION_MAP (window), "view-menu");
+ g_action_change_state (menu_action, g_variant_new_boolean (FALSE));
}
void
nautilus_window_reset_menus (NautilusWindow *window)
{
- nautilus_window_sync_allow_stop (window, nautilus_window_get_active_slot (window));
+ nautilus_window_sync_allow_stop (window, nautilus_window_get_active_slot (window));
}
void
-nautilus_window_sync_allow_stop (NautilusWindow *window,
- NautilusWindowSlot *slot)
-{
- GAction *stop_action;
- GAction *reload_action;
- gboolean allow_stop, slot_is_active, slot_allow_stop;
-
- stop_action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "stop");
- reload_action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "reload");
- allow_stop = g_action_get_enabled (stop_action);
-
- slot_allow_stop = nautilus_window_slot_get_allow_stop (slot);
- slot_is_active = (slot == nautilus_window_get_active_slot (window));
-
- if (!slot_is_active ||
- allow_stop != slot_allow_stop) {
- if (slot_is_active) {
- g_simple_action_set_enabled (G_SIMPLE_ACTION (stop_action), slot_allow_stop);
- g_simple_action_set_enabled (G_SIMPLE_ACTION (reload_action), !slot_allow_stop);
- }
- if (gtk_widget_get_realized (GTK_WIDGET (window))) {
- update_cursor (window);
- }
-
- /* Avoid updating the notebook if we are calling on dispose or
- * on removal of a notebook tab */
- if (nautilus_notebook_contains_slot (NAUTILUS_NOTEBOOK (window->priv->notebook), slot))
- nautilus_notebook_sync_loading (NAUTILUS_NOTEBOOK (window->priv->notebook), slot);
- }
+nautilus_window_sync_allow_stop (NautilusWindow *window,
+ NautilusWindowSlot *slot)
+{
+ GAction *stop_action;
+ GAction *reload_action;
+ gboolean allow_stop, slot_is_active, slot_allow_stop;
+
+ stop_action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "stop");
+ reload_action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "reload");
+ allow_stop = g_action_get_enabled (stop_action);
+
+ slot_allow_stop = nautilus_window_slot_get_allow_stop (slot);
+ slot_is_active = (slot == nautilus_window_get_active_slot (window));
+
+ if (!slot_is_active ||
+ allow_stop != slot_allow_stop)
+ {
+ if (slot_is_active)
+ {
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (stop_action), slot_allow_stop);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (reload_action), !slot_allow_stop);
+ }
+ if (gtk_widget_get_realized (GTK_WIDGET (window)))
+ {
+ update_cursor (window);
+ }
+
+ /* Avoid updating the notebook if we are calling on dispose or
+ * on removal of a notebook tab */
+ if (nautilus_notebook_contains_slot (NAUTILUS_NOTEBOOK (window->priv->notebook), slot))
+ {
+ nautilus_notebook_sync_loading (NAUTILUS_NOTEBOOK (window->priv->notebook), slot);
+ }
+ }
}
GtkWidget *
nautilus_window_get_notebook (NautilusWindow *window)
{
- return window->priv->notebook;
+ return window->priv->notebook;
}
/* Code should never force the window taller than this size.
@@ -833,7 +877,7 @@ nautilus_window_get_notebook (NautilusWindow *window)
static guint
get_max_forced_height (GdkScreen *screen)
{
- return (gdk_screen_get_height (screen) * 90) / 100;
+ return (gdk_screen_get_height (screen) * 90) / 100;
}
/* Code should never force the window wider than this size.
@@ -842,7 +886,7 @@ get_max_forced_height (GdkScreen *screen)
static guint
get_max_forced_width (GdkScreen *screen)
{
- return (gdk_screen_get_width (screen) * 90) / 100;
+ return (gdk_screen_get_width (screen) * 90) / 100;
}
/* This must be called when construction of NautilusWindow is finished,
@@ -852,76 +896,78 @@ get_max_forced_width (GdkScreen *screen)
static void
nautilus_window_set_initial_window_geometry (NautilusWindow *window)
{
- GdkScreen *screen;
- guint max_width_for_screen, max_height_for_screen;
- guint default_width, default_height;
+ GdkScreen *screen;
+ guint max_width_for_screen, max_height_for_screen;
+ guint default_width, default_height;
- screen = gtk_window_get_screen (GTK_WINDOW (window));
-
- max_width_for_screen = get_max_forced_width (screen);
- max_height_for_screen = get_max_forced_height (screen);
-
- default_width = NAUTILUS_WINDOW_DEFAULT_WIDTH;
- default_height = NAUTILUS_WINDOW_DEFAULT_HEIGHT;
+ screen = gtk_window_get_screen (GTK_WINDOW (window));
- gtk_window_set_default_size (GTK_WINDOW (window),
- MIN (default_width,
- max_width_for_screen),
- MIN (default_height,
- max_height_for_screen));
+ max_width_for_screen = get_max_forced_width (screen);
+ max_height_for_screen = get_max_forced_height (screen);
+
+ default_width = NAUTILUS_WINDOW_DEFAULT_WIDTH;
+ default_height = NAUTILUS_WINDOW_DEFAULT_HEIGHT;
+
+ gtk_window_set_default_size (GTK_WINDOW (window),
+ MIN (default_width,
+ max_width_for_screen),
+ MIN (default_height,
+ max_height_for_screen));
}
static gboolean
save_sidebar_width_cb (gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- window->priv->sidebar_width_handler_id = 0;
+ window->priv->sidebar_width_handler_id = 0;
- DEBUG ("Saving sidebar width: %d", window->priv->side_pane_width);
+ DEBUG ("Saving sidebar width: %d", window->priv->side_pane_width);
- g_settings_set_int (nautilus_window_state,
- NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH,
- window->priv->side_pane_width);
+ g_settings_set_int (nautilus_window_state,
+ NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH,
+ window->priv->side_pane_width);
- return FALSE;
+ return FALSE;
}
/* side pane helpers */
static void
-side_pane_size_allocate_callback (GtkWidget *widget,
- GtkAllocation *allocation,
- gpointer user_data)
+side_pane_size_allocate_callback (GtkWidget *widget,
+ GtkAllocation *allocation,
+ gpointer user_data)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = user_data;
+ window = user_data;
- if (window->priv->sidebar_width_handler_id != 0) {
- g_source_remove (window->priv->sidebar_width_handler_id);
- window->priv->sidebar_width_handler_id = 0;
- }
+ if (window->priv->sidebar_width_handler_id != 0)
+ {
+ g_source_remove (window->priv->sidebar_width_handler_id);
+ window->priv->sidebar_width_handler_id = 0;
+ }
- if (allocation->width != window->priv->side_pane_width &&
- allocation->width > 1) {
- window->priv->side_pane_width = allocation->width;
+ if (allocation->width != window->priv->side_pane_width &&
+ allocation->width > 1)
+ {
+ window->priv->side_pane_width = allocation->width;
- window->priv->sidebar_width_handler_id =
- g_idle_add (save_sidebar_width_cb, window);
- }
+ window->priv->sidebar_width_handler_id =
+ g_idle_add (save_sidebar_width_cb, window);
+ }
}
static void
setup_side_pane_width (NautilusWindow *window)
{
- g_return_if_fail (window->priv->sidebar != NULL);
+ g_return_if_fail (window->priv->sidebar != NULL);
- window->priv->side_pane_width =
- g_settings_get_int (nautilus_window_state,
- NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH);
+ window->priv->side_pane_width =
+ g_settings_get_int (nautilus_window_state,
+ NAUTILUS_WINDOW_STATE_SIDEBAR_WIDTH);
- gtk_paned_set_position (GTK_PANED (window->priv->content_paned),
- window->priv->side_pane_width);
+ gtk_paned_set_position (GTK_PANED (window->priv->content_paned),
+ window->priv->side_pane_width);
}
/* Callback used when the places sidebar changes location; we need to change the displayed folder */
@@ -930,88 +976,95 @@ open_location_cb (NautilusWindow *window,
GFile *location,
GtkPlacesOpenFlags open_flags)
{
- NautilusWindowOpenFlags flags;
+ NautilusWindowOpenFlags flags;
- switch (open_flags) {
- case GTK_PLACES_OPEN_NEW_TAB:
- flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB |
- NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
- break;
+ switch (open_flags)
+ {
+ case GTK_PLACES_OPEN_NEW_TAB:
+ {
+ flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB |
+ NAUTILUS_WINDOW_OPEN_FLAG_DONT_MAKE_ACTIVE;
+ }
+ break;
- case GTK_PLACES_OPEN_NEW_WINDOW:
- flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
- break;
+ case GTK_PLACES_OPEN_NEW_WINDOW:
+ {
+ flags = NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
+ }
+ break;
- case GTK_PLACES_OPEN_NORMAL: /* fall-through */
- default:
- flags = 0;
- break;
- }
+ case GTK_PLACES_OPEN_NORMAL: /* fall-through */
+ default:
+ {
+ flags = 0;
+ }
+ break;
+ }
- /* FIXME: We shouldn't need to provide the window, but seems gtk_application_get_active_window
- * is not working properly in GtkApplication, so we cannot rely on that...
- */
- nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
- location, flags, NULL, window, NULL);
+ /* FIXME: We shouldn't need to provide the window, but seems gtk_application_get_active_window
+ * is not working properly in GtkApplication, so we cannot rely on that...
+ */
+ nautilus_application_open_location_full (NAUTILUS_APPLICATION (g_application_get_default ()),
+ location, flags, NULL, window, NULL);
}
static void
notify_unmount_done (GMountOperation *op,
const gchar *message)
{
- NautilusApplication *application;
- gchar *notification_id;
+ NautilusApplication *application;
+ gchar *notification_id;
- application = nautilus_application_get_default ();
- notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
- nautilus_application_withdraw_notification (application, notification_id);
+ application = nautilus_application_get_default ();
+ notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
+ nautilus_application_withdraw_notification (application, notification_id);
- if (message != NULL)
+ if (message != NULL)
{
- GNotification *unplug;
- GIcon *icon;
- gchar **strings;
-
- strings = g_strsplit (message, "\n", 0);
- icon = g_themed_icon_new ("media-removable");
- unplug = g_notification_new (strings[0]);
- g_notification_set_body (unplug, strings[1]);
- g_notification_set_icon (unplug, icon);
-
- nautilus_application_send_notification (application, notification_id, unplug);
- g_object_unref (unplug);
- g_object_unref (icon);
- g_strfreev (strings);
+ GNotification *unplug;
+ GIcon *icon;
+ gchar **strings;
+
+ strings = g_strsplit (message, "\n", 0);
+ icon = g_themed_icon_new ("media-removable");
+ unplug = g_notification_new (strings[0]);
+ g_notification_set_body (unplug, strings[1]);
+ g_notification_set_icon (unplug, icon);
+
+ nautilus_application_send_notification (application, notification_id, unplug);
+ g_object_unref (unplug);
+ g_object_unref (icon);
+ g_strfreev (strings);
}
- g_free (notification_id);
+ g_free (notification_id);
}
static void
notify_unmount_show (GMountOperation *op,
const gchar *message)
{
- NautilusApplication *application;
- GNotification *unmount;
- gchar *notification_id;
- GIcon *icon;
- gchar **strings;
+ NautilusApplication *application;
+ GNotification *unmount;
+ gchar *notification_id;
+ GIcon *icon;
+ gchar **strings;
- application = nautilus_application_get_default ();
- strings = g_strsplit (message, "\n", 0);
- icon = g_themed_icon_new ("media-removable");
+ application = nautilus_application_get_default ();
+ strings = g_strsplit (message, "\n", 0);
+ icon = g_themed_icon_new ("media-removable");
- unmount = g_notification_new (strings[0]);
- g_notification_set_body (unmount, strings[1]);
- g_notification_set_icon (unmount, icon);
- g_notification_set_priority (unmount, G_NOTIFICATION_PRIORITY_URGENT);
+ unmount = g_notification_new (strings[0]);
+ g_notification_set_body (unmount, strings[1]);
+ g_notification_set_icon (unmount, icon);
+ g_notification_set_priority (unmount, G_NOTIFICATION_PRIORITY_URGENT);
- notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
- nautilus_application_send_notification (application, notification_id, unmount);
- g_object_unref (unmount);
- g_object_unref (icon);
- g_strfreev (strings);
- g_free (notification_id);
+ notification_id = g_strdup_printf ("nautilus-mount-operation-%p", op);
+ nautilus_application_send_notification (application, notification_id, unmount);
+ g_object_unref (unmount);
+ g_object_unref (icon);
+ g_strfreev (strings);
+ g_free (notification_id);
}
static void
@@ -1021,180 +1074,192 @@ show_unmount_progress_cb (GMountOperation *op,
gint64 bytes_left,
gpointer user_data)
{
- if (bytes_left == 0)
- notify_unmount_done (op, message);
- else
- notify_unmount_show (op, message);
+ if (bytes_left == 0)
+ {
+ notify_unmount_done (op, message);
+ }
+ else
+ {
+ notify_unmount_show (op, message);
+ }
}
static void
show_unmount_progress_aborted_cb (GMountOperation *op,
gpointer user_data)
{
- notify_unmount_done (op, NULL);
+ notify_unmount_done (op, NULL);
}
static void
places_sidebar_unmount_operation_cb (NautilusWindow *window,
- GMountOperation *mount_operation)
+ GMountOperation *mount_operation)
{
- g_signal_connect (mount_operation, "show-unmount-progress",
- G_CALLBACK (show_unmount_progress_cb), NULL);
- g_signal_connect (mount_operation, "aborted",
- G_CALLBACK (show_unmount_progress_aborted_cb), NULL);
+ g_signal_connect (mount_operation, "show-unmount-progress",
+ G_CALLBACK (show_unmount_progress_cb), NULL);
+ g_signal_connect (mount_operation, "aborted",
+ G_CALLBACK (show_unmount_progress_aborted_cb), NULL);
}
/* Callback used when the places sidebar needs us to present an error message */
static void
places_sidebar_show_error_message_cb (GtkPlacesSidebar *sidebar,
- const char *primary,
- const char *secondary,
- gpointer user_data)
+ const char *primary,
+ const char *secondary,
+ gpointer user_data)
{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+ NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- eel_show_error_dialog (primary, secondary, GTK_WINDOW (window));
+ eel_show_error_dialog (primary, secondary, GTK_WINDOW (window));
}
static void
places_sidebar_show_other_locations_with_flags (NautilusWindow *window,
GtkPlacesOpenFlags open_flags)
{
- GFile *location;
+ GFile *location;
- location = g_file_new_for_uri ("other-locations:///");
+ location = g_file_new_for_uri ("other-locations:///");
- open_location_cb (window, location, open_flags);
+ open_location_cb (window, location, open_flags);
- g_object_unref (location);
+ g_object_unref (location);
}
static GList *
build_selection_list_from_gfile_list (GList *gfile_list)
{
- GList *result;
- GList *l;
+ GList *result;
+ GList *l;
- result = NULL;
- for (l = gfile_list; l; l = l->next) {
- GFile *file;
- NautilusDragSelectionItem *item;
+ result = NULL;
+ for (l = gfile_list; l; l = l->next)
+ {
+ GFile *file;
+ NautilusDragSelectionItem *item;
- file = l->data;
+ file = l->data;
- item = nautilus_drag_selection_item_new ();
- item->uri = g_file_get_uri (file);
- item->file = nautilus_file_get_existing (file);
- item->got_icon_position = FALSE;
- result = g_list_prepend (result, item);
- }
+ item = nautilus_drag_selection_item_new ();
+ item->uri = g_file_get_uri (file);
+ item->file = nautilus_file_get_existing (file);
+ item->got_icon_position = FALSE;
+ result = g_list_prepend (result, item);
+ }
- return g_list_reverse (result);
+ return g_list_reverse (result);
}
void
nautilus_window_start_dnd (NautilusWindow *window,
GdkDragContext *context)
{
- gtk_places_sidebar_set_drop_targets_visible (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
- TRUE,
- context);
+ gtk_places_sidebar_set_drop_targets_visible (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+ TRUE,
+ context);
}
void
nautilus_window_end_dnd (NautilusWindow *window,
GdkDragContext *context)
{
- gtk_places_sidebar_set_drop_targets_visible (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
- FALSE,
- context);
+ gtk_places_sidebar_set_drop_targets_visible (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+ FALSE,
+ context);
}
/* Callback used when the places sidebar needs to know the drag action to suggest */
static GdkDragAction
places_sidebar_drag_action_requested_cb (GtkPlacesSidebar *sidebar,
- GdkDragContext *context,
- GFile *dest_file,
- GList *source_file_list,
- gpointer user_data)
-{
- GList *items;
- char *uri;
- int action = 0;
- NautilusDragInfo *info;
- guint32 source_actions;
-
- info = nautilus_drag_get_source_data (context);
- if (info != NULL) {
- items = info->selection_cache;
- source_actions = info->source_actions;
- } else {
- items = build_selection_list_from_gfile_list (source_file_list);
- source_actions = 0;
- }
- uri = g_file_get_uri (dest_file);
+ GdkDragContext *context,
+ GFile *dest_file,
+ GList *source_file_list,
+ gpointer user_data)
+{
+ GList *items;
+ char *uri;
+ int action = 0;
+ NautilusDragInfo *info;
+ guint32 source_actions;
+
+ info = nautilus_drag_get_source_data (context);
+ if (info != NULL)
+ {
+ items = info->selection_cache;
+ source_actions = info->source_actions;
+ }
+ else
+ {
+ items = build_selection_list_from_gfile_list (source_file_list);
+ source_actions = 0;
+ }
+ uri = g_file_get_uri (dest_file);
- if (g_list_length (items) < 1)
- goto out;
+ if (g_list_length (items) < 1)
+ {
+ goto out;
+ }
- nautilus_drag_default_drop_action_for_icons (context, uri, items, source_actions, &action);
+ nautilus_drag_default_drop_action_for_icons (context, uri, items, source_actions, &action);
out:
- if (info == NULL)
- nautilus_drag_destroy_selection_list (items);
+ if (info == NULL)
+ {
+ nautilus_drag_destroy_selection_list (items);
+ }
- g_free (uri);
+ g_free (uri);
- return action;
+ return action;
}
/* Callback used when the places sidebar needs us to pop up a menu with possible drag actions */
static GdkDragAction
places_sidebar_drag_action_ask_cb (GtkPlacesSidebar *sidebar,
- GdkDragAction actions,
- gpointer user_data)
+ GdkDragAction actions,
+ gpointer user_data)
{
- return nautilus_drag_drop_action_ask (GTK_WIDGET (sidebar), actions);
+ return nautilus_drag_drop_action_ask (GTK_WIDGET (sidebar), actions);
}
static GList *
build_uri_list_from_gfile_list (GList *file_list)
{
- GList *result;
- GList *l;
+ GList *result;
+ GList *l;
- result = NULL;
+ result = NULL;
- for (l = file_list; l; l = l->next) {
- GFile *file = l->data;
- char *uri;
+ for (l = file_list; l; l = l->next)
+ {
+ GFile *file = l->data;
+ char *uri;
- uri = g_file_get_uri (file);
- result = g_list_prepend (result, uri);
- }
+ uri = g_file_get_uri (file);
+ result = g_list_prepend (result, uri);
+ }
- return g_list_reverse (result);
-
+ return g_list_reverse (result);
}
/* Callback used when the places sidebar has URIs dropped into it. We do a normal file operation for them. */
static void
places_sidebar_drag_perform_drop_cb (GtkPlacesSidebar *sidebar,
- GFile *dest_file,
- GList *source_file_list,
- GdkDragAction action,
- gpointer user_data)
+ GFile *dest_file,
+ GList *source_file_list,
+ GdkDragAction action,
+ gpointer user_data)
{
- char *dest_uri;
- GList *source_uri_list;
+ char *dest_uri;
+ GList *source_uri_list;
- dest_uri = g_file_get_uri (dest_file);
- source_uri_list = build_uri_list_from_gfile_list (source_file_list);
+ dest_uri = g_file_get_uri (dest_file);
+ source_uri_list = build_uri_list_from_gfile_list (source_file_list);
- nautilus_file_operations_copy_move (source_uri_list, NULL, dest_uri, action, GTK_WIDGET (sidebar), NULL, NULL);
+ nautilus_file_operations_copy_move (source_uri_list, NULL, dest_uri, action, GTK_WIDGET (sidebar), NULL, NULL);
- g_free (dest_uri);
- g_list_free_full (source_uri_list, g_free);
+ g_free (dest_uri);
+ g_list_free_full (source_uri_list, g_free);
}
/* Callback used in the "empty trash" menu item from the places sidebar */
@@ -1203,9 +1268,9 @@ action_empty_trash (GSimpleAction *action,
GVariant *variant,
gpointer user_data)
{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+ NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- nautilus_file_operations_empty_trash (GTK_WIDGET (window));
+ nautilus_file_operations_empty_trash (GTK_WIDGET (window));
}
/* Callback used for the "properties" menu item from the places sidebar */
@@ -1214,43 +1279,43 @@ action_properties (GSimpleAction *action,
GVariant *variant,
gpointer user_data)
{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- GList *list;
- NautilusFile *file;
+ NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+ GList *list;
+ NautilusFile *file;
- file = nautilus_file_get (window->priv->selected_file);
+ file = nautilus_file_get (window->priv->selected_file);
- list = g_list_append (NULL, file);
- nautilus_properties_window_present (list, GTK_WIDGET (window), NULL);
- nautilus_file_list_free (list);
+ list = g_list_append (NULL, file);
+ nautilus_properties_window_present (list, GTK_WIDGET (window), NULL);
+ nautilus_file_list_free (list);
- g_clear_object (&window->priv->selected_file);
+ g_clear_object (&window->priv->selected_file);
}
static gboolean
check_have_gnome_disks (void)
{
- gchar *disks_path;
- gboolean res;
+ gchar *disks_path;
+ gboolean res;
- disks_path = g_find_program_in_path ("gnome-disks");
- res = (disks_path != NULL);
- g_free (disks_path);
+ disks_path = g_find_program_in_path ("gnome-disks");
+ res = (disks_path != NULL);
+ g_free (disks_path);
- return res;
+ return res;
}
static gboolean
should_show_format_command (GVolume *volume)
{
- gchar *unix_device_id;
- gboolean show_format;
+ gchar *unix_device_id;
+ gboolean show_format;
- unix_device_id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
- show_format = (unix_device_id != NULL) && check_have_gnome_disks ();
- g_free (unix_device_id);
+ unix_device_id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+ show_format = (unix_device_id != NULL) && check_have_gnome_disks ();
+ g_free (unix_device_id);
- return show_format;
+ return show_format;
}
static void
@@ -1258,429 +1323,455 @@ action_format (GSimpleAction *action,
GVariant *variant,
gpointer user_data)
{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- GAppInfo *app_info;
- gchar *cmdline, *device_identifier, *xid_string;
- gint xid;
+ NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+ GAppInfo *app_info;
+ gchar *cmdline, *device_identifier, *xid_string;
+ gint xid;
- device_identifier = g_volume_get_identifier (window->priv->selected_volume,
- G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
- xid = (gint) gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (window)));
- xid_string = g_strdup_printf ("%d", xid);
+ device_identifier = g_volume_get_identifier (window->priv->selected_volume,
+ G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+ xid = (gint) gdk_x11_window_get_xid (gtk_widget_get_window (GTK_WIDGET (window)));
+ xid_string = g_strdup_printf ("%d", xid);
- cmdline = g_strconcat ("gnome-disks ",
- "--block-device ", device_identifier, " ",
- "--format-device ",
- "--xid ", xid_string,
- NULL);
- app_info = g_app_info_create_from_commandline (cmdline, NULL, 0, NULL);
- g_app_info_launch (app_info, NULL, NULL, NULL);
+ cmdline = g_strconcat ("gnome-disks ",
+ "--block-device ", device_identifier, " ",
+ "--format-device ",
+ "--xid ", xid_string,
+ NULL);
+ app_info = g_app_info_create_from_commandline (cmdline, NULL, 0, NULL);
+ g_app_info_launch (app_info, NULL, NULL, NULL);
- g_free (cmdline);
- g_free (device_identifier);
- g_free (xid_string);
- g_clear_object (&app_info);
- g_clear_object (&window->priv->selected_volume);
+ g_free (cmdline);
+ g_free (device_identifier);
+ g_free (xid_string);
+ g_clear_object (&app_info);
+ g_clear_object (&window->priv->selected_volume);
}
static void
add_menu_separator (GtkWidget *menu)
{
- GtkWidget *separator;
+ GtkWidget *separator;
- separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- gtk_container_add (GTK_CONTAINER (menu), separator);
- gtk_widget_show (separator);
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_container_add (GTK_CONTAINER (menu), separator);
+ gtk_widget_show (separator);
}
static void
places_sidebar_populate_popup_cb (GtkPlacesSidebar *sidebar,
- GtkWidget *menu,
- GFile *selected_file,
- GVolume *selected_volume,
- gpointer user_data)
-{
- NautilusWindow *window = NAUTILUS_WINDOW (user_data);
- GFile *trash;
- GtkWidget *menu_item;
- GAction *action;
-
- g_clear_object (&window->priv->selected_file);
- g_clear_object (&window->priv->selected_volume);
-
- if (selected_file) {
- trash = g_file_new_for_uri ("trash:///");
- if (g_file_equal (trash, selected_file)) {
- add_menu_separator (menu);
-
- menu_item = gtk_model_button_new ();
- gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
- "win.empty-trash");
- g_object_set (menu_item, "text", _("Empty _Trash"), NULL);
- gtk_container_add (GTK_CONTAINER (menu), menu_item);
- gtk_widget_show (menu_item);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "empty-trash");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- !nautilus_trash_monitor_is_empty ());
- }
- g_object_unref (trash);
-
- if (g_file_is_native (selected_file)) {
- window->priv->selected_file = g_object_ref (selected_file);
- add_menu_separator (menu);
-
- menu_item = gtk_model_button_new ();
- gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
- "win.properties");
- g_object_set (menu_item, "text", _("_Properties"), NULL);
- gtk_container_add (GTK_CONTAINER (menu), menu_item);
- gtk_widget_show (menu_item);
- }
- }
- if (selected_volume) {
- if (should_show_format_command (selected_volume)) {
- menu_item = gtk_model_button_new ();
- gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
- "win.format");
- g_object_set (menu_item, "text", _("_Format…"), NULL);
- if (selected_volume != NULL && G_IS_VOLUME (selected_volume)) {
- window->priv->selected_volume = g_object_ref (selected_volume);
- }
- gtk_container_add (GTK_CONTAINER (menu), menu_item);
- gtk_widget_show (menu_item);
-
- action = g_action_map_lookup_action (G_ACTION_MAP (window),
- "format");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
- selected_volume != NULL &&
- G_IS_VOLUME (selected_volume));
- }
- }
+ GtkWidget *menu,
+ GFile *selected_file,
+ GVolume *selected_volume,
+ gpointer user_data)
+{
+ NautilusWindow *window = NAUTILUS_WINDOW (user_data);
+ GFile *trash;
+ GtkWidget *menu_item;
+ GAction *action;
+
+ g_clear_object (&window->priv->selected_file);
+ g_clear_object (&window->priv->selected_volume);
+
+ if (selected_file)
+ {
+ trash = g_file_new_for_uri ("trash:///");
+ if (g_file_equal (trash, selected_file))
+ {
+ add_menu_separator (menu);
+
+ menu_item = gtk_model_button_new ();
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
+ "win.empty-trash");
+ g_object_set (menu_item, "text", _("Empty _Trash"), NULL);
+ gtk_container_add (GTK_CONTAINER (menu), menu_item);
+ gtk_widget_show (menu_item);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "empty-trash");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ !nautilus_trash_monitor_is_empty ());
+ }
+ g_object_unref (trash);
+
+ if (g_file_is_native (selected_file))
+ {
+ window->priv->selected_file = g_object_ref (selected_file);
+ add_menu_separator (menu);
+
+ menu_item = gtk_model_button_new ();
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
+ "win.properties");
+ g_object_set (menu_item, "text", _("_Properties"), NULL);
+ gtk_container_add (GTK_CONTAINER (menu), menu_item);
+ gtk_widget_show (menu_item);
+ }
+ }
+ if (selected_volume)
+ {
+ if (should_show_format_command (selected_volume))
+ {
+ menu_item = gtk_model_button_new ();
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item),
+ "win.format");
+ g_object_set (menu_item, "text", _("_Format…"), NULL);
+ if (selected_volume != NULL && G_IS_VOLUME (selected_volume))
+ {
+ window->priv->selected_volume = g_object_ref (selected_volume);
+ }
+ gtk_container_add (GTK_CONTAINER (menu), menu_item);
+ gtk_widget_show (menu_item);
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (window),
+ "format");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
+ selected_volume != NULL &&
+ G_IS_VOLUME (selected_volume));
+ }
+ }
}
static void
nautilus_window_set_up_sidebar (NautilusWindow *window)
{
- setup_side_pane_width (window);
- g_signal_connect (window->priv->sidebar,
- "size-allocate",
- G_CALLBACK (side_pane_size_allocate_callback),
- window);
-
- gtk_places_sidebar_set_open_flags (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
- (GTK_PLACES_OPEN_NORMAL
- | GTK_PLACES_OPEN_NEW_TAB
- | GTK_PLACES_OPEN_NEW_WINDOW));
-
- g_signal_connect_swapped (window->priv->places_sidebar, "open-location",
- G_CALLBACK (open_location_cb), window);
- g_signal_connect (window->priv->places_sidebar, "show-error-message",
- G_CALLBACK (places_sidebar_show_error_message_cb), window);
- g_signal_connect (window->priv->places_sidebar, "drag-action-requested",
- G_CALLBACK (places_sidebar_drag_action_requested_cb), window);
- g_signal_connect (window->priv->places_sidebar, "drag-action-ask",
- G_CALLBACK (places_sidebar_drag_action_ask_cb), window);
- g_signal_connect (window->priv->places_sidebar, "drag-perform-drop",
- G_CALLBACK (places_sidebar_drag_perform_drop_cb), window);
- g_signal_connect (window->priv->places_sidebar, "populate-popup",
- G_CALLBACK (places_sidebar_populate_popup_cb), window);
- g_signal_connect (window->priv->places_sidebar, "unmount",
- G_CALLBACK (places_sidebar_unmount_operation_cb), window);
+ setup_side_pane_width (window);
+ g_signal_connect (window->priv->sidebar,
+ "size-allocate",
+ G_CALLBACK (side_pane_size_allocate_callback),
+ window);
+
+ gtk_places_sidebar_set_open_flags (GTK_PLACES_SIDEBAR (window->priv->places_sidebar),
+ (GTK_PLACES_OPEN_NORMAL
+ | GTK_PLACES_OPEN_NEW_TAB
+ | GTK_PLACES_OPEN_NEW_WINDOW));
+
+ g_signal_connect_swapped (window->priv->places_sidebar, "open-location",
+ G_CALLBACK (open_location_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "show-error-message",
+ G_CALLBACK (places_sidebar_show_error_message_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "drag-action-requested",
+ G_CALLBACK (places_sidebar_drag_action_requested_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "drag-action-ask",
+ G_CALLBACK (places_sidebar_drag_action_ask_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "drag-perform-drop",
+ G_CALLBACK (places_sidebar_drag_perform_drop_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "populate-popup",
+ G_CALLBACK (places_sidebar_populate_popup_cb), window);
+ g_signal_connect (window->priv->places_sidebar, "unmount",
+ G_CALLBACK (places_sidebar_unmount_operation_cb), window);
}
void
nautilus_window_hide_sidebar (NautilusWindow *window)
{
- DEBUG ("Called hide_sidebar()");
+ DEBUG ("Called hide_sidebar()");
- gtk_widget_hide (window->priv->sidebar);
+ gtk_widget_hide (window->priv->sidebar);
}
void
nautilus_window_show_sidebar (NautilusWindow *window)
{
- DEBUG ("Called show_sidebar()");
+ DEBUG ("Called show_sidebar()");
- if (window->priv->disable_chrome) {
- return;
- }
+ if (window->priv->disable_chrome)
+ {
+ return;
+ }
- gtk_widget_show (window->priv->sidebar);
- setup_side_pane_width (window);
+ gtk_widget_show (window->priv->sidebar);
+ setup_side_pane_width (window);
}
static inline NautilusWindowSlot *
get_first_inactive_slot (NautilusWindow *window)
{
- GList *l;
- NautilusWindowSlot *slot;
+ GList *l;
+ NautilusWindowSlot *slot;
- for (l = window->priv->slots; l != NULL; l = l->next) {
- slot = NAUTILUS_WINDOW_SLOT (l->data);
- if (slot != window->priv->active_slot) {
- return slot;
- }
- }
+ for (l = window->priv->slots; l != NULL; l = l->next)
+ {
+ slot = NAUTILUS_WINDOW_SLOT (l->data);
+ if (slot != window->priv->active_slot)
+ {
+ return slot;
+ }
+ }
- return NULL;
+ return NULL;
}
void
nautilus_window_slot_close (NautilusWindow *window,
- NautilusWindowSlot *slot)
+ NautilusWindowSlot *slot)
{
- NautilusWindowSlot *next_slot;
+ NautilusWindowSlot *next_slot;
- DEBUG ("Requesting to remove slot %p from window %p", slot, window);
- if (window == NULL)
- return;
+ DEBUG ("Requesting to remove slot %p from window %p", slot, window);
+ if (window == NULL)
+ {
+ return;
+ }
- if (window->priv->active_slot == slot) {
- next_slot = get_first_inactive_slot (window);
- nautilus_window_set_active_slot (window, next_slot);
- }
+ if (window->priv->active_slot == slot)
+ {
+ next_slot = get_first_inactive_slot (window);
+ nautilus_window_set_active_slot (window, next_slot);
+ }
- close_slot (window, slot, TRUE);
+ close_slot (window, slot, TRUE);
- /* If that was the last slot in the window, close the window. */
- if (window->priv->slots == NULL) {
- DEBUG ("Last slot removed, closing the window");
- nautilus_window_close (window);
- }
+ /* If that was the last slot in the window, close the window. */
+ if (window->priv->slots == NULL)
+ {
+ DEBUG ("Last slot removed, closing the window");
+ nautilus_window_close (window);
+ }
}
static void
nautilus_window_sync_bookmarks (NautilusWindow *window)
{
- gboolean can_bookmark = FALSE;
- NautilusWindowSlot *slot;
- NautilusBookmarkList *bookmarks;
- GAction *action;
- GFile *location;
+ gboolean can_bookmark = FALSE;
+ NautilusWindowSlot *slot;
+ NautilusBookmarkList *bookmarks;
+ GAction *action;
+ GFile *location;
- slot = window->priv->active_slot;
- location = nautilus_window_slot_get_location (slot);
+ slot = window->priv->active_slot;
+ location = nautilus_window_slot_get_location (slot);
- if (location != NULL) {
- bookmarks = nautilus_application_get_bookmarks
- (NAUTILUS_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
- can_bookmark = nautilus_bookmark_list_can_bookmark_location (bookmarks, location);
- }
+ if (location != NULL)
+ {
+ bookmarks = nautilus_application_get_bookmarks
+ (NAUTILUS_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
+ can_bookmark = nautilus_bookmark_list_can_bookmark_location (bookmarks, location);
+ }
- action = g_action_map_lookup_action (G_ACTION_MAP (window), "bookmark-current-location");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_bookmark);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "bookmark-current-location");
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), can_bookmark);
}
void
nautilus_window_sync_location_widgets (NautilusWindow *window)
{
- NautilusWindowSlot *slot;
- GFile *location;
- GAction *action;
- gboolean enabled;
+ NautilusWindowSlot *slot;
+ GFile *location;
+ GAction *action;
+ gboolean enabled;
- slot = window->priv->active_slot;
- location = nautilus_window_slot_get_location (slot);
+ slot = window->priv->active_slot;
+ location = nautilus_window_slot_get_location (slot);
- /* Change the location bar and path bar to match the current location. */
- if (location != NULL) {
- GtkWidget *location_entry;
- GtkWidget *path_bar;
+ /* Change the location bar and path bar to match the current location. */
+ if (location != NULL)
+ {
+ GtkWidget *location_entry;
+ GtkWidget *path_bar;
- location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
- nautilus_location_entry_set_location (NAUTILUS_LOCATION_ENTRY (location_entry), location);
+ location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ nautilus_location_entry_set_location (NAUTILUS_LOCATION_ENTRY (location_entry), location);
- path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->priv->toolbar));
- nautilus_path_bar_set_path (NAUTILUS_PATH_BAR (path_bar), location);
- }
+ path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ nautilus_path_bar_set_path (NAUTILUS_PATH_BAR (path_bar), location);
+ }
- action = g_action_map_lookup_action (G_ACTION_MAP (window), "back");
- enabled = nautilus_window_slot_get_back_history (slot) != NULL;
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "back");
+ enabled = nautilus_window_slot_get_back_history (slot) != NULL;
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
- action = g_action_map_lookup_action (G_ACTION_MAP (window), "forward");
- enabled = nautilus_window_slot_get_forward_history (slot) != NULL;
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), "forward");
+ enabled = nautilus_window_slot_get_forward_history (slot) != NULL;
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), enabled);
- nautilus_window_sync_bookmarks (window);
+ nautilus_window_sync_bookmarks (window);
}
static GtkWidget *
nautilus_window_ensure_location_entry (NautilusWindow *window)
{
- GtkWidget *location_entry;
+ GtkWidget *location_entry;
- remember_focus_widget (window);
+ remember_focus_widget (window);
- nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), TRUE);
+ nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar), TRUE);
- location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
- nautilus_location_entry_focus (NAUTILUS_LOCATION_ENTRY (location_entry));
+ location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ nautilus_location_entry_focus (NAUTILUS_LOCATION_ENTRY (location_entry));
- return location_entry;
+ return location_entry;
}
static void
remove_notifications (NautilusWindow *window)
{
- GtkRevealerTransitionType transition_type;
-
- /* Hide it inmediatily so we can animate the new notification. */
- transition_type = gtk_revealer_get_transition_type (GTK_REVEALER (window->priv->notification_delete));
- gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_delete),
- GTK_REVEALER_TRANSITION_TYPE_NONE);
- gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_delete),
- FALSE);
- gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_delete),
- transition_type);
- if (window->priv->notification_delete_timeout_id != 0) {
- g_source_remove (window->priv->notification_delete_timeout_id);
- window->priv->notification_delete_timeout_id = 0;
- }
-
- transition_type = gtk_revealer_get_transition_type (GTK_REVEALER (window->priv->notification_operation));
- gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_operation),
- GTK_REVEALER_TRANSITION_TYPE_NONE);
- gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_operation),
- FALSE);
- gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_operation),
- transition_type);
- if (window->priv->notification_operation_timeout_id != 0) {
- g_source_remove (window->priv->notification_operation_timeout_id);
- window->priv->notification_operation_timeout_id = 0;
- }
+ GtkRevealerTransitionType transition_type;
+
+ /* Hide it inmediatily so we can animate the new notification. */
+ transition_type = gtk_revealer_get_transition_type (GTK_REVEALER (window->priv->notification_delete));
+ gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_delete),
+ GTK_REVEALER_TRANSITION_TYPE_NONE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_delete),
+ FALSE);
+ gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_delete),
+ transition_type);
+ if (window->priv->notification_delete_timeout_id != 0)
+ {
+ g_source_remove (window->priv->notification_delete_timeout_id);
+ window->priv->notification_delete_timeout_id = 0;
+ }
+
+ transition_type = gtk_revealer_get_transition_type (GTK_REVEALER (window->priv->notification_operation));
+ gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_operation),
+ GTK_REVEALER_TRANSITION_TYPE_NONE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_operation),
+ FALSE);
+ gtk_revealer_set_transition_type (GTK_REVEALER (window->priv->notification_operation),
+ transition_type);
+ if (window->priv->notification_operation_timeout_id != 0)
+ {
+ g_source_remove (window->priv->notification_operation_timeout_id);
+ window->priv->notification_operation_timeout_id = 0;
+ }
}
static void
hide_notification_delete (NautilusWindow *window)
{
- if (window->priv->notification_delete_timeout_id != 0) {
- g_source_remove (window->priv->notification_delete_timeout_id);
- window->priv->notification_delete_timeout_id = 0;
- }
+ if (window->priv->notification_delete_timeout_id != 0)
+ {
+ g_source_remove (window->priv->notification_delete_timeout_id);
+ window->priv->notification_delete_timeout_id = 0;
+ }
- gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_delete), FALSE);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_delete), FALSE);
}
static void
nautilus_window_on_notification_delete_undo_clicked (GtkWidget *notification,
NautilusWindow *window)
{
- hide_notification_delete (window);
+ hide_notification_delete (window);
- nautilus_file_undo_manager_undo (GTK_WINDOW (window));
+ nautilus_file_undo_manager_undo (GTK_WINDOW (window));
}
static void
nautilus_window_on_notification_delete_close_clicked (GtkWidget *notification,
NautilusWindow *window)
{
- hide_notification_delete (window);
+ hide_notification_delete (window);
}
static gboolean
nautilus_window_on_notification_delete_timeout (NautilusWindow *window)
{
- hide_notification_delete (window);
+ hide_notification_delete (window);
- return FALSE;
+ return FALSE;
}
static char *
nautilus_window_notification_delete_get_label (NautilusFileUndoInfo *undo_info,
- GList *files)
+ GList *files)
{
- gchar *file_label;
- gchar *label;
- gint length;
+ gchar *file_label;
+ gchar *label;
+ gint length;
- length = g_list_length (files);
- if (length == 1) {
- file_label = g_file_get_basename (files->data);
- /* Translators: only one item has been deleted and %s is its name. */
- label = g_markup_printf_escaped (_("“%s” deleted"), file_label);
- g_free (file_label);
- } else {
- /* Translators: one or more items might have been deleted, and %d
- * is the count. */
- label = g_markup_printf_escaped (ngettext ("%d file deleted", "%d files deleted", length), length);
- }
+ length = g_list_length (files);
+ if (length == 1)
+ {
+ file_label = g_file_get_basename (files->data);
+ /* Translators: only one item has been deleted and %s is its name. */
+ label = g_markup_printf_escaped (_("“%s” deleted"), file_label);
+ g_free (file_label);
+ }
+ else
+ {
+ /* Translators: one or more items might have been deleted, and %d
+ * is the count. */
+ label = g_markup_printf_escaped (ngettext ("%d file deleted", "%d files deleted", length), length);
+ }
- return label;
+ return label;
}
static void
nautilus_window_on_undo_changed (NautilusFileUndoManager *manager,
NautilusWindow *window)
{
- NautilusFileUndoInfo *undo_info;
- NautilusFileUndoManagerState state;
- gchar *label;
- GList *files;
-
- undo_info = nautilus_file_undo_manager_get_action ();
- state = nautilus_file_undo_manager_get_state ();
-
- if (undo_info != NULL &&
- state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO &&
- nautilus_file_undo_info_get_op_type (undo_info) == NAUTILUS_FILE_UNDO_OP_MOVE_TO_TRASH &&
- !window->priv->disable_chrome) {
- files = nautilus_file_undo_info_trash_get_files (NAUTILUS_FILE_UNDO_INFO_TRASH (undo_info));
-
- /* Don't pop up a notification if user canceled the operation or the focus
- * is not in the this window. This is an easy way to know from which window
- * was the delete operation made */
- if (g_list_length (files) > 0 && gtk_window_has_toplevel_focus (GTK_WINDOW (window))) {
- label = nautilus_window_notification_delete_get_label (undo_info, files);
- gtk_label_set_markup (GTK_LABEL (window->priv->notification_delete_label), label);
- gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_delete), TRUE);
- window->priv->notification_delete_timeout_id = g_timeout_add_seconds (NOTIFICATION_TIMEOUT,
- (GSourceFunc) nautilus_window_on_notification_delete_timeout,
- window);
- g_free (label);
- }
- g_list_free (files);
- } else {
- hide_notification_delete (window);
+ NautilusFileUndoInfo *undo_info;
+ NautilusFileUndoManagerState state;
+ gchar *label;
+ GList *files;
+
+ undo_info = nautilus_file_undo_manager_get_action ();
+ state = nautilus_file_undo_manager_get_state ();
+
+ if (undo_info != NULL &&
+ state == NAUTILUS_FILE_UNDO_MANAGER_STATE_UNDO &&
+ nautilus_file_undo_info_get_op_type (undo_info) == NAUTILUS_FILE_UNDO_OP_MOVE_TO_TRASH &&
+ !window->priv->disable_chrome)
+ {
+ files = nautilus_file_undo_info_trash_get_files (NAUTILUS_FILE_UNDO_INFO_TRASH (undo_info));
+
+ /* Don't pop up a notification if user canceled the operation or the focus
+ * is not in the this window. This is an easy way to know from which window
+ * was the delete operation made */
+ if (g_list_length (files) > 0 && gtk_window_has_toplevel_focus (GTK_WINDOW (window)))
+ {
+ label = nautilus_window_notification_delete_get_label (undo_info, files);
+ gtk_label_set_markup (GTK_LABEL (window->priv->notification_delete_label), label);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_delete), TRUE);
+ window->priv->notification_delete_timeout_id = g_timeout_add_seconds (NOTIFICATION_TIMEOUT,
+ (GSourceFunc) nautilus_window_on_notification_delete_timeout,
+ window);
+ g_free (label);
}
+ g_list_free (files);
+ }
+ else
+ {
+ hide_notification_delete (window);
+ }
}
static void
hide_notification_operation (NautilusWindow *window)
{
- if (window->priv->notification_operation_timeout_id != 0) {
- g_source_remove (window->priv->notification_operation_timeout_id);
- window->priv->notification_operation_timeout_id = 0;
- }
+ if (window->priv->notification_operation_timeout_id != 0)
+ {
+ g_source_remove (window->priv->notification_operation_timeout_id);
+ window->priv->notification_operation_timeout_id = 0;
+ }
- gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_operation), FALSE);
- g_clear_object (&window->priv->folder_to_open);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_operation), FALSE);
+ g_clear_object (&window->priv->folder_to_open);
}
static void
on_notification_operation_open_clicked (GtkWidget *notification,
NautilusWindow *window)
{
- nautilus_window_open_location_full (window, window->priv->folder_to_open,
- 0, NULL, NULL);
- hide_notification_operation (window);
+ nautilus_window_open_location_full (window, window->priv->folder_to_open,
+ 0, NULL, NULL);
+ hide_notification_operation (window);
}
static void
on_notification_operation_close_clicked (GtkWidget *notification,
NautilusWindow *window)
{
- hide_notification_operation (window);
+ hide_notification_operation (window);
}
static gboolean
on_notification_operation_timeout (NautilusWindow *window)
{
- hide_notification_operation (window);
+ hide_notification_operation (window);
- return FALSE;
+ return FALSE;
}
void
@@ -1688,748 +1779,802 @@ nautilus_window_show_operation_notification (NautilusWindow *window,
gchar *main_label,
GFile *folder_to_open)
{
- gchar *button_label;
- gchar *folder_name;
- NautilusFile *folder;
- GFile *current_location;
-
- current_location = nautilus_window_slot_get_location (window->priv->active_slot);
- if (gtk_window_has_toplevel_focus (GTK_WINDOW (window)) &&
- !window->priv->disable_chrome) {
- remove_notifications (window);
- gtk_label_set_text (GTK_LABEL (window->priv->notification_operation_label),
- main_label);
-
- if (g_file_equal (folder_to_open, current_location)) {
- gtk_widget_hide (window->priv->notification_operation_open);
- } else {
- gtk_widget_show (window->priv->notification_operation_open);
- window->priv->folder_to_open = g_object_ref (folder_to_open);
- folder = nautilus_file_get (folder_to_open);
- folder_name = nautilus_file_get_display_name (folder);
- button_label = g_strdup_printf (_("Open %s"), folder_name);
- gtk_button_set_label (GTK_BUTTON (window->priv->notification_operation_open),
- button_label);
- nautilus_file_unref (folder);
- g_free (folder_name);
- g_free (button_label);
- }
-
- gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_operation), TRUE);
- window->priv->notification_operation_timeout_id = g_timeout_add_seconds (NOTIFICATION_TIMEOUT,
- (GSourceFunc) on_notification_operation_timeout,
- window);
- }
+ gchar *button_label;
+ gchar *folder_name;
+ NautilusFile *folder;
+ GFile *current_location;
+
+ current_location = nautilus_window_slot_get_location (window->priv->active_slot);
+ if (gtk_window_has_toplevel_focus (GTK_WINDOW (window)) &&
+ !window->priv->disable_chrome)
+ {
+ remove_notifications (window);
+ gtk_label_set_text (GTK_LABEL (window->priv->notification_operation_label),
+ main_label);
+
+ if (g_file_equal (folder_to_open, current_location))
+ {
+ gtk_widget_hide (window->priv->notification_operation_open);
+ }
+ else
+ {
+ gtk_widget_show (window->priv->notification_operation_open);
+ window->priv->folder_to_open = g_object_ref (folder_to_open);
+ folder = nautilus_file_get (folder_to_open);
+ folder_name = nautilus_file_get_display_name (folder);
+ button_label = g_strdup_printf (_("Open %s"), folder_name);
+ gtk_button_set_label (GTK_BUTTON (window->priv->notification_operation_open),
+ button_label);
+ nautilus_file_unref (folder);
+ g_free (folder_name);
+ g_free (button_label);
+ }
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (window->priv->notification_operation), TRUE);
+ window->priv->notification_operation_timeout_id = g_timeout_add_seconds (NOTIFICATION_TIMEOUT,
+ (GSourceFunc) on_notification_operation_timeout,
+ window);
+ }
}
static void
path_bar_location_changed_callback (GtkWidget *widget,
- GFile *location,
- NautilusWindow *window)
+ GFile *location,
+ NautilusWindow *window)
{
- NautilusWindowSlot *slot;
- int i;
+ NautilusWindowSlot *slot;
+ int i;
- slot = window->priv->active_slot;
- /* check whether we already visited the target location */
- i = bookmark_list_get_uri_index (nautilus_window_slot_get_back_history (slot), location);
- if (i >= 0) {
- nautilus_window_back_or_forward (window, TRUE, i, 0);
- } else {
- nautilus_window_open_location_full (window, location, 0, NULL, NULL);
- }
+ slot = window->priv->active_slot;
+ /* check whether we already visited the target location */
+ i = bookmark_list_get_uri_index (nautilus_window_slot_get_back_history (slot), location);
+ if (i >= 0)
+ {
+ nautilus_window_back_or_forward (window, TRUE, i, 0);
+ }
+ else
+ {
+ nautilus_window_open_location_full (window, location, 0, NULL, NULL);
+ }
}
static void
notebook_popup_menu_new_tab_cb (GtkMenuItem *menuitem,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_window_new_tab (window);
+ nautilus_window_new_tab (window);
}
static void
notebook_popup_menu_move_left_cb (GtkMenuItem *menuitem,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), -1);
+ nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), -1);
}
static void
notebook_popup_menu_move_right_cb (GtkMenuItem *menuitem,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), 1);
+ nautilus_notebook_reorder_current_child_relative (NAUTILUS_NOTEBOOK (window->priv->notebook), 1);
}
static void
notebook_popup_menu_close_cb (GtkMenuItem *menuitem,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
- NautilusWindowSlot *slot;
+ NautilusWindow *window = user_data;
+ NautilusWindowSlot *slot;
- slot = window->priv->active_slot;
- nautilus_window_slot_close (window, slot);
+ slot = window->priv->active_slot;
+ nautilus_window_slot_close (window, slot);
}
static void
notebook_popup_menu_show (NautilusWindow *window,
- GdkEventButton *event)
-{
- GtkWidget *popup;
- GtkWidget *item;
- int button, event_time;
- gboolean can_move_left, can_move_right;
- NautilusNotebook *notebook;
-
- notebook = NAUTILUS_NOTEBOOK (window->priv->notebook);
-
- can_move_left = nautilus_notebook_can_reorder_current_child_relative (notebook, -1);
- can_move_right = nautilus_notebook_can_reorder_current_child_relative (notebook, 1);
-
- popup = gtk_menu_new ();
-
- item = gtk_menu_item_new_with_mnemonic (_("_New Tab"));
- g_signal_connect (item, "activate",
- G_CALLBACK (notebook_popup_menu_new_tab_cb),
- window);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup),
- item);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (popup),
- gtk_separator_menu_item_new ());
-
- item = gtk_menu_item_new_with_mnemonic (_("Move Tab _Left"));
- g_signal_connect (item, "activate",
- G_CALLBACK (notebook_popup_menu_move_left_cb),
- window);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup),
- item);
- gtk_widget_set_sensitive (item, can_move_left);
-
- item = gtk_menu_item_new_with_mnemonic (_("Move Tab _Right"));
- g_signal_connect (item, "activate",
- G_CALLBACK (notebook_popup_menu_move_right_cb),
- window);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup),
- item);
- gtk_widget_set_sensitive (item, can_move_right);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (popup),
- gtk_separator_menu_item_new ());
-
- item = gtk_menu_item_new_with_mnemonic (_("_Close Tab"));
- g_signal_connect (item, "activate",
- G_CALLBACK (notebook_popup_menu_close_cb), window);
- gtk_menu_shell_append (GTK_MENU_SHELL (popup),
- item);
-
- gtk_widget_show_all (popup);
-
- if (event) {
- button = event->button;
- event_time = event->time;
- } else {
- button = 0;
- event_time = gtk_get_current_event_time ();
- }
-
- /* TODO is this correct? */
- gtk_menu_attach_to_widget (GTK_MENU (popup),
- window->priv->notebook,
- NULL);
-
- gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL,
- button, event_time);
+ GdkEventButton *event)
+{
+ GtkWidget *popup;
+ GtkWidget *item;
+ int button, event_time;
+ gboolean can_move_left, can_move_right;
+ NautilusNotebook *notebook;
+
+ notebook = NAUTILUS_NOTEBOOK (window->priv->notebook);
+
+ can_move_left = nautilus_notebook_can_reorder_current_child_relative (notebook, -1);
+ can_move_right = nautilus_notebook_can_reorder_current_child_relative (notebook, 1);
+
+ popup = gtk_menu_new ();
+
+ item = gtk_menu_item_new_with_mnemonic (_("_New Tab"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (notebook_popup_menu_new_tab_cb),
+ window);
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup),
+ item);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup),
+ gtk_separator_menu_item_new ());
+
+ item = gtk_menu_item_new_with_mnemonic (_("Move Tab _Left"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (notebook_popup_menu_move_left_cb),
+ window);
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup),
+ item);
+ gtk_widget_set_sensitive (item, can_move_left);
+
+ item = gtk_menu_item_new_with_mnemonic (_("Move Tab _Right"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (notebook_popup_menu_move_right_cb),
+ window);
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup),
+ item);
+ gtk_widget_set_sensitive (item, can_move_right);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup),
+ gtk_separator_menu_item_new ());
+
+ item = gtk_menu_item_new_with_mnemonic (_("_Close Tab"));
+ g_signal_connect (item, "activate",
+ G_CALLBACK (notebook_popup_menu_close_cb), window);
+ gtk_menu_shell_append (GTK_MENU_SHELL (popup),
+ item);
+
+ gtk_widget_show_all (popup);
+
+ if (event)
+ {
+ button = event->button;
+ event_time = event->time;
+ }
+ else
+ {
+ button = 0;
+ event_time = gtk_get_current_event_time ();
+ }
+
+ /* TODO is this correct? */
+ gtk_menu_attach_to_widget (GTK_MENU (popup),
+ window->priv->notebook,
+ NULL);
+
+ gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL,
+ button, event_time);
}
/* emitted when the user clicks the "close" button of tabs */
static void
notebook_tab_close_requested (NautilusNotebook *notebook,
- NautilusWindowSlot *slot,
- NautilusWindow *window)
+ NautilusWindowSlot *slot,
+ NautilusWindow *window)
{
- nautilus_window_slot_close (window, slot);
+ nautilus_window_slot_close (window, slot);
}
static gboolean
-notebook_button_press_cb (GtkWidget *widget,
- GdkEventButton *event,
- gpointer user_data)
+notebook_button_press_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
+ NautilusWindow *window = user_data;
- if (GDK_BUTTON_PRESS == event->type && 3 == event->button) {
- notebook_popup_menu_show (window, event);
- return TRUE;
- }
+ if (GDK_BUTTON_PRESS == event->type && 3 == event->button)
+ {
+ notebook_popup_menu_show (window, event);
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
notebook_popup_menu_cb (GtkWidget *widget,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
- notebook_popup_menu_show (window, NULL);
- return TRUE;
+ NautilusWindow *window = user_data;
+ notebook_popup_menu_show (window, NULL);
+ return TRUE;
}
GtkWidget *
nautilus_window_get_toolbar (NautilusWindow *window)
{
- return window->priv->toolbar;
+ return window->priv->toolbar;
}
static void
setup_toolbar (NautilusWindow *window)
{
- GtkWidget *path_bar;
- GtkWidget *location_entry;
-
- g_object_set (window->priv->toolbar, "window", window, NULL);
- g_object_bind_property (window, "disable-chrome",
- window->priv->toolbar, "visible",
- G_BINDING_INVERT_BOOLEAN);
+ GtkWidget *path_bar;
+ GtkWidget *location_entry;
- /* connect to the pathbar signals */
- path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ g_object_set (window->priv->toolbar, "window", window, NULL);
+ g_object_bind_property (window, "disable-chrome",
+ window->priv->toolbar, "visible",
+ G_BINDING_INVERT_BOOLEAN);
- g_signal_connect_object (path_bar, "path-clicked",
- G_CALLBACK (path_bar_location_changed_callback), window, 0);
- g_signal_connect_swapped (path_bar, "open-location",
- G_CALLBACK (open_location_cb), window);
+ /* connect to the pathbar signals */
+ path_bar = nautilus_toolbar_get_path_bar (NAUTILUS_TOOLBAR (window->priv->toolbar));
- /* connect to the location entry signals */
- location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ g_signal_connect_object (path_bar, "path-clicked",
+ G_CALLBACK (path_bar_location_changed_callback), window, 0);
+ g_signal_connect_swapped (path_bar, "open-location",
+ G_CALLBACK (open_location_cb), window);
- g_signal_connect_object (location_entry, "location-changed",
- G_CALLBACK (location_entry_location_changed_callback), window, 0);
- g_signal_connect_object (location_entry, "cancel",
- G_CALLBACK (location_entry_cancel_callback), window, 0);
+ /* connect to the location entry signals */
+ location_entry = nautilus_toolbar_get_location_entry (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ g_signal_connect_object (location_entry, "location-changed",
+ G_CALLBACK (location_entry_location_changed_callback), window, 0);
+ g_signal_connect_object (location_entry, "cancel",
+ G_CALLBACK (location_entry_cancel_callback), window, 0);
}
static void
notebook_page_removed_cb (GtkNotebook *notebook,
- GtkWidget *page,
- guint page_num,
- gpointer user_data)
+ GtkWidget *page,
+ guint page_num,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
- NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page), *next_slot;
- gboolean dnd_slot;
+ NautilusWindow *window = user_data;
+ NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page), *next_slot;
+ gboolean dnd_slot;
- dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
- if (!dnd_slot) {
- return;
- }
+ dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
+ if (!dnd_slot)
+ {
+ return;
+ }
- if (window->priv->active_slot == slot) {
- next_slot = get_first_inactive_slot (window);
- nautilus_window_set_active_slot (window, next_slot);
- }
+ if (window->priv->active_slot == slot)
+ {
+ next_slot = get_first_inactive_slot (window);
+ nautilus_window_set_active_slot (window, next_slot);
+ }
- close_slot (window, slot, FALSE);
+ close_slot (window, slot, FALSE);
}
static void
notebook_page_added_cb (GtkNotebook *notebook,
- GtkWidget *page,
- guint page_num,
- gpointer user_data)
+ GtkWidget *page,
+ guint page_num,
+ gpointer user_data)
{
- NautilusWindow *window = user_data;
- NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page);
- NautilusWindowSlot *dummy_slot;
- gboolean dnd_slot;
+ NautilusWindow *window = user_data;
+ NautilusWindowSlot *slot = NAUTILUS_WINDOW_SLOT (page);
+ NautilusWindowSlot *dummy_slot;
+ gboolean dnd_slot;
- dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
- if (!dnd_slot) {
- return;
- }
+ dnd_slot = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (slot), "dnd-window-slot"));
+ if (!dnd_slot)
+ {
+ return;
+ }
- g_object_set_data (G_OBJECT (page), "dnd-window-slot",
- GINT_TO_POINTER (FALSE));
+ g_object_set_data (G_OBJECT (page), "dnd-window-slot",
+ GINT_TO_POINTER (FALSE));
- nautilus_window_slot_set_window (slot, window);
- window->priv->slots = g_list_append (window->priv->slots, slot);
- g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
+ nautilus_window_slot_set_window (slot, window);
+ window->priv->slots = g_list_append (window->priv->slots, slot);
+ g_signal_emit (window, signals[SLOT_ADDED], 0, slot);
- nautilus_window_set_active_slot (window, slot);
+ nautilus_window_set_active_slot (window, slot);
- dummy_slot = g_list_nth_data (window->priv->slots, 0);
- if (dummy_slot != NULL) {
- close_slot (window, dummy_slot, TRUE);
- }
+ dummy_slot = g_list_nth_data (window->priv->slots, 0);
+ if (dummy_slot != NULL)
+ {
+ close_slot (window, dummy_slot, TRUE);
+ }
- gtk_widget_show (GTK_WIDGET (window));
+ gtk_widget_show (GTK_WIDGET (window));
}
static GtkNotebook *
notebook_create_window_cb (GtkNotebook *notebook,
- GtkWidget *page,
- gint x,
- gint y,
- gpointer user_data)
+ GtkWidget *page,
+ gint x,
+ gint y,
+ gpointer user_data)
{
- NautilusApplication *app;
- NautilusWindow *new_window;
- NautilusWindowSlot *slot;
+ NautilusApplication *app;
+ NautilusWindow *new_window;
+ NautilusWindowSlot *slot;
- if (!NAUTILUS_IS_WINDOW_SLOT (page)) {
- return NULL;
- }
+ if (!NAUTILUS_IS_WINDOW_SLOT (page))
+ {
+ return NULL;
+ }
- app = NAUTILUS_APPLICATION (g_application_get_default ());
- new_window = nautilus_application_create_window
- (app, gtk_widget_get_screen (GTK_WIDGET (notebook)));
+ app = NAUTILUS_APPLICATION (g_application_get_default ());
+ new_window = nautilus_application_create_window
+ (app, gtk_widget_get_screen (GTK_WIDGET (notebook)));
- slot = NAUTILUS_WINDOW_SLOT (page);
- g_object_set_data (G_OBJECT (slot), "dnd-window-slot",
- GINT_TO_POINTER (TRUE));
+ slot = NAUTILUS_WINDOW_SLOT (page);
+ g_object_set_data (G_OBJECT (slot), "dnd-window-slot",
+ GINT_TO_POINTER (TRUE));
- gtk_window_set_position (GTK_WINDOW (new_window), GTK_WIN_POS_MOUSE);
+ gtk_window_set_position (GTK_WINDOW (new_window), GTK_WIN_POS_MOUSE);
- return GTK_NOTEBOOK (new_window->priv->notebook);
+ return GTK_NOTEBOOK (new_window->priv->notebook);
}
static void
setup_notebook (NautilusWindow *window)
{
- g_signal_connect (window->priv->notebook, "tab-close-request",
- G_CALLBACK (notebook_tab_close_requested),
- window);
- g_signal_connect (window->priv->notebook, "popup-menu",
- G_CALLBACK (notebook_popup_menu_cb),
- window);
- g_signal_connect (window->priv->notebook, "switch-page",
- G_CALLBACK (notebook_switch_page_cb),
- window);
- g_signal_connect (window->priv->notebook, "create-window",
- G_CALLBACK (notebook_create_window_cb),
- window);
- g_signal_connect (window->priv->notebook, "page-added",
- G_CALLBACK (notebook_page_added_cb),
- window);
- g_signal_connect (window->priv->notebook, "page-removed",
- G_CALLBACK (notebook_page_removed_cb),
- window);
- g_signal_connect_after (window->priv->notebook, "button-press-event",
- G_CALLBACK (notebook_button_press_cb),
- window);
-}
-
-const GActionEntry win_entries[] = {
- { "back", action_back },
- { "forward", action_forward },
- { "up", action_up },
- { "view-menu", action_toggle_state_view_button, NULL, "false", NULL },
- { "reload", action_reload },
- { "stop", action_stop },
- { "new-tab", action_new_tab },
- { "enter-location", action_enter_location },
- { "bookmark-current-location", action_bookmark_current_location },
- { "undo", action_undo },
- { "redo", action_redo },
- /* Only accesible by shorcuts */
- { "close-current-view", action_close_current_view },
- { "go-home", action_go_home },
- { "tab-previous", action_tab_previous },
- { "tab-next", action_tab_next },
- { "tab-move-left", action_tab_move_left },
- { "tab-move-right", action_tab_move_right },
- { "prompt-root-location", action_prompt_for_location_root },
- { "prompt-home-location", action_prompt_for_location_home },
- { "go-to-tab", NULL, "i", "0", action_go_to_tab },
- { "empty-trash", action_empty_trash },
- { "properties", action_properties },
- { "format", action_format },
+ g_signal_connect (window->priv->notebook, "tab-close-request",
+ G_CALLBACK (notebook_tab_close_requested),
+ window);
+ g_signal_connect (window->priv->notebook, "popup-menu",
+ G_CALLBACK (notebook_popup_menu_cb),
+ window);
+ g_signal_connect (window->priv->notebook, "switch-page",
+ G_CALLBACK (notebook_switch_page_cb),
+ window);
+ g_signal_connect (window->priv->notebook, "create-window",
+ G_CALLBACK (notebook_create_window_cb),
+ window);
+ g_signal_connect (window->priv->notebook, "page-added",
+ G_CALLBACK (notebook_page_added_cb),
+ window);
+ g_signal_connect (window->priv->notebook, "page-removed",
+ G_CALLBACK (notebook_page_removed_cb),
+ window);
+ g_signal_connect_after (window->priv->notebook, "button-press-event",
+ G_CALLBACK (notebook_button_press_cb),
+ window);
+}
+
+const GActionEntry win_entries[] =
+{
+ { "back", action_back },
+ { "forward", action_forward },
+ { "up", action_up },
+ { "view-menu", action_toggle_state_view_button, NULL, "false", NULL },
+ { "reload", action_reload },
+ { "stop", action_stop },
+ { "new-tab", action_new_tab },
+ { "enter-location", action_enter_location },
+ { "bookmark-current-location", action_bookmark_current_location },
+ { "undo", action_undo },
+ { "redo", action_redo },
+ /* Only accesible by shorcuts */
+ { "close-current-view", action_close_current_view },
+ { "go-home", action_go_home },
+ { "tab-previous", action_tab_previous },
+ { "tab-next", action_tab_next },
+ { "tab-move-left", action_tab_move_left },
+ { "tab-move-right", action_tab_move_right },
+ { "prompt-root-location", action_prompt_for_location_root },
+ { "prompt-home-location", action_prompt_for_location_home },
+ { "go-to-tab", NULL, "i", "0", action_go_to_tab },
+ { "empty-trash", action_empty_trash },
+ { "properties", action_properties },
+ { "format", action_format },
};
static void
nautilus_window_initialize_actions (NautilusWindow *window)
{
- GApplication *app;
- GAction *action;
- GVariant *state;
- gchar detailed_action[80];
- gchar accel[80];
- gint i;
- const gchar *reload_accels[] = {
- "F5",
- "<ctrl>r",
- NULL
- };
-
- g_action_map_add_action_entries (G_ACTION_MAP (window),
- win_entries, G_N_ELEMENTS (win_entries),
- window);
-
- app = g_application_get_default ();
- nautilus_application_set_accelerator (app, "win.back", "<alt>Left");
- nautilus_application_set_accelerator (app, "win.forward", "<alt>Right");
- nautilus_application_set_accelerator (app, "win.enter-location", "<control>l");
- nautilus_application_set_accelerator (app, "win.new-tab", "<control>t");
- nautilus_application_set_accelerator (app, "win.close-current-view", "<control>w");
-
- /* Special case reload, since users are used to use two shortcuts instead of one */
- gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.reload", reload_accels);
-
- nautilus_application_set_accelerator (app, "win.undo", "<control>z");
- nautilus_application_set_accelerator (app, "win.redo", "<shift><control>z");
- /* Only accesible by shorcuts */
- nautilus_application_set_accelerator (app, "win.bookmark-current-location", "<control>d");
- nautilus_application_set_accelerator (app, "win.up", "<alt>Up");
- nautilus_application_set_accelerator (app, "win.go-home", "<alt>Home");
- nautilus_application_set_accelerator (app, "win.tab-previous", "<control>Page_Up");
- nautilus_application_set_accelerator (app, "win.tab-next", "<control>Page_Down");
- nautilus_application_set_accelerator (app, "win.tab-move-left", "<shift><control>Page_Up");
- nautilus_application_set_accelerator (app, "win.tab-move-right", "<shift><control>Page_Down");
- nautilus_application_set_accelerator (app, "win.prompt-root-location", "slash");
- nautilus_application_set_accelerator (app, "win.prompt-home-location", "asciitilde");
- nautilus_application_set_accelerator (app, "win.view-menu", "F10");
-
- /* Alt+N for the first 9 tabs */
- for (i = 0; i < 9; ++i) {
- g_snprintf (detailed_action, sizeof (detailed_action), "win.go-to-tab(%i)", i);
- g_snprintf (accel, sizeof (accel), "<alt>%i", i + 1);
- nautilus_application_set_accelerator (app, detailed_action, accel);
- }
-
- action = g_action_map_lookup_action (G_ACTION_MAP (app), "show-hide-sidebar");
- state = g_action_get_state (action);
- if (g_variant_get_boolean (state))
- nautilus_window_show_sidebar (window);
-
- g_variant_unref (state);
+ GApplication *app;
+ GAction *action;
+ GVariant *state;
+ gchar detailed_action[80];
+ gchar accel[80];
+ gint i;
+ const gchar *reload_accels[] =
+ {
+ "F5",
+ "<ctrl>r",
+ NULL
+ };
+
+ g_action_map_add_action_entries (G_ACTION_MAP (window),
+ win_entries, G_N_ELEMENTS (win_entries),
+ window);
+
+ app = g_application_get_default ();
+ nautilus_application_set_accelerator (app, "win.back", "<alt>Left");
+ nautilus_application_set_accelerator (app, "win.forward", "<alt>Right");
+ nautilus_application_set_accelerator (app, "win.enter-location", "<control>l");
+ nautilus_application_set_accelerator (app, "win.new-tab", "<control>t");
+ nautilus_application_set_accelerator (app, "win.close-current-view", "<control>w");
+
+ /* Special case reload, since users are used to use two shortcuts instead of one */
+ gtk_application_set_accels_for_action (GTK_APPLICATION (app), "win.reload", reload_accels);
+
+ nautilus_application_set_accelerator (app, "win.undo", "<control>z");
+ nautilus_application_set_accelerator (app, "win.redo", "<shift><control>z");
+ /* Only accesible by shorcuts */
+ nautilus_application_set_accelerator (app, "win.bookmark-current-location", "<control>d");
+ nautilus_application_set_accelerator (app, "win.up", "<alt>Up");
+ nautilus_application_set_accelerator (app, "win.go-home", "<alt>Home");
+ nautilus_application_set_accelerator (app, "win.tab-previous", "<control>Page_Up");
+ nautilus_application_set_accelerator (app, "win.tab-next", "<control>Page_Down");
+ nautilus_application_set_accelerator (app, "win.tab-move-left", "<shift><control>Page_Up");
+ nautilus_application_set_accelerator (app, "win.tab-move-right", "<shift><control>Page_Down");
+ nautilus_application_set_accelerator (app, "win.prompt-root-location", "slash");
+ nautilus_application_set_accelerator (app, "win.prompt-home-location", "asciitilde");
+ nautilus_application_set_accelerator (app, "win.view-menu", "F10");
+
+ /* Alt+N for the first 9 tabs */
+ for (i = 0; i < 9; ++i)
+ {
+ g_snprintf (detailed_action, sizeof (detailed_action), "win.go-to-tab(%i)", i);
+ g_snprintf (accel, sizeof (accel), "<alt>%i", i + 1);
+ nautilus_application_set_accelerator (app, detailed_action, accel);
+ }
+
+ action = g_action_map_lookup_action (G_ACTION_MAP (app), "show-hide-sidebar");
+ state = g_action_get_state (action);
+ if (g_variant_get_boolean (state))
+ {
+ nautilus_window_show_sidebar (window);
+ }
+
+ g_variant_unref (state);
}
static void
nautilus_window_constructed (GObject *self)
{
- NautilusWindow *window;
- NautilusWindowSlot *slot;
- NautilusApplication *application;
+ NautilusWindow *window;
+ NautilusWindowSlot *slot;
+ NautilusApplication *application;
- window = NAUTILUS_WINDOW (self);
+ window = NAUTILUS_WINDOW (self);
- nautilus_profile_start (NULL);
+ nautilus_profile_start (NULL);
- G_OBJECT_CLASS (nautilus_window_parent_class)->constructed (self);
+ G_OBJECT_CLASS (nautilus_window_parent_class)->constructed (self);
- application = NAUTILUS_APPLICATION (g_application_get_default ());
- gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (application));
+ application = NAUTILUS_APPLICATION (g_application_get_default ());
+ gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (application));
- setup_toolbar (window);
+ setup_toolbar (window);
- nautilus_window_set_initial_window_geometry (window);
- setup_notebook (window);
- nautilus_window_set_up_sidebar (window);
+ nautilus_window_set_initial_window_geometry (window);
+ setup_notebook (window);
+ nautilus_window_set_up_sidebar (window);
- g_signal_connect_after (nautilus_file_undo_manager_get (), "undo-changed",
- G_CALLBACK (nautilus_window_on_undo_changed), self);
+ g_signal_connect_after (nautilus_file_undo_manager_get (), "undo-changed",
+ G_CALLBACK (nautilus_window_on_undo_changed), self);
- /* Is required that the UI is constructed before initializating the actions, since
- * some actions trigger UI widgets to show/hide. */
- nautilus_window_initialize_actions (window);
+ /* Is required that the UI is constructed before initializating the actions, since
+ * some actions trigger UI widgets to show/hide. */
+ nautilus_window_initialize_actions (window);
- slot = nautilus_window_create_slot (window, NULL);
- nautilus_window_initialize_slot (window, slot, 0);
- nautilus_window_set_active_slot (window, slot);
+ slot = nautilus_window_create_slot (window, NULL);
+ nautilus_window_initialize_slot (window, slot, 0);
+ nautilus_window_set_active_slot (window, slot);
- window->priv->bookmarks_id =
- g_signal_connect_swapped (nautilus_application_get_bookmarks (application), "changed",
- G_CALLBACK (nautilus_window_sync_bookmarks), window);
+ window->priv->bookmarks_id =
+ g_signal_connect_swapped (nautilus_application_get_bookmarks (application), "changed",
+ G_CALLBACK (nautilus_window_sync_bookmarks), window);
- nautilus_toolbar_on_window_constructed (NAUTILUS_TOOLBAR (window->priv->toolbar));
+ nautilus_toolbar_on_window_constructed (NAUTILUS_TOOLBAR (window->priv->toolbar));
- nautilus_profile_end (NULL);
+ nautilus_profile_end (NULL);
}
static void
-nautilus_window_set_property (GObject *object,
- guint arg_id,
- const GValue *value,
- GParamSpec *pspec)
+nautilus_window_set_property (GObject *object,
+ guint arg_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = NAUTILUS_WINDOW (object);
-
- switch (arg_id) {
- case PROP_DISABLE_CHROME:
- window->priv->disable_chrome = g_value_get_boolean (value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
- break;
- }
+ window = NAUTILUS_WINDOW (object);
+
+ switch (arg_id)
+ {
+ case PROP_DISABLE_CHROME:
+ {
+ window->priv->disable_chrome = g_value_get_boolean (value);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, arg_id, pspec);
+ }
+ break;
+ }
}
static void
-nautilus_window_get_property (GObject *object,
- guint arg_id,
- GValue *value,
- GParamSpec *pspec)
+nautilus_window_get_property (GObject *object,
+ guint arg_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = NAUTILUS_WINDOW (object);
+ window = NAUTILUS_WINDOW (object);
- switch (arg_id) {
- case PROP_DISABLE_CHROME:
- g_value_set_boolean (value, window->priv->disable_chrome);
- break;
- }
+ switch (arg_id)
+ {
+ case PROP_DISABLE_CHROME:
+ {
+ g_value_set_boolean (value, window->priv->disable_chrome);
+ }
+ break;
+ }
}
static gint
-sort_slots_active_last (NautilusWindowSlot *a, NautilusWindowSlot *b, NautilusWindow *window)
+sort_slots_active_last (NautilusWindowSlot *a,
+ NautilusWindowSlot *b,
+ NautilusWindow *window)
{
- if (window->priv->active_slot == a) {
- return 1;
- }
- if (window->priv->active_slot == b) {
- return -1;
- }
- return 0;
+ if (window->priv->active_slot == a)
+ {
+ return 1;
+ }
+ if (window->priv->active_slot == b)
+ {
+ return -1;
+ }
+ return 0;
}
static void
destroy_slots_foreach (gpointer data,
- gpointer user_data)
+ gpointer user_data)
{
- NautilusWindowSlot *slot = data;
- NautilusWindow *window = user_data;
+ NautilusWindowSlot *slot = data;
+ NautilusWindow *window = user_data;
- close_slot (window, slot, TRUE);
+ close_slot (window, slot, TRUE);
}
static void
nautilus_window_destroy (GtkWidget *object)
{
- NautilusWindow *window;
- NautilusApplication *application;
- GList *slots_copy;
+ NautilusWindow *window;
+ NautilusApplication *application;
+ GList *slots_copy;
- window = NAUTILUS_WINDOW (object);
+ window = NAUTILUS_WINDOW (object);
- DEBUG ("Destroying window");
+ DEBUG ("Destroying window");
- /* close all slots safely */
- slots_copy = g_list_copy (window->priv->slots);
- if (window->priv->active_slot != NULL) {
- /* Make sure active slot is last one to be closed, to avoid default activation
- * of others slots when closing the active one, see bug #741952 */
- slots_copy = g_list_sort_with_data (slots_copy, (GCompareDataFunc) sort_slots_active_last, window);
- }
- g_list_foreach (slots_copy, (GFunc) destroy_slots_foreach, window);
- g_list_free (slots_copy);
+ /* close all slots safely */
+ slots_copy = g_list_copy (window->priv->slots);
+ if (window->priv->active_slot != NULL)
+ {
+ /* Make sure active slot is last one to be closed, to avoid default activation
+ * of others slots when closing the active one, see bug #741952 */
+ slots_copy = g_list_sort_with_data (slots_copy, (GCompareDataFunc) sort_slots_active_last, window);
+ }
+ g_list_foreach (slots_copy, (GFunc) destroy_slots_foreach, window);
+ g_list_free (slots_copy);
- /* the slots list should now be empty */
- g_assert (window->priv->slots == NULL);
+ /* the slots list should now be empty */
+ g_assert (window->priv->slots == NULL);
- window->priv->active_slot = NULL;
+ window->priv->active_slot = NULL;
- if (window->priv->bookmarks_id != 0) {
- application = NAUTILUS_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
- g_signal_handler_disconnect (nautilus_application_get_bookmarks (application),
- window->priv->bookmarks_id);
- window->priv->bookmarks_id = 0;
- }
+ if (window->priv->bookmarks_id != 0)
+ {
+ application = NAUTILUS_APPLICATION (gtk_window_get_application (GTK_WINDOW (window)));
+ g_signal_handler_disconnect (nautilus_application_get_bookmarks (application),
+ window->priv->bookmarks_id);
+ window->priv->bookmarks_id = 0;
+ }
- GTK_WIDGET_CLASS (nautilus_window_parent_class)->destroy (object);
+ GTK_WIDGET_CLASS (nautilus_window_parent_class)->destroy (object);
}
static void
nautilus_window_finalize (GObject *object)
{
- NautilusWindow *window;
+ NautilusWindow *window;
- window = NAUTILUS_WINDOW (object);
+ window = NAUTILUS_WINDOW (object);
- if (window->priv->sidebar_width_handler_id != 0) {
- g_source_remove (window->priv->sidebar_width_handler_id);
- window->priv->sidebar_width_handler_id = 0;
- }
+ if (window->priv->sidebar_width_handler_id != 0)
+ {
+ g_source_remove (window->priv->sidebar_width_handler_id);
+ window->priv->sidebar_width_handler_id = 0;
+ }
- if (window->priv->notification_delete_timeout_id != 0) {
- g_source_remove (window->priv->notification_delete_timeout_id);
- window->priv->notification_delete_timeout_id = 0;
- }
+ if (window->priv->notification_delete_timeout_id != 0)
+ {
+ g_source_remove (window->priv->notification_delete_timeout_id);
+ window->priv->notification_delete_timeout_id = 0;
+ }
- if (window->priv->notification_operation_timeout_id != 0) {
- g_source_remove (window->priv->notification_operation_timeout_id);
- window->priv->notification_operation_timeout_id = 0;
- }
+ if (window->priv->notification_operation_timeout_id != 0)
+ {
+ g_source_remove (window->priv->notification_operation_timeout_id);
+ window->priv->notification_operation_timeout_id = 0;
+ }
- g_clear_object (&window->priv->selected_file);
- g_clear_object (&window->priv->selected_volume);
+ g_clear_object (&window->priv->selected_file);
+ g_clear_object (&window->priv->selected_volume);
- g_signal_handlers_disconnect_by_func (nautilus_file_undo_manager_get (),
- G_CALLBACK (nautilus_window_on_undo_changed),
- window);
+ g_signal_handlers_disconnect_by_func (nautilus_file_undo_manager_get (),
+ G_CALLBACK (nautilus_window_on_undo_changed),
+ window);
- /* nautilus_window_close() should have run */
- g_assert (window->priv->slots == NULL);
+ /* nautilus_window_close() should have run */
+ g_assert (window->priv->slots == NULL);
- G_OBJECT_CLASS (nautilus_window_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_window_parent_class)->finalize (object);
}
static void
nautilus_window_save_geometry (NautilusWindow *window)
{
- char *geometry_string;
- gboolean is_maximized;
-
- g_assert (NAUTILUS_IS_WINDOW (window));
+ char *geometry_string;
+ gboolean is_maximized;
- if (gtk_widget_get_window (GTK_WIDGET (window))) {
- geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
- is_maximized = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)))
- & GDK_WINDOW_STATE_MAXIMIZED;
+ g_assert (NAUTILUS_IS_WINDOW (window));
- if (!is_maximized) {
- g_settings_set_string
- (nautilus_window_state, NAUTILUS_WINDOW_STATE_GEOMETRY,
- geometry_string);
- }
- g_free (geometry_string);
+ if (gtk_widget_get_window (GTK_WIDGET (window)))
+ {
+ geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
+ is_maximized = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)))
+ & GDK_WINDOW_STATE_MAXIMIZED;
+
+ if (!is_maximized)
+ {
+ g_settings_set_string
+ (nautilus_window_state, NAUTILUS_WINDOW_STATE_GEOMETRY,
+ geometry_string);
+ }
+ g_free (geometry_string);
- g_settings_set_boolean
- (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED,
- is_maximized);
- }
+ g_settings_set_boolean
+ (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED,
+ is_maximized);
+ }
}
void
nautilus_window_close (NautilusWindow *window)
{
- NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->close (window);
+ NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->close (window);
}
void
-nautilus_window_set_active_slot (NautilusWindow *window, NautilusWindowSlot *new_slot)
+nautilus_window_set_active_slot (NautilusWindow *window,
+ NautilusWindowSlot *new_slot)
{
- NautilusWindowSlot *old_slot;
+ NautilusWindowSlot *old_slot;
- g_assert (NAUTILUS_IS_WINDOW (window));
+ g_assert (NAUTILUS_IS_WINDOW (window));
- if (new_slot) {
- g_assert ((window == nautilus_window_slot_get_window (new_slot)));
- }
+ if (new_slot)
+ {
+ g_assert ((window == nautilus_window_slot_get_window (new_slot)));
+ }
- old_slot = nautilus_window_get_active_slot (window);
+ old_slot = nautilus_window_get_active_slot (window);
- if (old_slot == new_slot) {
- return;
- }
+ if (old_slot == new_slot)
+ {
+ return;
+ }
- DEBUG ("Setting new slot %p as active, old slot inactive %p", new_slot, old_slot);
+ DEBUG ("Setting new slot %p as active, old slot inactive %p", new_slot, old_slot);
- /* make old slot inactive if it exists (may be NULL after init, for example) */
- if (old_slot != NULL) {
- /* inform slot & view */
- nautilus_window_slot_set_active (old_slot, FALSE);
- }
+ /* make old slot inactive if it exists (may be NULL after init, for example) */
+ if (old_slot != NULL)
+ {
+ /* inform slot & view */
+ nautilus_window_slot_set_active (old_slot, FALSE);
+ }
- window->priv->active_slot = new_slot;
+ window->priv->active_slot = new_slot;
- /* make new slot active, if it exists */
- if (new_slot) {
- nautilus_toolbar_set_active_slot (NAUTILUS_TOOLBAR (window->priv->toolbar), new_slot);
+ /* make new slot active, if it exists */
+ if (new_slot)
+ {
+ nautilus_toolbar_set_active_slot (NAUTILUS_TOOLBAR (window->priv->toolbar), new_slot);
- /* inform slot & view */
- nautilus_window_slot_set_active (new_slot, TRUE);
+ /* inform slot & view */
+ nautilus_window_slot_set_active (new_slot, TRUE);
- on_location_changed (window);
- }
+ on_location_changed (window);
+ }
}
static void
nautilus_window_realize (GtkWidget *widget)
{
- GTK_WIDGET_CLASS (nautilus_window_parent_class)->realize (widget);
- update_cursor (NAUTILUS_WINDOW (widget));
+ GTK_WIDGET_CLASS (nautilus_window_parent_class)->realize (widget);
+ update_cursor (NAUTILUS_WINDOW (widget));
}
static gboolean
-nautilus_window_key_press_event (GtkWidget *widget,
- GdkEventKey *event)
+nautilus_window_key_press_event (GtkWidget *widget,
+ GdkEventKey *event)
{
- NautilusWindow *window;
- GtkWidget *focus_widget;
- int i;
+ NautilusWindow *window;
+ GtkWidget *focus_widget;
+ int i;
- window = NAUTILUS_WINDOW (widget);
+ window = NAUTILUS_WINDOW (widget);
- focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
- if (focus_widget != NULL && GTK_IS_EDITABLE (focus_widget)) {
- /* if we have input focus on a GtkEditable (e.g. a GtkEntry), forward
- * the event to it before activating accelerator bindings too.
- */
- if (gtk_window_propagate_key_event (GTK_WINDOW (window), event)) {
- return TRUE;
- }
- }
+ focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
+ if (focus_widget != NULL && GTK_IS_EDITABLE (focus_widget))
+ {
+ /* if we have input focus on a GtkEditable (e.g. a GtkEntry), forward
+ * the event to it before activating accelerator bindings too.
+ */
+ if (gtk_window_propagate_key_event (GTK_WINDOW (window), event))
+ {
+ return TRUE;
+ }
+ }
- for (i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++) {
- if (extra_window_keybindings[i].keyval == event->keyval) {
- GAction *action;
+ for (i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++)
+ {
+ if (extra_window_keybindings[i].keyval == event->keyval)
+ {
+ GAction *action;
- action = g_action_map_lookup_action (G_ACTION_MAP (window), extra_window_keybindings[i].action);
+ action = g_action_map_lookup_action (G_ACTION_MAP (window), extra_window_keybindings[i].action);
- g_assert (action != NULL);
- if (g_action_get_enabled (action)) {
- g_action_activate (action, NULL);
- return TRUE;
- }
+ g_assert (action != NULL);
+ if (g_action_get_enabled (action))
+ {
+ g_action_activate (action, NULL);
+ return TRUE;
+ }
- break;
- }
- }
+ break;
+ }
+ }
- if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event)) {
- return TRUE;
- }
+ if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event))
+ {
+ return TRUE;
+ }
- if (nautilus_window_slot_handle_event (window->priv->active_slot, event)) {
- return TRUE;
- }
+ if (nautilus_window_slot_handle_event (window->priv->active_slot, event))
+ {
+ return TRUE;
+ }
- return FALSE;
+ return FALSE;
}
void
-nautilus_window_sync_title (NautilusWindow *window,
- NautilusWindowSlot *slot)
+nautilus_window_sync_title (NautilusWindow *window,
+ NautilusWindowSlot *slot)
{
- if (NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->sync_title != NULL) {
- NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->sync_title (window, slot);
+ if (NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->sync_title != NULL)
+ {
+ NAUTILUS_WINDOW_CLASS (G_OBJECT_GET_CLASS (window))->sync_title (window, slot);
- return;
- }
+ return;
+ }
- if (slot == nautilus_window_get_active_slot (window)) {
- gtk_window_set_title (GTK_WINDOW (window), nautilus_window_slot_get_title (slot));
- }
+ if (slot == nautilus_window_get_active_slot (window))
+ {
+ gtk_window_set_title (GTK_WINDOW (window), nautilus_window_slot_get_title (slot));
+ }
- nautilus_notebook_sync_tab_label (NAUTILUS_NOTEBOOK (window->priv->notebook), slot);
+ nautilus_notebook_sync_tab_label (NAUTILUS_NOTEBOOK (window->priv->notebook), slot);
}
/**
* nautilus_window_show:
- * @widget: GtkWidget
+ * @widget: GtkWidget
*
* Call parent and then show/hide window items
* base on user prefs.
@@ -2437,336 +2582,357 @@ nautilus_window_sync_title (NautilusWindow *window,
static void
nautilus_window_show (GtkWidget *widget)
{
- GTK_WIDGET_CLASS (nautilus_window_parent_class)->show (widget);
+ GTK_WIDGET_CLASS (nautilus_window_parent_class)->show (widget);
}
NautilusWindowSlot *
nautilus_window_get_active_slot (NautilusWindow *window)
{
- g_assert (NAUTILUS_IS_WINDOW (window));
+ g_assert (NAUTILUS_IS_WINDOW (window));
- return window->priv->active_slot;
+ return window->priv->active_slot;
}
GList *
nautilus_window_get_slots (NautilusWindow *window)
{
- g_assert (NAUTILUS_IS_WINDOW (window));
+ g_assert (NAUTILUS_IS_WINDOW (window));
- return window->priv->slots;
+ return window->priv->slots;
}
static gboolean
-nautilus_window_state_event (GtkWidget *widget,
- GdkEventWindowState *event)
+nautilus_window_state_event (GtkWidget *widget,
+ GdkEventWindowState *event)
{
- if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED) {
- g_settings_set_boolean (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED,
- event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED);
- }
+ if (event->changed_mask & GDK_WINDOW_STATE_MAXIMIZED)
+ {
+ g_settings_set_boolean (nautilus_window_state, NAUTILUS_WINDOW_STATE_MAXIMIZED,
+ event->new_window_state & GDK_WINDOW_STATE_MAXIMIZED);
+ }
- if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->window_state_event != NULL) {
- return GTK_WIDGET_CLASS (nautilus_window_parent_class)->window_state_event (widget, event);
- }
+ if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->window_state_event != NULL)
+ {
+ return GTK_WIDGET_CLASS (nautilus_window_parent_class)->window_state_event (widget, event);
+ }
- return FALSE;
+ return FALSE;
}
static gboolean
-nautilus_window_delete_event (GtkWidget *widget,
- GdkEventAny *event)
+nautilus_window_delete_event (GtkWidget *widget,
+ GdkEventAny *event)
{
- nautilus_window_close (NAUTILUS_WINDOW (widget));
- return FALSE;
+ nautilus_window_close (NAUTILUS_WINDOW (widget));
+ return FALSE;
}
static gboolean
-nautilus_window_button_press_event (GtkWidget *widget,
- GdkEventButton *event)
+nautilus_window_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
{
- NautilusWindow *window;
- gboolean handled;
+ NautilusWindow *window;
+ gboolean handled;
- window = NAUTILUS_WINDOW (widget);
+ window = NAUTILUS_WINDOW (widget);
- if (mouse_extra_buttons && (event->button == mouse_back_button)) {
- nautilus_window_back_or_forward (window, TRUE, 0, 0);
- handled = TRUE;
- } else if (mouse_extra_buttons && (event->button == mouse_forward_button)) {
- nautilus_window_back_or_forward (window, FALSE, 0, 0);
- handled = TRUE;
- } else if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->button_press_event) {
- handled = GTK_WIDGET_CLASS (nautilus_window_parent_class)->button_press_event (widget, event);
- } else {
- handled = FALSE;
- }
- return handled;
+ if (mouse_extra_buttons && (event->button == mouse_back_button))
+ {
+ nautilus_window_back_or_forward (window, TRUE, 0, 0);
+ handled = TRUE;
+ }
+ else if (mouse_extra_buttons && (event->button == mouse_forward_button))
+ {
+ nautilus_window_back_or_forward (window, FALSE, 0, 0);
+ handled = TRUE;
+ }
+ else if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->button_press_event)
+ {
+ handled = GTK_WIDGET_CLASS (nautilus_window_parent_class)->button_press_event (widget, event);
+ }
+ else
+ {
+ handled = FALSE;
+ }
+ return handled;
}
static void
mouse_back_button_changed (gpointer callback_data)
{
- int new_back_button;
+ int new_back_button;
- new_back_button = g_settings_get_int (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON);
+ new_back_button = g_settings_get_int (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON);
- /* Bounds checking */
- if (new_back_button < 6 || new_back_button > UPPER_MOUSE_LIMIT)
- return;
+ /* Bounds checking */
+ if (new_back_button < 6 || new_back_button > UPPER_MOUSE_LIMIT)
+ {
+ return;
+ }
- mouse_back_button = new_back_button;
+ mouse_back_button = new_back_button;
}
static void
mouse_forward_button_changed (gpointer callback_data)
{
- int new_forward_button;
+ int new_forward_button;
- new_forward_button = g_settings_get_int (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON);
+ new_forward_button = g_settings_get_int (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON);
- /* Bounds checking */
- if (new_forward_button < 6 || new_forward_button > UPPER_MOUSE_LIMIT)
- return;
+ /* Bounds checking */
+ if (new_forward_button < 6 || new_forward_button > UPPER_MOUSE_LIMIT)
+ {
+ return;
+ }
- mouse_forward_button = new_forward_button;
+ mouse_forward_button = new_forward_button;
}
static void
use_extra_mouse_buttons_changed (gpointer callback_data)
{
- mouse_extra_buttons = g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS);
+ mouse_extra_buttons = g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS);
}
static void
nautilus_window_init (NautilusWindow *window)
{
- GtkWindowGroup *window_group;
+ GtkWindowGroup *window_group;
- window->priv = nautilus_window_get_instance_private (window);
+ window->priv = nautilus_window_get_instance_private (window);
- g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
- g_type_ensure (NAUTILUS_TYPE_NOTEBOOK);
- gtk_widget_init_template (GTK_WIDGET (window));
+ g_type_ensure (NAUTILUS_TYPE_TOOLBAR);
+ g_type_ensure (NAUTILUS_TYPE_NOTEBOOK);
+ gtk_widget_init_template (GTK_WIDGET (window));
- g_signal_connect_object (window->priv->notification_delete_close, "clicked",
- G_CALLBACK (nautilus_window_on_notification_delete_close_clicked), window, 0);
- g_signal_connect_object (window->priv->notification_delete_undo, "clicked",
- G_CALLBACK (nautilus_window_on_notification_delete_undo_clicked), window, 0);
+ g_signal_connect_object (window->priv->notification_delete_close, "clicked",
+ G_CALLBACK (nautilus_window_on_notification_delete_close_clicked), window, 0);
+ g_signal_connect_object (window->priv->notification_delete_undo, "clicked",
+ G_CALLBACK (nautilus_window_on_notification_delete_undo_clicked), window, 0);
- window->priv->slots = NULL;
- window->priv->active_slot = NULL;
+ window->priv->slots = NULL;
+ window->priv->active_slot = NULL;
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (window)),
- "nautilus-window");
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (window)),
+ "nautilus-window");
- window_group = gtk_window_group_new ();
- gtk_window_group_add_window (window_group, GTK_WINDOW (window));
- g_object_unref (window_group);
+ window_group = gtk_window_group_new ();
+ gtk_window_group_add_window (window_group, GTK_WINDOW (window));
+ g_object_unref (window_group);
}
static void
real_window_close (NautilusWindow *window)
{
- g_return_if_fail (NAUTILUS_IS_WINDOW (window));
+ g_return_if_fail (NAUTILUS_IS_WINDOW (window));
- nautilus_window_save_geometry (window);
+ nautilus_window_save_geometry (window);
- gtk_widget_destroy (GTK_WIDGET (window));
+ gtk_widget_destroy (GTK_WIDGET (window));
}
static void
nautilus_window_class_init (NautilusWindowClass *class)
{
- GObjectClass *oclass = G_OBJECT_CLASS (class);
- GtkWidgetClass *wclass = GTK_WIDGET_CLASS (class);
-
- oclass->finalize = nautilus_window_finalize;
- oclass->constructed = nautilus_window_constructed;
- oclass->get_property = nautilus_window_get_property;
- oclass->set_property = nautilus_window_set_property;
-
- wclass->destroy = nautilus_window_destroy;
- wclass->show = nautilus_window_show;
- wclass->realize = nautilus_window_realize;
- wclass->key_press_event = nautilus_window_key_press_event;
- wclass->window_state_event = nautilus_window_state_event;
- wclass->button_press_event = nautilus_window_button_press_event;
- wclass->delete_event = nautilus_window_delete_event;
- wclass->grab_focus = nautilus_window_grab_focus;
-
- class->close = real_window_close;
- class->create_slot = real_create_slot;
-
- gtk_widget_class_set_template_from_resource (wclass,
- "/org/gnome/nautilus/ui/nautilus-window.ui");
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, toolbar);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, content_paned);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, sidebar);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, places_sidebar);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, main_view);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notebook);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_label);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_undo);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_close);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation_label);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation_open);
- gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation_close);
-
- gtk_widget_class_bind_template_callback (wclass, places_sidebar_show_other_locations_with_flags);
-
- properties[PROP_DISABLE_CHROME] =
- g_param_spec_boolean ("disable-chrome",
- "Disable chrome",
- "Disable window chrome, for the desktop",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
- signals[SLOT_ADDED] =
- g_signal_new ("slot-added",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, NAUTILUS_TYPE_WINDOW_SLOT);
- signals[SLOT_REMOVED] =
- g_signal_new ("slot-removed",
- G_TYPE_FROM_CLASS (class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, NAUTILUS_TYPE_WINDOW_SLOT);
-
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON,
- G_CALLBACK(mouse_back_button_changed),
- NULL);
-
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON,
- G_CALLBACK(mouse_forward_button_changed),
- NULL);
-
- g_signal_connect_swapped (nautilus_preferences,
- "changed::" NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS,
- G_CALLBACK(use_extra_mouse_buttons_changed),
- NULL);
-
- gtk_widget_class_bind_template_callback (wclass, on_notification_operation_open_clicked);
- gtk_widget_class_bind_template_callback (wclass, on_notification_operation_close_clicked);
-
- g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
+ GObjectClass *oclass = G_OBJECT_CLASS (class);
+ GtkWidgetClass *wclass = GTK_WIDGET_CLASS (class);
+
+ oclass->finalize = nautilus_window_finalize;
+ oclass->constructed = nautilus_window_constructed;
+ oclass->get_property = nautilus_window_get_property;
+ oclass->set_property = nautilus_window_set_property;
+
+ wclass->destroy = nautilus_window_destroy;
+ wclass->show = nautilus_window_show;
+ wclass->realize = nautilus_window_realize;
+ wclass->key_press_event = nautilus_window_key_press_event;
+ wclass->window_state_event = nautilus_window_state_event;
+ wclass->button_press_event = nautilus_window_button_press_event;
+ wclass->delete_event = nautilus_window_delete_event;
+ wclass->grab_focus = nautilus_window_grab_focus;
+
+ class->close = real_window_close;
+ class->create_slot = real_create_slot;
+
+ gtk_widget_class_set_template_from_resource (wclass,
+ "/org/gnome/nautilus/ui/nautilus-window.ui");
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, toolbar);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, content_paned);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, sidebar);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, places_sidebar);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, main_view);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notebook);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_label);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_undo);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_delete_close);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation_label);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation_open);
+ gtk_widget_class_bind_template_child_private (wclass, NautilusWindow, notification_operation_close);
+
+ gtk_widget_class_bind_template_callback (wclass, places_sidebar_show_other_locations_with_flags);
+
+ properties[PROP_DISABLE_CHROME] =
+ g_param_spec_boolean ("disable-chrome",
+ "Disable chrome",
+ "Disable window chrome, for the desktop",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
+ signals[SLOT_ADDED] =
+ g_signal_new ("slot-added",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, NAUTILUS_TYPE_WINDOW_SLOT);
+ signals[SLOT_REMOVED] =
+ g_signal_new ("slot-removed",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1, NAUTILUS_TYPE_WINDOW_SLOT);
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_MOUSE_BACK_BUTTON,
+ G_CALLBACK (mouse_back_button_changed),
+ NULL);
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_MOUSE_FORWARD_BUTTON,
+ G_CALLBACK (mouse_forward_button_changed),
+ NULL);
+
+ g_signal_connect_swapped (nautilus_preferences,
+ "changed::" NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS,
+ G_CALLBACK (use_extra_mouse_buttons_changed),
+ NULL);
+
+ gtk_widget_class_bind_template_callback (wclass, on_notification_operation_open_clicked);
+ gtk_widget_class_bind_template_callback (wclass, on_notification_operation_close_clicked);
+
+ g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
NautilusWindow *
nautilus_window_new (GdkScreen *screen)
{
- return g_object_new (NAUTILUS_TYPE_WINDOW,
- "screen", screen,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_WINDOW,
+ "screen", screen,
+ NULL);
}
NautilusWindowOpenFlags
nautilus_event_get_window_open_flags (void)
{
- NautilusWindowOpenFlags flags = 0;
- GdkEvent *event;
+ NautilusWindowOpenFlags flags = 0;
+ GdkEvent *event;
- event = gtk_get_current_event ();
+ event = gtk_get_current_event ();
- if (event == NULL) {
- return flags;
- }
+ if (event == NULL)
+ {
+ return flags;
+ }
- if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) &&
- (event->button.button == 2)) {
- flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
- }
+ if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) &&
+ (event->button.button == 2))
+ {
+ flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
+ }
- gdk_event_free (event);
+ gdk_event_free (event);
- return flags;
+ return flags;
}
void
nautilus_window_show_about_dialog (NautilusWindow *window)
{
- const gchar *authors[] = {
- "Alexander Larsson",
- "Ali Abdin",
- "Anders Carlsson",
- "Andrew Walton",
- "Andy Hertzfeld",
- "Arlo Rose",
- "Christian Neumair",
- "Cosimo Cecchi",
- "Darin Adler",
- "David Camp",
- "Eli Goldberg",
- "Elliot Lee",
- "Eskil Heyn Olsen",
- "Ettore Perazzoli",
- "Gene Z. Ragan",
- "George Lebl",
- "Ian McKellar",
- "J Shane Culpepper",
- "James Willcox",
- "Jan Arne Petersen",
- "John Harper",
- "John Sullivan",
- "Josh Barrow",
- "Maciej Stachowiak",
- "Mark McLoughlin",
- "Mathieu Lacage",
- "Mike Engber",
- "Mike Fleming",
- "Pavel Cisler",
- "Ramiro Estrugo",
- "Raph Levien",
- "Rebecca Schulman",
- "Robey Pointer",
- "Robin * Slomkowski",
- "Seth Nickell",
- "Susan Kare",
- "Tomas Bzatek",
- "William Jon McCann",
- NULL
- };
- const gchar *documenters[] = {
- "GNOME Documentation Team",
- "Sun Microsystems",
- NULL
- };
-
- gtk_show_about_dialog (window ? GTK_WINDOW (window) : NULL,
- "program-name", _("Files"),
- "version", VERSION,
- "comments", _("Access and organize your files."),
- "copyright", "Copyright © 1999–2016 The Files Authors",
- "license-type", GTK_LICENSE_GPL_2_0,
- "authors", authors,
- "documenters", documenters,
- /* Translators should localize the following string
- * which will be displayed at the bottom of the about
- * box to give credit to the translator(s).
- */
- "translator-credits", _("translator-credits"),
- "logo-icon-name", "system-file-manager",
- NULL);
+ const gchar *authors[] =
+ {
+ "Alexander Larsson",
+ "Ali Abdin",
+ "Anders Carlsson",
+ "Andrew Walton",
+ "Andy Hertzfeld",
+ "Arlo Rose",
+ "Christian Neumair",
+ "Cosimo Cecchi",
+ "Darin Adler",
+ "David Camp",
+ "Eli Goldberg",
+ "Elliot Lee",
+ "Eskil Heyn Olsen",
+ "Ettore Perazzoli",
+ "Gene Z. Ragan",
+ "George Lebl",
+ "Ian McKellar",
+ "J Shane Culpepper",
+ "James Willcox",
+ "Jan Arne Petersen",
+ "John Harper",
+ "John Sullivan",
+ "Josh Barrow",
+ "Maciej Stachowiak",
+ "Mark McLoughlin",
+ "Mathieu Lacage",
+ "Mike Engber",
+ "Mike Fleming",
+ "Pavel Cisler",
+ "Ramiro Estrugo",
+ "Raph Levien",
+ "Rebecca Schulman",
+ "Robey Pointer",
+ "Robin * Slomkowski",
+ "Seth Nickell",
+ "Susan Kare",
+ "Tomas Bzatek",
+ "William Jon McCann",
+ NULL
+ };
+ const gchar *documenters[] =
+ {
+ "GNOME Documentation Team",
+ "Sun Microsystems",
+ NULL
+ };
+
+ gtk_show_about_dialog (window ? GTK_WINDOW (window) : NULL,
+ "program-name", _("Files"),
+ "version", VERSION,
+ "comments", _("Access and organize your files."),
+ "copyright", "Copyright © 1999–2016 The Files Authors",
+ "license-type", GTK_LICENSE_GPL_2_0,
+ "authors", authors,
+ "documenters", documenters,
+ /* Translators should localize the following string
+ * which will be displayed at the bottom of the about
+ * box to give credit to the translator(s).
+ */
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "system-file-manager",
+ NULL);
}
void
nautilus_window_search (NautilusWindow *window,
const gchar *text)
{
- NautilusWindowSlot *active_slot;
+ NautilusWindowSlot *active_slot;
- active_slot = nautilus_window_get_active_slot (window);
- if (active_slot)
- nautilus_window_slot_search (active_slot, text);
- else
- g_warning ("Trying search on a slot but no active slot present");
+ active_slot = nautilus_window_get_active_slot (window);
+ if (active_slot)
+ {
+ nautilus_window_slot_search (active_slot, text);
+ }
+ else
+ {
+ g_warning ("Trying search on a slot but no active slot present");
+ }
}
diff --git a/src/nautilus-x-content-bar.c b/src/nautilus-x-content-bar.c
index af633106b..74988e810 100644
--- a/src/nautilus-x-content-bar.c
+++ b/src/nautilus-x-content-bar.c
@@ -35,277 +35,326 @@
struct NautilusXContentBarPrivate
{
- GtkWidget *label;
+ GtkWidget *label;
- char **x_content_types;
- GMount *mount;
+ char **x_content_types;
+ GMount *mount;
};
-enum {
- PROP_0,
- PROP_MOUNT,
- PROP_X_CONTENT_TYPES,
+enum
+{
+ PROP_0,
+ PROP_MOUNT,
+ PROP_X_CONTENT_TYPES,
};
-enum {
- CONTENT_BAR_RESPONSE_APP = 1
+enum
+{
+ CONTENT_BAR_RESPONSE_APP = 1
};
G_DEFINE_TYPE (NautilusXContentBar, nautilus_x_content_bar, GTK_TYPE_INFO_BAR)
static void
content_bar_response_cb (GtkInfoBar *infobar,
- gint response_id,
- gpointer user_data)
+ gint response_id,
+ gpointer user_data)
{
- GAppInfo *default_app;
- NautilusXContentBar *bar = user_data;
-
- if (response_id < 0) {
- return;
- }
-
- if (bar->priv->x_content_types == NULL ||
- bar->priv->mount == NULL)
- return;
-
- /* FIXME */
- default_app = g_app_info_get_default_for_type (bar->priv->x_content_types[response_id], FALSE);
- if (default_app != NULL) {
- nautilus_launch_application_for_mount (default_app, bar->priv->mount,
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (bar))));
- g_object_unref (default_app);
- }
+ GAppInfo *default_app;
+ NautilusXContentBar *bar = user_data;
+
+ if (response_id < 0)
+ {
+ return;
+ }
+
+ if (bar->priv->x_content_types == NULL ||
+ bar->priv->mount == NULL)
+ {
+ return;
+ }
+
+ /* FIXME */
+ default_app = g_app_info_get_default_for_type (bar->priv->x_content_types[response_id], FALSE);
+ if (default_app != NULL)
+ {
+ nautilus_launch_application_for_mount (default_app, bar->priv->mount,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (bar))));
+ g_object_unref (default_app);
+ }
}
static void
-nautilus_x_content_bar_set_x_content_types (NautilusXContentBar *bar, const char * const *x_content_types)
+nautilus_x_content_bar_set_x_content_types (NautilusXContentBar *bar,
+ const char * const *x_content_types)
{
- char *message = NULL;
- guint num_types;
- guint n;
- GPtrArray *types;
- GPtrArray *apps;
- GAppInfo *default_app;
-
- g_strfreev (bar->priv->x_content_types);
-
- if (!should_handle_content_types (x_content_types)) {
- g_warning ("Content types in content types bar cannot be handled. Check before creating the content bar if they can be handled.");
- return;
+ char *message = NULL;
+ guint num_types;
+ guint n;
+ GPtrArray *types;
+ GPtrArray *apps;
+ GAppInfo *default_app;
+
+ g_strfreev (bar->priv->x_content_types);
+
+ if (!should_handle_content_types (x_content_types))
+ {
+ g_warning ("Content types in content types bar cannot be handled. Check before creating the content bar if they can be handled.");
+ return;
+ }
+
+ types = g_ptr_array_new ();
+ apps = g_ptr_array_new ();
+ g_ptr_array_set_free_func (apps, g_object_unref);
+ for (n = 0; x_content_types[n] != NULL; n++)
+ {
+ if (!should_handle_content_type (x_content_types[n]))
+ {
+ continue;
+ }
+
+ default_app = g_app_info_get_default_for_type (x_content_types[n], FALSE);
+ g_ptr_array_add (types, g_strdup (x_content_types[n]));
+ g_ptr_array_add (apps, default_app);
+ }
+
+ num_types = types->len;
+ g_ptr_array_add (types, NULL);
+
+ bar->priv->x_content_types = (char **) g_ptr_array_free (types, FALSE);
+
+ switch (num_types)
+ {
+ case 1:
+ {
+ message = get_message_for_content_type (bar->priv->x_content_types[0]);
+ }
+ break;
+
+ case 2:
+ {
+ message = get_message_for_two_content_types ((const char * const *) bar->priv->x_content_types);
+ }
+ break;
+
+ default:
+ {
+ message = g_strdup (_("Open with:"));
+ }
+ break;
+ }
+
+ gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
+ g_free (message);
+
+ gtk_widget_show (bar->priv->label);
+
+ for (n = 0; bar->priv->x_content_types[n] != NULL; n++)
+ {
+ const char *name;
+ GIcon *icon;
+ GtkWidget *image;
+ GtkWidget *button;
+ GAppInfo *app;
+ gboolean has_app;
+ guint i;
+
+ default_app = g_ptr_array_index (apps, n);
+ has_app = FALSE;
+
+ for (i = 0; i < n; i++)
+ {
+ app = g_ptr_array_index (apps, i);
+ if (g_app_info_equal (app, default_app))
+ {
+ has_app = TRUE;
+ break;
+ }
+ }
+
+ if (has_app)
+ {
+ continue;
+ }
+
+ icon = g_app_info_get_icon (default_app);
+ if (icon != NULL)
+ {
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_BUTTON);
+ }
+ else
+ {
+ image = NULL;
}
- types = g_ptr_array_new ();
- apps = g_ptr_array_new ();
- g_ptr_array_set_free_func (apps, g_object_unref);
- for (n = 0; x_content_types[n] != NULL; n++) {
- if (!should_handle_content_type (x_content_types[n]))
- continue;
-
- default_app = g_app_info_get_default_for_type (x_content_types[n], FALSE);
- g_ptr_array_add (types, g_strdup (x_content_types[n]));
- g_ptr_array_add (apps, default_app);
- }
-
- num_types = types->len;
- g_ptr_array_add (types, NULL);
-
- bar->priv->x_content_types = (char **) g_ptr_array_free (types, FALSE);
-
- switch (num_types) {
- case 1:
- message = get_message_for_content_type (bar->priv->x_content_types[0]);
- break;
- case 2:
- message = get_message_for_two_content_types ((const char* const *) bar->priv->x_content_types);
- break;
- default:
- message = g_strdup (_("Open with:"));
- break;
- }
-
- gtk_label_set_text (GTK_LABEL (bar->priv->label), message);
- g_free (message);
-
- gtk_widget_show (bar->priv->label);
-
- for (n = 0; bar->priv->x_content_types[n] != NULL; n++) {
- const char *name;
- GIcon *icon;
- GtkWidget *image;
- GtkWidget *button;
- GAppInfo *app;
- gboolean has_app;
- guint i;
-
- default_app = g_ptr_array_index (apps, n);
- has_app = FALSE;
-
- for (i = 0; i < n; i++) {
- app = g_ptr_array_index (apps, i);
- if (g_app_info_equal (app, default_app)) {
- has_app = TRUE;
- break;
- }
- }
-
- if (has_app) {
- continue;
- }
-
- icon = g_app_info_get_icon (default_app);
- if (icon != NULL) {
- image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_BUTTON);
- } else {
- image = NULL;
- }
-
- name = g_app_info_get_name (default_app);
- button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
- name,
- n);
-
- gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
- gtk_button_set_label (GTK_BUTTON (button), name);
- gtk_widget_show (button);
- }
-
- g_ptr_array_free (apps, TRUE);
+ name = g_app_info_get_name (default_app);
+ button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+ name,
+ n);
+
+ gtk_button_set_image (GTK_BUTTON (button), image);
+ gtk_button_set_always_show_image (GTK_BUTTON (button), TRUE);
+ gtk_button_set_label (GTK_BUTTON (button), name);
+ gtk_widget_show (button);
+ }
+
+ g_ptr_array_free (apps, TRUE);
}
static void
-nautilus_x_content_bar_set_mount (NautilusXContentBar *bar, GMount *mount)
+nautilus_x_content_bar_set_mount (NautilusXContentBar *bar,
+ GMount *mount)
{
- if (bar->priv->mount != NULL) {
- g_object_unref (bar->priv->mount);
- }
- bar->priv->mount = mount != NULL ? g_object_ref (mount) : NULL;
+ if (bar->priv->mount != NULL)
+ {
+ g_object_unref (bar->priv->mount);
+ }
+ bar->priv->mount = mount != NULL ? g_object_ref (mount) : NULL;
}
static void
nautilus_x_content_bar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- NautilusXContentBar *bar;
-
- bar = NAUTILUS_X_CONTENT_BAR (object);
-
- switch (prop_id) {
- case PROP_MOUNT:
- nautilus_x_content_bar_set_mount (bar, G_MOUNT (g_value_get_object (value)));
- break;
- case PROP_X_CONTENT_TYPES:
- nautilus_x_content_bar_set_x_content_types (bar, g_value_get_boxed (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ NautilusXContentBar *bar;
+
+ bar = NAUTILUS_X_CONTENT_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_MOUNT:
+ {
+ nautilus_x_content_bar_set_mount (bar, G_MOUNT (g_value_get_object (value)));
+ }
+ break;
+
+ case PROP_X_CONTENT_TYPES:
+ {
+ nautilus_x_content_bar_set_x_content_types (bar, g_value_get_boxed (value));
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_x_content_bar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- NautilusXContentBar *bar;
-
- bar = NAUTILUS_X_CONTENT_BAR (object);
-
- switch (prop_id) {
- case PROP_MOUNT:
- g_value_set_object (value, bar->priv->mount);
- break;
- case PROP_X_CONTENT_TYPES:
- g_value_set_boxed (value, &bar->priv->x_content_types);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ NautilusXContentBar *bar;
+
+ bar = NAUTILUS_X_CONTENT_BAR (object);
+
+ switch (prop_id)
+ {
+ case PROP_MOUNT:
+ {
+ g_value_set_object (value, bar->priv->mount);
+ }
+ break;
+
+ case PROP_X_CONTENT_TYPES:
+ {
+ g_value_set_boxed (value, &bar->priv->x_content_types);
+ }
+ break;
+
+ default:
+ {
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+ break;
+ }
}
static void
nautilus_x_content_bar_finalize (GObject *object)
{
- NautilusXContentBar *bar = NAUTILUS_X_CONTENT_BAR (object);
+ NautilusXContentBar *bar = NAUTILUS_X_CONTENT_BAR (object);
- g_strfreev (bar->priv->x_content_types);
- if (bar->priv->mount != NULL)
- g_object_unref (bar->priv->mount);
+ g_strfreev (bar->priv->x_content_types);
+ if (bar->priv->mount != NULL)
+ {
+ g_object_unref (bar->priv->mount);
+ }
- G_OBJECT_CLASS (nautilus_x_content_bar_parent_class)->finalize (object);
+ G_OBJECT_CLASS (nautilus_x_content_bar_parent_class)->finalize (object);
}
static void
nautilus_x_content_bar_class_init (NautilusXContentBarClass *klass)
{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = nautilus_x_content_bar_get_property;
- object_class->set_property = nautilus_x_content_bar_set_property;
- object_class->finalize = nautilus_x_content_bar_finalize;
-
- g_type_class_add_private (klass, sizeof (NautilusXContentBarPrivate));
-
- g_object_class_install_property (object_class,
- PROP_MOUNT,
- g_param_spec_object (
- "mount",
- "The GMount to run programs for",
- "The GMount to run programs for",
- G_TYPE_MOUNT,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
- g_object_class_install_property (object_class,
- PROP_X_CONTENT_TYPES,
- g_param_spec_boxed ("x-content-types",
- "The x-content types for the cluebar",
- "The x-content types for the cluebar",
- G_TYPE_STRV,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->get_property = nautilus_x_content_bar_get_property;
+ object_class->set_property = nautilus_x_content_bar_set_property;
+ object_class->finalize = nautilus_x_content_bar_finalize;
+
+ g_type_class_add_private (klass, sizeof (NautilusXContentBarPrivate));
+
+ g_object_class_install_property (object_class,
+ PROP_MOUNT,
+ g_param_spec_object (
+ "mount",
+ "The GMount to run programs for",
+ "The GMount to run programs for",
+ G_TYPE_MOUNT,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+ g_object_class_install_property (object_class,
+ PROP_X_CONTENT_TYPES,
+ g_param_spec_boxed ("x-content-types",
+ "The x-content types for the cluebar",
+ "The x-content types for the cluebar",
+ G_TYPE_STRV,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}
static void
nautilus_x_content_bar_init (NautilusXContentBar *bar)
{
- GtkWidget *content_area;
- GtkWidget *action_area;
- PangoAttrList *attrs;
+ GtkWidget *content_area;
+ GtkWidget *action_area;
+ PangoAttrList *attrs;
- bar->priv = NAUTILUS_X_CONTENT_BAR_GET_PRIVATE (bar);
- content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
- action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+ bar->priv = NAUTILUS_X_CONTENT_BAR_GET_PRIVATE (bar);
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+ action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
- gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
+ gtk_orientable_set_orientation (GTK_ORIENTABLE (action_area), GTK_ORIENTATION_HORIZONTAL);
- attrs = pango_attr_list_new ();
- pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
- bar->priv->label = gtk_label_new (NULL);
- gtk_label_set_attributes (GTK_LABEL (bar->priv->label), attrs);
- pango_attr_list_unref (attrs);
+ attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+ bar->priv->label = gtk_label_new (NULL);
+ gtk_label_set_attributes (GTK_LABEL (bar->priv->label), attrs);
+ pango_attr_list_unref (attrs);
- gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
- gtk_container_add (GTK_CONTAINER (content_area), bar->priv->label);
+ gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
+ gtk_container_add (GTK_CONTAINER (content_area), bar->priv->label);
- g_signal_connect (bar, "response",
- G_CALLBACK (content_bar_response_cb),
- bar);
+ g_signal_connect (bar, "response",
+ G_CALLBACK (content_bar_response_cb),
+ bar);
}
GtkWidget *
-nautilus_x_content_bar_new (GMount *mount,
- const char * const *x_content_types)
+nautilus_x_content_bar_new (GMount *mount,
+ const char * const *x_content_types)
{
- return g_object_new (NAUTILUS_TYPE_X_CONTENT_BAR,
- "message-type", GTK_MESSAGE_QUESTION,
- "mount", mount,
- "x-content-types", x_content_types,
- NULL);
+ return g_object_new (NAUTILUS_TYPE_X_CONTENT_BAR,
+ "message-type", GTK_MESSAGE_QUESTION,
+ "mount", mount,
+ "x-content-types", x_content_types,
+ NULL);
}
diff --git a/test/test-copy.c b/test/test-copy.c
index 428eea743..c927e47b1 100644
--- a/test/test-copy.c
+++ b/test/test-copy.c
@@ -5,96 +5,98 @@
#include <src/nautilus-progress-info-manager.h>
static void
-copy_done (GHashTable *debuting_uris,
- gboolean success,
- gpointer data)
+copy_done (GHashTable *debuting_uris,
+ gboolean success,
+ gpointer data)
{
- g_print ("Copy done\n");
+ g_print ("Copy done\n");
}
static void
changed_cb (NautilusProgressInfo *info,
- gpointer data)
+ gpointer data)
{
- g_print ("Changed: %s -- %s\n",
- nautilus_progress_info_get_status (info),
- nautilus_progress_info_get_details (info));
+ g_print ("Changed: %s -- %s\n",
+ nautilus_progress_info_get_status (info),
+ nautilus_progress_info_get_details (info));
}
static void
progress_changed_cb (NautilusProgressInfo *info,
- gpointer data)
+ gpointer data)
{
- g_print ("Progress changed: %f\n",
- nautilus_progress_info_get_progress (info));
+ g_print ("Progress changed: %f\n",
+ nautilus_progress_info_get_progress (info));
}
static void
finished_cb (NautilusProgressInfo *info,
- gpointer data)
+ gpointer data)
{
- g_print ("Finished\n");
- gtk_main_quit ();
+ g_print ("Finished\n");
+ gtk_main_quit ();
}
-int
-main (int argc, char* argv[])
+int
+main (int argc,
+ char *argv[])
{
- GtkWidget *window;
- GList *sources;
- GFile *dest;
- GFile *source;
- int i;
- GList *infos;
- NautilusProgressInfoManager *manager;
- NautilusProgressInfo *progress_info;
-
- test_init (&argc, &argv);
-
- if (argc < 3) {
- g_print ("Usage test-copy <sources...> <dest dir>\n");
- return 1;
- }
-
- sources = NULL;
- for (i = 1; i < argc - 1; i++) {
- source = g_file_new_for_commandline_arg (argv[i]);
- sources = g_list_prepend (sources, source);
- }
- sources = g_list_reverse (sources);
-
- dest = g_file_new_for_commandline_arg (argv[i]);
-
- window = test_window_new ("copy test", 5);
-
- gtk_widget_show (window);
-
- manager = nautilus_progress_info_manager_dup_singleton ();
-
- nautilus_file_operations_copy (sources,
- NULL /* GArray *relative_item_points */,
- dest,
- GTK_WINDOW (window),
- copy_done, NULL);
-
- infos = nautilus_progress_info_manager_get_all_infos (manager);
-
- if (infos == NULL) {
- g_object_unref (manager);
- return 0;
- }
-
- progress_info = NAUTILUS_PROGRESS_INFO (infos->data);
-
- g_signal_connect (progress_info, "changed", (GCallback)changed_cb, NULL);
- g_signal_connect (progress_info, "progress-changed", (GCallback)progress_changed_cb, NULL);
- g_signal_connect (progress_info, "finished", (GCallback)finished_cb, NULL);
-
- gtk_main ();
+ GtkWidget *window;
+ GList *sources;
+ GFile *dest;
+ GFile *source;
+ int i;
+ GList *infos;
+ NautilusProgressInfoManager *manager;
+ NautilusProgressInfo *progress_info;
+ test_init (&argc, &argv);
+
+ if (argc < 3)
+ {
+ g_print ("Usage test-copy <sources...> <dest dir>\n");
+ return 1;
+ }
+
+ sources = NULL;
+ for (i = 1; i < argc - 1; i++)
+ {
+ source = g_file_new_for_commandline_arg (argv[i]);
+ sources = g_list_prepend (sources, source);
+ }
+ sources = g_list_reverse (sources);
+
+ dest = g_file_new_for_commandline_arg (argv[i]);
+
+ window = test_window_new ("copy test", 5);
+
+ gtk_widget_show (window);
+
+ manager = nautilus_progress_info_manager_dup_singleton ();
+
+ nautilus_file_operations_copy (sources,
+ NULL /* GArray *relative_item_points */,
+ dest,
+ GTK_WINDOW (window),
+ copy_done, NULL);
+
+ infos = nautilus_progress_info_manager_get_all_infos (manager);
+
+ if (infos == NULL)
+ {
g_object_unref (manager);
-
- return 0;
-}
+ return 0;
+ }
+
+ progress_info = NAUTILUS_PROGRESS_INFO (infos->data);
+ g_signal_connect (progress_info, "changed", (GCallback) changed_cb, NULL);
+ g_signal_connect (progress_info, "progress-changed", (GCallback) progress_changed_cb, NULL);
+ g_signal_connect (progress_info, "finished", (GCallback) finished_cb, NULL);
+ gtk_main ();
+
+ g_object_unref (manager);
+
+ return 0;
+}
diff --git a/test/test-eel-background.c b/test/test-eel-background.c
index cb2e897ab..047508890 100644
--- a/test/test-eel-background.c
+++ b/test/test-eel-background.c
@@ -6,33 +6,34 @@
#define PATTERNS_DIR "/gnome-source/eel/data/patterns"
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- GtkWidget *window;
- EelBackground *background;
- char *image_uri;
+ GtkWidget *window;
+ EelBackground *background;
+ char *image_uri;
- gtk_init (&argc, &argv);
+ gtk_init (&argc, &argv);
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- g_signal_connect (window, "destroy",
- gtk_main_quit, NULL);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ g_signal_connect (window, "destroy",
+ gtk_main_quit, NULL);
- background = eel_get_widget_background (window);
+ background = eel_get_widget_background (window);
- eel_background_set_color (background,
- "red-blue:h");
+ eel_background_set_color (background,
+ "red-blue:h");
- image_uri = g_filename_to_uri (PATTERNS_DIR "/50s.png", NULL, NULL);
+ image_uri = g_filename_to_uri (PATTERNS_DIR "/50s.png", NULL, NULL);
#if 1
- eel_background_set_image_uri (background, image_uri);
+ eel_background_set_image_uri (background, image_uri);
#endif
- g_free (image_uri);
+ g_free (image_uri);
- gtk_widget_show_all (window);
- gtk_main ();
+ gtk_widget_show_all (window);
+ gtk_main ();
- return 0;
+ return 0;
}
diff --git a/test/test-eel-string-get-common-prefix.c b/test/test-eel-string-get-common-prefix.c
index 140b0be74..2dc5d9e9a 100644
--- a/test/test-eel-string-get-common-prefix.c
+++ b/test/test-eel-string-get-common-prefix.c
@@ -5,184 +5,186 @@
static void
-free_list_and_result (GList *list, char *result)
+free_list_and_result (GList *list,
+ char *result)
{
- g_list_free (list);
- g_free (result);
+ g_list_free (list);
+ g_free (result);
}
static void
test_has_large_enough_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "foo-1.txt");
- list = g_list_append (list, "foo-1.tar");
+ list = g_list_append (list, "foo-1.txt");
+ list = g_list_append (list, "foo-1.tar");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_cmpstr ("foo-1.t", ==, actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("foo-1.t", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_common_prefix_that_equals_the_min_required_length ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "food");
- list = g_list_append (list, "foody");
+ list = g_list_append (list, "food");
+ list = g_list_append (list, "foody");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_cmpstr ("food", ==, actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("food", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_common_prefix_that_equals_the_min_required_length2 ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "foody");
- list = g_list_append (list, "food");
+ list = g_list_append (list, "foody");
+ list = g_list_append (list, "food");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_cmpstr ("food", ==, actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("food", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_many_strings_with_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "some text that matches abcde");
- list = g_list_append (list, "some text that matches abc22");
- list = g_list_append (list, "some text that 11");
- list = g_list_append (list, "some text that matches---");
- list = g_list_append (list, "some text that matches £$$");
- list = g_list_append (list, "some text that matches.txt");
+ list = g_list_append (list, "some text that matches abcde");
+ list = g_list_append (list, "some text that matches abc22");
+ list = g_list_append (list, "some text that 11");
+ list = g_list_append (list, "some text that matches---");
+ list = g_list_append (list, "some text that matches £$$");
+ list = g_list_append (list, "some text that matches.txt");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_cmpstr ("some text that ", ==, actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("some text that ", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_strings_with_unicode_characters_that_have_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "ƹƱƱƬ");
- list = g_list_append (list, "ƹƱƱƬƧƥƧ");
+ list = g_list_append (list, "ƹƱƱƬ");
+ list = g_list_append (list, "ƹƱƱƬƧƥƧ");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_cmpstr ("ƹƱƱƬ", ==, actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_cmpstr ("ƹƱƱƬ", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_no_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "fyod");
- list = g_list_append (list, "completely different string");
+ list = g_list_append (list, "fyod");
+ list = g_list_append (list, "completely different string");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_null (actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_common_prefix_but_smaller_than_min_required_length ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "fyod");
- list = g_list_append (list, "fyoa");
+ list = g_list_append (list, "fyod");
+ list = g_list_append (list, "fyoa");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_null (actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_first_character_differs ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "tyodaa");
- list = g_list_append (list, "fyodaa");
+ list = g_list_append (list, "tyodaa");
+ list = g_list_append (list, "fyodaa");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_null (actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_strings_with_unicode_characters_that_dont_have_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "ƹƱƱƬ");
- list = g_list_append (list, "ƹƱƢƱƬƧƥƧ");
+ list = g_list_append (list, "ƹƱƱƬ");
+ list = g_list_append (list, "ƹƱƢƱƬƧƥƧ");
- actual = eel_str_get_common_prefix (list, 4);
- g_assert_null (actual);
+ actual = eel_str_get_common_prefix (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
setup_test_suite ()
{
- g_test_add_func ("/get-common-prefix/1.0",
- test_has_large_enough_common_prefix);
- g_test_add_func ("/get-common-prefix/1.1",
- test_has_common_prefix_that_equals_the_min_required_length);
- g_test_add_func ("/get-common-prefix/1.2",
- test_has_common_prefix_that_equals_the_min_required_length2);
- g_test_add_func ("/get-common-prefix/1.3",
- test_many_strings_with_common_prefix);
- g_test_add_func ("/get-common-prefix/1.4",
- test_strings_with_unicode_characters_that_have_common_prefix);
-
- g_test_add_func ("/get-common-prefix/2.0",
- test_no_common_prefix);
- g_test_add_func ("/get-common-prefix/2.1",
- test_has_common_prefix_but_smaller_than_min_required_length);
- g_test_add_func ("/get-common-prefix/2.2",
- test_first_character_differs);
- g_test_add_func ("/get-common-prefix/2.3",
- test_strings_with_unicode_characters_that_dont_have_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.0",
+ test_has_large_enough_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.1",
+ test_has_common_prefix_that_equals_the_min_required_length);
+ g_test_add_func ("/get-common-prefix/1.2",
+ test_has_common_prefix_that_equals_the_min_required_length2);
+ g_test_add_func ("/get-common-prefix/1.3",
+ test_many_strings_with_common_prefix);
+ g_test_add_func ("/get-common-prefix/1.4",
+ test_strings_with_unicode_characters_that_have_common_prefix);
+
+ g_test_add_func ("/get-common-prefix/2.0",
+ test_no_common_prefix);
+ g_test_add_func ("/get-common-prefix/2.1",
+ test_has_common_prefix_but_smaller_than_min_required_length);
+ g_test_add_func ("/get-common-prefix/2.2",
+ test_first_character_differs);
+ g_test_add_func ("/get-common-prefix/2.3",
+ test_strings_with_unicode_characters_that_dont_have_common_prefix);
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- g_test_init (&argc, &argv, NULL);
- g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
- g_test_set_nonfatal_assertions ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
- setup_test_suite ();
+ setup_test_suite ();
- return g_test_run ();
+ return g_test_run ();
}
diff --git a/test/test-eel-string-rtrim-punctuation.c b/test/test-eel-string-rtrim-punctuation.c
index 3dc1f947f..526ac9fb4 100644
--- a/test/test-eel-string-rtrim-punctuation.c
+++ b/test/test-eel-string-rtrim-punctuation.c
@@ -6,116 +6,117 @@
static void
test_single_punctuation_character_removed ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Yossarian-");
- g_assert_cmpstr ("Yossarian", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Yossarian-");
+ g_assert_cmpstr ("Yossarian", ==, actual);
+ g_free (actual);
}
static void
test_tailing_space_is_removed ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Yossarian ");
- g_assert_cmpstr ("Yossarian", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Yossarian ");
+ g_assert_cmpstr ("Yossarian", ==, actual);
+ g_free (actual);
}
static void
test_multiple_punctuation_characters_removed ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Yossarian-$$!£");
- g_assert_cmpstr ("Yossarian", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Yossarian-$$!£");
+ g_assert_cmpstr ("Yossarian", ==, actual);
+ g_free (actual);
}
static void
test_multiple_punctuation_characters_removed_try_all_punctuation_characters ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Yossarian-`¬!\"£$%^&*()_+-= {}[]:@~;'#<>?,./\\");
- g_assert_cmpstr ("Yossarian", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Yossarian-`¬!\"£$%^&*()_+-= {}[]:@~;'#<>?,./\\");
+ g_assert_cmpstr ("Yossarian", ==, actual);
+ g_free (actual);
}
static void
test_punctuation_characters_removed_when_punctuation_in_middle_of_string ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Yoss,,arian-$$!£");
- g_assert_cmpstr ("Yoss,,arian", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Yoss,,arian-$$!£");
+ g_assert_cmpstr ("Yoss,,arian", ==, actual);
+ g_free (actual);
}
static void
test_punctuation_characters_removed_when_prefix_is_single_character ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Y-$$ !£");
- g_assert_cmpstr ("Y", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Y-$$ !£");
+ g_assert_cmpstr ("Y", ==, actual);
+ g_free (actual);
}
static void
test_punctuation_characters_removed_when_unicode_characters_are_used ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Y✺ǨǨǨ-$$ !£");
- g_assert_cmpstr ("Y✺ǨǨǨ", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Y✺ǨǨǨ-$$ !£");
+ g_assert_cmpstr ("Y✺ǨǨǨ", ==, actual);
+ g_free (actual);
}
static void
test_when_no_trailing_punctuation ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("Yoss,,arian");
- g_assert_cmpstr ("Yoss,,arian", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("Yoss,,arian");
+ g_assert_cmpstr ("Yoss,,arian", ==, actual);
+ g_free (actual);
}
static void
test_when_single_character_and_no_trailing_punctuation ()
{
- char *actual;
- actual = eel_str_rtrim_punctuation ("t");
- g_assert_cmpstr ("t", ==, actual);
- g_free (actual);
+ char *actual;
+ actual = eel_str_rtrim_punctuation ("t");
+ g_assert_cmpstr ("t", ==, actual);
+ g_free (actual);
}
static void
setup_test_suite ()
{
- g_test_add_func ("/rtrim-punctuation/1.0",
- test_single_punctuation_character_removed);
- g_test_add_func ("/rtrim-punctuation/1.1",
- test_tailing_space_is_removed);
- g_test_add_func ("/rtrim-punctuation/1.2",
- test_multiple_punctuation_characters_removed);
- g_test_add_func ("/rtrim-punctuation/1.3",
- test_multiple_punctuation_characters_removed_try_all_punctuation_characters);
- g_test_add_func ("/rtrim-punctuation/1.4",
- test_punctuation_characters_removed_when_punctuation_in_middle_of_string);
- g_test_add_func ("/rtrim-punctuation/1.5",
- test_punctuation_characters_removed_when_prefix_is_single_character);
- g_test_add_func ("/rtrim-punctuation/1.6",
- test_punctuation_characters_removed_when_unicode_characters_are_used);
-
- g_test_add_func ("/rtrim-punctuation/2.0",
- test_when_no_trailing_punctuation);
- g_test_add_func ("/rtrim-punctuation/2.1",
- test_when_single_character_and_no_trailing_punctuation);
+ g_test_add_func ("/rtrim-punctuation/1.0",
+ test_single_punctuation_character_removed);
+ g_test_add_func ("/rtrim-punctuation/1.1",
+ test_tailing_space_is_removed);
+ g_test_add_func ("/rtrim-punctuation/1.2",
+ test_multiple_punctuation_characters_removed);
+ g_test_add_func ("/rtrim-punctuation/1.3",
+ test_multiple_punctuation_characters_removed_try_all_punctuation_characters);
+ g_test_add_func ("/rtrim-punctuation/1.4",
+ test_punctuation_characters_removed_when_punctuation_in_middle_of_string);
+ g_test_add_func ("/rtrim-punctuation/1.5",
+ test_punctuation_characters_removed_when_prefix_is_single_character);
+ g_test_add_func ("/rtrim-punctuation/1.6",
+ test_punctuation_characters_removed_when_unicode_characters_are_used);
+
+ g_test_add_func ("/rtrim-punctuation/2.0",
+ test_when_no_trailing_punctuation);
+ g_test_add_func ("/rtrim-punctuation/2.1",
+ test_when_single_character_and_no_trailing_punctuation);
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- g_test_init (&argc, &argv, NULL);
- g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
- g_test_set_nonfatal_assertions ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
- setup_test_suite ();
+ setup_test_suite ();
- return g_test_run ();
+ return g_test_run ();
}
diff --git a/test/test-file-utilities-get-common-filename-prefix.c b/test/test-file-utilities-get-common-filename-prefix.c
index 786c7dfb8..ae4dffc4d 100644
--- a/test/test-file-utilities-get-common-filename-prefix.c
+++ b/test/test-file-utilities-get-common-filename-prefix.c
@@ -5,533 +5,540 @@
static void
-free_list_and_result (GList *list, char *result)
+free_list_and_result (GList *list,
+ char *result)
{
- g_list_free (list);
- g_free (result);
+ g_list_free (list);
+ g_free (result);
}
static void
test_has_large_enough_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "test");
- list = g_list_append (list, "tests");
+ list = g_list_append (list, "test");
+ list = g_list_append (list, "tests");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("test", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("test", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_large_enough_common_prefix_with_spaces_in_middle ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "Cpt J Yossarian r1");
- list = g_list_append (list, "Cpt J Yossarian a1");
+ list = g_list_append (list, "Cpt J Yossarian r1");
+ list = g_list_append (list, "Cpt J Yossarian a1");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("Cpt J Yossarian", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt J Yossarian", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_large_enough_common_prefix_with_punctuation_in_middle ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "Cpt-J_Yossarian r1");
- list = g_list_append (list, "Cpt-J_Yossarian a1");
+ list = g_list_append (list, "Cpt-J_Yossarian r1");
+ list = g_list_append (list, "Cpt-J_Yossarian a1");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("Cpt-J_Yossarian", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt-J_Yossarian", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "Cpt-J, Yossarian.xml");
- list = g_list_append (list, "Cpt-J, Yossarian.xsl");
+ list = g_list_append (list, "Cpt-J, Yossarian.xml");
+ list = g_list_append (list, "Cpt-J, Yossarian.xsl");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("Cpt-J, Yossarian", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("Cpt-J, Yossarian", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_doesnt_have_large_enough_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "foo");
- list = g_list_append (list, "foob");
+ list = g_list_append (list, "foo");
+ list = g_list_append (list, "foob");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_doesnt_have_large_enough_common_prefix_completely_different_strings ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "this string really");
- list = g_list_append (list, "isn't the same as the other");
+ list = g_list_append (list, "this string really");
+ list = g_list_append (list, "isn't the same as the other");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_doesnt_have_large_enough_common_prefix_first_character_differs ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "foo");
- list = g_list_append (list, "roo");
+ list = g_list_append (list, "foo");
+ list = g_list_append (list, "roo");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "fools");
- list = g_list_append (list, "rools");
+ list = g_list_append (list, "fools");
+ list = g_list_append (list, "rools");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_large_enough_common_prefix_until_punctuation_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "tes$%^");
- list = g_list_append (list, "tes$%something");
+ list = g_list_append (list, "tes$%^");
+ list = g_list_append (list, "tes$%something");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_large_enough_common_prefix_until_extension_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "tes.txt");
- list = g_list_append (list, "tes.tar");
+ list = g_list_append (list, "tes.txt");
+ list = g_list_append (list, "tes.tar");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_has_large_enough_common_prefix_until_extension_and_punctuation_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "tux$&&&.txt");
- list = g_list_append (list, "tux$&&&.tar");
+ list = g_list_append (list, "tux$&&&.txt");
+ list = g_list_append (list, "tux$&&&.tar");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_extension_is_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nau tilus.c");
- list = g_list_append (list, "nau tilus.cpp");
+ list = g_list_append (list, "nau tilus.c");
+ list = g_list_append (list, "nau tilus.cpp");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nau tilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nau tilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_punctuation_is_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nautilus((&&£");
- list = g_list_append (list, "nautilus((&&xyz");
+ list = g_list_append (list, "nautilus((&&£");
+ list = g_list_append (list, "nautilus((&&xyz");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nautilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_whitespace_is_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nautilus ");
- list = g_list_append (list, "nautilus two");
+ list = g_list_append (list, "nautilus ");
+ list = g_list_append (list, "nautilus two");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nautilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_punctuation_and_whitespace_are_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nautilus! £ $\"TTR");
- list = g_list_append (list, "nautilus! £ $\"");
+ list = g_list_append (list, "nautilus! £ $\"TTR");
+ list = g_list_append (list, "nautilus! £ $\"");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nautilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_whitespace_and_punctuation_are_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nautilus !£ $\"TTR");
- list = g_list_append (list, "nautilus !£ $\"");
+ list = g_list_append (list, "nautilus !£ $\"TTR");
+ list = g_list_append (list, "nautilus !£ $\"");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nautilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_puctuation_and_extension_are_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nautilus!£$%^&*()_+-={}[];':@#~<>?,./\".tar");
- list = g_list_append (list, "nautilus!£$%^&*()_+-={}[];':@#~<>?,./\".tat");
+ list = g_list_append (list, "nautilus!£$%^&*()_+-={}[];':@#~<>?,./\".tar");
+ list = g_list_append (list, "nautilus!£$%^&*()_+-={}[];':@#~<>?,./\".tat");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nautilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_puctuation_extension_and_whitespace_are_removed ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "nautilus!£$%^&* ()_+-={}[ ];':@#~<>?,./\".tar");
- list = g_list_append (list, "nautilus!£$%^&* ()_+-={}[ ];':@#~<>?,./\".tat");
+ list = g_list_append (list, "nautilus!£$%^&* ()_+-={}[ ];':@#~<>?,./\".tar");
+ list = g_list_append (list, "nautilus!£$%^&* ()_+-={}[ ];':@#~<>?,./\".tat");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("nautilus", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("nautilus", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_unicode_on_outside ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "ӶtestӶ234");
- list = g_list_append (list, "ӶtestӶ1");
+ list = g_list_append (list, "ӶtestӶ234");
+ list = g_list_append (list, "ӶtestӶ1");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("ӶtestӶ", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ӶtestӶ", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_unicode_on_inside ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "QQӶtestӶabb234");
- list = g_list_append (list, "QQӶtestӶabb1");
+ list = g_list_append (list, "QQӶtestӶabb234");
+ list = g_list_append (list, "QQӶtestӶabb1");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("QQӶtestӶabb", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("QQӶtestӶabb", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_unicode_whole_string ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "ǣȸʸͻͻΎΘΛ");
- list = g_list_append (list, "ǣȸʸͻͻΎΘ");
+ list = g_list_append (list, "ǣȸʸͻͻΎΘΛ");
+ list = g_list_append (list, "ǣȸʸͻͻΎΘ");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("ǣȸʸͻͻΎΘ", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ǣȸʸͻͻΎΘ", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_unicode_extension ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "test.ǣȸʸͻͻΎΘΛ");
- list = g_list_append (list, "test.ǣȸʸͻͻΎΘ");
+ list = g_list_append (list, "test.ǣȸʸͻͻΎΘΛ");
+ list = g_list_append (list, "test.ǣȸʸͻͻΎΘ");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("test", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("test", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_unicode_with_punctuation ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%^");
- list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%&");
+ list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%^");
+ list = g_list_append (list, "ǣȸʸ- ͻͻΎΘ$%%&");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("ǣȸʸ- ͻͻΎΘ", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("ǣȸʸ- ͻͻΎΘ", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_many_strings ()
{
- GList *list = NULL;
- char *actual;
- char *filename;
- int i;
-
- for (i = 0; i < 500; ++i) {
- filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
- list = g_list_append (list, filename);
- }
-
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_cmpstr ("we are no longer the knights who say nii", ==, actual);
-
- g_free (actual);
- g_list_free_full (list, g_free);
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_cmpstr ("we are no longer the knights who say nii", ==, actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
}
static void
test_many_strings_last_differs ()
{
- GList *list = NULL;
- char *actual;
- char *filename;
- int i;
-
- for (i = 0; i < 500; ++i) {
- filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
-
- if (i == 499) {
- filename[2] = 'X';
- }
-
- list = g_list_append (list, filename);
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+
+ if (i == 499)
+ {
+ filename[2] = 'X';
}
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ list = g_list_append (list, filename);
+ }
- g_free (actual);
- g_list_free_full (list, g_free);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
+
+ g_free (actual);
+ g_list_free_full (list, g_free);
}
static void
test_many_strings_first_differs ()
{
- GList *list = NULL;
- char *actual;
- char *filename;
- int i;
-
- for (i = 0; i < 500; ++i) {
- filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
-
- if (i == 0) {
- filename[2] = 'X';
- }
-
- list = g_list_append (list, filename);
+ GList *list = NULL;
+ char *actual;
+ char *filename;
+ int i;
+
+ for (i = 0; i < 500; ++i)
+ {
+ filename = g_strdup_printf ("we are no longer the knights who say nii%d", i);
+
+ if (i == 0)
+ {
+ filename[2] = 'X';
}
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
- g_assert_null (actual);
+ list = g_list_append (list, filename);
+ }
+
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 4);
+ g_assert_null (actual);
- g_free (actual);
- g_list_free_full (list, g_free);
+ g_free (actual);
+ g_list_free_full (list, g_free);
}
static void
test_smaller_min_length_and_does_have_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "CA");
- list = g_list_append (list, "CB");
+ list = g_list_append (list, "CA");
+ list = g_list_append (list, "CB");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
- g_assert_cmpstr ("C", ==, actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
+ g_assert_cmpstr ("C", ==, actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
test_smaller_min_length_and_doesnt_have_common_prefix ()
{
- GList *list = NULL;
- char *actual;
+ GList *list = NULL;
+ char *actual;
- list = g_list_append (list, "CA");
- list = g_list_append (list, "BB");
+ list = g_list_append (list, "CA");
+ list = g_list_append (list, "BB");
- actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
- g_assert_null (actual);
+ actual = nautilus_get_common_filename_prefix_from_filenames (list, 1);
+ g_assert_null (actual);
- free_list_and_result (list, actual);
+ free_list_and_result (list, actual);
}
static void
setup_test_suite ()
{
- g_test_add_func ("/get-common-filename-prefix/1.0",
- test_has_large_enough_common_prefix);
- g_test_add_func ("/get-common-filename-prefix/1.1",
- test_has_large_enough_common_prefix_with_spaces_in_middle);
- g_test_add_func ("/get-common-filename-prefix/1.2",
- test_has_large_enough_common_prefix_with_punctuation_in_middle);
- g_test_add_func ("/get-common-filename-prefix/1.3",
- test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension);
-
- g_test_add_func ("/get-common-filename-prefix/2.0",
- test_doesnt_have_large_enough_common_prefix);
- g_test_add_func ("/get-common-filename-prefix/2.1",
- test_doesnt_have_large_enough_common_prefix_completely_different_strings);
- g_test_add_func ("/get-common-filename-prefix/2.2",
- test_doesnt_have_large_enough_common_prefix_first_character_differs);
- g_test_add_func ("/get-common-filename-prefix/2.3",
- test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string);
-
- g_test_add_func ("/get-common-filename-prefix/3.0",
- test_has_large_enough_common_prefix_until_punctuation_removed);
- g_test_add_func ("/get-common-filename-prefix/3.1",
- test_has_large_enough_common_prefix_until_extension_removed);
- g_test_add_func ("/get-common-filename-prefix/3.2",
- test_has_large_enough_common_prefix_until_extension_and_punctuation_removed);
-
- g_test_add_func ("/get-common-filename-prefix/4.0",
- test_extension_is_removed);
- g_test_add_func ("/get-common-filename-prefix/4.1",
- test_punctuation_is_removed);
- g_test_add_func ("/get-common-filename-prefix/4.2",
- test_whitespace_is_removed);
- g_test_add_func ("/get-common-filename-prefix/4.3",
- test_punctuation_and_whitespace_are_removed);
- g_test_add_func ("/get-common-filename-prefix/4.4",
- test_whitespace_and_punctuation_are_removed);
- g_test_add_func ("/get-common-filename-prefix/4.5",
- test_puctuation_and_extension_are_removed);
- g_test_add_func ("/get-common-filename-prefix/4.6",
- test_puctuation_extension_and_whitespace_are_removed);
-
- g_test_add_func ("/get-common-filename-prefix/5.0",
- test_unicode_on_inside);
- g_test_add_func ("/get-common-filename-prefix/5.1",
- test_unicode_on_outside);
- g_test_add_func ("/get-common-filename-prefix/5.2",
- test_unicode_whole_string);
- g_test_add_func ("/get-common-filename-prefix/5.3",
- test_unicode_extension);
- g_test_add_func ("/get-common-filename-prefix/5.4",
- test_unicode_with_punctuation);
-
- g_test_add_func ("/get-common-filename-prefix/6.0",
- test_many_strings);
- g_test_add_func ("/get-common-filename-prefix/6.1",
- test_many_strings_last_differs);
- g_test_add_func ("/get-common-filename-prefix/6.2",
- test_many_strings_first_differs);
-
- g_test_add_func ("/get-common-filename-prefix/7.0",
- test_smaller_min_length_and_does_have_common_prefix);
- g_test_add_func ("/get-common-filename-prefix/7.1",
- test_smaller_min_length_and_doesnt_have_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/1.0",
+ test_has_large_enough_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/1.1",
+ test_has_large_enough_common_prefix_with_spaces_in_middle);
+ g_test_add_func ("/get-common-filename-prefix/1.2",
+ test_has_large_enough_common_prefix_with_punctuation_in_middle);
+ g_test_add_func ("/get-common-filename-prefix/1.3",
+ test_has_large_enough_common_prefix_with_punctuation_in_middle_and_extension);
+
+ g_test_add_func ("/get-common-filename-prefix/2.0",
+ test_doesnt_have_large_enough_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/2.1",
+ test_doesnt_have_large_enough_common_prefix_completely_different_strings);
+ g_test_add_func ("/get-common-filename-prefix/2.2",
+ test_doesnt_have_large_enough_common_prefix_first_character_differs);
+ g_test_add_func ("/get-common-filename-prefix/2.3",
+ test_doesnt_have_large_enough_common_prefix_first_character_differs_longer_string);
+
+ g_test_add_func ("/get-common-filename-prefix/3.0",
+ test_has_large_enough_common_prefix_until_punctuation_removed);
+ g_test_add_func ("/get-common-filename-prefix/3.1",
+ test_has_large_enough_common_prefix_until_extension_removed);
+ g_test_add_func ("/get-common-filename-prefix/3.2",
+ test_has_large_enough_common_prefix_until_extension_and_punctuation_removed);
+
+ g_test_add_func ("/get-common-filename-prefix/4.0",
+ test_extension_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.1",
+ test_punctuation_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.2",
+ test_whitespace_is_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.3",
+ test_punctuation_and_whitespace_are_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.4",
+ test_whitespace_and_punctuation_are_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.5",
+ test_puctuation_and_extension_are_removed);
+ g_test_add_func ("/get-common-filename-prefix/4.6",
+ test_puctuation_extension_and_whitespace_are_removed);
+
+ g_test_add_func ("/get-common-filename-prefix/5.0",
+ test_unicode_on_inside);
+ g_test_add_func ("/get-common-filename-prefix/5.1",
+ test_unicode_on_outside);
+ g_test_add_func ("/get-common-filename-prefix/5.2",
+ test_unicode_whole_string);
+ g_test_add_func ("/get-common-filename-prefix/5.3",
+ test_unicode_extension);
+ g_test_add_func ("/get-common-filename-prefix/5.4",
+ test_unicode_with_punctuation);
+
+ g_test_add_func ("/get-common-filename-prefix/6.0",
+ test_many_strings);
+ g_test_add_func ("/get-common-filename-prefix/6.1",
+ test_many_strings_last_differs);
+ g_test_add_func ("/get-common-filename-prefix/6.2",
+ test_many_strings_first_differs);
+
+ g_test_add_func ("/get-common-filename-prefix/7.0",
+ test_smaller_min_length_and_does_have_common_prefix);
+ g_test_add_func ("/get-common-filename-prefix/7.1",
+ test_smaller_min_length_and_doesnt_have_common_prefix);
}
int
-main (int argc, char *argv[])
+main (int argc,
+ char *argv[])
{
- g_test_init (&argc, &argv, NULL);
- g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
- g_test_set_nonfatal_assertions ();
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=747907");
+ g_test_set_nonfatal_assertions ();
- setup_test_suite ();
+ setup_test_suite ();
- return g_test_run ();
+ return g_test_run ();
}
diff --git a/test/test-nautilus-directory-async.c b/test/test-nautilus-directory-async.c
index 4fbbb3268..da86ecab8 100644
--- a/test/test-nautilus-directory-async.c
+++ b/test/test-nautilus-directory-async.c
@@ -8,83 +8,89 @@ void *client1, *client2;
static void
files_added (NautilusDirectory *directory,
- GList *added_files)
+ GList *added_files)
{
#if 0
- GList *list;
+ GList *list;
- for (list = added_files; list != NULL; list = list->next) {
- NautilusFile *file = list->data;
+ for (list = added_files; list != NULL; list = list->next)
+ {
+ NautilusFile *file = list->data;
- g_print (" - %s\n", nautilus_file_get_uri (file));
- }
+ g_print (" - %s\n", nautilus_file_get_uri (file));
+ }
#endif
- g_print ("files added: %d files\n",
- g_list_length (added_files));
+ g_print ("files added: %d files\n",
+ g_list_length (added_files));
}
static void
files_changed (NautilusDirectory *directory,
- GList *changed_files)
+ GList *changed_files)
{
#if 0
- GList *list;
+ GList *list;
- for (list = changed_files; list != NULL; list = list->next) {
- NautilusFile *file = list->data;
+ for (list = changed_files; list != NULL; list = list->next)
+ {
+ NautilusFile *file = list->data;
- g_print (" - %s\n", nautilus_file_get_uri (file));
- }
+ g_print (" - %s\n", nautilus_file_get_uri (file));
+ }
#endif
- g_print ("files changed: %d\n",
- g_list_length (changed_files));
+ g_print ("files changed: %d\n",
+ g_list_length (changed_files));
}
static void
done_loading (NautilusDirectory *directory)
{
- g_print ("done loading\n");
- gtk_main_quit ();
+ g_print ("done loading\n");
+ gtk_main_quit ();
}
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
- NautilusDirectory *directory;
- NautilusFileAttributes attributes;
- const char *uri;
-
- client1 = g_new0 (int, 1);
- client2 = g_new0 (int, 1);
-
- gtk_init (&argc, &argv);
-
- if (argv[1] == NULL) {
- uri = "file:///tmp";
- } else {
- uri = argv[1];
- }
- g_print ("loading %s", uri);
- directory = nautilus_directory_get_by_uri (uri);
-
- g_signal_connect (directory, "files-added", G_CALLBACK (files_added), NULL);
- g_signal_connect (directory, "files-changed", G_CALLBACK (files_changed), NULL);
- g_signal_connect (directory, "done-loading", G_CALLBACK (done_loading), NULL);
-
- attributes =
- NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
- NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
- NAUTILUS_FILE_ATTRIBUTE_INFO |
- NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
- NAUTILUS_FILE_ATTRIBUTE_MOUNT |
- NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
-
- nautilus_directory_file_monitor_add (directory, client1, TRUE,
- attributes,
- NULL, NULL);
-
-
- gtk_main ();
- return 0;
+ NautilusDirectory *directory;
+ NautilusFileAttributes attributes;
+ const char *uri;
+
+ client1 = g_new0 (int, 1);
+ client2 = g_new0 (int, 1);
+
+ gtk_init (&argc, &argv);
+
+ if (argv[1] == NULL)
+ {
+ uri = "file:///tmp";
+ }
+ else
+ {
+ uri = argv[1];
+ }
+ g_print ("loading %s", uri);
+ directory = nautilus_directory_get_by_uri (uri);
+
+ g_signal_connect (directory, "files-added", G_CALLBACK (files_added), NULL);
+ g_signal_connect (directory, "files-changed", G_CALLBACK (files_changed), NULL);
+ g_signal_connect (directory, "done-loading", G_CALLBACK (done_loading), NULL);
+
+ attributes =
+ NAUTILUS_FILE_ATTRIBUTES_FOR_ICON |
+ NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT |
+ NAUTILUS_FILE_ATTRIBUTE_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_LINK_INFO |
+ NAUTILUS_FILE_ATTRIBUTE_MOUNT |
+ NAUTILUS_FILE_ATTRIBUTE_EXTENSION_INFO;
+
+ nautilus_directory_file_monitor_add (directory, client1, TRUE,
+ attributes,
+ NULL, NULL);
+
+
+ gtk_main ();
+ return 0;
}
diff --git a/test/test-nautilus-mime-actions-set.c b/test/test-nautilus-mime-actions-set.c
index b80c31767..a08f817d6 100644
--- a/test/test-nautilus-mime-actions-set.c
+++ b/test/test-nautilus-mime-actions-set.c
@@ -1,25 +1,25 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* test-mime.c - Test for the mime handler detection features of the GNOME
- Virtual File System Library
-
- Copyright (C) 2000 Eazel
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Author: Maciej Stachowiak <mjs@eazel.com>
-*/
+ * Virtual File System Library
+ *
+ * Copyright (C) 2000 Eazel
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Maciej Stachowiak <mjs@eazel.com>
+ */
#include <config.h>
@@ -32,129 +32,156 @@ static gboolean ready = FALSE;
static void
usage (const char *name)
{
- fprintf (stderr, "Usage: %s uri field value\n", name);
- fprintf (stderr, "Valid field values are: \n");
- fprintf (stderr, "\tdefault_action_type\n");
- fprintf (stderr, "\tdefault_application\n");
- fprintf (stderr, "\tdefault_component\n");
- fprintf (stderr, "\tshort_list_applicationss\n");
- fprintf (stderr, "\tshort_list_components\n");
- fprintf (stderr, "\tadd_to_all_applicationss\n");
- fprintf (stderr, "\tremove_from_all_applications\n");
- exit (1);
+ fprintf (stderr, "Usage: %s uri field value\n", name);
+ fprintf (stderr, "Valid field values are: \n");
+ fprintf (stderr, "\tdefault_action_type\n");
+ fprintf (stderr, "\tdefault_application\n");
+ fprintf (stderr, "\tdefault_component\n");
+ fprintf (stderr, "\tshort_list_applicationss\n");
+ fprintf (stderr, "\tshort_list_components\n");
+ fprintf (stderr, "\tadd_to_all_applicationss\n");
+ fprintf (stderr, "\tremove_from_all_applications\n");
+ exit (1);
}
static GnomeVFSMimeActionType
str_to_action_type (const char *str)
{
- if (g_ascii_strcasecmp (str, "component") == 0) {
- return GNOME_VFS_MIME_ACTION_TYPE_COMPONENT;
- } else if (g_ascii_strcasecmp (str, "application") == 0) {
- return GNOME_VFS_MIME_ACTION_TYPE_APPLICATION;
- } else {
- return GNOME_VFS_MIME_ACTION_TYPE_NONE;
- }
+ if (g_ascii_strcasecmp (str, "component") == 0)
+ {
+ return GNOME_VFS_MIME_ACTION_TYPE_COMPONENT;
+ }
+ else if (g_ascii_strcasecmp (str, "application") == 0)
+ {
+ return GNOME_VFS_MIME_ACTION_TYPE_APPLICATION;
+ }
+ else
+ {
+ return GNOME_VFS_MIME_ACTION_TYPE_NONE;
+ }
}
static char **
-strsplit_handle_null (const char *str, const char *delim, int max)
+strsplit_handle_null (const char *str,
+ const char *delim,
+ int max)
{
- return g_strsplit ((str == NULL ? "" : str), delim, max);
+ return g_strsplit ((str == NULL ? "" : str), delim, max);
}
static GList *
-strsplit_to_list (const char *str, const char *delim, int max)
+strsplit_to_list (const char *str,
+ const char *delim,
+ int max)
{
- char **strv;
- GList *retval;
- int i;
+ char **strv;
+ GList *retval;
+ int i;
- strv = strsplit_handle_null (str, delim, max);
+ strv = strsplit_handle_null (str, delim, max);
- retval = NULL;
+ retval = NULL;
- for (i = 0; strv[i] != NULL; i++) {
- retval = g_list_prepend (retval, strv[i]);
- }
+ for (i = 0; strv[i] != NULL; i++)
+ {
+ retval = g_list_prepend (retval, strv[i]);
+ }
- retval = g_list_reverse (retval);
- /* Don't strfreev, since we didn't copy the individual strings. */
- g_free (strv);
+ retval = g_list_reverse (retval);
+ /* Don't strfreev, since we didn't copy the individual strings. */
+ g_free (strv);
- return retval;
+ return retval;
}
static GList *
comma_separated_str_to_str_list (const char *str)
{
- return strsplit_to_list (str, ",", 0);
+ return strsplit_to_list (str, ",", 0);
}
static void
ready_callback (NautilusFile *file,
- gpointer callback_data)
+ gpointer callback_data)
{
- ready = TRUE;
+ ready = TRUE;
}
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
- const char *uri;
- const char *field;
- const char *value;
- NautilusFile *file;
- NautilusFileAttributes attributes;
-
- gtk_init (&argc, &argv);
-
- if (argc < 3) {
- usage (argv[0]);
- }
-
- uri = argv[1];
- field = argv[2];
- value = argv[3];
-
- file = nautilus_file_get_by_uri (uri);
-
- attributes = nautilus_mime_actions_get_full_file_attributes ();
- nautilus_file_call_when_ready (file, attributes, ready_callback, NULL);
-
- while (!ready) {
- gtk_main_iteration ();
- }
-
- if (strcmp (field, "default_action_type") == 0) {
- puts ("default_action_type");
- nautilus_mime_set_default_action_type_for_file (file, str_to_action_type (value));
- } else if (strcmp (field, "default_application") == 0) {
- puts ("default_application");
- nautilus_mime_set_default_application_for_file (file, value);
- } else if (strcmp (field, "default_component") == 0) {
- puts ("default_component");
- nautilus_mime_set_default_component_for_file (file, value);
- } else if (strcmp (field, "short_list_applicationss") == 0) {
- puts ("short_list_applications");
- nautilus_mime_set_short_list_applications_for_file
- (file, comma_separated_str_to_str_list (value));
- } else if (strcmp (field, "short_list_components") == 0) {
- puts ("short_list_components");
- nautilus_mime_set_short_list_components_for_file
- (file, comma_separated_str_to_str_list (value));
- } else if (strcmp (field, "add_to_all_applicationss") == 0) {
- puts ("add_to_all_applications");
- nautilus_mime_extend_all_applications_for_file
- (file, comma_separated_str_to_str_list (value));
- } else if (strcmp (field, "remove_from_all_applications") == 0) {
- puts ("remove_from_all_applications");
- nautilus_mime_remove_from_all_applications_for_file
- (file, comma_separated_str_to_str_list (value));
-
- } else {
- usage (argv[0]);
- }
-
- return 0;
+ const char *uri;
+ const char *field;
+ const char *value;
+ NautilusFile *file;
+ NautilusFileAttributes attributes;
+
+ gtk_init (&argc, &argv);
+
+ if (argc < 3)
+ {
+ usage (argv[0]);
+ }
+
+ uri = argv[1];
+ field = argv[2];
+ value = argv[3];
+
+ file = nautilus_file_get_by_uri (uri);
+
+ attributes = nautilus_mime_actions_get_full_file_attributes ();
+ nautilus_file_call_when_ready (file, attributes, ready_callback, NULL);
+
+ while (!ready)
+ {
+ gtk_main_iteration ();
+ }
+
+ if (strcmp (field, "default_action_type") == 0)
+ {
+ puts ("default_action_type");
+ nautilus_mime_set_default_action_type_for_file (file, str_to_action_type (value));
+ }
+ else if (strcmp (field, "default_application") == 0)
+ {
+ puts ("default_application");
+ nautilus_mime_set_default_application_for_file (file, value);
+ }
+ else if (strcmp (field, "default_component") == 0)
+ {
+ puts ("default_component");
+ nautilus_mime_set_default_component_for_file (file, value);
+ }
+ else if (strcmp (field, "short_list_applicationss") == 0)
+ {
+ puts ("short_list_applications");
+ nautilus_mime_set_short_list_applications_for_file
+ (file, comma_separated_str_to_str_list (value));
+ }
+ else if (strcmp (field, "short_list_components") == 0)
+ {
+ puts ("short_list_components");
+ nautilus_mime_set_short_list_components_for_file
+ (file, comma_separated_str_to_str_list (value));
+ }
+ else if (strcmp (field, "add_to_all_applicationss") == 0)
+ {
+ puts ("add_to_all_applications");
+ nautilus_mime_extend_all_applications_for_file
+ (file, comma_separated_str_to_str_list (value));
+ }
+ else if (strcmp (field, "remove_from_all_applications") == 0)
+ {
+ puts ("remove_from_all_applications");
+ nautilus_mime_remove_from_all_applications_for_file
+ (file, comma_separated_str_to_str_list (value));
+ }
+ else
+ {
+ usage (argv[0]);
+ }
+
+ return 0;
}
diff --git a/test/test-nautilus-mime-actions.c b/test/test-nautilus-mime-actions.c
index 761c4a960..38e140fd6 100644
--- a/test/test-nautilus-mime-actions.c
+++ b/test/test-nautilus-mime-actions.c
@@ -1,25 +1,25 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* test-mime.c - Test for the mime handler detection features of the GNOME
- Virtual File System Library
-
- Copyright (C) 2000 Eazel
-
- The Gnome Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Library 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
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- see <http://www.gnu.org/licenses/>.
-
- Author: Maciej Stachowiak <mjs@eazel.com>
-*/
+ * Virtual File System Library
+ *
+ * Copyright (C) 2000 Eazel
+ *
+ * The Gnome Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The Gnome Library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Maciej Stachowiak <mjs@eazel.com>
+ */
#include <config.h>
@@ -32,104 +32,114 @@ static gboolean ready = FALSE;
static void
append_comma_and_scheme (gpointer scheme,
- gpointer user_data)
+ gpointer user_data)
{
- char **string;
-
- string = (char **) user_data;
- if (strlen (*string) > 0) {
- *string = g_strconcat (*string, ", ", scheme, NULL);
- }
- else {
- *string = g_strdup (scheme);
- }
+ char **string;
+
+ string = (char **) user_data;
+ if (strlen (*string) > 0)
+ {
+ *string = g_strconcat (*string, ", ", scheme, NULL);
+ }
+ else
+ {
+ *string = g_strdup (scheme);
+ }
}
static char *
format_supported_uri_schemes_for_display (GList *supported_uri_schemes)
{
- char *string;
+ char *string;
- string = g_strdup ("");
- g_list_foreach (supported_uri_schemes,
- append_comma_and_scheme,
- &string);
- return string;
+ string = g_strdup ("");
+ g_list_foreach (supported_uri_schemes,
+ append_comma_and_scheme,
+ &string);
+ return string;
}
static void
print_application (GAppInfo *application)
{
- if (application == NULL) {
- puts ("(none)");
- } else {
- printf ("name: %s\ncommand: %s\nexpects_uris: %s\n",
- g_application_get_name (application),
- g_application_get_executable (application),
- (g_app_info_supports_uris (application) ? "TRUE" : "FALSE"));
- }
+ if (application == NULL)
+ {
+ puts ("(none)");
+ }
+ else
+ {
+ printf ("name: %s\ncommand: %s\nexpects_uris: %s\n",
+ g_application_get_name (application),
+ g_application_get_executable (application),
+ (g_app_info_supports_uris (application) ? "TRUE" : "FALSE"));
+ }
}
-static void
+static void
print_application_list (GList *applications)
{
- GList *p;
-
- if (applications == NULL) {
- puts ("(none)");
- } else {
- for (p = applications; p != NULL; p = p->next) {
- print_application (p->data);
- puts ("------");
- }
- }
+ GList *p;
+
+ if (applications == NULL)
+ {
+ puts ("(none)");
+ }
+ else
+ {
+ for (p = applications; p != NULL; p = p->next)
+ {
+ print_application (p->data);
+ puts ("------");
+ }
+ }
}
static void
ready_callback (NautilusFile *file,
- gpointer callback_data)
+ gpointer callback_data)
{
- ready = TRUE;
+ ready = TRUE;
}
int
-main (int argc, char **argv)
+main (int argc,
+ char **argv)
{
- const char *uri;
- GAppInfo *default_application;
- GList *all_applications;
- NautilusFile *file;
- NautilusFileAttributes attributes;
-
- gtk_init (&argc, &argv);
-
- if (argc != 2) {
- fprintf (stderr, "Usage: %s uri\n", *argv);
- return 1;
- }
-
- uri = argv[1];
- file = nautilus_file_get_by_uri (uri);
-
- attributes = nautilus_mime_actions_get_full_file_attributes ();
- nautilus_file_call_when_ready (file, attributes, ready_callback, NULL);
-
- while (!ready) {
- gtk_main_iteration ();
- }
-
- default_application = nautilus_mime_get_default_application_for_file (file);
- puts("Default Application");
- print_application (default_application);
- puts ("");
-
- all_applications = nautilus_mime_get_applications_for_file (file);
- puts("All Applications");
- print_application_list (all_applications);
- puts ("");
-
- return 0;
+ const char *uri;
+ GAppInfo *default_application;
+ GList *all_applications;
+ NautilusFile *file;
+ NautilusFileAttributes attributes;
+
+ gtk_init (&argc, &argv);
+
+ if (argc != 2)
+ {
+ fprintf (stderr, "Usage: %s uri\n", *argv);
+ return 1;
+ }
+
+ uri = argv[1];
+ file = nautilus_file_get_by_uri (uri);
+
+ attributes = nautilus_mime_actions_get_full_file_attributes ();
+ nautilus_file_call_when_ready (file, attributes, ready_callback, NULL);
+
+ while (!ready)
+ {
+ gtk_main_iteration ();
+ }
+
+ default_application = nautilus_mime_get_default_application_for_file (file);
+ puts ("Default Application");
+ print_application (default_application);
+ puts ("");
+
+ all_applications = nautilus_mime_get_applications_for_file (file);
+ puts ("All Applications");
+ print_application_list (all_applications);
+ puts ("");
+
+ return 0;
}
-
-
diff --git a/test/test-nautilus-search-engine.c b/test/test-nautilus-search-engine.c
index f37718072..2847109f4 100644
--- a/test/test-nautilus-search-engine.c
+++ b/test/test-nautilus-search-engine.c
@@ -3,57 +3,60 @@
#include <gtk/gtk.h>
static void
-hits_added_cb (NautilusSearchEngine *engine, GSList *hits)
-{
- g_print ("hits added\n");
- while (hits) {
- g_print (" - %s\n", (char *)hits->data);
- hits = hits->next;
- }
+hits_added_cb (NautilusSearchEngine *engine,
+ GSList *hits)
+{
+ g_print ("hits added\n");
+ while (hits)
+ {
+ g_print (" - %s\n", (char *) hits->data);
+ hits = hits->next;
+ }
}
static void
finished_cb (NautilusSearchEngine *engine,
NautilusSearchProviderStatus status)
{
- g_print ("finished!\n");
- gtk_main_quit ();
+ g_print ("finished!\n");
+ gtk_main_quit ();
}
-int
-main (int argc, char* argv[])
+int
+main (int argc,
+ char *argv[])
{
- NautilusSearchEngine *engine;
- NautilusSearchEngineModel *model;
- NautilusDirectory *directory;
- NautilusQuery *query;
- GFile *location;
-
- gtk_init (&argc, &argv);
-
- engine = nautilus_search_engine_new ();
- g_signal_connect (engine, "hits-added",
- G_CALLBACK (hits_added_cb), NULL);
- g_signal_connect (engine, "finished",
- G_CALLBACK (finished_cb), NULL);
-
- query = nautilus_query_new ();
- nautilus_query_set_text (query, "richard hult");
- nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
- g_object_unref (query);
-
- location = g_file_new_for_path (g_get_home_dir ());
- directory = nautilus_directory_get (location);
- g_object_unref (location);
-
- model = nautilus_search_engine_get_model_provider (engine);
- nautilus_search_engine_model_set_model (model, directory);
- g_object_unref (directory);
-
- nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine));
- nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
- g_object_unref (engine);
-
- gtk_main ();
- return 0;
+ NautilusSearchEngine *engine;
+ NautilusSearchEngineModel *model;
+ NautilusDirectory *directory;
+ NautilusQuery *query;
+ GFile *location;
+
+ gtk_init (&argc, &argv);
+
+ engine = nautilus_search_engine_new ();
+ g_signal_connect (engine, "hits-added",
+ G_CALLBACK (hits_added_cb), NULL);
+ g_signal_connect (engine, "finished",
+ G_CALLBACK (finished_cb), NULL);
+
+ query = nautilus_query_new ();
+ nautilus_query_set_text (query, "richard hult");
+ nautilus_search_provider_set_query (NAUTILUS_SEARCH_PROVIDER (engine), query);
+ g_object_unref (query);
+
+ location = g_file_new_for_path (g_get_home_dir ());
+ directory = nautilus_directory_get (location);
+ g_object_unref (location);
+
+ model = nautilus_search_engine_get_model_provider (engine);
+ nautilus_search_engine_model_set_model (model, directory);
+ g_object_unref (directory);
+
+ nautilus_search_provider_start (NAUTILUS_SEARCH_PROVIDER (engine));
+ nautilus_search_provider_stop (NAUTILUS_SEARCH_PROVIDER (engine));
+ g_object_unref (engine);
+
+ gtk_main ();
+ return 0;
}
diff --git a/test/test.c b/test/test.c
index 5481044f5..43e8fbc43 100644
--- a/test/test.c
+++ b/test/test.c
@@ -3,115 +3,123 @@
#include <unistd.h>
void
-test_init (int *argc,
- char ***argv)
+test_init (int *argc,
+ char ***argv)
{
- gtk_init (argc, argv);
+ gtk_init (argc, argv);
- eel_make_warnings_and_criticals_stop_in_debugger ();
+ eel_make_warnings_and_criticals_stop_in_debugger ();
}
int
test_quit (int exit_code)
{
- if (gtk_main_level () > 0) {
- gtk_main_quit ();
- }
+ if (gtk_main_level () > 0)
+ {
+ gtk_main_quit ();
+ }
- return exit_code;
+ return exit_code;
}
void
test_delete_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer callback_data)
+ GdkEvent *event,
+ gpointer callback_data)
{
- test_quit (0);
+ test_quit (0);
}
GtkWidget *
-test_window_new (const char *title, guint border_width)
+test_window_new (const char *title,
+ guint border_width)
{
- GtkWidget *window;
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- if (title != NULL) {
- gtk_window_set_title (GTK_WINDOW (window), title);
- }
-
- g_signal_connect (window, "delete_event",
- G_CALLBACK (test_delete_event), NULL);
-
- gtk_container_set_border_width (GTK_CONTAINER (window), border_width);
-
- return window;
+ GtkWidget *window;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ if (title != NULL)
+ {
+ gtk_window_set_title (GTK_WINDOW (window), title);
+ }
+
+ g_signal_connect (window, "delete_event",
+ G_CALLBACK (test_delete_event), NULL);
+
+ gtk_container_set_border_width (GTK_CONTAINER (window), border_width);
+
+ return window;
}
GdkPixbuf *
-test_pixbuf_new_named (const char *name, float scale)
+test_pixbuf_new_named (const char *name,
+ float scale)
{
- GdkPixbuf *pixbuf;
- char *path;
+ GdkPixbuf *pixbuf;
+ char *path;
- g_return_val_if_fail (name != NULL, NULL);
- g_return_val_if_fail (scale >= 0.0, NULL);
+ g_return_val_if_fail (name != NULL, NULL);
+ g_return_val_if_fail (scale >= 0.0, NULL);
- if (name[0] == '/') {
- path = g_strdup (name);
- } else {
- path = g_strdup_printf ("%s/%s", NAUTILUS_DATADIR, name);
- }
+ if (name[0] == '/')
+ {
+ path = g_strdup (name);
+ }
+ else
+ {
+ path = g_strdup_printf ("%s/%s", NAUTILUS_DATADIR, name);
+ }
- pixbuf = gdk_pixbuf_new_from_file (path, NULL);
+ pixbuf = gdk_pixbuf_new_from_file (path, NULL);
- g_free (path);
+ g_free (path);
- g_return_val_if_fail (pixbuf != NULL, NULL);
-
- if (scale != 1.0) {
- GdkPixbuf *scaled;
- float width = gdk_pixbuf_get_width (pixbuf) * scale;
- float height = gdk_pixbuf_get_width (pixbuf) * scale;
+ g_return_val_if_fail (pixbuf != NULL, NULL);
- scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
+ if (scale != 1.0)
+ {
+ GdkPixbuf *scaled;
+ float width = gdk_pixbuf_get_width (pixbuf) * scale;
+ float height = gdk_pixbuf_get_width (pixbuf) * scale;
- g_object_unref (pixbuf);
+ scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
- g_return_val_if_fail (scaled != NULL, NULL);
+ g_object_unref (pixbuf);
- pixbuf = scaled;
- }
+ g_return_val_if_fail (scaled != NULL, NULL);
- return pixbuf;
+ pixbuf = scaled;
+ }
+
+ return pixbuf;
}
GtkWidget *
test_label_new (const char *text,
- gboolean with_background,
- int num_sizes_larger)
+ gboolean with_background,
+ int num_sizes_larger)
{
- GtkWidget *label;
+ GtkWidget *label;
+
+ if (text == NULL)
+ {
+ text = "Foo";
+ }
- if (text == NULL) {
- text = "Foo";
- }
-
- label = gtk_label_new (text);
+ label = gtk_label_new (text);
- return label;
+ return label;
}
-void
-test_window_set_title_with_pid (GtkWindow *window,
- const char *title)
+void
+test_window_set_title_with_pid (GtkWindow *window,
+ const char *title)
{
- char *tmp;
-
- g_return_if_fail (GTK_IS_WINDOW (window));
+ char *tmp;
- tmp = g_strdup_printf ("%lu: %s", (gulong) getpid (), title);
- gtk_window_set_title (GTK_WINDOW (window), tmp);
- g_free (tmp);
-}
+ g_return_if_fail (GTK_IS_WINDOW (window));
+ tmp = g_strdup_printf ("%lu: %s", (gulong) getpid (), title);
+ gtk_window_set_title (GTK_WINDOW (window), tmp);
+ g_free (tmp);
+}
diff --git a/test/uncrustify-sample.c b/test/uncrustify-sample.c
deleted file mode 100644
index 2ed14be4f..000000000
--- a/test/uncrustify-sample.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-Extremely poorly formatted code to test uncrustify.cfg against the contiki code style
- */
-
-#if defined (FOO)
- # define BAR 3
-#else
- # define BAR 3
-# endif
-
-/* Aligment of parameters doesn't work as completely expected. Should align the
- * stars themselves. */
-static int some_function ( int *f , char **c, LongTypeException a) {
-
- /* This is indented with a tab. Should become spaces */
- int a = 5; // This should become a C comment
- int d= - 10; /* Space around assignment, No space between - and 10 */
- int* b; /* no space before the *, yes space between * and variable name */
-
- some_function(
- a,
- b
- )
-
-/* Should indent the for correctly and sort out spacing mess:
- - for(i = 0; i < 10; ++i)
- - Should pull the opening brace up to the same line as the for
-*/
-for( i=0 ;i<10; ++ i ) { if (a < 0) {
- a= ! c ; /* Should add space after a and remove space before and after c */
-
- /* } else { always in the same line */
- }
- else
- {
- /* incorrect indentation here */
-
- f();
- }
- }
-
- b = & c; /* 'address of' adjacent to variable */
- * b = 3; /* dereference: no space */
-
- /* Should automatically add braces below */
- if(a == 0)
- printf ( "a\n") ;
-
- while(1) ; /* This needs fixed */
-
- switch(a) {
- case 3 :
-4;
-5;
- break;
- }
-
- /* No blank lines before the closing brace */
-
- return (-1); /* No parenthesis around return values */
-
-
-}