File indexing completed on 2025-01-05 03:59:54

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2012-07-20
0007  * Description : scripting settings for camera interface.
0008  *
0009  * SPDX-FileCopyrightText: 2012 by Petri Damstén <damu@iki.fi>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "scriptingsettings.h"
0016 
0017 // Qt includes
0018 
0019 #include <QVBoxLayout>
0020 #include <QLabel>
0021 #include <QToolButton>
0022 #include <QApplication>
0023 #include <QStyle>
0024 #include <QIcon>
0025 
0026 // KDE includes
0027 
0028 #include <kconfiggroup.h>
0029 #include <klocalizedstring.h>
0030 
0031 // Local includes
0032 
0033 #include "dlayoutbox.h"
0034 #include "dfileselector.h"
0035 #include "digikam_debug.h"
0036 #include "tooltipdialog.h"
0037 
0038 namespace Digikam
0039 {
0040 
0041 class Q_DECL_HIDDEN ScriptingSettings::Private
0042 {
0043 public:
0044 
0045     explicit Private()
0046         : scriptLabel        (nullptr),
0047           script             (nullptr),
0048           tooltipDialog      (nullptr),
0049           tooltipToggleButton(nullptr)
0050     {
0051     }
0052 
0053     QLabel*        scriptLabel;
0054     DFileSelector* script;
0055     TooltipDialog* tooltipDialog;
0056     QToolButton*   tooltipToggleButton;
0057 };
0058 
0059 ScriptingSettings::ScriptingSettings(QWidget* const parent)
0060     : QWidget(parent),
0061       d      (new Private)
0062 {
0063     const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0064                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0065 
0066     d->tooltipDialog  = new TooltipDialog(this);
0067     d->tooltipDialog->setTooltip(i18n("<p>These expressions may be used to customize the command line:</p>"
0068                                       "<p><b>%file</b>: full path of the imported file</p>"
0069                                       "<p><b>%filename</b>: file name of the imported file</p>"
0070                                       "<p><b>%path</b>: path of the imported file</p>"
0071                                       "<p><b>%orgfilename</b>: original file name</p>"
0072                                       "<p><b>%orgpath</b>: original path</p>"
0073                                       "<p>If there are no expressions full path is added to the command.</p>"
0074                                      ));
0075     d->tooltipDialog->resize(650, 530);
0076 
0077     QVBoxLayout* const vlay = new QVBoxLayout(this);
0078     d->scriptLabel          = new QLabel(i18n("Execute script for image:"), this);
0079     DHBox* const hbox       = new DHBox(this);
0080     d->script               = new DFileSelector(hbox);
0081     d->script->setFileDlgMode(QFileDialog::ExistingFile);
0082     d->script->lineEdit()->setPlaceholderText(i18n("No script selected"));
0083     d->tooltipToggleButton  = new QToolButton(hbox);
0084     d->tooltipToggleButton->setIcon(QIcon::fromTheme(QLatin1String("dialog-information")));
0085     d->tooltipToggleButton->setToolTip(i18n("Show a list of all available options"));
0086 
0087     vlay->addWidget(d->scriptLabel);
0088     vlay->addWidget(hbox);
0089     vlay->addStretch();
0090     vlay->setContentsMargins(spacing, spacing, spacing, spacing);
0091     vlay->setSpacing(spacing);
0092 
0093     setWhatsThis(i18n("Set here the script that is executed for every imported image."));
0094 
0095     // ---------------------------------------------------------------------------------------
0096 
0097     connect(d->tooltipToggleButton, SIGNAL(clicked(bool)),
0098             this, SLOT(slotToolTipButtonToggled(bool)));
0099 }
0100 
0101 ScriptingSettings::~ScriptingSettings()
0102 {
0103     delete d;
0104 }
0105 
0106 void ScriptingSettings::readSettings(KConfigGroup& group)
0107 {
0108     d->script->setFileDlgPath(group.readEntry("Script", QString()));
0109 }
0110 
0111 void ScriptingSettings::saveSettings(KConfigGroup& group)
0112 {
0113     group.writeEntry("Script", d->script->fileDlgPath());
0114 }
0115 
0116 void ScriptingSettings::settings(DownloadSettings* const settings) const
0117 {
0118     settings->script = d->script->fileDlgPath();
0119 }
0120 
0121 void ScriptingSettings::slotToolTipButtonToggled(bool /*checked*/)
0122 {
0123     if (!d->tooltipDialog->isVisible())
0124     {
0125         d->tooltipDialog->show();
0126     }
0127 
0128     d->tooltipDialog->raise();
0129 }
0130 
0131 } // namespace Digikam
0132 
0133 #include "moc_scriptingsettings.cpp"