summaryrefslogtreecommitdiffstats
path: root/kitchensync/libqopensync/environment.h
blob: f412a32c01bebb3581372840b002f62a912c9400 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
    This file is part of libqopensync.

    Copyright (c) 2005 Tobias Koenig <tokoe@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef OSYNC_ENVIRONMENT_H
#define OSYNC_ENVIRONMENT_H

#include <qstring.h>

#include <libqopensync/group.h>
#include <libqopensync/plugin.h>
#include <libqopensync/result.h>
#include <libqopensync/conversion.h>

struct OSyncEnv;

namespace QSync {

class Environment
{
  public:
    Environment();
    ~Environment();

    class GroupIterator
    {
      friend class Environment;

      public:
        GroupIterator( Environment *environment )
          : mEnvironment( environment ), mPos( -1 )
        {
        }

        GroupIterator( const GroupIterator &it )
        {
          mEnvironment = it.mEnvironment;
          mPos = it.mPos;
        }

        Group operator*() 
        {
          return mEnvironment->groupAt( mPos );
        }

        GroupIterator &operator++() { mPos++; return *this; }
        GroupIterator &operator++( int ) { mPos++; return *this; }
        GroupIterator &operator--() { mPos--; return *this; }
        GroupIterator &operator--( int ) { mPos--; return *this; }
        bool operator==( const GroupIterator &it ) { return mEnvironment == it.mEnvironment && mPos == it.mPos; }
        bool operator!=( const GroupIterator &it ) { return mEnvironment == it.mEnvironment && mPos != it.mPos; }

      private:
        Environment *mEnvironment;
        int mPos;
    };

    class PluginIterator
    {
      friend class Environment;

      public:
        PluginIterator( Environment *environment )
          : mEnvironment( environment ), mPos( -1 )
        {
        }

        PluginIterator( const PluginIterator &it )
        {
          mEnvironment = it.mEnvironment;
          mPos = it.mPos;
        }

        Plugin operator*() 
        {
          return mEnvironment->pluginAt( mPos );
        }

        PluginIterator &operator++() { mPos++; return *this; }
        PluginIterator &operator++( int ) { mPos++; return *this; }
        PluginIterator &operator--() { mPos--; return *this; }
        PluginIterator &operator--( int ) { mPos--; return *this; }
        bool operator==( const PluginIterator &it ) { return mEnvironment == it.mEnvironment && mPos == it.mPos; }
        bool operator!=( const PluginIterator &it ) { return mEnvironment == it.mEnvironment && mPos != it.mPos; }

      private:
        Environment *mEnvironment;
        int mPos;
    };

    /**
      Returns an iterator pointing to the first item in the group list.
      This iterator equals groupEnd() if the group list is empty.
     */
    GroupIterator groupBegin();

    /**
      Returns an iterator pointing past the last item in the group list.
      This iterator equals groupBegin() if the group list is empty.
     */
    GroupIterator groupEnd();

    /**
      Returns an iterator pointing to the first item in the plugin list.
      This iterator equals pluginEnd() if the group list is empty.
     */
    PluginIterator pluginBegin();

    /**
      Returns an iterator pointing past the last item in the plugin list.
      This iterator equals pluginBegin() if the plugin list is empty.
     */
    PluginIterator pluginEnd();

    /**
      Initializes the environment ( e.g. loads the groups and plugins ).
      Has to be called before the groups or plugins can be accessed.
     */
    Result initialize();

    /**
      Finalizes the environment ( e.g. unloads the groups and plugins ).
      Should be the last call before the object is deleted.
     */
    Result finalize();

    /**
      Returns the number of groups.
     */
    int groupCount() const;

    /**
      Returns the group at position @param pos.
     */
    Group groupAt( int pos ) const;

    /**
      Returns a group by name or an invalid group when the group with this
      name doesn't exists.
     */
    Group groupByName( const QString &name ) const;

    /**
      Adds a new group to the environment.

      @returns the new group.
     */
    Group addGroup();

    /**
      Removes a group from the environment.
     */
    Result removeGroup( const Group &group );

    /**
      Returns the number of plugins.
     */
    int pluginCount() const;

    /**
      Returns the plugin at position @param pos.
     */
    Plugin pluginAt( int pos ) const;

    /**
      Returns a plugin by name or an invalid plugin when the plugin with this
      name doesn't exists.
     */
    Plugin pluginByName( const QString &name ) const;

    /**
      Returns the conversion object of this environment.
     */
    Conversion conversion() const;

  private:
    OSyncEnv *mEnvironment;
};

}

#endif