~khurshid-alam/unity-scope-firefoxbookmarks/fix-build-disco

« back to all changes in this revision

Viewing changes to src/unity_firefoxbookmarks_daemon.py

  • Committer: Mark Tully
  • Date: 2013-04-22 15:16:56 UTC
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: markjtully@gmail.com-20130422151656-frcctk5gxchivmjn
Fixed up activation & added a test

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
DEFAULT_RESULT_ICON = 'gtk-about'
39
39
DEFAULT_RESULT_MIMETYPE = 'text/html'
40
40
DEFAULT_RESULT_TYPE = Unity.ResultType.DEFAULT
 
41
FIREFOX_EXECUTABLE = '/usr/bin/firefox'
41
42
BOOKMARKS_PATH = os.getenv("HOME") + "/.mozilla/firefox/"
42
43
BOOKMARKS_QUERY = '''SELECT moz_bookmarks.title, moz_places.url, moz_favicons.url, '%s'
43
44
                     FROM moz_bookmarks, moz_places, moz_favicons
78
79
                file_name, profile_name = os.path.splitext(filename)
79
80
                profile_name = profile_name[1:]
80
81
                sqlite_query = BOOKMARKS_QUERY % (profile_name, search, search)
81
 
    
 
82
 
82
83
                conn = sqlite3.connect(dbfile)
83
84
                connection = conn.cursor()
84
85
                connection.execute(sqlite_query)
107
108
                        'category': 0,
108
109
                        'title': bookmark[0],
109
110
                        'comment': bookmark[1],
110
 
                        'user':GLib.Variant('s', bookmark[3])})
 
111
                        'user': GLib.Variant('s', bookmark[3])})
111
112
    return results
112
113
 
113
114
 
114
 
def activate(scope, uri):
 
115
def activate(result, metadata, id):
115
116
    '''
116
117
    Open the url in the default webbrowser
117
118
    Args:
118
119
      uri: The url to be opened
119
120
    '''
120
 
    webbrowser.open(uri)
121
 
    return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri='')
 
121
    parameters = [FIREFOX_EXECUTABLE, result.uri]
 
122
    GLib.spawn_async(parameters)
 
123
    return Unity.ActivationResponse(handled=Unity.HandledType.HIDE_DASH, goto_uri=None)
122
124
 
123
125
 
124
126
# Classes below this point establish communication
154
156
                    i['comment'] = ''
155
157
                if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
156
158
                    i['dnd_uri'] = i['uri']
157
 
                i['metadata'] = {}
158
 
                if EXTRA_METADATA:
159
 
                    for e in i:
160
 
                        for m in EXTRA_METADATA:
161
 
                            if m['id'] == e:
162
 
                                i['metadata'][e] = i[e]
163
 
                i['metadata']['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
164
 
                result = Unity.ScopeResult.create(str(i['uri']), str(i['icon']),
165
 
                                                  i['category'], i['result_type'],
166
 
                                                  str(i['mimetype']), str(i['title']),
167
 
                                                  str(i['comment']), str(i['dnd_uri']),
168
 
                                                  i['metadata'])
169
 
                result_set.add_result(result)
 
159
                i['provider_credits'] = GLib.Variant('s', PROVIDER_CREDITS)
 
160
                result_set.add_result(**i)
170
161
        except Exception as error:
171
162
            print(error)
172
163
 
222
213
        se = MySearch(search_context)
223
214
        return se
224
215
 
 
216
    def do_activate(self, result, metadata, id):
 
217
        return activate(result, metadata, id)
 
218
 
225
219
 
226
220
def load_scope():
227
221
    return Scope()