2019-10-31 09:56:53 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef MAINWINDOW_H
|
|
|
|
|
#define MAINWINDOW_H
|
|
|
|
|
|
|
|
|
|
#include <QMainWindow>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QSystemTrayIcon>
|
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
#include <QScreen>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QAction>
|
2020-02-18 14:01:09 +08:00
|
|
|
|
#include <QWidgetAction>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QPainter>
|
2019-10-31 09:56:53 +08:00
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QTimer>
|
2019-12-12 17:22:17 +08:00
|
|
|
|
#include <QtDBus/QDBusConnection>
|
|
|
|
|
#include <QtDBus/QDBusMessage>
|
|
|
|
|
#include <QtDBus/QDBusInterface>
|
|
|
|
|
#include <QtDBus/QDBusObjectPath>
|
|
|
|
|
#include <QDBusObjectPath>
|
2020-01-09 16:32:16 +08:00
|
|
|
|
#include <QVariant>
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/stat.h>
|
2020-01-09 16:32:16 +08:00
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
|
#include <unistd.h>
|
2019-10-31 09:56:53 +08:00
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
|
|
|
|
|
#include "ksimplenm.h"
|
|
|
|
|
#include "loadingdiv.h"
|
2020-02-18 14:01:09 +08:00
|
|
|
|
#include "networkspeed.h"
|
2020-01-09 16:32:16 +08:00
|
|
|
|
#include "kylin-dbus-interface.h"
|
2019-10-31 09:56:53 +08:00
|
|
|
|
#include "kylin-network-interface.h"
|
|
|
|
|
|
|
|
|
|
class OneConnForm;
|
|
|
|
|
class ConfForm;
|
|
|
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
class MainWindow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MainWindow : public QMainWindow
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
explicit MainWindow(QWidget *parent = 0);
|
|
|
|
|
~MainWindow();
|
|
|
|
|
|
|
|
|
|
void startLoading();
|
|
|
|
|
void stopLoading();
|
|
|
|
|
|
|
|
|
|
void setTrayIcon(QIcon icon);
|
|
|
|
|
void setTrayLoading(bool isLoading);
|
2019-12-04 14:28:52 +08:00
|
|
|
|
|
|
|
|
|
void initTimer();
|
|
|
|
|
void changeTimerState();
|
2019-12-12 19:05:54 +08:00
|
|
|
|
void checkIsWirelessDeviceOn();
|
2019-12-04 14:28:52 +08:00
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
void init_widget_action(QWidget *wid, QString iconstr, QString textstr);
|
|
|
|
|
|
2019-10-31 09:56:53 +08:00
|
|
|
|
QIcon iconLanOnline, iconLanOffline;
|
|
|
|
|
QIcon iconWifiFull, iconWifiHigh, iconWifiMedium, iconWifiLow;
|
|
|
|
|
QIcon iconConnecting;
|
|
|
|
|
QList<QIcon> loadIcons;
|
2020-01-09 16:32:16 +08:00
|
|
|
|
QString mwBandWidth;
|
|
|
|
|
KylinDBus *objKyDBus;
|
2020-02-18 14:01:09 +08:00
|
|
|
|
NetworkSpeed *objNetSpeed;
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
2019-11-29 17:55:39 +08:00
|
|
|
|
//状态设置,0为假,1为真
|
2020-01-09 16:32:16 +08:00
|
|
|
|
int is_update_wifi_list = 0; //是否是update wifi列表,而不是load wifi列表
|
2019-11-29 17:55:39 +08:00
|
|
|
|
int is_by_click_connect = 0; //是否是通过点击连接按钮进行的连接
|
|
|
|
|
int is_btnNetList_clicked = 1; //是否处于有线网界面
|
|
|
|
|
int is_btnWifiList_clicked = 0; //是否处于无线网界面
|
|
|
|
|
int is_wired_line_ready = 1; //主机是否连接网线
|
2019-12-12 17:22:17 +08:00
|
|
|
|
int is_wireless_adapter_ready = 1; //主机是否插入无线网卡
|
2019-12-04 14:28:52 +08:00
|
|
|
|
int is_keep_wifi_turn_on_state = 1; //是否要执行wifi开关变为打开样式
|
2020-01-09 16:32:16 +08:00
|
|
|
|
int is_stop_check_net_state = 0; //是否要在进行其他操作时停止检查网络状态
|
2020-02-18 14:01:09 +08:00
|
|
|
|
int is_fly_mode_on = 0; //是否打开飞行模式
|
|
|
|
|
int is_hot_sopt_on = 0; //是否已经打开热点
|
|
|
|
|
|
|
|
|
|
QString currSelNetName = ""; //当前ScrollArea中选中的网络名称
|
2019-12-12 17:22:17 +08:00
|
|
|
|
|
|
|
|
|
public slots:
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void onPhysicalCarrierChanged(bool flag);
|
|
|
|
|
void onCarrierUpHandle();
|
|
|
|
|
void onCarrierDownHandle();
|
2020-01-13 09:38:25 +08:00
|
|
|
|
void onDeleteLan();
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void onWirelessDeviceAdded(QDBusObjectPath objPath);
|
|
|
|
|
void onWirelessDeviceRemoved(QDBusObjectPath objPath);
|
|
|
|
|
void getLanBandWidth();
|
2019-11-29 17:55:39 +08:00
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
void oneLanFormSelected(QString lanName);
|
|
|
|
|
void oneTopLanFormSelected(QString lanName);
|
|
|
|
|
void oneWifiFormSelected(QString wifiName);
|
|
|
|
|
void oneTopWifiFormSelected(QString wifiName);
|
|
|
|
|
|
|
|
|
|
void on_btnHotspot_clicked();
|
|
|
|
|
void on_btnHotspotState();
|
|
|
|
|
|
2019-10-31 09:56:53 +08:00
|
|
|
|
private:
|
|
|
|
|
void checkSingle();
|
|
|
|
|
void getActiveInfo();
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void initNetwork();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
void createTrayIcon();
|
2020-02-18 14:01:09 +08:00
|
|
|
|
void handleIconClicked();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
bool checkLanOn();
|
|
|
|
|
bool checkWlOn();
|
|
|
|
|
void getLanList();
|
|
|
|
|
void getWifiList();
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void getInitLanSlist();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
Ui::MainWindow *ui;
|
|
|
|
|
|
|
|
|
|
LoadingDiv *loading;
|
|
|
|
|
|
2019-11-29 17:55:39 +08:00
|
|
|
|
QDesktopWidget desktop;
|
2019-10-31 09:56:53 +08:00
|
|
|
|
KSimpleNM *ksnm;
|
|
|
|
|
ConfForm *confForm;
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QWidget *topLanListWidget;
|
|
|
|
|
QWidget *topWifiListWidget;
|
2019-10-31 09:56:53 +08:00
|
|
|
|
QWidget *lanListWidget;
|
|
|
|
|
QWidget *wifiListWidget;
|
|
|
|
|
QWidget *optWifiWidget;
|
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QLabel *lbLoadDown;
|
|
|
|
|
QLabel *lbLoadUp;
|
|
|
|
|
|
2019-10-31 09:56:53 +08:00
|
|
|
|
QScrollArea *scrollAreal, *scrollAreaw;
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QLabel *lbTopLanList, *lbTopWifiList, *lbLanList, *lbWifiList;
|
2020-02-21 08:50:52 +08:00
|
|
|
|
QLabel *lbBb;
|
|
|
|
|
QPushButton *btnAddNet;
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
QSystemTrayIcon *trayIcon;
|
|
|
|
|
QMenu *trayIconMenu;
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QWidgetAction *mShowWindow;
|
|
|
|
|
QWidgetAction *mAdvConf;
|
2020-02-25 18:06:53 +08:00
|
|
|
|
QWidget *widShowWindow;
|
|
|
|
|
QWidget *widAdvConf;
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QString lname, wname; // 以太网卡和无线网卡名称
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QString btnOffQss, btnOnQss, btnBgOffQss, btnBgOnQss; // 主界面按钮底色
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QStringList oldLanSlist; //上一次获取Lan列表
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QStringList oldWifiSlist; //上一次获取wifi列表
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
//循环检测网络连接状态
|
|
|
|
|
QTimer *iconTimer;
|
2020-01-09 16:32:16 +08:00
|
|
|
|
QTimer *wiredCableUpTimer;
|
|
|
|
|
QTimer *wiredCableDownTimer;
|
2020-01-13 09:38:25 +08:00
|
|
|
|
QTimer *deleteLanTimer;
|
2020-01-09 16:32:16 +08:00
|
|
|
|
QTimer *checkWifiListChanged;
|
|
|
|
|
QTimer *checkIfLanConnect;
|
|
|
|
|
QTimer *checkIfWifiConnect;
|
|
|
|
|
QTimer *checkIfNetworkOn;
|
2020-02-18 14:01:09 +08:00
|
|
|
|
QTimer *setNetSpeed;
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
int currentIconIndex;
|
2020-02-18 14:01:09 +08:00
|
|
|
|
int activeWifiSignalLv;
|
|
|
|
|
|
|
|
|
|
long int start_rcv_rates = 0; //保存开始时的流量计数
|
|
|
|
|
long int end_rcv_rates = 0; //保存结束时的流量计数
|
|
|
|
|
long int start_tx_rates = 0; //保存开始时的流量计数
|
|
|
|
|
long int end_tx_rates = 0; //保存结束时的流量计数
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
2020-02-18 14:01:09 +08:00
|
|
|
|
|
2019-10-31 09:56:53 +08:00
|
|
|
|
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
|
|
|
|
|
|
|
|
|
|
void on_btnNet_clicked();
|
|
|
|
|
void on_btnWifi_clicked();
|
|
|
|
|
void on_btnNetList_clicked(int flag=0);
|
|
|
|
|
void on_btnWifiList_clicked();
|
|
|
|
|
|
|
|
|
|
void getLanListDone(QStringList slist);
|
|
|
|
|
void getWifiListDone(QStringList slist);
|
|
|
|
|
void loadWifiListDone(QStringList slist);
|
|
|
|
|
void updateWifiListDone(QStringList slist);
|
|
|
|
|
|
2020-02-18 14:01:09 +08:00
|
|
|
|
void on_showWindowAction();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
void on_btnAdvConf_clicked();
|
|
|
|
|
void on_btnNetList_pressed();
|
|
|
|
|
void on_btnWifiList_pressed();
|
|
|
|
|
|
|
|
|
|
void activeLanDisconn();
|
|
|
|
|
void activeWifiDisconn();
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void activeStartLoading();
|
|
|
|
|
void activeGetWifiList();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
void on_btnAdvConf_pressed();
|
|
|
|
|
void on_btnAdvConf_released();
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void on_checkWifiListChanged();
|
2020-02-18 14:01:09 +08:00
|
|
|
|
void on_setNetSpeed();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
void on_isLanConnect();
|
|
|
|
|
void on_isWifiConnect();
|
|
|
|
|
void on_isNetOn();
|
|
|
|
|
|
|
|
|
|
// 后台回调
|
|
|
|
|
void enNetDone();
|
|
|
|
|
void disNetDone();
|
|
|
|
|
void enWifiDone();
|
2019-11-29 17:55:39 +08:00
|
|
|
|
void launchLanDone();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
void disWifiDone();
|
|
|
|
|
void keepDisWifiState();
|
|
|
|
|
void connLanDone(int connFlag);
|
2020-01-09 16:32:16 +08:00
|
|
|
|
void connWifiDone(int connFlag);
|
2019-10-31 09:56:53 +08:00
|
|
|
|
|
|
|
|
|
void iconStep();
|
2020-02-18 14:01:09 +08:00
|
|
|
|
void on_btnFlyMode_clicked();
|
|
|
|
|
|
2020-02-21 08:50:52 +08:00
|
|
|
|
void on_btnAddNet_clicked();
|
2020-01-09 16:32:16 +08:00
|
|
|
|
signals:
|
|
|
|
|
void deleteRedundantNet();
|
2020-02-21 17:19:51 +08:00
|
|
|
|
|
|
|
|
|
void waitWifiStop();
|
|
|
|
|
void waitLanStop();
|
2019-10-31 09:56:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // MAINWINDOW_H
|