23#include <tqtextstream.h> 
   28#include <tdeprocess.h> 
   30#include <tdestandarddirs.h> 
   31#include <tdemessagebox.h> 
   32#include <kmimemagic.h> 
   37#include "knewstuffgeneric.h" 
   44  mConfig = TDEGlobal::config();
 
   47TDENewStuffGeneric::~TDENewStuffGeneric()
 
   55  KMimeMagicResult *res = KMimeMagic::self()->findFileType( fileName );
 
   56  if ( res->isValid() && res->accuracy() > 40 ) {
 
   57    if (
type().lower().contains(
"wallpaper")) {
 
   58      if (!res->mimeType().startsWith(
"image/")) {
 
   59        TQFile::remove(fileName);
 
   65  kdDebug() << 
"TDENewStuffGeneric::install(): " << fileName << endl;
 
   66  TQStringList list, list2;
 
   68  mConfig->setGroup(
"TDENewStuff");
 
   70  TQString uncompress = mConfig->readEntry( 
"Uncompress" );
 
   71  if ( !uncompress.isEmpty() ) {
 
   72    kdDebug() << 
"Uncompression method: " << uncompress << endl;
 
   73    KTar tar(fileName, uncompress);
 
   74    tar.open(IO_ReadOnly);
 
   75    const KArchiveDirectory *dir = tar.directory();
 
   76    dir->copyTo(destinationPath(0));
 
   78    TQFile::remove(fileName);
 
   81  TQString cmd = mConfig->readEntry( 
"InstallationCommand" );
 
   82  if ( !cmd.isEmpty() ) {
 
   83    kdDebug() << 
"InstallationCommand: " << cmd << endl;
 
   84    list = TQStringList::split( 
" ", cmd );
 
   85    for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) {
 
   86        list2 << (*it).replace(
"%f", fileName);
 
   90    proc.start( TDEProcess::Block );
 
  101TQString TDENewStuffGeneric::destinationPath( 
KNS::Entry *entry )
 
  103  TQString path, file, target, ext;
 
  105  mConfig->setGroup(
"TDENewStuff");
 
  109    ext = entry->
payload().fileName().section(
'.', 1);
 
  110    if ( ! ext.isEmpty() ) ext = 
"." + ext;
 
  115  TQString res = mConfig->readEntry( 
"StandardResource" );
 
  118    target = mConfig->readEntry(
"TargetDir");
 
  119    if ( !target.isEmpty())
 
  122      if ( entry ) target.append(
"/" + entry->
fullName() + ext);
 
  123      else target.append(
"/");
 
  128    path = mConfig->readEntry( 
"InstallPath" );
 
  130  if ( res.isEmpty() && path.isEmpty() )
 
  132    if ( !entry ) 
return TQString::null;
 
  136  if ( !path.isEmpty() )
 
  138    file = TQDir::home().path() + 
"/" + path + 
"/";
 
  139    if ( entry ) file += entry->
fullName() + ext;
 
  141  else file = locateLocal( res.utf8() , target );
 
  148  TQString file = destinationPath(entry);
 
  150  if ( TDEStandardDirs::exists( file ) ) {
 
  151    int result = KMessageBox::warningContinueCancel( 
parentWidget(),
 
  152        i18n(
"The file '%1' already exists. Do you want to overwrite it?")
 
  154        TQString::null, i18n(
"Overwrite") );
 
  155    if ( result == KMessageBox::Cancel ) 
return TQString::null;
 
TDENewStuff data entry container.
 
TQString fullName()
Return the full name for the meta information.
 
KURL payload(const TQString &lang=TQString::null) const
Retrieve the file name of the object.
 
bool install(const TQString &fileName)
Installs a downloaded file according to the application's configuration.
 
TQString downloadDestination(KNS::Entry *entry)
Queries the preferred destination file for a download.
 
TDENewStuffGeneric(const TQString &type, TQWidget *parent=0)
Constructor.
 
bool createUploadFile(const TQString &fileName)
Creates a file suitable for upload.
 
This class provides the functionality to download and upload "new stuff".
 
virtual TQString downloadDestination(KNS::Entry *entry)
Return a filename which should be used as destination for downloading the specified new stuff entry.
 
TQString type() const
Return type of data.
 
TQWidget * parentWidget() const
Return parent widget.