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

List:       kde-devel
Subject:    Re: Need help with Nepomuk Tags
From:       Christophe Olinger <olingerc () binarylooks ! com>
Date:       2010-06-07 11:51:45
Message-ID: AANLkTikieNbsFj0lK1r9bEtzxp--PkfwX1KLhR1LY3eP () mail ! gmail ! com
[Download RAW message or body]

On Mon, Jun 7, 2010 at 12:26 PM, Sebastian Trüg <trueg@kde.org> wrote:
> On 06/06/2010 10:08 AM, Christophe Olinger wrote:
>> I am trying to allow modifying Tags in plasma-mediacenter. I have a
>> label that displays tags and when the user clicks on that, the label
>> is replaced by a textbox which shows previous tags. The user can now
>> edit tags or add new ones separated by commas. Upon hitting enter, the
>> previous tags in the resource should be replaced by the new tags.
>> Displaying tags works nicely, and adding new tags also works. The
>> problem lies in the following code:
>>
>>     //Clear previous tags
>>     QList<Nepomuk::Tag> previousTags = resource->tags();
>>     foreach (Nepomuk::Tag tag, previousTags) {
>>         kWarning() << "Removing Tag:" << tag.label();
>>         tag.remove();
>>     }
>>
>> It doesn't clear the tags, at least not immediately. It seems they are
>> removed at a later point, but I am not really sure what happens. It
>> leaves tags without labels in the resource.
>
> Do you really want to delete tags here? I doubt that. I think what you
> want to do is removing the relation between the resource and the tags,
> i.e. simply call setTags() with a new list of tags.

Now that you say it like that, deleting tags indeed is a stupid idea,
since they can also apply to other resources. You shouldn't code after
midnight ;-) Separating them from this particular resource is what I
want. Thanks!

>
> As for the empty tags: that sounds like a bug and needs to be addressed.

I'll give you more details as soon as I am in front of my development
machine again


>
> And BTW: there is a nicer TagWidget in kdelibs now. You could also use that.
>

I'll certainly have a look whether it fits into what I want to accomplish.


>> I add new tags as follows:
>>
>>     //Add new tags
>>     foreach (QString tag, list) {
>>         if (tag != "" && tag != ",") {
>
> Always use QString::isEmpty() instead of comparing to an empty string.
> Also ',' or QLatin1String(",") is much better than a simple "," (just as
> a sidenote)
>
>>             Nepomuk::Tag nepomuktag("Tag" + tag + resource->identifierUri());
>
> please just use "tag" as id, i.e. set it to the same value as label.
>
>>             nepomuktag.setLabel(tag);
>>             resource->addTag(nepomuktag);
>>         }
>>     }
>
>
>> I use this code to display the tags in a label:
>>
>>     QList<Nepomuk::Tag> tags(resource->tags());
>>     QString tagList("");
>>     if (tags.isEmpty()) {
>>         tagList = "No Tags";
>>     }
>>     if (!tags.isEmpty()) {
>>         tagList = "Tags: ";
>>         foreach (Nepomuk::Tag tag, tags) {
>>             if (tag.label() != "") {
>>                 tagList = tagList + tag.label();
>
> I recommend Resource::genericLabel()
>
>>                 if (tag != tags.last()) {
>>                     tagList = tagList + QString(",");
>
> again: QLatin1String. And using QStringList::join is much cleaner here.



Thanks for the little coding tips. They are exactly the kind of tips I
need, since I did not study computer sciences and do not have a lot of
experience. I wish I could follow one of you experienced guys for one
day and look over your shoulders :-)

Thanks for your help,

Chris



>
> Cheers,
> Sebastian
>
>>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
>
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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