add user specified stylesheet option
[claws.git] / src / common / claws.c
blobc216472269043a53f002c321fa54174c5a6ede7d
1 /*
2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2012 the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include "defs.h"
26 #include <stdlib.h>
27 #include <glib.h>
28 #ifdef ENABLE_NLS
29 #include <glib/gi18n.h>
30 #else
31 #define _(a) (a)
32 #define N_(a) (a)
33 #endif
35 #if HAVE_LOCALE_H
36 # include <locale.h>
37 #endif
39 #include "claws.h"
40 #include "utils.h"
41 #include "ssl.h"
42 #include "version.h"
44 static gboolean claws_initialized = FALSE;
45 static gchar *startup_dir;
46 static void (*claws_idle_function)(void) = NULL;
48 /**
49 * Parse program parameters and remove all parameters
50 * that have been processed. Arguments are pointers to
51 * original passed programm arguments and these will
52 * be modified leaving only unknown parameters for
53 * further processing
55 * \param argc pointer to number of parameters
56 * \param argv pointer to array of parameter strings
58 static void parse_parameter(int *argc, char ***argv)
60 gint i, j, k;
62 cm_return_if_fail(argc != NULL);
63 cm_return_if_fail(argv != NULL);
65 for (i = 1; i < *argc;) {
66 if (strcmp("--debug", (*argv)[i]) == 0) {
67 debug_set_mode(TRUE);
69 (*argv)[i] = NULL;
72 i += 1;
75 /* Remove NULL args from argv[] for further processing */
76 for (i = 1; i < *argc; i++) {
77 for (k = i; k < *argc; k++)
78 if ((*argv)[k] != NULL)
79 break;
81 if (k > i) {
82 k -= i;
83 for (j = i + k; j < *argc; j++)
84 (*argv)[j - k] = (*argv)[j];
85 *argc -= k;
90 gboolean claws_init(int *argc, char ***argv)
92 if (claws_initialized)
93 return TRUE;
95 #ifdef USE_GNUTLS
96 ssl_init();
97 #endif
98 startup_dir = g_get_current_dir();
100 parse_parameter(argc, argv);
102 debug_print("Starting Claws Mail version %s\n", PROG_VERSION);
104 setlocale(LC_ALL, "");
105 #ifdef ENABLE_NLS
106 bindtextdomain(PACKAGE, get_locale_dir () );
107 bind_textdomain_codeset (PACKAGE, "UTF-8");
108 textdomain(PACKAGE);
109 #endif /*ENABLE_NLS*/
110 putenv("G_BROKEN_FILENAMES=1");
111 putenv("LIBOVERLAY_SCROLLBAR=0");
113 /* backup if old rc file exists */
114 if (is_file_exist(RC_DIR)) {
115 if (g_rename(RC_DIR, RC_DIR ".bak") < 0) {
116 FILE_OP_ERROR(RC_DIR, "rename");
117 return FALSE;
121 srand((gint) time(NULL));
123 claws_initialized = TRUE;
125 return TRUE;
128 void claws_done(void)
131 #ifdef USE_GNUTLS
132 ssl_done();
133 #endif
136 const gchar *claws_get_startup_dir(void)
138 return startup_dir;
141 guint claws_get_version(void)
143 return VERSION_NUMERIC;
146 void claws_register_idle_function (void (*idle_func)(void))
148 claws_idle_function = idle_func;
151 void claws_do_idle(void)
153 if (claws_idle_function != NULL)
154 claws_idle_function();