~ubuntu-branches/ubuntu/oneiric/gconf/oneiric-proposed

« back to all changes in this revision

Viewing changes to gconf/gconf-error.c

  • Committer: Bazaar Package Importer
  • Author(s): Takuo KITAME
  • Date: 2002-03-17 01:51:39 UTC
  • Revision ID: james.westby@ubuntu.com-20020317015139-z4f8fdg1hoe049g0
Tags: upstream-1.0.9
ImportĀ upstreamĀ versionĀ 1.0.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GConf
 
2
 * Copyright (C) 1999, 2000 Red Hat Inc.
 
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
#include "gconf-error.h"
 
21
#include "gconf-internals.h"
 
22
#include <stdarg.h>
 
23
 
 
24
static const gchar* err_msgs[] = {
 
25
  N_("Success"),
 
26
  N_("Failed"),
 
27
  N_("Configuration server couldn't be contacted"),
 
28
  N_("Permission denied"),
 
29
  N_("Couldn't resolve address for configuration source"),
 
30
  N_("Bad key or directory name"),
 
31
  N_("Parse error"),
 
32
  N_("Corrupt data in configuration source database"),
 
33
  N_("Type mismatch"),
 
34
  N_("Key operation on directory"),
 
35
  N_("Directory operation on key"),
 
36
  N_("Can't overwrite existing read-only value"),
 
37
  N_("Object Activation Framework error"),
 
38
  N_("Operation not allowed without configuration server"),
 
39
  N_("Failed to get a lock"),
 
40
  N_("No database available to save your configuration")
 
41
};
 
42
 
 
43
static const int n_err_msgs = sizeof(err_msgs)/sizeof(err_msgs[0]);
 
44
 
 
45
static const gchar* 
 
46
gconf_strerror       (GConfError en)
 
47
{
 
48
  g_return_val_if_fail (en < n_err_msgs, NULL);
 
49
 
 
50
  return _(err_msgs[en]);    
 
51
}
 
52
 
 
53
GQuark
 
54
gconf_error_quark (void)
 
55
{
 
56
  static GQuark err_q = 0;
 
57
 
 
58
  if (err_q == 0)
 
59
    err_q = g_quark_from_static_string ("gconf-error-quark");
 
60
 
 
61
  return err_q;
 
62
}
 
63
 
 
64
static GError* 
 
65
gconf_error_new_valist(GConfError en, const gchar* fmt, va_list args)
 
66
{
 
67
  GError *err;
 
68
  gchar* orig;
 
69
  
 
70
  orig = g_strdup_vprintf(fmt, args);
 
71
 
 
72
  err = g_error_new (GCONF_ERROR, en, "%s:\n %s",
 
73
                     gconf_strerror (en),
 
74
                     orig);  
 
75
 
 
76
  g_free(orig);
 
77
  
 
78
  return err;
 
79
}
 
80
 
 
81
GError*
 
82
gconf_error_new(GConfError en, const gchar* fmt, ...)
 
83
{
 
84
  GError* err;
 
85
  va_list args;
 
86
  
 
87
  va_start (args, fmt);
 
88
  err = gconf_error_new_valist(en, fmt, args);
 
89
  va_end (args);
 
90
 
 
91
  return err;
 
92
}
 
93
 
 
94
void
 
95
gconf_set_error      (GError** err, GConfError en, const gchar* fmt, ...)
 
96
{
 
97
  GError* obj;
 
98
  va_list args;
 
99
 
 
100
  if (err == NULL)
 
101
    return;
 
102
 
 
103
  /* Warn if we stack up errors on top
 
104
   * of each other. Keep the "deepest"
 
105
   * error
 
106
   */
 
107
  g_return_if_fail(*err == NULL);
 
108
  
 
109
  va_start (args, fmt);
 
110
  obj = gconf_error_new_valist(en, fmt, args);
 
111
  va_end (args);
 
112
 
 
113
  *err = obj;
 
114
}
 
115
 
 
116
/* This function should die. */
 
117
GError*
 
118
gconf_compose_errors (GError* err1, GError* err2)
 
119
{
 
120
  if (err1 == NULL && err2 == NULL)
 
121
    return NULL;
 
122
  else if (err1 == NULL)
 
123
    return g_error_copy(err2);
 
124
  else if (err2 == NULL)
 
125
    return g_error_copy(err1);
 
126
  else
 
127
    {
 
128
      GError *n;
 
129
 
 
130
      n = g_error_new (GCONF_ERROR, GCONF_ERROR_FAILED, " ");
 
131
 
 
132
      if (err1->code == err2->code)
 
133
        n->code = err1->code;
 
134
      else
 
135
        n->code = GCONF_ERROR_FAILED;
 
136
 
 
137
      g_free (n->message);
 
138
      
 
139
      n->message = g_strconcat(err1->message, "\n", err2->message, NULL);
 
140
 
 
141
      return n;
 
142
    }
 
143
}
 
144