119 lines
2.6 KiB
C++
119 lines
2.6 KiB
C++
/*
|
|
* Copyright 2024, Santiago Lema <santiago@lema.org>
|
|
* All rights reserved. Distributed under the terms of the MIT license.
|
|
*/
|
|
|
|
#include "App.h"
|
|
#include "MainWindow.h"
|
|
|
|
#include <AboutWindow.h>
|
|
#include <Catalog.h>
|
|
|
|
#include "Utils.h"
|
|
|
|
#undef B_TRANSLATION_CONTEXT
|
|
#define B_TRANSLATION_CONTEXT "Application"
|
|
|
|
const char *kApplicationSignature = "application/x-vnd.SLema-DumBer";
|
|
|
|
App::App() : BApplication(kApplicationSignature) {
|
|
|
|
BMessage s = LoadMessageFromFile(kSettingsFileName);
|
|
|
|
if (s.what=='STNG')
|
|
settingsMessage = s;
|
|
else
|
|
{
|
|
settingsMessage.what = 'STNG';
|
|
settingsMessage.AddInt32("settings_format_version", 1); // Initial data
|
|
}
|
|
|
|
MainWindow *m = new MainWindow();
|
|
m->SetLook(B_DOCUMENT_WINDOW_LOOK);
|
|
m->SetFeel(B_NORMAL_WINDOW_FEEL);
|
|
m->SetSizeLimits(350,B_SIZE_UNLIMITED,300,B_SIZE_UNLIMITED);
|
|
|
|
mainWindow = m;
|
|
mainWindow->Show();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
App::~App() {}
|
|
|
|
void App::AboutRequested() {
|
|
BAboutWindow *about = new BAboutWindow(B_TRANSLATE_SYSTEM_NAME("DumBer"),
|
|
kApplicationSignature);
|
|
about->AddDescription(B_TRANSLATE("about_body"));
|
|
about->AddCopyright(2025, "Santiago Lema");
|
|
about->AddText("e-mail me at haiku@lema.org");
|
|
about->AddText("or find me on the fediverse as\n@santi@gone.lema.org");
|
|
|
|
about->Show();
|
|
}
|
|
|
|
|
|
|
|
void App::MessageReceived(BMessage *message) {
|
|
|
|
switch (message->what) {
|
|
|
|
case kSettingsUpdate: {
|
|
|
|
// NO DO NOT CLEAR message, we can just overwrite one field and save the whole thing each time
|
|
//settingsMessage.MakeEmpty();
|
|
|
|
std::cout << "Received settings update: " ;
|
|
|
|
|
|
int32 count = message->CountNames(B_ANY_TYPE);
|
|
for (int32 index = 0; index < count; ++index) {
|
|
char* name;
|
|
uint32 type;
|
|
int32 itemCount;
|
|
|
|
std::cout << "Received settings update - key: " << name;
|
|
|
|
// Retrieve information about the item at the index
|
|
if (message->GetInfo(B_ANY_TYPE, index, &name, &type, &itemCount) == B_NO_ERROR) {
|
|
|
|
if (type == B_STRING_TYPE) {
|
|
BString value;
|
|
if (message->FindString(name, &value) == B_NO_ERROR) {
|
|
settingsMessage.AddString(name, value);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
SaveMessageToFile(settingsMessage,kSettingsFileName);
|
|
} break;
|
|
|
|
|
|
default: {
|
|
// message->PrintToStream();
|
|
BHandler::MessageReceived(
|
|
message); // call the parent handler for other messages
|
|
// _infoView->SetText(message->FindMessage());
|
|
break;
|
|
}
|
|
|
|
} // end switch
|
|
|
|
} // end function
|
|
|
|
|
|
|
|
int main() {
|
|
App *app = new App();
|
|
|
|
|
|
app->Run();
|
|
delete app;
|
|
return 0;
|
|
}
|