|
1 | 1 | #
|
2 | 2 | # gtkui.py
|
3 | 3 | #
|
4 |
| -# Copyright (C) 2013 Stefan Talpalaru <[email protected]> |
| 4 | +# Copyright (C) 2013-2015 Stefan Talpalaru <[email protected]> |
5 | 5 | #
|
6 | 6 | # Basic plugin template created by:
|
7 | 7 | # Copyright (C) 2008 Martijn Voncken <[email protected]>
|
|
44 | 44 | from deluge.ui.client import client
|
45 | 45 | from deluge.plugins.pluginbase import GtkPluginBase
|
46 | 46 | import deluge.component as component
|
47 |
| -import deluge.common |
| 47 | +#import deluge.common |
48 | 48 | from deluge.ui.gtkui import dialogs
|
49 |
| -from pprint import pprint |
| 49 | +#from pprint import pprint |
50 | 50 |
|
51 | 51 | from common import get_resource
|
52 | 52 |
|
@@ -95,30 +95,39 @@ def show(self, options=None, item_id=None, item_index=None):
|
95 | 95 |
|
96 | 96 | def load_options(self, options):
|
97 | 97 | if options:
|
98 |
| - self.glade.get_widget("tracker_entry").set_text(options.get("url", "")) |
| 98 | + self.glade.get_widget("tracker_entry").get_buffer().set_text(options.get("url", "")) |
| 99 | + |
| 100 | + def in_store(self, item): |
| 101 | + for row in self.gtkui.store: |
| 102 | + if row[0] == item: |
| 103 | + return True |
| 104 | + return False |
99 | 105 |
|
100 | 106 | def on_add(self, widget):
|
101 | 107 | try:
|
102 | 108 | options = self.generate_opts()
|
103 |
| - self.gtkui.store.append([options["url"]]) |
104 |
| - self.gtkui.trackers.append({"url": options["url"]}) |
| 109 | + for url in options["urls"]: |
| 110 | + if not self.in_store(url): |
| 111 | + self.gtkui.store.append([url]) |
| 112 | + self.gtkui.trackers.append({"url": url}) |
105 | 113 | except Exception, err:
|
106 | 114 | dialogs.ErrorDialog("Error", str(err), self.dialog).run()
|
107 | 115 |
|
108 | 116 | def generate_opts(self):
|
109 | 117 | # generate options dict based on gtk objects
|
| 118 | + buffer = self.glade.get_widget("tracker_entry").get_buffer() |
110 | 119 | options = {
|
111 |
| - "url": self.glade.get_widget("tracker_entry").get_text(), |
| 120 | + "urls": buffer.get_text(*buffer.get_bounds()).split(), |
112 | 121 | }
|
113 |
| - if len(options["url"]) == 0: |
114 |
| - raise Exception("empty URL") |
| 122 | + if len(options["urls"]) == 0: |
| 123 | + raise Exception("no URLs") |
115 | 124 | return options
|
116 | 125 |
|
117 | 126 | def on_apply(self, widget):
|
118 | 127 | try:
|
119 | 128 | options = self.generate_opts()
|
120 |
| - self.gtkui.store[self.item_id][0] = options["url"] |
121 |
| - self.gtkui.trackers[self.item_index]["url"] = options["url"] |
| 129 | + self.gtkui.store[self.item_id][0] = options["urls"][0] |
| 130 | + self.gtkui.trackers[self.item_index]["url"] = options["urls"][0] |
122 | 131 | except Exception, err:
|
123 | 132 | dialogs.ErrorDialog("Error", str(err), self.dialog).run()
|
124 | 133 |
|
|
0 commit comments