2 * This file is part of NumptyPhysics
3 * Copyright (C) 2008 Tim Edmonds
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of the
8 * License, or (at your option) any later version.
10 * This program 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. See the GNU
13 * General Public License for more details.
22 #include <glib-object.h>
23 #include <glibconfig.h>
24 #include <glib/gmacros.h>
26 #include <ossoemailinterface.h>
28 #include <hildon/hildon-program.h>
29 //#include <hildon/hildon-file-chooser-dialog.h>
34 #define Font __FONT_REDEF
37 #define NP_NAME "NumptyPhysics"
38 #define NP_SERVICE "org.maemo.garage.numptyphysics"
39 #define NP_OBJECT "org/maemo/garage/numptyphysics" /* / ?? */
40 #define NP_INTERFACE "org.maemo.garage.numptyphysics"
41 #define NP_VERSION "1.0"
45 static gint
dbus_handler(const gchar
*interface
,
51 class OsHildon
: public Os
53 GMainContext
*m_gcontext
;
54 osso_context_t
*m_osso
;
58 char* m_files
[MAX_FILES
];
63 m_gcontext
= g_main_context_new();
65 m_osso
= osso_initialize(NP_NAME
, NP_VERSION
, FALSE
, m_gcontext
);
67 fprintf(stderr
, "Failed to initialize libosso\n");
71 /* Set dbus handler to get mime open callbacks */
72 if ( osso_rpc_set_cb_f(m_osso
,
76 dbus_handler
, NULL
) != OSSO_OK
) {
77 fprintf(stderr
, "Failed to set mime callback\n");
85 osso_deinitialize( m_osso
);
88 g_main_context_unref( m_gcontext
);
94 if ( g_main_context_iteration( m_gcontext
, FALSE
) ) {
95 fprintf(stderr
, "Hildon::poll event!\n");
99 virtual char *getLaunchFile()
101 if ( m_numFiles
> 0 ) {
102 return m_files
[--m_numFiles
];
107 virtual bool openBrowser( const char* url
)
109 if ( url
&& strlen(url
) < 200 ) {
111 snprintf(buf
,256,"xdg-open %s",url
);
112 if ( system( buf
) == 0 ) {
119 virtual char* saveDialog( const char* path
)
122 static char buf
[256];
123 GtkWidget
*dialog
= hildon_file_chooser_dialog_new(NULL
,GTK_FILE_CHOOSER_ACTION_SAVE
);
124 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog
), path
);
125 if (gtk_dialog_run(GTK_DIALOG(dialog
)) == GTK_RESPONSE_OK
) {
127 name
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
));
128 strncpy( buf
, name
, 256 );
129 g_print("Saving as %s\n", name
);
141 static gint
dbus_handler(const gchar
*interface
,
147 OsHildon
* os
= (OsHildon
*)data
;
148 if (arguments
== NULL
) {
152 if (g_ascii_strcasecmp(method
, "mime_open") == 0) {
153 for(unsigned i
= 0; i
< arguments
->len
; ++i
) {
154 osso_rpc_t val
= g_array_index(arguments
, osso_rpc_t
, i
);
155 if (val
.type
== DBUS_TYPE_STRING
&& val
.value
.s
!= NULL
) {
157 fprintf(stderr
,"hildon mime open \"%s\"\n",val
.value
.s
);
158 if ( strncmp(val
.value
.s
,"file://",7)==0
159 && os
->m_numFiles
< MAX_FILES
) {
161 } else if ( ( strncmp(val
.value
.s
,"http://",7)==0
162 || strncmp(val
.value
.s
,"nptp://",7)==0 ) ) {
164 std::string
filename(val
.value
.s
+7);
165 if ( filename
.rfind('/') >= 0 ) {
166 filename
= filename
.substr( filename
.rfind('/')+1 );
168 std::string filepath
= Config::userDataDir() + Os::pathSep
;
169 if ( h
.get( val
.value
.s
+7, HTTP_TEMP_FILE
) ) {
174 if ( os
->m_files
[os
->m_numFiles
] ) {
175 g_free(os
->m_files
[os
->m_numFiles
]);
177 os
->m_files
[os
->m_numFiles
++] = g_strdup( f
);
193 const char Os::pathSep
= '/';
195 int main(int argc
, char** argv
)
197 gtk_init(&argc
, &argv
);