F:/KPlato/koffice/libs/kofficecore/tests/filter_graph.cpp

Aller à la documentation de ce fichier.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Werner Trobin <trobin@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <QFile>
00021 //Added by qt3to4:
00022 #include <Q3ValueList>
00023 #include <Q3CString>
00024 #include <QList>
00025 #include <KoQueryTrader.h>
00026 #include <KoFilterManager.h>
00027 #include <kinstance.h>
00028 #include <kdebug.h>
00029 
00030 int main( int /*argc*/, char ** /*argv*/ )
00031 {
00032     KInstance instance( "filter_graph" );  // we need an instance when using the trader
00033 
00034     Q3CString output = "digraph filters {\n";
00035 
00036     // The following code is shamelessly copied over from KOffice::Graph::buildGraph
00037     // It wasn't feasible to do some serious changes in the lib for that tiny bit
00038     // of duplicated code in a test file.
00039 
00040     QList<QString> vertices; // to keep track of already inserted values, not performance critical
00041 
00042     // Make sure that all available parts are added to the graph
00043     Q3ValueList<KoDocumentEntry> parts( KoDocumentEntry::query() );
00044     Q3ValueList<KoDocumentEntry>::ConstIterator partIt( parts.begin() );
00045     Q3ValueList<KoDocumentEntry>::ConstIterator partEnd( parts.end() );
00046 
00047     while ( partIt != partEnd ) {
00048         //kDebug() << ( *partIt ).service()->desktopEntryName() << endl;
00049         QStringList nativeMimeTypes = ( *partIt ).service()->property( "X-KDE-ExtraNativeMimeTypes" ).toStringList();
00050         nativeMimeTypes += ( *partIt ).service()->property( "X-KDE-NativeMimeType" ).toString();
00051         QStringList::ConstIterator it = nativeMimeTypes.begin();
00052         QStringList::ConstIterator end = nativeMimeTypes.end();
00053         for ( ; it != end; ++it ) {
00054             QString key = *it;
00055             //kDebug() << "    " << key << endl;
00056             if ( !key.isEmpty() ) {
00057                 output += "    \"";
00058                 output += key.toLatin1();
00059                 output += "\" [shape=box, style=filled, fillcolor=lightblue];\n";
00060                 if ( ! vertices.contains( key ) )
00061                     vertices.append( key );
00062             }
00063         }
00064         ++partIt;
00065     }
00066 
00067     Q3ValueList<KoFilterEntry::Ptr> filters( KoFilterEntry::query() ); // no constraint here - we want *all* :)
00068     Q3ValueList<KoFilterEntry::Ptr>::ConstIterator it = filters.begin();
00069     Q3ValueList<KoFilterEntry::Ptr>::ConstIterator end = filters.end();
00070 
00071     for ( ; it != end; ++it ) {
00072         kDebug() << "import " << ( *it )->import << " export " << ( *it )->export_ << endl;
00073         // First add the "starting points"
00074         QStringList::ConstIterator importIt = ( *it )->import.begin();
00075         QStringList::ConstIterator importEnd = ( *it )->import.end();
00076         for ( ; importIt != importEnd; ++importIt ) {
00077             // already there?
00078             if ( ! vertices.contains( *importIt ) ) {
00079                 vertices.append( *importIt );
00080                 output += "    \"";
00081                 output += ( *importIt ).toLatin1();
00082                 output += "\";\n";
00083             }
00084         }
00085 
00086         QStringList::ConstIterator exportIt = ( *it )->export_.begin();
00087         QStringList::ConstIterator exportEnd = ( *it )->export_.end();
00088 
00089         for ( ; exportIt != exportEnd; ++exportIt ) {
00090             // First make sure the export vertex is in place
00091             if ( ! vertices.contains( *exportIt ) ) {
00092                 output += "    \"";
00093                 output += ( *exportIt ).toLatin1();
00094                 output += "\";\n";
00095                 vertices.append( *exportIt );
00096             }
00097             // Then create the appropriate edges
00098             importIt = ( *it )->import.begin();
00099             for ( ; importIt != importEnd; ++importIt ) {
00100                 output += "    \"";
00101                 output += ( *importIt ).toLatin1();
00102                 output += "\" -> \"";
00103                 output += ( *exportIt ).toLatin1();
00104                 if ( KoFilterManager::filterAvailable( *it ) )
00105                     output += "\";\n";
00106                 else
00107                     output += "\" [style=dotted];\n";
00108             }
00109         }
00110     }
00111 
00112     output += "}\n";
00113 
00114     QFile f( "graph.dot" );
00115     if ( f.open( QIODevice::WriteOnly ) )
00116         f.write( output.data(), output.size() - 1 );
00117     f.close();
00118     return 0;
00119 }

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1