* @brief Returns the thumbnail image saved with the project. * @param url the path to the saved project file. */
| 175 | * @param url the path to the saved project file. |
| 176 | */ |
| 177 | QVariant 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. |