#! /usr/bin/python
# -*- coding: utf-8 -*-

#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
from gi.repository import EDataServer

def _registerAndroidSource():
    sourceList = EDataServer.SourceList.new_for_gconf_default("/apps/evolution/addressbook/sources")
    if sourceList:
        EDataServer.SourceList.ensure_group(sourceList, "Ubuntu Android", "android://", False)
        sourceGroup = EDataServer.SourceList.peek_group_by_base_uri(sourceList, "android://")
        sources = EDataServer.SourceGroup.peek_sources(sourceGroup)
        if (not sources) or (len(sources) == 0):
            source = EDataServer.Source.new("Android", "//")
            EDataServer.Source.set_property(source, "completion", "true")
            EDataServer.Source.set_property(source, "default", "true")
            EDataServer.SourceGroup.add_source(sourceGroup, source, -1)

if __name__ == "__main__":
    if len(sys.argv) == 2:
        if sys.argv[1] == "--contacts":
            _registerAndroidSource()
