cleanups
[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 #include "settings.h"
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     appData->gconf_client = settings_init(argc, argv);
123
124     maemo_recorder_ui_new(appData);
125
126     ret = osso_rpc_set_default_cb_f(appData->osso, 
127                  cbDBus, 
128                  appData->mainView);
129
130     if (ret != OSSO_OK)
131     {
132         ULOG_CRIT("osso_rpc_set_default_cb_f() failed: %d, exiting", ret);
133         LOG_CLOSE();
134         exit(1);
135     }
136   
137     gtk_main();
138
139     osso_mime_unset_cb(appData->osso);
140     osso_deinitialize(appData->osso);
141     destroyData(appData);
142
143     ULOG_INFO("maemo-recorder exiting");
144
145     LOG_CLOSE();
146     return 0;
147 }
148
149
150 /* general utilities  */
151
152 void 
153 setAppState(AppData *app, AppState state)
154 {
155     app->state = state;
156 }
157
158 AppState 
159 getAppState(AppData *app)
160 {
161     return app->state;
162 }
163
164 #if 0
165 AudioFormatSpec *
166 audio_format_spec_new(void)
167 {
168     AudioFormatSpec *af = NULL;
169
170     af = (AudioFormatSpec *) g_malloc0(sizeof(AudioFormatSpec));
171     g_assert(af);
172
173     return af;
174 }
175
176 void
177 audio_format_spec_free(AudioFormatSpec *af)
178 {
179     if (NULL == af)
180         return;
181
182     if (af->mime_type != NULL)
183     {
184         g_free(af->mime_type);
185         af->mime_type = NULL;
186     }
187     
188     g_free(af);
189 }
190
191 const gchar *
192 get_mime_type(const AudioFormatSpec *af)
193 {
194
195
196 }
197
198 const gchar *
199 get_gst_mime_type(AudioFormat af)
200 {
201     /* MUST keep in sync with AudioFormat enum */
202     static char * gst_types[] = 
203     {
204         NULL,
205         GST_TYPE_PCM,
206         GST_TYPE_PCMA,
207         GST_TYPE_PCMU,
208         GST_TYPE_ILBC,
209         NULL
210     };
211
212     return gst_types[af];
213 }
214 #endif