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

List:       kde-panel-devel
Subject:    Re: Code snippet review for plasmate
From:       Shantanu Tushar Jha <jhahoneyk () gmail ! com>
Date:       2009-05-14 15:22:46
Message-ID: ec556b640905140810w7987940cq9841698664b077ee () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Sun, May 10, 2009 at 6:29 AM, Aaron J. Seigo <aseigo@kde.org> wrote:

> On Saturday 09 May 2009, Shantanu Tushar Jha wrote:
> > I looked at the techbase about kparts and studied kwrite code a bit, and
> > finally started to try with embedding a text editing kpart in Plasmate.
> > I know there's a lot to be done. Just to make sure if I'm going in the
> > right direction and to find possible problems, I've attached a patch that
>
> the "correct" way to do this would be to make PackageModel::data suck less
> ;)
>
> there should be a MimeType role in PackageModel and when data is called for
> the MimeType it should return the mimetype from the package.
>
> so slotTreeActivated[1] would do something like:
>
> QStringList mimetypes = index->model()->data(index,
> PackageModel::MimeTypeRole);
>
>
> and in PackageModel::data, if it's a leaf node, e.g. a script, then it
> should
> do:
>
> return m_package->structure()->mimetypes(key);
>
> then based on the mimetypes you can query for the kpart associated with it;
> sth like:
>
> ========
> foreach (const QString &mimetype, mimetypes) {
>     KService::List offers = KMimeTypeTrader::self()->query(mimetype,
> "KParts/ReadWritePart");
>
>    if (offers.isEmpty()) {
>        offers = KMimeTypeTrader::self()->query(mimetype,
> "KParts/ReadOnlyPart");
>    }
>
>    if (!offers.isEmpty()) {
>         // create the part using offers.at(0)
>         return;
>    }
> }
>
> // report an error that we can't view this file type
> =======
>

I've tried this -

+    QStringList mimetypes =
index.data(PackageModel::MimeTypeRole).toStringList();

+    foreach (const QString &mimetype, mimetypes)
{

+        KService::List offers = KMimeTypeTrader::self()->query(mimetype,
"KParts/ReadWritePart");
+       kDebug() <<
mimetype;

+        if (offers.isEmpty())
{

+            offers = KMimeTypeTrader::self()->query(mimetype,
"KParts/ReadOnlyPart");
+
}

+        if (!offers.isEmpty())
{

+            //create the part using offers.at(0)
+
return;

+
}

+
}

+    //emit treeActivated(index);

and I get the following output when I click New.. in each of the categories
in the Editor tree-

plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType
"text/xml" ,  "KParts/ReadWritePart"  : returning  1  offers
plasmate(25711) EditPage::findEditor: "text/xml"
plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType
"image/svg+xml" ,  "KParts/ReadWritePart"  : returning  1  offers
plasmate(25711) EditPage::findEditor: "image/svg+xml"
plasmate(25711)/kdecore (trader) mimeTypeSycocaServiceOffers:
KMimeTypeTrader: mimeType "text/*" not found
plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType
"text/*" ,  "KParts/ReadWritePart"  : returning  0  offers
plasmate(25711) EditPage::findEditor: "text/*"
plasmate(25711)/kdecore (trader) mimeTypeSycocaServiceOffers:
KMimeTypeTrader: mimeType "text/*" not found
plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType
"text/*" ,  "KParts/ReadOnlyPart"  : returning  0  offers
plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType
"text/xml" ,  "KParts/ReadWritePart"  : returning  1  offers
plasmate(25711) EditPage::findEditor: "text/xml"

As you can see it can't find any editors for "text/*" when I click New...
under "Executable scripts". I guess its not taking * as 'all matches', so
its not returning any offer. I'm not sure what to do for this, or what am I
missing. Suggestions ?


> that will get us a kpart that can edit the file if it exists, a
> viewing-only
> part if there are no kparts available that can do editing, or nothing at
> all
> if we don't have any available kparts.
>
> this will then work with _all_ file types in the model :)
>
>
> [1] as a side note, please don't preface slot names with "slot"; that's an
> implementation detail that may or may not change over time, just name it
> after
> what it's job is, e.g. "loadEditor(const QModelIndex &)
>
> --
> Aaron J. Seigo
> humru othro a kohnu se
> GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43
>
> KDE core developer sponsored by Qt Software
>
>
> _______________________________________________
> Plasma-devel mailing list
> Plasma-devel@kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>
>


-- 
Shantanu Tushar    (GMT +0530)
http://www.shantanutushar.com

[Attachment #5 (text/html)]

<br><br><div class="gmail_quote">On Sun, May 10, 2009 at 6:29 AM, Aaron J. Seigo \
<span dir="ltr">&lt;<a href="mailto:aseigo@kde.org" \
target="_blank">aseigo@kde.org</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;">

<div>On Saturday 09 May 2009, Shantanu Tushar Jha wrote:<br>
&gt; I looked at the techbase about kparts and studied kwrite code a bit, and<br>
&gt; finally started to try with embedding a text editing kpart in Plasmate.<br>
&gt; I know there&#39;s a lot to be done. Just to make sure if I&#39;m going in \
the<br> &gt; right direction and to find possible problems, I&#39;ve attached a patch \
that<br> <br>
</div>the &quot;correct&quot; way to do this would be to make PackageModel::data suck \
less ;)<br> <br>
there should be a MimeType role in PackageModel and when data is called for<br>
the MimeType it should return the mimetype from the package.<br>
<br>
so slotTreeActivated[1] would do something like:<br>
<br>
QStringList mimetypes = index-&gt;model()-&gt;data(index,<br>
PackageModel::MimeTypeRole);<br>
<br>
<br>
and in PackageModel::data, if it&#39;s a leaf node, e.g. a script, then it should<br>
do:<br>
<br>
return m_package-&gt;structure()-&gt;mimetypes(key);<br>
<br>
then based on the mimetypes you can query for the kpart associated with it;<br>
sth like:<br>
<br>
========<br>
foreach (const QString &amp;mimetype, mimetypes) {<br>
     KService::List offers = KMimeTypeTrader::self()-&gt;query(mimetype,<br>
&quot;KParts/ReadWritePart&quot;);<br>
<br>
    if (offers.isEmpty()) {<br>
        offers = KMimeTypeTrader::self()-&gt;query(mimetype,<br>
&quot;KParts/ReadOnlyPart&quot;);<br>
    }<br>
<br>
    if (!offers.isEmpty()) {<br>
         // create the part using <a href="http://offers.at" \
target="_blank">offers.at</a>(0)<br>  return;<br>
    }<br>
}<br>
<br>
// report an error that we can&#39;t view this file type<br>
=======<br>
</blockquote><div><br>I&#39;ve tried this -<br><br>+    QStringList mimetypes = \
index.data(PackageModel::MimeTypeRole).toStringList();                                \
<br>+    foreach (const QString &amp;mimetype, mimetypes) {                           \
<br> +        KService::List offers = KMimeTypeTrader::self()-&gt;query(mimetype, \
&quot;KParts/ReadWritePart&quot;);                               <br>+       kDebug() \
&lt;&lt; mimetype;                                                                    \
<br> +        if (offers.isEmpty()) {                                                 \
<br>+            offers = KMimeTypeTrader::self()-&gt;query(mimetype, \
&quot;KParts/ReadOnlyPart&quot;);                                           <br> +    \
}                                                                                     \
<br>+        if (!offers.isEmpty()) {                                                 \
<br> +            //create the part using <a \
href="http://offers.at">offers.at</a>(0)<br>+        return;                          \
<br>+        }                                                                        \
<br> +    }                                                                           \
<br>+    //emit treeActivated(index);<br><br>and I get the following output when I \
click New.. in each of the categories in the Editor tree-<br> \
<br>plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType  \
&quot;text/xml&quot; ,  &quot;KParts/ReadWritePart&quot;  : returning  1  offers<br> \
plasmate(25711) EditPage::findEditor: &quot;text/xml&quot;<br>plasmate(25711)/kdecore \
(trader) KMimeTypeTrader::query: query for mimeType  &quot;image/svg+xml&quot; ,  \
&quot;KParts/ReadWritePart&quot;  : returning  1  offers<br>

plasmate(25711) EditPage::findEditor: \
&quot;image/svg+xml&quot;<br>plasmate(25711)/kdecore (trader) \
mimeTypeSycocaServiceOffers: KMimeTypeTrader: mimeType &quot;text/*&quot; not \
found<br>plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType  \
&quot;text/*&quot; ,  &quot;KParts/ReadWritePart&quot;  : returning  0  offers<br>

plasmate(25711) EditPage::findEditor: &quot;text/*&quot;<br>plasmate(25711)/kdecore \
(trader) mimeTypeSycocaServiceOffers: KMimeTypeTrader: mimeType &quot;text/*&quot; \
not found<br>plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for \
mimeType  &quot;text/*&quot; ,  &quot;KParts/ReadOnlyPart&quot;  : returning  0  \
offers<br>

plasmate(25711)/kdecore (trader) KMimeTypeTrader::query: query for mimeType  \
&quot;text/xml&quot; ,  &quot;KParts/ReadWritePart&quot;  : returning  1  \
offers<br>plasmate(25711) EditPage::findEditor: &quot;text/xml&quot;<br>

<br>As you can see it can&#39;t find any editors for &quot;text/*&quot; when I click \
New... under &quot;Executable scripts&quot;. I guess its not taking * as &#39;all \
matches&#39;, so its not returning any offer. I&#39;m not sure what to do for this, \
or what am I missing. Suggestions ?<br> <br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, \
204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br> that will get us a kpart \
that can edit the file if it exists, a viewing-only<br> part if there are no kparts \
available that can do editing, or nothing at all<br> if we don&#39;t have any \
available kparts.<br> <br>
this will then work with _all_ file types in the model :)<br>
<br>
<br>
[1] as a side note, please don&#39;t preface slot names with &quot;slot&quot;; \
that&#39;s an<br> implementation detail that may or may not change over time, just \
name it after<br> what it&#39;s job is, e.g. &quot;loadEditor(const QModelIndex \
&amp;)<br> <font color="#888888"><br>
--<br>
Aaron J. Seigo<br>
humru othro a kohnu se<br>
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43<br>
<br>
KDE core developer sponsored by Qt Software<br>
<br>
</font><br>_______________________________________________<br>
Plasma-devel mailing list<br>
<a href="mailto:Plasma-devel@kde.org" target="_blank">Plasma-devel@kde.org</a><br>
<a href="https://mail.kde.org/mailman/listinfo/plasma-devel" \
target="_blank">https://mail.kde.org/mailman/listinfo/plasma-devel</a><br> \
<br></blockquote></div><br><br clear="all"><br>-- <br>Shantanu Tushar    (GMT \
+0530)<br><a href="http://www.shantanutushar.com" \
target="_blank">http://www.shantanutushar.com</a><br>



_______________________________________________
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