summaryrefslogtreecommitdiffabout
path: root/microkde/kidmanager.cpp
Unidiff
Diffstat (limited to 'microkde/kidmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kidmanager.cpp130
1 files changed, 128 insertions, 2 deletions
diff --git a/microkde/kidmanager.cpp b/microkde/kidmanager.cpp
index ce6184a..d24a41f 100644
--- a/microkde/kidmanager.cpp
+++ b/microkde/kidmanager.cpp
@@ -4,7 +4,133 @@ KIdManager::KIdManager()
4{ 4{
5 5
6} 6}
7QString KIdManager::addId (const QString& idString,const QString& id,const QString& idvalue ) 7// :profilename;12;id_withLen12;123456:
8// 123456 is the csum
9QString KIdManager::setId (const QString& idString,const QString& prof,const QString& idvalue )
8{ 10{
9 11 int startProf;
12 int startIDnum;
13 int startIDnumlen;
14 int startID;
15 int lenID;
16 int startCsum;
17 int lenCsum;
18 int endall;
19 QString newIDString;
20 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) {
21 newIDString = idString.left(startIDnum ) + QString::number( idvalue.length() ) +";"+idvalue+ ";"+idString.mid( startCsum );
22 } else {
23 newIDString = idString + prof+";"+ QString::number( idvalue.length() ) +";"+idvalue +";0:";
24 }
25 qDebug("setID:profile:%s*retval:%s*idvalue:%s* ", prof.latin1(), newIDString.latin1() ,idvalue.latin1() );
26 return newIDString;
27}
28QString KIdManager::getId (const QString& idString,const QString& prof )
29{
30 int startProf;
31 int startIDnum;
32 int startIDnumlen;
33 int startID;
34 int lenID;
35 int startCsum;
36 int lenCsum;
37 int endall;
38 QString idval = "";
39 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) )
40 idval = idString.mid( startID, lenID );
41
42 qDebug("getID:profile:%s*retval:%s*idstring:%s* ", prof.latin1(), idval.latin1() ,idString.latin1() );
43 return idval;
44
45}
46
47QString KIdManager::removeId (const QString& idString,const QString& prof )
48{
49 int startProf;
50 int startIDnum;
51 int startIDnumlen;
52 int startID;
53 int lenID;
54 int startCsum;
55 int lenCsum;
56 int endall;
57 QString newIDString;
58 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) {
59 newIDString = idString.left(startProf) + idString.mid( endall );
60 } else {
61 newIDString = idString;
62 }
63 qDebug("removeID:profile:%s*retval:%s*oldidstring:%s* ", prof.latin1(), newIDString.latin1() ,idString.latin1() );
64 return newIDString;
65}
66
67QString KIdManager::setCsum (const QString& idString,const QString& prof,const QString& idCsum )
68{
69 int startProf;
70 int startIDnum;
71 int startIDnumlen;
72 int startID;
73 int lenID;
74 int startCsum;
75 int lenCsum;
76 int endall;
77 QString newIDString;
78 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) ) {
79 newIDString = idString.left(startCsum) + idCsum+ idString.mid( endall +1);
80 } else {
81 newIDString = idString + prof + ";3;_u_;"+ idCsum + ":";
82 }
83 qDebug("setCsum:profile:%s*retval:%s*idCsum:%s* ", prof.latin1(), newIDString.latin1() ,idCsum.latin1() );
84 return newIDString;
85}
86QString KIdManager::getCsum (const QString& idString,const QString& prof )
87{
88 int startProf;
89 int startIDnum;
90 int startIDnumlen;
91 int startID;
92 int lenID;
93 int startCsum;
94 int lenCsum;
95 int endall;
96 QString idval = "";
97 if ( KIdManager::getNumbers (idString, prof, startProf, startIDnum, startIDnumlen,startID, lenID, startCsum, lenCsum, endall) )
98 idval = idString.mid( startCsum, lenCsum );
99
100 qDebug("getCsum:profile:%s*retval:%s*idstring:%s* ", prof.latin1(), idval.latin1() ,idString.latin1() );
101 return idval;
102}
103// :profilename;12;id_withLen12;123456:
104bool KIdManager::getNumbers (const QString& idString,const QString& prof, int &startProf, int &startIDnum, int &startIDnumlen,int &startID, int& lenID, int &startCsum, int &lenCsum, int & endall)
105{
106 startProf = idString.find( ":"+prof+";" );
107 if ( startProf >= 0 ) {
108 startIDnum = prof.length()+2+startProf;
109 startID = idString.find( ";", startIDnum ) +1;
110 startIDnumlen = startID - startIDnum - 1;
111 if ( startIDnum > 0 ) {
112 bool ok;
113 lenID = idString.mid ( startIDnum,startIDnumlen).toInt( &ok );
114 if (ok) {
115 startCsum = startID+lenID+1;
116 endall = idString.find( ":", startCsum )-1;
117 if ( endall < 0 ) {
118 qDebug("Error getNumbers: andall not found ");
119 return false;
120 }
121 lenCsum = endall-startCsum+1;
122 }
123 else {
124 qDebug("Error getNumbers:length is no number:*%s* ", idString.mid ( startIDnum,startIDnumlen).toInt( &ok ));
125 return false;
126 }
127 } else {
128 qDebug("Error in KIdManager::getNumbers.startIDnum <= 0");
129 return false;
130 }
131 } else {
132 qDebug("getnumbers: profile not found *%s* ",prof.latin1() );
133 return false;
134 }
135 return true;
10} 136}