diff --git a/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp b/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp index 701ece7e0a5..c8c5bd285b2 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp +++ b/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp @@ -43,14 +43,16 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow() fCurrentState(STATE_HEAD), fWaitingSem(-1), fWaitingForButton(false), - fUserCancelRequested(false) + fUserCancelRequested(false), + fWarningAlertCount(0) { - fIcon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); + int32 iconSize = int(be_plain_font->Size() * 32.0 / 12.0); + fIcon = new BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32); team_info teamInfo; get_team_info(B_CURRENT_TEAM, &teamInfo); app_info appInfo; be_roster->GetRunningAppInfo(teamInfo.team, &appInfo); - BNodeInfo::GetTrackerIcon(&appInfo.ref, fIcon, B_LARGE_ICON); + BNodeInfo::GetTrackerIcon(&appInfo.ref, fIcon, icon_size(iconSize)); fStripeView = new StripeView(fIcon); @@ -127,6 +129,8 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow() fCancelAlertResponse.SetMessage(new BMessage(kMsgCancelResponse)); fCancelAlertResponse.SetTarget(this); + fWarningAlertDismissed.SetMessage(new BMessage(kMsgWarningDismissed)); + fWarningAlertDismissed.SetTarget(this); } @@ -236,6 +240,10 @@ SoftwareUpdaterWindow::MessageReceived(BMessage* message) break; } + case kMsgWarningDismissed: + fWarningAlertCount--; + break; + default: BWindow::MessageReceived(message); } @@ -293,6 +301,19 @@ SoftwareUpdaterWindow::AddPackageInfo(uint32 install_type, } +void +SoftwareUpdaterWindow::ShowWarningAlert(const char* text) +{ + BAlert* alert = new BAlert("warning", text, B_TRANSLATE("OK"), NULL, NULL, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->Go(&fWarningAlertDismissed); + alert->CenterIn(Frame()); + // Offset multiple alerts + alert->MoveBy(fWarningAlertCount * 15, fWarningAlertCount * 15); + fWarningAlertCount++; +} + + BLayoutItem* SoftwareUpdaterWindow::layout_item_for(BView* view) { @@ -342,9 +363,10 @@ SoftwareUpdaterWindow::_SetState(uint32 state) if (fCurrentState == STATE_GET_CONFIRMATION) { fPackagesLayoutItem->SetVisible(true); // Re-enable resizing - SetSizeLimits(fDefaultRect.Width(), 9999, - fDefaultRect.Height() + fListView->MinSize().Height() + 30, 9999); - ResizeTo(Bounds().Width(), 400); + float defaultWidth = fDefaultRect.Width(); + SetSizeLimits(defaultWidth, 9999, + fDefaultRect.Height() + 4 * fListView->ItemHeight(), 9999); + ResizeTo(defaultWidth, .75 * defaultWidth); } // Progress bar and string view @@ -455,11 +477,19 @@ PackageItem::PackageItem(const char* name, const char* version, fName(name), fVersion(version), fSummary(summary), - fTooltip(tooltip), + fToolTip(NULL), fSuperItem(super) { fLabelOffset = be_control_look->DefaultLabelSpacing(); -// SetToolTip(fTooltip); + if (tooltip != NULL) + fToolTip = new BTextToolTip(tooltip); +} + + +PackageItem::~PackageItem() +{ + if (fToolTip != NULL) + fToolTip->ReleaseReference(); } @@ -578,6 +608,21 @@ PackageListView::FrameResized(float newWidth, float newHeight) } +bool +PackageListView::GetToolTipAt(BPoint point, BToolTip** _tip) +{ + BListItem* item = ItemAt(IndexOf(point)); + if (item == NULL) + return false; + PackageItem* pItem = dynamic_cast(item); + if (pItem != NULL) { + *_tip = pItem->ToolTip(); + return true; + } + return false; +} + + void PackageListView::AddPackage(uint32 install_type, const char* name, const char* cur_ver, const char* new_ver, const char* summary, @@ -585,21 +630,23 @@ PackageListView::AddPackage(uint32 install_type, const char* name, { SuperItem* super; BString version; - BString tooltip; + BString tooltip(B_TRANSLATE_COMMENT("Package:", "Tooltip text")); + tooltip.Append(" ").Append(name).Append("\n") + .Append(B_TRANSLATE_COMMENT("Repository:", "Tooltip text")) + .Append(" ").Append(repository).Append("\n"); switch (install_type) { case PACKAGE_UPDATE: { if (fSuperUpdateItem == NULL) { - fSuperUpdateItem = new SuperItem( - B_TRANSLATE("Packages to be updated")); + fSuperUpdateItem = new SuperItem(B_TRANSLATE_COMMENT( + "Packages to be updated", "List super item label")); AddItem(fSuperUpdateItem); } super = fSuperUpdateItem; version.SetTo(new_ver); - tooltip.SetTo(B_TRANSLATE("Repository:")); - tooltip.Append(" ").Append(repository) - .Append("\n").Append(B_TRANSLATE("Update version")) + tooltip.Append(B_TRANSLATE_COMMENT("Updating version", + "Tooltip text")) .Append(" ").Append(cur_ver) .Append(" ").Append(B_TRANSLATE("to")) .Append(" ").Append(new_ver); @@ -609,16 +656,15 @@ PackageListView::AddPackage(uint32 install_type, const char* name, case PACKAGE_INSTALL: { if (fSuperInstallItem == NULL) { - fSuperInstallItem = new SuperItem( - B_TRANSLATE("New packages to be installed")); + fSuperInstallItem = new SuperItem(B_TRANSLATE_COMMENT( + "New packages to be installed", "List super item label")); AddItem(fSuperInstallItem); } super = fSuperInstallItem; version.SetTo(new_ver); - tooltip.SetTo(B_TRANSLATE("Repository:")); - tooltip.Append(" ").Append(repository) - .Append("\n").Append(B_TRANSLATE("Install version")) + tooltip.Append(B_TRANSLATE_COMMENT("Installing version", + "Tooltip text")) .Append(" ").Append(new_ver); break; } @@ -626,16 +672,15 @@ PackageListView::AddPackage(uint32 install_type, const char* name, case PACKAGE_UNINSTALL: { if (fSuperUninstallItem == NULL) { - fSuperUninstallItem = new SuperItem( - B_TRANSLATE("Packages to be uninstalled")); + fSuperUninstallItem = new SuperItem(B_TRANSLATE_COMMENT( + "Packages to be uninstalled", "List super item label")); AddItem(fSuperUninstallItem); } super = fSuperUninstallItem; version.SetTo(""); - tooltip.SetTo(B_TRANSLATE("Repository:")); - tooltip.Append(" ").Append(repository) - .Append("\n").Append(B_TRANSLATE("Uninstall version")) + tooltip.Append(B_TRANSLATE_COMMENT("Uninstalling version", + "Tooltip text")) .Append(" ").Append(new_ver); break; } @@ -657,34 +702,18 @@ PackageListView::SortItems() SortItemsUnder(fSuperUpdateItem, true, SortPackageItems); } -/* -BSize -PackageListView::PreferredSize() -{ - return BSize(B_SIZE_UNSET, 200); -}*/ -/* -void -PackageListView::GetPreferredSize(float* _width, float* _height) -{ - // TODO: Something more nice as default? I need to see how this looks - // when there are actually any packages... - if (_width != NULL) - *_width = 400.0; - - if (_height != NULL) - *_height = 200.0; -}*/ - -/* -BSize -PackageListView::MaxSize() +float +PackageListView::ItemHeight() { - return BLayoutUtils::ComposeSize(ExplicitMaxSize(), - BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); + if (fSuperUpdateItem != NULL) + return fSuperUpdateItem->GetPackageItemHeight(); + if (fSuperInstallItem != NULL) + return fSuperInstallItem->GetPackageItemHeight(); + if (fSuperUninstallItem != NULL) + return fSuperUninstallItem->GetPackageItemHeight(); + return 0; } -*/ FinalWindow::FinalWindow(BRect rect, BPoint location, const char* header, @@ -698,12 +727,13 @@ FinalWindow::FinalWindow(BRect rect, BPoint location, const char* header, fDetailView(NULL), fCancelButton(NULL) { - fIcon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32); + int32 iconSize = int(be_plain_font->Size() * 32.0 / 12.0); + fIcon = new BBitmap(BRect(0, 0, iconSize - 1, iconSize - 1), 0, B_RGBA32); team_info teamInfo; get_team_info(B_CURRENT_TEAM, &teamInfo); app_info appInfo; be_roster->GetRunningAppInfo(teamInfo.team, &appInfo); - BNodeInfo::GetTrackerIcon(&appInfo.ref, fIcon, B_LARGE_ICON); + BNodeInfo::GetTrackerIcon(&appInfo.ref, fIcon, icon_size(iconSize)); SetSizeLimits(rect.Width(), B_SIZE_UNLIMITED, 0, B_SIZE_UNLIMITED); fStripeView = new StripeView(fIcon); diff --git a/src/apps/softwareupdater/SoftwareUpdaterWindow.h b/src/apps/softwareupdater/SoftwareUpdaterWindow.h index 4c43f240edc..8987fa2347b 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterWindow.h +++ b/src/apps/softwareupdater/SoftwareUpdaterWindow.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "StripeView.h" @@ -62,16 +63,18 @@ class PackageItem : public BListItem { const char* summary, const char* tooltip, SuperItem* super); + ~PackageItem(); virtual void DrawItem(BView*, BRect, bool); virtual void Update(BView *owner, const BFont *font); void SetItemHeight(const BFont* font); int ICompare(PackageItem* item); + BTextToolTip* ToolTip() { return fToolTip; }; private: BString fName; BString fVersion; BString fSummary; - BString fTooltip; + BTextToolTip* fToolTip; BFont fRegularFont; BFont fSmallFont; font_height fSmallFontHeight; @@ -85,9 +88,6 @@ class PackageListView : public BOutlineListView { public: PackageListView(); virtual void FrameResized(float newWidth, float newHeight); -// virtual BSize PreferredSize(); -// virtual void GetPreferredSize(float* _width, float* _height); -// virtual BSize MaxSize(); void AddPackage(uint32 install_type, const char* name, const char* cur_ver, @@ -95,6 +95,10 @@ class PackageListView : public BOutlineListView { const char* summary, const char* repository); void SortItems(); + float ItemHeight(); + +protected: + virtual bool GetToolTipAt(BPoint point, BToolTip** _tip); private: SuperItem* fSuperUpdateItem; @@ -119,6 +123,7 @@ class SoftwareUpdaterWindow : public BWindow { const char* new_ver, const char* summary, const char* repository); + void ShowWarningAlert(const char* text); const BBitmap* GetIcon() { return fIcon; }; BRect GetDefaultRect() { return fDefaultRect; }; BPoint GetLocation() { return Frame().LeftTop(); }; @@ -154,6 +159,8 @@ class SoftwareUpdaterWindow : public BWindow { uint32 fButtonResult; bool fUserCancelRequested; BInvoker fCancelAlertResponse; + int32 fWarningAlertCount; + BInvoker fWarningAlertDismissed; }; diff --git a/src/apps/softwareupdater/StripeView.cpp b/src/apps/softwareupdater/StripeView.cpp index c28a4e82c2c..de0533e8ff5 100644 --- a/src/apps/softwareupdater/StripeView.cpp +++ b/src/apps/softwareupdater/StripeView.cpp @@ -6,33 +6,28 @@ * Ryan Leavengood * John Scipione * Joseph Groover + * Brian Hill */ #include "StripeView.h" - -static const float kStripeWidth = 30.0; +#include StripeView::StripeView(BBitmap* icon) : BView("StripeView", B_WILL_DRAW), - fIcon(icon) + fIcon(icon), + fWidth(0.0), + fStripeWidth(0.0) { SetViewUIColor(B_PANEL_BACKGROUND_COLOR); - float width = 0.0f; - if (icon != NULL) - width += icon->Bounds().Width() + 32.0f; - - SetExplicitSize(BSize(width, B_SIZE_UNSET)); - SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); -} - - -StripeView::~StripeView() -{ + if (icon != NULL) { + fStripeWidth = icon->Bounds().Width(); + fWidth = 2 * fStripeWidth + 2.0f; + } } @@ -46,28 +41,37 @@ StripeView::Draw(BRect updateRect) FillRect(updateRect); BRect stripeRect = Bounds(); - stripeRect.right = kStripeWidth; + stripeRect.right = fStripeWidth; SetHighColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); FillRect(stripeRect); SetDrawingMode(B_OP_ALPHA); SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - DrawBitmapAsync(fIcon, BPoint(15.0f, 10.0f)); + DrawBitmapAsync(fIcon, BPoint(fStripeWidth / 2.0f, 10.0f)); +} + + +BSize +StripeView::PreferredSize() +{ + return BSize(fWidth, B_SIZE_UNSET); } void -StripeView::SetIcon(BBitmap* icon) +StripeView::GetPreferredSize(float* _width, float* _height) { - if (fIcon != NULL) - delete fIcon; + if (_width != NULL) + *_width = fWidth; - fIcon = icon; + if (_height != NULL) + *_height = fStripeWidth + 20.0f; +} - float width = 0.0f; - if (icon != NULL) - width += icon->Bounds().Width() + 32.0f; - SetExplicitSize(BSize(width, B_SIZE_UNSET)); - SetExplicitPreferredSize(BSize(width, B_SIZE_UNLIMITED)); +BSize +StripeView::MaxSize() +{ + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), + BSize(fWidth, B_SIZE_UNLIMITED)); } diff --git a/src/apps/softwareupdater/StripeView.h b/src/apps/softwareupdater/StripeView.h index c03c3eeafa5..8eaa38a1835 100644 --- a/src/apps/softwareupdater/StripeView.h +++ b/src/apps/softwareupdater/StripeView.h @@ -6,6 +6,7 @@ * Ryan Leavengood * John Scipione * Joseph Groover + * Brian Hill */ #ifndef _STRIPE_VIEW_H #define _STRIPE_VIEW_H @@ -18,15 +19,16 @@ class StripeView : public BView { public: StripeView(BBitmap* icon); - ~StripeView(); virtual void Draw(BRect updateRect); - - BBitmap* Icon() const { return fIcon; }; - void SetIcon(BBitmap* icon); + virtual BSize PreferredSize(); + virtual void GetPreferredSize(float* _width, float* _height); + virtual BSize MaxSize(); private: BBitmap* fIcon; + float fWidth; + float fStripeWidth; }; diff --git a/src/apps/softwareupdater/UpdateAction.cpp b/src/apps/softwareupdater/UpdateAction.cpp index 54f7165a4be..7668698fb39 100644 --- a/src/apps/softwareupdater/UpdateAction.cpp +++ b/src/apps/softwareupdater/UpdateAction.cpp @@ -9,7 +9,6 @@ #include "UpdateAction.h" -#include #include #include #include @@ -42,11 +41,11 @@ UpdateAction::~UpdateAction() status_t UpdateAction::Perform() { - fUpdateManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES - | BPackageManager::B_ADD_REMOTE_REPOSITORIES - | BPackageManager::B_REFRESH_REPOSITORIES); - try { + fUpdateManager->Init(BPackageManager::B_ADD_INSTALLED_REPOSITORIES + | BPackageManager::B_ADD_REMOTE_REPOSITORIES + | BPackageManager::B_REFRESH_REPOSITORIES); + // These values indicate that all updates should be installed int packageCount = 0; const char* const packages = ""; @@ -55,16 +54,6 @@ UpdateAction::Perform() // fUpdateManager->SetDebugLevel(1); fUpdateManager->Update(&packages, packageCount); } catch (BFatalErrorException ex) { - BString errorString; - errorString.SetToFormat( - "Fatal error occurred while updating packages: " - "%s (%s)\n", ex.Message().String(), - ex.Details().String()); - BAlert* alert(new(std::nothrow) BAlert(B_TRANSLATE("Fatal error"), - errorString, B_TRANSLATE("Close"), NULL, NULL, - B_WIDTH_AS_USUAL, B_STOP_ALERT)); - if (alert != NULL) - alert->Go(); fUpdateManager->FinalUpdate(B_TRANSLATE("Updates did not complete"), ex.Message()); return ex.Error(); diff --git a/src/apps/softwareupdater/UpdateManager.cpp b/src/apps/softwareupdater/UpdateManager.cpp index afbb65aadf1..98c4702d6f1 100644 --- a/src/apps/softwareupdater/UpdateManager.cpp +++ b/src/apps/softwareupdater/UpdateManager.cpp @@ -79,7 +79,6 @@ UpdateManager::JobFailed(BSupportKit::BJob* job) void UpdateManager::JobAborted(BSupportKit::BJob* job) { - //DIE(job->Result(), "aborted"); printf("Job aborted\n"); } @@ -219,15 +218,27 @@ UpdateManager::ConfirmChanges(bool fromMostSpecific) void UpdateManager::Warn(status_t error, const char* format, ...) { + char buffer[256]; va_list args; va_start(args, format); vfprintf(stderr, format, args); + vsnprintf(buffer, 256, format, args); va_end(args); if (error == B_OK) printf("\n"); else printf(": %s\n", strerror(error)); + + if (fStatusWindow != NULL) + fStatusWindow->ShowWarningAlert(buffer); + else { + BString text("SoftwareUpdater:\n"); + text.Append(buffer); + BAlert* alert = new BAlert("warning", text, B_TRANSLATE("OK"), NULL, + NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + alert->Go(NULL); + } } @@ -531,6 +542,9 @@ UpdateManager::_UpdateDownloadProgress(const char* header, void UpdateManager::_FinalUpdate(const char* header, const char* text) { + if (fFinalWindow != NULL) + return; + BNotification notification(B_INFORMATION_NOTIFICATION); notification.SetGroup("SoftwareUpdater"); notification.SetTitle(header); diff --git a/src/apps/softwareupdater/constants.h b/src/apps/softwareupdater/constants.h index 648b5c494af..aa8e751abc8 100644 --- a/src/apps/softwareupdater/constants.h +++ b/src/apps/softwareupdater/constants.h @@ -32,9 +32,7 @@ static const uint32 kMsgProgressUpdate = 'iPRO'; static const uint32 kMsgCancel = 'iCAN'; static const uint32 kMsgCancelResponse = 'iCRE'; static const uint32 kMsgUpdateConfirmed = 'iCON'; -static const uint32 kMsgClose = 'iCLO'; -static const uint32 kMsgShow = 'iSHO'; -static const uint32 kMsgShowInfo = 'iSHI'; +static const uint32 kMsgWarningDismissed = 'iWDI'; static const uint32 kMsgRegister = 'iREG'; static const uint32 kMsgFinalQuit = 'iFIN'; @@ -44,7 +42,6 @@ static const uint32 kMsgFinalQuit = 'iFIN'; #define kKeyPackageName "key_packagename" #define kKeyPackageCount "key_packagecount" #define kKeyPercentage "key_percentage" -#define kKeyFrame "key_frame" #define kKeyMessenger "key_messenger"