// **************************************************************************** // copyright (c) 2000-2005 Horst Knorr // This file is part of the hk_kdeclasses library. // This file may be distributed and/or modified under the terms of the // GNU Library Public License version 2 as published by the Free Software // Foundation and appearing in the file LGPL included in the // packaging of this file. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // **************************************************************************** #include "hk_kdexmlexportdialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include QProgressDialog* hk_kdexmlexportdialog::p_progressdialog=NULL; bool hk_kdexmlexportdialog::p_cancelimport=false; hk_kdexmlexportdialog::hk_kdexmlexportdialog(const QString& table, QWidget* parent, const char* name, bool modal, WFlags fl ) : hk_kdexmlexportdialogbase( parent, name, modal, fl ), hk_reportxml() { p_tablename=table; p_datasourcetype=dt_table; maindocumenttagfield->setText(QString::fromUtf8(l2u(maindocumenttag()).c_str())); rowelementfield->setText(QString::fromUtf8(l2u(rowtag()).c_str())); structurefield->setChecked(includetableschema()); structurefield->setText(i18n("include tableschema?")); KConfig* c=kapp->config(); QRect rect(0,0,500,300); c->setGroup("XMLExport"); QRect g; g=c->readRectEntry("Geometry",&rect); setGeometry(g); } hk_kdexmlexportdialog::~hk_kdexmlexportdialog() { // no need to delete child widgets, Qt does it all for us } void hk_kdexmlexportdialog::ok_clicked() { set_filename(u2l(filefield->text().utf8().data())); long ds=new_datasource(u2l(tablenamefield->currentText().utf8().data()),p_datasourcetype); set_presentationdatasource(ds); set_maindocumenttag(u2l(maindocumenttagfield->text().utf8().data())); set_rowtag(u2l(rowelementfield->text().utf8().data())); set_includetableschema(structurefield->isChecked()); set_fieldname_as_attribute(attributefield->isChecked()?fieldnameattribute:fieldname); p_cancelimport=false; p_progressdialog= new QProgressDialog(this,NULL,true); p_progressdialog->setCaption(i18n("Exporting data...")); p_progressdialog->setTotalSteps(100); connect(p_progressdialog,SIGNAL(cancelled()),this,SLOT(printing_cancelled())); p_progressdialog->show(); qApp->processEvents(); if ( execute()) accept(); delete p_progressdialog; p_progressdialog=NULL; KConfig* c=kapp->config(); c->setGroup("XMLExport"); c->writeEntry("Geometry",geometry()); } void hk_kdexmlexportdialog::printing_cancelled(void) { cout <<"cancelclicked"<text().isEmpty() &&!maindocumenttagfield->text().isEmpty() &&!rowelementfield->text().isEmpty() &&!tablenamefield->currentText().isEmpty() ) buttonOk->setEnabled(true); else buttonOk->setEnabled(false); } void hk_kdexmlexportdialog::filebutton_clicked() { p_file = KFileDialog::getOpenFileName( ":xml", QString::null, this,i18n("Select a XML file")); filefield->setText(p_file); } void hk_kdexmlexportdialog::set_usetablelist() { p_datasourcetype=dt_table; set_datasourcelist(); } void hk_kdexmlexportdialog::set_useviewlist() { p_datasourcetype=dt_view; set_datasourcelist(); } void hk_kdexmlexportdialog::set_usequerylist() { p_datasourcetype=dt_query; set_datasourcelist(); } void hk_kdexmlexportdialog::set_datasourcelist(void) { tablenamefield->clear(); hk_database* p_db=database(); if (p_db==NULL)return ; vector* tbl=p_db->tablelist(); switch (p_datasourcetype) { case dt_table: { //tbl already set as default; tablenamelabel->setText( i18n("Tablename:" ) ); break; } case dt_query: { tbl=p_db->querylist(); tablenamelabel->setText( i18n("Queryname:" ) ); break; } case dt_view: { tbl=p_db->viewlist(); tablenamelabel->setText( i18n("Viewname:" ) ); break; } } vector::iterator it; if (tbl!=NULL) { for(it=tbl->begin();it!=tbl->end();it++) { tablenamefield->insertItem(QString::fromUtf8(l2u((*it)).c_str())); if (!p_tablename.isEmpty()&& p_tablename==(*it).c_str()) tablenamefield->setCurrentItem(tablenamefield->count()-1); } } } void hk_kdexmlexportdialog::listtype_changed() { switch (typefield->currentItem()) { case 1: p_datasourcetype=dt_query;break; case 2: p_datasourcetype=dt_view;break; default: p_datasourcetype=dt_table; } set_datasourcelist(); } void hk_kdexmlexportdialog::set_database(hk_database* d) { typefield->clear(); typefield->insertItem(i18n("Table")); typefield->insertItem(i18n("Query")); hk_presentation::set_database(d); if (d && d->connection()->server_supports(hk_connection::SUPPORTS_VIEWS)) { typefield->insertItem(i18n("View")); } set_datasourcelist(); } void hk_kdexmlexportdialog::help_clicked() { kapp->invokeHelp("exportxml"); } bool hk_kdexmlexportdialog::set_progress(long int position,long int total,const hk_string&txt) { if (p_progressdialog) { p_progressdialog->setCaption(QString::fromUtf8(l2u(txt).c_str())); p_progressdialog->setTotalSteps(total); p_progressdialog->setProgress(position); p_progressdialog->raise(); qApp->processEvents(); } return p_cancelimport; } void hk_kdexmlexportdialog::keyPressEvent ( QKeyEvent * e ) { if (e->key()==Key_F1) help_clicked(); }