File: classDataManager.cpp

package info (click to toggle)
unixodbc 2.2.14p2-5
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,620 kB
  • sloc: ansic: 104,255; cpp: 38,573; sh: 15,958; makefile: 2,728; sql: 1
file content (298 lines) | stat: -rw-r--r-- 8,821 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**************************************************
 *
 *  TODO's  (Look for TODO in the source)
 *
 *  - Use SQLGetInfo
 *      + to determine the library seperator (. or /)
 *  - Use SQLSetStmtAttr
 *      + to set SQL_ATTR_METADATA_ID TRUE
 *        in the cases where wild cards
 *        are not wanted (SQLColumns, SQLTables, ...)
 *
 **************************************************
 * This code was created by Peter Harvey @ CodeByDesign.
 * Released under GPL 18.FEB.99
 *
 * Contributions from...
 * -----------------------------------------------
 * Peter Harvey         - pharvey@codebydesign.com
 **************************************************/

#ifdef QT_V4LAYOUT
#include "classDataManager4.h"
#else
#include "classDataManager.h"
#endif
#include <stdlib.h>
#include <ini.h>
#ifdef QT_V4LAYOUT
#include <Qt/qpixmap.h>
#include <Qt/q3valuelist.h>
#include <Qt/qdir.h>
#else
#include <qpixmap.h>
#include <qdir.h>
#endif
#include "LinuxODBC.xpm"

classDataManager::classDataManager( QWidget *pParent, const char *pszName )
        : QWidget( pParent, pszName ) //, 503808 )
{
  setCaption( "DataManagerII " VERSION );

  setIcon( QPixmap( LinuxODBC_xpm ) );

  splSplitter = new QSplitter( this, "splSplitter" );

#ifdef QT_V4LAYOUT
  lvwBrowser = new Q3ListView( splSplitter, "lvwBrowser" );
#else
  lvwBrowser = new QListView( splSplitter, "lvwBrowser" );
#endif
  lvwBrowser->setMinimumSize( 50, 50 );
  lvwBrowser->setMaximumSize( 32767, 32767 );
#ifdef QT_V4LAYOUT
  connect( lvwBrowser, SIGNAL(rightButtonClicked(Q3ListViewItem*,const QPoint&,int)), SLOT(ItemMenu(Q3ListViewItem*,const QPoint&,int)) );
  connect( lvwBrowser, SIGNAL(selectionChanged(Q3ListViewItem*)), SLOT(ItemChanged(Q3ListViewItem*)) );
#else
  connect( lvwBrowser, SIGNAL(rightButtonClicked(QListViewItem*,const QPoint&,int)), SLOT(ItemMenu(QListViewItem*,const QPoint&,int)) );
  connect( lvwBrowser, SIGNAL(selectionChanged(QListViewItem*)), SLOT(ItemChanged(QListViewItem*)) );
#endif
#ifdef QT_V4LAYOUT
  lvwBrowser->setFocusPolicy( Qt::TabFocus );
  lvwBrowser->setBackgroundMode( Qt::PaletteBackground );
#else
  lvwBrowser->setFocusPolicy( QWidget::TabFocus );
  lvwBrowser->setBackgroundMode( QWidget::PaletteBackground );
#endif
  lvwBrowser->setFrameStyle( 17 );
#ifdef QT_V4LAYOUT
  lvwBrowser->setResizePolicy( Q3ScrollView::Manual );
  lvwBrowser->setVScrollBarMode( Q3ScrollView::Auto );
  lvwBrowser->setHScrollBarMode( Q3ScrollView::Auto );
#else
  lvwBrowser->setResizePolicy( QScrollView::Manual );
  lvwBrowser->setVScrollBarMode( QScrollView::Auto );
  lvwBrowser->setHScrollBarMode( QScrollView::Auto );
#endif
  lvwBrowser->setTreeStepSize( 20 );
  lvwBrowser->setMultiSelection( FALSE );
  lvwBrowser->setAllColumnsShowFocus( TRUE );
  lvwBrowser->setItemMargin( 1 );
  lvwBrowser->setRootIsDecorated( TRUE );
  lvwBrowser->addColumn( "Object", -1 );
#ifdef QT_V4LAYOUT
  lvwBrowser->setColumnWidthMode( 0, Q3ListView::Maximum );
#else
  lvwBrowser->setColumnWidthMode( 0, QListView::Maximum );
#endif
  lvwBrowser->setColumnAlignment( 0, 1 );
  lvwBrowser->addColumn( "Type", -1 );
#ifdef QT_V4LAYOUT
  lvwBrowser->setColumnWidthMode( 1, Q3ListView::Maximum );
#else
  lvwBrowser->setColumnWidthMode( 1, QListView::Maximum );
#endif
  lvwBrowser->setColumnAlignment( 1, 1 );
  lvwBrowser->addColumn( "Description", -1 );
#ifdef QT_V4LAYOUT
  lvwBrowser->setColumnWidthMode( 2, Q3ListView::Maximum );
#else
  lvwBrowser->setColumnWidthMode( 2, QListView::Maximum );
#endif
  lvwBrowser->setColumnAlignment( 2, 1 );
  lvwBrowser->setSorting( -1, 0 );
#ifdef QT_V4LAYOUT
  lvwBrowser->setSelectionMode( Q3ListView::Single );
#else
  lvwBrowser->setSelectionMode( QListView::Single );
#endif

  pCanvas = new classCanvas( splSplitter, "fraProperties" );

  LoadState();
  setMinimumSize( 0, 0 );
  setMaximumSize( 32767, 32767 );

  pODBC = new classODBC( lvwBrowser, pCanvas );
  pODBC->setOpen( TRUE ) ;
}

classDataManager::~classDataManager()
{
  SaveState();
}

#ifdef QT_V4LAYOUT
void classDataManager::ItemMenu(Q3ListViewItem *pItem, const QPoint &, int )
#else
void classDataManager::ItemMenu(QListViewItem *pItem, const QPoint &, int )
#endif
{
  if ( pItem == 0 ) return;
  lvwBrowser->setSelected( pItem, TRUE );
}

#ifdef QT_V4LAYOUT
void classDataManager::ItemChanged(Q3ListViewItem *pItem )
#else
void classDataManager::ItemChanged(QListViewItem *pItem )
#endif
{
  QString         qsType;

  if ( pItem == 0 ) return;
  lvwBrowser->setSelected( pItem, TRUE );
  pODBC->selectionChanged( pItem );
}

void classDataManager::Exit()
{
  exit( 0 );
}

void classDataManager::About()
{
  QMessageBox::information( this, "DataManager",  "DataManager " VERSION );
}

void classDataManager::resizeEvent( QResizeEvent * )
{
  int marg = 1;
  int w = width()  - marg * 2;
  int h = height() - marg * 2;

  splSplitter->setGeometry( marg, marg, w, h );
}

void classDataManager::LoadState()
{
  HINI hIni;
  char szObject[INI_MAX_OBJECT_NAME+1];
  char szPropertyName[INI_MAX_PROPERTY_NAME+1];
  char szPropertyValue[INI_MAX_PROPERTY_VALUE+1];
  char szINI[ODBC_FILENAME_MAX+1];

  sprintf( szINI, "%s/%s", QDir::homeDirPath().ascii(), ".DataManager/DataManager.ini" );
  // Fall out if the file does not exist
  if ( !QFile::exists( szINI ) )
    return ;

  if ( iniOpen( &hIni, szINI, "#;", '[', ']', '=', TRUE ) != INI_ERROR )
  {
    iniObjectFirst( hIni );
    while ( iniObjectEOL( hIni ) == FALSE )
    {
      szObject[0]        = '\0';
      szPropertyName[0]  = '\0';
      szPropertyValue[0] = '\0';
      iniObject( hIni, szObject );
      iniPropertyFirst( hIni );
      if ( strcmp( szObject, "GEOMETRY" ) == 0 )
      {
        int nX = x();
        int nY = y();
        int nW = width();
        int nH = height();
        int nCell1 = 0;
        int nCell2 = 0;

        while ( iniPropertyEOL( hIni ) == FALSE )
        {
          iniProperty( hIni, szPropertyName );
          if ( strncmp( szPropertyName, "X", INI_MAX_PROPERTY_NAME ) == 0 )
          {
            iniValue( hIni, szPropertyValue );
            nX = atoi( szPropertyValue );
          }
          if ( strncmp( szPropertyName, "Y", INI_MAX_PROPERTY_NAME ) == 0 )
          {
            iniValue( hIni, szPropertyValue );
            nY = atoi( szPropertyValue );
          }
          if ( strncmp( szPropertyName, "W", INI_MAX_PROPERTY_NAME ) == 0 )
          {
            iniValue( hIni, szPropertyValue );
            nW = atoi( szPropertyValue );
          }
          if ( strncmp( szPropertyName, "H", INI_MAX_PROPERTY_NAME ) == 0 )
          {
            iniValue( hIni, szPropertyValue );
            nH = atoi( szPropertyValue );
          }
          if ( strncmp( szPropertyName, "W_CELL1", INI_MAX_PROPERTY_NAME ) == 0 )
          {
            iniValue( hIni, szPropertyValue );
            nCell1 = atoi( szPropertyValue );
          }
          if ( strncmp( szPropertyName, "W_CELL2", INI_MAX_PROPERTY_NAME ) == 0 )
          {
            iniValue( hIni, szPropertyValue );
            nCell2 = atoi( szPropertyValue );
          }

          iniPropertyNext( hIni );
        }
        resize( nW, nH );
        move( nX, nY );
        if ( nCell1 && nCell2 )
        {
#ifdef QT_V4LAYOUT
          Q3ValueList<int> list;
#else
          QValueList<int> list;
#endif
          list.append( nCell1 );
          list.append( nCell2 );
          splSplitter->setSizes( list );
        }
      }
      iniObjectNext( hIni );
    }
    iniClose( hIni );
  }
  else
  {
    QMessageBox::warning(   this, "DataManager",  "Could not open ~/.DataManager/DataManager.ini.\nYou may not have a home dir." );
  }
}

