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