Working through message window wireup

This commit is contained in:
Jordan Sherer 2019-02-02 17:06:01 -05:00
parent 9a64af0879
commit a314d29115
4 changed files with 266 additions and 10 deletions

View File

@ -1380,6 +1380,40 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
displayActivity(true);
});
auto historyAction = new QAction(QString("Message History..."), ui->tableWidgetCalls);
connect(historyAction, &QAction::triggered, this, [this](){
QString selectedCall = callsignSelected();
if(selectedCall.isEmpty()){
return;
}
Inbox inbox(inboxPath());
if(!inbox.open()){
return;
}
QList<Message> msgs;
foreach(auto pair, inbox.values("UNREAD", "$.params.FROM", selectedCall, 0, 1000)){
msgs.append(pair.second);
}
foreach(auto pair, inbox.values("READ", "$.params.FROM", selectedCall, 0, 1000)){
msgs.append(pair.second);
}
qStableSort(msgs.begin(), msgs.end(), [](Message const &a, Message const &b){
return a.params().value("UTC") < b.params().value("UTC");
});
auto mw = new MessageWindow(this);
connect(mw, &MessageWindow::replyMessage, this, [this](const QString &text){
addMessageText(text, true, false);
toggleTx(true);
});
mw->setCall(selectedCall);
mw->populateMessages(msgs);
mw->show();
});
ui->tableWidgetCalls->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableWidgetCalls->horizontalHeader(), &QHeaderView::customContextMenuRequested, this, [this](QPoint const &point){
QMenu * menu = new QMenu(ui->tableWidgetCalls);
@ -1390,13 +1424,14 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
});
ui->tableWidgetCalls->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tableWidgetCalls, &QTableWidget::customContextMenuRequested, this, [this, logAction, clearAction4, clearActionAll, addStation, removeStation](QPoint const &point){
connect(ui->tableWidgetCalls, &QTableWidget::customContextMenuRequested, this, [this, logAction, historyAction, clearAction4, clearActionAll, addStation, removeStation](QPoint const &point){
QMenu * menu = new QMenu(ui->tableWidgetCalls);
ui->tableWidgetRXAll->selectionModel()->clearSelection();
QString selectedCall = callsignSelected();
bool isAllCall = isAllCallIncluded(selectedCall);
bool isGroupCall = isGroupCallIncluded(selectedCall);
bool missingCallsign = selectedCall.isEmpty();
if(!missingCallsign && !isAllCall){
@ -1413,6 +1448,9 @@ MainWindow::MainWindow(QDir const& temp_directory, bool multiple,
menu->addAction(logAction);
logAction->setDisabled(missingCallsign || isAllCall);
menu->addAction(historyAction);
historyAction->setDisabled(missingCallsign || isAllCall || isGroupCall);
menu->addSeparator();
auto savedMenu = menu->addMenu("Saved messages...");
@ -7832,7 +7870,9 @@ void MainWindow::on_tableWidgetCalls_cellDoubleClicked(int row, int col){
on_tableWidgetCalls_cellClicked(row, col);
auto call = callsignSelected();
addMessageText(call);
#if 0
if(m_rxInboxCountCache.value(call, 0) > 0){
// TODO:
@ -7843,6 +7883,15 @@ void MainWindow::on_tableWidgetCalls_cellDoubleClicked(int row, int col){
Inbox i(inboxPath());
if(i.open()){
QList<Message> msgs;
foreach(auto pair, i.values("UNREAD", "$.params.FROM", call, 0, 1000)){
msgs.append(pair.second);
}
auto mw = new MessageWindow(this);
mw->populateMessages(msgs);
mw->show();
auto pair = i.firstUnreadFrom(call);
auto id = pair.first;
auto msg = pair.second;
@ -7873,6 +7922,7 @@ void MainWindow::on_tableWidgetCalls_cellDoubleClicked(int row, int col){
} else {
addMessageText(call);
}
#endif
}
void MainWindow::on_tableWidgetCalls_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected){

View File

@ -1,14 +1,45 @@
#include "messagewindow.h"
#include "ui_messagewindow.h"
#include "moc_messagewindow.cpp"
#include <QDateTime>
#include "Radio.hpp"
#include "keyeater.h"
template<typename T>
QList<T> listCopyReverse(QList<T> const &list){
QList<T> newList = QList<T>();
auto iter = list.end();
while(iter != list.begin()){
newList.append(*(--iter));
}
return newList;
}
MessageWindow::MessageWindow(QWidget *parent) :
QWidget(parent),
QDialog(parent),
ui(new Ui::MessageWindow)
{
ui->setupUi(this);
this->setWindowTitle("Message History");
// connect selection model changed
connect(ui->messageTableWidget->selectionModel(), &QItemSelectionModel::selectionChanged, this, &MessageWindow::on_messageTableWidget_selectionChanged);
// reply when key pressed in the reply box
auto eke = new EnterKeyPressEater();
connect(eke, &EnterKeyPressEater::enterKeyPressed, this, [this](QObject *, QKeyEvent * e, bool *pProcessed){
if(e->modifiers() & Qt::ShiftModifier){
if(pProcessed) *pProcessed = false;
return;
}
if(pProcessed) *pProcessed = true;
ui->replyPushButton->click();
});
ui->replytextEdit->installEventFilter(eke);
ui->messageTableWidget->horizontalHeader()->setVisible(true);
ui->messageTableWidget->resizeColumnsToContents();
}
@ -16,3 +47,97 @@ MessageWindow::~MessageWindow()
{
delete ui;
}
void MessageWindow::setCall(const QString &call){
setWindowTitle(QString("Message History: %1").arg(call));
}
void MessageWindow::populateMessages(QList<Message> msgs){
for(int i = ui->messageTableWidget->rowCount(); i >= 0; i--){
ui->messageTableWidget->removeRow(i);
}
ui->messageTableWidget->setUpdatesEnabled(false);
{
foreach(auto msg, msgs){
auto params = msg.params();
int row = ui->messageTableWidget->rowCount();
ui->messageTableWidget->insertRow(row);
int col = 0;
auto typeItem = new QTableWidgetItem(msg.type() == "UNREAD" ? "\u2691" : "");
typeItem->setData(Qt::UserRole, msg.type());
typeItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
ui->messageTableWidget->setItem(row, col++, typeItem);
auto date = params.value("UTC").toString();
auto timestamp = QDateTime::fromString(date, "yyyy-MM-dd hh:mm:ss");
auto dateItem = new QTableWidgetItem(timestamp.toString());
dateItem->setData(Qt::UserRole, timestamp);
dateItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
ui->messageTableWidget->setItem(row, col++, dateItem);
auto dial = (quint64)params.value("DIAL").toInt();
auto dialItem = new QTableWidgetItem(QString("%1 MHz").arg(Radio::pretty_frequency_MHz_string(dial)));
dialItem->setData(Qt::UserRole, dial);
dialItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
ui->messageTableWidget->setItem(row, col++, dialItem);
auto path = params.value("PATH").toString();
auto segs = listCopyReverse(path.split(">"));
auto fromItem = new QTableWidgetItem(segs.join(" via "));
fromItem->setData(Qt::UserRole, path);
fromItem->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
ui->messageTableWidget->setItem(row, col++, fromItem);
auto text = params.value("TEXT").toString();
auto textItem = new QTableWidgetItem(text);
textItem->setData(Qt::UserRole, text);
textItem->setTextAlignment(Qt::AlignVCenter);
ui->messageTableWidget->setItem(row, col++, textItem);
}
ui->messageTableWidget->resizeColumnToContents(0);
ui->messageTableWidget->resizeColumnToContents(1);
ui->messageTableWidget->resizeColumnToContents(2);
ui->messageTableWidget->resizeColumnToContents(3);
}
ui->messageTableWidget->setUpdatesEnabled(true);
if(ui->messageTableWidget->rowCount() > 0){
ui->messageTableWidget->selectRow(0);
}
}
QString MessageWindow::prepareReplyMessage(QString path){
auto text = ui->replytextEdit->toPlainText();
return QString("%1 MSG %2").arg(path).arg(text);
}
void MessageWindow::on_messageTableWidget_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/){
auto row = ui->messageTableWidget->currentRow();
auto item = ui->messageTableWidget->item(row, ui->messageTableWidget->columnCount()-1);
if(!item){
return;
}
auto text = item->data(Qt::UserRole).toString();
ui->messageTextEdit->setPlainText(text);
}
void MessageWindow::on_replyPushButton_clicked(){
auto row = ui->messageTableWidget->currentRow();
auto item = ui->messageTableWidget->item(row, ui->messageTableWidget->columnCount()-2);
if(!item){
return;
}
auto path = item->data(Qt::UserRole).toString();
auto message = prepareReplyMessage(path);
emit replyMessage(message);
close();
}

View File

@ -1,13 +1,16 @@
#ifndef MESSAGEWINDOW_H
#define MESSAGEWINDOW_H
#include <QWidget>
#include <QDialog>
#include <QItemSelection>
#include "Message.h"
namespace Ui {
class MessageWindow;
}
class MessageWindow : public QWidget
class MessageWindow : public QDialog
{
Q_OBJECT
@ -15,6 +18,18 @@ public:
explicit MessageWindow(QWidget *parent = 0);
~MessageWindow();
signals:
void replyMessage(const QString &call);
public slots:
void setCall(const QString &call);
void populateMessages(QList<Message> msgs);
QString prepareReplyMessage(QString path);
private slots:
void on_messageTableWidget_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/);
void on_replyPushButton_clicked();
private:
Ui::MessageWindow *ui;
};

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MessageWindow</class>
<widget class="QWidget" name="MessageWindow">
<widget class="QDialog" name="MessageWindow">
<property name="geometry">
<rect>
<x>0</x>
@ -11,7 +11,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
<string>Message History</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
@ -38,21 +38,74 @@
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>4</verstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Received band activity is displayed with time since last heard, SNR, and the text received for each frequency offset in the passband.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
<property name="autoScroll">
<bool>false</bool>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="showDropIndicator" stdset="0">
<bool>false</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="textElideMode">
<enum>Qt::ElideRight</enum>
</property>
<property name="gridStyle">
<enum>Qt::DotLine</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderDefaultSectionSize">
<number>30</number>
</attribute>
<attribute name="horizontalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderMinimumSectionSize">
<number>10</number>
<number>20</number>
</attribute>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>⚑</string>
@ -66,6 +119,11 @@
<string>Date</string>
</property>
</column>
<column>
<property name="text">
<string>Frequency</string>
</property>
</column>
<column>
<property name="text">
<string>From</string>
@ -79,7 +137,7 @@
</widget>
<widget class="QTextEdit" name="messageTextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
@ -93,6 +151,14 @@
<string notr="true">QTextEdit { background-color:#ffeaa7; }</string>
</property>
</widget>
<widget class="QTextEdit" name="replytextEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
</widget>
</widget>
</item>
<item>