Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Recent/Pinned category #623

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Backend/App.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class Slingshot.Backend.App : Object {
public string exec { get; private set; }
public string[] keywords { get; private set;}
public Icon icon { get; private set; default = new ThemedIcon ("application-default-icon"); }
public double popularity { get; set; }
public int popularity { get; set; }
public string desktop_path { get; private set; }
public string categories { get; private set; }
public string generic_name { get; private set; default = ""; }
Expand Down
34 changes: 33 additions & 1 deletion src/Backend/AppSystem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,19 @@ public class Slingshot.Backend.AppSystem : Object {
private void update_app_system () {
debug ("Updating Applications menu tree…");
#if HAVE_ZEITGEIST
rl_service.refresh_popularity ();
rl_service.refresh_popularity.begin ();
#endif

update_categories_index ();
changed ();
}

public async void update_popularities () {
#if HAVE_ZEITGEIST
yield rl_service.refresh_popularity ();
#endif
}

private void update_categories_index () {
categories_cache.clear ();

Expand Down Expand Up @@ -220,4 +226,30 @@ public class Slingshot.Backend.AppSystem : Object {
private static int sort_apps_by_name (Backend.App a, Backend.App b) {
return a.name.collate (b.name);
}

#if HAVE_ZEITGEIST
public SList<App> get_apps_by_popularity () {
var sorted_apps = new SList<App> ();
string[] sorted_apps_execs = {};

foreach (Gee.ArrayList<App> category in apps.values) {
foreach (App app in category) {
if (!(app.exec in sorted_apps_execs)) {
sorted_apps.insert_sorted_with_data (app, sort_apps_by_popularity);
sorted_apps_execs += app.exec;
}
}
}

return sorted_apps;
}

private static int sort_apps_by_popularity (Backend.App a, Backend.App b) {
if (a.popularity == b.popularity) {
return a.name.collate (b.name);
}

return a.popularity > b.popularity ? 1 : -1;
}
#endif
}
34 changes: 18 additions & 16 deletions src/Backend/RelevancyService.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@ public class Slingshot.Backend.RelevancyService : Object {
private bool has_datahub_gio_module = false;
private bool refreshing = false;

private const float MULTIPLIER = 65535.0f;

public signal void update_complete ();

public RelevancyService () {

zg_log = new Zeitgeist.Log ();
app_popularity = new Gee.HashMap<string, int> ();

refresh_popularity ();
refresh_popularity.begin ();
check_data_sources.begin ();

Timeout.add_seconds (60*30, refresh_popularity);
Timeout.add_seconds (60*30, () => {
refresh_popularity.begin ();
return Source.CONTINUE;
});

}

Expand All @@ -64,12 +65,12 @@ public class Slingshot.Backend.RelevancyService : Object {
}
}

public bool refresh_popularity () {

load_application_relevancies.begin ();
public async bool refresh_popularity () {
yield load_application_relevancies ();
return true;

}

private void reload_relevancies () {

Idle.add_full (Priority.LOW, () => {
Expand Down Expand Up @@ -104,7 +105,6 @@ public class Slingshot.Backend.RelevancyService : Object {

var ptr_arr = new GLib.GenericArray<Zeitgeist.Event> ();
ptr_arr.add (event);

try {
Zeitgeist.ResultSet rs = yield zg_log.find_events (tr, ptr_arr,
Zeitgeist.StorageState.ANY,
Expand All @@ -119,13 +119,15 @@ public class Slingshot.Backend.RelevancyService : Object {
// Zeitgeist (0.6) doesn't have any stats API, so let's approximate

foreach (Zeitgeist.Event e in rs) {
if (e.num_subjects () <= 0) {
continue;
}

if (e.num_subjects () <= 0) continue;
Zeitgeist.Subject s = e.get_subject (0);

float power = index / (size * 2) + 0.5f; // linearly <0.5, 1.0>
float relevancy = 1.0f / Math.powf (index + 1, power);
app_popularity[s.uri] = (int)(relevancy * MULTIPLIER);
// Simply use the (inverted) order of the app in the result set as
// measure of popularity for now. Suffices for the applications menu.
app_popularity[s.uri] = (int) (size - index);
index++;
}
update_complete ();
Expand All @@ -137,15 +139,15 @@ public class Slingshot.Backend.RelevancyService : Object {
}
}

public float get_app_popularity (string desktop_id) {

public int get_app_popularity (string desktop_id) {
var id = "application://" + desktop_id;

if (app_popularity.has_key (id)) {
return app_popularity[id] / MULTIPLIER;
// return app_popularity[id] / MULTIPLIER;
return app_popularity[id];
}

return 0.0f;
return 0;
}

public void app_launched (App app) {
Expand Down
51 changes: 37 additions & 14 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
public class Slingshot.Indicator : Wingpanel.Indicator {
private const string KEYBINDING_SCHEMA = "io.elementary.desktop.wm.keybindings";
private const string GALA_BEHAVIOR_SCHEMA = "io.elementary.desktop.wm.behavior";
private const string DOCK_SCHEMA = "io.elementary.dock";

private DBusService? dbus_service = null;
private Gtk.Grid? indicator_grid = null;
private SlingshotView? view = null;

private static GLib.Settings? keybinding_settings;
private static GLib.Settings? gala_behavior_settings;
private static GLib.Settings? dock_settings;

public Indicator () {
Object (code_name: Wingpanel.Indicator.APP_LAUNCHER);
Expand All @@ -39,6 +41,10 @@ public class Slingshot.Indicator : Wingpanel.Indicator {
if (SettingsSchemaSource.get_default ().lookup (GALA_BEHAVIOR_SCHEMA, true) != null) {
gala_behavior_settings = new GLib.Settings (GALA_BEHAVIOR_SCHEMA);
}

if (SettingsSchemaSource.get_default ().lookup (DOCK_SCHEMA, true) != null) {
dock_settings = new GLib.Settings (DOCK_SCHEMA);
}
}

construct {
Expand All @@ -54,19 +60,6 @@ public class Slingshot.Indicator : Wingpanel.Indicator {
}

public override Gtk.Widget? get_widget () {
if (view == null) {
view = new SlingshotView ();

unowned var unity_client = Unity.get_default ();
unity_client.add_client (view);

view.close_indicator.connect (on_close_indicator);

if (dbus_service == null) {
dbus_service = new DBusService (view);
}
}

return view;
}

Expand Down Expand Up @@ -101,12 +94,42 @@ public class Slingshot.Indicator : Wingpanel.Indicator {

visible = true;

// Create the view now so that there is time for app popularities to initialise
// before the view is shown for the first time.
if (view == null) {
view = new SlingshotView ();

unowned var unity_client = Unity.get_default ();
unity_client.add_client (view);

view.close_indicator.connect (on_close_indicator);

if (dbus_service == null) {
dbus_service = new DBusService (view);
}

if (dock_settings != null) {
dock_settings.changed.connect ((key) => {
if (key == "launchers") {
view.update (dock_settings.get_strv ("launchers"));
}
});
}
}

// Wait for AppSystem to initialize
Idle.add (() => {
view.update (dock_settings != null ? dock_settings.get_strv ("launchers") : null);
return Source.REMOVE;
});

return indicator_grid;
}

public override void opened () {
if (view != null)
if (view != null) {
view.show_slingshot ();
}
}

public override void closed () {
Expand Down
8 changes: 6 additions & 2 deletions src/SlingshotView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,14 @@ public class Slingshot.SlingshotView : Gtk.Grid, UnityClient {
// Auto-update applications grid
app_system.changed.connect (() => {
grid_view.populate (app_system);

category_view.setup_sidebar ();
category_view.update (null);
});
}

public void update (string[] pinned) {
category_view.update (pinned);
}

public void update_launcher_entry (string sender_name, GLib.Variant parameters, bool is_retry = false) {
if (!is_retry) {
// Wait to let further update requests come in to catch the case where one application
Expand Down Expand Up @@ -323,6 +326,7 @@ public class Slingshot.SlingshotView : Gtk.Grid, UnityClient {

public void show_slingshot () {
search_entry.text = "";
category_view.update (null);

/* TODO
set_focus (null);
Expand Down
Loading
Loading