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 )
216 if ( status
.status
== unit_disconnected
)
221 if ( show_status( this, &status
) )
222 show_units( this, TRUE
);
223 if ( !this->app
->eof
&& mvcp_unit_get( this->app
->command
, this->app
->selected_unit
,
224 "eof", buf
, sizeof(buf
) ) != -1)
225 this->app
->eof
= buf
[0];
229 show_units( this, FALSE
);
231 if ( !this->terminated
)
233 GtkWidget
*widget
= lookup_widget( dv1394app_get_widget( this->app
), "button_disconnect" );
235 gtk_signal_emit_by_name( GTK_OBJECT( widget
), "clicked" );
242 void on_radiobutton_toggled( GtkToggleButton
*togglebutton
, gpointer user_data
)
244 page_status
this = user_data
;
245 dv1394app app
= this->app
;
247 GtkWidget
*widget
= this_page_get_widget( ( page
)this );
248 for ( index
= 0; index
< MAX_UNITS
; index
++ )
250 char button_name
[ 256 ];
251 sprintf( button_name
, "radiobutton_%d", index
);
252 if ( lookup_widget( widget
, button_name
) == GTK_WIDGET( togglebutton
) )
255 if ( index
< MAX_UNITS
)
257 mvcp_status_t status
;
258 mvcp_notifier notifier
= mvcp_get_notifier( this->status
);
259 dv1394app_on_unit_change( app
, index
);
260 mvcp_notifier_get( notifier
, &status
, index
);
261 gdk_threads_leave( );
262 show_status( this, &status
);
263 gdk_threads_enter( );
267 static GtkWidget
*this_page_get_widget( page super
)
269 page_status
this = ( page_status
)super
;
270 if ( this->widget
== NULL
)
271 this->widget
= create_page_status( );
275 static void this_page_get_toolbar_info( page super
, GtkIconSize size
, GtkWidget
**icon
, char **label
)
277 *icon
= gtk_image_new_from_stock( "gtk-home", size
);
278 *label
= _("_Units");
281 static void this_page_on_connect( page super
)
283 page_status
this = ( page_status
)super
;
284 if ( this->terminated
)
286 this->terminated
= 0;
287 this->status
= mvcp_init( dv1394app_get_parser( this->app
) );
288 pthread_create( &this->status_thread
, NULL
, status_thread
, this );
292 static void this_page_on_disconnect( page super
)
294 page_status
this = ( page_status
)super
;
295 if ( !this->terminated
)
298 this->terminated
= 1;
300 pthread_join( this->status_thread
, NULL
);
302 mvcp_close( this->status
);
303 widget
= lookup_widget( dv1394app_get_widget( this->app
), "statusbar" );
304 gtk_statusbar_push( GTK_STATUSBAR( widget
), this->context
, "Disconnected." );
308 static void this_page_close( page super
)
310 page_status
this = ( page_status
)super
;
315 page
page_status_init( dv1394app app
)
317 page_status
this = calloc( 1, sizeof( page_status_t
) );
321 this->parent
.get_widget
= this_page_get_widget
;
322 this->parent
.get_toolbar_info
= this_page_get_toolbar_info
;
323 this->parent
.on_connect
= this_page_on_connect
;
324 this->parent
.on_disconnect
= this_page_on_disconnect
;
325 this->parent
.close
= this_page_close
;
327 this->terminated
= 1;
329 for ( index
= 0; index
< MAX_UNITS
; index
++ )
331 char button_name
[ 256 ];
332 sprintf( button_name
, "radiobutton_%d", index
);
333 widget
= lookup_widget( this_page_get_widget( ( page
)this ), button_name
);
334 gtk_signal_connect( GTK_OBJECT( widget
), "toggled", GTK_SIGNAL_FUNC( on_radiobutton_toggled
), this );
337 widget
= lookup_widget( dv1394app_get_widget( this->app
), "statusbar" );
338 this->context
= gtk_statusbar_get_context_id( GTK_STATUSBAR( widget
), "info" );
339 gtk_statusbar_push( GTK_STATUSBAR( widget
), this->context
, "Disconnected." );