Commit 47027e01 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - Dialog implementation for registering the file association on Windows.

The Windows only code doesn't exist yet, but soon ?
parent 599e3942
...@@ -403,6 +403,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -403,6 +403,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
ui.assoName->hide(); ui.assoName->hide();
ui.assoButton->hide(); ui.assoButton->hide();
#endif #endif
BUTTONACT( ui.assoButton, assoDialog() );
/* interface */ /* interface */
char *psz_intf = config_GetPsz( p_intf, "intf" ); char *psz_intf = config_GetPsz( p_intf, "intf" );
...@@ -627,7 +628,68 @@ void SPrefsPanel::lastfm_Changed( int i_state ) ...@@ -627,7 +628,68 @@ void SPrefsPanel::lastfm_Changed( int i_state )
config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ); config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
} }
#ifdef WIN32
#include <QListWidget>
#include <QDialogButtonBox>
#include "util/registry.hpp"
void SPrefsPanel::assoDialog() 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 */
...@@ -64,6 +64,9 @@ class QLineEdit; ...@@ -64,6 +64,9 @@ class QLineEdit;
class QRadioButton; class QRadioButton;
class QCheckBox; class QCheckBox;
class QString; class QString;
#if WIN32
class QListWidgetItem;
#endif
class SPrefsCatList : public QWidget class SPrefsCatList : public QWidget
{ {
...@@ -96,11 +99,18 @@ private: ...@@ -96,11 +99,18 @@ private:
QList<QWidget *> optionWidgets; QList<QWidget *> optionWidgets;
QString qs_filter; QString qs_filter;
#if WIN32
QList<QListWidgetItem *> listAsso;
#endif
/* Display only the options for the selected audio output */ /* Display only the options for the selected audio output */
private slots: private slots:
void lastfm_Changed( int ); void lastfm_Changed( int );
void updateAudioOptions( int ); void updateAudioOptions( int );
#ifdef WIN32
void assoDialog(); void assoDialog();
void saveAsso();
#endif
}; };
#endif #endif
// License GPLv2+ // License GPLv2 or later
// COde by atmo
#include "registry.hpp" #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; HKEY keyHandle;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) { if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
RegCloseKey(keyHandle); {
return 1; RegCloseKey( keyHandle );
return true;
} }
return 0; return false;
} }
int QVLCRegistry::RegistryValueExists(char *path, char *valueName) { bool QVLCRegistry::RegistryValueExists( char *path, char *valueName )
{
HKEY keyHandle; HKEY keyHandle;
int temp = 0; bool temp = false;
DWORD size1; DWORD size1;
DWORD valueType; DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) { if( RegOpenKeyEx( m_RootKey, path, 0, KEY_READ, &keyHandle ) == ERROR_SUCCESS )
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1) == ERROR_SUCCESS) { {
temp = 1; if( RegQueryValueEx( keyHandle, valueName, NULL,
&valueType, NULL, &size1 ) == ERROR_SUCCESS )
{
temp = true;
} }
RegCloseKey(keyHandle); RegCloseKey( keyHandle );
} }
return temp; return temp;
} }
void QVLCRegistry::WriteRegistryInt(char *path, char *valueName, int value) { void QVLCRegistry::WriteRegistryInt( char *path, char *valueName, int value )
{
HKEY keyHandle; HKEY keyHandle;
if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL) == ERROR_SUCCESS) { if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
RegSetValueEx(keyHandle,valueName,0,REG_DWORD,(LPBYTE)&value,sizeof(int)); KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
RegCloseKey(keyHandle); {
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; HKEY keyHandle;
if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL) == ERROR_SUCCESS) { if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
RegSetValueEx(keyHandle,valueName,0,REG_SZ,(LPBYTE)value,(DWORD)(strlen(value)+1)); KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
RegCloseKey(keyHandle); {
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; HKEY keyHandle;
if( RegCreateKeyEx(m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &keyHandle, NULL) == ERROR_SUCCESS) { if( RegCreateKeyEx( m_RootKey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
RegSetValueEx(keyHandle,valueName,0,REG_BINARY,(LPBYTE)&value,sizeof(double)); KEY_WRITE, NULL, &keyHandle, NULL ) == ERROR_SUCCESS )
RegCloseKey(keyHandle); {
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; HKEY keyHandle;
int tempValue; int tempValue;
DWORD size1; DWORD size1;
DWORD valueType; DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == 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, NULL, &size1 ) == ERROR_SUCCESS )
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1) == ERROR_SUCCESS) { {
if( valueType == REG_DWORD )
{
if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1 ) == ERROR_SUCCESS )
{
default_value = tempValue; default_value = tempValue;
}; };
} }
} }
RegCloseKey(keyHandle); RegCloseKey( keyHandle );
} }
return default_value; 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; HKEY keyHandle;
char *tempValue = NULL; char *tempValue = NULL;
DWORD size1; DWORD size1;
DWORD valueType; DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == 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_SZ) { if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, NULL, &size1 ) == ERROR_SUCCESS )
{
if( valueType == REG_SZ )
{
// free // free
tempValue = (char *)malloc(size1+1); // +1 fr NullByte`? tempValue = ( char * )malloc( size1+1 ); // +1 fr NullByte`?
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)tempValue, &size1) == ERROR_SUCCESS) { if( RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)tempValue, &size1 ) == ERROR_SUCCESS )
{
default_value = tempValue; default_value = tempValue;
}; };
} }
} }
RegCloseKey(keyHandle); RegCloseKey( keyHandle );
} }
if(tempValue == NULL) { if( tempValue == NULL )
{
// wenn tempValue nicht aus registry gelesen wurde dafr sorgen das ein neuer String mit der Kopie von DefaultValue // wenn tempValue nicht aus registry gelesen wurde dafr sorgen das ein neuer String mit der Kopie von DefaultValue
// geliefert wird - das macht das Handling des Rckgabewertes der Funktion einfacher - immer schn mit free freigeben! // geliefert wird - das macht das Handling des Rckgabewertes der Funktion einfacher - immer schn mit free freigeben!
default_value = strdup(default_value); default_value = strdup( default_value );
} }
return 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; HKEY keyHandle;
double tempValue; double tempValue;
DWORD size1; DWORD size1;
DWORD valueType; DWORD valueType;
if( RegOpenKeyEx(m_RootKey, path, 0, KEY_READ, &keyHandle) == 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,
if(RegQueryValueEx( keyHandle, valueName, NULL, &valueType, (LPBYTE)&tempValue, &size1) == ERROR_SUCCESS) { 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; default_value = tempValue;
}; };
} }
} }
RegCloseKey(keyHandle); RegCloseKey( keyHandle );
} }
return default_value; return default_value;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment