~davidc3/unity-lens-photos/dummy-db

« back to all changes in this revision

Viewing changes to src/shotwell_scope.py

  • Committer: David Callé
  • Date: 2012-09-11 12:29:10 UTC
  • Revision ID: davidc@framli.eu-20120911122910-c0ocvh9avd34kd46
Add a cancellable flag for Shotwell search

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
        lens.add_local_scope (self._scope)
60
60
        self.tagdb = []
61
61
        self.db = None
 
62
        self.cancel_running_search = False
62
63
 
63
64
 
64
65
    def on_filtering_changed(self, *_):
87
88
        model = search.props.results_model
88
89
        search.set_reply_hint ("no-results-hint", GLib.Variant.new_string(NO_RESULTS_HINT))
89
90
        model.clear()
 
91
        self.cancel_running_search = True
90
92
        search_string = search.props.search_string.strip()
91
93
#        print ("Search changed to \"%s\"" % search_string)
92
94
 
96
98
                if len(search_string) > 0:
97
99
                    print ("Search changed to \"%s\"" % search_string)
98
100
                    cats = [4]
99
 
                    self.update_results_model(search_string, model, cats, date, search)
 
101
                    GLib.idle_add(self.update_results_model,search_string, model, cats, date, search)
100
102
                else:
101
103
                    search.finished()
102
104
            else:
104
106
                    cats = [1]
105
107
                else:
106
108
                    cats = [0,1]
107
 
                self.update_results_model(search_string, model, cats, date, search)
 
109
                GLib.idle_add(self.update_results_model,search_string, model, cats, date, search)
108
110
        else:
109
111
            search.finished()
 
112
        
110
113
 
111
114
 
112
115
    def update_results_model(self, search, model, cats, date, s):
117
120
            else:
118
121
                limit = 100
119
122
            for i in self.shotwell(search, date, limit):
120
 
                hex_id = "%x" % i[4]
121
 
                thumb_id = ("thumb" + "0"*(16 - len(hex_id)) + hex_id)
122
 
                try:
123
 
                    extension = i[1].split('.')[-1].lower ()
124
 
                except:
125
 
                    extension = "jpg"
126
 
                icon_hint = THUMB_CACHE + "thumbs128/" + thumb_id + "." + extension
127
 
                if not self.is_file (icon_hint):
128
 
                    icon_hint = THUMB_CACHE + "thumbs360/" + thumb_id + "." + extension
 
123
                if not self.cancel_running_search:
 
124
                    hex_id = "%x" % i[4]
 
125
                    thumb_id = ("thumb" + "0"*(16 - len(hex_id)) + hex_id)
 
126
                    try:
 
127
                        extension = i[1].split('.')[-1].lower ()
 
128
                    except:
 
129
                        extension = "jpg"
 
130
                    icon_hint = THUMB_CACHE + "thumbs128/" + thumb_id + "." + extension
129
131
                    if not self.is_file (icon_hint):
130
 
                        icon_hint = "image"
131
 
                title = i[0]
132
 
                comment = i[3]
133
 
                uri = "file://"+i[1]
134
 
                model.append (uri, icon_hint, cat,"text/html", title, comment, uri)
 
132
                        icon_hint = THUMB_CACHE + "thumbs360/" + thumb_id + "." + extension
 
133
                        if not self.is_file (icon_hint):
 
134
                            icon_hint = "image"
 
135
                    title = i[0]
 
136
                    comment = i[3]
 
137
                    uri = "file://"+i[1]
 
138
                    model.append (uri, icon_hint, cat,"text/html", title, comment, uri)
135
139
        s.finished ()
136
140
 
137
141
 
267
271
        data_list = []
268
272
        db = self.getDB ()
269
273
        eventcursor = db.cursor()
 
274
        
270
275
        if db:
 
276
            self.cancel_running_search = False
271
277
            try:
272
278
                photos = self.getPhotos (db, date)
273
279
            except:
274
280
                photos = []
275
281
            i = 0
276
282
            for photo in photos:
277
 
                if photo[16] != 4 and photo[16] != 8:
 
283
                if photo[16] != 4 and photo[16] != 8 and not self.cancel_running_search:
278
284
                    item_list = []
279
285
                    event_id = str(photo[10])
280
286
                    uri = photo[1]
281
287
                    pid = photo[0]
282
 
#                    try:
283
 
#                        tags = self.getTagsForPhotoId (db, pid, tagscursor)
284
 
#                    except:
285
 
#                        tags = ""
286
288
                    try:
287
289
                        event = self.getEventNameForEventId (db, event_id, eventcursor)
288
290
                    except: