1 /* 2 * Copyright 2016-2017 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@warpmail.net> 8 */ 9 #ifndef _SOFTWARE_UPDATER_WINDOW_H 10 #define _SOFTWARE_UPDATER_WINDOW_H 11 12 13 #include <Button.h> 14 #include <CheckBox.h> 15 #include <GroupView.h> 16 #include <OutlineListView.h> 17 #include <NodeInfo.h> 18 #include <Point.h> 19 #include <ScrollView.h> 20 #include <StatusBar.h> 21 #include <StringView.h> 22 #include <Window.h> 23 24 #include "StripeView.h" 25 26 using namespace BPrivate; 27 28 enum { 29 PACKAGE_UPDATE, 30 PACKAGE_INSTALL, 31 PACKAGE_UNINSTALL 32 }; 33 34 35 class SuperItem : public BListItem { 36 public: 37 SuperItem(const char* label); 38 ~SuperItem(); 39 virtual void DrawItem(BView*, BRect, bool); 40 virtual void Update(BView *owner, const BFont *font); 41 font_height GetFontHeight() { return fFontHeight; }; 42 float GetPackageItemHeight() 43 { return fPackageItemHeight; }; 44 BBitmap* GetIcon() { return fPackageIcon; }; 45 int16 GetIconSize() { return fIconSize; }; 46 void SetDetailLevel(bool showMoreDetails); 47 bool GetDetailLevel() { return fShowMoreDetails; }; 48 void SetItemCount(int32 count) 49 { fItemCount = count; }; 50 51 private: 52 void _SetHeights(); 53 void _GetPackageIcon(); 54 55 BString fLabel; 56 BFont fRegularFont; 57 BFont fBoldFont; 58 bool fShowMoreDetails; 59 font_height fFontHeight; 60 float fPackageItemHeight; 61 BBitmap* fPackageIcon; 62 int16 fIconSize; 63 int32 fItemCount; 64 }; 65 66 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 SetItemHeight(const BFont* font); 79 int NameCompare(PackageItem* item); 80 const char* FileName() { return fFileName.String(); }; 81 void SetDownloadProgress(float percent); 82 void ShowProgressBar() { fDrawBarFlag = true; }; 83 84 private: 85 void _DrawBar(BPoint where, BView* view, 86 icon_size which); 87 88 BString fName; 89 BString fSimpleVersion; 90 BString fDetailedVersion; 91 BString fRepository; 92 BString fSummary; 93 BFont fRegularFont; 94 BFont fSmallFont; 95 font_height fSmallFontHeight; 96 float fSmallTotalHeight; 97 float fLabelOffset; 98 SuperItem* fSuperItem; 99 BString fFileName; 100 float fDownloadProgress; 101 bool fDrawBarFlag; 102 }; 103 104 105 class PackageListView : public BOutlineListView { 106 public: 107 PackageListView(); 108 virtual void FrameResized(float newWidth, float newHeight); 109 void AddPackage(uint32 install_type, 110 const char* name, 111 const char* cur_ver, 112 const char* new_ver, 113 const char* summary, 114 const char* repository, 115 const char* file_name); 116 void UpdatePackageProgress(const char* packageName, 117 float percent); 118 void SortItems(); 119 float ItemHeight(); 120 void SetMoreDetails(bool showMore); 121 122 private: 123 void _SetItemHeights(); 124 125 SuperItem* fSuperUpdateItem; 126 SuperItem* fSuperInstallItem; 127 SuperItem* fSuperUninstallItem; 128 bool fShowMoreDetails; 129 PackageItem* fLastProgressItem; 130 int16 fLastProgressValue; 131 }; 132 133 134 class SoftwareUpdaterWindow : public BWindow { 135 public: 136 SoftwareUpdaterWindow(); 137 void MessageReceived(BMessage* message); 138 bool ConfirmUpdates(); 139 void UpdatesApplying(const char* header, 140 const char* detail); 141 bool UserCancelRequested(); 142 void AddPackageInfo(uint32 install_type, 143 const char* package_name, 144 const char* cur_ver, 145 const char* new_ver, 146 const char* summary, 147 const char* repository, 148 const char* file_name); 149 void ShowWarningAlert(const char* text); 150 BBitmap GetIcon(int32 iconSize); 151 BBitmap GetNotificationIcon(); 152 BRect GetDefaultRect() { return fDefaultRect; }; 153 BPoint GetLocation() { return Frame().LeftTop(); }; 154 BLayoutItem* layout_item_for(BView* view); 155 void FinalUpdate(const char* header, 156 const char* detail); 157 158 private: 159 uint32 _WaitForButtonClick(); 160 void _SetState(uint32 state); 161 uint32 _GetState(); 162 163 BRect fDefaultRect; 164 StripeView* fStripeView; 165 BStringView* fHeaderView; 166 BStringView* fDetailView; 167 BButton* fUpdateButton; 168 BButton* fCancelButton; 169 BStatusBar* fStatusBar; 170 PackageListView* fListView; 171 BScrollView* fScrollView; 172 BCheckBox* fDetailsCheckbox; 173 BLayoutItem* fDetailsLayoutItem; 174 BLayoutItem* fPackagesLayoutItem; 175 BLayoutItem* fProgressLayoutItem; 176 BLayoutItem* fUpdateButtonLayoutItem; 177 BLayoutItem* fDetailsCheckboxLayoutItem; 178 179 uint32 fCurrentState; 180 sem_id fWaitingSem; 181 bool fWaitingForButton; 182 uint32 fButtonResult; 183 bool fUpdateConfirmed; 184 bool fUserCancelRequested; 185 BInvoker fCancelAlertResponse; 186 int32 fWarningAlertCount; 187 BInvoker fWarningAlertDismissed; 188 189 }; 190 191 192 int SortPackageItems(const BListItem* item1, const BListItem* item2); 193 194 195 #endif // _SOFTWARE_UPDATER_WINDOW_H 196