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

📄 netgodialog.cpp

📁 Linux/Windows 环境下跨平台程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
{	// Make sure that a profile name is filled in. 	if (nameLE->text().isEmpty() ) {	 	QMessageBox::information(0, "Missing info", "You have to specify a profile name.");		return;	}		// Make sure that an interface is set, depending on other settings.	if (ifaceCB->currentText() == "None") {		if (!ipLE->text().isEmpty() ) {			QMessageBox::information(0, "Missing info", "You have to select an interface in order to set an ip address.");			return;		}		else if (!netmaskLE->text().isEmpty() ) {			QMessageBox::information(0, "Missing info", "You have to select an interface in order to set a netmask.");			return;		}		else if (modeCB->currentText() != "None" || !essidLE->text().isEmpty() || !keyLE->text().isEmpty() ) {			QMessageBox::information(0, "Missing info", "You have to select an interface in order to set any wireless options."); 			return;		}	}		// Check that the user has specified an unique profile-name.	int i;	for (i=0; i<Profile::profiles.size(); i++) {		if (Profile::profiles.at(i).name == nameLE->text() ) {			QMessageBox::information(0, "Invalid profile name", "You have choosen a profile name that already exists.");			return;		}	}		// Create a QSettings object so we can access the profiles.	settings = new QSettings();	settings->insertSearchPath(QSettings::Unix, QDir::homeDirPath() + "/.qt");		// Write the profile.	settings->beginGroup("/netgo/profiles/" + nameLE->text() );		settings->writeEntry("interface", ifaceCB->currentText() );		settings->writeEntry("ip", ipLE->text() );		settings->writeEntry("netmask", netmaskLE->text() );		settings->writeEntry("gateway", gwLE->text() );		settings->writeEntry("ns1", ns1LE->text() );		settings->writeEntry("ns2", ns2LE->text() );		settings->writeEntry("search", searchLE->text() );		settings->writeEntry("mode", modeCB->currentText() );		settings->writeEntry("essid", essidLE->text() );		settings->writeEntry("key", keyLE->text() );	settings->endGroup();		delete settings;		// Update the profile-vector.	Profile::fetchProfiles();		// Return to the main-page.	mainPage();}// Function that edits a profile's settings.void netGoDialog::editProfile(){	// Make sure that a profile name is filled in. 	if (editNameLE->text().isEmpty() ) {	 	QMessageBox::information(0, "Missing info", "You have to specify a profile name.");		return;	}		// Make sure that an interface is set, depending on other settings.	if (editIfaceCB->currentText() == "None") {		if (!editIpLE->text().isEmpty() ) {			QMessageBox::information(0, "Missing info", "You have to select an interface in order to set an ip address.");			return;		}		else if (!editNetmaskLE->text().isEmpty() ) {			QMessageBox::information(0, "Missing info", "You have to select an interface in order to set a netmask.");			return;		}		else if (editModeCB->currentText() != "None" || !editEssidLE->text().isEmpty() || !editKeyLE->text().isEmpty() ) {			QMessageBox::information(0, "Missing info", "You have to select an interface in order to set any wireless options."); 			return;		}	}		// Check that the user has specified an unique profile-name.	int i;	for (i=0; i<Profile::profiles.size(); i++) {		if (Profile::profiles.at(i).name == editNameLE->text() && editNameLE->text() != profileLB->currentText() ) {			QMessageBox::information(0, "Invalid profile-name", "You have choosen a profile-name that allready exists.");			return;		}	}		// Create a QSettings object so we can access the profiles.	settings = new QSettings();	settings->insertSearchPath(QSettings::Unix, QDir::homeDirPath() + "/.qt");		// Delete the profile's old settings before writing the new.	settings->beginGroup("/netgo/profiles/" + profileLB->currentText() );		settings->removeEntry("interface");		settings->removeEntry("ip");		settings->removeEntry("netmask");		settings->removeEntry("gateway");		settings->removeEntry("ns1");		settings->removeEntry("ns2");		settings->removeEntry("search");		settings->removeEntry("mode");		settings->removeEntry("essid");		settings->removeEntry("key");	settings->endGroup();		// Write the new edited settings.	settings->beginGroup("/netgo/profiles/" + editNameLE->text() );		settings->writeEntry("interface", editIfaceCB->currentText() );		settings->writeEntry("ip", editIpLE->text() );		settings->writeEntry("netmask", editNetmaskLE->text() );		settings->writeEntry("gateway", editGwLE->text() );		settings->writeEntry("ns1", editNs1LE->text() );		settings->writeEntry("ns2", editNs2LE->text() );		settings->writeEntry("search", editSearchLE->text() );		settings->writeEntry("mode", editModeCB->currentText() );		settings->writeEntry("essid", editEssidLE->text() );		settings->writeEntry("key", editKeyLE->text() );	settings->endGroup();		delete settings;		// Update the vector that contains all the profiles.	Profile::fetchProfiles();		// Return to mainPage.	mainPage();}// Function that deletes a profile.void netGoDialog::deleteProfile(const QString &profile){	// Ask the user if he's sure..	if (QMessageBox::critical( this, "Delete profile", "Are you sure you want to delete profile: " + profileLB->currentText() + " ?", "Yes", "No", 0, 0, 1 ) )		return;			// Loop through the vector...	for (int i=0; i<Profile::profiles.size(); i++) {		if (Profile::profiles.at(i).name == profile) { // Check if the current profile is matching the arg.			QValueVector<Profile>::iterator it = Profile::profiles.begin() + i;			Profile::profiles.erase(it); // Delete the profile that was matching the argument.		}	}		// Create a QSettings object so we can access the profiles.	settings = new QSettings();	settings->insertSearchPath(QSettings::Unix, QDir::homeDirPath() + "/.qt");		// Delete the specified profile.	settings->beginGroup("/netgo/profiles/" + profile );		settings->removeEntry("interface");		settings->removeEntry("ip");		settings->removeEntry("netmask");		settings->removeEntry("gateway");		settings->removeEntry("ns1");		settings->removeEntry("ns2");		settings->removeEntry("search");		settings->removeEntry("mode");		settings->removeEntry("essid");		settings->removeEntry("key");	settings->endGroup();		delete settings;		// Let the user know that we've deleted the profile.	QMessageBox::information(0, "Profile deleted", "Profile deleted successfully!");		// Update the profile-vector.	Profile::fetchProfiles();		// Return to mainpage.	mainPage();}/*------------------------------------------         Systemtray functions.------------------------------------------*/// Function that initializes the system tray.void netGoDialog::initTray(){	// Create a menu for the profiles.	profileMenu = new QPopupMenu();		// Make sure that we update the profiles before showing the menu.	connect(profileMenu, SIGNAL(aboutToShow()), this, SLOT(updateTrayProfiles()) );		// Create the "main menu" for the tray.	trayMenu = new QPopupMenu();		// Make sure that we update the menu before showing it.	connect(trayMenu, SIGNAL(aboutToShow()), this, SLOT(updateTray()) );		// Create the trayicon using Psi's class (God bless GPL!)	tray = new TrayIcon( QPixmap::fromMimeSource("globe_22x22.png"), "netGo", trayMenu);	QObject::connect(tray, SIGNAL(clicked( const QPoint&, int)), this, SLOT(showOrHide()) );		// Make the trayicon and its menu visible.	tray->show();	trayMenu->show();}// Function that updates the profiles in the systemtray.void netGoDialog::updateTrayProfiles(){	// Clear the profile menu.	profileMenu->clear();		// Insert the profiles.	for (int i=0; i<Profile::profiles.size(); i++)		profileMenu->insertItem(QPixmap::fromMimeSource("satelite_16x16.png"), Profile::profiles.at(i).name, this, SLOT(runFromTray(int)) );}// Function that updates the "main menu" in the systemtray.void netGoDialog::updateTray(){	// Clear the "main menu".	trayMenu->clear();		// Insert all the items.	if (this->isVisible()) // Insert "Hide" or "Unhide".		trayMenu->insertItem("&Hide", this, SLOT(hide()) );	else		trayMenu->insertItem("Un&hide", this, SLOT(show()) );		trayMenu->insertItem(QPixmap::fromMimeSource("globe_16x16.png"), "&Profiles", profileMenu);	trayMenu->insertSeparator();	trayMenu->insertItem(QPixmap::fromMimeSource("quit_16x16.png"), "&Quit", qApp, SLOT(quit()) );}// Function for executing a profile.// Used by the systemtray.void netGoDialog::runFromTray(int id){	// Show the app.	this->show();		// 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(profileMenu->text(id));}// Either show or hide the app when the user clicks the trayicon.void netGoDialog::showOrHide(){	// Show or hide.	if (this->isVisible())		this->hide();	else		this->show();}/*------------------------------------------             Misc functions.------------------------------------------*/// Function that updates the profiles in the listbox.void netGoDialog::updateProfiles(){	// Remove all the old items in the listbox.	profileLB->clear();	// Loop through all the profiles and parse out all the profile-names.	for (int i=0; i<Profile::profiles.size(); i++)		profileLB->insertItem(QPixmap::fromMimeSource("satelite_32x32.png"), Profile::profiles.at(i).name);		// Sort all the profiles in alphabetical order.	profileLB->sort(TRUE);		// Disable a couple of buttons if there are'nt any profiles.	if (profileLB->numRows() < 1) {		mainGoBut->setEnabled(0);		editProfileBut->setEnabled(0);		delProfileBut->setEnabled(0);	}}// Function that is called when the user press Cancel during// execution of a profile.void netGoDialog::cancelRunProfile(){	// Call the function that terminates the current process.	networkProc->terminateProc();		// Delete the Process class.	delete networkProc;		// Return to the main-page.	mainPage();}// Function that exits the app after the commandline execution.void netGoDialog::exitCmdline(){	// Exit the application.	exit(0);}// Function for fetching the available interfaces from 'ifconfig -a'.void netGoDialog::updateIfaces(){		// Open /proc/net/dev for reading.	QFile file("/proc/net/dev");	if (!file.open(IO_ReadOnly)) {		qWarning("Could not find /proc/net/dev");		QMessageBox::critical(this, "profiles.txt", "Couldn't find, or open profiles.txt.");		return;	}			// Regexp for fetching the interaces.	QRegExp iface("\\s+([^ ]+):");	QTextStream dev(&file);	QString row;	// Clear the stringlist before inserting the new interfaces.	ifaces.clear();		// Start with adding this item.	ifaces = "None";	// Loop through /proc/net/dev	while (!file.atEnd()) {				// Check if the line contains an interface.		row = dev.readLine();		if (iface.search(row) != -1 && iface.cap(1) != "lo")			ifaces += iface.cap(1);	}		// Insert the stringlist in the comboboxes.	ifaceCB->clear();	ifaceCB->insertStringList(ifaces);	editIfaceCB->clear();	editIfaceCB->insertStringList(ifaces);}// Reimplement this function so the app is hidden instead of exited.void netGoDialog::closeEvent(QCloseEvent *ce){	// Check if we need to show the msgbox about the trayicon.	if (Settings::NOTIFY_TRAY == "yes") {		MsgBox *notify = new MsgBox();		notify->exec();				// If the checkbox was checked.		if (notify->checkBox->isChecked() ) {			// Write the new settings.			settings = new QSettings();			settings->insertSearchPath(QSettings::Unix, QDir::homeDirPath() + "/.qt");			settings->writeEntry("/netgo/misc/notify tray", "no");			delete settings;			// Update the settings.			Settings::fetchSettings();		}	}	// Ignore the closing and hide the app instead.	ce->ignore();	this->hide();}

⌨️ 快捷键说明

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