• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
kdatatool.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
3  Copyright (C) 2001 David Faure <faure@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kdatatool.h"
22 
23 #include <kstandarddirs.h>
24 #include <klibloader.h>
25 #include <kdebug.h>
26 #include <kinstance.h>
27 
28 #include <ktrader.h>
29 #include <tdeparts/componentfactory.h>
30 
31 #include <tqpixmap.h>
32 #include <tqfile.h>
33 
34 /*************************************************
35  *
36  * KDataToolInfo
37  *
38  *************************************************/
39 
40 KDataToolInfo::KDataToolInfo()
41 {
42  m_service = 0;
43 }
44 
45 KDataToolInfo::KDataToolInfo( const KService::Ptr& service, TDEInstance* instance )
46 {
47  m_service = service;
48  m_instance = instance;
49 
50  if ( !!m_service && !m_service->serviceTypes().contains( "KDataTool" ) )
51  {
52  kdDebug(30003) << "The service " << m_service->name().latin1()
53  << " does not feature the service type KDataTool" << endl;
54  m_service = 0;
55  }
56 }
57 
58 KDataToolInfo::KDataToolInfo( const KDataToolInfo& info )
59 {
60  m_service = info.service();
61  m_instance = info.instance();
62 }
63 
64 KDataToolInfo& KDataToolInfo::operator= ( const KDataToolInfo& info )
65 {
66  m_service = info.service();
67  m_instance = info.instance();
68  return *this;
69 }
70 
71 TQString KDataToolInfo::dataType() const
72 {
73  if ( !m_service )
74  return TQString::null;
75 
76  return m_service->property( "DataType" ).toString();
77 }
78 
79 TQStringList KDataToolInfo::mimeTypes() const
80 {
81  if ( !m_service )
82  return TQStringList();
83 
84  return m_service->property( "DataMimeTypes" ).toStringList();
85 }
86 
87 bool KDataToolInfo::isReadOnly() const
88 {
89  if ( !m_service )
90  return true;
91 
92  return m_service->property( "ReadOnly" ).toBool();
93 }
94 
95 TQPixmap KDataToolInfo::icon() const
96 {
97  if ( !m_service )
98  return TQPixmap();
99 
100  TQPixmap pix;
101  TQStringList lst = TDEGlobal::dirs()->resourceDirs("icon");
102  TQStringList::ConstIterator it = lst.begin();
103  while (!pix.load( *it + "/" + m_service->icon() ) && it != lst.end() )
104  it++;
105 
106  return pix;
107 }
108 
109 TQPixmap KDataToolInfo::miniIcon() const
110 {
111  if ( !m_service )
112  return TQPixmap();
113 
114  TQPixmap pix;
115  TQStringList lst = TDEGlobal::dirs()->resourceDirs("mini");
116  TQStringList::ConstIterator it = lst.begin();
117  while (!pix.load( *it + "/" + m_service->icon() ) && it != lst.end() )
118  it++;
119 
120  return pix;
121 }
122 
123 TQString KDataToolInfo::iconName() const
124 {
125  if ( !m_service )
126  return TQString::null;
127  return m_service->icon();
128 }
129 
130 TQStringList KDataToolInfo::commands() const
131 {
132  if ( !m_service )
133  return TQString();
134 
135  return m_service->property( "Commands" ).toStringList();
136 }
137 
138 TQStringList KDataToolInfo::userCommands() const
139 {
140  if ( !m_service )
141  return TQString();
142 
143  return TQStringList::split( ',', m_service->comment() );
144 }
145 
146 KDataTool* KDataToolInfo::createTool( TQObject* parent, const char* name ) const
147 {
148  if ( !m_service )
149  return 0;
150 
151  KDataTool* tool = KParts::ComponentFactory::createInstanceFromService<KDataTool>( m_service, parent, name );
152  if ( tool )
153  tool->setInstance( m_instance );
154  return tool;
155 }
156 
157 KService::Ptr KDataToolInfo::service() const
158 {
159  return m_service;
160 }
161 
162 TQValueList<KDataToolInfo> KDataToolInfo::query( const TQString& datatype, const TQString& mimetype, TDEInstance* instance )
163 {
164  TQValueList<KDataToolInfo> lst;
165 
166  TQString constr;
167 
168  if ( !datatype.isEmpty() )
169  {
170  constr = TQString::fromLatin1( "DataType == '%1'" ).arg( datatype );
171  }
172  if ( !mimetype.isEmpty() )
173  {
174  TQString tmp = TQString::fromLatin1( "'%1' in DataMimeTypes" ).arg( mimetype );
175  if ( constr.isEmpty() )
176  constr = tmp;
177  else
178  constr = constr + " and " + tmp;
179  }
180 /* Bug in TDETrader ? Test with HEAD-tdelibs!
181  if ( instance )
182  {
183  TQString tmp = TQString::fromLatin1( "not ('%1' in ExcludeFrom)" ).arg( instance->instanceName() );
184  if ( constr.isEmpty() )
185  constr = tmp;
186  else
187  constr = constr + " and " + tmp;
188  } */
189 
190  // Query the trader
191  //kdDebug() << "KDataToolInfo::query " << constr << endl;
192  TDETrader::OfferList offers = TDETrader::self()->query( "KDataTool", constr );
193 
194  TDETrader::OfferList::ConstIterator it = offers.begin();
195  for( ; it != offers.end(); ++it )
196  {
197  // Temporary replacement for the non-working trader query above
198  if ( !instance || !(*it)->property("ExcludeFrom").toStringList()
199  .contains( instance->instanceName() ) )
200  lst.append( KDataToolInfo( *it, instance ) );
201  else
202  kdDebug() << (*it)->entryPath() << " excluded." << endl;
203  }
204 
205  return lst;
206 }
207 
208 bool KDataToolInfo::isValid() const
209 {
210  return( m_service );
211 }
212 
213 /*************************************************
214  *
215  * KDataToolAction
216  *
217  *************************************************/
218 KDataToolAction::KDataToolAction( const TQString & text, const KDataToolInfo & info, const TQString & command,
219  TQObject * parent, const char * name )
220  : TDEAction( text, info.iconName(), 0, parent, name ),
221  m_command( command ),
222  m_info( info )
223 {
224 }
225 
226 void KDataToolAction::slotActivated()
227 {
228  emit toolActivated( m_info, m_command );
229 }
230 
231 TQPtrList<TDEAction> KDataToolAction::dataToolActionList( const TQValueList<KDataToolInfo> & tools, const TQObject *receiver, const char* slot )
232 {
233  TQPtrList<TDEAction> actionList;
234  if ( tools.isEmpty() )
235  return actionList;
236 
237  actionList.append( new TDEActionSeparator() );
238  TQValueList<KDataToolInfo>::ConstIterator entry = tools.begin();
239  for( ; entry != tools.end(); ++entry )
240  {
241  TQStringList userCommands = (*entry).userCommands();
242  TQStringList commands = (*entry).commands();
243  Q_ASSERT(!commands.isEmpty());
244  if ( commands.count() != userCommands.count() )
245  kdWarning() << "KDataTool desktop file error (" << (*entry).service()->entryPath()
246  << "). " << commands.count() << " commands and "
247  << userCommands.count() << " descriptions." << endl;
248  TQStringList::ConstIterator uit = userCommands.begin();
249  TQStringList::ConstIterator cit = commands.begin();
250  for (; uit != userCommands.end() && cit != commands.end(); ++uit, ++cit )
251  {
252  //kdDebug() << "creating action " << *uit << " " << *cit << endl;
253  KDataToolAction * action = new KDataToolAction( *uit, *entry, *cit );
254  connect( action, TQT_SIGNAL( toolActivated( const KDataToolInfo &, const TQString & ) ),
255  receiver, slot );
256  actionList.append( action );
257  }
258  }
259 
260  return actionList;
261 }
262 
263 /*************************************************
264  *
265  * KDataTool
266  *
267  *************************************************/
268 
269 KDataTool::KDataTool( TQObject* parent, const char* name )
270  : TQObject( parent, name ), m_instance( 0L )
271 {
272 }
273 
274 TDEInstance* KDataTool::instance() const
275 {
276  return m_instance;
277 }
278 
279 void KDataToolAction::virtual_hook( int id, void* data )
280 { TDEAction::virtual_hook( id, data ); }
281 
282 void KDataTool::virtual_hook( int, void* )
283 { /*BASE::virtual_hook( id, data );*/ }
284 
285 #include "kdatatool.moc"
TDETrader::self
static TDETrader * self()
This is a static pointer to a TDETrader instance.
Definition: ktrader.cpp:90
KDataToolAction
This class helps applications implement support for KDataTool.
Definition: kdatatool.h:194
KDataToolInfo::miniIcon
TQPixmap miniIcon() const KDE_DEPRECATED
Returns the mini icon of this data tool.
Definition: kdatatool.cpp:109
KDataToolInfo::commands
TQStringList commands() const
Returns the list of commands the DataTool can execute.
Definition: kdatatool.cpp:130
KDataToolInfo::dataType
TQString dataType() const
Returns the data type that the DataTool can accept.
Definition: kdatatool.cpp:71
KDataToolInfo::operator=
KDataToolInfo & operator=(const KDataToolInfo &info)
Assignment operator.
Definition: kdatatool.cpp:64
KDataToolInfo::createTool
KDataTool * createTool(TQObject *parent=0, const char *name=0) const
Creates the data tool described by this KDataToolInfo.
Definition: kdatatool.cpp:146
KDataToolInfo
This is a convenience class for KService.
Definition: kdatatool.h:47
KDataToolInfo::query
static TQValueList< KDataToolInfo > query(const TQString &datatype, const TQString &mimetype, TDEInstance *instance)
Queries the TDETrader about installed KDataTool implementations.
Definition: kdatatool.cpp:162
TDETrader::query
virtual OfferList query(const TQString &servicetype, const TQString &constraint=TQString::null, const TQString &preferences=TQString::null) const
The main function in the TDETrader class.
Definition: ktrader.cpp:106
KDataToolInfo::iconName
TQString iconName() const
Returns the icon name for this DataTool.
Definition: kdatatool.cpp:123
KDataToolInfo::userCommands
TQStringList userCommands() const
Returns a list of strings that you can put in a TQPopupMenu item, for example to offer the DataTools ...
Definition: kdatatool.cpp:138
KDataToolAction::dataToolActionList
static TQPtrList< TDEAction > dataToolActionList(const TQValueList< KDataToolInfo > &tools, const TQObject *receiver, const char *slot)
Creates a list of actions from a list of information about data-tools.
Definition: kdatatool.cpp:231
KDataTool::instance
TDEInstance * instance() const
Returns the instance of the part that created this tool.
Definition: kdatatool.cpp:274
KDataToolInfo::instance
TDEInstance * instance() const
The instance of the service.
Definition: kdatatool.h:157
KDataToolInfo::service
KService::Ptr service() const
The KDataToolInfo's service that is represented by this class.
Definition: kdatatool.cpp:157
KDataToolInfo::KDataToolInfo
KDataToolInfo()
Create an invalid KDataToolInfo.
Definition: kdatatool.cpp:40
KDataToolInfo::isReadOnly
bool isReadOnly() const
Checks whether the DataTool is read-only.
Definition: kdatatool.cpp:87
KDataToolAction::toolActivated
void toolActivated(const KDataToolInfo &info, const TQString &command)
Emitted when a tool has been activated.
TDETrader::OfferList
TQValueList< KService::Ptr > OfferList
A list of services.
Definition: ktrader.h:92
KDataToolInfo::icon
TQPixmap icon() const KDE_DEPRECATED
Returns the icon of this data tool.
Definition: kdatatool.cpp:95
KDataToolInfo::isValid
bool isValid() const
A DataToolInfo may be invalid if the KService passed to its constructor does not feature the service ...
Definition: kdatatool.cpp:208
KDataToolAction::KDataToolAction
KDataToolAction(const TQString &text, const KDataToolInfo &info, const TQString &command, TQObject *parent=0, const char *name=0)
Constructs a new KDataToolAction.
Definition: kdatatool.cpp:218
KDataToolInfo::mimeTypes
TQStringList mimeTypes() const
Returns a list of mime type that will be accepted by the DataTool.
Definition: kdatatool.cpp:79
KDataTool
A generic tool that processes data.
Definition: kdatatool.h:254
KDataTool::KDataTool
KDataTool(TQObject *parent=0, const char *name=0)
Constructor The data-tool is only created when a menu-item, that relates to it, is activated...
Definition: kdatatool.cpp:269

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.