~ubuntu-branches/debian/sid/cheese/sid

« back to all changes in this revision

Viewing changes to src/cheese-main.c

  • Committer: Bazaar Package Importer
  • Author(s): Laurent Bigonville
  • Date: 2011-07-17 21:04:16 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110717210416-nt5qi659qei7a2yy
Tags: 3.0.1-2
* debian/control.in:
  - Change gir1.2-cheese-3.0 Section to libs
  - Make library packages depend against cheese-common package
  - Make cheese package recommends against hicolor-icon-theme
  - Move gst Dependency to libcheese package
* debian/patches/0002-fix-linking.patch: Add missing library to fix linking
* debian/watch:
  - Switch to .bz2 tarballs.
  - Bump version to 3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* cheese-main.c generated by valac 0.12.0, the Vala compiler
 
2
 * generated from cheese-main.vala, do not modify */
 
3
 
 
4
/*
 
5
 * Copyright © 2010 Yuvaraj Pandian T <yuvipanda@yuvi.in>
 
6
 * Copyright © 2010 daniel g. siegel <dgsiegel@gnome.org>
 
7
 * Copyright © 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
 
8
 *
 
9
 * Licensed under the GNU General Public License Version 2
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or modify
 
12
 * it under the terms of the GNU General Public License as published by
 
13
 * the Free Software Foundation; either version 2 of the License, or
 
14
 * (at your option) any later version.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU General Public License
 
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
23
 */
 
24
 
 
25
#include <glib.h>
 
26
#include <glib-object.h>
 
27
#include <gtk/gtk.h>
 
28
#include <stdlib.h>
 
29
#include <string.h>
 
30
#include <gio/gio.h>
 
31
#include <glib/gi18n-lib.h>
 
32
#include <cheese-config.h>
 
33
#include <stdio.h>
 
34
#include <gst/gst.h>
 
35
#include <clutter/clutter.h>
 
36
#include <clutter-gtk/clutter-gtk.h>
 
37
 
 
38
 
 
39
#define CHEESE_TYPE_MAIN (cheese_main_get_type ())
 
40
#define CHEESE_MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHEESE_TYPE_MAIN, CheeseMain))
 
41
#define CHEESE_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CHEESE_TYPE_MAIN, CheeseMainClass))
 
42
#define CHEESE_IS_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHEESE_TYPE_MAIN))
 
43
#define CHEESE_IS_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CHEESE_TYPE_MAIN))
 
44
#define CHEESE_MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CHEESE_TYPE_MAIN, CheeseMainClass))
 
45
 
 
46
typedef struct _CheeseMain CheeseMain;
 
47
typedef struct _CheeseMainClass CheeseMainClass;
 
48
typedef struct _CheeseMainPrivate CheeseMainPrivate;
 
49
 
 
50
#define CHEESE_TYPE_MAIN_WINDOW (cheese_main_window_get_type ())
 
51
#define CHEESE_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHEESE_TYPE_MAIN_WINDOW, CheeseMainWindow))
 
52
#define CHEESE_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CHEESE_TYPE_MAIN_WINDOW, CheeseMainWindowClass))
 
53
#define CHEESE_IS_MAIN_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHEESE_TYPE_MAIN_WINDOW))
 
54
#define CHEESE_IS_MAIN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CHEESE_TYPE_MAIN_WINDOW))
 
55
#define CHEESE_MAIN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CHEESE_TYPE_MAIN_WINDOW, CheeseMainWindowClass))
 
56
 
 
57
typedef struct _CheeseMainWindow CheeseMainWindow;
 
58
typedef struct _CheeseMainWindowClass CheeseMainWindowClass;
 
59
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
 
60
#define _g_free0(var) (var = (g_free (var), NULL))
 
61
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
 
62
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
 
63
 
 
64
struct _CheeseMain {
 
65
        GtkApplication parent_instance;
 
66
        CheeseMainPrivate * priv;
 
67
};
 
68
 
 
69
struct _CheeseMainClass {
 
70
        GtkApplicationClass parent_class;
 
71
};
 
72
 
 
73
 
 
74
static gpointer cheese_main_parent_class = NULL;
 
75
static gboolean cheese_main_wide;
 
76
static gboolean cheese_main_wide = FALSE;
 
77
static gchar* cheese_main_device;
 
78
static gchar* cheese_main_device = NULL;
 
79
static gboolean cheese_main_version;
 
80
static gboolean cheese_main_version = FALSE;
 
81
static gboolean cheese_main_fullscreen;
 
82
static gboolean cheese_main_fullscreen = FALSE;
 
83
static CheeseMainWindow* cheese_main_main_window;
 
84
static CheeseMainWindow* cheese_main_main_window = NULL;
 
85
 
 
86
GType cheese_main_get_type (void) G_GNUC_CONST;
 
87
enum  {
 
88
        CHEESE_MAIN_DUMMY_PROPERTY
 
89
};
 
90
GType cheese_main_window_get_type (void) G_GNUC_CONST;
 
91
CheeseMain* cheese_main_new (const gchar* app_id, GApplicationFlags flags);
 
92
CheeseMain* cheese_main_construct (GType object_type, const gchar* app_id, GApplicationFlags flags);
 
93
void cheese_main_on_app_activate (CheeseMain* self);
 
94
CheeseMainWindow* cheese_main_window_new (void);
 
95
CheeseMainWindow* cheese_main_window_construct (GType object_type);
 
96
void cheese_main_window_setup_ui (CheeseMainWindow* self);
 
97
void cheese_main_window_set_startup_wide_mode (CheeseMainWindow* self);
 
98
void cheese_main_window_set_startup_fullscreen_mode (CheeseMainWindow* self);
 
99
static void _gtk_main_quit_gtk_widget_destroy (GtkWidget* _sender, gpointer self);
 
100
void cheese_main_window_setup_camera (CheeseMainWindow* self, const gchar* uri);
 
101
static gboolean cheese_main_real_local_command_line (GApplication* base, gchar*** arguments, gint* exit_status);
 
102
static void cheese_main_finalize (GObject* obj);
 
103
gint _vala_main (gchar** args, int args_length1);
 
104
static void _cheese_main_on_app_activate_g_application_activate (GApplication* _sender, gpointer self);
 
105
static gint _vala_array_length (gpointer array);
 
106
 
 
107
static const GOptionEntry CHEESE_MAIN_options[5] = {{"wide", 'w', 0, G_OPTION_ARG_NONE, &cheese_main_wide, "Start in wide mode", NULL}, {"device", 'd', 0, G_OPTION_ARG_FILENAME, &cheese_main_device, "Device to use as a camera", "DEVICE"}, {"version", 'v', 0, G_OPTION_ARG_NONE, &cheese_main_version, "Output version information and exit", NULL}, {"fullscreen", 'f', 0, G_OPTION_ARG_NONE, &cheese_main_fullscreen, "Start in fullscreen mode", NULL}, {NULL}};
 
108
 
 
109
CheeseMain* cheese_main_construct (GType object_type, const gchar* app_id, GApplicationFlags flags) {
 
110
        CheeseMain * self = NULL;
 
111
        g_return_val_if_fail (app_id != NULL, NULL);
 
112
        self = (CheeseMain*) g_object_new (object_type, "application-id", app_id, "flags", flags, NULL);
 
113
        return self;
 
114
}
 
115
 
 
116
 
 
117
CheeseMain* cheese_main_new (const gchar* app_id, GApplicationFlags flags) {
 
118
        return cheese_main_construct (CHEESE_TYPE_MAIN, app_id, flags);
 
119
}
 
120
 
 
121
 
 
122
static void _gtk_main_quit_gtk_widget_destroy (GtkWidget* _sender, gpointer self) {
 
123
        gtk_main_quit ();
 
124
}
 
125
 
 
126
 
 
127
void cheese_main_on_app_activate (CheeseMain* self) {
 
128
        GList* _tmp0_ = NULL;
 
129
        g_return_if_fail (self != NULL);
 
130
        _tmp0_ = gtk_application_get_windows ((GtkApplication*) self);
 
131
        if (_tmp0_ != NULL) {
 
132
                gtk_window_present ((GtkWindow*) cheese_main_main_window);
 
133
        } else {
 
134
                CheeseMainWindow* _tmp1_ = NULL;
 
135
                const gchar* _tmp2_ = NULL;
 
136
                GtkIconTheme* _tmp3_ = NULL;
 
137
                gchar* _tmp4_ = NULL;
 
138
                gchar* _tmp5_;
 
139
                _tmp1_ = cheese_main_window_new ();
 
140
                _g_object_unref0 (cheese_main_main_window);
 
141
                cheese_main_main_window = g_object_ref_sink (_tmp1_);
 
142
                _tmp2_ = _ ("Cheese");
 
143
                g_set_application_name (_tmp2_);
 
144
                gtk_window_set_default_icon_name ("cheese");
 
145
                _tmp3_ = gtk_icon_theme_get_default ();
 
146
                _tmp4_ = g_build_filename (PACKAGE_DATADIR, "icons", NULL);
 
147
                _tmp5_ = _tmp4_;
 
148
                gtk_icon_theme_append_search_path (_tmp3_, _tmp5_);
 
149
                _g_free0 (_tmp5_);
 
150
                cheese_main_window_setup_ui (cheese_main_main_window);
 
151
                if (cheese_main_wide) {
 
152
                        cheese_main_window_set_startup_wide_mode (cheese_main_main_window);
 
153
                }
 
154
                if (cheese_main_fullscreen) {
 
155
                        cheese_main_window_set_startup_fullscreen_mode (cheese_main_main_window);
 
156
                }
 
157
                gtk_window_set_application ((GtkWindow*) cheese_main_main_window, (GtkApplication*) self);
 
158
                g_signal_connect ((GtkWidget*) cheese_main_main_window, "destroy", (GCallback) _gtk_main_quit_gtk_widget_destroy, NULL);
 
159
                gtk_widget_show ((GtkWidget*) cheese_main_main_window);
 
160
                cheese_main_window_setup_camera (cheese_main_main_window, cheese_main_device);
 
161
        }
 
162
}
 
