summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimrecord.h
blob: 4981a41f2ba80253554eee717a1d0405bba542f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
                             This file is part of the Opie Project
                             Copyright (C) The Main Author <main-author@whereever.org>
              =.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
            .=l.
           .>+-=
 _;:,     .>    :=|.         This program is free software; you can
.> <`_,   >  .   <=          redistribute it and/or  modify it under
:`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
.="- .-=="i,     .._         License as published by the Free Software
 - .   .-<_>     .<>         Foundation; either version 2 of the License,
     ._= =}       :          or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s.       This program is distributed in the hope that
     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
    : ..    .:,     . . .    without even the implied warranty of
    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ;      Library General Public License for more
++=   -.     .`     .:       details.
 :     =  ...= . :.=-
 -.   .:....=;==+<;          You should have received a copy of the GNU
  -_. . .   )=.  =           Library General Public License along with
    --        :-=`           this library; see the file COPYING.LIB.
                             If not, write to the Free Software Foundation,
                             Inc., 59 Temple Place - Suite 330,
                             Boston, MA 02111-1307, USA.
*/

#ifndef OPIMRECORD_H
#define OPIMRECORD_H

/* OPIE */
#include <opie2/opimxrefmanager.h>
/*
 * we need to get customMap which is private...
 */
#define private protected
#include <qpe/palmtoprecord.h>
#undef private

/* QT */
#include <qdatastream.h>
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>

namespace Opie
{
/**
 * This is the base class for
 * all PIM Records
 *
 */
class OPimRecord : public Qtopia::Record
{
  public:
    /**
     * c'tor
     * uid of 0 isEmpty
     * uid of 1 will be assigned a new one
     */
    OPimRecord( int uid = 0 );
    ~OPimRecord();

    /**
     * copy c'tor
     */
    OPimRecord( const OPimRecord& rec );

    /**
     * copy operator
     */
    OPimRecord &operator=( const OPimRecord& );

    /**
     * category names resolved
     */
    QStringList categoryNames( const QString& appname ) const;

    /**
     * set category names they will be resolved
     */
    void setCategoryNames( const QStringList& );

    /**
     * addCategoryName adds a name
     * to the internal category list
     */
    void addCategoryName( const QString& );

    /**
     * if a Record isEmpty
     * it's empty if it's 0
     */
    virtual bool isEmpty() const;

    /**
     * toRichText summary
     */
    virtual QString toRichText() const = 0;

    /**
     * a small one line summary
     */
    virtual QString toShortText() const = 0;

    /**
     * the name of the Record
     */
    virtual QString type() const = 0;

    /**
     * matches the Records the regular expression?
     */
    virtual bool match( const QString &regexp ) const
    {
        setLastHitField( -1 );
        return Qtopia::Record::match( QRegExp( regexp ) );
    };

    /**
     * if implemented this function returns which item has been
     * last hit by the match() function.
     * or -1 if not implemented or no hit has occured
     */
    int lastHitField() const;

    /**
     * converts the internal structure to a map
     */
    virtual QMap<int, QString> toMap() const = 0;
    // virtual fromMap( const <int, QString>& map ) = 0; // Should be added in the future (eilers)

    /**
     * key value representation of extra items
     */
    QMap<QString, QString> toExtraMap() const;
    void setExtraMap( const QMap<QString, QString>& );

    /**
     * the name for a recordField
     */
    virtual QString recordField( int ) const = 0;

    /**
     * returns a reference of the
     * Cross Reference Manager
     * Partner 'One' is THIS PIM RECORD!
     * 'Two' is the Partner where we link to
     */
    OPimXRefManager& xrefmanager();

    /**
     * set the uid
     */
    virtual void setUid( int uid );

    /*
     * used inside the Templates for casting
     * REIMPLEMENT in your ....
     */
    static int rtti();

    /**
     * some marshalling and de marshalling code
     * saves the OPimRecord
     * to and from a DataStream
     */
    virtual bool loadFromStream( QDataStream& );
    virtual bool saveToStream( QDataStream& stream ) const;

  protected:
    // need to be const cause it is called from const methods
    mutable int m_lastHit;
    void setLastHitField( int lastHit ) const;
    Qtopia::UidGen &uidGen();
    //    QString crossToString()const;

  private:
    class OPimRecordPrivate;
    OPimRecordPrivate *d;
    OPimXRefManager m_xrefman;
    static Qtopia::UidGen m_uidGen;

  private:
    void flush( const OPimXRefPartner&, QDataStream& stream ) const;
    OPimXRefPartner partner( QDataStream& );
};

}

#endif