📄 mainwindow.cxx
字号:
/* * 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 2 of the License, 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 Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* Copyright (C) 2004 * * Authors: Erik Eliasson <eliasson@it.kth.se> * Johan Bilien <jobi@via.ecp.fr>*/#include"MainWindow.h"#include <libminisip/conference/ConferenceControl.h>#include<libmutil/trim.h>#include<libmutil/itoa.h>#include<libmsip/SipCommandString.h>#include<libminisip/sip/SipSoftPhoneConfiguration.h>#include<libminisip/contactdb/ContactDb.h>#include<libminisip/mediahandler/MediaCommandString.h>#include"CallWidget.h"#include"ConferenceWidget.h"#include"PhoneBook.h"#include"SettingsDialog.h"#include"CertificateDialog.h"#include"DtmfWidget.h"#ifndef WIN32# include"TrayIcon.h"#endif#include"LogWidget.h"#include"ImWidget.h"#include"AccountsList.h"#include"AccountsStatusWidget.h"#include<libminisip/sip/SipSoftPhoneConfiguration.h>#include<libminisip/contactdb/ContactDb.h>#include<libmsip/SipCommandString.h>#ifdef HILDON_SUPPORT# include<hildon-lgpl/hildon-widgets/hildon-app.h># include<hildon-lgpl/hildon-widgets/hildon-appview.h>#endif#ifdef OLDLIBGLADEMM# define SLOT(a,b) SigC::slot(a,b)# define BIND SigC::bind #else# define SLOT(a,b) sigc::mem_fun(a,b) # define BIND sigc::bind#endifusing namespace std;MainWindow::MainWindow( Gtk::Main *main, std::string programDir ):kit( main ){ Gtk::Button * callButton; Gtk::Button * imButton; Gtk::MenuItem * prefMenu; Gtk::MenuItem * certMenu; Gtk::MenuItem * quitMenu; Gtk::MenuItem * addContactMenu; Gtk::MenuItem * addAddressContactMenu; Gtk::MenuItem * removeContactMenu; Gtk::MenuItem * editContactMenu; Gtk::MenuItem * callMenu; Gtk::MenuItem * conferenceMenu; Gtk::MenuItem * imMenu; Glib::RefPtr<Gnome::Glade::Xml> refXml;#ifndef OLDLIBGLADEMM Gtk::Expander * dtmfExpander;#endif nextConfId=0; this->programDir = programDir; registerIcons(); try{ refXml = Gnome::Glade::Xml::create( getDataFileName("minisip.glade") ); } catch(const Gnome::Glade::XmlError& ex){ std::cerr << ex.what() << std::endl; exit( 1 ); }#ifndef HILDON_SUPPORT refXml->get_widget( "minisipMain", mainWindowWidget ); refXml->get_widget( "mainTabWidget", mainTabWidget );#endif refXml->get_widget( "phoneBookTree", phoneBookTreeView ); refXml->get_widget( "phoneMenu", phoneMenu ); refXml->get_widget( "phoneAddMenu", phoneAddMenu ); refXml->get_widget( "phoneAddAddressMenu", phoneAddAddressMenu ); refXml->get_widget( "phoneRemoveMenu", phoneRemoveMenu ); refXml->get_widget( "phoneEditMenu", phoneEditMenu ); refXml->get_widget( "addContactMenu", addContactMenu ); refXml->get_widget( "addAddressContactMenu", addAddressContactMenu ); refXml->get_widget( "removeContactMenu", removeContactMenu ); refXml->get_widget( "editContactMenu", editContactMenu ); refXml->get_widget( "callMenu", callMenu ); refXml->get_widget( "conferenceMenu", conferenceMenu ); refXml->get_widget( "imMenu", imMenu );#ifndef OLDLIBGLADEMM DtmfWidget * dtmfWidget = manage( new DtmfWidget() ); dtmfWidget->setHandler( this ); refXml->get_widget( "dtmfExpander", dtmfExpander ); dtmfExpander->add( *dtmfWidget );#endif#ifdef HILDON_SUPPORT /* Create the hildon app */ mainWindowWidget = dynamic_cast<Gtk::Window *>( manage( Glib::wrap( hildon_app_new() ) ) ); /* Create a hildon app view */ Gtk::Container *appview = dynamic_cast<Gtk::Container *>( manage( Glib::wrap( hildon_appview_new( "Minisip" ) ) ) ); hildon_app_set_appview( HILDON_APP( mainWindowWidget->gobj() ), HILDON_APPVIEW( appview->gobj() ) ); hildon_app_set_title( HILDON_APP( mainWindowWidget->gobj() ), "Minisip" ); Gtk::Widget * w; Gtk::HBox * mainHBox; mainHBox = manage( new Gtk::HBox( true, 6 ) ); mainTabWidget = manage( new Gtk::Notebook() ); refXml->get_widget( "dialVBox", w ); w->reparent( *mainHBox ); mainHBox->add( *mainTabWidget ); //mainHBox->pack_end( *mainTabWidget ); mainHBox->show_all(); appview->add( *mainHBox ); Gtk::Menu * mainMenu = dynamic_cast<Gtk::Menu *>( Glib::wrap( hildon_appview_get_menu( HILDON_APPVIEW( appview->gobj() ) ) ) ); refXml->get_widget( "fileMenu", w ); w->reparent( *mainMenu ); refXml->get_widget( "viewMenu", w ); w->reparent( *mainMenu ); refXml->get_widget( "contactMenu", w ); w->reparent( *mainMenu );#endif treeSelection = phoneBookTreeView->get_selection();// treeSelection->set_select_function( SigC::slot( *this, // &MainWindow::phoneSelect ) ); treeSelection->signal_changed().connect( SLOT( *this, &MainWindow::phoneSelected ) ); phoneBookTree = new PhoneBookTree; phoneBookModel = new PhoneBookModel( phoneBookTree ); phoneBookTreeView->set_headers_visible( true ); phoneBookTreeView->set_rules_hint( false ); phoneBookTreeView->signal_button_press_event().connect_notify( SLOT( *this, &MainWindow::phoneTreeClicked ), false ); //phoneBookTreeView->set_hover_expand( true ); /* Context menu */ phoneAddAddressMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection>, bool >( SLOT( *phoneBookModel, &PhoneBookModel::addContact ), treeSelection, true )); phoneAddMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection>, bool>( SLOT( *phoneBookModel, &PhoneBookModel::addContact ), treeSelection, false )); phoneRemoveMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection> >( SLOT( *phoneBookModel, &PhoneBookModel::removeContact ), treeSelection )); phoneEditMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection> >( SLOT( *phoneBookModel, &PhoneBookModel::editContact ), treeSelection )); /* Contact menu from the menubar */ addAddressContactMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection>, bool >( SLOT( *phoneBookModel, &PhoneBookModel::addContact ), treeSelection, true )); addContactMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection>, bool>( SLOT( *phoneBookModel, &PhoneBookModel::addContact ), treeSelection, false )); removeContactMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection> >( SLOT( *phoneBookModel, &PhoneBookModel::removeContact ), treeSelection )); editContactMenu->signal_activate().connect( BIND<Glib::RefPtr<Gtk::TreeSelection> >( SLOT( *phoneBookModel, &PhoneBookModel::editContact ), treeSelection )); refXml->get_widget( "callButton", callButton ); callButton->signal_clicked().connect( SLOT( *this, &MainWindow::inviteClick ) ); callMenu->signal_activate().connect( SLOT( *this, &MainWindow::inviteClick ) ); //refXml->get_widget( "conferenceButton", conferenceButton ); //conferenceButton->signal_clicked().connect( SLOT( *this, &MainWindow::conference ) ); conferenceMenu->signal_activate().connect( SLOT( *this, &MainWindow::conference ) ); phoneBookTreeView->signal_row_activated().connect( SLOT( *this, &MainWindow::inviteFromTreeview ) ); refXml->get_widget( "imButton", imButton ); imButton->signal_clicked().connect( SLOT( *this, &MainWindow::imClick ) ); imMenu->signal_activate().connect( SLOT( *this, &MainWindow::imClick ) ); certificateDialog = new CertificateDialog( refXml ); settingsDialog = new SettingsDialog( refXml, certificateDialog ); refXml->get_widget( "uriEntry", uriEntry ); refXml->get_widget( "prefMenu", prefMenu ); refXml->get_widget( "certMenu", certMenu ); refXml->get_widget( "quitMenu", quitMenu ); refXml->get_widget( "viewCallListMenu", viewCallListMenu ); refXml->get_widget( "viewStatusMenu", viewStatusMenu ); prefMenu->signal_activate().connect( SLOT( *settingsDialog, &SettingsDialog::show ) ); certMenu->signal_activate().connect( SLOT( *this, &MainWindow::runCertificateSettings ) ); //This two signals are for closing minisip ... see MainWindow::quit quitMenu->signal_activate().connect( SLOT( *this, &MainWindow::quit ) ); mainWindowWidget->signal_delete_event().connect( SLOT( *this, &MainWindow::on_window_close ) ); viewCallListMenu->signal_activate().connect( BIND<uint8_t>( SLOT( *this, &MainWindow::viewToggle ), 0 )); viewStatusMenu->signal_activate().connect( BIND<uint8_t>( SLOT( *this, &MainWindow::viewToggle ), 1 )); dispatcher.connect( SLOT( *this, &MainWindow::gotCommand ) ); uriEntry->signal_activate().connect( SLOT( *this, &MainWindow::inviteClick ) );#if not defined WIN32 && not defined HILDON_SUPPORT trayIcon = new MTrayIcon( this, refXml ); mainWindowWidget->signal_hide().connect( SLOT( *this, &MainWindow::hideSlot ));#endif logWidget = new LogWidget( this ); //mainTabWidget->append_page( *logWidget, "Call list" ); accountsList = AccountsList::create( new AccountsListColumns() ); statusWidget = new AccountsStatusWidget( accountsList); //mainTabWidget->append_page( *statusWidget, "Accounts" ); logDispatcher.connect( SLOT( *this, &MainWindow::gotLogEntry ) ); mainTabWidget->signal_switch_page().connect( SLOT( *this, &MainWindow::onTabChange ) ); mainWindowWidget->show_all();// statusWidget->hide(); logWidget->hide(); mainWindowWidget->set_sensitive( false );}MainWindow::~MainWindow(){ factory->remove_default(); delete settingsDialog; delete certificateDialog; delete statusWidget; delete logWidget; delete phoneMenu;#ifndef WIN32 if( trayIcon ){ delete trayIcon; }#endif delete phoneBookTree; delete mainWindowWidget;}bool MainWindow::on_window_close (GdkEventAny* /*event*/ ) { //enter quit mode ... quit(); return true; }void MainWindow::run(){ //add to the command dispatcher queue the startup commands list<string>::iterator iter; iter = getSipSoftPhoneConfiguration()->startupActions.begin(); for( ; iter != getSipSoftPhoneConfiguration()->startupActions.end(); iter++ ) { int pos; pos = (*iter).find(' '); string cmd = (*iter).substr( 0, pos ); pos ++; //advance to the start of the params ... string params = (*iter).substr( pos, (*iter).size() - pos ); handleCommand( CommandString( "", "startup_" + cmd, params ) ); }#ifndef WIN32 if( trayIcon != NULL ){ Gtk::Window * window = NULL; window = trayIcon->getWindow(); kit->run( *window ); if( window != NULL ) delete window; } else#endif kit->run( *mainWindowWidget );}void MainWindow::quit(){ kit->quit();}bool MainWindow::isVisible(){ return mainWindowWidget->is_visible();}void MainWindow::hide(){ mainWindowWidget->hide();}void MainWindow::runPref(){ settingsDialog->run();}void MainWindow::show(){ mainWindowWidget->show();}void MainWindow::hideSlot(){}void MainWindow::handleCommand(const CommandString &command ){ commandsLock.lock(); commands.push_front( command ); commandsLock.unlock(); dispatcher.emit();}void MainWindow::gotCommand(){ list<CallWidget *>::iterator i; list<ConferenceWidget *>::iterator j; commandsLock.lock(); CommandString command = commands.pop_back(); commandsLock.unlock();#ifdef OUTPUT_DEBUG// merr << "DEBUG: MainWindow::gotCmd : " << command.getString() << end;#endif if( command.getOp() == "sip_ready" ){ mainWindowWidget->set_sensitive( true ); return; } if( command.getOp() == "config_updated" ){ updateConfig(); return; } if( command.getOp() == "error_message" ){ doDisplayErrorMessage( command.getParam() ); return; } for( i = callWidgets.begin(); i != callWidgets.end(); i++ ){ if( (*i)->handleCommand( command ) ){ return; } } for( j = conferenceWidgets.begin(); j != conferenceWidgets.end(); j++ ){ if( (*j)->handleCommand( command ) ){ return; } } if (command.getOp() == SipCommandString::incoming_im){ list<ImWidget *>::iterator i; for (i = imWidgets.begin(); i != imWidgets.end(); i++ ){ if( (*i)->handleIm( command.getParam(), command.getParam2()/*, command.getParam3()*/ ) ){ return; } } addIm(command.getParam2()); for (i = imWidgets.begin(); i != imWidgets.end(); i++ ){ if( (*i)->handleIm( command.getParam(), command.getParam2()/*, command.getParam3()*/ ) ){ return; } } return; } if( command.getOp() == SipCommandString::incoming_available ){ addCall( command.getDestinationId(), command.getParam(), true, command.getParam2() ); return; } if( command.getOp()=="conf_join_received" ){ //string confid=itoa(rand()); string confid=""; string users=command.getParam3(); int i=0; while (users[i]!=';'&& users.length()!=0 &&!((uint)i>(users.length()-1))){ confid=confid+users[i]; i++; } users=trim(users.substr(i)); addConference( confid, users,command.getParam(),command.getDestinationId(), true ); return; } if( command.getOp() == SipCommandString::remote_presence_update){ MRef<ContactEntry*> ce = contactDb->lookUp(command.getParam()); if (ce){ string state = command.getParam2();// cerr << "State is: "<< state << endl; if (state =="online"){// cerr << "Changed status to online "<< endl; ce->setOnlineStatus(CONTACT_STATUS_ONLINE); }else if (state=="offline") ce->setOnlineStatus(CONTACT_STATUS_OFFLINE); else ce->setOnlineStatus(CONTACT_STATUS_UNKNOWN); ce->setOnlineStatusDesc(command.getParam3()); phoneBookTreeView->queue_draw(); }else{// cerr << "MainWindow::gotCommand: WARNING: did not find uri <"<< command.getParam()<< "> to change presence info"<< endl; } return; } if( command.getOp() == "startup_call"){ string uri; string params; params = command.getParam(); uri = params.substr( 0, params.find(' ') ); invite( uri ); return; } else if ( command.getOp() == "startup_im") { string uri; string params, mesg; int pos; params = command.getParam(); pos = params.find( ' ' ); uri = params.substr( 0, pos ); //get uri pos++; mesg = params.substr( pos, params.size() - pos ); //get message im( uri, mesg ); return; } if( command.getOp() == "set_active_tab" ) { int pageIdx; string param; param = command.getParam(); if( param == "" ) pageIdx = 0; else pageIdx = atoi( param.c_str() ); mainTabWidget->set_current_page( pageIdx ); } #ifdef OUTPUT_DEBUG //merr << "MainWindow::gotCommand: Warning: did not handle command: "<< command.getOp()<< end;#endif} void MainWindow::gotPacket( int32_t /*i*/ ){}void MainWindow::displayMessage( string s, int /*style*/ ){ handleCommand( CommandString( "", "error_message", Glib::locale_to_utf8( s ) ) );}void MainWindow::doDisplayErrorMessage( string s ){ Gtk::MessageDialog dialog( s, Gtk::MESSAGE_ERROR ); dialog.run();}void MainWindow::setSipSoftPhoneConfiguration( MRef<SipSoftPhoneConfiguration *> config ){ this->config = config; handleCommand( CommandString( "", "config_updated" ) );}MRef<SipSoftPhoneConfiguration *> MainWindow::getSipSoftPhoneConfiguration() { return this->config;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -