1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/**************************************************
*
*
**************************************************
* This code was created by Peter Harvey @ CodeByDesign.
* Released under GPL 18.FEB.99
*
* Contributions from...
* -----------------------------------------------
* Peter Harvey - pharvey@codebydesign.com
**************************************************/
#include "classDataSources.h"
#include "qpixmap.h"
#include <ini.h>
#include <odbcinst.h>
#include "datasourcesuser.xpm"
#include "datasourcessystem.xpm"
classDataSources::classDataSources( QListViewItem *pParent, QListViewItem *pAfter, classCanvas *pCanvas, classODBC::DSType dataSourceType )
: classNode( pParent, pAfter, pCanvas ), dataSourceType( dataSourceType )
{
switch ( dataSourceType )
{
case classODBC::System :
setText( 0, "System Data Sources" );
setText( 1, "" );
setText( 2, "" );
setPixmap( 0, QPixmap( datasourcessystem_xpm ) );
break;
default:
setText( 0, "User Data Sources" );
setText( 1, "" );
setText( 2, "" );
setPixmap( 0, QPixmap( datasourcesuser_xpm ) );
}
pCanvas = pCanvas;
listDataSources.setAutoDelete( TRUE );
setExpandable( TRUE );
}
void classDataSources::setOpen( bool bOpen )
{
if ( bOpen && !childCount() ) // Load only once
{
char szResults[9600];
char szObjectName[INI_MAX_OBJECT_NAME+1];
memset( szResults, 0, sizeof(szResults) ); // Results buffer must be cleared
classDataSource *pDataSource = NULL ;
if ( dataSourceType == classODBC::User )
SQLSetConfigMode( ODBC_USER_DSN );
else
SQLSetConfigMode( ODBC_SYSTEM_DSN );
if ( SQLGetPrivateProfileString( 0, 0, 0, szResults, sizeof(szResults), 0 ) > 0 )
{
for ( int nElement = 0; iniElement( szResults, '\0', '\0', nElement, szObjectName, INI_MAX_OBJECT_NAME ) == INI_SUCCESS; nElement++ )
listDataSources.append( pDataSource = new classDataSource( this, pDataSource, pCanvas, dataSourceType, szObjectName ) );
}
SQLSetConfigMode( ODBC_BOTH_DSN );
}
QListViewItem::setOpen( bOpen );
}
void classDataSources::selectionChanged( QListViewItem *p )
{
classDataSource *pDataSource;
for ( pDataSource = listDataSources.first(); pDataSource != 0; pDataSource = listDataSources.next() )
pDataSource->selectionChanged( p );
}
|