summaryrefslogtreecommitdiff
path: root/src/useragent
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:09:41 +0100
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:09:41 +0100
commit288ace1df39dbea40cae66d0b04bfdefcd6cec70 (patch)
tree87c03b9dbfb330b7e743a45276d73de0cea0e950 /src/useragent
parentLindsay's credits (diff)
downloadrekonq-288ace1df39dbea40cae66d0b04bfdefcd6cec70.tar.xz
WARNING COMMIT --> FIRST REKONQ 2 IMPORT
Preparing repo to merge rekonq2 code...
Diffstat (limited to 'src/useragent')
-rw-r--r--src/useragent/useragentinfo.cpp202
-rw-r--r--src/useragent/useragentinfo.h86
-rw-r--r--src/useragent/useragentmanager.cpp173
-rw-r--r--src/useragent/useragentmanager.h63
-rw-r--r--src/useragent/useragentsettings.ui69
-rw-r--r--src/useragent/useragentwidget.cpp96
-rw-r--r--src/useragent/useragentwidget.h53
7 files changed, 0 insertions, 742 deletions
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 <adawit@kde.org>
-* Copyright (C) 2010-2012 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/>.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "useragentinfo.h"
-
-// Standard Includes
-#include <time.h>
-#include <sys/utsname.h>
-
-// KDE Includes
-#include <KService>
-#include <KServiceTypeTrader>
-
-#include <KConfig>
-#include <KConfigGroup>
-
-#include <KProtocolManager>
-
-// Qt includes
-#include <QStringBuilder>
-
-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 <adawit@kde.org>
-* Copyright (C) 2010-2012 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 USER_AGENT_INFO_H
-#define USER_AGENT_INFO_H
-
-
-// Rekonq Includes
-#include "rekonq_defines.h"
-
-// KDE Includes
-#include <KService>
-
-// Qt Includes
-#include <QString>
-
-
-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 <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/>.
-*
-* ============================================================ */
-
-
-// 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 <KAction>
-#include <KDialog>
-#include <KMenu>
-
-
-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<KDialog> 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<QAction *>(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 <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 USER_AGENT_MANAGER_H
-#define USER_AGENT_MANAGER_H
-
-
-// Qt Includes
-#include <QObject>
-#include <QWeakPointer>
-
-// 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<WebTab> 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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>UserAgent</class>
- <widget class="QWidget" name="UserAgent">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>609</width>
- <height>496</height>
- </rect>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QTreeWidget" name="sitePolicyTreeWidget">
- <property name="rootIsDecorated">
- <bool>false</bool>
- </property>
- <property name="sortingEnabled">
- <bool>true</bool>
- </property>
- <column>
- <property name="text">
- <string>Host</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Identification</string>
- </property>
- </column>
- </widget>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QPushButton" name="deleteButton">
- <property name="text">
- <string>Delete</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="deleteAllButton">
- <property name="text">
- <string>Delete All</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
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 <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/>.
-*
-* ============================================================ */
-
-
-// Self Includes
-#include "useragentwidget.h"
-#include "useragentwidget.moc"
-
-// KDE Includes
-#include <KProtocolManager>
-
-
-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 <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 USER_AGENT_WIDGET_H
-#define USER_AGENT_WIDGET_H
-
-
-// Rekonq Includes
-#include "rekonq_defines.h"
-
-// Qt Includes
-#include <QWidget>
-
-// 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