File indexing completed on 2024-04-28 08:50:25
0001 /* This file is part of the KDE project 0002 0003 SPDX-FileCopyrightText: 2001, 2003 Lukas Tinkl <lukas@kde.org> 0004 SPDX-FileCopyrightText: Andreas Schlapbach <schlpbch@iam.unibe.ch> 0005 0006 SPDX-License-Identifier: LGPL-2.0-only 0007 */ 0008 0009 #include "imgalleryplugin.h" 0010 0011 #include <QTextStream> 0012 #include <QFile> 0013 #include <QDateTime> 0014 #include <QPixmap> 0015 #include <QImage> 0016 #if QT_VERSION_MAJOR < 6 0017 #include <QTextCodec> 0018 #endif 0019 #include <QApplication> 0020 #include <QDesktopServices> 0021 #include <QImageReader> 0022 #include <QMimeDatabase> 0023 #include <QMimeType> 0024 #include <QPushButton> 0025 #include <QProgressDialog> 0026 0027 #include <klocalizedstring.h> 0028 #include <kmessagebox.h> 0029 #include <kpluginfactory.h> 0030 #include <kactioncollection.h> 0031 0032 #include <kparts/part.h> 0033 0034 #include "imgallerydialog.h" 0035 #include "imgallery_debug.h" 0036 0037 K_PLUGIN_CLASS_WITH_JSON(KImGalleryPlugin, "kimgalleryplugin.json") 0038 0039 // Eliminate lots of deprecation warnings with Qt 5.15. 0040 // Using a macro to redefine well known symbols is not good practice, but 0041 // the alternative is lots of QT_VERSION_CHECK conditionals everywhere. 0042 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) 0043 #define endl Qt::endl 0044 #endif 0045 0046 static QString directory(const QUrl &url) { 0047 return url.adjusted(QUrl::StripTrailingSlash).adjusted(QUrl::RemoveFilename).toLocalFile(); 0048 } 0049 0050 KImGalleryPlugin::KImGalleryPlugin(QObject *parent, const QVariantList &) 0051 : KonqParts::Plugin(parent), m_commentMap(nullptr) 0052 { 0053 QAction *a = actionCollection()->addAction(QStringLiteral("create_img_gallery")); 0054 a->setText(i18n("&Create Image Gallery...")); 0055 a->setIcon(QIcon::fromTheme(QStringLiteral("imagegallery"))); 0056 actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::Key_I)); 0057 connect(a, &QAction::triggered, this, &KImGalleryPlugin::slotExecute); 0058 } 0059 0060 void KImGalleryPlugin::slotExecute() 0061 { 0062 m_progressDlg = nullptr; 0063 if (!parent()) { 0064 KMessageBox::error(nullptr, i18n("Could not create the plugin, please report a bug.")); 0065 return; 0066 } 0067 m_part = qobject_cast<KParts::ReadOnlyPart *>(parent()); 0068 0069 if (!m_part || !m_part->url().isLocalFile()) { //TODO support remote URLs too? 0070 KMessageBox::error(m_part->widget(), i18n("Creating an image gallery works only on local folders.")); 0071 return; 0072 } 0073 0074 QString path = m_part->url().adjusted(QUrl::StripTrailingSlash).toLocalFile() + '/'; 0075 m_configDlg = new KIGPDialog(m_part->widget(), path); 0076 0077 if (m_configDlg->exec() == QDialog::Accepted) { 0078 qCDebug(IMAGEGALLERY_LOG) << "dialog is ok"; 0079 m_configDlg->writeConfig(); 0080 m_copyFiles = m_configDlg->copyOriginalFiles(); 0081 m_recurseSubDirectories = m_configDlg->recurseSubDirectories(); 0082 m_useCommentFile = m_configDlg->useCommentFile(); 0083 m_imagesPerRow = m_configDlg->getImagesPerRow(); 0084 0085 QUrl url(m_configDlg->getImageUrl()); 0086 if (!url.isEmpty() && url.isValid()) { 0087 m_progressDlg = new QProgressDialog(m_part->widget()); 0088 connect(m_progressDlg, &QProgressDialog::canceled, this, &KImGalleryPlugin::slotCancelled); 0089 0090 m_progressDlg->setLabelText(i18n("Creating thumbnails")); 0091 QPushButton *button = new QPushButton(m_progressDlg); 0092 KGuiItem::assign(button, KStandardGuiItem::cancel()); 0093 m_progressDlg->setCancelButton(button); 0094 m_cancelled = false; 0095 m_progressDlg->show(); 0096 if (createHtml(url, m_part->url().path(), m_configDlg->recursionLevel() > 0 ? m_configDlg->recursionLevel() + 1 : 0, m_configDlg->getImageFormat())) { 0097 QDesktopServices::openUrl(url); // Open a browser to show the result 0098 } else { 0099 deleteCancelledGallery(url, m_part->url().path(), m_configDlg->recursionLevel() > 0 ? m_configDlg->recursionLevel() + 1 : 0, m_configDlg->getImageFormat()); 0100 } 0101 } 0102 } 0103 delete m_progressDlg; 0104 } 0105 0106 bool KImGalleryPlugin::createDirectory(const QDir &dir, const QString &imgGalleryDir, const QString &dirName) 0107 { 0108 QDir thumb_dir(dir); 0109 0110 if (!thumb_dir.exists()) { 0111 thumb_dir.setPath(imgGalleryDir); 0112 if (!(thumb_dir.mkdir(dirName/*, false*/))) { 0113 KMessageBox::error(m_part->widget(), i18n("Could not create folder: %1", thumb_dir.path())); 0114 return false; 0115 } else { 0116 thumb_dir.setPath(imgGalleryDir + '/' + dirName + '/'); 0117 return true; 0118 } 0119 } else { 0120 return true; 0121 } 0122 } 0123 0124 void KImGalleryPlugin::createHead(QTextStream &stream) 0125 { 0126 const QString chsetName = 0127 //TODO KF6: in Qt6, QTextCodec doesn't exist anymore and its "replacement", QStringConverter, only supports a 0128 //small number of encodigs. For the time being, use the default (UTF-8). 0129 #if QT_VERSION_MAJOR < 6 0130 QTextCodec::codecForLocale()->name(); 0131 #else 0132 QStringLiteral("UTF-8"); 0133 #endif 0134 0135 stream << "<?xml version=\"1.0\" encoding=\"" + chsetName + "\" ?>" << endl; 0136 stream << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">" << endl; 0137 stream << "<html xmlns=\"http://www.w3.org/1999/xhtml\">" << endl; 0138 stream << "<head>" << endl; 0139 stream << "<title>" << m_configDlg->getTitle().toHtmlEscaped() << "</title>" << endl; 0140 stream << "<meta http-equiv=\"content-type\" content=\"text/html; charset=" << chsetName << "\"/>" << endl; 0141 stream << "<meta name=\"GENERATOR\" content=\"KDE Konqueror KImgallery plugin version " KDE_VERSION_STRING "\"/>" << endl; 0142 createCSSSection(stream); 0143 stream << "</head>" << endl; 0144 } 0145 0146 void KImGalleryPlugin::createCSSSection(QTextStream &stream) 0147 { 0148 const QString backgroundColor = m_configDlg->getBackgroundColor().name(); 0149 const QString foregroundColor = m_configDlg->getForegroundColor().name(); 0150 //adding a touch of style 0151 stream << "<style type='text/css'>\n"; 0152 stream << "BODY {color: " << foregroundColor << "; background: " << backgroundColor << ";" << endl; 0153 stream << " font-family: " << m_configDlg->getFontName() << ", sans-serif;" << endl; 0154 stream << " font-size: " << m_configDlg->getFontSize() << "pt; margin: 8%; }" << endl; 0155 stream << "H1 {color: " << foregroundColor << ";}" << endl; 0156 stream << "TABLE {text-align: center; margin-left: auto; margin-right: auto;}" << endl; 0157 stream << "TD { color: " << foregroundColor << "; padding: 1em}" << endl; 0158 stream << "IMG { border: 1px solid " << foregroundColor << "; }" << endl; 0159 stream << "</style>" << endl; 0160 } 0161 0162 QString KImGalleryPlugin::extension(const QString &imageFormat) 0163 { 0164 if (imageFormat == QLatin1String("PNG")) { 0165 return QStringLiteral(".png"); 0166 } 0167 if (imageFormat == QLatin1String("JPEG")) { 0168 return QStringLiteral(".jpg"); 0169 } 0170 Q_ASSERT(false); 0171 return QString(); 0172 } 0173 0174 void KImGalleryPlugin::createBody(QTextStream &stream, const QString &sourceDirName, const QStringList &subDirList, 0175 const QDir &imageDir, const QUrl &url, const QString &imageFormat) 0176 { 0177 int numOfImages = imageDir.count(); 0178 const QString imgGalleryDir = directory(url); 0179 const QString today(QLocale().toString(QDate::currentDate())); 0180 0181 stream << "<body>\n<h1>" << m_configDlg->getTitle().toHtmlEscaped() << "</h1><p>" << endl; 0182 stream << i18n("<i>Number of images</i>: %1", numOfImages) << "<br/>" << endl; 0183 stream << i18n("<i>Created on</i>: %1", today) << "</p>" << endl; 0184 0185 stream << "<hr/>" << endl; 0186 0187 if (m_recurseSubDirectories && subDirList.count() > 2) { //subDirList.count() is always >= 2 because of the "." and ".." directories 0188 stream << i18n("<i>Subfolders</i>:") << "<br>" << endl; 0189 for (QStringList::ConstIterator it = subDirList.constBegin(); it != subDirList.constEnd(); it++) { 0190 if (*it == QLatin1String(".") || *it == QLatin1String("..")) { 0191 continue; //disregard the "." and ".." directories 0192 } 0193 stream << "<a href=\"" << *it << "/" << url.fileName() 0194 << "\">" << *it << "</a><br>" << endl; 0195 } 0196 stream << "<hr/>" << endl; 0197 } 0198 0199 stream << "<table>" << endl; 0200 0201 //table with images 0202 int imgIndex; 0203 QFileInfo imginfo; 0204 QPixmap imgProp; 0205 for (imgIndex = 0; !m_cancelled && (imgIndex < numOfImages);) { 0206 stream << "<tr>" << endl; 0207 0208 for (int col = 0; !m_cancelled && (col < m_imagesPerRow) && (imgIndex < numOfImages); col++) { 0209 const QString imgName = imageDir[imgIndex]; 0210 0211 if (m_copyFiles) { 0212 stream << "<td align='center'>\n<a href=\"images/" << imgName << "\">"; 0213 } else { 0214 stream << "<td align='center'>\n<a href=\"" << imgName << "\">"; 0215 } 0216 0217 if (createThumb(imgName, sourceDirName, imgGalleryDir, imageFormat)) { 0218 const QString imgPath("thumbs/" + imgName + extension(imageFormat)); 0219 stream << "<img src=\"" << imgPath << "\" width=\"" << m_imgWidth << "\" "; 0220 stream << "height=\"" << m_imgHeight << "\" alt=\"" << imgPath << "\"/>"; 0221 m_progressDlg->setLabelText(i18n("Created thumbnail for: \n%1", imgName)); 0222 } else { 0223 qCDebug(IMAGEGALLERY_LOG) << "Creating thumbnail for " << imgName << " failed"; 0224 m_progressDlg->setLabelText(i18n("Creating thumbnail for: \n%1\n failed", imgName)); 0225 } 0226 stream << "</a>" << endl; 0227 0228 if (m_configDlg->printImageName()) { 0229 stream << "<div>" << imgName << "</div>" << endl; 0230 } 0231 0232 if (m_configDlg->printImageProperty()) { 0233 imgProp.load(imageDir.absoluteFilePath(imgName)); 0234 stream << "<div>" << imgProp.width() << " x " << imgProp.height() << "</div>" << endl; 0235 } 0236 0237 if (m_configDlg->printImageSize()) { 0238 imginfo.setFile(imageDir, imgName); 0239 stream << "<div>(" << (imginfo.size() / 1024) << " " << i18n("KiB") << ")" << "</div>" << endl; 0240 } 0241 0242 if (m_useCommentFile) { 0243 QString imgComment = (*m_commentMap)[imgName]; 0244 stream << "<div>" << imgComment.toHtmlEscaped() << "</div>" << endl; 0245 } 0246 stream << "</td>" << endl; 0247 0248 m_progressDlg->setMaximum(numOfImages); 0249 m_progressDlg->setValue(imgIndex); 0250 qApp->processEvents(); 0251 imgIndex++; 0252 } 0253 stream << "</tr>" << endl; 0254 } 0255 //close the HTML 0256 stream << "</table>\n</body>\n</html>" << endl; 0257 } 0258 0259 bool KImGalleryPlugin::createHtml(const QUrl &url, const QString &sourceDirName, int recursionLevel, const QString &imageFormat) 0260 { 0261 if (m_cancelled) { 0262 return false; 0263 } 0264 0265 if (!parent() || !parent()->inherits("DolphinPart")) { 0266 return false; 0267 } 0268 0269 QStringList subDirList; 0270 if (m_recurseSubDirectories && (recursionLevel >= 0)) { //recursionLevel == 0 means endless 0271 QDir toplevel_dir = QDir(sourceDirName); 0272 toplevel_dir.setFilter(QDir::Dirs | QDir::Readable | QDir::Writable); 0273 subDirList = toplevel_dir.entryList(); 0274 0275 for (QStringList::ConstIterator it = subDirList.constBegin(); it != subDirList.constEnd() && !m_cancelled; it++) { 0276 const QString currentDir = *it; 0277 if (currentDir == QLatin1String(".") || currentDir == QLatin1String("..")) { 0278 continue; //disregard the "." and ".." directories 0279 } 0280 QDir subDir = QDir(directory(url) + '/' + currentDir); 0281 if (!subDir.exists()) { 0282 subDir.setPath(directory(url)); 0283 if (!(subDir.mkdir(currentDir/*, false*/))) { 0284 KMessageBox::error(m_part->widget(), i18n("Could not create folder: %1", subDir.path())); 0285 continue; 0286 } else { 0287 subDir.setPath(directory(url) + '/' + currentDir); 0288 } 0289 } 0290 if (!createHtml(QUrl::fromLocalFile(subDir.path() + '/' + url.fileName()), sourceDirName + '/' + currentDir, 0291 recursionLevel > 1 ? recursionLevel - 1 : 0, imageFormat)) { 0292 return false; 0293 } 0294 } 0295 } 0296 0297 if (m_useCommentFile) { 0298 loadCommentFile(); 0299 } 0300 0301 qCDebug(IMAGEGALLERY_LOG) << "sourceDirName: " << sourceDirName; 0302 0303 QMimeDatabase db; 0304 QStringList imageNameFilters; 0305 const QList<QByteArray> &mimeNames = QImageReader::supportedMimeTypes(); 0306 for (const QByteArray &mimeName : mimeNames) 0307 { 0308 const QMimeType mimeType = db.mimeTypeForName(mimeName); 0309 imageNameFilters.append(mimeType.globPatterns()); 0310 } 0311 0312 QDir imageDir(sourceDirName, QString(), 0313 QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::Readable); 0314 imageDir.setNameFilters(imageNameFilters); 0315 0316 const QString imgGalleryDir = directory(url); 0317 qCDebug(IMAGEGALLERY_LOG) << "imgGalleryDir: " << imgGalleryDir; 0318 0319 // Create the "thumbs" subdirectory if necessary 0320 QDir thumb_dir(imgGalleryDir + QLatin1String("/thumbs/")); 0321 if (createDirectory(thumb_dir, imgGalleryDir, QStringLiteral("thumbs")) == false) { 0322 return false; 0323 } 0324 0325 // Create the "images" subdirectory if necessary 0326 QDir images_dir(imgGalleryDir + QLatin1String("/images/")); 0327 if (m_copyFiles) { 0328 if (createDirectory(images_dir, imgGalleryDir, QStringLiteral("images")) == false) { 0329 return false; 0330 } 0331 } 0332 0333 QFile file(url.path()); 0334 qCDebug(IMAGEGALLERY_LOG) << "url.path(): " << url.path() << ", thumb_dir: " << thumb_dir.path() 0335 << ", imageDir: " << imageDir.path(); 0336 0337 if (imageDir.exists() && file.open(QIODevice::WriteOnly)) { 0338 QTextStream stream(&file); 0339 //TODO KF6: in Qt6, QTextCodec doesn't exist anymore and its "replacement", QStringConverter, only supports a 0340 //small number of encodigs. For the time being, use the default (UTF-8). 0341 #if QT_VERSION_MAJOR < 6 0342 stream.setCodec(QTextCodec::codecForLocale()); 0343 #endif 0344 0345 createHead(stream); 0346 createBody(stream, sourceDirName, subDirList, imageDir, url, imageFormat); //ugly 0347 0348 file.close(); 0349 0350 return !m_cancelled; 0351 0352 } else { 0353 QString path = url.toLocalFile(); 0354 if (!path.endsWith("/")) { 0355 path += '/'; 0356 } 0357 KMessageBox::error(m_part->widget(), i18n("Could not open file: %1", path)); 0358 return false; 0359 } 0360 } 0361 0362 void KImGalleryPlugin::deleteCancelledGallery(const QUrl &url, const QString &sourceDirName, int recursionLevel, const QString &imageFormat) 0363 { 0364 if (m_recurseSubDirectories && (recursionLevel >= 0)) { 0365 QStringList subDirList; 0366 QDir toplevel_dir = QDir(sourceDirName); 0367 toplevel_dir.setFilter(QDir::Dirs); 0368 subDirList = toplevel_dir.entryList(); 0369 0370 for (QStringList::ConstIterator it = subDirList.constBegin(); it != subDirList.constEnd(); it++) { 0371 if (*it == QLatin1String(".") || *it == QLatin1String("..") || *it == QLatin1String("thumbs") || (m_copyFiles && *it == QLatin1String("images"))) { 0372 continue; //disregard the "." and ".." directories 0373 } 0374 deleteCancelledGallery(QUrl::fromLocalFile(directory(url) + '/' + *it + '/' + url.fileName()), 0375 sourceDirName + '/' + *it, 0376 recursionLevel > 1 ? recursionLevel - 1 : 0, imageFormat); 0377 } 0378 } 0379 0380 const QString imgGalleryDir = directory(url); 0381 QDir thumb_dir(imgGalleryDir + QLatin1String("/thumbs/")); 0382 QDir images_dir(imgGalleryDir + QLatin1String("/images/")); 0383 QDir imageDir(sourceDirName, QStringLiteral("*.png *.PNG *.gif *.GIF *.jpg *.JPG *.jpeg *.JPEG *.bmp *.BMP"), 0384 QDir::Name | QDir::IgnoreCase, QDir::Files | QDir::Readable); 0385 QFile file(url.path()); 0386 0387 // Remove the image file .. 0388 file.remove(); 0389 // ..all the thumbnails .. 0390 for (uint i = 0; i < imageDir.count(); i++) { 0391 const QString imgName = imageDir[i]; 0392 const QString imgNameFormat = imgName + extension(imageFormat); 0393 bool isRemoved = thumb_dir.remove(imgNameFormat); 0394 qCDebug(IMAGEGALLERY_LOG) << "removing: " << thumb_dir.path() << "/" << imgNameFormat << "; " << isRemoved; 0395 } 0396 // ..and the thumb directory 0397 thumb_dir.rmdir(thumb_dir.path()); 0398 0399 // ..and the images directory if images were to be copied 0400 if (m_copyFiles) { 0401 for (uint i = 0; i < imageDir.count(); i++) { 0402 const QString imgName = imageDir[i]; 0403 bool isRemoved = images_dir.remove(imgName); 0404 qCDebug(IMAGEGALLERY_LOG) << "removing: " << images_dir.path() << "/" << imgName << "; " << isRemoved; 0405 } 0406 images_dir.rmdir(images_dir.path()); 0407 } 0408 } 0409 0410 void KImGalleryPlugin::loadCommentFile() 0411 { 0412 QFile file(m_configDlg->getCommentFile()); 0413 if (file.open(QIODevice::ReadOnly)) { 0414 qCDebug(IMAGEGALLERY_LOG) << "File opened."; 0415 0416 QTextStream *m_textStream = new QTextStream(&file); 0417 0418 //TODO KF6: in Qt6, QTextCodec doesn't exist anymore and its "replacement", QStringConverter, only supports a 0419 //small number of encodigs. For the time being, use the default (UTF-8). 0420 #if QT_VERSION_MAJOR < 6 0421 m_textStream->setCodec(QTextCodec::codecForLocale()); 0422 #endif 0423 0424 delete m_commentMap; 0425 m_commentMap = new CommentMap; 0426 0427 QString picName, picComment, curLine, curLineStripped; 0428 while (!m_textStream->atEnd()) { 0429 curLine = m_textStream->readLine(); 0430 curLineStripped = curLine.trimmed(); 0431 // Lines starting with '#' are comment 0432 if (!(curLineStripped.isEmpty()) && !curLineStripped.startsWith(QLatin1String("#"))) { 0433 if (curLineStripped.endsWith(QLatin1String(":"))) { 0434 picComment.clear(); 0435 picName = curLineStripped.left(curLineStripped.length() - 1); 0436 qCDebug(IMAGEGALLERY_LOG) << "picName: " << picName; 0437 } else { 0438 do { 0439 //qCDebug(IMAGEGALLERY_LOG) << "picComment"; 0440 picComment += curLine + '\n'; 0441 curLine = m_textStream->readLine(); 0442 } while (!m_textStream->atEnd() && !(curLine.trimmed().isEmpty()) && 0443 !curLine.trimmed().startsWith(QLatin1String("#"))); 0444 //qCDebug(IMAGEGALLERY_LOG) << "Pic comment: " << picComment; 0445 m_commentMap->insert(picName, picComment); 0446 } 0447 } 0448 } 0449 CommentMap::ConstIterator it; 0450 for (it = m_commentMap->constBegin(); it != m_commentMap->constEnd(); ++it) { 0451 qCDebug(IMAGEGALLERY_LOG) << "picName: " << it.key() << ", picComment: " << it.value(); 0452 } 0453 file.close(); 0454 qCDebug(IMAGEGALLERY_LOG) << "File closed."; 0455 delete m_textStream; 0456 } else { 0457 KMessageBox::error(m_part->widget(), i18n("Could not open file: %1", m_configDlg->getCommentFile())); 0458 m_useCommentFile = false; 0459 } 0460 } 0461 0462 bool KImGalleryPlugin::createThumb(const QString &imgName, const QString &sourceDirName, 0463 const QString &imgGalleryDir, const QString &imageFormat) 0464 { 0465 QImage img; 0466 const QString pixPath = sourceDirName + QLatin1String("/") + imgName; 0467 0468 if (m_copyFiles) { 0469 QFile::copy(pixPath, imgGalleryDir + QLatin1String("/images/") + imgName); 0470 } 0471 0472 const QString imgNameFormat = imgName + extension(imageFormat); 0473 const QString thumbDir = imgGalleryDir + QLatin1String("/thumbs/"); 0474 int extent = m_configDlg->getThumbnailSize(); 0475 0476 // this code is stolen from kdebase/kioslave/thumbnail/imagecreator.cpp 0477 // (c) 2000 gis and malte 0478 0479 m_imgWidth = 120; // Setting the size of the images is 0480 m_imgHeight = 90; // required to generate faster 'loading' pages 0481 if (img.load(pixPath)) { 0482 int w = img.width(), h = img.height(); 0483 // scale to pixie size 0484 // qCDebug(IMAGEGALLERY_LOG) << "w: " << w << " h: " << h; 0485 // Resizing if to big 0486 if (w > extent || h > extent) { 0487 if (w > h) { 0488 h = (int)((double)(h * extent) / w); 0489 if (h == 0) { 0490 h = 1; 0491 } 0492 w = extent; 0493 Q_ASSERT(h <= extent); 0494 } else { 0495 w = (int)((double)(w * extent) / h); 0496 if (w == 0) { 0497 w = 1; 0498 } 0499 h = extent; 0500 Q_ASSERT(w <= extent); 0501 } 0502 const QImage scaleImg(img.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); 0503 if (scaleImg.width() != w || scaleImg.height() != h) { 0504 qCDebug(IMAGEGALLERY_LOG) << "Resizing failed. Aborting."; 0505 return false; 0506 } 0507 img = scaleImg; 0508 if (m_configDlg->colorDepthSet() == true) { 0509 QImage::Format format; 0510 switch (m_configDlg->getColorDepth()) { 0511 case 1: 0512 format = QImage::Format_Mono; 0513 break; 0514 case 8: 0515 format = QImage::Format_Indexed8; 0516 break; 0517 case 16: 0518 format = QImage::Format_RGB16; 0519 break; 0520 case 32: 0521 default: 0522 format = QImage::Format_RGB32; 0523 break; 0524 } 0525 0526 const QImage depthImg(img.convertToFormat(format)); 0527 img = depthImg; 0528 } 0529 } 0530 qCDebug(IMAGEGALLERY_LOG) << "Saving thumbnail to: " << thumbDir + imgNameFormat; 0531 if (!img.save(thumbDir + imgNameFormat, imageFormat.toLatin1().constData())) { 0532 qCDebug(IMAGEGALLERY_LOG) << "Saving failed. Aborting."; 0533 return false; 0534 } 0535 m_imgWidth = w; 0536 m_imgHeight = h; 0537 return true; 0538 } 0539 return false; 0540 } 0541 0542 void KImGalleryPlugin::slotCancelled() 0543 { 0544 m_cancelled = true; 0545 } 0546 0547 #include "imgalleryplugin.moc"