1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #include "mumble_pch.hpp"
7 
8 #include "Tokens.h"
9 
10 #include "Database.h"
11 #include "ServerHandler.h"
12 
13 // We define a global macro called 'g'. This can lead to issues when included code uses 'g' as a type or parameter name (like protobuf 3.7 does). As such, for now, we have to make this our last include.
14 #include "Global.h"
15 
Tokens(QWidget * p)16 Tokens::Tokens(QWidget *p) : QDialog(p) {
17 	setupUi(this);
18 
19 	qbaDigest = g.sh->qbaDigest;
20 	QStringList tokens = g.db->getTokens(qbaDigest);
21 	tokens.sort();
22 	foreach(const QString &qs, tokens) {
23 		QListWidgetItem *qlwi = new QListWidgetItem(qs);
24 		qlwi->setFlags(qlwi->flags() | Qt::ItemIsEditable);
25 		qlwTokens->addItem(qlwi);
26 	}
27 }
28 
accept()29 void Tokens::accept() {
30 	QStringList qsl;
31 
32 	QList<QListWidgetItem *> items = qlwTokens->findItems(QString(), Qt::MatchStartsWith);
33 	foreach(QListWidgetItem *qlwi, items) {
34 		const QString &text = qlwi->text().trimmed();
35 		if (! text.isEmpty())
36 			qsl << text;
37 	}
38 	g.db->setTokens(qbaDigest, qsl);
39 	g.sh->setTokens(qsl);
40 	QDialog::accept();
41 }
42 
on_qpbAdd_clicked()43 void Tokens::on_qpbAdd_clicked() {
44 	QListWidgetItem *qlwi = new QListWidgetItem(tr("Empty Token"));
45 	qlwi->setFlags(qlwi->flags() | Qt::ItemIsEditable);
46 
47 	qlwTokens->addItem(qlwi);
48 	qlwTokens->editItem(qlwi);
49 }
50 
on_qpbRemove_clicked()51 void Tokens::on_qpbRemove_clicked() {
52 	foreach(QListWidgetItem *qlwi, qlwTokens->selectedItems())
53 		delete qlwi;
54 }
55 
56