~kamstrup/zeitgeist/query-expansion

« back to all changes in this revision

Viewing changes to _zeitgeist/loggers/datasources/recent.py

  • Committer: Siegfried-Angel Gevatter Pujals
  • Date: 2010-01-21 14:57:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1323.
  • Revision ID: rainct@ubuntu.com-20100121145723-i7mdzuxi8ch699m8
And more stuff...

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
from zeitgeist import _config
34
34
from zeitgeist.datamodel import Event, Subject, Interpretation, Manifestation, \
35
 
        get_timestamp_for_now
 
35
        DataSource, get_timestamp_for_now
36
36
from _zeitgeist.loggers.zeitgeist_base import DataProvider
37
37
 
38
38
log = logging.getLogger("zeitgeist.logger.datasources.recent")
199
199
                u"SourceCode": MimeTypeSet(*DEVELOPMENT_MIMETYPES),
200
200
        }
201
201
        
202
 
        def __init__(self):
203
 
                DataProvider.__init__(self, name="Recently Used Documents")
 
202
        def __init__(self, client):
 
203
                DataProvider.__init__(self,
 
204
                        name="Recently Used Documents",
 
205
                        description="Logs events from GtkRecentlyUsed",
 
206
                        event_templates=[],
 
207
                        client=client)
 
208
                self._load_data_sources()
204
209
                self.recent_manager = recent_manager()
205
210
                self.recent_manager.set_limit(-1)
206
211
                self.recent_manager.connect("changed", lambda m: self.emit("reload"))
207
212
                self.config.connect("configured", lambda m: self.emit("reload"))
208
 
                self._timestamp_last_run = 0
 
213
                self._timestamp_last_run = 0 # FIXME: Get this from Zeitgeist's registry
 
214
        
 
215
        def _load_data_sources(self):
 
216
                ignore_apps = set()
 
217
                for source in self._registry.GetDataSources():
 
218
                        for tmpl in source[DataSource.EventTemplates]:
 
219
                                # TODO: Check whether the data-source is currently running
 
220
                                if tmpl[0][Event.Actor]:
 
221
                                        # TODO: Check for event types and only exclude those
 
222
                                        # types which are provided by the source, not all the actor
 
223
                                        ignore_apps.add(tmpl[0][Event.Actor])
 
224
                self._ignore_apps = ignore_apps
209
225
        
210
226
        @staticmethod
211
227
        def _find_desktop_file_for_application(application):
245
261
                
246
262
                for (num, info) in enumerate(self.recent_manager.get_items()):
247
263
                        if info.exists() and not info.get_private_hint() and not info.get_uri_display().startswith("/tmp/"):
 
264
                                last_application = info.last_application().strip()
 
265
                                application = info.get_application_info(last_application)[0].split()[0]
 
266
                                desktopfile = self._find_desktop_file_for_application(application)
 
267
                                if not desktopfile:
 
268
                                        continue
 
269
                                actor = u"application://%s" % os.path.basename(desktopfile)
 
270
                                
 
271
                                if actor in self._ignore_apps:
 
272
                                        # Do not insert duplicated events when the actor already
 
273
                                        # has a responsible data-source
 
274
                                        continue
 
275
                                
248
276
                                subject = Subject.new_for_values(
249
277
                                        uri = unicode(info.get_uri()),
250
278
                                        interpretation = self._get_interpretation_for_mimetype(
255
283
                                        origin = info.get_uri().rpartition("/")[0]
256
284
                                )
257
285
                                
258
 
                                last_application = info.last_application().strip()
259
 
                                application = info.get_application_info(last_application)[0].split()[0]
260
 
                                desktopfile = self._find_desktop_file_for_application(application)
261
286
                                times = (
262
287
                                        (info.get_added() * 1000, Interpretation.CREATE_EVENT.uri),
263
288
                                        (info.get_visited() * 1000, Interpretation.VISIT_EVENT.uri),
273
298
                                                timestamp = timestamp,
274
299
                                                interpretation = use,
275
300
                                                manifestation = Manifestation.USER_ACTIVITY.uri,
276
 
                                                actor = desktopfile or u"",
 
301
                                                actor = actor,
277
302
                                                subjects = [subject]
278
303
                                                ))
279
304
                        if num % 50 == 0:
282
307
                return events
283
308
 
284
309
if enabled:
285
 
        __datasource__ = RecentlyUsedManagerGtk()
 
310
        __datasource__ = RecentlyUsedManagerGtk