From 9894c2b26607d847b84c6b3015b71192f66e32d9 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 16 Jul 2012 23:26:14 +0200 Subject: Add simple creator thread --- Makefile | 2 +- creator_thread.cpp | 25 +++++++++++++++++++++++++ creator_thread.h | 19 +++++++++++++++++++ dialog.cpp | 14 +++++++++++++- dialog.h | 1 + 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 creator_thread.cpp create mode 100644 creator_thread.h diff --git a/Makefile b/Makefile index 672e497..939ac1a 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ WX_CFLAGS := $(shell wx-config --cflags) WX_LIBS := $(shell wx-config --libs) -OBJS_alpine-usb-creator-wxgtk := main.o dialog.o dialog_ui.o +OBJS_alpine-usb-creator-wxgtk := main.o dialog.o dialog_ui.o creator_thread.o LIBS_alpine-usb-creator-wxgtk := $(WX_LIBS) CFLAGS += $(WX_CFLAGS) diff --git a/creator_thread.cpp b/creator_thread.cpp new file mode 100644 index 0000000..2443c6b --- /dev/null +++ b/creator_thread.cpp @@ -0,0 +1,25 @@ +#include "creator_thread.h" + +CreatorThread::CreatorThread(Dialog *d) + : wxThread() +{ + m_dialog = d; +} + +void CreatorThread::OnExit() +{ +} + +wxThread::ExitCode CreatorThread::Entry() +{ + int i; + for (i = 0; i<=100; i++) { + wxMutexGuiEnter(); + m_dialog->SetProgress(i); + wxMutexGuiLeave(); + + wxMilliSleep(100); + } + return NULL; +} + diff --git a/creator_thread.h b/creator_thread.h new file mode 100644 index 0000000..82b218b --- /dev/null +++ b/creator_thread.h @@ -0,0 +1,19 @@ +#ifndef CREATOR_THREAD_H +#define CREATOR_THREAD_H + +#include +#include "dialog.h" + +class CreatorThread : public wxThread +{ +public: + CreatorThread(Dialog *d); + virtual void *Entry(); + virtual void OnExit(); + +protected: + Dialog *m_dialog; +}; + +#endif + diff --git a/dialog.cpp b/dialog.cpp index 3e03cb8..5d84300 100644 --- a/dialog.cpp +++ b/dialog.cpp @@ -3,6 +3,7 @@ #include #include "dialog.h" +#include "creator_thread.h" #ifdef __WINDOWS__ #include @@ -45,7 +46,14 @@ void Dialog::OnRefreshDrives(wxCommandEvent &event) void Dialog::OnStartButton(wxCommandEvent &event) { - wxMessageBox(wxT("To be implemented")); + CreatorThread *thread = new CreatorThread(this); + if (thread->Create() == wxTHREAD_NO_ERROR) { + m_start_button->Disable(); + m_target->Disable(); + m_iso_picker->Disable(); + m_refresh_button->Disable(); + thread->Run(); + } } void Dialog::OnCancelButton(wxCommandEvent &event) @@ -73,3 +81,7 @@ void Dialog::OnTargetChange(wxCommandEvent &event) UpdateStartButton(); } +void Dialog::SetProgress(int value) +{ + m_gauge->SetValue(value); +} diff --git a/dialog.h b/dialog.h index d8eb652..00e2bb6 100644 --- a/dialog.h +++ b/dialog.h @@ -8,6 +8,7 @@ class Dialog : public DialogUI public: Dialog(wxWindow *parent); void RefreshDrives(void); + void SetProgress(int value); protected: void UpdateStartButton(void); -- cgit v1.2.3