From 31a157091ad8a669da1219f3c9a9731919a8e9cf Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Sat, 20 Sep 2008 02:08:56 +0000 Subject: [PATCH] Allow adding multiple trackers at once in the edit tracker dialog --- ChangeLog | 1 + deluge/ui/gtkui/edittrackersdialog.py | 67 ++++++++++++----------- deluge/ui/gtkui/glade/edit_trackers.glade | 48 +++++++++------- 3 files changed, 65 insertions(+), 51 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc0e475cb..c8a2b6f6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,3 +9,4 @@ Deluge 1.1.0 - "" (In Development) * Add peer progress to the peers tab * Sorting # column will place downloaders above seeds * Remove dependency on libtorrent for add torrent dialog + * Allow adding multiple trackers at once in the edit tracker dialog diff --git a/deluge/ui/gtkui/edittrackersdialog.py b/deluge/ui/gtkui/edittrackersdialog.py index c89648ab6..d332ea1e3 100644 --- a/deluge/ui/gtkui/edittrackersdialog.py +++ b/deluge/ui/gtkui/edittrackersdialog.py @@ -1,7 +1,7 @@ # # edittrackersdialog.py # -# Copyright (C) 2007 Andrew Resch ('andar') +# Copyright (C) 2007, 2008 Andrew Resch ('andar') # # Deluge is free software. # @@ -125,7 +125,7 @@ class EditTrackersDialog: log.debug("on_button_add_clicked") # Show the add tracker dialog self.add_tracker_dialog.show() - self.glade.get_widget("entry_tracker").grab_focus() + self.glade.get_widget("textview_trackers").grab_focus() def on_button_remove_clicked(self, widget): log.debug("on_button_remove_clicked") @@ -185,38 +185,43 @@ class EditTrackersDialog: def on_button_add_ok_clicked(self, widget): log.debug("on_button_add_ok_clicked") - from re import search as re_search - tracker = self.glade.get_widget("entry_tracker").get_text() - if not re_search("[udp|http]s?://", tracker): - # Bad url.. lets prepend http:// - tracker = "http://" + tracker - - # Figure out what tier number to use.. it's going to be the highest+1 - # Also check for duplicates - self.highest_tier = 0 - self.duplicate = False - def tier_count(model, path, iter, data): - tier = model.get_value(iter, 0) - if tier > self.highest_tier: - self.highest_tier = tier - tracker = model.get_value(iter, 1) - if data == tracker: - # We already have this tracker in the list - self.duplicate = True - # Check if there are any entries - if self.liststore.iter_n_children(None) > 0: - self.liststore.foreach(tier_count, tracker) - else: - self.highest_tier = -1 - - # If not a duplicate, then add it to the list - if not self.duplicate: - # Add the tracker to the list - self.add_tracker(self.highest_tier + 1, tracker) + # Create a list of trackers from the textview widget + textview = self.glade.get_widget("textview_trackers") + trackers = [] + b = textview.get_buffer() + lines = b.get_text(b.get_start_iter(), b.get_end_iter()).strip().split("\n") + for l in lines: + if deluge.common.is_url(l): + trackers.append(l) + + for tracker in trackers: + # Figure out what tier number to use.. it's going to be the highest+1 + # Also check for duplicates + highest_tier = 0 + duplicate = False + def tier_count(model, path, iter, data): + tier = model.get_value(iter, 0) + if tier > data[1]: + data[1] = tier + tracker = model.get_value(iter, 1) + if data[0] == tracker: + # We already have this tracker in the list + data[2] = True + + # Check if there are any entries + if self.liststore.iter_n_children(None) > 0: + self.liststore.foreach(tier_count, [tracker, highest_tier, duplicate]) + else: + highest_tier = -1 + + # If not a duplicate, then add it to the list + if not duplicate: + # Add the tracker to the list + self.add_tracker(highest_tier + 1, tracker) # Clear the entry widget and hide the dialog - self.glade.get_widget("entry_tracker").set_text("") + textview.get_buffer().set_text("") self.add_tracker_dialog.hide() def on_button_add_cancel_clicked(self, widget): diff --git a/deluge/ui/gtkui/glade/edit_trackers.glade b/deluge/ui/gtkui/glade/edit_trackers.glade index 7cf478091..c45d6b6f3 100644 --- a/deluge/ui/gtkui/glade/edit_trackers.glade +++ b/deluge/ui/gtkui/glade/edit_trackers.glade @@ -1,6 +1,6 @@ - + 400 @@ -93,7 +93,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-go-up + gtk-go-up True 0 @@ -134,7 +134,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-remove + gtk-remove True 0 @@ -149,7 +149,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-go-down + gtk-go-down True 0 @@ -186,7 +186,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-cancel + gtk-cancel True 0 @@ -198,7 +198,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-ok + gtk-ok True 0 @@ -218,6 +218,7 @@ 400 + 200 GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK 5 Add Tracker @@ -256,7 +257,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - <b>Add Tracker</b> + <b>Add Trackers</b> True @@ -290,21 +291,30 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - Tracker: + 0 + 0 + Trackers: False - False - + True True - True - True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + + + True + True + 1 + 1 + False + + 1 @@ -312,8 +322,6 @@ - False - False 2 @@ -333,7 +341,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-cancel + gtk-cancel True 0 @@ -347,7 +355,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-ok + gtk-ok True 0 @@ -482,7 +490,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-cancel + gtk-cancel True 0 @@ -496,7 +504,7 @@ True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - gtk-ok + gtk-ok True 0