summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interfaces/interfaceinformationimp.cpp
blob: 39575c441a1df538d9f0ff62100b68d3b0c7184b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "interfaceinformationimp.h"
#include "interfaceadvanced.h"

#include <qpushbutton.h>
#include <qlabel.h>
#include <qgroupbox.h>
#include <qmessagebox.h>

#include <assert.h>

/**
 * Constructor for the InterfaceInformationImp class.  This class pretty much
 * just display's information about the interface that is passed to it.
 */ 
InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
  assert(i);
  
  interface = i;
  connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
  connect(i, SIGNAL(updateMessage(const QString &)), this, SLOT(showMessage(const QString &)));
  updateInterface(interface);
  connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
  connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
  connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
  connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
  connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
}

/**
 * Update the interface information and buttons.
 * @param Intarface *i the interface to update (should be the one we already
 *                     know about).
 */ 
void InterfaceInformationImp::updateInterface(Interface *i){
  if(interface->getStatus()){
    startButton->setEnabled(false);
    stopButton->setEnabled(true);
    restartButton->setEnabled(true);
  }
  else{
    startButton->setEnabled(true);
    stopButton->setEnabled(false);
    restartButton->setEnabled(false);
  }
  macAddressLabel->setText(interface->getMacAddress());
  ipAddressLabel->setText(interface->getIp());
  subnetMaskLabel->setText(interface->getSubnetMask());
  broadcastLabel->setText(interface->getBroadcast());
}

/**
 * Create the advanced widget. Fill it with the current interface's information.
 * Display it.
 */ 
void InterfaceInformationImp::advanced(){
  InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
  a->interfaceName->setText(interface->getInterfaceName());
  a->macAddressLabel->setText(interface->getMacAddress());
  a->ipAddressLabel->setText(interface->getIp());
  a->subnetMaskLabel->setText(interface->getSubnetMask());
  a->broadcastLabel->setText(interface->getBroadcast());
  a->dhcpServerLabel->setText(interface->getDhcpServerIp());
  a->leaseObtainedLabel->setText(interface->getLeaseObtained());
  a->leaseExpiresLabel->setText(interface->getLeaseExpires());
  a->dhcpInformation->setEnabled(interface->isDhcp());
	 
  a->showMaximized();
  a->show();
}

/**
 * Messages from the interface if start/stop went as planned.
 * Purly for user feedback.
 * @param message the message to display.
 */ 
void InterfaceInformationImp::showMessage(const QString &message){
  QMessageBox::information(this, "Message", message, QMessageBox::Ok);
}

// infoimp.cpp