kexi

kexicsv_importexportpart.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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") )
KDE Home | KDE Accessibility Home | Description of Access Keys