Added file viewer preference to Torrent Files plugin.

This commit is contained in:
Alex Dedul 2007-08-09 18:16:28 +00:00
parent a3d79bc2a7
commit 897d394581
3 changed files with 143 additions and 12 deletions

View File

@ -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()

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.2 on Thu Aug 9 21:08:16 2007 by plisk@plisk-->
<glade-interface>
<widget class="GtkDialog" id="dialog">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Files Preferences</property>
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">2</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="n_rows">1</property>
<property name="n_columns">2</property>
<child>
<widget class="GtkEntry" id="file_viewer">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="right_padding">10</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">File Viewer:</property>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button_cancel">
<property name="visible">True</property>
<property name="events"></property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_cancel_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_ok">
<property name="visible">True</property>
<property name="events"></property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_ok_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -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