コード例 #1
0
ファイル: path.cpp プロジェクト: gottcode/tetzle
QString Path::thumbnail(const QString& image, qreal pixelratio)
{
	QString pixel;
	if (pixelratio > 1.0) {
		pixel = QString("@%1x").arg(pixelratio);
	}
	return thumbnails() + image + pixel + ".png";
}
コード例 #2
0
ファイル: interface.cpp プロジェクト: rickysarraf/digikam
void Interface::thumbnail(const KUrl& url, int size)
{
    thumbnails(KUrl::List() << url, size);
}
コード例 #3
0
ファイル: cstester.cpp プロジェクト: crayonink/calligra-2
int main(int argc, char *argv[])
{
    KCmdLineArgs::init(argc, argv, "cstester", 0, KLocalizedString(), 0, KLocalizedString());

    KCmdLineOptions options;
    options.add("create", ki18n("create verification data for file"));
    options.add("indir <dir>", ki18n("directory to read the data from"));
    options.add("outdir <dir>", ki18n("directory to save the data to"));
    options.add("roundtrip", ki18n("load/save/load and check the document is the same after load and save/load"));
    options.add("verbose", ki18n("be verbose"));
    options.add("!verify", ki18n("verify the file"));
    options.add( "+file", ki18n("file to use"));
    KCmdLineArgs::addCmdLineOptions(options);

    QApplication app(argc, argv);

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    bool create = false;
    bool roundtrip = false;
    bool verify = false;
    int optionCount = 0;

    if (args->isSet("create")) {
        create = true;
        optionCount++;
    }
    if (args->isSet("roundtrip")) {
        roundtrip = true;
        optionCount++;
    }
    if (args->isSet("verify")) {
        verify = true;
        optionCount++;
    }

    if (optionCount > 1) {
        kError() << "create, roundtrip and verify cannot be used the same time";
        exit(1);
    }
    else if (optionCount < 1) {
        kError() << "one of the options create, roundtrip or verify needs to be specified";
        exit(1);
    }

    QString outDir;
    if (args->isSet("outdir")) {
        // check if it is a directory
        QDir dir(args->getOption("outdir"));
        if (!dir.exists()) {
            kError() << "outdir" << args->getOption("outdir") << "does not exist";
            exit(1);
        }
        outDir = dir.path();
    }

    QString inDir;
    if (args->isSet("indir")) {
        // check if it is a directory
        QDir dir(args->getOption("indir"));
        if (!dir.exists()) {
            kError() << "indir" << args->getOption("indir") << "does not exist";
            exit(1);
        }
        inDir = dir.path();
    }

    bool verbose = args->isSet("verbose");

    int exitValue = 0;

    int successful = 0;
    int failed = 0;
    for (int i=0; i < args->count(); ++i) {
        QString filename(args->arg(i));
        QFileInfo file(filename);
        QString checkDir;
        if (!args->isSet("indir")) {
            checkDir = filename + ".check";
        }
        else {
            checkDir = inDir + '/' + file.fileName() + ".check";
        }

        // this is wrong for multiple files in different dirs
        if (!args->isSet("outdir")) {
            outDir = file.path();
        }

        qDebug() << "filename" << filename << "path" << file.path() << file.completeBaseName() << checkDir << file.absoluteFilePath();
        qDebug() << "inDir" << inDir << "outDir" << outDir << "checkDir" << checkDir;

        // filename must be a absolute path
        KoDocument* document = openFile(file.absoluteFilePath());
        if (!document) {
            exit(2);
        }

        QList<QImage> thumbnails(createThumbnails(document, QSize(800,800)));

        qDebug() << "created" << thumbnails.size() << "thumbnails";
        if (create) {
            saveThumbnails(file, thumbnails, outDir);
        }
        else if (verify) {
            if (args->isSet("outdir")) {
                saveThumbnails(file, thumbnails, outDir);
            }
            if (checkThumbnails(thumbnails, checkDir, verbose)) {
                ++successful;
            }
            else {
                ++failed;
                exitValue = 2;
            }
        }
        else if (roundtrip) {
            QString rFilename = saveFile(document, filename, "cstester-roundtrip");
            delete document;
            QFileInfo rFile(rFilename);
            qDebug() << roundtrip << "rFilename" << rFilename << rFile.absoluteFilePath();
            document = openFile(rFile.absoluteFilePath());
            QList<QImage> others(createThumbnails(document, QSize(800,800)));
            if (args->isSet("outdir")) {
                saveThumbnails(file, others, outDir);
                saveThumbnails(file, thumbnails, outDir + "/before");
            }
            if (checkThumbnails(thumbnails, others, verbose)) {
                ++successful;
            }
            else {
                ++failed;
                exitValue = 2;
            }
        }
        delete document;
    }

    if (verify || roundtrip) {
        qDebug() << "Totals:" << successful << "passed" << failed << "failed";
    }

    QTimer::singleShot(1, &app, SLOT(quit()));
    app.exec();
    return exitValue;
}