2019-08-14 14:54:46 +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/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
#include "ui/squawk.h"
|
|
|
|
#include "core/squawk.h"
|
2019-04-02 21:58:43 +00:00
|
|
|
#include "signalcatcher.h"
|
2020-04-03 22:28:15 +00:00
|
|
|
#include "shared/global.h"
|
2019-03-29 14:54:34 +00:00
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
#include <QtCore/QThread>
|
|
|
|
#include <QtCore/QObject>
|
2019-04-02 21:58:43 +00:00
|
|
|
#include <QSettings>
|
2019-10-05 11:27:39 +00:00
|
|
|
#include <QTranslator>
|
|
|
|
#include <QLibraryInfo>
|
2019-10-07 15:35:55 +00:00
|
|
|
#include <QStandardPaths>
|
2019-03-29 14:54:34 +00:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-04-11 14:58:59 +00:00
|
|
|
qRegisterMetaType<Shared::Message>("Shared::Message");
|
2019-10-17 20:54:27 +00:00
|
|
|
qRegisterMetaType<Shared::VCard>("Shared::VCard");
|
2019-05-15 17:36:37 +00:00
|
|
|
qRegisterMetaType<std::list<Shared::Message>>("std::list<Shared::Message>");
|
2019-06-15 15:29:15 +00:00
|
|
|
qRegisterMetaType<QSet<QString>>("QSet<QString>");
|
2020-04-03 22:28:15 +00:00
|
|
|
qRegisterMetaType<Shared::ConnectionState>("Shared::ConnectionState");
|
|
|
|
qRegisterMetaType<Shared::Availability>("Shared::Availability");
|
2019-04-09 22:01:25 +00:00
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
QApplication app(argc, argv);
|
2019-04-02 21:58:43 +00:00
|
|
|
SignalCatcher sc(&app);
|
|
|
|
|
2019-10-10 11:45:21 +00:00
|
|
|
QApplication::setApplicationName("squawk");
|
|
|
|
QApplication::setApplicationDisplayName("Squawk");
|
2020-03-31 15:56:49 +00:00
|
|
|
QApplication::setApplicationVersion("0.1.3");
|
2019-10-05 11:27:39 +00:00
|
|
|
|
|
|
|
QTranslator qtTranslator;
|
|
|
|
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
|
|
|
app.installTranslator(&qtTranslator);
|
|
|
|
|
|
|
|
QTranslator myappTranslator;
|
2019-10-07 15:35:55 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2019-10-05 11:27:39 +00:00
|
|
|
app.installTranslator(&myappTranslator);
|
2019-04-02 21:58:43 +00:00
|
|
|
|
2019-06-22 20:37:22 +00:00
|
|
|
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);
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
new Shared::Global(); //translates enums
|
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
Squawk w;
|
|
|
|
w.show();
|
|
|
|
|
|
|
|
Core::Squawk* squawk = new Core::Squawk();
|
|
|
|
QThread* coreThread = new QThread();
|
|
|
|
squawk->moveToThread(coreThread);
|
|
|
|
|
2019-11-12 13:38:01 +00:00
|
|
|
QObject::connect(coreThread, &QThread::started, squawk, &Core::Squawk::start);
|
|
|
|
QObject::connect(&app, &QApplication::aboutToQuit, squawk, &Core::Squawk::stop);
|
2019-12-25 10:24:20 +00:00
|
|
|
QObject::connect(&app, &QApplication::aboutToQuit, &w, &QMainWindow::close);
|
2019-11-12 13:38:01 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::quit, coreThread, &QThread::quit);
|
|
|
|
QObject::connect(coreThread, &QThread::finished, squawk, &Core::Squawk::deleteLater);
|
|
|
|
|
2019-10-17 20:54:27 +00:00
|
|
|
QObject::connect(&w, &Squawk::newAccountRequest, squawk, &Core::Squawk::newAccountRequest);
|
|
|
|
QObject::connect(&w, &Squawk::modifyAccountRequest, squawk, &Core::Squawk::modifyAccountRequest);
|
|
|
|
QObject::connect(&w, &Squawk::removeAccountRequest, squawk, &Core::Squawk::removeAccountRequest);
|
|
|
|
QObject::connect(&w, &Squawk::connectAccount, squawk, &Core::Squawk::connectAccount);
|
|
|
|
QObject::connect(&w, &Squawk::disconnectAccount, squawk, &Core::Squawk::disconnectAccount);
|
|
|
|
QObject::connect(&w, &Squawk::changeState, squawk, &Core::Squawk::changeState);
|
2019-11-09 09:54:30 +00:00
|
|
|
QObject::connect(&w, qOverload<const QString&, const Shared::Message&>(&Squawk::sendMessage),
|
|
|
|
squawk, qOverload<const QString&, const Shared::Message&>(&Core::Squawk::sendMessage));
|
|
|
|
QObject::connect(&w, qOverload<const QString&, const Shared::Message&, const QString&>(&Squawk::sendMessage),
|
|
|
|
squawk, qOverload<const QString&, const Shared::Message&, const QString&>(&Core::Squawk::sendMessage));
|
2019-10-17 20:54:27 +00:00
|
|
|
QObject::connect(&w, &Squawk::requestArchive, squawk, &Core::Squawk::requestArchive);
|
|
|
|
QObject::connect(&w, &Squawk::subscribeContact, squawk, &Core::Squawk::subscribeContact);
|
|
|
|
QObject::connect(&w, &Squawk::unsubscribeContact, squawk, &Core::Squawk::unsubscribeContact);
|
|
|
|
QObject::connect(&w, &Squawk::addContactRequest, squawk, &Core::Squawk::addContactRequest);
|
|
|
|
QObject::connect(&w, &Squawk::removeContactRequest, squawk, &Core::Squawk::removeContactRequest);
|
|
|
|
QObject::connect(&w, &Squawk::setRoomJoined, squawk, &Core::Squawk::setRoomJoined);
|
|
|
|
QObject::connect(&w, &Squawk::setRoomAutoJoin, squawk, &Core::Squawk::setRoomAutoJoin);
|
|
|
|
QObject::connect(&w, &Squawk::removeRoomRequest, squawk, &Core::Squawk::removeRoomRequest);
|
|
|
|
QObject::connect(&w, &Squawk::addRoomRequest, squawk, &Core::Squawk::addRoomRequest);
|
|
|
|
QObject::connect(&w, &Squawk::fileLocalPathRequest, squawk, &Core::Squawk::fileLocalPathRequest);
|
|
|
|
QObject::connect(&w, &Squawk::downloadFileRequest, squawk, &Core::Squawk::downloadFileRequest);
|
2019-09-28 14:30:16 +00:00
|
|
|
QObject::connect(&w, &Squawk::addContactToGroupRequest, squawk, &Core::Squawk::addContactToGroupRequest);
|
|
|
|
QObject::connect(&w, &Squawk::removeContactFromGroupRequest, squawk, &Core::Squawk::removeContactFromGroupRequest);
|
2019-10-01 08:47:40 +00:00
|
|
|
QObject::connect(&w, &Squawk::renameContactRequest, squawk, &Core::Squawk::renameContactRequest);
|
2019-10-22 15:13:56 +00:00
|
|
|
QObject::connect(&w, &Squawk::requestVCard, squawk, &Core::Squawk::requestVCard);
|
2019-10-24 09:42:38 +00:00
|
|
|
QObject::connect(&w, &Squawk::uploadVCard, squawk, &Core::Squawk::uploadVCard);
|
2020-04-07 20:33:03 +00:00
|
|
|
QObject::connect(&w, &Squawk::responsePassword, squawk, &Core::Squawk::responsePassword);
|
2019-03-30 20:13:13 +00:00
|
|
|
|
2019-10-17 20:54:27 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::newAccount, &w, &Squawk::newAccount);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::addContact, &w, &Squawk::addContact);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::changeAccount, &w, &Squawk::changeAccount);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::removeAccount, &w, &Squawk::removeAccount);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::addGroup, &w, &Squawk::addGroup);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::removeGroup, &w, &Squawk::removeGroup);
|
|
|
|
QObject::connect(squawk, qOverload<const QString&, const QString&>(&Core::Squawk::removeContact),
|
|
|
|
&w, qOverload<const QString&, const QString&>(&Squawk::removeContact));
|
|
|
|
QObject::connect(squawk, qOverload<const QString&, const QString&, const QString&>(&Core::Squawk::removeContact),
|
|
|
|
&w, qOverload<const QString&, const QString&, const QString&>(&Squawk::removeContact));
|
|
|
|
QObject::connect(squawk, &Core::Squawk::changeContact, &w, &Squawk::changeContact);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::addPresence, &w, &Squawk::addPresence);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::removePresence, &w, &Squawk::removePresence);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::stateChanged, &w, &Squawk::stateChanged);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::accountMessage, &w, &Squawk::accountMessage);
|
2020-03-25 15:28:36 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::changeMessage, &w, &Squawk::changeMessage);
|
2019-10-17 20:54:27 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::responseArchive, &w, &Squawk::responseArchive);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::addRoom, &w, &Squawk::addRoom);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::changeRoom, &w, &Squawk::changeRoom);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::removeRoom, &w, &Squawk::removeRoom);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::addRoomParticipant, &w, &Squawk::addRoomParticipant);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::changeRoomParticipant, &w, &Squawk::changeRoomParticipant);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::removeRoomParticipant, &w, &Squawk::removeRoomParticipant);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::fileLocalPathResponse, &w, &Squawk::fileLocalPathResponse);
|
2019-11-12 13:38:01 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::downloadFileProgress, &w, &Squawk::fileProgress);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::downloadFileError, &w, &Squawk::fileError);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::uploadFileProgress, &w, &Squawk::fileProgress);
|
|
|
|
QObject::connect(squawk, &Core::Squawk::uploadFileError, &w, &Squawk::fileError);
|
2019-10-22 15:13:56 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::responseVCard, &w, &Squawk::responseVCard);
|
2020-04-07 20:33:03 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::requestPassword, &w, &Squawk::requestPassword);
|
2020-04-04 16:40:32 +00:00
|
|
|
QObject::connect(squawk, &Core::Squawk::ready, &w, &Squawk::readSettings);
|
2019-09-12 20:54:44 +00:00
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
coreThread->start();
|
|
|
|
|
2019-04-02 21:58:43 +00:00
|
|
|
int result = app.exec();
|
2019-12-25 10:24:20 +00:00
|
|
|
|
|
|
|
w.writeSettings();
|
2019-04-02 21:58:43 +00:00
|
|
|
coreThread->wait(500); //TODO hate doing that but settings for some reason don't get saved to the disk
|
|
|
|
|
2019-12-25 10:24:20 +00:00
|
|
|
|
2019-04-02 21:58:43 +00:00
|
|
|
return result;
|
2019-03-29 14:54:34 +00:00
|
|
|
}
|
|
|
|
|