diff options
author | Arno <am@disconnect.de> | 2010-12-22 10:43:59 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-12-22 10:43:59 +0100 |
commit | 270b5d60263c66c170ca37ac6d19c0df5060c981 (patch) | |
tree | 3c5203d53a6bbc19e91d136e21fe109c1b7fe7a6 | |
parent | f3d62ad86a1def4d11d132af7366874f43a438b9 (diff) | |
download | SheMov-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.
-rw-r--r-- | fileview.cpp | 94 | ||||
-rw-r--r-- | fileview.h | 7 |
2 files changed, 34 insertions, 67 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()){ @@ -13,7 +13,6 @@ class QContextMenuEvent; class QKeyEvent; class QResizeEvent; -class MessageDialog; class QModelIndex; class QAction; class HoverWindow; @@ -42,10 +41,6 @@ class FileView : public QTreeView { protected slots: virtual void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint); - private slots: - void doMark(); - void doCreateFolder(); - protected: virtual void contextMenuEvent(QContextMenuEvent *e); virtual void keyPressEvent(QKeyEvent *e); @@ -56,8 +51,6 @@ class FileView : public QTreeView { enum HoverFileType { Dir, Movie, Image, None }; bool exitHover(bool exitVal = true); void doHover(const QFileInfo &fi, int type); - MessageDialog *mMarkDialog; - MessageDialog *mCreateFolderDialog; QAction *mDeleteA; HoverWindow *mHoverWin; QModelIndex mCurHover; |