revolution 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/extconf.rb +6 -2
  2. data/revolution.c +172 -37
  3. metadata +3 -3
data/extconf.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  require 'mkmf'
2
2
 
3
- $CPPFLAGS += " -Wall " + `pkg-config --cflags libebook-1.0 libecal-1.0 glib-2.0 evolution-data-server-1.0`
4
- $LOCAL_LIBS += `pkg-config --libs libebook-1.0 libecal-1.0`
3
+ pkg_config('libebook-1.2') || pkg_config('libebook-1.0')
4
+ pkg_config('libecal-1.2') || pkg_config('libecal-1.0')
5
+ pkg_config('evolution-data-server-1.2') || pkg_config('evolution-data-server-1.0')
6
+ pkg_config('glib-2.0')
7
+
8
+ $CPPFLAGS += " -Wall "
5
9
 
6
10
  create_makefile("revolution")
7
11
 
@@ -8,15 +8,6 @@
8
8
  #include <libebook/e-book.h>
9
9
  #include <libecal/e-cal.h>
10
10
 
11
- #include <libical/pvl.h>
12
- #include <libical/ical.h>
13
-
14
- #include <libical/icalcomponent.h>
15
- #include <libical/icalproperty.h>
16
- #include <libical/icalvalue.h>
17
- #include <libical/icaltime.h>
18
- #include <libical/icalenums.h>
19
-
20
11
  VALUE crRevolution;
21
12
  VALUE module;
22
13
 
@@ -84,6 +75,8 @@ static VALUE evTask_init(VALUE self) {
84
75
  rb_define_attr(crEvTask, "description", 1, 0);
85
76
  rb_define_attr(crEvTask, "start", 1, 0);
86
77
  rb_define_attr(crEvTask, "due", 1, 0);
78
+ rb_define_attr(crEvTask, "status", 1, 0);
79
+ rb_define_attr(crEvTask, "priority", 1, 0);
87
80
  rb_define_attr(crEvTask, "last_modification", 1, 0);
88
81
  return Qtrue;
89
82
  }
@@ -111,6 +104,34 @@ void copy_into_task(const VALUE ruby_task, ECalComponent* ev_task) {
111
104
  rb_iv_set(ruby_task, "@due", rb_funcall( rb_cTime, rb_intern( "at" ), 1, INT2NUM(icaltime_as_timet(*due_date.value))));
112
105
  e_cal_component_free_datetime(&due_date);
113
106
  }
107
+
108
+ // Does this need to be freed? There's no API call to free it...
109
+ icalproperty_status status;
110
+ e_cal_component_get_status(ev_task, &status);
111
+ if (status == ICAL_STATUS_NONE) {
112
+ rb_iv_set(ruby_task, "@status", rb_str_new2("Not started"));
113
+ } else if (status == ICAL_STATUS_INPROCESS) {
114
+ rb_iv_set(ruby_task, "@status", rb_str_new2("In progress"));
115
+ } else if (status == ICAL_STATUS_COMPLETED) {
116
+ rb_iv_set(ruby_task, "@status", rb_str_new2("Completed"));
117
+ } else if (status == ICAL_STATUS_CANCELLED) {
118
+ rb_iv_set(ruby_task, "@status", rb_str_new2("Cancelled"));
119
+ }
120
+
121
+ int* priority;
122
+ e_cal_component_get_priority(ev_task, &priority);
123
+ if (priority) {
124
+ if (*priority == 7) {
125
+ rb_iv_set(ruby_task, "@priority", rb_str_new2("Low"));
126
+ } else if (*priority == 5) {
127
+ rb_iv_set(ruby_task, "@priority", rb_str_new2("Normal"));
128
+ } else if (*priority == 3) {
129
+ rb_iv_set(ruby_task, "@priority", rb_str_new2("High"));
130
+ } /* seems like nil is as good as undefined - else {
131
+ rb_iv_set(ruby_task, "@priority", rb_str_new2("Undefined"));
132
+ }*/
133
+ e_cal_component_free_priority(priority);
134
+ }
114
135
  }
115
136
 
