]> git.sesse.net Git - vlc/blobdiff - modules/gui/skins/src/skin_main.cpp
* all: don't use input_OffsetToTime anymore.
[vlc] / modules / gui / skins / src / skin_main.cpp
index 617ff7690e00a5100544850ffdde59bcf7873fc2..1c9868357032a84cc06776d398d6d3bd5438336e 100644 (file)
@@ -2,7 +2,7 @@
  * skin-main.cpp: skins plugin for VLC
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: skin_main.cpp,v 1.24 2003/05/02 15:53:32 gbazin Exp $
+ * $Id$
  *
  * Authors: Olivier Teulière <ipkiss@via.ecp.fr>
  *          Emmanuel Puig    <karibu@via.ecp.fr>
 #include <vlc/intf.h>
 #include <vlc/aout.h>
 
-//--- GENERAL ---------------------------------------------------------------
-#ifndef BASIC_SKINS
-#include <wx/wx.h>
-#endif
-
 //--- SKIN ------------------------------------------------------------------
 #include "../os_api.h"
 #include "event.h"
 #include "themeloader.h"
 #include "vlcproc.h"
 #include "skin_common.h"
-#ifndef BASIC_SKINS
-#include "wxdialogs.h"
-#endif
+#include "dialogs.h"
 
 #ifdef X11_SKINS
 #include <X11/Xlib.h>
+#include <Imlib2.h>
 #endif
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 intf_thread_t *g_pIntf;
 
-//---------------------------------------------------------------------------
-// Exported interface functions.
-//---------------------------------------------------------------------------
-#ifdef WIN32
-extern "C" __declspec( dllexport )
-    int __VLC_SYMBOL( vlc_entry ) ( module_t *p_module );
-#endif
-
 //---------------------------------------------------------------------------
 // Local prototypes.
 //---------------------------------------------------------------------------
@@ -84,6 +70,12 @@ static int Open ( vlc_object_t *p_this )
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     g_pIntf = p_intf;
 
+#if defined X11_SKINS
+    // Open/Test for an X11 display
+    Display *display = XOpenDisplay( NULL );
+    if( !display ) return VLC_EGENERIC;
+#endif
+
     // Allocate instance and initialize some members
     p_intf->p_sys = (intf_sys_t *) malloc( sizeof( intf_sys_t ) );
     if( p_intf->p_sys == NULL )
@@ -94,7 +86,6 @@ static int Open ( vlc_object_t *p_this )
 
     p_intf->pf_run = Run;
 
-
     // Suscribe to messages bank
     p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
 
@@ -105,25 +96,59 @@ static int Open ( vlc_object_t *p_this )
     p_intf->p_sys->i_index        = -1;
     p_intf->p_sys->i_size         = 0;
 
+    p_intf->p_sys->b_on_top = false;
+
     p_intf->p_sys->i_close_status = VLC_NOTHING;
 
     p_intf->p_sys->p_input = NULL;
     p_intf->p_sys->p_playlist = (playlist_t *)vlc_object_find( p_intf,
         VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
 
-#ifdef GTK2_SKINS
-    // Initialize GDK
-    int    i_args   = 3;
-    char  *p_args[] = { "", "", "--sync", NULL };
-    char **pp_args  = p_args;
-
-    gdk_init( &i_args, &pp_args );
-
-#elif defined X11_SKINS
+#if defined X11_SKINS
     // Initialize X11
-    p_intf->p_sys->display = XOpenDisplay( NULL );
+    p_intf->p_sys->display = display;
+    vlc_mutex_init( p_intf, &p_intf->p_sys->xlock );
+    // Fake window to receive broadcast events
+    Window root = DefaultRootWindow( display );
+    p_intf->p_sys->mainWin = XCreateSimpleWindow( display, root, 0, 0,
+                                                  1, 1, 0, 0, 0 );
+    XStoreName( display, p_intf->p_sys->mainWin, "VLC Media Player" );
+
+    // Load the vlc icon
+    int screen = DefaultScreen( display );
+    Screen *screenptr = DefaultScreenOfDisplay( display );
+    Visual *visual = DefaultVisualOfScreen( screenptr );
+    imlib_context_set_display( display );
+    imlib_context_set_visual( visual );
+    imlib_context_set_drawable( root );
+    imlib_context_set_colormap( DefaultColormap( display, screen ) );
+    imlib_context_set_dither( 1 );
+    imlib_context_set_blend( 1 );
+    Imlib_Image img = imlib_load_image_immediately( DATA_PATH"/vlc32x32.png" );
+    if( img == NULL )
+    {
+        // for developers ;)
+        img = imlib_load_image_immediately( "./share/vlc32x32.png" );
+    }
+    if( img == NULL )
+    {
+        msg_Err( p_intf, "loading vlc icon failed" );
+        p_intf->p_sys->iconPixmap = None;
+        p_intf->p_sys->iconMask = None;
+    }
+    else
+    {
+        imlib_context_set_image( img );
+        imlib_render_pixmaps_for_whole_image( &p_intf->p_sys->iconPixmap,
+                                              &p_intf->p_sys->iconMask );
+        imlib_free_image();
+    }
+
 
 #elif defined WIN32
+    // Interface thread id used to post broadcast messages
+    p_intf->p_sys->dwThreadId = GetCurrentThreadId();
+
     // We dynamically load msimg32.dll to get a pointer to TransparentBlt()
     p_intf->p_sys->h_msimg32_dll = LoadLibrary("msimg32.dll");
     if( !p_intf->p_sys->h_msimg32_dll ||
@@ -151,12 +176,6 @@ static int Open ( vlc_object_t *p_this )
 
 #endif
 
-#ifndef BASIC_SKINS
-    // Initialize conditions and mutexes
-    vlc_mutex_init( p_intf, &p_intf->p_sys->init_lock );
-    vlc_cond_init( p_intf, &p_intf->p_sys->init_cond );
-#endif
-
     p_intf->p_sys->p_theme = (Theme *)new OSTheme( p_intf );
 
     return( 0 );
@@ -169,7 +188,6 @@ static void Close ( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
 
-
     if( p_intf->p_sys->p_input )
     {
         vlc_object_release( p_intf->p_sys->p_input );
@@ -183,21 +201,25 @@ static void Close ( vlc_object_t *p_this )
     // Delete theme, it's important to do it correctly
     delete (OSTheme *)p_intf->p_sys->p_theme;
 
-    // Unsuscribe to messages bank
-    msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+#if defined X11_SKINS
+    XDestroyWindow( p_intf->p_sys->display, p_intf->p_sys->mainWin );
 
-#ifndef BASIC_SKINS
-    // Destroy conditions and mutexes
-    vlc_cond_destroy( &p_intf->p_sys->init_cond );
-    vlc_mutex_destroy( &p_intf->p_sys->init_lock );
+    // There is a bug in imlib2 which prevents us from closing the display
+    // (__imlib_RenderImage() can free old GC with already closed display)
+    //XCloseDisplay( p_intf->p_sys->display );
 #endif
 
+    // Unsuscribe to messages bank
+    msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
+
 #ifdef WIN32
     // Unload msimg32.dll and user32.dll
     if( p_intf->p_sys->h_msimg32_dll )
         FreeLibrary( p_intf->p_sys->h_msimg32_dll );
     if( p_intf->p_sys->h_user32_dll )
         FreeLibrary( p_intf->p_sys->h_user32_dll );
+#elif defined X11_SKINS
+    vlc_mutex_destroy( &p_intf->p_sys->xlock );
 #endif
 
     // Destroy structure
@@ -213,6 +235,10 @@ static void Run( intf_thread_t *p_intf )
 
     int a = OSAPI_GetTime();
 
+    // Initialize the dialog boxes
+    p_intf->p_sys->p_dialogs = new Dialogs( p_intf );
+    if( !p_intf->p_sys->p_dialogs ) return;
+
     // Load a theme
     char *skin_last = config_GetPsz( p_intf, "skin_last" );
     ThemeLoader *Loader = new ThemeLoader( p_intf );
@@ -220,47 +246,39 @@ static void Run( intf_thread_t *p_intf )
     if( skin_last == NULL || ! Loader->Load( skin_last ) )
     {
         // Too bad, it failed. Let's try with the default theme
-#if 0
-        if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
-#else
+//        if( ! Loader->Load( DEFAULT_SKIN_FILE ) )
 #ifdef WIN32
         string default_dir = (string)p_intf->p_libvlc->psz_vlcpath +
                              DIRECTORY_SEPARATOR + "skins" +
                              DIRECTORY_SEPARATOR + "default" +
                              DIRECTORY_SEPARATOR + "theme.xml";
-#else
-// FIXME: find VLC directory 
-        string default_dir = (string)"./share" +
-                             DIRECTORY_SEPARATOR + "skins" +
-                             DIRECTORY_SEPARATOR + "default" +
-                             DIRECTORY_SEPARATOR + "theme.xml";
-#endif
         if( ! Loader->Load( default_dir ) )
-#endif
         {
             // Last chance: the user can  select a new theme file
-// FIXME: wxWindows isn't initialized yet !!!
-#if 0
-#ifndef BASIC_SKINS
-            wxFileDialog dialog( NULL, _("Open a skin file"), "", "",
-                "Skin files (*.vlt)|*.vlt|Skin files (*.xml)|*.xml|"
-                    "All files|*.*", wxOPEN );
-
-            if( dialog.ShowModal() == wxID_OK )
-            {
-                // try to load selected file
-                if( ! Loader->Load( dialog.GetPath().c_str() ) )
-                {
-                    // He, he, what the hell is he doing ?
-                    delete Loader;
-                    return;
-                }
-            }
-            else
-#endif
+#else
+        string user_skin = (string)p_intf->p_vlc->psz_homedir +
+                              DIRECTORY_SEPARATOR + CONFIG_DIR +
+                              DIRECTORY_SEPARATOR + "skins" +
+                              DIRECTORY_SEPARATOR + "default" +
+                              DIRECTORY_SEPARATOR + "theme.xml";
+
+        string default_skin = (string)DATA_PATH +
+                              DIRECTORY_SEPARATOR + "skins" +
+                              DIRECTORY_SEPARATOR + "default" +
+                              DIRECTORY_SEPARATOR + "theme.xml";
+        if( !Loader->Load( user_skin ) && !Loader->Load( default_skin ) )
+        {
 #endif
+            p_intf->p_sys->p_dialogs->ShowOpenSkin( 1 /* block */ );
+
+            // try to load selected file
+            if( !p_intf->p_sys->p_new_theme_file ||
+                !Loader->Load( (string)p_intf->p_sys->p_new_theme_file ) )
             {
+                // He, he, what the hell is he doing ?
                 delete Loader;
+                delete p_intf->p_sys->p_dialogs;
+                if( skin_last ) free( skin_last );
                 return;
             }
         }
@@ -270,14 +288,17 @@ static void Run( intf_thread_t *p_intf )
     p_intf->p_sys->p_theme->InitTheme();
     p_intf->p_sys->p_theme->ShowTheme();
 
+    if( skin_last ) free( skin_last );
     delete Loader;
 
-    msg_Err( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
+    msg_Dbg( p_intf, "Load theme time : %i ms", OSAPI_GetTime() - a );
 
-    // Refresh the whole interface
     OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (int)true );
 
     OSRun( p_intf );
+
+    // clean up the dialog boxes
+    delete p_intf->p_sys->p_dialogs;
 }
 
 //---------------------------------------------------------------------------
@@ -301,10 +322,10 @@ vlc_module_begin();
               VLC_FALSE );
     add_bool( "show_in_taskbar", VLC_TRUE, NULL, SKIN_TASKBAR,
               SKIN_TASKBAR_LONG, VLC_FALSE );
-    set_description( _("Skinnable Interface") );
+    set_description( _("Skinnable interface") );
     set_capability( "interface", 30 );
     set_callbacks( Open, Close );
-    add_shortcut( "skins" );
+    set_program( "svlc" );
 vlc_module_end();
 
 
@@ -327,16 +348,6 @@ int SkinManage( intf_thread_t *p_intf )
         p_intf->p_sys->p_input = NULL;
     }
 
-    OSAPI_PostMessage( NULL, VLC_INTF_REFRESH, 0, (long)false );
-
-#ifndef BASIC_SKINS
-    // Update the log window
-    p_intf->p_sys->MessagesDlg->UpdateLog();
-
-    // Update the file info window
-    p_intf->p_sys->InfoDlg->UpdateFileInfo();
-#endif
-
     //-------------------------------------------------------------------------
     if( p_intf->p_sys->p_input != NULL && !p_intf->p_sys->p_input->b_die )
     {
@@ -354,41 +365,44 @@ int SkinManage( intf_thread_t *p_intf )
         OSAPI_PostMessage( NULL, CTRL_SET_SLIDER,
             (unsigned int)
             p_intf->p_sys->p_theme->EvtBank->Get( "volume_refresh" ),
-            (long)( volume * SLIDER_RANGE / AOUT_VOLUME_MAX ) );
-
+            (long)( volume * SLIDER_RANGE / (AOUT_VOLUME_DEFAULT * 2) ) );
 
         // Refresh slider
         // if( p_input->stream.b_seekable && p_intf->p_sys->b_playing )
-        if( p_input->stream.b_seekable )
-        {
 #define p_area p_input->stream.p_selected_area
+        if( p_input->stream.b_seekable && p_area->i_size )
+        {
 
             // Set value of sliders
-            long Value = SLIDER_RANGE *
-                p_input->stream.p_selected_area->i_tell /
-                p_input->stream.p_selected_area->i_size;
+            long Value = SLIDER_RANGE * p_area->i_tell / p_area->i_size;
 
             // Update sliders
             OSAPI_PostMessage( NULL, CTRL_SET_SLIDER, (unsigned int)
                 p_intf->p_sys->p_theme->EvtBank->Get( "time" ), (long)Value );
 
             // Text char * for updating text controls
-            char *text = new char[OFFSETTOTIME_MAX_SIZE];
+            char *text = new char[MSTRTIME_MAX_SIZE];
+
+            int64_t i_seconds, i_length;
+
+            i_seconds = var_GetTime( p_intf->p_sys->p_input, "time" ) / I64C(1000000 );
+            i_length = var_GetTime( p_intf->p_sys->p_input, "length" ) / I64C(1000000 );
+
+            secstotimestr( psz_time, i_seconds );
 
             // Create end time text
-            input_OffsetToTime( p_intf->p_sys->p_input, &text[1],
-                                p_area->i_size - p_area->i_tell );
+            secstotimestr( &text[1], i_length - i_seconds );
             text[0] = '-';
             p_intf->p_sys->p_theme->EvtBank->Get( "left_time" )
                 ->PostTextMessage( text );
 
             // Create time text and update
-            input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_tell );
+            secstotimestr( text, i_seconds );
             p_intf->p_sys->p_theme->EvtBank->Get( "time" )
                 ->PostTextMessage( text );
 
             // Create total time text
-            input_OffsetToTime( p_intf->p_sys->p_input, text, p_area->i_size );
+            secstotimestr( text, i_length );
             p_intf->p_sys->p_theme->EvtBank->Get( "total_time" )
                 ->PostTextMessage( text );