maillist.cpp

来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 188 行

CPP
188 行
字号
/******************************************************************************** Copyright (C) 2000-2006 TROLLTECH ASA. All rights reserved.**** This file is part of the Phone Edition of the Qtopia Toolkit.**** Licensees holding a valid license agreement from Trolltech or any of its** authorized distributors may use this file in accordance with** the License Agreement provided with the Licensed Software.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for**   information about Trolltech's Commercial License Agreements.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.********** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "maillist.h"void MailList::clear(){    QListIterator<dList*> it(sortedList);    while ( it.hasNext() )	delete it.next();    sortedList.clear();    currentPos = 0;}int MailList::count(){    return sortedList.count();}int MailList::size(){    int total = 0;    QListIterator<dList*> it(sortedList);    while ( it.hasNext() )	total += it.next()->size;        return total;}int MailList::currentSize(){    dList *mPtr;        if (currentPos == 0)	return -1;	        mPtr = sortedList.at(currentPos - 1);    return mPtr->size;}QUuid MailList::currentId(){    dList *mPtr;        if (currentPos == 0)	return QUuid();	        mPtr = sortedList.at(currentPos - 1);    return mPtr->internalId;}QString MailList::currentMailbox(){    dList *mPtr;        if (currentPos == 0)	return QString();	        mPtr = sortedList.at(currentPos - 1);    return mPtr->fromBox;}QString* MailList::first(){    dList *mPtr;        if (sortedList.count() == 0)	return NULL;	        mPtr = sortedList.at(0);    currentPos = 1;    return &(mPtr->serverId);}QString* MailList::next(){    dList *mPtr;        if ( currentPos >= (uint)sortedList.count())	return NULL;        mPtr = sortedList.at(currentPos);    currentPos++;    return &(mPtr->serverId);}void MailList::sizeInsert(QString serverId, uint size, QUuid id, QString box){    int x = 0;        dList *newEntry = new dList;    newEntry->serverId = serverId;    newEntry->size = size;    newEntry->internalId = id;    newEntry->fromBox = box;    QListIterator<dList*> it(sortedList);    while ( it.hasNext() ) {	if (newEntry->size < it.next()->size) {	    sortedList.insert(x, newEntry);	    return;	}	++x;    }    sortedList.append(newEntry);}void MailList::append(QString serverId, uint size, QUuid id, QString box){    dList *newEntry = new dList;    newEntry->serverId = serverId;    newEntry->size = size;    newEntry->internalId = id;    newEntry->fromBox = box;        sortedList.append(newEntry);}void MailList::moveFront(QString serverId){    dList *currentPtr;    uint tempPos;        tempPos = currentPos;    if ( tempPos >= (uint)sortedList.count() )	return;    currentPtr = sortedList.at(tempPos);    while ( ((tempPos+1) < (uint)sortedList.count()) && ( currentPtr->serverId != serverId) ) {	tempPos++;	currentPtr = sortedList.at(tempPos);    }        if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {	qWarning(QString("moved to front, message: " + serverId).toLatin1());		dList *itemPtr = sortedList.takeAt(tempPos);	sortedList.insert(currentPos, itemPtr);    }}//only works if mail is not already in downloadbool MailList::remove(QString serverId){    dList *currentPtr;    uint tempPos;        tempPos = currentPos;    if ( tempPos >= (uint)sortedList.count() )	return false;    currentPtr = sortedList.at(tempPos);    while ( ((tempPos + 1) < (uint)sortedList.count()) && ( currentPtr->serverId != serverId) ) {	tempPos++;	currentPtr = sortedList.at(tempPos);    }        if ( (currentPtr != NULL) && (currentPtr->serverId == serverId) ) {	qWarning(QString("deleted message: " + serverId).toLatin1());	sortedList.removeAt(tempPos);		return true;    }    return false;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?