Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 17.59 KB | None | 0 0
  1. diff --git a/acquisition.pro b/acquisition.pro
  2. index 4d56a42..523fd15 100644
  3. --- a/acquisition.pro
  4. +++ b/acquisition.pro
  5. @@ -4,7 +4,7 @@ win32 {
  6.      QT += winextras
  7.  }
  8.  
  9.  
  10.  TARGET = acquisition
  11.  TEMPLATE = app
  12. @@ -51,7 +51,8 @@ SOURCES += \
  13.      test/testdata.cpp \
  14.      test/testitem.cpp \
  15.      test/testshop.cpp \
  16. -    test/testutil.cpp
  17. +    test/testutil.cpp \
  18. +    src/currencymanager.cpp
  19.  
  20.  HEADERS += \
  21.      src/item.h \
  22. @@ -89,7 +90,8 @@ HEADERS += \
  23.      test/testdata.h \
  24.      test/testitem.h \
  25.      test/testshop.h \
  26. -    test/testutil.h
  27. +    test/testutil.h \
  28. +    src/currencymanager.h
  29.  
  30.  FORMS += \
  31.      forms/mainwindow.ui \
  32. diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
  33. index af29c86..b636a7a 100644
  34. --- a/forms/mainwindow.ui
  35. +++ b/forms/mainwindow.ui
  36. @@ -138,7 +138,7 @@
  37.       <x>0</x>
  38.       <y>0</y>
  39.       <width>867</width>
  40. -     <height>21</height>
  41. +     <height>27</height>
  42.      </rect>
  43.     </property>
  44.     <widget class="QMenu" name="menuShop">
  45. @@ -165,10 +165,19 @@
  46.      </property>
  47.      <addaction name="actionControl_poe_xyz_is_URL"/>
  48.      <addaction name="actionAutomatically_refresh_online_status"/>
  49. +    <addaction name="actionExilebro_com_account_key"/>
  50. +   </widget>
  51. +   <widget class="QMenu" name="menuCurrency">
  52. +    <property name="title">
  53. +     <string>Currency</string>
  54. +    </property>
  55. +    <addaction name="actionList_currency"/>
  56. +    <addaction name="actionGraph_currency"/>
  57.     </widget>
  58.     <addaction name="menuItems"/>
  59.     <addaction name="menuShop"/>
  60.     <addaction name="menuAuto_online"/>
  61. +   <addaction name="menuCurrency"/>
  62.    </widget>
  63.    <widget class="QStatusBar" name="statusBar"/>
  64.    <action name="actionForum_shop_thread">
  65. @@ -236,6 +245,21 @@
  66.      <string>Automatically refresh online status</string>
  67.     </property>
  68.    </action>
  69. +  <action name="actionExilebro_com_account_key">
  70. +   <property name="text">
  71. +    <string>exilebro.com account key ...</string>
  72. +   </property>
  73. +  </action>
  74. +  <action name="actionList_currency">
  75. +   <property name="text">
  76. +    <string>List currency</string>
  77. +   </property>
  78. +  </action>
  79. +  <action name="actionGraph_currency">
  80. +   <property name="text">
  81. +    <string>Graph currency</string>
  82. +   </property>
  83. +  </action>
  84.   </widget>
  85.   <layoutdefault spacing="6" margin="11"/>
  86.   <resources/>
  87. diff --git a/src/application.cpp b/src/application.cpp
  88. index 0f0f1da..1ed45cc 100644
  89. --- a/src/application.cpp
  90. +++ b/src/application.cpp
  91. @@ -24,6 +24,7 @@
  92.  #include "buyoutmanager.h"
  93.  #include "datamanager.h"
  94.  #include "itemsmanager.h"
  95. +#include "currencymanager.h"
  96.  #include "porting.h"
  97.  #include "shop.h"
  98.  
  99. @@ -45,6 +46,7 @@ void Application::InitLogin(std::unique_ptr<QNetworkAccessManager> login_manager
  100.      buyout_manager_ = std::make_unique<BuyoutManager>(*data_manager_);
  101.      shop_ = std::make_unique<Shop>(*this);
  102.      items_manager_ = std::make_unique<ItemsManager>(*this);
  103. +    currency_manager_ = std::make_unique<CurrencyManager>(*this, *data_manager_);
  104.      connect(items_manager_.get(), SIGNAL(ItemsRefreshed(Items, std::vector<std::string>)),
  105.          this, SLOT(OnItemsRefreshed(Items, std::vector<std::string>)));
  106.  
  107. @@ -56,4 +58,5 @@ void Application::OnItemsRefreshed(const Items &items, const std::vector<std::st
  108.      items_ = items;
  109.      tabs_ = tabs;
  110.      shop_->Update();
  111. +    currency_manager_->Update();
  112.  }
  113. diff --git a/src/application.h b/src/application.h
  114. index 79ea2a8..155a0f2 100644
  115. --- a/src/application.h
  116. +++ b/src/application.h
  117. @@ -29,6 +29,7 @@ class QNetworkReply;
  118.  class DataManager;
  119.  class ItemsManager;
  120.  class BuyoutManager;
  121. +class CurrencyManager;
  122.  class Shop;
  123.  
  124.  class Application : QObject {
  125. @@ -47,6 +48,7 @@ public:
  126.      DataManager &data_manager() const { return *data_manager_; }
  127.      DataManager &sensitive_data_manager() const { return *sensitive_data_manager_; }
  128.      BuyoutManager &buyout_manager() const { return *buyout_manager_; }
  129. +    CurrencyManager &currency_manager() { return *currency_manager_;}
  130.      QNetworkAccessManager &logged_in_nm() const { return *logged_in_nm_; }
  131.      const std::vector<std::string> &tabs() const { return tabs_; }
  132.      Shop &shop() const { return *shop_; }
  133. @@ -64,4 +66,5 @@ private:
  134.      std::unique_ptr<Shop> shop_;
  135.      std::unique_ptr<QNetworkAccessManager> logged_in_nm_;
  136.      std::unique_ptr<ItemsManager> items_manager_;
  137. -};
  138. \ No newline at end of file
  139. +    std::unique_ptr<CurrencyManager> currency_manager_;
  140. +};
  141. diff --git a/src/autoonline.cpp b/src/autoonline.cpp
  142. index f91337a..b7fe120 100644
  143. --- a/src/autoonline.cpp
  144. +++ b/src/autoonline.cpp
  145. @@ -39,6 +39,7 @@ AutoOnline::AutoOnline(DataManager &data, DataManager &sensitive_data):
  146.      sensitive_data_(sensitive_data),
  147.      enabled_(data_.GetBool("online_enabled")),
  148.      url_(sensitive_data_.Get("online_url")),
  149. +    key_exile_(sensitive_data.Get("online_key_exile")),
  150.      previous_status_(true)  // set to true to force first refresh
  151.  {
  152.      timer_.setInterval(kOnlineCheckInterval);
  153. @@ -95,14 +96,27 @@ void AutoOnline::Check() {
  154.      bool running = IsPoeRunning();
  155.  
  156.      std::string url = url_;
  157. -    if (!running)
  158. +    std::string key_exile = key_exile_;
  159. +    if (!running) {
  160.          url += "/offline";
  161. +        key_exile += "2";
  162. +    }
  163. +    else {
  164. +        key_exile += "1";
  165. +    }
  166.  
  167.      if (running || previous_status_) {
  168.          QNetworkRequest request(QUrl(url.c_str()));
  169.          QByteArray data;
  170.          request.setHeader(QNetworkRequest::UserAgentHeader, (std::string("Acquisition ") + VERSION_NAME).c_str());
  171.          nm_.post(request, data);
  172. +        if(IsKeyExileSet()){
  173. +            QNetworkRequest request_exile(QUrl(key_exile.c_str()));
  174. +            QByteArray data_exile;
  175. +            //Don't ask why, exilebro want a special useragent
  176. +            request_exile.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0");
  177. +            nm_.post(request_exile, data_exile);
  178. +        }
  179.      }
  180.  
  181.      previous_status_ = running;
  182. @@ -111,7 +125,7 @@ void AutoOnline::Check() {
  183.  }
  184.  
  185.  const std::string url_valid_prefix = "http://control.poe.xyz.is/";
  186. -
  187. +const std::string url_exile_valid_prefix = "http://exilebro.com/common/actions/online_client.php?code=";
  188.  void AutoOnline::SetUrl(const std::string &url) {
  189.      if (url.compare(0, url_valid_prefix.size(), url_valid_prefix))
  190.          QLOG_WARN() << "Online URL is probably invalid.";
  191. @@ -122,6 +136,13 @@ void AutoOnline::SetUrl(const std::string &url) {
  192.      sensitive_data_.Set("online_url", url);
  193.  }
  194.  
  195. +void AutoOnline::SetKeyExile(const std::string &key) {
  196. +    std::string key_exile = url_exile_valid_prefix + key + "&status=";
  197. +    key_exile_= key_exile;
  198. +    while (key_exile_.size() > 0 && key_exile_[key_exile_.size() - 1] == ' ')
  199. +        key_exile_.erase(key_exile_.size() - 1);
  200. +    sensitive_data_.Set("online_key_exile", key_exile_);
  201. +}
  202.  void AutoOnline::SetEnabled(bool enabled) {
  203.      enabled_ = enabled;
  204.      if (enabled)
  205. diff --git a/src/autoonline.h b/src/autoonline.h
  206. index c617342..41503ed 100644
  207. --- a/src/autoonline.h
  208. +++ b/src/autoonline.h
  209. @@ -30,9 +30,11 @@ class AutoOnline : public QObject {
  210.  public:
  211.      AutoOnline(DataManager &data, DataManager &sensitive_data);
  212.      void SetUrl(const std::string &url);
  213. +    void SetKeyExile(const std::string &key);
  214.      void SetEnabled(bool enabled);
  215.      bool enabled() { return enabled_; }
  216.      bool IsUrlSet() { return !url_.empty(); }
  217. +    bool IsKeyExileSet() { return !key_exile_.empty(); }
  218.  public slots:
  219.      void Check();
  220.  signals:
  221. @@ -42,7 +44,8 @@ private:
  222.      DataManager &sensitive_data_;
  223.      QTimer timer_;
  224.      std::string url_;
  225. +    std::string key_exile_;
  226.      bool enabled_;
  227.      bool previous_status_;
  228.      QNetworkAccessManager nm_;
  229. -};
  230. \ No newline at end of file
  231. +};
  232. diff --git a/src/currencymanager.cpp b/src/currencymanager.cpp
  233. index c7ac42c..59f26dd 100644
  234. --- a/src/currencymanager.cpp
  235. +++ b/src/currencymanager.cpp
  236. @@ -1,19 +1,161 @@
  237.  /*
  238. +    Copyright 2015 Ilya Zhuravlev
  239. +    This file is part of Acquisition.
  240. +    Acquisition is free software: you can redistribute it and/or modify
  241. +    it under the terms of the GNU General Public License as published by
  242. +    the Free Software Foundation, either version 3 of the License, or
  243. +    (at your option) any later version.
  244. +    Acquisition is distributed in the hope that it will be useful,
  245. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  246. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  247. +    GNU General Public License for more details.
  248. +
  249. +    You should have received a copy of the GNU General Public License
  250. +    along with Acquisition.  If not, see <http://www.gnu.org/licenses/>.
  251.  */
  252.  
  253. +#include <QNetworkReply>
  254. +#include <QSignalMapper>
  255. +#include <QTimer>
  256. +#include <QUrlQuery>
  257. +#include <QTimer>
  258. +#include <QThread>
  259. +#include <iostream>
  260. +#include <stdexcept>
  261. +#include <ctime>
  262. +#include "QsLog.h"
  263. +#include <QTextStream>
  264. +#include <QFile>
  265. +#include "application.h"
  266. +#include "datamanager.h"
  267. +#include "currencymanager.h"
  268. +#include "shop.h"
  269. +#include "util.h"
  270. +#include <QMessageBox>
  271. +QDebug operator<< (QDebug d, const CurrencyItem &item)
  272. +{
  273. +    d << "{" ;
  274. +    d << " \n name        => [" << item.name
  275. +      << "\n exalt value  => [" << item.exalt
  276. +      << "]\n count      => [" << item.count;
  277. +    d << "]\n}";
  278. +    return d;
  279. +}
  280. +CurrencyManager::CurrencyManager(Application &app, DataManager &data) : app_(app), data_(data)
  281. +{
  282. +    resetCurrency();
  283. +}
  284. +
  285. +CurrencyManager::~CurrencyManager()
  286. +{
  287. +
  288. +}
  289. +
  290. +void CurrencyManager::resetCurrency() {
  291. +    QList<CurrencyItem> currencys;
  292. +    for(unsigned int i=1;i<CurrencyAsString.size();i++)
  293. +    {
  294. +        CurrencyItem curr;
  295. +        curr.count=0;
  296. +        curr.name=CurrencyAsString[i].c_str();
  297. +        currencys<<curr;
  298. +    }
  299. +    currencys_=currencys;
  300. +}
  301. +
  302. +void CurrencyManager::updateExaltedValue() {
  303. +    for(int i=0;i<currencys_.size();i++){
  304. +        currencys_[i].exalt=currencys_[i].count/CurrencyExaltedValue[i+1];
  305. +    }
  306. +}
  307. +
  308. +double CurrencyManager::exaltedValue() {
  309. +    updateExaltedValue();
  310. +    double output=0;
  311. +    for (int i=0;i<currencys_.size();i++)
  312. +    {
  313. +        output+=currencys_[i].exalt;
  314. +    }
  315. +    return output;
  316. +
  317. +}
  318. +//Save AltNumb,FusNumb,...,DivineNumb,TotalExaltedValue
  319. +void CurrencyManager::saveCurrency() {
  320. +    std::string output;
  321. +    std::time_t timestamp=std::time(nullptr);
  322. +    for (int i=0;i<currencys_.size();i++){
  323. +        output+=std::to_string(currencys_[i].count) + ',';
  324. +    }
  325. +    std::string tmpEx=std::to_string(exaltedValue());
  326. +    std::replace(tmpEx.begin(), tmpEx.end(), ',', '.');
  327. +    output+=tmpEx;
  328. +    QString tmp=data_.Get("currency_timestamp_list").c_str();
  329. +    QStringList timestampList=tmp.split(',');
  330. +    std::string previousValue=data_.Get("currency_"+timestampList[timestampList.size()-1].toStdString());
  331. +    if(output==previousValue)
  332. +    {
  333. +        return;
  334. +    }
  335. +    timestampList << QString::number(timestamp);
  336. +    std::string key="currency_"+std::to_string(timestamp);
  337. +    data_.Set(key,output);
  338. +    data_.Set("currency_timestamp_list", timestampList.join(',').toStdString());
  339. +}
  340. +
  341. +void CurrencyManager::exportCurrency() {
  342. +    QString csv_output;
  343. +    QString tmp=data_.Get("currency_timestamp_list").c_str();
  344. +    for(int i=0;i<currencys_.size();i++)
  345. +    {
  346. +        csv_output+=currencys_[i].name + ',';
  347. +    }
  348. +    csv_output+="Total value,Timestamp\n";
  349. +    QStringList timestampList=tmp.split(',');
  350. +    for (int i=1;i<timestampList.size();i++)
  351. +    {
  352. +        std::string key="currency_" + timestampList[i].toStdString();
  353. +        std::string result=data_.Get(key);
  354. +        csv_output+=result.c_str();
  355. +        csv_output+=',' + timestampList[i] + '\n';
  356. +    }
  357. +    qDebug() << timestampList << csv_output;
  358. +    QFile file("export_currency.csv");
  359. +    if (file.open(QFile::WriteOnly | QFile::Truncate)) {
  360. +        QTextStream out(&file);
  361. +        out << csv_output;
  362. +    }
  363. +
  364. +}
  365. +void CurrencyManager::displayCurrency() {
  366. +    QString output="";
  367. +    for(int i=0;i<currencys_.size();i++)
  368. +    {
  369. +        //22 is chisel length
  370. +        QString name=currencys_[i].name + QString(" ").repeated(25-currencys_[i].name.size());
  371. +        output+=name + " : " + QString::number(currencys_[i].count) + "(" + QString::number(currencys_[i].exalt) + ")";
  372. +        output+="\n";
  373. +    }
  374. +    output+="Total value in exalt : ";
  375. +    output+= QString::number(exaltedValue());
  376. +
  377. +    QMessageBox::information(this, "List of currency", output);
  378. +}
  379. +
  380. +void CurrencyManager::Update() {
  381. +    resetCurrency();
  382. +    for (auto &item : app_.items()) {
  383. +        for(int i=0;i<currencys_.size();i++){
  384. +            if(item->PrettyName().c_str()==currencys_[i].name) {
  385. +                currencys_[i].count+=item->count();
  386. +                break;
  387. +            }
  388.  
  389. +        }
  390. +    }
  391. +    updateExaltedValue();
  392. +    saveCurrency();
  393. +    exportCurrency();
  394. +}
  395. diff --git a/src/currencymanager.h b/src/currencymanager.h
  396. index f0442c1..a1bdee0 100644
  397. --- a/src/currencymanager.h
  398. +++ b/src/currencymanager.h
  399. @@ -1,22 +1,76 @@
  400.  /*
  401. +    Copyright 2014 Ilya Zhuravlev
  402. +    This file is part of Acquisition.
  403. +    Acquisition is free software: you can redistribute it and/or modify
  404. +    it under the terms of the GNU General Public License as published by
  405. +    the Free Software Foundation, either version 3 of the License, or
  406. +    (at your option) any later version.
  407. +    Acquisition is distributed in the hope that it will be useful,
  408. +    but WITHOUT ANY WARRANTY; without even the implied warranty of
  409. +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  410. +    GNU General Public License for more details.
  411. +
  412. +    You should have received a copy of the GNU General Public License
  413. +    along with Acquisition.  If not, see <http://www.gnu.org/licenses/>.
  414.  */
  415.  
  416.  
  417.  
  418. +#pragma once
  419. +
  420. +#include <QTimer>
  421. +#include <memory>
  422. +#include <QWidget>
  423. +#include "item.h"
  424. +#include "itemsmanagerworker.h"
  425. +#include "buyoutmanager.h"
  426. +class QThread;
  427. +class Application;
  428. +class DataManager;
  429. +class ItemsManagerWorker;
  430. +struct ItemsFetchStatus;
  431. +class Shop;
  432. +struct CurrencyItem {
  433. +    int count;
  434. +    QString name;
  435. +    double exalt;
  436. +};
  437. +const QList<double> CurrencyExaltedValue({
  438. +     0,
  439. +     300,
  440. +     42,
  441. +     90,
  442. +     35,
  443. +     10,
  444. +     1,
  445. +     220,
  446. +     160,
  447. +     110,
  448. +     85,
  449. +     30,
  450. +     39,
  451. +     15,
  452. +     22,
  453. +     1.56
  454. +});
  455. +
  456.  
  457. +class CurrencyManager : public QWidget {
  458. +    Q_OBJECT
  459. +public:
  460. +    explicit CurrencyManager(Application &app, DataManager &data);
  461. +    ~CurrencyManager();
  462. +    void Update();
  463. +    void resetCurrency();
  464. +    void updateExaltedValue();
  465. +    void saveCurrency();
  466. +    void exportCurrency();
  467. +    double exaltedValue();
  468. +    void displayCurrency();
  469. +private:
  470. +    Application &app_;
  471. +    DataManager &data_;
  472. +    QList<CurrencyItem> currencys_;
  473. +};
  474. +QDebug operator<< (QDebug d, const CurrencyItem &item);
  475. diff --git a/src/item.h b/src/item.h
  476. index 58a45ec..e0b4bb1 100644
  477. --- a/src/item.h
  478. +++ b/src/item.h
  479. @@ -81,7 +81,7 @@ public:
  480.      const ItemSocketGroup &sockets() const { return sockets_; }
  481.      const std::vector<ItemSocketGroup> &socket_groups() const { return socket_groups_; }
  482.      const ItemLocation &location() const { return location_; }
  483. -    int count() const { return count_; };
  484. +    int count() const { return count_; }
  485.      bool has_mtx() const { return has_mtx_; }
  486.      const ModTable &mod_table() const { return mod_table_; }
  487.  
  488. diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
  489. index cfa894c..6cbfff3 100755
  490. --- a/src/mainwindow.cpp
  491. +++ b/src/mainwindow.cpp
  492. @@ -52,6 +52,7 @@
  493.  #include "shop.h"
  494.  #include "util.h"
  495.  #include "verticalscrollarea.h"
  496. +#include "currencymanager.h"
  497.  
  498.  const std::string POE_WEBCDN = "http://webcdn.pathofexile.com";
  499.  
  500. @@ -629,6 +630,10 @@ void MainWindow::UpdateOnlineGui() {
  501.      if (auto_online_.IsUrlSet())
  502.          action_label += " [******]";
  503.      ui->actionControl_poe_xyz_is_URL->setText(action_label.c_str());
  504. +    std::string action_label_exile = "exilebro.com account key ...";
  505. +    if (auto_online_.IsKeyExileSet())
  506. +        action_label_exile += " [******]";
  507. +    ui->actionExilebro_com_account_key->setText(action_label_exile.c_str());
  508.  }
  509.  
  510.  void MainWindow::OnUpdateAvailable() {
  511. @@ -690,6 +695,18 @@ void MainWindow::on_actionControl_poe_xyz_is_URL_triggered() {
  512.          auto_online_.SetUrl(url.toStdString());
  513.      UpdateOnlineGui();
  514.  }
  515. +void MainWindow::on_actionList_currency_triggered() {
  516. +    app_->currency_manager().displayCurrency();
  517. +}
  518. +
  519. +void MainWindow::on_actionExilebro_com_account_key_triggered() {
  520. +    bool ok;
  521. +    QString key = QInputDialog::getText(this, "exilebro.com account key",
  522. +     "Copy and paste your exilebro.com account key here", QLineEdit::Normal, "", &ok);
  523. +    if (ok && !key.isEmpty())
  524. +        auto_online_.SetKeyExile(key.toStdString());
  525. +    UpdateOnlineGui();
  526. +}
  527.  
  528.  void MainWindow::on_actionAutomatically_refresh_online_status_triggered() {
  529.      auto_online_.SetEnabled(ui->actionAutomatically_refresh_online_status->isChecked());
  530. diff --git a/src/mainwindow.h b/src/mainwindow.h
  531. index fe9accf..cca0e42 100755
  532. --- a/src/mainwindow.h
  533. +++ b/src/mainwindow.h
  534. @@ -88,7 +88,9 @@ private slots:
  535.      void on_actionShop_template_triggered();
  536.      void on_actionAutomatically_update_shop_triggered();
  537.      void on_actionControl_poe_xyz_is_URL_triggered();
  538. +    void on_actionExilebro_com_account_key_triggered();
  539.      void on_actionAutomatically_refresh_online_status_triggered();
  540. +    void on_actionList_currency_triggered();
  541.  
  542.  private:
  543.      void UpdateCurrentBucket();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement