diff options
| author | Anton <anton@picapica> | 2019-03-06 18:07:59 +0400 |
|---|---|---|
| committer | Anton <anton@picapica> | 2019-03-06 18:07:59 +0400 |
| commit | 73c06c18c5c6401ee08748ebed08c8896f63e344 (patch) | |
| tree | b832d62390181848e8d0b0efc7c5b9954c50e2b6 /pica-client | |
| parent | 032eb1f23992568e3ddd7946f94cd69a464167ba (diff) | |
| download | pica-pica-73c06c18c5c6401ee08748ebed08c8896f63e344.tar.gz pica-pica-73c06c18c5c6401ee08748ebed08c8896f63e344.zip | |
pica-client: display connection status, ciphersuite in chat window
Diffstat (limited to 'pica-client')
| -rw-r--r-- | pica-client/chatwindow.cpp | 17 | ||||
| -rw-r--r-- | pica-client/chatwindow.h | 4 | ||||
| -rw-r--r-- | pica-client/msguirouter.cpp | 14 | ||||
| -rw-r--r-- | pica-client/msguirouter.h | 2 | ||||
| -rw-r--r-- | pica-client/skynet.cpp | 12 | ||||
| -rw-r--r-- | pica-client/skynet.h | 4 |
6 files changed, 47 insertions, 6 deletions
diff --git a/pica-client/chatwindow.cpp b/pica-client/chatwindow.cpp index f1835d7..f50d489 100644 --- a/pica-client/chatwindow.cpp +++ b/pica-client/chatwindow.cpp @@ -28,7 +28,7 @@ #include <QMessageBox> -ChatWindow::ChatWindow(QByteArray peer_id) : +ChatWindow::ChatWindow(QByteArray peer_id, QString status) : QWidget(0), peer_id_(peer_id), hist(config_dbname, Accounts::GetCurrentAccount().id) { QVBoxLayout *layout; @@ -58,6 +58,7 @@ ChatWindow::ChatWindow(QByteArray peer_id) : layout = new QVBoxLayout; + lbConnStatus = new QLabel(status); chatw = new QTextEdit(this); sendtextw = new TextSend(this); @@ -67,8 +68,17 @@ ChatWindow::ChatWindow(QByteArray peer_id) : sendtextw->setMinimumWidth(240); sendtextw->setAcceptRichText(false); + { + QFont f = lbConnStatus->font(); + f.setBold(true); + //f.setItalic(true); + f.setStyleHint(QFont::Monospace); + lbConnStatus->setFont(f); + } + chatw->setReadOnly(true); + layout->addWidget(lbConnStatus, 0); layout->addWidget(chatw, 3); layout->addWidget(sendtextw, 1, Qt::AlignBottom); @@ -122,6 +132,11 @@ ChatWindow::ChatWindow(QByteArray peer_id) : } +void ChatWindow::update_status(QString status) +{ + lbConnStatus->setText(status); +} + void ChatWindow::put_message(QString msg, QByteArray id, bool is_me) { QString color, name; diff --git a/pica-client/chatwindow.h b/pica-client/chatwindow.h index 7b653f4..fa306a9 100644 --- a/pica-client/chatwindow.h +++ b/pica-client/chatwindow.h @@ -44,7 +44,7 @@ class ChatWindow : public QWidget { Q_OBJECT public: - explicit ChatWindow(QByteArray peer_id); + explicit ChatWindow(QByteArray peer_id, QString status); QByteArray getPeerId() { @@ -61,6 +61,7 @@ public slots: void msg_delivered(); void msg_informational(QString text);//юзер в оффлайне, набирает сообщение, и т.д. серым шрифтом, курсив void set_peer_name(); + void update_status(QString status); private: @@ -80,6 +81,7 @@ private: QPushButton *btAddCtNo; QPushButton *btAddCtBlacklist; QLabel *lbAddCtQuestion; + QLabel *lbConnStatus; bool isEmptyMessage(const QString &msg) const; void put_message(QString msg, QByteArray id, bool is_me); diff --git a/pica-client/msguirouter.cpp b/pica-client/msguirouter.cpp index f3d0916..4736006 100644 --- a/pica-client/msguirouter.cpp +++ b/pica-client/msguirouter.cpp @@ -42,6 +42,7 @@ MsgUIRouter::MsgUIRouter(QObject *parent) : connect(skynet, SIGNAL(CertificateForged(QByteArray, QString, QString)), this, SLOT(scary_cert_message(QByteArray, QString, QString))); connect(skynet, SIGNAL(StatusMsg(QString, bool)), this, SLOT(notification(QString, bool))); connect(systray, SIGNAL(doubleclicked()), this, SLOT(trayicon_dclick())); + connect(skynet, SIGNAL(ConnectionStatusUpdated(QByteArray,QString)), this, SLOT(update_status(QByteArray,QString))); } @@ -80,11 +81,22 @@ void MsgUIRouter::trayicon_dclick() } } +void MsgUIRouter::update_status(QByteArray peer_id, QString status) +{ + connstatus[peer_id] = status; + + if (chatwindows.contains(peer_id)) + chatwindows[peer_id]->update_status(status); +} + void MsgUIRouter::create_chatwindow(QByteArray peer_id) { ChatWindow *cw; - cw = new ChatWindow(peer_id); + if (!connstatus.contains(peer_id)) + connstatus[peer_id] = QString(tr("Disconnected")); + + cw = new ChatWindow(peer_id, connstatus[peer_id]); chatwindows[peer_id] = cw; diff --git a/pica-client/msguirouter.h b/pica-client/msguirouter.h index 32890c0..b908323 100644 --- a/pica-client/msguirouter.h +++ b/pica-client/msguirouter.h @@ -45,10 +45,12 @@ public slots: void scary_cert_message(QByteArray peer_id, QString received_cert, QString stored_cert); void notification(QString text, bool is_critical); + void update_status(QByteArray peer_id, QString status); void trayicon_dclick(); private: QMap<QByteArray, ChatWindow*> chatwindows; + QMap<QByteArray, QString> connstatus; QLinkedList<QByteArray> blinkqueue; void create_chatwindow(QByteArray peer_id); diff --git a/pica-client/skynet.cpp b/pica-client/skynet.cpp index 906e673..da39a3b 100644 --- a/pica-client/skynet.cpp +++ b/pica-client/skynet.cpp @@ -350,7 +350,7 @@ void SkyNet::timerEvent(QTimerEvent *e) ret = PICA_new_c2c(active_nodelink, (const unsigned char*)c2c_peer_ids[i].constData(), NULL, &chan); - qDebug() << "restoring c2c to " << c2c_peer_ids[i] << " ret =" << ret << " in timer event\n"; + qDebug() << "restoring c2c to " << c2c_peer_ids[i].toBase64() << " ret =" << ret << " in timer event\n"; } @@ -889,6 +889,11 @@ void SkyNet::emit_MultiloginMessageReceived(quint64 timestamp, QString node_addr emit MultiloginMessageReceived(timestamp, node_addr, node_port); } +void SkyNet::emit_ConnectionStatusUpdated(QByteArray peer_id, QString status) +{ + emit ConnectionStatusUpdated(peer_id, status); +} + //callbacks void SkyNet::newmsg_cb(const unsigned char *peer_id, const char *msgbuf, unsigned int nb, int type) @@ -903,14 +908,16 @@ void SkyNet::msgok_cb(const unsigned char *peer_id) skynet->emit_Delivered(QByteArray((const char*)peer_id, PICA_ID_SIZE)); } -void SkyNet::c2c_established_cb(const unsigned char *peer_id) +void SkyNet::c2c_established_cb(const unsigned char *peer_id, const char *ciphersuitename) { + skynet->emit_ConnectionStatusUpdated(QByteArray((const char*)peer_id, PICA_ID_SIZE), QString("🔐: %1").arg(ciphersuitename)); skynet->flush_queues(QByteArray((const char*)peer_id, PICA_ID_SIZE)); } void SkyNet::c2c_failed(const unsigned char *peer_id) { qDebug() << "c2c failed (" << QByteArray((const char*)peer_id, PICA_ID_SIZE).toBase64() << ")\n"; + skynet->emit_ConnectionStatusUpdated(QByteArray((const char*)peer_id, PICA_ID_SIZE), QString(tr("Failed to connect"))); } int SkyNet::accept_cb(const unsigned char *caller_id) @@ -941,6 +948,7 @@ void SkyNet::c2c_closed_cb(const unsigned char *peer_id, int reason) << ", error_code =" << reason << ")\n"; skynet->emit_c2cClosed(QByteArray((const char*)peer_id, PICA_ID_SIZE)); + skynet->emit_ConnectionStatusUpdated(QByteArray((const char*)peer_id, PICA_ID_SIZE), QString(tr("Disconnected"))); } void SkyNet::nodelist_cb(int type, void *addr_bin, const char *addr_str, unsigned int port) diff --git a/pica-client/skynet.h b/pica-client/skynet.h index 32b574f..cefcb91 100644 --- a/pica-client/skynet.h +++ b/pica-client/skynet.h @@ -75,6 +75,7 @@ signals: void OutgoingFileFinished(QByteArray peer_id); void IncomingFileFinished(QByteArray peer_id); void MultiloginMessageReceived(quint64 timestamp, QString node_addr, quint16 node_port); + void ConnectionStatusUpdated(QByteArray peer_id, QString status); void c2cClosed(QByteArray peer_id); @@ -129,13 +130,14 @@ private: void emit_MultiloginMessageReceived(quint64 timestamp, QString node_addr, quint16 node_port); void emit_c2cClosed(QByteArray peer_id); + void emit_ConnectionStatusUpdated(QByteArray peer_id, QString status); //получение сообщения. static void newmsg_cb(const unsigned char *peer_id, const char* msgbuf, unsigned int nb, int type); //получение подтверждения о доставке сообщения static void msgok_cb(const unsigned char *peer_id); //создание канала с собеседником - static void c2c_established_cb(const unsigned char *peer_id); + static void c2c_established_cb(const unsigned char *peer_id, const char *ciphersuitename); //создать канал не удалось static void c2c_failed(const unsigned char *peer_id); //входящий запрос на создание канала от пользователя с номером caller_id |
