AllExchangesDialog::AllExchangesDialog() : QDialog() { startIndex=1; exchangeNum=-1; ui.setupUi(this); ui.okButton->setEnabled(false); setWindowFlags(Qt::WindowCloseButtonHint); setWindowTitle("Qt Bitcoin Trader v"+baseValues.appVerStr+" - "+julyTr("ALL_EXCHANGES","All Exchanges")); QSettings listSettings(":/Resources/Exchanges/List.ini",QSettings::IniFormat); QStringList exchangesList=listSettings.childGroups(); allExchangesModel=new AllExchangesModel; ui.exchangesTableView->setModel(allExchangesModel); for(int n=startIndex;n<exchangesList.count();n++) { QString currentName=listSettings.value(exchangesList.at(n)+"/Name").toString(); if(currentName.isEmpty())continue; allExchangesModel->addExchange(n, currentName, loadCurrencies(currentName)); } mainWindow.setColumnResizeMode(ui.exchangesTableView,0,QHeaderView::ResizeToContents); mainWindow.setColumnResizeMode(ui.exchangesTableView,1,QHeaderView::Stretch); connect(ui.exchangesTableView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),this,SLOT(selectionExchange())); julyTranslator.translateUi(this); mainWindow.fixTableViews(this); }
CurrencyModel::CurrencyModel() : QAbstractListModel(0), fIndex(0), fTimer() { connect(&fNetManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(loadCurrenciesDone(QNetworkReply*))); loadCurrencies(); fTimer.setInterval(300 * 1000); // once per 5m, update currency prices connect(&fTimer, &QTimer::timeout, this, &CurrencyModel::loadCurrencies); fTimer.start(); }
FeaturedExchangesDialog::FeaturedExchangesDialog() : QDialog() { exchangeNum=-1; ui.setupUi(this); ui.okButton->setEnabled(false); setWindowFlags(Qt::WindowCloseButtonHint); setWindowTitle("Qt Bitcoin Trader v"+baseValues.appVerStr+" - "+julyTr("FEATURED_EXCHANGES","Featured Exchanges")); QSettings listSettings(":/Resources/Exchanges/List.ini",QSettings::IniFormat); allExchangesList=listSettings.childGroups(); { JulyHttp *httpGet=new JulyHttp("qbtapi.centrabit.com",0,this,true,false); connect(httpGet,SIGNAL(dataReceived(QByteArray,int)),this,SLOT(dataReceived(QByteArray,int))); httpGet->noReconnect=true; httpGet->sendData(145,"GET /?Object=General&Method=FeaturedExchanges"); QElapsedTimer elapsedRequest; elapsedRequest.restart(); int counter=0; while(cacheData.isEmpty()&&counter++<30&&elapsedRequest.elapsed()<3000) { QEventLoop loop; QTimer::singleShot(100,&loop,SLOT(quit())); loop.exec(); } delete httpGet; featuredExchangesList=QString(mainWindow.getMidData("Exchanges\":[","]",&cacheData)).split(","); cacheData.clear(); } for(int n=featuredExchangesList.count()-1;n>=0;n--) { if(featuredExchangesList.at(n).isEmpty())featuredExchangesList.removeAt(n); } if(featuredExchangesList.isEmpty()) { QSettings settings(appDataDir+"/QtBitcoinTrader.cfg",QSettings::IniFormat); featuredExchangesList=settings.value("LastFeaturedExchanges",featuredExchangesList).toStringList(); } else { QSettings settings(appDataDir+"/QtBitcoinTrader.cfg",QSettings::IniFormat); settings.setValue("LastFeaturedExchanges",featuredExchangesList); } for(int n=featuredExchangesList.count()-1;n>=0;n--) { if(featuredExchangesList.at(n).isEmpty())featuredExchangesList.removeAt(n); else if(featuredExchangesList.at(n).length()<2)featuredExchangesList[n].prepend("0"); } if(featuredExchangesList.count()==0) { exchangeNum=-2; return; } removeNotValidExchanges(); quint32 countCol=3; if(featuredExchangesList.count()<=4)countCol=2; for(int i=0;i<featuredExchangesList.count();i++) { QString currentName=listSettings.value(featuredExchangesList.at(i)+"/Name").toString(); QString currentLogo=fixLogo(listSettings.value(featuredExchangesList.at(i)+"/Logo").toString()); QString currentURL =fixURL(listSettings.value(featuredExchangesList.at(i)+"/GetApiUrl").toString()); if(currentName.isEmpty()||currentLogo.isEmpty()||currentURL.isEmpty())continue; ExchangeButton *exchangeItem = new ExchangeButton(currentLogo,loadCurrencies(currentName),currentURL,featuredExchangesListIndex.at(i),this); if(countCol==3 && i==featuredExchangesList.count()-1 && (i-qFloor(i/countCol)*countCol)==0)i++; ui.gridLayoutExchange->addWidget(exchangeItem,qFloor(i/countCol),i-qFloor(i/countCol)*countCol,Qt::AlignCenter); } julyTranslator.translateUi(this); setFixedSize(minimumSizeHint()); }