• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

knotes

resourcelocal.cpp

Go to the documentation of this file.
00001 /*******************************************************************
00002  This file is part of KNotes.
00003 
00004  Copyright (c) 2004, Bo Thorsen <bo@sonofthor.dk>
00005                2004-2006, Michael Brade <brade@kde.org>
00006 
00007  This program is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  This program is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with this program; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  MA  02110-1301, USA.
00021 
00022  In addition, as a special exception, the copyright holders give
00023  permission to link the code of this program with any edition of
00024  the Qt library by Trolltech AS, Norway (or with modified versions
00025  of Qt that use the same license as Qt), and distribute linked
00026  combinations including the two.  You must obey the GNU General
00027  Public License in all respects for all of the code used other than
00028  Qt.  If you modify this file, you may extend this exception to
00029  your version of the file, but you are not obligated to do so.  If
00030  you do not wish to do so, delete this exception statement from
00031  your version.
00032 *******************************************************************/
00033 
00034 #include <klocale.h>
00035 #include <kmessagebox.h>
00036 #include <kstandarddirs.h>
00037 #include <kconfiggroup.h>
00038 
00039 #include <kcal/icalformat.h>
00040 
00041 #include "knotes/resourcelocal.h"
00042 #include "knotes/resourcelocalconfig.h"
00043 #include "knotes/resourcemanager.h"
00044 #include "knotes/resourcenotes.h"
00045 
00046 
00047 ResourceLocal::ResourceLocal()
00048   : ResourceNotes(), mCalendar( QString::fromLatin1( "UTC" ) )
00049 {
00050   kDebug( 5500 ) << "ResourceLocal::ResourceLocal()";
00051   setType( "file" );
00052   mURL = KUrl::fromPath( KGlobal::dirs()->saveLocation( "data", "knotes/" ) +
00053                          "notes.ics" );
00054 }
00055 
00056 ResourceLocal::ResourceLocal( const KConfigGroup &group )
00057   : ResourceNotes( group ), mCalendar( QString::fromLatin1( "UTC" ) )
00058 {
00059   kDebug( 5500 ) << "ResourceLocal::ResourceLocal()";
00060   setType( "file" );
00061   mURL = KUrl::fromPath( KGlobal::dirs()->saveLocation( "data", "knotes/" ) +
00062                          "notes.ics" );
00063   
00064   KUrl u = group.readPathEntry( "NotesURL", QString() );
00065   if ( !u.isEmpty() ) {
00066     mURL = u;
00067   }
00068 }
00069 
00070 ResourceLocal::~ResourceLocal()
00071 {
00072 }
00073 
00074 void ResourceLocal::writeConfig( KConfigGroup &group )
00075 {
00076   KRES::Resource::writeConfig( group );
00077   group.writePathEntry( "NotesURL", mURL.prettyUrl() );
00078 }
00079 
00080 bool ResourceLocal::load()
00081 {
00082   mCalendar.load( mURL.path() );
00083   
00084   KCal::Journal::List notes = mCalendar.journals();
00085   KCal::Journal::List::ConstIterator it;
00086   for ( it = notes.begin(); it != notes.end(); ++it ) {
00087     manager()->registerNote( this, *it );
00088   }
00089   
00090   return true;
00091 }
00092 
00093 bool ResourceLocal::save()
00094 {
00095   if ( !mCalendar.save( mURL.path(), new KCal::ICalFormat() ) ) {
00096     KMessageBox::error( 0, i18n( "<qt>Unable to save the notes to <b>%1</b>. "
00097                                  "Check that there is sufficient disk space."
00098                                  "<br />There should be a backup in the same "
00099                                  "directory though.</qt>", mURL.path() ) );
00100     return false;
00101   }
00102   
00103     return true;
00104 }
00105 
00106 bool ResourceLocal::addNote( KCal::Journal *journal )
00107 {
00108   mCalendar.addJournal( journal );
00109   return true;
00110 }
00111 
00112 bool ResourceLocal::deleteNote( KCal::Journal *journal )
00113 {
00114   mCalendar.deleteJournal( journal );
00115   return true;
00116 }
00117 
00118 KCal::Alarm::List ResourceLocal::alarms( const KDateTime &from,
00119                                          const KDateTime &to )
00120 {
00121   KCal::Alarm::List alarms;
00122   KCal::Journal::List notes = mCalendar.journals();
00123   KCal::Journal::List::ConstIterator note;
00124   
00125   for ( note = notes.begin(); note != notes.end(); ++note ) {
00126     KDateTime preTime = from.addSecs( -1 );
00127     KCal::Alarm::List::ConstIterator it;
00128     for( it = ( *note )->alarms().begin();
00129          it != ( *note )->alarms().end(); ++it ) {
00130       if ( ( *it )->enabled() ) {
00131         KDateTime dt = ( *it )->nextRepetition( preTime );
00132         if ( dt.isValid() && dt <= to ) {
00133           alarms.append( *it );
00134         }
00135       }
00136     }
00137   }
00138   
00139   return alarms;
00140 }

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal