diff --git a/fm/src/mainwindow.cpp b/fm/src/mainwindow.cpp index df1e39a..29416eb 100644 --- a/fm/src/mainwindow.cpp +++ b/fm/src/mainwindow.cpp @@ -48,6 +48,37 @@ #ifdef Q_OS_MAC #include #endif +void MainWindow::loadSession() +{ + QString sessionFileName=Common::configDir()+"/session"; + QFile sessionFile(sessionFileName); + if(!sessionFile.open(QIODevice::ReadWrite)) {qDebug()<<"failed to open session file";return;} + QString data=sessionFile.readAll(); + + QStringList lines=data.split("\n"); + if(!lines.size()) return; + for(int ii=0;iiaddNewTab(pathname,0); + } + int startTab=0; + tree->setCurrentIndex(modelTree->mapFromSource(modelList->index( tabs->tabData(startTab).toString() ))); + tabs->setCurrentIndex(startTab); +} +void MainWindow::saveSession() +{ + QString sessionFileName=Common::configDir()+"/session"; + QFile sessionFile(sessionFileName); + if(!sessionFile.open(QIODevice::ReadWrite|QIODevice::Truncate)) {qDebug()<<"failed to find session file";return;} + if(!tabs->count()) { sessionFile.write(pathEdit->currentText().toUtf8()); sessionFile.write("\n");} + for(int ii=0;iicount();ii++){ + QString pathname=tabs->tabData(ii).toString(); + sessionFile.write( pathname.toUtf8() );sessionFile.write("\n"); + } + sessionFile.close(); +} MainWindow::MainWindow() { @@ -256,6 +287,12 @@ MainWindow::MainWindow() qApp->installEventFilter(this); QTimer::singleShot(0, this, SLOT(lateStart())); +} +MainWindow::~MainWindow() +{ + if(settings->value("saveSession",true).toBool()) { + saveSession(); + } } //--------------------------------------------------------------------------- @@ -398,7 +435,11 @@ void MainWindow::lateStart() { QTimer::singleShot(100, customActManager, SLOT(readActions())); // Read defaults - QTimer::singleShot(100, mimeUtils, SLOT(generateDefaults())); + QTimer::singleShot(100, mimeUtils, SLOT(generateDefaults())); + if(settings->value("saveSession",true).toBool()) { + loadSession(); + } + } //--------------------------------------------------------------------------- diff --git a/fm/src/mainwindow.h b/fm/src/mainwindow.h index 30d88ba..5175892 100644 --- a/fm/src/mainwindow.h +++ b/fm/src/mainwindow.h @@ -79,6 +79,9 @@ class MainWindow : public QMainWindow public: MainWindow(); myModel *modelList; + ~MainWindow(); + void loadSession(); + void saveSession(); protected: void closeEvent(QCloseEvent *event); diff --git a/fm/src/settingsdialog.cpp b/fm/src/settingsdialog.cpp index db915e6..0259ea9 100644 --- a/fm/src/settingsdialog.cpp +++ b/fm/src/settingsdialog.cpp @@ -77,6 +77,7 @@ SettingsDialog::SettingsDialog(QList *actionList, selector->addItem(new QListWidgetItem(icon4, tr("System Tray"), selector)); #endif selector->addItem(new QListWidgetItem(icon4, tr("Advanced"), selector)); + selector->addItem(new QListWidgetItem(icon4, tr("Session"), selector)); stack->addWidget(createGeneralSettings()); stack->addWidget(createAppearanceSettings()); @@ -87,6 +88,7 @@ SettingsDialog::SettingsDialog(QList *actionList, stack->addWidget(createSystraySettings()); #endif stack->addWidget(createAdvSettings()); + stack->addWidget(createSessionSettings()); connect(selector, SIGNAL(currentRowChanged(int)), @@ -496,6 +498,18 @@ QWidget *SettingsDialog::createAdvSettings() return widget; } +QWidget *SettingsDialog::createSessionSettings() +{ + // + QWidget *widget = new QWidget(); + QVBoxLayout* layoutWidget = new QVBoxLayout(widget); + checkSaveSession=new QCheckBox("Save tabs on exit"); + bool flgSaveSession=settingsPtr->value("saveSession",true).toBool(); + checkSaveSession->setChecked(flgSaveSession); + layoutWidget->addWidget(checkSaveSession); + return widget; +} + //--------------------------------------------------------------------------- /** @@ -748,6 +762,7 @@ void SettingsDialog::readSettings() { } settingsPtr->endGroup(); + checkSaveSession->setChecked(settingsPtr->value("saveSession",true).toBool()); // Loads icons for actions for (int x = 0; x < actionsWidget->topLevelItemCount(); x++) { QApplication::processEvents(); @@ -964,6 +979,10 @@ bool SettingsDialog::saveSettings() { settingsPtr->setValue(number, temp); } settingsPtr->endGroup(); + + bool flgSaveSession=checkSaveSession->isChecked(); + settingsPtr->setValue("saveSession",flgSaveSession ); + settingsPtr->setValue("customHeader", actionsWidget->header()->saveState()); // Shortcuts diff --git a/fm/src/settingsdialog.h b/fm/src/settingsdialog.h index ab6279c..9a7250b 100644 --- a/fm/src/settingsdialog.h +++ b/fm/src/settingsdialog.h @@ -62,6 +62,7 @@ protected slots: QWidget* createMimeSettings(); QWidget* createSystraySettings(); QWidget* createAdvSettings(); + QWidget* createSessionSettings(); MimeUtils* mimeUtilsPtr; QSettings* settingsPtr; QList *actionListPtr; @@ -99,6 +100,7 @@ protected slots: QCheckBox* checkWindowTitlePath; QLineEdit* editCopyX; QLineEdit* editCopyTS; + QCheckBox* checkSaveSession; }; #endif // SETTINGSDIALOG_H