<commit_before>
#include <qdir.h>
#include <qobject.h>
#include <qwidget.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qdatetime.h>

#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kparts/genericfactory.h>
#include <kparts/componentfactory.h>

#include <libkcal/icalformat.h>
#include <libkcal/calendarlocal.h>

#include "organizerbase.h"
#include "ksync_mainwindow.h"
#include "ksync_organizerpart.h"
#include <kalendarsyncentry.h>
#include <qptrlist.h>

#include "ksync_return.h"
#include "ksync_sync.h"

typedef KParts::GenericFactory< KitchenSync::OrganizerPart> OrganizerPartFactory;
K_EXPORT_COMPONENT_FACTORY( liborganizerpart, OrganizerPartFactory );

using namespace KitchenSync ;

namespace {
    void record( KCal::CalendarLocal* local ) {
        if ( local ==0 )
            return;
        const QPtrList<KCal::Todo> todos = local->getTodoList();
        QPtrListIterator<KCal::Todo> it( todos );
        QPtrList<KCal::Event> events = local->getAllEvents();
        KCal::Event* event;
        KCal::Todo* todo;
        for ( ; it.current(); ++it ) {
            todo = it.current();
            kdDebug() << "Todo: " << todo->description() << endl;
        }
        for ( event = events.first(); event != 0; event = events.next() ) {
            kdDebug() << "Event:" << event->summary() << endl;
        }
    }
    // dumps all meta information
    void dump( const QString &prefix,  KAlendarSyncEntry* entry ) {
        if ( entry->syncMode() == KSyncEntry::SYNC_META && !entry->firstSync() ) {
            kdDebug() << prefix << " Meta Informations" << endl;
            kdDebug() << prefix << "Modified" << endl;
            record( entry->modified() );
            kdDebug() << prefix << "Removed" << endl;
            record( entry->removed() );
            kdDebug() << prefix << "Added" << endl;
            record( entry->added() );
        }else{
            kdDebug() << prefix << "can not sync " << endl;
        }
    };

};

OrganizerPart::OrganizerPart(QWidget *parent, const char *name,
			     QObject *obj, const char *na, const QStringList & )
  : KitchenSync::ManipulatorPart( parent, name )
{
    kdDebug() << "Parent " << parent->className() << endl;
    kdDebug() << "Object " << obj->className() << endl;
  setInstance(OrganizerPartFactory::instance() );
  m_pixmap = KGlobal::iconLoader()->loadIcon("korganizer", KIcon::Desktop, 48 );
  m_widget=0;
  m_config=0;
  m_conf = new KConfig( "KitchenSyncOrganizerPart");
  m_configured = false;
}
OrganizerPart::~OrganizerPart()
{
    delete m_conf;
}
QPixmap* OrganizerPart::pixmap()
{
  return &m_pixmap;
}
QWidget* OrganizerPart::widget()
{
  kdDebug(5222) << "widget \n";
  if(m_widget==0 ){
    m_widget = new QWidget();
    m_widget->setBackgroundColor(Qt::green);
  }
  return m_widget;
}
QWidget* OrganizerPart::configWidget()
{
  //  if( m_config == 0 ){ cause of the reparent ;)
    if ( core() != 0 )
        kdDebug() << "Config Widget "<< endl;
    Profile prof = core()->currentProfile();
    if ( !m_configured ) {
        m_conf->setGroup( prof.name() );
        m_path = m_conf->readEntry("Path");
        m_evo = m_conf->readBoolEntry("Evo");
        m_configured = true;
    }
    kdDebug(5222) << "configWidget \n" ;
    m_config = new OrganizerDialogBase();
    m_config->urlReq->setURL( m_path );
    m_config->ckbEvo->setChecked( m_evo );
    //m_config->setBackgroundColor( Qt::green );
    //}
  return (QWidget*) m_config;
};

KAboutData *OrganizerPart::createAboutData()
{
  return new KAboutData("KSyncOrganizerPart", I18N_NOOP("Sync organizer part"), "0.0" );
}

void OrganizerPart::slotConfigOk()
{
    Profile prof = core()->currentProfile();
    m_path = m_config->urlReq->url();
    m_evo = m_config->ckbEvo->isChecked();
    m_conf->setGroup( prof.name() );
    m_conf->writeEntry( "Path",  m_path );
    m_conf->writeEntry( "Evo", m_evo );
}
void OrganizerPart::processEntry( const KSyncEntry::List& in,
                                  KSyncEntry::List& out )
{
    QPtrList<KAlendarSyncEntry> our;
    QPtrListIterator<KSyncEntry> it( in );
    KSyncEntry *entry;
    KAlendarSyncEntry* entry2 = 0;
    while ( (entry = it.current() ) != 0 ) {
        ++it;
        kdDebug() << entry->type() << endl;
        if ( entry->type() == QString::fromLatin1("KAlendarSyncEntry") ) {
            kdDebug() << "Found our type" << endl;
            our.append(  (KAlendarSyncEntry*) entry );
            //out.append(  entry->clone() );
            entry2 = (KAlendarSyncEntry*) entry->clone() ; //not cloning
            break;
        }
    }
    if (entry2 == 0 )
        return;
    // now load
    KAlendarSyncEntry* met = meta();

    // sync
    SyncManager manager( this,  "SyncManager");
    KSyncEntry::List one;
    one.append( entry2 );

    KSyncEntry::List two;
    two.append( met );
    SyncReturn ret =  manager.sync( SYNC_INTERACTIVE,  one, two );
    delete entry2;
    delete met;
    QDateTime time = QDateTime::currentDateTime();
    // write back if meta
    two = ret.synced();
    KAlendarSyncEntry *calendar=0;

    for ( entry = two.first(); entry != 0; entry = two.next() ) {
        if ( entry->type() == QString::fromLatin1("KalendarSyncEntry") ) {
            calendar = (KAlendarSyncEntry*)entry;
            break;
        }
    }
    if ( calendar == 0 )
        return;
    // store date time
    Profile prof = core()->currentProfile();
    Kapabilities cap = prof.caps();
    KCal::ICalFormat *form = new KCal::ICalFormat();
    if ( cap.isMetaSyncingEnabled() ) {
        m_conf->setGroup( prof.name() );
        m_conf->writeEntry("time", time );
        QString metaPath = m_conf->readEntry("metaPath" );
        calendar->calendar()->save( QDir::homeDirPath() + "/.kitchensync/meta/"+ metaPath + "/cal.vcf",  form);
        kdDebug() << "Dumping Opie " << endl;
        kdDebug() << "Sync mode == " << entry2->syncMode() << " first sync = " << entry2->firstSync() << endl;
        dump("Opie",  entry2);
        dump("KDE",  met );
    }
    KURL url(m_path );
    QString newPath;
    if ( !url.isLocalFile() ) {
        ;
    }else{
        newPath = url.path();
    }
    calendar->calendar()->save( newPath, form );
    delete form;
    out.append( calendar );
}

