superkaramba
sknewstuff.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <tdeapplication.h>
00022 #include <kdebug.h>
00023 #include <tdefilemetainfo.h>
00024 #include <tdeio/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_TDENEWSTUFF
00040 #include "sknewstuff.h"
00041
00042 SKNewStuff::SKNewStuff( ThemesDlg *dlg ) :
00043 TDENewStuff( "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 TDEStandardDirs 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 TDEStandardDirs::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-tar" ||
00068 result->name() == "application/x-tarz")
00069 {
00070 kdDebug() << "SKNewStuff::install() gzip/bzip2 mimetype encountered" <<
00071 endl;
00072 KTar archive( fileName );
00073 if ( !archive.open( IO_ReadOnly ) )
00074 return false;
00075 const KArchiveDirectory *archiveDir = archive.directory();
00076 archiveDir->copyTo(destDir);
00077
00078 mDlg->addThemeToDialog(archiveDir, destDir);
00079 archive.close();
00080 }
00081 else if(result->name() == "application/x-zip" ||
00082 result->name() == "application/x-superkaramba")
00083 {
00084 kdDebug() << "SKNewStuff::install() zip mimetype encountered" << endl;
00085
00086
00087
00088 KURL sourceFile(fileName);
00089 KURL destFile( destDir + sourceFile.fileName() );
00090 if(!TDEIO::NetAccess::file_copy( sourceFile, destFile ))
00091 {
00092 return false;
00093 }
00094 TDEIO::NetAccess::removeTempFile( sourceFile.url() );
00095
00096 mDlg->addSkzThemeToDialog(destFile.path());
00097 }
00098 else if(result->name() == "plain/text")
00099 {
00100 kdDebug() << "SKNewStuff::install() plain text" << endl;
00101 }
00102 else if(result->name() == "text/html")
00103 {
00104 kdDebug() << "SKNewStuff::install() text/html" << endl;
00105 KRun::runURL( m_sourceLink, "text/html");
00106 }
00107 else
00108 {
00109 kdDebug() << "SKNewStuff::install() Error no compatible mimetype encountered to install"
00110 << endl;
00111 return false;
00112 }
00113 return true;
00114 }
00115
00116 bool SKNewStuff::createUploadFile( const TQString &fileName )
00117 {
00118 kdDebug() << "SKNewStuff::createUploadFile(): " << fileName << endl;
00119 return true;
00120 }
00121
00122 TQString SKNewStuff::downloadDestination( KNS::Entry *entry )
00123 {
00124 KURL source = entry->payload();
00125 m_sourceLink = source;
00126
00127 kdDebug() << "SKNewStuff::downloadDestination() url: "
00128 << source.url() << " fileName: " << source.fileName() << endl;
00129 TQString file(source.fileName());
00130 if ( file.isEmpty() )
00131 {
00132 kdDebug() << "The file was empty. " << source.url() <<
00133 " must be a URL link." << endl;
00134 KRun::runURL( source, "text/html");
00135 return file;
00136 }
00137 return TDEGlobal::dirs()->saveLocation( "tmp" ) + source.fileName();
00138 }
00139 #endif //HAVE_TDENEWSTUFF