23 #include <tqptrdict.h> 24 #include <tqwindowdefs.h> 38 TQMap<TQString,TQString> mNameMap;
41 static TQPtrDict<EntryPrivate> *d_ptr = 0;
43 static EntryPrivate *d(
const Entry *e)
47 d_ptr =
new TQPtrDict<EntryPrivate>();
48 d_ptr->setAutoDelete(
true);
50 EntryPrivate *ret = d_ptr->find((
void*)e);
53 ret =
new EntryPrivate();
54 d_ptr->replace((
void*)e, ret);
61 return d(
this)->mEmail;
66 d(
this)->mEmail = email;
71 if ( d(
this)->mNameMap.isEmpty() )
return TQString::null;
73 if ( !d(
this)->mNameMap[ lang ].isEmpty() )
return d(
this)->mNameMap[ lang ];
75 TQStringList langs = KGlobal::locale()->languageList();
76 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
77 if( !d(
this)->mNameMap[ *it ].isEmpty() )
return d(
this)->mNameMap[ *it ];
79 if ( !d(
this)->mNameMap[ TQString::null ].isEmpty() )
return d(
this)->mNameMap[ TQString::null ];
80 else return *(mSummaryMap.begin());
85 d(
this)->mNameMap.insert( lang, name );
87 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
93 mRelease( 0 ), mReleaseDate( TQDate::currentDate() ), mRating( 0 ),
98 Entry::Entry(
const TQDomElement &e ) :
99 mRelease( 0 ), mRating( 0 ), mDownloads( 0 )
101 parseDomElement( e );
108 EntryPrivate *p = d_ptr->find(
this);
112 if (d_ptr->isEmpty())
167 mSummaryMap.insert( lang, text );
169 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
174 if ( mSummaryMap.isEmpty() )
return TQString::null;
176 if ( !mSummaryMap[ lang ].isEmpty() )
return mSummaryMap[ lang ];
178 TQStringList
langs = KGlobal::locale()->languageList();
179 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
180 if( !mSummaryMap[ *it ].isEmpty() )
return mSummaryMap[ *it ];
182 if ( !mSummaryMap[ TQString::null ].isEmpty() )
return mSummaryMap[ TQString::null ];
183 else return *(mSummaryMap.begin());
222 mPayloadMap.insert( lang, url );
224 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
229 KURL
payload = mPayloadMap[ lang ];
230 if ( payload.isEmpty() ) {
231 TQStringList
langs = KGlobal::locale()->languageList();
232 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
233 if( !mPayloadMap[ *it ].isEmpty() )
return mPayloadMap[ *it ];
235 if ( payload.isEmpty() ) payload = mPayloadMap [ TQString::null ];
236 if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
237 payload = *(mPayloadMap.begin());
245 mPreviewMap.insert( lang, url );
247 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
252 KURL
preview = mPreviewMap[ lang ];
253 if ( preview.isEmpty() ) {
254 TQStringList
langs = KGlobal::locale()->languageList();
255 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
256 if( !mPreviewMap[ *it ].isEmpty() )
return mPreviewMap[ *it ];
258 if ( preview.isEmpty() ) preview = mPreviewMap [ TQString::null ];
259 if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
260 preview = *(mPreviewMap.begin());
300 void Entry::parseDomElement(
const TQDomElement &element )
302 if ( element.tagName() !=
"stuff" )
return;
303 mType = element.attribute(
"type");
306 for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
307 TQDomElement e = n.toElement();
308 if ( e.tagName() ==
"name" )
310 TQString lang = e.attribute(
"lang" );
311 setName( e.text().stripWhiteSpace(), lang );
312 if(lang.isNull())
setName( e.text().stripWhiteSpace() );
314 if ( e.tagName() ==
"author" ) {
316 TQString email = e.attribute(
"email" );
319 if ( e.tagName() ==
"email" )
setAuthorEmail( e.text().stripWhiteSpace() );
320 if ( e.tagName() ==
"licence" )
setLicence( e.text().stripWhiteSpace() );
321 if ( e.tagName() ==
"summary" ) {
322 TQString lang = e.attribute(
"lang" );
323 setSummary( e.text().stripWhiteSpace(), lang );
325 if ( e.tagName() ==
"version" )
setVersion( e.text().stripWhiteSpace() );
326 if ( e.tagName() ==
"release" )
setRelease( e.text().toInt() );
327 if ( e.tagName() ==
"releasedate" ) {
328 TQDate date = TQT_TQDATE_OBJECT(TQDate::fromString( e.text().stripWhiteSpace(), Qt::ISODate ));
331 if ( e.tagName() ==
"preview" ) {
332 TQString lang = e.attribute(
"lang" );
333 setPreview( KURL( e.text().stripWhiteSpace() ), lang );
335 if ( e.tagName() ==
"payload" ) {
336 TQString lang = e.attribute(
"lang" );
337 setPayload( KURL( e.text().stripWhiteSpace() ), lang );
339 if ( e.tagName() ==
"rating" )
setRating( e.text().toInt() );
340 if ( e.tagName() ==
"downloads" )
setDownloads( e.text().toInt() );
344 TQDomElement Entry::createDomElement( TQDomDocument &doc,
345 TQDomElement &parent )
347 TQDomElement entry = doc.createElement(
"stuff" );
348 entry.setAttribute(
"type", mType);
349 parent.appendChild( entry );
351 addElement( doc, entry,
"name",
name() );
352 addElement( doc, entry,
"author",
author() );
354 addElement( doc, entry,
"licence",
license() );
355 addElement( doc, entry,
"version",
version() );
356 addElement( doc, entry,
"release", TQString::number(
release() ) );
357 addElement( doc, entry,
"rating", TQString::number(
rating() ) );
358 addElement( doc, entry,
"downloads", TQString::number(
downloads() ) );
360 addElement( doc, entry,
"releasedate",
363 TQStringList ls =
langs();
364 TQStringList::ConstIterator it;
365 for( it = ls.begin(); it != ls.end(); ++it ) {
366 TQDomElement e = addElement( doc, entry,
"summary",
summary( *it ) );
367 e.setAttribute(
"lang", *it );
368 e = addElement( doc, entry,
"preview",
preview( *it ).url() );
369 e.setAttribute(
"lang", *it );
370 e = addElement( doc, entry,
"payload",
payload( *it ).url() );
371 e.setAttribute(
"lang", *it );
377 TQDomElement Entry::addElement( TQDomDocument &doc, TQDomElement &parent,
378 const TQString &tag,
const TQString &value )
380 TQDomElement n = doc.createElement( tag );
381 n.appendChild( doc.createTextNode( value ) );
382 parent.appendChild( n );
int downloads()
Retrieve the download count for the object, which has been determined by its hosting sites and thus m...
TQString authorEmail() const
Retrieve the author's email address of the object.
int rating()
Retrieve the rating for the object, which has been determined by its users and thus might change over...
void setRelease(int)
Sets the release number, which is increased for feature-equal objects with the same version number...
KURL preview(const TQString &lang=TQString::null) const
Retrieve the file name of an image containing a preview of the object.
KNewStuff data entry container.
int release() const
Retrieve the release number of the object.
TQString license() const
Retrieve the license name of the object.
void setAuthor(const TQString &)
Sets the full name of the object's author.
TQString type() const
Retrieve the type of the data object.
void setDownloads(int)
Sets the number of downloads.
void setReleaseDate(const TQDate &)
Sets the release date.
void setVersion(const TQString &)
Sets the version number.
TQStringList langs()
Return the list of languages this object supports.
TQString fullName()
Return the full name for the meta information.
TQString author() const
Retrieve the author's name of the object.
void setType(const TQString &)
Sets the application type, e.g.
TQString name() const
Retrieve the name of the data object.
void setPreview(const KURL &, const TQString &lang=TQString::null)
Sets the object's preview file, if available.
TQString summary(const TQString &lang=TQString::null) const
Retrieve a short description about the object.
void setAuthorEmail(const TQString &)
Sets the email address of the object's author.
void setRating(int)
Sets the rating between 0 (worst) and 10 (best).
KURL payload(const TQString &lang=TQString::null) const
Retrieve the file name of the object.
TQDate releaseDate() const
Retrieve the date of the object's publication.
Handles security releated issues, like signing, verifying.
void setSummary(const TQString &, const TQString &lang=TQString::null)
Sets a short description on what the object is all about.
TQString version() const
Retrieve the version string of the object.
void setName(const TQString &)
Sets the (unique) name for this data object.
void setLicence(const TQString &)
Sets the license (abbreviation) applicable to the object.
void setPayload(const KURL &, const TQString &lang=TQString::null)
Sets the object's file.