diff --git a/epour/Epour.py b/epour/Epour.py index c886e00..42013e7 100644 --- a/epour/Epour.py +++ b/epour/Epour.py @@ -26,8 +26,8 @@ parser = ArgumentParser(description="A BitTorrent client.") parser.add_argument( '-v', '--verbose', action="count", help="max is -vvv") parser.add_argument( - '--add-with-dialog', action="store_true", - help="Torrents to be added from arguments open a dialog" + '--disable-add-dialog', action="store_true", + help="Torrents to be added from arguments don't open a dialog" ) parser.add_argument( 'torrents', nargs="*", help="file path, magnet uri, or info hash", @@ -48,8 +48,12 @@ except dbus.exceptions.DBusException: pass else: for f in args.torrents: - print("Sending %s via dbus".format(f)) - dbo.AddTorrent(f, dbus_interface="net.launchpad.epour") + print("Sending {0} via dbus".format(f)) + if args.disable_add_dialog: + dbo.AddTorrentWithoutDialog( + f, dbus_interface="net.launchpad.epour") + else: + dbo.AddTorrent(f, dbus_interface="net.launchpad.epour") sys.exit() import os @@ -84,7 +88,8 @@ class Epour(object): self.session.load_torrents() for t in args.torrents: - if args.add_with_dialog: + if (not args.disable_add_dialog) and \ + self.conf.getboolean("Settings", "add_dialog_enabled"): self.gui.add_torrent(t) else: add_dict = { @@ -135,7 +140,7 @@ class Epour(object): ), "move_completed_enabled": str(False), "confirm_exit": str(False), - "dialog_add_dbus": str(True), + "add_dialog_enabled": str(True), "delete_original": str(False), "listen_low": str(0), "listen_high": str(0), @@ -193,9 +198,8 @@ class EpourDBus(dbus.service.Object): in_signature='s', out_signature='') def AddTorrent(self, t): self.log.info("Adding %s from dbus" % t) - #self.session.add_torrent(str(t)) try: - if self.conf.getboolean("Settings", "dialog_add_dbus"): + if self.conf.getboolean("Settings", "add_dialog_enabled"): self.gui.add_torrent(t) else: add_dict = { @@ -211,6 +215,24 @@ class EpourDBus(dbus.service.Object): except Exception: self.log.exception("Error while adding torrent from dbus") + @dbus.service.method(dbus_interface='net.launchpad.epour', + in_signature='s', out_signature='') + def AddTorrentWithoutDialog(self, t): + self.log.info("Adding %s from dbus" % t) + try: + add_dict = { + "save_path": self.conf.get("Settings", "storage_path"), + "flags": 592 + } + if os.path.isfile(t): + self.session.add_torrent_from_file(add_dict, t) + elif t.startswith("magnet:"): + self.session.add_torrent_from_magnet(add_dict, t) + else: + self.session.add_torrent_from_hash(add_dict, t) + except Exception: + self.log.exception("Error while adding torrent from dbus") + if __name__ == "__main__": efllog = logging.getLogger("efl") efllog.setLevel(logging.INFO) diff --git a/epour/gui/Preferences.py b/epour/gui/Preferences.py index 81f8d9f..abba72c 100644 --- a/epour/gui/Preferences.py +++ b/epour/gui/Preferences.py @@ -164,10 +164,11 @@ class PreferencesGeneral(PreferencesDialog): chk3 = Check(self) chk3.size_hint_align = ALIGN_LEFT - chk3.text = "Torrents to be added from dbus open a dialog" - chk3.state = conf.getboolean("Settings", "dialog_add_dbus") + chk3.text = ( + "Torrents to be added from dbus or command line open a dialog") + chk3.state = conf.getboolean("Settings", "add_dialog_enabled") chk3.callback_changed_add(lambda x: conf.set( - "Settings", "confirmations", str(bool(chk3.state)) + "Settings", "add_dialog_enabled", str(bool(chk3.state)) )) sep2 = Separator(self)