• 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
  • core
theme.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  *******************************************************************************/
20 
21 #include "core/theme.h"
22 
23 #include <QDataStream>
24 
25 #include <KLocalizedString>
26 #include <KDebug>
27 
28 using namespace MessageList::Core;
29 
30 //
31 // Theme versioning
32 //
33 // The themes simply have a DWORD version number attacched.
34 // The earliest version we're able to load is 0x1013.
35 //
36 // Theme revision history:
37 //
38 // Version Date introduced Description
39 // --------------------------------------------------------------------------------------------------------------
40 // 0x1013 08.11.2008 Initial theme version, introduced when this piece of code has been moved into trunk.
41 // 0x1014 12.11.2008 Added runtime column data: width and column visibility
42 // 0x1015 03.03.2009 Added icon size
43 // 0x1016 08.03.2009 Added support for sorting by New/Unread status
44 // 0x1017 16.08.2009 Added support for column icon
45 // 0x1018 17.01.2010 Added support for annotation icon
46 // 0x1019 13.07.2010 Added support for invitation icon
47 //
48 static const int gThemeCurrentVersion = 0x1019; // increase if you add new fields or change the meaning of some
49 // you don't need to change the values below, but you might want to add new ones
50 static const int gThemeMinimumSupportedVersion = 0x1013;
51 static const int gThemeMinimumVersionWithColumnRuntimeData = 0x1014;
52 static const int gThemeMinimumVersionWithIconSizeField = 0x1015;
53 static const int gThemeMinimumVersionWithSortingByUnreadStatusAllowed = 0x1016;
54 static const int gThemeMinimumVersionWithColumnIcon = 0x1017;
55 static const int gThemeMinimumVersionWithAnnotationIcon = 0x1018;
56 static const int gThemeMinimumVersionWithInvitationIcon = 0x1019;
57 
58 // the default icon size
59 static const int gThemeDefaultIconSize = 16;
60 
61 
62 Theme::ContentItem::ContentItem( Type type )
63  : mType( type ), mFlags( 0 )
64 {
65 }
66 
67 Theme::ContentItem::ContentItem( const ContentItem &src )
68  : mType( src.mType ),
69  mFlags( src.mFlags ),
70  mFont( src.mFont ),
71  mCustomColor( src.mCustomColor )
72 {
73 }
74 
75 QString Theme::ContentItem::description( Type type )
76 {
77  switch ( type )
78  {
79  case Subject:
80  return i18nc( "Description of Type Subject", "Subject" );
81  break;
82  case Date:
83  return i18nc( "Description of Type Date", "Date" );
84  break;
85  case SenderOrReceiver:
86  return i18n( "Sender/Receiver" );
87  break;
88  case Sender:
89  return i18nc( "Description of Type Sender", "Sender" );
90  break;
91  case Receiver:
92  return i18nc( "Description of Type Receiver", "Receiver" );
93  break;
94  case Size:
95  return i18nc( "Description of Type Size", "Size" );
96  break;
97  case ReadStateIcon:
98  return i18n( "Unread/Read Icon" );
99  break;
100  case AttachmentStateIcon:
101  return i18n( "Attachment Icon" );
102  break;
103  case RepliedStateIcon:
104  return i18n( "Replied/Forwarded Icon" );
105  break;
106  case CombinedReadRepliedStateIcon:
107  return i18n( "Combined New/Unread/Read/Replied/Forwarded Icon" );
108  break;
109  case ActionItemStateIcon:
110  return i18n( "Action Item Icon" );
111  break;
112  case ImportantStateIcon:
113  return i18n( "Important Icon" );
114  break;
115  case GroupHeaderLabel:
116  return i18n( "Group Header Label" );
117  break;
118  case SpamHamStateIcon:
119  return i18n( "Spam/Ham Icon" );
120  break;
121  case WatchedIgnoredStateIcon:
122  return i18n( "Watched/Ignored Icon" );
123  break;
124  case ExpandedStateIcon:
125  return i18n( "Group Header Expand/Collapse Icon" );
126  break;
127  case EncryptionStateIcon:
128  return i18n( "Encryption State Icon" );
129  break;
130  case SignatureStateIcon:
131  return i18n( "Signature State Icon" );
132  break;
133  case VerticalLine:
134  return i18n( "Vertical Separation Line" );
135  break;
136  case HorizontalSpacer:
137  return i18n( "Horizontal Spacer" );
138  break;
139  case MostRecentDate:
140  return i18n( "Max Date" );
141  break;
142  case TagList:
143  return i18n( "Message Tags" );
144  break;
145  case AnnotationIcon:
146  return i18n( "Note Icon" );
147  case InvitationIcon:
148  return i18n( "Invitation Icon" );
149  default:
150  return i18nc( "Description for an Unknown Type", "Unknown" );
151  break;
152  }
153 }
154 
155 
156 bool Theme::ContentItem::applicableToMessageItems( Type type )
157 {
158  return ( static_cast< int >( type ) & ApplicableToMessageItems );
159 }
160 
161 bool Theme::ContentItem::applicableToGroupHeaderItems( Type type )
162 {
163  return ( static_cast< int >( type ) & ApplicableToGroupHeaderItems );
164 }
165 
166 void Theme::ContentItem::setFont( const QFont &font )
167 {
168  mFont = font;
169  mFontKey = font.key();
170 }
171 
172 void Theme::ContentItem::save( QDataStream &stream ) const
173 {
174  stream << (int)mType;
175  stream << mFlags;
176  stream << mFont;
177  stream << mCustomColor;
178 }
179 
180 bool Theme::ContentItem::load( QDataStream &stream, int /*themeVersion*/ )
181 {
182  int val;
183 
184  stream >> val;
185  mType = static_cast< Type >( val );
186  switch( mType )
187  {
188  case Subject:
189  case Date:
190  case SenderOrReceiver:
191  case Sender:
192  case Receiver:
193  case Size:
194  case ReadStateIcon:
195  case AttachmentStateIcon:
196  case RepliedStateIcon:
197  case GroupHeaderLabel:
198  case ActionItemStateIcon:
199  case ImportantStateIcon:
200  case SpamHamStateIcon:
201  case WatchedIgnoredStateIcon:
202  case ExpandedStateIcon:
203  case EncryptionStateIcon:
204  case SignatureStateIcon:
205  case VerticalLine:
206  case HorizontalSpacer:
207  case MostRecentDate:
208  case CombinedReadRepliedStateIcon:
209  case TagList:
210  case AnnotationIcon:
211  case InvitationIcon:
212  // ok
213  break;
214  default:
215  kDebug() << "Invalid content item type";
216  return false; // b0rken
217  break;
218  }
219 
220  stream >> mFlags;
221  stream >> mFont;
222  stream >> mCustomColor;
223  if ( mFlags & UseCustomColor )
224  {
225  if ( !mCustomColor.isValid() )
226  mFlags &= ~UseCustomColor;
227  }
228  return true;
229 }
230 
231 
232 
233 
234 Theme::Row::Row()
235 {
236 }
237 
238 Theme::Row::Row( const Row &src )
239 {
240  QList< ContentItem * >::ConstIterator end( src.mLeftItems.constEnd() );
241  for ( QList< ContentItem * >::ConstIterator it = src.mLeftItems.constBegin(); it != end ; ++it )
242  addLeftItem( new ContentItem( *( *it ) ) );
243 
244  end= src.mRightItems.constEnd();
245  for ( QList< ContentItem * >::ConstIterator it = src.mRightItems.constBegin(); it != end ; ++it )
246  addRightItem( new ContentItem( *( *it ) ) );
247 }
248 
249 
250 Theme::Row::~Row()
251 {
252  removeAllLeftItems();
253  removeAllRightItems();
254 }
255 
256 void Theme::Row::removeAllLeftItems()
257 {
258  while( !mLeftItems.isEmpty() )
259  delete mLeftItems.takeFirst();
260 }
261 
262 void Theme::Row::removeAllRightItems()
263 {
264  while( !mRightItems.isEmpty() )
265  delete mRightItems.takeFirst();
266 }
267 
268 void Theme::Row::insertLeftItem( int idx, ContentItem * item )
269 {
270  if ( idx >= mLeftItems.count() )
271  {
272  mLeftItems.append( item );
273  return;
274  }
275  mLeftItems.insert( idx, item );
276 }
277 
278 void Theme::Row::insertRightItem( int idx, ContentItem * item )
279 {
280  if ( idx >= mRightItems.count() )
281  {
282  mRightItems.append( item );
283  return;
284  }
285  mRightItems.insert( idx, item );
286 }
287 
288 bool Theme::Row::containsTextItems() const
289 {
290  QList< ContentItem * >::ConstIterator end( mLeftItems.constEnd() );
291  for ( QList< ContentItem * >::ConstIterator it = mLeftItems.constBegin(); it != end ; ++it )
292  {
293  if ( ( *it )->displaysText() )
294  return true;
295  }
296  end = mRightItems.constEnd();
297  for ( QList< ContentItem * >::ConstIterator it = mRightItems.constBegin(); it != end ; ++it )
298  {
299  if ( ( *it )->displaysText() )
300  return true;
301  }
302  return false;
303 }
304 
305 void Theme::Row::save( QDataStream &stream ) const
306 {
307  stream << (int)mLeftItems.count();
308 
309  int cnt = mLeftItems.count();
310 
311  for ( int i = 0; i < cnt ; ++i )
312  {
313  ContentItem * ci = mLeftItems.at( i );
314  ci->save( stream );
315  }
316 
317  stream << (int)mRightItems.count();
318 
319  cnt = mRightItems.count();
320 
321  for ( int i = 0; i < cnt ; ++i )
322  {
323  ContentItem * ci = mRightItems.at( i );
324  ci->save( stream );
325  }
326 }
327 
328 bool Theme::Row::LoadContentItem(int val, QDataStream &stream, int themeVersion, bool leftItem)
329 {
330  if ( ( val < 0 ) || ( val > 50 ) )
331  return false; // senseless
332 
333  // FIXME: Remove code duplication here
334 
335  for ( int i = 0; i < val ; ++i )
336  {
337  ContentItem * ci = new ContentItem( ContentItem::Subject ); // dummy type
338  if ( !ci->load( stream, themeVersion ) )
339  {
340  kDebug() << "Left content item loading failed";
341  delete ci;
342  return false;
343  }
344  if (leftItem)
345  addLeftItem( ci );
346  else
347  addRightItem( ci );
348 
349  // Add the annotation item next to the attachment icon, so that users upgrading from old
350  // versions don't manually need to set this.
351  // Don't do this for the stand-alone attchment column.
352  if ( ci->type() == ContentItem::AttachmentStateIcon &&
353  themeVersion < gThemeMinimumVersionWithAnnotationIcon &&
354  val > 1 ) {
355  kDebug() << "Old theme version detected, adding annotation item next to attachment icon.";
356  ContentItem *annotationItem = new ContentItem( ContentItem::AnnotationIcon ) ;
357  annotationItem->setHideWhenDisabled( true );
358  if (leftItem)
359  addLeftItem( annotationItem );
360  else
361  addRightItem( annotationItem );
362  }
363 
364  // Same as above, for the invitation icon
365  if ( ci->type() == ContentItem::AttachmentStateIcon &&
366  themeVersion < gThemeMinimumVersionWithInvitationIcon &&
367  val > 1 ) {
368  kDebug() << "Old theme version detected, adding invitation item next to attachment icon.";
369  ContentItem *invitationItem = new ContentItem( ContentItem::InvitationIcon ) ;
370  invitationItem->setHideWhenDisabled( true );
371  if (leftItem)
372  addLeftItem( invitationItem );
373  else
374  addRightItem( invitationItem );
375  }
376  }
377  return true;
378 }
379 
380 bool Theme::Row::load( QDataStream &stream, int themeVersion )
381 {
382  removeAllLeftItems();
383  removeAllRightItems();
384 
385  int val;
386 
387  // left item count
388 
389  stream >> val;
390  if (!LoadContentItem(val, stream, themeVersion, true))
391  return false;
392 
393  // right item count
394 
395  stream >> val;
396 
397  if (!LoadContentItem(val, stream, themeVersion, false))
398  return false;
399 
400  return true;
401 }
402 
403 
404 Theme::Column::SharedRuntimeData::SharedRuntimeData( bool currentlyVisible, int currentWidth )
405  : mReferences( 0 ), mCurrentlyVisible( currentlyVisible ), mCurrentWidth( currentWidth )
406 {
407 }
408 
409 Theme::Column::SharedRuntimeData::~SharedRuntimeData()
410 {
411 }
412 
413 void Theme::Column::SharedRuntimeData::addReference()
414 {
415  mReferences++;
416 }
417 
418 bool Theme::Column::SharedRuntimeData::deleteReference()
419 {
420  mReferences--;
421  Q_ASSERT( mReferences >= 0 );
422  return mReferences > 0;
423 }
424 
425 void Theme::Column::SharedRuntimeData::save( QDataStream &stream ) const
426 {
427  stream << mCurrentlyVisible;
428  stream << mCurrentWidth;
429 }
430 
431 bool Theme::Column::SharedRuntimeData::load( QDataStream &stream, int /* themeVersion */ )
432 {
433  stream >> mCurrentlyVisible;
434  stream >> mCurrentWidth;
435  if ( mCurrentWidth > 10000 )
436  {
437  kDebug() << "Theme has insane column width " << mCurrentWidth << " chopping to 100";
438  mCurrentWidth = 100; // avoid really insane values
439  }
440  return (mCurrentWidth >= -1);
441 }
442 
443 
444 Theme::Column::Column()
445  : mVisibleByDefault( true ),
446  mIsSenderOrReceiver( false ),
447  mMessageSorting( SortOrder::NoMessageSorting )
448 {
449  mSharedRuntimeData = new SharedRuntimeData( true, -1 );
450  mSharedRuntimeData->addReference();
451 }
452 
453 Theme::Column::Column( const Column &src )
454 {
455  mLabel = src.mLabel;
456  mPixmapName = src.mPixmapName;
457  mVisibleByDefault = src.mVisibleByDefault;
458  mIsSenderOrReceiver = src.mIsSenderOrReceiver;
459  mMessageSorting = src.mMessageSorting;
460 
461  mSharedRuntimeData = src.mSharedRuntimeData;
462  mSharedRuntimeData->addReference();
463  QList< Row * >::ConstIterator end( src.mMessageRows.constEnd() );
464  for ( QList< Row * >::ConstIterator it = src.mMessageRows.constBegin(); it != end ; ++it )
465  addMessageRow( new Row( *( *it ) ) );
466 
467  end = src.mGroupHeaderRows.constEnd();
468  for ( QList< Row * >::ConstIterator it = src.mGroupHeaderRows.constBegin(); it != end ; ++it )
469  addGroupHeaderRow( new Row( *( *it ) ) );
470 }
471 
472 Theme::Column::~Column()
473 {
474  removeAllMessageRows();
475  removeAllGroupHeaderRows();
476  if( !( mSharedRuntimeData->deleteReference() ) )
477  delete mSharedRuntimeData;
478 }
479 
480 void Theme::Column::detach()
481 {
482  if( mSharedRuntimeData->referenceCount() < 2 )
483  return; // nothing to detach
484  mSharedRuntimeData->deleteReference();
485 
486  mSharedRuntimeData = new SharedRuntimeData( mVisibleByDefault, -1 );
487  mSharedRuntimeData->addReference();
488 
489 }
490 
491 void Theme::Column::removeAllMessageRows()
492 {
493  while ( !mMessageRows.isEmpty() )
494  delete mMessageRows.takeFirst();
495 }
496 
497 void Theme::Column::removeAllGroupHeaderRows()
498 {
499  while ( !mGroupHeaderRows.isEmpty() )
500  delete mGroupHeaderRows.takeFirst();
501 }
502 
503 void Theme::Column::insertMessageRow( int idx, Row * row )
504 {
505  if ( idx >= mMessageRows.count() )
506  {
507  mMessageRows.append( row );
508  return;
509  }
510  mMessageRows.insert( idx, row );
511 }
512 
513 void Theme::Column::insertGroupHeaderRow( int idx, Row * row )
514 {
515  if ( idx >= mGroupHeaderRows.count() )
516  {
517  mGroupHeaderRows.append( row );
518  return;
519  }
520  mGroupHeaderRows.insert( idx, row );
521 }
522 
523 bool Theme::Column::containsTextItems() const
524 {
525  QList< Row * >::ConstIterator end( mMessageRows.constEnd() );
526  for ( QList< Row * >::ConstIterator it = mMessageRows.constBegin(); it != end ; ++it )
527  {
528  if ( ( *it )->containsTextItems() )
529  return true;
530  }
531  end = mGroupHeaderRows.constEnd();
532  for ( QList< Row * >::ConstIterator it = mGroupHeaderRows.constBegin(); it != end ; ++it )
533  {
534  if ( ( *it )->containsTextItems() )
535  return true;
536  }
537  return false;
538 }
539 
540 void Theme::Column::save( QDataStream &stream ) const
541 {
542  stream << mLabel;
543  stream << mPixmapName;
544  stream << mVisibleByDefault;
545  stream << mIsSenderOrReceiver;
546  stream << (int)mMessageSorting;
547 
548  stream << (int)mGroupHeaderRows.count();
549 
550  int cnt = mGroupHeaderRows.count();
551 
552  for ( int i = 0; i < cnt ; ++i )
553  {
554  Row * row = mGroupHeaderRows.at( i );
555  row->save( stream );
556  }
557 
558  cnt = mMessageRows.count();
559  stream << (int)cnt;
560 
561  for ( int i = 0; i < cnt ; ++i )
562  {
563  Row * row = mMessageRows.at( i );
564  row->save( stream );
565  }
566 
567  // added in version 0x1014
568  mSharedRuntimeData->save( stream );
569 
570 }
571 
572 bool Theme::Column::load( QDataStream &stream, int themeVersion )
573 {
574  removeAllGroupHeaderRows();
575  removeAllMessageRows();
576 
577  stream >> mLabel;
578 
579  if ( themeVersion >= gThemeMinimumVersionWithColumnIcon )
580  stream >> mPixmapName;
581 
582  stream >> mVisibleByDefault;
583  stream >> mIsSenderOrReceiver;
584 
585  int val;
586 
587  stream >> val;
588  mMessageSorting = static_cast< SortOrder::MessageSorting >( val );
589  if ( !SortOrder::isValidMessageSorting( mMessageSorting ) )
590  {
591  kDebug() << "Invalid message sorting";
592  return false;
593  }
594 
595  if ( themeVersion < gThemeMinimumVersionWithSortingByUnreadStatusAllowed )
596  {
597  // The default "Classic" theme "Unread" column had sorting disabled here.
598  // We want to be nice to the existing users and automatically set
599  // the new sorting method for this column (so they don't have to make the
600  // complex steps to set it by themselves).
601  // This piece of code isn't strictly required: it's just a niceness :)
602  if ( ( mMessageSorting == SortOrder::NoMessageSorting ) && ( mLabel == i18n( "Unread" ) ) )
603  mMessageSorting = SortOrder::SortMessagesByUnreadStatus;
604  }
605 
606  // group header row count
607  stream >> val;
608 
609  if ( ( val < 0 ) || ( val > 50 ) )
610  {
611  kDebug() << "Invalid group header row count";
612  return false; // senseless
613  }
614 
615  for ( int i = 0; i < val ; ++i )
616  {
617  Row * row = new Row();
618  if ( !row->load( stream, themeVersion ) )
619  {
620  kDebug() << "Group header row loading failed";
621  delete row;
622  return false;
623  }
624  addGroupHeaderRow( row );
625  }
626 
627  // message row count
628  stream >> val;
629 
630  if ( ( val < 0 ) || ( val > 50 ) )
631  {
632  kDebug() << "Invalid message row count";
633  return false; // senseless
634  }
635 
636  for ( int i = 0; i < val ; ++i )
637  {
638  Row * row = new Row();
639  if ( !row->load( stream, themeVersion ) )
640  {
641  kDebug() << "Message row loading failed";
642  delete row;
643  return false;
644  }
645  addMessageRow( row );
646  }
647 
648  if ( themeVersion >= gThemeMinimumVersionWithColumnRuntimeData )
649  {
650  // starting with version 0x1014 we have runtime data too
651  if( !mSharedRuntimeData->load( stream, themeVersion ) )
652  {
653  kDebug() << "Shared runtime data loading failed";
654  return false;
655  }
656  } else {
657  // assume default shared data
658  mSharedRuntimeData->setCurrentlyVisible( mVisibleByDefault );
659  mSharedRuntimeData->setCurrentWidth( -1 );
660  }
661 
662  return true;
663 }
664 
665 
666 
667 
668 Theme::Theme()
669  : OptionSet()
670 {
671  mGroupHeaderBackgroundMode = AutoColor;
672  mViewHeaderPolicy = ShowHeaderAlways;
673  mIconSize = gThemeDefaultIconSize;
674  mGroupHeaderBackgroundStyle = StyledJoinedRect;
675 }
676 
677 Theme::Theme( const QString &name, const QString &description, bool readOnly )
678  : OptionSet( name, description, readOnly )
679 {
680  mGroupHeaderBackgroundMode = AutoColor;
681  mGroupHeaderBackgroundStyle = StyledJoinedRect;
682  mViewHeaderPolicy = ShowHeaderAlways;
683  mIconSize = gThemeDefaultIconSize;
684 }
685 
686 
687 Theme::Theme( const Theme &src )
688  : OptionSet( src )
689 {
690  mGroupHeaderBackgroundMode = src.mGroupHeaderBackgroundMode;
691  mGroupHeaderBackgroundColor = src.mGroupHeaderBackgroundColor;
692  mGroupHeaderBackgroundStyle = src.mGroupHeaderBackgroundStyle;
693  mViewHeaderPolicy = src.mViewHeaderPolicy;
694  mIconSize = src.mIconSize;
695  QList< Column * >::ConstIterator end( src.mColumns.constEnd() );
696  for ( QList< Column * >::ConstIterator it = src.mColumns.constBegin(); it != end ; ++it )
697  addColumn( new Column( *( *it ) ) );
698 }
699 
700 Theme::~Theme()
701 {
702  removeAllColumns();
703 }
704 
705 void Theme::detach()
706 {
707  QList< Column * >::ConstIterator end( mColumns.constEnd() );
708  for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end ; ++it )
709  ( *it )->detach();
710 }
711 
712 void Theme::resetColumnState()
713 {
714  QList< Column * >::ConstIterator end( mColumns.constEnd() );
715  for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end ; ++it )
716  {
717  ( *it )->setCurrentlyVisible( ( *it )->visibleByDefault() );
718  ( *it )->setCurrentWidth( -1 );
719  }
720 }
721 
722 void Theme::resetColumnSizes()
723 {
724  QList< Column * >::ConstIterator end( mColumns.constEnd() );
725  for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end; ++it )
726  ( *it )->setCurrentWidth( -1 );
727 }
728 
729 
730 void Theme::removeAllColumns()
731 {
732  while ( !mColumns.isEmpty() )
733  delete mColumns.takeFirst();
734 }
735 
736 void Theme::insertColumn( int idx, Column * column )
737 {
738  if ( idx >= mColumns.count() )
739  {
740  mColumns.append( column );
741  return;
742  }
743  mColumns.insert( idx, column );
744 }
745 
746 void Theme::moveColumn(int idx, int newPosition)
747 {
748  if ( (newPosition >= mColumns.count()) || newPosition < 0 )
749  return;
750  mColumns.move( idx, newPosition );
751 }
752 
753 void Theme::setGroupHeaderBackgroundMode( GroupHeaderBackgroundMode bm )
754 {
755  mGroupHeaderBackgroundMode = bm;
756  if ( ( bm == CustomColor ) && !mGroupHeaderBackgroundColor.isValid() )
757  mGroupHeaderBackgroundColor = QColor( 127, 127, 127 ); // something neutral
758 }
759 
760 QList< QPair< QString, int > > Theme::enumerateViewHeaderPolicyOptions()
761 {
762  QList< QPair< QString, int > > ret;
763  ret.append( QPair< QString, int >( i18n( "Never Show" ), NeverShowHeader ) );
764  ret.append( QPair< QString, int >( i18n( "Always Show" ), ShowHeaderAlways ) );
765  return ret;
766 }
767 
768 QList< QPair< QString, int > > Theme::enumerateGroupHeaderBackgroundStyles()
769 {
770  QList< QPair< QString, int > > ret;
771  ret.append( QPair< QString, int >( i18n( "Plain Rectangles" ), PlainRect ) );
772  ret.append( QPair< QString, int >( i18n( "Plain Joined Rectangle" ), PlainJoinedRect ) );
773  ret.append( QPair< QString, int >( i18n( "Rounded Rectangles" ), RoundedRect ) );
774  ret.append( QPair< QString, int >( i18n( "Rounded Joined Rectangle" ), RoundedJoinedRect ) );
775  ret.append( QPair< QString, int >( i18n( "Gradient Rectangles" ), GradientRect ) );
776  ret.append( QPair< QString, int >( i18n( "Gradient Joined Rectangle" ), GradientJoinedRect ) );
777  ret.append( QPair< QString, int >( i18n( "Styled Rectangles" ), StyledRect ) );
778  ret.append( QPair< QString, int >( i18n( "Styled Joined Rectangles" ), StyledJoinedRect ) );
779 
780  return ret;
781 }
782 
783 void Theme::setIconSize( int iconSize )
784 {
785  mIconSize = iconSize;
786  if ( ( mIconSize < 8 ) || ( mIconSize > 64 ) )
787  mIconSize = gThemeDefaultIconSize;
788 }
789 
790 bool Theme::load( QDataStream &stream )
791 {
792  removeAllColumns();
793 
794  int themeVersion;
795 
796  stream >> themeVersion;
797 
798  // We support themes starting at version gThemeMinimumSupportedVersion (0x1013 actually)
799 
800  if (
801  ( themeVersion > gThemeCurrentVersion ) ||
802  ( themeVersion < gThemeMinimumSupportedVersion )
803  )
804  {
805  kDebug() << "Invalid theme version";
806  return false; // b0rken (invalid version)
807  }
808 
809  int val;
810 
811  stream >> val;
812  mGroupHeaderBackgroundMode = (GroupHeaderBackgroundMode)val;
813  switch(mGroupHeaderBackgroundMode)
814  {
815  case Transparent:
816  case AutoColor:
817  case CustomColor:
818  // ok
819  break;
820  default:
821  kDebug() << "Invalid theme group header background mode";
822  return false; // b0rken
823  break;
824  }
825 
826  stream >> mGroupHeaderBackgroundColor;
827 
828  stream >> val;
829  mGroupHeaderBackgroundStyle = (GroupHeaderBackgroundStyle)val;
830  switch(mGroupHeaderBackgroundStyle)
831  {
832  case PlainRect:
833  case PlainJoinedRect:
834  case RoundedRect:
835  case RoundedJoinedRect:
836  case GradientRect:
837  case GradientJoinedRect:
838  case StyledRect:
839  case StyledJoinedRect:
840  // ok
841  break;
842  default:
843  kDebug() << "Invalid theme group header background style";
844  return false; // b0rken
845  break;
846  }
847 
848  stream >> val;
849  mViewHeaderPolicy = (ViewHeaderPolicy)val;
850  switch(mViewHeaderPolicy)
851  {
852  case ShowHeaderAlways:
853  case NeverShowHeader:
854  // ok
855  break;
856  default:
857  kDebug() << "Invalid theme view header policy";
858  return false; // b0rken
859  break;
860  }
861 
862  if ( themeVersion >= gThemeMinimumVersionWithIconSizeField )
863  {
864  // icon size parameter
865  stream >> mIconSize;
866  if ( ( mIconSize < 8 ) || ( mIconSize > 64 ) )
867  mIconSize = gThemeDefaultIconSize; // limit insane values
868  } else {
869  mIconSize = gThemeDefaultIconSize;
870  }
871 
872  // column count
873  stream >> val;
874  if ( val < 1 || val > 50 )
875  return false; // plain b0rken ( negative, zero or more than 50 columns )
876 
877  for ( int i = 0; i < val ; ++i )
878  {
879  Column * col = new Column();
880  if ( !col->load( stream, themeVersion ) )
881  {
882  kDebug() << "Column loading failed";
883  delete col;
884  return false;
885  }
886  addColumn( col );
887  }
888 
889  return true;
890 }
891 
892 void Theme::save( QDataStream &stream ) const
893 {
894  stream << (int)gThemeCurrentVersion;
895 
896  stream << (int)mGroupHeaderBackgroundMode;
897  stream << mGroupHeaderBackgroundColor;
898  stream << (int)mGroupHeaderBackgroundStyle;
899  stream << (int)mViewHeaderPolicy;
900  stream << mIconSize;
901 
902  const int cnt = mColumns.count();
903  stream << (int)cnt;
904 
905 
906  for ( int i = 0; i < cnt ; ++i )
907  {
908  Column * col = mColumns.at( i );
909  col->save( stream );
910  }
911 }
912 
MessageList::Core::Theme::ContentItem
The ContentItem class defines a content item inside a Row.
Definition: theme.h:73
MessageList::Core::Theme::Row::load
bool load(QDataStream &stream, int themeVersion)
Handles row loading (used by Theme::Column::load())
Definition: theme.cpp:380
MessageList::Core::Theme::ContentItem::InvitationIcon
Whether the message is an invitation.
Definition: theme.h:223
MessageList::Core::Theme::ContentItem::applicableToMessageItems
static bool applicableToMessageItems(Type type)
Static test that returns true if an instance of ContentItem with the specified type makes sense in a ...
Definition: theme.cpp:156
MessageList::Core::Theme::removeAllColumns
void removeAllColumns()
Removes all columns from this theme.
Definition: theme.cpp:730
MessageList::Core::SortOrder
A class which holds information about sorting, e.g.
Definition: sortorder.h:37
MessageList::Core::Theme::Column::containsTextItems
bool containsTextItems() const
Returns true if this column contains text items.
Definition: theme.cpp:523
MessageList::Core::Theme::Row::removeAllLeftItems
void removeAllLeftItems()
Removes all the left items from this row: the items are deleted.
Definition: theme.cpp:256
MessageList::Core::OptionSet
A set of options that can be applied to the MessageList in one shot.
Definition: optionset.h:47
MessageList::Core::SortOrder::isValidMessageSorting
static bool isValidMessageSorting(SortOrder::MessageSorting ms)
Returns true if the ms parameter specifies a valid MessageSorting option.
Definition: sortorder.cpp:267
gThemeMinimumVersionWithColumnRuntimeData
static const int gThemeMinimumVersionWithColumnRuntimeData
Definition: theme.cpp:51
QDataStream
MessageList::Core::Theme::Column::SharedRuntimeData::addReference
void addReference()
Increments the reference count for this shared runtime data object.
Definition: theme.cpp:413
MessageList::Core::Theme::ContentItem::description
static QString description(Type type)
Returns a descriptive name for the specified content item type.
Definition: theme.cpp:75
MessageList::Core::Theme::Column::insertMessageRow
void insertMessageRow(int idx, Row *row)
Inserts a message row to this theme column in the specified position.
Definition: theme.cpp:503
QFont
MessageList::Core::Theme::insertColumn
void insertColumn(int idx, Column *column)
Inserts a column to this theme at the specified position.
Definition: theme.cpp:736
MessageList::Core::Theme::Row
The Row class defines a row of items inside a Column.
Definition: theme.h:466
MessageList::Core::Theme::moveColumn
void moveColumn(int idx, int newPosition)
Definition: theme.cpp:746
MessageList::Core::Theme::ContentItem::AttachmentStateIcon
The icon that displays the atachment state (may be disabled)
Definition: theme.h:158
MessageList::Core::Theme::ShowHeaderAlways
Definition: theme.h:909
theme.h
MessageList::Core::Theme::Column::load
bool load(QDataStream &stream, int themeVersion)
Handles column loading (used by Theme::load())
Definition: theme.cpp:572
MessageList::Core::Theme::Column::removeAllMessageRows
void removeAllMessageRows()
Removes all the message rows from this column.
Definition: theme.cpp:491
gThemeDefaultIconSize
static const int gThemeDefaultIconSize
Definition: theme.cpp:59
MessageList::Core::Theme::setGroupHeaderBackgroundMode
void setGroupHeaderBackgroundMode(GroupHeaderBackgroundMode bm)
Sets the group header background mode for this theme.
Definition: theme.cpp:753
MessageList::Core::Theme::ContentItem::applicableToGroupHeaderItems
static bool applicableToGroupHeaderItems(Type type)
Static test that returns true if an instance of ContentItem with the specified type makes sense in a ...
Definition: theme.cpp:161
MessageList::Core::Theme::ContentItem::load
bool load(QDataStream &stream, int themeVersion)
Handles content item loading (used by Theme::Row::load())
Definition: theme.cpp:180
MessageList::Core::Theme::ContentItem::AnnotationIcon
Whether the message has a annotation/note.
Definition: theme.h:218
MessageList::Core::Theme::Row::save
void save(QDataStream &stream) const
Handles row saving (used by Theme::Column::save())
Definition: theme.cpp:305
MessageList::Core::Theme::Column
The Column class defines a view column available inside this theme.
Definition: theme.h:565
MessageList::Core::Theme::StyledJoinedRect
One big styled rect per column.
Definition: theme.h:901
MessageList::Core::Theme::iconSize
int iconSize() const
Returns the currently set icon size.
Definition: theme.h:1038
MessageList::Core::Theme::ContentItem::setFont
void setFont(const QFont &font)
Sets the custom font to be used with this item.
Definition: theme.cpp:166
MessageList::Core::Theme::enumerateGroupHeaderBackgroundStyles
static QList< QPair< QString, int > > enumerateGroupHeaderBackgroundStyles()
Enumerates the available group header background styles.
Definition: theme.cpp:768
MessageList::Core::Theme::Transparent
No background at all: use style default.
Definition: theme.h:884
QList::append
void append(const T &value)
MessageList::Core::Theme::PlainRect
One plain rect per column.
Definition: theme.h:894
MessageList::Core::Theme::GradientJoinedRect
One big rounded gradient rect for all the columns.
Definition: theme.h:899
MessageList::Core::Theme::Row::removeAllRightItems
void removeAllRightItems()
Removes all the right items from this row.
Definition: theme.cpp:262
MessageList::Core::Theme::ContentItem::type
Type type() const
Returns the type of this content item.
Definition: theme.h:264
MessageList::Core::Theme::ContentItem::save
void save(QDataStream &stream) const
Handles content item saving (used by Theme::Row::save())
Definition: theme.cpp:172
MessageList::Core::Theme::ContentItem::Subject
Display the subject of the message item.
Definition: theme.h:130
MessageList::Core::Theme::Column::save
void save(QDataStream &stream) const
Handles column saving (used by Theme::save())
Definition: theme.cpp:540
MessageList::Core::Theme::Column::SharedRuntimeData::deleteReference
bool deleteReference()
Decrements the reference count for this shared runtime data object.
Definition: theme.cpp:418
QFont::key
QString key() const
MessageList::Core::SortOrder::MessageSorting
MessageSorting
The available message sorting options.
Definition: sortorder.h:78
gThemeMinimumVersionWithColumnIcon
static const int gThemeMinimumVersionWithColumnIcon
Definition: theme.cpp:54
MessageList::Core::Theme::GroupHeaderBackgroundMode
GroupHeaderBackgroundMode
Which color do we use to paint group header background ?
Definition: theme.h:882
gThemeMinimumVersionWithInvitationIcon
static const int gThemeMinimumVersionWithInvitationIcon
Definition: theme.cpp:56
MessageList::Core::Theme::resetColumnState
void resetColumnState()
Resets the column state (visibility and width) to their default values (the "visible by default" ones...
Definition: theme.cpp:712
QString
QList
QColor
MessageList::Core::Theme::Column::Column
Column()
Create an empty column with default settings.
Definition: theme.cpp:444
MessageList::Core::Theme::ContentItem::Type
Type
The available ContentItem types.
Definition: theme.h:125
MessageList::Core::Theme::NeverShowHeader
Definition: theme.h:910
MessageList::Core::Theme::Row::containsTextItems
bool containsTextItems() const
Returns true if this row contains text items.
Definition: theme.cpp:288
gThemeMinimumVersionWithSortingByUnreadStatusAllowed
static const int gThemeMinimumVersionWithSortingByUnreadStatusAllowed
Definition: theme.cpp:53
gThemeMinimumSupportedVersion
static const int gThemeMinimumSupportedVersion
Definition: theme.cpp:50
QPair
MessageList::Core::Theme::CustomColor
Use a custom color.
Definition: theme.h:886
MessageList::Core::Theme::resetColumnSizes
void resetColumnSizes()
Resets the column sizes to "default" (subset of resetColumnState() above).
Definition: theme.cpp:722
MessageList::Core::Theme::Theme
Theme()
Creates a totally uninitialized theme object.
Definition: theme.cpp:668
MessageList::Core::SortOrder::NoMessageSorting
Don't sort the messages at all.
Definition: sortorder.h:80
MessageList::Core::Theme::Column::~Column
~Column()
Kill a column object.
Definition: theme.cpp:472
MessageList::Core::Theme::Column::SharedRuntimeData::save
void save(QDataStream &stream) const
Saves this runtime data to the specified stream.
Definition: theme.cpp:425
MessageList::Core::Theme::RoundedJoinedRect
One big rounded rect for all the columns.
Definition: theme.h:897
MessageList::Core::Theme::PlainJoinedRect
One big plain rect for all the columns.
Definition: theme.h:895
MessageList::Core::Theme::setIconSize
void setIconSize(int iconSize)
Sets the icon size for this theme.
Definition: theme.cpp:783
MessageList::Core::Theme::enumerateViewHeaderPolicyOptions
static QList< QPair< QString, int > > enumerateViewHeaderPolicyOptions()
Enumerates the available view header policy options.
Definition: theme.cpp:760
MessageList::Core::Theme::Column::insertGroupHeaderRow
void insertGroupHeaderRow(int idx, Row *row)
Inserts a group header row to this theme column in the specified position.
Definition: theme.cpp:513
MessageList::Core::Theme::GroupHeaderBackgroundStyle
GroupHeaderBackgroundStyle
How do we paint group header background ?
Definition: theme.h:892
MessageList::Core::Theme::Column::detach
void detach()
Detaches the shared runtime data object and makes this object totally independent.
Definition: theme.cpp:480
gThemeCurrentVersion
static const int gThemeCurrentVersion
Definition: theme.cpp:48
gThemeMinimumVersionWithIconSizeField
static const int gThemeMinimumVersionWithIconSizeField
Definition: theme.cpp:52
MessageList::Core::Theme::ContentItem::ContentItem
ContentItem(Type type)
Creates a ContentItem with the specified type.
Definition: theme.cpp:62
MessageList::Core::SortOrder::SortMessagesByUnreadStatus
Sort the messages by the "Unread" flags of status.
Definition: sortorder.h:89
MessageList::Core::Theme::Row::insertLeftItem
void insertLeftItem(int idx, ContentItem *item)
Adds a left aligned item at the specified position in this row.
Definition: theme.cpp:268
MessageList::Core::Theme::detach
void detach()
Detaches this object from the shared runtime data for columns.
Definition: theme.cpp:705
MessageList::Core::Theme
The Theme class defines the visual appearance of the MessageList.
Definition: theme.h:65
MessageList::Core::Theme::Column::SharedRuntimeData::load
bool load(QDataStream &stream, int themeVersion)
Loads the shared runtime data from the specified stream assuming that it uses the specified theme ver...
Definition: theme.cpp:431
MessageList::Core::Theme::load
virtual bool load(QDataStream &stream)
Pure virtual reimplemented from OptionSet.
Definition: theme.cpp:790
MessageList::Core::Theme::Column::SharedRuntimeData::SharedRuntimeData
SharedRuntimeData(bool currentlyVisible, int currentWidth)
Create a shared runtime data object.
Definition: theme.cpp:404
MessageList::Core::Theme::save
virtual void save(QDataStream &stream) const
Pure virtual reimplemented from OptionSet.
Definition: theme.cpp:892
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
MessageList::Core::Theme::addColumn
void addColumn(Column *column)
Appends a column to this theme.
Definition: theme.h:960
gThemeMinimumVersionWithAnnotationIcon
static const int gThemeMinimumVersionWithAnnotationIcon
Definition: theme.cpp:55
MessageList::Core::Theme::Row::~Row
~Row()
Definition: theme.cpp:250
MessageList::Core::Theme::Row::Row
Row()
Definition: theme.cpp:234
MessageList::Core::Theme::AutoColor
Automatically determine the color (somewhere in the middle between background and text) ...
Definition: theme.h:885
MessageList::Core::Theme::Column::removeAllGroupHeaderRows
void removeAllGroupHeaderRows()
Removes all the group header rows from this column.
Definition: theme.cpp:497
MessageList::Core::Theme::~Theme
~Theme()
Destroys this theme object.
Definition: theme.cpp:700
MessageList::Core::Theme::GradientRect
One rounded gradient filled rect per column.
Definition: theme.h:898
MessageList::Core::Theme::Column::SharedRuntimeData::~SharedRuntimeData
~SharedRuntimeData()
Destroy a shared runtime data object.
Definition: theme.cpp:409
MessageList::Core::Theme::Row::insertRightItem
void insertRightItem(int idx, ContentItem *item)
Adds a right aligned item at the specified position in this row.
Definition: theme.cpp:278
MessageList::Core::Theme::StyledRect
One styled rect per column.
Definition: theme.h:900
MessageList::Core::Theme::Column::SharedRuntimeData
A set of shared runtime data.
Definition: theme.h:572
QColor::isValid
bool isValid() const
MessageList::Core::Theme::RoundedRect
One rounded rect per column.
Definition: theme.h:896
MessageList::Core::Theme::ViewHeaderPolicy
ViewHeaderPolicy
How do we manage the QHeaderView attacched to our View ?
Definition: theme.h:907
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