summaryrefslogtreecommitdiff
path: root/user_select_dialog.cpp
blob: c071fd73cc857ab566fc93e518c07a90e9db7256 (plain)
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
#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);
    load_players();
}

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 or selected a user
     * if they did, proceed
     */
    if (ui->steam_url_text->text() == NULL)
    {
        qDebug() << "No profile provided.";
    } else {
        download_info();
    }
}

void user_select_dialog::download_info()
{
    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->player_dropdown->setEnabled(false);
    ui->manage_users_button->setEnabled(false);
    ui->refresh_users_button->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();
        usernames.clear();
        userids.clear();
        this->hide();
    }
    else
    {
        qDebug() << "Failed";
        ui->close_button->setEnabled(true);
        ui->select_account_button->setEnabled(true);
        ui->steam_url_text->setEnabled(true);
        ui->player_dropdown->setEnabled(true);
        ui->manage_users_button->setEnabled(true);
        ui->info_label->setText("Failed to download, try again.");
    }
}

void user_select_dialog::load_players()
{
    parse.parse_users();
    usernames = parse.get_usernames();
    userids = parse.get_ids();
    for (int x = 0; x < usernames.length(); x++)
    {
        ui->player_dropdown->addItem(usernames.at(x));
    }
}

void user_select_dialog::on_player_dropdown_currentIndexChanged(int index)
{
    if (!usernames.isEmpty() && index != -1)
        ui->steam_url_text->setText(userids.at(index));
}

void user_select_dialog::on_manage_users_button_clicked()
{
    manage.show();
}

void user_select_dialog::on_refresh_users_button_clicked()
{
    ui->player_dropdown->clear();
    usernames.clear();
    userids.clear();
    load_players();
}