Check-in [9a8c5118a6]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added copyright notice
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:9a8c5118a648ed4164fccf269b7aaf6c9448fa55
User & Date: gwlester 2016-05-31 19:23:22
Context
2016-05-31
19:23
Added copyright notice Leaf check-in: 9a8c5118a6 user: gwlester tags: trunk
2016-05-30
19:13
Add comments check-in: 7ac59f698c user: gwlester tags: trunk
Changes

Changes to ReadMessages.tcl.

14
15
16
17
18
19
20












































21
22

23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
272
273
274
275
276
277
278
279


280
281
282
283
284
285
286
287













































































































































288
289
290
291
292
293
294
#  To Do List:                                                                 #
#       - Get the marking of the SMS as viewed working                         #
#       - Replace the polling with receipt of notification                     #
#       - Replace hard coded messages with a message catalog to make it easier #
#           to localize the code                                               #
#                                                                              #
################################################################################












































package require uri::urn
package require sqlite3



array set content {
    sms,uri {content://sms/inbox}
    phonelookup,uri {content://com.android.contacts/phone_lookup}
}

set processingMessages no
set promptFmt {You have a new message from %1$s. Do you want me to read it to you?}

##
## The viewed array is a to remember what we have seen and will go away when the
## update of the "seen" column is working
##
array set viewed {}

................................................................................
            set input [lindex $recog(results_recognition) 0]
            if {[string is boolean -strict $input]} {
                set answer $input
            } else {
                ##
                ## Not a valid response, so ask them to try again.
                ##
                speak {I'm sorry, I did not understand.  Please say yes or no.}
            }
	}
	default {
	    return
	}
    }
}
................................................................................
    return;
}

##
## Schedule another poll a minue later
##
proc check {} {
    after 60000 check


    if {!$::processingMessages} {
        ##
        ## Not currently processing messages, so process them
        ##
        processNewMessages
    }
}














































































































































##
## Register the speach recognition handler
##
borg speechrecognition callback processInputText

##
## Create the GUI







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>

>






<







 







|







 







|
>
>








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#  To Do List:                                                                 #
#       - Get the marking of the SMS as viewed working                         #
#       - Replace the polling with receipt of notification                     #
#       - Replace hard coded messages with a message catalog to make it easier #
#           to localize the code                                               #
#                                                                              #
################################################################################

################################################################################
################################################################################
# This software is copyrighted by the KnG Consulting, LLC and Gerald W. Lester.
# The following terms apply to all files associated with the software unless
# explicitly disclaimed in individual files.
#
# The authors hereby grant permission to use, copy, modify, distribute,
# and license this software and its documentation for any purpose, provided
# that existing copyright notices are retained in all copies and that this
# notice is included verbatim in any distributions. No written agreement,
# license, or royalty fee is required for any of the authorized uses.
# Modifications to this software may be copyrighted by their authors
# and need not follow the licensing terms described here, provided that
# the new terms are clearly indicated on the first page of each file where
# they apply.
#
# IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
# DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE
# IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
# NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# MODIFICATIONS.
#
# GOVERNMENT USE: If you are acquiring this software on behalf of the
# U.S. government, the Government shall have only "Restricted Rights"
# in the software and related documentation as defined in the Federal
# Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
# are acquiring the software on behalf of the Department of Defense, the
# software shall be classified as "Commercial Computer Software" and the
# Government shall have only "Restricted Rights" as defined in Clause
# 252.227-7014 (b) (3) of DFARs.  Notwithstanding the foregoing, the
# authors grant the U.S. Government and others acting in its behalf
# permission to use and distribute the software in accordance with the
# terms specified in this license.
################################################################################
################################################################################

package require uri::urn
package require sqlite3
package require msgcat

set settings(checkInterval) 1000
array set content {
    sms,uri {content://sms/inbox}
    phonelookup,uri {content://com.android.contacts/phone_lookup}
}

set processingMessages no


##
## The viewed array is a to remember what we have seen and will go away when the
## update of the "seen" column is working
##
array set viewed {}

................................................................................
            set input [lindex $recog(results_recognition) 0]
            if {[string is boolean -strict $input]} {
                set answer $input
            } else {
                ##
                ## Not a valid response, so ask them to try again.
                ##
                speak [::msgcat::mc msg_03]
            }
	}
	default {
	    return
	}
    }
}
................................................................................
    return;
}

##
## Schedule another poll a minue later
##
proc check {} {
    global settings

    after $settings(checkInterval) check
    if {!$::processingMessages} {
        ##
        ## Not currently processing messages, so process them
        ##
        processNewMessages
    }
}

##
## Open DB
##
proc openDb {fileName} {
    sqlite3 DB $filename

    return DB
}

##
## Create the DB with our messages in them
##
proc createDb {} {
    DB eval {
        create table setting (
            isDefault       INTEGER,
            settingName     TEXT,
            settingValue    TEXT
        )
    }
    DB eval {
        create table msgcat (
            msgLocale   TEXT,
            msgId       TEXT,
            msgValue    TEXT
        )
    }
    DB eval {
        create view getSettings (
            settingName,
            settingValue
        ) as
        select  settingName,
                settingValue
            from setting
            where isDefault = 0
        union
        select  a.settingName,
                a.settingValue
            from setting a
            where isDefault = 1
              and not exists (
                select 1 from setting b where b.settingName = .settingName and b.isDefault <> 1
              )
    }
    DB eval {
        create view getMsgcat (
            msgLocale,
            msgId,
            msgValue
        ) as
        select msgLocale, msgId, msgValue
           from msgcat
        union
        select 'C', msgId, msgValue
           from msgcat
           where msgLocale is null
    }
    DB eval {
        insert into setting ( isDefault, settingName, settingValue)
            values ( 1, 'checkInterval', '1000')
    }
    DB eval {
        insert into msgcat ( msgId, msgValue)
            values ( 'msg_01', 'You have a new message from')
    }
    DB eval {
        insert into msgcat ( msgId, msgValue)
            values ( 'msg_02', 'Do you want me to read it to you?')
    }
    DB eval {
        insert into msgcat ( msgId, msgValue)
            values ( 'msg_03', 'I''m sorry, I did not understand.  Please say yes or no.')
    }
{%1$s. Do you want me to read it to you?}

    return
}

##
## Load the settings from the DB
##
proc loadSettings {} {
    global settings

    DB eval {select settingName, settingValue from getMsgcat} rowArray {
        set settings($rowArray(settingName)) $rowArray(settingValue)
    }

    return;
}

##
## Load the messages  from the DB
##
proc loadMsgcat {} {

    DB eval {select msgLocale, msgId, msgValue from getSettings} rowArray {
        ::msgcat::mcset $rowArray(rowArray) $rowArray(msgId) $rowArray(msgValue)
    }

    return;
}

##
## Load the messages and settings from the DB
##
proc loadDb {} {
    global env
    global settings

    set fn [file join $env(INTERNAL_STORAGE) ReadMessages.db3]
    if {![file exists $fn]} {
        openDb $gn
        createDb
    } else {
        openDb $gn
    }

    loadSettings
    loadMsgcat

    DB closeƟ

    return;
}

##
## Save a custom message/traslation to the DB
##
proc saveMessage {mdsId text} {

}

##
## Load the messages from the DB
##
loadDb
set promptFmt {}
append promptFmt  [::msgcat::mc msg_01] " %1$s.  " [::msgcat::mc msg_02]

##
## Register the speach recognition handler
##
borg speechrecognition callback processInputText

##
## Create the GUI