From 5231302217cd8735a3359c26ca2bfdf80d71e5df Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Thu, 26 Jul 2018 14:42:37 +0300 Subject: [PATCH] Now the application does not start if it does not find ip, which starts with "fc" (ie, before starting the messenger, you need to run the cjdns daemon) --- src/kernel/network.cpp | 12 ++++++++++-- src/main.cpp | 4 ++++ src/mainwindow.cpp | 7 ++++++- src/mainwindow.h | 2 ++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/kernel/network.cpp b/src/kernel/network.cpp index 892c717..c055a6a 100644 --- a/src/kernel/network.cpp +++ b/src/kernel/network.cpp @@ -37,11 +37,19 @@ void Network::processTheDatagram() QString Network::localIPv6() { QHostAddress address; + QString addressString; foreach (address, QNetworkInterface::allAddresses()) { if (address.protocol() == QAbstractSocket::IPv6Protocol && address != QHostAddress(QHostAddress::LocalHostIPv6) && (address.toString()).contains("fc")) - break; + { + addressString = address.toString(); + break; + } + else + { + addressString = "null"; + } } - return(address.toString()); + return(addressString); } Network::~Network() diff --git a/src/main.cpp b/src/main.cpp index b48f94e..c86e878 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,10 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; + if(w.doQuit()) + { + return -1; + } w.show(); return a.exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 72178ff..ddb1da2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -5,8 +5,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi(this); network = new Network(false); + if(*network->myIPv6 == "null") + { + QMessageBox::critical(parent, tr("Cjdns is not running!"), tr("Cjdns is not running, so the application will be closed.")); + mDoQuit = true; + } + ui->setupUi(this); handler = new Handler(); timer = new QTimer(); connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm())); diff --git a/src/mainwindow.h b/src/mainwindow.h index 918790a..fa791d2 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -25,6 +25,7 @@ class MainWindow : public QMainWindow QVector pChatWindows; void setButtonToWaiting(); void setButtonToConnect(); + inline bool doQuit() const { return mDoQuit; } public slots: void peerReceiverAvailable(); private slots: @@ -42,4 +43,5 @@ class MainWindow : public QMainWindow Network *network; Handler *handler; bool receive = false; + bool mDoQuit = false; };