static void storeThumbnailToDiskCache(const QString& path, const QImage& image) { LOG(path); KTemporaryFile tmp; tmp.setPrefix(path + ".gwenview.tmp"); tmp.setSuffix(".png"); if (!tmp.open()) { kWarning() << "Could not create a temporary file."; return; } if (!image.save(tmp.fileName(), "png")) { kWarning() << "Could not save thumbnail"; return; } KDE_rename(QFile::encodeName(tmp.fileName()), QFile::encodeName(path)); }
void RenameImagesWidget::slotNext() { QTreeWidgetItem* it = ui->m_listView->selectedItems().first(); if (!it) { slotAbort(); return; } BatchProcessImagesItem* item = static_cast<BatchProcessImagesItem*>(it); KUrl src; src.setPath(item->pathSrc()); KUrl dst = src.upUrl(); dst.addPath(item->text(2)); bool skip = false; bool overwrite = false; if (!m_overwriteAll) { KDE_struct_stat info; while (KDE_stat(QFile::encodeName(dst.toLocalFile()), &info) == 0) { if (m_autoSkip) { skip = true; break; } QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog(this, i18n("Rename File"), src.path(), dst.path(), KIO::RenameDialog_Mode(KIO::M_MULTI | KIO::M_OVERWRITE | KIO::M_SKIP)); int result = dlg->exec(); dst = dlg->newDestUrl(); delete dlg; switch (result) { case KIO::R_CANCEL: { slotAbort(); return; } case KIO::R_SKIP: { skip = true; break; } case KIO::R_AUTO_SKIP: { m_autoSkip = true; skip = true; break; } case KIO::R_OVERWRITE: { overwrite = true; break; } case KIO::R_OVERWRITE_ALL: { m_overwriteAll = true; overwrite = true; break; } default: break; } if (skip || overwrite) break; } } if (skip) { item->changeResult(i18nc("batch process result", "Skipped")); } else { // Get the src info KIPIPlugins::KPImageInfo srcInfo(src); if (KDE_rename(QFile::encodeName(src.toLocalFile()), QFile::encodeName(dst.toLocalFile())) == 0) { // Rename XMP sidecar file KIPIPlugins::KPMetadata::moveSidecar(src, dst); srcInfo.setName(dst.fileName()); item->changeResult(i18nc("batch process result", "OK")); } else { item->changeResult(i18nc("batch process result", "Failed")); } } m_progress->progressBar()->setValue(m_progress->progressBar()->value() + 1); it = ui->m_listView->itemBelow(it); if (it) { ui->m_listView->setCurrentItem(it); ui->m_listView->scrollToItem(it); m_timer->setSingleShot(true); m_timer->start(0); } }
void Task::run() { if (d->cancel) return; QDateTime dt = d->itemsMap.value(d->url); if (!dt.isValid()) return; emit signalProcessStarted(d->url); bool metadataChanged = d->settings.updEXIFModDate || d->settings.updEXIFOriDate || d->settings.updEXIFDigDate || d->settings.updEXIFThmDate || d->settings.updIPTCDate || d->settings.updXMPDate; int status = MyImageList::NOPROCESS_ERROR; if (metadataChanged) { bool ret = true; KPMetadata meta; ret &= meta.load(d->url.path()); if (ret) { if (meta.canWriteExif(d->url.path())) { if (d->settings.updEXIFModDate) { ret &= meta.setExifTagString("Exif.Image.DateTime", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } if (d->settings.updEXIFOriDate) { ret &= meta.setExifTagString("Exif.Photo.DateTimeOriginal", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } if (d->settings.updEXIFDigDate) { ret &= meta.setExifTagString("Exif.Photo.DateTimeDigitized", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } if (d->settings.updEXIFThmDate) { ret &= meta.setExifTagString("Exif.Image.PreviewDateTime", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } } else if (d->settings.updEXIFModDate || d->settings.updEXIFOriDate || d->settings.updEXIFDigDate || d->settings.updEXIFThmDate) { ret = false; } if (d->settings.updIPTCDate) { if (meta.canWriteIptc(d->url.path())) { ret &= meta.setIptcTagString("Iptc.Application2.DateCreated", dt.date().toString(Qt::ISODate)); ret &= meta.setIptcTagString("Iptc.Application2.TimeCreated", dt.time().toString(Qt::ISODate)); } else { ret = false; } } if (d->settings.updXMPDate) { if (meta.supportXmp() && meta.canWriteXmp(d->url.path())) { ret &= meta.setXmpTagString("Xmp.exif.DateTimeOriginal", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.photoshop.DateCreated", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.tiff.DateTime", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.xmp.CreateDate", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.xmp.MetadataDate", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); ret &= meta.setXmpTagString("Xmp.xmp.ModifyDate", dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii()); } else { ret = false; } } ret &= meta.save(d->url.path()); if (!ret) { kDebug() << "Failed to update metadata in file " << d->url.fileName(); } } else { kDebug() << "Failed to load metadata from file " << d->url.fileName(); } if (!ret) { status |= MyImageList::META_TIME_ERROR; } } if (d->settings.updFileModDate) { // Since QFileInfo does not support timestamp updates, see Qt suggestion #79427 at // http://www.qtsoftware.com/developer/task-tracker/index_html?id=79427&method=entry // we have to use the utime() system call. utimbuf times; times.actime = QDateTime::currentDateTime().toTime_t(); times.modtime = dt.toTime_t(); if (utime(QFile::encodeName(d->url.toLocalFile()).constData(), ×) != 0) { status |= MyImageList::FILE_TIME_ERROR; } } if (d->settings.updFileName) { bool ret = true; KUrl newUrl = ActionThread::newUrl(d->url, dt); if (KDE_rename(QFile::encodeName(d->url.toLocalFile()), QFile::encodeName(newUrl.toLocalFile())) != 0) ret = false; ret &= KPMetadata::moveSidecar(d->url, newUrl); if (!ret) status |= MyImageList::FILE_NAME_ERROR; } if (d->settings.updAppDate) { KPImageInfo info(d->url); QDateTime dt = d->itemsMap.value(d->url); if (dt.isValid()) info.setDate(dt); } emit signalProcessEnded(d->url, status); }
int KMFolderIndex::writeIndex( bool createEmptyIndex ) { QString tempName; QString indexName; mode_t old_umask; indexName = indexLocation(); tempName = indexName + ".temp"; { int result = unlink( QFile::encodeName( tempName ) ); if ( ! ( result == 0 || (result == -1 && errno == ENOENT ) ) ) return errno; } // We touch the folder, otherwise the index is regenerated, if KMail is // running, while the clock switches from daylight savings time to normal time utime( QFile::encodeName( QDir::toNativeSeparators(location()) ), 0 ); old_umask = umask( 077 ); FILE *tmpIndexStream = KDE_fopen( QFile::encodeName( tempName ), "w" ); //kDebug( KMKernel::storageDebug() ) << "KDE_fopen(tempName=" << tempName << ", \"w\") == tmpIndexStream == " << tmpIndexStream; umask( old_umask ); if ( !tmpIndexStream ) { return errno; } fprintf(tmpIndexStream, "# KMail-Index V%d\n", INDEX_VERSION); // Header quint32 byteOrder = 0x12345678; quint32 sizeOfLong = sizeof(long); quint32 header_length = sizeof(byteOrder)+sizeof(sizeOfLong); char pad_char = '\0'; fwrite(&pad_char, sizeof(pad_char), 1, tmpIndexStream); fwrite(&header_length, sizeof(header_length), 1, tmpIndexStream); // Write header fwrite(&byteOrder, sizeof(byteOrder), 1, tmpIndexStream); fwrite(&sizeOfLong, sizeof(sizeOfLong), 1, tmpIndexStream); off_t nho = KDE_ftell(tmpIndexStream); int fError = 0; if ( !createEmptyIndex ) { fError = writeMessages( 0/*all*/, false /* !flush */, tmpIndexStream ); /* moved to writeMessages() KMMsgBase* msgBase; int len; const uchar *buffer = 0; for (unsigned int i=0; i<mMsgList.high(); i++) { if (!(msgBase = mMsgList.at(i))) continue; buffer = msgBase->asIndexString(len); fwrite(&len,sizeof(len), 1, tmpIndexStream); off_t tmp = KDE_ftell(tmpIndexStream); msgBase->setIndexOffset(tmp); msgBase->setIndexLength(len); if(fwrite(buffer, len, 1, tmpIndexStream) != 1) kDebug() << "Whoa!"; }*/ } fError |= ferror( tmpIndexStream ); if( fError != 0 ) { fclose( tmpIndexStream ); //kDebug( KMKernel::storageDebug() ) << "fclose(tmpIndexStream = " << tmpIndexStream << ")"; return fError; } if( ( fflush( tmpIndexStream ) != 0 ) || ( fsync( fileno( tmpIndexStream ) ) != 0 ) ) { int errNo = errno; fclose( tmpIndexStream ); kWarning() << "fflush() or fsync() failed; fclose(tmpIndexStream = " << tmpIndexStream << ")"; return errNo; } //kDebug( KMKernel::storageDebug() ) << "fclose(tmpIndexStream = " << tmpIndexStream << ")"; if( fclose( tmpIndexStream ) != 0 ) { kWarning() << "fclose() failed"; return errno; } #ifdef Q_WS_WIN if (mIndexStream) { // close before renaming // neither this fixes windows port: // if ( !updateIndexStreamPtr() ) // return 1; bool ok = fclose( mIndexStream ) == 0; //kDebug( KMKernel::storageDebug() ) << "fclose(mIndexStream = " << mIndexStream << ")"; mIndexStream = 0; if ( !ok ) { kWarning() << "fclose() failed"; return errno; } } #endif if ( KDE_rename(QFile::encodeName(tempName), QFile::encodeName(indexName)) != 0 ) return errno; mHeaderOffset = nho; #ifndef Q_WS_WIN if (mIndexStream) { fclose(mIndexStream); //kDebug( KMKernel::storageDebug() ) << "fclose(mIndexStream = " << mIndexStream << ")"; } #endif if ( createEmptyIndex ) return 0; mIndexStream = KDE_fopen(QFile::encodeName(indexName), "r+"); // index file //kDebug( KMKernel::storageDebug() ) << "KDE_fopen(indexName=" << indexName << ", \"r+\") == mIndexStream == " << mIndexStream; assert( mIndexStream ); #ifndef Q_WS_WIN fcntl(fileno(mIndexStream), F_SETFD, FD_CLOEXEC); #endif if ( !updateIndexStreamPtr() ) return 1; if ( 0 != writeFolderIdsFile() ) return 1; setDirty( false ); return 0; }