From 6181e316ce8cfc1bef05c466a2470427ceb2deac Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Wed, 15 Sep 2010 21:21:33 +0200 Subject: Prompt user before restoring session after a crash. Shows the about:closedTabs page in the background. Task: https://bugs.kde.org/show_bug.cgi?id=249228 --- src/application.cpp | 55 +++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) (limited to 'src/application.cpp') diff --git a/src/application.cpp b/src/application.cpp index ce353912..7e949220 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -41,6 +41,7 @@ #include "iconmanager.h" #include "mainview.h" #include "mainwindow.h" +#include "messagebar.h" #include "opensearchmanager.h" #include "sessionmanager.h" #include "stackedurlbar.h" @@ -50,10 +51,13 @@ // KDE Includes #include -#include +#include #include +#include #include +// Qt Includes +#include QWeakPointer Application::s_adblockManager; QWeakPointer Application::s_bookmarkProvider; @@ -115,7 +119,7 @@ int Application::newInstance() // so, we have 8 possible cases... bool isFirstLoad = m_mainWindows.isEmpty(); bool areThereArguments = (args->count() > 0); - bool isRekonqCrashed = (ReKonfig::recoverOnCrash() == 1); + bool isRekonqCrashed = ReKonfig::recoverOnCrash(); kDebug() << "is first load? " << isFirstLoad; kDebug() << "are there arguments? " << areThereArguments; @@ -123,26 +127,19 @@ int Application::newInstance() int exitValue = 1 * isFirstLoad + 2 * areThereArguments + 4 * isRekonqCrashed; - if(isRekonqCrashed) - { - if( isFirstLoad && sessionManager()->restoreSession() ) - { - kDebug() << "session restored from crash"; - } - } - else - { - if( isFirstLoad && ReKonfig::startupBehaviour() == 2 ) - { - sessionManager()->restoreSession(); - kDebug() << "session restored following settings"; - if(areThereArguments) - loadUrl( KUrl("about:blank"), Rekonq::NewFocusedTab); - } + if (isRekonqCrashed && isFirstLoad) { + loadUrl(KUrl("about:closedTabs")); + MessageBar *msgBar = new MessageBar(i18n("It seems rekonq wasn't closed properly, do you want " + "to restore the last saved session ?") + , mainWindow()->currentTab() + , QMessageBox::Warning + , MessageBar::Yes | MessageBar::No ); + + connect(msgBar, SIGNAL(accepted()), sessionManager(), SLOT(restoreSession())); + mainWindow()->currentTab()->insertBar(msgBar); } - if(areThereArguments) - { + if (areThereArguments) { KUrl::List urlList; for(int i = 0; i < args->count(); ++i) { @@ -153,8 +150,7 @@ int Application::newInstance() urlList += KUrl( args->arg(i) ); // "rekonq kde.org" || "rekonq kde:kdialog" case } - if (isFirstLoad) - { + if (isFirstLoad && !isRekonqCrashed) { // No windows in the current desktop? No windows at all? // Create a new one and load there sites... loadUrl(urlList.at(0), Rekonq::CurrentTab); @@ -169,9 +165,9 @@ int Application::newInstance() for (int i = 1; i < urlList.count(); ++i) loadUrl( urlList.at(i), Rekonq::NewTab); - } - else - { + + } else if (!isRekonqCrashed) { + if (isFirstLoad) // we are starting rekonq, for the first time with no args: use startup behaviour { switch (ReKonfig::startupBehaviour()) @@ -183,7 +179,8 @@ int Application::newInstance() loadUrl(KUrl("about:home")); break; case 2: // restore session - // NOTE: this has just been considered + sessionManager()->restoreSession(); + kDebug() << "session restored following settings"; break; default: mainWindow()->homePage(); @@ -235,15 +232,14 @@ void Application::postLaunch() setWindowIcon(KIcon("rekonq")); Application::historyManager(); - Application::sessionManager(); + Application::sessionManager()->setSessionManagementEnabled(true); // bookmarks loading connect(Application::bookmarkProvider(), SIGNAL(openUrl(const KUrl&, const Rekonq::OpenType&)), Application::instance(), SLOT(loadUrl(const KUrl&, const Rekonq::OpenType&))); // crash recovering - int n = ReKonfig::recoverOnCrash(); - ReKonfig::setRecoverOnCrash(++n); + ReKonfig::setRecoverOnCrash(ReKonfig::recoverOnCrash() + 1); saveConfiguration(); } @@ -367,6 +363,7 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) int tabIndex = w->mainView()->indexOf(tab); Q_ASSERT( tabIndex != -1 ); UrlBar *barForTab = qobject_cast(w->mainView()->widgetBar()->widget(tabIndex)); + barForTab->activateSuggestions(false); barForTab->setQUrl(url); WebView *view = tab->view(); -- cgit v1.2.1