/
MainWindow.cpp
231 lines (189 loc) · 4.94 KB
/
MainWindow.cpp
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
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "MainWindow.h"
#include <stdio.h>
#include <Alert.h>
#include <Application.h>
#include <Button.h>
#include <Catalog.h>
#include <LayoutBuilder.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Messenger.h>
#include <ScrollView.h>
#include <TabView.h>
#include "FilterView.h"
#include "PackageInfoView.h"
#include "PackageListView.h"
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "MainWindow"
MainWindow::MainWindow(BRect frame)
:
BWindow(frame, B_TRANSLATE_SYSTEM_NAME("HaikuDepot"),
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS)
{
_InitDummyModel();
BMenuBar* menuBar = new BMenuBar(B_TRANSLATE("Main Menu"));
_BuildMenu(menuBar);
fFilterView = new FilterView(fModel);
fPackageListView = new PackageListView();
fPackageInfoView = new PackageInfoView(&fPackageManager);
fSplitView = new BSplitView(B_VERTICAL, 5.0f);
BLayoutBuilder::Group<>(this, B_VERTICAL, 0.0f)
.Add(menuBar)
.Add(fFilterView)
.AddSplit(fSplitView)
.AddGroup(B_VERTICAL)
.Add(fPackageListView)
.SetInsets(
B_USE_DEFAULT_SPACING, 0.0f,
B_USE_DEFAULT_SPACING, 0.0f)
.End()
.Add(fPackageInfoView)
.End()
;
fSplitView->SetCollapsible(0, false);
fSplitView->SetCollapsible(1, false);
_AdoptModel();
}
MainWindow::~MainWindow()
{
}
bool
MainWindow::QuitRequested()
{
BMessage message(MSG_MAIN_WINDOW_CLOSED);
message.AddRect("window frame", Frame());
be_app->PostMessage(&message);
return true;
}
void
MainWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_SIMPLE_DATA:
case B_REFS_RECEIVED:
break;
case MSG_PACKAGE_SELECTED:
{
int32 index;
if (message->FindInt32("index", &index) == B_OK
&& index >= 0 && index < fVisiblePackages.CountItems()) {
_AdoptPackage(fVisiblePackages.ItemAtFast(index));
} else {
_ClearPackage();
}
break;
}
case MSG_CATEGORY_SELECTED:
{
BString name;
if (message->FindString("name", &name) != B_OK)
name = "";
fModel.SetCategory(name);
_AdoptModel();
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}
void
MainWindow::_BuildMenu(BMenuBar* menuBar)
{
BMenu* menu = new BMenu(B_TRANSLATE("Package"));
menuBar->AddItem(menu);
}
void
MainWindow::_AdoptModel()
{
fVisiblePackages = fModel.CreatePackageList();
fPackageListView->Clear();
for (int32 i = 0; i < fVisiblePackages.CountItems(); i++) {
fPackageListView->AddPackage(fVisiblePackages.ItemAtFast(i));
}
}
void
MainWindow::_AdoptPackage(const PackageInfo& package)
{
fPackageInfoView->SetPackage(package);
}
void
MainWindow::_ClearPackage()
{
fPackageInfoView->Clear();
}
void
MainWindow::_InitDummyModel()
{
// TODO: The Model could be filled from another thread by
// sending messages which contain collected package information.
// The Model could be cached on disk.
DepotInfo depot(B_TRANSLATE("Default"));
PackageInfo wonderbrush(
BitmapRef(new SharedBitmap(601), true),
"WonderBrush",
"2.1.2",
PublisherInfo(
BitmapRef(),
"YellowBites",
"superstippi@gmx.de",
"http://www.yellowbites.com"),
"A vector based graphics editor.",
"WonderBrush is YellowBites' software for doing graphics design "
"on Haiku. It combines many great under-the-hood features with "
"powerful tools and an efficient and intuitive interface.",
"2.1.2 - Initial Haiku release.");
wonderbrush.AddUserRating(
UserRating(UserInfo("humdinger"), 4.5f,
"Awesome!", "en", "2.1.2")
);
wonderbrush.AddUserRating(
UserRating(UserInfo("bonefish"), 5.0f,
"The best!", "en", "2.1.2")
);
wonderbrush.AddScreenshot(
BitmapRef(new SharedBitmap(603), true));
wonderbrush.AddCategory(fModel.CategoryGraphics());
wonderbrush.AddCategory(fModel.CategoryProductivity());
depot.AddPackage(wonderbrush);
PackageInfo paladin(
BitmapRef(new SharedBitmap(602), true),
"Paladin",
"1.2.0",
PublisherInfo(
BitmapRef(),
"DarkWyrm",
"bpmagic@columbus.rr.com",
"http://darkwyrm-haiku.blogspot.com"),
"A C/C++ IDE based on Pe.",
"If you like BeIDE, you'll like Paladin even better. "
"The interface is streamlined, it has some features sorely "
"missing from BeIDE, like running a project in the Terminal, "
"and has a bundled text editor based upon Pe.",
"");
paladin.AddUserRating(
UserRating(UserInfo("stippi"), 3.5f,
"Could be more integrated from the sounds of it.",
"en", "1.2.0")
);
paladin.AddUserRating(
UserRating(UserInfo("mmadia"), 5.0f,
"It rocks! Give a try",
"en", "1.1.0")
);
paladin.AddUserRating(
UserRating(UserInfo("bonefish"), 2.0f,
"It just needs to use my jam-rewrite 'ham' and it will be great.",
"en", "1.1.0")
);
paladin.AddScreenshot(
BitmapRef(new SharedBitmap(604), true));
paladin.AddCategory(fModel.CategoryDevelopment());
depot.AddPackage(paladin);
fModel.AddDepot(depot);
}