def __add_button_clicked(self, button): download_list = DownloadList() self.download = download_list.add_download(self.uri_entry.get_text(), self.download_filechooserbutton.get_current_folder(), self.headers) self.clipboard.disconnect(self.owner_change_id) self.dialog.destroy()
def __init(self, *args): gobject.GObject.__init__(self) self.config = config.Configuration() self.download_list = DownloadList() self.download_list.connect("download-added", self.__download_added) metalink.USER_AGENT = "%s %s" % (NAME, VERSION) self.__set_proxies()
def run(self): self.__init_i18n() [args, headers] = self.__get_options() gnome.init(NAME, VERSION) gtk.gdk.threads_init() gtk.window_set_default_icon_list(*gui.get_icon_list([16, 22, 24, 32])) self.download_list = DownloadList() self.download_manager = DownloadManager() self.dbus_service = dbus_service.DBusService() # If the DBus service is already running, add downloads using it if not self.dbus_service.register(): for uri in args: self.dbus_service.download_manager.AddDownload( uri, os.getcwd(), headers) return 0 self.dbus_service.register_object(dbus_service.DOWNLOAD_MGR_OBJ_PATH, self.download_list) self.main_window = MainWindow(self.config, self.download_list) self.dbus_service.register_object(dbus_service.MAIN_WINDOW_OBJ_PATH, self.main_window) if self.config.show_main_window: self.main_window.window.show() self.status_icon = TrayIcon(self.main_window) if not self.config.show_status_icon: self.status_icon.icon.hide_all() sys.excepthook = self.main_window.on_unhandled_exception self.download_list.load_from_xml() for uri in args: if self.config.ask_for_location: add = AddDownloadDialog(uri, headers) add.dialog.run() else: self.download_list.add_download(uri, self.config.default_folder, headers) gtk.main()
def run(self): self.__init_i18n() [args, headers] = self.__get_options() gnome.init(NAME, VERSION) gtk.gdk.threads_init() gtk.window_set_default_icon_list(*gui.get_icon_list([16, 22, 24, 32])) self.download_list = DownloadList() self.download_manager = DownloadManager() self.dbus_service = dbus_service.DBusService() # If the DBus service is already running, add downloads using it if not self.dbus_service.register(): for uri in args: self.dbus_service.download_manager.AddDownload(uri, os.getcwd(), headers) return 0 self.dbus_service.register_object(dbus_service.DOWNLOAD_MGR_OBJ_PATH, self.download_list) self.main_window = MainWindow(self.config, self.download_list) self.dbus_service.register_object(dbus_service.MAIN_WINDOW_OBJ_PATH, self.main_window) if self.config.show_main_window: self.main_window.window.show() self.status_icon = TrayIcon(self.main_window) if not self.config.show_status_icon: self.status_icon.icon.hide_all() sys.excepthook = self.main_window.on_unhandled_exception self.download_list.load_from_xml() for uri in args: if self.config.ask_for_location: add = AddDownloadDialog(uri, headers) add.dialog.run() else: self.download_list.add_download(uri, self.config.default_folder, headers) gtk.main()
class Application: def run(self): self.__init_i18n() [args, headers] = self.__get_options() gnome.init(NAME, VERSION) gtk.gdk.threads_init() gtk.window_set_default_icon_list(*gui.get_icon_list([16, 22, 24, 32])) self.download_list = DownloadList() self.download_manager = DownloadManager() self.dbus_service = dbus_service.DBusService() # If the DBus service is already running, add downloads using it if not self.dbus_service.register(): for uri in args: self.dbus_service.download_manager.AddDownload(uri, os.getcwd(), headers) return 0 self.dbus_service.register_object(dbus_service.DOWNLOAD_MGR_OBJ_PATH, self.download_list) self.main_window = MainWindow(self.config, self.download_list) self.dbus_service.register_object(dbus_service.MAIN_WINDOW_OBJ_PATH, self.main_window) if self.config.show_main_window: self.main_window.window.show() self.status_icon = TrayIcon(self.main_window) if not self.config.show_status_icon: self.status_icon.icon.hide_all() sys.excepthook = self.main_window.on_unhandled_exception self.download_list.load_from_xml() for uri in args: if self.config.ask_for_location: add = AddDownloadDialog(uri, headers) add.dialog.run() else: self.download_list.add_download(uri, self.config.default_folder, headers) gtk.main() def __init_i18n(self): gettext.bindtextdomain(NAME.lower(), LOCALE_DIR) gettext.textdomain(NAME.lower()) #locale.bindtextdomain(NAME.lower(), LOCALE_DIR) #locale.textdomain(NAME.lower()) def __get_options(self): """Get command line options.""" try: opts, args = getopt.getopt(sys.argv[1:], "dh", ["debug", "header=", "help"]) except getopt.GetoptError: opts = [] args = sys.argv[1:] debug = False headers = {} for o, a in opts: if o in ("-d", "--debug"): debug = True elif o in ("--header"): kv = a.split("=") if (len(kv) == 2): headers[kv[0]] = kv[1] elif o in ("-h", "--help"): self.__print_usage() self.config = config.Configuration(debug) return [args, headers] def __print_usage(self): """Output usage information and exit.""" print _("Usage: %s [OPTION]... [URI]...") % (sys.argv[0]) print "" print _("OPTIONS:") print " -d, --debug %s" % (_("enable debug messages")) print " -h, --help %s" % (_("show this help message and exit")) sys.exit()
class Application: def run(self): self.__init_i18n() [args, headers] = self.__get_options() gnome.init(NAME, VERSION) gtk.gdk.threads_init() gtk.window_set_default_icon_list(*gui.get_icon_list([16, 22, 24, 32])) self.download_list = DownloadList() self.download_manager = DownloadManager() self.dbus_service = dbus_service.DBusService() # If the DBus service is already running, add downloads using it if not self.dbus_service.register(): for uri in args: self.dbus_service.download_manager.AddDownload( uri, os.getcwd(), headers) return 0 self.dbus_service.register_object(dbus_service.DOWNLOAD_MGR_OBJ_PATH, self.download_list) self.main_window = MainWindow(self.config, self.download_list) self.dbus_service.register_object(dbus_service.MAIN_WINDOW_OBJ_PATH, self.main_window) if self.config.show_main_window: self.main_window.window.show() self.status_icon = TrayIcon(self.main_window) if not self.config.show_status_icon: self.status_icon.icon.hide_all() sys.excepthook = self.main_window.on_unhandled_exception self.download_list.load_from_xml() for uri in args: if self.config.ask_for_location: add = AddDownloadDialog(uri, headers) add.dialog.run() else: self.download_list.add_download(uri, self.config.default_folder, headers) gtk.main() def __init_i18n(self): gettext.bindtextdomain(NAME.lower(), LOCALE_DIR) gettext.textdomain(NAME.lower()) #locale.bindtextdomain(NAME.lower(), LOCALE_DIR) #locale.textdomain(NAME.lower()) def __get_options(self): """Get command line options.""" try: opts, args = getopt.getopt(sys.argv[1:], "dh", ["debug", "header=", "help"]) except getopt.GetoptError: opts = [] args = sys.argv[1:] debug = False headers = {} for o, a in opts: if o in ("-d", "--debug"): debug = True elif o in ("--header"): kv = a.split("=") if (len(kv) == 2): headers[kv[0]] = kv[1] elif o in ("-h", "--help"): self.__print_usage() self.config = config.Configuration(debug) return [args, headers] def __print_usage(self): """Output usage information and exit.""" print _("Usage: %s [OPTION]... [URI]...") % (sys.argv[0]) print "" print _("OPTIONS:") print " -d, --debug %s" % (_("enable debug messages")) print " -h, --help %s" % (_("show this help message and exit")) sys.exit()
class DownloadManager(gobject.GObject): """Singleton handling the downloads""" __gsignals__ = {"download-started": (gobject.SIGNAL_RUN_LAST, None, (object,))} instance = None def __new__(type, *args): if DownloadManager.instance is None: DownloadManager.instance = gobject.GObject.__new__(type) DownloadManager.instance.__init(*args) return DownloadManager.instance def __init(self, *args): gobject.GObject.__init__(self) self.config = config.Configuration() self.download_list = DownloadList() self.download_list.connect("download-added", self.__download_added) metalink.USER_AGENT = "%s %s" % (NAME, VERSION) self.__set_proxies() def __set_proxies(self): if self.config.proxy_mode == "gnome": if self.config.use_http_proxy: if self.config.use_http_proxy_auth: self.set_proxy("http", "http://%s:%s@%s:%s" % \ (self.config.http_proxy_user, self.config.http_proxy_pass, self.config.http_proxy_host, self.config.http_proxy_port)) if self.config.use_same_proxy: self.set_proxy("https", "https://%s:%s@%s:%s" % \ (self.config.http_proxy_user, self.config.http_proxy_pass, self.config.proxy_https_host, self.config.proxy_https_port)) self.set_proxy("ftp", "ftp://%s:%s@%s:%s" % \ (self.config.http_proxy_user, self.config.http_proxy_pass, self.config.proxy_ftp_host, self.config.proxy_ftp_port)) else: self.set_proxy("http", "http://%s:%s" % \ (self.config.http_proxy_host, self.config.http_proxy_port)) self.set_proxy("https", "https://%s:%s" % \ (self.config.proxy_https_host, self.config.proxy_https_port)) self.set_proxy("ftp", "ftp://%s:%s" % \ (self.config.proxy_ftp_host, self.config.proxy_ftp_port)) elif self.config.proxy_mode == "manual": if self.config.proxy_auth: self.set_proxy("http", "http://%s:%s@%s:%s" % \ (self.config.proxy_user, self.config.proxy_password, self.config.proxy_host, self.config.proxy_port)) else: self.set_proxy("http", "http://%s:%s" % \ (self.config.proxy_host, self.config.proxy_port)) def __download_added(self, download_list, download): """Called when a new download is added to DownloadList. Starts the download if its not already completed.""" download.connect("status-changed", self.__status_changed) if not download.status in [COMPLETED, CANCELED]: self.start_download(download) def __status_changed(self, download, status): """Called when the status of a download changes. If a canceled download is resumed we need to start the download again.""" if status == DOWNLOADING and \ download.old_status == CANCELED: self.start_download(download) def start_download(self, download): """Starts a download in a new thread.""" utils.debug_print("Starting download %s" % download) thread.start_new_thread(self.__start_download, (download,)) self.emit("download-started", (download)) def __start_download(self, download): # Python 2.5 seems to have a bug: sys.excepthook is not call from code # in a thread, see http://spyced.blogspot.com/2007/06/workaround-for-sysexcepthook-bug.html # sys.excepthook(*sys.exc_info()) if download.status in [-1, DOWNLOADING]: download.set_status(CONNECTING) try: result = metalink.get(download.uri, download.path, handlers={"status": download.update, "bitrate": download.bitrate, "cancel": download.is_canceled, "pause": download.is_paused}, headers=download.headers) if not result: download.set_status(ERROR) print "Failed downloading of file %s" % download.uri except Exception, e: print "Exception caught in DownloadManager.__start_download: " traceback.print_exc()