forked from hluk/CopyQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright (c) 2014, Lukas Holecek <[email protected]> | ||
This file is part of CopyQ. | ||
CopyQ is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
CopyQ is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with CopyQ. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef MACCLIPBOARD_H | ||
#define MACCLIPBOARD_H | ||
|
||
#include "platform/dummy/dummyclipboard.h" | ||
|
||
#include <QClipboard> | ||
|
||
class MacTimer; | ||
|
||
class MacClipboard : public DummyClipboard { | ||
Q_OBJECT | ||
public: | ||
explicit MacClipboard(); | ||
|
||
QVariantMap data(Mode mode, const QStringList &formats) const; | ||
|
||
signals: | ||
void changed(PlatformClipboard::Mode mode); | ||
|
||
private: | ||
long int m_prevChangeCount; | ||
MacTimer *m_clipboardCheckTimer; | ||
|
||
private slots: | ||
virtual void clipboardTimeout(); | ||
}; | ||
|
||
#endif // MACCLIPBOARD_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
Copyright (c) 2014, Lukas Holecek <[email protected]> | ||
This file is part of CopyQ. | ||
CopyQ is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
CopyQ is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with CopyQ. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "macclipboard.h" | ||
|
||
#include "common/common.h" | ||
#include "common/mimetypes.h" | ||
|
||
#include <QApplication> | ||
#include <QMimeData> | ||
#include <QClipboard> | ||
|
||
#include "mactimer.h" | ||
|
||
#include <Cocoa/Cocoa.h> | ||
#include <Carbon/Carbon.h> | ||
|
||
MacClipboard::MacClipboard(): | ||
m_prevChangeCount(0) | ||
, m_clipboardCheckTimer(new MacTimer(this)) { | ||
|
||
m_clipboardCheckTimer->setInterval(250); | ||
m_clipboardCheckTimer->setTolerance(500); | ||
|
||
connect(m_clipboardCheckTimer, SIGNAL(timeout()), this, SLOT(clipboardTimeout())); | ||
|
||
m_clipboardCheckTimer->start(); | ||
} | ||
|
||
QVariantMap MacClipboard::data(Mode mode, const QStringList &formats) const { | ||
Q_UNUSED(mode); | ||
|
||
// On OS X, when you copy files in Finder, etc. you get: | ||
// - The file name(s) (not paths) as plain text | ||
// - The file URI(s) | ||
// - The icon (not thumbnail) for the type of item you have in various image formants | ||
// We really only want the URI list, so throw the rest away | ||
|
||
QStringList macFormats = QStringList(formats); // Copy so we can modify | ||
if (mode == PlatformClipboard::Clipboard) { | ||
const QMimeData *data = clipboardData(QClipboard::Clipboard); | ||
|
||
if (data && data->formats().contains(mimeUriList) && macFormats.contains(mimeUriList)) { | ||
macFormats = QStringList() << mimeUriList; | ||
} | ||
} | ||
|
||
return DummyClipboard::data(mode, macFormats); | ||
} | ||
|
||
|
||
void MacClipboard::clipboardTimeout() { | ||
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; | ||
NSInteger newCount = [pasteboard changeCount]; | ||
|
||
if (newCount != m_prevChangeCount) { | ||
m_prevChangeCount = newCount; | ||
emit changed(PlatformClipboard::Clipboard); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters