sylpheedimportdata.cpp 3.29 KB
Newer Older
1
/*
2
   Copyright (C) 2012-2017 Montel Laurent <montel@kde.org>
3

Laurent Montel's avatar
Laurent Montel committed
4 5 6 7
   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.
8

Laurent Montel's avatar
Laurent Montel committed
9 10 11 12
   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.
13

Laurent Montel's avatar
Laurent Montel committed
14 15 16 17
   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.
18 19
*/

20
#include "sylpheed/sylpheedimportdata.h"
21
#include "mailimporter/filtersylpheed.h"
22 23
#include "mailimporter/filterinfo.h"
#include "importfilterinfogui.h"
Laurent Montel's avatar
Laurent Montel committed
24
#include "MailCommon/FilterImporterExporter"
Laurent Montel's avatar
Laurent Montel committed
25
#include "importwizard.h"
26
#include "sylpheed/sylpheedsettings.h"
27
#include "sylpheed/sylpheedaddressbook.h"
28

Laurent Montel's avatar
Laurent Montel committed
29
#include <KLocalizedString>
30
#include <kpluginfactory.h>
31 32
#include <QDir>

33 34
K_PLUGIN_FACTORY_WITH_JSON(SylpheedImporterFactory, "sylpheedimporter.json", registerPlugin<SylpheedImportData>();)

35
SylpheedImportData::SylpheedImportData(QObject *parent, const QList<QVariant> &)
Laurent Montel's avatar
Laurent Montel committed
36
    : AbstractImporter(parent)
37
{
Laurent Montel's avatar
Laurent Montel committed
38
    mPath = MailImporter::FilterSylpheed::defaultSettingsPath();
39 40 41 42 43 44 45 46
}

SylpheedImportData::~SylpheedImportData()
{
}

bool SylpheedImportData::foundMailer() const
{
Laurent Montel's avatar
Laurent Montel committed
47 48
    QDir directory(mPath);
    if (directory.exists()) {
Laurent Montel's avatar
Laurent Montel committed
49
        return true;
Laurent Montel's avatar
Laurent Montel committed
50
    }
Laurent Montel's avatar
Laurent Montel committed
51
    return false;
52 53 54 55
}

QString SylpheedImportData::name() const
{
Laurent Montel's avatar
Laurent Montel committed
56
    return QStringLiteral("Sylpheed");
57 58 59 60
}

bool SylpheedImportData::importSettings()
{
Laurent Montel's avatar
Laurent Montel committed
61
    const QString accountFile = mPath + QLatin1String("/accountrc");
62
    if (QFileInfo::exists(accountFile)) {
Laurent Montel's avatar
Laurent Montel committed
63
        SylpheedSettings account(mImportWizard);
Laurent Montel's avatar
Laurent Montel committed
64 65 66 67 68
        account.importSettings(accountFile, mPath);
    } else {
        addImportSettingsInfo(i18n("Sylpheed settings not found."));
    }
    return true;
69 70 71 72
}

bool SylpheedImportData::importMails()
{
Laurent Montel's avatar
Laurent Montel committed
73
    MailImporter::FilterSylpheed sylpheed;
Laurent Montel's avatar
Laurent Montel committed
74 75
    initializeFilter(sylpheed);
    sylpheed.filterInfo()->setStatusMessage(i18n("Import in progress"));
Laurent Montel's avatar
Laurent Montel committed
76 77
    const QString mailsPath = sylpheed.localMailDirPath();
    QDir directory(mailsPath);
Laurent Montel's avatar
Laurent Montel committed
78
    if (directory.exists()) {
Laurent Montel's avatar
Laurent Montel committed
79
        sylpheed.importMails(mailsPath);
Laurent Montel's avatar
Laurent Montel committed
80
    } else {
Laurent Montel's avatar
Laurent Montel committed
81
        sylpheed.import();
Laurent Montel's avatar
Laurent Montel committed
82
    }
Laurent Montel's avatar
Laurent Montel committed
83
    sylpheed.filterInfo()->setStatusMessage(i18n("Import finished"));
Laurent Montel's avatar
Laurent Montel committed
84
    return true;
85 86 87 88
}

bool SylpheedImportData::importFilters()
{
Laurent Montel's avatar
Laurent Montel committed
89
    const QString filterPath = mPath + QLatin1String("/filter.xml");
Laurent Montel's avatar
Laurent Montel committed
90
    return addFilters(filterPath, MailCommon::FilterImporterExporter::SylpheedFilter);
91 92 93 94
}

bool SylpheedImportData::importAddressBook()
{
Laurent Montel's avatar
Laurent Montel committed
95
    const QDir addressbookDir(mPath);
Laurent Montel's avatar
Laurent Montel committed
96
    SylpheedAddressBook account(addressbookDir, mImportWizard);
97
    account.importAddressBook();
Laurent Montel's avatar
Laurent Montel committed
98
    return true;
99 100
}

Laurent Montel's avatar
Laurent Montel committed
101
AbstractImporter::TypeSupportedOptions SylpheedImportData::supportedOption()
102
{
Laurent Montel's avatar
Laurent Montel committed
103
    TypeSupportedOptions options;
Laurent Montel's avatar
Laurent Montel committed
104 105 106 107
    options |= AbstractImporter::Mails;
    options |= AbstractImporter::Filters;
    options |= AbstractImporter::Settings;
    options |= AbstractImporter::AddressBooks;
Laurent Montel's avatar
Laurent Montel committed
108
    return options;
109
}
110 111

#include "sylpheedimportdata.moc"