File indexing completed on 2024-04-28 11:41:01

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2008 Peter Penz <peter.penz@gmx.at>
0004     SPDX-FileCopyrightText: 2008 George Goldberg <grundleborg@googlemail.com>
0005     SPDX-FileCopyrightText: 2009 David Faure <faure@kde.org>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0008 */
0009 
0010 #ifndef KFILEITEMLISTPROPERTIES_H
0011 #define KFILEITEMLISTPROPERTIES_H
0012 
0013 #include "kiocore_export.h"
0014 
0015 #include <QList>
0016 #include <QSharedDataPointer>
0017 #include <QUrl>
0018 
0019 class KFileItemListPropertiesPrivate;
0020 class KFileItemList;
0021 
0022 /**
0023  * @class KFileItemListProperties kfileitemlistproperties.h <KFileItemListProperties>
0024  *
0025  * @brief Provides information about the common properties of a group of
0026  *        KFileItem objects.
0027  *
0028  * Given a list of KFileItems, this class can determine (and cache) the common
0029  * MIME type for all items, whether all items are directories, whether all items
0030  * are readable, writable, etc.
0031  * As soon as one file item does not support a specific capability (read, write etc.),
0032  * it is marked as unsupported for all items.
0033  *
0034  * This class is implicitly shared, which means it can be used as a value and
0035  * copied around at almost no cost.
0036  *
0037  * @since 4.3
0038  */
0039 class KIOCORE_EXPORT KFileItemListProperties
0040 {
0041 public:
0042     /**
0043      * @brief Default constructor. Use setItems to specify the items.
0044      */
0045     KFileItemListProperties();
0046     /**
0047      * @brief Constructor that takes a KFileItemList and sets the capabilities
0048      *        supported by all the FileItems as true.
0049      * @param items The list of items that are to have their supported
0050      *              capabilities checked.
0051      */
0052     KFileItemListProperties(const KFileItemList &items);
0053     /**
0054      * @brief Copy constructor
0055      */
0056     KFileItemListProperties(const KFileItemListProperties &);
0057     /**
0058      * @brief Destructor
0059      */
0060     virtual ~KFileItemListProperties();
0061     /**
0062      * @brief Assignment operator
0063      */
0064     KFileItemListProperties &operator=(const KFileItemListProperties &other);
0065     /**
0066      * Sets the items that are to have their supported capabilities checked.
0067      */
0068     void setItems(const KFileItemList &items);
0069 
0070     /**
0071      * @brief Check if reading capability is supported
0072      * @return true if all the FileItems can be read, otherwise false.
0073      */
0074     bool supportsReading() const;
0075     /**
0076      * @brief Check if deleting capability is supported
0077      * @return true if all the FileItems can be deleted, otherwise false.
0078      */
0079     bool supportsDeleting() const;
0080     /**
0081      * @brief Check if writing capability is supported
0082      * (file managers use this mostly for directories)
0083      * @return true if all the FileItems can be written to, otherwise false.
0084      */
0085     bool supportsWriting() const;
0086     /**
0087      * @brief Check if moving capability is supported
0088      * @return true if all the FileItems can be moved, otherwise false.
0089      */
0090     bool supportsMoving() const;
0091     /**
0092      * @brief Check if files are local
0093      * @return true if all the FileItems are local, otherwise there is one or more
0094      *         remote file, so false.
0095      */
0096     bool isLocal() const;
0097 
0098     /**
0099      * List of fileitems passed to the constructor or to setItems().
0100      */
0101     KFileItemList items() const;
0102 
0103     /**
0104      * List of urls, gathered from the fileitems
0105      */
0106     QList<QUrl> urlList() const;
0107 
0108     /**
0109      * @return true if all items are directories
0110      */
0111     bool isDirectory() const;
0112 
0113     /**
0114      * @return Whether all items are files, as reported by KFileItem::isFile().
0115      * @since 5.47
0116      */
0117     bool isFile() const;
0118 
0119     /**
0120      * @return the MIME type of all items, if they all have the same, otherwise an empty string
0121      */
0122     QString mimeType() const;
0123 
0124     /**
0125      * @return the MIME type group (e.g. "text") of all items, if they all have the same, otherwise an empty string
0126      */
0127     QString mimeGroup() const;
0128 
0129 private:
0130     /** @brief d-pointer */
0131     QSharedDataPointer<KFileItemListPropertiesPrivate> d;
0132 };
0133 
0134 #endif /* KFILEITEMLISTPROPERTIES_H */