From b9224cb9de71995b9f89787d47b98f9bbb188d58 Mon Sep 17 00:00:00 2001 From: daniel-Jones Date: Thu, 21 Jul 2016 19:10:18 +0930 Subject: first commit, basic program currently --- README.md | 1 + csgo_stats.pro | 25 ++++ csgo_stats.pro.user | 333 +++++++++++++++++++++++++++++++++++++++++++++++ file_download.cpp | 28 ++++ file_download.h | 19 +++ main.cpp | 11 ++ stats_display_window.cpp | 49 +++++++ stats_display_window.h | 45 +++++++ stats_display_window.ui | 53 ++++++++ user_select_dialog.cpp | 57 ++++++++ user_select_dialog.h | 30 +++++ user_select_dialog.ui | 72 ++++++++++ 12 files changed, 723 insertions(+) create mode 100644 README.md create mode 100644 csgo_stats.pro create mode 100644 csgo_stats.pro.user create mode 100644 file_download.cpp create mode 100644 file_download.h create mode 100644 main.cpp create mode 100644 stats_display_window.cpp create mode 100644 stats_display_window.h create mode 100644 stats_display_window.ui create mode 100644 user_select_dialog.cpp create mode 100644 user_select_dialog.h create mode 100644 user_select_dialog.ui diff --git a/README.md b/README.md new file mode 100644 index 0000000..449efa3 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# CS-GO-Qt-C-Statistics diff --git a/csgo_stats.pro b/csgo_stats.pro new file mode 100644 index 0000000..ef1f61c --- /dev/null +++ b/csgo_stats.pro @@ -0,0 +1,25 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-07-21T13:21:39 +# +#------------------------------------------------- + +QT += core gui network + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = csgo_stats +TEMPLATE = app + + +SOURCES += main.cpp\ + user_select_dialog.cpp \ + file_download.cpp \ + stats_display_window.cpp + +HEADERS += user_select_dialog.h \ + file_download.h \ + stats_display_window.h + +FORMS += user_select_dialog.ui \ + stats_display_window.ui diff --git a/csgo_stats.pro.user b/csgo_stats.pro.user new file mode 100644 index 0000000..5349ab4 --- /dev/null +++ b/csgo_stats.pro.user @@ -0,0 +1,333 @@ + + + + + + EnvironmentId + {c148e485-3cf0-4847-b5fd-56246b2688e8} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + {a6071b8b-a567-46c9-babb-33312c5773b5} + 0 + 0 + 0 + + /home/daniel_j/programming/c++/csgo_stats/build-csgo_stats-Desktop-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/daniel_j/programming/c++/csgo_stats/build-csgo_stats-Desktop-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/daniel_j/programming/c++/csgo_stats/build-csgo_stats-Desktop-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/file_download.cpp b/file_download.cpp new file mode 100644 index 0000000..c155f8b --- /dev/null +++ b/file_download.cpp @@ -0,0 +1,28 @@ +#include "file_download.h" + +file_download::file_download() +{ + +} + +int file_download::file_download::download_file(QString url, QString save_location) +{ + /* + * this function will download a given url/file to a location + * no file location will be interpreted as . (current directory) + */ + qDebug() << "downloading to " + save_location + " from " + url; + if (QFile::exists(save_location)) + QFile::remove(save_location); + QNetworkReply *reply = http.get(QNetworkRequest(url)); + QObject::connect(reply, SIGNAL(finished()),&loop, SLOT(quit())); + loop.exec(); + QFile file(save_location); + file.open(QIODevice::WriteOnly); + file.write(reply->readAll()); + delete reply; + if (QFile::exists(save_location) && file.size() > 0) + return 1; /* file downloaded - could just be a blank file at this point */ + else + return 0; /* file did not download */ +} diff --git a/file_download.h b/file_download.h new file mode 100644 index 0000000..f8e1a94 --- /dev/null +++ b/file_download.h @@ -0,0 +1,19 @@ +#ifndef FILE_DOWNLOAD_H +#define FILE_DOWNLOAD_H +#include +#include +#include +#include +#include + +class file_download +{ +public: + file_download(); + int download_file(QString url, QString save_location); +private: + QNetworkAccessManager http; + QEventLoop loop; +}; + +#endif // FILE_DOWNLOAD_H diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..dffe85e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "user_select_dialog.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + user_select_dialog w; + w.show(); + + return a.exec(); +} diff --git a/stats_display_window.cpp b/stats_display_window.cpp new file mode 100644 index 0000000..1dee284 --- /dev/null +++ b/stats_display_window.cpp @@ -0,0 +1,49 @@ +#include "stats_display_window.h" +#include "ui_stats_display_window.h" + +stats_display_window::stats_display_window(QWidget *parent) : + QWidget(parent), + ui(new Ui::stats_display_window) +{ + ui->setupUi(this); + connect(this, SIGNAL(window_loaded()), this, SLOT(test()), Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection)); +} + +stats_display_window::~stats_display_window() +{ + delete ui; +} + +void stats_display_window::showEvent(QShowEvent *ev) +{ + emit window_loaded(); +} + +void stats_display_window::test() +{ + QFile file("userdata.dat"); + if (file.open(QIODevice::ReadOnly)) + { + QTextStream in(&file); + while (!in.atEnd()) + { + QString line = in.readLine(); + if (line.contains("\"personaname\":")) + user.username = line.split(": ")[1].replace("\"", "").replace(",", ""); + if (line.contains("\"realname\":")) + user.realname = line.split(": ")[1].replace("\"", "").replace(",", ""); + if (line.contains("\"avatarfull\":")) + user.avatar_url = line.split(": ")[1].replace("\"", "").replace(",", ""); + } + file.close(); + } + download.download_file(user.avatar_url, "avatar.jpg"); + ui->username_label->setText(user.username); + if (user.realname == NULL) + ui->realname_label->setText("Realname not set"); + else + ui->realname_label->setText(user.realname); + QPixmap image("avatar.jpg"); + ui->avatar_label->setPixmap(image); + +} diff --git a/stats_display_window.h b/stats_display_window.h new file mode 100644 index 0000000..887c550 --- /dev/null +++ b/stats_display_window.h @@ -0,0 +1,45 @@ +#ifndef STATS_DISPLAY_WINDOW_H +#define STATS_DISPLAY_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include "file_download.h" + +namespace Ui { +class stats_display_window; +} + +class stats_display_window : public QWidget +{ + Q_OBJECT + + +protected: + void showEvent(QShowEvent *ev); + +public: + explicit stats_display_window(QWidget *parent = 0); + ~stats_display_window(); + +private: + Ui::stats_display_window *ui; + + struct user_info { + QString username; + QString realname; + QString avatar_url; + } user; + + file_download download; +signals: + void window_loaded(); + +private slots: + void test(); +}; + +#endif // STATS_DISPLAY_WINDOW_H diff --git a/stats_display_window.ui b/stats_display_window.ui new file mode 100644 index 0000000..bf6d27e --- /dev/null +++ b/stats_display_window.ui @@ -0,0 +1,53 @@ + + + stats_display_window + + + Qt::ApplicationModal + + + + 0 + 0 + 740 + 479 + + + + CS:GO Statistics + + + + + + + Arial [Mono] + 14 + 75 + true + + + + username + + + + + + + realname + + + + + + + avatar + + + + + + + + diff --git a/user_select_dialog.cpp b/user_select_dialog.cpp new file mode 100644 index 0000000..81c40f4 --- /dev/null +++ b/user_select_dialog.cpp @@ -0,0 +1,57 @@ +#include "user_select_dialog.h" +#include "ui_user_select_dialog.h" + +user_select_dialog::user_select_dialog(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::user_select_dialog) +{ + ui->setupUi(this); +} + +user_select_dialog::~user_select_dialog() +{ + delete ui; +} + +void user_select_dialog::on_select_account_button_clicked() +{ + /* + * we need to check if the user gave a steam id + * if they did, proceed + */ + if (ui->steam_url_text->text() == NULL) + { + qDebug() << "No profile provided."; + } else { + qDebug() << "Profile selected:" << ui->steam_url_text->text(); + ui->close_button->setEnabled(false); + ui->select_account_button->setEnabled(false); + ui->steam_url_text->setEnabled(false); + ui->info_label->setText("Downloading data.."); + /* user data was a last second thought when designing this fucntion, clean it up one day, error checking etc */ + qDebug() << "Attempting to download user data"; + QString file_loc = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=FEBFDE46520663091143F867FEE39BFF&steamids=" + ui->steam_url_text->text(); + int success = download.download_file(file_loc, "userdata.dat"); + if (success == 1) + { + qDebug() << "Attempting to download cs:go data"; + file_loc = "http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=FEBFDE46520663091143F867FEE39BFF&steamid=" + ui->steam_url_text->text(); + success = download.download_file(file_loc, "csgodata.dat"); + } + if (success == 1) + { + qDebug() << "Downloaded everything"; /* file could be ANYTHING or empty! */ + n_window.show(); + this->hide(); + } + else + { + qDebug() << "Failed"; + ui->close_button->setEnabled(true); + ui->select_account_button->setEnabled(true); + ui->steam_url_text->setEnabled(true); + ui->info_label->setText("Failed to download, try again."); + } + + } +} diff --git a/user_select_dialog.h b/user_select_dialog.h new file mode 100644 index 0000000..98b3503 --- /dev/null +++ b/user_select_dialog.h @@ -0,0 +1,30 @@ +#ifndef USER_SELECT_DIALOG_H +#define USER_SELECT_DIALOG_H + +#include +#include +#include "file_download.h" +#include "stats_display_window.h" + +namespace Ui { +class user_select_dialog; +} + +class user_select_dialog : public QMainWindow +{ + Q_OBJECT + +public: + explicit user_select_dialog(QWidget *parent = 0); + ~user_select_dialog(); + +private slots: + void on_select_account_button_clicked(); + +private: + Ui::user_select_dialog *ui; + file_download download; + stats_display_window n_window; +}; + +#endif // USER_SELECT_DIALOG_H diff --git a/user_select_dialog.ui b/user_select_dialog.ui new file mode 100644 index 0000000..75a5e7d --- /dev/null +++ b/user_select_dialog.ui @@ -0,0 +1,72 @@ + + + user_select_dialog + + + Qt::ApplicationModal + + + + 0 + 0 + 181 + 115 + + + + Select a Steam account + + + + + + + Enter a Steam account ID + + + + + + + 76561198055087665 + + + + + + + Select + + + + + + + Close + + + + + + + + + + + close_button + clicked() + user_select_dialog + close() + + + 348 + 403 + + + 418 + 566 + + + + + -- cgit v1.2.3