~brandontschaefer/unity/lp.1099815-fix

« back to all changes in this revision

Viewing changes to unity-shared/GnomeFileManager.cpp

  • Committer: Tarmac
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2013-03-25 18:41:43 UTC
  • mfrom: (3212.3.12 trash-open-timestamp)
  • Revision ID: tarmac-20130325184143-sftn0atpeq9y21fq
FileManagerOpener: moved to unity-shared and renamed as FileManager

The implementation is GnomeFileManager. Updated TrashLauncherIcon and VolumeImp. Fixes: https://bugs.launchpad.net/bugs/807808.

Approved by PS Jenkins bot, Brandon Schaefer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *              Marco Trevisan <marco.trevisan@canonical.com>
19
19
 */
20
20
 
21
 
#include "FileManagerOpenerImp.h"
 
21
#include "GnomeFileManager.h"
22
22
#include <NuxCore/Logger.h>
23
23
#include <UnityCore/GLibWrapper.h>
 
24
#include <UnityCore/GLibDBusProxy.h>
24
25
#include <gdk/gdk.h>
 
26
#include <gio/gio.h>
25
27
 
26
28
namespace unity
27
29
{
28
 
namespace launcher
 
30
 
 
31
namespace
29
32
{
30
 
 
31
 
DECLARE_LOGGER(logger, "unity.launcher.filemanager.opener.imp");
32
 
 
33
 
void FileManagerOpenerImp::Open(std::string const& uri, unsigned long long timestamp)
 
33
DECLARE_LOGGER(logger, "unity.filemanager.gnome");
 
34
 
 
35
const std::string TRASH_URI = "trash:";
 
36
}
 
37
 
 
38
void GnomeFileManager::Open(std::string const& uri, unsigned long long timestamp)
34
39
{
35
40
  if (uri.empty())
36
41
  {
54
59
  }
55
60
}
56
61
 
57
 
}
 
62
void GnomeFileManager::Activate(unsigned long long timestamp)
 
63
{
 
64
  glib::Cancellable cancellable;
 
65
  glib::Object<GFile> file(g_file_new_for_uri(TRASH_URI.c_str()));
 
66
  glib::Object<GAppInfo> app_info(g_file_query_default_handler(file, cancellable, nullptr));
 
67
 
 
68
  if (app_info)
 
69
  {
 
70
    GdkDisplay* display = gdk_display_get_default();
 
71
    glib::Object<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
 
72
 
 
73
    if (timestamp > 0)
 
74
      gdk_app_launch_context_set_timestamp(context, timestamp);
 
75
 
 
76
    auto const& gcontext = glib::object_cast<GAppLaunchContext>(context);
 
77
    auto proxy = std::make_shared<glib::DBusProxy>("org.gnome.NautilusApplication",
 
78
                                                   "/org/gnome/NautilusApplication",
 
79
                                                   "org.gtk.Application");
 
80
 
 
81
    glib::String context_string(g_app_launch_context_get_startup_notify_id(gcontext, app_info, nullptr));
 
82
 
 
83
    if (context_string && g_utf8_validate(context_string, -1, nullptr))
 
84
    {
 
85
      GVariantBuilder builder;
 
86
      g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
 
87
      g_variant_builder_add(&builder, "{sv}", "desktop-startup-id", g_variant_new("s", context_string.Value()));
 
88
      GVariant *param = g_variant_new("(@a{sv})", g_variant_builder_end(&builder));
 
89
 
 
90
      // Passing the proxy to the lambda we ensure that it will be destroyed when needed
 
91
      proxy->CallBegin("Activate", param, [proxy] (GVariant*, glib::Error const&) {});
 
92
    }
 
93
  }
 
94
}
 
95
 
 
96
void GnomeFileManager::EmptyTrash(unsigned long long timestamp)
 
97
{
 
98
  Activate(timestamp);
 
99
 
 
100
  auto proxy = std::make_shared<glib::DBusProxy>("org.gnome.Nautilus", "/org/gnome/Nautilus",
 
101
                                                 "org.gnome.Nautilus.FileOperations");
 
102
 
 
103
  // Passing the proxy to the lambda we ensure that it will be destroyed when needed
 
104
  proxy->CallBegin("EmptyTrash", nullptr, [proxy] (GVariant*, glib::Error const&) {});
 
105
}
 
106
 
58
107
}