fileInstaller.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 static const char *fileinstaller_id =
00033 "$Id: fileInstaller.cc,v 1.12 2003/11/18 23:47:50 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 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
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 bool FileInstaller::runCopy(const QString & s, QWidget* w )
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 #if KDE_IS_VERSION(3,1,9)
00118 return KIO::NetAccess::copy(srcName, destDir, w);
00119 #else
00120 return KIO::NetAccess::copy(srcName,destDir);
00121 #endif
00122 }
00123
00124
00125 void FileInstaller::addFiles(const QStringList & fileList, QWidget* w)
00126 {
00127 FUNCTIONSETUP;
00128
00129 if (!enabled) return;
00130
00131 unsigned int succ = 0;
00132
00133 for(QStringList::ConstIterator it = fileList.begin();
00134 it != fileList.end(); ++it)
00135 {
00136 if (runCopy( *it, w ))
00137 succ++;
00138 }
00139
00140 if (succ)
00141 {
00142 emit filesChanged();
00143 }
00144 }
00145
00146 void FileInstaller::addFile( const QString & file, QWidget* w )
00147 {
00148 FUNCTIONSETUP;
00149
00150 if (!enabled) return;
00151
00152 if (runCopy(file, w))
00153 {
00154 emit(filesChanged());
00155 }
00156 }
00157
00158 void FileInstaller::copyCompleted()
00159 {
00160 FUNCTIONSETUP;
00161 }
00162
00163 const QStringList FileInstaller::fileNames() const
00164 {
00165 FUNCTIONSETUP;
00166
00167 QDir installDir(fDirName);
00168
00169 return installDir.entryList(QDir::Files |
00170 QDir::NoSymLinks | QDir::Readable);
00171 }
00172
00173 void FileInstaller::setEnabled(bool b)
00174 {
00175 FUNCTIONSETUP;
00176 enabled=b;
00177 }
00178
00179
This file is part of the documentation for kpilot Library Version 3.2.2.