-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsettingsdialog.cpp
202 lines (184 loc) · 8.5 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "settingsdialog.h"
#include "mainwindow.h"
#include "ui_settingsdialog.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QtCore>
#include <QDate>
//#include </usr/local/include/QtSpell-qt5/QtSpell.hpp>
#include "string.h"
#include <QKeyEvent>
#include <QUrl>
#include <QtWidgets>
bool timeractive;
int timerinteval;
settingsDialog::settingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::settingsDialog)
{
ui->setupUi(this);
int index=0;
QStringList blacklist,cryptolist,profilelist;
QStringList exchanges={"Binance","Bittrex","Kraken","FTX","Kucoin"}, maincoins={"BTC","ETH","USDT"};
ui->exchanges->clear();
ui->exchanges->addItems(exchanges);
ui->maincoins->clear();
cryptolist = loadsettings("cryptolist").toStringList();
if (cryptolist.isEmpty()) cryptolist = maincoins;
else ui->maincoins->addItems(cryptolist);
//qDebug() << ui->exchanges->currentText();
ui->exchanges->setCurrentText(exchange);
QString crypt = loadsettings(ui->exchanges->currentText()+"_stake").toString();
ui->stake_coin->setText(crypt+" Price usd");
ui->message->setText("If you find this program useful please donate");
blacklist = loadsettings(exchange.toLower()+"_blacklist").toStringList();
for(auto & a : blacklist) ui->blacklist->append(a);
for(auto & a : cryptolist) {
ui->maincoinslist->append(a);
if (a==crypt) ui->maincoins->setCurrentIndex(index);
index++;
}
ui->maincoins->setCurrentText(loadsettings(exchange.toLower()+"_stake").toString());
bool report=loadsettings("report").toBool();
ui->reports->setChecked(report);
QString json_path = loadsettings("json_path").toString();
ui->jsonpathstring->setText(json_path);
QString cryptolistwrite = loadsettings("cryptolistwrite").toString();
ui->cryptolistwrite->setText(cryptolistwrite);
QString cryptolistread = loadsettings("cryptolistread").toString();
ui->cryptolistread->setText(cryptolistread);
QString reportPath = loadsettings("reportpath").toString();
ui->reportPath->setText(reportPath);
double btc_price = loadsettings(exchange.toLower()+"_stake_coin_price").toDouble();
if (crypt.contains("USD")) btc_price=1;
ui->stake_coin_price->setValue(btc_price);
QString apikey = loadsettings("apikey").toString();
ui->apikey->setText(apikey);
bool autoupdatejson=loadsettings("autoupdatejson").toBool();
timeractive=autoupdatejson;
ui->cryptoInvestFile->setText(loadsettings("cryptoInvestFile").toString());
ui->balance->setValue(loadsettings("balance").toInt());
ui->autoupdatejson->setChecked(autoupdatejson);
int tableage = loadsettings("tableage").toInt();
if (tableage == 0) {
ui->tableage->setValue(999);
tableage = 999;
} else ui->tableage->setValue(tableage);
int autojsonmin = loadsettings("autojsonmin").toInt();
int mSecDelay = loadsettings("mSecDelay").toInt();
if (mSecDelay==0) ui->mSecDelay->setValue(20);
else ui->mSecDelay->setValue(mSecDelay);
ui->autojsonmin->setValue(autojsonmin);
if (autojsonmin == 0) {
ui->autojsonmin->setValue(240);
autojsonmin = 240;
} else ui->autojsonmin->setValue(autojsonmin);
timerinteval=autojsonmin;
int rowsintable = loadsettings("rowsintable").toInt();
ui->rowsintable->setValue(rowsintable);
if (rowsintable == 0) {
ui->rowsintable->setValue(500);
rowsintable = 500;
} else ui->rowsintable->setValue(rowsintable);
//int updateinterval=loadsettings("updateinterval").toInt();
//ui->updateinterval->setValue(updateinterval);
}
settingsDialog::~settingsDialog()
{
delete ui;
}
QVariant settingsDialog::loadsettings(QString settings)
{
QVariant returnvar;
QSettings appsettings("QTinman",appgroup);
appsettings.beginGroup(appgroup);
returnvar = appsettings.value(settings);
appsettings.endGroup();
return returnvar;
}
void settingsDialog::savesettings(QString settings, QVariant attr)
{
QSettings appsettings("QTinman",appgroup);
appsettings.beginGroup(appgroup);
appsettings.setValue(settings,QVariant::fromValue(attr));
appsettings.endGroup();
}
void settingsDialog::on_selectJsonFile_clicked()
{
QString json_path = QFileDialog::getExistingDirectory(this,"Select Json file from CoinMarkedCap",".");
ui->jsonpathstring->setText(json_path);
}
void settingsDialog::on_toolcryptolistwrite_clicked()
{
QString cryptolistpath = QFileDialog::getExistingDirectory(this,"Select outfile where pairs are stored",".");
ui->cryptolistwrite->setText(cryptolistpath);
}
void settingsDialog::on_toolcryptolistread_clicked()
{
QString cryptolistpath = QFileDialog::getExistingDirectory(this,"Select infile a list of pairs from exhange",".");
ui->cryptolistread->setText(cryptolistpath);
}
void settingsDialog::on_toolReportPath_clicked()
{
QString reportpath = QFileDialog::getExistingDirectory(this,"Select reports path",".");
ui->reportPath->setText(reportpath);
}
void settingsDialog::on_exchanges_activated()
{
QStringList blacklist;
//MainWindow main;
blacklist = loadsettings(ui->exchanges->currentText().toLower()+"_blacklist").toStringList();
ui->blacklist->clear();
for(auto & a : blacklist) ui->blacklist->append(a);
ui->maincoins->setCurrentText(loadsettings(ui->exchanges->currentText().toLower()+"_stake").toString());
}
void settingsDialog::on_pushButton_clicked()
{
QMessageBox msgBox;
QClipboard *clipboard=0;
msgBox.setWindowTitle("Donate!");
msgBox.setText("If you find this program useful please donate to.\nBTC bc1qmeetnrmdfu2czp43ggq4v56wrxtk7cfahyr2m9\nDOT 12XHN5kYhSfCUdwiEAKMkW87L2kKV2AjerLMQukHJ4CnmKbL\nXRP rGzJmHraBUCWpncm3DGdscmAsuy3rDin4R\nADA addr1q9h424fgyqw3y0zer34myqn9lyr303nxcyvzttk8nyqmr7r0242jsgqazg79j8rtkgpxt7g8zlrxdsgcykhv0xgpk8uqh49hnw\nVET 0x136349A99A5a56617e7E7AdbE8c55a0712B0068F\nSupport is most appreciated.");
QAbstractButton* pButtonYes = msgBox.addButton(tr("Copy to clipboard"), QMessageBox::YesRole);
msgBox.exec();
if (msgBox.clickedButton()==pButtonYes) {
clipboard->setText("BTC bc1qmeetnrmdfu2czp43ggq4v56wrxtk7cfahyr2m9\nDOT 12XHN5kYhSfCUdwiEAKMkW87L2kKV2AjerLMQukHJ4CnmKbL\nXRP rGzJmHraBUCWpncm3DGdscmAsuy3rDin4R\nADA addr1q9h424fgyqw3y0zer34myqn9lyr303nxcyvzttk8nyqmr7r0242jsgqazg79j8rtkgpxt7g8zlrxdsgcykhv0xgpk8uqh49hnw\nVET 0x136349A99A5a56617e7E7AdbE8c55a0712B0068F");
}
}
void settingsDialog::on_buttonBox_accepted()
{
QStringList profilelist,blacklist=ui->blacklist->toPlainText().split("\n"),cryptolist=ui->maincoinslist->toPlainText().split("\n");
QSettings appsettings("QTinman",appgroup);
appsettings.beginGroup(appgroup);
QString ex=ui->exchanges->currentText();
appsettings.setValue("cryptolist", QVariant::fromValue(cryptolist));
appsettings.setValue(ui->exchanges->currentText().toLower()+"_blacklist", QVariant::fromValue(blacklist));
appsettings.setValue(ui->exchanges->currentText().toLower()+"_stake", QVariant::fromValue(ui->maincoins->currentText()));
crypt = loadsettings(exchange.toLower()+"_stake").toString();
appsettings.endGroup();
savesettings("mSecDelay",ui->mSecDelay->value());
savesettings("json_path",ui->jsonpathstring->text());
savesettings("cryptolistread",ui->cryptolistread->text());
savesettings("cryptolistwrite",ui->cryptolistwrite->text());
savesettings("reportpath",ui->reportPath->text());
savesettings(ui->exchanges->currentText().toLower()+"_stake_coin_price",ui->stake_coin_price->value());
savesettings("report",ui->reports->isChecked());
savesettings("apikey",ui->apikey->text());
savesettings("autoupdatejson",ui->autoupdatejson->isChecked());
savesettings("autojsonmin",ui->autojsonmin->value());
savesettings("rowsintable",ui->rowsintable->value());
savesettings("cryptoInvestFile",ui->cryptoInvestFile->text());
savesettings("balance",ui->balance->value());
if ((ui->autoupdatejson->isChecked() && !timeractive) || (timerinteval != ui->autojsonmin->value() && ui->autoupdatejson->isChecked())) {
timer->setInterval(ui->autojsonmin->value()*60000);
//timer->stop();
//timer->start(ui->autojsonmin->value()*60000);
qDebug() << timer->remainingTime();
}
if (!ui->autoupdatejson->isChecked() && timeractive) timer->stop();
savesettings("tableage",ui->tableage->value());
}
void settingsDialog::on_cryptoInvestPath_clicked()
{
QString cryptoInvestPath = QFileDialog::getOpenFileName(this,"Select file exported by CoinBrowser",".");
ui->cryptoInvestFile->setText(cryptoInvestPath);
}