File indexing completed on 2024-05-19 04:59:19

0001 /* ============================================================
0002 * StatusBarIcons - Extra icons in statusbar for Falkon
0003 * Copyright (C) 2013-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "statusbariconsplugin.h"
0019 #include "sbi_iconsmanager.h"
0020 #include "sbi_settingsdialog.h"
0021 #include "pluginproxy.h"
0022 #include "browserwindow.h"
0023 #include "../config.h"
0024 #include "mainapplication.h"
0025 
0026 StatusBarIconsPlugin::StatusBarIconsPlugin()
0027     : QObject()
0028     , m_manager(nullptr)
0029 {
0030 }
0031 
0032 void StatusBarIconsPlugin::init(InitState state, const QString &settingsPath)
0033 {
0034     m_manager = new SBI_IconsManager(settingsPath);
0035 
0036     connect(mApp->plugins(), &PluginProxy::mainWindowCreated, m_manager, &SBI_IconsManager::mainWindowCreated);
0037     connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, m_manager, &SBI_IconsManager::mainWindowDeleted);
0038 
0039     // Make sure icons are added also to already created windows
0040     if (state == LateInitState) {
0041         const auto windows = mApp->windows();
0042         for (BrowserWindow* window : windows) {
0043             m_manager->mainWindowCreated(window);
0044         }
0045     }
0046 }
0047 
0048 void StatusBarIconsPlugin::unload()
0049 {
0050     // Make sure icons are properly removed when unloading plugin (but not when closing app)
0051     if (!mApp->isClosing()) {
0052         const auto windows = mApp->windows();
0053         for (BrowserWindow* window : windows) {
0054             m_manager->mainWindowDeleted(window);
0055         }
0056 
0057         delete m_manager;
0058     }
0059 }
0060 
0061 bool StatusBarIconsPlugin::testPlugin()
0062 {
0063     // Require the version that the plugin was built with
0064     return (QString::fromLatin1(Qz::VERSION) == QLatin1String(FALKON_VERSION));
0065 }
0066 
0067 void StatusBarIconsPlugin::showSettings(QWidget* parent)
0068 {
0069     auto* dialog = new SBI_SettingsDialog(m_manager, parent);
0070     dialog->open();
0071 }