File: SQLManageDataSources.cpp

package info (click to toggle)
unixodbc 2.2.14p2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,628 kB
  • ctags: 12,533
  • sloc: ansic: 104,243; cpp: 38,571; sh: 15,958; makefile: 2,727; sql: 1
file content (130 lines) | stat: -rw-r--r-- 3,488 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*!
 * \file
 *
 * \author  Peter Harvey <pharvey@peterharvey.org>
 * \author  \sa AUTHORS file
 * \version 2
 * \date    2007
 * \license Copyright unixODBC Project 2007-2008, LGPL
 */
#include <odbcinstext.h>

#include <QApplication>

#include "CODBCConfig.h"
#include "CDSNWizard.h"

/*! 
 * \brief   Manage Data Sources
 * 
 *          SQLManageDataSources done using Qt4. Here is where we enter into Qt4 'world'.
 * 
 * \param   hWnd
 * 
 * \return  BOOL
 */
static BOOL QT4ManageDataSources( HWND hWnd )
{
    /*
     * Here, we handle case where a non QT app has called us. Our approach here is a bit different 
     * than what we used for Qt3 because we were getting segfault upon app exit. Here; we instantiate
     * with a 'new' and NOT 'delete' it. Its a work around.
     */ 
    if ( !qApp )
    {
        int argc = 1;
        char *argv[] = { "odbcinstQ4", NULL };

        QApplication *pApplication = new QApplication( argc, argv );
        QCoreApplication::setOrganizationName("unixODBC");
        QCoreApplication::setOrganizationDomain("unixodbc.org");
        QCoreApplication::setApplicationName("ODBC Administrator");
    }

    // missing parent widget? Use desktop...
    QWidget *pWidget = (QWidget*)hWnd;
    if ( !pWidget )
        pWidget = qApp->desktop();

    // show dialog...
	CODBCConfig odbcconfig( pWidget );
	if ( odbcconfig.exec() == QDialog::Accepted )
        return true;

    return false;
}

/*! 
 * \brief   Create Data Source
 * 
 *          SQLCreateDataSource done using Qt4. Here is where we enter into Qt4 'world'.
 * 
 * \param   hWnd
 * 
 * \return  BOOL
 */
static BOOL QT4CreateDataSource( HWND hWnd, LPCSTR pszDataSourceName )
{
    /*
     * Here, we handle case where a non QT app has called us. Our approach here is a bit different 
     * than what we used for Qt3 because we were getting segfault upon app exit. Here; we instantiate
     * with a 'new' and NOT 'delete' it. Its a work around.
     */ 
    if ( !qApp )
    {
        int argc = 1;
        char *argv[] = { "odbcinstQ4", NULL };

        QApplication *pApplication = new QApplication( argc, argv );
        QCoreApplication::setOrganizationName("unixODBC");
        QCoreApplication::setOrganizationDomain("unixodbc.org");
        QCoreApplication::setApplicationName("ODBC Administrator");
    }

    // missing parent widget? Use desktop...
    QWidget *pWidget = (QWidget*)hWnd;
    if ( !pWidget )
        pWidget = qApp->desktop();

    // show dialog...
    CDSNWizardData  WizardData( pszDataSourceName );
    CDSNWizard      odbccreate( &WizardData, pWidget );
	int nReturn = odbccreate.exec();

    //  sucks to have to do this after wizard is on its way out - no fail and Back :(
    if ( nReturn == QDialog::Accepted )
        return CODBCInst::saveDataSourceName( pWidget, WizardData.hFirstProperty, WizardData.nType );

    return false;
}

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * \brief   Plugin in entry point.
 *
 *          This entry point is called to implement the SQLManageDataSources call. This
 *          plugin does it using Qt4.
 */
BOOL ODBCManageDataSources( HWND hWnd )
{
    return QT4ManageDataSources( hWnd );
}

/*!
 * \brief   Plugin in entry point.
 *
 *          This entry point is called to implement the SQLCreateDataSource call. This
 *          plugin does it using Qt4.
 */
BOOL ODBCCreateDataSource( HWND hWnd, LPCSTR lpszDS )
{
    return QT4CreateDataSource( hWnd, lpszDS );
}

#ifdef __cplusplus
};
#endif