broadcast_win.cc
上传用户:psq1974
上传日期:2007-01-06
资源大小:1195k
文件大小:7k
源码类别:

mpeg/mp3

开发平台:

C/C++

  1. /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
  2.    Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
  3.    Software license is located in file "COPYING"
  4. */
  5. #include  <unistd.h>
  6. #include  <gtk--.h>
  7. #include "gtk_text_win.h"
  8. #include "broadcast_win.h"
  9. const int BroadcastWindow::topWindowInitSizeX = 600;
  10. const int BroadcastWindow::topWindowInitSizeY = 400;
  11. const int BroadcastWindow::channelListColumns = 4;
  12. BroadcastWindow::BroadcastWindow( Session &s )
  13.   : session( s ), current_channel_id( -1 ), playing( false )
  14. {
  15.   set_usize( topWindowInitSizeX, topWindowInitSizeY );
  16.   // make vertical box
  17.   Gtk_VBox *top_vbox_layout = new Gtk_VBox();
  18.   top_vbox_layout->set_spacing( 10 );
  19.   {
  20.     // create menu bar
  21.     menuBar = new Gtk_MenuBar();
  22.     // create menu 'File'
  23.     Gtk_MenuItem *viewMenuRootItem = new Gtk_MenuItem( "View" );
  24.     menuBar->append( *viewMenuRootItem );
  25.     menuBar->show();
  26.     Gtk_Menu     *viewMenu = new Gtk_Menu();
  27.     viewMenuRootItem->set_submenu( *viewMenu );
  28.     viewMenuRootItem->show();
  29.     Gtk_MenuItem *updChMenuItem = new Gtk_MenuItem( "Update channel" );
  30.     viewMenu->append( *updChMenuItem );
  31.     updChMenuItem->show();
  32.     // connect entries
  33.     connect_to_method( updChMenuItem->activate, this, 
  34.        &BroadcastWindow::callback_update_channellist );
  35.     // pack to vbox container
  36.     top_vbox_layout->pack_start( *menuBar, FALSE, FALSE, 0 );
  37.     // handle box
  38.     Gtk_HandleBox *handleBox = new Gtk_HandleBox();
  39.     top_vbox_layout->pack_start( *handleBox, FALSE, FALSE, 0 );
  40.     handleBox->show();
  41.     // toolbar for handle box
  42.     Gtk_Toolbar *toolbar = new Gtk_Toolbar();
  43.     handleBox->add( toolbar );
  44.     toolbar->show();
  45.     // buttons:
  46.     // start button
  47.     Gtk_Button *bst = new Gtk_ImageTextButton( session.PlayPixmap.c_str(),"");
  48.     bst->show();
  49.     toolbar->add( bst );
  50.     connect_to_method( bst->clicked, this, 
  51.        &BroadcastWindow::callback_play );
  52.     // stop button
  53.     Gtk_Button *bsto = new Gtk_ImageTextButton( session.StopPixmap.c_str(),"");
  54.     bsto->show();
  55.     toolbar->add( bsto );
  56.     connect_to_method( bsto->clicked, this, 
  57.        &BroadcastWindow::callback_stop );
  58.     // record button
  59.     Gtk_Button *bre = new Gtk_ImageTextButton( session.RecPixmap.c_str(),"");
  60.     bre->show();
  61.     toolbar->add( bre );
  62.     connect_to_method( bre->clicked, this, 
  63.        &BroadcastWindow::callback_record );
  64.     // stop recording button
  65.     Gtk_Button *bstr = new Gtk_ImageTextButton( session.StopPixmap.c_str(),"");
  66.     bstr->show();
  67.     toolbar->add( bstr );
  68.     connect_to_method( bstr->clicked, this, 
  69.        &BroadcastWindow::callback_stop_recording );
  70.     // status bar
  71.     statusBar = new Gtk_Statusbar();
  72.     top_vbox_layout->pack_end( *statusBar, FALSE, FALSE, 0 );
  73.     statusBar->show();
  74.     // channel list
  75.     static char *ch_col_text[channelListColumns] = 
  76.     { "", "channel", "description", "active" };
  77.     GtkWidget *ch_clist;
  78.     ch_clist = gtk_clist_new_with_titles( channelListColumns, ch_col_text );
  79.     channelList = new Gtk_CList( GTK_CLIST (ch_clist) );
  80.     channelList->set_usize( topWindowInitSizeX, topWindowInitSizeY/4 );
  81.     channelList->set_column_width( 0, 10 );
  82.     channelList->set_column_width( 2, topWindowInitSizeX/2 );
  83.     channelList->set_selection_mode( GTK_SELECTION_BROWSE );
  84.     channelList->show();
  85.     // channelList is inside the scrolled window
  86.     Gtk_ScrolledWindow *ch_scrolled_win = new Gtk_ScrolledWindow ();
  87.     ch_scrolled_win->show();
  88.     ch_scrolled_win->set_policy (GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  89.     ch_scrolled_win->add( *channelList );
  90.     // connect
  91.     connect_to_method( channelList->select_row, this, 
  92.        &BroadcastWindow::callback_channel_select_row );
  93.     // text
  94.     static char *col_text[3] = { "", "text", "date" };
  95.     GtkWidget *clist;
  96.     clist = gtk_clist_new_with_titles( 3, col_text );
  97.     movieText = new Gtk_CList( GTK_CLIST (clist) );
  98.     movieText->set_usize( topWindowInitSizeX, topWindowInitSizeY*3/4 );
  99.     movieText->set_column_width( 0, 10 );
  100.     movieText->set_column_width( 1, topWindowInitSizeX *3/4);
  101.     movieText->show();
  102.     // movieText is inside the scrolled window
  103.     Gtk_ScrolledWindow *scrolled_win = new Gtk_ScrolledWindow ();
  104.     scrolled_win->show();
  105.     scrolled_win->set_policy (GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  106.     scrolled_win->add( *movieText );
  107.     // pack ch_scrolled_win and scrolled_win to vertical pane
  108.     Gtk_VPaned *vp = new Gtk_VPaned();
  109.     top_vbox_layout->pack_start( *vp, TRUE, TRUE, 0 );
  110.     vp->show();
  111.     vp->add1( *ch_scrolled_win );
  112.     vp->add2( *scrolled_win );
  113.   }
  114.   add( top_vbox_layout );
  115.   top_vbox_layout->show();
  116.   set_title( "Broadcast and Acquisition options" );
  117.   callback_update_channellist();
  118. }
  119. void BroadcastWindow::callback_play()
  120. {
  121.   channel_infos_mapT::iterator it;
  122.   it = channel_infos_map.find( current_channel_id );
  123.   if( it != channel_infos_map.end() )
  124.     {
  125.       session.playBroadcast( (*it).second->get_url() );
  126.       playing = true;
  127.     }
  128.   else  // error
  129.     session.put_message( 0, "Can't play broadcast channel #%d", 
  130.  current_channel_id );
  131. }
  132. void BroadcastWindow::callback_stop()
  133. {
  134.   playing = false;
  135.   session.stop();
  136. }
  137. void BroadcastWindow::callback_record()
  138. {
  139.   session.start_recording( current_channel_id );
  140. }
  141. void BroadcastWindow::callback_stop_recording()
  142. {
  143.   session.stop_recording( current_channel_id );
  144. }
  145. void BroadcastWindow::callback_channel_select_row
  146. ( gint row, gint col, GdkEvent *button )
  147. {
  148.   // row data must hold the channel id
  149.   current_channel_id = (int) channelList->get_row_data( row );
  150. }
  151. void BroadcastWindow::callback_update_channellist()
  152. {
  153.   // the currently selected channel should remains unchanged after 
  154.   // this operation
  155.   int row_to_be_selected = -1;
  156.   session.fill_channellist( channel_infos_map );
  157.   // renew the list
  158.   channelList->freeze();
  159.   channelList->clear();
  160.   channel_infos_mapT::iterator it;
  161.   char text[channelListColumns][100];
  162.   const gchar *texts[channelListColumns];
  163.   for( int i = 0; i < channelListColumns; i++ )
  164.     texts[i] = text[i];
  165.   for( it = channel_infos_map.begin(); it != channel_infos_map.end(); it++ )
  166.     {
  167.       int id = (*it).first;
  168.       channel_info &chi = *(*it).second;
  169.       text[0][0] = '';
  170.       sprintf( text[1], "%d", id );
  171.       strcpy( text[2], chi.get_description().c_str() );
  172.       cerr << chi.is_active() << endl;
  173.       if( chi.is_active() )
  174. strcpy( text[3], "active" );
  175.       else
  176. strcpy( text[3], "not active" );
  177.       int row = channelList->append( texts );
  178.       // set row data to be Id
  179.       channelList->set_row_data( row, (gpointer) (*it).first );
  180.       // which row to select at the end
  181.       if( id == current_channel_id )
  182. row_to_be_selected = row;
  183.     }
  184.   channelList->thaw();
  185.   if( row_to_be_selected != -1 )
  186.     channelList->cause_select_row( row_to_be_selected, 0 );
  187.   else
  188.     channelList->cause_select_row( 0, 0 );
  189. }