|
@@ -12,6 +12,8 @@
|
|
|
NetInterfaces::NetInterfaces(QObject *pParent) : QObject(pParent)
|
|
|
{
|
|
|
setObjectName("NetInterfaces");
|
|
|
+ m_itfFilterAF = Interface::AF_Inet;
|
|
|
+ m_itfFilterMethod = Interface::IM_Static;
|
|
|
}
|
|
|
|
|
|
NetInterfaces::~NetInterfaces(void)
|
|
@@ -25,32 +27,50 @@ void NetInterfaces::classBegin()
|
|
|
|
|
|
void NetInterfaces::componentComplete()
|
|
|
{
|
|
|
+ if(!initialize())
|
|
|
+ emitError("NetInterfaces::initialize failed!");
|
|
|
}
|
|
|
|
|
|
void NetInterfaces::reset(void)
|
|
|
{
|
|
|
- for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
|
|
|
+/* for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
|
|
|
{
|
|
|
Interface *pi = *it;
|
|
|
delete pi;
|
|
|
}
|
|
|
|
|
|
- m_itfList.clear();
|
|
|
+ m_itfList.clear();*/
|
|
|
+
|
|
|
+ Interface *pItf;
|
|
|
+
|
|
|
+ for(int i = 0; i < m_interfaces.count(); i++)
|
|
|
+ {
|
|
|
+ if((pItf = m_interfaces.at(i)))
|
|
|
+ delete pItf;
|
|
|
+ }
|
|
|
+ m_interfaces.clear();
|
|
|
+ emit interfaces_Changed();
|
|
|
+
|
|
|
m_eni._reset();
|
|
|
}
|
|
|
|
|
|
bool NetInterfaces::initialize(void)
|
|
|
{
|
|
|
- bool bRet = false;
|
|
|
+ bool bRet;
|
|
|
reset();
|
|
|
+
|
|
|
if((bRet = ::ParseEtcNetworkInterfaces(m_eni)))
|
|
|
{
|
|
|
for(auto it = m_eni.ibl.begin(); it != m_eni.ibl.end(); it++)
|
|
|
{
|
|
|
ITF_IFACE_BLOCK &ibl = *it;
|
|
|
- m_itfList.push_back(new Interface(ibl, static_cast<const Emitter&>(*this), this));
|
|
|
+ m_interfaces.append(new Interface(ibl, static_cast<const Emitter&>(*this), this));
|
|
|
+// m_itfList.push_back(new Interface(ibl, static_cast<const Emitter&>(*this), this));
|
|
|
}
|
|
|
+
|
|
|
+ emit interfaces_Changed();
|
|
|
}
|
|
|
+
|
|
|
return bRet;
|
|
|
}
|
|
|
|
|
@@ -59,15 +79,12 @@ bool NetInterfaces::save(void)
|
|
|
return ::WriteEtcNetworkInterfaces(m_eni, NULL);
|
|
|
}
|
|
|
|
|
|
-bool NetInterfaces::save(QString path)
|
|
|
+bool NetInterfaces::saveAs(const QString &path)
|
|
|
{
|
|
|
- std::string p;
|
|
|
- const char *pszPath = NULL;
|
|
|
- if(path.length() > 0)
|
|
|
- {
|
|
|
- p = path.toStdString();
|
|
|
- pszPath = p.c_str();
|
|
|
- }
|
|
|
+ if(!path.length())
|
|
|
+ return false;
|
|
|
+ std::string p = path.toStdString();
|
|
|
+ const char *pszPath = p.c_str();
|
|
|
return ::WriteEtcNetworkInterfaces(m_eni, pszPath);
|
|
|
}
|
|
|
|
|
@@ -87,9 +104,11 @@ QVariantList NetInterfaces::getInterface(const QString &itfName)
|
|
|
|
|
|
if(m_eni.ibl.size() > 0)
|
|
|
{
|
|
|
- for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
|
|
|
+// for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
|
|
|
+ for(int i = 0; i < m_interfaces.count(); i++)
|
|
|
{
|
|
|
- Interface *pi = *it;
|
|
|
+ Interface *pi = m_interfaces.at(i);
|
|
|
+// Interface *pi = *it;
|
|
|
const ITF_IFACE_BLOCK &ibl = pi->getIface();
|
|
|
|
|
|
if( itfName == ibl.cfgName.c_str() &&
|
|
@@ -105,6 +124,104 @@ QVariantList NetInterfaces::getInterface(const QString &itfName)
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+QVariant NetInterfaces::newInterface(QString name, int af, int method, QString cfg)
|
|
|
+{
|
|
|
+ m_eni.ibl.emplace_back();
|
|
|
+ ITF_IFACE_BLOCK &rib = m_eni.ibl.back();
|
|
|
+ rib.cfgName = name.toStdString();
|
|
|
+ rib.proto = (IfaceProtos)af;
|
|
|
+ rib.method = (IfaceMethods)method;
|
|
|
+ Interface *pi = new Interface(rib, static_cast<const Emitter&>(*this), this);
|
|
|
+
|
|
|
+ m_interfaces.append(pi);
|
|
|
+ emit interfaces_Changed();
|
|
|
+
|
|
|
+// m_itfList.push_back(pi);
|
|
|
+ return QVariant::fromValue(pi);
|
|
|
+}
|
|
|
+
|
|
|
+QQmlListProperty<Interface> NetInterfaces::interfaces(void)
|
|
|
+{
|
|
|
+ return QQmlListProperty<Interface>(this, m_interfaces);
|
|
|
+}
|
|
|
+
|
|
|
+QQmlListProperty<Interface> NetInterfaces::filteredInterfaces(void)
|
|
|
+{
|
|
|
+ m_filteredInterfaces.clear();
|
|
|
+
|
|
|
+ for(int i = 0; i < m_interfaces.count(); i++)
|
|
|
+ {
|
|
|
+ Interface *pi = m_interfaces.at(i);
|
|
|
+ const ITF_IFACE_BLOCK &ibl = pi->getIface();
|
|
|
+
|
|
|
+ if( m_itfFilterName == ibl.cfgName.c_str() &&
|
|
|
+ (int)ibl.proto == m_itfFilterAF &&
|
|
|
+ (int)ibl.method == m_itfFilterMethod)
|
|
|
+ {
|
|
|
+ m_filteredInterfaces.append(pi);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return QQmlListProperty<Interface>(this, m_filteredInterfaces);
|
|
|
+}
|
|
|
+
|
|
|
+const QString& NetInterfaces::itfFilterName(void) const
|
|
|
+{
|
|
|
+ return m_itfFilterName;
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::set_itfFilterName(const QString &val)
|
|
|
+{
|
|
|
+ if(val != m_itfFilterName)
|
|
|
+ {
|
|
|
+ m_itfFilterName = val;
|
|
|
+ emit itfFilterName_Changed(m_itfFilterName);
|
|
|
+ emit filteredInterfaces_Changed();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int NetInterfaces::itfFilterAF(void) const
|
|
|
+{
|
|
|
+ return m_itfFilterAF;
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::set_itfFilterAF(int af)
|
|
|
+{
|
|
|
+ if(af <= Interface::AF_Unknown || af >= Interface::AF_Invalid)
|
|
|
+ {
|
|
|
+ emitError("Invalid address family filter: %d!", af);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(m_itfFilterAF != af)
|
|
|
+ {
|
|
|
+ m_itfFilterAF = af;
|
|
|
+ emit itfFilterAF_Changed(af);
|
|
|
+ emit filteredInterfaces_Changed();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+int NetInterfaces::itfFilterMethod(void) const
|
|
|
+{
|
|
|
+ return m_itfFilterMethod;
|
|
|
+}
|
|
|
+
|
|
|
+void NetInterfaces::set_itfFilterMethod(int method)
|
|
|
+{
|
|
|
+ if(method <= Interface::IM_Unknown || method >= Interface::IM_Invalid)
|
|
|
+ {
|
|
|
+ emitError("Invalid method filter: %d!", method);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(m_itfFilterMethod != method)
|
|
|
+ {
|
|
|
+ m_itfFilterMethod = method;
|
|
|
+ emit itfFilterMethod_Changed(method);
|
|
|
+ emit filteredInterfaces_Changed();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
Interface::Interface(ITF_IFACE_BLOCK &ifb, const Emitter &errHandler, QObject *pParent) : QObject(pParent),
|
|
@@ -161,11 +278,21 @@ QString Interface::family(void) const
|
|
|
return ::GetIfaceProtoStr(m_ifb.proto);
|
|
|
}
|
|
|
|
|
|
+int Interface::af(void) const
|
|
|
+{
|
|
|
+ return (int)m_ifb.proto;
|
|
|
+}
|
|
|
+
|
|
|
QString Interface::method(void) const
|
|
|
{
|
|
|
return ::GetIfaceMethodStr(m_ifb.method);
|
|
|
}
|
|
|
|
|
|
+int Interface::itfMethod(void) const
|
|
|
+{
|
|
|
+ return (int)m_ifb.method;
|
|
|
+}
|
|
|
+
|
|
|
IPv4Address* Interface::ipAddress(void)
|
|
|
{
|
|
|
return &m_ipAddr;
|
|
@@ -226,6 +353,7 @@ QString Interface::dns3(void) const
|
|
|
|
|
|
IPv4Address::IPv4Address(struct in_addr &addr, const Emitter &errHandler, QObject *pParent) : QObject(pParent), m_addr(addr), m_errHandler(errHandler)
|
|
|
{
|
|
|
+ setObjectName("IPv4Address");
|
|
|
}
|
|
|
|
|
|
IPv4Address::~IPv4Address(void)
|