File: CProperties.cpp

package info (click to toggle)
unixodbc 2.2.11-16
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 17,332 kB
  • ctags: 12,399
  • sloc: ansic: 116,624; cpp: 29,333; sh: 25,024; makefile: 3,002; lex: 241; yacc: 182; perl: 142; sed: 16; sql: 1
file content (243 lines) | stat: -rw-r--r-- 7,944 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
/**************************************************
 *
 *
 **************************************************
 * This code was created by Peter Harvey @ CodeByDesign.
 * Released under GPL 31.JAN.99
 *
 * Contributions from...
 * -----------------------------------------------
 * Peter Harvey		- pharvey@codebydesign.com
 **************************************************/

#include "CProperties.h"

#ifdef HAVE_STRCASECMP
#ifdef HAVE_STRINGS
#include <strings.h>
#endif
#else
int strcasecmp( char *, char * );
#endif

#include "checkOk.xpm"
#include "checkCancel.xpm"

CProperties::CProperties( QWidget* parent, const char* name, HODBCINSTPROPERTY hTheFirstProperty )
	: QMainWindow( parent, name, 0 )
{
    HODBCINSTPROPERTY 	hProperty;
	int				    nProperty;

    pMainWidget     = new QWidget( this );
    setCentralWidget( pMainWidget );

	pTopLayout		= new QVBoxLayout( pMainWidget );

    // SETUP TOOLBAR
    toolbarMain = new QToolBar( this );
    addToolBar( toolbarMain, tr( "ToolBar" ), Top, FALSE );
    new QToolButton( QPixmap( checkOk_xpm ), QString(tr("Save and Exit")), QString(""), this, SLOT(pbOk_Clicked()), toolbarMain );
    new QToolButton( QPixmap( checkCancel_xpm ), QString(tr("Cancel any changes and Exit")), QString(""), this, SLOT(pbCancel_Clicked()), toolbarMain );
    QWhatsThis::whatsThisButton ( toolbarMain );

	/* PROPERTIES */
    hFirstProperty = hTheFirstProperty;
	for ( nProperties = 0, hProperty = hFirstProperty; hProperty != NULL; hProperty = hProperty->pNext )
	{
		nProperties++;
	}

	pGridLayout = new QGridLayout( nProperties, 2, 2 );
	pTopLayout->addLayout( pGridLayout );
	pGridLayout->setColStretch ( 0, 0 );
	pGridLayout->setColStretch ( 1, 1 );

	for ( nProperty = 0, hProperty = hFirstProperty; hProperty != NULL; nProperty++, hProperty = hProperty->pNext )
	{
        QLabel *pLabel = new QLabel( pMainWidget );
		// 1ST COLUMN IS ALWAYS A LABEL CONTAINING THE PROPERTY NAME
        if ( hProperty->nPromptType != ODBCINST_PROMPTTYPE_HIDDEN )
        {
            if ( hProperty->pszHelp )
                QWhatsThis::add( pLabel, hProperty->pszHelp );
            pLabel->setLineWidth( 1 );
            pLabel->setText( hProperty->szName );
            pLabel->setMinimumSize( pLabel->sizeHint() );
            pLabel->setFixedHeight( pLabel->sizeHint().height() );
            pGridLayout->addWidget( pLabel, nProperty, 0 );
        }

		// 2ND COLUMN IS WHERE THE USER ENTERS DATA SO CREATE A WIDGET THAT IS MEANINGFULL
		switch ( hProperty->nPromptType )
		{
		case ODBCINST_PROMPTTYPE_LABEL:
			{
				QLabel *pLabel2 = new QLabel( pMainWidget );
                if ( hProperty->pszHelp )
                    QWhatsThis::add( pLabel2, hProperty->pszHelp );
				pLabel2->setFrameStyle( QFrame::Box | QFrame::Sunken );
				pLabel2->setLineWidth( 1 );
				pLabel2->setText( hProperty->szValue );
				pLabel2->setMinimumSize( pLabel2->sizeHint() );
				pLabel2->setFixedHeight( pLabel2->sizeHint().height() );
				pGridLayout->addWidget( pLabel2, nProperty, 1 );
                hProperty->pWidget = pLabel2;
                if ( hProperty->pszHelp ) QToolTip::add( pLabel2, hProperty->pszHelp );
			}
			break;
		case ODBCINST_PROMPTTYPE_LISTBOX:
			{
				QComboBox *pComboBox = new QComboBox( pMainWidget );
                if ( hProperty->pszHelp )
                    QWhatsThis::add( pComboBox, hProperty->pszHelp );
				pComboBox->insertStrList( (const char **)hProperty->aPromptData );
				pComboBox->setMinimumSize( pComboBox->sizeHint() );
				pComboBox->setFixedHeight( pComboBox->sizeHint().height() );
				pGridLayout->addWidget( pComboBox, nProperty, 1 );
                hProperty->pWidget = pComboBox;
                if ( hProperty->pszHelp ) QToolTip::add( pComboBox, hProperty->pszHelp );
                setCurrentItem( pComboBox, hProperty->szValue );
            }
			break;
		case ODBCINST_PROMPTTYPE_COMBOBOX:
			{
				QComboBox *pComboBox = new QComboBox( true, pMainWidget );
                if ( hProperty->pszHelp )
                    QWhatsThis::add( pComboBox, hProperty->pszHelp );
				pComboBox->insertStrList( (const char **)hProperty->aPromptData );
                pComboBox->setEditText( hProperty->szValue );
				pComboBox->setMinimumSize( pComboBox->sizeHint() );
				pComboBox->setFixedHeight( pComboBox->sizeHint().height() );
				pGridLayout->addWidget( pComboBox, nProperty, 1 );
                hProperty->pWidget = pComboBox;
                if ( hProperty->pszHelp ) QToolTip::add( pComboBox, hProperty->pszHelp );
			}
			break;
		case ODBCINST_PROMPTTYPE_FILENAME:
			{
                CFileSelector *pFileSelector = new CFileSelector( pMainWidget );
                if ( hProperty->pszHelp )
                    QWhatsThis::add( pFileSelector, hProperty->pszHelp );
				pFileSelector->pLineEdit->setText( hProperty->szValue );
				pGridLayout->addWidget( pFileSelector, nProperty, 1 );
                hProperty->pWidget = pFileSelector;
                if ( hProperty->pszHelp ) QToolTip::add( pFileSelector, hProperty->pszHelp );
			}
			break;
        case ODBCINST_PROMPTTYPE_HIDDEN:
			delete pLabel;
            break;
		default: // PROMPTTYPE_TEXTEDIT and PROMPTTYPE_TEXTEDIT_PASSWORD
			{
				QLineEdit *pLineEdit = new QLineEdit( pMainWidget );
                if ( hProperty->pszHelp )
                    QWhatsThis::add( pLineEdit, hProperty->pszHelp );
				pLineEdit->setText( hProperty->szValue );
				pLineEdit->setMinimumHeight( pLineEdit->sizeHint().height() );
				pLineEdit->setFixedHeight( pLineEdit->sizeHint().height() );
		if (hProperty->nPromptType == ODBCINST_PROMPTTYPE_TEXTEDIT_PASSWORD)
			pLineEdit->setEchoMode( QLineEdit::Password ) ;
				pGridLayout->addWidget( pLineEdit, nProperty, 1 );
				pLabel->setBuddy( pLineEdit );
                hProperty->pWidget = pLineEdit;
                if ( hProperty->pszHelp ) QToolTip::add( pLineEdit, hProperty->pszHelp );
			}
		}
	}
	/* SPACER */
	QLabel *pSpacer = new QLabel( pMainWidget );
	pTopLayout->addWidget( pSpacer, 11 );	

	pTopLayout->activate();
    pMainWidget->show();

}


CProperties::~CProperties()
{
}

/*
void resizeEvent( QResizeEvent *p )
{
	pTopLayout->resize( p->size() );
}
*/

void CProperties::pbOk_Clicked()
{
    HODBCINSTPROPERTY 	hProperty;


	// COLLECT ALL VALUES
	for ( hProperty = hFirstProperty; hProperty != NULL; hProperty = hProperty->pNext )
	{
        if ( hProperty == hFirstProperty )
        {
            // 
            // check name is filled in
            //
            if ( ((QLineEdit *)hProperty->pWidget)->text().isEmpty())
            {
                return;
            }
        }

		switch ( hProperty->nPromptType )
		{
		case ODBCINST_PROMPTTYPE_LABEL:
			{
				strncpy( hProperty->szValue, ((QLabel *)hProperty->pWidget)->text(), INI_MAX_PROPERTY_VALUE );
			}
			break;
		case ODBCINST_PROMPTTYPE_LISTBOX:
		case ODBCINST_PROMPTTYPE_COMBOBOX:
			{
				strncpy( hProperty->szValue, ((QComboBox *)hProperty->pWidget)->currentText(), INI_MAX_PROPERTY_VALUE );
			}
			break;
		case ODBCINST_PROMPTTYPE_FILENAME:
			{
				strncpy( hProperty->szValue, ((CFileSelector *)hProperty->pWidget)->pLineEdit->text(), INI_MAX_PROPERTY_VALUE );
			}
			break;
		case ODBCINST_PROMPTTYPE_HIDDEN:
            break;
		default: // PROMPTTYPE_TEXTEDIT and PROMPTTYPE_TEXTEDIT_PASSWORD
			{
				strncpy( hProperty->szValue, ((QLineEdit *)hProperty->pWidget)->text(), INI_MAX_PROPERTY_VALUE );
			}
		}
	} // for

	// LET CALLER KNOW WHAT TO DO NEXT
    emit Ok();
}

void CProperties::pbCancel_Clicked()
{
    emit Cancel();
}

void CProperties::setCurrentItem( QComboBox *pComboBox, char *pszItem )
{
    QString stringItem;
	int n 			= 0;
	int nCurItem 	= 0;

    stringItem = pszItem;
	nCurItem = pComboBox->currentItem();
	for ( n=0; n < pComboBox->count(); n++ )
	{
		pComboBox->setCurrentItem( n );
		if ( stringItem == pComboBox->currentText() )
		{
			return;
		}
	}

	pComboBox->setCurrentItem( nCurItem );
}