diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2011-11-24 18:04:36 +0100 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2011-11-26 00:20:20 +0100 |
commit | 57afe14d972af3d7073926301c0c4f4ebf627171 (patch) | |
tree | 2b410f47ad1c74ba3f6973ceb548a5769f3a8780 | |
parent | clean up UserAgentManager code (diff) | |
download | rekonq-57afe14d972af3d7073926301c0c4f4ebf627171.tar.xz |
refactor UA menu to let it be in the same shape as Konqueror
REVIEW: 103230
REVIEWED-BY: fritz_van_tom
-rw-r--r-- | src/useragent/useragentinfo.cpp | 19 | ||||
-rw-r--r-- | src/useragent/useragentinfo.h | 6 | ||||
-rw-r--r-- | src/useragent/useragentmanager.cpp | 72 | ||||
-rw-r--r-- | src/useragent/useragentmanager.h | 4 |
4 files changed, 73 insertions, 28 deletions
diff --git a/src/useragent/useragentinfo.cpp b/src/useragent/useragentinfo.cpp index 0829a7e1..6ac411ba 100644 --- a/src/useragent/useragentinfo.cpp +++ b/src/useragent/useragentinfo.cpp @@ -46,18 +46,13 @@ UserAgentInfo::UserAgentInfo() { - /* KService::List m_providers = KServiceTypeTrader::self()->query("UserAgentStrings");*/ - - // NOTE: limiting User Agent Numbers - m_providers << KService::serviceByDesktopName("firefox36oncurrent"); - m_providers << KService::serviceByDesktopName("ie70onwinnt51"); - m_providers << KService::serviceByDesktopName("ie60oncurrent"); - m_providers << KService::serviceByDesktopName("chrome50oncurrent"); - m_providers << KService::serviceByDesktopName("safari40"); - m_providers << KService::serviceByDesktopName("op962oncurrent"); - m_providers << KService::serviceByDesktopName("ns71oncurrent"); - m_providers << KService::serviceByDesktopName("android10"); - m_providers << KService::serviceByDesktopName("googlebot"); + m_providers = KServiceTypeTrader::self()->query("UserAgentStrings"); +} + + +KService::List UserAgentInfo::availableProviders() const +{ + return m_providers; } diff --git a/src/useragent/useragentinfo.h b/src/useragent/useragentinfo.h index 417aeea1..86319d9e 100644 --- a/src/useragent/useragentinfo.h +++ b/src/useragent/useragentinfo.h @@ -46,6 +46,12 @@ public: UserAgentInfo(); /** + * Lists all available providers + * + */ + KService::List availableProviders() const; + + /** * Lists all available User Agents * * @returns the list of the UA descriptions diff --git a/src/useragent/useragentmanager.cpp b/src/useragent/useragentmanager.cpp index 78b5b1c0..20043549 100644 --- a/src/useragent/useragentmanager.cpp +++ b/src/useragent/useragentmanager.cpp @@ -42,17 +42,17 @@ UserAgentManager::UserAgentManager(QObject *parent) : QObject(parent) - , _uaSettingsAction(0) - , _uaTab(0) + , m_uaSettingsAction(0) + , m_uaTab(0) { - _uaSettingsAction = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this); - connect(_uaSettingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettings())); + m_uaSettingsAction = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this); + connect(m_uaSettingsAction, SIGNAL(triggered(bool)), this, SLOT(showSettings())); } void UserAgentManager::showSettings() { - QPointer<KDialog> dialog = new KDialog(_uaTab); + QPointer<KDialog> dialog = new KDialog(m_uaTab); dialog->setCaption(i18nc("@title:window", "User Agent Settings")); dialog->setButtons(KDialog::Ok); @@ -66,11 +66,11 @@ void UserAgentManager::showSettings() void UserAgentManager::populateUAMenuForTabUrl(KMenu *uaMenu, WebTab *uaTab) { - if (_uaTab) - disconnect(this, SIGNAL(reloadTab()), _uaTab->view(), SLOT(reload())); + if (m_uaTab) + disconnect(this, SIGNAL(reloadTab()), m_uaTab->view(), SLOT(reload())); - _uaTab = uaTab; - connect(this, SIGNAL(reloadTab()), _uaTab->view(), SLOT(reload())); + m_uaTab = uaTab; + connect(this, SIGNAL(reloadTab()), m_uaTab->view(), SLOT(reload())); bool defaultUA = true; @@ -87,9 +87,29 @@ void UserAgentManager::populateUAMenuForTabUrl(KMenu *uaMenu, WebTab *uaTab) uaMenu->addAction(defaultAction); uaMenu->addSeparator(); + // Main Browsers Menus + KMenu *ffMenu = new KMenu(i18n("Firefox"), uaMenu); + uaMenu->addMenu(ffMenu); + + KMenu *ieMenu = new KMenu(i18n("Internet Explorer"), uaMenu); + uaMenu->addMenu(ieMenu); + + KMenu *nsMenu = new KMenu(i18n("Netscape"), uaMenu); + uaMenu->addMenu(nsMenu); + + KMenu *opMenu = new KMenu(i18n("Opera"), uaMenu); + uaMenu->addMenu(opMenu); + + KMenu *sfMenu = new KMenu(i18n("Safari"), uaMenu); + uaMenu->addMenu(sfMenu); + + KMenu *otMenu = new KMenu(i18n("Other"), uaMenu); + uaMenu->addMenu(otMenu); + UserAgentInfo uaInfo; QStringList UAlist = uaInfo.availableUserAgents(); - int uaIndex = uaInfo.uaIndexForHost(_uaTab->url().host()); + const KService::List providers = uaInfo.availableProviders(); + int uaIndex = uaInfo.uaIndexForHost(m_uaTab->url().host()); for (int i = 0; i < UAlist.count(); ++i) { @@ -105,12 +125,37 @@ void UserAgentManager::populateUAMenuForTabUrl(KMenu *uaMenu, WebTab *uaTab) a->setChecked(true); defaultUA = false; } - uaMenu->addAction(a); + + QString tag = providers.at(i)->property("X-KDE-UA-TAG").toString(); + if (tag == QL1S("FF")) + { + ffMenu->addAction(a); + } + else if (tag == QL1S("IE")) + { + ieMenu->addAction(a); + } + else if (tag == QL1S("NN")) + { + nsMenu->addAction(a); + } + else if (tag == QL1S("OPR")) + { + opMenu->addAction(a); + } + else if (tag == QL1S("SAF")) + { + sfMenu->addAction(a); + } + else // OTHERs + { + otMenu->addAction(a); + } } defaultAction->setChecked(defaultUA); uaMenu->addSeparator(); - uaMenu->addAction(_uaSettingsAction); + uaMenu->addAction(m_uaSettingsAction); } @@ -118,10 +163,9 @@ void UserAgentManager::setUserAgent() { QAction *sender = static_cast<QAction *>(QObject::sender()); - QString desc = sender->text(); int uaIndex = sender->data().toInt(); UserAgentInfo uaInfo; - uaInfo.setUserAgentForHost(uaIndex, _uaTab->url().host()); + uaInfo.setUserAgentForHost(uaIndex, m_uaTab->url().host()); emit reloadTab(); } diff --git a/src/useragent/useragentmanager.h b/src/useragent/useragentmanager.h index 62bf4890..0592e55c 100644 --- a/src/useragent/useragentmanager.h +++ b/src/useragent/useragentmanager.h @@ -53,8 +53,8 @@ Q_SIGNALS: void reloadTab(); private: - KAction *_uaSettingsAction; - WebTab *_uaTab; + KAction *m_uaSettingsAction; + WebTab *m_uaTab; }; #endif // USER_AGENT_MANAGER_H |