Skip to content

Commit fb4446d

Browse files
fxriraveit65
authored andcommitted
Use new DBus API to show the current image in the file browser
This improves the functionality implemented with commit 9df5fd43. The new API that will be included in Nautilus 3.3.4 not only opens a view for the containing folder but also marks the image in the view. The old behaviour is still available as fallback if the new API is not offered on the system. https://bugzilla.gnome.org/show_bug.cgi?id=650402 origin commit: https://git.gnome.org/browse/eog/commit/?h=gnome-3-4&id=fa74473
1 parent 07de875 commit fb4446d

File tree

3 files changed

+96
-34
lines changed

3 files changed

+96
-34
lines changed

‎src/eom-util.c‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,89 @@ eom_util_file_is_persistent (GFile *file)
343343

344344
return TRUE;
345345
}
346+
347+
static void
348+
_eom_util_show_file_in_filemanager_fallback (GFile *file, GdkScreen *screen)
349+
{
350+
gchar *uri = NULL;
351+
GError *error = NULL;
352+
guint32 timestamp = gtk_get_current_event_time ();
353+
354+
if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY) {
355+
uri = g_file_get_uri (file);
356+
} else {
357+
/* If input file is not a directory we must open it's
358+
folder/parent to avoid opening the file itself */
359+
GFile *parent_file;
360+
361+
parent_file = g_file_get_parent (file);
362+
if (G_LIKELY (parent_file))
363+
uri = g_file_get_uri (parent_file);
364+
g_object_unref (parent_file);
365+
}
366+
367+
if (uri && !gtk_show_uri (screen, uri, timestamp, &error)) {
368+
g_warning ("Couldn't show containing folder \"%s\": %s", uri,
369+
error->message);
370+
g_error_free (error);
371+
}
372+
373+
g_free (uri);
374+
}
375+
376+
void
377+
eom_util_show_file_in_filemanager (GFile *file, GdkScreen *screen)
378+
{
379+
GDBusProxy *proxy;
380+
gboolean done = FALSE;
381+
382+
g_return_if_fail (file != NULL);
383+
384+
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
385+
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS |
386+
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
387+
NULL, "org.freedesktop.FileManager1",
388+
"/org/freedesktop/FileManager1",
389+
"org.freedesktop.FileManager1",
390+
NULL, NULL);
391+
392+
if (proxy) {
393+
gchar *uri = g_file_get_uri (file);
394+
gchar *startup_id;
395+
GVariant *params, *result;
396+
GVariantBuilder builder;
397+
398+
g_variant_builder_init (&builder,
399+
G_VARIANT_TYPE ("as"));
400+
g_variant_builder_add (&builder, "s", uri);
401+
402+
/* This seems to be the expected format, as other values
403+
cause the filemanager window not to get focus. */
404+
startup_id = g_strdup_printf("_TIME%u",
405+
gtk_get_current_event_time());
406+
407+
/* params is floating! */
408+
params = g_variant_new ("(ass)", &builder, startup_id);
409+
410+
g_free (startup_id);
411+
g_variant_builder_clear (&builder);
412+
413+
/* Floating params-GVariant is consumed here */
414+
result = g_dbus_proxy_call_sync (proxy, "ShowItems",
415+
params, G_DBUS_CALL_FLAGS_NONE,
416+
-1, NULL, NULL);
417+
418+
/* Receiving a non-NULL result counts as a successful call. */
419+
if (G_LIKELY (result != NULL)) {
420+
done = TRUE;
421+
g_variant_unref (result);
422+
}
423+
424+
g_free (uri);
425+
g_object_unref (proxy);
426+
}
427+
428+
/* Fallback to gtk_show_uri() if launch over DBus is not possible */
429+
if (!done)
430+
_eom_util_show_file_in_filemanager_fallback (file, screen);
431+
}

‎src/eom-util.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ char * eom_util_filename_get_extension (const char * filename_with_extensi
6363
G_GNUC_INTERNAL
6464
gboolean eom_util_file_is_persistent (GFile *file);
6565

66+
G_GNUC_INTERNAL
67+
void eom_util_show_file_in_filemanager (GFile *file,
68+
GdkScreen *screen);
69+
6670
G_END_DECLS
6771

6872
#endif /* __EOM_UTIL_H__ */

‎src/eom-window.c‎

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,49 +2956,21 @@ eom_window_cmd_save_as (GtkAction *action, gpointer user_data)
29562956
static void
29572957
eom_window_cmd_open_containing_folder (GtkAction *action, gpointer user_data)
29582958
{
2959-
EomWindow *window = EOM_WINDOW (user_data);
29602959
EomWindowPrivate *priv;
29612960

2962-
GtkWidget *eom_window_widget;
2963-
29642961
GFile *file;
2965-
GFile *parent = NULL;
2966-
2967-
eom_window_widget = GTK_WIDGET (window);
2968-
priv = window->priv;
2962+
g_return_if_fail (EOM_IS_WINDOW (user_data));
2963+
2964+
priv = EOM_WINDOW (user_data)->priv;
29692965

29702966
g_return_if_fail (priv->image != NULL);
29712967

29722968
file = eom_image_get_file (priv->image);
29732969

2974-
if (file) {
2975-
parent = g_file_get_parent (file);
2976-
g_object_unref(file);
2977-
}
2978-
2979-
if (parent) {
2980-
char *parent_uri;
2970+
g_return_if_fail (file != NULL);
29812971

2982-
parent_uri = g_file_get_uri (parent);
2983-
if (parent_uri) {
2984-
GdkScreen *screen;
2985-
guint32 timestamp;
2986-
GError *error;
2987-
2988-
screen = gtk_widget_get_screen (eom_window_widget);
2989-
timestamp = gtk_get_current_event_time ();
2990-
2991-
error = NULL;
2992-
if (!gtk_show_uri (screen, parent_uri, timestamp, &error)) {
2993-
eom_debug_message (DEBUG_WINDOW, "Could not open the containing folder");
2994-
g_error_free (error);
2995-
}
2996-
2997-
g_free (parent_uri);
2998-
}
2999-
3000-
g_object_unref(parent);
3001-
}
2972+
eom_util_show_file_in_filemanager (file,
2973+
gtk_widget_get_screen (GTK_WIDGET (user_data)));
30022974
}
30032975

30042976
static void

0 commit comments

Comments
 (0)