forked from ElvishArtisan/rivendell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdadd_cart.cpp
253 lines (226 loc) · 7.17 KB
/
rdadd_cart.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// rdadd_cart.cpp
//
// Add a Rivendell Cart
//
// (C) Copyright 2002-2019 Fred Gleason <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qpushbutton.h>
#include <qmessagebox.h>
#include <rddb.h>
#include <rdescape_string.h>
#include <rdgroup.h>
#include "rdadd_cart.h"
RDAddCart::RDAddCart(QString *group,RDCart::Type *type,QString *title,
const QString &username,const QString &caption,
RDSystem *system,QWidget *parent)
: RDDialog(parent)
{
QString sql;
RDSqlQuery *q;
cart_system=system;
cart_group=group;
cart_type=type;
cart_title=title;
//
// Fix the Window Size
//
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
setWindowTitle(caption+" - "+tr("Add Cart"));
//
// Group
//
cart_group_box=new QComboBox(this);
cart_group_box->setGeometry(145,11,160,19);
QLabel *cart_group_label=
new QLabel(cart_group_box,tr("&Group:"),this,
"cart_group_label");
cart_group_label->setGeometry(10,11,130,19);
cart_group_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic);
cart_group_label->setFont(labelFont());
sql=QString("select GROUP_NAME from USER_PERMS where ")+
"USER_NAME=\""+RDEscapeString(username)+"\" order by GROUP_NAME";
q=new RDSqlQuery(sql);
while(q->next()) {
cart_group_box->insertItem(q->value(0).toString());
if(q->value(0).toString()==*cart_group) {
cart_group_box->setCurrentItem(cart_group_box->count()-1);
}
}
delete q;
connect(cart_group_box,SIGNAL(activated(const QString &)),
this,SLOT(groupActivatedData(const QString &)));
//
// Cart Number
//
cart_number_edit=new QLineEdit(this);
cart_number_edit->setGeometry(145,32,60,19);
cart_number_edit->setMaxLength(6);
QIntValidator *validator=new QIntValidator(this,"validator");
validator->setRange(1,999999);
cart_number_edit->setValidator(validator);
QLabel *cart_number_label=
new QLabel(cart_number_edit,tr("&New Cart Number:"),this);
cart_number_label->setGeometry(10,32,130,19);
cart_number_label->setFont(labelFont());
cart_number_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic);
//
// Cart Type
//
cart_type_box=new QComboBox(this);
cart_type_box->setGeometry(145,53,100,19);
QLabel *cart_type_label=
new QLabel(cart_type_box,tr("&New Cart Type:"),this);
cart_type_label->setGeometry(10,53,130,19);
cart_type_label->setFont(labelFont());
cart_type_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic);
if((*cart_type==RDCart::All)||(*cart_type==RDCart::Audio)) {
cart_type_box->insertItem(tr("Audio"));
}
if((*cart_type==RDCart::All)||(*cart_type==RDCart::Macro)) {
cart_type_box->insertItem(tr("Macro"));
}
if(*cart_type==RDCart::All) {
sql=QString("select DEFAULT_CART_TYPE from GROUPS where ")+
"NAME=\""+RDEscapeString(*cart_group)+"\"";
q=new RDSqlQuery(sql);
if(q->first()) {
cart_type_box->setCurrentItem(q->value(0).toUInt()-1);
}
delete q;
}
//
// Cart Title
//
cart_title_edit=new QLineEdit(this);
cart_title_edit->setGeometry(145,73,sizeHint().width()-155,19);
cart_title_edit->setMaxLength(255);
// cart_title_edit->setValidator(text_validator);
cart_title_edit->setText(tr("[new cart]"));
QLabel *cart_title_label=
new QLabel(cart_title_edit,tr("&New Cart Title:"),this);
cart_title_label->setGeometry(10,73,130,19);
cart_title_label->setFont(labelFont());
cart_title_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter|Qt::TextShowMnemonic);
//
// Ok Button
//
QPushButton *ok_button=new QPushButton(this);
ok_button->setGeometry(sizeHint().width()-180,sizeHint().height()-60,80,50);
ok_button->setDefault(true);
ok_button->setFont(buttonFont());
ok_button->setText(tr("&OK"));
connect(ok_button,SIGNAL(clicked()),this,SLOT(okData()));
//
// Cancel Button
//
QPushButton *cancel_button=new QPushButton(this);
cancel_button->setGeometry(sizeHint().width()-90,sizeHint().height()-60,
80,50);
cancel_button->setFont(buttonFont());
cancel_button->setText(tr("&Cancel"));
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
groupActivatedData(cart_group_box->currentText());
}
QSize RDAddCart::sizeHint() const
{
return QSize(400,160);
}
QSizePolicy RDAddCart::sizePolicy() const
{
return QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
}
void RDAddCart::groupActivatedData(const QString &groupname)
{
unsigned cartnum=0;
RDGroup *group=new RDGroup(groupname);
if((cartnum=group->nextFreeCart())==0) {
cart_number_edit->clear();
if(group->enforceCartRange()) {
QMessageBox::warning(this,tr("No Available Cart Numbers"),
tr("There are no more available cart numbers for the group!"));
}
}
else {
cart_number_edit->setText(QString().sprintf("%06u",cartnum));
}
delete group;
}
void RDAddCart::okData()
{
RDSqlQuery *q;
QString sql;
unsigned num;
RDGroup *group=new RDGroup(cart_group_box->currentText());
if((sscanf((const char *)cart_number_edit->text(),"%d",&num)!=1)||
(num<=0)) {
QMessageBox::warning(this,tr("Invalid Number"),tr("Invalid Cart Number!"));
return;
}
if(cart_title_edit->text().isEmpty()) {
QMessageBox::warning(this,tr("Title Required"),
tr("You must enter a cart title!"));
return;
}
RDSystem *system=new RDSystem();
if(!system->allowDuplicateCartTitles()) {
sql=QString("select NUMBER from CART where ")+
"TITLE=\""+RDEscapeString(cart_title_edit->text())+"\"";
q=new RDSqlQuery(sql);
if(q->first()) {
QMessageBox::warning(this,tr("Duplicate Title"),
tr("The cart title must be unique!"));
delete q;
return;
}
delete q;
}
delete system;
if(group->enforceCartRange()) {
if((num<group->defaultLowCart())||(num>group->defaultHighCart())) {
QMessageBox::warning(this,tr("Invalid Number"),
tr("The cart number is outside of the permitted range for this group!"));
delete group;
return;
}
}
sql=QString().sprintf("select NUMBER from CART where NUMBER=%u",num);
q=new RDSqlQuery(sql);
if(q->first()) {
QMessageBox::information(this,tr("Cart Exists"),
tr("This cart already exists."),
QMessageBox::Ok);
delete q;
delete group;
return;
}
delete q;
delete group;
*cart_group=cart_group_box->currentText();
if(*cart_type==RDCart::All) {
*cart_type=(RDCart::Type)(cart_type_box->currentItem()+1);
}
*cart_title=cart_title_edit->text();
done(num);
}
void RDAddCart::cancelData()
{
done(-1);
}
void RDAddCart::closeEvent(QCloseEvent *e)
{
cancelData();
}