Display thumbnails of recent files in the overlay mode by using GnomeThumbnailFactory to get them. Fall back to the system icon for the file type provided by GtkRecentInfo when a thumbnail is not available.

svn path=/trunk/; revision=143
This commit is contained in:
Marina Zhurakhinskaya
2009-01-09 01:09:35 +00:00
parent 1e99f00e59
commit 849ddbd3f6
8 changed files with 105 additions and 21 deletions

View File

@ -56,11 +56,11 @@ AppDisplayItem.prototype = {
let iconTheme = Gtk.IconTheme.get_default();
let icon = new Clutter.Texture({ width: 48, height: 48});
let icon = new Clutter.Texture({ width: GenericDisplay.ITEM_DISPLAY_ICON_SIZE, height: GenericDisplay.ITEM_DISPLAY_ICON_SIZE});
let gicon = appInfo.get_icon();
let path = null;
if (gicon != null) {
let iconinfo = iconTheme.lookup_by_gicon(gicon, 48, Gtk.IconLookupFlags.NO_SVG);
let iconinfo = iconTheme.lookup_by_gicon(gicon, GenericDisplay.ITEM_DISPLAY_ICON_SIZE, Gtk.IconLookupFlags.NO_SVG);
if (iconinfo)
path = iconinfo.get_filename();
}
@ -68,6 +68,8 @@ AppDisplayItem.prototype = {
if (path) {
try {
icon.set_from_file(path);
icon.x = GenericDisplay.ITEM_DISPLAY_PADDING;
icon.y = GenericDisplay.ITEM_DISPLAY_PADDING;
} catch (e) {
// we can get an error here if the file path doesn't exist on the system
log('Error loading AppDisplayItem icon ' + e);

View File

@ -9,6 +9,8 @@ const Shell = imports.gi.Shell;
const GenericDisplay = imports.ui.genericDisplay;
const ITEM_DISPLAY_ICON_MARGIN = 2;
/* This class represents a single display item containing information about a document.
*
* docInfo - GtkRecentInfo object containing information about the document
@ -30,9 +32,24 @@ DocDisplayItem.prototype = {
// we can possibly display tags in the space for description in the future
let description = "";
let icon = new Clutter.Texture({width: 48, height: 48});
Shell.clutter_texture_set_from_pixbuf(icon, docInfo.get_icon(48));
let icon = new Clutter.Texture();
let pixbuf = Shell.get_thumbnail_for_recent_info(docInfo);
if (pixbuf) {
// We calculate the width and height of the texture so as to preserve the aspect ratio of the thumbnail.
// Because the images generated based on thumbnails don't have an internal padding like system icons do,
// we create a slightly smaller texture and then use extra margin when positioning it.
let scalingFactor = (GenericDisplay.ITEM_DISPLAY_ICON_SIZE - ITEM_DISPLAY_ICON_MARGIN * 2) / Math.max(pixbuf.get_width(), pixbuf.get_height());
icon.set_width(Math.ceil(pixbuf.get_width() * scalingFactor));
icon.set_height(Math.ceil(pixbuf.get_height() * scalingFactor));
Shell.clutter_texture_set_from_pixbuf(icon, pixbuf);
icon.x = GenericDisplay.ITEM_DISPLAY_PADDING + ITEM_DISPLAY_ICON_MARGIN;
icon.y = GenericDisplay.ITEM_DISPLAY_PADDING + ITEM_DISPLAY_ICON_MARGIN;
} else {
Shell.clutter_texture_set_from_pixbuf(icon, docInfo.get_icon(GenericDisplay.ITEM_DISPLAY_ICON_SIZE));
icon.x = GenericDisplay.ITEM_DISPLAY_PADDING;
icon.y = GenericDisplay.ITEM_DISPLAY_PADDING;
}
this._setItemInfo(name, description, icon);
},
@ -124,10 +141,13 @@ DocDisplay.prototype = {
// While this._allItems associative array seems to always be ordered by last added,
// as the results of this._recentManager.get_items() based on which it is constructed are,
// we should do the sorting manually because we want the order to be based on last visited.
// TODO: would it be better to store an additional array of doc ids as they are
// returned by this._recentManager.get_items() to avoid having to do this sorting?
// This function is called each time the search string is set back to '', so we are
// doing the sorting over the same items multiple times.
//
// This function is called each time the search string is set back to '' or we display
// the overlay, so we are doing the sorting over the same items multiple times if the list
// of recent items didn't change. We could store an additional array of doc ids and sort
// them once when they are returned by this._recentManager.get_items() to avoid having to do
// this sorting each time, but the sorting seems to be very fast anyway, so there is no need
// to introduce an additional class variable.
let docIds = [];
for (docId in this._allItems) {
docIds.push(docId);

View File

@ -20,7 +20,9 @@ const ITEM_DISPLAY_SELECTED_BACKGROUND_COLOR = new Clutter.Color();
ITEM_DISPLAY_SELECTED_BACKGROUND_COLOR.from_pixel(0x00ff0055);
const ITEM_DISPLAY_HEIGHT = 50;
const ITEM_DISPLAY_PADDING = 4;
const ITEM_DISPLAY_ICON_SIZE = 48;
const ITEM_DISPLAY_PADDING = 1;
const ITEM_DISPLAY_MARGIN = 4;
/* This is a virtual class that represents a single display item containing
* a name, a description, and an icon. It allows selecting an item and represents
@ -106,18 +108,16 @@ GenericDisplayItem.prototype = {
}
this._icon = iconActor;
this._icon.x = 0;
this._icon.y = 0;
this._group.add_actor(this._icon);
let text_width = this._availableWidth - (this._icon.width + 4);
let text_width = this._availableWidth - (ITEM_DISPLAY_ICON_SIZE + 4);
this._name = new Clutter.Label({ color: ITEM_DISPLAY_NAME_COLOR,
font_name: "Sans 14px",
width: text_width,
ellipsize: Pango.EllipsizeMode.END,
text: nameText,
x: this._icon.width + 4,
y: 0});
x: ITEM_DISPLAY_ICON_SIZE + 4,
y: ITEM_DISPLAY_PADDING});
this._group.add_actor(this._name);
this._description = new Clutter.Label({ color: ITEM_DISPLAY_DESCRIPTION_COLOR,
font_name: "Sans 12px",
@ -157,7 +157,8 @@ GenericDisplay.prototype = {
this._activatedItem = null;
this._selectedIndex = -1;
this._keepDisplayCurrent = false;
this._maxItems = this._height / (ITEM_DISPLAY_HEIGHT + ITEM_DISPLAY_PADDING);
// TODO: this should be Math.floor, but right now we get too few items if we apply it
this._maxItems = this._height / (ITEM_DISPLAY_HEIGHT + ITEM_DISPLAY_MARGIN);
this.actor = this._grid;
},

View File

@ -19,7 +19,7 @@ const OVERLAY_BACKGROUND_COLOR = new Clutter.Color();
OVERLAY_BACKGROUND_COLOR.from_pixel(0x000000ff);
const SIDESHOW_PAD = 6;
const SIDESHOW_PAD_BOTTOM = 60;
const SIDESHOW_PAD_BOTTOM = 40;
const SIDESHOW_MIN_WIDTH = 250;
const SIDESHOW_SECTION_PAD = 10;
const SIDESHOW_SECTION_LABEL_PAD_BOTTOM = 6;