File indexing completed on 2024-04-21 03:55:19

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2007 Kevin Ottens <ervin@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KFILEPLACESITEM_P_H
0009 #define KFILEPLACESITEM_P_H
0010 
0011 #include "kfileplacesmodel.h"
0012 #include <KBookmark>
0013 #include <KBookmarkManager>
0014 #include <QObject>
0015 #include <QPointer>
0016 #include <QStringList>
0017 #include <QUrl>
0018 #include <solid/device.h>
0019 
0020 class KDirLister;
0021 namespace Solid
0022 {
0023 class StorageAccess;
0024 class StorageVolume;
0025 class StorageDrive;
0026 class NetworkShare;
0027 class OpticalDisc;
0028 class PortableMediaPlayer;
0029 }
0030 
0031 class KFilePlacesItem : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     KFilePlacesItem(KBookmarkManager *manager, const QString &address, const QString &udi, KFilePlacesModel *parent);
0036     ~KFilePlacesItem() override;
0037 
0038     QString id() const;
0039 
0040     bool isDevice() const;
0041     KFilePlacesModel::DeviceAccessibility deviceAccessibility() const;
0042     bool isTeardownAllowed() const;
0043     bool isTeardownOverlayRecommended() const;
0044     bool isEjectAllowed() const;
0045     KBookmark bookmark() const;
0046     void setBookmark(const KBookmark &bookmark);
0047     Solid::Device device() const;
0048     QVariant data(int role) const;
0049     KFilePlacesModel::GroupType groupType() const;
0050     bool isHidden() const;
0051     void setHidden(bool hide);
0052 
0053     bool hasSupportedScheme(const QStringList &schemes) const;
0054 
0055     static KBookmark
0056     createBookmark(KBookmarkManager *manager, const QString &label, const QUrl &url, const QString &iconName, KFilePlacesItem *after = nullptr);
0057     /**
0058      * @param untranslatedLabel text for label. If to be translated, should be set by kli18nc("KFile System Bookmarks", "Label text").untranslatedText().
0059      */
0060     static KBookmark createSystemBookmark(KBookmarkManager *manager,
0061                                           const char *untranslatedLabel,
0062                                           const QUrl &url,
0063                                           const QString &iconName,
0064                                           const KBookmark &after = KBookmark());
0065     static KBookmark createDeviceBookmark(KBookmarkManager *manager, const Solid::Device &device);
0066     static KBookmark createTagBookmark(KBookmarkManager *manager, const QString &tag);
0067 
0068 Q_SIGNALS:
0069     void itemChanged(const QString &id, const QList<int> &roles = {});
0070 
0071 private Q_SLOTS:
0072     void onAccessibilityChanged(bool);
0073 
0074 private:
0075     QVariant bookmarkData(int role) const;
0076     QVariant deviceData(int role) const;
0077 
0078     QString iconNameForBookmark(const KBookmark &bookmark) const;
0079 
0080     static QString generateNewId();
0081     bool updateDeviceInfo(const QString &udi);
0082 
0083     KBookmarkManager *m_manager;
0084     KBookmark m_bookmark;
0085     bool m_folderIsEmpty;
0086     bool m_isCdrom;
0087     bool m_isAccessible;
0088     bool m_isTeardownAllowed;
0089     bool m_isTeardownOverlayRecommended;
0090     bool m_isTeardownInProgress;
0091     bool m_isSetupInProgress;
0092     bool m_isReadOnly;
0093     QString m_text;
0094     Solid::Device m_device;
0095     QPointer<Solid::StorageAccess> m_access;
0096     QPointer<Solid::StorageVolume> m_volume;
0097     QPointer<Solid::StorageDrive> m_drive;
0098     QPointer<Solid::OpticalDisc> m_disc;
0099     QPointer<Solid::PortableMediaPlayer> m_player;
0100     QPointer<Solid::NetworkShare> m_networkShare;
0101     QString m_deviceIconName;
0102     QStringList m_emblems;
0103     QString m_groupName;
0104     mutable QString m_deviceDisplayName;
0105 };
0106 
0107 #endif