connected frontend to backend

This commit is contained in:
Zach Tibbitts 2007-01-11 05:01:11 +00:00
commit 2d8a842029
3 changed files with 723 additions and 680 deletions

View file

@ -299,7 +299,7 @@ class Manager:
def remove_torrent(self, unique_ID, data_also): def remove_torrent(self, unique_ID, data_also):
# Save some data before we remove the torrent, needed later in this func # Save some data before we remove the torrent, needed later in this func
temp = self.unique_IDs[unique_ID] 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.remove_torrent_ns(unique_ID)
self.sync() self.sync()
@ -550,6 +550,12 @@ class Manager:
# Cache torrent file # Cache torrent file
(temp, filename_short) = os.path.split(filename) (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): if filename_short in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR):
raise DelugeError("Duplicate Torrent, it appears: " + filename_short) raise DelugeError("Duplicate Torrent, it appears: " + filename_short)
@ -564,10 +570,16 @@ class Manager:
def remove_torrent_ns(self, unique_ID): def remove_torrent_ns(self, unique_ID):
self.unique_IDs[unique_ID].delete_me = True self.unique_IDs[unique_ID].delete_me = True
# Sync the state.torrents and unique_IDs lists with the core # Sync the state.torrents and unique_IDs lists with the core
# ___ALL syncing code with the core is here, and ONLY here___ # ___ALL syncing code with the core is here, and ONLY here___
# Also all self-syncing is done here (various lists) # 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): def sync(self):
ret = None # We return new added unique ID(s), or None ret = None # We return new added unique ID(s), or None
@ -584,12 +596,15 @@ class Manager:
ret = unique_ID ret = unique_ID
self.unique_IDs[unique_ID] = torrent self.unique_IDs[unique_ID] = torrent
print torrents_with_unique_ID
# Remove torrents from core, unique_IDs and queue # Remove torrents from core, unique_IDs and queue
to_delete = [] to_delete = []
for torrent in self.state.torrents: for torrent in self.state.torrents:
print torrent
if torrent.delete_me: if torrent.delete_me:
deluge_core.remove_torrent(torrent.unique_ID, torrent.filename) unique_ID = torrents_with_unique_ID.index(torrent)
to_delete.append(torrent.unique_ID) deluge_core.remove_torrent(unique_ID)
to_delete.append(unique_ID)
for unique_ID in to_delete: for unique_ID in to_delete:
self.state.torrents.remove(self.unique_IDs[unique_ID]) self.state.torrents.remove(self.unique_IDs[unique_ID])

View file

@ -63,6 +63,7 @@ class DelugeGTK:
## File Menu ## File Menu
"new_torrent": self.new_torrent, "new_torrent": self.new_torrent,
"add_torrent": self.add_torrent, "add_torrent": self.add_torrent,
"remove_torrent" : self.remove_torrent,
"menu_quit": self.quit, "menu_quit": self.quit,
## Edit Menu ## Edit Menu
"pref_clicked": self.prf.show_pref, "pref_clicked": self.prf.show_pref,
@ -132,22 +133,47 @@ class DelugeGTK:
## Call via a timer to update the interface ## Call via a timer to update the interface
def update(self): def update(self):
itr = self.store.get_iter_first() itr = self.store.get_iter_first()
while itr is not None: while itr is not None:
uid = self.store.get_value(itr, 0) uid = self.store.get_value(itr, 0)
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) tlist = self.get_list_from_uid(uid)
for i in range(12): for i in range(12):
self.store.set_value(itr, i, tlist[i]) self.store.set_value(itr, i, tlist[i])
itr = self.store.iter_next(itr) 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 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 # UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share
def get_list_from_uid(self, unique_id): def get_list_from_uid(self, unique_id):
state = self.manager.get_torrent_state(unique_id) state = self.manager.get_torrent_state(unique_id)
return [unique_id, state['queue_pos'], state['name'], state['total_size'], queue = int(state['queue_pos']) + 1
int(state['progress'] * 100), deluge.STATE_MESSAGES[state['state']], state['total_seeds'], name = state['name']
state['total_peers'], state['download_rate'], state['upload_rate'], size = state['total_size']
"NULL", "NULL"] 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): def new_torrent(self, obj=None):
pass pass
@ -158,6 +184,9 @@ class DelugeGTK:
uid = self.manager.add_torrent(torrent, ".", True) uid = self.manager.add_torrent(torrent, ".", True)
self.store.append(self.get_list_from_uid(uid)) 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): def quit(self, obj=None):
self.manager.quit() self.manager.quit()
self.window.destroy() self.window.destroy()

File diff suppressed because it is too large Load diff