• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • tag
tag.cpp
Go to the documentation of this file.
1 /* Copyright 2010 Thomas McGuire <mcguire@kde.org>
2  Copyright 2012 Laurent Montel <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License as
6  published by the Free Software Foundation; either version 2 of
7  the License or (at your option) version 3 or any later version
8  accepted by the membership of KDE e.V. (or its successor approved
9  by the membership of KDE e.V.), which shall act as a proxy
10  defined in Section 14 of version 3 of the license.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #include "tag.h"
21 
22 #include "messagetag.h"
23 
24 #include <soprano/nao.h>
25 #include <Nepomuk2/Tag>
26 #include <Nepomuk2/Variant>
27 #include <QDebug>
28 
29 using namespace MailCommon;
30 
31 Tag::Ptr Tag::fromNepomuk( const Nepomuk2::Tag& nepomukTag )
32 {
33  Tag::Ptr tag( new Tag() );
34  tag->tagName = nepomukTag.label();
35 
36  tag->iconName = nepomukTag.genericIcon();
37  if ( tag->iconName.isEmpty() )
38  tag->iconName = QLatin1String("mail-tagged");
39 
40  tag->nepomukResourceUri = nepomukTag.uri();
41 
42  const QString identifier = nepomukTag.property( Soprano::Vocabulary::NAO::identifier() ).toString();
43  tag->tagStatus = (identifier == QLatin1String("important")) ||
44  (identifier == QLatin1String("todo")) ||
45  (identifier == QLatin1String("watched")) ||
46  (identifier == QLatin1String("deleted")) ||
47  (identifier == QLatin1String("spam")) ||
48  (identifier == QLatin1String("replied")) ||
49  (identifier == QLatin1String("ignored")) ||
50  (identifier == QLatin1String("forwarded")) ||
51  (identifier == QLatin1String("sent")) ||
52  (identifier == QLatin1String("queued")) ||
53  (identifier == QLatin1String("ham"));
54 
55  if ( nepomukTag.hasProperty( Vocabulary::MessageTag::textColor() ) ) {
56  const QString name = nepomukTag.property( Vocabulary::MessageTag::textColor() ).toString();
57  tag->textColor = QColor( name );
58  }
59 
60  if ( nepomukTag.hasProperty( Vocabulary::MessageTag::backgroundColor() ) ) {
61  const QString name = nepomukTag.property( Vocabulary::MessageTag::backgroundColor() ).toString();
62  tag->backgroundColor = QColor( name );
63  }
64 
65  if ( nepomukTag.hasProperty( Vocabulary::MessageTag::font() ) ) {
66  const QString fontString = nepomukTag.property( Vocabulary::MessageTag::font() ).toString();
67  QFont font;
68  font.fromString( fontString );
69  tag->textFont = font;
70  }
71 
72  if ( nepomukTag.hasProperty( Vocabulary::MessageTag::priority() ) ) {
73  tag->priority = nepomukTag.property( Vocabulary::MessageTag::priority() ).toInt();
74  }
75  else
76  tag->priority = -1;
77 
78  if ( nepomukTag.hasProperty( Vocabulary::MessageTag::shortcut() ) ) {
79  tag->shortcut = KShortcut( nepomukTag.property( Vocabulary::MessageTag::shortcut() ).toString() );
80  }
81 
82  if ( nepomukTag.hasProperty( Vocabulary::MessageTag::inToolbar() ) ) {
83  tag->inToolbar = nepomukTag.property( Vocabulary::MessageTag::inToolbar() ).toBool();
84  }
85  else
86  tag->inToolbar = false;
87 
88  return tag;
89 }
90 
91 void Tag::saveToNepomuk( SaveFlags saveFlags ) const
92 {
93  Nepomuk2::Tag nepomukTag( nepomukResourceUri );
94 
95  nepomukTag.setLabel( tagName );
96 
97  Nepomuk2::Resource symbol( QUrl(), Soprano::Vocabulary::NAO::FreeDesktopIcon() );
98  symbol.setProperty( Soprano::Vocabulary::NAO::iconName(), iconName );
99 
100  nepomukTag.setProperty( Soprano::Vocabulary::NAO::hasSymbol(), symbol );
101 
102  nepomukTag.setProperty( Vocabulary::MessageTag::priority(), priority );
103  nepomukTag.setProperty( Vocabulary::MessageTag::inToolbar(), inToolbar );
104  nepomukTag.setProperty( Vocabulary::MessageTag::shortcut(), shortcut.toString() );
105 
106  if ( textColor.isValid() && saveFlags & TextColor )
107  nepomukTag.setProperty( Vocabulary::MessageTag::textColor(), textColor.name() );
108  else
109  nepomukTag.removeProperty( Vocabulary::MessageTag::textColor() );
110 
111  if ( backgroundColor.isValid() && saveFlags & BackgroundColor )
112  nepomukTag.setProperty( Vocabulary::MessageTag::backgroundColor(), backgroundColor.name() );
113  else
114  nepomukTag.removeProperty( Vocabulary::MessageTag::backgroundColor() );
115 
116  if ( saveFlags & Font )
117  nepomukTag.setProperty( Vocabulary::MessageTag::font(), textFont.toString() );
118  else
119  nepomukTag.removeProperty( Vocabulary::MessageTag::font() );
120 }
121 
122 bool Tag::compare( Tag::Ptr &tag1, Tag::Ptr &tag2 )
123 {
124  if ( tag1->priority < tag2->priority )
125  return true;
126  else if (tag1->priority == tag2->priority)
127  return ( tag1->tagName < tag2->tagName );
128  else
129  return false;
130 }
131 
132 bool Tag::compareName( Tag::Ptr &tag1, Tag::Ptr &tag2 )
133 {
134  return ( tag1->tagName < tag2->tagName );
135 }
136 
137 bool Tag::operator==( const Tag &other ) const
138 {
139  return tagName == other.tagName &&
140  textColor == other.textColor &&
141  backgroundColor == other.backgroundColor &&
142  textFont == other.textFont &&
143  iconName == other.iconName &&
144  inToolbar == other.inToolbar &&
145  shortcut.toString() == other.shortcut.toString() &&
146  priority == other.priority &&
147  nepomukResourceUri == other.nepomukResourceUri;
148 }
149 
150 bool Tag::operator!=( const Tag &other ) const
151 {
152  return !( *this == other );
153 }
tag.h
MailCommon::Tag::Font
Definition: tag.h:50
MailCommon::Tag::TextColor
Definition: tag.h:48
QSharedPointer
Definition: collectiongeneralpage.h:30
MailCommon::Tag::fromNepomuk
static Ptr fromNepomuk(const Nepomuk2::Tag &nepomukTag)
Definition: tag.cpp:31
MailCommon::Tag::saveToNepomuk
void saveToNepomuk(SaveFlags saveFlags) const
Definition: tag.cpp:91
MailCommon::Tag::compareName
static bool compareName(Ptr &tag1, Ptr &tag2)
Definition: tag.cpp:132
MailCommon::Tag::SaveFlags
QFlags< SaveFlag > SaveFlags
Definition: tag.h:52
MailCommon::Tag
Definition: tag.h:41
MailCommon::Tag::operator==
bool operator==(const Tag &other) const
Definition: tag.cpp:137
MailCommon::Tag::nepomukResourceUri
QUrl nepomukResourceUri
Definition: tag.h:75
MailCommon::Tag::operator!=
bool operator!=(const Tag &other) const
Definition: tag.cpp:150
MailCommon::Tag::shortcut
KShortcut shortcut
Definition: tag.h:76
MailCommon::Tag::priority
int priority
Definition: tag.h:82
MailCommon::Tag::BackgroundColor
Definition: tag.h:49
MailCommon::Tag::iconName
QString iconName
Definition: tag.h:74
MailCommon::Tag::tagName
QString tagName
Definition: tag.h:70
MailCommon::Tag::backgroundColor
QColor backgroundColor
Definition: tag.h:72
MailCommon::Tag::textColor
QColor textColor
Definition: tag.h:71
MailCommon::Tag::compare
static bool compare(Ptr &tag1, Ptr &tag2)
Definition: tag.cpp:122
MailCommon::Tag::inToolbar
bool inToolbar
Definition: tag.h:77
MailCommon::Tag::textFont
QFont textFont
Definition: tag.h:73
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal