Code snippet review for plasmate

Shantanu Tushar Jha jhahoneyk at gmail.com
Mon May 11 19:44:56 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.
>

I'm not that experienced in Qt, so had a doubt-
There are some roles defined in the Qt namespace, but there isn't one for
MimeType. So, how to declare a new role in PackageModel (I think that will
be in packagemodel.h) ?


>
> 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
> =======
>
> 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 &)


Understood, I've renamed it.

>
>
> --
> 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/20090511/cd5427b3/attachment.htm 


More information about the Plasma-devel mailing list