Qt 4.8
Public Functions | Static Public Functions | Public Variables | Static Public Variables | List of all members
QWaylandSelection Struct Reference
Inheritance diagram for QWaylandSelection:

Public Functions

 QWaylandSelection (QWaylandDisplay *display, QMimeData *data)
 
 ~QWaylandSelection ()
 

Static Public Functions

static void cancelled (void *data, struct wl_selection *selection)
 
static uint32_t getTime ()
 
static void send (void *data, struct wl_selection *selection, const char *mime_type, int fd)
 

Public Variables

QMimeDatamMimeData
 
struct wl_selection * mSelection
 

Static Public Variables

static const struct wl_selection_listener selectionListener
 

Detailed Description

Definition at line 93 of file qwaylandclipboard.cpp.

Constructors and Destructors

◆ QWaylandSelection()

QWaylandSelection::QWaylandSelection ( QWaylandDisplay display,
QMimeData data 
)

Definition at line 120 of file qwaylandclipboard.cpp.

121  : mMimeData(data), mSelection(0)
122 {
123  struct wl_shell *shell = display->wl_shell();
124  mSelection = wl_shell_create_selection(shell);
125  wl_selection_add_listener(mSelection, &selectionListener, this);
126  foreach (const QString &format, data->formats())
127  wl_selection_offer(mSelection, format.toLatin1().constData());
128  wl_selection_activate(mSelection,
129  display->inputDevices().at(0)->wl_input_device(),
130  getTime());
131 }
virtual QStringList formats() const
Returns a list of formats supported by the object.
Definition: qmimedata.cpp:579
struct wl_input_device * wl_input_device() const
The QString class provides a Unicode character string.
Definition: qstring.h:83
static uint32_t getTime()
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static const struct wl_selection_listener selectionListener
struct wl_shell * wl_shell() const
struct wl_selection * mSelection
QList< QWaylandInputDevice * > inputDevices() const

◆ ~QWaylandSelection()

QWaylandSelection::~QWaylandSelection ( )

Definition at line 133 of file qwaylandclipboard.cpp.

134 {
135  if (mSelection) {
137  wl_selection_destroy(mSelection);
138  }
139  delete mMimeData;
140 }
static QWaylandClipboard * clipboard
void unregisterSelection(QWaylandSelection *selection)
struct wl_selection * mSelection

Functions

◆ cancelled()

void QWaylandSelection::cancelled ( void *  data,
struct wl_selection *  selection 
)
static

Definition at line 159 of file qwaylandclipboard.cpp.

160 {
161  Q_UNUSED(selection);
162  delete static_cast<QWaylandSelection *>(data);
163 }
static const char * data(const QByteArray &arr)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ getTime()

uint32_t QWaylandSelection::getTime ( )
static

Definition at line 113 of file qwaylandclipboard.cpp.

Referenced by QWaylandSelection().

114 {
115  struct timeval tv;
116  gettimeofday(&tv, 0);
117  return tv.tv_sec * 1000 + tv.tv_usec / 1000;
118 }

◆ send()

void QWaylandSelection::send ( void *  data,
struct wl_selection *  selection,
const char *  mime_type,
int  fd 
)
static

Definition at line 142 of file qwaylandclipboard.cpp.

146 {
147  Q_UNUSED(selection);
148  QWaylandSelection *self = static_cast<QWaylandSelection *>(data);
149  QString mimeType = QString::fromLatin1(mime_type);
150  QByteArray content = self->mMimeData->data(mimeType);
151  if (!content.isEmpty()) {
152  QFile f;
153  if (f.open(fd, QIODevice::WriteOnly))
154  f.write(content);
155  }
156  close(fd);
157 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition: qfile.cpp:1064
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char * data(const QByteArray &arr)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

Properties

◆ mMimeData

QMimeData* QWaylandSelection::mMimeData

Definition at line 104 of file qwaylandclipboard.cpp.

Referenced by QWaylandClipboard::mimeData(), and ~QWaylandSelection().

◆ mSelection

struct wl_selection* QWaylandSelection::mSelection

Definition at line 105 of file qwaylandclipboard.cpp.

Referenced by QWaylandSelection(), and ~QWaylandSelection().

◆ selectionListener

const struct wl_selection_listener QWaylandSelection::selectionListener
static

Definition at line 102 of file qwaylandclipboard.cpp.

Referenced by QWaylandSelection().


The documentation for this struct was generated from the following file: