Geoclue.geoclue

Package Geoclue :: Module geoclue |
[hide private]
[frames] | no frames]

# Source Code for Module Geoclue.geoclue

      1  # -*- coding: utf-8 -*-
      2  # This file is based on the original geoclue.py by Pierre-Luc Beaudoin
      3  #
      4  # Copyright (c) 2009 - Paulo Cabido <paulo.cabido@gmail.com>
      5  #
      6  # This program is free software: you can redistribute it and/or modify it under
      7  # the terms of the GNU General Public License as published by the Free Software
      8  # Foundation, either version 3 of the License, or (at your option) any later
      9  # version.
     10  #
     11  # This program is distributed in the hope that it will be useful, but WITHOUT
     12  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     13  # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
     14  # details.
     15  #
     16  # You should have received a copy of the GNU General Public License along with
     17  # this program.  If not, see <http://www.gnu.org/licenses/>.
     18
     19  import ConfigParser
     20  import dbus
     21
     22  POSITION_FIELDS_NONE = 0
     23  POSITION_FIELDS_LATITUDE = 1 << 0
     24  POSITION_FIELDS_LONGITUDE = 1 << 1
     25  POSITION_FIELDS_ALTITUDE = 1 << 2
     26
     27  ADDRESS_FIELD_STREET = "street"
     28  ADDRESS_FIELD_AREA = "area"
     29  ADDRESS_FIELD_LOCALITY = "locality"
     30  ADDRESS_FIELD_REGION = "region"
     31  ADDRESS_FIELD_COUNTRY = "country"
     32
     33  RESOURCE_NONE = 0
     34  RESOURCE_NETWORK = 1 << 0
     35  RESOURCE_CELL = 1 << 1
     36  RESOURCE_GPS = 1 << 2
     37  RESOURCE_ALL = (1 << 10) - 1
     38
     39  ACCURACY_LEVEL_NONE = 0
     40  ACCURACY_LEVEL_COUNTRY = 1
     41  ACCURACY_LEVEL_REGION = 2
     42  ACCURACY_LEVEL_LOCALITY = 3
     43  ACCURACY_LEVEL_POSTALCODE = 4
     44  ACCURACY_LEVEL_STREET = 5
     45  ACCURACY_LEVEL_DETAILED = 6
     46
     47  INTERFACE_NONE = 0
     48  INTERFACE_ADDRESS = 1 << 0
     49  INTERFACE_POSITION = 1 << 1
     50  INTERFACE_GEOCODE = 1 << 2
     51  INTERFACE_REVERSE_GEOCODE = 1 << 3
     52
     53  STATUS_ERROR = 0
     54  STATUS_UNAVAILABLE = 1
     55  STATUS_ACQUIRING = 2
     56  STATUS_AVAILABLE = 3
     57
     58  ### PROVIDERS - Added, pcabido
     59  MASTER_IFACE = "org.freedesktop.Geoclue.Master"
     60  MASTER_PATH = "/org/freedesktop/Geoclue/Master"
     61
     62  ADDRESS_IFACE = "org.freedesktop.Geoclue.Address"
     63  ADDRESS_PATH = "/org/freedesktop/Geoclue/Address"
     64
     65  POSITION_IFACE = "org.freedesktop.Geoclue.Position"
     66  POSITION_PATH = "/org/freedesktop/Geoclue/Position"
     67
     68  GEOCLUE_IFACE = "org.freedesktop.Geoclue"
     69  GEOCLUE_PATH = "/org/freedesktop/Geoclue"
     70
     71  GEONAMES_IFACE = "org.freedesktop.Geoclue.Providers.Geonames"
     72  GEONAMES_PATH = "/org/freedesktop/Geoclue/Providers/Geonames"
     73
     74  REVERSE_IFACE = "org.freedesktop.Geoclue.ReverseGeocode"
     75  REVERSE_PATH = "/org/freedesktop/Geoclue/ReverseGeocode"
     76  ###
     77
     78 -class GeoclueProvider():
     79      pass
     80
     81 -    def __init__ (self, filename):
     82          '''
     83          Takes the path to a .provider file
     84          '''
     85
     86          file = ConfigParser.RawConfigParser()
     87          file.read(filename)
     88
     89          self.name = file.get('Geoclue Provider', 'Name')
     90          self.path = file.get('Geoclue Provider', 'Path')
     91          self.service = file.get('Geoclue Provider', 'Service')
     92          interfaces = file.get('Geoclue Provider', 'Interfaces').split(";")
     93          self.interfaces = INTERFACE_NONE
     94
     95          for interface in interfaces:
     96              if interface == "org.freedesktop.Geoclue.Address":
     97                 self.interfaces += INTERFACE_ADDRESS
     98              elif interface == "org.freedesktop.Geoclue.Position":
     99                 self.interfaces += INTERFACE_POSITION
    100              elif interface == "org.freedesktop.Geoclue.Geocode":
    101                 self.interfaces += INTERFACE_GEOCODE
    102              elif interface == "org.freedesktop.Geoclue.ReverseGeocode":
    103                 self.interfaces += INTERFACE_REVERSE_GEOCODE
    104
    105 -    def get_proxy (self):
    106          self.bus = dbus.SessionBus()
    107          return self.bus.get_object(self.service, self.path)
    108