mobile/xul/modules/linuxTypes.jsm
author Ehsan Akhgari <ehsan@mozilla.com>
Tue, 29 Jan 2013 13:13:58 -0500
changeset 120251 3a8a7a8502be210bd3748421c540512c6cb72765
parent 111947 5ce71981e005a52d4cb0b831ad3db9284f2fb356
permissions -rw-r--r--
Merge the removal of global private browsing support

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

this.EXPORTED_SYMBOLS = ["GLib", "EBook"];

const Cu = Components.utils;

Cu.import("resource://gre/modules/ctypes.jsm");

this.GLib = {
  lib: null,

  init: function glib_init() {
    if (this.lib)
      return;

    this.lib = true; // TODO hook up the real glib
    
    this.GError = new ctypes.StructType("GError", [
      {"domain": ctypes.int32_t},
      {"code": ctypes.int32_t},
      {"message": ctypes.char.ptr}
    ]);

    this.GList = new ctypes.StructType("GList", [
      {"data": ctypes.voidptr_t},
      {"next": ctypes.voidptr_t},
      {"prev": ctypes.voidptr_t}
    ]);
  }
};

this.EBook = {
  lib: null,
  
  E_CONTACT_FULL_NAME: 4,
  E_CONTACT_EMAIL_1: 8,
  E_CONTACT_EMAIL_2: 9,
  E_CONTACT_EMAIL_3: 10,
  E_CONTACT_EMAIL_4: 11,
  E_CONTACT_PHONE_BUSINESS: 17,
  E_CONTACT_PHONE_BUSINESS_2: 18,
  E_CONTACT_PHONE_HOME: 23,
  E_CONTACT_PHONE_HOME_2: 24,
  E_CONTACT_PHONE_MOBILE: 27,

  E_CONTACT_EMAIL_FIRST: 8,
  E_CONTACT_EMAIL_LAST: 11,
  E_CONTACT_PHONE_FIRST: 16,
  E_CONTACT_PHONE_LAST: 34,

  init: function ebook_init() {
    if (this.lib)
      return;

    GLib.init();

    try {
      // Shipping on N900
      this.lib = ctypes.open("libebook-1.2.so.5");
    } catch (e) {
      try {
        // Shipping on Ubuntu
        this.lib = ctypes.open("libebook-1.2.so.9");
      } catch (e) {
        Cu.reportError("EBook: couldn't load libebook:\n" + e)
        this.lib = null;
        return;
      }
    }

    this.EBook = new ctypes.StructType("EBook");
    this.EQuery = new ctypes.StructType("EQuery");

    this.openSystem = this.lib.declare("e_book_new_system_addressbook", ctypes.default_abi, EBook.EBook.ptr, GLib.GError.ptr.ptr);
    this.openBook = this.lib.declare("e_book_open", ctypes.default_abi, ctypes.bool, EBook.EBook.ptr, ctypes.bool, GLib.GError.ptr.ptr);

    this.queryAnyFieldContains = this.lib.declare("e_book_query_any_field_contains", ctypes.default_abi, EBook.EQuery.ptr, ctypes.char.ptr);

    this.getContacts = this.lib.declare("e_book_get_contacts", ctypes.default_abi, ctypes.bool, EBook.EBook.ptr, EBook.EQuery.ptr, GLib.GList.ptr.ptr, GLib.GError.ptr.ptr);
    this.getContactField = this.lib.declare("e_contact_get_const", ctypes.default_abi, ctypes.char.ptr, ctypes.voidptr_t, ctypes.uint32_t);
  }
};