• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KNewStuff

knewstuffgeneric.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, 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() << "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() << "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() << "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, ext;
00091 
00092   mConfig->setGroup("KNewStuff");
00093 
00094   if ( entry )
00095   {
00096     ext = entry->payload().fileName().section('.', 1);
00097     if ( ! ext.isEmpty() ) ext = "." + ext;
00098 
00099     target = entry->fullName() + ext;
00100   }
00101   else target = "/";
00102   QString res = mConfig->readEntry( "StandardResource" );
00103   if ( res.isEmpty() )
00104   {
00105     target = mConfig->readEntry("TargetDir");
00106     if ( !target.isEmpty())
00107     {
00108       res = "data";
00109       if ( entry ) target.append("/" + entry->fullName() + ext);
00110       else target.append("/");
00111     }
00112   }
00113   if ( res.isEmpty() )
00114   {
00115     path = mConfig->readEntry( "InstallPath" );
00116   }
00117   if ( res.isEmpty() && path.isEmpty() )
00118   {
00119     if ( !entry ) return QString::null;
00120     else return KNewStuff::downloadDestination( entry );
00121   }
00122 
00123   if ( !path.isEmpty() )
00124   {
00125     file = QDir::home().path() + "/" + path + "/";
00126     if ( entry ) file += entry->fullName() + ext;
00127   }
00128   else file = locateLocal( res.utf8() , target );
00129 
00130   return file;
00131 }
00132 
00133 QString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
00134 {
00135   QString file = destinationPath(entry);
00136 
00137   if ( KStandardDirs::exists( file ) ) {
00138     int result = KMessageBox::warningContinueCancel( parentWidget(),
00139         i18n("The file '%1' already exists. Do you want to overwrite it?")
00140         .arg( file ),
00141         QString::null, i18n("Overwrite") );
00142     if ( result == KMessageBox::Cancel ) return QString::null;
00143   }
00144 
00145   return file;
00146 }

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal