Ubuntu Pastebin

Paste from Nick Dedekind at Mon, 15 Dec 2014 16:15:33 +0000

Download as text
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 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
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
#  Copyright 2013 Canonical Ltd.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; version 3.
#
#  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 Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#  Authors:
#       Bill Filler
#       Renato Araujo Oliveira Filho <renato@canonical.com>

from gi.repository import GLib, Gio, MessagingMenu
import subprocess
import os
import sys
import time

def _getImagePrefix():
    DATA_PATHS = ['/usr/local/share/chewie/examples/data/',
                  '/usr/share/chewie/examples/data/',
                  os.path.dirname(os.path.realpath(sys.argv[0])) + '/data/',
                  os.getcwd() + '/data/']

    for path in DATA_PATHS:
        if os.path.exists(path):
            return path

    return './'

predefined_messages = GLib.Variant('as', ['I missed your call - can you call me now?',
                                          'I\'m running late. I\'m on my way.',
                                          'I\'m busy at the moment. I\'ll call later.',
                                          'I\'ll be 20 minutes late.',
                                          'Sorry. I\'m still busy. I\'ll call you later.'])
IMAGE_PREFIX = _getImagePrefix()

def sms_activated(msg, action, param):
  print 'sms activated %s - %s -%s' % (msg.get_id(), action, param)
  return True

def call_activated(msg, action, param):
  print 'call activated %s - %s -%s' % (msg.get_id(), action, param)
  return True

def facebook_activated(msg, action, param):
  print 'facebook activated %s - %s -%s' % (msg.get_id(), action, param)
  return True

def email_activated(msg, action, param):
  print 'email activted %s - %s -%s' % (msg.get_id(), action, param)
  return True

textMsg = MessagingMenu.App(desktop_id='dialer-app.desktop')
textMsg.register()

phoneCall = MessagingMenu.App(desktop_id='unity8.desktop')
phoneCall.register()

facebook = MessagingMenu.App(desktop_id='signon-ui.desktop')
facebook.register()

email = MessagingMenu.App(desktop_id='webbrowser-app.desktop')
email.register()

TEXT_MSG = [ textMsg, sms_activated]
PHONE_CALL = [ phoneCall, call_activated]
FACEBOOK_MSG = [ facebook, facebook_activated]
EMAIL_MSG = [ email, email_activated]

