• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdenewstuff
 

tdenewstuff

  • tdenewstuff
entry.cpp
1/*
2 This file is part of KOrganizer.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4 Copyright (c) 2014 Timothy Pearson <kb9vqf@pearsoncomputing.net>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#include "entry.h"
23
24#include <tqptrdict.h>
25#include <tqwindowdefs.h>
26
27#include <tdeglobal.h>
28#include <tdelocale.h>
29
30using namespace KNS;
31
32// BCI for KDE 3.5 only
33
34class EntryPrivate
35{
36 public:
37 EntryPrivate(){}
38 TQString mEmail;
39 TQMap<TQString,TQString> mNameMap;
40};
41
42static TQPtrDict<EntryPrivate> *d_ptr = 0;
43
44static EntryPrivate *d(const Entry *e)
45{
46 if(!d_ptr)
47 {
48 d_ptr = new TQPtrDict<EntryPrivate>();
49 d_ptr->setAutoDelete(true);
50 }
51 EntryPrivate *ret = d_ptr->find((void*)e);
52 if(!ret)
53 {
54 ret = new EntryPrivate();
55 d_ptr->replace((void*)e, ret);
56 }
57 return ret;
58}
59
60TQString Entry::authorEmail() const
61{
62 return d(this)->mEmail;
63}
64
65void Entry::setAuthorEmail( const TQString& email )
66{
67 d(this)->mEmail = email;
68}
69
70TQString Entry::name( const TQString &lang ) const
71{
72 if ( d(this)->mNameMap.isEmpty() ) return TQString::null;
73
74 if ( !d(this)->mNameMap[ lang ].isEmpty() ) return d(this)->mNameMap[ lang ];
75 else {
76 TQStringList langs = TDEGlobal::locale()->languageList();
77 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
78 if( !d(this)->mNameMap[ *it ].isEmpty() ) return d(this)->mNameMap[ *it ];
79 }
80 if ( !d(this)->mNameMap[ TQString::null ].isEmpty() ) return d(this)->mNameMap[ TQString::null ];
81 else return *(mSummaryMap.begin());
82}
83
84void Entry::setName( const TQString &name, const TQString &lang )
85{
86 d(this)->mNameMap.insert( lang, name );
87
88 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
89}
90
91// BCI part ends here
92
93Entry::Entry() :
94 mRelease( 0 ), mReleaseDate( TQDate::currentDate() ), mRating( 0 ),
95 mDownloads( 0 )
96{
97}
98
99Entry::Entry( const TQDomElement &e ) :
100 mRelease( 0 ), mRating( 0 ), mDownloads( 0 )
101{
102 parseDomElement( e );
103}
104
105Entry::~Entry()
106{
107 if (d_ptr)
108 {
109 EntryPrivate *p = d_ptr->find(this);
110 if (p)
111 d_ptr->remove(p);
112
113 if (d_ptr->isEmpty())
114 {
115 delete d_ptr;
116 d_ptr = 0L;
117 }
118 }
119}
120
121
122void Entry::setName( const TQString &name )
123{
124 mName = name;
125}
126
127TQString Entry::name() const
128{
129 return mName;
130}
131
132
133void Entry::setType( const TQString &type )
134{
135 mType = type;
136}
137
138TQString Entry::type() const
139{
140 return mType;
141}
142
143
144void Entry::setAuthor( const TQString &author )
145{
146 mAuthor = author;
147}
148
149TQString Entry::author() const
150{
151 return mAuthor;
152}
153
154
155void Entry::setLicence( const TQString &license )
156{
157 mLicence = license;
158}
159
160TQString Entry::license() const
161{
162 return mLicence;
163}
164
165
166void Entry::setSummary( const TQString &text, const TQString &lang )
167{
168 mSummaryMap.insert( lang, text );
169
170 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
171}
172
173TQString Entry::summary( const TQString &lang ) const
174{
175 if ( mSummaryMap.isEmpty() ) return TQString::null;
176
177 if ( !mSummaryMap[ lang ].isEmpty() ) return mSummaryMap[ lang ];
178 else {
179 TQStringList langs = TDEGlobal::locale()->languageList();
180 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
181 if( !mSummaryMap[ *it ].isEmpty() ) return mSummaryMap[ *it ];
182 }
183 if ( !mSummaryMap[ TQString::null ].isEmpty() ) return mSummaryMap[ TQString::null ];
184 else return *(mSummaryMap.begin());
185}
186
187
188void Entry::setVersion( const TQString &version )
189{
190 mVersion = version;
191}
192
193TQString Entry::version() const
194{
195 return mVersion;
196}
197
198
199void Entry::setRelease( int release )
200{
201 mRelease = release;
202}
203
204int Entry::release() const
205{
206 return mRelease;
207}
208
209
210void Entry::setReleaseDate( const TQDate &d )
211{
212 mReleaseDate = d;
213}
214
215TQDate Entry::releaseDate() const
216{
217 return mReleaseDate;
218}
219
220
221void Entry::setPayload( const KURL &url, const TQString &lang )
222{
223 mPayloadMap.insert( lang, url );
224
225 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
226}
227
228KURL Entry::payload( const TQString &lang ) const
229{
230 KURL payload = mPayloadMap[ lang ];
231 if ( payload.isEmpty() ) {
232 TQStringList langs = TDEGlobal::locale()->languageList();
233 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
234 if( !mPayloadMap[ *it ].isEmpty() ) return mPayloadMap[ *it ];
235 }
236 if ( payload.isEmpty() ) payload = mPayloadMap [ TQString::null ];
237 if ( payload.isEmpty() && !mPayloadMap.isEmpty() ) {
238 payload = *(mPayloadMap.begin());
239 }
240 return payload;
241}
242
243
244void Entry::setPreview( const KURL &url, const TQString &lang )
245{
246 mPreviewMap.insert( lang, url );
247
248 if ( mLangs.find( lang ) == mLangs.end() ) mLangs.append( lang );
249}
250
251KURL Entry::preview( const TQString &lang ) const
252{
253 KURL preview = mPreviewMap[ lang ];
254 if ( preview.isEmpty() ) {
255 TQStringList langs = TDEGlobal::locale()->languageList();
256 for(TQStringList::Iterator it = langs.begin(); it != langs.end(); ++it)
257 if( !mPreviewMap[ *it ].isEmpty() ) return mPreviewMap[ *it ];
258 }
259 if ( preview.isEmpty() ) preview = mPreviewMap [ TQString::null ];
260 if ( preview.isEmpty() && !mPreviewMap.isEmpty() ) {
261 preview = *(mPreviewMap.begin());
262 }
263 return preview;
264}
265
266
267void Entry::setRating( int rating )
268{
269 mRating = rating;
270}
271
272int Entry::rating()
273{
274 return mRating;
275}
276
277
278void Entry::setDownloads( int downloads )
279{
280 mDownloads = downloads;
281}
282
283int Entry::downloads()
284{
285 return mDownloads;
286}
287
288TQString Entry::fullName()
289{
290 if ( version().isEmpty() )
291 return name();
292 else
293 return name() + "-" + version() + "-" + TQString::number( release() );
294}
295
296TQStringList Entry::langs()
297{
298 return mLangs;
299}
300
301// FIXME
302// It appears that OCS has removed the ability to retrieve author EMail;
303// further confirmation is needed before removing EMail-related code
304// NOTE
305// OCS also removed the ability to have individually localized names and summaries for a single item
306// As this would be a useful feature to add to the OCS system I'm keeping the lang code skeleton in at this time
307// Note that the "language" XML tag refers to the intended language of the content, not the language of the entry!
308void Entry::parseDomElement( const TQDomElement &element )
309{
310 if ( element.tagName() != "content" ) return;
311 mType = element.attribute("type");
312
313 TQDomNode n;
314 TQString lang;
315 for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
316 TQDomElement e = n.toElement();
317 if ( e.tagName() == "name" )
318 {
319 setName( e.text().stripWhiteSpace(), lang );
320 setName( e.text().stripWhiteSpace() ); /* primary key - no i18n */
321 }
322 if ( e.tagName() == "personid" ) {
323 setAuthor( e.text().stripWhiteSpace() );
324// TQString email = e.attribute( "email" );
325// setAuthorEmail( email );
326 }
327// if ( e.tagName() == "email" ) setAuthorEmail( e.text().stripWhiteSpace() ); /* kde-look; change on server! */
328 if ( e.tagName() == "licence" ) setLicence( e.text().stripWhiteSpace() );
329 if ( e.tagName() == "description" ) {
330 setSummary( e.text().stripWhiteSpace(), lang );
331 }
332 if ( e.tagName() == "version" ) setVersion( e.text().stripWhiteSpace() );
333// if ( e.tagName() == "release" ) setRelease( e.text().toInt() );
334 if ( e.tagName() == "created" ) {
335 TQDate date = TQDate::fromString( e.text().stripWhiteSpace(), TQt::ISODate );
336 setReleaseDate( date );
337 }
338 if ( e.tagName() == "smallpreviewpic1" ) {
339 setPreview( KURL( e.text().stripWhiteSpace() ), lang );
340 }
341 if ( e.tagName() == "downloadlink1" ) {
342 setPayload( KURL( e.text().stripWhiteSpace() ), lang );
343 }
344 if ( e.tagName() == "score" ) setRating( e.text().toInt() );
345 if ( e.tagName() == "downloads" ) setDownloads( e.text().toInt() );
346// if ( e.tagName() == "typename" ) setType( e.text() );
347 }
348}
349
350TQDomElement Entry::createDomElement( TQDomDocument &doc,
351 TQDomElement &parent )
352{
353 TQDomElement entry = doc.createElement( "content" );
354 entry.setAttribute("type", mType);
355 parent.appendChild( entry );
356
357 addElement( doc, entry, "language", langs().first() );
358
359 addElement( doc, entry, "name", name() );
360 addElement( doc, entry, "personid", author() );
361// addElement( doc, entry, "email", authorEmail() );
362 addElement( doc, entry, "licence", license() );
363 addElement( doc, entry, "version", version() );
364// addElement( doc, entry, "release", TQString::number( release() ) );
365 addElement( doc, entry, "score", TQString::number( rating() ) );
366 addElement( doc, entry, "downloads", TQString::number( downloads() ) );
367
368 addElement( doc, entry, "created",
369 releaseDate().toString( TQt::ISODate ) );
370
371 addElement( doc, entry, "description", summary() );
372 addElement( doc, entry, "preview", preview().url() );
373 addElement( doc, entry, "payload", payload().url() );
374
375 return entry;
376}
377
378TQDomElement Entry::addElement( TQDomDocument &doc, TQDomElement &parent,
379 const TQString &tag, const TQString &value )
380{
381 TQDomElement n = doc.createElement( tag );
382 n.appendChild( doc.createTextNode( value ) );
383 parent.appendChild( n );
384
385 return n;
386}
KNS::Entry
TDENewStuff data entry container.
Definition: entry.h:46
KNS::Entry::fullName
TQString fullName()
Return the full name for the meta information.
Definition: entry.cpp:288
KNS::Entry::rating
int rating()
Retrieve the rating for the object, which has been determined by its users and thus might change over...
Definition: entry.cpp:272
KNS::Entry::downloads
int downloads()
Retrieve the download count for the object, which has been determined by its hosting sites and thus m...
Definition: entry.cpp:283
KNS::Entry::name
TQString name() const
Retrieve the name of the data object.
Definition: entry.cpp:127
KNS::Entry::setSummary
void setSummary(const TQString &, const TQString &lang=TQString::null)
Sets a short description on what the object is all about.
Definition: entry.cpp:166
KNS::Entry::releaseDate
TQDate releaseDate() const
Retrieve the date of the object's publication.
Definition: entry.cpp:215
KNS::Entry::setLicence
void setLicence(const TQString &)
Sets the license (abbreviation) applicable to the object.
Definition: entry.cpp:155
KNS::Entry::setName
void setName(const TQString &)
Sets the (unique) name for this data object.
Definition: entry.cpp:122
KNS::Entry::payload
KURL payload(const TQString &lang=TQString::null) const
Retrieve the file name of the object.
Definition: entry.cpp:228
KNS::Entry::langs
TQStringList langs()
Return the list of languages this object supports.
Definition: entry.cpp:296
KNS::Entry::setDownloads
void setDownloads(int)
Sets the number of downloads.
Definition: entry.cpp:278
KNS::Entry::setAuthorEmail
void setAuthorEmail(const TQString &)
Sets the email address of the object's author.
Definition: entry.cpp:65
KNS::Entry::preview
KURL preview(const TQString &lang=TQString::null) const
Retrieve the file name of an image containing a preview of the object.
Definition: entry.cpp:251
KNS::Entry::setRating
void setRating(int)
Sets the rating between 0 (worst) and 10 (best).
Definition: entry.cpp:267
KNS::Entry::release
int release() const
Retrieve the release number of the object.
Definition: entry.cpp:204
KNS::Entry::setReleaseDate
void setReleaseDate(const TQDate &)
Sets the release date.
Definition: entry.cpp:210
KNS::Entry::type
TQString type() const
Retrieve the type of the data object.
Definition: entry.cpp:138
KNS::Entry::author
TQString author() const
Retrieve the author's name of the object.
Definition: entry.cpp:149
KNS::Entry::~Entry
~Entry()
Destructor.
Definition: entry.cpp:105
KNS::Entry::summary
TQString summary(const TQString &lang=TQString::null) const
Retrieve a short description about the object.
Definition: entry.cpp:173
KNS::Entry::setRelease
void setRelease(int)
Sets the release number, which is increased for feature-equal objects with the same version number,...
Definition: entry.cpp:199
KNS::Entry::setType
void setType(const TQString &)
Sets the application type, e.g.
Definition: entry.cpp:133
KNS::Entry::version
TQString version() const
Retrieve the version string of the object.
Definition: entry.cpp:193
KNS::Entry::license
TQString license() const
Retrieve the license name of the object.
Definition: entry.cpp:160
KNS::Entry::setPayload
void setPayload(const KURL &, const TQString &lang=TQString::null)
Sets the object's file.
Definition: entry.cpp:221
KNS::Entry::setVersion
void setVersion(const TQString &)
Sets the version number.
Definition: entry.cpp:188
KNS::Entry::setPreview
void setPreview(const KURL &, const TQString &lang=TQString::null)
Sets the object's preview file, if available.
Definition: entry.cpp:244
KNS::Entry::setAuthor
void setAuthor(const TQString &)
Sets the full name of the object's author.
Definition: entry.cpp:144
KNS
Handles security releated issues, like signing, verifying.
Definition: downloaddialog.h:37

tdenewstuff

Skip menu "tdenewstuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdenewstuff

Skip menu "tdenewstuff"
  • 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 tdenewstuff by doxygen 1.9.4
This website is maintained by Timothy Pearson.