| 1 | /* |
| 2 | * File: Preferences.h |
| 3 | * |
| 4 | * Author: Jacob Dekel |
| 5 | * Created on: Aug 7, 2009 |
| 6 | * |
| 7 | * Copyright (c) 2009-2013 Jacob Dekel |
| 8 | * $Id$ |
| 9 | * |
| 10 | * This singleton object manages user preferences |
| 11 | * |
| 12 | * This program is free software: you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation, either version 3 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #ifndef PREFERENCES_H_ |
| 28 | #define PREFERENCES_H_ |
| 29 | |
| 30 | #include "Psw.h" |
| 31 | #include "HerculesStudio.h" |
| 32 | |
| 33 | #include <string> |
| 34 | #include <vector> |
| 35 | |
| 36 | #include <QString> |
| 37 | |
| 38 | class Preferences_1_0 |
| 39 | { |
| 40 | public: |
| 41 | enum keys |
| 42 | { |
| 43 | HerculesDir = 0, |
| 44 | ConfigurationDir = 1, |
| 45 | LogsDir = 2, |
| 46 | Font = 3, |
| 47 | FontSize = 4, |
| 48 | FontVariation = 5, |
| 49 | LogTimestamp = 6, |
| 50 | RegsViews = 7 |
| 51 | }; |
| 52 | enum general |
| 53 | { |
| 54 | NumberOfLines = 8 |
| 55 | }; |
| 56 | |
| 57 | enum Views |
| 58 | { |
| 59 | ViewGR32 = 0x80, |
| 60 | ViewCR32 = 0x40, |
| 61 | ViewFR32 = 0x20, |
| 62 | ViewAR32 = 0x10, |
| 63 | ViewGR64 = 0x08, |
| 64 | ViewCR64 = 0x04, |
| 65 | ViewFR64 = 0x02, |
| 66 | ViewPsw = 0x01 |
| 67 | }; |
| 68 | |
| 69 | enum VariationMasks |
| 70 | { |
| 71 | Bold = 128, |
| 72 | Italic = 64 |
| 73 | }; |
| 74 | |
| 75 | virtual ~Preferences_1_0(); |
| 76 | static Preferences_1_0& getInstance(); |
| 77 | |
| 78 | void write(); |
| 79 | |
| 80 | void setHercDir(const std::string& hercDir); |
| 81 | std::string& hercDir(){return mPrefs[HerculesDir]; } |
| 82 | void setConfigDir(const std::string& logsDir) ; |
| 83 | void setVolatileConfigDir(const std::string& logsDir) ; |
| 84 | const std::string& configDir(); |
| 85 | void setLogsDir(const std::string& logsDir) ; |
| 86 | std::string& logsDir(){return mPrefs[LogsDir]; } |
| 87 | void setFontName( const std::string& fontName) ; |
| 88 | std::string& fontName () ; |
| 89 | void setFontSize( int variation ); |
| 90 | int fontSize(); |
| 91 | void setFontVariation( int variation ); |
| 92 | int fontVariation(); |
| 93 | bool fontIsBold(); |
| 94 | bool fontIsItalic(); |
| 95 | bool logTimestamp(); |
| 96 | void setLogTimestamp(bool isTrue); |
| 97 | |
| 98 | // register views |
| 99 | void setRegs(Views v,bool view); |
| 100 | bool regs(Views v); |
| 101 | |
| 102 | protected: |
| 103 | Preferences_1_0(); |
| 104 | private: |
| 105 | void readPref(); |
| 106 | void assertConfDir(); |
| 107 | std::string getValue(char * line, const char * keyword); |
| 108 | QString getFileName(); |
| 109 | |
| 110 | std::string mPath; |
| 111 | int mView; |
| 112 | std::string mVolatileConfigDir; |
| 113 | |
| 114 | static Preferences_1_0 *instance; |
| 115 | static const char *sFileName; |
| 116 | static const char *sKeywords[]; |
| 117 | std::vector<std::string> mPrefs; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | class Preferences_1_1 |
| 122 | { |
| 123 | public: |
| 124 | enum keys |
| 125 | { |
| 126 | HerculesDir = 0, |
| 127 | ConfigurationDir = 1, |
| 128 | LogsDir = 2, |
| 129 | Font = 3, |
| 130 | FontSize = 4, |
| 131 | FontVariation = 5, |
| 132 | LogTimestamp = 6, |
| 133 | RegsViews = 7, |
| 134 | Version = 8, |
| 135 | LogFont = 9, |
| 136 | RegsFont = 10, |
| 137 | PswFont = 11, |
| 138 | CommandFont = 12 |
| 139 | }; |
| 140 | enum FontObject |
| 141 | { |
| 142 | LogFontObject = 0, |
| 143 | RegsFontObject = 1, |
| 144 | PswFontObject = 2, |
| 145 | CommandFontObject = 3 |
| 146 | }; |
| 147 | enum general |
| 148 | { |
| 149 | NumberOfLines = 13, |
| 150 | PREF_LINE_LENGTH = 300 |
| 151 | }; |
| 152 | |
| 153 | enum Views |
| 154 | { |
| 155 | ViewGR32 = 0x80, |
| 156 | ViewCR32 = 0x40, |
| 157 | ViewFR32 = 0x20, |
| 158 | ViewAR32 = 0x10, |
| 159 | ViewGR64 = 0x08, |
| 160 | ViewCR64 = 0x04, |
| 161 | ViewFR64 = 0x02, |
| 162 | ViewPsw = 0x01 |
| 163 | }; |
| 164 | |
| 165 | virtual ~Preferences_1_1(); |
| 166 | static Preferences_1_1& getInstance(); |
| 167 | |
| 168 | void write(); |
| 169 | |
| 170 | // hercules directory |
| 171 | void setHercDir(const std::string& hercDir); |
| 172 | std::string& hercDir(){return mPrefs[HerculesDir]; } |
| 173 | |
| 174 | // configuration default directory |
| 175 | void setConfigDir(const std::string& logsDir) ; |
| 176 | void setVolatileConfigDir(const std::string& logsDir) ; |
| 177 | const std::string& configDir(); |
| 178 | |
| 179 | // log directory |
| 180 | void setLogsDir(const std::string& logsDir) ; |
| 181 | std::string& logsDir(){return mPrefs[LogsDir]; } |
| 182 | |
| 183 | // font name |
| 184 | void setFontName( FontObject fontObject, const std::string& fontName) ; |
| 185 | std::string fontName (FontObject fontObject) ; |
| 186 | |
| 187 | // font size |
| 188 | void setFontSize( FontObject fontObject, int variation ); |
| 189 | int fontSize(FontObject fontObject); |
| 190 | |
| 191 | // bold |
| 192 | void setBold( FontObject fontObject, bool bold); |
| 193 | bool fontIsBold(FontObject fontObject); |
| 194 | |
| 195 | // italic |
| 196 | void setItalic (FontObject fontObject, bool italic); |
| 197 | bool fontIsItalic(FontObject fontObject); |
| 198 | |
| 199 | // logs time stamp |
| 200 | bool logTimestamp(); |
| 201 | void setLogTimestamp(bool isTrue); |
| 202 | const std::string& version(); |
| 203 | |
| 204 | // register views |
| 205 | void setRegs(Views v,bool view); |
| 206 | bool regs(Views v); |
| 207 | |
| 208 | protected: |
| 209 | Preferences_1_1(); |
| 210 | |
| 211 | private: |
| 212 | void readPref(); |
| 213 | void assertConfDir(); |
| 214 | std::string getValue(char * line, const char * keyword); |
| 215 | QString getFileName(); |
| 216 | const std::string& getVersion(); |
| 217 | keys fontObjectToIndex(FontObject fontObject); |
| 218 | |
| 219 | std::string mPath; |
| 220 | int mView; |
| 221 | std::string mVolatileConfigDir; |
| 222 | |
| 223 | static Preferences_1_1 *instance; |
| 224 | static const char *sFileName; |
| 225 | static const char *sKeywords[]; |
| 226 | std::vector<std::string> mPrefs; |
| 227 | static const char cFontLog[], cFontRegs[], cFontPsw[], cFontCommand[]; |
| 228 | }; |
| 229 | |
| 230 | class Preferences_1_2_0 |
| 231 | { |
| 232 | public: |
| 233 | enum keys |
| 234 | { |
| 235 | HerculesDir = 0, |
| 236 | ConfigurationDir = 1, |
| 237 | LogsDir = 2, |
| 238 | Font = 3, |
| 239 | FontSize = 4, |
| 240 | FontVariation = 5, |
| 241 | LogTimestamp = 6, |
| 242 | RegsViews = 7, |
| 243 | Version = 8, |
| 244 | LogFont = 9, |
| 245 | RegsFont = 10, |
| 246 | PswFont = 11, |
| 247 | CommandFont = 12, |
| 248 | MipsAsGauge = 13, |
| 249 | PswMode = 14, |
| 250 | SplitLog = 15, |
| 251 | AutosaveLog = 16 |
| 252 | }; |
| 253 | enum FontObject |
| 254 | { |
| 255 | LogFontObject = 0, |
| 256 | RegsFontObject = 1, |
| 257 | PswFontObject = 2, |
| 258 | CommandFontObject = 3 |
| 259 | }; |
| 260 | enum general |
| 261 | { |
| 262 | NumberOfLines = 17, |
| 263 | PREF_LINE_LENGTH = 300 |
| 264 | }; |
| 265 | |
| 266 | enum Views |
| 267 | { |
| 268 | ViewGR32 = 0x80, |
| 269 | ViewCR32 = 0x40, |
| 270 | ViewFR32 = 0x20, |
| 271 | ViewAR32 = 0x10, |
| 272 | ViewGR64 = 0x08, |
| 273 | ViewCR64 = 0x04, |
| 274 | ViewFR64 = 0x02, |
| 275 | ViewPsw = 0x01 |
| 276 | }; |
| 277 | |
| 278 | virtual ~Preferences_1_2_0(); |
| 279 | static Preferences_1_2_0& getInstance(); |
| 280 | |
| 281 | void write(); |
| 282 | |
| 283 | // hercules directory |
| 284 | void setHercDir(const std::string& hercDir); |
| 285 | std::string& hercDir(){return mPrefs[HerculesDir]; } |
| 286 | |
| 287 | // configuration default directory |
| 288 | void setConfigDir(const std::string& logsDir) ; |
| 289 | void setVolatileConfigDir(const std::string& logsDir) ; |
| 290 | const std::string& configDir(); |
| 291 | |
| 292 | // log directory |
| 293 | void setLogsDir(const std::string& logsDir) ; |
| 294 | std::string& logsDir(){return mPrefs[LogsDir]; } |
| 295 | |
| 296 | // font name |
| 297 | void setFontName( FontObject fontObject, const std::string& fontName) ; |
| 298 | std::string fontName (FontObject fontObject) ; |
| 299 | |
| 300 | // font size |
| 301 | void setFontSize( FontObject fontObject, int variation ); |
| 302 | int fontSize(FontObject fontObject); |
| 303 | |
| 304 | // bold |
| 305 | void setBold( FontObject fontObject, bool bold); |
| 306 | bool fontIsBold(FontObject fontObject); |
| 307 | |
| 308 | // italic |
| 309 | void setItalic (FontObject fontObject, bool italic); |
| 310 | bool fontIsItalic(FontObject fontObject); |
| 311 | |
| 312 | // logs time stamp |
| 313 | bool logTimestamp(); |
| 314 | void setLogTimestamp(bool isTrue); |
| 315 | const std::string& version(); |
| 316 | |
| 317 | // register views |
| 318 | void setRegs(Views v,bool view); |
| 319 | bool regs(Views v); |
| 320 | |
| 321 | // Mips as gauge |
| 322 | void setMipsAsGauge(bool gauge); |
| 323 | bool mipsAsGauge(); |
| 324 | |
| 325 | // Psw Mode |
| 326 | Psw::PswMode pswMode(); |
| 327 | void setPswMode(Psw::PswMode mode); |
| 328 | |
| 329 | // Split log |
| 330 | bool splitLog(); |
| 331 | void setSplitLog(bool); |
| 332 | |
| 333 | // Autosave log |
| 334 | bool autosaveLog(); |
| 335 | void setAutosaveLog(bool); |
| 336 | |
| 337 | protected: |
| 338 | Preferences_1_2_0(); |
| 339 | |
| 340 | private: |
| 341 | void readPref(); |
| 342 | void assertConfDir(); |
| 343 | std::string getValue(char * line, const char * keyword); |
| 344 | QString getFileName(); |
| 345 | const std::string& getVersion(); |
| 346 | keys fontObjectToIndex(FontObject fontObject); |
| 347 | |
| 348 | QString mPath; |
| 349 | int mView; |
| 350 | std::string mVolatileConfigDir; |
| 351 | |
| 352 | static Preferences_1_2_0 *instance; |
| 353 | static const char *sFileName; |
| 354 | static const char *sKeywords[]; |
| 355 | std::vector<std::string> mPrefs; |
| 356 | static const char cFontLog[], cFontRegs[], cFontPsw[], cFontCommand[], |
| 357 | cMipsAsGauge[], cPswMode[], cSplitLog[], cAutosaveLog[]; |
| 358 | }; |
| 359 | |
| 360 | class QSettings; |
| 361 | mk_shared_ptr(PrinterItem) |
| 362 | mk_shared_ptr(Stationery) |
| 363 | class DecolationRules; |
| 364 | |
| 365 | class Preferences |
| 366 | { |
| 367 | public: |
| 368 | enum keys |
| 369 | { |
| 370 | HerculesDir = 0, |
| 371 | ConfigurationDir = 1, |
| 372 | LogsDir = 2, |
| 373 | LogTimestamp = 3, |
| 374 | RegsViews = 4, |
| 375 | Version = 5, |
| 376 | LogFont = 6, |
| 377 | RegsFont = 7, |
| 378 | PswFont = 8, |
| 379 | CommandFont = 9, |
| 380 | MipsAsGauge = 10, |
| 381 | PswMode = 11, |
| 382 | SplitLog = 12, |
| 383 | AutosaveLog = 13, |
| 384 | Theme = 14, |
| 385 | LogFileLines = 15, |
| 386 | GreenLed = 16, |
| 387 | Animate=17, |
| 388 | DarkBackground=18, |
| 389 | IplDevice=19, |
| 390 | LastPrinterName=20, |
| 391 | BalloonDecolation=21, |
| 392 | BalloonStationery=22 |
| 393 | }; |
| 394 | |
| 395 | enum FontObject |
| 396 | { |
| 397 | LogFontObject = 0, |
| 398 | RegsFontObject = 1, |
| 399 | PswFontObject = 2, |
| 400 | CommandFontObject = 3, |
| 401 | ConfigurationFontObject = 4 |
| 402 | }; |
| 403 | |
| 404 | enum Views |
| 405 | { |
| 406 | ViewGR32 = 0, |
| 407 | ViewCR32 = 1, |
| 408 | ViewFR32 = 2, |
| 409 | ViewAR32 = 3, |
| 410 | ViewGR64 = 4, |
| 411 | ViewCR64 = 5, |
| 412 | ViewFR64 = 6, |
| 413 | ViewPsw = 7 |
| 414 | }; |
| 415 | |
| 416 | enum Themes |
| 417 | { |
| 418 | Classic = 0, |
| 419 | Modern = 1 |
| 420 | }; |
| 421 | |
| 422 | virtual ~Preferences(); |
| 423 | static Preferences& getInstance(); |
| 424 | |
| 425 | void write(); |
| 426 | |
| 427 | // hercules directory |
| 428 | void setHercDir(const std::string& hercDir); |
| 429 | std::string hercDir() const; |
| 430 | |
| 431 | // configuration default directory |
| 432 | void setConfigDir(const std::string& configDir) ; |
| 433 | void setVolatileConfigDir(const std::string& logsDir) ; |
| 434 | std::string configDir() const; |
| 435 | std::string configDir_() const; |
| 436 | |
| 437 | // log directory |
| 438 | void setLogsDir(const std::string& logsDir) ; |
| 439 | std::string logsDir() const; |
| 440 | |
| 441 | // font name |
| 442 | void setFontName( FontObject fontObject, const std::string& fontName) ; |
| 443 | std::string fontName (FontObject fontObject) const; |
| 444 | |
| 445 | // font size |
| 446 | void setFontSize( FontObject fontObject, int variation ); |
| 447 | int fontSize(FontObject fontObject) const; |
| 448 | |
| 449 | // bold |
| 450 | void setBold( FontObject fontObject, bool bold); |
| 451 | bool fontIsBold(FontObject fontObject) const; |
| 452 | |
| 453 | // italic |
| 454 | void setItalic (FontObject fontObject, bool italic); |
| 455 | bool fontIsItalic(FontObject fontObject) const; |
| 456 | |
| 457 | // logs time stamp |
| 458 | bool logTimestamp() const; |
| 459 | void setLogTimestamp(bool isTrue); |
| 460 | const std::string& version() const; |
| 461 | |
| 462 | // register views |
| 463 | void setRegs(Views v,bool view); |
| 464 | bool regs(Views v) const; |
| 465 | |
| 466 | // Mips as gauge |
| 467 | void setMipsAsGauge(bool gauge); |
| 468 | bool mipsAsGauge() const; |
| 469 | |
| 470 | // Led Color green (mips) |
| 471 | void setGreenLed(bool green); |
| 472 | bool greenLed() const; |
| 473 | |
| 474 | // Psw Mode |
| 475 | void setPswMode(Psw::PswMode mode); |
| 476 | Psw::PswMode pswMode() const; |
| 477 | |
| 478 | // Split log |
| 479 | bool splitLog() const; |
| 480 | void setSplitLog(bool); |
| 481 | |
| 482 | // Autosave log |
| 483 | void setAutosaveLog(bool); |
| 484 | bool autosaveLog() const; |
| 485 | |
| 486 | // theme |
| 487 | void setTheme(Themes theme); |
| 488 | Themes theme() const; |
| 489 | |
| 490 | // LogFileLines |
| 491 | void setLogFileLines(int lines); |
| 492 | int logFileLines() const; |
| 493 | |
| 494 | //command line history |
| 495 | void setHistory(QVector<QString>& history); |
| 496 | void getHistory(QVector<QString>& history); |
| 497 | |
| 498 | //animation |
| 499 | void setAnimate(bool animate); |
| 500 | bool animate() const; |
| 501 | |
| 502 | //dark background |
| 503 | void setDarkBackground(bool dark); |
| 504 | bool darkBackground() const; |
| 505 | |
| 506 | // IPL device |
| 507 | void setIplDevice(const std::string& iplDevice); |
| 508 | std::string iplDevice() const; |
| 509 | |
| 510 | // Stationery |
| 511 | bool setStationery(const QString& name, const QString& stationeryString, bool replace=true); |
| 512 | bool setStationery(const QString& name, const Stationery& stationery, bool replace=true); |
| 513 | StationeryPtr stationery(QString name); |
| 514 | QStringList stationeryList(); |
| 515 | void deleteStationery(const QString& item); |
| 516 | |
| 517 | // Printers |
| 518 | bool setPrinter(const QString& name, const PrinterItem& printerItem, bool replace=true); |
| 519 | PrinterItemPtr printer(QString name); |
| 520 | QStringList printerList(); |
| 521 | void deletePrinter(const QString& item); |
| 522 | void setLastPrinterName(const std::string& lastPrinterName); |
| 523 | std::string lastPrinterName() const; |
| 524 | |
| 525 | // Decolations |
| 526 | DecolationRules *decolation(QString name); |
| 527 | QStringList decolationList(); |
| 528 | void deleteDecolation(const QString& item); |
| 529 | void setDecolation(DecolationRules& decolation); |
| 530 | |
| 531 | void setBalloonDecolation(bool popped); |
| 532 | bool balloonDecolation() const; |
| 533 | |
| 534 | void setBalloonStationery(bool popped); |
| 535 | bool balloonStationery() const; |
| 536 | |
| 537 | |
| 538 | protected: |
| 539 | Preferences(); |
| 540 | |
| 541 | private: |
| 542 | static Preferences *instance; |
| 543 | QSettings *mSettings; |
| 544 | |
| 545 | static const char *sKeywords[]; |
| 546 | static const char *sRegsViews[]; |
| 547 | std::string mVolatileConfigDir; |
| 548 | |
| 549 | const char * fontObjectToString(FontObject fontObject) const; |
| 550 | void defaultDecolations(); |
| 551 | void defaultStationery(); |
| 552 | void convert(); |
| 553 | }; |
| 554 | |
| 555 | #endif /* PREFERENCES_H_ */ |