knewstuff Library API Documentation

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 
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027 #include <kprocess.h>
00028 #include <kconfig.h>
00029 #include <kstandarddirs.h>
00030 #include <kmessagebox.h>
00031 
00032 #include "entry.h"
00033 
00034 #include "knewstuffgeneric.h"
00035 
00036 using namespace std;
00037 
00038 KNewStuffGeneric::KNewStuffGeneric( const QString &type, QWidget *parent )
00039   : KNewStuff( type, parent )
00040 {
00041   mConfig = KGlobal::config();
00042   mConfig->setGroup("KNewStuff");
00043 }
00044 
00045 KNewStuffGeneric::~KNewStuffGeneric()
00046 {
00047 }
00048 
00049 bool KNewStuffGeneric::install( const QString &fileName )
00050 {
00051   kdDebug(5850) << "KNewStuffGeneric::install(): " << fileName << endl;
00052   QStringList list, list2;
00053 
00054   QString cmd = mConfig->readEntry( "InstallationCommand" );
00055   if ( !cmd.isEmpty() ) {
00056     kdDebug(5850) << "InstallationCommand: " << cmd << endl;
00057     list = QStringList::split( " ", cmd );
00058     for ( QStringList::iterator it = list.begin(); it != list.end(); it++ ) {
00059         list2 << (*it).replace("%f", fileName);
00060     }
00061     KProcess proc;
00062     proc << list2;
00063     proc.start( KProcess::Block );
00064   }
00065 
00066   return true;
00067 }
00068 
00069 bool KNewStuffGeneric::createUploadFile( const QString & /*fileName*/ )
00070 {
00071   return false;
00072 }
00073 
00074 QString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
00075 {
00076   QString target = entry->fullName();
00077   QString res = mConfig->readEntry( "StandardResource" );
00078   if ( res.isEmpty() )
00079   {
00080     target = mConfig->readEntry("TargetDir");
00081     if ( !target.isEmpty())
00082     {
00083       res = "data";
00084       target.append("/" + entry->fullName());
00085     }
00086   }
00087   if ( res.isEmpty() ) return KNewStuff::downloadDestination( entry );
00088 
00089   QString file = locateLocal( res.utf8() , target );
00090   if ( KStandardDirs::exists( file ) ) {
00091     int result = KMessageBox::questionYesNo( parentWidget(),
00092         i18n("The file '%1' already exists. Do you want to override it?")
00093         .arg( file ),
00094         QString::null, i18n("Overwrite") );
00095     if ( result == KMessageBox::No ) return QString::null;
00096   }
00097 
00098   return file;
00099 }
KDE Logo
This file is part of the documentation for knewstuff Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:19:01 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003