File indexing completed on 2024-04-28 07:43:52

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  */
0038 class KIOCORE_EXPORT KFileItemListProperties
0039 {
0040 public:
0041     /**
0042      * @brief Default constructor. Use setItems to specify the items.
0043      */
0044     KFileItemListProperties();
0045     /**
0046      * @brief Constructor that takes a KFileItemList and sets the capabilities
0047      *        supported by all the FileItems as true.
0048      * @param items The list of items that are to have their supported
0049      *              capabilities checked.
0050      */
0051     KFileItemListProperties(const KFileItemList &items);
0052     /**
0053      * @brief Copy constructor
0054      */
0055     KFileItemListProperties(const KFileItemListProperties &);
0056     /**
0057      * @brief Destructor
0058      */
0059     virtual ~KFileItemListProperties();
0060     /**
0061      * @brief Assignment operator
0062      */
0063     KFileItemListProperties &operator=(const KFileItemListProperties &other);
0064     /**
0065      * Sets the items that are to have their supported capabilities checked.
0066      */
0067     void setItems(const KFileItemList &items);
0068 
0069     /**
0070      * @brief Check if reading capability is supported
0071      * @return true if all the FileItems can be read, otherwise false.
0072      */
0073     bool supportsReading() const;
0074     /**
0075      * @brief Check if deleting capability is supported
0076      * @return true if all the FileItems can be deleted, otherwise false.
0077      */
0078     bool supportsDeleting() const;
0079     /**
0080      * @brief Check if writing capability is supported
0081      * (file managers use this mostly for directories)
0082      * @return true if all the FileItems can be written to, otherwise false.
0083      */
0084     bool supportsWriting() const;
0085     /**
0086      * @brief Check if moving capability is supported
0087      * @return true if all the FileItems can be moved, otherwise false.
0088      */
0089     bool supportsMoving() const;
0090     /**
0091      * @brief Check if files are local
0092      * @return true if all the FileItems are local, otherwise there is one or more
0093      *         remote file, so false.
0094      */
0095     bool isLocal() const;
0096 
0097     /**
0098      * List of fileitems passed to the constructor or to setItems().
0099      */
0100     KFileItemList items() const;
0101 
0102     /**
0103      * List of urls, gathered from the fileitems
0104      */
0105     QList<QUrl> urlList() const;
0106 
0107     /**
0108      * @return true if all items are directories
0109      */
0110     bool isDirectory() const;
0111 
0112     /**
0113      * @return Whether all items are files, as reported by KFileItem::isFile().
0114      * @since 5.47
0115      */
0116     bool isFile() const;
0117 
0118     /**
0119      * @return the MIME type of all items, if they all have the same, otherwise an empty string
0120      */
0121     QString mimeType() const;
0122 
0123     /**
0124      * @return the MIME type group (e.g. "text") of all items, if they all have the same, otherwise an empty string
0125      */
0126     QString mimeGroup() const;
0127 
0128 private:
0129     /** @brief d-pointer */
0130     QSharedDataPointer<KFileItemListPropertiesPrivate> d;
0131 };
0132 
0133 #endif /* KFILEITEMLISTPROPERTIES_H */