kword13picture.cpp
1/*
2 This file is part of the KDE project
3 Copyright (C) 2004 Nicolas GOUTTE <goutte@kde.org>
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqfile.h>
22
23#include <kdebug.h>
24#include <tdetempfile.h>
25
26#include <KoStore.h>
27#include <KoStoreDevice.h>
28
29#include "kword13picture.h"
30
31KWord13Picture::KWord13Picture( void ) : m_tempFile( 0 ), m_valid( false )
32{
33
34}
35
36KWord13Picture::~KWord13Picture( void )
37{
38 delete m_tempFile;
39}
40
41bool KWord13Picture::loadPicture( KoStore* store )
42{
43 kdDebug(30520) << "Loading picture: " << m_storeName << endl;
44
45 m_tempFile = new KTempFile( TQString(), ".bin" );
46 m_tempFile->setAutoDelete( true );
47
48 if ( ! store->extractFile( m_storeName, m_tempFile->name() ) )
49 {
50 kdWarning(30520) << "Could not write temporary file!" << endl;
51 delete m_tempFile;
52 m_tempFile = 0;
53 m_valid = false;
54 }
55 else
56 {
57 m_valid = true;
58 }
59 return m_valid;
60}
61
62TQString KWord13Picture::getOasisPictureName( void ) const
63{
64 if ( ! m_valid || ! m_tempFile )
65 return TQString();
66
67 // We need a 32 digit hex value of the picture number
68 // Please note: it is an exact 32 digit value, truncated if the value is more than 512 bits wide. :-)
69 TQString number;
70 number.fill('0',32);
71 // ### TODO: have a real counter instead of using the pointers
72 number += TQString::number( (long long)( (void*) m_tempFile ) , 16 ); // in hex
73
74 TQString strExtension( m_storeName.lower() );
75 const int result = m_storeName.findRev( '.' );
76 if ( result >= 0 )
77 {
78 strExtension = m_storeName.mid( result );
79 }
80
81 TQString ooName( "Pictures/" );
82 ooName += number.right( 32 );
83 ooName += strExtension;
84
85 return ooName;
86}