31 #include <kstandarddirs.h>
35 using namespace KNode;
36 using namespace KNode::Utilities;
41 i_d(-1), p_arentId(-1), i_ndexDirty(false), w_asOpen(true)
49 QString fname=
path()+QString(
"custom_%1").arg(
i_d);
68 QString fname=
path()+QString(
"%1_%2").arg(prefix).arg(
i_d);
102 QString dir( KStandardDirs::locateLocal(
"data",
"knode/folders/" ) );
111 if(infoPath.isEmpty())
116 KConfig info(
i_nfoPath, KConfig::SimpleConfig);
117 KConfigGroup grp(&info, QString());
119 n_ame=grp.readEntry(
"name");
120 i_d=grp.readEntry(
"id", -1);
123 w_asOpen=grp.readEntry(
"wasOpen",
true);
126 QFileInfo fi(infoPath);
127 QString fname = fi.absolutePath() +
'/' + fi.baseName();
149 KConfig info(
i_nfoPath, KConfig::SimpleConfig);
150 KConfigGroup grp(&info, QString());
152 grp.writeEntry(
"name",
n_ame);
153 grp.writeEntry(
"id",
i_d);
157 grp.writeEntry(
"wasOpen",
l_istItem->isExpanded());
172 kDebug(5003) <<
"KNFolder::loadHdrs() : already loaded";
177 kError(5003) <<
"KNFolder::loadHdrs() : cannot open index-file!";
182 if(!
m_boxFile.open(QIODevice::ReadOnly)) {
183 kError(5003) <<
"KNFolder::loadHdrs() : cannot open mbox-file!";
191 int pos1=0, pos2=0, cnt=0, byteCount;
194 knGlobals.setStatusMsg(i18n(
" Loading folder..."));
201 if(byteCount!=
sizeof(
DynData)) {
203 kWarning(5003) <<
"KNFolder::loadHeaders() : found broken entry in index-file: Ignored!";
207 kError(5003) <<
"KNFolder::loadHeaders() : corrupted index-file, IO-error!";
220 if ( !
m_boxFile.seek( art->startOffset() ) ) {
221 kError(5003) <<
"KNFolder::loadHdrs() : cannot set mbox file-pointer!";
227 if ( tmp.endsWith(
'\n' ) )
228 tmp.resize( tmp.length() - 1 );
230 if(
m_boxFile.error() == QFile::NoError ) {
231 kWarning(5003) <<
"found broken entry in mbox-file: Ignored!";
235 kError(5003) <<
"KNFolder::loadHdrs() : corrupted mbox-file, IO-error!";
244 pos1 = tmp.indexOf(
' ' ) + 1;
245 pos2 = tmp.indexOf(
'\t', pos1 );
250 art->subject()->from7BitString(tmp.mid(pos1, pos2-pos1));
254 pos2 = tmp.indexOf(
'\t', pos1 );
259 art->newsgroups()->from7BitString(tmp.mid(pos1, pos2-pos1));
264 pos2 = tmp.indexOf(
'\t', pos1 );
269 art->to()->from7BitString(tmp.mid(pos1,pos2-pos1));
275 art->lines()->from7BitString(tmp.mid(pos1,pos2-pos1));
303 for(
int idx=0; idx<
length(); idx++) {
305 if (a->hasContent() && !
knGlobals.articleManager()->unloadArticle(a, force))
320 if(!
m_boxFile.open(QIODevice::ReadOnly)) {
321 kError(5003) <<
"KNFolder::loadArticle(KNLocalArticle *a) : cannot open mbox file:"
327 if ( !
m_boxFile.seek( a->startOffset() ) ) {
328 kError(5003) <<
"KNFolder::loadArticle(KNLocalArticle *a) : cannot set mbox file-pointer!";
336 unsigned int size = a->endOffset() -
m_boxFile.pos() - 1;
338 buff.resize( size + 10 );
339 int readBytes=
m_boxFile.read(buff.data(), size);
341 if ( readBytes < (
int)(size) &&
m_boxFile.error() != QFile::NoError ) {
342 kError(5003) <<
"KNFolder::loadArticle(KNLocalArticle *a) : corrupted mbox file, IO-error!";
347 buff.resize( readBytes );
360 if(!
m_boxFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
361 kError(5003) <<
"KNFolder::saveArticles() : cannot open mbox-file!";
370 ts.setCodec(
"ISO 8859-1" );
372 for ( KNLocalArticle::List::Iterator it = l.begin(); it != l.end(); ++it ) {
375 if ( (*it)->id() == -1 || (*it)->collection().get() != this ) {
376 if ( (*it)->id() != -1 ) {
378 if ( !(*it)->hasContent() )
379 if( !( clear = oldFolder->loadArticle( (*it) ) ) ) {
386 oldFolder->removeArticles( l,
false );
389 (*it)->setCollection( thisFolderPtr() );
393 if (
byId( (*it)->id() ) == (*it) ) {
396 ts <<
"From aaa@aaa Mon Jan 01 00:00:00 1997\n";
398 (*it)->setStartOffset(
m_boxFile.pos() );
401 ts <<
"X-KNode-Overview: ";
402 ts << (*it)->subject()->as7BitString(
false) <<
'\t';
404 KMime::Headers::Base* h;
405 if( ( h = (*it)->newsgroups(
false ) ) !=0 )
406 ts << h->as7BitString(
false);
409 if( (h = (*it)->to(
false ) ) != 0 )
410 ts << h->as7BitString(
false);
413 ts << (*it)->lines()->as7BitString(
false) <<
'\n';
416 (*it)->toStream( ts );
423 ArticleWidget::articleChanged( (*it) );
428 kError(5003) <<
"KNFolder::saveArticle() : article not in folder!";
433 (*it)->KNLocalArticle::Content::clear();
442 knGlobals.articleManager()->updateViewForCollection( thisFolderPtr() );
455 for (
int idx = 0; idx < l.count(); ++idx ) {
457 if ( a->isLocked() ) {
469 ArticleWindow::closeAllWindowsForArticle( a );
470 ArticleWidget::articleRemoved( a );
471 delete a->listItem();
519 kError(5003) <<
"KNFolder::syncIndex(bool force) : cannot open index-file!";
526 for(
int idx=0; idx<
length(); idx++) {
555 ti=a->date()->dateTime().toTime_t();
557 flags[0]=a->doMail();
558 flags[1]=a->mailed();
559 flags[2]=a->doPost();
560 flags[3]=a->posted();
561 flags[4]=a->canceled();
562 flags[5]=a->editDisabled();
571 a->date()->setDateTime( dt );
572 a->setStartOffset(so);
575 a->setDoMail(flags[0]);
576 a->setMailed(flags[1]);
577 a->setDoPost(flags[2]);
578 a->setPosted(flags[3]);
579 a->setCanceled(flags[4]);
580 a->setEditDisabled(flags[5]);
KNLocalArticle::Ptr at(int i)
boost::shared_ptr< KNLocalArticle > Ptr
Shared pointer to a KNLocalArticle. To be used instead of raw KNLocalArticle*.
bool saveArticles(KNLocalArticle::List &l)
KNCollection::Ptr p_arent
A pointer to the parent collection.
unsigned int lockedArticles()
static KNGlobals * self()
Return the KNGlobals instance.
boost::shared_ptr< KNFolder > Ptr
Shared pointer to a KNFolder.
virtual const QString & name()
Returns the collection name.
bool loadArticle(KNLocalArticle::Ptr a)
Load the full content of an article.
bool unloadHdrs(bool force=true)
This class encapsulates an article, that is stored locally in an MBOX-file.
QString n_ame
The name of this collection.
KNArticleFactory * articleFactory()
Returns the article factory.
KNLocalArticle::Ptr byId(int id)
KNCollectionViewItem * l_istItem
The list view item representing this collection in the folder tree.
void setParent(KNCollection::Ptr p)
Sets the parent collection.
void deleteComposerForArticle(KNLocalArticle::Ptr a)
void setData(KNLocalArticle::Ptr a)
boost::shared_ptr< KNCollection > Ptr
Shared pointer to a KNCollection.
void append(KNArticle::Ptr a)
Appends an article to this collection.
void writeConfig()
Save the properties/settings of this collection.
void removeArticles(KNLocalArticle::List &l, bool del=true)
void getData(KNLocalArticle::Ptr a)
boost::shared_ptr< KNArticleCollection > Ptr
Shared pointer to a KNArticle.
Representation of a folder.
KNFolderManager * folderManager()
Returns the folder manager.
Abstract base class for article collections, ie.
void syncIndex(bool force=false)
This object change the application cursor to a given type and then restore the previous cursor when i...
void updateListItem()
Updates the listview item after the collection has changed.
#define knGlobals
Keep compatibility with the old way.
KNFolder::Ptr folder(int id)