116
137
  /*
@@ -276,6 +297,8 @@ static VALUE revolution_get_all_appointments(VALUE self, VALUE start, VALUE end)
276
297
  ///////////////////////////////////////////////////////
277
298
  // Address Book
278
299
  VALUE crEvContact;
300
+ VALUE crEvContactAddress;
301
+ VALUE crEvContactIMAddress;
279
302
 
280
303
  /*
281
304
  * call-seq:
@@ -289,42 +312,150 @@ static VALUE evContact_init(VALUE self) {
289
312
  rb_define_attr(crEvContact, "last_name", 1, 0);
290
313
  rb_define_attr(crEvContact, "home_email", 1, 0);
291
314
  rb_define_attr(crEvContact, "work_email", 1, 0);
315
+ rb_define_attr(crEvContact, "email_addresses", 1, 0);
316
+ rb_define_attr(crEvContact, "birthday", 1, 0);
317
+ rb_define_attr(crEvContact, "home_phone", 1, 0);
318
+ rb_define_attr(crEvContact, "work_phone", 1, 0);
319
+ rb_define_attr(crEvContact, "mobile_phone", 1, 0);
320
+ rb_define_attr(crEvContact, "home_address", 1, 0);
321
+ rb_define_attr(crEvContact, "work_address", 1, 0);
322
+ rb_define_attr(crEvContact, "other_address", 1, 0);
323
+ rb_define_attr(crEvContact, "organization", 1, 0);
324
+ rb_define_attr(crEvContact, "title", 1, 0);
325
+ rb_define_attr(crEvContact, "im_addresses", 1, 0);
326
+ return Qtrue;
327
+ }
328
+
329
+ /*
330
+ * call-seq:
331
+ * new() -> EvContactIMAddress
332
+ *
333
+ * Creates a new EvContactIMAddress object
334
+ */
335
+ static VALUE evContactIMAddress_init(VALUE self) {
336
+ rb_define_attr(crEvContactIMAddress, "provider", 1, 0);
337
+ rb_define_attr(crEvContactIMAddress, "location", 1, 0);
338
+ rb_define_attr(crEvContactIMAddress, "address", 1, 0);
339
+ return Qtrue;
340
+ }
341
+ /*
342
+ * call-seq:
343
+ * new() -> EvContactAddress
344
+ *
345
+ * Creates a new EvContactAddress object
346
+ */
347
+ static VALUE evContactAddress_init(VALUE self) {
348
+ rb_define_attr(crEvContactAddress, "address_format", 1, 0);
349
+ rb_define_attr(crEvContactAddress, "po", 1, 0);
350
+ rb_define_attr(crEvContactAddress, "ext", 1, 0);
351
+ rb_define_attr(crEvContactAddress, "street", 1, 0);
352
+ rb_define_attr(crEvContactAddress, "locality", 1, 0);
353
+ rb_define_attr(crEvContactAddress, "region", 1, 0);
354
+ rb_define_attr(crEvContactAddress, "code", 1, 0);
355
+ rb_define_attr(crEvContactAddress, "country", 1, 0);
292
356
  return Qtrue;
293
357
  }
294
358
 
