00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 QString file = locate(
"data",
"knewstuff/types" );
00042
00043 kdDebug() <<
"typedescription file: " << file << endl;
00044
00045 mConfig =
new KConfig( file );
00046 mConfig->setGroup( type );
00047 }
00048
00049 KNewStuffGeneric::~KNewStuffGeneric()
00050 {
00051
delete mConfig;
00052 }
00053
00054
bool KNewStuffGeneric::install(
const QString &fileName )
00055 {
00056 kdDebug(5850) <<
"KNewStuffGeneric::install(): " << fileName << endl;
00057 QStringList list, list2;
00058
00059 QString cmd = mConfig->readEntry(
"InstallationCommand" );
00060
if ( !cmd.isEmpty() ) {
00061 kdDebug(5850) <<
"InstallationCommand: " << cmd << endl;
00062 list = QStringList::split(
" ", cmd );
00063
for ( QStringList::iterator it = list.begin(); it != list.end(); it++ ) {
00064 list2 << (*it).replace(
"%f", fileName);
00065 }
00066 KProcess proc;
00067 proc << list2;
00068 proc.start( KProcess::Block );
00069 }
00070
00071
return true;
00072 }
00073
00074
bool KNewStuffGeneric::createUploadFile(
const QString & )
00075 {
00076
return false;
00077 }
00078
00079 QString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
00080 {
00081 QString target = entry->fullName();
00082 QString res = mConfig->readEntry(
"StandardResource" );
00083
if ( res.isEmpty() )
00084 {
00085 target = mConfig->readEntry(
"TargetDir");
00086
if ( !target.isEmpty())
00087 {
00088 res =
"data";
00089 target.append(
"/" + entry->fullName());
00090 }
00091 }
00092
if ( res.isEmpty() )
return KNewStuff::downloadDestination( entry );
00093
00094 QString file = locateLocal( res.utf8() , target );
00095
if ( KStandardDirs::exists( file ) ) {
00096
int result = KMessageBox::questionYesNo(
parentWidget(),
00097 i18n(
"The file '%1' already exists. Do you want to override it?")
00098 .arg( file ),
00099 QString::null, i18n(
"Overwrite") );
00100
if ( result == KMessageBox::No )
return QString::null;
00101 }
00102
00103
return file;
00104 }