Diffstat (limited to 'library/backend/palmtoprecord.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | library/backend/palmtoprecord.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/library/backend/palmtoprecord.cpp b/library/backend/palmtoprecord.cpp new file mode 100644 index 0000000..0d57699 --- a/dev/null +++ b/library/backend/palmtoprecord.cpp | |||
@@ -0,0 +1,127 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free | ||
8 | ** Software Foundation and appearing in the file LICENSE.GPL included | ||
9 | ** in the packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING | ||
12 | ** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A | ||
13 | ** PARTICULAR PURPOSE. | ||
14 | ** | ||
15 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
16 | ** | ||
17 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
18 | ** not clear to you. | ||
19 | ** | ||
20 | **********************************************************************/ | ||
21 | #include "palmtoprecord.h" | ||
22 | #include "stringutil.h" | ||
23 | #include <qstringlist.h> | ||
24 | |||
25 | namespace Qtopia { | ||
26 | |||
27 | Record &Record::operator=( const Record &c ) | ||
28 | { | ||
29 | mUid = c.mUid; | ||
30 | mCats = c.mCats; | ||
31 | customMap = c.customMap; | ||
32 | return *this; | ||
33 | } | ||
34 | |||
35 | void Record::setCategories( int single ) | ||
36 | { | ||
37 | if ( single == 0 ) | ||
38 | return; | ||
39 | mCats.resize(1); | ||
40 | mCats[0] = single; | ||
41 | } | ||
42 | |||
43 | // convenience methods provided for loading and saving to xml | ||
44 | QString Record::idsToString( const QArray<int> &cats ) | ||
45 | { | ||
46 | QString str; | ||
47 | for ( uint i = 0; i < cats.size(); i++ ) | ||
48 | if ( i == 0 ) | ||
49 | str = QString::number( cats[int(i)] ); | ||
50 | else | ||
51 | str += ";" + QString::number( cats[int(i)] ); | ||
52 | |||
53 | return str; | ||
54 | } | ||
55 | |||
56 | // convenience methods provided for loading and saving to xml | ||
57 | QArray<int> Record::idsFromString( const QString &str ) | ||
58 | { | ||
59 | QStringList catStrs = QStringList::split( ";", str ); | ||
60 | QArray<int> cats( catStrs.count() ); | ||
61 | uint i = 0; | ||
62 | for ( QStringList::ConstIterator it = catStrs.begin(); | ||
63 | it != catStrs.end(); ++it ) { | ||
64 | cats[int(i)] = (*it).toInt(); | ||
65 | i++; | ||
66 | } | ||
67 | return cats; | ||
68 | } | ||
69 | |||
70 | /*! | ||
71 | Returns the string stored for the custom field \a key. | ||
72 | Returns a null string if the field does not exist. | ||
73 | */ | ||
74 | QString Record::customField( const QString &key) const | ||
75 | { | ||
76 | if (customMap.contains(key)) | ||
77 | return customMap[key]; | ||
78 | |||
79 | return QString::null; | ||
80 | } | ||
81 | |||
82 | /*! | ||
83 | Sets the string stored for the custom field \a key to \a value. | ||
84 | */ | ||
85 | void Record::setCustomField( const QString &key, const QString &value) | ||
86 | { | ||
87 | qWarning("setting custom " + key + " to " + value); | ||
88 | if (customMap.contains(key)) | ||
89 | customMap.replace(key, value); | ||
90 | else | ||
91 | customMap.insert(key, value); | ||
92 | |||
93 | qWarning(QString("custom size %1").arg(customMap.count())); | ||
94 | } | ||
95 | |||
96 | /*! | ||
97 | Removes the custom field \a key. | ||
98 | */ | ||
99 | void Record::removeCustomField(const QString &key) | ||
100 | { | ||
101 | customMap.remove(key); | ||
102 | } | ||
103 | |||
104 | QString Record::customToXml() const | ||
105 | { | ||
106 | //qWarning(QString("writing custom %1").arg(customMap.count())); | ||
107 | QString buf(" "); | ||
108 | for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); | ||
109 | cit != customMap.end(); ++cit) { | ||
110 | qWarning(".ITEM."); | ||
111 | buf += cit.key(); | ||
112 | buf += "=\""; | ||
113 | buf += escapeString(cit.data()); | ||
114 | buf += "\" "; | ||
115 | } | ||
116 | return buf; | ||
117 | } | ||
118 | |||
119 | void Record::dump( const QMap<int, QString> &map ) | ||
120 | { | ||
121 | QMap<int, QString>::ConstIterator it; | ||
122 | for( it = map.begin(); it != map.end(); ++it ) | ||
123 | qDebug("%d : %s", it.key(), it.data().local8Bit().data() ); | ||
124 | } | ||
125 | |||
126 | } | ||
127 | |||