163
 
 
164
 
 
165
static gboolean cheese_main_real_local_command_line (GApplication* base, gchar*** arguments, gint* exit_status) {
 
166
        CheeseMain * self;
 
167
        gint _exit_status = 0;
 
168
        gboolean result = FALSE;
 
169
        gchar** local_args;
 
170
        gint local_args_length1;
 
171
        gint _local_args_size_;
 
172
        gint n_args;
 
173
        GError * _inner_error_ = NULL;
 
174
        self = (CheeseMain*) base;
 
175
        g_application_register ((GApplication*) self, NULL, &_inner_error_);
 
176
        if (_inner_error_ != NULL) {
 
177
                goto __catch0_g_error;
 
178
        }
 
179
        goto __finally0;
 
180
        __catch0_g_error:
 
181
        {
 
182
                GError * e;
 
183
                e = _inner_error_;
 
184
                _inner_error_ = NULL;
 
185
                fprintf (stdout, "Error: %s\n", e->message);
 
186
                _exit_status = 1;
 
187
                result = TRUE;
 
188
                _g_error_free0 (e);
 
189
                if (exit_status) {
 
190
                        *exit_status = _exit_status;
 
191
                }
 
192
                return result;
 
193
        }
 
194
        __finally0:
 
195
        if (_inner_error_ != NULL) {
 
196
                g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
197
                g_clear_error (&_inner_error_);
 
198
                return FALSE;
 
199
        }
 
200
        local_args = *arguments;
 
201
        local_args_length1 = _vala_array_length (*arguments);
 
202
        _local_args_size_ = _vala_array_length (*arguments);
 
203
        n_args = local_args_length1;
 
204
        if (n_args <= 1) {
 
205
                gst_init (&local_args_length1, &local_args);
 
206
                g_application_activate ((GApplication*) self);
 
207
                _exit_status = 0;
 
208
        } else {
 
209
                const gchar* _tmp0_ = NULL;
 
210
                GOptionContext* _tmp1_ = NULL;
 
211
                GOptionContext* context;
 
212
                GOptionGroup* _tmp2_ = NULL;
 
213
                GOptionGroup* _tmp3_ = NULL;
 
214
                GOptionGroup* _tmp4_ = NULL;
 
215
                gboolean _tmp6_;
 
216
                _tmp0_ = _ ("- Take photos and videos from your webcam");
 
217
                _tmp1_ = g_option_context_new (_tmp0_);
 
218
                context = _tmp1_;
 
219
                g_option_context_set_help_enabled (context, TRUE);
 
220
                g_option_context_add_main_entries (context, CHEESE_MAIN_options, NULL);
 
221
                _tmp2_ = gtk_get_option_group (TRUE);
 
222
                g_option_context_add_group (context, _tmp2_);
 
223
                _tmp3_ = clutter_get_option_group ();
 
224
                g_option_context_add_group (context, _tmp3_);
 
225
                _tmp4_ = gst_init_get_option_group ();
 
226
                g_option_context_add_group (context, _tmp4_);
 
227
                g_option_context_parse (context, &local_args_length1, &local_args, &_inner_error_);
 
228
                if (_inner_error_ != NULL) {
 
229
                        _g_option_context_free0 (context);
 
230
                        if (_inner_error_->domain == G_OPTION_ERROR) {
 
231
                                goto __catch1_g_option_error;
 
232
                        }
 
233
                        _g_option_context_free0 (context);
 
234
                        g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
235
                        g_clear_error (&_inner_error_);
 
236
                        return FALSE;
 
237
                }
 
238
                _g_option_context_free0 (context);
 
239
                goto __finally1;
 
240
                __catch1_g_option_error:
 
241
                {
 
242
                        GError * e;
 
243
                        const gchar* _tmp5_ = NULL;
 
244
                        e = _inner_error_;
 
245
                        _inner_error_ = NULL;
 
246
                        fprintf (stdout, "%s\n", e->message);
 
247
                        _tmp5_ = _ ("Run '%s --help' to see a full list of available command line options.\n");
 
248
                        fprintf (stdout, _tmp5_, (*arguments)[0]);
 
249
                        _exit_status = 1;
 
250
                        result = TRUE;
 
251
                        _g_error_free0 (e);
 
252
                        if (exit_status) {
 
253
                                *exit_status = _exit_status;
 
254
                        }
 
255
                        return result;
 
256
                }
 
257
                __finally1:
 
258
                if (_inner_error_ != NULL) {
 
259
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
 
260
                        g_clear_error (&_inner_error_);
 
261
                        return FALSE;
 
262
                }
 
263
                if (cheese_main_version) {
 
264
                        fprintf (stdout, "%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
 
265
                        _exit_status = 1;
 
266
                        result = TRUE;
 
267
                        if (exit_status) {
 
268
                                *exit_status = _exit_status;
 
269
                        }
 
270
                        return result;
 
271
                }
 
272
                _tmp6_ = g_application_get_is_remote ((GApplication*) self);
 
273
                if (_tmp6_) {
 
274
                        const gchar* _tmp7_ = NULL;
 
275
                        _tmp7_ = _ ("Another instance of Cheese is currently running\n");
 
276
                        fprintf (stdout, "%s", _tmp7_);
 
277
                        _exit_status = 1;
 
278
                        result = TRUE;
 
279
                        if (exit_status) {
 
280
                                *exit_status = _exit_status;
 
281
                        }
 
282
                        return result;
 
283
                } else {
 
284
                        gst_init (&local_args_length1, &local_args);
 
285
                        g_application_activate ((GApplication*) self);
 
286
                        _exit_status = 0;
 
287
                }
 
288
        }
 
289
        result = TRUE;
 
290
        if (exit_status) {
 
291
                *exit_status = _exit_status;
 
292
        }
 
293
        return result;
 
294
}
 
295
 
 
296
 
 
297
static void cheese_main_class_init (CheeseMainClass * klass) {
 
298
        cheese_main_parent_class = g_type_class_peek_parent (klass);
 
299
        G_APPLICATION_CLASS (klass)->local_command_line = cheese_main_real_local_command_line;
 
300
        G_OBJECT_CLASS (klass)->finalize = cheese_main_finalize;
 
301
}
 
302
 
 
303
 
 
304
static void cheese_main_instance_init (CheeseMain * self) {
 
305
}
 
306
 
 
307
 
 
308
static void cheese_main_finalize (GObject* obj) {
 
309
        CheeseMain * self;
 
310
        self = CHEESE_MAIN (obj);
 
311
        G_OBJECT_CLASS (cheese_main_parent_class)->finalize (obj);
 
312
}
 
313
 
 
314
 
 
315
GType cheese_main_get_type (void) {
 
316
        static volatile gsize cheese_main_type_id__volatile = 0;
 
317
        if (g_once_init_enter (&cheese_main_type_id__volatile)) {
 
318
                static const GTypeInfo g_define_type_info = { sizeof (CheeseMainClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) cheese_main_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CheeseMain), 0, (GInstanceInitFunc) cheese_main_instance_init, NULL };
 
319
                GType cheese_main_type_id;
 
320
                cheese_main_type_id = g_type_register_static (GTK_TYPE_APPLICATION, "CheeseMain", &g_define_type_info, 0);
 
321
                g_once_init_leave (&cheese_main_type_id__volatile, cheese_main_type_id);
 
322
        }
 
323
        return cheese_main_type_id__volatile;
 
324
}
 
