You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.2 KiB
97 lines
3.2 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
* Copyright (C) 2004 Bram Schoenmakers <bramschoenmakers@kde.nl>
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU General Public
|
||
|
* License as published by the Free Software Foundation version 2.
|
||
|
*
|
||
|
* This program is distributed in the hope that
|
||
|
t it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; see the file COPYING. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqdatetime.h>
|
||
|
#include <tqfile.h>
|
||
15 years ago
|
|
||
|
#include <libkcal/calendarlocal.h>
|
||
|
#include <libkcal/todo.h>
|
||
|
|
||
12 years ago
|
#include "tdefile_ics.h"
|
||
15 years ago
|
|
||
|
#include <kgenericfactory.h>
|
||
|
|
||
|
using namespace KCal;
|
||
|
|
||
|
typedef KGenericFactory<ICSPlugin> ICSFactory;
|
||
12 years ago
|
K_EXPORT_COMPONENT_FACTORY(tdefile_ics, ICSFactory( "tdefile_ics" ))
|
||
15 years ago
|
|
||
14 years ago
|
ICSPlugin::ICSPlugin( TQObject *parent, const char *name, const TQStringList& args )
|
||
|
: KFilePlugin( parent, name, args )
|
||
15 years ago
|
{
|
||
|
KFileMimeTypeInfo* info = addMimeTypeInfo( "text/calendar" ); //TODO: vcs !!
|
||
|
|
||
|
KFileMimeTypeInfo::GroupInfo* group = 0L;
|
||
|
group = addGroupInfo(info, "ICSInfo", i18n("Calendar Statistics"));
|
||
|
|
||
15 years ago
|
addItemInfo( group, "ProductID", i18n("Product ID"), TQVariant::String );
|
||
|
addItemInfo( group, "Events", i18n("Events"), TQVariant::Int );
|
||
|
addItemInfo( group, "Todos", i18n("To-dos"), TQVariant::Int );
|
||
|
addItemInfo( group, "TodoCompleted", i18n("Completed To-dos"), TQVariant::Int );
|
||
|
addItemInfo( group, "TodoOverdue", i18n("Overdue To-dos"), TQVariant::Int );
|
||
|
addItemInfo( group, "Journals", i18n("Journals"), TQVariant::Int );
|
||
|
// addItemInfo( group, "Reminders", i18n("Reminders"), TQVariant::Int );
|
||
15 years ago
|
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
I chose to use libkcal instead of reading the calendar manually. It's easier to
|
||
|
maintain this way.
|
||
|
*/
|
||
|
bool ICSPlugin::readInfo( KFileMetaInfo& info, uint /*what*/ )
|
||
|
{
|
||
|
KFileMetaInfoGroup group = appendGroup( info, "ICSInfo");
|
||
|
|
||
13 years ago
|
CalendarLocal cal ( TQString::fromLatin1( "UTC" ) );
|
||
15 years ago
|
if( !cal.load( info.path() ) ) {
|
||
|
kdDebug() << "Could not load calendar" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
appendItem( group, "ProductID", TQVariant( cal.productId() ) );
|
||
|
appendItem( group, "Events", TQVariant( int( cal.events().count() ) ) );
|
||
|
appendItem( group, "Journals", TQVariant( int( cal.journals().count() ) ) );
|
||
15 years ago
|
Todo::List todos = cal.todos();
|
||
|
|
||
|
// count completed and overdue
|
||
|
Todo::List::ConstIterator it = todos.begin();
|
||
|
Todo::List::ConstIterator end = todos.end();
|
||
|
|
||
|
int completed = 0;
|
||
|
int overdue = 0;
|
||
|
for ( ; it != end ; ++it ) {
|
||
|
Todo *todo = *it;
|
||
|
if ( todo->isCompleted() )
|
||
|
++completed;
|
||
13 years ago
|
else if ( todo->hasDueDate() && todo->dtDue().date() < TQDate::currentDate() )
|
||
15 years ago
|
++overdue;
|
||
|
}
|
||
|
|
||
15 years ago
|
appendItem( group, "Todos", TQVariant( int(todos.count() ) ) );
|
||
|
appendItem( group, "TodoCompleted", TQVariant( completed ) );
|
||
|
appendItem( group, "TodoOverdue", TQVariant( overdue ) );
|
||
15 years ago
|
|
||
|
cal.close();
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdefile_ics.moc"
|