summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Kang <jonathan121537@gmail.com>2014-11-20 15:29:13 +0800
committerDavid King <davidk@gnome.org>2014-12-03 08:48:44 +0000
commita8fa51368b8515f751d96c5fdc69570f463015c8 (patch)
tree1773ad3ba0c3e75cf1e3aa2f5e722aa265616c3b
parentbca82bc5f81c2609bac66c1094749ba5bcd49321 (diff)
downloadgnome-logs-a8fa51368b8515f751d96c5fdc69570f463015c8.tar.gz
Add an option for log view direction
https://bugzilla.gnome.org/show_bug.cgi?id=709160
-rw-r--r--.gitignore2
-rw-r--r--Makefile.am7
-rw-r--r--configure.ac2
-rw-r--r--data/org.gnome.Logs.gschema.xml10
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/gl-application.c33
-rw-r--r--src/gl-application.h7
-rw-r--r--src/gl-eventview.c15
-rw-r--r--src/gl-eventview.h3
-rw-r--r--src/gl-eventviewlist.c94
-rw-r--r--src/gl-eventviewlist.h3
-rw-r--r--src/gl-window.c15
-rw-r--r--src/gl-window.h3
13 files changed, 195 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 4ea4637..830408e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,6 +8,7 @@ Makefile.in
/data/org.gnome.Logs.appdata.valid
/data/org.gnome.Logs.appdata.xml
/data/org.gnome.Logs.desktop
+/data/org.gnome.Logs.gschema.valid
/data/org.gnome.Logs.service
/data/version.xml
/help/*/*.mo
@@ -16,6 +17,7 @@ Makefile.in
/help/*/legal.xml
!/help/C
/m4/
+/org.gnome.Logs.enums.xml
/po/.intltool-merge-cache
/po/Makefile.in*
/po/POTFILES
diff --git a/Makefile.am b/Makefile.am
index 5a0c4a2..6bbeeec 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -90,6 +90,12 @@ servicedir = $(datadir)/dbus-1/services
service_in_files = data/org.gnome.Logs.service.in
service_DATA = $(service_in_files:.service.in=.service)
+gsettings_ENUM_FILES = src/gl-application.h
+gsettings_ENUM_NAMESPACE = org.gnome.Logs
+gsettings_SCHEMAS = data/org.gnome.Logs.gschema.xml
+data/org.gnome.Logs.gschema.valid: data/.dstamp
+@GSETTINGS_RULES@
+
if ENABLE_MAN
data/gnome-logs.1: data/gnome-logs.xml
$(AM_V_GEN)xsltproc --nonet --path $(builddir)/data --output $(builddir)/data/ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
@@ -198,6 +204,7 @@ dist_noinst_DATA = \
$(appstream_in_files) \
$(desktop_in_files) \
$(service_in_files) \
+ $(gsettings_SCHEMAS) \
data/org.gnome.Logs.gresource.xml \
data/gnome-logs.xml \
data/icons/gnome-logs.svg
diff --git a/configure.ac b/configure.ac
index 02aeda8..0b2249d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,8 @@ GTK_REQUIRED="gtk+-3.0 >= 3.13.4"
SYSTEMD_JOURNAL_REQUIRED="libsystemd-journal"
PKG_CHECK_MODULES([LOGS], [$GIO_REQUIRED $GTK_REQUIRED $SYSTEMD_JOURNAL_REQUIRED])
+GLIB_GSETTINGS
+
AC_CONFIG_FILES([
data/version.xml
help/Makefile
diff --git a/data/org.gnome.Logs.gschema.xml b/data/org.gnome.Logs.gschema.xml
new file mode 100644
index 0000000..849096b
--- /dev/null
+++ b/data/org.gnome.Logs.gschema.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<schemalist>
+ <schema id="org.gnome.Logs" path="/org/gnome/logs/">
+ <key name="sort-order" enum="org.gnome.Logs.GlSortOrder">
+ <summary>How to sort list rows in the event view list</summary>
+ <description>Sort list rows in ascending or descending order for the selected type</description>
+ <default>'descending-time'</default>
+ </key>
+ </schema>
+</schemalist>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 90d9d55..e902d19 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@
[type: gettext/glade]data/menus.ui
data/org.gnome.Logs.appdata.xml.in
data/org.gnome.Logs.desktop.in
+data/org.gnome.Logs.gschema.xml
src/gl-application.c
src/gl-eventviewdetail.c
src/gl-eventviewlist.c
diff --git a/src/gl-application.c b/src/gl-application.c
index 8f3dcd0..a4649c4 100644
--- a/src/gl-application.c
+++ b/src/gl-application.c
@@ -31,13 +31,16 @@
typedef struct
{
GSettings *desktop;
+ GSettings *settings;
gchar *monospace_font;
} GlApplicationPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GlApplication, gl_application, GTK_TYPE_APPLICATION)
static const gchar DESKTOP_SCHEMA[] = "org.gnome.desktop.interface";
+static const gchar SETTINGS_SCHEMA[] = "org.gnome.Logs";
static const gchar DESKTOP_MONOSPACE_FONT_NAME[] = "monospace-font-name";
+static const gchar SORT_ORDER[] = "sort-order";
static void
on_new_window (GSimpleAction *action,
@@ -118,6 +121,25 @@ on_quit (GSimpleAction *action,
}
static void
+on_sort_order_changed (GSettings *settings,
+ const gchar *key,
+ GlApplication *application)
+{
+ GList *window;
+ gint sort_order;
+
+ window = gtk_application_get_windows (GTK_APPLICATION (application));
+ sort_order = g_settings_get_enum (settings, SORT_ORDER);
+
+ /* refresh the event view list for every logs window */
+ while (window != NULL)
+ {
+ gl_window_set_sort_order (window->data, sort_order);
+ window = g_list_next (window);
+ }
+}
+
+static void
on_monospace_font_name_changed (GSettings *settings,
const gchar *key,
GlApplicationPrivate *priv)
@@ -233,6 +255,7 @@ gl_application_finalize (GObject *object)
priv = gl_application_get_instance_private (application);
g_clear_object (&priv->desktop);
+ g_clear_object (&priv->settings);
g_clear_pointer (&priv->monospace_font, g_free);
}
@@ -241,6 +264,7 @@ gl_application_init (GlApplication *application)
{
GlApplicationPrivate *priv;
gchar *changed_font;
+ GAction *action;
priv = gl_application_get_instance_private (application);
@@ -254,6 +278,15 @@ gl_application_init (GlApplication *application)
G_CALLBACK (on_monospace_font_name_changed),
priv);
+ priv->settings = g_settings_new (SETTINGS_SCHEMA);
+ action = g_settings_create_action (priv->settings, SORT_ORDER);
+ g_action_map_add_action (G_ACTION_MAP (application), action);
+
+ g_signal_connect (priv->settings, "changed::sort-order",
+ G_CALLBACK (on_sort_order_changed),
+ application);
+
+ g_object_unref (action);
g_free (changed_font);
}
diff --git a/src/gl-application.h b/src/gl-application.h
index d853812..af23ae9 100644
--- a/src/gl-application.h
+++ b/src/gl-application.h
@@ -35,6 +35,13 @@ typedef struct
GtkApplicationClass parent_class;
} GlApplicationClass;
+/* Types of sorting. See the GSettings key "sort-order". */
+typedef enum
+{
+ GL_SORT_ORDER_ASCENDING_TIME,
+ GL_SORT_ORDER_DESCENDING_TIME
+} GlSortOrder;
+
#define GL_TYPE_APPLICATION (gl_application_get_type ())
#define GL_APPLICATION(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GL_TYPE_APPLICATION, GlApplication))
diff --git a/src/gl-eventview.c b/src/gl-eventview.c
index 1df5148..8a82546 100644
--- a/src/gl-eventview.c
+++ b/src/gl-eventview.c
@@ -100,6 +100,21 @@ gl_event_view_set_search_mode (GlEventView *view,
gl_event_view_list_set_search_mode (events, state);
}
+void
+gl_event_view_set_sort_order (GlEventView *view,
+ GlSortOrder sort_order)
+{
+ GlEventViewPrivate *priv;
+ GlEventViewList *events;
+
+ g_return_if_fail (GL_EVENT_VIEW (view));
+
+ priv = gl_event_view_get_instance_private (view);
+ events = GL_EVENT_VIEW_LIST (priv->events);
+
+ gl_event_view_list_set_sort_order (events, sort_order);
+}
+
static void
on_notify_mode (GlEventView *view,
GParamSpec *pspec,
diff --git a/src/gl-eventview.h b/src/gl-eventview.h
index 67e6e1a..53a7627 100644
--- a/src/gl-eventview.h
+++ b/src/gl-eventview.h
@@ -22,6 +22,8 @@
#include <gtk/gtk.h>
+#include "gl-application.h"
+
G_BEGIN_DECLS
typedef struct
@@ -59,6 +61,7 @@ void gl_event_view_set_mode (GlEventView *view, GlEventViewMode mode);
void gl_event_view_show_detail (GlEventView *view);
gboolean gl_event_view_handle_search_event (GlEventView *view, GAction *action, GdkEvent *event);
void gl_event_view_set_search_mode (GlEventView *view, gboolean state);
+void gl_event_view_set_sort_order (GlEventView *view, GlSortOrder sort_order);
G_END_DECLS
diff --git a/src/gl-eventviewlist.c b/src/gl-eventviewlist.c
index 0588536..9f7f529 100644
--- a/src/gl-eventviewlist.c
+++ b/src/gl-eventviewlist.c
@@ -54,7 +54,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (GlEventViewList, gl_event_view_list, GTK_TYPE_BOX)
static const gssize N_RESULTS = -1;
static const gssize N_RESULTS_IDLE = 25;
static const gchar DESKTOP_SCHEMA[] = "org.gnome.desktop.interface";
+static const gchar SETTINGS_SCHEMA[] = "org.gnome.Logs";
static const gchar CLOCK_FORMAT[] = "clock-format";
+static const gchar SORT_ORDER[] = "sort-order";
static gboolean
gl_event_view_search_is_case_sensitive (GlEventViewList *view)
@@ -860,6 +862,8 @@ on_notify_category (GlCategoryList *list,
GtkStack *stack;
GtkWidget *scrolled;
GtkWidget *viewport;
+ GSettings *settings;
+ gint sort_order;
view = GL_EVENT_VIEW_LIST (user_data);
priv = gl_event_view_list_get_instance_private (view);
@@ -923,6 +927,96 @@ on_notify_category (GlCategoryList *list,
scrolled = gtk_stack_get_visible_child (stack);
viewport = gtk_bin_get_child (GTK_BIN (scrolled));
priv->active_listbox = GTK_LIST_BOX (gtk_bin_get_child (GTK_BIN (viewport)));
+
+ settings = g_settings_new (SETTINGS_SCHEMA);
+ sort_order = g_settings_get_enum (settings, SORT_ORDER);
+ g_object_unref (settings);
+ gl_event_view_list_set_sort_order (view, sort_order);
+}
+
+static gint
+gl_event_view_sort_by_ascending_time (GtkListBoxRow *row1,
+ GtkListBoxRow *row2)
+{
+ GlJournalResult *result1;
+ GlJournalResult *result2;
+ guint64 time1;
+ guint64 time2;
+
+ result1 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row1));
+ result2 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row2));
+ time1 = result1->timestamp;
+ time2 = result2->timestamp;
+
+ if (time1 > time2)
+ {
+ return 1;
+ }
+ else if (time1 < time2)
+ {
+ return -1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+static gint
+gl_event_view_sort_by_descending_time (GtkListBoxRow *row1,
+ GtkListBoxRow *row2)
+{
+ GlJournalResult *result1;
+ GlJournalResult *result2;
+ guint64 time1;
+ guint64 time2;
+
+ result1 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row1));
+ result2 = gl_event_view_row_get_result (GL_EVENT_VIEW_ROW (row2));
+ time1 = result1->timestamp;
+ time2 = result2->timestamp;
+
+ if (time1 > time2)
+ {
+ return -1;
+ }
+ else if (time1 < time2)
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+void
+gl_event_view_list_set_sort_order (GlEventViewList *view,
+ GlSortOrder sort_order)
+{
+ GlEventViewListPrivate *priv;
+
+ g_return_if_fail (GL_EVENT_VIEW_LIST (view));
+
+ priv = gl_event_view_list_get_instance_private (view);
+
+ switch (sort_order)
+ {
+ case GL_SORT_ORDER_ASCENDING_TIME:
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->active_listbox),
+ (GtkListBoxSortFunc) gl_event_view_sort_by_ascending_time,
+ NULL, NULL);
+ break;
+ case GL_SORT_ORDER_DESCENDING_TIME:
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->active_listbox),
+ (GtkListBoxSortFunc) gl_event_view_sort_by_descending_time,
+ NULL, NULL);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
}
static void
diff --git a/src/gl-eventviewlist.h b/src/gl-eventviewlist.h
index 22d50a0..64956d0 100644
--- a/src/gl-eventviewlist.h
+++ b/src/gl-eventviewlist.h
@@ -20,6 +20,8 @@
#define GL_EVENT_VIEW_LIST_H_
#include <gtk/gtk.h>
+
+#include "gl-application.h"
#include "gl-journal.h"
G_BEGIN_DECLS
@@ -47,6 +49,7 @@ gboolean gl_event_view_list_handle_search_event (GlEventViewList *view,
GAction *action,
GdkEvent *event);
void gl_event_view_list_set_search_mode (GlEventViewList *view, gboolean state);
+void gl_event_view_list_set_sort_order (GlEventViewList *view, GlSortOrder sort_order);
G_END_DECLS
diff --git a/src/gl-window.c b/src/gl-window.c
index fc6f6b6..6b97fba 100644
--- a/src/gl-window.c
+++ b/src/gl-window.c
@@ -217,6 +217,21 @@ on_gl_window_key_press_event (GlWindow *window,
return GDK_EVENT_PROPAGATE;
}
+void
+gl_window_set_sort_order (GlWindow *window,
+ GlSortOrder sort_order)
+{
+ GlWindowPrivate *priv;
+ GlEventView *event;
+
+ g_return_if_fail (GL_WINDOW (window));
+
+ priv = gl_window_get_instance_private (window);
+ event = GL_EVENT_VIEW (priv->event);
+
+ gl_event_view_set_sort_order (event, sort_order);
+}
+
static GActionEntry actions[] = {
{ "view-mode", on_action_radio, "s", "'list'", on_view_mode },
{ "toolbar-mode", on_action_radio, "s", "'list'", on_toolbar_mode },
diff --git a/src/gl-window.h b/src/gl-window.h
index 7123745..0e9da24 100644
--- a/src/gl-window.h
+++ b/src/gl-window.h
@@ -21,6 +21,8 @@
#include <gtk/gtk.h>
+#include "gl-application.h"
+
G_BEGIN_DECLS
typedef struct
@@ -40,6 +42,7 @@ typedef struct
GType gl_window_get_type (void);
GtkWidget * gl_window_new (GtkApplication *application);
+void gl_window_set_sort_order (GlWindow *window, GlSortOrder sort_order);
G_END_DECLS