| 51 | | private: |
| 52 | | KCalDataSource *kcal; |
| 53 | | KNotesDataSource *knotes; |
| 54 | | KContactDataSource *kaddrbook; |
| 55 | | |
| 56 | | OSyncHashTable *hashtable; |
| 57 | | OSyncMember *member; |
| 58 | | |
| 59 | | KApplication *application; |
| 60 | | |
| 61 | | |
| 62 | | public: |
| 63 | | KdePluginImplementation(OSyncMember *memb) |
| 64 | | :member(memb) |
| 65 | | { |
| 66 | | } |
| 67 | | |
| 68 | | void initKDE() { |
| 69 | | if (sentinal) { |
| 70 | | return; |
| 71 | | } |
| 72 | | |
| 73 | | KAboutData aboutData( |
| 74 | | "libopensync-kdepim-plugin", // internal program name |
| 75 | | "OpenSync-KDE-plugin", // displayable program name. |
| 76 | | "0.1", // version string |
| 77 | | "OpenSync KDEPIM plugin", // short porgram description |
| 78 | | KAboutData::License_GPL, // license type |
| 79 | | "(c) 2005, Eduardo Pereira Habkost", // copyright statement |
| 80 | | 0, // any free form text |
| 81 | | "http://www.opensync.org", // program home page address |
| 82 | | "http://www.opensync.org/newticket" // bug report email address |
| 83 | | ); |
| 84 | | |
| 85 | | KCmdLineArgs::init(&aboutData); |
| 86 | | application = new KApplication(); |
| 87 | | |
| 88 | | sentinal = true; |
| 89 | | } |
| 90 | | |
| 91 | | bool init(OSyncError **error) |
| 92 | | { |
| 93 | | osync_trace(TRACE_ENTRY, "%s(%p)", __func__, error); |
| 94 | | |
| 95 | | initKDE(); |
| 96 | | |
| 97 | | hashtable = osync_hashtable_new(); |
| 98 | | |
| 99 | | kcal = new KCalDataSource(member, hashtable); |
| 100 | | knotes = new KNotesDataSource(member, hashtable); |
| 101 | | kaddrbook = new KContactDataSource(member, hashtable); |
| 102 | | |
| | 51 | public: |
| | 52 | KdePluginImplementation( OSyncMember *member ) |
| | 53 | : mMember( member ), |
| | 54 | mApplication( 0 ), |
| | 55 | mNewApplication( false ) |
| | 56 | { |
| | 57 | } |
| | 58 | |
| | 59 | void initKDE() |
| | 60 | { |
| | 61 | if (sentinal) |
| | 62 | return; |
| | 63 | |
| | 64 | KAboutData aboutData( |
| | 65 | "libopensync-kdepim-plugin", // internal program name |
| | 66 | "OpenSync-KDE-plugin", // displayable program name. |
| | 67 | "0.1", // version string |
| | 68 | "OpenSync KDEPIM plugin", // short porgram description |
| | 69 | KAboutData::License_GPL, // license type |
| | 70 | "(c) 2005, Eduardo Pereira Habkost", // copyright statement |
| | 71 | 0, // any free form text |
| | 72 | "http://www.opensync.org", // program home page address |
| | 73 | "http://www.opensync.org/newticket" // bug report email address |
| | 74 | ); |
| | 75 | |
| | 76 | KCmdLineArgs::init( &aboutData ); |
| | 77 | if ( kapp ) |
| | 78 | mApplication = kapp; |
| | 79 | else { |
| | 80 | mApplication = new KApplication( false, false ); |
| | 81 | mNewApplication = true; |
| | 82 | } |
| | 83 | |
| | 84 | sentinal = true; |
| | 85 | } |
| | 86 | |
| | 87 | bool init(OSyncError **error) |
| | 88 | { |
| | 89 | osync_trace(TRACE_ENTRY, "%s(%p)", __func__, error); |
| | 90 | |
| | 91 | initKDE(); |
| | 92 | |
| | 93 | mHashtable = osync_hashtable_new(); |
| | 94 | |
| | 95 | mKcal = new KCalDataSource(mMember, mHashtable); |
| | 96 | mKnotes = new KNotesDataSource(mMember, mHashtable); |
| | 97 | mKaddrbook = new KContactDataSource(mMember, mHashtable); |
| | 98 | |
| | 99 | osync_trace(TRACE_EXIT, "%s", __func__); |
| | 100 | return true; |
| | 101 | } |
| | 102 | |
| | 103 | virtual ~KdePluginImplementation() |
| | 104 | { |
| | 105 | delete mKcal; |
| | 106 | mKcal = 0; |
| | 107 | |
| | 108 | delete mKnotes; |
| | 109 | mKnotes = 0; |
| | 110 | |
| | 111 | if ( mNewApplication ) { |
| | 112 | delete mApplication; |
| | 113 | mApplication = 0; |
| | 114 | } |
| | 115 | |
| | 116 | if ( mHashtable ) |
| | 117 | osync_hashtable_free(mHashtable); |
| | 118 | } |
| | 119 | |
| | 120 | virtual void connect(OSyncContext *ctx) |
| | 121 | { |
| | 122 | osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); |
| | 123 | |
| | 124 | OSyncError *error = NULL; |
| | 125 | if ( !osync_hashtable_load(mHashtable, mMember, &error) ) { |
| | 126 | osync_context_report_osyncerror(ctx, &error); |
| | 127 | osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); |
| | 128 | osync_error_free(&error); |
| | 129 | return; |
| | 130 | } |
| | 131 | |
| | 132 | |
| | 133 | if (mKcal && (osync_member_objtype_enabled(mMember, "todo") || |
| | 134 | osync_member_objtype_enabled(mMember, "event")) && !mKcal->connect(ctx)) { |
| | 135 | osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open calendar", __func__); |
| | 136 | return; |
| | 137 | } |
| | 138 | |
| | 139 | if (mKnotes && osync_member_objtype_enabled(mMember, "note") && \ |
| | 140 | !mKnotes->connect(ctx)) { |
| | 141 | osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open notes", __func__); |
| | 142 | return; |
| | 143 | } |
| | 144 | |
| | 145 | if (mKaddrbook && osync_member_objtype_enabled(mMember, "contact") && \ |
| | 146 | !mKaddrbook->connect(ctx)) { |
| | 147 | osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open addressbook", __func__); |
| | 148 | return; |
| | 149 | } |
| | 150 | |
| | 151 | osync_context_report_success(ctx); |
| 104 | | return true; |
| 105 | | } |
| 106 | | |
| 107 | | virtual ~KdePluginImplementation() |
| 108 | | { |
| 109 | | if (kcal) { |
| 110 | | delete kcal; |
| 111 | | kcal = NULL; |
| 112 | | } |
| 113 | | |
| 114 | | if (knotes) { |
| 115 | | delete knotes; |
| 116 | | knotes = NULL; |
| 117 | | } |
| 118 | | |
| 119 | | /*if (application) { |
| 120 | | delete application; |
| 121 | | application = NULL; |
| 122 | | }*/ |
| 123 | | |
| 124 | | if (hashtable) |
| 125 | | osync_hashtable_free(hashtable); |
| 126 | | } |
| 127 | | |
| 128 | | virtual void connect(OSyncContext *ctx) |
| 129 | | { |
| 130 | | osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx); |
| 131 | | |
| 132 | | OSyncError *error = NULL; |
| 133 | | if (!osync_hashtable_load(hashtable, member, &error)) { |
| 134 | | osync_context_report_osyncerror(ctx, &error); |
| 135 | | osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(&error)); |
| 136 | | osync_error_free(&error); |
| 137 | | return; |
| 138 | | } |
| 139 | | |
| 140 | | |
| 141 | | if (kcal && \ |
| 142 | | (osync_member_objtype_enabled(member, "todo") || \ |
| 143 | | osync_member_objtype_enabled(member, "event")) && \ |
| 144 | | !kcal->connect(ctx)) { |
| 145 | | osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open calendar", __func__); |
| 146 | | return; |
| 147 | | } |
| 148 | | |
| 149 | | if (knotes && \ |
| 150 | | osync_member_objtype_enabled(member, "note") && \ |
| 151 | | !knotes->connect(ctx)) { |
| 152 | | osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open notes", __func__); |
| 153 | | return; |
| 154 | | } |
| 155 | | |
| 156 | | if (kaddrbook && \ |
| 157 | | osync_member_objtype_enabled(member, "contact") && \ |
| 158 | | !kaddrbook->connect(ctx)) { |
| 159 | | osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open addressbook", __func__); |
| 160 | | return; |
| 161 | | } |
| 162 | | |
| 163 | | osync_context_report_success(ctx); |
| 164 | | osync_trace(TRACE_EXIT, "%s", __func__); |
| 165 | | } |
| 166 | | |
| 167 | | virtual void disconnect(OSyncContext *ctx) |
| 168 | | { |
| 169 | | osync_hashtable_close(hashtable); |
| 170 | | |
| 171 | | if (kcal && kcal->connected && !kcal->disconnect(ctx)) |
| 172 | | return; |
| 173 | | if (knotes && knotes->connected && !knotes->disconnect(ctx)) |
| 174 | | return; |
| 175 | | if (kaddrbook && kaddrbook->connected && !kaddrbook->disconnect(ctx)) |
| 176 | | return; |
| 177 | | |
| 178 | | osync_context_report_success(ctx); |
| 179 | | } |
| 180 | | |
| 181 | | virtual void get_changeinfo(OSyncContext *ctx) |
| 182 | | { |
| 183 | | if (kaddrbook && kaddrbook->connected && !kaddrbook->contact_get_changeinfo(ctx)) |
| 184 | | return; |
| 185 | | |
| 186 | | if (kcal && kcal->connected && !kcal->get_changeinfo_events(ctx)) |
| 187 | | return; |
| 188 | | |
| 189 | | if (kcal && kcal->connected && !kcal->get_changeinfo_todos(ctx)) |
| 190 | | return; |
| 191 | | |
| 192 | | if (knotes && knotes->connected && !knotes->get_changeinfo(ctx)) |
| 193 | | return; |
| 194 | | |
| 195 | | osync_context_report_success(ctx); |
| 196 | | } |
| 197 | | |
| 198 | | virtual bool vcard_access(OSyncContext *ctx, OSyncChange *chg) |
| 199 | | { |
| 200 | | if (kaddrbook) |
| 201 | | return kaddrbook->vcard_access(ctx, chg); |
| 202 | | else { |
| 203 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); |
| 204 | | return false; |
| 205 | | } |
| 206 | | return true; |
| 207 | | } |
| 208 | | |
| 209 | | virtual bool vcard_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| 210 | | { |
| 211 | | if (kaddrbook) |
| 212 | | return kaddrbook->vcard_commit_change(ctx, chg); |
| 213 | | else { |
| 214 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); |
| 215 | | return false; |
| 216 | | } |
| 217 | | return true; |
| 218 | | } |
| 219 | | |
| 220 | | virtual bool event_access(OSyncContext *ctx, OSyncChange *chg) |
| 221 | | { |
| 222 | | if (kcal) |
| 223 | | return kcal->event_access(ctx, chg); |
| 224 | | else { |
| 225 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| 226 | | return false; |
| 227 | | } |
| 228 | | return true; |
| 229 | | } |
| 230 | | |
| 231 | | virtual bool event_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| 232 | | { |
| 233 | | if (kcal) |
| 234 | | return kcal->event_commit_change(ctx, chg); |
| 235 | | else { |
| 236 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| 237 | | return false; |
| 238 | | } |
| 239 | | return true; |
| 240 | | } |
| 241 | | |
| 242 | | virtual bool todo_access(OSyncContext *ctx, OSyncChange *chg) |
| 243 | | { |
| 244 | | if (kcal) |
| 245 | | return kcal->todo_access(ctx, chg); |
| 246 | | else { |
| 247 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| 248 | | return false; |
| 249 | | } |
| 250 | | return true; |
| 251 | | } |
| 252 | | |
| 253 | | virtual bool todo_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| 254 | | { |
| 255 | | if (kcal) |
| 256 | | return kcal->todo_commit_change(ctx, chg); |
| 257 | | else { |
| 258 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| 259 | | return false; |
| 260 | | } |
| 261 | | return true; |
| 262 | | } |
| 263 | | |
| 264 | | virtual bool note_access(OSyncContext *ctx, OSyncChange *chg) |
| 265 | | { |
| 266 | | if (knotes) |
| 267 | | return knotes->access(ctx, chg); |
| 268 | | else { |
| 269 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No notes loaded"); |
| 270 | | return false; |
| 271 | | } |
| 272 | | return true; |
| 273 | | } |
| 274 | | |
| 275 | | virtual bool note_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| 276 | | { |
| 277 | | if (knotes) |
| 278 | | return knotes->commit_change(ctx, chg); |
| 279 | | else { |
| 280 | | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No notes loaded"); |
| 281 | | return false; |
| 282 | | } |
| 283 | | return true; |
| 284 | | } |
| 285 | | |
| | 153 | } |
| | 154 | |
| | 155 | virtual void disconnect(OSyncContext *ctx) |
| | 156 | { |
| | 157 | osync_hashtable_close(mHashtable); |
| | 158 | |
| | 159 | if (mKcal && mKcal->connected && !mKcal->disconnect(ctx)) |
| | 160 | return; |
| | 161 | if (mKnotes && mKnotes->connected && !mKnotes->disconnect(ctx)) |
| | 162 | return; |
| | 163 | if (mKaddrbook && mKaddrbook->connected && !mKaddrbook->disconnect(ctx)) |
| | 164 | return; |
| | 165 | |
| | 166 | osync_context_report_success(ctx); |
| | 167 | } |
| | 168 | |
| | 169 | virtual void get_changeinfo(OSyncContext *ctx) |
| | 170 | { |
| | 171 | if (mKaddrbook && mKaddrbook->connected && !mKaddrbook->contact_get_changeinfo(ctx)) |
| | 172 | return; |
| | 173 | |
| | 174 | if (mKcal && mKcal->connected && !mKcal->get_changeinfo_events(ctx)) |
| | 175 | return; |
| | 176 | |
| | 177 | if (mKcal && mKcal->connected && !mKcal->get_changeinfo_todos(ctx)) |
| | 178 | return; |
| | 179 | |
| | 180 | if (mKnotes && mKnotes->connected && !mKnotes->get_changeinfo(ctx)) |
| | 181 | return; |
| | 182 | |
| | 183 | osync_context_report_success(ctx); |
| | 184 | } |
| | 185 | |
| | 186 | virtual bool vcard_access(OSyncContext *ctx, OSyncChange *chg) |
| | 187 | { |
| | 188 | if (mKaddrbook) |
| | 189 | return mKaddrbook->vcard_access(ctx, chg); |
| | 190 | else { |
| | 191 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); |
| | 192 | return false; |
| | 193 | } |
| | 194 | return true; |
| | 195 | } |
| | 196 | |
| | 197 | virtual bool vcard_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| | 198 | { |
| | 199 | if (mKaddrbook) |
| | 200 | return mKaddrbook->vcard_commit_change(ctx, chg); |
| | 201 | else { |
| | 202 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No addressbook loaded"); |
| | 203 | return false; |
| | 204 | } |
| | 205 | return true; |
| | 206 | } |
| | 207 | |
| | 208 | virtual bool event_access(OSyncContext *ctx, OSyncChange *chg) |
| | 209 | { |
| | 210 | if (mKcal) |
| | 211 | return mKcal->event_access(ctx, chg); |
| | 212 | else { |
| | 213 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| | 214 | return false; |
| | 215 | } |
| | 216 | return true; |
| | 217 | } |
| | 218 | |
| | 219 | virtual bool event_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| | 220 | { |
| | 221 | if (mKcal) |
| | 222 | return mKcal->event_commit_change(ctx, chg); |
| | 223 | else { |
| | 224 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| | 225 | return false; |
| | 226 | } |
| | 227 | return true; |
| | 228 | } |
| | 229 | |
| | 230 | virtual bool todo_access(OSyncContext *ctx, OSyncChange *chg) |
| | 231 | { |
| | 232 | if (mKcal) |
| | 233 | return mKcal->todo_access(ctx, chg); |
| | 234 | else { |
| | 235 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| | 236 | return false; |
| | 237 | } |
| | 238 | return true; |
| | 239 | } |
| | 240 | |
| | 241 | virtual bool todo_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| | 242 | { |
| | 243 | if (mKcal) |
| | 244 | return mKcal->todo_commit_change(ctx, chg); |
| | 245 | else { |
| | 246 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No calendar loaded"); |
| | 247 | return false; |
| | 248 | } |
| | 249 | return true; |
| | 250 | } |
| | 251 | |
| | 252 | virtual bool note_access(OSyncContext *ctx, OSyncChange *chg) |
| | 253 | { |
| | 254 | if (mKnotes) |
| | 255 | return mKnotes->access(ctx, chg); |
| | 256 | else { |
| | 257 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No notes loaded"); |
| | 258 | return false; |
| | 259 | } |
| | 260 | return true; |
| | 261 | } |
| | 262 | |
| | 263 | virtual bool note_commit_change(OSyncContext *ctx, OSyncChange *chg) |
| | 264 | { |
| | 265 | if (mKnotes) |
| | 266 | return mKnotes->commit_change(ctx, chg); |
| | 267 | else { |
| | 268 | osync_context_report_error(ctx, OSYNC_ERROR_NOT_SUPPORTED, "No notes loaded"); |
| | 269 | return false; |
| | 270 | } |
| | 271 | return true; |
| | 272 | } |
| | 273 | |
| | 274 | private: |
| | 275 | KCalDataSource *mKcal; |
| | 276 | KNotesDataSource *mKnotes; |
| | 277 | KContactDataSource *mKaddrbook; |
| | 278 | |
| | 279 | OSyncHashTable *mHashtable; |
| | 280 | OSyncMember *mMember; |
| | 281 | |
| | 282 | KApplication *mApplication; |
| | 283 | bool mNewApplication; |