1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2008-04-07
7 * Description : Raw camera list dialog
8 *
9 * Copyright (C) 2008-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option)
15 * 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 "rawcameradlg.h"
25
26 // Qt includes
27
28 #include <QStringList>
29 #include <QString>
30 #include <QLabel>
31 #include <QLayout>
32 #include <QGridLayout>
33 #include <QTreeWidget>
34 #include <QHeaderView>
35
36 // KDE includes
37
38 #include <klocalizedstring.h>
39
40 // Local includes
41
42 #include "drawdecoder.h"
43
44 namespace Digikam
45 {
46
47 class Q_DECL_HIDDEN RawCameraDlg::Private
48 {
49 public:
50
Private()51 explicit Private()
52 : header(nullptr),
53 searchBar(nullptr)
54 {
55 }
56
57 QLabel* header;
58 SearchTextBar* searchBar;
59 };
60
RawCameraDlg(QWidget * const parent)61 RawCameraDlg::RawCameraDlg(QWidget* const parent)
62 : InfoDlg(parent),
63 d(new Private)
64 {
65 setWindowTitle(i18n("List of supported RAW cameras"));
66
67 QStringList list = DRawDecoder::supportedCamera();
68
69 // --------------------------------------------------------
70
71 d->header = new QLabel(this);
72 d->searchBar = new SearchTextBar(this, QLatin1String("RawCameraDlgSearchBar"));
73 updateHeader();
74
75 listView()->setColumnCount(1);
76 listView()->setHeaderLabels(QStringList() << QLatin1String("Camera Model")); // Header is hidden. No i18n here.
77 listView()->header()->hide();
78
79 for (QStringList::const_iterator it = list.constBegin() ; it != list.constEnd() ; ++it)
80 {
81 new QTreeWidgetItem(listView(), QStringList() << *it);
82 }
83
84 // --------------------------------------------------------
85
86 QGridLayout* const grid = dynamic_cast<QGridLayout*>(mainWidget()->layout());
87 grid->addWidget(d->header, 1, 0, 1, -1);
88 grid->addWidget(d->searchBar, 3, 0, 1, -1);
89
90 // --------------------------------------------------------
91
92 connect(d->searchBar, SIGNAL(signalSearchTextSettings(SearchTextSettings)),
93 this, SLOT(slotSearchTextChanged(SearchTextSettings)));
94 }
95
~RawCameraDlg()96 RawCameraDlg::~RawCameraDlg()
97 {
98 delete d;
99 }
100
slotSearchTextChanged(const SearchTextSettings & settings)101 void RawCameraDlg::slotSearchTextChanged(const SearchTextSettings& settings)
102 {
103 bool query = false;
104 int results = 0;
105 QString search = settings.text.toLower();
106
107 QTreeWidgetItemIterator it(listView());
108
109 while (*it)
110 {
111 QTreeWidgetItem* const item = *it;
112
113 if (item->text(0).toLower().contains(search, settings.caseSensitive))
114 {
115 ++results;
116 query = true;
117 item->setHidden(false);
118 }
119 else
120 {
121 item->setHidden(true);
122 }
123
124 ++it;
125 }
126
127 updateHeader(results);
128 d->searchBar->slotSearchResult(query);
129 }
130
updateHeader(int results)131 void RawCameraDlg::updateHeader(int results)
132 {
133 QString librawVer = DRawDecoder::librawVersion();
134 QStringList list = DRawDecoder::supportedCamera();
135
136 if (!results)
137 {
138 d->header->setText(i18np("Using LibRaw version %2<br/>"
139 "1 model on the list",
140 "Using LibRaw version %2<br/>"
141 "%1 models on the list",
142 list.count(),
143 librawVer
144 ));
145 }
146 else
147 {
148 d->header->setText(i18np("Using LibRaw version %2<br/>"
149 "1 model on the list (found: %3)",
150 "Using LibRaw version %2<br/>"
151 "%1 models on the list (found: %3)",
152 list.count(),
153 librawVer,
154 results));
155 }
156 }
157
158 } // namespace Digikam
159