Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

dialogs.cpp

00001 /*****************************************************************************
00002  * dialogs.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2003 the VideoLAN team
00005  * $Id: dialogs.cpp 12802 2005-10-09 17:57:58Z ipkiss $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *          Olivier Teulière <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 #include "dialogs.hpp"
00026 #include "../commands/async_queue.hpp"
00027 #include "../commands/cmd_change_skin.hpp"
00028 #include "../commands/cmd_quit.hpp"
00029 #include "../commands/cmd_playlist.hpp"
00030 #include "../commands/cmd_playtree.hpp"
00031 
00032 
00034 void Dialogs::showChangeSkinCB( intf_dialog_args_t *pArg )
00035 {
00036     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
00037 
00038     if( pArg->i_results )
00039     {
00040         if( pArg->psz_results[0] )
00041         {
00042             // Create a change skin command
00043             CmdChangeSkin *pCmd =
00044                 new CmdChangeSkin( pIntf, pArg->psz_results[0] );
00045 
00046             // Push the command in the asynchronous command queue
00047             AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
00048             pQueue->remove( "change skin" );
00049             pQueue->push( CmdGenericPtr( pCmd ) );
00050         }
00051     }
00052     else if( !pIntf->p_sys->p_theme )
00053     {
00054         // If no theme is already loaded, it's time to quit!
00055         CmdQuit *pCmd = new CmdQuit( pIntf );
00056         AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
00057         pQueue->push( CmdGenericPtr( pCmd ) );
00058     }
00059 }
00060 
00061 
00062 void Dialogs::showPlaylistLoadCB( intf_dialog_args_t *pArg )
00063 {
00064     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
00065 
00066     if( pArg->i_results && pArg->psz_results[0] )
00067     {
00068         // Create a Playlist Load command
00069         CmdPlaylistLoad *pCmd =
00070             new CmdPlaylistLoad( pIntf, pArg->psz_results[0] );
00071 
00072         // Push the command in the asynchronous command queue
00073         AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
00074         pQueue->remove( "load playlist" );
00075         pQueue->remove( "load playtree" );
00076         pQueue->push( CmdGenericPtr( pCmd ) );
00077     }
00078 }
00079 
00080 
00081 void Dialogs::showPlaylistSaveCB( intf_dialog_args_t *pArg )
00082 {
00083     intf_thread_t *pIntf = (intf_thread_t *)pArg->p_arg;
00084 
00085     if( pArg->i_results && pArg->psz_results[0] )
00086     {
00087         // Create a Playlist Save command
00088         CmdPlaylistSave *pCmd =
00089             new CmdPlaylistSave( pIntf, pArg->psz_results[0] );
00090 
00091         // Push the command in the asynchronous command queue
00092         AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
00093         pQueue->remove( "load playlist" );
00094         pQueue->remove( "load playtree" );
00095         pQueue->push( CmdGenericPtr( pCmd ) );
00096     }
00097 }
00098 
00099 
00101 static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
00102                         vlc_value_t old_val, vlc_value_t new_val, void *param )
00103 {
00104     Dialogs *p_dialogs = (Dialogs *)param;
00105     p_dialogs->showPopupMenu( new_val.b_bool != 0 );
00106 
00107     return VLC_SUCCESS;
00108 }
00109 
00110 
00111 Dialogs::Dialogs( intf_thread_t *pIntf ):
00112     SkinObject( pIntf ), m_pProvider( NULL ), m_pModule( NULL )
00113 {
00114 }
00115 
00116 
00117 Dialogs::~Dialogs()
00118 {
00119     if( m_pProvider && m_pModule )
00120     {
00121         // Detach the dialogs provider from its parent interface
00122         vlc_object_detach( m_pProvider );
00123 
00124         module_Unneed( m_pProvider, m_pModule );
00125         vlc_object_destroy( m_pProvider );
00126     }
00127 
00128     /* Unregister callbacks */
00129     var_DelCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
00130                      PopupMenuCB, this );
00131 }
00132 
00133 
00134 Dialogs *Dialogs::instance( intf_thread_t *pIntf )
00135 {
00136     if( ! pIntf->p_sys->p_dialogs )
00137     {
00138         Dialogs *pDialogs = new Dialogs( pIntf );
00139         if( pDialogs->init() )
00140         {
00141             // Initialization succeeded
00142             pIntf->p_sys->p_dialogs = pDialogs;
00143         }
00144         else
00145         {
00146             // Initialization failed
00147             delete pDialogs;
00148         }
00149     }
00150     return pIntf->p_sys->p_dialogs;
00151 }
00152 
00153 
00154 void Dialogs::destroy( intf_thread_t *pIntf )
00155 {
00156     if( pIntf->p_sys->p_dialogs )
00157     {
00158         delete pIntf->p_sys->p_dialogs;
00159         pIntf->p_sys->p_dialogs = NULL;
00160     }
00161 }
00162 
00163 
00164 bool Dialogs::init()
00165 {
00166     // Allocate descriptor
00167     m_pProvider = (intf_thread_t *)vlc_object_create( getIntf(),
00168                                                       VLC_OBJECT_DIALOGS );
00169     if( m_pProvider == NULL )
00170     {
00171         msg_Err( getIntf(), "out of memory" );
00172         return false;
00173     }
00174 
00175     m_pModule = module_Need( m_pProvider, "dialogs provider", NULL, 0 );
00176     if( m_pModule == NULL )
00177     {
00178         msg_Err( getIntf(), "No suitable dialogs provider found (hint: compile the wxWidgets plugin, and make sure it is loaded properly)" );
00179         vlc_object_destroy( m_pProvider );
00180         m_pProvider = NULL;
00181         return false;
00182     }
00183 
00184     // Attach the dialogs provider to its parent interface
00185     vlc_object_attach( m_pProvider, getIntf() );
00186 
00187     // Initialize dialogs provider
00188     // (returns as soon as initialization is done)
00189     if( m_pProvider->pf_run )
00190     {
00191         m_pProvider->pf_run( m_pProvider );
00192     }
00193 
00194     /* Register callback for the intf-popupmenu variable */
00195     var_AddCallback( getIntf()->p_sys->p_playlist, "intf-popupmenu",
00196                      PopupMenuCB, this );
00197 
00198     return true;
00199 }
00200 
00201 
00202 void Dialogs::showFileGeneric( const string &rTitle, const string &rExtensions,
00203                                DlgCallback callback, int flags )
00204 {
00205     if( m_pProvider && m_pProvider->pf_show_dialog )
00206     {
00207         intf_dialog_args_t *p_arg =
00208             (intf_dialog_args_t *)malloc( sizeof(intf_dialog_args_t) );
00209         memset( p_arg, 0, sizeof(intf_dialog_args_t) );
00210 
00211         p_arg->psz_title = strdup( rTitle.c_str() );
00212         p_arg->psz_extensions = strdup( rExtensions.c_str() );
00213 
00214         p_arg->b_save = flags & kSAVE;
00215         p_arg->b_multiple = flags & kMULTIPLE;
00216 
00217         p_arg->p_arg = getIntf();
00218         p_arg->pf_callback = callback;
00219 
00220         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_GENERIC,
00221                                      0, p_arg );
00222     }
00223 }
00224 
00225 
00226 void Dialogs::showChangeSkin()
00227 {
00228     showFileGeneric( _("Open a skin file"),
00229                      _("Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml"),
00230                      showChangeSkinCB, kOPEN );
00231 }
00232 
00233 
00234 void Dialogs::showPlaylistLoad()
00235 {
00236     showFileGeneric( _("Open playlist"),
00237                      _("All playlists|*.pls;*.m3u;*.asx;*.b4s|M3U files|*.m3u"),
00238                      showPlaylistLoadCB, kOPEN );
00239 }
00240 
00241 
00242 void Dialogs::showPlaylistSave()
00243 {
00244     showFileGeneric( _("Save playlist"), _("M3U file|*.m3u"),
00245                      showPlaylistSaveCB, kSAVE );
00246 }
00247 
00248 
00249 void Dialogs::showFileSimple( bool play )
00250 {
00251     if( m_pProvider && m_pProvider->pf_show_dialog )
00252     {
00253         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE_SIMPLE,
00254                                      (int)play, 0 );
00255     }
00256 }
00257 
00258 
00259 void Dialogs::showFile( bool play )
00260 {
00261     if( m_pProvider && m_pProvider->pf_show_dialog )
00262     {
00263         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILE,
00264                                      (int)play, 0 );
00265     }
00266 }
00267 
00268 
00269 void Dialogs::showDirectory( bool play )
00270 {
00271     if( m_pProvider && m_pProvider->pf_show_dialog )
00272     {
00273         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DIRECTORY,
00274                                      (int)play, 0 );
00275     }
00276 }
00277 
00278 
00279 void Dialogs::showDisc( bool play )
00280 {
00281     if( m_pProvider && m_pProvider->pf_show_dialog )
00282     {
00283         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_DISC,
00284                                      (int)play, 0 );
00285     }
00286 }
00287 
00288 
00289 void Dialogs::showNet( bool play )
00290 {
00291     if( m_pProvider && m_pProvider->pf_show_dialog )
00292     {
00293         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_NET,
00294                                      (int)play, 0 );
00295     }
00296 }
00297 
00298 
00299 void Dialogs::showMessages()
00300 {
00301     if( m_pProvider && m_pProvider->pf_show_dialog )
00302     {
00303         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_MESSAGES, 0, 0 );
00304     }
00305 }
00306 
00307 
00308 void Dialogs::showPrefs()
00309 {
00310     if( m_pProvider && m_pProvider->pf_show_dialog )
00311     {
00312         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_PREFS, 0, 0 );
00313     }
00314 }
00315 
00316 
00317 void Dialogs::showFileInfo()
00318 {
00319     if( m_pProvider && m_pProvider->pf_show_dialog )
00320     {
00321         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_FILEINFO, 0, 0 );
00322     }
00323 }
00324 
00325 
00326 void Dialogs::showStreamingWizard()
00327 {
00328     if( m_pProvider && m_pProvider->pf_show_dialog )
00329     {
00330         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_WIZARD, 0, 0 );
00331     }
00332 }
00333 
00334 
00335 void Dialogs::showPopupMenu( bool bShow )
00336 {
00337     if( m_pProvider && m_pProvider->pf_show_dialog )
00338     {
00339         m_pProvider->pf_show_dialog( m_pProvider, INTF_DIALOG_POPUPMENU,
00340                                      (int)bShow, 0 );
00341     }
00342 }
00343 

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2