kexi

kexiblobbuffer.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KEXIBLOBBUFFER_H
00021 #define KEXIBLOBBUFFER_H
00022 
00023 #include <qobject.h>
00024 #include <qintdict.h>
00025 #include <qdict.h>
00026 #include <qpixmap.h>
00027 
00028 #include <kurl.h>
00029 
00030 namespace KexiDB
00031 {
00032     class Connection;
00033 }
00034 
00036 
00080 class KEXICORE_EXPORT KexiBLOBBuffer : public QObject
00081 {
00082     Q_OBJECT
00083 
00084     private:
00085         class Item;
00086     public:
00089         typedef long Id_t;
00090 
00092         static KexiBLOBBuffer* self();
00093 
00094         static void setConnection(KexiDB::Connection *conn);
00095 
00097         class KEXICORE_EXPORT Handle {
00098             public:
00101                 Handle();
00102 
00104                 Handle(const Handle& handle);
00105 
00106                 ~Handle();
00107 
00108                 Id_t id() const { return m_item ? m_item->id : 0; }
00109 
00112                 bool stored() const { return m_item ? m_item->stored : false; }
00113 
00115                 operator bool() const { return m_item; }
00116 
00117                 Handle& operator=(const Handle& handle);
00118 
00119                 QByteArray data() const { return m_item ? m_item->data() : QByteArray(); }
00120 
00121                 QPixmap pixmap() const { return m_item ? m_item->pixmap() : QPixmap(); }
00122 
00125                 void setStoredWidthID(Id_t id);
00126 
00127                 QString originalFileName() const { return m_item ? m_item->name: QString::null; }
00128 
00129                 QString mimeType() const { return m_item ? m_item->mimeType : QString::null; }
00130 
00131                 Id_t folderId() const { return m_item ? m_item->folderId : 0; }
00132 
00133             protected:
00135                 Handle(Item* item);
00136             private:
00137                 Item* m_item;
00138             friend class KexiBLOBBuffer;
00139         };
00140 
00142         KexiBLOBBuffer();
00143 
00144         ~KexiBLOBBuffer();
00145 
00151         Handle insertPixmap(const KURL& url);
00152 
00162         Handle insertObject(const QByteArray& data, const QString& name, 
00163             const QString& caption, const QString& mimeType, Id_t identifier = 0);
00164 
00166         Handle insertPixmap(const QPixmap& pixmap);
00167 
00171         Handle objectForId(Id_t id, bool stored);
00172 
00175         Handle objectForId(Id_t id);
00176 
00177     protected:
00180         void removeItem(Id_t id, bool stored);
00181 
00183         void takeItem(Item* item);
00184 
00186         void insertItem(Item* item);
00187 
00188     private:
00189         class KEXICORE_EXPORT Item {
00190             public:
00191                 Item(const QByteArray& data, Id_t ident,
00192                     bool stored,
00193                     const QString& name = QString::null,
00194                     const QString& caption = QString::null,
00195                     const QString& mimeType = QString::null,
00196                     Id_t folderId = 0,
00197                     const QPixmap& pixmap = QPixmap());
00198                 ~Item();
00199                 QPixmap pixmap() const;
00200                 QByteArray data() const;
00201 //              KexiBLOBBuffer* buf;
00202 //              KURL url;
00203                 QString name;
00204                 QString caption; 
00205                 QString mimeType;
00206                 uint refs;
00207                 Id_t id;
00208                 Id_t folderId;
00209                 bool stored : 1;
00210                 QString prettyURL; 
00211             private:
00212                 QByteArray *m_data;
00213                 QPixmap *m_pixmap;
00214                 bool *m_pixmapLoaded; 
00215 
00216             friend class KexiBLOBBuffer;
00217         };
00218         class Private;
00219         Private *d;
00220         friend class Handle;
00221 };
00222 
00223 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys