Skip to content

Commit

Permalink
added proxy sort model, sort files
Browse files Browse the repository at this point in the history
  • Loading branch information
whoozle committed Apr 28, 2015
1 parent 2cefb24 commit f724c0f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
29 changes: 22 additions & 7 deletions qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "fileuploader.h"
#include <mtp/usb/TimeoutException.h>
#include <QDebug>
#include <QSortFilterProxyModel>
#include <QMessageBox>
#include <QKeyEvent>
#include <QFileDialog>
Expand All @@ -34,12 +35,21 @@
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
_ui(new Ui::MainWindow),
_proxyModel(new QSortFilterProxyModel),
_objectModel(new MtpObjectsModel()),
_uploader(new FileUploader(_objectModel, this))
{
_ui->setupUi(this);
setWindowIcon(QIcon(":/icons/android-file-transfer.png"));

_ui->listView->setModel(_proxyModel);

_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
_proxyModel->sort(0);
_proxyModel->setDynamicSortFilter(true);

_objectModel->moveToThread(QApplication::instance()->thread());

connect(_ui->listView, SIGNAL(doubleClicked(QModelIndex)), SLOT(onActivated(QModelIndex)));
connect(_ui->listView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenu(QPoint)));
connect(_ui->actionBack, SIGNAL(triggered()), SLOT(back()));
Expand Down Expand Up @@ -91,13 +101,18 @@ void MainWindow::showEvent(QShowEvent *)

_objectModel->setSession(session);
qDebug() << "session opened, starting";
_ui->listView->setModel(_objectModel);
_proxyModel->setSourceModel(_objectModel);
}
}

QModelIndex MainWindow::mapIndex(const QModelIndex &index)
{
return _proxyModel->mapToSource(index);
}

void MainWindow::onActivated ( const QModelIndex & index )
{
if (_objectModel->enter(index.row()))
if (_objectModel->enter(mapIndex(index).row()))
_history.push_back(_objectModel->parentObjectId());
}

Expand All @@ -121,7 +136,7 @@ void MainWindow::showContextMenu ( const QPoint & pos )
QList<quint32> objects;
for(int i = 0; i < rows.size(); ++i)
{
QModelIndex row = rows[i];
QModelIndex row = mapIndex(rows[i]);
objects.push_back(_objectModel->objectIdAt(row.row()));
}
downloadFiles(objects);
Expand All @@ -130,7 +145,7 @@ void MainWindow::showContextMenu ( const QPoint & pos )
{
for(int i = rows.size() - 1; i >= 0; --i)
{
QModelIndex row = rows[i];
QModelIndex row = mapIndex(rows[i]);
if (action == delete_objects)
_objectModel->removeRow(row.row());
else if (action == rename_object)
Expand All @@ -157,7 +172,7 @@ void MainWindow::back()

void MainWindow::down()
{
if (_objectModel->enter(_ui->listView->currentIndex().row()))
if (_objectModel->enter(mapIndex(_ui->listView->currentIndex()).row()))
_history.push_back(_objectModel->parentObjectId());
}

Expand All @@ -174,7 +189,7 @@ void MainWindow::uploadFiles(const QStringList &files)
return;

qDebug() << "uploadFiles " << files;
_ui->listView->setModel(NULL);
_proxyModel->setSourceModel(NULL);
ProgressDialog progressDialog(this);
progressDialog.setModal(true);
progressDialog.setValue(0);
Expand All @@ -188,7 +203,7 @@ void MainWindow::uploadFiles(const QStringList &files)
progressDialog.exec();

_objectModel->moveToThread(QApplication::instance()->thread());
_ui->listView->setModel(_objectModel);
_proxyModel->setSourceModel(_objectModel);
}


Expand Down
13 changes: 8 additions & 5 deletions qt/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MainWindow;

class MtpObjectsModel;
class FileUploader;
class QSortFilterProxyModel;

class MainWindow : public QMainWindow
{
Expand All @@ -43,6 +44,7 @@ class MainWindow : public QMainWindow

private:
void showEvent(QShowEvent *e);
QModelIndex mapIndex(const QModelIndex &index);

private slots:
void back();
Expand All @@ -58,12 +60,13 @@ private slots:
void downloadFiles(const QList<quint32> &objects);
void uploadFiles(const QStringList &files);

Ui::MainWindow * _ui;
MtpObjectsModel * _objectModel;
FileUploader * _uploader;
QVector<mtp::u32> _history;
Ui::MainWindow * _ui;
QSortFilterProxyModel * _proxyModel;
MtpObjectsModel * _objectModel;
FileUploader * _uploader;
QVector<mtp::u32> _history;

mtp::DevicePtr _device;
mtp::DevicePtr _device;
};

#endif // MAINWINDOW_H

0 comments on commit f724c0f

Please sign in to comment.