summaryrefslogtreecommitdiffstats
path: root/filesystemwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'filesystemwidget.cpp')
-rw-r--r--filesystemwidget.cpp72
1 files changed, 33 insertions, 39 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp
index b3ab4e1..e4363f0 100644
--- a/filesystemwidget.cpp
+++ b/filesystemwidget.cpp
@@ -37,6 +37,7 @@
#include "helper.h"
#include "pictureviewer2.h"
#include "smglobals.h"
+#include "smdirmodel.h"
FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent), mClipboardMode(None) {
mModel = new FileSystemModel(this);
@@ -62,7 +63,9 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent), mClipboar
mFileView = new FileView;
mFileProxy = new FilesystemFileProxy;
- mFileProxy->setSourceModel(mModel);
+ QStringList fHeaders = QStringList() << tr("Name") << tr("Size") << tr("Type") << tr("Created") << tr("Md5Sum") << tr("Duration") << tr("Bitrate") << tr("Full Path");
+ mFileModel = new SmDirModel(fHeaders, this);
+ mFileProxy->setSourceModel(mFileModel);
mFileView->setModel(mFileProxy);
mFileView->setSortingEnabled(true);
mFileView->sortByColumn(0, Qt::AscendingOrder);
@@ -70,6 +73,7 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent), mClipboar
mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection);
mFileView->setEditTriggers(QAbstractItemView::NoEditTriggers);
mFileView->setAlternatingRowColors(true);
+ mFileView->setColumnHidden(static_cast<int>(SmDirModel::FullPath), true);
connect(mFileView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), mFileView, SLOT(selectedFilesChanged()));
mPicViewer = SmGlobals::instance()->pictureViewer();
@@ -100,8 +104,6 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent), mClipboar
connect(mFileView, SIGNAL(delFiles()), this, SLOT(deleteFiles()));
connect(mFileView, SIGNAL(editorClosed(QModelIndex)), this, SLOT(fileEditorClosed(QModelIndex)));
- mFileView->resizeColumnToContents(0);
-
QVBoxLayout *mainLayout = new QVBoxLayout;
QSplitter *splitter = new QSplitter;
splitter->addWidget(mDirView);
@@ -147,7 +149,12 @@ void FilesystemWidget::directoryChanged(const QModelIndex &selected, const QMode
mDirEdit->setText(mModel->filePath(real));
setWindowTitle(mModel->filePath(real));
mFileView->selectionModel()->clear();
- mFileView->setRootIndex(mFileProxy->mapFromSource(real));
+ mFileModel->setDir(mModel->filePath(real));
+ mFileView->resizeColumnToContents(0);
+ mFileView->resizeColumnToContents(1);
+ mFileView->resizeColumnToContents(2);
+ mFileView->resizeColumnToContents(3);
+ mFileView->resizeColumnToContents(4);
}
void FilesystemWidget::directoryEdited(){
@@ -164,16 +171,17 @@ void FilesystemWidget::directoryEdited(){
void FilesystemWidget::fileViewActivated(const QModelIndex &idx){
QModelIndex real = mFileProxy->mapToSource(idx);
- if(mModel->isDir(real)){
+ if(mFileModel->isDir(real)){
if(idx.data().toString() == ".."){
parentDir();
return;
}
fileView()->selectionModel()->select(idx, QItemSelectionModel::Deselect);
- mDirView->setCurrentIndex(mDirProxy->mapFromSource(real));
+ QModelIndex curDir = mModel->index(real.data(SmDirModel::FullPathRole).toString());
+ mDirView->setCurrentIndex(mDirProxy->mapFromSource(curDir));
return;
}
- QString path = mModel->filePath(real);
+ QString path = real.data(SmDirModel::FullPathRole).toString();
QString mt = Helper::mimeType(path);
QStringList programArgs;
QString program;
@@ -215,32 +223,20 @@ void FilesystemWidget::goBack(){
}
void FilesystemWidget::deleteFiles(){
- QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(mFileView->model());
+ QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(mFileView->model());
QModelIndexList selected = mFileView->selectionModel()->selectedRows();
- int count(0);
- if(!selected.isEmpty()){
- count = selected.count();
- QString message = QString(tr("Really delete %1 files?")).arg(QString::number(selected.count()));
- int retval = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No);
- if(retval == QMessageBox::Yes){
- foreach(QModelIndex idx, selected){
- QModelIndex real = proxy->mapToSource(idx);
- deleteRecursive(mModel->fileInfo(real));
- }
- }
- mFileView->selectionModel()->clearSelection();
- }else{
- count = 1;
- QModelIndex cur = mFileView->currentIndex();
- QModelIndex real = proxy->mapToSource(cur);
- QString message = QString(tr("Really delete %1?")).arg(mModel->fileName(real));
- int retval = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No);
- if(retval == QMessageBox::Yes){
- deleteRecursive(mModel->fileInfo(real));
- }
- }
- QString message = QString(tr("Deleted %1 file(s)")).arg(count);
- emit statusbarMessage(message);
+ if(selected.isEmpty()){
+ return;
+ }
+
+ QString message = QString(tr("Really delete %1 files?")).arg(QString::number(selected.count()));
+ int retval = QMessageBox::question(this, tr("Question"), message, QMessageBox::Yes | QMessageBox::No);
+ if(retval == QMessageBox::Yes){
+ foreach(QModelIndex idx, selected){
+ QModelIndex real = proxy->mapToSource(idx);
+ deleteRecursive(mFileModel->fileInfo(real));
+ }
+ }
}
void FilesystemWidget::toClipboard(int clipmode){
@@ -254,10 +250,10 @@ void FilesystemWidget::toClipboard(int clipmode){
}
QList<QUrl> files;
foreach(QModelIndex idx, selected){
- if(idx.data(QFileSystemModel::FileNameRole).toString() == ".."){
+ if(idx.data(SmDirModel::NameRole).toString() == ".."){
continue;
}
- files << QUrl::fromLocalFile(idx.data(QFileSystemModel::FilePathRole).toString());
+ files << QUrl::fromLocalFile(idx.data(SmDirModel::FullPathRole).toString());
mModel->markForClipboard(mFileProxy->mapToSource(idx));
}
QMimeData *mimeData = new QMimeData;
@@ -540,9 +536,9 @@ void FilesystemWidget::dirCollapsed(const QModelIndex &idx){
}
void FilesystemWidget::fileEditorClosed(const QModelIndex &idx){
- QModelIndex real = mDirProxy->mapFromSource(idx);
+ QModelIndex real = mFileProxy->mapFromSource(idx);
if(real.isValid()){
- mDirView->update(real);
+ mFileView->update(real);
}
}
@@ -552,10 +548,8 @@ QStringList FilesystemWidget::selectedFiles(){
if(selected.isEmpty()){
return QStringList();
}
- QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(fileView()->model());
foreach(QModelIndex idx, selected){
- QModelIndex src = proxy->mapToSource(idx);
- retval << mModel->filePath(src);
+ retval << idx.data(SmDirModel::FullPathRole).toString();
}
return retval;
}