AppPreferences.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2012, Casalinuovo Dario. All rights reserved.
  3. * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
  4. * All rights reserved. Distributed under the terms of the MIT license.
  5. */
  6. #include "AppPreferences.h"
  7. #include "Utils.h"
  8. AppPreferences* AppPreferences::fInstance = NULL;
  9. AppPreferences*
  10. AppPreferences::Get()
  11. {
  12. if (fInstance == NULL) {
  13. fInstance = new AppPreferences();
  14. fInstance->Load();
  15. }
  16. return fInstance;
  17. }
  18. void
  19. AppPreferences::Load()
  20. {
  21. const char* path = _PreferencesPath();
  22. BFile file(_PreferencesPath(), B_READ_ONLY);
  23. BMessage settings;
  24. if (file.InitCheck() == B_OK)
  25. settings.Unflatten(&file);
  26. MoveToCurrentWorkspace = settings.GetBool("MoveToCurrentWorkpace", false);
  27. RaiseOnMessageReceived = settings.GetBool("RaiseOnMessageReceived", false);
  28. MarkUnreadWindow = settings.GetBool("MarkUnreadWindow", false);
  29. NotifyProtocolStatus = settings.GetBool("NotifyProtocolStatus", true);
  30. NotifyNewMessage = settings.GetBool("NotifyNewMessage", true);
  31. NotifyContactStatus = settings.GetBool("NotifyContactStatus", false);
  32. SoundOnMessageReceived = settings.GetBool("SoundOnMessageReceived", true);
  33. SoundOnMention = settings.GetBool("SoundOnMention", true);
  34. HideDeskbar = settings.GetBool("HideDeskbar", false);
  35. DisableReplicant = settings.GetBool("DisableReplicant", true);
  36. DisableQuitConfirm = settings.GetBool("DisableQuitConfirm", false);
  37. IgnoreEmoticons = settings.GetBool("IgnoreEmoticons", true);
  38. HideOffline = settings.GetBool("HideOffline", false);
  39. MainWindowListWeight = settings.GetFloat("MainWindowListWeight", 1);
  40. MainWindowChatWeight = settings.GetFloat("MainWindowChatWeight", 5);
  41. ChatViewHorizChatWeight = settings.GetFloat("ChatViewHorizChatWeight", 8);
  42. ChatViewHorizListWeight = settings.GetFloat("ChatViewHorizListWeight", 1);
  43. ChatViewVertChatWeight = settings.GetFloat("ChatViewVertChatWeight", 20);
  44. ChatViewVertSendWeight = settings.GetFloat("ChatViewVertSendWeight", 1);
  45. MainWindowRect = settings.GetRect("MainWindowRect", BRect(0, 0, 600, 400));
  46. }
  47. void
  48. AppPreferences::Save()
  49. {
  50. const char* path = _PreferencesPath();
  51. BFile file(_PreferencesPath(), B_WRITE_ONLY | B_CREATE_FILE);
  52. BMessage settings;
  53. settings.AddBool("MoveToCurrentWorkpace", MoveToCurrentWorkspace);
  54. settings.AddBool("RaiseOnMessageReceived", RaiseOnMessageReceived);
  55. settings.AddBool("MarkUnreadWindow", MarkUnreadWindow);
  56. settings.AddBool("NotifyProtocolStatus", NotifyProtocolStatus);
  57. settings.AddBool("NotifyNewMessage", NotifyNewMessage);
  58. settings.AddBool("NotifyContactStatus", NotifyContactStatus);
  59. settings.AddBool("SoundOnMessageReceived", SoundOnMessageReceived);
  60. settings.AddBool("SoundOnMention", SoundOnMention);
  61. settings.AddBool("HideDeskbar", HideDeskbar);
  62. settings.AddBool("DisableReplicant", DisableReplicant);
  63. settings.AddBool("DisableQuitConfirm", DisableQuitConfirm);
  64. settings.AddBool("IgnoreEmoticons", IgnoreEmoticons);
  65. settings.AddBool("HideOffline", HideOffline);
  66. settings.AddFloat("MainWindowListWeight", MainWindowListWeight);
  67. settings.AddFloat("MainWindowChatWeight", MainWindowChatWeight);
  68. settings.AddFloat("ChatViewHorizChatWeight", ChatViewHorizChatWeight);
  69. settings.AddFloat("ChatViewHorizListWeight", ChatViewHorizListWeight);
  70. settings.AddFloat("ChatViewVertChatWeight", ChatViewVertChatWeight);
  71. settings.AddFloat("ChatViewVertSendWeight", ChatViewVertSendWeight);
  72. settings.AddRect("MainWindowRect", MainWindowRect);
  73. if (file.InitCheck() == B_OK)
  74. settings.Flatten(&file);
  75. }
  76. const char*
  77. AppPreferences::_PreferencesPath()
  78. {
  79. BPath path(SettingsPath());
  80. path.Append("preferences");
  81. return path.Path();
  82. }