MCPcopy Create free account
hub / github.com/KDE/labplot / getProjectThumbnail

Method getProjectThumbnail

src/frontend/welcomescreen/WelcomeScreenHelper.cpp:177–226  ·  view source on GitHub ↗

* @brief Returns the thumbnail image saved with the project. * @param url the path to the saved project file. */

Source from the content-addressed store, hash-verified

175 * @param url the path to the saved project file.
176 */
177QVariant WelcomeScreenHelper::getProjectThumbnail(const QUrl& url) {
178 QString filename;
179 if (url.isLocalFile()) // fix for Windows
180 filename = url.toLocalFile();
181 else
182 filename = url.path();
183
184 QIODevice* file;
185 // first try gzip compression, because projects can be gzipped and end with .lml
186 if (filename.endsWith(QLatin1String(".lml"), Qt::CaseInsensitive))
187 file = new KCompressionDevice(filename, KFilterDev::compressionTypeForMimeType("application/x-gzip"));
188 else // opens filename using file ending
189 file = new KFilterDev(filename);
190
191 if (!file)
192 file = new QFile(filename);
193
194 if (!file->open(QIODevice::ReadOnly)) {
195 qDebug() << "Could not open file for reading.";
196 return QVariant();
197 }
198
199 char c;
200 bool rc = file->getChar(&c);
201 if (!rc) {
202 qDebug() << "The project file is empty.";
203 file->close();
204 delete file;
205 return false;
206 }
207 file->seek(0);
208
209 // parse XML
210 XmlStreamReader reader(file);
211 while (!(reader.isStartDocument() || reader.atEnd()))
212 reader.readNext();
213
214 if (!(reader.atEnd())) {
215 if (!reader.skipToNextTag())
216 return false;
217
218 if (reader.name() == "project") {
219 QString thumbnail = reader.attributes().value("thumbnail").toString();
220
221 thumbnail.prepend("data:image/jpg;base64,");
222 return QVariant(thumbnail);
223 }
224 }
225 return QVariant();
226}
227
228/**
229 * @brief Returns a pointer to the datasetModel of the class.

Callers

nothing calls this directly

Calls 8

atEndMethod · 0.80
skipToNextTagMethod · 0.80
pathMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
nameMethod · 0.45
toStringMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected