~sil2100/unity-2d/bump_new_nux_libunity

« back to all changes in this revision

Viewing changes to launcher/app/launcherview.cpp

  • Committer: Florian Boucault
  • Date: 2011-02-10 14:40:03 UTC
  • mfrom: (359.2.44 maverick)
  • Revision ID: florian@boucault.net-20110210144003-6hhny3axzwvty3h2
Merged from 'maverick' branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    setAcceptDrops(true);
39
39
}
40
40
 
 
41
QList<QUrl>
 
42
LauncherView::getEventUrls(QDropEvent* event)
 
43
{
 
44
    const QMimeData* mimeData = event->mimeData();
 
45
    if (mimeData->hasUrls()) {
 
46
        return mimeData->urls();
 
47
    }
 
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();
 
55
        QUrl url(text);
 
56
        if (url.isRelative()) {
 
57
            /* On top of that, chromium sometimes chops off the scheme… */
 
58
            url = QUrl("http://" + text);
 
59
        }
 
60
        if (url.isValid()) {
 
61
            QList<QUrl> urls;
 
62
            urls.append(url);
 
63
            return urls;
 
64
        }
 
65
    }
 
66
 
 
67
    return QList<QUrl>();
 
68
}
 
69
 
41
70
void LauncherView::dragEnterEvent(QDragEnterEvent *event)
42
71
{
43
 
    // Check that data has a list of URLs and that at least one is
44
 
    // a desktop file.
45
 
    if (!event->mimeData()->hasUrls()) return;
46
 
 
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);
 
75
 
 
76
    if (urls.isEmpty()) {
 
77
        return;
 
78
    }
 
79
 
 
80
    foreach (QUrl url, urls) {
 
81
        if ((url.scheme() == "file" && url.path().endsWith(".desktop")) ||
 
82
            url.scheme().startsWith("http")) {
49
83
            event->acceptProposedAction();
50
84
            break;
51
85
        }
61
95
{
62
96
    bool accepted = false;
63
97
 
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());
67
102
            accepted = true;
68
103
        }
 
104
        else if (url.scheme().startsWith("http")) {
 
105
            emit webpageUrlDropped(url);
 
106
            accepted = true;
 
107
        }
69
108
    }
70
109
 
71
110
    if (accepted) event->accept();