File indexing completed on 2025-11-09 04:06:40

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-04-07
0007  * Description : Raw camera list dialog
0008  *
0009  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "rawcameradlg.h"
0016 
0017 // Qt includes
0018 
0019 #include <QStringList>
0020 #include <QString>
0021 #include <QLabel>
0022 #include <QLayout>
0023 #include <QGridLayout>
0024 #include <QTreeWidget>
0025 #include <QHeaderView>
0026 
0027 // KDE includes
0028 
0029 #include <klocalizedstring.h>
0030 
0031 // Local includes
0032 
0033 #include "drawdecoder.h"
0034 
0035 namespace Digikam
0036 {
0037 
0038 class Q_DECL_HIDDEN RawCameraDlg::Private
0039 {
0040 public:
0041 
0042     explicit Private()
0043       : header(nullptr),
0044         searchBar(nullptr)
0045     {
0046     }
0047 
0048     QLabel*        header;
0049     SearchTextBar* searchBar;
0050 };
0051 
0052 RawCameraDlg::RawCameraDlg(QWidget* const parent)
0053     : InfoDlg(parent),
0054       d(new Private)
0055 {
0056     setWindowTitle(i18nc("@title:window", "List of Supported RAW Cameras"));
0057 
0058     QStringList list = DRawDecoder::supportedCamera();
0059 
0060     // --------------------------------------------------------
0061 
0062     d->header    = new QLabel(this);
0063     d->searchBar = new SearchTextBar(this, QLatin1String("RawCameraDlgSearchBar"));
0064     updateHeader();
0065 
0066     listView()->setColumnCount(1);
0067     listView()->setHeaderLabels(QStringList() << QLatin1String("Camera Model")); // Header is hidden. No i18n here.
0068     listView()->header()->hide();
0069 
0070     for (QStringList::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it)
0071     {
0072         new QTreeWidgetItem(listView(), QStringList() << *it);
0073     }
0074 
0075     // --------------------------------------------------------
0076 
0077     QGridLayout* const  grid = dynamic_cast<QGridLayout*>(mainWidget()->layout());
0078     grid->addWidget(d->header,    1, 0, 1, -1);
0079     grid->addWidget(d->searchBar, 3, 0, 1, -1);
0080 
0081     // --------------------------------------------------------
0082 
0083     connect(d->searchBar, SIGNAL(signalSearchTextSettings(SearchTextSettings)),
0084             this, SLOT(slotSearchTextChanged(SearchTextSettings)));
0085 }
0086 
0087 RawCameraDlg::~RawCameraDlg()
0088 {
0089     delete d;
0090 }
0091 
0092 void RawCameraDlg::slotSearchTextChanged(const SearchTextSettings& settings)
0093 {
0094     bool query     = false;
0095     int  results   = 0;
0096     QString search = settings.text.toLower();
0097 
0098     QTreeWidgetItemIterator it(listView());
0099 
0100     while (*it)
0101     {
0102         QTreeWidgetItem* const item  = *it;
0103 
0104         if (item->text(0).toLower().contains(search, settings.caseSensitive))
0105         {
0106             ++results;
0107             query = true;
0108             item->setHidden(false);
0109         }
0110         else
0111         {
0112             item->setHidden(true);
0113         }
0114 
0115         ++it;
0116     }
0117 
0118     updateHeader(results);
0119     d->searchBar->slotSearchResult(query);
0120 }
0121 
0122 void RawCameraDlg::updateHeader(int results)
0123 {
0124     QString librawVer = DRawDecoder::librawVersion();
0125     QStringList list  = DRawDecoder::supportedCamera();
0126 
0127     if (!results)
0128     {
0129         d->header->setText(i18np("Using LibRaw version %2<br/>"
0130                                  "1 model on the list",
0131                                  "Using LibRaw version %2<br/>"
0132                                  "%1 models on the list",
0133                                  list.count(),
0134                                  librawVer
0135                                  ));
0136     }
0137     else
0138     {
0139         d->header->setText(i18np("Using LibRaw version %2<br/>"
0140                                  "1 model on the list (found: %3)",
0141                                  "Using LibRaw version %2<br/>"
0142                                  "%1 models on the list (found: %3)",
0143                                  list.count(),
0144                                  librawVer,
0145                                  results));
0146     }
0147 }
0148 
0149 } // namespace Digikam
0150 
0151 #include "moc_rawcameradlg.cpp"