From 974efa126bb149d1a219b62c2ff13230a205839b Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Fri, 7 Mar 2008 02:32:29 +0000 Subject: [PATCH] Modified all providers to separate them between factory and factory manager. This will make plugin system easier. Also, made hunspell register manually as well. Originally committed to SVN as r1946. --- aegisub/audio_display.cpp | 10 +- aegisub/audio_player.cpp | 16 +-- aegisub/audio_player.h | 18 ++-- aegisub/audio_player_dsound.h | 1 - aegisub/audio_provider.cpp | 10 +- aegisub/audio_provider.h | 21 ++-- aegisub/audio_provider_avs.h | 1 - aegisub/dialog_options.cpp | 8 +- aegisub/dialog_spellchecker.cpp | 2 +- aegisub/dialog_style_editor.cpp | 2 +- aegisub/factory_manager.h | 107 +++++++++++++++++++++ aegisub/options.cpp | 10 +- aegisub/plugin_manager.cpp | 10 +- aegisub/spellchecker.cpp | 16 ++- aegisub/spellchecker.h | 20 ++-- aegisub/spellchecker_hunspell.cpp | 38 +------- aegisub/spellchecker_hunspell.h | 82 ++++++++++++++++ aegisub/subs_edit_ctrl.cpp | 2 +- aegisub/subs_preview.cpp | 2 +- aegisub/subtitle_format_dvd.cpp | 2 +- aegisub/subtitles_provider.cpp | 13 +-- aegisub/subtitles_provider.h | 19 ++-- aegisub/subtitles_provider_csri.h | 1 - aegisub/video_context.cpp | 4 +- aegisub/video_provider.cpp | 12 +-- aegisub/video_provider.h | 22 +++-- aegisub/video_provider_avs.h | 1 - aegisub/video_provider_dshow.h | 1 - build/aegisub_vs2008/aegisub_vs2008.vcproj | 9 +- 29 files changed, 325 insertions(+), 135 deletions(-) create mode 100644 aegisub/factory_manager.h create mode 100644 aegisub/spellchecker_hunspell.h diff --git a/aegisub/audio_display.cpp b/aegisub/audio_display.cpp index 1b3a3058e..714f6da6a 100644 --- a/aegisub/audio_display.cpp +++ b/aegisub/audio_display.cpp @@ -878,15 +878,15 @@ void AudioDisplay::SetFile(wxString file) { is_dummy = true; provider = new DummyAudioProvider(150*60*1000, true); // 150 minutes noise } else { - provider = AudioProviderFactory::GetAudioProvider(file); + provider = AudioProviderFactoryManager::GetAudioProvider(file); } #else - provider = AudioProviderFactory::GetAudioProvider(file); + provider = AudioProviderFactoryManager::GetAudioProvider(file); #endif // Get player wxLogDebug(_T("AudioDisplay::SetFile: get audio player")); - player = AudioPlayerFactory::GetAudioPlayer(); + player = AudioPlayerFactoryManager::GetAudioPlayer(); player->SetDisplayTimer(&UpdateTimer); player->SetProvider(provider); player->OpenStream(); @@ -1022,12 +1022,12 @@ void AudioDisplay::Play(int start,int end) { try { // Get provider if (!VideoContext::Get()->videoName.StartsWith(_T("?dummy"))) - provider = AudioProviderFactory::GetAudioProvider(VideoContext::Get()->videoName, 0); + provider = AudioProviderFactoryManager::GetAudioProvider(VideoContext::Get()->videoName, 0); else return; // Get player - player = AudioPlayerFactory::GetAudioPlayer(); + player = AudioPlayerFactoryManager::GetAudioPlayer(); player->SetDisplayTimer(&UpdateTimer); player->SetProvider(provider); player->OpenStream(); diff --git a/aegisub/audio_player.cpp b/aegisub/audio_player.cpp index ec71f70f0..37a0114ab 100644 --- a/aegisub/audio_player.cpp +++ b/aegisub/audio_player.cpp @@ -126,7 +126,7 @@ void AudioPlayer::OnStopAudio(wxCommandEvent &event) { ////////////// // Get player -AudioPlayer* AudioPlayerFactory::GetAudioPlayer() { +AudioPlayer* AudioPlayerFactoryManager::GetAudioPlayer() { // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Audio player"))); @@ -152,26 +152,26 @@ AudioPlayer* AudioPlayerFactory::GetAudioPlayer() { ////////////////////////// // Register all factories -void AudioPlayerFactory::RegisterProviders() { +void AudioPlayerFactoryManager::RegisterProviders() { #ifdef WITH_ALSA - new AlsaPlayerFactory(); + RegisterFactory(new AlsaPlayerFactory(),_T("ALSA")); #endif #ifdef WITH_DIRECTSOUND - new DirectSoundPlayerFactory(); + RegisterFactory(new DirectSoundPlayerFactory(),_T("DirectSound")); #endif #ifdef WITH_OPENAL - new OpenALPlayerFactory(); + RegisterFactory(new OpenALPlayerFactory(),_T("OpenAL")); #endif #ifdef WITH_PORTAUDIO - new PortAudioPlayerFactory(); + RegisterFactory(new PortAudioPlayerFactory(),_T("PortAudio")); #endif #ifdef WITH_PULSEAUDIO - new PulseAudioPlayerFactory(); + RegisterFactory(new PulseAudioPlayerFactory(),_T("PulseAudio")); #endif } ////////// // Static -template std::map* AegisubFactory::factories=NULL; +template std::map* FactoryManager::factories=NULL; diff --git a/aegisub/audio_player.h b/aegisub/audio_player.h index d9fe29a0b..ae4c6ae68 100644 --- a/aegisub/audio_player.h +++ b/aegisub/audio_player.h @@ -44,7 +44,7 @@ #include #include #include -#include "factory.h" +#include "factory_manager.h" ////////////// @@ -96,18 +96,22 @@ public: /////////// // Factory -class AudioPlayerFactory : public AegisubFactory { -protected: - virtual AudioPlayer *CreatePlayer()=0; - AudioPlayerFactory(wxString name) { RegisterFactory(name); } - +class AudioPlayerFactory { +public: + virtual AudioPlayer *CreatePlayer()=0; +}; + + +/////////////////// +// Factory Manager +class AudioPlayerFactoryManager : public FactoryManager { public: - virtual ~AudioPlayerFactory() {} static AudioPlayer *GetAudioPlayer(); static void RegisterProviders(); }; + ///////// // Event DECLARE_EVENT_TYPE(wxEVT_STOP_AUDIO, -1) diff --git a/aegisub/audio_player_dsound.h b/aegisub/audio_player_dsound.h index 105d2833c..6643413fc 100644 --- a/aegisub/audio_player_dsound.h +++ b/aegisub/audio_player_dsound.h @@ -137,7 +137,6 @@ public: class DirectSoundPlayerFactory : public AudioPlayerFactory { public: AudioPlayer *CreatePlayer() { return new DirectSoundPlayer(); } - DirectSoundPlayerFactory() : AudioPlayerFactory(_T("dsound")) {} }; #endif diff --git a/aegisub/audio_provider.cpp b/aegisub/audio_provider.cpp index 15e76c29d..c70261499 100644 --- a/aegisub/audio_provider.cpp +++ b/aegisub/audio_provider.cpp @@ -191,7 +191,7 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, //////////////// // Get provider -AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cache) { +AudioProvider *AudioProviderFactoryManager::GetAudioProvider(wxString filename, int cache) { // Prepare provider AudioProvider *provider = NULL; @@ -254,16 +254,16 @@ AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cac /////////////////////////// // Register all providers -void AudioProviderFactory::RegisterProviders() { +void AudioProviderFactoryManager::RegisterProviders() { #ifdef WITH_AVISYNTH - new AvisynthAudioProviderFactory(); + RegisterFactory(new AvisynthAudioProviderFactory(),_T("Avisynth")); #endif #ifdef WITH_FFMPEG - new LAVCAudioProviderFactory(); + RegisterFactory(new LAVCAudioProviderFactory(),_T("FFMPEG")); #endif } ////////// // Static -template std::map* AegisubFactory::factories=NULL; +template std::map* FactoryManager::factories=NULL; diff --git a/aegisub/audio_provider.h b/aegisub/audio_provider.h index 6a1d39b83..0f6e3eee1 100644 --- a/aegisub/audio_provider.h +++ b/aegisub/audio_provider.h @@ -41,7 +41,7 @@ // Headers #include #include -#include "factory.h" +#include "factory_manager.h" ////////////// @@ -84,13 +84,16 @@ public: /////////// // Factory -class AudioProviderFactory : public AegisubFactory { -protected: - virtual AudioProvider *CreateProvider(wxString filename)=0; - AudioProviderFactory(wxString name) { RegisterFactory(name); } - +class AudioProviderFactory { public: - virtual ~AudioProviderFactory() {} - static AudioProvider *GetAudioProvider(wxString filename, int cache=-1); - static void RegisterProviders(); + virtual AudioProvider *CreateProvider(wxString filename)=0; +}; + + +/////////////////// +// Factory Manager +class AudioProviderFactoryManager : public FactoryManager { +public: + static void RegisterProviders(); + static AudioProvider *GetAudioProvider(wxString filename, int cache=-1); }; diff --git a/aegisub/audio_provider_avs.h b/aegisub/audio_provider_avs.h index 1699f8e42..3c29c9471 100644 --- a/aegisub/audio_provider_avs.h +++ b/aegisub/audio_provider_avs.h @@ -71,7 +71,6 @@ public: class AvisynthAudioProviderFactory : public AudioProviderFactory { public: AudioProvider *CreateProvider(wxString file) { return new AvisynthAudioProvider(file); } - AvisynthAudioProviderFactory() : AudioProviderFactory(_T("avisynth")) {} }; #endif diff --git a/aegisub/dialog_options.cpp b/aegisub/dialog_options.cpp index dce9abe5a..c949f575e 100644 --- a/aegisub/dialog_options.cpp +++ b/aegisub/dialog_options.cpp @@ -390,12 +390,12 @@ DialogOptions::DialogOptions(wxWindow *parent) // Second sizer videoSizer4->Add(new wxStaticText(videoPage,-1,_("Video provider: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10); - wxArrayString choices4 = VideoProviderFactory::GetFactoryList(); + wxArrayString choices4 = VideoProviderFactoryManager::GetFactoryList(); control = new wxComboBox(videoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,choices4,wxCB_DROPDOWN | wxCB_READONLY); Bind(control,_T("Video provider"),1); videoSizer4->Add(control,1,wxEXPAND); videoSizer4->Add(new wxStaticText(videoPage,-1,_("Subtitles provider: ")),0,wxALIGN_CENTER_VERTICAL | wxRIGHT,10); - wxArrayString choices5 = SubtitlesProviderFactory::GetFactoryList(); + wxArrayString choices5 = SubtitlesProviderFactoryManager::GetFactoryList(); control = new wxComboBox(videoPage,-1,_T(""),wxDefaultPosition,wxDefaultSize,choices5,wxCB_DROPDOWN | wxCB_READONLY); Bind(control,_T("Subtitles provider"),1); videoSizer4->Add(control,1,wxEXPAND); @@ -529,8 +529,8 @@ DialogOptions::DialogOptions(wxWindow *parent) wxString choices3[3] = { _T("ConvertToMono"), _T("GetLeftChannel"), _T("GetRightChannel") }; #endif - AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio provider"),_T("Audio Provider"),AudioProviderFactory::GetFactoryList(),true,1); - AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio player"),_T("Audio Player"),AudioPlayerFactory::GetFactoryList(),true,1); + AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio provider"),_T("Audio Provider"),AudioProviderFactoryManager::GetFactoryList(),true,1); + AddComboControl(audioAdvPage,audioAdvSizer1,_("Audio player"),_T("Audio Player"),AudioPlayerFactoryManager::GetFactoryList(),true,1); AddComboControl(audioAdvPage,audioAdvSizer1,_("Cache type"),_T("Audio Cache"),wxArrayString(3,choices2),true); #ifdef WIN32 AddComboControl(audioAdvPage,audioAdvSizer1,_("Avisynth down-mixer"),_T("Audio Downmixer"),wxArrayString(3,choices3),false); diff --git a/aegisub/dialog_spellchecker.cpp b/aegisub/dialog_spellchecker.cpp index 9d83b3c77..1cc41b474 100644 --- a/aegisub/dialog_spellchecker.cpp +++ b/aegisub/dialog_spellchecker.cpp @@ -70,7 +70,7 @@ DialogSpellChecker::DialogSpellChecker(wxFrame *parent) SetIcon(BitmapToIcon(wxBITMAP(spellcheck_toolbutton))); // Get spell checker - spellchecker = SpellCheckerFactory::GetSpellChecker(); + spellchecker = SpellCheckerFactoryManager::GetSpellChecker(); if (!spellchecker) { wxMessageBox(_T("No spellchecker available."),_T("Error"),wxICON_ERROR); Destroy(); diff --git a/aegisub/dialog_style_editor.cpp b/aegisub/dialog_style_editor.cpp index 67ceacff6..d162f774a 100644 --- a/aegisub/dialog_style_editor.cpp +++ b/aegisub/dialog_style_editor.cpp @@ -299,7 +299,7 @@ DialogStyleEditor::DialogStyleEditor (wxWindow *parent, AssStyle *_style, Subtit // Preview SubsPreview = NULL; PreviewText = NULL; - if (SubtitlesProviderFactory::ProviderAvailable()) { + if (SubtitlesProviderFactoryManager::ProviderAvailable()) { PreviewText = new wxTextCtrl(this,TEXT_PREVIEW,Options.AsText(_T("Style editor preview text"))); previewButton = new ColourButton(this,BUTTON_PREVIEW_COLOR,wxSize(45,16),Options.AsColour(_T("Style editor preview background"))); SubsPreview = new SubtitlesPreview(this,-1,wxDefaultPosition,wxSize(100,60),wxSUNKEN_BORDER,Options.AsColour(_T("Style editor preview background"))); diff --git a/aegisub/factory_manager.h b/aegisub/factory_manager.h new file mode 100644 index 000000000..3a0fab148 --- /dev/null +++ b/aegisub/factory_manager.h @@ -0,0 +1,107 @@ +// Copyright (c) 2007-2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include +#include +#include + + +///////////////// +// Factory class +template +class FactoryManager { +protected: + // Static map of all factories + static std::map *factories; + + // Register one factory type (with possible subtypes) + static void RegisterFactory(T* factory,wxString name, wxArrayString subTypes=wxArrayString()) { + // Create factories if it doesn't exist + if (factories == NULL) factories = new std::map; + + // Prepare subtypes + if (subTypes.GetCount() == 0) subTypes.Add(_T("")); + else { + for (unsigned int i=0;iinsert(std::make_pair(name.Lower() + subTypes[i],factory)); + } + } + + // Get a factory with name + static T *GetFactory(wxString name) { + // No factories + if (factories == NULL) { + factories = new std::map; + return NULL; + } + + // Search for factory that matches + typename std::map::iterator cur; + for (cur = factories->begin();cur != factories->end();cur++) { + if (cur->first.StartsWith(name)) return cur->second; + } + + // None found + return NULL; + } + +public: + // Virtual destructor + virtual ~FactoryManager() {} + + // Get list of all factories, with favourite as first + static wxArrayString GetFactoryList(wxString favourite=_T("")) { + if (factories == NULL) factories = new std::map; + wxArrayString list; + favourite = favourite.Lower(); + for (typename std::map::iterator cur=factories->begin();cur!=factories->end();cur++) { + if (cur->first == favourite) list.Insert(cur->first,0); + else list.Add(cur->first); + } + return list; + } +}; diff --git a/aegisub/options.cpp b/aegisub/options.cpp index d2b316f92..f9c7eadd4 100644 --- a/aegisub/options.cpp +++ b/aegisub/options.cpp @@ -160,7 +160,11 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) { SetModificationType(MOD_VIDEO_RELOAD); SetInt(_T("Avisynth MemoryMax"),64,1700); SetBool(_T("Threaded Video"),false,1700); + #ifdef __WINDOWS__ SetText(_T("Video Provider"),_T("Avisynth"),1700); + #else + SetText(_T("Video Provider"),_T("FFMPEG"),1945); + #endif SetBool(_T("Allow Ancient Avisynth"),false,1700); SetText(_T("Avisynth subs renderer"),_T("vsfilter"),1700); SetBool(_T("Avisynth render own subs"),true,1700); @@ -190,13 +194,15 @@ void OptionsManager::LoadDefaults(bool onlyDefaults,bool doOverride) { SetModificationType(MOD_AUDIO_RELOAD); SetInt(_T("Audio Cache"),1,1700); #if defined(__WINDOWS__) - SetText(_T("Audio Player"),_T("dsound"),1700); + SetText(_T("Audio Player"),_T("DirectSound"),1945); + SetText(_T("Audio Provider"),_T("avisynth"),1700); #elif defined(__APPLE__) SetText(_T("Audio Player"), _T("openal")); + SetText(_T("Audio Provider"),_T("FFMPEG"),1945); #else SetText(_T("Audio Player"),_T("portaudio")); // FIXME: should this be something else? perhaps alsa on linux and portaudio on everything else? + SetText(_T("Audio Provider"),_T("FFMPEG"),1945); #endif - SetText(_T("Audio Provider"),_T("avisynth"),1700); // TODO: proper default on non-windows SetText(_T("Audio Downmixer"),_T("ConvertToMono"),1700); SetText(_T("Audio Alsa Device"), _T("plughw:0,0")); SetText(_T("Audio HD Cache Location"),_T("default"),1700); diff --git a/aegisub/plugin_manager.cpp b/aegisub/plugin_manager.cpp index 20aafe946..60a229fdf 100644 --- a/aegisub/plugin_manager.cpp +++ b/aegisub/plugin_manager.cpp @@ -41,6 +41,7 @@ #include "audio_provider.h" #include "audio_player.h" #include "subtitles_provider.h" +#include "spellchecker.h" /////////////// @@ -60,10 +61,11 @@ PluginManager::~PluginManager() { // Registers all built-in plugins void PluginManager::RegisterBuiltInPlugins() { if (!init) { - VideoProviderFactory::RegisterProviders(); - AudioProviderFactory::RegisterProviders(); - AudioPlayerFactory::RegisterProviders(); - SubtitlesProviderFactory::RegisterProviders(); + VideoProviderFactoryManager::RegisterProviders(); + AudioProviderFactoryManager::RegisterProviders(); + AudioPlayerFactoryManager::RegisterProviders(); + SubtitlesProviderFactoryManager::RegisterProviders(); + SpellCheckerFactoryManager::RegisterProviders(); } // Done diff --git a/aegisub/spellchecker.cpp b/aegisub/spellchecker.cpp index d02f80b7b..e30a2ad3f 100644 --- a/aegisub/spellchecker.cpp +++ b/aegisub/spellchecker.cpp @@ -37,12 +37,15 @@ /////////// // Headers #include "spellchecker.h" +#ifdef WITH_HUNSPELL +#include "spellchecker_hunspell.h" +#endif #include "options.h" ///////////////////// // Get spell checker -SpellChecker *SpellCheckerFactory::GetSpellChecker() { +SpellChecker *SpellCheckerFactoryManager::GetSpellChecker() { // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Spell Checker"))); @@ -66,6 +69,15 @@ SpellChecker *SpellCheckerFactory::GetSpellChecker() { } +////////////////////////// +// Register all providers +void SpellCheckerFactoryManager::RegisterProviders() { +#ifdef WITH_HUNSPELL + RegisterFactory(new HunspellSpellCheckerFactory(),_T("Hunspell")); +#endif +} + + ////////// // Static -template std::map* AegisubFactory::factories=NULL; +template std::map* FactoryManager::factories=NULL; diff --git a/aegisub/spellchecker.h b/aegisub/spellchecker.h index 71fa86acb..692fc1148 100644 --- a/aegisub/spellchecker.h +++ b/aegisub/spellchecker.h @@ -40,7 +40,7 @@ /////////// // Headers #include -#include "factory.h" +#include "factory_manager.h" /////////////////////////// @@ -63,12 +63,16 @@ public: /////////// // Factory -class SpellCheckerFactory : public AegisubFactory { -protected: - virtual SpellChecker *CreateSpellChecker()=0; - SpellCheckerFactory(wxString name) { RegisterFactory(name); } - +class SpellCheckerFactory { public: - virtual ~SpellCheckerFactory() {} - static SpellChecker *GetSpellChecker(); + virtual SpellChecker *CreateSpellChecker()=0; +}; + + +/////////////////// +// Factory Manager +class SpellCheckerFactoryManager : public FactoryManager { +public: + static SpellChecker *GetSpellChecker(); + static void RegisterProviders(); }; diff --git a/aegisub/spellchecker_hunspell.cpp b/aegisub/spellchecker_hunspell.cpp index 11c1f90e6..faf354167 100644 --- a/aegisub/spellchecker_hunspell.cpp +++ b/aegisub/spellchecker_hunspell.cpp @@ -39,7 +39,7 @@ #ifdef WITH_HUNSPELL -#include "spellchecker.h" +#include "spellchecker_hunspell.h" #include "standard_paths.h" #include "utils.h" #include "options.h" @@ -52,42 +52,6 @@ #include -////////////////// -// Hunspell class -class HunspellSpellChecker : public SpellChecker { -private: - Hunspell *hunspell; - wxCSConv *conv; - wxString affpath; - wxString dicpath; - wxString usrdicpath; - - void Reset(); - -public: - HunspellSpellChecker(); - ~HunspellSpellChecker(); - - void AddWord(wxString word); - bool CanAddWord(wxString word); - - bool CheckWord(wxString word); - wxArrayString GetSuggestions(wxString word); - - wxArrayString GetLanguageList(); - void SetLanguage(wxString language); -}; - - -/////////// -// Factory -class HunspellSpellCheckerFactory : public SpellCheckerFactory { -public: - SpellChecker *CreateSpellChecker() { return new HunspellSpellChecker(); } - HunspellSpellCheckerFactory() : SpellCheckerFactory(_T("hunspell")) {} -} registerHunspell; - - /////////////// // Constructor HunspellSpellChecker::HunspellSpellChecker() { diff --git a/aegisub/spellchecker_hunspell.h b/aegisub/spellchecker_hunspell.h new file mode 100644 index 000000000..bd98c902d --- /dev/null +++ b/aegisub/spellchecker_hunspell.h @@ -0,0 +1,82 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers + +#ifdef WITH_HUNSPELL + +#include "spellchecker.h" +#include +#include + + + +////////////////// +// Hunspell class +class HunspellSpellChecker : public SpellChecker { +private: + Hunspell *hunspell; + wxCSConv *conv; + wxString affpath; + wxString dicpath; + wxString usrdicpath; + + void Reset(); + +public: + HunspellSpellChecker(); + ~HunspellSpellChecker(); + + void AddWord(wxString word); + bool CanAddWord(wxString word); + + bool CheckWord(wxString word); + wxArrayString GetSuggestions(wxString word); + + wxArrayString GetLanguageList(); + void SetLanguage(wxString language); +}; + + +/////////// +// Factory +class HunspellSpellCheckerFactory : public SpellCheckerFactory { +public: + SpellChecker *CreateSpellChecker() { return new HunspellSpellChecker(); } +}; + +#endif diff --git a/aegisub/subs_edit_ctrl.cpp b/aegisub/subs_edit_ctrl.cpp index fc93a3c4a..4bec872bc 100644 --- a/aegisub/subs_edit_ctrl.cpp +++ b/aegisub/subs_edit_ctrl.cpp @@ -70,7 +70,7 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxWindowID id, const wxStri CmdKeyClear('U',wxSTC_SCMOD_CTRL); // Set spellchecker - spellchecker = SpellCheckerFactory::GetSpellChecker(); + spellchecker = SpellCheckerFactoryManager::GetSpellChecker(); // Set thesaurus thesaurus = Thesaurus::GetThesaurus(); diff --git a/aegisub/subs_preview.cpp b/aegisub/subs_preview.cpp index 7f85b2595..4dbb73611 100644 --- a/aegisub/subs_preview.cpp +++ b/aegisub/subs_preview.cpp @@ -143,7 +143,7 @@ void SubtitlesPreview::UpdateBitmap(int w,int h) { // Try to get subtitles provider SubtitlesProvider *provider = NULL; try { - provider = SubtitlesProviderFactory::GetProvider(); + provider = SubtitlesProviderFactoryManager::GetProvider(); } catch (...) { wxMessageBox(_T("Could not get any subtitles provider for the preview box. Make sure that you have a provider installed."),_T("No subtitles provider"),wxICON_ERROR); diff --git a/aegisub/subtitle_format_dvd.cpp b/aegisub/subtitle_format_dvd.cpp index c98132be4..b6a2a5216 100644 --- a/aegisub/subtitle_format_dvd.cpp +++ b/aegisub/subtitle_format_dvd.cpp @@ -97,7 +97,7 @@ void DVDSubtitleFormat::GetSubPictureList(std::vector &pics) { pics.resize(count); SubtitlesProvider *provider = NULL; - provider = SubtitlesProviderFactory::GetProvider(); + provider = SubtitlesProviderFactoryManager::GetProvider(); provider->LoadSubtitles(GetAssFile()); // Write lines diff --git a/aegisub/subtitles_provider.cpp b/aegisub/subtitles_provider.cpp index 59792158e..1960988d5 100644 --- a/aegisub/subtitles_provider.cpp +++ b/aegisub/subtitles_provider.cpp @@ -54,7 +54,7 @@ SubtitlesProvider::~SubtitlesProvider() { //////////////////////////////////////////////////////////////// // Check if provider available (doesn't verify provider works!) -bool SubtitlesProviderFactory::ProviderAvailable() { +bool SubtitlesProviderFactoryManager::ProviderAvailable() { // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider"))); @@ -65,7 +65,7 @@ bool SubtitlesProviderFactory::ProviderAvailable() { //////////////// // Get provider -SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { +SubtitlesProvider* SubtitlesProviderFactoryManager::GetProvider() { // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider"))); @@ -94,16 +94,17 @@ SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { ////////////////////// // Register providers -void SubtitlesProviderFactory::RegisterProviders() { +void SubtitlesProviderFactoryManager::RegisterProviders() { #ifdef WITH_CSRI - new CSRISubtitlesProviderFactory(); + CSRISubtitlesProviderFactory *csri = new CSRISubtitlesProviderFactory(); + RegisterFactory(csri,_T("CSRI"),csri->GetSubTypes()); #endif #ifdef WITH_LIBASS - new LibassSubtitlesProviderFactory(); + RegisterFactory(new LibassSubtitlesProviderFactory(),_T("libass")); #endif } ////////// // Static -template std::map* AegisubFactory::factories=NULL; +template std::map* FactoryManager::factories=NULL; diff --git a/aegisub/subtitles_provider.h b/aegisub/subtitles_provider.h index af320dca6..7781d7703 100644 --- a/aegisub/subtitles_provider.h +++ b/aegisub/subtitles_provider.h @@ -41,7 +41,7 @@ // Headers #include #include "video_frame.h" -#include "factory.h" +#include "factory_manager.h" ////////////// @@ -65,16 +65,19 @@ public: /////////// // Factory -class SubtitlesProviderFactory : public AegisubFactory { -protected: - virtual SubtitlesProvider *CreateProvider(wxString subType=_T(""))=0; - SubtitlesProviderFactory(wxString name,wxArrayString subTypes=wxArrayString()) { - RegisterFactory(name,subTypes); - } - +class SubtitlesProviderFactory { public: virtual ~SubtitlesProviderFactory() {} + virtual SubtitlesProvider *CreateProvider(wxString subType=_T(""))=0; +}; + + +/////////////////// +// Factory Manager +class SubtitlesProviderFactoryManager : public FactoryManager { +public: static SubtitlesProvider *GetProvider(); static void RegisterProviders(); static bool ProviderAvailable(); }; + diff --git a/aegisub/subtitles_provider_csri.h b/aegisub/subtitles_provider_csri.h index 003c16014..8a03f045f 100644 --- a/aegisub/subtitles_provider_csri.h +++ b/aegisub/subtitles_provider_csri.h @@ -75,7 +75,6 @@ class CSRISubtitlesProviderFactory : public SubtitlesProviderFactory { public: SubtitlesProvider *CreateProvider(wxString subType=_T("")) { return new CSRISubtitlesProvider(subType); } wxArrayString GetSubTypes(); - CSRISubtitlesProviderFactory() : SubtitlesProviderFactory(_T("csri"),GetSubTypes()) {} }; #endif diff --git a/aegisub/video_context.cpp b/aegisub/video_context.cpp index a76d3600e..2d066e793 100644 --- a/aegisub/video_context.cpp +++ b/aegisub/video_context.cpp @@ -329,13 +329,13 @@ void VideoContext::SetVideo(const wxString &filename) { #endif // Choose a provider - provider = VideoProviderFactory::GetProvider(filename,overFps); + provider = VideoProviderFactoryManager::GetProvider(filename,overFps); loaded = provider != NULL; // Get subtitles provider try { subsProvider = provider->GetAsSubtitlesProvider(); - if (!subsProvider) subsProvider = SubtitlesProviderFactory::GetProvider(); + if (!subsProvider) subsProvider = SubtitlesProviderFactoryManager::GetProvider(); } catch (wxString err) { wxMessageBox(_T("Error while loading subtitles provider: ") + err,_T("Subtitles provider")); } catch (const wchar_t *err) { wxMessageBox(_T("Error while loading subtitles provider: ") + wxString(err),_T("Subtitles provider")); } diff --git a/aegisub/video_provider.cpp b/aegisub/video_provider.cpp index 92486d464..b70cb339f 100644 --- a/aegisub/video_provider.cpp +++ b/aegisub/video_provider.cpp @@ -55,7 +55,7 @@ //////////////// // Get provider -VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) { +VideoProvider *VideoProviderFactoryManager::GetProvider(wxString video,double fps) { // First check special case of dummy video if (video.StartsWith(_T("?dummy:"))) { return new DummyVideoProvider(video, fps); @@ -93,19 +93,19 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) { ////////////////////////// // Register all providers -void VideoProviderFactory::RegisterProviders() { +void VideoProviderFactoryManager::RegisterProviders() { #ifdef WITH_AVISYNTH - new AvisynthVideoProviderFactory(); + RegisterFactory(new AvisynthVideoProviderFactory(),_T("Avisynth")); #endif #ifdef WITH_DIRECTSHOW - new DirectShowVideoProviderFactory(); + RegisterFactory(new DirectShowVideoProviderFactory(),_T("DirectShow")); #endif #ifdef WITH_FFMPEG - new LAVCVideoProviderFactory(); + RegisterFactory(new LAVCVideoProviderFactory(),_T("FFMPEG")); #endif } ////////// // Static -template std::map* AegisubFactory::factories=NULL; +template std::map* FactoryManager::factories=NULL; diff --git a/aegisub/video_provider.h b/aegisub/video_provider.h index 49a4bdded..c8ce3af59 100644 --- a/aegisub/video_provider.h +++ b/aegisub/video_provider.h @@ -41,7 +41,7 @@ // Headers #include #include "video_frame.h" -#include "factory.h" +#include "factory_manager.h" ////////////// @@ -86,14 +86,16 @@ public: /////////// // Factory -class VideoProviderFactory : public AegisubFactory { -protected: - virtual VideoProvider *CreateProvider(wxString video,double fps=0.0)=0; - VideoProviderFactory(wxString name) { RegisterFactory(name); } - +class VideoProviderFactory { public: - virtual ~VideoProviderFactory() {} - static VideoProvider *GetProvider(wxString video,double fps=0.0); - - static void RegisterProviders(); + virtual VideoProvider *CreateProvider(wxString video,double fps=0.0)=0; +}; + + +/////////////////// +// Factory Manager +class VideoProviderFactoryManager : public FactoryManager { +public: + static void RegisterProviders(); + static VideoProvider *GetProvider(wxString video,double fps=0.0); }; diff --git a/aegisub/video_provider_avs.h b/aegisub/video_provider_avs.h index 963afb445..efdd17600 100644 --- a/aegisub/video_provider_avs.h +++ b/aegisub/video_provider_avs.h @@ -101,7 +101,6 @@ public: class AvisynthVideoProviderFactory : public VideoProviderFactory { public: VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new AvisynthVideoProvider(video,fps); } - AvisynthVideoProviderFactory() : VideoProviderFactory(_T("avisynth")) {} }; diff --git a/aegisub/video_provider_dshow.h b/aegisub/video_provider_dshow.h index f8cc29a5b..a774bd0df 100644 --- a/aegisub/video_provider_dshow.h +++ b/aegisub/video_provider_dshow.h @@ -124,7 +124,6 @@ public: class DirectShowVideoProviderFactory : public VideoProviderFactory { public: VideoProvider *CreateProvider(wxString video,double fps=0.0) { return new DirectShowVideoProvider(video,fps); } - DirectShowVideoProviderFactory() : VideoProviderFactory(_T("dshow")) {} }; #endif diff --git a/build/aegisub_vs2008/aegisub_vs2008.vcproj b/build/aegisub_vs2008/aegisub_vs2008.vcproj index a284007a6..cde59070a 100644 --- a/build/aegisub_vs2008/aegisub_vs2008.vcproj +++ b/build/aegisub_vs2008/aegisub_vs2008.vcproj @@ -222,10 +222,11 @@ OpenMP="true" UsePrecompiledHeader="2" PrecompiledHeaderThrough="stdwx.h" + ProgramDataBaseFileName="$(IntDir)\vc90.pdb" WarningLevel="3" WarnAsError="true" Detect64BitPortabilityProblems="false" - DebugInformationFormat="3" + DebugInformationFormat="0" DisableSpecificWarnings="4267" ForcedIncludeFiles="stdwx.h;config.h" /> @@ -917,7 +918,7 @@ > + +