kget
autorotatelogjob.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "autorotatelogjob.h"
00021 #include <kurl.h>
00022 #include <util/fileops.h>
00023 #include "log.h"
00024 #include "compressfilejob.h"
00025
00026 namespace bt
00027 {
00028
00029 AutoRotateLogJob::AutoRotateLogJob(const QString & file,Log* lg)
00030 : KIO::Job(),file(file),cnt(10),lg(lg)
00031 {
00032 update();
00033 }
00034
00035
00036 AutoRotateLogJob::~AutoRotateLogJob()
00037 {}
00038
00039 void AutoRotateLogJob::kill(bool)
00040 {
00041 emitResult();
00042 }
00043
00044 void AutoRotateLogJob::update()
00045 {
00046 while (cnt > 1)
00047 {
00048 QString prev = QString("%1-%2.gz").arg(file).arg(cnt - 1);
00049 QString curr = QString("%1-%2.gz").arg(file).arg(cnt);
00050 if (bt::Exists(prev))
00051 {
00052 KIO::Job* sj = KIO::file_move(KUrl(prev),KUrl(curr),-1, KIO::Overwrite | KIO::HideProgressInfo);
00053 connect(sj,SIGNAL(result(KJob*)),this,SLOT(moveJobDone(KJob* )));
00054 return;
00055 }
00056 else
00057 {
00058 cnt--;
00059 }
00060 }
00061
00062 if (cnt == 1)
00063 {
00064
00065 KIO::Job* sj = KIO::file_move(KUrl(file),KUrl(file + "-1"),-1, KIO::Overwrite | KIO::HideProgressInfo);
00066 connect(sj,SIGNAL(result(KJob*)),this,SLOT(moveJobDone(KJob* )));
00067 }
00068 else
00069 {
00070
00071 CompressFileJob* gzip = new CompressFileJob(file + "-1");
00072 connect(gzip,SIGNAL(result(KJob*)),this,SLOT(compressJobDone(KJob*)));
00073 gzip->start();
00074 }
00075 }
00076
00077
00078 void AutoRotateLogJob::moveJobDone(KJob*)
00079 {
00080 cnt--;
00081 update();
00082 }
00083
00084 void AutoRotateLogJob::compressJobDone(KJob*)
00085 {
00086 lg->logRotateDone();
00087 emitResult();
00088 }
00089
00090 }
00091 #include "autorotatelogjob.moc"