diff --git a/deluge/plugins/autoadd/autoadd/core.py b/deluge/plugins/autoadd/autoadd/core.py index ce6d88240..17dc2816f 100644 --- a/deluge/plugins/autoadd/autoadd/core.py +++ b/deluge/plugins/autoadd/autoadd/core.py @@ -60,6 +60,7 @@ OPTIONS_AVAILABLE = { #option: builtin "enabled":False, "path":False, "append_extension":False, + "copy_torrent": False, "abspath":False, "download_location":True, "max_download_speed":True, @@ -120,7 +121,7 @@ class Core(CorePluginBase): def update(self): pass - @export() + @export def set_options(self, watchdir_id, options): """Update the options for a watch folder.""" watchdir_id = str(watchdir_id) @@ -192,6 +193,7 @@ class Core(CorePluginBase): if OPTIONS_AVAILABLE.get(option): if watchdir.get(option+'_toggle', True): opts[option] = value + for filename in os.listdir(watchdir["abspath"]): if filename.split(".")[-1] == "torrent": try: @@ -239,6 +241,9 @@ class Core(CorePluginBase): if not watchdir.get('append_extension'): watchdir['append_extension'] = ".added" os.rename(filepath, filepath + watchdir['append_extension']) + elif watchdir.get('copy_torrent_toggle'): + copy_torrent_path = watchdir['copy_torrent'] + os.rename(filepath, copy_torrent_path) else: os.remove(filepath) @@ -291,7 +296,7 @@ class Core(CorePluginBase): """Returns the config dictionary.""" return self.config.config - @export() + @export def get_watchdirs(self): return self.watchdirs.keys() @@ -303,13 +308,16 @@ class Core(CorePluginBase): opts[key] = options[key] return opts - @export() + @export def add(self, options={}): """Add a watch folder.""" options = self._make_unicode(options) abswatchdir = os.path.abspath(options['path']) CheckInput(os.path.isdir(abswatchdir) , _("Path does not exist.")) - CheckInput(os.access(abswatchdir, os.R_OK|os.W_OK), "You must have read and write access to watch folder.") + CheckInput( + os.access(abswatchdir, os.R_OK|os.W_OK), + "You must have read and write access to watch folder." + ) if abswatchdir in [wd['abspath'] for wd in self.watchdirs.itervalues()]: raise Exception("Path is already being watched.") options.setdefault('enabled', False) @@ -327,7 +335,8 @@ class Core(CorePluginBase): def remove(self, watchdir_id): """Remove a watch folder.""" watchdir_id = str(watchdir_id) - CheckInput(watchdir_id in self.watchdirs, "Unknown Watchdir: %s" % self.watchdirs) + CheckInput(watchdir_id in self.watchdirs, + "Unknown Watchdir: %s" % self.watchdirs) if self.watchdirs[watchdir_id]['enabled']: self.disable_watchdir(watchdir_id) del self.watchdirs[watchdir_id] @@ -338,3 +347,7 @@ class Core(CorePluginBase): for watchdir_id in config['watchdirs'].iterkeys(): config['watchdirs'][watchdir_id]['owner'] = 'localclient' return config + + ### XXX: Handle torrent finished / remove torrent file per whatchdir + ### deluge/core/torrentmanager.py: + ### filename = self.torrents[torrent_id].filename diff --git a/deluge/plugins/autoadd/autoadd/data/autoadd_options.glade b/deluge/plugins/autoadd/autoadd/data/autoadd_options.glade index 5c8bab041..58545ebe8 100644 --- a/deluge/plugins/autoadd/autoadd/data/autoadd_options.glade +++ b/deluge/plugins/autoadd/autoadd/data/autoadd_options.glade @@ -295,7 +295,6 @@ True select-folder - True Select A Folder diff --git a/deluge/plugins/autoadd/autoadd/gtkui.py b/deluge/plugins/autoadd/autoadd/gtkui.py index 53e2fc9ef..8ee1aff98 100644 --- a/deluge/plugins/autoadd/autoadd/gtkui.py +++ b/deluge/plugins/autoadd/autoadd/gtkui.py @@ -90,9 +90,6 @@ class OptionsDialog(): self.load_options(options) # Not implemented feateures present in UI - self.glade.get_widget("copy_torrent_toggle").hide() - self.glade.get_widget("copy_torrent_entry").hide() - self.glade.get_widget("copy_torrent_chooser").hide() self.glade.get_widget("delete_copy_torrent_toggle").hide() self.dialog.run() @@ -108,6 +105,9 @@ class OptionsDialog(): self.glade.get_widget('download_location_toggle').set_active( options.get('download_location_toggle', False) ) + self.glade.get_widget('copy_torrent_toggle').set_active( + options.get('copy_torrent_toggle', False) + ) self.accounts.clear() self.labels.clear() combobox = self.glade.get_widget('OwnerCombobox') @@ -137,7 +137,7 @@ class OptionsDialog(): for field in ['move_completed_path', 'path', 'download_location', 'copy_torrent']: if client.is_localhost(): - self.glade.get_widget(field+"_chooser").set_filename( + self.glade.get_widget(field+"_chooser").set_current_folder( options.get(field, os.path.expanduser("~")) ) self.glade.get_widget(field+"_chooser").show() @@ -268,19 +268,21 @@ class OptionsDialog(): options['path'] = self.glade.get_widget('path_chooser').get_filename() options['download_location'] = self.glade.get_widget('download_location_chooser').get_filename() options['move_completed_path'] = self.glade.get_widget('move_completed_path_chooser').get_filename() + options['copy_torrent'] = self.glade.get_widget('copy_torrent_chooser').get_filename() else: options['path'] = self.glade.get_widget('path_entry').get_text() options['download_location'] = self.glade.get_widget('download_location_entry').get_text() options['move_completed_path'] = self.glade.get_widget('move_completed_path_entry').get_text() + options['copy_torrent'] = self.glade.get_widget('copy_torrent_entry').get_text() + options['label'] = self.glade.get_widget('label').child.get_text().lower() + options['append_extension'] = self.glade.get_widget('append_extension').get_text() options['owner'] = self.accounts[ self.glade.get_widget('OwnerCombobox').get_active()][0] - options['append_extension_toggle'] = self.glade.get_widget('append_extension_toggle').get_active() - options['append_extension'] = self.glade.get_widget('append_extension').get_text() - options['download_location_toggle'] = self.glade.get_widget('download_location_toggle').get_active() - options['label'] = self.glade.get_widget('label').child.get_text().lower() - options['label_toggle'] = self.glade.get_widget('label_toggle').get_active() + for key in ['append_extension_toggle', 'download_location_toggle', + 'label_toggle', 'copy_torrent_toggle']: + options[key] = self.glade.get_widget(key).get_active() for id in self.spin_ids: options[id] = self.glade.get_widget(id).get_value()