Code snippet review for plasmate

Shantanu Tushar Jha jhahoneyk at gmail.com
Thu May 14 17:10:46 CEST 2009


On Sun, May 10, 2009 at 6:29 AM, Aaron J. Seigo <aseigo at 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 at kde.org
> https://mail.kde.org/mailman/listinfo/plasma-devel
>
>


-- 
Shantanu Tushar    (GMT +0530)
http://www.shantanutushar.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/plasma-devel/attachments/20090514/db5e33e5/attachment-0001.htm 


More information about the Plasma-devel mailing list