QTfrontend/ui/page/pageadmin.cpp
changeset 8157 695f1eef72c8
parent 6952 7f70f37bbf08
child 8177 1fc36c2168c4
equal deleted inserted replaced
8156:3ccc61102b58 8157:695f1eef72c8
    20 #include <QLabel>
    20 #include <QLabel>
    21 #include <QLineEdit>
    21 #include <QLineEdit>
    22 #include <QSpinBox>
    22 #include <QSpinBox>
    23 #include <QPushButton>
    23 #include <QPushButton>
    24 #include <QTextBrowser>
    24 #include <QTextBrowser>
       
    25 #include <QTableWidget>
       
    26 #include <QHeaderView>
    25 
    27 
    26 #include "pageadmin.h"
    28 #include "pageadmin.h"
    27 #include "chatwidget.h"
    29 #include "chatwidget.h"
       
    30 #include "bandialog.h"
    28 
    31 
    29 QLayout * PageAdmin::bodyLayoutDefinition()
    32 QLayout * PageAdmin::bodyLayoutDefinition()
    30 {
    33 {
    31     QGridLayout * pageLayout = new QGridLayout();
    34     QVBoxLayout * pageLayout = new QVBoxLayout();
    32 
    35 
    33     // 0
    36     QTabWidget * tabs = new QTabWidget(this);
    34     pbAsk = addButton(tr("Fetch data"), pageLayout, 0, 0, 1, 3);
    37     pageLayout->addWidget(tabs);
    35 
    38     QWidget * page1 = new QWidget(this);
    36     // 1
    39     QWidget * page2 = new QWidget(this);
    37     QLabel * lblSMN = new QLabel(this);
    40     tabs->addTab(page1, tr("General"));
    38     lblSMN->setText(tr("Server message for latest version:"));
    41     tabs->addTab(page2, tr("Bans"));
    39     pageLayout->addWidget(lblSMN, 1, 0);
    42 
    40 
    43     // page 1
    41     leServerMessageNew = new QLineEdit(this);
    44     {
    42     pageLayout->addWidget(leServerMessageNew, 1, 1);
    45         QGridLayout * tab1Layout = new QGridLayout(page1);
    43 
    46 
    44     // 2
    47         // 0
    45     QLabel * lblSMO = new QLabel(this);
    48         pbAsk = addButton(tr("Fetch data"), tab1Layout, 0, 0, 1, 3);
    46     lblSMO->setText(tr("Server message for previous versions:"));
    49 
    47     pageLayout->addWidget(lblSMO, 2, 0);
    50         // 1
    48 
    51         QLabel * lblSMN = new QLabel(this);
    49     leServerMessageOld = new QLineEdit(this);
    52         lblSMN->setText(tr("Server message for latest version:"));
    50     pageLayout->addWidget(leServerMessageOld, 2, 1);
    53         tab1Layout->addWidget(lblSMN, 1, 0);
    51 
    54 
    52     // 3
    55         leServerMessageNew = new QLineEdit(this);
    53     QLabel * lblP = new QLabel(this);
    56         tab1Layout->addWidget(leServerMessageNew, 1, 1);
    54     lblP->setText(tr("Latest version protocol number:"));
    57 
    55     pageLayout->addWidget(lblP, 3, 0);
    58         // 2
    56 
    59         QLabel * lblSMO = new QLabel(this);
    57     sbProtocol = new QSpinBox(this);
    60         lblSMO->setText(tr("Server message for previous versions:"));
    58     pageLayout->addWidget(sbProtocol, 3, 1);
    61         tab1Layout->addWidget(lblSMO, 2, 0);
    59 
    62 
    60     // 4
    63         leServerMessageOld = new QLineEdit(this);
    61     QLabel * lblPreview = new QLabel(this);
    64         tab1Layout->addWidget(leServerMessageOld, 2, 1);
    62     lblPreview->setText(tr("MOTD preview:"));
    65 
    63     pageLayout->addWidget(lblPreview, 4, 0);
    66         // 3
    64 
    67         QLabel * lblP = new QLabel(this);
    65     tb = new QTextBrowser(this);
    68         lblP->setText(tr("Latest version protocol number:"));
    66     tb->setOpenExternalLinks(true);
    69         tab1Layout->addWidget(lblP, 3, 0);
    67     tb->document()->setDefaultStyleSheet(HWChatWidget::styleSheet());
    70 
    68     pageLayout->addWidget(tb, 4, 1, 1, 2);
    71         sbProtocol = new QSpinBox(this);
    69 
    72         tab1Layout->addWidget(sbProtocol, 3, 1);
    70     // 5
    73 
    71     pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), pageLayout, 5, 0);
    74         // 4
    72 
    75         QLabel * lblPreview = new QLabel(this);
    73     // 6
    76         lblPreview->setText(tr("MOTD preview:"));
    74     pbSetSM = addButton(tr("Set data"), pageLayout, 6, 0, 1, 3);
    77         tab1Layout->addWidget(lblPreview, 4, 0);
       
    78 
       
    79         tb = new QTextBrowser(this);
       
    80         tb->setOpenExternalLinks(true);
       
    81         tb->document()->setDefaultStyleSheet(HWChatWidget::styleSheet());
       
    82         tab1Layout->addWidget(tb, 4, 1, 1, 2);
       
    83 
       
    84         // 5
       
    85         pbClearAccountsCache = addButton(tr("Clear Accounts Cache"), tab1Layout, 5, 0);
       
    86 
       
    87         // 6
       
    88         pbSetSM = addButton(tr("Set data"), tab1Layout, 6, 0, 1, 3);
       
    89     }
       
    90 
       
    91     // page 2
       
    92     {
       
    93         QGridLayout * tab2Layout = new QGridLayout(page2);
       
    94         twBans = new QTableWidget(this);
       
    95         twBans->setColumnCount(3);
       
    96         twBans->setHorizontalHeaderLabels(QStringList()
       
    97                               << tr("IP/Nick")
       
    98                               << tr("Expiration")
       
    99                               << tr("Reason")
       
   100                     );
       
   101         twBans->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
       
   102         twBans->setEditTriggers(QAbstractItemView::NoEditTriggers);
       
   103         twBans->setSelectionBehavior(QAbstractItemView::SelectRows);
       
   104         twBans->setSelectionMode(QAbstractItemView::SingleSelection);
       
   105         twBans->setAlternatingRowColors(true);
       
   106         tab2Layout->addWidget(twBans, 0, 1, 4, 1);
       
   107 
       
   108         QPushButton * btnRefresh = addButton(tr("Refresh"), tab2Layout, 0, 0);
       
   109         QPushButton * btnAdd = addButton(tr("Add"), tab2Layout, 1, 0);
       
   110         QPushButton * btnRemove = addButton(tr("Remove"), tab2Layout, 2, 0);
       
   111 
       
   112         connect(btnRefresh, SIGNAL(clicked()), this, SIGNAL(bansListRequest()));
       
   113         connect(btnRefresh, SIGNAL(clicked()), this, SLOT(onRefreshClicked()));
       
   114         connect(btnAdd, SIGNAL(clicked()), this, SLOT(onAddClicked()));
       
   115         connect(btnRemove, SIGNAL(clicked()), this, SLOT(onRemoveClicked()));
       
   116     }
    75 
   117 
    76     return pageLayout;
   118     return pageLayout;
    77 }
   119 }
    78 
   120 
    79 void PageAdmin::connectSignals()
   121 void PageAdmin::connectSignals()
   104 
   146 
   105 void PageAdmin::serverMessageOld(const QString & str)
   147 void PageAdmin::serverMessageOld(const QString & str)
   106 {
   148 {
   107     leServerMessageOld->setText(str);
   149     leServerMessageOld->setText(str);
   108 }
   150 }
       
   151 
   109 void PageAdmin::protocol(int proto)
   152 void PageAdmin::protocol(int proto)
   110 {
   153 {
   111     sbProtocol->setValue(proto);
   154     sbProtocol->setValue(proto);
   112 }
   155 }
       
   156 
       
   157 void PageAdmin::onAddClicked()
       
   158 {
       
   159     BanDialog dialog;
       
   160 
       
   161     if(dialog.exec())
       
   162     {
       
   163         if(dialog.byIP())
       
   164         {
       
   165             emit banIP(dialog.banId(), dialog.reason(), dialog.duration());
       
   166         } else
       
   167         {
       
   168             emit banNick(dialog.banId(), dialog.reason(), dialog.duration());
       
   169         }
       
   170 
       
   171         emit bansListRequest();
       
   172     }
       
   173 }
       
   174 
       
   175 void PageAdmin::onRemoveClicked()
       
   176 {
       
   177     QList<QTableWidgetItem *> sel = twBans->selectedItems();
       
   178 
       
   179     if(sel.size())
       
   180     {
       
   181         emit removeBan(twBans->item(sel[0]->row(), 0)->data(Qt::DisplayRole).toString());
       
   182         emit bansListRequest();
       
   183     }
       
   184 }
       
   185 
       
   186 void PageAdmin::setBansList(const QStringList & bans)
       
   187 {
       
   188     if(bans.size() % 4)
       
   189         return;
       
   190 
       
   191     twBans->setRowCount(bans.size() / 4);
       
   192 
       
   193     for(int i = 0; i < bans.size(); i += 4)
       
   194     {
       
   195         if(!twBans->item(i / 4, 0))
       
   196         {
       
   197             twBans->setItem(i / 4, 0, new QTableWidgetItem());
       
   198             twBans->setItem(i / 4, 1, new QTableWidgetItem());
       
   199             twBans->setItem(i / 4, 2, new QTableWidgetItem());
       
   200         }
       
   201 
       
   202         twBans->item(i / 4, 0)->setData(Qt::DisplayRole, bans[i + 1]);
       
   203         twBans->item(i / 4, 1)->setData(Qt::DisplayRole, bans[i + 3]);
       
   204         twBans->item(i / 4, 2)->setData(Qt::DisplayRole, bans[i + 2]);
       
   205     }
       
   206 }
       
   207 
       
   208 void PageAdmin::onRefreshClicked()
       
   209 {
       
   210     twBans->setRowCount(0);
       
   211 }