Skip to content

Commit

Permalink
Messages 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
xdn-project committed May 31, 2016
1 parent d2d28be commit fb52b54
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 148 deletions.
2 changes: 1 addition & 1 deletion CryptoNoteWallet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
set(CN_PROJECT_NAME "digitalnotewallet")
set(CN_CURRENCY_DISPLAY_NAME "DigitalNote")
set(CN_CURRENCY_TICKER "XDN")
set(CN_VERSION 1.0.7-beta)
set(CN_VERSION 1.0.8-beta)
2 changes: 1 addition & 1 deletion src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void Settings::load() {
}

QStringList defaultPoolList;
defaultPoolList << "xdn.miner.center:4555" << "duckpool.mooo.com:2222" << "xdn.poolto.be:11010";
defaultPoolList << "xdn.miner.center:4555" << "xdn.poolto.be:11010";
if (!m_settings.contains(OPTION_MINING_POOLS)) {
setMiningPoolList(QStringList() << defaultPoolList);
} else {
Expand Down
19 changes: 17 additions & 2 deletions src/WalletAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ void WalletAdapter::backup(const QString& _file) {
}
}

void WalletAdapter::reset() {
Q_CHECK_PTR(m_wallet);
save(false, false);
lock();
m_wallet->removeObserver(this);
m_isSynchronized = false;
m_newTransactionsNotificationTimer.stop();
m_lastWalletTransactionId = std::numeric_limits<quint64>::max();
Q_EMIT walletCloseCompletedSignal();
QCoreApplication::processEvents();
delete m_wallet;
m_wallet = nullptr;
unlock();
}

