File indexing completed on 2024-12-22 04:52:49

0001 /*
0002    SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "evolutionv3importdata.h"
0008 #include "evolutionaddressbook.h"
0009 #include "evolutioncalendar.h"
0010 #include "evolutionsettings.h"
0011 #include <MailImporter/FilterEvolution_v3>
0012 #include <MailImporter/FilterInfo>
0013 
0014 #include <KPluginFactory>
0015 #include <MailCommon/FilterImporterExporter>
0016 
0017 #include <KLocalizedString>
0018 
0019 #include <QDir>
0020 
0021 K_PLUGIN_CLASS_WITH_JSON(Evolutionv3ImportData, "evolutionv3importer.json")
0022 
0023 Evolutionv3ImportData::Evolutionv3ImportData(QObject *parent, const QList<QVariant> &)
0024     : LibImportWizard::AbstractImporter(parent)
0025 {
0026     mPath = MailImporter::FilterEvolution_v3::defaultSettingsPath();
0027 }
0028 
0029 Evolutionv3ImportData::~Evolutionv3ImportData() = default;
0030 
0031 bool Evolutionv3ImportData::foundMailer() const
0032 {
0033     QDir directory(mPath);
0034     if (directory.exists()) {
0035         return true;
0036     }
0037     return false;
0038 }
0039 
0040 QString Evolutionv3ImportData::name() const
0041 {
0042     return QStringLiteral("Evolution 3.x");
0043 }
0044 
0045 bool Evolutionv3ImportData::importSettings()
0046 {
0047     const QString accountFile = QDir::homePath() + QLatin1StringView("/.gconf/apps/evolution/mail/%gconf.xml");
0048     if (QFileInfo::exists(accountFile)) {
0049         EvolutionSettings account;
0050         account.setAbstractDisplayInfo(mAbstractDisplayInfo);
0051         account.loadAccount(accountFile);
0052         const QString ldapFile = QDir::homePath() + QLatin1StringView("/.gconf/apps/evolution/addressbook/%gconf.xml");
0053         if (QFileInfo::exists(ldapFile)) {
0054             account.loadLdap(ldapFile);
0055         }
0056     } else {
0057         addImportSettingsInfo(i18n("Evolution settings not found."));
0058     }
0059     return true;
0060 }
0061 
0062 bool Evolutionv3ImportData::importMails()
0063 {
0064     MailImporter::FilterEvolution_v3 evolution;
0065     initializeFilter(evolution);
0066     evolution.filterInfo()->setStatusMessage(i18n("Import in progress"));
0067     const QString mailsPath = mPath;
0068     QDir directory(mailsPath);
0069     if (directory.exists()) {
0070         evolution.importMails(mailsPath);
0071     } else {
0072         evolution.import();
0073     }
0074     evolution.filterInfo()->setStatusMessage(i18n("Import finished"));
0075     return true;
0076 }
0077 
0078 bool Evolutionv3ImportData::importFilters()
0079 {
0080     const QString filterPath = QDir::homePath() + QLatin1StringView("/.config/evolution/mail/filter.xml");
0081     return addFilters(filterPath, MailCommon::FilterImporterExporter::EvolutionFilter);
0082 }
0083 
0084 bool Evolutionv3ImportData::importAddressBook()
0085 {
0086     EvolutionAddressBook addressbook;
0087     addressbook.setAbstractDisplayInfo(mAbstractDisplayInfo);
0088     addressbook.exportEvolutionAddressBook();
0089     return true;
0090 }
0091 
0092 bool Evolutionv3ImportData::importCalendar()
0093 {
0094     const QString calendarFile = QDir::homePath() + QLatin1StringView("/.gconf/apps/evolution/calendar/%gconf.xml");
0095     if (QFileInfo::exists(calendarFile)) {
0096         EvolutionCalendar calendar;
0097         calendar.setAbstractDisplayInfo(mAbstractDisplayInfo);
0098         calendar.loadCalendar(calendarFile);
0099     } else {
0100         addImportCalendarInfo(i18n("Evolution calendar not found."));
0101     }
0102     return true;
0103 }
0104 
0105 LibImportWizard::AbstractImporter::TypeSupportedOptions Evolutionv3ImportData::supportedOption()
0106 {
0107     TypeSupportedOptions options;
0108     options |= LibImportWizard::AbstractImporter::Mails;
0109     options |= LibImportWizard::AbstractImporter::Filters;
0110     options |= LibImportWizard::AbstractImporter::Settings;
0111     options |= LibImportWizard::AbstractImporter::Calendars;
0112     options |= LibImportWizard::AbstractImporter::AddressBooks;
0113     return options;
0114 }
0115 
0116 #include "evolutionv3importdata.moc"