1/* This library is free software; you can redistribute it and/or
2 * modify it under the terms of the GNU Lesser General Public
3 * License as published by the Free Software Foundation; either
4 * version 2 of the License, or (at your option) any later version.
5 *
6 * This library is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 * Lesser General Public License for more details.
10 *
11 * You should have received a copy of the GNU Lesser General Public
12 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
13 */
14#include "config.h"
15#include "gtkfilechoosererrorstackprivate.h"
16#include "gtkstack.h"
17#include "gtklabel.h"
18#include "gtkintl.h"
19#include "gtkbinlayout.h"
20
21G_DEFINE_TYPE (GtkFileChooserErrorStack, gtk_file_chooser_error_stack, GTK_TYPE_WIDGET)
22
23static void
24gtk_file_chooser_error_stack_dispose (GObject *object)
25{
26 GtkFileChooserErrorStack *self = GTK_FILE_CHOOSER_ERROR_STACK (object);
27
28 g_clear_pointer (&self->stack, gtk_widget_unparent);
29
30 G_OBJECT_CLASS (gtk_file_chooser_error_stack_parent_class)->dispose (object);
31}
32
33static void
34gtk_file_chooser_error_stack_class_init (GtkFileChooserErrorStackClass *class)
35{
36 GObjectClass *object_class = G_OBJECT_CLASS (class);
37 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
38
39 object_class->dispose = gtk_file_chooser_error_stack_dispose;
40
41 gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
42}
43
44static void
45gtk_file_chooser_error_stack_init (GtkFileChooserErrorStack *self)
46{
47 GtkWidget *label;
48 GtkStack *stack;
49
50 self->stack = gtk_stack_new ();
51 gtk_widget_set_parent (widget: self->stack, GTK_WIDGET (self));
52 stack = GTK_STACK (self->stack);
53
54 gtk_stack_set_transition_type (stack, transition: GTK_STACK_TRANSITION_TYPE_CROSSFADE);
55 gtk_stack_set_transition_duration (stack, duration: 50);
56
57 label = gtk_label_new (str: "");
58 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
59 gtk_stack_add_named (stack, child: label, name: "no-error");
60
61 label = gtk_label_new (str: "");
62 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
63 gtk_stack_add_named (stack, child: label, name: "custom");
64
65 label = gtk_label_new (_("A folder cannot be called “.”"));
66 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
67 gtk_stack_add_named (stack, child: label, name: "folder-cannot-be-called-dot");
68
69 label = gtk_label_new (_("A file cannot be called “.”"));
70 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
71 gtk_stack_add_named (stack, child: label, name: "file-cannot-be-called-dot");
72
73 label = gtk_label_new (_("A folder cannot be called “..”"));
74 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
75 gtk_stack_add_named (stack, child: label, name: "folder-cannot-be-called-dot-dot");
76
77 label = gtk_label_new (_("A file cannot be called “..”"));
78 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
79 gtk_stack_add_named (stack, child: label, name: "file-cannot-be-called-dot-dot");
80
81 label = gtk_label_new (_("Folder names cannot contain “/”"));
82 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
83 gtk_stack_add_named (stack, child: label, name: "folder-name-cannot-contain-slash");
84
85 label = gtk_label_new (_("File names cannot contain “/”"));
86 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
87 gtk_stack_add_named (stack, child: label, name: "file-name-cannot-contain-slash");
88
89 label = gtk_label_new (_("Folder names should not begin with a space"));
90 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
91 gtk_stack_add_named (stack, child: label, name: "folder-name-should-not-begin-with-space");
92
93 label = gtk_label_new (_("File names should not begin with a space"));
94 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
95 gtk_stack_add_named (stack, child: label, name: "file-name-should-not-begin-with-space");
96
97 label = gtk_label_new (_("Folder names should not end with a space"));
98 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
99 gtk_stack_add_named (stack, child: label, name: "folder-name-should-not-end-with-space");
100
101 label = gtk_label_new (_("File names should not end with a space"));
102 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
103 gtk_stack_add_named (stack, child: label, name: "file-name-should-not-end-with-space");
104
105 label = gtk_label_new (_("Folder names starting with a “.” are hidden"));
106 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
107 gtk_stack_add_named (stack, child: label, name: "folder-name-with-dot-is-hidden");
108
109 label = gtk_label_new (_("File names starting with a “.” are hidden"));
110 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
111 gtk_stack_add_named (stack, child: label, name: "file-name-with-dot-is-hidden");
112
113 label = gtk_label_new (_("A folder with that name already exists"));
114 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
115 gtk_stack_add_named (stack, child: label, name: "folder-name-already-exists");
116
117 label = gtk_label_new (_("A file with that name already exists"));
118 gtk_widget_set_halign (widget: label, align: GTK_ALIGN_START);
119 gtk_stack_add_named (stack, child: label, name: "file-name-already-exists");
120
121 gtk_stack_set_visible_child_name (stack, name: "no-error");
122}
123
124void
125gtk_file_chooser_error_stack_set_error (GtkFileChooserErrorStack *self,
126 gboolean is_folder,
127 const char *label_name)
128{
129 char *child_name;
130
131 if (g_strcmp0 (str1: label_name, str2: "no-error") == 0)
132 {
133 gtk_stack_set_visible_child_name (GTK_STACK (self->stack), name: "no-error");
134 return;
135 }
136
137 child_name = g_strdup_printf (format: "%s-%s",
138 is_folder ? "folder" : "file",
139 label_name);
140
141 gtk_stack_set_visible_child_name (GTK_STACK (self->stack), name: child_name);
142
143 g_free (mem: child_name);
144}
145
146
147void
148gtk_file_chooser_error_stack_set_custom_error (GtkFileChooserErrorStack *self,
149 const char *label_text)
150{
151 GtkWidget *label = gtk_stack_get_child_by_name (GTK_STACK (self->stack), name: "custom");
152
153 gtk_label_set_text (GTK_LABEL (label), str: label_text);
154
155 gtk_stack_set_visible_child_name (GTK_STACK (self->stack), name: "custom");
156}
157

source code of gtk/gtk/gtkfilechoosererrorstack.c