Commit 15fa6e24 authored by Méven Car's avatar Méven Car
Browse files

Thumbnails: Refactor, Add ThumbnailProtocol::ensureDirsCreated

parent 01b8eb0f
Pipeline #64691 passed with stage
in 3 minutes and 8 seconds
...@@ -634,6 +634,18 @@ ThumbCreator* ThumbnailProtocol::getThumbCreator(const QString& plugin) ...@@ -634,6 +634,18 @@ ThumbCreator* ThumbnailProtocol::getThumbCreator(const QString& plugin)
return creator; return creator;
} }
void ThumbnailProtocol::ensureDirsCreated()
{
if (m_thumbBasePath.isEmpty()) {
m_thumbBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/");
QDir basePath(m_thumbBasePath);
basePath.mkpath("normal/");
QFile::setPermissions(basePath.absoluteFilePath("normal"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
basePath.mkpath("large/");
QFile::setPermissions(basePath.absoluteFilePath("large"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
}
}
bool ThumbnailProtocol::createSubThumbnail(QImage &thumbnail, const QString &filePath, bool ThumbnailProtocol::createSubThumbnail(QImage &thumbnail, const QString &filePath,
int segmentWidth, int segmentHeight) int segmentWidth, int segmentHeight)
{ {
...@@ -655,14 +667,7 @@ bool ThumbnailProtocol::createSubThumbnail(QImage &thumbnail, const QString &fil ...@@ -655,14 +667,7 @@ bool ThumbnailProtocol::createSubThumbnail(QImage &thumbnail, const QString &fil
md5.addData(fileUrl); md5.addData(fileUrl);
const QString thumbName = QString::fromLatin1(md5.result().toHex()).append(".png"); const QString thumbName = QString::fromLatin1(md5.result().toHex()).append(".png");
if (m_thumbBasePath.isEmpty()) { ensureDirsCreated();
m_thumbBasePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/thumbnails/");
QDir basePath(m_thumbBasePath);
basePath.mkpath("normal/");
QFile::setPermissions(basePath.absoluteFilePath("normal"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
basePath.mkpath("large/");
QFile::setPermissions(basePath.absoluteFilePath("large"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner);
}
QDir thumbPath(m_thumbBasePath); QDir thumbPath(m_thumbBasePath);
if ((segmentWidth <= 128) && (segmentHeight <= 128)) { if ((segmentWidth <= 128) && (segmentHeight <= 128)) {
......
...@@ -57,6 +57,8 @@ private: ...@@ -57,6 +57,8 @@ private:
void drawSubThumbnail(QPainter& p, QImage subThumbnail, int width, int height, void drawSubThumbnail(QPainter& p, QImage subThumbnail, int width, int height,
int xPos, int yPos, int frameWidth); int xPos, int yPos, int frameWidth);
private: private:
void ensureDirsCreated();
QString m_mimeType; QString m_mimeType;
int m_width; int m_width;
int m_height; int m_height;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment