00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <kparts/factory.h>
00021
00022
#include <koQueryTrader.h>
00023
#include <koDocument.h>
00024
#include <koFilter.h>
00025
#include <ktrader.h>
00026
#include <kservicetype.h>
00027
#include <kdebug.h>
00028
00029
#include <qfile.h>
00030
00031
#include <limits.h>
00032
00040
00041
00042
00043
00044
00045
00046 KoDocumentEntry::KoDocumentEntry( KService::Ptr service )
00047 : m_service( service )
00048 {
00049 }
00050
00051 KoDocument*
KoDocumentEntry::createDoc(
KoDocument* parent,
const char* name )
const
00052
{
00053 KLibFactory* factory = KLibLoader::self()->factory( QFile::encodeName(m_service->library()) );
00054
00055
if( !factory ) {
00056 kdWarning(30003) << KLibLoader::self()->lastErrorMessage() << endl;
00057
return 0;
00058 }
00059
00060
QObject* obj;
00061
if ( factory->inherits(
"KParts::Factory" ) )
00062 obj = static_cast<KParts::Factory *>(factory)->createPart( 0L,
"", parent, name,
"KoDocument" );
00063
else {
00064 kdWarning(30003) <<
"factory doesn't inherit KParts::Factory ! It is a " << factory->className() << endl;
00065 obj = factory->create( parent, name,
"KoDocument" );
00066 }
00067
00068
if ( !obj || !obj->inherits(
"KoDocument" ) )
00069 {
00070
delete obj;
00071
return 0;
00072 }
00073
00074
return static_cast<KoDocument*>(obj);
00075 }
00076
00077 KoDocumentEntry KoDocumentEntry::queryByMimeType(
const QString & mimetype )
00078 {
00079
QString constr = QString::fromLatin1(
"[X-KDE-NativeMimeType] == '%1'" ).arg( mimetype );
00080
00081
QValueList<KoDocumentEntry> vec =
query(
false,constr );
00082
if ( vec.isEmpty() )
00083 {
00084 kdWarning(30003) <<
"Got no results with " << constr << endl;
00085
00086
QString constr = QString::fromLatin1(
"'%1' in ServiceTypes" ).arg( mimetype );
00087 vec = query( constr );
00088
if ( vec.isEmpty() )
00089 {
00090
00091
00092
if ( KServiceType::serviceType( mimetype ) == 0L )
00093 {
00094 kdError(30003) <<
"Unknown KOffice MimeType " << mimetype <<
"." << endl;
00095 kdError(30003) <<
"Check your installation (for instance, run 'kde-config --path mime' and check the result)." << endl;
00096 }
else
00097 {
00098 kdError(30003) <<
"Found no KOffice part able to handle " << mimetype <<
"!" << endl;
00099 kdError(30003) <<
"Check your installation (does the desktop file have X-KDE-NativeMimeType and KOfficePart, did you install KOffice in a different prefix than KDE, without adding the prefix to /etc/kderc ?)" << endl;
00100 }
00101
return KoDocumentEntry();
00102 }
00103 }
00104
00105
return vec[0];
00106 }
00107
00108 QValueList<KoDocumentEntry> KoDocumentEntry::query(
const QString & _constr )
00109 {
00110
return query(
true,_constr);
00111 }
00112
00113 QValueList<KoDocumentEntry> KoDocumentEntry::query(
bool _onlyDocEmb,
const QString & _constr )
00114 {
00115
00116
QValueList<KoDocumentEntry> lst;
00117
QString constr;
00118
if ( !_constr.isEmpty() ) {
00119 constr =
"(";
00120 constr += _constr;
00121 constr +=
") and ";
00122 }
00123 constr +=
" exist Library";
00124
00125
00126 KTrader::OfferList offers = KTrader::self()->query(
"KOfficePart", constr );
00127
00128 KTrader::OfferList::ConstIterator it = offers.begin();
00129
unsigned int max = offers.count();
00130
for(
unsigned int i = 0; i < max; i++, ++it )
00131 {
00132
00133
00134
if ( (*it)->library().isEmpty() )
00135
continue;
00136
00137
if ((!_onlyDocEmb) || ((*it)->property(
"X-KDE-NOTKoDocumentEmbeddable").toString()!=
"1"))
00138 {
00139
KoDocumentEntry d( *it );
00140
00141 lst.append( d );
00142
00143 }
00144 }
00145
00146
if ( lst.count() > 1 && !_constr.isEmpty() )
00147 kdWarning(30003) <<
"KoDocumentEntry::query " << _constr <<
" got " << max <<
" offers!" << endl;
00148
return lst;
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 KoFilterEntry::KoFilterEntry( KService::Ptr service )
00161 : m_service( service )
00162 {
00163
import = service->property(
"X-KDE-Import" ).toStringList();
00164 export_ = service->property(
"X-KDE-Export" ).toStringList();
00165
int w = service->property(
"X-KDE-Weight" ).toString().toInt();
00166 weight = w < 0 ? UINT_MAX : static_cast<unsigned int>( w );
00167 available = service->property(
"X-KDE-Available" ).toString();
00168 }
00169
00170 QValueList<KoFilterEntry::Ptr> KoFilterEntry::query(
const QString & _constr )
00171 {
00172 kdDebug(30500) <<
"KoFilterEntry::query( " << _constr <<
" )" << endl;
00173
QValueList<KoFilterEntry::Ptr> lst;
00174
00175 KTrader::OfferList offers = KTrader::self()->query(
"KOfficeFilter", _constr );
00176
00177 KTrader::OfferList::ConstIterator it = offers.begin();
00178
unsigned int max = offers.count();
00179
00180
for(
unsigned int i = 0; i < max; i++ )
00181 {
00182
00183
00184
00185 lst.append(
new KoFilterEntry( *it ) );
00186
00187 it++;
00188 }
00189
00190
return lst;
00191 }
00192
00193
KoFilter* KoFilterEntry::createFilter(
KoFilterChain* chain,
QObject* parent,
const char* name )
00194 {
00195 KLibFactory* factory = KLibLoader::self()->factory( QFile::encodeName( m_service->library() ) );
00196
00197
if ( !factory )
00198
return 0;
00199
00200
QObject* obj = factory->create( parent, name,
"KoFilter" );
00201
if ( !obj || !obj->inherits(
"KoFilter" ) )
00202 {
00203
delete obj;
00204
return 0;
00205 }
00206
00207
KoFilter* filter = static_cast<KoFilter*>( obj );
00208 filter->
m_chain = chain;
00209
return filter;
00210 }