From 80828dcd0a812149993c04d81c24a8d8bd2e971f Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 30 Mar 2013 14:47:03 +0100 Subject: Implement session saving, inspired from kate session management (or at least, for what I see...) Added session manager widget and ability to load/save/rename sessions --- src/CMakeLists.txt | 2 + src/rekonq.kcfg | 5 +- src/session.ui | 66 +++++++++++++++++++++++ src/sessionmanager.cpp | 40 +++++++++++--- src/sessionmanager.h | 6 ++- src/sessionwidget.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++ src/sessionwidget.h | 62 +++++++++++++++++++++ src/webwindow/rekonqui.rc | 8 +-- src/webwindow/webwindow.cpp | 8 +-- 9 files changed, 302 insertions(+), 24 deletions(-) create mode 100644 src/session.ui create mode 100644 src/sessionwidget.cpp create mode 100644 src/sessionwidget.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3e84d13d..f88c396f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,7 @@ set(rekonq_KDEINIT_SRCS autosaver.cpp searchengine.cpp sessionmanager.cpp + sessionwidget.cpp urlresolver.cpp websnap.cpp #---------------------------------------- @@ -166,6 +167,7 @@ KDE4_ADD_UI_FILES( rekonq_KDEINIT_SRCS webtab/sslinfo.ui # ---------------------------------------- cleardata.ui + session.ui webappcreation.ui ) diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index 3997587d..152b83bf 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -62,7 +62,10 @@ false - + + + + diff --git a/src/session.ui b/src/session.ui new file mode 100644 index 00000000..2f32edaf --- /dev/null +++ b/src/session.ui @@ -0,0 +1,66 @@ + + + Session + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + + + + + + + + + + Save + + + + + + + Load + + + + + + + Delete + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index 9aa02560..00a3064e 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -33,6 +33,7 @@ // Local Includes #include "application.h" #include "tabhistory.h" +#include "sessionwidget.h" #include "rekonqwindow.h" #include "tabbar.h" @@ -41,12 +42,15 @@ #include "webpage.h" // KDE Includes +#include +#include #include #include // Qt Includes #include #include +#include // Only used internally @@ -374,18 +378,20 @@ QList SessionManager::closedSitesForWindow(const QString &windowName // ------------------------------------------------------------------------------------------------------- -bool SessionManager::saveYourSession() +bool SessionManager::saveYourSession(int index) { kDebug() << "SAVING YOUR OWN SESSION..."; - const QString & sessionName = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); + const QString & sessionPath = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); + const QString & sessionName = QL1S("ses") + QString::number(index); - QFile sessionFile(sessionName + QL1S("prova")); // FIXME + QFile sessionFile(sessionPath + sessionName); if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate)) { kDebug() << "Unable to open session file" << sessionFile.fileName(); - return true; + return false; } + RekonqWindowList wl = rApp->rekonqWindowList(); QDomDocument document("session"); QDomElement session = document.createElement("session"); @@ -437,16 +443,17 @@ bool SessionManager::saveYourSession() sessionFile.close(); return true; - } -bool SessionManager::restoreYourSession() +bool SessionManager::restoreYourSession(int index) { - const QString & sessionName = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); + const QString & sessionPath = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); + const QString & sessionName = QL1S("ses") + QString::number(index); + QDomDocument document("session"); - if (!readSessionDocument(document,sessionName + QL1S("prova"))) // FIXME + if (!readSessionDocument(document,sessionPath + sessionName)) return false; for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++) @@ -462,3 +469,20 @@ bool SessionManager::restoreYourSession() return true; } + + +void SessionManager::manageSession() +{ + kDebug() << "OK ,manage session.."; + + QPointer dialog = new KDialog(rApp->rekonqWindow()); + dialog->setCaption(i18nc("@title:window", "Manage Session")); + dialog->setButtons(KDialog::Ok); + + dialog->button(KDialog::Ok)->setText(i18n("Done")); + + SessionWidget widg; + widg.show(); + dialog->setMainWidget(&widg); + dialog->exec(); +} diff --git a/src/sessionmanager.h b/src/sessionmanager.h index 22665dc4..604a67e5 100644 --- a/src/sessionmanager.h +++ b/src/sessionmanager.h @@ -70,6 +70,9 @@ public: // This method restores a single Window bool restoreWindow(RekonqWindow * window); + bool saveYourSession(int); + bool restoreYourSession(int); + private: explicit SessionManager(QObject *parent = 0); @@ -87,8 +90,7 @@ private Q_SLOTS: // after a crash void restoreCrashedSession(); - bool saveYourSession(); - bool restoreYourSession(); + void manageSession(); private: QString m_sessionFilePath; diff --git a/src/sessionwidget.cpp b/src/sessionwidget.cpp new file mode 100644 index 00000000..fa8330a7 --- /dev/null +++ b/src/sessionwidget.cpp @@ -0,0 +1,129 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2013 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +// Self Includes +#include "sessionwidget.h" +#include "sessionwidget.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "sessionmanager.h" + +// KDE Includes +#include + +// Qt Includes +#include + + +SessionWidget::SessionWidget(QWidget *parent) + : QWidget(parent) +{ + setupUi(this); + + QStringList ses = ReKonfig::savedSessions(); + + Q_FOREACH(const QString & s, ses) + { + QListWidgetItem *item = new QListWidgetItem(s, listWidget, 0); + item->setFlags (item->flags () | Qt::ItemIsEditable); + listWidget->addItem(item); + } + + loadButton->setIcon(KIcon("system-run")); + connect(loadButton, SIGNAL(clicked()), this, SLOT(loadSession())); + + saveButton->setIcon(KIcon("document-save")); + connect(saveButton, SIGNAL(clicked()), this, SLOT(saveSession())); + + deleteButton->setIcon(KIcon("edit-delete")); + connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteSession())); + + connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtons(int))); + connect(listWidget, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(save())); + + updateButtons(-1); +} + + +void SessionWidget::loadSession() +{ + int cc = listWidget->currentRow(); + SessionManager::self()->restoreYourSession(cc); + // close(); +} + + +void SessionWidget::saveSession() +{ + int cc = listWidget->count(); + SessionManager::self()->saveYourSession(cc); + + QListWidgetItem *item = new QListWidgetItem(i18n("untitled"), listWidget, 0); + item->setFlags (item->flags () | Qt::ItemIsEditable); + listWidget->addItem(item); +} + + +void SessionWidget::deleteSession() +{ + listWidget->takeItem(listWidget->currentRow()); + save(); +} + + +void SessionWidget::updateButtons(int index) +{ + kDebug() << "UPDATE INDEX: " << index; + if (index < 0) + { + loadButton->setEnabled(false); + deleteButton->setEnabled(false); + return; + } + + loadButton->setEnabled(true); + deleteButton->setEnabled(true); +} + + +void SessionWidget::save() +{ + kDebug() << " ------------------------ SAVE --------------------------"; + + QStringList ses; + + int c = listWidget->count(); + for (int i = 0; i < c; ++i) + { + QListWidgetItem *item = listWidget->item(i); + ses << item->text(); + } + + ReKonfig::setSavedSessions(ses); +} diff --git a/src/sessionwidget.h b/src/sessionwidget.h new file mode 100644 index 00000000..d40dee7f --- /dev/null +++ b/src/sessionwidget.h @@ -0,0 +1,62 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2013 by Andrea Diamantini +* +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License or (at your option) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +* +* ============================================================ */ + + +#ifndef SESSION_WIDGET_H +#define SESSION_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_session.h" + +// Qt Includes +#include + +// Forward Includes +class QListWidgetItem; + + +class SessionWidget : public QWidget , private Ui::Session +{ + Q_OBJECT + +public: + SessionWidget(QWidget *parent = 0); + +private Q_SLOTS: + void save(); + + void loadSession(); + void saveSession(); + void deleteSession(); + + void updateButtons(int); +}; + + +#endif // SESSION_WIDGET_H diff --git a/src/webwindow/rekonqui.rc b/src/webwindow/rekonqui.rc index 72ae6672..6e23416f 100644 --- a/src/webwindow/rekonqui.rc +++ b/src/webwindow/rekonqui.rc @@ -30,13 +30,7 @@ &Tools - - - &Sessions - - - - + diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp index da7a1bc5..a6e5d876 100644 --- a/src/webwindow/webwindow.cpp +++ b/src/webwindow/webwindow.cpp @@ -281,13 +281,9 @@ void WebWindow::setupActions() connect(a, SIGNAL(triggered(bool)) , this, SLOT(openLocation())); // User sessions management - a = new KAction(KIcon("document-save"), i18n("&Save Session"), this); - actionCollection()->addAction(QL1S("session_save"), a); - connect(a, SIGNAL(triggered(bool)), SessionManager::self(), SLOT(saveYourSession())); - - a = new KAction(KIcon("view-choose"), i18n("&Manage Session"), this); + a = new KAction(KIcon("view-choose"), i18n("&Manage Sessions"), this); actionCollection()->addAction(QL1S("session_manage"), a); - connect(a, SIGNAL(triggered(bool)), SessionManager::self(), SLOT(restoreYourSession())); + connect(a, SIGNAL(triggered(bool)), SessionManager::self(), SLOT(manageSession())); // ===== Tools Actions ================================= a = new KAction(i18n("View Page S&ource"), this); -- cgit v1.2.1