[GTKUI] Cleanup Standalone/Thin client dialogs

This commit is contained in:
Calum Lind 2014-08-09 18:01:26 +01:00
parent dc7a4df39a
commit 8cc96d9b89
6 changed files with 54 additions and 146 deletions

View File

@ -54,7 +54,7 @@ class BaseDialog(gtk.Dialog):
MainWindow MainWindow
""" """
super(BaseDialog, self).__init__( super(BaseDialog, self).__init__(
title="", title=header,
parent=parent if parent else component.get("MainWindow").window, parent=parent if parent else component.get("MainWindow").window,
flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR, flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR,
buttons=buttons) buttons=buttons)
@ -80,11 +80,6 @@ class BaseDialog(gtk.Dialog):
image.set_alignment(0.5, 0.0) image.set_alignment(0.5, 0.0)
hbox.pack_start(image, False, False) hbox.pack_start(image, False, False)
vbox = gtk.VBox(spacing=5) vbox = gtk.VBox(spacing=5)
label = gtk.Label("<b><big>" + header + "</big></b>")
label.set_use_markup(True)
label.set_alignment(0.0, 0.5)
label.set_line_wrap(True)
vbox.pack_start(label, False, False)
tlabel = gtk.Label(text) tlabel = gtk.Label(text)
tlabel.set_use_markup(True) tlabel.set_use_markup(True)
tlabel.set_line_wrap(True) tlabel.set_line_wrap(True)

View File

@ -416,7 +416,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">The classic self-contained application</property> <property name="tooltip_text" translatable="yes">The standalone self-contained application</property>
<property name="active">True</property> <property name="active">True</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
</object> </object>
@ -520,19 +520,16 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Besides being experimental, using the pieces bar <property name="tooltip_text" translatable="yes">The pieces bar
will increase the bandwidth used between client will increase bandwidth use between client
and daemon(does not apply in classic mode). and daemon (does not apply in Standalone mode).</property>
Use at your own risk if you wish to help us debug
this new feature.</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<signal name="toggled" handler="on_piecesbar_toggle_toggled" swapped="no"/> <signal name="toggled" handler="on_piecesbar_toggle_toggled" swapped="no"/>
<child> <child>
<object class="GtkLabel" id="label62"> <object class="GtkLabel" id="label62">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="label" translatable="yes">Show a pieces bar in the torrent's <property name="label" translatable="yes">Show a pieces bar in Status tab</property>
status tab (&lt;b&gt;EXPERIMENTAL!!!&lt;/b&gt;)</property>
<property name="use_markup">True</property> <property name="use_markup">True</property>
</object> </object>
</child> </child>

View File

