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

tdenewstuff

  • tdenewstuff
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 <tdelocale.h>
28#include <tdeprocess.h>
29#include <tdeconfig.h>
30#include <tdestandarddirs.h>
31#include <tdemessagebox.h>
32#include <kmimemagic.h>
33#include <ktar.h>
34
35#include "entry.h"
36
37#include "knewstuffgeneric.h"
38
39using namespace std;
40
41TDENewStuffGeneric::TDENewStuffGeneric( const TQString &type, TQWidget *parent )
42 : TDENewStuff( type, parent )
43{
44 mConfig = TDEGlobal::config();
45}
46
47TDENewStuffGeneric::~TDENewStuffGeneric()
48{
49}
50
51bool TDENewStuffGeneric::install( const TQString &fileName )
52{
53 // Try to detect the most common cases where (usually adware) Web pages are downloaded
54 // instead of the desired file and abort
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);
60 return false;
61 }
62 }
63}
64
65 kdDebug() << "TDENewStuffGeneric::install(): " << fileName << endl;
66 TQStringList list, list2;
67
68 mConfig->setGroup("TDENewStuff");
69
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));
77 tar.close();
78 TQFile::remove(fileName);
79 }
80
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);
87 }
88 TDEProcess proc;
89 proc << list2;
90 proc.start( TDEProcess::Block );
91 }
92
93 return true;
94}
95
96bool TDENewStuffGeneric::createUploadFile( const TQString & /*fileName*/ )
97{
98 return false;
99}
100
101TQString TDENewStuffGeneric::destinationPath( KNS::Entry *entry )
102{
103 TQString path, file, target, ext;
104
105 mConfig->setGroup("TDENewStuff");
106
107 if ( entry )
108 {
109 ext = entry->payload().fileName().section('.', 1);
110 if ( ! ext.isEmpty() ) ext = "." + ext;
111
112 target = entry->fullName() + ext;
113 }
114 else target = "/";
115 TQString res = mConfig->readEntry( "StandardResource" );
116 if ( res.isEmpty() )
117 {
118 target = mConfig->readEntry("TargetDir");
119 if ( !target.isEmpty())
120 {
121 res = "data";
122 if ( entry ) target.append("/" + entry->fullName() + ext);
123 else target.append("/");
124 }
125 }
126 if ( res.isEmpty() )
127 {
128 path = mConfig->readEntry( "InstallPath" );
129 }
130 if ( res.isEmpty() && path.isEmpty() )
131 {
132 if ( !entry ) return TQString::null;
133 else return TDENewStuff::downloadDestination( entry );
134 }
135
136 if ( !path.isEmpty() )
137 {
138 file = TQDir::home().path() + "/" + path + "/";
139 if ( entry ) file += entry->fullName() + ext;
140 }
141 else file = locateLocal( res.utf8() , target );
142
143 return file;
144}
145
146TQString TDENewStuffGeneric::downloadDestination( KNS::Entry *entry )
147{
148 TQString file = destinationPath(entry);
149
150 if ( TDEStandardDirs::exists( file ) ) {
151 int result = KMessageBox::warningContinueCancel( parentWidget(),
152 i18n("The file '%1' already exists. Do you want to overwrite it?")
153 .arg( file ),
154 TQString::null, i18n("Overwrite") );
155 if ( result == KMessageBox::Cancel ) return TQString::null;
156 }
157
158 return file;
159}
KNS::Entry
TDENewStuff data entry container.
Definition: entry.h:46
KNS::Entry::fullName
TQString fullName()
Return the full name for the meta information.
Definition: entry.cpp:288
KNS::Entry::payload
KURL payload(const TQString &lang=TQString::null) const
Retrieve the file name of the object.
Definition: entry.cpp:228
TDENewStuffGeneric::install
bool install(const TQString &fileName)
Installs a downloaded file according to the application's configuration.
Definition: knewstuffgeneric.cpp:51
TDENewStuffGeneric::downloadDestination
TQString downloadDestination(KNS::Entry *entry)
Queries the preferred destination file for a download.
Definition: knewstuffgeneric.cpp:146
TDENewStuffGeneric::TDENewStuffGeneric
TDENewStuffGeneric(const TQString &type, TQWidget *parent=0)
Constructor.
Definition: knewstuffgeneric.cpp:41
TDENewStuffGeneric::createUploadFile
bool createUploadFile(const TQString &fileName)
Creates a file suitable for upload.
Definition: knewstuffgeneric.cpp:96
TDENewStuff
This class provides the functionality to download and upload "new stuff".
Definition: knewstuff.h:70
TDENewStuff::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
TDENewStuff::type
TQString type() const
Return type of data.
Definition: knewstuff.cpp:52
TDENewStuff::parentWidget
TQWidget * parentWidget() const
Return parent widget.
Definition: knewstuff.cpp:57

tdenewstuff

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

tdenewstuff

Skip menu "tdenewstuff"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdenewstuff by doxygen 1.9.4
This website is maintained by Timothy Pearson.