2005-11-18 [colin] 1.9.100cvs22
[claws.git] / src / manual.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <string.h>
28
29 #if HAVE_LOCALE_H
30 #  include <locale.h>
31 #endif
32
33
34 #include "prefs_common.h"
35 #include "manual.h"
36 #include "utils.h"
37
38 static gchar *sylpheeddoc_manuals[] =
39 {
40     "en",
41     "es", 
42     "fr", 
43     "de",
44 };
45
46 static gchar *get_language()
47 {
48         gchar *language;
49         gchar *c;
50
51         language = g_strdup(setlocale(LC_MESSAGES, NULL));
52         if((c = strchr(language, ',')) != NULL)
53                 *c = '\0';
54         if((c = strchr(language, '_')) != NULL)
55                 *c = '\0';
56
57         return language;
58 }
59
60 static gchar *get_local_path_with_locale(gchar *rootpath)
61 {
62         gchar *lang_str, *dir;
63
64         lang_str = get_language();
65         dir = g_strconcat(rootpath, G_DIR_SEPARATOR_S, 
66                           lang_str, NULL);
67         g_free(lang_str);
68         if(!is_dir_exist(dir)) {
69                 g_free(dir);
70                 dir = g_strconcat(rootpath, G_DIR_SEPARATOR_S,
71                                   "en", NULL);
72                 if(!is_dir_exist(dir)) {
73                         g_free(dir);
74                         dir = NULL;
75                 }
76         }
77
78         return dir;
79 }
80
81 gboolean manual_available(ManualType type)
82 {
83         gboolean ret = FALSE;
84         gchar *dir = NULL;
85         
86         switch (type) {
87                 case MANUAL_MANUAL_LOCAL:
88                         dir = get_local_path_with_locale(MANUALDIR);
89                         if (dir != NULL) {
90                                 g_free(dir);
91                                 ret = TRUE;
92                         }
93                         break;
94                 case MANUAL_FAQ_LOCAL:
95                         dir = get_local_path_with_locale(FAQDIR);
96                         if (dir != NULL) {
97                                 g_free(dir);
98                                 ret = TRUE;
99                         }
100                         break;
101                 default:
102                         ret = FALSE;
103         }
104
105         return ret;
106 }
107
108 static gchar *get_syldoc_language()
109 {
110         gchar *language;
111         int i;
112         
113         language = get_language();
114         for (i = 0; i < sizeof(sylpheeddoc_manuals) / sizeof(sylpheeddoc_manuals[0]); i++) {
115                 if (strcmp(language, sylpheeddoc_manuals[i]) == 0) {
116                         return language;
117                 }
118         }
119         g_free(language);
120         
121         return g_strdup("en");
122 }
123
124 void manual_open(ManualType type)
125 {
126         gchar *uri = NULL;
127         gchar *dir;
128         gchar *lang_str;
129
130         switch (type) {
131                 case MANUAL_MANUAL_LOCAL:
132                         dir = get_local_path_with_locale(MANUALDIR);
133                         if (dir != NULL) {
134                                 uri = g_strconcat("file://", dir, G_DIR_SEPARATOR_S, MANUAL_HTML_INDEX, NULL);
135                                 g_free(dir);
136                         }
137                         break;
138
139                 case MANUAL_FAQ_LOCAL:
140                         dir = get_local_path_with_locale(FAQDIR);
141                         if (dir != NULL) {
142                                 uri = g_strconcat("file://", dir, G_DIR_SEPARATOR_S, FAQ_HTML_INDEX, NULL);
143                                 g_free(dir);
144                         }
145                         break;
146
147                 case MANUAL_MANUAL_SYLDOC:
148                         lang_str = get_syldoc_language();
149                         uri = g_strconcat(SYLDOC_URI, lang_str, SYLDOC_MANUAL_HTML_INDEX, NULL);
150                         g_free(lang_str);
151                         break;
152
153                 case MANUAL_FAQ_SYLDOC:
154                         lang_str = get_syldoc_language();
155                         uri = g_strconcat(SYLDOC_URI, lang_str, SYLDOC_FAQ_HTML_INDEX, NULL);
156                         g_free(lang_str);
157                         break;
158
159                 case MANUAL_FAQ_CLAWS:
160                         uri = g_strconcat(FAQ_URI, NULL);
161                         break;
162
163                 default:
164                         break;
165         }
166         open_uri(uri, prefs_common.uri_cmd);
167         g_free(uri);
168 }