2 * test-gsm-receive - Play with receiving GSM data
4 * Copyright (C) 2010 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 public DBus.Connection sbus;
25 //string VERSION = "0.1";
27 public class GSMReceive: Object //, zavai.Resource
29 public dynamic DBus.Object device;
30 public dynamic DBus.Object network;
31 public dynamic DBus.Object call;
35 //zavai.gsm.gsm.request("GSMReceive");
37 device = sbus.get_object(
38 "org.freesmartphone.ogsmd",
39 "/org/freesmartphone/GSM/Device",
40 "org.freesmartphone.GSM.Device");
42 network = sbus.get_object(
43 "org.freesmartphone.ogsmd",
44 "/org/freesmartphone/GSM/Device",
45 "org.freesmartphone.GSM.Network");
47 call = sbus.get_object(
48 "org.freesmartphone.ogsmd",
49 "/org/freesmartphone/GSM/Device",
50 "org.freesmartphone.GSM.Call");
52 stderr.printf("Antenna is %s\n", device.GetAntennaPower() ? "on" : "off");
53 stderr.printf("Signal strength: %d\n", network.GetSignalStrength());
54 stderr.printf("Calling identification: %s\n", network.GetCallingIdentification());
56 network.Status += on_network_Status;
57 network.SignalStrength += on_network_SignalStrength;
58 call.CallStatus += on_call_Status;
61 public void shutdown()
63 //zavai.gsm.gsm.release("GSMReceive");
66 public void on_network_SignalStrength(DBus.Object sender, int strength)
68 stderr.printf("SIGNAL STRENGTH %d\n", strength);
71 public void on_network_Status(DBus.Object sender, HashTable<string, Value?> status)
73 stderr.printf("NETWORK STATUS\n");
75 // dbg("cbNetworkStatus %s" % formatDict(status))
78 public void on_call_Status(DBus.Object sender, int index, string status, HashTable<string, Value?> properties)
80 stderr.printf("CALL STATUS %d %s\n", index, status);
82 dbg("cbCallStatus %d, %s, %s" % (id, status, formatDict(properties)))
84 if status == "incoming":
85 if "peer" in properties and properties["peer"] == "+358942832031":
86 self.gsm_call_iface.ReleaseAll()
87 os.system("kapula-debug-call-handler &")
89 os.system("alsactl restore -f /etc/alsa-scenarios/stereoout-maxvolume.state")
90 os.system("vibrator-start")
91 os.system("ringtone-start")
92 os.system("ledctrl --on-time 400 --off-time 200 gta02-aux:red");
93 if status == "release":
94 os.system("ringtone-stop")
95 os.system("vibrator-stop")
96 os.system("ledctrl --off gta02-aux:red");
102 def onIncomingUssd( self, mode, message ):
103 logger.info( "USSD Message: %s" % message )
104 self.main.groups["alert"].activate( "<title>Operator Message</title>%s" % message, [("OK")] )
105 def onCallStatus( self, id, status, properties ):
107 self.update_status(status)
108 if not status in ["release"]:
109 if "peer" in properties:
110 self.part_text_set( "label", self.main.groups["contacts"].tryNumberToName( properties[ "peer" ] ) )
111 self.part_text_set( "sublabel", properties[ "peer" ] )
113 self.part_text_set( "label", _("unknown number") )
114 self.part_text_set( "sublabel", "" )
116 @edje.decorators.signal_callback( "mouse,clicked,1", "button_*" )
117 def on_edje_signal_dialer_button_pressed(self, emission, source):
118 key = source.split("_", 1)[1]
119 if key in ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"):
120 dbus_object.gsm_call_iface.SendDtmf( key )
121 self.text.append(key)
123 dbus_object.gsm_call_iface.SendDtmf( "*" )
124 self.text.append("*")
126 dbus_object.gsm_call_iface.SendDtmf( "#" )
128 # The trailing whitespace is a workaround for the one char invisible
129 # bug due to some problems with scaling of text parts.
130 self.part_text_set("label", "".join(self.text)+" ")
132 @edje.decorators.signal_callback("call_button_pressed", "button_right")
133 def on_edje_signal_call_button_right_pressed(self, emission, source):
134 self.main.transition_to("call")
136 def sendMessage( self, index ):
137 logger.info( "trying to send message w/ index %d..." % index )
138 dbus_object.gsm_sim_iface.SendStoredMessage( index, reply_handler=self.cbSendReply, error_handler=self.cbSendError )
140 def cbSendReply( self, reference, timestamp ):
141 logger.info( "sent message successfully w/ reference number %d (timestamp: %s)" % ( reference, timestamp ) )
143 def cbSendError( self, e ):
144 logger.error( "could not send message. leaving in outgoing. error was: %s" % e )
146 def cbStoreReply( self, result ):
147 logger.info( "stored message lives at SIM position %d" % result )
148 self.sendMessage( result )
150 dbus_object.gsm_sim_iface.RetrieveMessagebook(
152 reply_handler=self.cbMessagebookReply,
153 error_handler=self.cbMessagebookError
157 def cbStoreError( self, e ):
158 logger.warning( "error while storing message - %s" % e.get_dbus_name() )
159 if e.get_dbus_name() == "org.freesmartphone.GSM.SIM.MemoryFull":
160 self.main.groups["alert"].activate( "<title>Failed to send message</title>SIM Memory Full", [("OK")] )
162 def cbSend1( self, selected, cb_data ):
163 self.main.groups["text_edit"].setup(
167 selected[1], # reference
171 def cbSend2( self, text, number ):
172 if dbus_object.gsm_device_obj:
173 dbus_object.gsm_sim_iface.StoreMessage(
175 reply_handler=self.cbStoreReply,
176 error_handler=self.cbStoreError
179 def cbDelete( self, result, reference ):
180 if result == "abort":
182 if dbus_object.gsm_device_obj:
183 dbus_object.gsm_sim_iface.DeleteMessage(
186 for i in range( len( self.messagebook ) ):
187 if self.messagebook[i][0] == reference:
188 del self.messagebook[i]
192 def cbForward( self, selected, text ):
193 if dbus_object.gsm_device_obj:
194 dbus_object.gsm_sim_iface.StoreMessage(
195 selected[1], text, {},
196 reply_handler=self.cbStoreReply,
197 error_handler=self.cbStoreError
200 def cbReply( self, text, number):
201 if dbus_object.gsm_device_obj:
202 dbus_object.gsm_sim_iface.StoreMessage(
204 reply_handler=self.cbStoreReply,
205 error_handler=self.cbStoreError
208 def cbMenu( self, result ):
209 if result == _("send"):
210 self.main.groups["contacts"].prepare()
211 if self.main.groups["contacts"].ready:
212 self.main.groups["list_choose"].setup(
214 [ (x[1], x[2]) for x in self.main.groups["contacts"].phonebook],
218 elif result == _("delete"):
219 self.main.groups["alert"].activate(
221 (_("abort"), _("delete")),
222 self.current[self.selected][0], # reference
225 elif result == _("forward"):
226 self.main.groups["contacts"].prepare()
227 if self.main.groups["contacts"].ready:
228 self.main.groups["list_choose"].setup(
230 [ (x[1], x[2] ) for x in self.main.groups["contacts"].phonebook],
231 self.current[self.selected][3],
234 elif result == _("reply"):
235 self.main.groups["text_edit"].setup(
238 self.current[self.selected][2], # title = number
239 self.current[self.selected][2], # reference = number
243 def cbMessagebookReply( self, result ):
244 logger.info( "retrieved messagebook: %s" % result )
246 self.messagebook = result
249 self.main.groups["main"].targets["sms"] = True
250 self.main.groups["main"].update()
251 if not self.newindex is None:
252 message = [x for x in self.messagebook if x[0] == self.newindex]
254 if message and self.main.current_group == self.main.groups["main"]:
256 if "read" in message[1]:
258 timestamp = message[4]["timestamp"]
261 timestamp = _("Unknown")
262 from_text = self.main.groups["contacts"].tryNumberToName( message[2] )
263 self.main.groups["text_show"].setup(
265 _("%s: %s<br>Date: %s<p>%s") % (
269 textblock_escape( message[3] ).replace( '\n', '<br>' )
272 if dbus_object.gsm_device_obj:
273 messagebookInfo = dbus_object.gsm_sim_iface.GetMessagebookInfo()
274 if messagebookInfo["used"] == messagebookInfo["last"]:
275 self.main.groups["alert"].activate( "<title>Warning</title>SIM Memory Full", [("OK")] )
277 def cbMessagebookError( self, e ):
278 logger.warning( "error while retrieving messagebook" )
281 def onIncomingMessage( self, index ):
282 logger.info( "new message! Retrieving messagebook..." )
283 self.newindex = index
285 dbus_object.gsm_sim_iface.RetrieveMessagebook(
287 reply_handler=self.cbMessagebookReply,
288 error_handler=self.cbMessagebookError
293 if not self.ready and not self.busy:
294 if dbus_object.gsm_device_obj:
295 logger.info( "retrieving messagebook..." )
296 dbus_object.gsm_sim_iface.RetrieveMessagebook(
298 reply_handler=self.cbMessagebookReply,
299 error_handler=self.cbMessagebookError
303 # Fake messagebook...
304 self.cbMessagebookReply( [
305 (0, "read", "+4544555", "Hello World!"),
306 (1, "read", "+456663443", "Zhone!"),
307 (2, "read", "+456663443", "Hi Guy\nGuess what, I now "+
308 "know to write multi-line SMSs.\nIsn't that "+
309 "nice?\n\nSome Buddy"),
310 (3, "read", "Flash SMS", "An SMS without digits. Strange, isn't it?"),
313 def onReadyStatus( self, status ):
314 logger.debug( "SIM is ready: %s" % status )
324 def updateList( self):
325 self.main.groups["contacts"].prepare()
326 self.pages = max( ( len( self.messagebook ) - 1 ) / 6 + 1, 1 )
327 if self.page >= self.pages:
328 self.page = self.pages - 1
331 self.current = self.messagebook[self.page*6:(self.page+1)*6]
332 text = u"".join( [u"□"]*self.page+[u"▣"]+[u"□"]*(self.pages-self.page-1) )
333 self.part_text_set( "pager", text )
334 for i in range( 0, len( self.current ) ):
335 main_text = self.main.groups["contacts"].tryNumberToName( self.current[i][2] )
336 self.part_text_set( "label_main_list_%i" % i, main_text )
337 sub_text = " ".join(self.current[i][3].splitlines())
338 self.part_text_set( "label_sub_list_%i" % i, u"(%s) %s" % ( self.current[i][1], sub_text ) )
339 for i in range( len( self.current ), 6):
340 self.part_text_set( "label_main_list_%i" % i, u"" )
341 self.part_text_set( "label_sub_list_%i" % i, u"" )
344 self.signal_emit( "deactivate_target_list_%i" % i, "" )
347 @edje.decorators.signal_callback( "mouse,clicked,1", "target_list_*" )
348 def on_edje_signal_button_list_pressed( self, emission, source ):
349 id = int( source.split( "_" )[-1] )
350 if self.selected == id:
352 if self.selected is not None:
353 self.signal_emit( "deactivate_target_list_%i" % self.selected, "" )
354 self.signal_emit( "activate_target_list_%i" % id, "" )
357 @edje.decorators.signal_callback( "mouse,clicked,1", "button_action_left" )
358 def on_edje_signal_button_action_left_pressed( self, emission, source ):
362 @edje.decorators.signal_callback( "mouse,clicked,1", "button_action_right" )
363 def on_edje_signal_button_action_right_pressed( self, emission, source ):
367 @edje.decorators.signal_callback( "mouse,clicked,1", "button_action_open" )
368 def on_edje_signal_button_action_open_pressed( self, emission, source ):
369 if self.selected is not None:
370 if "read" in self.current[self.selected][1]:
372 timestamp = self.current[self.selected][4]["timestamp"]
375 timestamp = _("Unknown")
376 from_text = self.main.groups["contacts"].tryNumberToName( self.current[self.selected][2] )
377 self.main.groups["text_show"].setup(
379 _("%s: %s<br>Date: %s<p>%s") % (
383 textblock_escape( self.current[self.selected][3] ).replace( '\n', '<br>' )
387 @edje.decorators.signal_callback( "mouse,clicked,1", "button_bottom_middle" )
388 def on_edje_signal_button_bottom_middle_pressed( self, emission, source ):
389 self.main.groups["menu"].activate( ( _("send"), _("delete"), _("forward"), _("reply") ), self.cbMenu )
390 self.main.groups["menu"].part_text_set( "target_label_cancel", _("cancel") )
394 static int main (string[] args) {
396 // Gst.init (ref args);
399 sbus = DBus.Bus.get(DBus.BusType.SYSTEM);
401 // Core infrastructure
402 // zavai.config = new zavai.Config();
403 // zavai.config.argv0 = args[0];
404 // zavai.registry = new zavai.Registry();
406 // Additional infrastructure
411 var gr = new GSMReceive();
415 // zavai.info("Shutting down")
416 // zavai.registry.shutdown();