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

tdeio/tdeio

kdatatool.cpp
00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
00003    Copyright (C) 2001 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kdatatool.h"
00022 
00023 #include <kstandarddirs.h>
00024 #include <klibloader.h>
00025 #include <kdebug.h>
00026 #include <kinstance.h>
00027 
00028 #include <ktrader.h>
00029 #include <tdeparts/componentfactory.h>
00030 
00031 #include <tqpixmap.h>
00032 #include <tqfile.h>
00033 
00034 /*************************************************
00035  *
00036  * KDataToolInfo
00037  *
00038  *************************************************/
00039 
00040 KDataToolInfo::KDataToolInfo()
00041 {
00042     m_service = 0;
00043 }
00044 
00045 KDataToolInfo::KDataToolInfo( const KService::Ptr& service, TDEInstance* instance )
00046 {
00047     m_service = service;
00048     m_instance = instance;
00049 
00050     if ( !!m_service && !m_service->serviceTypes().contains( "KDataTool" ) )
00051     {
00052         kdDebug(30003) << "The service " << m_service->name().latin1()
00053                        << " does not feature the service type KDataTool" << endl;
00054         m_service = 0;
00055     }
00056 }
00057 
00058 KDataToolInfo::KDataToolInfo( const KDataToolInfo& info )
00059 {
00060     m_service = info.service();
00061     m_instance = info.instance();
00062 }
00063 
00064 KDataToolInfo& KDataToolInfo::operator= ( const KDataToolInfo& info )
00065 {
00066     m_service = info.service();
00067     m_instance = info.instance();
00068     return *this;
00069 }
00070 
00071 TQString KDataToolInfo::dataType() const
00072 {
00073     if ( !m_service )
00074         return TQString::null;
00075 
00076     return m_service->property( "DataType" ).toString();
00077 }
00078 
00079 TQStringList KDataToolInfo::mimeTypes() const
00080 {
00081     if ( !m_service )
00082         return TQStringList();
00083 
00084     return m_service->property( "DataMimeTypes" ).toStringList();
00085 }
00086 
00087 bool KDataToolInfo::isReadOnly() const
00088 {
00089     if ( !m_service )
00090         return true;
00091 
00092     return m_service->property( "ReadOnly" ).toBool();
00093 }
00094 
00095 TQPixmap KDataToolInfo::icon() const
00096 {
00097     if ( !m_service )
00098         return TQPixmap();
00099 
00100     TQPixmap pix;
00101     TQStringList lst = TDEGlobal::dirs()->resourceDirs("icon");
00102     TQStringList::ConstIterator it = lst.begin();
00103     while (!pix.load( *it + "/" + m_service->icon() ) && it != lst.end() )
00104         it++;
00105 
00106     return pix;
00107 }
00108 
00109 TQPixmap KDataToolInfo::miniIcon() const
00110 {
00111     if ( !m_service )
00112         return TQPixmap();
00113 
00114     TQPixmap pix;
00115     TQStringList lst = TDEGlobal::dirs()->resourceDirs("mini");
00116     TQStringList::ConstIterator it = lst.begin();
00117     while (!pix.load( *it + "/" + m_service->icon() ) && it != lst.end() )
00118         it++;
00119 
00120     return pix;
00121 }
00122 
00123 TQString KDataToolInfo::iconName() const
00124 {
00125     if ( !m_service )
00126         return TQString::null;
00127     return m_service->icon();
00128 }
00129 
00130 TQStringList KDataToolInfo::commands() const
00131 {
00132     if ( !m_service )
00133         return TQString();
00134 
00135     return m_service->property( "Commands" ).toStringList();
00136 }
00137 
00138 TQStringList KDataToolInfo::userCommands() const
00139 {
00140     if ( !m_service )
00141         return TQString();
00142 
00143     return TQStringList::split( ',', m_service->comment() );
00144 }
00145 
00146 KDataTool* KDataToolInfo::createTool( TQObject* parent, const char* name ) const
00147 {
00148     if ( !m_service )
00149         return 0;
00150 
00151     KDataTool* tool = KParts::ComponentFactory::createInstanceFromService<KDataTool>( m_service, parent, name );
00152     if ( tool )
00153         tool->setInstance( m_instance );
00154     return tool;
00155 }
00156 
00157 KService::Ptr KDataToolInfo::service() const
00158 {
00159     return m_service;
00160 }
00161 
00162 TQValueList<KDataToolInfo> KDataToolInfo::query( const TQString& datatype, const TQString& mimetype, TDEInstance* instance )
00163 {
00164     TQValueList<KDataToolInfo> lst;
00165 
00166     TQString constr;
00167 
00168     if ( !datatype.isEmpty() )
00169     {
00170         constr = TQString::fromLatin1( "DataType == '%1'" ).arg( datatype );
00171     }
00172     if ( !mimetype.isEmpty() )
00173     {
00174         TQString tmp = TQString::fromLatin1( "'%1' in DataMimeTypes" ).arg( mimetype );
00175         if ( constr.isEmpty() )
00176             constr = tmp;
00177         else
00178             constr = constr + " and " + tmp;
00179     }
00180 /* Bug in TDETrader ? Test with HEAD-tdelibs!
00181     if ( instance )
00182     {
00183         TQString tmp = TQString::fromLatin1( "not ('%1' in ExcludeFrom)" ).arg( instance->instanceName() );
00184         if ( constr.isEmpty() )
00185             constr = tmp;
00186         else
00187             constr = constr + " and " + tmp;
00188     } */
00189 
00190     // Query the trader
00191     //kdDebug() << "KDataToolInfo::query " << constr << endl;
00192     TDETrader::OfferList offers = TDETrader::self()->query( "KDataTool", constr );
00193 
00194     TDETrader::OfferList::ConstIterator it = offers.begin();
00195     for( ; it != offers.end(); ++it )
00196     {
00197         // Temporary replacement for the non-working trader query above
00198         if ( !instance || !(*it)->property("ExcludeFrom").toStringList()
00199              .contains( instance->instanceName() ) )
00200             lst.append( KDataToolInfo( *it, instance ) );
00201         else
00202             kdDebug() << (*it)->entryPath() << " excluded." << endl;
00203     }
00204 
00205     return lst;
00206 }
00207 
00208 bool KDataToolInfo::isValid() const
00209 {
00210     return( m_service );
00211 }
00212 
00213 /*************************************************
00214  *
00215  * KDataToolAction
00216  *
00217  *************************************************/
00218 KDataToolAction::KDataToolAction( const TQString & text, const KDataToolInfo & info, const TQString & command,
00219                                     TQObject * parent, const char * name )
00220     : TDEAction( text, info.iconName(), 0, parent, name ),
00221       m_command( command ),
00222       m_info( info )
00223 {
00224 }
00225 
00226 void KDataToolAction::slotActivated()
00227 {
00228     emit toolActivated( m_info, m_command );
00229 }
00230 
00231 TQPtrList<TDEAction> KDataToolAction::dataToolActionList( const TQValueList<KDataToolInfo> & tools, const TQObject *receiver, const char* slot )
00232 {
00233     TQPtrList<TDEAction> actionList;
00234     if ( tools.isEmpty() )
00235         return actionList;
00236 
00237     actionList.append( new TDEActionSeparator() );
00238     TQValueList<KDataToolInfo>::ConstIterator entry = tools.begin();
00239     for( ; entry != tools.end(); ++entry )
00240     {
00241         TQStringList userCommands = (*entry).userCommands();
00242         TQStringList commands = (*entry).commands();
00243         Q_ASSERT(!commands.isEmpty());
00244         if ( commands.count() != userCommands.count() )
00245             kdWarning() << "KDataTool desktop file error (" << (*entry).service()->entryPath()
00246                         << "). " << commands.count() << " commands and "
00247                         << userCommands.count() << " descriptions." << endl;
00248         TQStringList::ConstIterator uit = userCommands.begin();
00249         TQStringList::ConstIterator cit = commands.begin();
00250         for (; uit != userCommands.end() && cit != commands.end(); ++uit, ++cit )
00251         {
00252             //kdDebug() << "creating action " << *uit << " " << *cit << endl;
00253             KDataToolAction * action = new KDataToolAction( *uit, *entry, *cit );
00254             connect( action, TQT_SIGNAL( toolActivated( const KDataToolInfo &, const TQString & ) ),
00255                      receiver, slot );
00256             actionList.append( action );
00257         }
00258     }
00259 
00260     return actionList;
00261 }
00262 
00263 /*************************************************
00264  *
00265  * KDataTool
00266  *
00267  *************************************************/
00268 
00269 KDataTool::KDataTool( TQObject* parent, const char* name )
00270     : TQObject( parent, name ), m_instance( 0L )
00271 {
00272 }
00273 
00274 TDEInstance* KDataTool::instance() const
00275 {
00276    return m_instance;
00277 }
00278 
00279 void KDataToolAction::virtual_hook( int id, void* data )
00280 { TDEAction::virtual_hook( id, data ); }
00281 
00282 void KDataTool::virtual_hook( int, void* )
00283 { /*BASE::virtual_hook( id, data );*/ }
00284 
00285 #include "kdatatool.moc"

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.