Skip to content

Commit

Permalink
Merge pull request #71 from egbertbouman/improvements
Browse files Browse the repository at this point in the history
Checkpoint after force_recheck + split filter and channel/playlist header
  • Loading branch information
egbertbouman committed Apr 5, 2013
2 parents d9fecb5 + 2bdaa8b commit 06275a6
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 153 deletions.
14 changes: 9 additions & 5 deletions Tribler/Core/Libtorrent/LibtorrentDownloadImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, session, tdef):
self.finished_time = 0.0
self.done = False
self.pause_after_next_hashcheck = False
self.checkpoint_after_next_hashcheck = False
self.prebuffsize = 5*1024*1024
self.queue_position = -1

Expand Down Expand Up @@ -347,10 +348,7 @@ def on_metadata_received_alert(self, alert):
elif self.session.lm.torrent_db:
self.session.lm.torrent_db.addExternalTorrent(self.tdef, source = '', extra_info = {'status':'good'}, commit = True)

# Checkpoint
(infohash, pstate) = self.network_checkpoint()
checkpoint = lambda : self.session.lm.save_download_pstate(infohash, pstate)
self.session.lm.rawserver.add_task(checkpoint, 0)
self.checkpoint()

def on_file_renamed_alert(self, alert):
if os.path.exists(self.unwanteddir_abs) and not os.listdir(self.unwanteddir_abs) and all(self.handle.file_priorities()):
Expand All @@ -376,6 +374,9 @@ def on_torrent_checked_alert(self, alert):
if self.pause_after_next_hashcheck:
self.pause_after_next_hashcheck = False
self.handle.pause()
if self.checkpoint_after_next_hashcheck:
self.checkpoint_after_next_hashcheck = False
self.checkpoint()

def update_lt_stats(self):
status = self.handle.status()
Expand Down Expand Up @@ -469,6 +470,7 @@ def force_recheck(self):
if self.handle is not None and not isinstance(self.tdef, TorrentDefNoMetainfo):
if self.dlstate == DLSTATUS_STOPPED:
self.pause_after_next_hashcheck = True
self.checkpoint_after_next_hashcheck = True
self.handle.resume()
self.handle.force_recheck()

Expand Down Expand Up @@ -774,7 +776,9 @@ def get_ext(filename):

def checkpoint(self):
""" Called by any thread """
self.network_checkpoint()
(infohash, pstate) = self.network_checkpoint()
checkpoint = lambda : self.session.lm.save_download_pstate(infohash, pstate)
self.session.lm.rawserver.add_task(checkpoint, 0)

def network_checkpoint(self):
""" Called by network thread """
Expand Down
57 changes: 27 additions & 30 deletions Tribler/Main/vwxGUI/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,22 +262,6 @@ def __init__(self, parent):

@warnWxThread
def _PostInit(self):
if self.guiutility.frame.top_bg:
self.header = self.CreateHeader(self.parent)
else:
raise NotYetImplementedException('')
# self.header = ChannelOnlyHeader(self.parent, self, [])
#
# def showSettings(event):
# self.guiutility.ShowPage('settings')
#
# def showLibrary(event):
# self.guiutility.ShowPage('my_files')
#
# self.header.SetEvents(showSettings, showLibrary)

self.Add(self.header, 0, wx.EXPAND)

#Hack to prevent focus on tabs
PageContainer.SetFocus = lambda a: None

Expand All @@ -291,17 +275,19 @@ def _PostInit(self):
self.notebook.SetForegroundColour(self.parent.GetForegroundColour())
self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnChange)

list = wx.Panel(self.notebook)
list.SetForegroundColour(self.notebook.GetForegroundColour())
list.SetFocus = list.SetFocusIgnoringChildren
contentList = wx.Panel(self.notebook)
contentList.SetForegroundColour(self.notebook.GetForegroundColour())
contentList.SetFocus = contentList.SetFocusIgnoringChildren

vSizer = wx.BoxSizer(wx.VERTICAL)
self.header = self.CreateHeader(contentList)
self.list = self.CreateList(contentList)

self.list = self.CreateList(list)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.Add(self.header, 0, wx.EXPAND)
vSizer.Add(self.list, 1, wx.EXPAND)

list.SetSizer(vSizer)
self.notebook.AddPage(list, "Contents")
contentList.SetSizer(vSizer)

self.notebook.AddPage(contentList, "Contents")

self.commentList = NotebookPanel(self.notebook)
self.commentList.SetList(CommentList(self.commentList, self, canReply=True))
Expand All @@ -322,6 +308,9 @@ def _PostInit(self):
listSizer.Add(self.leftLine, 0, wx.EXPAND)
listSizer.Add(self.notebook, 1, wx.EXPAND)
listSizer.Add(self.rightLine, 0, wx.EXPAND)

self.top_header = self.CreateTopHeader(self.parent)
self.Add(self.top_header, 0, wx.EXPAND)
self.Add(listSizer, 1, wx.EXPAND)

self.SetBackgroundColour(self.background)
Expand All @@ -340,7 +329,11 @@ def _special_icon(self, item):

@warnWxThread
def CreateHeader(self, parent):
return SelectedChannelFilter(self.parent, self, show_bundle = False)
return SelectedChannelFilter(parent, self, show_bundle = False)

@warnWxThread
def CreateTopHeader(self, parent):
return ChannelHeader(parent, self)

@warnWxThread
def Reset(self):
Expand Down Expand Up @@ -404,15 +397,15 @@ def SetChannelState(self, state, iamModerator):

#Update header + list ids
self.ResetBottomWindow()
self.header.SetHeadingButtons(self.channel)
self.top_header.SetButtons(self.channel)
self.commentList.GetManager().SetIds(channel = self.channel)
self.activityList.GetManager().SetIds(channel = self.channel)
self.moderationList.GetManager().SetIds(channel = self.channel)

@warnWxThread
def SetTitle(self, channel):
self.title = channel.name
self.header.SetHeading(channel)
self.top_header.SetTitle(channel)
self.Layout()

def GetManager(self):
Expand Down Expand Up @@ -485,7 +478,7 @@ def OnExpand(self, item):
details = TorrentDetails(self.guiutility.frame.splitter_bottom_window, item.original_data, noChannel = True)
item.expandedPanel = details
self.guiutility.SetBottomSplitterWindow(details)
self.header.heading_list.DeselectAll()
self.top_header.header_list.DeselectAll()
return True

@warnWxThread
Expand Down Expand Up @@ -846,7 +839,11 @@ def GetManager(self):

@warnWxThread
def CreateHeader(self, parent):
return SelectedPlaylistFilter(self.parent, self, show_bundle = False)
return SelectedPlaylistFilter(parent, self, show_bundle = False)

@warnWxThread
def CreateTopHeader(self, parent):
return PlaylistHeader(parent, self)

def Set(self, playlist):
self.playlist = playlist
Expand All @@ -855,7 +852,7 @@ def Set(self, playlist):
if self.notebook.GetPageCount() > 0:
self.notebook.SetSelection(0)
if self.playlist:
self.header.SetHeading(self.playlist)
self.top_header.SetTitle(self.playlist)
self.Layout()

def SetTitle(self, title, description):
Expand Down
Loading

0 comments on commit 06275a6

Please sign in to comment.