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)

This commit is contained in:
Denis Davydov 2018-07-26 14:42:37 +03:00
parent 3b58f486ec
commit 5231302217
4 changed files with 22 additions and 3 deletions

View File

@ -37,11 +37,19 @@ void Network::processTheDatagram()
QString Network::localIPv6() QString Network::localIPv6()
{ {
QHostAddress address; QHostAddress address;
QString addressString;
foreach (address, QNetworkInterface::allAddresses()) { foreach (address, QNetworkInterface::allAddresses()) {
if (address.protocol() == QAbstractSocket::IPv6Protocol && address != QHostAddress(QHostAddress::LocalHostIPv6) && (address.toString()).contains("fc")) 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() Network::~Network()

View File

@ -5,6 +5,10 @@ int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
if(w.doQuit())
{
return -1;
}
w.show(); w.show();
return a.exec(); return a.exec();

View File

@ -5,8 +5,13 @@ MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow) ui(new Ui::MainWindow)
{ {
ui->setupUi(this);
network = new Network(false); 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(); handler = new Handler();
timer = new QTimer(); timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm())); connect(timer, SIGNAL(timeout()), this, SLOT(slotTimerAlarm()));

View File

@ -25,6 +25,7 @@ class MainWindow : public QMainWindow
QVector<ChatWindow*> pChatWindows; QVector<ChatWindow*> pChatWindows;
void setButtonToWaiting(); void setButtonToWaiting();
void setButtonToConnect(); void setButtonToConnect();
inline bool doQuit() const { return mDoQuit; }
public slots: public slots:
void peerReceiverAvailable(); void peerReceiverAvailable();
private slots: private slots:
@ -42,4 +43,5 @@ class MainWindow : public QMainWindow
Network *network; Network *network;
Handler *handler; Handler *handler;
bool receive = false; bool receive = false;
bool mDoQuit = false;
}; };