summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2009-09-26 00:03:00 +0200
committerAndrea Diamantini <adjam7@gmail.com>2009-09-26 00:03:00 +0200
commit64475d706faf1620cec8899da7165f4bc369d8a2 (patch)
treeb57275e990201b2d59422fa6d79d5528830fb8d3 /src
parentFixing a bit thumbs tableWidget (diff)
downloadrekonq-64475d706faf1620cec8899da7165f4bc369d8a2.tar.xz
Fixing sessionmanager (at least I hope so):
- moved from DataStream to TextStream (we use strings..) - implemented a semaphore (m_safe) - closing every time file
Diffstat (limited to 'src')
-rw-r--r--src/application.cpp18
-rw-r--r--src/mainview.cpp2
-rw-r--r--src/sessionmanager.cpp33
-rw-r--r--src/sessionmanager.h7
4 files changed, 35 insertions, 25 deletions
diff --git a/src/application.cpp b/src/application.cpp
index ffde7203..683a405f 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -89,12 +89,16 @@ int Application::newInstance()
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
// is your app session restored? restore session...
- if (isSessionRestored())
+ // this mechanism also falls back to load usual plain rekonq
+ // if something goes wrong...
+ if (isSessionRestored() && sessionManager()->restoreSession())
{
- sessionManager()->restoreSession();
+ kDebug() << "session restored";
return 0;
}
-
+
+// --------------------------------------------------------------------------
+
if (args->count() > 0)
{
// is there a window open on the current desktop ? use it!
@@ -143,10 +147,6 @@ void Application::postLaunch()
// set Icon Database Path to store "favicons" associated with web sites
QString directory = KStandardDirs::locateLocal("cache" , "" , true);
- if (directory.isEmpty())
- {
- directory = QDir::homePath() + QLatin1String("/.") + QCoreApplication::applicationName();
- }
QWebSettings::setIconDatabasePath(directory);
Application::historyManager();
@@ -166,7 +166,6 @@ MainWindow *Application::mainWindow()
{
kDebug() << "No extant windows: creating one new...";
MainWindow *w = newMainWindow();
- QTimer::singleShot(0, this, SLOT(postLaunch()));
return w;
}
@@ -401,7 +400,8 @@ MainWindow *Application::newMainWindow()
m_mainWindows.prepend(w);
w->show();
-
+ QTimer::singleShot(0, this, SLOT(postLaunch()));
+
return w;
}
diff --git a/src/mainview.cpp b/src/mainview.cpp
index 61e340cb..5baf99ed 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -103,7 +103,7 @@ MainView::MainView(QWidget *parent)
connect(m_tabBar, SIGNAL(tabCloseRequested(int)), this, SLOT(slotCloseTab(int)));
// Session Manager
- connect (this,SIGNAL(tabsChanged()),Application::sessionManager(),SLOT(saveSession()));
+ connect (this, SIGNAL(tabsChanged()), Application::sessionManager(), SLOT(saveSession()));
}
diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp
index 0c2c5c32..6b7d6b9e 100644
--- a/src/sessionmanager.cpp
+++ b/src/sessionmanager.cpp
@@ -41,11 +41,12 @@
// Qt Includes
#include <QFile>
-#include <QDataStream>
+#include <QTextStream>
SessionManager::SessionManager(QObject *parent)
: QObject(parent)
+ , m_safe(true)
{
m_sessionFilePath = KStandardDirs::locateLocal("appdata" , "session");
}
@@ -58,23 +59,28 @@ SessionManager::~SessionManager()
void SessionManager::saveSession()
{
+ 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();
return;
}
- QDataStream out(&sessionFile);
+ QTextStream out(&sessionFile);
MainWindowList wl = Application::instance()->mainWindowList();
Q_FOREACH(QPointer<MainWindow> w, wl)
{
- out << QByteArray("window");
+ out << "window\n";
MainView *mv = w->mainView();
for (int i = 0 ; i < mv->count() ; i++)
{
- out << mv->webView(i)->url().toEncoded();
+ out << mv->webView(i)->url().toEncoded(QUrl::StripTrailingSlash) << "\n";
}
}
+ sessionFile.close();
+ m_safe = true;
return;
}
@@ -90,22 +96,23 @@ bool SessionManager::restoreSession()
return false;
}
- QDataStream in(&sessionFile);
- int i = 0;
- while (!sessionFile.atEnd())
+ QTextStream in(&sessionFile);
+ QString line;
+ do
{
- ++i;
- QByteArray data;
- in >> data;
- if(data == QByteArray("window"))
+ line = in.readLine();
+ if(line == QString("window"))
{
Application::instance()->newMainWindow();
+ line = in.readLine();
+ Application::instance()->loadUrl(line);
}
else
{
- Application::instance()->loadUrl(data,Rekonq::NewCurrentTab);
+ Application::instance()->loadUrl(line, Rekonq::NewCurrentTab);
}
}
-
+ while(!line.isNull());
+
return true;
}
diff --git a/src/sessionmanager.h b/src/sessionmanager.h
index 1ff8fa53..b66415e5 100644
--- a/src/sessionmanager.h
+++ b/src/sessionmanager.h
@@ -34,6 +34,7 @@
#include <QtCore/QObject>
#include <QtCore/QString>
+
/**
*
*/
@@ -43,13 +44,15 @@ class SessionManager : public QObject
public:
SessionManager(QObject *parent = 0);
~SessionManager();
+ bool restoreSession();
-public slots:
+private slots:
void saveSession();
- bool restoreSession();
+
private:
QString m_sessionFilePath;
+ bool m_safe;
};