diff options
-rw-r--r-- | filesystemwidget.cpp | 76 | ||||
-rw-r--r-- | filesystemwidget.h | 6 | ||||
-rw-r--r-- | shemov.cpp | 30 | ||||
-rw-r--r-- | shemov.h | 5 |
4 files changed, 90 insertions, 27 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index bd02098..187d92c 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -82,29 +82,13 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { fileWidget->setLayout(fwLayout); connect(mDirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(directoryChanged(const QModelIndex &, const QModelIndex &))); + connect(mDirView, SIGNAL(expanded(QModelIndex)), this, SLOT(dirExpanded(QModelIndex))); + connect(mDirView, SIGNAL(collapsed(QModelIndex)), this, SLOT(dirCollapsed(QModelIndex))); connect(mFileView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(fileViewActivated(const QModelIndex &))); connect(mFileView, SIGNAL(enterPressed(const QModelIndex &)), this, SLOT(fileViewActivated(const QModelIndex &))); connect(mFileView, SIGNAL(upDir()), this, SLOT(parentDir())); connect(mDirEdit, SIGNAL(returnPressed()), this, SLOT(directoryEdited())); - QSettings s; - QStringList expandPaths = s.value("ui/expandpaths").toStringList(); - QString last; - foreach(QString p, expandPaths){ - QModelIndex idx = mModel->index(p); - last = p; - if(idx.isValid()){ - QModelIndex proxy = mDirProxy->mapFromSource(idx); - mDirView->setExpanded(proxy, true); - expandParents(proxy); - } - } - QString select = s.value("ui/selectstartup").toString(); - windowTitle(select); - setWindowTitle(select); - QModelIndex sel = mModel->index(select); - mDirView->setCurrentIndex(mDirProxy->mapFromSource(sel)); - mFileView->resizeColumnToContents(0); QVBoxLayout *mainLayout = new QVBoxLayout; @@ -407,6 +391,42 @@ void FilesystemWidget::playSelected(){ QProcess::startDetached(program, programArgs); } +void FilesystemWidget::readSettings(){ + QSettings s; + QStringList expandedDirs = s.value("paths/expandeddirs").toStringList(); + if(expandedDirs.isEmpty()){ + expandedDirs << QDir::homePath(); + } + foreach(QString p, expandedDirs){ + QModelIndex idx = mModel->index(p); + if(idx.isValid()){ + QModelIndex pidx = mDirProxy->mapFromSource(idx); + if(pidx.isValid()){ + mDirView->setExpanded(pidx, true); + } + } + } + QString selectedDir = s.value("paths/selecteddir").toString(); + if(!selectedDir.isEmpty()){ + QModelIndex diridx = mModel->index(selectedDir); + if(diridx.isValid()){ + QModelIndex pidx = mDirProxy->mapFromSource(diridx); + mDirView->selectionModel()->setCurrentIndex(pidx, QItemSelectionModel::ClearAndSelect); + } + } +} + +void FilesystemWidget::writeSettings(){ + QSettings s; + s.setValue("paths/expandeddirs", mExpandedDirs); + QModelIndex currentDir = mDirView->selectionModel()->currentIndex(); + if(currentDir.isValid()){ + QModelIndex real = mDirProxy->mapToSource(currentDir); + QString dir = mModel->filePath(real); + s.setValue("paths/selecteddir", dir); + } +} + void FilesystemWidget::setWindowTitle(const QString &dir){ mWindowTitle = QString("%1 - %2").arg(qApp->applicationName()).arg(dir); emit windowTitle(mWindowTitle); @@ -466,14 +486,20 @@ void FilesystemWidget::doRenameFile(){ emit newTemplate(mTemplate); } -void FilesystemWidget::expandParents(const QModelIndex &idx){ - if(idx.isValid()){ - QModelIndex parent = idx.parent(); - do{ - mDirView->setExpanded(parent, true); - parent = parent.parent(); +void FilesystemWidget::dirExpanded(const QModelIndex &idx){ + QModelIndex real = mDirProxy->mapToSource(idx); + if(real.isValid()){ + mExpandedDirs << mModel->filePath(real); + } +} - }while(parent.isValid()); +void FilesystemWidget::dirCollapsed(const QModelIndex &idx){ + QModelIndex real = mDirProxy->mapToSource(idx); + if(real.isValid()){ + QString path = mModel->filePath(real); + if(mExpandedDirs.contains(path)){ + mExpandedDirs.removeAll(path); + } } } diff --git a/filesystemwidget.h b/filesystemwidget.h index 0191065..6e8523c 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -54,16 +54,20 @@ class FilesystemWidget : public QWidget { void archiveFiles(); void refreshDir(const QString &dir); void playSelected(); + void readSettings(); + void writeSettings(); private slots: void doRenameFile(); + void dirExpanded(const QModelIndex &idx); + void dirCollapsed(const QModelIndex &idx); private: void setWindowTitle(const QString &dir); void deleteRecursive(const QFileInfo &start); void copyRecursive(const QFileInfo &start, const QString &destdir); - void expandParents(const QModelIndex &idx); QStringList selectedFiles(); + QStringList mExpandedDirs; QAction *action(QWidget *widget, const QVariant &data) const; QDirModel *mModel; QTreeView *mDirView; @@ -24,6 +24,7 @@ #include <QFont> #include <QFontMetrics> #include <QLocale> +#include <QCloseEvent> #include <sys/vfs.h> #include "shemov.h" @@ -101,10 +102,18 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla QWidget *centralWidget = new QWidget; centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); - showMaximized(); + readSettings(); + mFSWidget->readSettings(); + show(); mFSWidget->fileView()->setFocus(Qt::ActiveWindowFocusReason); } +void SheMov::closeEvent(QCloseEvent *event){ + mFSWidget->writeSettings(); + writeSettings(); + event->accept(); +} + void SheMov::updateSelectionCount(const QItemSelection & /* sel */, const QItemSelection & /* prev */){ QLocale l; switch (mTab->currentIndex()) { @@ -444,3 +453,22 @@ void SheMov::createExtractMenu(){ } } +void SheMov::writeSettings(){ + QSettings s; + s.setValue("windows/mainpos", pos()); + s.setValue("windows/mainsize", size()); + bool winState = windowState() & Qt::WindowMaximized; + s.setValue("windows/maximized", winState); +} + +void SheMov::readSettings(){ + QSettings s; + QPoint winPos = s.value("windwos/mainpos").toPoint(); + QSize winSize = s.value("windows/mainsize").toSize(); + bool winState = s.value("windows/maximized", false).toBool(); + resize(winSize); + move(winPos); + if(winState){ + setWindowState(Qt::WindowMaximized); + } +} @@ -32,6 +32,9 @@ class SheMov : public QMainWindow { SheMov(QWidget *parent = 0, Qt::WindowFlags flags = 0); ~SheMov() {}; + protected: + virtual void closeEvent(QCloseEvent *event); + private slots: void updateSelectionCount(const QItemSelection &sel, const QItemSelection &prev); void newWindowTitle(const QString &title); @@ -48,6 +51,8 @@ class SheMov : public QMainWindow { void createActions(); void createMenus(); void createExtractMenu(); + void writeSettings(); + void readSettings(); //Statusbar Items QLabel *mSelectedItems; |