diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/rekonq.kcfg | 5 | ||||
-rw-r--r-- | src/session.ui | 66 | ||||
-rw-r--r-- | src/sessionmanager.cpp | 40 | ||||
-rw-r--r-- | src/sessionmanager.h | 6 | ||||
-rw-r--r-- | src/sessionwidget.cpp | 129 | ||||
-rw-r--r-- | src/sessionwidget.h | 62 | ||||
-rw-r--r-- | src/webwindow/rekonqui.rc | 8 | ||||
-rw-r--r-- | src/webwindow/webwindow.cpp | 8 |
9 files changed, 302 insertions, 24 deletions
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 @@ </entry> <entry name="showBookmarksPanel" type="Bool"> <default>false</default> - </entry> + </entry> + <entry name="savedSessions" type="StringList"> + <default></default> + </entry> </group> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Session</class> + <widget class="QWidget" name="Session"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QListWidget" name="listWidget"/> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QPushButton" name="saveButton"> + <property name="text"> + <string>Save</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="loadButton"> + <property name="text"> + <string>Load</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="deleteButton"> + <property name="text"> + <string>Delete</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> 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 <KDialog> +#include <KPushButton> #include <KStandardDirs> #include <KUrl> // Qt Includes #include <QFile> #include <QDomDocument> +#include <QPointer> // Only used internally @@ -374,18 +378,20 @@ QList<TabHistory> 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<KDialog> 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 <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +// Self Includes +#include "sessionwidget.h" +#include "sessionwidget.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "sessionmanager.h" + +// KDE Includes +#include <KIcon> + +// Qt Includes +#include <QListWidgetItem> + + +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 <adjam7 at gmail dot com> +* +* +* 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 <http://www.gnu.org/licenses/>. +* +* ============================================================ */ + + +#ifndef SESSION_WIDGET_H +#define SESSION_WIDGET_H + + +// Rekonq Includes +#include "rekonq_defines.h" + +// Ui Includes +#include "ui_session.h" + +// Qt Includes +#include <QWidget> + +// 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 @@ <text>&Tools</text> <Action name="clear_private_data" /> <Separator/> - - <Menu name="sessionMenu" noMerge="1"> - <text>&Sessions</text> - <Action name="session_save" /> - <Action name="session_manage" /> - </Menu> - + <Action name="session_manage" /> <Action name="webapp_shortcut" /> <Action name="web_inspector" /> <Action name="page_source" /> 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); |