Merge pull request #142 from mammonsama666/0522-dev
feat(log): Add log file.
This commit is contained in:
commit
a058591a12
|
@ -218,6 +218,7 @@ void BackThread::execConnLan(QString connName, QString ifname, QString connectTy
|
||||||
} else {
|
} else {
|
||||||
mycmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + ifname + "'";
|
mycmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + ifname + "'";
|
||||||
}
|
}
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<connName;
|
||||||
|
|
||||||
if (isWiredCableAlready) {
|
if (isWiredCableAlready) {
|
||||||
QStringList options;
|
QStringList options;
|
||||||
|
@ -375,6 +376,7 @@ void BackThread::execConnRememberedHiddenWifi(QString wifiName)
|
||||||
}
|
}
|
||||||
if (! is_hidden) {
|
if (! is_hidden) {
|
||||||
QString cmd = "nmcli connection up '" + wifiName + "'";
|
QString cmd = "nmcli connection up '" + wifiName + "'";
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<wifiName;
|
||||||
int res = Utils::m_system(cmd.toUtf8().data());
|
int res = Utils::m_system(cmd.toUtf8().data());
|
||||||
if (res == 0) {
|
if (res == 0) {
|
||||||
emit connDone(6);
|
emit connDone(6);
|
||||||
|
@ -413,6 +415,7 @@ void BackThread::execConnWifi(QString connName, QString connIfName)
|
||||||
//qDebug() << "-------------------------> connName = " << connName;
|
//qDebug() << "-------------------------> connName = " << connName;
|
||||||
cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + connIfName + "'\n";
|
cmdStr = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "' ifname '" + connIfName + "'\n";
|
||||||
}
|
}
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<connName;
|
||||||
|
|
||||||
QStringList options;
|
QStringList options;
|
||||||
options << "-c" << cmdStr;
|
options << "-c" << cmdStr;
|
||||||
|
@ -427,6 +430,7 @@ void BackThread::execReconnWIfi(QString uuid)
|
||||||
Utils::m_system(cmd.toUtf8().data());
|
Utils::m_system(cmd.toUtf8().data());
|
||||||
cmd = "nmcli connection up " + uuid;
|
cmd = "nmcli connection up " + uuid;
|
||||||
Utils::m_system(cmd.toUtf8().data());
|
Utils::m_system(cmd.toUtf8().data());
|
||||||
|
qDebug()<<"Trying to connect wifi. uuid="<<uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackThread::onReadOutputWifi()
|
void BackThread::onReadOutputWifi()
|
||||||
|
|
47
src/main.cpp
47
src/main.cpp
|
@ -27,15 +27,62 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
#include <syslog.h>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
#define LOG_IDENT "ukui_kylin_nm"
|
#define LOG_IDENT "ukui_kylin_nm"
|
||||||
|
|
||||||
|
void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
|
{
|
||||||
|
QByteArray localMsg = msg.toLocal8Bit();
|
||||||
|
QByteArray currentTime = QTime::currentTime().toString().toLocal8Bit();
|
||||||
|
|
||||||
|
bool showDebug = true;
|
||||||
|
QString logFilePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/ukui/kylin-nm.log";
|
||||||
|
//若不需要自动创建日志文件,请放开此注释
|
||||||
|
// if (!QFile::exists(logFilePath)) {
|
||||||
|
// showDebug = false;
|
||||||
|
// }
|
||||||
|
FILE *log_file = nullptr;
|
||||||
|
|
||||||
|
if (showDebug) {
|
||||||
|
log_file = fopen(logFilePath.toLocal8Bit().constData(), "a+");
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *file = context.file ? context.file : "";
|
||||||
|
const char *function = context.function ? context.function : "";
|
||||||
|
switch (type) {
|
||||||
|
case QtDebugMsg:
|
||||||
|
if (!log_file) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(log_file, "Debug: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function);
|
||||||
|
break;
|
||||||
|
case QtInfoMsg:
|
||||||
|
fprintf(log_file? log_file: stdout, "Info: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function);
|
||||||
|
break;
|
||||||
|
case QtWarningMsg:
|
||||||
|
fprintf(log_file? log_file: stderr, "Warning: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function);
|
||||||
|
break;
|
||||||
|
case QtCriticalMsg:
|
||||||
|
fprintf(log_file? log_file: stderr, "Critical: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function);
|
||||||
|
break;
|
||||||
|
case QtFatalMsg:
|
||||||
|
fprintf(log_file? log_file: stderr, "Fatal: %s: %s (%s:%u, %s)\n", currentTime.constData(), localMsg.constData(), file, context.line, function);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log_file)
|
||||||
|
fclose(log_file);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
qInstallMessageHandler(messageOutput);
|
||||||
|
|
||||||
openlog(LOG_IDENT, LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_USER);
|
openlog(LOG_IDENT, LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_USER);
|
||||||
syslog(LOG_DEBUG, "Kylin Network Manager Is Already Launched");
|
syslog(LOG_DEBUG, "Kylin Network Manager Is Already Launched");
|
||||||
|
|
|
@ -1802,6 +1802,7 @@ void MainWindow::getWifiListDone(QStringList slist)
|
||||||
int mdf_res = system(modifyCmd.toUtf8().data());
|
int mdf_res = system(modifyCmd.toUtf8().data());
|
||||||
qDebug()<<"Modification finished, cmd = "<<modifyCmd<<". res = "<<mdf_res;
|
qDebug()<<"Modification finished, cmd = "<<modifyCmd<<". res = "<<mdf_res;
|
||||||
QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\"";
|
QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\"";
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<wifiSsid;
|
||||||
int con_res = system(reconnectWifiCmd.toUtf8().data());
|
int con_res = system(reconnectWifiCmd.toUtf8().data());
|
||||||
qDebug()<<"Reconnect finished, cmd = "<<reconnectWifiCmd<<". res = "<<con_res;
|
qDebug()<<"Reconnect finished, cmd = "<<reconnectWifiCmd<<". res = "<<con_res;
|
||||||
emit this->stopReconnectWifi(wifiSsid);
|
emit this->stopReconnectWifi(wifiSsid);
|
||||||
|
@ -2254,7 +2255,7 @@ QVector<structWifiProperty> MainWindow::connectableWifiPriorityList(const QStrin
|
||||||
QString wifiname = line.mid(indexName).trimmed();
|
QString wifiname = line.mid(indexName).trimmed();
|
||||||
QString wifibssid = line.mid(indexBSsid, indexPath-indexBSsid).trimmed();
|
QString wifibssid = line.mid(indexBSsid, indexPath-indexBSsid).trimmed();
|
||||||
QString wifiObjectPath;
|
QString wifiObjectPath;
|
||||||
if (indexCate) {
|
if (indexCate >= 0) {
|
||||||
wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed();
|
wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed();
|
||||||
} else {
|
} else {
|
||||||
wifiObjectPath = line.mid(indexPath,indexName-indexPath).trimmed();
|
wifiObjectPath = line.mid(indexPath,indexName-indexPath).trimmed();
|
||||||
|
@ -2487,12 +2488,11 @@ void MainWindow::loadWifiListDone(QStringList slist)
|
||||||
wcate = line.mid(indexCate, 1).trimmed();
|
wcate = line.mid(indexCate, 1).trimmed();
|
||||||
else
|
else
|
||||||
wcate = QString::number(0);
|
wcate = QString::number(0);
|
||||||
int Path = line.indexOf("/org/");
|
|
||||||
QString wDbusPath;
|
QString wDbusPath;
|
||||||
if (indexCate >= 0) {
|
if (indexCate >= 0) {
|
||||||
wDbusPath = line.mid(Path,indexCate-Path).trimmed();
|
wDbusPath = line.mid(indexPath,indexCate-indexPath).trimmed();
|
||||||
} else {
|
} else {
|
||||||
wDbusPath = line.mid(Path,indexName-Path).trimmed();
|
wDbusPath = line.mid(indexPath,indexName-indexPath).trimmed();
|
||||||
}
|
}
|
||||||
QDBusInterface interface("org.freedesktop.NetworkManager",
|
QDBusInterface interface("org.freedesktop.NetworkManager",
|
||||||
wDbusPath,
|
wDbusPath,
|
||||||
|
@ -2525,13 +2525,11 @@ void MainWindow::loadWifiListDone(QStringList slist)
|
||||||
int max_freq = wfreq.toInt();
|
int max_freq = wfreq.toInt();
|
||||||
int min_freq = wfreq.toInt();
|
int min_freq = wfreq.toInt();
|
||||||
for (int k = i; k < slist.size(); k ++) {
|
for (int k = i; k < slist.size(); k ++) {
|
||||||
QString tmpLine = slist.at(k);
|
|
||||||
int Path = tmpLine.indexOf("/org/");
|
|
||||||
QString m_DbusPath;
|
QString m_DbusPath;
|
||||||
if (indexCate >= 0) {
|
if (indexCate >= 0) {
|
||||||
m_DbusPath = line.mid(Path,indexCate-Path).trimmed();
|
m_DbusPath = slist.at(k).mid(indexPath,indexCate-indexPath).trimmed();
|
||||||
} else {
|
} else {
|
||||||
m_DbusPath = line.mid(Path,indexName-Path).trimmed();
|
m_DbusPath = slist.at(k).mid(indexPath,indexName-indexPath).trimmed();
|
||||||
}
|
}
|
||||||
QDBusInterface m_interface("org.freedesktop.NetworkManager",
|
QDBusInterface m_interface("org.freedesktop.NetworkManager",
|
||||||
m_DbusPath,
|
m_DbusPath,
|
||||||
|
@ -2548,7 +2546,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qDebug()<<"Wifi ssid="<<wname<<". max_freq="<<max_freq<<". min_freq="<<min_freq;
|
||||||
int freqState = 0;
|
int freqState = 0;
|
||||||
if (max_freq < 3000) {
|
if (max_freq < 3000) {
|
||||||
//只有2.4GHZ
|
//只有2.4GHZ
|
||||||
|
@ -2801,7 +2799,7 @@ void MainWindow::updateWifiListDone(QStringList slist)
|
||||||
QString wname = line.mid(indexName).trimmed();
|
QString wname = line.mid(indexName).trimmed();
|
||||||
QString wfreq = line.mid(indexFreq, 4).trimmed();
|
QString wfreq = line.mid(indexFreq, 4).trimmed();
|
||||||
QString wpath;
|
QString wpath;
|
||||||
if (indexCate) {
|
if (indexCate >= 0) {
|
||||||
wpath = line.mid(indexPath, indexCate - indexPath).trimmed();
|
wpath = line.mid(indexPath, indexCate - indexPath).trimmed();
|
||||||
} else {
|
} else {
|
||||||
wpath = line.mid(indexPath, indexName - indexPath).trimmed();
|
wpath = line.mid(indexPath, indexName - indexPath).trimmed();
|
||||||
|
@ -2831,6 +2829,7 @@ void MainWindow::updateWifiListDone(QStringList slist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug()<<"Wifi ssid="<<wname<<". max_freq="<<max_freq<<". min_freq="<<min_freq;
|
||||||
int freqState = 0;
|
int freqState = 0;
|
||||||
if (max_freq < 3000) {
|
if (max_freq < 3000) {
|
||||||
//只有2.4GHZ
|
//只有2.4GHZ
|
||||||
|
@ -3992,6 +3991,7 @@ void MainWindow::connWifiDone(int connFlag)
|
||||||
// Wifi连接结果,0点击连接成功 1失败 2没有配置文件 3开机启动网络工具时已经连接 4密码错误 5找不到已保存的网络
|
// Wifi连接结果,0点击连接成功 1失败 2没有配置文件 3开机启动网络工具时已经连接 4密码错误 5找不到已保存的网络
|
||||||
if (connFlag == 0) {
|
if (connFlag == 0) {
|
||||||
syslog(LOG_DEBUG, "Wi-Fi already connected by clicking button");
|
syslog(LOG_DEBUG, "Wi-Fi already connected by clicking button");
|
||||||
|
qDebug()<<"Wi-Fi connected succeed. res=0";
|
||||||
if (!isHuaWeiPC) {
|
if (!isHuaWeiPC) {
|
||||||
//如果不是华为电脑,使用获取连接信号的方式更新列表
|
//如果不是华为电脑,使用获取连接信号的方式更新列表
|
||||||
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
|
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
|
||||||
|
@ -4005,6 +4005,7 @@ void MainWindow::connWifiDone(int connFlag)
|
||||||
objKyDBus->showDesktopNotify(txt);
|
objKyDBus->showDesktopNotify(txt);
|
||||||
} else if (connFlag == 1) {
|
} else if (connFlag == 1) {
|
||||||
syslog(LOG_DEBUG, "Confirm your Wi-Fi password or usable of wireless card");
|
syslog(LOG_DEBUG, "Confirm your Wi-Fi password or usable of wireless card");
|
||||||
|
qWarning()<<"Wi-Fi connected failed. res=1";
|
||||||
//is_stop_check_net_state = 0;
|
//is_stop_check_net_state = 0;
|
||||||
is_connect_net_failed = 1;
|
is_connect_net_failed = 1;
|
||||||
is_connect_hide_wifi = 0;
|
is_connect_hide_wifi = 0;
|
||||||
|
@ -4012,20 +4013,24 @@ void MainWindow::connWifiDone(int connFlag)
|
||||||
objKyDBus->showDesktopNotify(txt);
|
objKyDBus->showDesktopNotify(txt);
|
||||||
} else if (connFlag == 3) {
|
} else if (connFlag == 3) {
|
||||||
syslog(LOG_DEBUG, "Launch kylin-nm, Wi-Fi already connected");
|
syslog(LOG_DEBUG, "Launch kylin-nm, Wi-Fi already connected");
|
||||||
|
qWarning()<<"Wi-Fi connected failed. res=3";
|
||||||
} else if (connFlag == 4) {
|
} else if (connFlag == 4) {
|
||||||
syslog(LOG_DEBUG, "Confirm your Wi-Fi password");
|
syslog(LOG_DEBUG, "Confirm your Wi-Fi password");
|
||||||
is_connect_net_failed = 1;
|
is_connect_net_failed = 1;
|
||||||
QString txt(tr("Confirm your Wi-Fi password"));
|
QString txt(tr("Confirm your Wi-Fi password"));
|
||||||
|
qWarning()<<"Wi-Fi connected failed. res=4";
|
||||||
objKyDBus->showDesktopNotify(txt);
|
objKyDBus->showDesktopNotify(txt);
|
||||||
} else if (connFlag == 5) {
|
} else if (connFlag == 5) {
|
||||||
syslog(LOG_DEBUG, "Selected Wifi has not been scanned.");
|
syslog(LOG_DEBUG, "Selected Wifi has not been scanned.");
|
||||||
is_connect_net_failed = 1;
|
is_connect_net_failed = 1;
|
||||||
QString txt(tr("Selected Wifi has not been scanned."));
|
QString txt(tr("Selected Wifi has not been scanned."));
|
||||||
|
qWarning()<<"Wi-Fi connected failed. res=5";
|
||||||
objKyDBus->showDesktopNotify(txt);
|
objKyDBus->showDesktopNotify(txt);
|
||||||
} else if (connFlag == 6) {
|
} else if (connFlag == 6) {
|
||||||
syslog(LOG_DEBUG, "Connect Hidden Wifi Success.");
|
syslog(LOG_DEBUG, "Connect Hidden Wifi Success.");
|
||||||
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
|
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
|
||||||
QString txt(tr("Connect Hidden Wifi Success"));
|
QString txt(tr("Connect Hidden Wifi Success"));
|
||||||
|
qWarning()<<"Wi-Fi connected failed. res=6";
|
||||||
objKyDBus->showDesktopNotify(txt);
|
objKyDBus->showDesktopNotify(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -732,6 +732,7 @@ void OneConnForm::toConnectWirelessNetwork()
|
||||||
connect(t, &QThread::started, this, [ = ]() {
|
connect(t, &QThread::started, this, [ = ]() {
|
||||||
this->startWifiWaiting(true);
|
this->startWifiWaiting(true);
|
||||||
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
|
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<wifiName;
|
||||||
emit this->sigConnWifiPsk(cmdStr);
|
emit this->sigConnWifiPsk(cmdStr);
|
||||||
});
|
});
|
||||||
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
|
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
|
||||||
|
@ -790,6 +791,7 @@ void OneConnForm::on_btnConnPWD_clicked()
|
||||||
connect(t, &QThread::started, this, [ = ]() {
|
connect(t, &QThread::started, this, [ = ]() {
|
||||||
this->startWifiWaiting(true);
|
this->startWifiWaiting(true);
|
||||||
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
|
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<wifiName;
|
||||||
emit this->sigConnWifiPsk(cmdStr);
|
emit this->sigConnWifiPsk(cmdStr);
|
||||||
});
|
});
|
||||||
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
|
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
|
||||||
|
@ -983,8 +985,10 @@ void OneConnForm::slotConnWifiResult(int connFlag)
|
||||||
qDebug() << "实际连接的wifi的bssid是 " << wifiBSsid;
|
qDebug() << "实际连接的wifi的bssid是 " << wifiBSsid;
|
||||||
if (currConnWifiBssid != wifiBSsid && !currConnWifiBssid.isEmpty()) {
|
if (currConnWifiBssid != wifiBSsid && !currConnWifiBssid.isEmpty()) {
|
||||||
QString modityCmd = "nmcli connection modify \""+ wifiName + "\" " + "802-11-wireless.bssid " + wifiBSsid;
|
QString modityCmd = "nmcli connection modify \""+ wifiName + "\" " + "802-11-wireless.bssid " + wifiBSsid;
|
||||||
system(modityCmd.toUtf8().data());
|
int res = system(modityCmd.toUtf8().data());
|
||||||
|
qDebug()<<"Modified bssid for wifi. ssid="<<wifiName<<". bssid="<<wifiBSsid<<". res="<<res;
|
||||||
QString reconnectWifiCmd = "nmcli connection up \"" + wifiName + "\"";
|
QString reconnectWifiCmd = "nmcli connection up \"" + wifiName + "\"";
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<wifiName;
|
||||||
system(reconnectWifiCmd.toUtf8().data());
|
system(reconnectWifiCmd.toUtf8().data());
|
||||||
} else {
|
} else {
|
||||||
emit requestRefreshWifiList();
|
emit requestRefreshWifiList();
|
||||||
|
|
|
@ -54,6 +54,7 @@ void UpConnThread::run() {
|
||||||
} else {
|
} else {
|
||||||
cmdStr = "nmcli connection up '" + this->conn_name + "'";
|
cmdStr = "nmcli connection up '" + this->conn_name + "'";
|
||||||
}
|
}
|
||||||
|
qDebug()<<"Trying to connect wifi. ssid="<<this->conn_name;
|
||||||
qDebug()<<"qDebug: 激活连接: \n"<<
|
qDebug()<<"qDebug: 激活连接: \n"<<
|
||||||
"qDebug: " + cmdStr;
|
"qDebug: " + cmdStr;
|
||||||
int res = Utils::m_system(cmdStr.toUtf8().data());
|
int res = Utils::m_system(cmdStr.toUtf8().data());
|
||||||
|
|
Loading…
Reference in New Issue