View Single Post
electroaudio's Avatar
Posts: 381 | Thanked: 336 times | Joined on Jan 2011 @ Stockholm, Sweden
#103
Here is the significant part to read a configfile from deskypplet.c

Code:
confyfile="/home/user/.deskypplet/deskypplet.conf";
	get_sizes (confyfile);
You could simplify it by using get_sizes("/usr/share/theme/launcher.cfg") directly instead, or maybe just copy the code inside get_sizes{} directly into the hildon-desktop code.
Also, the assigning of the values to a variable has to be remade, since deskypplet uses a structure to store the values.
Code:
if(strstr(readbuf,"title height"))
				sscanf(readbuf,"title height=%d\n",&(app->title_height));
Code:
void get_sizes (gchar *conffile)
{
	/*printf ("get_sizes conffile %s\n",conffile);*/
	GIOChannel *f=NULL;
	GIOStatus st;
	GdkColormap *colormap;
	gchar *readbuf=NULL;
	gchar *fontbuffer=NULL;
	gchar *red=NULL;
	gchar *green=NULL;
	gchar *blue=NULL;
    
	/*gdk_color_parse (DEFAULT_COLOR, &(app->color));
	gdk_color_parse (DEFAULT_FONT_COLOR, &(app->fontcolor));
	app->fontname=g_new0(gchar,strlen(DEFAULT_FONT)+1);
	strcpy(app->fontname,DEFAULT_FONT);
	app->bg_alpha=(gfloat)DEFAULT_BG_ALPHA/100;*/
  	
	f=g_io_channel_new_file(conffile,"r",NULL);

	if(f!=NULL)
		{
		 while((st=g_io_channel_read_line(f,&readbuf,NULL,NULL,NULL) )!=G_IO_STATUS_EOF)
			{
			 if(strstr(readbuf,"bgcolor="))
				{
				 red=strchr(readbuf,'=')+1;
				 green=strchr(red,',');
				 *green=0;
				 green+=1;
				 blue=strchr(green,',');
				 *blue=0;
				 blue+=1;
				 fontbuffer=strchr(blue,'\n');
				 *fontbuffer=0;
				 (app->color).red=(guint16)atoi(red);
				 (app->color).green=(guint16)atoi(green);
				 (app->color).blue=(guint16)atoi(blue);
				 colormap=gdk_colormap_get_system();
				 gdk_colormap_alloc_color(colormap,&(app->color),TRUE,TRUE);
				}
			 if(strstr(readbuf,"bgalpha"))
				{
				 gint alpha;
				 sscanf(readbuf,"bgalpha=%d\n",&alpha);
				 app->bg_alpha=(gfloat)alpha/100;
				}

			if(strstr(readbuf,"autorefresh active"))
				sscanf(readbuf,"autorefresh active=%d\n",&(autorefresh));

			if(strstr(readbuf,"icons size"))
				{
				 sscanf(readbuf,"icons size=%d\n",&(app->icon_x_size));
				 app->icon_y_size=app->icon_x_size;	
				}
			if(strstr(readbuf,"filename textbox height"))
				sscanf(readbuf,"filename textbox height=%d\n",&(app->icon_label_y_size));					

			if(strstr(readbuf,"filename textbox width"))
				sscanf(readbuf,"filename textbox width=%d\n",&(app->icon_label_x_size));					
			
			if(strstr(readbuf,"bookmark icons size"))
				{
				 sscanf(readbuf,"bookmark icons size=%d\n",&(app->bookm_x_size));
				 app->bookm_y_size=app->bookm_x_size;
				}
			if(strstr(readbuf,"bookmark textbox height"))
				sscanf(readbuf,"bookmark textbox height=%d\n",&(app->bookm_label_y_size));					

			if(strstr(readbuf,"bookmark textbox width"))
				sscanf(readbuf,"bookmark textbox width=%d\n",&(app->bookm_label_x_size));					
			
			if(strstr(readbuf,"font for filenames="))
			{
				fontbuffer=strchr(readbuf,'\n');
				*fontbuffer=0;
				fontbuffer=strchr(readbuf,'=')+1;
				app->files_name_size=g_new0(gchar,strlen(fontbuffer)+1);
				strcpy(app->files_name_size,fontbuffer);
			}
			if(strstr(readbuf,"font for bookmarks="))
			{
				fontbuffer=strchr(readbuf,'\n');
				*fontbuffer=0;
				fontbuffer=strchr(readbuf,'=')+1;
				app->bookmarks_name_size=g_new0(gchar,strlen(fontbuffer)+1);
				strcpy(app->bookmarks_name_size,fontbuffer);
			}
			
			if(strstr(readbuf,"title buttons size"))
				sscanf(readbuf,"title buttons size=%d\n",&(app->title_button_size));

			if(strstr(readbuf,"title height"))
				sscanf(readbuf,"title height=%d\n",&(app->title_height));
			
			if(strstr(readbuf,"font for title="))
			{
				fontbuffer=strchr(readbuf,'\n');
				*fontbuffer=0;
				fontbuffer=strchr(readbuf,'=')+1;
				app->title_font_size=g_new0(gchar,strlen(fontbuffer)+1);
				strcpy(app->title_font_size,fontbuffer);
			}
						
			if(strstr(readbuf,"fontcolor"))
			{
				red=strchr(readbuf,'=')+1;
				green=strchr(red,',');
				*green=0;
				green+=1;
				blue=strchr(green,',');
				*blue=0;
				blue+=1;
				fontbuffer=strchr(blue,'\n');
				*fontbuffer=0;
				(app->fontcolor).red=(guint16)atoi(red);
				(app->fontcolor).green=(guint16)atoi(green);
				(app->fontcolor).blue=(guint16)atoi(blue);
				colormap=gdk_colormap_get_system();
				gdk_colormap_alloc_color(colormap,&(app->fontcolor),TRUE,TRUE);
			}

			g_free(readbuf);
		}
		g_io_channel_close(f);
	}

	if (autorefresh==1)
		{autorefresh_status="Autorefresh Activated";}
	else
		{autorefresh_status="Autorefresh Deactivated";}

	return;
And here are the declarations from deskypplet.h
Code:
/*read preferences from config file and load into object*/
void get_sizes (gchar *conffile);
__________________
Deskypplet , a desktop for N900 *RIP*

Last edited by electroaudio; 2013-08-17 at 12:07.