group.h
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 #ifndef TQSYNC_GROUP_H
23 #define TQSYNC_GROUP_H
24 
25 #include <tqdatetime.h>
26 #include <tqstringlist.h>
27 
28 #include <libqopensync/filter.h>
29 #include <libqopensync/member.h>
30 
31 class OSyncGroup;
32 
33 namespace QSync {
34 
38 class GroupConfig
39 {
40  friend class Group;
41 
42  public:
43  GroupConfig();
44 
45  TQStringList activeObjectTypes() const;
46  void setActiveObjectTypes( const TQStringList &objectTypes );
47 
48  private:
49  OSyncGroup *mGroup;
50 };
51 
52 
53 class Group
54 {
55  friend class Engine;
56  friend class Environment;
57 
58  public:
59  enum LockType
60  {
61  LockOk,
62  Locked,
63  LockStale
64  };
65 
66  Group();
67  ~Group();
68 
72  bool isValid() const;
73 
74  class Iterator
75  {
76  friend class Group;
77 
78  public:
79  Iterator( Group *group )
80  : mGroup( group ), mPos( -1 )
81  {
82  }
83 
84  Iterator( const Iterator &it )
85  {
86  mGroup = it.mGroup;
87  mPos = it.mPos;
88  }
89 
90  Member operator*()
91  {
92  return mGroup->memberAt( mPos );
93  }
94 
95  Iterator &operator++() { mPos++; return *this; }
96  Iterator &operator++( int ) { mPos++; return *this; }
97  Iterator &operator--() { mPos--; return *this; }
98  Iterator &operator--( int ) { mPos--; return *this; }
99  bool operator==( const Iterator &it ) { return mGroup == it.mGroup && mPos == it.mPos; }
100  bool operator!=( const Iterator &it ) { return mGroup == it.mGroup && mPos != it.mPos; }
101 
102  private:
103  Group *mGroup;
104  int mPos;
105  };
106 
111  Iterator begin();
112 
117  Iterator end();
118 
122  void setName( const TQString &name );
123 
127  TQString name() const;
128 
132  void setLastSynchronization( const TQDateTime &dateTime );
133 
137  TQDateTime lastSynchronization() const;
138 
144  LockType lock();
145 
151  void unlock( bool removeFile = true );
152 
158  Member addMember();
159 
163  void removeMember( const Member &member );
164 
168  int memberCount() const;
169 
173  Member memberAt( int pos ) const;
174 
178  int filterCount() const;
179 
183  Filter filterAt( int pos );
184 
189  void setObjectTypeEnabled( const TQString &objectType, bool enabled );
190 
195  bool isObjectTypeEnabled( const TQString &objectType ) const;
196 
200  Result save();
201 
207  GroupConfig config() const;
208 
209  bool operator==( const Group &group ) const { return mGroup == group.mGroup; }
210 
211  private:
212  OSyncGroup *mGroup;
213 };
214 
215 }
216 
217 #endif