⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conf.c

📁 lrc 歌词解析和实时显示源码, 是开发 mp3, 播放器的很好的模块
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  XLyrics by xiaosuo <xiaosuo1@eyou.com> *  Homepage gentux.blogchina.com * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program 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 General Public License for more details. */#include<gtk/gtk.h>#include<gdk/gdk.h>#include<glib.h>#include<stdio.h>#include<dirent.h>#include"xlyrics.h"#include"conf.h"#include"internal.h"GtkWidget* conf_win;GtkWidget* color_win;GtkWidget* font_win;GtkWidget* file_win;GtkWidget* bg_entry;GtkWidget* ac_entry;GtkWidget* ua_entry;GSList* read_config(gchar *config_name){	FILE *conf_file;	GSList *list = NULL;	ConfItem *item = NULL;	gchar full_name[255];	gchar *in_index;	gchar *in_value;	gchar *iter;	gchar buffer[255];	if( config_name == NULL)		return NULL;	snprintf(full_name, 255, "%s/.%s", g_get_home_dir(), config_name);	if((conf_file = fopen( full_name, "r")) == NULL)		return NULL;	while(1)	{		if(!fgets(buffer, 255, conf_file))		{			fclose(conf_file);			return list;		}		buffer[254] = 0;		iter = buffer + strlen(buffer) - 1;		*iter = 0;				if((iter = strstr(buffer, " = ")))		{			*iter = 0;			in_index = buffer;			in_value = iter+3;		}		else		{			in_index = buffer;			in_value = buffer;		}		item = g_new(ConfItem, 1);		item->index = (gchar*)strdup(in_index);		item->value = (gchar*)strdup(in_value);		list = g_slist_append(list, item);	}}gboolean write_config(gchar *config_name, GSList *config_list){	FILE *conf_file;	ConfItem *item;	GSList *list;	gchar full_name[255];	if( config_name == NULL || config_list == NULL)		return FALSE;	snprintf(full_name, 255, "%s/.%s", g_get_home_dir(), config_name);	if((conf_file = fopen( full_name, "w+")) == NULL)		return FALSE;	for(list=config_list; list; list=list->next)	{		item = (ConfItem*)(list->data);		fprintf(conf_file, "%s = %s\n",				item->index, item->value);	}	fclose(conf_file);	return TRUE;}gboolean free_config(GSList *config_list){	GSList *list;	ConfItem *item;	if(!config_list)		return FALSE;	list = config_list;	while(list)	{		item = (ConfItem*)(list->data);		g_free(item->index);		g_free(item->value);		g_free(item);		list = list->next;	}	g_slist_free(config_list);	return TRUE;}gboolean get_config_str(GSList *config_list, gchar* index, gchar* value){	GSList *list;	ConfItem *item;	for(list=config_list; list; list=list->next)	{		item = (ConfItem*)(list->data);		if(!strcmp(index, item->index))		{			strcpy(value, item->value);			return TRUE;		}	}	return FALSE;}gboolean set_config_str(GSList** config_list, gchar* index, gchar* value){	GSList *list;	ConfItem *item;	for(list=*config_list; list; list=list->next)	{		item = (ConfItem*)(list->data);		if(!strcmp(index, item->index))		{			g_free(item->value);			item->value = g_strdup(value);			return TRUE;		}	}	item = g_new(ConfItem, 1);	item->index = (gchar*)strdup(index);	item->value = (gchar*)strdup(value);	*config_list = g_slist_append(*config_list, item);	return FALSE;}gboolean get_config_int(GSList *config_list, gchar* index, gint* value){	GSList *list;	ConfItem *item;	for(list=config_list; list; list=list->next)	{		item = (ConfItem*)(list->data);		if(!strcmp(index, item->index))		{			*value = atoi(item->value);			return TRUE;		}	}	return FALSE;}gboolean set_config_int(GSList** config_list, gchar* index, gint* value){	GSList *list;	ConfItem *item;	for(list=*config_list; list; list=list->next)	{		item = (ConfItem*)(list->data);		if(!strcmp(index, item->index))		{			g_free(item->value);			item->value = g_strdup_printf("%d", *value);			return TRUE;		}	}	item = g_new(ConfItem, 1);	item->index = g_strdup(index);	item->value = g_strdup_printf("%d", *value);	*config_list = g_slist_append(*config_list, item);	return FALSE;}gboolean init_config(gchar *config_name){	GSList *list;	list = read_config(config_name);	/*have the lyrics file*/	if(list)	{		get_config_int(list, "width", &width);		get_config_int(list, "height", &height);		get_config_int(list, "pos_x", &pos_x);		get_config_int(list, "pos_y", &pos_y);		get_config_int(list, "look_in_mp3dir_mode", &look_in_mp3dir_mode);		get_config_int(list, "is_keep_above", &is_keep_above);		get_config_int(list, "have_border", &have_border);		get_config_int(list, "is_fit_width", &is_fit_width);		get_config_int(list, "hide_not_found", &hide_not_found);		get_config_str(list, "lyrics_font", lyrics_font);		get_config_str(list, "lyrics_dir", lyrics_dir);		get_config_str(list, "plugin_name", plugin_name);		get_config_int(list, "opacity",(gint*)&(opacity));		get_config_int(list, "bg_color.pixel",(gint*)&(bg_color.pixel));		get_config_int(list, "bg_color.red", (gint*)&(bg_color.red));		get_config_int(list, "bg_color.green", (gint*)&(bg_color.green));		get_config_int(list, "bg_color.blue", (gint*)&(bg_color.blue));		get_config_int(list, "ac_color.pixel", (gint*)&(ac_color.pixel));		get_config_int(list, "ac_color.red", (gint*)&(ac_color.red));		get_config_int(list, "ac_color.green", (gint*)&(ac_color.green));		get_config_int(list, "ac_color.blue", (gint*)&(ac_color.blue));		get_config_int(list, "ua_color.pixel", (gint*)&(ua_color.pixel));		get_config_int(list, "ua_color.red", (gint*)&(ua_color.red));		get_config_int(list, "ua_color.green", (gint*)&(ua_color.green));		get_config_int(list, "ua_color.blue", (gint*)&(ua_color.blue));	}	/* else use the default*/	free_config(list);}gboolean update_config(gchar *config_name){	GSList *list = NULL;	set_config_int(&list, "width", &width);	set_config_int(&list, "height", &height);	set_config_int(&list, "pos_x", &pos_x);	set_config_int(&list, "pos_y", &pos_y);	set_config_int(&list, "look_in_mp3dir_mode", &look_in_mp3dir_mode);	set_config_int(&list, "is_keep_above", &is_keep_above);	set_config_int(&list, "have_border", &have_border);	set_config_int(&list, "is_fit_width", &is_fit_width);	set_config_int(&list, "hide_not_found", &hide_not_found);	set_config_str(&list, "lyrics_font", lyrics_font);	set_config_str(&list, "lyrics_dir", lyrics_dir);	set_config_str(&list, "plugin_name", plugin_name);	set_config_int(&list, "opacity",(gint*)&(opacity));	set_config_int(&list, "bg_color.pixel",(gint*)&(bg_color.pixel));	set_config_int(&list, "bg_color.red", (gint*)&(bg_color.red));	set_config_int(&list, "bg_color.green", (gint*)&(bg_color.green));	set_config_int(&list, "bg_color.blue", (gint*)&(bg_color.blue));	set_config_int(&list, "ac_color.pixel", (gint*)&(ac_color.pixel));	set_config_int(&list, "ac_color.red", (gint*)&(ac_color.red));	set_config_int(&list, "ac_color.green", (gint*)&(ac_color.green));	set_config_int(&list, "ac_color.blue", (gint*)&(ac_color.blue));	set_config_int(&list, "ua_color.pixel", (gint*)&(ua_color.pixel));	set_config_int(&list, "ua_color.red", (gint*)&(ua_color.red));	set_config_int(&list, "ua_color.green", (gint*)&(ua_color.green));	set_config_int(&list, "ua_color.blue", (gint*)&(ua_color.blue));	write_config(config_name, list);	free_config(list);}/* the interface design*/GtkWidget* about(void){	GtkWidget *about;	about = gtk_label_new(NULL);	gtk_label_set_justify(GTK_LABEL(about), GTK_JUSTIFY_CENTER);	gtk_label_set_markup(GTK_LABEL(about),			_("<span foreground=\"red\"><big>Xlyrics</big></span>\n Xlyrics is a software \n used for display the lyrics for XMMS\n and Beep Media Player, etc.\n\n Author: xiaosuo (xiaosuo1@eyou.com)\n Homepage: gentux.blogchina.com"));	return about;}void set_color(GtkWidget *widget, gpointer option){	if((gchar*)option == NULL)	{		gtk_widget_destroy(GTK_WIDGET(color_win));		return;	}	else if(!strcmp((gchar*)option, "bg"))	{		gtk_color_selection_get_current_color(				GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_win)->colorsel), &bg_color);		gtk_widget_modify_base(bg_entry, GTK_STATE_NORMAL, &bg_color);	}	else if(!strcmp((gchar*)option, "ac"))	{		gtk_color_selection_get_current_color(				GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_win)->colorsel), &ac_color);		gtk_widget_modify_base(ac_entry, GTK_STATE_NORMAL, &ac_color);	}	else if(!strcmp((gchar*)option, "ua"))	{		gtk_color_selection_get_current_color(				GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_win)->colorsel), &ua_color);		gtk_widget_modify_base(ua_entry, GTK_STATE_NORMAL, &ua_color);	}	is_config_update = TRUE;	gtk_widget_destroy(GTK_WIDGET(color_win));}void sel_color(GtkWidget *widget, GdkEvent *event, gpointer option){	gchar* title;	if(!strcmp((gchar*)option, "bg"))		title = g_strdup(_("Change background color"));	else if(!strcmp((gchar*)option, "ac"))		title = g_strdup(_("Change activated font color"));	else if(!strcmp((gchar*)option, "ua"))		title = g_strdup(_("Change unactivated font color"));	else		return;	color_win = gtk_color_selection_dialog_new(title);	if(!strcmp((gchar*)option, "bg"))		gtk_color_selection_set_current_color(			GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_win)->colorsel), &bg_color);	else if(!strcmp((gchar*)option, "ac"))		gtk_color_selection_set_current_color(			GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_win)->colorsel), &ac_color);	else if(!strcmp((gchar*)option, "ua"))		gtk_color_selection_set_current_color(

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -