[gnome-builder/wip/greeter] greeter: incremental greeter design work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/greeter] greeter: incremental greeter design work
- Date: Sun, 10 May 2015 05:31:25 +0000 (UTC)
commit 5a79d8a020e4eed38dae22b8dddb3577bc1f7dce
Author: Christian Hergert <christian hergert me>
Date: Sat May 9 22:27:38 2015 -0700
greeter: incremental greeter design work
data/ui/gb-greeter-window.ui | 22 +---------
src/app/gb-application.c | 3 +
src/greeter/gb-greeter-project-row.c | 66 +++++++++++++++++++++++++++++-
src/greeter/gb-greeter-window.c | 75 +++++++++++++++++++--------------
4 files changed, 113 insertions(+), 53 deletions(-)
---
diff --git a/data/ui/gb-greeter-window.ui b/data/ui/gb-greeter-window.ui
index 8e68b58..e66b5d0 100644
--- a/data/ui/gb-greeter-window.ui
+++ b/data/ui/gb-greeter-window.ui
@@ -2,6 +2,8 @@
<interface>
<!-- interface-requires gtk+ 3.16 -->
<template class="GbGreeterWindow" parent="GtkApplicationWindow">
+ <property name="default-width">1280</property>
+ <property name="default-height">720</property>
<child type="titlebar">
<object class="GtkHeaderBar" id="header_bar">
<property name="show-close-button">true</property>
@@ -118,26 +120,6 @@
<object class="GtkListBox" id="my_projects_list_box">
<property name="visible">true</property>
<property name="selection-mode">none</property>
- <child>
- <object class="GbGreeterProjectRow">
- <property name="visible">true</property>
- </object>
- </child>
- <child>
- <object class="GbGreeterProjectRow">
- <property name="visible">true</property>
- </object>
- </child>
- <child>
- <object class="GbGreeterProjectRow">
- <property name="visible">true</property>
- </object>
- </child>
- <child>
- <object class="GbGreeterProjectRow">
- <property name="visible">true</property>
- </object>
- </child>
</object>
</child>
</object>
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index abb658c..938469e 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -447,10 +447,13 @@ gb_application_show_projects_window (GbApplication *self)
}
#if 1
+ IdeRecentProjects *projects = ide_recent_projects_new ();
window = g_object_new (GB_TYPE_GREETER_WINDOW,
"application", self,
+ "recent-projects", projects,
NULL);
gtk_window_present (GTK_WINDOW (window));
+ ide_recent_projects_discover_async (projects, NULL, NULL, NULL);
#endif
window = g_object_new (GB_TYPE_PROJECTS_DIALOG,
diff --git a/src/greeter/gb-greeter-project-row.c b/src/greeter/gb-greeter-project-row.c
index 02ea68e..5a001fe 100644
--- a/src/greeter/gb-greeter-project-row.c
+++ b/src/greeter/gb-greeter-project-row.c
@@ -23,6 +23,7 @@
#include "egg-binding-set.h"
+#include "gb-glib.h"
#include "gb-greeter-project-row.h"
struct _GbGreeterProjectRow
@@ -31,6 +32,7 @@ struct _GbGreeterProjectRow
IdeProjectInfo *project_info;
EggBindingSet *bindings;
+ GFile *home_dir;
GtkLabel *date_label;
GtkLabel *description_label;
@@ -47,6 +49,7 @@ enum {
};
static GParamSpec *gParamSpecs [LAST_PROP];
+static GFile *gHomeDir;
IdeProjectInfo *
gb_greeter_project_row_get_project_info (GbGreeterProjectRow *self)
@@ -70,12 +73,68 @@ gb_greeter_project_row_set_project_info (GbGreeterProjectRow *self,
}
}
+static gboolean
+humanize_date_time (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ GDateTime *dt;
+ gchar *str;
+
+ g_assert (G_VALUE_HOLDS (from_value, G_TYPE_DATE_TIME));
+ g_assert (G_VALUE_HOLDS (to_value, G_TYPE_STRING));
+
+ if (!(dt = g_value_get_boxed (from_value)))
+ return FALSE;
+
+ str = gb_date_time_format_for_display (dt);
+ g_value_take_string (to_value, str);
+
+ return TRUE;
+}
+
+static gboolean
+truncate_location (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
+{
+ GFile *file;
+ gchar *uri;
+
+ g_assert (G_VALUE_HOLDS (from_value, G_TYPE_FILE));
+ g_assert (G_VALUE_HOLDS (to_value, G_TYPE_STRING));
+
+ if (!(file = g_value_get_object (from_value)))
+ return FALSE;
+
+ if (g_file_is_native (file))
+ {
+ gchar *relative_path;
+
+ if ((relative_path = g_file_get_relative_path (gHomeDir, file)) ||
+ (relative_path = g_file_get_path (file)))
+ {
+ g_value_set_string (to_value, relative_path);
+ return TRUE;
+ }
+ }
+
+ uri = g_file_get_uri (file);
+ g_value_set_string (to_value, uri);
+
+ return TRUE;
+}
+
static void
gb_greeter_project_row_finalize (GObject *object)
{
GbGreeterProjectRow *self = (GbGreeterProjectRow *)object;
g_clear_object (&self->project_info);
+ g_clear_object (&self->bindings);
+ g_clear_object (&self->home_dir);
G_OBJECT_CLASS (gb_greeter_project_row_parent_class)->finalize (object);
}
@@ -142,6 +201,8 @@ gb_greeter_project_row_class_init (GbGreeterProjectRowClass *klass)
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROJECT_INFO,
gParamSpecs [PROP_PROJECT_INFO]);
+
+ gHomeDir = g_file_new_for_path (g_get_home_dir ());
}
static void
@@ -152,9 +213,12 @@ gb_greeter_project_row_init (GbGreeterProjectRow *self)
self->bindings = egg_binding_set_new ();
egg_binding_set_bind (self->bindings, "name", self->title_label, "label", 0);
+ egg_binding_set_bind_full (self->bindings, "last-modified-at", self->date_label, "label", 0,
+ humanize_date_time, NULL, NULL, NULL);
+ egg_binding_set_bind_full (self->bindings, "directory", self->location_label, "label", 0,
+ truncate_location, NULL, NULL, NULL);
#if 0
egg_binding_set_bind (self->bindings, "directory", self->location_label, "label", 0);
egg_binding_set_bind (self->bindings, "description", self->description_label, "label", 0);
- egg_binding_set_bind (self->bindings, "last-modified-at", self->date_label, "label", 0);
#endif
}
diff --git a/src/greeter/gb-greeter-window.c b/src/greeter/gb-greeter-window.c
index 21bad6f..0712e4d 100644
--- a/src/greeter/gb-greeter-window.c
+++ b/src/greeter/gb-greeter-window.c
@@ -25,6 +25,7 @@
#include "gb-greeter-project-row.h"
#include "gb-greeter-window.h"
+#include "gb-gtk.h"
#include "gb-scrolled-window.h"
struct _GbGreeterWindow
@@ -57,6 +58,38 @@ gb_greeter_window_get_recent_projects (GbGreeterWindow *self)
return self->recent_projects;
}
+static void
+gb_greeter_window__recent_projects_items_changed (GbGreeterWindow *self,
+ guint position,
+ guint removed,
+ guint added,
+ GListModel *list_model)
+{
+ IdeRecentProjects *recent_projects = (IdeRecentProjects *)list_model;
+ GbGreeterProjectRow *row;
+ gsize i;
+
+ g_assert (GB_IS_GREETER_WINDOW (self));
+ g_assert (G_IS_LIST_MODEL (list_model));
+ g_assert (IDE_IS_RECENT_PROJECTS (recent_projects));
+
+ for (i = 0; i < added; i++)
+ {
+ IdeProjectInfo *project_info;
+
+ project_info = g_list_model_get_item (list_model, position + i);
+
+ if (!ide_project_info_get_is_recent (project_info))
+ continue;
+
+ row = g_object_new (GB_TYPE_GREETER_PROJECT_ROW,
+ "visible", TRUE,
+ "project-info", project_info,
+ NULL);
+ gtk_list_box_insert (self->my_projects_list_box, GTK_WIDGET (row), position + i);
+ }
+}
+
void
gb_greeter_window_set_recent_projects (GbGreeterWindow *self,
IdeRecentProjects *recent_projects)
@@ -67,43 +100,22 @@ gb_greeter_window_set_recent_projects (GbGreeterWindow *self,
if (g_set_object (&self->recent_projects, recent_projects))
{
egg_signal_group_set_target (self->signal_group, recent_projects);
- g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_RECENT_PROJECTS]);
- }
-}
-static void
-gb_greeter_window_row_header_cb (GtkListBoxRow *row,
- GtkListBoxRow *before,
- gpointer user_data)
-{
- g_assert (GTK_IS_LIST_BOX_ROW (row));
+ if (recent_projects != NULL)
+ {
+ GListModel *list_model;
+ guint n_items;
- if (before != NULL)
- {
- GtkWidget *header;
+ list_model = G_LIST_MODEL (recent_projects);
+ n_items = g_list_model_get_n_items (list_model);
+ gb_greeter_window__recent_projects_items_changed (self, 0, 0, n_items, list_model);
+ }
- header = g_object_new (GTK_TYPE_SEPARATOR,
- "orientation", GTK_ORIENTATION_HORIZONTAL,
- "visible", TRUE,
- NULL);
- gtk_list_box_row_set_header (row, header);
+ g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_RECENT_PROJECTS]);
}
}
static void
-gb_greeter_window__recent_projects_items_changed (GListModel *list_model,
- guint position,
- guint removed,
- guint added,
- gpointer user_data)
-{
- IdeRecentProjects *recent_projects = (IdeRecentProjects *)list_model;
-
- g_assert (G_IS_LIST_MODEL (list_model));
- g_assert (IDE_IS_RECENT_PROJECTS (recent_projects));
-}
-
-static void
gb_greeter_window_finalize (GObject *object)
{
GbGreeterWindow *self = (GbGreeterWindow *)object;
@@ -184,7 +196,6 @@ static void
gb_greeter_window_init (GbGreeterWindow *self)
{
self->signal_group = egg_signal_group_new (IDE_TYPE_RECENT_PROJECTS);
-
egg_signal_group_connect_object (self->signal_group,
"items-changed",
G_CALLBACK (gb_greeter_window__recent_projects_items_changed),
@@ -194,6 +205,6 @@ gb_greeter_window_init (GbGreeterWindow *self)
gtk_widget_init_template (GTK_WIDGET (self));
gtk_list_box_set_header_func (self->my_projects_list_box,
- gb_greeter_window_row_header_cb,
+ gb_gtk_list_box_row_separator_func,
NULL, NULL);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]