23 #include <tqtextstream.h> 30 #include <kstandarddirs.h> 31 #include <kmessagebox.h> 36 #include "knewstuffgeneric.h" 43 mConfig = KGlobal::config();
46 KNewStuffGeneric::~KNewStuffGeneric()
52 kdDebug() <<
"KNewStuffGeneric::install(): " << fileName << endl;
53 TQStringList list, list2;
55 mConfig->setGroup(
"KNewStuff");
57 TQString uncompress = mConfig->readEntry(
"Uncompress" );
58 if ( !uncompress.isEmpty() ) {
59 kdDebug() <<
"Uncompression method: " << uncompress << endl;
60 KTar tar(fileName, uncompress);
61 tar.open(IO_ReadOnly);
62 const KArchiveDirectory *dir = tar.directory();
63 dir->copyTo(destinationPath(0));
65 TQFile::remove(fileName);
68 TQString cmd = mConfig->readEntry(
"InstallationCommand" );
69 if ( !cmd.isEmpty() ) {
70 kdDebug() <<
"InstallationCommand: " << cmd << endl;
71 list = TQStringList::split(
" ", cmd );
72 for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) {
73 list2 << (*it).replace(
"%f", fileName);
77 proc.start( KProcess::Block );
88 TQString KNewStuffGeneric::destinationPath(
KNS::Entry *entry )
90 TQString path, file, target, ext;
92 mConfig->setGroup(
"KNewStuff");
96 ext = entry->
payload().fileName().section(
'.', 1);
97 if ( ! ext.isEmpty() ) ext =
"." + ext;
102 TQString res = mConfig->readEntry(
"StandardResource" );
105 target = mConfig->readEntry(
"TargetDir");
106 if ( !target.isEmpty())
109 if ( entry ) target.append(
"/" + entry->
fullName() + ext);
110 else target.append(
"/");
115 path = mConfig->readEntry(
"InstallPath" );
117 if ( res.isEmpty() && path.isEmpty() )
119 if ( !entry )
return TQString::null;
123 if ( !path.isEmpty() )
125 file = TQDir::home().path() +
"/" + path +
"/";
126 if ( entry ) file += entry->
fullName() + ext;
128 else file = locateLocal( res.utf8() , target );
135 TQString file = destinationPath(entry);
137 if ( KStandardDirs::exists( file ) ) {
138 int result = KMessageBox::warningContinueCancel(
parentWidget(),
139 i18n(
"The file '%1' already exists. Do you want to overwrite it?")
141 TQString::null, i18n(
"Overwrite") );
142 if ( result == KMessageBox::Cancel )
return TQString::null;
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.
KNewStuff data entry container.
TQString downloadDestination(KNS::Entry *entry)
Queries the preferred destination file for a download.
virtual TQString downloadDestination(KNS::Entry *entry)
Return a filename which should be used as destination for downloading the specified new stuff entry...
TQString fullName()
Return the full name for the meta information.
KNewStuffGeneric(const TQString &type, TQWidget *parent=0)
Constructor.
This class provides the functionality to download and upload "new stuff".
bool createUploadFile(const TQString &fileName)
Creates a file suitable for upload.
TQWidget * parentWidget() const
Return parent widget.