main.cpp 2.8 KB
Newer Older
1 2 3 4 5
#include <QApplication>
#include <QProcess>
#include <QDir>
#include <QFile>
#include <QTextStream>
Carson Black's avatar
Carson Black committed
6 7 8
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
9 10 11
#include <QtDebug>
#include <Plasma/Svg>
#include <QIcon>
Carson Black's avatar
Carson Black committed
12
#include <QtWebEngine>
13
#include "iconsetter.h"
Carson Black's avatar
Carson Black committed
14
#include "iconmanipulator.h"
Carson Black's avatar
Carson Black committed
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

void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    QByteArray localMsg = msg.toLocal8Bit();
    const char *file = context.file ? context.file : "";
    const char *function = context.function ? context.function : "";
    switch (type) {
    case QtDebugMsg:
        fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtInfoMsg:
        fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtWarningMsg:
        fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtCriticalMsg:
        fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    case QtFatalMsg:
        fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
        break;
    }
}

40 41 42 43 44 45 46 47 48
bool fileExists(QString path)
{
    QFileInfo check_file(path);
    if (check_file.exists() && check_file.isFile()) {
        return true;
    } else {
        return false;
    }
}
Carson Black's avatar
Carson Black committed
49 50 51 52 53
int main(int argc, char *argv[])
{
    qInstallMessageHandler(myMessageOutput);
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

Carson Black's avatar
Carson Black committed
54
    QApplication app(argc, argv);
55
    // QQuickStyle::setStyle("Plasma");
Carson Black's avatar
Carson Black committed
56 57
    app.setOrganizationName("Appadeia");
    app.setOrganizationDomain("me.appadeia");
Carson Black's avatar
Carson Black committed
58
    app.setApplicationName("Ikona");
Carson Black's avatar
Carson Black committed
59

Carson Black's avatar
Carson Black committed
60 61
    QtWebEngine::initialize();

62 63 64 65 66 67 68 69
    if (fileExists(QDir::homePath() + "/.iconPreviewTheme")) {
        QFile file(QDir::homePath() + "/.iconPreviewTheme");
        if (file.open(QFile::ReadOnly)) {
            QTextStream in(&file);
            QIcon::setThemeName(in.readAll().trimmed());
            qDebug() << in.readAll().trimmed();
        }
    }
Carson Black's avatar
Carson Black committed
70 71 72 73 74
    QDir dir(QDir::homePath() + "/.ikona");
    if (!dir.exists()) {
        dir.mkdir(QDir::homePath() + "/.ikona");
    }

Carson Black's avatar
Carson Black committed
75 76
    qmlRegisterType<IconSetter>("me.appadeia.Ikona", 1, 0, "IconSetter");
    qmlRegisterType<IconManipulator>("me.appadeia.Ikona", 1, 0, "IconManipulator");
Carson Black's avatar
Carson Black committed
77 78 79 80

    QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << QDir::homePath() + "/.ikona");
    qDebug() << QIcon::fallbackSearchPaths();

Carson Black's avatar
Carson Black committed
81
    app.setWindowIcon(QIcon::fromTheme(QString("ikona")));
82

Carson Black's avatar
Carson Black committed
83 84 85 86 87 88 89
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}