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

Remere at users.sourceforge.net Remere at users.sourceforge.net
Fri Jun 19 19:28:18 CEST 2009


Revision: 41678
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41678&view=rev
Author:   Remere
Date:     2009-06-19 17:28:18 +0000 (Fri, 19 Jun 2009)

Log Message:
-----------
*Added an advanced page for choosing tool manually.
*Added a class to represent a useable tool that contains info about input files, supported audio formats etc.
*ScummToolsFrame now remembers prior pages and can return to them at any time, removes the need for an explicit ::onPrevious handler for almost all pages.

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

Added Paths:
-----------
    tools/branches/gsoc2009-gui/gui/tools.cpp
    tools/branches/gsoc2009-gui/gui/tools.h

Modified: tools/branches/gsoc2009-gui/gui/configuration.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/configuration.h	2009-06-19 17:03:28 UTC (rev 41677)
+++ tools/branches/gsoc2009-gui/gui/configuration.h	2009-06-19 17:28:18 UTC (rev 41678)
@@ -23,6 +23,8 @@
 #ifndef CONFIGURATION_H
 #define CONFIGURATION_H
 
+#include <wx/string.h>
+
 struct Configuration {
 	Configuration();
 	
@@ -30,6 +32,7 @@
 	// this class is just a glorified map with different types, so it seems
 	// unnecessary.
 
+	bool advanced;
 	bool compressing;
 	wxString selectedGame;
 	wxString selectedTool;
@@ -38,6 +41,7 @@
 inline Configuration::Configuration() {
 	// Default values for all the settings
 
+	advanced = false;
 	compressing = false;
 
 	selectedGame = wxT("");

Modified: tools/branches/gsoc2009-gui/gui/main.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.cpp	2009-06-19 17:03:28 UTC (rev 41677)
+++ tools/branches/gsoc2009-gui/gui/main.cpp	2009-06-19 17:28:18 UTC (rev 41678)
@@ -110,6 +110,11 @@
 	_buttons->setPage(introPage);
 }
 
+ScummToolsFrame::~ScummToolsFrame() {
+	for(std::vector<WizardPageClass *>::iterator iter = _previousPages.begin(); iter != _previousPages.end(); ++iter)
+		delete *iter;
+}
+
 void ScummToolsFrame::SwitchPage(WizardPage *next) {
 	// Find the old page
 	WizardPage *old = dynamic_cast<WizardPage*>(_wizardpane->FindWindow(wxT("Wizard Page")));
@@ -118,6 +123,9 @@
 
 	old->save(configuration);
 
+	// Save the old page
+	_previousPages.push_back(old->getClass());
+
 	// Destroy the old page
 	old->Destroy();
 
@@ -135,6 +143,13 @@
 	_buttons->setPage(next);
 }
 
+void ScummToolsFrame::SwitchToPreviousPage() {
+	WizardPage *prev = _previousPages.back()->create(_wizardpane);
+	delete _previousPages.back();
+	_previousPages.pop_back();
+	SwitchPage(prev);
+}
+
 BEGIN_EVENT_TABLE(WizardButtons, wxPanel)
 	EVT_BUTTON(ID_NEXT, WizardButtons::onClickNext)
 	EVT_BUTTON(ID_PREV, WizardButtons::onClickPrevious)

Modified: tools/branches/gsoc2009-gui/gui/main.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.h	2009-06-19 17:03:28 UTC (rev 41677)
+++ tools/branches/gsoc2009-gui/gui/main.h	2009-06-19 17:28:18 UTC (rev 41678)
@@ -24,10 +24,12 @@
 #define GUI_MAIN_H
 
 #include <wx/wx.h>
+#include <vector>
 
 #include "configuration.h"
 
 class WizardButtons;
+struct WizardPageClass;
 class WizardPage;
 
 enum GUI_ID {
@@ -43,14 +45,20 @@
 {
 public:
 	ScummToolsFrame(const wxString &title, const wxPoint &pos, const wxSize &size);
+	~ScummToolsFrame();
 
 	// Switches to this page and resets the buttons
 	void SwitchPage(WizardPage *nextPage);
 
+	// Switches to the previous page
+	void SwitchToPreviousPage();
+
 private:
 	Configuration configuration;
 	wxPanel *_wizardpane;
 	WizardButtons *_buttons;
+	
+	std::vector<WizardPageClass *> _previousPages;
 
 	DECLARE_EVENT_TABLE()
 };

Modified: tools/branches/gsoc2009-gui/gui/pages.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.cpp	2009-06-19 17:03:28 UTC (rev 41677)
+++ tools/branches/gsoc2009-gui/gui/pages.cpp	2009-06-19 17:28:18 UTC (rev 41678)
@@ -32,11 +32,10 @@
 
 #include "main.h"
 #include "pages.h"
+#include "tools.h"
 
 WizardPage::WizardPage(wxWindow *parent)
 	: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("Wizard Page")),
-	  _nextPage(NULL),
-	  _prevPage(NULL),
 	  _buttons(NULL)
 {
 }
@@ -65,7 +64,24 @@
 	}
 }
 
