Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Commit

Permalink
Finished network details
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroHLC committed Oct 5, 2019
1 parent 29216b2 commit d4325e4
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 14 deletions.
1 change: 1 addition & 0 deletions qml/MainContainer.qml
Expand Up @@ -79,4 +79,5 @@ Rectangle {
KeyboardPicker { id: keyboardPicker }
NetworkUp { id: networkUp }
WifiMenu { id: wifiMenu }
EthernetMenu { id: ethMenu }
}
11 changes: 10 additions & 1 deletion qml/NetworkUp.qml
Expand Up @@ -51,9 +51,18 @@ Component {
anchors.horizontalCenter: parent.horizontalCenter

Button {
text: qsTr('Configure Internet Address')
text: qsTr('Configure Ethernet')
onClicked: contentStack.push(ethMenu)
}
}

Row {
anchors.horizontalCenter: parent.horizontalCenter

Text {
text: qsTr('* In both options you\'ll find a form that will be used for generating a netctl profile,\nthis profile can be manually edited before starting it.')
}
}
}
}

Expand Down
49 changes: 46 additions & 3 deletions qml/WifiMenu.qml
Expand Up @@ -19,7 +19,7 @@ Component {
apPicker.currentIndex = 0;
}

onWifiCardsChanged: {
onCardsChanged: {
wifiIfacePicker.currentIndex = 0;
}
}
Expand Down Expand Up @@ -78,7 +78,46 @@ Component {
TextField {
placeholderText: qsTr('WPA2 personal password only')
passwordCharacter: "*"
echoMode: TextInput.Password
echoMode: TextInput.PasswordEchoOnEdit
onEditingFinished: net.setWifiPassword(text)
text: net.wifiPassword
}
}
}

Row {
Button {
text: qsTr('Generate profile')
onClicked: net.genWifiProfile();
}
}

Row {
id: wifiProfileTextView
width: 480
height: 90
ScrollView {
anchors.top: parent.top
width: parent.width
height: parent.height
clip: true

contentWidth: wifiProfileText.width
contentHeight: wifiProfileText.height

ScrollBar.vertical: ScrollBar {
policy: ScrollBar.AlwaysOn;
parent: wifiProfileTextView
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
}

TextArea {
id: wifiProfileText
text: net.wifiProfile
width: parent.width
onEditingFinished: net.setWifiProfile(text)
}
}
}
Expand All @@ -103,8 +142,12 @@ Component {

Column {
Button {
text: qsTr('View script && Apply')
text: qsTr('Apply')
highlighted: true
onClicked: {
net.applyWifiProfile();
contentStack.pop();
}
}
}
}
Expand Down
90 changes: 87 additions & 3 deletions src/lib/network.cpp
Expand Up @@ -9,7 +9,7 @@ Network::Network(QObject *parent) : QObject (parent) {
}

bool Network::getAvailability() {
return false;
return QProcess::execute("wget -q --spider http://google.com") == 0;
}

bool Network::getWifiCardsExists() {
Expand All @@ -32,6 +32,18 @@ QString Network::getWifiIface() {
return wifiIface;
}

QString Network::getWifiProfile() {
return wifiProfile;
}

QString Network::getEthProfile() {
return ethProfile;
}

QString Network::getWifiPassword() {
return wifiPsw;
}

QDir Network::interfacesDir = QDir(QStringLiteral("/sys/class/net"));

void Network::loadCards() {
Expand All @@ -52,8 +64,11 @@ void Network::loadCards() {

if(wifiCardsCache.size() >= 1)
setWifiIface(0);

if(cardsCache.size() >= 1)
setEthIface(0);

emit wifiCardsChanged();
emit cardsChanged();
}

void Network::scanWifi() {
Expand Down Expand Up @@ -89,4 +104,73 @@ void Network::setWifiIface(int iface_i) {
void Network::setWifiAP(int ap_i) {
wifiSSID = wifiAPs.at(ap_i);
qDebug() << "User selected " << wifiSSID;
}
}

void Network::setWifiPassword(QString psw) {
wifiPsw = psw;
qDebug() << QString("%1 characters password was entered.").arg(psw.size());

emit wifiPasswordChanged();
}

void Network::setWifiProfile(QString profile) {
wifiProfile = profile;

emit wifiProfileChanged();
}

void Network::genWifiProfile() {
wifiProfile = QString("Interface=%1\n"
"Connection=wireless\n"
"Security=wpa\n"
"IP=dhcp\n"
"ESSID='%2'\n"
"Key=\"%3\"\n"
).arg(wifiIface).arg(wifiSSID).arg(wifiPsw);

emit wifiProfileChanged();
}

void Network::applyWifiProfile() {
if (wifiProfile.size() < 1)
genWifiProfile();
applyProfile(wifiProfile);
}

void Network::applyProfile(QString profileData) {
QProcess::execute(QStringLiteral("netctl stop-all"));

QFile proFile("/etc/netctl/chaotic-setup");
proFile.write(profileData.toUtf8());
proFile.close();

QProcess::execute(QStringLiteral("netctl start chaotic-setup"));

emit availabilityChanged();
}

void Network::setEthIface(int iface_i) {
ethIface = cardsCache.at(iface_i);
}

void Network::setEthProfile(QString profile) {
ethProfile = profile;

emit ethProfileChanged();
}

void Network::genEthProfile() {
ethProfile = QString("Interface=%1\n"
"Connection=ethernet\n"
"IP=dhcp\n"
).arg(ethIface);

emit ethProfileChanged();
}

void Network::applyEthProfile() {
if (ethProfile.size() < 1)
genEthProfile();
applyProfile(ethProfile);
}

36 changes: 29 additions & 7 deletions src/lib/network.hpp
Expand Up @@ -7,11 +7,13 @@
class Network : public QObject {
Q_OBJECT
Q_PROPERTY(bool available READ getAvailability NOTIFY availabilityChanged)
Q_PROPERTY(bool wifiCardExists READ getWifiCardsExists NOTIFY wifiCardsChanged)
Q_PROPERTY(QStringList wifiCards READ getWifiCards NOTIFY wifiCardsChanged)
Q_PROPERTY(bool wifiCardExists READ getWifiCardsExists NOTIFY cardsChanged)
Q_PROPERTY(QStringList cards READ getCards NOTIFY cardsChanged)
Q_PROPERTY(QStringList wifiCards READ getWifiCards NOTIFY cardsChanged)
Q_PROPERTY(QStringList wifiAPs READ getWifiAPs NOTIFY wifiAPsChanged)
//Q_PROPERTY(QString selectedWifiIface READ getWifiIface WRITE setWifiIface NOTIFY wifiCardsChanged)
//Q_PROPERTY(QString selectedWifiAP READ getWifiSSID WRITE setWifiAP NOTIFY wifiAPsChanged)
Q_PROPERTY(QString wifiPassword READ getWifiPassword WRITE setWifiPassword NOTIFY wifiPasswordChanged)
Q_PROPERTY(QString wifiProfile READ getWifiProfile WRITE setWifiProfile NOTIFY wifiProfileChanged)
Q_PROPERTY(QString ethProfile READ getEthProfile WRITE setEthProfile NOTIFY ethProfileChanged)

private:
static QDir interfacesDir;
Expand All @@ -20,6 +22,12 @@ class Network : public QObject {
QStringList wifiAPs;
QString wifiIface;
QString wifiSSID;
QString wifiPsw;
QString wifiProfile;
QString ethIface;
QString ethProfile;

void applyProfile(QString);

public:
explicit Network(QObject *parent = nullptr);
Expand All @@ -31,17 +39,31 @@ class Network : public QObject {
QStringList getWifiCards();
QStringList getCards();
QString getWifiIface();
QString getWifiPassword();
QString getWifiProfile();
QString getEthIface();
QString getEthProfile();

void loadCards();

Q_INVOKABLE void loadCards();
Q_INVOKABLE void scanWifi();
Q_INVOKABLE void setWifiAP(int ap_i);
Q_INVOKABLE void setWifiIface(int iface_i);
Q_INVOKABLE void setWifiPassword(QString password);
Q_INVOKABLE void setWifiProfile(QString script);
Q_INVOKABLE void genWifiProfile();
Q_INVOKABLE void applyWifiProfile();
Q_INVOKABLE void setEthIface(int iface_i);
Q_INVOKABLE void setEthProfile(QString script);
Q_INVOKABLE void genEthProfile();
Q_INVOKABLE void applyEthProfile();

signals:
void availabilityChanged();
void cardsChanged();
void wifiAPsChanged();
void wifiCardsChanged();
void wifiPasswordChanged();
void wifiProfileChanged();
void ethProfileChanged();
};

#endif // NETWORK_H

0 comments on commit d4325e4

Please sign in to comment.