[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-panel-devel
Subject:    Re: dropped URL handling in containment,
From:       Sebastian =?iso-8859-15?q?K=FCgler?= <sebas () kde ! org>
Date:       2009-10-28 1:23:08
Message-ID: 200910280223.14613.sebas () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Tuesday 27 October 2009 17:19:24 Aaron J. Seigo wrote:
>   On October 27, 2009, Sebastian Kügler wrote:
> > Is this something I should pursue? It sounds simple enough ...
> 
> sure; i don't see any downside to it and the results could be interesting; 
> worst case is we'd have a failed experimnt on our hands and one more way
>  not  to do it (in the words of Edison ;) but i think this could work out
>  very well..

The attached patch seems to work. I've not really tested it, just confirmed that it 
works at least in one case (emailmessage, added X-Plasma-DropUrlPatterns=akonadi:* to 
its desktop file) -- it's late and I should sleep. If it's conceptually OK, I'll 
clean it up and submit it to review board.

Cheers,
-- 
sebas

 http://www.kde.org | http://vizZzion.org |  GPG Key ID: 9119 0EF9 

["plasma-containment-dropurlpatterns.diff" (text/x-patch)]

Index: applet.h
===================================================================
--- applet.h	(revision 1041410)
+++ applet.h	(working copy)
@@ -306,6 +306,13 @@
         static KPluginInfo::List listAppletInfoForMimetype(const QString &mimetype);
 
         /**
+         * Returns a list of all known applets associated with a certain URL.
+         *
+         * @return list of applets
+         **/
+        static KPluginInfo::List listAppletInfoForUrl(const QUrl &url);
+
+        /**
          * Returns a list of all the categories used by installed applets.
          *
          * @param parentApp the application to filter applets on. Uses the
Index: applet.cpp
===================================================================
--- applet.cpp	(revision 1041410)
+++ applet.cpp	(working copy)
@@ -37,6 +37,7 @@
 #include <QList>
 #include <QGraphicsLinearLayout>
 #include <QPainter>
+#include <QRegExp>
 #include <QSize>
 #include <QStyleOptionGraphicsItem>
 #include <QTextDocument>
@@ -2074,6 +2075,32 @@
     return KPluginInfo::fromServices(offers);
 }
 
+KPluginInfo::List Applet::listAppletInfoForUrl(const QUrl &url)
+{
+    QString constraint;
+    //kDebug() << "listAppletInfoForMimetype with" << mimetype << constraint;
+    KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", \
constraint); +    offers << KServiceTypeTrader::self()->query("Plasma/PopupApplet", \
constraint); +
+    KPluginInfo::List allApplets = KPluginInfo::fromServices(offers);
+    KPluginInfo::List filtered;
+    foreach (const KPluginInfo &info, allApplets) {
+        kDebug() << "=========>URL" << info.name() << \
info.property("X-Plasma-DropUrlPatterns").toStringList(); +        QStringList \
urlPatterns = info.property("X-Plasma-DropUrlPatterns").toStringList(); +        \
foreach (const QString &glob, urlPatterns) { +            QRegExp rx(glob);
+            rx.setPatternSyntax(QRegExp::Wildcard);
+            if (rx.exactMatch(url.toString())) {
+                kDebug() << "showing (match) ..." << glob << url;
+                filtered << info;
+            } else {
+                kDebug() << "No Match:" << glob << url;
+            }
+        }
+    }
+    return filtered;
+}
+
 QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
 {
     QString constraint = "exist [X-KDE-PluginInfo-Category]";
Index: private/containment_p.h
===================================================================
--- private/containment_p.h	(revision 1041410)
+++ private/containment_p.h	(working copy)
@@ -161,6 +161,7 @@
     Containment::Type type;
     QHash<KJob*, QPointF> dropPoints;
     QHash<KJob*, KMenu*> dropMenus;
+    QHash<KJob*, KPluginInfo::List> dropPlugins;
     QTimer *showDropZoneDelayTimer;
     bool drawWallpaper;
 };
Index: data/servicetypes/plasma-applet.desktop
===================================================================
--- data/servicetypes/plasma-applet.desktop	(revision 1041410)
+++ data/servicetypes/plasma-applet.desktop	(working copy)
@@ -76,6 +76,9 @@
 [PropertyDef::X-Plasma-DropMimeTypes]
 Type=QStringList
 
+[PropertyDef::X-Plasma-DropUrlPatterns]
+Type=QStringList
+
 [PropertyDef::X-Plasma-DefaultSize]
 Type=QSize
 
Index: containment.cpp
===================================================================
--- containment.cpp	(revision 1041410)
+++ containment.cpp	(working copy)
@@ -1296,6 +1296,7 @@
                 kDebug() << "can decode" << mimeName << args;
                 kDebug() << "protocol:" << url.protocol();
                 KPluginInfo::List appletList = \
Applet::listAppletInfoForMimetype(mimeName); +                appletList << \
Applet::listAppletInfoForUrl(url.url());  KPluginInfo::List wallpaperList;
                 if (q->drawWallpaper()) {
                     wallpaperList = \
Wallpaper::listWallpaperInfoForMimetype(mimeName); @@ -1305,6 +1306,7 @@
                 KIO::JobFlags flags = KIO::HideProgressInfo;
                 KIO::TransferJob *job = KIO::get(url, KIO::NoReload, flags);
                 dropPoints[job] = dropEvent->pos();
+                dropPlugins[job] = appletList;
                 QObject::connect(job, SIGNAL(result(KJob*)), q, \
                SLOT(dropJobResult(KJob*)));
                 QObject::connect(job, SIGNAL(mimetype(KIO::Job *, const QString&)),
                                  q, SLOT(mimeTypeRetrieved(KIO::Job *, const \
QString&))); @@ -1420,26 +1422,39 @@
 {
     if (job->error()) {
         // TODO: error feedback
-        clearDataForMimeJob(qobject_cast<KIO::Job *>(job));
         kDebug() << "ERROR" << job->error() << ' ' << job->errorString();
+        KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
+        if (!tjob) {
+            kDebug() << "job should be a TransferJob, but isn't";
+            clearDataForMimeJob(qobject_cast<KIO::Job *>(job));
+            return;
+        }
+        if (!dropPlugins.value(tjob).count()) {
+            kDebug() << "Cleaning up, no other plugins";
+            clearDataForMimeJob(qobject_cast<KIO::Job *>(job));
+            return;
+        }
+        mimeTypeRetrieved(qobject_cast<KIO::Job *>(job), QString());
     }
 }
 
 void ContainmentPrivate::mimeTypeRetrieved(KIO::Job *job, const QString &mimetype)
 {
     kDebug() << "Mimetype Job returns." << mimetype;
-    if (job->error()) {
+    KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
+    if (!tjob) {
+        kDebug() << "job should be a TransferJob, but isn't";
+        clearDataForMimeJob(job);
+        return;
+    }
+    KPluginInfo::List al = dropPlugins.value(tjob);
+    kDebug() << "plugins found already:" << al.count();
+    if (job->error() && !al.count()) {
         // TODO: error feedback
         clearDataForMimeJob(job);
         kDebug() << "ERROR" << job->error() << ' ' << job->errorString();
         return;
     } else {
-        KIO::TransferJob* tjob = dynamic_cast<KIO::TransferJob*>(job);
-        if (!tjob) {
-            kDebug() << "job should be a TransferJob, but isn't";
-            clearDataForMimeJob(job);
-            return;
-        }
 
         QPointF posi; // will be overwritten with the event's position
         if (dropPoints.keys().contains(tjob)) {
@@ -1463,8 +1478,11 @@
         args << tjob->url().url() << mimetype;
 
         kDebug() << "Creating menu for:" << mimetype  << posi << args;
-        KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(mimetype);
 
+        KPluginInfo::List appletList = dropPlugins.value(tjob);
+        appletList << Applet::listAppletInfoForMimetype(mimetype);
+        //appletList << Applet::listAppletInfoForUrl(tjob->url().url());
+
         KPluginInfo::List wallpaperList;
         if (q->drawWallpaper()) {
             wallpaperList = Wallpaper::listWallpaperInfoForMimetype(mimetype);
@@ -1514,9 +1532,10 @@
                 // Put the job on hold so it can be recycled to fetch the actual \
                content,
                 // which is to be expected when something's dropped onto the desktop \
and  // an applet is to be created with this URL
-                tjob->putOnHold();
-                KIO::Scheduler::publishSlaveOnHold();
-
+                if (!tjob->error()) {
+                    tjob->putOnHold();
+                    KIO::Scheduler::publishSlaveOnHold();
+                }
                 QString plugin = actionsToApplets.value(choice);
                 if (plugin.isEmpty()) {
                     //set wallpapery stuff


["signature.asc" (application/pgp-signature)]

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic