1 /* ============================================================
2  *
3  * This file is a part of kipi-plugins project
4  * https://www.digikam.org
5  *
6  * Date        : 2008-09-24
7  * Description : file list view and items.
8  *
9  * Copyright (C) 2008-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2011      by Veaceslav Munteanu <slavuttici at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "dngconverterlist.h"
25 
26 // Qt includes
27 
28 #include <QFileInfo>
29 #include <QDir>
30 
31 // KDE includes
32 
33 #include <klocalizedstring.h>
34 
35 // LibKDcraw includes
36 
37 #include "drawdecoder.h"
38 
39 namespace DigikamGenericDNGConverterPlugin
40 {
41 
DNGConverterList(QWidget * const parent)42 DNGConverterList::DNGConverterList(QWidget* const parent)
43     : DItemsList(parent)
44 {
45     setControlButtonsPlacement(DItemsList::ControlButtonsBelow);
46     listView()->setColumnLabel(DItemsListView::Filename, i18n("Raw File"));
47     listView()->setColumn(static_cast<DItemsListView::ColumnType>(TARGETFILENAME), i18n("Target File"), true);
48     listView()->setColumn(static_cast<DItemsListView::ColumnType>(IDENTIFICATION), i18n("Camera"),      true);
49     listView()->setColumn(static_cast<DItemsListView::ColumnType>(STATUS),         i18n("Status"),      true);
50 }
51 
~DNGConverterList()52 DNGConverterList::~DNGConverterList()
53 {
54 }
55 
slotAddImages(const QList<QUrl> & list)56 void DNGConverterList::slotAddImages(const QList<QUrl>& list)
57 {
58     /**
59      * Replaces the DItemsList::slotAddImages method, so that
60      * DNGConverterListViewItems can be added instead of ImagesListViewItems
61      */
62 
63     // Figure out which of the supplied Url's should actually be added and which
64     // of them already exist.
65 
66     bool found = false;
67 
68     for (QList<QUrl>::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it)
69     {
70         QUrl imageUrl = *it;
71         found         = false;
72 
73         for (int i = 0 ; i < listView()->topLevelItemCount() ; ++i)
74         {
75             DNGConverterListViewItem* const currItem = dynamic_cast<DNGConverterListViewItem*>(listView()->topLevelItem(i));
76 
77             if (currItem && (currItem->url() == imageUrl))
78             {
79                 found = true;
80                 break;
81             }
82         }
83 
84         if (!found                                                                       &&
85             (DRawDecoder::isRawFile(imageUrl))                                           &&
86             (QFileInfo(imageUrl.toLocalFile()).suffix().toUpper() != QLatin1String("DNG")))
87         {
88             new DNGConverterListViewItem(listView(), imageUrl);
89         }
90     }
91 
92     // Duplicate the signalImageListChanged of the ImageWindow, to enable the upload button again.
93 
94     emit signalImageListChanged();
95 }
96 
slotRemoveItems()97 void DNGConverterList::slotRemoveItems()
98 {
99     bool find = false;
100 
101     do
102     {
103         find = false;
104         QTreeWidgetItemIterator it(listView());
105 
106         while (*it)
107         {
108             DNGConverterListViewItem* const item = dynamic_cast<DNGConverterListViewItem*>(*it);
109 
110             if (item && item->isSelected())
111             {
112                 delete item;
113                 find = true;
114                 break;
115             }
116 
117             ++it;
118         }
119     }
120     while(find);
121 }
122 
123 // ------------------------------------------------------------------------------------------------
124 
125 class DNGConverterListViewItem::Private
126 {
127 public:
128 
Private()129     Private()
130     {
131     }
132 
133     QString destFileName;
134     QString identity;
135     QString status;
136 };
137 
DNGConverterListViewItem(DItemsListView * const view,const QUrl & url)138 DNGConverterListViewItem::DNGConverterListViewItem(DItemsListView* const view, const QUrl& url)
139     : DItemsListViewItem(view, url),
140       d                 (new Private)
141 {
142 }
143 
~DNGConverterListViewItem()144 DNGConverterListViewItem::~DNGConverterListViewItem()
145 {
146     delete d;
147 }
148 
setDestFileName(const QString & str)149 void DNGConverterListViewItem::setDestFileName(const QString& str)
150 {
151     d->destFileName = str;
152     setText(DNGConverterList::TARGETFILENAME, d->destFileName);
153 }
154 
destFileName() const155 QString DNGConverterListViewItem::destFileName() const
156 {
157     return d->destFileName;
158 }
159 
setIdentity(const QString & str)160 void DNGConverterListViewItem::setIdentity(const QString& str)
161 {
162     d->identity = str;
163     setText(DNGConverterList::IDENTIFICATION, d->identity);
164 }
165 
identity() const166 QString DNGConverterListViewItem::identity() const
167 {
168     return d->identity;
169 }
170 
setStatus(const QString & str)171 void DNGConverterListViewItem::setStatus(const QString& str)
172 {
173     d->status = str;
174     setText(DNGConverterList::STATUS, d->status);
175 }
176 
destPath() const177 QString DNGConverterListViewItem::destPath() const
178 {
179     return (QDir::fromNativeSeparators(QFileInfo(url().toLocalFile()).path() + QLatin1String("/") + destFileName()));
180 }
181 
182 } // namespace DigikamGenericDNGConverterPlugin
183