knewstuff Library: knewstuffgeneric.cpp Source File (knewstuff Library)

| # knewstuff Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# knewstuffgeneric.cpp

    00001 /*
    00002     This file is part of KDE.
    00003
    00004     Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
    00005
    00006     This library is free software; you can redistribute it and/or
    00007     modify it under the terms of the GNU Library General Public
    00008     License as published by the Free Software Foundation; either
    00009     version 2 of the License, or (at your option) any later version.
    00010
    00011     This library is distributed in the hope that it will be useful,
    00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014     Library General Public License for more details.
    00015
    00016     You should have received a copy of the GNU Library General Public License
    00017     along with this library; see the file COPYING.LIB.  If not, write to
    00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019     Boston, MA 02111-1307, USA.
    00020 */
    00021
    00022 #include <qfile.h>
    00023 #include <qtextstream.h>
    00024 #include <qdir.h>
    00025
    00026 #include <kdebug.h>
    00027 #include <klocale.h>
    00028 #include <kprocess.h>
    00029 #include <kconfig.h>
    00030 #include <kstandarddirs.h>
    00031 #include <kmessagebox.h>
    00032 #include <ktar.h>
    00033
    00034 #include "entry.h"
    00035
    00036 #include "knewstuffgeneric.h"
    00037
    00038 using namespace std;
    00039
    00040 KNewStuffGeneric::KNewStuffGeneric( const QString &type, QWidget *parent )
    00041   : KNewStuff( type, parent )
    00042 {
    00043   mConfig = KGlobal::config();
    00044 }
    00045
    00046 KNewStuffGeneric::~KNewStuffGeneric()
    00047 {
    00048 }
    00049
    00050 bool KNewStuffGeneric::install( const QString &fileName )
    00051 {
    00052   kdDebug(5850) << "KNewStuffGeneric::install(): " << fileName << endl;
    00053   QStringList list, list2;
    00054
    00055   mConfig->setGroup("KNewStuff");
    00056
    00057   QString uncompress = mConfig->readEntry( "Uncompress" );
    00058   if ( !uncompress.isEmpty() ) {
    00059     kdDebug(5850) << "Uncompression method: " << uncompress << endl;
    00060     KTar tar(fileName, uncompress);
    00061     tar.open(IO_ReadOnly);
    00062     const KArchiveDirectory *dir = tar.directory();
    00063     dir->copyTo(destinationPath(0));
    00064     tar.close();
    00065     QFile::remove(fileName);
    00066   }
    00067
    00068   QString cmd = mConfig->readEntry( "InstallationCommand" );
    00069   if ( !cmd.isEmpty() ) {
    00070     kdDebug(5850) << "InstallationCommand: " << cmd << endl;
    00071     list = QStringList::split( " ", cmd );
    00072     for ( QStringList::iterator it = list.begin(); it != list.end(); it++ ) {
    00073         list2 << (*it).replace("%f", fileName);
    00074     }
    00075     KProcess proc;
    00076     proc << list2;
    00077     proc.start( KProcess::Block );
    00078   }
    00079
    00080   return true;
    00081 }
    00082
    00083 bool KNewStuffGeneric::createUploadFile( const QString & /*fileName*/ )
    00084 {
    00085   return false;
    00086 }
    00087
    00088 QString KNewStuffGeneric::destinationPath( KNS::Entry *entry )
    00089 {
    00090   QString path, file, target;
    00091
    00092   mConfig->setGroup("KNewStuff");
    00093
    00094   if( entry ) target = entry->fullName();
    00095   else target = "/";
    00096   QString res = mConfig->readEntry( "StandardResource" );
    00097   if ( res.isEmpty() )
    00098   {
    00099     target = mConfig->readEntry("TargetDir");
    00100     if ( !target.isEmpty())
    00101     {
    00102       res = "data";
    00103       if ( entry ) target.append("/" + entry->fullName());
    00104       else target.append("/");
    00105     }
    00106   }
    00107   if ( res.isEmpty() )
    00108   {
    00109     path = mConfig->readEntry( "InstallPath" );
    00110   }
    00111   if ( res.isEmpty() && path.isEmpty() )
    00112   {
    00113     if ( !entry ) return QString::null;
    00114     else return KNewStuff::downloadDestination( entry );
    00115   }
    00116
    00117   if ( !path.isEmpty() )
    00118   {
    00119     file = QDir::home().path() + "/" + path + "/";
    00120     if ( entry ) file += entry->fullName();
    00121   }
    00122   else file = locateLocal( res.utf8() , target );
    00123
    00124   return file;
    00125 }
    00126
    00127 QString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
    00128 {
    00129   QString file = destinationPath(entry);
    00130
    00131   if ( KStandardDirs::exists( file ) ) {
    00132     int result = KMessageBox::questionYesNo( parentWidget(),
    00133         i18n("The file '%1' already exists. Do you want to override it?")
    00134         .arg( file ),
    00135         QString::null, i18n("Overwrite") );
    00136     if ( result == KMessageBox::No ) return QString::null;
    00137   }
    00138
    00139   return file;
    00140 }

This file is part of the documentation for knewstuff Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:28:34 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003