File indexing completed on 2025-01-19 03:55:42

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2018-12-31
0007  * Description : digiKam plugin main dialog
0008  *
0009  * SPDX-FileCopyrightText: 2018-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "dplugindialog.h"
0016 
0017 // Qt includes
0018 
0019 #include <QApplication>
0020 #include <QPushButton>
0021 #include <QPointer>
0022 #include <QMenu>
0023 #include <QIcon>
0024 #include <QAction>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 #include <ksharedconfig.h>
0030 #include <kconfiggroup.h>
0031 
0032 // Local includes
0033 
0034 #include "digikam_globals.h"
0035 #include "dpluginaboutdlg.h"
0036 #include "dxmlguiwindow.h"
0037 #include "dplugin.h"
0038 
0039 namespace Digikam
0040 {
0041 
0042 DPluginDialog::DPluginDialog(QWidget* const parent, const QString& objName)
0043     : QDialog  (parent),
0044       m_buttons(nullptr),
0045       m_tool   (nullptr)
0046 {
0047     setObjectName(objName);
0048     setWindowFlags((windowFlags() & ~Qt::Dialog) |
0049                    Qt::Window                    |
0050                    Qt::WindowCloseButtonHint     |
0051                    Qt::WindowMinMaxButtonsHint);
0052 
0053     m_buttons = new QDialogButtonBox(this);
0054     restoreDialogSize();
0055 }
0056 
0057 DPluginDialog::~DPluginDialog()
0058 {
0059     saveDialogSize();
0060 }
0061 
0062 void DPluginDialog::setPlugin(DPlugin* const tool)
0063 {
0064     m_tool = tool;
0065 
0066     if (m_tool)
0067     {
0068         QPushButton* const help       = m_buttons->addButton(QDialogButtonBox::Help);
0069         help->setIcon(QIcon::fromTheme(QLatin1String("help-browser")));
0070         help->setText(i18nc("@action: button", "Help"));
0071         help->setAutoDefault(false);
0072         QMenu* const menu             = new QMenu(help);
0073         QAction* const handbookAction = menu->addAction(QIcon::fromTheme(QLatin1String("globe")), i18n("Online Handbook..."));
0074         QAction* const aboutAction    = menu->addAction(QIcon::fromTheme(QLatin1String("help-about")), i18n("About..."));
0075         help->setMenu(menu);
0076 
0077         connect(handbookAction, SIGNAL(triggered()),
0078                 this, SLOT(slotOnlineHandbook()));
0079 
0080         connect(aboutAction, SIGNAL(triggered()),
0081                 this, SLOT(slotAboutPlugin()));
0082     }
0083 }
0084 
0085 void DPluginDialog::slotAboutPlugin()
0086 {
0087     QPointer<DPluginAboutDlg> dlg = new DPluginAboutDlg(m_tool);
0088     dlg->exec();
0089     delete dlg;
0090 }
0091 
0092 void DPluginDialog::slotOnlineHandbook()
0093 {
0094     openOnlineDocumentation(m_tool->handbookSection(), m_tool->handbookChapter(), m_tool->handbookReference());
0095 }
0096 
0097 void DPluginDialog::restoreDialogSize()
0098 {
0099     KSharedConfigPtr config = KSharedConfig::openConfig();
0100     KConfigGroup group      = config->group(objectName());
0101 
0102     winId();
0103     DXmlGuiWindow::setGoodDefaultWindowSize(windowHandle());
0104     DXmlGuiWindow::restoreWindowSize(windowHandle(), group);
0105     resize(windowHandle()->size());
0106 }
0107 
0108 void DPluginDialog::saveDialogSize()
0109 {
0110     KSharedConfigPtr config = KSharedConfig::openConfig();
0111     KConfigGroup group      = config->group(objectName());
0112     DXmlGuiWindow::saveWindowSize(windowHandle(), group);
0113 }
0114 
0115 } // namespace Digikam
0116 
0117 #include "moc_dplugindialog.cpp"