Back to index

unity  6.0.0
test_service_model.c
Go to the documentation of this file.
00001 #include "test_service_model.h"
00002 
00003 G_DEFINE_TYPE(ServiceModel, service_model, G_TYPE_OBJECT);
00004 
00005 static void service_model_create_model(ServiceModel* self);
00006 static void service_model_create_results(ServiceModel* self);
00007 static void service_model_create_categories(ServiceModel* self);
00008 
00009 static void
00010 service_model_dispose(GObject* object)
00011 {
00012   ServiceModel* self = SERVICE_MODEL(object);
00013 
00014   g_object_unref(self->model_);
00015   g_object_unref(self->results_model_);
00016   g_object_unref(self->categories_model_);
00017 }
00018 
00019 static void
00020 service_model_class_init(ServiceModelClass* klass)
00021 {
00022   G_OBJECT_CLASS(klass)->dispose = service_model_dispose;
00023 }
00024 
00025 static void
00026 service_model_init(ServiceModel* self)
00027 {
00028   service_model_create_model(self);
00029   service_model_create_results(self);
00030   service_model_create_categories(self);
00031 }
00032 
00033 static void
00034 service_model_create_model(ServiceModel* self)
00035 {
00036   self->model_ = dee_shared_model_new("com.canonical.test.model");
00037   dee_model_set_schema(self->model_, "u", "s", NULL);
00038 
00039   guint i;
00040   for (i = 0; i < 100; i++)
00041   {
00042     gchar* name = g_strdup_printf("Test%d", i);
00043     dee_model_append(self->model_, i, name);
00044     g_free(name);
00045   }
00046 }
00047 
00048 static void
00049 service_model_create_results(ServiceModel* self)
00050 {
00051   self->results_model_ = dee_shared_model_new("com.canonical.test.resultsmodel");
00052   dee_model_set_schema(self->results_model_, "s", "s", "u", "s", "s", "s", "s", NULL);
00053 
00054   int i;
00055   for(i = 0; i < 200; i++)
00056   {
00057     gchar* name = g_strdup_printf("Result%d", i);
00058     dee_model_append(self->results_model_,
00059                      name,
00060                      name,
00061                      (guint)i,
00062                      name,
00063                      name,
00064                      name,
00065                      name);
00066     g_free(name);
00067   }
00068 }
00069 
00070 static void
00071 service_model_create_categories(ServiceModel* self)
00072 {
00073   self->categories_model_ = dee_shared_model_new("com.canonical.test.categoriesmodel");
00074   dee_model_set_schema(self->categories_model_, "s", "s", "s", "a{sv}", NULL);
00075 
00076   GVariantBuilder b;
00077   g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}"));
00078   GVariant *hints = g_variant_builder_end(&b);
00079 
00080   int i;
00081   for(i = 0; i < 5; i++)
00082   {
00083     gchar* name = g_strdup_printf("Category%d", i);
00084     dee_model_append(self->categories_model_,
00085                      name,
00086                      "gtk-apply",
00087                      "grid",
00088                      hints);
00089     g_free(name);
00090   }
00091   g_variant_unref(hints);
00092 }
00093 
00094 ServiceModel*
00095 service_model_new()
00096 {
00097   return g_object_new(SERVICE_TYPE_MODEL, NULL);
00098 }