@ -10,7 +10,6 @@
# include "addressbook.h"
# include "ui_memodialog.h"
# include "ui_contactrequest.h"
# include "addressbook.h"
# include <QtWidgets>
# include <QUuid>
# include "DataStore/DataStore.h"
@ -27,20 +26,6 @@ ChatModel::ChatModel(std::vector<ChatItem> chatItems)
this - > setItems ( chatItems ) ;
}
/*QString ChatModel::generateChatItemID(ChatItem item)
{
QString key = QString : : number ( item . getTimestamp ( ) ) + QString ( " - " ) ;
key + = QString ( QCryptographicHash : : hash (
QString (
QString : : number ( item . getTimestamp ( ) ) +
item . getAddress ( ) +
item . getContact ( ) +
item . getMemo ( )
) . toUtf8 ( )
, QCryptographicHash : : Md5 ) . toHex ( ) ) ;
return key ;
} */
std : : map < QString , ChatItem > ChatModel : : getItems ( )
{
return this - > chatItems ;
@ -82,10 +67,12 @@ void ChatModel::showMessages()
{
for ( auto & c : this - > chatItems )
{
qDebug ( ) < < c . second . toChatLine ( ) ;
// qDebug() << c.second.toChatLine();
}
}
void MainWindow : : renderContactRequest ( ) {
@ -96,8 +83,8 @@ void MainWindow::renderContactRequest(){
QStandardItemModel * contactRequest = new QStandardItemModel ( ) ;
{
for ( auto & c : DataStore : : getChatDataStore ( ) - > getAllContactRequests ( ) )
for ( auto & c : DataStore : : getChatDataStore ( ) - > getAllNewContactRequests ( ) )
{
QStandardItem * Items = new QStandardItem ( c . second . getAddress ( ) ) ;
@ -105,22 +92,34 @@ void MainWindow::renderContactRequest(){
requestContact . requestContact - > setModel ( contactRequest ) ;
requestContact . requestContact - > show ( ) ;
}
}
QStandardItemModel * contactRequestOld = new QStandardItemModel ( ) ;
for ( auto & p : AddressBook : : getInstance ( ) - > getAllAddressLabels ( ) )
for ( auto & c : DataStore : : getChatDataStore ( ) - > getAllOldContactRequests ( ) )
{
if ( p . getPartnerAddress ( ) = = c . second . getRequestZaddr ( ) )
{
QStandardItem * Items = new QStandardItem ( c . second . getAddress ( ) ) ;
contactRequestOld - > appendRow ( Items ) ;
requestContact . requestContactOld - > setModel ( contactRequestOld ) ;
requestContact . requestContactOld - > show ( ) ;
} else { }
}
QObject : : connect ( requestContact . requestContact , & QTableView : : clicked , [ & ] ( ) {
for ( auto & c : DataStore : : getChatDataStore ( ) - > getAllRawChatItems ( ) ) { //this->chatItems){
for ( auto & c : DataStore : : getChatDataStore ( ) - > getAllRawChatItems ( ) ) {
QModelIndex index = requestContact . requestContact - > currentIndex ( ) ;
QString label_contact = index . data ( Qt : : DisplayRole ) . toString ( ) ;
QStandardItemModel * contactMemo = new QStandardItemModel ( ) ;
if ( c . second . isOutgoing ( ) = = false ) {
if ( label_contact = = c . second . getAddress ( ) ) {
if ( c . second . getMemo ( ) . startsWith ( " { " ) ) {
if ( ( c . second . isOutgoing ( ) = = false ) & & ( label_contact = = c . second . getAddress ( ) ) & & ( c . second . getType ( ) ! = " Cont " ) )
{
} else {
QStandardItem * Items = new QStandardItem ( c . second . getMemo ( ) ) ;
contactMemo - > appendRow ( Items ) ;
contactMemo - > appendRow ( Items ) ;
requestContact . requestMemo - > setModel ( contactMemo ) ;
requestContact . requestMemo - > show ( ) ;
@ -128,11 +127,38 @@ void MainWindow::renderContactRequest(){
requestContact . requestZaddr - > setText ( c . second . getRequestZaddr ( ) ) ;
requestContact . requestCID - > setText ( c . second . getCid ( ) ) ;
requestContact . requestMyAddr - > setText ( c . second . getAddress ( ) ) ;
}
} else { }
}
}
}
} ) ;
QObject : : connect ( requestContact . requestContactOld , & QTableView : : clicked , [ & ] ( ) {
for ( auto & c : DataStore : : getChatDataStore ( ) - > getAllRawChatItems ( ) ) {
QModelIndex index = requestContact . requestContactOld - > currentIndex ( ) ;
QString label_contactold = index . data ( Qt : : DisplayRole ) . toString ( ) ;
QStandardItemModel * contactMemo = new QStandardItemModel ( ) ;
if ( ( c . second . isOutgoing ( ) = = false ) & & ( label_contactold = = c . second . getAddress ( ) ) & & ( c . second . getType ( ) ! = " Cont " ) )
{
QStandardItem * Items = new QStandardItem ( c . second . getMemo ( ) ) ;
contactMemo - > appendRow ( Items ) ;
requestContact . requestMemo - > setModel ( contactMemo ) ;
requestContact . requestMemo - > show ( ) ;
requestContact . requestZaddr - > setText ( c . second . getRequestZaddr ( ) ) ;
requestContact . requestCID - > setText ( c . second . getCid ( ) ) ;
requestContact . requestMyAddr - > setText ( c . second . getAddress ( ) ) ;
} else { }
}
} ) ;
QObject : : connect ( requestContact . pushButton , & QPushButton : : clicked , [ & ] ( ) {
@ -173,9 +199,13 @@ void MainWindow::renderContactRequest(){
QMessageBox : : information ( this , " Added Contact " , " successfully added your new contact. You can now Chat with this contact " ) ;
} ) ;
dialog . exec ( ) ;
rpc - > refreshContacts (
ui - > listContactWidget
) ;
}
void ChatModel : : addCid ( QString tx , QString cid )
@ -286,7 +316,8 @@ Tx MainWindow::createTxFromChatPage() {
qDebug ( ) < < " pushback chattx " ;
} }
}
}
tx . fee = Settings : : getMinerFee ( ) ;
@ -425,7 +456,8 @@ QString MainWindow::doSendChatTxValidations(Tx tx) {
}
void : : MainWindow : : addContact ( ) {
Ui_Dialog request ;
QDialog dialog ( this ) ;
request . setupUi ( & dialog ) ;
@ -434,24 +466,29 @@ void::MainWindow::addContact() {
bool sapling = true ;
rpc - > createNewZaddr ( sapling , [ = ] ( json reply ) {
QString myAddr = QString : : fromStdString ( reply . get < json : : array_t > ( ) [ 0 ] ) ;
QString cid = QUuid : : createUuid ( ) . toString ( QUuid : : WithoutBraces ) ;
request . myzaddr - > setText ( myAddr ) ;
ui - > listReceiveAddresses - > insertItem ( 0 , myAddr ) ;
ui - > listReceiveAddresses - > setCurrentIndex ( 0 ) ;
qDebug ( ) < < " new generated myAddr " < < myAddr ;
request . myzaddr - > setText ( myAddr ) ;
request . cid - > setText ( cid ) ;
} ) ;
QString cid = QUuid : : createUuid ( ) . toString ( QUuid : : WithoutBraces ) ;
request . cid - > setText ( cid ) ;
QObject : : connect ( request . sendRequestButton , & QPushButton : : clicked , [ & ] ( ) {
QString cid = request . cid - > text ( ) ;
auto addr = request . zaddr - > text ( ) . trimmed ( ) ;
QString getrequest = addr ;
QString newLabel = request . labelRequest - > text ( ) . trimmed ( ) ;
auto myAddr = request . myzaddr - > text ( ) . trimmed ( ) ;
// ChatModel->addSendRequest(myAddr, cid, addr);
QString avatar = QString ( " :/icons/res/ " ) + request . comboBoxAvatar - > currentText ( ) + QString ( " .png " ) ;
if ( addr . isEmpty ( ) | | newLabel . isEmpty ( ) )
@ -489,18 +526,28 @@ void::MainWindow::addContact() {
) ;
return ;
} ) ;
// QObject::connect(request.sendRequestButton, &QPushButton::clicked, this, &MainWindow::ContactRequest);
dialog . exec ( ) ;
rpc - > refreshContacts (
ui - > listContactWidget
) ;
}
// Create a Tx for a contact Request
Tx MainWindow : : createTxForSafeContactRequest ( ) {
Tx tx ;
Tx tx ;
// For each addr/amt in the Chat tab
{
{
CAmount totalAmt ;
QString amtStr = " 0 " ;
@ -510,41 +557,45 @@ Tx MainWindow::createTxForSafeContactRequest() {
amt = CAmount : : fromDecimalString ( " 0 " ) ;
totalAmt = totalAmt + amt ;
for ( auto & c : AddressBook : : getInstance ( ) - > getAllAddressLabels ( ) )
if ( ui - > contactNameMemo - > text ( ) . trimmed ( ) = = c . getName ( ) ) {
for ( auto & c : AddressBook : : getInstance ( ) - > getAllAddressLabels ( ) )
if ( ui - > contactNameMemo - > text ( ) . trimmed ( ) = = c . getName ( ) ) {
QString cid = c . getCid ( ) ;
QString myAddr = c . getMyAddress ( ) ;
QString type = " cont " ;
QString addr = c . getPartnerAddress ( ) ;
QString type = " Cont " ;
QString addr = c . getPartnerAddress ( ) ;
QString hmemo = createHeaderMemo ( type , cid , myAddr ) ;
QString memo = ui - > memoTxtChat - > toPlainText ( ) . trimmed ( ) ;
QString hmemo = createHeaderMemo ( type , cid , myAddr ) ;
QString memo = ui - > memoTxtChat - > toPlainText ( ) . trimmed ( ) ;
tx . toAddrs . push_back ( ToFields { addr , amt , memo } ) ;
tx . toAddrs . push_back ( ToFields { addr , amt , hmemo } ) ;
// ui->memoSizeChat->setLenDisplayLabel();// Todo -> activate lendisplay for chat
tx . toAddrs . push_back ( ToFields { addr , amt , hmemo } ) ;
tx . toAddrs . push_back ( ToFields { addr , amt , memo } ) ;
qDebug ( ) < < " pushback chattx " ;
}
qDebug ( ) < < " pushback chattx " ;
tx . fee = Settings : : getMinerFee ( ) ;
}
}
return tx ;
qDebug ( ) < < " RequestTx created " ;
}
}
}
void MainWindow : : ContactRequest ( ) {
if ( ui - > contactNameMemo - > text ( ) . trimmed ( ) . isEmpty ( ) | | ui - > memoTxtChat - > toPlainText ( ) . trimmed ( ) . isEmpty ( ) ) {
/* if (request.labelRequest->text().trimmed().isEmpty() || request.memorequest->toPlainText().trimmed().isEmpty()) {
// auto addr = "";
// if (! Settings::isZAddress(AddressBook::addressFromAddressLabel(addr->text()))) {
@ -554,7 +605,7 @@ void MainWindow::ContactRequest() {
msg . exec ( ) ;
return ;
}
} */
Tx tx = createTxForSafeContactRequest ( ) ;
@ -632,7 +683,7 @@ void MainWindow::ContactRequest() {
QMessageBox : : critical ( this , QObject : : tr ( " Transaction Error " ) , errStr , QMessageBox : : Ok ) ;
}
) ;
}
@ -664,4 +715,4 @@ QString MainWindow::doSendRequestTxValidations(Tx tx) {
}
return " " ;
}
}