RendererSettings.cpp 5.52 KB
Newer Older
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
1 2 3 4 5
/*****************************************************************************
 * RendererSettings.cpp: Edit the output file parameters
 *****************************************************************************
 * Copyright (C) 2008-2010 VideoLAN
 *
6
 * Authors: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23
#include "Media.h"
24
#include "RendererSettings.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
25 26 27
#include "SettingsManager.h"
#include "ui_RendererSettings.h"

28 29
#include <QCompleter>
#include <QDirModel>
30
#include <QFileDialog>
31
#include <QFileInfo>
32
#include <QMessageBox>
33
#include <QSslSocket>
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34

35
RendererSettings::RendererSettings( bool shareOnInternet )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
36
{
37
    m_ui.setupUi( this );
38

39
    if( shareOnInternet )
40
    {
41 42 43
        m_ui.outputLabel->setVisible( false );
        m_ui.outputFileName->setVisible( false );
        m_ui.outputFileNameButton->setVisible( false );
44 45 46
        m_ui.outputFileName->setText(
            VLMC_GET_STRING( "general/TempFolderLocation" ) + "/" +
            VLMC_PROJECT_GET_STRING( "general/ProjectName" ) + "-vlmc.mp4" );
47
        setWindowTitle( tr("Export Settings: Publish on Internet") );
48 49
    }

50 51 52
    m_ui.width->setValue( VLMC_PROJECT_GET_INT( "video/VideoProjectWidth" ) );
    m_ui.height->setValue( VLMC_PROJECT_GET_INT( "video/VideoProjectHeight" ) );
    m_ui.fps->setValue( VLMC_PROJECT_GET_DOUBLE( "video/VLMCOutputFPS" ) );
53 54 55 56

    QCompleter* completer = new QCompleter( this );
    completer->setModel( new QDirModel( completer ) );
    m_ui.outputFileName->setCompleter( completer );
57 58 59 60 61

    connect( m_ui.outputFileNameButton, SIGNAL( clicked() ),
             this, SLOT(selectOutputFileName() ) );
    connect( m_ui.videoPresetBox, SIGNAL( activated( int ) ),
             this, SLOT( updateVideoPreset( int ) ) );
62 63 64 65

    if( !QSslSocket::supportsSsl() )
	    QMessageBox::information(0, "SSL Error",
		    "This build has no OpenSSL support, video upload may not work.");
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
66 67 68 69 70 71 72
}

void
RendererSettings::selectOutputFileName()
{
    QString outputFileName =
            QFileDialog::getSaveFileName( NULL, tr ( "Enter the output file name" ),
73
                                          QDir::currentPath(), tr( "Videos(%1)" ).arg( Media::VideoExtensions ) );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
74 75 76
    m_ui.outputFileName->setText( outputFileName );
}

77
void
78
RendererSettings::setPreset( quint32 width, quint32 height, double fps )
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
{
    m_ui.width->setValue( width );
    m_ui.height->setValue( height );
    m_ui.fps->setValue( fps );
}

void
RendererSettings::updateVideoPreset( int index )
{
    m_ui.width->setEnabled( false );
    m_ui.height->setEnabled( false );
    m_ui.fps->setEnabled( false );

    switch( index )
    {
        case QVGA:  setPreset( 320, 240, 30);   break;
        case VGA:   setPreset( 640, 480, 30);   break;
        case SVGA:  setPreset( 800, 600, 30);   break;
        case XVGA:  setPreset( 1024, 768, 30);  break;
98
        case P480:  setPreset( 720, 480, 29.97);   break;
99
        case P576:  setPreset( 720, 576, 25);   break;
100 101
        case P720:  setPreset( 1280, 720, 29.97);  break;
        case P1080: setPreset( 1920, 1080, 29.97); break;
102 103 104 105 106 107 108 109
        case Custom:
        default:
             m_ui.width->setEnabled( true );
             m_ui.height->setEnabled( true );
             m_ui.fps->setEnabled( true );
    }
}

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
110 111 112
void
RendererSettings::accept()
{
113
    if ( width() <= 0 || height() <= 0 || fps() <= .0f )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
114
    {
Ludovic Fauvet's avatar
Ludovic Fauvet committed
115 116
        QMessageBox::warning( this, tr( "Invalid parameters" ),
                              tr( "Please enter valid rendering parameters" ) );
117
        return;
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
118
    }
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

    QFileInfo fileInfo( m_ui.outputFileName->text() );

    if ( outputFileName().isEmpty() || fileInfo.isDir() || !fileInfo.dir().exists() )
    {
        QMessageBox::warning( this, tr( "Invalid parameters" ),
                              tr( "Please provide a valid output file!" ) );
        m_ui.outputFileName->setFocus();
        return;
    }

    if ( fileInfo.isFile() )
    {
        QMessageBox::StandardButton b =
                QMessageBox::question( this, tr( "File already exists!" ),
                                       tr( "Output file already exists, do you want to "
135
                                           "overwrite it?" ),
136 137 138 139 140 141 142
                                       QMessageBox::Yes | QMessageBox::No,
                                       QMessageBox::No );
        if ( b == QMessageBox::No )
            return;
    }

    QDialog::accept();
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
}

quint32
RendererSettings::width() const
{
    return m_ui.width->value();
}

quint32
RendererSettings::height() const
{
    return m_ui.height->value();
}

double
RendererSettings::fps() const
{
    return m_ui.fps->value();
}

quint32
RendererSettings::videoBitrate() const
{
    return m_ui.videoQuality->value();
}

quint32
RendererSettings::audioBitrate() const
{
    return m_ui.audioQuality->value();
}

QString
RendererSettings::outputFileName() const
{
    return m_ui.outputFileName->text();
}