sknewstuff.cpp
00001 /* 00002 * Copyright (C) 2005 Ryan Nickell <p0z3r @ earthlink . net> 00003 * 00004 * This file is part of SuperKaramba. 00005 * 00006 * SuperKaramba is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * SuperKaramba is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with SuperKaramba; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 ****************************************************************************/ 00020 00021 #include <kapplication.h> 00022 #include <kdebug.h> 00023 #include <kfilemetainfo.h> 00024 #include <kio/netaccess.h> 00025 #include <kmimetype.h> 00026 #include <krun.h> 00027 #include <kstandarddirs.h> 00028 #include <ktar.h> 00029 #include <kurl.h> 00030 #include <tqdir.h> 00031 #include <tqfileinfo.h> 00032 00033 #ifdef HAVE_CONFIG_H 00034 #include <config.h> 00035 #endif 00036 00037 #include "karambaapp.h" 00038 #include "themesdlg.h" 00039 #ifdef HAVE_KNEWSTUFF 00040 #include "sknewstuff.h" 00041 00042 SKNewStuff::SKNewStuff( ThemesDlg *dlg ) : 00043 KNewStuff( "superkaramba/themes", dlg ), 00044 mDlg( dlg ) 00045 { 00046 } 00047 00048 bool SKNewStuff::install( const TQString &fileName ) 00049 { 00050 kdDebug() << "SKNewStuff::install(): " << fileName << endl; 00051 00052 KMimeType::Ptr result = KMimeType::findByURL(fileName); 00053 KStandardDirs myStdDir; 00054 TQFileInfo fi(fileName); 00055 TQString base = fi.baseName(); 00056 TQString baseDestDir =myStdDir.saveLocation("data", kapp->instanceName() + "/themes/", true); 00057 const TQString destDir = baseDestDir + base + "/"; 00058 KStandardDirs::makeDir( destDir ); 00059 00060 kdDebug() << "SKNewStuff::install() mimetype: " << result->name() << endl; 00061 00062 if( result->name() == "application/x-gzip" || 00063 result->name() == "application/x-tgz" || 00064 result->name() == "application/x-bzip" || 00065 result->name() == "application/x-bzip2" || 00066 result->name() == "application/x-tbz" || 00067 result->name() == "application/x-tbz2" || 00068 result->name() == "application/x-tar" || 00069 result->name() == "application/x-tarz") 00070 { 00071 kdDebug() << "SKNewStuff::install() gzip/bzip2 mimetype encountered" << 00072 endl; 00073 KTar archive( fileName ); 00074 if ( !archive.open( IO_ReadOnly ) ) 00075 return false; 00076 const KArchiveDirectory *archiveDir = archive.directory(); 00077 archiveDir->copyTo(destDir); 00078 //Add the theme to the Theme Dialog 00079 mDlg->addThemeToDialog(archiveDir, destDir); 00080 archive.close(); 00081 } 00082 else if(result->name() == "application/x-zip" || 00083 result->name() == "application/x-superkaramba") 00084 { 00085 kdDebug() << "SKNewStuff::install() zip mimetype encountered" << endl; 00086 //TODO: write a routine to check if this is a valid .skz file 00087 //otherwise we need to unpack it like it is an old theme that was packaged 00088 //as a .zip instead of .bz2 or .tar.gz 00089 KURL sourceFile(fileName); 00090 KURL destFile( destDir + sourceFile.fileName() ); 00091 if(!KIO::NetAccess::file_copy( sourceFile, destFile )) 00092 { 00093 return false; 00094 } 00095 KIO::NetAccess::removeTempFile( sourceFile.url() ); 00096 //Add the skz theme to the Theme Dialog 00097 mDlg->addSkzThemeToDialog(destFile.path()); 00098 } 00099 else if(result->name() == "plain/text") 00100 { 00101 kdDebug() << "SKNewStuff::install() plain text" << endl; 00102 } 00103 else if(result->name() == "text/html") 00104 { 00105 kdDebug() << "SKNewStuff::install() text/html" << endl; 00106 KRun::runURL( m_sourceLink, "text/html"); 00107 } 00108 else 00109 { 00110 kdDebug() << "SKNewStuff::install() Error no compatible mimetype encountered to install" 00111 << endl; 00112 return false; 00113 } 00114 return true; 00115 } 00116 00117 bool SKNewStuff::createUploadFile( const TQString &fileName ) 00118 { 00119 kdDebug() << "SKNewStuff::createUploadFile(): " << fileName << endl; 00120 return true; 00121 } 00122 00123 TQString SKNewStuff::downloadDestination( KNS::Entry *entry ) 00124 { 00125 KURL source = entry->payload(); 00126 m_sourceLink = source; 00127 00128 kdDebug() << "SKNewStuff::downloadDestination() url: " 00129 << source.url() << " fileName: " << source.fileName() << endl; 00130 TQString file(source.fileName()); 00131 if ( file.isEmpty() ) 00132 { 00133 kdDebug() << "The file was empty. " << source.url() << 00134 " must be a URL link." << endl; 00135 KRun::runURL( source, "text/html"); 00136 return file; 00137 } 00138 return KGlobal::dirs()->saveLocation( "tmp" ) + source.fileName(); 00139 } 00140 #endif //HAVE_KNEWSTUFF