-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkupondialog.cpp
More file actions
75 lines (65 loc) · 1.5 KB
/
kupondialog.cpp
File metadata and controls
75 lines (65 loc) · 1.5 KB
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
#include "kupondialog.h"
#include "ui_kupondialog.h"
KuponDialog::KuponDialog(Settings* settings, QWidget *parent) :
QDialog(parent),
ui(new Ui::KuponDialog)
{
s = settings;
ui->setupUi(this);
}
KuponDialog::~KuponDialog()
{
delete ui;
}
void KuponDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void KuponDialog::show(){
ui->lineEdit->selectAll();
QDialog::show();
}
void KuponDialog::loadCodes(){
QFile* f = new QFile("codes.txt");
f->open(QIODevice::ReadOnly);
while(!f->atEnd()){
codes.insert(QString::fromAscii(f->readLine()).trimmed());
}
f->close();
}
void KuponDialog::clearCodes(){
codes.clear();
}
int KuponDialog::kreditGain(QString code){
int x = code.length()-6;
int a=s->getInt("credits/base_gain");
for(;x>0;x--)
a*=2;
return a+1; //+1 kvoli tomu resizu co sa zavola
}
void KuponDialog::accept(){
QString code = ui->lineEdit->text();
clearCodes();
loadCodes();
if(!codes.contains(code)){
qDebug() << "wrong code";
QDialog::reject();
return;
}
if(s->isset("used/"+code)){
qDebug() << "already used code";
QDialog::reject();
return;
}
Logger::log("Pouzity kupon "+code+", ziskali "+QString::number(kreditGain(code))+" kreditov");
s->setProp("used/"+code,1);
s->increment("credits/count",kreditGain(code));
QDialog::accept();
}