diff --git a/src/apps/softwareupdater/Jamfile b/src/apps/softwareupdater/Jamfile index c960256076..45a9b236c5 100644 --- a/src/apps/softwareupdater/Jamfile +++ b/src/apps/softwareupdater/Jamfile @@ -1,6 +1,6 @@ SubDir HAIKU_TOP src apps softwareupdater ; -UsePrivateHeaders interface shared package ; +UsePrivateHeaders app interface shared package ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src servers package ] ; diff --git a/src/apps/softwareupdater/SoftwareUpdater.rdef b/src/apps/softwareupdater/SoftwareUpdater.rdef index 347b87935e..cf145929b9 100644 --- a/src/apps/softwareupdater/SoftwareUpdater.rdef +++ b/src/apps/softwareupdater/SoftwareUpdater.rdef @@ -9,7 +9,7 @@ resource app_version { variety = B_APPV_BETA, internal = 0, short_info = "SoftwareUpdater", - long_info = "Software Updater ©2008-2017 Haiku" + long_info = "Software Updater ©2008-2019 Haiku" }; resource vector_icon { diff --git a/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp b/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp index b4e0448425..46985c096c 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp +++ b/src/apps/softwareupdater/SoftwareUpdaterWindow.cpp @@ -1,10 +1,11 @@ /* - * Copyright 2016-2017 Haiku, Inc. All rights reserved. + * Copyright 2016-2019 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license * * Authors: * Alexander von Gluck IV * Brian Hill + * Jacob Secunda */ @@ -20,6 +21,7 @@ #include #include #include +#include #include #include @@ -60,6 +62,8 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow() fUpdateButton->MakeDefault(true); fCancelButton = new BButton(B_TRANSLATE("Cancel"), new BMessage(kMsgCancel)); + fRebootButton = new BButton(B_TRANSLATE("Reboot"), + new BMessage(kMsgReboot)); fHeaderView = new BStringView("header", B_TRANSLATE("Checking for updates"), B_WILL_DRAW); @@ -104,6 +108,7 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow() .AddGlue() .Add(fCancelButton) .Add(fUpdateButton) + .Add(fRebootButton) .End() .End() .End(); @@ -113,6 +118,7 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow() fPackagesLayoutItem = layout_item_for(fScrollView); fCancelButtonLayoutItem = layout_item_for(fCancelButton); fUpdateButtonLayoutItem = layout_item_for(fUpdateButton); + fRebootButtonLayoutItem = layout_item_for(fRebootButton); fDetailsCheckboxLayoutItem = layout_item_for(fDetailsCheckbox); _SetState(STATE_DISPLAY_STATUS); @@ -307,6 +313,33 @@ SoftwareUpdaterWindow::MessageReceived(BMessage* message) break; } + case kMsgShowReboot: + { + fRebootButtonLayoutItem->SetVisible(true); + fRebootButton->SetLabel(B_TRANSLATE_COMMENT("Reboot", + "Button label")); + fRebootButton->MakeDefault(true); + break; + } + + case kMsgReboot: + { + if (_GetState() != STATE_FINAL_MESSAGE) + break; + + BRoster roster; + BRoster::Private rosterPrivate(roster); + status_t error = rosterPrivate.ShutDown(true, true, false); + if (error != B_OK) { + BAlert* alert = new BAlert("reboot request", B_TRANSLATE( + "For some reason, we could not reboot your computer."), + B_TRANSLATE("Ok"), NULL, NULL, + B_WIDTH_AS_USUAL, B_STOP_ALERT); + alert->Go(); + } + break; + } + case kMsgCancelResponse: { // Verify whether the cancel alert was confirmed @@ -567,6 +600,7 @@ SoftwareUpdaterWindow::_SetState(uint32 state) fPackagesLayoutItem->SetVisible(false); fDetailsCheckboxLayoutItem->SetVisible(false); fCancelButtonLayoutItem->SetVisible(false); + fRebootButtonLayoutItem->SetVisible(false); } fCurrentState = state; @@ -655,7 +689,7 @@ SoftwareUpdaterWindow::_SetState(uint32 state) if (fCurrentState == STATE_FINAL_MESSAGE) { fCancelButtonLayoutItem->SetVisible(true); fCancelButton->SetLabel(B_TRANSLATE_COMMENT("Quit", "Button label")); - fCancelButton->MakeDefault(true); + fCancelButton->MakeDefault(true); } Unlock(); diff --git a/src/apps/softwareupdater/SoftwareUpdaterWindow.h b/src/apps/softwareupdater/SoftwareUpdaterWindow.h index 8de8ddbc54..b8a4b7e31f 100644 --- a/src/apps/softwareupdater/SoftwareUpdaterWindow.h +++ b/src/apps/softwareupdater/SoftwareUpdaterWindow.h @@ -1,10 +1,11 @@ /* - * Copyright 2016-2017 Haiku, Inc. All rights reserved. + * Copyright 2016-2019 Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT license * * Authors: * Alexander von Gluck IV * Brian Hill + * Jacob Secunda */ #ifndef _SOFTWARE_UPDATER_WINDOW_H #define _SOFTWARE_UPDATER_WINDOW_H @@ -50,7 +51,7 @@ public: private: BBitmap* _GetPackageIcon(float listItemHeight); - + BString fLabel; BString fItemText; BFont fRegularFont; @@ -84,7 +85,7 @@ public: { return fMoreDetailsWidth; }; float LessDetailsWidth() { return fLessDetailsWidth; }; - + private: void _DrawBar(BPoint where, BView* view, icon_size which); @@ -172,13 +173,14 @@ private: uint32 _GetState(); status_t _WriteSettings(); status_t _ReadSettings(BMessage& settings); - + BRect fDefaultRect; StripeView* fStripeView; BStringView* fHeaderView; BStringView* fDetailView; BButton* fUpdateButton; BButton* fCancelButton; + BButton* fRebootButton; BStatusBar* fStatusBar; PackageListView* fListView; BScrollView* fScrollView; @@ -188,8 +190,9 @@ private: BLayoutItem* fProgressLayoutItem; BLayoutItem* fCancelButtonLayoutItem; BLayoutItem* fUpdateButtonLayoutItem; + BLayoutItem* fRebootButtonLayoutItem; BLayoutItem* fDetailsCheckboxLayoutItem; - + uint32 fCurrentState; sem_id fWaitingSem; bool fWaitingForButton; diff --git a/src/apps/softwareupdater/UpdateManager.cpp b/src/apps/softwareupdater/UpdateManager.cpp index aa9f295344..81824e98f8 100644 --- a/src/apps/softwareupdater/UpdateManager.cpp +++ b/src/apps/softwareupdater/UpdateManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2019, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -7,6 +7,7 @@ * Rene Gollent * Ingo Weinhold * Brian Hill + * Jacob Secunda */ @@ -80,7 +81,7 @@ UpdateManager::CheckNetworkConnection() return; } } - + // No network connection detected, cannot continue throw BException(B_TRANSLATE_COMMENT( "No active network connection was found", "Error message")); @@ -131,7 +132,7 @@ UpdateManager::JobFailed(BSupportKit::BJob* job) { if (!fVerbose) return; - + BString error = job->ErrorString(); if (error.Length() > 0) { error.ReplaceAll("\n", "\n*** "); @@ -179,7 +180,7 @@ UpdateManager::ConfirmChanges(bool fromMostSpecific) int32 upgradeCount = 0; int32 installCount = 0; int32 uninstallCount = 0; - + if (fromMostSpecific) { for (int32 i = count - 1; i >= 0; i--) _PrintResult(*fInstalledRepositories.ItemAt(i), upgradeCount, @@ -189,16 +190,16 @@ UpdateManager::ConfirmChanges(bool fromMostSpecific) _PrintResult(*fInstalledRepositories.ItemAt(i), upgradeCount, installCount, uninstallCount); } - + if (fVerbose) printf("Upgrade count=%" B_PRId32 ", Install count=%" B_PRId32 ", Uninstall count=%" B_PRId32 "\n", upgradeCount, installCount, uninstallCount); - + fChangesConfirmed = fStatusWindow->ConfirmUpdates(); if (!fChangesConfirmed) throw BAbortedByUserException(); - + _SetCurrentStep(ACTION_STEP_DOWNLOAD); fPackageDownloadsTotal = upgradeCount + installCount; fPackageDownloadsCount = 1; @@ -221,7 +222,7 @@ UpdateManager::Warn(status_t error, const char* format, ...) else printf(": %s\n", strerror(error)); } - + if (fStatusWindow != NULL) { if (fStatusWindow->UserCancelRequested()) throw BAbortedByUserException(); @@ -244,7 +245,7 @@ UpdateManager::ProgressPackageDownloadStarted(const char* packageName) _UpdateDownloadProgress(header.String(), packageName, 0.0); fNewDownloadStarted = false; } - + if (fVerbose) printf("Downloading %s...\n", packageName); } @@ -277,22 +278,22 @@ UpdateManager::ProgressPackageDownloadActive(const char* packageName, "\xE2\x96\x89", "\xE2\x96\x88", }; - + int width = 70; - + struct winsize winSize; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winSize) == 0 && winSize.ws_col < 77) { // We need 7 characters for the percent display width = winSize.ws_col - 7; } - + int position; int ipart = (int)(completionValue * width); int fpart = (int)(((completionValue * width) - ipart) * 8); - + fputs("\r", stdout); // return to the beginning of the line - + for (position = 0; position < width; position++) { if (position < ipart) { // This part is fully downloaded, show a full block @@ -305,13 +306,13 @@ UpdateManager::ProgressPackageDownloadActive(const char* packageName, fputs(progressChars[fpart], stdout); } } - + // Also print the progress percentage printf(" %3d%%", (int)(completionValue * 100)); - + fflush(stdout); } - + } @@ -322,7 +323,7 @@ UpdateManager::ProgressPackageDownloadComplete(const char* packageName) _UpdateDownloadProgress(NULL, packageName, 100.0); fPackageDownloadsCount++; } - + if (fVerbose) { // Overwrite the progress bar with whitespace fputs("\r", stdout); @@ -331,7 +332,7 @@ UpdateManager::ProgressPackageDownloadComplete(const char* packageName) for (int i = 0; i < (w.ws_col); i++) fputs(" ", stdout); fputs("\r\x1b[1A", stdout); // Go to previous line. - + printf("Downloading %s...done.\n", packageName); } } @@ -343,7 +344,7 @@ UpdateManager::ProgressPackageChecksumStarted(const char* title) // Repository checksums if (fCurrentStep == ACTION_STEP_START) _UpdateStatusWindow(NULL, title); - + if (fVerbose) printf("%s...", title); } @@ -364,7 +365,7 @@ UpdateManager::ProgressStartApplyingChanges(InstalledRepository& repository) BString header(B_TRANSLATE("Applying changes")); BString detail(B_TRANSLATE("Packages are being updated")); fStatusWindow->UpdatesApplying(header.String(), detail.String()); - + if (fVerbose) printf("[%s] Applying changes ...\n", repository.Name().String()); } @@ -376,8 +377,16 @@ UpdateManager::ProgressTransactionCommitted(InstalledRepository& repository, { _SetCurrentStep(ACTION_STEP_COMPLETE); BString header(B_TRANSLATE("Updates completed")); - BString detail(B_TRANSLATE("A reboot may be necessary to complete some " - "updates.")); + + BString detail; + if (BPackageRoster().IsRebootNeeded()) { + detail = B_TRANSLATE("A reboot is necessary to complete the " + "update process."); + fStatusWindow->PostMessage(kMsgShowReboot); + } else { + detail = B_TRANSLATE("Updates have been successfully installed."); + } + _FinalUpdate(header.String(), detail.String()); if (fVerbose) { @@ -394,7 +403,7 @@ UpdateManager::ProgressTransactionCommitted(InstalledRepository& repository, issue->PackageName().String(), issue->ToString().String()); } } - + printf("[%s] Changes applied. Old activation state backed up in \"%s\"\n", repositoryName, result.OldStateDirectory().String()); printf("[%s] Cleaning up ...\n", repositoryName); @@ -508,10 +517,10 @@ UpdateManager::_UpdateStatusWindow(const char* header, const char* detail) { if (header == NULL && detail == NULL) return; - + if (fStatusWindow->UserCancelRequested()) throw BAbortedByUserException(); - + BMessage message(kMsgTextUpdate); if (header != NULL) message.AddString(kKeyHeader, header); @@ -527,10 +536,10 @@ UpdateManager::_UpdateDownloadProgress(const char* header, { if (packageName == NULL) return; - + if (fStatusWindow->UserCancelRequested()) throw BAbortedByUserException(); - + BString packageCount; packageCount.SetToFormat( B_TRANSLATE_COMMENT("%i of %i", "Do not translate %i"), @@ -556,7 +565,7 @@ UpdateManager::_FinalUpdate(const char* header, const char* text) notification.SetContent(text); notification.Send(); } - + fStatusWindow->FinalUpdate(header, text); } diff --git a/src/apps/softwareupdater/UpdateManager.h b/src/apps/softwareupdater/UpdateManager.h index 266430d630..61e5623de8 100644 --- a/src/apps/softwareupdater/UpdateManager.h +++ b/src/apps/softwareupdater/UpdateManager.h @@ -1,11 +1,12 @@ /* - * Copyright 2013-2017, Haiku, Inc. All Rights Reserved. + * Copyright 2013-2019, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Ingo Weinhold * Rene Gollent * Brian Hill + * Jacob Secunda */ #ifndef UPDATE_MANAGER_H #define UPDATE_MANAGER_H @@ -85,7 +86,7 @@ private: private: BPackageManager::ClientInstallationInterface fClientInstallationInterface; - + SoftwareUpdaterWindow* fStatusWindow; ProblemWindow* fProblemWindow; uint32 fCurrentStep; @@ -97,4 +98,4 @@ private: }; -#endif // UPDATE_MANAGER_H +#endif // UPDATE_MANAGER_H diff --git a/src/apps/softwareupdater/constants.h b/src/apps/softwareupdater/constants.h index aa1e1a20b0..8fee984d5d 100644 --- a/src/apps/softwareupdater/constants.h +++ b/src/apps/softwareupdater/constants.h @@ -1,9 +1,10 @@ /* - * Copyright 2017, Haiku, Inc. All Rights Reserved. + * Copyright 2017-2019, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: * Brian Hill + * Jacob Secunda */ #ifndef CONSTANTS_H #define CONSTANTS_H @@ -54,6 +55,8 @@ static const uint32 kMsgFinalQuit = 'iFIN'; static const uint32 kMsgMoreDetailsToggle = 'iDTO'; static const uint32 kMsgWindowFrameChanged = 'iWFC'; static const uint32 kMsgSetZoomLimits = 'iSZL'; +static const uint32 kMsgReboot = 'iREB'; +static const uint32 kMsgShowReboot = 'iSRB'; // Message data keys #define kKeyHeader "key_header"