patch_for_bug_930.txt

patch to apply after string freeze - Jürgen Fischer, 2008-04-13 02:55 PM

Download (27.7 KB)

 
1
Index: qgsconnectiondialog.h
2
===================================================================
3
--- qgsconnectiondialog.h	(revision 8346)
4
+++ qgsconnectiondialog.h	(working copy)
5
@@ -1,45 +0,0 @@
6
-/***************************************************************************
7
-                          qgsconnectiondialog.h  -  description
8
-                             -------------------
9
-    begin                : Thu Dec 10 2003
10
-    copyright            : (C) 2003 by Denis Antipov
11
-    email                : 
12
- ***************************************************************************/
13
-
14
-/***************************************************************************
15
- *                                                                         *
16
- *   This program is free software; you can redistribute it and/or modify  *
17
- *   it under the terms of the GNU General Public License as published by  *
18
- *   the Free Software Foundation; either version 2 of the License, or     *
19
- *   (at your option) any later version.                                   *
20
- *                                                                         *
21
- ***************************************************************************/
22
-
23
-#ifndef QGSCONNECTIONDIALOG_H
24
-#define QGSCONNECTIONDIALOG_H
25
-
26
-// $Id$
27
-
28
-#include "ui_qgsconnectiondialogbase.h"
29
-#include "qgisgui.h"
30
-
31
-class QgsConnectionDialog : public QDialog, private Ui::QgsConnectionDialogBase
32
-{
33
-  Q_OBJECT
34
- public:
35
-
36
-    QgsConnectionDialog(QWidget *parent = 0, const QString& connName = QString::null, Qt::WFlags fl = QgisGui::ModalDialogFlags);
37
-    ~QgsConnectionDialog();
38
-    void testConnection();
39
-    void saveConnection();
40
-    void helpInfo();
41
-
42
-public slots:
43
-
44
-  void on_buttonBox_accepted()      { saveConnection(); }
45
-  void on_buttonBox_rejected()      { reject(); }
46
-  void on_buttonBox_helpRequested() { helpInfo(); }
47
-  void on_btnConnect_clicked()      { testConnection(); }
48
-};
49
-
50
-#endif
51
Index: qgsspit.h
52
===================================================================
53
--- qgsspit.h	(revision 8346)
54
+++ qgsspit.h	(working copy)
55
@@ -44,7 +44,7 @@
56
   //! Populate the list of available database connections
57
   void populateConnectionList();
58
   //! Connect to the selected database
59
-  void dbConnect() {};
60
+  void dbConnect();
61
   //! Return a list of selected tables
62
   QStringList selectedTables();
63
   //! Return the connection info
64
@@ -67,13 +67,8 @@
65
   void useDefaultGeom();
66
   //! Show brief help
67
   void helpInfo();
68
-  //! Get schemas available in the database
69
-  void getSchema();
70
-  void updateSchema();
71
   //! Import shapefiles into PostgreSQL
72
   void import();
73
-  //! Edit import properties of a shapefile in the queue
74
-  void editShapefile( int, int, int, const QPoint & );
75
 
76
 public slots:
77
 
78
@@ -95,7 +90,6 @@
79
   void on_tblShapefiles_itemClicked(QTableWidgetItem* item) 
80
     { tblShapefiles->editItem(item); }
81
   // When the user changes the selected connection, update the schema list
82
-  void on_cmbConnections_activated(int) { getSchema(); }
83
   void on_chkUseDefaultSrid_toggled(bool) { useDefaultSrid(); }
84
   void on_chkUseDefaultGeom_toggled(bool) { useDefaultGeom(); }
85
 
86
@@ -120,7 +114,7 @@
87
   QString defGeom;
88
   int defaultSridValue;
89
   QString defaultGeomValue;
90
-  QString gl_key;
91
+  PGconn *conn;
92
 };
93
 
94
 // We want to provide combo boxes in the table of shape files to
