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.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 /* 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, 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 /* slot */ 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 /* slot */ void FileInstaller::setEnabled(bool b) 00174 { 00175 FUNCTIONSETUP; 00176 enabled=b; 00177 } 00178 00179
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:57:48 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003