19 #include <QProgressBar>
20 #include <QVBoxLayout>
21 #include <QApplication>
23 #include <QTextStream>
24 #include <QCloseEvent>
27 #include <kmessagebox.h>
28 #include <kseparator.h>
60 for ( KNArticleCollection::List::Iterator it =
mColList.begin(); it !=
mColList.end(); ++it ) {
62 d_lg->
showMessage( i18n(
"Deleting expired articles in <b>%1</b>", (*it)->name() ) );
63 qApp->processEvents();
64 expireGroup( boost::static_pointer_cast<KNGroup>( (*it) ) );
68 d_lg->
showMessage( i18n(
"Compacting folder <b>%1</b>", (*it)->name() ) );
69 qApp->processEvents();
70 compactFolder( boost::static_pointer_cast<KNFolder>( (*it) ) );
90 int expDays=0, idRef=0, foundId=-1, delCnt=0, leftCnt=0, newCnt=0, firstArtNr=g->firstNr(), firstNew=-1;
91 bool unavailable=
false;
96 g->setNotUnloadable(
true);
98 if (!g->isLoaded() && !
knGlobals.groupManager()->loadHeaders(g)) {
99 g->setNotUnloadable(
false);
104 for(
int i=0; i<g->length(); ++i) {
113 unavailable = (art->articleNumber() < firstArtNr);
115 art->setExpired( (art->date()->ageInDays() >= expDays) || unavailable );
120 for(
int i=0; i<g->length(); ++i) {
122 if(!art->isExpired()) {
126 ref->setExpired(
false);
134 for(
int i=0; i<g->length(); ++i) {
136 if(!art->isExpired()) {
139 while(foundId==0 && idRef!=0) {
141 if(!ref->isExpired()) foundId=ref->id();
144 art->setIdRef(foundId);
149 for(
int i=0; i<g->length(); ++i) {
151 if(art->isExpired()) {
155 if (art->hasContent())
156 knGlobals.articleManager()->unloadArticle(art,
true);
158 else if(art->isNew() && !art->isRead()) {
165 g->setNotUnloadable(
false);
168 g->saveStaticData(g->length(),
true);
169 g->saveDynamicData(g->length(),
true);
171 g->setNewCount(newCnt);
172 g->setFirstNewIndex(firstNew);
174 knGlobals.groupManager()->unloadHeaders(g,
true);
177 g->syncDynamicData();
183 kDebug(5003) <<
"KNCleanUp::expireGroup() :" << g->groupname() <<
":"
184 << delCnt <<
"deleted ," << leftCnt <<
"left";
187 KMessageBox::information(
knGlobals.topWidget,
188 i18n(
"<b>%1</b><br />expired: %2<br />left: %3", g->groupname(), delCnt, leftCnt));
204 f->setNotUnloadable(
true);
206 if (!f->isLoaded() && !
knGlobals.folderManager()->loadHeaders(f)) {
207 f->setNotUnloadable(
false);
212 QFileInfo info(f->m_boxFile);
213 QString oldName=info.fileName();
214 QString newName=oldName+
".new";
215 QFile newMBoxFile( info.absolutePath() +
'/' + newName );
217 if( (f->m_boxFile.open(QIODevice::ReadOnly)) && (newMBoxFile.open(QIODevice::WriteOnly)) ) {
218 QTextStream ts(&newMBoxFile);
219 ts.setCodec(
"ISO 8859-1" );
220 for(
int idx=0; idx<f->length(); idx++) {
222 if ( f->m_boxFile.seek( art->startOffset() ) ) {
223 ts <<
"From aaa@aaa Mon Jan 01 00:00:00 1997\n";
225 art->setStartOffset( newMBoxFile.pos() );
226 while ( f->m_boxFile.pos() < (uint)art->endOffset() && !f->m_boxFile.atEnd() )
227 ts << f->m_boxFile.readLine();
229 art->setEndOffset( newMBoxFile.pos() );
230 newMBoxFile.putChar(
'\n');
239 dir.rename(newName, oldName);
242 f->setNotUnloadable(
false);
255 setCaption(i18n(
"Cleaning Up"));
256 setButtons( KDialog::None );
260 top->setGeometry(0,0, w,h);
262 QVBoxLayout *topL=
new QVBoxLayout(top);
263 topL->setSpacing(10);
265 QLabel *l=
new QLabel(i18n(
"Cleaning up. Please wait..."),top);
268 KSeparator *sep=
new KSeparator(top);
269 topL->addWidget(sep);
272 topL->addWidget(
m_sg);
308 mProgressBar->setValue( mProgressBar->value() + 1 );
boost::shared_ptr< KNLocalArticle > Ptr
Shared pointer to a KNLocalArticle. To be used instead of raw KNLocalArticle*.
void expireGroup(KNGroup::Ptr g, bool showResult=false)
int maxAgeForRead() const
KNArticleCollection::List mColList
QProgressBar * mProgressBar
void compactFolder(KNFolder::Ptr f)
Compacts the given folder, ie.
Expirery/cleaup settings (globally or per account/group/folder).
boost::shared_ptr< KNFolder > Ptr
Shared pointer to a KNFolder.
void doProgress()
Increments the progress counter by one.
int maxAgeForUnread() const
bool preserveThreads() const
void closeEvent(QCloseEvent *e)
bool removeUnavailable() const
boost::shared_ptr< KNRemoteArticle > Ptr
Shared pointer to a KNRemoteArticle. To be used instead of raw KNRemoteArticle*.
void showMessage(const QString &s)
Shows a message in the progress dialog.
ProgressDialog(int steps, QWidget *parent=0)
Creates a new progress dialog.
#define knGlobals
Keep compatibility with the old way.
boost::shared_ptr< KNGroup > Ptr
Shared pointer to a KNGroup.