~ci-train-bot/qtmir/qtmir-ubuntu-yakkety-2077

« back to all changes in this revision

Viewing changes to src/platforms/mirserver/clipboard.h

  • Committer: Bileto Bot
  • Author(s): Daniel d'Andrada
  • Date: 2016-08-31 01:51:29 UTC
  • mfrom: (552.2.3 content-hub-clipboard)
  • Revision ID: ci-train-bot@canonical.com-20160831015129-6x3jpc70k5ydce6h
Use content-hub for clipboard services

And remove our own implementation of such service (LP: #1471998)

Approved by: Michael Terry

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2014-2015 Canonical, Ltd.
 
2
 * Copyright (C) 2014-2016 Canonical, Ltd.
3
3
 *
4
4
 * This program is free software: you can redistribute it and/or modify it under
5
5
 * the terms of the GNU Lesser General Public License version 3, as published by
18
18
#define QTMIR_CLIPBOARD_H
19
19
 
20
20
#include <qpa/qplatformclipboard.h>
21
 
#include <QObject>
 
21
 
 
22
#include <QMimeData>
 
23
#include <QScopedPointer>
 
24
 
 
25
namespace com {
 
26
    namespace ubuntu {
 
27
        namespace content {
 
28
            class Hub;
 
29
        }
 
30
    }
 
31
}
 
32
 
 
33
class QDBusPendingCallWatcher;
22
34
 
23
35
namespace qtmir {
24
36
 
25
 
class DBusClipboard : public QObject {
26
 
    Q_OBJECT
27
 
    Q_CLASSINFO("D-Bus Interface", "com.canonical.QtMir.Clipboard")
28
 
public:
29
 
    DBusClipboard(QObject *parent = nullptr);
30
 
    virtual ~DBusClipboard() {}
31
 
 
32
 
    void setContents(QByteArray contents);
33
 
    const QByteArray &contents() const { return m_contents; }
34
 
 
35
 
    static const int maxContentsSize = 4 * 1024 * 1024;  // 4 Mb
36
 
 
37
 
    // To make it testable
38
 
    static bool skipDBusRegistration;
39
 
 
40
 
Q_SIGNALS:
41
 
    Q_SCRIPTABLE void ContentsChanged(const QByteArray &contents);
42
 
    void contentsChangedRemotely();
43
 
 
44
 
public Q_SLOTS:
45
 
    Q_SCRIPTABLE QByteArray GetContents() const;
46
 
    Q_SCRIPTABLE void SetContents(QByteArray contents);
47
 
 
48
 
private:
49
 
    void performDBusRegistration();
50
 
    bool setContentsHelper(QByteArray newContents);
51
 
 
52
 
    // Contains a serialized QMimeData
53
 
    // Serialization and deserialization is done by the QPlatformClipboard
54
 
    // implementation.
55
 
    QByteArray m_contents;
56
 
};
57
 
 
58
37
class Clipboard : public QObject, public QPlatformClipboard
59
38
{
60
39
    Q_OBJECT
61
40
public:
62
 
    Clipboard(QObject *parent = nullptr);
63
 
    virtual ~Clipboard() {}
64
 
 
65
 
    QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard) override;
66
 
    void setMimeData(QMimeData *data, QClipboard::Mode mode) override;
67
 
 
68
 
    void setupDBusService();
69
 
 
70
 
private Q_SLOTS:
71
 
    void setMimeDataWithDBusClibpboardContents();
 
41
    Clipboard();
 
42
    virtual ~Clipboard();
 
43
 
 
44
    // QPlatformClipboard methods.
 
45
    QMimeData* mimeData(QClipboard::Mode mode = QClipboard::Clipboard) override;
 
46
    void setMimeData(QMimeData* data, QClipboard::Mode mode = QClipboard::Clipboard) override;
 
47
    bool supportsMode(QClipboard::Mode mode) const override;
 
48
    bool ownsMode(QClipboard::Mode mode) const override;
72
49
 
73
50
private:
74
 
 
75
 
    DBusClipboard *m_dbusClipboard;
 
51
    void updateMimeData();
 
52
    void requestMimeData();
 
53
 
 
54
    QScopedPointer<QMimeData> m_mimeData;
 
55
 
 
56
    enum {
 
57
        OutdatedClipboard, // Our mimeData is outdated, need to fetch latest from ContentHub
 
58
        SyncingClipboard, // Our mimeData is outdated and we are waiting for ContentHub to reply with the latest paste
 
59
        SyncedClipboard // Our mimeData is in sync with what ContentHub has
 
60
    } m_clipboardState{OutdatedClipboard};
 
61
 
 
62
    com::ubuntu::content::Hub *m_contentHub;
 
63
 
 
64
    QDBusPendingCallWatcher *m_pasteReply{nullptr};
76
65
};
77
66
 
78
 
// NB: Copied from qtubuntu. Must be kept in sync with the original version!
79
 
// Best thing would be to share this code somehow, but not bothering with it right now
80
 
// as the clipboard will move to content-hub at some point.
81
 
QByteArray serializeMimeData(QMimeData *mimeData);
82
 
QMimeData *deserializeMimeData(const QByteArray &serializedMimeData);
83
 
 
84
67
} // namespace qtmir
85
68
 
86
69
#endif // QTMIR_CLIPBOARD_H