summaryrefslogtreecommitdiffstats
path: root/fileview.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-12-22 10:43:59 +0100
committerArno <am@disconnect.de>2010-12-22 10:43:59 +0100
commit270b5d60263c66c170ca37ac6d19c0df5060c981 (patch)
tree3c5203d53a6bbc19e91d136e21fe109c1b7fe7a6 /fileview.cpp
parentf3d62ad86a1def4d11d132af7366874f43a438b9 (diff)
downloadSheMov-270b5d60263c66c170ca37ac6d19c0df5060c981.tar.gz
SheMov-270b5d60263c66c170ca37ac6d19c0df5060c981.tar.bz2
SheMov-270b5d60263c66c170ca37ac6d19c0df5060c981.zip
Removed last instances of MessageDialog
Removed two instances of MessageDialog from FileView and replaced them with QInputDialogs. Also got rid of the awkward doCreateFolder and doMark slots.
Diffstat (limited to 'fileview.cpp')
-rw-r--r--fileview.cpp94
1 files changed, 34 insertions, 60 deletions
diff --git a/fileview.cpp b/fileview.cpp
index 331c7b8..0670bd1 100644
--- a/fileview.cpp
+++ b/fileview.cpp
@@ -23,11 +23,9 @@
#include <QList>
#include <QDir>
#include <QSortFilterProxyModel>
-
-#include <QDebug>
+#include <QInputDialog>
#include "fileview.h"
-#include "messagedialog.h"
#include "hoverwindow.h"
#include "smglobals.h"
#include "helper.h"
@@ -35,13 +33,6 @@
FileView::FileView(QWidget *parent) : QTreeView(parent), mDeleteA(0) {
setAttribute(Qt::WA_Hover);
setRootIsDecorated(false);
- QString title = QString("%1 - %2");
- QString markTitle = title.arg(qApp->applicationName(), tr("Mark files"));
- mMarkDialog = new MessageDialog(tr("Enter pattern to mark"), markTitle, this);
- connect(mMarkDialog, SIGNAL(accepted()), this, SLOT(doMark()));
- QString folderTitle = title.arg(qApp->applicationName(), tr("Create folder"));
- mCreateFolderDialog = new MessageDialog(tr("Enter folder name"), folderTitle, this);
- connect(mCreateFolderDialog, SIGNAL(accepted()), this, SLOT(doCreateFolder()));
mHoverWin = new HoverWindow;
QSize curSize = SmGlobals::instance()->cursorSize();
mHoverWin->setHoverOffset(QPoint(curSize.width() + 30, 0));
@@ -49,7 +40,26 @@ FileView::FileView(QWidget *parent) : QTreeView(parent), mDeleteA(0) {
}
void FileView::markFiles(){
- mMarkDialog->show();
+ bool ok;
+ QString title = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(tr("Mark files"));
+ QString glob = QInputDialog::getText(this, title, tr("Enter filename pattern"), QLineEdit::Normal, QString(), &ok);
+ if(!ok){
+ return;
+ }
+ int rowCount = model()->rowCount(rootIndex());
+ if(!rowCount || glob.isEmpty()){
+ return;
+ }
+ QRegExp re(glob);
+ for(int i = 0; i < rowCount; ++i){
+ QModelIndex cur = rootIndex().child(i, 0);
+ if(cur.data(QFileSystemModel::FileNameRole).toString() == ".."){
+ continue;
+ }
+ if(re.indexIn(cur.data(QFileSystemModel::FileNameRole).toString()) != -1){
+ selectionModel()->select(cur, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ }
+ }
}
void FileView::unmarkFiles(){
@@ -57,7 +67,19 @@ void FileView::unmarkFiles(){
}
void FileView::createFolder(){
- mCreateFolderDialog->show();
+ bool ok;
+ QString title = QString(tr("%1 - %2")).arg(qApp->applicationName()).arg(tr("Mark files"));
+ QString folderName = QInputDialog::getText(this, title, tr("Enter new folder name"), QLineEdit::Normal, QString(), &ok);
+ if(!ok){
+ return;
+ }
+ if(!ok || folderName.isEmpty()){
+ return;
+ }
+ QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(model());
+ QFileSystemModel *fsModel = qobject_cast<QFileSystemModel*>(proxy->sourceModel());
+ QModelIndex root = proxy->mapToSource(rootIndex());
+ fsModel->mkdir(root, folderName);
}
void FileView::readConfig(){
@@ -76,54 +98,6 @@ void FileView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint h
emit editorClosed(sourceIdx);
}
-void FileView::doMark(){
- int rowCount = model()->rowCount(rootIndex());
- QString sRegex = mMarkDialog->text();
- if(rowCount && !sRegex.isEmpty()){
- QRegExp re(sRegex);
- QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(model());
- QFileSystemModel *model = static_cast<QFileSystemModel*>(proxy->sourceModel());
- bool match(false);
- for(int i = 0; i < rowCount; ++i){
- QModelIndex cur = rootIndex().child(i, 0);
- QModelIndex sCur = proxy->mapToSource(cur);
- if(model->isDir(sCur)){
- continue;
- }
- if(re.indexIn(cur.data().toString()) != -1){
- selectionModel()->select(cur, QItemSelectionModel::Select | QItemSelectionModel::Rows);
- match = true;
- }
- }
- if(match){
- statusbarMessage(QString());
- }else{
- emit statusbarMessage(tr("No match found!"));
- }
- }else{
- emit statusbarMessage(tr("Nothing to mark!"));
- }
-}
-
-void FileView::doCreateFolder(){
- QString folderName = mCreateFolderDialog->text();
- if(folderName.isEmpty()){
- emit statusbarMessage(tr("No foldername given!"));
- return;
- }
- QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(model());
- QFileSystemModel *model = static_cast<QFileSystemModel*>(proxy->sourceModel());
- QModelIndex sRoot = proxy->mapToSource(rootIndex());
- QModelIndex newIdx = model->mkdir(sRoot, folderName);
- if(newIdx == QModelIndex()){
- QString msg = QString(tr("Failed to create %1/%2")).arg(model->filePath(sRoot)).arg(folderName);
- emit statusbarMessage(msg);
- }else{
- QString msg = QString(tr("Created folder %1")).arg(model->filePath(newIdx));
- emit statusbarMessage(msg);
- }
-}
-
void FileView::contextMenuEvent(QContextMenuEvent *e){
QMenu contextMenu(this);
foreach(QAction *a, actions()){