summaryrefslogtreecommitdiffstats
path: root/kbabel/common/catalogfileplugin.h
blob: 631a94b3ef1596e412a48589d3099aa23d3425bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* ****************************************************************************
  This file is part of KBabel

  Copyright (C) 2002-2003	 by Stanislav Visnovsky
                        	    <visnovsky@kde.org>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

  In addition, as a special exception, the copyright holders give
  permission to link the code of this program with any edition of
  the TQt library by Trolltech AS, Norway (or with modified versions
  of TQt that use the same license as TQt), and distribute linked
  combinations including the two.  You must obey the GNU General
  Public License in all respects for all of the code used other than
  TQt. If you modify this file, you may extend this exception to
  your version of the file, but you are not obligated to do so.  If
  you do not wish to do so, delete this exception statement from
  your version.
**************************************************************************** */
#ifndef IMPORTPLUGIN_H
#define IMPORTPLUGIN_H

#include <tqobject.h>

#include <kdemacros.h>

class TQString;

namespace KBabel 
{

class Catalog;
class CatalogItem;
class CatalogImportPluginPrivate;
class CatalogExportPluginPrivate;

// ### KDE4: force OK=0
/**
 * Result of the conversion
 */
enum ConversionStatus { 
    OK,
    NOT_IMPLEMENTED,
    NO_FILE,
    NO_PERMISSIONS,
    PARSE_ERROR,
    RECOVERED_PARSE_ERROR,
    OS_ERROR,
    NO_PLUGIN,
    UNSUPPORTED_TYPE,
    HEADER_ERROR, ///< Old name for a recovered error in header @deprecated
    RECOVERED_HEADER_ERROR = HEADER_ERROR, ///< Header error that could be recovered @since 1.11.2 (KDE 3.5.2)
    STOPPED,
    BUSY,
    NO_ENTRY_ERROR ///< The loaded catalog has not any entry! @since 1.11.2 (KDE 3.5.2)
};

/**
* This class is the base for import plugins for catalogs.
* It provides "transactional behavior", so the changes are stored in 
* catalog only if the import process finishes successfully. 
*
* To use it, just subclass and redefine load() and id() methods.
* When importing, you can use the protected methods for setting
* the catalog. New catalog items can be added using appendCatalogItem.
*
* @short Base class for Catalog import plugins
* @author Stanislav Visnovsky <visnovsky@kde.org>
*/    
class KDE_EXPORT CatalogImportPlugin: public TQObject
{
    Q_OBJECT
  TQ_OBJECT
    
public:
    CatalogImportPlugin(TQObject* parent, const char* name);
    virtual ~CatalogImportPlugin();
    
    /**
     * Load the file and fill the corresponding catalog. The file
     * is considered to be of @ref mimetype MIME type.
     * 
     * @param file     local file name to be opened
     * @param mimetype the MIME type is should be handled as
     * @param catalog  the catalog to be filled
     * @return result of the operation
     */
    ConversionStatus open(const TQString& file, const TQString& mimetype, Catalog* catalog);
    
    /**
    * Reimplement this method to load the local file passed as an argument.
    * Throughout the run, you can use the protected methods for setting
    * the contents of the resulting catalog.
    * This method must call \see setMimeTypes to setup correct MIME types
    * for the loaded file. Also, it should use \see isStopped to 
    * abort loading and the signals for providing user feedback.
    * @param file file to be loaded
    * @param mimetype the expected MIME type (the type used for plugin selection
    */
    virtual ConversionStatus load(const TQString& file, const TQString& mimetype) = 0;
    /**
    * Reimplement this method to return unique identification of your plugin
    */
    virtual const TQString id() = 0;
    
    /** @return the list of all available MIME types for which there
     *  is a import plugin.
     */
    static TQStringList availableImportMimeTypes();

public slots:
    /** stop the current operation */
    void stop();

protected:
    /** Append a new catalog item, either as normal or as an obsolete one
     *  @param item the new item
     *  @param obsolete flag that the item is obsolete
     */
    void appendCatalogItem( const CatalogItem& item, const bool obsolete = false );
    
    /** set flag that the file is generated from DocBook */
    void setGeneratedFromDocbook(const bool fromDocbook);
    /** set the list of parse error indexes */
    void setErrorIndex(const TQValueList<uint>& errors);
    /** set the file codec */
    void setFileCodec(TQTextCodec* codec);
    
    /** set extra data for the catalog, which can't be stored in
     *  @ref CatalogItem. The format can be arbitrary */
    void setCatalogExtraData( const TQStringList& data );
    /** set the header catalog item */
    void setHeader( const CatalogItem& header );
    /** set the MIME types which can be used for this catalog */
    void setMimeTypes( const TQString& catalog );
    
    /** start a new transaction. You should never call this method. */
    void startTransaction();
    /** commit the data in the current transaction. You should never call this method. */
    void commitTransaction();
    
    /** Flag, whether the operation should be stopped immediately.*/
    bool isStopped() const;
    
signals:
    /** Signal start of the operation */
    void signalResetProgressBar(TQString,int);
    /** Signal progress of the operation */
    void signalProgress(int);
    /** Signal end of the operation */
    void signalClearProgressBar();

private:
    CatalogImportPluginPrivate* d;
};


/**
* This class is the base for export plugins for catalogs.
*
* To use it, just subclass and redefine the save() method.
*
* @short Base class for Catalog export plugins
* @author Stanislav Visnovsky <visnovsky@kde.org>
*/    
class KDE_EXPORT CatalogExportPlugin: public TQObject
{
    Q_OBJECT
  TQ_OBJECT

public:
    CatalogExportPlugin(TQObject* parent, const char* name);
    virtual ~CatalogExportPlugin();
    virtual ConversionStatus save(const TQString& file, const TQString& mimetype, const Catalog* catalog) = 0;

    static TQStringList availableExportMimeTypes();

public slots:
    void stop();

protected:
    bool isStopped() const;
    
signals:
    void signalResetProgressBar(TQString,int);
    void signalProgress(int);
    void signalClearProgressBar();

private:
    CatalogExportPluginPrivate* d;
};

}

#endif