11/* This file is part of YUView - The YUV player with advanced analytics toolset
2- * <https://github.com/IENT/YUView>
3- * Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4- *
5- * This program is free software; you can redistribute it and/or modify
6- * it under the terms of the GNU General Public License as published by
7- * the Free Software Foundation; either version 3 of the License, or
8- * (at your option) any later version.
9- *
10- * In addition, as a special exception, the copyright holders give
11- * permission to link the code of portions of this program with the
12- * OpenSSL library under certain conditions as described in each
13- * individual source file, and distribute linked combinations including
14- * the two.
15- *
16- * You must obey the GNU General Public License in all respects for all
17- * of the code used other than OpenSSL. If you modify file(s) with this
18- * exception, you may extend this exception to your version of the
19- * file(s), but you are not obligated to do so. If you do not wish to do
20- * so, delete this exception statement from your version. If you delete
21- * this exception statement from all source files in the program, then
22- * also delete it here.
23- *
24- * This program is distributed in the hope that it will be useful,
25- * but WITHOUT ANY WARRANTY; without even the implied warranty of
26- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27- * GNU General Public License for more details.
28- *
29- * You should have received a copy of the GNU General Public License
30- * along with this program. If not, see <http://www.gnu.org/licenses/>.
31- */
2+ * <https://github.com/IENT/YUView>
3+ * Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
4+ *
5+ * This program is free software; you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation; either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * In addition, as a special exception, the copyright holders give
11+ * permission to link the code of portions of this program with the
12+ * OpenSSL library under certain conditions as described in each
13+ * individual source file, and distribute linked combinations including
14+ * the two.
15+ *
16+ * You must obey the GNU General Public License in all respects for all
17+ * of the code used other than OpenSSL. If you modify file(s) with this
18+ * exception, you may extend this exception to your version of the
19+ * file(s), but you are not obligated to do so. If you do not wish to do
20+ * so, delete this exception statement from your version. If you delete
21+ * this exception statement from all source files in the program, then
22+ * also delete it here.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ */
3232
3333#include " ItemMemoryHandler.h"
3434
@@ -48,26 +48,32 @@ namespace itemMemoryHandler
4848
4949struct ItemData
5050{
51- QString filePath;
52- QDateTime itemChangedLast;
53- QString format;
54- QString toString () const { return QString (" File: %1 Last Changed: %2 Format: %3" ).arg (filePath).arg (itemChangedLast.toString (" yy-M-d H-m-s" )).arg (format); }
51+ QString filePath;
52+ QDateTime itemChangedLast;
53+ std::string format;
54+ QString toString () const
55+ {
56+ return QString (" File: %1 Last Changed: %2 Format: %3" )
57+ .arg (filePath)
58+ .arg (itemChangedLast.toString (" yy-M-d H-m-s" ))
59+ .arg (format);
60+ }
5561};
5662
5763QList<ItemData> getAllValidItems ()
5864{
59- QSettings settings;
65+ QSettings settings;
6066 QList<ItemData> validItems;
61- auto timeYesterday = QDateTime::currentDateTime ().addDays (-2 );
67+ auto timeYesterday = QDateTime::currentDateTime ().addDays (-2 );
6268
6369 auto size = settings.beginReadArray (" itemMemory" );
64- for (int i = 0 ; i < size; ++i)
70+ for (int i = 0 ; i < size; ++i)
6571 {
6672 settings.setArrayIndex (i);
6773 ItemData data;
68- data.filePath = settings.value (" filePath" ).toString ();
74+ data.filePath = settings.value (" filePath" ).toString ();
6975 data.itemChangedLast = settings.value (" dateChanged" ).toDateTime ();
70- data.format = settings.value (" format" ).toString ();
76+ data.format = settings.value (" format" ).toString (). toStdString ();
7177 if (data.itemChangedLast >= timeYesterday)
7278 {
7379 validItems.append (data);
@@ -86,22 +92,22 @@ QList<ItemData> getAllValidItems()
8692void writeNewItemList (QList<ItemData> newItemList)
8793{
8894 QSettings settings;
89- settings.remove (" itemMemory" ); // Delete the old list
95+ settings.remove (" itemMemory" ); // Delete the old list
9096
9197 settings.beginWriteArray (" itemMemory" );
92- for (int i = 0 ; i < newItemList.size (); ++i)
98+ for (int i = 0 ; i < newItemList.size (); ++i)
9399 {
94100 const auto &item = newItemList[i];
95101 settings.setArrayIndex (i);
96102 settings.setValue (" filePath" , item.filePath );
97103 settings.setValue (" dateChanged" , QVariant (item.itemChangedLast ));
98- settings.setValue (" format" , item.format );
104+ settings.setValue (" format" , QString::fromStdString ( item.format ) );
99105 DEBUG_MEMORY (" writeNewItemList Written item " << item.toString ());
100106 }
101107 settings.endArray ();
102108}
103109
104- void itemMemoryAddFormat (QString filePath, QString format)
110+ void itemMemoryAddFormat (const QString & filePath, const std::string & format)
105111{
106112 auto validItems = getAllValidItems ();
107113
@@ -111,8 +117,8 @@ void itemMemoryAddFormat(QString filePath, QString format)
111117 if (validItems[i].filePath == filePath)
112118 {
113119 validItems[i].itemChangedLast = QDateTime::currentDateTime ();
114- validItems[i].format = format;
115- itemUpdated = true ;
120+ validItems[i].format = format;
121+ itemUpdated = true ;
116122 DEBUG_MEMORY (" itemMemoryAddFormat Modified item " << validItems[i].toString ());
117123 break ;
118124 }
@@ -121,17 +127,17 @@ void itemMemoryAddFormat(QString filePath, QString format)
121127 if (!itemUpdated)
122128 {
123129 ItemData newItem;
124- newItem.filePath = filePath;
130+ newItem.filePath = filePath;
125131 newItem.itemChangedLast = QDateTime::currentDateTime ();
126- newItem.format = format;
132+ newItem.format = format;
127133 validItems.append (newItem);
128134 DEBUG_MEMORY (" itemMemoryAddFormat Added new item " << newItem.toString ());
129135 }
130-
136+
131137 writeNewItemList (validItems);
132138}
133139
134- QString itemMemoryGetFormat (QString filePath)
140+ std::optional<std::string> itemMemoryGetFormat (const QString & filePath)
135141{
136142 auto validItems = getAllValidItems ();
137143
0 commit comments