connected frontend to backend

This commit is contained in:
Zach Tibbitts 2007-01-11 05:01:11 +00:00
parent eafe924107
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):
# 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])

View File

@ -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()

File diff suppressed because it is too large Load Diff