1414#ifndef SRC_DATA_HPP_
1515#define SRC_DATA_HPP_
1616
17- #include < QObject>
18- #include < QSqlDatabase>
19- #include < QSqlQuery>
2017#include < QDebug>
21- #include < QSqlError >
18+ #include < QFileInfo >
2219#include < QIcon>
20+ #include < QObject>
2321#include < QPixmap>
22+ #include < QSqlDatabase>
23+ #include < QSqlError>
24+ #include < QSqlQuery>
2425
2526/* *
2627 * @struct FolderNames
@@ -112,25 +113,48 @@ struct ListItemData {
112113 QIcon picture;
113114};
114115
116+ /* *
117+ * @struct InfoData
118+ * @brief Store HTML data and a list of icons generated from image WEBP data.
119+ *
120+ * This struct is designed to store a body of HTML and convert a list of image data
121+ * (provided as `QByteArray`) into `QIcon` objects. The `QIcon` objects can then
122+ * be used in Qt-based applications with QtWebEngine and QIcons in a split view manner.
123+ */
115124struct InfoData {
116125 /* *
117- * @struct InfoData
118- * @brief
119- * @param
120- * @details
126+ * @brief Default constructor for `InfoData`.
127+ *
128+ * Initializes an empty body and an empty list of icons.
121129 */
122130 InfoData () {}
123- InfoData (QString body, QVector<QByteArray> imageList) : body(body) {
124- for (const QByteArray &image : imageList) {
131+
132+ /* *
133+ * @brief Constructs an `InfoData` object with the given body and image list.
134+ *
135+ * Converts each image in the provided `QVector<QByteArray>` to a `QIcon` object
136+ * using the "WEBP" format and stores them in the icon list.
137+ *
138+ * @param body A string representing the main textual content.
139+ * @param imageList A vector of image data in `QByteArray` format.
140+ */
141+ InfoData (const QString& body, const QVector<QByteArray>& imageList)
142+ : m_body(body) {
143+ for (const QByteArray& image : imageList) {
125144 QPixmap pixmap;
126- QIcon final ;
127- pixmap.loadFromData (image, " WEBP" );
128- final .addPixmap (pixmap);
129- this ->imageList .push_back (final );
145+ QIcon finalIcon;
146+
147+ // Load image data into a QPixmap and convert it to a QIcon
148+ if (pixmap.loadFromData (image, " WEBP" )) {
149+ finalIcon.addPixmap (pixmap);
150+ }
151+
152+ m_imageList.push_back (finalIcon);
130153 }
131154 }
132- QString body;
133- QVector<QIcon> imageList;
155+
156+ QString m_body; // /< The textual content associated with this object.
157+ QVector<QIcon> m_imageList; // /< A list of icons generated from image data.
134158};
135159
136160class Data : public QObject {
@@ -142,17 +166,28 @@ class Data : public QObject {
142166 return instance;
143167 }
144168
145- bool initializeDatabase (QString path) {
146- db = QSqlDatabase::addDatabase ( " QSQLITE " ) ;
147- db. setDatabaseName ( path + " /tombll.db" ) ;
148- db. setConnectOptions ( " QSQLITE_OPEN_READONLY " );
169+ bool initializeDatabase (const QString& path) {
170+ bool status = false ;
171+ const QString filePath = path + " /tombll.db" ;
172+ QFileInfo fileInfo (filePath );
149173
150- if (db.open ()) {
151- return true ;
174+ // Open the file
175+ if (!fileInfo.exists () || !fileInfo.isFile ()) {
176+ qCritical ()
177+ << " Error: The database path is not a regular file: " << path;
178+ status = false ;
152179 } else {
153- qDebug () << " Error opening database:" << db.lastError ().text ();
154- return false ;
180+ db = QSqlDatabase::addDatabase (" QSQLITE" );
181+ db.setDatabaseName (path + " /tombll.db" );
182+ db.setConnectOptions (" QSQLITE_OPEN_READONLY" );
183+ if (db.open ()) { // flawfinder: ignore
184+ status = true ;
185+ } else {
186+ qDebug () << " Error opening database:" << db.lastError ().text ();
187+ status = false ;
188+ }
155189 }
190+ return status;
156191 }
157192
158193 void releaseDatabase () {
0 commit comments