]> git.sesse.net Git - vlc/blobdiff - modules/gui/qt4/components/open_panels.cpp
Qt4: fix pontential NULL dereference and show the right containing forlder.
[vlc] / modules / gui / qt4 / components / open_panels.cpp
index 8967f534ceea0d56274e250899cce1f935526105..6e4afb5bcd073018e41fe387200bf9734701616e 100644 (file)
@@ -76,7 +76,7 @@ FileOpenPanel::FileOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     QCompleter *fileCompleter = new QCompleter( fileCompleteList, this );
     fileCompleter->setModel( new QDirModel( fileCompleter ) );
     lineFileEdit->setCompleter( fileCompleter );*/
-    if( config_GetInt( p_intf, "qt-embedded-open" ) )
+    if( var_InheritBool( p_intf, "qt-embedded-open" ) )
     {
         ui.tempWidget->hide();
         BuildOldPanel();
@@ -274,9 +274,9 @@ DiscOpenPanel::DiscOpenPanel( QWidget *_parent, intf_thread_t *_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" );
+    psz_dvddiscpath = var_InheritString( p_intf, "dvd" );
+    psz_vcddiscpath = var_InheritString( p_intf, "vcd" );
+    psz_cddadiscpath = var_InheritString( p_intf, "cd-audio" );
 
     /* State to avoid overwritting the users changes with the configuration */
     b_firstdvd = true;
@@ -492,31 +492,16 @@ NetOpenPanel::NetOpenPanel( QWidget *_parent, intf_thread_t *_p_intf ) :
     ui.setupUi( this );
 
     /* CONNECTs */
-    CONNECT( ui.protocolCombo, activated( int ),
-             this, updateProtocol( int ) );
-    CONNECT( ui.portSpin, valueChanged( int ), this, updateMRL() );
-    CONNECT( ui.addressText, textChanged( const QString& ), this, updateMRL());
-
-    ui.protocolCombo->addItem( "" );
-    ui.protocolCombo->addItem("HTTP", QVariant("http"));
-    ui.protocolCombo->addItem("HTTPS", QVariant("https"));
-    ui.protocolCombo->addItem("MMS", QVariant("mms"));
-    ui.protocolCombo->addItem("FTP", QVariant("ftp"));
-    ui.protocolCombo->addItem("RTSP", QVariant("rtsp"));
-    ui.protocolCombo->addItem("RTP", QVariant("rtp"));
-    ui.protocolCombo->addItem("UDP", QVariant("udp"));
-    ui.protocolCombo->addItem("RTMP", QVariant("rtmp"));
-
-    updateProtocol( ui.protocolCombo->currentIndex() );
-
-    if( config_GetInt( p_intf, "qt-recentplay" ) )
+    CONNECT( ui.urlText, textChanged( const QString& ), this, updateMRL());
+
+    if( var_InheritBool( p_intf, "qt-recentplay" ) )
     {
         mrlList = new QStringListModel(
                 getSettings()->value( "Open/netMRL" ).toStringList() );
         QCompleter *completer = new QCompleter( mrlList, this );
-        ui.addressText->setCompleter( completer );
+        ui.urlText->setCompleter( completer );
 
-        CONNECT( ui.addressText, editingFinished(), this, updateCompleter() );
+        CONNECT( ui.urlText, editingFinished(), this, updateCompleter() );
     }
     else
         mrlList = NULL;
@@ -537,111 +522,50 @@ NetOpenPanel::~NetOpenPanel()
 void NetOpenPanel::clear()
 {}
 
-/* update the widgets according the type of protocol */
-void NetOpenPanel::updateProtocol( int idx_proto ) {
-    QString addr = ui.addressText->text();
-    QString proto = ui.protocolCombo->itemData( idx_proto ).toString();
-
-    ui.portSpin->setEnabled( idx_proto == UDP_PROTO ||
-                             idx_proto == RTP_PROTO );
-
-    if( idx_proto == NO_PROTO ) return;
-
-    /* If we already have a protocol in the address, replace it */
-    if( addr.contains( "://"))
-    {
-        if( idx_proto != UDP_PROTO && idx_proto != RTP_PROTO )
-            addr.replace( QRegExp("^.*://@*"), proto + "://");
-        else if ( ( addr.contains(QRegExp("://((22[4-9])|(23\\d)|(\\[?[fF]{2}[0-9a-fA-F]{2}:))"))) ||
-                ( !addr.contains(QRegExp("^\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}[.]\\d{1,3}")) &&
-                !addr.contains(QRegExp(":[a-fA-F0-9]{1,4}:")) ) )
-             addr.replace( QRegExp("^.*://"), proto + "://@");
-    else
-             addr.replace( QRegExp("^.*://"), proto + "://");
-        addr.replace( QRegExp("@+"), "@");
-        ui.addressText->setText( addr );
-    }
-    updateMRL();
+static int strcmp_void( const void *k, const void *e )
+{
+    return strcmp( (const char *)k, (const char *)e );
 }
 
-void NetOpenPanel::updateMRL() {
-    QString mrl = "";
-    QString addr = ui.addressText->text();
-    int idx_proto = ui.protocolCombo->currentIndex();
-    if( addr.contains( "://"))
-    {
-        /* Match the correct item in the comboBox */
-        ui.protocolCombo->setCurrentIndex(
-                ui.protocolCombo->findData( addr.section( ':', 0, 0 ) ) );
-        mrl = addr;
-    }
-    else
+void NetOpenPanel::updateMRL()
+{
+    static const struct caching_map
     {
-        switch( idx_proto ) {
-        case HTTP_PROTO:
-            mrl = "http://" + addr;
-            emit methodChanged("http-caching");
-            break;
-        case HTTPS_PROTO:
-            mrl = "https://" + addr;
-            emit methodChanged("http-caching");
-            break;
-        case MMS_PROTO:
-            mrl = "mms://" + addr;
-            emit methodChanged("mms-caching");
-            break;
-        case FTP_PROTO:
-            mrl = "ftp://" + addr;
-            emit methodChanged("ftp-caching");
-            break;
-        case RTSP_PROTO:
-            mrl = "rtsp://" + addr;
-            emit methodChanged("rtsp-caching");
-            break;
-        case RTP_PROTO:
-        case UDP_PROTO:
-            mrl = qfu(((idx_proto == RTP_PROTO) ? "rtp" : "udp"));
-            mrl += qfu( "://" );
-            if( addr[0] == ':' ) /* Port number without address */
-                mrl += addr;
-            else
-            {
-                if( !addr.contains( "@" ) )
-                    mrl += qfu( "@" );
-                switch( addr.count( ":" ) )
-                {
-                    case 0: /* DNS or IPv4 literal, no port number */
-                        mrl += addr;
-                        mrl += QString(":%1").arg( ui.portSpin->value() );
-                        break;
-                    case 1: /* DNS or IPv4 literal plus port number */
-                        mrl += addr;
-                        break;
-                    default: /* IPv6 literal */
-                        if( !addr.contains( "]:" ) )
-                        {
-                            if( addr[0] != '[' ) /* Missing brackets */
-                                mrl += qfu( "[" ) + addr + qfu( "]" );
-                            else
-                                mrl += addr;
-                            mrl += QString(":%1").arg( ui.portSpin->value() );
-                        }
-                        else /* Brackets present, port present */
-                            mrl += addr;
-                        break;
-                }
-            }
-            emit methodChanged(idx_proto == RTP_PROTO
-                                   ? "rtp-caching" : "udp-caching");
-            break;
-        case RTMP_PROTO:
-            mrl = "rtmp://" + addr;
-            emit methodChanged("rtmp-caching");
-            break;
-        }
-    }
-
-    QStringList qsl; qsl<< mrl;
+        char proto[6];
+        char caching[6];
+    } schemes[] =
+    {   /* KEEP alphabetical order on first column!! */
+        { "dccp",  "rtp"   },
+        { "ftp",   "ftp"   },
+        { "ftps",  "ftp"   },
+        { "http",  "http"  },
+        { "https", "http"  },
+        { "mms",   "mms"   },
+        { "mmsh",  "mms"   },
+        { "mmst",  "mms"   },
+        { "mmsu",  "mms"   },
+        { "sftp",  "sftp"  },
+        { "smb",   "smb"   },
+        { "rtmp",  "rtmp"  },
+        { "rtp",   "rtp"   },
+        { "rtsp",  "rtsp"  },
+        { "udp",   "udp"   },
+    };
+
+    QString url = ui.urlText->text();
+    if( !url.contains( "://") )
+        return; /* nothing to do this far */
+
+    /* Match the correct item in the comboBox */
+    QString proto = url.section( ':', 0, 0 );
+    const struct caching_map *r = (const struct caching_map *)
+        bsearch( qtu(proto), schemes, sizeof(schemes) / sizeof(schemes[0]),
+                 sizeof(schemes[0]), strcmp_void );
+    if( r != NULL && module_exists( r->caching ) )
+        emit methodChanged( qfu( r->caching ) + qfu( "-caching" ) );
+
+    QStringList qsl;
+    qsl << url;
     emit mrlUpdated( qsl, "" );
 }
 
@@ -649,8 +573,8 @@ void NetOpenPanel::updateCompleter()
 {
     assert( mrlList );
     QStringList tempL = mrlList->stringList();
-    if( !tempL.contains( ui.addressText->text() ) )
-        tempL.append( ui.addressText->text() );
+    if( !tempL.contains( ui.urlText->text() ) )
+        tempL.append( ui.urlText->text() );
     mrlList->setStringList( tempL );
 }
 
@@ -1150,15 +1074,14 @@ void CaptureOpenPanel::updateMRL()
         mrl+= " :dshow-vdev=" +
             colon_escape( QString("%1").arg( vdevDshowW->getValue() ) );
         mrl+= " :dshow-adev=" +
-            colon_escape( QString("%1").arg( adevDshowW->getValue() ) );
+            colon_escape( QString("%1").arg( adevDshowW->getValue() ) )+" ";
         if( dshowVSizeLine->isModified() )
-            mrl += " :dshow-size=" + dshowVSizeLine->text();
+            mrl += ":dshow-size=" + dshowVSizeLine->text();
         emit methodChanged( "dshow-caching" );
         break;
 #else
     case V4L_DEVICE:
-        fileList << "v4l://";
-        mrl += " :v4l-vdev=" + v4lVideoDevice->text();
+        fileList << "v4l://" + v4lVideoDevice->text();
         mrl += " :input-slave=alsa://" + v4lAudioDevice->text();
         mrl += " :v4l-norm=" + QString::number( v4lNormBox->currentIndex() );
         mrl += " :v4l-frequency=" + QString::number( v4lFreq->value() );