From kde-commits Tue Feb 16 22:27:55 2010 From: Frank Osterfeld Date: Tue, 16 Feb 2010 22:27:55 +0000 To: kde-commits Subject: KDE/kdepim/akregator/src Message-Id: <1266359275.923695.10744.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=126635928615796 SVN commit 1091469 by osterfeld: Restore open tabs after crash Patch by Steffen Hanikel BUG:179931 M +87 -0 akregator_part.cpp M +32 -0 akregator_part.h M +10 -0 mainwidget.cpp M +2 -0 mainwidget.h M +0 -28 mainwindow.cpp M +0 -11 mainwindow.h --- trunk/KDE/kdepim/akregator/src/akregator_part.cpp #1091468:1091469 @@ -164,6 +164,7 @@ : inherited(parent) , m_standardListLoaded(false) , m_shuttingDown(false) + , m_doCrashSave(true) , m_backedUpList(false) , m_mainWidget(0) , m_storage(0) @@ -253,6 +254,9 @@ Syndication::FileRetriever::setUserAgent( useragent ); loadPlugins( QLatin1String("extension") ); // FIXME: also unload them! + + if (!readCrashProperties()) + autoReadProperties(); } void Part::loadPlugins( const QString& type ) @@ -275,6 +279,7 @@ void Part::slotOnShutdown() { + autoSaveProperties(); m_shuttingDown = true; m_autosaveTimer->stop(); saveSettings(); @@ -691,6 +696,88 @@ return true; } +void Part::clearCrashProperties() +{ + if (!m_doCrashSave) + return; + KConfig config("crashed", KConfig::SimpleConfig, + "appdata"); + KConfigGroup configGroup(&config, "Part"); + configGroup.writeEntry("crashed", false); +} + + +void Part::saveCrashProperties() +{ + if (!m_doCrashSave) + return; + KConfig config("crashed", KConfig::SimpleConfig, + "appdata"); + KConfigGroup configGroup(&config, "Part"); + configGroup.deleteGroup(); + + configGroup.writeEntry("crashed", true); + + saveProperties(configGroup); +} + +bool Part::readCrashProperties() +{ + KConfig config("crashed", KConfig::SimpleConfig, + "appdata"); + KConfigGroup configGroup(&config, "Part"); + + if (!configGroup.readEntry("crashed", false)) + return false; + + const int choice = KMessageBox::questionYesNoCancel( m_mainWidget, + i18n("Akregator did not close correctly. Would you like to restore the previous session?"), + i18n("Restore Session?"), + KGuiItem(i18n("Restore Session"), "window-new"), + KGuiItem(i18n("Do Not Restore"), "dialog-close"), + KGuiItem(i18n("Ask Me Later"), "chronometer"), + "Restore session when akregator didn't close correctly" ); + switch ( choice ) { + case KMessageBox::Yes: + readProperties(configGroup); + return true; + case KMessageBox::No: + clearCrashProperties(); + return false; + default: + break; + } + m_doCrashSave = false; + return false; +} + +void Part::slotAutoSave() +{ + saveCrashProperties(); +} + +void Part::autoSaveProperties() +{ + KConfig config("autosaved", KConfig::SimpleConfig, "appdata"); + KConfigGroup configGroup(&config, "Part"); + configGroup.deleteGroup(); + + saveProperties(configGroup); + + clearCrashProperties(); +} + +void Part::autoReadProperties() +{ + if(kapp->isSessionRestored()) + return; + + KConfig config("autosaved", KConfig::SimpleConfig, "appdata"); + KConfigGroup configGroup(&config, "Part"); + + readProperties(configGroup); +} + } // namespace Akregator #include "akregator_part.moc" --- trunk/KDE/kdepim/akregator/src/akregator_part.h #1091468:1091469 @@ -140,6 +140,9 @@ void showOptions(); void showNotificationOptions(); + /** Call to auto save */ + void slotAutoSave(); + signals: void signalSettingsChanged(); @@ -180,6 +183,34 @@ bool writeToTextFile( const QString& data, const QString& fname ) const; + /** + * This function ist called by the MainWindow upon restore + */ + void autoReadProperties(); + + /** + * This is called when exiting akregator in order to be able to restore + * its state next time it starts. + */ + void autoSaveProperties(); + + /** + * Saves the session in a special file, so akregator can restore the session in + * case of a crash. + */ + void saveCrashProperties(); + + /** + * Tries to restore the session, if akregator crashed. + */ + bool readCrashProperties(); + + /** + * Clears the crash data. + */ + void clearCrashProperties(); + + private: // attributes class ApplyFiltersInterceptor; @@ -187,6 +218,7 @@ QString m_standardFeedList; bool m_standardListLoaded; bool m_shuttingDown; + bool m_doCrashSave; KParts::BrowserExtension *m_extension; --- trunk/KDE/kdepim/akregator/src/mainwidget.cpp #1091468:1091469 @@ -171,6 +171,11 @@ connect( Kernel::self()->frameManager(), SIGNAL(signalRequestNewFrame(int&)), this, SLOT( slotRequestNewFrame(int&) ) ); + connect( Kernel::self()->frameManager(), SIGNAL(signalFrameAdded(Akregator::Frame*)), + this, SLOT(slotFramesChanged())); + connect( Kernel::self()->frameManager(), SIGNAL(signalFrameRemoved(int)), + this, SLOT(slotFramesChanged())); + m_tabWidget->setWhatsThis( i18n("You can view multiple articles in several open tabs.")); m_mainTab = new QWidget(this); @@ -996,6 +1001,11 @@ selected->setNotificationMode( true ); } +void Akregator::MainWidget::slotFramesChanged() +{ + // We need to wait till the frame is fully loaded + QMetaObject::invokeMethod( m_part, "slotAutoSave", Qt::QueuedConnection ); +} void Akregator::MainWidget::slotArticleToggleKeepFlag( bool ) { --- trunk/KDE/kdepim/akregator/src/mainwidget.h #1091468:1091469 @@ -230,6 +230,8 @@ void slotFetchingStarted(); void slotFetchingStopped(); + void slotFramesChanged(); + private: void deleteExpiredArticles( const boost::shared_ptr& feedList ); --- trunk/KDE/kdepim/akregator/src/mainwindow.cpp #1091468:1091469 @@ -86,7 +86,6 @@ KStandardAction::showMenubar( menuBar(), SLOT(setVisible(bool)), actionCollection()); setStandardToolBarMenuEnabled(true); createStandardStatusBarAction(); - autoReadProperties(); connect( KPIM::BroadcastStatus::instance(), SIGNAL( statusMsg( const QString& ) ), this, SLOT( slotSetStatusBarText(const QString&) ) ); @@ -192,7 +191,6 @@ { if ( !kapp->sessionSaving() ) { - autoSaveProperties(); delete m_part; // delete that here instead of dtor to ensure nested khtmlparts are deleted before singleton objects like KHTMLPageCache } return KMainWindow::queryExit(); @@ -202,7 +200,6 @@ { if (TrayIcon::getInstance()) TrayIcon::getInstance()->hide(); - autoSaveProperties(); kapp->quit(); } @@ -211,10 +208,7 @@ if (kapp->sessionSaving()) return true; else if (TrayIcon::getInstance() == 0 || !TrayIcon::getInstance()->isVisible() ) - { - autoSaveProperties(); return true; - } const QPixmap shot = TrayIcon::getInstance()->takeScreenshot(); KTemporaryFile tmp; @@ -244,26 +238,4 @@ m_statusLabel->setText(text); } -void MainWindow::autoSaveProperties() -{ - KConfig config("autosaved", KConfig::SimpleConfig, - "appdata"); - KConfigGroup configGroup(&config, "MainWindow"); - configGroup.deleteGroup(); - - saveProperties(configGroup); -} - -void MainWindow::autoReadProperties() -{ - if(kapp->isSessionRestored()) - return; - - KConfig config("autosaved", KConfig::SimpleConfig, - "appdata"); - KConfigGroup configGroup(&config, "MainWindow"); - - readProperties(configGroup); -} - #include "mainwindow.moc" --- trunk/KDE/kdepim/akregator/src/mainwindow.h #1091468:1091469 @@ -103,17 +103,6 @@ void readProperties(const KConfigGroup &); /** - * This is called when exiting akregator in order to be able to restore - * its state next time it starts. - */ - void autoSaveProperties(); - - /** - * This function is called when starting akregator and it will restore - * the state akregator the last time it was closed if possible. - */ - void autoReadProperties(); - /** * Reimplemented to save settings */ bool queryExit();