summaryrefslogtreecommitdiff
path: root/libopie/pim/opimrecord.cpp
blob: 21cf13146845ef97db94058468db55b621e076c5 (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
#include <qpe/categories.h>
#include <qpe/categoryselect.h>

#include "opimrecord.h"

Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );


OPimRecord::OPimRecord( int uid )
    : Qtopia::Record() {

    setUid( uid );
}
OPimRecord::~OPimRecord() {
}
OPimRecord::OPimRecord( const OPimRecord& rec )
    : Qtopia::Record( rec )
{
    (*this) = rec;
}

OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
    Qtopia::Record::operator=( rec );
    m_relations = rec.m_relations;

    return  *this;
}
/*
 * category names
 */
QStringList OPimRecord::categoryNames()const {
    QStringList list;
    QArray<int> cats = categories();
    Categories catDB;
    catDB.load( categoryFileName() );

    for (uint i = 0; i < cats.count(); i++ ) {
        list << catDB.label("Todo List", cats[i] );
    }

    return list;
}
void OPimRecord::setCategoryNames( const QStringList& ) {

}
void OPimRecord::addCategoryName( const QString& ) {
    Categories catDB;
    catDB.load( categoryFileName() );


}
bool OPimRecord::isEmpty()const {
    return ( uid() == 0 );
}
QStringList OPimRecord::relatedApps()const{
    QStringList list;
    QMap<QString, QArray<int> >::ConstIterator it;
    for ( it = m_relations.begin(); it != m_relations.end(); ++it ) {
        list << it.key();
    }
    return list;
}
QArray<int> OPimRecord::relations(const QString& app )const {
    QArray<int> tmp;
    QMap<QString, QArray<int> >::ConstIterator it;
    it = m_relations.find( app);
    if ( it != m_relations.end() )
        tmp = it.data();
    return tmp;
}
void OPimRecord::clearRelation( const QString& app ) {
    m_relations.remove( app );
}
void OPimRecord::addRelation( const QString& app,  int id ) {

    QMap<QString, QArray<int> >::Iterator  it;
    QArray<int> tmp;

    it = m_relations.find( app );
    if ( it == m_relations.end() ) {
        tmp.resize(1 );
        tmp[0] = id;
    }else{
        tmp = it.data();
        tmp.resize( tmp.size() + 1 );
        tmp[tmp.size() - 1] = id;
    }
    m_relations.replace( app,  tmp );
}
void OPimRecord::setRelations( const QString& app,  QArray<int> ids ) {

    QMap<QString, QArray<int> >::Iterator it;
    QArray<int> tmp;

    it = m_relations.find( app);
    if ( it == m_relations.end() ) {
        tmp = ids;
    }else{
        tmp = it.data();
        int offset = tmp.size()-1;
        tmp.resize( tmp.size() + ids.size() );
        for (uint i = 0; i < ids.size(); i++ ) {
            tmp[offset+i] = ids[i];
        }

    }
    m_relations.replace( app,  tmp );
}
QString OPimRecord::crossToString()const {
    QString str;
    QMap<QString, QArray<int> >::ConstIterator it;
    for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
        QArray<int> id = it.data();
        for ( uint i = 0; i < id.size(); ++i ) {
            str += it.key() + "," + QString::number( i ) + ";";
        }
    }
    str = str.remove( str.length()-1, 1); // strip the ;
    //qWarning("IDS " + str );

    return str;
}
/* if uid = 1 assign a new one */
void OPimRecord::setUid( int uid ) {
    if ( uid == 1)
        uid = uidGen().generate();

    Qtopia::Record::setUid( uid );
};
Qtopia::UidGen &OPimRecord::uidGen() {
    return m_uidGen;
}