mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-27 19:55:57 +00:00
Add state saving to the the files tab so that column size, sort order
and positions are persistent.
This commit is contained in:
parent
13b507a925
commit
c4ee6c090e
@ -35,14 +35,24 @@ import gtk, gtk.glade
|
|||||||
import gobject
|
import gobject
|
||||||
import gettext
|
import gettext
|
||||||
import os.path
|
import os.path
|
||||||
|
import cPickle
|
||||||
|
|
||||||
from deluge.ui.client import aclient as client
|
from deluge.ui.client import aclient as client
|
||||||
|
from deluge.configmanager import ConfigManager
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.ui.gtkui.listview
|
import deluge.ui.gtkui.listview
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
class ColumnState:
|
||||||
|
def __init__(self, name, position, width, sort, sort_order):
|
||||||
|
self.name = name
|
||||||
|
self.position = position
|
||||||
|
self.width = width
|
||||||
|
self.sort = sort
|
||||||
|
self.sort_order = sort_order
|
||||||
|
|
||||||
class FilesTab:
|
class FilesTab:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
glade = component.get("MainWindow").get_glade()
|
glade = component.get("MainWindow").get_glade()
|
||||||
@ -55,6 +65,12 @@ class FilesTab:
|
|||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
column.pack_start(render, False)
|
column.pack_start(render, False)
|
||||||
column.add_attribute(render, "text", 0)
|
column.add_attribute(render, "text", 0)
|
||||||
|
column.set_sort_column_id(0)
|
||||||
|
column.set_clickable(True)
|
||||||
|
column.set_resizable(True)
|
||||||
|
column.set_expand(False)
|
||||||
|
column.set_min_width(10)
|
||||||
|
column.set_reorderable(True)
|
||||||
self.listview.append_column(column)
|
self.listview.append_column(column)
|
||||||
|
|
||||||
# Size column
|
# Size column
|
||||||
@ -62,14 +78,26 @@ class FilesTab:
|
|||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
column.pack_start(render, False)
|
column.pack_start(render, False)
|
||||||
column.set_cell_data_func(render, deluge.ui.gtkui.listview.cell_data_size, 1)
|
column.set_cell_data_func(render, deluge.ui.gtkui.listview.cell_data_size, 1)
|
||||||
|
column.set_sort_column_id(1)
|
||||||
|
column.set_clickable(True)
|
||||||
|
column.set_resizable(True)
|
||||||
|
column.set_expand(False)
|
||||||
|
column.set_min_width(10)
|
||||||
|
column.set_reorderable(True)
|
||||||
self.listview.append_column(column)
|
self.listview.append_column(column)
|
||||||
|
|
||||||
# Progress column
|
# Progress column
|
||||||
column = gtk.TreeViewColumn(_("Progress"))
|
column = gtk.TreeViewColumn(_("Progress"))
|
||||||
render = gtk.CellRendererProgress()
|
render = gtk.CellRendererProgress()
|
||||||
column.pack_start(render, False)
|
column.pack_start(render)
|
||||||
column.add_attribute(render, "text", 2)
|
column.add_attribute(render, "text", 2)
|
||||||
column.add_attribute(render, "value", 3)
|
column.add_attribute(render, "value", 3)
|
||||||
|
column.set_sort_column_id(3)
|
||||||
|
column.set_clickable(True)
|
||||||
|
column.set_resizable(True)
|
||||||
|
column.set_expand(False)
|
||||||
|
column.set_min_width(10)
|
||||||
|
column.set_reorderable(True)
|
||||||
self.listview.append_column(column)
|
self.listview.append_column(column)
|
||||||
|
|
||||||
# Priority column
|
# Priority column
|
||||||
@ -77,15 +105,76 @@ class FilesTab:
|
|||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
column.pack_start(render, False)
|
column.pack_start(render, False)
|
||||||
column.add_attribute(render, "text", 4)
|
column.add_attribute(render, "text", 4)
|
||||||
|
column.set_sort_column_id(4)
|
||||||
|
column.set_clickable(True)
|
||||||
|
column.set_resizable(True)
|
||||||
|
column.set_expand(False)
|
||||||
|
column.set_min_width(10)
|
||||||
|
column.set_reorderable(True)
|
||||||
self.listview.append_column(column)
|
self.listview.append_column(column)
|
||||||
|
|
||||||
self.listview.set_model(self.liststore)
|
self.listview.set_model(self.liststore)
|
||||||
|
|
||||||
|
# Attempt to load state
|
||||||
|
self.load_state()
|
||||||
|
|
||||||
# torrent_id: (filepath, size)
|
# torrent_id: (filepath, size)
|
||||||
self.files_list = {}
|
self.files_list = {}
|
||||||
|
|
||||||
self.torrent_id = None
|
self.torrent_id = None
|
||||||
|
|
||||||
|
def save_state(self):
|
||||||
|
filename = "files_tab.state"
|
||||||
|
state = []
|
||||||
|
for index, column in enumerate(self.listview.get_columns()):
|
||||||
|
state.append(ColumnState(column.get_title(), index, column.get_width(),
|
||||||
|
column.get_sort_indicator(), int(column.get_sort_order())))
|
||||||
|
|
||||||
|
# Get the config location for saving the state file
|
||||||
|
config_location = ConfigManager("gtkui.conf")["config_location"]
|
||||||
|
|
||||||
|
try:
|
||||||
|
log.debug("Saving FilesTab state file: %s", filename)
|
||||||
|
state_file = open(os.path.join(config_location, filename), "wb")
|
||||||
|
cPickle.dump(state, state_file)
|
||||||
|
state_file.close()
|
||||||
|
except IOError, e:
|
||||||
|
log.warning("Unable to save state file: %s", e)
|
||||||
|
|
||||||
|
def load_state(self):
|
||||||
|
filename = "files_tab.state"
|
||||||
|
# Get the config location for loading the state file
|
||||||
|
config_location = ConfigManager("gtkui.conf")["config_location"]
|
||||||
|
state = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
log.debug("Loading FilesTab state file: %s", filename)
|
||||||
|
state_file = open(os.path.join(config_location, filename), "rb")
|
||||||
|
state = cPickle.load(state_file)
|
||||||
|
state_file.close()
|
||||||
|
except IOError, e:
|
||||||
|
log.warning("Unable to load state file: %s", e)
|
||||||
|
|
||||||
|
if state == None:
|
||||||
|
return
|
||||||
|
|
||||||
|
for column_state in state:
|
||||||
|
# Find matching columns in the listview
|
||||||
|
for (index, column) in enumerate(self.listview.get_columns()):
|
||||||
|
if column_state.name == column.get_title():
|
||||||
|
# We have a match, so set options that were saved in state
|
||||||
|
if column_state.width > 0:
|
||||||
|
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||||
|
column.set_fixed_width(column_state.width)
|
||||||
|
column.set_sort_indicator(column_state.sort)
|
||||||
|
column.set_sort_order(column_state.sort_order)
|
||||||
|
if column_state.position != index:
|
||||||
|
# Column is in wrong position
|
||||||
|
if column_state.position == 0:
|
||||||
|
self.listview.move_column_after(column, None)
|
||||||
|
else:
|
||||||
|
self.listview.move_column_after(column, self.listview.get_columns()[column_state.position - 1])
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
# Get the first selected torrent
|
# Get the first selected torrent
|
||||||
torrent_id = component.get("TorrentView").get_selected_torrents()
|
torrent_id = component.get("TorrentView").get_selected_torrents()
|
||||||
|
@ -74,6 +74,13 @@ class TorrentDetails(component.Component):
|
|||||||
self.window.vpaned.set_position(-1)
|
self.window.vpaned.set_position(-1)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
# Save the state of the tabs
|
||||||
|
for tab in self.tabs:
|
||||||
|
try:
|
||||||
|
tab.save_state()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user