the_messages = [
    {
        'type' : PHONE_CALL,
        'title' : 'Renato Araujo',
        'subject' : '07714 610987',
        'body' : '1 missed call',
        'icon' : IMAGE_PREFIX + 'renato.jpg',
        'dayOffset' : -20 ,
        'time' : "12:28",
        'actions' : [ ('call', 'Call back', None, None), ('message', 'Send', GLib.VariantType.new ('s'), predefined_messages) ],
        },
    {
        'type' : FACEBOOK_MSG,
        'title' : 'Ellen Arnold',
        'subject' : '',
        'body' : 'I posted the pictures of the trip! Enjoy them :)',
        'icon' : IMAGE_PREFIX + 'ellen_arnold.jpg',
        'dayOffset' : -5 ,
        'time' : "12:46",
        'actions' : [ ('send', 'Send', GLib.VariantType.new ('s'), None) ],
        },
    {
        'type' : EMAIL_MSG,
        'title' : 'Renato Araujo',
        'subject' : 'Birthday Gift',
        'body' : "Hi Lola, I am in the Eastmeadow shopping for Peter birthday. I show a book that he may like it. However, it is a 15 pounds over our budget. I do not if I should buy it or not. Help! :) See you later",
        'icon' : IMAGE_PREFIX + 'renato.jpg',
        'dayOffset' : -2 ,
        'time' : "12:46",
        'actions' : [ ('send', 'Send', GLib.VariantType.new ('s'), None) ],
        },
    {
        'type' : FACEBOOK_MSG,
        'title': 'Xi Zhu',
        'subject': '',
        'body' : "You girls had a good time!",
        'icon' : IMAGE_PREFIX + 'xi_zhu.jpg',
        'dayOffset' : -1,
        'time' : "13:12",
        'actions' : [ ('send', 'Send', GLib.VariantType.new ('s'), None) ],
        },
    {
        'type' : FACEBOOK_MSG,
        'title': 'Florian Boucault',
        'subject': '',
        'body' : "Have you seen P. Sam's comment on twitter? Check it out. Hilarious :)!!",
        'icon' : IMAGE_PREFIX + 'florian.jpg',
        'dayOffset' : 0 ,
        'time' : "17:36",
        'actions' : [ ('send', 'Send', GLib.VariantType.new ('s'), None) ],
        },
    {
        'type' : EMAIL_MSG,
        'title': 'Katie Taylor',
        'subject': 'Dinner with Mara',
        'body' : "Hello Lola, Guess who I ran into yesterday? Mara from high school. We were in a rush but we are metting tomorrow for dinner.  Would be great to catch up the three of us! See you, Hugs",
        'icon' : IMAGE_PREFIX + 'katie_taylor.jpg',
        'dayOffset' : 1 ,
        'time' : "20:03",
        'actions' : [ ('send', 'Send', GLib.VariantType.new ('s'), None) ],
        },
    {
        'type' : FACEBOOK_MSG,
        'title' : 'Ricardo Mendoza',
        'subject' : '',
        'body' : "I am going to arrive late at the party, please do not wait for me. I hope to leave asap. X",
        'icon' : IMAGE_PREFIX + 'ricardo_mendoza.jpg',
        'dayOffset' : 2 ,
        'time' : "10:34",
        'actions' : [ ('send', 'Send', GLib.VariantType.new ('s'), None) ],
        },
    {
        'type' : PHONE_CALL,
        'title': 'Ricardo Salveti',
        'subject': '7791275277',
        'body' : '1 missed call',
        'icon' : IMAGE_PREFIX + 'rsalveti.jpg',
        'dayOffset' : 5 ,
        'time' : "11:32",
        'actions' : [ ('call', 'Call back', None, None), ('message', 'Send', GLib.VariantType.new ('s'), predefined_messages) ],
        },
    {
        'type' : PHONE_CALL,
        'title' : 'Renato Araujo',
        'subject' : '07714 610987',
        'body' : '1 missed call',
        'icon' : IMAGE_PREFIX + 'renato.jpg',
        'dayOffset' : -20 ,
        'time' : "12:28",
        'actions' : [ ('call', 'Call back', None, None), ('message', 'Send', GLib.VariantType.new ('s'), predefined_messages) ],
        }
    ]

def run_phone_app():
    subprocess.call(['/usr/bin/phone-app', '--fullscreen'])

def calculate_date(currentDay, dayOffset, timeStr):
    prevDay = currentDay.add_days(dayOffset)
    hour, min = timeStr.split(':')
    newDate = GLib.DateTime.new_local(prevDay.get_year(), prevDay.get_month(), prevDay.get_day_of_month(), int(hour), int(min), 0)
    return newDate.to_unix() * 1000000

def pushMessages ():
    current = GLib.DateTime.new_now_local();
    for (i, m) in enumerate(the_messages, start=1):
        msgType = m['type'];
#        msg = MessagingMenu.Message.new('msg-%d' % i, Gio.Icon.new_for_string(m['icon']), m['title'], m['subject'], m['body'], calculate_date(current, m['dayOffset'], m['time']))
        msg = MessagingMenu.Message.new('msg-%d' % i, None, m['title'], m['subject'], m['body'], calculate_date(current, m['dayOffset'], m['time']))
        msg.connect('activate', msgType[1])
        for act in m['actions']:
            msg.add_action(act[0], act[1], act[2], act[3])
        msgType[0].append_message (msg, None, False)

# push all of the messages to the menu
pushMessages()

GLib.MainLoop().run()
Download as text