Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session auto-save on exit ( Supersedes #154 ) #170

Draft
wants to merge 2 commits into
base: 6.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion fm/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,37 @@
#ifdef Q_OS_MAC
#include <QStyleFactory>
#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;ii<lines.size();ii++)
{
QString pathname=lines[ii];
if(pathname.isEmpty()) continue;
tabs->addNewTab(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;ii<tabs->count();ii++){
QString pathname=tabs->tabData(ii).toString();
sessionFile.write( pathname.toUtf8() );sessionFile.write("\n");
}
sessionFile.close();
}

MainWindow::MainWindow()
{
Expand Down Expand Up @@ -256,6 +287,12 @@ MainWindow::MainWindow()
qApp->installEventFilter(this);

QTimer::singleShot(0, this, SLOT(lateStart()));
}
MainWindow::~MainWindow()
{
if(settings->value("saveSession",true).toBool()) {
saveSession();
}
}
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -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();
}

}
//---------------------------------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions fm/src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class MainWindow : public QMainWindow
public:
MainWindow();
myModel *modelList;
~MainWindow();
void loadSession();
void saveSession();

protected:
void closeEvent(QCloseEvent *event);
Expand Down
19 changes: 19 additions & 0 deletions fm/src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ SettingsDialog::SettingsDialog(QList<QAction *> *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());
Expand All @@ -87,6 +88,7 @@ SettingsDialog::SettingsDialog(QList<QAction *> *actionList,
stack->addWidget(createSystraySettings());
#endif
stack->addWidget(createAdvSettings());
stack->addWidget(createSessionSettings());

connect(selector,
SIGNAL(currentRowChanged(int)),
Expand Down Expand Up @@ -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;
}

//---------------------------------------------------------------------------

/**
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions fm/src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ protected slots:
QWidget* createMimeSettings();
QWidget* createSystraySettings();
QWidget* createAdvSettings();
QWidget* createSessionSettings();
MimeUtils* mimeUtilsPtr;
QSettings* settingsPtr;
QList<QAction*> *actionListPtr;
Expand Down Expand Up @@ -99,6 +100,7 @@ protected slots:
QCheckBox* checkWindowTitlePath;
QLineEdit* editCopyX;
QLineEdit* editCopyTS;
QCheckBox* checkSaveSession;
};

#endif // SETTINGSDIALOG_H