def add_link_task(self):
def do_add_link_task(source_url):<EOL><INDENT>def on_link_task_added(info, error=None):<EOL><INDENT>if error or not info:<EOL><INDENT>logger.error('<STR_LIT>' %<EOL>(info, error))<EOL>self.app.toast(_('<STR_LIT>'))<EOL>return<EOL><DEDENT>if info.get('<STR_LIT>', -<NUM_LIT:1>) != <NUM_LIT:0>:<EOL><INDENT>logger.error('<STR_LIT>' %<EOL>(info, error))<EOL><DEDENT>if '<STR_LIT>' in info or info['<STR_LIT>'] == <NUM_LIT:0>:<EOL><INDENT>self.reload()<EOL><DEDENT>elif info['<STR_LIT>'] == -<NUM_LIT>:<EOL><INDENT>vcode = info['<STR_LIT>']<EOL>vcode_dialog = VCodeDialog(self, self.app, info)<EOL>response = vcode_dialog.run()<EOL>vcode_input = vcode_dialog.get_vcode()<EOL>vcode_dialog.destroy()<EOL>if response != Gtk.ResponseType.OK:<EOL><INDENT>return<EOL><DEDENT>gutil.async_call(pcs.cloud_add_link_task, self.app.cookie,<EOL>self.app.tokens, source_url, save_path,<EOL>vcode, vcode_input,<EOL>callback=on_link_task_added)<EOL><DEDENT>else:<EOL><INDENT>self.app.toast(_('<STR_LIT>').format(info['<STR_LIT>']))<EOL><DEDENT><DEDENT>gutil.async_call(pcs.cloud_add_link_task, self.app.cookie,<EOL>self.app.tokens, source_url, save_path,<EOL>callback=on_link_task_added)<EOL><DEDENT>self.check_first()<EOL>dialog = Gtk.Dialog(_('<STR_LIT>'), self.app.window,<EOL>Gtk.DialogFlags.MODAL,<EOL>(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,<EOL>Gtk.STOCK_OK, Gtk.ResponseType.OK))<EOL>dialog.set_border_width(<NUM_LIT:10>)<EOL>dialog.set_default_size(<NUM_LIT>, <NUM_LIT>)<EOL>dialog.set_default_response(Gtk.ResponseType.OK)<EOL>box = dialog.get_content_area()<EOL>scrolled_win = Gtk.ScrolledWindow()<EOL>box.pack_start(scrolled_win, True, True, <NUM_LIT:0>)<EOL>links_buf = Gtk.TextBuffer()<EOL>links_tv = Gtk.TextView.new_with_buffer(links_buf)<EOL>links_tv.set_tooltip_text(_('<STR_LIT>'))<EOL>scrolled_win.add(links_tv)<EOL>infobar = Gtk.InfoBar()<EOL>infobar.set_message_type(Gtk.MessageType.INFO)<EOL>box.pack_start(infobar, False, False, <NUM_LIT:5>)<EOL>info_content = infobar.get_content_area()<EOL>info_label = Gtk.Label.new(<EOL>_('<STR_LIT>'))<EOL>info_content.pack_start(info_label, False, False, <NUM_LIT:0>)<EOL>box.show_all()<EOL>response = dialog.run()<EOL>contents = gutil.text_buffer_get_all_text(links_buf)<EOL>dialog.destroy()<EOL>if response != Gtk.ResponseType.OK or not contents:<EOL><INDENT>return<EOL><DEDENT>link_tasks = []<EOL>bt_tasks = []<EOL>for source_url in contents.split('<STR_LIT:\n>'):<EOL><INDENT>source_url = source_url.strip()<EOL>if not source_url:<EOL><INDENT>continue<EOL><DEDENT>if source_url.startswith('<STR_LIT>'):<EOL><INDENT>bt_tasks.append(source_url)<EOL><DEDENT>else:<EOL><INDENT>priv_url = decoder.decode(source_url)<EOL>if priv_url:<EOL><INDENT>link_tasks.append(priv_url)<EOL><DEDENT>else:<EOL><INDENT>link_tasks.append(source_url)<EOL><DEDENT><DEDENT><DEDENT>folder_browser = FolderBrowserDialog(self, self.app, _('<STR_LIT>'))<EOL>response = folder_browser.run()<EOL>save_path = folder_browser.get_path()<EOL>folder_browser.destroy()<EOL>if response != Gtk.ResponseType.OK or not save_path:<EOL><INDENT>return<EOL><DEDENT>for source_url in link_tasks:<EOL><INDENT>do_add_link_task(source_url)<EOL><DEDENT>for source_url in bt_tasks:<EOL><INDENT>self.add_cloud_bt_task(source_url, save_path)<EOL><DEDENT>
新建普通的链接任务