]> git.sesse.net Git - vlc/commitdiff
Qt4 - Dialog implementation for registering the file association on Windows.
authorJean-Baptiste Kempf <jb@videolan.org>
Tue, 22 Jan 2008 03:51:41 +0000 (03:51 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 22 Jan 2008 03:51:41 +0000 (03:51 +0000)
The Windows only code doesn't exist yet, but soon ?

modules/gui/qt4/components/simple_preferences.cpp
modules/gui/qt4/components/simple_preferences.hpp
modules/gui/qt4/util/registry.cpp

index 6c97ba81ea4b8967267ae1df240550ee25fd1368..f091fd0fd97524b5b266be0f7b1041ffe51cf74a 100644 (file)
@@ -403,6 +403,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
             ui.assoName->hide();
             ui.assoButton->hide();
 #endif
+            BUTTONACT( ui.assoButton, assoDialog() );
 
             /* interface */
             char *psz_intf = config_GetPsz( p_intf, "intf" );
@@ -627,7 +628,68 @@ void SPrefsPanel::lastfm_Changed( int i_state )
         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
 }
 
+#ifdef WIN32
+
+#include <QListWidget>
+#include <QDialogButtonBox>
+#include "util/registry.hpp"
+
 void SPrefsPanel::assoDialog()
+{
+    QDialog *d = new QDialog( this );
+    QGridLayout *assoLayout = new QGridLayout( d );
+
+    QListWidget *filetypeList = new QListWidget;
+    assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
+
+    QListWidgetItem *currentItem;
+
+#define addType( ext ) \
+    currentItem = new QListWidgetItem( ext, filetypeList ); \
+    currentItem->setCheckState( Qt::Checked ); \
+    listAsso.append( currentItem );
+
+    addType( ".avi" );
+
+    QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
+    QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
+    QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
+    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
+    buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
+
+    assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
+
+    CONNECT( closeButton, clicked(), this, saveAsso() );
+    CONNECT( clearButton, clicked(), d, reject() );
+    d->exec();
+    delete d;
+}
+
+void addAsso( char *psz_ext )
 {
 
 }
+
+void delAsso( char *psz_ext )
+{
+
+}
+void SPrefsPanel::saveAsso()
+{
+    for( int i = 0; i < listAsso.size(); i ++ )
+    {
+        if( listAsso[i]->checkState() > 0 )
+        {
+            addAsso( qtu( listAsso[i]->text() ) );
+        }
+        else
+        {
+            delAsso( qtu( listAsso[i]->text() ) );
+        }
+    }
+    /* Gruik ? Naaah */
+    qobject_cast<QDialog *>(listAsso[0]->listWidget()->parent())->accept();
+}
+
+#endif /* WIN32 */
+
index 7e249836cc50dce1caba5537f9c1f5d48eaf65c0..1f2fd88d8f7de41f4886b9e765fc5090e55d61f1 100644 (file)
@@ -64,6 +64,9 @@ class QLineEdit;
 class QRadioButton;
 class QCheckBox;
 class QString;
+#if WIN32
+class QListWidgetItem;
+#endif
 
 class SPrefsCatList : public QWidget
 {
@@ -96,11 +99,18 @@ private:
     QList<QWidget *> optionWidgets;
     QString qs_filter;
 
+#if WIN32
+    QList<QListWidgetItem *> listAsso;
+#endif
+
 /* Display only the options for the selected audio output */
 private slots:
     void lastfm_Changed( int );
     void updateAudioOptions( int );
+#ifdef WIN32
     void assoDialog();
+    void saveAsso();
+#endif
 };
 
 #endif
index af47deda89a45434c9c01700e05f1fcf2ae04b0f..7664fa246480d4f3cc56519a321c57e15a9076d1 100644 (file)
-// License GPLv2+
+// License GPLv2 or later
+// COde by atmo
 
 #include "registry.hpp"
 
-QVLCRegistry::QVLCRegistry(HKEY rootKey)
+QVLCRegistry::QVLCRegistry( HKEY rootKey )
 {
-    this->m_RootKey = rootKey;
+    m_RootKey = rootKey;
 }
 
-QVLCRegistry::~QVLCRegistry(void)
+QVLCRegistry::~QVLCRegistry( void )
 {
 }
 
