~ken-vandine/content-hub/noclick

« back to all changes in this revision

Viewing changes to tools/clipboard/paste-data-model.h

  • Committer: Ken VanDine
  • Date: 2017-03-15 12:54:42 UTC
  • mfrom: (321.1.7 content-hub)
  • Revision ID: ken.vandine@canonical.com-20170315125442-jultuh0alb8kjknp
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Arthur Mello <arthur.mello@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef PASTEDATAMODEL_H
 
20
#define PASTEDATAMODEL_H
 
21
 
 
22
#include <QAbstractListModel>
 
23
 
 
24
class PasteDataProvider;
 
25
 
 
26
class PasteDataModel : public QAbstractListModel
 
27
{
 
28
    Q_OBJECT
 
29
 
 
30
    Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged)
 
31
    Q_PROPERTY(QString surfaceId READ surfaceId WRITE setSurfaceId NOTIFY surfaceIdChanged)
 
32
    Q_PROPERTY(int appState READ appState WRITE setAppState NOTIFY appStateChanged)
 
33
    Q_PROPERTY(bool anyEntrySelected READ anyEntrySelected NOTIFY anyEntrySelectedChanged)
 
34
    Q_PROPERTY(bool allEntriesSelected READ allEntriesSelected NOTIFY allEntriesSelectedChanged)
 
35
 
 
36
    Q_ENUMS(Roles)
 
37
    Q_ENUMS(PasteDataType)
 
38
    Q_ENUMS(PasteOutputType)
 
39
 
 
40
public:
 
41
    PasteDataModel(QObject* parent=0);
 
42
    ~PasteDataModel();
 
43
 
 
44
    enum Roles {
 
45
        Id = Qt::UserRole + 1,
 
46
        Source,
 
47
        DataType,
 
48
        TextData,
 
49
        HtmlData,
 
50
        ImageData,
 
51
        EntrySelected,
 
52
        Deleted,
 
53
        OutputType 
 
54
    };
 
55
 
 
56
    enum PasteDataType {
 
57
        Text,
 
58
        Image,
 
59
        ImageUrl
 
60
    };
 
61
 
 
62
    enum PasteOutputType {
 
63
        PlainText,
 
64
        RichText
 
65
    };
 
66
 
 
67
    // reimplemented from QAbstractListModel
 
68
    QHash<int, QByteArray> roleNames() const;
 
69
    int rowCount(const QModelIndex& parent=QModelIndex()) const;
 
70
    QVariant data(const QModelIndex& index, int role) const;
 
71
 
 
72
    QString surfaceId() const; 
 
73
    void setSurfaceId(QString surfaceId); 
 
74
 
 
75
    int appState() const; 
 
76
    void setAppState(int state); 
 
77
 
 
78
    bool anyEntrySelected() const;
 
79
    bool allEntriesSelected() const;
 
80
 
 
81
    Q_INVOKABLE void selectAll(bool selected);
 
82
    Q_INVOKABLE void selectByIndex(int index, bool selected);
 
83
    Q_INVOKABLE void markSelectedForDeletion();
 
84
    Q_INVOKABLE void markForDeletionByIndex(int index, bool deleted);
 
85
    Q_INVOKABLE void cancelDeletion();
 
86
    Q_INVOKABLE void deleteEntries();
 
87
    Q_INVOKABLE void deleteByIndex(int index);
 
88
    Q_INVOKABLE void setOutputTypeByIndex(int index, PasteOutputType outputType);
 
89
 
 
90
protected:
 
91
    struct PasteEntry {
 
92
        QString id;
 
93
        QString source;
 
94
        PasteDataType dataType;
 
95
        QString textData;
 
96
        QString htmlData;
 
97
        QString imageData;
 
98
        bool entrySelected;
 
99
        bool deleted;
 
100
        PasteOutputType outputType;
 
101
    };
 
102
    QList<PasteEntry> m_entries;
 
103
 
 
104
 
 
105
Q_SIGNALS:
 
106
    void rowCountChanged();
 
107
    void surfaceIdChanged();
 
108
    void appStateChanged();
 
109
    void anyEntrySelectedChanged();
 
110
    void allEntriesSelectedChanged();
 
111
 
 
112
private Q_SLOTS:
 
113
    void onPasteboardChanged();
 
114
 
 
115
private:
 
116
    void addToModelByPasteId(const QString& pasteId);
 
117
    void addToModel(PasteEntry& entry);
 
118
    void removeFromModel(int index);
 
119
    void updateModel();
 
120
 
 
121
    PasteDataProvider* m_provider;
 
122
    QString m_surfaceId;
 
123
    int m_appState;
 
124
    int m_selectedEntries;
 
125
    bool m_shouldUpdateModel;
 
126
};
 
127
 
 
128
#endif // PASTEDATAMODEL_H