Warning, file /maui/mauikit-filebrowsing/src/code/placeslist.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002  * <one line to give the program's name and a brief idea of what it does.>
0003  * Copyright (C) 2018  camilo <milo.h@aol.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #pragma once
0020 
0021 #include <QObject>
0022 #include <QModelIndex>
0023 #include <QHash>
0024 
0025 #include "fmstatic.h"
0026 
0027 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0028 #include <MauiKit3/Core/mauilist.h>
0029 #else
0030 #include <MauiKit4/Core/mauilist.h>
0031 #endif
0032 
0033 class KFilePlacesModel;
0034 
0035 /**
0036  * @brief The list model of the system locations, such as bookmarks, standard places, networks and devices.
0037  * 
0038  * A graphical interface for this controller functionality is available for quick usage as PlacesListBrowser.
0039  */
0040 class PlacesList : public MauiList
0041 {
0042     Q_OBJECT
0043     Q_DISABLE_COPY(PlacesList)
0044     
0045     /**
0046      * The groups to be listed.
0047      * The possible list of groups are defined at FMList::PATHTYPE
0048      * To set it from QML:
0049      * @code
0050      * list.groups:  [FMList.BOOKMARKS_PATH, FMList.REMOTE_PATH, FMList.CLOUD_PATH, FMList.DRIVES_PATH]
0051      * @endcode
0052      */
0053     Q_PROPERTY(QVariantList groups READ getGroups WRITE setGroups NOTIFY groupsChanged)
0054 
0055 public:
0056     PlacesList(QObject *parent = nullptr);
0057 
0058     /**
0059      * @private
0060      */
0061     const FMH::MODEL_LIST &items() const override;
0062 
0063     QVariantList getGroups() const;
0064     void setGroups(const QVariantList &value);
0065 
0066     /**
0067      * @private
0068      */
0069     void componentComplete() override final;
0070 
0071 protected:
0072     void setList();
0073 
0074 public Q_SLOTS:
0075     /**
0076      * @brief Removes a place from the model and if the data at the given index is a file URL bookmark then it gets removed from the bookmarks.
0077      * @param index index of the item to be removed in the model
0078      */
0079     void removePlace(const int &index);
0080 
0081     /**
0082      * @brief Checks of a file URL exists in the places model
0083      * @param path file URL to be checked
0084      * @return Whether it exists
0085      */
0086     bool contains(const QUrl &path);
0087 
0088     /**
0089      * @brief Check if a entry at the given index is a device
0090      * @param index index position of the entry in the list
0091      * @return whether it is a device type
0092      */
0093     bool isDevice(const int &index);
0094 
0095     /**
0096      * @brief Check if a device type entry needs to be setup, as in mounted.
0097      * @param index the index position of the entry
0098      * @return whether it needs to be setup
0099      */
0100     bool setupNeeded(const int &index);
0101 
0102     /**
0103      * @brief Request to eject a removable device type at the given index
0104      * @param index the index position of the entry
0105      */
0106     void requestEject (const int &index);
0107 
0108     /**
0109      * @brief Request to setup or mount the device type entry at the given index
0110      * @param index index position of the entry
0111      */
0112     void requestSetup (const int &index);
0113     
0114     /**
0115      * @brief Add a location to the bookmarks sections
0116      * @param url The URL path of the location or directory
0117      */
0118     static void addBookmark(const QUrl &url);
0119 
0120     /**
0121      * @brief Given an URL path, if it exists in the places list return its index position
0122      * @param url The URL path to be checked
0123      * @return the index position if it exists otherwise `-1`
0124      */
0125     int indexOfPath(const QUrl &url) const;
0126     
0127     /**
0128      * @brief Hide/show a section
0129      * @param The section type to be toggle. The possible values are defined in FMStatic::PATHTYPE_KEY. 
0130      */
0131     void toggleSection(const int &section);
0132     
0133     /**
0134      * @brief Whether the current listing contains a group type. The possible values are defined in FMStatic::PATHTYPE_KEY
0135      * @param group the group type
0136      * @return whether it is being listed
0137      */
0138     bool containsGroup(const int &group);
0139 
0140 private:
0141     FMH::MODEL_LIST list;
0142     KFilePlacesModel *model;
0143 
0144     QVariantList groups;
0145 
0146     QHash<QString, QModelIndex> m_devices;
0147 
0148     FMH::MODEL_LIST getGroup(const KFilePlacesModel &model, const FMStatic::PATHTYPE_KEY &type);
0149 
0150 Q_SIGNALS:
0151     void groupsChanged();
0152     
0153     /**
0154      * @brief Emitted when a new bookmark entry has been added
0155      */
0156     void bookmarksChanged();
0157 };