2 * page_command.c -- Command 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.
29 #include "interface.h"
31 #include "dv1394app.h"
34 typedef struct page_command_t
42 static GtkWidget
*this_page_get_widget( page_command
);
44 /** Main window - command tab - command to be executed.
47 static gboolean
on_command_pressed( GtkWidget
*button
, gpointer user_data
)
49 page_command
this = user_data
;
51 GtkTextBuffer
*buffer
;
53 PangoFontDescription
*font_desc
;
55 if ( dv1394app_get_parser( this->app
) != NULL
)
58 mvcp_response response
= NULL
;
61 widget
= lookup_widget( this_page_get_widget( this ), "entry_command" );
62 command
= (char *)gtk_entry_get_text( GTK_ENTRY( widget
) );
64 widget
= lookup_widget( this_page_get_widget( this ), "textview_command" );
66 font_desc
= pango_font_description_from_string( "Courier 9" );
67 gtk_widget_modify_font( widget
, font_desc
);
68 pango_font_description_free( font_desc
);
69 buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW( widget
) );
70 gtk_text_buffer_get_end_iter( buffer
, &iter
);
71 gtk_text_buffer_place_cursor( buffer
, &iter
);
72 gtk_text_buffer_insert_at_cursor( buffer
, "> ", -1 );
73 gtk_text_buffer_insert_at_cursor( buffer
, command
, -1 );
74 gtk_text_buffer_insert_at_cursor( buffer
, "\n", -1 );
75 mvcp_execute( dv1394app_get_command( this->app
), 1024, "%s", command
);
76 response
= mvcp_get_last_response( dv1394app_get_command( this->app
) );
77 for ( index
= 0; index
< mvcp_response_count( response
); index
++ )
79 if ( index
!= mvcp_response_count( response
) - 1 ||
80 strcmp( mvcp_response_get_line( response
, index
), "" ) )
82 gtk_text_buffer_insert_at_cursor( buffer
, mvcp_response_get_line( response
, index
), -1 );
83 gtk_text_buffer_insert_at_cursor( buffer
, "\n", -1 );
86 gtk_text_buffer_insert_at_cursor( buffer
, "\n", -1 );
87 gtk_text_view_scroll_mark_onscreen( GTK_TEXT_VIEW( widget
), gtk_text_buffer_get_insert( buffer
) );
88 widget
= lookup_widget( this_page_get_widget( this ), "entry_command" );
89 gtk_entry_set_text( GTK_ENTRY( widget
), "" );
90 gtk_widget_grab_focus( widget
);
100 /** Main window - command tab - clear button pressed.
103 static gboolean
on_command_cleared( GtkWidget
*button
, gpointer user_data
)
105 page_command
this = user_data
;
106 GtkWidget
*widget
= lookup_widget( this_page_get_widget( this ), "textview_command" );
107 GtkTextBuffer
*buffer
= gtk_text_view_get_buffer( GTK_TEXT_VIEW( widget
) );
108 gtk_text_buffer_set_text( buffer
, "", -1 );
112 static GtkWidget
*this_page_get_widget( page_command
this )
114 if ( this->widget
== NULL
)
115 this->widget
= create_page_shell( );
119 static void this_page_get_toolbar_info( page
this, GtkIconSize size
, GtkWidget
**icon
, char **label
)
121 *icon
= gtk_image_new_from_stock( "gtk-dialog-info", size
);
125 static void this_on_connect( page_command
this )
129 static void this_on_disconnect( page_command
this )
133 static void this_close( page_command
this )
139 page
page_command_init( dv1394app app
)
142 page_command
this = calloc( 1, sizeof( struct page_command_t
) );
144 this->parent
.get_widget
= ( GtkWidget
*(*)( page
) )this_page_get_widget
;
145 this->parent
.get_toolbar_info
= this_page_get_toolbar_info
;
146 this->parent
.on_connect
= ( void (*)( page
) )this_on_connect
;
147 this->parent
.on_disconnect
= ( void (*)( page
) )this_on_disconnect
;
148 this->parent
.close
= ( void (*)( page
) )this_close
;
151 /* Command execution handling */
152 widget
= lookup_widget( this_page_get_widget( this ), "entry_command" );
153 gtk_signal_connect( GTK_OBJECT( widget
), "activate", GTK_SIGNAL_FUNC( on_command_pressed
), this );
154 widget
= lookup_widget( this_page_get_widget( this ), "button_command" );
155 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_command_pressed
), this );
156 widget
= lookup_widget( this_page_get_widget( this ), "button_command_clear" );
157 gtk_signal_connect( GTK_OBJECT( widget
), "clicked", GTK_SIGNAL_FUNC( on_command_cleared
), this );