inital gtk2 patch
[claws.git] / src / common / sylpheed.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999,2000 Hiroyuki Yamamoto
4  *
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 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25 #include <stdlib.h>
26 #include <glib.h>
27
28 #if HAVE_LOCALE_H
29 #  include <locale.h>
30 #endif
31
32 #include "sylpheed.h"
33 #include "intl.h"
34 #include "utils.h"
35 #include "ssl.h"
36 #include "version.h"
37 #include "plugin.h"
38
39 static gboolean sylpheed_initialized = FALSE;
40 static gchar *startup_dir;
41
42 /**
43  * Parse program parameters and remove all parameters
44  * that have been processed. Arguments are pointers to
45  * original passed programm arguments and these will
46  * be modified leaving only unknown parameters for
47  * further processing
48  *
49  * \param argc pointer to number of parameters
50  * \param argv pointer to array of parameter strings
51  */
52 static void parse_parameter(int *argc, char ***argv)
53 {
54         gint i, j, k;
55
56         g_return_if_fail(argc != NULL);
57         g_return_if_fail(argv != NULL);
58
59         for (i = 1; i < *argc;) {
60                 if (strcmp("--debug", (*argv)[i]) == 0) {
61                         debug_set_mode(TRUE);
62
63                         (*argv)[i] = NULL;
64                 }
65
66                 i += 1;
67         }
68
69         /* Remove NULL args from argv[] for further processing */
70         for (i = 1; i < *argc; i++) {
71                 for (k = i; k < *argc; k++)
72                         if ((*argv)[k] != NULL)
73                                 break;
74
75                 if (k > i) {
76                         k -= i;
77                         for (j = i + k; j < *argc; j++)
78                                 (*argv)[j - k] = (*argv)[j];
79                         *argc -= k;
80                 }
81         }
82 }
83
84 gboolean sylpheed_init(int *argc, char ***argv)
85 {
86         if (sylpheed_initialized)
87                 return TRUE;
88
89         startup_dir = g_get_current_dir();
90
91         parse_parameter(argc, argv);
92
93         debug_print("Starting sylpheed version %08x\n", VERSION_NUMERIC);
94
95         setlocale(LC_ALL, "");
96         bindtextdomain(PACKAGE, LOCALEDIR);
97         bind_textdomain_codeset (PACKAGE, "UTF-8");
98         textdomain(PACKAGE);
99         putenv("G_BROKEN_FILENAMES=1");
100
101         /* backup if old rc file exists */
102         if (is_file_exist(RC_DIR)) {
103                 if (rename(RC_DIR, RC_DIR ".bak") < 0) {
104                         FILE_OP_ERROR(RC_DIR, "rename");
105                         return FALSE;
106                 }
107         }
108
109         srandom((gint)time(NULL));
110
111 #if USE_OPENSSL
112         ssl_init();
113 #endif
114
115         plugin_load_all("Common");
116
117         sylpheed_initialized = TRUE;
118
119         return TRUE;
120 }
121
122 void sylpheed_done(void)
123 {
124         plugin_unload_all("Common");
125
126 #if USE_OPENSSL
127         ssl_done();
128 #endif
129 }
130
131 const gchar *sylpheed_get_startup_dir(void)
132 {
133         return startup_dir;
134 }
135
136 guint sylpheed_get_version(void)
137 {
138         return VERSION_NUMERIC;
139 }