Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ver0.7.*.3

  • Loading branch information...
commit 807953f92a06a91059b96013f1c9d41b5586118d 1 parent 6083976
lanstat authored
46 src/core/DeviceSerial.py
View
@@ -1,46 +0,0 @@
-import gobject
-from mobile import *
-
-class PhoneData(gobject.GObject):
-
- __gsignals__ = {'new_sms' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
- 'signal_update' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,))}
-
- def __init__(self, port="ttyUSB1"):
- gobject.GObject.__init__(self)
- dev = ATTerminalConnection("/dev/"+port)
- self.__phone = None
- self.__device = None
- if(dev != None):
- self.__phone = MobilePhone(dev)
- self.__device = MobileDevice(dev)
- gobject.timeout_add_seconds(20,self.__check_device)
-
- def get_signal(self):
- return self.__device.get_signal_strenght()
-
- def __check_device(self):
- signal = self.__device.get_signal_strenght()
- self.emit('signal_update',signal)
- sms = self.__device.list_new_sms()
- if(len(sms)>0):
- self.emit('new_sms')
-
- return True
-
- def get_addressbook(self):
- address_book = self.__phone.get_phonebook()
- return address_book
-
- def get_old_sms(self):
- return self.__device.list_old_sms()
-
- def get_new_sms(self):
- return self.__device.list_new_sms()
-
- def is_active(self):
- return (self.__phone != None)
-
- def send_sms(self, message, phone):
- sms = self.__device.create_sms(message,phone)
- sms.send()
50 src/core/Devices.py
View
@@ -1,50 +0,0 @@
-from xml.dom.minidom import parse
-from const import CONF_DIR
-
-class Device:
- def __init__(self):
- self.name = None
- self.vendor = None
- self.product = None
- self.dev_props = None
- self.port = {}
-
- def get_port(self,str):
- return self.port[str]
-
- def __str__(self):
- return '\nName: '+self.name+'\nVendor: '+self.vendor+'\nProduct: '+self.product+'\nPort: '+self.port['data']+' '+self.port['conf']
-
-class DevicesAvalaible:
- def __init__(self):
- midom=parse(CONF_DIR + 'modems.xml')
- self.vendors = midom.childNodes[1].childNodes
- self.__nProduct = None
- self.__nVendor = None
-
- def is_device_supported(self,idVendor,idProduct):
- for vendor in self.vendors:
- if(vendor.nodeType==1):
- if(vendor.attributes.get("id").value==idVendor):
- products = vendor.childNodes
- for product in products:
- if(product.nodeType==1):
- if(product.attributes.get("id").value==idProduct):
- self.__nProduct = product
- self.__nVendor = vendor
- return True
- break
- return False
-
- def get_Device(self):
- if(self.__nProduct != None):
- d = Device()
- d.name = self.__nVendor.attributes.get("name").value
- d.vendor = self.__nVendor.attributes.get("id").value
- d.product = self.__nProduct.attributes.get("id").value
- attribs = self.__nProduct.childNodes
- for attrib in attribs:
- if(attrib.nodeType == 1 and attrib.nodeName != "capabilities"):
- d.port[attrib.nodeName] = attrib.childNodes[0].data
- return d
- return None
113 src/core/DevicesController.py
View
@@ -1,113 +0,0 @@
-import dbus
-import os
-import gobject
-from Devices import *
-if getattr(dbus, "version", (0,0,0)) >= (0,41,0):
- import dbus.glib
-
-class DeviceController(gobject.GObject):
-
- __gsignals__ = {'added_device' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,)),
- 'removed_device' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
- 'support_device_detected' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,())}
-
- def __init__(self):
- gobject.GObject.__init__(self)
- self.dbus = dbus.SystemBus()
- self.hal_manager_obj = self.dbus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager")
- self.hal_manager = dbus.Interface(self.hal_manager_obj, "org.freedesktop.Hal.Manager")
-
-
- #Signals
- self.hal_manager.connect_to_signal("DeviceAdded", self.__plug_device_cb)
- self.hal_manager.connect_to_signal("DeviceRemoved", self.__unplug_device_cb)
-
- self.devices_avalaible = DevicesAvalaible()
- self.device_active = None
- self.__first_time_hardware_detection()
- self.available_devices = []
-
- def __first_time_hardware_detection(self):
- self.devices = self.hal_manager.GetAllDevices()
- for dev in self.devices:
- device_dbus_obj = self.dbus.get_object("org.freedesktop.Hal", dev)
- try:
- props = device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
- except:
- return False
- if props.has_key("info.subsystem"):
- if props["info.subsystem"] == "usb_device":
- if props.has_key("usb_device.product_id") and props.has_key("usb_device.product_id"):
- if self.devices_avalaible.is_device_supported(str(props["usb_device.vendor_id"]),
- str(props["usb_device.product_id"])):
- self.device_active = self.devices_avalaible.get_Device()
- self.device_active.dev_props = props
- break
- if(self.device_active != None):
- if(self.get_ports()):
- print self.device_active
- self.emit('added_device',self.device_active.name)
- else:
- print "Dispositivo no encontrado"
- self.devices = []
-
- def get_ports(self):
- ports = []
- self.devices = self.hal_manager.GetAllDevices()
- for dev in self.devices:
- device_dbus_obj = self.dbus.get_object("org.freedesktop.Hal", dev)
- try:
- props = device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
- except:
- return False
- if props.has_key("info.parent") and props["info.parent"] == self.device_active.dev_props["info.udi"]:
- if props.has_key("usb.linux.sysfs_path") :
- files = os.listdir(props["usb.linux.sysfs_path"])
- for f in files:
- if f.startswith("ttyUSB") :
- ports.append(f)
- ports.sort()
- if(len(ports)<1):
- self.device_active = None
- print "Dispositivo no reconocido por el sistema"
- return False
- else:
- data = self.device_active.port['data']
- self.device_active.port['data'] = ports[int(data)]
- conf = self.device_active.port['conf']
- self.device_active.port['conf'] = ports[int(conf)]
- print "Dispositivo reconocido "
- return True
-
- def __real_plug_device_cb(self, udi):
- #print "plug"
- self.devices.append(udi)
- device_dbus_obj = self.dbus.get_object("org.freedesktop.Hal", udi)
- try:
- dev_props = device_dbus_obj.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
- except:
- return False
- if dev_props.has_key("info.subsystem"):
- if dev_props["info.subsystem"] == "usb_device":
- if dev_props.has_key("usb_device.product_id") and dev_props.has_key("usb_device.product_id"):
- if self.devices_avalaible.is_device_supported(str(dev_props["usb_device.vendor_id"]),
- str(dev_props["usb_device.product_id"])):
- self.device_active = self.devices_avalaible.get_Device()
- self.device_active.dev_props = dev_props
- if(self.get_ports()):
- print self.device_active.name+" "+self.device_active.port['data']
- print self.device_active
- self.emit('added_device',self.device_active.name)
- print "Dispositivo encontrado"
-
- return False
-
- def __plug_device_cb(self, udi):
- gobject.timeout_add(3000, self.__real_plug_device_cb, udi)
-
- def __unplug_device_cb(self, udi):
- if (self.device_active != None):
- if(self.device_active.dev_props['info.udi'] == udi):
- self.device_active = None
- self.emit('removed_device')
- print "unplug device"
265 src/core/DialerMonitor.py
View
@@ -1,265 +0,0 @@
-try:
- import os
- from __init__ import operator
-except Exception, detail:
- print detail
-from subprocess import Popen, PIPE
-import gobject
-import time
-from Status import *
-from random import random
-
-class monitor(gobject.GObject):
-
- __gsignals__ = {'connecting' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
- 'connected' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,)),
- 'disconnecting' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
- 'disconnected' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,()),
- 'connecting_state_change' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_STRING,)),
- 'pppstats_signal' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,(gobject.TYPE_INT,gobject.TYPE_INT,
- gobject.TYPE_INT,))}
-
- def __init__(self):
- gobject.GObject.__init__(self)
- home = Popen('echo $HOME', shell=True, stdout=PIPE, close_fds=True)
- self.wvdial_conf_file = home.stdout.readline().replace('\n','')+'/.nugget/dialer.conf'
- self.wvdial_p = None
- self.wvdial_pid = None
- self.pppd_pid = None
- self.ppp_if = None
- self.last_traffic_time = 0.0
- self.dns_data = None
- self.select_operator = None
- self.status_flag = PPP_STATUS_DISCONNECTED
-
- self.test_up = 0
- self.test_down = 0
-
- #gobject.timeout_add_seconds(1,self.__algo)
-
- def __algo(self):
- self.test_up = self.test_up + int(random()*10)
- self.test_down = self.test_down + int(random()*10) + 20
- self.emit('pppstats_signal',self.test_down,self.test_up,1)
- return True
-
- def __create_config(self, modem_active):
- wvdial_conf = "[Dialer Defaults]\n"
- wvdial_conf = wvdial_conf + "Modem = /dev/%s\n" % modem_active
- phone = "*99#"
- if(self.__select_operator.get_attrib("phone")!=""):
- phone = self.__select_operator.get_attrib("phone")
- wvdial_conf = wvdial_conf + "Phone = %s\n" % phone
- wvdial_conf = wvdial_conf + "Username = '%s'\n" % self.__select_operator.get_attrib("username")
- wvdial_conf = wvdial_conf + "Password = '%s'\n" % self.__select_operator.get_attrib("password")
- os.system("rm -f %s" % self.wvdial_conf_file)
- fd = open(self.wvdial_conf_file, "w")
- fd.write(wvdial_conf)
- fd.close()
- self.__start_wvdial()
-
- def status(self):
- return self.status_flag
-
- def __start_wvdial(self):
- print "Starting Wvdial"
- self.status_flag = PPP_STATUS_CONNECTING
- self.emit('connecting')
-
- cmd = "/usr/bin/wvdial -C %s" % self.wvdial_conf_file
- self.wvdial_p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE,stderr=PIPE, close_fds=True)
- gobject.timeout_add(1, self.__wvdial_monitor)
- gobject.timeout_add(3000, self.__pppd_monitor)
-
- def __get_real_wvdial_pid(self):
- cmd = "ps -eo ppid,pid | grep '^[ ]*%s' | awk '{print $2}'" % self.wvdial_p.pid
- pm = Popen(cmd, shell=True, stdout=PIPE, close_fds=True)
-
- ret = pm.stdout.readline().strip("\n")
- if ret != "" :
- return ret
- else:
- return None
-
- def __wvdial_monitor(self):
- self.__real_wvdial_monitor()
- gobject.timeout_add(2000, self.__real_wvdial_monitor)
- return False
-
- def __real_wvdial_monitor(self):
- if self.wvdial_p.poll() == None :
- #print "Wvdial monitor : Wvdial running"
- return True
- else:
- print "Wvdial monitor : Wvdial killed"
- self.wvdial_p = None
- self.wvdial_p = None
- self.wvdial_pid = None
- self.pppd_pid = None
- self.ppp_if = None
- self.last_traffic_time = 0.0
- self.dns_data = None
- self.status_flag = PPP_STATUS_DISCONNECTED
-
- print "emit disconnected"
- self.emit('disconnected')
-
- return False
-
- def __pppd_monitor(self):
- if self.status_flag == PPP_STATUS_DISCONNECTING or self.status_flag == PPP_STATUS_DISCONNECTED :
- print "pppd monitor stopped, status disconnecting or disconected"
- self.pppd_pid == None
- self.ppp_if = None
- return False
-
- if self.wvdial_p == None:
- print "pppd monitor stopped, not wvdial running"
- return False
- elif self.wvdial_p.poll() != None:
- print "pppd monitor stopped, not wvdial running"
- return False
-
- if self.pppd_pid == None :
- if self.wvdial_pid == None :
- if os.path.exists("/etc/debian_version") :
- self.wvdial_pid = self.__get_real_wvdial_pid()
- else:
- self.wvdial_pid = self.wvdial_p.pid
- print "--------> WVDIAL PID %s" % self.wvdial_pid
- if self.wvdial_pid == None :
- return True
-
- #print "pppd monitor : looking for pppd"
- self.emit('connecting_state_change','Creando pppd')
- cmd = "ps -eo ppid,pid | grep '^[ ]*%s' | awk '{print $2}'" % self.wvdial_pid
- pm = Popen(cmd, shell=True, stdout=PIPE, close_fds=True)
-
- pppd_pid = pm.stdout.readline().strip("\n")
-
- if pppd_pid != "" :
- self.pppd_pid = pppd_pid
- print "--------> PPPD PID %s" % self.pppd_pid
- self.emit('connecting_state_change',"Buscando IP...")
-
- wvdial_stderr = self.wvdial_p.stderr
- while True:
- tmp_str = wvdial_stderr.readline()
- if "Using interface" in tmp_str :
- self.ppp_if = tmp_str.split()[-1]
- #print "pppd monitor : %s" % self.ppp_if
- break
-
- return True
- elif self.ppp_if != None :
- #print "pppd monitor : looking for ip"
- self.emit('connecting_state_change','Buscando IP...')
- cmd = "LANG=C ifconfig %s | grep 'inet addr'" % self.ppp_if
- pm = Popen(cmd, shell=True, stdout=PIPE, close_fds=True)
- out = pm.stdout.readline()
- if out != "" :
- sp = out.strip().split(" ")[1]
- ip = sp.split(":")[1]
- #print "pppd monitor : pppd connected"
- self.__set_dns_info()
- self.status_flag = PPP_STATUS_CONNECTED
- self.emit('connected',ip)
- gobject.timeout_add(2000, self.__stats_monitor)
- return False
- else:
- return True
- else:
- return True
-
- def start(self, current_op, modem_active):
- print "DAEMON ----> INIT"
- if self.status_flag != PPP_STATUS_DISCONNECTED :
- return
- self.__select_operator = current_op
- self.__create_config(modem_active)
-
- def stop(self):
- print "Stopping pppd"
-
- if self.wvdial_p == None:
- print "Stop : no wvdial_p"
- return
- elif self.wvdial_p.poll() != None:
- print "Stop : wvdial_p.poll() != None"
- return
-
-
- if self.wvdial_pid != None :
- print "emit disconnecting"
- self.emit('disconnecting')
- self.status_flag = PPP_STATUS_DISCONNECTING
- print "kill -15 %s" % self.wvdial_pid
- os.kill(int(self.wvdial_pid), 15)
-
- elif self.wvdial_p != None :
- if os.path.exists("/etc/debian_version") :
- self.wvdial_pid = self.__get_real_wvdial_pid()
- else:
- self.wvdial_pid = self.wvdial_p.pid
-
- self.emit('disconnecting')
- print "emit disconnecting"
- self.status_flag = PPP_STATUS_DISCONNECTING
-
- print "kill -15 %s" % self.wvdial_pid
- os.kill(int(self.wvdial_pid), 15)
-
- def __set_dns_info(self):
- print "-----> __set_dns_info (%s)" % self.dns_data
- if self.dns_data == None :
- return
-
- os.system("echo ';Nugget manager dns data' > /etc/resolv.conf")
- if self.dns_data[2] != "" :
- os.system("echo 'search %s' >> /etc/resolv.conf" % self.dns_data[2])
-
- if self.dns_data[0] != "" :
- os.system("echo 'nameserver %s' >> /etc/resolv.conf" % self.dns_data[0])
-
- if self.dns_data[1] != "" :
- os.system("echo 'nameserver %s' >> /etc/resolv.conf" % self.dns_data[1])
-
- def __parse_stats_response(self):
- cmd = "cat /proc/net/dev | grep %s | sed s/.*://g | awk '{print $1; print $9}'" % self.ppp_if
- pm = Popen(cmd, shell=True, stdout=PIPE, close_fds=True)
- rb = pm.stdout.readline().strip("\n")
- tb = pm.stdout.readline().strip("\n")
-
- if rb == "" and tb == "" :
- return 0, 0
- else:
- return int(rb) , int(tb)
-
- def __stats_monitor(self):
- if self.status_flag == PPP_STATUS_DISCONNECTING or self.status_flag == PPP_STATUS_DISCONNECTED :
- print "stats monitor stopped, status flag disconnecting or disconnected"
- return False
-
- if self.wvdial_p == None:
- print "stats monitor stopped, not wvdial running"
- return False
- elif self.wvdial_p.poll() != None:
- print "stats monitor stopped, not wvdial running"
- return False
-
- if self.ppp_if == None :
- return False
-
- recived_bytes , sent_bytes = self.__parse_stats_response()
- if self.last_traffic_time == 0.0 :
- self.last_traffic_time = time.time()
- else:
- if recived_bytes > 0 and sent_bytes > 0 :
- new_time = time.time()
- interval_time = new_time - self.last_traffic_time
- self.last_traffic_time = new_time
- if self.status_flag == PPP_STATUS_CONNECTED :
- self.emit("pppstats_signal", recived_bytes, sent_bytes, interval_time)
- #print "stats monitor : %i %i %d" % (recived_bytes, sent_bytes, interval_time)
-
- return True
4 src/core/Status.py
View
@@ -1,4 +0,0 @@
-PPP_STATUS_DISCONNECTED = 0
-PPP_STATUS_CONNECTED = 1
-PPP_STATUS_CONNECTING = 2
-PPP_STATUS_DISCONNECTING = 3
3  src/core/const.py
View
@@ -1,3 +0,0 @@
-GLADE_DIR = '../../data/glade/'
-ICONS_DIR = '../../data/icons/'
-CONF_DIR = '../../data/conf/'
579 src/core/mobile.py
View
@@ -1,579 +0,0 @@
-'''
-Created on 04/08/2011
-
-@author: Luis Ariel Vega Soliz (vsoliz.ariel@gmail.com)
-@contact: Uremix Team (http://uremix.org)
-
-'''
-
-import serial, time, datetime
-
-
-__ALL__ = ['PhoneBook', 'PhoneBookEntry', 'SMS', 'ATTerminalConnection', 'MobileDevice', 'MobilePhone']
-
-EOL = '\r\n'
-EOF = chr(26)
-RWSTORAGE = ['SM', 'ME', 'MT']
-
-def list_at_terminals(findlist = ['USB']):
- ''' Function that lists all the AT terminals connected to the computer '''
- atlist = []
- for interface in findlist:
- step = -1
- while step < 255:
- step = step + 1
- try:
- attc = ATTerminalConnection('/dev/tty' + interface + str(step))
- attc.set_timeout(0.01)
- attc.open()
- res = attc.send_command('AT')
- if 'OK' in res:
- attc.close()
- atlist.append(attc)
- attc.set_timeout(None)
- except Exception, e:
- pass
- return atlist
-
-def _parse_txt_to_sms((txt, device)):
- txt = txt.strip().split('\r\n')
- if (txt.count('ERROR')>0):
- return
- while(txt.count('OK')>0):
- txt.remove('OK')
- while(txt.count('')>0):
- txt.remove('')
- if(len(txt) <> 2):
- return
- message = txt[-1]
- txt = txt[0].strip().split(',')
- while(txt.count('')>0):
- txt.remove('')
- pos = txt[0].replace('"','')
- memory = txt[1].replace('"','')
- phone = txt[2].replace('"','')
- date=""
- if(len(txt)>3):
- date = (txt[3] +', '+ txt[4]).replace('"','')
- return SMS(message, phone, date, pos, memory, device)
-
-def _parse_txt_to_phonebook_entry((txt, memory)):
- txt = txt.strip().split('\r\n')
- if (txt.count('ERROR')>0):
- return
- while(txt.count('OK')>0):
- txt.remove('OK')
- while(txt.count('')>0):
- txt.remove('')
- if(len(txt) == 0):
- return
- txt = txt[0].strip().split(',')
- while(txt.count('')>0):
- txt.remove('')
- pos = txt[0].replace('"','')
- phone = txt[1].replace('"','')
- type = txt[2].replace('"','')
- name = txt[3].replace('"','')
- return PhoneBookEntry(name, phone, pos, type, memory)
-
-def _parse_txt_to_phonebook((txt, device)):
- txt = txt.strip().split('\r\n')
- if (txt.count('ERROR')>0):
- return
- while(txt.count('OK')>0):
- txt.remove('OK')
- while(txt.count('')>0):
- txt.remove('')
- if(len(txt) == 0):
- return
- txt = txt[0].strip().split(',')
- while(txt.count('')>0):
- txt.remove('')
- name = txt[0].replace('"','')
- capacity = txt[2].replace('"','')
- return PhoneBook(name, capacity, device)
-
-
-
-class PhoneBook:
- ''' Represents a phonebook '''
- def __init__(self, name, capacity, device):
- self.__name = name
- self.__capacity = int(capacity)
- self.__device = device
- self.__entries = []
-
- def get_name(self):
- return self.__name
-
- def get_entry(self, position):
- return self.__entries[position]
-
- def get_used(self):
- res = 0
- for e in self.__entries:
- if e <> None:
- res = res + 1
- return res
-
- def get_capacity(self):
- return self.__capacity
-
- def add_entries(self, entry):
- if len(self.__entries) == 0:
- self.load()
- if isinstance(entry, list):
- for i in entry:
- self.add_entry(i)
-
- def add_entry(self, entry):
- if len(self.__entries) == 0:
- self.load()
- if isinstance(entry, PhoneBookEntry):
- if self.__entries[entry.get_position()] <> None :
- if self.__entries[entry.get_position()] <> entry :
- entry.set_position(self.get_free_position())
- else:
- return
- self.__entries[entry.get_position()] = entry
-
- def get_free_position(self):
- i = 0
- while i < self.__capacity:
- if self.__entries[i] <> None:
- return i + 1
- i = i + 1
- return None
-
- def create_entry(self, name, phone):
- return PhoneBookEntry(name, phone, self.get_free_position(), phonebook = self)
-
- def delete_entry(self, entry):
- pass
-
- def save_entry(self, entry):
- self.__device._save_phonebook_entry(self.__name, entry)
-
- def load(self):
- if len(self.__entries) == 0:
- i = 0
- while i < self.__capacity:
- self.__entries.append(None)
- i = i + 1
- entries = self.__device._get_phonebook_entries(self.__name)
- for entry in entries:
- if entry <> None:
- self.__entries[entry.get_position()] = entry
-
- def __str__(self):
- return 'Storage: ' + self.__name + '\nMax: ' + str(self.__capacity) + '\nUsed: ' + str(self.get_used()) + '\nEntries:\n' + '\n'.join([str(i) for i in self.__entries])
-
- def __repr__(self):
- return str(self)
-
- def __iter__(self):
- return self
-
- def next(self):
- self.__entries = self.__entries[1:] + [self.__entries[0]]
- return self.__entries[-1]
-
-
-class PhoneBookEntry:
- ''' It represents a entry on the phonebook '''
- def __init__(self, name, phone, pos = -1, atype = 161, phonebook = None):
- self.__name = name
- self.__phone_number = phone
- self.__position = int(pos) - 1
- self.__type = atype
- self.__phonebook = phonebook
-
- def get_name(self):
- return self.__name
-
- def get_phone_number(self):
- return self.__phone_number
-
- def get_position(self):
- return self.__position
-
- def get_type(self):
- return self.__type
-
- def get_phonebook(self):
- return self.__phonebook
-
- def set_name(self, name):
- self.__name = name
-
- def set_phone_number(self, number):
- self.__phone_number = number
-
- def set_position(self, position):
- self.__position = position
-
- def set_type(self, type):
- self.__type = type
-
- def set_phonebook(self, phonebook):
- self.__phonebook = phonebook
-
- def delete(self):
- pass
-
- def save(self):
- self.__phonebook.save_entry(self)
-
- def __str__(self):
- return self.__name + ': ' + str(self.__phone_number)
-
- def __repr__(self):
- return str(self)
-
- def __eq__(self, other):
- try:
- return self.__name == other.get_name() and self.__phone_number == other.get_phone_number() and self.__position == other.get_position() and self.__type == other.get_type()
- except:
- return False
-
- def __neq__(self, other):
- return not self.__eq__(other)
-
-
-
-class SMS:
- ''' Represents a SMS, it can be sent or deleted '''
- def __init__(self, message, phone, date = datetime.date.today().strftime('%y/%m/%d,%T'), pos = -1, memory = 'VOLATILE', device = None):
- self.__phone_number = phone
- self.__message = message
- self.__date = date
- self.__position = int(pos)
- self.__memory = memory
- self.__device = device
-
- def send(self):
- if (self.__device == None) or (self.get_memory() == 'REC READ'):
- print 'no se puede enviar el mensaje'
- print self
- return
- self.__device.send_sms(self)
-
- def delete(self):
- if self.__device == None:
- return
- self.__device.delete_sms(self)
-
- def get_phone_number(self):
- return self.__phone_number
-
- def get_message(self):
- return self.__message
-
- def get_date(self):
- return self.__date
-
- def get_position(self):
- return self.__position
-
- def get_memory(self):
- return self.__memory
-
- def set_phone_number(self, number):
- self.__phone_number = number
-
- def set_message(self, message):
- self.__message = message
-
- def set_date(self, date):
- self.__date = date
-
- def set_position(self, position):
- self.__position = position
-
- def set_memory(self, memory):
- self.__memory = memory
-
- def __str__(self):
- res = 'Phone: '+ str(self.__phone_number) +'\nMsg: '+ self.__message + '\nDate: '+ self.__date + '\nMemory: ' + self.__memory + '\nPosition: '+ str(self.__position) + '\n:::'
- return res
-
- def __repr__(self):
- return str(self)
-
-
-
-class ATTerminalConnection:
- ''' Represents a terminal who process AT commands '''
- def __init__(self, port = '/dev/ttyUSB0'):
- self.__port_name = port
- self.__is_open = False
- self.__port = None
- self.__timeout = None
-
- def get_port_name(self):
- return self.__port_name
-
- def send_command(self, command, response = True):
- return self.send_direct_command(command +EOL, response)
-
- def send_direct_command(self, command, response = False):
- if(self.is_open()):
- self.__port.write(command)
- if response:
- res = self.read_buffer()
- return res
-
- def read_buffer(self):
- if self.__port == None:
- return
- res = ''
- a = time.time()
- b = time.time()
- while self.__port.inWaiting() or not self.__is_valid_response(res):
- buff = self.__port.readline()
- if not buff.startswith('^'):
- res = res + buff
- if (self.__timeout == None) or ( (b-a) < self.__timeout ):
- b = time.time()
- time.sleep(0.0001)
- else:
- break
- self.__port.flushInput()
- return res
-
- def __is_valid_response(self, response):
- return ('OK' in response) or ('ERROR' in response) or ('COMMAND NOT SUPPORT' in response)
-
- def clear_buffer(self):
- if self.__port == None:
- return
- self.__port.flushInput()
-
- def open(self):
- if (self.is_open()):
- return
- try:
- if self.__port == None:
- self.__port = serial.Serial(self.__port_name)
- self.__port.open()
- self.__is_open = True
- except:
- raise
-
- def close(self):
- if (self.__port == None) or (not self.is_open()):
- return
- try:
- self.__port.close()
- self.__is_open = False
- except:
- pass
-
- def set_timeout(self, timeout):
- self.__timeout = timeout
- if self.__port <> None:
- self.__port.setTimeout(timeout)
-
- def get_timeout(self):
- return self.__timeout
-
- def is_open(self):
- return self.__is_open
-
- def exist_command(self, command, timeout = None):
- to = self.__timeout
- self.set_timeout(timeout)
- if not self.is_open():
- self.open()
- self.send_command(command, False)
- res = self.read_buffer()
- self.close()
- else:
- res = self.send_command(command)
- self.set_timeout(to)
- return '\r\nOK\r\n' in res
-
- def __str__(self):
- return self.__port_name
-
- def __repr__(self):
- return str(self)
-
-
-
-class MobileDevice:
- ''' Represents a mobile device, this is the base class of a mobile phone '''
- def __init__(self, atport):
- self._port = atport
- self._port.open()
-
- def _prepare(self):
- self._port.send_command('ATE0')
- self._port.send_command('AT+CMGF=1')
- self._port.send_command('AT+CPMS="ME","ME","ME"')
- self._port.send_command('AT+COPS=0,0')
-
- def get_manufacturer(self):
- return self._port.send_command('AT+CGMI')
-
- def get_model(self):
- return self._port.send_command('AT+CGMM')
-
- def get_imei(self):
- return self._port.send_command('AT+CGSN')
-
- def create_sms(self, message, phone):
- return SMS(message, phone, device = self)
-
- def send_sms(self, message, phone = None):
- self._prepare()
- if isinstance(message, str) and phone == None:
- return
- if isinstance(message, SMS):
- phone = message.get_phone_number()
- message = message.get_message()
- to = self._port.get_timeout()
- self._port.set_timeout(None)
- self._port.send_command('AT+CMGS="'+str(phone)+'"', False)
- self._port.send_command(message,False)
- self._port.send_direct_command(EOF)
- #self._port.clear_buffer()
- print self._port.read_buffer()
- self._port.set_timeout(to)
-
- def _list_sms(self, memory = 'ALL'):
- self._prepare()
- self._port.clear_buffer()
- res = self._port.send_command('AT+CMGL="'+memory+'"')
- res = res.split('+CMGL:')
- while(res.count('\r\n')>0):
- res.remove('\r\n')
- res = map(_parse_txt_to_sms, [(x,y) for x in res for y in [self]])
- return res
-
- def list_sms(self):
- return self._list_sms()
-
- def list_new_sms(self):
- return self._list_sms('REC UNREAD')
-
- def list_old_sms(self):
- return self._list_sms('REC READ')
-
- def list_unsend_sms(self):
- return self._list_sms('STO UNSENT')
-
- def list_sended_sms(self):
- return self._list_sms('STO SENT')
-
- def delete_sms(self, sms):
- self._prepare()
- if isinstance(sms, SMS):
- sms = sms.get_position()
- print self._port.send_command('AT+CMGD='+str(sms))
-
- def get_operator(self):
- self._prepare()
- res = self._port.send_command('AT+COPS?').split(',')
- return res[-2].replace('"','')
-
- def get_signal_strenght(self):
- signal = self._port.send_command('AT+CSQ')
- signal = signal.split('\r\n')
- for line in signal:
- if(line.startswith('+CSQ')):
- line=line.split(':')[1]
- return int(line.split(',')[0])
- return 0
-
-
-
-class MobilePhone(MobileDevice):
- ''' Represents a mobile phone, it has methods for make and response a call '''
-
- def __init__(self, atport):
- MobileDevice.__init__(self, atport)
- self._port.set_timeout(0.5)
-
- def _get_storage(self, storage = None):
- self._prepare()
- oldstorage = None
- if storage <> None:
- oldstorage = self._get_storage()
- self._port.send_command('AT+CPBS="'+ storage +'" ')
- res = self._port.send_command('AT+CPBS? ')
- res = res.split('+CPBS:')
- while(res.count('\r\n')>0):
- res.remove('\r\n')
- res = _parse_txt_to_phonebook((res[0], self))
- if oldstorage <> None:
- self._port.send_command('AT+CPBS="'+ oldstorage.get_name() +'" ')
- return res
-
- def _get_phonebook(self, storage = None):
- self._prepare()
- oldstorage = None
- if storage <> None:
- oldstorage = self._get_storage()
- self._port.send_command('AT+CPBS="'+ storage +'" ')
- res = self._get_storage()
- res.add_entries(self._get_phonebook_entries())
- if oldstorage <> None:
- self._port.send_command('AT+CPBS="'+ oldstorage.get_name() +'" ')
- return res
-
- def _get_phonebook_entries(self, storage = None):
- self._prepare()
- if isinstance(storage, str):
- storage = self._get_storage(storage)
- oldstorage = None
- if storage <> None:
- oldstorage = self._get_storage()
- self._port.send_command('AT+CPBS="'+ storage.get_name() +'" ')
- else:
- storage = self._get_storage()
- res = self._port.send_command('AT+CPBR=1,' + str(storage.get_capacity()) )
- res = res.split('+CPBR:')
- while(res.count('\r\n')>0):
- res.remove('\r\n')
- res = map(_parse_txt_to_phonebook_entry, [(x,y) for x in res for y in [self._get_storage()]])
- if oldstorage <> None:
- self._port.send_command('AT+CPBS="'+ oldstorage.get_name() +'" ')
- return res
-
- def get_phonebook(self):
- return self._get_phonebook()
-
- def get_missed_calls(self):
- return self._get_phonebook('MC')
-
- def get_dialed_calls(self):
- return self._get_phonebook('DC')
-
- def get_received_calls(self):
- return self._get_phonebook('RC')
-
- def _save_phonebook_entry(self, storage, entry):
- oldstorage = self._get_storage()
- if storage not in RWSTORAGE:
- return
- self._port.send_command('AT+CPBS="'+storage+'"')
- self._port.send_command('AT+CPBW='+str(entry.get_position())+','+entry.get_phone_number(),','+str(entry.get_type())+',"'+entry.get_name()+'"')
- self._port.send_command('AT+CPBS="'+oldstorage.get_name()+'"')
-
- def call(self, phone):
- self._prepare()
- return self._port.send_command('ATD'+phone)
-
-
-
-if __name__ == '__main__':
- #terms = list_at_terminals() # list available terminals :D
- #print terms
- #if len(terms)>0:
- dev = ATTerminalConnection("/dev/ttyUSB1")
- mobile = MobilePhone(dev) # create a mobile phone with the last terminal
- #sms = mobile.create_sms('jejejejeje', 70927261) # we create a SMS
- #sms.send() # yeah babe! :D
- print mobile.list_sms() # watch the sms's on the phone :D
- #print mobile.get_signal_strenght()
31 src/core/osd.py
View
@@ -1,31 +0,0 @@
-import pynotify
-
-path = "file:///home/lance/aplicaciones/nugget/data/icons/"
-img_device = path+'drive.png'
-img_sms = path+'sms_new.png'
-img_connected = path+'connected.png'
-img_disconnected = path+'disconnected.png'
-
-def show_device_found(modem):
- pynotify.init("Device found")
- notification = pynotify.Notification("Dispositivo encontrado",modem+'\n\n', img_device)
- notification.show()
-
-def show_new_sms(number):
- pynotify.init("New SMS")
- notification = pynotify.Notification("Nuevo SMS",number, img_sms)
- notification.show()
-
-def show_connected(ip, dns):
- pynotify.init("Connected")
- notification = pynotify.Notification("Coneccion establecida",'IP: '+ip+'\nDNS: '+dns, img_connected)
- notification.show()
-
-def show_disconnect():
- pynotify.init("DisConnected")
- notification = pynotify.Notification("Desconectado correctamente",None, img_disconnected)
- notification.show()
-
-
-if __name__ == "__main__":
- show_connected('10.2.3.4','20.3.42.3')
16 src/core/util.py
View
@@ -1,16 +0,0 @@
-
-class operator:
- def __init__(self):
- self.__attrib={}
- self.__attrib["name"]=""
- self.__attrib["phone"]=""
- self.__attrib["username"]=""
- self.__attrib["password"]=""
- self.__attrib["logo"]=""
- self.__attrib["stupid_mode"]=""
-
- def add(self,atr,data):
- self.__attrib[atr]=data
-
- def get_attrib(self,atr):
- return self.__attrib[atr]
65 src/gtk/Notification.py
View
@@ -1,65 +0,0 @@
-#!/usr/bin/env python
-
-
-import os
-import gtk
-
-class TrackerStatusIcon(gtk.StatusIcon):
- def __init__(self):
- gtk.StatusIcon.__init__(self)
- menu = '''
- <ui>
- <menubar name="Menubar">
- <menu action="Menu">
- <menuitem action="Search"/>
- <menuitem action="Preferences"/>
- <separator/>
- <menuitem action="About"/>
- </menu>
- </menubar>
- </ui>
- '''
- actions = [
- ('Menu', None, 'Menu'),
- ('Search', None, '_Search...', None, 'Search files with MetaTracker', self.on_activate),
- ('Preferences', gtk.STOCK_PREFERENCES, '_Preferences...', None, 'Change MetaTracker preferences', self.on_preferences),
- ('About', gtk.STOCK_ABOUT, '_About...', None, 'About MetaTracker', self.on_about)]
- ag = gtk.ActionGroup('Actions')
- ag.add_actions(actions)
- self.manager = gtk.UIManager()
- self.manager.insert_action_group(ag, 0)
- self.manager.add_ui_from_string(menu)
- self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent
- search = self.manager.get_widget('/Menubar/Menu/Search')
- search.get_children()[0].set_markup('<b>_Search...</b>')
- search.get_children()[0].set_use_underline(True)
- search.get_children()[0].set_use_markup(True)
- #search.get_children()[1].set_from_stock(gtk.STOCK_FIND, gtk.ICON_SIZE_MENU)
- self.set_from_stock(gtk.STOCK_FIND)
- self.set_tooltip('Tracker Desktop Search')
- self.set_visible(True)
- self.connect('activate', self.on_activate)
- self.connect('popup-menu', self.on_popup_menu)
-
- def on_activate(self, data):
- #os.spawnlpe(os.P_NOWAIT, 'tracker-search-tool', os.environ)
- print 'search'
-
- def on_popup_menu(self, status, button, time):
- self.menu.popup(None, None, None, button, time)
-
- def on_preferences(self, data):
- print 'preferences'
-
- def on_about(self, data):
- dialog = gtk.AboutDialog()
- dialog.set_name('Tracker')
- dialog.set_version('0.5.0')
- dialog.set_comments('A desktop indexing and search tool')
- dialog.set_website('www.freedesktop.org/Tracker')
- dialog.run()
- dialog.destroy()
-
-if __name__ == '__main__':
- TrackerStatusIcon()
- gtk.main()
64 src/gtk/Progress.py
View
@@ -1,64 +0,0 @@
-try:
- import pygtk
- pygtk.require("2.0")
- import gtk
- import gobject
-except Exception, detail:
- print detail
-
-import sys
-sys.path.append('/home/lance/aplicaciones/nugget/src/core')
-from const import GLADE_DIR, ICONS_DIR
-
-
-class ProgressDialog:
-
- def __init__(self):
- self.glade = GLADE_DIR + 'interface.glade'
- self.dTree = gtk.glade.XML(self.glade, 'progress_dialog')
- self.window = self.dTree.get_widget('progress_dialog')
- self.label = self.dTree.get_widget('label_operation')
- self.button = self.dTree.get_widget('button_cancel')
- self.image = self.dTree.get_widget('image2')
- self.should_change = True
- self.__switch = True
-
- def show(self):
- def image_change():
- if(not self.should_change):
- return False
- if(self.__switch):
- self.image.set_from_file(ICONS_DIR + 'network-transmit.png')
- self.__switch = False
- else:
- self.image.set_from_file(ICONS_DIR + 'network-receive.png')
- self.__switch = True
- return self.should_change
- self.should_change = True
- self.window.show_all()
- gobject.timeout_add_seconds(1, image_change)
-
- def show_error(self, msg):
- self.image.set_from_file(ICONS_DIR + 'network-error.png')
- self.label.set_markup(msg)
- self.button.set_label('Cerrar')
- self.window.show_all()
-
- def show_disconnect(self,msg):
- self.image.set_from_file(ICONS_DIR + 'network-offline.png')
- self.label.set_markup(msg)
- self.button.set_label('Cerrar')
- self.window.show_all()
-
- def show_phone_error(self,msg):
- self.image.set_from_file(ICONS_DIR + 'modem-warning.png')
- self.label.set_markup(msg)
- self.button.set_label('Cerrar')
- self.window.show_all()
-
- def change_message(self, msg):
- self.label.set_markup(msg)
-
- def hide(self):
- self.__should_change = False
- self.window.hide()
104 src/gtk/Screen.py
View
@@ -1,104 +0,0 @@
-import gtk
-import gtk.glade
-import cairo
-import gobject
-from random import random
-
-class Point:
- def __init__(self, p_x = 0, p_y = 0):
- self.down = p_x
- self.up = p_y
-
-class Screen(gtk.DrawingArea):
- def __init__(self):
- super(Screen, self).__init__()
- self.__intervals = []
- self.__limite = 36
- self.__width = 0
- self.__height = 0
- self.__max_speed = 100
- self.connect("expose_event", self.expose)
- self.update()
-
- def redraw_canvas(self):
- if self.window:
- alloc = self.get_allocation()
- rect = gtk.gdk.Rectangle(0, 0, alloc.width, alloc.height)
- self.window.invalidate_rect(rect, True)
- self.queue_draw_area(alloc.x, alloc.y, alloc.width, alloc.height)
- self.window.process_updates(True)
-
- def update(self):
- self.redraw_canvas()
- return True
-
- def expose(self,widget,event):
- context = widget.window.cairo_create()
- context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height)
- context.clip()
- rect = self.get_allocation()
- self.__limite = int((rect.width-30)/5)
- self.__width = rect.width
- self.__height = rect.height
- self.draw(context,rect.width,rect.height)
- return False
-
- def draw(self, cr, width, height):
- self.style.apply_default_background(self.window, True, gtk.STATE_NORMAL, None, 0, 0, width, height)
- cr.set_source_rgb( 0, 0, 0)
- cr.rectangle(0, 0, width, height)
- cr.fill()
- if(len(self.__intervals) > 0):
- position = self.__intervals[0]
- pos_x=width-len(self.__intervals)*5
- cr.set_source_rgb( 1, 0, 0)
- for point in self.__intervals:
- cr.move_to(pos_x,position.down)
- pos_x = pos_x+5
- cr.line_to(pos_x,point.down)
- position = point
- cr.set_line_width(1.5)
- cr.stroke()
- if(len(self.__intervals) > 0):
- position = self.__intervals[0]
- pos_x=width-len(self.__intervals)*5
- cr.set_source_rgb( 0, 0, 1)
- for point in self.__intervals:
- cr.move_to(pos_x,position.up)
- pos_x = pos_x+5
- cr.line_to(pos_x,point.up)
- position = point
- cr.set_line_width(1.5)
- cr.stroke()
- self.__draw_frame(cr,width, height)
-
- def __draw_frame(self, cr, width, height):
- cr.set_source_rgb( 1, 1, 1)
- cr.move_to(40,10)
- cr.line_to(40,height-20)
- cr.move_to(40,height-20)
- cr.line_to(width-10,height-20)
- cr.set_line_width(1.5)
- cr.stroke()
- cr.move_to(10,10)
- cr.select_font_face("Droid")
- cr.set_font_size(12)
- cr.show_text(str(self.__max_speed))
- cr.move_to(450,15)
- cr.set_source_rgb(1,0,0)
- cr.show_text("Datos Recibidos")
- cr.move_to(450,30)
- cr.set_source_rgb(0,0,1)
- cr.show_text("Datos Enviados")
-
- def update_points(self,down,up):
- if(len(self.__intervals) == self.__limite):
- del self.__intervals[0]
- if(down>self.__max_speed):
- while(down>self.__max_speed):
- self.__max_speed = self.__max_speed + 50
- down = (156*down)/self.__max_speed
- up = (156*up)/self.__max_speed
- down = self.__height - 30 - down
- up = self.__height - 30 - up
- self.__intervals.append(Point(down,up))
76 src/gtk/StatusIcon.py
View
@@ -1,76 +0,0 @@
-#!/usr/bin/env python
-
-
-import os
-import gtk
-import gobject
-import pyosd
-
-class Status(gtk.StatusIcon,gobject.GObject):
-
-
-
- def __init__(self):
- gtk.StatusIcon.__init__(self)
- gobject.GObject.__init__(self)
- menu = '''
- <ui>
- <menubar name="Menubar">
- <menu action="Menu">
- <menuitem action="View"/>
- <menuitem action="About"/>
- <separator/>
- <menuitem action="Quit"/>
- </menu>
- </menubar>
- </ui>
- '''
- actions = [
- ('Menu', None, 'Menu'),
- ('View', None, '_Mostrar ventana', None, 'Mostrar ventana', self.on_activate),
- ('About', gtk.STOCK_ABOUT, '_Acerca de Nugget', None, 'Acerca de Nugget', self.on_about),
- ('Quit',None,'_Salir',None,None,self.on_quit)]
- ag = gtk.ActionGroup('Actions')
- ag.add_actions(actions)
- self.manager = gtk.UIManager()
- self.manager.insert_action_group(ag, 0)
- self.manager.add_ui_from_string(menu)
- self.menu = self.manager.get_widget('/Menubar/Menu/About').props.parent
- self.set_from_stock(gtk.STOCK_FIND)
- self.set_tooltip('Tracker Desktop Search')
- self.set_visible(True)
- self.connect('activate', self.on_activate)
- self.connect('popup-menu', self.on_popup_menu)
-
- def on_activate(self, data):
- #os.spawnlpe(os.P_NOWAIT, 'tracker-search-tool', os.environ)
- print 'search'
- osd = pyosd.osd()
- #osd.set_colour("red")
- #osd.set_align(pyosd.ALIGN_CENTER)
- osd.display('hola')
- osd.wait_until_no_display()
- #osd.show()
-
- def on_popup_menu(self, status, button, time):
- self.menu.popup(None, None, None, button, time)
-
- def on_preferences(self, data):
- print 'preferences'
-
- def on_about(self, data):
- dialog = gtk.AboutDialog()
- dialog.set_name('Tracker')
- dialog.set_version('0.5.0')
- dialog.set_comments('A desktop indexing and search tool')
- dialog.set_website('www.freedesktop.org/Tracker')
- dialog.run()
- dialog.destroy()
-
- def on_quit(self,data):
- print 'quit'
- gtk.main_quit()
-
-if __name__ == '__main__':
- Status()
- gtk.main()
327 src/gtk/gtk_interface.py
View
@@ -1,327 +0,0 @@
-try:
- import pygtk
- pygtk.require("2.0")
- import gtk
- import gtk.glade
- import os
- import threading
- import gobject
-except Exception, detail:
- print detail
-
-import sys
-sys.path.append('/home/lance/aplicaciones/nugget/src/core')
-from DialerMonitor import monitor
-from Progress import ProgressDialog
-from subprocess import Popen, PIPE
-from Status import *
-from DevicesController import DeviceController
-from Screen import Screen
-from DeviceSerial import PhoneData
-from const import *
-from util import operator
-from interface import Interface
-import osd
-
-class MainInterface:
-
- def __init__(self):
- #Instances
- self.__interface = Interface()
- self.__dialog = ProgressDialog()
- self.controller = DeviceController()
- self.dev_active = self.controller.device_active
- self.operators = []
- self.mon = monitor()
- self.myScreen = Screen()
- self.phone_data = None
-
- self.build_list_operators()
- self.build_combo_operators()
- self.build_phone_options()
- self.__create_graphics_cairo()
- self.__create_sms_model()
- self.__create_address_book_model()
-
- if(self.dev_active != None):
- self.__interface.set_status("Dispositivo activo: "+self.dev_active.name)
- gobject.timeout_add_seconds(5,self.__connect_to_phone)
-
- #vars
- self.__last_received = 0
- self.__last_sent = 0
-
- #signals
- self.__dialog.button.connect("clicked",self.cancel_connection,self.__dialog)
- self.__interface.window.connect("destroy", self.quit_cb)
- self.__interface.button_connect.connect("pressed",self.connect)
- self.__interface.menu_about.connect("activate",self.show_about)
- self.__interface.box_options.connect("cursor-changed",self.change_option)
- self.__interface.send_sms.connect('clicked',self.send_message)
- self.controller.connect('added_device',self.__plug)
- self.controller.connect('removed_device',self.__unplug)
-
- #self.__interface.button1.connect("pressed",self.__connect_to_phone)
-
- self.mon.connect('connecting',self.__connecting_dialog)
- self.mon.connect('connected',self.__connected_dialog)
- self.mon.connect('disconnecting',self.__disconnecting_dialog)
- self.mon.connect('disconnected',self.__disconnected_dialog)
- self.mon.connect('connecting_state_change',self.__connecting_dialog)
- self.mon.connect('pppstats_signal',self.__ppp_stats)
-
- self.__interface.window.show_all()
-
- def __show_signal(self,phonedata,signal):
- if(self.phone_data != None):
- #signal = int(self.phone_data.get_signal())
- if(signal>=23):
- path = ICONS_DIR+'nm-signal-100.png'
- elif(signal>=15):
- path = ICONS_DIR+'nm-signal-75.png'
- elif(signal>=8):
- path = ICONS_DIR+'nm-signal-25.png'
- else:
- path = ICONS_DIR+'nm-signal-00.png'
- else:
- path = ICONS_DIR+'nm-signal-00.png'
- self.__interface.image_signal.set_from_file(path)
-
- def build_phone_options(self):
- box_options=self.__interface.box_options
- liststore = gtk.ListStore(gtk.gdk.Pixbuf,str)
- tvcolumn = gtk.TreeViewColumn()
- box_options.append_column(tvcolumn)
- px = gtk.CellRendererPixbuf()
- cell = gtk.CellRendererText()
- tvcolumn.pack_start(px, False)
- tvcolumn.pack_start(cell, True)
- tvcolumn.add_attribute(px, 'pixbuf', 0)
- tvcolumn.add_attribute(cell, 'text', 1)
- options = ['Nuevo','Buzon de entrada','Buzon de salida','Agenda']
- icons = ['new_sms','received_sms','mail-copy','addressbook']
- i = 0
- while( i <len(options)):
- iter = liststore.append()
- liststore.set_value(iter, 1, options[i])
- logo_path =ICONS_DIR + icons[i]+ '.png'
- if os.path.exists(logo_path):
- liststore.set_value(iter, 0, gtk.gdk.pixbuf_new_from_file(logo_path))
- i = i +1
- box_options.set_model(liststore)
-
- def __create_address_book_model(self):
- box = self.__interface.box_address
- cell1 = gtk.CellRendererText()
- cell2 = gtk.CellRendererText()
- tcolumn = gtk.TreeViewColumn('Nombre')
- tcolumn1 = gtk.TreeViewColumn('Numero')
- box.append_column(tcolumn)
- box.append_column(tcolumn1)
- tcolumn.pack_start(cell1, True)
- tcolumn1.pack_start(cell2, True)
- tcolumn.add_attribute(cell1, 'text',0)
- tcolumn1.add_attribute(cell2, 'text',1)
-
- def __create_address_book_list(self):
- liststore2 = gtk.ListStore(str,str)
- list = self.phone_data.get_addressbook()
- for item in list:
- if(item != None):
- iter = liststore2.append()
- liststore2.set_value(iter,0,item.get_name())
- liststore2.set_value(iter,1,item.get_phone_number())
- else:
- break
- self.__interface.box_address.set_model(liststore2)
-
- def __create_sms_model(self):
- box = self.__interface.box_sms
- cell1 = gtk.CellRendererText()
- cell2 = gtk.CellRendererText()
- cell3 = gtk.CellRendererText()
- tcolumn = gtk.TreeViewColumn('Numero')
- tcolumn1 = gtk.TreeViewColumn('Asunto')
- tcolumn2 = gtk.TreeViewColumn('Fecha')
- box.append_column(tcolumn)
- box.append_column(tcolumn1)
- box.append_column(tcolumn2)
- tcolumn.pack_start(cell1, True)
- tcolumn1.pack_start(cell2, True)
- tcolumn2.pack_start(cell3, True)
- tcolumn.add_attribute(cell1, 'text',0)
- tcolumn1.add_attribute(cell2, 'text',1)
- tcolumn2.add_attribute(cell3, 'text',2)
-
- def __create_sms_list(self):
- list = self.phone_data.get_old_sms()
- liststore2 = gtk.ListStore(str,str,str)
- for item in list:
- if(item <> None):
- iter = liststore2.append()
- liststore2.set_value(iter,0,item.get_phone_number())
- liststore2.set_value(iter,1,item.get_message())
- liststore2.set_value(iter,2,item.get_date())
- self.__interface.box_sms.set_model(liststore2)
-
- def __add_sms_list(self, phonedata):
- list = self.phone_data.get_new_sms()
- liststore2 = self.__interface.box_sms.get_model()
- for sms in list:
- if(sms <> None):
- iter = liststore2.preppend()
- liststore2.set_value(iter,0,item.get_phone_number())
- liststore2.set_value(iter,1,item.get_message())
- liststore2.set_value(iter,2,item.get_date())
- self.__interface.box_sms.set_model(liststore2)
-
- def __ppp_stats(self,monitor,received,sent,interval):
- up_speed = ((sent - self.__last_sent)/interval)/1024
- down_speed = ((received - self.__last_received)/interval)/1024
- self.__last_sent = sent
- self.__last_received = received
- self.myScreen.update_points(down_speed,up_speed)
- if (self.__interface.notebook.get_current_page() == 1):
- self.__interface.upspeed.set_markup(str(up_speed)+" KB")
- self.__interface.downspeed.set_markup(str(down_speed)+" KB")
- self.__interface.label_up.set_markup(str(sent)+" KB")
- self.__interface.label_down.set_markup(str(received)+" KB")
-
- self.myScreen.update()
-
- def __create_graphics_cairo(self):
- kids = self.__interface.vbox_cairo.get_children()
- if(kids is not None):
- for sprog in kids:
- self.__interface.vbox_cairo.remove(sprog)
- self.__interface.vbox_cairo.add(self.myScreen)
- self.__interface.vbox_cairo.show_all()
-
- def __connecting_dialog(self,monitor,data = None):
- if(data == None):
- self.__dialog.change_message("Conectando...")
- else:
- self.__dialog.change_message(data)
-
- def __connected_dialog(self,monitor,ip):
- self.__dialog.hide()
- self.__interface.label_ip.set_markup(ip)
- self.__interface.button_connect.set_label("Desconectar")
- self.__interface.button_connect.set_active(True)
- self.__interface.window.set_sensitive(True)
- osd.show_connected(ip,'10.23.4.5')
-
- def __disconnecting_dialog(self,monitor):
- self.__dialog.show_disconnect("Desconectando...")
-
- def __disconnected_dialog(self,monitor):
- self.__dialog.should_change = False
- self.__dialog.show_disconnect('Correctamente desconectado.')
- self.__dialog.hide()
- self.__interface.window.set_sensitive(True)
- osd.show_disconnect()
-
- def __plug(self,m_controller,dev):
- self.dev_active = self.controller.device_active
- self.__interface.set_status("Dispositivo activo: "+dev)
- gobject.timeout_add_seconds(15,self.__connect_to_phone)
- osd.show_device_found(dev)
-
- def __connect_to_phone(self):
- self.phone_data = PhoneData(self.dev_active.port['conf'])
- signal = self.phone_data.get_signal()
- self.__show_signal(self.phone_data,signal)
- self.phone_data.connect('signal_update',self.__show_signal)
- self.phone_data.connect('new_sms',self.__add_sms_list)
- self.__create_sms_list()
- self.__create_address_book_list()
-
- return False
-
- def __unplug(self,m_controller):
- self.__interface.set_status('No hay ningun dispositivo activo')
- self.phone_data = None
-
- def build_list_operators(self):
- from xml.dom.minidom import parse
-
- midom = parse(CONF_DIR + 'operators.xml')
- m_operators = midom.childNodes[0].childNodes
- for m_operator in m_operators:
- if (m_operator.nodeType == 1):
- op = operator()
- op.add("name",m_operator.attributes.get("name").value)
- attribs = m_operator.childNodes
- for attrib in attribs:
- if(attrib.nodeType == 1):
- op.add(attrib.nodeName,attrib.childNodes[0].data)
- self.operators.append(op)
-
- def connect(self,widget, data = None):
- if(self.controller.device_active == None):
- self.__dialog.show_error("No hay dispositivo conectado.")
- return
- combo = self.__interface.combo_operator
- active = combo.get_active()
- if(active == -1):
- self.__dialog.show_error('Seleccione un operador.')
- return
- if(self.mon.status() == PPP_STATUS_DISCONNECTED):
- self.__interface.window.set_sensitive(False)
- self.__dialog.show()
- self.mon.start(self.operators[active],self.dev_active.port['data'])
- else:
- widget.set_label("Conectar")
- self.mon.stop()
-
- def send_message(self,widget):
- if(self.phone_data <> None):
- phone,message = self.__interface.send_message()
- self.phone_data.send_sms(message,phone)
- else:
- self.__dialog.show_phone_error('No hay un dispositivo conectado.')
-
- def cancel_connection(self,widget,dialog,data = None):
- if(self.mon.status() == PPP_STATUS_CONNECTING):
- self.mon.stop()
- return
- if(self.mon.status() == PPP_STATUS_DISCONNECTED):
- dialog.hide()
- self.__interface.window.set_sensitive(True)
-
- def show_about(self,widget):
- self.__interface.show_about()
-
- def change_option(self,widget):
- treeselection = widget.get_selection()
- (model, iter) = treeselection.get_selected()
- [path,] = model.get_path(iter)
- self.__interface.notebook_phone.set_current_page(path)
-
- def build_combo_operators(self):
- box_operators=self.__interface.combo_operator
- liststore = gtk.ListStore(gtk.gdk.Pixbuf,str)
- px = gtk.CellRendererPixbuf()
- cell = gtk.CellRendererText()
- box_operators.pack_start(px)
- box_operators.pack_start(cell)
- box_operators.add_attribute(px, 'pixbuf', 0)
- box_operators.add_attribute(cell, 'text', 1)
- for i in self.operators:
- iter = liststore.append()
- liststore.set_value(iter, 1, i.get_attrib('name'))
- logo_path =ICONS_DIR+i.get_attrib('logo')+ '.png'
- if os.path.exists(logo_path):
- liststore.set_value(iter, 0, gtk.gdk.pixbuf_new_from_file(logo_path))
- box_operators.set_model(liststore)
- box_operators.set_active(-1)
-
- def quit_cb(self,widget, data=None):
- gtk.main_quit()
-
-def main():
- gtk.main()
-
-if __name__ == "__main__":
- m_interface = MainInterface()
- main()
50 src/gtk/interface.py
View
@@ -1,50 +0,0 @@
-try:
- import pygtk
- pygtk.require("2.0")
- import gtk
- import gtk.glade
-except Exception, detail:
- print detail
-from const import *
-
-
-class Interface:
-
- def __init__(self):
- self.glade = GLADE_DIR + 'interface.glade'
- self.wTree = gtk.glade.XML(self.glade,'mainUI')
- self.window = self.wTree.get_widget('mainUI')
- self.label_status = self.wTree.get_widget('label_status')
- self.image_signal = self.wTree.get_widget('image1')
- self.box_options = self.wTree.get_widget('treeview-list')
- self.box_address = self.wTree.get_widget('treeview-address')
- self.box_sms = self.wTree.get_widget('treeview_sms')
- self.notebook = self.wTree.get_widget('notebook1')
- self.upspeed = self.wTree.get_widget('upspeed')
- self.downspeed = self.wTree.get_widget('downspeed')
- self.label_up = self.wTree.get_widget('uplabel')
- self.label_down = self.wTree.get_widget('downlabel')
- self.label_ip = self.wTree.get_widget("iplabel")
- self.button_connect = self.wTree.get_widget("connect")
- self.combo_operator = self.wTree.get_widget('combobox')
- self.menu_about = self.wTree.get_widget('menu_item_about')
- self.vbox_cairo = self.wTree.get_widget('vbox_cairo')
- self.button1 = self.wTree.get_widget("button1")
- self.send_sms = self.wTree.get_widget('send_sms')
- self.notebook_phone = self.wTree.get_widget('nb_phone')
-
- def set_status(self, msg):
- self.label_status.set_markup(msg)
-
- def show_about(self):
- self.about = gtk.glade.XML(self.glade,'about-dialog')
- self.about.get_widget('about-dialog').show_all()
-
- def send_message(self):
- phone = self.wTree.get_widget('entry_phone').get_text()
- buffer = self.wTree.get_widget('tv_sms').get_buffer()
- start, end = buffer.get_bounds()
- message = buffer.get_text(start, end, include_hidden_chars=True)
- return (phone,message)
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.