-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAboutWindow.cpp
More file actions
342 lines (292 loc) · 9.13 KB
/
Copy pathAboutWindow.cpp
File metadata and controls
342 lines (292 loc) · 9.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* AboutWindow.cpp - About dialog for EmailViews
* Distributed under the terms of the MIT License.
*/
#include "AboutWindow.h"
#include "AppInfo.h"
#include <AppFileInfo.h>
#include <Application.h>
#include <Bitmap.h>
#include <Button.h>
#include <Catalog.h>
#include <Directory.h>
#include <File.h>
#include <FindDirectory.h>
#include <Font.h>
#include <GroupView.h>
#include <LayoutBuilder.h>
#include <Message.h>
#include <Path.h>
#include <Roster.h>
#include <ScrollView.h>
#include <String.h>
#include <StringView.h>
#include <TextView.h>
#include <View.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "AboutWindow"
static const char* kAppDescription =
B_TRANSLATE("EmailViews is a fast, lightweight email viewer for Haiku that uses live "
"queries to organize and explore your emails effortlessly.");
static const char* kAppAuthors =
B_TRANSLATE("Created with the assistance of AI tools.\n"
"Maintained by Jorge Mare.");
// Credits section — headers are translated separately so they can be
// both inserted into the text and used as FindFirst() keys for bold styling.
static const char* kCreditsHeader =
B_TRANSLATE("Credits:");
static const char* kCreditsBody =
B_TRANSLATE("Haiku Mail application by the Haiku Project.\n"
"Icons from Haiku and Zumi icon sets.");
static const char* kInspirationHeader =
B_TRANSLATE("Sources of inspiration:");
static const char* kInspirationBody =
B_TRANSLATE("Beam by Oliver Tappe (attribute search UI, drag-and-drop handling, "
"attachment caching).\n"
"QuickLaunch by Humdinger (Deskbar replicant integration).\n"
"Tracker by the Haiku Project.");
static const char* kThanksHeader =
B_TRANSLATE("Special thanks:");
static const char* kThanksBody =
B_TRANSLATE("Humdinger, for ideas, testing, bug reports, and code contributions.");
// Helper function to get version string from app resources
static BString
GetVersionString()
{
BString versionStr;
// Find the EmailViews binary. When the About dialog is opened from the
// Deskbar replicant, be_app points to Deskbar, not EmailViews. Use the
// app roster to locate our binary by signature instead.
entry_ref appRef;
bool found = false;
if (be_roster->FindApp("application/x-vnd.EmailViews", &appRef) == B_OK)
found = true;
if (found) {
BFile appFile(&appRef, B_READ_ONLY);
if (appFile.InitCheck() == B_OK) {
BAppFileInfo appFileInfo(&appFile);
if (appFileInfo.InitCheck() == B_OK) {
version_info versionInfo;
if (appFileInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK) {
// Use short_info from rdef (e.g., "EmailViews - 1.0")
// Extract just the version part after the dash
BString shortInfo = versionInfo.short_info;
int32 dashPos = shortInfo.FindFirst(" - ");
if (dashPos >= 0) {
shortInfo.Remove(0, dashPos + 3);
versionStr = shortInfo;
} else {
versionStr = versionInfo.short_info;
}
}
}
}
}
// Fallback if we couldn't read from resources
if (versionStr.IsEmpty())
versionStr = "1.0";
// Prepend "Version " and append build timestamp
BString result;
result << "Version " << versionStr << " (" << BUILD_TIMESTAMP << ")";
return result;
}
// Helper view for displaying the application icon
class IconView : public BView {
public:
explicit IconView(BBitmap* icon)
: BView("icon", B_WILL_DRAW),
fIcon(icon)
{
SetExplicitMinSize(BSize(64, 64));
SetExplicitMaxSize(BSize(64, 64));
}
virtual void Draw(BRect updateRect)
{
SetHighUIColor(B_PANEL_BACKGROUND_COLOR);
FillRect(Bounds());
if (fIcon) {
SetDrawingMode(B_OP_ALPHA);
DrawBitmap(fIcon, BPoint(0, 0));
}
}
private:
BBitmap* fIcon; // Not owned, AboutWindow owns it
};
AboutWindow::AboutWindow(BBitmap* icon)
: BWindow(BRect(0, 0, 480, 320), "About",
B_MODAL_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,
B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS |
B_CLOSE_ON_ESCAPE),
fIcon(icon)
{
// Icon view (64x64)
IconView* iconView = new IconView(fIcon);
// App name in large bold font (2x normal size)
BStringView* nameView = new BStringView("name", kAppName);
BFont boldFont(be_bold_font);
boldFont.SetSize(boldFont.Size() * 2.0);
nameView->SetFont(&boldFont);
nameView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
// Version string (read from app resources)
BString versionStr = GetVersionString();
BStringView* versionView = new BStringView("version", versionStr.String());
versionView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
// Description text in a scrollable view
fTextView = new BTextView("description");
fTextView->SetViewUIColor(B_LIST_BACKGROUND_COLOR);
fTextView->SetLowUIColor(B_LIST_BACKGROUND_COLOR);
fTextView->SetHighUIColor(B_LIST_ITEM_TEXT_COLOR);
fTextView->MakeEditable(false);
fTextView->MakeSelectable(false);
fTextView->SetStylable(true);
fTextView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
BString descText;
descText << kAppDescription << "\n\n"
<< kAppAuthors << "\n\n"
<< kCreditsHeader << "\n" << kCreditsBody << "\n\n"
<< kInspirationHeader << "\n" << kInspirationBody << "\n\n"
<< kThanksHeader << "\n" << kThanksBody << "\n";
fTextView->SetText(descText.String());
// Apply text color to all text
rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
fTextView->SetFontAndColor(0, descText.Length(), NULL, B_FONT_ALL, &textColor);
// Apply bold to section headers using the same translated strings
BFont sectionFont(be_bold_font);
int32 creditsPos = descText.FindFirst(kCreditsHeader);
if (creditsPos >= 0) {
fTextView->SetFontAndColor(creditsPos,
creditsPos + strlen(kCreditsHeader),
§ionFont, B_FONT_ALL, &textColor);
}
int32 sourcesPos = descText.FindFirst(kInspirationHeader);
if (sourcesPos >= 0) {
fTextView->SetFontAndColor(sourcesPos,
sourcesPos + strlen(kInspirationHeader),
§ionFont, B_FONT_ALL, &textColor);
}
int32 thanksPos = descText.FindFirst(kThanksHeader);
if (thanksPos >= 0) {
fTextView->SetFontAndColor(thanksPos,
thanksPos + strlen(kThanksHeader),
§ionFont, B_FONT_ALL, &textColor);
}
BScrollView* scrollView = new BScrollView("scroll", fTextView,
B_WILL_DRAW | B_FRAME_EVENTS, false, true, B_PLAIN_BORDER);
scrollView->SetExplicitMinSize(BSize(350, 150));
scrollView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
// OK button
BButton* okButton = new BButton("ok", B_TRANSLATE("OK"), new BMessage(MSG_OK));
okButton->MakeDefault(true);
// Layout: icon on left, everything else in right column
// Create left column (icon)
BGroupView* leftColumn = new BGroupView(B_VERTICAL);
BLayoutBuilder::Group<>(leftColumn)
.Add(iconView)
.AddGlue();
// Create right column (content)
BGroupView* rightColumn = new BGroupView(B_VERTICAL, B_USE_SMALL_SPACING);
rightColumn->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED));
BLayoutBuilder::Group<>(rightColumn)
.Add(nameView)
.Add(versionView)
.AddStrut(B_USE_SMALL_SPACING)
.Add(scrollView, 1.0f)
.AddGroup(B_HORIZONTAL)
.AddGlue()
.Add(okButton)
.End();
// Main horizontal layout with weights
BLayoutBuilder::Group<>(this, B_HORIZONTAL, B_USE_DEFAULT_SPACING)
.SetInsets(B_USE_WINDOW_INSETS)
.Add(leftColumn, 0.0f)
.Add(rightColumn, 1.0f);
// Load saved frame or center on screen
_LoadFrame();
}
AboutWindow::~AboutWindow()
{
delete fIcon;
}
void
AboutWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_OK:
PostMessage(B_QUIT_REQUESTED);
break;
case B_COLORS_UPDATED:
{
// Update text color when system colors change
if (fTextView != NULL) {
rgb_color textColor = ui_color(B_LIST_ITEM_TEXT_COLOR);
int32 textLength = fTextView->TextLength();
if (textLength > 0) {
fTextView->SetFontAndColor(0, textLength, NULL, B_FONT_ALL, &textColor);
}
fTextView->Invalidate();
}
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}
bool
AboutWindow::QuitRequested()
{
_SaveFrame();
return true;
}
void
AboutWindow::_SaveFrame()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return;
path.Append("EmailViews");
create_directory(path.Path(), 0755);
path.Append("emailviews_settings");
// Load existing settings to preserve other data
BMessage settings;
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() == B_OK) {
settings.Unflatten(&file);
}
file.Unset();
// Update about window frame
settings.RemoveName("about_window_frame");
settings.AddRect("about_window_frame", Frame());
// Save back
file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
if (file.InitCheck() == B_OK) {
settings.Flatten(&file);
}
}
void
AboutWindow::_LoadFrame()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) {
CenterOnScreen();
return;
}
path.Append("EmailViews/emailviews_settings");
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() != B_OK) {
CenterOnScreen();
return;
}
BMessage settings;
if (settings.Unflatten(&file) != B_OK) {
CenterOnScreen();
return;
}
BRect frame;
if (settings.FindRect("about_window_frame", &frame) == B_OK) {
MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height());
} else {
CenterOnScreen();
}
}