Commit eefe7ddb authored by Zander Brown's avatar Zander Brown Committed by Guido Gunther
Browse files

overview: Move favorites launchers into app-grid

They inetract closely, e.g. on search so it makes sense to have them in
the same widget.

TODO: the css name change from phosh-favorites to phosh-overview should
go in a separte commit

Closes: #38
parent 3eb94ff8
......@@ -19,10 +19,62 @@ struct _PhoshAppGridPrivate {
GtkWidget *search;
GtkWidget *apps;
GtkWidget *favs;
GSettings *settings;
};
G_DEFINE_TYPE_WITH_PRIVATE (PhoshAppGrid, phosh_app_grid, GTK_TYPE_BOX)
enum {
APP_LAUNCHED,
N_SIGNALS
};
static guint signals[N_SIGNALS] = { 0 };
static void
app_launched_cb (GtkWidget *widget,
GAppInfo *info,
PhoshAppGrid *self)
{
g_signal_emit (self, signals[APP_LAUNCHED], 0, info);
}
static void
favorites_changed (GSettings *settings,
const gchar *key,
PhoshAppGrid *self)
{
PhoshAppGridPrivate *priv = phosh_app_grid_get_instance_private (self);
gchar **favorites = g_settings_get_strv (settings, key);
GtkWidget *btn;
/* Remove all favorites first */
gtk_container_foreach (GTK_CONTAINER (priv->favs),
(GtkCallback) gtk_widget_destroy, NULL);
for (gint i = 0; i < g_strv_length (favorites); i++) {
gchar *fav = favorites[i];
GDesktopAppInfo *info;
info = g_desktop_app_info_new (fav);
if (!info)
continue;
btn = phosh_app_grid_button_new_favorite (G_APP_INFO (info));
g_signal_connect (btn, "app-launched",
G_CALLBACK (app_launched_cb), self);
gtk_widget_show (btn);
if (btn)
gtk_flow_box_insert (GTK_FLOW_BOX (priv->favs), btn, -1);
}
g_strfreev (favorites);
}
static gint
sort_apps (gconstpointer a,
gconstpointer b,
......@@ -101,10 +153,13 @@ search_apps (gpointer item, gpointer data)
static GtkWidget *
create_launcher (gpointer item,
gpointer user_data)
gpointer self)
{
GtkWidget *btn = phosh_app_grid_button_new (G_APP_INFO (item));
g_signal_connect (btn, "app-launched",
G_CALLBACK (app_launched_cb), self);
gtk_widget_show (btn);
return btn;
......@@ -118,6 +173,11 @@ phosh_app_grid_init (PhoshAppGrid *self)
gtk_widget_init_template (GTK_WIDGET (self));
priv->settings = g_settings_new ("sm.puri.phosh");
g_signal_connect (priv->settings, "changed::favorites",
G_CALLBACK (favorites_changed), self);
favorites_changed (priv->settings, "favorites", self);
/* fill the grid with apps */
sorted = gtk_sort_list_model_new (G_LIST_MODEL (phosh_app_list_model_get_default ()),
sort_apps,
......@@ -138,6 +198,7 @@ phosh_app_grid_finalize (GObject *object)
PhoshAppGridPrivate *priv = phosh_app_grid_get_instance_private (self);
g_clear_object (&priv->model);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (phosh_app_grid_parent_class)->finalize (object);
}
......@@ -176,9 +237,16 @@ phosh_app_grid_class_init (PhoshAppGridClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, PhoshAppGrid, search);
gtk_widget_class_bind_template_child_private (widget_class, PhoshAppGrid, apps);
gtk_widget_class_bind_template_child_private (widget_class, PhoshAppGrid, favs);
gtk_widget_class_bind_template_callback (widget_class, search_changed);
signals[APP_LAUNCHED] = g_signal_new ("app-launched",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_APP_INFO);
gtk_widget_class_set_css_name (widget_class, "phosh-app-grid");
}
......
......@@ -2,10 +2,6 @@
* Copyright (C) 2018 Purism SPC
* SPDX-License-Identifier: GPL-3.0+
* Author: Guido Günther <agx@sigxcpu.org>
*
* Based on maynard's favorites which is
* Copyright (C) 2013 Collabora Ltd.
* Author: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
*/
#define G_LOG_DOMAIN "phosh-overview"
......@@ -37,15 +33,11 @@ static guint signals[N_SIGNALS] = { 0 };
typedef struct
{
/* Favorites and later on installed apps */
GtkWidget *evbox_apps;
GtkWidget *fb_apps;
GSettings *settings;
/* Running activities */
GtkWidget *evbox_running_activities;
GtkWidget *box_running_activities;
GtkWidget *app_grid;
} PhoshOverviewPrivate;
......@@ -189,50 +181,6 @@ app_launched_cb (PhoshOverview *self,
}
static GtkWidget*
create_favorite (PhoshOverview *self,
const gchar *favorite)
{
GDesktopAppInfo *info;
GtkWidget *btn;
info = g_desktop_app_info_new (favorite);
if (!info)
return NULL;
btn = phosh_app_grid_button_new_favorite (G_APP_INFO (info));
g_signal_connect_swapped (btn, "app-launched",
G_CALLBACK (app_launched_cb), self);
return btn;
}
static void
favorites_changed (GSettings *settings,
const gchar *key,
PhoshOverview *self)
{
PhoshOverviewPrivate *priv = phosh_overview_get_instance_private (self);
g_auto(GStrv) favorites = g_settings_get_strv (settings, key);
GtkWidget *btn;
/* Remove all favorites first */
gtk_container_foreach (GTK_CONTAINER (priv->fb_apps),
(GtkCallback) gtk_widget_destroy, NULL);
for (gint i = 0; i < g_strv_length (favorites); i++) {
gchar *fav = favorites[i];
btn = create_favorite (self, fav);
if (btn) {
gtk_flow_box_insert (GTK_FLOW_BOX (priv->fb_apps), btn, -1);
gtk_widget_show (btn);
}
}
}
static gboolean
evbox_button_press_event_cb (PhoshOverview *self, GdkEventButton *event)
{
......@@ -251,17 +199,6 @@ phosh_overview_constructed (GObject *object)
G_OBJECT_CLASS (phosh_overview_parent_class)->constructed (object);
/* Close on click */
g_signal_connect_swapped (priv->evbox_apps, "button_press_event",
G_CALLBACK (evbox_button_press_event_cb),
self);
gtk_widget_set_events (priv->evbox_apps, GDK_BUTTON_PRESS_MASK);
priv->settings = g_settings_new ("sm.puri.phosh");
g_signal_connect (priv->settings, "changed::favorites",
G_CALLBACK (favorites_changed), self);
favorites_changed (priv->settings, "favorites", self);
/* Close on click */
g_signal_connect_swapped (priv->evbox_running_activities, "button_press_event",
G_CALLBACK (evbox_button_press_event_cb),
......@@ -274,18 +211,9 @@ phosh_overview_constructed (GObject *object)
G_CONNECT_SWAPPED);
get_running_activities (self);
}
static void
phosh_overview_dispose (GObject *object)
{
PhoshOverview *self = PHOSH_OVERVIEW (object);
PhoshOverviewPrivate *priv = phosh_overview_get_instance_private (self);
g_clear_object (&priv->settings);
G_OBJECT_CLASS (phosh_overview_parent_class)->dispose (object);
g_signal_connect_swapped (priv->app_grid, "app-launched",
G_CALLBACK (app_launched_cb), self);
}
......@@ -295,7 +223,6 @@ phosh_overview_class_init (PhoshOverviewClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = phosh_overview_dispose;
object_class->constructed = phosh_overview_constructed;
widget_class->size_allocate = phosh_overview_size_allocate;
......@@ -306,10 +233,9 @@ phosh_overview_class_init (PhoshOverviewClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/sm/puri/phosh/ui/overview.ui");
gtk_widget_class_bind_template_child_private (widget_class, PhoshOverview, evbox_apps);
gtk_widget_class_bind_template_child_private (widget_class, PhoshOverview, fb_apps);
gtk_widget_class_bind_template_child_private (widget_class, PhoshOverview, evbox_running_activities);
gtk_widget_class_bind_template_child_private (widget_class, PhoshOverview, box_running_activities);
gtk_widget_class_bind_template_child_private (widget_class, PhoshOverview, app_grid);
gtk_widget_class_bind_template_callback (widget_class, evbox_button_press_event_cb);
......@@ -326,7 +252,7 @@ phosh_overview_class_init (PhoshOverviewClass *klass)
G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL,
NULL, G_TYPE_NONE, 0);
gtk_widget_class_set_css_name (widget_class, "phosh-favorites");
gtk_widget_class_set_css_name (widget_class, "phosh-overview");
}
......
......@@ -158,7 +158,7 @@ phosh-home, .phosh-panel {
}
/* switcher */
phosh-favorites {
phosh-overview {
background: rgba(0,0,0,0.6);
}
......@@ -166,6 +166,11 @@ phosh-app-grid {
background: rgba(0,0,0,0.4);
}
phosh-app-grid separator {
background: gray;
padding: 1px;
}
phosh-app-grid-button {
font-size: 0.8rem;
}
......
......@@ -44,7 +44,7 @@
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkFlowBox" id="apps">
<object class="GtkFlowBox" id="favs">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">3</property>
......@@ -58,15 +58,32 @@
<property name="row-spacing">6</property>
</object>
<packing>
<property name="expand">True</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">-1</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFlowBox" id="favs">
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFlowBox" id="apps">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">3</property>
<property name="margin_right">3</property>
<property name="margin_bottom">3</property>
<property name="hexpand">True</property>
<property name="homogeneous">True</property>
<property name="selection_mode">none</property>
<property name="activate_on_single_click">False</property>
......@@ -74,9 +91,9 @@
<property name="row-spacing">6</property>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">2</property>
</packing>
</child>
</object>
......
......@@ -10,6 +10,8 @@
<object class="GtkEventBox" id="evbox_running_activities">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<signal name="button-press-event" handler="evbox_button_press_event_cb" object="PhoshOverview" swapped="yes"/>
<child>
<object class="GtkScrolledWindow" id="sw_running_activities">
<property name="visible">True</property>
......@@ -58,82 +60,21 @@
</packing>
</child>
<child>
<object class="GtkEventBox" id="evbox_apps">
<property name="name">evbox</property>
<object class="GtkEventBox" id="evbox_app_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<signal name="button-press-event" handler="evbox_button_press_event_cb" object="PhoshOverview" swapped="yes"/>
<child>
<object class="GtkScrolledWindow" id="sw_apps">
<property name="name">sw_overview</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">end</property>
<property name="hscrollbar_policy">never</property>
<property name="propagate_natural_height">True</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFlowBox" id="fb_apps">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="homogeneous">True</property>
<property name="min_children_per_line">4</property>
<property name="max_children_per_line">4</property>
<property name="column-spacing">20</property>
<property name="row-spacing">20</property>
<property name="selection_mode">none</property>
<property name="activate_on_single_click">False</property>
<style>
<class name="phosh-overview-flowbox"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<object class="PhoshAppGrid" id="app_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
<signal name="button-press-event" handler="evbox_button_press_event_cb" object="PhoshFavorites" swapped="yes"/>
<child>
<object class="PhoshAppGrid">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment