[Xfce4-commits] <thunar:master> Implement a new D-Bus method RenameFile(uri, display, startup-id).
Jannis Pohlmann
noreply at xfce.org
Mon Oct 18 14:10:03 CEST 2010
Updating branch refs/heads/master
to d06ae5418ce434dd83579b2a21e56e00355bc572 (commit)
from ad739c46f8e0b06c1cfefb1117ed8c870de9ff12 (commit)
commit d06ae5418ce434dd83579b2a21e56e00355bc572
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Mon Oct 18 14:06:58 2010 +0200
Implement a new D-Bus method RenameFile(uri, display, startup-id).
This method can be used by applications like xfdesktop in order to
prompt the user to choose a new name for a file. This way xfdesktop
doesn't have to implement the rename dialog and method itself anymore,
which results in a more consistent UI and only one place would have to
be changed if this UI needs to be revamped later.
thunar/thunar-application.c | 70 ++++++++++++++++++++++++++++++++++
thunar/thunar-application.h | 5 ++
thunar/thunar-dbus-service-infos.xml | 17 ++++++++-
thunar/thunar-dbus-service.c | 34 ++++++++++++++++
4 files changed, 125 insertions(+), 1 deletions(-)
diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c
index f0de840..950604a 100644
--- a/thunar/thunar-application.c
+++ b/thunar/thunar-application.c
@@ -148,6 +148,7 @@ struct _ThunarApplication
static GQuark thunar_application_screen_quark;
static GQuark thunar_application_startup_id_quark;
+static GQuark thunar_application_file_quark;
@@ -166,6 +167,8 @@ thunar_application_class_init (ThunarApplicationClass *klass)
g_quark_from_static_string ("thunar-application-screen");
thunar_application_startup_id_quark =
g_quark_from_static_string ("thunar-application-startup-id");
+ thunar_application_file_quark =
+ g_quark_from_static_string ("thunar-application-file");
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = thunar_application_finalize;
@@ -1209,6 +1212,73 @@ thunar_application_is_processing (ThunarApplication *application)
+static void
+thunar_application_rename_file_error (ExoJob *job,
+ GError *error,
+ ThunarApplication *application)
+{
+ ThunarFile *file;
+ GdkScreen *screen;
+
+ _thunar_return_if_fail (EXO_IS_JOB (job));
+ _thunar_return_if_fail (error != NULL);
+ _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
+
+ screen = g_object_get_qdata (G_OBJECT (job), thunar_application_screen_quark);
+ file = g_object_get_qdata (G_OBJECT (job), thunar_application_file_quark);
+
+ g_assert (screen != NULL);
+ g_assert (file != NULL);
+
+ thunar_dialogs_show_error (screen, error, _("Failed to rename \"%s\""),
+ thunar_file_get_display_name (file));
+}
+
+
+
+/**
+ * thunar_application_rename_file:
+ * @application : a #ThunarApplication.
+ * @file : a #ThunarFile to be renamed.
+ * @screen : the #GdkScreen on which to open the window or %NULL
+ * to open on the default screen.
+ * @startup_id : startup id from startup notification passed along
+ * with dbus to make focus stealing work properly.
+ *
+ * Prompts the user to rename the @file.
+ **/
+void
+thunar_application_rename_file (ThunarApplication *application,
+ ThunarFile *file,
+ GdkScreen *screen,
+ const gchar *startup_id)
+{
+ ThunarJob *job;
+
+ _thunar_return_if_fail (THUNAR_IS_APPLICATION (application));
+ _thunar_return_if_fail (THUNAR_IS_FILE (file));
+ _thunar_return_if_fail (GDK_IS_SCREEN (screen));
+ _thunar_return_if_fail (startup_id != NULL);
+
+ /* TODO pass the startup ID to the rename dialog */
+
+ /* run the rename dialog */
+ job = thunar_dialogs_show_rename_file (screen, file);
+ if (G_LIKELY (job != NULL))
+ {
+ /* remember the screen and file */
+ g_object_set_qdata (G_OBJECT (job), thunar_application_screen_quark, screen);
+ g_object_set_qdata_full (G_OBJECT (job), thunar_application_file_quark,
+ g_object_ref (file), g_object_unref);
+
+ /* handle rename errors */
+ g_signal_connect (job, "error",
+ G_CALLBACK (thunar_application_rename_file_error), application);
+ }
+}
+
+
+
/**
* thunar_application_copy_to:
* @application : a #ThunarApplication.
diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h
index 7b1ceab..f00be2a 100644
--- a/thunar/thunar-application.h
+++ b/thunar/thunar-application.h
@@ -75,6 +75,11 @@ gboolean thunar_application_process_filenames (ThunarApplication *ap
gboolean thunar_application_is_processing (ThunarApplication *application);
+void thunar_application_rename_file (ThunarApplication *application,
+ ThunarFile *file,
+ GdkScreen *screen,
+ const gchar *startup_id);
+
void thunar_application_copy_to (ThunarApplication *application,
gpointer parent,
GList *source_file_list,
diff --git a/thunar/thunar-dbus-service-infos.xml b/thunar/thunar-dbus-service-infos.xml
index 4e19add..fd53a52 100644
--- a/thunar/thunar-dbus-service-infos.xml
+++ b/thunar/thunar-dbus-service-infos.xml
@@ -263,7 +263,7 @@
display : the screen on which to launch the filenames or ""
to use the default screen of the file manager.
startup_id : the DESKTOP_STARTUP_ID environment variable for properly
- handling startup notification and focus stealing.
+ handling startup notification and focus stealing.
-->
<method name="LaunchFiles">
<arg direction="in" name="working_directory" type="s" />
@@ -271,6 +271,21 @@
<arg direction="in" name="display" type="s" />
<arg direction="in" name="startup_id" type="s" />
</method>
+
+ <!--
+ RenameFile (uri : STRING, display : STRING, startup_id : STRING) : VOID
+
+ uri : a URI to rename. This may be either a file:-URI or an absolute path.
+ display : the screen on which to launch the filenames or ""
+ to use the default screen of the file manager.
+ startup_id : the DESKTOP_STARTUP_ID environment variable for properly
+ handling startup notification and focus stealing.
+ -->
+ <method name="RenameFile">
+ <arg direction="in" name="filename" type="s" />
+ <arg direction="in" name="display" type="s" />
+ <arg direction="in" name="startup_id" type="s" />
+ </method>
</interface>
diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c
index 312da62..672a0de 100644
--- a/thunar/thunar-dbus-service.c
+++ b/thunar/thunar-dbus-service.c
@@ -136,6 +136,11 @@ static gboolean thunar_dbus_service_launch_files (ThunarDBusServi
const gchar *display,
const gchar *startup_id,
GError **error);
+static gboolean thunar_dbus_service_rename_file (ThunarDBusService *dbus_service,
+ const gchar *uri,
+ const gchar *display,
+ const gchar *startup_id,
+ GError **error);
static gboolean thunar_dbus_service_copy_to (ThunarDBusService *dbus_service,
const gchar *working_directory,
gchar **source_filenames,
@@ -798,6 +803,35 @@ thunar_dbus_service_launch_files (ThunarDBusService *dbus_service,
static gboolean
+thunar_dbus_service_rename_file (ThunarDBusService *dbus_service,
+ const gchar *uri,
+ const gchar *display,
+ const gchar *startup_id,
+ GError **error)
+{
+ ThunarApplication *application;
+ ThunarFile *file;
+ GdkScreen *screen;
+
+ /* parse uri and display parameters */
+ if (!thunar_dbus_service_parse_uri_and_display (dbus_service, uri, display, &file, &screen, error))
+ return FALSE;
+
+ /* popup a new window for the folder */
+ application = thunar_application_get ();
+ thunar_application_rename_file (application, file, screen, startup_id);
+ g_object_unref (G_OBJECT (application));
+
+ /* cleanup */
+ g_object_unref (G_OBJECT (screen));
+ g_object_unref (G_OBJECT (file));
+
+ return TRUE;
+}
+
+
+
+static gboolean
thunar_dbus_service_transfer_files (ThunarDBusTransferMode transfer_mode,
const gchar *working_directory,
const gchar * const *source_filenames,
More information about the Xfce4-commits
mailing list