2 * irreco-backend-browser
3 * Copyright (C) 2008 Arto Karppinen <arto.karppinen@iki.fi>
5 * irreco-backend-browser is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * irreco-backend-browser is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "browser_run.h"
23 static IrrecoBackendStatus
24 browser_spawn( gchar
**argv
, gint
*status
)
31 g_spawn_sync( getenv( "HOME" ), /* working_directory */
34 G_SPAWN_SEARCH_PATH
, /* flags */
35 NULL
, /* child_setup */
37 &out
, /* standard_output */
38 &err
, /* standard_error */
39 status
, /* exit_status */
42 if ( irreco_gerror_check_print( &error
)) {
43 IRRECO_RETURN_ENUM( BROWSER_ERROR_SPAWN_FAILED
)
46 IRRECO_PRINTF( "%s status: %i\n", argv
[ 0 ], *status
);
47 if ( ! irreco_str_isempty( out
)) {
48 IRRECO_PRINTF( "%s stdout:\n%s", argv
[ 0 ], out
);
50 if ( ! irreco_str_isempty( err
)) {
51 IRRECO_PRINTF( "%s stderr:\n%s", argv
[ 0 ], err
);
57 IRRECO_RETURN_ENUM( IRRECO_BACKEND_OK
)
61 browser_run_maemo( const gchar
*url
)
63 IrrecoBackendStatus status
= 0;
64 gint child_status
= 0;
65 GString
*string
= NULL
;
66 gchar
*argv
[] = { "dbus-send",
68 "--dest=com.nokia.osso_browser",
69 "/com/nokia/osso_browser",
70 "com.nokia.osso_browser.load_url",
74 string
= g_string_new( "string:" );
75 g_string_append( string
, url
);
76 argv
[ 5 ] = string
->str
;
78 status
= browser_spawn( argv
, &child_status
);
80 if ( status
== IRRECO_BACKEND_OK
&& child_status
!= 0 ) {
81 status
= BROWSER_ERROR_MAEMO_BROWSER
;
84 g_string_free( string
, TRUE
);
85 IRRECO_RETURN_INT( status
);
89 browser_run_wget( const gchar
*url
)
91 IrrecoBackendStatus status
= 0;
92 gint child_status
= 0;
93 gchar
*argv
[] = { "wget",
101 argv
[ 5 ] = (gchar
*) url
;
103 status
= browser_spawn( argv
, &child_status
);
104 if ( status
== IRRECO_BACKEND_OK
&& child_status
!= 0 ) {
105 status
= BROWSER_ERROR_WGET
;
108 IRRECO_RETURN_ENUM( status
)
112 browser_run( BrowserApplicationType type
, const gchar
*url
)
117 case BROWSER_APPLICATION_MAEMO
:
118 IRRECO_RETURN_INT( browser_run_maemo( url
));
120 case BROWSER_APPLICATION_WGET
:
121 IRRECO_RETURN_INT( browser_run_wget( url
));
124 IRRECO_RETURN_ENUM( BROWSER_ERROR_INVALID_APP
)