File indexing completed on 2024-05-26 16:15:29

0001 /* This file is part of the KDE project
0002    Copyright 2004 Nicolas GOUTTE <goutte@kde.org>
0003    
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef __koStore_p_h_
0021 #define __koStore_p_h_
0022 
0023 
0024 #include "KoStore.h"
0025 
0026 #include <QStringList>
0027 #include <QStack>
0028 
0029 #include <QUrl>
0030 
0031 class QWidget;
0032 
0033 class KoStorePrivate
0034 {
0035 public:
0036     explicit KoStorePrivate(KoStore *qq, KoStore::Mode _mode, bool _writeMimetype)
0037         : q(qq),
0038         fileMode(Local),
0039         window(0),
0040         mode(_mode),
0041         size(0),
0042         stream(0),
0043         isOpen(false),
0044         good(false),
0045         finalized(false),
0046         writeMimetype(_writeMimetype)
0047     {
0048     }
0049 
0050     enum FileMode { /*Bad=0,*/ Local = 1, RemoteRead, RemoteWrite };
0051 
0052     /**
0053      * Conversion routine
0054      * @param internalNaming name used internally : "root", "tar:/0", ...
0055      * @return the name used in the file, more user-friendly ("maindoc.xml",
0056      *         "part0/maindoc.xml", ...)
0057      * Examples:
0058      *
0059      * tar:/0 is saved as part0/maindoc.xml
0060      * tar:/0/1 is saved as part0/part1/maindoc.xml
0061      * tar:/0/1/pictures/picture0.png is saved as part0/part1/pictures/picture0.png
0062      *
0063      * see specification (calligra/lib/store/SPEC) for details.
0064      */
0065     QString toExternalNaming(const QString &internalNaming) const;
0066 
0067     /**
0068      * Enter *one* single directory. Nothing like foo/bar/bleh allowed.
0069      * Performs some checking when in Read mode
0070      */
0071     bool enterDirectoryInternal(const QString &directory);
0072 
0073     bool extractFile(const QString &sourceName, QIODevice &buffer);
0074 
0075     KoStore *q;
0076     /**
0077      * original URL of the remote file
0078      * (undefined for a local file)
0079      */
0080     QUrl url;
0081     FileMode fileMode;
0082     QString localFileName;
0083     QWidget *window;
0084 
0085     KoStore::Mode mode;
0086 
0087     /// Store the filenames (with full path inside the archive) when writing, to avoid duplicates
0088     QStringList filesList;
0089 
0090     /// The "current directory" (path)
0091     QStringList currentPath;
0092 
0093     /// Current filename (between an open() and a close())
0094     QString fileName;
0095     /// Current size of the file named m_sName
0096     qint64 size;
0097 
0098     /// The stream for the current read or write operation
0099     QIODevice *stream;
0100 
0101     bool isOpen;
0102     /// Must be set by the constructor.
0103     bool good;
0104     bool finalized;
0105 
0106     QStack<QString> directoryStack;
0107 
0108     bool writeMimetype; ///< true if the backend is allowed to create "mimetype" automatically.
0109 };
0110 
0111 #endif