[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
"""
super(BaseDialog, self).__init__(
title="",
title=header,
parent=parent if parent else component.get("MainWindow").window,
flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT | gtk.DIALOG_NO_SEPARATOR,
buttons=buttons)
@ -80,11 +80,6 @@ class BaseDialog(gtk.Dialog):
image.set_alignment(0.5, 0.0)
hbox.pack_start(image, False, False)
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.set_use_markup(True)
tlabel.set_line_wrap(True)

View File

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

View File

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

View File

@ -1,39 +1,14 @@
#
# menubar.py
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com>
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
#
# 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.
#
# 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.
#
import os.path
import pygtk
pygtk.require('2.0')
@ -179,8 +154,6 @@ class MenuBar(component.Component):
"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("TorrentResumedEvent", self.on_torrentresumed_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).set_no_show_all(True)
if not self.config["classic_mode"]:
self.main_builder.get_object("separatormenuitem").show()
self.main_builder.get_object("menuitem_quitdaemon").show()
self.main_builder.get_object("separatormenuitem").set_visible(not self.config["classic_mode"])
self.main_builder.get_object("menuitem_quitdaemon").set_visible(not self.config["classic_mode"])
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
self.menu_torrent.show()
@ -503,12 +476,6 @@ class MenuBar(component.Component):
self.config["sidebar_show_trackers"] = widget.get_active()
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):
known_accounts_to_log = []
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
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):
if response == gtk.RESPONSE_NO:
# Set each changed config value in the core
self.gtkui_config["classic_mode"] = True
self.builder.get_object("radio_classic").set_active(True)
if response == gtk.RESPONSE_YES:
shutdown_daemon = (not client.is_classicmode() and
client.connected() and
client.is_localhost())
component.get("MainWindow").quit(shutdown=shutdown_daemon)
else:
client.disconnect()
component.stop()
self.builder.get_object("radio_thinclient").set_active(True)
self.gtkui_config["classic_mode"] = not new_gtkui_in_classic_mode
self.builder.get_object("radio_classic").set_active(self.gtkui_config["classic_mode"])
self.builder.get_object("radio_thinclient").set_active(not self.gtkui_config["classic_mode"])
dialog = dialogs.YesNoDialog(
_("Attention"),
_("Your current session will be stopped. Continue?")
_("Switching client mode..."),
_("Your current session will be stopped. Do you wish to continue?")
)
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):
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
pygtk.require('2.0')
import gtk
import gobject
import logging
import deluge.component as component
from deluge.ui.client import client
from deluge.configmanager import ConfigManager
log = logging.getLogger(__name__)
class ToolBar(component.Component):
def __init__(self):
component.Component.__init__(self, "ToolBar")
@ -75,14 +47,12 @@ class ToolBar(component.Component):
"find_menuitem"
]
self.config.register_set_function("classic_mode", self._on_classic_mode, True)
# Hide if necessary
self.visible(self.config["show_toolbar"])
def start(self):
if not self.config["classic_mode"]:
self.window.get_builder().get_object("toolbutton_connectionmanager").show()
self.window.get_builder().get_object("toolbutton_connectionmanager").set_visible(
not self.config["classic_mode"])
for widget in self.change_sensitivity:
self.window.get_builder().get_object(widget).set_sensitive(True)
@ -99,10 +69,8 @@ class ToolBar(component.Component):
self.config["show_toolbar"] = visible
def add_toolbutton(self, callback, label=None, image=None, stock=None,
tooltip=None):
def add_toolbutton(self, callback, label=None, image=None, stock=None, tooltip=None):
"""Adds a toolbutton to the toolbar"""
# Create the button
toolbutton = gtk.ToolButton()
if stock is not None:
toolbutton.set_stock_id(stock)
@ -110,16 +78,11 @@ class ToolBar(component.Component):
toolbutton.set_label(label)
if image is not None:
toolbutton.set_icon_widget(image)
# Set the tooltip
if tooltip is not None:
toolbutton.set_tooltip_text(tooltip)
# Connect the 'clicked' event callback
toolbutton.connect("clicked", callback)
# Append the button to the toolbar
self.toolbar.insert(toolbutton, -1)
# Show the new toolbutton
toolbutton.show_all()
return toolbutton
@ -130,7 +93,6 @@ class ToolBar(component.Component):
if position is not None:
self.toolbar.insert(sep, position)
else:
# Append the separator
self.toolbar.insert(sep, -1)
sep.show()
@ -141,35 +103,30 @@ class ToolBar(component.Component):
"""Removes a widget from the toolbar"""
self.toolbar.remove(widget)
### Callbacks ###
### Callbacks (Uses the menubar's callback) ###
def on_toolbutton_add_clicked(self, data):
log.debug("on_toolbutton_add_clicked")
# Use the menubar's callback
component.get("MenuBar").on_menuitem_addtorrent_activate(data)
def on_toolbutton_remove_clicked(self, data):
log.debug("on_toolbutton_remove_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_remove_activate(data)
def on_toolbutton_pause_clicked(self, data):
log.debug("on_toolbutton_pause_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_pause_activate(data)
def on_toolbutton_resume_clicked(self, data):
log.debug("on_toolbutton_resume_clicked")
# Use the menubar's calbacks
component.get("MenuBar").on_menuitem_resume_activate(data)
def on_toolbutton_preferences_clicked(self, data):
log.debug("on_toolbutton_preferences_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_preferences_activate(data)
def on_toolbutton_connectionmanager_clicked(self, data):
log.debug("on_toolbutton_connectionmanager_clicked")
# Use the menubar's callbacks
component.get("MenuBar").on_menuitem_connectionmanager_activate(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):
log.debug("on_toolbutton_queue_down_clicked")
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()