File indexing completed on 2024-12-15 04:47:01

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 "operaimportdata.h"
0008 #include "operaaddressbook.h"
0009 #include "operasettings.h"
0010 #include <MailImporter/FilterInfo>
0011 #include <MailImporter/FilterOpera>
0012 
0013 #include <KLocalizedString>
0014 #include <KPluginFactory>
0015 #include <QDir>
0016 
0017 K_PLUGIN_CLASS_WITH_JSON(OperaImportData, "operaimporter.json")
0018 
0019 OperaImportData::OperaImportData(QObject *parent, const QList<QVariant> &)
0020     : LibImportWizard::AbstractImporter(parent)
0021 {
0022     mPath = MailImporter::FilterOpera::defaultSettingsPath();
0023 }
0024 
0025 OperaImportData::~OperaImportData() = default;
0026 
0027 bool OperaImportData::foundMailer() const
0028 {
0029     QDir directory(mPath);
0030     if (directory.exists()) {
0031         return true;
0032     }
0033     return false;
0034 }
0035 
0036 QString OperaImportData::name() const
0037 {
0038     return QStringLiteral("Opera");
0039 }
0040 
0041 bool OperaImportData::importMails()
0042 {
0043     MailImporter::FilterOpera opera;
0044     initializeFilter(opera);
0045     opera.filterInfo()->setStatusMessage(i18n("Import in progress"));
0046     const QString mailPath(mPath + QStringLiteral("mail/store/"));
0047     QDir directory(mailPath);
0048     if (directory.exists()) {
0049         opera.importMails(mailPath);
0050     } else {
0051         opera.import();
0052     }
0053     opera.filterInfo()->setStatusMessage(i18n("Import finished"));
0054     return true;
0055 }
0056 
0057 bool OperaImportData::importAddressBook()
0058 {
0059     const QString addressbookFile(mPath + QStringLiteral("bookmarks.adr"));
0060     OperaAddressBook addressbook(addressbookFile);
0061     addressbook.setAbstractDisplayInfo(mAbstractDisplayInfo);
0062     addressbook.importAddressBook();
0063     return true;
0064 }
0065 
0066 bool OperaImportData::importSettings()
0067 {
0068     const QString settingFile(mPath + QStringLiteral("mail/accounts.ini"));
0069     OperaSettings settings(settingFile);
0070     settings.setAbstractDisplayInfo(mAbstractDisplayInfo);
0071     settings.importSettings();
0072     return true;
0073 }
0074 
0075 LibImportWizard::AbstractImporter::TypeSupportedOptions OperaImportData::supportedOption()
0076 {
0077     TypeSupportedOptions options;
0078     options |= LibImportWizard::AbstractImporter::Mails;
0079     options |= LibImportWizard::AbstractImporter::AddressBooks;
0080     options |= LibImportWizard::AbstractImporter::Settings;
0081     return options;
0082 }
0083 
0084 #include "operaimportdata.moc"