QTfrontend/ui/dialog/bandialog.cpp
changeset 8157 695f1eef72c8
child 8159 e226be871b6e
equal deleted inserted replaced
8156:3ccc61102b58 8157:695f1eef72c8
       
     1 #include <QFormLayout>
       
     2 #include <QComboBox>
       
     3 #include <QRadioButton>
       
     4 #include <QLineEdit>
       
     5 #include <QLabel>
       
     6 #include <QPushButton>
       
     7 #include <QHBoxLayout>
       
     8 #include <QMessageBox>
       
     9 
       
    10 #include "bandialog.h"
       
    11 
       
    12 BanDialog::BanDialog(QWidget *parent) :
       
    13     QDialog(parent)
       
    14 {
       
    15     QFormLayout * formLayout = new QFormLayout(this);
       
    16 
       
    17     rbIP = new QRadioButton(this);
       
    18     rbIP->setChecked(true);
       
    19     rbNick = new QRadioButton(this);
       
    20     leId = new QLineEdit(this);
       
    21     leReason = new QLineEdit(this);
       
    22     cbTime = new QComboBox(this);
       
    23 
       
    24     cbTime->addItem(tr("10 minutes"), 5 * 60);
       
    25     cbTime->addItem(tr("30 minutes"), 10 * 60);
       
    26     cbTime->addItem(tr("1 hour"), 60 * 60);
       
    27     cbTime->addItem(tr("3 hours"), 3 * 60 * 60);
       
    28     cbTime->addItem(tr("5 hours"), 5 * 60 * 60);
       
    29     cbTime->addItem(tr("24 hours"), 24 * 60 * 60);
       
    30     cbTime->addItem(tr("3 days"), 72 * 60 * 60);
       
    31     cbTime->addItem(tr("7 days"), 168 * 60 * 60);
       
    32     cbTime->addItem(tr("14 days"), 336 * 60 * 60);
       
    33     cbTime->addItem(tr("permanent"), 3650 * 60 * 60);
       
    34     cbTime->setCurrentIndex(0);
       
    35 
       
    36     formLayout->addRow(tr("IP"), rbIP);
       
    37     formLayout->addRow(tr("Nick"), rbNick);
       
    38     formLayout->addRow(tr("IP/Nick"), leId);
       
    39     formLayout->addRow(tr("Reason"), leReason);
       
    40     formLayout->addRow(tr("Duration"), cbTime);
       
    41 
       
    42     formLayout->setLabelAlignment(Qt::AlignRight);
       
    43 
       
    44     QHBoxLayout * hbox = new QHBoxLayout();
       
    45     formLayout->addRow(hbox);
       
    46     QPushButton * btnOk = new QPushButton(tr("Ok"), this);
       
    47     QPushButton * btnCancel = new QPushButton(tr("Cancel"), this);
       
    48     hbox->addStretch();
       
    49     hbox->addWidget(btnOk);
       
    50     hbox->addWidget(btnCancel);
       
    51 
       
    52     connect(btnOk, SIGNAL(clicked()), this, SLOT(okClicked()));
       
    53     connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject()));
       
    54 }
       
    55 
       
    56 bool BanDialog::byIP()
       
    57 {
       
    58     return rbIP->isChecked();
       
    59 }
       
    60 
       
    61 int BanDialog::duration()
       
    62 {
       
    63     return cbTime->itemData(cbTime->currentIndex()).toInt();
       
    64 }
       
    65 
       
    66 QString BanDialog::banId()
       
    67 {
       
    68     return leId->text();
       
    69 }
       
    70 
       
    71 QString BanDialog::reason()
       
    72 {
       
    73     return leReason->text().isEmpty() ? tr("you know why") : leReason->text();
       
    74 }
       
    75 
       
    76 void BanDialog::okClicked()
       
    77 {
       
    78     if(leId->text().isEmpty())
       
    79     {
       
    80         QMessageBox::warning(this, tr("Warning"), tr("Please, specify %1").arg(byIP() ? tr("IP") : tr("nickname")));
       
    81         return;
       
    82     }
       
    83 
       
    84     accept();
       
    85 }