gint Lyric_GetSearchAppCount() { int iTmp = 0; ConfigDb *cfgfile = aud_cfg_db_open(); aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "SearchAppCount", &iTmp); aud_cfg_db_close(cfgfile); return iTmp; }
int SaveSettings(LPSETTINGS pSettings) { ConfigDb *cfg = GetConfigFile(); if (!cfg) return 0; aud_cfg_db_set_int(cfg,CUBE_CONFIG_TAG,LOOPCOUNT_NAME,pSettings->loopcount); aud_cfg_db_set_int(cfg,CUBE_CONFIG_TAG,FADESECOND_NAME,pSettings->fadeseconds); aud_cfg_db_set_int(cfg,CUBE_CONFIG_TAG,FADEDELAYSECOND_NAME,pSettings->fadedelayseconds); aud_cfg_db_close(cfg); return 1; }
GSList *search_skins_indirectory (char *dirname,GSList *skinlist) { DIR *dirhandle; struct dirent *direntry; mcs_handle_t *config; gchar *skin_path; dirhandle = opendir (dirname); if (dirhandle>0) { while ((direntry=readdir(dirhandle))) { if (fnmatch("*.ini",direntry->d_name,0)==0) { // Construct the skin path skin_path = g_strconcat (dirname,DIR_SEPARATOR_STRING,direntry->d_name,NULL); // We found a inifile, read the data //config = xmms_cfg_open_file (skin_path); config = aud_cfg_db_open (); if (config) { gchar *skin_type,*skin_author,*skin_path_copy,*skin_title; _skinsearch_entry *skinentry = malloc (sizeof(_skinsearch_entry)); skin_type=skin_author=skin_title=NULL; // Test the skin type aud_cfg_db_get_string (config,"SKIN","skintype",&skin_type); if (skin_type==NULL) break; if (strcmp(skin_type,SKIN_TYPE_IDENTIFIER)) break; // Read in the author aud_cfg_db_get_string (config,"SKIN","author",&skin_author); skinentry->skin_author = skin_author; // Read in the title aud_cfg_db_get_string (config,"SKIN","title",&skin_title); skinentry->skin_title = skin_title; // Save the skin path skin_path_copy = strdup (skin_path); skinentry->skin_path = skin_path_copy; DPRINT (__DEBUG_GENERAL__,"Found skin: '%s','%s','%s'", skinentry->skin_title,skinentry->skin_author,skinentry->skin_path); // Save the new entry to our skinlist skinlist = g_slist_append (skinlist,skinentry); // Free the unused skin_type and free config g_free (skin_type); aud_cfg_db_close (config); } g_free (skin_path); } } closedir (dirhandle); } return skinlist; }
gboolean Lyric_GetSearchApp(gint nIndex, AppInfo* pApp) { if (nIndex >= Lyric_GetSearchAppCount()) return FALSE; ConfigDb *cfgfile = aud_cfg_db_open(); gchar *lpszTmp= NULL; gchar szKey[200] = {0}; sprintf(szKey, "SearchApp_App_%d", nIndex); aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, szKey, &lpszTmp); strncpy(pApp->szApp, lpszTmp, MAX_PATH); sprintf(szKey, "SearchApp_Name_%d", nIndex); aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, szKey, &lpszTmp); strncpy(pApp->szName, lpszTmp, MAX_PATH); aud_cfg_db_close(cfgfile); return TRUE; }
gboolean Lyric_SetSearchApp(gint nIndex, AppInfo app) { if (nIndex > Lyric_GetSearchAppCount())return FALSE; ConfigDb *cfgfile = aud_cfg_db_open(); gchar szKey[200] = {0}; sprintf(szKey, "SearchApp_App_%d", nIndex); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, szKey, app.szApp); sprintf(szKey, "SearchApp_Name_%d", nIndex); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, szKey, app.szName); if (nIndex == Lyric_GetSearchAppCount()) { aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "SearchAppCount", nIndex + 1); } aud_cfg_db_close(cfgfile); return TRUE; }
// 保存配置信息 // @pConfigs: 配置信息 gboolean Lyric_SaveConfigs(IN Configs* pConfigs) { // 保存配置信息 ConfigDb *cfgfile = aud_cfg_db_open(); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "LyricPath", pConfigs->szLyricPath); aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "SearchAppIndex", pConfigs->nSearchAppIndex); #define SAVE_COLOR(name, color) do {\ gchar* lpszColor = gdk_color_to_string (&color);\ aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, name, lpszColor);\ free(lpszColor);\ }while(0) SAVE_COLOR("BackgroundColor", pConfigs->colors.background); SAVE_COLOR("NormalColor", pConfigs->colors.normal); SAVE_COLOR("CurrColor", pConfigs->colors.current); SAVE_COLOR("DragColor", pConfigs->colors.drag); SAVE_COLOR("MsgColor", pConfigs->colors.msg); SAVE_COLOR("ErrorColor", pConfigs->colors.error); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "ShowWindowLyric", pConfigs->bShowWindowLyric); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "IsKaLaOK", pConfigs->bIsKaLaOK); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SmartShowWin", pConfigs->bSmartShowWin); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "ShowBroad", pConfigs->bShowBroad); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SmartDownLoad", pConfigs->bSmartDownLoad); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SaveLyricToSongFolder", pConfigs->bSaveLyricToSongFolder); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "SaveLyricAsFileName", pConfigs->bSaveLyricAsFileName); aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "Opacity", pConfigs->iOpacity); aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "Pos_iX", pConfigs->pos.iX); aud_cfg_db_set_int(cfgfile, PLUGIN_NAME, "Pos_iY", pConfigs->pos.iY); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "LyricFontName", pConfigs->szLyricFontName); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "LyricEncode", pConfigs->szLyricEncode); aud_cfg_db_set_bool(cfgfile, PLUGIN_NAME, "ShowOSDLyric", pConfigs->bShowOSDLyric ); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "OSD_fake_translucent_bg", pConfigs->OSD.fake_translucent_bg); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "OSD_vposition", pConfigs->OSD.vposition); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "OSD_halignment", pConfigs->OSD.halignment); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "OSD_animations", pConfigs->OSD.animations); aud_cfg_db_set_string(cfgfile, PLUGIN_NAME, "OSD_font", pConfigs->OSD.szFontName); aud_cfg_db_close(cfgfile); return TRUE; }
int LoadSettings(LPSETTINGS pSettings) { ConfigDb *cfg = GetConfigFile(); if (!cfg) { DefaultSettings(pSettings); } else { int bRet = (aud_cfg_db_get_int(cfg,CUBE_CONFIG_TAG,LOOPCOUNT_NAME,&pSettings->loopcount) && aud_cfg_db_get_int(cfg,CUBE_CONFIG_TAG,FADESECOND_NAME,&pSettings->fadeseconds) && aud_cfg_db_get_int(cfg,CUBE_CONFIG_TAG,FADEDELAYSECOND_NAME,&pSettings->fadedelayseconds)); aud_cfg_db_close(cfg); // check if reading one value failed. If so, then use defaults if (!bRet) DefaultSettings(pSettings); } return 1; }
// 加载配置信息 // @pConfigs: 配置信息 gboolean Lyric_LoadConfigs(OUT Configs* pConfigs) { int iTmp = 0; // 加载配置信息 ConfigDb *cfgfile = aud_cfg_db_open(); gchar *lpszTmp= NULL; if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "LyricPath", &lpszTmp)) { strncpy(pConfigs->szLyricPath, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "SearchAppIndex", &iTmp)) pConfigs->nSearchAppIndex = iTmp; #define LOAD_COLOR(name, to) if(aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, name, &lpszTmp)) {\ gdk_color_parse(lpszTmp, &to);\ } LOAD_COLOR("BackgroundColor", pConfigs->colors.background); LOAD_COLOR("NormalColor", pConfigs->colors.normal); LOAD_COLOR("CurrColor", pConfigs->colors.current); LOAD_COLOR("DragColor", pConfigs->colors.drag); LOAD_COLOR("MsgColor", pConfigs->colors.msg); LOAD_COLOR("ErrorColor", pConfigs->colors.error); gboolean bTmp = FALSE; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "ShowWindowLyric", &bTmp)) pConfigs->bShowWindowLyric = bTmp; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SmartShowWin", &bTmp)) pConfigs->bSmartShowWin = bTmp; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SmartDownLoad", &bTmp)) pConfigs->bSmartDownLoad = bTmp; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "ShowBroad", &bTmp)) pConfigs->bShowBroad = bTmp; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SaveLyricToSongFolder", &bTmp)) pConfigs->bSaveLyricToSongFolder = bTmp; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "SaveLyricAsFileName", &bTmp)) { pConfigs->bSaveLyricAsFileName = bTmp; } if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "Opacity", &iTmp)) pConfigs->iOpacity = iTmp; if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "Pos_iX", &iTmp)) pConfigs->pos.iX = iTmp; if (aud_cfg_db_get_int(cfgfile, PLUGIN_NAME, "Pos_iY", &iTmp)) pConfigs->pos.iY = iTmp; if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "LyricFontName", &lpszTmp)) { strncpy(pConfigs->szLyricFontName, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "LyricEncode", &lpszTmp)) { strncpy(pConfigs->szLyricEncode, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "ShowOSDLyric", &bTmp)) pConfigs->bShowOSDLyric = bTmp; if (aud_cfg_db_get_bool(cfgfile, PLUGIN_NAME, "IsKaLaOK", &bTmp)) pConfigs->bIsKaLaOK = bTmp; if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "OSD_fake_translucent_bg", &lpszTmp)) { strncpy(pConfigs->OSD.fake_translucent_bg, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "OSD_vposition", &lpszTmp)) { strncpy(pConfigs->OSD.vposition, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "OSD_halignment", &lpszTmp)) { strncpy(pConfigs->OSD.halignment, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "OSD_animations", &lpszTmp)) { strncpy(pConfigs->OSD.animations, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } if (aud_cfg_db_get_string(cfgfile, PLUGIN_NAME, "OSD_font", &lpszTmp)) { strncpy(pConfigs->OSD.szFontName, lpszTmp, MAX_PATH); g_free(lpszTmp); lpszTmp = NULL; } aud_cfg_db_close(cfgfile); return TRUE; }
void write_xmms_config() { /*char tempname[100];*/ char *tempname = (char *)malloc(sizeof(char)*100); int count; GSList *position = cdcover_config.cover_searchpaths; GSList *positionext = cdcover_config.cover_extensions; mcs_handle_t *config; DPRINT (__DEBUG_GENERAL__,"Writing config"); config = aud_cfg_db_open (); if (config) { // Window position aud_cfg_db_set_bool (config,PLUGIN_NAME,"savewindowpos",cdcover_config.save_window_pos); aud_cfg_db_set_int (config,PLUGIN_NAME,"windowposx",cdcover_config.winpos_x); aud_cfg_db_set_int (config,PLUGIN_NAME,"windowposy",cdcover_config.winpos_y); // Aspect ratio aud_cfg_db_set_bool (config,PLUGIN_NAME,"aspectratio",cdcover_config.preserve_aspectratio); // Iterate through the search list and save the paths count=0; while (position!=NULL) { count++; sprintf (tempname,"path%d",count); aud_cfg_db_set_string (config,PLUGIN_NAME,tempname,position->data); //printf("Wrote path %s (%d, %s)\n", (char *)position->data, count, tempname); position = g_slist_next (position); } //printf("Done writing paths\n"); // Delete the next key, so there's a hole and read_xmms_config can stop here // Not too nice, as we probably leave garbage in the xmms config file sprintf (tempname,"path%d",count+1); aud_cfg_db_unset_key (config,PLUGIN_NAME,tempname); // Iterate through the search list and save the extensions count=0; //printf("About to write extensions\n"); while (positionext!=NULL) { count++; sprintf (tempname,"ext%d",count); aud_cfg_db_set_string (config,PLUGIN_NAME,tempname,positionext->data); //printf("Wrote extension %s (%d, %s)\n", (char *)positionext->data, count, tempname); positionext = g_slist_next (positionext); } //printf("Done with the extensions too\n"); // Delete the next key, so there's a hole and read_xmms_config can stop here // Not too nice, as we probably leave garbage in the xmms config file sprintf (tempname,"ext%d",count+1); aud_cfg_db_unset_key (config,PLUGIN_NAME,tempname); // Save the skin if (cdcover_config.skin_path!=NULL) { // Save the user selected skin aud_cfg_db_set_string (config,PLUGIN_NAME,"skinpath",cdcover_config.skin_path); } else { // Built in default skin, delete the key aud_cfg_db_unset_key (config,PLUGIN_NAME,"skinpath"); } // Write and then free the config //printf("About to close config file\n"); aud_cfg_db_close (config); //printf("Closed config file\n"); } else { DPRINT (__DEBUG_GENERAL__,"cannot open config file for writing"); } }
void read_xmms_config() { int count; /*char tempname[100];*/ char *tempname = (char *)malloc(sizeof(char)*100); gchar *path; gchar *ext; mcs_handle_t *config; DPRINT (__DEBUG_GENERAL__,"Starting to read xmms config"); // empty cover search list, the plugin is probably initialized twice by the user g_slist_free (cdcover_config.cover_searchpaths); cdcover_config.cover_searchpaths = NULL; // empty extension search list, the plugin is probably initialized twice by the user g_slist_free (cdcover_config.cover_extensions); cdcover_config.cover_extensions = NULL; config = aud_cfg_db_open (); if (config) { // Window position aud_cfg_db_get_bool (config,PLUGIN_NAME,"savewindowpos",&cdcover_config.save_window_pos); aud_cfg_db_get_int (config,PLUGIN_NAME,"windowposx",&cdcover_config.winpos_x); aud_cfg_db_get_int (config,PLUGIN_NAME,"windowposy",&cdcover_config.winpos_y); // Aspect ratio aud_cfg_db_get_bool (config,PLUGIN_NAME,"aspectratio",&cdcover_config.preserve_aspectratio); // Skin if (!aud_cfg_db_get_string (config,PLUGIN_NAME,"skinpath",&cdcover_config.skin_path)) { cdcover_config.skin_path = NULL; } // Read in the paths sprintf (tempname,"path1"); count=1; while (aud_cfg_db_get_string (config,PLUGIN_NAME,tempname,&path)) { // save the pointer to this resource string in the list cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path); //printf("Got path '%s' with var %s\n", path, tempname); // construct next path variable count++; sprintf (tempname,"path%d",count); } // Where we able to read any search paths ? if (g_slist_length(cdcover_config.cover_searchpaths)==0) { // Some default paths to start with // Allocate memory, so we can free it on shutdown //printf("No paths found, populating with defaults\n"); gchar *path1 = g_strconcat ("?PATH?/cover.jpg",NULL); gchar *path2 = g_strconcat ("?PATH?/?BASE?.jpg",NULL); gchar *path3 = g_strconcat ("?PATH?/media/?FILENAME?.jpg",NULL); gchar *path4 = g_strconcat ("?PATH?/*.jpg",NULL); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path1); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path2); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path3); cdcover_config.cover_searchpaths = g_slist_append (cdcover_config.cover_searchpaths,path4); } // Read in the extensions sprintf (tempname,"ext1"); count=1; while (aud_cfg_db_get_string (config,PLUGIN_NAME,tempname,&ext)) { // save the pointer to this resource string in the list cdcover_config.cover_extensions = g_slist_append (cdcover_config.cover_extensions,ext); //printf("Got ext '%s' with var %s\n", ext, tempname); // construct next path variable count++; sprintf (tempname,"ext%d",count); } // Were we able to read any extensions? if (g_slist_length(cdcover_config.cover_extensions)==0) { // Some default extensions to start with // Allocate memory, so we can free it on shutdown //printf("No extensions found, populating with defaults\n"); gchar *ext1 = g_strconcat ("png",NULL); gchar *ext2 = g_strconcat ("jpg",NULL); gchar *ext3 = g_strconcat ("gif",NULL); cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext1); cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext2); cdcover_config.cover_extensions = g_slist_append(cdcover_config.cover_extensions,ext3); } // Free config handle aud_cfg_db_close (config); } else { DPRINT (__DEBUG_GENERAL__,"Cannot open config file"); } }