📄 mainwindow.cxx
字号:
void MainWindow::updateConfig(){ accountsList->loadFromConfig( config ); settingsDialog->setAccounts( accountsList ); settingsDialog->setConfig( config ); certificateDialog->setCertChain( config->securityConfig.cert ); certificateDialog->setRootCa( config->securityConfig.cert_db ); const Glib::RefPtr<PhoneBookModel> modelPtr( phoneBookModel ); list< MRef<PhoneBook *> > phonebooks = config->phonebooks; list< MRef<PhoneBook *> >::iterator i; for( i = phonebooks.begin(); i != phonebooks.end(); i++ ){ phoneBookModel->setPhoneBook( *i ); } Gtk::CellRendererText * renderer; phoneBookTreeView->set_model( modelPtr ); if( phonebooks.size() > 0 ){ renderer = manage( new Gtk::CellRendererText() ); phoneBookTreeView->insert_column_with_data_func( 0, "Contact", *renderer, SLOT( *phoneBookModel, &PhoneBookModel::setFont ) ); }}void MainWindow::setContactDb( MRef<ContactDb *> contactDb ){ this->contactDb = contactDb; logWidget->setContactDb( contactDb );} bool MainWindow::configDialog( MRef<SipSoftPhoneConfiguration *> conf ){ int ret; settingsDialog->setConfig( conf ); ret = settingsDialog->run(); return ( ret == Gtk::RESPONSE_OK );}void MainWindow::log( int /*type*/, string /*msg*/ ){}CallWidget * MainWindow::addCall( string callId, string remoteUri, bool incoming, string securityStatus ){ ContactEntry * entry; Gtk::Image * icon; Gtk::Label * label = manage( new Gtk::Label ); Gtk::HBox * hbox = manage( new Gtk::HBox ); Glib::ustring tabLabelText; CallWidget * callWidget = new CallWidget( callId, remoteUri, this, incoming, securityStatus ); callWidgets.push_back( callWidget ); entry = contactDb->lookUp( remoteUri ); if( entry != NULL ){ tabLabelText = Glib::locale_to_utf8( entry->getName() ); } else{ tabLabelText = remoteUri; } label->set_text( tabLabelText ); if( incoming ){ icon = manage( new Gtk::Image( Gtk::Stock::GO_BACK, Gtk::ICON_SIZE_SMALL_TOOLBAR ) ); } else{ icon = manage( new Gtk::Image( Gtk::Stock::GO_FORWARD, Gtk::ICON_SIZE_SMALL_TOOLBAR ) ); } hbox->add( *icon ); hbox->add( *label ); hbox->show_all(); mainTabWidget->append_page( *callWidget, *hbox ) ; callWidget->show(); mainTabWidget->set_current_page( mainTabWidget->get_n_pages() - 1 ); return callWidget;}void MainWindow::removeCall( string callId ){ //do not increase the iterator automatically ... // we remove elements, thus we obtain the next element inside the loop for( list<CallWidget *>::iterator i = callWidgets.begin(); i != callWidgets.end(); i++){ if( (*i)->getMainCallId() == callId ){ mainTabWidget->remove_page( *(*i) ); callWidgets.erase( i ); return; } }}void MainWindow::addConference( string confId, string users,string remoteUri,string callId, bool incoming ){ //ContactEntry * entry; //not used Gtk::Image * icon; Gtk::Label * label = new Gtk::Label; Gtk::HBox * hbox = new Gtk::HBox; Glib::ustring tabLabelText; string from = config->inherited->sipIdentity->sipUsername + "@" + config->inherited->sipIdentity->sipDomain; ConferenceWidget * conferenceWidget = new ConferenceWidget(from, confId, users, remoteUri,callId, this, incoming); conferenceWidgets.push_back( conferenceWidget ); tabLabelText = "Conference "+confId; label->set_text( tabLabelText ); if( incoming ){ icon = new Gtk::Image( Gtk::Stock::GO_BACK, Gtk::ICON_SIZE_SMALL_TOOLBAR ); } else{ icon = new Gtk::Image( Gtk::Stock::GO_FORWARD, Gtk::ICON_SIZE_SMALL_TOOLBAR ); } hbox->add( *icon ); hbox->add( *label ); hbox->show_all(); mainTabWidget->append_page( *conferenceWidget, *hbox ) ; conferenceWidget->show(); mainTabWidget->set_current_page( mainTabWidget->get_n_pages() - 1 );}void MainWindow::removeConference( string callId ){ for( list<ConferenceWidget *>::iterator i = conferenceWidgets.begin(); i != conferenceWidgets.end(); i++ ){ if( (*i)->getMainConfId() == callId ){ mainTabWidget->remove_page( *(*i) ); conferenceWidgets.erase( i ); return; } }}ImWidget * MainWindow::addIm( string uri ){ string from = config->inherited->sipIdentity->sipUsername + "@" + config->inherited->sipIdentity->sipDomain; ImWidget * imWidget = new ImWidget( this, uri, from ); imWidgets.push_back( imWidget ); mainTabWidget->append_page( *imWidget, "Im " + uri ) ; imWidget->show(); mainTabWidget->set_current_page( mainTabWidget->get_n_pages() - 1 ); return imWidget;}void MainWindow::removeIm( string uri ){ for( list<ImWidget *>::iterator i = imWidgets.begin(); i != imWidgets.end(); i++ ){ if( (*i)->getToUri() == uri ){ mainTabWidget->remove_page( *(*i) ); imWidgets.erase( i ); return; } }}void MainWindow::setActiveTabWidget( Gtk::Widget * widget ) { //mainTabWidget->set_focus_child( *widget ); Gtk::Widget * currentWidget; currentWidget = mainTabWidget->get_nth_page( mainTabWidget->get_current_page() ); for( int idx = 0; idx<mainTabWidget->get_n_pages(); idx++ ) { if( mainTabWidget->get_nth_page( idx ) == widget ) { handleCommand( CommandString( "", "set_active_tab", itoa(idx ) ) ); } }}void MainWindow::setActiveTabWidget( int pageIdx ) { if( pageIdx >= 0 && pageIdx < mainTabWidget->get_n_pages() ) { handleCommand( CommandString( "", "set_active_tab", itoa( pageIdx ) ) ); } #ifdef DEBUG_OUTPUT else { cerr << "MainWindow::setActiveTabWidget(int) - ignoring order (bad index)!" << endl; }#endif}void MainWindow::inviteFromTreeview( const Gtk::TreeModel::Path&, Gtk::TreeViewColumn * ){ phoneSelected(); invite();}void MainWindow::inviteClick() { invite( uriEntry->get_text() );}void MainWindow::invite( string uri ){ if( uri.length() > 0 ){ //string id = callback->guicb_doInvite( uri ); CommandString inv("",SipCommandString::invite, uri); CommandString resp=callback->handleCommandResp("sip",inv); string id = resp.getDestinationId(); if( id == "malformed" ){ Gtk::MessageDialog dialog( "The SIP address you specified is not valid", Gtk::MESSAGE_WARNING ); dialog.show(); } addCall( id, uri, false ); }}void MainWindow::conference(){ string confid=itoa(rand()); //callback->guicb_confDoInvite("ali"); //string id = callback->guicb_doInvite( uri ); addConference( confid, "","","",false );}void MainWindow::imClick( ) { im( uriEntry->get_text() );}void MainWindow::im( string uri, string message ){ if( uri.length() > 0 ){ bool found = false; ImWidget * imW=NULL; for( list<ImWidget *>::iterator i = imWidgets.begin(); i != imWidgets.end(); i++ ){ if( (*i)->getToUri() == uri ){ mainTabWidget->set_current_page( mainTabWidget->page_num( **i ) ); imW = (*i); found = true; break; } } if( !found ) { imW = addIm( uri ); } if( message != "" && imW ) { imW->send( message ); } }}bool MainWindow::phoneSelect( const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeModel::Path& path, bool ){ const Gtk::TreeModel::iterator iter = model->get_iter( path ); /* Only the leaves can be selected */ return iter->children().empty();}void MainWindow::phoneSelected(){ Glib::RefPtr<Gtk::TreeSelection> treeSelection2 = phoneBookTreeView->get_selection(); Gtk::TreeModel::iterator iter = treeSelection2->get_selected(); if( iter ){ if( uriEntry ){ uriEntry->set_text( (*iter)[phoneBookModel->tree->uri] ); } }}void MainWindow::phoneTreeClicked( GdkEventButton * event ){ Gtk::TreeModel::Path path; Gtk::TreeViewColumn * column; int cellx,celly; bool gotPath; gotPath = phoneBookTreeView->get_path_at_pos( (int)event->x, (int)event->y, path, column, cellx, celly ); /* Collapse or expand the phonebook entries */ // FIXME: cellx >= 13 used to avoid the expander arrow, find // some proper way if( event->button == 1 && gotPath && path.get_depth() <= 1 && cellx >= 13){ if( phoneBookTreeView->row_expanded( path ) ){ phoneBookTreeView->collapse_row( path ); } else{ phoneBookTreeView->collapse_all(); phoneBookTreeView->expand_row( path, true ); } } /* right click: pop up the menu */ else if( event->button == 3 ){ Glib::RefPtr<Gtk::TreeSelection> treeSelection2 = phoneBookTreeView->get_selection(); bool noSelect = (treeSelection2->count_selected_rows() == 0 ); phoneAddAddressMenu->set_sensitive( !noSelect ); phoneRemoveMenu->set_sensitive( !noSelect ); phoneEditMenu->set_sensitive( !noSelect ); phoneMenu->popup( event->button, gtk_get_current_event_time() ); }}void MainWindow::handle( MRef<LogEntry *> logEntry ){ logEntriesLock.lock(); logEntries.push_front( logEntry ); logEntriesLock.unlock(); logDispatcher.emit();}void MainWindow::gotLogEntry(){ list<CallWidget *>::iterator i; logEntriesLock.lock(); MRef< LogEntry * > logEntry = logEntries.pop_back(); logEntriesLock.unlock(); logWidget->addLogEntry( logEntry );} void MainWindow::viewToggle( uint8_t w ){ Gtk::Widget * widget; Glib::ustring title; switch( w ){ case 0: widget = logWidget; title = "Call list"; break; case 1: widget = statusWidget; title = "Accounts"; break; default: return; } if( widget->is_visible() ){ mainTabWidget->remove_page( *widget ); widget->hide(); } else{ mainTabWidget->append_page( *widget, title ); mainTabWidget->show_all(); }}void MainWindow::setCallback( MRef<CommandReceiver*> callback ){ statusWidget->setCallback( callback ); settingsDialog->setCallback( callback ); handleCommand( CommandString( "", "sip_ready" ) ); Gui::setCallback( callback );}void MainWindow::runCertificateSettings(){ certificateDialog->run(); config->save();}static string ensureAbsolutePath( string fileName ){ if( Glib::path_is_absolute( fileName ) ){ return fileName; } else{ return Glib::build_filename( Glib::get_current_dir(), fileName ); }}string MainWindow::getDataFileName( string baseName ){ // Check last data dir if( !lastDataDir.empty() ){ string lastDirName = Glib::build_filename( lastDataDir, baseName ); if( Glib::file_test( lastDirName, Glib::FILE_TEST_EXISTS ) ){ return ensureAbsolutePath( lastDirName ); } }#ifdef MINISIP_DATADIR // Check configured data dir string dataDirName = Glib::build_filename( MINISIP_DATADIR, baseName ); if( Glib::file_test( dataDirName, Glib::FILE_TEST_EXISTS ) ){ lastDataDir = MINISIP_DATADIR; return ensureAbsolutePath( dataDirName ); }#endif // Check share sub directory in the program directory string progDirName = Glib::build_filename( Glib::build_filename( programDir, "share" ), baseName ); if( Glib::file_test( progDirName, Glib::FILE_TEST_EXISTS ) ){ lastDataDir = Glib::build_filename( programDir, "share" ); return ensureAbsolutePath( progDirName ); } merr << "Can't find data file: " << baseName << end; return "";}void MainWindow::registerIcons(){ factory = Gtk::IconFactory::create(); Gtk::IconSet * iconSet = new Gtk::IconSet; Gtk::IconSource * iconSource = new Gtk::IconSource; iconSource->set_filename( getDataFileName( "secure.png" ) ); iconSource->set_size( Gtk::ICON_SIZE_DIALOG ); iconSet->add_source( *iconSource ); factory->add( Gtk::StockID( "minisip_secure" ), *iconSet ); delete iconSource; delete iconSet; iconSource = new Gtk::IconSource; iconSet = new Gtk::IconSet; iconSource->set_filename( getDataFileName( "insecure.png" ) ); iconSource->set_size( Gtk::ICON_SIZE_DIALOG ); iconSet->add_source( *iconSource ); factory->add( Gtk::StockID( "minisip_insecure" ), *iconSet ); delete iconSource; delete iconSet; iconSource = new Gtk::IconSource; iconSet = new Gtk::IconSet; iconSource->set_filename( getDataFileName( "play.png" ) ); iconSource->set_size( Gtk::ICON_SIZE_BUTTON ); iconSet->add_source( *iconSource ); factory->add( Gtk::StockID( "minisip_play" ), *iconSet ); delete iconSource; delete iconSet; iconSource = new Gtk::IconSource; iconSet = new Gtk::IconSet; iconSource->set_filename( getDataFileName( "noplay.png" ) ); iconSource->set_size( Gtk::ICON_SIZE_BUTTON ); iconSet->add_source( *iconSource ); factory->add( Gtk::StockID( "minisip_noplay" ), *iconSet ); delete iconSource; delete iconSet; iconSource = new Gtk::IconSource; iconSet = new Gtk::IconSet; iconSource->set_filename( getDataFileName( "record.png" ) ); iconSource->set_size( Gtk::ICON_SIZE_BUTTON ); iconSet->add_source( *iconSource ); factory->add( Gtk::StockID( "minisip_record" ), *iconSet ); delete iconSource; delete iconSet; iconSource = new Gtk::IconSource; iconSet = new Gtk::IconSet; iconSource->set_filename( getDataFileName( "norecord.png" ) ); iconSource->set_size( Gtk::ICON_SIZE_BUTTON ); iconSet->add_source( *iconSource ); factory->add( Gtk::StockID( "minisip_norecord" ), *iconSet ); factory->add_default(); delete iconSet; delete iconSource;}void MainWindow::dtmfPressed( uint8_t symbol ){ Glib::ustring uri = uriEntry->get_text(); switch( symbol ){ case 1: uri += "1"; break; case 2: uri += "2"; break; case 3: uri += "3"; break; case 4: uri += "4"; break; case 5: uri += "5"; break; case 6: uri += "6"; break; case 7: uri += "7"; break; case 8: uri += "8"; break; case 9: uri += "9"; break; case 0: uri += "0"; break; } uriEntry->set_text( uri );}void MainWindow::onTabChange( GtkNotebookPage * page, guint index ){ Gtk::Widget * currentPage = mainTabWidget->get_nth_page( index ); CallWidget * callWidget = NULL; ConferenceWidget *confWidget = NULL; ImWidget * imWidget = NULL; //cast the current page to the possible media widgets ... callWidget = dynamic_cast< CallWidget *>( currentPage ); if( callWidget == NULL ) confWidget = dynamic_cast< ConferenceWidget *>( currentPage ); if( confWidget == NULL ) imWidget = dynamic_cast< ImWidget *>( currentPage ); //go through all the widgets, notifying them of the change list<CallWidget *>::iterator iterCall; for( iterCall = callWidgets.begin(); iterCall != callWidgets.end(); iterCall++ ) { bool equal = false; if( callWidget ) equal = (callWidget == (*iterCall) ); (*iterCall)->activeWidgetChanged( equal, index ); } list<ConferenceWidget *>::iterator iterConf; for( iterConf = conferenceWidgets.begin(); iterConf != conferenceWidgets.end(); iterConf++ ) { bool equal = false; if( confWidget ) equal = (confWidget == (*iterConf) ); (*iterConf)->activeWidgetChanged( equal, index ); } list<ImWidget *>::iterator iterIm; for( iterIm = imWidgets.begin(); iterIm != imWidgets.end(); iterIm++ ) { bool equal = false; if( imWidget ) equal = (imWidget == (*iterIm) ); (*iterIm)->activeWidgetChanged( equal, index ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -