From 70c7aa4a9476f0be7112a4090d4b53e696bfb956 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 19 May 2014 18:29:58 +0200 Subject: [PATCH] refs #240, removed text message parts from main GUI window * text message now encapsulated in component * adjusted main GUI window to be used with component --- samples/blackgui/mainwindow.h | 55 +-- samples/blackgui/mainwindow.ui | 170 +-------- samples/blackgui/mainwindow_cockpit.cpp | 4 +- samples/blackgui/mainwindow_init.cpp | 35 +- samples/blackgui/mainwindow_textmessages.cpp | 352 ------------------- 5 files changed, 47 insertions(+), 569 deletions(-) delete mode 100644 samples/blackgui/mainwindow_textmessages.cpp diff --git a/samples/blackgui/mainwindow.h b/samples/blackgui/mainwindow.h index 045402af1..702978f97 100644 --- a/samples/blackgui/mainwindow.h +++ b/samples/blackgui/mainwindow.h @@ -171,29 +171,6 @@ private: //! Update the COM frequency displays void updateComFrequencyDisplays(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2); - /*! - * \brief Add new text message tab - * \param tabName name of the new tab, usually the channel name - * \return - */ - QWidget *addNewTextMessageTab(const QString &tabName); - - //! Find text message tab by its name - QWidget *findTextMessageTabByName(const QString &name) const; - - /*! - * \brief Private channel text message - * \param textMessage - * \param sending sending or receiving - */ - void addPrivateChannelTextMessage(const BlackMisc::Network::CTextMessage &textMessage, bool sending = false); - - /*! - * Stub for sending a text message (eihter radio or private message). - * Sets sender / receiver depending on frequency / channel situation. - */ - BlackMisc::Network::CTextMessage getTextMessageStubForChannel(); - //! Audio device lists void setAudioDeviceLists(); @@ -208,12 +185,6 @@ private: */ void setTestPosition(const QString &wgsLatitude, const QString &wgsLongitude, const BlackMisc::Aviation::CAltitude &altitude); - //! Display the overlay window - void displayOverlayInfo(const QString &message = ""); - - //! Overlay info displaying status message - void displayOverlayInfo(const BlackMisc::CStatusMessage &message); - /*! * \brief Is given main page selected? * \param mainPage index to be checked @@ -221,9 +192,6 @@ private: */ bool isMainPageSelected(MainPageIndex mainPage) const; - //! For this text message's recepient, is the current tab selected? - bool isCorrespondingTextMessageTabSelected(BlackMisc::Network::CTextMessage textMessage) const; - //! Start all update timers void startUpdateTimers(); @@ -243,7 +211,7 @@ private: void audioTestUpdate(); //! Play notifcation sound - void playNotifcationSound(BlackSound::CSoundGenerator::Notification notification) const; + void playNotifcationSound(BlackSound::CNotificationSounds::Notification notification) const; //! Update simulator page with latest user aircraft data void updateSimulatorData(); @@ -276,13 +244,6 @@ private slots: */ void connectionStatusChanged(uint from, uint to, const QString &message); - /*! - * \brief Append text messages (received, to be sent) to GUI - * \param messages - * \param sending - */ - void appendTextMessagesToGui(const BlackMisc::Network::CTextMessageList &messages, bool sending = false); - //! Reload settings void reloadSettings(); @@ -332,12 +293,6 @@ private slots: //! Update timer void timerBasedUpdates(); - //! Command entered - void commandEntered(); - - //! Close text message tab - void closeTextMessageTab(); - //! Cockpit values changed void cockpitValuesChanged(); @@ -387,6 +342,14 @@ private slots: //! Toogle Windows stay on top void toogleWindowStayOnTop(); + //! Display the overlay window + //! Empty string hides window + void displayOverlayInfo(const QString &message = ""); + + //! Overlay info displaying status message + void displayOverlayInfo(const BlackMisc::CStatusMessage &message); + + }; #pragma pop_macro("interface") diff --git a/samples/blackgui/mainwindow.ui b/samples/blackgui/mainwindow.ui index d0c07b8c6..54a5cd5ed 100644 --- a/samples/blackgui/mainwindow.ui +++ b/samples/blackgui/mainwindow.ui @@ -461,7 +461,7 @@ QStatusBar QLabel { QFrame::NoFrame - 1 + 5 @@ -571,7 +571,7 @@ QStatusBar QLabel { 0 0 - 90 + 86 59 @@ -694,7 +694,7 @@ QStatusBar QLabel { 0 - + 0 @@ -743,7 +743,7 @@ QStatusBar QLabel { 0 - + @@ -765,7 +765,7 @@ QStatusBar QLabel { 0 - + @@ -1329,150 +1329,10 @@ QStatusBar QLabel { 0 - + - 0 + -1 - - - All - - - - 0 - - - 2 - - - 3 - - - 2 - - - 0 - - - - - QTextEdit::NoWrap - - - true - - - 10 - - - - - - - - UNICOM - - - - 0 - - - 2 - - - 3 - - - 2 - - - 0 - - - - - QTextEdit::NoWrap - - - true - - - 10 - - - - - - - - COM 1 - - - - 0 - - - 2 - - - 3 - - - 2 - - - 0 - - - - - QTextEdit::NoWrap - - - true - - - 10 - - - - - - - - COM 2 - - - - 0 - - - 2 - - - 3 - - - 2 - - - 0 - - - - - QTextEdit::NoWrap - - - true - - - 10 - - - - - @@ -1519,7 +1379,7 @@ QStatusBar QLabel { - 1 + 3 @@ -2944,6 +2804,12 @@ QStatusBar QLabel {
blackgui/atcstationcomponent.h
1 + + BlackGui::CTextMessageComponent + QTabWidget +
blackgui/textmessagecomponent.h
+ 1 +
cb_StatusWithDBus @@ -2951,7 +2817,7 @@ QStatusBar QLabel { le_StatusAudioContext tvp_StatusMessages le_CommandLineInput - twp_AtcStations + comp_AtcStations pb_CockpitToggleCom1 ds_CockpitCom1Active ds_CockpitCom1Standby @@ -2971,11 +2837,7 @@ QStatusBar QLabel { cb_CockpitVoiceRoom2Override tvp_CockpitVoiceRoom1 tvp_CockpitVoiceRoom2 - tw_TextMessages - te_TextMessagesAll - te_TextMessagesUnicom - te_TextMessagesCOM1 - te_TextMessagesCOM2 + comp_TextMessages tw_Settings tvp_SettingsTnServers le_SettingsTnCsName diff --git a/samples/blackgui/mainwindow_cockpit.cpp b/samples/blackgui/mainwindow_cockpit.cpp index 2e351bee1..e35088717 100644 --- a/samples/blackgui/mainwindow_cockpit.cpp +++ b/samples/blackgui/mainwindow_cockpit.cpp @@ -154,8 +154,8 @@ void MainWindow::updateCockpitFromContext() } // update some other GUI elements - this->ui->tw_TextMessages->setTabToolTip(this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM1), com1.getFrequencyActive().valueRoundedWithUnit(3)); - this->ui->tw_TextMessages->setTabToolTip(this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2), com2.getFrequencyActive().valueRoundedWithUnit(3)); + this->ui->comp_TextMessages->setTabToolTip(BlackGui::CTextMessageComponent::TextMessagesCom1, com1.getFrequencyActive().valueRoundedWithUnit(3)); + this->ui->comp_TextMessages->setTabToolTip(BlackGui::CTextMessageComponent::TextMessagesCom2, com2.getFrequencyActive().valueRoundedWithUnit(3)); } /* diff --git a/samples/blackgui/mainwindow_init.cpp b/samples/blackgui/mainwindow_init.cpp index bda4d9cfc..fce46ad4f 100644 --- a/samples/blackgui/mainwindow_init.cpp +++ b/samples/blackgui/mainwindow_init.cpp @@ -14,6 +14,7 @@ #include "blackcore/context_runtime.h" #include "blackgui/atcstationlistmodel.h" #include "blackgui/keyboardkeylistmodel.h" +#include "blackgui/textmessagecomponent.h" #include "blackmisc/avselcal.h" #include "blackmisc/project.h" #include @@ -111,7 +112,7 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) this->connect(this->getIContextNetwork(), &IContextNetwork::connectionTerminated, this, &MainWindow::connectionTerminated); this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &MainWindow::connectionStatusChanged); this->connect(this->getIContextSettings(), &IContextSettings::changedSettings, this, &MainWindow::changedSettings); - connect = this->connect(this->getIContextNetwork(), SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)), this, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList))); + connect = this->connect(this->getIContextNetwork(), SIGNAL(textMessagesReceived(BlackMisc::Network::CTextMessageList)), this->ui->comp_TextMessages, SLOT(appendTextMessagesToGui(BlackMisc::Network::CTextMessageList))); Q_ASSERT(connect); this->connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &MainWindow::simulatorConnectionChanged); this->connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::timerBasedUpdates); @@ -121,8 +122,8 @@ void MainWindow::init(const CRuntimeConfig &runtimeConfig) connect = this->connect(this->getIContextAudio(), &IContextAudio::audioTestCompleted, this, &MainWindow::audioTestUpdate); // sliders - this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this->ui->twp_Users, &BlackGui::CUserComponent::setUpdateIntervalSeconds); - this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this->ui->twp_Aircrafts, &BlackGui::CAircraftComponent::setUpdateIntervalSeconds); + this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this->ui->comp_Users, &BlackGui::CUserComponent::setUpdateIntervalSeconds); + this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this->ui->comp_Aircrafts, &BlackGui::CAircraftComponent::setUpdateIntervalSeconds); Q_ASSERT(connect); Q_UNUSED(connect); // suppress GCC warning in release build @@ -220,8 +221,12 @@ void MainWindow::initGuiSignals() this->connect(this->ui->menu_FileSettingsDirectory, &QAction::triggered, this, &MainWindow::menuClicked); this->connect(this->ui->menu_FileResetSettings, &QAction::triggered, this, &MainWindow::menuClicked); - // command line - this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &MainWindow::commandEntered); + // command line / text messages + connected = this->connect(this->ui->le_CommandLineInput, SIGNAL(returnPressed()), this->ui->comp_TextMessages, SLOT(commandEntered())); + Q_ASSERT(connected); + this->connect(this->ui->comp_TextMessages, SIGNAL(displayOverlayInfo(BlackMisc::CStatusMessage)), this, SLOT(displayOverlayInfo(BlackMisc::CStatusMessage))); + Q_ASSERT(connected); + this->ui->comp_TextMessages->setSelcalCallback(std::bind(&MainWindow::getSelcalCode, this)); // cockpit connected = this->connect(this->ui->cbp_CockpitTransponderMode, SIGNAL(currentIndexChanged(QString)), this, SLOT(cockpitValuesChanged())); @@ -289,12 +294,12 @@ void MainWindow::initialDataReads() if (this->getIContextNetwork()->isConnected()) { // connection is already established - this->ui->twp_Aircrafts->update(); - this->ui->twp_AtcStations->update(); + this->ui->comp_Aircrafts->update(); + this->ui->comp_AtcStations->update(); this->updateGuiStatusInformation(); - this->ui->twp_Users->update(); - this->ui->twp_Aircrafts->update(); + this->ui->comp_Users->update(); + this->ui->comp_Aircrafts->update(); } this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeGui, CStatusMessage::SeverityInfo, "initial data read")); @@ -305,9 +310,9 @@ void MainWindow::initialDataReads() */ void MainWindow::startUpdateTimers() { - this->ui->twp_Aircrafts->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAtcRefreshTime->value()); - this->ui->twp_AtcStations->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAircraftRefreshTime->value()); - this->ui->twp_Users->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiUserRefreshTime->value()); + this->ui->comp_Aircrafts->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAtcRefreshTime->value()); + this->ui->comp_AtcStations->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiAircraftRefreshTime->value()); + this->ui->comp_Users->setUpdateIntervalSeconds(this->ui->hs_SettingsGuiUserRefreshTime->value()); } /* @@ -315,9 +320,9 @@ void MainWindow::startUpdateTimers() */ void MainWindow::stopUpdateTimers() { - this->ui->twp_AtcStations->stopTimer(); - this->ui->twp_Aircrafts->stopTimer(); - this->ui->twp_Users->stopTimer(); + this->ui->comp_AtcStations->stopTimer(); + this->ui->comp_Aircrafts->stopTimer(); + this->ui->comp_Users->stopTimer(); } void MainWindow::stopAllTimers(bool disconnect) diff --git a/samples/blackgui/mainwindow_textmessages.cpp b/samples/blackgui/mainwindow_textmessages.cpp deleted file mode 100644 index c7512c264..000000000 --- a/samples/blackgui/mainwindow_textmessages.cpp +++ /dev/null @@ -1,352 +0,0 @@ -#include "mainwindow.h" -#include "ui_mainwindow.h" -#include "blacksound/soundgenerator.h" - -using namespace BlackCore; -using namespace BlackMisc; -using namespace BlackGui; -using namespace BlackMisc::Network; -using namespace BlackMisc::Aviation; -using namespace BlackMisc::PhysicalQuantities; -using namespace BlackMisc::Geo; -using namespace BlackMisc::Settings; -using namespace BlackMisc::Audio; - -/* - * Text messages received or send, append to GUI - */ -void MainWindow::appendTextMessagesToGui(const CTextMessageList &messages, bool sending) -{ - if (messages.isEmpty()) return; - foreach(CTextMessage message, messages) - { - const QString currentSelcal = this->getSelcalCode(); - if (CSelcal::isValidCode(currentSelcal) && message.isSelcalMessageFor(currentSelcal)) - { - if (this->m_ownAircraft.isActiveFrequencyWithin25kHzChannel(message.getFrequency())) - { - // this is SELCAL for me - if (this->m_contextAudioAvailable) - { - CAudioDevice dev = this->getIContextAudio()->getCurrentAudioDevices().getOutputDevices()[0]; - BlackSound::CSoundGenerator::playSelcal(90, CSelcal(currentSelcal), dev); - } - else - { - this->displayOverlayInfo("SELCAL received"); - } - } - continue; // not displayed - } - - bool relevantForMe = false; - QString m = message.asString(true, true, "\t"); - m = message.asString(true, false, "\t"); - - if (message.isSendToUnicom()) - { - this->ui->te_TextMessagesUnicom->append(m); - relevantForMe = true; - } - - // check message - if (message.isRadioMessage()) - { - // check for own COM frequencies - if (message.isSendToFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive())) - { - this->ui->te_TextMessagesCOM1->append(m); - relevantForMe = true; - } - if (message.isSendToFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive())) - { - this->ui->te_TextMessagesCOM2->append(m); - relevantForMe = true; - } - } - else if (message.isPrivateMessage() && !message.isServerMessage()) - { - // private message - this->addPrivateChannelTextMessage(message, sending); - relevantForMe = true; - } - - // message for me? right frequency? otherwise quit - if (relevantForMe || message.isServerMessage()) this->ui->te_TextMessagesAll->append(m); - if (!relevantForMe) return; - - // overlay message if this channel is not selected - if (!sending && !message.isSendToUnicom() && !message.isServerMessage()) - { - // if the channel is selected, do nothing - if (!this->isCorrespondingTextMessageTabSelected(message)) - this->displayOverlayInfo(m); - } - } -} - -/* - * Is the tab of the message's receiver selected? - */ -bool MainWindow::isCorrespondingTextMessageTabSelected(CTextMessage textMessage) const -{ - if (!this->isMainPageSelected(MainPageTextMessages)) return false; - if (!textMessage.hasValidRecipient()) return false; - if (textMessage.isEmpty()) return false; // ignore empty message - if (textMessage.isPrivateMessage()) - { - // private message - CCallsign cs = textMessage.getSenderCallsign(); - if (cs.isEmpty()) return false; - QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet()); - if (!tab) return false; - return this->ui->tw_TextMessages->currentWidget() == tab; - } - else - { - // frequency message - if (this->ui->tw_TextMessages->currentWidget() == this->ui->tb_TextMessagesAll) return true; - if (textMessage.isSendToFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive())) - return this->ui->tw_TextMessages->currentWidget() == this->ui->tb_TextMessagesCOM1; - if (textMessage.isSendToFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive())) - return this->ui->tw_TextMessages->currentWidget() == this->ui->tb_TextMessagesCOM2; - return false; - } -} - -/* - * Add new text message tab - */ -QWidget *MainWindow::addNewTextMessageTab(const QString &tabName) -{ - QWidget *newTab = new QWidget(this->ui->tw_TextMessages); - QPushButton *closeButton = new QPushButton("Close", newTab); - QVBoxLayout *layout = new QVBoxLayout(newTab); - QTextEdit *textEdit = new QTextEdit(newTab); - int marginLeft, marginRight, marginTop, marginBottom; - this->ui->tb_TextMessagesAll->layout()->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom); - newTab->layout()->setContentsMargins(marginLeft, marginTop, marginRight, 2); - textEdit->setReadOnly(true); - textEdit->setWordWrapMode(QTextOption::NoWrap); - layout->addWidget(textEdit); - layout->addWidget(closeButton); - newTab->setLayout(layout); - int index = this->ui->tw_TextMessages->addTab(newTab, tabName); - this->connect(closeButton, SIGNAL(released()), this, SLOT(closeTextMessageTab())); - this->ui->tw_TextMessages->setCurrentIndex(index); - return newTab; -} - -/* - * Add a private channel text message - */ -void MainWindow::addPrivateChannelTextMessage(const CTextMessage &textMessage, bool sending) -{ - if (!textMessage.isPrivateMessage()) return; - CCallsign cs = sending ? textMessage.getRecipientCallsign() : textMessage.getSenderCallsign(); - if (cs.isEmpty()) return; - QWidget *tab = this->findTextMessageTabByName(cs.getStringAsSet()); - if (tab == nullptr) tab = this->findTextMessageTabByName(cs.asString()); - if (tab == nullptr) tab = this->addNewTextMessageTab(cs.getStringAsSet()); - Q_ASSERT(tab != nullptr); - QTextEdit *textEdit = tab->findChild(); - Q_ASSERT(textEdit != nullptr); - if (textEdit == nullptr) return; // do not crash, though this situation could not happen - textEdit->append(textMessage.asString(true, false, "\t")); - - // sound - this->playNotifcationSound(BlackSound::CSoundGenerator::NotificationTextMessage); -} - -/* - * Message tab by name - */ -QWidget *MainWindow::findTextMessageTabByName(const QString &name) const -{ - if (name.isEmpty()) return nullptr; - QString n = name.trimmed(); - for (int index = 0; index < this->ui->tw_TextMessages->count(); index++) - { - QString tabName = this->ui->tw_TextMessages->tabText(index); - if (tabName.indexOf(n, 0, Qt::CaseInsensitive) < 0) continue; - QWidget *tab = this->ui->tw_TextMessages->widget(index); - return tab; - } - return nullptr; -} - -/* - * Text message stub (sender/receiver) for current channel - */ -CTextMessage MainWindow::getTextMessageStubForChannel() -{ - CTextMessage tm; - int index = this->ui->tw_TextMessages->currentIndex(); - if (index < 0) return tm; - if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesAll)) return tm; - - // from - tm.setSenderCallsign(this->m_ownAircraft.getCallsign()); - - // frequency text message? - if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM1)) - { - tm.setFrequency(this->m_ownAircraft.getCom1System().getFrequencyActive()); - } - else if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesCOM2)) - { - tm.setFrequency(this->m_ownAircraft.getCom2System().getFrequencyActive()); - } - else if (index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesUnicom)) - { - tm.setFrequency(CPhysicalQuantitiesConstants::FrequencyUnicom()); - } - else - { - // not a standard channel - QString selectedTabText = this->ui->tw_TextMessages->tabText(index); - bool isNumber; - double frequency = selectedTabText.toDouble(&isNumber); - if (isNumber) - { - CFrequency radioFrequency = CFrequency(frequency, CFrequencyUnit::MHz()); - if (CComSystem::isValidCivilAviationFrequency(radioFrequency)) - { - tm.setFrequency(radioFrequency); - } - else - { - CCallsign toCallsign(selectedTabText); - tm.setRecipientCallsign(toCallsign); - } - } - else - { - CCallsign toCallsign(selectedTabText); - tm.setRecipientCallsign(toCallsign); - } - } - return tm; // now valid message stub with receiver -} - -/* - * Close message tab - */ -void MainWindow::closeTextMessageTab() -{ - QObject *sender = QObject::sender(); - QWidget *parentWidget = qobject_cast(sender->parent()); - int index = -1; - - while (index < 0 && parentWidget) - { - index = this->ui->tw_TextMessages->indexOf(parentWidget); - parentWidget = parentWidget->parentWidget(); - } - if (index >= 0) this->ui->tw_TextMessages->removeTab(index); -} - -/* - * Command entered - */ -void MainWindow::commandEntered() -{ - // TODO: just a first draft of the command line parser - // needs to be refactored, as soon as a first version works - - QString cmdLine = this->ui->le_CommandLineInput->text().simplified(); - if (cmdLine.isEmpty()) return; - QList parts = cmdLine.toLower().split(' '); - if (parts.length() < 1) return; - QString cmd = parts[0].startsWith('.') ? parts[0].toLower() : ""; - if (cmd == ".m" || cmd == ".msg") - { - if (!this->m_contextNetworkAvailable || !this->getIContextNetwork()->isConnected()) - { - this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "network needs to be connected")); - return; - } - if (parts.length() < 3) - { - this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError, "incorrect message")); - return; - } - QString p = parts[1].trimmed(); // receiver - - // select current tab by command - this->setMainPage(MainPageTextMessages); - if (p == "c1" || p == "com1") - { - this->ui->tw_TextMessages->setCurrentWidget(this->ui->tb_TextMessagesCOM1); - } - else if (p == "c2" || p == "com2") - { - this->ui->tw_TextMessages->setCurrentWidget(this->ui->tb_TextMessagesCOM2); - } - else if (p == "u" || p == "unicom" || p == "uni") - { - this->ui->tw_TextMessages->setCurrentWidget(this->ui->tb_TextMessagesUnicom); - } - else - { - QWidget *tab = this->findTextMessageTabByName(p.trimmed()); - if (tab == nullptr) tab = this->addNewTextMessageTab(p.trimmed().toUpper()); - this->ui->tw_TextMessages->setCurrentWidget(tab); - } - CTextMessage tm = this->getTextMessageStubForChannel(); - int index = cmdLine.indexOf(tm.getRecipientCallsign().getStringAsSet(), 0, Qt::CaseInsensitive); - if (index < 0) - { - this->displayStatusMessage( - CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError, - "incomplete message") - ); - return; - } - QString msg(cmdLine.mid(index + tm.getRecipientCallsign().asString().length() + 1)); - tm.setMessage(msg); - if (tm.isEmpty()) return; - if (!this->isContextNetworkAvailableCheck()) return; - CTextMessageList tml(tm); - this->getIContextNetwork()->sendTextMessages(tml); - this->appendTextMessagesToGui(tml, true); - this->ui->le_CommandLineInput->setText(""); - } - else if (cmd.startsWith(".")) - { - // dump CMDs - } - else - { - // single line, no command - // line is considered to be a message to the selected channel, send - if (!this->getIContextNetwork()->isConnected()) - { - this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "network needs to be connected")); - return; - } - - if (!this->isMainPageSelected(MainPageTextMessages)) - { - this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "text messages can only be sent from corresponding page")); - return; - } - - int index = this->ui->tw_TextMessages->currentIndex(); - if (index < 0 || index == this->ui->tw_TextMessages->indexOf(this->ui->tb_TextMessagesAll)) - { - this->displayStatusMessage(CStatusMessage(CStatusMessage::TypeValidation, CStatusMessage::SeverityError, "incorrect channel")); - } - else - { - CTextMessage tm = this->getTextMessageStubForChannel(); - tm.setMessage(cmdLine); - if (tm.isEmpty()) return; - if (!this->isContextNetworkAvailableCheck()) return; - CTextMessageList textMessageList(tm); - this->getIContextNetwork()->sendTextMessages(textMessageList); - this->appendTextMessagesToGui(textMessageList, true); - this->ui->le_CommandLineInput->setText(""); - } - } -}