~ken-vandine/unity-scope-gdrive/libunity7_merge

« back to all changes in this revision

Viewing changes to unity-scope-gdrive

  • Committer: David Callé
  • Date: 2013-03-11 16:43:34 UTC
  • Revision ID: davidc@framli.eu-20130311164334-nccegbnn587uczl9
Port to Libunity7 (DeprecatedScope), filtering is WIP

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 
10
10
import sys
11
11
from gi.repository import GLib, GObject, Gio
12
 
from gi.repository import Dee
13
12
from gi.repository import Accounts, Signon
14
13
from gi.repository import GData
15
 
 
16
 
# FIXME: Some weird bug in Dee or PyGI makes Dee fail unless we probe
17
 
#        it *before* we import the Unity module... ?!
18
 
_m = dir(Dee.SequenceModel)
19
 
from gi.repository import Unity
 
14
from gi.repository import Unity, UnityExtras
20
15
 
21
16
from datetime import datetime, timedelta
22
17
import time
38
33
class Daemon:
39
34
 
40
35
  def __init__ (self):
41
 
    self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdrive")
 
36
    self._scope = Unity.DeprecatedScope.new ("/net/launchpad/unity/scope/gdrive", "gdrive")
42
37
    self._scope.search_in_global = True;
43
38
    self._preferences = Unity.PreferencesManager.get_default()
44
39
    self._preferences.connect ("notify::remote-content-search",
61
56
    # Though it's possible to connect to a more-specific changed signal on each
62
57
    # Fitler, as we re-do the search anyway, this catch-all signal is perfect for
63
58
    # us.
64
 
    self._scope.connect ("filters-changed", self._on_filters_or_preferences_changed);
 
59
#    self._scope.connect ("filters-changed", self._on_filters_or_preferences_changed);
65
60
    self._scope.export()
66
61
 
67
62
  def _on_enabled_event (self, account_manager, account_id):
82
77
    search_string = search.props.search_string
83
78
    results = search.props.results_model
84
79
    results.clear()
85
 
    # Flush the results
86
 
    results.flush_revision_queue()
87
80
 
88
81
    if self._preferences.props.remote_content_search != Unity.PreferencesManagerRemoteContent.ALL:
89
82
      search.emit("finished")
129
122
    identity = auth_data.get_credentials_id()
130
123
    session_data = auth_data.get_parameters()
131
124
    self._auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
132
 
    self._main_loop = GObject.MainLoop()
 
125
    self._main_loop = GLib.MainLoop()
133
126
    self._auth_session.process(session_data,
134
127
            auth_data.get_mechanism(),
135
128
            self.login_cb, None)
193
186
        else:
194
187
          category = 0
195
188
 
196
 
      model.append(entry.look_up_link(GData.LINK_ALTERNATE).get_uri(),
197
 
                   self.icon_for_type(rtype),
198
 
                   category,
199
 
                   "text/html",
200
 
                   entry.props.title,
201
 
                   rtype,
202
 
                   entry.props.content_uri);
 
189
      model.append(uri=entry.look_up_link(GData.LINK_ALTERNATE).get_uri(),
 
190
                   icon_hint=self.icon_for_type(rtype),
 
191
                   category=category,
 
192
                   mimetype="text/html",
 
193
                   title=entry.props.title,
 
194
                   comment=rtype,
 
195
                   dnd_uri=entry.props.content_uri,
 
196
                   result_type=Unity.ResultType.PERSONAL);
203
197
 
204
198
  # This is where we do the actual search for documents
205
199
  def get_doc_list (self, search, is_global):
275
269
 
276
270
    return ret;
277
271
 
278
 
if __name__ == "__main__":
279
 
  # NOTE: If we used the normal 'dbus' module for Python we'll get
280
 
  #       slightly odd results because it uses a default connection
281
 
  #       to the session bus that is different from the default connection
282
 
  #       GDBus (hence libunity) will use. Meaning that the daemon name
283
 
  #       will be owned by a connection different from the one all our
284
 
  #       Dee + Unity magic is working on...
285
 
  #       Still waiting for nice GDBus bindings to land:
286
 
  #                        http://www.piware.de/2011/01/na-zdravi-pygi/  
287
 
  session_bus_connection = Gio.bus_get_sync (Gio.BusType.SESSION, None)
288
 
  session_bus = Gio.DBusProxy.new_sync (session_bus_connection, 0, None,
289
 
                                        'org.freedesktop.DBus',
290
 
                                        '/org/freedesktop/DBus',
291
 
                                        'org.freedesktop.DBus', None)
292
 
  result = session_bus.call_sync('RequestName',
293
 
                                 GLib.Variant ("(su)", (BUS_NAME, 0x4)),
294
 
                                 0, -1, None)
295
 
                                 
296
 
  # Unpack variant response with signature "(u)". 1 means we got it.
297
 
  result = result.unpack()[0]
298
 
  
299
 
  if result != 1 :
300
 
    print("Failed to own name %s. Bailing out." % BUS_NAME)
301
 
    raise SystemExit (1)
302
 
  
303
 
  daemon = Daemon()
304
 
  GObject.MainLoop().run()
 
272
if __name__ == '__main__':
 
273
    daemon = UnityExtras.dbus_own_name(BUS_NAME, Daemon, None)
 
274
    if daemon:
 
275
        GLib.unix_signal_add(0, 2, lambda x: daemon.quit(), None)
 
276
        daemon.run([])
305
277