Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/acquisition.pro b/acquisition.pro
- index 4d56a42..523fd15 100644
- --- a/acquisition.pro
- +++ b/acquisition.pro
- @@ -4,7 +4,7 @@ win32 {
- QT += winextras
- }
- TARGET = acquisition
- TEMPLATE = app
- @@ -51,7 +51,8 @@ SOURCES += \
- test/testdata.cpp \
- test/testitem.cpp \
- test/testshop.cpp \
- - test/testutil.cpp
- + test/testutil.cpp \
- + src/currencymanager.cpp
- HEADERS += \
- src/item.h \
- @@ -89,7 +90,8 @@ HEADERS += \
- test/testdata.h \
- test/testitem.h \
- test/testshop.h \
- - test/testutil.h
- + test/testutil.h \
- + src/currencymanager.h
- FORMS += \
- forms/mainwindow.ui \
- diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
- index af29c86..b636a7a 100644
- --- a/forms/mainwindow.ui
- +++ b/forms/mainwindow.ui
- @@ -138,7 +138,7 @@
- <x>0</x>
- <y>0</y>
- <width>867</width>
- - <height>21</height>
- + <height>27</height>
- </rect>
- </property>
- <widget class="QMenu" name="menuShop">
- @@ -165,10 +165,19 @@
- </property>
- <addaction name="actionControl_poe_xyz_is_URL"/>
- <addaction name="actionAutomatically_refresh_online_status"/>
- + <addaction name="actionExilebro_com_account_key"/>
- + </widget>
- + <widget class="QMenu" name="menuCurrency">
- + <property name="title">
- + <string>Currency</string>
- + </property>
- + <addaction name="actionList_currency"/>
- + <addaction name="actionGraph_currency"/>
- </widget>
- <addaction name="menuItems"/>
- <addaction name="menuShop"/>
- <addaction name="menuAuto_online"/>
- + <addaction name="menuCurrency"/>
- </widget>
- <widget class="QStatusBar" name="statusBar"/>
- <action name="actionForum_shop_thread">
- @@ -236,6 +245,21 @@
- <string>Automatically refresh online status</string>
- </property>
- </action>
- + <action name="actionExilebro_com_account_key">
- + <property name="text">
- + <string>exilebro.com account key ...</string>
- + </property>
- + </action>
- + <action name="actionList_currency">
- + <property name="text">
- + <string>List currency</string>
- + </property>
- + </action>
- + <action name="actionGraph_currency">
- + <property name="text">
- + <string>Graph currency</string>
- + </property>
- + </action>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <resources/>
- diff --git a/src/application.cpp b/src/application.cpp
- index 0f0f1da..1ed45cc 100644
- --- a/src/application.cpp
- +++ b/src/application.cpp
- @@ -24,6 +24,7 @@
- #include "buyoutmanager.h"
- #include "datamanager.h"
- #include "itemsmanager.h"
- +#include "currencymanager.h"
- #include "porting.h"
- #include "shop.h"
- @@ -45,6 +46,7 @@ void Application::InitLogin(std::unique_ptr<QNetworkAccessManager> login_manager
- buyout_manager_ = std::make_unique<BuyoutManager>(*data_manager_);
- shop_ = std::make_unique<Shop>(*this);
- items_manager_ = std::make_unique<ItemsManager>(*this);
- + currency_manager_ = std::make_unique<CurrencyManager>(*this, *data_manager_);
- connect(items_manager_.get(), SIGNAL(ItemsRefreshed(Items, std::vector<std::string>)),
- this, SLOT(OnItemsRefreshed(Items, std::vector<std::string>)));
- @@ -56,4 +58,5 @@ void Application::OnItemsRefreshed(const Items &items, const std::vector<std::st
- items_ = items;
- tabs_ = tabs;
- shop_->Update();
- + currency_manager_->Update();
- }
- diff --git a/src/application.h b/src/application.h
- index 79ea2a8..155a0f2 100644
- --- a/src/application.h
- +++ b/src/application.h
- @@ -29,6 +29,7 @@ class QNetworkReply;
- class DataManager;
- class ItemsManager;
- class BuyoutManager;
- +class CurrencyManager;
- class Shop;
- class Application : QObject {
- @@ -47,6 +48,7 @@ public:
- DataManager &data_manager() const { return *data_manager_; }
- DataManager &sensitive_data_manager() const { return *sensitive_data_manager_; }
- BuyoutManager &buyout_manager() const { return *buyout_manager_; }
- + CurrencyManager ¤cy_manager() { return *currency_manager_;}
- QNetworkAccessManager &logged_in_nm() const { return *logged_in_nm_; }
- const std::vector<std::string> &tabs() const { return tabs_; }
- Shop &shop() const { return *shop_; }
- @@ -64,4 +66,5 @@ private:
- std::unique_ptr<Shop> shop_;
- std::unique_ptr<QNetworkAccessManager> logged_in_nm_;
- std::unique_ptr<ItemsManager> items_manager_;
- -};
- \ No newline at end of file
- + std::unique_ptr<CurrencyManager> currency_manager_;
- +};
- diff --git a/src/autoonline.cpp b/src/autoonline.cpp
- index f91337a..b7fe120 100644
- --- a/src/autoonline.cpp
- +++ b/src/autoonline.cpp
- @@ -39,6 +39,7 @@ AutoOnline::AutoOnline(DataManager &data, DataManager &sensitive_data):
- sensitive_data_(sensitive_data),
- enabled_(data_.GetBool("online_enabled")),
- url_(sensitive_data_.Get("online_url")),
- + key_exile_(sensitive_data.Get("online_key_exile")),
- previous_status_(true) // set to true to force first refresh
- {
- timer_.setInterval(kOnlineCheckInterval);
- @@ -95,14 +96,27 @@ void AutoOnline::Check() {
- bool running = IsPoeRunning();
- std::string url = url_;
- - if (!running)
- + std::string key_exile = key_exile_;
- + if (!running) {
- url += "/offline";
- + key_exile += "2";
- + }
- + else {
- + key_exile += "1";
- + }
- if (running || previous_status_) {
- QNetworkRequest request(QUrl(url.c_str()));
- QByteArray data;
- request.setHeader(QNetworkRequest::UserAgentHeader, (std::string("Acquisition ") + VERSION_NAME).c_str());
- nm_.post(request, data);
- + if(IsKeyExileSet()){
- + QNetworkRequest request_exile(QUrl(key_exile.c_str()));
- + QByteArray data_exile;
- + //Don't ask why, exilebro want a special useragent
- + request_exile.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0");
- + nm_.post(request_exile, data_exile);
- + }
- }
- previous_status_ = running;
- @@ -111,7 +125,7 @@ void AutoOnline::Check() {
- }
- const std::string url_valid_prefix = "http://control.poe.xyz.is/";
- -
- +const std::string url_exile_valid_prefix = "http://exilebro.com/common/actions/online_client.php?code=";
- void AutoOnline::SetUrl(const std::string &url) {
- if (url.compare(0, url_valid_prefix.size(), url_valid_prefix))
- QLOG_WARN() << "Online URL is probably invalid.";
- @@ -122,6 +136,13 @@ void AutoOnline::SetUrl(const std::string &url) {
- sensitive_data_.Set("online_url", url);
- }
- +void AutoOnline::SetKeyExile(const std::string &key) {
- + std::string key_exile = url_exile_valid_prefix + key + "&status=";
- + key_exile_= key_exile;
- + while (key_exile_.size() > 0 && key_exile_[key_exile_.size() - 1] == ' ')
- + key_exile_.erase(key_exile_.size() - 1);
- + sensitive_data_.Set("online_key_exile", key_exile_);
- +}
- void AutoOnline::SetEnabled(bool enabled) {
- enabled_ = enabled;
- if (enabled)
- diff --git a/src/autoonline.h b/src/autoonline.h
- index c617342..41503ed 100644
- --- a/src/autoonline.h
- +++ b/src/autoonline.h
- @@ -30,9 +30,11 @@ class AutoOnline : public QObject {
- public:
- AutoOnline(DataManager &data, DataManager &sensitive_data);
- void SetUrl(const std::string &url);
- + void SetKeyExile(const std::string &key);
- void SetEnabled(bool enabled);
- bool enabled() { return enabled_; }
- bool IsUrlSet() { return !url_.empty(); }
- + bool IsKeyExileSet() { return !key_exile_.empty(); }
- public slots:
- void Check();
- signals:
- @@ -42,7 +44,8 @@ private:
- DataManager &sensitive_data_;
- QTimer timer_;
- std::string url_;
- + std::string key_exile_;
- bool enabled_;
- bool previous_status_;
- QNetworkAccessManager nm_;
- -};
- \ No newline at end of file
- +};
- diff --git a/src/currencymanager.cpp b/src/currencymanager.cpp
- index c7ac42c..59f26dd 100644
- --- a/src/currencymanager.cpp
- +++ b/src/currencymanager.cpp
- @@ -1,19 +1,161 @@
- /*
- + Copyright 2015 Ilya Zhuravlev
- + This file is part of Acquisition.
- + Acquisition is free software: you can redistribute it and/or modify
- + it under the terms of the GNU General Public License as published by
- + the Free Software Foundation, either version 3 of the License, or
- + (at your option) any later version.
- + Acquisition 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 General Public License for more details.
- +
- + You should have received a copy of the GNU General Public License
- + along with Acquisition. If not, see <http://www.gnu.org/licenses/>.
- */
- +#include <QNetworkReply>
- +#include <QSignalMapper>
- +#include <QTimer>
- +#include <QUrlQuery>
- +#include <QTimer>
- +#include <QThread>
- +#include <iostream>
- +#include <stdexcept>
- +#include <ctime>
- +#include "QsLog.h"
- +#include <QTextStream>
- +#include <QFile>
- +#include "application.h"
- +#include "datamanager.h"
- +#include "currencymanager.h"
- +#include "shop.h"
- +#include "util.h"
- +#include <QMessageBox>
- +QDebug operator<< (QDebug d, const CurrencyItem &item)
- +{
- + d << "{" ;
- + d << " \n name => [" << item.name
- + << "\n exalt value => [" << item.exalt
- + << "]\n count => [" << item.count;
- + d << "]\n}";
- + return d;
- +}
- +CurrencyManager::CurrencyManager(Application &app, DataManager &data) : app_(app), data_(data)
- +{
- + resetCurrency();
- +}
- +
- +CurrencyManager::~CurrencyManager()
- +{
- +
- +}
- +
- +void CurrencyManager::resetCurrency() {
- + QList<CurrencyItem> currencys;
- + for(unsigned int i=1;i<CurrencyAsString.size();i++)
- + {
- + CurrencyItem curr;
- + curr.count=0;
- + curr.name=CurrencyAsString[i].c_str();
- + currencys<<curr;
- + }
- + currencys_=currencys;
- +}
- +
- +void CurrencyManager::updateExaltedValue() {
- + for(int i=0;i<currencys_.size();i++){
- + currencys_[i].exalt=currencys_[i].count/CurrencyExaltedValue[i+1];
- + }
- +}
- +
- +double CurrencyManager::exaltedValue() {
- + updateExaltedValue();
- + double output=0;
- + for (int i=0;i<currencys_.size();i++)
- + {
- + output+=currencys_[i].exalt;
- + }
- + return output;
- +
- +}
- +//Save AltNumb,FusNumb,...,DivineNumb,TotalExaltedValue
- +void CurrencyManager::saveCurrency() {
- + std::string output;
- + std::time_t timestamp=std::time(nullptr);
- + for (int i=0;i<currencys_.size();i++){
- + output+=std::to_string(currencys_[i].count) + ',';
- + }
- + std::string tmpEx=std::to_string(exaltedValue());
- + std::replace(tmpEx.begin(), tmpEx.end(), ',', '.');
- + output+=tmpEx;
- + QString tmp=data_.Get("currency_timestamp_list").c_str();
- + QStringList timestampList=tmp.split(',');
- + std::string previousValue=data_.Get("currency_"+timestampList[timestampList.size()-1].toStdString());
- + if(output==previousValue)
- + {
- + return;
- + }
- + timestampList << QString::number(timestamp);
- + std::string key="currency_"+std::to_string(timestamp);
- + data_.Set(key,output);
- + data_.Set("currency_timestamp_list", timestampList.join(',').toStdString());
- +}
- +
- +void CurrencyManager::exportCurrency() {
- + QString csv_output;
- + QString tmp=data_.Get("currency_timestamp_list").c_str();
- + for(int i=0;i<currencys_.size();i++)
- + {
- + csv_output+=currencys_[i].name + ',';
- + }
- + csv_output+="Total value,Timestamp\n";
- + QStringList timestampList=tmp.split(',');
- + for (int i=1;i<timestampList.size();i++)
- + {
- + std::string key="currency_" + timestampList[i].toStdString();
- + std::string result=data_.Get(key);
- + csv_output+=result.c_str();
- + csv_output+=',' + timestampList[i] + '\n';
- + }
- + qDebug() << timestampList << csv_output;
- + QFile file("export_currency.csv");
- + if (file.open(QFile::WriteOnly | QFile::Truncate)) {
- + QTextStream out(&file);
- + out << csv_output;
- + }
- +
- +}
- +void CurrencyManager::displayCurrency() {
- + QString output="";
- + for(int i=0;i<currencys_.size();i++)
- + {
- + //22 is chisel length
- + QString name=currencys_[i].name + QString(" ").repeated(25-currencys_[i].name.size());
- + output+=name + " : " + QString::number(currencys_[i].count) + "(" + QString::number(currencys_[i].exalt) + ")";
- + output+="\n";
- + }
- + output+="Total value in exalt : ";
- + output+= QString::number(exaltedValue());
- +
- + QMessageBox::information(this, "List of currency", output);
- +}
- +
- +void CurrencyManager::Update() {
- + resetCurrency();
- + for (auto &item : app_.items()) {
- + for(int i=0;i<currencys_.size();i++){
- + if(item->PrettyName().c_str()==currencys_[i].name) {
- + currencys_[i].count+=item->count();
- + break;
- + }
- + }
- + }
- + updateExaltedValue();
- + saveCurrency();
- + exportCurrency();
- +}
- diff --git a/src/currencymanager.h b/src/currencymanager.h
- index f0442c1..a1bdee0 100644
- --- a/src/currencymanager.h
- +++ b/src/currencymanager.h
- @@ -1,22 +1,76 @@
- /*
- + Copyright 2014 Ilya Zhuravlev
- + This file is part of Acquisition.
- + Acquisition is free software: you can redistribute it and/or modify
- + it under the terms of the GNU General Public License as published by
- + the Free Software Foundation, either version 3 of the License, or
- + (at your option) any later version.
- + Acquisition 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 General Public License for more details.
- +
- + You should have received a copy of the GNU General Public License
- + along with Acquisition. If not, see <http://www.gnu.org/licenses/>.
- */
- +#pragma once
- +
- +#include <QTimer>
- +#include <memory>
- +#include <QWidget>
- +#include "item.h"
- +#include "itemsmanagerworker.h"
- +#include "buyoutmanager.h"
- +class QThread;
- +class Application;
- +class DataManager;
- +class ItemsManagerWorker;
- +struct ItemsFetchStatus;
- +class Shop;
- +struct CurrencyItem {
- + int count;
- + QString name;
- + double exalt;
- +};
- +const QList<double> CurrencyExaltedValue({
- + 0,
- + 300,
- + 42,
- + 90,
- + 35,
- + 10,
- + 1,
- + 220,
- + 160,
- + 110,
- + 85,
- + 30,
- + 39,
- + 15,
- + 22,
- + 1.56
- +});
- +
- +class CurrencyManager : public QWidget {
- + Q_OBJECT
- +public:
- + explicit CurrencyManager(Application &app, DataManager &data);
- + ~CurrencyManager();
- + void Update();
- + void resetCurrency();
- + void updateExaltedValue();
- + void saveCurrency();
- + void exportCurrency();
- + double exaltedValue();
- + void displayCurrency();
- +private:
- + Application &app_;
- + DataManager &data_;
- + QList<CurrencyItem> currencys_;
- +};
- +QDebug operator<< (QDebug d, const CurrencyItem &item);
- diff --git a/src/item.h b/src/item.h
- index 58a45ec..e0b4bb1 100644
- --- a/src/item.h
- +++ b/src/item.h
- @@ -81,7 +81,7 @@ public:
- const ItemSocketGroup &sockets() const { return sockets_; }
- const std::vector<ItemSocketGroup> &socket_groups() const { return socket_groups_; }
- const ItemLocation &location() const { return location_; }
- - int count() const { return count_; };
- + int count() const { return count_; }
- bool has_mtx() const { return has_mtx_; }
- const ModTable &mod_table() const { return mod_table_; }
- diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
- index cfa894c..6cbfff3 100755
- --- a/src/mainwindow.cpp
- +++ b/src/mainwindow.cpp
- @@ -52,6 +52,7 @@
- #include "shop.h"
- #include "util.h"
- #include "verticalscrollarea.h"
- +#include "currencymanager.h"
- const std::string POE_WEBCDN = "http://webcdn.pathofexile.com";
- @@ -629,6 +630,10 @@ void MainWindow::UpdateOnlineGui() {
- if (auto_online_.IsUrlSet())
- action_label += " [******]";
- ui->actionControl_poe_xyz_is_URL->setText(action_label.c_str());
- + std::string action_label_exile = "exilebro.com account key ...";
- + if (auto_online_.IsKeyExileSet())
- + action_label_exile += " [******]";
- + ui->actionExilebro_com_account_key->setText(action_label_exile.c_str());
- }
- void MainWindow::OnUpdateAvailable() {
- @@ -690,6 +695,18 @@ void MainWindow::on_actionControl_poe_xyz_is_URL_triggered() {
- auto_online_.SetUrl(url.toStdString());
- UpdateOnlineGui();
- }
- +void MainWindow::on_actionList_currency_triggered() {
- + app_->currency_manager().displayCurrency();
- +}
- +
- +void MainWindow::on_actionExilebro_com_account_key_triggered() {
- + bool ok;
- + QString key = QInputDialog::getText(this, "exilebro.com account key",
- + "Copy and paste your exilebro.com account key here", QLineEdit::Normal, "", &ok);
- + if (ok && !key.isEmpty())
- + auto_online_.SetKeyExile(key.toStdString());
- + UpdateOnlineGui();
- +}
- void MainWindow::on_actionAutomatically_refresh_online_status_triggered() {
- auto_online_.SetEnabled(ui->actionAutomatically_refresh_online_status->isChecked());
- diff --git a/src/mainwindow.h b/src/mainwindow.h
- index fe9accf..cca0e42 100755
- --- a/src/mainwindow.h
- +++ b/src/mainwindow.h
- @@ -88,7 +88,9 @@ private slots:
- void on_actionShop_template_triggered();
- void on_actionAutomatically_update_shop_triggered();
- void on_actionControl_poe_xyz_is_URL_triggered();
- + void on_actionExilebro_com_account_key_triggered();
- void on_actionAutomatically_refresh_online_status_triggered();
- + void on_actionList_currency_triggered();
- private:
- void UpdateCurrentBucket();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement