<commit_before>#include <buteosyncfw/PluginCbInterface.h>
#include <buteosyncfw/LogMacros.h>

#include <QCoreApplication>
#include <QTranslator>

#include "trace.h"
#include "buteosocialsync.h"

#include "syncservice.h"
#include "socialnetworksyncadaptor.h"

extern "C" ButeoSocial* createPlugin(const QString& pluginName, const Buteo::SyncProfile& profile, Buteo::PluginCbInterface *callbackInterface)
{
    return new ButeoSocial(pluginName, profile, callbackInterface);
}

extern "C" void destroyPlugin(ButeoSocial* plugin)
{
    delete plugin;
}

ButeoSocial::ButeoSocial(const QString& pluginName, const Buteo::SyncProfile& profile, Buteo::PluginCbInterface *callbackInterface)
    : ClientPlugin(pluginName, profile, callbackInterface)
{
    QString translationPath("/usr/share/translations/");
    // QTranslator life-cycles owner by ButeoSocial and removed by its own destructor
    QTranslator *engineeringEnglish = new QTranslator(this);
    engineeringEnglish->load("sociald_eng_en", translationPath);
    QCoreApplication::instance()->installTranslator(engineeringEnglish);

    QTranslator *translator = new QTranslator(this);
    translator->load(QLocale(), "sociald", "-", translationPath);
    QCoreApplication::instance()->installTranslator(translator);
}

ButeoSocial::~ButeoSocial()
{
}

bool ButeoSocial::init()
{
    // Profile names look like twitter.Posts, facebook.Posts, etc.
    QString profile = getProfileName();
    QStringList servicePlusDataType = profile.split(".");
    if (servicePlusDataType.length() == 2) {
        m_serviceName = servicePlusDataType.at(0);
        m_dataType = servicePlusDataType.at(1);
        // Database connections are created per profile
        SyncService *syncService = new SyncService(profile, this);
        m_socialNetworkSyncAdaptor = syncService->createAdaptor(m_serviceName, m_dataType, this);
        if (m_socialNetworkSyncAdaptor) {
            if (!m_socialNetworkSyncAdaptor->enabled()) {
                TRACE(SOCIALD_DEBUG,
                      QString(QLatin1String("%1 is not currently enabled")).arg(m_serviceName));
                return false;
            }

            connect(m_socialNetworkSyncAdaptor, SIGNAL(statusChanged()), this, SLOT(syncStatusChanged()));
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

bool ButeoSocial::uninit()
{
    disconnect(m_socialNetworkSyncAdaptor, SIGNAL(statusChanged()), this, SLOT(syncStatusChanged()));
    return true;
}

bool ButeoSocial::startSync()
{
    if (m_socialNetworkSyncAdaptor && m_socialNetworkSyncAdaptor->enabled()) {
        if (m_socialNetworkSyncAdaptor->status() == SocialNetworkSyncAdaptor::Inactive) {
            TRACE(SOCIALD_DEBUG,
                  QString(QLatin1String("performing sync of %1 from %2"))
                  .arg(m_dataType).arg(m_serviceName));
            m_socialNetworkSyncAdaptor->sync(m_dataType);
        } else {
            TRACE(SOCIALD_DEBUG,
                    QString(QLatin1String("%1 sync adaptor for %2 is still busy with last sync"))
                  .arg(m_serviceName)
                  .arg(m_dataType));
        }
    } else {
        TRACE(SOCIALD_DEBUG,
                QString(QLatin1String("no enabled %1 sync adaptor for %2"))
              .arg(m_serviceName)
              .arg(m_dataType));
    }
    return true;
}

void ButeoSocial::abortSync(Sync::SyncStatus)
{
    // TODO ? Should we do something over here?
}

bool ButeoSocial::cleanUp()
{
    // TODO anything needed?, see synchronizer.cpp:875
    // PluginRunner gets destroyed rigth after cleanup()
    return true;
}
<commit_msg>Return true only for started sync task.<commit_after>#include <buteosyncfw/PluginCbInterface.h>
#include <buteosyncfw/LogMacros.h>

#include <QCoreApplication>
#include <QTranslator>

#include "trace.h"
#include "buteosocialsync.h"

#include "syncservice.h"
#include "socialnetworksyncadaptor.h"

extern "C" ButeoSocial* createPlugin(const QString& pluginName, const Buteo::SyncProfile& profile, Buteo::PluginCbInterface *callbackInterface)
{
    return new ButeoSocial(pluginName, profile, callbackInterface);
}

extern "C" void destroyPlugin(ButeoSocial* plugin)
{
    delete plugin;
}

ButeoSocial::ButeoSocial(const QString& pluginName, const Buteo::SyncProfile& profile, Buteo::PluginCbInterface *callbackInterface)
    : ClientPlugin(pluginName, profile, callbackInterface)
{
    QString translationPath("/usr/share/translations/");
    // QTranslator life-cycles owner by ButeoSocial and removed by its own destructor
    QTranslator *engineeringEnglish = new QTranslator(this);
    engineeringEnglish->load("sociald_eng_en", translationPath);
    QCoreApplication::instance()->installTranslator(engineeringEnglish);

    QTranslator *translator = new QTranslator(this);
    translator->load(QLocale(), "sociald", "-", translationPath);
    QCoreApplication::instance()->installTranslator(translator);
}

ButeoSocial::~ButeoSocial()
{
}

bool ButeoSocial::init()
{
    // Profile names look like twitter.Posts, facebook.Posts, etc.
    QString profile = getProfileName();
    QStringList servicePlusDataType = profile.split(".");
    if (servicePlusDataType.length() == 2) {
        m_serviceName = servicePlusDataType.at(0);
        m_dataType = servicePlusDataType.at(1);
        // Database connections are created per profile
        SyncService *syncService = new SyncService(profile, this);
        m_socialNetworkSyncAdaptor = syncService->createAdaptor(m_serviceName, m_dataType, this);
        if (m_socialNetworkSyncAdaptor) {
            if (!m_socialNetworkSyncAdaptor->enabled()) {
                TRACE(SOCIALD_DEBUG,
                      QString(QLatin1String("%1 is not currently enabled")).arg(m_serviceName));
                return false;
            }

            connect(m_socialNetworkSyncAdaptor, SIGNAL(statusChanged()), this, SLOT(syncStatusChanged()));
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

bool ButeoSocial::uninit()
{
    disconnect(m_socialNetworkSyncAdaptor, SIGNAL(statusChanged()), this, SLOT(syncStatusChanged()));
    return true;
}

bool ButeoSocial::startSync()
{
    if (m_socialNetworkSyncAdaptor && m_socialNetworkSyncAdaptor->enabled()) {
        if (m_socialNetworkSyncAdaptor->status() == SocialNetworkSyncAdaptor::Inactive) {
            TRACE(SOCIALD_DEBUG,
                  QString(QLatin1String("performing sync of %1 from %2"))
                  .arg(m_dataType).arg(m_serviceName));
            m_socialNetworkSyncAdaptor->sync(m_dataType);
            return true;
        } else {
            TRACE(SOCIALD_DEBUG,
                    QString(QLatin1String("%1 sync adaptor for %2 is still busy with last sync"))
                  .arg(m_serviceName)
                  .arg(m_dataType));
        }
    } else {
        TRACE(SOCIALD_DEBUG,
                QString(QLatin1String("no enabled %1 sync adaptor for %2"))
              .arg(m_serviceName)
              .arg(m_dataType));
    }
    return false;
}

void ButeoSocial::abortSync(Sync::SyncStatus)
{
    // TODO ? Should we do something over here?
}

bool ButeoSocial::cleanUp()
{
    // TODO anything needed?, see synchronizer.cpp:875
    // PluginRunner gets destroyed rigth after cleanup()
    return true;
}

{'fraction_non_alphanumeric': 0.11011662598318415, 'fraction_numerical': 0.004610794684024953, 'mean_word_length': 3.353600944510035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6239152', 'n_tokens_mistral': 2246, 'n_tokens_neox': 2183, 'n_words': 442}