diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-11-24 17:16:28 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-11-26 00:16:20 +0100 |
commit | c1d1c10af5a89da77a1005bcf28cde2d216bef74 (patch) | |
tree | d30041a3b63ac120f09a5a422a2714e870cab277 | |
parent | Moving UA management code to a new UserAgentManager (diff) | |
download | rekonq-c1d1c10af5a89da77a1005bcf28cde2d216bef74.tar.xz |
clean up UserAgentManager code
This way we got the following gains:
- UA Manager is NOT loaded until it is really used
- rekonq other code does know ANYTHING about UA Manager (but the app
instance)
To let this really shine, we should link this directly to the webtab.
Another point for moving tabs up :)
-rw-r--r-- | src/mainwindow.cpp | 11 | ||||
-rw-r--r-- | src/mainwindow.h | 2 | ||||
-rw-r--r-- | src/useragent/useragentmanager.cpp | 53 | ||||
-rw-r--r-- | src/useragent/useragentmanager.h | 12 |
4 files changed, 41 insertions, 37 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f242439f..ff500b4a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -502,7 +502,9 @@ void MainWindow::setupActions() // User Agent a = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this); actionCollection()->addAction(QL1S("useragent"), a); - a->setMenu(rApp->userAgentManager()->userAgentMenu()); + KMenu *uaMenu = new KMenu(this); + a->setMenu(uaMenu); + connect(uaMenu, SIGNAL(aboutToShow()), this, SLOT(populateUserAgentMenu())); // Editable Page a = new KAction(KIcon("document-edit"), i18n("Set Editable"), this); @@ -1497,3 +1499,10 @@ void MainWindow::closeEvent(QCloseEvent *event) kDebug() << "CLOSING WINDOW..."; KXmlGuiWindow::closeEvent(event); } + + +void MainWindow::populateUserAgentMenu() +{ + KMenu *uaMenu = static_cast<KMenu *>(QObject::sender()); + rApp->userAgentManager()->populateUAMenuForTabUrl(uaMenu, currentTab()); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 3b5706c6..581b4fd1 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -176,6 +176,8 @@ private Q_SLOTS: void openActionUrl(QAction *action); void openActionTab(QAction *action); + void populateUserAgentMenu(); + void enableNetworkAnalysis(bool); void setEditable(bool); diff --git a/src/useragent/useragentmanager.cpp b/src/useragent/useragentmanager.cpp index db6e0708..78b5b1c0 100644 --- a/src/useragent/useragentmanager.cpp +++ b/src/useragent/useragentmanager.cpp @@ -31,9 +31,8 @@ // Local Includes #include "useragentinfo.h" #include "useragentwidget.h" -#include "application.h" -#include "mainwindow.h" #include "webtab.h" +#include "webview.h" // KDE Includes #include <KAction> @@ -44,30 +43,16 @@ UserAgentManager::UserAgentManager(QObject *parent) : QObject(parent) , _uaSettingsAction(0) - , _uaMenu(new KMenu) + , _uaTab(0) { _uaSettingsAction = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this); connect(_uaSettingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettings())); - - connect(_uaMenu, SIGNAL(aboutToShow()), this, SLOT(populateUserAgentMenu())); -} - - -UserAgentManager::~UserAgentManager() -{ - delete _uaMenu; -} - - -KMenu *UserAgentManager::userAgentMenu() -{ - return _uaMenu; } void UserAgentManager::showSettings() { - QPointer<KDialog> dialog = new KDialog; + QPointer<KDialog> dialog = new KDialog(_uaTab); dialog->setCaption(i18nc("@title:window", "User Agent Settings")); dialog->setButtons(KDialog::Ok); @@ -79,33 +64,38 @@ void UserAgentManager::showSettings() } -void UserAgentManager::populateUserAgentMenu() +void UserAgentManager::populateUAMenuForTabUrl(KMenu *uaMenu, WebTab *uaTab) { + if (_uaTab) + disconnect(this, SIGNAL(reloadTab()), _uaTab->view(), SLOT(reload())); + + _uaTab = uaTab; + connect(this, SIGNAL(reloadTab()), _uaTab->view(), SLOT(reload())); + bool defaultUA = true; - KUrl url = rApp->mainWindow()->currentTab()->url(); QAction *a, *defaultAction; // just to be sure... - _uaMenu->clear(); + uaMenu->clear(); - defaultAction = new QAction(i18nc("Default rekonq user agent", "Default"), this); + defaultAction = new QAction(i18nc("Default rekonq user agent", "Default"), uaMenu); defaultAction->setData(-1); defaultAction->setCheckable(true); connect(defaultAction, SIGNAL(triggered(bool)), this, SLOT(setUserAgent())); - _uaMenu->addAction(defaultAction); - _uaMenu->addSeparator(); + uaMenu->addAction(defaultAction); + uaMenu->addSeparator(); UserAgentInfo uaInfo; QStringList UAlist = uaInfo.availableUserAgents(); - int uaIndex = uaInfo.uaIndexForHost(url.host()); + int uaIndex = uaInfo.uaIndexForHost(_uaTab->url().host()); for (int i = 0; i < UAlist.count(); ++i) { QString uaDesc = UAlist.at(i); - a = new QAction(uaDesc, this); + a = new QAction(uaDesc, uaMenu); a->setData(i); a->setCheckable(true); connect(a, SIGNAL(triggered(bool)), this, SLOT(setUserAgent())); @@ -115,12 +105,12 @@ void UserAgentManager::populateUserAgentMenu() a->setChecked(true); defaultUA = false; } - _uaMenu->addAction(a); + uaMenu->addAction(a); } defaultAction->setChecked(defaultUA); - _uaMenu->addSeparator(); - _uaMenu->addAction(_uaSettingsAction); + uaMenu->addSeparator(); + uaMenu->addAction(_uaSettingsAction); } @@ -131,8 +121,7 @@ void UserAgentManager::setUserAgent() QString desc = sender->text(); int uaIndex = sender->data().toInt(); - KUrl url = rApp->mainWindow()->currentTab()->url(); UserAgentInfo uaInfo; - uaInfo.setUserAgentForHost(uaIndex, url.host()); - rApp->mainWindow()->currentTab()->page()->triggerAction(QWebPage::Reload); + uaInfo.setUserAgentForHost(uaIndex, _uaTab->url().host()); + emit reloadTab(); } diff --git a/src/useragent/useragentmanager.h b/src/useragent/useragentmanager.h index ae38ac6d..62bf4890 100644 --- a/src/useragent/useragentmanager.h +++ b/src/useragent/useragentmanager.h @@ -30,27 +30,31 @@ #include <QObject> +class WebTab; + class KAction; class KMenu; + class UserAgentManager : public QObject { Q_OBJECT public: UserAgentManager(QObject *parent = 0); - ~UserAgentManager(); - KMenu *userAgentMenu(); + void populateUAMenuForTabUrl(KMenu *, WebTab *); private Q_SLOTS: void showSettings(); void setUserAgent(); - void populateUserAgentMenu(); + +Q_SIGNALS: + void reloadTab(); private: KAction *_uaSettingsAction; - KMenu *_uaMenu; + WebTab *_uaTab; }; #endif // USER_AGENT_MANAGER_H |