38
38
setAcceptDrops(true);
42
LauncherView::getEventUrls(QDropEvent* event)
44
const QMimeData* mimeData = event->mimeData();
45
if (mimeData->hasUrls()) {
46
return mimeData->urls();
48
else if (mimeData->hasText()) {
49
/* When dragging an URL from firefox’s address bar, it is properly
50
recognized as such by the event. However, the same doesn’t work
51
for chromium: the URL is recognized as plain text.
52
We cope with this unfriendly behaviour by trying to build a URL out
53
of the text. This assumes there’s only one URL. */
54
QString text = mimeData->text();
56
if (url.isRelative()) {
57
/* On top of that, chromium sometimes chops off the scheme… */
58
url = QUrl("http://" + text);
41
70
void LauncherView::dragEnterEvent(QDragEnterEvent *event)
43
// Check that data has a list of URLs and that at least one is
45
if (!event->mimeData()->hasUrls()) return;
47
foreach (QUrl url, event->mimeData()->urls()) {
48
if (url.scheme() == "file" && url.path().endsWith(".desktop")) {
72
// Check that data has a list of URLs and that at least one is either
73
// a desktop file or a web page.
74
QList<QUrl> urls = getEventUrls(event);
80
foreach (QUrl url, urls) {
81
if ((url.scheme() == "file" && url.path().endsWith(".desktop")) ||
82
url.scheme().startsWith("http")) {
49
83
event->acceptProposedAction();
62
96
bool accepted = false;
64
foreach (QUrl url, event->mimeData()->urls()) {
98
QList<QUrl> urls = getEventUrls(event);
99
foreach (QUrl url, urls) {
65
100
if (url.scheme() == "file" && url.path().endsWith(".desktop")) {
66
101
emit desktopFileDropped(url.path());
104
else if (url.scheme().startsWith("http")) {
105
emit webpageUrlDropped(url);
71
110
if (accepted) event->accept();