summaryrefslogtreecommitdiffabout
path: root/kmicromail/mailistviewitem.cpp
blob: 5ef5b6a2ab363535ea92fa00575c4899bd8b1f7c (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// CHANGED 2004-08-06 Lutz Rogowski
#include "mailistviewitem.h"
#include <libmailwrapper/abstractmail.h>
#include <qtextstream.h>
#include <kiconloader.h>
//#include <qpe/resource.h>

MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item )
        :QListViewItem(parent,item),mail_data()
{
}

void MailListViewItem::showEntry()
{
    if ( mail_data->getFlags().testBit( FLAG_ANSWERED ) == true) {
        setPixmap( 0, SmallIcon ( "kmmsgreplied") );
    } else if ( mail_data->getFlags().testBit( FLAG_SEEN ) == true )  {
        /* I think it looks nicer if there are not such a log of icons but only on mails
           replied or new - Alwin*/ 
        //setPixmap( 0,SmallIcon ("kmmsgunseen") );
    } else  {
        setPixmap( 0,SmallIcon ( "kmmsgnew") );
    }
    double s = mail_data->Msgsize();
    int w = 0;
    s/=1024;
    if (s>999.0) {
        s/=1024.0;
        ++w;
    }
    QString fsort;
    fsort.sprintf( "%.2f", s );
    QString fsize = QString::number( s, 'f', 2 );
    //  1.23
    // 11.23
    // 111.23
    // 999.23 maxlen
    switch(fsize.length() ) {
    case 4:
        fsort = "00" + fsize ;
        break;
    case 5:
        fsort = "0" + fsize ;
        break;
    default:
        fsort = fsize ;
    break;
    
    }
    if ( w == 0 ) {
        setText(3, fsize + "kB" );
        mKeyMap.insert(3, "k" + fsort);
        //setText(3, "kB" + fsort ); // test only
    } else {
        //setText(3, fsize + "MB");
        mKeyMap.insert(3, "M" +fsort );
    }
    setText(1,QString::fromUtf8( mail_data->getSubject().latin1()));
    setText(2,QString::fromUtf8( mail_data->getFrom().latin1()));
#if 0    
    QString date = mail_data->getDate();
    
    int kom = date.find( ",")+2;
    if ( kom == 1 )
    kom = 0;
    if (  date.mid(kom,1) == " ")
        ++kom;
    if ( date.mid(kom+1,1) == " " )
        date =  "0" + date.mid( kom ); 
    else if ( kom )
        date =  date.mid( kom ); 
    if ( kom || date.mid(2,1 ) == " ") {
        QString mon = date.mid(3,3);
        QString so = 00;
        if ( mon == "Jan" )
            so = "01";
        else if ( mon == "Feb" )
            so = "02";
        else if ( mon == "Mar" )
            so = "03";
        else if ( mon == "Apr" )
            so = "04";
        else if ( mon == "May" )
            so = "05";
        else if ( mon == "Jun" )
            so = "06";
        else if ( mon == "Jul" )
            so = "07";
        else if ( mon == "Aug" )
            so = "08";
        else if ( mon == "Sep" )
            so = "09";
        else if ( mon == "Oct" )
            so = "10";
        else if ( mon == "Nov" )
            so = "11";
        else if ( mon == "Dec" )
            so = "12";
        date = date.mid(7,4)+so+date.left(2)+date.mid(12,14);
    }
    //qDebug("insert Date %s ", date.latin1());
    // if ( date.left(1) != "1" || date.left(1) != "2" )
    //  date = date.mid(5);
    mKeyMap.insert(4,date);
#endif
    mKeyMap.insert(4,mail_data->getIsoDate());
    setText(4,mail_data->getDate());
}

void MailListViewItem::storeData(const RecMailP&data)
{
    mail_data = data;
}
void MailListViewItem::setSortKey(int column,const QString &key)
{
    mKeyMap.insert(column,key);
}
QString MailListViewItem::key(int column, bool) const
{
    // to make is fast, we use here special cases
    if ( column == 3  ||  column == 4 ) {
        return *mKeyMap.find(column);
    }
    if ( column == 1 ) {
        if ( text(1).left(4).lower() == "re: " )
            return text(1).mid(4);

    }
    return text(column);
    /*
    QMap<int,QString>::ConstIterator it = mKeyMap.find(column);
    if (it == mKeyMap.end()) return text(column);
    else return *it;
    */
}

const RecMailP& MailListViewItem::data()const
{
    return mail_data;
}

MAILLIB::ATYPE MailListViewItem::wrapperType()
{
    if (!mail_data->Wrapper()) return MAILLIB::A_UNDEFINED;
    return mail_data->Wrapper()->getType();
}