-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
439 lines (362 loc) · 12.2 KB
/
mainwindow.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#include <QtGui>
#include <QInputDialog>
#include <QFile>
#include <QDir>
#include <QTextStream>
#include <QTimer>
#include "sessionenum.h"
#include "mainwindow.h"
#include "debugbox.h"
const int OwnerPos = 0;
const int AudioPos = 1;
const int VideoPos = 2;
const int TextPos = 3;
const int ConfNamePos = 4;
const int OrganizerPos = 5;
const int ContactPos = 6;
MainWindow::MainWindow(char *argv[], QWidget *parent)
:QDialog(parent)
{
readSettings();
binaryPath = argv[0];
QString temp = binaryPath.left(binaryPath.lastIndexOf("/"));
binaryPath = temp;
debug("binary path is " + temp);
pubConfList = new QTreeWidget;
pubConfList->setEnabled(false);
pubConfList->setRootIsDecorated(false);
pubConfList->setHeaderLabels(QStringList() << tr("")<<tr("")<<tr("")<<tr("")<<tr("Conference Name")<<tr("Organizer")<<tr("Contact"));
pubConfList->setColumnWidth(OwnerPos, 25);
pubConfList->setColumnWidth(AudioPos, 25);
pubConfList->setColumnWidth(VideoPos, 25);
pubConfList->setColumnWidth(TextPos, 25);
pubConfList->setColumnWidth(ConfNamePos, 200);
pubConfList->setColumnWidth(ContactPos, 150);
confDesc = new QTextEdit;
confDesc->setReadOnly(true);
confDesc->setEnabled(false);
pubConfLabel = new QLabel(tr("Public Conferences"));
confDescLabel = new QLabel(tr("Conference Descriptions"));
QString warning = "Current prefix for voice data is: " + prefix ;
currentPrefLabel = new QLabel(warning);
newButton = new QPushButton(tr("New"));
prefButton = new QPushButton(tr("Preferences"));
exportCertButton = new QPushButton(tr("Export Cert"));
quitButton = new QPushButton(tr("Quit"));
joinAudioButton = new QPushButton(tr("Join Audio Session"));
joinAudioButton->setEnabled(false);
joinVideoButton = new QPushButton(tr("Join Video Session"));
joinVideoButton->setEnabled(false);
dismissButton = new QPushButton(tr("Dismiss"));
dismissButton->setEnabled(false);
listPrivate = new QCheckBox(tr("Also List Private Conferences"));
connect(listPrivate, SIGNAL(stateChanged(int)), this, SLOT(listPrivateConferences()));
QHBoxLayout *topLayout = new QHBoxLayout;
topLayout->addWidget(newButton);
topLayout->addWidget(prefButton);
topLayout->addWidget(exportCertButton);
topLayout->addWidget(quitButton);
footButtonBox = new QDialogButtonBox;
footButtonBox->addButton(joinAudioButton, QDialogButtonBox::ActionRole);
footButtonBox->addButton(joinVideoButton, QDialogButtonBox::ActionRole);
footButtonBox->addButton(dismissButton, QDialogButtonBox::ActionRole);
QHBoxLayout *midLayout = new QHBoxLayout;
midLayout->addWidget(pubConfLabel);
midLayout->addWidget(listPrivate);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
mainLayout->addLayout(midLayout);
mainLayout->addWidget(pubConfList);
mainLayout->addWidget(confDescLabel);
mainLayout->addWidget(confDesc);
mainLayout->addWidget(currentPrefLabel);
mainLayout->addWidget(footButtonBox);
setLayout(mainLayout);
setWindowTitle(tr("Conference Management Tool"));
connect(newButton, SIGNAL(clicked()), this, SLOT(newConference()));
connect(prefButton, SIGNAL(clicked()), this, SLOT(changePref()));
connect(exportCertButton, SIGNAL(clicked()), this, SLOT(exportCert()));
connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(joinAudioButton, SIGNAL(clicked()), this, SLOT(joinAudioConference()));
connect(joinVideoButton, SIGNAL(clicked()), this, SLOT(joinVideoConference()));
connect(dismissButton, SIGNAL(clicked()), this, SLOT(dismissConference()));
connect(pubConfList, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(processItem()));
sd = new SessionEnum();
connect(sd, SIGNAL(expired(QString, QString)), this, SLOT(removeConferenceFromList(QString, QString)));
connect(sd, SIGNAL(add(Announcement *)), this, SLOT(addConferenceToList(Announcement *)));
if (prefix == "") {
QTimer::singleShot(500, this, SLOT(changePref()));
}
audioProcess = NULL;
mumbleProcess = NULL;
kiwiProcess = NULL;
}
QSize MainWindow::sizeHint() const
{
return QSize(600, 600);
}
void MainWindow::processItem(){
QTreeWidgetItem *current = pubConfList->currentItem();
if (!current) {
pubConfList->setEnabled(false);
confDesc->clear();
confDesc->setEnabled(false);
joinAudioButton->setEnabled(false);
joinVideoButton->setEnabled(false);
dismissButton->setEnabled(false);
return;
}
Announcement *a = itemToAnnouncement[current];
if (a->getOwner()) {
dismissButton->setEnabled(true);
} else {
dismissButton->setEnabled(false);
}
if (a->getAudio())
joinAudioButton->setEnabled(true);
else
joinAudioButton->setEnabled(false);
if (a->getVideo())
joinVideoButton->setEnabled(true);
else
joinVideoButton->setEnabled(false);
//QString desc = current->data(3, Qt::UserRole).toString();
QString desc = a->getDesc();
confDesc->setPlainText(desc);
}
void MainWindow::readSettings() {
QSettings settings("UCLA_IRL", "ACTD");
prefix = settings.value("prefix", QString("")).toString();
}
void MainWindow::writeSettings() {
QSettings settings("UCLA_IRL", "ACTD");
settings.setValue("prefix", prefix);
}
void MainWindow::exportCert() {
QString certFilename = QString("%1/.actd/actd_cert.pem").arg(getenv("HOME"));
QFile certFile(certFilename);
if (!certFile.exists()) {
QString keystoreFilename = QString("%1/.actd/.actd_keystore").arg(getenv("HOME"));
QFile keystoreFile(keystoreFilename);
if (!keystoreFile.exists()) {
critical("Keystore file has been deleted or renamed after actd launches. Please restart actd.");
}
FILE *fp;
PKCS12 *keystore;
OpenSSL_add_all_algorithms();
fp = fopen(keystoreFilename.toStdString().c_str(), "rb");
if (fp == NULL)
abort();
keystore = d2i_PKCS12_fp(fp, NULL);
fclose(fp);
if (keystore == NULL)
abort();
EVP_PKEY *private_key;
X509 *certificate;
int res = PKCS12_parse(keystore, (char *)"Th1s1s@p8ssw0rdf0r8ctd.", &private_key, &certificate, NULL);
PKCS12_free(keystore);
if (res == 0)
return;
fp = fopen(certFilename.toStdString().c_str(), "w");
res = PEM_write_X509(fp, certificate);
fclose(fp);
if (res == 0)
abort();
}
QString exportFilename = QFileDialog::getSaveFileName(this, "Export Actd Cert", QString("%1/actd_cert.pem").arg(getenv("HOME")));
if (!certFile.copy(exportFilename)) {
QFile::remove(exportFilename);
if (!certFile.copy(exportFilename)) {
QMessageBox::warning(this, "Export Cert Failed", "Can not export cert. Please check if you have write permission");
}
}
}
void MainWindow::changePref() {
bool ok;
QString text = QInputDialog::getText(this, tr("Get Name Prefix for Conference"), tr("Input the name prefix for the conference application:"), QLineEdit::Normal, prefix, &ok);
if (ok && !text.isEmpty()) {
prefix = text;
writeSettings();
QString warning = "Current prefix for voice data is: " + prefix ;
currentPrefLabel->setText(warning);
}
}
void MainWindow::writeConfig() {
QTreeWidgetItem *current = pubConfList->currentItem();
if (!current) {
critical("current is null");
}
QString confName = current->text(ConfNamePos);
QString qsConfig = "<config><prefix>" + prefix + "</prefix><confName>";
Announcement *a = itemToAnnouncement[current];
if (a->getIsPrivate()) {
qsConfig += a->getOpaqueName() + "</confName>";
qsConfig += "<private>true</private>";
QByteArray confKey((const char *)a->conferenceKey, (int)sizeof(a->conferenceKey));
QString qsConfKey = QString(confKey.toBase64());
qsConfig += "<confKey>" + qsConfKey + "</confKey>";
QByteArray sessionKey((const char *)a->audioSessionKey, (int)sizeof(a->audioSessionKey));
QString qsSessionKey = QString(sessionKey.toBase64());
qsConfig += "<sessionKey>" + qsSessionKey + "</sessionKey>";
}
else {
qsConfig += confName + "</confName>";
qsConfig += "<private>false</private>";
}
qsConfig += "<channelName>" + confName + "</channelName>";
qsConfig += "</config>";
QDomDocument doc;
QDir actDir(QDir::homePath() + "/" + ".actd");
if (!actDir.exists()) {
QDir homedir = QDir::home();
homedir.mkdir(".actd");
}
QString fileName = actDir.absolutePath() + "/" + ".config";
QFile config(fileName);
if (config.exists()) {
config.remove();
}
config.open(QIODevice::WriteOnly | QIODevice::Truncate);
QTextStream out (&config);
out << qsConfig;
// flush, maybe not needed, but sometimes release version of murmurd on iMac
// uses old conference name
config.flush();
config.close();
}
void MainWindow::joinAudioConference() {
mumbleCleanup();
writeConfig();
audioProcess = new QProcess(this);
mumbleProcess = new QProcess(this);
#ifdef __APPLE__
audioPath = "/Applications/Mumble.app/Contents/MacOS/ndn-murmurd";
mumblePath = "/Applications/Mumble.app/Contents/MacOS/Mumble";
#else
audioPath = "ndn-murmurd";
mumblePath = "ndn-mumble";
#endif
audioProcess->start(audioPath);
mumbleProcess->start(mumblePath);
}
void MainWindow::joinVideoConference() {
writeConfig();
kiwiProcess = new QProcess(this);
#ifdef __APPLE__
kiwiPath = "/Applications/Kiwi.app/Contents/MacOS/kiwi";
#else
kiwiPath = "kiwi";
#endif
kiwiProcess->start(kiwiPath);
}
void MainWindow::mumbleCleanup() {
if (mumbleProcess != NULL) {
mumbleProcess->kill();
mumbleProcess->deleteLater();
mumbleProcess = NULL;
}
if (audioProcess != NULL) {
audioProcess->kill();
audioProcess->deleteLater();
audioProcess = NULL;
}
}
void MainWindow::dismissConference() {
QTreeWidgetItem *current = pubConfList->currentItem();
if (!current) {
QString qs = "Dismiss: current is null!";
critical(qs);
}
Announcement *a = itemToAnnouncement[current];
sd->removeFromMyConferences(a);
//delete a;
itemToAnnouncement.remove(current);
// remove from GUI
delete current;
}
void MainWindow::newConference() {
Announcement *a = new Announcement();
ConfWizard wizard;
wizard.exec();
Announcement *announce = wizard.getAnnouncement();
if (announce == NULL)
return;
a->copy(announce);
addConferenceToList(a);
sd->addToMyConferences(a);
}
void MainWindow::addConferenceToList(Announcement *announce) {
if (announce == NULL) {
QString qs ="add: conference announcement is null!";
critical(qs);
}
QTreeWidgetItem *item = new QTreeWidgetItem;
itemToAnnouncement.insert(item, announce);
item->setText(ConfNamePos, announce->getConfName());
QString oDesc = announce->getDesc();
QString date = announce->getDate().toString("ddd MMM d");
QString start = announce->getTime().toString("h:mm AP");
int hours = announce->getHours();
int minutes = announce->getMinutes();
QString desc = QString("Date: %1\nTime: %2\nDuration: %3 Hours %4 Minutes\n-------------------------------\n%5").arg(date).arg(start).arg(hours).arg(minutes).arg(oDesc);
//item->setData(4, Qt::UserRole, desc);
item->setText(OrganizerPos, announce->getOrganizer());
item->setText(ContactPos, announce->getEmail());
if (announce->getOwner() ) {
QPixmap setting(":/images/setting.png");
item->setIcon(OwnerPos, setting);
} else {
if (announce->getIsPrivate()) {
QPixmap priv(":/images/priv.png");
item->setIcon(OwnerPos, priv);
}
}
if (announce->getAudio()) {
QPixmap audio(":/images/audio.png");
item->setIcon(AudioPos, audio);
}
if (announce->getVideo()) {
QPixmap video(":/images/video.png");
item->setIcon(VideoPos, video);
}
if (announce->getText()) {
QPixmap text(":/images/text.png");
item->setIcon(TextPos, text);
}
pubConfList->addTopLevelItem(item);
if (!pubConfList->currentItem()) {
pubConfList->setCurrentItem(pubConfList->topLevelItem(0));
pubConfList->setEnabled(true);
confDesc->setEnabled(true);
}
}
void MainWindow::removeConferenceFromList(QString confName, QString organizer) {
// remove from GUI
QList<QTreeWidgetItem *> conferences = pubConfList->findItems(confName,
Qt::MatchFixedString, ConfNamePos);
if (conferences.isEmpty()) {
QString qs = QString("no conference named %1 found!!").arg(confName);
//critical(qs);
// complain but not crash
debug(qs);
return;
}
while (!conferences.isEmpty()) {
QTreeWidgetItem *item = NULL;
item = conferences.takeFirst();
if (item != NULL && item->text(OrganizerPos) == organizer) {
itemToAnnouncement.remove(item);
delete item;
}
}
}
void MainWindow::listPrivateConferences() {
if (listPrivate->isChecked()) {
pubConfLabel->setText("Public And Private Conferences");
sd->setListPrivate(true);
}
else {
sd->setListPrivate(false);
pubConfLabel->setText("Public Conferences");
}
}