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

List:       kde-panel-devel
Subject:    Re: Code snippet review for plasmate
From:       "Aaron J. Seigo" <aseigo () kde ! org>
Date:       2009-05-10 0:59:14
Message-ID: 200905091859.20438.aseigo () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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

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


["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