TDE core libraries
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.

knewstuffgeneric.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. This file is part of KDE.
  3. Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tqfile.h>
  18. #include <tqtextstream.h>
  19. #include <tqdir.h>
  20. #include <kdebug.h>
  21. #include <tdelocale.h>
  22. #include <kprocess.h>
  23. #include <tdeconfig.h>
  24. #include <kstandarddirs.h>
  25. #include <tdemessagebox.h>
  26. #include <ktar.h>
  27. #include "entry.h"
  28. #include "knewstuffgeneric.h"
  29. using namespace std;
  30. KNewStuffGeneric::KNewStuffGeneric( const TQString &type, TQWidget *parent )
  31. : KNewStuff( type, parent )
  32. {
  33. mConfig = TDEGlobal::config();
  34. }
  35. KNewStuffGeneric::~KNewStuffGeneric()
  36. {
  37. }
  38. bool KNewStuffGeneric::install( const TQString &fileName )
  39. {
  40. kdDebug() << "KNewStuffGeneric::install(): " << fileName << endl;
  41. TQStringList list, list2;
  42. mConfig->setGroup("KNewStuff");
  43. TQString uncompress = mConfig->readEntry( "Uncompress" );
  44. if ( !uncompress.isEmpty() ) {
  45. kdDebug() << "Uncompression method: " << uncompress << endl;
  46. KTar tar(fileName, uncompress);
  47. tar.open(IO_ReadOnly);
  48. const KArchiveDirectory *dir = tar.directory();
  49. dir->copyTo(destinationPath(0));
  50. tar.close();
  51. TQFile::remove(fileName);
  52. }
  53. TQString cmd = mConfig->readEntry( "InstallationCommand" );
  54. if ( !cmd.isEmpty() ) {
  55. kdDebug() << "InstallationCommand: " << cmd << endl;
  56. list = TQStringList::split( " ", cmd );
  57. for ( TQStringList::iterator it = list.begin(); it != list.end(); ++it ) {
  58. list2 << (*it).replace("%f", fileName);
  59. }
  60. TDEProcess proc;
  61. proc << list2;
  62. proc.start( TDEProcess::Block );
  63. }
  64. return true;
  65. }
  66. bool KNewStuffGeneric::createUploadFile( const TQString & /*fileName*/ )
  67. {
  68. return false;
  69. }
  70. TQString KNewStuffGeneric::destinationPath( KNS::Entry *entry )
  71. {
  72. TQString path, file, target, ext;
  73. mConfig->setGroup("KNewStuff");
  74. if ( entry )
  75. {
  76. ext = entry->payload().fileName().section('.', 1);
  77. if ( ! ext.isEmpty() ) ext = "." + ext;
  78. target = entry->fullName() + ext;
  79. }
  80. else target = "/";
  81. TQString res = mConfig->readEntry( "StandardResource" );
  82. if ( res.isEmpty() )
  83. {
  84. target = mConfig->readEntry("TargetDir");
  85. if ( !target.isEmpty())
  86. {
  87. res = "data";
  88. if ( entry ) target.append("/" + entry->fullName() + ext);
  89. else target.append("/");
  90. }
  91. }
  92. if ( res.isEmpty() )
  93. {
  94. path = mConfig->readEntry( "InstallPath" );
  95. }
  96. if ( res.isEmpty() && path.isEmpty() )
  97. {
  98. if ( !entry ) return TQString::null;
  99. else return KNewStuff::downloadDestination( entry );
  100. }
  101. if ( !path.isEmpty() )
  102. {
  103. file = TQDir::home().path() + "/" + path + "/";
  104. if ( entry ) file += entry->fullName() + ext;
  105. }
  106. else file = locateLocal( res.utf8() , target );
  107. return file;
  108. }
  109. TQString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
  110. {
  111. TQString file = destinationPath(entry);
  112. if ( TDEStandardDirs::exists( file ) ) {
  113. int result = KMessageBox::warningContinueCancel( parentWidget(),
  114. i18n("The file '%1' already exists. Do you want to overwrite it?")
  115. .arg( file ),
  116. TQString::null, i18n("Overwrite") );
  117. if ( result == KMessageBox::Cancel ) return TQString::null;
  118. }
  119. return file;
  120. }