From 770cfa0a07c0d0484bac131fa3057937d50d2490 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 9 Jul 2007 02:50:20 +0000 Subject: [PATCH] Update to my branch.. --- deluge/src/config.py | 8 +++- deluge/src/core.py | 52 ++++++++++++++++++--- deluge/src/gtkui.py | 62 +++++++++++++++++++++++++ deluge/src/gtkui_mainwindow.py | 84 ++++++++++++++++++++++++++++++++++ deluge/src/main.py | 13 +----- deluge/src/torrent.py | 42 +++++++++++++++++ deluge/src/ui.py | 28 ++++++++++-- setup.py | 12 +++-- 8 files changed, 273 insertions(+), 28 deletions(-) create mode 100644 deluge/src/gtkui.py create mode 100644 deluge/src/gtkui_mainwindow.py create mode 100644 deluge/src/torrent.py diff --git a/deluge/src/config.py b/deluge/src/config.py index 4b7af2d1d..37eb13c62 100644 --- a/deluge/src/config.py +++ b/deluge/src/config.py @@ -95,4 +95,10 @@ class Config: return value except KeyError: log.warning("Key does not exist, returning None") - return None + return + + def __getitem__(self, key): + return self.config[key] + + def __setitem__(self, key, value): + self.config[key] = value diff --git a/deluge/src/core.py b/deluge/src/core.py index 78d706f8d..ea7fc4e8f 100644 --- a/deluge/src/core.py +++ b/deluge/src/core.py @@ -47,14 +47,19 @@ except: dbus_imported = False else: dbus_imported = True import gobject +import libtorrent as lt from deluge.config import Config import deluge.common +from deluge.torrent import Torrent # Get the logger log = logging.getLogger("deluge") DEFAULT_PREFS = { + "listen_ports": [6881, 6891], + "download_location": "/home/andrew/Downloads", + "compact_allocation": True } class Core(dbus.service.Object): @@ -64,11 +69,44 @@ class Core(dbus.service.Object): bus=dbus.SessionBus()) dbus.service.Object.__init__(self, bus_name, path) self.config = Config("core.conf", DEFAULT_PREFS) - log.debug("Starting main loop..") - loop = gobject.MainLoop() - loop.run() - - @dbus.service.method("org.deluge_torrent.Deluge") - def test(self): - print "test" + # Setup the libtorrent session and listen on the configured ports + log.debug("Starting libtorrent session..") + self.session = lt.session() + log.debug("Listening on %i-%i", self.config.get("listen_ports")[0], + self.config.get("listen_ports")[1]) + self.session.listen_on(self.config.get("listen_ports")[0], + self.config.get("listen_ports")[1]) + + log.debug("Starting main loop..") + self.loop = gobject.MainLoop() + self.loop.run() + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", + in_signature="s", out_signature="") + def add_torrent_file(self, _filename): + """Adds a torrent file to the libtorrent session + """ + log.info("Adding torrent: %s", _filename) + torrent = Torrent(filename=_filename) + self.session.add_torrent(torrent.torrent_info, + self.config["download_location"], + self.config["compact_allocation"]) + + @dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", + in_signature="s", out_signature="") + def add_torrent_url(self, _url): + """Adds a torrent from url to the libtorrent session + """ + log.info("Adding torrent: %s", _url) + torrent = Torrent(url=_url) + self.session.add_torrent(torrent.torrent_info, + self.config["download_location"], + self.config["compact_allocation"]) + + + @dbus.service.method("org.deluge_torrent.Deluge") + def shutdown(self): + log.info("Shutting down core..") + self.loop.quit() + diff --git a/deluge/src/gtkui.py b/deluge/src/gtkui.py new file mode 100644 index 000000000..13837d689 --- /dev/null +++ b/deluge/src/gtkui.py @@ -0,0 +1,62 @@ +# +# gtkui.py +# +# Copyright (C) Andrew Resch 2007 +# +# 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 2 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 logging + +import pygtk +pygtk.require('2.0') +import gtk, gtk.glade +import pkg_resources + +import gtkui_mainwindow + +# Get the logger +log = logging.getLogger("deluge") + +class GtkUI: + def __init__(self, core): + # Get the core proxy object from the args + self.core = core + + # Get the glade file for the main window + self.main_glade = gtk.glade.XML( + pkg_resources.resource_filename("deluge", "glade/main_window.glade")) + + # Initialize the main window + self.main_window = gtkui_mainwindow.GtkUIMainWindow(self.main_glade) + + # Show the main window + self.main_window.show() + + # Start the gtk main loop + gtk.main() diff --git a/deluge/src/gtkui_mainwindow.py b/deluge/src/gtkui_mainwindow.py new file mode 100644 index 000000000..b63d09e20 --- /dev/null +++ b/deluge/src/gtkui_mainwindow.py @@ -0,0 +1,84 @@ +# +# gtkui_mainwindow.py +# +# Copyright (C) Andrew Resch 2007 +# +# 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 2 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 logging + +import pygtk +pygtk.require('2.0') +import gtk, gtk.glade + +# Get the logger +log = logging.getLogger("deluge") + +class GtkUIMainWindow: + def __init__(self, glade_xml): + self.main_glade = glade_xml + self.window = self.main_glade.get_widget("main_window") + + # Initialize various components of the gtkui + self.menubar = GtkUIMainWindow_MenuBar(self) + + def show(self): + self.window.show_all() + + def hide(self): + self.window.hide() + + def quit(self): + self.hide() + gtk.main_quit() + +class GtkUIMainWindow_MenuBar: + def __init__(self, mainwindow): + self.mainwindow = mainwindow + + ### Connect Signals ### + self.mainwindow.main_glade.signal_autoconnect({ + ## File Menu + "on_addtorrent_menuitem_activate": self.on_addtorrent_menuitem_activate, + "on_addurl_menuitem_activate": self.on_addurl_menuitem_activate, + "on_clearcompleted_menuitem_activate": \ + self.on_clearcompleted_menuitem_activate, + "on_quit_menuitem_activate": self.on_quit_menuitem_activate + }) + + ### Callbacks ### + def on_addtorrent_menuitem_activate(self, data=None): + log.debug("on_addtorrent_menuitem_activate") + def on_addurl_menuitem_activate(self, data=None): + log.debug("on_addurl_menuitem_activate") + def on_clearcompleted_menuitem_activate(self, data=None): + log.debug("on_clearcompleted_menuitem_activate") + def on_quit_menuitem_activate(self, data=None): + log.debug("on_quit_menuitem_activate") + self.mainwindow.quit() diff --git a/deluge/src/main.py b/deluge/src/main.py index e0663ea4d..87bc8eb71 100644 --- a/deluge/src/main.py +++ b/deluge/src/main.py @@ -40,7 +40,7 @@ import signal from optparse import OptionParser from deluge.daemon import Daemon -from deluge.ui import Ui +from deluge.ui import UI import deluge.common # Setup the logger @@ -88,13 +88,4 @@ def main(): # Start the UI if options.ui: log.info("Starting ui..") - ui = Ui() - - # Stop Deluge - log.info ("Stopping Deluge..") - - # Kill the daemon - if pid: - log.info("Killing daemon..") - os.kill(pid, signal.SIGTERM) - + ui = UI() diff --git a/deluge/src/torrent.py b/deluge/src/torrent.py new file mode 100644 index 000000000..1c4f6592c --- /dev/null +++ b/deluge/src/torrent.py @@ -0,0 +1,42 @@ +# +# torrent.py +# +# Copyright (C) Andrew Resch 2007 +# +# 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 2 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 libtorrent as lt + +class Torrent: + def __init__(self, filename=None, url=None): + # Load the torrent file + if filename is not None: + torrent_file = lt.bdecode(open(filename, 'rb').read()) + self.torrent_info = lt.torrent_info(torrent_file) + diff --git a/deluge/src/ui.py b/deluge/src/ui.py index 47d64a2a1..8fb13c189 100644 --- a/deluge/src/ui.py +++ b/deluge/src/ui.py @@ -46,18 +46,36 @@ try: except: dbus_imported = False else: dbus_imported = True +import time + +from deluge.config import Config + # Get the logger log = logging.getLogger("deluge") -class Ui: +DEFAULT_PREFS = { + "selected_ui": "gtk" +} + +class UI: def __init__(self): - log.debug("Ui init..") + log.debug("UI init..") + self.config = Config("ui.conf", DEFAULT_PREFS) log.debug("Getting core proxy object from DBUS..") # Get the proxy object from DBUS bus = dbus.SessionBus() proxy = bus.get_object("org.deluge_torrent.Deluge", "/org/deluge_torrent/Core") self.core = dbus.Interface(proxy, "org.deluge_torrent.Deluge") - log.debug("Got core proxy object..") - # Test the interface.. this calls test() in Core - self.core.test() + log.debug("Got core proxy object..") + + if self.config["selected_ui"] == "gtk": + log.info("Starting GtkUI..") + from deluge.gtkui import GtkUI + ui = GtkUI(self.core) + + # Test the interface.. +# self.core.add_torrent_file("/home/andrew/Downloads/test.torrent", None) + # time.sleep(3) + # Shutdown the core thus stopping the daemon process +# self.core.shutdown() diff --git a/setup.py b/setup.py index 1391ae213..dc02e4df1 100644 --- a/setup.py +++ b/setup.py @@ -59,12 +59,15 @@ _libraries = [ 'boost_filesystem', 'boost_date_time', 'boost_thread', + 'boost_python', 'z', 'pthread', 'ssl' ] -_sources = glob.glob("./libtorrent/src/*.cpp") + glob.glob("./libtorrent/src/kademelia/*.cpp") + glob.glob("./libtorrent/bindings/python/src/*.cpp") +_sources = glob.glob("./libtorrent/src/*.cpp") + \ + glob.glob("./libtorrent/src/kademlia/*.cpp") + \ + glob.glob("./libtorrent/bindings/python/src/*.cpp") # Remove file_win.cpp as it is only for Windows builds for source in _sources: @@ -83,8 +86,8 @@ libtorrent = Extension( # Main setup _data_files = [ - # ('share/deluge/glade', glob.glob("share/deluge/glade/*.glade")), - # ('share/deluge/pixmaps', glob.glob('share/deluge/pixmaps/*.png')), + ('deluge/glade', glob.glob("deluge/glade/*.glade")), + ('deluge/pixmaps', glob.glob('deluge/pixmaps/*.png')), ('share/applications' , ["deluge/share/applications/deluge.desktop"]), ('share/pixmaps' , ["deluge/share/pixmaps/deluge.xpm"]) ] @@ -94,7 +97,8 @@ setup( fullname = "Deluge Bittorent Client", version = "0.6", author = "Zach Tibbitts, Alon Zakai, Marcos Pinto, Andrew Resch", - author_email = "zach@collegegeek.org, kripkensteiner@gmail.com, marcospinto@dipconsultants.com, andrewresch@gmail.com", + author_email = "zach@collegegeek.org, kripkensteiner@gmail.com, \ + marcospinto@dipconsultants.com, andrewresch@gmail.com", description = "GTK+ bittorrent client", url = "http://deluge-torrent.org", license = "GPLv2",