void classDataManager::SaveState()
{
  HINI hIni;
  char szPropertyValue[INI_MAX_PROPERTY_VALUE+1];
  char szINI[ODBC_FILENAME_MAX+1];

  sprintf( szINI, "%s/%s", QDir::homeDirPath().ascii(), ".DataManager/DataManager.ini" );
  if ( iniOpen( &hIni, szINI, "#;", '[', ']', '=', TRUE ) != INI_ERROR )
  {
    // REMOVE OBJECT
    iniObjectSeekSure( hIni, "GEOMETRY" );
    iniObjectDelete( hIni );

    // ADD OBJECT
    iniObjectSeekSure( hIni, "GEOMETRY" );
    sprintf( szPropertyValue, "%d", pos().x() );
    iniPropertyInsert( hIni, "X", szPropertyValue );

    sprintf( szPropertyValue, "%d", pos().y() );
    iniPropertyInsert( hIni, "Y", szPropertyValue );

    sprintf( szPropertyValue, "%d", size().width() );
    iniPropertyInsert( hIni, "W", szPropertyValue );

    sprintf( szPropertyValue, "%d", size().height() );
    iniPropertyInsert( hIni, "H", szPropertyValue );

    sprintf( szPropertyValue, "%d", splSplitter->sizes().first() );
    iniPropertyInsert( hIni, "W_CELL1", szPropertyValue );

    sprintf( szPropertyValue, "%d", splSplitter->sizes().last() );
    iniPropertyInsert( hIni, "W_CELL2", szPropertyValue );

    iniCommit( hIni );
    iniClose( hIni );
  }
}