kexi
kexicsv_importexportpart.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kexicsv_importexportpart.h"
00021 #include "kexicsvimportdialog.h"
00022 #include "kexicsvexportwizard.h"
00023 #include <core/keximainwindow.h>
00024 #include <core/kexiproject.h>
00025 #include <kexiutils/utils.h>
00026
00027 #include <kgenericfactory.h>
00028
00029 KexiCSVImportExportPart::KexiCSVImportExportPart(QObject *parent, const char *name, const QStringList &args)
00030 : KexiInternalPart(parent, name, args)
00031 {
00032 }
00033
00034 KexiCSVImportExportPart::~KexiCSVImportExportPart()
00035 {
00036 }
00037
00038 QWidget *KexiCSVImportExportPart::createWidget(const char* widgetClass, KexiMainWindow* mainWin,
00039 QWidget *parent, const char *objName, QMap<QString,QString>* args )
00040 {
00041 if (0==qstrcmp(widgetClass, "KexiCSVImportDialog")) {
00042 KexiCSVImportDialog::Mode mode = (args && (*args)["sourceType"]=="file")
00043 ? KexiCSVImportDialog::File : KexiCSVImportDialog::Clipboard;
00044 KexiCSVImportDialog *dlg = new KexiCSVImportDialog( mode, mainWin, parent, objName );
00045 m_cancelled = dlg->cancelled();
00046 if (m_cancelled) {
00047 delete dlg;
00048 return 0;
00049 }
00050 return dlg;
00051 }
00052 else if (0==qstrcmp(widgetClass, "KexiCSVExportWizard")) {
00053 if (!args)
00054 return 0;
00055 KexiCSVExport::Options options;
00056 if (!options.assign( *args ))
00057 return 0;
00058 KexiCSVExportWizard *dlg = new KexiCSVExportWizard( options, mainWin, parent, objName);
00059 m_cancelled = dlg->cancelled();
00060 if (m_cancelled) {
00061 delete dlg;
00062 return 0;
00063 }
00064 return dlg;
00065 }
00066 return 0;
00067 }
00068
00069 bool KexiCSVImportExportPart::executeCommand(KexiMainWindow* mainWin, const char* commandName,
00070 QMap<QString,QString>* args)
00071 {
00072 if (0==qstrcmp(commandName, "KexiCSVExport")) {
00073 KexiCSVExport::Options options;
00074 if (!options.assign( *args ))
00075 return false;
00076 KexiDB::TableOrQuerySchema tableOrQuery(
00077 mainWin->project()->dbConnection(), options.itemId);
00078 QTextStream *stream = 0;
00079 if (args->contains("textStream"))
00080 stream = KexiUtils::stringToPtr<QTextStream>( (*args)["textStream"] );
00081 return KexiCSVExport::exportData(tableOrQuery, options, -1, stream);
00082 }
00083 return false;
00084 }
00085
00086 K_EXPORT_COMPONENT_FACTORY( kexihandler_csv_importexport,
00087 KGenericFactory<KexiCSVImportExportPart>("kexihandler_csv_importexport") )
|