[gnome-boxes/wip/generic-gnome-cont: 3/4] os-db: Add list_os_by_distro method
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/generic-gnome-cont: 3/4] os-db: Add list_os_by_distro method
- Date: Thu, 3 Oct 2013 01:06:40 +0000 (UTC)
commit f00876f194bdcee603db10db9beab47fee7f5453
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Oct 3 03:46:39 2013 +0300
os-db: Add list_os_by_distro method
Add a method to get a list of OS entries given a distro name.
Optionally, caller can pass a GLib.Date to only list OSes released (or
to be released) after a particular date.
src/os-database.vala | 38 ++++++++++++++++++++++++++++++++++++++
1 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/os-database.vala b/src/os-database.vala
index b37df23..a93372e 100644
--- a/src/os-database.vala
+++ b/src/os-database.vala
@@ -82,6 +82,44 @@ private class Boxes.OSDatabase : GLib.Object {
return os;
}
+ // Returned list is in ascending order by release dates. If release date is
+ // unavailable, we assume that OS is very old, or at least older than
+ // entries with release dates and @after.
+ // If @after is non-null, only list releases after the given date.
+ public async GLib.List<Os> list_os_by_distro (string distro, GLib.Date? after = null) throws
OSDatabaseError {
+ if (!yield ensure_db_loaded ())
+ throw new OSDatabaseError.DB_LOADING_FAILED ("Failed to load OS database");
+
+ var os_list = db.get_os_list ();
+ var filter = new Filter ();
+ filter.add_constraint (OS_PROP_DISTRO, distro);
+ os_list = (os_list as Osinfo.List).new_filtered (filter) as OsList;
+
+ var after_list = new GLib.List<Os> ();
+ foreach (var entity in os_list.get_elements ()) {
+ if (after != null) {
+ var release_date = (entity as Os).get_release_date ();
+ if (release_date != null && release_date.compare (after) > 0)
+ after_list.append (entity as Os);
+ } else
+ after_list.append (entity as Os);
+ }
+
+ after_list.sort ((os_a, os_b) => {
+ var release_a = os_a.get_release_date ();
+ var release_b = os_b.get_release_date ();
+
+ if (release_a == null)
+ return 1;
+ else if (release_b == null)
+ return -1;
+ else
+ return release_a.compare (release_b);
+ });
+
+ return after_list;
+ }
+
public Media get_media_by_id (Os os, string id) throws OSDatabaseError {
var medias = os.get_media_list ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]