325
 
 
326
 
 
327
static void _cheese_main_on_app_activate_g_application_activate (GApplication* _sender, gpointer self) {
 
328
        cheese_main_on_app_activate (self);
 
329
}
 
330
 
 
331
 
 
332
gint _vala_main (gchar** args, int args_length1) {
 
333
        gint result = 0;
 
334
        CheeseMain* app = NULL;
 
335
        CheeseMain* _tmp0_ = NULL;
 
336
        gint _tmp1_;
 
337
        gint status;
 
338
        bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
 
339
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
340
        textdomain (GETTEXT_PACKAGE);
 
341
        gtk_clutter_init (&args_length1, &args);
 
342
        _tmp0_ = cheese_main_new ("org.gnome.Cheese", G_APPLICATION_FLAGS_NONE);
 
343
        _g_object_unref0 (app);
 
344
        app = _tmp0_;
 
345
        g_signal_connect_object ((GApplication*) app, "activate", (GCallback) _cheese_main_on_app_activate_g_application_activate, app, 0);
 
346
        _tmp1_ = g_application_run ((GApplication*) app, args_length1, args);
 
347
        status = _tmp1_;
 
348
        result = status;
 
349
        _g_object_unref0 (app);
 
350
        return result;
 
351
}
 
352
 
 
353
 
 
354
int main (int argc, char ** argv) {
 
355
        g_thread_init (NULL);
 
356
        g_type_init ();
 
357
        return _vala_main (argv, argc);
 
358
}
 
359
 
 
360
 
 
361
static gint _vala_array_length (gpointer array) {
 
362
        int length;
 
363
        length = 0;
 
364
        if (array) {
 
365
                while (((gpointer*) array)[length]) {
 
366
                        length++;
 
367
                }
 
368
        }
 
369
        return length;
 
370
}
 
371
 
 
372
 
 
373