Implement 'Classic Mode'

This commit is contained in:
Andrew Resch 2008-06-23 00:12:30 +00:00
commit 48d18e3c52
8 changed files with 88 additions and 49 deletions

1
TODO
View file

@ -3,7 +3,6 @@ For 0.6 release:
of deluge. of deluge.
* Update checking * Update checking
* Translations * Translations
* Implement 'Classic' mode
* Add progress bars for downloading and importing lists instead of hanging (blocklist) * Add progress bars for downloading and importing lists instead of hanging (blocklist)
After 0.6 release: After 0.6 release:

View file

@ -117,6 +117,18 @@ class ConnectionManager(component.Component):
self.hostlist.get_selection().connect("changed", self.hostlist.get_selection().connect("changed",
self.on_selection_changed) self.on_selection_changed)
# If classic mode is set, we just start up a localhost daemon and connect to it
if self.gtkui_config["classic_mode"]:
uri = "http://localhost:58846"
os.popen("deluged -p 58846")
time.sleep(0.1)
# We need to wait for the host to start before connecting
while not self.test_online_status(uri):
time.sleep(0.01)
client.set_core_uri(uri)
self.hide()
return
self._update() self._update()
# Auto connect to a host if applicable # Auto connect to a host if applicable

View file

@ -96,7 +96,8 @@ DEFAULT_PREFS = {
"autoadd_queued": False, "autoadd_queued": False,
"autoadd_enable": False, "autoadd_enable": False,
"autoadd_location": "", "autoadd_location": "",
"choose_directory_dialog_path": deluge.common.get_default_download_dir() "choose_directory_dialog_path": deluge.common.get_default_download_dir(),
"classic_mode": False
} }
class GtkUI: class GtkUI:
@ -164,7 +165,7 @@ class GtkUI:
# Show the connection manager # Show the connection manager
self.connectionmanager = ConnectionManager() self.connectionmanager = ConnectionManager()
if self.config["show_connection_manager_on_start"]: if self.config["show_connection_manager_on_start"] and not self.config["classic_mode"]:
self.connectionmanager.show() self.connectionmanager.show()
# Start the gtk main loop # Start the gtk main loop

View file

@ -57,6 +57,7 @@ class MainWindow(component.Component):
self.window = self.main_glade.get_widget("main_window") self.window = self.main_glade.get_widget("main_window")
self.window.set_icon(deluge.common.get_logo(32)) self.window.set_icon(deluge.common.get_logo(32))
self.vpaned = self.main_glade.get_widget("vpaned") self.vpaned = self.main_glade.get_widget("vpaned")
# Load the window state # Load the window state
self.load_window_state() self.load_window_state()
@ -88,10 +89,18 @@ class MainWindow(component.Component):
def hide(self): def hide(self):
component.pause("TorrentView") component.pause("TorrentView")
component.pause("StatusBar") component.pause("StatusBar")
# Store the x, y positions for when we restore the window
self.window_x_pos = self.window.get_position()[0]
self.window_y_pos = self.window.get_position()[1]
self.window.hide() self.window.hide()
def present(self): def present(self):
# Restore the proper x,y coords for the window prior to showing it
self.config["window_x_pos"] = self.window_x_pos
self.config["window_y_pos"] = self.window_y_pos
self.window.present() self.window.present()
self.load_window_state()
def active(self): def active(self):
"""Returns True if the window is active, False if not.""" """Returns True if the window is active, False if not."""
@ -122,7 +131,7 @@ class MainWindow(component.Component):
self.config["window_height"] - self.config["window_pane_position"]) self.config["window_height"] - self.config["window_pane_position"])
def on_window_configure_event(self, widget, event): def on_window_configure_event(self, widget, event):
if self.config["window_maximized"] == False: if self.config["window_maximized"] == False and self.visible:
self.config.set("window_x_pos", self.window.get_position()[0]) self.config.set("window_x_pos", self.window.get_position()[0])
self.config.set("window_y_pos", self.window.get_position()[1]) self.config.set("window_y_pos", self.window.get_position()[1])
self.config.set("window_width", event.width) self.config.set("window_width", event.width)
@ -131,6 +140,7 @@ class MainWindow(component.Component):
def on_window_state_event(self, widget, event): def on_window_state_event(self, widget, event):
if event.changed_mask & gtk.gdk.WINDOW_STATE_MAXIMIZED: if event.changed_mask & gtk.gdk.WINDOW_STATE_MAXIMIZED:
if event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED: if event.new_window_state & gtk.gdk.WINDOW_STATE_MAXIMIZED:
log.debug("pos: %s", self.window.get_position())
self.config.set("window_maximized", True) self.config.set("window_maximized", True)
else: else:
self.config.set("window_maximized", False) self.config.set("window_maximized", False)

View file

@ -39,6 +39,7 @@ import pkg_resources
import deluge.component as component import deluge.component as component
from deluge.ui.client import aclient as client from deluge.ui.client import aclient as client
import deluge.common as common import deluge.common as common
from deluge.configmanager import ConfigManager
from deluge.log import LOG as log from deluge.log import LOG as log
@ -47,6 +48,8 @@ class MenuBar(component.Component):
log.debug("MenuBar init..") log.debug("MenuBar init..")
component.Component.__init__(self, "MenuBar") component.Component.__init__(self, "MenuBar")
self.window = component.get("MainWindow") self.window = component.get("MainWindow")
self.config = ConfigManager("gtkui.conf")
# Get the torrent menu from the glade file # Get the torrent menu from the glade file
self.torrentmenu_glade = gtk.glade.XML( self.torrentmenu_glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
@ -145,6 +148,12 @@ class MenuBar(component.Component):
self.change_sensitivity = [ self.change_sensitivity = [
"menuitem_addtorrent" "menuitem_addtorrent"
] ]
if self.config["classic_mode"]:
# We need to remove the 'quit and shutdown daemon' menu item
self.window.main_glade.get_widget("menuitem_quitdaemon").hide()
self.window.main_glade.get_widget("separatormenuitem").hide()
self.window.main_glade.get_widget("menuitem_connectionmanager").hide()
def start(self): def start(self):
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
@ -166,9 +175,10 @@ class MenuBar(component.Component):
# 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()
self.window.main_glade.get_widget("separatormenuitem").show() if not self.config["classic_mode"]:
self.window.main_glade.get_widget("menuitem_quitdaemon").show() self.window.main_glade.get_widget("separatormenuitem").show()
self.window.main_glade.get_widget("menuitem_quitdaemon").show()
def stop(self): def stop(self):
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
@ -201,6 +211,8 @@ class MenuBar(component.Component):
def on_menuitem_quit_activate(self, data=None): def on_menuitem_quit_activate(self, data=None):
log.debug("on_menuitem_quit_activate") log.debug("on_menuitem_quit_activate")
if self.config["classic_mode"]:
client.shutdown()
self.window.quit() self.window.quit()
## Edit Menu ## ## Edit Menu ##

View file

@ -382,6 +382,8 @@ class Preferences(component.Component):
self.gtkui_config["start_in_tray"]) self.gtkui_config["start_in_tray"])
self.glade.get_widget("chk_lock_tray").set_active( self.glade.get_widget("chk_lock_tray").set_active(
self.gtkui_config["lock_tray"]) self.gtkui_config["lock_tray"])
self.glade.get_widget("chk_classic_mode").set_active(
self.gtkui_config["classic_mode"])
## Other tab ## ## Other tab ##
self.glade.get_widget("chk_new_releases").set_active( self.glade.get_widget("chk_new_releases").set_active(
@ -514,6 +516,8 @@ class Preferences(component.Component):
.hexdigest() .hexdigest()
if passhex != "c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7": if passhex != "c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7":
new_gtkui_config["tray_password"] = passhex new_gtkui_config["tray_password"] = passhex
new_gtkui_config["classic_mode"] = \
self.glade.get_widget("chk_classic_mode").get_active()
## Other tab ## ## Other tab ##
new_gtkui_config["check_new_releases"] = \ new_gtkui_config["check_new_releases"] = \

View file

@ -77,6 +77,7 @@ class SystemTray(component.Component):
self.tray_glade = gtk.glade.XML( self.tray_glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/tray_menu.glade")) "glade/tray_menu.glade"))
try: try:
self.tray = gtk.status_icon_new_from_icon_name("deluge") self.tray = gtk.status_icon_new_from_icon_name("deluge")
except: except:
@ -107,6 +108,12 @@ class SystemTray(component.Component):
deluge.common.get_pixmap("downloading16.png")) deluge.common.get_pixmap("downloading16.png"))
self.tray_glade.get_widget("upload-limit-image").set_from_file( self.tray_glade.get_widget("upload-limit-image").set_from_file(
deluge.common.get_pixmap("seeding16.png")) deluge.common.get_pixmap("seeding16.png"))
if self.config["classic_mode"]:
self.hide_widget_list.remove("menuitem_quitdaemon")
self.hide_widget_list.remove("separatormenuitem4")
self.tray_glade.get_widget("menuitem_quitdaemon").hide()
self.tray_glade.get_widget("separatormenuitem4").hide()
if client.get_core_uri() == None: if client.get_core_uri() == None:
# Hide menu widgets because we're not connected to a host. # Hide menu widgets because we're not connected to a host.
@ -232,16 +239,14 @@ class SystemTray(component.Component):
def on_tray_clicked(self, icon): def on_tray_clicked(self, icon):
"""Called when the tray icon is left clicked.""" """Called when the tray icon is left clicked."""
if self.window.visible(): if self.config["lock_tray"]:
if self.window.active(): if not self.unlock_tray():
self.window.hide() return
else:
self.window.present() if self.window.active():
self.window.hide()
else: else:
if self.config["lock_tray"] == True: self.window.present()
self.unlock_tray("mainwinshow")
else:
self.window.show()
def on_tray_popup(self, status_icon, button, activate_time): def on_tray_popup(self, status_icon, button, activate_time):
"""Called when the tray icon is right clicked.""" """Called when the tray icon is right clicked."""
@ -256,10 +261,10 @@ class SystemTray(component.Component):
def on_menuitem_show_deluge_activate(self, menuitem): def on_menuitem_show_deluge_activate(self, menuitem):
log.debug("on_menuitem_show_deluge_activate") log.debug("on_menuitem_show_deluge_activate")
if menuitem.get_active() and not self.window.visible(): if menuitem.get_active() and not self.window.visible():
if self.config["lock_tray"] == True: if self.config["lock_tray"]:
self.unlock_tray("mainwinshow") if not self.unlock_tray():
else: return
self.window.show() self.window.present()
elif not menuitem.get_active() and self.window.visible(): elif not menuitem.get_active() and self.window.visible():
self.window.hide() self.window.hide()
@ -278,25 +283,23 @@ class SystemTray(component.Component):
def on_menuitem_quit_activate(self, menuitem): def on_menuitem_quit_activate(self, menuitem):
log.debug("on_menuitem_quit_activate") log.debug("on_menuitem_quit_activate")
if self.window.visible(): if self.config["lock_tray"]:
self.window.quit() if not self.unlock_tray():
else: return
if self.config["lock_tray"] == True:
self.unlock_tray("quitui")
else:
self.window.quit()
if self.config["classic_mode"]:
client.shutdown()
self.window.quit()
def on_menuitem_quitdaemon_activate(self, menuitem): def on_menuitem_quitdaemon_activate(self, menuitem):
log.debug("on_menuitem_quitdaemon_activate") log.debug("on_menuitem_quitdaemon_activate")
if self.window.visible(): if self.config["lock_tray"]:
self.window.quit() if not self.unlock_tray():
client.shutdown() return
else:
if self.config["lock_tray"] == True: client.shutdown()
self.unlock_tray("quitdaemon") self.window.quit()
else:
self.window.quit()
client.shutdown()
def tray_setbwdown(self, widget, data=None): def tray_setbwdown(self, widget, data=None):
self.setbwlimit(widget, _("Download"), "max_download_speed", self.setbwlimit(widget, _("Download"), "max_download_speed",
@ -328,6 +331,8 @@ class SystemTray(component.Component):
def unlock_tray(self, comingnext, is_showing_dlg=[False]): def unlock_tray(self, comingnext, is_showing_dlg=[False]):
import sha import sha
log.debug("Show tray lock dialog") log.debug("Show tray lock dialog")
result = False
if is_showing_dlg[0]: if is_showing_dlg[0]:
return return
is_showing_dlg[0] = True is_showing_dlg[0] = True
@ -353,18 +358,9 @@ window, please enter your password"))
if tray_lock.run() == gtk.RESPONSE_ACCEPT: if tray_lock.run() == gtk.RESPONSE_ACCEPT:
if self.config["tray_password"] == sha.new(entered_pass.get_text())\ if self.config["tray_password"] == sha.new(entered_pass.get_text())\
.hexdigest(): .hexdigest():
if comingnext == "mainwinshow": result = True
log.debug("Showing main window via tray")
self.window.show()
elif comingnext == "quitdaemon":
client.shutdown()
self.window.hide()
self.window.quit()
elif comingnext == "quitui":
log.debug("Quiting UI via tray")
self.window.hide()
self.window.quit()
tray_lock.destroy() tray_lock.destroy()
is_showing_dlg[0] = False is_showing_dlg[0] = False
return True
return result

View file

@ -40,6 +40,7 @@ import deluge.component as component
from deluge.log import LOG as log from deluge.log import LOG as log
from deluge.common import TORRENT_STATE from deluge.common import TORRENT_STATE
from deluge.ui.client import aclient as client from deluge.ui.client import aclient as client
from deluge.configmanager import ConfigManager
class ToolBar(component.Component): class ToolBar(component.Component):
def __init__(self): def __init__(self):
@ -47,6 +48,7 @@ class ToolBar(component.Component):
log.debug("ToolBar Init..") log.debug("ToolBar Init..")
self.window = component.get("MainWindow") self.window = component.get("MainWindow")
self.toolbar = self.window.main_glade.get_widget("toolbar") self.toolbar = self.window.main_glade.get_widget("toolbar")
self.config = ConfigManager("gtkui.conf")
### Connect Signals ### ### Connect Signals ###
self.window.main_glade.signal_autoconnect({ self.window.main_glade.signal_autoconnect({
"on_toolbutton_add_clicked": self.on_toolbutton_add_clicked, "on_toolbutton_add_clicked": self.on_toolbutton_add_clicked,
@ -74,6 +76,9 @@ class ToolBar(component.Component):
tb_remove.set_menu( tb_remove.set_menu(
component.get("MenuBar").torrentmenu_glade.get_widget("remove_torrent_menu")) component.get("MenuBar").torrentmenu_glade.get_widget("remove_torrent_menu"))
if self.config["classic_mode"]:
self.window.main_glade.get_widget("toolbutton_connectionmanager").hide()
def start(self): def start(self):
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(True) self.window.main_glade.get_widget(widget).set_sensitive(True)