2005-12-09 [paul] 1.9.100cvs81
[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 *get_language()
39 {
40         gchar *language;
41         gchar *c;
42
43         language = g_strdup(setlocale(LC_MESSAGES, NULL));
44         if((c = strchr(language, ',')) != NULL)
45                 *c = '\0';
46         if((c = strchr(language, '_')) != NULL)
47                 *c = '\0';
48
49         return language;
50 }
51
52 static gchar *get_local_path_with_locale(gchar *rootpath)
53 {
54         gchar *lang_str, *dir;
55
56         lang_str = get_language();
57         dir = g_strconcat(rootpath, G_DIR_SEPARATOR_S, 
58                           lang_str, NULL);
59         g_free(lang_str);
60         if(!is_dir_exist(dir)) {
61                 g_free(dir);
62                 dir = g_strconcat(rootpath, G_DIR_SEPARATOR_S,
63                                   "en", NULL);
64                 if(!is_dir_exist(dir)) {
65                         g_free(dir);
66                         dir = NULL;
67                 }
68         }
69
70         return dir;
71 }
72
73 gboolean manual_available(ManualType type)
74 {
75         gboolean ret = FALSE;
76         gchar *dir = NULL;
77         
78         switch (type) {
79                 case MANUAL_MANUAL_LOCAL:
80                         dir = get_local_path_with_locale(MANUALDIR);
81                         if (dir != NULL) {
82                                 g_free(dir);
83                                 ret = TRUE;
84                         }
85                         break;
86                 default:
87                         ret = FALSE;
88         }
89
90         return ret;
91 }
92
93 void manual_open(ManualType type)
94 {
95         gchar *uri = NULL;
96         gchar *dir;
97
98         switch (type) {
99                 case MANUAL_MANUAL_LOCAL:
100                         dir = get_local_path_with_locale(MANUALDIR);
101                         if (dir != NULL) {
102                                 uri = g_strconcat("file://", dir, G_DIR_SEPARATOR_S, MANUAL_HTML_INDEX, NULL);
103                                 g_free(dir);
104                         }
105                         break;
106                 case MANUAL_FAQ_CLAWS:
107                         uri = g_strconcat(FAQ_URI, NULL);
108                         break;
109
110                 default:
111                         break;
112         }
113         open_uri(uri, prefs_common.uri_cmd);
114         g_free(uri);
115 }