File: classDataManager.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 (240 lines) | stat: -rw-r--r-- 7,326 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
/**************************************************
 *
 *  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
 **************************************************/

#include "classDataManager.h"
#include <stdlib.h>
#include <ini.h>
#include <qpixmap.h>
#include <qdir.h>
#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" );

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

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

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

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

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

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

void classDataManager::ItemChanged(QListViewItem *pItem )
{
  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 )
        {
          QValueList<int> list;
          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 );
  }
}