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

mailcommon

  • sources
  • kde-4.14
  • kdepim
  • mailcommon
  • tag
tag.cpp
Go to the documentation of this file.
1 /* Copyright 2010 Thomas McGuire <mcguire@kde.org>
2  Copyright 2012-2015 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 <Akonadi/Tag>
23 #include <Akonadi/TagAttribute>
24 
25 #include <QDebug>
26 
27 using namespace MailCommon;
28 
29 Tag::Ptr Tag::createDefaultTag(const QString& name)
30 {
31  Tag::Ptr tag( new Tag() );
32  tag->tagName = name;
33  tag->iconName = QLatin1String("mail-tagged");
34 
35  tag->priority = -1;
36  tag->inToolbar = false;
37  tag->isImmutable = false;
38  return tag;
39 }
40 
41 Tag::Ptr Tag::fromAkonadi(const Akonadi::Tag& akonadiTag)
42 {
43  Tag::Ptr tag( new Tag() );
44  tag->tagName = akonadiTag.name();
45  tag->mTag = akonadiTag;
46  tag->priority = -1;
47  tag->iconName = QLatin1String("mail-tagged");
48  tag->inToolbar = false;
49  tag->isImmutable = akonadiTag.isImmutable();
50  Akonadi::TagAttribute *attr = akonadiTag.attribute<Akonadi::TagAttribute>();
51  if (attr) {
52  if (!attr->iconName().isEmpty()) {
53  tag->iconName = attr->iconName();
54  }
55  tag->inToolbar = attr->inToolbar();
56  tag->shortcut = KShortcut(attr->shortcut());
57  tag->textColor = attr->textColor();
58  tag->backgroundColor = attr->backgroundColor();
59  if (!attr->font().isEmpty()) {
60  tag->textFont.fromString( attr->font() );
61  }
62  tag->priority = attr->priority();
63  }
64  return tag;
65 }
66 
67 Akonadi::Tag Tag::saveToAkonadi(Tag::SaveFlags saveFlags) const
68 {
69  Akonadi::Tag tag( tagName );
70  Akonadi::TagAttribute *attr = tag.attribute<Akonadi::TagAttribute>(Akonadi::AttributeEntity::AddIfMissing);
71  attr->setDisplayName( tagName );
72  attr->setIconName( iconName );
73  attr->setInToolbar( inToolbar );
74  attr->setShortcut( shortcut.toString() );
75  attr->setPriority( priority );
76 
77  if ( textColor.isValid() && (saveFlags & TextColor) )
78  attr->setTextColor( textColor );
79  else
80  attr->setTextColor( QColor() );
81 
82  if ( backgroundColor.isValid() && (saveFlags & BackgroundColor) )
83  attr->setBackgroundColor( backgroundColor );
84  else
85  attr->setBackgroundColor( QColor() );
86 
87  if ( (textFont != QFont()) && (saveFlags & Font) )
88  attr->setFont( textFont.toString() );
89  else
90  attr->setFont( QString() );
91 
92  tag.addAttribute(attr);
93  return tag;
94 }
95 
96 bool Tag::compare( Tag::Ptr &tag1, Tag::Ptr &tag2 )
97 {
98  if ( tag1->priority < tag2->priority )
99  return true;
100  else if (tag1->priority == tag2->priority)
101  return ( tag1->tagName < tag2->tagName );
102  else
103  return false;
104 }
105 
106 bool Tag::compareName( Tag::Ptr &tag1, Tag::Ptr &tag2 )
107 {
108  return ( tag1->tagName < tag2->tagName );
109 }
110 
111 bool Tag::operator==( const Tag &other ) const
112 {
113 #if 0
114  if (mTag.isValid()) {
115  return id() == other.id();
116  }
117 #endif
118  return tagName == other.tagName &&
119  textColor == other.textColor &&
120  backgroundColor == other.backgroundColor &&
121  textFont == other.textFont &&
122  iconName == other.iconName &&
123  inToolbar == other.inToolbar &&
124  shortcut.toString() == other.shortcut.toString() &&
125  priority == other.priority;
126 }
127 
128 bool Tag::operator!=( const Tag &other ) const
129 {
130  return !( *this == other );
131 }
132 
133 qint64 Tag::id() const
134 {
135  return mTag.id();
136 }
137 
138 QString Tag::name() const
139 {
140  return mTag.name();
141 }
142 
143 Akonadi::Tag Tag::tag() const
144 {
145  return mTag;
146 }
147 
tag.h
MailCommon::Tag::Font
Definition: tag.h:47
MailCommon::Tag::TextColor
Definition: tag.h:45
MailCommon::Tag::name
QString name() const
Definition: tag.cpp:138
QFont
MailCommon::Tag::fromAkonadi
static Ptr fromAkonadi(const Akonadi::Tag &tag)
Definition: tag.cpp:41
MailCommon::Tag::id
qint64 id() const
Definition: tag.cpp:133
QFlags
MailCommon::Tag::compareName
static bool compareName(Ptr &tag1, Ptr &tag2)
Definition: tag.cpp:106
QSharedPointer
Definition: collectiongeneralpage.h:30
MailCommon::Tag::createDefaultTag
static Ptr createDefaultTag(const QString &name)
Definition: tag.cpp:29
MailCommon::Tag
Definition: tag.h:38
MailCommon::Tag::operator==
bool operator==(const Tag &other) const
Definition: tag.cpp:111
MailCommon::Tag::operator!=
bool operator!=(const Tag &other) const
Definition: tag.cpp:128
MailCommon::Tag::shortcut
KShortcut shortcut
Definition: tag.h:76
QString
QColor
MailCommon::Tag::priority
int priority
Definition: tag.h:81
MailCommon::Tag::BackgroundColor
Definition: tag.h:46
MailCommon::Tag::saveToAkonadi
Akonadi::Tag saveToAkonadi(SaveFlags saveFlags) const
Definition: tag.cpp:67
MailCommon::Tag::iconName
QString iconName
Definition: tag.h:75
MailCommon::Tag::tag
Akonadi::Tag tag() const
Definition: tag.cpp:143
MailCommon::Tag::tagName
QString tagName
Definition: tag.h:71
MailCommon::Tag::backgroundColor
QColor backgroundColor
Definition: tag.h:73
QFont::toString
QString toString() const
QLatin1String
MailCommon::Tag::textColor
QColor textColor
Definition: tag.h:72
MailCommon::Tag::compare
static bool compare(Ptr &tag1, Ptr &tag2)
Definition: tag.cpp:96
MailCommon::Tag::inToolbar
bool inToolbar
Definition: tag.h:77
MailCommon::Tag::textFont
QFont textFont
Definition: tag.h:74
QColor::isValid
bool isValid() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:41 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
  • pimprint

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