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

superkaramba

  • superkaramba
  • src
sknewstuff.cpp
1 /*
2  * Copyright (C) 2005 Ryan Nickell <p0z3r @ earthlink . net>
3  *
4  * This file is part of SuperKaramba.
5  *
6  * SuperKaramba is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * SuperKaramba 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SuperKaramba; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  ****************************************************************************/
20 
21 #include <tdeapplication.h>
22 #include <kdebug.h>
23 #include <tdefilemetainfo.h>
24 #include <tdeio/netaccess.h>
25 #include <kmimetype.h>
26 #include <krun.h>
27 #include <kstandarddirs.h>
28 #include <ktar.h>
29 #include <kurl.h>
30 #include <tqdir.h>
31 #include <tqfileinfo.h>
32 
33 #ifdef HAVE_CONFIG_H
34  #include <config.h>
35 #endif
36 
37 #include "karambaapp.h"
38 #include "themesdlg.h"
39 #ifdef HAVE_TDENEWSTUFF
40 #include "sknewstuff.h"
41 
42 SKNewStuff::SKNewStuff( ThemesDlg *dlg ) :
43  TDENewStuff( "superkaramba/themes", dlg ),
44  mDlg( dlg )
45 {
46 }
47 
48 bool SKNewStuff::install( const TQString &fileName )
49 {
50  kdDebug() << "SKNewStuff::install(): " << fileName << endl;
51 
52  KMimeType::Ptr result = KMimeType::findByURL(fileName);
53  TDEStandardDirs myStdDir;
54  TQFileInfo fi(fileName);
55  TQString base = fi.baseName();
56  TQString baseDestDir =myStdDir.saveLocation("data", kapp->instanceName() + "/themes/", true);
57  const TQString destDir = baseDestDir + base + "/";
58  TDEStandardDirs::makeDir( destDir );
59 
60  kdDebug() << "SKNewStuff::install() mimetype: " << result->name() << endl;
61 
62  if( result->name() == "application/x-gzip" ||
63  result->name() == "application/x-tgz" ||
64  result->name() == "application/x-bzip" ||
65  result->name() == "application/x-bzip2" ||
66  result->name() == "application/x-tbz" ||
67  result->name() == "application/x-tbz2" ||
68  result->name() == "application/x-tar" ||
69  result->name() == "application/x-tarz")
70  {
71  kdDebug() << "SKNewStuff::install() gzip/bzip2 mimetype encountered" <<
72  endl;
73  KTar archive( fileName );
74  if ( !archive.open( IO_ReadOnly ) )
75  return false;
76  const KArchiveDirectory *archiveDir = archive.directory();
77  archiveDir->copyTo(destDir);
78  //Add the theme to the Theme Dialog
79  mDlg->addThemeToDialog(archiveDir, destDir);
80  archive.close();
81  }
82  else if(result->name() == "application/x-zip" ||
83  result->name() == "application/x-superkaramba")
84  {
85  kdDebug() << "SKNewStuff::install() zip mimetype encountered" << endl;
86  //TODO: write a routine to check if this is a valid .skz file
87  //otherwise we need to unpack it like it is an old theme that was packaged
88  //as a .zip instead of .bz2 or .tar.gz
89  KURL sourceFile(fileName);
90  KURL destFile( destDir + sourceFile.fileName() );
91  if(!TDEIO::NetAccess::file_copy( sourceFile, destFile ))
92  {
93  return false;
94  }
95  TDEIO::NetAccess::removeTempFile( sourceFile.url() );
96  //Add the skz theme to the Theme Dialog
97  mDlg->addSkzThemeToDialog(destFile.path());
98  }
99  else if(result->name() == "plain/text")
100  {
101  kdDebug() << "SKNewStuff::install() plain text" << endl;
102  }
103  else if(result->name() == "text/html")
104  {
105  kdDebug() << "SKNewStuff::install() text/html" << endl;
106  KRun::runURL( m_sourceLink, "text/html");
107  }
108  else
109  {
110  kdDebug() << "SKNewStuff::install() Error no compatible mimetype encountered to install"
111  << endl;
112  return false;
113  }
114  return true;
115 }
116 
117 bool SKNewStuff::createUploadFile( const TQString &fileName )
118 {
119  kdDebug() << "SKNewStuff::createUploadFile(): " << fileName << endl;
120  return true;
121 }
122 
123 TQString SKNewStuff::downloadDestination( KNS::Entry *entry )
124 {
125  KURL source = entry->payload();
126  m_sourceLink = source;
127 
128  kdDebug() << "SKNewStuff::downloadDestination() url: "
129  << source.url() << " fileName: " << source.fileName() << endl;
130  TQString file(source.fileName());
131  if ( file.isEmpty() )
132  {
133  kdDebug() << "The file was empty. " << source.url() <<
134  " must be a URL link." << endl;
135  KRun::runURL( source, "text/html");
136  return file;
137  }
138  return TDEGlobal::dirs()->saveLocation( "tmp" ) + source.fileName();
139 }
140 #endif //HAVE_TDENEWSTUFF

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.8.11
This website is maintained by Timothy Pearson.