• 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 <tdestandarddirs.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( "Karamba & Superkaramba", 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", tdeApp->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-tar" ||
68  result->name() == "application/x-tarz")
69  {
70  kdDebug() << "SKNewStuff::install() gzip/bzip2 mimetype encountered" <<
71  endl;
72  KTar archive( fileName );
73  if ( !archive.open( IO_ReadOnly ) )
74  return false;
75  const KArchiveDirectory *archiveDir = archive.directory();
76  archiveDir->copyTo(destDir);
77  //Add the theme to the Theme Dialog
78  mDlg->addThemeToDialog(archiveDir, destDir);
79  archive.close();
80  }
81  else if(result->name() == "application/x-zip" ||
82  result->name() == "application/x-superkaramba")
83  {
84  kdDebug() << "SKNewStuff::install() zip mimetype encountered" << endl;
85  //TODO: write a routine to check if this is a valid .skz file
86  //otherwise we need to unpack it like it is an old theme that was packaged
87  //as a .zip instead of .bz2 or .tar.gz
88  KURL sourceFile(fileName);
89  KURL destFile( destDir + sourceFile.fileName() );
90  if(!TDEIO::NetAccess::file_copy( sourceFile, destFile ))
91  {
92  return false;
93  }
94  TDEIO::NetAccess::removeTempFile( sourceFile.url() );
95  //Add the skz theme to the Theme Dialog
96  mDlg->addSkzThemeToDialog(destFile.path());
97  }
98  else if(result->name() == "plain/text")
99  {
100  kdDebug() << "SKNewStuff::install() plain text" << endl;
101  }
102  else if(result->name() == "text/html")
103  {
104  kdDebug() << "SKNewStuff::install() text/html" << endl;
105  KRun::runURL( m_sourceLink, "text/html");
106  }
107  else
108  {
109  kdDebug() << "SKNewStuff::install() Error no compatible mimetype encountered to install"
110  << endl;
111  return false;
112  }
113  return true;
114 }
115 
116 bool SKNewStuff::createUploadFile( const TQString &fileName )
117 {
118  kdDebug() << "SKNewStuff::createUploadFile(): " << fileName << endl;
119  return true;
120 }
121 
122 TQString SKNewStuff::downloadDestination( KNS::Entry *entry )
123 {
124  KURL source = entry->payload();
125  m_sourceLink = source;
126 
127  kdDebug() << "SKNewStuff::downloadDestination() url: "
128  << source.url() << " fileName: " << source.fileName() << endl;
129  TQString file(source.fileName());
130  if ( file.isEmpty() )
131  {
132  kdDebug() << "The file was empty. " << source.url() <<
133  " must be a URL link." << endl;
134  KRun::runURL( source, "text/html");
135  return file;
136  }
137  return TDEGlobal::dirs()->saveLocation( "tmp" ) + source.fileName();
138 }
139 #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.13
This website is maintained by Timothy Pearson.