From 8b78a8791bc539bcffe7159f9d9714d577cb3d7d Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- filters/kspread/kexi/Makefile.am | 4 +- filters/kspread/kexi/kspread_kexiimport.cc | 249 ---------------------- filters/kspread/kexi/kspread_kexiimport.cpp | 249 ++++++++++++++++++++++ filters/kspread/kexi/kspread_kexiimportdialog.cc | 236 -------------------- filters/kspread/kexi/kspread_kexiimportdialog.cpp | 236 ++++++++++++++++++++ 5 files changed, 487 insertions(+), 487 deletions(-) delete mode 100644 filters/kspread/kexi/kspread_kexiimport.cc create mode 100644 filters/kspread/kexi/kspread_kexiimport.cpp delete mode 100644 filters/kspread/kexi/kspread_kexiimportdialog.cc create mode 100644 filters/kspread/kexi/kspread_kexiimportdialog.cpp (limited to 'filters/kspread/kexi') diff --git a/filters/kspread/kexi/Makefile.am b/filters/kspread/kexi/Makefile.am index 6f76a296..acfedf97 100644 --- a/filters/kspread/kexi/Makefile.am +++ b/filters/kspread/kexi/Makefile.am @@ -7,9 +7,9 @@ INCLUDES= -I$(srcdir) -I$(top_srcdir)/kspread -I$(top_srcdir)/kexi $(KOFFICE_INC kde_module_LTLIBRARIES = libkspreadkexiimport.la -libkspreadkexiimport_la_SOURCES = kspread_kexiimport.cc \ +libkspreadkexiimport_la_SOURCES = kspread_kexiimport.cpp \ kspread_kexiimportdialogbase.ui \ - kspread_kexiimportdialog.cc + kspread_kexiimportdialog.cpp libkspreadkexiimport_la_LDFLAGS = -avoid-version -module -no-undefined \ $(all_libraries) libkspreadkexiimport_la_LIBADD = ../../../kexi/kexidb/libkexidb.la \ diff --git a/filters/kspread/kexi/kspread_kexiimport.cc b/filters/kspread/kexi/kspread_kexiimport.cc deleted file mode 100644 index 6100dabe..00000000 --- a/filters/kspread/kexi/kspread_kexiimport.cc +++ /dev/null @@ -1,249 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Adam Pigg * - * adam@piggz.co.uk * - * * - * Based on insert calendar code: * - * Copyright (C) 2005 by Raphael Langerhorst * - * raphael-langerhorst@gmx.at * - * * - * Permission is hereby granted, free of charge, to any person obtaining * - * a copy of this software and associated documentation files (the * - * "Software"), to deal in the Software without restriction, including * - * without limitation the rights to use, copy, modify, merge, publish, * - * distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to * - * the following conditions: * - * * - * The above copyright notice and this permission notice shall be * - * included in all copies or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * - * OTHER DEALINGS IN THE SOFTWARE. * - ***************************************************************************/ - -#include "kspread_kexiimport.h" - -#include "kspread_kexiimportdialog.h" - -//KSpread Includes -#include -#include -//#include -#include -#include -#include - -//Koffice Includes -#include -#include -#include - -//Kexi Includes -#include -#include -#include - -//KDE Includes -#include -#include -#include -#include -#include - -typedef KGenericFactory KSpreadKexiImportFactory; -K_EXPORT_COMPONENT_FACTORY( libkspreadkexiimport, KSpreadKexiImportFactory( "kofficefilters" ) ) - - -//============================================================================= - -KSpreadKexiImport::KSpreadKexiImport(KoFilter *parent, const char *name, const TQStringList&) -{ -} - -//============================================================================= - -KSpreadKexiImport::~KSpreadKexiImport() -{ - delete m_dialog; -} - -//============================================================================= - -KoFilter::ConversionStatus KSpreadKexiImport::convert( const TQCString& from, const TQCString& to ) -{ - TQPtrList objects; - TQString file( m_chain->inputFile() ); - - //Create dialog - m_dialog = new KSpreadKexiImportDialog(); - - m_dialog->openDatabase( file, 0); - if (!m_dialog->exec()) - { - return KoFilter::UserCancelled; - } - - objects = m_dialog->selectedItems(); - - kdDebug() << "Getting Documents..." << endl; - - KoDocument* document = m_chain->outputDocument(); - - if ( !document ) - return KoFilter::StupidError; - - kdDebug() << "here we go... " << document->className() << endl; - - if ( !::tqqt_cast( document ) ) - { - kdWarning() << "document isn't a KSpread::Doc but a " << document->className() << endl; - return KoFilter::NotImplemented; - } - if(from!="application/x-kexiproject-sqlite3" || to!="application/x-kspread") - { - kdWarning() << "Invalid mimetypes " << from << " " << to << endl; - return KoFilter::NotImplemented; - } - - ksdoc = static_cast( document ); // type checked above - - if(ksdoc->mimeType()!="application/x-kspread") - { - kdWarning() << "Invalid document mimetype " << ksdoc->mimeType() << endl; - return KoFilter::NotImplemented; - } - - document->emitBeginOperation(); - - TQListViewItem *itm; - for(itm = objects.first(); itm ; itm = objects.next()) - { - if (!insertObject(itm->text(1), itm->text(0))) - { - return KoFilter::StupidError; - } - } - if (m_dialog->customQuery()) - { - if (!insertObject(m_dialog->customQueryString(), "Custom")) - { - return KoFilter::StupidError; - } - } - - document->emitEndOperation(); - kdDebug() << "inserting kexi data completed" << endl; - return KoFilter::OK; -} - -bool KSpreadKexiImport::insertObject(const TQString& object, const TQString& type) -{ - TQStringList fieldNames; - KSpread::Sheet *sheet; - KexiDB::Parser *parser; - KexiDB::QuerySchema *query; - - sheet = ksdoc->map()->addNewSheet(); - if (!sheet) - { - KMessageBox::error(NULL, i18n("Cant find sheet"), i18n("Error")); - return false; - } - - if (type == "Custom") - { - sheet->setSheetName("Custom"); - } - else - { - sheet->setSheetName(object); - } - - //Get the field names - if (type == "Table") - { - fieldNames = m_dialog->connection()->tableSchema(object)->names(); - } - else if (type == "Query") - { - //Note....for queries such as select * from....field names are not available - fieldNames = m_dialog->connection()->querySchema(object)->names(); - } - else if (type == "Custom") //Custom Query - { - parser = new KexiDB::Parser(m_dialog->connection()); - parser->parse( object ); - - if (parser->operation() != KexiDB::Parser::OP_Select) - { - KMessageBox::error(NULL, i18n("Your query was invalid or not a SELECT query"), i18n("Error")); - return false; - } - query = parser->query(); - fieldNames = query->names(); - } - - //Insert the field headings - TQStringList::iterator it; - int i = 1; - for (it = fieldNames.begin(); it != fieldNames.end(); ++it, ++i) - { - KSpread::Cell *c = sheet->nonDefaultCell(i ,1); - c->setCellText(*it, true); - c->format()->setBgColor(TQColor(200,200,200)); - c->format()->setTextFontBold(true); - } - - //Insert the data - KexiDB::Cursor *cur; - if (type == "Table") //Table - { - cur = m_dialog->connection()->executeQuery( *(m_dialog->connection()->tableSchema(object))); - } - else if (type == "Query") //Query - { - cur = m_dialog->connection()->executeQuery( *(m_dialog->connection()->querySchema(object))); - } - else if (type == "Custom") //Custom Query - { - cur = m_dialog->connection()->executeQuery( *query ); - } - else - { - cur = 0; - } - - if (!cur) - { - KMessageBox::error(NULL, i18n("Error executing query"), i18n("Error")); - return false; - } - - cur->moveFirst(); - int j = cur->fieldCount(); - - unsigned int k = 2; //start on row 2 - bool asText = false; - - if(m_dialog->conversion() == 2) - asText = true; - - while (!cur->eof()) - { - for (i = 0; i < j; ++i) - { - sheet->nonDefaultCell(i+1 ,k)->setCellText(cur->value(i).toString(), asText); - } - - kdDebug() << k << endl; - cur->moveNext(); - ++k; - } - return true; -} -#include "kspread_kexiimport.moc" diff --git a/filters/kspread/kexi/kspread_kexiimport.cpp b/filters/kspread/kexi/kspread_kexiimport.cpp new file mode 100644 index 00000000..6100dabe --- /dev/null +++ b/filters/kspread/kexi/kspread_kexiimport.cpp @@ -0,0 +1,249 @@ +/*************************************************************************** + * Copyright (C) 2006 by Adam Pigg * + * adam@piggz.co.uk * + * * + * Based on insert calendar code: * + * Copyright (C) 2005 by Raphael Langerhorst * + * raphael-langerhorst@gmx.at * + * * + * Permission is hereby granted, free of charge, to any person obtaining * + * a copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to * + * the following conditions: * + * * + * The above copyright notice and this permission notice shall be * + * included in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * + * OTHER DEALINGS IN THE SOFTWARE. * + ***************************************************************************/ + +#include "kspread_kexiimport.h" + +#include "kspread_kexiimportdialog.h" + +//KSpread Includes +#include +#include +//#include +#include +#include +#include + +//Koffice Includes +#include +#include +#include + +//Kexi Includes +#include +#include +#include + +//KDE Includes +#include +#include +#include +#include +#include + +typedef KGenericFactory KSpreadKexiImportFactory; +K_EXPORT_COMPONENT_FACTORY( libkspreadkexiimport, KSpreadKexiImportFactory( "kofficefilters" ) ) + + +//============================================================================= + +KSpreadKexiImport::KSpreadKexiImport(KoFilter *parent, const char *name, const TQStringList&) +{ +} + +//============================================================================= + +KSpreadKexiImport::~KSpreadKexiImport() +{ + delete m_dialog; +} + +//============================================================================= + +KoFilter::ConversionStatus KSpreadKexiImport::convert( const TQCString& from, const TQCString& to ) +{ + TQPtrList objects; + TQString file( m_chain->inputFile() ); + + //Create dialog + m_dialog = new KSpreadKexiImportDialog(); + + m_dialog->openDatabase( file, 0); + if (!m_dialog->exec()) + { + return KoFilter::UserCancelled; + } + + objects = m_dialog->selectedItems(); + + kdDebug() << "Getting Documents..." << endl; + + KoDocument* document = m_chain->outputDocument(); + + if ( !document ) + return KoFilter::StupidError; + + kdDebug() << "here we go... " << document->className() << endl; + + if ( !::tqqt_cast( document ) ) + { + kdWarning() << "document isn't a KSpread::Doc but a " << document->className() << endl; + return KoFilter::NotImplemented; + } + if(from!="application/x-kexiproject-sqlite3" || to!="application/x-kspread") + { + kdWarning() << "Invalid mimetypes " << from << " " << to << endl; + return KoFilter::NotImplemented; + } + + ksdoc = static_cast( document ); // type checked above + + if(ksdoc->mimeType()!="application/x-kspread") + { + kdWarning() << "Invalid document mimetype " << ksdoc->mimeType() << endl; + return KoFilter::NotImplemented; + } + + document->emitBeginOperation(); + + TQListViewItem *itm; + for(itm = objects.first(); itm ; itm = objects.next()) + { + if (!insertObject(itm->text(1), itm->text(0))) + { + return KoFilter::StupidError; + } + } + if (m_dialog->customQuery()) + { + if (!insertObject(m_dialog->customQueryString(), "Custom")) + { + return KoFilter::StupidError; + } + } + + document->emitEndOperation(); + kdDebug() << "inserting kexi data completed" << endl; + return KoFilter::OK; +} + +bool KSpreadKexiImport::insertObject(const TQString& object, const TQString& type) +{ + TQStringList fieldNames; + KSpread::Sheet *sheet; + KexiDB::Parser *parser; + KexiDB::QuerySchema *query; + + sheet = ksdoc->map()->addNewSheet(); + if (!sheet) + { + KMessageBox::error(NULL, i18n("Cant find sheet"), i18n("Error")); + return false; + } + + if (type == "Custom") + { + sheet->setSheetName("Custom"); + } + else + { + sheet->setSheetName(object); + } + + //Get the field names + if (type == "Table") + { + fieldNames = m_dialog->connection()->tableSchema(object)->names(); + } + else if (type == "Query") + { + //Note....for queries such as select * from....field names are not available + fieldNames = m_dialog->connection()->querySchema(object)->names(); + } + else if (type == "Custom") //Custom Query + { + parser = new KexiDB::Parser(m_dialog->connection()); + parser->parse( object ); + + if (parser->operation() != KexiDB::Parser::OP_Select) + { + KMessageBox::error(NULL, i18n("Your query was invalid or not a SELECT query"), i18n("Error")); + return false; + } + query = parser->query(); + fieldNames = query->names(); + } + + //Insert the field headings + TQStringList::iterator it; + int i = 1; + for (it = fieldNames.begin(); it != fieldNames.end(); ++it, ++i) + { + KSpread::Cell *c = sheet->nonDefaultCell(i ,1); + c->setCellText(*it, true); + c->format()->setBgColor(TQColor(200,200,200)); + c->format()->setTextFontBold(true); + } + + //Insert the data + KexiDB::Cursor *cur; + if (type == "Table") //Table + { + cur = m_dialog->connection()->executeQuery( *(m_dialog->connection()->tableSchema(object))); + } + else if (type == "Query") //Query + { + cur = m_dialog->connection()->executeQuery( *(m_dialog->connection()->querySchema(object))); + } + else if (type == "Custom") //Custom Query + { + cur = m_dialog->connection()->executeQuery( *query ); + } + else + { + cur = 0; + } + + if (!cur) + { + KMessageBox::error(NULL, i18n("Error executing query"), i18n("Error")); + return false; + } + + cur->moveFirst(); + int j = cur->fieldCount(); + + unsigned int k = 2; //start on row 2 + bool asText = false; + + if(m_dialog->conversion() == 2) + asText = true; + + while (!cur->eof()) + { + for (i = 0; i < j; ++i) + { + sheet->nonDefaultCell(i+1 ,k)->setCellText(cur->value(i).toString(), asText); + } + + kdDebug() << k << endl; + cur->moveNext(); + ++k; + } + return true; +} +#include "kspread_kexiimport.moc" diff --git a/filters/kspread/kexi/kspread_kexiimportdialog.cc b/filters/kspread/kexi/kspread_kexiimportdialog.cc deleted file mode 100644 index 0e15acbe..00000000 --- a/filters/kspread/kexi/kspread_kexiimportdialog.cc +++ /dev/null @@ -1,236 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Adam Pigg * - * adam@piggz.co.uk * - * * - * Based on insert calendar code: * - * Copyright (C) 2005 by Raphael Langerhorst * - * raphael-langerhorst@gmx.at * - * * - * Permission is hereby granted, free of charge, to any person obtaining * - * a copy of this software and associated documentation files (the * - * "Software"), to deal in the Software without restriction, including * - * without limitation the rights to use, copy, modify, merge, publish, * - * distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to * - * the following conditions: * - * * - * The above copyright notice and this permission notice shall be * - * included in all copies or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* - * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * - * OTHER DEALINGS IN THE SOFTWARE. * - ***************************************************************************/ - -#include "kspread_kexiimportdialog.h" - -//KDE Includes -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//Kexi Includes -#include -#include -#include -#include -#include -#include - -//KSpread includes -#include -#include -#include - -/** - * Constructor - * @param parent Pointer to kspread view - * @param name Name of the dialog - * @return None - */ - KSpreadKexiImportDialog::KSpreadKexiImportDialog(TQWidget* parent, const char* name) - : KSpreadKexiImportDialogBase(parent,name) -{ - connect(this->m_insertButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(accept())); - connect(this->m_cancelButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(reject())); -} - -/** - * Destructor - * @return None - */ -KSpreadKexiImportDialog::~KSpreadKexiImportDialog() -{} - -/** - * Accepts the dialog and start the import process - */ -void KSpreadKexiImportDialog::accept() -{ - kdDebug() << "insert kexi data dialog accepted (insert button clicked)" << endl; - done(TQDialog::Accepted); - emit insertKexi(); -} - -/** - * Cancels the dialog - */ -void KSpreadKexiImportDialog::reject() -{ - kdDebug() << "insert kexi data dialog rejected (cancel button clicked)" << endl; - done(TQDialog::Rejected); -} - -/** - * Opens a database given either a filename or connection data - * @param fileName name of file to open if cdata is null - * @param cdata connection data to server based database...not implemented though - */ -void KSpreadKexiImportDialog::openDatabase( TQString fileName , KexiDB::ConnectionData *cdata) -{ - kdDebug() << "openDatabase" << endl; - KexiDB::Driver *dr; - KexiDB::DriverManager *dm; - KexiDB::ConnectionData cd; - - //Open file db - dm = new KexiDB::DriverManager(); - dr = dm->driver("sqlite3"); - if (!dr) - { - kdDebug() << "Unable to create driver" << endl; - return; - } - - if (cdata) - { - //Open server db - cd = *cdata; - } - else - { - if (!fileName.isEmpty()) - { - cd.setFileName(fileName); - } - else - { - kdDebug() << "No file name" << endl; - KMessageBox::error(NULL, i18n("No file specified"), i18n("Error")); - return; - } - } - - conn = dr->createConnection(cd); - - if (!conn) - { - KMessageBox::error(NULL, i18n("Error creating connection"), i18n("Error")); - return; - } - - if(!conn->connect()) - { - KMessageBox::error(NULL, i18n("Error connecting to database"), i18n("Error")); - conn->debugError(); - return; - } - - if (!conn->useDatabase( fileName )) - { - KMessageBox::error(NULL, i18n("Error using database"), i18n("Error")); - conn->debugError(); - return; - } - - populateTables(); - -} - -/** - * Gets all the tables and queries from the database - * and adds them to m_sourceList - */ -void KSpreadKexiImportDialog::populateTables() -{ - TQValueList tids; - TQValueList qids; - - kdDebug() << "Getting Tables and Queries" << endl; - tids = conn->objectIds(KexiDB::TableObjectType); - qids = conn->objectIds(KexiDB::QueryObjectType); - - kdDebug() << qids.count() << " queries " << tids.count() << " tables" << endl; - - TQValueList::iterator it; - - for ( it = tids.begin(); it != tids.end(); ++it ) - { - (void) new TDEListViewItem(m_sourceList,"Table", conn->tableSchema(*it)->name()); - kdDebug() << "Table ID:" << (*it) << " " << conn->tableSchema(*it)->name()<< endl; - } - - for ( it = qids.begin(); it != qids.end(); ++it ) - { - (void) new TDEListViewItem(m_sourceList,"Query", conn->querySchema(*it)->name()); - kdDebug() << "Query ID:" << (*it) << " " << conn->querySchema(*it)->name() << endl; - } - - //Select the first item - if(m_sourceList->firstChild()) - { - m_sourceList->setSelected(m_sourceList->firstChild(), true); - } - -} - -/** - * - * @return the custom query that has been entered - */ -TQString KSpreadKexiImportDialog::customQueryString() -{ - return m_CustomQueryText->text(); -} - -TQPtrList KSpreadKexiImportDialog::selectedItems() -{ - TQPtrList lst; - TQListViewItemIterator it( m_sourceList ); - while ( it.current() ) - { - if ( it.current()->isSelected() ) - lst.append( it.current() ); - ++it; - } - return lst; -} - -bool KSpreadKexiImportDialog::customQuery() -{ - return m_customQueryCheck->isChecked(); -} -/** - * Returns the user specified option for data conversion - * @return integer stating the type of cenverion to make - */ -int KSpreadKexiImportDialog::conversion() -{ - if ( m_convKSRadio->isChecked()) - return 1; - else if ( m_convTextRadio->isChecked()) - return 2; - else - return -1; -} - diff --git a/filters/kspread/kexi/kspread_kexiimportdialog.cpp b/filters/kspread/kexi/kspread_kexiimportdialog.cpp new file mode 100644 index 00000000..0e15acbe --- /dev/null +++ b/filters/kspread/kexi/kspread_kexiimportdialog.cpp @@ -0,0 +1,236 @@ +/*************************************************************************** + * Copyright (C) 2006 by Adam Pigg * + * adam@piggz.co.uk * + * * + * Based on insert calendar code: * + * Copyright (C) 2005 by Raphael Langerhorst * + * raphael-langerhorst@gmx.at * + * * + * Permission is hereby granted, free of charge, to any person obtaining * + * a copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to * + * the following conditions: * + * * + * The above copyright notice and this permission notice shall be * + * included in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.* + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * + * OTHER DEALINGS IN THE SOFTWARE. * + ***************************************************************************/ + +#include "kspread_kexiimportdialog.h" + +//KDE Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//Kexi Includes +#include +#include +#include +#include +#include +#include + +//KSpread includes +#include +#include +#include + +/** + * Constructor + * @param parent Pointer to kspread view + * @param name Name of the dialog + * @return None + */ + KSpreadKexiImportDialog::KSpreadKexiImportDialog(TQWidget* parent, const char* name) + : KSpreadKexiImportDialogBase(parent,name) +{ + connect(this->m_insertButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(accept())); + connect(this->m_cancelButton,TQT_SIGNAL(clicked()),this,TQT_SLOT(reject())); +} + +/** + * Destructor + * @return None + */ +KSpreadKexiImportDialog::~KSpreadKexiImportDialog() +{} + +/** + * Accepts the dialog and start the import process + */ +void KSpreadKexiImportDialog::accept() +{ + kdDebug() << "insert kexi data dialog accepted (insert button clicked)" << endl; + done(TQDialog::Accepted); + emit insertKexi(); +} + +/** + * Cancels the dialog + */ +void KSpreadKexiImportDialog::reject() +{ + kdDebug() << "insert kexi data dialog rejected (cancel button clicked)" << endl; + done(TQDialog::Rejected); +} + +/** + * Opens a database given either a filename or connection data + * @param fileName name of file to open if cdata is null + * @param cdata connection data to server based database...not implemented though + */ +void KSpreadKexiImportDialog::openDatabase( TQString fileName , KexiDB::ConnectionData *cdata) +{ + kdDebug() << "openDatabase" << endl; + KexiDB::Driver *dr; + KexiDB::DriverManager *dm; + KexiDB::ConnectionData cd; + + //Open file db + dm = new KexiDB::DriverManager(); + dr = dm->driver("sqlite3"); + if (!dr) + { + kdDebug() << "Unable to create driver" << endl; + return; + } + + if (cdata) + { + //Open server db + cd = *cdata; + } + else + { + if (!fileName.isEmpty()) + { + cd.setFileName(fileName); + } + else + { + kdDebug() << "No file name" << endl; + KMessageBox::error(NULL, i18n("No file specified"), i18n("Error")); + return; + } + } + + conn = dr->createConnection(cd); + + if (!conn) + { + KMessageBox::error(NULL, i18n("Error creating connection"), i18n("Error")); + return; + } + + if(!conn->connect()) + { + KMessageBox::error(NULL, i18n("Error connecting to database"), i18n("Error")); + conn->debugError(); + return; + } + + if (!conn->useDatabase( fileName )) + { + KMessageBox::error(NULL, i18n("Error using database"), i18n("Error")); + conn->debugError(); + return; + } + + populateTables(); + +} + +/** + * Gets all the tables and queries from the database + * and adds them to m_sourceList + */ +void KSpreadKexiImportDialog::populateTables() +{ + TQValueList tids; + TQValueList qids; + + kdDebug() << "Getting Tables and Queries" << endl; + tids = conn->objectIds(KexiDB::TableObjectType); + qids = conn->objectIds(KexiDB::QueryObjectType); + + kdDebug() << qids.count() << " queries " << tids.count() << " tables" << endl; + + TQValueList::iterator it; + + for ( it = tids.begin(); it != tids.end(); ++it ) + { + (void) new TDEListViewItem(m_sourceList,"Table", conn->tableSchema(*it)->name()); + kdDebug() << "Table ID:" << (*it) << " " << conn->tableSchema(*it)->name()<< endl; + } + + for ( it = qids.begin(); it != qids.end(); ++it ) + { + (void) new TDEListViewItem(m_sourceList,"Query", conn->querySchema(*it)->name()); + kdDebug() << "Query ID:" << (*it) << " " << conn->querySchema(*it)->name() << endl; + } + + //Select the first item + if(m_sourceList->firstChild()) + { + m_sourceList->setSelected(m_sourceList->firstChild(), true); + } + +} + +/** + * + * @return the custom query that has been entered + */ +TQString KSpreadKexiImportDialog::customQueryString() +{ + return m_CustomQueryText->text(); +} + +TQPtrList KSpreadKexiImportDialog::selectedItems() +{ + TQPtrList lst; + TQListViewItemIterator it( m_sourceList ); + while ( it.current() ) + { + if ( it.current()->isSelected() ) + lst.append( it.current() ); + ++it; + } + return lst; +} + +bool KSpreadKexiImportDialog::customQuery() +{ + return m_customQueryCheck->isChecked(); +} +/** + * Returns the user specified option for data conversion + * @return integer stating the type of cenverion to make + */ +int KSpreadKexiImportDialog::conversion() +{ + if ( m_convKSRadio->isChecked()) + return 1; + else if ( m_convTextRadio->isChecked()) + return 2; + else + return -1; +} + -- cgit v1.2.1