File indexing completed on 2024-05-12 04:33:19
0001 /* 0002 SPDX-FileCopyrightText: 2009-2010 Michael G. Hansen <mike at mghansen dot de> 0003 SPDX-FileCopyrightText: 2011-2018 Gilles Caulier <caulier dot gilles at gmail dot com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "kipiuploadwidget.h" 0009 0010 // Qt includes: 0011 0012 #include <QListWidget> 0013 #include <QVBoxLayout> 0014 #include <QLabel> 0015 #include <QDebug> 0016 0017 // Libkipi includes 0018 0019 #include "imagecollection.h" 0020 0021 // Local includes 0022 0023 #include "kipiinterface.h" 0024 0025 namespace KXMLKipiCmd 0026 { 0027 0028 KipiUploadWidget::KipiUploadWidget(KipiInterface* const interface, QWidget* const parent) 0029 : UploadWidget(parent), 0030 m_interface(interface), 0031 m_listWidget(nullptr) 0032 { 0033 QVBoxLayout* const layout = new QVBoxLayout(this); 0034 layout->addWidget(new QLabel(QString::fromLatin1("Please select a target album:"))); // no need i18n. 0035 m_listWidget = new QListWidget(this); 0036 layout->addWidget(m_listWidget); 0037 0038 setLayout(layout); 0039 0040 connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &KipiUploadWidget::slotItemSelectionChanged); 0041 0042 // add all albums to the list widget: 0043 m_allAlbums = m_interface->allAlbums(); 0044 0045 for (QList<ImageCollection>::const_iterator it = m_allAlbums.constBegin(); it != m_allAlbums.constEnd(); ++it) 0046 { 0047 m_listWidget->addItem(it->name()); 0048 0049 // is the album selected? 0050 const QUrl itemPath = it->url(); 0051 m_listWidget->item(m_listWidget->count()-1)->setSelected(m_interface->m_selectedAlbums.contains(itemPath)); 0052 } 0053 } 0054 0055 KipiUploadWidget::~KipiUploadWidget() 0056 { 0057 } 0058 0059 ImageCollection KipiUploadWidget::selectedImageCollection() const 0060 { 0061 // return the selected albums (should be only one): 0062 const QList<QListWidgetItem*> selectedItems = m_listWidget->selectedItems(); 0063 0064 if (selectedItems.isEmpty()) 0065 { 0066 // this should not happen!!! the calling application will probably crash now... 0067 qDebug() << "Nothing selected... impossible!"; 0068 return ImageCollection(nullptr); 0069 } 0070 0071 const int row = m_listWidget->row(selectedItems.at(0)); 0072 0073 return m_allAlbums.at(row); 0074 } 0075 0076 void KipiUploadWidget::slotItemSelectionChanged() 0077 { 0078 Q_EMIT selectionChanged(); 0079 } 0080 0081 } // namespace KXMLKipiCmd 0082 0083 #include "moc_kipiuploadwidget.cpp"