File: filteractionstatus.cpp

package info (click to toggle)
kdepim 4%3A4.14.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 62,764 kB
  • sloc: cpp: 530,022; xml: 5,446; perl: 1,434; sh: 812; ansic: 433; php: 44; makefile: 22
file content (111 lines) | stat: -rw-r--r-- 3,722 bytes parent folder | download | duplicates (2)
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
/* -*- mode: C++; c-file-style: "gnu" -*-

  Copyright (c) 2012 Montel Laurent <montel@kde.org>

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License, version 2, as
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "filteractionstatus.h"
#include <KDE/Akonadi/KMime/MessageStatus>
#include <KDE/KLocale>
using namespace MailCommon;

Akonadi::MessageStatus MailCommon::FilterActionStatus::stati[] =
{
    Akonadi::MessageStatus::statusImportant(),
    Akonadi::MessageStatus::statusRead(),
    Akonadi::MessageStatus::statusUnread(),
    Akonadi::MessageStatus::statusReplied(),
    Akonadi::MessageStatus::statusForwarded(),
    Akonadi::MessageStatus::statusWatched(),
    Akonadi::MessageStatus::statusIgnored(),
    Akonadi::MessageStatus::statusSpam(),
    Akonadi::MessageStatus::statusHam(),
    Akonadi::MessageStatus::statusToAct()
};

int MailCommon::FilterActionStatus::StatiCount = sizeof( MailCommon::FilterActionStatus::stati ) / sizeof( Akonadi::MessageStatus );

FilterActionStatus::FilterActionStatus(const QString &name, const QString &label, QObject *parent )
    : FilterActionWithStringList( name, label, parent )
{
    // if you change this list, also update
    // FilterActionSetStatus::stati above
    mParameterList.append(QString() );
    mParameterList.append( i18nc( "msg status", "Important" ) );
    mParameterList.append( i18nc( "msg status", "Read" ) );
    mParameterList.append( i18nc( "msg status", "Unread" ) );
    mParameterList.append( i18nc( "msg status", "Replied" ) );
    mParameterList.append( i18nc( "msg status", "Forwarded" ) );
    mParameterList.append( i18nc( "msg status", "Watched" ) );
    mParameterList.append( i18nc( "msg status", "Ignored" ) );
    mParameterList.append( i18nc( "msg status", "Spam" ) );
    mParameterList.append( i18nc( "msg status", "Ham" ) );
    mParameterList.append( i18nc( "msg status", "Action Item" ) );

    mParameter = mParameterList.at( 0 );
}

SearchRule::RequiredPart FilterActionStatus::requiredPart() const
{
    return SearchRule::Envelope;
}

bool FilterActionStatus::isEmpty() const
{
    return false;
}

QString FilterActionStatus::realStatusString( const QString &statusStr )
{
    QString result( statusStr );

    if ( result.size() == 2 )
        result.remove( QLatin1Char( 'U' ) );

    return result;
}


void FilterActionStatus::argsFromString( const QString &argsStr )
{
    if ( argsStr.length() == 1 ) {
        Akonadi::MessageStatus status;

        for ( int i = 0 ; i < FilterActionStatus::StatiCount; ++i ) {
            status = stati[i];
            if ( realStatusString( status.statusStr() ) == QLatin1String(argsStr.toLatin1()) ) {
                mParameter = mParameterList.at( i + 1 );
                return;
            }
        }
    }

    mParameter = mParameterList.at( 0 );
}

QString FilterActionStatus::argsAsString() const
{
    const int index = mParameterList.indexOf( mParameter );
    if ( index < 1 )
        return QString();

    return realStatusString( FilterActionStatus::stati[index - 1].statusStr() );
}

QString FilterActionStatus::displayString() const
{
    return label() + QLatin1String( " \"" ) + mParameter + QLatin1String( "\"" );
}