diff --git a/src/UpdateDialogGtk.cpp b/src/UpdateDialogGtk.cpp index b1afaee..d1daed8 100644 --- a/src/UpdateDialogGtk.cpp +++ b/src/UpdateDialogGtk.cpp @@ -73,21 +73,22 @@ void UpdateDialogGtk::finish(GtkWidget* widget, gpointer _dialog) gboolean UpdateDialogGtk::notify(void* _message) { - Message* message = static_cast(_message); + UpdateMessage* message = static_cast(_message); + UpdateDialogGtk* dialog = static_cast(message->receiver); switch (message->type) { - case Message::UpdateProgress: - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(message->dialog->m_progressBar),message->progress/100.0); + case UpdateMessage::UpdateProgress: + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dialog->m_progressBar),message->progress/100.0); break; - case Message::UpdateFailed: - gtk_label_set_text(GTK_LABEL(message->dialog->m_progressLabel), + case UpdateMessage::UpdateFailed: + gtk_label_set_text(GTK_LABEL(dialog->m_progressLabel), ("There was a problem installing the update: " + message->message).c_str());; - gtk_widget_set_sensitive(message->dialog->m_finishButton,true); + gtk_widget_set_sensitive(dialog->m_finishButton,true); break; - case Message::UpdateFinished: - gtk_label_set_text(GTK_LABEL(message->dialog->m_progressLabel), + case UpdateMessage::UpdateFinished: + gtk_label_set_text(GTK_LABEL(dialog->m_progressLabel), "Update installed. Click 'Finish' to restart the application."); - gtk_widget_set_sensitive(message->dialog->m_finishButton,true); + gtk_widget_set_sensitive(dialog->m_finishButton,true); break; } delete message; @@ -99,7 +100,7 @@ gboolean UpdateDialogGtk::notify(void* _message) // callbacks during update installation void UpdateDialogGtk::updateError(const std::string& errorMessage) { - Message* message = new Message(this,Message::UpdateFailed); + UpdateMessage* message = new UpdateMessage(this,UpdateMessage::UpdateFailed); message->message = errorMessage; g_idle_add(&UpdateDialogGtk::notify,message); } @@ -111,14 +112,14 @@ bool UpdateDialogGtk::updateRetryCancel(const std::string& message) void UpdateDialogGtk::updateProgress(int percentage) { - Message* message = new Message(this,Message::UpdateProgress); + UpdateMessage* message = new UpdateMessage(this,UpdateMessage::UpdateProgress); message->progress = percentage; g_idle_add(&UpdateDialogGtk::notify,message); } void UpdateDialogGtk::updateFinished() { - Message* message = new Message(this,Message::UpdateFinished); + UpdateMessage* message = new UpdateMessage(this,UpdateMessage::UpdateFinished); g_idle_add(&UpdateDialogGtk::notify,message); } diff --git a/src/UpdateDialogGtk.h b/src/UpdateDialogGtk.h index 8f5e4f7..4af2d2e 100644 --- a/src/UpdateDialogGtk.h +++ b/src/UpdateDialogGtk.h @@ -1,5 +1,6 @@ #pragma once +#include "UpdateMessage.h" #include "UpdateObserver.h" #include @@ -22,27 +23,6 @@ class UpdateDialogGtk : public UpdateObserver virtual void updateFinished(); private: - struct Message - { - enum Type - { - UpdateFailed, - UpdateProgress, - UpdateFinished - }; - - Message(UpdateDialogGtk* _dialog, Type _type) - : dialog(_dialog) - , type(_type) - { - } - - UpdateDialogGtk* dialog; - Type type; - std::string message; - int progress; - }; - static void finish(GtkWidget* widget, gpointer dialog); static gboolean notify(void* message); diff --git a/src/UpdateDialogWin32.cpp b/src/UpdateDialogWin32.cpp index 6e21190..2096089 100644 --- a/src/UpdateDialogWin32.cpp +++ b/src/UpdateDialogWin32.cpp @@ -124,7 +124,7 @@ void UpdateDialogWin32::exec() void UpdateDialogWin32::updateError(const std::string& errorMessage) { - Message* message = new Message(Message::UpdateFailed); + UpdateMessage* message = new UpdateMessage(UpdateMessage::UpdateFailed); message->message = errorMessage; SendNotifyMessage(m_window.GetHwnd(),WM_USER,reinterpret_cast(message),0); } @@ -136,14 +136,14 @@ bool UpdateDialogWin32::updateRetryCancel(const std::string& message) void UpdateDialogWin32::updateProgress(int percentage) { - Message* message = new Message(Message::UpdateProgress); + UpdateMessage* message = new UpdateMessage(UpdateMessage::UpdateProgress); message->progress = percentage; SendNotifyMessage(m_window.GetHwnd(),WM_USER,reinterpret_cast(message),0); } void UpdateDialogWin32::updateFinished() { - Message* message = new Message(Message::UpdateFinished); + UpdateMessage* message = new UpdateMessage(UpdateMessage::UpdateFinished); SendNotifyMessage(m_window.GetHwnd(),WM_USER,reinterpret_cast(message),0); } @@ -169,10 +169,10 @@ LRESULT WINAPI UpdateDialogWin32::windowProc(HWND window, UINT message, WPARAM w { if (window == m_window.GetHwnd()) { - Message* message = reinterpret_cast(wParam); + UpdateMessage* message = reinterpret_cast(wParam); switch (message->type) { - case Message::UpdateFailed: + case UpdateMessage::UpdateFailed: { m_hadError = true; std::string text = "There was a problem installing the update:\n\n" + @@ -180,10 +180,10 @@ LRESULT WINAPI UpdateDialogWin32::windowProc(HWND window, UINT message, WPARAM w MessageBox(m_window.GetHwnd(),text.c_str(),"Update Problem",MB_OK); } break; - case Message::UpdateProgress: + case UpdateMessage::UpdateProgress: m_progressBar.SetPos(message->progress); break; - case Message::UpdateFinished: + case UpdateMessage::UpdateFinished: { std::string message; m_finishButton.EnableWindow(true); diff --git a/src/UpdateDialogWin32.h b/src/UpdateDialogWin32.h index a5103b2..572c3ae 100644 --- a/src/UpdateDialogWin32.h +++ b/src/UpdateDialogWin32.h @@ -1,6 +1,7 @@ #pragma once #include "Platform.h" +#include "UpdateMessage.h" #include "UpdateObserver.h" #include "wincore.h" @@ -25,26 +26,6 @@ class UpdateDialogWin32 : public UpdateObserver LRESULT WINAPI windowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam); private: - struct Message - { - enum Type - { - UpdateFailed, - UpdateProgress, - UpdateFinished - }; - - Message(Type _type) - : type(_type) - , progress(0) - { - } - - Type type; - std::string message; - int progress; - }; - void installWindowProc(CWnd* window); CWinApp m_app; diff --git a/src/UpdateMessage.h b/src/UpdateMessage.h new file mode 100644 index 0000000..6fc6988 --- /dev/null +++ b/src/UpdateMessage.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +class UpdateMessage +{ + public: + enum Type + { + UpdateFailed, + UpdateProgress, + UpdateFinished + }; + + UpdateMessage(void* receiver, Type type) + { + init(receiver,type); + } + + UpdateMessage(Type type) + { + init(0,type); + } + + void init(void* receiver, Type type) + { + this->progress = 0; + this->receiver = receiver; + this->type = type; + } + + void* receiver; + Type type; + std::string message; + int progress; +}; +