diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 04a438d5a..64b08e07c 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -416,6 +416,21 @@ bool MainApplication::isStateChanged() return false; } +QList MainApplication::mainWindows() +{ + QList list; + + for (int i = 0; i < m_mainWindows.count(); i++) { + if (!m_mainWindows.at(i)) { + continue; + } + + list.append(m_mainWindows.at(i).data()); + } + + return list; +} + void MainApplication::togglePrivateBrowsingMode(bool state) { webSettings()->setAttribute(QWebSettings::PrivateBrowsingEnabled, state); @@ -543,9 +558,9 @@ void MainApplication::translateApp() return; } - QTranslator* app = new QTranslator(); + QTranslator* app = new QTranslator(this); app->load(TRANSLATIONSDIR + file); - QTranslator* sys = new QTranslator(); + QTranslator* sys = new QTranslator(this); if (QFile::exists(TRANSLATIONSDIR + "qt_" + longLoc + ".qm")) { sys->load(TRANSLATIONSDIR + "qt_" + longLoc + ".qm"); diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index f9f3b73cf..6354f62f6 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -67,6 +67,8 @@ public: void aboutToCloseWindow(QupZilla* window); bool isStateChanged(); + QList mainWindows(); + inline static MainApplication* getInstance() { return static_cast(QCoreApplication::instance()); } inline QString getActiveProfilPath() { return m_activeProfil; } inline QString getActiveLanguage() { return m_activeLanguage; } diff --git a/src/lib/app/qupzilla.cpp b/src/lib/app/qupzilla.cpp index afac17540..eabbbb074 100644 --- a/src/lib/app/qupzilla.cpp +++ b/src/lib/app/qupzilla.cpp @@ -100,6 +100,7 @@ QupZilla::QupZilla(Qz::BrowserWindow type, QUrl startUrl) , m_macMenuBar(new QMenuBar()) #endif , m_actionPrivateBrowsing(0) + , m_sideBarManager(new SideBarManager(this)) , m_statusBarMessage(new StatusBarMessage(this)) , m_usingTransparentBackground(false) { @@ -372,15 +373,6 @@ void QupZilla::setupMenu() actionEncoding->setMenu(m_menuEncoding); connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu())); - m_actionShowBookmarksSideBar = new QAction(tr("Bookmarks"), this); - m_actionShowBookmarksSideBar->setCheckable(true); - m_actionShowBookmarksSideBar->setShortcut(QKeySequence("Ctrl+B")); - connect(m_actionShowBookmarksSideBar, SIGNAL(triggered()), this, SLOT(showBookmarksSideBar())); - m_actionShowHistorySideBar = new QAction(tr("History"), this); - m_actionShowHistorySideBar->setCheckable(true); - m_actionShowHistorySideBar->setShortcut(QKeySequence("Ctrl+H")); - connect(m_actionShowHistorySideBar, SIGNAL(triggered()), this, SLOT(showHistorySideBar())); - QMenu* toolbarsMenu = new QMenu(tr("Toolbars")); #ifndef Q_WS_MAC toolbarsMenu->addAction(m_actionShowMenubar); @@ -388,8 +380,7 @@ void QupZilla::setupMenu() toolbarsMenu->addAction(m_actionShowToolbar); toolbarsMenu->addAction(m_actionShowBookmarksToolbar); QMenu* sidebarsMenu = new QMenu(tr("Sidebars")); - sidebarsMenu->addAction(m_actionShowBookmarksSideBar); - sidebarsMenu->addAction(m_actionShowHistorySideBar); + m_sideBarManager->setSideBarMenu(sidebarsMenu); m_menuView->addMenu(toolbarsMenu); m_menuView->addMenu(sidebarsMenu); @@ -588,14 +579,7 @@ void QupZilla::loadSettings() m_navigationBar->buttonNext()->setVisible(showBackForwardIcons); m_navigationBar->buttonAddTab()->setVisible(showAddTab); - if (activeSideBar != "None") { - if (activeSideBar == "Bookmarks") { - m_actionShowBookmarksSideBar->trigger(); - } - else if (activeSideBar == "History") { - m_actionShowHistorySideBar->trigger(); - } - } + m_sideBarManager->showSideBar(activeSideBar); //Private browsing m_actionPrivateBrowsing->setChecked(mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)); @@ -924,16 +908,6 @@ void QupZilla::aboutToShowViewMenu() #endif m_actionShowStatusbar->setChecked(statusBar()->isVisible()); m_actionShowBookmarksToolbar->setChecked(m_bookmarksToolbar->isVisible()); - - if (!m_sideBar) { - m_actionShowBookmarksSideBar->setChecked(false); - m_actionShowHistorySideBar->setChecked(false); - } - else { - SideBar::SideWidget actWidget = m_sideBar.data()->activeWidget(); - m_actionShowBookmarksSideBar->setChecked(actWidget == SideBar::Bookmarks); - m_actionShowHistorySideBar->setChecked(actWidget == SideBar::History); - } } void QupZilla::aboutToShowEditMenu() @@ -1233,42 +1207,20 @@ void QupZilla::showBookmarksToolbar() settings.setValue("Browser-View-Settings/showBookmarksToolbar", !status); } -void QupZilla::showBookmarksSideBar() -{ - addSideBar(); - - if (m_sideBar.data()->activeWidget() != SideBar::Bookmarks) { - m_sideBar.data()->showBookmarks(); - } - else { - m_sideBar.data()->close(); - } -} - -void QupZilla::showHistorySideBar() -{ - addSideBar(); - - if (m_sideBar.data()->activeWidget() != SideBar::History) { - m_sideBar.data()->showHistory(); - } - else { - m_sideBar.data()->close(); - } -} - -void QupZilla::addSideBar() +SideBar* QupZilla::addSideBar() { if (m_sideBar) { - return; + return m_sideBar.data(); } - m_sideBar = new SideBar(this); + m_sideBar = new SideBar(m_sideBarManager, this); m_mainSplitter->insertWidget(0, m_sideBar.data()); m_mainSplitter->setCollapsible(0, false); m_mainSplitter->setSizes(QList() << m_sideBarWidth << m_webViewWidth); + + return m_sideBar.data(); } void QupZilla::saveSideBarWidth() diff --git a/src/lib/app/qupzilla.h b/src/lib/app/qupzilla.h index 969cb161f..2d980d1ba 100644 --- a/src/lib/app/qupzilla.h +++ b/src/lib/app/qupzilla.h @@ -41,6 +41,7 @@ class MainApplication; class WebTab; class AdBlockIcon; class SideBar; +class SideBarManager; class ProgressBar; class StatusBarMessage; class NavigationBar; @@ -75,6 +76,7 @@ public: void restoreWindowState(const QByteArray &window, const QByteArray &tabs); + SideBar* addSideBar(); virtual QMenuBar* menuBar() const; TabbedWebView* weView() const; @@ -84,10 +86,8 @@ public: inline BookmarksToolbar* bookmarksToolbar() { return m_bookmarksToolbar; } inline StatusBarMessage* statusBarMessage() { return m_statusBarMessage; } inline NavigationBar* navigationBar() { return m_navigationBar; } - + inline SideBarManager* sideBarManager() { return m_sideBarManager; } inline ProgressBar* progressBar() { return m_progressBar; } - inline QString activeProfil() { return m_activeProfil; } - inline QString activeLanguage() { return m_activeLanguage; } inline QLabel* ipLabel() { return m_ipLabel; } inline AdBlockIcon* adBlockIcon() { return m_adblockIcon; } inline QMenu* menuHelp() { return m_menuHelp; } @@ -95,6 +95,9 @@ public: inline QAction* actionReload() { return m_actionReload; } inline QMenu* superMenu() { return m_superMenu; } + inline QString activeProfil() { return m_activeProfil; } + inline QString activeLanguage() { return m_activeLanguage; } + inline bool isClosing() { return m_isClosing; } inline QUrl homepageUrl() { return m_homepage; } @@ -147,9 +150,7 @@ private slots: void searchOnPage(); void showCookieManager(); void showHistoryManager(); - void showHistorySideBar(); void showBookmarksManager(); - void showBookmarksSideBar(); void showRSSManager(); void showDownloadManager(); void showMenubar(); @@ -197,7 +198,6 @@ private: void setupUi(); void setupMenu(); - void addSideBar(); void disconnectObjects(); @@ -255,6 +255,7 @@ private: BookmarksToolbar* m_bookmarksToolbar; TabWidget* m_tabWidget; QWeakPointer m_sideBar; + SideBarManager* m_sideBarManager; StatusBarMessage* m_statusBarMessage; NavigationBar* m_navigationBar; diff --git a/src/lib/lib.pro b/src/lib/lib.pro index 1472aa870..d84819846 100644 --- a/src/lib/lib.pro +++ b/src/lib/lib.pro @@ -308,7 +308,8 @@ HEADERS += \ bookmarksimport/bookmarksimporticonfetcher.h \ other/checkboxdialog.h \ network/schemehandler.h \ - tools/plaineditwithlines.h + tools/plaineditwithlines.h \ + sidebar/sidebarinterface.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index 395cb4283..05ddc0764 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -51,7 +51,7 @@ QString titleForUrl(QString title, const QUrl &url) QIcon iconForPage(const QUrl &url, const QIcon &sIcon) { QIcon icon; - icon.addPixmap(url.scheme() == "qupzilla" ? QIcon(":icons/qupzilla.png").pixmap(16, 16) :_iconForUrl(url).pixmap(16, 16)); + icon.addPixmap(url.scheme() == "qupzilla" ? QIcon(":icons/qupzilla.png").pixmap(16, 16) : _iconForUrl(url).pixmap(16, 16)); icon.addPixmap(sIcon.pixmap(16, 16), QIcon::Active); return icon; } @@ -204,7 +204,7 @@ void NavigationBar::aboutToShowHistoryBackMenu() if (item.isValid() && lastUrl != item.url()) { QString title = titleForUrl(item.title(), item.url()); - const QIcon &icon = iconForPage(item.url(), IconProvider::fromTheme("go-previous")); + const QIcon &icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowBack)); Action* act = new Action(icon, title); act->setData(i); connect(act, SIGNAL(triggered()), this, SLOT(goAtHistoryIndex())); @@ -241,7 +241,7 @@ void NavigationBar::aboutToShowHistoryNextMenu() if (item.isValid() && lastUrl != item.url()) { QString title = titleForUrl(item.title(), item.url()); - const QIcon &icon = iconForPage(item.url(), IconProvider::fromTheme("go-next")); + const QIcon &icon = iconForPage(item.url(), IconProvider::standardIcon(QStyle::SP_ArrowForward)); Action* act = new Action(icon, title); act->setData(i); connect(act, SIGNAL(triggered()), this, SLOT(goAtHistoryIndex())); diff --git a/src/lib/plugins/plugininterface.h b/src/lib/plugins/plugininterface.h index 0b8de5d25..09bb7e44c 100644 --- a/src/lib/plugins/plugininterface.h +++ b/src/lib/plugins/plugininterface.h @@ -20,7 +20,6 @@ #include #include -#include #include "qz_namespace.h" @@ -47,6 +46,7 @@ class QMenu; class QWebHitTestResult; class QMouseEvent; class QKeyEvent; +class QWheelEvent; class WebView; diff --git a/src/lib/sidebar/sidebar.cpp b/src/lib/sidebar/sidebar.cpp index da5326986..404f707ad 100644 --- a/src/lib/sidebar/sidebar.cpp +++ b/src/lib/sidebar/sidebar.cpp @@ -16,16 +16,22 @@ * along with this program. If not, see . * ============================================================ */ #include "sidebar.h" +#include "sidebarinterface.h" #include "docktitlebarwidget.h" #include "bookmarkssidebar.h" #include "historysidebar.h" +#include "mainapplication.h" #include "qupzilla.h" #include "settings.h" -SideBar::SideBar(QupZilla* mainClass, QWidget* parent) - : QWidget(parent) +#include + +QHash > SideBarManager::m_sidebars; + +SideBar::SideBar(SideBarManager* manager, QupZilla* mainClass) + : QWidget(mainClass) , p_QupZilla(mainClass) - , m_activeWidget(None) + , m_manager(manager) { setObjectName("sidebar"); setAttribute(Qt::WA_DeleteOnClose); @@ -39,31 +45,9 @@ SideBar::SideBar(QupZilla* mainClass, QWidget* parent) m_layout->addWidget(m_titleBar); } -void SideBar::showBookmarks() +void SideBar::setTitle(const QString &title) { - m_titleBar->setTitle(tr("Bookmarks")); - BookmarksSideBar* bar = new BookmarksSideBar(p_QupZilla); - setWidget(bar); - m_activeWidget = Bookmarks; - - Settings settings; - settings.setValue("Browser-View-Settings/SideBar", "Bookmarks"); -} - -void SideBar::showHistory() -{ - m_titleBar->setTitle(tr("History")); - HistorySideBar* bar = new HistorySideBar(p_QupZilla); - setWidget(bar); - m_activeWidget = History; - - Settings settings; - settings.setValue("Browser-View-Settings/SideBar", "History"); -} - -void SideBar::showRSS() -{ - + m_titleBar->setTitle(title); } void SideBar::setWidget(QWidget* widget) @@ -75,16 +59,168 @@ void SideBar::setWidget(QWidget* widget) m_layout->addWidget(widget); } +void SideBar::showBookmarks() +{ + m_titleBar->setTitle(tr("Bookmarks")); + BookmarksSideBar* bar = new BookmarksSideBar(p_QupZilla); + setWidget(bar); +} + +void SideBar::showHistory() +{ + m_titleBar->setTitle(tr("History")); + HistorySideBar* bar = new HistorySideBar(p_QupZilla); + setWidget(bar); +} + void SideBar::close() { - Settings settings; - settings.setValue("Browser-View-Settings/SideBar", "None"); - - p_QupZilla->saveSideBarWidth(); + m_manager->closeSideBar(); QWidget::close(); } -SideBar::~SideBar() +SideBarManager::SideBarManager(QupZilla* parent) + : QObject(parent) + , p_QupZilla(parent) + , m_menu(0) { } + +void SideBarManager::setSideBarMenu(QMenu* menu) +{ + m_menu = menu; + + refreshMenu(); +} + +void SideBarManager::addSidebar(const QString &id, SideBarInterface* interface) +{ + m_sidebars[id] = interface; + + foreach(QupZilla * window, mApp->mainWindows()) { + window->sideBarManager()->refreshMenu(); + } +} + +void SideBarManager::removeSidebar(const QString &id) +{ + m_sidebars.remove(id); + + foreach(QupZilla * window, mApp->mainWindows()) { + window->sideBarManager()->sideBarRemoved(id); + } +} + +void SideBarManager::refreshMenu() +{ + if (!m_menu) { + return; + } + + m_menu->clear(); + QAction* act = m_menu->addAction(SideBar::tr("Bookmarks"), this, SLOT(slotShowSideBar())); + act->setCheckable(true); + act->setShortcut(QKeySequence("Ctrl+B")); + act->setData("Bookmarks"); + + act = m_menu->addAction(SideBar::tr("History"), this, SLOT(slotShowSideBar())); + act->setCheckable(true); + act->setShortcut(QKeySequence("Ctrl+H")); + act->setData("History"); + + foreach(const QWeakPointer &sidebar, m_sidebars) { + if (!sidebar) { + continue; + } + + QAction* act = sidebar.data()->menuAction(); + act->setData(m_sidebars.key(sidebar)); + connect(act, SIGNAL(triggered()), this, SLOT(slotShowSideBar())); + + m_menu->addAction(act); + } + + updateActions(); +} + +void SideBarManager::slotShowSideBar() +{ + if (QAction* act = qobject_cast(sender())) { + showSideBar(act->data().toString()); + } +} + +void SideBarManager::updateActions() +{ + if (!m_menu) { + return; + } + + foreach(QAction * act, m_menu->actions()) { + act->setChecked(act->data().toString() == m_activeBar); + } +} + +void SideBarManager::showSideBar(const QString &id) +{ + if (id == "None") { + return; + } + + if (!m_sideBar) { + m_sideBar = p_QupZilla->addSideBar(); + } + + if (id == m_activeBar) { + m_sideBar.data()->close(); + + m_activeBar = "None"; + return; + } + + if (id == "Bookmarks") { + m_sideBar.data()->showBookmarks(); + } + else if (id == "History") { + m_sideBar.data()->showHistory(); + } + else { + SideBarInterface* sidebar = m_sidebars[id].data(); + if (!sidebar) { + m_sideBar.data()->close(); + return; + } + + m_sideBar.data()->setTitle(sidebar->title()); + m_sideBar.data()->setWidget(sidebar->createSideBarWidget(p_QupZilla)); + } + + m_activeBar = id; + + Settings settings; + settings.setValue("Browser-View-Settings/SideBar", id); + + updateActions(); +} + +void SideBarManager::sideBarRemoved(const QString &id) +{ + if (m_activeBar == id && m_sideBar) { + m_sideBar.data()->close(); + } + + refreshMenu(); +} + +void SideBarManager::closeSideBar() +{ + m_activeBar = "None"; + + Settings settings; + settings.setValue("Browser-View-Settings/SideBar", m_activeBar); + + p_QupZilla->saveSideBarWidth(); + + updateActions(); +} diff --git a/src/lib/sidebar/sidebar.h b/src/lib/sidebar/sidebar.h index a9ba8374f..a2dbeaaa9 100644 --- a/src/lib/sidebar/sidebar.h +++ b/src/lib/sidebar/sidebar.h @@ -19,40 +19,69 @@ #define SIDEBAR_H #include +#include +#include #include "qz_namespace.h" class QVBoxLayout; +class QMenu; class DockTitleBarWidget; +class SideBarInterface; +class SideBarManager; class QupZilla; class QT_QUPZILLA_EXPORT SideBar : public QWidget { Q_OBJECT public: - enum SideWidget { None = 0, Bookmarks, History, RSS }; - - explicit SideBar(QupZilla* mainClass, QWidget* parent = 0); - ~SideBar(); + explicit SideBar(SideBarManager* manager, QupZilla* mainClass); void showBookmarks(); void showHistory(); - void showRSS(); - SideWidget activeWidget() { return m_activeWidget; } -signals: + void setTitle(const QString &title); + void setWidget(QWidget* widget); public slots: void close(); private: - void setWidget(QWidget* widget); - QupZilla* p_QupZilla; QVBoxLayout* m_layout; DockTitleBarWidget* m_titleBar; - SideWidget m_activeWidget; + SideBarManager* m_manager; +}; + +class QT_QUPZILLA_EXPORT SideBarManager : public QObject +{ + Q_OBJECT +public: + explicit SideBarManager(QupZilla* parent); + + void setSideBarMenu(QMenu* menu); + void refreshMenu(); + + void showSideBar(const QString &id); + void sideBarRemoved(const QString &id); + void closeSideBar(); + + static QHash > m_sidebars; + static void addSidebar(const QString &id, SideBarInterface* interface); + static void removeSidebar(const QString &id); + +private slots: + void slotShowSideBar(); + +private: + void updateActions(); + + QupZilla* p_QupZilla; + QWeakPointer m_sideBar; + QMenu* m_menu; + + QString m_activeBar; }; #endif // SIDEBAR_H diff --git a/src/lib/sidebar/sidebarinterface.h b/src/lib/sidebar/sidebarinterface.h new file mode 100644 index 000000000..a77532e2a --- /dev/null +++ b/src/lib/sidebar/sidebarinterface.h @@ -0,0 +1,40 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* 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 3 of the License, or +* (at your option) any later version. +* +* 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 SIDEBARINTERFACE_H +#define SIDEBARINTERFACE_H + +#include + +#include "qz_namespace.h" + +class QAction; + +class QupZilla; + +class QT_QUPZILLA_EXPORT SideBarInterface : public QObject +{ +public: + explicit SideBarInterface(QObject* parent = 0) : QObject(parent) { } + + virtual QString title() const = 0; + virtual QAction* menuAction() = 0; + + virtual QWidget* createSideBarWidget(QupZilla* mainWindow) = 0; +}; + +#endif // SIDEBARINTERFACE_H diff --git a/src/lib/tools/docktitlebarwidget.cpp b/src/lib/tools/docktitlebarwidget.cpp index cd0f4931d..88c40bf3a 100644 --- a/src/lib/tools/docktitlebarwidget.cpp +++ b/src/lib/tools/docktitlebarwidget.cpp @@ -25,6 +25,8 @@ DockTitleBarWidget::DockTitleBarWidget(const QString &title, QWidget* parent) closeButton->setIcon(QIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton).pixmap(16, 16))); label->setText(title); connect(closeButton, SIGNAL(clicked()), parent, SLOT(close())); + + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); } void DockTitleBarWidget::setTitle(const QString &title) diff --git a/src/plugins/AccessKeysNavigation/akn_plugin.cpp b/src/plugins/AccessKeysNavigation/akn_plugin.cpp index 81604e2bb..98128f87b 100644 --- a/src/plugins/AccessKeysNavigation/akn_plugin.cpp +++ b/src/plugins/AccessKeysNavigation/akn_plugin.cpp @@ -65,7 +65,7 @@ bool AKN_Plugin::testPlugin() QTranslator* AKN_Plugin::getTranslator(const QString &locale) { - QTranslator* translator = new QTranslator(); + QTranslator* translator = new QTranslator(this); translator->load(":/accesskeysnavigation/locale/" + locale); return translator; } diff --git a/src/plugins/MouseGestures/mousegesturesplugin.cpp b/src/plugins/MouseGestures/mousegesturesplugin.cpp index ab6072c86..5aeabc86b 100644 --- a/src/plugins/MouseGestures/mousegesturesplugin.cpp +++ b/src/plugins/MouseGestures/mousegesturesplugin.cpp @@ -68,7 +68,7 @@ bool MouseGesturesPlugin::testPlugin() QTranslator* MouseGesturesPlugin::getTranslator(const QString &locale) { - QTranslator* translator = new QTranslator(); + QTranslator* translator = new QTranslator(this); translator->load(":/mousegestures/locale/" + locale); return translator; } diff --git a/src/plugins/TestPlugin/TestPlugin.pro b/src/plugins/TestPlugin/TestPlugin.pro index e5aefec6b..f332787ef 100644 --- a/src/plugins/TestPlugin/TestPlugin.pro +++ b/src/plugins/TestPlugin/TestPlugin.pro @@ -8,8 +8,10 @@ TARGET = TestPlugin # OS/2 allows only 8 chars in TARGET os2: TARGET = TestPlug -SOURCES += testplugin.cpp -HEADERS += testplugin.h +SOURCES += testplugin.cpp \ + testplugin_sidebar.cpp +HEADERS += testplugin.h \ + testplugin_sidebar.h RESOURCES += testplugin.qrc TRANSLATIONS += translations/cs_CZ.ts\ diff --git a/src/plugins/TestPlugin/testplugin.cpp b/src/plugins/TestPlugin/testplugin.cpp index e260bfa77..ac83d27d5 100644 --- a/src/plugins/TestPlugin/testplugin.cpp +++ b/src/plugins/TestPlugin/testplugin.cpp @@ -16,10 +16,12 @@ * along with this program. If not, see . * ============================================================ */ #include "testplugin.h" +#include "testplugin_sidebar.h" #include "qupzilla.h" #include "webview.h" #include "pluginproxy.h" #include "mainapplication.h" +#include "sidebar.h" #include #include @@ -41,7 +43,7 @@ PluginSpec TestPlugin::pluginSpec() spec.name = "Example Plugin"; spec.info = "Example minimal plugin"; spec.description = "Very simple minimal plugin example"; - spec.version = "0.0.1"; + spec.version = "0.1.5"; spec.author = "David Rosca "; spec.icon = QPixmap(":qupzilla.png"); spec.hasSettings = true; @@ -59,7 +61,12 @@ void TestPlugin::init(const QString &sPath) m_settingsPath = sPath; + // Registering this plugin as a MousePressHandler. + // Otherwise mousePress() function will never be called QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler); + + // Adding new sidebar into application + SideBarManager::addSidebar("testplugin-sidebar", new TestPlugin_Sidebar(this)); } void TestPlugin::unload() @@ -68,6 +75,9 @@ void TestPlugin::unload() // This function will be called when unloading plugin // it will be also called if we return false from testPlugin() + + // Removing sidebar from application + SideBarManager::removeSidebar("testplugin-sidebar"); } bool TestPlugin::testPlugin() @@ -81,13 +91,19 @@ bool TestPlugin::testPlugin() QTranslator* TestPlugin::getTranslator(const QString &locale) { - QTranslator* translator = new QTranslator(); + // Loads translation according to locale file + // QString locale will contains "fr_FR.qm" for French locale + + QTranslator* translator = new QTranslator(this); translator->load(":/testplugin/locale/" + locale); return translator; } void TestPlugin::showSettings(QWidget* parent) { + // This function will be called from Preferences after clicking on Settings button. + // Settings button will be enabled if PluginSpec.hasSettings == true + QDialog* dialog = new QDialog(parent); QPushButton* b = new QPushButton("Example Plugin v0.0.1"); QPushButton* closeButton = new QPushButton(tr("Close")); @@ -110,6 +126,8 @@ void TestPlugin::showSettings(QWidget* parent) void TestPlugin::populateWebViewMenu(QMenu* menu, WebView* view, const QWebHitTestResult &r) { + // Called from WebView when creating context menu + m_view = view; QString title; @@ -132,6 +150,9 @@ bool TestPlugin::mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEven { qDebug() << "mousePress" << type << obj << event; + // Returning false means, that we don't want to block propagating this event + // Returning true may affect behaviour of QupZilla, so make sure you know what + // you are doing! return false; } @@ -140,5 +161,7 @@ void TestPlugin::actionSlot() QMessageBox::information(m_view, tr("Hello"), tr("First plugin action works :-)")); } -//Export plugin macro +// Export plugin macro +// This macro has to be only in class derived from PluginInterface +// Don't call it in other files! Q_EXPORT_PLUGIN2(ExamplePlugin, TestPlugin) diff --git a/src/plugins/TestPlugin/testplugin_sidebar.cpp b/src/plugins/TestPlugin/testplugin_sidebar.cpp new file mode 100644 index 000000000..b19d9eb10 --- /dev/null +++ b/src/plugins/TestPlugin/testplugin_sidebar.cpp @@ -0,0 +1,58 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* 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 3 of the License, or +* (at your option) any later version. +* +* 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 . +* ============================================================ */ +#include "testplugin_sidebar.h" + +#include +#include +#include +#include + +TestPlugin_Sidebar::TestPlugin_Sidebar(QObject* parent) + : SideBarInterface(parent) +{ +} + +QString TestPlugin_Sidebar::title() const +{ + return tr("Testing Sidebar"); +} + +QAction* TestPlugin_Sidebar::menuAction() +{ + QAction* act = new QAction(tr("Testing Sidebar"), 0); + act->setCheckable(true); + + return act; +} + +QWidget* TestPlugin_Sidebar::createSideBarWidget(QupZilla* mainWindow) +{ + Q_UNUSED(mainWindow) + + QWidget* w = new QWidget; + QPushButton* b = new QPushButton("Example Plugin v0.0.1"); + QLabel* label = new QLabel(); + label->setPixmap(QPixmap(":icons/other/about.png")); + + QVBoxLayout* l = new QVBoxLayout(w); + l->addWidget(label); + l->addWidget(b); + w->setLayout(l); + + return w; +} diff --git a/src/plugins/TestPlugin/testplugin_sidebar.h b/src/plugins/TestPlugin/testplugin_sidebar.h new file mode 100644 index 000000000..69faed971 --- /dev/null +++ b/src/plugins/TestPlugin/testplugin_sidebar.h @@ -0,0 +1,35 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2012 David Rosca +* +* 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 3 of the License, or +* (at your option) any later version. +* +* 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 TESTPLUGIN_SIDEBAR_H +#define TESTPLUGIN_SIDEBAR_H + +#include "sidebarinterface.h" + +class TestPlugin_Sidebar : public SideBarInterface +{ + Q_OBJECT +public: + explicit TestPlugin_Sidebar(QObject* parent = 0); + + QString title() const; + QAction* menuAction(); + + QWidget* createSideBarWidget(QupZilla* mainWindow); +}; + +#endif // TESTPLUGIN_SIDEBAR_H