summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/interface.cpp
Side-by-side diff
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
@@ -8,57 +8,98 @@
#define IFCONFIG "/sbin/ifconfig"
#define HDCP_INFO_DIR "/etc/dhcpc"
#include <stdio.h>
#include <stdlib.h>
-Interface::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){
+Interface::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){
refresh();
}
/**
+ * Set status
+ * @param newStatus - the new status
+ * emit updateInterface
+ */
+void Interface::setStatus(bool newStatus){
+ if(status != newStatus){
+ status = newStatus;
+ refresh();
+ }
+};
+
+/**
+ * Set if attached or not (802.11 card pulled out for example)
+ * @param isAttached - if attached
+ * emit updateInterface
+ */
+void Interface::setAttached(bool isAttached){
+ attached = isAttached;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Hardware name
+ * @param name - the new name
+ * emit updateInterface
+ */
+void Interface::setHardwareName(QString name){
+ hardareName = name;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Module owner
+ * @param owner - the new owner
+ * emit updateInterface
+ */
+void Interface::setModuleOwner(Module *owner){
+ moduleOwner = owner;
+ emit(updateInterface(this));
+};
+
+
+/**
* Try to start the interface.
- * @return bool true if successfull.
*/
-bool Interface::start(){
+void Interface::start(){
// check to see if we are already running.
- if(status)
- return false;
+ if(true == status)
+ return;
int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
+ // See if it was successfull...
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
/**
* Try to stop the interface.
- * @return bool true if successfull.
*/
-bool Interface::stop(){
+void Interface::stop(){
// check to see if we are already stopped.
- if(status == false)
- return false;
+ if(false == status)
+ return;
int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
+
/**
* Try to restart the interface.
- * @return bool true if successfull.
*/
-bool Interface::restart(){
- return (stop() && start());
+void Interface::restart(){
+ stop();
+ start();
}
/**
* Try to refresh the information about the interface.
* First call ifconfig, then check the dhcp-info file
* @return bool true if successfull.
@@ -71,12 +112,13 @@ bool Interface::refresh(){
subnetMask = "0.0.0.0";
broadcast = "";
dhcp = false;
dhcpServerIp = "";
leaseObtained = "";
leaseExpires = "";
+ emit(updateInterface(this));
return true;
}
QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName);
int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1());
if(ret != 0){
@@ -135,12 +177,13 @@ bool Interface::refresh(){
dhcpDirectory = "/var/run";
// See if we have
QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
// If there is no DHCP information then exit now with no errors.
if(!QFile::exists(dhcpFile)){
+ emit(updateInterface(this));
return true;
}
file.setName(dhcpFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
@@ -232,11 +275,13 @@ bool Interface::refresh(){
// Calculate the start and renew times
datetime = datetime.addSecs(leaseTime);
leaseExpires = datetime.toString();
dhcp = true;
+
+ emit(updateInterface(this));
return true;
}
// interface.cpp