-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetUserId.cpp
75 lines (60 loc) · 1.68 KB
/
GetUserId.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
#include "GetUserId.hpp"
#include <stdexcept>
#include <QApplication>
#include <QString>
#include <QDialog>
#include <QLineEdit>
#include <QRegExpValidator>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QVBoxLayout>
//
// Dialog to get callsign
//
class CallsignDialog final
: public QDialog
{
Q_OBJECT;
private:
Q_DISABLE_COPY (CallsignDialog);
public:
explicit CallsignDialog (QWidget * parent = nullptr)
: QDialog {parent}
{
setWindowTitle (QApplication::applicationName () + " - " + tr ("Callsign"));
callsign_.setValidator (new QRegExpValidator {QRegExp {"[A-Za-z0-9]+"}, this});
auto form_layout = new QFormLayout ();
form_layout->addRow ("&Callsign:", &callsign_);
auto main_layout = new QVBoxLayout (this);
main_layout->addLayout (form_layout);
auto button_box = new QDialogButtonBox {QDialogButtonBox::Ok | QDialogButtonBox::Cancel};
main_layout->addWidget (button_box);
connect (button_box, &QDialogButtonBox::accepted, this, &CallsignDialog::accept);
connect (button_box, &QDialogButtonBox::rejected, this, &CallsignDialog::reject);
}
QString callsign () const {return callsign_.text ();}
private:
QLineEdit callsign_;
};
#include "GetUserId.moc"
QString get_user_id ()
{
// get the users callsign so we can use it to persist the
// settings and log file against a unique tag
QString id;
{
CallsignDialog dialog;
while (id.isEmpty ())
{
if (QDialog::Accepted == dialog.exec ())
{
id = dialog.callsign ().toUpper ();
}
else
{
throw std::runtime_error ("Callsign required");
}
}
}
return id;
}