Пример #1
0
    def on_cloud_button_clicked(self, button):
        def on_transfer_files(info, error=None):
            if error or not info:
                self.app.toast(_('Failed to copy selected files!'))
                logger.error('SharePage.on_cloud_button_clicked: %s %s' %
                             (info, error))
            elif info['errno'] != 0:
                self.app.toast(_('Failed to copy selected files! {0}').format(
                                ErrorMsg.o.get(info['errno'])))
                logger.error('SharePage.on_cloud_button_clicked: %s %s' %
                             (info, error))
            else:
                self.app.blink_page(self.app.home_page)

        filelist = [row[PATH_COL] for row in self.liststore if
                    row[CHECK_COL] and row[NAME_COL] != '..']
        if not filelist:
            return
        folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
        response = folder_browser.run()
        dest = folder_browser.get_path()
        folder_browser.destroy()
        if response != Gtk.ResponseType.OK:
            return
        gutil.async_call(pcs.share_transfer, self.app.cookie, self.app.tokens,
                         self.shareid, self.uk, filelist, dest,
                         self.app.profile['upload-mode'],
                         callback=on_transfer_files)
Пример #2
0
    def on_copyto_activated(self, menu_item):
        tree_paths = self.iconview.get_selected_items()
        if len(tree_paths) == 0:
            return

        dialog = FolderBrowserDialog(self.parent, self.app, _('Copy To...'))
        response = dialog.run()
        targ_path = ''
        if response == Gtk.ResponseType.OK:
            targ_path = dialog.get_path()
        dialog.destroy()
        if not targ_path:
            return

        filelist = []
        for tree_path in tree_paths:
            filelist.append({
                'path': self.liststore[tree_path][PATH_COL],
                'dest': targ_path,
                'newname': self.liststore[tree_path][DISNAME_COL],
                })
        gutil.async_call(
                pcs.copy,
                self.app.cookie, self.app.tokens, filelist,
                callback=self.parent.reload)
