📄 open_panels.cpp
字号:
/***************************************************************************** * open.cpp : Panels for the open dialogs **************************************************************************** * Copyright (C) 2006-2008 the VideoLAN team * Copyright (C) 2007 Société des arts technologiques * Copyright (C) 2007 Savoir-faire Linux * * $Id: f7e1cb296ff152c4cc279422d0ad45312e5f8e83 $ * * Authors: Clément Stenac <zorglub@videolan.org> * Jean-Baptiste Kempf <jb@videolan.org> * Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include "qt4.hpp"#include "components/open_panels.hpp"#include "dialogs/open.hpp"#include "dialogs_provider.hpp"#include <QFileDialog>#include <QDialogButtonBox>#include <QLineEdit>#include <QStackedLayout>#include <QListView>#include <QCompleter>#include <QDirModel>#include <QScrollArea>#include <QUrl>#define I_DEVICE_TOOLTIP N_("Select the device or the VIDEO_TS directory")/************************************************************************** * Open Files and subtitles * **************************************************************************/FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) : OpenPanel( _parent, _p_intf ){ /* Classic UI Setup */ ui.setupUi( this ); /** BEGIN QFileDialog tweaking **/ /* Use a QFileDialog and customize it because we don't want to rewrite it all. Be careful to your eyes cause there are a few hacks. Be very careful and test correctly when you modify this. */ /* Set Filters for file selection */ QString fileTypes = ""; ADD_FILTER_MEDIA( fileTypes ); ADD_FILTER_VIDEO( fileTypes ); ADD_FILTER_AUDIO( fileTypes ); ADD_FILTER_PLAYLIST( fileTypes ); ADD_FILTER_ALL( fileTypes ); fileTypes.replace( QString(";*"), QString(" *")); // Make this QFileDialog a child of tempWidget from the ui. dialogBox = new FileOpenBox( ui.tempWidget, NULL, qfu( p_intf->p_sys->psz_filepath ), fileTypes ); dialogBox->setFileMode( QFileDialog::ExistingFiles ); dialogBox->setAcceptMode( QFileDialog::AcceptOpen );#if HAS_QT43 dialogBox->restoreState( getSettings()->value( "file-dialog-state" ).toByteArray() );#endif /* We don't want to see a grip in the middle of the window, do we? */ dialogBox->setSizeGripEnabled( false ); /* Add a tooltip */ dialogBox->setToolTip( qtr( "Select one or multiple files" ) ); dialogBox->setMinimumHeight( 250 ); // But hide the two OK/Cancel buttons. Enable them for debug. QDialogButtonBox *fileDialogAcceptBox = dialogBox->findChildren<QDialogButtonBox*>()[0]; fileDialogAcceptBox->hide(); /* Ugly hacks to get the good Widget */ //This lineEdit is the normal line in the fileDialog.#if HAS_QT43 lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];#else lineFileEdit = dialogBox->findChildren<QLineEdit*>()[1];#endif /* Make a list of QLabel inside the QFileDialog to access the good ones */ QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>(); /* Hide the FileNames one. Enable it for debug */ listLabel[1]->setText( qtr( "File names:" ) ); /* Change the text that was uncool in the usual box */ listLabel[2]->setText( qtr( "Filter:" ) ); dialogBox->layout()->setMargin( 0 ); dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint ); /** END of QFileDialog tweaking **/ // Add the DialogBox to the layout ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 ); //TODO later: fill the fileCompleteList with previous items played. QCompleter *fileCompleter = new QCompleter( fileCompleteList, this ); fileCompleter->setModel( new QDirModel( fileCompleter ) ); lineFileEdit->setCompleter( fileCompleter ); // Hide the subtitles control by default. ui.subFrame->hide(); /* Build the subs size combo box */ setfillVLCConfigCombo( "freetype-rel-fontsize" , p_intf, ui.sizeSubComboBox ); /* Build the subs align combo box */ setfillVLCConfigCombo( "subsdec-align", p_intf, ui.alignSubComboBox ); /* Connects */ BUTTONACT( ui.subBrowseButton, browseFileSub() ); BUTTONACT( ui.subCheckBox, toggleSubtitleFrame()); CONNECT( lineFileEdit, textChanged( QString ), this, updateMRL() ); CONNECT( ui.subInput, textChanged( QString ), this, updateMRL() ); CONNECT( ui.alignSubComboBox, currentIndexChanged( int ), this, updateMRL() ); CONNECT( ui.sizeSubComboBox, currentIndexChanged( int ), this, updateMRL() );}FileOpenPanel::~FileOpenPanel(){#if HAS_QT43 getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );#endif}/* Show a fileBrowser to select a subtitle */void FileOpenPanel::browseFileSub(){ // TODO Handle selection of more than one subtitles file QStringList files = THEDP->showSimpleOpen( qtr("Open subtitles file"), EXT_FILTER_SUBTITLE, dialogBox->directory().absolutePath() ); if( files.isEmpty() ) return; ui.subInput->setText( files.join(" ") ); updateMRL();}/* Update the current MRL */void FileOpenPanel::updateMRL(){ QString mrl = ""; foreach( QString file, dialogBox->selectedFiles() ) { mrl += "\"" + file + "\" "; } if( ui.subCheckBox->isChecked() ) { mrl.append( " :sub-file=\"" + ui.subInput->text() + "\"" ); int align = ui.alignSubComboBox->itemData( ui.alignSubComboBox->currentIndex() ).toInt(); mrl.append( " :subsdec-align=" + QString().setNum( align ) ); int size = ui.sizeSubComboBox->itemData( ui.sizeSubComboBox->currentIndex() ).toInt(); mrl.append( " :freetype-rel-fontsize=" + QString().setNum( size ) ); } emit mrlUpdated( mrl ); emit methodChanged( "file-caching" );}/* Function called by Open Dialog when clicke on Play/Enqueue */void FileOpenPanel::accept(){ //TODO set the completer p_intf->p_sys->psz_filepath = qtu( dialogBox->directory().absolutePath() );}void FileOpenBox::accept(){ OpenDialog::getInstance( NULL, NULL, true )->selectSlots();}void FileOpenBox::reject(){ OpenDialog::getInstance( NULL, NULL, true )->cancel();}/* Function called by Open Dialog when clicked on cancel */void FileOpenPanel::clear(){ lineFileEdit->clear(); ui.subInput->clear();}void FileOpenPanel::toggleSubtitleFrame(){ TOGGLEV( ui.subFrame ); /* Update the MRL */ updateMRL();}/************************************************************************** * Open Discs ( DVD, CD, VCD and similar devices ) * **************************************************************************/DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) : OpenPanel( _parent, _p_intf ){ ui.setupUi( this ); /* Get the default configuration path for the devices */ psz_dvddiscpath = config_GetPsz( p_intf, "dvd" ); psz_vcddiscpath = config_GetPsz( p_intf, "vcd" ); psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" ); /* State to avoid overwritting the users changes with the configuration */ b_firstdvd = true; b_firstvcd = true; b_firstcdda = true; ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP )); ui.deviceCombo->setToolTip( I_DEVICE_TOOLTIP );#if WIN32 /* Disc drives probing for Windows */ char szDrives[512]; szDrives[0] = '\0'; if( GetLogicalDriveStringsA( sizeof( szDrives ) - 1, szDrives ) ) { char *drive = szDrives; UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS ); while( *drive ) { if( GetDriveTypeA(drive) == DRIVE_CDROM ) ui.deviceCombo->addItem( drive ); /* go to next drive */ while( *(drive++) ); } SetErrorMode(oldMode); }#else /* Use a Completer under Linux */ QCompleter *discCompleter = new QCompleter( this ); discCompleter->setModel( new QDirModel( discCompleter ) ); ui.deviceCombo->setCompleter( discCompleter );#endif /* CONNECTs */ BUTTONACT( ui.dvdRadioButton, updateButtons() ); BUTTONACT( ui.vcdRadioButton, updateButtons() ); BUTTONACT( ui.audioCDRadioButton, updateButtons() ); BUTTONACT( ui.dvdsimple, updateButtons() ); BUTTONACT( ui.browseDiscButton, browseDevice() ); BUTTON_SET_ACT_I( ui.ejectButton, "", eject, qtr( "Eject the disc" ), eject() ); CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL()); CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL()); CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL()); CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL()); CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL()); /* Run once the updateButtons function in order to fill correctly the comboBoxes */ updateButtons();}DiscOpenPanel::~DiscOpenPanel(){ free( psz_dvddiscpath ); free( psz_vcddiscpath ); free( psz_cddadiscpath );}void DiscOpenPanel::clear(){ ui.titleSpin->setValue( 0 ); ui.chapterSpin->setValue( 0 ); b_firstcdda = true; b_firstdvd = true; b_firstvcd = true;}#ifdef WIN32 #define setDrive( psz_name ) {\ int index = ui.deviceCombo->findText( qfu( psz_name ) ); \ if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}#else #define setDrive( psz_name ) {\ ui.deviceCombo->setEditText( qfu( psz_name ) ); }#endif/* update the buttons according the type of device */void DiscOpenPanel::updateButtons(){ if ( ui.dvdRadioButton->isChecked() ) { if( b_firstdvd ) { setDrive( psz_dvddiscpath ); b_firstdvd = false; } ui.titleLabel->setText( qtr("Title") ); ui.chapterLabel->show(); ui.chapterSpin->show(); ui.diskOptionBox_2->show(); ui.dvdsimple->setEnabled( true ); } else if ( ui.vcdRadioButton->isChecked() ) { if( b_firstvcd ) { setDrive( psz_vcddiscpath ); b_firstvcd = false; } ui.titleLabel->setText( qtr("Entry") ); ui.chapterLabel->hide(); ui.chapterSpin->hide(); ui.diskOptionBox_2->show(); ui.dvdsimple->setEnabled( false ); } else /* CDDA */ { if( b_firstcdda ) { setDrive( psz_cddadiscpath ); b_firstcdda = false; } ui.titleLabel->setText( qtr("Track") ); ui.chapterLabel->hide(); ui.chapterSpin->hide(); ui.diskOptionBox_2->hide(); ui.dvdsimple->setEnabled( false ); } updateMRL();}/* Update the current MRL */void DiscOpenPanel::updateMRL(){ QString mrl = ""; /* CDDAX and VCDX not implemented. TODO ? */ /* DVD */ if( ui.dvdRadioButton->isChecked() ) { if( !ui.dvdsimple->isChecked() ) mrl = "\"dvd://"; else mrl = "\"dvdsimple://"; mrl += ui.deviceCombo->currentText(); emit methodChanged( "dvdnav-caching" ); if ( ui.titleSpin->value() > 0 ) { mrl += QString("@%1").arg( ui.titleSpin->value() ); if ( ui.chapterSpin->value() > 0 ) { mrl+= QString(":%1").arg( ui.chapterSpin->value() ); } } /* VCD */ } else if ( ui.vcdRadioButton->isChecked() ) { mrl = "\"vcd://" + ui.deviceCombo->currentText(); emit methodChanged( "vcd-caching" ); if( ui.titleSpin->value() > 0 ) { mrl += QString("@E%1").arg( ui.titleSpin->value() ); } /* CDDA */ } else { mrl = "\"cdda://" + ui.deviceCombo->currentText(); if( ui.titleSpin->value() > 0 ) { QString("@%1").arg( ui.titleSpin->value() ); } } mrl += "\""; if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() ) { if ( ui.audioSpin->value() >= 0 ) { mrl += " :audio-track=" + QString("%1").arg( ui.audioSpin->value() ); } if ( ui.subtitlesSpin->value() >= 0 ) { mrl += " :sub-track=" + QString("%1").arg( ui.subtitlesSpin->value() ); } } emit mrlUpdated( mrl );}void DiscOpenPanel::browseDevice(){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -