improve compatibility

This commit is contained in:
Syping 2021-04-29 18:56:12 +02:00
parent 8880762ff3
commit ff55423d5d
3 changed files with 45 additions and 13 deletions

View file

@ -8,7 +8,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
@ -19,6 +19,7 @@ add_executable(xmppbot
src/xmppbot/main.cpp src/xmppbot/main.cpp
src/xmppbot/unixsocket.cpp src/xmppbot/unixsocket.cpp
src/xmppbot/unixsocket.h src/xmppbot/unixsocket.h
src/xmppbot/xmppbot.h
) )
add_dependencies(xmppbot qxmpp) add_dependencies(xmppbot qxmpp)

View file

@ -25,6 +25,7 @@
#include <QProcess> #include <QProcess>
#include <QFile> #include <QFile>
#include "xmppbot.h"
#include "unixsocket.h" #include "unixsocket.h"
#include "QXmppClient.h" #include "QXmppClient.h"
#include "QXmppMessage.h" #include "QXmppMessage.h"
@ -33,7 +34,7 @@ int main(int argc, char *argv[])
{ {
QCoreApplication app(argc, argv); QCoreApplication app(argc, argv);
app.setApplicationName("xmppbot"); app.setApplicationName("xmppbot");
app.setApplicationVersion("0.2"); app.setApplicationVersion("0.2.1");
QCommandLineParser commandLineParser; QCommandLineParser commandLineParser;
commandLineParser.addPositionalArgument("config", QCoreApplication::translate("xmppbot", "Configuration file.")); commandLineParser.addPositionalArgument("config", QCoreApplication::translate("xmppbot", "Configuration file."));
@ -49,7 +50,7 @@ int main(int argc, char *argv[])
settingsPath = a_settingsPath; settingsPath = a_settingsPath;
} }
else { else {
QTextStream(stderr) << "xmppbot: " << a_settingsPath << " not found!" << Qt::endl; QTextStream(stderr) << "xmppbot: " << a_settingsPath << " not found!" << xendl;
return 1; return 1;
} }
} }
@ -76,7 +77,7 @@ int main(int argc, char *argv[])
loginSet = true; loginSet = true;
} }
else { else {
QTextStream(stderr) << "xmppbot: Login password can only be set once!" << Qt::endl; QTextStream(stderr) << "xmppbot: Login password can only be set once!" << xendl;
return 1; return 1;
} }
} }
@ -113,14 +114,14 @@ int main(int argc, char *argv[])
} }
#endif #endif
if (listen) { if (listen) {
QTextStream(stderr) << "xmppbot: Account socket " << group << " initialised" << Qt::endl; QTextStream(stderr) << "xmppbot: Account socket " << group << " initialised" << xendl;
const QString incoming = settings.value("Incoming", QString()).toString(); const QString incoming = settings.value("Incoming", QString()).toString();
if (incoming.startsWith("message:")) { if (incoming.startsWith("message:")) {
QTextStream(stderr) << "xmppbot: Account message incoming " << group << " initialised" << Qt::endl; QTextStream(stderr) << "xmppbot: Account message incoming " << group << " initialised" << xendl;
h_msg.insert(group, incoming.mid(8)); h_msg.insert(group, incoming.mid(8));
} }
if (incoming.startsWith("run:")) { if (incoming.startsWith("run:")) {
QTextStream(stderr) << "xmppbot: Account run incoming " << group << " initialised" << Qt::endl; QTextStream(stderr) << "xmppbot: Account run incoming " << group << " initialised" << xendl;
h_run.insert(group, incoming.mid(4)); h_run.insert(group, incoming.mid(4));
} }
} }
@ -133,23 +134,23 @@ int main(int argc, char *argv[])
} }
} }
else { else {
QTextStream(stderr) << "xmppbot: Can't initialise without settings.ini!" << Qt::endl; QTextStream(stderr) << "xmppbot: Can't initialise without settings.ini!" << xendl;
return 1; return 1;
} }
if (jid.isEmpty() || jpw.isEmpty()) { if (jid.isEmpty() || jpw.isEmpty()) {
QTextStream(stderr) << "xmppbot: Can't initialise without XMPP account!" << Qt::endl; QTextStream(stderr) << "xmppbot: Can't initialise without XMPP account!" << xendl;
return 1; return 1;
} }
QObject::connect(&client, &QXmppClient::connected, [&]() { QObject::connect(&client, &QXmppClient::connected, [&]() {
QTextStream(stderr) << "xmppbot: Account " << jid << " connected" << Qt::endl; QTextStream(stderr) << "xmppbot: Account " << jid << " connected" << xendl;
QXmppPresence xmppPresence(QXmppPresence::Available); QXmppPresence xmppPresence(QXmppPresence::Available);
client.setClientPresence(xmppPresence); client.setClientPresence(xmppPresence);
}); });
QObject::connect(&client, &QXmppClient::disconnected, [&]() { QObject::connect(&client, &QXmppClient::disconnected, [&]() {
QTextStream(stderr) << "xmppbot: Account " << jid << " disconnected" << Qt::endl; QTextStream(stderr) << "xmppbot: Account " << jid << " disconnected" << xendl;
client.connectToServer(jid, jpw); client.connectToServer(jid, jpw);
}); });
@ -174,14 +175,14 @@ int main(int argc, char *argv[])
qint64 pid; qint64 pid;
bool isStarted = QProcess::startDetached(run, QStringList() << from << xmppMessage.to() << xmppMessage.body(), QString(), &pid); bool isStarted = QProcess::startDetached(run, QStringList() << from << xmppMessage.to() << xmppMessage.body(), QString(), &pid);
if (isStarted) { if (isStarted) {
QTextStream(stderr) << "xmppbot: Account " << from_jid << " executed pid " << pid << Qt::endl; QTextStream(stderr) << "xmppbot: Account " << from_jid << " executed pid " << pid << xendl;
} }
} }
}); });
client.connectToServer(jid, jpw); client.connectToServer(jid, jpw);
QTextStream(stderr) << "xmppbot: Account login " << jid << " initialised" << Qt::endl; QTextStream(stderr) << "xmppbot: Account login " << jid << " initialised" << xendl;
return app.exec(); return app.exec();
} }

30
src/xmppbot/xmppbot.h Normal file
View file

@ -0,0 +1,30 @@
/*****************************************************************************
* xmppbot Simple unix socket based XMPP bot
* Copyright (C) 2021 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef XMPPBOT_H
#define XMPPBOT_H
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#define xendl Qt::endl;
#else
#define xendl endl;
#endif
#endif // XMPPBOT_H