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

kio/kio

  • kio
  • kio
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 <kparts/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, KInstance* 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 = KGlobal::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 = KGlobal::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, KInstance* 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 KTrader ? Test with HEAD-kdelibs!
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  KTrader::OfferList offers = KTrader::self()->query( "KDataTool", constr );
193 
194  KTrader::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  : KAction( 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<KAction> KDataToolAction::dataToolActionList( const TQValueList<KDataToolInfo> & tools, const TQObject *receiver, const char* slot )
232 {
233  TQPtrList<KAction> actionList;
234  if ( tools.isEmpty() )
235  return actionList;
236 
237  actionList.append( new KActionSeparator() );
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 KInstance* KDataTool::instance() const
275 {
276  return m_instance;
277 }
278 
279 void KDataToolAction::virtual_hook( int id, void* data )
280 { KAction::virtual_hook( id, data ); }
281 
282 void KDataTool::virtual_hook( int, void* )
283 { /*BASE::virtual_hook( id, data );*/ }
284 
285 #include "kdatatool.moc"

kio/kio

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

kio/kio

Skip menu "kio/kio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kio by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |