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

messagelist

  • sources
  • kde-4.14
  • kdepim
  • messagelist
messagelistutil.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  This file is part of KMail, the KDE mail client.
3  Copyright (c) 2011-2015 Montel Laurent <montel@kde.org>
4 
5  KMail is free software; you can redistribute it and/or modify it
6  under the terms of the GNU General Public License, version 2, as
7  published by the Free Software Foundation.
8 
9  KMail is distributed in the hope that it will be useful, but
10  WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #include "messagelistutil.h"
19 #include "core/settings.h"
20 #include <QTextDocument>
21 
22 #include <KConfigGroup>
23 #include <KMenu>
24 #include <KIcon>
25 #include <KLocalizedString>
26 #include <KMime/Message>
27 #include <Akonadi/Item>
28 
29 using namespace MessageList::Core;
30 
31 QString MessageList::Util::messageSortingConfigName()
32 {
33  return QLatin1String( "MessageSorting" );
34 }
35 
36 QString MessageList::Util::messageSortDirectionConfigName()
37 {
38  return QLatin1String( "MessageSortDirection" );
39 }
40 
41 QString MessageList::Util::groupSortingConfigName()
42 {
43  return QLatin1String( "GroupSorting" );
44 }
45 
46 QString MessageList::Util::groupSortDirectionConfigName()
47 {
48  return QLatin1String( "GroupSortDirection" );
49 }
50 
51 QString MessageList::Util::messageUniqueIdConfigName()
52 {
53  return QString::fromLatin1( "MessageUniqueIdForStorageModel%1" );
54 }
55 
56 QString MessageList::Util::storageModelSortOrderGroup()
57 {
58  return QLatin1String( "MessageListView::StorageModelSortOrder" );
59 }
60 
61 QString MessageList::Util::storageModelThemesGroup()
62 {
63  return QLatin1String( "MessageListView::StorageModelThemes" );
64 }
65 
66 QString MessageList::Util::storageModelAggregationsGroup()
67 {
68  return QLatin1String( "MessageListView::StorageModelAggregations" );
69 }
70 
71 
72 QString MessageList::Util::setForStorageModelConfigName()
73 {
74  return QString::fromLatin1( "SetForStorageModel%1" );
75 }
76 
77 QString MessageList::Util::storageModelSelectedMessageGroup()
78 {
79  return QLatin1String( "MessageListView::StorageModelSelectedMessages" );
80 }
81 
82 
83 void MessageList::Util::deleteConfig( const QString& collectionId )
84 {
85  KConfigGroup confselectedMessage( Settings::self()->config(),
86  MessageList::Util::storageModelSelectedMessageGroup() );
87  confselectedMessage.deleteEntry( MessageList::Util::messageUniqueIdConfigName().arg( collectionId ) );
88 
89  KConfigGroup storageModelOrder( Settings::self()->config(),
90  MessageList::Util::storageModelSortOrderGroup() );
91  storageModelOrder.deleteEntry( collectionId + groupSortDirectionConfigName() );
92  storageModelOrder.deleteEntry( collectionId + groupSortingConfigName() );
93  storageModelOrder.deleteEntry( collectionId + messageSortDirectionConfigName() );
94  storageModelOrder.deleteEntry( collectionId + messageSortingConfigName() );
95 
96  KConfigGroup storageModelTheme( Settings::self()->config(),
97  MessageList::Util::storageModelThemesGroup() );
98  storageModelTheme.deleteEntry( collectionId + setForStorageModelConfigName() );
99 
100 
101  KConfigGroup storageModelAggregation( Settings::self()->config(),
102  MessageList::Util::storageModelAggregationsGroup() );
103  storageModelAggregation.deleteEntry( collectionId + setForStorageModelConfigName() );
104 
105 }
106 
107 QColor MessageList::Util::unreadDefaultMessageColor()
108 {
109  return QColor( "blue" );
110 }
111 
112 QColor MessageList::Util::importantDefaultMessageColor()
113 {
114  return QColor( 0x98, 0x0, 0x0 );
115 }
116 
117 QColor MessageList::Util::todoDefaultMessageColor()
118 {
119  return QColor( 0x0, 0x98, 0x0 );
120 }
121 
122 void MessageList::Util::fillViewMenu( KMenu * menu, QObject *receiver )
123 {
124  KMenu* sortingMenu = new KMenu( i18n( "Sorting" ), menu );
125  sortingMenu->setIcon( KIcon( QLatin1String( "view-sort-ascending" ) ) );
126  menu->addMenu( sortingMenu );
127  QObject::connect( sortingMenu, SIGNAL(aboutToShow()),
128  receiver, SLOT(sortOrderMenuAboutToShow()) );
129 
130  KMenu* aggregationMenu = new KMenu( i18n( "Aggregation" ), menu );
131  aggregationMenu->setIcon( KIcon( QLatin1String( "view-process-tree" ) ) );
132  menu->addMenu( aggregationMenu );
133  QObject::connect( aggregationMenu, SIGNAL(aboutToShow()),
134  receiver, SLOT(aggregationMenuAboutToShow()) );
135 
136  KMenu* themeMenu = new KMenu( i18n( "Theme" ), menu );
137  themeMenu->setIcon( KIcon( QLatin1String( "preferences-desktop-theme" ) ) );
138  menu->addMenu( themeMenu );
139  QObject::connect( themeMenu, SIGNAL(aboutToShow()),
140  receiver, SLOT(themeMenuAboutToShow()) );
141 }
142 
143 QString MessageList::Util::contentSummary( const Akonadi::Item &item )
144 {
145  if ( !item.hasPayload<KMime::Message::Ptr>() ) {
146  return QString();
147  }
148 
149  KMime::Message::Ptr message = item.payload<KMime::Message::Ptr>();
150  KMime::Content *textContent = message->textContent();
151  if ( !textContent ) {
152  return QString();
153  }
154  const QString content = textContent->decodedText( true, true );
155  if ( content.isEmpty() ) {
156  return QString();
157  }
158 
159  // Extract the first 5 non-empty, non-quoted lines from the content and return it
160  int numLines = 0;
161  const int maxLines = 5;
162  const QStringList lines = content.split( QLatin1Char( '\n' ) );
163  QString ret;
164  foreach( const QString &line, lines ) {
165  const QString lineTrimmed = line.trimmed();
166  const bool isQuoted = lineTrimmed.startsWith( QLatin1Char( '>' ) ) || lineTrimmed.startsWith( QLatin1Char( '|' ) );
167  if ( !isQuoted && !lineTrimmed.isEmpty() ) {
168  ret += line + QLatin1Char( '\n' );
169  numLines++;
170  if ( numLines >= maxLines )
171  break;
172  }
173  }
174  return Qt::escape(ret);
175 }
176 
MessageList::Util::messageUniqueIdConfigName
MESSAGELIST_EXPORT QString messageUniqueIdConfigName()
Definition: messagelistutil.cpp:51
MessageList::Util::storageModelSelectedMessageGroup
MESSAGELIST_EXPORT QString storageModelSelectedMessageGroup()
Definition: messagelistutil.cpp:77
MessageList::Util::importantDefaultMessageColor
MESSAGELIST_EXPORT QColor importantDefaultMessageColor()
Definition: messagelistutil.cpp:112
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
MessageList::Util::storageModelSortOrderGroup
MESSAGELIST_EXPORT QString storageModelSortOrderGroup()
Definition: messagelistutil.cpp:56
MessageList::Util::groupSortingConfigName
MESSAGELIST_EXPORT QString groupSortingConfigName()
Definition: messagelistutil.cpp:41
MessageList::Util::messageSortingConfigName
MESSAGELIST_EXPORT QString messageSortingConfigName()
Definition: messagelistutil.cpp:31
MessageList::Util::contentSummary
MESSAGELIST_EXPORT QString contentSummary(const Akonadi::Item &item)
Returns the first few lines of the actual email text if available.
Definition: messagelistutil.cpp:143
QObject
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
MessageList::Util::storageModelThemesGroup
MESSAGELIST_EXPORT QString storageModelThemesGroup()
Definition: messagelistutil.cpp:61
MessageList::Util::storageModelAggregationsGroup
MESSAGELIST_EXPORT QString storageModelAggregationsGroup()
Definition: messagelistutil.cpp:66
MessageList::Util::groupSortDirectionConfigName
MESSAGELIST_EXPORT QString groupSortDirectionConfigName()
Definition: messagelistutil.cpp:46
QString
QColor
MessageList::Util::setForStorageModelConfigName
MESSAGELIST_EXPORT QString setForStorageModelConfigName()
Definition: messagelistutil.cpp:72
QStringList
MessageList::Util::messageSortDirectionConfigName
MESSAGELIST_EXPORT QString messageSortDirectionConfigName()
Definition: messagelistutil.cpp:36
MessageList::Util::todoDefaultMessageColor
MESSAGELIST_EXPORT QColor todoDefaultMessageColor()
Definition: messagelistutil.cpp:117
QLatin1Char
MessageList::Util::unreadDefaultMessageColor
MESSAGELIST_EXPORT QColor unreadDefaultMessageColor()
Definition: messagelistutil.cpp:107
messagelistutil.h
MessageList::Util::fillViewMenu
MESSAGELIST_EXPORT void fillViewMenu(KMenu *menu, QObject *receiver)
Definition: messagelistutil.cpp:122
QLatin1String
Qt::escape
QString escape(const QString &plain)
MessageList::Util::deleteConfig
MESSAGELIST_EXPORT void deleteConfig(const QString &collectionId)
Definition: messagelistutil.cpp:83
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messagelist

Skip menu "messagelist"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

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