19
19
errordomain IconError
24
24
public class Slingshot.Backend.App : Object {
32
public signal void start_search (Synapse.SearchMatch search_match, Synapse.Match? target);
32
public signal void start_search (Synapse.SearchMatch search_match, Synapse.Match? target);
34
34
public string name { get; construct set; }
35
35
public string description { get; private set; default = ""; }
43
43
public string desktop_path { get; private set; }
44
44
public string categories { get; private set; }
45
45
public string generic_name { get; private set; default = ""; }
46
public AppType app_type { get; private set; default = AppType.APP; }
46
public AppType app_type { get; private set; default = AppType.APP; }
48
public Synapse.Match? match { get; private set; default = null; }
49
public Synapse.Match? target { get; private set; default = null; }
48
public Synapse.Match? match { get; private set; default = null; }
49
public Synapse.Match? target { get; private set; default = null; }
51
51
public signal void icon_changed ();
52
52
public signal void launched (App app);
54
54
public App (GMenu.TreeEntry entry) {
55
app_type = AppType.APP;
55
app_type = AppType.APP;
57
57
unowned GLib.DesktopAppInfo info = entry.get_app_info ();
58
58
name = info.get_display_name ().dup ();
102
public App.from_synapse_match (Synapse.Match match, Synapse.Match? target = null) {
104
app_type = AppType.SYNAPSE;
107
description = match.description;
108
icon_name = match.icon_name;
111
this.target = target;
102
public App.from_synapse_match (Synapse.Match match, Synapse.Match? target = null) {
104
app_type = AppType.SYNAPSE;
107
description = match.description;
108
icon_name = match.icon_name;
111
this.target = target;
117
117
public void update_icon () {
118
118
icon = load_icon (Slingshot.settings.icon_size);
132
132
public Gdk.Pixbuf? load_icon (int size) {
133
if (app_type == AppType.SYNAPSE) {
135
// for contacts we can load the thumbnail because we expect it to be
136
// the avatar. For other types it'd be ridiculously small.
137
if (match.match_type == Synapse.MatchType.CONTACT && match.has_thumbnail) {
138
return new Gdk.Pixbuf.from_file_at_scale (match.thumbnail_path, size, size, true);
141
var icon = Icon.new_for_string (icon_name);
142
var info = Gtk.IconTheme.get_default ().lookup_by_gicon (icon,
143
size, Gtk.IconLookupFlags.FORCE_SIZE);
146
throw new IconError.NOT_FOUND ("Not found");
148
return info.load_icon ();
150
warning ("Failed to load icon: %s\n", e.message);
153
return Slingshot.icon_theme.load_icon ("application-default-icon",
154
size, Gtk.IconLookupFlags.FORCE_SIZE);
133
if (app_type == AppType.SYNAPSE) {
135
// for contacts we can load the thumbnail because we expect it to be
136
// the avatar. For other types it'd be ridiculously small.
137
if (match.match_type == Synapse.MatchType.CONTACT && match.has_thumbnail) {
138
return new Gdk.Pixbuf.from_file_at_scale (match.thumbnail_path, size, size, true);
141
var icon = Icon.new_for_string (icon_name);
142
var info = Gtk.IconTheme.get_default ().lookup_by_gicon (icon,
143
size, Gtk.IconLookupFlags.FORCE_SIZE);
146
throw new IconError.NOT_FOUND ("Not found");
148
return info.load_icon ();
150
warning ("Failed to load icon: %s\n", e.message);
153
return Slingshot.icon_theme.load_icon ("application-default-icon",
154
size, Gtk.IconLookupFlags.FORCE_SIZE);
157
157
Gdk.Pixbuf icon = null;
158
158
var flags = Gtk.IconLookupFlags.FORCE_SIZE;
214
214
public bool launch () {
216
216
switch (app_type) {
217
case AppType.COMMAND:
218
debug (@"Launching command: $name");
219
Process.spawn_command_line_async (exec);
222
launched (this); // Emit launched signal
223
new DesktopAppInfo (desktop_id).launch (null, null);
224
debug (@"Launching application: $name");
226
case AppType.SYNAPSE:
227
if (match.match_type == Synapse.MatchType.SEARCH) {
228
start_search (match as Synapse.SearchMatch, target);
232
Backend.SynapseSearch.find_actions_for_match (match).get (0).execute_with_target (match);
234
match.execute_with_target (target);
217
case AppType.COMMAND:
218
debug (@"Launching command: $name");
219
Process.spawn_command_line_async (exec);
222
launched (this); // Emit launched signal
223
new DesktopAppInfo (desktop_id).launch (null, null);
224
debug (@"Launching application: $name");
226
case AppType.SYNAPSE:
227
if (match.match_type == Synapse.MatchType.SEARCH) {
228
start_search (match as Synapse.SearchMatch, target);
232
Backend.SynapseSearch.find_actions_for_match (match).get (0).execute_with_target (match);
234
match.execute_with_target (target);
238
238
} catch (Error e) {
239
239
warning ("Failed to launch %s: %s", name, exec);