⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netgodialog.cpp

📁 Linux/Windows 环境下跨平台程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2004 Per Johansson		This file is part of netGo.    netGo 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 2 of the License, or    (at your option) any later version.    netGo 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 netGo; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include <qpushbutton.h>#include <qlabel.h>#include <qdir.h>#include <qlistbox.h>#include <qlineedit.h>#include <qstring.h>#include <qmessagebox.h>#include <qwidgetstack.h>#include <qcombobox.h>#include <qregexp.h>#include <qvalidator.h>#include <qapplication.h>#include <qprocess.h>#include <qsettings.h>#include <stdio.h>#include <qpopupmenu.h>#include <qevent.h>#include <qcheckbox.h>#include "netgodialog.h"#include "netgodialogbase.h"#include "settings.h"#include "setup.h"#include "profile.h"#include "process.h"#include "trayicon.h"#include "msgbox.h"// Version-number.const QString version = "v0.4";// Constructor for netGoDialog (with GUI).netGoDialog::netGoDialog(QWidget *parent, const char *name)			: netGoDialogBase(parent, name){	// Disable the "ok-button", "edit profile"-button and the "delete profile"-button 	// when no profile is selected.	mainGoBut->setEnabled(0);	editProfileBut->setEnabled(0);	delProfileBut->setEnabled(0);		// Print the current version in the versionLabel.	versionLabel->setText("<p align=\"right\">" + version + "</p>");		// Fetch all the profiles from the textfile and save them in a vector.	Profile::fetchProfiles();		// Update the profiles in the listbox.	updateProfiles();		// Update the stringlist with the system's interfaces.	updateIfaces();		// Initialize the system tray.	initTray();		// Signals and slots for the mainpage.	connect(quitBut, SIGNAL(clicked()), this, SLOT(close()) );	connect(mainGoBut, SIGNAL(clicked()), this, SLOT(runProfilePage()) );	connect(addProfileBut, SIGNAL(clicked()), this, SLOT(clearAddProfile()) );	connect(editProfileBut, SIGNAL(clicked()), this, SLOT(fillEditProfilePage()) );	connect(delProfileBut, SIGNAL(clicked()), this, SLOT(deleteProfilePage()) );		// Signals and slots for the addProfilePage.	connect(addProfileOkBut, SIGNAL(clicked()), this, SLOT(addProfile()) );	connect(addProfileCancelBut, SIGNAL(clicked()), this, SLOT(mainPage()) );	connect(moreSettingsBut, SIGNAL(clicked()), this, SLOT(morePage()) );	connect(moreSettingsBackBut, SIGNAL(clicked()), this, SLOT(addProfilePage()) );	connect(ipLE, SIGNAL(textChanged(const QString &)), this, SLOT(onDhcp(const QString &)) );		// Signals and slots for the editProfilePage.	connect(editProfileSaveBut, SIGNAL(clicked()), this, SLOT(editProfile()) );	connect(editProfileCancelBut, SIGNAL(clicked()), this, SLOT(mainPage()) );	connect(editMoreSettingsBut, SIGNAL(clicked()), this, SLOT(editMorePage()) );	connect(editMoreBackBut, SIGNAL(clicked()), this, SLOT(editProfilePage()) );	connect(editIpLE, SIGNAL(textChanged(const QString &)), this, SLOT(onDhcpEdit(const QString &)) );		// Signals and slots for the runProfilePage.	connect(runProfileOkBut, SIGNAL(clicked()), this, SLOT(mainPage()) );	connect(runProfileCancelBut, SIGNAL(clicked()), this, SLOT(cancelRunProfile()) );		// Signals and slots for the profile-listbox.	connect(profileLB, SIGNAL(clicked(QListBoxItem*)), this, SLOT(enableMainGoBut()) );	connect(profileLB, SIGNAL(clicked(QListBoxItem*)), this, SLOT(enableEditProfileBut()) );	connect(profileLB, SIGNAL(clicked(QListBoxItem*)), this, SLOT(enableDeleteProfileBut()) );	// Regular expressions used as input validators.	common = QRegExp("[^ ]*");	ip = QRegExp("^[0-9]{1,3}[.]{1}[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$");	ipOrDhcp = QRegExp("(^[0-9]{1,3}[.]{1}[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$|dhcp)");		// Apply validators to the line-edits.	nameLE->setValidator(new QRegExpValidator(common, this) );	ipLE->setValidator( new QRegExpValidator(ipOrDhcp, this) );	netmaskLE->setValidator( new QRegExpValidator(ip, this) );	gwLE->setValidator( new QRegExpValidator(ip, this) );	ns1LE->setValidator( new QRegExpValidator(ip, this) );	ns2LE->setValidator( new QRegExpValidator(ip, this) );	searchLE->setValidator( new QRegExpValidator(common, this) );		editNameLE->setValidator( new QRegExpValidator(common, this) );	editIpLE->setValidator( new QRegExpValidator(ipOrDhcp, this) );	editNetmaskLE->setValidator( new QRegExpValidator(ip, this) );	editGwLE->setValidator( new QRegExpValidator(ip, this) );	editNs1LE->setValidator( new QRegExpValidator(ip, this) );	editNs2LE->setValidator( new QRegExpValidator(ip, this) );	editSearchLE->setValidator( new QRegExpValidator(common, this) );}// Constructor for commandline execution (without GUI).netGoDialog::netGoDialog(const char *profile){	// Fetch all the profiles from the textfile and save them in a vector.	Profile::fetchProfiles();		int i, match = 0;	// Check that the specified profile exists.	for (i=0; i<Profile::profiles.size(); i++) {		if (Profile::profiles.at(i).name == profile) {			match = 1;			break;		}	}		// Bash colors.	QString NORMAL = "\e[1m";	QString normal = "\e[0m";		// If the profile doesn't exist - exit.	if (match != 1) {		qWarning("Profile " + NORMAL + "%s" + normal + " doesn't exist. Aborting.", profile);		exit(1);	}	else {		// Execute the profile from the commandline.		cmdlineExecution(profile);	}}// Function for executing a profile from the commandline.void netGoDialog::cmdlineExecution(const char *profile){	// Bash escape sequences for coloured text.	QString blue = "\e[0;34m";	QString BLUE = "\e[1;34m";	QString green = "\e[0;32m";	QString GREEN = "\e[1;32m";	QString normal = "\e[0m";	qWarning("\n" + blue + "Executing profile: " + BLUE + "%s\n"			"" + normal + "================================\n", profile);	// Create a Process-object.	networkProc = new Process(procBrowser, runProfileOkBut);		// Call the member-method that executes the specified profile's network settings.	networkProc->runProfile(profile);		// After the execution is finished - exit.	connect(networkProc, SIGNAL(procsFinished()), this, SLOT(exitCmdline()) );}/*------------------------------------------  Functions that enables/disables buttons.------------------------------------------*/// Function that enables the Go-button on the mainpage.void netGoDialog::enableMainGoBut(){	// Enable the mainGoBut. 	if (profileLB->numRows() > 0)		mainGoBut->setEnabled(1);}// Function that enables the edit profile-button on the mainpage.void netGoDialog::enableEditProfileBut(){	// Enable the editProfileBut.	if (profileLB->numRows() > 0)		editProfileBut->setEnabled(1);}// Function that enables the delete profile-button on the mainpage.void netGoDialog::enableDeleteProfileBut(){	// Enable the delProfileBut.	if (profileLB->numRows() > 0)		delProfileBut->setEnabled(1);}// Function that enables/disables some lineedits depending on// if the user specified a static ip or dhcp.void netGoDialog::onDhcp(const QString &text){	if (text == "dhcp") {		netmaskLE->setEnabled(0);		gwLE->setEnabled(0);		ns1LE->setEnabled(0);		ns2LE->setEnabled(0);		searchLE->setEnabled(0);	}	else {		netmaskLE->setEnabled(1);		gwLE->setEnabled(1);		ns1LE->setEnabled(1);		ns2LE->setEnabled(1);		searchLE->setEnabled(1);	}}// Identical function to the one above, for the edit page.void netGoDialog::onDhcpEdit(const QString &text){	if (text == "dhcp") {		editNetmaskLE->setEnabled(0);		editGwLE->setEnabled(0);		editNs1LE->setEnabled(0);		editNs2LE->setEnabled(0);		editSearchLE->setEnabled(0);	}	else {		editNetmaskLE->setEnabled(1);		editGwLE->setEnabled(1);		editNs1LE->setEnabled(1);		editNs2LE->setEnabled(1);		editSearchLE->setEnabled(1);	}} 	/*------------------------------------------      Functions that raises pages.------------------------------------------*/// Function that shows the mainpage.  void netGoDialog::mainPage(){	// Update the profiles in the listbox before showing the mainpage.	updateProfiles();		// Raise the mainpage.	widgetStack->raiseWidget(0);}// Function that shows the add profile-page.void netGoDialog::addProfilePage(){		// Raise the add profile-page.	widgetStack->raiseWidget(1);}// Function that clear all the settings on the add profile-page.void netGoDialog::clearAddProfile(){	// Clear all the lineedit's.	nameLE->clear();	ipLE->clear();	netmaskLE->clear();	gwLE->clear();	ns1LE->clear();	ns2LE->clear();	searchLE->clear();	modeCB->setCurrentText("None");	essidLE->clear();	keyLE->clear();		// Set focus to the first line-edit.	nameLE->setFocus();	// Show "None" as interface.	ifaceCB->setCurrentText("None");		// Raise the add profile-page.	addProfilePage();	}// Function that shows the more page.void netGoDialog::morePage(){	// Raise the more page and set focus to the mode combobox.	widgetStack->raiseWidget(4);	modeCB->setFocus();}// Function that shows the run profile-page.void netGoDialog::runProfilePage(){	// Raise the run profile-page.	widgetStack->raiseWidget(2);		// Create a Process-object.	networkProc = new Process(procBrowser, runProfileOkBut);	// Call the member-method that executes the selected profile's network-settings.	networkProc->runProfile(profileLB->currentText() ); }// Function that shows the edit profile-page.void netGoDialog::editProfilePage(){	// Raise the edit profile-page.	widgetStack->raiseWidget(3);}// Function that shows the edit profile-page and fills up the profile's settings.void netGoDialog::fillEditProfilePage(){	// Raise the edit profile-page.	widgetStack->raiseWidget(3);		// Search after the appropriate profile and print its settings in the line-edit's.	int i;	for (i=0; i<Profile::profiles.size(); i++) {		if (Profile::profiles.at(i).name == profileLB->currentText()) // Check if it's the one.		{			// Fill in the corresponding settings in the textfields.			editNameLE->setText(Profile::profiles.at(i).name);			editIfaceCB->setCurrentText(Profile::profiles.at(i).iface);			editIpLE->setText(Profile::profiles.at(i).ip);			editNetmaskLE->setText(Profile::profiles.at(i).netmask);			editGwLE->setText(Profile::profiles.at(i).gw);			editNs1LE->setText(Profile::profiles.at(i).ns1);			editNs2LE->setText(Profile::profiles.at(i).ns2);			editSearchLE->setText(Profile::profiles.at(i).search);				editModeCB->setCurrentText(Profile::profiles.at(i).mode);			editEssidLE->setText(Profile::profiles.at(i).essid);			editKeyLE->setText(Profile::profiles.at(i).key);		}	}		// Set focus to the lineedit on the top.	editNameLE->setFocus();	}// Function that shows the edit more-page.void netGoDialog::editMorePage(){	// Raise the edit more-page.	widgetStack->raiseWidget(5);		// Set focus to the combobox at the top.	editModeCB->setFocus();}// Function that shows the delete profile-page.void netGoDialog::deleteProfilePage(){	// Call the function that does the actually "deleting".	deleteProfile(profileLB->currentText() );}/*------------------------------------------     Functions that handles the profiles.------------------------------------------*/// Function that adds a profilevoid netGoDialog::addProfile()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -