The last part of typo fixes (I really hope)
[kdepim.git] / kmail / tag.cpp
bloba1f405278865d09a4bd4cc9d61e310f04984f661
1 /* Copyright 2010 Thomas McGuire <mcguire@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public License as
5 published by the Free Software Foundation; either version 2 of
6 the License or (at your option) version 3 or any later version
7 accepted by the membership of KDE e.V. (or its successor approved
8 by the membership of KDE e.V.), which shall act as a proxy
9 defined in Section 14 of version 3 of the license.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "tag.h"
21 #include "messagetag.h"
23 #include <Nepomuk/Tag>
24 #include <Nepomuk/Variant>
26 using namespace KMail;
28 Tag::Ptr Tag::fromNepomuk( const Nepomuk::Tag& nepomukTag )
30 Tag::Ptr tag( new Tag() );
31 tag->tagName = nepomukTag.label();
33 if ( nepomukTag.symbols().isEmpty() )
34 tag->iconName = "mail-tagged";
35 else
36 tag->iconName = nepomukTag.symbols().first();
38 tag->nepomukResourceUri = nepomukTag.resourceUri();
40 if ( nepomukTag.hasProperty( Vocabulary::MessageTag::textColor() ) ) {
41 const QString name = nepomukTag.property( Vocabulary::MessageTag::textColor() ).toString();
42 tag->textColor = QColor( name );
45 if ( nepomukTag.hasProperty( Vocabulary::MessageTag::backgroundColor() ) ) {
46 const QString name = nepomukTag.property( Vocabulary::MessageTag::backgroundColor() ).toString();
47 tag->backgroundColor = QColor( name );
50 if ( nepomukTag.hasProperty( Vocabulary::MessageTag::font() ) ) {
51 const QString fontString = nepomukTag.property( Vocabulary::MessageTag::font() ).toString();
52 QFont font;
53 font.fromString( fontString );
54 tag->textFont = font;
57 if ( nepomukTag.hasProperty( Vocabulary::MessageTag::priority() ) ) {
58 tag->priority = nepomukTag.property( Vocabulary::MessageTag::priority() ).toInt();
60 else
61 tag->priority = -1;
63 if ( nepomukTag.hasProperty( Vocabulary::MessageTag::shortcut() ) ) {
64 tag->shortcut = KShortcut( nepomukTag.property( Vocabulary::MessageTag::shortcut() ).toString() );
67 if ( nepomukTag.hasProperty( Vocabulary::MessageTag::inToolbar() ) ) {
68 tag->inToolbar = nepomukTag.property( Vocabulary::MessageTag::inToolbar() ).toBool();
70 else
71 tag->inToolbar = false;
73 return tag;
76 void Tag::saveToNepomuk( SaveFlags saveFlags ) const
78 Nepomuk::Tag nepomukTag( nepomukResourceUri );
79 nepomukTag.setLabel( tagName );
80 nepomukTag.setSymbols( QStringList( iconName ) );
81 nepomukTag.setProperty( Vocabulary::MessageTag::priority(), priority );
82 nepomukTag.setProperty( Vocabulary::MessageTag::inToolbar(), inToolbar );
83 nepomukTag.setProperty( Vocabulary::MessageTag::shortcut(), shortcut.toString() );
85 if ( textColor.isValid() && saveFlags & TextColor )
86 nepomukTag.setProperty( Vocabulary::MessageTag::textColor(), textColor.name() );
87 else
88 nepomukTag.removeProperty( Vocabulary::MessageTag::textColor() );
90 if ( backgroundColor.isValid() && saveFlags & BackgroundColor )
91 nepomukTag.setProperty( Vocabulary::MessageTag::backgroundColor(), backgroundColor.name() );
92 else
93 nepomukTag.removeProperty( Vocabulary::MessageTag::backgroundColor() );
95 if ( saveFlags & Font )
96 nepomukTag.setProperty( Vocabulary::MessageTag::font(), textFont.toString() );
97 else
98 nepomukTag.removeProperty( Vocabulary::MessageTag::font() );
101 bool Tag::compare( Tag::Ptr &tag1, Tag::Ptr &tag2 )
103 return tag1->priority < tag2->priority;
106 bool Tag::operator==( const Tag &other ) const
108 return tagName == other.tagName &&
109 textColor == other.textColor &&
110 backgroundColor == other.backgroundColor &&
111 textFont == other.textFont &&
112 iconName == other.iconName &&
113 inToolbar == other.inToolbar &&
114 shortcut.toString() == other.shortcut.toString() &&
115 priority == other.priority &&
116 nepomukResourceUri == other.nepomukResourceUri;
119 bool Tag::operator!=( const Tag &other ) const
121 return !( *this == other );