void * bg_db_get_thumbnail(bg_db_t * db, int64_t id, int max_width, int max_height, const char * mimetype) { browse_t b; int64_t thumb_id; if((thumb_id = cache_get(&db->th_cache, id, max_width, max_height, mimetype)) > 0) return bg_db_object_query(db, thumb_id); memset(&b, 0, sizeof(b)); b.max_width = max_width; b.max_height = max_height; b.mimetype = mimetype; bg_db_browse_thumbnails(db, id, browse_callback, &b); if(!b.ret) { bg_db_object_t * img = bg_db_object_query(db, id); b.ret = make_thumbnail(db, img, max_width, max_height, mimetype); bg_db_object_unref(img); } cache_put(&db->th_cache, id, max_width, max_height, mimetype, bg_db_object_get_id(b.ret)); return b.ret; }
QImage Media::make_icon() { if (thumb.isNull()) { QImage image; image.load(filepath()); thumb = make_thumbnail(image); } if (width()>height()) return thumb.scaledToWidth(25, Qt::SmoothTransformation); else return thumb.scaledToHeight(25, Qt::SmoothTransformation); }
Media::Media(QString filename) { uploadedSize = 0; QFile readfile(filename); valid = readfile.open(QFile::ReadOnly); if (!valid) return; readfile.close(); file = filename; filesize = QFile(filename).size(); createTypeList(); if (filename.split(".").length() < 2) { valid = false; return; } QString extension = filename.split('.').last().toLower(); QPair<QString, QString> mimetype; if (types.contains(extension)) mimetype = types[extension]; else { valid = false; return; } mediaClass = mimetype.first; mediaType = mimetype.second; removeSize = false; // File size check if (mediaClass == "image") // There is not size limit for video files { QSettings sets; if (sets.value("loggedin", QVariant(false)).toBool()) // this is set by loginwidget { if (filesize > LOGGEDIN_IMAGE_SIZE_LIMIT) { toolarge = true; valid = false; return; } } else { if (filesize > NOT_LOGGEDIN_IMAGE_SIZE_LIMIT) { toolarge = true; valid = false; return; } } } toolarge = false; // if it is too large, this should not happen if (mediaClass == "image") { QImage image; valid = image.load(filename); #ifdef Q_OS_WIN // This is hack to upload TIFFs on Windows where some // TIFF encodings are not supported. // Yes, Windows really sucks. if (!valid) { if (mediaType == "tiff") { image.load(":/images/images/tiff.png"); valid = true; } else return; } #else if (!valid) return; #endif image_width = image.width(); image_height = image.height(); thumb = make_thumbnail(image); ic = make_icon(); } else if (mediaType == "pdf") { image_width = image_height = 150; thumb = QImage(":/images/images/pdf.jpg"); ic = thumb.scaledToWidth(25, Qt::SmoothTransformation); } else if (mediaType == "x-shockwave-flash") { QImage im(":/images/images/flash.png"); image_width = image_height = 150; thumb = QImage(":/images/images/flash.png"); ic = thumb.scaledToWidth(25, Qt::SmoothTransformation); } else if (mediaClass == "video") { VideoPreviewCreator prev; QImage img = prev.getPreview(filename); videoPreview = img; if (img.isNull()) img.load(":/images/images/video.png"); image_width = img.width(); image_height = img.height(); thumb = make_thumbnail(img); ic = thumb.scaledToWidth(25, Qt::SmoothTransformation); } privacy = false; lastModified = QFileInfo(this->file).lastModified(); }