File indexing completed on 2025-01-05 03:52:07

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-04-04
0007  * Description : a tool to generate jAlbum image galleries
0008  *
0009  * SPDX-FileCopyrightText: 2013-2019 by Andrew Goodbody <ajg zero two at elfringham dot co dot uk>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "jalbumintropage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QLabel>
0020 #include <QPixmap>
0021 #include <QComboBox>
0022 #include <QGroupBox>
0023 #include <QIcon>
0024 
0025 // KDE includes
0026 
0027 #include <klocalizedstring.h>
0028 
0029 // Local includes
0030 
0031 #include "digikam_debug.h"
0032 #include "digikam_config.h"
0033 #include "dbinarysearch.h"
0034 #include "jalbumjar.h"
0035 #include "jalbumjava.h"
0036 #include "jalbumwizard.h"
0037 #include "jalbumsettings.h"
0038 #include "dlayoutbox.h"
0039 
0040 namespace DigikamGenericJAlbumPlugin
0041 {
0042 
0043 class Q_DECL_HIDDEN JAlbumIntroPage::Private
0044 {
0045 public:
0046 
0047     explicit Private(QWizard* const dialog)
0048       : imageGetOption(nullptr),
0049         hbox(nullptr),
0050         wizard(nullptr),
0051         settings(nullptr),
0052         iface(nullptr),
0053         binSearch(nullptr)
0054     {
0055         wizard = dynamic_cast<JAlbumWizard*>(dialog);
0056 
0057         if (wizard)
0058         {
0059             settings  = wizard->settings();
0060             iface = settings->m_iface;
0061         }
0062     }
0063 
0064     QComboBox*       imageGetOption;
0065     DHBox*           hbox;
0066     JAlbumWizard*    wizard;
0067     JAlbumSettings*  settings;
0068     DInfoInterface*  iface;
0069     DBinarySearch*   binSearch;
0070     JalbumJar        jalbumBin;
0071     JalbumJava       jalbumJava;
0072 };
0073 
0074 JAlbumIntroPage::JAlbumIntroPage(QWizard* const dialog, const QString& title)
0075     : DWizardPage(dialog, title),
0076       d(new Private(dialog))
0077 {
0078     DVBox* const vbox  = new DVBox(this);
0079     QLabel* const desc = new QLabel(vbox);
0080 
0081     desc->setWordWrap(true);
0082     desc->setOpenExternalLinks(true);
0083     desc->setText(i18n("<qt>"
0084                        "<p><h1><b>Welcome to jAlbum export tool</b></h1></p>"
0085                        "<p>This assistant will guide you to export quickly</p><p></p>"
0086                        "<p>your images as a jAlbum project.</p>"
0087                        "</qt>"));
0088 
0089     // ComboBox for image selection method
0090 
0091     d->hbox                     = new DHBox(vbox);
0092     QLabel* const getImageLabel = new QLabel(i18n("&Choose image selection method:"), d->hbox);
0093     d->imageGetOption           = new QComboBox(d->hbox);
0094     d->imageGetOption->insertItem(JAlbumSettings::ALBUMS, i18n("Albums"));
0095     d->imageGetOption->insertItem(JAlbumSettings::IMAGES, i18n("Images"));
0096     getImageLabel->setBuddy(d->imageGetOption);
0097 
0098     // --------------------
0099 
0100     QGroupBox* const binaryBox      = new QGroupBox(vbox);
0101     QGridLayout* const binaryLayout = new QGridLayout;
0102     binaryBox->setLayout(binaryLayout);
0103     binaryBox->setTitle(i18nc("@title:group", "jAlbum Binaries"));
0104     d->binSearch                    = new DBinarySearch(binaryBox);
0105     d->binSearch->addBinary(d->jalbumBin);
0106     d->binSearch->addBinary(d->jalbumJava);
0107 
0108     vbox->setStretchFactor(desc,      2);
0109     vbox->setStretchFactor(d->hbox,   1);
0110     vbox->setStretchFactor(binaryBox, 3);
0111 
0112     setPageWidget(vbox);
0113     setLeftBottomPix(QIcon::fromTheme(QLatin1String("text-html")));
0114 
0115 #ifdef Q_OS_WIN
0116 
0117     d->binSearch->addDirectory(QLatin1String(qgetenv("ProgramFiles").constData()) + QLatin1String("\\jAlbum\\"));
0118 
0119 #else
0120 
0121     d->binSearch->addDirectory(QLatin1String("/usr/share/"));
0122     d->binSearch->addDirectory(QLatin1String("/usr/share/jAlbum/"));
0123     d->binSearch->addDirectory(QLatin1String("/usr/share/jalbum/"));
0124     d->binSearch->addDirectory(QLatin1String("/usr/lib/jalbum/"));
0125 
0126 #endif
0127 
0128     connect(d->binSearch, SIGNAL(signalBinariesFound(bool)),
0129             this, SLOT(slotBinariesFound()));
0130 }
0131 
0132 JAlbumIntroPage::~JAlbumIntroPage()
0133 {
0134     delete d;
0135 }
0136 
0137 void JAlbumIntroPage::initializePage()
0138 {
0139     bool albumSupport = (d->iface && d->iface->supportAlbums());
0140 
0141     if (!albumSupport)
0142     {
0143         d->imageGetOption->setCurrentIndex(JAlbumSettings::IMAGES);
0144         d->hbox->setEnabled(false);
0145     }
0146     else
0147     {
0148         d->imageGetOption->setCurrentIndex(d->settings->m_getOption);
0149     }
0150 
0151     d->binSearch->allBinariesFound();
0152     slotBinariesFound();
0153 }
0154 
0155 bool JAlbumIntroPage::validatePage()
0156 {
0157     d->settings->m_getOption = (JAlbumSettings::ImageGetOption)d->imageGetOption->currentIndex();
0158 
0159     return true;
0160 }
0161 
0162 void JAlbumIntroPage::slotBinariesFound()
0163 {
0164     d->settings->m_jalbumPath = d->jalbumBin.path();
0165     d->settings->m_javaPath   = d->jalbumJava.path();
0166 
0167     Q_EMIT completeChanged();
0168 }
0169 
0170 bool JAlbumIntroPage::isComplete() const
0171 {
0172     QString val = d->wizard->settings()->m_javaPath + d->wizard->settings()->m_jalbumPath;
0173     qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << val;
0174 
0175     return (!val.isEmpty());
0176 }
0177 
0178 } // namespace DigikamGenericJAlbumPlugin
0179 
0180 #include "moc_jalbumintropage.cpp"