QTfrontend/ui/dialog/bandialog.cpp
author Mitchell Kember <mk12360@gmail.com>
Sun, 02 Dec 2012 17:44:34 -0500
changeset 8192 81da6576b0c3
parent 8177 1fc36c2168c4
child 8411 cb371dac50c0
permissions -rw-r--r--
Make video recording options have fixed size and merge with spinbox->combobox change.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8157
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     1
#include <QFormLayout>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     2
#include <QComboBox>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     3
#include <QRadioButton>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     4
#include <QLineEdit>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     5
#include <QLabel>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     6
#include <QPushButton>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     7
#include <QHBoxLayout>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     8
#include <QMessageBox>
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
     9
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    10
#include "bandialog.h"
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    11
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    12
BanDialog::BanDialog(QWidget *parent) :
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    13
    QDialog(parent)
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    14
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    15
    QFormLayout * formLayout = new QFormLayout(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    16
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    17
    rbIP = new QRadioButton(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    18
    rbIP->setChecked(true);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    19
    rbNick = new QRadioButton(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    20
    leId = new QLineEdit(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    21
    leReason = new QLineEdit(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    22
    cbTime = new QComboBox(this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    23
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    24
    cbTime->addItem(tr("10 minutes"), 5 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    25
    cbTime->addItem(tr("30 minutes"), 10 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    26
    cbTime->addItem(tr("1 hour"), 60 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    27
    cbTime->addItem(tr("3 hours"), 3 * 60 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    28
    cbTime->addItem(tr("5 hours"), 5 * 60 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    29
    cbTime->addItem(tr("24 hours"), 24 * 60 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    30
    cbTime->addItem(tr("3 days"), 72 * 60 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    31
    cbTime->addItem(tr("7 days"), 168 * 60 * 60);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    32
    cbTime->addItem(tr("14 days"), 336 * 60 * 60);
8177
1fc36c2168c4 Some fixes
unc0rr
parents: 8159
diff changeset
    33
    cbTime->addItem(tr("permanent"), 3650 * 24 * 60 * 60);
8157
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    34
    cbTime->setCurrentIndex(0);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    35
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    36
    formLayout->addRow(tr("IP"), rbIP);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    37
    formLayout->addRow(tr("Nick"), rbNick);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    38
    formLayout->addRow(tr("IP/Nick"), leId);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    39
    formLayout->addRow(tr("Reason"), leReason);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    40
    formLayout->addRow(tr("Duration"), cbTime);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    41
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    42
    formLayout->setLabelAlignment(Qt::AlignRight);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    43
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    44
    QHBoxLayout * hbox = new QHBoxLayout();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    45
    formLayout->addRow(hbox);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    46
    QPushButton * btnOk = new QPushButton(tr("Ok"), this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    47
    QPushButton * btnCancel = new QPushButton(tr("Cancel"), this);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    48
    hbox->addStretch();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    49
    hbox->addWidget(btnOk);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    50
    hbox->addWidget(btnCancel);
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    51
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    52
    connect(btnOk, SIGNAL(clicked()), this, SLOT(okClicked()));
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    53
    connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
8159
e226be871b6e set window modality for new ban dialogs
koda
parents: 8157
diff changeset
    54
e226be871b6e set window modality for new ban dialogs
koda
parents: 8157
diff changeset
    55
    this->setWindowModality(Qt::WindowModal);
8157
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    56
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    57
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    58
bool BanDialog::byIP()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    59
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    60
    return rbIP->isChecked();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    61
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    62
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    63
int BanDialog::duration()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    64
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    65
    return cbTime->itemData(cbTime->currentIndex()).toInt();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    66
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    67
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    68
QString BanDialog::banId()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    69
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    70
    return leId->text();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    71
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    72
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    73
QString BanDialog::reason()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    74
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    75
    return leReason->text().isEmpty() ? tr("you know why") : leReason->text();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    76
}
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    77
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    78
void BanDialog::okClicked()
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    79
{
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    80
    if(leId->text().isEmpty())
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    81
    {
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    82
        QMessageBox::warning(this, tr("Warning"), tr("Please, specify %1").arg(byIP() ? tr("IP") : tr("nickname")));
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    83
        return;
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    84
    }
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    85
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    86
    accept();
695f1eef72c8 Bans manager
unc0rr
parents:
diff changeset
    87
}