Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/engine/UpdateInstallDialog.cpp

Issue 11304082: Download updates automatically, ask to install from a modeless dialog (Closed)
Patch Set: Created July 31, 2013, 7:16 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/engine/UpdateInstallDialog.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/engine/UpdateInstallDialog.cpp
@@ -0,0 +1,129 @@
+#include <sstream>
+#include <string>
+#include <Windows.h>
+
+#include "../shared/Dictionary.h"
+#include "../shared/Utils.h"
+#include "UpdateInstallDialog.h"
+
+namespace
+{
+ LRESULT CALLBACK ProcessWindowMessage(HWND window, UINT message,
+ WPARAM wParam, LPARAM lParam)
+ {
+ switch (message)
+ {
+ case WM_CLOSE:
+ PostQuitMessage(0);
+ return 0;
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDYES:
+ PostQuitMessage(1);
+ return 0;
+ case IDNO:
+ PostQuitMessage(0);
+ return 0;
+ }
+ break;
+ }
+ return DefWindowProc(window, message, wParam, lParam);
+ }
+}
+
+UpdateInstallDialog::UpdateInstallDialog()
+{
+ const std::wstring windowClassName = L"UPDATE_INSTALL_DIALOG";
+ WNDCLASSEX windowClass = {};
Wladimir Palant 2013/08/01 09:58:24 We should use WNDCLASSEXW explicitly.
+ windowClass.cbSize = sizeof(WNDCLASSEX);
Wladimir Palant 2013/08/01 09:58:24 sizeof(windowClass) to avoid repeating the type na
Felix Dahlke 2013/08/02 10:48:01 Done.
+ windowClass.lpfnWndProc = ProcessWindowMessage;
+ windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_MENU + 1);
+ windowClass.lpszClassName = windowClassName.c_str();
Oleksandr 2013/08/01 07:05:12 Maybe use hIcon here with ABP logo? A default wind
+ if (!RegisterClassEx(&windowClass))
+ {
+ std::stringstream stream;
+ stream << "Failed to register window class "
+ << ToUtf8String(windowClassName) << ": " << GetLastError();
+ throw std::runtime_error(stream.str());
+ }
+
+ Dictionary* dictionary = Dictionary::GetInstance();
+ std::wstring title = dictionary->Lookup("updater", "install-question-title");
Oleksandr 2013/07/31 22:16:59 This is fine only for when download is ready. How
Felix Dahlke 2013/08/01 07:21:17 Like I said earlier, I think it's better to focus
+
+ RECT workArea;
+ SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
+
+ const int width = 300;
+ const int height = 150;
Wladimir Palant 2013/08/01 09:58:24 Where do these numbers come from? What will happen
Felix Dahlke 2013/08/02 10:48:01 Done.
+ const int margin = 10;
+
+ window = CreateWindowExW(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
+ windowClassName.c_str(), title.c_str(), WS_SYSMENU,
+ workArea.right - width - margin,
+ workArea.bottom - height - margin,
+ width, height, 0, 0, 0, 0);
Oleksandr 2013/08/01 07:05:12 Should we do something like: SetForegroundWindow(
+ CreateText();
+ CreateButtons();
Oleksandr 2013/07/31 22:16:59 No CreateButtons() in the overridden constructor I
Felix Dahlke 2013/08/01 07:21:17 As I said above, let's make this more generic when
+}
+
+UpdateInstallDialog::~UpdateInstallDialog()
+{
+ DestroyWindow(window);
+}
+
+bool UpdateInstallDialog::Show()
+{
+ ShowWindow(window, SW_SHOW);
+ MSG message;
+ while(GetMessage(&message, 0, 0, 0) > 0)
+ {
+ TranslateMessage(&message);
+ DispatchMessage(&message);
+ }
+ ShowWindow(window, SW_HIDE);
+ return message.wParam;
Wladimir Palant 2013/08/01 09:58:24 Doesn't this cause a warning? I would rather cast
Felix Dahlke 2013/08/02 10:48:01 Done. Opted for message.wParam == 0 in case of yes
+}
+
+void UpdateInstallDialog::CreateText()
+{
+ Dictionary* dictionary = Dictionary::GetInstance();
+ std::wstring text = dictionary->Lookup("updater", "install-question-text");
+
+ RECT clientRect;
+ GetClientRect(window, &clientRect);
+
+ const int margin = 10;
+ const int width = clientRect.right - margin * 2;
+ const int height = 60;
+
+ CreateWindowW(L"STATIC", text.c_str(), WS_CHILD | WS_VISIBLE| SS_LEFT,
+ margin, margin, width, height, window, 0, 0, 0);
+}
+
+void UpdateInstallDialog::CreateButtons()
+{
+ Dictionary* dictionary = Dictionary::GetInstance();
+ const std::wstring yesLabel = dictionary->Lookup("general", "button-yes");
+ const std::wstring noLabel = dictionary->Lookup("general", "button-no");
+
+ const DWORD buttonFlags = WS_CHILD | WS_VISIBLE;
+
+ RECT clientRect;
+ GetClientRect(window, &clientRect);
+
+ const int buttonWidth = 100;
+ const int buttonHeight = 30;
Felix Dahlke 2013/08/02 10:48:01 Done.
+ const int margin = 10;
+ const int combinedWidth = buttonWidth * 2 + margin;
+ const int yesButtonX = clientRect.right - combinedWidth - margin;
+ const int noButtonX = yesButtonX + buttonWidth + margin;
+ const int buttonY = clientRect.bottom - buttonHeight - margin;
+
+ CreateWindowW(L"BUTTON", yesLabel.c_str(), buttonFlags,
+ yesButtonX, buttonY, buttonWidth, buttonHeight,
+ window, reinterpret_cast<HMENU>(IDYES), 0, 0);
+ CreateWindowW(L"BUTTON", noLabel.c_str(), buttonFlags,
+ noButtonX, buttonY, buttonWidth, buttonHeight,
+ window, reinterpret_cast<HMENU>(IDNO), 0, 0);
+}

Powered by Google App Engine
This is Rietveld