broadcast_win.cc
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:7k
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- */
- #include <unistd.h>
- #include <gtk--.h>
- #include "gtk_text_win.h"
- #include "broadcast_win.h"
- const int BroadcastWindow::topWindowInitSizeX = 600;
- const int BroadcastWindow::topWindowInitSizeY = 400;
- const int BroadcastWindow::channelListColumns = 4;
- BroadcastWindow::BroadcastWindow( Session &s )
- : session( s ), current_channel_id( -1 ), playing( false )
- {
- set_usize( topWindowInitSizeX, topWindowInitSizeY );
- // make vertical box
- Gtk_VBox *top_vbox_layout = new Gtk_VBox();
- top_vbox_layout->set_spacing( 10 );
- {
- // create menu bar
- menuBar = new Gtk_MenuBar();
- // create menu 'File'
- Gtk_MenuItem *viewMenuRootItem = new Gtk_MenuItem( "View" );
- menuBar->append( *viewMenuRootItem );
- menuBar->show();
- Gtk_Menu *viewMenu = new Gtk_Menu();
- viewMenuRootItem->set_submenu( *viewMenu );
- viewMenuRootItem->show();
- Gtk_MenuItem *updChMenuItem = new Gtk_MenuItem( "Update channel" );
- viewMenu->append( *updChMenuItem );
- updChMenuItem->show();
- // connect entries
- connect_to_method( updChMenuItem->activate, this,
- &BroadcastWindow::callback_update_channellist );
- // pack to vbox container
- top_vbox_layout->pack_start( *menuBar, FALSE, FALSE, 0 );
- // handle box
- Gtk_HandleBox *handleBox = new Gtk_HandleBox();
- top_vbox_layout->pack_start( *handleBox, FALSE, FALSE, 0 );
- handleBox->show();
- // toolbar for handle box
- Gtk_Toolbar *toolbar = new Gtk_Toolbar();
- handleBox->add( toolbar );
- toolbar->show();
- // buttons:
- // start button
- Gtk_Button *bst = new Gtk_ImageTextButton( session.PlayPixmap.c_str(),"");
- bst->show();
- toolbar->add( bst );
- connect_to_method( bst->clicked, this,
- &BroadcastWindow::callback_play );
- // stop button
- Gtk_Button *bsto = new Gtk_ImageTextButton( session.StopPixmap.c_str(),"");
- bsto->show();
- toolbar->add( bsto );
- connect_to_method( bsto->clicked, this,
- &BroadcastWindow::callback_stop );
- // record button
- Gtk_Button *bre = new Gtk_ImageTextButton( session.RecPixmap.c_str(),"");
- bre->show();
- toolbar->add( bre );
- connect_to_method( bre->clicked, this,
- &BroadcastWindow::callback_record );
- // stop recording button
- Gtk_Button *bstr = new Gtk_ImageTextButton( session.StopPixmap.c_str(),"");
- bstr->show();
- toolbar->add( bstr );
- connect_to_method( bstr->clicked, this,
- &BroadcastWindow::callback_stop_recording );
- // status bar
- statusBar = new Gtk_Statusbar();
- top_vbox_layout->pack_end( *statusBar, FALSE, FALSE, 0 );
- statusBar->show();
- // channel list
- static char *ch_col_text[channelListColumns] =
- { "", "channel", "description", "active" };
- GtkWidget *ch_clist;
- ch_clist = gtk_clist_new_with_titles( channelListColumns, ch_col_text );
- channelList = new Gtk_CList( GTK_CLIST (ch_clist) );
- channelList->set_usize( topWindowInitSizeX, topWindowInitSizeY/4 );
- channelList->set_column_width( 0, 10 );
- channelList->set_column_width( 2, topWindowInitSizeX/2 );
- channelList->set_selection_mode( GTK_SELECTION_BROWSE );
- channelList->show();
- // channelList is inside the scrolled window
- Gtk_ScrolledWindow *ch_scrolled_win = new Gtk_ScrolledWindow ();
- ch_scrolled_win->show();
- ch_scrolled_win->set_policy (GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- ch_scrolled_win->add( *channelList );
- // connect
- connect_to_method( channelList->select_row, this,
- &BroadcastWindow::callback_channel_select_row );
- // text
- static char *col_text[3] = { "", "text", "date" };
- GtkWidget *clist;
- clist = gtk_clist_new_with_titles( 3, col_text );
- movieText = new Gtk_CList( GTK_CLIST (clist) );
- movieText->set_usize( topWindowInitSizeX, topWindowInitSizeY*3/4 );
- movieText->set_column_width( 0, 10 );
- movieText->set_column_width( 1, topWindowInitSizeX *3/4);
- movieText->show();
- // movieText is inside the scrolled window
- Gtk_ScrolledWindow *scrolled_win = new Gtk_ScrolledWindow ();
- scrolled_win->show();
- scrolled_win->set_policy (GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- scrolled_win->add( *movieText );
- // pack ch_scrolled_win and scrolled_win to vertical pane
- Gtk_VPaned *vp = new Gtk_VPaned();
- top_vbox_layout->pack_start( *vp, TRUE, TRUE, 0 );
- vp->show();
- vp->add1( *ch_scrolled_win );
- vp->add2( *scrolled_win );
- }
- add( top_vbox_layout );
- top_vbox_layout->show();
- set_title( "Broadcast and Acquisition options" );
- callback_update_channellist();
- }
- void BroadcastWindow::callback_play()
- {
- channel_infos_mapT::iterator it;
- it = channel_infos_map.find( current_channel_id );
- if( it != channel_infos_map.end() )
- {
- session.playBroadcast( (*it).second->get_url() );
- playing = true;
- }
- else // error
- session.put_message( 0, "Can't play broadcast channel #%d",
- current_channel_id );
- }
- void BroadcastWindow::callback_stop()
- {
- playing = false;
- session.stop();
- }
- void BroadcastWindow::callback_record()
- {
- session.start_recording( current_channel_id );
- }
- void BroadcastWindow::callback_stop_recording()
- {
- session.stop_recording( current_channel_id );
- }
- void BroadcastWindow::callback_channel_select_row
- ( gint row, gint col, GdkEvent *button )
- {
- // row data must hold the channel id
- current_channel_id = (int) channelList->get_row_data( row );
- }
- void BroadcastWindow::callback_update_channellist()
- {
- // the currently selected channel should remains unchanged after
- // this operation
- int row_to_be_selected = -1;
- session.fill_channellist( channel_infos_map );
- // renew the list
- channelList->freeze();
- channelList->clear();
- channel_infos_mapT::iterator it;
- char text[channelListColumns][100];
- const gchar *texts[channelListColumns];
- for( int i = 0; i < channelListColumns; i++ )
- texts[i] = text[i];
- for( it = channel_infos_map.begin(); it != channel_infos_map.end(); it++ )
- {
- int id = (*it).first;
- channel_info &chi = *(*it).second;
- text[0][0] = '';
- sprintf( text[1], "%d", id );
- strcpy( text[2], chi.get_description().c_str() );
- cerr << chi.is_active() << endl;
- if( chi.is_active() )
- strcpy( text[3], "active" );
- else
- strcpy( text[3], "not active" );
- int row = channelList->append( texts );
- // set row data to be Id
- channelList->set_row_data( row, (gpointer) (*it).first );
- // which row to select at the end
- if( id == current_channel_id )
- row_to_be_selected = row;
- }
- channelList->thaw();
- if( row_to_be_selected != -1 )
- channelList->cause_select_row( row_to_be_selected, 0 );
- else
- channelList->cause_select_row( 0, 0 );
- }