diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 93e2481..6e99e23 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -565,27 +565,17 @@ try { QString AddressBook::writeableFile() { - auto filename = QStringLiteral("addresslabels.dat"); - auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + auto filename = QStringLiteral("addresslabels.dat"); - try { + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); if (!dir.exists()) QDir().mkpath(dir.absolutePath()); - if (Settings::getInstance()->isTestnet()) + if (Settings::getInstance()->isTestnet()) { return dir.filePath("testnet-" % filename); - - else + } else { return dir.filePath(filename); - - } catch(...) { - QMessageBox msgWarning; - msgWarning.setText("WARNING!\nCould not write Addressbook."); - msgWarning.setIcon(QMessageBox::Warning); - msgWarning.setWindowTitle("Caution"); - msgWarning.exec(); - - } + } } diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 33cf8dc..c21b512 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -237,6 +237,20 @@ void MainWindow::renderContactRequest(){ return; } + // Don't allow duplicate address labels. + + if (!AddressBook::getInstance()->getAddressForLabel(newLabel).isEmpty()) + { + QMessageBox::critical( + this, + QObject::tr("Label Error"), + QObject::tr("The label '%1' already exists. Please remove the existing label.").arg(newLabel), + QMessageBox::Ok + ); + qDebug()<<"Doppelter Name"; + return; + } + // Test if address is valid. if (!Settings::isValidAddress(addr)) { @@ -248,12 +262,15 @@ void MainWindow::renderContactRequest(){ ); return; } - AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar); - rpc->refreshContacts( - ui->listContactWidget); - QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact"); - dialog.close(); + + + AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar); + rpc->refreshContacts( + ui->listContactWidget); + + QMessageBox::information(this, "Added Contact","successfully added your new contact. You can now Chat with this contact"); + dialog.close(); }); dialog.exec(); @@ -684,7 +701,7 @@ QString MainWindow::doSendChatTxValidations(Tx tx) { return QString(tr("Recipient Address ")) % addr % tr(" is Invalid"); ui->memoTxtChat->setEnabled(true); } - + // This technically shouldn't be possible, but issue #62 seems to have discovered a bug // somewhere, so just add a check to make sure. if (toAddr.amount.toqint64() < 0) { @@ -828,6 +845,19 @@ void MainWindow::ContactRequest() { msg.exec(); return; } + + QString newLabel = contactRequest.getLabel(); + + if (!AddressBook::getInstance()->getAddressForLabel(newLabel).isEmpty()) + { + QMessageBox::critical( + this, + QObject::tr("Label Error"), + QObject::tr("The label '%1' already exists. Please remove the existing label.").arg(newLabel), + QMessageBox::Ok + ); + return; + } int max = 512; QString chattext = contactRequest.getMemo();; @@ -916,6 +946,17 @@ void MainWindow::ContactRequest() { return; } + if (!AddressBook::getInstance()->getAddressForLabel(newLabel).isEmpty()) + { + QMessageBox::critical( + this, + QObject::tr("Label Error"), + QObject::tr("The label '%1' already exists. Please remove the existing label.").arg(newLabel), + QMessageBox::Ok + ); + return; + } + // Test if address is valid. if (!Settings::isValidAddress(addr)) { @@ -928,8 +969,6 @@ void MainWindow::ContactRequest() { return; } - ///////Todo: Test if label allready exist! - ////// Success, so show it AddressBook::getInstance()->addAddressLabel(newLabel, addr, myAddr, cid, avatar); rpc->refreshContacts( diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d9f2402..a9f28fc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -81,6 +81,11 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); + auto dir = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)); + if (!dir.exists()){ + QDir().mkpath(dir.absolutePath()); + }else{} + logger = new Logger(this, QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("silentdragonlite-wallet.log")); // Check for encryption @@ -1667,13 +1672,21 @@ if (-1 != pos) QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () { - ui->listContactWidget->setContextMenuPolicy(Qt::ActionsContextMenu); - ui->listContactWidget->addAction(HushAction); - ui->listContactWidget->addAction(editAction); + ui->listContactWidget->setContextMenuPolicy(Qt::ActionsContextMenu); + ui->listContactWidget->addAction(HushAction); + ui->listContactWidget->addAction(editAction); + int requestsize = DataStore::getChatDataStore()->getAllNewContactRequests().size(); - ui->memoTxtChat->setEnabled(false); - ui->emojiButton->setEnabled(false); - ui->sendChatButton->setEnabled(false); + if (requestsize > 0) + { + ui->newRequest->setStyleSheet("color: red;"); + }else{} + + ui->newRequest->setNum(requestsize); + + ui->memoTxtChat->setEnabled(false); + ui->emojiButton->setEnabled(false); + ui->sendChatButton->setEnabled(false); QModelIndex index = ui->listContactWidget->currentIndex(); QString label_contact = index.data(Qt::DisplayRole).toString(); @@ -1773,6 +1786,19 @@ if (-1 != pos) ui->memoTxtChat->setLenDisplayLabelChat(ui->memoSizeChat); +ui->newRequest->setStyleSheet("color: red;"); + + +////get amount of new contact request as intervall + +QTimer* timer = new QTimer(); +timer->setInterval(30000); + +connect(timer, &QTimer::timeout, this, [=](){ + int requestsize = DataStore::getChatDataStore()->getAllNewContactRequests().size(); + ui->newRequest->setNum(requestsize); +}); +timer->start(); } diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f14a9fe..17386a2 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -66,210 +66,6 @@ HushChat - - - - - - QLayout::SetDefaultConstraint - - - 0 - - - 0 - - - 15 - - - - - - 51 - 51 - - - - - 51 - 51 - - - - - 100 - 0 - - - - Incoming contact request - - - false - - - - - - - :/icons/res/requestBlack.png:/icons/res/requestBlack.png - - - - 50 - 45 - - - - true - - - - - - - - 51 - 51 - - - - - 51 - 51 - - - - - 100 - 0 - - - - Add a new contact - - - - - - - :/icons/res/addContactBlack.png - - - - - 50 - 45 - - - - true - - - - - - - - 51 - 51 - - - - - 51 - 51 - - - - Get a new Address - - - - - - - :/icons/res/getAddrBlack.png:/icons/res/getAddrBlack.png - - - - 50 - 45 - - - - true - - - - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 100 - 20 - - - - - - - - - - - 0 - 0 - - - - - 300 - 0 - - - - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Contactlist</span></p></body></html> - - - - - - - - 0 - 0 - - - - true - - - QAbstractItemView::NoEditTriggers - - - false - - - false - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectItems - - - - - @@ -547,6 +343,223 @@ + + + + + + QLayout::SetDefaultConstraint + + + 0 + + + 0 + + + 15 + + + + + + 51 + 51 + + + + + 51 + 51 + + + + + 100 + 0 + + + + Incoming contact request + + + false + + + + + + + :/icons/res/requestBlack.png:/icons/res/requestBlack.png + + + + 50 + 45 + + + + true + + + + + + + + 20 + 20 + + + + + + + + + + + + 51 + 51 + + + + + 51 + 51 + + + + + 100 + 0 + + + + Add a new contact + + + + + + + :/icons/res/addContactBlack.png + + + + + 50 + 45 + + + + true + + + + + + + + 51 + 51 + + + + + 51 + 51 + + + + Get a new Address + + + + + + + :/icons/res/getAddrBlack.png:/icons/res/getAddrBlack.png + + + + 50 + 45 + + + + true + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 100 + 20 + + + + + + + + + + + 0 + 0 + + + + + 300 + 0 + + + + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Contactlist</span></p></body></html> + + + + + + + + 0 + 0 + + + + true + + + QAbstractItemView::NoEditTriggers + + + false + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectItems + + + + + diff --git a/src/version.h b/src/version.h index 1f79e63..69ca9b6 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define APP_VERSION "1.3.10" +#define APP_VERSION "1.3.11"