95
Index: qgsconnectiondialogbase.ui
96
===================================================================
97
--- qgsconnectiondialogbase.ui	(revision 8346)
98
+++ qgsconnectiondialogbase.ui	(working copy)
99
@@ -1,196 +0,0 @@
100
-<ui version="4.0" >
101
- <class>QgsConnectionDialogBase</class>
102
- <widget class="QDialog" name="QgsConnectionDialogBase" >
103
-  <property name="geometry" >
104
-   <rect>
105
-    <x>0</x>
106
-    <y>0</y>
107
-    <width>348</width>
108
-    <height>332</height>
109
-   </rect>
110
-  </property>
111
-  <property name="windowTitle" >
112
-   <string>Create a New PostGIS connection</string>
113
-  </property>
114
-  <property name="sizeGripEnabled" >
115
-   <bool>true</bool>
116
-  </property>
117
-  <property name="modal" >
118
-   <bool>true</bool>
119
-  </property>
120
-  <layout class="QVBoxLayout" >
121
-   <property name="margin" >
122
-    <number>9</number>
123
-   </property>
124
-   <property name="spacing" >
125
-    <number>6</number>
126
-   </property>
127
-   <item>
128
-    <widget class="QGroupBox" name="groupBox" >
129
-     <property name="title" >
130
-      <string>Connection Information</string>
131
-     </property>
132
-     <layout class="QGridLayout" >
133
-      <property name="margin" >
134
-       <number>9</number>
135
-      </property>
136
-      <property name="spacing" >
137
-       <number>6</number>
138
-      </property>
139
-      <item row="1" column="0" >
140
-       <layout class="QHBoxLayout" >
141
-        <property name="margin" >
142
-         <number>0</number>
143
-        </property>
144
-        <property name="spacing" >
145
-         <number>6</number>
146
-        </property>
147
-        <item>
148
-         <widget class="QCheckBox" name="chkStorePassword" >
149
-          <property name="text" >
150
-           <string>Save Password</string>
151
-          </property>
152
-         </widget>
153
-        </item>
154
-        <item>
155
-         <widget class="QPushButton" name="btnConnect" >
156
-          <property name="text" >
157
-           <string>Test Connect</string>
158
-          </property>
159
-         </widget>
160
-        </item>
161
-       </layout>
162
-      </item>
163
-      <item row="0" column="0" >
164
-       <layout class="QHBoxLayout" >
165
-        <property name="margin" >
166
-         <number>0</number>
167
-        </property>
168
-        <property name="spacing" >
169
-         <number>6</number>
170
-        </property>
171
-        <item>
172
-         <layout class="QVBoxLayout" >
173
-          <property name="margin" >
174
-           <number>0</number>
175
-          </property>
176
-          <property name="spacing" >
177
-           <number>6</number>
178
-          </property>
179
-          <item>
180
-           <widget class="QLabel" name="TextLabel1_2" >
181
-            <property name="text" >
182
-             <string>Name</string>
183
-            </property>
184
-           </widget>
185
-          </item>
186
-          <item>
187
-           <widget class="QLabel" name="TextLabel1" >
188
-            <property name="text" >
189
-             <string>Host</string>
190
-            </property>
191
-           </widget>
192
-          </item>
193
-          <item>
194
-           <widget class="QLabel" name="TextLabel2" >
195
-            <property name="text" >
196
-             <string>Database</string>
197
-            </property>
198
-           </widget>
199
-          </item>
200
-          <item>
201
-           <widget class="QLabel" name="TextLabel2_2" >
202
-            <property name="text" >
203
-             <string>Port</string>
204
-            </property>
205
-           </widget>
206
-          </item>
207
-          <item>
208
-           <widget class="QLabel" name="TextLabel3" >
209
-            <property name="text" >
210
-             <string>Username</string>
211
-            </property>
212
-           </widget>
213
-          </item>
214
-          <item>
215
-           <widget class="QLabel" name="TextLabel3_2" >
216
-            <property name="text" >
217
-             <string>Password</string>
218
-            </property>
219
-           </widget>
220
-          </item>
221
-         </layout>
222
-        </item>
223
-        <item>
224
-         <layout class="QVBoxLayout" >
225
-          <property name="margin" >
226
-           <number>0</number>
227
-          </property>
228
-          <property name="spacing" >
229
-           <number>6</number>
230
-          </property>
231
-          <item>
232
-           <widget class="QLineEdit" name="txtName" >
233
-            <property name="toolTip" >
234
-             <string>Name of the new connection</string>
235
-            </property>
236
-           </widget>
237
-          </item>
238
-          <item>
239
-           <widget class="QLineEdit" name="txtHost" />
240
-          </item>
241
-          <item>
242
-           <widget class="QLineEdit" name="txtDatabase" />
243
-          </item>
244
-          <item>
245
-           <widget class="QLineEdit" name="txtPort" >
246
-            <property name="text" >
247
-             <string>5432</string>
248
-            </property>
249
-           </widget>
250
-          </item>
251
-          <item>
252
-           <widget class="QLineEdit" name="txtUsername" />
253
-          </item>
254
-          <item>
255
-           <widget class="QLineEdit" name="txtPassword" >
256
-            <property name="echoMode" >
257
-             <enum>QLineEdit::Password</enum>
258
-            </property>
259
-           </widget>
260
-          </item>
261
-         </layout>
262
-        </item>
263
-       </layout>
264
-      </item>
265
-     </layout>
266
-    </widget>
267
-   </item>
268
-   <item>
269
-    <widget class="QDialogButtonBox" name="buttonBox" >
270
-     <property name="orientation" >
271
-      <enum>Qt::Horizontal</enum>
272
-     </property>
273
-     <property name="standardButtons" >
274
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok</set>
275
-     </property>
276
-    </widget>
277
-   </item>
278
-  </layout>
279
- </widget>
280
- <layoutdefault spacing="6" margin="11" />
281
- <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
282
- <tabstops>
283
-  <tabstop>txtName</tabstop>
284
-  <tabstop>txtHost</tabstop>
285
-  <tabstop>txtDatabase</tabstop>
286
-  <tabstop>txtPort</tabstop>
287
-  <tabstop>txtUsername</tabstop>
288
-  <tabstop>txtPassword</tabstop>
289
-  <tabstop>chkStorePassword</tabstop>
290
-  <tabstop>btnConnect</tabstop>
291
-  <tabstop>buttonBox</tabstop>
292
- </tabstops>
293
- <resources/>
294
- <connections/>
295
-</ui>
296
Index: qgsspitbase.ui
297
===================================================================
298
--- qgsspitbase.ui	(revision 8346)
299
+++ qgsspitbase.ui	(working copy)
300
@@ -55,7 +55,7 @@
301
      </property>
