environment.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 "environment.h"
23
24#include <opensync/opensync.h>
25
26using namespace QSync;
27
28Environment::Environment()
29{
30 mEnvironment = osync_env_new();
31}
32
33Environment::~Environment()
34{
35 osync_env_free( mEnvironment );
36}
37
38Environment::GroupIterator Environment::groupBegin()
39{
40 GroupIterator it( this );
41 it.mPos = 0;
42
43 return it;
44}
45
46Environment::GroupIterator Environment::groupEnd()
47{
48 GroupIterator it( this );
49 it.mPos = groupCount();
50
51 return it;
52}
53
54Environment::PluginIterator Environment::pluginBegin()
55{
56 PluginIterator it( this );
57 it.mPos = 0;
58
59 return it;
60}
61
62Environment::PluginIterator Environment::pluginEnd()
63{
64 PluginIterator it( this );
65 it.mPos = pluginCount();
66
67 return it;
68}
69
70Result Environment::initialize()
71{
72 OSyncError *error = 0;
73 if ( !osync_env_initialize( mEnvironment, &error ) )
74 return Result( &error );
75 else
76 return Result();
77}
78
79Result Environment::finalize()
80{
81 OSyncError *error = 0;
82 if ( !osync_env_finalize( mEnvironment, &error ) )
83 return Result( &error);
84 else
85 return Result();
86}
87
88int Environment::groupCount() const
89{
90 return osync_env_num_groups( mEnvironment );
91}
92
93Group Environment::groupAt( int pos ) const
94{
95 Group group;
96
97 if ( pos < 0 || pos >= groupCount() )
98 return group;
99
100 OSyncGroup *ogroup = osync_env_nth_group( mEnvironment, pos );
101 group.mGroup = ogroup;
102
103 return group;
104}
105
106Group Environment::groupByName( const TQString &name ) const
107{
108 Group group;
109
110 OSyncGroup *ogroup = osync_env_find_group( mEnvironment, name.latin1() );
111 if ( ogroup )
112 group.mGroup = ogroup;
113
114 return group;
115}
116
117Group Environment::addGroup()
118{
119 Group group;
120
121 OSyncGroup *ogroup = osync_group_new( mEnvironment );
122 if ( ogroup )
123 group.mGroup = ogroup;
124
125 return group;
126}
127
128Result Environment::removeGroup( const Group &group )
129{
130 OSyncError *error = 0;
131 if ( !osync_group_delete( group.mGroup, &error ) )
132 return Result( &error );
133 else
134 return Result();
135}
136
137int Environment::pluginCount() const
138{
139 return osync_env_num_plugins( mEnvironment );
140}
141
142Plugin Environment::pluginAt( int pos ) const
143{
144 Plugin plugin;
145
146 if ( pos < 0 || pos >= pluginCount() )
147 return plugin;
148
149 OSyncPlugin *oplugin = osync_env_nth_plugin( mEnvironment, pos );
150 plugin.mPlugin = oplugin;
151
152 return plugin;
153}
154
155Plugin Environment::pluginByName( const TQString &name ) const
156{
157 Plugin plugin;
158
159 OSyncPlugin *oplugin = osync_env_find_plugin( mEnvironment, name.latin1() );
160 if ( oplugin )
161 plugin.mPlugin = oplugin;
162
163 return plugin;
164}
165
166Conversion Environment::conversion() const
167{
168 Conversion conversion;
169 conversion.mEnvironment = mEnvironment;
170
171 return conversion;
172}