kexicsv_importexportpart.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexicsv_importexportpart.h"
21#include "kexicsvimportdialog.h"
22#include "kexicsvexportwizard.h"
23#include <core/keximainwindow.h>
24#include <core/kexiproject.h>
25#include <kexiutils/utils.h>
26
27#include <kgenericfactory.h>
28
29KexiCSVImportExportPart::KexiCSVImportExportPart(TQObject *parent, const char *name, const TQStringList &args)
30 : KexiInternalPart(parent, name, args)
31{
32}
33
34KexiCSVImportExportPart::~KexiCSVImportExportPart()
35{
36}
37
38TQWidget *KexiCSVImportExportPart::createWidget(const char* widgetClass, KexiMainWindow* mainWin,
39 TQWidget *parent, const char *objName, TQMap<TQString,TQString>* args )
40{
41 if (0==qstrcmp(widgetClass, "KexiCSVImportDialog")) {
42 KexiCSVImportDialog::Mode mode = (args && (*args)["sourceType"]=="file")
43 ? KexiCSVImportDialog::File : KexiCSVImportDialog::Clipboard;
44 KexiCSVImportDialog *dlg = new KexiCSVImportDialog( mode, mainWin, parent, objName );
45 m_cancelled = dlg->cancelled();
46 if (m_cancelled) {
47 delete dlg;
48 return 0;
49 }
50 return dlg;
51 }
52 else if (0==qstrcmp(widgetClass, "KexiCSVExportWizard")) {
53 if (!args)
54 return 0;
56 if (!options.assign( *args ))
57 return 0;
58 KexiCSVExportWizard *dlg = new KexiCSVExportWizard( options, mainWin, parent, objName);
59 m_cancelled = dlg->cancelled();
60 if (m_cancelled) {
61 delete dlg;
62 return 0;
63 }
64 return dlg;
65 }
66 return 0;
67}
68
69bool KexiCSVImportExportPart::executeCommand(KexiMainWindow* mainWin, const char* commandName,
70 TQMap<TQString,TQString>* args)
71{
72 if (0==qstrcmp(commandName, "KexiCSVExport")) {
74 if (!options.assign( *args ))
75 return false;
76 KexiDB::TableOrQuerySchema tableOrQuery(
77 mainWin->project()->dbConnection(), options.itemId);
78 TQTextStream *stream = 0;
79 if (args->contains("textStream"))
80 stream = KexiUtils::stringToPtr<TQTextStream>( (*args)["textStream"] );
81 return KexiCSVExport::exportData(tableOrQuery, options, -1, stream);
82 }
83 return false;
84}
85
86K_EXPORT_COMPONENT_FACTORY( kexihandler_csv_importexport,
87 KGenericFactory<KexiCSVImportExportPart>("kexihandler_csv_importexport") )
Kexi CSV export wizard Supports exporting to a file and to a clipboard.
Options used in KexiCSVExportWizard contructor.
bool assign(TQMap< TQString, TQString > &args)
Assigns args.
int itemId
Table or query ID.
Kexi CSV import dialog.
virtual TQWidget * createWidget(const char *widgetClass, KexiMainWindow *mainWin, TQWidget *parent, const char *objName=0, TQMap< TQString, TQString > *args=0)
virtual bool executeCommand(KexiMainWindow *mainWin, const char *commandName, TQMap< TQString, TQString > *args=0)
A prototype for Kexi Internal Parts (plugins) implementation.
bool m_cancelled
Used in cancelled()
Kexi's main window interface This interface is implemented by KexiMainWindowImpl class.
virtual KexiProject * project()=0
Project data of currently opened project or NULL if no project here yet.
KexiDB::Connection * dbConnection() const
type * findParent(TQObject *o, const char *className)