~didrocks/ubuntuone-client/use_result_var

« back to all changes in this revision

Viewing changes to bin/ubuntuone-preferences

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2010-09-15 22:17:37 UTC
  • mto: This revision was merged to the branch mainline in revision 55.
  • Revision ID: james.westby@ubuntu.com-20100915221737-l0sy32v8vh0c9coj
Tags: upstream-1.4.1
ImportĀ upstreamĀ versionĀ 1.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# You should have received a copy of the GNU General Public License along
21
21
# with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 
23
 
from __future__ import division
 
23
from __future__ import division, with_statement
24
24
 
25
25
import pygtk
26
26
pygtk.require('2.0')
31
31
import time
32
32
import gettext
33
33
import subprocess
 
34
from multiprocessing import Pipe, Process
34
35
from threading import Thread
35
36
from oauth import oauth
36
37
 
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)
43
43
 
117
117
    except DBusException, e:
118
118
        error_handler(e)
119
119
 
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.
 
122
 
 
123
    Necessary because of libproxy's orneriness WRT threads: LP:633241.
 
124
    """
 
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)
123
 
 
124
 
    gtk.gdk.threads_enter()
125
 
    callback(result)
126
 
    gtk.gdk.threads_leave()
 
129
    logger.debug("got result for really_do_rest_request (%s:%s)", method, url)
 
130
    conn.send(result)
 
131
    logger.debug("end really_do_rest_request (%s:%s)", method, url)
 
132
 
 
133
def do_rest_request(proc, conn, callback):
 
134
    """Helper that handles the REST request."""
 
135
    pid = os.getpid()
 
136
    logger.debug("do_rest_request (%s)", pid)
 
137
    proc.join()
 
138
 
 
139
    result = conn.recv()
 
140
    logger.debug("got result for do_rest_request (%d)", pid)
 
141
    if callback is not None:
 
142
        with gtk.gdk.lock:
 
143
            callback(result)
 
144
    logger.debug("end do_rest_request (%d)", pid)
127
145
 
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))
 
151
    p.start()
 
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)
132
155
 
133
156
class DevicesWidget(gtk.Table):
134
157
    """
581
604
                'percent' : percent })
582
605
        self.usage_graph.set_fraction(percent / 100)
583
606
 
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"))
587
 
        if is_paid_account:
588
 
            self.upgrade_link.hide()
589
 
        else:
590
 
            self.upgrade_link.show()
591
 
 
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.")
597
 
            if is_paid_account:
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.")
601
 
            else:
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.")
609
 
            if is_paid_account:
610
 
                desc = _("Automatic synchronization will stop when you reach"
611
 
                         " your storage limit.")
612
 
            else:
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.")
616
622
        else:
617
623
            self.overquota_img.clear()
618
624
            label = desc = ""
636
642
        if user:
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"]
 
650
            else:
 
651
                desc = _("Unknown")
 
652
            self.plan_label.set_label(desc)
639
653
 
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)
785
799
                else:
786
800
                    self.music_check.set_active(False)
787
 
 
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())
790
805
 
791
806
    def connect_file_sync_callbacks(self):
905
920
            link.set_alignment(0.0, 0.5)
906
921
            table.attach(link, 0, 2, 5-n, 6-n)
907
922
            link.show()
908
 
        self.upgrade_link = link
909
 
        self.upgrade_link.hide()
910
923
 
911
924
        # Devices tab
912
925
        sw = gtk.ScrolledWindow()