1 /*****************************************************************************
2 * openurl.cpp: Open a MRL or clipboard content
3 *****************************************************************************
4 * Copyright © 2009 the VideoLAN team
7 * Authors: Jean-Philippe André <jpeg@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include "dialogs/openurl.hpp"
29 #include "util/customwidgets.hpp"
31 #include <QPushButton>
32 #include <QDialogButtonBox>
33 #include <QApplication>
43 OpenUrlDialog::OpenUrlDialog( intf_thread_t *_p_intf,
45 QVLCDialog( (QWidget*)_p_intf->p_sys->p_mi, _p_intf ), bClipboard( _bClipboard )
47 setWindowTitle( qtr( "Open URL" ) );
48 setWindowRole( "vlc-open-url" );
53 QDialogButtonBox *box = new QDialogButtonBox( this );
54 but = box->addButton( QDialogButtonBox::Ok );
55 CONNECT( but, clicked(), this, play() );
56 but = box->addButton( QDialogButtonBox::Cancel );
57 but = box->addButton( qtr( "&Enqueue" ), QDialogButtonBox::AcceptRole );
58 CONNECT( but, clicked(), this, enqueue() );
60 CONNECT( box, rejected(), this, reject() );
62 /* Info label and line edit */
63 edit = new ClickLineEdit( qtr( "Enter URL here..." ), this );
65 QLabel *info = new QLabel( qtr( "Please enter the URL or path "
66 "to the media you want to play"),
69 setToolTip( qtr( "If your clipboard contains a valid URL\n"
70 "or the path to a file on your computer,\n"
71 "it will be automatically selected." ) );
74 QVBoxLayout *vlay = new QVBoxLayout( this );
76 vlay->addWidget( info );
77 vlay->addWidget( edit );
78 vlay->addWidget( box );
81 void OpenUrlDialog::enqueue()
83 bShouldEnqueue = true;
84 lastUrl = edit->text();
88 void OpenUrlDialog::play()
90 lastUrl = edit->text();
94 QString OpenUrlDialog::url() const
99 bool OpenUrlDialog::shouldEnqueue() const
101 return bShouldEnqueue;
105 * When the dialog is shown, try to extract an URL from the clipboard
106 * and paste it in the Edit box.
107 * showEvent can happen not only on exec() but I think it's cool to
108 * actualize the URL on showEvent (eg. change virtual desktop...)
110 void OpenUrlDialog::showEvent( QShowEvent *ev )
113 bShouldEnqueue = false;
114 edit->setFocus( Qt::OtherFocusReason );
115 if( !lastUrl.isEmpty() && edit->text().isEmpty() )
117 /* The text should not have been changed, excepted if the user
118 has clicked Cancel before */
119 edit->setText( lastUrl );
126 QClipboard *clipboard = QApplication::clipboard();
127 assert( clipboard != NULL );
128 QString txt = clipboard->text( QClipboard::Selection ).trimmed();
130 if( txt.isEmpty() || ( !txt.contains("://") && !QFile::exists(txt) ) )
131 txt = clipboard->text( QClipboard::Clipboard ).trimmed();
133 if( txt.contains( "://" ) || QFile::exists( txt ) )
134 edit->setText( txt );