[Scummvm-cvs-logs] SF.net SVN: scummvm:[42453] tools/branches/gsoc2009-gui

Remere at users.sourceforge.net Remere at users.sourceforge.net
Mon Jul 13 23:20:25 CEST 2009


Revision: 42453
          http://scummvm.svn.sourceforge.net/scummvm/?rev=42453&view=rev
Author:   Remere
Date:     2009-07-13 21:20:24 +0000 (Mon, 13 Jul 2009)

Log Message:
-----------
*Added a progress bar to the process page, no tool support procentual progress, so now it just bounces back and forth to indicate something is happening (exact look depends on OS). 
*Added a failure page instead of finish page, to indicate that the wizard did _not_ finish properly.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/gui/pages.cpp
    tools/branches/gsoc2009-gui/gui/pages.h
    tools/branches/gsoc2009-gui/gui/tools.cpp
    tools/branches/gsoc2009-gui/gui/tools.h
    tools/branches/gsoc2009-gui/tool.cpp
    tools/branches/gsoc2009-gui/tool.h

Modified: tools/branches/gsoc2009-gui/gui/pages.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.cpp	2009-07-13 19:53:53 UTC (rev 42452)
+++ tools/branches/gsoc2009-gui/gui/pages.cpp	2009-07-13 21:20:24 UTC (rev 42453)
@@ -902,6 +902,11 @@
 	  _finished(false),
 	  _success(false)
 {
+	_gauge = NULL;
+	_outwin = NULL;
+
+	_output.done = 0;
+	_output.total = 100;
 }
 
 wxWindow *ProcessPage::CreatePanel(wxWindow *parent) {
@@ -915,8 +920,12 @@
 	
 	_outwin = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 
 		wxTE_MULTILINE | wxTE_READONLY, wxDefaultValidator, wxT("OutputWindow"));
-	sizer->Add(_outwin, wxSizerFlags(1).Expand().Border(wxALL, 10));
+	sizer->Add(_outwin, wxSizerFlags(1).Expand().Border(wxTOP | wxLEFT | wxRIGHT, 10));
 
+	_gauge = new wxGauge(panel, wxID_ANY, _output.total, wxDefaultPosition, wxDefaultSize, 
+		wxGA_HORIZONTAL, wxDefaultValidator, wxT("ProgressBar"));
+	sizer->Add(_gauge, wxSizerFlags(0).Expand().Border(wxBOTTOM | wxLEFT | wxRIGHT, 10));
+
 	panel->SetSizer(sizer);
 
 	// Run the tool
@@ -941,15 +950,23 @@
 }
 
 bool ProcessPage::onIdle(wxPanel *panel) {
+	const ToolGUI *tool = _topframe->_configuration.selectedTool;
+
 	if (!_thread)
 		return false;
 
 	{
 		wxMutexLocker lock(_output.mutex);
 
+		// Write text
 		_outwin->WriteText(wxString(_output.buffer.c_str(), wxConvUTF8));
+		_output.buffer = "";
 
-		_output.buffer = "";
+		if(tool->supportsProgressBar()) {
+			// Update gauge
+			_gauge->SetRange(_output.total);
+			_gauge->SetValue(_output.done);
+		}
 	}
 
 	// Check if thread finished
@@ -965,11 +982,19 @@
 		return false;
 	}
 
+	if(!tool->supportsProgressBar()) {
+		// Just move the bar back & forth
+		_gauge->Pulse();
+	}
+
 	return true;
 }
 
 void ProcessPage::onNext(wxWindow *panel) {
-	switchPage(new FinishPage(_topframe));
+	if(_success)
+		switchPage(new FinishPage(_topframe));
+	else
+		switchPage(new FailurePage(_topframe));
 }
 
 void ProcessPage::onCancel(wxWindow *panel) {
@@ -984,10 +1009,17 @@
 		buttons->enablePrevious(false);
 		buttons->enableNext(true);
 		buttons->showAbort(false);
+
+		_gauge->SetRange(100);
+		_gauge->SetValue(100);
 	} else if (_finished) {
 		buttons->enablePrevious(true);
 		buttons->enableNext(true);
 		buttons->showAbort(false);
+
+		// It's not possible to disable them, leave it empty instead
+		_gauge->SetRange(0);
+		_gauge->SetValue(100);
 	} else {
 		buttons->enablePrevious(false);
 		buttons->enableNext(false);
@@ -1006,6 +1038,7 @@
 	_finished = false;
 	
 	_tool->_backend->setPrintFunction(writeToOutput, reinterpret_cast<void *>(this));
+	_tool->_backend->setProgressFunction(gaugeProgress, reinterpret_cast<void *>(this));
 }
 
 wxThread::ExitCode ProcessToolThread::Entry() {
@@ -1032,8 +1065,16 @@
 	self->_output.buffer += text;
 }
 
-// Page to choose ANY tool to use
+void ProcessToolThread::gaugeProgress(void *udata, int done, int total) {
+	ProcessToolThread *self = reinterpret_cast<ProcessToolThread *>(udata);
+	
+	wxMutexLocker lock(self->_output.mutex);
+	self->_output.done  = done;
+	self->_output.total = total;
+}
 
+// Last page of the wizard, offers the option to open the output directory
+
 FinishPage::FinishPage(ScummToolsFrame* frame)
 	: WizardPage(frame)
 {
@@ -1083,4 +1124,37 @@
 }
 
 
+// If the tool fails, this page is shown instead of the last page
 
+FailurePage::FailurePage(ScummToolsFrame* frame)
+	: WizardPage(frame)
+{
+}
+
+wxWindow *FailurePage::CreatePanel(wxWindow *parent) {
+	wxWindow *panel = WizardPage::CreatePanel(parent);
+
+	wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+	sizer->AddSpacer(15);
+
+	sizer->Add(new wxStaticText(panel, wxID_ANY,
+		wxT("The execution of the tool failed. You can try running the wizard again and ensure that the file paths are accurate.")),
+		wxSizerFlags(1).Expand());
+
+	SetAlignedSizer(panel, sizer);
+
+	return panel;
+}
+
+void FailurePage::onNext(wxWindow *panel) {
+	_topframe->Close(true);
+}
+
+void FailurePage::updateButtons(wxWindow *panel, WizardButtons *buttons) {
+	buttons->enablePrevious(false);
+	buttons->showFinish(true);
+}
+
+
+

Modified: tools/branches/gsoc2009-gui/gui/pages.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.h	2009-07-13 19:53:53 UTC (rev 42452)
+++ tools/branches/gsoc2009-gui/gui/pages.h	2009-07-13 21:20:24 UTC (rev 42453)
@@ -313,6 +313,8 @@
 
 struct ThreadOutputBuffer {
 	std::string buffer;
+	int done;
+	int total;
 	wxMutex mutex;
 };
 
@@ -341,6 +343,13 @@
 	 */
 	static void writeToOutput(void *udata, const char *text);
 
+	/**
+	 * Update progress bar, thread-safe
+	 * simply updates the values in the shared buffer, and the actual control
+	 * is then updated in the main thread.
+	 */
+	static void gaugeProgress(void *udata, int done, int total);
+
 	bool _finished;
 
 protected:
@@ -367,6 +376,8 @@
 	bool _finished;
 	/** Output window */
 	wxTextCtrl *_outwin;
+	/** Gauge showing progress */
+	wxGauge *_gauge;
 	/** The thread which the tool is run in */
 	ProcessToolThread *_thread;
 	/** The structure to exchange output between thread & gui */
@@ -409,3 +420,21 @@
 
 	void updateButtons(wxWindow *panel, WizardButtons *buttons);
 };
+
+/**
+ * Displays a message saying that we failed, and clicking next will close the wizard
+ *
+ */
+
+class FailurePage : public WizardPage
+{
+public:
+	FailurePage(ScummToolsFrame* frame);
+
+	wxWindow *CreatePanel(wxWindow *parent);
+
+	void onNext(wxWindow *panel);
+
+	void updateButtons(wxWindow *panel, WizardButtons *buttons);
+};
+

Modified: tools/branches/gsoc2009-gui/gui/tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.cpp	2009-07-13 19:53:53 UTC (rev 42452)
+++ tools/branches/gsoc2009-gui/gui/tools.cpp	2009-07-13 21:20:24 UTC (rev 42453)
@@ -315,9 +315,13 @@
 }
 
 bool ToolGUI::supportsAudioFormat(AudioFormat format) const {
-	return (_backend->_supported_formats & format) == format;
+	return (_backend->_supportedFormats & format) == format;
 }
 
+bool ToolGUI::supportsProgressBar() const {
+	return _backend->_supportsProgressBar;
+}
+
 bool ToolGUI::outputToDirectory() const {
 	return _backend->_outputToDirectory;
 }

Modified: tools/branches/gsoc2009-gui/gui/tools.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.h	2009-07-13 19:53:53 UTC (rev 42452)
+++ tools/branches/gsoc2009-gui/gui/tools.h	2009-07-13 21:20:24 UTC (rev 42453)
@@ -108,6 +108,11 @@
 	 * @param format The audio format(s) to test for
 	 */
 	bool supportsAudioFormat(AudioFormat format) const;
+	
+	/**
+	 * Returns true if the tool supports a load bar for displaying progress
+	 */
+	bool supportsProgressBar() const;
 
 	/**
 	 * Returns true if the tool outputs to an entire directory, not a single file

Modified: tools/branches/gsoc2009-gui/tool.cpp
===================================================================
--- tools/branches/gsoc2009-gui/tool.cpp	2009-07-13 19:53:53 UTC (rev 42452)
+++ tools/branches/gsoc2009-gui/tool.cpp	2009-07-13 21:20:24 UTC (rev 42453)
@@ -34,7 +34,8 @@
 
 	_inputFromDirectory = false;
 	_outputToDirectory = true;
-	_supported_formats = AUDIO_NONE;
+	_supportedFormats = AUDIO_NONE;
+	_supportsProgressBar = false;
 
 	_internalPrint = printToSTDOUT;
 	_print_udata = NULL;
@@ -68,7 +69,7 @@
 	}
 
 	// Read standard arguments
-	if (_supported_formats != AUDIO_NONE)
+	if (_supportedFormats != AUDIO_NONE)
 		parseAudioArguments();
 	parseOutputArguments();
 	// Read tool specific arguments

Modified: tools/branches/gsoc2009-gui/tool.h
===================================================================
--- tools/branches/gsoc2009-gui/tool.h	2009-07-13 19:53:53 UTC (rev 42452)
+++ tools/branches/gsoc2009-gui/tool.h	2009-07-13 21:20:24 UTC (rev 42453)
@@ -136,7 +136,9 @@
 	/** We don't take a single file, but an entire directory as input .*/
 	bool _inputFromDirectory;
 	/** Formats supported by this tool. */
-	AudioFormat _supported_formats;
+	AudioFormat _supportedFormats;
+	/** If this tool can display output progress in % */
+	bool _supportsProgressBar;
 
 	/** Name of the tool */
 	std::string _name;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list