-
Notifications
You must be signed in to change notification settings - Fork 0
/
firstTimeWizard.cpp
161 lines (135 loc) · 5.12 KB
/
firstTimeWizard.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
#include"firstTimeWizard.h"
FirstTimeWizard::FirstTimeWizard(QWidget *parent, const char *name) : QWizard( parent, name, TRUE)
{
setPageOne();
setPageTwo();
setPageThree();
setPageFour();
showPage(pageOne);
exec();
}
///////////////////////////////////////////////////////////////////////////
//
// By overriding the default QWizard::showPage()
// function, I can catch if the user is ready for pageThree,
// and if so, I can execute the system() function before showing
// the page.
//
////////////////////////////////////////////////////////////////////////////
void FirstTimeWizard::showPage(QWidget* page)
{
if(page == pageThree)
{
QString hostStr = QString::null ;
if(!server->text().isNull() && server->text() != "localhost")
hostStr = QString("-h %1" ).arg(server->text());
QString sysStr = QString("mysql -u %1 -p %2 %3 << hdm_ddl.sql") .arg(username->text()) .arg(password->text() .arg(hostStr));
int error = std::system(sysStr);
if( error == -1)
QWizard::showPage(pageThree);
else
QWizard::showPage(pageFour);
}
QWizard::showPage(page);
}
void FirstTimeWizard::setPageOne()
{
pageOne = new QHBox( this );
QLabel * label = new QLabel(pageOne);
label->setText("This appears to be the first time you \n"
"have used the Hattrick Depth Manager\n\n"
"This Wizard will help you set up your database\n"
"And create it's configuration files\n\n\n"
"Press the Next button to continue");
addPage(pageOne, "Intro");
setBackEnabled(pageOne,false);
setNextEnabled(pageOne,true);
setHelpEnabled(pageOne,false);
setFinishEnabled(pageOne,false);
}
void FirstTimeWizard::setPageTwo()
{
pageTwo = new QWidget( this );
// databaseLabel->setMinimumWidth(usernameLabel->sizeHint().width());
// serverLabel->setMinimumWidth(usernameLabel->sizeHint().width());
// usernameLabel->setMinimumWidth(usernameLabel->sizeHint().width());
// passwordLabel->setMinimumWidth(usernameLabel->sizeHint().width());
QLabel * databaseLabel = new QLabel(pageTwo);
databaseLabel->setAlignment(Qt::AlignVCenter);
databaseSelect = new QComboBox(pageTwo);
databaseSelect->insertItem("MySql");
QLabel * serverLabel = new QLabel("server",pageTwo);
serverLabel->setAlignment(Qt::AlignVCenter);
//QPushButton * connectButton = new QPushButton("Connect", pageTwo);
// connect(connectButton,clicked(),this, makeConnection());
server = new QLineEdit(pageTwo);
QHBoxLayout* line1 = new QHBoxLayout();
line1->addWidget(databaseLabel);
line1->addWidget(databaseSelect);
QHBoxLayout* line2 = new QHBoxLayout();
line2->addWidget(serverLabel);
line2->addWidget(server);
QHBoxLayout* line3 = new QHBoxLayout();
QLabel * usernameLabel = new QLabel("user name",pageTwo);
usernameLabel->setAlignment(Qt::AlignVCenter);
line3->addWidget(usernameLabel);
username = new QLineEdit(pageTwo);
line3->addWidget(username);
QHBoxLayout* line4 = new QHBoxLayout();
QLabel * passwordLabel = new QLabel("password",pageTwo);
passwordLabel->setAlignment(Qt::AlignVCenter);
line4->addWidget(passwordLabel);
password = new QLineEdit(pageTwo);
password->setEchoMode(QLineEdit::Password);
line4->addWidget(password);
QVBoxLayout * formBox = new QVBoxLayout();
formBox->setMargin(11);
formBox->addLayout(line1);
formBox->addLayout(line2);
formBox->addLayout(line3);
formBox->addLayout(line4);
// formBox->addWidget(connectButton);
QLabel * pageInfo = new QLabel(pageTwo);
pageInfo->setText("<h2>Enter Database Info</h2> <p>please enter your connection info for a MySql database.</p> "
"<p>HDM will attempt to connect to the database, and, if successful, create the required database tables.</p>");
/*pageInfo->setText("Enter the information about your database\n\n"
"At This time HDM only supports MySQL\n\n"
"HDM asks for your username and password\n"
"of a MySql account so that it can set up\n"
"it's own username, and database tables\n"
"and will not keep this info");
*/
QHBoxLayout * mainLayout = new QHBoxLayout(pageTwo);
mainLayout->addWidget(pageInfo);
mainLayout->addStretch(4);
mainLayout->addLayout(formBox);
addPage(pageTwo, "Enter Database Info");
setBackEnabled(pageTwo,true);
setNextEnabled(pageTwo,false);
setHelpEnabled(pageTwo,true);
setFinishEnabled(pageTwo,false);
}
void FirstTimeWizard::setPageThree()
{
pageThree = new QHBox(this);
QLabel * pageThreeLabel = new QLabel(pageThree);
pageThreeLabel->setText("<h2>Error</h2>"
"<p>HDM was unable to connect to the database.</p>"
"<p>Please press the Back button and re-enter the info</p>"
"<p>and be certain to start the database server, if it has not been allready");
addPage(pageThree,"Database Configuration Unsucessful");
setNextEnabled(pageThree, false);
setBackEnabled(pageThree, true);
}
void FirstTimeWizard::setPageFour()
{
pageFour = new QHBox(this);
QLabel *pageFourLabel = new QLabel(pageFour);
pageFourLabel->setText("<h2> Success! </h2>"
"<p>HDM's database tables were successfully created and you"
"are now ready to use HDM. Probably the first thing you should"
"do is download your player info.<p>");
setBackEnabled(pageFour, false);
setFinishEnabled(pageFour, true);
addPage(pageFour, "Success");
}