295
- char* fetch_field_or_empty_str(EContact* ev_contact, const EContactField field) {
296
- char* value = e_contact_get(ev_contact, field);
297
- return (value) ? value : "";
359
+ void copy_in_address(EContactAddress* address, VALUE ruby_contact, char* field) {
360
+ if (address) {
361
+ VALUE rb_addr = rb_class_new_instance(0, 0, crEvContactAddress);
362
+ rb_iv_set(rb_addr, "@address_format", address->address_format ? rb_str_new2(address->address_format) : Qnil);
363
+ rb_iv_set(rb_addr, "@po", address->po ? rb_str_new2(address->po) : Qnil);
364
+ rb_iv_set(rb_addr, "@ext", address->ext ? rb_str_new2(address->ext) : Qnil);
365
+ rb_iv_set(rb_addr, "@street", address->street ? rb_str_new2(address->street) : Qnil);
366
+ rb_iv_set(rb_addr, "@locality", address->locality ? rb_str_new2(address->locality) : Qnil);
367
+ rb_iv_set(rb_addr, "@region", address->region ? rb_str_new2(address->region) : Qnil);
368
+ rb_iv_set(rb_addr, "@code", address->code ? rb_str_new2(address->code) : Qnil);
369
+ rb_iv_set(rb_addr, "@country", address->country ? rb_str_new2(address->country) : Qnil);
370
+
371
+ rb_iv_set(ruby_contact, field, rb_addr);
372
+ e_contact_address_free(address);
373
+ }
374
+ }
375
+
376
+ void copy_in_im_address(VALUE im_addresses, char* address, char* provider, char* location) {
377
+ if (!address) {
378
+ return;
379
+ }
380
+ VALUE rb_addr = rb_class_new_instance(0, 0, crEvContactIMAddress);
381
+ rb_iv_set(rb_addr, "@provider", rb_str_new2(provider));
382
+ rb_iv_set(rb_addr, "@location", rb_str_new2(location));
383
+ rb_iv_set(rb_addr, "@address", rb_str_new2(address));
384
+ rb_ary_push(im_addresses, rb_addr);
298
385
  }
299
386
 
300
387
  void copy_into_contact(const VALUE ruby_contact, EContact* ev_contact) {
301
- // last mod time will work in v2.16+ : e_contact_get (ev_contact, E_CONTACT_REV));
302
- rb_iv_set(ruby_contact, "@uid", rb_str_new2(fetch_field_or_empty_str(ev_contact, E_CONTACT_UID)));
303
- rb_iv_set(ruby_contact, "@first_name", rb_str_new2(fetch_field_or_empty_str(ev_contact, E_CONTACT_GIVEN_NAME)));
304
- rb_iv_set(ruby_contact, "@last_name", rb_str_new2(fetch_field_or_empty_str(ev_contact, E_CONTACT_FAMILY_NAME)));
305
-
306
- gpointer email1 = e_contact_get(ev_contact, E_CONTACT_EMAIL);
307
- if (email1) {
308
- GList* attrs, *attr;
309
- attrs = e_contact_get_attributes(ev_contact, E_CONTACT_EMAIL);
310
- for (attr = attrs; attr ; attr = attr->next) {
311
- EVCardAttribute* a = attr->data; // g_message("attr name = %s\n", e_vcard_attribute_get_name(a));
312
- char* value = e_vcard_attribute_get_value(a);
313
- GList* params, *l;
314
- params = e_vcard_attribute_get_params(a);
315
- for (l = params; l; l = l->next) {
316
- EVCardAttributeParam* p = l->data;
317
- if (!g_ascii_strcasecmp((char*)e_vcard_attribute_param_get_name(p), "TYPE")) {
318
- char* type = e_vcard_attribute_param_get_values(p)->data;
319
- if (!g_ascii_strcasecmp(type, "WORK")) {
320
- rb_iv_set(ruby_contact, "@work_email", rb_str_new2(value));
321
- } else if (!g_ascii_strcasecmp(type, "HOME")) {
322
- rb_iv_set(ruby_contact, "@home_email", rb_str_new2(value));
323
- }
388
+ // last mod time will work in v2.16+ : e_contact_get (ev_contact, E_CONTACT_REV));
389
+ // what's the best way to handle version differences? #ifdef them in?
390
+
391
+ rb_iv_set(ruby_contact, "@uid", rb_str_new2(e_contact_get(ev_contact, E_CONTACT_UID)));
392
+
393
+ char* value = e_contact_get(ev_contact, E_CONTACT_GIVEN_NAME);
394
+ rb_iv_set(ruby_contact, "@first_name", value ? rb_str_new2(value) : Qnil);
395
+
396
+ value = e_contact_get(ev_contact, E_CONTACT_FAMILY_NAME);
397
+ rb_iv_set(ruby_contact, "@last_name", value ? rb_str_new2(value) : Qnil);
398
+
399
+ value = e_contact_get(ev_contact, E_CONTACT_PHONE_HOME);
400
+ rb_iv_set(ruby_contact, "@home_phone", value ? rb_str_new2(value) : Qnil);
401
+
402
+ value = e_contact_get(ev_contact, E_CONTACT_PHONE_BUSINESS);
403
+ rb_iv_set(ruby_contact, "@work_phone", value ? rb_str_new2(value) : Qnil);
404
+
405
+ value = e_contact_get(ev_contact, E_CONTACT_PHONE_MOBILE);
406
+ rb_iv_set(ruby_contact, "@mobile_phone", value ? rb_str_new2(value) : Qnil);
407
+
408
+ value = e_contact_get(ev_contact, E_CONTACT_ORG);
409
+ rb_iv_set(ruby_contact, "@organization", value ? rb_str_new2(value) : Qnil);
410
+
411
+ value = e_contact_get(ev_contact, E_CONTACT_TITLE);
412
+ rb_iv_set(ruby_contact, "@title", value ? rb_str_new2(value) : Qnil);
413
+
414
+ EContactDate *birth_date = e_contact_get(ev_contact, E_CONTACT_BIRTH_DATE);
415
+ if (birth_date) {
416
+ rb_iv_set(ruby_contact, "@birthday", rb_funcall(rb_cTime, rb_intern("gm"), 6, INT2NUM(birth_date->year), INT2NUM(birth_date->month), INT2NUM(birth_date->day), INT2NUM(0), INT2NUM(0), INT2NUM(0)));
417
+ e_contact_date_free(birth_date);
418
+ }
419
+
420
+ rb_iv_set(ruby_contact, "@email_addresses", rb_hash_new());
421
+ if (e_contact_get(ev_contact, E_CONTACT_EMAIL)) {
422
+ GList* attrs, *attr;
423
+ attrs = e_contact_get_attributes(ev_contact, E_CONTACT_EMAIL);
424
+ for (attr = attrs; attr; attr = attr->next) {
425
+ EVCardAttribute* a = attr->data;
426
+ GList* l;
427
+ for (l = e_vcard_attribute_get_params(a); l; l = l->next) {
428
+ EVCardAttributeParam* p = l->data;
429
+ if (!g_ascii_strcasecmp((char*)e_vcard_attribute_param_get_name(p), "TYPE")) {
430
+ VALUE email_addresses = rb_iv_get(ruby_contact, "@email_addresses");
431
+ VALUE rb_type = rb_str_new2(e_vcard_attribute_param_get_values(p)->data);
432
+ if (rb_hash_aref(email_addresses, rb_type) == Qnil) {
433
+ rb_hash_aset(email_addresses, rb_type, rb_ary_new());
324
434
  }
435
+ rb_ary_push(rb_hash_aref(email_addresses, rb_type), rb_str_new2(e_vcard_attribute_get_value(a)));
325
436
  }
326
- }
327
- }
437
+ }
438
+ }
439
+ }
440
+
441
+ copy_in_address(e_contact_get(ev_contact, E_CONTACT_ADDRESS_HOME), ruby_contact, "@home_address");
442
+ copy_in_address(e_contact_get(ev_contact, E_CONTACT_ADDRESS_WORK), ruby_contact, "@work_address");
443
+ copy_in_address(e_contact_get(ev_contact, E_CONTACT_ADDRESS_OTHER), ruby_contact, "@other_address");
444
+
445
+ VALUE im_addresses = rb_ary_new();
446
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_AIM_HOME_1), "AIM", "HOME");
447
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_AIM_WORK_1), "AIM", "WORK");
448
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_YAHOO_HOME_1), "Yahoo", "HOME");
449
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_YAHOO_WORK_1), "Yahoo", "WORK");
450
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_GROUPWISE_HOME_1), "Groupwise", "HOME");
451
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_GROUPWISE_WORK_1), "Groupwise", "WORK");
452
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_JABBER_HOME_1), "Jabber", "HOME");
453
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_JABBER_WORK_1), "Jabber", "WORK");
454
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_MSN_HOME_1), "MSN", "HOME");
455
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_MSN_WORK_1), "MSN", "WORK");
456
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_ICQ_HOME_1), "ICQ", "HOME");
457
+ copy_in_im_address(im_addresses, e_contact_get(ev_contact, E_CONTACT_IM_ICQ_WORK_1), "ICQ", "WORK");
458
+ rb_iv_set(ruby_contact, "@im_addresses", im_addresses);
328
459
  }
329
460
 
330
461
  /*
@@ -381,6 +512,10 @@ void Init_revolution() {
381
512
 
382
513
  crEvContact = rb_define_class_under(module, "EvContact", rb_cObject);
383
514
  rb_define_method(crEvContact, "initialize", evContact_init, 0);
515
+ crEvContactAddress = rb_define_class_under(module, "EvContactAddress", rb_cObject);
516
+ rb_define_method(crEvContactAddress, "initialize", evContactAddress_init, 0);
517
+ crEvContactIMAddress = rb_define_class_under(module, "EvContactIMAddress", rb_cObject);
518
+ rb_define_method(crEvContactIMAddress, "initialize", evContactIMAddress_init, 0);
384
519
 
385
520
  crEvAppointment = rb_define_class_under(module, "EvAppointment", rb_cObject);
386
521
  rb_define_method(crEvAppointment, "initialize", evAppointment_init, 0);
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.8
2
+ rubygems_version: 0.8.4
3
3
  specification_version: 1
4
4
  name: revolution
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2005-03-21
6
+ version: "0.2"
7
+ date: 2005-03-25
8
8
  summary: Revolution is a binding for the Evolution email client
9
9
  require_paths:
10
10
  - ''