System tray updates.

This commit is contained in:
Andrew Resch 2007-11-10 06:00:23 +00:00
parent 3c9209dce4
commit 4dc601c845
8 changed files with 201 additions and 131 deletions

View File

@ -35,6 +35,7 @@
import cPickle
import gobject
import deluge.common
from deluge.log import LOG as log

View File

@ -194,6 +194,20 @@ def pause_torrent(torrent_ids):
except (AttributeError, socket.error):
set_core_uri(None)
def pause_all_torrents():
"""Pauses all torrents"""
try:
get_core().pause_all_torrents()
except (AttributeError, socket.error):
set_core_uri(None)
def resume_all_torrents():
"""Resumes all torrents"""
try:
get_core().resume_all_torrents()
except (AttributeError, socket.error):
set_core_uri(None)
def resume_torrent(torrent_ids):
"""Resume torrent_ids"""
try:

View File

@ -127,6 +127,9 @@ class ConnectionManager(component.Component):
uri[7:].split(":")[0] == "127.0.0.1":
# This is a localhost, so lets try to start it
port = uri[7:].split(":")[1]
# First add it to the list
self.add_host("localhost", port)
os.popen("deluged -p %s" % port)
# We need to wait for the host to start before connecting
while not self.test_online_status(uri):
@ -328,6 +331,18 @@ class ConnectionManager(component.Component):
# Get the port and concatenate the hostname string
hostname = hostname + ":" + str(port)
# Check to see if there is already an entry for this host and return
# if thats the case
self.hosts_liststore = []
def each_row(model, path, iter, data):
self.hosts_liststore.append(
model.get_value(iter, HOSTLIST_COL_URI))
self.liststore.foreach(each_row, None)
if hostname in self.hosts_liststore:
return
# Host isn't in the list, so lets add it
row = self.liststore.append()
self.liststore.set_value(row, HOSTLIST_COL_URI, hostname)
# Save the host list to file

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.2 on Wed Aug 8 23:27:43 2007 by markybob@peg-->
<!--Generated with glade3 3.2.2 on Fri Nov 9 18:22:43 2007 by andrew@fragment-->
<glade-interface>
<widget class="GtkDialog" id="remove_torrent_dlg">
<property name="title" translatable="yes">Remove Torrent</property>
@ -239,10 +239,12 @@
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Speed</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="window_position">GTK_WIN_POS_MOUSE</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="decorated">False</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox2">

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.2.2 on Fri Nov 9 15:44:33 2007 by andrew@fragment-->
<!--Generated with glade3 3.2.2 on Fri Nov 9 18:28:55 2007 by andrew@fragment-->
<glade-interface>
<widget class="GtkDialog" id="pref_dialog">
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -640,8 +640,8 @@
<widget class="GtkCheckButton" id="chk_utpex">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">µTorrent Peer-Exchange</property>
<property name="label" translatable="yes">µTorrent-PeX</property>
<property name="tooltip" translatable="yes">Peer Exchange</property>
<property name="label" translatable="yes">Peer Exchange</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="active">True</property>
@ -883,71 +883,40 @@ Either</property>
<property name="n_columns">2</property>
<property name="column_spacing">15</property>
<child>
<widget class="GtkLabel" id="label16">
<widget class="GtkSpinButton" id="spin_max_upload_slots_global">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Speed (KiB/s):</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label15">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Connections:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Slots:</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload slots for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_connections_global">
<widget class="GtkSpinButton" id="spin_max_upload">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property>
<property name="max_length">4</property>
<property name="tooltip" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="digits">1</property>
<property name="numeric">True</property>
<property name="update_policy">GTK_UPDATE_IF_VALID</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum download speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Download Speed (KiB/s):</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
@ -972,43 +941,74 @@ Either</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_upload">
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="digits">1</property>
<property name="numeric">True</property>
<property name="tooltip" translatable="yes">The maximum download speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Download Speed (KiB/s):</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_upload_slots_global">
<widget class="GtkSpinButton" id="spin_max_connections_global">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload slots for all torrents. Set -1 for unlimited.</property>
<property name="tooltip" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property>
<property name="max_length">4</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="update_policy">GTK_UPDATE_IF_VALID</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Slots:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label15">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Connections:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label16">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Speed (KiB/s):</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</widget>
</child>
</widget>
@ -1052,29 +1052,24 @@ Either</property>
<property name="n_columns">2</property>
<property name="column_spacing">15</property>
<child>
<widget class="GtkLabel" id="label18">
<widget class="GtkSpinButton" id="spin_max_upload_slots_per_torrent">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Slots:</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload slots per torrent. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label17">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Connections:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_connections_per_torrent">
<property name="visible">True</property>
@ -1092,19 +1087,24 @@ Either</property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_max_upload_slots_per_torrent">
<widget class="GtkLabel" id="label17">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip" translatable="yes">The maximum upload slots per torrent. Set -1 for unlimited.</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9000 1 10 10</property>
<property name="climb_rate">1</property>
<property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Connections:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label18">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Maximum Upload Slots:</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
@ -1356,15 +1356,33 @@ Either</property>
<property name="n_columns">2</property>
<property name="column_spacing">10</property>
<child>
<widget class="GtkEntry" id="txt_open_folder_location">
<widget class="GtkRadioButton" id="radio_open_folder_stock">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Open folder with:</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_toggle"/>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="radio_open_folder_custom">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Custom:</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">radio_open_folder_stock</property>
<signal name="toggled" handler="on_toggle"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
@ -1394,38 +1412,20 @@ Thunar</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="radio_open_folder_custom">
<widget class="GtkEntry" id="txt_open_folder_location">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Custom:</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">radio_open_folder_stock</property>
<signal name="toggled" handler="on_toggle"/>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkRadioButton" id="radio_open_folder_stock">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Open folder with:</property>
<property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_toggle"/>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</widget>
</child>
</widget>

View File

@ -17,7 +17,6 @@
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
<child>
@ -38,9 +37,8 @@
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem5">
<widget class="GtkSeparatorMenuItem" id="separatormenuitem2">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
<child>
@ -80,7 +78,6 @@
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
<child>
@ -118,11 +115,10 @@
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem4">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem1">
<widget class="GtkImageMenuItem" id="menuitem_quitdaemon">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Quit &amp; Shutdown Daemon</property>
@ -138,6 +134,11 @@
</child>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem5">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menuitem_quit">
<property name="visible">True</property>

View File

@ -45,13 +45,26 @@ class SystemTray(component.Component):
component.Component.__init__(self, "SystemTray")
self.window = component.get("MainWindow")
self.config = ConfigManager("gtkui.conf")
# List of widgets that need to be hidden when not connected to a host
self.hide_widget_list = [
"menuitem_add_torrent",
"menuitem_pause_all",
"menuitem_resume_all",
"menuitem_download_limit",
"menuitem_upload_limit",
"menuitem_quitdaemon",
"separatormenuitem1",
"separatormenuitem2",
"separatormenuitem3",
"separatormenuitem4"
]
self.config.register_set_function("enable_system_tray",
self.on_enable_system_tray_set)
def enable(self):
"""Enables the system tray icon."""
log.debug("Enabling the system tray icon..")
self.tray = gtk.status_icon_new_from_icon_name('deluge')
self.tray = gtk.status_icon_new_from_icon_name("deluge")
self.tray.connect("activate", self.on_tray_clicked)
self.tray.connect("popup-menu", self.on_tray_popup)
@ -73,18 +86,37 @@ class SystemTray(component.Component):
self.on_menuitem_quitdaemon_activate
})
self.tray_menu = self.tray_glade.get_widget("tray_menu")
self.tray_menu = self.tray_glade.get_widget("tray_menu")
self.tray_glade.get_widget("download-limit-image").set_from_file(
deluge.common.get_pixmap("downloading16.png"))
self.tray_glade.get_widget("upload-limit-image").set_from_file(
deluge.common.get_pixmap("seeding16.png"))
# Hide widgets now because we're not sure if we'll be connected to a
# host
for widget in self.hide_widget_list:
self.tray_glade.get_widget(widget).hide()
def start(self):
log.debug("SystemTray start..")
# Build the bandwidth speed limit menus
self.build_tray_bwsetsubmenu()
# Show widgets in the hide list because we've connected to a host
for widget in self.hide_widget_list:
self.tray_glade.get_widget(widget).show()
if self.config["enable_system_tray"]:
# Build the bandwidth speed limit menus
self.build_tray_bwsetsubmenu()
def stop(self):
log.debug("SystemTray stop..")
try:
# Hide widgets in hide list because we're not connected to a host
for widget in self.hide_widget_list:
self.tray_glade.get_widget(widget).hide()
except Exception, e:
log.debug("Unable to hide system tray menu widgets: %s", e)
def build_tray_bwsetsubmenu(self):
# Create the Download speed list sub-menu
submenu_bwdownset = self.build_menu_radio_list(
@ -111,10 +143,14 @@ class SystemTray(component.Component):
def disable(self):
"""Disables the system tray icon."""
log.debug("Disabling the system tray icon..")
self.tray.set_visible(False)
del self.tray
del self.tray_glade
del self.tray_menu
try:
self.tray.set_visible(False)
del self.tray
del self.tray_glade
del self.tray_menu
except Exception, e:
log.warning(
"Unable to disable system tray, probably wasn't enabled: %s", e)
def on_enable_system_tray_set(self, key, value):
"""Called whenever the 'enable_system_tray' config key is modified"""

View File

@ -73,6 +73,7 @@ class ToolBar(component.Component):
def start(self):
for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(True)
self.update_buttons()
gobject.idle_add(self.update_buttons)
def stop(self):