Logo Search packages:      
Sourcecode: valatoys version File versions  Download package

templates.c

/* templates.c generated by valac 0.10.0, the Vala compiler
 * generated from templates.vala, do not modify */

/* templates.vala
 *
 * Copyright (C) 2010  Andrea Del Signore
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 *    Andrea Del Signore <sejerpz@tin.it>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <config.h>
#include <glib/gstdio.h>


#define GEN_PROJECT_TYPE_TEMPLATES (gen_project_templates_get_type ())
#define GEN_PROJECT_TEMPLATES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEN_PROJECT_TYPE_TEMPLATES, GenProjectTemplates))
#define GEN_PROJECT_TEMPLATES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEN_PROJECT_TYPE_TEMPLATES, GenProjectTemplatesClass))
#define GEN_PROJECT_IS_TEMPLATES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEN_PROJECT_TYPE_TEMPLATES))
#define GEN_PROJECT_IS_TEMPLATES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEN_PROJECT_TYPE_TEMPLATES))
#define GEN_PROJECT_TEMPLATES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEN_PROJECT_TYPE_TEMPLATES, GenProjectTemplatesClass))

typedef struct _GenProjectTemplates GenProjectTemplates;
typedef struct _GenProjectTemplatesClass GenProjectTemplatesClass;
typedef struct _GenProjectTemplatesPrivate GenProjectTemplatesPrivate;

#define GEN_PROJECT_TYPE_TEMPLATE_DEFINITION (gen_project_template_definition_get_type ())
#define GEN_PROJECT_TEMPLATE_DEFINITION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION, GenProjectTemplateDefinition))
#define GEN_PROJECT_TEMPLATE_DEFINITION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION, GenProjectTemplateDefinitionClass))
#define GEN_PROJECT_IS_TEMPLATE_DEFINITION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION))
#define GEN_PROJECT_IS_TEMPLATE_DEFINITION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION))
#define GEN_PROJECT_TEMPLATE_DEFINITION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEN_PROJECT_TYPE_TEMPLATE_DEFINITION, GenProjectTemplateDefinitionClass))

typedef struct _GenProjectTemplateDefinition GenProjectTemplateDefinition;
typedef struct _GenProjectTemplateDefinitionClass GenProjectTemplateDefinitionClass;
#define __g_list_free_g_object_unref0(var) ((var == NULL) ? NULL : (var = (_g_list_free_g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_dir_close0(var) ((var == NULL) ? NULL : (var = (g_dir_close (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GenProjectTemplates {
      GObject parent_instance;
      GenProjectTemplatesPrivate * priv;
};

struct _GenProjectTemplatesClass {
      GObjectClass parent_class;
};

00069 struct _GenProjectTemplatesPrivate {
      GList* _definitions;
      gint _next_id;
};


static gpointer gen_project_templates_parent_class = NULL;

GType gen_project_templates_get_type (void) G_GNUC_CONST;
GType gen_project_template_definition_get_type (void) G_GNUC_CONST;
#define GEN_PROJECT_TEMPLATES_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GEN_PROJECT_TYPE_TEMPLATES, GenProjectTemplatesPrivate))
enum  {
      GEN_PROJECT_TEMPLATES_DUMMY_PROPERTY,
      GEN_PROJECT_TEMPLATES_DEFINITIONS
};
static void _g_list_free_g_object_unref (GList* self);
static GenProjectTemplates* gen_project_templates_new (void);
static GenProjectTemplates* gen_project_templates_construct (GType object_type);
GenProjectTemplates* gen_project_templates_load (char** user_path, int user_path_length1);
static void gen_project_templates_scan_path (GenProjectTemplates* self, const char* path);
static gint _lambda0_ (void* a, void* b);
const char* gen_project_template_definition_get_name (GenProjectTemplateDefinition* self);
static gint __lambda0__gcompare_func (void* a, void* b);
GenProjectTemplateDefinition* gen_project_template_definition_load (const char* filename);
void gen_project_template_definition_set_id (GenProjectTemplateDefinition* self, gint value);
GList* gen_project_templates_get_definitions (GenProjectTemplates* self);
static void gen_project_templates_finalize (GObject* obj);
static void gen_project_templates_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);



static void _g_list_free_g_object_unref (GList* self) {
      g_list_foreach (self, (GFunc) g_object_unref, NULL);
      g_list_free (self);
}


static GenProjectTemplates* gen_project_templates_construct (GType object_type) {
      GenProjectTemplates * self;
      self = (GenProjectTemplates*) g_object_new (object_type, NULL);
      return self;
}


static GenProjectTemplates* gen_project_templates_new (void) {
      return gen_project_templates_construct (GEN_PROJECT_TYPE_TEMPLATES);
}


static gpointer _g_object_ref0 (gpointer self) {
      return self ? g_object_ref (self) : NULL;
}


static gint _lambda0_ (void* a, void* b) {
      gint result = 0;
      GenProjectTemplateDefinition* t1;
      GenProjectTemplateDefinition* t2;
      t1 = _g_object_ref0 (GEN_PROJECT_TEMPLATE_DEFINITION (a));
      t2 = _g_object_ref0 (GEN_PROJECT_TEMPLATE_DEFINITION (b));
      result = g_strcmp0 (gen_project_template_definition_get_name (t1), gen_project_template_definition_get_name (t2));
      _g_object_unref0 (t2);
      _g_object_unref0 (t1);
      return result;
}


static gint __lambda0__gcompare_func (void* a, void* b) {
      gint result;
      result = _lambda0_ (a, b);
      return result;
}


GenProjectTemplates* gen_project_templates_load (char** user_path, int user_path_length1) {
      GenProjectTemplates* result = NULL;
      GenProjectTemplates* _result_;
      gint standard_path_length1;
      gint _standard_path_size_;
      char** _tmp1_;
      char** _tmp0_ = NULL;
      char** standard_path;
      _result_ = gen_project_templates_new ();
      standard_path = (_tmp1_ = (_tmp0_ = g_new0 (char*, 2 + 1), _tmp0_[0] = g_build_filename (PACKAGE_DATADIR, "templates", NULL), _tmp0_[1] = g_build_filename (g_get_user_data_dir (), "gen-project", "templates", NULL), _tmp0_), standard_path_length1 = 2, _standard_path_size_ = standard_path_length1, _tmp1_);
      {
            char** path_collection;
            int path_collection_length1;
            int path_it;
            path_collection = standard_path;
            path_collection_length1 = standard_path_length1;
            for (path_it = 0; path_it < standard_path_length1; path_it = path_it + 1) {
                  char* path;
                  path = g_strdup (path_collection[path_it]);
                  {
                        g_message ("templates.vala:49: scanning directory %s for templates", path);
                        gen_project_templates_scan_path (_result_, path);
                        _g_free0 (path);
                  }
            }
      }
      if (user_path != NULL) {
            {
                  char** path_collection;
                  int path_collection_length1;
                  int path_it;
                  path_collection = user_path;
                  path_collection_length1 = user_path_length1;
                  for (path_it = 0; path_it < user_path_length1; path_it = path_it + 1) {
                        char* path;
                        path = g_strdup (path_collection[path_it]);
                        {
                              g_message ("templates.vala:56: scanning user directory %s for templates", path);
                              gen_project_templates_scan_path (_result_, path);
                              _g_free0 (path);
                        }
                  }
            }
      }
      _result_->priv->_definitions = g_list_sort (_result_->priv->_definitions, __lambda0__gcompare_func);
      result = _result_;
      standard_path = (_vala_array_free (standard_path, standard_path_length1, (GDestroyNotify) g_free), NULL);
      return result;
}


static glong string_get_length (const char* self) {
      glong result;
      g_return_val_if_fail (self != NULL, 0L);
      result = g_utf8_strlen (self, (gssize) (-1));
      return result;
}


static char* string_substring (const char* self, glong offset, glong len) {
      char* result = NULL;
      glong string_length;
      const char* start;
      g_return_val_if_fail (self != NULL, NULL);
      string_length = string_get_length (self);
      if (offset < 0) {
            offset = string_length + offset;
            g_return_val_if_fail (offset >= 0, NULL);
      } else {
            g_return_val_if_fail (offset <= string_length, NULL);
      }
      if (len < 0) {
            len = string_length - offset;
      }
      g_return_val_if_fail ((offset + len) <= string_length, NULL);
      start = g_utf8_offset_to_pointer (self, offset);
      result = g_strndup (start, ((gchar*) g_utf8_offset_to_pointer (start, len)) - ((gchar*) start));
      return result;
}


static void gen_project_templates_scan_path (GenProjectTemplates* self, const char* path) {
      GError * _inner_error_ = NULL;
      g_return_if_fail (self != NULL);
      g_return_if_fail (path != NULL);
      {
            GDir* dir;
            if (!g_file_test (path, G_FILE_TEST_IS_DIR)) {
                  return;
            }
            dir = g_dir_open (path, 0, &_inner_error_);
            if (_inner_error_ != NULL) {
                  goto __catch5_g_error;
            }
            if (dir != NULL) {
                  char* file;
                  file = NULL;
                  while (TRUE) {
                        char* _tmp0_;
                        gboolean _tmp1_ = FALSE;
                        if (!((file = (_tmp0_ = g_strdup (g_dir_read_name (dir)), _g_free0 (file), _tmp0_)) != NULL)) {
                              break;
                        }
                        if (file != NULL) {
                              _tmp1_ = g_str_has_suffix (file, ".ini");
                        } else {
                              _tmp1_ = FALSE;
                        }
                        if (_tmp1_) {
                              char* _tmp2_;
                              char* _tmp3_;
                              char* template_name;
                              char* _tmp4_;
                              char* _tmp5_;
                              char* tar_filename;
                              template_name = (_tmp3_ = string_substring (_tmp2_ = g_path_get_basename (file), (glong) 0, string_get_length (file) - 4), _g_free0 (_tmp2_), _tmp3_);
                              tar_filename = (_tmp5_ = g_build_filename (path, _tmp4_ = g_strconcat (template_name, ".tar.gz", NULL), NULL), _g_free0 (_tmp4_), _tmp5_);
                              if (g_file_test (tar_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_SYMLINK)) {
                                    char* _tmp6_;
                                    GenProjectTemplateDefinition* _tmp7_;
                                    GenProjectTemplateDefinition* template_definition;
                                    template_definition = (_tmp7_ = gen_project_template_definition_load (_tmp6_ = g_build_filename (path, file, NULL)), _g_free0 (_tmp6_), _tmp7_);
                                    if (template_definition != NULL) {
                                          gen_project_template_definition_set_id (template_definition, self->priv->_next_id);
                                          self->priv->_definitions = g_list_append (self->priv->_definitions, _g_object_ref0 (template_definition));
                                          self->priv->_next_id++;
                                    }
                                    _g_object_unref0 (template_definition);
                              }
                              _g_free0 (tar_filename);
                              _g_free0 (template_name);
                        }
                  }
                  _g_free0 (file);
            }
            _g_dir_close0 (dir);
      }
      goto __finally5;
      __catch5_g_error:
      {
            GError * err;
            err = _inner_error_;
            _inner_error_ = NULL;
            {
                  g_critical ("templates.vala:97: error %s", err->message);
                  _g_error_free0 (err);
            }
      }
      __finally5:
      if (_inner_error_ != NULL) {
            g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
            g_clear_error (&_inner_error_);
            return;
      }
}


GList* gen_project_templates_get_definitions (GenProjectTemplates* self) {
      GList* result;
      g_return_val_if_fail (self != NULL, NULL);
      result = self->priv->_definitions;
      return result;
}


static void gen_project_templates_class_init (GenProjectTemplatesClass * klass) {
      gen_project_templates_parent_class = g_type_class_peek_parent (klass);
      g_type_class_add_private (klass, sizeof (GenProjectTemplatesPrivate));
      G_OBJECT_CLASS (klass)->get_property = gen_project_templates_get_property;
      G_OBJECT_CLASS (klass)->finalize = gen_project_templates_finalize;
      g_object_class_install_property (G_OBJECT_CLASS (klass), GEN_PROJECT_TEMPLATES_DEFINITIONS, g_param_spec_pointer ("definitions", "definitions", "definitions", G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
}


static void gen_project_templates_instance_init (GenProjectTemplates * self) {
      self->priv = GEN_PROJECT_TEMPLATES_GET_PRIVATE (self);
      self->priv->_definitions = NULL;
      self->priv->_next_id = 0;
}


static void gen_project_templates_finalize (GObject* obj) {
      GenProjectTemplates * self;
      self = GEN_PROJECT_TEMPLATES (obj);
      __g_list_free_g_object_unref0 (self->priv->_definitions);
      G_OBJECT_CLASS (gen_project_templates_parent_class)->finalize (obj);
}


GType gen_project_templates_get_type (void) {
      static volatile gsize gen_project_templates_type_id__volatile = 0;
      if (g_once_init_enter (&gen_project_templates_type_id__volatile)) {
            static const GTypeInfo g_define_type_info = { sizeof (GenProjectTemplatesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gen_project_templates_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GenProjectTemplates), 0, (GInstanceInitFunc) gen_project_templates_instance_init, NULL };
            GType gen_project_templates_type_id;
            gen_project_templates_type_id = g_type_register_static (G_TYPE_OBJECT, "GenProjectTemplates", &g_define_type_info, 0);
            g_once_init_leave (&gen_project_templates_type_id__volatile, gen_project_templates_type_id);
      }
      return gen_project_templates_type_id__volatile;
}


static void gen_project_templates_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
      GenProjectTemplates * self;
      self = GEN_PROJECT_TEMPLATES (object);
      switch (property_id) {
            case GEN_PROJECT_TEMPLATES_DEFINITIONS:
            g_value_set_pointer (value, gen_project_templates_get_definitions (self));
            break;
            default:
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
            break;
      }
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
      if ((array != NULL) && (destroy_func != NULL)) {
            int i;
            for (i = 0; i < array_length; i = i + 1) {
                  if (((gpointer*) array)[i] != NULL) {
                        destroy_func (((gpointer*) array)[i]);
                  }
            }
      }
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
      _vala_array_destroy (array, array_length, destroy_func);
      g_free (array);
}





Generated by  Doxygen 1.6.0   Back to index