diff options
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/application.cpp | 59 | ||||
-rw-r--r-- | src/application.h | 6 | ||||
-rw-r--r-- | src/historymenu.cpp | 109 | ||||
-rw-r--r-- | src/historymenu.h | 76 | ||||
-rw-r--r-- | src/mainwindow.cpp | 2 | ||||
-rw-r--r-- | src/mainwindow.h | 1 |
7 files changed, 42 insertions, 212 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a6c93e5..a2d0db60 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,6 @@ SET( rekonq_SRCS cookiejar.cpp history.cpp historymodels.cpp - historymenu.cpp bookmarks.cpp modelmenu.cpp urlbar.cpp diff --git a/src/application.cpp b/src/application.cpp index 8e1740fc..5aefb4fb 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -73,7 +73,7 @@ Application::Application() Application::~Application() { - delete m_mainWindow; + qDeleteAll(m_mainWindows); delete s_bookmarkProvider; delete s_networkAccessManager; delete s_historyManager; @@ -85,17 +85,11 @@ int Application::newInstance() KCmdLineArgs::setCwd(QDir::currentPath().toUtf8()); KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); - if (!m_mainWindow) - { - m_mainWindow = new MainWindow(); - - m_mainWindow->setObjectName("MainWindow"); - setWindowIcon(KIcon("rekonq")); - - m_mainWindow->show(); - - QTimer::singleShot(0, this, SLOT(postLaunch())); - } + // creating new window + MainWindow *w = new MainWindow; + w->setObjectName("MainWindow"); + m_mainWindows.prepend(w); + w->show(); if (args->count() > 0) { @@ -107,8 +101,8 @@ int Application::newInstance() } else { - m_mainWindow->mainView()->newTab(); - m_mainWindow->slotHome(); + w->mainView()->newTab(); + w->slotHome(); } return 0; @@ -123,6 +117,8 @@ Application *Application::instance() void Application::postLaunch() { + setWindowIcon(KIcon("rekonq")); + // set Icon Database Path to store "favicons" associated with web sites QString directory = KStandardDirs::locateLocal("cache" , "" , true); if (directory.isEmpty()) @@ -143,7 +139,23 @@ void Application::slotSaveConfiguration() const MainWindow *Application::mainWindow() { - return m_mainWindow; + if(m_mainWindows.isEmpty()) + { + kDebug() << "No extant windows: creating one new..."; + MainWindow *w = new MainWindow(); + m_mainWindows.prepend(w); + w->show(); + QTimer::singleShot(0, this, SLOT(postLaunch())); + return w; + } + + MainWindow *active = qobject_cast<MainWindow*>(QApplication::activeWindow()); + + if(!active) + { + return m_mainWindows.at(0); + } + return active; } @@ -302,26 +314,27 @@ void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) } WebView *webView = 0; - + MainWindow *w = mainWindow(); + switch(type) { case Rekonq::SettingOpenTab: - webView = m_mainWindow->mainView()->newWebView(!ReKonfig::openTabsBack()); + webView = w->mainView()->newWebView(!ReKonfig::openTabsBack()); if (!ReKonfig::openTabsBack()) { - m_mainWindow->mainView()->urlBar()->setUrl(loadingUrl.prettyUrl()); + w->mainView()->urlBar()->setUrl(loadingUrl.prettyUrl()); } break; case Rekonq::NewCurrentTab: - webView = m_mainWindow->mainView()->newWebView(true); - m_mainWindow->mainView()->urlBar()->setUrl(loadingUrl.prettyUrl()); + webView = w->mainView()->newWebView(true); + w->mainView()->urlBar()->setUrl(loadingUrl.prettyUrl()); break; case Rekonq::NewBackTab: - webView = m_mainWindow->mainView()->newWebView(false); + webView = w->mainView()->newWebView(false); break; case Rekonq::CurrentTab: - webView = m_mainWindow->mainView()->currentWebView(); - m_mainWindow->mainView()->urlBar()->setUrl(loadingUrl.prettyUrl()); + webView = w->mainView()->currentWebView(); + w->mainView()->urlBar()->setUrl(loadingUrl.prettyUrl()); break; }; diff --git a/src/application.h b/src/application.h index 44173373..01558b9f 100644 --- a/src/application.h +++ b/src/application.h @@ -39,6 +39,7 @@ // Qt Includes #include <QPointer> +#include <QList> // Forward Declarations class KIcon; @@ -50,6 +51,9 @@ class MainWindow; class NetworkAccessManager; +typedef QList< QPointer<MainWindow> > MainWindowList; + + namespace Rekonq { /** @@ -134,7 +138,7 @@ private: static QPointer<NetworkAccessManager> s_networkAccessManager; static QPointer<BookmarkProvider> s_bookmarkProvider; - QPointer<MainWindow> m_mainWindow; + MainWindowList m_mainWindows; }; #endif // APPLICATION_H diff --git a/src/historymenu.cpp b/src/historymenu.cpp deleted file mode 100644 index f7029d64..00000000 --- a/src/historymenu.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com> -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* ============================================================ */ - - -// Auto Includes -#include "historymenu.h" -#include "historymenu.moc" - -// Local Includes -#include "application.h" -#include "mainwindow.h" - -// Qt Includes -#include <QtGui/QWidget> -#include <QtCore/QModelIndex> - -// KDE Includes -#include <KMessageBox> - - -HistoryMenu::HistoryMenu(QWidget *parent) - : ModelMenu(parent) - , m_history(0) -{ - connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(activated(const QModelIndex &))); - setHoverRole(HistoryModel::UrlStringRole); -} - - -void HistoryMenu::activated(const QModelIndex &index) -{ - emit openUrl(index.data(HistoryModel::UrlRole).toUrl()); -} - - -bool HistoryMenu::prePopulated() -{ - if (!m_history) - { - m_history = Application::historyManager(); - m_historyMenuModel = new HistoryMenuModel(m_history->historyTreeModel(), this); - setModel(m_historyMenuModel); - } - // initial actions - for (int i = 0; i < m_initialActions.count(); ++i) - addAction(m_initialActions.at(i)); - if (!m_initialActions.isEmpty()) - addSeparator(); - setFirstSeparator(m_historyMenuModel->bumpedRows()); - - return false; -} - - -void HistoryMenu::postPopulated() -{ - if (m_history->history().count() > 0) - addSeparator(); - - QAction *showAllAction = Application::instance()->mainWindow()->actionByName("show_history_panel"); - showAllAction->setIcon(KIcon("view-history")); - addAction(showAllAction); - - KAction *clearAction = new KAction(i18n("Clear History"), this); - connect(clearAction, SIGNAL(triggered()), this, SLOT(clearHistory())); - addAction(clearAction); -} - - -void HistoryMenu::clearHistory() -{ - int res = KMessageBox::warningYesNo(this, i18n("Are you sure you want to clear the history?"), i18n("Clear History") ); - - if (res == KMessageBox::Yes) - { - m_history->clear(); - } -} - - -void HistoryMenu::setInitialActions(QList<QAction*> actions) -{ - m_initialActions = actions; - for (int i = 0; i < m_initialActions.count(); ++i) - addAction(m_initialActions.at(i)); -} diff --git a/src/historymenu.h b/src/historymenu.h deleted file mode 100644 index 0237777f..00000000 --- a/src/historymenu.h +++ /dev/null @@ -1,76 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com> -* -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License as -* published by the Free Software Foundation; either version 2 of -* the License or (at your option) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* ============================================================ */ - - -#ifndef HISTORYMENU_H -#define HISTORYMENU_H - -// Local Includes -#include "history.h" -#include "historymodels.h" - -// Qt Includes -#include <QtCore/QList> -#include <QtGui/QAction> - -// Forward Declarations -class ModelMenu; -class QWidget; -class QModelIndex; -class KUrl; - - -/** - * Menu that is dynamically populated from the history - * - */ - -class HistoryMenu : public ModelMenu -{ - Q_OBJECT - -signals: - void openUrl(const KUrl &url); - -public: - HistoryMenu(QWidget *parent = 0); - void setInitialActions(QList<QAction*> actions); - -protected: - bool prePopulated(); - void postPopulated(); - -private slots: - void activated(const QModelIndex &index); - void clearHistory(); - -private: - HistoryManager *m_history; - HistoryMenuModel *m_historyMenuModel; - QList<QAction*> m_initialActions; -}; - -#endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2e8852f0..8d288ff9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -36,7 +36,7 @@ // Local Includes #include "application.h" #include "settings.h" -#include "historymenu.h" +#include "history.h" #include "cookiejar.h" #include "networkaccessmanager.h" #include "bookmarks.h" diff --git a/src/mainwindow.h b/src/mainwindow.h index fe4d3089..a30ff208 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -46,7 +46,6 @@ class QWebFrame; class KAction; class KPassivePopup; -class HistoryMenu; class FindBar; class SidePanel; class WebView; |