From 288ace1df39dbea40cae66d0b04bfdefcd6cec70 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 10 Dec 2012 02:09:41 +0100 Subject: WARNING COMMIT --> FIRST REKONQ 2 IMPORT Preparing repo to merge rekonq2 code... --- src/useragent/useragentinfo.cpp | 202 ------------------------------------- src/useragent/useragentinfo.h | 86 ---------------- src/useragent/useragentmanager.cpp | 173 ------------------------------- src/useragent/useragentmanager.h | 63 ------------ src/useragent/useragentsettings.ui | 69 ------------- src/useragent/useragentwidget.cpp | 96 ------------------ src/useragent/useragentwidget.h | 53 ---------- 7 files changed, 742 deletions(-) delete mode 100644 src/useragent/useragentinfo.cpp delete mode 100644 src/useragent/useragentinfo.h delete mode 100644 src/useragent/useragentmanager.cpp delete mode 100644 src/useragent/useragentmanager.h delete mode 100644 src/useragent/useragentsettings.ui delete mode 100644 src/useragent/useragentwidget.cpp delete mode 100644 src/useragent/useragentwidget.h (limited to 'src/useragent') diff --git a/src/useragent/useragentinfo.cpp b/src/useragent/useragentinfo.cpp deleted file mode 100644 index 00f0a9db..00000000 --- a/src/useragent/useragentinfo.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (c) 2001 by Dawit Alemayehu -* Copyright (C) 2010-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 "useragentinfo.h" - -// Standard Includes -#include -#include - -// KDE Includes -#include -#include - -#include -#include - -#include - -// Qt includes -#include - -UserAgentInfo::UserAgentInfo() -{ - m_providers = KServiceTypeTrader::self()->query("UserAgentStrings"); -} - - -KService::List UserAgentInfo::availableProviders() const -{ - return m_providers; -} - - -QString UserAgentInfo::userAgentString(int i) -{ - if (i < 0 || !providerExists(i)) - { - kDebug() << "oh oh... wrong index on the user agent choice! INDEX = " << i; - return QL1S("Default"); - } - - QString tmp = m_providers.at(i)->property("X-KDE-UA-FULL").toString(); - - struct utsname utsn; - uname(&utsn); - - tmp.replace(QL1S("appSysName"), QString(utsn.sysname)); - tmp.replace(QL1S("appSysRelease"), QString(utsn.release)); - tmp.replace(QL1S("appMachineType"), QString(utsn.machine)); - - QStringList languageList = KGlobal::locale()->languageList(); - if (languageList.count()) - { - int ind = languageList.indexOf(QL1S("C")); - if (ind >= 0) - { - if (languageList.contains(QL1S("en"))) - languageList.removeAt(ind); - else - languageList.value(ind) = QL1S("en"); - } - } - - tmp.replace(QL1S("appLanguage"), QString("%1").arg(languageList.join(", "))); - tmp.replace(QL1S("appPlatform"), QL1S("X11")); - - return tmp; -} - - -QString UserAgentInfo::userAgentName(int i) -{ - if (i < 0 || !providerExists(i)) - { - kDebug() << "oh oh... wrong index on the user agent choice! INDEX = " << i; - return QL1S("Default"); - } - - return m_providers.at(i)->property("X-KDE-UA-NAME").toString(); -} - - -QString UserAgentInfo::userAgentVersion(int i) -{ - if (i < 0 || !providerExists(i)) - { - kDebug() << "oh oh... wrong index on the user agent choice! INDEX = " << i; - return QL1S("Default"); - } - - return m_providers.at(i)->property("X-KDE-UA-VERSION").toString(); -} - - -QString UserAgentInfo::userAgentDescription(int i) -{ - if (i < 0 || !providerExists(i)) - { - kDebug() << "oh oh... wrong index on the user agent choice! INDEX = " << i; - return QL1S("Default"); - } - - QString systemName = m_providers.at(i)->property("X-KDE-UA-SYSNAME").toString(); - QString systemRelease = m_providers.at(i)->property("X-KDE-UA-SYSRELEASE").toString(); - QString systemSummary; - - if (!systemName.isEmpty() && !systemRelease.isEmpty()) - { - systemSummary = i18nc("describe UA platform, eg: firefox 3.1 \"on Windows XP\"", " on %1 %2", systemName, systemRelease); - } - - return userAgentName(i) % QL1C(' ') % userAgentVersion(i) % systemSummary; -} - - -QStringList UserAgentInfo::availableUserAgents() -{ - QStringList UAs; - int n = m_providers.count(); - for (int i = 0; i < n; ++i) - { - UAs << userAgentDescription(i); - } - return UAs; -} - - -bool UserAgentInfo::setUserAgentForHost(int uaIndex, const QString &host) -{ - KConfig config("kio_httprc", KConfig::NoGlobals); - - QStringList modifiedHosts = config.groupList(); - KConfigGroup hostGroup(&config, host); - - if (uaIndex == -1) - { - if (!hostGroup.exists()) - { - kDebug() << "Host does NOT exists!"; - return false; - } - hostGroup.deleteGroup(); - KProtocolManager::reparseConfiguration(); - return true; - } - - hostGroup.writeEntry(QL1S("UserAgent"), userAgentString(uaIndex)); - - KProtocolManager::reparseConfiguration(); - return true; -} - - -int UserAgentInfo::uaIndexForHost(const QString &host) -{ - QString KDEUserAgent = KProtocolManager::userAgentForHost(host); - - int n = m_providers.count(); - for (int i = 0; i < n; ++i) - { - QString rekonqUserAgent = userAgentString(i); - if (KDEUserAgent == rekonqUserAgent) - return i; - } - return -1; -} - - -bool UserAgentInfo::providerExists(int i) -{ - KService::Ptr s = m_providers.at(i); - if (s.isNull()) - { - return false; - } - return true; -} diff --git a/src/useragent/useragentinfo.h b/src/useragent/useragentinfo.h deleted file mode 100644 index 3162fa82..00000000 --- a/src/useragent/useragentinfo.h +++ /dev/null @@ -1,86 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (c) 2001 by Dawit Alemayehu -* Copyright (C) 2010-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 USER_AGENT_INFO_H -#define USER_AGENT_INFO_H - - -// Rekonq Includes -#include "rekonq_defines.h" - -// KDE Includes -#include - -// Qt Includes -#include - - -class UserAgentInfo -{ -public: - UserAgentInfo(); - - /** - * Lists all available providers - * - */ - KService::List availableProviders() const; - - /** - * Lists all available User Agents - * - * @returns the list of the UA descriptions - */ - QStringList availableUserAgents(); - - /** - * Set User Agent for host - * - * @param uaIndex the index of the UA description. @see availableUserAgents() - * @param host the host to se the UA - */ - bool setUserAgentForHost(int uaIndex, const QString &host); - - /** - * @returns the index of the UA set for the @p host - */ - int uaIndexForHost(const QString &); - -private: - QString userAgentString(int); - QString userAgentName(int); - QString userAgentVersion(int); - QString userAgentDescription(int); - - bool providerExists(int); - -private: - KService::List m_providers; -}; - -#endif // USER_AGENT_INFO_H diff --git a/src/useragent/useragentmanager.cpp b/src/useragent/useragentmanager.cpp deleted file mode 100644 index 9a2db3c9..00000000 --- a/src/useragent/useragentmanager.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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 "useragentmanager.h" -#include "useragentmanager.moc" - -// Local Includes -#include "useragentinfo.h" -#include "useragentwidget.h" -#include "webtab.h" -#include "webview.h" - -// KDE Includes -#include -#include -#include - - -UserAgentManager::UserAgentManager(QObject *parent) - : QObject(parent) - , m_uaSettingsAction(0) -{ - 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 dialog = new KDialog(m_uaTab.data()); - dialog->setCaption(i18nc("@title:window", "User Agent Settings")); - dialog->setButtons(KDialog::Ok); - - UserAgentWidget widget; - dialog->setMainWidget(&widget); - dialog->exec(); - - dialog->deleteLater(); -} - - -void UserAgentManager::populateUAMenuForTabUrl(KMenu *uaMenu, WebTab *uaTab) -{ - if (!m_uaTab.isNull()) - { - disconnect(this, SIGNAL(reloadTab()), m_uaTab.data()->view(), SLOT(reload())); - m_uaTab.clear(); - } - - m_uaTab = uaTab; - connect(this, SIGNAL(reloadTab()), m_uaTab.data()->view(), SLOT(reload())); - - bool defaultUA = true; - - QAction *a, *defaultAction; - - // just to be sure... - uaMenu->clear(); - - 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(); - - // 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(); - const KService::List providers = uaInfo.availableProviders(); - int uaIndex = uaInfo.uaIndexForHost(m_uaTab.data()->url().host()); - - for (int i = 0; i < UAlist.count(); ++i) - { - QString uaDesc = UAlist.at(i); - - a = new QAction(uaDesc, uaMenu); - a->setData(i); - a->setCheckable(true); - connect(a, SIGNAL(triggered(bool)), this, SLOT(setUserAgent())); - - if (i == uaIndex) - { - a->setChecked(true); - defaultUA = false; - } - - 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(m_uaSettingsAction); -} - - -void UserAgentManager::setUserAgent() -{ - QAction *sender = static_cast(QObject::sender()); - - int uaIndex = sender->data().toInt(); - - UserAgentInfo uaInfo; - uaInfo.setUserAgentForHost(uaIndex, m_uaTab.data()->url().host()); - emit reloadTab(); -} diff --git a/src/useragent/useragentmanager.h b/src/useragent/useragentmanager.h deleted file mode 100644 index 57a65c31..00000000 --- a/src/useragent/useragentmanager.h +++ /dev/null @@ -1,63 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2011-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 USER_AGENT_MANAGER_H -#define USER_AGENT_MANAGER_H - - -// Qt Includes -#include -#include - -// Forward Declarations -class WebTab; - -class KAction; -class KMenu; - - -class UserAgentManager : public QObject -{ - Q_OBJECT - -public: - UserAgentManager(QObject *parent = 0); - - void populateUAMenuForTabUrl(KMenu *, WebTab *); - -private Q_SLOTS: - void showSettings(); - void setUserAgent(); - -Q_SIGNALS: - void reloadTab(); - -private: - KAction *m_uaSettingsAction; - QWeakPointer m_uaTab; -}; - -#endif // USER_AGENT_MANAGER_H diff --git a/src/useragent/useragentsettings.ui b/src/useragent/useragentsettings.ui deleted file mode 100644 index e2cd5454..00000000 --- a/src/useragent/useragentsettings.ui +++ /dev/null @@ -1,69 +0,0 @@ - - - UserAgent - - - - 0 - 0 - 609 - 496 - - - - - - - false - - - true - - - - Host - - - - - Identification - - - - - - - - - - Delete - - - - - - - Delete All - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - diff --git a/src/useragent/useragentwidget.cpp b/src/useragent/useragentwidget.cpp deleted file mode 100644 index 92ba3ce4..00000000 --- a/src/useragent/useragentwidget.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010-2011 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 "useragentwidget.h" -#include "useragentwidget.moc" - -// KDE Includes -#include - - -UserAgentWidget::UserAgentWidget(QWidget *parent) - : QWidget(parent) -{ - setupUi(this); - - connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteUserAgent())); - connect(deleteAllButton, SIGNAL(clicked()), this, SLOT(deleteAll())); - - KConfig config("kio_httprc", KConfig::NoGlobals); - - QStringList hosts = config.groupList(); - Q_FOREACH(const QString & host, hosts) - { - QStringList tmp; - tmp << host; - - KConfigGroup hostGroup(&config, host); - tmp << hostGroup.readEntry(QL1S("UserAgent"), QString()); - - QTreeWidgetItem *item = new QTreeWidgetItem(sitePolicyTreeWidget, tmp); - sitePolicyTreeWidget->addTopLevelItem(item); - } -} - - -void UserAgentWidget::deleteUserAgent() -{ - QTreeWidgetItem *item = sitePolicyTreeWidget->currentItem(); - if (!item) - return; - - sitePolicyTreeWidget->takeTopLevelItem(sitePolicyTreeWidget->indexOfTopLevelItem(item)); - - QString host = item->text(0); - - KConfig config("kio_httprc", KConfig::NoGlobals); - KConfigGroup group(&config, host); - if (group.exists()) - { - group.deleteGroup(); - KProtocolManager::reparseConfiguration(); - } -} - - -void UserAgentWidget::deleteAll() -{ - sitePolicyTreeWidget->clear(); - - KConfig config("kio_httprc", KConfig::NoGlobals); - - QStringList list = config.groupList(); - Q_FOREACH(const QString & groupName, list) - { - KConfigGroup group(&config, groupName); - group.deleteGroup(); - } - KConfigGroup group(&config, QString()); - group.deleteGroup(); - - KProtocolManager::reparseConfiguration(); -} diff --git a/src/useragent/useragentwidget.h b/src/useragent/useragentwidget.h deleted file mode 100644 index 1c850d9e..00000000 --- a/src/useragent/useragentwidget.h +++ /dev/null @@ -1,53 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2010-2011 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 USER_AGENT_WIDGET_H -#define USER_AGENT_WIDGET_H - - -// Rekonq Includes -#include "rekonq_defines.h" - -// Qt Includes -#include - -// Ui Includes -#include "ui_useragentsettings.h" - - -class UserAgentWidget : public QWidget, private Ui::UserAgent -{ - Q_OBJECT - -public: - UserAgentWidget(QWidget *parent = 0); - -private Q_SLOTS: - void deleteUserAgent(); - void deleteAll(); -}; - -#endif -- cgit v1.2.1