1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/*
This Program was written by Eric Baudach <Eric.Baudach@web.de>
and is licensed under the GPL version 3 or newer versions of GPL.
<Copyright (C) 2010-2011 Eric Baudach>
*/
#include "threadb.h"
#include "widget.h"
threadb::threadb(QWidget *parent) :
QThread(parent)
{
QObject::moveToThread(this);
}
void threadb::sleeping(int sec){
this->sleep(sec);
}
void threadb::FileAdded(const QStringList & Files){
QImage image = QImage();
const QImage & refimage = image;
if(!shouldIStop) {
const int & reflenght = Files.length();
for(int i = 0; i < reflenght; i++) {
const QString & reffile = Files.at(i);
if(fileschanged == true) {
i = reflenght -1;
}
QString fileDir = QFileInfo(reffile).absolutePath();
QString filename = QFileInfo(reffile).fileName();
QString thumb = fileDir % "/.thumb_" % filename;
if(!QFile(thumb).exists()) {
while(IShouldSleep == true) {
this->sleep(2);
}
mutex.lock();
try {
image = QImage(reffile).scaled(80, 80, Qt::KeepAspectRatio, Qt::SmoothTransformation);
} catch (...) {
qDebug() << reffile << " couldn't be loaded!";
i++;
}
const QStringList & refFiles = Files;
if(fileschanged == true) {
i = reflenght -1;
}
if(!image.isNull()) {
mutex.unlock();
Q_EMIT valueChanged(refimage,refFiles[i]);
Q_EMIT(ImageSaved(true));
if(!refimage.save(thumb, 0, 100)) {
qDebug() << thumb << " couldn't be saved!";
}
if(!image.isNull()) {
mutex.lock();
image = QImage();
mutex.unlock();
}
} else {
mutex.unlock();
qDebug() << "Failed to load " << refFiles[i];
}
} else {
image = QImage();
Q_EMIT valueChanged(refimage,reffile);
}
}
Q_EMIT(ImageSaved(false));
} else {
Q_EMIT(IShouldStop());
}
}
void threadb::run()
{
exec();
}
|