29#include "kspread_kexiimportdialog.h"
34#include <kpushbutton.h>
35#include <tdelistview.h>
37#include <tqradiobutton.h>
38#include <tqtextedit.h>
39#include <tqcheckbox.h>
43#include <kexidb/global.h>
44#include <kexidb/kexidb_export.h>
45#include <kexidb/connectiondata.h>
46#include <kexidb/connection.h>
47#include <kexidb/drivermanager.h>
48#include <kexidb/driver.h>
51#include <kspread_view.h>
52#include <kspread_doc.h>
53#include <kspread_map.h>
61 KSpreadKexiImportDialog::KSpreadKexiImportDialog(TQWidget* parent,
const char* name)
62 : KSpreadKexiImportDialogBase(parent,name)
64 connect(this->m_insertButton,TQ_SIGNAL(clicked()),
this,TQ_SLOT(accept()));
65 connect(this->m_cancelButton,TQ_SIGNAL(clicked()),
this,TQ_SLOT(reject()));
72KSpreadKexiImportDialog::~KSpreadKexiImportDialog()
78void KSpreadKexiImportDialog::accept()
80 kdDebug() <<
"insert kexi data dialog accepted (insert button clicked)" << endl;
81 done(TQDialog::Accepted);
88void KSpreadKexiImportDialog::reject()
90 kdDebug() <<
"insert kexi data dialog rejected (cancel button clicked)" << endl;
91 done(TQDialog::Rejected);
99void KSpreadKexiImportDialog::openDatabase( TQString fileName , KexiDB::ConnectionData *cdata)
101 kdDebug() <<
"openDatabase" << endl;
103 KexiDB::DriverManager *dm;
104 KexiDB::ConnectionData cd;
107 dm =
new KexiDB::DriverManager();
108 dr = dm->driver(
"sqlite3");
111 kdDebug() <<
"Unable to create driver" << endl;
122 if (!fileName.isEmpty())
124 cd.setFileName(fileName);
128 kdDebug() <<
"No file name" << endl;
129 KMessageBox::error(NULL, i18n(
"No file specified"), i18n(
"Error"));
134 conn = dr->createConnection(cd);
138 KMessageBox::error(NULL, i18n(
"Error creating connection"), i18n(
"Error"));
144 KMessageBox::error(NULL, i18n(
"Error connecting to database"), i18n(
"Error"));
149 if (!conn->useDatabase( fileName ))
151 KMessageBox::error(NULL, i18n(
"Error using database"), i18n(
"Error"));
164void KSpreadKexiImportDialog::populateTables()
166 TQValueList<int> tids;
167 TQValueList<int> qids;
169 kdDebug() <<
"Getting Tables and Queries" << endl;
170 tids = conn->objectIds(KexiDB::TableObjectType);
171 qids = conn->objectIds(KexiDB::QueryObjectType);
173 kdDebug() << qids.count() <<
" queries " << tids.count() <<
" tables" << endl;
175 TQValueList<int>::iterator it;
177 for ( it = tids.begin(); it != tids.end(); ++it )
179 (void)
new TDEListViewItem(m_sourceList,
"Table", conn->tableSchema(*it)->name());
180 kdDebug() <<
"Table ID:" << (*it) <<
" " << conn->tableSchema(*it)->name()<< endl;
183 for ( it = qids.begin(); it != qids.end(); ++it )
185 (void)
new TDEListViewItem(m_sourceList,
"Query", conn->querySchema(*it)->name());
186 kdDebug() <<
"Query ID:" << (*it) <<
" " << conn->querySchema(*it)->name() << endl;
190 if(m_sourceList->firstChild())
192 m_sourceList->setSelected(m_sourceList->firstChild(),
true);
201TQString KSpreadKexiImportDialog::customQueryString()
203 return m_CustomQueryText->text();
206TQPtrList<TQListViewItem> KSpreadKexiImportDialog::selectedItems()
208 TQPtrList<TQListViewItem> lst;
209 TQListViewItemIterator it( m_sourceList );
210 while ( it.current() )
212 if ( it.current()->isSelected() )
213 lst.append( it.current() );
219bool KSpreadKexiImportDialog::customQuery()
221 return m_customQueryCheck->isChecked();
227int KSpreadKexiImportDialog::conversion()
229 if ( m_convKSRadio->isChecked())
231 else if ( m_convTextRadio->isChecked())