4
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
6
# Deluge is free software.
8
# You may redistribute it and/or modify it under the terms of the
9
# GNU General Public License, as published by the Free Software
10
# Foundation; either version 3 of the License, or (at your option)
13
# deluge is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
# See the GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with deluge. If not, write to:
20
# The Free Software Foundation, Inc.,
21
# 51 Franklin Street, Fifth Floor
22
# Boston, MA 02110-1301, USA.
24
# In addition, as a special exception, the copyright holders give
25
# permission to link the code of portions of this program with the OpenSSL
27
# You must obey the GNU General Public License in all respects for all of
28
# the code used other than OpenSSL. If you modify file(s) with this
29
# exception, you may extend this exception to your version of the file(s),
30
# but you are not obligated to do so. If you do not wish to do so, delete
31
# this exception statement from your version. If you delete this exception
32
# statement from all source files in the program, then also delete it here.
37
import deluge.component as component
40
from deluge.ui.client import client
42
from deluge.log import LOG as log
44
class EventLog(component.Component):
46
Prints out certain events as they are received from the core.
49
component.Component.__init__(self, "EventLog")
50
self.console = component.get("ConsoleUI")
51
self.prefix = "{!event!}* "
53
client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event)
54
client.register_event_handler("PreTorrentRemovedEvent", self.on_torrent_removed_event)
55
client.register_event_handler("TorrentStateChangedEvent", self.on_torrent_state_changed_event)
56
client.register_event_handler("TorrentFinishedEvent", self.on_torrent_finished_event)
57
client.register_event_handler("NewVersionAvailableEvent", self.on_new_version_available_event)
58
client.register_event_handler("SessionPausedEvent", self.on_session_paused_event)
59
client.register_event_handler("SessionResumedEvent", self.on_session_resumed_event)
60
client.register_event_handler("ConfigValueChangedEvent", self.on_config_value_changed_event)
61
client.register_event_handler("PluginEnabledEvent", self.on_plugin_enabled_event)
62
client.register_event_handler("PluginDisabledEvent", self.on_plugin_disabled_event)
64
def on_torrent_added_event(self, torrent_id):
65
def on_torrent_status(status):
66
self.console.write(self.prefix + "TorrentAdded: {!info!}%s (%s)" % (status["name"], torrent_id))
67
client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
69
def on_torrent_removed_event(self, torrent_id):
70
self.console.write(self.prefix + "TorrentRemoved: {!info!}%s (%s)" %
71
(self.console.get_torrent_name(torrent_id), torrent_id))
73
def on_torrent_state_changed_event(self, torrent_id, state):
74
# Modify the state string color
75
if state in colors.state_color:
76
state = colors.state_color[state] + state
78
self.console.write(self.prefix + "TorrentStateChanged: %s {!info!}%s (%s)" %
79
(state, self.console.get_torrent_name(torrent_id), torrent_id))
81
def on_torrent_paused_event(self, torrent_id):
82
self.console.write(self.prefix + "TorrentPaused: {!info!}%s (%s)" %
83
(self.console.get_torrent_name(torrent_id), torrent_id))
85
def on_torrent_finished_event(self, torrent_id):
86
self.console.write(self.prefix + "TorrentFinished: {!info!}%s (%s)" %
87
(self.console.get_torrent_name(torrent_id), torrent_id))
89
def on_new_version_available_event(self, version):
90
self.console.write(self.prefix + "NewVersionAvailable: {!info!}%s" %
93
def on_session_paused_event(self):
94
self.console.write(self.prefix + "SessionPaused")
96
def on_session_resumed_event(self):
97
self.console.write(self.prefix + "SessionResumed")
99
def on_config_value_changed_event(self, key, value):
100
color = "{!white,black,bold!}"
101
if type(value) in colors.type_color:
102
color = colors.type_color[type(value)]
104
self.console.write(self.prefix + "ConfigValueChanged: {!input!}%s: %s%s" %
107
def on_plugin_enabled_event(self, name):
108
self.console.write(self.prefix + "PluginEnabled: {!info!}%s" % name)
110
def on_plugin_disabled_event(self, name):
111
self.console.write(self.prefix + "PluginDisabled: {!info!}%s" % name)