summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/application.cpp18
-rw-r--r--src/application.h3
-rw-r--r--src/mainwindow.cpp84
-rw-r--r--src/mainwindow.h7
-rw-r--r--src/useragent/useragentmanager.cpp138
-rw-r--r--src/useragent/useragentmanager.h56
7 files changed, 218 insertions, 89 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ced397c7..ea33df82 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -90,6 +90,7 @@ SET( rekonq_KDEINIT_SRCS
opensearch/suggestionparser.cpp
#----------------------------------------
useragent/useragentinfo.cpp
+ useragent/useragentmanager.cpp
useragent/useragentwidget.cpp
)
diff --git a/src/application.cpp b/src/application.cpp
index f37720ff..14e34686 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -50,6 +50,7 @@
#include "stackedurlbar.h"
#include "tabbar.h"
#include "urlbar.h"
+#include "useragentmanager.h"
#include "webtab.h"
// KDE Includes
@@ -142,6 +143,13 @@ Application::~Application()
m_adblockManager.clear();
}
+ if (!m_userAgentManager.isNull())
+ {
+ kDebug() << "deleting user agent manager";
+ delete m_userAgentManager.data();
+ m_userAgentManager.clear();
+ }
+
// TODO:
// add a check to NOT close rekonq
// until last download is finished
@@ -385,6 +393,16 @@ DownloadManager *Application::downloadManager()
}
+UserAgentManager *Application::userAgentManager()
+{
+ if (m_userAgentManager.isNull())
+ {
+ m_userAgentManager = new UserAgentManager(instance());
+ }
+ return m_userAgentManager.data();
+}
+
+
void Application::loadUrl(const KUrl& url, const Rekonq::OpenType& type)
{
if (url.isEmpty())
diff --git a/src/application.h b/src/application.h
index acc0335f..02b3009b 100644
--- a/src/application.h
+++ b/src/application.h
@@ -52,6 +52,7 @@ class IconManager;
class MainWindow;
class OpenSearchManager;
class SessionManager;
+class UserAgentManager;
class KAction;
@@ -94,6 +95,7 @@ public:
OpenSearchManager *opensearchManager();
IconManager *iconManager();
DownloadManager *downloadManager();
+ UserAgentManager *userAgentManager();
KAction *privateBrowsingAction()
{
@@ -139,6 +141,7 @@ private:
QWeakPointer<OpenSearchManager> m_opensearchManager;
QWeakPointer<IconManager> m_iconManager;
QWeakPointer<DownloadManager> m_downloadManager;
+ QWeakPointer<UserAgentManager> m_userAgentManager;
MainWindowList m_mainWindows;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index c53fcb6c..f242439f 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -55,8 +55,7 @@
#include "webpage.h"
#include "webtab.h"
#include "zoombar.h"
-#include "useragentinfo.h"
-#include "useragentwidget.h"
+#include "useragentmanager.h"
// Ui Includes
#include "ui_cleardata.h"
@@ -113,7 +112,6 @@ MainWindow::MainWindow()
, m_analyzerPanel(0)
, m_historyBackMenu(0)
, m_historyForwardMenu(0)
- , m_userAgentMenu(new KMenu(this))
, m_bookmarksBar(0)
, m_popup(new QLabel(this))
, m_hidePopupTimer(new QTimer(this))
@@ -504,12 +502,7 @@ void MainWindow::setupActions()
// User Agent
a = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this);
actionCollection()->addAction(QL1S("useragent"), a);
- a->setMenu(m_userAgentMenu);
- connect(m_userAgentMenu, SIGNAL(aboutToShow()), this, SLOT(populateUserAgentMenu()));
-
- a = new KAction(KIcon("preferences-web-browser-identification"), i18n("Browser Identification"), this);
- actionCollection()->addAction(QL1S("UserAgentSettings"), a);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(showUserAgentSettings()));
+ a->setMenu(rApp->userAgentManager()->userAgentMenu());
// Editable Page
a = new KAction(KIcon("document-edit"), i18n("Set Editable"), this);
@@ -1438,65 +1431,6 @@ void MainWindow::openActionTab(QAction* action)
}
-void MainWindow::setUserAgent()
-{
- QAction *sender = static_cast<QAction *>(QObject::sender());
-
- QString info;
- QString desc = sender->text();
- int uaIndex = sender->data().toInt();
-
- KUrl url = currentTab()->url();
- UserAgentInfo uaInfo;
- uaInfo.setUserAgentForHost(uaIndex, url.host());
- currentTab()->page()->triggerAction(QWebPage::Reload);
-}
-
-
-void MainWindow::populateUserAgentMenu()
-{
- bool defaultUA = true;
- KUrl url = currentTab()->url();
-
- QAction *a, *defaultAction;
-
- m_userAgentMenu->clear();
-
- defaultAction = new QAction(i18nc("Default rekonq user agent", "Default"), this);
- defaultAction->setData(-1);
- defaultAction->setCheckable(true);
- connect(defaultAction, SIGNAL(triggered(bool)), this, SLOT(setUserAgent()));
-
- m_userAgentMenu->addAction(defaultAction);
- m_userAgentMenu->addSeparator();
-
- UserAgentInfo uaInfo;
- QStringList UAlist = uaInfo.availableUserAgents();
- int uaIndex = uaInfo.uaIndexForHost(currentTab()->url().host());
-
- for (int i = 0; i < UAlist.count(); ++i)
- {
- QString uaDesc = UAlist.at(i);
-
- a = new QAction(uaDesc, this);
- a->setData(i);
- a->setCheckable(true);
- connect(a, SIGNAL(triggered(bool)), this, SLOT(setUserAgent()));
-
- if (i == uaIndex)
- {
- a->setChecked(true);
- defaultUA = false;
- }
- m_userAgentMenu->addAction(a);
- }
- defaultAction->setChecked(defaultUA);
-
- m_userAgentMenu->addSeparator();
- m_userAgentMenu->addAction(actionByName("UserAgentSettings"));
-}
-
-
void MainWindow::enableNetworkAnalysis(bool b)
{
currentTab()->page()->enableNetworkAnalyzer(b);
@@ -1529,20 +1463,6 @@ void MainWindow::setupBookmarksAndToolsShortcuts()
}
-void MainWindow::showUserAgentSettings()
-{
- QPointer<KDialog> dialog = new KDialog(this);
- dialog->setCaption(i18nc("@title:window", "User Agent Settings"));
- dialog->setButtons(KDialog::Ok);
-
- UserAgentWidget widget;
- dialog->setMainWidget(&widget);
- dialog->exec();
-
- dialog->deleteLater();
-}
-
-
void MainWindow::moveEvent(QMoveEvent *event)
{
if (m_hidePopupTimer)
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 9dfe4a1e..3b5706c6 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -176,11 +176,6 @@ private Q_SLOTS:
void openActionUrl(QAction *action);
void openActionTab(QAction *action);
- // user agent
- void setUserAgent();
- void populateUserAgentMenu();
- void showUserAgentSettings();
-
void enableNetworkAnalysis(bool);
void setEditable(bool);
@@ -204,8 +199,6 @@ private:
KMenu *m_tabListMenu;
- KMenu *m_userAgentMenu;
-
BookmarkToolBar *m_bookmarksBar;
QString m_lastSearch;
diff --git a/src/useragent/useragentmanager.cpp b/src/useragent/useragentmanager.cpp
new file mode 100644
index 00000000..db6e0708
--- /dev/null
+++ b/src/useragent/useragentmanager.cpp
@@ -0,0 +1,138 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 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 "useragentmanager.h"
+#include "useragentmanager.moc"
+
+// Local Includes
+#include "useragentinfo.h"
+#include "useragentwidget.h"
+#include "application.h"
+#include "mainwindow.h"
+#include "webtab.h"
+
+// KDE Includes
+#include <KAction>
+#include <KDialog>
+#include <KMenu>
+
+
+UserAgentManager::UserAgentManager(QObject *parent)
+ : QObject(parent)
+ , _uaSettingsAction(0)
+ , _uaMenu(new KMenu)
+{
+ _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;
+ dialog->setCaption(i18nc("@title:window", "User Agent Settings"));
+ dialog->setButtons(KDialog::Ok);
+
+ UserAgentWidget widget;
+ dialog->setMainWidget(&widget);
+ dialog->exec();
+
+ dialog->deleteLater();
+}
+
+
+void UserAgentManager::populateUserAgentMenu()
+{
+ bool defaultUA = true;
+ KUrl url = rApp->mainWindow()->currentTab()->url();
+
+ QAction *a, *defaultAction;
+
+ // just to be sure...
+ _uaMenu->clear();
+
+ defaultAction = new QAction(i18nc("Default rekonq user agent", "Default"), this);
+ defaultAction->setData(-1);
+ defaultAction->setCheckable(true);
+ connect(defaultAction, SIGNAL(triggered(bool)), this, SLOT(setUserAgent()));
+
+ _uaMenu->addAction(defaultAction);
+ _uaMenu->addSeparator();
+
+ UserAgentInfo uaInfo;
+ QStringList UAlist = uaInfo.availableUserAgents();
+ int uaIndex = uaInfo.uaIndexForHost(url.host());
+
+ for (int i = 0; i < UAlist.count(); ++i)
+ {
+ QString uaDesc = UAlist.at(i);
+
+ a = new QAction(uaDesc, this);
+ a->setData(i);
+ a->setCheckable(true);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(setUserAgent()));
+
+ if (i == uaIndex)
+ {
+ a->setChecked(true);
+ defaultUA = false;
+ }
+ _uaMenu->addAction(a);
+ }
+ defaultAction->setChecked(defaultUA);
+
+ _uaMenu->addSeparator();
+ _uaMenu->addAction(_uaSettingsAction);
+}
+
+
+void UserAgentManager::setUserAgent()
+{
+ QAction *sender = static_cast<QAction *>(QObject::sender());
+
+ 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);
+}
diff --git a/src/useragent/useragentmanager.h b/src/useragent/useragentmanager.h
new file mode 100644
index 00000000..ae38ac6d
--- /dev/null
+++ b/src/useragent/useragentmanager.h
@@ -0,0 +1,56 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 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_MANAGER_H
+#define USER_AGENT_MANAGER_H
+
+
+#include <QObject>
+
+class KAction;
+class KMenu;
+
+class UserAgentManager : public QObject
+{
+ Q_OBJECT
+
+public:
+ UserAgentManager(QObject *parent = 0);
+ ~UserAgentManager();
+
+ KMenu *userAgentMenu();
+
+private Q_SLOTS:
+ void showSettings();
+ void setUserAgent();
+ void populateUserAgentMenu();
+
+private:
+ KAction *_uaSettingsAction;
+ KMenu *_uaMenu;
+};
+
+#endif // USER_AGENT_MANAGER_H