Initial SVN import
[maemo-recorder] / src / maemo-recorder.c
1 /* vim: set ts=4 sw=4 et: */
2 /*
3  * maemo-recorder.c
4  *
5  * Copyright (C) 2006 Nokia Corporation
6  *
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22
23 #include <string.h>
24 #include <stdlib.h>
25 #include <gtk/gtk.h>
26 #include <libosso.h>
27 #include <gst/gst.h>
28 #include <glib.h>
29 #include <glib/gi18n-lib.h>
30 #include <libgnomevfs/gnome-vfs.h>
31 #include <locale.h>
32
33 #include "maemo-recorder.h"
34 #include "maemo-recorder-ui.h"
35
36
37 static gboolean createData(AppData **data);
38 static gboolean destroyData(AppData *data);
39
40 static gboolean 
41 createData(AppData **data)
42 {
43     *data = (AppData *) g_malloc0((gulong)sizeof(AppData));
44
45     g_assert(*data);
46
47     ((AppData *)*data)->state = APPSTATE_READY;
48     ((AppData *)*data)->saved = TRUE;
49
50     return TRUE;
51 }
52
53 static gboolean 
54 destroyData(AppData *data)
55 {
56     g_free(data->openFileName);
57     g_free(data->saveFileName);
58     g_free(data);
59
60     return TRUE;
61 }
62
63 static gint
64 cbDBus(const gchar *interface, const gchar *method,
65               GArray *arguments, gpointer data,
66               osso_rpc_t *retval)
67 {
68     ULOG_INFO("dbus: %s, %s", interface, method);
69
70     if (!strcmp(method, "top_application"))
71         gtk_window_present(GTK_WINDOW(data));
72
73     retval->type = DBUS_TYPE_INVALID;
74     return OSSO_OK;
75 }
76
77 int
78 main(int argc, char *argv[])
79 {
80     AppData *appData;
81     osso_return_t ret;
82     guint minor = 0, major = 0, micro = 0, nano = 0;
83
84     /* Initialise the locale stuff */
85     setlocale(LC_ALL, "");
86     bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
87     bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
88     textdomain(GETTEXT_PACKAGE);
89
90     ULOG_OPEN("maemo_recorder " PACKAGE_VERSION);
91     ULOG_INFO("maemo-recorder %s", PACKAGE_VERSION);
92
93     createData (&appData);
94
95     appData->osso = osso_initialize(SERVICE_NAME,
96                                      PACKAGE_VERSION, FALSE, NULL);
97     if (appData->osso == NULL)
98     {
99         ULOG_CRIT("osso_initialize() failed");
100         exit(1);
101     }
102
103     if (osso_mime_set_cb(appData->osso,
104              (osso_mime_cb_f *)  (&maemo_recorder_mime_open),
105              (gpointer) appData
106              ) != OSSO_OK)
107     {
108         ULOG_CRIT("osso_mime_set_cb() failed");
109     }
110
111     /* initialise gst */
112     gst_init(&argc, &argv);
113     gst_version (&major, &minor, &micro, &nano);
114     gnome_vfs_init();
115
116     ULOG_INFO("This program utilises GStreamer %d.%d.%d.%d", major, minor, micro, nano);
117     /* ULOG_DEBUG("GST_SECOND is %llu", GST_SECOND); */
118
119     /* initialise gtk */
120     gtk_init(&argc, &argv);
121
122     maemo_recorder_ui_new(appData);
123
124     ret = osso_rpc_set_default_cb_f(appData->osso, 
125                  cbDBus, 
126                  appData->mainView);
127
128     if (ret != OSSO_OK)
129     {
130         ULOG_CRIT("osso_rpc_set_default_cb_f() failed: %d, exiting", ret);
131         LOG_CLOSE();
132         exit(1);
133     }
134   
135     gtk_main();
136
137     osso_mime_unset_cb(appData->osso);
138     osso_deinitialize(appData->osso);
139     destroyData(appData);
140
141     ULOG_INFO("maemo-recorder exiting");
142
143     LOG_CLOSE();
144     return 0;
145 }
146
147
148 /* general utilities  */
149
150 void 
151 setAppState(AppData *app, AppState state)
152 {
153     app->state = state;
154 }
155
156 AppState 
157 getAppState(AppData *app)
158 {
159     return app->state;
160 }
161
162 #if 0
163 AudioFormatSpec *
164 audio_format_spec_new(void)
165 {
166     AudioFormatSpec *af = NULL;
167
168     af = (AudioFormatSpec *) g_malloc0(sizeof(AudioFormatSpec));
169     g_assert(af);
170
171     return af;
172 }
173
174 void
175 audio_format_spec_free(AudioFormatSpec *af)
176 {
177     if (NULL == af)
178         return;
179
180     if (af->mime_type != NULL)
181     {
182         g_free(af->mime_type);
183         af->mime_type = NULL;
184     }
185     
186     g_free(af);
187 }
188
189 const gchar *
190 get_mime_type(const AudioFormatSpec *af)
191 {
192
193
194 }
195
196 const gchar *
197 get_gst_mime_type(AudioFormat af)
198 {
199     /* MUST keep in sync with AudioFormat enum */
200     static char * gst_types[] = 
201     {
202         NULL,
203         GST_TYPE_PCM,
204         GST_TYPE_PCMA,
205         GST_TYPE_PCMU,
206         GST_TYPE_ILBC,
207         NULL
208     };
209
210     return gst_types[af];
211 }
212 #endif