From 2d8a842029b5c94613d176a6f1954dc0a69b222f Mon Sep 17 00:00:00 2001 From: Zach Tibbitts Date: Thu, 11 Jan 2007 05:01:11 +0000 Subject: [PATCH] connected frontend to backend --- deluge.py | 23 +- delugegtk.py | 47 +- glade/delugegtk.glade | 1333 ++++++++++++++++++++--------------------- 3 files changed, 723 insertions(+), 680 deletions(-) diff --git a/deluge.py b/deluge.py index 5f49a5dcd..e9d189477 100644 --- a/deluge.py +++ b/deluge.py @@ -299,7 +299,7 @@ class Manager: def remove_torrent(self, unique_ID, data_also): # Save some data before we remove the torrent, needed later in this func temp = self.unique_IDs[unique_ID] - temp_fileinfo = deluge_core.get_fileinfo(unique_ID) + temp_fileinfo = deluge_core.get_file_info(unique_ID) self.remove_torrent_ns(unique_ID) self.sync() @@ -550,6 +550,12 @@ class Manager: # Cache torrent file (temp, filename_short) = os.path.split(filename) + # Remove torrents from core, unique_IDs and queue + to_delete = [] + for torrent in self.state.torrents: + if torrent.delete_me: + deluge_core.remove_torrent(torrent.unique_ID, torrent.filename) + to_delete.append(torrent.unique_ID) if filename_short in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR): raise DelugeError("Duplicate Torrent, it appears: " + filename_short) @@ -563,11 +569,17 @@ class Manager: def remove_torrent_ns(self, unique_ID): self.unique_IDs[unique_ID].delete_me = True + # Sync the state.torrents and unique_IDs lists with the core # ___ALL syncing code with the core is here, and ONLY here___ # Also all self-syncing is done here (various lists) + ## + ## I had to make some changes here to get things to work properly + ## Some of these changes may be hack-ish, so look at them and make + ## sure nothing is wrong. + ## def sync(self): ret = None # We return new added unique ID(s), or None @@ -583,13 +595,16 @@ class Manager: # print "Got unique ID:", unique_ID ret = unique_ID self.unique_IDs[unique_ID] = torrent - + + print torrents_with_unique_ID # Remove torrents from core, unique_IDs and queue to_delete = [] for torrent in self.state.torrents: + print torrent if torrent.delete_me: - deluge_core.remove_torrent(torrent.unique_ID, torrent.filename) - to_delete.append(torrent.unique_ID) + unique_ID = torrents_with_unique_ID.index(torrent) + deluge_core.remove_torrent(unique_ID) + to_delete.append(unique_ID) for unique_ID in to_delete: self.state.torrents.remove(self.unique_IDs[unique_ID]) diff --git a/delugegtk.py b/delugegtk.py index bd4ec3233..6ea16f6b1 100755 --- a/delugegtk.py +++ b/delugegtk.py @@ -63,6 +63,7 @@ class DelugeGTK: ## File Menu "new_torrent": self.new_torrent, "add_torrent": self.add_torrent, + "remove_torrent" : self.remove_torrent, "menu_quit": self.quit, ## Edit Menu "pref_clicked": self.prf.show_pref, @@ -132,22 +133,47 @@ class DelugeGTK: ## Call via a timer to update the interface def update(self): itr = self.store.get_iter_first() - while itr is not None: uid = self.store.get_value(itr, 0) - tlist = self.get_list_from_uid(uid) - for i in range(12): - self.store.set_value(itr, i, tlist[i]) - itr = self.store.iter_next(itr) + try: + state = self.manager.get_torrent_state(uid) + except deluge.DelugeError: + print "Removing Torrent" + self.store.remove(itr) + tab = self.wtree.get_widget("torrent_info").get_current_page() + if tab == 0: #Torrent List + tlist = self.get_list_from_uid(uid) + for i in range(12): + self.store.set_value(itr, i, tlist[i]) + itr = self.store.iter_next(itr) + elif tab == 1: #Details Pane + pass + elif tab == 2: #Peers List + pass + elif tab == 3: #File List + pass + return True + def get_selected_torrent(self): + return self.store.get_value(self.view.get_selection().get_selected()[1], 0) + # UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share def get_list_from_uid(self, unique_id): state = self.manager.get_torrent_state(unique_id) - return [unique_id, state['queue_pos'], state['name'], state['total_size'], - int(state['progress'] * 100), deluge.STATE_MESSAGES[state['state']], state['total_seeds'], - state['total_peers'], state['download_rate'], state['upload_rate'], - "NULL", "NULL"] + queue = int(state['queue_pos']) + 1 + name = state['name'] + size = state['total_size'] + progress = int(state['progress'] * 100) + message = deluge.STATE_MESSAGES[state['state']] + seeds = str(state['num_seeds']) + " (" + str(state['total_seeds']) + ")" + peers = str(state['num_peers']) + " (" + str(state['total_peers']) + ")" + dlrate = state['download_rate'] + ulrate = state['upload_rate'] + eta = "NULL" + share = "NULL" + return [unique_id, queue, name, size, progress, message, + seeds, peers, dlrate, ulrate, eta, share] def new_torrent(self, obj=None): pass @@ -157,6 +183,9 @@ class DelugeGTK: if torrent is not None: uid = self.manager.add_torrent(torrent, ".", True) self.store.append(self.get_list_from_uid(uid)) + + def remove_torrent(self, obj=None): + self.manager.remove_torrent(self.get_selected_torrent(), False) def quit(self, obj=None): self.manager.quit() diff --git a/glade/delugegtk.glade b/glade/delugegtk.glade index 0eb2d58f6..9bd2e847c 100644 --- a/glade/delugegtk.glade +++ b/glade/delugegtk.glade @@ -16,162 +16,626 @@ 4 3 - + True - GTK_TOOLBAR_BOTH_HORIZ - False + True - + True - Add Torrent - Add Torrent - True - gtk-add - + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + True + True + False + + + - False + False - + True - Remove Torrent - Remove Torrent - True - gtk-remove - + Torrents - False + tab + False + False - + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + + + True + 10 + 12 + 4 + + + + + + + + + + + + + + + True + + + 3 + 4 + 10 + 11 + + + + + True + 0 + <b>Estimated Time Remaining:</b> + True + + + 2 + 3 + 10 + 11 + + + + + True + + + 3 + 4 + 4 + 5 + + + + + True + + + 1 + 2 + 4 + 5 + + + + + True + 0 + <b>Peers:</b> + True + + + 2 + 3 + 4 + 5 + + + + + True + 0 + <b>Seeders:</b> + True + + + 4 + 5 + + + + + True + 0 + True + + + 1 + 4 + + + + + True + 0 + <b>Total Size:</b> + True + + + 1 + 2 + + + + + True + 0 + <b>Total Downloaded:</b> + True + + + 2 + 3 + + + + + True + 0 + <b>Percentage Done:</b> + True + + + 5 + 6 + + + + + True + 0 + <b>Downloaded this session:</b> + True + + + 6 + 7 + + + + + True + 0 + + + 1 + 2 + 1 + 2 + + + + + True + 0 + + + 1 + 2 + 2 + 3 + + + + + True + 0 + + + 1 + 2 + 5 + 6 + + + + + True + 0 + + + 1 + 2 + 6 + 7 + + + + + True + 0 + <b>Tracker:</b> + True + + + 7 + 8 + + + + + True + 0 + <b>Tracker Response:</b> + True + + + 8 + 9 + + + + + True + 0 + <b>Tracker Status:</b> + True + + + 9 + 10 + + + + + True + 0 + + + 1 + 2 + 9 + 10 + + + + + True + 0 + <b>Next Announce:</b> + True + + + 2 + 3 + 9 + 10 + + + + + True + 0 + + + 3 + 4 + 9 + 10 + + + + + True + 0 + <b>Pieces:</b> + True + + + 2 + 3 + 1 + 2 + + + + + True + 0 + <b>Total Uploaded:</b> + True + + + 2 + 3 + 2 + 3 + + + + + True + 0 + + + 3 + 4 + 1 + 2 + + + + + True + 0 + + + 3 + 4 + 2 + 3 + + + + + True + 0 + <b>Share Ratio:</b> + True + + + 2 + 3 + 5 + 6 + + + + + True + 0 + <b>Uploaded This Session:</b> + True + + + 2 + 3 + 6 + 7 + + + + + True + 0 + + + 3 + 4 + 5 + 6 + + + + + True + 0 + + + 3 + 4 + 6 + 7 + + + + + True + 0 + + + 1 + 4 + 7 + 8 + + + + + True + 0 + + + 1 + 4 + 8 + 9 + + + + + True + 0 + <b>Name:</b> + True + + + + + True + 0 + <b>Use compact storage allocation:</b> + True + + + 10 + 11 + + + + + True + 0 + + + 1 + 2 + 10 + 11 + + + + + True + 0 + <b>Download Rate:</b> + True + + + 3 + 4 + + + + + True + 0 + + + 1 + 2 + 3 + 4 + + + + + True + 0 + <b>Upload Rate:</b> + True + + + 2 + 3 + 3 + 4 + + + + + True + 0 + + + 3 + 4 + 3 + 4 + + + + + + - False - False + 1 + False - + True - Update Tracker - Update Tracker - True - gtk-refresh - + Details - False + tab + 1 + False + False - + True - Clear Finished Torrents - Clear Finished - True - gtk-clear - + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + + - False + 2 + False - + True + Peers - False - False + tab + 2 + False + False - + True - Force Pause/Resume Torrent - Force Pause/Resume Torrent - True - gtk-media-pause - + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + + + True + True + + - False + 3 + False - + True + Files - False - False - - - - - True - Queue Torrent Up - Move Up - True - gtk-go-up - - - - False - - - - - True - Queue Torrent Down - Move Down - True - gtk-go-down - - - - False + tab + 3 + False + False - 1 - 2 - - GTK_FILL - - - - - True - GTK_TOOLBAR_BOTH_HORIZ - - - 1 - 2 - 1 - 2 - GTK_FILL - - - - - True - GTK_TOOLBAR_BOTH_HORIZ - False - - - 2 3 - 1 - 2 - - GTK_FILL + 2 + 3 + + + + + True + + + 3 + 3 + 4 + @@ -449,627 +913,162 @@ - + True + GTK_TOOLBAR_BOTH_HORIZ + False + 2 3 - 3 - 4 - + 1 + 2 + + GTK_FILL - + True - True + GTK_TOOLBAR_BOTH_HORIZ + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + True + GTK_TOOLBAR_BOTH_HORIZ + False - + True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - - - True - True - True - False - - - + Add Torrent + Add Torrent + True + gtk-add + - False + False - + True - Torrents + Remove Torrent + Remove Torrent + True + gtk-remove + - tab - False - False + False - + True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - - - True - - - True - 10 - 12 - 4 - - - - - - - - - - - - - - - True - 0 - - - 3 - 4 - 3 - 4 - - - - - True - 0 - <b>Upload Rate:</b> - True - - - 2 - 3 - 3 - 4 - - - - - True - 0 - - - 1 - 2 - 3 - 4 - - - - - True - 0 - <b>Download Rate:</b> - True - - - 3 - 4 - - - - - True - 0 - - - 1 - 2 - 10 - 11 - - - - - True - 0 - <b>Use compact storage allocation:</b> - True - - - 10 - 11 - - - - - True - 0 - <b>Name:</b> - True - - - - - True - 0 - - - 1 - 4 - 8 - 9 - - - - - True - 0 - - - 1 - 4 - 7 - 8 - - - - - True - 0 - - - 3 - 4 - 6 - 7 - - - - - True - 0 - - - 3 - 4 - 5 - 6 - - - - - True - 0 - <b>Uploaded This Session:</b> - True - - - 2 - 3 - 6 - 7 - - - - - True - 0 - <b>Share Ratio:</b> - True - - - 2 - 3 - 5 - 6 - - - - - True - 0 - - - 3 - 4 - 2 - 3 - - - - - True - 0 - - - 3 - 4 - 1 - 2 - - - - - True - 0 - <b>Total Uploaded:</b> - True - - - 2 - 3 - 2 - 3 - - - - - True - 0 - <b>Pieces:</b> - True - - - 2 - 3 - 1 - 2 - - - - - True - 0 - - - 3 - 4 - 9 - 10 - - - - - True - 0 - <b>Next Announce:</b> - True - - - 2 - 3 - 9 - 10 - - - - - True - 0 - - - 1 - 2 - 9 - 10 - - - - - True - 0 - <b>Tracker Status:</b> - True - - - 9 - 10 - - - - - True - 0 - <b>Tracker Response:</b> - True - - - 8 - 9 - - - - - True - 0 - <b>Tracker:</b> - True - - - 7 - 8 - - - - - True - 0 - - - 1 - 2 - 6 - 7 - - - - - True - 0 - - - 1 - 2 - 5 - 6 - - - - - True - 0 - - - 1 - 2 - 2 - 3 - - - - - True - 0 - - - 1 - 2 - 1 - 2 - - - - - True - 0 - <b>Downloaded this session:</b> - True - - - 6 - 7 - - - - - True - 0 - <b>Percentage Done:</b> - True - - - 5 - 6 - - - - - True - 0 - <b>Total Downloaded:</b> - True - - - 2 - 3 - - - - - True - 0 - <b>Total Size:</b> - True - - - 1 - 2 - - - - - True - 0 - True - - - 1 - 4 - - - - - True - 0 - <b>Seeders:</b> - True - - - 4 - 5 - - - - - True - 0 - <b>Peers:</b> - True - - - 2 - 3 - 4 - 5 - - - - - True - - - 1 - 2 - 4 - 5 - - - - - True - - - 3 - 4 - 4 - 5 - - - - - True - 0 - <b>Estimated Time Remaining:</b> - True - - - 2 - 3 - 10 - 11 - - - - - True - - - 3 - 4 - 10 - 11 - - - - - - - 1 - False + False + False - + True - Details + Update Tracker + Update Tracker + True + gtk-refresh + - tab - 1 - False - False + False - + True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - - - True - - + Clear Finished Torrents + Clear Finished + True + gtk-clear + - 2 - False + False - + True - Files - tab - 2 - False - False + False + False - + True - True - GTK_POLICY_AUTOMATIC - GTK_POLICY_AUTOMATIC - - - True - True - - + Force Pause/Resume Torrent + Force Pause/Resume Torrent + True + gtk-media-pause + - 3 - False + False - + True - Peers - tab - 3 - False - False + False + False + + + + + True + Queue Torrent Up + Move Up + True + gtk-go-up + + + + False + + + + + True + Queue Torrent Down + Move Down + True + gtk-go-down + + + + False - 3 - 2 - 3 + 1 + 2 + + GTK_FILL