xref: /haiku/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp (revision 7bdeef54a24d3417300f251af891df962b638b9b)
1 /*
2  * Copyright 2016 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT license
4  *
5  * Authors:
6  *		Alexander von Gluck IV <kallisti5@unixzen.com>
7  */
8 
9 
10 #include "SoftwareUpdaterWindow.h"
11 
12 #include <stdio.h>
13 #include <AppDefs.h>
14 #include <Application.h>
15 #include <Button.h>
16 #include <GroupLayout.h>
17 #include <GroupLayoutBuilder.h>
18 #include <NodeInfo.h>
19 #include <LayoutBuilder.h>
20 #include <Message.h>
21 #include <Resources.h>
22 #include <SeparatorView.h>
23 #include <String.h>
24 #include <StringView.h>
25 
26 
27 #undef B_TRANSLATION_CONTEXT
28 #define B_TRANSLATION_CONTEXT "SoftwareUpdater"
29 
30 
31 const uint32 UPDATE_MESSAGE = 'iUPD';
32 const uint32 EXIT_MESSAGE = 'iEXT';
33 
34 
35 SoftwareUpdaterWindow::SoftwareUpdaterWindow()
36 	:
37 	BWindow(BRect(0, 0, 0, 300), "Software Update",
38 		B_TITLED_WINDOW, B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE),
39 	fStripeView(NULL)
40 {
41 	uint32 updatesAvailable = 45;
42 
43 	BBitmap* icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
44 	team_info teamInfo;
45 	get_team_info(B_CURRENT_TEAM, &teamInfo);
46 	app_info appInfo;
47 	be_roster->GetRunningAppInfo(teamInfo.team, &appInfo);
48 	BNodeInfo::GetTrackerIcon(&appInfo.ref, icon, B_LARGE_ICON);
49 
50 	fStripeView = new StripeView(icon);
51 
52 	BButton* updateButton = new BButton("Update now",
53 		new BMessage(UPDATE_MESSAGE));
54 
55 	BButton* exitButton = new BButton("Cancel",
56 		new BMessage(EXIT_MESSAGE));
57 
58 	// Form text based on updates available
59 	BStringView* headerView;
60 	BStringView* detailView;
61 
62 	if (updatesAvailable > 0) {
63 		headerView = new BStringView("header",
64 			"Software updates are available.", B_WILL_DRAW);
65 		char detailString[1024];
66 		snprintf(detailString, 1024, "There are %" B_PRIu32 " updates available"
67 			" for your system.", updatesAvailable);
68 		detailView = new BStringView("detail", detailString, B_WILL_DRAW);
69 		updateButton->MakeDefault(true);
70 	} else {
71 		headerView = new BStringView("header",
72 			"Your system is up to date.", B_WILL_DRAW);
73 		detailView = new BStringView("detail",
74 			"No updates are available at this time.",
75 			B_WILL_DRAW);
76 		updateButton->Hide();
77 		exitButton->SetLabel("Quit");
78 		exitButton->MakeDefault(true);
79 	}
80 
81 	BFont font;
82 	headerView->GetFont(&font);
83 	font.SetFace(B_BOLD_FACE);
84 	font.SetSize(font.Size() * 1.5);
85 	headerView->SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_SIZE
86 		| B_FONT_FLAGS);
87 
88 	BLayoutBuilder::Group<>(this, B_HORIZONTAL, 0)
89 		.Add(fStripeView)
90 		.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
91 			.SetInsets(0, B_USE_DEFAULT_SPACING,
92 				B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
93 			.Add(headerView)
94 			.Add(detailView)
95 			.AddStrut(B_USE_DEFAULT_SPACING)
96 			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING)
97 				.AddGlue()
98 				.Add(exitButton)
99 				.Add(updateButton)
100 			.End()
101 		.End()
102 		.AddGlue()
103 		//.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
104 	;
105 	CenterOnScreen();
106 	Show();
107 }
108 
109 
110 SoftwareUpdaterWindow::~SoftwareUpdaterWindow()
111 {
112 }
113 
114 
115 bool
116 SoftwareUpdaterWindow::QuitRequested()
117 {
118 	be_app->PostMessage(B_QUIT_REQUESTED);
119 	return true;
120 }
121