kpilot/kpilot
fileInstaller.cc00001
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 437980 2005-07-23 19:53:57Z kainhofe $";
00034
00035
00036 #include "options.h"
00037
00038 #include <unistd.h>
00039
00040 #include <qstring.h>
00041 #include <qstrlist.h>
00042 #include <qdir.h>
00043
00044 #include <kglobal.h>
00045 #include <kstandarddirs.h>
00046 #include <kurl.h>
00047 #include <kio/netaccess.h>
00048 #include <kmessagebox.h>
00049
00050 #include "fileInstaller.moc"
00051
00052 FileInstaller::FileInstaller() :
00053 enabled(true)
00054 {
00055 FUNCTIONSETUP;
00056
00057 fDirName = KGlobal::dirs()->saveLocation("data",
00058 CSL1("kpilot/pending_install/"));
00059 fPendingCopies = 0;
00060
00061 (void) fileinstaller_id;
00062 }
00063
00064 FileInstaller::~FileInstaller()
00065 {
00066 FUNCTIONSETUP;
00067 }
00068
00069
00070 void FileInstaller::clearPending()
00071 {
00072 FUNCTIONSETUP;
00073
00074 unsigned int i;
00075
00076 QDir installDir(fDirName);
00077
00078
00079
00080 for (i = 2; i < installDir.count(); i++)
00081 {
00082 QFile::remove(fDirName + installDir[i]);
00083 }
00084
00085 if (i > 2)
00086 {
00087 emit filesChanged();
00088 }
00089 }
00090
00091 void FileInstaller::deleteFile(const QString &file)
00092 {
00093 QFile::remove(fDirName + file);
00094 emit filesChanged();
00095 }
00096
00097 void FileInstaller::deleteFiles(const QStringList &files)
00098 {
00099 if(files.empty())
00100 return;
00101
00102 for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it)
00103 QFile::remove(fDirName + *it);
00104
00105 emit filesChanged();
00106 }
00107
00108 bool FileInstaller::runCopy(const QString & s, QWidget* w )
00109 {
00110 FUNCTIONSETUP;
00111
00112 if(!(s.endsWith(CSL1(".pdb"), false) || s.endsWith(CSL1(".prc"), false))) {
00113 KMessageBox::detailedSorry(w, i18n("Cannot install %1").arg(s),
00114 i18n("Only PalmOS database files (like *.pdb and *.prc) can be installed by the file installer."));
00115 return false;
00116 }
00117
00118 #ifdef DEBUG
00119 DEBUGDAEMON << fname << ": Copying " << s << endl;
00120 #endif
00121
00122 KURL srcName;
00123 srcName.setPath(s);
00124 KURL destDir(fDirName + CSL1("/") + srcName.fileName());
00125
00126 #if KDE_IS_VERSION(3,1,9)
00127 return KIO::NetAccess::copy(srcName, destDir, w);
00128 #else
00129 return KIO::NetAccess::copy(srcName,destDir);
00130 #endif
00131 }
00132
00133
00134 void FileInstaller::addFiles(const QStringList & fileList, QWidget* w)
00135 {
00136 FUNCTIONSETUP;
00137
00138 if (!enabled) return;
00139
00140 unsigned int succ = 0;
00141
00142 for(QStringList::ConstIterator it = fileList.begin();
00143 it != fileList.end(); ++it)
00144 {
00145 if (runCopy( *it, w ))
00146 succ++;
00147 }
00148
00149 if (succ)
00150 {
00151 emit filesChanged();
00152 }
00153 }
00154
00155 void FileInstaller::addFile( const QString & file, QWidget* w )
00156 {
00157 FUNCTIONSETUP;
00158
00159 if (!enabled) return;
00160
00161 if (runCopy(file, w))
00162 {
00163 emit(filesChanged());
00164 }
00165 }
00166
00167 void FileInstaller::copyCompleted()
00168 {
00169 FUNCTIONSETUP;
00170 }
00171
00172 const QStringList FileInstaller::fileNames() const
00173 {
00174 FUNCTIONSETUP;
00175
00176 QDir installDir(fDirName);
00177
00178 return installDir.entryList(QDir::Files |
00179 QDir::NoSymLinks | QDir::Readable);
00180 }
00181
00182 void FileInstaller::setEnabled(bool b)
00183 {
00184 FUNCTIONSETUP;
00185 enabled=b;
00186 }
00187
00188
|