summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2010-05-10 15:41:08 +0200
committerArno <am@disconnect.de>2010-05-10 15:41:08 +0200
commit9f0caecf7875f998dc9c85d4f35f985335222d67 (patch)
tree0cd54108b7461d7944194e8e46e7b95859788230
parent2038b81df36cc44b63c44313a4fe39557c850760 (diff)
downloadSheMov-9f0caecf7875f998dc9c85d4f35f985335222d67.tar.gz
SheMov-9f0caecf7875f998dc9c85d4f35f985335222d67.tar.bz2
SheMov-9f0caecf7875f998dc9c85d4f35f985335222d67.zip
Implemented read/write settings at startup/exit
The window position and size is now written to disk on exit and read on startup. Also, the expanded directories from the tree are saved and restored. This means I can get rid of this ugly expand dirs on startup thing. Never liked it very much.
-rw-r--r--filesystemwidget.cpp76
-rw-r--r--filesystemwidget.h6
-rw-r--r--shemov.cpp30
-rw-r--r--shemov.h5
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;
diff --git a/shemov.cpp b/shemov.cpp
index b4b7327..53ae8de 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -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);
+ }
+}
diff --git a/shemov.h b/shemov.h
index 78cd664..7b79372 100644
--- a/shemov.h
+++ b/shemov.h
@@ -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;