source: trunk/third/evolution/shell/e-shell-utils.c @ 18142

Revision 18142, 3.1 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18141, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* e-shell-utils.c
3 *
4 * Copyright (C) 2000  Ximian, Inc.
5 *
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.
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 GNU
13 * General Public License for more details.
14 *
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.
19 *
20 * Author: Ettore Perazzoli
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include <string.h>
28
29#include <glib.h>
30#include <libgnome/gnome-defs.h>
31#include <libgnome/gnome-util.h>
32#include <libgnome/gnome-i18n.h>
33
34#include "e-shell-constants.h"
35#include "e-shell-utils.h"
36
37
38static char *
39get_icon_path (const char *icon_name)
40{
41        char *icon_path;
42
43        if (g_path_is_absolute (icon_name))
44                icon_path = g_strdup (icon_name);
45        else
46                icon_path = g_concat_dir_and_file (EVOLUTION_IMAGES, icon_name);
47
48        if (g_file_exists (icon_path)) {
49                return icon_path;
50        } else {
51                g_free (icon_path);
52                return NULL;
53        }
54}
55
56static char *
57get_mini_name (const char *icon_name)
58{
59        const char *dot_ptr;
60        const char *basename;
61        char *name_without_extension;
62        char *mini_name;
63
64        basename = g_basename (icon_name);
65        if (basename == NULL)
66                return NULL;
67
68        dot_ptr = strrchr (basename, '.');
69
70        if (dot_ptr == NULL) {
71                /* No extension.  */
72                return g_strconcat (icon_name, E_SHELL_MINI_ICON_SUFFIX, NULL);
73        }
74
75        name_without_extension = g_strndup (icon_name, dot_ptr - icon_name);
76        mini_name = g_strconcat (name_without_extension, E_SHELL_MINI_ICON_SUFFIX,
77                                 dot_ptr, NULL);
78        g_free (name_without_extension);
79
80        return mini_name;
81}
82
83
84char *
85e_shell_get_icon_path (const char *icon_name,
86                       gboolean try_mini)
87{
88        if (try_mini) {
89                char *path;
90                char *mini_name;
91
92                mini_name = get_mini_name (icon_name);
93                if (mini_name == NULL) {
94                        path = NULL;
95                } else {
96                        path = get_icon_path (mini_name);
97                        g_free (mini_name);
98                }
99
100                if (path != NULL)
101                        return path;
102        }
103
104        return get_icon_path (icon_name);
105}
106
107
108gboolean
109e_shell_folder_name_is_valid (const char *name,
110                              const char **reason_return)
111{
112        if (name == NULL || *name == '\0') {
113                if (reason_return != NULL)
114                        *reason_return = _("No folder name specified.");
115                return FALSE;
116        }
117       
118        /* GtkEntry is broken - if you hit KP_ENTER you get a \r inserted... */
119        if (strchr (name, '\r')) {
120                if (reason_return != NULL)
121                        *reason_return = _("Folder name cannot contain the Return character.");
122                return FALSE;
123        }
124       
125        if (strchr (name, E_PATH_SEPARATOR) != NULL) {
126                if (reason_return != NULL)
127                        *reason_return = _("Folder name cannot contain slashes.");
128                return FALSE;
129        }
130       
131        if (strcmp (name, ".") == 0 || strcmp (name, "..") == 0) {
132                if (reason_return != NULL)
133                        *reason_return = _("'.' and '..' are reserved folder names.");
134                return FALSE;
135        }
136
137        *reason_return = NULL;
138       
139        return TRUE;
140}
141
Note: See TracBrowser for help on using the repository browser.