mirror of
https://github.com/etlegacy/Update-Installer.git
synced 2025-01-22 15:31:08 +00:00
Refactor similar UpdateDialogGtk::Message and UpdateDialogWin32::Message class into a single shared UpdateMessage class.
This commit is contained in:
parent
0ca5928f08
commit
61e7561615
5 changed files with 59 additions and 60 deletions
|
@ -73,21 +73,22 @@ void UpdateDialogGtk::finish(GtkWidget* widget, gpointer _dialog)
|
|||
|
||||
gboolean UpdateDialogGtk::notify(void* _message)
|
||||
{
|
||||
Message* message = static_cast<Message*>(_message);
|
||||
UpdateMessage* message = static_cast<UpdateMessage*>(_message);
|
||||
UpdateDialogGtk* dialog = static_cast<UpdateDialogGtk*>(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "UpdateMessage.h"
|
||||
#include "UpdateObserver.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<WPARAM>(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<WPARAM>(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<WPARAM>(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<Message*>(wParam);
|
||||
UpdateMessage* message = reinterpret_cast<UpdateMessage*>(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);
|
||||
|
|
|
@ -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;
|
||||
|
|
37
src/UpdateMessage.h
Normal file
37
src/UpdateMessage.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
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;
|
||||
};
|
||||
|
Loading…
Reference in a new issue