Commit 71ce26a1 authored by Joris Guisson's avatar Joris Guisson
Browse files

Merged rev 794736 (files tab sorting)

svn path=/branches/ktorrent/3.0/; revision=794739
parent 36b58967
......@@ -5,6 +5,7 @@ Changes in 3.0.2 :
- When recreating files, make sure directory they are in, exists
- Fix remove from group not working (160499)
- Fix crash in torrent creator when there are no trackers
- Fix sorting in files tab
Changes in 3.0.1 :
- Fix sessionTTL not being able to be bigger then 99
......
......@@ -476,7 +476,11 @@ namespace kt
KConfigGroup g = cfg->group(QString("View%1").arg(idx));
QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
if (!s.isNull())
header()->restoreState(s);
{
QHeaderView* v = header();
v->restoreState(s);
sortByColumn(v->sortIndicatorSection(),v->sortIndicatorOrder());
}
QMap<QAction*,int>::iterator i = column_idx_map.begin();
while (i != column_idx_map.end())
......
......@@ -99,6 +99,19 @@ namespace kt
default: return QVariant();
}
}
else if (role == Qt::UserRole) // sorting
{
switch (index.column())
{
case 0: return multi ? tc->getTorrentFile(r).getPath() : s.torrent_name;
case 1:
if (multi)
return tc->getTorrentFile(r).getSize();
else
return s.total_bytes;
default: return QVariant();
}
}
else if (role == Qt::DecorationRole && index.column() == 0)
{
// if this is an empty folder then we are in the single file case
......
......@@ -288,6 +288,19 @@ namespace kt
default: return QVariant();
}
}
else if (role == Qt::UserRole) // sorting
{
switch (index.column())
{
case 0: return n->name;
case 1:
if (tc->getStats().multi_file_torrent)
return n->fileSize(tc);
else
return tc->getStats().total_bytes;
default: return QVariant();
}
}
else if (role == Qt::DecorationRole && index.column() == 0)
{
// if this is an empty folder then we are in the single file case
......
......@@ -112,7 +112,11 @@ namespace kt
KConfigGroup g = cfg->group("ChunkDownloadView");
QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
if (!s.isNull())
m_chunk_view->header()->restoreState(s);
{
QHeaderView* v = m_chunk_view->header();
v->restoreState(s);
m_chunk_view->sortByColumn(v->sortIndicatorSection(),v->sortIndicatorOrder());
}
}
}
......
......@@ -21,6 +21,7 @@
#include <QHeaderView>
#include <QItemSelectionModel>
#include <QSortFilterProxyModel>
#include <klocale.h>
#include <kiconloader.h>
#include <kglobal.h>
......@@ -56,6 +57,10 @@ namespace kt
setSelectionMode(QAbstractItemView::ExtendedSelection);
setSelectionBehavior(QAbstractItemView::SelectRows);
proxy_model = new QSortFilterProxyModel(this);
proxy_model->setSortRole(Qt::UserRole);
setModel(proxy_model);
context_menu = new KMenu(this);
open_action = context_menu->addAction(KIcon("document-open"),i18nc("Open file", "Open"),this,SLOT(open()));
context_menu->addSeparator();
......@@ -92,7 +97,7 @@ namespace kt
if (curr_tc)
expanded_state_map[curr_tc] = model->saveExpandedState(this);
}
setModel(0);
proxy_model->setSourceModel(0);
delete model;
model = 0;
curr_tc = tc;
......@@ -107,7 +112,7 @@ namespace kt
else
model = new IWFileTreeModel(tc,this);
setModel(model);
proxy_model->setSourceModel(model);
setRootIsDecorated(tc->getStats().multi_file_torrent);
loadState(cfg);
QMap<bt::TorrentInterface*,QByteArray>::iterator i = expanded_state_map.find(tc);
......@@ -118,7 +123,7 @@ namespace kt
}
else
{
setModel(0);
proxy_model->setSourceModel(0);
model = 0;
}
}
......@@ -151,7 +156,7 @@ namespace kt
}
QModelIndex item = sel.front();
bt::TorrentFileInterface* file = model->indexToFile(item);
bt::TorrentFileInterface* file = model->indexToFile(proxy_model->mapToSource(item));
download_first_action->setEnabled(false);
download_last_action->setEnabled(false);
......@@ -206,7 +211,12 @@ namespace kt
void FileView::changePriority(bt::Priority newpriority)
{
model->changePriority(selectionModel()->selectedRows(2),newpriority);
QModelIndexList sel = selectionModel()->selectedRows(2);
for (QModelIndexList::iterator i = sel.begin();i != sel.end();i++)
*i = proxy_model->mapToSource(*i);
model->changePriority(sel,newpriority);
proxy_model->invalidate();
}
......@@ -236,7 +246,7 @@ namespace kt
Uint32 n = sel.count();
if (n == 1) // single item can be a directory
{
if (!model->indexToFile(sel.front()))
if (!model->indexToFile(proxy_model->mapToSource(sel.front())))
n++;
}
......@@ -261,7 +271,7 @@ namespace kt
foreach (QModelIndex idx,sel)
{
bt::TorrentFileInterface* tfi = model->indexToFile(idx);
bt::TorrentFileInterface* tfi = model->indexToFile(proxy_model->mapToSource(idx));
if (!tfi)
continue;
......@@ -293,7 +303,7 @@ namespace kt
if (s.multi_file_torrent)
{
bt::TorrentFileInterface* file = model->indexToFile(index);
bt::TorrentFileInterface* file = model->indexToFile(proxy_model->mapToSource(index));
if (!file)
{
// directory
......@@ -326,7 +336,11 @@ namespace kt
KConfigGroup g = cfg->group("FileView");
QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
if (!s.isNull())
header()->restoreState(s);
{
QHeaderView* v = header();
v->restoreState(s);
sortByColumn(v->sortIndicatorSection(),v->sortIndicatorOrder());
}
}
void FileView::update()
......@@ -352,7 +366,7 @@ namespace kt
saveState(cfg);
expanded_state_map[curr_tc] = model->saveExpandedState(this);
setModel(0);
proxy_model->setSourceModel(0);
delete model;
model = 0;
......@@ -361,7 +375,7 @@ namespace kt
else
model = new IWFileTreeModel(curr_tc,this);
setModel(model);
proxy_model->setSourceModel(model);
setRootIsDecorated(curr_tc->getStats().multi_file_torrent);
loadState(cfg);
QMap<bt::TorrentInterface*,QByteArray>::iterator i = expanded_state_map.find(curr_tc);
......
......@@ -25,6 +25,7 @@
#include <ksharedconfig.h>
class KMenu;
class QSortFilterProxyModel;
namespace bt
{
......@@ -86,6 +87,7 @@ namespace kt
QString preview_path;
bool show_list_of_files;
QMap<bt::TorrentInterface*,QByteArray> expanded_state_map;
QSortFilterProxyModel* proxy_model;
};
}
......
......@@ -100,9 +100,16 @@ namespace kt
if (!index.isValid() || index.row() < 0 || index.row() >= rowCount(QModelIndex()))
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
if (role == Qt::DisplayRole)
return displayData(index);
else if (role == Qt::UserRole)
return sortData(index);
return QVariant();
}
QVariant IWFileListModel::displayData(const QModelIndex & index) const
{
if (tc->getStats().multi_file_torrent)
{
const bt::TorrentFileInterface* file = &tc->getTorrentFile(index.row());
......@@ -150,10 +157,52 @@ namespace kt
default: return QVariant();
}
}
return QVariant();
}
QVariant IWFileListModel::sortData(const QModelIndex & index) const
{
if (tc->getStats().multi_file_torrent)
{
const bt::TorrentFileInterface* file = &tc->getTorrentFile(index.row());
switch (index.column())
{
case 2: return (int)file->getPriority();
case 3:
if (file->isMultimedia())
{
if (tc->readyForPreview(file->getFirstChunk(), file->getFirstChunk()+1) )
return 3;
else
return 2;
}
else
return 1;
case 4:
return file->getDownloadPercentage();
}
}
else
{
switch (index.column())
{
case 2: return QVariant();
case 3:
if (mmfile)
{
if (tc->readyForPreview(0,1))
return 3;
else
return 2;
}
else
return 1;
case 4:
return bt::Percentage(tc->getStats());
}
}
return QVariant();
}
bool IWFileListModel::setData(const QModelIndex & index, const QVariant & value, int role)
......
......@@ -49,6 +49,10 @@ namespace kt
void onPercentageUpdated(float p);
void onPreviewAvailable(bool av);
private:
QVariant displayData(const QModelIndex & index) const;
QVariant sortData(const QModelIndex & index) const;
private:
bool preview;
bool mmfile;
......
......@@ -98,9 +98,16 @@ namespace kt
if (!index.isValid() || !(n = (Node*)index.internalPointer()))
return QVariant();
if (role != Qt::DisplayRole)
return QVariant();
if (role == Qt::DisplayRole)
return displayData(n,index);
else if (role == Qt::UserRole)
return sortData(n,index);
return QVariant();
}
QVariant IWFileTreeModel::displayData(Node* n,const QModelIndex & index) const
{
if (tc->getStats().multi_file_torrent && n->file)
{
const bt::TorrentFileInterface* file = n->file;
......@@ -148,10 +155,52 @@ namespace kt
default: return QVariant();
}
}
return QVariant();
}
QVariant IWFileTreeModel::sortData(Node* n,const QModelIndex & index) const
{
if (tc->getStats().multi_file_torrent && n->file)
{
const bt::TorrentFileInterface* file = n->file;
switch (index.column())
{
case 2: return (int)file->getPriority();
case 3:
if (file->isMultimedia())
{
if (tc->readyForPreview(file->getFirstChunk(), file->getFirstChunk()+1) )
return 3;
else
return 2;
}
else
return 1;
case 4:
return file->getDownloadPercentage();
}
}
else if (!tc->getStats().multi_file_torrent)
{
switch (index.column())
{
case 2: return QVariant();
case 3:
if (mmfile)
{
if (tc->readyForPreview(0,1))
return 3;
else
return 2;
}
else
return 1;
case 4:
return bt::Percentage(tc->getStats());
}
}
return QVariant();
}
bool IWFileTreeModel::setData(const QModelIndex & index, const QVariant & value, int role)
......
......@@ -51,6 +51,8 @@ namespace kt
private:
void update(const QModelIndex & index,bt::TorrentFileInterface* file,int col);
QVariant displayData(Node* n,const QModelIndex & index) const;
QVariant sortData(Node* n,const QModelIndex & index) const;
private:
bool preview;
......
......@@ -130,7 +130,11 @@ namespace kt
KConfigGroup g = cfg->group("PeerView");
QByteArray s = QByteArray::fromBase64(g.readEntry("state",QByteArray()));
if (!s.isNull())
header()->restoreState(s);
{
QHeaderView* v = header();
v->restoreState(s);
sortByColumn(v->sortIndicatorSection(),v->sortIndicatorOrder());
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment