File indexing completed on 2024-04-14 04:45:15

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef _K3B_PLACES_MODEL_H_
0007 #define _K3B_PLACES_MODEL_H_
0008 
0009 #include "k3bmetaitemmodel.h"
0010 
0011 #include <QUrl>
0012 
0013 class KFileItem;
0014 
0015 namespace K3b {
0016     namespace Device {
0017         class Device;
0018         class DeviceManager;
0019     }
0020 
0021     /**
0022      * Wraps multiple KDirModels and a DeviceModel
0023      */
0024     class PlacesModel : public MetaItemModel
0025     {
0026         Q_OBJECT
0027 
0028     public:
0029         explicit PlacesModel( QObject* parent = 0 );
0030         ~PlacesModel() override;
0031 
0032         /**
0033          * Will return an invalid item if the index is not part
0034          * of a KDirModel.
0035          */
0036         KFileItem itemForIndex( const QModelIndex& index ) const;
0037 
0038         /**
0039          * Will return 0 if the index does not refer to a device item.
0040          */
0041         Device::Device* deviceForIndex( const QModelIndex& index ) const;
0042 
0043         /**
0044          * Will return invalid index if model does not contain such device
0045          */
0046         QModelIndex indexForDevice( Device::Device* dev ) const;
0047 
0048     Q_SIGNALS:
0049         /**
0050          * Emitted for each subdirectory that is a parent of a url
0051          * passed to expandToUrl This allows one to asynchronously open
0052          * a tree view down to a given directory.
0053          *
0054          * \sa KDirModel::expand
0055          */
0056         void expand( const QModelIndex& index );
0057 
0058     public Q_SLOTS:
0059         void addPlace( const QString& name, const QIcon& icon, const QUrl& rootUrl );
0060 
0061         /**
0062          * \short Lists subdirectories using fetchMore() as needed until the given \p url exists in the model.
0063          *
0064          * When the model is used by a treeview, call KDirLister::openUrl with the base url of the tree,
0065          * then the treeview will take care of calling fetchMore() when the user opens directories.
0066          * However if you want the tree to show a given URL (i.e. open the tree recursively until that URL),
0067          * call expandToUrl().
0068          * Note that this is asynchronous; the necessary listing of subdirectories will take time so
0069          * the model will not immediately have this url available.
0070          * The model emits the signal expand() when an index has become available; this can be connected
0071          * to the treeview in order to let it open that index.
0072          * \param url the url of a subdirectory of the directory model
0073          *
0074          * \sa KDirModel::expandToUrl
0075          */
0076         void expandToUrl( const QUrl& url );
0077 
0078     private Q_SLOTS:
0079         void slotDevicesChanged( K3b::Device::DeviceManager* dm );
0080         void slotExpand( const QModelIndex& index );
0081 
0082     private:
0083         class Private;
0084         Private* const d;
0085     };
0086 }
0087 
0088 #endif