filemanager/model/foldermodel.h

213 lines
6 KiB
C
Raw Normal View History

2021-03-29 01:51:34 -07:00
#ifndef FOLDERMODEL_H
#define FOLDERMODEL_H
#include "../widgets/itemviewadapter.h"
#include "../helper/pathhistory.h"
#include <QSortFilterProxyModel>
#include <QItemSelectionModel>
#include <QQmlParserStatus>
#include <QQuickItem>
#include <KDirLister>
#include <KDirModel>
#include <KDirWatch>
#include <KActionCollection>
class QDrag;
class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(QUrl resolvedUrl READ resolvedUrl NOTIFY resolvedUrlChanged)
Q_PROPERTY(int sortMode READ sortMode WRITE setSortMode NOTIFY sortModeChanged)
Q_PROPERTY(bool sortDirsFirst READ sortDirsFirst WRITE setSortDirsFirst NOTIFY sortDirsFirstChanged)
Q_PROPERTY(bool dragging READ dragging NOTIFY draggingChanged)
Q_PROPERTY(QObject *viewAdapter READ viewAdapter WRITE setViewAdapter NOTIFY viewAdapterChanged)
Q_PROPERTY(QString statusText READ statusText NOTIFY statusTextChanged)
2021-03-29 07:53:21 -07:00
Q_PROPERTY(bool isDesktop READ isDesktop WRITE setIsDesktop NOTIFY isDesktopChanged)
2021-03-29 01:51:34 -07:00
public:
enum DataRole {
BlankRole = Qt::UserRole + 1,
SelectedRole,
IsDirRole,
UrlRole,
FileNameRole,
IconNameRole,
ThumbnailRole
};
enum FilterMode {
NoFilter = 0,
FilterShowMatches,
FilterHideMatches,
};
enum Status {
None,
Ready,
Listing,
Canceled,
};
Q_ENUM(Status)
struct DragImage {
int row;
QRect rect;
QPoint cursorOffset;
QImage image;
bool blank;
};
explicit FolderModel(QObject *parent = nullptr);
~FolderModel() override;
void classBegin() override;
void componentComplete() override;
QHash<int, QByteArray> roleNames() const override;
static QHash<int, QByteArray> staticRoleNames();
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
KFileItem itemForIndex(const QModelIndex &index) const;
QList<QUrl> selectedUrls() const;
QString url() const;
void setUrl(const QString &url);
QUrl resolvedUrl() const;
Q_INVOKABLE QUrl resolve(const QString &url);
Status status() const;
void setStatus(Status status);
int sortMode() const;
void setSortMode(int mode);
bool sortDirsFirst() const;
void setSortDirsFirst(bool enable);
QObject *viewAdapter() const;
void setViewAdapter(QObject *adapter);
bool dragging() const;
bool isDir(const QModelIndex &index, const KDirModel *dirModel) const;
bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
Qt::DropActions supportedDragActions() const override;
Qt::DropActions supportedDropActions() const override;
KFileItem rootItem() const;
QString statusText();
2021-03-31 19:25:20 -07:00
int selectionCound() const;
2021-03-29 01:51:34 -07:00
Q_INVOKABLE QString homePath() const;
Q_INVOKABLE QString desktopPath() const;
Q_INVOKABLE QAction *action(const QString &name) const;
Q_INVOKABLE void up();
Q_INVOKABLE void goBack();
Q_INVOKABLE void goForward();
Q_INVOKABLE bool supportSetAsWallpaper(const QString &mimeType);
Q_INVOKABLE int fileExtensionBoundary(int row);
Q_INVOKABLE bool hasSelection() const;
Q_INVOKABLE bool isSelected(int row) const;
Q_INVOKABLE bool isBlank(int row) const;
Q_INVOKABLE void setSelected(int row);
Q_INVOKABLE void selectAll();
Q_INVOKABLE void toggleSelected(int row);
Q_INVOKABLE void setRangeSelected(int anchor, int to);
Q_INVOKABLE void updateSelection(const QVariantList &rows, bool toggle);
Q_INVOKABLE void clearSelection();
Q_INVOKABLE void pinSelection();
Q_INVOKABLE void unpinSelection();
Q_INVOKABLE void newFolder();
2021-03-29 01:51:34 -07:00
Q_INVOKABLE void rename(int row, const QString &name);
Q_INVOKABLE void copy();
Q_INVOKABLE void paste();
Q_INVOKABLE void cut();
Q_INVOKABLE void openSelected();
Q_INVOKABLE void deleteSelected();
Q_INVOKABLE void moveSelectedToTrash();
Q_INVOKABLE void emptyTrash();
2021-03-31 19:25:20 -07:00
Q_INVOKABLE void keyDeletePress();
2021-03-29 01:51:34 -07:00
Q_INVOKABLE void setDragHotSpotScrollOffset(int x, int y);
Q_INVOKABLE void addItemDragImage(int row, int x, int y, int width, int height, const QVariant &image);
Q_INVOKABLE void clearDragImages();
Q_INVOKABLE void dragSelected(int x, int y);
Q_INVOKABLE void setWallpaperSelected();
Q_INVOKABLE void openContextMenu(QQuickItem *visualParent = nullptr, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
Q_INVOKABLE void openPropertiesDialog();
Q_INVOKABLE void openInTerminal();
2021-03-29 07:53:21 -07:00
bool isDesktop() const;
void setIsDesktop(bool isDesktop);
2021-03-29 01:51:34 -07:00
signals:
void urlChanged();
void resolvedUrlChanged();
void statusChanged();
void sortModeChanged();
void sortDescChanged();
void sortDirsFirstChanged();
void requestRename();
void draggingChanged();
void viewAdapterChanged();
void statusTextChanged();
2021-03-29 07:53:21 -07:00
void isDesktopChanged();
2021-03-31 19:25:20 -07:00
void selectionCoundChanged();
2021-03-29 01:51:34 -07:00
private slots:
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
void dragSelectedInternal(int x, int y);
private:
void invalidateIfComplete();
void invalidateFilterIfComplete();
void createActions();
void updateActions();
void addDragImage(QDrag *drag, int x, int y);
bool isSupportThumbnails(const QString &mimeType) const;
private:
KDirModel *m_dirModel;
KDirWatch *m_dirWatch;
QItemSelectionModel *m_selectionModel;
QItemSelection m_pinnedSelection;
QString m_url;
Status m_status;
int m_sortMode;
bool m_sortDesc;
bool m_sortDirsFirst;
bool m_complete;
2021-03-29 07:53:21 -07:00
bool m_isDesktop;
2021-03-29 01:51:34 -07:00
KActionCollection m_actionCollection;
QHash<int, DragImage *> m_dragImages;
QModelIndexList m_dragIndexes;
QPoint m_dragHotSpotScrollOffset;
bool m_dragInProgress;
QPointer<ItemViewAdapter> m_viewAdapter;
// Save path history
PathHistory m_pathHistory;
};
#endif // FOLDERMODEL_H