summaryrefslogtreecommitdiff
path: root/src/sessionmanager.cpp
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/sessionmanager.cpp
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/sessionmanager.cpp')
-rw-r--r--src/sessionmanager.cpp33
1 files changed, 20 insertions, 13 deletions
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;
}