mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-11 02:46:39 +00:00
TorrentNotification plugin updates. Thanks, eternalswd.
This commit is contained in:
parent
4e8fe33658
commit
1c5db57f79
@ -46,15 +46,18 @@ class TorrentNotification:
|
|||||||
|
|
||||||
# Create an options file and try to load existing Values
|
# Create an options file and try to load existing Values
|
||||||
self.config_file = deluge.common.CONFIG_DIR + "/notification.conf"
|
self.config_file = deluge.common.CONFIG_DIR + "/notification.conf"
|
||||||
self.config = deluge.pref.Preferences()
|
self.config = deluge.pref.Preferences(self.config_file)
|
||||||
try:
|
try:
|
||||||
self.config.load(self.config_file)
|
self.config.load()
|
||||||
except IOError:
|
except IOError:
|
||||||
# File does not exist
|
# File does not exist
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.glade = gtk.glade.XML(path + "/notification_preferences.glade")
|
self.glade = gtk.glade.XML(path + "/notification_preferences.glade")
|
||||||
self.dialog = self.glade.get_widget("dialog")
|
self.dialog = self.glade.get_widget("dialog")
|
||||||
|
self.glade.signal_autoconnect({
|
||||||
|
'toggle_ui': self.toggle_ui
|
||||||
|
})
|
||||||
|
|
||||||
def handle_event(self, event):
|
def handle_event(self, event):
|
||||||
if event['message'] == "torrent has finished downloading":
|
if event['message'] == "torrent has finished downloading":
|
||||||
@ -62,6 +65,8 @@ class TorrentNotification:
|
|||||||
self.set_tray_flashing_on()
|
self.set_tray_flashing_on()
|
||||||
if self.config.get("enable_notification"):
|
if self.config.get("enable_notification"):
|
||||||
self.show_notification(event)
|
self.show_notification(event)
|
||||||
|
if self.config.get("enable_sound"):
|
||||||
|
self.play_sound()
|
||||||
|
|
||||||
def unload(self):
|
def unload(self):
|
||||||
self.core.disconnect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
|
self.core.disconnect_event(self.core.constants['EVENT_FINISHED'], self.handle_event)
|
||||||
@ -92,15 +97,46 @@ class TorrentNotification:
|
|||||||
print "there was a problem initializing the pynotify module"
|
print "there was a problem initializing the pynotify module"
|
||||||
|
|
||||||
def configure(self):
|
def configure(self):
|
||||||
|
import os.path
|
||||||
try:
|
try:
|
||||||
self.glade.get_widget("chk_tray_blink").set_active(self.config.get("enable_tray_blink"))
|
self.glade.get_widget("chk_tray_blink").set_active(self.config.get("enable_tray_blink"))
|
||||||
self.glade.get_widget("chk_notification").set_active(self.config.get("enable_notification"))
|
self.glade.get_widget("chk_notification").set_active(self.config.get("enable_notification"))
|
||||||
|
self.glade.get_widget("chk_sound").set_active(self.config.get("enable_sound"))
|
||||||
|
self.glade.get_widget("sound_path_button").set_sensitive(self.config.get("enable_sound"))
|
||||||
|
self.glade.get_widget("sound_path_button").set_filename(self.config.get("sound_path"))
|
||||||
except:
|
except:
|
||||||
self.glade.get_widget("chk_tray_blink").set_active(False)
|
self.glade.get_widget("chk_tray_blink").set_active(False)
|
||||||
self.glade.get_widget("chk_notification").set_active(False)
|
self.glade.get_widget("chk_notification").set_active(False)
|
||||||
|
self.glade.get_widget("chk_sound").set_active(False)
|
||||||
|
self.glade.get_widget("sound_path_button").set_filename(os.path.expanduser("~/"))
|
||||||
|
self.glade.get_widget("sound_path_button").set_sensitive(False)
|
||||||
self.dialog.show()
|
self.dialog.show()
|
||||||
response = self.dialog.run()
|
response = self.dialog.run()
|
||||||
self.dialog.hide()
|
self.dialog.hide()
|
||||||
if response:
|
if response:
|
||||||
self.config.set("enable_tray_blink", self.glade.get_widget("chk_tray_blink").get_active())
|
self.config.set("enable_tray_blink", self.glade.get_widget("chk_tray_blink").get_active())
|
||||||
self.config.set("enable_notification", self.glade.get_widget("chk_notification").get_active())
|
self.config.set("enable_notification", self.glade.get_widget("chk_notification").get_active())
|
||||||
|
self.config.set("enable_sound", self.glade.get_widget("chk_sound").get_active())
|
||||||
|
self.config.set("sound_path", self.glade.get_widget("sound_path_button").get_filename())
|
||||||
|
|
||||||
|
def toggle_ui(self, widget):
|
||||||
|
value = widget.get_active()
|
||||||
|
if widget == self.glade.get_widget("chk_sound"):
|
||||||
|
self.glade.get_widget("sound_path_button").set_sensitive(value)
|
||||||
|
|
||||||
|
def play_sound(self):
|
||||||
|
import pygame
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
|
pygame.init()
|
||||||
|
try:
|
||||||
|
name = self.config.get("sound_path")
|
||||||
|
except:
|
||||||
|
print "no file set"
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
alert_sound = pygame.mixer.music
|
||||||
|
alert_sound.load(name)
|
||||||
|
alert_sound.play()
|
||||||
|
except pygame.error, message:
|
||||||
|
print 'Cannot load sound:'
|
||||||
|
@ -5,14 +5,47 @@
|
|||||||
<widget class="GtkDialog" id="dialog">
|
<widget class="GtkDialog" id="dialog">
|
||||||
<property name="border_width">5</property>
|
<property name="border_width">5</property>
|
||||||
<property name="title" translatable="yes">Torrent Notification Preferences</property>
|
<property name="title" translatable="yes">Torrent Notification Preferences</property>
|
||||||
<property name="default_width">313</property>
|
<property name="default_width">400</property>
|
||||||
<property name="default_height">167</property>
|
<property name="default_height">150</property>
|
||||||
<property name="has_separator">False</property>
|
<property name="has_separator">False</property>
|
||||||
<child internal-child="vbox">
|
<child internal-child="vbox">
|
||||||
<widget class="GtkVBox" id="dialog-vbox1">
|
<widget class="GtkVBox" id="dialog-vbox1">
|
||||||
<property name="visible">True</property>
|
<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 | GDK_ENTER_NOTIFY_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
|
||||||
<property name="spacing">2</property>
|
<property name="spacing">2</property>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkHBox" id="dialog-hbox1">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkCheckButton" id="chk_sound">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="label" translatable="yes">Enable event sound (requires pygame)</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<property name="response_id">0</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<signal name="toggled" handler="toggle_ui"/>
|
||||||
|
</widget>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<widget class="GtkFileChooserButton" id="sound_path_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
|
<property name="action">GTK_FILE_CHOOSER_ACTION_SELECT_FILE</property>
|
||||||
|
<property name="title" translatable="yes">Select A File</property>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</widget>
|
||||||
|
<packing>
|
||||||
|
<property name="fill">False</property>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkTable" id="table1">
|
<widget class="GtkTable" id="table1">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -31,7 +64,7 @@
|
|||||||
<widget class="GtkCheckButton" id="chk_notification">
|
<widget class="GtkCheckButton" id="chk_notification">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="label" translatable="yes">Enable popup notification</property>
|
<property name="label" translatable="yes">Enable popup notification (requires notify-python)</property>
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="response_id">0</property>
|
<property name="response_id">0</property>
|
||||||
<property name="draw_indicator">True</property>
|
<property name="draw_indicator">True</property>
|
||||||
@ -43,7 +76,8 @@
|
|||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="position">1</property>
|
<property name="fill">False</property>
|
||||||
|
<property name="expand">False</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child internal-child="action_area">
|
<child internal-child="action_area">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user