diff --git a/aegisub/Makefile.am b/aegisub/Makefile.am index 8ae3c2da4..f68c907ca 100644 --- a/aegisub/Makefile.am +++ b/aegisub/Makefile.am @@ -231,6 +231,7 @@ aegisub_SOURCES = \ mkv_wrap.cpp \ mythes.cxx \ options.cpp \ + plugin_manager.cpp \ scintilla_text_ctrl.cpp \ spellchecker.cpp \ spline.cpp \ diff --git a/aegisub/audio_player.cpp b/aegisub/audio_player.cpp index ea2f4b6f6..ec71f70f0 100644 --- a/aegisub/audio_player.cpp +++ b/aegisub/audio_player.cpp @@ -127,12 +127,6 @@ void AudioPlayer::OnStopAudio(wxCommandEvent &event) { ////////////// // Get player AudioPlayer* AudioPlayerFactory::GetAudioPlayer() { - // Register factories - // HACK: fix me - static bool init = false; - if (!init) RegisterFactories(); - init = true; - // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Audio player"))); @@ -158,7 +152,7 @@ AudioPlayer* AudioPlayerFactory::GetAudioPlayer() { ////////////////////////// // Register all factories -void AudioPlayerFactory::RegisterFactories() { +void AudioPlayerFactory::RegisterProviders() { #ifdef WITH_ALSA new AlsaPlayerFactory(); #endif diff --git a/aegisub/audio_player.h b/aegisub/audio_player.h index 4190e4ee8..d9fe29a0b 100644 --- a/aegisub/audio_player.h +++ b/aegisub/audio_player.h @@ -104,7 +104,7 @@ protected: public: virtual ~AudioPlayerFactory() {} static AudioPlayer *GetAudioPlayer(); - static void RegisterFactories(); + static void RegisterProviders(); }; diff --git a/aegisub/audio_provider.cpp b/aegisub/audio_provider.cpp index 500baafb3..15e76c29d 100644 --- a/aegisub/audio_provider.cpp +++ b/aegisub/audio_provider.cpp @@ -192,12 +192,6 @@ void AudioProvider::GetAudioWithVolume(void *buf, int64_t start, int64_t count, //////////////// // Get provider AudioProvider *AudioProviderFactory::GetAudioProvider(wxString filename, int cache) { - // Initialize providers - // HACK: fixme - static bool init = false; - if (!init) RegisterProviders(); - init = true; - // Prepare provider AudioProvider *provider = NULL; diff --git a/aegisub/main.cpp b/aegisub/main.cpp index ab78a5052..3eb2400ac 100644 --- a/aegisub/main.cpp +++ b/aegisub/main.cpp @@ -65,6 +65,7 @@ #include "auto4_base.h" #endif #include "version.h" +#include "plugin_manager.h" /////////////////// @@ -156,11 +157,9 @@ bool AegisubApp::OnInit() { locale.Init(wxLANGUAGE_DEFAULT); #endif - // Set association -#ifndef _DEBUG - StartupLog(_T("Install file type associations")); - RegistryAssociate(); -#endif + // Load plugins + plugins = new PluginManager(); + plugins->RegisterBuiltInPlugins(); // Load Automation scripts #ifdef WITH_AUTOMATION @@ -172,6 +171,12 @@ bool AegisubApp::OnInit() { StartupLog(_T("Prepare export filters")); AssExportFilterChain::PrepareFilters(); + // Set association +#ifndef _DEBUG + StartupLog(_T("Install file type associations")); + RegistryAssociate(); +#endif + // Get parameter subs StartupLog(_T("Parse command line")); wxArrayString subs; @@ -205,6 +210,7 @@ bool AegisubApp::OnInit() { int AegisubApp::OnExit() { SubtitleFormat::DestroyFormats(); VideoContext::Clear(); + delete plugins; Options.Clear(); #ifdef WITH_AUTOMATION delete global_scripts; diff --git a/aegisub/main.h b/aegisub/main.h index fa8da8744..94722ca6e 100644 --- a/aegisub/main.h +++ b/aegisub/main.h @@ -51,6 +51,7 @@ ////////////// // Prototypes class FrameMain; +class PluginManager; namespace Automation4 { class AutoloadScriptManager; } @@ -58,6 +59,8 @@ namespace Automation4 { class AutoloadScriptManager; } // Application class definition class AegisubApp: public wxApp { private: + PluginManager *plugins; + void OnMouseWheel(wxMouseEvent &event); void OnKey(wxKeyEvent &key); diff --git a/aegisub/plugin_manager.cpp b/aegisub/plugin_manager.cpp new file mode 100644 index 000000000..20aafe946 --- /dev/null +++ b/aegisub/plugin_manager.cpp @@ -0,0 +1,71 @@ +// 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 +#include "plugin_manager.h" +#include "video_provider.h" +#include "audio_provider.h" +#include "audio_player.h" +#include "subtitles_provider.h" + + +/////////////// +// Constructor +PluginManager::PluginManager() { + init = false; +} + + +////////////// +// Destructor +PluginManager::~PluginManager() { +} + + +////////////////////////////////// +// Registers all built-in plugins +void PluginManager::RegisterBuiltInPlugins() { + if (!init) { + VideoProviderFactory::RegisterProviders(); + AudioProviderFactory::RegisterProviders(); + AudioPlayerFactory::RegisterProviders(); + SubtitlesProviderFactory::RegisterProviders(); + } + + // Done + init = true; +} diff --git a/aegisub/plugin_manager.h b/aegisub/plugin_manager.h new file mode 100644 index 000000000..74b994c87 --- /dev/null +++ b/aegisub/plugin_manager.h @@ -0,0 +1,51 @@ +// 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 +// + + +#pragma once + + +//////////////////////// +// Plugin manager class +class PluginManager { +private: + bool init; + +public: + PluginManager(); + ~PluginManager(); + + void RegisterBuiltInPlugins(); +}; diff --git a/aegisub/subtitles_provider.cpp b/aegisub/subtitles_provider.cpp index fa71a6044..59792158e 100644 --- a/aegisub/subtitles_provider.cpp +++ b/aegisub/subtitles_provider.cpp @@ -66,12 +66,6 @@ bool SubtitlesProviderFactory::ProviderAvailable() { //////////////// // Get provider SubtitlesProvider* SubtitlesProviderFactory::GetProvider() { - // Register them - // HACK: fix me - static bool init = false; - if (!init) RegisterProviders(); - init = true; - // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Subtitles provider"))); diff --git a/aegisub/video_provider.cpp b/aegisub/video_provider.cpp index e0bcd1200..92486d464 100644 --- a/aegisub/video_provider.cpp +++ b/aegisub/video_provider.cpp @@ -61,12 +61,6 @@ VideoProvider *VideoProviderFactory::GetProvider(wxString video,double fps) { return new DummyVideoProvider(video, fps); } - // Register the first time - // HACK: move this into program initialization later - static bool init = false; - if (!init) RegisterProviders(); - init = true; - // List of providers wxArrayString list = GetFactoryList(Options.AsText(_T("Video provider"))); diff --git a/build/aegisub_vs2008/aegisub_vs2008.vcproj b/build/aegisub_vs2008/aegisub_vs2008.vcproj index d08d6f47e..a284007a6 100644 --- a/build/aegisub_vs2008/aegisub_vs2008.vcproj +++ b/build/aegisub_vs2008/aegisub_vs2008.vcproj @@ -1444,6 +1444,14 @@ RelativePath="..\..\aegisub\options.h" > + + + +