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.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 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)
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 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 void FileInstaller::setEnabled(bool b)
00194 {
00195 FUNCTIONSETUP;
00196 enabled=b;
00197 }
00198
00199
This file is part of the documentation for kdelibs Version 3.1.5.