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