diff --git a/deluge/common.py b/deluge/common.py index f21e4b14c..af5bc920a 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -640,61 +640,6 @@ def is_ip(ip): return False -def path_join(*parts): - """ - An implementation of os.path.join that always uses / for the separator - to ensure that the correct paths are produced when working with internal - paths on Windows. - """ - path = '' - for part in parts: - if not part: - continue - elif part[0] == '/': - path = part - elif not path: - path = part - else: - path += '/' + part - return path - -XML_ESCAPES = ( - ('&', '&'), - ('<', '<'), - ('>', '>'), - ('"', '"'), - ("'", ''') -) - - -def xml_decode(string): - """ - Unescape a string that was previously encoded for use within xml. - - :param string: The string to escape - :type string: string - :returns: The unescaped version of the string. - :rtype: string - """ - for char, escape in XML_ESCAPES: - string = string.replace(escape, char) - return string - - -def xml_encode(string): - """ - Escape a string for use within an xml element or attribute. - - :param string: The string to escape - :type string: string - :returns: An escaped version of the string. - :rtype: string - """ - for char, escape in XML_ESCAPES: - string = string.replace(char, escape) - return string - - def decode_string(s, encoding="utf8"): """ Decodes a string and return unicode. If it cannot decode using diff --git a/deluge/ui/common.py b/deluge/ui/common.py index b3b2c0db1..6087cc8c0 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -18,7 +18,7 @@ from hashlib import sha1 as sha import deluge.configmanager from deluge import bencode -from deluge.common import path_join, utf8_encoded +from deluge.common import utf8_encoded log = logging.getLogger(__name__) @@ -304,7 +304,7 @@ class FileTree2(object): """ def walk(directory, parent_path): for path in directory["contents"].keys(): - full_path = path_join(parent_path, path) + full_path = os.path.join(parent_path, path).replace("\\", "/") if directory["contents"][path]["type"] == "dir": directory["contents"][path] = callback(full_path, directory["contents"][path] ) or directory["contents"][path] diff --git a/deluge/ui/gtkui/mainwindow.py b/deluge/ui/gtkui/mainwindow.py index 4689eece0..d36b16e39 100644 --- a/deluge/ui/gtkui/mainwindow.py +++ b/deluge/ui/gtkui/mainwindow.py @@ -126,7 +126,6 @@ class MainWindow(component.Component): self.config.register_set_function("show_rate_in_title", self._on_set_show_rate_in_title, apply_now=False) client.register_event_handler("NewVersionAvailableEvent", self.on_newversionavailable_event) - client.register_event_handler("TorrentFinishedEvent", self.on_torrentfinished_event) def connect_signals(self, mapping_or_class): self.gtk_builder_signals_holder.connect_signals(mapping_or_class) @@ -324,10 +323,6 @@ class MainWindow(component.Component): from deluge.ui.gtkui.new_release_dialog import NewReleaseDialog reactor.callLater(5.0, NewReleaseDialog().show, new_version) - def on_torrentfinished_event(self, torrent_id): - from deluge.ui.gtkui.notification import Notification - Notification().notify(torrent_id) - def is_on_active_workspace(self): """Determines if MainWindow is on the active workspace. diff --git a/deluge/ui/gtkui/notification.py b/deluge/ui/gtkui/notification.py deleted file mode 100644 index cda220312..000000000 --- a/deluge/ui/gtkui/notification.py +++ /dev/null @@ -1,124 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2008 Marcos Mobley ('markybob') -# -# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with -# the additional special exception to link portions of this program with the OpenSSL library. -# See LICENSE for more details. -# - -import logging - -import deluge.common -import deluge.component as component -from deluge.configmanager import ConfigManager -from deluge.ui.gtkui.common import get_logo - -log = logging.getLogger(__name__) - - -class Notification: - def __init__(self): - self.config = ConfigManager("gtkui.conf") - self.tray = component.get("SystemTray") - - def notify(self, torrent_id): - if self.config["ntf_tray_blink"]: - self.tray.blink(True) - if self.config["ntf_popup"] or self.config["ntf_email"]: - self.get_torrent_status(torrent_id) - - def get_torrent_status(self, torrent_id): - component.get("SessionProxy").get_torrent_status(torrent_id, [ - "name", "num_files", "total_payload_download" - ]).addCallback(self._on_get_torrent_status) - - def _on_get_torrent_status(self, status): - if status is None: - return - if status["total_payload_download"]: - if self.config["ntf_popup"]: - self.popup(status) - if self.config["ntf_email"]: - self.email(status) - if self.config["ntf_sound"]: - self.sound() - - def popup(self, status): - """popups up notification of finished torrent""" - if not deluge.common.windows_check(): - try: - import pynotify - except: - log.warning("pynotify is not installed") - else: - if not pynotify.init("Deluge"): - return - title = deluge.common.xml_encode(_("Torrent complete")) - message = deluge.common.xml_encode("%s\n%s %i %s" % (status["name"], - _("Including"), status["num_files"], _("files"))) - self.note = pynotify.Notification(title, message) - self.note.set_icon_from_pixbuf(get_logo(48)) - if not self.note.show(): - log.warning("pynotify failed to show notification") - - def sound(self): - """plays a sound when a torrent finishes""" - try: - import pygame - except: - log.warning("pygame is not installed") - else: - pygame.init() - try: - alert_sound = pygame.mixer.music - alert_sound.load(self.config["ntf_sound_path"]) - alert_sound.play() - except pygame.error as ex: - log.warning("pygame failed to play because %s", ex) - else: - log.info("sound notification played successfully") - - def email(self, status): - """sends email notification of finished torrent""" - import smtplib - headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % ( - self.config["ntf_email_add"], self.config["ntf_email_add"], - "Finished torrent %s" % (status["name"])) - text = _("This email is to inform you that Deluge has finished " - "downloading %(name)s , which includes %(num_files)i files.\n" - "To stop receiving these alerts, simply turn off email " - "notification in Deluge's preferences.\n\n" - "Thank you,\nDeluge") % {"name": status["name"], - "num_files": status["num_files"]} - message = headers + text - if self.config["ntf_security"] == 'SSL': - port = 465 - elif self.config["ntf_security"] == 'TLS': - port = 587 - elif self.config["ntf_security"] is None: - port = 25 - try: - mail_server = smtplib.SMTP(self.config["ntf_server"], port) - except Exception as ex: - log.error("There was an error sending the notification email: %s", ex) - return - - if self.config["ntf_username"] and self.config["ntf_pass"]: - if self.config["ntf_security"] == 'SSL' or 'TLS': - mail_server.ehlo('x') - mail_server.starttls() - mail_server.ehlo('x') - try: - mail_server.login(self.config["ntf_username"], self.config["ntf_pass"]) - except smtplib.SMTPHeloError: - log.warning("The server didn't reply properly to the helo greeting") - except smtplib.SMTPAuthenticationError: - log.warning("The server didn't accept the username/password combination") - try: - mail_server.sendmail(self.config["ntf_email_add"], self.config["ntf_email_add"], message) - mail_server.quit() - except: - log.warning("sending email notification of finished torrent failed") - else: - log.info("sending email notification of finished torrent was successful")