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#include <MauiKit4/Core/mauilist.h>
29
30#include "filebrowsing_export.h"
31
33
34/**
35 * @brief The list model of the system locations, such as bookmarks, standard places, networks and devices.
36 *
37 * A graphical interface for this controller functionality is available for quick usage as PlacesListBrowser.
38 */
39class FILEBROWSING_EXPORT PlacesList : public MauiList
40{
41 Q_OBJECT
42 QML_ELEMENT
43 Q_DISABLE_COPY(PlacesList)
44
45 /**
46 * The groups to be listed.
47 * The possible list of groups are defined at FMList::PATHTYPE
48 * To set it from QML:
49 * @code
50 * list.groups: [FMList.BOOKMARKS_PATH, FMList.REMOTE_PATH, FMList.CLOUD_PATH, FMList.DRIVES_PATH]
51 * @endcode
52 */
53 Q_PROPERTY(QVariantList groups READ getGroups WRITE setGroups NOTIFY groupsChanged)
54
55public:
56 PlacesList(QObject *parent = nullptr);
57
58 /**
59 * @private
60 */
61 const FMH::MODEL_LIST &items() const override;
62
63 QVariantList getGroups() const;
64 void setGroups(const QVariantList &value);
65
66 /**
67 * @private
68 */
69 void componentComplete() override final;
70
71protected:
72 void setList();
73
74public Q_SLOTS:
75 /**
76 * @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.
77 * @param index index of the item to be removed in the model
78 */
79 void removePlace(const int &index);
80
81 /**
82 * @brief Checks of a file URL exists in the places model
83 * @param path file URL to be checked
84 * @return Whether it exists
85 */
86 bool contains(const QUrl &path);
87
88 /**
89 * @brief Check if a entry at the given index is a device
90 * @param index index position of the entry in the list
91 * @return whether it is a device type
92 */
93 bool isDevice(const int &index);
94
95 /**
96 * @brief Check if a device type entry needs to be setup, as in mounted.
97 * @param index the index position of the entry
98 * @return whether it needs to be setup
99 */
100 bool setupNeeded(const int &index);
101
102 /**
103 * @brief Request to eject a removable device type at the given index
104 * @param index the index position of the entry
105 */
106 void requestEject (const int &index);
107
108 /**
109 * @brief Request to setup or mount the device type entry at the given index
110 * @param index index position of the entry
111 */
112 void requestSetup (const int &index);
113
114 /**
115 * @brief Add a location to the bookmarks sections
116 * @param url The URL path of the location or directory
117 */
118 static void addBookmark(const QUrl &url);
119
120 /**
121 * @brief Given an URL path, if it exists in the places list return its index position
122 * @param url The URL path to be checked
123 * @return the index position if it exists otherwise `-1`
124 */
125 int indexOfPath(const QUrl &url) const;
126
127 /**
128 * @brief Hide/show a section
129 * @param The section type to be toggle. The possible values are defined in FMStatic::PATHTYPE_KEY.
130 */
131 void toggleSection(const int &section);
132
133 /**
134 * @brief Whether the current listing contains a group type. The possible values are defined in FMStatic::PATHTYPE_KEY
135 * @param group the group type
136 * @return whether it is being listed
137 */
138 bool containsGroup(const int &group);
139
140private:
141 FMH::MODEL_LIST list;
142 KFilePlacesModel *model;
143
144 QVariantList groups;
145
146 QHash<QString, QModelIndex> m_devices;
147
148 FMH::MODEL_LIST getGroup(const KFilePlacesModel &model, const FMStatic::PATHTYPE_KEY &type);
149
150Q_SIGNALS:
151 void groupsChanged();
152
153 /**
154 * @brief Emitted when a new bookmark entry has been added
155 */
156 void bookmarksChanged();
157};
The FMStatic class is a group of static file management methods, this class has a constructor only as...
Definition fmstatic.h:30
The list model of the system locations, such as bookmarks, standard places, networks and devices.
Definition placeslist.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:32:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.