mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-05 16:13:41 +00:00
Replaced TrayBlink plugin with TorrentNotification plugin. Patch from
eternalswd.
This commit is contained in:
parent
b123ffbc34
commit
8ba55e4dfa
100
plugins/TorrentNotification/__init__.py
Normal file
100
plugins/TorrentNotification/__init__.py
Normal file
@ -0,0 +1,100 @@
|
||||
# Copyright (C) 2007 - Micah Bucy <eternalsword@gmail.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
### Initialization ###
|
||||
|
||||
plugin_name = _("Torrent Notification")
|
||||
plugin_author = "Micah Bucy"
|
||||
plugin_version = "0.1"
|
||||
plugin_description = _("Make tray icon blink when torrent finishes downloading and/or popup a notification")
|
||||
|
||||
def deluge_init(deluge_path):
|
||||
global path
|
||||
path = deluge_path
|
||||
|
||||
def enable(core, interface):
|
||||
global path
|
||||
return TorrentNotification(path, core, interface)
|
||||
|
||||
### The Plugin ###
|
||||
import deluge
|
||||
import gtk
|
||||
|
||||
class TorrentNotification:
|
||||
|
||||
def __init__(self, path, core, interface):
|
||||
print "Loading TorrentNotification plugin..."
|
||||
self.path = path
|
||||
self.core = core
|
||||
self.interface = interface
|
||||
self.window = self.interface.window
|
||||
self.window.connect("focus_in_event", self.set_tray_flashing_off)
|
||||
self.core.connect_event(self.core.constants['EVENT_FINISHED'], self)
|
||||
|
||||
# Create an options file and try to load existing Values
|
||||
self.config_file = deluge.common.CONFIG_DIR + "/notification.conf"
|
||||
self.config = deluge.pref.Preferences()
|
||||
try:
|
||||
self.config.load(self.config_file)
|
||||
except IOError:
|
||||
# File does not exist
|
||||
pass
|
||||
|
||||
self.glade = gtk.glade.XML(path + "/notification_preferences.glade")
|
||||
self.dialog = self.glade.get_widget("dialog")
|
||||
|
||||
def handle_event(self, event):
|
||||
if self.config.get("enable_tray_blink"):
|
||||
self.set_tray_flashing_on()
|
||||
if self.config.get("enable_notification"):
|
||||
self.show_notification(event)
|
||||
|
||||
def unload(self):
|
||||
self.config.save(self.config_file)
|
||||
|
||||
def set_tray_flashing_off(self, focusdata1, focusdata2):
|
||||
self.interface.tray_icon.set_blinking(False)
|
||||
|
||||
def set_tray_flashing_on(self):
|
||||
if self.window.has_toplevel_focus() is not True:
|
||||
self.interface.tray_icon.set_blinking(True)
|
||||
|
||||
|
||||
def show_notification(self, event):
|
||||
import pynotify
|
||||
file_info = self.interface.manager.get_torrent_file_info(event['unique_ID'])
|
||||
self.filelist = ""
|
||||
for file in file_info:
|
||||
self.filelist += file['path']+"\n"
|
||||
if pynotify.init("My Application Name"):
|
||||
n = pynotify.Notification("Torrent complete", "Files:\n"+self.filelist)
|
||||
n.show()
|
||||
else:
|
||||
print "there was a problem initializing the pynotify module"
|
||||
|
||||
def configure(self):
|
||||
try:
|
||||
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"))
|
||||
except:
|
||||
self.glade.get_widget("chk_tray_blink").set_active(False)
|
||||
self.glade.get_widget("chk_notification").set_active(False)
|
||||
self.dialog.show()
|
||||
response = self.dialog.run()
|
||||
self.dialog.hide()
|
||||
if response:
|
||||
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())
|
94
plugins/TorrentNotification/notification_preferences.glade
Normal file
94
plugins/TorrentNotification/notification_preferences.glade
Normal file
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
|
||||
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
|
||||
|
||||
<glade-interface>
|
||||
<widget class="GtkDialog" id="dialog">
|
||||
<property name="border_width">5</property>
|
||||
<property name="title" translatable="yes">Torrent Notification Preferences</property>
|
||||
<property name="default_width">313</property>
|
||||
<property name="default_height">167</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 | GDK_ENTER_NOTIFY_MASK</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<widget class="GtkTable" id="table1">
|
||||
<property name="visible">True</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">1</property>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_tray_blink">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Enable blinking tray icon</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">False</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="chk_notification">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Enable popup notification</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">False</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<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 | GDK_ENTER_NOTIFY_MASK</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_cancel">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">gtk-cancel</property>
|
||||
<property name="use_stock">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_ok">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">gtk-ok</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">1</property>
|
||||
</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>
|
@ -1,57 +0,0 @@
|
||||
# Copyright (C) 2007 - Micah Bucy <eternalsword@gmail.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
### Initialization ###
|
||||
|
||||
plugin_name = _("Tray Blink")
|
||||
plugin_author = "Micah Bucy"
|
||||
plugin_version = "0.1"
|
||||
plugin_description = _("Make tray icon blink when torrent finishes downloading")
|
||||
|
||||
def deluge_init(deluge_path):
|
||||
global path
|
||||
path = deluge_path
|
||||
|
||||
def enable(core, interface):
|
||||
global path
|
||||
return TrayBlink(path, core, interface)
|
||||
|
||||
### The Plugin ###
|
||||
|
||||
import deluge
|
||||
import gtk
|
||||
|
||||
class TrayBlink:
|
||||
|
||||
def __init__(self, path, core, interface):
|
||||
print "Loading TrayBlink plugin..."
|
||||
self.path = path
|
||||
self.core = core
|
||||
self.interface = interface
|
||||
self.window = self.interface.window
|
||||
self.window.connect("focus_in_event", self.set_tray_flashing_off)
|
||||
self.core.connect_event(self.core.constants['EVENT_FINISHED'], self)
|
||||
|
||||
def handle_event(self, event):
|
||||
self.set_tray_flashing_on()
|
||||
|
||||
def set_tray_flashing_off(self, focusdata1, focusdata2):
|
||||
self.interface.tray_icon.set_blinking(False)
|
||||
|
||||
def set_tray_flashing_on(self):
|
||||
if self.window.has_toplevel_focus() is not True:
|
||||
self.interface.tray_icon.set_blinking(True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user