main.cpp 2.3 KB
Newer Older
1
#include <QApplication>
Camilo Higuita's avatar
src  
Camilo Higuita committed
2
#include <QQmlApplicationEngine>
3
#include <QQmlContext>
Camilo Higuita's avatar
Camilo Higuita committed
4
#include <QQuickStyle>
5
#include <QIcon>
6 7
#include <QCommandLineParser>
#include <QFileInfo>
8
#include "src/pix.h"
9

10 11 12
#ifdef Q_OS_ANDROID
#include "./3rdparty/kirigami/src/kirigamiplugin.h"
#endif
Camilo Higuita's avatar
src  
Camilo Higuita committed
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
QStringList getFolderImages(const QString &path)
{
    QStringList urls;

    if (QFileInfo(path).isDir())
    {
        QDirIterator it(path, PIX::formats, QDir::Files, QDirIterator::Subdirectories);
        while (it.hasNext()) urls<<it.next();

    } else if (QFileInfo(path).isFile()) urls<<path;

    return urls;
}

QStringList openFiles(const QStringList &files)
{
    QStringList urls;

    if(files.size()>1)
        urls = files;
    else
    {
        auto folder = QFileInfo(files.first()).dir().absolutePath();
        urls = getFolderImages(folder);
        urls.removeOne(QString(files.first()));
        urls.insert(0, QString(files.first()));
    }

    return urls;
}

Camilo Higuita's avatar
src  
Camilo Higuita committed
45 46 47 48
int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

49
    QApplication app(argc, argv);
50 51 52 53
    app.setApplicationName(PIX::App);
    app.setApplicationVersion(PIX::version);
    app.setApplicationDisplayName(PIX::App);
    app.setWindowIcon(QIcon(":/img/assets/pix.png"));
Camilo Higuita's avatar
Camilo Higuita committed
54

55 56 57 58 59 60 61 62 63 64 65 66 67 68
    QCommandLineParser parser;
    parser.setApplicationDescription("Pix Image gallery viewer");
    const QCommandLineOption versionOption = parser.addVersionOption();
    parser.addOption(versionOption);
    parser.process(app);

    const QStringList args = parser.positionalArguments();

    QStringList pics;

    if(!args.isEmpty())
        pics = openFiles(args);


69 70
#ifdef Q_OS_ANDROID
    KirigamiPlugin::getInstance().registerTypes();
71 72 73
    //#else
    //    if(QQuickStyle::availableStyles().contains("nomad"))
    //        QQuickStyle::setStyle("nomad");
74
#endif
Camilo Higuita's avatar
Camilo Higuita committed
75

76
    Pix pix;
77

Camilo Higuita's avatar
src  
Camilo Higuita committed
78
    QQmlApplicationEngine engine;
79 80 81 82
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, [&]()
    {
        qDebug()<<"FINISHED LOADING QML APP";
        pix.refreshCollection();
83 84
        if(!pics.isEmpty())
            pix.openPics(pics);
85
    });
86

87
    auto context = engine.rootContext();
Camilo Higuita's avatar
Camilo Higuita committed
88
    context->setContextProperty("pix", &pix);
89

Camilo Higuita's avatar
src  
Camilo Higuita committed
90 91 92 93 94 95
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}