summaryrefslogtreecommitdiff
path: root/noncore/net/mailit/maillist.cpp
Unidiff
Diffstat (limited to 'noncore/net/mailit/maillist.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mailit/maillist.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/noncore/net/mailit/maillist.cpp b/noncore/net/mailit/maillist.cpp
new file mode 100644
index 0000000..b5325a9
--- a/dev/null
+++ b/noncore/net/mailit/maillist.cpp
@@ -0,0 +1,131 @@
1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved.
3**
4** This file is part of Qt Palmtop 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 Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "maillist.h"
21
22void MailList::clear()
23{
24 sortedList.setAutoDelete(TRUE);
25 sortedList.clear();
26 currentPos = 0;
27}
28
29int MailList::count()
30{
31 return sortedList.count();
32}
33
34int* MailList::first()
35{
36 dList *mPtr;
37
38 if (sortedList.count() == 0)
39 return NULL;
40
41 mPtr = sortedList.at(0);
42 currentPos = 1;
43 return &(mPtr->serverId);
44}
45
46int* MailList::next()
47{
48 dList *mPtr;
49
50 if ( (currentPos) >= sortedList.count())
51 return NULL;
52
53 mPtr = sortedList.at(currentPos);
54 currentPos++;
55 return &(mPtr->serverId);
56}
57
58void MailList::sizeInsert(int serverId, uint size)
59{
60 dList *tempPtr;
61 int x;
62
63 dList *newEntry = new dList;
64 newEntry->serverId = serverId;
65 newEntry->size = size;
66
67 for (tempPtr = sortedList.first(); tempPtr != NULL; tempPtr = sortedList.next() ) {
68 if (newEntry->size < tempPtr->size) {
69 x = sortedList.at();
70 sortedList.insert(x, newEntry);
71 return;
72 }
73 }
74 sortedList.append(newEntry);
75}
76
77void MailList::moveFront(int serverId, uint size)
78{
79 dList *currentPtr;
80 uint tempPos;
81 QString temp;
82
83 tempPos = currentPos;
84 if ( tempPos >= sortedList.count() )
85 return;
86 currentPtr = sortedList.at(tempPos);
87 while ( ((tempPos+1) < sortedList.count()) && ( currentPtr->serverId != serverId) ) {
88 tempPos++;
89 currentPtr = sortedList.at(tempPos);
90 }
91
92 if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {
93 temp.setNum(currentPtr->serverId);
94 qWarning("moved to front, message: " + temp);
95
96 dList *itemPtr = sortedList.take(tempPos);
97 sortedList.insert(currentPos, itemPtr);
98 }
99
100}
101
102//only works if mail is not already in download
103bool MailList::remove(int serverId, uint size)
104{
105 dList *currentPtr;
106 uint tempPos;
107 QString temp;
108
109 tempPos = currentPos;
110 if ( tempPos >=sortedList.count() )
111 return FALSE;
112 currentPtr = sortedList.at(tempPos);
113 while ( ((tempPos + 1) < sortedList.count()) && ( currentPtr->serverId != serverId) ) {
114 tempPos++;
115 currentPtr = sortedList.at(tempPos);
116 }
117
118 if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {
119 temp.setNum(currentPtr->serverId);
120 qWarning("deleted message: " + temp);
121 sortedList.remove(tempPos);
122
123 return TRUE;
124 }
125 return FALSE;
126}
127
128void MailList::insert(int pos, int serverId, uint size)
129{
130 //sortedList.insert(pos, mPtr);
131}