quint64 WalletAdapter::getTransactionCount() const {
Q_CHECK_PTR(m_wallet);
try {
Expand Down Expand Up @@ -301,11 +316,11 @@ void WalletAdapter::sendTransaction(const QVector<CryptoNote::WalletLegacyTransf
}

void WalletAdapter::sendMessage(const QVector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, quint64 _mixin,
const QVector<CryptoNote::TransactionMessage>& _messages) {
const QVector<CryptoNote::TransactionMessage>& _messages, quint64 _ttl) {
Q_CHECK_PTR(m_wallet);
try {
lock();
m_sentMessageId = m_wallet->sendTransaction(_transfers.toStdVector(), _fee, "", _mixin, 0, _messages.toStdVector());
m_sentMessageId = m_wallet->sendTransaction(_transfers.toStdVector(), _fee, "", _mixin, 0, _messages.toStdVector(), _ttl);
Q_EMIT walletStateChangedSignal(tr("Sending messages"));
} catch (std::system_error&) {
unlock();
Expand Down
3 changes: 2 additions & 1 deletion src/WalletAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WalletAdapter : public QObject, public CryptoNote::IWalletLegacyObserver {
void close();
bool save(bool _details, bool _cache);
void backup(const QString& _file);
void reset();

QString getAddress() const;
quint64 getActualBalance() const;
Expand All @@ -45,7 +46,7 @@ class WalletAdapter : public QObject, public CryptoNote::IWalletLegacyObserver {
void sendTransaction(const QVector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, const QString& _payment_id, quint64 _mixin,
const QVector<CryptoNote::TransactionMessage>& _messages);
void sendMessage(const QVector<CryptoNote::WalletLegacyTransfer>& _transfers, quint64 _fee, quint64 _mixin,
const QVector<CryptoNote::TransactionMessage>& _messages);
const QVector<CryptoNote::TransactionMessage>& _messages, quint64 _ttl);
void deposit(quint32 _term, quint64 _amount, quint64 _fee, quint64 _mixIn);
void withdrawUnlockedDeposits(QVector<CryptoNote::DepositId> _depositIds, quint64 _fee);
bool changePassword(const QString& _old_pass, const QString& _new_pass);
Expand Down
11 changes: 11 additions & 0 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ void MainWindow::backupWallet() {
}
}

void MainWindow::resetWallet() {
Q_ASSERT(WalletAdapter::instance().isOpen());
if (QMessageBox::warning(this, tr("Warning"), tr("Your wallet will be reset and restored from blockchain.\n"
"Are you sure?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok) {
WalletAdapter::instance().reset();
WalletAdapter::instance().open("");
}
}

void MainWindow::encryptWallet() {
if (Settings::instance().isEncrypted()) {
bool error = false;
Expand Down Expand Up @@ -426,6 +435,7 @@ void MainWindow::walletOpened(bool _error, const QString& _error_text) {
m_encryptionStateIconLabel->show();
m_synchronizationStateIconLabel->show();
m_ui->m_backupWalletAction->setEnabled(true);
m_ui->m_resetAction->setEnabled(true);
encryptedFlagChanged(Settings::instance().isEncrypted());

QList<QAction*> tabActions = m_tabActionGroup->actions();
Expand All @@ -444,6 +454,7 @@ void MainWindow::walletClosed() {
m_ui->m_backupWalletAction->setEnabled(false);
m_ui->m_encryptWalletAction->setEnabled(false);
m_ui->m_changePasswordAction->setEnabled(false);
m_ui->m_resetAction->setEnabled(false);
m_ui->m_overviewFrame->hide();
m_ui->m_sendFrame->hide();
m_ui->m_transactionsFrame->hide();
Expand Down
1 change: 1 addition & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class MainWindow : public QMainWindow {
Q_SLOT void openWallet();
Q_SLOT void importKey();
Q_SLOT void backupWallet();
Q_SLOT void resetWallet();
Q_SLOT void encryptWallet();
Q_SLOT void aboutQt();
Q_SLOT void about();
Expand Down
74 changes: 74 additions & 0 deletions src/gui/MessageAddressFrame.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <QApplication>
#include <QClipboard>

#include "MessageAddressFrame.h"
#include "AddressBookDialog.h"
#include "AliasProvider.h"
#include "MainWindow.h"
#include "ui_messageaddressframe.h"

namespace WalletGui {

namespace {
Q_DECL_CONSTEXPR quint32 MESSAGE_ADDRESS_INPUT_INTERVAL = 1500;
}

MessageAddressFrame::MessageAddressFrame(QWidget* _parent) : QFrame(_parent),
m_ui(new Ui::MessageAddressFrame), m_aliasProvider(new AliasProvider(this)), m_addressInputTimerId(-1) {
m_ui->setupUi(this);

connect(m_aliasProvider, &AliasProvider::aliasFoundSignal, this, &MessageAddressFrame::onAliasFound);
}

MessageAddressFrame::~MessageAddressFrame() {

}

QString MessageAddressFrame::getAddress() const {
return m_ui->m_addressEdit->text();
}

void MessageAddressFrame::disableRemoveButton(bool _disable) {
m_ui->m_removeButton->setDisabled(_disable);
}

void MessageAddressFrame::timerEvent(QTimerEvent* _event) {
if (_event->timerId() == m_addressInputTimerId) {
m_aliasProvider->getAddresses(m_ui->m_addressEdit->text().trimmed());
killTimer(m_addressInputTimerId);
m_addressInputTimerId = -1;
return;
}

QFrame::timerEvent(_event);
}

void MessageAddressFrame::onAliasFound(const QString& _name, const QString& _address) {
m_ui->m_addressEdit->setText(QString("%1 <%2>").arg(_name).arg(_address));
}

void MessageAddressFrame::addressBookClicked() {
AddressBookDialog dlg(&MainWindow::instance());
if(dlg.exec() == QDialog::Accepted) {
m_ui->m_addressEdit->setText(dlg.getAddress());
}
}

void MessageAddressFrame::addressEdited(const QString& _text) {
if (m_addressInputTimerId != -1) {
killTimer(m_addressInputTimerId);
}

m_addressInputTimerId = startTimer(MESSAGE_ADDRESS_INPUT_INTERVAL);
}

void MessageAddressFrame::pasteClicked() {
m_ui->m_addressEdit->setText(QApplication::clipboard()->text());
}

}
44 changes: 44 additions & 0 deletions src/gui/MessageAddressFrame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2011-2016 The Cryptonote developers
// Copyright (c) 2015-2016 XDN developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

#include <QFrame>

namespace Ui {
class MessageAddressFrame;
}

namespace WalletGui {

class AliasProvider;

class MessageAddressFrame : public QFrame {
Q_OBJECT
Q_DISABLE_COPY(MessageAddressFrame)

public:
MessageAddressFrame(QWidget* _parent);
~MessageAddressFrame();

QString getAddress() const;
void disableRemoveButton(bool _disable);

protected:
void timerEvent(QTimerEvent* _event) Q_DECL_OVERRIDE;

private:
QScopedPointer<Ui::MessageAddressFrame> m_ui;
AliasProvider* m_aliasProvider;
int m_addressInputTimerId;

void onAliasFound(const QString& _name, const QString& _address);

Q_SLOT void addressBookClicked();
Q_SLOT void addressEdited(const QString& _text);
Q_SLOT void pasteClicked();
};

}

0 comments on commit fb52b54

Please sign in to comment.