[gnome-builder] project-info: add compare helper
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] project-info: add compare helper
- Date: Wed, 22 Apr 2015 21:52:27 +0000 (UTC)
commit 92944b65994b9175ef1b2fca8215d702ca22daf1
Author: Christian Hergert <christian hergert me>
Date: Wed Apr 22 14:50:08 2015 -0700
project-info: add compare helper
This adds ide_project_info_compare() to IdeProjectInfo so that it can
be reused in various places.
libide/ide-project-info.c | 47 ++++++++++++++++++++++++++++++++++++++++++++-
libide/ide-project-info.h | 2 +
2 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/libide/ide-project-info.c b/libide/ide-project-info.c
index 2edfe59..dfd6d69 100644
--- a/libide/ide-project-info.c
+++ b/libide/ide-project-info.c
@@ -16,9 +16,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#define G_LOG_DOMAIN "ide-project-info"
#include <glib/gi18n.h>
+#include <string.h>
#include "ide-project-info.h"
@@ -33,7 +38,7 @@
struct _IdeProjectInfo
{
- GObject parent_instance;
+ GObject parent_instance;
GDateTime *last_modified_at;
GFile *directory;
@@ -324,3 +329,43 @@ static void
ide_project_info_init (IdeProjectInfo *self)
{
}
+
+gint
+ide_project_info_compare (IdeProjectInfo *info1,
+ IdeProjectInfo *info2)
+{
+ const gchar *name1;
+ const gchar *name2;
+ GDateTime *dt1;
+ GDateTime *dt2;
+ gint ret;
+ gint prio1;
+ gint prio2;
+
+ g_assert (IDE_IS_PROJECT_INFO (info1));
+ g_assert (IDE_IS_PROJECT_INFO (info2));
+
+ prio1 = ide_project_info_get_priority (info1);
+ prio2 = ide_project_info_get_priority (info2);
+
+ if (prio1 != prio2)
+ return prio1 - prio2;
+
+ dt1 = ide_project_info_get_last_modified_at (info1);
+ dt2 = ide_project_info_get_last_modified_at (info2);
+
+ ret = g_date_time_compare (dt2, dt1);
+
+ if (ret != 0)
+ return ret;
+
+ name1 = ide_project_info_get_name (info1);
+ name2 = ide_project_info_get_name (info2);
+
+ if (name1 == NULL)
+ return 1;
+ else if (name2 == NULL)
+ return -1;
+ else
+ return strcasecmp (name1, name2);
+}
diff --git a/libide/ide-project-info.h b/libide/ide-project-info.h
index a547d71..9616474 100644
--- a/libide/ide-project-info.h
+++ b/libide/ide-project-info.h
@@ -27,6 +27,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (IdeProjectInfo, ide_project_info, IDE, PROJECT_INFO, GObject)
+gint ide_project_info_compare (IdeProjectInfo *info1,
+ IdeProjectInfo *info2);
GFile *ide_project_info_get_file (IdeProjectInfo *self);
GFile *ide_project_info_get_directory (IdeProjectInfo *self);
gint ide_project_info_get_priority (IdeProjectInfo *self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]