result.cpp
1/*
2 This file is part of libqopensync.
3
4 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "result.h"
23
24#include <opensync/opensync.h>
25
26using namespace QSync;
27
28Result::Result()
29 : mType( NoError )
30{
31}
32
33Result::Result( Type type )
34 : mType( type )
35{
36}
37
38Result::Result( OSyncError **error, bool deleteError )
39{
40 OSyncErrorType otype = osync_error_get_type( error );
41 Type type;
42
43 switch ( otype ) {
44 case OSYNC_NO_ERROR:
45 type = NoError;
46 break;
47 default:
48 case OSYNC_ERROR_GENERIC:
49 type = GenericError;
50 break;
51 case OSYNC_ERROR_IO_ERROR:
52 type = IOError;
53 break;
54 case OSYNC_ERROR_NOT_SUPPORTED:
55 type = NotSupported;
56 break;
57 case OSYNC_ERROR_TIMEOUT:
58 type = Timeout;
59 break;
60 case OSYNC_ERROR_DISCONNECTED:
61 type = Disconnected;
62 break;
63 case OSYNC_ERROR_FILE_NOT_FOUND:
64 type = FileNotFound;
65 break;
66 case OSYNC_ERROR_EXISTS:
67 type = Exists;
68 break;
69 case OSYNC_ERROR_CONVERT:
70 type = Convert;
71 break;
72 case OSYNC_ERROR_MISCONFIGURATION:
73 type = Misconfiguration;
74 break;
75 case OSYNC_ERROR_INITIALIZATION:
76 type = Initialization;
77 break;
78 case OSYNC_ERROR_PARAMETER:
79 type = Parameter;
80 break;
81 case OSYNC_ERROR_EXPECTED:
82 type = Expected;
83 break;
84 case OSYNC_ERROR_NO_CONNECTION:
85 type = NoConnection;
86 break;
87 case OSYNC_ERROR_TEMPORARY:
88 type = Temporary;
89 break;
90 case OSYNC_ERROR_LOCKED:
91 type = Locked;
92 break;
93 case OSYNC_ERROR_PLUGIN_NOT_FOUND:
94 type = PluginNotFound;
95 break;
96 }
97
98 mType = type;
99 mName = TQString::fromUtf8( osync_error_get_name( error ) );
100 mMessage = TQString::fromUtf8( osync_error_print( error ) );
101
102 if ( deleteError )
103 osync_error_free( error );
104}
105
106Result::~Result()
107{
108}
109
110void Result::setName( const TQString &name )
111{
112 mName = name;
113}
114
115TQString Result::name() const
116{
117 return mName;
118}
119
120void Result::setMessage( const TQString &message )
121{
122 mMessage = message;
123}
124
125TQString Result::message() const
126{
127 return mMessage;
128}
129
130void Result::setType( Type type )
131{
132 mType = type;
133}
134
135Result::Type Result::type() const
136{
137 return mType;
138}
139
140bool Result::isError() const
141{
142 return mType != NoError;
143}
144
145Result::operator bool () const
146{
147 return ( mType != NoError );
148}
149