[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/apps/konqueror/src
From:       David Faure <faure () kde ! org>
Date:       2010-07-02 15:37:20
Message-ID: 20100702153720.4518DAC8E2 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1145333 by dfaure:

Fix closed tabs showing up in the "restore crashed session" dialog by mistake; this \
was simply the KConfig not being cleaned up between saves so old items were still \
lying around and showing up in the dialog (which does a simple grep, not a full \
profile loading). These tabs were not restored when saying "yes", though.

+ unittest showing that closing a tab deletes the part (for pino)
CCMAIL: maksim@kde.org, pino@kde.org


 M  +16 -22    konqsessionmanager.cpp  
 M  +6 -6      konqsessionmanager.h  
 M  +1 -1      konqviewmanager.cpp  
 M  +44 -0     tests/konqviewmgrtest.cpp  
 M  +1 -0      tests/konqviewmgrtest.h  


--- trunk/KDE/kdebase/apps/konqueror/src/konqsessionmanager.cpp #1145332:1145333
@@ -81,9 +81,8 @@
     dbus.connect(QString(), dbusPath, dbusInterface, "saveCurrentSession", this, \
SLOT(slotSaveCurrentSession(QString)));  
     // Initialize the timer
-    int interval = KonqSettings::autoSaveInterval();
-    if(interval > 0)
-    {
+    const int interval = KonqSettings::autoSaveInterval();
+    if (interval > 0) {
         m_autoSaveTimer.setInterval(interval*1000);
         connect( &m_autoSaveTimer, SIGNAL( timeout() ), this,
             SLOT( autoSaveSession() ) );
@@ -103,10 +102,7 @@
 
     m_autosaveEnabled = false;
     m_autoSaveTimer.stop();
-    QString file = KStandardDirs::locateLocal("appdata",
-        m_autoSavedSessionConfig->name());
-    QFile::remove(file);
-    delete m_autoSavedSessionConfig;
+    QFile::remove(m_autoSavedSessionConfig);
 }
 
 void KonqSessionManager::enableAutosave()
@@ -116,11 +112,9 @@
 
     // Create the config file for autosaving current session
     QString filename = "autosave/" + m_baseService;
-    QString file = KStandardDirs::locateLocal("appdata", filename);
-    QFile::remove(file);
+    m_autoSavedSessionConfig = KStandardDirs::locateLocal("appdata", filename);
+    QFile::remove(m_autoSavedSessionConfig);
 
-    m_autoSavedSessionConfig = new KConfig(filename, KConfig::SimpleConfig,
-        "appdata");
     m_autosaveEnabled = true;
     m_autoSaveTimer.start();
 }
@@ -150,11 +144,11 @@
     if(!m_autosaveEnabled)
         return;
 
-    bool isActive = m_autoSaveTimer.isActive();
+    const bool isActive = m_autoSaveTimer.isActive();
     if(isActive)
         m_autoSaveTimer.stop();
 
-    saveCurrentSession(m_autoSavedSessionConfig);
+    saveCurrentSessionToFile(m_autoSavedSessionConfig);
 
     // Now that we have saved current session it's safe to remove our owned_by
     // directory
@@ -171,14 +165,15 @@
 
 void KonqSessionManager::slotSaveCurrentSession(const QString & path)
 {
-    QString filename = path + '/' + m_baseService;
-
-    KConfig sessionConfig(filename, KConfig::SimpleConfig, "appdata");
-    saveCurrentSession(&sessionConfig);
+    const QString filename = path + '/' + m_baseService;
+    saveCurrentSessionToFile(filename);
 }
 
-void KonqSessionManager::saveCurrentSession(KConfig* sessionConfig)
+void KonqSessionManager::saveCurrentSessionToFile(const QString& sessionConfigPath)
 {
+    QFile::remove(sessionConfigPath);
+    KConfig sessionConfig(sessionConfigPath, KConfig::SimpleConfig, "appdata");
+
     QList<KonqMainWindow*> *mainWindows = KonqMainWindow::mainWindowList();
     unsigned int counter = 0;
 
@@ -187,14 +182,13 @@
 
     foreach ( KonqMainWindow* window, *mainWindows )
     {
-        KConfigGroup configGroup(sessionConfig, "Window" +
+        KConfigGroup configGroup(&sessionConfig, "Window" +
             QString::number(counter));
         window->saveProperties(configGroup);
         counter++;
     }
-    KConfigGroup configGroup(sessionConfig, "General");
+    KConfigGroup configGroup(&sessionConfig, "General");
     configGroup.writeEntry("Number of Windows", counter);
-    sessionConfig->sync();
 }
 
 QStringList KonqSessionManager::takeSessionsOwnership()
@@ -315,7 +309,7 @@
         const KConfig config(sessionFile, KConfig::SimpleConfig);
         const QList<KConfigGroup> groups = windowConfigGroups(config);
         Q_FOREACH(const KConfigGroup& group, groups) {
-            // Do avoid recursive search, let's do linear search on \
Foo_CurrentHistoryItem=1 +            // To avoid a recursive search, let's do linear \
search on Foo_CurrentHistoryItem=1  Q_FOREACH(const QString& key, group.keyList()) {
                 if (key.endsWith("_CurrentHistoryItem")) {
                     const QString viewId = key.left(key.length() - \
                strlen("_CurrentHistoryItem"));
--- trunk/KDE/kdebase/apps/konqueror/src/konqsessionmanager.h #1145332:1145333
@@ -99,6 +99,11 @@
      */
     void deleteOwnedSessions();
 
+    /**
+     * Save current session in a given path (absolute path to a file)
+     */
+    void saveCurrentSessionToFile(const QString& sessionConfig);
+
 public Q_SLOTS:
     /**
      * Ask the user with a KPassivePopup ballon if session should be restored
@@ -118,11 +123,6 @@
     //void restoreSessions();
 
     /**
-     * Save current session in a custom KConfig
-     */
-    void saveCurrentSession(KConfig* sessionConfig);
-
-    /**
      * Save current sessions of all konqueror instances (propagated via a
      * dbus signal).
      */
@@ -146,7 +146,7 @@
     QTimer m_autoSaveTimer;
     QString m_autosaveDir;
     QString m_baseService;
-    KConfig *m_autoSavedSessionConfig;
+    QString m_autoSavedSessionConfig; // full path
     bool m_autosaveEnabled;
 Q_SIGNALS: // DBUS signals
     /**
--- trunk/KDE/kdebase/apps/konqueror/src/konqviewmanager.cpp #1145332:1145333
@@ -863,7 +863,7 @@
 void KonqViewManager::saveViewProfileToFile(const QString & fileName, const QString \
& profileName, KonqFrameBase::Options options)  {
     const QString path = KStandardDirs::locateLocal("data", \
                QString::fromLatin1("konqueror/profiles/") +
-                                                    fileName, \
KGlobal::mainComponent()); +                                                    \
fileName);  QFile::remove(path); // in case it exists already
 
     KConfig _cfg(path, KConfig::SimpleConfig);
--- trunk/KDE/kdebase/apps/konqueror/src/tests/konqviewmgrtest.cpp #1145332:1145333
@@ -497,6 +497,7 @@
     for (int i = 0; i < titles.count(); ++i)
         QCOMPARE(tabWidget->tabText(i), QString(titles[i]));
     QPointer<KonqView> viewTab2Pointer(viewTab2);
+    QPointer<KParts::ReadOnlyPart> tab2PartPointer(viewTab2->part());
 
     // Ensure tabwidget has a nice size
     mainWindow.resize(599, 699);
@@ -508,6 +509,7 @@
     QVERIFY(frame);
     viewManager->removeTab(frame);
     QVERIFY(viewTab2Pointer.isNull()); // check the view got deleted
+    QVERIFY(tab2PartPointer.isNull()); // check the part got deleted too, since pino \
is a non-believer :)  QList<int> expectedTitles; expectedTitles << 0 << 1 << 3 << 4;
     for (int i = 0; i < expectedTitles.count(); ++i)
         QCOMPARE(tabWidget->tabText(i), titles[expectedTitles[i]]);
@@ -675,6 +677,48 @@
     QFile::remove(profile);
 }
 
+void ViewMgrTest::testSaveProfile()
+{
+    KonqMainWindow mainWindow;
+    const KUrl url("data:text/html, <p>Hello World</p>");
+    mainWindow.openUrl(0, url, "text/html");
+    KonqViewManager* viewManager = mainWindow.viewManager();
+    KonqView* view2 = viewManager->addTab("text/html");
+    const KUrl url2("data:text/html, <p>view2</p>");
+    view2->openUrl(url2, "2");
+    KTabWidget* tabWidget = mainWindow.findChild<KTabWidget*>();
+    QVERIFY(tabWidget);
+
+    // Save a profile with two tabs (via KonqSessionManager)
+    KonqSessionManager* sessionMgr = KonqSessionManager::self();
+    const QString filePath = QDir::currentPath() + "unittest_profile";
+    sessionMgr->saveCurrentSessionToFile(filePath);
+    QVERIFY(QFile::exists(filePath));
+
+    {
+        KConfig cfg(filePath, KConfig::SimpleConfig);
+        KConfigGroup profileGroup(&cfg, "Window0");
+        QCOMPARE(profileGroup.readEntry("RootItem"), QString("Tabs0"));
+        QCOMPARE(profileGroup.readEntry("Tabs0_Children"), \
QString("ViewT0,ViewT1")); +        \
QCOMPARE(profileGroup.readEntry("HistoryItemViewT0_0Url"), url.url()); +        \
QCOMPARE(profileGroup.readEntry("HistoryItemViewT1_0Url"), url2.url()); +    }
+
+    // Now close a tab and save again - to check that the stuff from the old
+    // tab isn't lying around.
+    viewManager->removeTab(view2->frame());
+    sessionMgr->saveCurrentSessionToFile(filePath);
+    {
+        KConfig cfg(filePath, KConfig::SimpleConfig);
+        KConfigGroup profileGroup(&cfg, "Window0");
+        QCOMPARE(profileGroup.readEntry("RootItem"), QString("Tabs0"));
+        QCOMPARE(profileGroup.readEntry("Tabs0_Children"), QString("ViewT0"));
+        QCOMPARE(profileGroup.readEntry("HistoryItemViewT0_0Url"), url.url());
+        QVERIFY(!profileGroup.hasKey("HistoryItemViewT1_0Url"));
+    }
+    QFile::remove(filePath);
+}
+
 void ViewMgrTest::testDuplicateWindow()
 {
     KonqMainWindow mainWindow;
--- trunk/KDE/kdebase/apps/konqueror/src/tests/konqviewmgrtest.h #1145332:1145333
@@ -52,6 +52,7 @@
     void testDeletePartInTab();
     void testLoadProfile();
     void testLoadOldProfile();
+    void testSaveProfile();
 
     void testDuplicateWindow();
     void testDuplicateWindowWithSidebar();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic