kpilot/kpilot

fileInstaller.cc

00001 /* 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., 51 Franklin Street, Fifth Floor, Boston,
00025 ** MA 02110-1301, 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 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 /* virtual */ 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     // Start from 2 to skip . and ..
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 /* virtual */ 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 /* slot */ 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 /* slot */ void FileInstaller::setEnabled(bool b)
00183 {
00184     FUNCTIONSETUP;
00185     enabled=b;
00186 }
00187 
00188 
KDE Home | KDE Accessibility Home | Description of Access Keys