22
21
LOG = logging.getLogger(__name__)
24
from os.path import join, isfile
25
from subprocess import Popen
26
23
from threading import Thread
28
25
from lottanzb.core.environ import _
26
from lottanzb.backend import Backend
27
from lottanzb.backend.sessions.local import LocalSession
28
from lottanzb.backend.sessions.remote import RemoteSession
29
29
from lottanzb.backend.hubs.config import ConfigHub
30
30
from lottanzb.backend.hubs.general import GeneralHub
31
from lottanzb.resources import is_installed, get_help
32
31
from lottanzb.config.section import ConfigSection
33
32
from lottanzb.util import gproperty
34
33
from lottanzb.util.signalmanager import SignalManager
35
34
from lottanzb.util.misc import open_directory
36
from lottanzb.gui import add_file, add_url, about, log, prefs
35
from lottanzb.gui import add_file, add_url, about, log, prefs, sessions
36
from lottanzb.gui.help import open_help
37
37
from lottanzb.gui.messaging import MessagingManager
38
38
from lottanzb.gui.download_list import DownloadList
39
39
from lottanzb.gui.info_bar import InfoBar
42
42
ConduitCollection, Conduit, GObjectEndPoint, ToggleActionEndPoint)
44
44
class Config(ConfigSection):
45
# Holds a configuration section of type `ViewConfig'.
46
view = gproperty(type=object)
45
48
width = gproperty(type=int, default=700)
46
49
height = gproperty(type=int, default=350)
47
50
x_pos = gproperty(type=int, default=100)
48
51
y_pos = gproperty(type=int, default=100)
49
52
maximized = gproperty(type=bool, default=False)
54
def find_section_class(self, section):
58
return ConfigSection.find_section_class(self, section)
61
class ViewConfig(ConfigSection):
62
"""Holds information about what elements are visible in the main window.
64
The boolean options have been moved to a separate configuration section
65
because they are closely related and the functionality might one day be
66
moved to a separate submodule called `view'.
69
toolbar = gproperty(type=bool, default=True)
70
infobar = gproperty(type=bool, default=True)
71
reordering_pane = gproperty(type=bool, default=True)
74
class WidgetVisibilityEndPoint(GObjectEndPoint):
75
"""An endpoint for a widget that modifies the widget's visibility given
76
boolean values sent through the conduit.
52
82
class MainWindow(MainDelegateComponent):
53
83
builder_file = "main_window"
63
93
# The list of actions that may only be used if connected to an instance
65
95
self.backend_actions = [self.add, self.add_url, self.clear, self.paused,
66
self.open_download_dir, self.edit_preferences]
96
self.open_download_dir, self.edit_preferences,
97
self.select_local_session, self.select_remote_session,
98
self.open_web_interface]
68
100
def on_general_hub_changed(self, *args):
69
101
self.on_general_hub_updated(None)
74
106
def create_ui(self):
75
107
self.enable_rgba_support()
76
108
self.restore_window_geometry()
110
# Make the 'View -> Toolbar' `gtk.CheckMenuItem' functional.
111
self.view_toolbar_conduit = Conduit(
112
GObjectEndPoint(self.config.view, "toolbar"),
113
ToggleActionEndPoint(self.view_toolbar),
114
WidgetVisibilityEndPoint(self.toolbar))
116
# Make the 'View -> Infobar' `gtk.CheckMenuItem' functional.
117
self.view_infobar_conduit = Conduit(
118
GObjectEndPoint(self.config.view, "infobar"),
119
ToggleActionEndPoint(self.view_infobar),
120
WidgetVisibilityEndPoint(self.infobar))
122
# Make the 'View -> Reordering Pane' `gtk.CheckMenuItem' functional.
123
# Because the actual reordering pane is dynamically added to the window
124
# when LottaNZB is connected to SABnzbd, the corresponding end point
125
# will also be added and removed dynamically.
126
# This is required so that the check menu items is still functional
127
# even if LottaNZB is not connected to SABnzbd.
128
self.view_reordering_pane_conduit = Conduit(
129
GObjectEndPoint(self.config.view, "reordering_pane"),
130
ToggleActionEndPoint(self.view_reordering_pane))
132
self.view_reordering_pane_endpoint = None
134
self.select_local_session.set_property("visible", False)
78
136
def attach_to_backend(self, backend):
79
137
self.general_hub = self._component_manager.load(GeneralHub)
91
149
from lottanzb.gui.messaging import (download_import,
92
150
postprocessing_priority, servers)
94
info_bar = self._component_manager.load(InfoBar)
152
infobar = self._component_manager.load(InfoBar)
95
153
download_list = self._component_manager.load(DownloadList)
96
154
manager = self._component_manager.load(MessagingManager)
98
self.attach_slave(self.info_bar, info_bar)
156
self.attach_slave(self.infobar, infobar)
99
157
self.attach_slave(self.download_list, download_list)
100
158
self.attach_slave(self.message, manager)
160
self.view_reordering_pane_endpoint = WidgetVisibilityEndPoint(
161
download_list.reordering_pane)
162
self.view_reordering_pane_conduit.add_endpoint(
163
self.view_reordering_pane_endpoint)
102
165
self.toolbar_remove.set_related_action(download_list.remove)
166
self.select_local_session.set_property("visible",
167
not isinstance(backend.session, LocalSession))
104
169
def detach_from_backend(self):
105
170
self.detach_all_slaves()
106
171
self.session_signals.disconnect_all()
107
172
self.session_conduits.remove_all()
174
if self.view_reordering_pane_endpoint:
175
self.view_reordering_pane_conduit.remove_endpoint(
176
self.view_reordering_pane_endpoint)
109
178
self._component_manager.unload(DownloadList)
110
179
self._component_manager.unload(MessagingManager)
193
262
Thread(target=sys.exit).run()
264
def show_session_selection_dialog(self, session_type):
265
self._component_manager.unload(Backend)
267
dialog = self._component_manager.load(sessions.SelectionDialog)
268
dialog.preselect_session_type(session_type)
270
def on_select_local_session__activate(self, widget):
271
self.show_session_selection_dialog(LocalSession)
273
def on_select_remote_session__activate(self, widget):
274
self.show_session_selection_dialog(RemoteSession)
276
def on_open_web_interface__activate(self, widget):
277
"""Open the SABnzbd web interface in a browser tab."""
279
backend = self._component_manager.get(Backend)
280
url = backend.interface.connection_info.url
282
webbrowser.open_new_tab(url)
195
284
def on_edit_preferences__activate(self, widget):
196
285
"""Open the preferences dialog."""
206
295
window.show(self.get_toplevel())
208
297
def on_show_help_content__activate(self, widget):
210
if not is_installed():
211
for l in [locale.getlocale()[0][:2], "C"]:
212
help_file = get_help(join(l, "lottanzb.xml"))
214
if isfile(help_file):
215
Popen(["yelp", help_file])
218
default_screen = gtk.gdk.screen_get_default()
219
event_time = gtk.get_current_event_time()
221
gtk.show_uri(default_screen, "ghelp:lottanzb", event_time)
223
webbrowser.open_new_tab("http://www.lottanzb.org/help")
225
300
def on_show_about_dialog__activate(self, widget):
226
301
dialog = self._component_manager.load(about.Dialog)