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