summaryrefslogtreecommitdiffstats
path: root/kitchensync/libqopensync/callbackhandler.cpp
blob: 504afea995746a6354c2d6cfed9e194de3e58273 (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
/*
    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.
*/

#include <osengine/engine.h>

#include <libqopensync/engine.h>

#include <tqapplication.h>

#include "callbackhandler.h"

using namespace QSync;

class CallbackHandler::ConflictEvent : public QCustomEvent
{
  public:
    ConflictEvent( const SyncMapping& mapping )
      : TQCustomEvent( ConflictEventType ), mMapping( mapping )
    {
    }

    SyncMapping mapping() const { return mMapping; }

  private:
    SyncMapping mMapping;
};

class CallbackHandler::ChangeEvent : public QCustomEvent
{
  public:
    ChangeEvent( const SyncChangeUpdate& change )
      : TQCustomEvent( ChangeEventType ), mChange( change )
    {
    }

    SyncChangeUpdate change() const { return mChange; }

  private:
    SyncChangeUpdate mChange;
};

class CallbackHandler::MappingEvent : public QCustomEvent
{
  public:
    MappingEvent( const SyncMappingUpdate& mapping )
      : TQCustomEvent( MappingEventType ), mMapping( mapping )
    {
    }

    SyncMappingUpdate mapping() const { return mMapping; }

  private:
    SyncMappingUpdate mMapping;
};

class CallbackHandler::EngineEvent : public QCustomEvent
{
  public:
    EngineEvent( const SyncEngineUpdate& engine )
      : TQCustomEvent( EngineEventType ), mEngine( engine )
    {
    }

    SyncEngineUpdate engine() const { return mEngine; }

  private:
    SyncEngineUpdate mEngine;
};

class CallbackHandler::MemberEvent : public QCustomEvent
{
  public:
    MemberEvent( const SyncMemberUpdate& member )
      : TQCustomEvent( MemberEventType ), mMember( member )
    {
    }

    SyncMemberUpdate member() const { return mMember; }

  private:
    SyncMemberUpdate mMember;
};

CallbackHandler::CallbackHandler()
{
}

CallbackHandler::~CallbackHandler()
{
}

void CallbackHandler::setEngine( Engine *engine )
{
  mEngine = engine;

  osengine_set_conflict_callback( engine->mEngine, &conflict_callback, this );
  osengine_set_changestatus_callback( engine->mEngine, &change_callback, this );
  osengine_set_mappingstatus_callback( engine->mEngine, &mapping_callback, this );
  osengine_set_enginestatus_callback( engine->mEngine, &engine_callback, this );
  osengine_set_memberstatus_callback( engine->mEngine, &member_callback, this );
}

Engine* CallbackHandler::engine() const
{
  return mEngine;
}

void CallbackHandler::customEvent( TQCustomEvent *event )
{
  if ( event->type() == static_cast<TQEvent::Type>( ConflictEventType ) ) {
    ConflictEvent *conflictEvent = static_cast<ConflictEvent*>( event );
    emit conflict( conflictEvent->mapping() );
  } else if ( event->type() == static_cast<TQEvent::Type>( ChangeEventType ) ) {
    ChangeEvent *changeEvent = static_cast<ChangeEvent*>( event );
    emit change( changeEvent->change() );
  } else if ( event->type() == static_cast<TQEvent::Type>( MappingEventType ) ) {
    MappingEvent *mappingEvent = static_cast<MappingEvent*>( event );
    emit mapping( mappingEvent->mapping() );
  } else if ( event->type() == static_cast<TQEvent::Type>( EngineEventType ) ) {
    EngineEvent *engineEvent = static_cast<EngineEvent*>( event );
    emit engine( engineEvent->engine() );
  } else if ( event->type() == static_cast<TQEvent::Type>( MemberEventType ) ) {
    MemberEvent *memberEvent = static_cast<MemberEvent*>( event );
    emit member( memberEvent->member() );
  }
}

void CallbackHandler::conflict_callback( OSyncEngine *engine, OSyncMapping *omapping, void *data )
{
  SyncMapping mapping( omapping, engine );

  CallbackHandler *handler = static_cast<CallbackHandler*>( data );

  TQApplication::postEvent( handler, new ConflictEvent( mapping ) );
}

void CallbackHandler::change_callback( OSyncEngine*, OSyncChangeUpdate *update, void *data )
{
  SyncChangeUpdate change( update );

  CallbackHandler *handler = static_cast<CallbackHandler*>( data );

  TQApplication::postEvent( handler, new ChangeEvent( change ) );
}

void CallbackHandler::mapping_callback( OSyncMappingUpdate *update, void *data )
{
  CallbackHandler *handler = static_cast<CallbackHandler*>( data );

  SyncMappingUpdate mapping( update, handler->engine()->mEngine );

  TQApplication::postEvent( handler, new MappingEvent( mapping ) );
}

void CallbackHandler::engine_callback( OSyncEngine*, OSyncEngineUpdate *update, void *data )
{
  SyncEngineUpdate engine( update );

  CallbackHandler *handler = static_cast<CallbackHandler*>( data );

  TQApplication::postEvent( handler, new EngineEvent( engine ) );
}

void CallbackHandler::member_callback( OSyncMemberUpdate *update, void *data )
{
  SyncMemberUpdate member( update );

  CallbackHandler *handler = static_cast<CallbackHandler*>( data );

  TQApplication::postEvent( handler, new MemberEvent( member ) );
}

#include "callbackhandler.moc"