2024-11-12 14:53:44 -08:00
|
|
|
#include "aboutwindow.h"
|
|
|
|
#include <SplitView.h>
|
|
|
|
#include <license.hpp>
|
|
|
|
#include <GroupLayout.h>
|
|
|
|
#include <SplitView.h>
|
|
|
|
#include <StringView.h>
|
|
|
|
#include <ScrollView.h>
|
|
|
|
#include "main_window.h"
|
|
|
|
#define CMD_LOAD_LICENSE 0x40
|
2024-11-21 10:22:34 -08:00
|
|
|
HaikuLicenseItem::HaikuLicenseItem(const LicenseData license) : BStringItem("") {
|
2024-11-12 14:53:44 -08:00
|
|
|
SetText(fmt::format("{} ({})", license.Project, license.Spdx).c_str());
|
|
|
|
this->license_text = license.LicenseContents;
|
|
|
|
}
|
|
|
|
|
2024-11-21 10:22:34 -08:00
|
|
|
HaikuAboutWindow::HaikuAboutWindow() : BWindow(BRect(100, 100, 600, 400), "About Looper", B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS) {
|
2024-11-12 14:53:44 -08:00
|
|
|
BGroupLayout *root_layout = new BGroupLayout(B_VERTICAL);
|
|
|
|
float minW, minH, maxW, maxH;
|
|
|
|
GetSizeLimits(&minW, &maxW, &minH, &maxH);
|
|
|
|
SetLayout(root_layout);
|
|
|
|
root_layout->SetSpacing(0.0);
|
|
|
|
BFont *title_font = new BFont();
|
|
|
|
title_font->SetSize(title_font->Size() * 4.0);
|
|
|
|
BStringView *looper_title = new BStringView("about:title", "Looper");
|
|
|
|
looper_title->SetAlignment(B_ALIGN_HORIZONTAL_CENTER);
|
|
|
|
looper_title->SetFont(title_font);
|
|
|
|
float title_height, version_height;
|
|
|
|
looper_title->GetPreferredSize(NULL, &title_height);
|
|
|
|
looper_title->SetExplicitMaxSize(BSize(maxW, title_height));
|
|
|
|
looper_title->ResizeToPreferred();
|
|
|
|
BStringView *version_text = new BStringView("about:version_text", fmt::format("Version {}", TAG).c_str());
|
|
|
|
version_text->SetAlignment(B_ALIGN_HORIZONTAL_CENTER);
|
|
|
|
version_text->GetPreferredSize(NULL, &version_height);
|
|
|
|
version_text->SetExplicitMaxSize(BSize(maxW, version_height));
|
|
|
|
version_text->ResizeToPreferred();
|
|
|
|
BLayoutItem *title_item = root_layout->AddView(looper_title);
|
|
|
|
BLayoutItem *version_item = root_layout->AddView(version_text);
|
|
|
|
title_item->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
|
|
|
version_item->SetExplicitAlignment(BAlignment(B_ALIGN_HORIZONTAL_CENTER, B_ALIGN_VERTICAL_CENTER));
|
|
|
|
BSplitView *view = new BSplitView();
|
|
|
|
view->SetExplicitMaxSize(BSize(maxW, maxH));
|
|
|
|
root_layout->AddView(view);
|
|
|
|
license_list = new BListView();
|
|
|
|
license_list->SetTarget(this);
|
|
|
|
for (auto &license : get_license_data()) {
|
2024-11-21 10:43:50 -08:00
|
|
|
license_list->AddItem(new HaikuLicenseItem(license));
|
2024-11-12 14:53:44 -08:00
|
|
|
}
|
|
|
|
license_list->SetSelectionMessage(new BMessage(CMD_LOAD_LICENSE));
|
|
|
|
BScrollView *license_list_scroller = new BScrollView("about:license-list-scroller", license_list, B_FOLLOW_ALL_SIDES, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS, false, true);
|
|
|
|
license_text = new BTextView("about:license-text");
|
|
|
|
license_text->MakeEditable(false);
|
|
|
|
BScrollView *license_text_scroller = new BScrollView("about:license-text-scroller", license_text, B_FOLLOW_ALL_SIDES, B_SUPPORTS_LAYOUT|B_FRAME_EVENTS, false, true);
|
|
|
|
view->AddChild(license_list_scroller);
|
|
|
|
view->AddChild(license_text_scroller);
|
|
|
|
license_list->Select(0);
|
|
|
|
InvalidateLayout(true);
|
|
|
|
UpdateIfNeeded();
|
|
|
|
}
|
2024-11-21 10:22:34 -08:00
|
|
|
void HaikuAboutWindow::Show() {
|
2024-11-12 14:53:44 -08:00
|
|
|
BWindow::Show();
|
|
|
|
}
|
2024-11-21 10:22:34 -08:00
|
|
|
bool HaikuAboutWindow::QuitRequested() {
|
2024-11-12 14:53:44 -08:00
|
|
|
Hide();
|
|
|
|
return quitting;
|
|
|
|
}
|
2024-11-21 10:22:34 -08:00
|
|
|
void HaikuAboutWindow::MessageReceived(BMessage *msg) {
|
2024-11-12 14:53:44 -08:00
|
|
|
if (msg->IsSystem()) return;
|
|
|
|
if (msg->what == CMD_LOAD_LICENSE) {
|
|
|
|
auto selection = license_list->ItemAt(msg->GetInt32("index", 0));
|
2024-11-21 10:43:50 -08:00
|
|
|
std::string str = ((HaikuLicenseItem*)selection)->license_text;
|
2024-11-12 14:53:44 -08:00
|
|
|
|
|
|
|
license_text->SetText(str.c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|