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"
36 std::ostream
& operator<< (std::ostream
&os
, const string_list_type
&list
)
38 string_list_type::const_iterator b
= list
.begin(), e
= list
.end();
39 for( ; b
!= e
; ++b
) {
45 std::ostream
& operator<< (std::ostream
&os
, const Member
&member
)
47 os
<< "Member ID: 0x" << hex
<< member
.id
48 << "\n Plugin Name: " << member
.plugin_name
;
49 os
<< "\n Friendly Name: ";
50 if( member
.friendly_name
.size() )
51 os
<< member
.friendly_name
;
57 std::ostream
& operator<< (std::ostream
&os
, const member_list_type
&list
)
59 member_list_type::const_iterator b
= list
.begin(), e
= list
.end();
60 for( ; b
!= e
; ++b
) {
66 std::ostream
& operator<< (std::ostream
&os
, const Format
&format
)
68 os
<< "Format: " << format
.name
69 << " (Object Type: " << format
.object_type
<< ")";
73 std::ostream
& operator<< (std::ostream
&os
, const format_list_type
&list
)
75 format_list_type::const_iterator b
= list
.begin(), e
= list
.end();
76 for( ; b
!= e
; ++b
) {
83 /////////////////////////////////////////////////////////////////////////////
84 // MemberSet public members
86 Member
* MemberSet::Find(long id
)
88 iterator b
= begin(), e
= end();
89 for( ; b
!= e
; ++b
) {
96 Member
* MemberSet::Find(const char *plugin_name
)
98 iterator b
= begin(), e
= end();
99 for( ; b
!= e
; ++b
) {
100 if( b
->plugin_name
== plugin_name
)
106 long MemberSet::FindId(const char *plugin_name
)
108 iterator b
= begin(), e
= end();
109 for( ; b
!= e
; ++b
) {
110 if( b
->plugin_name
== plugin_name
)
116 /////////////////////////////////////////////////////////////////////////////
117 // FormatSet public members
119 Format
* FormatSet::Find(const char *name
)
121 iterator b
= begin(), e
= end();
122 for( ; b
!= e
; ++b
) {
123 if( b
->name
== name
)
129 /////////////////////////////////////////////////////////////////////////////
130 // SyncConflict public members
132 SyncConflict::SyncConflict(SyncConflictPrivateBase
&conflict
)
133 : m_conflict(conflict
)
137 SyncConflict::~SyncConflict()
141 bool SyncConflict::IsAbortSupported() const
143 return m_conflict
.IsAbortSupported();
146 bool SyncConflict::IsIgnoreSupported() const
148 return m_conflict
.IsIgnoreSupported();
151 bool SyncConflict::IsKeepNewerSupported() const
153 return m_conflict
.IsKeepNewerSupported();
156 std::string
SyncConflict::GetMenu() const
159 oss
<< _C("Which entry do you want to use?\n[1-9] To select a side");
161 // Translator note: the menu letters must remain the same!
162 if( IsAbortSupported() )
163 oss
<< _C(", [A]bort");
165 oss
<< _C(", [D]uplicate");
167 if( IsIgnoreSupported() )
168 oss
<< _C(", [I]gnore");
170 if( IsKeepNewerSupported() )
171 oss
<< _C(", Keep [N]ewer");
176 void SyncConflict::Select(int change_index
)
178 m_conflict
.Select(change_index
);
181 void SyncConflict::Abort()
186 void SyncConflict::Duplicate()
188 m_conflict
.Duplicate();
191 void SyncConflict::Ignore()
196 void SyncConflict::KeepNewer()
198 m_conflict
.KeepNewer();
201 std::ostream
& SyncConflict::Dump(std::ostream
&os
) const
203 const_iterator b
= begin(), e
= end();
204 for( ; b
!= e
; ++b
) {
205 os
<< "Entry " << (b
->id
+1) << ":\n"
206 << "Member: " << b
->member_id
<< "(" << b
->plugin_name
<< ")\n"
207 << "UID: " << b
->uid
<< "\n"
208 << "Data: " << b
->printable_data
<< "\n";
214 /////////////////////////////////////////////////////////////////////////////
215 // SyncSummary public members
217 SyncSummary::SyncSummary(SyncSummaryPrivateBase
&summary
)
222 SyncSummary::~SyncSummary()
226 void SyncSummary::Abort()
231 void SyncSummary::Continue()
233 m_summary
.Continue();
236 std::ostream
& SyncSummary::Dump(std::ostream
&os
) const
239 const_iterator b
= begin(), e
= end();
240 for( ; b
!= e
; ++b
) {
241 if( b
->objtype_name
!= objtype_name
) {
242 objtype_name
= b
->objtype_name
;
243 os
<< "Objtype: " << b
->objtype_name
<< "\n";
246 os
<< "\tMember " << b
->id
<< "(" << b
->member_id
<< ") "
248 << ": Adding(" << b
->added
<< ") "
249 << "Modifying(" << b
->modified
<< ") "
250 << "Deleting(" << b
->deleted
<< ")\n";
256 /////////////////////////////////////////////////////////////////////////////
257 // SyncStatus public members - default, CLI imeplementations
259 SyncStatus::~SyncStatus()
263 void SyncStatus::HandleConflict(SyncConflict
&conflict
)
268 cout
<< _C("Conflicting items:") << "\n" << conflict
<< endl
;
269 cout
<< conflict
.GetMenu() << ": ";
283 conflict
.Select(atoi(line
.c_str()) - 1);
287 if( conflict
.IsAbortSupported() )
290 cout
<< _C("Abort not supported!") << endl
;
294 conflict
.Duplicate();
298 if( conflict
.IsIgnoreSupported() )
301 cout
<< _C("Ignore not supported!") << endl
;
305 if( conflict
.IsKeepNewerSupported() )
306 conflict
.KeepNewer();
308 cout
<< _C("Keep Newer not supported!") << endl
;
317 void SyncStatus::EntryStatus(const std::string
&msg
, bool error
)
320 cout
<< _C("ERROR: ");
324 void SyncStatus::MappingStatus(const std::string
&msg
, bool error
)
327 cout
<< _C("ERROR: ");
331 void SyncStatus::EngineStatus(const std::string
&msg
, bool error
, bool slowsync
)
334 cout
<< _C("ERROR: ");
338 void SyncStatus::MemberStatus(long member_id
,
339 const std::string
&plugin_name
,
340 const std::string
&msg
,
344 cout
<< _C("ERROR: ");
348 void SyncStatus::CheckSummary(SyncSummary
&summary
)
350 cout
<< "\n" << _C("Synchronization Forecast Summary:") << "\n";
351 cout
<< summary
<< endl
;
353 cout
<< _C("Do you want to continue the synchronization? (N/y): ");
357 // Abort if not got accepted with 'y'
358 if( line
[0] != 'y') {
359 cout
<< "\n" << _C("Aborting! Synchronization got aborted by user!") << endl
;
362 cout
<< "\n" << _C("OK! Completing synchronization!") << endl
;
367 void SyncStatus::ReportError(const std::string
&msg
)
369 cout
<< _C("CALLBACK ERROR: ") << msg
<< endl
;
373 /////////////////////////////////////////////////////////////////////////////
374 // OpenSyncAPISet public members
382 iterator b
= begin(), e
= end();
383 for( ; b
!= e
; ++b
) {
390 // throws if not all can be opened
391 void APISet::OpenAll()
393 push_back( new OpenSync40
);
394 push_back( new OpenSync22
);
398 int APISet::OpenAvailable()
403 API
*p
= new OpenSync40
;
407 catch( std::exception
&e
) {
408 cerr
<< _C("Unable to load opensync 0.40: ") << e
.what();
413 API
*p
= new OpenSync22
;
417 catch( std::exception
&e
) {
418 cerr
<< _C("Unable to load opensync 0.22: ") << e
.what();
425 int APISet::GetAvailable() const
427 return ((*this)[0] ? 1 : 0) + ((*this)[1] ? 1 : 0);
440 } // namespace OpenSync