File indexing completed on 2025-01-19 03:52:45

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-06-27
0007  * Description : a tool to export items by email.
0008  *
0009  * SPDX-FileCopyrightText: 2017-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 "mailintropage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QLabel>
0020 #include <QPixmap>
0021 #include <QComboBox>
0022 #include <QIcon>
0023 #include <QGroupBox>
0024 #include <QGridLayout>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 
0030 // Local includes
0031 
0032 #include "digikam_debug.h"
0033 #include "digikam_config.h"
0034 #include "digikam_globals.h"
0035 #include "dlayoutbox.h"
0036 #include "mailwizard.h"
0037 #include "mailsettings.h"
0038 #include "dbinarysearch.h"
0039 #include "balsabinary.h"
0040 #include "clawsmailbinary.h"
0041 #include "kmailbinary.h"
0042 #include "evolutionbinary.h"
0043 #include "netscapebinary.h"
0044 #include "outlookbinary.h"
0045 #include "sylpheedbinary.h"
0046 #include "thunderbirdbinary.h"
0047 
0048 namespace DigikamGenericSendByMailPlugin
0049 {
0050 
0051 class Q_DECL_HIDDEN MailIntroPage::Private
0052 {
0053 public:
0054 
0055     explicit Private(QWizard* const dialog)
0056       : imageGetOption(nullptr),
0057         hbox(nullptr),
0058         wizard(nullptr),
0059         iface(nullptr),
0060         binSearch(nullptr)
0061     {
0062         wizard = dynamic_cast<MailWizard*>(dialog);
0063 
0064         if (wizard)
0065         {
0066             iface = wizard->iface();
0067         }
0068     }
0069 
0070     QComboBox*        imageGetOption;
0071     DHBox*            hbox;
0072     MailWizard*       wizard;
0073     DInfoInterface*   iface;
0074     DBinarySearch*    binSearch;
0075     BalsaBinary       balsaBin;
0076     ClawsMailBinary   clawsBin;
0077     EvolutionBinary   evoluBin;
0078     KmailBinary       kmailBin;
0079     NetscapeBinary    netscBin;
0080     OutlookBinary     outloBin;
0081     SylpheedBinary    sylphBin;
0082     ThunderbirdBinary thundBin;
0083 };
0084 
0085 MailIntroPage::MailIntroPage(QWizard* const dialog, const QString& title)
0086     : DWizardPage(dialog, title),
0087       d(new Private(dialog))
0088 {
0089     DVBox* const vbox  = new DVBox(this);
0090     QLabel* const desc = new QLabel(vbox);
0091 
0092     desc->setWordWrap(true);
0093     desc->setOpenExternalLinks(true);
0094     desc->setText(i18n("<qt>"
0095                        "<p><h1><b>Welcome to Email Tool</b></h1></p>"
0096                        "<p>This assistant will guide you to send "
0097                        "your items with a mail client application.</p>"
0098                        "<p>Before to export contents, you will be able to adjust attachments "
0099                        "properties accordingly with your mail service capabilities.</p>"
0100                        "</qt>"));
0101 
0102     // ComboBox for image selection method
0103 
0104     d->hbox                     = new DHBox(vbox);
0105     QLabel* const getImageLabel = new QLabel(i18n("&Choose image selection method:"), d->hbox);
0106     d->imageGetOption           = new QComboBox(d->hbox);
0107     d->imageGetOption->insertItem(MailSettings::ALBUMS, i18n("Albums"));
0108     d->imageGetOption->insertItem(MailSettings::IMAGES, i18n("Images"));
0109     getImageLabel->setBuddy(d->imageGetOption);
0110 
0111     // --------------------
0112 
0113     QGroupBox* const binaryBox      = new QGroupBox(vbox);
0114     QGridLayout* const binaryLayout = new QGridLayout;
0115     binaryBox->setLayout(binaryLayout);
0116     binaryBox->setTitle(i18nc("@title:group", "Mail client application Binaries"));
0117     d->binSearch = new DBinarySearch(binaryBox);
0118     d->binSearch->addBinary(d->balsaBin);
0119     d->binSearch->addBinary(d->clawsBin);
0120     d->binSearch->addBinary(d->kmailBin);
0121     d->binSearch->addBinary(d->evoluBin);
0122     d->binSearch->addBinary(d->netscBin);
0123     d->binSearch->addBinary(d->outloBin);
0124     d->binSearch->addBinary(d->sylphBin);
0125     d->binSearch->addBinary(d->thundBin);
0126 
0127 #ifdef Q_OS_MACOS
0128 
0129     // Std Macports install
0130 
0131     d->binSearch->addDirectory(QLatin1String("/opt/local/bin"));
0132 
0133     // digiKam Bundle PKG install
0134 
0135     d->binSearch->addDirectory(macOSBundlePrefix() + QLatin1String("bin"));
0136 
0137 #endif
0138 
0139 #ifdef Q_OS_WIN
0140 
0141     // FIXME : adjust paths
0142 
0143     d->binSearch->addDirectory(QLatin1String("C:/Program Files/"));
0144 
0145     d->binSearch->addDirectory(QLatin1String("C:/Program Files (x86)/"));
0146 
0147 #endif
0148 
0149     vbox->setStretchFactor(desc,      2);
0150     vbox->setStretchFactor(d->hbox,   1);
0151     vbox->setStretchFactor(binaryBox, 3);
0152 
0153     setPageWidget(vbox);
0154     setLeftBottomPix(QIcon::fromTheme(QLatin1String("mail-client")));
0155 
0156     connect(d->binSearch, SIGNAL(signalBinariesFound(bool)),
0157             this, SLOT(slotBinariesFound()));
0158 }
0159 
0160 MailIntroPage::~MailIntroPage()
0161 {
0162     delete d;
0163 }
0164 
0165 void MailIntroPage::initializePage()
0166 {
0167     bool albumSupport = (d->iface && d->iface->supportAlbums());
0168 
0169     if (!albumSupport)
0170     {
0171         d->imageGetOption->setCurrentIndex(MailSettings::IMAGES);
0172         d->hbox->setEnabled(false);
0173     }
0174     else
0175     {
0176         d->imageGetOption->setCurrentIndex(d->wizard->settings()->selMode);
0177     }
0178 
0179     d->binSearch->allBinariesFound();
0180     slotBinariesFound();
0181 }
0182 
0183 bool MailIntroPage::validatePage()
0184 {
0185     d->wizard->settings()->selMode = (MailSettings::Selection)d->imageGetOption->currentIndex();
0186 
0187     return true;
0188 }
0189 
0190 void MailIntroPage::slotBinariesFound()
0191 {
0192     d->wizard->settings()->binPaths.insert(MailSettings::BALSA, d->balsaBin.isValid() ?
0193                                            d->balsaBin.path() : QString());
0194 
0195     d->wizard->settings()->binPaths.insert(MailSettings::CLAWSMAIL, d->clawsBin.isValid() ?
0196                                            d->clawsBin.path() : QString());
0197 
0198     d->wizard->settings()->binPaths.insert(MailSettings::EVOLUTION, d->evoluBin.isValid() ?
0199                                            d->evoluBin.path() : QString());
0200 
0201     d->wizard->settings()->binPaths.insert(MailSettings::KMAIL, d->kmailBin.isValid() ?
0202                                            d->kmailBin.path() : QString());
0203 
0204     d->wizard->settings()->binPaths.insert(MailSettings::NETSCAPE, d->netscBin.isValid() ?
0205                                            d->netscBin.path() : QString());
0206 
0207     d->wizard->settings()->binPaths.insert(MailSettings::OUTLOOK, d->outloBin.isValid() ?
0208                                            d->outloBin.path() : QString());
0209 
0210     d->wizard->settings()->binPaths.insert(MailSettings::SYLPHEED, d->sylphBin.isValid() ?
0211                                            d->sylphBin.path() : QString());
0212 
0213     d->wizard->settings()->binPaths.insert(MailSettings::THUNDERBIRD, d->thundBin.isValid() ?
0214                                            d->thundBin.path() : QString());
0215 
0216     Q_EMIT completeChanged();
0217 }
0218 
0219 bool MailIntroPage::isComplete() const
0220 {
0221     QString val = d->wizard->settings()->binPaths.values().join(QString());
0222     qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << val;
0223 
0224     return (!val.isEmpty());
0225 }
0226 
0227 } // namespace DigikamGenericSendByMailPlugin
0228 
0229 #include "moc_mailintropage.cpp"