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

messagelist

  • sources
  • kde-4.12
  • 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 <KLocale>
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::load( QDataStream &stream, int themeVersion )
329 {
330  removeAllLeftItems();
331  removeAllRightItems();
332 
333  int val;
334 
335  // left item count
336 
337  stream >> val;
338 
339  if ( ( val < 0 ) || ( val > 50 ) )
340  return false; // senseless
341 
342  // FIXME: Remove code duplication here
343 
344  for ( int i = 0; i < val ; ++i )
345  {
346  ContentItem * ci = new ContentItem( ContentItem::Subject ); // dummy type
347  if ( !ci->load( stream, themeVersion ) )
348  {
349  kDebug() << "Left content item loading failed";
350  delete ci;
351  return false;
352  }
353  addLeftItem( ci );
354 
355  // Add the annotation item next to the attachment icon, so that users upgrading from old
356  // versions don't manually need to set this.
357  // Don't do this for the stand-alone attchment column.
358  if ( ci->type() == ContentItem::AttachmentStateIcon &&
359  themeVersion < gThemeMinimumVersionWithAnnotationIcon &&
360  val > 1 ) {
361  kDebug() << "Old theme version detected, adding annotation item next to attachment icon.";
362  ContentItem *annotationItem = new ContentItem( ContentItem::AnnotationIcon ) ;
363  annotationItem->setHideWhenDisabled( true );
364  addLeftItem( annotationItem );
365  }
366 
367  // Same as above, for the invitation icon
368  if ( ci->type() == ContentItem::AttachmentStateIcon &&
369  themeVersion < gThemeMinimumVersionWithInvitationIcon &&
370  val > 1 ) {
371  kDebug() << "Old theme version detected, adding invitation item next to attachment icon.";
372  ContentItem *invitationItem = new ContentItem( ContentItem::InvitationIcon ) ;
373  invitationItem->setHideWhenDisabled( true );
374  addLeftItem( invitationItem );
375  }
376  }
377 
378  // right item count
379 
380  stream >> val;
381 
382  if ( ( val < 0 ) || ( val > 50 ) )
383  return false; // senseless
384 
385  for ( int i = 0; i < val ; ++i )
386  {
387  ContentItem * ci = new ContentItem( ContentItem::Subject ); // dummy type
388  if ( !ci->load( stream, themeVersion ) )
389  {
390  kDebug() << "Right content item loading failed";
391  delete ci;
392  return false;
393  }
394  addRightItem( ci );
395  if ( ci->type() == ContentItem::AttachmentStateIcon &&
396  themeVersion < gThemeMinimumVersionWithAnnotationIcon &&
397  val > 1 ) {
398  kDebug() << "Old theme version detected, adding annotation item next to attachment icon.";
399  ContentItem *annotationItem = new ContentItem( ContentItem::AnnotationIcon ) ;
400  annotationItem->setHideWhenDisabled( true );
401  addRightItem( annotationItem );
402  }
403  if ( ci->type() == ContentItem::AttachmentStateIcon &&
404  themeVersion < gThemeMinimumVersionWithInvitationIcon &&
405  val > 1 ) {
406  kDebug() << "Old theme version detected, adding invitation item next to attachment icon.";
407  ContentItem *invitationItem = new ContentItem( ContentItem::InvitationIcon ) ;
408  invitationItem->setHideWhenDisabled( true );
409  addRightItem( invitationItem );
410  }
411  }
412 
413  return true;
414 }
415 
416 
417 Theme::Column::SharedRuntimeData::SharedRuntimeData( bool currentlyVisible, int currentWidth )
418  : mReferences( 0 ), mCurrentlyVisible( currentlyVisible ), mCurrentWidth( currentWidth )
419 {
420 }
421 
422 Theme::Column::SharedRuntimeData::~SharedRuntimeData()
423 {
424 }
425 
426 void Theme::Column::SharedRuntimeData::addReference()
427 {
428  mReferences++;
429 }
430 
431 bool Theme::Column::SharedRuntimeData::deleteReference()
432 {
433  mReferences--;
434  Q_ASSERT( mReferences >= 0 );
435  return mReferences > 0;
436 }
437 
438 void Theme::Column::SharedRuntimeData::save( QDataStream &stream ) const
439 {
440  stream << mCurrentlyVisible;
441  stream << mCurrentWidth;
442 }
443 
444 bool Theme::Column::SharedRuntimeData::load( QDataStream &stream, int /* themeVersion */ )
445 {
446  stream >> mCurrentlyVisible;
447  stream >> mCurrentWidth;
448  if ( mCurrentWidth > 10000 )
449  {
450  kDebug() << "Theme has insane column width " << mCurrentWidth << " chopping to 100";
451  mCurrentWidth = 100; // avoid really insane values
452  }
453  return (mCurrentWidth >= -1);
454 }
455 
456 
457 Theme::Column::Column()
458  : mVisibleByDefault( true ),
459  mIsSenderOrReceiver( false ),
460  mMessageSorting( SortOrder::NoMessageSorting )
461 {
462  mSharedRuntimeData = new SharedRuntimeData( true, -1 );
463  mSharedRuntimeData->addReference();
464 }
465 
466 Theme::Column::Column( const Column &src )
467 {
468  mLabel = src.mLabel;
469  mPixmapName = src.mPixmapName;
470  mVisibleByDefault = src.mVisibleByDefault;
471  mIsSenderOrReceiver = src.mIsSenderOrReceiver;
472  mMessageSorting = src.mMessageSorting;
473 
474  mSharedRuntimeData = src.mSharedRuntimeData;
475  mSharedRuntimeData->addReference();
476  QList< Row * >::ConstIterator end( src.mMessageRows.constEnd() );
477  for ( QList< Row * >::ConstIterator it = src.mMessageRows.constBegin(); it != end ; ++it )
478  addMessageRow( new Row( *( *it ) ) );
479 
480  end = src.mGroupHeaderRows.constEnd();
481  for ( QList< Row * >::ConstIterator it = src.mGroupHeaderRows.constBegin(); it != end ; ++it )
482  addGroupHeaderRow( new Row( *( *it ) ) );
483 }
484 
485 Theme::Column::~Column()
486 {
487  removeAllMessageRows();
488  removeAllGroupHeaderRows();
489  if( !( mSharedRuntimeData->deleteReference() ) )
490  delete mSharedRuntimeData;
491 }
492 
493 void Theme::Column::detach()
494 {
495  if( mSharedRuntimeData->referenceCount() < 2 )
496  return; // nothing to detach
497  mSharedRuntimeData->deleteReference();
498 
499  mSharedRuntimeData = new SharedRuntimeData( mVisibleByDefault, -1 );
500  mSharedRuntimeData->addReference();
501 
502 }
503 
504 void Theme::Column::removeAllMessageRows()
505 {
506  while ( !mMessageRows.isEmpty() )
507  delete mMessageRows.takeFirst();
508 }
509 
510 void Theme::Column::removeAllGroupHeaderRows()
511 {
512  while ( !mGroupHeaderRows.isEmpty() )
513  delete mGroupHeaderRows.takeFirst();
514 }
515 
516 void Theme::Column::insertMessageRow( int idx, Row * row )
517 {
518  if ( idx >= mMessageRows.count() )
519  {
520  mMessageRows.append( row );
521  return;
522  }
523  mMessageRows.insert( idx, row );
524 }
525 
526 void Theme::Column::insertGroupHeaderRow( int idx, Row * row )
527 {
528  if ( idx >= mGroupHeaderRows.count() )
529  {
530  mGroupHeaderRows.append( row );
531  return;
532  }
533  mGroupHeaderRows.insert( idx, row );
534 }
535 
536 bool Theme::Column::containsTextItems() const
537 {
538  QList< Row * >::ConstIterator end( mMessageRows.constEnd() );
539  for ( QList< Row * >::ConstIterator it = mMessageRows.constBegin(); it != end ; ++it )
540  {
541  if ( ( *it )->containsTextItems() )
542  return true;
543  }
544  end = mGroupHeaderRows.constEnd();
545  for ( QList< Row * >::ConstIterator it = mGroupHeaderRows.constBegin(); it != end ; ++it )
546  {
547  if ( ( *it )->containsTextItems() )
548  return true;
549  }
550  return false;
551 }
552 
553 void Theme::Column::save( QDataStream &stream ) const
554 {
555  stream << mLabel;
556  stream << mPixmapName;
557  stream << mVisibleByDefault;
558  stream << mIsSenderOrReceiver;
559  stream << (int)mMessageSorting;
560 
561  stream << (int)mGroupHeaderRows.count();
562 
563  int cnt = mGroupHeaderRows.count();
564 
565  for ( int i = 0; i < cnt ; ++i )
566  {
567  Row * row = mGroupHeaderRows.at( i );
568  row->save( stream );
569  }
570 
571  cnt = mMessageRows.count();
572  stream << (int)cnt;
573 
574  for ( int i = 0; i < cnt ; ++i )
575  {
576  Row * row = mMessageRows.at( i );
577  row->save( stream );
578  }
579 
580  // added in version 0x1014
581  mSharedRuntimeData->save( stream );
582 
583 }
584 
585 bool Theme::Column::load( QDataStream &stream, int themeVersion )
586 {
587  removeAllGroupHeaderRows();
588  removeAllMessageRows();
589 
590  stream >> mLabel;
591 
592  if ( themeVersion >= gThemeMinimumVersionWithColumnIcon )
593  stream >> mPixmapName;
594 
595  stream >> mVisibleByDefault;
596  stream >> mIsSenderOrReceiver;
597 
598  int val;
599 
600  stream >> val;
601  mMessageSorting = static_cast< SortOrder::MessageSorting >( val );
602  if ( !SortOrder::isValidMessageSorting( mMessageSorting ) )
603  {
604  kDebug() << "Invalid message sorting";
605  return false;
606  }
607 
608  if ( themeVersion < gThemeMinimumVersionWithSortingByUnreadStatusAllowed )
609  {
610  // The default "Classic" theme "Unread" column had sorting disabled here.
611  // We want to be nice to the existing users and automatically set
612  // the new sorting method for this column (so they don't have to make the
613  // complex steps to set it by themselves).
614  // This piece of code isn't strictly required: it's just a niceness :)
615  if ( ( mMessageSorting == SortOrder::NoMessageSorting ) && ( mLabel == i18n( "Unread" ) ) )
616  mMessageSorting = SortOrder::SortMessagesByUnreadStatus;
617  }
618 
619  // group header row count
620  stream >> val;
621 
622  if ( ( val < 0 ) || ( val > 50 ) )
623  {
624  kDebug() << "Invalid group header row count";
625  return false; // senseless
626  }
627 
628  for ( int i = 0; i < val ; ++i )
629  {
630  Row * row = new Row();
631  if ( !row->load( stream, themeVersion ) )
632  {
633  kDebug() << "Group header row loading failed";
634  delete row;
635  return false;
636  }
637  addGroupHeaderRow( row );
638  }
639 
640  // message row count
641  stream >> val;
642 
643  if ( ( val < 0 ) || ( val > 50 ) )
644  {
645  kDebug() << "Invalid message row count";
646  return false; // senseless
647  }
648 
649  for ( int i = 0; i < val ; ++i )
650  {
651  Row * row = new Row();
652  if ( !row->load( stream, themeVersion ) )
653  {
654  kDebug() << "Message row loading failed";
655  delete row;
656  return false;
657  }
658  addMessageRow( row );
659  }
660 
661  if ( themeVersion >= gThemeMinimumVersionWithColumnRuntimeData )
662  {
663  // starting with version 0x1014 we have runtime data too
664  if( !mSharedRuntimeData->load( stream, themeVersion ) )
665  {
666  kDebug() << "Shared runtime data loading failed";
667  return false;
668  }
669  } else {
670  // assume default shared data
671  mSharedRuntimeData->setCurrentlyVisible( mVisibleByDefault );
672  mSharedRuntimeData->setCurrentWidth( -1 );
673  }
674 
675  return true;
676 }
677 
678 
679 
680 
681 Theme::Theme()
682  : OptionSet()
683 {
684  mGroupHeaderBackgroundMode = AutoColor;
685  mViewHeaderPolicy = ShowHeaderAlways;
686  mIconSize = gThemeDefaultIconSize;
687  mGroupHeaderBackgroundStyle = StyledJoinedRect;
688 }
689 
690 Theme::Theme( const QString &name, const QString &description, bool readOnly )
691  : OptionSet( name, description, readOnly )
692 {
693  mGroupHeaderBackgroundMode = AutoColor;
694  mGroupHeaderBackgroundStyle = StyledJoinedRect;
695  mViewHeaderPolicy = ShowHeaderAlways;
696  mIconSize = gThemeDefaultIconSize;
697 }
698 
699 
700 Theme::Theme( const Theme &src )
701  : OptionSet( src )
702 {
703  mGroupHeaderBackgroundMode = src.mGroupHeaderBackgroundMode;
704  mGroupHeaderBackgroundColor = src.mGroupHeaderBackgroundColor;
705  mGroupHeaderBackgroundStyle = src.mGroupHeaderBackgroundStyle;
706  mViewHeaderPolicy = src.mViewHeaderPolicy;
707  mIconSize = src.mIconSize;
708  QList< Column * >::ConstIterator end( src.mColumns.constEnd() );
709  for ( QList< Column * >::ConstIterator it = src.mColumns.constBegin(); it != end ; ++it )
710  addColumn( new Column( *( *it ) ) );
711 }
712 
713 Theme::~Theme()
714 {
715  removeAllColumns();
716 }
717 
718 void Theme::detach()
719 {
720  QList< Column * >::ConstIterator end( mColumns.constEnd() );
721  for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end ; ++it )
722  ( *it )->detach();
723 }
724 
725 void Theme::resetColumnState()
726 {
727  QList< Column * >::ConstIterator end( mColumns.constEnd() );
728  for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end ; ++it )
729  {
730  ( *it )->setCurrentlyVisible( ( *it )->visibleByDefault() );
731  ( *it )->setCurrentWidth( -1 );
732  }
733 }
734 
735 void Theme::resetColumnSizes()
736 {
737  QList< Column * >::ConstIterator end( mColumns.constEnd() );
738  for ( QList< Column * >::ConstIterator it = mColumns.constBegin(); it != end; ++it )
739  ( *it )->setCurrentWidth( -1 );
740 }
741 
742 
743 void Theme::removeAllColumns()
744 {
745  while ( !mColumns.isEmpty() )
746  delete mColumns.takeFirst();
747 }
748 
749 void Theme::insertColumn( int idx, Column * column )
750 {
751  if ( idx >= mColumns.count() )
752  {
753  mColumns.append( column );
754  return;
755  }
756  mColumns.insert( idx, column );
757 }
758 
759 void Theme::moveColumn(int idx, int newPosition)
760 {
761  if ( (newPosition >= mColumns.count()) || newPosition < 0 )
762  return;
763  mColumns.move( idx, newPosition );
764 }
765 
766 void Theme::setGroupHeaderBackgroundMode( GroupHeaderBackgroundMode bm )
767 {
768  mGroupHeaderBackgroundMode = bm;
769  if ( ( bm == CustomColor ) && !mGroupHeaderBackgroundColor.isValid() )
770  mGroupHeaderBackgroundColor = QColor( 127, 127, 127 ); // something neutral
771 }
772 
773 QList< QPair< QString, int > > Theme::enumerateViewHeaderPolicyOptions()
774 {
775  QList< QPair< QString, int > > ret;
776  ret.append( QPair< QString, int >( i18n( "Never Show" ), NeverShowHeader ) );
777  ret.append( QPair< QString, int >( i18n( "Always Show" ), ShowHeaderAlways ) );
778  return ret;
779 }
780 
781 QList< QPair< QString, int > > Theme::enumerateGroupHeaderBackgroundStyles()
782 {
783  QList< QPair< QString, int > > ret;
784  ret.append( QPair< QString, int >( i18n( "Plain Rectangles" ), PlainRect ) );
785  ret.append( QPair< QString, int >( i18n( "Plain Joined Rectangle" ), PlainJoinedRect ) );
786  ret.append( QPair< QString, int >( i18n( "Rounded Rectangles" ), RoundedRect ) );
787  ret.append( QPair< QString, int >( i18n( "Rounded Joined Rectangle" ), RoundedJoinedRect ) );
788  ret.append( QPair< QString, int >( i18n( "Gradient Rectangles" ), GradientRect ) );
789  ret.append( QPair< QString, int >( i18n( "Gradient Joined Rectangle" ), GradientJoinedRect ) );
790  ret.append( QPair< QString, int >( i18n( "Styled Rectangles" ), StyledRect ) );
791  ret.append( QPair< QString, int >( i18n( "Styled Joined Rectangles" ), StyledJoinedRect ) );
792 
793  return ret;
794 }
795 
796 void Theme::setIconSize( int iconSize )
797 {
798  mIconSize = iconSize;
799  if ( ( mIconSize < 8 ) || ( mIconSize > 64 ) )
800  mIconSize = gThemeDefaultIconSize;
801 }
802 
803 bool Theme::load( QDataStream &stream )
804 {
805  removeAllColumns();
806 
807  int themeVersion;
808 
809  stream >> themeVersion;
810 
811  // We support themes starting at version gThemeMinimumSupportedVersion (0x1013 actually)
812 
813  if (
814  ( themeVersion > gThemeCurrentVersion ) ||
815  ( themeVersion < gThemeMinimumSupportedVersion )
816  )
817  {
818  kDebug() << "Invalid theme version";
819  return false; // b0rken (invalid version)
820  }
821 
822  int val;
823 
824  stream >> val;
825  mGroupHeaderBackgroundMode = (GroupHeaderBackgroundMode)val;
826  switch(mGroupHeaderBackgroundMode)
827  {
828  case Transparent:
829  case AutoColor:
830  case CustomColor:
831  // ok
832  break;
833  default:
834  kDebug() << "Invalid theme group header background mode";
835  return false; // b0rken
836  break;
837  }
838 
839  stream >> mGroupHeaderBackgroundColor;
840 
841  stream >> val;
842  mGroupHeaderBackgroundStyle = (GroupHeaderBackgroundStyle)val;
843  switch(mGroupHeaderBackgroundStyle)
844  {
845  case PlainRect:
846  case PlainJoinedRect:
847  case RoundedRect:
848  case RoundedJoinedRect:
849  case GradientRect:
850  case GradientJoinedRect:
851  case StyledRect:
852  case StyledJoinedRect:
853  // ok
854  break;
855  default:
856  kDebug() << "Invalid theme group header background style";
857  return false; // b0rken
858  break;
859  }
860 
861  stream >> val;
862  mViewHeaderPolicy = (ViewHeaderPolicy)val;
863  switch(mViewHeaderPolicy)
864  {
865  case ShowHeaderAlways:
866  case NeverShowHeader:
867  // ok
868  break;
869  default:
870  kDebug() << "Invalid theme view header policy";
871  return false; // b0rken
872  break;
873  }
874 
875  if ( themeVersion >= gThemeMinimumVersionWithIconSizeField )
876  {
877  // icon size parameter
878  stream >> mIconSize;
879  if ( ( mIconSize < 8 ) || ( mIconSize > 64 ) )
880  mIconSize = gThemeDefaultIconSize; // limit insane values
881  } else {
882  mIconSize = gThemeDefaultIconSize;
883  }
884 
885  // column count
886  stream >> val;
887  if ( val < 1 || val > 50 )
888  return false; // plain b0rken ( negative, zero or more than 50 columns )
889 
890  for ( int i = 0; i < val ; ++i )
891  {
892  Column * col = new Column();
893  if ( !col->load( stream, themeVersion ) )
894  {
895  kDebug() << "Column loading failed";
896  delete col;
897  return false;
898  }
899  addColumn( col );
900  }
901 
902  return true;
903 }
904 
905 void Theme::save( QDataStream &stream ) const
906 {
907  stream << (int)gThemeCurrentVersion;
908 
909  stream << (int)mGroupHeaderBackgroundMode;
910  stream << mGroupHeaderBackgroundColor;
911  stream << (int)mGroupHeaderBackgroundStyle;
912  stream << (int)mViewHeaderPolicy;
913  stream << mIconSize;
914 
915  const int cnt = mColumns.count();
916  stream << (int)cnt;
917 
918 
919  for ( int i = 0; i < cnt ; ++i )
920  {
921  Column * col = mColumns.at( i );
922  col->save( stream );
923  }
924 }
925 
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:328
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:743
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:536
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:266
gThemeMinimumVersionWithColumnRuntimeData
static const int gThemeMinimumVersionWithColumnRuntimeData
Definition: theme.cpp:51
MessageList::Core::Theme::Column::SharedRuntimeData::addReference
void addReference()
Increments the reference count for this shared runtime data object.
Definition: theme.cpp:426
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:516
MessageList::Core::Theme::insertColumn
void insertColumn(int idx, Column *column)
Inserts a column to this theme at the specified position.
Definition: theme.cpp:749
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:759
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:908
theme.h
MessageList::Core::Theme::Column::load
bool load(QDataStream &stream, int themeVersion)
Handles column loading (used by Theme::load())
Definition: theme.cpp:585
MessageList::Core::Theme::Column::removeAllMessageRows
void removeAllMessageRows()
Removes all the message rows from this column.
Definition: theme.cpp:504
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:766
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:564
MessageList::Core::Theme::StyledJoinedRect
One big styled rect per column.
Definition: theme.h:900
MessageList::Core::Theme::iconSize
int iconSize() const
Returns the currently set icon size.
Definition: theme.h:1037
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:781
MessageList::Core::Theme::Transparent
No background at all: use style default.
Definition: theme.h:883
MessageList::Core::Theme::PlainRect
One plain rect per column.
Definition: theme.h:893
MessageList::Core::Theme::GradientJoinedRect
One big rounded gradient rect for all the columns.
Definition: theme.h:898
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:553
MessageList::Core::Theme::Column::SharedRuntimeData::deleteReference
bool deleteReference()
Decrements the reference count for this shared runtime data object.
Definition: theme.cpp:431
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:881
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:725
MessageList::Core::Theme::Column::Column
Column()
Create an empty column with default settings.
Definition: theme.cpp:457
MessageList::Core::Theme::ContentItem::Type
Type
The available ContentItem types.
Definition: theme.h:125
MessageList::Core::Theme::NeverShowHeader
Definition: theme.h:909
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
MessageList::Core::Theme::CustomColor
Use a custom color.
Definition: theme.h:885
MessageList::Core::Theme::resetColumnSizes
void resetColumnSizes()
Resets the column sizes to "default" (subset of resetColumnState() above).
Definition: theme.cpp:735
MessageList::Core::Theme::Theme
Theme()
Creates a totally uninitialized theme object.
Definition: theme.cpp:681
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:485
MessageList::Core::Theme::Column::SharedRuntimeData::save
void save(QDataStream &stream) const
Saves this runtime data to the specified stream.
Definition: theme.cpp:438
MessageList::Core::Theme::RoundedJoinedRect
One big rounded rect for all the columns.
Definition: theme.h:896
MessageList::Core::Theme::PlainJoinedRect
One big plain rect for all the columns.
Definition: theme.h:894
MessageList::Core::Theme::setIconSize
void setIconSize(int iconSize)
Sets the icon size for this theme.
Definition: theme.cpp:796
MessageList::Core::Theme::enumerateViewHeaderPolicyOptions
static QList< QPair< QString, int > > enumerateViewHeaderPolicyOptions()
Enumerates the available view header policy options.
Definition: theme.cpp:773
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:526
MessageList::Core::Theme::GroupHeaderBackgroundStyle
GroupHeaderBackgroundStyle
How do we paint group header background ?
Definition: theme.h:891
MessageList::Core::Theme::Column::detach
void detach()
Detaches the shared runtime data object and makes this object totally independent.
Definition: theme.cpp:493
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:718
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:444
MessageList::Core::Theme::load
virtual bool load(QDataStream &stream)
Pure virtual reimplemented from OptionSet.
Definition: theme.cpp:803
MessageList::Core::Theme::Column::SharedRuntimeData::SharedRuntimeData
SharedRuntimeData(bool currentlyVisible, int currentWidth)
Create a shared runtime data object.
Definition: theme.cpp:417
MessageList::Core::Theme::save
virtual void save(QDataStream &stream) const
Pure virtual reimplemented from OptionSet.
Definition: theme.cpp:905
MessageList::Core::Theme::addColumn
void addColumn(Column *column)
Appends a column to this theme.
Definition: theme.h:959
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:884
MessageList::Core::Theme::Column::removeAllGroupHeaderRows
void removeAllGroupHeaderRows()
Removes all the group header rows from this column.
Definition: theme.cpp:510
MessageList::Core::Theme::~Theme
~Theme()
Destroys this theme object.
Definition: theme.cpp:713
MessageList::Core::Theme::GradientRect
One rounded gradient filled rect per column.
Definition: theme.h:897
MessageList::Core::Theme::Column::SharedRuntimeData::~SharedRuntimeData
~SharedRuntimeData()
Destroy a shared runtime data object.
Definition: theme.cpp:422
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::ContentItem::setHideWhenDisabled
void setHideWhenDisabled(bool hideWhenDisabled)
Sets the flag that causes this item to be hidden when disabled.
Definition: theme.h:372
MessageList::Core::Theme::StyledRect
One styled rect per column.
Definition: theme.h:899
MessageList::Core::Theme::Column::SharedRuntimeData
A set of shared runtime data.
Definition: theme.h:571
MessageList::Core::Theme::RoundedRect
One rounded rect per column.
Definition: theme.h:895
MessageList::Core::Theme::ViewHeaderPolicy
ViewHeaderPolicy
How do we manage the QHeaderView attacched to our View ?
Definition: theme.h:906
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:32 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

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