2022-04-22 15:26:18 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "shared/global.h"
|
|
|
|
#include "shared/messageinfo.h"
|
|
|
|
#include "shared/pathcheck.h"
|
2022-08-22 20:29:43 +00:00
|
|
|
#include "shared/identity.h"
|
2022-04-22 15:26:18 +00:00
|
|
|
#include "main/application.h"
|
|
|
|
#include "core/signalcatcher.h"
|
|
|
|
#include "core/squawk.h"
|
|
|
|
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QTranslator>
|
|
|
|
#include <QtCore/QObject>
|
|
|
|
#include <QtCore/QThread>
|
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
#include <QDir>
|
|
|
|
|
2022-12-14 23:08:08 +00:00
|
|
|
#ifdef WITH_OMEMO
|
|
|
|
#include <QXmppOmemoStorage.h>
|
|
|
|
#endif
|
|
|
|
|
2022-04-22 15:26:18 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
qRegisterMetaType<Shared::Message>("Shared::Message");
|
|
|
|
qRegisterMetaType<Shared::MessageInfo>("Shared::MessageInfo");
|
|
|
|
qRegisterMetaType<Shared::VCard>("Shared::VCard");
|
|
|
|
qRegisterMetaType<std::list<Shared::Message>>("std::list<Shared::Message>");
|
|
|
|
qRegisterMetaType<std::list<Shared::MessageInfo>>("std::list<Shared::MessageInfo>");
|
2022-12-14 23:08:08 +00:00
|
|
|
qRegisterMetaType<std::list<QString>>("std::list<QString>");
|
|
|
|
qRegisterMetaType<std::set<QString>>("std::set<QString>");
|
|
|
|
qRegisterMetaType<std::list<Shared::Identity>>("std::list<Shared::Identity>");
|
2022-04-22 15:26:18 +00:00
|
|
|
qRegisterMetaType<QSet<QString>>("QSet<QString>");
|
|
|
|
qRegisterMetaType<Shared::ConnectionState>("Shared::ConnectionState");
|
|
|
|
qRegisterMetaType<Shared::Availability>("Shared::Availability");
|
2023-01-01 17:25:51 +00:00
|
|
|
qRegisterMetaType<Shared::KeyInfo>("Shared::KeyInfo");
|
2022-12-14 23:08:08 +00:00
|
|
|
#ifdef WITH_OMEMO
|
|
|
|
qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
|
2022-12-26 22:01:01 +00:00
|
|
|
qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
|
|
|
|
qRegisterMetaType<QXmppOmemoStorage::Device>("QXmppOmemoStorage::Device");
|
2022-12-14 23:08:08 +00:00
|
|
|
#endif
|
2022-04-22 15:26:18 +00:00
|
|
|
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
SignalCatcher sc(&app);
|
|
|
|
|
|
|
|
QApplication::setApplicationName("squawk");
|
|
|
|
QApplication::setOrganizationName("macaw.me");
|
|
|
|
QApplication::setApplicationDisplayName("Squawk");
|
2022-06-03 06:44:48 +00:00
|
|
|
QApplication::setApplicationVersion("0.2.3");
|
2022-04-23 13:58:08 +00:00
|
|
|
app.setDesktopFileName("squawk");
|
2022-04-22 15:26:18 +00:00
|
|
|
|
|
|
|
QTranslator qtTranslator;
|
|
|
|
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
app.installTranslator(&qtTranslator);
|
|
|
|
|
|
|
|
QTranslator myappTranslator;
|
|
|
|
QStringList shares = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
|
|
|
|
bool found = false;
|
|
|
|
for (QString share : shares) {
|
|
|
|
found = myappTranslator.load(QLocale(), QLatin1String("squawk"), ".", share + "/l10n");
|
|
|
|
if (found) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
myappTranslator.load(QLocale(), QLatin1String("squawk"), ".", QCoreApplication::applicationDirPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
app.installTranslator(&myappTranslator);
|
|
|
|
|
|
|
|
QIcon icon;
|
|
|
|
icon.addFile(":images/logo.svg", QSize(16, 16));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(24, 24));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(32, 32));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(48, 48));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(64, 64));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(96, 96));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(128, 128));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(256, 256));
|
|
|
|
icon.addFile(":images/logo.svg", QSize(512, 512));
|
|
|
|
QApplication::setWindowIcon(icon);
|
|
|
|
|
|
|
|
new Shared::Global(); //translates enums
|
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
QVariant vs = settings.value("style");
|
|
|
|
if (vs.isValid()) {
|
|
|
|
QString style = vs.toString().toLower();
|
|
|
|
if (style != "system") {
|
|
|
|
Shared::Global::setStyle(style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Shared::Global::supported("colorSchemeTools")) {
|
|
|
|
QVariant vt = settings.value("theme");
|
|
|
|
if (vt.isValid()) {
|
|
|
|
QString theme = vt.toString();
|
|
|
|
if (theme.toLower() != "system") {
|
|
|
|
Shared::Global::setTheme(theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QString path = Shared::downloadsPathCheck();
|
|
|
|
if (path.size() > 0) {
|
|
|
|
settings.setValue("downloadsPath", path);
|
|
|
|
} else {
|
|
|
|
qDebug() << "couldn't initialize directory for downloads, quitting";
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::Squawk* squawk = new Core::Squawk();
|
|
|
|
QThread* coreThread = new QThread();
|
|
|
|
squawk->moveToThread(coreThread);
|
|
|
|
|
|
|
|
Application application(squawk);
|
|
|
|
|
|
|
|
QObject::connect(&sc, &SignalCatcher::interrupt, &application, &Application::quit);
|
|
|
|
|
|
|
|
QObject::connect(coreThread, &QThread::started, squawk, &Core::Squawk::start);
|
|
|
|
QObject::connect(&application, &Application::quitting, squawk, &Core::Squawk::stop);
|
|
|
|
//QObject::connect(&app, &QApplication::aboutToQuit, &w, &QMainWindow::close);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::quit, squawk, &Core::Squawk::deleteLater);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::destroyed, coreThread, &QThread::quit, Qt::QueuedConnection);
|
|
|
|
QObject::connect(coreThread, &QThread::finished, &app, &QApplication::quit, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
coreThread->start();
|
|
|
|
int result = app.exec();
|
|
|
|
|
|
|
|
if (coreThread->isRunning()) {
|
|
|
|
//coreThread->wait();
|
|
|
|
//todo if I uncomment that, the app will not quit if it has reconnected at least once
|
|
|
|
//it feels like a symptom of something badly desinged in the core thread
|
|
|
|
//need to investigate;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|