1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2017-06-27
7 * Description : a tool to export items by email.
8 *
9 * Copyright (C) 2017-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * ============================================================ */
22
23 #include "mailimagespage.h"
24
25 // Qt includes
26
27 #include <QIcon>
28 #include <QPixmap>
29 #include <QLabel>
30
31 // KDE includes
32
33 #include <klocalizedstring.h>
34
35 // Local includes
36
37 #include "mailwizard.h"
38 #include "ditemslist.h"
39 #include "dlayoutbox.h"
40
41 namespace DigikamGenericSendByMailPlugin
42 {
43
44 class Q_DECL_HIDDEN MailImagesPage::Private
45 {
46 public:
47
Private(QWizard * const dialog)48 explicit Private(QWizard* const dialog)
49 : imageList(nullptr),
50 wizard(nullptr),
51 iface(nullptr)
52 {
53 wizard = dynamic_cast<MailWizard*>(dialog);
54
55 if (wizard)
56 {
57 iface = wizard->iface();
58 }
59 }
60
61 DItemsList* imageList;
62 MailWizard* wizard;
63 DInfoInterface* iface;
64 };
65
MailImagesPage(QWizard * const dialog,const QString & title)66 MailImagesPage::MailImagesPage(QWizard* const dialog, const QString& title)
67 : DWizardPage(dialog, title),
68 d(new Private(dialog))
69 {
70 DVBox* const vbox = new DVBox(this);
71 QLabel* const desc = new QLabel(vbox);
72 desc->setText(i18n("<p>This view list all items to export by mail.</p>"));
73
74 d->imageList = new DItemsList(vbox);
75 d->imageList->setObjectName(QLatin1String("MailImages ImagesList"));
76 d->imageList->setControlButtonsPlacement(DItemsList::ControlButtonsBelow);
77
78 setPageWidget(vbox);
79 setLeftBottomPix(QIcon::fromTheme(QLatin1String("image-stack")));
80
81 connect(d->imageList, SIGNAL(signalImageListChanged()),
82 this, SIGNAL(completeChanged()));
83 }
84
~MailImagesPage()85 MailImagesPage::~MailImagesPage()
86 {
87 delete d;
88 }
89
setItemsList(const QList<QUrl> & urls)90 void MailImagesPage::setItemsList(const QList<QUrl>& urls)
91 {
92 d->imageList->slotAddImages(urls);
93 }
94
initializePage()95 void MailImagesPage::initializePage()
96 {
97 d->imageList->setIface(d->iface);
98 d->imageList->listView()->clear();
99
100 if (d->wizard->settings()->selMode == MailSettings::IMAGES)
101 {
102 d->imageList->loadImagesFromCurrentSelection();
103 }
104 else
105 {
106 setItemsList(d->wizard->settings()->inputImages);
107 }
108 }
109
validatePage()110 bool MailImagesPage::validatePage()
111 {
112 if (d->imageList->imageUrls().isEmpty())
113 {
114 return false;
115 }
116
117 d->wizard->settings()->inputImages = d->imageList->imageUrls();
118
119 return true;
120 }
121
isComplete() const122 bool MailImagesPage::isComplete() const
123 {
124 return (!d->imageList->imageUrls().isEmpty());
125 }
126
127 } // namespace DigikamGenericSendByMailPlugin
128