[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[E-devel] Module development issue



Hi all,

I'm developing a small module to display informations about the currently
playing song.
I'm aware about the Eloquence module : my module is not a replacement of it
but just a exercise to learn more about the EFL.
I created an .edc file with only one part of type TEXT.
I've added an ecore timer in the .c file to check the eventual change of the
song.
However, the use of edje_object_part_text_set gives me a segmentation fault,
crashing e17.

I've attached the .c file and the .edc file.

Thanks in advance for your help,

Olivier
#include <e.h>
#include <libmpd/libmpd.h>
#include "e_mod_main.h"

/* Func Proto Requirements for Gadcon */
static E_Gadcon_Client *_gc_init     (E_Gadcon *gc, const char *name, const char *id, const char *style);
static void             _gc_shutdown (E_Gadcon_Client *gcc);
static void             _gc_orient   (E_Gadcon_Client *gcc);
static char            *_gc_label    (void);
static Evas_Object     *_gc_icon     (Evas *evas);

/* Module Protos */
static int _isound_cb_check (void *data);

static E_Config_DD *conf_edd = NULL;
static Ecore_Timer *check_timer;
static MpdObj 	   *mo;

Config *isound_config = NULL;

/* Define the class and gadcon functions this module provides */
static const E_Gadcon_Client_Class _gadcon_class = {
	GADCON_CLIENT_CLASS_VERSION,
	"isound", {_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon},
	E_GADCON_CLIENT_STYLE_PLAIN
};

typedef struct _Instance Instance;
struct _Instance
{
	E_Gadcon_Client *gcc;
	Evas_Object *isound;
};


	static E_Gadcon_Client *
_gc_init (E_Gadcon * gc, const char *name, const char *id, const char *style)
{
	Evas_Object *o;
	E_Gadcon_Client *gcc;
	Instance *inst;
	char buf[4096];

	inst = E_NEW (Instance, 1);

	o = edje_object_add(gc->evas);
	snprintf(buf, sizeof(buf), "%s/isound.edj",
			e_module_dir_get(isound_config->module));
	edje_object_file_set(o,buf, "isound");
	evas_object_show(o);

	gcc = e_gadcon_client_new (gc, name, id, style, o);
	gcc->data = inst;
	inst->gcc = gcc;
	inst->isound = o;

	mo = mpd_new_default();

	if(mpd_connect(mo))
	{
		mpd_free(mo);
		// TODO : prevenir utilisateur de l'echec de connection
	}
	
	_isound_cb_check(inst);
	if(!check_timer)
		check_timer = ecore_timer_add(1.0, _isound_cb_check, NULL); 

	return gcc;
}

	static void
_gc_shutdown (E_Gadcon_Client * gcc)
{
	Instance *inst;

	inst = gcc->data;

	evas_object_del(inst->isound);

	if (check_timer)
		ecore_timer_del(check_timer);
	check_timer = NULL;

	free (inst);
	inst = NULL;
}

	static void
_gc_orient (E_Gadcon_Client * gcc)
{
	Instance *inst;
	Evas_Coord mw, mh;

	inst = gcc->data;
	e_gadcon_client_aspect_set(gcc, 32, 16);
	e_gadcon_client_min_size_set(gcc, 16, 16);

}

	static char *
_gc_label (void)
{
	return _("ISound");
}

	static Evas_Object *
_gc_icon (Evas * evas)
{
	Evas_Object *o;
	char buf[4096];

	o = edje_object_add (evas);
	snprintf (buf, sizeof (buf), "%s/module.edj",
			e_module_dir_get (isound_config->module));
	edje_object_file_set (o, buf, "icon");
	return o;
}

static int _isound_cb_check(void *data) {
	Instance *inst;
	mpd_Song *song;
	char buf[1024];
	
	mpd_status_update(mo);
	song = mpd_playlist_get_current_song(mo);
	snprintf(buf, sizeof(buf), "%s - %s" ,
			song->artist, song->title);
	edje_object_part_text_set(inst->isound,"song",buf);

    return 1;
}

EAPI E_Module_Api e_modapi = {
	E_MODULE_API_VERSION,
	"ISound"
};

	EAPI void *
e_modapi_init (E_Module * m)
{

	conf_edd = E_CONFIG_DD_NEW("Isound_Config", Config);
	isound_config = e_config_domain_load("module.isound", conf_edd);  
	if (!isound_config)
	{
		isound_config = E_NEW(Config, 1);
	}

   isound_config->module = m;
   
   e_gadcon_provider_register(&_gadcon_class);	

	return m;
}

	EAPI int
e_modapi_shutdown (E_Module * m)
{
	isound_config->module = NULL;
	e_gadcon_provider_unregister (&_gadcon_class);

	free(isound_config);
	isound_config = NULL;
	E_CONFIG_DD_FREE(conf_edd);
	
	return 1;
}

	EAPI int
e_modapi_save (E_Module * m)
{
   e_config_domain_save("module.isound", conf_edd, isound_config);	
	return 1;
}

	EAPI int
e_modapi_about (E_Module * m)
{
	e_module_dialog_show (m, _("ISound"),
			_("Displays the informations of the current playing song"));
	return 1;
}

Attachment: isound.edc
Description: Binary data