source: deluge/ui/gtkui/gtkui.py@ 7b72d7

2.0.x develop extjs4-port
Last change on this file since 7b72d7 was 7b72d7, checked in by Andrew Resch <andrewresch@gmail.com>, 16 years ago

Made TrackerIcons a component to prevent trying to get an icon multiple
times
Fixed showing the wrong tracker icon in the TorrentView when the icon
could not be retrieved from the tracker

  • Property mode set to 100644
File size: 8.0 KB
Line 
1#
2# gtkui.py
3#
4# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
5#
6# Deluge is free software.
7#
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)
11# any later version.
12#
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.
17#
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.
23#
24
25
26from deluge.log import LOG as log
27
28# Install the twisted reactor
29from twisted.internet import gtk2reactor
30reactor = gtk2reactor.install()
31
32import gobject
33import gettext
34import locale
35import pkg_resources
36import gtk, gtk.glade
37
38import deluge.component as component
39from deluge.ui.client import client
40from mainwindow import MainWindow
41from menubar import MenuBar
42from toolbar import ToolBar
43from torrentview import TorrentView
44from torrentdetails import TorrentDetails
45from sidebar import SideBar
46from filtertreeview import FilterTreeView
47from preferences import Preferences
48from systemtray import SystemTray
49from statusbar import StatusBar
50from connectionmanager import ConnectionManager
51from pluginmanager import PluginManager
52from ipcinterface import IPCInterface
53from deluge.ui.tracker_icons import TrackerIcons
54
55from queuedtorrents import QueuedTorrents
56from addtorrentdialog import AddTorrentDialog
57import deluge.configmanager
58import deluge.common
59
60DEFAULT_PREFS = {
61 "classic_mode": True,
62 "interactive_add": True,
63 "focus_add_dialog": True,
64 "enable_system_tray": True,
65 "close_to_tray": True,
66 "start_in_tray": False,
67 "lock_tray": False,
68 "tray_password": "",
69 "check_new_releases": True,
70 "default_load_path": None,
71 "window_maximized": False,
72 "window_x_pos": 0,
73 "window_y_pos": 0,
74 "window_width": 640,
75 "window_height": 480,
76 "window_pane_position": -1,
77 "tray_download_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0],
78 "tray_upload_speed_list" : [5.0, 10.0, 30.0, 80.0, 300.0],
79 "connection_limit_list": [50, 100, 200, 300, 500],
80 "enabled_plugins": [],
81 "show_connection_manager_on_start": True,
82 "autoconnect": False,
83 "autoconnect_host_id": None,
84 "autostart_localhost": False,
85 "autoadd_queued": False,
86 "autoadd_enable": False,
87 "autoadd_location": "",
88 "choose_directory_dialog_path": deluge.common.get_default_download_dir(),
89 "show_new_releases": True,
90 "signal_port": 40000,
91 "ntf_tray_blink": True,
92 "ntf_sound": False,
93 "ntf_sound_path": deluge.common.get_default_download_dir(),
94 "ntf_popup": False,
95 "ntf_email": False,
96 "ntf_email_add": "",
97 "ntf_username": "",
98 "ntf_pass": "",
99 "ntf_server": "",
100 "ntf_security": None,
101 "signal_port": 40000,
102 "show_sidebar": True,
103 "show_toolbar": True,
104 "show_statusbar": True,
105 "sidebar_show_zero": False,
106 "sidebar_show_trackers": True,
107 "sidebar_position": 170,
108 "show_rate_in_title": False
109}
110
111class GtkUI:
112 def __init__(self, args):
113
114 # Initialize gettext
115 try:
116 if hasattr(locale, "bindtextdomain"):
117 locale.bindtextdomain("deluge", pkg_resources.resource_filename("deluge", "i18n"))
118 if hasattr(locale, "textdomain"):
119 locale.textdomain("deluge")
120 gettext.bindtextdomain("deluge", pkg_resources.resource_filename("deluge", "i18n"))
121 gettext.textdomain("deluge")
122 gettext.install("deluge", pkg_resources.resource_filename("deluge", "i18n"))
123 gtk.glade.bindtextdomain("deluge", pkg_resources.resource_filename("deluge", "i18n"))
124 gtk.glade.textdomain("deluge")
125 except Exception, e:
126 log.error("Unable to initialize gettext/locale!")
127 log.exception(e)
128 # Setup signals
129 try:
130 import gnome.ui
131 self.gnome_client = gnome.ui.Client()
132 self.gnome_client.connect("die", self.shutdown)
133 except:
134 pass
135
136 # Twisted catches signals to terminate, so just have it call the shutdown
137 # method.
138 reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
139
140 if deluge.common.windows_check():
141 from win32api import SetConsoleCtrlHandler
142 from win32con import CTRL_CLOSE_EVENT
143 from win32con import CTRL_SHUTDOWN_EVENT
144 def win_handler(ctrl_type):
145 log.debug("ctrl_type: %s", ctrl_type)
146 if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT:
147 self.shutdown()
148 return 1
149 SetConsoleCtrlHandler(win_handler)
150
151 # Make sure gtkui.conf has at least the defaults set
152 self.config = deluge.configmanager.ConfigManager("gtkui.conf", DEFAULT_PREFS)
153
154 # We need to check on exit if it was started in classic mode to ensure we
155 # shutdown the daemon.
156 self.started_in_classic = self.config["classic_mode"]
157
158 # Start the IPC Interface before anything else.. Just in case we are
159 # already running.
160 self.queuedtorrents = QueuedTorrents()
161 self.ipcinterface = IPCInterface(args)
162
163 # Initialize gdk threading
164 gtk.gdk.threads_init()
165 gobject.threads_init()
166
167 # We make sure that the UI components start once we get a core URI
168 client.set_disconnect_callback(self.__on_disconnect)
169
170 self.trackericons = TrackerIcons()
171 # Initialize various components of the gtkui
172 self.mainwindow = MainWindow()
173 self.menubar = MenuBar()
174 self.toolbar = ToolBar()
175 self.torrentview = TorrentView()
176 self.torrentdetails = TorrentDetails()
177 self.sidebar = SideBar()
178 self.filtertreeview = FilterTreeView()
179 self.preferences = Preferences()
180 self.systemtray = SystemTray()
181 self.statusbar = StatusBar()
182 self.addtorrentdialog = AddTorrentDialog()
183
184 # Initalize the plugins
185 self.plugins = PluginManager()
186
187 # Show the connection manager
188 self.connectionmanager = ConnectionManager()
189
190 reactor.callWhenRunning(self._on_reactor_start)
191
192 # Start the gtk main loop
193 try:
194 gtk.gdk.threads_enter()
195 reactor.run()
196 gtk.gdk.threads_leave()
197 except KeyboardInterrupt:
198 self.shutdown()
199 else:
200 self.shutdown()
201
202 def shutdown(self, *args, **kwargs):
203 log.debug("gtkui shutting down..")
204
205 # Shutdown all components
206 component.shutdown()
207 if self.started_in_classic:
208 try:
209 client.daemon.shutdown()
210 except:
211 pass
212
213 # Make sure the config is saved.
214 self.config.save()
215
216 try:
217 gtk.main_quit()
218 except RuntimeError:
219 pass
220
221 def _on_reactor_start(self):
222 log.debug("_on_reactor_start")
223 if self.config["classic_mode"]:
224 client.start_classic_mode()
225 component.start()
226 return
227
228 # Autoconnect to a host
229 if self.config["autoconnect"]:
230 for host in self.connectionmanager.config["hosts"]:
231 if host[0] == self.config["autoconnect_host_id"]:
232 def on_connect(connector):
233 component.start()
234 client.connect(*host[1:]).addCallback(on_connect)
235
236 if self.config["show_connection_manager_on_start"]:
237 # XXX: We need to call a simulate() here, but this could be a bug in twisted
238 reactor.simulate()
239 self.connectionmanager.show()
240
241
242
243 def __on_disconnect(self):
244 """
245 Called when disconnected from the daemon. We basically just stop all
246 the components here.
247 """
248 component.stop()
Note: See TracBrowser for help on using the repository browser.