File indexing completed on 2025-01-19 03:52:37
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2022-08-26 0007 * Description : file list view and items 0008 * 0009 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2022 by Quoc Hung Tran <quochungtran1999 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "textconverterlist.h" 0017 0018 // KDE includes 0019 0020 #include <klocalizedstring.h> 0021 0022 // LibKDcraw includes 0023 0024 #include "drawdecoder.h" 0025 #include "digikam_debug.h" 0026 0027 using namespace Digikam; 0028 0029 namespace DigikamGenericTextConverterPlugin 0030 { 0031 0032 0033 class TextConverterListViewItem::Private 0034 { 0035 public: 0036 0037 Private() 0038 { 0039 } 0040 0041 QString destFileName; 0042 QString recognizedWords; 0043 QString identity; 0044 QString status; 0045 }; 0046 0047 TextConverterListViewItem::TextConverterListViewItem(DItemsListView* const view, const QUrl& url) 0048 : DItemsListViewItem(view, url), 0049 d (new Private) 0050 { 0051 } 0052 0053 TextConverterListViewItem::~TextConverterListViewItem() 0054 { 0055 delete d; 0056 } 0057 0058 void TextConverterListViewItem::setDestFileName(const QString& str) 0059 { 0060 d->destFileName = str; 0061 setText(TextConverterList::TARGETFILENAME, d->destFileName); 0062 } 0063 0064 QString TextConverterListViewItem::destFileName() const 0065 { 0066 return d->destFileName; 0067 } 0068 0069 void TextConverterListViewItem::setRecognizedWords(const QString& str) 0070 { 0071 d->recognizedWords = str; 0072 setText(TextConverterList::RECOGNIZEDWORDS, d->recognizedWords); 0073 } 0074 0075 QString TextConverterListViewItem::recognizedWords() const 0076 { 0077 return d->recognizedWords; 0078 } 0079 0080 void TextConverterListViewItem::setStatus(const QString& str) 0081 { 0082 d->status = str; 0083 setText(TextConverterList::STATUS, d->status); 0084 } 0085 0086 // -------------------------------------------------------------------------------------- 0087 0088 TextConverterList::TextConverterList(QWidget* const parent) 0089 : DItemsList(parent) 0090 { 0091 listView()->setColumn(static_cast<DItemsListView::ColumnType>(RECOGNIZEDWORDS), i18n("Words"), true); 0092 listView()->setColumn(static_cast<DItemsListView::ColumnType>(TARGETFILENAME), i18n("Target File"), true); 0093 listView()->setColumn(static_cast<DItemsListView::ColumnType>(STATUS), i18n("Status"), true); 0094 } 0095 0096 TextConverterList::~TextConverterList() 0097 { 0098 } 0099 0100 void TextConverterList::slotAddImages(const QList<QUrl>& list) 0101 { 0102 if (list.count() == 0) 0103 { 0104 return; 0105 } 0106 0107 QList<QUrl> urls; 0108 bool raw = false; 0109 0110 for (const auto& imageUrl : list) 0111 { 0112 // Check if the new item already exist in the list. 0113 0114 bool found = false; 0115 0116 for (int i = 0 ; i < listView()->topLevelItemCount() ; ++i) 0117 { 0118 TextConverterListViewItem* const currItem = dynamic_cast<TextConverterListViewItem*>(listView()->topLevelItem(i)); 0119 0120 if (currItem && (currItem->url() == imageUrl)) 0121 { 0122 found = true; 0123 break; 0124 } 0125 } 0126 0127 if (!found) 0128 { 0129 if (DRawDecoder::isRawFile(imageUrl)) 0130 { 0131 raw = true; 0132 continue; 0133 } 0134 0135 new TextConverterListViewItem(listView(), imageUrl); 0136 urls.append(imageUrl); 0137 } 0138 } 0139 0140 Q_EMIT signalAddItems(urls); 0141 Q_EMIT signalFoundRAWImages(raw); 0142 Q_EMIT signalImageListChanged(); 0143 } 0144 0145 void TextConverterList::slotRemoveItems() 0146 { 0147 bool find = false; 0148 0149 do 0150 { 0151 find = false; 0152 QTreeWidgetItemIterator it(listView()); 0153 0154 while (*it) 0155 { 0156 TextConverterListViewItem* const item = dynamic_cast<TextConverterListViewItem*>(*it); 0157 0158 if (item && item->isSelected()) 0159 { 0160 delete item; 0161 find = true; 0162 break; 0163 } 0164 0165 ++it; 0166 } 0167 } 0168 while (find); 0169 } 0170 0171 } // namespace DigikamGenericTextConverterPlugin 0172 0173 #include "moc_textconverterlist.cpp"