[vlc-commits] [Git][videolan/vlc][master] 5 commits: qt/CoverGenerator: add size in generated file name

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Tue Nov 9 08:21:16 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
f3c22003 by Prince Gupta at 2021-11-08T19:25:09+00:00
qt/CoverGenerator: add size in generated file name

- - - - -
a5bdf3d1 by Prince Gupta at 2021-11-08T19:25:09+00:00
qt/CoverGenerator: add fileName()

- - - - -
359dea5a by Prince Gupta at 2021-11-08T19:25:09+00:00
qt/mlgenremodel: don't generate cover if already exist

- - - - -
c26e30ad by Prince Gupta at 2021-11-08T19:25:09+00:00
qt/mlgrouplistmodel: don't generate cover if already exist

- - - - -
1cd0c893 by Prince Gupta at 2021-11-08T19:25:09+00:00
qt/mlplaylistlistmodel: don't generate cover if already exist

- - - - -


5 changed files:

- modules/gui/qt/medialibrary/mlgenremodel.cpp
- modules/gui/qt/medialibrary/mlgrouplistmodel.cpp
- modules/gui/qt/medialibrary/mlplaylistlistmodel.cpp
- modules/gui/qt/util/covergenerator.cpp
- modules/gui/qt/util/covergenerator.hpp


Changes:

=====================================
modules/gui/qt/medialibrary/mlgenremodel.cpp
=====================================
@@ -143,6 +143,13 @@ QString MLGenreModel::getCover(MLGenre * genre) const
 
     generator->setDefaultThumbnail(":/noart_album.svg");
 
+    if (generator->cachedFileAvailable())
+    {
+        genre->setCover(generator->cachedFileURL());
+        generator->deleteLater();
+        return genre->getCover();
+    }
+
     // NOTE: We'll apply the new cover once it's loaded.
     connect(generator, &CoverGenerator::result, this, &MLGenreModel::onCover);
 


=====================================
modules/gui/qt/medialibrary/mlgrouplistmodel.cpp
=====================================
@@ -234,6 +234,13 @@ QString MLGroupListModel::getCover(MLGroup * group, int index) const
 
     generator->setDefaultThumbnail(":/noart_videoCover.svg");
 
+    if (generator->cachedFileAvailable())
+    {
+        group->setCover(generator->cachedFileURL());
+        generator->deleteLater();
+        return group->getCover();
+    }
+
     // NOTE: We'll apply the new thumbnail once it's loaded.
     connect(generator, &CoverGenerator::result, this, &MLGroupListModel::onCover);
 


=====================================
modules/gui/qt/medialibrary/mlplaylistlistmodel.cpp
=====================================
@@ -259,6 +259,13 @@ QString MLPlaylistListModel::getCover(MLPlaylist * playlist, int index) const
 
     generator->setPrefix(m_coverPrefix);
 
+    if (generator->cachedFileAvailable())
+    {
+        playlist->setCover(generator->cachedFileURL());
+        generator->deleteLater();
+        return playlist->getCover();
+    }
+
     // NOTE: We'll apply the new thumbnail once it's loaded.
     connect(generator, &CoverGenerator::result, this, &MLPlaylistListModel::onCover);
 


=====================================
modules/gui/qt/util/covergenerator.cpp
=====================================
@@ -113,6 +113,26 @@ CoverGenerator::CoverGenerator(vlc_medialibrary_t * ml, const MLItemId & itemId,
     m_prefix = prefix;
 }
 
+bool CoverGenerator::cachedFileAvailable() const
+{
+    return QFile::exists(fileName());
+}
+
+QString CoverGenerator::cachedFileURL() const
+{
+    return QUrl::fromLocalFile(fileName()).toString();
+}
+
+QString CoverGenerator::fileName() const
+{
+    QDir dir(config_GetUserDir(VLC_CACHE_DIR) + COVERGENERATOR_STORAGE);
+    return dir.absoluteFilePath(QString("%1_thumbnail_%2_%3x%4.jpg")
+                                .arg((m_prefix.isEmpty() ? getPrefix(m_id.type) : m_prefix)
+                                     , QString::number(m_id.id)
+                                     , QString::number(m_size.width())
+                                     , QString::number(m_size.height())));
+}
+
 //-------------------------------------------------------------------------------------------------
 // QRunnable implementation
 //-------------------------------------------------------------------------------------------------
@@ -127,18 +147,7 @@ QString CoverGenerator::execute() /* override */
 
     int64_t id = m_id.id;
 
-    QString fileName;
-
-    // NOTE: If we don't have a valid prefix we generate one based on the item type.
-    if (m_prefix.isEmpty())
-    {
-        m_prefix = getPrefix(type);
-    }
-
-    fileName = QString("%1_thumbnail_%2.jpg").arg(m_prefix).arg(id);
-
-    fileName = dir.absoluteFilePath(fileName);
-
+    QString fileName = this->fileName();
     if (dir.exists(fileName))
     {
         return QUrl::fromLocalFile(fileName).toString();


=====================================
modules/gui/qt/util/covergenerator.hpp
=====================================
@@ -78,10 +78,16 @@ public: // Interface
     // NOTE: This lets us enforce a specific prefix for the cover fileName.
     Q_INVOKABLE void setPrefix(const QString & prefix);
 
+    bool cachedFileAvailable() const;
+
+    QString cachedFileURL() const;
+
 public: // AsyncTask implementation
     QString execute() override;
 
 private: // Functions
+    QString fileName() const;
+
     void draw(QPainter & painter, const QStringList & fileNames, int countX, int countY);
 
     void drawImage(QPainter & painter, const QString & fileName, const QRect & rect);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/856f20a22e0136e180f58615de3721acb1afa1ba...1cd0c893a3d597871ca4a34d2c8c4bc146932470

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/856f20a22e0136e180f58615de3721acb1afa1ba...1cd0c893a3d597871ca4a34d2c8c4bc146932470
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list