Пример #3
0
    def add_cloud_bt_task(self, source_url, save_path=None):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        save_path  - 要保存到的路径, 如果为None, 就会弹出目录选择的对话框
        '''
        def check_vcode(info, error=None):
            if error or not info:
                logger.error('CloudPage.check_vcode: %s, %s' % (info, error))
                return
            if info.get('error_code', -1) != 0:
                logger.error('CloudPage.check_vcode: %s, %s' % (info, error))

            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(pcs.cloud_add_bt_task, self.app.cookie,
                                 self.app.tokens, source_url, save_path,
                                 selected_idx, file_sha1, info['vcode'],
                                 vcode_input, callback=check_vcode)
            else:
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()

        if not save_path:
            folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
            response = folder_browser.run()
            save_path = folder_browser.get_path()
            folder_browser.destroy()
            if response != Gtk.ResponseType.OK:
                return
        if not save_path:
            return

        bt_browser = BTBrowserDialog(self, self.app, _('Choose..'),
                                     source_url, save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(pcs.cloud_add_bt_task, self.app.cookie,
                         self.app.tokens, source_url, save_path, selected_idx,
                         file_sha1, callback=check_vcode)
        self.app.blink_page(self.app.cloud_page)
Пример #4
0
    def add_file_tasks(self, source_paths, dir_name=None):
        '''批量创建上传任务

        source_path - 本地文件的绝对路径
        dir_name    - 文件在服务器上的父目录, 如果为None的话, 会弹出一个
                      对话框让用户来选择一个目录.
        '''
        def scan_folders(folder_path):
            file_list = os.listdir(folder_path)
            source_paths = [os.path.join(folder_path, f) for f in file_list]
            self.add_file_tasks(
                source_paths,
                os.path.join(dir_name,
                             os.path.split(folder_path)[1]))

        self.check_first()
        if not dir_name:
            folder_dialog = FolderBrowserDialog(self, self.app)
            response = folder_dialog.run()
            if response != Gtk.ResponseType.OK:
                folder_dialog.destroy()
                return
            dir_name = folder_dialog.get_path()
            folder_dialog.destroy()
        for source_path in source_paths:
            if (os.path.split(source_path)[1].startswith('.')
                    and not self.app.profile['uploading-hidden-files']):
                continue
            if os.path.isfile(source_path):
                self.add_file_task(source_path, dir_name)
            elif os.path.isdir(source_path):
                scan_folders(source_path)
        self.app.blink_page(self)
        self.scan_tasks()
Пример #5
0
    def on_copyto_activated(self, menu_item):
        tree_paths = self.iconview.get_selected_items()
        if not tree_paths:
            return

        dialog = FolderBrowserDialog(self.parent, self.app, _('Copy To...'))
        response = dialog.run()
        targ_path = ''
        if response != Gtk.ResponseType.OK:
            dialog.destroy()
            return
        targ_path = dialog.get_path()
        dialog.destroy()

        filelist = []
        for tree_path in tree_paths:
            filelist.append({
                'path': self.liststore[tree_path][PATH_COL],
                'dest': targ_path,
                'newname': self.liststore[tree_path][NAME_COL],
                })
        gutil.async_call(
                pcs.copy,
                self.app.cookie, self.app.tokens, filelist,
                callback=self.parent.reload)
Пример #6
0
    def add_cloud_bt_task(self, source_url):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        '''
        def check_vcode(info, error=None):
            if error or not info:
                print('Error in check_vcode:', info)
                return
            if 'error_code' not in info or info['error_code'] == 0:
                self.reload()
                return
            if info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(
                    pcs.cloud_add_bt_task, self.app.cookie,
                    self.app.tokens, source_url, save_path,
                    selected_idx, file_sha1, info['vcode'], vcode_input,
                    callback=check_vcode)
            else:
                print('Unknown error info:', info)

        self.check_first()
        folder_browser = FolderBrowserDialog(
                self, self.app, _('Save to..'))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()

        bt_browser = BTBrowserDialog(
                self, self.app, _('Choose..'), source_url, save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(
            pcs.cloud_add_bt_task, self.app.cookie, self.app.tokens,
            source_url, save_path, selected_idx, file_sha1,
            callback=check_vcode)
Пример #7
0
 def on_destdir_clicked(self, button):
     folder_dialog = FolderBrowserDialog(self, self.app)
     response = folder_dialog.run()
     if response != Gtk.ResponseType.OK:
         folder_dialog.destroy()
         return
     dir_name = folder_dialog.get_path()
     folder_dialog.destroy()
     button.set_label(dir_name)
     self.app.profile['dest-sync-dir'] = dir_name
Пример #8
0
    def add_cloud_bt_task(self, source_url):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        '''
        def check_vcode(info, error=None):
            if error or not info:
                return
            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(pcs.cloud_add_bt_task,
                                 self.app.cookie,
                                 self.app.tokens,
                                 source_url,
                                 save_path,
                                 selected_idx,
                                 file_sha1,
                                 info['vcode'],
                                 vcode_input,
                                 callback=check_vcode)
            else:
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()
        folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            folder_browser.destroy()
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()

        bt_browser = BTBrowserDialog(self, self.app, _('Choose..'), source_url,
                                     save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(pcs.cloud_add_bt_task,
                         self.app.cookie,
                         self.app.tokens,
                         source_url,
                         save_path,
                         selected_idx,
                         file_sha1,
                         callback=check_vcode)
        self.app.blink_page(self.app.cloud_page)
Пример #9
0
    def add_file_tasks(self, source_paths, dir_name=None):
        '''批量创建上传任务

        source_path - 本地文件的绝对路径
        dir_name    - 文件在服务器上的父目录, 如果为None的话, 会弹出一个
                      对话框让用户来选择一个目录.
        '''
        def scan_folders(folder_path):
            file_list = os.listdir(folder_path)
            source_paths = [os.path.join(folder_path, f) for f in file_list]
            self.add_file_tasks(
                    source_paths,
                    os.path.join(dir_name, os.path.split(folder_path)[1]))

        self.check_first()
        if not dir_name:
            folder_dialog = FolderBrowserDialog(self, self.app)
            response = folder_dialog.run()
            if response != Gtk.ResponseType.OK:
                folder_dialog.destroy()
                return
            dir_name = folder_dialog.get_path()
            folder_dialog.destroy()
        for source_path in source_paths:
            if (os.path.split(source_path)[1].startswith('.') and
                    not self.app.profile['uploading-hidden-files']):
                continue
            if os.path.isfile(source_path):
                self.add_file_task(source_path, dir_name)
            elif os.path.isdir(source_path):
                scan_folders(source_path)
        self.app.blink_page(self)
        self.scan_tasks()
Пример #10
0
    def add_link_task(self):
        self.check_first()
        dialog = Gtk.Dialog(
                _('Add new link task'), self.app.window,
                Gtk.DialogFlags.MODAL,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_border_width(10)
        dialog.set_default_size(480, 180)
        box = dialog.get_content_area()
        entry = Gtk.Entry()
        entry.set_placeholder_text(_('Link ..'))
        box.pack_start(entry, False, False, 0)

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.INFO)
        box.pack_start(infobar, False, False, 5)
        info_content = infobar.get_content_area()
        info_label = Gtk.Label(
                _('Support http/https/ftp/eMule/Magnet format'))
        info_content.pack_start(info_label, False, False, 0)

        box.show_all()
        response = dialog.run()
        source_url = entry.get_text()
        dialog.destroy()
        if response != Gtk.ResponseType.OK or not len(source_url):
            return

        if source_url.startswith('magent'):
            self.add_cloud_bt_task(source_url)
            return

        folder_browser = FolderBrowserDialog(
                self, self.app, _('Save to..'))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()
        gutil.async_call(
            pcs.cloud_add_link_task, self.app.cookie, self.app.tokens,
            source_url, save_path, callback=self.reload)
Пример #11
0
    def add_cloud_bt_task(self, source_url):
        """从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        """

        def check_vcode(info, error=None):
            if error or not info:
                return
            if "task_id" in info or info["error_code"] == 0:
                self.reload()
            elif info["error_code"] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(
                    pcs.cloud_add_bt_task,
                    self.app.cookie,
                    self.app.tokens,
                    source_url,
                    save_path,
                    selected_idx,
                    file_sha1,
                    info["vcode"],
                    vcode_input,
                    callback=check_vcode,
                )
            else:
                self.app.toast(_("Error: {0}").format(info["error_msg"]))

        self.check_first()
        folder_browser = FolderBrowserDialog(self, self.app, _("Save to.."))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            folder_browser.destroy()
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()

        bt_browser = BTBrowserDialog(self, self.app, _("Choose.."), source_url, save_path)
        response = bt_browser.run()
        selected_idx, file_sha1 = bt_browser.get_selected()
        bt_browser.destroy()
        if response != Gtk.ResponseType.OK or not selected_idx:
            return
        gutil.async_call(
            pcs.cloud_add_bt_task,
            self.app.cookie,
            self.app.tokens,
            source_url,
            save_path,
            selected_idx,
            file_sha1,
            callback=check_vcode,
        )
Пример #12
0
 def on_destdir_clicked(self, button):
     folder_dialog = FolderBrowserDialog(self, self.app)
     response = folder_dialog.run()
     if response != Gtk.ResponseType.OK:
         folder_dialog.destroy()
         return
     dir_name = folder_dialog.get_path()
     folder_dialog.destroy()
     button.set_label(dir_name)
     self.app.profile['dest-sync-dir'] = dir_name
Пример #13
0
    def on_cloud_button_clicked(self, button):
        def on_transfer_files(info, error=None):
            if error or not info:
                self.app.toast(_('Failed to copy selected files!'))
                logger.error('SharePage.on_cloud_button_clicked: %s %s' %
                             (info, error))
            elif info['errno'] != 0:
                self.app.toast(_('Failed to copy selected files! {0}').format(
                                ErrorMsg.o.get(info['errno'])))
                logger.error('SharePage.on_cloud_button_clicked: %s %s' %
                             (info, error))
            else:
                self.app.blink_page(self.app.home_page)

        filelist = [row[PATH_COL] for row in self.liststore if
                    row[CHECK_COL] and row[NAME_COL] != '..']
        if not filelist:
            return
        folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
        response = folder_browser.run()
        dest = folder_browser.get_path()
        folder_browser.destroy()
        if response != Gtk.ResponseType.OK:
            return
        gutil.async_call(pcs.share_transfer, self.app.cookie, self.app.tokens,
                         self.shareid, self.uk, filelist, dest,
                         self.app.profile['upload-mode'],
                         callback=on_transfer_files)
Пример #14
0
 def do_extract(path):
     '''选择压缩包中需要解压的文件,解压到指定位置'''
     unzip_dialog = UnzipBrowserDialog(self.app, path)
     response = unzip_dialog.run()
     selected_paths = unzip_dialog.get_selected_paths()
     unzip_dialog.destroy()
     if response != Gtk.ResponseType.OK or not selected_paths:
         return
     folder_browser = FolderBrowserDialog(self, self.app, _('Extract to..'))
     response = folder_browser.run()
     save_path = folder_browser.get_path()
     folder_browser.destroy()
     if response != Gtk.ResponseType.OK or not save_path:
         return
     for subpath in selected_paths:
         gutil.async_call(pcs.unzip_extract, self.app.cookie,
                          path, save_path, subpath, True, callback=on_do_extract)
Пример #15
0
    def on_copyto_activated(self, menu_item):
        tree_paths = self.iconview.get_selected_items()
        if not tree_paths:
            return

        dialog = FolderBrowserDialog(self.parent, self.app, _("Copy To..."))
        response = dialog.run()
        target_path = ""
        if response != Gtk.ResponseType.OK:
            dialog.destroy()
            return
        target_path = dialog.get_path()
        dialog.destroy()

        filelist = []
        for tree_path in tree_paths:
            filelist.append(
                {
                    "path": self.liststore[tree_path][PATH_COL],
                    "dest": target_path,
                    "newname": self.liststore[tree_path][NAME_COL],
                }
            )
        gutil.async_call(pcs.copy, self.app.cookie, self.app.tokens, filelist, callback=self.parent.reload)
Пример #16
0
    def add_link_task(self):
        '''新建普通的链接任务'''
        def do_add_link_task(source_url):
            def on_link_task_added(info, error=None):
                if error or not info:
                    logger.error('CloudPage.do_add_link_task: %s, %s' %
                                 (info, error))
                    self.app.toast(_('Failed to parse download link'))
                    return
                if info.get('error_code', -1) != 0:
                    logger.error('CloudPage.do_add_link_task: %s, %s' %
                                 (info, error))

                if 'task_id' in info or info['error_code'] == 0:
                    self.reload()
                elif info['error_code'] == -19:
                    vcode = info['vcode']
                    vcode_dialog = VCodeDialog(self, self.app, info)
                    response = vcode_dialog.run()
                    vcode_input = vcode_dialog.get_vcode()
                    vcode_dialog.destroy()
                    if response != Gtk.ResponseType.OK:
                        return
                    gutil.async_call(pcs.cloud_add_link_task, self.app.cookie,
                                     self.app.tokens, source_url, save_path,
                                     vcode, vcode_input,
                                     callback=on_link_task_added)
                else:
                    self.app.toast(_('Error: {0}').format(info['error_msg']))
            gutil.async_call(pcs.cloud_add_link_task, self.app.cookie,
                             self.app.tokens, source_url, save_path,
                             callback=on_link_task_added)

        self.check_first()
        dialog = Gtk.Dialog(_('Add new link tasks'), self.app.window,
                            Gtk.DialogFlags.MODAL,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                            Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_border_width(10)
        dialog.set_default_size(480, 300)
        dialog.set_default_response(Gtk.ResponseType.OK)
        box = dialog.get_content_area()
        scrolled_win = Gtk.ScrolledWindow()
        box.pack_start(scrolled_win, True, True, 0)
        links_buf = Gtk.TextBuffer()
        links_tv = Gtk.TextView.new_with_buffer(links_buf)
        links_tv.set_tooltip_text(_('Paste links here, line by line'))
        scrolled_win.add(links_tv)

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.INFO)
        box.pack_start(infobar, False, False, 5)
        info_content = infobar.get_content_area()
        info_label = Gtk.Label.new(
            _('Support http/https/ftp/thunder/qqdl/flashget/eMule/Magnet format'))
        info_content.pack_start(info_label, False, False, 0)

        box.show_all()
        response = dialog.run()
        contents = gutil.text_buffer_get_all_text(links_buf)
        dialog.destroy()
        if response != Gtk.ResponseType.OK or not contents:
            return
        link_tasks = []
        bt_tasks = []
        for source_url in contents.split('\n'):
            source_url = source_url.strip()
            if not source_url:
                continue
            if source_url.startswith('magnet'):
                bt_tasks.append(source_url)
            else:
                priv_url = decoder.decode(source_url)
                if priv_url:
                    link_tasks.append(priv_url)
                else:
                    link_tasks.append(source_url)

        folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
        response = folder_browser.run()
        save_path = folder_browser.get_path()
        folder_browser.destroy()
        if response != Gtk.ResponseType.OK or not save_path:
            return
        for source_url in link_tasks:
            do_add_link_task(source_url)
        for source_url in bt_tasks:
            self.add_cloud_bt_task(source_url, save_path)
Пример #17
0
    def add_link_task(self):
        '''新建普通的链接任务'''
        def on_link_task_added(info, error=None):
            if error or not info:
                return
            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode = info['vcode']
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(
                    pcs.cloud_add_link_task, self.app.cookie,
                    self.app.tokens, source_url, save_path, vcode,
                    vcode_input, callback=on_link_task_added)
            else:
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()
        dialog = Gtk.Dialog(
                _('Add new link task'), self.app.window,
                Gtk.DialogFlags.MODAL,
                (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_border_width(10)
        dialog.set_default_size(480, 180)
        dialog.set_default_response(Gtk.ResponseType.OK)
        box = dialog.get_content_area()
        entry = Gtk.Entry()
        entry.set_placeholder_text(_('Link ..'))
        box.pack_start(entry, False, False, 0)

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.INFO)
        box.pack_start(infobar, False, False, 5)
        info_content = infobar.get_content_area()
        info_label = Gtk.Label.new(
            _('Support http/https/ftp/thunder/qqdl/flashget/eMule/Magnet format'))
        info_content.pack_start(info_label, False, False, 0)

        box.show_all()
        response = dialog.run()
        source_url = entry.get_text()
        dialog.destroy()
        if response != Gtk.ResponseType.OK or not len(source_url):
            return

        if source_url.startswith('magnet'):
            self.add_cloud_bt_task(source_url)
            return

        priv_url = decoder.decode(source_url)
        if priv_url:
            source_url = priv_url 
        folder_browser = FolderBrowserDialog(
                self, self.app, _('Save to..'))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            folder_browser.destroy()
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()
        gutil.async_call(
            pcs.cloud_add_link_task, self.app.cookie, self.app.tokens,
            source_url, save_path, callback=on_link_task_added)
Пример #18
0
    def add_file_tasks(self, source_paths, dir_name=None):
        '''批量创建上传任务

        source_path - 本地文件的绝对路径
        dir_name    - 文件在服务器上的父目录, 如果为None的话, 会弹出一个
                      对话框让用户来选择一个目录.
        '''
        def scan_folders(folder_path):
            file_list = os.listdir(folder_path)
            source_paths = [os.path.join(folder_path, f) for f in file_list]
            self.add_file_tasks(source_paths,
                    os.path.join(dir_name, os.path.split(folder_path)[1]))

        self.check_first()
        if not dir_name:
            folder_dialog = FolderBrowserDialog(self, self.app)
            response = folder_dialog.run()
            if response != Gtk.ResponseType.OK:
                folder_dialog.destroy()
                return
            dir_name = folder_dialog.get_path()
            folder_dialog.destroy()
        invalid_paths = []
        for source_path in source_paths:
            if util.validate_pathname(source_path) != ValidatePathState.OK:
                invalid_paths.append(source_path)
                continue
            if (os.path.split(source_path)[1].startswith('.') and
                    not self.app.profile['uploading-hidden-files']):
                continue
            if os.path.isfile(source_path):
                self.add_file_task(source_path, dir_name)
            elif os.path.isdir(source_path):
                scan_folders(source_path)

        self.app.blink_page(self)
        self.scan_tasks()

        if not invalid_paths:
            return
        dialog = Gtk.Dialog(_('Invalid Filepath'), self.app.window,
                            Gtk.DialogFlags.MODAL,
                            (Gtk.STOCK_CLOSE, Gtk.ResponseType.OK))
        dialog.set_default_size(640, 480)
        dialog.set_border_width(10)
        box = dialog.get_content_area()

        scrolled_window = Gtk.ScrolledWindow()
        box.pack_start(scrolled_window, True, True, 0)
        text_buffer = Gtk.TextBuffer()
        textview = Gtk.TextView.new_with_buffer(text_buffer)
        scrolled_window.add(textview)
        for invalid_path in invalid_paths:
            text_buffer.insert_at_cursor(invalid_path)
            text_buffer.insert_at_cursor('\n')

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.ERROR)
        box.pack_end(infobar, False, False, 0)
        info_label= Gtk.Label()
        infobar.get_content_area().pack_start(info_label, False, False, 0)
        info_label.set_label(''.join([
            '* ', ValidatePathStateText[1], '\n',
            '* ', ValidatePathStateText[2], '\n',
            '* ', ValidatePathStateText[3], '\n',
        ]))

        box.show_all()
        dialog.run()
        dialog.destroy()
Пример #19
0
    def add_link_task(self):
        '''新建普通的链接任务'''
        def do_add_link_task(source_url):
            def on_link_task_added(info, error=None):
                if error or not info:
                    logger.error('CloudPage.do_add_link_task: %s, %s' %
                                 (info, error))
                    self.app.toast(_('Failed to parse download link'))
                    return
                if info.get('error_code', -1) != 0:
                    logger.error('CloudPage.do_add_link_task: %s, %s' %
                                 (info, error))

                if 'task_id' in info or info['error_code'] == 0:
                    self.reload()
                elif info['error_code'] == -19:
                    vcode = info['vcode']
                    vcode_dialog = VCodeDialog(self, self.app, info)
                    response = vcode_dialog.run()
                    vcode_input = vcode_dialog.get_vcode()
                    vcode_dialog.destroy()
                    if response != Gtk.ResponseType.OK:
                        return
                    gutil.async_call(pcs.cloud_add_link_task,
                                     self.app.cookie,
                                     self.app.tokens,
                                     source_url,
                                     save_path,
                                     vcode,
                                     vcode_input,
                                     callback=on_link_task_added)
                else:
                    self.app.toast(_('Error: {0}').format(info['error_msg']))

            gutil.async_call(pcs.cloud_add_link_task,
                             self.app.cookie,
                             self.app.tokens,
                             source_url,
                             save_path,
                             callback=on_link_task_added)

        self.check_first()
        dialog = Gtk.Dialog(_('Add new link tasks'), self.app.window,
                            Gtk.DialogFlags.MODAL,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_OK, Gtk.ResponseType.OK))
        dialog.set_border_width(10)
        dialog.set_default_size(480, 300)
        dialog.set_default_response(Gtk.ResponseType.OK)
        box = dialog.get_content_area()
        scrolled_win = Gtk.ScrolledWindow()
        box.pack_start(scrolled_win, True, True, 0)
        links_buf = Gtk.TextBuffer()
        links_tv = Gtk.TextView.new_with_buffer(links_buf)
        links_tv.set_tooltip_text(_('Paste links here, line by line'))
        scrolled_win.add(links_tv)

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.INFO)
        box.pack_start(infobar, False, False, 5)
        info_content = infobar.get_content_area()
        info_label = Gtk.Label.new(
            _('Support http/https/ftp/thunder/qqdl/flashget/eMule/Magnet format'
              ))
        info_content.pack_start(info_label, False, False, 0)

        box.show_all()
        response = dialog.run()
        contents = gutil.text_buffer_get_all_text(links_buf)
        dialog.destroy()
        if response != Gtk.ResponseType.OK or not contents:
            return
        link_tasks = []
        bt_tasks = []
        for source_url in contents.split('\n'):
            source_url = source_url.strip()
            if not source_url:
                continue
            if source_url.startswith('magnet'):
                bt_tasks.append(source_url)
            else:
                priv_url = decoder.decode(source_url)
                if priv_url:
                    link_tasks.append(priv_url)
                else:
                    link_tasks.append(source_url)

        folder_browser = FolderBrowserDialog(self, self.app, _('Save to..'))
        response = folder_browser.run()
        save_path = folder_browser.get_path()
        folder_browser.destroy()
        if response != Gtk.ResponseType.OK or not save_path:
            return
        for source_url in link_tasks:
            do_add_link_task(source_url)
        for source_url in bt_tasks:
            self.add_cloud_bt_task(source_url, save_path)
Пример #20
0
    def add_cloud_bt_task(self, source_url, save_path=None):
        '''从服务器上获取种子, 并建立离线下载任务

        source_url - BT 种子在服务器上的绝对路径, 或者是磁链的地址.
        save_path  - 要保存到的路径, 如果为None, 就会弹出目录选择的对话框
        '''
        def check_vcode(info, error=None):
            if error or not info:
                logger.error('CloudPage.check_vcode: %s, %s' % (info, error))
                return
            if info.get('error_code', -1) != 0:
                logger.error('CloudPage.check_vcode: %s, %s' % (info, error))

            if 'task_id' in info or info['error_code'] == 0:
                self.reload()
            elif info['error_code'] == -19:
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(pcs.cloud_add_bt_task,
                                 self.app.cookie,
                                 self.app.tokens,
                                 source_url,
                                 save_path,
                                 selected_idx,
                                 file_sha1,
                                 info['vcode'],
                                 vcode_input,
                                 callback=check_vcode)
            else:
                self.app.toast(_('Error: {0}').format(info['error_msg']))

        self.check_first()
        ###################################
        if not save_path:
            folder_browser = FolderBrowserDialog(self, self.app,
                                                 _('Save to..'))
            response = folder_browser.run()
            save_path = folder_browser.get_path()
            folder_browser.destroy()
            if response != Gtk.ResponseType.OK:
                return
        if not save_path:
            return

#        bt_browser = BTBrowserDialog(self, self.app, _('Choose..'),
#                                     source_url, save_path)
        print('before run')
        #        response = bt_browser.run()
        self.taskList.clear()
        print('after run0')

        def on_tasks_received():
            print(
                '/usr/local/lib/python3.4/dist-packages/bcloud/BTBrowserDialog.py:on_tasks_received 75'
            )
            if error or not info:
                logger.error('BTBrowserDialog.on_tasks_received: %s, %s.' %
                             (info, error))
                lock.release()
                return
            if 'magnet_info' in info:
                tasks = info['magnet_info']
            elif 'torrent_info' in info:
                tasks = info['torrent_info']['file_info']
                self.file_sha1 = info['torrent_info']['sha1']
            elif 'error_code' in info:
                logger.error('BTBrowserDialog.on_tasks_received: %s, %s.' %
                             (info, error))
                self.app.toast(info.get('error_msg', ''))
                lock.release()
                return
            else:
                logger.error('BTBrowserDialog.on_tasks_received: %s, %s.' %
                             (info, error))
                self.app.toast(_('Unknown error occured: %s') % info)
                lock.release()
                return
            count = 0
            for task in tasks:
                count = count + 1
                taskList.append(count)
            self.lock.release()

        print('after run2')
        self.lock.acquire()
        self.lock.release()
        gutil.async_call(pcs.cloud_query_magnetinfo,
                         self.app.cookie,
                         self.app.tokens,
                         source_url,
                         save_path,
                         callback=on_tasks_received)
        print('after async_call')
        self.lock.acquire()
        print('get select start')
        #        selected_idx, file_sha1 = bt_browser.get_selected()
        file_sha1 = ''
        print(file_sha1)
        print('get select end')
        #        bt_browser.destroy()
        if len(taskList) == 0:
            return
        gutil.async_call(pcs.cloud_add_bt_task,
                         self.app.cookie,
                         self.app.tokens,
                         source_url,
                         save_path,
                         taskList,
                         file_sha1,
                         callback=check_vcode)
        self.app.blink_page(self.app.cloud_page)
        self.lock.acquire()
Пример #21
0
    def add_link_task(self):
        """新建普通的链接任务"""

        def on_link_task_added(info, error=None):
            if error or not info:
                return
            if "task_id" in info or info["error_code"] == 0:
                self.reload()
            elif info["error_code"] == -19:
                vcode = info["vcode"]
                vcode_dialog = VCodeDialog(self, self.app, info)
                response = vcode_dialog.run()
                vcode_input = vcode_dialog.get_vcode()
                vcode_dialog.destroy()
                if response != Gtk.ResponseType.OK:
                    return
                gutil.async_call(
                    pcs.cloud_add_link_task,
                    self.app.cookie,
                    self.app.tokens,
                    source_url,
                    save_path,
                    vcode,
                    vcode_input,
                    callback=on_link_task_added,
                )
            else:
                self.app.toast(_("Error: {0}").format(info["error_msg"]))

        self.check_first()
        dialog = Gtk.Dialog(
            _("Add new link task"),
            self.app.window,
            Gtk.DialogFlags.MODAL,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OK, Gtk.ResponseType.OK),
        )
        dialog.set_border_width(10)
        dialog.set_default_size(480, 180)
        dialog.set_default_response(Gtk.ResponseType.OK)
        box = dialog.get_content_area()
        entry = Gtk.Entry()
        entry.set_placeholder_text(_("Link .."))
        box.pack_start(entry, False, False, 0)

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.INFO)
        box.pack_start(infobar, False, False, 5)
        info_content = infobar.get_content_area()
        info_label = Gtk.Label.new(_("Support http/https/ftp/thunder/qqdl/flashget/eMule/Magnet format"))
        info_content.pack_start(info_label, False, False, 0)

        box.show_all()
        response = dialog.run()
        source_url = entry.get_text()
        dialog.destroy()
        if response != Gtk.ResponseType.OK or not len(source_url):
            return

        if source_url.startswith("magnet"):
            self.add_cloud_bt_task(source_url)
            return

        priv_url = decoder.decode(source_url)
        if priv_url:
            source_url = priv_url
        folder_browser = FolderBrowserDialog(self, self.app, _("Save to.."))
        response = folder_browser.run()
        if response != Gtk.ResponseType.OK:
            folder_browser.destroy()
            return
        save_path = folder_browser.get_path()
        folder_browser.destroy()
        gutil.async_call(
            pcs.cloud_add_link_task,
            self.app.cookie,
            self.app.tokens,
            source_url,
            save_path,
            callback=on_link_task_added,
        )
Пример #22
0
    def upload_files(self, source_paths, dir_name=None):
        '''批量创建上传任务, 会扫描子目录并依次上传.

        source_path - 本地文件的绝对路径
        dir_name    - 文件在服务器上的父目录, 如果为None的话, 会弹出一个
                      对话框让用户来选择一个目录.
        '''
        def scan_folders(folder_path):
            file_list = os.listdir(folder_path)
            source_paths = [os.path.join(folder_path, f) for f in file_list]
            self.upload_files(source_paths,
                    os.path.join(dir_name, os.path.split(folder_path)[1]))

        self.check_first()
        if not dir_name:
            folder_dialog = FolderBrowserDialog(self, self.app)
            response = folder_dialog.run()
            if response != Gtk.ResponseType.OK:
                folder_dialog.destroy()
                return
            dir_name = folder_dialog.get_path()
            folder_dialog.destroy()
        invalid_paths = []
        for source_path in source_paths:
            if util.validate_pathname(source_path) != ValidatePathState.OK:
                invalid_paths.append(source_path)
                continue
            if (os.path.split(source_path)[1].startswith('.') and
                    not self.app.profile['uploading-hidden-files']):
                continue
            if os.path.isfile(source_path):
                self.upload_file(source_path, dir_name)
            elif os.path.isdir(source_path):
                scan_folders(source_path)

        self.app.blink_page(self)
        self.scan_tasks()

        if not invalid_paths:
            return
        dialog = Gtk.Dialog(_('Invalid Filepath'), self.app.window,
                            Gtk.DialogFlags.MODAL,
                            (Gtk.STOCK_CLOSE, Gtk.ResponseType.OK))
        dialog.set_default_size(640, 480)
        dialog.set_border_width(10)
        box = dialog.get_content_area()

        scrolled_window = Gtk.ScrolledWindow()
        box.pack_start(scrolled_window, True, True, 0)
        text_buffer = Gtk.TextBuffer()
        textview = Gtk.TextView.new_with_buffer(text_buffer)
        scrolled_window.add(textview)
        for invalid_path in invalid_paths:
            text_buffer.insert_at_cursor(invalid_path)
            text_buffer.insert_at_cursor('\n')

        infobar = Gtk.InfoBar()
        infobar.set_message_type(Gtk.MessageType.ERROR)
        box.pack_end(infobar, False, False, 0)
        info_label= Gtk.Label()
        infobar.get_content_area().pack_start(info_label, False, False, 0)
        info_label.set_label(''.join([
            '* ', ValidatePathStateText[1], '\n',
            '* ', ValidatePathStateText[2], '\n',
            '* ', ValidatePathStateText[3], '\n',
        ]))

        box.show_all()
        dialog.run()
        dialog.destroy()