You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.9 KiB
147 lines
3.9 KiB
15 years ago
|
/*
|
||
|
This file is part of KDE.
|
||
|
|
||
|
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqfile.h>
|
||
13 years ago
|
#include <tqtextstream.h>
|
||
15 years ago
|
#include <tqdir.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <kprocess.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <ktar.h>
|
||
|
|
||
|
#include "entry.h"
|
||
|
|
||
|
#include "knewstuffgeneric.h"
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
10 years ago
|
TDENewStuffGeneric::TDENewStuffGeneric( const TQString &type, TQWidget *parent )
|
||
|
: TDENewStuff( type, parent )
|
||
15 years ago
|
{
|
||
12 years ago
|
mConfig = TDEGlobal::config();
|
||
15 years ago
|
}
|
||
|
|
||
10 years ago
|
TDENewStuffGeneric::~TDENewStuffGeneric()
|
||
15 years ago
|
{
|
||
|
}
|
||
|
|
||
10 years ago
|
bool TDENewStuffGeneric::install( const TQString &fileName )
|
||
15 years ago
|
{
|
||
10 years ago
|
kdDebug() << "TDENewStuffGeneric::install(): " << fileName << endl;
|
||
15 years ago
|
TQStringList list, list2;
|
||
15 years ago
|
|
||
10 years ago
|
mConfig->setGroup("TDENewStuff");
|
||
15 years ago
|
|
||
15 years ago
|
TQString uncompress = mConfig->readEntry( "Uncompress" );
|
||
15 years ago
|
if ( !uncompress.isEmpty() ) {
|
||
|
kdDebug() << "Uncompression method: " << uncompress << endl;
|
||
|
KTar tar(fileName, uncompress);
|
||
|
tar.open(IO_ReadOnly);
|
||
|
const KArchiveDirectory *dir = tar.directory();
|
||
|
dir->copyTo(destinationPath(0));
|
||
|
tar.close();
|
||
15 years ago
|
TQFile::remove(fileName);
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString cmd = mConfig->readEntry( "InstallationCommand" );
|
||
15 years ago
|
if ( !cmd.isEmpty() ) {
|
||
|
kdDebug() << "InstallationCommand: " << cmd << endl;
|
||
15 years ago
|
list = TQStringList::split( " ", cmd );
|
||
|
for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) {
|
||
14 years ago
|
list2 << (*it).replace("%f", fileName);
|
||
15 years ago
|
}
|
||
12 years ago
|
TDEProcess proc;
|
||
15 years ago
|
proc << list2;
|
||
12 years ago
|
proc.start( TDEProcess::Block );
|
||
15 years ago
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
10 years ago
|
bool TDENewStuffGeneric::createUploadFile( const TQString & /*fileName*/ )
|
||
15 years ago
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
10 years ago
|
TQString TDENewStuffGeneric::destinationPath( KNS::Entry *entry )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString path, file, target, ext;
|
||
15 years ago
|
|
||
10 years ago
|
mConfig->setGroup("TDENewStuff");
|
||
15 years ago
|
|
||
|
if ( entry )
|
||
|
{
|
||
|
ext = entry->payload().fileName().section('.', 1);
|
||
|
if ( ! ext.isEmpty() ) ext = "." + ext;
|
||
|
|
||
|
target = entry->fullName() + ext;
|
||
|
}
|
||
|
else target = "/";
|
||
15 years ago
|
TQString res = mConfig->readEntry( "StandardResource" );
|
||
15 years ago
|
if ( res.isEmpty() )
|
||
|
{
|
||
|
target = mConfig->readEntry("TargetDir");
|
||
|
if ( !target.isEmpty())
|
||
|
{
|
||
|
res = "data";
|
||
|
if ( entry ) target.append("/" + entry->fullName() + ext);
|
||
|
else target.append("/");
|
||
|
}
|
||
|
}
|
||
|
if ( res.isEmpty() )
|
||
|
{
|
||
|
path = mConfig->readEntry( "InstallPath" );
|
||
|
}
|
||
|
if ( res.isEmpty() && path.isEmpty() )
|
||
|
{
|
||
15 years ago
|
if ( !entry ) return TQString::null;
|
||
10 years ago
|
else return TDENewStuff::downloadDestination( entry );
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( !path.isEmpty() )
|
||
|
{
|
||
15 years ago
|
file = TQDir::home().path() + "/" + path + "/";
|
||
15 years ago
|
if ( entry ) file += entry->fullName() + ext;
|
||
|
}
|
||
|
else file = locateLocal( res.utf8() , target );
|
||
|
|
||
|
return file;
|
||
|
}
|
||
|
|
||
10 years ago
|
TQString TDENewStuffGeneric::downloadDestination( KNS::Entry *entry )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString file = destinationPath(entry);
|
||
15 years ago
|
|
||
12 years ago
|
if ( TDEStandardDirs::exists( file ) ) {
|
||
14 years ago
|
int result = KMessageBox::warningContinueCancel( parentWidget(),
|
||
15 years ago
|
i18n("The file '%1' already exists. Do you want to overwrite it?")
|
||
|
.arg( file ),
|
||
15 years ago
|
TQString::null, i18n("Overwrite") );
|
||
|
if ( result == KMessageBox::Cancel ) return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
return file;
|
||
|
}
|