302
      <layout class="QGridLayout" >
303
       <property name="margin" >
304
-       <number>9</number>
305
+       <number>11</number>
306
       </property>
307
       <property name="spacing" >
308
        <number>6</number>
309
@@ -122,6 +122,19 @@
310
         </property>
311
        </widget>
312
       </item>
313
+      <item row="1" column="0" >
314
+       <widget class="QPushButton" name="btnConnect" >
315
+        <property name="toolTip" >
316
+         <string>Connect to PostGIS</string>
317
+        </property>
318
+        <property name="whatsThis" >
319
+         <string>Connect to PostGIS</string>
320
+        </property>
321
+        <property name="text" >
322
+         <string>Connect</string>
323
+        </property>
324
+       </widget>
325
+      </item>
326
      </layout>
327
     </widget>
328
    </item>
329
Index: qgsspit.cpp
330
===================================================================
331
--- qgsspit.cpp	(revision 8346)
332
+++ qgsspit.cpp	(working copy)
333
@@ -28,6 +28,7 @@
334
 #include <QTextCodec>
335
 #include <QList>
336
 #include <QTableWidgetItem>
337
+#include <QInputDialog>
338
 
339
 #include <iostream>
340
     
341
@@ -35,7 +36,7 @@
342
 
343
 #include "qgspgutil.h"
344
 #include "qgsspit.h"
345
-#include "qgsconnectiondialog.h"
346
+#include "qgsnewconnection.h"
347
 #include "qgsdatasourceuri.h"
348
 #include "qgsmessageviewer.h"
349
 #include "spiticon.xpm"
350
@@ -85,9 +86,8 @@
351
   txtPrimaryKeyName->setText("gid");
352
 
353
   schema_list << "public";
354
-  gl_key = "/PostgreSQL/connections/";
355
-  getSchema();
356
-
357
+  conn = NULL;
358
+  
359
   // Install a delegate that provides the combo box widget for
360
   // changing the schema (but there can only be one delegate per
361
   // table, so it also provides edit widgets for the textual columns).
362
@@ -102,6 +102,8 @@
363
 
364
 QgsSpit::~QgsSpit()
365
 {
366
+  if(conn)
367
+    PQfinish(conn);
368
 }
369
 
370
 void QgsSpit::populateConnectionList()
371
@@ -119,25 +121,22 @@
372
 
373
 void QgsSpit::newConnection()
374
 {
375
-  QgsConnectionDialog * con = new QgsConnectionDialog( this, tr("New Connection") );
376
+  QgsNewConnection *nc = new QgsNewConnection(this);
377
 
378
-  if ( con->exec() )
379
+  if (nc->exec())
380
   {
381
     populateConnectionList();
382
-    getSchema();
383
   }
384
-  delete con;
385
 }
386
 
387
 void QgsSpit::editConnection()
388
 {
389
-  QgsConnectionDialog * con = new QgsConnectionDialog( this, cmbConnections->currentText() );
390
-  if ( con->exec() )
391
+  QgsNewConnection *nc = new QgsNewConnection(this, cmbConnections->currentText());
392
+
393
+  if (nc->exec())
394
   {
395
-    con->saveConnection();
396
-    getSchema();
397
+    nc->saveConnection();
398
   }
399
-  delete con;
400
 }
401
 
402
 void QgsSpit::removeConnection()
403
@@ -155,8 +154,7 @@
404
     settings.removeEntry( key + "/password" );
405
     settings.removeEntry( key + "/save" );
406
 
407
-    cmbConnections->removeItem( cmbConnections->currentItem() );
408
-    getSchema();
409
+    cmbConnections->removeItem( cmbConnections->currentItem() );  
410
   }
411
 }
412
 
413
@@ -379,35 +377,65 @@
414
   e->exec(); // deletes itself on close
415
 }
416
 
417
-PGconn* QgsSpit::checkConnection()
418
+void QgsSpit::dbConnect()
419
 {
420
+  if(conn)
421
+  {
422
+    PQfinish(conn);
423
+    conn=NULL;
424
+  }
425
+
426
   QSettings settings;
427
-  PGconn * pd;
428
-  bool result = true;
429
   QString connName = cmbConnections->currentText();
430
   if ( connName.isEmpty() )
431
   {
432
     QMessageBox::warning( this, tr("Import Shapefiles"), tr("You need to specify a Connection first") );
433
-    result = false;
434
+    return;
435
   }
436
-  else
437
+
438
+  QString key = "/PostgreSQL/connections/" + connName;
439
+  QString database = settings.readEntry(key + "/database");
440
+  QString username = settings.readEntry(key + "/username");
441
+  QString password = settings.readEntry(key + "/password");
442
+
443
+  bool makeConnection = true;
444
+
445
+  if ( password.isEmpty() )
446
   {
447
+    // get password from user 
448
+    password = QInputDialog::getText(tr("Password for ") + username,
449
+      tr("Please enter your password:"),
450
+      QLineEdit::Password, QString::null, &makeConnection, this);
451
+  }
452
+
453
+  if(makeConnection)
454
+  {
455
+    // allow null password entry in case its valid for the database
456
     QgsDataSourceURI uri;
457
-    uri.setConnection( settings.readEntry( gl_key + connName + "/host" ),
458
-      settings.readEntry( gl_key + connName + "/port" ),
459
-      settings.readEntry( gl_key + connName + "/database" ),
460
-      settings.readEntry( gl_key + connName + "/username" ),
461
-      settings.readEntry( gl_key + connName + "/password" ) );
462
+    uri.setConnection( settings.readEntry(key + "/host"),
463
+      settings.readEntry(key + "/port"),
464
+      database,
465
+      settings.readEntry(key + "/username"),
466
+      password );
467
+  
468
+    conn = PQconnectdb( ( const char * ) uri.connInfo() );
469
+  }
470
 
471
-    pd = PQconnectdb( ( const char * ) uri.connInfo() );
472
-
473
-    if ( PQstatus( pd ) != CONNECTION_OK )
474
-    {
475
-      QMessageBox::warning( this, tr("Import Shapefiles"), tr("Connection failed - Check settings and try again") );
476
-      result = false;
477
+  if( conn==NULL || PQstatus(conn)!=CONNECTION_OK )
478
+  {
479
+    QMessageBox::warning( this, tr("Import Shapefiles"), tr("Connection failed - Check settings and try again") );
480
+    if(conn) {
481
+      PQfinish(conn);
482
+      conn=0;
483
     }
484
+  }
485
 
486
-    int errcode=PQsetClientEncoding(pd, QString("UNICODE").toLocal8Bit());
487
+  schema_list.clear();
488
+  schema_list << "public";
489
+
490
+  if(conn)
491
+  {
492
+    int errcode=PQsetClientEncoding(conn, QString("UNICODE").toLocal8Bit());
493
     if(errcode==0) 
494
     {
495
       QgsDebugMsg("encoding successfully set");
496
@@ -420,48 +448,29 @@
497
     {
498
       QgsDebugMsg("undefined return value from encoding setting");
499
     }
500
-  }
501
 
502
-  if (result )
503
-  {
504
     // Check that the database actually has postgis in it.
505
     QString sql1 = "SELECT postgis_lib_version()"; // available from v 0.9.0 onwards
506
     QString sql2 = "SELECT postgis_version()"; // depreciated 
507
 
508
-    PGresult* ver = PQexec(pd, sql1.toUtf8() );
509
+    PGresult* ver = PQexec(conn, sql1.toUtf8() );
510
     if ( PQresultStatus(ver) != PGRES_TUPLES_OK)
511
     {
512
       // In case the version of postgis is older than 0.9.0, try the
513
       // depreciated call before erroring out.
514
       PQclear(ver);
515
-      ver = PQexec(pd, sql2.toUtf8() );
516
+      ver = PQexec(conn, sql2.toUtf8() );
517
       if ( PQresultStatus(ver) != PGRES_TUPLES_OK)
518
       {
519
         QMessageBox::warning( this, tr("PostGIS not available"),
520
           tr("<p>The chosen database does not have PostGIS installed, "
521
           "but this is required for storage of spatial data.</p>"));
522
-        return NULL;
523
       }
524
     }
525
-    return pd;
526
-  }
527
-  else
528
-    return NULL;
529
-}
530
 
531
-void QgsSpit::getSchema()
532
-{
533
-  QSettings settings;
534
-  schema_list.clear();
535
-  schema_list << "public";
536
-  PGconn* pd = checkConnection();
537
-  if ( pd != NULL )
538
-  {
539
-    QString connName = cmbConnections->currentText();
540
-    QString user = settings.readEntry( gl_key + connName + "/username" );
541
     QString schemaSql = QString( "select nspname from pg_namespace,pg_user where nspowner=usesysid and usename=%1" )
542
-                          .arg( QgsPgUtil::quotedValue(user) );
543
-    PGresult *schemas = PQexec( pd, schemaSql.toUtf8() );
544
+      .arg( QgsPgUtil::quotedValue(username) );
545
+    PGresult *schemas = PQexec( conn, schemaSql.toUtf8() );
546
     // get the schema names
547
     if ( PQresultStatus( schemas ) == PGRES_TUPLES_OK )
548
     {
549
@@ -474,8 +483,6 @@
550
     PQclear( schemas );
551
   }
552
 
553
-  PQfinish(pd);
554
-
555
   // install a new delegate with an updated schema list (rather than
556
   // update the existing delegate because delegates don't seem able to
557
   // store modifiable data). 
558
@@ -487,15 +494,6 @@
559
   cmbSchema->setCurrentIndex( 0 ); // index 0 is always "public"
560
 }
561
 
562
-void QgsSpit::updateSchema()
563
-{
564
-  // install a new delegate with an updated schema list (rather than
565
-  // update the existing delegate because delegates don't seem able to
566
-  // store modifiable data). 
567
-  ShapefileTableDelegate* delegate = new ShapefileTableDelegate(tblShapefiles, schema_list);
568
-  tblShapefiles->setItemDelegate(delegate);
569
-}
570
-
571
 void QgsSpit::import()
572
 {
573
   QList<QTableWidgetItem*> selected = tblShapefiles->selectedItems();
574
@@ -505,15 +503,14 @@
575
   QString connName = cmbConnections->currentText();
576
   QSettings settings;
577
   bool canceled = false;
578
-  PGconn* pd = checkConnection();
579
-  QString query;
580
 
581
+  QString query;
582
   if ( total_features == 0 )
583
   {
584
     QMessageBox::warning( this, tr("Import Shapefiles"), 
585
       tr("You need to add shapefiles to the list first") );
586
   }
587
-  else if ( pd != NULL )
588
+  else if ( conn != NULL )
589
   {
590
     PGresult * res;
591
     QProgressDialog pro( tr("Importing files"), tr("Cancel"), 
592
@@ -585,7 +582,7 @@
593
       query = QString("SELECT f_table_name FROM geometry_columns WHERE f_table_name=%1 AND f_table_schema=%2")
594
                 .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text()) )
595
                 .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text()) );
596
-      res = PQexec( pd, query.toUtf8() );
597
+      res = PQexec( conn, query.toUtf8() );
598
       rel_exists1 = ( PQntuples( res ) > 0 );
599
 
600
       if ( PQresultStatus( res ) != PGRES_TUPLES_OK )
601
@@ -605,7 +602,7 @@
602
       query = QString("SELECT tablename FROM pg_tables WHERE tablename=%1  AND schemaname=%2")
603
                 .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) )
