• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • knewstuff
 

knewstuff

  • knewstuff
knewstuffgeneric.cpp
1 /*
2  This file is part of KDE.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include <tqfile.h>
23 #include <tqtextstream.h>
24 #include <tqdir.h>
25 
26 #include <kdebug.h>
27 #include <klocale.h>
28 #include <kprocess.h>
29 #include <kconfig.h>
30 #include <kstandarddirs.h>
31 #include <kmessagebox.h>
32 #include <ktar.h>
33 
34 #include "entry.h"
35 
36 #include "knewstuffgeneric.h"
37 
38 using namespace std;
39 
40 KNewStuffGeneric::KNewStuffGeneric( const TQString &type, TQWidget *parent )
41  : KNewStuff( type, parent )
42 {
43  mConfig = KGlobal::config();
44 }
45 
46 KNewStuffGeneric::~KNewStuffGeneric()
47 {
48 }
49 
50 bool KNewStuffGeneric::install( const TQString &fileName )
51 {
52  kdDebug() << "KNewStuffGeneric::install(): " << fileName << endl;
53  TQStringList list, list2;
54 
55  mConfig->setGroup("KNewStuff");
56 
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));
64  tar.close();
65  TQFile::remove(fileName);
66  }
67 
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);
74  }
75  KProcess proc;
76  proc << list2;
77  proc.start( KProcess::Block );
78  }
79 
80  return true;
81 }
82 
83 bool KNewStuffGeneric::createUploadFile( const TQString & /*fileName*/ )
84 {
85  return false;
86 }
87 
88 TQString KNewStuffGeneric::destinationPath( KNS::Entry *entry )
89 {
90  TQString path, file, target, ext;
91 
92  mConfig->setGroup("KNewStuff");
93 
94  if ( entry )
95  {
96  ext = entry->payload().fileName().section('.', 1);
97  if ( ! ext.isEmpty() ) ext = "." + ext;
98 
99  target = entry->fullName() + ext;
100  }
101  else target = "/";
102  TQString res = mConfig->readEntry( "StandardResource" );
103  if ( res.isEmpty() )
104  {
105  target = mConfig->readEntry("TargetDir");
106  if ( !target.isEmpty())
107  {
108  res = "data";
109  if ( entry ) target.append("/" + entry->fullName() + ext);
110  else target.append("/");
111  }
112  }
113  if ( res.isEmpty() )
114  {
115  path = mConfig->readEntry( "InstallPath" );
116  }
117  if ( res.isEmpty() && path.isEmpty() )
118  {
119  if ( !entry ) return TQString::null;
120  else return KNewStuff::downloadDestination( entry );
121  }
122 
123  if ( !path.isEmpty() )
124  {
125  file = TQDir::home().path() + "/" + path + "/";
126  if ( entry ) file += entry->fullName() + ext;
127  }
128  else file = locateLocal( res.utf8() , target );
129 
130  return file;
131 }
132 
133 TQString KNewStuffGeneric::downloadDestination( KNS::Entry *entry )
134 {
135  TQString file = destinationPath(entry);
136 
137  if ( KStandardDirs::exists( file ) ) {
138  int result = KMessageBox::warningContinueCancel( parentWidget(),
139  i18n("The file '%1' already exists. Do you want to overwrite it?")
140  .arg( file ),
141  TQString::null, i18n("Overwrite") );
142  if ( result == KMessageBox::Cancel ) return TQString::null;
143  }
144 
145  return file;
146 }
KNewStuffGeneric::install
bool install(const TQString &fileName)
Installs a downloaded file according to the application's configuration.
Definition: knewstuffgeneric.cpp:50
KNS::Entry
KNewStuff data entry container.
Definition: entry.h:44
std
KNewStuffGeneric::downloadDestination
TQString downloadDestination(KNS::Entry *entry)
Queries the preferred destination file for a download.
Definition: knewstuffgeneric.cpp:133
KNewStuff::downloadDestination
virtual TQString downloadDestination(KNS::Entry *entry)
Return a filename which should be used as destination for downloading the specified new stuff entry...
Definition: knewstuff.cpp:72
KNS::Entry::fullName
TQString fullName()
Return the full name for the meta information.
Definition: entry.cpp:287
KNewStuff::parentWidget
TQWidget * parentWidget() const
Return parent widget.
Definition: knewstuff.cpp:57
KNewStuffGeneric::KNewStuffGeneric
KNewStuffGeneric(const TQString &type, TQWidget *parent=0)
Constructor.
Definition: knewstuffgeneric.cpp:40
KNewStuff
This class provides the functionality to download and upload "new stuff".
Definition: knewstuff.h:69
KNewStuffGeneric::createUploadFile
bool createUploadFile(const TQString &fileName)
Creates a file suitable for upload.
Definition: knewstuffgeneric.cpp:83
KNS::Entry::payload
KURL payload(const TQString &lang=TQString::null) const
Retrieve the file name of the object.
Definition: entry.cpp:227

knewstuff

Skip menu "knewstuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

knewstuff

Skip menu "knewstuff"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for knewstuff by doxygen 1.8.8
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |