filters

kword13picture.cpp

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2004 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qfile.h>
00022 
00023 #include <kdebug.h>
00024 #include <ktempfile.h>
00025 
00026 #include <KoStore.h>
00027 #include <KoStoreDevice.h>
00028 
00029 #include "kword13picture.h"
00030     
00031 KWord13Picture::KWord13Picture( void ) : m_tempFile( 0 ), m_valid( false )
00032 {
00033     
00034 }
00035 
00036 KWord13Picture::~KWord13Picture( void )
00037 {
00038     delete m_tempFile;
00039 }
00040 
00041 bool KWord13Picture::loadPicture( KoStore* store )
00042 {
00043     kdDebug(30520) << "Loading picture: " << m_storeName << endl;
00044  
00045     m_tempFile = new KTempFile( QString::null, ".bin" );
00046     m_tempFile->setAutoDelete( true );
00047  
00048     if ( ! store->extractFile( m_storeName, m_tempFile->name() ) )   
00049     {
00050         kdWarning(30520) << "Could not write temporary file!" << endl;
00051         delete m_tempFile;
00052         m_tempFile = 0;
00053         m_valid = false;
00054     }
00055     else
00056     {
00057         m_valid = true;
00058     }
00059     return m_valid;
00060 }
00061 
00062 QString KWord13Picture::getOasisPictureName( void ) const
00063 {
00064     if ( ! m_valid || ! m_tempFile )
00065         return QString::null;
00066         
00067     // We need a 32 digit hex value of the picture number
00068     // Please note: it is an exact 32 digit value, truncated if the value is more than 512 bits wide. :-)
00069     QString number;
00070     number.fill('0',32);
00071     // ### TODO: have a real counter instead of using the pointers
00072     number += QString::number( (long long)( (void*) m_tempFile ) , 16 ); // in hex
00073 
00074     QString strExtension( m_storeName.lower() );
00075     const int result = m_storeName.findRev( '.' );
00076     if ( result >= 0 )
00077     {
00078         strExtension = m_storeName.mid( result );
00079     }
00080     
00081     QString ooName( "Pictures/" );
00082     ooName += number.right( 32 );
00083     ooName += strExtension;
00084 
00085     return ooName;
00086 }
KDE Home | KDE Accessibility Home | Description of Access Keys