• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
knarticle.cpp
Go to the documentation of this file.
1 /*
2  KNode, the KDE newsreader
3  Copyright (c) 1999-2005 the KNode authors.
4  See file AUTHORS for details
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  You should have received a copy of the GNU General Public License
11  along with this program; if not, write to the Free Software Foundation,
12  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
13 */
14 
15 #include "knarticle.h"
16 
17 #include "knhdrviewitem.h"
18 #include "kngroup.h"
19 #include "knglobals.h"
20 #include "knconfigmanager.h"
21 #include "settings.h"
22 #include "utilities.h"
23 #include "utils/locale.h"
24 
25 #include <kcodecs.h>
26 #include <kmimetype.h>
27 
28 
29 using namespace KNode::Utilities;
30 using namespace KMime;
31 
32 
33 KNArticle::KNArticle( KNArticleCollection::Ptr c )
34  : i_d( -1 ), c_ol( c ), i_tem( 0 )
35 {
36 }
37 
38 
39 KNArticle::~KNArticle()
40 {
41  delete i_tem;
42 }
43 
44 
45 void KNArticle::clear()
46 {
47  f_lags.clear();
48 }
49 
50 
51 void KNArticle::setListItem( KNHdrViewItem *it, KNArticle::Ptr a )
52 {
53  Q_ASSERT_X( this == a.get(), "KNArticle::setListItem", "By contract, setListItem second parameter must be a reference to 'this' article" );
54  i_tem=it;
55  if( i_tem ) {
56  i_tem->art = a;
57  }
58 }
59 
60 
61 void KNArticle::setLocked(bool b)
62 {
63  f_lags.set(0, b);
64  if(c_ol) { // local articles may have c_ol==0 !
65  if(b)
66  c_ol->articleLocked();
67  else
68  c_ol->articleUnlocked();
69  }
70 }
71 
72 
73 //=========================================================================================
74 
75 
76 KNRemoteArticle::KNRemoteArticle( KNGroup::Ptr g )
77  : KNArticle(g), a_rticleNumber(-1), i_dRef(-1), t_hrLevel(0), s_core(0),
78  c_olor(knGlobals.settings()->unreadThreadColor()),
79  u_nreadFups(0), n_ewFups(0), s_ubThreadChangeDate(0)
80 {
81  setDefaultCharset( Locale::defaultCharset( g ) );
82 
83  // Remote article are read-only
84  setFrozen( true );
85 }
86 
87 
88 KNRemoteArticle::~KNRemoteArticle()
89 {}
90 
91 
92 void KNRemoteArticle::parse()
93 {
94  KNArticle::parse();
95  QByteArray raw;
96 
97  raw = KMime::extractHeader( head(), from()->type() );
98  if ( !raw.isEmpty() ) {
99  QByteArray f;
100  Locale::encodeTo7Bit( raw, defaultCharset(), f );
101  from()->from7BitString( f );
102  }
103 
104  raw = KMime::extractHeader( head(), subject()->type() );
105  if( !raw.isEmpty() ) {
106  QByteArray subjectStr;
107  Locale::encodeTo7Bit( raw, defaultCharset(), subjectStr );
108  subject()->from7BitString( subjectStr );
109  }
110 }
111 
112 
113 void KNRemoteArticle::initListItem()
114 {
115  if(!i_tem) return;
116 
117  KMime::Types::Mailbox mbox;
118  if ( !from()->isEmpty() ) {
119  mbox = from()->mailboxes().first();
120  }
121  if ( mbox.hasName() )
122  i_tem->setText( 1, mbox.name() );
123  else
124  i_tem->setText( 1, QString::fromLatin1( mbox.address() ) );
125 
126  updateListItem();
127 }
128 
129 
130 void KNRemoteArticle::updateListItem()
131 {
132  if(!i_tem) return;
133 
134  KNode::Appearance *app=knGlobals.configManager()->appearance();
135 
136  if(isRead()) {
137  if(hasContent())
138  i_tem->setPixmap(0, app->icon(KNode::Appearance::greyBallChkd));
139  else
140  i_tem->setPixmap(0, app->icon(KNode::Appearance::greyBall));
141  }
142  else {
143  if(hasContent())
144  i_tem->setPixmap(0,app->icon(KNode::Appearance::redBallChkd));
145  else
146  i_tem->setPixmap(0, app->icon(KNode::Appearance::redBall));
147  }
148 
149  if(hasNewFollowUps())
150  i_tem->setPixmap(1, app->icon(KNode::Appearance::newFups));
151  else
152  i_tem->setPixmap(1, app->icon(KNode::Appearance::null));
153 
154  if(isWatched())
155  i_tem->setPixmap(2, app->icon(KNode::Appearance::eyes));
156  else {
157  if(isIgnored())
158  i_tem->setPixmap(2, app->icon(KNode::Appearance::ignore));
159  else
160  i_tem->setPixmap(2, app->icon(KNode::Appearance::null));
161  }
162 
163  i_tem->setExpandable( (threadMode() && hasVisibleFollowUps()) );
164 
165  i_tem->repaint(); //force repaint
166 }
167 
168 
169 void KNRemoteArticle::thread(KNRemoteArticle::List &l)
170 {
171  KNRemoteArticle::Ptr tmp;
172  KNGroup::Ptr g = boost::static_pointer_cast<KNGroup>( c_ol );
173  int idRef=i_dRef, topID=-1;
174  KNRemoteArticle::Ptr ref = g->byId( id() ); // get self reference
175 
176  while(idRef!=0) {
177  ref=g->byId(idRef);
178  if(!ref)
179  return; // sh#t !!
180  idRef=ref->idRef();
181  }
182 
183  topID=ref->id();
184  l.append(ref);
185 
186  for(int i=0; i<g->length(); ++i) {
187  tmp=g->at(i);
188  if(tmp->idRef()!=0) {
189  idRef=tmp->idRef();
190  while(idRef!=0) {
191  ref=g->byId(idRef);
192  idRef=ref->idRef();
193  }
194  if(ref->id()==topID)
195  l.append(tmp);
196  }
197  }
198 }
199 
200 
201 void KNRemoteArticle::setForceDefaultCharset(bool b)
202 {
203  if (!b) { // restore default
204  KNGroup::Ptr g = boost::static_pointer_cast<KNGroup>( c_ol );
205  setDefaultCharset( Locale::defaultCharset( g ) );
206  }
207  KNArticle::setForceDefaultCharset( b );
208  initListItem();
209 }
210 
211 
212 void KNRemoteArticle::propagateThreadChangedDate()
213 {
214  KNGroup::Ptr g = boost::static_pointer_cast<KNGroup>( c_ol );
215  KNRemoteArticle::Ptr ref = g->byId( id() );
216  int idRef=i_dRef;
217 
218  while (idRef!=0) {
219  ref=g->byId(idRef);
220  if(!ref)
221  return; // sh#t !!
222  idRef=ref->idRef();
223  }
224 
225  if (date()->dateTime() > ref->date()->dateTime()) {
226  ref->setSubThreadChangeDate(date()->dateTime().toTime_t());
227  }
228 }
229 
230 
231 //=========================================================================================
232 
233 
234 KNLocalArticle::KNLocalArticle( KNArticleCollection::Ptr c )
235  : KNArticle(c), s_Offset(0), e_Offset(0), s_erverId(-1)
236 {
237  setDefaultCharset( Locale::defaultCharset() );
238 }
239 
240 
241 KNLocalArticle::~KNLocalArticle()
242 {}
243 
244 
245 void KNLocalArticle::updateListItem()
246 {
247  if(!i_tem)
248  return;
249 
250  QString tmp;
251  int idx=0;
252  KNode::Appearance *app=knGlobals.configManager()->appearance();
253 
254  if(isSavedRemoteArticle()) {
255  i_tem->setPixmap(0, app->icon(KNode::Appearance::savedRemote));
256  Headers::Newsgroups *hdrNewsgroup = newsgroups( false );
257  if ( hdrNewsgroup && !hdrNewsgroup->isEmpty() ) {
258  tmp = hdrNewsgroup->asUnicodeString();
259  } else {
260  Headers::To *hdrTo = to( false );
261  if ( hdrTo && !hdrTo->isEmpty() ) {
262  tmp = hdrTo->asUnicodeString();
263  }
264  }
265  } else {
266  if(doPost()) {
267  tmp += newsgroups()->asUnicodeString();
268  if(canceled())
269  i_tem->setPixmap(idx++, app->icon(KNode::Appearance::canceledPosting));
270  else
271  i_tem->setPixmap(idx++, app->icon(KNode::Appearance::posting));
272  }
273 
274  if(doMail()) {
275  i_tem->setPixmap(idx++, app->icon(KNode::Appearance::mail));
276  if(doPost())
277  tmp+=" / ";
278  tmp += to()->asUnicodeString();
279  }
280  }
281 
282  i_tem->setText(1, tmp);
283 }
284 
285 
286 void KNLocalArticle::setForceDefaultCharset( bool b )
287 {
288  if (!b) // restore default
289  setDefaultCharset( Locale::defaultCharset() );
290  KNArticle::setForceDefaultCharset( b );
291  updateListItem();
292 }
293 
294 
295 //=========================================================================================
296 
297 
298 KNAttachment::KNAttachment(Content *c)
299  : c_ontent(c), l_oadHelper(0), f_ile(0), i_sAttached(true)
300 {
301  Headers::ContentType *t=c->contentType();
302  Headers::ContentTransferEncoding *e=c->contentTransferEncoding();
303  Headers::ContentDescription *d=c->contentDescription(false);
304 
305  n_ame=t->name();
306 
307  if(d)
308  d_escription=d->asUnicodeString();
309 
310 
311  setMimeType(t->mimeType());
312 
313  if(e->encoding()==Headers::CEuuenc) {
314  setCte( Headers::CEbase64 );
315  updateContentInfo();
316  }
317  else
318  e_ncoding.setEncoding( e->encoding() );
319 
320 
321  h_asChanged=false; // has been set to "true" in setMimeType()
322 }
323 
324 
325 KNAttachment::KNAttachment(KNLoadHelper *helper)
326  : c_ontent(0), l_oadHelper(helper), f_ile(helper->getFile()), i_sAttached(false), h_asChanged(true)
327 {
328  setMimeType(KMimeType::findByPath(f_ile->fileName())->name());
329  n_ame=helper->getURL().fileName();
330 }
331 
332 
333 KNAttachment::~KNAttachment()
334 {
335  if(!i_sAttached && c_ontent)
336  delete c_ontent;
337  delete l_oadHelper;
338 }
339 
340 
341 void KNAttachment::setMimeType(const QString &s)
342 {
343  mMimeType = s;
344  h_asChanged=true;
345 
346  if ( !mMimeType.contains( "text/", Qt::CaseInsensitive ) ) {
347  f_b64=true;
348  e_ncoding.setEncoding(Headers::CEbase64);
349  }
350  else {
351  f_b64=false;
352  if ( knGlobals.settings()->allow8BitBody() )
353  setCte(Headers::CE8Bit);
354  else
355  setCte(Headers::CEquPr);
356  }
357 }
358 
359 
360 QString KNAttachment::contentSize() const
361 {
362  int s=0;
363 
364  if(c_ontent && c_ontent->hasContent())
365  s=c_ontent->size();
366  else {
367  if (f_ile)
368  s=f_ile->size();
369  }
370 
371  return KGlobal::locale()->formatByteSize( s );
372 }
373 
374 
375 void KNAttachment::updateContentInfo()
376 {
377  if(!h_asChanged || !c_ontent)
378  return;
379 
380  //Content-Type
381  Headers::ContentType *t=c_ontent->contentType();
382  t->setMimeType( mMimeType.toLatin1() );
383  t->setName(n_ame, "UTF-8");
384  t->setCategory(Headers::CCmixedPart);
385 
386  //Content-Description
387  if(d_escription.isEmpty())
388  c_ontent->removeHeader("Content-Description");
389  else
390  c_ontent->contentDescription()->fromUnicodeString(d_escription, "UTF-8");
391 
392  //Content-Disposition
393  Headers::ContentDisposition *d=c_ontent->contentDisposition();
394  d->setDisposition(Headers::CDattachment);
395  d->setFilename(n_ame);
396 
397  //Content-Transfer-Encoding
398  if(i_sAttached)
399  c_ontent->changeEncoding(e_ncoding.encoding());
400  else
401  c_ontent->contentTransferEncoding()->setEncoding(e_ncoding.encoding());
402 
403  c_ontent->assemble();
404 
405  h_asChanged=false;
406 }
407 
408 
409 
410 void KNAttachment::attach(Content *c)
411 {
412  if(i_sAttached || !f_ile)
413  return;
414 
415  c_ontent=new Content();
416  updateContentInfo();
417  Headers::ContentType *type=c_ontent->contentType();
418  Headers::ContentTransferEncoding *e=c_ontent->contentTransferEncoding();
419  QByteArray data;
420 
421  data = f_ile->readAll();
422 
423  if ( data.size() < f_ile->size() && f_ile->error() != QFile::NoError ) {
424  KNHelper::displayExternalFileError();
425  delete c_ontent;
426  c_ontent=0;
427  } else {
428  if (e_ncoding.encoding()==Headers::CEbase64 || !type->isText()) { //encode base64
429  c_ontent->setBody( KCodecs::base64Encode(data, true) + '\n' );
430  // c_ontent->b_ody += '\n';
431  e->setEncoding(Headers::CEbase64);
432  e->setDecoded(false);
433  } else {
434  c_ontent->setBody( data + '\n' );
435  // c_ontent->b_ody += '\n';
436  e->setDecoded(true);
437  }
438  }
439 
440  if(c_ontent) {
441  c->addContent(c_ontent);
442  i_sAttached=true;
443  }
444 }
445 
446 
447 void KNAttachment::detach(Content *c)
448 {
449  if(i_sAttached) {
450  c->removeContent(c_ontent, false);
451  i_sAttached=false;
452  }
453 }
KNRemoteArticle::threadMode
bool threadMode()
Definition: knarticle.h:149
KNRemoteArticle::isWatched
bool isWatched()
Definition: knarticle.h:138
KNode::Appearance::greyBallChkd
Definition: knconfig.h:62
KNAttachment::KNAttachment
KNAttachment(KMime::Content *c)
KNAttachment::h_asChanged
bool h_asChanged
Definition: knarticle.h:323
KNRemoteArticle::~KNRemoteArticle
~KNRemoteArticle()
Definition: knarticle.cpp:88
KNLocalArticle::doPost
bool doPost()
Definition: knarticle.h:231
KNAttachment::f_ile
QFile * f_ile
Definition: knarticle.h:318
utilities.h
KNode::Appearance::ignore
Definition: knconfig.h:64
KNRemoteArticle::thread
void thread(List &f)
Definition: knarticle.cpp:169
KNRemoteArticle::parse
virtual void parse()
Definition: knarticle.cpp:92
KNRemoteArticle::isRead
bool isRead()
Definition: knarticle.h:128
date
time_t date() const
KNAttachment::updateContentInfo
void updateContentInfo()
Definition: knarticle.cpp:375
KNRemoteArticle::updateListItem
void updateListItem()
Definition: knarticle.cpp:130
KNode::Appearance::redBall
Definition: knconfig.h:62
KNArticle::f_lags
KMime::BoolFlags f_lags
Definition: knarticle.h:91
KNode::Appearance::savedRemote
Definition: knconfig.h:65
KNode::Appearance::eyes
Definition: knconfig.h:63
KNLocalArticle::KNLocalArticle
KNLocalArticle(boost::shared_ptr< KNArticleCollection > c=boost::shared_ptr< KNArticleCollection >())
Definition: knarticle.cpp:234
KNRemoteArticle::initListItem
void initListItem()
Definition: knarticle.cpp:113
KNLocalArticle::isSavedRemoteArticle
bool isSavedRemoteArticle()
Definition: knarticle.h:240
KNGroup
Representation of a news group.
Definition: kngroup.h:41
KNLocalArticle::doMail
bool doMail()
Definition: knarticle.h:225
from
QString from() const
KNode::Appearance::null
Definition: knconfig.h:66
kngroup.h
KNode::Appearance::greyBall
Definition: knconfig.h:62
KNRemoteArticle::KNRemoteArticle
KNRemoteArticle(boost::shared_ptr< KNGroup > g)
Definition: knarticle.cpp:76
KNLoadHelper
File open helper (includes file open dialog and network download).
Definition: utilities.h:55
KNAttachment::l_oadHelper
KNLoadHelper * l_oadHelper
Definition: knarticle.h:317
KNAttachment::n_ame
QString n_ame
Definition: knarticle.h:320
KNAttachment::attach
void attach(KMime::Content *c)
Definition: knarticle.cpp:410
KNArticle::setListItem
void setListItem(KNHdrViewItem *i, KNArticle::Ptr a)
Sets the headerview item associated to this article.
Definition: knarticle.cpp:51
KNArticle::KNArticle
KNArticle(boost::shared_ptr< KNArticleCollection > c)
Definition: knarticle.cpp:33
KNLoadHelper::getURL
KUrl getURL() const
Definition: utilities.h:69
KNRemoteArticle::propagateThreadChangedDate
void propagateThreadChangedDate()
Definition: knarticle.cpp:212
KNArticle::clear
virtual void clear()
Definition: knarticle.cpp:45
KNHelper::displayExternalFileError
static void displayExternalFileError(QWidget *w=0)
use this for all external files
Definition: utilities.cpp:350
KNode::Appearance::redBallChkd
Definition: knconfig.h:63
KNAttachment::d_escription
QString d_escription
Definition: knarticle.h:320
KNRemoteArticle::i_dRef
int i_dRef
Definition: knarticle.h:191
KNArticle::i_tem
KNHdrViewItem * i_tem
Definition: knarticle.h:89
KNode::Appearance::icon
const QPixmap & icon(IconIndex i)
Definition: knconfig.h:69
KNHdrViewItem
Header view item.
Definition: knhdrviewitem.h:26
KNRemoteArticle::hasNewFollowUps
bool hasNewFollowUps()
Definition: knarticle.h:156
to
QString to() const
subject
QString subject() const
KNAttachment::i_sAttached
bool i_sAttached
Definition: knarticle.h:323
KNRemoteArticle::hasVisibleFollowUps
bool hasVisibleFollowUps()
Definition: knarticle.h:172
locale.h
KNAttachment::setMimeType
void setMimeType(const QString &s)
Definition: knarticle.cpp:341
KNRemoteArticle::type
articleType type() const
Definition: knarticle.h:115
KNAttachment::c_ontent
KMime::Content * c_ontent
Definition: knarticle.h:316
KNLocalArticle::canceled
bool canceled()
Definition: knarticle.h:235
KNGroup::byId
KNRemoteArticle::Ptr byId(int id)
Definition: kngroup.h:122
KNode::Appearance::canceledPosting
Definition: knconfig.h:65
KNode::Appearance::newFups
Definition: knconfig.h:63
knglobals.h
KNLocalArticle::setForceDefaultCharset
virtual void setForceDefaultCharset(bool b)
Definition: knarticle.cpp:286
KNArticle
This class encapsulates a generic article.
Definition: knarticle.h:35
KNRemoteArticle::Ptr
boost::shared_ptr< KNRemoteArticle > Ptr
Shared pointer to a KNRemoteArticle. To be used instead of raw KNRemoteArticle*.
Definition: knarticle.h:107
KNHdrViewItem::art
KNArticle::Ptr art
Definition: knhdrviewitem.h:48
KNLocalArticle::updateListItem
void updateListItem()
Definition: knarticle.cpp:245
settings.h
KNArticle::Ptr
boost::shared_ptr< KNArticle > Ptr
Shared pointer to a KNArticle. To be used instead of raw KNArticle*.
Definition: knarticle.h:39
KNAttachment::contentSize
QString contentSize() const
Definition: knarticle.cpp:360
KNRemoteArticle::idRef
int idRef()
Definition: knarticle.h:142
KNAttachment::setCte
void setCte(int e)
Definition: knarticle.h:301
knarticle.h
KNRemoteArticle::setForceDefaultCharset
virtual void setForceDefaultCharset(bool b)
Definition: knarticle.cpp:201
KNArticle::c_ol
boost::shared_ptr< KNArticleCollection > c_ol
Definition: knarticle.h:88
KNArticleCollection::Ptr
boost::shared_ptr< KNArticleCollection > Ptr
Shared pointer to a KNArticle.
Definition: knarticlecollection.h:82
knconfigmanager.h
KNLocalArticle::~KNLocalArticle
~KNLocalArticle()
Definition: knarticle.cpp:241
KNAttachment::mMimeType
QString mMimeType
Definition: knarticle.h:319
KNAttachment::e_ncoding
KMime::Headers::ContentTransferEncoding e_ncoding
Definition: knarticle.h:322
KNode::Appearance
Ex-Appearance settings.
Definition: knconfig.h:55
KNAttachment::name
const QString & name()
Definition: knarticle.h:288
KNRemoteArticle::isIgnored
bool isIgnored()
Definition: knarticle.h:136
knhdrviewitem.h
KNArticle::setLocked
void setLocked(bool b=true)
Definition: knarticle.cpp:61
knGlobals
#define knGlobals
Keep compatibility with the old way.
Definition: knglobals.h:28
KNAttachment::detach
void detach(KMime::Content *c)
Definition: knarticle.cpp:447
KNode::Appearance::posting
Definition: knconfig.h:64
KNAttachment::~KNAttachment
~KNAttachment()
Definition: knarticle.cpp:333
KNAttachment::f_b64
bool f_b64
Definition: knarticle.h:323
QList
KNGroup::Ptr
boost::shared_ptr< KNGroup > Ptr
Shared pointer to a KNGroup.
Definition: kngroup.h:47
KNode::Appearance::mail
Definition: knconfig.h:64
KNArticle::~KNArticle
~KNArticle()
Definition: knarticle.cpp:39
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal