2 * page_status.c -- Status Page Handling
3 * Copyright (C) 2002-2003 Charles Yates <charles.yates@pandora.be>
4 * Copyright (C) 2010 Dan Dennedy <dan@dennedy.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "interface.h"
32 #include "dv1394app.h"
42 pthread_t status_thread
;
47 *page_status
, page_status_t
;
49 static GtkWidget
*this_page_get_widget( page
);
51 /** Show the status associated to a unit.
54 static int show_status( page_status
this, mvcp_status status
)
56 GtkWidget
*widget
= this_page_get_widget( ( page
)this );
57 char temp
[ 1024 ] = "";
59 char label_name
[ 256 ];
61 sprintf( temp
, "%05d %05d %05d %s [", status
->in
, status
->position
, status
->out
, status
->clip
);
63 switch( status
->status
)
66 strcat( temp
, "offline" );
69 strcat( temp
, "undefined" );
72 strcat( temp
, "unloaded" );
75 strcat( temp
, "stopped" );
78 strcat( temp
, "playing" );
81 strcat( temp
, "paused" );
83 case unit_disconnected
:
84 strcat( temp
, "disconnect" );
87 strcat( temp
, "unknown" );
93 sprintf( label_name
, "label_unit_%d", status
->unit
);
96 widget
= lookup_widget( widget
, label_name
);
97 gtk_label_set_text( GTK_LABEL( widget
), temp
);
98 if ( status
->unit
== dv1394app_get_selected_unit( this->app
) )
100 sprintf( temp2
, "U%d - %s", status
->unit
, temp
);
101 widget
= lookup_widget( dv1394app_get_widget( this->app
), "statusbar" );
102 gtk_statusbar_pop( GTK_STATUSBAR( widget
), this->context
);
103 gtk_statusbar_push( GTK_STATUSBAR( widget
), this->context
, temp2
);
104 dv1394app_show_status( this->app
, status
);
109 return status
->unit
>= this->count
;
112 static void show_units( page_status
this, gboolean active
)
118 char temp
[ 1024 ] = "";
119 char button_name
[ 256 ];
121 mvcp_units units
= NULL
;
122 mvcp_unit_entry_t unit
;
125 mvcp_nodes nodes
= NULL
;
126 mvcp_node_entry_t node
;
131 units
= mvcp_units_init( this->status
);
132 unit_count
= mvcp_units_count( units
);
133 nodes
= mvcp_nodes_init( this->status
);
134 node_count
= mvcp_nodes_count( nodes
);
135 this->count
= unit_count
;
140 for ( index
= 0; index
< MAX_UNITS
; index
++ )
142 if ( index
< unit_count
)
144 mvcp_units_get( units
, index
, &unit
);
146 for ( index2
= 0; index2
< node_count
; index2
++ )
148 mvcp_nodes_get( nodes
, index2
, &node
);
149 if ( !strcmp( node
.guid
, unit
.guid
) )
153 if ( index2
< node_count
)
154 sprintf( temp
, "U%d - %s (%s)", unit
.unit
, node
.name
, unit
.guid
);
156 sprintf( temp
, "U%d - %s", unit
.unit
, unit
.guid
);
158 sprintf( button_name
, "radiobutton_%d", index
);
159 widget
= lookup_widget( this_page_get_widget( ( page
)this ), button_name
);
160 gtk_widget_show( widget
);
161 gtk_button_set_label( GTK_BUTTON( widget
), temp
);
162 sprintf( button_name
, "label_unit_%d", index
);
163 widget
= lookup_widget( this_page_get_widget( ( page
)this ), button_name
);
164 gtk_widget_show( widget
);
168 sprintf( button_name
, "radiobutton_%d", index
);
169 widget
= lookup_widget( this_page_get_widget( ( page
)this ), button_name
);
170 gtk_widget_hide( widget
);
171 sprintf( button_name
, "label_unit_%d", index
);
172 widget
= lookup_widget( this_page_get_widget( ( page
)this ), button_name
);
173 gtk_widget_hide( widget
);
179 mvcp_notifier notifier
= mvcp_get_notifier( this->status
);
180 mvcp_status_t status
;
182 for ( index
= 0; index
< MAX_UNITS
; index
++ )
186 status
.status
= unit_disconnected
;
188 mvcp_notifier_get( notifier
, &status
, index
);
189 show_status( this, &status
);
194 mvcp_nodes_close( nodes
);
195 mvcp_units_close( units
);
199 /** Status monitoring thread.
202 static void *status_thread( void *arg
)
204 page_status
this = arg
;
205 mvcp_notifier notifier
= mvcp_get_notifier( this->status
);
206 mvcp_status_t status
;
208 show_units( this, TRUE
);
210 while ( !this->terminated
)
212 if ( mvcp_notifier_wait( notifier
, &status
) != -1 )
214 if ( status
.status
== unit_disconnected
)
216 if ( show_status( this, &status
) )
217 show_units( this, TRUE
);
221 show_units( this, FALSE
);
223 if ( !this->terminated
)
225 GtkWidget
*widget
= lookup_widget( dv1394app_get_widget( this->app
), "button_disconnect" );
227 gtk_signal_emit_by_name( GTK_OBJECT( widget
), "clicked" );
234 void on_radiobutton_toggled( GtkToggleButton
*togglebutton
, gpointer user_data
)
236 page_status
this = user_data
;
237 dv1394app app
= this->app
;
239 GtkWidget
*widget
= this_page_get_widget( ( page
)this );
240 for ( index
= 0; index
< MAX_UNITS
; index
++ )
242 char button_name
[ 256 ];
243 sprintf( button_name
, "radiobutton_%d", index
);
244 if ( lookup_widget( widget
, button_name
) == GTK_WIDGET( togglebutton
) )
247 if ( index
< MAX_UNITS
)
249 mvcp_status_t status
;
250 mvcp_notifier notifier
= mvcp_get_notifier( this->status
);
251 dv1394app_on_unit_change( app
, index
);
252 mvcp_notifier_get( notifier
, &status
, index
);
253 gdk_threads_leave( );
254 show_status( this, &status
);
255 gdk_threads_enter( );
259 static GtkWidget
*this_page_get_widget( page super
)
261 page_status
this = ( page_status
)super
;
262 if ( this->widget
== NULL
)
263 this->widget
= create_page_status( );
267 static void this_page_get_toolbar_info( page super
, GtkIconSize size
, GtkWidget
**icon
, char **label
)
269 *icon
= gtk_image_new_from_stock( "gtk-execute", size
);
273 static void this_page_on_connect( page super
)
275 page_status
this = ( page_status
)super
;
276 if ( this->terminated
)
278 this->terminated
= 0;
279 this->status
= mvcp_init( dv1394app_get_parser( this->app
) );
280 pthread_create( &this->status_thread
, NULL
, status_thread
, this );
284 static void this_page_on_disconnect( page super
)
286 page_status
this = ( page_status
)super
;
287 if ( !this->terminated
)
290 this->terminated
= 1;
292 pthread_join( this->status_thread
, NULL
);
294 mvcp_close( this->status
);
295 widget
= lookup_widget( dv1394app_get_widget( this->app
), "statusbar" );
296 gtk_statusbar_push( GTK_STATUSBAR( widget
), this->context
, "Disconnected." );
300 static void this_page_close( page super
)
302 page_status
this = ( page_status
)super
;
307 page
page_status_init( dv1394app app
)
309 page_status
this = calloc( 1, sizeof( page_status_t
) );
313 this->parent
.get_widget
= this_page_get_widget
;
314 this->parent
.get_toolbar_info
= this_page_get_toolbar_info
;
315 this->parent
.on_connect
= this_page_on_connect
;
316 this->parent
.on_disconnect
= this_page_on_disconnect
;
317 this->parent
.close
= this_page_close
;
319 this->terminated
= 1;
321 for ( index
= 0; index
< MAX_UNITS
; index
++ )
323 char button_name
[ 256 ];
324 sprintf( button_name
, "radiobutton_%d", index
);
325 widget
= lookup_widget( this_page_get_widget( ( page
)this ), button_name
);
326 gtk_signal_connect( GTK_OBJECT( widget
), "toggled", GTK_SIGNAL_FUNC( on_radiobutton_toggled
), this );
329 widget
= lookup_widget( dv1394app_get_widget( this->app
), "statusbar" );
330 this->context
= gtk_statusbar_get_context_id( GTK_STATUSBAR( widget
), "info" );
331 gtk_statusbar_push( GTK_STATUSBAR( widget
), this->context
, "Disconnected." );