diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 49c453a9..0d1aa4d7 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -33,6 +33,7 @@ QT_TS = \ QT_FORMS_UI = \ qt/forms/addressbookpage.ui \ qt/forms/askpassphrasedialog.ui \ + qt/forms/chatwindowpage.ui \ qt/forms/coincontroldialog.ui \ qt/forms/editaddressdialog.ui \ qt/forms/governancelist.ui \ @@ -52,6 +53,7 @@ QT_FORMS_UI = \ qt/forms/sendcoinsdialog.ui \ qt/forms/sendcoinsentry.ui \ qt/forms/signverifymessagedialog.ui \ + qt/forms/tradingdialogpage.ui \ qt/forms/transactiondescdialog.ui QT_MOC_CPP = \ @@ -63,6 +65,7 @@ QT_MOC_CPP = \ qt/moc_bitcoinamountfield.cpp \ qt/moc_bitcoingui.cpp \ qt/moc_bitcoinunits.cpp \ + qt/moc_chatwindowpage.cpp \ qt/moc_clientmodel.cpp \ qt/moc_coincontroldialog.cpp \ qt/moc_coincontroltreewidget.cpp \ @@ -93,8 +96,10 @@ QT_MOC_CPP = \ qt/moc_rpcconsole.cpp \ qt/moc_sendcoinsdialog.cpp \ qt/moc_sendcoinsentry.cpp \ + qt/moc_serveur.cpp \ qt/moc_signverifymessagedialog.cpp \ qt/moc_splashscreen.cpp \ + qt/moc_tradingdialogpage.cpp \ qt/moc_trafficgraphwidget.cpp \ qt/moc_transactiondesc.cpp \ qt/moc_transactiondescdialog.cpp \ @@ -137,6 +142,7 @@ BITCOIN_QT_H = \ qt/bitcoinamountfield.h \ qt/bitcoingui.h \ qt/bitcoinunits.h \ + qt/chatwindowpage.h \ qt/clientmodel.h \ qt/coincontroldialog.h \ qt/coincontroltreewidget.h \ @@ -172,8 +178,10 @@ BITCOIN_QT_H = \ qt/rpcconsole.h \ qt/sendcoinsdialog.h \ qt/sendcoinsentry.h \ + qt/serveur.h \ qt/signverifymessagedialog.h \ qt/splashscreen.h \ + qt/tradingdialogpage.h \ qt/trafficgraphdata.h \ qt/trafficgraphwidget.h \ qt/transactiondesc.h \ @@ -498,6 +506,7 @@ BITCOIN_QT_WALLET_CPP = \ qt/addressbookpage.cpp \ qt/addresstablemodel.cpp \ qt/askpassphrasedialog.cpp \ + qt/chatwindowpage.cpp \ qt/coincontroldialog.cpp \ qt/coincontroltreewidget.cpp \ qt/editaddressdialog.cpp \ @@ -515,7 +524,9 @@ BITCOIN_QT_WALLET_CPP = \ qt/recentrequeststablemodel.cpp \ qt/sendcoinsdialog.cpp \ qt/sendcoinsentry.cpp \ + qt/serveur.cpp \ qt/signverifymessagedialog.cpp \ + qt/tradingdialogpage.cpp \ qt/transactiondesc.cpp \ qt/transactiondescdialog.cpp \ qt/transactionfilterproxy.cpp \ diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 345ac7c8..1e1e9bca 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -22,6 +22,8 @@ #include "platformstyle.h" #include "rpcconsole.h" #include "utilitydialog.h" +/* #include "tradingdialogpage.h" */ +#include "chatwindowpage.h" #ifdef ENABLE_WALLET #include "privatesend-client.h" @@ -139,7 +141,9 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *_platformStyle, const NetworkStyle * prevBlocks(0), spinnerFrame(0), governanceAction(0), + /* tradingAction(0), */ externalDonate(0), + chatWindowPage(0), platformStyle(_platformStyle) { /* Open CSS when configured */ @@ -485,16 +489,30 @@ void BitcoinGUI::createActions() governanceAction->setToolTip(governanceAction->statusTip()); governanceAction->setCheckable(true); #ifdef Q_OS_MAC - governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_5)); + governanceAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_6)); #else - governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_5)); + governanceAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_6)); #endif tabGroup->addAction(governanceAction); connect(governanceAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); connect(governanceAction, SIGNAL(triggered()), this, SLOT(gotoGovernancePage())); } - + /* { + tradingAction = new QAction(QIcon(":/icons/chat"), tr("&Trading"), this); + tradingAction->setStatusTip(tr("Trade HTH Today")); + tradingAction->setToolTip(tradingAction->statusTip()); + tradingAction->setCheckable(true); +#ifdef Q_OS_MAC + tradingAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_7)); +#else + tradingAction->setShortcut(QKeySequence(Qt::ALT + Qt::Key_7)); +#endif + tabGroup->addAction(tradingAction); + connect(tradingAction, SIGNAL(triggered()), this, SLOT(showNormalIfMinimized())); + connect(tradingAction, SIGNAL(triggered()), this, SLOT(gotoTradingDialogPage())); + + } */ /* privatesendAction = new QAction(QIcon(":/icons/coinmix"), tr("&Private Send"), this); privatesendAction->setStatusTip(tr("Show Private Send of wallet")); privatesendAction->setToolTip(privatesendAction->statusTip()); @@ -600,6 +618,10 @@ void BitcoinGUI::createActions() // HTHW Donate externalDonate = new QAction(QIcon(":/icons/" + theme + "/about"), tr("Donate To HTHW"), this); externalDonate->setStatusTip(tr("Donate to Help The Homeless Worldwide")); + + // HTH Chat + chatWindowPage = new QAction(QIcon(":/icons/" + theme + "/chat"), tr("HTH Chat"), this); + chatWindowPage->setStatusTip(tr("HTH World IRC Chat")); connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -614,6 +636,9 @@ void BitcoinGUI::createActions() // HTHW Donate connect(externalDonate, SIGNAL(triggered()), this, SLOT(openDonate())); + // HTHW Chat + connect(chatWindowPage, SIGNAL(triggered()), this, SLOT(gotoChatWindowPage())); + // Jump directly to tabs in RPC-console connect(openInfoAction, SIGNAL(triggered()), this, SLOT(showInfo())); connect(openRPCConsoleAction, SIGNAL(triggered()), this, SLOT(showConsole())); @@ -714,6 +739,9 @@ void BitcoinGUI::createMenuBar() QMenu* donate = appMenuBar->addMenu(tr("&Donate")); donate->addAction(externalDonate); + QMenu* chat = appMenuBar->addMenu(tr("&HTH Chat")); + chat->addAction(chatWindowPage); + } void BitcoinGUI::createToolBars() @@ -737,7 +765,10 @@ void BitcoinGUI::createToolBars() } toolbar->addAction(governanceAction); toolbar->addAction(unlockWalletAction); - + + /* toolbar->addAction(tradingAction); + toolbar->addAction(unlockWalletAction); */ + toolbar->setMovable(false); // remove unused icon in upper left corner overviewAction->setChecked(true); @@ -888,6 +919,7 @@ void BitcoinGUI::setWalletActionsEnabled(bool enabled) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool() && masternodeAction) { masternodeAction->setEnabled(enabled); } + /*tradingAction->setEnabled(enabled); */ governanceAction->setEnabled(enabled); encryptWalletAction->setEnabled(enabled); backupWalletAction->setEnabled(enabled); @@ -1023,7 +1055,6 @@ void BitcoinGUI::showHelpMessageClicked() { if(!clientModel) return; - HelpMessageDialog dlg(this, HelpMessageDialog::pshelp); dlg.exec(); } */ @@ -1038,6 +1069,19 @@ void BitcoinGUI::openClicked() } } +void BitcoinGUI::gotoChatWindowPage() +{ + chatWindowPage->setChecked(true); + if (walletFrame) walletFrame->gotoChatWindowPage(); +} + +/*void BitcoinGUI::gotoTradingDialogPage() +{ + + tradingAction->setChecked(true); + if (walletFrame) walletFrame->gotoTradingDialogPage(); +} */ + void BitcoinGUI::openDonate() { openExternalURL("https://helpthehomelessworldwide.org/donate"); @@ -1641,7 +1685,6 @@ void BitcoinGUI::detectShutdown() } } } - } */ diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h index 9011d71d..055119d2 100644 --- a/src/qt/bitcoingui.h +++ b/src/qt/bitcoingui.h @@ -38,6 +38,8 @@ class HelpMessageDialog; class ModalOverlay; class QNetworkAccessManager; class QNetworkRequest; +/*class tradingDialogPage; */ +class ChatWindowPage; class CWallet; @@ -103,8 +105,10 @@ class BitcoinGUI : public QMainWindow QMenuBar *appMenuBar; + QAction* chatWindowPage; QAction* externalDonate; QAction *governanceAction; + /* QAction *tradingAction; */ /* QAction* privatesendAction; */ QAction *overviewAction; QAction *historyAction; @@ -230,11 +234,15 @@ public Q_SLOTS: private Q_SLOTS: #ifdef ENABLE_WALLET - - /** Switch to masternode page */ + + /** Switch to chat page */ + void gotoChatWindowPage(); + /** Switch to trading page */ + /* void gotoTradingDialogPage(); */ + /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ - /* void gotoPrivateSendPage(); */ + /* void gotoPrivateSendPage(); */ /** Switch to overview (home) page */ void gotoOverviewPage(); /** Switch to history (transactions) page */ diff --git a/src/qt/chatwindowpage.cpp b/src/qt/chatwindowpage.cpp new file mode 100644 index 00000000..87bff742 --- /dev/null +++ b/src/qt/chatwindowpage.cpp @@ -0,0 +1,231 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ + +#include "chatwindowpage.h" +#include "ui_chatwindowpage.h" + +#include +#include +#include +#include +#include +#include + +ChatWindowPage::ChatWindowPage(QWidget *parent) + : QWidget(parent), ui(new Ui::ChatWindowPage) +{ + ui->setupUi(this); + setFixedSize(750,600); + ui->splitter->hide(); + + connect(ui->buttonConnect, SIGNAL(clicked()), this, SLOT(connecte())); + + connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(close())); + connect(ui->actionCloseTab, SIGNAL(triggered()), this, SLOT(closeTab())); + + connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(sendCommande())); + + + ui->pushButton_WebChat->setStatusTip(tr("Visit Help The Homeless Worldwide Web Chat")); + + + + + + connect(ui->disconnect, SIGNAL(clicked()), this, SLOT(disconnectFromServer())); + connect(ui->tab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) ); + connect(ui->tab, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosing(int)) ); + +} + + + +void ChatWindowPage::tabChanged(int index) +{ + if(index!=0 && joining == false) + currentTab()->updateUsersList(ui->tab->tabText(index)); +} + +void ChatWindowPage::tabClosing(int index) +{ + currentTab()->leave(ui->tab->tabText(index)); +} +/*void ChatWindow::tabRemoved(int index) +{ + currentTab()->leave(ui->tab->tabText(index)); +}*/ + +void ChatWindowPage::disconnectFromServer() { + + QMapIterator i(serveurs); + + while(i.hasNext()) + { + i.next(); + QMapIterator i2(i.value()->conversations); + while(i2.hasNext()) + { + i2.next(); + i.value()->sendData("QUIT "+i2.key() + " "); + } + } + + + ui->splitter->hide(); + ui->hide3->show(); + +} + +Serveur *ChatWindowPage::currentTab() +{ + QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); + return serveurs[tooltip]; + //return ui->tab->currentWidget()->findChild(); +} + +void ChatWindowPage::closeTab() +{ + QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); + QString txt=ui->tab->tabText(ui->tab->currentIndex()); + + if(txt==tooltip) + { + QMapIterator i(serveurs[tooltip]->conversations); + + int count=ui->tab->currentIndex()+1; + + while(i.hasNext()) + { + i.next(); + ui->tab->removeTab(count); + } + + currentTab()->abort(); + ui->tab->removeTab(ui->tab->currentIndex()); + } + else + { + + ui->tab->removeTab(ui->tab->currentIndex()); + currentTab()->conversations.remove(txt); + } +} + +void ChatWindowPage::sendCommande() +{ + QString tooltip=ui->tab->tabToolTip(ui->tab->currentIndex()); + QString txt=ui->tab->tabText(ui->tab->currentIndex()); + if(txt==tooltip) + { + currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text(),true) ); + } + else + { + currentTab()->sendData(currentTab()->parseCommande(ui->lineEdit->text()) ); + } + ui->lineEdit->clear(); + ui->lineEdit->setFocus(); +} + +void ChatWindowPage::tabJoined() +{ + joining=true; +} +void ChatWindowPage::tabJoining() +{ + joining=false; +} + +void ChatWindowPage::connecte() +{ + + ui->splitter->show(); + Serveur *serveur=new Serveur; + QTextEdit *textEdit=new QTextEdit; + ui->hide3->hide(); + + ui->tab->addTab(textEdit,"Console/PM"); + ui->tab->setTabToolTip(ui->tab->count()-1,"irc.freenode.net"); + // current tab is now the last, therefore remove all but the last + for (int i = ui->tab->count(); i > 1; --i) { + ui->tab->removeTab(0); + } + + serveurs.insert("irc.freenode.net",serveur); + + serveur->pseudo=ui->editPseudo->text(); + serveur->serveur="irc.freenode.net"; + serveur->port=6667; + serveur->affichage=textEdit; + serveur->tab=ui->tab; + serveur->userList=ui->userView; + serveur->parent=this; + + textEdit->setReadOnly(true); + + connect(serveur, SIGNAL(joinTab()),this, SLOT(tabJoined() )); + connect(serveur, SIGNAL(tabJoined()),this, SLOT(tabJoining() )); + + serveur->connectToHost("irc.freenode.net",6667); + + ui->tab->setCurrentIndex(ui->tab->count()-1); +} + +void ChatWindowPage::closeEvent(QCloseEvent *event) +{ + (void) event; + + QMapIterator i(serveurs); + + while(i.hasNext()) + { + i.next(); + QMapIterator i2(i.value()->conversations); + while(i2.hasNext()) + { + i2.next(); + i.value()->sendData("QUIT "+i2.key() + " "); + } + } +} +void ChatWindowPage ::setModel(ClientModel *model) +{ + this->model = model; +} + +void ChatWindowPage::on_pushButton_WebChat_clicked() { // #HTHWorld Chat + + QDesktopServices::openUrl(QUrl("https://webchat.freenode.net//", QUrl::TolerantMode)); + +} + + +ChatWindowPage::~ChatWindowPage() +{ + delete ui; + QMapIterator i(serveurs); + + while(i.hasNext()) + { + i.next(); + QMapIterator i2(i.value()->conversations); + while(i2.hasNext()) + { + i2.next(); + i.value()->sendData("QUIT "+i2.key() + " "); + } + } +} diff --git a/src/qt/chatwindowpage.h b/src/qt/chatwindowpage.h new file mode 100644 index 00000000..2beba14b --- /dev/null +++ b/src/qt/chatwindowpage.h @@ -0,0 +1,73 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ + +#ifndef CHATWINDOWPAGE_H +#define CHATWINDOWPAGE_H + +#include +#include +#include "clientmodel.h" +#include "serveur.h" + +#include +#include +#include + + + +namespace Ui +{ + class ChatWindowPage; +} + +class ChatWindowPage : public QWidget +{ + Q_OBJECT + +public: + ChatWindowPage(QWidget *parent = 0); + ~ChatWindowPage(); + void setModel(ClientModel *model); + Serveur * currentTab(); + Q_SIGNALS: + void changeTab(); + + public Q_SLOTS: + void sendCommande(); + void connecte(); + void closeTab(); + + void tabChanged(int index); + + void tabJoined(); + void tabJoining(); + void disconnectFromServer(); + void tabClosing(int index); + + +private: + Ui::ChatWindowPage *ui; + ClientModel *model; + QMap serveurs; + bool joining; + void closeEvent(QCloseEvent *event); + +private Q_SLOTS: + void on_pushButton_WebChat_clicked(); + +}; + +#endif // CHATWINDOWPAGE_H diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index ffe7a99d..3fdc4cd2 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -29,6 +29,10 @@ #include #include +#include +#include +#include +#include class CBlockIndex; diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index ba30a287..7f9a9f69 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -11,6 +11,10 @@ #include #include +#include +#include +#include +#include #include @@ -19,6 +23,8 @@ class BanTableModel; class OptionsModel; class PeerTableModel; class TransactionTableModel; +class QNetworkAccessManager; +class QNetworkRequest; class CWallet; class CBlockIndex; @@ -101,6 +107,8 @@ class ClientModel : public QObject OptionsModel *optionsModel; PeerTableModel *peerTableModel; BanTableModel *banTableModel; + QNetworkAccessManager* networkManager; + QNetworkRequest* request; QTimer *pollTimer; diff --git a/src/qt/forms/chatwindowpage.ui b/src/qt/forms/chatwindowpage.ui new file mode 100644 index 00000000..663f0ba3 --- /dev/null +++ b/src/qt/forms/chatwindowpage.ui @@ -0,0 +1,323 @@ + + + ChatWindowPage + + + + 0 + 0 + 878 + 692 + + + + + + 0 + 50 + 851 + 611 + + + + + true + + + + 10 + 10 + 721 + 501 + + + + + + + + + 10 + 0 + 541 + 451 + + + + + + + QTabWidget::Rounded + + + 1 + + + false + + + + Tab 1 + + + + + Tab 2 + + + + + + + 10 + 460 + 701 + 30 + + + + + 0 + 0 + + + + + 16777215 + 30 + + + + + + + 560 + 20 + 161 + 391 + + + + + 0 + 300 + + + + border-radius:10px; + + + + + + 595 + 420 + 100 + 30 + + + + + 100 + 30 + + + + + 100 + 30 + + + + border-style: solid; +border-width: 2px; +border-color: #34bcaa; +border-radius: 10px; +font-size: 11px; + + + Leave + + + + + + + 10 + 10 + 851 + 671 + + + + + + 179 + 40 + 241 + 29 + + + + + 7 + + + + + font-weight: bold; +font-size: 20px; + + + HTH World Chat + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 60 + 20 + + + + + + + + + + 185 + 210 + 151 + 22 + + + + + + + + + + 80 + 210 + 81 + 21 + + + + Nickname: + + + + + + 185 + 275 + 151 + 41 + + + + border-style: solid; +border-width: 2px; +border-color: #34bcaa; +border-radius: 10px; +font-size: 11px; + + + Click to Connect + + + + + + 140 + 142 + 251 + 25 + + + + <html><head/><body><p><span style=" font-weight:600;">Connect to #HTHWorld TrollBox</span></p></body></html> + + + Qt::AlignCenter + + + + + + 200 + 380 + 231 + 61 + + + + <html><head/><body><p>Enter your Nick</p><p>Enter #HTHWorld as Channel</p></body></html> + + + + + + 30 + 400 + 120 + 30 + + + + + 100 + 30 + + + + + 120 + 30 + + + + Visit HTH World Web Chat + + + border-style: solid; +border-width: 2px; +border-color: #34bcaa; +border-radius: 10px; +font-size: 11px; + + + #HTHWorld + + + + + + + Quitter + + + Ctrl+Q + + + + + Fermer l'onglet + + + + + + + diff --git a/src/qt/forms/modaloverlay.ui b/src/qt/forms/modaloverlay.ui index f63b94b7..0f46c9c3 100644 --- a/src/qt/forms/modaloverlay.ui +++ b/src/qt/forms/modaloverlay.ui @@ -206,10 +206,10 @@ 0 0 651 - 81 + 85 - + 20 @@ -257,22 +257,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 113 - 20 - - - - diff --git a/src/qt/forms/tradingdialogpage.ui b/src/qt/forms/tradingdialogpage.ui new file mode 100644 index 00000000..a7b8a4d3 --- /dev/null +++ b/src/qt/forms/tradingdialogpage.ui @@ -0,0 +1,3013 @@ + + + TradingDialogPage + + + + 0 + 0 + 849 + 480 + + + + Dialog + + + + true + + + + 10 + 40 + 831 + 431 + + + + + 50 + false + + + + QTabWidget::North + + + QTabWidget::Rounded + + + 6 + + + + Buy + + + + + 30 + 330 + 75 + 23 + + + + Buy MACRON + + + + + + 10 + 110 + 46 + 23 + + + + + 75 + true + + + + Units + + + + + + 330 + 110 + 451 + 23 + + + + + 9 + 75 + true + + + + + + + 330 + 140 + 451 + 23 + + + + + 9 + 75 + true + + + + + + + 790 + 110 + 31 + 23 + + + + MACRON + + + + + + 790 + 140 + 21 + 23 + + + + BTC + + + + + + 10 + 140 + 46 + 23 + + + + + 75 + true + + + + Bid + + + + + + 10 + 170 + 71 + 16 + + + + + 75 + true + + + + Order Type + + + + + + 129 + 110 + 191 + 23 + + + + + 10 + + + + Max + + + + + + 129 + 140 + 191 + 23 + + + + + 10 + + + + + + + 129 + 170 + 191 + 23 + + + + + 10 + + + + + + + 21 + 11 + 180 + 15 + + + + + + + + 75 + true + + + + BTC Available: + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 75 + true + + + + 0.00000000 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + BTC + + + + + + + + + 11 + 301 + 209 + 15 + + + + + + + + 75 + true + + + + Total w/ 0.25% Fee + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 75 + true + + + + false + + + 0.00000000 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + 50 + false + + + + BTC + + + + + + + + + Sell + + + + + 790 + 140 + 21 + 23 + + + + BTC + + + + + + 129 + 140 + 191 + 23 + + + + + 10 + + + + + + + 10 + 110 + 46 + 23 + + + + + 75 + true + + + + Units + + + + + + 129 + 110 + 191 + 23 + + + + + 10 + + + + Max + + + + + + 10 + 170 + 71 + 16 + + + + + 75 + true + + + + Order Type + + + + + + 129 + 170 + 191 + 23 + + + + + 10 + + + + + + + 10 + 140 + 46 + 23 + + + + + 75 + true + + + + Bid + + + + + + 790 + 110 + 31 + 23 + + + + MACRON + + + + + + 330 + 110 + 451 + 23 + + + + + 9 + 75 + true + + + + + + + 330 + 140 + 451 + 23 + + + + + 9 + 75 + true + + + + + + + 30 + 330 + 75 + 23 + + + + Sell MACRON + + + + + + 22 + 12 + 200 + 15 + + + + + + + + 75 + true + + + + MACRON Available: + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 75 + true + + + + 0.00000000 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 75 + true + + + + MACRON + + + + + + + + + 10 + 300 + 218 + 15 + + + + + + + + 75 + true + + + + Total w/ 0.25% Fee + + + + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 127 + 212 + 127 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 255 + 0 + + + + + + + 0 + 212 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 113 + 0 + + + + + + + 0 + 85 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 85 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 170 + 0 + + + + + + + 255 + 255 + 220 + + + + + + + 0 + 0 + 0 + + + + + + + + + 75 + true + + + + false + + + 0.00000000 + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + 50 + false + + + + BTC + + + + + + + + + Order Book + + + + + 10 + 60 + 391 + 321 + + + + + 9 + 50 + false + + + + + + + 420 + 60 + 391 + 321 + + + + + 9 + 50 + false + + + + + + + 10 + 10 + 91 + 16 + + + + Bids + + + + + + 420 + 10 + 91 + 16 + + + + Asks + + + + + + 570 + 10 + 241 + 16 + + + + label + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 160 + 10 + 241 + 16 + + + + label + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 220 + 30 + 181 + 16 + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 630 + 30 + 181 + 16 + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 400 + 60 + 20 + 321 + + + + Qt::Vertical + + + + + + Market History + + + + + 10 + 10 + 801 + 371 + + + + + + + Open Orders + + + + + 10 + 40 + 801 + 341 + + + + + + + 10 + 10 + 101 + 17 + + + + Advanced View + + + + + + Trade history + + + + + 0 + 10 + 821 + 361 + + + + + + + Balance + + + + + 357 + 30 + 150 + 16 + + + + TextLabel + + + + + + 120 + 30 + 150 + 16 + + + + TextLabel + + + + + + 30 + 30 + 75 + 16 + + + + + 75 + true + + + + MACRON Balance: + + + + + + 270 + 30 + 71 + 16 + + + + + 75 + true + + + + BTC Balance: + + + + + + 120 + 70 + 150 + 16 + + + + TextLabel + + + + + + 30 + 70 + 83 + 16 + + + + + 75 + true + + + + MACRON Available: + + + + + + 30 + 110 + 76 + 16 + + + + + 75 + true + + + + MACRON Pending: + + + + + + 120 + 110 + 150 + 16 + + + + TextLabel + + + + + + 270 + 70 + 81 + 16 + + + + + 75 + true + + + + BTC Available + + + + + + 357 + 70 + 150 + 16 + + + + TextLabel + + + + + + 270 + 110 + 69 + 16 + + + + + 75 + true + + + + BTC Pending + + + + + + 357 + 110 + 150 + 16 + + + + TextLabel + + + + + + 30 + 200 + 171 + 16 + + + + + 75 + true + + + + Bittrex MACRON Deposit Address: + + + + + + 30 + 160 + 411 + 23 + + + + Generate MACRON Coin Deposit Address + + + + + + 200 + 200 + 261 + 16 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 255 + + + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 255 + + + + + + + + + 120 + 120 + 120 + + + + + + + 120 + 120 + 120 + + + + + + + + + 75 + true + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + Settings + + + + + 200 + 50 + 300 + 23 + + + + + + + + + + 30 + 90 + 71 + 20 + + + + + 75 + true + + + + Secret Key + + + + + + 30 + 50 + 51 + 20 + + + + + 75 + true + + + + API Key + + + + + + 200 + 90 + 300 + 23 + + + + + + + 560 + 90 + 191 + 23 + + + + Update API Keys + + + label + ApiKeyInput + label_2 + SecretKeyInput + UpdateKeys + + + + + + 0 + 0 + + + + + 849 + 30 + + + + + 16777215 + 220 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + 11 + 11 + 151 + 16 + + + + + 151 + 0 + + + + 0.00000000 + + + + + + + + 532 + 11 + 201 + 16 + + + + + 201 + 0 + + + + 0.000000000 + + + + + + + + 168 + 11 + 181 + 16 + + + + + 181 + 0 + + + + 0.00000000 + + + + + + + + 355 + 11 + 171 + 16 + + + + + 171 + 0 + + + + 0.00000000 + + + + + + + + + + + diff --git a/src/qt/governancelist.cpp b/src/qt/governancelist.cpp index b79745e7..d91077a3 100644 --- a/src/qt/governancelist.cpp +++ b/src/qt/governancelist.cpp @@ -47,6 +47,7 @@ GovernanceList::GovernanceList(const PlatformStyle *platformStyle, QWidget *pare timer->start(1000); fFilterUpdated = false; nTimeFilterUpdated = GetTime(); + } void GovernanceList::on_voteYesButton_clicked() diff --git a/src/qt/governancelist.h b/src/qt/governancelist.h index e640eede..f1cce380 100644 --- a/src/qt/governancelist.h +++ b/src/qt/governancelist.h @@ -10,10 +10,12 @@ #include #include #include +#include #define GOBJECT_UPDATE_SECONDS 15 #define GOBJECT_COOLDOWN_SECONDS 3 + namespace Ui { class GovernanceList; } @@ -46,6 +48,7 @@ class GovernanceList : public QWidget int64_t nTimeFilterUpdated; bool fFilterUpdated; + public Q_SLOTS: void updateGobjects(); diff --git a/src/qt/guiconstants.h b/src/qt/guiconstants.h index 8a10b956..f4eb8931 100644 --- a/src/qt/guiconstants.h +++ b/src/qt/guiconstants.h @@ -37,6 +37,9 @@ static const bool DEFAULT_SPLASHSCREEN = true; /* Transaction list -- TX status decoration - LockedByInstantSend color */ #define COLOR_TX_STATUS_LOCKED QColor(0, 128, 255) +/* Color of labels */ +#define COLOR_LABELS QColor("#000") + /* Tooltips longer than this (in characters) are converted into rich text, so that they can be word-wrapped. */ diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index d6a314ac..49ba384f 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -89,7 +89,7 @@ namespace GUIUtil { { return dateTimeStr(QDateTime::fromTime_t((qint32)nTime)); } - + QFont fixedPitchFont() { #if QT_VERSION >= 0x50200 @@ -523,22 +523,22 @@ namespace GUIUtil { } // We need to disconnect these while handling the resize events, otherwise we can enter infinite loops. - void TableViewLastColumnResizingFixer::disconnectViewHeadersSignals() - { - disconnect(tableView->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), this, SLOT(on_sectionResized(int, int, int))); - disconnect(tableView->horizontalHeader(), SIGNAL(geometriesChanged()), this, SLOT(on_geometriesChanged())); - } +void TableViewLastColumnResizingFixer::disconnectViewHeadersSignals() +{ + disconnect(tableView->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(on_sectionResized(int,int,int))); + disconnect(tableView->horizontalHeader(), SIGNAL(geometriesChanged()), this, SLOT(on_geometriesChanged())); +} - // Setup the resize mode, handles compatibility for Qt5 and below as the method signatures changed. - // Refactored here for readability. - void TableViewLastColumnResizingFixer::setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode) - { +// Setup the resize mode, handles compatibility for Qt5 and below as the method signatures changed. +// Refactored here for readability. +void TableViewLastColumnResizingFixer::setViewHeaderResizeMode(int logicalIndex, QHeaderView::ResizeMode resizeMode) +{ #if QT_VERSION < 0x050000 - tableView->horizontalHeader()->setResizeMode(logicalIndex, resizeMode); + tableView->horizontalHeader()->setResizeMode(logicalIndex, resizeMode); #else - tableView->horizontalHeader()->setSectionResizeMode(logicalIndex, resizeMode); + tableView->horizontalHeader()->setSectionResizeMode(logicalIndex, resizeMode); #endif - } +} void TableViewLastColumnResizingFixer::resizeColumn(int nColumnIndex, int width) { @@ -957,7 +957,7 @@ namespace GUIUtil { { return QString::fromStdString(path.string(utf8)); } - + QString formatDurationStr(int secs) { QStringList strList; @@ -977,18 +977,14 @@ namespace GUIUtil { return strList.join(" "); } - std::string FROMQS(QString qs) -{ - std::string sOut = qs.toUtf8().constData(); - return sOut; -} -QString TOQS(std::string s) + QString TOQS(std::string s) { QString str1 = QString::fromUtf8(s.c_str()); return str1; } + QString formatServicesStr(quint64 mask) { QStringList strList; diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h index 24aaf89a..c959f028 100644 --- a/src/qt/guiutil.h +++ b/src/qt/guiutil.h @@ -36,13 +36,15 @@ QT_END_NAMESPACE */ namespace GUIUtil { - QString TOQS(std::string s); - std::string FROMQS(QString qs); + + QString TOQS(std::string s); + std::string FROMQS(QString qs); // Create human-readable string from date QString dateTimeStr(const QDateTime &datetime); QString dateTimeStr(qint64 nTime); + // Return a monospace font QFont fixedPitchFont(); @@ -81,7 +83,6 @@ namespace GUIUtil /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix when no suffix is provided by the user. - @param[in] parent Parent window (or 0) @param[in] caption Window caption (or empty, for default) @param[in] dir Starting directory (or empty, to default to documents directory) @@ -94,7 +95,6 @@ namespace GUIUtil QString *selectedSuffixOut); /** Get open filename, convenience wrapper for QFileDialog::getOpenFileName. - @param[in] parent Parent window (or 0) @param[in] caption Window caption (or empty, for default) @param[in] dir Starting directory (or empty, to default to documents directory) @@ -107,7 +107,6 @@ namespace GUIUtil QString *selectedSuffixOut); /** Get connection type to call object slot in GUI thread with invokeMethod. The call will be blocking. - @returns If called from the GUI thread, return a Qt::DirectConnection. If called from another thread, return a Qt::BlockingQueuedConnection. */ @@ -207,7 +206,6 @@ namespace GUIUtil /* Convert OS specific boost path to QString through UTF-8 */ QString boostPathToQString(const boost::filesystem::path &path); - /* Convert seconds into a QString with days, hours, mins, secs */ QString formatDurationStr(int secs); diff --git a/src/qt/helpthehomeless.qrc b/src/qt/helpthehomeless.qrc index 8bb49e70..842849b5 100644 --- a/src/qt/helpthehomeless.qrc +++ b/src/qt/helpthehomeless.qrc @@ -15,6 +15,7 @@ res/icons/github.png res/icons/coinmix.png res/icons/governance.png + res/icons/chat.png res/icons/drkblue/address-book.png diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index 31acdd39..7299c197 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #define ICON_OFFSET 16 #define DECORATION_SIZE 54 @@ -76,7 +77,6 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) ui->setupUi(this); QString theme = GUIUtil::getThemeName(); - ui->pushButton_Website->setStatusTip(tr("Visit Help The Homeless Worldwide A NJ Nonprofit Corporation")); ui->pushButton_Website_1->setStatusTip(tr("Visit Help The Homeless Coin")); @@ -102,7 +102,8 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) timerinfo_peers = new QTimer(this); connect(timerinfo_peers, SIGNAL(timeout()), this, SLOT(updatePeersInfo())); timerinfo_peers->start(1000); - + + // start with displaying the "out of sync" warnings showOutOfSyncWarning(true); @@ -221,6 +222,7 @@ void OverviewPage::updateDisplayUnit() /**** Blockchain Information *****/ + void OverviewPage::updateMasternodeInfo() { if (!clientModel) { diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index c7db811b..71c54401 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -21,6 +21,7 @@ #include #include #include +#include #define MASTERNODELIST_UPDATE_SECONDS 3 #define MASTERNODELIST_FILTER_COOLDOWN_SECONDS 3 @@ -30,6 +31,8 @@ class TransactionFilterProxy; /* class TxViewDelegate; */ class PlatformStyle; class WalletModel; +class QNetworkAccessManager; +class QNetworkRequest; namespace Ui { @@ -85,6 +88,8 @@ public Q_SLOTS: QTimer* timerinfo_mn; QTimer* timerinfo_blockchain; QTimer* timerinfo_peers; + QNetworkAccessManager* networkManager; + QNetworkRequest* request; Ui::OverviewPage *ui; ClientModel *clientModel; WalletModel *walletModel; @@ -126,7 +131,7 @@ private Q_SLOTS: void on_pushButton_Mine_AMD_clicked(); void updateBlockChainInfo(); void updateMasternodeInfo(); - void updatePeersInfo(); + void updatePeersInfo(); }; #endif // BITCOIN_QT_OVERVIEWPAGE_H diff --git a/src/qt/res/css/drkblue.css b/src/qt/res/css/drkblue.css index beff53fc..dd50a599 100644 --- a/src/qt/res/css/drkblue.css +++ b/src/qt/res/css/drkblue.css @@ -2090,6 +2090,7 @@ QWidget .QFrame#frameBlockchainInfo_2 .QLabel#label_6 { } + /* MODAL OVERLAY */ QWidget#bgWidget { /* The 'frame' overlaying the overview-page */ diff --git a/src/qt/res/icons/chat.png b/src/qt/res/icons/chat.png new file mode 100644 index 00000000..06214345 Binary files /dev/null and b/src/qt/res/icons/chat.png differ diff --git a/src/qt/serveur.cpp b/src/qt/serveur.cpp new file mode 100644 index 00000000..8178aec1 --- /dev/null +++ b/src/qt/serveur.cpp @@ -0,0 +1,359 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ +#include +#include "serveur.h" + QStringList users; + bool delist = true; +Serveur::Serveur() +{ + connect(this, SIGNAL(readyRead()), this, SLOT(readServeur())); + connect(this, SIGNAL(connected()), this, SLOT(connected())); + connect(this, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(errorSocket(QAbstractSocket::SocketError))); + + updateUsers=false; +} + + + + +void Serveur::errorSocket(QAbstractSocket::SocketError error) +{ + switch(error) + { + case QAbstractSocket::HostNotFoundError: + affichage->append(tr("ERROR : can't find HTHWorld server.")); + break; + case QAbstractSocket::ConnectionRefusedError: + affichage->append(tr("ERROR : server refused connection")); + break; + case QAbstractSocket::RemoteHostClosedError: + affichage->append(tr("ERROR : server cut connection")); + break; + default: + affichage->append(tr("ERROR : ") + this->errorString() + tr("")); + } +} + +void Serveur::connected() +{ + affichage->append("Connecting... to HTHWorld IRC. Please wait."); + + sendData("USER "+pseudo+" localhost "+serveur+" :"+pseudo); + sendData("NICK "+pseudo); + affichage->append("Connected to HTHWorld IRC."); + +} + +void Serveur::joins() +{ + join("#HTHWorld"); +} + +void Serveur::readServeur() +{ + QString message=QString::fromUtf8(this->readAll()); + + + QString currentChan=tab->tabText(tab->currentIndex()); + + if(message.startsWith("PING :")) + { + QStringList liste=message.split(" "); + QString msg="PONG "+liste.at(1); + sendData(msg); + } + else if(message.contains("Nickname is already in use.")) + { + pseudo=pseudo+"_2"; + pseudo.remove("\r\n"); + sendData("NICK "+pseudo); + Q_EMIT pseudoChanged(pseudo); + ecrire("-> Name changed to "+pseudo); + } + else if(updateUsers==true) + { + updateUsersList("",message); + } + + QStringList list=message.split("\r\n"); + Q_FOREACH(QString msg,list) + { + if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PRIVMSG ([a-zA-Z0-9\\#]+) :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 <\\1> \\3"),"",msg2.replace(reg,"\\2 <\\1> \\3")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ JOIN ([a-zA-Z0-9\\#]+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 join \\2
"),"",msg2.replace(reg,"-> \\1 join \\2")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ PART ([a-zA-Z0-9\\#]+) :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 quit \\2 (\\3)
"),"",msg2.replace(reg,"-> \\1 quit \\2")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ QUIT (.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 quit this server (\\2)
"),"",msg2.replace(reg,"-> \\1 left")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NICK :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\1 is now called \\2
"),"",msg2.replace(reg,"-> \\1 is now called \\2")); + updateUsersList(currentChan); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"))) + { + QRegExp reg(":([a-zA-Z0-9]+)\\!~[a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ KICK ([a-zA-Z0-9\\#]+) ([a-zA-Z0-9]+) :(.+)"); + QString msg2=msg; + ecrire(msg.replace(reg,"\\2 -> \\1 kicked \\3 (\\4)
"),"",msg2.replace(reg,"-> \\1 quit \\3")); + updateUsersList(msg.replace(reg,"\\2")); + } + else if(msg.contains(QRegExp(":([a-zA-Z0-9]+)\\![a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE ([a-zA-Z0-9]+) :(.+)"))) + { + if(conversations.contains(currentChan)) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); + ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
"),currentChan); + } + else if(currentChan==serveur) + { + QRegExp reg(":([a-zA-Z0-9]+)\\![~a-zA-Z0-9]+@[a-zA-Z0-9\\/\\.-]+ NOTICE [a-zA-Z0-9]+ :(.+)"); + ecrire(msg.replace(reg,"[NOTICE] \\1 : \\2
")); + } + } + else if(msg.contains("/MOTD command.")) + { + joins(); + + + } + + + + } + + //} +} + +void Serveur::sendData(QString txt) +{ + if(this->state()==QAbstractSocket::ConnectedState) + { + this->write((txt+"\r\n").toUtf8()); + } +} + +QString Serveur::parseCommande(QString comm,bool serveur) +{ + if(comm.startsWith("/")) + { + comm.remove(0,1); + QString pref=comm.split(" ").first(); + QStringList args=comm.split(" "); + args.removeFirst(); + QString destChan=tab->tabText(tab->currentIndex()); + QString msg=args.join(" "); + + if(pref=="me") + return "PRIVMSG "+destChan+" ACTION " + msg + ""; + else if(pref=="msg") + return "MSG "+destChan+" ACTION " + msg + ""; + else if(pref=="join") + { + join(msg); + return " "; + } + else if(pref=="quit") + { + if(msg == "") + return "QUIT "+msgQuit; + else + return "QUIT "+msg; + } + else if(pref=="part") + { + tab->removeTab(tab->currentIndex()); + + if(msg == "") + { + if(msg.startsWith("#")) + destChan=msg.split(" ").first(); + + if(msgQuit=="") + return "PART "+destChan+" using IrcLightClient"; + else + return "PART "+destChan+" "+msgQuit; + } + else + return "PART "+destChan+" "+msg; + + conversations.remove(destChan); + } + else if(pref=="kick") + { + QStringList tableau=msg.split(" "); + QString c1,c2,c3; + if(tableau.count() > 0) c1=" "+tableau.first(); + else c1=""; + if(tableau.count() > 1) c2=" "+tableau.at(1); + else c2=""; + if(tableau.count() > 2) c3=" "+tableau.at(2); + else c3=""; + + if(c1.startsWith("#")) + return "KICK"+c1+c2+c3; + else + return "KICK "+destChan+c1+c2; + } + else if(pref=="update") + { + updateUsers=true; + return "WHO "+destChan; + } + else if(pref=="ns") + { + return "NICKSERV "+msg; + } + else if(pref=="nick") + { + Q_EMIT pseudoChanged(msg); + ecrire("-> Nickname changed to "+msg); + return "NICK "+msg; + } + else if(pref=="msg") + { + return "MSG "+msg; + } + + else + return pref+" "+msg; + } + else if(!serveur) + { + QString destChan=tab->tabText(tab->currentIndex()); + if(comm.endsWith("
")) + comm=comm.remove(QRegExp("
$")); + ecrire("<"+pseudo+"> "+comm,destChan); + + if(comm.startsWith(":")) + comm.insert(0,":"); + + return "PRIVMSG "+destChan+" "+comm.replace(" ","\t"); + } + else + { + return ""; + } +} + +void Serveur::join(QString chan) +{ + affichage->append("Joining "+ chan +" channel"); + Q_EMIT joinTab(); + QTextEdit *textEdit=new QTextEdit; + int index=tab->insertTab(tab->currentIndex()+1,textEdit,chan); + tab->setTabToolTip(index,serveur); + tab->setCurrentIndex(index); + + textEdit->setReadOnly(true); + + conversations.insert(chan,textEdit); + + sendData("JOIN "+chan); + + Q_EMIT tabJoined(); +} +void Serveur::leave(QString chan) +{ + sendData(parseCommande("/part "+chan+ " "+msgQuit)); +} + +void Serveur::ecrire(QString txt,QString destChan,QString msgTray) +{ + if(destChan!="") + { + conversations[destChan]->setHtml(conversations[destChan]->toHtml()+txt); + QScrollBar *sb = conversations[destChan]->verticalScrollBar(); + sb->setValue(sb->maximum()); + } + else if(txt.startsWith("#")) + { + QString dest=txt.split(" ").first(); + QStringList list=txt.split(" "); + list.removeFirst(); + txt=list.join(" "); + conversations[dest]->setHtml(conversations[dest]->toHtml()+txt); + QScrollBar *sb = conversations[dest]->verticalScrollBar(); + sb->setValue(sb->maximum()); } + else + { + txt.replace("\r\n","
"); + affichage->setHtml(affichage->toHtml()+txt+"
"); + QScrollBar *sb = affichage->verticalScrollBar(); + sb->setValue(sb->maximum()); + } + + +} + +void Serveur::updateUsersList(QString chan,QString message) +{ + message = message.replace("\r\n",""); + message = message.replace("\r",""); + if(chan!=serveur) + { + if(updateUsers==true || message != "") + { + QString liste2=message.replace(":",""); + QStringList liste=liste2.split(" "); + + if (delist == true) users.clear(); + + for(int i=5; i < liste.count(); i++) + { + users.append(liste.at(i)); + } + updateUsers=false; + if (liste.count() < 53) delist = true; + else delist = false; + QStringListModel *model = new QStringListModel(users); + userList->setModel(model); + userList->update(); + } + else + { + updateUsers=true; + sendData("NAMES "+chan); + } + } + else + { + QStringListModel model; + userList->setModel(&model); + userList->update(); + } +} diff --git a/src/qt/serveur.h b/src/qt/serveur.h new file mode 100644 index 00000000..9d2f6270 --- /dev/null +++ b/src/qt/serveur.h @@ -0,0 +1,67 @@ +/*Copyright (C) 2009 Cleriot Simon +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 2.1 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA*/ + +#ifndef SERVEUR_H +#define SERVEUR_H + +#include +#include +#include +#include +#include +#include + +class Serveur : public QTcpSocket +{ + Q_OBJECT + + public: + Serveur(); + QTextEdit *affichage; + QListView *userList; + QString pseudo,serveur,msgQuit; + int port; + QTabWidget *tab; + QMap conversations; + QSystemTrayIcon *tray; + + bool updateUsers; + + QString parseCommande(QString comm,bool serveur=false); + + QWidget *parent; + + + Q_SIGNALS: + void pseudoChanged(QString newPseudo); + void joinTab(); + void tabJoined(); + + public Q_SLOTS: + void readServeur(); + void errorSocket(QAbstractSocket::SocketError); + void connected(); + void joins(); + void sendData(QString txt); + void join(QString chan); + void leave(QString chan); + void ecrire(QString txt,QString destChan="",QString msgTray=""); + void updateUsersList(QString chan="",QString message=""); + + //void tabChanged(int index); +}; + +#endif // SERVEUR_H diff --git a/src/qt/tradingdialogpage.cpp b/src/qt/tradingdialogpage.cpp new file mode 100644 index 00000000..d0bdca29 --- /dev/null +++ b/src/qt/tradingdialogpage.cpp @@ -0,0 +1,1002 @@ +#include "tradingdialogpage.h" +#include "ui_tradingdialogpage.h" +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; + +TradingDialogPage::TradingDialogPage(QWidget *parent) : + QDialog(parent), + ui(new Ui::TradingDialogPage) +{ + ui->setupUi(this); + timerid = 0; + qDebug() << "Expected this"; + + QPalette sample_palette; + sample_palette.setColor(QPalette::Window, Qt::green); + + ui->BuyCostLabel->setPalette(sample_palette); + ui->SellCostLabel->setPalette(sample_palette); + ui->MACRONAvailableLabel->setPalette(sample_palette); + ui->BtcAvailableLbl_2->setPalette(sample_palette); + //Set tabs to inactive + ui->TradingTabWidget->setTabEnabled(0,false); + ui->TradingTabWidget->setTabEnabled(1,false); + ui->TradingTabWidget->setTabEnabled(4,false); + ui->TradingTabWidget->setTabEnabled(5,false); + ui->TradingTabWidget->setTabEnabled(6,false); + + + /*OrderBook Table Init*/ + CreateOrderBookTables(*ui->BidsTable,QStringList() << "TOTAL(BTC)"<< "MACRON(SIZE)" << "BID(BTC)"); + CreateOrderBookTables(*ui->AsksTable,QStringList() << "ASK(BTC)" << "MACRON(SIZE)" << "TOTAL(BTC)"); + /*OrderBook Table Init*/ + + /*Market History Table Init*/ + ui->MarketHistoryTable->setColumnCount(5); + ui->MarketHistoryTable->verticalHeader()->setVisible(false); + + ui->MarketHistoryTable->setHorizontalHeaderLabels(QStringList()<<"DATE"<<"BUY/SELL"<<"BID/ASK"<<"TOTAL UNITS(MACRON)"<<"TOTAL COST(BTC"); + ui->MarketHistoryTable->setRowCount(0); + + int Cellwidth = ui->MarketHistoryTable->width() / 5; + + ui->MarketHistoryTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + + ui->MarketHistoryTable->horizontalHeader()->resizeSection(1,Cellwidth); // column 1, width 50 + ui->MarketHistoryTable->horizontalHeader()->resizeSection(2,Cellwidth); + ui->MarketHistoryTable->horizontalHeader()->resizeSection(3,Cellwidth); + ui->MarketHistoryTable->horizontalHeader()->resizeSection(4,Cellwidth); + ui->MarketHistoryTable->horizontalHeader()->resizeSection(5,Cellwidth); + ui->MarketHistoryTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + ui->MarketHistoryTable->horizontalHeader()->setStyleSheet("QHeaderView::section, QHeaderView::section * {font-weight :bold;}"); + /*Market History Table Init*/ + + /*Account History Table Init*/ + ui->TradeHistoryTable->setColumnCount(13); + + ui->TradeHistoryTable->setHorizontalHeaderLabels(QStringList() << "Date Time" << "Exchange" << "OrderType" << "Limit" << "QTY" << "QTY_Rem" << "Price" << "PricePerUnit" << + "Conditional" << "Condition" << "Condition Target" << "ImmediateOrCancel" << "Closed"); + ui->TradeHistoryTable->setRowCount(0); + ui->TradeHistoryTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + ui->TradeHistoryTable->horizontalHeader()->setStyleSheet("QHeaderView::section, QHeaderView::section * {font-weight :bold;}"); + ui->TradeHistoryTable->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + /*Account History Table Init*/ + + /*Open Orders Table*/ + ui->OpenOrdersTable->setColumnCount(15); + ui->OpenOrdersTable->setHorizontalHeaderLabels(QStringList() << "OrderId" << "Date Time" << "Exchange" << "OrderType" << "Limit" << "QTY" << "QTY_Rem" << "Price" << "PricePerUnit" << "CancelInitiated" << + "Conditional" << "Condition" << "Condition Target" << "ImmediateOrCancel" << "Cancel Order"); + ui->OpenOrdersTable->setRowCount(0); + ui->OpenOrdersTable->setColumnHidden(0,true); + ui->OpenOrdersTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + ui->OpenOrdersTable->horizontalHeader()->setStyleSheet("QHeaderView::section, QHeaderView::section * {font-weight :bold;}"); + + ui->OpenOrdersTable->horizontalHeader()->resizeSection(1,120); // column 1, width 50 + ui->OpenOrdersTable->horizontalHeader()->resizeSection(2,70); + ui->OpenOrdersTable->horizontalHeader()->resizeSection(3,70); + ui->OpenOrdersTable->horizontalHeader()->resizeSection(4,70); + ui->OpenOrdersTable->horizontalHeader()->resizeSection(5,70); + ui->OpenOrdersTable->horizontalHeader()->resizeSection(6,70); + ui->OpenOrdersTable->horizontalHeader()->resizeSection(7,70); + + ui->OpenOrdersTable->setColumnHidden(9,true); + ui->OpenOrdersTable->setColumnHidden(10,true); + ui->OpenOrdersTable->setColumnHidden(11,true); + ui->OpenOrdersTable->setColumnHidden(12,true); + ui->OpenOrdersTable->setColumnHidden(13,true); + + connect (ui->OpenOrdersTable, SIGNAL(cellClicked(int,int)), this, SLOT(CancelOrderSlot(int, int))); + /*Open Orders Table*/ + + /*populate static combo values*/ + ui->BuyBidcomboBox -> addItems(QStringList()<<"Last"<<"Bid"<<"Ask"); + ui->buyOrdertypeCombo-> addItems(QStringList()<<"Limit"<<"Market"); + ui->SellBidcomboBox -> addItems(QStringList()<<"Last"<<"Bid"<<"Ask"); + ui->SellOrdertypeCombo-> addItems(QStringList()<<"Limit"<<"Market"); + //ui->BuyTimeInForceCombo-> addItems(QStringList()<<"Good 'Til Cancelled"<<"Immediate Or Cancel"); + //ui->BuyConditionCombo-> addItems(QStringList()<<"Greater Than Or Equal To"<<"Less Than Or Equal To"); + //ui->BuyConditionCombo->hide(); + //ui->BuyWhenPriceLabel->hide(); + //ui->ConditionLineEdit->hide(); + /*populate static combo values*/ +} + +void TradingDialogPage::InitTrading() +{ //todo - add internet connection/socket error checking. + + //Get default exchange info for the qlabels + UpdaterFunction(); + qDebug() << "Updater called"; + if(this->timerid == 0) + { + //Timer is not set,lets create one. + this->timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(UpdaterFunction())); + this->timer->start(5000); + this->timerid = this->timer->timerId(); + } + +} + +void TradingDialogPage::UpdaterFunction(){ + //MACRONst get the main exchange info in order to populate qLabels in maindialog. then get data + //required for the current tab. + + int Retval = SetExchangeInfoTextLabels(); + + if (Retval == 0){ + ActionsOnSwitch(-1); + } +} + +QString TradingDialogPage::GetMarketSummary(){ + + QString Response = sendRequest("https://bittrex.com/api/v1.1/public/GetMarketSummary?market=BTC-MACRON"); + return Response; +} + +QString TradingDialogPage::GetOrderBook(){ + + QString Response = sendRequest("https://bittrex.com/api/v1.1/public/getorderbook?market=BTC-MACRON&type=both&depth=50"); + return Response; +} + +QString TradingDialogPage::GetMarketHistory(){ + QString Response = sendRequest("https://bittrex.com/api/v1.1/public/getmarkethistory?market=BTC-MACRON&count=100"); + return Response; +} + +QString TradingDialogPage::CancelOrder(QString OrderId){ + + QString URL = "https://bittrex.com/api/v1.1/market/cancel?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434&uuid="; + URL += OrderId; + + QString Response = sendRequest(URL); + return Response; +} + +QString TradingDialogPage::BuyMACRON(QString OrderType, double Quantity, double Rate){ + + QString str = ""; + QString URL = "https://bittrex.com/api/v1.1/market/"; + URL += OrderType; + URL += "?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434&market=BTC-MACRON&quantity="; + URL += str.number(Quantity,'i',8); + URL += "&rate="; + URL += str.number(Rate,'i',8); + + QString Response = sendRequest(URL); + return Response; +} + +QString TradingDialogPage::SellMACRON(QString OrderType, double Quantity, double Rate){ + + QString str = ""; + QString URL = "https://bittrex.com/api/v1.1/market/"; + URL += OrderType; + URL += "?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434&market=BTC-MACRON&quantity="; + URL += str.number(Quantity,'i',8); + URL += "&rate="; + URL += str.number(Rate,'i',8); + + QString Response = sendRequest(URL); + return Response; +} + +QString TradingDialogPage::GetOpenOrders(){ + QString URL = "https://bittrex.com/api/v1.1/market/getopenorders?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434&market=MACRON-BTC"; + + QString Response = sendRequest(URL); + return Response; +} + +QString TradingDialogPage::GetBalance(QString Currency){ + + QString URL = "https://bittrex.com/api/v1.1/account/getbalance?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434¤cy=MACRON"; + URL += Currency; + + QString Response = sendRequest(URL); + return Response; +} + +QString TradingDialogPage::GetDepositAddress(){ + + QString URL = "https://bittrex.com/api/v1.1/account/getdepositaddress?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434¤cy=MACRON"; + + QString Response = sendRequest(URL); + return Response; +} + +QString TradingDialogPage::GetAccountHistory(){ + + QString URL = "https://bittrex.com/api/v1.1/account/getorderhistory?apikey="; + URL += this->ApiKey; + URL += "&nonce=12345434&market=MACRON-BTC&count=10"; + + QString Response = sendRequest(URL); + return Response; +} + +int TradingDialogPage::SetExchangeInfoTextLabels(){ + //Get the current exchange information + information for the current open tab if required. + QString str = ""; + QString Response = GetMarketSummary(); + + //Set the labels, parse the json result to get values. + QJsonObject obj = GetResultObjectFromJSONArray(Response); + + //set labels to richtext to use css. + ui->Bid->setTextFormat(Qt::RichText); + ui->Ask->setTextFormat(Qt::RichText); + ui->volumet->setTextFormat(Qt::RichText); + ui->volumebtc->setTextFormat(Qt::RichText); + + ui->Ask->setText("Ask: " + str.number(obj["Ask"].toDouble(),'i',8) + " BTC"); + + ui->Bid->setText("Bid: " + str.number(obj["Bid"].toDouble(),'i',8) + " BTC"); + + ui->volumet->setText("MACRON Volume: " + str.number(obj["Volume"].toDouble(),'i',8) + " MACRON"); + + ui->volumebtc->setText("BTC Volume: " + str.number(obj["BaseVolume"].toDouble(),'i',8) + " BTC"); + + obj.empty(); + +return 0; + } + +void TradingDialogPage::CreateOrderBookTables(QTableWidget& Table,QStringList TableHeader){ + + Table.setColumnCount(3); + Table.verticalHeader()->setVisible(false); + + Table.setHorizontalHeaderLabels(TableHeader); + + int Cellwidth = Table.width() / 3; + + Table.horizontalHeader()->resizeSection(1,Cellwidth); // column 1, width 50 + Table.horizontalHeader()->resizeSection(2,Cellwidth); + Table.horizontalHeader()->resizeSection(3,Cellwidth); + + Table.setRowCount(0); + + Table.horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); + Table.horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + Table.horizontalHeader()->setStyleSheet("QHeaderView::section, QHeaderView::section * { font-weight :bold;}"); +} + +void TradingDialogPage::DisplayBalance(QLabel &BalanceLabel,QLabel &Available, QLabel &Pending, QString Currency,QString Response){ + + QString str; + + BalanceLabel.setTextFormat(Qt::RichText); + Available.setTextFormat(Qt::RichText); + Pending.setTextFormat(Qt::RichText); + + //Set the labels, parse the json result to get values. + QJsonObject ResultObject = GetResultObjectFromJSONObject(Response); + + BalanceLabel.setText("" + str.number( ResultObject["Balance"].toDouble(),'i',8) + " " + Currency); + Available.setText("" + str.number( ResultObject["Available"].toDouble(),'i',8) + " " +Currency); + Pending.setText("" + str.number( ResultObject["Pending"].toDouble(),'i',8) + " " +Currency); +} + +void TradingDialogPage::ParseAndPopulateOpenOrdersTable(QString Response){ + + int itteration = 0, RowCount = 0; + + QJsonArray jsonArray = GetResultArrayFromJSONObject(Response); + QJsonObject obj; + + ui->OpenOrdersTable->setRowCount(0); + + Q_FOREACH (const QJsonValue & value, jsonArray) + { + QString str = ""; + obj = value.toObject(); + + RowCount = ui->OpenOrdersTable->rowCount(); + + QString ios; + QString IsConditional; + QString ConditionTarget; + QString CancelInitiated; + + obj["ImmediateOrCancel"].toBool() == true ? (ios = "true") : ( ios = "false"); + obj["IsConditional"].toBool() == true ? (IsConditional = "true") : ( IsConditional = "false"); + obj["ConditionTarget"].toBool() == true ? (ConditionTarget = "true") : ( ConditionTarget = "false"); + obj["CancelInitiated"].toBool() == true ? (CancelInitiated = "true") : ( CancelInitiated = "false"); + + ui->OpenOrdersTable->insertRow(RowCount); + ui->OpenOrdersTable->setItem(itteration, 0, new QTableWidgetItem(obj["OrderUuid"].toString())); + ui->OpenOrdersTable->setItem(itteration, 1, new QTableWidgetItem(BittrexTimeStampToReadable(obj["Opened"].toString()))); + ui->OpenOrdersTable->setItem(itteration, 2, new QTableWidgetItem(obj["Exchange"].toString())); + ui->OpenOrdersTable->setItem(itteration, 3, new QTableWidgetItem(obj["OrderType"].toString())); + ui->OpenOrdersTable->setItem(itteration, 4, new QTableWidgetItem(str.number(obj["Limit"].toDouble(),'i',8))); + ui->OpenOrdersTable->setItem(itteration, 5, new QTableWidgetItem(str.number(obj["Quantity"].toDouble(),'i',8))); + ui->OpenOrdersTable->setItem(itteration, 6, new QTableWidgetItem(str.number(obj["QuantityRemaining"].toDouble(),'i',8))); + ui->OpenOrdersTable->setItem(itteration, 7, new QTableWidgetItem(str.number(obj["Price"].toDouble(),'i',8))); + ui->OpenOrdersTable->setItem(itteration, 8, new QTableWidgetItem(str.number(obj["PricePerUnit"].toDouble(),'i',8))); + ui->OpenOrdersTable->setItem(itteration, 9, new QTableWidgetItem(CancelInitiated)); + ui->OpenOrdersTable->setItem(itteration, 10, new QTableWidgetItem(IsConditional)); + ui->OpenOrdersTable->setItem(itteration, 11, new QTableWidgetItem(obj["Condition"].toString())); + ui->OpenOrdersTable->setItem(itteration, 12, new QTableWidgetItem(ConditionTarget)); + ui->OpenOrdersTable->setItem(itteration, 13, new QTableWidgetItem(ios)); + ui->OpenOrdersTable->setItem(itteration, 14, new QTableWidgetItem(tr("Cancel Order"))); + + //Handle the cancel link in open orders table + QTableWidgetItem* CancelCell; + CancelCell= ui->OpenOrdersTable->item(itteration, 14); //Set the wtablewidget item to the cancel cell item. + CancelCell->setForeground(QColor::fromRgb(255,0,0)); //make this item red. + CancelCell->setTextAlignment(Qt::AlignCenter); + } +} + + +void TradingDialogPage::CancelOrderSlot(int row, int col){ + + QString OrderId = ui->OpenOrdersTable->model()->data(ui->OpenOrdersTable->model()->index(row,0)).toString(); + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this,"Cancel Order","Are you sure you want to cancel the order?",QMessageBox::Yes|QMessageBox::No); + + if (reply == QMessageBox::Yes) { + + QString Response = CancelOrder(OrderId); + + QJsonDocument jsonResponse = QJsonDocument::fromJson(Response.toUtf8()); + QJsonObject ResponseObject = jsonResponse.object(); + + if (ResponseObject["success"].toBool() == false){ + + QMessageBox::information(this,"Failed To Cancel Order",ResponseObject["message"].toString()); + + }else if (ResponseObject["success"].toBool() == true){ + ui->OpenOrdersTable->model()->removeRow(row); + QMessageBox::information(this,"Success","You're order was cancelled."); + } + } else { + qDebug() << "Do Nothing"; + } +} + +void TradingDialogPage::ParseAndPopulateAccountHistoryTable(QString Response){ + + int itteration = 0, RowCount = 0; + + QJsonArray jsonArray = GetResultArrayFromJSONObject(Response); + QJsonObject obj; + + ui->TradeHistoryTable->setRowCount(0); + + Q_FOREACH (const QJsonValue & value, jsonArray) + { + QString str = ""; + obj = value.toObject(); + + RowCount = ui->TradeHistoryTable->rowCount(); + + QString ios; + QString IsConditional; + QString ConditionTarget; + + obj["ImmediateOrCancel"].toBool() == true ? (ios = "true") : ( ios = "false"); + obj["IsConditional"].toBool() == true ? (IsConditional = "true") : ( IsConditional = "false"); + obj["ConditionTarget"].toBool() == true ? (ConditionTarget = "true") : ( ConditionTarget = "false"); + + ui->TradeHistoryTable->insertRow(RowCount); + ui->TradeHistoryTable->setItem(itteration, 0, new QTableWidgetItem(BittrexTimeStampToReadable(obj["TimeStamp"].toString()))); + ui->TradeHistoryTable->setItem(itteration, 1, new QTableWidgetItem(obj["Exchange"].toString())); + ui->TradeHistoryTable->setItem(itteration, 2, new QTableWidgetItem(obj["OrderType"].toString())); + ui->TradeHistoryTable->setItem(itteration, 3, new QTableWidgetItem(str.number(obj["Limit"].toDouble(),'i',8))); + ui->TradeHistoryTable->setItem(itteration, 4, new QTableWidgetItem(str.number(obj["Quantity"].toDouble(),'i',8))); + ui->TradeHistoryTable->setItem(itteration, 5, new QTableWidgetItem(str.number(obj["QuantityRemaining"].toDouble(),'i',8))); + ui->TradeHistoryTable->setItem(itteration, 6, new QTableWidgetItem(str.number(obj["Price"].toDouble(),'i',8))); + ui->TradeHistoryTable->setItem(itteration, 7, new QTableWidgetItem(str.number(obj["PricePerUnit"].toDouble(),'i',8))); + ui->TradeHistoryTable->setItem(itteration, 8, new QTableWidgetItem(IsConditional)); + ui->TradeHistoryTable->setItem(itteration, 9, new QTableWidgetItem(obj["Condition"].toString())); + ui->TradeHistoryTable->setItem(itteration, 10, new QTableWidgetItem(ConditionTarget)); + ui->TradeHistoryTable->setItem(itteration, 11, new QTableWidgetItem(ios)); + ui->TradeHistoryTable->setItem(itteration, 12, new QTableWidgetItem(obj["Closed"].toString())); + itteration++; + } + + obj.empty(); +} + + +void TradingDialogPage::ParseAndPopulateOrderBookTables(QString OrderBook){ + + QString str; + QJsonObject obj; + QJsonObject ResultObject = GetResultObjectFromJSONObject(OrderBook); + + int BuyItteration = 0,SellItteration = 0, BidRows = 0, AskRows = 0; + + QJsonArray BuyArray = ResultObject.value("buy").toArray(); //get buy/sell object from result object + QJsonArray SellArray = ResultObject.value("sell").toArray(); //get buy/sell object from result object + + double MACRONSupply = 0; + double MACRONDemand = 0; + double BtcSupply = 0; + double BtcDemand = 0; + + ui->AsksTable->setRowCount(0); + + Q_FOREACH (const QJsonValue & value, SellArray) + { + obj = value.toObject(); + + double x = obj["Rate"].toDouble(); //would like to use int64 here + double y = obj["Quantity"].toDouble(); + double a = (x * y); + + MACRONSupply = MACRONSupply + y; + BtcSupply = BtcSupply + a; + + AskRows = ui->AsksTable->rowCount(); + ui->AsksTable->insertRow(AskRows); + + ui->AsksTable->setItem(SellItteration, 0, new QTableWidgetItem(str.number(x,'i',8))); + ui->AsksTable->setItem(SellItteration, 1, new QTableWidgetItem(str.number(y,'i',8))); + ui->AsksTable->setItem(SellItteration, 2, new QTableWidgetItem(str.number(a,'i',8))); + SellItteration++; + } + + ui->BidsTable->setRowCount(0); + + Q_FOREACH (const QJsonValue & value, BuyArray) + { + obj = value.toObject(); + + double x = obj["Rate"].toDouble(); //would like to use int64 here + double y = obj["Quantity"].toDouble(); + double a = (x * y); + + MACRONDemand = MACRONDemand + y; + BtcDemand = BtcDemand + a; + + BidRows = ui->BidsTable->rowCount(); + ui->BidsTable->insertRow(BidRows); + ui->BidsTable->setItem(BuyItteration, 0, new QTableWidgetItem(str.number(a,'i',8))); + ui->BidsTable->setItem(BuyItteration, 1, new QTableWidgetItem(str.number(y,'i',8))); + ui->BidsTable->setItem(BuyItteration, 2, new QTableWidgetItem(str.number(x,'i',8))); + BuyItteration++; + } + + ui->MACRONSupply->setText("Supply: " + str.number(MACRONSupply,'i',8) + " MACRON"); + ui->BtcSupply->setText("" + str.number(BtcSupply,'i',8) + " BTC"); + ui->AsksCount->setText("Ask's : " + str.number(ui->AsksTable->rowCount()) + ""); + + + ui->MACRONDemand->setText("Demand: " + str.number(MACRONDemand,'i',8) + " MACRON"); + ui->BtcDemand->setText("" + str.number(BtcDemand,'i',8) + " BTC"); + ui->BidsCount->setText("Bid's : " + str.number(ui->BidsTable->rowCount()) + ""); + obj.empty(); +} + + +void TradingDialogPage::ParseAndPopulateMarketHistoryTable(QString Response){ + + int itteration = 0, RowCount = 0; + QJsonArray jsonArray = GetResultArrayFromJSONObject(Response); + QJsonObject obj; + + ui->MarketHistoryTable->setRowCount(0); + + Q_FOREACH (const QJsonValue & value, jsonArray) + { + QString str = ""; + obj = value.toObject(); + + RowCount = ui->MarketHistoryTable->rowCount(); + + ui->MarketHistoryTable->insertRow(RowCount); + ui->MarketHistoryTable->setItem(itteration, 0, new QTableWidgetItem(BittrexTimeStampToReadable(obj["TimeStamp"].toString()))); + ui->MarketHistoryTable->setItem(itteration, 1, new QTableWidgetItem(obj["OrderType"].toString())); + ui->MarketHistoryTable->setItem(itteration, 2, new QTableWidgetItem(str.number(obj["Price"].toDouble(),'i',8))); + ui->MarketHistoryTable->setItem(itteration, 3, new QTableWidgetItem(str.number(obj["Quantity"].toDouble(),'i',8))); + ui->MarketHistoryTable->setItem(itteration, 4, new QTableWidgetItem(str.number(obj["Total"].toDouble(),'i',8))); + ui->MarketHistoryTable->item(itteration,1)->setBackgroundColor((obj["OrderType"] == "BUY") ? (QColor (150, 191, 70,255)) : ( QColor (201, 119, 153,255))); + itteration++; + } + obj.empty(); +} + +void TradingDialogPage::ActionsOnSwitch(int index = -1){ + + QString Response = ""; + + if(index == -1){ + index = ui->TradingTabWidget->currentIndex(); + } + + switch (index){ + case 0: //buy tab is active + Response = GetMarketSummary(); + if(Response.size() > 0 && Response != "Error"){ + + QString balance = GetBalance("BTC"); + + QString str; + QJsonObject ResultObject = GetResultObjectFromJSONObject(balance); + + ui->BtcAvailableLbl->setText(str.number(ResultObject["Available"].toDouble(),'i',8)); + } + + break; + + case 1: //sell tab active + //Sell tab is active + Response = GetMarketSummary(); + if(Response.size() > 0 && Response != "Error"){ + + QString balance = GetBalance("MACRON"); + QString str; + QJsonObject ResultObject = GetResultObjectFromJSONObject(balance); + + ui->MACRONAvailableLabel->setText(str.number(ResultObject["Available"].toDouble(),'i',8)); + } + + break; + + case 2: //Order book tab is the current tab - update the info + Response = GetOrderBook(); + if(Response.size() > 0 && Response != "Error"){ + ParseAndPopulateOrderBookTables(Response); + } + + break; + + case 3://market history tab + Response = GetMarketHistory(); + if(Response.size() > 0 && Response != "Error"){ + ParseAndPopulateMarketHistoryTable(Response); + } + break; + + case 4: //open orders tab + Response = GetOpenOrders(); + if(Response.size() > 0 && Response != "Error"){ + ParseAndPopulateOpenOrdersTable(Response); + } + + break; + + case 5://account history tab + Response = GetAccountHistory(); + if(Response.size() > 0 && Response != "Error"){ + ParseAndPopulateAccountHistoryTable(Response); + } + break; + + case 6://show balance tab + Response = GetBalance("BTC"); + if(Response.size() > 0 && Response != "Error"){ + DisplayBalance(*ui->BitcoinBalanceLabel,*ui->BitcoinAvailableLabel,*ui->BitcoinPendingLabel, QString::fromUtf8("BTC"),Response); + } + + Response = GetBalance("MACRON"); + + if(Response.size() > 0 && Response != "Error"){ + DisplayBalance(*ui->MACRONBalanceLabel,*ui->MACRONAvailableLabel,*ui->MACRONPendingLabel, QString::fromUtf8("MACRON"),Response); + } + break; + + case 7: + + break; + + } + +} + +void TradingDialogPage::on_TradingTabWidget_tabBarClicked(int index) +{ + //tab was clicked, interrupt the timer and restart after action completed. + + this->timer->stop(); + + ActionsOnSwitch(index); + + this->timer->start(); +} + + +QString TradingDialogPage::sendRequest(QString url){ + + QString Response = ""; + QString Secret = this->SecretKey; + + // create custom temporary event loop on stack + QEventLoop eventLoop; + + // "quit()" the event-loop, when the network request "finished()" + QNetworkAccessManager mgr; + QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); + + // the HTTP request + QNetworkRequest req = QNetworkRequest(QUrl(url)); + + req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + + //make this conditional,depending if we are using private api call + req.setRawHeader("apisign",HMAC_SHA512_SIGNER(url,Secret).toStdString().c_str()); //set header for bittrex + + QNetworkReply *reply = mgr.get(req); + eventLoop.exec(); // blocks stack until "finished()" has been called + + if (reply->error() == QNetworkReply::NoError) { + //success + Response = reply->readAll(); + delete reply; + } + else{ + //failure + qDebug() << "Failure" <errorString(); + Response = "Error"; + //QMessageBox::information(this,"Error",reply->errorString()); + delete reply; + } + + return Response; +} + +QString TradingDialogPage::BittrexTimeStampToReadable(QString DateTime){ + //Seperate Time and date. + int TPos = DateTime.indexOf("T"); + int sPos = DateTime.indexOf("."); + QDateTime Date = QDateTime::fromString(DateTime.left(TPos),"yyyy-MM-dd"); //format to convert from + DateTime.remove(sPos,sizeof(DateTime)); + DateTime.remove(0,TPos+1); + QDateTime Time = QDateTime::fromString(DateTime.right(TPos),"hh:mm:ss"); + + //Reconstruct time and date in our own format, one that QDateTime will recognise. + QString DisplayDate = Date.toString("dd/MM/yyyy") + " " + Time.toString("hh:mm:ss A"); //formats to convert to + + return DisplayDate; +} + +void TradingDialogPage::CalculateBuyCostLabel(){ + + double price = ui->BuyBidPriceEdit->text().toDouble(); + double Quantity = ui->UnitsInput->text().toDouble(); + double cost = ((price * Quantity) + ((price * Quantity / 100) * 0.25)); + + QString Str = ""; + ui->BuyCostLabel->setText(Str.number(cost,'i',8)); +} + +void TradingDialogPage::CalculateSellCostLabel(){ + + double price = ui->SellBidPriceEdit->text().toDouble(); + double Quantity = ui->UnitsInputMACRON->text().toDouble(); + double cost = ((price * Quantity) - ((price * Quantity / 100) * 0.25)); + + QString Str = ""; + ui->SellCostLabel->setText(Str.number(cost,'i',8)); +} + +void TradingDialogPage::on_UpdateKeys_clicked() +{ + this->ApiKey = ui->ApiKeyInput->text(); + this->SecretKey = ui->SecretKeyInput->text(); + + QJsonDocument jsonResponse = QJsonDocument::fromJson(GetAccountHistory().toUtf8()); //get json from str. + QJsonObject ResponseObject = jsonResponse.object(); //get json obj + + if ( ResponseObject.value("success").toBool() == false){ + QMessageBox::information(this,"API Configuration Failed","Api configuration was unsuccesful."); + + }else if ( ResponseObject.value("success").toBool() == true){ + QMessageBox::information(this,"API Configuration Complete","Api connection has been successfully configured and tested."); + ui->ApiKeyInput->setEchoMode(QLineEdit::Password); + ui->SecretKeyInput->setEchoMode(QLineEdit::Password); + ui->TradingTabWidget->setTabEnabled(0,true); + ui->TradingTabWidget->setTabEnabled(1,true); + ui->TradingTabWidget->setTabEnabled(3,true); + ui->TradingTabWidget->setTabEnabled(4,true); + ui->TradingTabWidget->setTabEnabled(5,true); + ui->TradingTabWidget->setTabEnabled(6,true); + } + +} + +void TradingDialogPage::on_GenDepositBTN_clicked() +{ + QString response = GetDepositAddress(); + QJsonObject ResultObject = GetResultObjectFromJSONObject(response); + ui->DepositAddressLabel->setText(ResultObject["Address"].toString()); +} + + +void TradingDialogPage::on_Sell_Max_Amount_clicked() +{ + //calculate amount of BTC that can be gained from selling MACRON available balance + QString responseA = GetBalance("MACRON"); + QString str; + QJsonObject ResultObject = GetResultObjectFromJSONObject(responseA); + + double AvailableMACRON = ResultObject["Available"].toDouble(); + + ui->UnitsInputMACRON->setText(str.number(AvailableMACRON,'i',8)); +} + +void TradingDialogPage::on_Buy_Max_Amount_clicked() +{ + //calculate amount of currency than can be brought with the BTC balance available + QString responseA = GetBalance("BTC"); + QString responseB = GetMarketSummary(); + QString str; + + QJsonObject ResultObject = GetResultObjectFromJSONObject(responseA); + QJsonObject ResultObj = GetResultObjectFromJSONArray(responseB); + + //Get the Bid ask or last value from combo + QString value = ui->BuyBidcomboBox->currentText(); + + double AvailableBTC = ResultObject["Available"].toDouble(); + double CurrentASK = ResultObj[value].toDouble(); + double Result = (AvailableBTC / CurrentASK); + double percentofnumber = (Result * 0.0025); + + Result = Result - percentofnumber; + ui->UnitsInput->setText(str.number(Result,'i',8)); +} + +void TradingDialogPage::on_buyOrdertypeCombo_activated(const QString &arg1) +{ + if(arg1 == "Conditional"){ + //ui->BuyWhenPriceLabel->show(); + //ui->BuyConditionCombo->show(); + //ui->ConditionLineEdit->show(); + //ui->Conditionlabel->show(); + }else if (arg1 == "Limit"){ + // ui->BuyWhenPriceLabel->hide(); + // ui->BuyConditionCombo->hide(); + // ui->ConditionLineEdit->hide(); + // ui->Conditionlabel->hide(); + } +} + + +QJsonObject TradingDialogPage::GetResultObjectFromJSONObject(QString response){ + + QJsonDocument jsonResponse = QJsonDocument::fromJson(response.toUtf8()); //get json from str. + QJsonObject ResponseObject = jsonResponse.object(); //get json obj + QJsonObject ResultObject = ResponseObject.value(QString("result")).toObject(); //get result object + + return ResultObject; +} + +QJsonObject TradingDialogPage::GetResultObjectFromJSONArray(QString response){ + + QJsonDocument jsonResponsea = QJsonDocument::fromJson(response.toUtf8()); + QJsonObject jsonObjecta = jsonResponsea.object(); + QJsonArray jsonArraya = jsonObjecta["result"].toArray(); + QJsonObject obj; + + Q_FOREACH (const QJsonValue & value, jsonArraya) + { + obj = value.toObject(); + } + +return obj; +} + +QJsonArray TradingDialogPage::GetResultArrayFromJSONObject(QString response){ + + QJsonDocument jsonResponse = QJsonDocument::fromJson(response.toUtf8()); + QJsonObject jsonObject = jsonResponse.object(); + QJsonArray jsonArray = jsonObject["result"].toArray(); + +return jsonArray; +} + +QString TradingDialogPage::HMAC_SHA512_SIGNER(QString UrlToSign, QString Secret){ + + QString retval = ""; + + QByteArray byteArray = UrlToSign.toUtf8(); + const char* URL = byteArray.constData(); + + QByteArray byteArrayB = Secret.toUtf8(); + const char* Secretkey = byteArrayB.constData(); + + unsigned char* digest; + + // Using sha512 hash engine here. + digest = HMAC(EVP_sha512(), Secretkey, strlen( Secretkey), (unsigned char*) URL, strlen( URL), NULL, NULL); + + // Be careful of the length of string with the choosen hash engine. SHA1 produces a 20-byte hash value which rendered as 40 characters. + // Change the length accordingly with your choosen hash engine + char mdString[128]; + + for(int i = 0; i < 64; i++){ + sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]); + } + retval = mdString; + //qDebug() << "HMAC digest:"<< retval; + + return retval; +} + +void TradingDialogPage::on_SellBidcomboBox_currentIndexChanged(const QString &arg1) +{ + QString response = GetMarketSummary(); + QJsonObject ResultObject = GetResultObjectFromJSONArray(response); + QString Str; + + //Get the Bid ask or last value from combo + ui->SellBidPriceEdit->setText(Str.number(ResultObject[arg1].toDouble(),'i',8)); + + CalculateSellCostLabel(); //update cost +} + +void TradingDialogPage::on_BuyBidcomboBox_currentIndexChanged(const QString &arg1) +{ + QString response = GetMarketSummary(); + QJsonObject ResultObject = GetResultObjectFromJSONArray(response); + QString Str; + + //Get the Bid ask or last value from combo + ui->BuyBidPriceEdit->setText(Str.number(ResultObject[arg1].toDouble(),'i',8)); + + CalculateBuyCostLabel(); //update cost +} + +void TradingDialogPage::on_BuyMACRON_clicked() +{ + double Rate; + double Quantity; + + Rate = ui->BuyBidPriceEdit->text().toDouble(); + Quantity = ui->UnitsInput->text().toDouble(); + + QString OrderType = ui->buyOrdertypeCombo->currentText(); + QString Order; + + if(OrderType == "Limit"){Order = "buylimit";}else if (OrderType == "Market"){ Order = "buymarket";} + + QString Msg = "Are you sure you want to buy "; + Msg += ui->UnitsInput->text(); + Msg += "MACRON @ "; + Msg += ui->BuyBidPriceEdit->text(); + Msg += " BTC Each"; + + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this,"Buy Order",Msg,QMessageBox::Yes|QMessageBox::No); + + if (reply == QMessageBox::Yes) { + + QString Response = BuyMACRON(Order,Quantity,Rate); + + QJsonDocument jsonResponse = QJsonDocument::fromJson(Response.toUtf8()); //get json from str. + QJsonObject ResponseObject = jsonResponse.object(); //get json obj + + if (ResponseObject["success"].toBool() == false){ + + QMessageBox::information(this,"Buy Order Failed",ResponseObject["message"].toString()); + + }else if (ResponseObject["success"].toBool() == true){ + QMessageBox::information(this,"Buy Order Initiated","You Placed an order"); + } + }else{ + + //do nothing + } +} + +void TradingDialogPage::on_SellMACRONBTN_clicked() +{ + double Rate; + double Quantity; + + Rate = ui->SellBidPriceEdit->text().toDouble(); + Quantity = ui->UnitsInputMACRON->text().toDouble(); + + QString OrderType = ui->SellOrdertypeCombo->currentText(); + QString Order; + + if(OrderType == "Limit"){Order = "selllimit";}else if (OrderType == "Market"){ Order = "sellmarket";} + + QString Msg = "Are you sure you want to Sell "; + Msg += ui->UnitsInputMACRON->text(); + Msg += " MACRON @ "; + Msg += ui->SellBidPriceEdit->text(); + Msg += " BTC Each"; + + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this,"Sell Order",Msg,QMessageBox::Yes|QMessageBox::No); + + if (reply == QMessageBox::Yes) { + + QString Response = SellMACRON(Order,Quantity,Rate); + QJsonDocument jsonResponse = QJsonDocument::fromJson(Response.toUtf8()); //get json from str. + QJsonObject ResponseObject = jsonResponse.object(); //get json obj + + if (ResponseObject["success"].toBool() == false){ + + QMessageBox::information(this,"Sell Order Failed",ResponseObject["message"].toString()); + + }else if (ResponseObject["success"].toBool() == true){ + QMessageBox::information(this,"Sell Order Initiated","You Placed an order"); + } +}else{ + + //do nothing + } +} + + +void TradingDialogPage::on_AdvancedView_stateChanged(int arg1) +{ + //Show or hide columns in OpenOrders Table depending on checkbox state + if(arg1 == 2){ + ui->OpenOrdersTable->setColumnHidden(9,false); + ui->OpenOrdersTable->setColumnHidden(10,false); + ui->OpenOrdersTable->setColumnHidden(11,false); + ui->OpenOrdersTable->setColumnHidden(12,false); + ui->OpenOrdersTable->setColumnHidden(13,false); + }else if(arg1 == 0) { + ui->OpenOrdersTable->setColumnHidden(9,true); + ui->OpenOrdersTable->setColumnHidden(10,true); + ui->OpenOrdersTable->setColumnHidden(11,true); + ui->OpenOrdersTable->setColumnHidden(12,true); + ui->OpenOrdersTable->setColumnHidden(13,true); + + } +} + +void TradingDialogPage::on_UnitsInputMACRON_textChanged(const QString &arg1) +{ + CalculateSellCostLabel(); //update cost +} + +void TradingDialogPage::on_UnitsInput_textChanged(const QString &arg1) +{ + CalculateBuyCostLabel(); //update cost +} + +void TradingDialogPage::on_BuyBidPriceEdit_textChanged(const QString &arg1) +{ + CalculateBuyCostLabel(); //update cost +} + +void TradingDialogPage::on_SellBidPriceEdit_textChanged(const QString &arg1) +{ + CalculateSellCostLabel(); +} + +TradingDialogPage::~TradingDialogPage() +{ + delete ui; +} diff --git a/src/qt/tradingdialogpage.h b/src/qt/tradingdialogpage.h new file mode 100644 index 00000000..a86110bd --- /dev/null +++ b/src/qt/tradingdialogpage.h @@ -0,0 +1,87 @@ +#ifndef TRADINGDIALOGPAGE_H +#define TRADINGDIALOGPAGE_H + +#include +#include +#include +#include "ui_tradingdialogpage.h" + +#include +#include + +namespace Ui { +class TradingDialogPage; +} + +class TradingDialogPage : public QDialog +{ + Q_OBJECT + +public: + explicit TradingDialogPage(QWidget *parent = 0); + ~TradingDialogPage(); + +private Q_SLOTS: + + void InitTrading(); + void on_TradingTabWidget_tabBarClicked(int index); + void ParseAndPopulateOrderBookTables(QString Response); + void ParseAndPopulateMarketHistoryTable(QString Response); + void ParseAndPopulateAccountHistoryTable(QString Response); + void ParseAndPopulateOpenOrdersTable(QString Response); + void UpdaterFunction(); + void CreateOrderBookTables(QTableWidget& Table,QStringList TableHeader); + void CalculateBuyCostLabel(); + void CalculateSellCostLabel(); + void DisplayBalance(QLabel &BalanceLabel,QLabel &Available, QLabel &Pending, QString Currency,QString Response); + void ActionsOnSwitch(int index); + void CancelOrderSlot(int row, int col); + void on_UpdateKeys_clicked(); + void on_GenDepositBTN_clicked(); + void on_Buy_Max_Amount_clicked(); + void on_buyOrdertypeCombo_activated(const QString &arg1); + void on_BuyBidcomboBox_currentIndexChanged(const QString &arg1); + void on_UnitsInput_textChanged(const QString &arg1); + void on_BuyBidPriceEdit_textChanged(const QString &arg1); + void on_BuyMACRON_clicked(); + void on_SellMACRONBTN_clicked(); + void on_SellBidcomboBox_currentIndexChanged(const QString &arg1); + void on_Sell_Max_Amount_clicked(); + void on_UnitsInputMACRON_textChanged(const QString &arg1); + void on_SellBidPriceEdit_textChanged(const QString &arg1); + void on_AdvancedView_stateChanged(int arg1); + + int SetExchangeInfoTextLabels(); + + QString BittrexTimeStampToReadable(QString DateTime); + QString CancelOrder(QString Orderid); + QString BuyMACRON(QString OrderType, double Quantity, double Rate); + QString SellMACRON(QString OrderType, double Quantity, double Rate); + QString GetMarketHistory(); + QString GetMarketSummary(); + QString GetOrderBook(); + QString GetOpenOrders(); + QString GetAccountHistory(); + QString GetBalance(QString Currency); + QString GetDepositAddress(); + QString HMAC_SHA512_SIGNER(QString UrlToSign,QString Secretkey); + QString sendRequest(QString url); + QJsonObject GetResultObjectFromJSONObject(QString response); + QJsonObject GetResultObjectFromJSONArray(QString response); + QJsonArray GetResultArrayFromJSONObject(QString response); + +public Q_SLOTS: + + +private: + Ui::TradingDialogPage *ui; + //Socket *socket; + int timerid; + QTimer *timer; + QString ApiKey; + QString SecretKey; + + +}; + +#endif // TRADINGDIALOGPAGE_H diff --git a/src/qt/walletframe.cpp b/src/qt/walletframe.cpp index 6783019e..1389bb79 100644 --- a/src/qt/walletframe.cpp +++ b/src/qt/walletframe.cpp @@ -108,6 +108,22 @@ void WalletFrame::showOutOfSyncWarning(bool fShow) i.value()->showOutOfSyncWarning(fShow); } +void WalletFrame::gotoChatWindowPage() +{ + + QMap::const_iterator i; + for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) + i.value()->gotoChatWindowPage(); +} + +/*void WalletFrame::gotoTradingDialogPage() +{ + + QMap::const_iterator i; + for (i = mapWalletViews.constBegin(); i != mapWalletViews.constEnd(); ++i) + i.value()->gotoTradingDialogPage(); +} */ + void WalletFrame::gotoGovernancePage() { QMap::const_iterator i; diff --git a/src/qt/walletframe.h b/src/qt/walletframe.h index 54527997..866caea5 100644 --- a/src/qt/walletframe.h +++ b/src/qt/walletframe.h @@ -63,6 +63,10 @@ class WalletFrame : public QFrame public Q_SLOTS: + /** Switch to chat page */ + void gotoChatWindowPage(); + /** Switch to trading page */ + /* void gotoTradingDialogPage(); */ /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */ diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index f503bccd..fb6e2527 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -84,14 +84,21 @@ WalletView::WalletView(const PlatformStyle *_platformStyle, QWidget *parent): addWidget(receiveCoinsPage); addWidget(sendCoinsPage); addWidget(privateSendPage); + + /* tradingDialogPage = new TradingDialogPage(); + addWidget(tradingDialogPage); */ + + chatWindowPage = new ChatWindowPage(); + addWidget(chatWindowPage); QSettings settings; if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage = new MasternodeList(platformStyle); addWidget(masternodeListPage); } - governanceListPage = new GovernanceList(platformStyle); + governanceListPage = new GovernanceList(platformStyle); addWidget(governanceListPage); + // Clicking on a transaction on the overview pre-selects the transaction on the transaction history page connect(overviewPage, SIGNAL(transactionClicked(QModelIndex)), transactionView, SLOT(focusTransaction(QModelIndex))); @@ -158,6 +165,7 @@ void WalletView::setClientModel(ClientModel *_clientModel) masternodeListPage->setClientModel(_clientModel); } governanceListPage->setClientModel(_clientModel); + } void WalletView::setWalletModel(WalletModel *_walletModel) @@ -172,6 +180,7 @@ void WalletView::setWalletModel(WalletModel *_walletModel) if (!fLiteMode && settings.value("fShowMasternodesTab").toBool()) { masternodeListPage->setWalletModel(_walletModel); } + governanceListPage->setWalletModel(_walletModel); receiveCoinsPage->setModel(_walletModel); sendCoinsPage->setModel(_walletModel); @@ -232,6 +241,16 @@ void WalletView::processNewTransaction(const QModelIndex& parent, int start, int Q_EMIT incomingTransaction(date, walletModel->getOptionsModel()->getDisplayUnit(), amount, type, address, label); } +void WalletView::gotoChatWindowPage() +{ + setCurrentWidget(chatWindowPage); +} + +/*void WalletView::gotoTradingDialogPage() +{ + setCurrentWidget(tradingDialogPage); +} */ + void WalletView::gotoGovernancePage() { QSettings settings; diff --git a/src/qt/walletview.h b/src/qt/walletview.h index 8ed2b8eb..d1fc4313 100644 --- a/src/qt/walletview.h +++ b/src/qt/walletview.h @@ -8,6 +8,8 @@ #include "amount.h" #include "masternodelist.h" #include "governancelist.h" +/* #include "tradingdialogpage.h" */ +#include "chatwindowpage.h" #include @@ -24,6 +26,8 @@ class WalletModel; class AddressBookPage; class PrivateSendPage; class GovernancePage; +/* class TradingDialogPage; */ +class ChatWindowPage; QT_BEGIN_NAMESPACE @@ -74,6 +78,8 @@ class WalletView : public QStackedWidget PrivateSendPage *privateSendPage; GovernanceList *governanceListPage; TransactionView *transactionView; + /* TradingDialogPage *tradingDialogPage; */ + ChatWindowPage *chatWindowPage; QProgressDialog *progressDialog; QLabel *transactionSum; @@ -81,6 +87,10 @@ class WalletView : public QStackedWidget public Q_SLOTS: + /** Switch to chat page */ + void gotoChatWindowPage(); + /** Switch to trading page */ + /* void gotoTradingDialogPage(); */ /** Switch to governance page */ void gotoGovernancePage(); /** Switch to private send page */