Updated Traditional Chinese translation.
[evolution.git] / shell / e-shell-utils.c
blob195b25b986c343ab950e8230f0527b055757a571
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* e-shell-utils.c
4 * Copyright (C) 2000 Ximian, Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
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 GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Ettore Perazzoli
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <string.h>
29 #include <glib.h>
31 #include <libgnome/gnome-util.h>
32 #include <libgnome/gnome-i18n.h>
34 #include "e-shell-constants.h"
35 #include "e-shell-utils.h"
38 static char *
39 get_icon_path (const char *icon_name)
41 char *icon_path;
43 if (g_path_is_absolute (icon_name))
44 icon_path = g_strdup (icon_name);
45 else
46 icon_path = g_build_filename (EVOLUTION_IMAGES, icon_name, NULL);
48 if (g_file_test (icon_path, G_FILE_TEST_EXISTS)) {
49 return icon_path;
50 } else {
51 g_free (icon_path);
52 return NULL;
56 static char *
57 get_mini_name (const char *icon_name)
59 const char *dot_ptr;
60 char *basename;
61 char *name_without_extension;
62 char *mini_name;
64 basename = g_path_get_basename (icon_name);
65 if (basename == NULL)
66 return NULL;
68 dot_ptr = strrchr (basename, '.');
70 if (dot_ptr == NULL) {
71 /* No extension. */
72 g_free (basename);
73 return g_strconcat (icon_name, E_SHELL_MINI_ICON_SUFFIX, NULL);
76 name_without_extension = g_strndup (icon_name, dot_ptr - basename);
77 mini_name = g_strconcat (name_without_extension, E_SHELL_MINI_ICON_SUFFIX,
78 dot_ptr, NULL);
79 g_free (name_without_extension);
81 g_free (basename);
82 return mini_name;
86 char *
87 e_shell_get_icon_path (const char *icon_name,
88 gboolean try_mini)
90 if (try_mini) {
91 char *path;
92 char *mini_name;
94 mini_name = get_mini_name (icon_name);
95 if (mini_name == NULL) {
96 path = NULL;
97 } else {
98 path = get_icon_path (mini_name);
99 g_free (mini_name);
102 if (path != NULL)
103 return path;
106 return get_icon_path (icon_name);
110 gboolean
111 e_shell_folder_name_is_valid (const char *name,
112 const char **reason_return)
114 if (name == NULL || *name == '\0') {
115 if (reason_return != NULL)
116 *reason_return = _("No folder name specified.");
117 return FALSE;
120 /* GtkEntry is broken - if you hit KP_ENTER you get a \r inserted... */
121 if (strchr (name, '\r')) {
122 if (reason_return != NULL)
123 *reason_return = _("Folder name cannot contain the Return character.");
124 return FALSE;
127 if (strchr (name, E_PATH_SEPARATOR) != NULL) {
128 if (reason_return != NULL)
129 *reason_return = _("Folder name cannot contain the character \"/\".");
130 return FALSE;
133 if (strchr (name, '#') != NULL) {
134 if (reason_return != NULL)
135 *reason_return = _("Folder name cannot contain the character \"#\".");
136 return FALSE;
139 if (strcmp (name, ".") == 0 || strcmp (name, "..") == 0) {
140 if (reason_return != NULL)
141 *reason_return = _("'.' and '..' are reserved folder names.");
142 return FALSE;
145 *reason_return = NULL;
147 return TRUE;