filters
kspread_kexiimportdialog.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "kspread_kexiimportdialog.h"
00030
00031
00032 #include <kdebug.h>
00033 #include <kglobal.h>
00034 #include <kpushbutton.h>
00035 #include <klistview.h>
00036 #include <kcombobox.h>
00037 #include <qradiobutton.h>
00038 #include <qtextedit.h>
00039 #include <qcheckbox.h>
00040 #include <klocale.h>
00041
00042
00043 #include <kexidb/global.h>
00044 #include <kexidb/kexidb_export.h>
00045 #include <kexidb/connectiondata.h>
00046 #include <kexidb/connection.h>
00047 #include <kexidb/drivermanager.h>
00048 #include <kexidb/driver.h>
00049
00050
00051 #include <kspread_view.h>
00052 #include <kspread_doc.h>
00053 #include <kspread_map.h>
00054
00061 KSpreadKexiImportDialog::KSpreadKexiImportDialog(QWidget* parent, const char* name)
00062 : KSpreadKexiImportDialogBase(parent,name)
00063 {
00064 connect(this->m_insertButton,SIGNAL(clicked()),this,SLOT(accept()));
00065 connect(this->m_cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
00066 }
00067
00072 KSpreadKexiImportDialog::~KSpreadKexiImportDialog()
00073 {}
00074
00078 void KSpreadKexiImportDialog::accept()
00079 {
00080 kdDebug() << "insert kexi data dialog accepted (insert button clicked)" << endl;
00081 done(QDialog::Accepted);
00082 emit insertKexi();
00083 }
00084
00088 void KSpreadKexiImportDialog::reject()
00089 {
00090 kdDebug() << "insert kexi data dialog rejected (cancel button clicked)" << endl;
00091 done(QDialog::Rejected);
00092 }
00093
00099 void KSpreadKexiImportDialog::openDatabase( QString fileName , KexiDB::ConnectionData *cdata)
00100 {
00101 kdDebug() << "openDatabase" << endl;
00102 KexiDB::Driver *dr;
00103 KexiDB::DriverManager *dm;
00104 KexiDB::ConnectionData cd;
00105
00106
00107 dm = new KexiDB::DriverManager();
00108 dr = dm->driver("sqlite3");
00109 if (!dr)
00110 {
00111 kdDebug() << "Unable to create driver" << endl;
00112 return;
00113 }
00114
00115 if (cdata)
00116 {
00117
00118 cd = *cdata;
00119 }
00120 else
00121 {
00122 if (!fileName.isEmpty())
00123 {
00124 cd.setFileName(fileName);
00125 }
00126 else
00127 {
00128 kdDebug() << "No file name" << endl;
00129 KMessageBox::error(NULL, i18n("No file specified"), i18n("Error"));
00130 return;
00131 }
00132 }
00133
00134 conn = dr->createConnection(cd);
00135
00136 if (!conn)
00137 {
00138 KMessageBox::error(NULL, i18n("Error creating connection"), i18n("Error"));
00139 return;
00140 }
00141
00142 if(!conn->connect())
00143 {
00144 KMessageBox::error(NULL, i18n("Error connecting to database"), i18n("Error"));
00145 conn->debugError();
00146 return;
00147 }
00148
00149 if (!conn->useDatabase( fileName ))
00150 {
00151 KMessageBox::error(NULL, i18n("Error using database"), i18n("Error"));
00152 conn->debugError();
00153 return;
00154 }
00155
00156 populateTables();
00157
00158 }
00159
00164 void KSpreadKexiImportDialog::populateTables()
00165 {
00166 QValueList<int> tids;
00167 QValueList<int> qids;
00168
00169 kdDebug() << "Getting Tables and Queries" << endl;
00170 tids = conn->objectIds(KexiDB::TableObjectType);
00171 qids = conn->objectIds(KexiDB::QueryObjectType);
00172
00173 kdDebug() << qids.count() << " queries " << tids.count() << " tables" << endl;
00174
00175 QValueList<int>::iterator it;
00176
00177 for ( it = tids.begin(); it != tids.end(); ++it )
00178 {
00179 (void) new KListViewItem(m_sourceList,"Table", conn->tableSchema(*it)->name());
00180 kdDebug() << "Table ID:" << (*it) << " " << conn->tableSchema(*it)->name()<< endl;
00181 }
00182
00183 for ( it = qids.begin(); it != qids.end(); ++it )
00184 {
00185 (void) new KListViewItem(m_sourceList,"Query", conn->querySchema(*it)->name());
00186 kdDebug() << "Query ID:" << (*it) << " " << conn->querySchema(*it)->name() << endl;
00187 }
00188
00189
00190 if(m_sourceList->firstChild())
00191 {
00192 m_sourceList->setSelected(m_sourceList->firstChild(), true);
00193 }
00194
00195 }
00196
00201 QString KSpreadKexiImportDialog::customQueryString()
00202 {
00203 return m_CustomQueryText->text();
00204 }
00205
00206 QPtrList<QListViewItem> KSpreadKexiImportDialog::selectedItems()
00207 {
00208 QPtrList<QListViewItem> lst;
00209 QListViewItemIterator it( m_sourceList );
00210 while ( it.current() )
00211 {
00212 if ( it.current()->isSelected() )
00213 lst.append( it.current() );
00214 ++it;
00215 }
00216 return lst;
00217 }
00218
00219 bool KSpreadKexiImportDialog::customQuery()
00220 {
00221 return m_customQueryCheck->isChecked();
00222 }
00227 int KSpreadKexiImportDialog::conversion()
00228 {
00229 if ( m_convKSRadio->isChecked())
00230 return 1;
00231 else if ( m_convTextRadio->isChecked())
00232 return 2;
00233 else
00234 return -1;
00235 }
00236
|