From 9a111024c84f7f7cc10cbbd5fc43ee82e48ae79e Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 28 Jul 2012 11:11:56 +0200 Subject: Class Application Import, first (important) part --- src/CMakeLists.txt | 6 + src/application.cpp | 520 ++++++++++++++++++++++++++++++++++++++++++++ src/application.h | 104 +++++++++ src/main.cpp | 36 +-- src/rekonq.kcfg | 286 ++++++++++++++++++++++++ src/rekonq.kcfgc | 5 + src/tabwindow/tabwindow.cpp | 43 +++- src/tabwindow/tabwindow.h | 31 ++- 8 files changed, 993 insertions(+), 38 deletions(-) create mode 100644 src/application.cpp create mode 100644 src/application.h create mode 100644 src/rekonq.kcfg create mode 100644 src/rekonq.kcfgc (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eeaf4ef3..6150691e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,6 +7,7 @@ ADD_SUBDIRECTORY( data ) set(rekonq_KDEINIT_SRCS #---------------------------------------- + application.cpp searchengine.cpp urlresolver.cpp websnap.cpp @@ -42,6 +43,11 @@ ADD_DEFINITIONS ( ${KDE4_DEFINITIONS} ) KDE4_ADD_APP_ICON( rekonq_KDEINIT_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../icons/hi*-app-rekonq.png ) +### -------------- ADDING APPLICATION KCFG FILES... + +KDE4_ADD_KCFG_FILES( rekonq_KDEINIT_SRCS rekonq.kcfgc ) + + ### --------------- ADDING EXECUTABLE... # NOTE: This is the simple main used to test the tabwindow :) diff --git a/src/application.cpp b/src/application.cpp new file mode 100644 index 00000000..98b74649 --- /dev/null +++ b/src/application.cpp @@ -0,0 +1,520 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +// Self Includes +#include "application.h" +#include "application.moc" + +// Auto Includes +#include "rekonq.h" + +// Local Includes +#include "tabwindow.h" +#include "webwindow.h" +#include "urlresolver.h" + +// // KDE Includes +#include + +#include +#include +#include + +#include +// #include +// #include +// #include + +// #include +// #include +// #include +// #include +// +// // Qt Includes +// #include +// #include +// #include + + +Application::Application() + : KUniqueApplication() +{ +} + + +Application::~Application() +{ + // ok, we are closing well. + // Don't recover on next load.. + ReKonfig::setRecoverOnCrash(0); + saveConfiguration(); + + kDebug() << "Bye bye (k)baby..."; +} + + +int Application::newInstance() +{ + KCmdLineArgs* args = KCmdLineArgs::parsedArgs(); + + // not that easy, indeed + // We have to consider 3 variables here: + // 1) Is first load? + // 2) Are there arguments? + // 3) Is rekonq recovering from crash? + // so, we have 8 possible cases... + static bool isFirstLoad = true; + bool areThereArguments = (args->count() > 0); + bool hasToBeRecovered = (ReKonfig::recoverOnCrash() > 0); + // note that hasToBeRecovered is always true if it is not the first load + // !isFirstLoad -> hasToBeRecovered + + kDebug() << "is first load? " << isFirstLoad; + kDebug() << "are there arguments? " << areThereArguments; + kDebug() << "is rekonq crashed? " << hasToBeRecovered; + + if (!isSessionRestored()) + { + if (areThereArguments) + { + // prepare URLS to load + KUrl::List urlList; + for (int i = 0; i < args->count(); ++i) + { + const KUrl u = args->url(i); + + if (u.isLocalFile() && QFile::exists(u.toLocalFile())) // "rekonq somefile.html" case + { + urlList += u; + } + else + { + // "rekonq kde.org" || "rekonq kde:kdialog" cases + urlList += UrlResolver::urlFromTextTyped(args->arg(i)); + } + } + +// if (isFirstLoad && (ReKonfig::startupBehaviour() == 2)) // && sessionManager()->restoreSessionFromScratch()) +// { +// isFirstLoad = false; +// } + + // first argument: 99% of the time we have just that... + if (isFirstLoad) + { + // No windows in the current desktop? No windows at all? + // Create a new one and load there sites... + loadUrl(urlList.at(0), Rekonq::NewWindow); + } + else + { + if (!ReKonfig::openExternalLinksInNewWindow()) + { + loadUrl(urlList.at(0), Rekonq::NewFocusedTab); + } + else + { + loadUrl(urlList.at(0), Rekonq::NewWindow); + } + + if (!tabWindow()->isActiveWindow()) + KWindowSystem::demandAttention(tabWindow()->winId(), true); + } + + // following arguments: what's best behavior here? + // I'm pretty sure no one has real opinion about... + if (!ReKonfig::openExternalLinksInNewWindow()) + { + for (int i = 1; i < urlList.count(); ++i) + loadUrl(urlList.at(i), Rekonq::NewFocusedTab); + } + else + { + for (int i = 1; i < urlList.count(); ++i) + loadUrl(urlList.at(i), Rekonq::NewWindow); + } + } + else + { + if (isFirstLoad) + { + if (hasToBeRecovered) + { + loadUrl(KUrl("about:closedTabs"), Rekonq::NewWindow); + } + else + { + switch (ReKonfig::startupBehaviour()) + { + case 0: // open home page + newTabWindow()->newCleanTab(); + break; + case 1: // open new tab page + loadUrl(KUrl("about:home"), Rekonq::NewWindow); + break; + case 2: // restore session FIXME +// if (sessionManager()->restoreSessionFromScratch()) +// { +// break; +// } + default: + newTabWindow()->newCleanTab(); + break; + } + } + } + else + { + switch (ReKonfig::newTabsBehaviour()) + { + case 0: // new tab page + loadUrl(KUrl("about:home") , Rekonq::NewWindow); + break; + case 2: // homepage + loadUrl(KUrl(ReKonfig::homePage()) , Rekonq::NewWindow); + break; + case 1: // blank page + default: + loadUrl(KUrl("about:blank") , Rekonq::NewWindow); + break; + } + } + } + } // !isSessionRestored() + +// if (isFirstLoad) +// { +// FIXME +// if (hasToBeRecovered) +// { +// QTimer::singleShot(1000, tabWindow()->currentTab(), SLOT(showMessageBar())); +// } +// else +// { +// sessionManager()->setSessionManagementEnabled(true); +// } +// +// if (ReKonfig::checkDefaultSearchEngine() && !hasToBeRecovered && SearchEngine::defaultEngine().isNull()) +// QTimer::singleShot(2000, tabWindow()->currentTab(), SLOT(showSearchEngineBar())); + + // updating rekonq configuration + updateConfiguration(); + + setWindowIcon(KIcon("rekonq")); + +// FIXME historyManager(); + + ReKonfig::setRecoverOnCrash(ReKonfig::recoverOnCrash() + 1); + saveConfiguration(); +// } + + KStartupInfo::appStarted(); + isFirstLoad = false; + + return 0; +} + + +Application *Application::instance() +{ + return (qobject_cast(QCoreApplication::instance())); +} + + +void Application::saveConfiguration() const +{ + ReKonfig::self()->writeConfig(); +} + + +TabWindow *Application::tabWindow() +{ + TabWindow *active = qobject_cast(QApplication::activeWindow()); + + if (!active) + { + if (m_tabWindows.isEmpty()) + return 0; + + Q_FOREACH(const QWeakPointer &pointer, m_tabWindows) + { + if (KWindowInfo(pointer.data()->effectiveWinId(), NET::WMDesktop, 0).isOnCurrentDesktop()) + return pointer.data(); + } + return m_tabWindows.at(0).data(); + } + return active; +} + + +void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type) +{ + if (url.isEmpty()) + return; + + if (!url.isValid()) + { + KMessageBox::error(0, i18n("Malformed URL:\n%1", url.url(KUrl::RemoveTrailingSlash))); + return; + } + + Rekonq::OpenType newType = type; + // Don't open useless tabs or windows for actions in about: pages + if (url.url().contains("about:") && url.url().contains("/")) + newType = Rekonq::CurrentTab; + + TabWindow *w = 0; + if (newType == Rekonq::NewWindow + || (newType == Rekonq::NewTab && ReKonfig::openLinksInNewWindow())) + { + w = newTabWindow(); + newType = Rekonq::CurrentTab; + } + else + { + w = tabWindow(); + } + + w->loadUrl(url, newType); +} + + +TabWindow *Application::newTabWindow() +{ + TabWindow *w = new TabWindow; + // This is used to track which window was activated most recently + w->installEventFilter(this); + + m_tabWindows.prepend(w); + w->show(); + + return w; +} + + +void Application::removeTabWindow(TabWindow *window) +{ + m_tabWindows.removeOne(window); + kDebug() << "Removing Window from app window list..."; + + // bye bye... + if (m_tabWindows.count() == 0) + quit(); +} + + +TabWindowList Application::tabWindowList() +{ + return m_tabWindows; +} + + +bool Application::eventFilter(QObject* watched, QEvent* event) +{ + // Track which window was activated most recently to prefer it on window choosing + // (e.g. when another application opens a link) + if (event->type() == QEvent::WindowActivate) + { + TabWindow *window = qobject_cast(watched); + if (window) + { + if (m_tabWindows.at(0).data() != window) + { + int index = m_tabWindows.indexOf(QWeakPointer(window)); + Q_ASSERT(index != -1); + m_tabWindows.prepend(m_tabWindows.takeAt(index)); + } + } + } + + return QObject::eventFilter(watched, event); +} + + +void Application::updateConfiguration() +{ + kDebug() << "Updating... NOTHING!!!"; +// // ============== Tabs ================== +// bool b = ReKonfig::closeTabSelectPrevious(); +// Q_FOREACH(const QWeakPointer &w, m_tabWindows) +// { +// MainView *mv = w.data()->mainView(); +// mv->updateTabBar(); +// +// mv->tabBar()->setAnimatedTabHighlighting(ReKonfig::animatedTabHighlighting()); +// +// if (b) +// mv->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); +// else +// mv->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectRightTab); +// } +// +// QWebSettings *defaultSettings = QWebSettings::globalSettings(); +// +// // =========== Fonts ============== +// defaultSettings->setFontFamily(QWebSettings::StandardFont, ReKonfig::standardFontFamily()); +// defaultSettings->setFontFamily(QWebSettings::FixedFont, ReKonfig::fixedFontFamily()); +// defaultSettings->setFontFamily(QWebSettings::SerifFont, ReKonfig::serifFontFamily()); +// defaultSettings->setFontFamily(QWebSettings::SansSerifFont, ReKonfig::sansSerifFontFamily()); +// defaultSettings->setFontFamily(QWebSettings::CursiveFont, ReKonfig::cursiveFontFamily()); +// defaultSettings->setFontFamily(QWebSettings::FantasyFont, ReKonfig::fantasyFontFamily()); +// +// // compute font size +// // (I have to admit I know nothing about these DPI questions..: copied from kwebkitpart, as someone suggested) +// // font size in pixels = font size in inches × screen dpi +// if (tabWindow() && tabWindow()->currentTab()) +// { +// int logDpiY = tabWindow()->currentTab()->view()->logicalDpiY(); +// float toPix = (logDpiY < 96.0) +// ? 96.0 / 72.0 +// : logDpiY / 72.0 ; +// +// int defaultFontSize = ReKonfig::defaultFontSize(); +// int minimumFontSize = ReKonfig::minFontSize(); +// +// defaultSettings->setFontSize(QWebSettings::DefaultFontSize, qRound(defaultFontSize * toPix)); +// defaultSettings->setFontSize(QWebSettings::MinimumFontSize, qRound(minimumFontSize * toPix)); +// } +// +// // encodings +// QString enc = ReKonfig::defaultEncoding(); +// defaultSettings->setDefaultTextEncoding(enc); +// +// // ================ WebKit ============================ +// defaultSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, ReKonfig::dnsPrefetch()); +// defaultSettings->setAttribute(QWebSettings::PrintElementBackgrounds, ReKonfig::printElementBackgrounds()); +// +// defaultSettings->setAttribute(QWebSettings::JavascriptEnabled, ReKonfig::javascriptEnabled()); +// defaultSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows, ReKonfig::javascriptCanOpenWindows()); +// defaultSettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, ReKonfig::javascriptCanAccessClipboard()); +// +// defaultSettings->setAttribute(QWebSettings::JavaEnabled, ReKonfig::javaEnabled()); +// +// if (ReKonfig::pluginsEnabled() == 2) +// defaultSettings->setAttribute(QWebSettings::PluginsEnabled, false); +// else +// defaultSettings->setAttribute(QWebSettings::PluginsEnabled, true); +// +// // Enabling WebKit "Page Cache" feature: http://webkit.org/blog/427/webkit-page-cache-i-the-basics/ +// defaultSettings->setMaximumPagesInCache(3); +// +// // ===== HTML 5 features WebKit support ====== +// defaultSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, ReKonfig::offlineStorageDatabaseEnabled()); +// defaultSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, ReKonfig::offlineWebApplicationCacheEnabled()); +// defaultSettings->setAttribute(QWebSettings::LocalStorageEnabled, ReKonfig::localStorageEnabled()); +// if (ReKonfig::localStorageEnabled()) +// { +// QString path = KStandardDirs::locateLocal("cache", QString("WebkitLocalStorage/rekonq"), true); +// path.remove("rekonq"); +// QWebSettings::setOfflineStoragePath(path); +// QWebSettings::setOfflineStorageDefaultQuota(50000); +// } +// +// // ================= WebGl =================== +// defaultSettings->setAttribute(QWebSettings::WebGLEnabled, ReKonfig::webGL()); +// defaultSettings->setAttribute(QWebSettings::AcceleratedCompositingEnabled, ReKonfig::webGL()); +// +// // Applies user defined CSS to all open webpages. +// defaultSettings->setUserStyleSheetUrl(ReKonfig::userCSS()); +// +// // ====== load Settings on main classes +// historyManager()->loadSettings(); +// +// defaultSettings = 0; +// +// if (!tabWindow()) +// return; +// +// ReKonfig::useFavicon() +// ? tabWindow()->changeWindowIcon(tabWindow()->mainView()->currentIndex()) +// : tabWindow()->setWindowIcon(KIcon("rekonq")) +// ; +// +// // hovering unfocused tabs options +// switch (ReKonfig::hoveringTabOption()) +// { +// case 0: // tab previews +// case 3: // nothing +// for (int i = 0; i < tabWindow()->mainView()->tabBar()->count(); i++) +// { +// tabWindow()->mainView()->tabBar()->setTabToolTip(i, QL1S("")); +// } +// break; +// +// case 1: // title previews +// for (int i = 0; i < tabWindow()->mainView()->tabBar()->count(); i++) +// { +// tabWindow()->mainView()->tabBar()->setTabToolTip(i, tabWindow()->mainView()->tabText(i).remove('&')); +// } +// break; +// +// case 2: // url previews +// for (int i = 0; i < tabWindow()->mainView()->tabBar()->count(); i++) +// { +// tabWindow()->mainView()->tabBar()->setTabToolTip(i, tabWindow()->mainView()->webTab(i)->url().toMimeDataString()); +// } +// break; +// +// default: // non extant case +// ASSERT_NOT_REACHED(unknown hoveringTabOption); +// break; +// } + +} + + +void Application::queryQuit() +{ + if (tabWindowList().count() > 1) + { + int answer = KMessageBox::questionYesNoCancel( + tabWindow(), + i18n("Do you want to close the window or the whole application?"), + i18n("Application/Window closing..."), + KGuiItem(i18n("C&lose Current Window"), + KIcon("window-close")), + KStandardGuiItem::quit(), + KStandardGuiItem::cancel(), + "confirmClosingMultipleWindows" + ); + + switch (answer) + { + case KMessageBox::Yes: + tabWindow()->close(); + return; + + case KMessageBox::No: + break; + + default: + return; + } + } + + // in case of just one window... + quit(); +} diff --git a/src/application.h b/src/application.h new file mode 100644 index 00000000..a9f6ff63 --- /dev/null +++ b/src/application.h @@ -0,0 +1,104 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2012 by Andrea Diamantini +* +* +* 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 . +* +* ============================================================ */ + + +#ifndef APPLICATION_H +#define APPLICATION_H + + +// Local Includes +#include "tabwindow.h" + +// KDE Includes +#include +#include + +// Qt Includes +#include + +// Forward Declarations +class WebWindow; + + +typedef QList< QWeakPointer > TabWindowList; + + +// --------------------------------------------------------------------------------------------------------------- + + +#define rApp Application::instance() + +/** + * Rekonq Application class + */ +class Application : public KUniqueApplication +{ + Q_OBJECT + +public: + Application(); + ~Application(); + + int newInstance(); + static Application *instance(); + + TabWindow *tabWindow(); + TabWindow *newTabWindow(); + TabWindowList tabWindowList(); + +public Q_SLOTS: + /** + * Save application's configuration + * + * @see ReKonfig::self()->writeConfig(); + */ + void saveConfiguration() const; + + /** + * @short load url + * + * @param url The url to load + * @param type the type where loading the url. @see Rekonq::OpenType + */ + void loadUrl(const KUrl& url, + const Rekonq::OpenType& type = Rekonq::CurrentTab + ); + + void removeTabWindow(TabWindow *window); + +protected: + // This is used to track which window was activated most recently + bool eventFilter(QObject *watched, QEvent *event); + +private Q_SLOTS: + void updateConfiguration(); + + void queryQuit(); + +private: + TabWindowList m_tabWindows; +}; + +#endif // APPLICATION_H diff --git a/src/main.cpp b/src/main.cpp index 5c55aa81..c5759d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,12 +21,14 @@ // version include #include "config-version.h" +#include "application.h" #include "tabwindow.h" #include "urlresolver.h" #include -#include +#include #include +#include #include #include @@ -62,18 +64,18 @@ extern "C" KDE_EXPORT int kdemain(int argc, char **argv) // Register the supported options KCmdLineArgs::addCmdLineOptions(options); -// if (!Application::start()) -// { -// kWarning() << "rekonq is already running!"; -// return 0; -// } + if (!Application::start()) + { + kWarning() << "rekonq is already running!"; + return 0; + } #if defined(Q_WS_X11) // On X11, the raster engine gives better performance than native. QApplication::setGraphicsSystem(QLatin1String("raster")); #endif - KApplication app; + Application app; QWebSettings::setIconDatabasePath("/tmp/iconcache"); @@ -83,26 +85,6 @@ extern "C" KDE_EXPORT int kdemain(int argc, char **argv) KCmdLineArgs::setCwd(QDir::currentPath().toUtf8()); - TabWindow *w = new TabWindow; - - // no session.. just start up normally - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - if (args->count() == 0) - { - w->newCleanTab(); - w->show(); - } - else - { - int i = 0; - for (; i < args->count(); i++) - { - w->loadUrlInNewTab( UrlResolver::urlFromTextTyped(args->arg(i)) ); - } - w->show(); - } - args->clear(); - // if (app.isSessionRestored()) // for (int i = 1; MainWindow::canBeRestored(i); i++) // app.newMainWindow(false)->restore(i); diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg new file mode 100644 index 00000000..7def60c2 --- /dev/null +++ b/src/rekonq.kcfg @@ -0,0 +1,286 @@ + + + + + +QtWebKit +QDateTime +KUrl +KGlobalSettings + + + + + + + true + + + false + + + false + + + + + + 0 + + + true + + + false + + + true + + + true + + + true + + + true + + + true + + + true + + + true + + + + + + + + KDE Homepage,rekonq site + + + http://www.kde.org/,http://rekonq.kde.org/ + + + + + + + + 1 + + + false + + + http://www.kde.org/ + + + KGlobalSettings::downloadPath() + + + false + + + false + + + false + + + + + + + + + 0 + + + 0 + + + + 0 + + + + false + + + false + + + false + + + true + + + false + + + false + + + + + + + + KGlobalSettings::generalFont().family() + + + KGlobalSettings::fixedFont().family() + + + QWebSettings::globalSettings()->fontFamily(QWebSettings::SerifFont) + + + QWebSettings::globalSettings()->fontFamily(QWebSettings::SansSerifFont) + + + QWebSettings::globalSettings()->fontFamily(QWebSettings::CursiveFont) + + + QWebSettings::globalSettings()->fontFamily(QWebSettings::FantasyFont) + + + 12 + + + 7 + + + ISO 8859-1 + + + + + + + + + + + false + + + false + + + 0 + + + true + + + + + + + + + true + + + + 0 + + + + false + + + false + + + false + + + + true + + + false + + + false + + + false + + + true + + + true + + + + + + + + false + + + false + + + false + + + true + + + false + + + 2 + + + + + + + + false + + + false + + + false + + + false + + + 0 + + + + + + + + + + + + + + + 21 + + + + diff --git a/src/rekonq.kcfgc b/src/rekonq.kcfgc new file mode 100644 index 00000000..50a9817d --- /dev/null +++ b/src/rekonq.kcfgc @@ -0,0 +1,5 @@ +File=rekonq.kcfg +ClassName=ReKonfig +Singleton=true +Mutators=true +UseEnumTypes=true diff --git a/src/tabwindow/tabwindow.cpp b/src/tabwindow/tabwindow.cpp index 9e2a17ce..a849426e 100644 --- a/src/tabwindow/tabwindow.cpp +++ b/src/tabwindow/tabwindow.cpp @@ -85,6 +85,11 @@ TabWindow::TabWindow(QWidget *parent) connect(this, SIGNAL(currentChanged(int)), this, SLOT(currentChanged(int))); + // NOTE: NEVER create a tabwindow without AT LEAST one tab... + WebWindow *tab = prepareNewTab(); + addTab(tab, i18n("new tab")); + setCurrentWidget(tab); + // FIXME: Manage sizes... kDebug() << "SIZE: " << size(); kDebug() << "SIZE HINT: " << sizeHint(); @@ -147,15 +152,35 @@ WebWindow *TabWindow::prepareNewTab(WebPage *page) } -void TabWindow::loadUrlInNewTab(const QUrl &url, TabHistory *history) +void TabWindow::loadUrl(const KUrl &url, Rekonq::OpenType type, TabHistory *history) { - WebWindow *tab = prepareNewTab(); + WebWindow *tab = 0; + switch (type) + { + case Rekonq::NewTab: + case Rekonq::NewBackGroundTab: + tab = prepareNewTab(); + addTab(tab, i18n("new tab")); + break; + + case Rekonq::NewFocusedTab: + tab = prepareNewTab(); + addTab(tab, i18n("new tab")); + setCurrentWidget(tab); + break; + + case Rekonq::NewWindow: + // TODO +// emit loadUrlInNewWindow(url); + return; - // Now, the dirty jobs... - addTab(tab, i18n("new tab")); - tab->load(url); + case Rekonq::CurrentTab: + default: + tab = currentWebWindow(); + break; + }; - setCurrentWidget(tab); + tab->load(url); if (history) { @@ -169,7 +194,7 @@ void TabWindow::loadUrlInNewTab(const QUrl &url, TabHistory *history) void TabWindow::newCleanTab() { QUrl u = QUrl::fromUserInput("/DATI/WEBPAGES/HomePage/index.htm"); - loadUrlInNewTab(u); + loadUrl(u, Rekonq::NewTab); } @@ -338,7 +363,7 @@ void TabWindow::cloneTab(int index) QWebHistory* history = webWindow(index)->page()->history(); TabHistory tHistory(history); - loadUrlInNewTab(u, &tHistory); + loadUrl(u, Rekonq::NewTab, &tHistory); } @@ -440,7 +465,7 @@ void TabWindow::restoreClosedTab(int i) QUrl u = QUrl(history.url); - loadUrlInNewTab(u, &history); + loadUrl(u, Rekonq::NewTab, &history); // just to get sure... m_recentlyClosedTabs.removeAll(history); diff --git a/src/tabwindow/tabwindow.h b/src/tabwindow/tabwindow.h index f8cb759f..24f1b42e 100644 --- a/src/tabwindow/tabwindow.h +++ b/src/tabwindow/tabwindow.h @@ -25,8 +25,9 @@ #include +class KUrl; + class QLabel; -class QUrl; class QToolButton; class QWebHistory; @@ -37,6 +38,32 @@ class WebPage; class WebWindow; +// -------------------------------------------------------------------------------------- + + +namespace Rekonq +{ + +/** +* @short Open link options +* Different modes of opening new tab +*/ +enum OpenType +{ + CurrentTab, ///< open url in current tab + NewTab, ///< open url according to users settings + NewFocusedTab, ///< open url in new tab and focus it + NewBackGroundTab, ///< open url in new background tab + NewWindow ///< open url in new window +}; + + +} + + +// -------------------------------------------------------------------------------------- + + class TabWindow : public KTabWidget { Q_OBJECT @@ -52,7 +79,7 @@ public: TabBar* tabBar() const; public Q_SLOTS: - void loadUrlInNewTab(const QUrl &, TabHistory *history = 0); + void loadUrl(const KUrl &, Rekonq::OpenType type = Rekonq::CurrentTab, TabHistory *history = 0); void newCleanTab(); private: -- cgit v1.2.1