• 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
optionset.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/optionset.h"
22 
23 #include <time.h> // for ::time( time_t * )
24 
25 #include <QDataStream>
26 
27 static const int gOptionSetInitialMarker = 0xcafe; // don't change
28 static const int gOptionSetFinalMarker = 0xbabe; // don't change
29 
30 static const int gOptionSetCurrentVersion = 0x1001; // increase if you add new fields of change the meaning of some
31 
32 static const int gOptionSetWithReadOnLyModeVersion = 0x1002;
33 
34 using namespace MessageList::Core;
35 
36 OptionSet::OptionSet()
37  : mReadOnly( false )
38 {
39  generateUniqueId();
40 }
41 
42 OptionSet::OptionSet( const OptionSet &set )
43  : mId( set.mId ), mName( set.mName ), mDescription( set.mDescription ), mReadOnly( set.mReadOnly )
44 {
45 }
46 
47 OptionSet::OptionSet( const QString &name, const QString &description, bool readOnly )
48  : mName( name ), mDescription( description ), mReadOnly( readOnly )
49 {
50  generateUniqueId();
51 }
52 
53 OptionSet::~OptionSet()
54 {
55 }
56 
57 void OptionSet::generateUniqueId()
58 {
59  static int nextUniqueId = 0;
60  nextUniqueId++;
61  mId = QString::fromLatin1( "%1-%2" ).arg( (unsigned int)::time(0) ).arg( nextUniqueId );
62 }
63 
64 QString OptionSet::saveToString() const
65 {
66  QByteArray raw;
67 
68  {
69  QDataStream s( &raw, QIODevice::WriteOnly );
70 
71  s << gOptionSetInitialMarker;
72  s << gOptionSetWithReadOnLyModeVersion;
73  s << mId;
74  s << mName;
75  s << mDescription;
76  s << mReadOnly;
77 
78  save( s );
79 
80  s << gOptionSetFinalMarker;
81  }
82 
83  return QString::fromLatin1( raw.toHex() );
84 }
85 
86 bool OptionSet::loadFromString(const QString &data )
87 {
88  QByteArray raw = QByteArray::fromHex( data.toLatin1() );
89 
90  QDataStream s( &raw, QIODevice::ReadOnly );
91 
92  int marker;
93 
94  s >> marker;
95 
96  if ( marker != gOptionSetInitialMarker )
97  return false; // invalid configuration
98 
99  int currentVersion;
100 
101  s >> currentVersion;
102 
103  if ( currentVersion > gOptionSetWithReadOnLyModeVersion)
104  return false; // invalid configuration
105 
106  s >> mId;
107 
108  if ( mId.isEmpty() )
109  return false; // invalid configuration
110 
111  s >> mName;
112 
113  if ( mName.isEmpty() )
114  return false; // invalid configuration
115 
116  s >> mDescription;
117 
118  bool readOnly = false;
119  if ( currentVersion == gOptionSetWithReadOnLyModeVersion )
120  s >> readOnly;
121  mReadOnly = readOnly;
122 
123  if ( !load( s ) )
124  return false; // invalid configuration
125 
126  s >> marker;
127 
128  if ( marker != gOptionSetFinalMarker )
129  return false; // invalid configuration
130 
131  return true;
132 }
133 
MessageList::Core::OptionSet::mName
QString mName
Definition: optionset.h:57
MessageList::Core::OptionSet
A set of options that can be applied to the MessageList in one shot.
Definition: optionset.h:47
gOptionSetFinalMarker
static const int gOptionSetFinalMarker
Definition: optionset.cpp:28
MessageList::Core::OptionSet::mId
QString mId
Definition: optionset.h:56
optionset.h
gOptionSetInitialMarker
static const int gOptionSetInitialMarker
Definition: optionset.cpp:27
MessageList::Core::OptionSet::generateUniqueId
void generateUniqueId()
(Re)generates a (hopefully) unique identifier for this option set.
Definition: optionset.cpp:57
MessageList::Core::OptionSet::loadFromString
bool loadFromString(const QString &data)
Attempts to unpack this configuration object from a string (that is likely to come out from a config ...
Definition: optionset.cpp:86
gOptionSetWithReadOnLyModeVersion
static const int gOptionSetWithReadOnLyModeVersion
Definition: optionset.cpp:32
MessageList::Core::OptionSet::save
virtual void save(QDataStream &s) const =0
Saves the inner contents of this option set to the specified data stream.
MessageList::Core::OptionSet::mDescription
QString mDescription
Definition: optionset.h:58
MessageList::Core::OptionSet::OptionSet
OptionSet()
Definition: optionset.cpp:36
gOptionSetCurrentVersion
static const int gOptionSetCurrentVersion
Definition: optionset.cpp:30
MessageList::Core::OptionSet::mReadOnly
bool mReadOnly
Definition: optionset.h:59
MessageList::Core::OptionSet::saveToString
QString saveToString() const
Packs this configuration object into a string suitable for storing in a config file.
Definition: optionset.cpp:64
MessageList::Core::OptionSet::readOnly
bool readOnly() const
Definition: optionset.h:118
MessageList::Core::OptionSet::~OptionSet
virtual ~OptionSet()
Definition: optionset.cpp:53
MessageList::Core::OptionSet::load
virtual bool load(QDataStream &s)=0
Loads the inner contents of this option set from the specified data stream.
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