diff --git a/plugins/TorrentFiles/__init__.py b/plugins/TorrentFiles/__init__.py index 5a1ea5e86..ac87f089c 100644 --- a/plugins/TorrentFiles/__init__.py +++ b/plugins/TorrentFiles/__init__.py @@ -42,6 +42,21 @@ class TorrentFiles: print "Loading TorrentFiles plugin..." self.parent = interface self.manager = core + config_file = deluge.common.CONFIG_DIR + "/files.conf" + self.config = deluge.pref.Preferences(config_file, False, + defaults={'file_viewer': 'xdg-open'}) + try: + self.config.load() + except IOError: + # File does not exist + pass + + self.glade = gtk.glade.XML(path + "/files_preferences.glade") + self.dialog = self.glade.get_widget("dialog") + self.glade.signal_autoconnect({ + 'on_button_cancel_clicked': self.on_button_cancel_clicked, + 'on_button_ok_clicked': self.on_button_ok_clicked + }) tree_view = gtk.TreeView() scrolled_window = gtk.ScrolledWindow() @@ -58,11 +73,13 @@ class TorrentFiles: self.tab_files = FilesTabManager(tree_view, core) self.tab_files.build_file_view() + self.tab_files.set_file_viewer(self.config.get("file_viewer")) def unload(self): self.tab_files.clear_file_store() tab_page = self.parent_notebook.page_num(self.top_widget) self.parent_notebook.remove_page(tab_page) + self.config.save() def update(self): if not self.parent.update_interface: @@ -87,3 +104,21 @@ class TorrentFiles: self.tab_files.prepare_file_store() else: self.tab_files.update_file_store() + + def configure(self, window): + self.glade.get_widget("file_viewer").\ + set_text(self.config.get("file_viewer")) + self.dialog.set_transient_for(window) + self.dialog.show() + + def on_button_ok_clicked(self, button): + self.dialog.hide() + + self.config.set("file_viewer", + self.glade.get_widget("file_viewer").get_text()) + self.config.save() + + self.tab_files.set_file_viewer(self.config.get("file_viewer")) + + def on_button_cancel_clicked(self, button): + self.dialog.hide() diff --git a/plugins/TorrentFiles/files_preferences.glade b/plugins/TorrentFiles/files_preferences.glade new file mode 100644 index 000000000..25830cbbe --- /dev/null +++ b/plugins/TorrentFiles/files_preferences.glade @@ -0,0 +1,94 @@ + + + + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + Files Preferences + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_NORMAL + True + True + False + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 1 + 2 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + 1 + 2 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 10 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + File Viewer: + + + + + + + False + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_BUTTONBOX_END + + + True + + gtk-cancel + True + 0 + + + + + + True + + gtk-ok + True + 0 + + + + 1 + + + + + False + GTK_PACK_END + + + + + + diff --git a/plugins/TorrentFiles/tab_files.py b/plugins/TorrentFiles/tab_files.py index 2199c69ba..8ccd419bd 100644 --- a/plugins/TorrentFiles/tab_files.py +++ b/plugins/TorrentFiles/tab_files.py @@ -20,6 +20,8 @@ class FilesTabManager(FilesBaseManager): # in self.update_file_store() self.file_store_dict = {} + self.file_viewer = None + def build_file_view(self): super(FilesTabManager, self).build_file_view() @@ -39,22 +41,22 @@ class FilesTabManager(FilesBaseManager): else: super(FilesTabManager, self).priority_clicked(widget) + def set_file_viewer(self, file_viewer): + self.file_viewer = file_viewer + def open_file(self, widget): - selected_paths = self.file_view.get_selection().get_selected_rows()[1] import os + + save_dir = self.manager.unique_IDs[self.file_unique_id].save_dir + selected_paths = self.file_view.get_selection().get_selected_rows()[1] try: for path in selected_paths: - child_path = self.file_store_sorted.convert_path_to_child_path(path) - result = os.system("xdg-open %s/%s" %(self.manager.unique_IDs[self.file_unique_id].save_dir, \ - self.file_store.get_value(self.file_store.get_iter(child_path), 0))) - if result != 0: - warning = gtk.MessageDialog(parent = None, - flags = gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, - buttons= gtk.BUTTONS_OK, - message_format=_("xdg-open was not found. Please install xdg-utils for this feature to work"), - type = gtk.MESSAGE_WARNING) - warning.run() - warning.destroy() + child_path = self.file_store_sorted.\ + convert_path_to_child_path(path) + file_name = self.file_store.get_value( + self.file_store.get_iter(child_path), 0) + os.system('%s "%s" &' % (self.file_viewer, + os.path.join(save_dir, file_name))) except KeyError: pass