Beispiel #1
0
void AghPhoneDialog::menuTriggered(QAction *action) {
	cout << action->text().toLocal8Bit().data() << endl;
	QString operation = action->text();

	if (operation == "Preferences") {
		prefDialog->exec();
		prefDialog->updateConfiguration();
		configuration->saveConf();
	} else if (operation == "Close") {
		terminateApplication();
	} else if (operation == "Search in directory") {
		searchDir->exec();
		TerminalAddress *foundTerminal = searchDir->getSelectedTerminal();

		// check whether terminal was selected
		if (foundTerminal == NULL) {
			return;
		}

		QString foundTermName = foundTerminal->name.c_str();
		foundTermName += ":";
		foundTermName += foundTerminal->port.c_str();
		if (foundTerminal != 0) {
			this->putTerminalIntoList(foundTerminal, foundTermName);
		}
	} else if (operation == "Log in") {
		registeredAddress = new TerminalAddress;

		if (isRegistered) {
			QMessageBox::critical( this, this->windowTitle(),
					"User already registered");
			return;
		}

		if (this->configuration->directoryAlias->size() <= 0) {
			QMessageBox::critical( this, this->windowTitle(),
					"User alias not specified! Check your configuration.");
			return;
		}

		if (this->configuration->localPort->size() <= 0) {
			QMessageBox::critical( this, this->windowTitle(),
					"Local port not specified! Check your configuration.");
			return;
		}

		registeredAddress->name = *(this->configuration->directoryAlias);
		registeredAddress->port = *(this->configuration->localPort);

		// Get directory reference
		QString errorMessage = this->configuration->validateDirectory().c_str();

		if (errorMessage.count() > 0) {
			QMessageBox::critical( this, this->windowTitle(),
					errorMessage);

		} else {
			// search for directory
			try {
				Ice::CommunicatorPtr ic = Ice::initialize();
				stringstream a;
				a << *(configuration->directoryName)
				<< ":default -h " << *(configuration->directoryAddress)
				<< " -p " << *(configuration->directoryPort);
				Ice::ObjectPrx base = ic->stringToProxy ( a.str() );
				DirectoryPrx directory = DirectoryPrx::checkedCast ( base );

				if ( !directory ) {
					QMessageBox::critical( this, this->windowTitle(),
							"Connection to directory failed, please check your configuration!");
				} else {
					directory->registerTerminal(*registeredAddress);
					isRegistered = true;


					QString message("Terminal ");
					message += registeredAddress->name.c_str();
					message += " successfully registered.";
					statusbar->showMessage(message, 5000);
				}

				ic->destroy();

			} catch (TerminalExistsException ex) {
				QMessageBox::critical( this, this->windowTitle(),
						"User already registered, change your alias!");
				return;
			}  catch (...) {
				QMessageBox::critical( this, this->windowTitle(),
						"Connection to directory failed, please check your configuration!");
				return;
			}
		}

	} else if (operation == "Log out") {

		if (!isRegistered) {
			QMessageBox::critical( this, this->windowTitle(),
					"User not registered");
			return;
		}

		// Get directory reference
		QString errorMessage = this->configuration->validateDirectory().c_str();

		if (errorMessage.count() > 0) {
			QMessageBox::critical( this, this->windowTitle(),
					errorMessage);

		} else {
			// search for directory
			try {
				Ice::CommunicatorPtr ic = Ice::initialize();
				stringstream a;
				a << *(configuration->directoryName)
				<< ":default -h " << *(configuration->directoryAddress)
				<< " -p " << *(configuration->directoryPort);
				Ice::ObjectPrx base = ic->stringToProxy ( a.str() );
				DirectoryPrx directory = DirectoryPrx::checkedCast ( base );

				if ( !directory ) {
					QMessageBox::critical( this, this->windowTitle(),
							"Connection to directory failed, please check your configuration!");
				} else {
					directory->removeTerminal(registeredAddress->name);

					QString message("Terminal ");
					message += registeredAddress->name.c_str();
					message += " successfully unregistered.";
					statusbar->showMessage(message, 5000);

					delete registeredAddress;
					isRegistered = false;
				}

				ic->destroy();

			} catch (NoSuchTerminalException ex) {
				QMessageBox::critical( this, this->windowTitle(),
						"Such user does not exists in directory!");
			}  catch (...) {
				QMessageBox::critical( this, this->windowTitle(),
						"Connection to directory failed, please check your configuration!");
				return;
			}
		}
	} else if (operation == "About") {
		QString about;
		QDate curDate = QDate::currentDate();
		about += "AGHPhone VoIP application\n";
		about += "\n\nVersion 0.9.0.2b from ";
		about += curDate.toString();
		about += "\n\nCopyright (C) 2008  Mateusz Kramarczyk <*****@*****.**>\n";
		about += "Copyright (C) 2008  Tomasz Kijas <*****@*****.**>\n";
		about += "Copyright (C) 2008  Tomir Kryza <*****@*****.**>\n";
		about += "Copyright (C) 2008  Maciej Kluczny <*****@*****.**>\n";
		about += "Copyright (C) 2008  AGH University of Science and Technology <www.agh.edu.pl>\n";
		QMessageBox::about(this, "About AGHPhone", about);
	} else if (operation == "About Qt") {
		QMessageBox::aboutQt(this, "About Qt");
	} else if (operation == "License") {
		QString msg;
		msg += "This program is free software: you can redistribute it and/or modify\n";
		msg += "it under the terms of the GNU General Public License as published by\n";
		msg += "the Free Software Foundation, either version 3 of the License, or\n";
		msg += "(at your option) any later version.\n";
		msg += "\n";
		msg += "This program is distributed in the hope that it will be useful,\n";
		msg += "but WITHOUT ANY WARRANTY; without even the implied warranty of\n";
		msg += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n";
		msg += "GNU General Public License for more details.\n";
		msg += "\n";
		msg += "You should have received a copy of the GNU General Public License\n";
		msg += "along with this program.  If not, see <http://www.gnu.org/licenses/>.\n";

		QMessageBox::about(this, "AGHPhone license regulations", msg);
	}
}
Beispiel #2
0
int main(int argc, char **argv) {

	int lIcePort;
	int lRtpPort;
	int rDirPort;
	string rDirAddr;
	string alias;
	DirectoryPrx directory;

	if (argc < 6) {
		cout << "bad usage:\n\n";
		cout << "\t\tprogram lIcePort lRtpPort rDirPort rDirAddr alias\n\n";
		return 0;
	}

	/* arguments */
	lIcePort = atoi(argv[1]);
	lRtpPort = atoi(argv[2]);
	rDirPort = atoi(argv[3]);
	rDirAddr.append(argv[4]);
	alias.append(argv[5]);

	try {
		/* locate directory */
		Ice::CommunicatorPtr ic = Ice::initialize ();
		stringstream a;
		a << string("Directory") << ":default -h " << rDirAddr << " -p " << rDirPort;
		Ice::ObjectPrx base = ic->stringToProxy ( a.str() );
		directory = DirectoryPrx::checkedCast ( base );
		if ( !directory )
			throw "Invalid proxy";
		/* log in */
		TerminalAddress address;
		address.name = alias;
		std::ostringstream o2;
		o2 << string("") << lIcePort;
		address.port = o2.str();
		address.type = MCUTERMINAL;

		try {
			directory->registerTerminal(address);
		} catch(BadLoginException e) {
			cerr << "Bad login\n";
		} catch(TerminalExistsException e) {
			cerr << "Terminal already exists\n";
		}

	} catch(...) {
		clog << "Directory lookup error" << endl;
	}

	try {
		// Set up a simple configuration that logs on the console.
		BasicConfigurator::configure();
	} catch(log4cxx::helpers::Exception& e) {
		clog << "severe error" << endl;
	}

	Mixer m(lIcePort);
	m.setLocalRtpPort(lRtpPort);
}