[konqueror] src: Allow to save a session only including the current window
Martin Koller
null at kde.org
Sat Jan 14 16:56:49 UTC 2017
Git commit 06c11dd8ce9771fa90bf0f1de39c486d061ed758 by Martin Koller.
Committed on 14/01/2017 at 16:53.
Pushed by mkoller into branch 'master'.
Allow to save a session only including the current window
REVIEW: 129735
GUI: new selection dialog for single/all windows
M +1 -1 src/konqmainwindow.cpp
M +39 -31 src/konqnewsessiondlg_base.ui
M +24 -14 src/konqsessiondlg.cpp
M +3 -1 src/konqsessiondlg.h
M +26 -25 src/konqsessiondlg_base.ui
M +16 -6 src/konqsessionmanager.cpp
M +3 -2 src/konqsessionmanager.h
https://commits.kde.org/konqueror/06c11dd8ce9771fa90bf0f1de39c486d061ed758
diff --git a/src/konqmainwindow.cpp b/src/konqmainwindow.cpp
index e9e2eb7bf..0cf0f4bc9 100644
--- a/src/konqmainwindow.cpp
+++ b/src/konqmainwindow.cpp
@@ -2867,7 +2867,7 @@ void KonqMainWindow::slotSessionsListAboutToShow()
void KonqMainWindow::saveCurrentSession()
{
- KonqNewSessionDlg dlg(this);
+ KonqNewSessionDlg dlg(this, this);
dlg.exec();
}
diff --git a/src/konqnewsessiondlg_base.ui b/src/konqnewsessiondlg_base.ui
index 454e16170..2108a04c8 100644
--- a/src/konqnewsessiondlg_base.ui
+++ b/src/konqnewsessiondlg_base.ui
@@ -1,59 +1,67 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>KonqNewSessionDlgBase</class>
- <widget class="QWidget" name="KonqNewSessionDlgBase" >
- <property name="geometry" >
+ <widget class="QWidget" name="KonqNewSessionDlgBase">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
- <height>75</height>
+ <height>163</height>
</rect>
</property>
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <layout class="QVBoxLayout" name="verticalLayout" >
- <property name="sizeConstraint" >
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
- <widget class="QLabel" name="lblDescription" >
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text" >
- <string>Save open tabs and windows for easy retrieval</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- <property name="buddy" >
- <cstring>m_pSessionName</cstring>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>Save open &tabs and windows for easy retrieval</string>
</property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <widget class="QRadioButton" name="m_pAllWindows">
+ <property name="text">
+ <string>A&ll open windows</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="m_pCurrentWindow">
+ <property name="text">
+ <string>Onl&y current window</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
</widget>
</item>
<item>
- <layout class="QHBoxLayout" name="horizontalLayout" >
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QLabel" name="lblSessionName" >
- <property name="text" >
- <string>&Session name:</string>
+ <widget class="QLabel" name="lblSessionName">
+ <property name="text">
+ <string>Session n&ame:</string>
</property>
- <property name="buddy" >
+ <property name="buddy">
<cstring>m_pSessionName</cstring>
</property>
</widget>
</item>
<item>
- <widget class="KLineEdit" name="m_pSessionName" />
+ <widget class="KLineEdit" name="m_pSessionName"/>
</item>
</layout>
</item>
diff --git a/src/konqsessiondlg.cpp b/src/konqsessiondlg.cpp
index f33e0f8c7..ed899394f 100644
--- a/src/konqsessiondlg.cpp
+++ b/src/konqsessiondlg.cpp
@@ -21,6 +21,7 @@
#include "konqsettingsxt.h"
#include "konqviewmanager.h"
#include "konqsessionmanager.h"
+#include "konqmainwindow.h"
#include "ui_konqsessiondlg_base.h"
#include "ui_konqnewsessiondlg_base.h"
@@ -128,7 +129,7 @@ void KonqSessionDlg::slotOpen()
KonqSessionManager::self()->restoreSessions(d->m_pModel->itemForIndex(
d->m_pListView->currentIndex()).url().path(),
d->m_pOpenTabsInsideCurrentWindow->isChecked(),
- reinterpret_cast<KonqMainWindow *>(parent()));
+ d->m_pViewManager->mainWindow());
close();
}
@@ -140,15 +141,16 @@ void KonqSessionDlg::slotSave()
QFileInfo fileInfo(
d->m_pModel->itemForIndex(d->m_pListView->currentIndex()).url().path());
- QString dirpath = "sessions/" + KIO::encodeFileName(fileInfo.fileName());
- slotDelete();
- KonqSessionManager::self()->saveCurrentSessions(dirpath);
+ KonqNewSessionDlg newDialog(this, d->m_pViewManager->mainWindow(),
+ KIO::encodeFileName(fileInfo.fileName()), KonqNewSessionDlg::ReplaceFile);
+
+ newDialog.exec();
}
void KonqSessionDlg::slotNew()
{
- KonqNewSessionDlg newDialog(this);
+ KonqNewSessionDlg newDialog(this, d->m_pViewManager->mainWindow());
newDialog.exec();
}
@@ -205,17 +207,20 @@ class KonqNewSessionDlg::KonqNewSessionDlgPrivate : public QWidget,
public Ui::KonqNewSessionDlgBase
{
public:
- KonqNewSessionDlgPrivate(QWidget *parent = Q_NULLPTR)
- : QWidget(parent), m_pParent(parent)
+ KonqNewSessionDlgPrivate(QWidget *parent = Q_NULLPTR, KonqMainWindow *mainWindow = Q_NULLPTR,
+ KonqNewSessionDlg::Mode m = KonqNewSessionDlg::NewFile)
+ : QWidget(parent), m_pParent(parent), m_mainWindow(mainWindow), m_mode(m)
{
setupUi(this);
}
QWidget *m_pParent;
+ KonqMainWindow *m_mainWindow;
+ KonqNewSessionDlg::Mode m_mode;
};
-KonqNewSessionDlg::KonqNewSessionDlg(QWidget *parent, QString sessionName)
+KonqNewSessionDlg::KonqNewSessionDlg(QWidget *parent, KonqMainWindow *mainWindow, QString sessionName, Mode mode)
: KDialog(parent)
- , d(new KonqNewSessionDlgPrivate(this))
+ , d(new KonqNewSessionDlgPrivate(this, mainWindow, mode))
{
d->layout()->setMargin(0);
setMainWidget(d);
@@ -229,6 +234,7 @@ KonqNewSessionDlg::KonqNewSessionDlg(QWidget *parent, QString sessionName)
if (!sessionName.isEmpty()) {
d->m_pSessionName->setText(sessionName);
+ enableButton(Ok, true);
}
d->m_pSessionName->setFocus();
@@ -247,17 +253,21 @@ void KonqNewSessionDlg::slotAddSession()
QDir dir(dirpath);
if (dir.exists()) {
- if (KMessageBox::questionYesNo(this,
+ if ((d->m_mode == ReplaceFile) ||
+ KMessageBox::questionYesNo(this,
i18n("A session with the name '%1' already exists, do you want to overwrite it?", d->m_pSessionName->text()),
i18nc("@title:window", "Session exists. Overwrite?")) == KMessageBox::Yes) {
KTempDir::removeDir(dirpath);
} else {
- KonqNewSessionDlg newDialog(d->m_pParent,
- d->m_pSessionName->text());
- newDialog.exec();
+ return;
}
}
- KonqSessionManager::self()->saveCurrentSessions(dirpath);
+
+ if (d->m_pAllWindows->isChecked()) {
+ KonqSessionManager::self()->saveCurrentSessions(dirpath);
+ } else {
+ KonqSessionManager::self()->saveCurrentSessionToFile(dirpath + QLatin1String("/1"), d->m_mainWindow);
+ }
}
void KonqNewSessionDlg::slotTextChanged(const QString &text)
diff --git a/src/konqsessiondlg.h b/src/konqsessiondlg.h
index 262600cdf..3a6a19def 100644
--- a/src/konqsessiondlg.h
+++ b/src/konqsessiondlg.h
@@ -27,6 +27,7 @@
#include <QUrl>
class KonqViewManager;
+class KonqMainWindow;
/**
* This is the konqueror sesions administration dialog, which allows the user
@@ -57,7 +58,8 @@ class KonqNewSessionDlg : public KDialog
{
Q_OBJECT
public:
- explicit KonqNewSessionDlg(QWidget *parent = Q_NULLPTR, QString sessionName = QString());
+ enum Mode { NewFile, ReplaceFile };
+ explicit KonqNewSessionDlg(QWidget *parent, KonqMainWindow *mainWindow, QString sessionName = QString(), Mode mode = NewFile);
~KonqNewSessionDlg();
protected Q_SLOTS:
diff --git a/src/konqsessiondlg_base.ui b/src/konqsessiondlg_base.ui
index 7f379654f..81759d039 100644
--- a/src/konqsessiondlg_base.ui
+++ b/src/konqsessiondlg_base.ui
@@ -1,48 +1,49 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>KonqSessionDlgBase</class>
- <widget class="QWidget" name="KonqSessionDlgBase" >
- <property name="geometry" >
+ <widget class="QWidget" name="KonqSessionDlgBase">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>335</width>
- <height>187</height>
+ <height>195</height>
</rect>
</property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <layout class="QHBoxLayout" name="horizontalLayout" >
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QListView" name="m_pListView" />
+ <widget class="QListView" name="m_pListView"/>
</item>
<item>
- <layout class="QVBoxLayout" name="verticalLayout_2" >
+ <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
- <layout class="QVBoxLayout" name="verticalLayout" >
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QPushButton" name="m_pNewButton" >
- <property name="text" >
+ <widget class="QPushButton" name="m_pNewButton">
+ <property name="text">
<string comment="@action:button New session">New...</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="m_pSaveCurrentButton" >
- <property name="text" >
- <string comment="@action:button Save current session">Save Current</string>
+ <widget class="QPushButton" name="m_pSaveCurrentButton">
+ <property name="text">
+ <string comment="@action:button Save current session">Save Current...</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="m_pRenameButton" >
- <property name="text" >
+ <widget class="QPushButton" name="m_pRenameButton">
+ <property name="text">
<string comment="@action:button Rename session">Rename...</string>
</property>
</widget>
</item>
<item>
- <widget class="QPushButton" name="m_pDeleteButton" >
- <property name="text" >
+ <widget class="QPushButton" name="m_pDeleteButton">
+ <property name="text">
<string comment="@action:button Delete session">Delete</string>
</property>
</widget>
@@ -50,11 +51,11 @@
</layout>
</item>
<item>
- <spacer name="verticalSpacer" >
- <property name="orientation" >
+ <spacer name="verticalSpacer">
+ <property name="orientation">
<enum>Qt::Vertical</enum>
</property>
- <property name="sizeHint" stdset="0" >
+ <property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
@@ -66,9 +67,9 @@
</item>
</layout>
</item>
- <item row="1" column="0" >
- <widget class="QCheckBox" name="m_pOpenTabsInsideCurrentWindow" >
- <property name="text" >
+ <item row="1" column="0">
+ <widget class="QCheckBox" name="m_pOpenTabsInsideCurrentWindow">
+ <property name="text">
<string>Open tabs inside current window</string>
</property>
</widget>
diff --git a/src/konqsessionmanager.cpp b/src/konqsessionmanager.cpp
index a2b69374d..95152c54c 100644
--- a/src/konqsessionmanager.cpp
+++ b/src/konqsessionmanager.cpp
@@ -487,23 +487,33 @@ void KonqSessionManager::slotSaveCurrentSession(const QString &path)
saveCurrentSessionToFile(filename);
}
-void KonqSessionManager::saveCurrentSessionToFile(const QString &sessionConfigPath)
+void KonqSessionManager::saveCurrentSessionToFile(const QString &sessionConfigPath, KonqMainWindow *mainWindow)
{
QFile::remove(sessionConfigPath);
KConfig config(sessionConfigPath, KConfig::SimpleConfig);
- saveCurrentSessionToFile(&config);
+
+ QList<KonqMainWindow *> mainWindows;
+ if (mainWindow) {
+ mainWindows << mainWindow;
+ }
+ saveCurrentSessionToFile(&config, mainWindows);
}
-void KonqSessionManager::saveCurrentSessionToFile(KConfig *config)
+void KonqSessionManager::saveCurrentSessionToFile(KConfig *config, const QList<KonqMainWindow *> &theMainWindows)
{
- QList<KonqMainWindow *> *mainWindows = KonqMainWindow::mainWindowList();
+ QList<KonqMainWindow *> mainWindows = theMainWindows;
+
+ if (mainWindows.isEmpty() && KonqMainWindow::mainWindowList()) {
+ mainWindows = *KonqMainWindow::mainWindowList();
+ }
+
unsigned int counter = 0;
- if (!mainWindows || mainWindows->isEmpty()) {
+ if (mainWindows.isEmpty()) {
return;
}
- foreach (KonqMainWindow *window, *mainWindows) {
+ foreach (KonqMainWindow *window, mainWindows) {
KConfigGroup configGroup(config, "Window" + QString::number(counter));
window->saveProperties(configGroup);
counter++;
diff --git a/src/konqsessionmanager.h b/src/konqsessionmanager.h
index b1a06bfef..75be9b52f 100644
--- a/src/konqsessionmanager.h
+++ b/src/konqsessionmanager.h
@@ -152,8 +152,9 @@ public:
/**
* Save current session in a given path (absolute path to a file)
+ * @param mainWindow if 0, all windows will be saved, else only the given one
*/
- void saveCurrentSessionToFile(const QString &sessionConfig);
+ void saveCurrentSessionToFile(const QString &sessionConfigPath, KonqMainWindow *mainWindow = Q_NULLPTR);
/**
* Returns the autosave directory
@@ -204,7 +205,7 @@ private:
return m_autosaveDir + "/owned_by" + m_baseService;
}
- void saveCurrentSessionToFile(KConfig *);
+ void saveCurrentSessionToFile(KConfig *config, const QList<KonqMainWindow *> &mainWindows = QList<KonqMainWindow *>());
private:
QTimer m_autoSaveTimer;
QString m_autosaveDir;
More information about the kde-doc-english
mailing list