summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/KoQueryTrader.h
blob: 511bd9188acc3e28b6d05160a98c5214966323c6 (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
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>

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

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef __ko_query_trader_h__
#define __ko_query_trader_h__

#include <kservice.h>
#include <ksharedptr.h>
#include <tqvaluelist.h>
#include <koffice_export.h>

class TQObject;
class TQStringList;
class KoDocument;
class KoFilter;
class KoFilterChain;

/**
 *  Represents an available KOffice component
 *  that supports the document interface.
 */
class KOFFICECORE_EXPORT KoDocumentEntry
{

public:
  KoDocumentEntry() { m_service = 0L; } // for TQValueList
  KoDocumentEntry( KService::Ptr service );
  ~KoDocumentEntry() { }

  KService::Ptr service() const { return m_service; }

  /**
   * @return TRUE if the service pointer is null
   */
  bool isEmpty() const { return m_service == 0L; }

  /**
   * @return name of the associated service
   */
  TQString name() const { return m_service->name(); }

  /**
   *  Mimetypes (and other service types) which this document can handle.
   */
  TQStringList mimeTypes() const { return m_service->serviceTypes(); }

  /**
   *  @return TRUE if the document can handle the requested mimetype.
   */
  bool supportsMimeType( const TQString & _mimetype ) const
  { return mimeTypes().contains( _mimetype ); }

  /**
   *  Uses the factory of the component to create
   *  a document. If that is not possible, 0 is returned.
   */
  KoDocument* createDoc( KoDocument* parent = 0, const char* name = 0 ) const;

  /**
   *  This function will query tdesycoca to find all available components.
   *  The result will only contain parts, which are embeddable into a document
   *
   *  @param _constr is a constraint expression as used by TDETrader.
   *                 You can use it to set additional restrictions on the available
   *                 components.
   */
  static TQValueList<KoDocumentEntry> query( const TQString &  _constr = TQString() );

  /**
   *  This function will query the system to find all available filters.
   *
   *  @param _onlyDocEmb specifies if only KOffice Parts should be listed which are
   *                 embeddable into other koDocuments, or all (if false)
   *                 (eg.: it makes no sense to embed Kexi into KWord,
   *                 but it makes sense to embed it into KoShell)
   *  @param _constr is a constraint expression as used by KDEDs trader interface.
   *                 You can use it to set additional restrictions on the available
   *                 components.
   */
  // ### TODO: MERGE WITH ABOVE METHODE WHEN BIC+SIC CHANGES ARE ALLOWED
  static TQValueList<KoDocumentEntry> query( bool _onlyDocEmb,const TQString& _constr);
  /* this is how the signature should be looking after merging
  static TQValueList<KoDocumentEntry> query( bool _onlyDocEmb =true, const TQString& _constr = TQString() );
  or better: use an enum for the first arg.
  */


  /**
   *  This is a convenience function.
   *
   *  @return a document entry for the KOffice component that supports
   *          the requested mimetype and fits the user best.
   */
  static KoDocumentEntry queryByMimeType( const TQString & mimetype );

private:
  KService::Ptr m_service;
};

/**
 *  Represents an available filter.
 */
class KoFilterEntry : public TDEShared
{

public:
  typedef TDESharedPtr<KoFilterEntry> Ptr;

  KoFilterEntry() : weight( 0 ) { m_service = 0L; } // for TQValueList
  KoFilterEntry( KService::Ptr service );
  ~KoFilterEntry() { }

  KoFilter* createFilter( KoFilterChain* chain, TQObject* parent = 0, const char* name = 0 );

  /**
   *  The imported mimetype(s).
   */
  TQStringList import;

  /**
   *  The exported mimetype(s).
   */
  TQStringList export_;

  /**
   *  The "weight" of this filter path. Has to be > 0 to be valid.
   */
  unsigned int weight;

  /**
   *  Do we have to check during runtime?
   */
  TQString available;

  /**
   *  @return TRUE if the filter can import the requested mimetype.
   */
  bool imports( const TQString& _mimetype ) const
  { return ( import.contains( _mimetype ) ); }

  /**
   *  @return TRUE if the filter can export the requested mimetype.
   */
  bool exports( const TQString& _m ) const
  { return ( export_.contains( _m ) ); }

  /**
   *  This function will query KDED to find all available filters.
   *
   *  @param _constr is a constraint expression as used by KDEDs trader interface.
   *                 You can use it to set additional restrictions on the available
   *                 components.
   */
  static TQValueList<KoFilterEntry::Ptr> query( const TQString& _constr = TQString() );

  KService::Ptr service() const { return m_service; }

private:
  KService::Ptr m_service;
};

#endif