summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interface.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/interface.cpp77
1 files changed, 61 insertions, 16 deletions
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp
index 1f32093..1e01da4 100644
--- a/noncore/settings/networksettings/interface.cpp
+++ b/noncore/settings/networksettings/interface.cpp
@@ -11,51 +11,92 @@
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13 13
14Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){ 14Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
15 refresh(); 15 refresh();
16} 16}
17 17
18/** 18/**
19 * Set status
20 * @param newStatus - the new status
21 * emit updateInterface
22 */
23void Interface::setStatus(bool newStatus){
24 if(status != newStatus){
25 status = newStatus;
26 refresh();
27 }
28};
29
30/**
31 * Set if attached or not (802.11 card pulled out for example)
32 * @param isAttached - if attached
33 * emit updateInterface
34 */
35void Interface::setAttached(bool isAttached){
36 attached = isAttached;
37 emit(updateInterface(this));
38};
39
40/**
41 * Set Hardware name
42 * @param name - the new name
43 * emit updateInterface
44 */
45void Interface::setHardwareName(QString name){
46 hardareName = name;
47 emit(updateInterface(this));
48};
49
50/**
51 * Set Module owner
52 * @param owner - the new owner
53 * emit updateInterface
54 */
55void Interface::setModuleOwner(Module *owner){
56 moduleOwner = owner;
57 emit(updateInterface(this));
58};
59
60
61/**
19 * Try to start the interface. 62 * Try to start the interface.
20 * @return bool true if successfull.
21 */ 63 */
22bool Interface::start(){ 64void Interface::start(){
23 // check to see if we are already running. 65 // check to see if we are already running.
24 if(status) 66 if(true == status)
25 return false; 67 return;
26 68
27 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1()); 69 int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
70 // See if it was successfull...
28 if(ret != 0) 71 if(ret != 0)
29 return false; 72 return;
30 73
31 status = true; 74 status = true;
32 refresh(); 75 refresh();
33 return true;
34} 76}
35 77
36/** 78/**
37 * Try to stop the interface. 79 * Try to stop the interface.
38 * @return bool true if successfull.
39 */ 80 */
40bool Interface::stop(){ 81void Interface::stop(){
41 // check to see if we are already stopped. 82 // check to see if we are already stopped.
42 if(status == false) 83 if(false == status)
43 return false; 84 return;
44 85
45 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1()); 86 int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
46 if(ret != 0) 87 if(ret != 0)
47 return false; 88 return;
48 89
49 status = true; 90 status = true;
50 refresh(); 91 refresh();
51 return true;
52} 92}
93
53/** 94/**
54 * Try to restart the interface. 95 * Try to restart the interface.
55 * @return bool true if successfull.
56 */ 96 */
57bool Interface::restart(){ 97void Interface::restart(){
58 return (stop() && start()); 98 stop();
99 start();
59} 100}
60 101
61/** 102/**
@@ -74,6 +115,7 @@ bool Interface::refresh(){
74 dhcpServerIp = ""; 115 dhcpServerIp = "";
75 leaseObtained = ""; 116 leaseObtained = "";
76 leaseExpires = ""; 117 leaseExpires = "";
118 emit(updateInterface(this));
77 return true; 119 return true;
78 } 120 }
79 121
@@ -138,6 +180,7 @@ bool Interface::refresh(){
138 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName)); 180 QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
139 // If there is no DHCP information then exit now with no errors. 181 // If there is no DHCP information then exit now with no errors.
140 if(!QFile::exists(dhcpFile)){ 182 if(!QFile::exists(dhcpFile)){
183 emit(updateInterface(this));
141 return true; 184 return true;
142 } 185 }
143 186
@@ -235,6 +278,8 @@ bool Interface::refresh(){
235 leaseExpires = datetime.toString(); 278 leaseExpires = datetime.toString();
236 279
237 dhcp = true; 280 dhcp = true;
281
282 emit(updateInterface(this));
238 return true; 283 return true;
239} 284}
240 285