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