2009-06-16 16:20:12 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
|
|
|
const Clutter = imports.gi.Clutter;
|
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Gtk = imports.gi.Gtk;
|
|
|
|
const Shell = imports.gi.Shell;
|
|
|
|
|
2009-07-09 01:06:06 +00:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
2009-06-16 16:20:12 +00:00
|
|
|
const Main = imports.ui.main;
|
|
|
|
|
|
|
|
const THUMBNAIL_ICON_MARGIN = 2;
|
|
|
|
|
|
|
|
function DocInfo(recentInfo) {
|
|
|
|
this._init(recentInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
DocInfo.prototype = {
|
|
|
|
_init : function(recentInfo) {
|
2009-10-21 20:56:06 +00:00
|
|
|
this.recentInfo = recentInfo;
|
2009-07-25 15:00:37 +00:00
|
|
|
// We actually used get_modified() instead of get_visited()
|
|
|
|
// here, as GtkRecentInfo doesn't updated get_visited()
|
|
|
|
// correctly. See http://bugzilla.gnome.org/show_bug.cgi?id=567094
|
|
|
|
this.timestamp = recentInfo.get_modified().getTime() / 1000;
|
2009-06-16 16:20:12 +00:00
|
|
|
this.name = recentInfo.get_display_name();
|
|
|
|
this.uri = recentInfo.get_uri();
|
|
|
|
this.mimeType = recentInfo.get_mime_type();
|
|
|
|
},
|
|
|
|
|
2009-06-29 19:08:48 +00:00
|
|
|
createIcon : function(size) {
|
2009-10-21 20:56:06 +00:00
|
|
|
return Shell.TextureCache.get_default().load_recent_thumbnail(size, this.recentInfo);
|
2009-06-16 16:20:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
launch : function() {
|
2009-11-29 22:43:25 +00:00
|
|
|
Shell.DocSystem.get_default().open(this.recentInfo);
|
2009-06-16 16:20:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
exists : function() {
|
2009-10-21 20:56:06 +00:00
|
|
|
return this.recentInfo.exists();
|
2009-06-16 16:20:12 +00:00
|
|
|
}
|
|
|
|
};
|
2009-07-09 01:06:06 +00:00
|
|
|
|
|
|
|
var docManagerInstance = null;
|
|
|
|
|
2009-08-17 02:23:44 +00:00
|
|
|
function getDocManager() {
|
2009-07-09 01:06:06 +00:00
|
|
|
if (docManagerInstance == null)
|
2009-08-17 02:23:44 +00:00
|
|
|
docManagerInstance = new DocManager();
|
2009-07-09 01:06:06 +00:00
|
|
|
return docManagerInstance;
|
|
|
|
}
|
|
|
|
|
2009-11-29 22:43:25 +00:00
|
|
|
/**
|
|
|
|
* DocManager wraps the DocSystem, primarily to expose DocInfo objects
|
|
|
|
* which conform to the GenericDisplay item API.
|
|
|
|
*/
|
2009-08-17 02:23:44 +00:00
|
|
|
function DocManager() {
|
|
|
|
this._init();
|
2009-07-09 01:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DocManager.prototype = {
|
2009-08-17 02:23:44 +00:00
|
|
|
_init: function() {
|
2009-11-29 22:43:25 +00:00
|
|
|
this._docSystem = Shell.DocSystem.get_default();
|
|
|
|
this._infosByTimestamp = [];
|
|
|
|
this._infosByUri = {};
|
|
|
|
this._docSystem.connect('changed', Lang.bind(this, this._reload));
|
2009-07-09 01:06:06 +00:00
|
|
|
this._reload();
|
|
|
|
},
|
|
|
|
|
|
|
|
_reload: function() {
|
2009-11-29 22:43:25 +00:00
|
|
|
let docs = this._docSystem.get_all();
|
|
|
|
this._infosByTimestamp = [];
|
|
|
|
this._infosByUri = {};
|
2009-07-09 01:06:06 +00:00
|
|
|
for (let i = 0; i < docs.length; i++) {
|
|
|
|
let recentInfo = docs[i];
|
2009-08-17 02:23:44 +00:00
|
|
|
|
2009-07-09 01:06:06 +00:00
|
|
|
let docInfo = new DocInfo(recentInfo);
|
2009-11-29 22:43:25 +00:00
|
|
|
this._infosByTimestamp.push(docInfo);
|
|
|
|
this._infosByUri[docInfo.uri] = docInfo;
|
2009-07-09 01:06:06 +00:00
|
|
|
}
|
2009-11-29 22:43:25 +00:00
|
|
|
this.emit('changed');
|
|
|
|
},
|
|
|
|
|
|
|
|
getTimestampOrderedInfos: function() {
|
|
|
|
return this._infosByTimestamp;
|
|
|
|
},
|
|
|
|
|
|
|
|
getInfosByUri: function() {
|
|
|
|
return this._infosByUri;
|
|
|
|
},
|
|
|
|
|
|
|
|
lookupByUri: function(uri) {
|
|
|
|
return this._infosByUri[uri];
|
2009-07-09 01:06:06 +00:00
|
|
|
},
|
|
|
|
|
2009-11-29 22:43:25 +00:00
|
|
|
queueExistenceCheck: function(count) {
|
|
|
|
return this._docSystem.queue_existence_check(count);
|
2009-07-09 01:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Signals.addSignalMethods(DocManager.prototype);
|