SHARE
TWEET

Untitled

a guest Jun 27th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/src/backend/core/Project.cpp b/src/backend/core/Project.cpp
  2. index 477d3124b..8b001fff5 100644
  3. --- a/src/backend/core/Project.cpp
  4. +++ b/src/backend/core/Project.cpp
  5. @@ -53,6 +53,7 @@
  6.  #include <QMenu>
  7.  #include <QThreadPool>
  8.  #include <QUndoStack>
  9. +#include <QBuffer>
  10.  
  11.  #include <KConfig>
  12.  #include <KConfigGroup>
  13. @@ -223,10 +224,8 @@ QString Project::supportedExtensions() {
  14.  //##############################################################################
  15.  //##################  Serialization/Deserialization  ###########################
  16.  //##############################################################################
  17. -/**
  18. - * \brief Save as XML
  19. - */
  20. -void Project::save(QXmlStreamWriter* writer) const {
  21. +
  22. +void Project::save(const QPixmap& thumbnail, QXmlStreamWriter* writer) const {
  23.     //set the version and the modification time to the current values
  24.     d->version = LVERSION;
  25.     d->modificationTime = QDateTime::currentDateTime();
  26. @@ -240,10 +239,25 @@ void Project::save(QXmlStreamWriter* writer) const {
  27.     writer->writeAttribute("fileName", fileName());
  28.     writer->writeAttribute("modificationTime", modificationTime().toString("yyyy-dd-MM hh:mm:ss:zzz"));
  29.     writer->writeAttribute("author", author());
  30. +
  31. +   QByteArray bArray;
  32. +   QBuffer buffer(&bArray);
  33. +   buffer.open(QIODevice::WriteOnly);
  34. +   thumbnail.save(&buffer, "JPEG");
  35. +   QString image = QString::fromLatin1(bArray.toBase64().data());
  36. +   writer->writeAttribute("thumbnail", image);
  37. +
  38.     writeBasicAttributes(writer);
  39.  
  40.     writeCommentElement(writer);
  41.  
  42. +   save(writer);
  43. +}
  44. +
  45. +/**
  46. + * \brief Save as XML
  47. + */
  48. +void Project::save(QXmlStreamWriter* writer) const {
  49.     //save all children
  50.     for (auto* child : children<AbstractAspect>(IncludeHidden)) {
  51.         writer->writeStartElement("child_aspect");
  52. diff --git a/src/backend/core/Project.h b/src/backend/core/Project.h
  53. index 2558c9cd4..8bd3aee86 100644
  54. --- a/src/backend/core/Project.h
  55. +++ b/src/backend/core/Project.h
  56. @@ -73,7 +73,7 @@ public:
  57.     bool hasChanged() const;
  58.     void navigateTo(const QString& path);
  59.  
  60. -   void save(QXmlStreamWriter*) const override;
  61. +   void save(const QPixmap&, QXmlStreamWriter*) const;
  62.     bool load(XmlStreamReader*, bool preview) override;
  63.     bool load(const QString&, bool preview = false);
  64.  
  65. @@ -98,6 +98,7 @@ private:
  66.     class Private;
  67.     Private* d;
  68.     bool readProjectAttributes(XmlStreamReader*);
  69. +   void save(QXmlStreamWriter*) const override;
  70.  };
  71.  
  72.  #endif // ifndef PROJECT_H
  73. diff --git a/src/kdefrontend/MainWin.cpp b/src/kdefrontend/MainWin.cpp
  74. index da62a398d..2dba76f64 100644
  75. --- a/src/kdefrontend/MainWin.cpp
  76. +++ b/src/kdefrontend/MainWin.cpp
  77. @@ -1097,8 +1097,10 @@ bool MainWin::save(const QString& fileName) {
  78.     if (file->open(QIODevice::WriteOnly)) {
  79.         m_project->setFileName(fileName);
  80.  
  81. +       QPixmap thumbnail = centralWidget()->grab();
  82. +
  83.         QXmlStreamWriter writer(file);
  84. -       m_project->save(&writer);
  85. +       m_project->save(thumbnail, &writer);
  86.         m_project->undoStack()->clear();
  87.         m_project->setChanged(false);
  88.         file->close();
  89.  
  90.  
  91.  
  92.  
  93.  
  94. +QVariant WelcomeScreenHelper::getProjectThumbnail(const QUrl& url) {
  95. +   QString filename;
  96. +   if (url.isLocalFile())  // fix for Windows
  97. +       filename = url.toLocalFile();
  98. +   else
  99. +       filename = url.path();
  100. +
  101. +   QIODevice* file;
  102. +   // first try gzip compression, because projects can be gzipped and end with .lml
  103. +   if (filename.endsWith(QLatin1String(".lml"), Qt::CaseInsensitive))
  104. +       file = new KCompressionDevice(filename,KFilterDev::compressionTypeForMimeType("application/x-gzip"));
  105. +   else    // opens filename using file ending
  106. +       file = new KFilterDev(filename);
  107. +
  108. +   if (!file)
  109. +       file = new QFile(filename);
  110. +
  111. +   if (!file->open(QIODevice::ReadOnly)) {
  112. +       qDebug() << "Could not open file for reading.";
  113. +       return QVariant();
  114. +   }
  115. +
  116. +   char c;
  117. +   bool rc = file->getChar(&c);
  118. +   if (!rc) {
  119. +       qDebug() << "The project file is empty.";
  120. +       file->close();
  121. +       delete file;
  122. +       return false;
  123. +   }
  124. +   file->seek(0);
  125. +
  126. +   //parse XML
  127. +   XmlStreamReader reader(file);
  128. +
  129. +   while (!(reader.isStartDocument() || reader.atEnd()))
  130. +       reader.readNext();
  131. +
  132. +   if (!(reader.atEnd())) {
  133. +       if (!reader.skipToNextTag())
  134. +           return false;
  135. +
  136. +       if (reader.name() == "project") {
  137. +           QString thumbnail = reader.attributes().value("thumbnail").toString();
  138. +
  139. +           thumbnail.prepend("data:image/jpg;base64,");
  140. +           qDebug() << "Return thumbnail " <<thumbnail;
  141. +           return QVariant(thumbnail);
  142. +       }
  143. +   }
  144. +
  145. +   return QVariant();
  146. +}
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top