-int QVLCRegistry::RegistryKeyExists(char *path) {
+bool QVLCRegistry::RegistryKeyExists( char *path )
+{
     HKEY keyHandle;
-    if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
-        RegCloseKey(keyHandle);
-        return 1;
+    if(  RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
+    {
+        RegCloseKey( keyHandle );
+        return true;
     }
-    return 0;
+    return false;
 }
 
-int QVLCRegistry::RegistryValueExists(char *path, char *valueName) {
+bool QVLCRegistry::RegistryValueExists( char *path, char *valueName )
+{
     HKEY keyHandle;
-    int temp = 0;
+    bool temp = false;
     DWORD size1;
     DWORD valueType;
 
-    if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
-        if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
-           temp = 1;
+    if(  RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
+    {
+        if( RegQueryValueEx( keyHandle, valueName, NULL,
+                             &valueType, NULL, &size1 ) == ERROR_SUCCESS )
+        {
+           temp = true;
         }
-        RegCloseKey(keyHandle);
+        RegCloseKey( keyHandle );
     }
     return temp;
 }
 
-void QVLCRegistry::WriteRegistryInt(char *path, char *valueName, int value) {
+void QVLCRegistry::WriteRegistryInt( char *path, char *valueName, int value )
+{
     HKEY keyHandle;
 
-    if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL)  == ERROR_SUCCESS) {
-        RegSetValueEx(keyHandle,valueName,0,REG_DWORD,(LPBYTE)&value,sizeof(int));
-        RegCloseKey(keyHandle);
+    if(  RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
+                         KEY_WRITE, NULL, &keyHandle, NULL )  == ERROR_SUCCESS )
+    {
+        RegSetValueEx( keyHandle, valueName, 0, REG_DWORD,
+                (LPBYTE)&value, sizeof( int ) );
+        RegCloseKey( keyHandle );
     }
-
 }
 
-void QVLCRegistry::WriteRegistryString(char *path, char *valueName, char *value) {
+void QVLCRegistry::WriteRegistryString( char *path, char *valueName, char *value )
+{
     HKEY keyHandle;
 
-    if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL)  == ERROR_SUCCESS) {
-        RegSetValueEx(keyHandle,valueName,0,REG_SZ,(LPBYTE)value,(DWORD)(strlen(value)+1));
-        RegCloseKey(keyHandle);
+    if(  RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
+                         KEY_WRITE, NULL, &keyHandle, NULL )  == ERROR_SUCCESS )
+    {
+        RegSetValueEx( keyHandle, valueName, 0, REG_SZ, (LPBYTE)value,
+                (DWORD)( strlen( value ) + 1 ) );
+        RegCloseKey( keyHandle );
     }
 }
 
-void QVLCRegistry::WriteRegistryDouble(char *path, char *valueName, double value) {
+void QVLCRegistry::WriteRegistryDouble( char *path, char *valueName, double value )
+{
     HKEY keyHandle;
-    if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL)  == ERROR_SUCCESS) {
-        RegSetValueEx(keyHandle,valueName,0,REG_BINARY,(LPBYTE)&value,sizeof(double));
-        RegCloseKey(keyHandle);
+    if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
+                       KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
+    {
+        RegSetValueEx( keyHandle, valueName, 0, REG_BINARY, (LPBYTE)&value, sizeof( double ) );
+        RegCloseKey( keyHandle );
     }
 }
 
-int QVLCRegistry::ReadRegistryInt(char *path, char *valueName, int default_value) {
+int QVLCRegistry::ReadRegistryInt( char *path, char *valueName, int default_value ) {
     HKEY keyHandle;
     int tempValue;
     DWORD size1;
     DWORD valueType;
 
-    if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
-        if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
-           if(valueType == REG_DWORD) {
-               if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1) == ERROR_SUCCESS) {
+    if(  RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
+    {
+        if( RegQueryValueEx(  keyHandle, valueName, NULL, &valueType, NULL, &size1 ) == ERROR_SUCCESS )
+        {
+           if( valueType == REG_DWORD )
+           {
+               if( RegQueryValueEx(  keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1 ) == ERROR_SUCCESS )
+               {
                   default_value = tempValue;
                };
            }
         }
-        RegCloseKey(keyHandle);
+        RegCloseKey( keyHandle );
     }
     return default_value;
 }
 
-char * QVLCRegistry::ReadRegistryString(char *path, char *valueName, char *default_value) {
+char * QVLCRegistry::ReadRegistryString( char *path, char *valueName, char *default_value )
+{
     HKEY keyHandle;
     char *tempValue = NULL;
     DWORD size1;
     DWORD valueType;
 
-    if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
-        if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
-           if(valueType == REG_SZ) {
+    if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
+    {
+        if( RegQueryValueEx(  keyHandle, valueName, NULL, &valueType, NULL, &size1 ) == ERROR_SUCCESS )
+        {
+           if( valueType == REG_SZ )
+           {
                // free
-               tempValue = (char *)malloc(size1+1); // +1 für NullByte`?
-               if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)tempValue, &size1) == ERROR_SUCCESS) {
+               tempValue = ( char * )malloc( size1+1 ); // +1 für NullByte`?
+               if( RegQueryValueEx(  keyHandle, valueName, NULL, &valueType, (LPBYTE)tempValue, &size1 ) == ERROR_SUCCESS )
+               {
                   default_value = tempValue;
                };
            }
         }
-        RegCloseKey(keyHandle);
+        RegCloseKey( keyHandle );
     }
-    if(tempValue == NULL)  {
+    if( tempValue == NULL )
+    {
         // wenn tempValue nicht aus registry gelesen wurde dafür sorgen das ein neuer String mit der Kopie von DefaultValue
         // geliefert wird - das macht das Handling des Rückgabewertes der Funktion einfacher - immer schön mit free freigeben!
-        default_value = strdup(default_value);
+        default_value = strdup( default_value );
     }
 
     return default_value;
 }
 
-double QVLCRegistry::ReadRegistryDouble(char *path, char *valueName, double default_value) {
+double QVLCRegistry::ReadRegistryDouble( char *path, char *valueName, double default_value )
+{
     HKEY keyHandle;
     double tempValue;
     DWORD size1;
     DWORD valueType;
 
-    if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) {
-        if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) {
-           if((valueType == REG_BINARY) && (size1 == sizeof(double))) {
-               if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1) == ERROR_SUCCESS) {
+    if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
+    {
+        if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType,
+                             NULL, &size1 ) == ERROR_SUCCESS )
+        {
+           if( ( valueType == REG_BINARY ) && ( size1 == sizeof( double ) ) )
+           {
+               if( RegQueryValueEx(  keyHandle, valueName, NULL, &valueType,
+                           (LPBYTE)&tempValue, &size1 ) == ERROR_SUCCESS )
+               {
                   default_value = tempValue;
                };
            }
         }
-        RegCloseKey(keyHandle);
+        RegCloseKey( keyHandle );
     }
     return default_value;
 }
+