qt4.cpp 19.7 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * qt4.cpp : QT4 interface
 ****************************************************************************
4
 * Copyright © 2006-2008 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf <jb@videolan.org>
zorglub's avatar
zorglub committed
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 * 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
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23
 *****************************************************************************/
24

25
26
27
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
zorglub's avatar
zorglub committed
28
29

#include <QApplication>
Christophe Mutricy's avatar
Christophe Mutricy committed
30
31
#include <QLocale>
#include <QTranslator>
32
#include <QDate>
33
34
35
#include <QMutex>
#include <QMutexLocker>
#include <QWaitCondition>
36
#include <QPointer>
zorglub's avatar
zorglub committed
37

zorglub's avatar
zorglub committed
38
39
#include "qt4.hpp"
#include "dialogs_provider.hpp"
zorglub's avatar
zorglub committed
40
#include "input_manager.hpp"
zorglub's avatar
zorglub committed
41
#include "main_interface.hpp"
42
#include "dialogs/help.hpp" /* update */
Ludovic Fauvet's avatar
Ludovic Fauvet committed
43
#include "recents.hpp"
44
#include "util/qvlcapp.hpp"
zorglub's avatar
zorglub committed
45

Rafaël Carré's avatar
Rafaël Carré committed
46
47
48
49
#ifdef HAVE_X11_XLIB_H
#include <X11/Xlib.h>
#endif

zorglub's avatar
zorglub committed
50
#include "../../../share/vlc32x32.xpm"
51
#include "../../../share/vlc32x32-christmas.xpm"
52
#include <vlc_plugin.h>
zorglub's avatar
zorglub committed
53

54
55
56
57
58
#ifdef WIN32
 #include <QtPlugin>
 Q_IMPORT_PLUGIN(qjpeg)
#endif

zorglub's avatar
zorglub committed
59
60
61
62
63
64
/*****************************************************************************
 * Local prototypes.
 *****************************************************************************/
static int  Open         ( vlc_object_t * );
static void Close        ( vlc_object_t * );
static int  OpenDialogs  ( vlc_object_t * );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
65
66
static int  WindowOpen   ( vlc_object_t * );
static void WindowClose  ( vlc_object_t * );
zorglub's avatar
zorglub committed
67
static void Run          ( intf_thread_t * );
68
static void *Thread      ( void * );
zorglub's avatar
zorglub committed
69
70
71
72
73
static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
74
#define ADVANCED_PREFS_TEXT N_( "Show advanced preferences over simple ones" )
75
76
#define ADVANCED_PREFS_LONGTEXT N_( "Show advanced preferences and not simple "\
                                    "preferences when opening the preferences "\
77
                                    "dialog." )
78

79
80
81
#define SYSTRAY_TEXT N_( "Systray icon" )
#define SYSTRAY_LONGTEXT N_( "Show an icon in the systray " \
                             "allowing you to control VLC media player " \
82
                             "for basic actions." )
83

84
#define MINIMIZED_TEXT N_( "Start VLC with only a systray icon" )
85
86
#define MINIMIZED_LONGTEXT N_( "VLC will start with just an icon in " \
                               "your taskbar" )
87

88
89
#define TITLE_TEXT N_( "Show playing item name in window title" )
#define TITLE_LONGTEXT N_( "Show the name of the song or video in the " \
90
                           "controler window title." )
91

92
#define FILEDIALOG_PATH_TEXT N_( "Path to use in openfile dialog" )
93

94
#define NOTIFICATION_TEXT N_( "Show notification popup on track change" )
95
96
#define NOTIFICATION_LONGTEXT N_( \
    "Show a notification popup with the artist and track name when " \
97
    "the current playlist item changes, when VLC is minimized or hidden." )
98

99
100
#define ADVANCED_OPTIONS_TEXT N_( "Advanced options" )
#define ADVANCED_OPTIONS_LONGTEXT N_( "Show all the advanced options " \
101
                                      "in the dialogs." )
102

103
104
#define OPACITY_TEXT N_( "Windows opacity between 0.1 and 1." )
#define OPACITY_LONGTEXT N_( "Sets the windows opacity between 0.1 and 1 " \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
105
                             "for main interface, playlist and extended panel."\
106
107
                             " This option only works with Windows and " \
                             "X11 with composite extensions." )
108

109
#define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
110

111
#define UPDATER_TEXT N_( "Activate the updates availability notification" )
112
#define UPDATER_LONGTEXT N_( "Activate the automatic notification of new " \
113
114
                            "versions of the software. It runs once every " \
                            "two weeks." )
dionoea's avatar
dionoea committed
115
#define UPDATER_DAYS_TEXT N_("Number of days between two update checks")
116

117
118
119
120
121
#define COMPLETEVOL_TEXT N_( "Allow the volume to be set to 400%" )
#define COMPLETEVOL_LONGTEXT N_( "Allow the volume to have range from 0% to " \
                                 "400%, instead of 0% to 200%. This option " \
                                 "can distort the audio, since it uses " \
                                 "software amplification." )
122

123
124
#define SAVEVOL_TEXT N_( "Automatically save the volume on exit" )

125
#define BLING_TEXT N_( "Use non native buttons and volume slider" )
126

127
#define PRIVACY_TEXT N_( "Ask for network policy at start" )
128

Ludovic Fauvet's avatar
Ludovic Fauvet committed
129
#define RECENTPLAY_TEXT N_( "Save the recently played items in the menu" )
130

Ludovic Fauvet's avatar
Ludovic Fauvet committed
131
#define RECENTPLAY_FILTER_TEXT N_( "List of words separated by | to filter" )
132
133
#define RECENTPLAY_FILTER_LONGTEXT N_( "Regular expression used to filter " \
        "the recent items played in the player" )
Ludovic Fauvet's avatar
Ludovic Fauvet committed
134

135
136
137
138
#define SLIDERCOL_TEXT N_( "Define the colors of the volume slider " )
#define SLIDERCOL_LONGTEXT N_( "Define the colors of the volume slider\n" \
                       "By specifying the 12 numbers separated by a ';'\n" \
            "Default is '255;255;255;20;226;20;255;176;15;235;30;20'\n" \
139
            "An alternative can be '30;30;50;40;40;100;50;50;160;150;150;255' ")
140
141
142
143

#define QT_MODE_TEXT N_( "Selection of the starting mode and look " )
#define QT_MODE_LONGTEXT N_( "Start VLC with:\n" \
                             " - normal mode\n"  \
144
                             " - a zone always present to show information " \
145
146
147
148
149
150
151
                                  "as lyrics, album arts...\n" \
                             " - minimal mode with limited controls" )

#define QT_NORMAL_MODE_TEXT N_( "Classic look" )
#define QT_ALWAYS_VIDEO_MODE_TEXT N_( "Complete look with information area" )
#define QT_MINIMAL_MODE_TEXT N_( "Minimal look with no menus" )

152
153
#define QT_FULLSCREEN_TEXT N_( "Show a controller in fullscreen mode" )

154
static const int i_mode_list[] =
155
    { QT_NORMAL_MODE, QT_ALWAYS_VIDEO_MODE, QT_MINIMAL_MODE };
156
static const char *const psz_mode_list_text[] =
157
158
    { QT_NORMAL_MODE_TEXT, QT_ALWAYS_VIDEO_MODE_TEXT, QT_MINIMAL_MODE_TEXT };

zorglub's avatar
zorglub committed
159
vlc_module_begin();
160
161
    set_shortname( "Qt" );
    set_description( N_("Qt interface") );
Christophe Mutricy's avatar
Christophe Mutricy committed
162
    set_category( CAT_INTERFACE ) ;
zorglub's avatar
zorglub committed
163
    set_subcategory( SUBCAT_INTERFACE_MAIN );
164
    set_capability( "interface", 151 );
zorglub's avatar
zorglub committed
165
166
    set_callbacks( Open, Close );

Christophe Mutricy's avatar
Christophe Mutricy committed
167
    add_shortcut("qt");
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    add_integer( "qt-display-mode", QT_NORMAL_MODE, NULL,
                 QT_MODE_TEXT, QT_MODE_LONGTEXT, false );
        change_integer_list( i_mode_list, psz_mode_list_text, NULL );

    add_bool( "qt-notification", true, NULL, NOTIFICATION_TEXT,
              NOTIFICATION_LONGTEXT, false );

    add_float_with_range( "qt-opacity", 1., 0.1, 1., NULL, OPACITY_TEXT,
                          OPACITY_LONGTEXT, false );
    add_bool( "qt-blingbling", true, NULL, BLING_TEXT, BLING_TEXT, false );

    add_bool( "qt-system-tray", true, NULL, SYSTRAY_TEXT,
              SYSTRAY_LONGTEXT, false);
    add_bool( "qt-start-minimized", false, NULL, MINIMIZED_TEXT,
              MINIMIZED_LONGTEXT, true);
    add_bool( "qt-name-in-title", true, NULL, TITLE_TEXT,
              TITLE_LONGTEXT, false );
    add_bool( "qt-fs-controller", true, NULL, QT_FULLSCREEN_TEXT,
              QT_FULLSCREEN_TEXT, false );

    add_bool( "qt-volume-complete", false, NULL, COMPLETEVOL_TEXT,
              COMPLETEVOL_LONGTEXT, true );
    add_bool( "qt-autosave-volume", false, NULL, SAVEVOL_TEXT,
              SAVEVOL_TEXT, true );
    add_string( "qt-filedialog-path", NULL, NULL, FILEDIALOG_PATH_TEXT,
193
                FILEDIALOG_PATH_TEXT, true );
194
195
        change_autosave();
        change_internal();
196

197
198
199
    add_bool( "qt-recentplay", true, NULL, RECENTPLAY_TEXT,
              RECENTPLAY_TEXT, false );
    add_string( "qt-recentplay-filter", "xxx|porn", NULL,
200
201
                RECENTPLAY_FILTER_TEXT, RECENTPLAY_FILTER_LONGTEXT, false );

202
203
204
205
206
207
    add_bool( "qt-adv-options", false, NULL, ADVANCED_OPTIONS_TEXT,
              ADVANCED_OPTIONS_LONGTEXT, true );
    add_bool( "qt-advanced-pref", false, NULL, ADVANCED_PREFS_TEXT,
              ADVANCED_PREFS_LONGTEXT, false );
    add_bool( "qt-error-dialogs", true, NULL, ERROR_TEXT,
              ERROR_TEXT, false );
208
#ifdef UPDATE_CHECK
209
210
211
212
    add_bool( "qt-updates-notif", true, NULL, UPDATER_TEXT,
              UPDATER_LONGTEXT, false );
    add_integer( "qt-updates-days", 7, NULL, UPDATER_DAYS_TEXT,
                 UPDATER_DAYS_TEXT, false );
213
#endif
214
    add_string( "qt-slider-colours",
215
                "255;255;255;20;226;20;255;176;15;235;30;20",
216
                NULL, SLIDERCOL_TEXT, SLIDERCOL_LONGTEXT, false );
217

218
219
220
221
222
223
224
    add_bool( "qt-privacy-ask", true, NULL, PRIVACY_TEXT, PRIVACY_TEXT,
              false );
        change_internal();

    add_submodule();
        set_description( "Dialogs provider" );
        set_capability( "dialogs provider", 51 );
225

zorglub's avatar
zorglub committed
226
        set_callbacks( OpenDialogs, Close );
227

228
#if !defined (Q_WS_X11) || HAS_QT43
229
230
    add_submodule();
        set_capability( "vout window", 50 );
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
231
        set_callbacks( WindowOpen, WindowClose );
232
#endif
zorglub's avatar
zorglub committed
233
234
vlc_module_end();

235
236
237
238
239
240
static struct
{
    QMutex lock;
    QWaitCondition ready;
} iface;

zorglub's avatar
zorglub committed
241
242
243
244
245
246
/*****************************************************************************
 * Module callbacks
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
247
    intf_sys_t *p_sys;
248

249
#if defined Q_WS_X11 && defined HAVE_X11_XLIB_H
Rafaël Carré's avatar
Rafaël Carré committed
250
    /* Thanks for libqt4 calling exit() in QApplication::QApplication()
251
252
     * instead of returning an error, we have to check the X11 display */
    Display *p_display = XOpenDisplay( NULL );
Rafaël Carré's avatar
Rafaël Carré committed
253
254
    if( !p_display )
    {
255
        msg_Err( p_intf, "Could not connect to X server" );
256
257
        return VLC_EGENERIC;
    }
Rafaël Carré's avatar
Rafaël Carré committed
258
    XCloseDisplay( p_display );
259
#endif
260

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
261
    /* Allocations */
262
263
264
265
266
267
268
269
270
271
272
    p_sys = p_intf->p_sys = new intf_sys_t;
    p_sys->b_isDialogProvider = false;
    p_sys->p_video = NULL; /* ??? */
    p_sys->p_popup_menu = NULL; /* ??? */
    p_sys->p_playlist = pl_Hold( p_intf );
    p_sys->p_mi = NULL;

    if (vlc_clone (&p_sys->thread, Thread, p_intf, VLC_THREAD_PRIORITY_LOW))
    {
        pl_Release (p_sys->p_playlist);
        delete p_sys;
Christophe Mutricy's avatar
Christophe Mutricy committed
273
        return VLC_ENOMEM;
274
275
276
277
    }
    else
    {
        QMutexLocker locker (&iface.lock);
zorglub's avatar
zorglub committed
278

279
280
281
        while (p_sys->p_mi == NULL)
            iface.ready.wait (&iface.lock);
    }
zorglub's avatar
zorglub committed
282
283
284
285
286
287
    return VLC_SUCCESS;
}

static int OpenDialogs( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
288
289
    p_intf->pf_show_dialog = ShowDialog;

290
291
292
293
    int val = Open( p_this );
    if( val )
        return val;

zorglub's avatar
zorglub committed
294
295
296
297
298
299
    return VLC_SUCCESS;
}

static void Close( vlc_object_t *p_this )
{
    intf_thread_t *p_intf = (intf_thread_t *)p_this;
300
301
302
    intf_sys_t *p_sys = p_intf->p_sys;

    QApplication::postEvent (p_sys->p_mi, new QCloseEvent());
303

304
    if( p_intf->p_sys->b_isDialogProvider )
305
    {
306
        if( DialogsProvider::isAlive() )
307
        {
308
            msg_Dbg( p_intf, "Asking the DP to quit nicely" );
309
310
311
            DialogEvent *event = new DialogEvent( INTF_DIALOG_EXIT, 0, NULL );
            QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
        }
312
313
314
        vlc_thread_join( p_intf );
    }

315
316
317
    vlc_join (p_sys->thread, NULL);
    pl_Release (p_this);
    delete p_sys;
zorglub's avatar
zorglub committed
318
319
320
321
}



322
323
324
static QMutex windowLock;
static QWaitCondition windowWait;

325
static void *Thread( void *obj )
zorglub's avatar
zorglub committed
326
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
327
    intf_thread_t *p_intf = (intf_thread_t *)obj;
328
    MainInterface *p_mi;
329
    vlc_value_t val;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
330
331
    char dummy[] = "";
    char *argv[] = { dummy };
zorglub's avatar
zorglub committed
332
    int argc = 1;
333

Rafaël Carré's avatar
Rafaël Carré committed
334
    Q_INIT_RESOURCE( vlc );
335

336
337
#if !defined(WIN32) && !defined(__APPLE__)
    /* KLUDGE:
338
339
     * disables icon theme use because that makes Cleanlooks style bug
     * because it asks gconf for some settings that timeout because of threads
Rafaël Carré's avatar
Rafaël Carré committed
340
     * see commits 21610 21622 21654 for reference */
341

342
    /* If you don't have a gconftool-2 binary, you should comment this line */
Rafaël Carré's avatar
Rafaël Carré committed
343
344
    if( strcmp( qVersion(), "4.4.0" ) < 0 ) /* fixed in Qt 4.4.0 */
        QApplication::setDesktopSettingsAware( false );
Rafaël Carré's avatar
Rafaël Carré committed
345
#endif
346
347

    /* Start the QApplication here */
348
    QVLCApp *app = new QVLCApp( argc, argv , true );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
349
350
    p_intf->p_sys->p_app = app;

351
352
353
354
355
356
357
358
    p_intf->p_sys->mainSettings = new QSettings(
#ifdef WIN32
            QSettings::IniFormat,
#else
            QSettings::NativeFormat,
#endif
            QSettings::UserScope, "vlc", "vlc-qt-interface" );

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
359
    /* Icon setting */
360
361
362
363
    if( QDate::currentDate().dayOfYear() >= 354 )
        app->setWindowIcon( QIcon( QPixmap(vlc_christmas_xpm) ) );
    else
        app->setWindowIcon( QIcon( QPixmap(vlc_xpm) ) );
Rafaël Carré's avatar
Rafaël Carré committed
364

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
365
    /* Initialize timers and the Dialog Provider */
366
    DialogsProvider::getInstance( p_intf );
zorglub's avatar
zorglub committed
367

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#ifdef UPDATE_CHECK
    /* Checking for VLC updates */
    if( config_GetInt( p_intf, "qt-updates-notif" ) &&
        !config_GetInt( p_intf, "qt-privacy-ask" ) )
    {
        int interval = config_GetInt( p_intf, "qt-updates-days" );
        if( QDate::currentDate() >
             getSettings()->value( "updatedate" ).toDate().addDays( interval ) )
        {
            /* The constructor of the update Dialog will do the 1st request */
            UpdateDialog::getInstance( p_intf );
            getSettings()->setValue( "updatedate", QDate::currentDate() );
        }
    }
#endif

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
384
    /* Create the normal interface in non-DP mode */
zorglub's avatar
zorglub committed
385
386
    if( !p_intf->pf_show_dialog )
    {
387
        p_mi = new MainInterface( p_intf );
388
389
        /* We don't show it because it is done in the MainInterface constructor
        p_mi->show(); */
390

391
392
393
        QMutexLocker locker (&iface.lock);
        p_intf->p_sys->p_mi = p_mi;
        iface.ready.wakeAll ();
zorglub's avatar
zorglub committed
394
    }
395
    else
396
    {
zorglub's avatar
zorglub committed
397
        vlc_thread_ready( p_intf );
398
        p_intf->p_sys->b_isDialogProvider = true;
399
        p_mi = NULL;
400
    }
401

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
402
403
    /* Explain to the core how to show a dialog :D */
    p_intf->pf_show_dialog = ShowDialog;
404

405
#ifdef ENABLE_NLS
Christophe Mutricy's avatar
Christophe Mutricy committed
406
    // Translation - get locale
Christophe Mutricy's avatar
Christophe Mutricy committed
407
#   if defined (WIN32) || defined (__APPLE__)
Christophe Mutricy's avatar
Christophe Mutricy committed
408
409
    char* psz_tmp = config_GetPsz( p_intf, "language" );
    QString lang = qfu( psz_tmp );
Christophe Mutricy's avatar
Typo    
Christophe Mutricy committed
410
    free( psz_tmp);
Christophe Mutricy's avatar
Christophe Mutricy committed
411
412
413
414
415
    if (lang == "auto")
        lang = QLocale::system().name();
#   else
    QString lang = QLocale::system().name();
#   endif
Christophe Mutricy's avatar
Christophe Mutricy committed
416
417
418
419
    // Translations for qt's own dialogs
    QTranslator qtTranslator( 0 );
    // Let's find the right path for the translation file
#if !defined( WIN32 )
420
    QString path =  QString( QT4LOCALEDIR );
Christophe Mutricy's avatar
Christophe Mutricy committed
421
#else
422
    QString path = QString( QString(config_GetDataDir()) + DIR_SEP +
423
                            "locale" + DIR_SEP + "qt4" + DIR_SEP );
Christophe Mutricy's avatar
Christophe Mutricy committed
424
425
#endif
    // files depending on locale
Christophe Mutricy's avatar
Christophe Mutricy committed
426
    bool b_loaded = qtTranslator.load( path + "qt_" + lang );
Christophe Mutricy's avatar
Christophe Mutricy committed
427
    if (!b_loaded)
428
429
        msg_Dbg( p_intf, "Error while initializing qt-specific localization" );
    app->installTranslator( &qtTranslator );
430
#endif  //ENABLE_NLS
431

432
    /* Last settings */
zorglub's avatar
zorglub committed
433
    app->setQuitOnLastWindowClosed( false );
434

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
435
    /* Retrieve last known path used in file browsing */
436
    char *psz_path = config_GetPsz( p_intf, "qt-filedialog-path" );
437
438
    p_intf->p_sys->psz_filepath = EMPTY_STR( psz_path ) ? config_GetHomeDir()
                                                        : psz_path;
439

440
    /* Launch */
zorglub's avatar
zorglub committed
441
    app->exec();
442
443

    /* And quit */
444
    msg_Dbg( p_intf, "Quitting the Qt4 Interface" );
445

446
    if (p_mi != NULL)
447
    {
448
449
        QMutexLocker locker (&iface.lock);
        p_intf->p_sys->p_mi = NULL;
450
451
452

        /* We need to warn to detach from any vout before
         * deleting miP (WindowClose will not be called after it) */
453
454
455
456
457
458
        p_mi->releaseVideo( NULL );

        /* Destroy first the main interface because it is connected to some
           slots in the MainInputManager */
        /* Destroy under the iface lock to sync vout QPointer */
        delete p_mi;
459
    }
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
460

461
462
463
464
465
    /* Destroy all remaining windows,
       because some are connected to some slots
       in the MainInputManager
       Settings must be destroyed after that.
     */
zorglub's avatar
zorglub committed
466
    DialogsProvider::killInstance();
467

Ludovic Fauvet's avatar
Ludovic Fauvet committed
468
469
470
    /* Delete the recentsMRL object before the configuration */
    RecentsMRL::killInstance();

471
472
    /* Delete the configuration. Application has to be deleted after that. */
    delete p_intf->p_sys->mainSettings;
473
474
475
476

    /* Destroy the MainInputManager */
    MainInputManager::killInstance();

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
477
    /* Delete the application */
478
479
    delete app;

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
480
    /* Save the path */
481
    config_PutPsz( p_intf, "qt-filedialog-path", p_intf->p_sys->psz_filepath );
482
    free( psz_path );
483
    return NULL;
zorglub's avatar
zorglub committed
484
485
486
487
488
489
490
491
492
}

/*****************************************************************************
 * Callback to show a dialog
 *****************************************************************************/
static void ShowDialog( intf_thread_t *p_intf, int i_dialog_event, int i_arg,
                        intf_dialog_args_t *p_arg )
{
    DialogEvent *event = new DialogEvent( i_dialog_event, i_arg, p_arg );
zorglub's avatar
zorglub committed
493
    QApplication::postEvent( THEDP, static_cast<QEvent*>(event) );
zorglub's avatar
zorglub committed
494
}
zorglub's avatar
zorglub committed
495
496
497
498
499
500
501
502
503
504
505
506
507

/*****************************************************************************
 * PopupMenuCB: callback to show the popupmenu.
 *  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 )
{
    intf_thread_t *p_intf = (intf_thread_t *)param;
    ShowDialog( p_intf, INTF_DIALOG_POPUPMENU, new_val.b_bool, 0 );
    return VLC_SUCCESS;
}
508
509
510
511
512
513

/**
 * Video output window provider
 */
#include <vlc_window.h>

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
514
static int WindowControl (vout_window_t *, int, va_list);
515

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
516
static int WindowOpen (vlc_object_t *obj)
517
518
{
    vout_window_t *wnd = (vout_window_t *)obj;
519
    QPointer<MainInterface> *miP;
520

521
522
523
    if (config_GetInt (obj, "embedded-video") <= 0)
        return VLC_EGENERIC;

524
525
526
527
528
529
    intf_thread_t *intf = (intf_thread_t *)
        vlc_object_find_name (obj, "qt4", FIND_ANYWHERE);
    if (intf == NULL)
        return VLC_EGENERIC; /* Qt4 not in use */
    assert (intf->i_object_type == VLC_OBJECT_INTF);

530
    QMutexLocker (&iface.lock);
531
    msg_Dbg (obj, "waiting for interface...");
532
533
    while (intf->p_sys->p_mi == NULL)
        iface.ready.wait (&iface.lock);
534

535
    msg_Dbg (obj, "requesting window...");
536
537
    /* create our own copy */
    miP = new QPointer<MainInterface> (intf->p_sys->p_mi);
538
539
540
541
    vlc_object_release (intf);

    if (miP->isNull ())
        return VLC_EGENERIC;
542

543
544
    wnd->handle = (*miP)->requestVideo (wnd->vout, &wnd->pos_x, &wnd->pos_y,
                                        &wnd->width, &wnd->height);
545
546
547
    if (!wnd->handle)
        return VLC_EGENERIC;

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
548
    wnd->control = WindowControl;
549
    wnd->p_private = miP;
550
551
552
    return VLC_SUCCESS;
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
553
static int WindowControl (vout_window_t *wnd, int query, va_list args)
554
{
555
    QMutexLocker locker (&iface.lock);
556
557
558
559
560
    QPointer<MainInterface> *miP = (QPointer<MainInterface> *)wnd->p_private;

    if (miP->isNull ())
        return VLC_EGENERIC;
    return (*miP)->controlVideo (wnd->handle, query, args);
561
562
}

Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
563
static void WindowClose (vlc_object_t *obj)
564
565
{
    vout_window_t *wnd = (vout_window_t *)obj;
566
    QMutexLocker locker (&iface.lock);
567
    QPointer<MainInterface> *miP = (QPointer<MainInterface> *)wnd->p_private;
568

569
    if (!miP->isNull ())
570
        (*miP)->releaseVideo( wnd->handle );
571
    delete miP;
572
}