34
from multiprocessing import Pipe, Process
34
35
from threading import Thread
35
36
from oauth import oauth
37
38
from ubuntu_sso import DBUS_BUS_NAME, DBUS_IFACE_CRED_NAME, DBUS_CRED_PATH
38
39
from ubuntuone import clientdefs
39
40
from ubuntuone.syncdaemon.tools import SyncDaemonTool
40
from ubuntuone.api.restclient import RestClient
41
41
from ubuntuone.logger import (basic_formatter, LOGFOLDER,
42
42
CustomRotatingFileHandler)
117
117
except DBusException, e:
120
def do_rest_request(rest_client, url, method, callback):
121
"""Helper that handles the REST request."""
120
def really_do_rest_request(url, method, conn):
121
"""Second-order helper that does the REST request.
123
Necessary because of libproxy's orneriness WRT threads: LP:633241.
125
from ubuntuone.api.restclient import RestClient
126
logger.debug("really_do_rest_request (%s:%s)", method, url)
127
rest_client = RestClient(url)
122
128
result = rest_client.call(url, method, oauth_consumer, oauth_token)
124
gtk.gdk.threads_enter()
126
gtk.gdk.threads_leave()
129
logger.debug("got result for really_do_rest_request (%s:%s)", method, url)
131
logger.debug("end really_do_rest_request (%s:%s)", method, url)
133
def do_rest_request(proc, conn, callback):
134
"""Helper that handles the REST request."""
136
logger.debug("do_rest_request (%s)", pid)
140
logger.debug("got result for do_rest_request (%d)", pid)
141
if callback is not None:
144
logger.debug("end do_rest_request (%d)", pid)
128
146
def make_rest_request(url=None, method='GET', callback=None):
129
147
"""Helper that makes an oauth-wrapped REST request."""
130
rest_client = RestClient(url)
131
Thread(target=do_rest_request, args=(rest_client, url, method, callback)).start()
148
logger.debug("make_rest_request (%s:%s)", method, url)
149
conn1, conn2 = Pipe(False)
150
p = Process(target=really_do_rest_request, args=(url, method, conn2))
152
logger.debug("make_rest_request (%s:%s) started %d", method, url, p.pid)
153
Thread(target=do_rest_request, args=(p, conn1, callback)).start()
154
logger.debug("end make_rest_request (%s:%s)", method, url)
133
156
class DevicesWidget(gtk.Table):
581
604
'percent' : percent })
582
605
self.usage_graph.set_fraction(percent / 100)
584
# assumes all paid accounts will have more than 50GB
585
is_paid_account = total >= 50<<30
586
self.plan_label.set_label(_("Paid") if is_paid_account else _("Free"))
588
self.upgrade_link.hide()
590
self.upgrade_link.show()
592
607
if percent >= 100.:
593
608
self.overquota_img.set_from_icon_name('dialog-warning',
594
609
gtk.ICON_SIZE_DIALOG)
595
610
self.overquota.show_all()
596
611
label = _("You are using all of your Ubuntu One storage.")
598
desc = _("Synchronization is now disabled. Remove files from"
599
" synchronization or upgrade your subscription. Use"
600
" the Support options if an upgrade is not available.")
602
desc = _("Synchronization is now disabled. Remove files from"
603
" synchronization or upgrade your subscription.")
612
desc = _("Synchronization is now disabled. Remove files from"
613
" synchronization or upgrade your subscription.")
604
614
elif percent >= 95.:
605
615
self.overquota_img.set_from_icon_name('dialog-information',
606
616
gtk.ICON_SIZE_DIALOG)
607
617
self.overquota.show_all()
608
618
label = _("You are near your Ubuntu One storage limit.")
610
desc = _("Automatic synchronization will stop when you reach"
611
" your storage limit.")
613
desc = _("Automatic synchronization will stop when you reach"
614
" your storage limit. Please consider upgrading to"
615
" avoid a service interruption.")
619
desc = _("Automatic synchronization will stop when you reach"
620
" your storage limit. Please consider upgrading to"
621
" avoid a service interruption.")
617
623
self.overquota_img.clear()
618
624
label = desc = ""
637
643
self.name_label.set_text(user.get('nickname', _("Unknown")))
638
644
self.mail_label.set_text(user.get('email', _("Unknown")))
645
if "current_plan" in user:
646
desc = user["current_plan"]
647
elif "subscription" in user \
648
and "description" in user["subscription"]:
649
desc = user["subscription"]["description"]
652
self.plan_label.set_label(desc)
640
654
def request_account_info(self):
641
655
"""Request account info from server, and update display."""
784
798
self.music_check.set_active(True)
786
800
self.music_check.set_active(False)
788
self.sdtool.get_folder_info(U1MSPATH).addCallbacks(got_info, got_ms_err)
801
if os.path.exists(U1MSPATH):
802
self.sdtool.get_folder_info(
803
U1MSPATH).addCallbacks(got_info, got_ms_err)
789
804
self.files_check.set_active(self.sdtool.is_files_sync_enabled())
791
806
def connect_file_sync_callbacks(self):