-// Our default handler for cancel
+// Our default handler for next/prev/cancel
+
+void WizardPage::onNext() {
+}
+
+void WizardPage::onPrevious() {
+	wxWindow *grandparent = GetParent();
+	while(grandparent->GetParent() != NULL)
+		grandparent = grandparent->GetParent();
+
+	if(grandparent) {
+		ScummToolsFrame *frame = dynamic_cast<ScummToolsFrame*>(grandparent);
+		frame->SwitchToPreviousPage();
+		// We are probably dead now, make sure to do nothing 
+		// involving member variabls after this point
+	}
+}
+
 void WizardPage::onCancel() {
 	wxMessageDialog dlg(this, wxT("Are you sure you want to abort the wizard?"), wxT("Abort"), wxYES | wxNO);
 	wxWindowID ret = dlg.ShowModal();
@@ -109,10 +125,11 @@
 	
 	wxString choices[] = {
 		wxT("Extract from game data files"),
-		wxT("Compress audio files")
+		wxT("Compress audio files"),
+		wxT("Choose tool to use (advanced)")
 	};
 
-	_options = new wxRadioBox(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 2, choices, 1, wxRA_SPECIFY_COLS | wxBORDER_NONE);
+	_options = new wxRadioBox(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 3, choices, 1, wxRA_SPECIFY_COLS | wxBORDER_NONE);
 	sizer->Add(_options);
 	_options->SetSelection(0);
 
@@ -125,26 +142,35 @@
 }
 
 void IntroPage::load(Configuration &config) {
-	if(config.compressing)
+	// TODO use generic way to get indexes
+	if(config.advanced)
+		_options->SetSelection(2);
+	else if(config.compressing)
 		_options->SetSelection(1);
+	else
+		_options->SetSelection(0);
 }
 
 void IntroPage::save(Configuration &config) {
+	config.advanced    = _options->GetStringSelection().Lower().Find(wxT("advanced")) != wxNOT_FOUND;
 	config.compressing = _options->GetStringSelection().Lower().Find(wxT("extract")) == wxNOT_FOUND;
 }
 
 void IntroPage::onNext() {
 	if(_options->GetStringSelection().Lower().Find(wxT("extract")) != wxNOT_FOUND) {
 		// extract
+	} else if(_options->GetStringSelection().Lower().Find(wxT("advanced")) != wxNOT_FOUND) {
+		// advanced
+		SwitchPage(new ChooseToolPage(this->GetParent()));
 	} else {
 		// compress
-		SwitchPage(new CompressionPage(this->GetParent()));
+		SwitchPage(new ChooseCompressionPage(this->GetParent()));
 	}
 }
 
-// Page to choose compression tool
+// Page to choose what game files to compress
 
-CompressionPage::CompressionPage(wxWindow *parent)
+ChooseCompressionPage::ChooseCompressionPage(wxWindow *parent)
 	: WizardPage(parent)
 {
 	wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
@@ -160,6 +186,8 @@
 	// Many games use the same tool internally, and are grouped by tool used here
 	// the array is ordered before being displayed, though
 
+	// TODO: This should be moved to tools.cpp and stored in each tool instead
+
 	// compress_agos
 	choices.Add(wxT("Feeble Files")),
 	choices.Add(wxT("Simon the Sorcerer I/II")),
@@ -178,8 +206,7 @@
 
 	// compress_saga
 	choices.Add(wxT("SAGA: Inherit The Earth")),
-	choices.Add(wxT("I Have No Mouth")),
-	choices.Add(wxT("I Must Scream")),
+	choices.Add(wxT("I Have No Mouth and I Must Scream")),
 
 	// compress_scumm_bun
 	choices.Add(wxT("The Secret of Monkey Island")),
@@ -213,19 +240,48 @@
 	SetAlignedSizer(sizer);
 }
 
-void CompressionPage::onPrevious() {
-	// It's kinda ugly that we must know the type here, would be better
-	// if we could infer previous page automatically, somehow, possibly
-	// templates + inheritence could solve this?
-	SwitchPage(new IntroPage(this->GetParent()));
-}
 
-
 // Load/Save settings
-void CompressionPage::load(Configuration &config) {
+void ChooseCompressionPage::load(Configuration &config) {
 	_game->SetStringSelection(config.selectedGame);
 }
 
-void CompressionPage::save(Configuration &config) {
+void ChooseCompressionPage::save(Configuration &config) {
 	config.selectedGame = _game->GetStringSelection();
 }
+
+// Page to choose ANY tool to use
+
+ChooseToolPage::ChooseToolPage(wxWindow *parent)
+	: WizardPage(parent)
+{
+	wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
+
+	sizer->AddSpacer(15);
+
+	sizer->Add(new wxStaticText(this, wxID_ANY, 
+		wxT("Select what tool you'd like to use.")));
+	
+	// This list is most likely incomplete
+	wxArrayString choices = g_tools.getToolList();
+
+	// Sort the array for display (it should actually always be sorted since 
+	// they're stored in a ordered tree but you can never be too safe)
+	choices.Sort();
+
+	_tool = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
+	sizer->Add(_tool);
+	_tool->SetSelection(0);
+
+	SetAlignedSizer(sizer);
+}
+
+
+// Load/Save settings
+void ChooseToolPage::load(Configuration &config) {
+	_tool->SetStringSelection(config.selectedTool);
+}
+
+void ChooseToolPage::save(Configuration &config) {
+	config.selectedTool = _tool->GetStringSelection();
+}

Modified: tools/branches/gsoc2009-gui/gui/pages.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.h	2009-06-19 17:03:28 UTC (rev 41677)
+++ tools/branches/gsoc2009-gui/gui/pages.h	2009-06-19 17:28:18 UTC (rev 41678)
@@ -24,6 +24,15 @@
 
 #include "configuration.h"
 
+struct WizardPageClass {
+	virtual WizardPage *create(wxWindow *parent) = 0;
+};
+
+template <typename T>
+struct WizardPageClass_ : public WizardPageClass {
+	virtual WizardPage *create(wxWindow *parent) {return new T(parent);}
+};
+
 // Wizard Page
 // A page in the extraction wizard
 
@@ -32,6 +41,7 @@
 public:
 	WizardPage(wxWindow *parent);
 	virtual void updateButtons();
+	virtual WizardPageClass *getClass() = 0;
 
 	// This adds an offset (about 100px) to the left of the sizer
 	// to center the text somewhat, before adding it to the panel
@@ -48,16 +58,14 @@
 	
 	// Event handlers
 	// overload these to handle prev/next/cancel clicks
-	virtual void onNext() {}
-	virtual void onPrevious() {}
+	virtual void onNext();
+	virtual void onPrevious();
 	virtual void onCancel(); // Default is to display 'Are you sure' and quit if you click 'Yes'
 
 	// Calls updateButtons
 	void onUpdateButtons(WizardButtons *buttons);
 
 protected:
-	WizardPage *_nextPage;
-	WizardPage *_prevPage;
 	WizardButtons *_buttons;
 };
 
@@ -68,6 +76,8 @@
 public:
 	IntroPage(wxWindow *parent);
 	virtual void updateButtons();
+	virtual WizardPageClass *getClass() {return new WizardPageClass_<IntroPage>();}
+	
 
 	void load(Configuration &configuration);
 	void save(Configuration &configuration);
@@ -78,16 +88,28 @@
 	wxRadioBox *_options;
 };
 
-class CompressionPage : public WizardPage
+class ChooseCompressionPage : public WizardPage
 {
 public:
-	CompressionPage(wxWindow *parent);
+	ChooseCompressionPage(wxWindow *parent);
+	virtual WizardPageClass *getClass() {return new WizardPageClass_<ChooseCompressionPage>();}
 
 	void load(Configuration &configuration);
 	void save(Configuration &configuration);
 
-	virtual void onPrevious();
-
 protected:
 	wxChoice *_game;
 };
+
+class ChooseToolPage : public WizardPage
+{
+public:
+	ChooseToolPage(wxWindow *parent);
+	virtual WizardPageClass *getClass() {return new WizardPageClass_<ChooseToolPage>();}
+
+	void load(Configuration &configuration);
+	void save(Configuration &configuration);
+
+protected:
+	wxChoice *_tool;
+};

Added: tools/branches/gsoc2009-gui/gui/tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.cpp	                        (rev 0)
+++ tools/branches/gsoc2009-gui/gui/tools.cpp	2009-06-19 17:28:18 UTC (rev 41678)
@@ -0,0 +1,110 @@
+/* tools.cpp - List & description of all supported tools
+ * Copyright (C) 2009 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL
+ * $Id
+ *
+ */
+
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+	#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+	#include "wx/wx.h"
+#endif
+
+#include "tools.h"
+
+Tools g_tools;
+
+Tools::Tools() {
+
+	// Compress agos also has a --mac parameter, need to add an additional page / option for this
+	Tool compress_agos(wxT("compress_agos"), wxT("*."));
+	addTool(compress_agos);
+
+	Tool compress_gob(wxT("compress_gob"), wxT("*.*"));
+	addTool(compress_gob);
+
+	Tool compress_kyra(wxT("compress_kyra"), wxT("*.*"));
+	addTool(compress_kyra);
+}
+
+void Tools::addTool(const Tool& tool) {
+	tools[tool._name] = tool;
+}
+
+wxArrayString Tools::getToolList() {
+	wxArrayString l;
+	for(std::map<wxString, Tool>::const_iterator iter = tools.begin(); iter != tools.end(); ++iter)
+		l.Add(iter->first);
+	return l;
+}
+
+const Tool &Tools::operator[](const wxString& name) {
+	std::map<wxString, Tool>::const_iterator iter = tools.find(name);
+
+	wxASSERT_MSG(iter != tools.end(), wxT("All tools should be added, never try to access a tool that does not exist."));
+
+	return iter->second;
+}
+
+
+// The Tool class
+
+Tool::Tool() {
+	// should never be called
+	// required for std::map template to work
+	wxLogError(wxT("Created empty tool, should never happened."));
+}
+
+Tool::Tool(wxString name, wxString input_extensions) {
+	_name = name;
+	
+	// Sensible defaults
+	_supportedFormats = AUDIO_ALL;
+	ToolInput input;
+	input._extension = input_extensions;
+	input._file = true;
+	_inputs.push_back(input);
+}
+
+bool Tool::supportsAudioFormat(AudioFormat format) {
+	return (_supportedFormats & format) == format;
+}
+
+bool Tool::pickFiles() {
+	for(ToolInputs::const_iterator iter = _inputs.begin(); iter != _inputs.end(); ++iter)
+		if(iter->_file)
+			return true;
+	return false;
+}
+
+bool Tool::pickDirs() {
+	return !pickFiles();
+}
+
+wxString Tool::getExecutable() {
+#ifdef WIN32
+	return _name + wxT(".exe");
+#else
+	return _name;
+#endif
+}


Property changes on: tools/branches/gsoc2009-gui/gui/tools.cpp
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native

Added: tools/branches/gsoc2009-gui/gui/tools.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.h	                        (rev 0)
+++ tools/branches/gsoc2009-gui/gui/tools.h	2009-06-19 17:28:18 UTC (rev 41678)
@@ -0,0 +1,86 @@
+/* tools.h - List & description of all supported tools
+ * Copyright (C) 2009 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL
+ * $Id
+ *
+ */
+
+#ifndef TOOLS_H
+#define TOOLS_H
+
+#include <wx/string.h>
+
+#include <map>
+#include <vector>
+
+// Different audio formats
+// They're used for bitwise operations
+enum AudioFormat {
+	AUDIO_VORBIS = 1,
+	AUDIO_FLAC = 2,
+	AUDIO_MP3 = 4,
+	AUDIO_ALL = AUDIO_VORBIS | AUDIO_FLAC | AUDIO_MP3
+};
+
+
+// Describes a possible input to the tool (since some take two seperate files, 
+// some a dir and some a single file
+struct ToolInput {
+	wxString _extension;
+	bool _file; // dir otherwise
+};
+
+// A tool, contains all info necessary to run it
+class Tool {
+public:
+	Tool();
+	Tool(wxString name, wxString input_extensions = wxT("*.*"));
+
+	// Helpfer functions to get info about the tool
+	bool supportsAudioFormat(AudioFormat format);
+	bool pickFiles();
+	bool pickDirs();
+	wxString getExecutable();
+
+
+	wxString _name;
+	AudioFormat _supportedFormats;
+	typedef std::vector<ToolInput> ToolInputs;
+	ToolInputs _inputs;
+};
+
+// Collection of all tools
+class Tools {
+public:
+	Tools();
+
+	const Tool &operator[](const wxString &name);
+
+	// Returns all tool names in a list
+	// conveinent for creating the choose tool page
+	wxArrayString getToolList();
+
+protected:
+	void addTool(const Tool &tool);
+
+	std::map<wxString, Tool> tools;
+};
+
+extern Tools g_tools;
+
+#endif


Property changes on: tools/branches/gsoc2009-gui/gui/tools.h
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Date Rev Author URL Id
Added: svn:eol-style
   + native


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