39
38
from ConfigParser import ConfigParser
40
39
from dbus.exceptions import DBusException
41
40
from dbus.mainloop.glib import DBusGMainLoop
42
from ubuntuone.oauthdesktop.main import Login
43
41
from xdg.BaseDirectory import xdg_config_home
44
42
from threading import Lock, Thread
45
43
from urllib import quote
91
89
def __init__(self, *args, **kw):
92
90
"""Initializes the child threads and dbus monitor."""
93
from twisted.internet import gtk2reactor
95
login = Login(dbus.service.BusName(DBUS_IFACE_AUTH_NAME,
96
bus=dbus.SessionBus()))
98
91
logger.info(_("Starting Ubuntu One client version %s") %
99
92
clientdefs.VERSION)
145
138
handler_function=self.__no_credentials,
146
139
signal_name="NoCredentials",
147
140
dbus_interface=DBUS_IFACE_AUTH_NAME)
148
self.__bus.add_signal_receiver(
149
handler_function=self.__got_oauth_error,
150
signal_name="OAuthError",
151
dbus_interface=DBUS_IFACE_AUTH_NAME)
153
142
self.__icon = AppletIcon(main=self, config=self.config)
194
181
except DBusException, e:
197
from twisted.internet import reactor
200
186
def __no_credentials(self):
201
187
"""Signal callback for when no credentials exist in the keyring."""
202
188
self.is_authorized = False
204
def __got_oauth_error(self, message=None):
205
"""Signal callback for when an OAuth error occured."""
206
def dialog_response(dialog, response):
207
"""Handle the dialog closing."""
211
logger.error(message)
212
dialog = gtk.Dialog(title=_("Ubuntu One: Error"),
213
flags=gtk.DIALOG_NO_SEPARATOR,
214
buttons=(gtk.STOCK_CLOSE,
216
dialog.set_default_response(gtk.RESPONSE_CLOSE)
217
dialog.set_icon_name("ubuntuone-client")
219
area = dialog.get_content_area()
221
hbox = gtk.HBox(spacing=12)
222
hbox.set_border_width(12)
223
area.pack_start(hbox)
227
image.set_from_icon_name("dialog-error", gtk.ICON_SIZE_DIALOG)
228
image.set_alignment(0.5, 0.0)
230
hbox.pack_start(image, False, False)
232
vbox = gtk.VBox(spacing=12)
234
hbox.pack_start(vbox)
236
label = gtk.Label("<b>%s</b>" % _("Authorization Error"))
237
label.set_use_markup(True)
238
label.set_alignment(0.0, 0.5)
240
vbox.pack_start(label, False, False)
242
label = gtk.Label(message)
243
label.set_line_wrap(True)
244
label.set_max_width_chars(64)
245
label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
246
label.set_alignment(0.0, 0.0)
248
vbox.pack_start(label, True, True)
250
dialog.connect('close', dialog_response, gtk.RESPONSE_CLOSE)
251
dialog.connect('response', dialog_response)
255
logger.error(_("Got an OAuth error with no message."))
257
190
def check_for_token(self, do_login=False):
258
191
"""Method to check for an existing token."""
259
192
def local_dbus_error(e):
325
def set_up_desktopcouch_pairing(self, consumer_key):
326
"""Add a pairing record between desktopcouch and Ubuntu One"""
328
from desktopcouch.pair.couchdb_pairing.couchdb_io import \
329
put_static_paired_service, PAIRED_SERVER_RECORD_TYPE
330
from desktopcouch.records.server import CouchDatabase
332
# desktopcouch is not installed
333
logger.debug(_("Not adding desktopcouch pairing since"
334
" desktopcouch is not installed"))
336
# Check whether there is already a record of the Ubuntu One service
337
db = CouchDatabase("management", create=True)
338
if not db.view_exists("ubuntu_one_pair_record","ubuntu_one_pair_record"):
339
map_js = """function(doc) {
340
if (doc.service_name == "ubuntuone") {
341
if (doc.application_annotations &&
342
doc.application_annotations["Ubuntu One"] &&
343
doc.application_annotations["Ubuntu One"]["private_application_annotations"] &&
344
doc.application_annotations["Ubuntu One"]["private_application_annotations"]["deleted"]) {
351
db.add_view("ubuntu_one_pair_record", map_js, None,
352
"ubuntu_one_pair_record")
353
results = db.execute_view("ubuntu_one_pair_record",
354
"ubuntu_one_pair_record")
357
# Results should contain either one row or no rows
358
# If there is one row, its value will be 0, meaning that there is
359
# already an Ubuntu One pairing record, or 1, meaning that there
360
# was an Ubuntu One pairing record but it has since been unpaired
361
# Only create a new record if there is not one already. Specifically,
362
# do not add the record if there is a deleted one, as this means
363
# that the user explicitly unpaired it!
368
logger.debug(_("Not adding desktopcouch pairing since"
369
" the user has explicitly unpaired with Ubuntu One"))
371
logger.debug(_("Not adding desktopcouch pairing since"
372
" we are already paired"))
374
put_static_paired_service(None, "ubuntuone")
375
logger.debug(_("Pairing desktopcouch with Ubuntu One"))
378
259
"""Starts the gtk main loop."""
379
from twisted.internet import reactor
380
260
if self.connect != 2 or (self.connect == 1 and self.connected):
381
261
gobject.idle_add(self.check_for_token, True)
386
266
def authorized(self):