gst/gsterror.c (FILE_A_BUG): Be polite *and* helpful. Fixes #305291.
[platform/upstream/gstreamer.git] / gst / gsterror.c
1 /* GStreamer
2  * Copyright (C) <2003> David A. Schleef <ds@schleef.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /**
21  * SECTION:gsterror
22  * @short_description: Categorized error messages
23  *
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "gst_private.h"
31 #include <gst/gst.h>
32 #include "gst-i18n-lib.h"
33
34 #define TABLE(t, d, a, b) t[GST_ ## d ## _ERROR_ ## a] = g_strdup (b)
35 #define QUARK_FUNC(string)                                              \
36 GQuark gst_ ## string ## _error_quark (void) {                          \
37   static GQuark quark;                                                  \
38   if (!quark)                                                           \
39     quark = g_quark_from_static_string ("gst-" # string "-error-quark"); \
40   return quark; }
41
42 GType
43 gst_g_error_get_type (void)
44 {
45   static GType type = 0;
46
47   if (!type)
48     type = g_boxed_type_register_static ("GstGError",
49         (GBoxedCopyFunc) g_error_copy, (GBoxedFreeFunc) g_error_free);
50   return type;
51 }
52
53 #define FILE_A_BUG "  Please file a bug at "\
54     "http://bugzilla.gnome.org/enter_bug.cgi?product=GStreamer."
55
56 /* initialize the dynamic table of translated core errors */
57 static gchar **
58 _gst_core_errors_init (void)
59 {
60   gchar **t = NULL;
61
62   t = g_new0 (gchar *, GST_CORE_ERROR_NUM_ERRORS);
63
64   TABLE (t, CORE, FAILED,
65       N_("GStreamer encountered a general core library error."));
66   TABLE (t, CORE, TOO_LAZY,
67       N_("GStreamer developers were too lazy to assign an error code "
68           "to this error." FILE_A_BUG));
69   TABLE (t, CORE, NOT_IMPLEMENTED,
70       N_("Internal GStreamer error: code not implemented." FILE_A_BUG));
71   TABLE (t, CORE, STATE_CHANGE,
72       N_("Internal GStreamer error: state change failed." FILE_A_BUG));
73   TABLE (t, CORE, PAD, N_("Internal GStreamer error: pad problem." FILE_A_BUG));
74   TABLE (t, CORE, THREAD,
75       N_("Internal GStreamer error: thread problem." FILE_A_BUG));
76   TABLE (t, CORE, NEGOTIATION,
77       N_("Internal GStreamer error: negotiation problem." FILE_A_BUG));
78   TABLE (t, CORE, EVENT,
79       N_("Internal GStreamer error: event problem." FILE_A_BUG));
80   TABLE (t, CORE, SEEK,
81       N_("Internal GStreamer error: seek problem." FILE_A_BUG));
82   TABLE (t, CORE, CAPS,
83       N_("Internal GStreamer error: caps problem." FILE_A_BUG));
84   TABLE (t, CORE, TAG, N_("Internal GStreamer error: tag problem." FILE_A_BUG));
85
86   return t;
87 }
88
89 /* initialize the dynamic table of translated library errors */
90 static gchar **
91 _gst_library_errors_init (void)
92 {
93   gchar **t = NULL;
94
95   t = g_new0 (gchar *, GST_LIBRARY_ERROR_NUM_ERRORS);
96
97   TABLE (t, LIBRARY, FAILED,
98       N_("GStreamer encountered a general supporting library error."));
99   TABLE (t, LIBRARY, TOO_LAZY,
100       N_("GStreamer developers were too lazy to assign an error code "
101           "to this error." FILE_A_BUG));
102   TABLE (t, LIBRARY, INIT, N_("Could not initialize supporting library."));
103   TABLE (t, LIBRARY, SHUTDOWN, N_("Could not close supporting library."));
104   TABLE (t, LIBRARY, SETTINGS, N_("Could not close supporting library."));
105
106   return t;
107 }
108
109 /* initialize the dynamic table of translated resource errors */
110 static gchar **
111 _gst_resource_errors_init (void)
112 {
113   gchar **t = NULL;
114
115   t = g_new0 (gchar *, GST_RESOURCE_ERROR_NUM_ERRORS);
116
117   TABLE (t, RESOURCE, FAILED,
118       N_("GStreamer encountered a general resource error."));
119   TABLE (t, RESOURCE, TOO_LAZY,
120       N_("GStreamer developers were too lazy to assign an error code "
121           "to this error." FILE_A_BUG));
122   TABLE (t, RESOURCE, NOT_FOUND, N_("Resource not found."));
123   TABLE (t, RESOURCE, BUSY, N_("Resource busy or not available."));
124   TABLE (t, RESOURCE, OPEN_READ, N_("Could not open resource for reading."));
125   TABLE (t, RESOURCE, OPEN_WRITE, N_("Could not open resource for writing."));
126   TABLE (t, RESOURCE, OPEN_READ_WRITE,
127       N_("Could not open resource for reading and writing."));
128   TABLE (t, RESOURCE, CLOSE, N_("Could not close resource."));
129   TABLE (t, RESOURCE, READ, N_("Could not read from resource."));
130   TABLE (t, RESOURCE, WRITE, N_("Could not write to resource."));
131   TABLE (t, RESOURCE, SEEK, N_("Could not perform seek on resource."));
132   TABLE (t, RESOURCE, SYNC, N_("Could not synchronize on resource."));
133   TABLE (t, RESOURCE, SETTINGS,
134       N_("Could not get/set settings from/on resource."));
135
136   return t;
137 }
138
139 /* initialize the dynamic table of translated stream errors */
140 static gchar **
141 _gst_stream_errors_init (void)
142 {
143   gchar **t = NULL;
144
145   t = g_new0 (gchar *, GST_STREAM_ERROR_NUM_ERRORS);
146
147   TABLE (t, STREAM, FAILED,
148       N_("GStreamer encountered a general stream error."));
149   TABLE (t, STREAM, TOO_LAZY,
150       N_("GStreamer developers were too lazy to assign an error code "
151           "to this error." FILE_A_BUG));
152   TABLE (t, STREAM, NOT_IMPLEMENTED,
153       N_("Element doesn't implement handling of this stream. "
154           "Please file a bug."));
155   TABLE (t, STREAM, TYPE_NOT_FOUND, N_("Could not determine type of stream."));
156   TABLE (t, STREAM, WRONG_TYPE,
157       N_("The stream is of a different type than handled by this element."));
158   TABLE (t, STREAM, CODEC_NOT_FOUND,
159       N_("There is no codec present that can handle the stream's type."));
160   TABLE (t, STREAM, DECODE, N_("Could not decode stream."));
161   TABLE (t, STREAM, ENCODE, N_("Could not encode stream."));
162   TABLE (t, STREAM, DEMUX, N_("Could not demultiplex stream."));
163   TABLE (t, STREAM, MUX, N_("Could not multiplex stream."));
164
165   return t;
166 }
167
168 QUARK_FUNC (core);
169 QUARK_FUNC (library);
170 QUARK_FUNC (resource);
171 QUARK_FUNC (stream);
172
173 /**
174  * gst_error_get_message:
175  * @domain: the GStreamer error domain this error belongs to.
176  * @code: the error code belonging to the domain.
177  *
178  * Get a string describing the error message in the current locale.
179  *
180  * Returns: a newly allocated string describing the error message in the
181  * current locale.
182  */
183 gchar *
184 gst_error_get_message (GQuark domain, gint code)
185 {
186   static gchar **gst_core_errors = NULL;
187   static gchar **gst_library_errors = NULL;
188   static gchar **gst_resource_errors = NULL;
189   static gchar **gst_stream_errors = NULL;
190
191   gchar *message = NULL;
192
193   /* initialize error message tables if necessary */
194   if (gst_core_errors == NULL)
195     gst_core_errors = _gst_core_errors_init ();
196   if (gst_library_errors == NULL)
197     gst_library_errors = _gst_library_errors_init ();
198   if (gst_resource_errors == NULL)
199     gst_resource_errors = _gst_resource_errors_init ();
200   if (gst_stream_errors == NULL)
201     gst_stream_errors = _gst_stream_errors_init ();
202
203
204   if (domain == GST_CORE_ERROR)
205     message = gst_core_errors[code];
206   else if (domain == GST_LIBRARY_ERROR)
207     message = gst_library_errors[code];
208   else if (domain == GST_RESOURCE_ERROR)
209     message = gst_resource_errors[code];
210   else if (domain == GST_STREAM_ERROR)
211     message = gst_stream_errors[code];
212   else {
213     g_warning ("No error messages for domain %s", g_quark_to_string (domain));
214     return g_strdup_printf (_("No error message for domain %s."),
215         g_quark_to_string (domain));
216   }
217   if (message)
218     return g_strdup (_(message));
219   else
220     return
221         g_strdup_printf (_
222         ("No standard error message for domain %s and code %d."),
223         g_quark_to_string (domain), code);
224 }