/* relevancy-service.c generated by valac 0.56.17, the Vala compiler
 * generated from relevancy-service.vala, do not modify */

/*
 * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
 *
 * 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 program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by Michal Hruby <michal.mhr@gmail.com>
 *
 */

#include "synapse-core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <gio/gio.h>
#include <glib-object.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	SYNAPSE_RELEVANCY_SERVICE_0_PROPERTY,
	SYNAPSE_RELEVANCY_SERVICE_NUM_PROPERTIES
};
static GParamSpec* synapse_relevancy_service_properties[SYNAPSE_RELEVANCY_SERVICE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define SYNAPSE_TYPE_ZEITGEIST_RELEVANCY_BACKEND (synapse_zeitgeist_relevancy_backend_get_type ())
#define SYNAPSE_ZEITGEIST_RELEVANCY_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYNAPSE_TYPE_ZEITGEIST_RELEVANCY_BACKEND, SynapseZeitgeistRelevancyBackend))
#define SYNAPSE_ZEITGEIST_RELEVANCY_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYNAPSE_TYPE_ZEITGEIST_RELEVANCY_BACKEND, SynapseZeitgeistRelevancyBackendClass))
#define SYNAPSE_IS_ZEITGEIST_RELEVANCY_BACKEND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYNAPSE_TYPE_ZEITGEIST_RELEVANCY_BACKEND))
#define SYNAPSE_IS_ZEITGEIST_RELEVANCY_BACKEND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYNAPSE_TYPE_ZEITGEIST_RELEVANCY_BACKEND))
#define SYNAPSE_ZEITGEIST_RELEVANCY_BACKEND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYNAPSE_TYPE_ZEITGEIST_RELEVANCY_BACKEND, SynapseZeitgeistRelevancyBackendClass))

typedef struct _SynapseZeitgeistRelevancyBackend SynapseZeitgeistRelevancyBackend;
typedef struct _SynapseZeitgeistRelevancyBackendClass SynapseZeitgeistRelevancyBackendClass;

struct _SynapseRelevancyServicePrivate {
	SynapseRelevancyBackend* backend;
};

static gint SynapseRelevancyService_private_offset;
static gpointer synapse_relevancy_service_parent_class = NULL;
static SynapseRelevancyService* synapse_relevancy_service_instance;
static SynapseRelevancyService* synapse_relevancy_service_instance = NULL;

static GType synapse_relevancy_backend_get_type_once (void);
static SynapseRelevancyService* synapse_relevancy_service_new (void);
static SynapseRelevancyService* synapse_relevancy_service_construct (GType object_type);
static void synapse_relevancy_service_initialize_relevancy_backend (SynapseRelevancyService* self);
VALA_EXTERN SynapseZeitgeistRelevancyBackend* synapse_zeitgeist_relevancy_backend_new (void);
VALA_EXTERN SynapseZeitgeistRelevancyBackend* synapse_zeitgeist_relevancy_backend_construct (GType object_type);
VALA_EXTERN GType synapse_zeitgeist_relevancy_backend_get_type (void) G_GNUC_CONST ;
static GObject * synapse_relevancy_service_constructor (GType type,
                                                 guint n_construct_properties,
                                                 GObjectConstructParam * construct_properties);
static void synapse_relevancy_service_finalize (GObject * obj);
static GType synapse_relevancy_service_get_type_once (void);

gfloat
synapse_relevancy_backend_get_application_popularity (SynapseRelevancyBackend* self,
                                                      const gchar* desktop_id)
{
	SynapseRelevancyBackendIface* _iface_;
#line 25 "relevancy-service.vala"
	g_return_val_if_fail (self != NULL, 0.0F);
#line 25 "relevancy-service.vala"
	_iface_ = SYNAPSE_RELEVANCY_BACKEND_GET_INTERFACE (self);
#line 25 "relevancy-service.vala"
	if (_iface_->get_application_popularity) {
#line 25 "relevancy-service.vala"
		return _iface_->get_application_popularity (self, desktop_id);
#line 95 "relevancy-service.c"
	}
#line 25 "relevancy-service.vala"
	return -1.0F;
#line 99 "relevancy-service.c"
}

gfloat
synapse_relevancy_backend_get_uri_popularity (SynapseRelevancyBackend* self,
                                              const gchar* uri)
{
	SynapseRelevancyBackendIface* _iface_;
#line 26 "relevancy-service.vala"
	g_return_val_if_fail (self != NULL, 0.0F);
#line 26 "relevancy-service.vala"
	_iface_ = SYNAPSE_RELEVANCY_BACKEND_GET_INTERFACE (self);
#line 26 "relevancy-service.vala"
	if (_iface_->get_uri_popularity) {
#line 26 "relevancy-service.vala"
		return _iface_->get_uri_popularity (self, uri);
#line 115 "relevancy-service.c"
	}
#line 26 "relevancy-service.vala"
	return -1.0F;
#line 119 "relevancy-service.c"
}

void
synapse_relevancy_backend_application_launched (SynapseRelevancyBackend* self,
                                                GAppInfo* app_info)
{
	SynapseRelevancyBackendIface* _iface_;
#line 28 "relevancy-service.vala"
	g_return_if_fail (self != NULL);
#line 28 "relevancy-service.vala"
	_iface_ = SYNAPSE_RELEVANCY_BACKEND_GET_INTERFACE (self);
#line 28 "relevancy-service.vala"
	if (_iface_->application_launched) {
#line 28 "relevancy-service.vala"
		_iface_->application_launched (self, app_info);
#line 135 "relevancy-service.c"
	}
}

static void
synapse_relevancy_backend_default_init (SynapseRelevancyBackendIface * iface,
                                        gpointer iface_data)
{
}

static GType
synapse_relevancy_backend_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SynapseRelevancyBackendIface), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) synapse_relevancy_backend_default_init, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
	GType synapse_relevancy_backend_type_id;
	synapse_relevancy_backend_type_id = g_type_register_static (G_TYPE_INTERFACE, "SynapseRelevancyBackend", &g_define_type_info, 0);
	g_type_interface_add_prerequisite (synapse_relevancy_backend_type_id, G_TYPE_OBJECT);
	return synapse_relevancy_backend_type_id;
}

GType
synapse_relevancy_backend_get_type (void)
{
	static volatile gsize synapse_relevancy_backend_type_id__once = 0;
	if (g_once_init_enter (&synapse_relevancy_backend_type_id__once)) {
		GType synapse_relevancy_backend_type_id;
		synapse_relevancy_backend_type_id = synapse_relevancy_backend_get_type_once ();
		g_once_init_leave (&synapse_relevancy_backend_type_id__once, synapse_relevancy_backend_type_id);
	}
	return synapse_relevancy_backend_type_id__once;
}

static inline gpointer
synapse_relevancy_service_get_instance_private (SynapseRelevancyService* self)
{
	return G_STRUCT_MEMBER_P (self, SynapseRelevancyService_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
#line 37 "relevancy-service.vala"
	return self ? g_object_ref (self) : NULL;
#line 178 "relevancy-service.c"
}

SynapseRelevancyService*
synapse_relevancy_service_get_default (void)
{
	SynapseRelevancyService* _tmp0_ = NULL;
	SynapseRelevancyService* _tmp1_;
	SynapseRelevancyService* _tmp2_;
	SynapseRelevancyService* _tmp4_;
	SynapseRelevancyService* result;
#line 37 "relevancy-service.vala"
	_tmp1_ = synapse_relevancy_service_instance;
#line 37 "relevancy-service.vala"
	_tmp2_ = _g_object_ref0 (_tmp1_);
#line 37 "relevancy-service.vala"
	_tmp0_ = _tmp2_;
#line 37 "relevancy-service.vala"
	if (_tmp0_ == NULL) {
#line 197 "relevancy-service.c"
		SynapseRelevancyService* _tmp3_;
#line 37 "relevancy-service.vala"
		_tmp3_ = synapse_relevancy_service_new ();
#line 37 "relevancy-service.vala"
		_g_object_unref0 (_tmp0_);
#line 37 "relevancy-service.vala"
		_tmp0_ = _tmp3_;
#line 205 "relevancy-service.c"
	}
#line 37 "relevancy-service.vala"
	_tmp4_ = _tmp0_;
#line 37 "relevancy-service.vala"
	_tmp0_ = NULL;
#line 37 "relevancy-service.vala"
	result = _tmp4_;
#line 37 "relevancy-service.vala"
	_g_object_unref0 (_tmp0_);
#line 37 "relevancy-service.vala"
	return result;
#line 217 "relevancy-service.c"
}

static SynapseRelevancyService*
synapse_relevancy_service_construct (GType object_type)
{
	SynapseRelevancyService * self = NULL;
#line 40 "relevancy-service.vala"
	self = (SynapseRelevancyService*) g_object_new (object_type, NULL);
#line 40 "relevancy-service.vala"
	return self;
#line 228 "relevancy-service.c"
}

static SynapseRelevancyService*
synapse_relevancy_service_new (void)
{
#line 40 "relevancy-service.vala"
	return synapse_relevancy_service_construct (SYNAPSE_TYPE_RELEVANCY_SERVICE);
#line 236 "relevancy-service.c"
}

static void
synapse_relevancy_service_initialize_relevancy_backend (SynapseRelevancyService* self)
{
	SynapseZeitgeistRelevancyBackend* _tmp0_;
#line 58 "relevancy-service.vala"
	g_return_if_fail (self != NULL);
#line 61 "relevancy-service.vala"
	_tmp0_ = synapse_zeitgeist_relevancy_backend_new ();
#line 61 "relevancy-service.vala"
	_g_object_unref0 (self->priv->backend);
#line 61 "relevancy-service.vala"
	self->priv->backend = (SynapseRelevancyBackend*) _tmp0_;
#line 251 "relevancy-service.c"
}

gfloat
synapse_relevancy_service_get_application_popularity (SynapseRelevancyService* self,
                                                      const gchar* desktop_id)
{
	SynapseRelevancyBackend* _tmp0_;
	SynapseRelevancyBackend* _tmp1_;
	gfloat result;
#line 65 "relevancy-service.vala"
	g_return_val_if_fail (self != NULL, 0.0F);
#line 65 "relevancy-service.vala"
	g_return_val_if_fail (desktop_id != NULL, 0.0F);
#line 67 "relevancy-service.vala"
	_tmp0_ = self->priv->backend;
#line 67 "relevancy-service.vala"
	if (_tmp0_ == NULL) {
#line 67 "relevancy-service.vala"
		result = 0.0f;
#line 67 "relevancy-service.vala"
		return result;
#line 273 "relevancy-service.c"
	}
#line 68 "relevancy-service.vala"
	_tmp1_ = self->priv->backend;
#line 68 "relevancy-service.vala"
	result = synapse_relevancy_backend_get_application_popularity (_tmp1_, desktop_id);
#line 68 "relevancy-service.vala"
	return result;
#line 281 "relevancy-service.c"
}

gfloat
synapse_relevancy_service_get_uri_popularity (SynapseRelevancyService* self,
                                              const gchar* uri)
{
	SynapseRelevancyBackend* _tmp0_;
	SynapseRelevancyBackend* _tmp1_;
	gfloat result;
#line 71 "relevancy-service.vala"
	g_return_val_if_fail (self != NULL, 0.0F);
#line 71 "relevancy-service.vala"
	g_return_val_if_fail (uri != NULL, 0.0F);
#line 73 "relevancy-service.vala"
	_tmp0_ = self->priv->backend;
#line 73 "relevancy-service.vala"
	if (_tmp0_ == NULL) {
#line 73 "relevancy-service.vala"
		result = 0.0f;
#line 73 "relevancy-service.vala"
		return result;
#line 303 "relevancy-service.c"
	}
#line 74 "relevancy-service.vala"
	_tmp1_ = self->priv->backend;
#line 74 "relevancy-service.vala"
	result = synapse_relevancy_backend_get_uri_popularity (_tmp1_, uri);
#line 74 "relevancy-service.vala"
	return result;
#line 311 "relevancy-service.c"
}

void
synapse_relevancy_service_application_launched (SynapseRelevancyService* self,
                                                GAppInfo* app_info)
{
	SynapseRelevancyBackend* _tmp0_;
	SynapseRelevancyBackend* _tmp1_;
#line 77 "relevancy-service.vala"
	g_return_if_fail (self != NULL);
#line 77 "relevancy-service.vala"
	g_return_if_fail (app_info != NULL);
#line 79 "relevancy-service.vala"
	g_debug ("relevancy-service.vala:79: application launched");
#line 80 "relevancy-service.vala"
	_tmp0_ = self->priv->backend;
#line 80 "relevancy-service.vala"
	if (_tmp0_ == NULL) {
#line 80 "relevancy-service.vala"
		return;
#line 332 "relevancy-service.c"
	}
#line 81 "relevancy-service.vala"
	_tmp1_ = self->priv->backend;
#line 81 "relevancy-service.vala"
	synapse_relevancy_backend_application_launched (_tmp1_, app_info);
#line 338 "relevancy-service.c"
}

gint
synapse_relevancy_service_compute_relevancy (gint base_relevancy,
                                             gfloat modifier)
{
	gint relevancy = 0;
	gint result;
#line 88 "relevancy-service.vala"
	relevancy = (gint) (base_relevancy + ((modifier * SYNAPSE_MATCH_SCORE_INCREMENT_LARGE) * 2));
#line 90 "relevancy-service.vala"
	result = relevancy;
#line 90 "relevancy-service.vala"
	return result;
#line 353 "relevancy-service.c"
}

static GObject *
synapse_relevancy_service_constructor (GType type,
                                       guint n_construct_properties,
                                       GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	SynapseRelevancyService * self;
#line 48 "relevancy-service.vala"
	parent_class = G_OBJECT_CLASS (synapse_relevancy_service_parent_class);
#line 48 "relevancy-service.vala"
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
#line 48 "relevancy-service.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SYNAPSE_TYPE_RELEVANCY_SERVICE, SynapseRelevancyService);
#line 50 "relevancy-service.vala"
	synapse_relevancy_service_instance = self;
#line 51 "relevancy-service.vala"
	g_object_add_weak_pointer ((GObject*) self, &synapse_relevancy_service_instance);
#line 53 "relevancy-service.vala"
	synapse_relevancy_service_initialize_relevancy_backend (self);
#line 48 "relevancy-service.vala"
	return obj;
#line 378 "relevancy-service.c"
}

static void
synapse_relevancy_service_class_init (SynapseRelevancyServiceClass * klass,
                                      gpointer klass_data)
{
#line 31 "relevancy-service.vala"
	synapse_relevancy_service_parent_class = g_type_class_peek_parent (klass);
#line 31 "relevancy-service.vala"
	g_type_class_adjust_private_offset (klass, &SynapseRelevancyService_private_offset);
#line 31 "relevancy-service.vala"
	G_OBJECT_CLASS (klass)->constructor = synapse_relevancy_service_constructor;
#line 31 "relevancy-service.vala"
	G_OBJECT_CLASS (klass)->finalize = synapse_relevancy_service_finalize;
#line 393 "relevancy-service.c"
}

static void
synapse_relevancy_service_instance_init (SynapseRelevancyService * self,
                                         gpointer klass)
{
#line 31 "relevancy-service.vala"
	self->priv = synapse_relevancy_service_get_instance_private (self);
#line 402 "relevancy-service.c"
}

static void
synapse_relevancy_service_finalize (GObject * obj)
{
	SynapseRelevancyService * self;
#line 31 "relevancy-service.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SYNAPSE_TYPE_RELEVANCY_SERVICE, SynapseRelevancyService);
#line 56 "relevancy-service.vala"
	_g_object_unref0 (self->priv->backend);
#line 31 "relevancy-service.vala"
	G_OBJECT_CLASS (synapse_relevancy_service_parent_class)->finalize (obj);
#line 415 "relevancy-service.c"
}

static GType
synapse_relevancy_service_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (SynapseRelevancyServiceClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) synapse_relevancy_service_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SynapseRelevancyService), 0, (GInstanceInitFunc) synapse_relevancy_service_instance_init, NULL };
	GType synapse_relevancy_service_type_id;
	synapse_relevancy_service_type_id = g_type_register_static (G_TYPE_OBJECT, "SynapseRelevancyService", &g_define_type_info, 0);
	SynapseRelevancyService_private_offset = g_type_add_instance_private (synapse_relevancy_service_type_id, sizeof (SynapseRelevancyServicePrivate));
	return synapse_relevancy_service_type_id;
}

GType
synapse_relevancy_service_get_type (void)
{
	static volatile gsize synapse_relevancy_service_type_id__once = 0;
	if (g_once_init_enter (&synapse_relevancy_service_type_id__once)) {
		GType synapse_relevancy_service_type_id;
		synapse_relevancy_service_type_id = synapse_relevancy_service_get_type_once ();
		g_once_init_leave (&synapse_relevancy_service_type_id__once, synapse_relevancy_service_type_id);
	}
	return synapse_relevancy_service_type_id__once;
}

