kpilot Library API Documentation

fileInstaller.cc

00001 /* fileInstaller.cc                     KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 **
00005 ** This is a class that does "the work" of adding and deleting
00006 ** files in the pending_install directory of KPilot. It is used
00007 ** by the fileInstallWidget and by the daemon's drag-and-drop
00008 ** file accepter.
00009 */
00010 
00011 /*
00012 ** This program is free software; you can redistribute it and/or modify
00013 ** it under the terms of the GNU General Public License as published by
00014 ** the Free Software Foundation; either version 2 of the License, or
00015 ** (at your option) any later version.
00016 **
00017 ** This program is distributed in the hope that it will be useful,
00018 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 ** GNU General Public License for more details.
00021 **
00022 ** You should have received a copy of the GNU General Public License
00023 ** along with this program in a file called COPYING; if not, write to
00024 ** the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
00025 ** MA 02111-1307, USA.
00026 */
00027 
00028 /*
00029 ** Bug reports and questions can be sent to kde-pim@kde.org
00030 */
00031 
00032 static const char *fileinstaller_id =
00033         "$Id: fileInstaller.cc,v 1.4.6.4 2003/03/12 23:31:14 adridg Exp $";
00034 
00035 
00036 #ifndef _KPILOT_OPTIONS_H
00037 #include "options.h"
00038 #endif
00039 
00040 #include <unistd.h>
00041 
00042 #ifndef QSTRING_H
00043 #include <qstring.h>
00044 #endif
00045 #ifndef QSTRLIST_H
00046 #include <qstrlist.h>
00047 #endif
00048 #ifndef QDIR_H
00049 #include <qdir.h>
00050 #endif
00051 
00052 #ifndef _KGLOBAL_H
00053 #include <kglobal.h>
00054 #endif
00055 #ifndef _KSTDDIRS_H
00056 #include <kstddirs.h>
00057 #endif
00058 #ifndef _KURL_H
00059 #include <kurl.h>
00060 #endif
00061 #ifndef _KIO_NETACCESS_H
00062 #include <kio/netaccess.h>
00063 #endif
00064 
00065 #include "fileInstaller.moc"
00066 
00067 FileInstaller::FileInstaller() :
00068         enabled(true)
00069 {
00070         FUNCTIONSETUP;
00071 
00072         fDirName = KGlobal::dirs()->saveLocation("data",
00073                 CSL1("kpilot/pending_install/"));
00074         fPendingCopies = 0;
00075 
00076         (void) fileinstaller_id;
00077 }
00078 
00079 /* virtual */ FileInstaller::~FileInstaller()
00080 {
00081         FUNCTIONSETUP;
00082 }
00083 
00084 
00085 void FileInstaller::clearPending()
00086 {
00087         FUNCTIONSETUP;
00088 
00089         unsigned int i;
00090 
00091         QDir installDir(fDirName);
00092 
00093         // Start from 2 to skip . and ..
00094         //
00095         for (i = 2; i < installDir.count(); i++)
00096         {
00097                 QFile::remove(fDirName + installDir[i]);
00098         }
00099 
00100         if (i > 2)
00101         {
00102                 emit filesChanged();
00103         }
00104 }
00105 
00106 /* virtual */ bool FileInstaller::runCopy(const QString & s)
00107 {
00108         FUNCTIONSETUP;
00109 
00110 #ifdef DEBUG
00111         DEBUGDAEMON << fname << ": Copying " << s << endl;
00112 #endif
00113 
00114         KURL srcName(s);
00115         KURL destDir(fDirName + CSL1("/") + srcName.filename());
00116 
00117         return KIO::NetAccess::copy(srcName, destDir);
00118 }
00119 
00120 
00121 
00122 void FileInstaller::addFiles(QStrList & fileList)
00123 {
00124         FUNCTIONSETUP;
00125 
00126         if (!enabled) return;
00127         
00128         unsigned int i = 0;
00129         unsigned int succ = 0;
00130 
00131         while (i < fileList.count())
00132         {
00133                 if (runCopy(QFile::decodeName(fileList.at(i))))
00134                         succ++;
00135                 i++;
00136         }
00137 
00138         if (succ)
00139         {
00140                 emit filesChanged();
00141         }
00142 }
00143 
00144 void FileInstaller::addFiles(QStringList & fileList)
00145 {
00146         FUNCTIONSETUP;
00147 
00148         if (!enabled) return;
00149         
00150         unsigned int i = 0;
00151         unsigned int succ = 0;
00152 
00153         while (i < fileList.count())
00154         {
00155                 if (runCopy(fileList[i]))
00156                         succ++;
00157                 i++;
00158         }
00159 
00160         if (succ)
00161         {
00162                 emit filesChanged();
00163         }
00164 }
00165 
00166 void FileInstaller::addFile(const QString & file)
00167 {
00168         FUNCTIONSETUP;
00169 
00170         if (!enabled) return;
00171         
00172         if (runCopy(file))
00173         {
00174                 emit(filesChanged());
00175         }
00176 }
00177 
00178 /* slot */ void FileInstaller::copyCompleted()
00179 {
00180         FUNCTIONSETUP;
00181 }
00182 
00183 const QStringList FileInstaller::fileNames() const
00184 {
00185         FUNCTIONSETUP;
00186 
00187         QDir installDir(fDirName);
00188 
00189         return installDir.entryList(QDir::Files |
00190                 QDir::NoSymLinks | QDir::Readable);
00191 }
00192 
00193 /* slot */ void FileInstaller::setEnabled(bool b)
00194 {
00195         FUNCTIONSETUP;
00196         enabled=b;
00197 }
00198 
00199 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:14 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001