diff options
Diffstat (limited to 'src/sessionmanager.cpp')
-rw-r--r-- | src/sessionmanager.cpp | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp index f4e7cd3e..6aada509 100644 --- a/src/sessionmanager.cpp +++ b/src/sessionmanager.cpp @@ -2,9 +2,9 @@ * * This file is a part of the rekonq project * -* Copyright (C) 2009 by Andrea Diamantini <adjam7 at gmail dot com> +* Copyright (C) 2009-2010 by Andrea Diamantini <adjam7 at gmail dot com> * Copyright (C) 2009 by Yoram Bar-Haim <<yoram.b at zend dot com> -* Copyright (C) 2009 by Lionel Chauvin <megabigbug@yahoo.fr> +* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr> * * * This program is free software; you can redistribute it and/or @@ -38,16 +38,16 @@ // KDE Includes #include <KStandardDirs> -#include <KDebug> // Qt Includes -#include <QFile> -#include <QTextStream> +#include <QtCore/QFile> +#include <QtCore/QTextStream> + SessionManager::SessionManager(QObject *parent) - : QObject(parent) - , m_safe(true) + : QObject(parent) + , m_safe(true) { m_sessionFilePath = KStandardDirs::locateLocal("appdata" , "session"); } @@ -60,21 +60,21 @@ SessionManager::~SessionManager() void SessionManager::saveSession() { - if(!m_safe) + if (!m_safe) return; m_safe = false; QFile sessionFile(m_sessionFilePath); if (!sessionFile.open(QFile::WriteOnly | QFile::Truncate)) { - kWarning() << "Unable to open session file" << sessionFile.fileName(); + kDebug() << "Unable to open session file" << sessionFile.fileName(); return; } QTextStream out(&sessionFile); MainWindowList wl = Application::instance()->mainWindowList(); - Q_FOREACH(QPointer<MainWindow> w, wl) + Q_FOREACH(const QWeakPointer<MainWindow> &w, wl) { out << "window\n"; - MainView *mv = w->mainView(); + MainView *mv = w.data()->mainView(); for (int i = 0 ; i < mv->count() ; i++) { out << mv->webTab(i)->url().toEncoded() << "\n"; @@ -93,7 +93,7 @@ bool SessionManager::restoreSession() return false; if (!sessionFile.open(QFile::ReadOnly)) { - kWarning() << "Unable to open session file" << sessionFile.fileName(); + kDebug() << "Unable to open session file" << sessionFile.fileName(); return false; } @@ -102,18 +102,48 @@ bool SessionManager::restoreSession() do { line = in.readLine(); - if(line == QString("window")) + if (line == QString("window")) { - Application::instance()->newMainWindow(); line = in.readLine(); - Application::instance()->loadUrl(line); + kDebug() << "New Window line: " << line; + Application::instance()->loadUrl( KUrl(line), Rekonq::NewWindow); } else { - Application::instance()->loadUrl(line, Rekonq::NewCurrentTab); + kDebug() << "New Current Tab line: " << line; + Application::instance()->loadUrl( KUrl(line), Rekonq::NewCurrentTab); } } - while(!line.isNull()); - + while (!line.isEmpty()); + return true; } + + +QStringList SessionManager::closedSites() +{ + QStringList list; + + QFile sessionFile(m_sessionFilePath); + if (!sessionFile.exists()) + return list; + if (!sessionFile.open(QFile::ReadOnly)) + { + kDebug() << "Unable to open session file" << sessionFile.fileName(); + return list; + } + + QTextStream in(&sessionFile); + QString line; + do + { + line = in.readLine(); + if (line != QString("window")) + { + list << QString(line); + } + } + while (!line.isEmpty()); + + return list; +} |