summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid E. Narváez <david.narvaez@computer.org>2012-01-20 08:35:37 -0500
committerDavid E. Narváez <david.narvaez@computer.org>2012-01-20 08:35:37 -0500
commitd07773e737e781bea89149e076ca4c11b9bd6c1c (patch)
tree593621bb2363c0ec619a26f56888f2a96a135380 /src
parentKrazy fixes (diff)
downloadrekonq-d07773e737e781bea89149e076ca4c11b9bd6c1c.tar.xz
Refactoring Code to Load Configuration Document
Factor out all code that loads the DOM Document, and use proper calls in each method. REVIEW: 103722
Diffstat (limited to 'src')
-rw-r--r--src/sessionmanager.cpp114
1 files changed, 34 insertions, 80 deletions
diff --git a/src/sessionmanager.cpp b/src/sessionmanager.cpp
index e67012a9..d5298ecb 100644
--- a/src/sessionmanager.cpp
+++ b/src/sessionmanager.cpp
@@ -43,6 +43,28 @@
// Qt Includes
#include <QtCore/QFile>
+// Only used internally
+bool readSessionDocument(QDomDocument & document, const QString & m_sessionFilePath)
+{
+ QFile sessionFile(m_sessionFilePath);
+
+ if (!sessionFile.exists())
+ return false;
+
+ if (!sessionFile.open(QFile::ReadOnly))
+ {
+ kDebug() << "Unable to open session file" << sessionFile.fileName();
+ return false;
+ }
+
+ if (!document.setContent(&sessionFile, false))
+ {
+ kDebug() << "Unable to parse session file" << sessionFile.fileName();
+ return false;
+ }
+
+ return true;
+}
SessionManager::SessionManager(QObject *parent)
: QObject(parent)
@@ -120,21 +142,10 @@ void SessionManager::saveSession()
bool SessionManager::restoreSessionFromScratch()
{
- QFile sessionFile(m_sessionFilePath);
- if (!sessionFile.exists())
- return false;
- if (!sessionFile.open(QFile::ReadOnly))
- {
- kDebug() << "Unable to open session file" << sessionFile.fileName();
- return false;
- }
-
QDomDocument document("session");
- if (!document.setContent(&sessionFile, false))
- {
- kDebug() << "Unable to parse session file" << sessionFile.fileName();
- return false;
- }
+
+ if(!readSessionDocument(document, m_sessionFilePath))
+ return false;
for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++)
{
@@ -172,25 +183,10 @@ bool SessionManager::restoreSessionFromScratch()
void SessionManager::restoreCrashedSession()
{
- QFile sessionFile(m_sessionFilePath);
- if (!sessionFile.exists())
- {
- kDebug() << "Unable to find session file" << sessionFile.fileName();
- return;
- }
-
- if (!sessionFile.open(QFile::ReadOnly))
- {
- kDebug() << "Unable to open session file" << sessionFile.fileName();
- return;
- }
-
QDomDocument document("session");
- if (!document.setContent(&sessionFile, false))
- {
- kDebug() << "Unable to parse session file" << sessionFile.fileName();
+
+ if (!readSessionDocument(document, m_sessionFilePath))
return;
- }
for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++)
{
@@ -227,25 +223,10 @@ void SessionManager::restoreCrashedSession()
int SessionManager::restoreSavedSession()
{
- QFile sessionFile(m_sessionFilePath);
- if (!sessionFile.exists())
- {
- kDebug() << "Unable to find session file" << sessionFile.fileName();
- return 0;
- }
-
- if (!sessionFile.open(QFile::ReadOnly))
- {
- kDebug() << "Unable to open session file" << sessionFile.fileName();
- return 0;
- }
-
QDomDocument document("session");
- if (!document.setContent(&sessionFile, false))
- {
- kDebug() << "Unable to parse session file" << sessionFile.fileName();
+
+ if (!readSessionDocument(document, m_sessionFilePath))
return 0;
- }
unsigned int winNo;
@@ -283,25 +264,10 @@ int SessionManager::restoreSavedSession()
bool SessionManager::restoreMainWindow(MainWindow* window)
{
- QFile sessionFile(m_sessionFilePath);
- if (!sessionFile.exists())
- {
- kDebug() << "Unable to find session file" << sessionFile.fileName();
- return 0;
- }
-
- if (!sessionFile.open(QFile::ReadOnly))
- {
- kDebug() << "Unable to open session file" << sessionFile.fileName();
- return 0;
- }
-
QDomDocument document("session");
- if (!document.setContent(&sessionFile, false))
- {
- kDebug() << "Unable to parse session file" << sessionFile.fileName();
- return 0;
- }
+
+ if (!readSessionDocument(document, m_sessionFilePath))
+ return false;
unsigned int winNo;
@@ -346,22 +312,10 @@ bool SessionManager::restoreMainWindow(MainWindow* window)
QList<TabHistory> SessionManager::closedSites()
{
QList<TabHistory> 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;
- }
-
QDomDocument document("session");
- if (!document.setContent(&sessionFile, false))
- {
- kDebug() << "Unable to parse session file" << sessionFile.fileName();
+
+ if (!readSessionDocument(document, m_sessionFilePath))
return list;
- }
for (unsigned int tabNo = 0; tabNo < document.elementsByTagName("tab").length(); tabNo++)
{