xref: /haiku/src/apps/softwareupdater/SoftwareUpdaterWindow.h (revision 66cb2efaa8ea36030bb48a16ae664d975bb06e27)
1 /*
2  * Copyright 2016-2019 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  *		Brian Hill <supernova@tycho.email>
8  *		Jacob Secunda
9  */
10 #ifndef _SOFTWARE_UPDATER_WINDOW_H
11 #define _SOFTWARE_UPDATER_WINDOW_H
12 
13 
14 #include <Button.h>
15 #include <CheckBox.h>
16 #include <GroupView.h>
17 #include <MessageRunner.h>
18 #include <NodeInfo.h>
19 #include <OutlineListView.h>
20 #include <Path.h>
21 #include <Point.h>
22 #include <ScrollView.h>
23 #include <StatusBar.h>
24 #include <StringView.h>
25 #include <Window.h>
26 
27 #include "StripeView.h"
28 
29 using namespace BPrivate;
30 
31 enum {
32 	PACKAGE_UPDATE,
33 	PACKAGE_INSTALL,
34 	PACKAGE_UNINSTALL
35 };
36 
37 
38 class SuperItem : public BListItem {
39 public:
40 								SuperItem(const char* label);
41 								~SuperItem();
42 	virtual void				DrawItem(BView*, BRect, bool);
43 	float						GetPackageItemHeight();
44 	float						GetPackageItemHeight(bool showMoreDetails);
45 	BBitmap*					GetIcon(bool showMoreDetails);
46 	float						GetIconSize(bool showMoreDetails);
47 	void						SetDetailLevel(bool showMoreDetails);
GetDetailLevel()48 	bool						GetDetailLevel() { return fShowMoreDetails; };
49 	void						SetItemCount(int32 count);
50 	float						ZoomWidth(BView *owner);
51 
52 private:
53 			BBitmap*			_GetPackageIcon(float listItemHeight);
54 
55 			BString				fLabel;
56 			BString				fItemText;
57 			BFont				fRegularFont;
58 			BFont				fBoldFont;
59 			bool				fShowMoreDetails;
60 			font_height			fBoldFontHeight;
61 			float				fPackageItemLineHeight;
62 			BBitmap*			fPackageLessIcon;
63 			BBitmap*			fPackageMoreIcon;
64 			int32				fItemCount;
65 };
66 
67 
68 class PackageItem : public BListItem {
69 public:
70 								PackageItem(const char* name,
71 									const char* simple_version,
72 									const char* detailed_version,
73 									const char* repository,
74 									const char* summary,
75 									const char* file_name,
76 									SuperItem* super);
77 	virtual void				DrawItem(BView*, BRect, bool);
78 	virtual void				Update(BView *owner, const BFont *font);
79 	void						CalculateZoomWidths(BView *owner);
80 	int							NameCompare(PackageItem* item);
FileName()81 	const char*					FileName() { return fFileName.String(); };
82 	void						SetDownloadProgress(float percent);
ShowProgressBar()83 	void						ShowProgressBar() { fDrawBarFlag = true; };
MoreDetailsWidth()84 	float						MoreDetailsWidth()
85 									{ return fMoreDetailsWidth; };
LessDetailsWidth()86 	float						LessDetailsWidth()
87 									{ return fLessDetailsWidth; };
88 
89 private:
90 			void				_DrawBar(BPoint where, BView* view,
91 									icon_size which);
92 
93 			BString				fName;
94 			BString				fSimpleVersion;
95 			BString				fDetailedVersion;
96 			BString				fRepository;
97 			BString				fSummary;
98 			BFont				fSmallFont;
99 			font_height			fSmallFontHeight;
100 			float				fSmallTotalHeight;
101 			float				fLabelOffset;
102 			SuperItem*			fSuperItem;
103 			BString				fFileName;
104 			float				fDownloadProgress;
105 			bool				fDrawBarFlag;
106 			float				fMoreDetailsWidth;
107 			float				fLessDetailsWidth;
108 };
109 
110 
111 class PackageListView : public BOutlineListView {
112 public:
113 								PackageListView();
114 	virtual	void				FrameResized(float newWidth, float newHeight);
115 			void				ExpandOrCollapse(BListItem *superItem,
116 									bool expand);
117 			void				AddPackage(uint32 install_type,
118 									const char* name,
119 									const char* cur_ver,
120 									const char* new_ver,
121 									const char* summary,
122 									const char* repository,
123 									const char* file_name);
124 			void				UpdatePackageProgress(const char* packageName,
125 									float percent);
126 			void				SortItems();
127 			float				ItemHeight();
128 			void				SetMoreDetails(bool showMore);
129 			BPoint				ZoomPoint();
130 
131 private:
132 			void				_SetItemHeights();
133 
134 			SuperItem*			fSuperUpdateItem;
135 			SuperItem*			fSuperInstallItem;
136 			SuperItem*			fSuperUninstallItem;
137 			bool				fShowMoreDetails;
138 			PackageItem*		fLastProgressItem;
139 			int16				fLastProgressValue;
140 };
141 
142 
143 class SoftwareUpdaterWindow : public BWindow {
144 public:
145 								SoftwareUpdaterWindow();
146 			bool				QuitRequested();
147 			void				FrameMoved(BPoint newPosition);
148 			void				FrameResized(float newWidth, float newHeight);
149 			void				Zoom(BPoint origin, float width, float height);
150 			void				MessageReceived(BMessage* message);
151 			bool				ConfirmUpdates();
152 			void				UpdatesApplying(const char* header,
153 									const char* detail);
154 			bool				UserCancelRequested();
155 			void				AddPackageInfo(uint32 install_type,
156 									const char* package_name,
157 									const char* cur_ver,
158 									const char* new_ver,
159 									const char* summary,
160 									const char* repository,
161 									const char* file_name);
162 			void				ShowWarningAlert(const char* text);
163 			BBitmap				GetIcon(int32 iconSize);
GetDefaultRect()164 			BRect				GetDefaultRect() { return fDefaultRect; };
GetLocation()165 			BPoint				GetLocation() { return Frame().LeftTop(); };
166 			BLayoutItem*		layout_item_for(BView* view);
167 			void				FinalUpdate(const char* header,
168 									const char* detail);
169 
170 private:
171 			uint32				_WaitForButtonClick();
172 			void				_SetState(uint32 state);
173 			uint32				_GetState();
174 			status_t			_WriteSettings();
175 			status_t			_ReadSettings(BMessage& settings);
176 
177 			BRect				fDefaultRect;
178 			BStripeView*		fStripeView;
179 			BStringView*		fHeaderView;
180 			BStringView*		fDetailView;
181 			BButton*			fUpdateButton;
182 			BButton*			fCancelButton;
183 			BButton*			fRebootButton;
184 			BStatusBar*			fStatusBar;
185 			PackageListView*	fListView;
186 			BScrollView*		fScrollView;
187 			BCheckBox*			fDetailsCheckbox;
188 			BLayoutItem*		fDetailsLayoutItem;
189 			BLayoutItem*		fPackagesLayoutItem;
190 			BLayoutItem*		fProgressLayoutItem;
191 			BLayoutItem*		fCancelButtonLayoutItem;
192 			BLayoutItem*		fUpdateButtonLayoutItem;
193 			BLayoutItem*		fRebootButtonLayoutItem;
194 			BLayoutItem*		fDetailsCheckboxLayoutItem;
195 
196 			uint32				fCurrentState;
197 			sem_id				fWaitingSem;
198 			bool				fWaitingForButton;
199 			uint32				fButtonResult;
200 			bool				fUpdateConfirmed;
201 			bool				fUserCancelRequested;
202 			BInvoker			fCancelAlertResponse;
203 			int32				fWarningAlertCount;
204 			BInvoker			fWarningAlertDismissed;
205 			BPath				fSettingsPath;
206 			status_t			fSettingsReadStatus;
207 			BMessage			fInitialSettings;
208 			bool				fSaveFrameChanges;
209 			BMessageRunner*		fMessageRunner;
210 			BMessage			fFrameChangeMessage;
211 			float				fZoomHeightBaseline;
212 			float				fZoomWidthBaseline;
213 };
214 
215 
216 int SortPackageItems(const BListItem* item1, const BListItem* item2);
217 
218 
219 #endif // _SOFTWARE_UPDATER_WINDOW_H
220