604
                 .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text() ) );
605
-      res = PQexec( pd, query.toUtf8() );
606
+      res = PQexec( conn, query.toUtf8() );
607
 
608
       rel_exists2 = ( PQntuples( res ) > 0 );
609
 
610
@@ -628,7 +625,7 @@
611
 
612
       // begin session
613
       query = "BEGIN";
614
-      res = PQexec( pd, query.toUtf8() );
615
+      res = PQexec( conn, query.toUtf8() );
616
       if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
617
       {
618
         QString err = PQresultErrorMessage( res );
619
@@ -649,7 +646,7 @@
620
       if ( tblShapefiles->item( i, ColDBSCHEMA )->text() != "public" )
621
         query += QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBSCHEMA )->text() ) + ",";
622
       query += QgsPgUtil::quotedValue( "public" );
623
-      res = PQexec( pd, query.toUtf8() );
624
+      res = PQexec( conn, query.toUtf8() );
625
 
626
       if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
627
       {
628
@@ -684,7 +681,7 @@
629
             query = QString("DROP TABLE %1")
630
                       .arg( QgsPgUtil::quotedIdentifier( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) );
631
 
632
-            res = PQexec( pd, query.toUtf8() );
633
+            res = PQexec( conn, query.toUtf8() );
634
             if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
635
             {
636
               QString err = PQresultErrorMessage( res );
637
@@ -709,7 +706,7 @@
638
               .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text()) );
639
 
640
             QStringList columns;
641
-            res = PQexec( pd, query.toUtf8() );
642
+            res = PQexec( conn, query.toUtf8() );
643
             if( PQresultStatus( res ) != PGRES_TUPLES_OK )
644
             {
645
               for(int i=0; i<PQntuples(res); i++)
646
@@ -724,7 +721,7 @@
647
                 .arg( QgsPgUtil::quotedValue( tblShapefiles->item( i, ColDBRELATIONNAME )->text() ) )
648
                 .arg( QgsPgUtil::quotedValue( columns[i] ) );
649
 
650
-              res = PQexec( pd, query.toUtf8() );
651
+              res = PQexec( conn, query.toUtf8() );
652
               if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
653
               {
654
                 QString err = PQresultErrorMessage( res );
655
@@ -742,7 +739,7 @@
656
         else
657
         {
658
           query = "ROLLBACK";
659
-          res = PQexec( pd, query.toUtf8() );
660
+          res = PQexec( conn, query.toUtf8() );
661
           if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
662
           {
663
             QString err = PQresultErrorMessage( res );
664
@@ -762,16 +759,17 @@
665
       int temp_progress = pro.value();
666
       canceled = false;
667
 
668
-      QString dbname = settings.readEntry( gl_key + connName + "/database" );
669
+      QString key = "/PostgreSQL/connections/" + connName;
670
+      QString dbname = settings.readEntry( key + "/database" );
671
       QString schema = tblShapefiles->item( i, ColDBSCHEMA )->text();
672
       QString srid = QString( "%1" ).arg( spinSrid->value() );
673
       QString errorText;
674
 
675
-      bool layerInserted = fileList[i]->insertLayer(dbname, schema, txtPrimaryKeyName->text(), txtGeomName->text(), srid, pd, pro, canceled, errorText );
676
+      bool layerInserted = fileList[i]->insertLayer(dbname, schema, txtPrimaryKeyName->text(), txtGeomName->text(), srid, conn, pro, canceled, errorText );
677
       if ( layerInserted && !canceled )
678
       { // if file has been imported successfully
679
         query = "COMMIT";
680
-        res = PQexec( pd, query.toUtf8() );
681
+        res = PQexec( conn, query.toUtf8() );
682
         if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
683
         {
684
           QString err = PQresultErrorMessage( res );
685
@@ -805,7 +803,7 @@
686
         QString errTxt = error + "\n" + errorText;
687
         QMessageBox::warning( this, tr("Import Shapefiles"), errTxt );
688
         query = "ROLLBACK";
689
-        res = PQexec( pd, query.toUtf8() );
690
+        res = PQexec( conn, query.toUtf8() );
691
         if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
692
         {
693
           QString err = PQresultErrorMessage( res );
694
@@ -822,27 +820,18 @@
695
         break;
696
       }
697
     }
698
-    PQfinish( pd );
699
 
700
     if(successes==count)
701
       accept();
702
     else
703
       QMessageBox::information( &pro, tr("Import Shapefiles"), QString( tr("%1 of %2 shapefiles could not be imported.") ).arg(count-successes).arg(count) );
704
   }
705
-}
706
-
707
-void QgsSpit::editShapefile(int row, int col, int button, const QPoint& mousePos)
708
-{
709
-  // FIXME Is this necessary any more?
710
-  /*
711
-  if (ColFEATURECLASS == col || ColDBRELATIONNAME == col)
712
+  else
713
   {
714
-  tblShapefiles->editCell(row, col, FALSE);
715
+    QMessageBox::warning( this, tr("Import Shapefiles"), tr("You need to specify a Connection first") );
716
   }
717
-  */
718
 }
719
 
720
-
721
 QWidget *ShapefileTableDelegate::createEditor(QWidget *parent,
722
                                         const QStyleOptionViewItem &,
723
                                         const QModelIndex & index) const
724
Index: qgsconnectiondialog.cpp
725
===================================================================
726
--- qgsconnectiondialog.cpp	(revision 8346)
727
+++ qgsconnectiondialog.cpp	(working copy)
728
@@ -1,100 +0,0 @@
729
-/***************************************************************************
730
-                          qgsconnectiondialog.cpp  -  description
731
-                             -------------------
732
-    begin                : Thu Dec 10 2003
733
-    copyright            : (C) 2003 by Denis Antipov
734
-    email                :
735
- ***************************************************************************/
736
-
737
-/***************************************************************************
738
- *                                                                         *
739
- *   This program is free software; you can redistribute it and/or modify  *
740
- *   it under the terms of the GNU General Public License as published by  *
741
- *   the Free Software Foundation; either version 2 of the License, or     *
742
- *   (at your option) any later version.                                   *
743
- *                                                                         *
744
- ***************************************************************************/
745
- 
746
-// $Id$
747
-
748
-#include <iostream>
749
-
750
-#include <QSettings>
751
-#include <QMessageBox>
752
-
753
-extern "C"
754
-{
755
-  #include <libpq-fe.h>
756
-}
757
-
758
-#include "qgsconnectiondialog.h"
759
-#include "qgsmessageviewer.h"
760
-#include "qgsdatasourceuri.h"
761
-
762
-QgsConnectionDialog::QgsConnectionDialog(QWidget *parent, const QString& connName, Qt::WFlags fl)
763
-	: QDialog(parent, fl)
764
-{
765
-    setupUi(this);
766
-	if (!connName.isEmpty()) {
767
-		QSettings settings;
768
-		QString key = "/PostgreSQL/connections/" + connName;
769
-		txtHost->setText(settings.readEntry(key + "/host"));
770
-		txtDatabase->setText(settings.readEntry(key + "/database"));
771
-		if(settings.readEntry(key + "/port").length() ==0){
772
-			txtPort->setText("5432");
773
-		}
774
-		else {
775
-			txtPort->setText(settings.readEntry(key + "/port"));
776
-		}
777
-		txtUsername->setText(settings.readEntry(key + "/username"));
778
-		if(settings.readEntry(key + "/save") == "true"){
779
-			txtPassword->setText(settings.readEntry(key + "/password"));
780
-			chkStorePassword->setChecked(true);
781
-		}
782
-		txtName->setText(connName);
783
-	}
784
-}
785
-
786
-QgsConnectionDialog::~QgsConnectionDialog()
787
-{
788
-
789
-}
790
-
791
-
792
-void QgsConnectionDialog::testConnection()
793
-{
794
-  QgsDataSourceURI uri;
795
-  uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
796
-  PGconn *pd = PQconnectdb((const char *) uri.connInfo() );
797
-
798
-  if (PQstatus(pd) == CONNECTION_OK) {
799
-    // Database successfully opened; we can now issue SQL commands.
800
-    QMessageBox::information(this, tr("Test connection"), tr("Connection to ") + txtDatabase->text() + tr(" was successfull"));
801
-  } else {
802
-    QMessageBox::information(this, tr("Test connection"), tr("Connection failed - Check settings and try again "));
803
-  }
804
-
805
-  PQfinish(pd);
806
-}
807
-
808
-void QgsConnectionDialog::saveConnection()
809
-{
810
-	QSettings settings;
811
-	QString baseKey = "/PostgreSQL/connections/";
812
-	baseKey += txtName->text();
813
-	settings.writeEntry(baseKey + "/host", txtHost->text());
814
-	settings.writeEntry(baseKey + "/database", txtDatabase->text());
815
-	settings.writeEntry(baseKey + "/port", txtPort->text());
816
-	settings.writeEntry(baseKey + "/username", txtUsername->text());
817
-	settings.writeEntry(baseKey + "/password", txtPassword->text());
818
-  if(chkStorePassword->isChecked())  settings.writeEntry(baseKey + "/save", "true");
819
-  else settings.writeEntry(baseKey + "/save", "false");
820
-  accept();
821
-}
822
-
823
-void QgsConnectionDialog::helpInfo(){
824
-  QString message = tr("General Interface Help:\n\n");
825
-  QgsMessageViewer * e = new QgsMessageViewer(this);
826
-  e->setMessageAsPlainText(message);
827
-  e->exec();  // deletes itself on close
828
-}
829
Index: CMakeLists.txt
830
===================================================================
831
--- CMakeLists.txt	(revision 8346)
832
+++ CMakeLists.txt	(working copy)
833
@@ -4,7 +4,7 @@
834
 
835
 SET (SPIT_SRCS
836
      qgsspit.cpp
837
-     qgsconnectiondialog.cpp
838
+     ../../app/qgsnewconnection.cpp
839
      qgspgutil.cpp
840
      qgsshapefile.cpp
841
 )
842
@@ -20,7 +20,7 @@
843
 )
844
 
845
 SET (SPIT_UIS
846
-     qgsconnectiondialogbase.ui
847
+     ../../ui/qgsnewconnectionbase.ui
848
      qgsspitbase.ui
849
      ../../ui/qgsmessageviewer.ui
850
 )
851
@@ -28,7 +28,7 @@
852
 SET (SPIT_EXE_MOC_HDRS
853
      qgsspit.h
854
      qgsshapefile.h
855
-     qgsconnectiondialog.h
856
+     ../../app/qgsnewconnection.h
857
 )
858
 
859
 SET (SPIT_PLUGIN_MOC_HDRS
860
@@ -54,6 +54,8 @@
861
      ${CMAKE_CURRENT_BINARY_DIR}
862
      ../../core ../../core/raster ../../core/renderer ../../core/symbology
863
      ../../gui
864
+     ../../ui
865
+     ../../app
866
      ..
867
      ${POSTGRES_INCLUDE_DIR}
868
      ${GDAL_INCLUDE_DIR}
869
Index: .cvsignore
870
===================================================================
871
--- .cvsignore	(revision 8346)
872
+++ .cvsignore	(working copy)
873
@@ -16,4 +16,3 @@
874
 qgsscangeometries.h
875
 qgsspitbase.cpp
876
 qgsspitbase.h
877
-