open_panels.cpp 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. /*****************************************************************************
  2. * open_panels.cpp : Panels for the open dialogs
  3. ****************************************************************************
  4. * Copyright (C) 2006-2009 the VideoLAN team
  5. * Copyright (C) 2007 Société des arts technologiques
  6. * Copyright (C) 2007 Savoir-faire Linux
  7. *
  8. * $Id$
  9. *
  10. * Authors: Clément Stenac <zorglub@videolan.org>
  11. * Jean-Baptiste Kempf <jb@videolan.org>
  12. * Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  27. *****************************************************************************/
  28. #ifdef HAVE_CONFIG_H
  29. # include "config.h"
  30. #endif
  31. #include "qt.hpp"
  32. #include "components/open_panels.hpp"
  33. #include "dialogs/open.hpp"
  34. #include "dialogs_provider.hpp" /* Open Subtitle file */
  35. #include "util/qt_dirs.hpp"
  36. #include "util/validators.hpp"
  37. #include <vlc_intf_strings.h>
  38. #include <vlc_modules.h>
  39. #include <vlc_plugin.h>
  40. #ifdef _WIN32
  41. #include <vlc_charset.h> /* FromWide for Win32 */
  42. #endif
  43. #include <QFileDialog>
  44. #include <QDialogButtonBox>
  45. #include <QLineEdit>
  46. #include <QStackedLayout>
  47. #include <QCompleter>
  48. #include <QDirModel>
  49. #include <QScrollArea>
  50. #include <QUrl>
  51. #include <QMimeData>
  52. #include <QDropEvent>
  53. #define I_DEVICE_TOOLTIP \
  54. I_DIR_OR_FOLDER( N_("Select a device or a VIDEO_TS directory"), \
  55. N_("Select a device or a VIDEO_TS folder") )
  56. #include "../../eject.c"
  57. /* Populate a combobox with the devices matching a pattern.
  58. Combobox will automatically do autocompletion on the edit zone */
  59. #define POPULATE_WITH_DEVS(ppsz_devlist, targetCombo) \
  60. QStringList targetCombo ## StringList = QStringList(); \
  61. for ( size_t i = 0; i< sizeof(ppsz_devlist) / sizeof(*ppsz_devlist); i++ ) \
  62. targetCombo ## StringList << QString( ppsz_devlist[ i ] ); \
  63. targetCombo->addItems( QDir( "/dev/" )\
  64. .entryList( targetCombo ## StringList, QDir::System )\
  65. .replaceInStrings( QRegExp("^"), "/dev/" ) \
  66. );
  67. static const char psz_devModule[][8] = { "v4l2", "pvr", "dtv",
  68. "dshow", "screen", "jack" };
  69. /**************************************************************************
  70. * Open Files and subtitles *
  71. **************************************************************************/
  72. FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
  73. OpenPanel( _parent, _p_intf ), dialogBox( NULL )
  74. {
  75. /* Classic UI Setup */
  76. ui.setupUi( this );
  77. setAcceptDrops( true );
  78. /* Set Filters for file selection */
  79. /* QString fileTypes = "";
  80. ADD_FILTER_MEDIA( fileTypes );
  81. ADD_FILTER_VIDEO( fileTypes );
  82. ADD_FILTER_AUDIO( fileTypes );
  83. ADD_FILTER_PLAYLIST( fileTypes );
  84. ADD_FILTER_ALL( fileTypes );
  85. fileTypes.replace( QString(";*"), QString(" *")); */
  86. /* lineFileEdit = ui.fileEdit;
  87. //TODO later: fill the fileCompleteList with previous items played.
  88. QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
  89. fileCompleter->setModel( new QDirModel( fileCompleter ) );
  90. lineFileEdit->setCompleter( fileCompleter );*/
  91. if( var_InheritBool( p_intf, "qt-embedded-open" ) )
  92. {
  93. ui.tempWidget->hide();
  94. BuildOldPanel();
  95. }
  96. /* Subtitles */
  97. /* Deactivate the subtitles control by default. */
  98. ui.subGroupBox->setEnabled( false );
  99. /* Connects */
  100. BUTTONACT( ui.fileBrowseButton, browseFile() );
  101. BUTTONACT( ui.removeFileButton, removeFile() );
  102. BUTTONACT( ui.subBrowseButton, browseFileSub() );
  103. CONNECT( ui.subGroupBox, toggled( bool ), this, updateMRL() );
  104. CONNECT( ui.fileListWidg, itemChanged( QListWidgetItem * ), this, updateMRL() );
  105. CONNECT( ui.subInput, textChanged( const QString& ), this, updateMRL() );
  106. updateButtons();
  107. }
  108. inline void FileOpenPanel::BuildOldPanel()
  109. {
  110. /** BEGIN QFileDialog tweaking **/
  111. /* Use a QFileDialog and customize it because we don't want to
  112. rewrite it all. Be careful to your eyes cause there are a few hacks.
  113. Be very careful and test correctly when you modify this. */
  114. /* Make this QFileDialog a child of tempWidget from the ui. */
  115. dialogBox = new FileOpenBox( ui.tempWidget, NULL,
  116. p_intf->p_sys->filepath, "" );
  117. dialogBox->setFileMode( QFileDialog::ExistingFiles );
  118. dialogBox->setAcceptMode( QFileDialog::AcceptOpen );
  119. dialogBox->restoreState(
  120. getSettings()->value( "file-dialog-state" ).toByteArray() );
  121. /* We don't want to see a grip in the middle of the window, do we? */
  122. dialogBox->setSizeGripEnabled( false );
  123. /* Add a tooltip */
  124. dialogBox->setToolTip( qtr( "Select one or multiple files" ) );
  125. dialogBox->setMinimumHeight( 250 );
  126. // But hide the two OK/Cancel buttons. Enable them for debug.
  127. QDialogButtonBox *fileDialogAcceptBox =
  128. dialogBox->findChildren<QDialogButtonBox*>()[0];
  129. fileDialogAcceptBox->hide();
  130. /* Ugly hacks to get the good Widget */
  131. //This lineEdit is the normal line in the fileDialog.
  132. QLineEdit *lineFileEdit = dialogBox->findChildren<QLineEdit*>()[0];
  133. /* Make a list of QLabel inside the QFileDialog to access the good ones */
  134. QList<QLabel *> listLabel = dialogBox->findChildren<QLabel*>();
  135. /* Hide the FileNames one. Enable it for debug */
  136. listLabel[1]->setText( qtr( "File names:" ) );
  137. /* Change the text that was uncool in the usual box */
  138. listLabel[2]->setText( qtr( "Filter:" ) );
  139. dialogBox->layout()->setMargin( 0 );
  140. dialogBox->layout()->setSizeConstraint( QLayout::SetNoConstraint );
  141. /** END of QFileDialog tweaking **/
  142. // Add the DialogBox to the layout
  143. ui.gridLayout->addWidget( dialogBox, 0, 0, 1, 3 );
  144. CONNECT( lineFileEdit, textChanged( const QString& ), this, updateMRL() );
  145. dialogBox->installEventFilter( this );
  146. }
  147. FileOpenPanel::~FileOpenPanel()
  148. {
  149. if( dialogBox )
  150. getSettings()->setValue( "file-dialog-state", dialogBox->saveState() );
  151. }
  152. void FileOpenPanel::dragEnterEvent( QDragEnterEvent *event )
  153. {
  154. event->acceptProposedAction();
  155. }
  156. void FileOpenPanel::dragMoveEvent( QDragMoveEvent *event )
  157. {
  158. event->acceptProposedAction();
  159. }
  160. void FileOpenPanel::dragLeaveEvent( QDragLeaveEvent *event )
  161. {
  162. event->accept();
  163. }
  164. void FileOpenPanel::dropEvent( QDropEvent *event )
  165. {
  166. if( event->possibleActions() & Qt::CopyAction )
  167. event->setDropAction( Qt::CopyAction );
  168. else
  169. return;
  170. const QMimeData *mimeData = event->mimeData();
  171. foreach( const QUrl &url, mimeData->urls() )
  172. {
  173. if( url.isValid() )
  174. {
  175. QListWidgetItem *item = new QListWidgetItem(
  176. toNativeSeparators( url.toLocalFile() ),
  177. ui.fileListWidg );
  178. item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
  179. ui.fileListWidg->addItem( item );
  180. }
  181. }
  182. updateMRL();
  183. updateButtons();
  184. event->accept();
  185. }
  186. void FileOpenPanel::browseFile()
  187. {
  188. QStringList files = QFileDialog::getOpenFileNames( this, qtr( "Select one or multiple files" ), p_intf->p_sys->filepath );
  189. foreach( const QString &file, files )
  190. {
  191. QListWidgetItem *item =
  192. new QListWidgetItem( toNativeSeparators( file ), ui.fileListWidg );
  193. item->setFlags( Qt::ItemIsEditable | Qt::ItemIsEnabled );
  194. ui.fileListWidg->addItem( item );
  195. savedirpathFromFile( file );
  196. }
  197. updateButtons();
  198. updateMRL();
  199. }
  200. void FileOpenPanel::removeFile()
  201. {
  202. int i = ui.fileListWidg->currentRow();
  203. if( i != -1 )
  204. {
  205. QListWidgetItem *temp = ui.fileListWidg->takeItem( i );
  206. delete temp;
  207. }
  208. updateMRL();
  209. updateButtons();
  210. }
  211. /* Show a fileBrowser to select a subtitle */
  212. void FileOpenPanel::browseFileSub()
  213. {
  214. // TODO Handle selection of more than one subtitles file
  215. QStringList urls = THEDP->showSimpleOpen( qtr("Open subtitle file"),
  216. EXT_FILTER_SUBTITLE, p_intf->p_sys->filepath );
  217. if( urls.isEmpty() ) return;
  218. ui.subInput->setText( urls.join(" ") );
  219. updateMRL();
  220. }
  221. /* Update the current MRL */
  222. void FileOpenPanel::updateMRL()
  223. {
  224. QStringList fileList;
  225. QString mrl;
  226. /* File Listing */
  227. if( dialogBox == NULL )
  228. for( int i = 0; i < ui.fileListWidg->count(); i++ )
  229. {
  230. if( !ui.fileListWidg->item( i )->text().isEmpty() )
  231. fileList << toURI(ui.fileListWidg->item( i )->text());
  232. }
  233. else
  234. {
  235. #if HAS_QT5
  236. QList<QUrl> urls = dialogBox->selectedUrls();
  237. foreach( const QUrl &url, urls )
  238. fileList.append( url.toEncoded() );
  239. #else
  240. fileList = dialogBox->selectedFiles();
  241. for( int i = 0; i < fileList.count(); i++ )
  242. fileList[i] = toURI( fileList[i] );
  243. #endif
  244. }
  245. /* Options */
  246. if( ui.subGroupBox->isChecked() && !ui.subInput->text().isEmpty() ) {
  247. mrl.append( " :sub-file=" + colon_escape( ui.subInput->text() ) );
  248. }
  249. emit methodChanged( "file-caching" );
  250. emit mrlUpdated( fileList, mrl );
  251. }
  252. /* Function called by Open Dialog when clicke on Play/Enqueue */
  253. void FileOpenPanel::accept()
  254. {
  255. if( dialogBox )
  256. p_intf->p_sys->filepath = dialogBox->directory().absolutePath();
  257. ui.fileListWidg->clear();
  258. }
  259. /* Function called by Open Dialog when clicked on cancel */
  260. void FileOpenPanel::clear()
  261. {
  262. ui.fileListWidg->clear();
  263. ui.subInput->clear();
  264. }
  265. /* Update buttons depending on current selection */
  266. void FileOpenPanel::updateButtons()
  267. {
  268. bool b_has_files = ( ui.fileListWidg->count() > 0 );
  269. ui.removeFileButton->setEnabled( b_has_files );
  270. ui.subGroupBox->setEnabled( b_has_files );
  271. }
  272. /**************************************************************************
  273. * Open Discs ( DVD, CD, VCD and similar devices ) *
  274. **************************************************************************/
  275. DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
  276. OpenPanel( _parent, _p_intf )
  277. {
  278. ui.setupUi( this );
  279. /* Get the default configuration path for the devices */
  280. psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
  281. psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
  282. psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
  283. /* State to avoid overwritting the users changes with the configuration */
  284. m_discType = None;
  285. ui.browseDiscButton->setToolTip( qtr( I_DEVICE_TOOLTIP ));
  286. ui.deviceCombo->setToolTip( qtr(I_DEVICE_TOOLTIP) );
  287. ui.deviceCombo->setInsertPolicy( QComboBox::InsertAtTop );
  288. #if !defined( _WIN32 ) && !defined( __OS2__ )
  289. char const * const ppsz_discdevices[] = {
  290. "sr*",
  291. "sg*",
  292. "scd*",
  293. "dvd*",
  294. "cd*"
  295. };
  296. QComboBox *discCombo = ui.deviceCombo; /* avoid namespacing in macro */
  297. POPULATE_WITH_DEVS( ppsz_discdevices, discCombo );
  298. char *psz_config = config_GetPsz( p_intf, "dvd" );
  299. int temp = ui.deviceCombo->findData( psz_config, Qt::UserRole, Qt::MatchStartsWith );
  300. free( psz_config );
  301. if( temp != -1 )
  302. ui.deviceCombo->setCurrentIndex( temp );
  303. #endif
  304. /* CONNECTs */
  305. BUTTONACT( ui.dvdRadioButton, updateButtons() );
  306. BUTTONACT( ui.bdRadioButton, updateButtons() );
  307. BUTTONACT( ui.vcdRadioButton, updateButtons() );
  308. BUTTONACT( ui.audioCDRadioButton, updateButtons() );
  309. BUTTONACT( ui.dvdsimple, updateButtons() );
  310. BUTTONACT( ui.browseDiscButton, browseDevice() );
  311. BUTTON_SET_ACT_I( ui.ejectButton, "", toolbar/eject, qtr( "Eject the disc" ),
  312. eject() );
  313. CONNECT( ui.deviceCombo, editTextChanged( QString ), this, updateMRL());
  314. CONNECT( ui.deviceCombo, currentIndexChanged( QString ), this, updateMRL());
  315. CONNECT( ui.titleSpin, valueChanged( int ), this, updateMRL());
  316. CONNECT( ui.chapterSpin, valueChanged( int ), this, updateMRL());
  317. CONNECT( ui.audioSpin, valueChanged( int ), this, updateMRL());
  318. CONNECT( ui.subtitlesSpin, valueChanged( int ), this, updateMRL());
  319. CONNECT( ui.dvdsimple, toggled( bool ), this, updateMRL());
  320. /* Run once the updateButtons function in order to fill correctly the comboBoxes */
  321. updateButtons();
  322. }
  323. #ifdef _WIN32 /* Disc drives probing for Windows */
  324. void DiscOpenPanel::onFocus()
  325. {
  326. ui.deviceCombo->clear();
  327. wchar_t szDrives[512];
  328. szDrives[0] = '\0';
  329. if( GetLogicalDriveStringsW( sizeof( szDrives ) - 1, szDrives ) )
  330. {
  331. wchar_t *drive = szDrives;
  332. UINT oldMode = SetErrorMode( SEM_FAILCRITICALERRORS );
  333. while( *drive )
  334. {
  335. if( GetDriveTypeW(drive) == DRIVE_CDROM )
  336. {
  337. wchar_t psz_name[512] = L"";
  338. GetVolumeInformationW( drive, psz_name, 511, NULL, NULL, NULL, NULL, 0 );
  339. char *psz_drive = FromWide( drive );
  340. QString displayName = psz_drive;
  341. char *psz_title = FromWide( psz_name );
  342. if( !EMPTY_STR(psz_title)) {
  343. displayName = displayName + " - " + psz_title;
  344. }
  345. ui.deviceCombo->addItem( displayName, psz_drive );
  346. free( psz_drive );
  347. free( psz_title );
  348. }
  349. /* go to next drive */
  350. while( *(drive++) );
  351. }
  352. SetErrorMode(oldMode);
  353. }
  354. char *psz_config = config_GetPsz( p_intf, "dvd" );
  355. int temp = ui.deviceCombo->findData( psz_config, Qt::UserRole, Qt::MatchStartsWith );
  356. free( psz_config );
  357. if( temp != -1 )
  358. ui.deviceCombo->setCurrentIndex( temp );
  359. }
  360. #elif defined( __OS2__ ) /* Disc drives probing for OS/2 */
  361. void DiscOpenPanel::onFocus()
  362. {
  363. ui.deviceCombo->clear();
  364. #define IOCTL_CDROMDISK2 0x82
  365. #define CDROMDISK2_DRIVELETTERS 0x60
  366. HFILE hcd2;
  367. ULONG ulAction;
  368. ULONG ulParamLen;
  369. ULONG ulData;
  370. ULONG ulDataLen;
  371. if( DosOpen(( PSZ )"CD-ROM2$", ( PHFILE )&hcd2, &ulAction, 0, FILE_NORMAL,
  372. OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW,
  373. OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE,
  374. NULL ))
  375. return;
  376. if( !DosDevIOCtl( hcd2, IOCTL_CDROMDISK2, CDROMDISK2_DRIVELETTERS,
  377. NULL, 0, &ulParamLen, &ulData, sizeof( ulData ), &ulDataLen ))
  378. {
  379. char szDriveName[] = "X:\\";
  380. int count = LOUSHORT( ulData );
  381. int drive = HIUSHORT( ulData );
  382. for( ; count; --count, ++drive )
  383. {
  384. szDriveName[ 0 ] = 'A' + drive;
  385. QString name = qfu( szDriveName );
  386. ui.deviceCombo->addItem( name, name );
  387. }
  388. }
  389. DosClose( hcd2 );
  390. }
  391. #endif
  392. void DiscOpenPanel::updateContext(int c)
  393. {
  394. OpenPanel::updateContext(c);
  395. ui.dvdsimple->setChecked( context == OpenPanel::CONTEXT_BATCH );
  396. }
  397. DiscOpenPanel::~DiscOpenPanel()
  398. {
  399. free( psz_dvddiscpath );
  400. free( psz_vcddiscpath );
  401. free( psz_cddadiscpath );
  402. }
  403. void DiscOpenPanel::clear()
  404. {
  405. ui.titleSpin->setValue( 0 );
  406. ui.chapterSpin->setValue( 0 );
  407. ui.subtitlesSpin->setValue( -1 );
  408. ui.audioSpin->setValue( -1 );
  409. m_discType = None;
  410. }
  411. #if defined( _WIN32 ) || defined( __OS2__ )
  412. #define setDrive( psz_name ) {\
  413. int index = ui.deviceCombo->findText( qfu( psz_name ) ); \
  414. if( index != -1 ) ui.deviceCombo->setCurrentIndex( index );}
  415. #else
  416. #define setDrive( psz_name ) {\
  417. ui.deviceCombo->setEditText( qfu( psz_name ) ); }
  418. #endif
  419. /* update the buttons according the type of device */
  420. void DiscOpenPanel::updateButtons()
  421. {
  422. if ( ui.dvdRadioButton->isChecked() )
  423. {
  424. if( m_discType != Dvd )
  425. {
  426. setDrive( psz_dvddiscpath );
  427. m_discType = Dvd;
  428. }
  429. ui.titleLabel->setText( qtr("Title") );
  430. ui.chapterLabel->show();
  431. ui.chapterSpin->show();
  432. ui.diskOptionBox_2->show();
  433. ui.dvdsimple->setEnabled( true );
  434. }
  435. else if ( ui.bdRadioButton->isChecked() )
  436. {
  437. if( m_discType != BRD )
  438. {
  439. setDrive( psz_dvddiscpath );
  440. m_discType = BRD;
  441. ui.dvdsimple->setChecked( !var_InheritBool( p_intf, "bluray-menu" ) );
  442. }
  443. ui.titleLabel->setText( qtr("Title") );
  444. ui.chapterLabel->hide();
  445. ui.chapterSpin->hide();
  446. ui.diskOptionBox_2->hide();
  447. ui.dvdsimple->setEnabled( true );
  448. }
  449. else if ( ui.vcdRadioButton->isChecked() )
  450. {
  451. if( m_discType != Vcd )
  452. {
  453. setDrive( psz_vcddiscpath );
  454. m_discType = Vcd;
  455. }
  456. ui.titleLabel->setText( qtr("Entry") );
  457. ui.chapterLabel->hide();
  458. ui.chapterSpin->hide();
  459. ui.diskOptionBox_2->show();
  460. ui.dvdsimple->setEnabled( false );
  461. }
  462. else /* CDDA */
  463. {
  464. if( m_discType != Cdda )
  465. {
  466. setDrive( psz_cddadiscpath );
  467. m_discType = Cdda;
  468. }
  469. ui.titleLabel->setText( qtr("Track") );
  470. ui.chapterLabel->hide();
  471. ui.chapterSpin->hide();
  472. ui.diskOptionBox_2->hide();
  473. ui.dvdsimple->setEnabled( false );
  474. }
  475. updateMRL();
  476. }
  477. #undef setDrive
  478. /* Update the current MRL */
  479. void DiscOpenPanel::updateMRL()
  480. {
  481. QString discPath;
  482. QStringList fileList;
  483. discPath = ui.deviceCombo->currentText();
  484. int tmp = ui.deviceCombo->findText( discPath );
  485. if( tmp != -1 && ui.deviceCombo->itemData( tmp ) != QVariant::Invalid )
  486. discPath = ui.deviceCombo->itemData( tmp ).toString();
  487. /* MRL scheme */
  488. const char *scheme;
  489. /* DVD */
  490. if( ui.dvdRadioButton->isChecked() ) {
  491. if( !ui.dvdsimple->isChecked() )
  492. scheme = "dvd";
  493. else
  494. scheme = "dvdsimple";
  495. } else if ( ui.bdRadioButton->isChecked() )
  496. scheme = "bluray";
  497. /* VCD */
  498. else if ( ui.vcdRadioButton->isChecked() )
  499. scheme = "vcd";
  500. /* CDDA */
  501. else
  502. scheme = "cdda";
  503. char *mrl = vlc_path2uri( qtu(discPath), scheme );
  504. if( unlikely(mrl == NULL) )
  505. return;
  506. /* Title/chapter encoded in MRL */
  507. QString anchor = "";
  508. if( ui.titleSpin->value() > 0 ) {
  509. if( ui.dvdRadioButton->isChecked() || ui.bdRadioButton->isChecked() ) {
  510. anchor = QString("#%1").arg( ui.titleSpin->value() );
  511. if ( ui.chapterSpin->value() > 0 )
  512. anchor += QString(":%1").arg( ui.chapterSpin->value() );
  513. }
  514. else if ( ui.vcdRadioButton->isChecked() )
  515. anchor = QString("#%1").arg( ui.titleSpin->value() );
  516. }
  517. emit methodChanged( "disc-caching" );
  518. fileList << (qfu(mrl) + anchor);
  519. free(mrl);
  520. QString opts = "";
  521. /* Input item options */
  522. if ( ui.dvdRadioButton->isChecked() || ui.vcdRadioButton->isChecked() )
  523. {
  524. if ( ui.audioSpin->value() >= 0 )
  525. opts += " :audio-track=" +
  526. QString("%1").arg( ui.audioSpin->value() );
  527. if ( ui.subtitlesSpin->value() >= 0 )
  528. opts += " :sub-track=" +
  529. QString("%1").arg( ui.subtitlesSpin->value() );
  530. }
  531. else if( ui.audioCDRadioButton->isChecked() )
  532. {
  533. if( ui.titleSpin->value() > 0 )
  534. opts += QString(" :cdda-track=%1").arg( ui.titleSpin->value() );
  535. }
  536. else if ( ui.bdRadioButton->isChecked() )
  537. {
  538. if ( ui.dvdsimple->isChecked() )
  539. opts += " :no-bluray-menu";
  540. }
  541. emit mrlUpdated( fileList, opts );
  542. }
  543. void DiscOpenPanel::browseDevice()
  544. {
  545. QString dir = QFileDialog::getExistingDirectory( this,
  546. qtr( I_DEVICE_TOOLTIP ), p_intf->p_sys->filepath );
  547. if( !dir.isEmpty() )
  548. {
  549. ui.deviceCombo->addItem( toNativeSepNoSlash( dir ) );
  550. ui.deviceCombo->setCurrentIndex( ui.deviceCombo->findText( toNativeSepNoSlash( dir ) ) );
  551. }
  552. updateMRL();
  553. }
  554. void DiscOpenPanel::eject()
  555. {
  556. intf_Eject( p_intf, qtu( ui.deviceCombo->currentText() ) );
  557. }
  558. void DiscOpenPanel::accept()
  559. {}
  560. /**************************************************************************
  561. * Open Network streams and URL pages *
  562. **************************************************************************/
  563. NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
  564. OpenPanel( _parent, _p_intf )
  565. {
  566. ui.setupUi( this );
  567. CONNECT( ui.urlComboBox, editTextChanged( const QString& ), this, updateMRL());
  568. /* */
  569. if( var_InheritBool( p_intf, "qt-recentplay" ) )
  570. {
  571. b_recentList = true;
  572. ui.urlComboBox->addItems( getSettings()->value( "OpenDialog/netMRL" ).toStringList() );
  573. ui.urlComboBox->setMaxCount( 10 );
  574. }
  575. else
  576. b_recentList = false;
  577. QFont smallFont = QApplication::font();
  578. smallFont.setPointSize( smallFont.pointSize() - 1 );
  579. ui.examples->setFont( smallFont );
  580. /* Use a simple validator for URLs */
  581. ui.urlComboBox->setValidator( new UrlValidator( this ) );
  582. ui.urlComboBox->setFocus();
  583. }
  584. NetOpenPanel::~NetOpenPanel()
  585. {
  586. if( !b_recentList ) return;
  587. /* Create the list with the current items */
  588. QStringList mrlList;
  589. for( int i = 0; i < ui.urlComboBox->count(); i++ )
  590. mrlList << ui.urlComboBox->itemText( i );
  591. if( mrlList.count() > 0 )
  592. {
  593. /* Clean the list... */
  594. mrlList.removeDuplicates();
  595. /* ...and save the 8 last entries */
  596. getSettings()->setValue( "OpenDialog/netMRL", mrlList );
  597. }
  598. }
  599. void NetOpenPanel::clear()
  600. {
  601. ui.urlComboBox->lineEdit()->clear();
  602. }
  603. void NetOpenPanel::onAccept()
  604. {
  605. if( ui.urlComboBox->findText( ui.urlComboBox->currentText() ) == -1 )
  606. ui.urlComboBox->insertItem( 0, ui.urlComboBox->currentText());
  607. }
  608. void NetOpenPanel::onFocus()
  609. {
  610. ui.urlComboBox->setFocus();
  611. ui.urlComboBox->lineEdit()->selectAll();
  612. }
  613. void NetOpenPanel::updateMRL()
  614. {
  615. QString url = ui.urlComboBox->lineEdit()->text();
  616. emit methodChanged( qfu( "network-caching" ) );
  617. QStringList qsl;
  618. if( !url.isEmpty() ) qsl << url;
  619. emit mrlUpdated( qsl, "" );
  620. }
  621. /**************************************************************************
  622. * Open Capture device ( DVB, PVR, V4L, and similar ) *
  623. **************************************************************************/
  624. CaptureOpenPanel::CaptureOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
  625. OpenPanel( _parent, _p_intf )
  626. {
  627. isInitialized = false;
  628. #ifdef _WIN32
  629. vdevDshowW = NULL;
  630. adevDshowW = NULL;
  631. #endif
  632. }
  633. void CaptureOpenPanel::initialize()
  634. {
  635. if( isInitialized ) return;
  636. isInitialized = true;
  637. ui.setupUi( this );
  638. BUTTONACT( ui.advancedButton, advancedDialog() );
  639. CONNECT( ui.deviceCombo, currentIndexChanged(int), this, enableAdvancedDialog(int) );
  640. /* Create two stacked layouts in the main comboBoxes */
  641. QStackedLayout *stackedDevLayout = new QStackedLayout;
  642. ui.cardBox->setLayout( stackedDevLayout );
  643. QStackedLayout *stackedPropLayout = new QStackedLayout;
  644. ui.optionsBox->setLayout( stackedPropLayout );
  645. /* Creation and connections of the WIdgets in the stacked layout */
  646. #define addModuleAndLayouts( number, name, label, layout ) \
  647. QWidget * name ## DevPage = new QWidget( this ); \
  648. QWidget * name ## PropPage = new QWidget( this ); \
  649. stackedDevLayout->addWidget( name ## DevPage ); \
  650. stackedPropLayout->addWidget( name ## PropPage ); \
  651. layout * name ## DevLayout = new layout; \
  652. layout * name ## PropLayout = new layout; \
  653. name ## DevPage->setLayout( name ## DevLayout ); \
  654. name ## PropPage->setLayout( name ## PropLayout ); \
  655. ui.deviceCombo->addItem( qtr( label ), QVariant( number ) );
  656. #define CuMRL( widget, slot ) CONNECT( widget , slot , this, updateMRL() );
  657. #ifdef _WIN32
  658. /*********************
  659. * DirectShow Stuffs *
  660. *********************/
  661. if( module_exists( "dshow" ) ){
  662. addModuleAndLayouts( DSHOW_DEVICE, dshow, "DirectShow", QGridLayout );
  663. /* dshow Main */
  664. int line = 0;
  665. module_config_t *p_config =
  666. config_FindConfig( VLC_OBJECT(p_intf), "dshow-vdev" );
  667. vdevDshowW = new StringListConfigControl(
  668. VLC_OBJECT(p_intf), p_config, this );
  669. vdevDshowW->insertIntoExistingGrid( dshowDevLayout, line );
  670. line++;
  671. p_config = config_FindConfig( VLC_OBJECT(p_intf), "dshow-adev" );
  672. adevDshowW = new StringListConfigControl(
  673. VLC_OBJECT(p_intf), p_config, this );
  674. adevDshowW->insertIntoExistingGrid( dshowDevLayout, line );
  675. line++;
  676. /* dshow Properties */
  677. QLabel *dshowVSizeLabel = new QLabel( qtr( "Video size" ) );
  678. dshowPropLayout->addWidget( dshowVSizeLabel, 0, 0 );
  679. dshowVSizeLine = new QLineEdit;
  680. dshowPropLayout->addWidget( dshowVSizeLine, 0, 1);
  681. dshowPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
  682. 1, 0, 3, 1 );
  683. /* dshow CONNECTs */
  684. CuMRL( vdevDshowW, changed() );
  685. CuMRL( adevDshowW, changed() );
  686. CuMRL( dshowVSizeLine, textChanged( const QString& ) );
  687. configList << "dshow-vdev" << "dshow-adev" << "dshow-size";
  688. }
  689. #else /* _WIN32 */
  690. /*******
  691. * V4L2*
  692. *******/
  693. char const * const ppsz_v4lvdevices[] = {
  694. "video*"
  695. };
  696. if( module_exists( "v4l2" ) ){
  697. addModuleAndLayouts( V4L2_DEVICE, v4l2, "Video camera", QGridLayout );
  698. /* V4L2 main panel */
  699. QLabel *v4l2VideoDeviceLabel = new QLabel( qtr( "Video device name" ) );
  700. v4l2DevLayout->addWidget( v4l2VideoDeviceLabel, 0, 0 );
  701. v4l2VideoDevice = new QComboBox( this );
  702. v4l2VideoDevice->setEditable( true );
  703. POPULATE_WITH_DEVS( ppsz_v4lvdevices, v4l2VideoDevice );
  704. v4l2DevLayout->addWidget( v4l2VideoDevice, 0, 1 );
  705. QLabel *v4l2AudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
  706. v4l2DevLayout->addWidget( v4l2AudioDeviceLabel, 1, 0 );
  707. v4l2AudioDevice = new QComboBox( this );
  708. v4l2AudioDevice->setEditable( true );
  709. {
  710. QStringList patterns = QStringList();
  711. patterns << QString( "pcmC*D*c" );
  712. QStringList nodes = QDir( "/dev/snd" ).entryList( patterns,
  713. QDir::System );
  714. QStringList names = nodes.replaceInStrings( QRegExp("^pcmC"), "hw:" )
  715. .replaceInStrings( QRegExp("c$"), "" )
  716. .replaceInStrings( QRegExp("D"), "," );
  717. v4l2AudioDevice->addItems( names );
  718. }
  719. v4l2AudioDevice->clearEditText();
  720. v4l2DevLayout->addWidget( v4l2AudioDevice, 1, 1 );
  721. /* v4l2 Props panel */
  722. QLabel *v4l2StdLabel = new QLabel( qtr( "Video standard" ) );
  723. v4l2PropLayout->addWidget( v4l2StdLabel, 0 , 0 );
  724. v4l2StdBox = new QComboBox;
  725. setfillVLCConfigCombo( "v4l2-standard", p_intf, v4l2StdBox );
  726. v4l2PropLayout->addWidget( v4l2StdBox, 0 , 1 );
  727. v4l2PropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
  728. 1, 0, 3, 2 );
  729. /* v4l2 CONNECTs */
  730. CuMRL( v4l2VideoDevice->lineEdit(), textChanged( const QString& ) );
  731. CuMRL( v4l2VideoDevice, currentIndexChanged ( int ) );
  732. CuMRL( v4l2AudioDevice->lineEdit(), textChanged( const QString& ) );
  733. CuMRL( v4l2AudioDevice, currentIndexChanged ( int ) );
  734. CuMRL( v4l2StdBox, currentIndexChanged ( int ) );
  735. configList << "v4l2-standard";
  736. }
  737. /*******
  738. * JACK *
  739. *******/
  740. if( module_exists( "jack" ) ){
  741. addModuleAndLayouts( JACK_DEVICE, jack, "JACK Audio Connection Kit",
  742. QGridLayout);
  743. /* Jack Main panel */
  744. /* Channels */
  745. QLabel *jackChannelsLabel = new QLabel( qtr( "Channels:" ) );
  746. jackDevLayout->addWidget( jackChannelsLabel, 1, 0 );
  747. jackChannels = new QSpinBox;
  748. setSpinBoxFreq( jackChannels );
  749. jackChannels->setMaximum(255);
  750. jackChannels->setValue(2);
  751. jackChannels->setAlignment( Qt::AlignRight );
  752. jackDevLayout->addWidget( jackChannels, 1, 1 );
  753. /* Selected ports */
  754. QLabel *jackPortsLabel = new QLabel( qtr( "Selected ports:" ) );
  755. jackDevLayout->addWidget( jackPortsLabel, 0 , 0 );
  756. jackPortsSelected = new QLineEdit( qtr( ".*") );
  757. jackPortsSelected->setAlignment( Qt::AlignRight );
  758. jackDevLayout->addWidget( jackPortsSelected, 0, 1 );
  759. /* Jack Props panel */
  760. /* Pace */
  761. jackPace = new QCheckBox(qtr( "Use VLC pace" ));
  762. jackPropLayout->addWidget( jackPace, 1, 1 );
  763. /* Auto Connect */
  764. jackConnect = new QCheckBox( qtr( "Auto connection" ));
  765. jackPropLayout->addWidget( jackConnect, 1, 2 );
  766. /* Jack CONNECTs */
  767. CuMRL( jackChannels, valueChanged( int ) );
  768. CuMRL( jackPace, stateChanged( int ) );
  769. CuMRL( jackConnect, stateChanged( int ) );
  770. CuMRL( jackPortsSelected, textChanged( const QString& ) );
  771. configList << "jack-input-use-vlc-pace" << "jack-input-auto-connect";
  772. }
  773. #endif
  774. /*************
  775. * DVB Stuff *
  776. *************/
  777. if( module_exists( "dtv" ) ){
  778. addModuleAndLayouts( DTV_DEVICE, dvb, N_("TV - digital"), QGridLayout );
  779. /* DVB Main */
  780. QLabel *dvbDeviceLabel = new QLabel( qtr( "Tuner card" ) );
  781. QLabel *dvbTypeLabel = new QLabel( qtr( "Delivery system" ) );
  782. dvbCard = new QSpinBox;
  783. dvbCard->setAlignment( Qt::AlignRight );
  784. #ifdef __unix__
  785. dvbCard->setPrefix( "/dev/dvb/adapter" );
  786. #endif
  787. dvbDevLayout->addWidget( dvbDeviceLabel, 0, 0 );
  788. dvbDevLayout->addWidget( dvbCard, 0, 1, 1, 2 );
  789. dvbc = new QRadioButton( "DVB-C" );
  790. dvbs = new QRadioButton( "DVB-S" );
  791. dvbs2 = new QRadioButton( "DVB-S2" );
  792. dvbt = new QRadioButton( "DVB-T" );
  793. dvbt2 = new QRadioButton( "DVB-T2" );
  794. atsc = new QRadioButton( "ATSC" );
  795. cqam = new QRadioButton( "Clear QAM" );
  796. dvbt->setChecked( true );
  797. dvbDevLayout->addWidget( dvbTypeLabel, 1, 0, 2, 1 );
  798. dvbDevLayout->addWidget( dvbc, 1, 1 );
  799. dvbDevLayout->addWidget( dvbs, 1, 2 );
  800. dvbDevLayout->addWidget( dvbs2, 2, 2 );
  801. dvbDevLayout->addWidget( dvbt, 1, 3 );
  802. dvbDevLayout->addWidget( dvbt2, 2, 3 );
  803. dvbDevLayout->addWidget( atsc, 1, 4 );
  804. dvbDevLayout->addWidget( cqam, 2, 4 );
  805. /* DVB Props panel */
  806. QLabel *dvbFreqLabel =
  807. new QLabel( qtr( "Transponder/multiplex frequency" ) );
  808. dvbPropLayout->addWidget( dvbFreqLabel, 0, 0 );
  809. dvbFreq = new QSpinBox;
  810. dvbFreq->setAlignment( Qt::AlignRight );
  811. dvbFreq->setSuffix(" kHz");
  812. dvbFreq->setSingleStep( 1000 );
  813. setSpinBoxFreq( dvbFreq );
  814. dvbPropLayout->addWidget( dvbFreq, 0, 1 );
  815. dvbSrateLabel = new QLabel( qtr( "Transponder symbol rate" ) );
  816. dvbPropLayout->addWidget( dvbSrateLabel, 1, 0 );
  817. dvbSrate = new QSpinBox;
  818. dvbSrate->setAlignment( Qt::AlignRight );
  819. dvbSrate->setSuffix(" bauds");
  820. setSpinBoxFreq( dvbSrate );
  821. dvbPropLayout->addWidget( dvbSrate, 1, 1 );
  822. dvbModLabel = new QLabel( qtr( "Modulation / Constellation" ) );
  823. dvbPropLayout->addWidget( dvbModLabel, 2, 0 );
  824. dvbQamBox = new QComboBox;
  825. dvbQamBox->addItem( qtr( "Automatic" ), qfu("QAM") );
  826. dvbQamBox->addItem( "256-QAM", qfu("256QAM") );
  827. dvbQamBox->addItem( "128-QAM", qfu("128QAM") );
  828. dvbQamBox->addItem( "64-QAM", qfu("64QAM") );
  829. dvbQamBox->addItem( "32-QAM", qfu("32QAM") );
  830. dvbQamBox->addItem( "16-QAM", qfu("16QAM") );
  831. dvbPropLayout->addWidget( dvbQamBox, 2, 1 );
  832. dvbPskBox = new QComboBox;
  833. dvbPskBox->addItem( "QPSK", qfu("QPSK") );
  834. dvbPskBox->addItem( "DQPSK", qfu("DQPSK") );
  835. dvbPskBox->addItem( "8-PSK", qfu("8PSK") );
  836. dvbPskBox->addItem( "16-APSK", qfu("16APSK") );
  837. dvbPskBox->addItem( "32-APSK", qfu("32APSK") );
  838. dvbPropLayout->addWidget( dvbPskBox, 2, 1 );
  839. dvbModLabel->hide();
  840. dvbQamBox->hide();
  841. dvbPskBox->hide();
  842. dvbBandLabel = new QLabel( qtr( "Bandwidth" ) );
  843. dvbPropLayout->addWidget( dvbBandLabel, 2, 0 );
  844. dvbBandBox = new QComboBox;
  845. setfillVLCConfigCombo( "dvb-bandwidth", p_intf, dvbBandBox );
  846. dvbPropLayout->addWidget( dvbBandBox, 2, 1 );
  847. dvbBandLabel->hide();
  848. dvbBandBox->hide();
  849. dvbPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
  850. 2, 0, 2, 1 );
  851. /* DVB CONNECTs */
  852. CuMRL( dvbCard, valueChanged ( int ) );
  853. CuMRL( dvbFreq, valueChanged ( int ) );
  854. CuMRL( dvbSrate, valueChanged ( int ) );
  855. CuMRL( dvbQamBox, currentIndexChanged ( int ) );
  856. CuMRL( dvbPskBox, currentIndexChanged ( int ) );
  857. CuMRL( dvbBandBox, currentIndexChanged ( int ) );
  858. BUTTONACT( dvbc, updateButtons() );
  859. BUTTONACT( dvbs, updateButtons() );
  860. BUTTONACT( dvbs2, updateButtons() );
  861. BUTTONACT( dvbt, updateButtons() );
  862. BUTTONACT( dvbt2, updateButtons() );
  863. BUTTONACT( atsc, updateButtons() );
  864. BUTTONACT( cqam, updateButtons() );
  865. BUTTONACT( dvbc, updateMRL() );
  866. BUTTONACT( dvbt, updateMRL() );
  867. BUTTONACT( dvbt2, updateMRL() );
  868. BUTTONACT( dvbs, updateMRL() );
  869. BUTTONACT( dvbs2, updateMRL() );
  870. BUTTONACT( atsc, updateMRL() );
  871. BUTTONACT( cqam, updateMRL() );
  872. configList << "dvb-adapter" << "dvb-frequency" << "dvb-modulation"
  873. << "dvb-bandwidth";
  874. }
  875. #ifndef _WIN32
  876. /************
  877. * PVR *
  878. ************/
  879. if( module_exists( "v4l2" ) ){
  880. addModuleAndLayouts( PVR_DEVICE, pvr, N_("TV - analog"), QGridLayout );
  881. /* PVR Main panel */
  882. QLabel *pvrDeviceLabel = new QLabel( qtr( "Device name" ) );
  883. pvrDevLayout->addWidget( pvrDeviceLabel, 0, 0 );
  884. pvrDevice = new QComboBox;
  885. pvrDevice->setEditable( true );
  886. POPULATE_WITH_DEVS( ppsz_v4lvdevices, pvrDevice );
  887. v4l2VideoDevice->clearEditText();
  888. pvrDevLayout->addWidget( pvrDevice, 0, 1 );
  889. QLabel *pvrAudioDeviceLabel = new QLabel( qtr( "Audio device name" ) );
  890. pvrDevLayout->addWidget( pvrAudioDeviceLabel, 1, 0 );
  891. pvrAudioDevice = new QComboBox( this );
  892. pvrAudioDevice->setEditable( true );
  893. {
  894. QStringList patterns = QStringList();
  895. patterns << QString( "pcmC*D*c" );
  896. QStringList nodes = QDir( "/dev/snd" ).entryList( patterns,
  897. QDir::System );
  898. QStringList names = nodes.replaceInStrings( QRegExp("^pcmC"), "hw:" )
  899. .replaceInStrings( QRegExp("c$"), "" )
  900. .replaceInStrings( QRegExp("D"), "," );
  901. pvrAudioDevice->addItems( names );
  902. }
  903. pvrAudioDevice->clearEditText();
  904. pvrDevLayout->addWidget( pvrAudioDevice, 1, 1 );
  905. /* PVR props panel */
  906. QLabel *pvrNormLabel = new QLabel( qtr( "Video standard" ) );
  907. pvrPropLayout->addWidget( pvrNormLabel, 0, 0 );
  908. pvrNormBox = new QComboBox;
  909. setfillVLCConfigCombo( "v4l2-standard", p_intf, pvrNormBox );
  910. pvrPropLayout->addWidget( pvrNormBox, 0, 1 );
  911. QLabel *pvrFreqLabel = new QLabel( qtr( "Frequency" ) );
  912. pvrPropLayout->addWidget( pvrFreqLabel, 1, 0 );
  913. pvrFreq = new QSpinBox;
  914. pvrFreq->setAlignment( Qt::AlignRight );
  915. pvrFreq->setSuffix(" kHz");
  916. setSpinBoxFreq( pvrFreq );
  917. pvrPropLayout->addWidget( pvrFreq, 1, 1 );
  918. pvrPropLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding ),
  919. 2, 0, 1, 1 );
  920. /* PVR CONNECTs */
  921. CuMRL( pvrDevice, editTextChanged( const QString& ) );
  922. CuMRL( pvrAudioDevice, editTextChanged( const QString& ) );
  923. CuMRL( pvrFreq, valueChanged ( int ) );
  924. CuMRL( pvrNormBox, currentIndexChanged ( int ) );
  925. }
  926. #endif
  927. /**********
  928. * Screen *
  929. **********/
  930. addModuleAndLayouts( SCREEN_DEVICE, screen, "Desktop", QGridLayout );
  931. QLabel *screenLabel = new QLabel( qtr( "Your display will be "
  932. "opened and played in order to stream or save it." ) );
  933. screenLabel->setWordWrap( true );
  934. screenDevLayout->addWidget( screenLabel, 0, 0 );
  935. QLabel *screenFPSLabel = new QLabel(
  936. qtr( "Desired frame rate for the capture." ) );
  937. screenPropLayout->addWidget( screenFPSLabel, 0, 0 );
  938. screenFPS = new QDoubleSpinBox;
  939. screenFPS->setValue( 1. );
  940. screenFPS->setRange( .01, 100. );
  941. screenFPS->setAlignment( Qt::AlignRight );
  942. /* xgettext: frames per second */
  943. screenFPS->setSuffix( qtr( " f/s" ) );
  944. screenPropLayout->addWidget( screenFPS, 0, 1 );
  945. /* Screen connect */
  946. CuMRL( screenFPS, valueChanged( double ) );
  947. /* General connects */
  948. CONNECT( ui.deviceCombo, activated( int ) ,
  949. stackedDevLayout, setCurrentIndex( int ) );
  950. CONNECT( ui.deviceCombo, activated( int ),
  951. stackedPropLayout, setCurrentIndex( int ) );
  952. CONNECT( ui.deviceCombo, activated( int ), this, updateMRL() );
  953. CONNECT( ui.deviceCombo, activated( int ), this, updateButtons() );
  954. #undef CuMRL
  955. #undef addModuleAndLayouts
  956. }
  957. CaptureOpenPanel::~CaptureOpenPanel()
  958. {
  959. #ifdef _WIN32
  960. delete vdevDshowW;
  961. delete adevDshowW;
  962. #endif
  963. }
  964. void CaptureOpenPanel::clear()
  965. {
  966. advMRL.clear();
  967. }
  968. void CaptureOpenPanel::updateMRL()
  969. {
  970. QString mrl = "";
  971. QStringList fileList;
  972. int i_devicetype = ui.deviceCombo->itemData(
  973. ui.deviceCombo->currentIndex() ).toInt();
  974. switch( i_devicetype )
  975. {
  976. #ifdef _WIN32
  977. case DSHOW_DEVICE:
  978. fileList << "dshow://";
  979. mrl+= " :dshow-vdev=" +
  980. colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
  981. mrl+= " :dshow-adev=" +
  982. colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
  983. if( dshowVSizeLine->isModified() )
  984. mrl += ":dshow-size=" + dshowVSizeLine->text();
  985. break;
  986. #else
  987. case V4L2_DEVICE:
  988. fileList << "v4l2://" + v4l2VideoDevice->currentText();
  989. mrl += ":v4l2-standard="
  990. + v4l2StdBox->itemData( v4l2StdBox->currentIndex() ).toString();
  991. if( !v4l2AudioDevice->currentText().isEmpty() )
  992. mrl += " :input-slave=alsa://" + v4l2AudioDevice->currentText();
  993. break;
  994. case JACK_DEVICE:
  995. mrl = "jack://";
  996. mrl += "channels=" + QString::number( jackChannels->value() );
  997. mrl += ":ports=" + jackPortsSelected->text();
  998. fileList << mrl; mrl = "";
  999. if ( jackPace->isChecked() )
  1000. {
  1001. mrl += " :jack-input-use-vlc-pace";
  1002. }
  1003. if ( jackConnect->isChecked() )
  1004. {
  1005. mrl += " :jack-input-auto-connect";
  1006. }
  1007. break;
  1008. case PVR_DEVICE:
  1009. fileList << "v4l2://" + pvrDevice->currentText();
  1010. mrl += ":v4l2-standard="
  1011. + pvrNormBox->itemData( pvrNormBox->currentIndex() ).toString();
  1012. if( pvrFreq->value() )
  1013. mrl += ":v4l2-tuner-frequency=" + QString::number( pvrFreq->value() );
  1014. if( !pvrAudioDevice->currentText().isEmpty() )
  1015. mrl += " :input-slave=" + pvrAudioDevice->currentText();
  1016. break;
  1017. #endif
  1018. case DTV_DEVICE:
  1019. if( dvbc->isChecked() ) mrl = "dvb-c://";
  1020. else
  1021. if( dvbs->isChecked() ) mrl = "dvb-s://";
  1022. else
  1023. if( dvbs2->isChecked() ) mrl = "dvb-s2://";
  1024. else
  1025. if( dvbt->isChecked() ) mrl = "dvb-t://";
  1026. else
  1027. if( dvbt2->isChecked() ) mrl = "dvb-t2://";
  1028. else
  1029. if( atsc->isChecked() ) mrl = "atsc://";
  1030. else
  1031. if( cqam->isChecked() ) mrl = "cqam://";
  1032. mrl += "frequency=" + QString::number( dvbFreq->value() ) + "000";
  1033. if( dvbc->isChecked() || cqam->isChecked() )
  1034. mrl += ":modulation="
  1035. + dvbQamBox->itemData( dvbQamBox->currentIndex() ).toString();
  1036. if( dvbs2->isChecked() )
  1037. mrl += ":modulation="
  1038. + dvbPskBox->itemData( dvbPskBox->currentIndex() ).toString();
  1039. if( dvbc->isChecked() || dvbs->isChecked() || dvbs2->isChecked() )
  1040. mrl += ":srate=" + QString::number( dvbSrate->value() );
  1041. if( dvbt->isChecked() || dvbt2->isChecked() )
  1042. mrl += ":bandwidth=" +
  1043. QString::number( dvbBandBox->itemData(
  1044. dvbBandBox->currentIndex() ).toInt() );
  1045. fileList << mrl; mrl= "";
  1046. mrl += " :dvb-adapter=" + QString::number( dvbCard->value() );
  1047. break;
  1048. case SCREEN_DEVICE:
  1049. fileList << "screen://";
  1050. mrl = " :screen-fps=" + QString::number( screenFPS->value(), 'f' );
  1051. updateButtons();
  1052. break;
  1053. }
  1054. emit methodChanged( "live-caching" );
  1055. if( !advMRL.isEmpty() ) mrl += " " + advMRL;
  1056. emit mrlUpdated( fileList, mrl );
  1057. }
  1058. /**
  1059. * Update the Buttons (show/hide) for the GUI as all device type don't
  1060. * use the same ui. elements.
  1061. **/
  1062. void CaptureOpenPanel::updateButtons()
  1063. {
  1064. /* Be sure to display the ui Elements in case they were hidden by
  1065. * some Device Type (like Screen://) */
  1066. ui.optionsBox->show();
  1067. ui.advancedButton->show();
  1068. /* Get the current Device Number */
  1069. int i_devicetype = ui.deviceCombo->itemData(
  1070. ui.deviceCombo->currentIndex() ).toInt();
  1071. switch( i_devicetype )
  1072. {
  1073. case DTV_DEVICE:
  1074. dvbSrate->hide();
  1075. dvbSrateLabel->hide();
  1076. dvbQamBox->hide();
  1077. dvbPskBox->hide();
  1078. dvbModLabel->hide();
  1079. dvbBandBox->hide();
  1080. dvbBandLabel->hide();
  1081. if( dvbc->isChecked() )
  1082. {
  1083. dvbSrate->show();
  1084. dvbSrateLabel->show();
  1085. dvbQamBox->show();
  1086. dvbModLabel->show();
  1087. }
  1088. else if( dvbs->isChecked() )
  1089. {
  1090. dvbSrate->show();
  1091. dvbSrateLabel->show();
  1092. }
  1093. else if( dvbs2->isChecked() )
  1094. {
  1095. dvbSrate->show();
  1096. dvbSrateLabel->show();
  1097. dvbPskBox->show();
  1098. dvbModLabel->show();
  1099. }
  1100. else if( dvbt->isChecked() || dvbt2->isChecked() )
  1101. {
  1102. dvbBandBox->show();
  1103. dvbBandLabel->show();
  1104. }
  1105. break;
  1106. case SCREEN_DEVICE:
  1107. //ui.optionsBox->hide();
  1108. ui.advancedButton->hide();
  1109. break;
  1110. }
  1111. advMRL.clear();
  1112. }
  1113. void CaptureOpenPanel::enableAdvancedDialog( int i_index )
  1114. {
  1115. int i_devicetype = ui.deviceCombo->itemData( i_index ).toInt();
  1116. module_t *p_module =
  1117. module_find( psz_devModule[i_devicetype] );
  1118. ui.advancedButton->setEnabled( NULL != p_module );
  1119. }
  1120. void CaptureOpenPanel::advancedDialog()
  1121. {
  1122. /* Get selected device type */
  1123. int i_devicetype = ui.deviceCombo->itemData(
  1124. ui.deviceCombo->currentIndex() ).toInt();
  1125. /* Get the corresponding module */
  1126. module_t *p_module =
  1127. module_find( psz_devModule[i_devicetype] );
  1128. if( NULL == p_module ) return;
  1129. /* Init */
  1130. QList<ConfigControl *> controls;
  1131. /* Get the confsize */
  1132. unsigned int i_confsize;
  1133. module_config_t *p_config;
  1134. p_config = module_config_get( p_module, &i_confsize );
  1135. /* New Adv Prop dialog */
  1136. adv = new QDialog( this );
  1137. adv->setWindowTitle( qtr( "Advanced Options" ) );
  1138. adv->setWindowRole( "vlc-advanced-options" );
  1139. /* A main Layout with a Frame */
  1140. QVBoxLayout *mainLayout = new QVBoxLayout( adv );
  1141. QScrollArea *scroll = new QScrollArea;
  1142. mainLayout->addWidget( scroll );
  1143. QFrame *advFrame = new QFrame;
  1144. /* GridLayout inside the Frame */
  1145. QGridLayout *gLayout = new QGridLayout( advFrame );
  1146. scroll->setWidgetResizable( true );
  1147. scroll->setWidget( advFrame );
  1148. /* Create the options inside the FrameLayout */
  1149. for( int n = 0; n < (int)i_confsize; n++ )
  1150. {
  1151. module_config_t *p_item = p_config + n;
  1152. QString name = p_item->psz_name;
  1153. if( name.isEmpty() || configList.contains( name ) )
  1154. continue;
  1155. msg_Dbg( p_intf, "item %s", p_item->psz_name);
  1156. ConfigControl *config = ConfigControl::createControl(
  1157. VLC_OBJECT( p_intf ), p_item, advFrame, gLayout, n );
  1158. if( config )
  1159. controls.append( config );
  1160. }
  1161. /* Button stuffs */
  1162. QDialogButtonBox *advButtonBox = new QDialogButtonBox( adv );
  1163. QPushButton *closeButton = new QPushButton( qtr( "OK" ) );
  1164. QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ) );
  1165. CONNECT( closeButton, clicked(), adv, accept() );
  1166. CONNECT( cancelButton, clicked(), adv, reject() );
  1167. advButtonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
  1168. advButtonBox->addButton( cancelButton, QDialogButtonBox::RejectRole );
  1169. mainLayout->addWidget( advButtonBox );
  1170. /* Creation of the MRL */
  1171. if( adv->exec() )
  1172. {
  1173. QString tempMRL = "";
  1174. for( int i = 0; i < controls.count(); i++ )
  1175. {
  1176. ConfigControl *control = controls[i];
  1177. tempMRL += (i ? " :" : ":");
  1178. if( control->getType() == CONFIG_ITEM_BOOL )
  1179. if( !(qobject_cast<VIntConfigControl *>(control)->getValue() ) )
  1180. tempMRL += "no-";
  1181. tempMRL += control->getName();
  1182. switch( control->getType() )
  1183. {
  1184. case CONFIG_ITEM_STRING:
  1185. case CONFIG_ITEM_LOADFILE:
  1186. case CONFIG_ITEM_SAVEFILE:
  1187. case CONFIG_ITEM_DIRECTORY:
  1188. case CONFIG_ITEM_MODULE:
  1189. tempMRL += colon_escape( QString("=%1").arg( qobject_cast<VStringConfigControl *>(control)->getValue() ) );
  1190. break;
  1191. case CONFIG_ITEM_INTEGER:
  1192. tempMRL += QString("=%1").arg( qobject_cast<VIntConfigControl *>(control)->getValue() );
  1193. break;
  1194. case CONFIG_ITEM_FLOAT:
  1195. tempMRL += QString("=%1").arg( qobject_cast<VFloatConfigControl *>(control)->getValue() );
  1196. break;
  1197. }
  1198. }
  1199. advMRL = tempMRL;
  1200. updateMRL();
  1201. }
  1202. qDeleteAll( controls );
  1203. delete adv;
  1204. module_config_free( p_config );
  1205. }