Chat-O-Matic/application/TheApp.cpp

162 lines
3.3 KiB
C++
Raw Normal View History

/*
2011-12-03 16:38:03 -06:00
* Copyright 2009-2011, Andrea Anzani. All rights reserved.
* Copyright 2009-2011, Pier Luigi Fiorini. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Andrea Anzani, andrea.anzani@gmail.com
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/
2021-05-19 16:12:19 -05:00
#include "TheApp.h"
#include <stdio.h>
#include <Alert.h>
2021-07-19 09:54:27 -05:00
#include <Catalog.h>
#include <Path.h>
#include <Roster.h>
2021-05-19 16:12:19 -05:00
#include <librunview/Emoticor.h>
2010-05-12 13:57:19 -05:00
#include "AboutWindow.h"
2021-06-22 01:06:00 -05:00
#include "Cardie.h"
2021-06-20 12:44:20 -05:00
#include "AppMessages.h"
#include "FilePanel.h"
#include "MainWindow.h"
#include "ProtocolManager.h"
#include "ReplicantStatusView.h"
#include "Server.h"
2021-07-19 09:54:27 -05:00
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "TheApp"
2021-06-23 14:15:22 -05:00
int
main(int argc, char* argv[])
{
TheApp app;
app.Run();
return 0;
}
TheApp::TheApp()
2010-05-19 17:28:26 -05:00
:
2021-06-20 12:44:20 -05:00
BApplication(APP_SIGNATURE),
fMainWin(NULL)
{
}
void
TheApp::ReadyToRun()
{
app_info theInfo;
fMainWin = new MainWindow();
if (be_app->GetAppInfo(&theInfo) == B_OK) {
BPath appDir(&theInfo.ref);
appDir.GetParent(&appDir);
// Emoticons settings
BPath currentPath = appDir;
currentPath.Append("smileys");
currentPath.Append("settings.xml");
// Load emoticons
BEntry entry(currentPath.Path());
if (entry.Exists())
Emoticor::Get()->LoadConfig(currentPath.Path());
else {
2021-07-19 09:54:27 -05:00
BString msg(B_TRANSLATE("Can't find smileys settings in:\n\n%path%"));
msg.ReplaceAll("%path%", currentPath.Path());
BAlert* alert = new BAlert("", msg.String(), B_TRANSLATE("Ouch!"));
// alert->Go();
}
printf("Loaded Emoticons settings from: %s\n", currentPath.Path());
currentPath = appDir;
currentPath.Append("protocols");
if (BEntry(currentPath.Path()).Exists()) {
printf("Looking for protocols from: %s\n", currentPath.Path());
ProtocolManager::Get()->Init(BDirectory(currentPath.Path()),
fMainWin);
} else {
2021-07-19 09:54:27 -05:00
BString msg("Can't find protocols in:\n\n%path%");
msg.ReplaceAll("%path%", currentPath.Path());
BAlert* alert = new BAlert("", msg.String(), B_TRANSLATE("Ouch!"));
alert->Go();
PostMessage(B_QUIT_REQUESTED);
return;
}
}
fMainWin->Start();
fMainWin->Show();
}
2010-05-12 13:57:19 -05:00
void
TheApp::AboutRequested()
{
const char* holders[] = {
"2009-2010 Andrea Anzani",
"2010-2015 Dario Casalinuovo",
2010-05-12 13:57:19 -05:00
"2009-2010 Pier Luigi Fiorini",
2021-06-22 01:06:00 -05:00
"2021 Jaidyn Levesque",
2010-05-12 13:57:19 -05:00
NULL
};
const char* authors[] = {
"Andrea Anzani",
"Dario Casalinuovo",
2010-05-12 13:57:19 -05:00
"Pier Luigi Fiorini",
2021-06-20 12:44:20 -05:00
"Jaidyn Levesque",
2010-05-12 13:57:19 -05:00
NULL
};
2021-07-19 09:54:27 -05:00
BString extraInfo(B_TRANSLATE("%app% is released under the GNU GPL "
"License.\nSome parts of %app% are available under MIT license.\n"
"Built: %buildDate%"));
extraInfo.ReplaceAll("%buildDate", BUILD_DATE);
extraInfo.ReplaceAll("%app%", B_TRANSLATE_SYSTEM_NAME(APP_NAME));
2010-05-12 13:57:19 -05:00
2021-07-19 09:54:27 -05:00
AboutWindow* about = new AboutWindow(B_TRANSLATE_SYSTEM_NAME(APP_NAME),
holders, authors, extraInfo.String());
2010-05-12 13:57:19 -05:00
about->Show();
delete about;
2010-05-12 13:57:19 -05:00
}
MainWindow*
TheApp::GetMainWindow() const
{
return fMainWin;
}
void
TheApp::MessageReceived(BMessage* message)
{
switch (message->what) {
2021-06-20 12:44:20 -05:00
case APP_REPLICANT_STATUS_SET:
case APP_REPLICANT_SHOW_WINDOW:
case APP_SHOW_SETTINGS:
case APP_REPLICANT_MESSENGER:
DetachCurrentMessage();
fMainWin->PostMessage(message);
break;
2021-06-20 12:44:20 -05:00
case APP_REPLICANT_EXIT:
// TODO BAlert here
PostMessage(B_QUIT_REQUESTED);
break;
default:
BLooper::MessageReceived(message);
}
}