|
@@ -4,200 +4,202 @@
|
4
|
4
|
|
5
|
5
|
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
6
|
6
|
{
|
7
|
|
- ui->setupUi(this);
|
|
7
|
+ ui->setupUi(this);
|
8
|
8
|
|
9
|
9
|
QShortcut* quit = new QShortcut(QKeySequence("Ctrl+Q"), this);
|
10
|
10
|
connect(quit, SIGNAL(activated()), qApp, SLOT(quit()));
|
11
|
11
|
|
12
|
12
|
|
13
|
|
- /*EpiUser usr;
|
14
|
|
- usr.setLogin("azerty_u");
|
15
|
|
- usr.setPwd_ppp("psswd");
|
16
|
|
- Epimafia::saveUser(usr);
|
17
|
|
- usr.setLogin("");
|
18
|
|
- usr.setPwd_ppp("ppp");
|
19
|
|
- Epimafia::saveUser(usr);
|
20
|
|
- usr.setLogin("login_x");
|
21
|
|
- Epimafia::saveUser(usr);*/
|
22
|
|
-
|
23
|
|
- m_currentUser = 0;
|
24
|
|
-
|
25
|
|
- foreach(QLineEdit* line, findChildren<QLineEdit*>())
|
26
|
|
- connect(line, SIGNAL(returnPressed()), this, SLOT(search()));
|
27
|
|
- m_intra = new IntraBocal(this);
|
28
|
|
- connect(m_intra, SIGNAL(error(IntraBocal::Error)), this, SLOT(intraError(IntraBocal::Error)));
|
29
|
|
- connect(m_intra, SIGNAL(logged()), this, SLOT(intraLogged()));
|
30
|
|
- connect(m_intra, SIGNAL(searchFinished(QList<QList<QString> >)), this, SLOT(intraSearchFinished(QList<QList<QString> >)));
|
31
|
|
- foreach(City city, IntraBocal::getCities())
|
32
|
|
- ui->comboBox->addItem(city.second, city.first);
|
33
|
|
-
|
34
|
|
- loadUsers();
|
35
|
|
-
|
36
|
|
- QStringList args = qApp->arguments();
|
37
|
|
- for(int i = 1; i < args.size() - 1; ++i)
|
38
|
|
- {
|
39
|
|
- QString arg = args.at(i);
|
40
|
|
- if(arg == "-firstName")
|
41
|
|
- ui->lineFirstName->setText(args.at(++i));
|
42
|
|
- else if(arg == "-lastName")
|
43
|
|
- ui->lineLastName->setText(args.at(++i));
|
44
|
|
- else if(arg == "-login")
|
45
|
|
- ui->lineLogin->setText(args.at(++i));
|
46
|
|
- else if(arg == "-promo")
|
47
|
|
- ui->linePromo->setText(args.at(++i));
|
48
|
|
- else if(arg == "-school")
|
49
|
|
- ui->lineSchool->setText(args.at(++i));
|
50
|
|
- }
|
51
|
|
- if(!ui->lineFirstName->text().isEmpty() || !ui->lineLastName->text().isEmpty() || !ui->lineLogin->text().isEmpty() || !ui->linePromo->text().isEmpty() || !ui->lineSchool->text().isEmpty())
|
52
|
|
- search();
|
|
13
|
+ /*EpiUser usr;
|
|
14
|
+ usr.setLogin("azerty_u");
|
|
15
|
+ usr.setPwd_ppp("psswd");
|
|
16
|
+ Epimafia::saveUser(usr);
|
|
17
|
+ usr.setLogin("");
|
|
18
|
+ usr.setPwd_ppp("ppp");
|
|
19
|
+ Epimafia::saveUser(usr);
|
|
20
|
+ usr.setLogin("login_x");
|
|
21
|
+ Epimafia::saveUser(usr);*/
|
|
22
|
+
|
|
23
|
+ m_currentUser = 0;
|
|
24
|
+
|
|
25
|
+ foreach(QLineEdit* line, findChildren<QLineEdit*>())
|
|
26
|
+ connect(line, SIGNAL(returnPressed()), this, SLOT(search()));
|
|
27
|
+ m_intra = new IntraBocal(this);
|
|
28
|
+ connect(m_intra, SIGNAL(error(IntraBocal::Error)), this, SLOT(intraError(IntraBocal::Error)));
|
|
29
|
+ connect(m_intra, SIGNAL(logged()), this, SLOT(intraLogged()));
|
|
30
|
+ connect(m_intra, SIGNAL(searchFinished(QList<QList<QString> >)), this, SLOT(intraSearchFinished(QList<QList<QString> >)));
|
|
31
|
+ foreach(City city, IntraBocal::getCities())
|
|
32
|
+ ui->comboBox->addItem(city.second, city.first);
|
|
33
|
+
|
|
34
|
+ loadUsers();
|
|
35
|
+
|
|
36
|
+ QStringList args = qApp->arguments();
|
|
37
|
+ for(int i = 1; i < args.size() - 1; ++i)
|
|
38
|
+ {
|
|
39
|
+ QString arg = args.at(i);
|
|
40
|
+ if(arg == "-firstName")
|
|
41
|
+ ui->lineFirstName->setText(args.at(++i));
|
|
42
|
+ else if(arg == "-lastName")
|
|
43
|
+ ui->lineLastName->setText(args.at(++i));
|
|
44
|
+ else if(arg == "-login")
|
|
45
|
+ ui->lineLogin->setText(args.at(++i));
|
|
46
|
+ else if(arg == "-promo")
|
|
47
|
+ ui->linePromo->setText(args.at(++i));
|
|
48
|
+ else if(arg == "-school")
|
|
49
|
+ ui->lineSchool->setText(args.at(++i));
|
|
50
|
+ }
|
|
51
|
+ if(!ui->lineFirstName->text().isEmpty() || !ui->lineLastName->text().isEmpty() || !ui->lineLogin->text().isEmpty() || !ui->linePromo->text().isEmpty() || !ui->lineSchool->text().isEmpty())
|
|
52
|
+ search();
|
53
|
53
|
|
54
|
54
|
}
|
55
|
55
|
|
56
|
56
|
Widget::~Widget()
|
57
|
57
|
{
|
58
|
|
- delete ui;
|
|
58
|
+ delete ui;
|
59
|
59
|
}
|
60
|
60
|
|
61
|
61
|
void Widget::paintEvent(QPaintEvent *)
|
62
|
62
|
{
|
63
|
|
- resizeToMin();
|
|
63
|
+ resizeToMin();
|
64
|
64
|
}
|
65
|
65
|
|
66
|
66
|
void Widget::search(bool badLogin)
|
67
|
67
|
{
|
68
|
|
- if(m_users.isEmpty())
|
69
|
|
- {
|
70
|
|
- askStartUsrMgr();
|
71
|
|
- return;
|
72
|
|
- }
|
73
|
|
- if(badLogin)
|
74
|
|
- ui->labelStatus->setText("Bad Loggin. Trying Another...");
|
75
|
|
- else
|
76
|
|
- ui->labelStatus->setText("Logging in...");
|
77
|
|
- EpiUser usr = m_users.at(m_currentUser);
|
78
|
|
- m_intra->login(usr.getLogin(), usr.getPwd_ppp());
|
79
|
|
- clearLayout(ui->gridLayout);
|
|
68
|
+ if(m_users.isEmpty())
|
|
69
|
+ {
|
|
70
|
+ askStartUsrMgr();
|
|
71
|
+ return;
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ if(badLogin)
|
|
75
|
+ ui->labelStatus->setText("Bad Loggin. Trying Another...");
|
|
76
|
+ else
|
|
77
|
+ ui->labelStatus->setText("Logging in...");
|
|
78
|
+ EpiUser usr = m_users.at(m_currentUser);
|
|
79
|
+ m_intra->login(usr.getLogin(), usr.getPwd_ppp());
|
|
80
|
+ clearLayout(ui->gridLayout);
|
80
|
81
|
}
|
81
|
82
|
|
82
|
83
|
void Widget::loadUsers()
|
83
|
84
|
{
|
84
|
|
- m_users = Epimafia::loadUsers();
|
85
|
|
- for(int i = 0; i < m_users.size(); ++i)
|
86
|
|
- {
|
87
|
|
- EpiUser usr = m_users.at(i);
|
88
|
|
- if(!usr.hasLogin() || usr.isUnknown() || !usr.hasPwd_ppp())
|
89
|
|
- m_users.removeAt(i--);
|
90
|
|
- }
|
91
|
|
- m_currentUser = 0;
|
|
85
|
+ m_users = Epimafia::loadUsers();
|
|
86
|
+ for(int i = 0; i < m_users.size(); ++i)
|
|
87
|
+ {
|
|
88
|
+ EpiUser usr = m_users.at(i);
|
|
89
|
+ if(!usr.hasLogin() || usr.isUnknown() || !usr.hasPwd_ppp())
|
|
90
|
+ m_users.removeAt(i--);
|
|
91
|
+ }
|
|
92
|
+ m_currentUser = 0;
|
92
|
93
|
}
|
93
|
94
|
|
94
|
95
|
void Widget::askStartUsrMgr()
|
95
|
96
|
{
|
96
|
|
- QMessageBox* msg = new QMessageBox(this);
|
97
|
|
- msg->setIcon(QMessageBox::Question);
|
98
|
|
- msg->setWindowTitle("No logins found");
|
99
|
|
- msg->setText("No logins with ppp are available.\nDo you want to open User Manager to create one?");
|
100
|
|
- connect(msg->addButton(QMessageBox::Yes), SIGNAL(clicked()), this, SLOT(startUsrMgr()));
|
101
|
|
- connect(msg->addButton(QMessageBox::No), SIGNAL(clicked()), this, SLOT(loadUsers()));
|
102
|
|
- msg->show();
|
|
97
|
+ QMessageBox* msg = new QMessageBox(this);
|
|
98
|
+ msg->setIcon(QMessageBox::Question);
|
|
99
|
+ msg->setWindowTitle("No logins found");
|
|
100
|
+ msg->setText("No logins with ppp are available.\nDo you want to open User Manager to create one?");
|
|
101
|
+ connect(msg->addButton(QMessageBox::Yes), SIGNAL(clicked()), this, SLOT(startUsrMgr()));
|
|
102
|
+ connect(msg->addButton(QMessageBox::No), SIGNAL(clicked()), this, SLOT(loadUsers()));
|
|
103
|
+ msg->show();
|
103
|
104
|
}
|
104
|
105
|
|
105
|
106
|
void Widget::startUsrMgr()
|
106
|
107
|
{
|
107
|
|
- QProcess* p = new QProcess(this);
|
108
|
|
- connect(p, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
|
|
108
|
+ QProcess* p = new QProcess(this);
|
|
109
|
+ connect(p, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
|
109
|
110
|
QString exe;
|
110
|
111
|
#ifdef Q_OS_WIN
|
111
|
|
-exe = "usermgr.exe";
|
|
112
|
+ exe = "usermgr.exe";
|
112
|
113
|
#else
|
113
|
|
- #ifdef Q_OS_LINUX
|
|
114
|
+#ifdef Q_OS_LINUX
|
114
|
115
|
exe = "usermgr";
|
115
|
|
- #else
|
116
|
|
- #error "OS specific"
|
117
|
|
- #endif
|
|
116
|
+#else
|
|
117
|
+#error "OS specific"
|
|
118
|
+#endif
|
118
|
119
|
#endif
|
119
|
120
|
p->start(exe);
|
120
|
121
|
}
|
121
|
122
|
|
122
|
123
|
void Widget::intraError(IntraBocal::Error e)
|
123
|
124
|
{
|
124
|
|
- if(e == IntraBocal::BadLogin)
|
125
|
|
- {
|
126
|
|
- ui->labelStatus->setText("#BadLogin#");
|
127
|
|
- ++m_currentUser;
|
128
|
|
- if(m_currentUser < m_users.size())
|
129
|
|
- search(true);
|
130
|
|
- else
|
131
|
|
- askStartUsrMgr();
|
132
|
|
- }
|
133
|
|
- else if(e == IntraBocal::NetworkError)
|
134
|
|
- ui->labelStatus->setText("#NetworkError#");
|
135
|
|
- else if(e == IntraBocal::ParseError)
|
136
|
|
- ui->labelStatus->setText("#ParseError#");
|
137
|
|
- else if(e == IntraBocal::SslError)
|
138
|
|
- ui->labelStatus->setText("#SslError#");
|
|
125
|
+ if(e == IntraBocal::BadLogin)
|
|
126
|
+ {
|
|
127
|
+ ui->labelStatus->setText("#BadLogin#");
|
|
128
|
+ ++m_currentUser;
|
|
129
|
+ if(m_currentUser < m_users.size())
|
|
130
|
+ search(true);
|
|
131
|
+ else
|
|
132
|
+ askStartUsrMgr();
|
|
133
|
+ }
|
|
134
|
+ else if(e == IntraBocal::NetworkError)
|
|
135
|
+ ui->labelStatus->setText("#NetworkError#");
|
|
136
|
+ else if(e == IntraBocal::ParseError)
|
|
137
|
+ ui->labelStatus->setText("#ParseError#");
|
|
138
|
+ else if(e == IntraBocal::SslError)
|
|
139
|
+ ui->labelStatus->setText("#SslError#");
|
139
|
140
|
}
|
140
|
141
|
|
141
|
142
|
void Widget::intraLogged()
|
142
|
143
|
{
|
143
|
|
- ui->labelStatus->setText("Logged in. Searching...");
|
144
|
|
- m_intra->searchUser(ui->lineLastName->text(), ui->lineFirstName->text(), ui->lineLogin->text(), ui->linePromo->text(),
|
145
|
|
- ui->lineSchool->text(), ui->comboBox->itemData(ui->comboBox->currentIndex()).toString());
|
|
144
|
+ ui->labelStatus->setText("Logged in. Searching...");
|
|
145
|
+ m_intra->searchUser(ui->lineLastName->text(), ui->lineFirstName->text(), ui->lineLogin->text(), ui->linePromo->text(),
|
|
146
|
+ ui->lineSchool->text(), ui->comboBox->itemData(ui->comboBox->currentIndex()).toString());
|
146
|
147
|
}
|
147
|
148
|
|
148
|
149
|
void Widget::intraSearchFinished(QList<QList<QString> > users)
|
149
|
150
|
{
|
150
|
|
- if(users.isEmpty())
|
151
|
|
- {
|
152
|
|
- ui->labelStatus->setText("No results");
|
153
|
|
- return;
|
154
|
|
- }
|
155
|
|
- QList<QString> header = users.at(0);
|
156
|
|
- for(int c = 0; c < header.size(); ++c)
|
157
|
|
- {
|
158
|
|
- QLabel* lbl = new QLabel();
|
159
|
|
- QFont f = lbl->font();
|
160
|
|
- f.setBold(true);
|
161
|
|
- lbl->setFont(f);
|
162
|
|
- lbl->setText(header.at(c));
|
163
|
|
- ui->gridLayout->addWidget(lbl, 0, c);
|
164
|
|
- }
|
165
|
|
- for(int i = 1; i < users.size(); ++i)
|
166
|
|
- {
|
167
|
|
- QList<QString> user = users.at(i);
|
168
|
|
- for(int c = 0; c < user.size(); ++c)
|
169
|
|
- {
|
170
|
|
- QLabel* lbl = new QLabel();
|
171
|
|
- lbl->setText(user.at(c));
|
172
|
|
- ui->gridLayout->addWidget(lbl, i, c);
|
173
|
|
- }
|
174
|
|
- }
|
175
|
|
- ui->labelStatus->setText("idle");
|
|
151
|
+ if(users.isEmpty())
|
|
152
|
+ {
|
|
153
|
+ ui->labelStatus->setText("No results");
|
|
154
|
+ return;
|
|
155
|
+ }
|
|
156
|
+ QList<QString> header = users.at(0);
|
|
157
|
+ for(int c = 0; c < header.size(); ++c)
|
|
158
|
+ {
|
|
159
|
+ QLabel* lbl = new QLabel();
|
|
160
|
+ QFont f = lbl->font();
|
|
161
|
+ f.setBold(true);
|
|
162
|
+ lbl->setFont(f);
|
|
163
|
+ lbl->setText(header.at(c));
|
|
164
|
+ ui->gridLayout->addWidget(lbl, 0, c);
|
|
165
|
+ }
|
|
166
|
+ for(int i = 1; i < users.size(); ++i)
|
|
167
|
+ {
|
|
168
|
+ QList<QString> user = users.at(i);
|
|
169
|
+ for(int c = 0; c < user.size(); ++c)
|
|
170
|
+ {
|
|
171
|
+ QLabel* lbl = new QLabel();
|
|
172
|
+ lbl->setText(user.at(c));
|
|
173
|
+ ui->gridLayout->addWidget(lbl, i, c);
|
|
174
|
+ }
|
|
175
|
+ }
|
|
176
|
+ ui->labelStatus->setText("idle");
|
176
|
177
|
}
|
177
|
178
|
|
178
|
179
|
void Widget::resizeToMin()
|
179
|
180
|
{
|
180
|
|
- resize(minimumSizeHint());
|
181
|
|
- setFixedSize(size());
|
|
181
|
+ resize(minimumSizeHint());
|
|
182
|
+ setFixedSize(size());
|
182
|
183
|
}
|
183
|
184
|
|
184
|
185
|
void Widget::processFinished(int)
|
185
|
186
|
{
|
186
|
|
- sender()->deleteLater();
|
187
|
|
- search();
|
|
187
|
+ sender()->deleteLater();
|
|
188
|
+ loadUsers();
|
|
189
|
+ search();
|
188
|
190
|
}
|
189
|
191
|
|
190
|
192
|
void Widget::clearLayout(QLayout *layout)
|
191
|
193
|
{
|
192
|
|
- QLayoutItem *item;
|
193
|
|
- while((item = layout->takeAt(0))) {
|
194
|
|
- if (item->layout()) {
|
195
|
|
- clearLayout(item->layout());
|
196
|
|
- delete item->layout();
|
197
|
|
- }
|
198
|
|
- if (item->widget()) {
|
199
|
|
- delete item->widget();
|
200
|
|
- }
|
201
|
|
- delete item;
|
202
|
|
- }
|
|
194
|
+ QLayoutItem *item;
|
|
195
|
+ while((item = layout->takeAt(0))) {
|
|
196
|
+ if (item->layout()) {
|
|
197
|
+ clearLayout(item->layout());
|
|
198
|
+ delete item->layout();
|
|
199
|
+ }
|
|
200
|
+ if (item->widget()) {
|
|
201
|
+ delete item->widget();
|
|
202
|
+ }
|
|
203
|
+ delete item;
|
|
204
|
+ }
|
203
|
205
|
}
|