36
36
# The primary bus name we grab *must* match what we specify in our .scope file
38
self._scopes.append(scope)
42
+ self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdocs")
43
+ self._scope.search_in_global = True;
45
+ self._gdocs_accounts = []
46
self._account_manager = Accounts.Manager.new_for_service_type("documents")
47
self._account_manager.connect("enabled-event", self._on_enabled_event);
48
for account in self._account_manager.get_enabled_account_services():
49
self.add_account_service(account)
51
- def _on_enabled_event (self, account_manager, account_id):
52
- account = self._account_manager.get_account(account_id)
53
- for service in account.list_services():
54
- account_service = Accounts.AccountService.new(account, service)
55
- if account_service.get_enabled():
56
- self.add_account_service(account_service)
58
- def add_account_service(self, account_service):
59
- for scope in self._scopes:
60
- if scope.get_account_service() == account_service:
62
- scope = UserScope(account_service);
63
- self._scopes.append(scope)
41
66
-class OAuth2Token:
42
67
- def __init__(self, token):
43
68
- self._token = token
49
74
- def __eq__(self, other):
50
75
- return other and self._token == other._token
77
-# Encapsulates searching a single user's GDocs
79
- def __init__ (self, account_service):
80
- self._account_service = account_service
81
- self._account_service.connect("enabled", self._on_account_enabled)
82
- self._enabled = self._account_service.get_enabled()
83
- self._authenticating = False
84
- self._client = gdata.docs.client.DocsClient(source='njpatel-UnityLensGDocs-0.1')
85
- self._client.ssl = True
86
- self._client.http_client.debug = False
87
- self._queued_search = None
89
- self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdocs")
90
- self._scope.search_in_global = True;
92
# Listen for changes and requests
93
self._scope.connect ("search-changed", self._on_search_changed)
96
self._scope.connect ("filters-changed", self._on_filters_changed);
99
- # Initiate the login
103
- if self._authenticating:
106
- self._authenticating = True
107
+ def _on_enabled_event (self, account_manager, account_id):
108
+ account = self._account_manager.get_account(account_id)
109
+ for service in account.list_services():
110
+ account_service = Accounts.AccountService.new(account, service)
111
+ if account_service.get_enabled():
112
+ self.add_account_service(account_service)
114
+ def add_account_service(self, account_service):
115
+ for gdocs_account in self._gdocs_accounts:
116
+ if gdocs_account.get_account_service() == account_service:
118
+ gdocs_account = GDocsAccount(self._scope, account_service);
119
+ self._gdocs_accounts.append(gdocs_account)
121
+ def _on_search_changed (self, scope, search, search_type, cancellable):
122
+ search_string = search.props.search_string
123
+ results = search.props.results_model
124
+ if search_type == Unity.SearchType.GLOBAL:
129
+ print("Search changed to: '%s'" % search_string)
132
+ for gdocs_account in self._gdocs_accounts:
133
+ gdocs_account.update_results_model (search_string, results, is_global)
134
+ search.emit("finished")
136
+ def _on_filters_changed (self, scope, param_spec=None):
137
+ scope.queue_search_changed(Unity.SearchType.DEFAULT)
51
140
+class SignOnAuthorizer(GObject.Object, GData.Authorizer):
52
141
+ __g_type_name__ = "SignOnAuthorizer"
53
142
+ def __init__(self, account_service):
64
153
+ def do_refresh_authorization(self, cancellable):
65
154
+ old_token = self._token
66
+ # Get the global account settings
67
+ auth_data = self._account_service.get_auth_data()
68
+ identity = auth_data.get_credentials_id()
69
+ session_data = auth_data.get_parameters()
155
# Get the global account settings
156
auth_data = self._account_service.get_auth_data()
157
identity = auth_data.get_credentials_id()
158
session_data = auth_data.get_parameters()
159
- self.auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
160
- self.auth_session.process(session_data,
70
161
+ self._auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
71
162
+ self._main_loop = GObject.MainLoop()
72
163
+ self._auth_session.process(session_data,
73
+ auth_data.get_mechanism(),
74
+ self.login_cb, None)
164
auth_data.get_mechanism(),
75
166
+ if self._main_loop:
76
167
+ self._main_loop.run()
77
168
+ if self._token == old_token:
81
172
+ print("Got token: %s", (self._token))
84
+ def login_cb(self, session, reply, error, user_data):
175
def login_cb(self, session, reply, error, user_data):
176
- print "login finished"
177
- self._authenticating = False
85
178
+ print("login finished")
86
179
+ self._main_loop.quit()
87
180
+ self._main_loop = None
182
- print >> sys.stderr, "Got authentication error:", error.message
89
183
+ print("Got authentication error:", error.message)
91
+ if reply.has_key("AuthToken"):
92
+ self._token = reply["AuthToken"]
93
+ elif reply.has_key("AccessToken"):
94
+ self._token = reply["AccessToken"]
96
+ print("Didn't find token in session:", reply)
99
# Encapsulates searching a single user's GDocs
102
self._account_service.connect("enabled", self._on_account_enabled)
103
self._enabled = self._account_service.get_enabled()
104
self._authenticating = False
105
- self._client = gdata.docs.client.DocsClient(source='njpatel-UnityLensGDocs-0.1')
106
- self._client.ssl = True
107
- self._client.http_client.debug = False
108
- self._queued_search = None
109
+ authorizer = SignOnAuthorizer(self._account_service)
110
+ authorizer.refresh_authorization(None)
111
+ self._client = GData.DocumentsService(authorizer=authorizer)
113
self._scope = Unity.Scope.new ("/net/launchpad/unity/scope/gdocs")
114
self._scope.search_in_global = True;
116
self._scope.connect ("filters-changed", self._on_filters_changed);
119
- # Initiate the login
123
- if self._authenticating:
126
- self._authenticating = True
127
- # Get the global account settings
128
- auth_data = self._account_service.get_auth_data()
129
- identity = auth_data.get_credentials_id()
130
- session_data = auth_data.get_parameters()
131
- self.auth_session = Signon.AuthSession.new(identity, auth_data.get_method())
132
- self.auth_session.process(session_data,
133
- auth_data.get_mechanism(),
134
- self.login_cb, None)
136
- def login_cb(self, session, reply, error, user_data):
137
- print "login finished"
138
- self._authenticating = False
140
- print >> sys.stderr, "Got authentication error:", error.message
142
185
- old_token = self._client.auth_token
143
186
- if reply.has_key("AuthToken"):
144
187
- self._client.auth_token = gdata.gauth.ClientLoginToken(reply["AuthToken"])
147
190
- #self._client.auth_token = gdata.gauth.OAuth2Token(None, None, None, None,
148
191
- # access_token=reply["AccessToken"])
149
192
- self._client.auth_token = OAuth2Token(reply["AccessToken"])
193
+ if "AuthToken" in reply:
194
+ self._token = reply["AuthToken"]
195
+ elif "AccessToken" in reply:
196
+ self._token = reply["AccessToken"]
151
198
- print >> sys.stderr, "Didn't find token in session:", reply
153
200
- if self._client.auth_token == old_token:
157
204
- if self._queued_search:
158
205
- print "Performing queued search"
159
206
- self._on_search_changed(*self._queued_search)
207
+ print("Didn't find token in session:", reply)
210
+# Encapsulates searching a single user's GDocs
212
+ def __init__ (self, scope, account_service):
213
+ self._scope = scope
214
+ self._account_service = account_service
215
+ self._account_service.connect("enabled", self._on_account_enabled)
216
+ self._enabled = self._account_service.get_enabled()
217
+ self._authenticating = False
218
+ authorizer = SignOnAuthorizer(self._account_service)
219
+ authorizer.refresh_authorization(None)
220
+ self._client = GData.DocumentsService(authorizer=authorizer)
161
222
def get_account_service (self):
162
223
return self._account_service
225
- def get_scope (self):
226
- return self._scope;
228
def _on_account_enabled (self, account, enabled):
229
+ print("account %s, enabled %s" % (account, enabled))
165
230
self._enabled = enabled
167
def _on_search_changed (self, scope, search, search_type, cancellable):
232
- def _on_search_changed (self, scope, search, search_type, cancellable):
168
233
- self._queued_search = (scope, search, search_type, cancellable)
169
234
- if self._authenticating:
170
235
- print "authenticating, queuing search"
173
search_string = search.props.search_string
174
results = search.props.results_model
175
if search_type == Unity.SearchType.GLOBAL:
176
@@ -159,17 +149,12 @@
236
+ def update_results_model (self, search, model, is_global=False):
237
+ if not self._enabled:
240
- search_string = search.props.search_string
241
- results = search.props.results_model
242
- if search_type == Unity.SearchType.GLOBAL:
180
247
- print "Search changed to: '%s'" % search_string
181
+ print("Search changed to: '%s'" % search_string)
185
251
- self._update_results_model (search_string, results, is_global)
186
252
- except gdata.client.Unauthorized:
189
+ self._update_results_model (search_string, results, is_global)
192
257
- self._queued_search = None
193
search.emit("finished")
195
def _on_filters_changed (self, scope, param_spec=None):
258
- search.emit("finished")
260
- def _on_filters_changed (self, scope, param_spec=None):
261
- scope.queue_search_changed(Unity.SearchType.DEFAULT)
263
- def _update_results_model (self, search, model, is_global=False):
264
- # Clear out the current results in the model as we'll get a new list
265
- # NOTE: We could be clever and only remove/add things entries that have
266
- # changed, however the cost of doing that for a small result set probably
267
- # outweighs the gains. Especially if you consider the complexity,
197
270
# Get the list of documents
198
271
feed = self.get_doc_list(search, is_global);
199
272
for entry in feed:
279
352
filter_type = TYPE_MAP.get(rtype, "other")
280
353
return f.get_option(filter_type).props.active
355
ret = "x-office-spreadsheet"
282
356
elif doc_type == "folder":
358
+ elif doc_type == "file":
359
+ ret = "gnome-fs-regular"
285
361
- print "Unhandled icon type: ", doc_type
286
362
+ print("Unhandled icon type: ", doc_type)
291
367
result = result.unpack()[0]
298
374
daemon = Daemon()
376
=== modified file 'setup.py'
377
--- old/setup.py 2012-08-15 06:14:42 +0000
378
+++ new/setup.py 2012-08-23 17:06:33 +0000
381
applications_path = subprocess.check_output(['pkg-config',
382
'--variable=applicationfilesdir',
383
- 'libaccounts-glib']).rstrip('\n')
384
+ 'libaccounts-glib']).rstrip().decode()
385
setup(name="unity-scope-gdocs",
387
author="Alberto Mardegan",