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
#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 & )
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 }