#include #include #include #include #include #include #include #include #include #include #include #include #include #include "config.h" #include "dialog.h" #include "globals.h" #include "xsession.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QTranslator translator; translator.load(":" + QLocale::system().name()); a.installTranslator(&translator); if (!Config::init(a, Config::CONFIG)) { qDebug() << "Error initializing config. Invalid --config passed?"; return 1; } if (Config::isSet(Config::DUMP_CONFIG)) { Config::dump(); return 0; } if (Config::isSet(Config::INSECURE)) { qDebug() << "Warning: Certificate validation disabled"; QSslConfiguration sslConf = QSslConfiguration::defaultConfiguration(); sslConf.setPeerVerifyMode(QSslSocket::VerifyNone); QSslConfiguration::setDefaultConfiguration(sslConf); } if (Config::isSet(Config::DEBUG)) { g_debugMode = true; } if (Config::isSet(Config::LOCATION_MODE)) { QString mode = Config::get(Config::LOCATION_MODE); if (mode == "IGNORE") { g_forLocationHandling = LOCATION_IGNORE; } else if (mode == "BUMP") { g_forLocationHandling = LOCATION_BUMP; } else if (mode == "EXCLUSIVE") { g_forLocationHandling = LOCATION_EXCLUSIVE; } else { qDebug() << "Invalid location mode: " << mode; QMessageBox::critical(nullptr, "Error", "Invalid location mode: " + mode); return 1; } } if (Config::isSet(Config::TEMPLATE_MODE)) { QString mode = Config::get(Config::TEMPLATE_MODE); if (mode == "IGNORE") { g_templateHandling = TEMPLATES_IGNORE; } else if (mode == "BUMP") { g_templateHandling = TEMPLATES_BUMP; } else { qDebug() << "Invalid template mode: " << mode; QMessageBox::critical(nullptr, "Error", "Invalid template mode: " + mode); return 1; } } g_noVtx = Config::isSet(Config::NO_VTX); if (Config::isSet(Config::AUTOQUIT)) { bool ok = false; g_autoQuitSeconds = Config::get(Config::AUTOQUIT).toInt(&ok, 10); if (!ok) { g_autoQuitSeconds = 0; } } /* read session files */ QList xsessions(XSession::readSessions(Config::get(Config::XSESSION_PATH))); Dialog w; QRect desktopRect = QApplication::desktop()->availableGeometry(&w); int width = VMCHOOSER_DEFAULT_WIDTH, height = VMCHOOSER_DEFAULT_HEIGHT; if (Config::isSet(Config::FULLSCREEN) || Config::get(Config::WINDOW_SIZE) == QLatin1String("fullscreen")) { width = desktopRect.width(); height = desktopRect.height(); g_fullscreen = true; } else { QString size(Config::get(Config::WINDOW_SIZE)); if (!size.isEmpty()) { QRegExp rx("^(\\d+)x(\\d+)$"); if (rx.indexIn(size) != -1) { QStringList list = rx.capturedTexts(); width = list.value(1).toInt(); height = list.value(2).toInt(); } else { std::cerr << a.translate("Console", "vmchooser: invalid size argument").toUtf8().data() << std::endl; return EXIT_FAILURE; } } } w.downloadData(Config::get(Config::LOCATIONS)); w.setTheme(); w.setWindowFlag(Qt::FramelessWindowHint, true); w.resize(width, height); if (xsessions.size()) { qSort(xsessions.begin(), xsessions.end(), sessionComparator); w.addItems(xsessions, 0); } w.show(); if (Config::isSet(Config::AUTOSTART_UUID)) { qDebug() << "using startSession() from main.cpp"; w.startSession(Config::get(Config::AUTOSTART_UUID)); } // center dialog on primary screen QPoint center = desktopRect.center(); w.move(center.x() - w.width() / 2, center.y() - w.height() / 2); a.setActiveWindow(&w); return a.exec(); }