2
* Copyright © 2007-2009 daniel g. siegel <dgsiegel@gnome.org>
3
* Copyright © 2007,2008 Jaap Haitsma <jaap@haitsma.org>
4
* Copyright © 2008 Felix Kaser <f.kaser@gmx.net>
6
* Licensed under the GNU General Public License Version 2
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include <cheese-config.h>
27
#include <glib/gi18n.h>
31
#include <librsvg/rsvg.h>
33
#include "cheese-fileutil.h"
34
#include "cheese-window.h"
35
#include "cheese-dbus.h"
45
cheese_print_handler (char *string)
47
static FILE *fp = NULL;
49
char *filename, *path;
51
CheeseFileUtil *fileutil = cheese_fileutil_new ();
53
if (CheeseOptions.verbose)
54
fprintf (stdout, "%s", string);
58
path = cheese_fileutil_get_log_path (fileutil);
60
dir = g_dir_open (path, 0, NULL);
66
/* remove the old logfile if it exists */
67
filename = g_build_filename (path, "log", NULL);
68
if (g_file_test (filename, G_FILE_TEST_EXISTS))
70
GFile *old = g_file_new_for_path (filename);
71
g_file_delete (old, NULL, NULL);
76
filename = g_build_filename (path, "log.txt", NULL);
77
fp = fopen (filename, "w");
78
fputs ("Cheese " VERSION "\n\n", fp);
80
g_object_unref (fileutil);
89
main (int argc, char **argv)
91
GOptionContext *context;
92
CheeseDbus *dbus_server;
95
GOptionEntry options[] = {
96
{"verbose", 'v', 0, G_OPTION_ARG_NONE, &CheeseOptions.verbose,
97
_("Be verbose"), NULL},
98
{"wide", 'w', 0, G_OPTION_ARG_NONE, &CheeseOptions.wide_mode,
99
_("Enable wide mode"), NULL},
100
{"version", 0, 0, G_OPTION_ARG_NONE, &CheeseOptions.version,
101
_("output version information and exit"), NULL},
105
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
106
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
107
textdomain (GETTEXT_PACKAGE);
109
gtk_rc_parse (APPNAME_DATA_DIR G_DIR_SEPARATOR_S "gtkrc");
111
g_thread_init (NULL);
114
/* initialize rsvg */
115
/* needed to load the camera icon for the countdown widget */
118
g_set_application_name (_("Cheese"));
120
context = g_option_context_new (N_("- Take photos and videos with your webcam, with fun graphical effects"));
121
g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
122
g_option_context_add_group (context, gtk_get_option_group (TRUE));
123
g_option_context_add_group (context, gst_init_get_option_group ());
124
if (g_option_context_parse (context, &argc, &argv, &error) == FALSE)
126
gchar *help_text = g_option_context_get_help (context, TRUE, NULL);
127
g_print ("%s\n\n%s", error->message, help_text);
129
g_error_free (error);
130
g_option_context_free (context);
133
g_option_context_free (context);
135
if (CheeseOptions.version)
137
g_print ("Cheese " VERSION " \n");
141
dbus_server = cheese_dbus_new ();
142
if (dbus_server == NULL)
144
gdk_notify_startup_complete ();
148
g_set_print_handler ((GPrintFunc) cheese_print_handler);
149
g_print ("Cheese " VERSION " \n");
151
gtk_window_set_default_icon_name ("cheese");
152
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
153
APPNAME_DATA_DIR G_DIR_SEPARATOR_S "icons");
155
CheeseWindow *window = g_object_new (CHEESE_TYPE_WINDOW,
156
"startup-wide", CheeseOptions.wide_mode,
159
cheese_dbus_set_window (window);
161
gtk_widget_show (GTK_WIDGET (window));
163
gdk_threads_enter ();
165
gdk_threads_leave ();
168
/* Note: this function is bad with multithread applications as it
169
* calls xmlCleanupParser() and should be only called right before