revolution 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/revolution.c +303 -95
  2. metadata +3 -3
data/revolution.c CHANGED
@@ -65,14 +65,14 @@ VALUE cTask;
65
65
  * Creates a new Task object
66
66
  *
67
67
  * Attributes:
68
- * @uid - a unique id for this task
69
- * @summary
70
- * @description
71
- * @start - the start Time
72
- * @due - the due Time
73
- * @status - 'Not started', 'In progress', 'Completed', 'Cancelled'
74
- * @priority - 'Low', 'Medium', 'High', or nil
75
- * @last_modification - Time of last modification
68
+ * @uid [String] a unique id for this task
69
+ * @summary [String]
70
+ * @description [String]
71
+ * @start [Time] the start time
72
+ * @due [Time] the due time
73
+ * @status [String] 'Not started', 'In progress', 'Completed', 'Cancelled'
74
+ * @priority [String] 'Low', 'Medium', 'High', or nil
75
+ * @last_modification [Time]
76
76
  */
77
77
  static VALUE evTask_init(VALUE self) {
78
78
  return Qtrue;
@@ -189,16 +189,16 @@ VALUE cAppointment;
189
189
  * Creates a new Appointment object
190
190
  *
191
191
  * Attributes:
192
- * @uid - a unique id for this task
193
- * @summary
194
- * @location
195
- * @organizer
196
- * @start - start Time
197
- * @end - end Time
198
- * @alarm_set - is an alarm set for this appointment
199
- * @busy_status
200
- * @recurring - is this appointment recurring
201
- * @last_modification
192
+ * @uid [String] a unique id for this task
193
+ * @summary [String]
194
+ * @location [String]
195
+ * @organizer [String]
196
+ * @start [Time] the start time
197
+ * @due [Time] the due time
198
+ * @alarm_set [Boolean] is an alarm set for this appointment
199
+ * @busy_status [Boolean]
200
+ * @recurring [Boolean] is this appointment recurring
201
+ * @last_modification [Time]
202
202
  */
203
203
  static VALUE evAppointment_init(VALUE self) {
204
204
  return Qtrue;
@@ -305,22 +305,22 @@ VALUE cContactIMAddress;
305
305
  * Creates a new Contact object
306
306
  *
307
307
  * Attributes:
308
- * @uid - the unique ID for this contact
309
- * @first_name
310
- * @last_name
311
- * @email_addresses - a Hash of type->addr, i.e. 'HOME'->['tom@home.com', 'tom@bar.com']
312
- * @birthday - a Time
313
- * @home_phone
314
- * @work_phone
315
- * @mobile_phone
316
- * @home_address - an ContactAddress object
317
- * @work_address - an ContactAddress object
318
- * @other_address - an ContactAddress object
319
- * @organization - employee
320
- * @title - job title
321
- * @im_addresses - an Array of ContactIMAddress objects
308
+ * @uid [String] the unique ID for this contact
309
+ * @first_name [String]
310
+ * @last_name [String]
311
+ * @email_addresses [Hash] A Hash of type->Array of addresses, i.e. 'HOME'->['tom@home.com', 'tom@bar.com']
312
+ * @birthday [Time]
313
+ * @home_phone [String]
314
+ * @work_phone [String]
315
+ * @mobile_phone [String]
316
+ * @home_address [ContactAddress]
317
+ * @work_address [ContactAddress]
318
+ * @other_address [ContactAddress]
319
+ * @organization [String]
320
+ * @title [String]
321
+ * @im_addresses [Array] An Array of ContactIMAddress objects
322
322
  */
323
- static VALUE evContact_init(VALUE self) {
323
+ static VALUE contact_init(VALUE self) {
324
324
  return Qtrue;
325
325
  }
326
326
 
@@ -331,11 +331,11 @@ static VALUE evContact_init(VALUE self) {
331
331
  * Creates a new ContactIMAddress object
332
332
  *
333
333
  * Attributes:
334
- * @provider - i.e., AOL, Yahoo
335
- * @address - i.e., tom_copeland
336
- * @type - HOME or WORK
334
+ * @provider [String] i.e., AOL, Yahoo
335
+ * @address [String] i.e., tom_copeland
336
+ * @type [String] HOME or WORK
337
337
  */
338
- static VALUE evContactIMAddress_init(VALUE self) {
338
+ static VALUE contactIMAddress_init(VALUE self) {
339
339
  return Qtrue;
340
340
  }
341
341
  /*
@@ -345,16 +345,16 @@ static VALUE evContactIMAddress_init(VALUE self) {
345
345
  * Creates a new ContactAddress object
346
346
  *
347
347
  * Attributes:
348
- * @address_format
349
- * @po - P.O. Box
350
- * @ext
351
- * @street
352
- * @locality
353
- * @region
354
- * @code
355
- * @country
348
+ * @address_format [String]
349
+ * @po [String] P.O. Box
350
+ * @ext [String]
351
+ * @street [String]
352
+ * @locality [String]
353
+ * @region [String]
354
+ * @code [String]
355
+ * @country [String]
356
356
  */
357
- static VALUE evContactAddress_init(VALUE self) {
357
+ static VALUE contactAddress_init(VALUE self) {
358
358
  return Qtrue;
359
359
  }
360
360
 
@@ -475,7 +475,6 @@ static VALUE revolution_get_all_contacts(VALUE self) {
475
475
  g_clear_error(&error);
476
476
  return result;
477
477
  }
478
-
479
478
  e_book_open(book, TRUE, &error);
480
479
  if (error) {
481
480
  g_warning("Unable to open the Evolution address book: %s", error->message);
@@ -505,6 +504,210 @@ static VALUE revolution_get_all_contacts(VALUE self) {
505
504
  return result;
506
505
  }
507
506
 
507
+ EBook* open_book() {
508
+ GError* error = 0;
509
+ EBook* book = e_book_new_default_addressbook(&error);
510
+ if (error != NULL) {
511
+ g_warning("Unable to locate the default Evolution address book: %s", error->message);
512
+ g_clear_error(&error);
513
+ return NULL;
514
+ }
515
+ e_book_open(book, TRUE, &error);
516
+ if (error) {
517
+ g_warning("Unable to open the Evolution address book: %s", error->message);
518
+ g_clear_error(&error);
519
+ return NULL;
520
+ }
521
+ return book;
522
+ }
523
+
524
+ /*
525
+ * call-seq:
526
+ * get_contacts_with_query(query)
527
+ *
528
+ * Gets contacts with an arbitrary s-expression query, i.e., (contains "full_name" "Smith") would
529
+ * return any contacts whose named contained "Smith" - Joe Smith, Fred Smithson, etc.
530
+ */
531
+ static VALUE revolution_get_contacts_with_query(VALUE self, VALUE rb_query) {
532
+ VALUE result = rb_ary_new();
533
+ EBook* book = open_book();
534
+ if (!book) {
535
+ return Qnil;
536
+ }
537
+
538
+ EBookQuery* query = e_book_query_from_string(RSTRING(StringValue(rb_query))->ptr);
539
+ GError* error = 0;
540
+ GList* results, *l = NULL;
541
+ e_book_get_contacts(book, query, &results, &error);
542
+ if (error) {
543
+ g_warning("Unable to query the Evolution address book: %s", error->message);
544
+ g_clear_error(&error);
545
+ return Qnil;
546
+ }
547
+
548
+ for (l = results; l; l = l->next) {
549
+ EContact* ev_contact = E_CONTACT(l->data);
550
+ VALUE ruby_contact = rb_class_new_instance(0, 0, cContact);
551
+ copy_into_contact(ruby_contact, ev_contact);
552
+ rb_ary_push(result, ruby_contact);
553
+ g_object_unref(ev_contact);
554
+ }
555
+ e_book_query_unref(query);
556
+ g_list_free(results);
557
+
558
+ return result;
559
+ }
560
+
561
+ /*
562
+ * call-seq:
563
+ * get_contacts_by_name(name)
564
+ *
565
+ * Gets contacts by name; returns any name that contains the passed in parameter
566
+ */
567
+ static VALUE revolution_get_contacts_by_name(VALUE self, VALUE rb_name) {
568
+ VALUE result = rb_ary_new();
569
+ GError* error = 0;
570
+ EBook* book = open_book();
571
+ if (!book) {
572
+ return Qnil;
573
+ }
574
+ char* name = RSTRING(StringValue(rb_name))->ptr;
575
+ char* query_str = g_strdup_printf ("(contains \"full_name\" \"%s\")", name);
576
+ EBookQuery* query = e_book_query_from_string(query_str);
577
+ GList* results, *l = NULL;
578
+ e_book_get_contacts(book, query, &results, &error);
579
+ if (error) {
580
+ g_warning("Unable to query the Evolution address book: %s", error->message);
581
+ g_clear_error(&error);
582
+ return Qnil;
583
+ }
584
+
585
+ for (l = results; l; l = l->next) {
586
+ EContact* ev_contact = E_CONTACT(l->data);
587
+ VALUE ruby_contact = rb_class_new_instance(0, 0, cContact);
588
+ copy_into_contact(ruby_contact, ev_contact);
589
+ rb_ary_push(result, ruby_contact);
590
+ g_object_unref(ev_contact);
591
+ }
592
+ e_book_query_unref(query);
593
+ g_list_free(results);
594
+
595
+ return result;
596
+ }
597
+
598
+ /*
599
+ * call-seq:
600
+ * get_contact_by_uid(contact_uid)
601
+ *
602
+ * Gets a single contact by the Evolution unique id
603
+ */
604
+ static VALUE revolution_get_contact_by_uid(VALUE self, VALUE contact_uid) {
605
+ GError* error = 0;
606
+ EBook* book = open_book();
607
+ if (!book) {
608
+ return Qnil;
609
+ }
610
+
611
+ char* uid = RSTRING(StringValue(contact_uid))->ptr;
612
+ char* query_str = g_strdup_printf ("(is \"id\" \"%s\")", uid);
613
+ EBookQuery* query = e_book_query_from_string(query_str);
614
+ GList* results = NULL;
615
+ e_book_get_contacts(book, query, &results, &error);
616
+ if (error) {
617
+ g_warning("Unable to query the Evolution address book: %s", error->message);
618
+ g_clear_error(&error);
619
+ return Qnil;
620
+ }
621
+ if (!results) {
622
+ // A contact for that id wasn't found, so just return nil
623
+ return Qnil;
624
+ }
625
+
626
+ EContact* ev_contact = E_CONTACT(results->data);
627
+ VALUE ruby_contact = rb_class_new_instance(0, 0, cContact);
628
+ copy_into_contact(ruby_contact, ev_contact);
629
+ g_object_unref(ev_contact);
630
+ e_book_query_unref(query);
631
+ g_list_free(results);
632
+
633
+ return ruby_contact;
634
+ }
635
+
636
+ /*
637
+ * call-seq:
638
+ * delete_contact(contact_uid)
639
+ *
640
+ * Deletes a contact
641
+ */
642
+ static VALUE revolution_delete_contact(VALUE self, VALUE contact_uid) {
643
+ GError* error = 0;
644
+ EBook* book = open_book();
645
+ if (!book) {
646
+ return Qnil;
647
+ }
648
+
649
+ char* uid = RSTRING(StringValue(contact_uid))->ptr;
650
+ char* query_str = g_strdup_printf ("(is \"id\" \"%s\")", uid);
651
+ EBookQuery* query = e_book_query_from_string(query_str);
652
+ GList* results = NULL;
653
+ e_book_get_contacts(book, query, &results, &error);
654
+ if (error) {
655
+ g_warning("Unable to query the Evolution address book: %s", error->message);
656
+ g_clear_error(&error);
657
+ return Qnil;
658
+ }
659
+ if (!results) { // A contact for that id wasn't found, so just bail out
660
+ return Qnil;
661
+ }
662
+
663
+ e_book_remove_contact(book, uid, &error);
664
+ if (error) {
665
+ g_warning("Unable to delete contact: %s", error->message);
666
+ g_clear_error(&error);
667
+ }
668
+
669
+ return Qnil;
670
+ }
671
+
672
+ /*
673
+ * call-seq:
674
+ * add_contact(contact) -> [String] the new contact's Evolution unique ID
675
+ *
676
+ * Adds a contact
677
+ */
678
+ static VALUE revolution_add_contact(VALUE self, VALUE rb_contact) {
679
+ GError* error = 0;
680
+ EBook* book = open_book();
681
+ if (!book) {
682
+ return Qnil;
683
+ }
684
+
685
+ EContact* ev_contact = e_contact_new();
686
+
687
+ EContactName* name = e_contact_name_new ();
688
+ VALUE fname = rb_iv_get(rb_contact, "@first_name");
689
+ if (fname) {
690
+ name->given = RSTRING(StringValue(fname))->ptr;
691
+ }
692
+ VALUE lname = rb_iv_get(rb_contact, "@last_name");
693
+ if (lname) {
694
+ name->family = RSTRING(StringValue(lname))->ptr;
695
+ }
696
+
697
+ e_contact_set(ev_contact, E_CONTACT_FULL_NAME, e_contact_name_to_string (name));
698
+ e_book_add_contact(book, ev_contact, &error);
699
+ // Hm, this causes problems... GLib complains about a double free
700
+ // e_contact_name_free (name);
701
+
702
+ if (error) {
703
+ g_warning("Unable to add a contact: %s", error->message);
704
+ g_clear_error(&error);
705
+ return Qnil;
706
+ }
707
+
708
+ return rb_str_new2(e_contact_get(ev_contact, E_CONTACT_UID));
709
+ }
710
+
508
711
  /*
509
712
  * An interface to the Evolution[http://www.gnome.org/projects/evolution/]
510
713
  * calendar, contact, and task information.
@@ -513,66 +716,71 @@ void Init_revolution() {
513
716
  module = rb_define_module("Revolution");
514
717
 
515
718
  cContact = rb_define_class_under(module, "Contact", rb_cObject);
516
- rb_define_attr(cContact, "uid", 1, 0);
517
- rb_define_attr(cContact, "first_name", 1, 0);
518
- rb_define_attr(cContact, "last_name", 1, 0);
519
- rb_define_attr(cContact, "home_email", 1, 0);
520
- rb_define_attr(cContact, "work_email", 1, 0);
521
- rb_define_attr(cContact, "email_addresses", 1, 0);
522
- rb_define_attr(cContact, "birthday", 1, 0);
523
- rb_define_attr(cContact, "home_phone", 1, 0);
524
- rb_define_attr(cContact, "work_phone", 1, 0);
525
- rb_define_attr(cContact, "mobile_phone", 1, 0);
526
- rb_define_attr(cContact, "home_address", 1, 0);
527
- rb_define_attr(cContact, "work_address", 1, 0);
528
- rb_define_attr(cContact, "other_address", 1, 0);
529
- rb_define_attr(cContact, "organization", 1, 0);
530
- rb_define_attr(cContact, "title", 1, 0);
531
- rb_define_attr(cContact, "im_addresses", 1, 0);
532
- rb_define_method(cContact, "initialize", evContact_init, 0);
719
+ rb_define_attr(cContact, "uid", 1, 1);
720
+ rb_define_attr(cContact, "first_name", 1, 1);
721
+ rb_define_attr(cContact, "last_name", 1, 1);
722
+ rb_define_attr(cContact, "home_email", 1, 1);
723
+ rb_define_attr(cContact, "work_email", 1, 1);
724
+ rb_define_attr(cContact, "email_addresses", 1, 1);
725
+ rb_define_attr(cContact, "birthday", 1, 1);
726
+ rb_define_attr(cContact, "home_phone", 1, 1);
727
+ rb_define_attr(cContact, "work_phone", 1, 1);
728
+ rb_define_attr(cContact, "mobile_phone", 1, 1);
729
+ rb_define_attr(cContact, "home_address", 1, 1);
730
+ rb_define_attr(cContact, "work_address", 1, 1);
731
+ rb_define_attr(cContact, "other_address", 1, 1);
732
+ rb_define_attr(cContact, "organization", 1, 1);
733
+ rb_define_attr(cContact, "title", 1, 1);
734
+ rb_define_attr(cContact, "im_addresses", 1, 1);
735
+ rb_define_method(cContact, "initialize", contact_init, 0);
533
736
  cContactAddress = rb_define_class_under(module, "ContactAddress", rb_cObject);
534
- rb_define_attr(cContactAddress, "address_format", 1, 0);
535
- rb_define_attr(cContactAddress, "po", 1, 0);
536
- rb_define_attr(cContactAddress, "ext", 1, 0);
537
- rb_define_attr(cContactAddress, "street", 1, 0);
538
- rb_define_attr(cContactAddress, "locality", 1, 0);
539
- rb_define_attr(cContactAddress, "region", 1, 0);
540
- rb_define_attr(cContactAddress, "code", 1, 0);
541
- rb_define_attr(cContactAddress, "country", 1, 0);
542
- rb_define_method(cContactAddress, "initialize", evContactAddress_init, 0);
737
+ rb_define_attr(cContactAddress, "address_format", 1, 1);
738
+ rb_define_attr(cContactAddress, "po", 1, 1);
739
+ rb_define_attr(cContactAddress, "ext", 1, 1);
740
+ rb_define_attr(cContactAddress, "street", 1, 1);
741
+ rb_define_attr(cContactAddress, "locality", 1, 1);
742
+ rb_define_attr(cContactAddress, "region", 1, 1);
743
+ rb_define_attr(cContactAddress, "code", 1, 1);
744
+ rb_define_attr(cContactAddress, "country", 1, 1);
745
+ rb_define_method(cContactAddress, "initialize", contactAddress_init, 0);
543
746
  cContactIMAddress = rb_define_class_under(module, "ContactIMAddress", rb_cObject);
544
- rb_define_attr(cContactIMAddress, "provider", 1, 0);
545
- rb_define_attr(cContactIMAddress, "location", 1, 0);
546
- rb_define_attr(cContactIMAddress, "address", 1, 0);
547
- rb_define_method(cContactIMAddress, "initialize", evContactIMAddress_init, 0);
747
+ rb_define_attr(cContactIMAddress, "provider", 1, 1);
748
+ rb_define_attr(cContactIMAddress, "location", 1, 1);
749
+ rb_define_attr(cContactIMAddress, "address", 1, 1);
750
+ rb_define_method(cContactIMAddress, "initialize", contactIMAddress_init, 0);
548
751
 
549
752
  cAppointment = rb_define_class_under(module, "Appointment", rb_cObject);
550
- rb_define_attr(cAppointment, "uid", 1, 0);
551
- rb_define_attr(cAppointment, "summary", 1, 0);
552
- rb_define_attr(cAppointment, "location", 1, 0);
553
- rb_define_attr(cAppointment, "organizer", 1, 0);
554
- rb_define_attr(cAppointment, "start", 1, 0);
555
- rb_define_attr(cAppointment, "end", 1, 0);
556
- rb_define_attr(cAppointment, "last_modification", 1, 0);
557
- rb_define_attr(cAppointment, "alarm_set", 1, 0);
558
- rb_define_attr(cAppointment, "busy_status", 1, 0);
559
- rb_define_attr(cAppointment, "recurring", 1, 0);
753
+ rb_define_attr(cAppointment, "uid", 1, 1);
754
+ rb_define_attr(cAppointment, "summary", 1, 1);
755
+ rb_define_attr(cAppointment, "location", 1, 1);
756
+ rb_define_attr(cAppointment, "organizer", 1, 1);
757
+ rb_define_attr(cAppointment, "start", 1, 1);
758
+ rb_define_attr(cAppointment, "end", 1, 1);
759
+ rb_define_attr(cAppointment, "last_modification", 1, 1);
760
+ rb_define_attr(cAppointment, "alarm_set", 1, 1);
761
+ rb_define_attr(cAppointment, "busy_status", 1, 1);
762
+ rb_define_attr(cAppointment, "recurring", 1, 1);
560
763
  rb_define_method(cAppointment, "initialize", evAppointment_init, 0);
561
764
  // INLINE RUBY CODE define an "all_day" method
562
765
 
563
766
  cTask = rb_define_class_under(module, "Task", rb_cObject);
564
- rb_define_attr(cTask, "uid", 1, 0);
565
- rb_define_attr(cTask, "summary", 1, 0);
566
- rb_define_attr(cTask, "description", 1, 0);
567
- rb_define_attr(cTask, "start", 1, 0);
568
- rb_define_attr(cTask, "due", 1, 0);
569
- rb_define_attr(cTask, "status", 1, 0);
570
- rb_define_attr(cTask, "priority", 1, 0);
571
- rb_define_attr(cTask, "last_modification", 1, 0);
767
+ rb_define_attr(cTask, "uid", 1, 1);
768
+ rb_define_attr(cTask, "summary", 1, 1);
769
+ rb_define_attr(cTask, "description", 1, 1);
770
+ rb_define_attr(cTask, "start", 1, 1);
771
+ rb_define_attr(cTask, "due", 1, 1);
772
+ rb_define_attr(cTask, "status", 1, 1);
773
+ rb_define_attr(cTask, "priority", 1, 1);
774
+ rb_define_attr(cTask, "last_modification", 1, 1);
572
775
  rb_define_method(cTask, "initialize", evTask_init, 0);
573
776
 
574
777
  cRevolution = rb_define_class_under(module, "Revolution", rb_cObject);
575
778
  rb_define_method(cRevolution, "initialize", revolution_init, 0);
779
+ rb_define_method(cRevolution, "add_contact", revolution_add_contact, 1);
780
+ rb_define_method(cRevolution, "delete_contact", revolution_delete_contact, 1);
781
+ rb_define_method(cRevolution, "get_contact_by_uid", revolution_get_contact_by_uid, 1);
782
+ rb_define_method(cRevolution, "get_contacts_by_name", revolution_get_contacts_by_name, 1);
783
+ rb_define_method(cRevolution, "get_contacts_with_query", revolution_get_contacts_with_query, 1);
576
784
  rb_define_method(cRevolution, "get_all_contacts", revolution_get_all_contacts, 0);
577
785
  rb_define_method(cRevolution, "get_all_appointments", revolution_get_all_appointments, 2);
578
786
  rb_define_method(cRevolution, "get_all_tasks", revolution_get_all_tasks, 0);
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.4
2
+ rubygems_version: 0.8.8
3
3
  specification_version: 1
4
4
  name: revolution
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.3"
7
- date: 2005-03-25
6
+ version: "0.4"
7
+ date: 2005-03-30
8
8
  summary: Revolution is a binding for the Evolution email client
9
9
  require_paths:
10
10
  - ''