1 /** =========================================================== 2 * @file 3 * 4 * This file is a part of KDE project 5 * 6 * 7 * @date 2009-11-21 8 * @brief kipi host test application 9 * 10 * @author Copyright (C) 2009-2010 by Michael G. Hansen 11 * <a href="mailto:mike at mghansen dot de">mike at mghansen dot de</a> 12 * @author Copyright (C) 2011-2018 by Gilles Caulier 13 * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a> 14 * 15 * This program is free software; you can redistribute it 16 * and/or modify it under the terms of the GNU General 17 * Public License as published by the Free Software Foundation; 18 * either version 2, or (at your option) any later version. 19 * 20 * This program is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * GNU General Public License for more details. 24 * 25 * ============================================================ */ 26 27 #include "kipiuploadwidget.h" 28 29 // Qt includes: 30 31 #include <QListWidget> 32 #include <QVBoxLayout> 33 #include <QLabel> 34 #include <QDebug> 35 36 // Libkipi includes 37 38 #include "imagecollection.h" 39 40 // Local includes 41 42 #include "kipiinterface.h" 43 44 namespace KXMLKipiCmd 45 { 46 KipiUploadWidget(KipiInterface * const interface,QWidget * const parent)47KipiUploadWidget::KipiUploadWidget(KipiInterface* const interface, QWidget* const parent) 48 : UploadWidget(parent), 49 m_interface(interface), 50 m_listWidget(nullptr) 51 { 52 QVBoxLayout* const layout = new QVBoxLayout(this); 53 layout->addWidget(new QLabel(QString::fromLatin1("Please select a target album:"))); // no need i18n. 54 m_listWidget = new QListWidget(this); 55 layout->addWidget(m_listWidget); 56 57 setLayout(layout); 58 59 connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &KipiUploadWidget::slotItemSelectionChanged); 60 61 // add all albums to the list widget: 62 m_allAlbums = m_interface->allAlbums(); 63 64 for (QList<ImageCollection>::const_iterator it = m_allAlbums.constBegin(); it != m_allAlbums.constEnd(); ++it) 65 { 66 m_listWidget->addItem(it->name()); 67 68 // is the album selected? 69 const QUrl itemPath = it->url(); 70 m_listWidget->item(m_listWidget->count()-1)->setSelected(m_interface->m_selectedAlbums.contains(itemPath)); 71 } 72 } 73 ~KipiUploadWidget()74KipiUploadWidget::~KipiUploadWidget() 75 { 76 } 77 selectedImageCollection() const78ImageCollection KipiUploadWidget::selectedImageCollection() const 79 { 80 // return the selected albums (should be only one): 81 const QList<QListWidgetItem*> selectedItems = m_listWidget->selectedItems(); 82 83 if (selectedItems.isEmpty()) 84 { 85 // this should not happen!!! the calling application will probably crash now... 86 qDebug() << "Nothing selected... impossible!"; 87 return ImageCollection(nullptr); 88 } 89 90 const int row = m_listWidget->row(selectedItems.at(0)); 91 92 return m_allAlbums.at(row); 93 } 94 slotItemSelectionChanged()95void KipiUploadWidget::slotItemSelectionChanged() 96 { 97 emit(selectionChanged()); 98 } 99 100 } // namespace KXMLKipiCmd 101