KArchive

karchivedirectory.h
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at>
4
5 Moved from ktar.h by Roberto Teixeira <maragato@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9#ifndef KARCHIVEDIRECTORY_H
10#define KARCHIVEDIRECTORY_H
11
12#include <sys/stat.h>
13#include <sys/types.h>
14
15#include <QDate>
16#include <QString>
17#include <QStringList>
18
19#include <karchiveentry.h>
20
21class KArchiveDirectoryPrivate;
22class KArchiveFile;
23/**
24 * @class KArchiveDirectory karchivedirectory.h KArchiveDirectory
25 *
26 * Represents a directory entry in a KArchive.
27 * @short A directory in an archive.
28 *
29 * @see KArchive
30 * @see KArchiveFile
31 */
32class KARCHIVE_EXPORT KArchiveDirectory : public KArchiveEntry
33{
34public:
35 /**
36 * Creates a new directory entry.
37 * @param archive the entries archive
38 * @param name the name of the entry
39 * @param access the permissions in unix format
40 * @param date the date (in seconds since 1970)
41 * @param user the user that owns the entry
42 * @param group the group that owns the entry
43 * @param symlink the symlink, or QString()
44 */
46 const QString &name,
47 int access,
48 const QDateTime &date,
49 const QString &user,
50 const QString &group,
51 const QString &symlink);
52
53 ~KArchiveDirectory() override;
54
55 /**
56 * Returns a list of sub-entries.
57 * Note that the list is not sorted, it's even in random order (due to using a hashtable).
58 * Use sort() on the result to sort the list by filename.
59 *
60 * @return the names of all entries in this directory (filenames, no path).
61 */
62 QStringList entries() const;
63
64 /**
65 * Returns the entry in the archive with the given name.
66 * The entry could be a file or a directory, use isFile() to find out which one it is.
67 * @param name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc.
68 * @return a pointer to the entry in the directory, or a null pointer if there is no such entry.
69 */
70 const KArchiveEntry *entry(const QString &name) const;
71
72 /**
73 * Returns the file entry in the archive with the given name.
74 * If the entry exists and is a file, a KArchiveFile is returned.
75 * Otherwise, a null pointer is returned.
76 * This is a convenience method for entry(), when we know the entry is expected to be a file.
77 *
78 * @param name may be "test1", "mydir/test3", "mydir/mysubdir/test3", etc.
79 * @return a pointer to the file entry in the directory, or a null pointer if there is no such file entry.
80 * @since 5.3
81 */
82 const KArchiveFile *file(const QString &name) const;
83
84 /**
85 * @internal
86 * Adds a new entry to the directory.
87 * Note: this can delete the entry if another one with the same name is already present
88 */
89 void addEntry(KArchiveEntry *); // KF6 TODO: return bool
90
91 /**
92 * @internal
93 * Adds a new entry to the directory.
94 * @return whether the entry was added or not. Non added entries are deleted
95 */
96 bool addEntryV2(KArchiveEntry *); // KF6 TODO: merge with the one above
97
98 /**
99 * @internal
100 * Removes an entry from the directory.
101 */
102 void removeEntry(KArchiveEntry *); // KF6 TODO: return bool since it can fail
103
104 /**
105 * Checks whether this entry is a directory.
106 * @return true, since this entry is a directory
107 */
108 bool isDirectory() const override;
109
110 /**
111 * Extracts all entries in this archive directory to the directory
112 * @p dest.
113 * @param dest the directory to extract to
114 * @param recursive if set to true, subdirectories are extracted as well
115 * @return true on success, false if the directory (dest + '/' + name()) couldn't be created
116 */
117 bool copyTo(const QString &dest, bool recursive = true) const;
118
119protected:
120 void virtual_hook(int id, void *data) override;
121
122private:
123 friend class KArchiveDirectoryPrivate;
124 KArchiveDirectoryPrivate *const d;
125};
126
127#endif
Represents a directory entry in a KArchive.
A base class for entries in an KArchive.
virtual bool isDirectory() const
Checks whether the entry is a directory.
Definition karchive.cpp:745
Represents a file entry in a KArchive.
KArchive is a base class for reading and writing archives.
Definition karchive.h:41
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.