Commit 11dde1ae authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Astyle kdelibs

parent ad8ee28a
......@@ -80,7 +80,7 @@ void Backuper::backup(const QString &filename, const QList<Akonadi::Entity::Id>
m_filename = filename;
Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(),
Akonadi::CollectionFetchJob::Recursive);
Akonadi::CollectionFetchJob::Recursive);
job->fetchScope().setContentMimeTypes(KCalCore::Incidence::mimeTypes());
connect(job, &Akonadi::CollectionFetchJob::result, this, &Backuper::onCollectionsFetched);
......@@ -91,10 +91,11 @@ void Backuper::onCollectionsFetched(KJob *job)
{
if (job->error() == 0) {
QSet<QString> mimeTypeSet = KCalCore::Incidence::mimeTypes().toSet();
Akonadi::CollectionFetchJob *cfj = qobject_cast<Akonadi::CollectionFetchJob*>(job);
foreach(const Akonadi::Collection &collection, cfj->collections()) {
if (!m_requestedCollectionIds.isEmpty() && !m_requestedCollectionIds.contains(collection.id()))
Akonadi::CollectionFetchJob *cfj = qobject_cast<Akonadi::CollectionFetchJob *>(job);
foreach (const Akonadi::Collection &collection, cfj->collections()) {
if (!m_requestedCollectionIds.isEmpty() && !m_requestedCollectionIds.contains(collection.id())) {
continue;
}
if (!mimeTypeSet.intersect(collection.contentMimeTypes().toSet()).isEmpty()) {
m_collections << collection;
loadCollection(collection);
......
......@@ -45,8 +45,9 @@ static void print(const QString &message, bool newline = true)
{
QTextStream out(stdout);
out << message;
if (newline)
if (newline) {
out << "\n";
}
}
static void bailOut()
......@@ -63,8 +64,9 @@ static bool collectionIsReadOnly(const Akonadi::Collection &collection)
static bool incidenceIsOld(const KCalCore::Incidence::Ptr &incidence)
{
if (incidence->recurs() || incidence->type() == KCalCore::Incidence::TypeJournal)
if (incidence->recurs() || incidence->type() == KCalCore::Incidence::TypeJournal) {
return false;
}
KDateTime datetime = incidence->dtStart();
if (!datetime.isValid() && incidence->type() == KCalCore::Incidence::TypeTodo) {
......@@ -75,13 +77,13 @@ static bool incidenceIsOld(const KCalCore::Incidence::Ptr &incidence)
}
CalendarJanitor::CalendarJanitor(const Options &options, QObject *parent) : QObject(parent)
, m_collectionLoader(new CollectionLoader(this))
, m_options(options)
, m_currentSanityCheck(Options::CheckNone)
, m_pendingModifications(0)
, m_pendingDeletions(0)
, m_strippingOldAlarms(false)
, m_returnCode(0)
, m_collectionLoader(new CollectionLoader(this))
, m_options(options)
, m_currentSanityCheck(Options::CheckNone)
, m_pendingModifications(0)
, m_pendingDeletions(0)
, m_strippingOldAlarms(false)
, m_returnCode(0)
{
m_changer = new Akonadi::IncidenceChanger(this);
m_changer->setShowDialogsOnError(false);
......@@ -105,8 +107,9 @@ void CalendarJanitor::onCollectionsFetched(bool success)
}
foreach (const Akonadi::Collection &collection, m_collectionLoader->collections()) {
if (m_options.testCollection(collection.id()))
if (m_options.testCollection(collection.id())) {
m_collectionsToProcess << collection;
}
}
if (m_collectionsToProcess.isEmpty()) {
......@@ -142,8 +145,9 @@ void CalendarJanitor::onModifyFinished(int changeId, const Akonadi::Item &item,
bailOut();
return;
}
if (!m_options.stripOldAlarms())
if (!m_options.stripOldAlarms()) {
print(i18n("Fixed item %1", item.id()));
}
m_pendingModifications--;
if (m_pendingModifications == 0) {
......@@ -224,9 +228,9 @@ void CalendarJanitor::runNextTest()
}
int currentType = static_cast<int>(m_currentSanityCheck);
m_currentSanityCheck = static_cast<Options::SanityCheck>(currentType+1);
m_currentSanityCheck = static_cast<Options::SanityCheck>(currentType + 1);
switch(m_currentSanityCheck) {
switch (m_currentSanityCheck) {
case Options::CheckEmptySummary:
sanityCheck1();
break;
......@@ -269,7 +273,7 @@ void CalendarJanitor::sanityCheck1()
foreach (const Akonadi::Item &item, m_itemsToProcess) {
KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence(item);
if (incidence->summary().isEmpty() && incidence->description().isEmpty()
&& incidence->attachments().isEmpty()) {
&& incidence->attachments().isEmpty()) {
printFound(item);
deleteIncidence(item);
}
......@@ -303,8 +307,9 @@ void CalendarJanitor::sanityCheck3()
foreach (const Akonadi::Item &item, m_itemsToProcess) {
KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence(item);
KCalCore::Event::Ptr event = incidence.dynamicCast<KCalCore::Event>();
if (!event)
if (!event) {
continue;
}
KDateTime start = event->dtStart();
KDateTime end = event->dtEnd();
......@@ -339,8 +344,9 @@ void CalendarJanitor::sanityCheck4()
foreach (const Akonadi::Item &item, m_itemsToProcess) {
KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence(item);
KCalCore::Todo::Ptr todo = incidence.dynamicCast<KCalCore::Todo>();
if (!todo)
if (!todo) {
continue;
}
KDateTime start = todo->dtStart();
KDateTime due = todo->dtDue();
......@@ -373,8 +379,9 @@ void CalendarJanitor::sanityCheck5()
beginTest(i18n("Checking for journals with invalid DTSTART..."));
foreach (const Akonadi::Item &item, m_itemsToProcess) {
KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence(item);
if (incidence->type() != KCalCore::Incidence::TypeJournal)
if (incidence->type() != KCalCore::Incidence::TypeJournal) {
continue;
}
if (!incidence->dtStart().isValid()) {
printFound(item);
......@@ -416,8 +423,9 @@ void CalendarJanitor::sanityCheck7()
KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence(item);
QList<KCalCore::Incidence::Ptr> existingIncidences = m_incidenceMap.values(incidence->instanceIdentifier());
if (existingIncidences.count() == 1)
if (existingIncidences.count() == 1) {
continue;
}
foreach (const KCalCore::Incidence::Ptr &existingIncidence, existingIncidences) {
if (existingIncidence != incidence && *incidence == *existingIncidence) {
......@@ -432,10 +440,11 @@ void CalendarJanitor::sanityCheck7()
KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence(item);
QList<KCalCore::Incidence::Ptr> existingIncidences = m_incidenceMap.values(incidence->instanceIdentifier());
if (existingIncidences.count() == 1)
if (existingIncidences.count() == 1) {
continue;
}
for (int i=1; i<existingIncidences.count(); ++i) {
for (int i = 1; i < existingIncidences.count(); ++i) {
printFound(item);
if (m_fixingEnabled) {
KCalCore::Incidence::Ptr existingIncidence = existingIncidences.at(i);
......@@ -489,15 +498,17 @@ void CalendarJanitor::sanityCheck8()
m_counts[incidence->type()]++;
if (incidenceIsOld(incidence)) {
if (!incidence->alarms().isEmpty())
if (!incidence->alarms().isEmpty()) {
numOldAlarms++;
}
numOldIncidences++;
}
numAttachments += incidence->attachments().count();
if (item.remoteId().isEmpty())
if (item.remoteId().isEmpty()) {
numEmptyRID++;
}
}
printStat(i18n("Events"), m_counts[KCalCore::Incidence::TypeEvent]);
......@@ -514,9 +525,9 @@ void CalendarJanitor::sanityCheck8()
printStat(i18n("Total size of inline attachments (KB)"), totalAttachmentSize / 1024);
}
if (numEmptyRID > 0)
if (numEmptyRID > 0) {
m_returnCode = -2;
}
endTest(/**print=*/false);
}
......@@ -596,15 +607,17 @@ static QString dateString(const KCalCore::Incidence::Ptr &incidence)
str += QLatin1String("\n ");
if (incidence->type() == KCalCore::Incidence::TypeTodo)
if (incidence->type() == KCalCore::Incidence::TypeTodo) {
str += QLatin1String("DTDUE=");
else if (incidence->type() == KCalCore::Incidence::TypeEvent)
} else if (incidence->type() == KCalCore::Incidence::TypeEvent) {
str += QLatin1String("DTEND=");
}
str+= (start.isValid() ? end.toString() : i18n("invalid")) + QLatin1String("; ");
str += (start.isValid() ? end.toString() : i18n("invalid")) + QLatin1String("; ");
if (incidence->recurs())
if (incidence->recurs()) {
str += i18n("recurrent");
}
return str;
}
......@@ -639,10 +652,11 @@ void CalendarJanitor::endTest(bool printEnabled, const QString fixExplanation, c
print(QLatin1String(" [OK]"));
} else if (m_numDamaged > 0) {
print(QLatin1String("\n "), false);
if (m_options.action() == Options::ActionScanAndFix)
if (m_options.action() == Options::ActionScanAndFix) {
print(fixExplanation2);
else
} else {
print(fixExplanation);
}
print(QString());
}
......
......@@ -37,7 +37,6 @@
class CollectionLoader;
class CalendarJanitor : public QObject
{
Q_OBJECT
......
......@@ -39,7 +39,7 @@ CollectionLoader::CollectionLoader(QObject *parent) :
void CollectionLoader::load()
{
Akonadi::CollectionFetchJob *job = new Akonadi::CollectionFetchJob(Akonadi::Collection::root(),
Akonadi::CollectionFetchJob::Recursive);
Akonadi::CollectionFetchJob::Recursive);
job->fetchScope().setContentMimeTypes(KCalCore::Incidence::mimeTypes());
connect(job, &Akonadi::CollectionFetchJob::result, this, &CollectionLoader::onCollectionsLoaded);
......@@ -54,9 +54,9 @@ Akonadi::Collection::List CollectionLoader::collections() const
void CollectionLoader::onCollectionsLoaded(KJob *job)
{
if (job->error() == 0) {
Akonadi::CollectionFetchJob *cfj = qobject_cast<Akonadi::CollectionFetchJob*>(job);
Akonadi::CollectionFetchJob *cfj = qobject_cast<Akonadi::CollectionFetchJob *>(job);
Q_ASSERT(cfj);
foreach(const Akonadi::Collection &collection, cfj->collections()) {
foreach (const Akonadi::Collection &collection, cfj->collections()) {
QSet<QString> mimeTypeSet = KCalCore::Incidence::mimeTypes().toSet();
if (!mimeTypeSet.intersect(collection.contentMimeTypes().toSet()).isEmpty()) {
m_collections << collection;
......
......@@ -41,7 +41,7 @@ Q_SIGNALS:
void loaded(bool succcess);
private Q_SLOTS:
void onCollectionsLoaded(KJob*);
void onCollectionsLoaded(KJob *);
private:
Akonadi::Collection::List m_collections;
......
......@@ -76,19 +76,18 @@ int main(int argv, char *argc[])
{
KLocalizedString::setApplicationDomain("calendarjanitor");
K4AboutData aboutData(progName, 0, // internal program name
ki18n(progDisplay), // displayable program name.
progVersion, // version string
ki18n(progDesc), // short program description
K4AboutData::License_GPL, // license type
ki18n("(c) 2013, Sérgio Martins"),
ki18n(0), // any free form text
0, // program home page address
"bugs.kde.org");
ki18n(progDisplay), // displayable program name.
progVersion, // version string
ki18n(progDesc), // short program description
K4AboutData::License_GPL, // license type
ki18n("(c) 2013, Sérgio Martins"),
ki18n(0), // any free form text
0, // program home page address
"bugs.kde.org");
aboutData.addAuthor(ki18n("Sérgio Martins"), ki18n("Maintainer"), "iamsergio@gmail.com", 0);
KCmdLineArgs::init(argv, argc, &aboutData, KCmdLineArgs::CmdLineArgNone);
KCmdLineOptions options;
options.add("collections <ids>", ki18n("List of collection ids to scan"));
options.add("fix", ki18n("Fix broken incidences"));
......@@ -107,7 +106,7 @@ int main(int argv, char *argc[])
"$ calendarjanitor --backup backup.ics --collections 10,20\n\n"
"Strip alarms from incidences older than 365 days:\n"
"$ calendarjanitor --strip-old-alarms --collections 10,20")
);
);
KCmdLineArgs::addCmdLineOptions(options);
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
......@@ -174,7 +173,7 @@ int main(int argv, char *argc[])
janitorOptions.setAction(Options::ActionScan);
}
switch(janitorOptions.action()) {
switch (janitorOptions.action()) {
case Options::ActionBackup: {
Backuper *backuper = new Backuper();
backuper->backup(backupFile, janitorOptions.collections());
......@@ -190,6 +189,5 @@ int main(int argv, char *argc[])
Q_ASSERT(false);
}
return app.exec();
}
This diff is collapsed.
......@@ -49,14 +49,14 @@ class QTextStream;
*/
class KonsoleKalendar
{
public:
public:
/**
* Constructs a KonsoleKalendar object from command line arguments.
*
* @param variables is a pointer to a #KonsoleKalendarVariables object
* containing all the command line arguments.
*/
explicit KonsoleKalendar( KonsoleKalendarVariables *variables );
explicit KonsoleKalendar(KonsoleKalendarVariables *variables);
/**
* Destructor
......@@ -95,7 +95,7 @@ class KonsoleKalendar
* @param enddate Ending date
* @param summary Which summary event should have have
*/
bool isEvent( const QDateTime &startdate, const QDateTime &enddate, const QString &summary );
bool isEvent(const QDateTime &startdate, const QDateTime &enddate, const QString &summary);
/**
* Creates calendar file (If it doesn't exists)
......@@ -107,7 +107,7 @@ class KonsoleKalendar
*/
bool printCalendarList();
private:
private:
/**
* Print event specs for dryrun and verbose options
*/
......@@ -125,7 +125,7 @@ class KonsoleKalendar
* @param eventList which event we should print
* @param dt is the date to use when printing the event for recurring events
*/
bool printEventList( QTextStream *ts, KCalCore::Event::List *eventList, QDate dt );
bool printEventList(QTextStream *ts, KCalCore::Event::List *eventList, QDate dt);
/**
* Prints a single event in many formats
......@@ -134,7 +134,7 @@ class KonsoleKalendar
* @param event which we should print
* @param dt is the date to use when printing the event for recurring events
*/
bool printEvent( QTextStream *ts, const KCalCore::Event::Ptr &event, QDate dt );
bool printEvent(QTextStream *ts, const KCalCore::Event::Ptr &event, QDate dt);
/**
* Variables that changes stuff in program
......
......@@ -55,9 +55,9 @@
using namespace KCalCore;
using namespace std;
KonsoleKalendarAdd::KonsoleKalendarAdd( KonsoleKalendarVariables *vars )
KonsoleKalendarAdd::KonsoleKalendarAdd(KonsoleKalendarVariables *vars)
{
m_variables = vars;
m_variables = vars;
}
KonsoleKalendarAdd::~KonsoleKalendarAdd()
......@@ -70,70 +70,70 @@ KonsoleKalendarAdd::~KonsoleKalendarAdd()
bool KonsoleKalendarAdd::addEvent()
{
bool status = true;
bool status = true;
qDebug() << "konsolekalendaradd.cpp::addEvent()";
if ( m_variables->isDryRun() ) {
cout << i18n( "Insert Event <Dry Run>:" ).toLocal8Bit().data()
<< endl;
printSpecs();
} else {
if ( m_variables->isVerbose() ) {
cout << i18n( "Insert Event <Verbose>:" ).toLocal8Bit().data()
<< endl;
printSpecs();
}
Event::Ptr event = Event::Ptr( new Event() );
KDateTime::Spec timeSpec = m_variables->getCalendar()->timeSpec();
event->setDtStart( KDateTime( m_variables->getStartDateTime(), timeSpec ) );
event->setDtEnd( KDateTime( m_variables->getEndDateTime(), timeSpec ) );
event->setSummary( m_variables->getSummary() );
event->setAllDay( m_variables->getFloating() );
event->setDescription( m_variables->getDescription() );
event->setLocation( m_variables->getLocation() );
Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar();
QEventLoop loop;
QObject::connect(calendar.data(), SIGNAL(createFinished(bool,QString)),
&loop, SLOT(quit()));
QElapsedTimer t;
t.start();
Q_ASSERT(calendar->incidence(event->uid()) == 0 ); // can't exist yet
if (!m_variables->allowGui()) {
Akonadi::IncidenceChanger *changer = calendar->incidenceChanger();
changer->setShowDialogsOnError(false);
Akonadi::Collection collection = m_variables->collectionId() != -1 ? Akonadi::Collection(m_variables->collectionId())
: Akonadi::Collection(CalendarSupport::KCalPrefs::instance()->defaultCalendarId());
if (!collection.isValid()) {
cout << i18n("Calendar is invalid. Please specify one with --calendar").toLocal8Bit().data() << "\n";
}
changer->setDefaultCollection(collection);
changer->setDestinationPolicy(Akonadi::IncidenceChanger::DestinationPolicyNeverAsk);
}
calendar->addEvent(event);
loop.exec();
qDebug() << "Creation took " << t.elapsed() << "ms.";
status = calendar->incidence(event->uid()) != 0;
if ( status ) {
cout << i18n( "Success: \"%1\" inserted",
m_variables->getSummary() ).toLocal8Bit().data()
<< endl;
qDebug() << "konsolekalendaradd.cpp::addEvent()";
if (m_variables->isDryRun()) {
cout << i18n("Insert Event <Dry Run>:").toLocal8Bit().data()
<< endl;
printSpecs();
} else {
cout << i18n( "Failure: \"%1\" not inserted",
m_variables->getSummary() ).toLocal8Bit().data()
<< endl;
status = false;
if (m_variables->isVerbose()) {
cout << i18n("Insert Event <Verbose>:").toLocal8Bit().data()
<< endl;
printSpecs();
}
Event::Ptr event = Event::Ptr(new Event());
KDateTime::Spec timeSpec = m_variables->getCalendar()->timeSpec();
event->setDtStart(KDateTime(m_variables->getStartDateTime(), timeSpec));
event->setDtEnd(KDateTime(m_variables->getEndDateTime(), timeSpec));
event->setSummary(m_variables->getSummary());
event->setAllDay(m_variables->getFloating());
event->setDescription(m_variables->getDescription());
event->setLocation(m_variables->getLocation());
Akonadi::CalendarBase::Ptr calendar = m_variables->getCalendar();
QEventLoop loop;
QObject::connect(calendar.data(), SIGNAL(createFinished(bool,QString)),
&loop, SLOT(quit()));
QElapsedTimer t;
t.start();
Q_ASSERT(calendar->incidence(event->uid()) == 0); // can't exist yet
if (!m_variables->allowGui()) {
Akonadi::IncidenceChanger *changer = calendar->incidenceChanger();
changer->setShowDialogsOnError(false);
Akonadi::Collection collection = m_variables->collectionId() != -1 ? Akonadi::Collection(m_variables->collectionId())
: Akonadi::Collection(CalendarSupport::KCalPrefs::instance()->defaultCalendarId());
if (!collection.isValid()) {
cout << i18n("Calendar is invalid. Please specify one with --calendar").toLocal8Bit().data() << "\n";
}
changer->setDefaultCollection(collection);
changer->setDestinationPolicy(Akonadi::IncidenceChanger::DestinationPolicyNeverAsk);
}
calendar->addEvent(event);
loop.exec();
qDebug() << "Creation took " << t.elapsed() << "ms.";
status = calendar->incidence(event->uid()) != 0;
if (status) {
cout << i18n("Success: \"%1\" inserted",
m_variables->getSummary()).toLocal8Bit().data()
<< endl;
} else {
cout << i18n("Failure: \"%1\" not inserted",
m_variables->getSummary()).toLocal8Bit().data()
<< endl;
status = false;
}
}
}
qDebug() << "konsolekalendaradd.cpp::addEvent() | Done";
return status;
qDebug() << "konsolekalendaradd.cpp::addEvent() | Done";
return status;
}
bool KonsoleKalendarAdd::addImportedCalendar()
......@@ -141,55 +141,55 @@ bool KonsoleKalendarAdd::addImportedCalendar()
// If --file specified, then import into that file
// else, import into the standard calendar
/*
* TODO_SERGIO
QString fileName;
if ( m_variables->getCalendarFile().isEmpty() ) {
fileName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "korganizer/std.ics" ;
} else {
fileName = m_variables->getCalendarFile();
}
CalendarLocal *cal = new CalendarLocal( KSystemTimeZones::local() );
if ( !cal->load( fileName ) ||
!cal->load( m_variables->getImportFile() ) ||
!cal->save( fileName ) ) {
qDebug() << "konsolekalendaradd.cpp::importCalendar() |"
<< "Can't import file:"
<< m_variables->getImportFile();
return false;
}
qDebug() << "konsolekalendaradd.cpp::importCalendar() |"
<< "Successfully imported file:"
<< m_variables->getImportFile();
*/
return true;
/*
* TODO_SERGIO
QString fileName;
if ( m_variables->getCalendarFile().isEmpty() ) {
fileName = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + "korganizer/std.ics" ;
} else {
fileName = m_variables->getCalendarFile();
}
CalendarLocal *cal = new CalendarLocal( KSystemTimeZones::local() );
if ( !cal->load( fileName ) ||
!cal->load( m_variables->getImportFile() ) ||
!cal->save( fileName ) ) {
qDebug() << "konsolekalendaradd.cpp::importCalendar() |"
<< "Can't import file:"
<< m_variables->getImportFile();
return false;
}
qDebug() << "konsolekalendaradd.cpp::importCalendar() |"
<< "Successfully imported file:"
<< m_variables->getImportFile();
*/
return true;
}
void KonsoleKalendarAdd::printSpecs()
{
cout << i18n( " What: %1",
m_variables->getSummary() ).toLocal8Bit().data()
<< endl;
cout << i18n( " Begin: %1",
m_variables->getStartDateTime().toString( Qt::TextDate ) ).toLocal8Bit().data()
<< endl;
cout << i18n(" What: %1",
m_variables->getSummary()).toLocal8Bit().data()
<< endl;
cout << i18n( " End: %1",
m_variables->getEndDateTime().toString( Qt::TextDate ) ).toLocal8Bit().data()
<< endl;
cout << i18n(" Begin: %1",
m_variables->getStartDateTime().toString(Qt::TextDate)).toLocal8Bit().data()
<< endl;
if ( m_variables->getFloating() == true ) {
cout << i18n( " No Time Associated with Event" ).toLocal8Bit().data()
cout << i18n(" End: %1",
m_variables->getEndDateTime().toString(Qt::TextDate)).toLocal8Bit().data()
<< endl;
}
cout << i18n( " Desc: %1",
m_variables->getDescription() ).toLocal8Bit().data()
<< endl;
if (m_variables->getFloating() == true) {