kpilot

kcalRecord.cc

Go to the documentation of this file.
00001 /* kcalRecord.cc                       KPilot
00002 **
00003 ** Copyright (C) 2006 by Adriaan de Groot <groot@kde.org>
00004 ** Copyright (C) 2002-2003 by Reinhold Kainhofer
00005 ** Copyright (C) 2001 by Dan Pilone
00006 **
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
00028 */
00029 
00030 #include "options.h"
00031 
00032 #include <libkcal/calendar.h>
00033 #include <libkcal/calendarlocal.h>
00034 #include <libkcal/recurrence.h>
00035 #include <libkcal/vcalformat.h>
00036 
00037 #include "pilot.h"
00038 #include "pilotRecord.h"
00039 #include "kcalRecord.h"
00040 
00041 void KCalSync::setCategory(PilotRecordBase *de,
00042     const KCal::Incidence *e,
00043     const CategoryAppInfo &info)
00044 {
00045     FUNCTIONSETUP;
00046 
00047     if (!de || !e)
00048     {
00049         return;
00050     }
00051 
00052     QString deCategory;
00053     QStringList eventCategories = e->categories();
00054     if (eventCategories.size() < 1)
00055     {
00056         // This event has no categories.
00057         de->setCategory(Pilot::Unfiled);
00058         return;
00059     }
00060 
00061     // Quick check: does the record (not unfiled) have an entry
00062     // in the categories list? If so, use that.
00063     if (de->category() != Pilot::Unfiled)
00064     {
00065         deCategory = Pilot::categoryName(&info,de->category());
00066         if (eventCategories.contains(deCategory))
00067         {
00068             // Found, so leave the category unchanged.
00069             return;
00070         }
00071     }
00072 
00073     QStringList availableHandheldCategories = Pilot::categoryNames(&info);
00074 
00075     // Either the record is unfiled, and should be filed, or
00076     // it has a category set which is not in the list of
00077     // categories that the event has. So go looking for
00078     // a category that is available both for the event
00079     // and on the handheld.
00080     for ( QStringList::ConstIterator it = eventCategories.begin();
00081         it != eventCategories.end(); ++it )
00082     {
00083         // Odd, an empty category string.
00084         if ( (*it).isEmpty() )
00085         {
00086             continue;
00087         }
00088 
00089         if (availableHandheldCategories.contains(*it))
00090         {
00091             // Since the string is in the list of available categories,
00092             // this *can't* fail.
00093             int c = Pilot::findCategory(&info,*it,false);
00094             Q_ASSERT( Pilot::validCategory(c) );
00095             de->setCategory(c);
00096             return;
00097         }
00098     }
00099 
00100     de->setCategory(Pilot::Unfiled);
00101 }
00102 
00103 void KCalSync::setCategory(KCal::Incidence *e,
00104     const PilotRecordBase *de,
00105     const CategoryAppInfo &info)
00106 {
00107     FUNCTIONSETUP;
00108 
00109     if (!e || !de)
00110     {
00111         DEBUGKPILOT << fname << ": error.  unable to set kcal category. e: ["
00112             << (void *)e << "], de: [" << (void *)de << "]" << endl;
00113         return;
00114     }
00115 
00116     QStringList cats=e->categories();
00117     int cat = de->category();
00118     QString newcat = Pilot::categoryName(&info,cat);
00119 
00120     DEBUGKPILOT << fname << ": palm category id: [" << cat <<
00121         "], label: [" << newcat << "]" << endl;
00122 
00123     if ( Pilot::validCategory(cat) && (cat != Pilot::Unfiled))
00124     {
00125         if (!cats.contains(newcat))
00126         {
00127             // if this event only has one category associated with it, then we can
00128             // safely assume that what we should be doing here is changing it to match
00129             // the palm.  if there's already more than one category in the event, however, we
00130             // won't cause data loss--we'll just append what the palm has to the
00131             // event's categories
00132             if (cats.count() <=1)
00133             {
00134                 cats.clear();
00135             }
00136 
00137             cats.append( newcat );
00138             e->setCategories(cats);
00139         }
00140     }
00141 
00142     DEBUGKPILOT << fname << ": kcal categories now: [" << cats.join(",") << "]" << endl;
00143 }