Added reboot button for after successful update

Change-Id: Ia444132bd8ffc2ccde53efcdbcbd9f31c3f2a439
Reviewed-on: https://review.haiku-os.org/c/968
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
CodeforEvolution
2019-03-26 20:39:44 +00:00
committed by waddlesplash
parent e1b41d44a3
commit 134abee09e
7 changed files with 92 additions and 42 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
SubDir HAIKU_TOP src apps softwareupdater ; SubDir HAIKU_TOP src apps softwareupdater ;
UsePrivateHeaders interface shared package ; UsePrivateHeaders app interface shared package ;
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src servers package ] ; SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src servers package ] ;
@@ -9,7 +9,7 @@ resource app_version {
variety = B_APPV_BETA, variety = B_APPV_BETA,
internal = 0, internal = 0,
short_info = "SoftwareUpdater", short_info = "SoftwareUpdater",
long_info = "Software Updater ©2008-2017 Haiku" long_info = "Software Updater ©2008-2019 Haiku"
}; };
resource vector_icon { resource vector_icon {
@@ -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 * Distributed under the terms of the MIT license
* *
* Authors: * Authors:
* Alexander von Gluck IV <[email protected]> * Alexander von Gluck IV <[email protected]>
* Brian Hill <[email protected]> * Brian Hill <[email protected]>
* Jacob Secunda
*/ */
@@ -20,6 +21,7 @@
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <Message.h> #include <Message.h>
#include <Roster.h> #include <Roster.h>
#include <RosterPrivate.h>
#include <Screen.h> #include <Screen.h>
#include <String.h> #include <String.h>
@@ -60,6 +62,8 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow()
fUpdateButton->MakeDefault(true); fUpdateButton->MakeDefault(true);
fCancelButton = new BButton(B_TRANSLATE("Cancel"), fCancelButton = new BButton(B_TRANSLATE("Cancel"),
new BMessage(kMsgCancel)); new BMessage(kMsgCancel));
fRebootButton = new BButton(B_TRANSLATE("Reboot"),
new BMessage(kMsgReboot));
fHeaderView = new BStringView("header", fHeaderView = new BStringView("header",
B_TRANSLATE("Checking for updates"), B_WILL_DRAW); B_TRANSLATE("Checking for updates"), B_WILL_DRAW);
@@ -104,6 +108,7 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow()
.AddGlue() .AddGlue()
.Add(fCancelButton) .Add(fCancelButton)
.Add(fUpdateButton) .Add(fUpdateButton)
.Add(fRebootButton)
.End() .End()
.End() .End()
.End(); .End();
@@ -113,6 +118,7 @@ SoftwareUpdaterWindow::SoftwareUpdaterWindow()
fPackagesLayoutItem = layout_item_for(fScrollView); fPackagesLayoutItem = layout_item_for(fScrollView);
fCancelButtonLayoutItem = layout_item_for(fCancelButton); fCancelButtonLayoutItem = layout_item_for(fCancelButton);
fUpdateButtonLayoutItem = layout_item_for(fUpdateButton); fUpdateButtonLayoutItem = layout_item_for(fUpdateButton);
fRebootButtonLayoutItem = layout_item_for(fRebootButton);
fDetailsCheckboxLayoutItem = layout_item_for(fDetailsCheckbox); fDetailsCheckboxLayoutItem = layout_item_for(fDetailsCheckbox);
_SetState(STATE_DISPLAY_STATUS); _SetState(STATE_DISPLAY_STATUS);
@@ -307,6 +313,33 @@ SoftwareUpdaterWindow::MessageReceived(BMessage* message)
break; 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: case kMsgCancelResponse:
{ {
// Verify whether the cancel alert was confirmed // Verify whether the cancel alert was confirmed
@@ -567,6 +600,7 @@ SoftwareUpdaterWindow::_SetState(uint32 state)
fPackagesLayoutItem->SetVisible(false); fPackagesLayoutItem->SetVisible(false);
fDetailsCheckboxLayoutItem->SetVisible(false); fDetailsCheckboxLayoutItem->SetVisible(false);
fCancelButtonLayoutItem->SetVisible(false); fCancelButtonLayoutItem->SetVisible(false);
fRebootButtonLayoutItem->SetVisible(false);
} }
fCurrentState = state; fCurrentState = state;
@@ -655,7 +689,7 @@ SoftwareUpdaterWindow::_SetState(uint32 state)
if (fCurrentState == STATE_FINAL_MESSAGE) { if (fCurrentState == STATE_FINAL_MESSAGE) {
fCancelButtonLayoutItem->SetVisible(true); fCancelButtonLayoutItem->SetVisible(true);
fCancelButton->SetLabel(B_TRANSLATE_COMMENT("Quit", "Button label")); fCancelButton->SetLabel(B_TRANSLATE_COMMENT("Quit", "Button label"));
fCancelButton->MakeDefault(true); fCancelButton->MakeDefault(true);
} }
Unlock(); Unlock();
@@ -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 * Distributed under the terms of the MIT license
* *
* Authors: * Authors:
* Alexander von Gluck IV <kallisti5@unixzen.com> * Alexander von Gluck IV <kallisti5@unixzen.com>
* Brian Hill <supernova@tycho.email> * Brian Hill <supernova@tycho.email>
* Jacob Secunda
*/ */
#ifndef _SOFTWARE_UPDATER_WINDOW_H #ifndef _SOFTWARE_UPDATER_WINDOW_H
#define _SOFTWARE_UPDATER_WINDOW_H #define _SOFTWARE_UPDATER_WINDOW_H
@@ -50,7 +51,7 @@ public:
private: private:
BBitmap* _GetPackageIcon(float listItemHeight); BBitmap* _GetPackageIcon(float listItemHeight);
BString fLabel; BString fLabel;
BString fItemText; BString fItemText;
BFont fRegularFont; BFont fRegularFont;
@@ -84,7 +85,7 @@ public:
{ return fMoreDetailsWidth; }; { return fMoreDetailsWidth; };
float LessDetailsWidth() float LessDetailsWidth()
{ return fLessDetailsWidth; }; { return fLessDetailsWidth; };
private: private:
void _DrawBar(BPoint where, BView* view, void _DrawBar(BPoint where, BView* view,
icon_size which); icon_size which);
@@ -172,13 +173,14 @@ private:
uint32 _GetState(); uint32 _GetState();
status_t _WriteSettings(); status_t _WriteSettings();
status_t _ReadSettings(BMessage& settings); status_t _ReadSettings(BMessage& settings);
BRect fDefaultRect; BRect fDefaultRect;
StripeView* fStripeView; StripeView* fStripeView;
BStringView* fHeaderView; BStringView* fHeaderView;
BStringView* fDetailView; BStringView* fDetailView;
BButton* fUpdateButton; BButton* fUpdateButton;
BButton* fCancelButton; BButton* fCancelButton;
BButton* fRebootButton;
BStatusBar* fStatusBar; BStatusBar* fStatusBar;
PackageListView* fListView; PackageListView* fListView;
BScrollView* fScrollView; BScrollView* fScrollView;
@@ -188,8 +190,9 @@ private:
BLayoutItem* fProgressLayoutItem; BLayoutItem* fProgressLayoutItem;
BLayoutItem* fCancelButtonLayoutItem; BLayoutItem* fCancelButtonLayoutItem;
BLayoutItem* fUpdateButtonLayoutItem; BLayoutItem* fUpdateButtonLayoutItem;
BLayoutItem* fRebootButtonLayoutItem;
BLayoutItem* fDetailsCheckboxLayoutItem; BLayoutItem* fDetailsCheckboxLayoutItem;
uint32 fCurrentState; uint32 fCurrentState;
sem_id fWaitingSem; sem_id fWaitingSem;
bool fWaitingForButton; bool fWaitingForButton;
+38 -29
View File
@@ -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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -7,6 +7,7 @@
* Rene Gollent <rene@gollent.com> * Rene Gollent <rene@gollent.com>
* Ingo Weinhold <ingo_weinhold@gmx.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
* Brian Hill <supernova@tycho.email> * Brian Hill <supernova@tycho.email>
* Jacob Secunda
*/ */
@@ -80,7 +81,7 @@ UpdateManager::CheckNetworkConnection()
return; return;
} }
} }
// No network connection detected, cannot continue // No network connection detected, cannot continue
throw BException(B_TRANSLATE_COMMENT( throw BException(B_TRANSLATE_COMMENT(
"No active network connection was found", "Error message")); "No active network connection was found", "Error message"));
@@ -131,7 +132,7 @@ UpdateManager::JobFailed(BSupportKit::BJob* job)
{ {
if (!fVerbose) if (!fVerbose)
return; return;
BString error = job->ErrorString(); BString error = job->ErrorString();
if (error.Length() > 0) { if (error.Length() > 0) {
error.ReplaceAll("\n", "\n*** "); error.ReplaceAll("\n", "\n*** ");
@@ -179,7 +180,7 @@ UpdateManager::ConfirmChanges(bool fromMostSpecific)
int32 upgradeCount = 0; int32 upgradeCount = 0;
int32 installCount = 0; int32 installCount = 0;
int32 uninstallCount = 0; int32 uninstallCount = 0;
if (fromMostSpecific) { if (fromMostSpecific) {
for (int32 i = count - 1; i >= 0; i--) for (int32 i = count - 1; i >= 0; i--)
_PrintResult(*fInstalledRepositories.ItemAt(i), upgradeCount, _PrintResult(*fInstalledRepositories.ItemAt(i), upgradeCount,
@@ -189,16 +190,16 @@ UpdateManager::ConfirmChanges(bool fromMostSpecific)
_PrintResult(*fInstalledRepositories.ItemAt(i), upgradeCount, _PrintResult(*fInstalledRepositories.ItemAt(i), upgradeCount,
installCount, uninstallCount); installCount, uninstallCount);
} }
if (fVerbose) if (fVerbose)
printf("Upgrade count=%" B_PRId32 ", Install count=%" B_PRId32 printf("Upgrade count=%" B_PRId32 ", Install count=%" B_PRId32
", Uninstall count=%" B_PRId32 "\n", ", Uninstall count=%" B_PRId32 "\n",
upgradeCount, installCount, uninstallCount); upgradeCount, installCount, uninstallCount);
fChangesConfirmed = fStatusWindow->ConfirmUpdates(); fChangesConfirmed = fStatusWindow->ConfirmUpdates();
if (!fChangesConfirmed) if (!fChangesConfirmed)
throw BAbortedByUserException(); throw BAbortedByUserException();
_SetCurrentStep(ACTION_STEP_DOWNLOAD); _SetCurrentStep(ACTION_STEP_DOWNLOAD);
fPackageDownloadsTotal = upgradeCount + installCount; fPackageDownloadsTotal = upgradeCount + installCount;
fPackageDownloadsCount = 1; fPackageDownloadsCount = 1;
@@ -221,7 +222,7 @@ UpdateManager::Warn(status_t error, const char* format, ...)
else else
printf(": %s\n", strerror(error)); printf(": %s\n", strerror(error));
} }
if (fStatusWindow != NULL) { if (fStatusWindow != NULL) {
if (fStatusWindow->UserCancelRequested()) if (fStatusWindow->UserCancelRequested())
throw BAbortedByUserException(); throw BAbortedByUserException();
@@ -244,7 +245,7 @@ UpdateManager::ProgressPackageDownloadStarted(const char* packageName)
_UpdateDownloadProgress(header.String(), packageName, 0.0); _UpdateDownloadProgress(header.String(), packageName, 0.0);
fNewDownloadStarted = false; fNewDownloadStarted = false;
} }
if (fVerbose) if (fVerbose)
printf("Downloading %s...\n", packageName); printf("Downloading %s...\n", packageName);
} }
@@ -277,22 +278,22 @@ UpdateManager::ProgressPackageDownloadActive(const char* packageName,
"\xE2\x96\x89", "\xE2\x96\x89",
"\xE2\x96\x88", "\xE2\x96\x88",
}; };
int width = 70; int width = 70;
struct winsize winSize; struct winsize winSize;
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winSize) == 0 if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &winSize) == 0
&& winSize.ws_col < 77) { && winSize.ws_col < 77) {
// We need 7 characters for the percent display // We need 7 characters for the percent display
width = winSize.ws_col - 7; width = winSize.ws_col - 7;
} }
int position; int position;
int ipart = (int)(completionValue * width); int ipart = (int)(completionValue * width);
int fpart = (int)(((completionValue * width) - ipart) * 8); int fpart = (int)(((completionValue * width) - ipart) * 8);
fputs("\r", stdout); // return to the beginning of the line fputs("\r", stdout); // return to the beginning of the line
for (position = 0; position < width; position++) { for (position = 0; position < width; position++) {
if (position < ipart) { if (position < ipart) {
// This part is fully downloaded, show a full block // This part is fully downloaded, show a full block
@@ -305,13 +306,13 @@ UpdateManager::ProgressPackageDownloadActive(const char* packageName,
fputs(progressChars[fpart], stdout); fputs(progressChars[fpart], stdout);
} }
} }
// Also print the progress percentage // Also print the progress percentage
printf(" %3d%%", (int)(completionValue * 100)); printf(" %3d%%", (int)(completionValue * 100));
fflush(stdout); fflush(stdout);
} }
} }
@@ -322,7 +323,7 @@ UpdateManager::ProgressPackageDownloadComplete(const char* packageName)
_UpdateDownloadProgress(NULL, packageName, 100.0); _UpdateDownloadProgress(NULL, packageName, 100.0);
fPackageDownloadsCount++; fPackageDownloadsCount++;
} }
if (fVerbose) { if (fVerbose) {
// Overwrite the progress bar with whitespace // Overwrite the progress bar with whitespace
fputs("\r", stdout); fputs("\r", stdout);
@@ -331,7 +332,7 @@ UpdateManager::ProgressPackageDownloadComplete(const char* packageName)
for (int i = 0; i < (w.ws_col); i++) for (int i = 0; i < (w.ws_col); i++)
fputs(" ", stdout); fputs(" ", stdout);
fputs("\r\x1b[1A", stdout); // Go to previous line. fputs("\r\x1b[1A", stdout); // Go to previous line.
printf("Downloading %s...done.\n", packageName); printf("Downloading %s...done.\n", packageName);
} }
} }
@@ -343,7 +344,7 @@ UpdateManager::ProgressPackageChecksumStarted(const char* title)
// Repository checksums // Repository checksums
if (fCurrentStep == ACTION_STEP_START) if (fCurrentStep == ACTION_STEP_START)
_UpdateStatusWindow(NULL, title); _UpdateStatusWindow(NULL, title);
if (fVerbose) if (fVerbose)
printf("%s...", title); printf("%s...", title);
} }
@@ -364,7 +365,7 @@ UpdateManager::ProgressStartApplyingChanges(InstalledRepository& repository)
BString header(B_TRANSLATE("Applying changes")); BString header(B_TRANSLATE("Applying changes"));
BString detail(B_TRANSLATE("Packages are being updated")); BString detail(B_TRANSLATE("Packages are being updated"));
fStatusWindow->UpdatesApplying(header.String(), detail.String()); fStatusWindow->UpdatesApplying(header.String(), detail.String());
if (fVerbose) if (fVerbose)
printf("[%s] Applying changes ...\n", repository.Name().String()); printf("[%s] Applying changes ...\n", repository.Name().String());
} }
@@ -376,8 +377,16 @@ UpdateManager::ProgressTransactionCommitted(InstalledRepository& repository,
{ {
_SetCurrentStep(ACTION_STEP_COMPLETE); _SetCurrentStep(ACTION_STEP_COMPLETE);
BString header(B_TRANSLATE("Updates completed")); 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()); _FinalUpdate(header.String(), detail.String());
if (fVerbose) { if (fVerbose) {
@@ -394,7 +403,7 @@ UpdateManager::ProgressTransactionCommitted(InstalledRepository& repository,
issue->PackageName().String(), issue->ToString().String()); issue->PackageName().String(), issue->ToString().String());
} }
} }
printf("[%s] Changes applied. Old activation state backed up in \"%s\"\n", printf("[%s] Changes applied. Old activation state backed up in \"%s\"\n",
repositoryName, result.OldStateDirectory().String()); repositoryName, result.OldStateDirectory().String());
printf("[%s] Cleaning up ...\n", repositoryName); printf("[%s] Cleaning up ...\n", repositoryName);
@@ -508,10 +517,10 @@ UpdateManager::_UpdateStatusWindow(const char* header, const char* detail)
{ {
if (header == NULL && detail == NULL) if (header == NULL && detail == NULL)
return; return;
if (fStatusWindow->UserCancelRequested()) if (fStatusWindow->UserCancelRequested())
throw BAbortedByUserException(); throw BAbortedByUserException();
BMessage message(kMsgTextUpdate); BMessage message(kMsgTextUpdate);
if (header != NULL) if (header != NULL)
message.AddString(kKeyHeader, header); message.AddString(kKeyHeader, header);
@@ -527,10 +536,10 @@ UpdateManager::_UpdateDownloadProgress(const char* header,
{ {
if (packageName == NULL) if (packageName == NULL)
return; return;
if (fStatusWindow->UserCancelRequested()) if (fStatusWindow->UserCancelRequested())
throw BAbortedByUserException(); throw BAbortedByUserException();
BString packageCount; BString packageCount;
packageCount.SetToFormat( packageCount.SetToFormat(
B_TRANSLATE_COMMENT("%i of %i", "Do not translate %i"), 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.SetContent(text);
notification.Send(); notification.Send();
} }
fStatusWindow->FinalUpdate(header, text); fStatusWindow->FinalUpdate(header, text);
} }
+4 -3
View File
@@ -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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Ingo Weinhold <ingo_weinhold@gmx.de> * Ingo Weinhold <ingo_weinhold@gmx.de>
* Rene Gollent <rene@gollent.com> * Rene Gollent <rene@gollent.com>
* Brian Hill <supernova@tycho.email> * Brian Hill <supernova@tycho.email>
* Jacob Secunda
*/ */
#ifndef UPDATE_MANAGER_H #ifndef UPDATE_MANAGER_H
#define UPDATE_MANAGER_H #define UPDATE_MANAGER_H
@@ -85,7 +86,7 @@ private:
private: private:
BPackageManager::ClientInstallationInterface BPackageManager::ClientInstallationInterface
fClientInstallationInterface; fClientInstallationInterface;
SoftwareUpdaterWindow* fStatusWindow; SoftwareUpdaterWindow* fStatusWindow;
ProblemWindow* fProblemWindow; ProblemWindow* fProblemWindow;
uint32 fCurrentStep; uint32 fCurrentStep;
@@ -97,4 +98,4 @@ private:
}; };
#endif // UPDATE_MANAGER_H #endif // UPDATE_MANAGER_H
+4 -1
View File
@@ -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. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Brian Hill <supernova@tycho.email> * Brian Hill <supernova@tycho.email>
* Jacob Secunda
*/ */
#ifndef CONSTANTS_H #ifndef CONSTANTS_H
#define CONSTANTS_H #define CONSTANTS_H
@@ -54,6 +55,8 @@ static const uint32 kMsgFinalQuit = 'iFIN';
static const uint32 kMsgMoreDetailsToggle = 'iDTO'; static const uint32 kMsgMoreDetailsToggle = 'iDTO';
static const uint32 kMsgWindowFrameChanged = 'iWFC'; static const uint32 kMsgWindowFrameChanged = 'iWFC';
static const uint32 kMsgSetZoomLimits = 'iSZL'; static const uint32 kMsgSetZoomLimits = 'iSZL';
static const uint32 kMsgReboot = 'iREB';
static const uint32 kMsgShowReboot = 'iSRB';
// Message data keys // Message data keys
#define kKeyHeader "key_header" #define kKeyHeader "key_header"