TheApp.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * Copyright 2009-2011, Andrea Anzani. All rights reserved.
  3. * Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
  4. * Copyright 2021, Jaidyn Levesque. All rights reserved.
  5. * Distributed under the terms of the MIT License.
  6. *
  7. * Authors:
  8. * Andrea Anzani, andrea.anzani@gmail.com
  9. * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
  10. * Jaidyn Levesque, jadedctrl@teknik.io
  11. */
  12. #include "TheApp.h"
  13. #include <stdio.h>
  14. #include <Alert.h>
  15. #include <Catalog.h>
  16. #include <Path.h>
  17. #include <Roster.h>
  18. #include <librunview/Emoticor.h>
  19. #include "AboutWindow.h"
  20. #include "ChatOMatic.h"
  21. #include "AppMessages.h"
  22. #include "FilePanel.h"
  23. #include "MainWindow.h"
  24. #include "ProtocolManager.h"
  25. #include "ReplicantStatusView.h"
  26. #include "Server.h"
  27. #undef B_TRANSLATION_CONTEXT
  28. #define B_TRANSLATION_CONTEXT "TheApp"
  29. int
  30. main(int argc, char* argv[])
  31. {
  32. TheApp app;
  33. app.Run();
  34. return 0;
  35. }
  36. TheApp::TheApp()
  37. :
  38. BApplication(APP_SIGNATURE),
  39. fMainWin(NULL)
  40. {
  41. }
  42. void
  43. TheApp::ReadyToRun()
  44. {
  45. app_info theInfo;
  46. fMainWin = new MainWindow();
  47. if (be_app->GetAppInfo(&theInfo) == B_OK) {
  48. BPath appDir(&theInfo.ref);
  49. appDir.GetParent(&appDir);
  50. // Emoticons settings
  51. BPath currentPath = appDir;
  52. currentPath.Append("smileys");
  53. currentPath.Append("settings.xml");
  54. // Load emoticons
  55. BEntry entry(currentPath.Path());
  56. if (entry.Exists())
  57. Emoticor::Get()->LoadConfig(currentPath.Path());
  58. else {
  59. BString msg(B_TRANSLATE("Can't find smileys settings in:\n\n%path%"));
  60. msg.ReplaceAll("%path%", currentPath.Path());
  61. BAlert* alert = new BAlert("", msg.String(), B_TRANSLATE("Ouch!"));
  62. // alert->Go();
  63. }
  64. printf("Loaded Emoticons settings from: %s\n", currentPath.Path());
  65. bool win = false;
  66. if (_LoadProtocols(B_SYSTEM_ADDONS_DIRECTORY)) win = true;
  67. if (_LoadProtocols(B_USER_ADDONS_DIRECTORY)) win = true;
  68. if (_LoadProtocols(B_SYSTEM_NONPACKAGED_ADDONS_DIRECTORY)) win = true;
  69. if (_LoadProtocols(B_USER_NONPACKAGED_ADDONS_DIRECTORY)) win = true;
  70. if (_LoadProtocols(appDir)) win = true;
  71. if (win == false) {
  72. BString msg(B_TRANSLATE("No protocols found!\nPlease make sure %app% was installed correctly."));
  73. msg.ReplaceAll("%app%", APP_NAME);
  74. BAlert* alert = new BAlert("", msg.String(), B_TRANSLATE("Ouch!"));
  75. alert->Go();
  76. PostMessage(B_QUIT_REQUESTED);
  77. return;
  78. }
  79. }
  80. fMainWin->Start();
  81. fMainWin->Show();
  82. }
  83. void
  84. TheApp::AboutRequested()
  85. {
  86. const char* holders[] = {
  87. "2009-2010 Andrea Anzani",
  88. "2010-2015 Dario Casalinuovo",
  89. "2009-2010 Pier Luigi Fiorini",
  90. "2021 Jaidyn Levesque",
  91. NULL
  92. };
  93. const char* authors[] = {
  94. "Andrea Anzani",
  95. "Dario Casalinuovo",
  96. "Pier Luigi Fiorini",
  97. "Jaidyn Levesque",
  98. NULL
  99. };
  100. BString extraInfo(B_TRANSLATE("%app% is released under the MIT License.\n"
  101. "Add-on and library licenses may vary.\n"
  102. "Built: %buildDate%"));
  103. extraInfo.ReplaceAll("%buildDate", BUILD_DATE);
  104. extraInfo.ReplaceAll("%app%", B_TRANSLATE_SYSTEM_NAME(APP_NAME));
  105. AboutWindow* about = new AboutWindow(B_TRANSLATE_SYSTEM_NAME(APP_NAME),
  106. holders, authors, extraInfo.String());
  107. about->Show();
  108. delete about;
  109. }
  110. MainWindow*
  111. TheApp::GetMainWindow() const
  112. {
  113. return fMainWin;
  114. }
  115. void
  116. TheApp::MessageReceived(BMessage* message)
  117. {
  118. switch (message->what) {
  119. case APP_REPLICANT_STATUS_SET:
  120. case APP_REPLICANT_SHOW_WINDOW:
  121. case APP_SHOW_SETTINGS:
  122. case APP_REPLICANT_MESSENGER:
  123. DetachCurrentMessage();
  124. fMainWin->PostMessage(message);
  125. break;
  126. case APP_REPLICANT_EXIT:
  127. // TODO BAlert here
  128. PostMessage(B_QUIT_REQUESTED);
  129. break;
  130. default:
  131. BLooper::MessageReceived(message);
  132. }
  133. }
  134. bool
  135. TheApp::_LoadProtocols(directory_which finddir)
  136. {
  137. BPath path;
  138. if (find_directory(finddir, &path) == B_OK)
  139. return _LoadProtocols(path);
  140. return false;
  141. }
  142. bool
  143. TheApp::_LoadProtocols(BPath path)
  144. {
  145. path.Append(BString(APP_NAME).ToLower());
  146. if (BEntry(path.Path()).Exists()) {
  147. printf("Looking for protocols from: %s\n", path.Path());
  148. return ProtocolManager::Get()->Init(BDirectory(path.Path()), fMainWin);
  149. }
  150. return false;
  151. }