Example #1
0
 def __init__(self, params):
     self._content_type = params.get('content_type', 'executable')
     #check if the accounts directory is present, create otherwise
     # keep dataPath "utf-8" encoded
     dataPath = xbmc.translatePath(
         ADDON.getAddonInfo('profile')).decode("utf-8")
     self._accounts_dir = dataPath + u'/accounts/'
     if not xbmcvfs.exists(self._accounts_dir.encode("utf-8")):
         xbmcvfs.mkdirs(self._accounts_dir.encode("utf-8"))
     #Check if we need to get previous account settings from old addon settings
     if ADDON.getSetting('access_token').decode("utf-8") != u'':
         #Old access_token present so convert old settings!
         log('Converting old account settings and saving it')
         account_name = u'Account1'
         access_token = ADDON.getSetting('access_token').decode("utf-8")
         client = XBMCDropBoxClient(access_token=access_token)
         account_info = client.getAccountInfo()
         if 'display_name' in account_info:
             account_name = path_from(account_info['display_name'])
         new_account = AccountSettings(account_name)
         new_account.access_token = ADDON.getSetting('access_token').decode(
             "utf-8")
         new_account.passcode = ADDON.getSetting('passcode')
         passcodetimeout = ADDON.getSetting('passcodetimeout')
         if passcodetimeout != '':
             new_account.passcodetimeout = int(passcodetimeout)
         #new_account.session_id = tmp_dict.session_id
         new_account.synchronisation = (
             'true' == ADDON.getSetting('synchronisation').lower())
         syncfreq = ADDON.getSetting('syncfreq')
         if syncfreq != '':
             new_account.syncfreq = int(syncfreq)
         new_account.syncpath = ADDON.getSetting('syncpath').decode("utf-8")
         new_account.remotepath = ADDON.getSetting('remotepath').decode(
             "utf-8")
         new_account.save()
         #Now clear all old settings
         ADDON.setSetting('access_token', '')
         ADDON.setSetting('passcode', '')
         ADDON.setSetting('passcodetimeout', '')
         ADDON.setSetting('synchronisation', 'false')
         ADDON.setSetting('syncpath', '')
         ADDON.setSetting('remotepath', '')
         #cleanup old cache and shadow dirs
         #keep cache_path "utf-8" encoded
         cache_path = ADDON.getSetting('cachepath')
         #Use user defined location?
         if cache_path == '' or os.path.normpath(cache_path) == '':
             #get the default path
             cache_path = xbmc.translatePath(ADDON.getAddonInfo('profile'))
         shadowPath = os.path.normpath(cache_path + '/shadow/')
         thumbPath = os.path.normpath(cache_path + '/thumb/')
         if xbmcvfs.exists(shadowPath.encode("utf-8")):
             shutil.rmtree(shadowPath)
         if xbmcvfs.exists(thumbPath.encode("utf-8")):
             shutil.rmtree(thumbPath)
         #Notify the DropboxSynchronizer of the new account
         NotifySyncClient().account_added_removed()
 def __init__( self, params ):
     self._content_type = params.get('content_type', 'executable')
     #check if the accounts directory is present, create otherwise
     # keep dataPath "utf-8" encoded
     dataPath = xbmc.translatePath( ADDON.getAddonInfo('profile') ).decode("utf-8")
     self._accounts_dir = dataPath + u'/accounts/'
     if not xbmcvfs.exists( self._accounts_dir.encode("utf-8") ):
         xbmcvfs.mkdirs( self._accounts_dir.encode("utf-8") )
     #Check if we need to get previous account settings from old addon settings
     if ADDON.getSetting('access_token').decode("utf-8") != u'':
         #Old access_token present so convert old settings!
         log('Converting old account settings and saving it')
         account_name = u'Account1'
         access_token = ADDON.getSetting('access_token').decode("utf-8")
         client = XBMCDropBoxClient(access_token=access_token)
         account_info = client.getAccountInfo()
         if 'display_name' in account_info:
             account_name = path_from(account_info['display_name'])
         new_account = AccountSettings(account_name)
         new_account.access_token = ADDON.getSetting('access_token').decode("utf-8")
         new_account.passcode = ADDON.getSetting('passcode')
         passcodetimeout = ADDON.getSetting('passcodetimeout')
         if passcodetimeout != '':
             new_account.passcodetimeout = int( passcodetimeout )
         #new_account.session_id = tmp_dict.session_id
         new_account.synchronisation = ('true' == ADDON.getSetting('synchronisation').lower())
         syncfreq = ADDON.getSetting('syncfreq')
         if syncfreq != '':
             new_account.syncfreq = int( syncfreq )
         new_account.syncpath = ADDON.getSetting('syncpath').decode("utf-8")
         new_account.remotepath = ADDON.getSetting('remotepath').decode("utf-8")
         new_account.save()
         #Now clear all old settings
         ADDON.setSetting('access_token', '')
         ADDON.setSetting('passcode', '')
         ADDON.setSetting('passcodetimeout', '')
         ADDON.setSetting('synchronisation', 'false')
         ADDON.setSetting('syncpath', '')
         ADDON.setSetting('remotepath', '')
         #cleanup old cache and shadow dirs
         #keep cache_path "utf-8" encoded
         cache_path = ADDON.getSetting('cachepath')
         #Use user defined location?
         if cache_path == '' or os.path.normpath(cache_path) == '':
             #get the default path 
             cache_path = xbmc.translatePath( ADDON.getAddonInfo('profile') )
         shadowPath = os.path.normpath(cache_path + '/shadow/')
         thumbPath = os.path.normpath(cache_path + '/thumb/')
         if xbmcvfs.exists(shadowPath.encode("utf-8")):
             shutil.rmtree(shadowPath)
         if xbmcvfs.exists(thumbPath.encode("utf-8")):
             shutil.rmtree(thumbPath)
         #Notify the DropboxSynchronizer of the new account
         NotifySyncClient().account_added_removed()
Example #3
0
def run(params):  # This is the entrypoint
    action = params.get('action', '')
    if action == 'add':
        #add an account
        access_token = login.getAccessToken()
        if access_token:
            #save the new account
            account_name = 'Account1'
            client = XBMCDropBoxClient(access_token=access_token)
            account_info = client.getAccountInfo()
            if 'display_name' in account_info:
                account_name = path_from(account_info['display_name'])
            new_account = AccountSettings(account_name)
            new_account.access_token = access_token
            new_account.save()
            #Notify the DropboxSynchronizer
            NotifySyncClient().account_added_removed()
            #notify the user the account is added
            dialog = xbmcgui.Dialog()
            dialog.ok(ADDON_NAME, LANGUAGE_STRING(30004), account_name)
        #return to where we were and refresh
        xbmc.executebuiltin('container.Refresh()')
    elif action == 'remove':
        #remove the selected account
        account_name = urllib.unquote(params.get('account', ''))
        account_settings = login.get_account(account_name)
        if account_settings:
            dialog = xbmcgui.Dialog()
            #'are you sure' dialog
            if dialog.yesno(ADDON_NAME, LANGUAGE_STRING(30045),
                            account_name) == True:
                try:
                    account_settings.remove()
                except Exception as exc:
                    log_error("Failed to remove the account: %s" % (str(exc)))
                else:
                    #Notify the DropboxSynchronizer
                    NotifySyncClient().account_added_removed()
        else:
            log_error("Failed to remove the account!")
            dialog = xbmcgui.Dialog()
            dialog.ok(ADDON_NAME, LANGUAGE_STRING(30203))
        #return to where we were and refresh
        xbmc.executebuiltin('container.Refresh()')
    elif action == 'change_passcode':
        account_name = urllib.unquote(params.get('account', ''))
        account_settings = login.get_account(account_name)
        if account_settings:
            change_passcode(account_settings)
        #return to where we were
        xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False)
    elif action == 'change_synchronization':
        account_name = urllib.unquote(params.get('account', ''))
        account_settings = login.get_account(account_name)
        if account_settings:
            change_synchronization(account_settings)
        #return to where we were
        xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False)
    else:
        browser = AccountBrowser(params)
        browser.buildList()
        browser.show()
def run(params): # This is the entrypoint
    action = params.get('action', '')
    if action == 'add':
        #add an account
        access_token = login.getAccessToken()
        if access_token:
            #save the new account
            account_name = 'Account1'
            client = XBMCDropBoxClient(access_token=access_token)
            account_info = client.getAccountInfo()
            if 'display_name' in account_info:
                account_name = path_from(account_info['display_name'])
            new_account = AccountSettings(account_name)
            new_account.access_token = access_token
            new_account.save()
            #Notify the DropboxSynchronizer
            NotifySyncClient().account_added_removed()
            #notify the user the account is added
            dialog = xbmcgui.Dialog()
            dialog.ok(ADDON_NAME, LANGUAGE_STRING(30004), account_name)
        #return to where we were and refresh
        xbmc.executebuiltin('container.Refresh()')
    elif action == 'remove':
        #remove the selected account
        account_name = urllib.unquote( params.get('account', '') )
        account_settings = login.get_account(account_name) 
        if account_settings:
            dialog = xbmcgui.Dialog()
            #'are you sure' dialog
            if dialog.yesno(ADDON_NAME, LANGUAGE_STRING(30045), account_name ) == True:
                try:
                    account_settings.remove()
                except Exception as exc:
                    log_error("Failed to remove the account: %s" % (str(exc)) )
                else:
                    #Notify the DropboxSynchronizer
                    NotifySyncClient().account_added_removed()
        else:
            log_error("Failed to remove the account!")
            dialog = xbmcgui.Dialog()
            dialog.ok(ADDON_NAME, LANGUAGE_STRING(30203))
        #return to where we were and refresh
        xbmc.executebuiltin('container.Refresh()')
    elif action == 'change_passcode':
        account_name = urllib.unquote( params.get('account', '') )
        account_settings = login.get_account(account_name)
        if account_settings:
            change_passcode(account_settings)
        #return to where we were
        xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False)
    elif action == 'change_synchronization':
        account_name = urllib.unquote( params.get('account', '') )
        account_settings = login.get_account(account_name)
        if account_settings:
            change_synchronization(account_settings)
        #return to where we were
        xbmcplugin.endOfDirectory(int(sys.argv[1]), succeeded=False)
    else:
        browser = AccountBrowser(params)
        browser.buildList()
        browser.show()