Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[clipboard] Disable mimeData checking before copying
mimeData always null if clipboard is empty
  • Loading branch information
CODeRUS committed Jan 17, 2014
1 parent 349b189 commit 9073480
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 39 deletions.
53 changes: 23 additions & 30 deletions terminal.cpp
Expand Up @@ -1283,38 +1283,31 @@ void Terminal::copySelectionToClipboard()
if (selection().isNull())
return;

//mimeData() could be null when the clipboard QPA plugin of the platform doesn't support QClipboard::Clipboard, or
//the plugin is bugged.
//In those cases, disable clipboard features.
QClipboard *cb = QGuiApplication::clipboard();
if(!cb->mimeData())
qDebug() << "FIXME: QClipboard::mimeData() returned NULL, the clipboard functionality will not be used";
else {
cb->clear();

QString text;
QString line;

// backbuffer
if (iBackBufferScrollPos > 0 && !iUseAltScreenBuffer) {
int lineFrom = iBackBuffer.size() - iBackBufferScrollPos + selection().top() - 1;
int lineTo = iBackBuffer.size() - iBackBufferScrollPos + selection().bottom() - 1;

for (int i=lineFrom; i<=lineTo; i++) {
if (i >= 0 && i < iBackBuffer.size()) {
line.clear();
int start = 0;
int end = iBackBuffer[i].size()-1;
if (i==lineFrom)
start = selection().left()-1;
if (i==lineTo)
end = selection().right()-1;
for (int j=start; j<=end; j++) {
if (j >= 0 && j < iBackBuffer[i].size() && iBackBuffer[i][j].c.isPrint())
line += iBackBuffer[i][j].c;
}
text += line.trimmed() + "\n";
cb->clear();

QString text;
QString line;

// backbuffer
if (iBackBufferScrollPos > 0 && !iUseAltScreenBuffer) {
int lineFrom = iBackBuffer.size() - iBackBufferScrollPos + selection().top() - 1;
int lineTo = iBackBuffer.size() - iBackBufferScrollPos + selection().bottom() - 1;

for (int i=lineFrom; i<=lineTo; i++) {
if (i >= 0 && i < iBackBuffer.size()) {
line.clear();
int start = 0;
int end = iBackBuffer[i].size()-1;
if (i==lineFrom)
start = selection().left()-1;
if (i==lineTo)
end = selection().right()-1;
for (int j=start; j<=end; j++) {
if (j >= 0 && j < iBackBuffer[i].size() && iBackBuffer[i][j].c.isPrint())
line += iBackBuffer[i][j].c;
}
text += line.trimmed() + "\n";
}
}

Expand Down
12 changes: 3 additions & 9 deletions util.cpp
Expand Up @@ -367,15 +367,9 @@ void Util::notifyText(QString text)
void Util::copyTextToClipboard(QString str)
{
QClipboard *cb = QGuiApplication::clipboard();
//mimeData() could be null when the clipboard QPA plugin of the platform doesn't support QClipboard::Clipboard, or
//the plugin is bugged.
//In those cases, disable clipboard features.
if(!cb->mimeData())
qDebug() << "FIXME: QClipboard::mimeData() returned NULL, the clipboard functionality will not be used";
else {
cb->clear();
cb->setText(str);
}

cb->clear();
cb->setText(str);
}

bool Util::terminalHasSelection()
Expand Down

0 comments on commit 9073480

Please sign in to comment.