diff options
| author | Iain R. Learmonth <irl@debian.org> | 2015-10-18 18:51:00 +0100 |
|---|---|---|
| committer | Iain R. Learmonth <irl@debian.org> | 2015-10-18 18:51:00 +0100 |
| commit | d63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch) | |
| tree | b9c1f6245147a310aac3762630bad389bbb57335 /GetUserId.cpp | |
| parent | c720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff) | |
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'GetUserId.cpp')
| -rw-r--r-- | GetUserId.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/GetUserId.cpp b/GetUserId.cpp new file mode 100644 index 00000000..238c3b5a --- /dev/null +++ b/GetUserId.cpp @@ -0,0 +1,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; +} |
