gmyth/src/gui/mmyth_ui.c.r2518
author leo_sobral
Wed Sep 20 23:45:35 2006 +0100 (2006-09-20)
branchtrunk
changeset 1 ffdf467315ec
permissions -rw-r--r--
[svn r2] imported to sf repository
     1 
     2 #include <gtk/gtk.h>
     3 #include <gdk/gdkx.h>
     4 #include <gst/interfaces/xoverlay.h>
     5 
     6 #include "mmyth_ui.h"
     7 #include "mmyth_uicommon.h"
     8 /* FIXME
     9 #include "mmyth_videoplayer.h"
    10 #include "mmyth_esg_grid_view.h"
    11 #include "mmyth_common.h"
    12 */
    13 
    14 static gint button_press_handler (GtkWidget *widget, GdkEvent *event);
    15 
    16 MMythUiCommon *create_main_view (MMythUi * mmyth_ui);
    17 MMythUiCommon *create_video_view (MMythUi * mmyth_ui);
    18 MMythUiCommon *create_esg_grid_view (MMythUi * mmyth_ui);
    19 static void cb_video_close_button (GtkButton * button, gpointer user_data);
    20 
    21 /* main box from button box separator*/
    22 static GtkWidget *main_vseparator = NULL;
    23 
    24 GdkPixbuf *icon_sports, *icon_news, 
    25           *icon_movies, *icon_shows, *icon_default;
    26 
    27 /* FIXME: UGLY HACK */
    28 MMythUi *popup_mmyth_ui;
    29 
    30 void
    31 mmyth_ui_initialize_icons ()
    32 {
    33     GError *error = NULL;
    34 
    35 #ifdef MMYTH_DEVEL
    36     icon_sports =
    37         gdk_pixbuf_new_from_file ("../pixmaps/ico_sports.png", &error);
    38 #else
    39     icon_sports = gdk_pixbuf_new_from_file (PIX_DIR "ico_sports.png", &error);
    40 #endif
    41 
    42     if (error) {
    43         g_warning ("Could not load icon sports: %s\n", error->message);
    44         g_error_free (error);
    45         error = NULL;
    46     }
    47 
    48 #ifdef MMYTH_DEVEL
    49     icon_news = gdk_pixbuf_new_from_file ("../pixmaps/ico_news.png", &error);
    50 #else
    51     icon_news = gdk_pixbuf_new_from_file (PIX_DIR "ico_news.png", &error);
    52 #endif
    53 
    54     if (error) {
    55         g_warning ("Could not load icon news: %s\n", error->message);
    56         g_error_free (error);
    57         error = NULL;
    58     }
    59 
    60 #ifdef MMYTH_DEVEL
    61     icon_movies =
    62         gdk_pixbuf_new_from_file ("../pixmaps/ico_movies.png", &error);
    63 #else
    64     icon_movies = gdk_pixbuf_new_from_file (PIX_DIR "ico_movies.png", &error);
    65 #endif
    66     if (error) {
    67         g_warning ("Could not load icon movies: %s\n", error->message);
    68         g_error_free (error);
    69         error = NULL;
    70     }
    71 
    72 #ifdef MMYTH_DEVEL
    73     icon_shows = gdk_pixbuf_new_from_file ("../pixmaps/ico_shows.png", &error);
    74 #else
    75     icon_shows = gdk_pixbuf_new_from_file (PIX_DIR "ico_shows.png", &error);
    76 #endif
    77     if (error) {
    78         g_warning ("Could not load icon shows: %s\n", error->message);
    79         g_error_free (error);
    80         error = NULL;
    81     }
    82 
    83 #ifdef MMYTH_DEVEL
    84     icon_default =
    85         gdk_pixbuf_new_from_file ("../pixmaps/ico_default.png", &error);
    86 #else
    87     icon_default = gdk_pixbuf_new_from_file (PIX_DIR "ico_default.png", &error);
    88 #endif
    89 
    90     if (error) {
    91         g_warning ("Could not load icon default: %s\n", error->message);
    92         g_error_free (error);
    93         error = NULL;
    94     }
    95 
    96 }
    97 
    98 MMythUi *
    99 mmyth_ui_initialize (GtkWidget * main_window)
   100 {
   101     MMythUi *mmyth_ui;
   102 
   103 	// FIXME: REMOVE ME
   104 	//mmyth_settings_load ( );
   105     
   106     mmyth_ui = g_new0 (MMythUi, 1);
   107 
   108     mmyth_ui->main_window = main_window;    
   109 
   110     /* Horizontal box that divides the view into control and video area */
   111     mmyth_ui->main_hbox = gtk_hbox_new (FALSE, 0);
   112     gtk_widget_show (mmyth_ui->main_hbox);
   113     g_object_ref (mmyth_ui->main_hbox);
   114 
   115     mmyth_ui_initialize_icons ();
   116     
   117     main_bg_color.red   = 65000;
   118     main_bg_color.green = 65000;
   119     main_bg_color.blue  = 65000;
   120     
   121     // Main widget is mmyth_ui->main_hbox
   122     mmyth_ui->main_uicommon       = create_main_view (mmyth_ui);
   123     mmyth_ui->video_uicommon      = create_video_view (mmyth_ui);
   124     mmyth_ui->esg_grid_uicommon   = create_esg_grid_view (mmyth_ui);
   125 
   126     /* Popup menu */
   127     /* FIXME: URGENT ugly, ugly hack */
   128     popup_mmyth_ui = mmyth_ui;
   129     g_signal_connect (G_OBJECT (mmyth_ui->main_hbox), "event",
   130                       G_CALLBACK (button_press_handler),
   131                       G_OBJECT (mmyth_ui->main_hbox));    
   132     
   133     gtk_container_add (GTK_CONTAINER (mmyth_ui->main_window),
   134                        mmyth_ui->main_hbox);
   135 
   136     /* Add the gst video widget to hbox. It should never be removed. */    
   137     /* FIXME: mmyth_ui->video_alignment == NULL when mmyth_player_init fails */
   138     if(mmyth_ui->video_alignment != NULL)
   139         gtk_box_pack_start (GTK_BOX (mmyth_ui->main_hbox),
   140                             mmyth_ui->video_alignment, TRUE, TRUE, 0);    
   141 
   142     mmyth_ui_set_widget (mmyth_ui, mmyth_ui->main_uicommon);
   143 
   144     return mmyth_ui;
   145 }
   146 
   147 void
   148 mmyth_ui_finalize (MMythUi * mmyth_ui)
   149 {
   150     if (mmyth_ui != NULL)
   151         g_free (mmyth_ui);
   152 
   153     mmyth_uicommon_unref_all (mmyth_ui->main_uicommon);
   154     mmyth_uicommon_unref_all (mmyth_ui->video_uicommon);
   155     mmyth_uicommon_unref_all (mmyth_ui->esgcurrent_uicommon);
   156 }
   157 
   158 void
   159 mmyth_ui_set_widget (MMythUi * mmyth_ui, MMythUiCommon * new_uicommon)
   160 {
   161     if (mmyth_ui->current_uicommon) {
   162         if (mmyth_ui->current_uicommon == mmyth_ui->video_uicommon) {
   163             gtk_widget_hide (mmyth_ui->current_uicommon->main_widget);
   164             gtk_widget_hide (mmyth_ui->videow);
   165         }
   166         else {
   167             gtk_container_remove (GTK_CONTAINER (mmyth_ui->main_hbox),
   168                                   mmyth_ui->current_uicommon->main_widget);
   169         }
   170 
   171         gtk_container_remove (GTK_CONTAINER (mmyth_ui->main_hbox),
   172                               mmyth_ui->current_uicommon->event_box);
   173         gtk_container_remove (GTK_CONTAINER (mmyth_ui->main_hbox),
   174                               main_vseparator);        
   175 
   176     }
   177 
   178     if (new_uicommon->main_widget == mmyth_ui->video_alignment) {
   179         //gst_player_video_show (GST_PLAYER_VIDEO(mmyth_ui->videow));
   180         gtk_widget_show (mmyth_ui->video_alignment);
   181         gtk_widget_show (mmyth_ui->videow);
   182     }
   183     else {
   184         /* FIXME: Fst call is NULL when mmyth_player_init fails */
   185         if(mmyth_ui->video_alignment != NULL)
   186             gtk_widget_hide (mmyth_ui->video_alignment);
   187         /* FIXME: Fst call is NULL when mmyth_player_init fails */
   188         if(mmyth_ui->videow != NULL)
   189             gtk_widget_hide (mmyth_ui->videow);
   190 
   191         gtk_box_pack_start (GTK_BOX (mmyth_ui->main_hbox),
   192                             new_uicommon->main_widget, TRUE, TRUE, 0);
   193     }
   194 
   195     if(main_vseparator == NULL) {
   196         /* FIXME: should free this variable*/
   197         main_vseparator = gtk_vseparator_new();
   198         g_object_ref (main_vseparator);                   
   199     }  
   200     gtk_box_pack_start (GTK_BOX (mmyth_ui->main_hbox),
   201                         main_vseparator, FALSE, FALSE, 0);    
   202     gtk_widget_show (main_vseparator);
   203 
   204     gtk_box_pack_end (GTK_BOX (mmyth_ui->main_hbox), new_uicommon->event_box, FALSE,
   205                       FALSE, 0);         
   206 
   207     mmyth_ui->current_uicommon = new_uicommon;
   208 
   209 }
   210 
   211 /* The close callback is the same for all windows*/
   212 static void
   213 cb_not_impl_button (GtkButton * button, gpointer user_data)
   214 {
   215     MMythUi *mmyth_ui = (MMythUi *) user_data;
   216 
   217     GtkWidget *msg_dialog = gtk_message_dialog_new (
   218                                            GTK_WINDOW(mmyth_ui->main_window),
   219                                            GTK_DIALOG_MODAL |
   220                                            GTK_DIALOG_DESTROY_WITH_PARENT,
   221                                            GTK_MESSAGE_INFO,
   222                                            GTK_BUTTONS_OK,
   223                                            "Feature not implemented yet");
   224     gtk_widget_set_size_request (msg_dialog, 300, 120);
   225 
   226     gtk_dialog_run (GTK_DIALOG (msg_dialog));
   227 
   228     gtk_widget_destroy(GTK_WIDGET(msg_dialog)); 
   229 }
   230 
   231 /******************************************************************************
   232  *                        POPUP MENU WIDGET METHODS                           *
   233  *****************************************************************************/
   234 
   235 void 
   236 detacher (GtkWidget *attach_widget,GtkMenu *menu) 
   237 {
   238 }
   239 
   240 void 
   241 menu_item_settings_cb (GtkMenuItem *menuitem,
   242                             gpointer user_data)
   243 {
   244     /* MMythUi *mmyth_ui = (MMythUi *) user_data; */
   245 
   246     /* FIXME
   247     MMythUi *mmyth_ui = popup_mmyth_ui;
   248     
   249     settings_show_dialog (GTK_WINDOW (mmyth_ui->main_window));    
   250     */
   251 }
   252 
   253 static void
   254 do_popup_menu (GtkWidget *my_widget, GdkEventButton *event)
   255 {
   256     GtkWidget *popup;
   257     int button, event_time;
   258     
   259     popup = gtk_menu_new ();
   260     
   261     /* ... add menu items ... */
   262     GtkWidget *menu_item = gtk_menu_item_new_with_label("Settings");
   263     gtk_menu_append(popup, menu_item);
   264     
   265     g_signal_connect (G_OBJECT(menu_item), "activate", 
   266                       G_CALLBACK (menu_item_settings_cb), NULL);
   267     
   268     if (event)
   269     {
   270       button = event->button;
   271       event_time = event->time;
   272     }
   273     else
   274     {
   275       button = 0;
   276       event_time = gtk_get_current_event_time ();
   277     }
   278     
   279     //gtk_menu_attach_to_widget (GTK_MENU (popup), my_widget, detacher);
   280     gtk_menu_popup (GTK_MENU (popup), NULL, NULL, NULL, NULL, 
   281                   button, event_time);
   282     gtk_widget_show_all(popup);
   283 }
   284 
   285 /* Respond to a button-press by posting a menu passed in as widget.
   286  *
   287  * Note that the "widget" argument is the menu being posted, NOT
   288  * the button that was pressed.
   289  */
   290 
   291 static gint 
   292 button_press_handler (GtkWidget *widget, GdkEvent *event)
   293 {
   294 
   295     if (event->type == GDK_BUTTON_PRESS) {
   296       GdkEventButton *bevent = (GdkEventButton *) event; 
   297           /* Ignore double-clicks and triple-clicks */
   298       if (bevent->button == 3)
   299         {
   300           do_popup_menu (widget, bevent);
   301           return TRUE;
   302         }
   303     }
   304 
   305     /* Tell calling code that we have not handled this event; pass it on. */
   306     return FALSE;
   307 }
   308 
   309 
   310 /******************************************************************************
   311  *                          MAIN APP VIEW METHODS                             *
   312  *****************************************************************************/
   313 
   314 /* The close callback is the same for all windows*/
   315 static void
   316 cb_close_button (GtkButton * button, gpointer user_data)
   317 {
   318     MMythUi *mmyth_ui = (MMythUi *) user_data;
   319 
   320     mmyth_ui_set_widget (mmyth_ui, mmyth_ui->main_uicommon);
   321 }
   322 
   323 /* FIXME
   324 static void 
   325 cb_esg_today_button (GtkButton * button, gpointer user_data)
   326 {
   327     MMythUi *mmyth_ui = (MMythUi *) user_data;
   328 
   329     mmyth_ui_set_widget (mmyth_ui, mmyth_ui->esg_grid_uicommon);
   330 }
   331 */
   332 
   333 MMythUiCommon *
   334 create_main_view (MMythUi * mmyth_ui)
   335 {
   336     MMythUiCommon *ui_common;
   337     GtkWidget *main_widget;
   338     GtkWidget *image;
   339 
   340     // FIXME: file path
   341 #ifdef MMYTH_DEV
   342     image = gtk_image_new_from_file ("../pixmaps/main_logo.gif");
   343 #else
   344     image = gtk_image_new_from_file ("../pixmaps/main_logo.gif");
   345 #endif
   346     
   347     main_widget = gtk_event_box_new();
   348     
   349     gtk_container_add (GTK_CONTAINER (main_widget),
   350                        image);
   351     
   352 
   353     gtk_widget_show_all (main_widget);
   354     g_object_ref (main_widget);
   355 
   356     ui_common = mmyth_uicommon_new (main_widget,
   357                                     "Channels", "Current", "Today");
   358 
   359     /* Button signals */
   360     /* FIXME
   361     g_signal_connect (G_OBJECT (ui_common->button1), "clicked",
   362                       G_CALLBACK (cb_channels_button), mmyth_ui);
   363     g_signal_connect (G_OBJECT (ui_common->button2), "clicked",
   364                       G_CALLBACK (cb_esg_current_button), mmyth_ui);
   365     g_signal_connect (G_OBJECT (ui_common->button3), "clicked",
   366                       G_CALLBACK (cb_esg_today_button), mmyth_ui);
   367     */
   368 
   369     return ui_common;
   370 
   371 }
   372 
   373 /******************************************************************************
   374  *                         ESG GRID VIEW METHODS                              *
   375  *****************************************************************************/
   376 
   377 static void
   378 cb_esg_grid_view_button (GtkButton * button, gpointer user_data)
   379 {
   380     /* FIXME 
   381     MMythUi *mmyth_ui = (MMythUi *) user_data;
   382     guint32 service_id = -1;
   383 
   384     // Retrieves the user selected service ID 
   385     DVBHScheduleEvent *schedule = (DVBHScheduleEvent *) mmyth_esg_grid_view_get_selected_schedule();
   386     
   387     if(schedule != NULL) {
   388         service_id = schedule->service->number;
   389         mmyth_play_channel (mmyth_ui, service_id);    
   390     }
   391     */
   392 }
   393 
   394 MMythUiCommon *
   395 create_esg_grid_view (MMythUi * mmyth_ui)
   396 {
   397     MMythUiCommon *ui_common;        
   398     /* FIXME
   399     GtkWidget *esg_grid_view = GTK_WIDGET (esg_grid_view_new (mmyth_ui));
   400     
   401     
   402     ui_common = mmyth_uicommon_new (esg_grid_view,
   403                                     "View", "Remind",
   404                                     "Close");    
   405     */
   406     
   407     /* Button signals */
   408     g_signal_connect (G_OBJECT (ui_common->button1), "clicked",
   409                       G_CALLBACK (cb_esg_grid_view_button), mmyth_ui);
   410     g_signal_connect (G_OBJECT (ui_common->button2), "clicked",
   411                       G_CALLBACK (cb_not_impl_button), mmyth_ui);
   412     g_signal_connect (G_OBJECT (ui_common->button3), "clicked",
   413                       G_CALLBACK (cb_close_button), mmyth_ui);
   414     
   415     return ui_common;
   416 }
   417 
   418 /******************************************************************************
   419  *                         GST VIDEO WIDGET METHODS                           *
   420  *****************************************************************************/
   421 
   422 static void
   423 cb_video_close_button (GtkButton * button, gpointer user_data)
   424 {
   425     MMythUi *mmyth_ui = (MMythUi *) user_data;
   426 
   427     /* FIXME
   428     mmyth_player_stop (mmyth_ui);
   429     */
   430 
   431     mmyth_ui_set_widget (mmyth_ui, mmyth_ui->main_uicommon);
   432 }
   433 
   434 MMythUiCommon *
   435 create_video_view (MMythUi * mmyth_ui)
   436 {
   437 
   438     MMythUiCommon *ui_common;
   439 
   440     /* FIXME
   441     mmyth_player_init (mmyth_ui);
   442     */
   443 
   444     ui_common = mmyth_uicommon_new (mmyth_ui->video_alignment,
   445                                     "  Full\nScreen", "Other\nServices",
   446                                     "Close");
   447 
   448     g_signal_connect (G_OBJECT (ui_common->button1), "clicked",
   449                       G_CALLBACK (cb_not_impl_button), mmyth_ui);
   450     g_signal_connect (G_OBJECT (ui_common->button2), "clicked",
   451                       G_CALLBACK (cb_not_impl_button), mmyth_ui);    
   452     g_signal_connect (G_OBJECT (ui_common->button3), "clicked",
   453                       G_CALLBACK (cb_video_close_button), mmyth_ui);
   454 
   455     return ui_common;
   456 }