summaryrefslogtreecommitdiff
path: root/user_management.cpp
blob: 488773b761e5c427e4535a2ee80df3accae3cfba (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
#include "user_management.h"
#include "ui_user_management.h"

user_management::user_management(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::user_management)
{
    ui->setupUi(this);
    load_players();
}

user_management::~user_management()
{
    delete ui;
}

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

void user_management::on_refresh_users_button_clicked()
{
    load_players();
}

void user_management::on_delete_user_button_clicked()
{
    int opt = msgbox.confirm_box("You are about to delete a user", "Are you sure?", "Warning");
    switch (opt) {
       case QMessageBox::Yes: {
            QString to_remove = ui->user_dropdown->currentText() + "=" + userids.at(ui->user_dropdown->currentIndex());
            parse.delete_user(to_remove);
            load_players();
            break;
    }
       case QMessageBox::No:
           break;
       default:
           break;
     }
}

void user_management::on_add_user_button_clicked()
{
    if (ui->username_text->text() != "" && ui->user_id_text->text() != "")
    {
        QString user = ui->username_text->text() + "=" + ui->user_id_text->text();
        parse.add_user(user);
    }
}