]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/src/dialogs.cpp
* modules/gui/wxwindows/*: enable popup menu support in the "dialogs provider".
[vlc] / modules / gui / skins / src / dialogs.cpp
index b44e7a2da936ee6cd3979a509ac00a2a902d6de4..cd23ca5703ae74dc52ce98ab83aef45e1df7e2ae 100644 (file)
-/*****************************************************************************\r
- * dialogs.cpp: Handles all the different dialog boxes we provide.\r
- *****************************************************************************\r
- * Copyright (C) 2003 VideoLAN\r
- * $Id: dialogs.cpp,v 1.1 2003/06/03 22:20:00 gbazin Exp $\r
- *\r
- * Authors: Olivier Teulière <ipkiss@via.ecp.fr>\r
- *          Emmanuel Puig    <karibu@via.ecp.fr>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,\r
- * USA.\r
- *****************************************************************************/\r
-\r
-//--- VLC -------------------------------------------------------------------\r
-#include <vlc/vlc.h>\r
-#include <vlc/intf.h>\r
-\r
-//--- SKIN ------------------------------------------------------------------\r
-#include "../os_api.h"\r
-#include "event.h"\r
-#include "banks.h"\r
-#include "theme.h"\r
-#include "../os_theme.h"\r
-#include "themeloader.h"\r
-#include "window.h"\r
-#include "vlcproc.h"\r
-#include "skin_common.h"\r
-#include "dialogs.h"\r
-\r
-#ifdef BASIC_SKINS\r
-\r
-// Constructor\r
-Dialogs::Dialogs( intf_thread_t *_p_intf ){}\r
-// Destructor\r
-Dialogs::~Dialogs(){}\r
-\r
-void Dialogs::ShowOpen( bool b_play ){}\r
-void Dialogs::ShowMessages(){}\r
-void Dialogs::ShowPrefs(){}\r
-void Dialogs::ShowFileInfo(){}\r
-\r
-#else // BASIC_SKINS\r
-\r
-#include "../../wxwindows/wxwindows.h"\r
-#include "share/vlc32x32.xpm"       // include the graphic icon\r
-\r
-#define ShowOpen_Event     0\r
-#define ShowMessages_Event 1\r
-#define ShowPrefs_Event    2\r
-#define ShowFileInfo_Event 3\r
-#define ExitThread_Event   99\r
-\r
-//---------------------------------------------------------------------------\r
-// Local classes declarations.\r
-//---------------------------------------------------------------------------\r
-\r
-DEFINE_EVENT_TYPE(wxEVT_DIALOG)\r
-\r
-class Instance: public wxApp\r
-{\r
-public:\r
-    Instance();\r
-#ifdef GTK2_SKINS\r
-    Instance( intf_thread_t *_p_intf, CallBackObjects *callback );\r
-#else\r
-    Instance( intf_thread_t *_p_intf );\r
-#endif\r
-\r
-    bool OnInit();\r
-    int  OnExit();\r
-\r
-private:\r
-    intf_thread_t *p_intf;\r
-\r
-#ifdef GTK2_SKINS\r
-    CallBackObjects *callbackobj;\r
-#endif\r
-\r
-    DECLARE_EVENT_TABLE();\r
-};\r
-\r
-BEGIN_EVENT_TABLE(Instance, wxApp)\r
-    EVT_COMMAND(ShowOpen_Event, wxEVT_DIALOG, Dialogs::OnShowOpen)\r
-    EVT_COMMAND(ShowMessages_Event, wxEVT_DIALOG, Dialogs::OnShowMessages)\r
-    EVT_COMMAND(ShowPrefs_Event, wxEVT_DIALOG, Dialogs::OnShowPrefs)\r
-    EVT_COMMAND(ShowFileInfo_Event, wxEVT_DIALOG, Dialogs::OnShowFileInfo)\r
-    EVT_COMMAND(ExitThread_Event, wxEVT_DIALOG, Dialogs::OnExitThread)\r
-END_EVENT_TABLE()\r
-\r
-//---------------------------------------------------------------------------\r
-// Implementation of Instance class\r
-//---------------------------------------------------------------------------\r
-Instance::Instance( )\r
-{\r
-}\r
-\r
-#ifdef GTK2_SKINS\r
-Instance::Instance( intf_thread_t *_p_intf, CallBackObjects *callback )\r
-{\r
-    // Initialization\r
-    p_intf = _p_intf;\r
-    callbackobj = callback;\r
-}\r
-#else\r
-Instance::Instance( intf_thread_t *_p_intf )\r
-{\r
-    // Initialization\r
-    p_intf = _p_intf;\r
-}\r
-#endif\r
-\r
-IMPLEMENT_APP_NO_MAIN(Instance)\r
-\r
-bool Instance::OnInit()\r
-{\r
-    p_intf->p_sys->p_icon = new wxIcon( vlc_xpm );\r
-\r
-#ifdef GTK2_SKINS\r
-    // Set event callback. Yes, it's a big hack ;)\r
-    gdk_event_handler_set( GTK2Proc, (gpointer)callbackobj, NULL );\r
-#endif\r
-\r
-    // Create all the dialog boxes\r
-    p_intf->p_sys->p_dialogs->OpenDlg =\r
-        new OpenDialog( p_intf, NULL, FILE_ACCESS );\r
-    p_intf->p_sys->p_dialogs->MessagesDlg = new Messages( p_intf, NULL );\r
-    p_intf->p_sys->p_dialogs->PrefsDlg = new PrefsDialog( p_intf, NULL );\r
-    p_intf->p_sys->p_dialogs->FileInfoDlg = new FileInfo( p_intf, NULL );\r
-\r
-#ifdef GTK2_SKINS\r
-    // Add timer\r
-    g_timeout_add( 200, (GSourceFunc)RefreshTimer, (gpointer)p_intf );\r
-#endif\r
-\r
-    // OK, initialization is over, now the other thread can go on working...\r
-    vlc_thread_ready( p_intf );\r
-\r
-    return TRUE;\r
-}\r
-\r
-int Instance::OnExit()\r
-{\r
-    // Delete evertything\r
-    delete p_intf->p_sys->p_dialogs->FileInfoDlg;\r
-    delete p_intf->p_sys->p_dialogs->PrefsDlg;\r
-    delete p_intf->p_sys->p_dialogs->MessagesDlg;\r
-    delete p_intf->p_sys->p_dialogs->OpenDlg;\r
-    delete p_intf->p_sys->p_icon;\r
-\r
-    return 0;\r
-}\r
-\r
-//---------------------------------------------------------------------------\r
-#if !defined(__BUILTIN__) && defined( WIN32 )\r
-HINSTANCE hInstance = 0;\r
-extern "C" BOOL WINAPI\r
-DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)\r
-{\r
-    hInstance = (HINSTANCE)hModule;\r
-    return TRUE;\r
-}\r
-#endif\r
-\r
-//---------------------------------------------------------------------------\r
-// Thread callback\r
-// We create all wxWindows dialogs in a separate thread because we don't want\r
-// any interaction with our own message loop\r
-//---------------------------------------------------------------------------\r
-void SkinsDialogsThread( intf_thread_t *p_intf )\r
-{\r
-#if !defined( WIN32 )\r
-    static char  *p_args[] = { "" };\r
-#endif\r
-\r
-    /* Hack to pass the p_intf pointer to the new wxWindow Instance object */\r
-    wxTheApp = new Instance( p_intf );\r
-\r
-#if defined( WIN32 )\r
-#if !defined(__BUILTIN__)\r
-    wxEntry( hInstance/*GetModuleHandle(NULL)*/, NULL, NULL, SW_SHOW, TRUE );\r
-#else\r
-    wxEntry( GetModuleHandle( NULL ), NULL, NULL, SW_SHOW, TRUE );\r
-#endif\r
-#else\r
-    wxEntry( 1, p_args );\r
-#endif\r
-\r
-    return;\r
-}\r
-\r
-//---------------------------------------------------------------------------\r
-// Implementation of Dialogs class\r
-//---------------------------------------------------------------------------\r
-Dialogs::Dialogs( intf_thread_t *_p_intf )\r
-{\r
-    p_intf = _p_intf;\r
-    p_intf->p_sys->p_dialogs = this;\r
-\r
-    // Create a new thread for wxWindows\r
-    if( vlc_thread_create( p_intf, "Skins Dialogs Thread", SkinsDialogsThread,\r
-                           0, VLC_TRUE ) )\r
-    {\r
-        OpenDlg = NULL;\r
-        msg_Err( p_intf, "cannot create SkinsDialogsThread" );\r
-    }\r
-}\r
-\r
-Dialogs::~Dialogs()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ExitThread_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-\r
-    vlc_thread_join( p_intf ); //FIXME, use own vlc_object\r
-}\r
-\r
-void Dialogs::ShowOpen( bool b_play )\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowOpen_Event );\r
-    event.SetClientData( this );\r
-    event.SetInt( b_play );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowMessages()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowMessages_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowPrefs()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowPrefs_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::ShowFileInfo()\r
-{\r
-    wxCommandEvent event( wxEVT_DIALOG, ShowFileInfo_Event );\r
-    event.SetClientData( this );\r
-\r
-    wxTheApp->AddPendingEvent( event );\r
-}\r
-\r
-void Dialogs::OnShowOpen( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    bool b_play = event.GetInt() ? TRUE : FALSE;\r
-\r
-    //p_dialogs->OpenDlg->Show( !p_dialogs->OpenDlg->IsShown() );\r
\r
-    if( p_dialogs->OpenDlg->ShowModal() != wxID_OK )\r
-    {\r
-        return;\r
-    }\r
-\r
-    // Check if playlist is available\r
-    playlist_t *p_playlist = p_dialogs->p_intf->p_sys->p_playlist;\r
-    if( p_playlist == NULL )\r
-    {\r
-        return;\r
-    }\r
-\r
-    if( b_play )\r
-    {\r
-        // Append and play\r
-        for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )\r
-        {\r
-            playlist_Add( p_playlist,\r
-                (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),\r
-                PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO), PLAYLIST_END );\r
-        }\r
-        p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "play" )->SendEvent();\r
-    }\r
-    else\r
-    {\r
-        // Append only\r
-        for( size_t i = 0; i < p_dialogs->OpenDlg->mrl.GetCount(); i++ )\r
-        {\r
-            playlist_Add( p_playlist,\r
-                (const char *)p_dialogs->OpenDlg->mrl[i].mb_str(),\r
-                PLAYLIST_APPEND, PLAYLIST_END );\r
-        }\r
-    }\r
-\r
-    // Refresh interface !\r
-    p_dialogs->p_intf->p_sys->p_theme->EvtBank->Get( "playlist_refresh" )\r
-        ->PostSynchroMessage();\r
-\r
-    return;\r
-}\r
-\r
-void Dialogs::OnShowMessages( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    p_dialogs->MessagesDlg->Show( !p_dialogs->MessagesDlg->IsShown() );\r
-}\r
-\r
-void Dialogs::OnShowPrefs( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    p_dialogs->PrefsDlg->Show( !p_dialogs->PrefsDlg->IsShown() );\r
-}\r
-\r
-void Dialogs::OnShowFileInfo( wxCommandEvent& event )\r
-{\r
-    Dialogs *p_dialogs = (Dialogs *)event.GetClientData();\r
-    p_dialogs->FileInfoDlg->Show( !p_dialogs->FileInfoDlg->IsShown() );\r
-}\r
-\r
-void Dialogs::OnExitThread( wxCommandEvent& event )\r
-{\r
-    wxTheApp->ExitMainLoop();\r
-}\r
-#endif // BASIC_SKINS\r
+/*****************************************************************************
+ * dialogs.cpp: Handles all the different dialog boxes we provide.
+ *****************************************************************************
+ * Copyright (C) 2003 VideoLAN
+ * $Id: dialogs.cpp,v 1.11 2003/07/17 18:58:23 gbazin Exp $
+ *
+ * Authors: Gildas Bazin <gbazin@netcourrier.com>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA  02111,
+ * USA.
+ *****************************************************************************/
+
+//--- VLC -------------------------------------------------------------------
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
+
+//--- SKIN ------------------------------------------------------------------
+#include "../os_api.h"
+#include "event.h"
+#include "banks.h"
+#include "theme.h"
+#include "../os_theme.h"
+#include "themeloader.h"
+#include "window.h"
+#include "vlcproc.h"
+#include "skin_common.h"
+#include "dialogs.h"
+
+/* Callback prototype */
+static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
+                       vlc_value_t old_val, vlc_value_t new_val, void *param );
+
+//---------------------------------------------------------------------------
+// Implementation of Dialogs class
+//---------------------------------------------------------------------------
+Dialogs::Dialogs( intf_thread_t *_p_intf )
+{
+    /* Errors while loading the dialogs provider are not fatal.
+     * Dialogs just won't be available. */
+
+    p_intf = _p_intf;
+    p_intf->p_sys->p_dialogs = this;
+    b_popup_change = VLC_FALSE;
+
+    /* Allocate descriptor */
+    p_provider = (intf_thread_t *)vlc_object_create( p_intf, VLC_OBJECT_INTF );
+    if( p_provider == NULL )
+    {
+        msg_Err( p_intf, "out of memory" );
+        return;
+    }
+
+    p_module = module_Need( p_provider, "dialogs provider", NULL );
+    if( p_module == NULL )
+    {
+        msg_Err( p_intf, "no suitable dialogs provider found" );
+        vlc_object_destroy( p_provider );
+        p_provider = NULL;
+        return;
+    }
+
+    /* Initialize dialogs provider
+     * (returns as soon as initialization is done) */
+    if( p_provider->pf_run ) p_provider->pf_run( p_provider );
+
+    /* Register callback for the intf-popupmenu variable */
+    playlist_t *p_playlist =
+        (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
+                                       FIND_ANYWHERE );
+    if( p_playlist != NULL )
+    {
+        var_AddCallback( p_playlist, "intf-popupmenu", PopupMenuCB,
+                         p_intf->p_sys->p_dialogs );
+        vlc_object_release( p_playlist );
+    }
+}
+
+Dialogs::~Dialogs()
+{
+    if( p_provider && p_module )
+    {
+        module_Unneed( p_provider, p_module );
+        vlc_object_destroy( p_provider );
+    }
+}
+
+void Dialogs::ShowDialog( intf_thread_t *p_intf, int i_dialog_event,
+                          int i_arg )
+{
+}
+
+void Dialogs::ShowOpen( bool b_play )
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE, b_play );
+}
+
+void Dialogs::ShowOpenSkin()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILE, 0 );
+}
+
+void Dialogs::ShowMessages()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_MESSAGES, 0 );
+}
+
+void Dialogs::ShowPrefs()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_PREFS, 0 );
+}
+
+void Dialogs::ShowFileInfo()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_FILEINFO, 0 );
+}
+
+void Dialogs::ShowPopup()
+{
+    if( p_provider && p_provider->pf_show_dialog )
+        p_provider->pf_show_dialog( p_provider, INTF_DIALOG_POPUPMENU, 0 );
+}
+
+/*****************************************************************************
+ * PopupMenuCB: callback triggered by the intf-popupmenu playlist variable.
+ *  We don't show the menu directly here because we don't want the
+ *  caller to block for a too long time.
+ *****************************************************************************/
+static int PopupMenuCB( vlc_object_t *p_this, const char *psz_variable,
+                        vlc_value_t old_val, vlc_value_t new_val, void *param )
+{
+    Dialogs *p_dialogs = (Dialogs *)param;
+    p_dialogs->ShowPopup();
+
+    return VLC_SUCCESS;
+}