summaryrefslogtreecommitdiff
path: root/src/webwindow
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-08-06 15:37:28 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-12-10 02:48:04 +0100
commit095efa83a05459336decb6ff565496ebc11fd026 (patch)
tree3f7fc03a4ce646d28be77f2ef87b6fe19ab67b8e /src/webwindow
parentset window object name right (diff)
downloadrekonq-095efa83a05459336decb6ff565496ebc11fd026.tar.xz
Add RekonqFactory to locally generate rekonq toolbars and menus by the
ui xml file
Diffstat (limited to 'src/webwindow')
-rw-r--r--src/webwindow/rekonqfactory.cpp173
-rw-r--r--src/webwindow/rekonqfactory.h48
-rw-r--r--src/webwindow/webwindow.cpp205
-rw-r--r--src/webwindow/webwindow.h6
4 files changed, 422 insertions, 10 deletions
diff --git a/src/webwindow/rekonqfactory.cpp b/src/webwindow/rekonqfactory.cpp
new file mode 100644
index 00000000..e3f62f9f
--- /dev/null
+++ b/src/webwindow/rekonqfactory.cpp
@@ -0,0 +1,173 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 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/>.
+*
+* ============================================================ */
+
+
+#include "rekonqfactory.h"
+
+#include "rekonqmenu.h"
+
+#include <KActionCollection>
+#include <KMenu>
+#include <KStandardDirs>
+#include <KToolBar>
+
+#include <QFile>
+#include <QString>
+#include <QWidget>
+
+#include <QDomDocument>
+#include <QDomElement>
+
+
+QWidget *RekonqFactory::createWidget(const QString &name, QWidget *parent, KActionCollection *ac)
+{
+ QString xmlFilePath;
+ xmlFilePath = KStandardDirs::locateLocal( "data", "rekonq/rekonqui.rc");
+ kDebug() << "local xmlfile: " << xmlFilePath;
+ if (!QFile::exists(xmlFilePath))
+ {
+ xmlFilePath = KStandardDirs::locate( "data", "rekonq/rekonqui.rc");
+ kDebug() << "general xmlfile: " << xmlFilePath;
+ }
+
+ QFile xmlFile(xmlFilePath);
+
+ QDomDocument document("rekonqui.rc");
+ document.setContent(&xmlFile, false);
+
+ // Toolbars ----------------------------------------------------------------------
+ QDomNodeList elementList = document.elementsByTagName(QL1S("ToolBar"));
+ if (elementList.isEmpty())
+ {
+ return 0;
+ }
+
+ for(unsigned int i = 0; i < elementList.length(); ++i)
+ {
+ QDomElement element = elementList.at(i).toElement();
+
+ if (element.attribute("name") != name)
+ continue;
+
+ if (element.attribute("deleted").toLower() == "true")
+ {
+ return 0;
+ }
+ KToolBar *bar = new KToolBar(parent, false, false);
+ QDomNodeList actionList = element.elementsByTagName(QL1S("Action"));
+
+ for(unsigned int j = 0; j < actionList.length(); ++j)
+ {
+ QDomElement actionElement = actionList.at(j).toElement();
+ const QString actionName = actionElement.attribute("name");
+ QAction *a = ac->action(actionName);
+ if (a)
+ bar->addAction(a);
+ }
+
+ return bar;
+ }
+
+ // Rekonq Menu ----------------------------------------------------------------------
+ QDomNodeList elementMenuList = document.elementsByTagName(QL1S("Menu"));
+ if (elementMenuList.isEmpty())
+ {
+ return 0;
+ }
+
+ for(unsigned int i = 0; i < elementMenuList.length(); ++i)
+ {
+ QDomNode node = elementMenuList.at(i);
+ QDomElement element = node.toElement();
+ if (element.attribute("name") != name)
+ continue;
+
+ if (element.attribute("deleted").toLower() == "true")
+ {
+ return 0;
+ }
+
+ if (name == QL1S("rekonqMenu"))
+ {
+ RekonqMenu *m = new RekonqMenu(parent);
+ kDebug() << "filling menu...";
+ fillMenu(m, node, ac);
+ return m;
+ }
+ else
+ {
+ KMenu *m = new KMenu(parent);
+ fillMenu(m, node, ac);
+ return m;
+ }
+
+ }
+
+ kDebug() << "NO WIDGET RETURNED";
+ return 0;
+}
+
+
+void RekonqFactory::fillMenu(KMenu *m, QDomNode node, KActionCollection *ac)
+{
+ QDomNodeList childrenList = node.childNodes();
+
+ for(unsigned int i = 0; i < childrenList.length(); ++i)
+ {
+ QDomElement el = childrenList.at(i).toElement();
+
+ if (el.tagName() == QL1S("Action"))
+ {
+ const QString actionName = el.attribute("name");
+ QAction *a = ac->action(actionName);
+ if (a)
+ {
+ kDebug() << "ADDING ACTION " << actionName << " to menu " << m;
+ m->addAction(a);
+ }
+
+ }
+
+ if (el.tagName() == QL1S("Separator"))
+ {
+ m->addSeparator();
+ }
+
+ if (el.tagName() == QL1S("Menu"))
+ {
+ const QString menuName = el.attribute("name");
+ KMenu *subm = qobject_cast<KMenu *>(createWidget(menuName, m, ac));
+ m->addMenu(subm);
+ }
+
+ if (el.tagName() == QL1S("text"))
+ {
+ const QString menuTitle = el.text();
+ m->setTitle(menuTitle);
+ }
+
+ }
+}
+
diff --git a/src/webwindow/rekonqfactory.h b/src/webwindow/rekonqfactory.h
new file mode 100644
index 00000000..6a59adcd
--- /dev/null
+++ b/src/webwindow/rekonqfactory.h
@@ -0,0 +1,48 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 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 REKONQ_FACTORY_H
+#define REKONQ_FACTORY_H
+
+// Rekonq Includes
+#include "rekonq_defines.h"
+
+class KActionCollection;
+class KMenu;
+
+class QDomNode;
+class QString;
+class QWidget;
+
+
+namespace RekonqFactory
+{
+ QWidget *createWidget(const QString &name, QWidget *parent, KActionCollection *);
+
+ void fillMenu(KMenu *, QDomNode, KActionCollection *);
+};
+
+#endif
diff --git a/src/webwindow/webwindow.cpp b/src/webwindow/webwindow.cpp
index aec2ebe2..8d6ca22c 100644
--- a/src/webwindow/webwindow.cpp
+++ b/src/webwindow/webwindow.cpp
@@ -27,6 +27,8 @@
#include "webwindow.h"
#include "webwindow.moc"
+#include "application.h"
+
#include "bookmarkmanager.h"
#include "iconmanager.h"
@@ -34,12 +36,18 @@
#include "webtab.h"
#include "bookmarkstoolbar.h"
+#include "rekonqfactory.h"
#include "rekonqmenu.h"
#include "urlbar.h"
#include "websnap.h"
+// KDE Includes
+#include <KIO/Job>
+#include <KFileDialog>
+#include <KJobUiDelegate>
#include <KUrl>
+#include <KToggleFullScreenAction>
#include <KToolBar>
#include <QLabel>
@@ -56,7 +64,7 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg)
: QWidget(parent)
, _tab(new WebTab(this))
, _bar(new UrlBar(_tab))
- , _mainToolBar(new KToolBar(this, false, false))
+ , _mainToolBar(0)
, _bookmarksBar(0)
, m_loadStopReloadAction(0)
, m_rekonqMenu(0)
@@ -77,12 +85,8 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg)
setupTools();
// main toolbar
- _mainToolBar->addAction(actionByName(QL1S("go_back")));
- _mainToolBar->addAction(actionByName(QL1S("go_forward")));
- _mainToolBar->addAction(actionByName(QL1S("url_bar")));
- _mainToolBar->addAction(actionByName(QL1S("load_stop_reload")));
- _mainToolBar->addAction(actionByName(QL1S("rekonq_tools")));
-
+ _mainToolBar = qobject_cast<KToolBar *>(RekonqFactory::createWidget(QL1S("mainToolBar"), this, actionCollection()));
+
// bookmarks toolbar
if (_bookmarksBar)
{
@@ -120,6 +124,8 @@ WebWindow::WebWindow(QWidget *parent, WebPage *pg)
m_popup->hide();
connect(m_hidePopupTimer, SIGNAL(timeout()), m_popup, SLOT(hide()));
connect(_tab->page(), SIGNAL(linkHovered(QString,QString,QString)), this, SLOT(notifyMessage(QString)));
+
+ updateHistoryActions();
}
@@ -160,7 +166,108 @@ void WebWindow::setupActions()
m_loadStopReloadAction->setToolTip(i18n("Go"));
m_loadStopReloadAction->setText(i18n("Go"));
- updateHistoryActions();
+ // new window action
+ a = new KAction(KIcon("window-new"), i18n("&New Window"), this);
+ a->setShortcut(KShortcut(Qt::CTRL | Qt::Key_N));
+ actionCollection()->addAction(QL1S("new_window"), a);
+ connect(a, SIGNAL(triggered(bool)), rApp, SLOT(newTabWindow()));
+
+ // Standard Actions
+ KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
+ KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
+ KStandardAction::print(this, SLOT(printRequested()), actionCollection());
+ KStandardAction::quit(rApp, SLOT(queryQuit()), actionCollection());
+
+ a = KStandardAction::fullScreen(this, SLOT(viewFullScreen(bool)), this, actionCollection());
+ KShortcut fullScreenShortcut = KStandardShortcut::fullScreen();
+ fullScreenShortcut.setAlternate(Qt::Key_F11);
+ a->setShortcut(fullScreenShortcut);
+
+ a = KStandardAction::redisplay(_tab->view(), SLOT(reload()), actionCollection());
+ a->setText(i18n("Reload"));
+ KShortcut reloadShortcut = KStandardShortcut::reload();
+ reloadShortcut.setAlternate(Qt::CTRL + Qt::Key_R);
+ a->setShortcut(reloadShortcut);
+
+ a = new KAction(KIcon("process-stop"), i18n("&Stop"), this);
+ a->setShortcut(KShortcut(Qt::CTRL | Qt::Key_Period));
+ actionCollection()->addAction(QL1S("stop"), a);
+ connect(a, SIGNAL(triggered(bool)), _tab->view(), SLOT(stop()));
+
+ // Open location action
+ a = new KAction(i18n("Open Location"), this);
+ KShortcut openLocationShortcut(Qt::CTRL + Qt::Key_L);
+ openLocationShortcut.setAlternate(Qt::ALT + Qt::Key_D);
+ a->setShortcut(openLocationShortcut);
+ actionCollection()->addAction(QL1S("open_location"), a);
+ connect(a, SIGNAL(triggered(bool)) , this, SLOT(openLocation()));
+
+ // ===== Tools Actions =================================
+ a = new KAction(i18n("View Page S&ource"), this);
+ a->setIcon(KIcon("application-xhtml+xml"));
+ a->setShortcut(KShortcut(Qt::CTRL + Qt::Key_U));
+ actionCollection()->addAction(QL1S("page_source"), a);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(viewPageSource()));
+
+ a = new KAction(KIcon("view-media-artist"), i18n("Private &Browsing"), this);
+ a->setCheckable(true);
+// FIXME connect(a, SIGNAL(triggered(bool)), this, SLOT(setPrivateBrowsingMode(bool)));
+ a->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_P);
+ actionCollection()->addAction(QL1S("private_browsing"), a);
+
+ a = new KAction(KIcon("edit-clear"), i18n("Clear Private Data..."), this);
+ a->setShortcut(Qt::ControlModifier + Qt::ShiftModifier + Qt::Key_Delete);
+ actionCollection()->addAction(QL1S("clear_private_data"), a);
+ connect(a, SIGNAL(triggered(bool)), this, SLOT(clearPrivateData()));
+
+// <Menu name="rekonqMenu" noMerge="1">
+// <Action name="new_tab" />
+// <Action name="new_window" /> +
+// <Action name="private_browsing" /> +
+// <Separator/>
+// <Action name="file_open" /> +
+// <Action name="file_save_as" /> +
+// <Action name="file_print" /> +
+// <Action name="edit_find" />
+// <Action name="view_zoom" />
+// <Separator/>
+//
+// <Menu name="toolsMenu" icon="preferences-other" noMerge="1">
+// <text>&amp;Tools</text>
+// <Action name="clear_private_data" /> +
+// <Separator/>
+// <Action name="webapp_shortcut" />
+// <Action name="web_inspector" />
+// <Action name="page_source" /> +
+// <Action name="net_analyzer" />
+// <Action name="set_editable" /> +
+// <Separator/>
+// <Action name="useragent" />
+// <Action name="sync" />
+// <Action name="adblock" />
+// </Menu>
+//
+// <Separator/>
+// <Action name="show_bookmarks_toolbar" />
+// <Action name="fullscreen" /> +
+// <Separator/>
+//
+// <Menu name="help" icon="help-browser">
+// <text>&amp;Help</text>
+// <Action name="help_contents"/>
+// <Action name="help_whats_this"/>
+// <Separator weakSeparator="1"/>
+// <Action name="help_report_bug"/>
+// <Separator weakSeparator="1"/>
+// <Action name="switch_application_language"/>
+// <Separator weakSeparator="1"/>
+// <Action name="help_about_app"/>
+// <Action name="help_about_kde"/>
+// </Menu>
+//
+// <Action name="options_configure" />
+// </Menu>
+
}
@@ -170,7 +277,7 @@ void WebWindow::setupTools()
toolsAction->setDelayed(false);
toolsAction->setShortcutConfigurable(true);
toolsAction->setShortcut(KShortcut(Qt::ALT + Qt::Key_T));
- m_rekonqMenu = new RekonqMenu(this);
+ m_rekonqMenu = qobject_cast<RekonqMenu *>(RekonqFactory::createWidget(QL1S("rekonqMenu"), this, actionCollection()));
toolsAction->setMenu(m_rekonqMenu); // dummy menu to have the dropdown arrow
// adding rekonq_tools to rekonq actionCollection
@@ -506,3 +613,83 @@ bool WebWindow::isLoading()
{
return _progress != 0 && _progress != 100;
}
+
+
+void WebWindow::fileOpen()
+{
+ QString filePath = KFileDialog::getOpenFileName(KUrl(),
+ i18n("*.html *.htm *.svg *.png *.gif *.svgz|Web Resources (*.html *.htm *.svg *.png *.gif *.svgz)\n"
+ "*.*|All files (*.*)"),
+ this,
+ i18n("Open Web Resource"));
+
+ if (filePath.isEmpty())
+ return;
+
+ load(KUrl(filePath));
+}
+
+
+void WebWindow::fileSaveAs()
+{
+ KUrl srcUrl = url();
+
+ if (page()->isOnRekonqPage())
+ {
+ KParts::ReadOnlyPart *p = _tab->part();
+ if (p)
+ {
+ // if this is a KParts document then the w->url() will be empty and the srcUrl
+ // must be set to the document url
+ srcUrl = p->url();
+ }
+ }
+
+ // First, try with suggested file name...
+ QString name = page()->suggestedFileName();
+
+ // Second, with KUrl fileName...
+ if (name.isEmpty())
+ {
+ name = srcUrl.fileName();
+ }
+
+ // Last chance...
+ if (name.isEmpty())
+ {
+ name = srcUrl.host() + QString(".html");
+ }
+
+ const KUrl destUrl = KFileDialog::getSaveUrl(name, QString(), this);
+ if (destUrl.isEmpty())
+ return;
+
+ if (page()->isContentEditable())
+ {
+ QString code = page()->mainFrame()->toHtml();
+ QFile file(destUrl.url());
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
+ return;
+
+ QTextStream out(&file);
+ out << code;
+
+ return;
+ }
+
+ KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite);
+ job->addMetaData("MaxCacheSize", "0"); // Don't store in http cache.
+ job->addMetaData("cache", "cache"); // Use entry from cache if available.
+ job->uiDelegate()->setAutoErrorHandlingEnabled(true);
+}
+
+
+void WebWindow::openLocation()
+{
+ if (isFullScreen())
+ {
+ _mainToolBar->show();
+ }
+ _bar->selectAll();
+ _bar->setFocus();
+}
diff --git a/src/webwindow/webwindow.h b/src/webwindow/webwindow.h
index a300f6f4..b618ab42 100644
--- a/src/webwindow/webwindow.h
+++ b/src/webwindow/webwindow.h
@@ -82,7 +82,6 @@ public:
QAction *actionByName(const QString &name);
private:
- void init();
void setupActions();
void setupTools();
@@ -104,6 +103,11 @@ private Q_SLOTS:
*/
void notifyMessage(const QString &msg);
+ // File Menu slots
+ void openLocation();
+ void fileOpen();
+ void fileSaveAs();
+
Q_SIGNALS:
void titleChanged(QString);