kitchensync
environment.cpp
00001 /* 00002 This file is part of libqopensync. 00003 00004 Copyright (c) 2005 Tobias Koenig <tokoe@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include "environment.h" 00023 00024 #include <opensync/opensync.h> 00025 00026 using namespace QSync; 00027 00028 Environment::Environment() 00029 { 00030 mEnvironment = osync_env_new(); 00031 } 00032 00033 Environment::~Environment() 00034 { 00035 osync_env_free( mEnvironment ); 00036 } 00037 00038 Environment::GroupIterator Environment::groupBegin() 00039 { 00040 GroupIterator it( this ); 00041 it.mPos = 0; 00042 00043 return it; 00044 } 00045 00046 Environment::GroupIterator Environment::groupEnd() 00047 { 00048 GroupIterator it( this ); 00049 it.mPos = groupCount(); 00050 00051 return it; 00052 } 00053 00054 Environment::PluginIterator Environment::pluginBegin() 00055 { 00056 PluginIterator it( this ); 00057 it.mPos = 0; 00058 00059 return it; 00060 } 00061 00062 Environment::PluginIterator Environment::pluginEnd() 00063 { 00064 PluginIterator it( this ); 00065 it.mPos = pluginCount(); 00066 00067 return it; 00068 } 00069 00070 Result Environment::initialize() 00071 { 00072 OSyncError *error = 0; 00073 if ( !osync_env_initialize( mEnvironment, &error ) ) 00074 return Result( &error ); 00075 else 00076 return Result(); 00077 } 00078 00079 Result Environment::finalize() 00080 { 00081 OSyncError *error = 0; 00082 if ( !osync_env_finalize( mEnvironment, &error ) ) 00083 return Result( &error); 00084 else 00085 return Result(); 00086 } 00087 00088 int Environment::groupCount() const 00089 { 00090 return osync_env_num_groups( mEnvironment ); 00091 } 00092 00093 Group Environment::groupAt( int pos ) const 00094 { 00095 Group group; 00096 00097 if ( pos < 0 || pos >= groupCount() ) 00098 return group; 00099 00100 OSyncGroup *ogroup = osync_env_nth_group( mEnvironment, pos ); 00101 group.mGroup = ogroup; 00102 00103 return group; 00104 } 00105 00106 Group Environment::groupByName( const QString &name ) const 00107 { 00108 Group group; 00109 00110 OSyncGroup *ogroup = osync_env_find_group( mEnvironment, name.latin1() ); 00111 if ( ogroup ) 00112 group.mGroup = ogroup; 00113 00114 return group; 00115 } 00116 00117 Group Environment::addGroup() 00118 { 00119 Group group; 00120 00121 OSyncGroup *ogroup = osync_group_new( mEnvironment ); 00122 if ( ogroup ) 00123 group.mGroup = ogroup; 00124 00125 return group; 00126 } 00127 00128 Result Environment::removeGroup( const Group &group ) 00129 { 00130 OSyncError *error = 0; 00131 if ( !osync_group_delete( group.mGroup, &error ) ) 00132 return Result( &error ); 00133 else 00134 return Result(); 00135 } 00136 00137 int Environment::pluginCount() const 00138 { 00139 return osync_env_num_plugins( mEnvironment ); 00140 } 00141 00142 Plugin Environment::pluginAt( int pos ) const 00143 { 00144 Plugin plugin; 00145 00146 if ( pos < 0 || pos >= pluginCount() ) 00147 return plugin; 00148 00149 OSyncPlugin *oplugin = osync_env_nth_plugin( mEnvironment, pos ); 00150 plugin.mPlugin = oplugin; 00151 00152 return plugin; 00153 } 00154 00155 Plugin Environment::pluginByName( const QString &name ) const 00156 { 00157 Plugin plugin; 00158 00159 OSyncPlugin *oplugin = osync_env_find_plugin( mEnvironment, name.latin1() ); 00160 if ( oplugin ) 00161 plugin.mPlugin = oplugin; 00162 00163 return plugin; 00164 } 00165 00166 Conversion Environment::conversion() const 00167 { 00168 Conversion conversion; 00169 conversion.mEnvironment = mEnvironment; 00170 00171 return conversion; 00172 }