⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsettings_win.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    } , {	RegQueryValueExA( handle, e.isEmpty() ? (const char*)0 : (const char*)e.local8Bit(), NULL, &type, data, &size );    } );    QByteArray result;    result.setRawData( (const char*)data, size );    RegCloseKey( handle );    return result;}void QSettingsPrivate::sysInit(){    sysd = new QSettingsSysPrivate( this );}void QSettingsPrivate::sysClear(){    delete sysd;}bool QSettingsPrivate::sysSync(){    if ( sysd->local )	RegFlushKey( sysd->local );    if ( sysd->user )	RegFlushKey( sysd->user );    return TRUE;}bool QSettingsPrivate::sysReadBoolEntry(const QString &key, bool def, bool *ok ) const{    return sysReadNumEntry( key, def, ok );}double QSettingsPrivate::sysReadDoubleEntry( const QString &key, double def, bool *ok ) const{    Q_ASSERT(sysd);    if ( ok )	*ok = FALSE;    ulong type;    QByteArray array = sysd->readKey( key, type );    if ( type != REG_BINARY ) {	char *data = array.data();	array.resetRawData( data, array.size() );	delete[] data;	return def;    }    if ( array.size() != sizeof(double) )	return def;    if ( ok )	*ok = TRUE;    double res = 0;    char* data = (char*)&res;    for ( int i = 0; i < sizeof(double); ++i )	data[i] = array[ i ];    char *adata = array.data();    array.resetRawData( adata, array.size() );    delete[] adata;    return res;}int QSettingsPrivate::sysReadNumEntry(const QString &key, int def, bool *ok ) const{    Q_ASSERT(sysd);    if ( ok )	*ok = FALSE;    ulong type;    QByteArray array = sysd->readKey( key, type );    if ( type != REG_DWORD ) {	char *data = array.data();	array.resetRawData( data, array.size() );	delete[] data;	return def;    }    if ( array.size() != sizeof(int) )	return def;    if ( ok )	*ok = TRUE;    int res = 0;    char* data = (char*)&res;    for ( int i = 0; i < sizeof(int); ++i )	data[i] = array[ i ];    char *adata = array.data();    array.resetRawData( adata, array.size() );    delete[] adata;    return res;}QString QSettingsPrivate::sysReadEntry(const QString &key, const QString &def, bool *ok ) const{    if ( ok ) // no, everything is not ok	*ok = FALSE;    ulong type;    QByteArray array = sysd->readKey( key, type );    if ( type != REG_SZ ) {	char *data = array.data();	array.resetRawData( data, array.size() );	delete[] data;	return def;    }    if ( ok )	*ok = TRUE;    QString result = QString::null;    QT_WA( {	int s = array.size();	for ( int i = 0; i < s; i+=2 ) {	    QChar c( array[ i ], array[ i+1 ] );	    if( !c.isNull() )		result+=c;	}    } , {	result = QString::fromLocal8Bit( array );    } );        if ( array.size() == 2 && result.isNull() )	result = "";    char *data = array.data();    array.resetRawData( data, array.size() );    delete[] data;    return result;}bool QSettingsPrivate::sysWriteEntry( const QString &key, bool value ){    return sysWriteEntry( key, (int)value );}bool QSettingsPrivate::sysWriteEntry( const QString &key, double value ){    Q_ASSERT(sysd);    QByteArray array( sizeof(double) );    const char *data = (char*)&value;    for ( int i = 0; i < sizeof(double); ++i )	array[i] = data[i];    return sysd->writeKey( key, array, REG_BINARY );}bool QSettingsPrivate::sysWriteEntry( const QString &key, int value ){    Q_ASSERT(sysd);    QByteArray array( sizeof(int) );    const char* data = (char*)&value;    for ( int i = 0; i < sizeof(int ); ++i )	array[i] = data[i];    return sysd->writeKey( key, array, REG_DWORD );}bool QSettingsPrivate::sysWriteEntry( const QString &key, const QString &value ){    Q_ASSERT(sysd);    QByteArray array( 0 );    QT_WA( {	array.resize( value.length() * 2 + 2 );	const QChar *data = value.unicode();	int i;	for ( i = 0; i < (int)value.length(); ++i ) {	    array[ 2*i ] = data[ i ].cell();	    array[ (2*i)+1 ] = data[ i ].row();	}	array[ (2*i) ] = 0;	array[ (2*i)+1 ] = 0;    } , {	array.resize( value.length() );	array = value.local8Bit();    } );    return sysd->writeKey( key, array, REG_SZ );}bool QSettingsPrivate::sysRemoveEntry( const QString &key ){    Q_ASSERT(sysd);    QString e;    LONG res;    HKEY handle = 0;    for ( QStringList::Iterator it = sysd->paths.fromLast(); it != sysd->paths.end(); --it ) {	QString k = (*it).isEmpty() ? key : *it + "/" + key;	handle = sysd->openKey( k, FALSE, TRUE );	e = sysd->entry( k );	if ( handle )	    break;    }    if ( !handle )	return TRUE;    if ( e == "Default" || e == "." )	e = "";    QT_WA( {	res = RegDeleteValueW( handle, (TCHAR*)e.ucs2() );    } , {	res = RegDeleteValueA( handle, e.local8Bit() );    } );    if ( res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND ) {#if defined(QT_CHECK_STATE)	qSystemWarning( "Error deleting value " + key, res );#endif	return FALSE;    }    char vname[2];    DWORD vnamesz = 1;    FILETIME lastWrite;#ifdef Q_OS_TEMP    LONG res2 = RegEnumValue( handle, 0, (LPWSTR)vname, &vnamesz, NULL, NULL, NULL, NULL );    LONG res3 = RegEnumKeyEx( handle, 0, (LPWSTR)vname, &vnamesz, NULL, NULL, NULL, &lastWrite );#else    LONG res2 = RegEnumValueA( handle, 0, vname, &vnamesz, NULL, NULL, NULL, NULL );    LONG res3 = RegEnumKeyExA( handle, 0, vname, &vnamesz, NULL, NULL, NULL, &lastWrite );#endif    if ( res2 == ERROR_NO_MORE_ITEMS && res3 == ERROR_NO_MORE_ITEMS )#ifdef Q_OS_TEMP	RegDeleteKeyW( handle, L"" );#else    RegDeleteKeyA( handle, "" );#endif    else	RegCloseKey( handle );    return TRUE;}QStringList QSettingsPrivate::sysEntryList( const QString &key ) const{    Q_ASSERT(sysd);    QStringList result;    HKEY handle = 0;    for ( QStringList::Iterator it = sysd->paths.fromLast(); it != sysd->paths.end(); --it ) {	QString k = (*it).isEmpty() ? key + "/fake" : *it + "/" + key + "/fake";	handle = sysd->openKey( k, FALSE );	if ( handle )	    break;    }    if ( !handle )	return result;    DWORD count;    DWORD maxlen;        QT_WA( {	RegQueryInfoKeyW( handle, NULL, NULL, NULL, NULL, NULL, NULL, &count, &maxlen, NULL, NULL, NULL );    } , {	RegQueryInfoKeyA( handle, NULL, NULL, NULL, NULL, NULL, NULL, &count, &maxlen, NULL, NULL, NULL );    } );    maxlen++;    DWORD index = 0;    TCHAR *vnameT = new TCHAR[ maxlen ];    char *vnameA = new char[ maxlen ];    QString qname;    DWORD vnamesz = 0;    LONG res = ERROR_SUCCESS;    while ( res != ERROR_NO_MORE_ITEMS ) {	vnamesz = maxlen;	QT_WA( {	    res = RegEnumValueW( handle, index, vnameT, &vnamesz, NULL, NULL, NULL, NULL );	    if ( res == ERROR_SUCCESS )		qname = QString::fromUcs2( (ushort*)vnameT );	} , {	    res = RegEnumValueA( handle, index, vnameA, &vnamesz, NULL, NULL, NULL, NULL );	    if ( res == ERROR_SUCCESS )		qname = vnameA;	} );	if ( res == ERROR_NO_MORE_ITEMS )	    break;	if ( qname.isEmpty() )	    result.append( "Default" );	else	    result.append( qname );	++index;    }    delete [] vnameA;    delete [] vnameT;    RegCloseKey( handle );    return result;}QStringList QSettingsPrivate::sysSubkeyList( const QString &key ) const{    Q_ASSERT(sysd);    QStringList result;    HKEY handle = 0;    for ( QStringList::Iterator it = sysd->paths.fromLast(); it != sysd->paths.end(); --it ) {	QString k = (*it).isEmpty() ? key + "/fake" : *it + "/" + key + "/fake";	handle = sysd->openKey( k, FALSE );	if ( handle )	    break;    }    if ( !handle )	return result;    DWORD count;    DWORD maxlen;    QT_WA( {	RegQueryInfoKeyW( handle, NULL, NULL, NULL, &count, &maxlen, NULL, NULL, NULL, NULL, NULL, NULL );	maxlen++;    } , {	RegQueryInfoKeyA( handle, NULL, NULL, NULL, &count, &maxlen, NULL, NULL, NULL, NULL, NULL, NULL );    } );    DWORD index = 0;    FILETIME lastWrite;    TCHAR *vnameT = new TCHAR[ maxlen ];    char *vnameA = new char[ maxlen ];    QString qname;    DWORD vnamesz = 0;    LONG res = ERROR_SUCCESS;    while ( res != ERROR_NO_MORE_ITEMS ) {	vnamesz = maxlen;	QT_WA( {	    res = RegEnumKeyExW( handle, index, vnameT, &vnamesz, NULL, NULL, NULL, &lastWrite );	    if ( res == ERROR_SUCCESS )		qname = QString::fromUcs2( (ushort*)vnameT );	} , {	    res = RegEnumKeyExA( handle, index, vnameA, &vnamesz, NULL, NULL, NULL, &lastWrite );	    if ( res == ERROR_SUCCESS )		qname = vnameA;	} );	if ( res == ERROR_NO_MORE_ITEMS )	    break;	result.append( qname );	++index;    }    delete [] vnameA;    delete [] vnameT;    RegCloseKey( handle );    return result;}void QSettingsPrivate::sysInsertSearchPath( QSettings::System s, const QString &path ){    Q_ASSERT(sysd);    if ( s != QSettings::Windows || path.isEmpty() )	return;    QString p = path;    if ( p[0] != '/' )	p = "/" + p;    sysd->paths.append( p );}void QSettingsPrivate::sysRemoveSearchPath( QSettings::System s, const QString &path ){    Q_ASSERT(sysd);    if ( s != QSettings::Windows || path.isEmpty() )	return;    QString p = path;    if ( p[0] != '/' )	p = "/" + p;    sysd->paths.remove( p );}#endif //QT_NO_SETTINGS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -