MauiKit File Browsing

placeslist.h
1/*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2018 camilo <milo.h@aol.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#pragma once
20
21#include <QObject>
22#include <QModelIndex>
23#include <QHash>
24#include <QQmlEngine>
25
26#include "fmstatic.h"
27
28#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
29#include <MauiKit3/Core/mauilist.h>
30#else
31#include <MauiKit4/Core/mauilist.h>
32#endif
33
34#include "filebrowsing_export.h"
35
37
38/**
39 * @brief The list model of the system locations, such as bookmarks, standard places, networks and devices.
40 *
41 * A graphical interface for this controller functionality is available for quick usage as PlacesListBrowser.
42 */
43class FILEBROWSING_EXPORT PlacesList : public MauiList
44{
45 Q_OBJECT
46 QML_ELEMENT
47 Q_DISABLE_COPY(PlacesList)
48
49 /**
50 * The groups to be listed.
51 * The possible list of groups are defined at FMList::PATHTYPE
52 * To set it from QML:
53 * @code
54 * list.groups: [FMList.BOOKMARKS_PATH, FMList.REMOTE_PATH, FMList.CLOUD_PATH, FMList.DRIVES_PATH]
55 * @endcode
56 */
57 Q_PROPERTY(QVariantList groups READ getGroups WRITE setGroups NOTIFY groupsChanged)
58
59public:
60 PlacesList(QObject *parent = nullptr);
61
62 /**
63 * @private
64 */
65 const FMH::MODEL_LIST &items() const override;
66
67 QVariantList getGroups() const;
68 void setGroups(const QVariantList &value);
69
70 /**
71 * @private
72 */
73 void componentComplete() override final;
74
75protected:
76 void setList();
77
78public Q_SLOTS:
79 /**
80 * @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.
81 * @param index index of the item to be removed in the model
82 */
83 void removePlace(const int &index);
84
85 /**
86 * @brief Checks of a file URL exists in the places model
87 * @param path file URL to be checked
88 * @return Whether it exists
89 */
90 bool contains(const QUrl &path);
91
92 /**
93 * @brief Check if a entry at the given index is a device
94 * @param index index position of the entry in the list
95 * @return whether it is a device type
96 */
97 bool isDevice(const int &index);
98
99 /**
100 * @brief Check if a device type entry needs to be setup, as in mounted.
101 * @param index the index position of the entry
102 * @return whether it needs to be setup
103 */
104 bool setupNeeded(const int &index);
105
106 /**
107 * @brief Request to eject a removable device type at the given index
108 * @param index the index position of the entry
109 */
110 void requestEject (const int &index);
111
112 /**
113 * @brief Request to setup or mount the device type entry at the given index
114 * @param index index position of the entry
115 */
116 void requestSetup (const int &index);
117
118 /**
119 * @brief Add a location to the bookmarks sections
120 * @param url The URL path of the location or directory
121 */
122 static void addBookmark(const QUrl &url);
123
124 /**
125 * @brief Given an URL path, if it exists in the places list return its index position
126 * @param url The URL path to be checked
127 * @return the index position if it exists otherwise `-1`
128 */
129 int indexOfPath(const QUrl &url) const;
130
131 /**
132 * @brief Hide/show a section
133 * @param The section type to be toggle. The possible values are defined in FMStatic::PATHTYPE_KEY.
134 */
135 void toggleSection(const int &section);
136
137 /**
138 * @brief Whether the current listing contains a group type. The possible values are defined in FMStatic::PATHTYPE_KEY
139 * @param group the group type
140 * @return whether it is being listed
141 */
142 bool containsGroup(const int &group);
143
144private:
145 FMH::MODEL_LIST list;
146 KFilePlacesModel *model;
147
148 QVariantList groups;
149
150 QHash<QString, QModelIndex> m_devices;
151
152 FMH::MODEL_LIST getGroup(const KFilePlacesModel &model, const FMStatic::PATHTYPE_KEY &type);
153
154Q_SIGNALS:
155 void groupsChanged();
156
157 /**
158 * @brief Emitted when a new bookmark entry has been added
159 */
160 void bookmarksChanged();
161};
The FMStatic class is a group of static file management methods, this class has a constructor only as...
Definition fmstatic.h:35
The list model of the system locations, such as bookmarks, standard places, networks and devices.
Definition placeslist.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:51:27 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.