source: src-qt4/warden-gui/dialogEditIP.cpp @ 0cfe72f

9.1-release9.2-releasereleng/10.0releng/10.0.1
Last change on this file since 0cfe72f was 0cfe72f, checked in by Kris Moore <kris@…>, 12 months ago

Add all the changes for related using of split pcbsd-utils libs

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12// QT Includes
13#include <QInputDialog>
14#include <QProcess>
15#include <QString>
16#include <QFileDialog>
17#include <QMessageBox>
18#include <QDebug>
19#include "pcbsd-utils.h"
20
21// Local Includes
22#include "dialogEditIP.h"
23
24void dialogEditIP::programInit(QString jIP, QStringList IPs)
25{
26  wardenIP = jIP;
27  listIP->clear();
28  for ( int i=0; i<IPs.count() ; i++)
29     if ( ! IPs.at(i).isEmpty() )
30        listIP->addItem(IPs.at(i));
31
32  // Our buttons / slots
33  connect( pushSave, SIGNAL( clicked() ), this, SLOT( slotSaveClicked() ) );
34  connect( pushCancel, SIGNAL( clicked() ), this, SLOT( slotCancelClicked() ) );
35  connect( pushAdd, SIGNAL( clicked() ), this, SLOT( slotAddClicked() ) );
36  connect( pushRemove, SIGNAL( clicked() ), this, SLOT( slotRemClicked() ) );
37}
38
39void dialogEditIP::slotCancelClicked()
40{
41   close();
42}
43
44bool dialogEditIP::sanityCheckSettings()
45{
46  return true;
47}
48
49void dialogEditIP::slotSaveClicked()
50{
51   if ( sanityCheckSettings() )
52   {
53     saveSettings();
54     emit saved();
55     close();
56   }
57}
58
59void dialogEditIP::saveSettings()
60{
61        QStringList IPs;
62        for ( int i=0; i<listIP->count() ; i++)
63                IPs << listIP->item(i)->text();
64
65        qDebug() << "Updating IPs...";
66        QProcess ipcmd;
67        if ( IPs.count() == 0 )
68          ipcmd.start(QString("warden"), QStringList() << "set" << "ip" << wardenIP << "" );
69        else
70          ipcmd.start(QString("warden"), QStringList() << "set" << "ip" << wardenIP << IPs.join(",") );
71
72        setEnabled(false);
73        ipcmd.waitForFinished(1000);
74        while ( ipcmd.state() != QProcess::NotRunning ) {
75                ipcmd.waitForFinished(100);
76                QCoreApplication::processEvents();
77        }
78       
79}
80
81void dialogEditIP::slotAddClicked()
82{
83        bool ok;
84        QString url = QInputDialog::getText(this, tr("Add IP"),
85                                        tr("IP Address:"), QLineEdit::Normal,
86                                        QString(), &ok);
87        if ( ok ) {
88          if ( pcbsd::Utils::validateIPV4(url) || pcbsd::Utils::validateIPV6(url) )
89            listIP->addItem(url);
90          else
91            QMessageBox::critical(this, tr("Warden"), \
92                                tr("Please enter a valid IPV4 or IPV6 address!"), \
93                                QMessageBox::Ok, \
94                                QMessageBox::Ok);
95        }
96}
97
98void dialogEditIP::slotRemClicked()
99{
100        if ( ! listIP->currentItem() )
101                return;
102
103        delete listIP->currentItem();
104}
Note: See TracBrowser for help on using the repository browser.