settings.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:7k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************
  2.  *
  3.  * This program is free software ; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  16.  *
  17.  * $Id: settings.c 345 2005-11-19 15:57:54Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #include "../common/common.h"
  24. #include "win.h"
  25. #include "settings.h"
  26. #define SETTINGS_PAGES 10000
  27. #define MAXPAGE 64
  28. typedef struct settings 
  29. {
  30. win Win;
  31. node* Current;
  32. int Count;
  33. int Node[MAXPAGE];
  34. int Menu;
  35. } settings;
  36. static int Done(settings* p)
  37. {
  38. if (p->Win.Flags & WIN_PROP_SOFTRESET)
  39. ShowMessage(LangStr(SETTINGS_ID,NODE_NAME),LangStr(SETTINGS_ID,SETTINGS_SOFTRESET));
  40. else
  41. if (p->Win.Flags & WIN_PROP_RESTART)
  42. ShowMessage(LangStr(SETTINGS_ID,NODE_NAME),LangStr(SETTINGS_ID,SETTINGS_RESTART));
  43. if (p->Win.Flags & WIN_PROP_RESYNC)
  44. {
  45. player* Player = (player*)Context()->Player;
  46. if (Player)
  47. Player->Set(Player,PLAYER_RESYNC,NULL,0);
  48. }
  49. if (p->Win.Flags & WIN_PROP_CHANGED)
  50. {
  51. p->Win.Flags &= ~WIN_PROP_CHANGED;
  52. #ifdef REGISTRY_GLOBAL
  53. NodeRegSaveGlobal();
  54. #else
  55. if (p->Current)
  56. NodeRegSave(p->Current);
  57. #endif
  58. }
  59. NodeDelete(p->Current);
  60. p->Current = NULL;
  61. return ERR_NONE;
  62. }
  63. static void UpdatePage(settings* p)
  64. {
  65. datadef DataDef;
  66. node* Node;
  67. bool_t Found = 0;
  68. int Class = Context()->SettingsPage;
  69. int No,i;
  70. winunit y;
  71. bool_t CheckList;
  72. tchar_t Data[MAXDATA/sizeof(tchar_t)];
  73. #ifndef REGISTRY_GLOBAL
  74. if (p->Win.Flags & WIN_PROP_CHANGED)
  75. {
  76. p->Win.Flags &= ~WIN_PROP_CHANGED;
  77. if (p->Current)
  78. NodeRegSave(p->Current);
  79. }
  80. #endif
  81. WinBeginUpdate(&p->Win);
  82. for (No=0;No<p->Count;++No)
  83. {
  84. if (p->Node[No]==Class)
  85. Found = 1;
  86. WinMenuCheck(&p->Win,p->Menu,SETTINGS_PAGES+No,p->Node[No]==Class);
  87. }
  88. if (!Found && p->Count>0)
  89. Class = p->Node[0];
  90. NodeDelete(p->Current);
  91. p->Current = Node = NodeCreate(Class);
  92. if (Node)
  93. {
  94. WinTitle(&p->Win,LangStr(Class,NODE_NAME));
  95. p->Win.LabelWidth = 
  96. (Class == PLATFORM_ID) ? 60:
  97. (p->Win.ScreenWidth < 130) ? 80:
  98. (Class == PLAYER_ID || Class == ADVANCED_ID) ? 120:90;
  99. CheckList = Class == ASSOCIATION_ID;
  100. y = 2;
  101. // if the menu is in bottom of screen. print a hint before platform settings (first page shown)
  102. if (Class == PLATFORM_ID && (p->Win.Flags & WIN_BOTTOMTOOLBAR) && !(p->Win.Flags & WIN_2BUTTON))
  103. {
  104. WinLabel(&p->Win,&y,-1,-1,LangStr(SETTINGS_ID,SETTINGS_HINT),PROPSIZE,0,NULL);
  105. y += 10;
  106. }
  107. for (No=0;NodeEnum(Node,No,&DataDef)==ERR_NONE;++No)
  108. if ((DataDef.Flags & DF_SETUP) && !(DataDef.Flags & DF_HIDDEN))
  109. {
  110. if (DataDef.Flags & DF_GAP)
  111. y += 7;
  112. if (!(DataDef.Flags & DF_RDONLY))
  113. WinPropValue(&p->Win,&y,Node,DataDef.No);
  114. else
  115. if (Node->Get(Node,DataDef.No,Data,DataDef.Size)==ERR_NONE)
  116. {
  117. switch (DataDef.Type)
  118. {
  119. case TYPE_LABEL:
  120. WinLabel(&p->Win,&y,-1,-1,DataDef.Name,PROPSIZE,0,NULL);
  121. break;
  122. case TYPE_TICK:
  123. TickToString(Data,TSIZEOF(Data),*(tick_t*)Data,0,1,0);
  124. WinPropLabel(&p->Win,&y,DataDef.Name,Data);
  125. break;
  126. case TYPE_INT:
  127. i = *(int*)Data;
  128. if (DataDef.Flags & DF_ENUMCLASS)
  129. tcscpy_s(Data,TSIZEOF(Data),LangStr(i,NODE_NAME));
  130. else
  131. if (DataDef.Flags & DF_ENUMSTRING)
  132. tcscpy_s(Data,TSIZEOF(Data),LangStr(DataDef.Format1,i));
  133. else
  134. Data[0] = 0;
  135. if (!Data[0])
  136. IntToString(Data,TSIZEOF(Data),i,(DataDef.Flags & DF_HEX)!=0);
  137. if (DataDef.Flags & DF_KBYTE)
  138. tcscat_s(Data,TSIZEOF(Data),T(" KB"));
  139. if (DataDef.Flags & DF_MHZ)
  140. tcscat_s(Data,TSIZEOF(Data),T(" Mhz"));
  141. WinPropLabel(&p->Win,&y,DataDef.Name,Data);
  142. break;
  143. case TYPE_STRING:
  144. WinPropLabel(&p->Win,&y,DataDef.Name,Data);
  145. break;
  146. case TYPE_HOTKEY:
  147. HotKeyToString(Data,TSIZEOF(Data),*(int*)Data);
  148. WinPropLabel(&p->Win,&y,DataDef.Name,Data);
  149. break;
  150. case TYPE_BOOL:
  151. WinPropLabel(&p->Win,&y,DataDef.Name,
  152. LangStr(PLATFORM_ID,*(bool_t*)Data ? PLATFORM_YES:PLATFORM_NO));
  153. break;
  154. default:
  155. WinPropLabel(&p->Win,&y,DataDef.Name,NULL);
  156. break;
  157. }
  158. }
  159. }
  160. }
  161. WinEndUpdate(&p->Win);
  162. }
  163. static int Init(settings* p)
  164. {
  165. array List;
  166. int* i;
  167. p->Menu = WinMenuFind(&p->Win,SETTINGS_PAGES-1);
  168. p->Win.Flags &= ~(WIN_PROP_RESTART|WIN_PROP_SOFTRESET|WIN_PROP_RESYNC|WIN_PROP_CHANGED);
  169. NodeEnumClass(&List,NODE_CLASS);
  170. for (i=ARRAYBEGIN(List,int);i!=ARRAYEND(List,int);++i)
  171. if ((NodeClassDef(*i)->Flags & (CF_GLOBAL|CF_SETTINGS))==(CF_GLOBAL|CF_SETTINGS))
  172. {
  173. WinMenuInsert(&p->Win,p->Menu,SETTINGS_PAGES-1,SETTINGS_PAGES+p->Count,LangStr(*i,NODE_NAME));
  174. p->Node[p->Count++] = *i;
  175. if (p->Count==MAXPAGE)
  176. break;
  177. }
  178. ArrayClear(&List);
  179. WinMenuDelete(&p->Win,p->Menu,SETTINGS_PAGES-1);
  180. UpdatePage(p);
  181. return ERR_NONE;
  182. }
  183. static int Command(settings* p,int Cmd)
  184. {
  185. if (Cmd >= SETTINGS_PAGES && Cmd < SETTINGS_PAGES+p->Count)
  186. {
  187. Context()->SettingsPage = p->Node[Cmd-SETTINGS_PAGES];
  188. UpdatePage(p);
  189. return ERR_NONE;
  190. }
  191. return ERR_INVALID_PARAM;
  192. }
  193. static const menudef MenuDef[] =
  194. {
  195. { 0, PLATFORM_ID, PLATFORM_OK },
  196. { 0, SETTINGS_ID, SETTINGS_SELECTPAGE },
  197. { 1, SETTINGS_ID, SETTINGS_PAGES-1 }, // just place holder (will be deleted)
  198. MENUDEF_END
  199. };
  200. WINCREATE(Settings)
  201. static int Create(settings* p)
  202. {
  203. SettingsCreate(&p->Win);
  204. #ifdef TARGET_WIN32
  205. p->Win.WinWidth = 190;
  206. #else
  207. p->Win.WinWidth = 180;
  208. #endif
  209. p->Win.WinHeight = 240;
  210. p->Win.Flags |= WIN_DIALOG;
  211. p->Win.MenuDef = MenuDef;
  212. p->Win.Init = (nodefunc)Init;
  213. p->Win.Done = (nodefunc)Done;
  214. p->Win.Command = (wincommand)Command;
  215. return ERR_NONE;
  216. }
  217. static const nodedef Settings =
  218. {
  219. sizeof(settings),
  220. SETTINGS_ID,
  221. WIN_CLASS,
  222. PRI_DEFAULT,
  223. (nodecreate)Create
  224. };
  225. void Settings_Init()
  226. {
  227. NodeRegisterClass(&Settings);
  228. }
  229. void Settings_Done()
  230. {
  231. NodeUnRegisterClass(SETTINGS_ID);
  232. }