DBus-1-TQt  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tqdbuserror.cpp
Go to the documentation of this file.
1 /* qdbuserror.cpp TQT_DBusError object
2  *
3  * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
4  * Copyright (C) 2005-2007 Kevin Krammer <kevin.krammer@gmx.at>
5  *
6  * Licensed under the Academic Free License version 2.1
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  *
23  */
24 
25 #include "tqdbuserror.h"
26 
27 #include <dbus/dbus.h>
28 
29 #include <tqmap.h>
30 
31 typedef TQMap<TQString, TQT_DBusError::ErrorType> ErrorNameMap;
33 
35 {
36  switch (type)
37  {
39  Q_ASSERT(false);
40  return TQString();
41 
43  return TQString::fromUtf8(DBUS_ERROR_FAILED);
45  return TQString::fromUtf8(DBUS_ERROR_NO_MEMORY);
47  return TQString::fromUtf8(DBUS_ERROR_SERVICE_UNKNOWN);
49  return TQString::fromUtf8(DBUS_ERROR_NAME_HAS_NO_OWNER);
51  return TQString::fromUtf8(DBUS_ERROR_NO_REPLY);
53  return TQString::fromUtf8(DBUS_ERROR_IO_ERROR);
55  return TQString::fromUtf8(DBUS_ERROR_BAD_ADDRESS);
57  return TQString::fromUtf8(DBUS_ERROR_NOT_SUPPORTED);
59  return TQString::fromUtf8(DBUS_ERROR_LIMITS_EXCEEDED);
61  return TQString::fromUtf8(DBUS_ERROR_ACCESS_DENIED);
63  return TQString::fromUtf8(DBUS_ERROR_AUTH_FAILED);
65  return TQString::fromUtf8(DBUS_ERROR_NO_SERVER);
67  return TQString::fromUtf8(DBUS_ERROR_TIMEOUT);
69  return TQString::fromUtf8(DBUS_ERROR_NO_NETWORK);
71  return TQString::fromUtf8(DBUS_ERROR_DISCONNECTED);
73  return TQString::fromUtf8(DBUS_ERROR_INVALID_ARGS);
75  return TQString::fromUtf8(DBUS_ERROR_FILE_NOT_FOUND);
77  return TQString::fromUtf8(DBUS_ERROR_FILE_EXISTS);
79  return TQString::fromUtf8(DBUS_ERROR_UNKNOWN_METHOD);
81  return TQString::fromUtf8(DBUS_ERROR_TIMED_OUT);
83  return TQString::fromUtf8(DBUS_ERROR_INVALID_SIGNATURE);
84 
86  Q_ASSERT(false);
87  return TQString();
88  }
89 
90  Q_ASSERT(false);
91  return TQString();
92 }
93 
95 {
97  {
100  }
101 }
102 
104 {
105  if (name.isEmpty()) return TQT_DBusError::InvalidError;
106 
107  if (errorTypesByName.isEmpty())
109 
110  ErrorNameMap::const_iterator it = errorTypesByName.find(name);
111  if (it != errorTypesByName.end()) return it.data();
112 
114 }
115 
116 TQT_DBusError::TQT_DBusError() : errorType(InvalidError), m_dbusErrorSet(false)
117 {
118 }
119 
120 TQT_DBusError::TQT_DBusError(const DBusError *error) : errorType(InvalidError), m_dbusErrorSet(false)
121 {
122  if (!error || !dbus_error_is_set(error))
123  return;
124 
125  nm = TQString::fromUtf8(error->name);
126  msg = TQString::fromUtf8(error->message);
127 
129 }
130 
131 TQT_DBusError::TQT_DBusError(const TQString& error, const TQString& message)
132  : errorType(UserDefined), m_dbusErrorSet(false), nm(error), msg(message)
133 {
135 }
136 
138 {
139  return errorType != InvalidError && !nm.isEmpty() && !msg.isEmpty();
140 }
141 
142 TQT_DBusError::TQT_DBusError(ErrorType type, const TQString& message)
143  : errorType(type), m_dbusErrorSet(false), msg(message)
144 {
145  nm = qDBusErrorNameForType(type);
146 }
147 
148 TQT_DBusError TQT_DBusError::stdFailed(const TQString& message)
149 {
150  return TQT_DBusError(TQT_DBusError::Failed, message);
151 }
152 
154 {
155  return TQT_DBusError(TQT_DBusError::NoMemory, message);
156 }
157 
158 TQT_DBusError TQT_DBusError::stdNoReply(const TQString& message)
159 {
160  return TQT_DBusError(TQT_DBusError::NoReply, message);
161 }
162 
163 TQT_DBusError TQT_DBusError::stdIOError(const TQString& message)
164 {
165  return TQT_DBusError(TQT_DBusError::IOError, message);
166 }
167 
169 {
171 }
172 
174 {
176 }
177 
179 {
181 }
182 
184 {
185  return TQT_DBusError(TQT_DBusError::AuthFailed, message);
186 }
187 
188 TQT_DBusError TQT_DBusError::stdTimeout(const TQString& message)
189 {
190  return TQT_DBusError(TQT_DBusError::Timeout, message);
191 }
192 
194 {
195  return TQT_DBusError(TQT_DBusError::InvalidArgs, message);
196 }
197 
199 {
201 }
202 
204 {
205  return TQT_DBusError(TQT_DBusError::FileExists, message);
206 }
207 
209 {
211 }
212 
214 {
216 }