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