KAlendarSyncEntry* OrganizerPart::meta()
{
    KAlendarSyncEntry* entry = new KAlendarSyncEntry();
    KCal::CalendarLocal* cal = new KCal::CalendarLocal();
    if ( m_path.isEmpty() ) {
        KConfig conf("korganizerrc");
        conf.setGroup("General");
        m_path = conf.readEntry("Active Calendar");
    }
    KURL url(m_path );
    QString newPath;
    if ( !url.isLocalFile() ) {
        ;
    }else{
        newPath = url.path();<commit_msg>remove two stupid bugs now I need to fix libkcal again.<commit_after>
#include <qdir.h>
#include <qobject.h>
#include <qwidget.h>
#include <qlineedit.h>
#include <qcheckbox.h>
#include <qdatetime.h>

#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kparts/genericfactory.h>
#include <kparts/componentfactory.h>

#include <libkcal/icalformat.h>
#include <libkcal/calendarlocal.h>

#include "organizerbase.h"
#include "ksync_mainwindow.h"
#include "ksync_organizerpart.h"
#include <kalendarsyncentry.h>
#include <qptrlist.h>

#include "ksync_return.h"
#include "ksync_sync.h"

typedef KParts::GenericFactory< KitchenSync::OrganizerPart> OrganizerPartFactory;
K_EXPORT_COMPONENT_FACTORY( liborganizerpart, OrganizerPartFactory );

using namespace KitchenSync ;

namespace {
    void record( KCal::CalendarLocal* local ) {
        if ( local ==0 )
            return;
        const QPtrList<KCal::Todo> todos = local->getTodoList();
        QPtrListIterator<KCal::Todo> it( todos );
        QPtrList<KCal::Event> events = local->getAllEvents();
        KCal::Event* event;
        KCal::Todo* todo;
        for ( ; it.current(); ++it ) {
            todo = it.current();
            kdDebug() << "Todo: " << todo->description() << endl;
        }
        for ( event = events.first(); event != 0; event = events.next() ) {
            kdDebug() << "Event:" << event->summary() << endl;
        }
    }
    // dumps all meta information
    void dump( const QString &prefix,  KAlendarSyncEntry* entry ) {
        if ( entry->syncMode() == KSyncEntry::SYNC_META && !entry->firstSync() ) {
            kdDebug() << prefix << " Meta Informations" << endl;
            kdDebug() << prefix << "Modified" << endl;
            record( entry->modified() );
            kdDebug() << prefix << "Removed" << endl;
            record( entry->removed() );
            kdDebug() << prefix << "Added" << endl;
            record( entry->added() );
        }else{
            kdDebug() << prefix << "can not sync " << endl;
        }
    };

};

OrganizerPart::OrganizerPart(QWidget *parent, const char *name,
			     QObject *obj, const char *na, const QStringList & )
  : KitchenSync::ManipulatorPart( parent, name )
{
    kdDebug() << "Parent " << parent->className() << endl;
    kdDebug() << "Object " << obj->className() << endl;
  setInstance(OrganizerPartFactory::instance() );
  m_pixmap = KGlobal::iconLoader()->loadIcon("korganizer", KIcon::Desktop, 48 );
  m_widget=0;
  m_config=0;
  m_conf = new KConfig( "KitchenSyncOrganizerPart");
  m_configured = false;
}
OrganizerPart::~OrganizerPart()
{
    delete m_conf;
}
QPixmap* OrganizerPart::pixmap()
{
  return &m_pixmap;
}
QWidget* OrganizerPart::widget()
{
  kdDebug(5222) << "widget \n";
  if(m_widget==0 ){
    m_widget = new QWidget();
    m_widget->setBackgroundColor(Qt::green);
  }
  return m_widget;
}
QWidget* OrganizerPart::configWidget()
{
  //  if( m_config == 0 ){ cause of the reparent ;)
    if ( core() != 0 )
        kdDebug() << "Config Widget "<< endl;
    Profile prof = core()->currentProfile();
    if ( !m_configured ) {
        m_conf->setGroup( prof.name() );
        m_path = m_conf->readEntry("Path");
        m_evo = m_conf->readBoolEntry("Evo");
        m_configured = true;
    }
    kdDebug(5222) << "configWidget \n" ;
    m_config = new OrganizerDialogBase();
    m_config->urlReq->setURL( m_path );
    m_config->ckbEvo->setChecked( m_evo );
    //m_config->setBackgroundColor( Qt::green );
    //}
  return (QWidget*) m_config;
};

KAboutData *OrganizerPart::createAboutData()
{
  return new KAboutData("KSyncOrganizerPart", I18N_NOOP("Sync organizer part"), "0.0" );
}

void OrganizerPart::slotConfigOk()
{
    Profile prof = core()->currentProfile();
    m_path = m_config->urlReq->url();
    m_evo = m_config->ckbEvo->isChecked();
    m_conf->setGroup( prof.name() );
    m_conf->writeEntry( "Path",  m_path );
    m_conf->writeEntry( "Evo", m_evo );
}
void OrganizerPart::processEntry( const KSyncEntry::List& in,
                                  KSyncEntry::List& out )
{
    QPtrList<KAlendarSyncEntry> our;
    QPtrListIterator<KSyncEntry> it( in );
    KSyncEntry *entry;
    KAlendarSyncEntry* entry2 = 0;
    while ( (entry = it.current() ) != 0 ) {
        ++it;
        kdDebug() << entry->type() << endl;
        if ( entry->type() == QString::fromLatin1("KAlendarSyncEntry") ) {
            kdDebug() << "Found our type" << endl;
            our.append(  (KAlendarSyncEntry*) entry );
            //out.append(  entry->clone() );
            entry2 = (KAlendarSyncEntry*) entry->clone() ; //not cloning
            break;
        }
    }
    if (entry2 == 0 )
        return;
    // now load
    KAlendarSyncEntry* met = meta();
    dump("Opie",  entry2);
    dump("KDE",  met );
    // sync
    SyncManager manager( this,  "SyncManager");
    KSyncEntry::List one;
    one.append( entry2 );

    KSyncEntry::List two;
    two.append( met );
    SyncReturn ret =  manager.sync( SYNC_INTERACTIVE,  one, two );
    delete entry2;
    delete met;
    QDateTime time = QDateTime::currentDateTime();
    // write back if meta
    two = ret.synced();
    KAlendarSyncEntry *calendar=0;

    for ( entry = two.first(); entry != 0; entry = two.next() ) {
        if ( entry->type() == QString::fromLatin1("KAlendarSyncEntry") ) {
            calendar = (KAlendarSyncEntry*)entry;
            break;
        }
    }
    if ( calendar == 0 )
        return;
    // store date time
    Profile prof = core()->currentProfile();
    Kapabilities cap = prof.caps();
    KCal::ICalFormat *form = new KCal::ICalFormat();
    if ( cap.isMetaSyncingEnabled() ) {
        m_conf->setGroup( prof.name() );
        m_conf->writeEntry("time", time );
        QString metaPath = m_conf->readEntry("metaPath" );
        calendar->calendar()->save( QDir::homeDirPath() + "/.kitchensync/meta/"+ metaPath + "/cal.vcf",  form);
        kdDebug() << "Dumping Opie " << endl;
        kdDebug() << "Sync mode == " << entry2->syncMode() << " first sync = " << entry2->firstSync() << endl;
    }
    KURL url(m_path );
    QString newPath;
    if ( !url.isLocalFile() ) {
        ;
    }else{
        newPath = url.path();
    }
    calendar->calendar()->save( newPath, form );
    delete form;
    out.append( calendar );
}

KAlendarSyncEntry* OrganizerPart::meta()
{
    KAlendarSyncEntry* entry = new KAlendarSyncEntry();
    KCal::CalendarLocal* cal = new KCal::CalendarLocal();
    if ( m_path.isEmpty() ) {
        KConfig conf("korganizerrc");
        conf.setGroup("General");
        m_path = conf.readEntry("Active Calendar");
    }
    KURL url(m_path );
    QString newPath;
    if ( !url.isLocalFile() ) {
        ;
    }else{
        newPath = url.path();
{'fraction_non_alphanumeric': 0.16071033822120698, 'fraction_numerical': 0.0054528037727507184, 'mean_word_length': 2.845848682346274, 'pattern_counts': {'":': 0, '<': 217, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5008784', 'n_tokens_mistral': 4552, 'n_tokens_neox': 4489, 'n_words': 927}