3 /// Base API class helpers
7 Copyright (C) 2009-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
25 #include "osprivatebase.h"
35 std::ostream
& operator<< (std::ostream
&os
, const string_list_type
&list
)
37 string_list_type::const_iterator b
= list
.begin(), e
= list
.end();
38 for( ; b
!= e
; ++b
) {
44 std::ostream
& operator<< (std::ostream
&os
, const Member
&member
)
46 os
<< "Member ID: 0x" << hex
<< member
.id
47 << "\n Plugin Name: " << member
.plugin_name
;
48 os
<< "\n Friendly Name: ";
49 if( member
.friendly_name
.size() )
50 os
<< member
.friendly_name
;
56 std::ostream
& operator<< (std::ostream
&os
, const member_list_type
&list
)
58 member_list_type::const_iterator b
= list
.begin(), e
= list
.end();
59 for( ; b
!= e
; ++b
) {
65 std::ostream
& operator<< (std::ostream
&os
, const Format
&format
)
67 os
<< "Format: " << format
.name
68 << " (Object Type: " << format
.object_type
<< ")";
72 std::ostream
& operator<< (std::ostream
&os
, const format_list_type
&list
)
74 format_list_type::const_iterator b
= list
.begin(), e
= list
.end();
75 for( ; b
!= e
; ++b
) {
82 /////////////////////////////////////////////////////////////////////////////
83 // MemberSet public members
85 Member
* MemberSet::Find(long id
)
87 iterator b
= begin(), e
= end();
88 for( ; b
!= e
; ++b
) {
95 Member
* MemberSet::Find(const char *plugin_name
)
97 iterator b
= begin(), e
= end();
98 for( ; b
!= e
; ++b
) {
99 if( b
->plugin_name
== plugin_name
)
105 long MemberSet::FindId(const char *plugin_name
)
107 iterator b
= begin(), e
= end();
108 for( ; b
!= e
; ++b
) {
109 if( b
->plugin_name
== plugin_name
)
115 /////////////////////////////////////////////////////////////////////////////
116 // FormatSet public members
118 Format
* FormatSet::Find(const char *name
)
120 iterator b
= begin(), e
= end();
121 for( ; b
!= e
; ++b
) {
122 if( b
->name
== name
)
128 /////////////////////////////////////////////////////////////////////////////
129 // SyncConflict public members
131 SyncConflict::SyncConflict(SyncConflictPrivateBase
&conflict
)
132 : m_conflict(conflict
)
136 SyncConflict::~SyncConflict()
140 bool SyncConflict::IsAbortSupported() const
142 return m_conflict
.IsAbortSupported();
145 bool SyncConflict::IsIgnoreSupported() const
147 return m_conflict
.IsIgnoreSupported();
150 bool SyncConflict::IsKeepNewerSupported() const
152 return m_conflict
.IsKeepNewerSupported();
155 std::string
SyncConflict::GetMenu() const
158 oss
<< "Which entry do you want to use?\n[1-9] To select a side";
160 if( IsAbortSupported() )
163 oss
<< ", [D]uplicate";
165 if( IsIgnoreSupported() )
168 if( IsKeepNewerSupported() )
169 oss
<< ", Keep [N]ewer";
174 void SyncConflict::Select(int change_index
)
176 m_conflict
.Select(change_index
);
179 void SyncConflict::Abort()
184 void SyncConflict::Duplicate()
186 m_conflict
.Duplicate();
189 void SyncConflict::Ignore()
194 void SyncConflict::KeepNewer()
196 m_conflict
.KeepNewer();
199 std::ostream
& SyncConflict::Dump(std::ostream
&os
) const
201 const_iterator b
= begin(), e
= end();
202 for( ; b
!= e
; ++b
) {
203 os
<< "Entry " << (b
->id
+1) << ":\n"
204 << "Member: " << b
->member_id
<< "(" << b
->plugin_name
<< ")\n"
205 << "UID: " << b
->uid
<< "\n"
206 << "Data: " << b
->printable_data
<< "\n";
212 /////////////////////////////////////////////////////////////////////////////
213 // SyncSummary public members
215 SyncSummary::SyncSummary(SyncSummaryPrivateBase
&summary
)
220 SyncSummary::~SyncSummary()
224 void SyncSummary::Abort()
229 void SyncSummary::Continue()
231 m_summary
.Continue();
234 std::ostream
& SyncSummary::Dump(std::ostream
&os
) const
237 const_iterator b
= begin(), e
= end();
238 for( ; b
!= e
; ++b
) {
239 if( b
->objtype_name
!= objtype_name
) {
240 objtype_name
= b
->objtype_name
;
241 os
<< "Objtype: " << b
->objtype_name
<< "\n";
244 os
<< "\tMember " << b
->id
<< "(" << b
->member_id
<< ") "
246 << ": Adding(" << b
->added
<< ") "
247 << "Modifying(" << b
->modified
<< ") "
248 << "Deleting(" << b
->deleted
<< ")\n";
254 /////////////////////////////////////////////////////////////////////////////
255 // SyncStatus public members - default, CLI imeplementations
257 SyncStatus::~SyncStatus()
261 void SyncStatus::HandleConflict(SyncConflict
&conflict
)
266 cout
<< "Conflicting items:\n" << conflict
<< endl
;
267 cout
<< conflict
.GetMenu() << ": ";
281 conflict
.Select(atoi(line
.c_str()) - 1);
285 if( conflict
.IsAbortSupported() )
288 cout
<< "Abort not supported!" << endl
;
292 conflict
.Duplicate();
296 if( conflict
.IsIgnoreSupported() )
299 cout
<< "Ignore not supported!" << endl
;
303 if( conflict
.IsKeepNewerSupported() )
304 conflict
.KeepNewer();
306 cout
<< "Keep Newer not supported!" << endl
;
315 void SyncStatus::EntryStatus(const std::string
&msg
, bool error
)
322 void SyncStatus::MappingStatus(const std::string
&msg
, bool error
)
329 void SyncStatus::EngineStatus(const std::string
&msg
, bool error
, bool slowsync
)
336 void SyncStatus::MemberStatus(long member_id
,
337 const std::string
&plugin_name
,
338 const std::string
&msg
,
346 void SyncStatus::CheckSummary(SyncSummary
&summary
)
348 cout
<< "\nSynchronization Forecast Summary:\n";
349 cout
<< summary
<< endl
;
351 cout
<< "Do you want to continue the synchronization? (N/y): ";
355 // Abort if not got accepted with 'y'
356 if( line
[0] != 'y') {
357 cout
<< "\nAborting! Synchronization got aborted by user!" << endl
;
360 cout
<< "\nOK! Completing synchronization!" << endl
;
365 void SyncStatus::ReportError(const std::string
&msg
)
367 cout
<< "CALLBACK ERROR: " << msg
<< endl
;
371 /////////////////////////////////////////////////////////////////////////////
372 // OpenSyncAPISet public members
380 iterator b
= begin(), e
= end();
381 for( ; b
!= e
; ++b
) {
388 // throws if not all can be opened
389 void APISet::OpenAll()
391 push_back( new OpenSync40
);
392 push_back( new OpenSync22
);
396 int APISet::OpenAvailable()
401 API
*p
= new OpenSync40
;
405 catch( std::exception
&e
) {
406 cerr
<< "Unable to load opensync 0.40: " << e
.what();
411 API
*p
= new OpenSync22
;
415 catch( std::exception
&e
) {
416 cerr
<< "Unable to load opensync 0.22: " << e
.what();
423 int APISet::GetAvailable() const
425 return ((*this)[0] ? 1 : 0) + ((*this)[1] ? 1 : 0);
438 } // namespace OpenSync