+bool Core::init()
+{
+ _startTime = QDateTime::currentDateTime().toUTC(); // for uptime :)
+
+ Quassel::loadTranslation(QLocale::system());
+
+ // check settings version
+ // so far, we only have 1
+ CoreSettings s;
+ if (s.version() != 1) {
+ qCritical() << "Invalid core settings version, terminating!";
+ QCoreApplication::exit(EXIT_FAILURE);
+ return false;
+ }
+
+ // Set up storage and authentication backends
+ registerStorageBackends();
+ registerAuthenticators();
+
+ QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
+ bool config_from_environment = Quassel::isOptionSet("config-from-environment");
+
+ QString db_backend;
+ QVariantMap db_connectionProperties;
+
+ QString auth_authenticator;
+ QVariantMap auth_properties;
+
+ bool writeError = false;
+
+ if (config_from_environment) {
+ db_backend = environment.value("DB_BACKEND");
+ auth_authenticator = environment.value("AUTH_AUTHENTICATOR");
+ } else {
+ CoreSettings cs;
+
+ QVariantMap dbsettings = cs.storageSettings().toMap();
+ db_backend = dbsettings.value("Backend").toString();
+ db_connectionProperties = dbsettings.value("ConnectionProperties").toMap();
+
+ QVariantMap authSettings = cs.authSettings().toMap();
+ auth_authenticator = authSettings.value("Authenticator", "Database").toString();
+ auth_properties = authSettings.value("AuthProperties").toMap();
+
+ writeError = !cs.isWritable();
+ }
+
+ // legacy
+ _configured = initStorage(db_backend, db_connectionProperties, environment, config_from_environment);
+
+ // Not entirely sure what is 'legacy' about the above, but it seems to be the way things work!
+ if (_configured) {
+ initAuthenticator(auth_authenticator, auth_properties, environment, config_from_environment);
+ }
+
+ if (Quassel::isOptionSet("select-backend") || Quassel::isOptionSet("select-authenticator")) {
+ bool success{true};
+ if (Quassel::isOptionSet("select-backend")) {
+ success &= selectBackend(Quassel::optionValue("select-backend"));
+ }
+ if (Quassel::isOptionSet("select-authenticator")) {
+ success &= selectAuthenticator(Quassel::optionValue("select-authenticator"));
+ }
+ QCoreApplication::exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
+ return success;
+ }
+
+ if (!_configured) {
+ if (config_from_environment) {
+ _configured = initStorage(db_backend, db_connectionProperties, environment, config_from_environment, true);
+ initAuthenticator(auth_authenticator, auth_properties, environment, config_from_environment, true);
+
+ if (!_configured) {
+ qWarning() << "Cannot configure from environment";
+ QCoreApplication::exit(EXIT_FAILURE);
+ return false;
+ }
+ }
+ else {
+ if (_registeredStorageBackends.empty()) {
+ quWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting..."));
+ quWarning()
+ << qPrintable(tr("Currently, Quassel supports SQLite3 and PostgreSQL. You need to build your\n"
+ "Qt library with the sqlite or postgres plugin enabled in order for quasselcore\n"
+ "to work."));
+ QCoreApplication::exit(EXIT_FAILURE); // TODO make this less brutal (especially for mono client -> popup)
+ return false;
+ }
+
+ if (writeError) {
+ qWarning() << "Cannot write quasselcore configuration; probably a permission problem.";
+ QCoreApplication::exit(EXIT_FAILURE);
+ return false;
+ }
+
+ quInfo() << "Core is currently not configured! Please connect with a Quassel Client for basic setup.";
+ }
+ }
+ else {
+ if (Quassel::isOptionSet("add-user")) {
+ bool success = createUser();
+ QCoreApplication::exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
+ return success;
+ }
+
+ if (Quassel::isOptionSet("change-userpass")) {
+ bool success = changeUserPass(Quassel::optionValue("change-userpass"));
+ QCoreApplication::exit(success ? EXIT_SUCCESS : EXIT_FAILURE);
+ return success;