Warning, file /office/calligra/gemini/thumbnailhelper.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * Assists in creating thumbnails for Gemini's file views
0003  * SPDX-FileCopyrightText: 2014 Dan Leinir Turthra Jensen <admin@leinir.dk>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #include <QFile>
0009 #include <QDir>
0010 #include <QProcessEnvironment>
0011 #include <QDebug>
0012 #include <QTimer>
0013 #include <QCommandLineParser>
0014 #include <QApplication>
0015 
0016 #include <KAboutData>
0017 #include <KLocalizedString>
0018 #include <KCrash>
0019 
0020 #include <calligraversion.h>
0021 
0022 #include "ThumbnailHelperImpl.h"
0023 
0024 #ifdef Q_OS_WIN
0025 #include <windows.h>
0026 #endif
0027 
0028 int main( int argc, char** argv )
0029 {
0030 #ifdef Q_OS_WIN
0031     SetErrorMode(SEM_NOGPFAULTERRORBOX); 
0032 #endif
0033 
0034 #if defined HAVE_X11
0035     QApplication::setAttribute(Qt::AA_X11InitThreads);
0036 #endif
0037 
0038     // needed as kdelibs4support linking plugins seem to inject activated drkonqi
0039     // TODO: fix it, that seems very wrong
0040     KCrash::setDrKonqiEnabled(false);
0041 
0042     QApplication app(argc, argv);
0043 
0044     KAboutData aboutData("calligrageminithumbnailer",
0045                          i18n("Calligra Gemini Thumbnailer"),
0046                          QStringLiteral(CALLIGRA_VERSION_STRING),
0047                          i18n("Calligra Gemini: Writing and Presenting at Home and on the Go"),
0048                          KAboutLicense::GPL,
0049                          i18n("(c) 1999-%1 The Calligra team and KO GmbH.\n", QStringLiteral(CALLIGRA_YEAR)),
0050                          QString(),
0051                          QStringLiteral("https://www.calligra.org"),
0052                          QStringLiteral("submit@bugs.kde.org"));
0053 
0054     KAboutData::setApplicationData(aboutData);
0055 
0056     QCommandLineParser parser;
0057     aboutData.setupCommandLine(&parser);
0058 
0059     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("in"), i18n("Document to thumbnail"), QStringLiteral("local-url")));
0060     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("out"), i18n("The full path for the thumbnail file"), QStringLiteral("local-url")));
0061     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("width"), i18n("The width in pixels of the thumbnail"), QStringLiteral("pixels")));
0062     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("height"), i18n("The height in pixels of the thumbnail"), QStringLiteral("pixels")));
0063 
0064     parser.process(app);
0065     aboutData.processCommandLine(&parser);
0066 
0067 #ifdef Q_OS_WIN
0068     QDir appdir(app.applicationDirPath());
0069     appdir.cdUp();
0070 
0071     QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
0072     if (!env.contains("KDESYCOCA")) {
0073         _putenv_s("KDESYCOCA", QString(appdir.absolutePath() + "/sycoca").toLocal8Bit());
0074     }
0075     if (!env.contains("XDG_DATA_DIRS")) {
0076         _putenv_s("XDG_DATA_DIRS", QString(appdir.absolutePath() + "/share").toLocal8Bit());
0077     }
0078     _putenv_s("PATH", QString(appdir.absolutePath() + "/bin" + ";"
0079               + appdir.absolutePath() + "/lib" + ";"
0080               + appdir.absolutePath() + "/lib"  +  "/kde4" + ";"
0081               + appdir.absolutePath()).toLocal8Bit());
0082 
0083     app.addLibraryPath(appdir.absolutePath());
0084     app.addLibraryPath(appdir.absolutePath() + "/bin");
0085     app.addLibraryPath(appdir.absolutePath() + "/lib");
0086     app.addLibraryPath(appdir.absolutePath() + "/lib/kde4");
0087 #endif
0088 
0089     QString inFile = parser.value("in");
0090     QString outFile = parser.value("out");
0091     // Only create the thunbnail if:
0092     // 1) The infile exists and
0093     // 2) The outfile does /not/ exist
0094     if(!QFile::exists(inFile)) {
0095         qDebug() << "The document you are attempting to create a thumbnail of does not exist on disk:" << inFile;
0096     }
0097     else if(QFile::exists(outFile)) {
0098         qDebug() << "The thumbnail file you are asking to have used already exists on disk. We will refuse to overwrite it." << outFile;
0099     }
0100     else {
0101         ThumbnailHelperImpl helper;
0102         helper.convert(inFile, outFile, parser.value("width").toInt(), parser.value("height").toInt());
0103     }
0104     QTimer::singleShot(0, &app, &QApplication::quit);
0105 
0106     return app.exec();
0107 }