• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdenetwork
  • Sitemap
  • Contact Us
 

kget

autorotatelogjob.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Joris Guisson                                   *
00003  *   joris.guisson@gmail.com                                               *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.          *
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)) // if file exists start the move job
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             // move current log to 1 and zip it
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             // final log file is moved, now zip it and end the job
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--; // decrease counter so the new file will be moved in update
00081         update(); // don't care about result of job
00082     }
00083     
00084     void AutoRotateLogJob::compressJobDone(KJob*)
00085     {
00086         lg->logRotateDone();
00087         emitResult();
00088     }
00089 
00090 }
00091 #include "autorotatelogjob.moc"

kget

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

kdenetwork

Skip menu "kdenetwork"
  • kget
  • kopete
  •   kopete
  •   libkopete
  •       libpapillon
  • krfb
Generated for kdenetwork by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal