Changeset View
Changeset View
Standalone View
Standalone View
xwl/transfer.cpp
Show First 20 Lines • Show All 345 Lines • ▼ Show 20 Line(s) | 331 | { | |||
---|---|---|---|---|---|
346 | } | 346 | } | ||
347 | if (m_receiver) { | 347 | if (m_receiver) { | ||
348 | // second selection notify element - misbehaving source | 348 | // second selection notify element - misbehaving source | ||
349 | 349 | | |||
350 | // TODO: cancel this transfer? | 350 | // TODO: cancel this transfer? | ||
351 | return True; | 351 | return True; | ||
352 | } | 352 | } | ||
353 | 353 | | |||
354 | if (event->target == atoms->netscape_url) { | ||||
355 | m_receiver = new NetscapeUrlReceiver; | ||||
356 | } else if (event->target == atoms->moz_url) { | ||||
357 | m_receiver = new MozUrlReceiver; | ||||
358 | } else { | ||||
354 | m_receiver = new DataReceiver; | 359 | m_receiver = new DataReceiver; | ||
360 | } | ||||
355 | startTransfer(); | 361 | startTransfer(); | ||
356 | return true; | 362 | return true; | ||
357 | } | 363 | } | ||
358 | 364 | | |||
359 | void TransferXtoWl::startTransfer() | 365 | void TransferXtoWl::startTransfer() | ||
360 | { | 366 | { | ||
361 | auto *xcbConn = kwinApp()->x11Connection(); | 367 | auto *xcbConn = kwinApp()->x11Connection(); | ||
362 | auto cookie = xcb_get_property(xcbConn, | 368 | auto cookie = xcb_get_property(xcbConn, | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 463 | { | |||
458 | m_propertyStart += length; | 464 | m_propertyStart += length; | ||
459 | if (m_propertyStart == m_data.size()) { | 465 | if (m_propertyStart == m_data.size()) { | ||
460 | Q_ASSERT(m_propertyReply); | 466 | Q_ASSERT(m_propertyReply); | ||
461 | free(m_propertyReply); | 467 | free(m_propertyReply); | ||
462 | m_propertyReply = nullptr; | 468 | m_propertyReply = nullptr; | ||
463 | } | 469 | } | ||
464 | } | 470 | } | ||
465 | 471 | | |||
472 | void NetscapeUrlReceiver::setData(char *value, int length) | ||||
473 | { | ||||
474 | auto origData = QByteArray::fromRawData(value, length); | ||||
475 | | ||||
476 | if (origData.indexOf('\n') == -1) { | ||||
477 | // there are no line breaks, not in Netscape url format or empty, | ||||
478 | // but try anyway | ||||
479 | setDataInternal(origData); | ||||
480 | return; | ||||
481 | } | ||||
482 | // remove every second line | ||||
483 | QByteArray data; | ||||
484 | int start = 0; | ||||
485 | bool remLine = false; | ||||
486 | while (start < length) { | ||||
487 | auto part = QByteArray::fromRawData(value + start, length - start); | ||||
488 | const int linebreak = part.indexOf('\n'); | ||||
489 | if (linebreak == -1) { | ||||
490 | // no more linebreaks, end of work | ||||
491 | if (!remLine) { | ||||
492 | // append the rest | ||||
493 | data.append(part); | ||||
494 | } | ||||
495 | break; | ||||
496 | } | ||||
497 | if (remLine) { | ||||
498 | // no data to add, but add a linebreak for the next line | ||||
499 | data.append('\n'); | ||||
500 | } else { | ||||
501 | // add data till before linebreak | ||||
502 | data.append(part.data(), linebreak); | ||||
503 | } | ||||
504 | remLine = !remLine; | ||||
505 | start = linebreak + 1; | ||||
506 | } | ||||
zzag: Could you please clarify format of NETSCAPE_URL? According to https://chromium.googlesource. | |||||
507 | setDataInternal(data); | ||||
508 | } | ||||
509 | | ||||
510 | void MozUrlReceiver::setData(char *value, int length) | ||||
511 | { | ||||
512 | // represent as QByteArray (guaranteed '\0'-terminated) | ||||
513 | const auto origData = QByteArray::fromRawData(value, length); | ||||
514 | | ||||
515 | // text/x-moz-url data is sent in utf-16 - copies the content | ||||
516 | // and converts it into 8 byte representation | ||||
517 | const auto byteData = QString::fromUtf16(reinterpret_cast<const char16_t*>(origData.data())).toLatin1(); | ||||
518 | | ||||
519 | if (byteData.indexOf('\n') == -1) { | ||||
520 | // there are no line breaks, not in text/x-moz-url format or empty, | ||||
521 | // but try anyway | ||||
522 | setDataInternal(byteData); | ||||
523 | return; | ||||
524 | } | ||||
525 | // remove every second line | ||||
526 | QByteArray data; | ||||
527 | int start = 0; | ||||
528 | bool remLine = false; | ||||
529 | while (start < length) { | ||||
530 | auto part = QByteArray::fromRawData(byteData.data() + start, byteData.size() - start); | ||||
531 | const int linebreak = part.indexOf('\n'); | ||||
532 | if (linebreak == -1) { | ||||
533 | // no more linebreaks, end of work | ||||
534 | if (!remLine) { | ||||
535 | // append the rest | ||||
536 | data.append(part); | ||||
537 | } | ||||
538 | break; | ||||
539 | } | ||||
540 | if (remLine) { | ||||
541 | // no data to add, but add a linebreak for the next line | ||||
542 | data.append('\n'); | ||||
543 | } else { | ||||
544 | // add data till before linebreak | ||||
545 | data.append(part.data(), linebreak); | ||||
546 | } | ||||
547 | remLine = !remLine; | ||||
548 | start = linebreak + 1; | ||||
549 | } | ||||
550 | setDataInternal(data); | ||||
551 | } | ||||
552 | | ||||
466 | void TransferXtoWl::dataSourceWrite() | 553 | void TransferXtoWl::dataSourceWrite() | ||
467 | { | 554 | { | ||
468 | QByteArray property = m_receiver->data(); | 555 | QByteArray property = m_receiver->data(); | ||
469 | 556 | | |||
470 | ssize_t len = write(fd(), property.constData(), property.size()); | 557 | ssize_t len = write(fd(), property.constData(), property.size()); | ||
471 | if (len == -1) { | 558 | if (len == -1) { | ||
472 | qCWarning(KWIN_XWL) << "X11 to Wayland write error on fd:" << fd(); | 559 | qCWarning(KWIN_XWL) << "X11 to Wayland write error on fd:" << fd(); | ||
473 | endTransfer(); | 560 | endTransfer(); | ||
Show All 33 Lines |
Could you please clarify format of NETSCAPE_URL? According to https://chromium.googlesource.com/chromium/src/+/3624c6c095108839db78c01dce92c731cf10b954/ui/base/dragdrop/os_exchange_data_provider_aurax11.cc#178 it looks we don't need this loop.
Why do we have to remove each second line?