@ -323,31 +323,34 @@ class GtkUI(object):
self.mainwindow.first_show() self.mainwindow.first_show()
if self.config["classic_mode"]: if self.config["classic_mode"]:
def on_dialog_response(response): def on_dialog_response(response):
if response != gtk.RESPONSE_YES: if response != gtk.RESPONSE_YES:
# The user does not want to turn Classic Mode off, so just quit # The user does not want to turn Standalone Mode off, so just quit
self.mainwindow.quit() self.mainwindow.quit()
return return
# Turning off classic_mode # Turning off classic_mode
self.config["classic_mode"] = False self.config["classic_mode"] = False
self.__start_non_classic() self.__start_non_classic()
try: try:
try: try:
client.start_classic_mode() client.start_classic_mode()
except deluge.error.DaemonRunningError: except deluge.error.DaemonRunningError:
d = dialogs.YesNoDialog( d = dialogs.YesNoDialog(
_("Turn off Classic Mode?"), _("Switch to Thin Client Mode?"),
_("It appears that a Deluge daemon process (deluged) is already running.\n\n\ _("A Deluge daemon process (deluged) is already running. "
You will either need to stop the daemon or turn off Classic Mode to continue.")).run() "To use Standalone mode, stop this daemon and restart Deluge."
"\n\n"
"Continue in Thin Client mode?")).run()
self.started_in_classic = False self.started_in_classic = False
d.addCallback(on_dialog_response) d.addCallback(on_dialog_response)
except ImportError, e: except ImportError, e:
if "No module named libtorrent" in e.message: if "No module named libtorrent" in e.message:
d = dialogs.YesNoDialog( d = dialogs.YesNoDialog(
_("Enable Thin Client Mode?"), _("Switch to Thin Client Mode?"),
_("Thin client mode is only available because libtorrent is not installed.\n\n\ _("Only Thin Client mode is available because libtorrent is not installed."
To use Deluge standalone (Classic mode) please install libtorrent.")).run() "\n\n"
"To use Deluge Standalone mode, please install libtorrent.")).run()
self.started_in_classic = False self.started_in_classic = False
d.addCallback(on_dialog_response) d.addCallback(on_dialog_response)
else: else:
@ -360,13 +363,14 @@ To use Deluge standalone (Classic mode) please install libtorrent.")).run()
tb = sys.exc_info() tb = sys.exc_info()
ed = dialogs.ErrorDialog( ed = dialogs.ErrorDialog(
_("Error Starting Core"), _("Error Starting Core"),
_("There was an error starting the core component which is required to run Deluge in Classic Mode.\n\n\ _("An error occurred starting the core component required to run Deluge in Standalone mode."
Please see the details below for more information."), details=traceback.format_exc(tb[2])).run() "\n\n"
"Please see the details below for more information."), details=traceback.format_exc(tb[2])).run()
def on_ed_response(response): def on_ed_response(response):
d = dialogs.YesNoDialog( d = dialogs.YesNoDialog(
_("Turn off Classic Mode?"), _("Switch to Thin Client Mode?"),
_("Since there was an error starting in Classic Mode would you like to continue by turning it off?") _("Unable to start Standalone mode would you like to continue in Thin Client mode?")
).run() ).run()
self.started_in_classic = False self.started_in_classic = False
d.addCallback(on_dialog_response) d.addCallback(on_dialog_response)

View File

@ -1,39 +1,14 @@
# # -*- coding: utf-8 -*-
# menubar.py
# #
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
# #
# Deluge is free software. # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# # the additional special exception to link portions of this program with the OpenSSL library.
# You may redistribute it and/or modify it under the terms of the # See LICENSE for more details.
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge 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 deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
#
# #
import os.path import os.path
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
@ -179,8 +154,6 @@ class MenuBar(component.Component):
"menuitem_addtorrent" "menuitem_addtorrent"
] ]
self.config.register_set_function("classic_mode", self._on_classic_mode)
client.register_event_handler("TorrentStateChangedEvent", self.on_torrentstatechanged_event) client.register_event_handler("TorrentStateChangedEvent", self.on_torrentstatechanged_event)
client.register_event_handler("TorrentResumedEvent", self.on_torrentresumed_event) client.register_event_handler("TorrentResumedEvent", self.on_torrentresumed_event)
client.register_event_handler("SessionPausedEvent", self.on_sessionpaused_event) client.register_event_handler("SessionPausedEvent", self.on_sessionpaused_event)
@ -204,9 +177,9 @@ class MenuBar(component.Component):
self.builder.get_object(widget).hide() self.builder.get_object(widget).hide()
self.builder.get_object(widget).set_no_show_all(True) self.builder.get_object(widget).set_no_show_all(True)
if not self.config["classic_mode"]: self.main_builder.get_object("separatormenuitem").set_visible(not self.config["classic_mode"])
self.main_builder.get_object("separatormenuitem").show() self.main_builder.get_object("menuitem_quitdaemon").set_visible(not self.config["classic_mode"])
self.main_builder.get_object("menuitem_quitdaemon").show() self.main_builder.get_object("menuitem_connectionmanager").set_visible(not self.config["classic_mode"])
# Show the Torrent menu because we're connected to a host # Show the Torrent menu because we're connected to a host
self.menu_torrent.show() self.menu_torrent.show()
@ -503,12 +476,6 @@ class MenuBar(component.Component):
self.config["sidebar_show_trackers"] = widget.get_active() self.config["sidebar_show_trackers"] = widget.get_active()
component.get("FilterTreeView").update() component.get("FilterTreeView").update()
def _on_classic_mode(self, key, value):
if value:
self.main_builder.get_object("menuitem_connectionmanager").hide()
else:
self.main_builder.get_object("menuitem_connectionmanager").show()
def _on_known_accounts(self, known_accounts): def _on_known_accounts(self, known_accounts):
known_accounts_to_log = [] known_accounts_to_log = []
for account in known_accounts: for account in known_accounts:

View File

@ -786,27 +786,22 @@ class Preferences(component.Component):
# Re-show the dialog to make sure everything has been updated # Re-show the dialog to make sure everything has been updated
self.show() self.show()
if classic_mode_was_set and not new_gtkui_in_classic_mode: if classic_mode_was_set != new_gtkui_in_classic_mode:
def on_response(response): def on_response(response):
if response == gtk.RESPONSE_NO: if response == gtk.RESPONSE_YES:
# Set each changed config value in the core shutdown_daemon = (not client.is_classicmode() and
self.gtkui_config["classic_mode"] = True client.connected() and
self.builder.get_object("radio_classic").set_active(True) client.is_localhost())
component.get("MainWindow").quit(shutdown=shutdown_daemon)
else: else:
client.disconnect() self.gtkui_config["classic_mode"] = not new_gtkui_in_classic_mode
component.stop() self.builder.get_object("radio_classic").set_active(self.gtkui_config["classic_mode"])
self.builder.get_object("radio_thinclient").set_active(True) self.builder.get_object("radio_thinclient").set_active(not self.gtkui_config["classic_mode"])
dialog = dialogs.YesNoDialog( dialog = dialogs.YesNoDialog(
_("Attention"), _("Switching client mode..."),
_("Your current session will be stopped. Continue?") _("Your current session will be stopped. Do you wish to continue?")
) )
dialog.run().addCallback(on_response) dialog.run().addCallback(on_response)
elif not classic_mode_was_set and new_gtkui_in_classic_mode:
dialog = dialogs.InformationDialog(
_("Attention"),
_("You must now restart the deluge UI")
)
dialog.run()
def hide(self): def hide(self):
self.window_open = False self.window_open = False

View File

@ -1,51 +1,23 @@
# -*- coding: utf-8 -*-
# #
# toolbar.py # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
# #
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
# #
# Deluge is free software.
#
# You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software
# Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# deluge 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 deluge. If not, write to:
# The Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor
# Boston, MA 02110-1301, USA.
#
# In addition, as a special exception, the copyright holders give
# permission to link the code of portions of this program with the OpenSSL
# library.
# You must obey the GNU General Public License in all respects for all of
# the code used other than OpenSSL. If you modify file(s) with this
# exception, you may extend this exception to your version of the file(s),
# but you are not obligated to do so. If you do not wish to do so, delete
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
#
#
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
import gtk import gtk
import gobject
import logging import logging
import deluge.component as component import deluge.component as component
from deluge.ui.client import client
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class ToolBar(component.Component): class ToolBar(component.Component):
def __init__(self): def __init__(self):
component.Component.__init__(self, "ToolBar") component.Component.__init__(self, "ToolBar")
@ -75,14 +47,12 @@ class ToolBar(component.Component):
"find_menuitem" "find_menuitem"
] ]
self.config.register_set_function("classic_mode", self._on_classic_mode, True)
# Hide if necessary # Hide if necessary
self.visible(self.config["show_toolbar"]) self.visible(self.config["show_toolbar"])
def start(self): def start(self):
if not self.config["classic_mode"]: self.window.get_builder().get_object("toolbutton_connectionmanager").set_visible(
self.window.get_builder().get_object("toolbutton_connectionmanager").show() not self.config["classic_mode"])
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
self.window.get_builder().get_object(widget).set_sensitive(True) self.window.get_builder().get_object(widget).set_sensitive(True)
@ -99,10 +69,8 @@ class ToolBar(component.Component):
self.config["show_toolbar"] = visible self.config["show_toolbar"] = visible
def add_toolbutton(self, callback, label=None, image=None, stock=None, def add_toolbutton(self, callback, label=None, image=None, stock=None, tooltip=None):
tooltip=None):
"""Adds a toolbutton to the toolbar""" """Adds a toolbutton to the toolbar"""
# Create the button
toolbutton = gtk.ToolButton() toolbutton = gtk.ToolButton()
if stock is not None: if stock is not None:
toolbutton.set_stock_id(stock) toolbutton.set_stock_id(stock)
@ -110,16 +78,11 @@ class ToolBar(component.Component):
toolbutton.set_label(label) toolbutton.set_label(label)
if image is not None: if image is not None:
toolbutton.set_icon_widget(image) toolbutton.set_icon_widget(image)
# Set the tooltip
if tooltip is not None: if tooltip is not None:
toolbutton.set_tooltip_text(tooltip) toolbutton.set_tooltip_text(tooltip)
# Connect the 'clicked' event callback
toolbutton.connect("clicked", callback) toolbutton.connect("clicked", callback)
# Append the button to the toolbar
self.toolbar.insert(toolbutton, -1) self.toolbar.insert(toolbutton, -1)
# Show the new toolbutton
toolbutton.show_all() toolbutton.show_all()
return toolbutton return toolbutton
@ -130,7 +93,6 @@ class ToolBar(component.Component):
if position is not None: if position is not None:
self.toolbar.insert(sep, position) self.toolbar.insert(sep, position)
else: else:
# Append the separator
self.toolbar.insert(sep, -1) self.toolbar.insert(sep, -1)
sep.show() sep.show()
@ -141,35 +103,30 @@ class ToolBar(component.Component):
"""Removes a widget from the toolbar""" """Removes a widget from the toolbar"""
self.toolbar.remove(widget) self.toolbar.remove(widget)
### Callbacks ### ### Callbacks (Uses the menubar's callback) ###
def on_toolbutton_add_clicked(self, data): def on_toolbutton_add_clicked(self, data):
log.debug("on_toolbutton_add_clicked") log.debug("on_toolbutton_add_clicked")
# Use the menubar's callback
component.get("MenuBar").on_menuitem_addtorrent_activate(data) component.get("MenuBar").on_menuitem_addtorrent_activate(data)
def on_toolbutton_remove_clicked(self, data): def on_toolbutton_remove_clicked(self, data):
log.debug("on_toolbutton_remove_clicked") log.debug("on_toolbutton_remove_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_remove_activate(data) component.get("MenuBar").on_menuitem_remove_activate(data)
def on_toolbutton_pause_clicked(self, data): def on_toolbutton_pause_clicked(self, data):
log.debug("on_toolbutton_pause_clicked") log.debug("on_toolbutton_pause_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_pause_activate(data) component.get("MenuBar").on_menuitem_pause_activate(data)
def on_toolbutton_resume_clicked(self, data): def on_toolbutton_resume_clicked(self, data):
log.debug("on_toolbutton_resume_clicked") log.debug("on_toolbutton_resume_clicked")
# Use the menubar's calbacks
component.get("MenuBar").on_menuitem_resume_activate(data) component.get("MenuBar").on_menuitem_resume_activate(data)
def on_toolbutton_preferences_clicked(self, data): def on_toolbutton_preferences_clicked(self, data):
log.debug("on_toolbutton_preferences_clicked") log.debug("on_toolbutton_preferences_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_preferences_activate(data) component.get("MenuBar").on_menuitem_preferences_activate(data)
def on_toolbutton_connectionmanager_clicked(self, data): def on_toolbutton_connectionmanager_clicked(self, data):
log.debug("on_toolbutton_connectionmanager_clicked") log.debug("on_toolbutton_connectionmanager_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_connectionmanager_activate(data) component.get("MenuBar").on_menuitem_connectionmanager_activate(data)
def on_toolbutton_queue_up_clicked(self, data): def on_toolbutton_queue_up_clicked(self, data):
@ -179,10 +136,3 @@ class ToolBar(component.Component):
def on_toolbutton_queue_down_clicked(self, data): def on_toolbutton_queue_down_clicked(self, data):
log.debug("on_toolbutton_queue_down_clicked") log.debug("on_toolbutton_queue_down_clicked")
component.get("MenuBar").on_menuitem_queue_down_activate(data) component.get("MenuBar").on_menuitem_queue_down_activate(data)
def _on_classic_mode(self, key, value):
w = self.window.get_builder().get_object("toolbutton_connectionmanager")
if value:
w.hide()
else:
w.show()