Ticket #13269: 0005-Added-a-stringList-support-for-settingfiles.patch
File 0005-Added-a-stringList-support-for-settingfiles.patch, 3.1 KB (added by , 8 years ago) |
---|
-
src/apps/codycam/Settings.cpp
From 93a45117567aad1c4d64d895444c862d3ea31a36 Mon Sep 17 00:00:00 2001 From: Paradoxon <two4god@gmail.com> Date: Tue, 31 Jan 2017 22:36:20 +0100 Subject: [PATCH 5/5] Added a stringList support for settingfiles --- src/apps/codycam/Settings.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++ src/apps/codycam/Settings.h | 26 ++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/src/apps/codycam/Settings.cpp b/src/apps/codycam/Settings.cpp index 537d0bf..4a6fa2e 100644
a b BooleanValueSetting::SaveSettingValue(Settings* settings) 257 257 { 258 258 settings->Write(fValue ? "on" : "off"); 259 259 } 260 261 262 263 StringListSetting::StringListSetting(const char* name, 264 BStringList* defaultPathList) 265 : 266 SettingsArgvDispatcher(name), 267 fDefaultStringList(defaultPathList), 268 fStringList(defaultPathList) 269 { 270 } 271 272 273 StringListSetting::~StringListSetting() 274 { 275 delete fDefaultStringList; 276 delete fStringList; 277 } 278 279 280 void 281 StringListSetting::ValueChanged(BStringList *newList) 282 { 283 fStringList=newList; 284 } 285 286 287 BStringList* 288 StringListSetting::Value() const 289 { 290 return fStringList; 291 } 292 293 294 void 295 StringListSetting::SaveSettingValue(Settings* settings) 296 { 297 if (fStringList->CountStrings()>0){ 298 //write the first one with only one tab 299 settings->Write("\t %s ", fStringList->StringAt(0).String()); 300 for (int32 i=1; i<fStringList->CountStrings();i++) { 301 //first add a backslach 302 settings->Write("\\\n"); 303 settings->Write("\t\t %s", fStringList->StringAt(i).String()); 304 } 305 settings->Write("\n"); 306 } 307 } 308 309 310 bool 311 StringListSetting::NeedsSaving() const 312 { 313 // needs saving if different than default 314 int32 i = 0; 315 if (fStringList->CountStrings() != fDefaultStringList->CountStrings()) 316 return true; 317 for (i=0;i<fStringList->CountStrings();i++) 318 { 319 if (fDefaultStringList->HasString(fStringList->StringAt(i))!= true) 320 return true; 321 } 322 return false; 323 } 324 325 326 const char* 327 StringListSetting::Handle(const char *const *argv) 328 { 329 if (!*++argv) { 330 return "String expected"; 331 } 332 fStringList->MakeEmpty(); 333 int32 i=0; 334 while (argv[i]!=NULL) 335 { 336 fStringList->Add(argv[i]); 337 i++; 338 } 339 return 0; 340 } 341 -
src/apps/codycam/Settings.h
diff --git a/src/apps/codycam/Settings.h b/src/apps/codycam/Settings.h index cde0f82..dd76cc6 100644
a b 2 2 #define SETTINGS_H 3 3 4 4 #include "SettingsHandler.h" 5 #include <StringList.h> 5 6 6 7 void SetUpSettings(char* filename); 7 8 void QuitSettings(); … … protected: 95 96 virtual void SaveSettingValue(Settings *); 96 97 }; 97 98 99 100 //value of a string 101 class StringListSetting : public SettingsArgvDispatcher { 102 public: 103 StringListSetting(const char* name, 104 BStringList* defaultStringList); 105 106 virtual ~StringListSetting(); 107 108 void ValueChanged(BStringList *newList); 109 BStringList* Value() const; 110 virtual const char* Handle(const char *const *argv); 111 112 protected: 113 virtual void SaveSettingValue(Settings*); 114 virtual bool NeedsSaving() const; 115 116 BStringList* fDefaultStringList; 117 BStringList* fStringList; 118 119 }; 120 121 98 122 #endif // SETTINGS_H 123 124