summaryrefslogtreecommitdiff
path: root/wikipedia/models
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2013-08-02 14:55:29 -0700
committerPhilip Chimento <philip@endlessm.com>2013-08-02 17:42:45 -0700
commit3515a9d94829f42133ab8ef2779574e8a605d3cc (patch)
tree1d9eaeb7079e67f68b0418b1b643a6cd2d3aa5c1 /wikipedia/models
parentbdc0fb8dadb8982ee74c50d3178fb1ce30db1b66 (diff)
Integrate Wikipedia into SDK build system
Now you should be able to import the app generator using const EndlessWikipedia = imports.wikipedia.EndlessWikipedia; [endlessm/eos-sdk#206] [endlessm/eos-sdk#206]
Diffstat (limited to 'wikipedia/models')
-rw-r--r--wikipedia/models/article_model.js22
-rw-r--r--wikipedia/models/category_model.js37
-rw-r--r--wikipedia/models/domain_wiki_model.js48
-rw-r--r--wikipedia/models/utils/json_utils.js56
-rw-r--r--wikipedia/models/utils/locale_utils.js19
5 files changed, 182 insertions, 0 deletions
diff --git a/wikipedia/models/article_model.js b/wikipedia/models/article_model.js
new file mode 100644
index 0000000..ac6ea49
--- /dev/null
+++ b/wikipedia/models/article_model.js
@@ -0,0 +1,22 @@
+const Endless = imports.gi.Endless;
+const GObject = imports.gi.GObject;
+const Lang = imports.lang;
+
+
+const ArticleModel = new Lang.Class({
+ Name: "ArticleModel",
+ Extends: GObject.Object,
+ Properties: {
+ 'title': GObject.ParamSpec.string('title', 'Article Title', 'Human Readable Article Title',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT,
+ ""),
+ 'uri': GObject.ParamSpec.string('uri', 'Article URI', 'Title URI as stored in wikipedia database',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT,
+ "")
+ },
+
+ _init: function(params) {
+ this.parent(params);
+ }
+
+}); \ No newline at end of file
diff --git a/wikipedia/models/category_model.js b/wikipedia/models/category_model.js
new file mode 100644
index 0000000..ea9bfb6
--- /dev/null
+++ b/wikipedia/models/category_model.js
@@ -0,0 +1,37 @@
+const Endless = imports.gi.Endless;
+const GObject = imports.gi.GObject;
+const Lang = imports.lang;
+
+// Local libraries
+const ArticleModel = imports.models.article_model;
+
+const CategoryModel = new Lang.Class({
+ Name: "CategoryModel",
+ Extends: GObject.Object,
+ Properties: {
+ 'description': GObject.ParamSpec.string('description', 'Category Description', 'This is the text that the user reads on the category page.',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT,
+ ""),
+ 'title': GObject.ParamSpec.string('title', 'Category Name', 'This is the name that is displayed on the front page and as the title on the category page.',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT,
+ ""),
+ 'image-uri': GObject.ParamSpec.string('image-uri', 'Category Image URI', 'Path to image for this category in the GResource',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT,
+ ""),
+ 'image-thumbnail-uri': GObject.ParamSpec.string('image-thumbnail-uri', 'Category Thumbnail Image URI', 'Path to thumbnail image for this category in the GResource',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT,
+ ""),
+ },
+
+ _init: function(params) {
+ this.parent(params);
+ },
+
+ addArticles: function(articles) {
+ this._articles = articles;
+ },
+
+ getArticles: function() {
+ return this._articles;
+ }
+}); \ No newline at end of file
diff --git a/wikipedia/models/domain_wiki_model.js b/wikipedia/models/domain_wiki_model.js
new file mode 100644
index 0000000..c838361
--- /dev/null
+++ b/wikipedia/models/domain_wiki_model.js
@@ -0,0 +1,48 @@
+
+const Endless = imports.gi.Endless;
+const Gio = imports.gi.Gio;
+const GObject = imports.gi.GObject;
+const Lang = imports.lang;
+
+// Local libraries
+const CategoryModel = imports.models.category_model;
+const Utils = imports.utils;
+
+const DomainWikiModel = new Lang.Class({
+
+ Name: "DomainWikiModel",
+ Extends: GObject.Object,
+ Properties: {
+ 'image-uri': GObject.ParamSpec.string('image-uri',
+ 'Application image URI',
+ 'URI describing a path to the image for this application.',
+ GObject.ParamFlags.READABLE | GObject.ParamFlags.WRITABLE | GObject.ParamFlags.CONSTRUCT_ONLY,
+ ''),
+
+ // Name of the Wikipedia-based application, e.g. 'Brazil', 'Math'
+ 'application-name': GObject.ParamSpec.string('application-name',
+ 'Application name',
+ 'Name of the Wikipedia-based application',
+ GObject.ParamFlags.READABLE,
+ '')
+ },
+
+ //params should have the image-uri for the app's image, and the application name.
+ _init: function(params) {
+ this.parent(params);
+ },
+
+ //categories should be a list of category models, already populated with article models.
+ addCategories: function(categories){
+ this._categories = categories;
+ },
+
+ getArticlesForCategoryIndex: function(index){
+ let category = this.getCategories()[index];
+ return category.getArticles();
+ },
+
+ getCategories: function() {
+ return this._categories;
+ }
+}); \ No newline at end of file
diff --git a/wikipedia/models/utils/json_utils.js b/wikipedia/models/utils/json_utils.js
new file mode 100644
index 0000000..b66b388
--- /dev/null
+++ b/wikipedia/models/utils/json_utils.js
@@ -0,0 +1,56 @@
+const Gio = imports.gi.Gio;
+const Json = imports.gi.Json;
+const Gettext = imports.gettext;
+
+const _JSON_VAL_STRING = 0;
+const _JSON_VAL_INT = 1;
+const _JSON_VAL_DOUBLE = 2;
+const _JSON_VAL_BOOLEAN = 3;
+
+
+function getJsonMemberStringValue(reader, key) {
+
+ return _getJsonMemberValue(reader, key, _JSON_VAL_STRING);
+}
+
+function getJsonMemberIntValue(reader, key) {
+
+ return _getJsonMemberValue(reader, key, _JSON_VAL_INT);
+}
+
+function getJsonMemberDoubleValue(reader, key) {
+
+ return _getJsonMemberValue(reader, key, _JSON_VAL_DOUBLE);
+}
+
+function getJsonMemberBooleanValue(reader, key) {
+
+ return _getJsonMemberValue(reader, key, _JSON_VAL_BOOLEAN);
+}
+
+function getJsonMemberLocalizedValue(reader, key) {
+
+ return Gettext.gettext(_getJsonMemberValue(reader, key + '_', _JSON_VAL_STRING));
+}
+
+function _getJsonMemberValue(reader, key, type) {
+
+ reader.read_member(key);
+ let value;
+ switch(type) {
+ case _JSON_VAL_STRING:
+ value = reader.get_string_value();
+ break;
+ case _JSON_VAL_INT:
+ value = reader.get_int_value();
+ break;
+ case _JSON_VAL_DOUBLE:
+ value = reader.get_double_value();
+ break;
+ case _JSON_VAL_BOOLEAN:
+ value = reader.get_boolean_value();
+ break;
+ }
+ reader.end_member();
+ return value;
+}
diff --git a/wikipedia/models/utils/locale_utils.js b/wikipedia/models/utils/locale_utils.js
new file mode 100644
index 0000000..71d177a
--- /dev/null
+++ b/wikipedia/models/utils/locale_utils.js
@@ -0,0 +1,19 @@
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+
+
+function getSubdirectoryWithLocale(theDir) {
+
+ let locales = GLib.get_language_names();
+ let dir = Gio.File.new_for_path(theDir);
+ let localeSegment = 'C';
+
+ for(let i=0; i<locales.length; i++) {
+ let currLocale = dir.get_child(locales[i]);
+ if(currLocale.query_exists(null)) {
+ localeSegment = locales[i];
+ break;
+ }
+ }
+ return theDir + localeSegment + '/';
+} \ No newline at end of file