mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-11 12:04:10 +00:00
[#2698] [GTKUI] Fix corrupted column indexes when using multiple col_types
* Ensures that removing multiple items from liststore_columns list does not affect the index.
This commit is contained in:
parent
a68d836beb
commit
a9e7aec5b6
@ -13,6 +13,18 @@ deluge.common.setup_translations()
|
||||
|
||||
class TorrentviewTestCase(unittest.TestCase):
|
||||
|
||||
default_column_index = ['filter', 'torrent_id', 'dirty', '#', u'Name', u'Size',
|
||||
u'Downloaded', u'Uploaded', u'Remaining', u'Progress',
|
||||
u'Seeds', u'Peers', u'Seeds:Peers', u'Down Speed',
|
||||
u'Up Speed', u'Down Limit', u'Up Limit', u'ETA', u'Ratio',
|
||||
u'Avail', u'Added', u'Completed', u'Complete Seen',
|
||||
u'Tracker', u'Download Folder', u'Owner', u'Shared']
|
||||
default_liststore_columns = [bool, str, bool, int, str, str, gobject.TYPE_UINT64,
|
||||
gobject.TYPE_UINT64, gobject.TYPE_UINT64, gobject.TYPE_UINT64,
|
||||
float, str, int, int, int, int, float, float, float,
|
||||
float, float, int, float, float, float, float,
|
||||
float, str, str, str, str, bool]
|
||||
|
||||
def setUp(self): # NOQA
|
||||
self.mainwindow = MainWindow()
|
||||
self.torrentview = TorrentView()
|
||||
@ -26,39 +38,96 @@ class TorrentviewTestCase(unittest.TestCase):
|
||||
|
||||
def test_torrentview_columns(self):
|
||||
|
||||
default_column_index = ['filter', 'torrent_id', 'dirty', '#', u'Name', u'Size',
|
||||
u'Downloaded', u'Uploaded', u'Remaining', u'Progress',
|
||||
u'Seeds', u'Peers', u'Seeds:Peers', u'Down Speed',
|
||||
u'Up Speed', u'Down Limit', u'Up Limit', u'ETA', u'Ratio',
|
||||
u'Avail', u'Added', u'Completed', u'Complete Seen',
|
||||
u'Tracker', u'Download Folder', u'Owner', u'Shared']
|
||||
default_liststore_columns = [bool, str, bool, int, str, str, gobject.TYPE_UINT64,
|
||||
gobject.TYPE_UINT64, gobject.TYPE_UINT64, gobject.TYPE_UINT64,
|
||||
float, str, int, int, int, int, float, float, float,
|
||||
float, float, int, float, float, float, float,
|
||||
float, str, str, str, str, bool]
|
||||
self.assertEquals(self.torrentview.column_index, default_column_index)
|
||||
self.assertEquals(self.torrentview.liststore_columns, default_liststore_columns)
|
||||
|
||||
def test_addcolumn_verify_index(self):
|
||||
|
||||
self.assertEquals(self.torrentview.column_index, TorrentviewTestCase.default_column_index)
|
||||
self.assertEquals(self.torrentview.liststore_columns, TorrentviewTestCase.default_liststore_columns)
|
||||
self.assertEquals(self.torrentview.columns["Download Folder"].column_indices, [29])
|
||||
|
||||
def test_add_column(self):
|
||||
|
||||
# Add a text column
|
||||
test_col = "Test column"
|
||||
self.torrentview.add_text_column(test_col, status_field=["label"])
|
||||
self.assertEquals(len(self.torrentview.liststore_columns), 33)
|
||||
self.assertEquals(len(self.torrentview.column_index), 28)
|
||||
self.assertEquals(len(self.torrentview.liststore_columns),
|
||||
len(TorrentviewTestCase.default_liststore_columns) + 1)
|
||||
self.assertEquals(len(self.torrentview.column_index),
|
||||
len(TorrentviewTestCase.default_column_index) + 1)
|
||||
self.assertEquals(self.torrentview.column_index[-1], test_col)
|
||||
self.assertEquals(self.torrentview.columns[test_col].column_indices, [32])
|
||||
|
||||
def test_add_columns(self):
|
||||
|
||||
# Add a text column
|
||||
test_col = "Test column"
|
||||
self.torrentview.add_text_column(test_col, status_field=["label"])
|
||||
|
||||
# Add a second text column
|
||||
test_col2 = "Test column2"
|
||||
self.torrentview.add_text_column(test_col2, status_field=["label2"])
|
||||
self.assertEquals(len(self.torrentview.liststore_columns), 34)
|
||||
self.assertEquals(len(self.torrentview.column_index), 29)
|
||||
|
||||
self.assertEquals(len(self.torrentview.liststore_columns),
|
||||
len(TorrentviewTestCase.default_liststore_columns) + 2)
|
||||
self.assertEquals(len(self.torrentview.column_index),
|
||||
len(TorrentviewTestCase.default_column_index) + 2)
|
||||
# test_col
|
||||
self.assertEquals(self.torrentview.column_index[-2], test_col)
|
||||
self.assertEquals(self.torrentview.columns[test_col].column_indices, [32])
|
||||
|
||||
# test_col2
|
||||
self.assertEquals(self.torrentview.column_index[-1], test_col2)
|
||||
self.assertEquals(self.torrentview.columns[test_col2].column_indices, [33])
|
||||
|
||||
def test_remove_column(self):
|
||||
|
||||
# Add and remove text column
|
||||
test_col = "Test column"
|
||||
self.torrentview.add_text_column(test_col, status_field=["label"])
|
||||
self.torrentview.remove_column(test_col)
|
||||
self.assertEquals(len(self.torrentview.liststore_columns), 33)
|
||||
self.assertEquals(len(self.torrentview.column_index), 28)
|
||||
|
||||
self.assertEquals(len(self.torrentview.liststore_columns), len(TorrentviewTestCase.default_liststore_columns))
|
||||
self.assertEquals(len(self.torrentview.column_index), len(TorrentviewTestCase.default_column_index))
|
||||
self.assertEquals(self.torrentview.column_index[-1], TorrentviewTestCase.default_column_index[-1])
|
||||
self.assertEquals(self.torrentview.columns[TorrentviewTestCase.default_column_index[-1]].column_indices, [31])
|
||||
|
||||
def test_remove_columns(self):
|
||||
|
||||
# Add two columns
|
||||
test_col = "Test column"
|
||||
self.torrentview.add_text_column(test_col, status_field=["label"])
|
||||
test_col2 = "Test column2"
|
||||
self.torrentview.add_text_column(test_col2, status_field=["label2"])
|
||||
|
||||
# Remove test_col
|
||||
self.torrentview.remove_column(test_col)
|
||||
self.assertEquals(len(self.torrentview.liststore_columns),
|
||||
len(TorrentviewTestCase.default_liststore_columns) + 1)
|
||||
self.assertEquals(len(self.torrentview.column_index),
|
||||
len(TorrentviewTestCase.default_column_index) + 1)
|
||||
self.assertEquals(self.torrentview.column_index[-1], test_col2)
|
||||
self.assertEquals(self.torrentview.columns[test_col2].column_indices, [32])
|
||||
|
||||
# Remove test_col2
|
||||
self.torrentview.remove_column(test_col2)
|
||||
self.assertEquals(len(self.torrentview.liststore_columns), len(TorrentviewTestCase.default_liststore_columns))
|
||||
self.assertEquals(len(self.torrentview.column_index), len(TorrentviewTestCase.default_column_index))
|
||||
self.assertEquals(self.torrentview.column_index[-1], TorrentviewTestCase.default_column_index[-1])
|
||||
self.assertEquals(self.torrentview.columns[TorrentviewTestCase.default_column_index[-1]].column_indices, [31])
|
||||
|
||||
def test_add_remove_column_multiple_types(self):
|
||||
|
||||
# Add a column with multiple column types
|
||||
test_col3 = "Test column3"
|
||||
self.torrentview.add_progress_column(test_col3, status_field=["progress", "label3"], col_types=[float, str])
|
||||
self.assertEquals(len(self.torrentview.liststore_columns),
|
||||
len(TorrentviewTestCase.default_liststore_columns) + 2)
|
||||
self.assertEquals(len(self.torrentview.column_index),
|
||||
len(TorrentviewTestCase.default_column_index) + 1)
|
||||
self.assertEquals(self.torrentview.column_index[-1], test_col3)
|
||||
self.assertEquals(self.torrentview.columns[test_col3].column_indices, [32, 33])
|
||||
|
||||
# Remove multiple column-types column
|
||||
self.torrentview.remove_column(test_col3)
|
||||
|
||||
self.assertEquals(len(self.torrentview.liststore_columns), len(TorrentviewTestCase.default_liststore_columns))
|
||||
self.assertEquals(len(self.torrentview.column_index), len(TorrentviewTestCase.default_column_index))
|
||||
self.assertEquals(self.torrentview.column_index[-1], TorrentviewTestCase.default_column_index[-1])
|
||||
self.assertEquals(self.torrentview.columns[TorrentviewTestCase.default_column_index[-1]].column_indices, [31])
|
||||
|
@ -435,8 +435,8 @@ class ListView:
|
||||
# Delete the column
|
||||
del self.columns[header]
|
||||
self.column_index.remove(header)
|
||||
# Shift the column_indices values of those columns effected by the
|
||||
# removal. Any column_indices > the one removed.
|
||||
# Shift the column_indices values of those columns affected by the
|
||||
# removal. Any column_indices > the one removed.
|
||||
for column in self.columns.values():
|
||||
if column.column_indices[0] > column_indices[0]:
|
||||
# We need to shift this column_indices
|
||||
@ -446,7 +446,7 @@ class ListView:
|
||||
self.update_treeview_column(column.name, add=False)
|
||||
|
||||
# Remove from the liststore columns list
|
||||
for index in column_indices:
|
||||
for index in sorted(column_indices, reverse=True):
|
||||
del self.liststore_columns[index]
|
||||
|
||||
# Create a new liststore
|
||||
|
Loading…
x
Reference in New Issue
Block a user