confirmaddressinterface.cpp 2.84 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
   Copyright (C) 2016 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 as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   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; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "confirmaddressinterface.h"
Laurent Montel's avatar
Laurent Montel committed
21
#include "confirmaddressconfigurewidget.h"
Laurent Montel's avatar
Laurent Montel committed
22
23
24
#include "confirmaddressdialog.h"

#include <QPointer>
Laurent Montel's avatar
Laurent Montel committed
25
26
#include <KConfigGroup>
#include <KSharedConfig>
Laurent Montel's avatar
Laurent Montel committed
27

Laurent Montel's avatar
Laurent Montel committed
28
29
30
#include <KIdentityManagement/IdentityManager>
#include <KIdentityManagement/Identity>

Laurent Montel's avatar
Laurent Montel committed
31
ConfirmAddressInterface::ConfirmAddressInterface(QObject *parent)
Laurent Montel's avatar
Laurent Montel committed
32
33
    : MessageComposer::PluginEditorCheckBeforeSendInterface(parent),
      mEnabled(false)
Laurent Montel's avatar
Laurent Montel committed
34
{
Laurent Montel's avatar
Laurent Montel committed
35
    reloadConfig();
Laurent Montel's avatar
Laurent Montel committed
36
37
38
39
40
41
42
}

ConfirmAddressInterface::~ConfirmAddressInterface()
{

}

Laurent Montel's avatar
Laurent Montel committed
43
bool ConfirmAddressInterface::exec(const MessageComposer::PluginEditorCheckBeforeSendParams &params)
Laurent Montel's avatar
Laurent Montel committed
44
45
{
    if (mEnabled) {
Laurent Montel's avatar
Laurent Montel committed
46
        if (params.addresses().isEmpty()) {
Laurent Montel's avatar
Laurent Montel committed
47
48
            return true;
        }
Laurent Montel's avatar
Laurent Montel committed
49
        // not configurated => validate it.
Laurent Montel's avatar
Laurent Montel committed
50
51
        const ConfirmAddressSettings settings = mHashSettings.value(params.identity());
        if (settings.mDomains.isEmpty() && settings.mWhiteLists.isEmpty()) {
52
53
            return true;
        }
Laurent Montel's avatar
Laurent Montel committed
54

55
#ifdef USE_PLUGIN
Laurent Montel's avatar
Laurent Montel committed
56
57
58
59
60
61
62
        QPointer<ConfirmAddressDialog> dlg = new ConfirmAddressDialog(parentWidget());
        //TODO use params
        if (dlg->exec()) {
            return true;
        } else {
            return false;
        }
63
64
65
#else
        return true;
#endif
Laurent Montel's avatar
Laurent Montel committed
66
67
68
69
70
    } else {
        return true;
    }
}

Laurent Montel's avatar
Laurent Montel committed
71
void ConfirmAddressInterface::reloadConfig()
Laurent Montel's avatar
Laurent Montel committed
72
{
Laurent Montel's avatar
Laurent Montel committed
73
74
    KConfigGroup grp(KSharedConfig::openConfig(), "Confirm Address");
    mEnabled = grp.readEntry("Enabled", false);
Laurent Montel's avatar
Laurent Montel committed
75
76
77
78
79
80
81
82
83
84
85
86
    mHashSettings.clear();

    KIdentityManagement::IdentityManager manager(true);
    KIdentityManagement::IdentityManager::ConstIterator end = manager.end();
    for (KIdentityManagement::IdentityManager::ConstIterator it = manager.begin(); it != end; ++it) {
        const uint identity = (*it).uoid();
        KConfigGroup identityGroup = grp.group(QStringLiteral("Confirm Address %1").arg(identity));
        ConfirmAddressSettings settings;
        settings.mDomains = identityGroup.readEntry("Domains", QStringList());
        settings.mWhiteLists = identityGroup.readEntry("Emails", QStringList());
        mHashSettings.insert(identity, settings);
    }
Laurent Montel's avatar
Laurent Montel committed
87
}