From 47027e01d45a642cf671c9566a776459a2872d85 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Kempf Date: Tue, 22 Jan 2008 03:51:41 +0000 Subject: [PATCH] Qt4 - Dialog implementation for registering the file association on Windows. The Windows only code doesn't exist yet, but soon ? --- .../gui/qt4/components/simple_preferences.cpp | 62 ++++++++ .../gui/qt4/components/simple_preferences.hpp | 10 ++ modules/gui/qt4/util/registry.cpp | 133 +++++++++++------- 3 files changed, 156 insertions(+), 49 deletions(-) diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp index 6c97ba81ea..f091fd0fd9 100644 --- a/modules/gui/qt4/components/simple_preferences.cpp +++ b/modules/gui/qt4/components/simple_preferences.cpp @@ -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 +#include +#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(listAsso[0]->listWidget()->parent())->accept(); +} + +#endif /* WIN32 */ + diff --git a/modules/gui/qt4/components/simple_preferences.hpp b/modules/gui/qt4/components/simple_preferences.hpp index 7e249836cc..1f2fd88d8f 100644 --- a/modules/gui/qt4/components/simple_preferences.hpp +++ b/modules/gui/qt4/components/simple_preferences.hpp @@ -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 optionWidgets; QString qs_filter; +#if WIN32 + QList 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 diff --git a/modules/gui/qt4/util/registry.cpp b/modules/gui/qt4/util/registry.cpp index af47deda89..7664fa2464 100644 --- a/modules/gui/qt4/util/registry.cpp +++ b/modules/gui/qt4/util/registry.cpp @@ -1,128 +1,163 @@ -// 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; } + -- 2.39.5