2011-12-20 17:41:23 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
const GdkPixbuf = imports.gi.GdkPixbuf;
|
|
|
|
const GLib = imports.gi.GLib;
|
2012-10-02 19:16:56 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
2011-12-20 17:41:23 +00:00
|
|
|
const Lang = imports.lang;
|
|
|
|
const St = imports.gi.St;
|
|
|
|
|
|
|
|
const IconGrid = imports.ui.iconGrid;
|
2012-08-16 19:37:27 +00:00
|
|
|
const Layout = imports.ui.layout;
|
2011-12-20 17:41:23 +00:00
|
|
|
const Main = imports.ui.main;
|
2012-11-27 18:14:30 +00:00
|
|
|
const Panel = imports.ui.panel;
|
2011-12-20 17:41:23 +00:00
|
|
|
|
|
|
|
const FISH_NAME = 'wanda';
|
2013-03-09 23:26:02 +00:00
|
|
|
const FISH_FILENAME = 'wanda.png';
|
2011-12-20 17:41:23 +00:00
|
|
|
const FISH_SPEED = 300;
|
|
|
|
const FISH_COMMAND = 'fortune';
|
2013-03-09 23:26:02 +00:00
|
|
|
// The size of an individual frame in the animation
|
|
|
|
const FISH_HEIGHT = 22;
|
|
|
|
const FISH_WIDTH = 36;
|
2011-12-20 17:41:23 +00:00
|
|
|
|
|
|
|
const FISH_GROUP = 'Fish Animation';
|
|
|
|
|
|
|
|
const MAGIC_FISH_KEY = 'free the fish';
|
|
|
|
|
|
|
|
const WandaIcon = new Lang.Class({
|
|
|
|
Name: 'WandaIcon',
|
|
|
|
Extends: IconGrid.BaseIcon,
|
|
|
|
|
|
|
|
_init : function(fish, label, params) {
|
2013-03-09 23:26:02 +00:00
|
|
|
this.parent(label, params);
|
2011-12-20 17:41:23 +00:00
|
|
|
|
2013-03-09 23:26:02 +00:00
|
|
|
this._fish = fish;
|
|
|
|
this._imageFile = GLib.build_filenamev([global.datadir, fish + '.png']);
|
2011-12-20 17:41:23 +00:00
|
|
|
|
2013-03-09 23:26:02 +00:00
|
|
|
this._imgHeight = FISH_HEIGHT;
|
|
|
|
this._imgWidth = FISH_WIDTH;
|
2011-12-20 17:41:23 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
createIcon: function(iconSize) {
|
2012-11-27 18:14:30 +00:00
|
|
|
this._animations = new Panel.Animation(this._imageFile, this._imgWidth, this._imgHeight, FISH_SPEED);
|
|
|
|
this._animations.play();
|
|
|
|
return this._animations.actor;
|
2011-12-20 17:41:23 +00:00
|
|
|
},
|
|
|
|
|
2012-09-16 17:35:41 +00:00
|
|
|
_createIconTexture: function(size) {
|
|
|
|
if (size == this.iconSize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.parent(size);
|
2012-11-27 18:14:30 +00:00
|
|
|
}
|
2011-12-20 17:41:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const WandaIconBin = new Lang.Class({
|
|
|
|
Name: 'WandaIconBin',
|
|
|
|
|
|
|
|
_init: function(fish, label, params) {
|
2012-08-02 01:48:10 +00:00
|
|
|
this.actor = new St.Bin({ reactive: true,
|
2011-12-20 17:41:23 +00:00
|
|
|
track_hover: true });
|
|
|
|
this.icon = new WandaIcon(fish, label, params);
|
|
|
|
|
|
|
|
this.actor.child = this.icon.actor;
|
|
|
|
this.actor.label_actor = this.icon.label;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const FortuneDialog = new Lang.Class({
|
|
|
|
Name: 'FortuneDialog',
|
|
|
|
|
|
|
|
_init: function(name, command) {
|
|
|
|
let text;
|
|
|
|
|
|
|
|
try {
|
|
|
|
let [res, stdout, stderr, status] = GLib.spawn_command_line_sync(command);
|
|
|
|
text = String.fromCharCode.apply(null, stdout);
|
|
|
|
} catch(e) {
|
|
|
|
text = _("Sorry, no wisdom for you today:\n%s").format(e.message);
|
|
|
|
}
|
|
|
|
|
2012-02-09 20:52:21 +00:00
|
|
|
this._title = new St.Label({ style_class: 'prompt-dialog-headline',
|
2011-12-20 17:41:23 +00:00
|
|
|
text: _("%s the Oracle says").format(name) });
|
2012-02-09 20:52:21 +00:00
|
|
|
this._label = new St.Label({ style_class: 'prompt-dialog-description',
|
2011-12-20 17:41:23 +00:00
|
|
|
text: text });
|
|
|
|
this._label.clutter_text.line_wrap = true;
|
|
|
|
|
|
|
|
this._box = new St.BoxLayout({ vertical: true,
|
2012-02-09 20:52:21 +00:00
|
|
|
style_class: 'prompt-dialog' // this is just to force a reasonable width
|
2011-12-20 17:41:23 +00:00
|
|
|
});
|
|
|
|
this._box.add(this._title, { align: St.Align.MIDDLE });
|
|
|
|
this._box.add(this._label, { expand: true });
|
|
|
|
|
|
|
|
this._button = new St.Button({ button_mask: St.ButtonMask.ONE,
|
|
|
|
style_class: 'modal-dialog',
|
|
|
|
reactive: true });
|
|
|
|
this._button.connect('clicked', Lang.bind(this, this.destroy));
|
|
|
|
this._button.child = this._box;
|
|
|
|
|
2012-08-16 19:37:27 +00:00
|
|
|
this._bin = new St.Bin({ x_align: St.Align.MIDDLE,
|
|
|
|
y_align: St.Align.MIDDLE });
|
|
|
|
this._bin.add_constraint(new Layout.MonitorConstraint({ primary: true }));
|
|
|
|
this._bin.add_actor(this._button);
|
2011-12-20 17:41:23 +00:00
|
|
|
|
2012-08-16 19:37:27 +00:00
|
|
|
Main.layoutManager.addChrome(this._bin);
|
2011-12-20 17:41:23 +00:00
|
|
|
|
|
|
|
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 10, Lang.bind(this, this.destroy));
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function() {
|
2012-08-16 19:37:27 +00:00
|
|
|
this._bin.destroy();
|
2011-12-20 17:41:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function capitalize(str) {
|
|
|
|
return str[0].toUpperCase() + str.substring(1, str.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
const WandaSearchProvider = new Lang.Class({
|
|
|
|
Name: 'WandaSearchProvider',
|
|
|
|
|
|
|
|
_init: function() {
|
2012-08-09 21:52:36 +00:00
|
|
|
this.id = 'wanda';
|
2011-12-20 17:41:23 +00:00
|
|
|
},
|
|
|
|
|
2012-05-02 19:54:25 +00:00
|
|
|
getResultMetas: function(fish, callback) {
|
2012-05-02 19:45:37 +00:00
|
|
|
callback([{ 'id': fish[0], // there may be many fish in the sea, but
|
|
|
|
// only one which speaks the truth!
|
|
|
|
'name': capitalize(fish[0]),
|
|
|
|
'createIcon': function(iconSize) {
|
2012-10-02 19:16:56 +00:00
|
|
|
return new St.Icon({ gicon: Gio.icon_new_for_string('face-smile'),
|
|
|
|
icon_size: iconSize });
|
2012-05-02 19:45:37 +00:00
|
|
|
}
|
|
|
|
}]);
|
2011-12-20 17:41:23 +00:00
|
|
|
},
|
|
|
|
|
2012-05-02 19:54:25 +00:00
|
|
|
getInitialResultSet: function(terms) {
|
2011-12-20 17:41:23 +00:00
|
|
|
if (terms.join(' ') == MAGIC_FISH_KEY) {
|
2012-05-02 19:45:37 +00:00
|
|
|
this.searchSystem.pushResults(this, [ FISH_NAME ]);
|
|
|
|
} else {
|
|
|
|
this.searchSystem.pushResults(this, []);
|
2011-12-20 17:41:23 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-02 19:54:25 +00:00
|
|
|
getSubsearchResultSet: function(previousResults, terms) {
|
|
|
|
this.getInitialResultSet(terms);
|
2011-12-20 17:41:23 +00:00
|
|
|
},
|
|
|
|
|
2012-12-05 15:05:48 +00:00
|
|
|
activateResult: function(fish) {
|
2011-12-20 17:41:23 +00:00
|
|
|
if (this._dialog)
|
|
|
|
this._dialog.destroy();
|
|
|
|
this._dialog = new FortuneDialog(capitalize(fish), FISH_COMMAND);
|
|
|
|
},
|
|
|
|
|
|
|
|
createResultActor: function (resultMeta, terms) {
|
|
|
|
let icon = new WandaIconBin(resultMeta.id, resultMeta.name);
|
|
|
|
return icon.actor;
|
|
|
|
}
|
|
|
|
});
|